1 // Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // File : VISU_Tools.cxx
21 // Author : Oleg UVAROV
24 #include "VISU_Tools.h"
26 #include "VISU_Gen_i.hh"
27 #include "VISU_Table_i.hh"
28 #include "VISU_ViewManager_i.hh"
30 #include <VISU_ActorBase.h>
32 #include <LightApp_Displayer.h>
34 #include <SalomeApp_Study.h>
35 #include <SalomeApp_Application.h>
36 #include <SalomeApp_Module.h>
38 #include <SPlot2d_ViewModel.h>
39 #include <Plot2d_ViewFrame.h>
40 #include <Plot2d_ViewManager.h>
42 #include <SUIT_ResourceMgr.h>
43 #include <SUIT_Session.h>
45 //=============================================================================
48 //------------------------------------------------------------
49 // Internal function used by several public functions below
51 UpdateCurve(VISU::Curve_i* theCurve,
52 Plot2d_ViewFrame* thePlot,
53 SPlot2d_Curve* plotCurve,
56 if ( theDisplaying == VISU::eErase ) {
57 if ( plotCurve && thePlot )
58 thePlot->eraseCurve( plotCurve, false );
60 else if ( theDisplaying == VISU::eDisplay || theDisplaying == VISU::eDisplayOnly ) {
62 plotCurve->setHorTitle( theCurve->GetHorTitle().c_str() );
63 //plotCurve->setVerTitle( ( theCurve->GetVerTitle().c_str() ) );
64 plotCurve->setVerTitle( theCurve->GetName().c_str() );
65 plotCurve->setHorUnits( theCurve->GetHorUnits().c_str() );
66 plotCurve->setVerUnits( theCurve->GetVerUnits().c_str() );
70 int nbPoints = theCurve->GetData( xList, yList, zList );
71 if ( nbPoints > 0 && xList && yList ) {
72 plotCurve->setData( xList, yList, nbPoints, zList );
74 if ( !theCurve->IsAuto() ) {
75 plotCurve->setLine( (Plot2d::LineType)theCurve->GetLine(), theCurve->GetLineWidth() );
76 plotCurve->setMarker( (Plot2d::MarkerType)theCurve->GetMarker() );
77 SALOMEDS::Color color = theCurve->GetColor();
78 plotCurve->setColor( QColor( (int)(color.R*255.), (int)(color.G*255.), (int)(color.B*255.) ) );
80 plotCurve->setAutoAssign( theCurve->IsAuto() );
82 thePlot->displayCurve( plotCurve, false );
85 Plot2d_Curve* crv = theCurve->CreatePresentation();
88 thePlot->displayCurve( crv, false );
89 theCurve->SetLine( (VISU::Curve::LineType)crv->getLine(), crv->getLineWidth() );
90 theCurve->SetMarker( (VISU::Curve::MarkerType)crv->getMarker());
91 SALOMEDS::Color newColor;
92 newColor.R = crv->getColor().red()/255.;
93 newColor.G = crv->getColor().green()/255.;
94 newColor.B = crv->getColor().blue()/255.;
95 theCurve->SetColor( newColor );
96 crv->setAutoAssign( theCurve->IsAuto() );
102 //------------------------------------------------------------
104 PlotTable(SalomeApp_Study* theStudy,
105 Plot2d_ViewFrame* thePlot,
106 VISU::Table_i* table,
112 if ( theDisplaying == VISU::eDisplayOnly )
114 QList<Plot2d_Curve*> clist;
115 thePlot->getCurves( clist );
116 _PTR(Study) aStudy = theStudy->studyDS();
117 _PTR(SObject) TableSO = aStudy->FindObjectID( table->GetEntry() );
119 _PTR(ChildIterator) Iter = aStudy->NewChildIterator( TableSO );
120 for ( ; Iter->More(); Iter->Next() ) {
121 CORBA::Object_var childObject = VISU::ClientSObjectToObject( Iter->Value() );
122 if( !CORBA::is_nil( childObject ) ) {
123 CORBA::Object_ptr aCurve = VISU::Curve::_narrow( childObject );
124 if( !CORBA::is_nil( aCurve ) ) {
125 VISU::Curve_i* theCurve = dynamic_cast<VISU::Curve_i*>(VISU::GetServant(aCurve).in());
126 SPlot2d_Curve* plotCurve = 0;
127 SPlot2d_Curve* tmpCurve;
128 for ( int i = 0; i < clist.count(); i++ ) {
129 tmpCurve = dynamic_cast<SPlot2d_Curve*>( clist.at( i ) );
130 if (tmpCurve && tmpCurve->hasIO() &&
131 theCurve->GetEntry() == tmpCurve->getIO()->getEntry()) {
132 plotCurve = tmpCurve;
137 UpdateCurve( theCurve, thePlot, plotCurve, theDisplaying );
138 CurveVisibilityChanged(theCurve, theDisplaying, true, false, true);
140 if ( theDisplaying == VISU::eErase && plotCurve ) {
141 clist.removeAll(plotCurve );
147 SetVisibilityState(table->GetEntry(),GetStateByDisplaying(theDisplaying));
152 //------------------------------------------------------------
154 PlotCurve(Plot2d_ViewFrame* thePlot,
155 VISU::Curve_i* theCurve,
161 // if ( theDisplaying == VISU::eDisplayOnly )
162 // thePlot->EraseAll();
163 QList<Plot2d_Curve*> clist;
164 thePlot->getCurves( clist );
165 SPlot2d_Curve* plotCurve = 0;
166 SPlot2d_Curve* tmpCurve;
167 if(theDisplaying == VISU::eErase) {
168 // 23.06.2008 skl for IPAL17672
169 for (int i = 0; i < clist.count(); i++) {
170 tmpCurve = dynamic_cast<SPlot2d_Curve*>(clist.at(i));
171 if (tmpCurve && tmpCurve->hasIO() &&
172 theCurve->GetEntry() == tmpCurve->getIO()->getEntry()) {
173 plotCurve = tmpCurve;
174 thePlot->eraseCurve(clist.at(i));
178 UpdateCurve(theCurve, thePlot, plotCurve, theDisplaying);
181 for (int i = 0; i < clist.count(); i++) {
182 tmpCurve = dynamic_cast<SPlot2d_Curve*>(clist.at(i));
183 if (tmpCurve && tmpCurve->hasIO() &&
184 theCurve->GetEntry() == tmpCurve->getIO()->getEntry()) {
185 plotCurve = tmpCurve;
187 else if (theDisplaying == VISU::eDisplayOnly) {
188 thePlot->eraseCurve(clist.at(i));
191 UpdateCurve(theCurve, thePlot, plotCurve, theDisplaying);
196 SetVisibilityState(theCurve->GetEntry(),GetStateByDisplaying(theDisplaying));
197 CurveVisibilityChanged(theCurve,theDisplaying,false, true, true);
200 //------------------------------------------------------------
202 PlotRemoveCurve(SalomeApp_Application* theApp,
205 QString anEntry = pCrv->GetEntry().c_str();
206 ViewManagerList pvm_list;
207 theApp->viewManagers( SPlot2d_Viewer::Type(), pvm_list );
208 ViewManagerList::Iterator pvm_it = pvm_list.begin();
209 for( ; pvm_it != pvm_list.end(); pvm_it++ ){
210 Plot2d_ViewManager* pvm = dynamic_cast<Plot2d_ViewManager*>( *pvm_it );
212 SPlot2d_Viewer* aSPlot2d = dynamic_cast<SPlot2d_Viewer*>( pvm->getViewModel() );
214 Plot2d_ViewFrame* thePlot = aSPlot2d->getActiveViewFrame();
216 QList<Plot2d_Curve*> clist;
217 thePlot->getCurves( clist );
218 for (int i = 0; i < clist.count(); i++) {
219 if(SPlot2d_Curve* plotCurve = dynamic_cast<SPlot2d_Curve*>(clist[i]))
220 if(plotCurve->hasIO() && (plotCurve->getIO()->getEntry() == anEntry))
221 thePlot->eraseCurve(clist[i]);
229 //------------------------------------------------------------
230 // Internal function used by the function below
231 SPlot2d_Curve* GetCurveByIO( const Handle(SALOME_InteractiveObject)& theIObject,
232 Plot2d_ViewFrame* thePlot )
234 if ( !theIObject.IsNull() && thePlot ) {
235 CurveDict aCurves = thePlot->getCurves();
236 CurveDict::Iterator it = aCurves.begin();
237 for( ; it != aCurves.end(); ++it ) {
238 SPlot2d_Curve* aCurve = dynamic_cast<SPlot2d_Curve*>( it.value() );
240 if ( aCurve->hasIO() && aCurve->getIO()->isSame( theIObject ) )
248 //------------------------------------------------------------
250 PlotContainer(Plot2d_ViewFrame* thePlot,
251 VISU::Container_i* container,
257 if ( theDisplaying == VISU::eDisplayOnly )
259 QList<Plot2d_Curve*> clist;
260 thePlot->getCurves( clist );
261 if ( container->GetNbCurves() > 0 ) {
262 int nbCurves = container->GetNbCurves();
263 for ( int k = 1; k <= nbCurves; k++ ) {
264 VISU::Curve_i* theCurve = container->GetCurve( k );
265 if ( theCurve && theCurve->IsValid() ) {
266 SPlot2d_Curve* plotCurve = GetCurveByIO(new SALOME_InteractiveObject(theCurve->GetEntry().c_str(), "", ""), thePlot);
268 UpdateCurve( theCurve, thePlot, plotCurve, theDisplaying );
270 if ( plotCurve && theDisplaying == VISU::eErase ) {
271 clist.removeAll( plotCurve );
273 CurveVisibilityChanged(theCurve, theDisplaying, true, true, true);
279 if(GetResourceMgr()->booleanValue("VISU","automatic_fit_all",false)){
283 qApp->processEvents();
286 //------------------------------------------------------------
288 CreatePlot(VISU_Gen_i* theVisuGen,
289 Plot2d_ViewFrame* thePlot,
290 _PTR(SObject) theTableSO)
292 _PTR(GenericAttribute) anAttr;
294 ( theTableSO->FindAttribute( anAttr, "AttributeTableOfInteger" ) ||
295 theTableSO->FindAttribute( anAttr, "AttributeTableOfReal" ) ) ) {
296 CORBA::Object_var aTable = VISU::ClientSObjectToObject(theTableSO);
297 CORBA::Object_var aContainer = theVisuGen->CreateContainer();
299 if ( !CORBA::is_nil( aTable ) && !CORBA::is_nil( aContainer ) ) {
300 VISU::Table_i* pTable = dynamic_cast<VISU::Table_i*>(VISU::GetServant(aTable).in());
301 VISU::Container_i* pContainer = dynamic_cast<VISU::Container_i*>(VISU::GetServant(aContainer).in());
303 if ( pContainer && pTable ) {
304 for ( int i = 2; i <= pTable->GetNbRows(); i++ ) {
305 CORBA::Object_var aNewCurve = theVisuGen->CreateCurve( pTable->_this(), 1, i );
306 if( !CORBA::is_nil( aNewCurve ) ) {
307 VISU::Curve_i* pCrv = dynamic_cast<VISU::Curve_i*>( VISU::GetServant(aNewCurve).in() );
309 pContainer->AddCurve( pCrv->_this() );
313 PlotContainer( thePlot, pContainer, VISU::eDisplay );
315 QString anEntry = pContainer->GetEntry().c_str();
316 _PTR(Study) aStudy = theTableSO->GetStudy();
317 _PTR(SObject) aContainerSO = aStudy->FindObjectID(anEntry.toLatin1().data());
318 _PTR(SObject) aParentSO = aContainerSO->GetFather();
324 //------------------------------------------------------------
325 void SetVisibilityState(std::string entry, Qtx::VisibilityState state) {
329 if( SUIT_Session* aSession = SUIT_Session::session() )
330 if( SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>(aSession->activeApplication()) )
331 if( SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(anApp->activeStudy()) )
332 aStudy->setVisibilityState(entry.c_str(), state);
336 //------------------------------------------------------------
337 void SetVisibilityState(VISU_ActorBase *theActor, Qtx::VisibilityState state) {
338 if(!theActor || theActor->hasIO() || !theActor->getIO()->hasEntry())
340 SetVisibilityState(theActor->getIO()->getEntry(), state);
343 void CurveVisibilityChanged(VISU::Curve_i* theCurve,
347 bool updateContainers) {
349 SUIT_Session* aSession = SUIT_Session::session();
350 if (!aSession) return;
352 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>(aSession->activeApplication());
353 if ( !anApp ) return;
355 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
356 if ( !aStudy ) return;
358 SalomeApp_Module* aModule = dynamic_cast<SalomeApp_Module*>( anApp->module( anApp->moduleTitle( "VISU" ) ) );
359 if ( !aModule ) return;
361 LightApp_Displayer* aDisplayer = aModule->displayer();
363 SUIT_ViewManager* aManager = anApp->activeViewManager();
365 Qtx::VisibilityState state = ( aManager && aManager->getType() == SPlot2d_Viewer::Type() ) ?
366 GetStateByDisplaying(theDisplaying) : Qtx::UnpresentableState;
369 SetVisibilityState( theCurve->GetEntry(), state );
372 Table_i* aTable = theCurve->getTable();
374 _PTR(SObject) TableSO = aStudy->studyDS()->FindObjectID( aTable->GetEntry() );
376 bool isTableVisible = false;
377 if ( aDisplayer && state != Qtx::UnpresentableState ) {
378 _PTR(ChildIterator) Iter = aStudy->studyDS()->NewChildIterator( TableSO );
379 for ( ; Iter->More() && !isTableVisible ; Iter->Next() ) {
380 CORBA::Object_var childObject = VISU::ClientSObjectToObject( Iter->Value() );
381 if ( CORBA::is_nil( childObject ) ) continue;
382 VISU::Curve_i* aCurve = dynamic_cast<VISU::Curve_i*>( VISU::GetServant( childObject.in() ).in() );
383 isTableVisible = aCurve && aDisplayer->IsDisplayed( aCurve->GetEntry().c_str() );
385 } // if ( aDisplayer ... )
386 if ( state != Qtx::UnpresentableState )
387 SetVisibilityState( aTable->GetEntry(), ( isTableVisible ? Qtx::ShownState : Qtx::HiddenState ) );
389 SetVisibilityState( aTable->GetEntry(), state );
392 } // if ( updateTable )
394 if ( updateContainers ) {
395 ContainerSet aContainers = theCurve->getContainers();
396 ContainerSet::ConstIterator it = aContainers.begin();
397 for ( ; it != aContainers.end(); it++ ) {
398 _PTR(SObject) aSObject = aStudy->studyDS()->FindObjectID( (*it).toLatin1().data() );
399 if ( !aSObject ) continue;
400 bool isContainerDisplayed = false;
401 if ( aDisplayer && state != Qtx::UnpresentableState ) {
402 CORBA::Object_var anObj = VISU::ClientSObjectToObject( aSObject );
403 if ( CORBA::is_nil( anObj ) ) continue;
404 VISU::Container_i* aContainer = dynamic_cast<VISU::Container_i*>( VISU::GetServant( anObj.in() ).in() );
405 if ( !aContainer ) continue;
406 int nbCurves = aContainer->GetNbCurves();
407 for ( int k = 1; k <= nbCurves && !isContainerDisplayed; k++ ) {
408 VISU::Curve_i* aCurve = aContainer->GetCurve( k );
409 isContainerDisplayed = aCurve && aDisplayer->IsDisplayed( aCurve->GetEntry().c_str() );
411 } // if ( aDisplayer ... )
412 if ( state != Qtx::UnpresentableState )
413 SetVisibilityState( (*it).toLatin1().constData(), ( isContainerDisplayed ? Qtx::ShownState : Qtx::HiddenState ) );
415 SetVisibilityState( (*it).toLatin1().constData(), state );
417 } // for ( ; it != aContainers.end(); it++ )
421 Qtx::VisibilityState GetStateByDisplaying(int theDisplaying)
423 Qtx::VisibilityState state = Qtx::UnpresentableState;
424 if(theDisplaying == eDisplayAll ||
425 theDisplaying == eDisplay ||
426 theDisplaying == eDisplayOnly ) {
427 state = Qtx::ShownState;
429 } else if (theDisplaying == eErase || theDisplaying == eEraseAll) {
430 state = Qtx::HiddenState;
435 void updateContainerVisibility(VISU::Container_i* theContainer)
437 if ( !theContainer ) return;
439 SUIT_Session* aSession = SUIT_Session::session();
440 if (!aSession) return;
442 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>(aSession->activeApplication());
443 if ( !anApp ) return;
445 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
446 if ( !aStudy ) return;
448 SalomeApp_Module* aModule = dynamic_cast<SalomeApp_Module*>( anApp->module( "VISU" ) );
449 if ( !aModule ) return;
451 SUIT_ViewManager* aManager = anApp->activeViewManager();
452 Qtx::VisibilityState state = ( aManager && aManager->getType() == SPlot2d_Viewer::Type() ) ?
453 Qtx::HiddenState : Qtx::UnpresentableState;
455 LightApp_Displayer* aDisplayer = aModule->displayer();
457 int nbCurves = theContainer->GetNbCurves();
458 if ( nbCurves > 0 && aDisplayer ) {
459 for ( int k = 1; k <= nbCurves; k++ ) {
460 VISU::Curve_i* aCurve = theContainer->GetCurve( k );
461 if ( aCurve && aDisplayer->IsDisplayed( aCurve->GetEntry().c_str() ) ) {
462 state = Qtx::ShownState;
467 aStudy->setVisibilityState( theContainer->GetEntry().c_str(), state );