1 // Copyright (C) 2007-2008 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
22 // File : VISU_Tools.cxx
23 // Author : Oleg UVAROV
26 #include "VISU_Tools.h"
28 #include "VISU_Gen_i.hh"
29 #include "VISU_Table_i.hh"
30 #include "VISU_ViewManager_i.hh"
32 #include <SalomeApp_Study.h>
33 #include <SalomeApp_Application.h>
35 #include <SPlot2d_ViewModel.h>
36 #include <Plot2d_ViewFrame.h>
37 #include <Plot2d_ViewManager.h>
39 #include <SUIT_ResourceMgr.h>
41 //=============================================================================
44 //------------------------------------------------------------
45 // Internal function used by several public functions below
47 UpdateCurve(VISU::Curve_i* theCurve,
48 Plot2d_ViewFrame* thePlot,
49 SPlot2d_Curve* plotCurve,
52 if ( theDisplaying == VISU::eErase ) {
53 if ( plotCurve && thePlot )
54 thePlot->eraseCurve( plotCurve, false );
56 else if ( theDisplaying == VISU::eDisplay || theDisplaying == VISU::eDisplayOnly ) {
58 plotCurve->setHorTitle( theCurve->GetHorTitle().c_str() );
59 //plotCurve->setVerTitle( ( theCurve->GetVerTitle().c_str() ) );
60 plotCurve->setVerTitle( theCurve->GetName().c_str() );
61 plotCurve->setHorUnits( theCurve->GetHorUnits().c_str() );
62 plotCurve->setVerUnits( theCurve->GetVerUnits().c_str() );
66 int nbPoints = theCurve->GetData( xList, yList, zList );
67 if ( nbPoints > 0 && xList && yList ) {
68 plotCurve->setData( xList, yList, nbPoints, zList );
70 if ( !theCurve->IsAuto() ) {
71 plotCurve->setLine( (Plot2d::LineType)theCurve->GetLine(), theCurve->GetLineWidth() );
72 plotCurve->setMarker( (Plot2d::MarkerType)theCurve->GetMarker() );
73 SALOMEDS::Color color = theCurve->GetColor();
74 plotCurve->setColor( QColor( (int)(color.R*255.), (int)(color.G*255.), (int)(color.B*255.) ) );
76 plotCurve->setAutoAssign( theCurve->IsAuto() );
78 thePlot->displayCurve( plotCurve, false );
81 Plot2d_Curve* crv = theCurve->CreatePresentation();
84 thePlot->displayCurve( crv, false );
85 theCurve->SetLine( (VISU::Curve::LineType)crv->getLine(), crv->getLineWidth() );
86 theCurve->SetMarker( (VISU::Curve::MarkerType)crv->getMarker());
87 SALOMEDS::Color newColor;
88 newColor.R = crv->getColor().red()/255.;
89 newColor.G = crv->getColor().green()/255.;
90 newColor.B = crv->getColor().blue()/255.;
91 theCurve->SetColor( newColor );
92 crv->setAutoAssign( theCurve->IsAuto() );
98 //------------------------------------------------------------
100 PlotTable(SalomeApp_Study* theStudy,
101 Plot2d_ViewFrame* thePlot,
102 VISU::Table_i* table,
108 if ( theDisplaying == VISU::eDisplayOnly )
110 QList<Plot2d_Curve*> clist;
111 thePlot->getCurves( clist );
112 _PTR(Study) aStudy = theStudy->studyDS();
113 _PTR(SObject) TableSO = aStudy->FindObjectID( table->GetEntry() );
115 _PTR(ChildIterator) Iter = aStudy->NewChildIterator( TableSO );
116 for ( ; Iter->More(); Iter->Next() ) {
117 CORBA::Object_var childObject = VISU::ClientSObjectToObject( Iter->Value() );
118 if( !CORBA::is_nil( childObject ) ) {
119 CORBA::Object_ptr aCurve = VISU::Curve::_narrow( childObject );
120 if( !CORBA::is_nil( aCurve ) ) {
121 VISU::Curve_i* theCurve = dynamic_cast<VISU::Curve_i*>(VISU::GetServant(aCurve).in());
122 SPlot2d_Curve* plotCurve = 0;
123 SPlot2d_Curve* tmpCurve;
124 for ( int i = 0; i < clist.count(); i++ ) {
125 tmpCurve = dynamic_cast<SPlot2d_Curve*>( clist.at( i ) );
126 if (tmpCurve && tmpCurve->hasIO() &&
127 theCurve->GetEntry() == tmpCurve->getIO()->getEntry()) {
128 plotCurve = tmpCurve;
133 UpdateCurve( theCurve, thePlot, plotCurve, theDisplaying );
135 if ( theDisplaying == VISU::eErase && plotCurve ) {
136 clist.removeAll(plotCurve );
145 //------------------------------------------------------------
147 PlotCurve(Plot2d_ViewFrame* thePlot,
148 VISU::Curve_i* theCurve,
154 // if ( theDisplaying == VISU::eDisplayOnly )
155 // thePlot->EraseAll();
156 QList<Plot2d_Curve*> clist;
157 thePlot->getCurves( clist );
158 SPlot2d_Curve* plotCurve = 0;
159 SPlot2d_Curve* tmpCurve;
160 if(theDisplaying == VISU::eErase) {
161 // 23.06.2008 skl for IPAL17672
162 for (int i = 0; i < clist.count(); i++) {
163 tmpCurve = dynamic_cast<SPlot2d_Curve*>(clist.at(i));
164 if (tmpCurve && tmpCurve->hasIO() &&
165 theCurve->GetEntry() == tmpCurve->getIO()->getEntry()) {
166 plotCurve = tmpCurve;
167 thePlot->eraseCurve(clist.at(i));
171 UpdateCurve(theCurve, thePlot, plotCurve, theDisplaying);
174 for (int i = 0; i < clist.count(); i++) {
175 tmpCurve = dynamic_cast<SPlot2d_Curve*>(clist.at(i));
176 if (tmpCurve && tmpCurve->hasIO() &&
177 theCurve->GetEntry() == tmpCurve->getIO()->getEntry()) {
178 plotCurve = tmpCurve;
180 else if (theDisplaying == VISU::eDisplayOnly) {
181 thePlot->eraseCurve(clist.at(i));
184 UpdateCurve(theCurve, thePlot, plotCurve, theDisplaying);
190 //------------------------------------------------------------
192 PlotRemoveCurve(SalomeApp_Application* theApp,
195 QString anEntry = pCrv->GetEntry().c_str();
196 ViewManagerList pvm_list;
197 theApp->viewManagers( SPlot2d_Viewer::Type(), pvm_list );
198 ViewManagerList::Iterator pvm_it = pvm_list.begin();
199 for( ; pvm_it != pvm_list.end(); pvm_it++ ){
200 Plot2d_ViewManager* pvm = dynamic_cast<Plot2d_ViewManager*>( *pvm_it );
202 SPlot2d_Viewer* aSPlot2d = dynamic_cast<SPlot2d_Viewer*>( pvm->getViewModel() );
204 Plot2d_ViewFrame* thePlot = aSPlot2d->getActiveViewFrame();
206 QList<Plot2d_Curve*> clist;
207 thePlot->getCurves( clist );
208 for (int i = 0; i < clist.count(); i++) {
209 if(SPlot2d_Curve* plotCurve = dynamic_cast<SPlot2d_Curve*>(clist[i]))
210 if(plotCurve->hasIO() && (plotCurve->getIO()->getEntry() == anEntry))
211 thePlot->eraseCurve(clist[i]);
219 //------------------------------------------------------------
220 // Internal function used by the function below
221 SPlot2d_Curve* GetCurveByIO( const Handle(SALOME_InteractiveObject)& theIObject,
222 Plot2d_ViewFrame* thePlot )
224 if ( !theIObject.IsNull() && thePlot ) {
225 CurveDict aCurves = thePlot->getCurves();
226 CurveDict::Iterator it = aCurves.begin();
227 for( ; it != aCurves.end(); ++it ) {
228 SPlot2d_Curve* aCurve = dynamic_cast<SPlot2d_Curve*>( it.value() );
230 if ( aCurve->hasIO() && aCurve->getIO()->isSame( theIObject ) )
238 //------------------------------------------------------------
240 PlotContainer(Plot2d_ViewFrame* thePlot,
241 VISU::Container_i* container,
247 if ( theDisplaying == VISU::eDisplayOnly )
249 QList<Plot2d_Curve*> clist;
250 thePlot->getCurves( clist );
251 if ( container->GetNbCurves() > 0 ) {
252 int nbCurves = container->GetNbCurves();
253 for ( int k = 1; k <= nbCurves; k++ ) {
254 VISU::Curve_i* theCurve = container->GetCurve( k );
255 if ( theCurve && theCurve->IsValid() ) {
256 SPlot2d_Curve* plotCurve = GetCurveByIO(new SALOME_InteractiveObject(theCurve->GetEntry().c_str(), "", ""), thePlot);
258 UpdateCurve( theCurve, thePlot, plotCurve, theDisplaying );
260 if ( plotCurve && theDisplaying == VISU::eErase ) {
261 clist.removeAll( plotCurve );
267 if(GetResourceMgr()->booleanValue("VISU","automatic_fit_all",false)){
270 qApp->processEvents();
273 //------------------------------------------------------------
275 CreatePlot(VISU_Gen_i* theVisuGen,
276 Plot2d_ViewFrame* thePlot,
277 _PTR(SObject) theTableSO)
279 _PTR(GenericAttribute) anAttr;
281 ( theTableSO->FindAttribute( anAttr, "AttributeTableOfInteger" ) ||
282 theTableSO->FindAttribute( anAttr, "AttributeTableOfReal" ) ) ) {
283 CORBA::Object_var aTable = VISU::ClientSObjectToObject(theTableSO);
284 CORBA::Object_var aContainer = theVisuGen->CreateContainer();
286 if ( !CORBA::is_nil( aTable ) && !CORBA::is_nil( aContainer ) ) {
287 VISU::Table_i* pTable = dynamic_cast<VISU::Table_i*>(VISU::GetServant(aTable).in());
288 VISU::Container_i* pContainer = dynamic_cast<VISU::Container_i*>(VISU::GetServant(aContainer).in());
290 if ( pContainer && pTable ) {
291 for ( int i = 2; i <= pTable->GetNbRows(); i++ ) {
292 CORBA::Object_var aNewCurve = theVisuGen->CreateCurve( pTable->_this(), 1, i );
293 if( !CORBA::is_nil( aNewCurve ) ) {
294 VISU::Curve_i* pCrv = dynamic_cast<VISU::Curve_i*>( VISU::GetServant(aNewCurve).in() );
296 pContainer->AddCurve( pCrv->_this() );
300 PlotContainer( thePlot, pContainer, VISU::eDisplay );
302 QString anEntry = pContainer->GetEntry().c_str();
303 _PTR(Study) aStudy = theTableSO->GetStudy();
304 _PTR(SObject) aContainerSO = aStudy->FindObjectID(anEntry.toLatin1().data());
305 _PTR(SObject) aParentSO = aContainerSO->GetFather();