1 // Copyright (C) 2007-2012 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 // VISU VISUGUI : Displayer for VISU module
24 // File : VisuGUI_Displayer.cxx
25 // Author : Alexander SOLOVYOV
27 // $Header: /home/server/cvs/VISU/VISU_SRC/src/VISUGUI/VisuGUI_Displayer.cxx
29 #include "VisuGUI_Displayer.h"
32 #include "VisuGUI_Tools.h"
33 #include "VISU_Tools.h"
34 #include "VISU_ViewManager_i.hh"
35 #include "VISU_Actor.h"
37 #include <VISU_Table_i.hh>
39 //#include "VVTK_ViewModel.h"
41 #include <SVTK_ViewModel.h>
42 #include <SVTK_ViewWindow.h>
44 #include <SPlot2d_ViewModel.h>
45 #include <SPlot2d_Prs.h>
46 #include <Plot2d_ViewWindow.h>
48 #include <SalomeApp_Application.h>
49 #include <SalomeApp_Study.h>
51 #include <SUIT_ViewManager.h>
52 #include <SUIT_MessageBox.h>
53 #include <SUIT_Desktop.h>
57 void changeVisibility(int theDisplaying, QString entry, SalomeApp_Study* study)
59 _PTR(SObject) obj = study->studyDS()->FindObjectID( (const char*)entry.toLatin1() );
60 CORBA::Object_var anObj = VISU::ClientSObjectToObject( obj );
61 if( CORBA::is_nil( anObj ) )
64 if(VISU::Curve_i* aCurve = dynamic_cast<VISU::Curve_i*>( VISU::GetServant( anObj ).in()) ) {
65 VISU::CurveVisibilityChanged(aCurve,theDisplaying, false, true, true);
68 if(VISU::Container_i* aContainer = dynamic_cast<VISU::Container_i*>( VISU::GetServant( anObj ).in()) ) {
69 int nbCurves = aContainer->GetNbCurves();
70 for( int k=1; k<=nbCurves; k++ ) {
71 VISU::Curve_i* aCurve = aContainer->GetCurve( k );
73 VISU::CurveVisibilityChanged(aCurve,theDisplaying, true, true, true);
77 if(VISU::Table_i* aTable = dynamic_cast<VISU::Table_i*>( VISU::GetServant( anObj ).in()) ) {
78 _PTR(SObject) TableSO = study->studyDS()->FindObjectID( aTable->GetEntry() );
80 _PTR(ChildIterator) Iter = study->studyDS()->NewChildIterator( TableSO );
82 for ( ; Iter->More(); Iter->Next() ) {
83 CORBA::Object_var childObject = VISU::ClientSObjectToObject( Iter->Value() );
84 if( !CORBA::is_nil( childObject ) ) {
85 CORBA::Object_ptr aCurve_ptr = VISU::Curve::_narrow( childObject );
86 if( !CORBA::is_nil( aCurve_ptr ) ) {
87 VISU::Curve_i* aCurve = dynamic_cast<VISU::Curve_i*>(VISU::GetServant(aCurve_ptr).in());
89 VISU::CurveVisibilityChanged(aCurve,theDisplaying, true, false, true);
98 VisuGUI_Displayer::VisuGUI_Displayer( SalomeApp_Application* app )
99 : LightApp_Displayer(),
104 VisuGUI_Displayer::~VisuGUI_Displayer()
109 bool VisuGUI_Displayer::IsDisplayed( const QString& id, SALOME_View* vf ) const {
111 bool displayed = false;
112 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
116 _PTR(SObject) aSObject = aStudy->studyDS()->FindObjectID( (const char*)id.toLatin1() );
117 CORBA::Object_var anObj = VISU::ClientSObjectToObject( aSObject );
118 if( CORBA::is_nil( anObj ) )
119 return LightApp_Displayer::IsDisplayed(id, vf);
121 if(VISU::Container_i* aContainer = dynamic_cast<VISU::Container_i*>( VISU::GetServant( anObj ).in())) {
122 int nbCurves = aContainer->GetNbCurves();
123 for( int k=1; k<=nbCurves; k++ ) {
124 VISU::Curve_i* aCurve = aContainer->GetCurve( k );
125 if(aCurve && LightApp_Displayer::IsDisplayed(aCurve->GetEntry().c_str(), vf)) {
131 } else if( VISU::Table_i* aTable = dynamic_cast<VISU::Table_i*>( VISU::GetServant( anObj ).in()) ) {
133 SPlot2d_Viewer* view2D = dynamic_cast<SPlot2d_Viewer*>(vf);
135 return LightApp_Displayer::IsDisplayed(id, vf);
137 _PTR(SObject) TableSO = aStudy->studyDS()->FindObjectID( (const char*)id.toLatin1() );
139 _PTR(ChildIterator) Iter = aStudy->studyDS()->NewChildIterator( TableSO );
140 for( ; Iter->More(); Iter->Next() ) {
141 CORBA::Object_var childObject = VISU::ClientSObjectToObject( Iter->Value() );
142 if( !CORBA::is_nil( childObject ) ) {
143 CORBA::Object_ptr aCurve = VISU::Curve::_narrow( childObject );
144 if( !CORBA::is_nil( aCurve ) ) {
145 VISU::Curve_i* aCurve_i = dynamic_cast<VISU::Curve_i*>(VISU::GetServant(aCurve).in());
146 if(aCurve && LightApp_Displayer::IsDisplayed(aCurve_i->GetEntry().c_str(), vf)) {
156 return LightApp_Displayer::IsDisplayed(id, vf);
160 SALOME_Prs* VisuGUI_Displayer::buildPresentation( const QString& theEntry, SALOME_View* theView )
162 SALOME_Prs* aPrs = 0;
164 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
167 _PTR(SObject) aSObject = aStudy->studyDS()->FindObjectID( (const char*)theEntry.toLatin1() );
168 CORBA::Object_var anObject = VISU::ClientSObjectToObject( aSObject );
169 if( CORBA::is_nil( anObject ) )
172 VISU::Base_var aBase = VISU::Base::_narrow(anObject);
173 if (CORBA::is_nil(aBase))
176 VISU::Base_i* aBaseServant = dynamic_cast<VISU::Base_i*>(VISU::GetServant(aBase).in());
178 SALOME_View* aView = theView ? theView : GetActiveView();
179 VISU::VISUType aType = aBase->GetType();
180 VISU::Prs3d_var aPrs3d = VISU::Prs3d::_narrow(aBase);
181 if(!CORBA::is_nil(aPrs3d) || aType == VISU::TCOLOREDPRS3DHOLDER){
182 SVTK_Viewer* aViewer = dynamic_cast<SVTK_Viewer*>( aView );
184 //aViewer = dynamic_cast<SVTK_Viewer*>( aView );
186 SUIT_ViewManager* aViewManager = aViewer->getViewManager();
187 SUIT_ViewWindow* aWindow = aViewManager->getActiveView();
188 if(SVTK_ViewWindow* aViewWindow = dynamic_cast<SVTK_ViewWindow*>( aWindow )){
189 VISU::Prs3d_i* aPrs3d = NULL;
190 if(aType == VISU::TCOLOREDPRS3DHOLDER){
191 VISU::ColoredPrs3dHolder_var aHolder = VISU::ColoredPrs3dHolder::_narrow(aBase);
192 VISU::ColoredPrs3d_var aColoredPrs3d = aHolder->GetDevice();
193 aPrs3d = dynamic_cast<VISU::Prs3d_i*>(VISU::GetServant(aColoredPrs3d).in());
194 }else if (aType == VISU::TPOINTMAP3D) {
195 VISU::PointMap3d_i* aTable3d = dynamic_cast<VISU::PointMap3d_i*>(aBaseServant);
196 VISU_ActorBase* anActorBase = VISU::FindActorBase(aViewWindow, aTable3d);
198 anActorBase->SetVisibility(true);
199 aViewWindow->Repaint();
202 VISU_PointMap3dActor* aPointMap3dActor = aTable3d->CreateActor();
203 if (aPointMap3dActor) {
204 aViewWindow->AddActor(aPointMap3dActor);
205 aPointMap3dActor->SetVisibility(true);
206 aViewWindow->Repaint();
209 VISU::SetVisibilityState(qPrintable(theEntry),Qtx::ShownState);
212 aPrs3d = dynamic_cast<VISU::Prs3d_i*>(aBaseServant);
215 buildPrs3d( aViewWindow, aPrs3d );
216 Handle(SALOME_InteractiveObject) anIO = aPrs3d->GetIO();
217 if(anIO->hasEntry()){
218 std::string anEntry = anIO->getEntry();
219 aPrs = LightApp_Displayer::buildPresentation( anEntry.c_str(), aView );
226 SPlot2d_Viewer* aViewer = 0;
227 if (aView) aViewer = dynamic_cast<SPlot2d_Viewer*>(aView);
228 if(!aViewer && (aType==VISU::TCURVE || aType==VISU::TCONTAINER))
229 if(VisuGUI* aVisuGUI = dynamic_cast<VisuGUI*>(myApp->activeModule()))
230 aViewer = VISU::GetPlot2dViewer( (SalomeApp_Module*)aVisuGUI, true );
233 SUIT_ViewManager* aViewManager = aViewer->getViewManager();
234 SUIT_ViewWindow* aWindow = aViewManager->getActiveView();
235 Plot2d_ViewWindow* aViewWindow = dynamic_cast<Plot2d_ViewWindow*>( aWindow );
239 SPlot2d_Prs* aPlot2dPrs = 0;
242 VISU::Curve_i* aCurve = dynamic_cast<VISU::Curve_i*>(aBaseServant);
243 aPlot2dPrs = buildCurve( aViewWindow, aCurve );
246 case VISU::TCONTAINER: {
247 VISU::Container_i* aContainer = dynamic_cast<VISU::Container_i*>(aBaseServant);
248 aPlot2dPrs = buildContainer( aViewWindow, aContainer );
251 case VISU::TPOINTMAP3D: {
252 VISU::Table_i* aTable = dynamic_cast<VISU::Table_i*>(aBaseServant);
253 aPlot2dPrs = buildTable( aViewWindow, aTable );
257 VISU::Table_i* aTable = dynamic_cast<VISU::Table_i*>(aBaseServant);
258 aPlot2dPrs = buildTable( aViewWindow, aTable );
263 aPrs = new SPlot2d_Prs( aPlot2dPrs );
272 void VisuGUI_Displayer::buildPrs3d( SVTK_ViewWindow* theViewWindow, VISU::Prs3d_i* thePrs3d ) const
274 VISU_Actor* anActor = VISU::FindActor(theViewWindow, thePrs3d);
277 anActor = thePrs3d->CreateActor();
278 } catch (std::runtime_error& exc) {
279 thePrs3d->RemoveActors();
282 SUIT_MessageBox::warning
283 (myApp->desktop(), QObject::tr("WRN_VISU"),
284 QObject::tr("ERR_CANT_BUILD_PRESENTATION") + ": " + QObject::tr(exc.what()),
285 QObject::tr("BUT_OK"));
288 theViewWindow->AddActor(anActor);
290 anActor->SetVisibility(true);
292 theViewWindow->Repaint();
295 bool VisuGUI_Displayer::addCurve( SPlot2d_Prs* prs, Plot2d_ViewWindow* wnd, VISU::Curve_i* c ) const
297 if( !prs || !wnd || !c )
300 QString entry = c->GetSObject()->GetID();
301 SPlot2d_Viewer* vv = dynamic_cast<SPlot2d_Viewer*>( wnd->getModel() );
305 SPlot2d_Curve* curve = vv->getCurveByIO( vv->FindIObject( (const char*)entry.toLatin1() ) );
308 curve = c->CreatePresentation();
309 VISU::UpdateCurve( c, 0, curve, VISU::eDisplay );
312 prs->AddObject( curve );
317 SPlot2d_Prs* VisuGUI_Displayer::buildCurve( Plot2d_ViewWindow* wnd, VISU::Curve_i* c ) const
319 SPlot2d_Prs* prs = new SPlot2d_Prs();
320 if( !addCurve( prs, wnd, c ) )
328 SPlot2d_Prs* VisuGUI_Displayer::buildContainer( Plot2d_ViewWindow* wnd, VISU::Container_i* c ) const
330 SPlot2d_Prs* prs = new SPlot2d_Prs();
332 int nbCurves = c ? c->GetNbCurves() : 0;
333 for( int k=1; k<=nbCurves; k++ )
335 VISU::Curve_i* theCurve = c->GetCurve( k );
336 if( theCurve && theCurve->IsValid() )
337 addCurve( prs, wnd, theCurve );
339 if( prs->getObjects().count()==0 )
347 SPlot2d_Prs* VisuGUI_Displayer::buildTable( Plot2d_ViewWindow* wnd, VISU::Table_i* t ) const
349 SPlot2d_Prs* prs = new SPlot2d_Prs();
350 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
354 _PTR(SObject) TableSO = study->studyDS()->FindObjectID( t->GetEntry() );
359 _PTR(ChildIterator) Iter = study->studyDS()->NewChildIterator( TableSO );
360 for( ; Iter->More(); Iter->Next() )
362 CORBA::Object_var childObject = VISU::ClientSObjectToObject( Iter->Value() );
363 if( !CORBA::is_nil( childObject ) )
365 CORBA::Object_ptr aCurve = VISU::Curve::_narrow( childObject );
366 if( !CORBA::is_nil( aCurve ) )
368 VISU::Curve_i* theCurve = dynamic_cast<VISU::Curve_i*>(VISU::GetServant(aCurve).in());
369 addCurve( prs, wnd, theCurve );
373 if( prs->getObjects().count()==0 )
381 bool VisuGUI_Displayer::canBeDisplayed( const QString& entry, const QString& viewer_type ) const
383 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
387 _PTR(SObject) obj = study->studyDS()->FindObjectID( (const char*)entry.toLatin1() );
388 CORBA::Object_var anObj = VISU::ClientSObjectToObject( obj );
389 if( CORBA::is_nil( anObj ) )
392 if( study->isComponent( entry ) )
395 if( (dynamic_cast<VISU::Curve_i*>( VISU::GetServant( anObj ).in() )
397 dynamic_cast<VISU::Container_i*>( VISU::GetServant( anObj ).in() ))
398 && viewer_type==SPlot2d_Viewer::Type())
401 if( viewer_type==SVTK_Viewer::Type() /*|| viewer_type==VVTK_Viewer::Type()*/)
403 VISU::Base_i* aBase = dynamic_cast<VISU::Base_i*>(VISU::GetServant(anObj).in());
408 if(aBase->GetType() == VISU::TCOLOREDPRS3DHOLDER)
411 if(aBase->GetType() == VISU::TPOINTMAP3D)
412 return dynamic_cast<VISU::PointMap3d_i*>(aBase);
414 return dynamic_cast<VISU::Prs3d_i*>(aBase);
416 else if( viewer_type==SPlot2d_Viewer::Type() )
418 VISU::Table_i* aTable = dynamic_cast<VISU::Table_i*>(VISU::GetServant( anObj ).in() );
425 void VisuGUI_Displayer::AfterDisplay( SALOME_View* vf, const SALOME_Prs2d* p ) {
426 changeVisibility(VISU::eDisplay, myLastEntry, dynamic_cast<SalomeApp_Study*>( myApp->activeStudy()));
429 void VisuGUI_Displayer::AfterErase( SALOME_View* vf, const SALOME_Prs2d* p ) {
430 changeVisibility(VISU::eErase, myLastEntry, dynamic_cast<SalomeApp_Study*>( myApp->activeStudy()));