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 "SalomeApp_Application.h"
31 #ifndef DISABLE_PLOT2DVIEWER
32 #include <SPlot2d_ViewModel.h>
33 #include <SPlot2d_Histogram.h>
34 #include <Plot2d_ViewManager.h>
38 #include "utilities.h"
40 #include <vtkUnstructuredGrid.h>
41 #include <vtkXMLUnstructuredGridWriter.h>
42 #include <vtkUnstructuredGridWriter.h>
45 static int MYDEBUG = 1;
47 static int MYDEBUG = 0;
54 GetFloat( const QString& theValue,
55 vtkFloatingPointType theDefault )
57 int pos = theValue.indexOf( ":" );
58 vtkFloatingPointType val = theDefault;
61 QString name = theValue.right( theValue.length()-pos-1 ),
62 sect = theValue.left( pos );
63 if( !name.isEmpty() && !sect.isEmpty() )
64 val = GetFloat( name, sect, theDefault );
70 GetFloat( const QString& theValue,
71 const QString& theSection,
72 vtkFloatingPointType theDefault )
74 vtkFloatingPointType val = theDefault;
75 SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
77 val = (vtkFloatingPointType) mgr->doubleValue( theSection, theValue, theDefault );
83 WriteUnstructuredGrid(vtkUnstructuredGrid* theGrid,
84 const char* theFileName)
86 vtkXMLUnstructuredGridWriter* aWriter = vtkXMLUnstructuredGridWriter::New();
87 aWriter->SetFileName(theFileName);
88 aWriter->SetInput(theGrid);
89 aWriter->SetDataModeToAscii();
90 if(theGrid->GetNumberOfCells()){
97 GetColor( const QString& theSect,
98 const QString& theName,
102 SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
104 c = mgr->colorValue( theSect, theName, def );
109 GetColor( const QString& theSect,
110 const QString& theName,
117 SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
119 c = mgr->colorValue( theSect, theName, def );
121 SUIT_Tools::rgbSet( SUIT_Tools::rgbSet( c ), r, g, b );
125 GetColor( const QString& theSect,
126 const QString& theName,
127 vtkFloatingPointType& r,
128 vtkFloatingPointType& g,
129 vtkFloatingPointType& b,
132 int ir( 0 ), ig( 0 ), ib( 0 );
133 GetColor( theSect, theName, ir, ig, ib, def );
139 #ifndef DISABLE_PLOT2DVIEWER
140 //=======================================================================
142 Get histogram from the input actor
143 Repaint/Remove the histogram in/from each opened Plot2D Viewer
145 //=======================================================================
146 void ProcessIn2DViewers( SMESH_Actor *theActor, Viewer2dActionType aType ) {
147 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>(SUIT_Session::session()->activeApplication());
149 if(!anApp || !theActor)
152 SPlot2d_Histogram* aHistogram = 0;
154 if(theActor->GetPlot2Histogram())
155 if(aType == UpdateIn2dViewer)
156 aHistogram = theActor->UpdatePlot2Histogram();
158 aHistogram = theActor->GetPlot2Histogram();
162 ViewManagerList aViewManagerList;
163 anApp->viewManagers(SPlot2d_Viewer::Type(), aViewManagerList);
165 aType = aHistogram->getPointList().empty() ? RemoveFrom2dViewer : aType;
167 SUIT_ViewManager* aViewManager;
168 foreach( aViewManager, aViewManagerList ) {
169 if (Plot2d_ViewManager* aManager = dynamic_cast<Plot2d_ViewManager*>(aViewManager)) {
170 if (SPlot2d_Viewer* aViewer = dynamic_cast<SPlot2d_Viewer*>(aManager->getViewModel())) {
171 if (Plot2d_ViewFrame* aViewFrame = aViewer->getActiveViewFrame()) {
172 if(aType == UpdateIn2dViewer )
173 aViewFrame->displayObject(aHistogram, true);
174 else if (aType == RemoveFrom2dViewer)
175 aViewFrame->eraseObject(aHistogram, true);
181 #endif //DISABLE_PLOT2DVIEWER