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();
353 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>(aSession->activeApplication());
357 SUIT_ViewManager* aManager = anApp->activeViewManager();
362 bool is2dViewActive = aManager->getType() == SPlot2d_Viewer::Type();
364 Qtx::VisibilityState state = is2dViewActive ? GetStateByDisplaying(theDisplaying) : Qtx::UnpresentableState;
367 SetVisibilityState(theCurve->GetEntry(), state);
370 Table_i* aTable = theCurve->getTable();
372 if( SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(anApp->activeStudy()) ) {
373 _PTR(SObject) TableSO = aStudy->studyDS()->FindObjectID( aTable->GetEntry() );
375 _PTR(ChildIterator) Iter = aStudy->studyDS()->NewChildIterator( TableSO );
376 bool isTableVisible = false;
377 LightApp_Displayer* aDisplayer = (dynamic_cast<SalomeApp_Module*>(anApp->activeModule()))->displayer();
378 if(aDisplayer && state != Qtx::UnpresentableState ) {
379 for ( ; Iter->More(); Iter->Next() ) {
380 CORBA::Object_var childObject = VISU::ClientSObjectToObject( Iter->Value() );
381 if( !CORBA::is_nil( childObject ) ) {
382 CORBA::Object_ptr aCurve_ptr = VISU::Curve::_narrow( childObject );
383 if( !CORBA::is_nil( aCurve_ptr ) ) {
384 VISU::Curve_i* aCurve = dynamic_cast<VISU::Curve_i*>(VISU::GetServant(aCurve_ptr).in());
385 if(aDisplayer->IsDisplayed(aCurve->GetEntry().c_str())) {
386 isTableVisible = true;
389 } //!CORBA::is_nil( aCurve )
390 } // !CORBA::is_nil( childObject )
392 if(state != Qtx::UnpresentableState)
393 SetVisibilityState(aTable->GetEntry(), (isTableVisible ? Qtx::ShownState : Qtx::HiddenState));
395 SetVisibilityState(aTable->GetEntry(), state);
402 if(updateContainers) {
403 if( SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(anApp->activeStudy()) ) {
404 if(LightApp_Displayer* aDisplayer = (dynamic_cast<SalomeApp_Module*>(anApp->activeModule()))->displayer()) {
405 ContainerSet aContainers = theCurve->getContainers();
406 ContainerSet::ConstIterator it = aContainers.begin();
407 for(;it != aContainers.end();it++ ) {
408 if(state != Qtx::UnpresentableState) {
409 bool isContainerDisplayed = false;
410 _PTR(SObject) aSObject = aStudy->studyDS()->FindObjectID( (*it).toLatin1().data());
411 CORBA::Object_var anObj = VISU::ClientSObjectToObject( aSObject );
412 if( !CORBA::is_nil( anObj ) ) {
413 if(VISU::Container_i* aContainer = dynamic_cast<VISU::Container_i*>( VISU::GetServant( anObj ).in())) {
414 int nbCurves = aContainer->GetNbCurves();
415 for( int k=1; k<=nbCurves; k++ ) {
416 VISU::Curve_i* aCurve = aContainer->GetCurve( k );
417 if(aCurve && aDisplayer->IsDisplayed(aCurve->GetEntry().c_str())) {
418 isContainerDisplayed = true;
420 } // aCurve && aDisplater->IsDisplayed
422 SetVisibilityState(aContainer->GetEntry(), (isContainerDisplayed ? Qtx::ShownState : Qtx::HiddenState));
424 } //!CORBA::is_nil( anObj )
425 } //state != Qtx::UnpresentableState
427 SetVisibilityState((*it).toLatin1().data(), state);
435 Qtx::VisibilityState GetStateByDisplaying(int theDisplaying) {
437 Qtx::VisibilityState state = Qtx::UnpresentableState;
438 if(theDisplaying == eDisplayAll ||
439 theDisplaying == eDisplay ||
440 theDisplaying == eDisplayOnly ) {
441 state = Qtx::ShownState;
443 } else if (theDisplaying == eErase || theDisplaying == eEraseAll) {
444 state = Qtx::HiddenState;
449 void updateContainerVisibility(VISU::Container_i* theContainer) {
453 if( SUIT_Session* aSession = SUIT_Session::session() ) {
454 if( SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>(aSession->activeApplication()) ) {
455 if( SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(anApp->activeStudy()) ) {
456 Qtx::VisibilityState state = Qtx::UnpresentableState;
457 int nbCurves = theContainer->GetNbCurves();
459 if(LightApp_Displayer* aDisplayer = (dynamic_cast<SalomeApp_Module*>(anApp->activeModule()))->displayer()) {
460 for( int k=1; k<=nbCurves; k++ ) {
461 VISU::Curve_i* aCurve = theContainer->GetCurve( k );
462 if(aCurve && aDisplayer->IsDisplayed(aCurve->GetEntry().c_str())) {
463 state = Qtx::ShownState;
467 if ( state == Qtx::UnpresentableState) {
468 if( SUIT_ViewManager * vm = anApp->activeViewManager()){
469 if(vm->getType() == SPlot2d_Viewer::Type()) {
470 state = Qtx::HiddenState;
475 } else if(SUIT_ViewManager * vm = anApp->activeViewManager()){
476 if(vm->getType() == SPlot2d_Viewer::Type()) {
477 state = Qtx::HiddenState;
480 aStudy->setVisibilityState(theContainer->GetEntry().c_str(),state);