1 // Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "SMESH_ActorUtils.h"
24 #include "SMESH_Actor.h"
26 #include "SUIT_Tools.h"
27 #include "SUIT_Session.h"
28 #include "SUIT_ResourceMgr.h"
29 #include <SALOMEconfig.h> // To fix some redefinition
30 #include "SalomeApp_Application.h"
32 #ifndef DISABLE_PLOT2DVIEWER
33 #include <SPlot2d_ViewModel.h>
34 #include <SPlot2d_Histogram.h>
35 #include <Plot2d_ViewManager.h>
39 #include "utilities.h"
41 #include <vtkUnstructuredGrid.h>
42 #include <vtkXMLUnstructuredGridWriter.h>
43 #include <vtkUnstructuredGridWriter.h>
46 static int MYDEBUG = 1;
48 static int MYDEBUG = 0;
55 GetFloat( const QString& theValue,
56 vtkFloatingPointType theDefault )
58 int pos = theValue.indexOf( ":" );
59 vtkFloatingPointType val = theDefault;
62 QString name = theValue.right( theValue.length()-pos-1 ),
63 sect = theValue.left( pos );
64 if( !name.isEmpty() && !sect.isEmpty() )
65 val = GetFloat( name, sect, theDefault );
71 GetFloat( const QString& theValue,
72 const QString& theSection,
73 vtkFloatingPointType theDefault )
75 vtkFloatingPointType val = theDefault;
76 SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
78 val = (vtkFloatingPointType) mgr->doubleValue( theSection, theValue, theDefault );
84 WriteUnstructuredGrid(vtkUnstructuredGrid* theGrid,
85 const char* theFileName)
87 vtkXMLUnstructuredGridWriter* aWriter = vtkXMLUnstructuredGridWriter::New();
88 aWriter->SetFileName(theFileName);
89 aWriter->SetInput(theGrid);
90 aWriter->SetDataModeToAscii();
91 if(theGrid->GetNumberOfCells()){
98 GetColor( const QString& theSect,
99 const QString& theName,
103 SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
105 c = mgr->colorValue( theSect, theName, def );
110 GetColor( const QString& theSect,
111 const QString& theName,
118 SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
120 c = mgr->colorValue( theSect, theName, def );
122 SUIT_Tools::rgbSet( SUIT_Tools::rgbSet( c ), r, g, b );
126 GetColor( const QString& theSect,
127 const QString& theName,
128 vtkFloatingPointType& r,
129 vtkFloatingPointType& g,
130 vtkFloatingPointType& b,
133 int ir( 0 ), ig( 0 ), ib( 0 );
134 GetColor( theSect, theName, ir, ig, ib, def );
140 #ifndef DISABLE_PLOT2DVIEWER
141 //=======================================================================
143 Get histogram from the input actor
144 Repaint/Remove the histogram in/from each opened Plot2D Viewer
146 //=======================================================================
147 void ProcessIn2DViewers( SMESH_Actor *theActor, Viewer2dActionType aType ) {
148 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>(SUIT_Session::session()->activeApplication());
150 if(!anApp || !theActor)
153 SPlot2d_Histogram* aHistogram = 0;
155 if(theActor->GetPlot2Histogram())
156 if(aType == UpdateIn2dViewer)
157 aHistogram = theActor->UpdatePlot2Histogram();
159 aHistogram = theActor->GetPlot2Histogram();
163 ViewManagerList aViewManagerList;
164 anApp->viewManagers(SPlot2d_Viewer::Type(), aViewManagerList);
166 aType = aHistogram->getPointList().empty() ? RemoveFrom2dViewer : aType;
168 SUIT_ViewManager* aViewManager;
169 foreach( aViewManager, aViewManagerList ) {
170 if (Plot2d_ViewManager* aManager = dynamic_cast<Plot2d_ViewManager*>(aViewManager)) {
171 if (SPlot2d_Viewer* aViewer = dynamic_cast<SPlot2d_Viewer*>(aManager->getViewModel())) {
172 if (Plot2d_ViewFrame* aViewFrame = aViewer->getActiveViewFrame()) {
173 if(aType == UpdateIn2dViewer )
174 aViewFrame->displayObject(aHistogram, true);
175 else if (aType == RemoveFrom2dViewer)
176 aViewFrame->eraseObject(aHistogram, true);
182 #endif //DISABLE_PLOT2DVIEWER