Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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>
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
00046
00047
00048
00049
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 }