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 // GEOM GEOMGUI : GUI for Geometry component
23 // File : DisplayGUI.cxx
24 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
26 #include "DisplayGUI.h"
27 #include <GeometryGUI.h>
28 #include "GeometryGUI_Operations.h"
29 #include <GEOM_Displayer.h>
30 #include <GEOM_AISShape.hxx>
31 #include <GEOM_Actor.h>
33 #include <SUIT_Desktop.h>
34 #include <SUIT_ViewWindow.h>
35 #include <SUIT_OverrideCursor.h>
37 #include <OCCViewer_ViewManager.h>
38 #include <OCCViewer_ViewModel.h>
40 #include <SALOME_ListIO.hxx>
41 #include <SALOME_ListIteratorOfListIO.hxx>
43 #include <SVTK_ViewWindow.h>
44 #include <SVTK_View.h>
45 #include <SVTK_ViewModel.h>
46 #include <SOCC_ViewModel.h>
50 #include <QtxActionMenuMgr.h>
52 #include <SalomeApp_Application.h>
53 #include <LightApp_SelectionMgr.h>
54 #include <SalomeApp_Study.h>
56 #include <AIS_ListIteratorOfListOfInteractive.hxx>
58 #include <vtkActorCollection.h>
59 #include <vtkRenderer.h>
63 //=======================================================================
64 // function : DisplayGUI::DisplayGUI()
65 // purpose : Constructor
66 //=======================================================================
67 DisplayGUI::DisplayGUI( GeometryGUI* parent ) : GEOMGUI( parent )
71 //=======================================================================
72 // function : DisplayGUI::~DisplayGUI()
73 // purpose : Destructor
74 //=======================================================================
75 DisplayGUI::~DisplayGUI()
80 //=======================================================================
81 // function : DisplayGUI::OnGUIEvent()
82 // purpose : Dispatch menu command
83 //=======================================================================
84 bool DisplayGUI::OnGUIEvent(int theCommandID, SUIT_Desktop* parent)
86 SalomeApp_Application* app = getGeometryGUI()->getApp();
87 if (!app) return false;
89 LightApp_SelectionMgr *Sel = app->selectionMgr();
90 SALOME_ListIO selected;
91 Sel->selectedObjects( selected );
93 switch ( theCommandID ) {
94 case GEOMOp::OpDisplayMode: // MENU VIEW - DISPLAY MODE - WIREFRAME/SHADING
96 getGeometryGUI()->action( GEOMOp::OpDisplayMode )->setText
97 ( GetDisplayMode() == 1 ? tr( "GEOM_MEN_WIREFRAME" ) : tr("GEOM_MEN_SHADING") );
98 getGeometryGUI()->menuMgr()->update();
100 case GEOMOp::OpShowAll: // MENU VIEW - SHOW ALL
101 getGeometryGUI()->EmitSignalDeactivateDialog();
104 case GEOMOp::OpShowOnly: // POPUP MENU - SHOW ONLY
105 getGeometryGUI()->EmitSignalDeactivateDialog();
108 case GEOMOp::OpHideAll: // MENU VIEW - HIDE ALL
111 case GEOMOp::OpHide: // POPUP MENU - HIDE
114 case GEOMOp::OpShow: // POPUP MENU - SHOW
115 getGeometryGUI()->EmitSignalDeactivateDialog();
118 case GEOMOp::OpSwitchVectors: // MENU VIEW - DISPLAY MODE - SHOW EDGE DIRECTION
119 SetVectorMode(!GetVectorMode());
120 getGeometryGUI()->action( GEOMOp::OpSwitchVectors )->setText
121 ( GetVectorMode() ? tr("MEN_VECTOR_MODE_ON") : tr( "MEN_VECTOR_MODE_OFF" ) );
122 getGeometryGUI()->menuMgr()->update();
124 case GEOMOp::OpWireframe: // POPUP MENU - DISPLAY MODE - WIREFRAME
125 ChangeDisplayMode( 0 );
127 case GEOMOp::OpShading: // POPUP MENU - DISPLAY MODE - SHADING
128 ChangeDisplayMode( 1 );
130 case GEOMOp::OpVectors: // POPUP MENU - DISPLAY MODE - SHOW EDGE DIRECTION
131 ChangeDisplayMode( 2 );
134 app->putInfo(tr("GEOM_PRP_COMMAND").arg(theCommandID));
137 Sel->setSelectedObjects( selected );
141 //=====================================================================================
142 // function : DisplayGUI::DisplayAll()
143 // purpose : Display all GEOM objects
144 //=====================================================================================
145 void DisplayGUI::DisplayAll()
147 SalomeApp_Application* app = getGeometryGUI()->getApp();
150 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
151 if ( !appStudy ) return;
152 _PTR(Study) aStudy = appStudy->studyDS();
153 if ( !aStudy ) return;
154 _PTR(SComponent) SC ( aStudy->FindComponent( "GEOM" ) );
158 SALOME_ListIO listIO;
159 _PTR(ChildIterator) anIter ( aStudy->NewChildIterator( SC ) );
160 anIter->InitEx( true );
162 SUIT_OverrideCursor();
164 while( anIter->More() ) {
165 _PTR(SObject) valSO ( anIter->Value() );
167 if ( !valSO->ReferencedObject( refSO ) ) {
168 listIO.Append( new SALOME_InteractiveObject(valSO->GetID().c_str(),
169 SC->ComponentDataType().c_str(),
170 valSO->GetName().c_str()) );
174 GEOM_Displayer( appStudy ).Display( listIO, true );
177 //=====================================================================================
178 // function : DisplayGUI::EraseAll()
179 // purpose : Erase all GEOM objects
180 //=====================================================================================
181 void DisplayGUI::EraseAll()
183 SUIT_OverrideCursor();
185 SUIT_Application* app = getGeometryGUI()->getApp();
187 SUIT_ViewWindow* vw = app->desktop()->activeWindow();
189 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
190 SUIT_ViewManager* vman = vw->getViewManager();
191 if ( vman->getType() == OCCViewer_Viewer::Type() ||
192 vman->getType() == SVTK_Viewer::Type() ) {
193 GEOM_Displayer( appStudy ).EraseAll();
199 //=====================================================================================
200 // function : DisplayGUI::DisplayOnly()
201 // purpose : Display selected GEOM objects and erase other
202 //=====================================================================================
203 void DisplayGUI::DisplayOnly()
209 //=====================================================================================
210 // function : DisplayGUI::Display()
211 // purpose : Display selected GEOM objects
212 //=====================================================================================
213 void DisplayGUI::Display()
215 SALOME_ListIO listIO;
217 SalomeApp_Application* app = getGeometryGUI()->getApp();
220 SalomeApp_Study* anActiveStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
221 if ( !anActiveStudy ) return;
223 //get SalomeApp selection manager
224 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
225 if ( !aSelMgr ) return;
228 aSelMgr->selectedObjects( aList );
229 SALOME_ListIteratorOfListIO It( aList );
231 SUIT_OverrideCursor();
233 for( ;It.More();It.Next() ) {
234 Handle(SALOME_InteractiveObject) anIObject = It.Value();
235 if ( anIObject->hasEntry() ) {
236 _PTR(SObject) SO ( anActiveStudy->studyDS()->FindObjectID( anIObject->getEntry() ) );
237 if ( SO && QString(SO->GetID().c_str()) == QString(SO->GetFatherComponent()->GetID().c_str()) ) {
238 _PTR(SComponent) SC ( SO->GetFatherComponent() );
239 // if component is selected
241 _PTR(ChildIterator) anIter ( anActiveStudy->studyDS()->NewChildIterator( SO ) );
242 anIter->InitEx( true );
243 while( anIter->More() ) {
244 _PTR(SObject) valSO ( anIter->Value() );
246 if ( !valSO->ReferencedObject( refSO ) ) {
247 listIO.Append( new SALOME_InteractiveObject(valSO->GetID().c_str(),
248 SC->ComponentDataType().c_str(),
249 valSO->GetName().c_str()) );
256 listIO.Append( anIObject );
260 listIO.Append( anIObject );
263 GEOM_Displayer( anActiveStudy ).Display( listIO, true );
267 //=====================================================================================
268 // function : DisplayGUI::Erase()
269 // purpose : Erase selected GEOM objects
270 //=====================================================================================
271 void DisplayGUI::Erase()
273 SALOME_ListIO listIO;
275 SalomeApp_Application* app = getGeometryGUI()->getApp();
278 SalomeApp_Study* anActiveStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
279 if ( !anActiveStudy ) return;
281 //get SalomeApp selection manager
282 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
283 if ( !aSelMgr ) return;
286 aSelMgr->selectedObjects( aList );
287 SALOME_ListIteratorOfListIO It( aList );
289 SUIT_OverrideCursor();
291 for( ; It.More(); It.Next() ) {
292 Handle(SALOME_InteractiveObject) anIObject = It.Value();
293 if ( anIObject->hasEntry() ) {
294 _PTR(SObject) SO ( anActiveStudy->studyDS()->FindObjectID( anIObject->getEntry() ) );
295 if ( SO && QString(SO->GetID().c_str()) == QString(SO->GetFatherComponent()->GetID().c_str()) ) {
296 _PTR(SComponent) SC ( SO->GetFatherComponent() );
297 // if component is selected
299 _PTR(ChildIterator) anIter ( anActiveStudy->studyDS()->NewChildIterator( SO ) );
300 anIter->InitEx( true );
301 while( anIter->More() ) {
302 _PTR(SObject) valSO ( anIter->Value() );
304 if ( !valSO->ReferencedObject( refSO ) ) {
305 listIO.Append( new SALOME_InteractiveObject(valSO->GetID().c_str(),
306 SC->ComponentDataType().c_str(),
307 valSO->GetName().c_str()) );
314 listIO.Append( anIObject );
318 listIO.Append( anIObject );
322 SUIT_ViewWindow* viewWindow = app->desktop()->activeWindow();
323 bool aIsForced = true;
324 if(viewWindow->getViewManager()->getType() == SVTK_Viewer::Type())
327 GEOM_Displayer(anActiveStudy).Erase( listIO, aIsForced);
328 getGeometryGUI()->getApp()->selectionMgr()->clearSelected();
331 //=====================================================================================
332 // function : DisplayGUI::SetDisplayMode()
333 // purpose : Set display mode for the viewer (current viewer if <viewWindow> - 0 )
334 //=====================================================================================
335 void DisplayGUI::SetDisplayMode( const int mode, SUIT_ViewWindow* viewWindow )
337 SUIT_OverrideCursor();
340 viewWindow = getGeometryGUI()->getApp()->desktop()->activeWindow();
341 if ( viewWindow->getViewManager()->getType() == SVTK_Viewer::Type() ) {
342 SVTK_View* aView = ((SVTK_ViewWindow*)viewWindow)->getView();
343 aView->SetDisplayMode( mode );
345 else if ( viewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() ) {
346 OCCViewer_Viewer* v3d = ((OCCViewer_ViewManager*)(viewWindow->getViewManager()))->getOCCViewer();
347 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
348 AIS_DisplayMode newmode = (mode == 1 ? AIS_Shaded : AIS_WireFrame);
349 AIS_ListOfInteractive List;
350 ic->DisplayedObjects( List );
351 AIS_ListOfInteractive List1;
352 ic->ObjectsInCollector( List1 );
353 List.Append( List1 );
355 AIS_ListIteratorOfListOfInteractive ite( List );
356 while( ite.More() ) {
357 if( ite.Value()->IsInstance( STANDARD_TYPE(GEOM_AISShape) ) ) {
358 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast( ite.Value() );
359 ic->SetDisplayMode( aSh, Standard_Integer( newmode ),true );
364 ic->SetDisplayMode( newmode, Standard_False );
368 //=====================================================================================
369 // function : DisplayGUI::GetDisplayMode()
370 // purpose : Get display mode of the viewer (current viewer if <viewWindow> - 0 )
371 //=====================================================================================
372 int DisplayGUI::GetDisplayMode( SUIT_ViewWindow* viewWindow )
376 viewWindow = getGeometryGUI()->getApp()->desktop()->activeWindow();
377 if ( viewWindow->getViewManager()->getType() == SVTK_Viewer::Type() ) {
378 SVTK_View* aView = ((SVTK_ViewWindow*)viewWindow)->getView();
379 dispMode = aView->GetDisplayMode();
381 else if ( viewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() ) {
382 OCCViewer_Viewer* v3d = ((OCCViewer_ViewManager*)(viewWindow->getViewManager()))->getOCCViewer();
383 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
384 AIS_DisplayMode mode = (AIS_DisplayMode)ic->DisplayMode();
385 dispMode = (mode == AIS_WireFrame ? 0 : 1 );
390 //=====================================================================================
391 // function : DisplayGUI::SetVectorsMode()
392 // purpose : Set vector mode for the viewer
393 //=====================================================================================
394 void DisplayGUI::SetVectorMode( const bool mode, SUIT_ViewWindow* viewWindow )
396 SUIT_OverrideCursor();
399 viewWindow = getGeometryGUI()->getApp()->desktop()->activeWindow();
400 if ( viewWindow->getViewManager()->getType() == SVTK_Viewer::Type() ) {
401 viewWindow->setCustomData( "VectorsMode", QVariant( mode ) );
402 SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>( viewWindow );
403 vtkActorCollection* allActors = vw->getRenderer()->GetActors();
404 allActors->InitTraversal();
405 while (vtkActor* actor = allActors->GetNextActor()) {
406 if (actor->GetVisibility()) { // only for visible actors
407 GEOM_Actor* aGeomActor = 0;
408 if ( actor->IsA( "GEOM_Actor" ) ) {
409 aGeomActor = GEOM_Actor::SafeDownCast( actor );
411 aGeomActor->SetVectorMode( mode );
416 else if ( viewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() ) {
417 viewWindow->setCustomData( "VectorsMode", QVariant( mode ) );
418 OCCViewer_Viewer* v3d = ((OCCViewer_ViewManager*)(viewWindow->getViewManager()))->getOCCViewer();
419 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
420 AIS_ListOfInteractive List;
421 ic->DisplayedObjects( List );
422 AIS_ListOfInteractive List1;
423 ic->ObjectsInCollector( List1 );
424 List.Append( List1 );
426 AIS_ListIteratorOfListOfInteractive ite( List );
427 while( ite.More() ) {
428 if( ite.Value()->IsInstance( STANDARD_TYPE(GEOM_AISShape) ) ) {
429 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast( ite.Value() );
430 aSh->SetDisplayVectors(mode);
431 ic->RecomputePrsOnly(ite.Value());
438 //=====================================================================================
439 // function : DisplayGUI::GetVectorMode()
440 // purpose : Get the "show edge direction" mode of the viewer
441 //=====================================================================================
442 int DisplayGUI::GetVectorMode( SUIT_ViewWindow* viewWindow )
445 viewWindow = getGeometryGUI()->getApp()->desktop()->activeWindow();
446 return viewWindow->getCustomData( "VectorsMode" ).toBool();
449 //=====================================================================================
450 // function : DisplayGUI::InvertDisplayMode()
451 // purpose : Invert display mode ( shadin <-> wireframe ) for the viewer
452 // (current viewer if <viewWindow> = 0 )
453 //=====================================================================================
454 void DisplayGUI::InvertDisplayMode( SUIT_ViewWindow* viewWindow )
456 SetDisplayMode( 1 - GetDisplayMode( viewWindow ) );
459 //=====================================================================================
460 // function : DisplayGUI::ChangeDisplayMode()
461 // purpose : Set display mode for selected objects in the viewer given
462 // (current viewer if <viewWindow> = 0 )
463 //=====================================================================================
464 void DisplayGUI::ChangeDisplayMode( const int mode, SUIT_ViewWindow* viewWindow )
466 SalomeApp_Application* app = getGeometryGUI()->getApp();
470 viewWindow = app->desktop()->activeWindow();
472 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
473 if ( !aSelMgr ) return;
475 SUIT_OverrideCursor();
479 if ( viewWindow->getViewManager()->getType() == SVTK_Viewer::Type() ) {
480 SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>( viewWindow );
481 SVTK_View* aView = vw->getView();
483 aSelMgr->selectedObjects( aList );
484 SALOME_ListIteratorOfListIO It( aList );
486 for( ;It.More(); It.Next() ) {
487 SVTK_Viewer* stvkViewer = dynamic_cast<SVTK_Viewer*>(vw->getViewManager()->getViewModel());
489 stvkViewer ? dynamic_cast<SVTK_Prs*>( stvkViewer->CreatePrs( It.Value()->getEntry() ) ) : 0;
490 if ( vtkPrs && !vtkPrs->IsNull() ) {
492 aView->ChangeRepresentationToWireframe( vtkPrs->GetObjects() );
493 else if ( mode == 1 )
494 aView->ChangeRepresentationToSurface( vtkPrs->GetObjects() );
495 else if ( mode == 2 ) {
496 vtkActorCollection* anActors = vtkPrs->GetObjects();
497 anActors->InitTraversal();
498 while (vtkActor* anAct = anActors->GetNextActor()) {
499 GEOM_Actor* aGeomActor = GEOM_Actor::SafeDownCast(anAct);
500 aGeomActor->SetVectorMode(!aGeomActor->GetVectorMode());
507 else if ( viewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() ) {
508 OCCViewer_Viewer* v3d = ((OCCViewer_ViewManager*)(viewWindow->getViewManager()))->getOCCViewer();
509 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
511 aSelMgr->selectedObjects( aList );
512 SALOME_ListIteratorOfListIO It( aList );
514 for( ;It.More(); It.Next() ) {
515 SOCC_Viewer* soccViewer = (SOCC_Viewer*)(viewWindow->getViewManager()->getViewModel());
516 SOCC_Prs* occPrs = dynamic_cast<SOCC_Prs*>( soccViewer->CreatePrs( It.Value()->getEntry() ) );
517 if ( occPrs && !occPrs->IsNull() ) {
518 AIS_ListOfInteractive shapes; occPrs->GetObjects( shapes );
519 AIS_ListIteratorOfListOfInteractive interIter( shapes );
520 for ( ; interIter.More(); interIter.Next() ) {
522 ic->SetDisplayMode( interIter.Value(), AIS_WireFrame, false );
523 else if ( mode == 1 )
524 ic->SetDisplayMode( interIter.Value(), AIS_Shaded, false );
526 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast( interIter.Value() );
527 if ( !aSh.IsNull() ) {
528 aSh->SetDisplayVectors(!aSh->isShowVectors());
529 ic->RecomputePrsOnly(interIter.Value());
535 ic->UpdateCurrentViewer();
539 //=====================================================================================
541 //=====================================================================================
545 __declspec( dllexport )
547 GEOMGUI* GetLibGUI( GeometryGUI* parent )
549 return new DisplayGUI( parent );