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 // 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 switch ( theCommandID ) {
96 case GEOMOp::OpDMWireframe: // MENU VIEW - DISPLAY MODE - WIREFRAME
99 case GEOMOp::OpDMShading: // MENU VIEW - DISPLAY MODE - SHADING
102 case GEOMOp::OpDMShadingWithEdges: // MENU VIEW - DISPLAY MODE - SHADING WITH EDGES
105 case GEOMOp::OpShowAll: // MENU VIEW - SHOW ALL
106 getGeometryGUI()->EmitSignalDeactivateDialog();
109 case GEOMOp::OpShowOnly: // POPUP MENU - SHOW ONLY
110 getGeometryGUI()->EmitSignalDeactivateDialog();
113 case GEOMOp::OpHideAll: // MENU VIEW - HIDE ALL
116 case GEOMOp::OpHide: // POPUP MENU - HIDE
119 case GEOMOp::OpShow: // POPUP MENU - SHOW
120 getGeometryGUI()->EmitSignalDeactivateDialog();
123 case GEOMOp::OpSwitchVectors: // MENU VIEW - DISPLAY MODE - SHOW EDGE DIRECTION
124 SetVectorMode(!GetVectorMode());
125 getGeometryGUI()->action( GEOMOp::OpSwitchVectors )->setText
126 ( GetVectorMode() ? tr("MEN_VECTOR_MODE_ON") : tr( "MEN_VECTOR_MODE_OFF" ) );
127 getGeometryGUI()->menuMgr()->update();
129 case GEOMOp::OpWireframe: // POPUP MENU - DISPLAY MODE - WIREFRAME
130 ChangeDisplayMode( 0 );
132 case GEOMOp::OpShading: // POPUP MENU - DISPLAY MODE - SHADING
133 ChangeDisplayMode( 1 );
135 case GEOMOp::OpShadingWithEdges: // POPUP MENU - DISPLAY MODE - SHADING WITH EDGES
136 ChangeDisplayMode( 2 );
138 case GEOMOp::OpTexture: // POPUP MENU - DISPLAY MODE - TEXTURE
139 ChangeDisplayMode( 3 );
141 case GEOMOp::OpVectors: // POPUP MENU - DISPLAY MODE - SHOW EDGE DIRECTION
142 ChangeDisplayMode( 4 );
145 app->putInfo(tr("GEOM_PRP_COMMAND").arg(theCommandID));
148 Sel->setSelectedObjects( selected );
152 //=====================================================================================
153 // function : DisplayGUI::DisplayAll()
154 // purpose : Display all GEOM objects
155 //=====================================================================================
156 void DisplayGUI::DisplayAll()
158 SalomeApp_Application* app = getGeometryGUI()->getApp();
161 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
162 if ( !appStudy ) return;
163 _PTR(Study) aStudy = appStudy->studyDS();
164 if ( !aStudy ) return;
165 _PTR(SComponent) SC ( aStudy->FindComponent( "GEOM" ) );
169 SALOME_ListIO listIO;
170 _PTR(ChildIterator) anIter ( aStudy->NewChildIterator( SC ) );
171 anIter->InitEx( true );
173 SUIT_OverrideCursor();
175 while( anIter->More() ) {
176 _PTR(SObject) valSO ( anIter->Value() );
178 if ( !valSO->ReferencedObject( refSO ) ) {
179 listIO.Append( new SALOME_InteractiveObject(valSO->GetID().c_str(),
180 SC->ComponentDataType().c_str(),
181 valSO->GetName().c_str()) );
185 GEOM_Displayer( appStudy ).Display( listIO, true );
188 //=====================================================================================
189 // function : DisplayGUI::EraseAll()
190 // purpose : Erase all GEOM objects
191 //=====================================================================================
192 void DisplayGUI::EraseAll()
194 SUIT_OverrideCursor();
196 SUIT_Application* app = getGeometryGUI()->getApp();
198 SUIT_ViewWindow* vw = app->desktop()->activeWindow();
200 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
201 SUIT_ViewManager* vman = vw->getViewManager();
202 if ( vman->getType() == OCCViewer_Viewer::Type() ||
203 vman->getType() == SVTK_Viewer::Type() ) {
204 GEOM_Displayer( appStudy ).EraseAll();
210 //=====================================================================================
211 // function : DisplayGUI::DisplayOnly()
212 // purpose : Display selected GEOM objects and erase other
213 //=====================================================================================
214 void DisplayGUI::DisplayOnly()
220 //=====================================================================================
221 // function : DisplayGUI::Display()
222 // purpose : Display selected GEOM objects
223 //=====================================================================================
224 void DisplayGUI::Display()
226 SALOME_ListIO listIO;
228 SalomeApp_Application* app = getGeometryGUI()->getApp();
231 SalomeApp_Study* anActiveStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
232 if ( !anActiveStudy ) return;
234 //get SalomeApp selection manager
235 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
236 if ( !aSelMgr ) return;
239 aSelMgr->selectedObjects( aList );
240 SALOME_ListIteratorOfListIO It( aList );
242 SUIT_OverrideCursor();
244 for( ;It.More();It.Next() ) {
245 Handle(SALOME_InteractiveObject) anIObject = It.Value();
246 if ( anIObject->hasEntry() ) {
247 _PTR(SObject) SO ( anActiveStudy->studyDS()->FindObjectID( anIObject->getEntry() ) );
248 if ( SO && QString(SO->GetID().c_str()) == QString(SO->GetFatherComponent()->GetID().c_str()) ) {
249 _PTR(SComponent) SC ( SO->GetFatherComponent() );
250 // if component is selected
252 _PTR(ChildIterator) anIter ( anActiveStudy->studyDS()->NewChildIterator( SO ) );
253 anIter->InitEx( true );
254 while( anIter->More() ) {
255 _PTR(SObject) valSO ( anIter->Value() );
257 if ( !valSO->ReferencedObject( refSO ) ) {
258 listIO.Append( new SALOME_InteractiveObject(valSO->GetID().c_str(),
259 SC->ComponentDataType().c_str(),
260 valSO->GetName().c_str()) );
267 listIO.Append( anIObject );
271 listIO.Append( anIObject );
274 GEOM_Displayer( anActiveStudy ).Display( listIO, true );
278 //=====================================================================================
279 // function : DisplayGUI::Erase()
280 // purpose : Erase selected GEOM objects
281 //=====================================================================================
282 void DisplayGUI::Erase()
284 SALOME_ListIO listIO;
286 SalomeApp_Application* app = getGeometryGUI()->getApp();
289 SalomeApp_Study* anActiveStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
290 if ( !anActiveStudy ) return;
292 //get SalomeApp selection manager
293 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
294 if ( !aSelMgr ) return;
297 aSelMgr->selectedObjects( aList );
298 SALOME_ListIteratorOfListIO It( aList );
300 SUIT_OverrideCursor();
302 for( ; It.More(); It.Next() ) {
303 Handle(SALOME_InteractiveObject) anIObject = It.Value();
304 if ( anIObject->hasEntry() ) {
305 _PTR(SObject) SO ( anActiveStudy->studyDS()->FindObjectID( anIObject->getEntry() ) );
306 if ( SO && QString(SO->GetID().c_str()) == QString(SO->GetFatherComponent()->GetID().c_str()) ) {
307 _PTR(SComponent) SC ( SO->GetFatherComponent() );
308 // if component is selected
310 _PTR(ChildIterator) anIter ( anActiveStudy->studyDS()->NewChildIterator( SO ) );
311 anIter->InitEx( true );
312 while( anIter->More() ) {
313 _PTR(SObject) valSO ( anIter->Value() );
315 if ( !valSO->ReferencedObject( refSO ) ) {
316 listIO.Append( new SALOME_InteractiveObject(valSO->GetID().c_str(),
317 SC->ComponentDataType().c_str(),
318 valSO->GetName().c_str()) );
325 listIO.Append( anIObject );
329 listIO.Append( anIObject );
333 SUIT_ViewWindow* viewWindow = app->desktop()->activeWindow();
334 bool aIsForced = true;
335 if(viewWindow->getViewManager()->getType() == SVTK_Viewer::Type())
338 GEOM_Displayer(anActiveStudy).Erase( listIO, aIsForced);
339 getGeometryGUI()->getApp()->selectionMgr()->clearSelected();
342 //=====================================================================================
343 // function : DisplayGUI::SetDisplayMode()
344 // purpose : Set display mode for the viewer (current viewer if <viewWindow> - 0 )
345 //=====================================================================================
346 void DisplayGUI::SetDisplayMode( const int mode, SUIT_ViewWindow* viewWindow )
348 SUIT_OverrideCursor();
351 viewWindow = getGeometryGUI()->getApp()->desktop()->activeWindow();
352 if ( viewWindow->getViewManager()->getType() == SVTK_Viewer::Type() ) {
353 SVTK_View* aView = ((SVTK_ViewWindow*)viewWindow)->getView();
354 aView->SetDisplayMode( mode );
355 GeometryGUI::Modified();
357 else if ( viewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() ) {
358 OCCViewer_Viewer* v3d = ((OCCViewer_ViewManager*)(viewWindow->getViewManager()))->getOCCViewer();
359 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
361 AIS_DisplayMode newmode;
364 newmode = AIS_WireFrame;
367 newmode = AIS_Shaded;
370 newmode = AIS_DisplayMode( GEOM_AISShape::ShadingWithEdges );
373 newmode = AIS_DisplayMode( GEOM_AISShape::TexturedShape );
379 AIS_ListOfInteractive List;
380 ic->DisplayedObjects( List );
381 AIS_ListOfInteractive List1;
382 ic->ObjectsInCollector( List1 );
383 List.Append( List1 );
385 AIS_ListIteratorOfListOfInteractive ite( List );
386 while( ite.More() ) {
387 if( ite.Value()->IsInstance( STANDARD_TYPE(GEOM_AISShape) ) ) {
388 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast( ite.Value() );
389 if(aSh->isTopLevel()) {
390 aSh->setPrevDisplayMode(Standard_Integer( newmode ));
393 ic->SetDisplayMode( aSh, Standard_Integer( newmode ),true );
399 ic->SetDisplayMode( newmode, Standard_False );
401 GeometryGUI::Modified();
405 //=====================================================================================
406 // function : DisplayGUI::SetVectorsMode()
407 // purpose : Set vector mode for the viewer
408 //=====================================================================================
409 void DisplayGUI::SetVectorMode( const bool mode, SUIT_ViewWindow* viewWindow )
411 SUIT_OverrideCursor();
414 viewWindow = getGeometryGUI()->getApp()->desktop()->activeWindow();
415 if ( viewWindow->getViewManager()->getType() == SVTK_Viewer::Type() ) {
416 viewWindow->setProperty( "VectorsMode", mode );
417 SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>( viewWindow );
418 vtkActorCollection* allActors = vw->getRenderer()->GetActors();
419 allActors->InitTraversal();
420 while (vtkActor* actor = allActors->GetNextActor()) {
421 if (actor->GetVisibility()) { // only for visible actors
422 GEOM_Actor* aGeomActor = 0;
423 if ( actor->IsA( "GEOM_Actor" ) ) {
424 aGeomActor = GEOM_Actor::SafeDownCast( actor );
426 aGeomActor->SetVectorMode( mode );
430 GeometryGUI::Modified();
432 else if ( viewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() ) {
433 viewWindow->setProperty( "VectorsMode", mode );
434 OCCViewer_Viewer* v3d = ((OCCViewer_ViewManager*)(viewWindow->getViewManager()))->getOCCViewer();
435 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
436 AIS_ListOfInteractive List;
437 ic->DisplayedObjects( List );
438 AIS_ListOfInteractive List1;
439 ic->ObjectsInCollector( List1 );
440 List.Append( List1 );
442 AIS_ListIteratorOfListOfInteractive ite( List );
443 while( ite.More() ) {
444 if( ite.Value()->IsInstance( STANDARD_TYPE(GEOM_AISShape) ) ) {
445 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast( ite.Value() );
446 aSh->SetDisplayVectors(mode);
447 ic->RecomputePrsOnly(ite.Value());
451 GeometryGUI::Modified();
455 //=====================================================================================
456 // function : DisplayGUI::GetVectorMode()
457 // purpose : Get the "show edge direction" mode of the viewer
458 //=====================================================================================
459 int DisplayGUI::GetVectorMode( SUIT_ViewWindow* viewWindow )
462 viewWindow = getGeometryGUI()->getApp()->desktop()->activeWindow();
463 return viewWindow->property( "VectorsMode" ).toBool();
466 //=====================================================================================
467 // function : DisplayGUI::ChangeDisplayMode()
468 // purpose : Set display mode for selected objects in the viewer given
469 // (current viewer if <viewWindow> = 0 )
470 //=====================================================================================
471 void DisplayGUI::ChangeDisplayMode( const int mode, SUIT_ViewWindow* viewWindow )
473 SalomeApp_Application* app = getGeometryGUI()->getApp();
477 viewWindow = app->desktop()->activeWindow();
479 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
480 if ( !aSelMgr ) return;
482 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
487 SUIT_OverrideCursor();
491 if ( viewWindow->getViewManager()->getType() == SVTK_Viewer::Type() ) {
492 SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>( viewWindow );
493 SVTK_View* aView = vw->getView();
494 int mgrId = viewWindow->getViewManager()->getGlobalId();
495 bool vectorMode = false;
497 aSelMgr->selectedObjects( aList );
498 SALOME_ListIteratorOfListIO It( aList );
500 for( ;It.More(); It.Next() ) {
501 SVTK_Viewer* stvkViewer = dynamic_cast<SVTK_Viewer*>(vw->getViewManager()->getViewModel());
503 stvkViewer ? dynamic_cast<SVTK_Prs*>( stvkViewer->CreatePrs( It.Value()->getEntry() ) ) : 0;
504 if ( vtkPrs && !vtkPrs->IsNull() ) {
506 aView->ChangeRepresentationToWireframe( vtkPrs->GetObjects() );
507 else if ( mode == 1 )
508 aView->ChangeRepresentationToSurface( vtkPrs->GetObjects() );
509 else if ( mode == 2 )
510 aView->ChangeRepresentationToSurfaceWithEdges( vtkPrs->GetObjects() );
511 else if ( mode == 4 ) {
512 vtkActorCollection* anActors = vtkPrs->GetObjects();
513 anActors->InitTraversal();
514 while (vtkActor* anAct = anActors->GetNextActor()) {
515 GEOM_Actor* aGeomActor = GEOM_Actor::SafeDownCast(anAct);
516 vectorMode = !aGeomActor->GetVectorMode();
517 aGeomActor->SetVectorMode(vectorMode);
520 if(mode == 0 || mode == 1 || mode == 2) {
521 aStudy->setObjectProperty(mgrId,It.Value()->getEntry(),DISPLAY_MODE_PROP, mode);
523 else if (mode == 4) {
524 aStudy->setObjectProperty(mgrId, It.Value()->getEntry(),VECTOR_MODE_PROP, vectorMode);
529 GeometryGUI::Modified();
531 else if ( viewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() ) {
532 OCCViewer_Viewer* v3d = ((OCCViewer_ViewManager*)(viewWindow->getViewManager()))->getOCCViewer();
533 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
535 aSelMgr->selectedObjects( aList );
536 SALOME_ListIteratorOfListIO It( aList );
537 int mgrId = viewWindow->getViewManager()->getGlobalId();
540 for( ;It.More(); It.Next() ) {
541 SOCC_Viewer* soccViewer = (SOCC_Viewer*)(viewWindow->getViewManager()->getViewModel());
542 SOCC_Prs* occPrs = dynamic_cast<SOCC_Prs*>( soccViewer->CreatePrs( It.Value()->getEntry() ) );
543 if ( occPrs && !occPrs->IsNull() ) {
544 AIS_ListOfInteractive shapes; occPrs->GetObjects( shapes );
545 AIS_ListIteratorOfListOfInteractive interIter( shapes );
546 for ( ; interIter.More(); interIter.Next() ) {
547 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast( interIter.Value() );
548 if ( !aSh.IsNull() ) {
549 if(!aSh->isTopLevel()) {
551 ic->SetDisplayMode( interIter.Value(), AIS_WireFrame, false );
552 else if ( mode == 1 )
553 ic->SetDisplayMode( interIter.Value(), AIS_Shaded, false );
554 else if ( mode == 2 )
555 ic->SetDisplayMode( interIter.Value(), GEOM_AISShape::ShadingWithEdges, false );
556 else if ( mode == 3 )
557 ic->SetDisplayMode( interIter.Value(), AIS_ExactHLR, false );
559 aSh->setPrevDisplayMode(mode);
562 vectorMode = !aSh->isShowVectors();
563 aSh->SetDisplayVectors(vectorMode);
564 ic->RecomputePrsOnly(interIter.Value());
568 if(mode == 0 || mode == 1 || mode == 2 || mode == 3) {
569 aStudy->setObjectProperty(mgrId, It.Value()->getEntry(),DISPLAY_MODE_PROP, mode);
571 else if (mode == 4) {
572 aStudy->setObjectProperty(mgrId, It.Value()->getEntry(),VECTOR_MODE_PROP, vectorMode);
576 ic->UpdateCurrentViewer();
577 GeometryGUI::Modified();
581 //=====================================================================================
583 //=====================================================================================
587 __declspec( dllexport )
589 GEOMGUI* GetLibGUI( GeometryGUI* parent )
591 return new DisplayGUI( parent );