1 // Copyright (C) 2007-2011 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 // GEOM GEOMGUI : GUI for Geometry component
24 // File : DisplayGUI.cxx
25 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
27 #include "DisplayGUI.h"
28 #include <GeometryGUI.h>
29 #include "GeometryGUI_Operations.h"
30 #include <GEOM_Constants.h>
31 #include <GEOM_Displayer.h>
32 #include <GEOM_AISShape.hxx>
33 #include <GEOM_Actor.h>
35 #include <SUIT_Desktop.h>
36 #include <SUIT_ViewWindow.h>
37 #include <SUIT_OverrideCursor.h>
39 #include <OCCViewer_ViewManager.h>
40 #include <OCCViewer_ViewModel.h>
42 #include <SALOME_ListIO.hxx>
43 #include <SALOME_ListIteratorOfListIO.hxx>
45 #include <SVTK_ViewWindow.h>
46 #include <SVTK_View.h>
47 #include <SVTK_ViewModel.h>
48 #include <SOCC_ViewModel.h>
52 #include <QtxActionMenuMgr.h>
54 #include <SalomeApp_Application.h>
55 #include <LightApp_SelectionMgr.h>
56 #include <SalomeApp_Study.h>
58 #include <AIS_ListIteratorOfListOfInteractive.hxx>
60 #include <vtkActorCollection.h>
61 #include <vtkRenderer.h>
65 //=======================================================================
66 // function : DisplayGUI::DisplayGUI()
67 // purpose : Constructor
68 //=======================================================================
69 DisplayGUI::DisplayGUI( GeometryGUI* parent ) : GEOMGUI( parent )
73 //=======================================================================
74 // function : DisplayGUI::~DisplayGUI()
75 // purpose : Destructor
76 //=======================================================================
77 DisplayGUI::~DisplayGUI()
82 //=======================================================================
83 // function : DisplayGUI::OnGUIEvent()
84 // purpose : Dispatch menu command
85 //=======================================================================
86 bool DisplayGUI::OnGUIEvent(int theCommandID, SUIT_Desktop* parent)
88 SalomeApp_Application* app = getGeometryGUI()->getApp();
89 if (!app) return false;
91 LightApp_SelectionMgr *Sel = app->selectionMgr();
92 SALOME_ListIO selected;
93 Sel->selectedObjects( selected );
95 QString aDispModeName;
97 if ( theCommandID == GEOMOp::OpDisplayMode )
98 aDispMode = GetDisplayMode();
100 switch ( theCommandID ) {
101 case GEOMOp::OpDisplayMode: // MENU VIEW - DISPLAY MODE - WIREFRAME/SHADING/SHADING WITH EDGES
102 //InvertDisplayMode();
103 switch ( aDispMode) {
105 aDispModeName = tr( "GEOM_MEN_WIREFRAME" );
108 aDispModeName = tr("GEOM_MEN_SHADING");
111 aDispModeName = tr("GEOM_MEN_SHADING_WITH_EDGES");
116 getGeometryGUI()->action( GEOMOp::OpDisplayMode )->setText( aDispModeName );
117 getGeometryGUI()->menuMgr()->update();
119 case GEOMOp::OpShowAll: // MENU VIEW - SHOW ALL
120 getGeometryGUI()->EmitSignalDeactivateDialog();
123 case GEOMOp::OpShowOnly: // POPUP MENU - SHOW ONLY
124 getGeometryGUI()->EmitSignalDeactivateDialog();
127 case GEOMOp::OpHideAll: // MENU VIEW - HIDE ALL
130 case GEOMOp::OpHide: // POPUP MENU - HIDE
133 case GEOMOp::OpShow: // POPUP MENU - SHOW
134 getGeometryGUI()->EmitSignalDeactivateDialog();
137 case GEOMOp::OpSwitchVectors: // MENU VIEW - DISPLAY MODE - SHOW EDGE DIRECTION
138 SetVectorMode(!GetVectorMode());
139 getGeometryGUI()->action( GEOMOp::OpSwitchVectors )->setText
140 ( GetVectorMode() ? tr("MEN_VECTOR_MODE_ON") : tr( "MEN_VECTOR_MODE_OFF" ) );
141 getGeometryGUI()->menuMgr()->update();
143 case GEOMOp::OpWireframe: // POPUP MENU - DISPLAY MODE - WIREFRAME
144 ChangeDisplayMode( 0 );
146 case GEOMOp::OpShading: // POPUP MENU - DISPLAY MODE - SHADING
147 ChangeDisplayMode( 1 );
149 case GEOMOp::OpShadingWithEdges: // POPUP MENU - DISPLAY MODE - SHADING WITH EDGES
150 ChangeDisplayMode( 2 );
152 case GEOMOp::OpTexture: // POPUP MENU - DISPLAY MODE - TEXTURE
153 ChangeDisplayMode( 3 );
155 case GEOMOp::OpVectors: // POPUP MENU - DISPLAY MODE - SHOW EDGE DIRECTION
156 ChangeDisplayMode( 4 );
159 app->putInfo(tr("GEOM_PRP_COMMAND").arg(theCommandID));
162 Sel->setSelectedObjects( selected );
166 //=====================================================================================
167 // function : DisplayGUI::DisplayAll()
168 // purpose : Display all GEOM objects
169 //=====================================================================================
170 void DisplayGUI::DisplayAll()
172 SalomeApp_Application* app = getGeometryGUI()->getApp();
175 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
176 if ( !appStudy ) return;
177 _PTR(Study) aStudy = appStudy->studyDS();
178 if ( !aStudy ) return;
179 _PTR(SComponent) SC ( aStudy->FindComponent( "GEOM" ) );
183 SALOME_ListIO listIO;
184 _PTR(ChildIterator) anIter ( aStudy->NewChildIterator( SC ) );
185 anIter->InitEx( true );
187 SUIT_OverrideCursor();
189 while( anIter->More() ) {
190 _PTR(SObject) valSO ( anIter->Value() );
192 if ( !valSO->ReferencedObject( refSO ) ) {
193 listIO.Append( new SALOME_InteractiveObject(valSO->GetID().c_str(),
194 SC->ComponentDataType().c_str(),
195 valSO->GetName().c_str()) );
199 GEOM_Displayer( appStudy ).Display( listIO, true );
202 //=====================================================================================
203 // function : DisplayGUI::EraseAll()
204 // purpose : Erase all GEOM objects
205 //=====================================================================================
206 void DisplayGUI::EraseAll()
208 SUIT_OverrideCursor();
210 SUIT_Application* app = getGeometryGUI()->getApp();
212 SUIT_ViewWindow* vw = app->desktop()->activeWindow();
214 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
215 SUIT_ViewManager* vman = vw->getViewManager();
216 if ( vman->getType() == OCCViewer_Viewer::Type() ||
217 vman->getType() == SVTK_Viewer::Type() ) {
218 GEOM_Displayer( appStudy ).EraseAll();
224 //=====================================================================================
225 // function : DisplayGUI::DisplayOnly()
226 // purpose : Display selected GEOM objects and erase other
227 //=====================================================================================
228 void DisplayGUI::DisplayOnly()
234 //=====================================================================================
235 // function : DisplayGUI::Display()
236 // purpose : Display selected GEOM objects
237 //=====================================================================================
238 void DisplayGUI::Display()
240 SALOME_ListIO listIO;
242 SalomeApp_Application* app = getGeometryGUI()->getApp();
245 SalomeApp_Study* anActiveStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
246 if ( !anActiveStudy ) return;
248 //get SalomeApp selection manager
249 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
250 if ( !aSelMgr ) return;
253 aSelMgr->selectedObjects( aList );
254 SALOME_ListIteratorOfListIO It( aList );
256 SUIT_OverrideCursor();
258 for( ;It.More();It.Next() ) {
259 Handle(SALOME_InteractiveObject) anIObject = It.Value();
260 if ( anIObject->hasEntry() ) {
261 _PTR(SObject) SO ( anActiveStudy->studyDS()->FindObjectID( anIObject->getEntry() ) );
262 if ( SO && QString(SO->GetID().c_str()) == QString(SO->GetFatherComponent()->GetID().c_str()) ) {
263 _PTR(SComponent) SC ( SO->GetFatherComponent() );
264 // if component is selected
266 _PTR(ChildIterator) anIter ( anActiveStudy->studyDS()->NewChildIterator( SO ) );
267 anIter->InitEx( true );
268 while( anIter->More() ) {
269 _PTR(SObject) valSO ( anIter->Value() );
271 if ( !valSO->ReferencedObject( refSO ) ) {
272 listIO.Append( new SALOME_InteractiveObject(valSO->GetID().c_str(),
273 SC->ComponentDataType().c_str(),
274 valSO->GetName().c_str()) );
281 listIO.Append( anIObject );
285 listIO.Append( anIObject );
288 GEOM_Displayer( anActiveStudy ).Display( listIO, true );
292 //=====================================================================================
293 // function : DisplayGUI::Erase()
294 // purpose : Erase selected GEOM objects
295 //=====================================================================================
296 void DisplayGUI::Erase()
298 SALOME_ListIO listIO;
300 SalomeApp_Application* app = getGeometryGUI()->getApp();
303 SalomeApp_Study* anActiveStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
304 if ( !anActiveStudy ) return;
306 //get SalomeApp selection manager
307 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
308 if ( !aSelMgr ) return;
311 aSelMgr->selectedObjects( aList );
312 SALOME_ListIteratorOfListIO It( aList );
314 SUIT_OverrideCursor();
316 for( ; It.More(); It.Next() ) {
317 Handle(SALOME_InteractiveObject) anIObject = It.Value();
318 if ( anIObject->hasEntry() ) {
319 _PTR(SObject) SO ( anActiveStudy->studyDS()->FindObjectID( anIObject->getEntry() ) );
320 if ( SO && QString(SO->GetID().c_str()) == QString(SO->GetFatherComponent()->GetID().c_str()) ) {
321 _PTR(SComponent) SC ( SO->GetFatherComponent() );
322 // if component is selected
324 _PTR(ChildIterator) anIter ( anActiveStudy->studyDS()->NewChildIterator( SO ) );
325 anIter->InitEx( true );
326 while( anIter->More() ) {
327 _PTR(SObject) valSO ( anIter->Value() );
329 if ( !valSO->ReferencedObject( refSO ) ) {
330 listIO.Append( new SALOME_InteractiveObject(valSO->GetID().c_str(),
331 SC->ComponentDataType().c_str(),
332 valSO->GetName().c_str()) );
339 listIO.Append( anIObject );
343 listIO.Append( anIObject );
347 SUIT_ViewWindow* viewWindow = app->desktop()->activeWindow();
348 bool aIsForced = true;
349 if(viewWindow->getViewManager()->getType() == SVTK_Viewer::Type())
352 GEOM_Displayer(anActiveStudy).Erase( listIO, aIsForced);
353 getGeometryGUI()->getApp()->selectionMgr()->clearSelected();
356 //=====================================================================================
357 // function : DisplayGUI::SetDisplayMode()
358 // purpose : Set display mode for the viewer (current viewer if <viewWindow> - 0 )
359 //=====================================================================================
360 void DisplayGUI::SetDisplayMode( const int mode, SUIT_ViewWindow* viewWindow )
362 SUIT_OverrideCursor();
365 viewWindow = getGeometryGUI()->getApp()->desktop()->activeWindow();
366 if ( viewWindow->getViewManager()->getType() == SVTK_Viewer::Type() ) {
367 SVTK_View* aView = ((SVTK_ViewWindow*)viewWindow)->getView();
368 aView->SetDisplayMode( mode );
369 GeometryGUI::Modified();
371 else if ( viewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() ) {
372 OCCViewer_Viewer* v3d = ((OCCViewer_ViewManager*)(viewWindow->getViewManager()))->getOCCViewer();
373 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
375 AIS_DisplayMode newmode;
378 newmode = AIS_WireFrame;
381 newmode = AIS_Shaded;
384 newmode = AIS_DisplayMode( GEOM_AISShape::ShadingWithEdges );
387 newmode = AIS_DisplayMode( GEOM_AISShape::TexturedShape );
393 AIS_ListOfInteractive List;
394 ic->DisplayedObjects( List );
395 AIS_ListOfInteractive List1;
396 ic->ObjectsInCollector( List1 );
397 List.Append( List1 );
399 AIS_ListIteratorOfListOfInteractive ite( List );
400 while( ite.More() ) {
401 if( ite.Value()->IsInstance( STANDARD_TYPE(GEOM_AISShape) ) ) {
402 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast( ite.Value() );
403 ic->SetDisplayMode( aSh, Standard_Integer( newmode ),true );
408 ic->SetDisplayMode( newmode, Standard_False );
410 GeometryGUI::Modified();
414 //=====================================================================================
415 // function : DisplayGUI::GetDisplayMode()
416 // purpose : Get display mode of the viewer (current viewer if <viewWindow> - 0 )
417 //=====================================================================================
418 int DisplayGUI::GetDisplayMode( SUIT_ViewWindow* viewWindow )
422 viewWindow = getGeometryGUI()->getApp()->desktop()->activeWindow();
423 if ( viewWindow->getViewManager()->getType() == SVTK_Viewer::Type() ) {
424 SVTK_View* aView = ((SVTK_ViewWindow*)viewWindow)->getView();
425 dispMode = aView->GetDisplayMode();
427 else if ( viewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() ) {
428 OCCViewer_Viewer* v3d = ((OCCViewer_ViewManager*)(viewWindow->getViewManager()))->getOCCViewer();
429 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
430 dispMode = ic->DisplayMode();
435 //=====================================================================================
436 // function : DisplayGUI::SetVectorsMode()
437 // purpose : Set vector mode for the viewer
438 //=====================================================================================
439 void DisplayGUI::SetVectorMode( const bool mode, SUIT_ViewWindow* viewWindow )
441 SUIT_OverrideCursor();
444 viewWindow = getGeometryGUI()->getApp()->desktop()->activeWindow();
445 if ( viewWindow->getViewManager()->getType() == SVTK_Viewer::Type() ) {
446 viewWindow->setProperty( "VectorsMode", mode );
447 SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>( viewWindow );
448 vtkActorCollection* allActors = vw->getRenderer()->GetActors();
449 allActors->InitTraversal();
450 while (vtkActor* actor = allActors->GetNextActor()) {
451 if (actor->GetVisibility()) { // only for visible actors
452 GEOM_Actor* aGeomActor = 0;
453 if ( actor->IsA( "GEOM_Actor" ) ) {
454 aGeomActor = GEOM_Actor::SafeDownCast( actor );
456 aGeomActor->SetVectorMode( mode );
460 GeometryGUI::Modified();
462 else if ( viewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() ) {
463 viewWindow->setProperty( "VectorsMode", mode );
464 OCCViewer_Viewer* v3d = ((OCCViewer_ViewManager*)(viewWindow->getViewManager()))->getOCCViewer();
465 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
466 AIS_ListOfInteractive List;
467 ic->DisplayedObjects( List );
468 AIS_ListOfInteractive List1;
469 ic->ObjectsInCollector( List1 );
470 List.Append( List1 );
472 AIS_ListIteratorOfListOfInteractive ite( List );
473 while( ite.More() ) {
474 if( ite.Value()->IsInstance( STANDARD_TYPE(GEOM_AISShape) ) ) {
475 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast( ite.Value() );
476 aSh->SetDisplayVectors(mode);
477 ic->RecomputePrsOnly(ite.Value());
481 GeometryGUI::Modified();
485 //=====================================================================================
486 // function : DisplayGUI::GetVectorMode()
487 // purpose : Get the "show edge direction" mode of the viewer
488 //=====================================================================================
489 int DisplayGUI::GetVectorMode( SUIT_ViewWindow* viewWindow )
492 viewWindow = getGeometryGUI()->getApp()->desktop()->activeWindow();
493 return viewWindow->property( "VectorsMode" ).toBool();
496 //=====================================================================================
497 // function : DisplayGUI::InvertDisplayMode()
498 // purpose : Invert display mode ( shading <-> wireframe ) for the viewer
499 // (current viewer if <viewWindow> = 0 )
500 //=====================================================================================
501 void DisplayGUI::InvertDisplayMode( SUIT_ViewWindow* viewWindow )
503 SetDisplayMode( 1 - GetDisplayMode( viewWindow ) );
506 //=====================================================================================
507 // function : DisplayGUI::ChangeDisplayMode()
508 // purpose : Set display mode for selected objects in the viewer given
509 // (current viewer if <viewWindow> = 0 )
510 //=====================================================================================
511 void DisplayGUI::ChangeDisplayMode( const int mode, SUIT_ViewWindow* viewWindow )
513 SalomeApp_Application* app = getGeometryGUI()->getApp();
517 viewWindow = app->desktop()->activeWindow();
519 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
520 if ( !aSelMgr ) return;
522 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
527 SUIT_OverrideCursor();
531 if ( viewWindow->getViewManager()->getType() == SVTK_Viewer::Type() ) {
532 SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>( viewWindow );
533 SVTK_View* aView = vw->getView();
534 int mgrId = viewWindow->getViewManager()->getGlobalId();
535 bool vectorMode = false;
537 aSelMgr->selectedObjects( aList );
538 SALOME_ListIteratorOfListIO It( aList );
540 for( ;It.More(); It.Next() ) {
541 SVTK_Viewer* stvkViewer = dynamic_cast<SVTK_Viewer*>(vw->getViewManager()->getViewModel());
543 stvkViewer ? dynamic_cast<SVTK_Prs*>( stvkViewer->CreatePrs( It.Value()->getEntry() ) ) : 0;
544 if ( vtkPrs && !vtkPrs->IsNull() ) {
546 aView->ChangeRepresentationToWireframe( vtkPrs->GetObjects() );
547 else if ( mode == 1 )
548 aView->ChangeRepresentationToSurface( vtkPrs->GetObjects() );
549 else if ( mode == 2 )
550 aView->ChangeRepresentationToSurfaceWithEdges( vtkPrs->GetObjects() );
551 else if ( mode == 4 ) {
552 vtkActorCollection* anActors = vtkPrs->GetObjects();
553 anActors->InitTraversal();
554 while (vtkActor* anAct = anActors->GetNextActor()) {
555 GEOM_Actor* aGeomActor = GEOM_Actor::SafeDownCast(anAct);
556 vectorMode = !aGeomActor->GetVectorMode();
557 aGeomActor->SetVectorMode(vectorMode);
560 if(mode == 0 || mode == 1 || mode == 2) {
561 aStudy->setObjectProperty(mgrId,It.Value()->getEntry(),DISPLAY_MODE_PROP, mode);
563 else if (mode == 4) {
564 aStudy->setObjectProperty(mgrId, It.Value()->getEntry(),VECTOR_MODE_PROP, vectorMode);
569 GeometryGUI::Modified();
571 else if ( viewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() ) {
572 OCCViewer_Viewer* v3d = ((OCCViewer_ViewManager*)(viewWindow->getViewManager()))->getOCCViewer();
573 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
575 aSelMgr->selectedObjects( aList );
576 SALOME_ListIteratorOfListIO It( aList );
577 int mgrId = viewWindow->getViewManager()->getGlobalId();
580 for( ;It.More(); It.Next() ) {
581 SOCC_Viewer* soccViewer = (SOCC_Viewer*)(viewWindow->getViewManager()->getViewModel());
582 SOCC_Prs* occPrs = dynamic_cast<SOCC_Prs*>( soccViewer->CreatePrs( It.Value()->getEntry() ) );
583 if ( occPrs && !occPrs->IsNull() ) {
584 AIS_ListOfInteractive shapes; occPrs->GetObjects( shapes );
585 AIS_ListIteratorOfListOfInteractive interIter( shapes );
586 for ( ; interIter.More(); interIter.Next() ) {
588 ic->SetDisplayMode( interIter.Value(), AIS_WireFrame, false );
589 else if ( mode == 1 )
590 ic->SetDisplayMode( interIter.Value(), AIS_Shaded, false );
591 else if ( mode == 2 )
592 ic->SetDisplayMode( interIter.Value(), GEOM_AISShape::ShadingWithEdges, false );
593 else if ( mode == 3 )
594 ic->SetDisplayMode( interIter.Value(), AIS_ExactHLR, false );
595 else if (mode == 4 ) {
596 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast( interIter.Value() );
597 if ( !aSh.IsNull() ) {
598 vectorMode = !aSh->isShowVectors();
599 aSh->SetDisplayVectors(vectorMode);
600 ic->RecomputePrsOnly(interIter.Value());
604 if(mode == 0 || mode == 1 || mode == 2 || mode == 3) {
605 aStudy->setObjectProperty(mgrId, It.Value()->getEntry(),DISPLAY_MODE_PROP, mode);
607 else if (mode == 4) {
608 aStudy->setObjectProperty(mgrId, It.Value()->getEntry(),VECTOR_MODE_PROP, vectorMode);
612 ic->UpdateCurrentViewer();
613 GeometryGUI::Modified();
617 //=====================================================================================
619 //=====================================================================================
623 __declspec( dllexport )
625 GEOMGUI* GetLibGUI( GeometryGUI* parent )
627 return new DisplayGUI( parent );