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 // 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 _PTR(SObject) TableSO = aStudy->studyDS()->FindObjectID( (const char*)id.toLatin1() );
135 _PTR(ChildIterator) Iter = aStudy->studyDS()->NewChildIterator( TableSO );
136 for( ; Iter->More(); Iter->Next() ) {
137 CORBA::Object_var childObject = VISU::ClientSObjectToObject( Iter->Value() );
138 if( !CORBA::is_nil( childObject ) ) {
139 CORBA::Object_ptr aCurve = VISU::Curve::_narrow( childObject );
140 if( !CORBA::is_nil( aCurve ) ) {
141 VISU::Curve_i* aCurve_i = dynamic_cast<VISU::Curve_i*>(VISU::GetServant(aCurve).in());
142 if(aCurve && LightApp_Displayer::IsDisplayed(aCurve_i->GetEntry().c_str(), vf)) {
152 return LightApp_Displayer::IsDisplayed(id, vf);
156 SALOME_Prs* VisuGUI_Displayer::buildPresentation( const QString& theEntry, SALOME_View* theView )
158 SALOME_Prs* aPrs = 0;
160 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
163 _PTR(SObject) aSObject = aStudy->studyDS()->FindObjectID( (const char*)theEntry.toLatin1() );
164 CORBA::Object_var anObject = VISU::ClientSObjectToObject( aSObject );
165 if( CORBA::is_nil( anObject ) )
168 VISU::Base_var aBase = VISU::Base::_narrow(anObject);
169 if (CORBA::is_nil(aBase))
172 VISU::Base_i* aBaseServant = dynamic_cast<VISU::Base_i*>(VISU::GetServant(aBase).in());
174 SALOME_View* aView = theView ? theView : GetActiveView();
175 VISU::VISUType aType = aBase->GetType();
176 VISU::Prs3d_var aPrs3d = VISU::Prs3d::_narrow(aBase);
177 if(!CORBA::is_nil(aPrs3d) || aType == VISU::TCOLOREDPRS3DHOLDER){
178 SVTK_Viewer* aViewer = dynamic_cast<SVTK_Viewer*>( aView );
180 //aViewer = dynamic_cast<SVTK_Viewer*>( aView );
182 SUIT_ViewManager* aViewManager = aViewer->getViewManager();
183 SUIT_ViewWindow* aWindow = aViewManager->getActiveView();
184 if(SVTK_ViewWindow* aViewWindow = dynamic_cast<SVTK_ViewWindow*>( aWindow )){
185 VISU::Prs3d_i* aPrs3d = NULL;
186 if(aType == VISU::TCOLOREDPRS3DHOLDER){
187 VISU::ColoredPrs3dHolder_var aHolder = VISU::ColoredPrs3dHolder::_narrow(aBase);
188 VISU::ColoredPrs3d_var aColoredPrs3d = aHolder->GetDevice();
189 aPrs3d = dynamic_cast<VISU::Prs3d_i*>(VISU::GetServant(aColoredPrs3d).in());
190 }else if (aType == VISU::TPOINTMAP3D) {
191 VISU::PointMap3d_i* aTable3d = dynamic_cast<VISU::PointMap3d_i*>(aBaseServant);
192 VISU_ActorBase* anActorBase = VISU::FindActorBase(aViewWindow, aTable3d);
194 anActorBase->SetVisibility(true);
195 aViewWindow->Repaint();
198 VISU_PointMap3dActor* aPointMap3dActor = aTable3d->CreateActor();
199 if (aPointMap3dActor) {
200 aViewWindow->AddActor(aPointMap3dActor);
201 aPointMap3dActor->SetVisibility(true);
202 aViewWindow->Repaint();
205 VISU::SetVisibilityState(qPrintable(theEntry),Qtx::ShownState);
208 aPrs3d = dynamic_cast<VISU::Prs3d_i*>(aBaseServant);
211 buildPrs3d( aViewWindow, aPrs3d );
212 Handle(SALOME_InteractiveObject) anIO = aPrs3d->GetIO();
213 if(anIO->hasEntry()){
214 std::string anEntry = anIO->getEntry();
215 aPrs = LightApp_Displayer::buildPresentation( anEntry.c_str(), aView );
222 SPlot2d_Viewer* aViewer = 0;
223 if (aView) aViewer = dynamic_cast<SPlot2d_Viewer*>(aView);
224 if(!aViewer && (aType==VISU::TCURVE || aType==VISU::TCONTAINER))
225 if(VisuGUI* aVisuGUI = dynamic_cast<VisuGUI*>(myApp->activeModule()))
226 aViewer = VISU::GetPlot2dViewer( (SalomeApp_Module*)aVisuGUI, true );
229 SUIT_ViewManager* aViewManager = aViewer->getViewManager();
230 SUIT_ViewWindow* aWindow = aViewManager->getActiveView();
231 Plot2d_ViewWindow* aViewWindow = dynamic_cast<Plot2d_ViewWindow*>( aWindow );
235 SPlot2d_Prs* aPlot2dPrs = 0;
238 VISU::Curve_i* aCurve = dynamic_cast<VISU::Curve_i*>(aBaseServant);
239 aPlot2dPrs = buildCurve( aViewWindow, aCurve );
242 case VISU::TCONTAINER: {
243 VISU::Container_i* aContainer = dynamic_cast<VISU::Container_i*>(aBaseServant);
244 aPlot2dPrs = buildContainer( aViewWindow, aContainer );
247 case VISU::TPOINTMAP3D: {
248 VISU::Table_i* aTable = dynamic_cast<VISU::Table_i*>(aBaseServant);
249 aPlot2dPrs = buildTable( aViewWindow, aTable );
253 VISU::Table_i* aTable = dynamic_cast<VISU::Table_i*>(aBaseServant);
254 aPlot2dPrs = buildTable( aViewWindow, aTable );
259 aPrs = new SPlot2d_Prs( aPlot2dPrs );
268 void VisuGUI_Displayer::buildPrs3d( SVTK_ViewWindow* theViewWindow, VISU::Prs3d_i* thePrs3d ) const
270 VISU_Actor* anActor = VISU::FindActor(theViewWindow, thePrs3d);
273 anActor = thePrs3d->CreateActor();
274 } catch (std::runtime_error& exc) {
275 thePrs3d->RemoveActors();
278 SUIT_MessageBox::warning
279 (myApp->desktop(), QObject::tr("WRN_VISU"),
280 QObject::tr("ERR_CANT_BUILD_PRESENTATION") + ": " + QObject::tr(exc.what()),
281 QObject::tr("BUT_OK"));
284 theViewWindow->AddActor(anActor);
286 anActor->SetVisibility(true);
288 theViewWindow->Repaint();
291 bool VisuGUI_Displayer::addCurve( SPlot2d_Prs* prs, Plot2d_ViewWindow* wnd, VISU::Curve_i* c ) const
293 if( !prs || !wnd || !c )
296 QString entry = c->GetSObject()->GetID();
297 SPlot2d_Viewer* vv = dynamic_cast<SPlot2d_Viewer*>( wnd->getModel() );
301 SPlot2d_Curve* curve = vv->getCurveByIO( vv->FindIObject( (const char*)entry.toLatin1() ) );
304 curve = c->CreatePresentation();
305 VISU::UpdateCurve( c, 0, curve, VISU::eDisplay );
308 prs->AddObject( curve );
313 SPlot2d_Prs* VisuGUI_Displayer::buildCurve( Plot2d_ViewWindow* wnd, VISU::Curve_i* c ) const
315 SPlot2d_Prs* prs = new SPlot2d_Prs();
316 if( !addCurve( prs, wnd, c ) )
324 SPlot2d_Prs* VisuGUI_Displayer::buildContainer( Plot2d_ViewWindow* wnd, VISU::Container_i* c ) const
326 SPlot2d_Prs* prs = new SPlot2d_Prs();
328 int nbCurves = c ? c->GetNbCurves() : 0;
329 for( int k=1; k<=nbCurves; k++ )
331 VISU::Curve_i* theCurve = c->GetCurve( k );
332 if( theCurve && theCurve->IsValid() )
333 addCurve( prs, wnd, theCurve );
335 if( prs->getObjects().count()==0 )
343 SPlot2d_Prs* VisuGUI_Displayer::buildTable( Plot2d_ViewWindow* wnd, VISU::Table_i* t ) const
345 SPlot2d_Prs* prs = new SPlot2d_Prs();
346 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
350 _PTR(SObject) TableSO = study->studyDS()->FindObjectID( t->GetEntry() );
355 _PTR(ChildIterator) Iter = study->studyDS()->NewChildIterator( TableSO );
356 for( ; Iter->More(); Iter->Next() )
358 CORBA::Object_var childObject = VISU::ClientSObjectToObject( Iter->Value() );
359 if( !CORBA::is_nil( childObject ) )
361 CORBA::Object_ptr aCurve = VISU::Curve::_narrow( childObject );
362 if( !CORBA::is_nil( aCurve ) )
364 VISU::Curve_i* theCurve = dynamic_cast<VISU::Curve_i*>(VISU::GetServant(aCurve).in());
365 addCurve( prs, wnd, theCurve );
369 if( prs->getObjects().count()==0 )
377 bool VisuGUI_Displayer::canBeDisplayed( const QString& entry, const QString& viewer_type ) const
379 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
383 _PTR(SObject) obj = study->studyDS()->FindObjectID( (const char*)entry.toLatin1() );
384 CORBA::Object_var anObj = VISU::ClientSObjectToObject( obj );
385 if( CORBA::is_nil( anObj ) )
388 if( study->isComponent( entry ) )
391 if( (dynamic_cast<VISU::Curve_i*>( VISU::GetServant( anObj ).in() )
393 dynamic_cast<VISU::Container_i*>( VISU::GetServant( anObj ).in() ))
394 && viewer_type==SPlot2d_Viewer::Type())
397 if( viewer_type==SVTK_Viewer::Type() /*|| viewer_type==VVTK_Viewer::Type()*/)
399 VISU::Base_i* aBase = dynamic_cast<VISU::Base_i*>(VISU::GetServant(anObj).in());
404 if(aBase->GetType() == VISU::TCOLOREDPRS3DHOLDER)
407 if(aBase->GetType() == VISU::TPOINTMAP3D)
408 return dynamic_cast<VISU::PointMap3d_i*>(aBase);
410 return dynamic_cast<VISU::Prs3d_i*>(aBase);
412 else if( viewer_type==SPlot2d_Viewer::Type() )
414 VISU::Table_i* aTable = dynamic_cast<VISU::Table_i*>(VISU::GetServant( anObj ).in() );
421 void VisuGUI_Displayer::AfterDisplay( SALOME_View* vf, const SALOME_Plot2dViewType& ) {
422 changeVisibility(VISU::eDisplay, myLastEntry,dynamic_cast<SalomeApp_Study*>( myApp->activeStudy()));
425 void VisuGUI_Displayer::AfterErase( SALOME_View* vf, const SALOME_Plot2dViewType& ) {
426 changeVisibility(VISU::eErase, myLastEntry,dynamic_cast<SalomeApp_Study*>( myApp->activeStudy()));