Version: 6.3.1

src/OBJECT/SMESH_ActorUtils.cxx

Go to the documentation of this file.
00001 // Copyright (C) 2007-2011  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 #include "SMESH_ActorUtils.h"
00024 #include "SMESH_Actor.h"
00025 
00026 #include "SUIT_Tools.h"
00027 #include "SUIT_Session.h"
00028 #include "SUIT_ResourceMgr.h"
00029 #include <SALOMEconfig.h> // To fix some redefinition
00030 #include "SalomeApp_Application.h"
00031 
00032 #ifndef DISABLE_PLOT2DVIEWER
00033 #include <SPlot2d_ViewModel.h>
00034 #include <SPlot2d_Histogram.h>
00035 #include <Plot2d_ViewManager.h>
00036 #endif
00037 
00038 
00039 #include "utilities.h"
00040 
00041 #include <vtkUnstructuredGrid.h>
00042 #include <vtkXMLUnstructuredGridWriter.h>
00043 #include <vtkUnstructuredGridWriter.h>
00044 
00045 //#ifdef _DEBUG_
00046 //static int MYDEBUG = 1;
00047 //#else
00048 //static int MYDEBUG = 0;
00049 //#endif
00050 
00051 namespace SMESH
00052 {
00053 
00054   vtkFloatingPointType
00055   GetFloat( const QString& theValue, 
00056             vtkFloatingPointType theDefault )
00057   {
00058     int pos = theValue.indexOf( ":" );
00059     vtkFloatingPointType val = theDefault;
00060     if( pos>=0 ) 
00061     {
00062       QString name = theValue.right( theValue.length()-pos-1 ),
00063               sect = theValue.left( pos );
00064       if( !name.isEmpty() && !sect.isEmpty() )
00065         val = GetFloat( name, sect, theDefault );
00066     }
00067     return val;
00068   }
00069 
00070   vtkFloatingPointType
00071   GetFloat( const QString& theValue, 
00072             const QString& theSection, 
00073             vtkFloatingPointType theDefault )
00074   {
00075     vtkFloatingPointType val = theDefault;
00076     SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
00077     if( mgr )
00078       val = (vtkFloatingPointType) mgr->doubleValue( theSection, theValue, theDefault );
00079 
00080     return val;
00081   }
00082 
00083   void
00084   WriteUnstructuredGrid(vtkUnstructuredGrid* theGrid, 
00085                         const char* theFileName)
00086   {
00087     vtkXMLUnstructuredGridWriter* aWriter = vtkXMLUnstructuredGridWriter::New();
00088     aWriter->SetFileName(theFileName);
00089     aWriter->SetInput(theGrid);
00090     aWriter->SetDataModeToAscii();
00091     if(theGrid->GetNumberOfCells()){
00092       aWriter->Write();
00093     }
00094     aWriter->Delete();
00095   }
00096 
00097   QColor
00098   GetColor( const QString& theSect, 
00099             const QString& theName, 
00100             const QColor& def )
00101   {
00102     QColor c = def;
00103     SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
00104     if ( mgr )
00105       c = mgr->colorValue( theSect, theName, def );
00106     return c;
00107   }
00108 
00109   void
00110   GetColor( const QString& theSect, 
00111             const QString& theName, 
00112             int& r, 
00113             int& g, 
00114             int& b, 
00115             const QColor& def )
00116   {
00117     QColor c = def;
00118     SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
00119     if ( mgr )
00120       c = mgr->colorValue( theSect, theName, def );
00121 
00122     SUIT_Tools::rgbSet( SUIT_Tools::rgbSet( c ), r, g, b );
00123   }
00124 
00125   void
00126   GetColor( const QString& theSect, 
00127             const QString& theName, 
00128             vtkFloatingPointType& r, 
00129             vtkFloatingPointType& g, 
00130             vtkFloatingPointType& b, 
00131             const QColor& def )
00132   {
00133     int ir( 0 ), ig( 0 ), ib( 0 );
00134     GetColor( theSect, theName, ir, ig, ib, def );
00135     r = ir / 255.;
00136     g = ig / 255.;
00137     b = ib / 255.;
00138   }
00139 
00140 #ifndef DISABLE_PLOT2DVIEWER
00141   //=======================================================================
00146   //=======================================================================
00147   void ProcessIn2DViewers( SMESH_Actor *theActor, Viewer2dActionType aType ) {
00148     SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>(SUIT_Session::session()->activeApplication());
00149     
00150     if(!anApp || !theActor)
00151       return;
00152     
00153     SPlot2d_Histogram* aHistogram = 0;
00154     
00155     if(theActor->GetPlot2Histogram())
00156       if(aType == UpdateIn2dViewer)
00157         aHistogram = theActor->UpdatePlot2Histogram();
00158       else
00159         aHistogram = theActor->GetPlot2Histogram();
00160     else 
00161       return;
00162     
00163     ViewManagerList aViewManagerList;
00164     anApp->viewManagers(SPlot2d_Viewer::Type(), aViewManagerList);
00165     
00166     aType = aHistogram->getPointList().empty() ? RemoveFrom2dViewer : aType;
00167     
00168     SUIT_ViewManager* aViewManager;
00169     foreach( aViewManager, aViewManagerList ) {
00170       if (Plot2d_ViewManager* aManager = dynamic_cast<Plot2d_ViewManager*>(aViewManager)) {
00171         if (SPlot2d_Viewer* aViewer = dynamic_cast<SPlot2d_Viewer*>(aManager->getViewModel())) {
00172           if (Plot2d_ViewFrame* aViewFrame = aViewer->getActiveViewFrame()) {
00173             if(aType == UpdateIn2dViewer )
00174               aViewFrame->displayObject(aHistogram, true);
00175             else if (aType == RemoveFrom2dViewer)
00176               aViewFrame->eraseObject(aHistogram, true);
00177           }
00178         }
00179       }
00180     }
00181   }
00182 #endif //DISABLE_PLOT2DVIEWER
00183   
00184 }
Copyright © 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
Copyright © 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS