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_Displayer.h>
31 #include <GEOM_AISShape.hxx>
32 #include <GEOM_Actor.h>
34 #include <SUIT_Desktop.h>
35 #include <SUIT_ViewWindow.h>
36 #include <SUIT_OverrideCursor.h>
38 #include <OCCViewer_ViewManager.h>
39 #include <OCCViewer_ViewModel.h>
41 #include <SALOME_ListIO.hxx>
42 #include <SALOME_ListIteratorOfListIO.hxx>
44 #include <SVTK_ViewWindow.h>
45 #include <SVTK_View.h>
46 #include <SVTK_ViewModel.h>
47 #include <SOCC_ViewModel.h>
51 #include <QtxActionMenuMgr.h>
53 #include <SalomeApp_Application.h>
54 #include <LightApp_SelectionMgr.h>
55 #include <SalomeApp_Study.h>
57 #include <AIS_ListIteratorOfListOfInteractive.hxx>
59 #include <vtkActorCollection.h>
60 #include <vtkRenderer.h>
64 //=======================================================================
65 // function : DisplayGUI::DisplayGUI()
66 // purpose : Constructor
67 //=======================================================================
68 DisplayGUI::DisplayGUI( GeometryGUI* parent ) : GEOMGUI( parent )
72 //=======================================================================
73 // function : DisplayGUI::~DisplayGUI()
74 // purpose : Destructor
75 //=======================================================================
76 DisplayGUI::~DisplayGUI()
81 //=======================================================================
82 // function : DisplayGUI::OnGUIEvent()
83 // purpose : Dispatch menu command
84 //=======================================================================
85 bool DisplayGUI::OnGUIEvent(int theCommandID, SUIT_Desktop* parent)
87 SalomeApp_Application* app = getGeometryGUI()->getApp();
88 if (!app) return false;
90 LightApp_SelectionMgr *Sel = app->selectionMgr();
91 SALOME_ListIO selected;
92 Sel->selectedObjects( selected );
94 switch ( theCommandID ) {
95 case GEOMOp::OpDisplayMode: // MENU VIEW - DISPLAY MODE - WIREFRAME/SHADING
97 getGeometryGUI()->action( GEOMOp::OpDisplayMode )->setText
98 ( GetDisplayMode() == 1 ? tr( "GEOM_MEN_WIREFRAME" ) : tr("GEOM_MEN_SHADING") );
99 getGeometryGUI()->menuMgr()->update();
101 case GEOMOp::OpShowAll: // MENU VIEW - SHOW ALL
102 getGeometryGUI()->EmitSignalDeactivateDialog();
105 case GEOMOp::OpShowOnly: // POPUP MENU - SHOW ONLY
106 getGeometryGUI()->EmitSignalDeactivateDialog();
109 case GEOMOp::OpHideAll: // MENU VIEW - HIDE ALL
112 case GEOMOp::OpHide: // POPUP MENU - HIDE
115 case GEOMOp::OpShow: // POPUP MENU - SHOW
116 getGeometryGUI()->EmitSignalDeactivateDialog();
119 case GEOMOp::OpSwitchVectors: // MENU VIEW - DISPLAY MODE - SHOW EDGE DIRECTION
120 SetVectorMode(!GetVectorMode());
121 getGeometryGUI()->action( GEOMOp::OpSwitchVectors )->setText
122 ( GetVectorMode() ? tr("MEN_VECTOR_MODE_ON") : tr( "MEN_VECTOR_MODE_OFF" ) );
123 getGeometryGUI()->menuMgr()->update();
125 case GEOMOp::OpWireframe: // POPUP MENU - DISPLAY MODE - WIREFRAME
126 ChangeDisplayMode( 0 );
128 case GEOMOp::OpShading: // POPUP MENU - DISPLAY MODE - SHADING
129 ChangeDisplayMode( 1 );
131 case GEOMOp::OpVectors: // POPUP MENU - DISPLAY MODE - SHOW EDGE DIRECTION
132 ChangeDisplayMode( 2 );
135 app->putInfo(tr("GEOM_PRP_COMMAND").arg(theCommandID));
138 Sel->setSelectedObjects( selected );
142 //=====================================================================================
143 // function : DisplayGUI::DisplayAll()
144 // purpose : Display all GEOM objects
145 //=====================================================================================
146 void DisplayGUI::DisplayAll()
148 SalomeApp_Application* app = getGeometryGUI()->getApp();
151 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
152 if ( !appStudy ) return;
153 _PTR(Study) aStudy = appStudy->studyDS();
154 if ( !aStudy ) return;
155 _PTR(SComponent) SC ( aStudy->FindComponent( "GEOM" ) );
159 SALOME_ListIO listIO;
160 _PTR(ChildIterator) anIter ( aStudy->NewChildIterator( SC ) );
161 anIter->InitEx( true );
163 SUIT_OverrideCursor();
165 while( anIter->More() ) {
166 _PTR(SObject) valSO ( anIter->Value() );
168 if ( !valSO->ReferencedObject( refSO ) ) {
169 listIO.Append( new SALOME_InteractiveObject(valSO->GetID().c_str(),
170 SC->ComponentDataType().c_str(),
171 valSO->GetName().c_str()) );
175 GEOM_Displayer( appStudy ).Display( listIO, true );
178 //=====================================================================================
179 // function : DisplayGUI::EraseAll()
180 // purpose : Erase all GEOM objects
181 //=====================================================================================
182 void DisplayGUI::EraseAll()
184 SUIT_OverrideCursor();
186 SUIT_Application* app = getGeometryGUI()->getApp();
188 SUIT_ViewWindow* vw = app->desktop()->activeWindow();
190 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
191 SUIT_ViewManager* vman = vw->getViewManager();
192 if ( vman->getType() == OCCViewer_Viewer::Type() ||
193 vman->getType() == SVTK_Viewer::Type() ) {
194 GEOM_Displayer( appStudy ).EraseAll();
200 //=====================================================================================
201 // function : DisplayGUI::DisplayOnly()
202 // purpose : Display selected GEOM objects and erase other
203 //=====================================================================================
204 void DisplayGUI::DisplayOnly()
210 //=====================================================================================
211 // function : DisplayGUI::Display()
212 // purpose : Display selected GEOM objects
213 //=====================================================================================
214 void DisplayGUI::Display()
216 SALOME_ListIO listIO;
218 SalomeApp_Application* app = getGeometryGUI()->getApp();
221 SalomeApp_Study* anActiveStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
222 if ( !anActiveStudy ) return;
224 //get SalomeApp selection manager
225 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
226 if ( !aSelMgr ) return;
229 aSelMgr->selectedObjects( aList );
230 SALOME_ListIteratorOfListIO It( aList );
232 SUIT_OverrideCursor();
234 for( ;It.More();It.Next() ) {
235 Handle(SALOME_InteractiveObject) anIObject = It.Value();
236 if ( anIObject->hasEntry() ) {
237 _PTR(SObject) SO ( anActiveStudy->studyDS()->FindObjectID( anIObject->getEntry() ) );
238 if ( SO && QString(SO->GetID().c_str()) == QString(SO->GetFatherComponent()->GetID().c_str()) ) {
239 _PTR(SComponent) SC ( SO->GetFatherComponent() );
240 // if component is selected
242 _PTR(ChildIterator) anIter ( anActiveStudy->studyDS()->NewChildIterator( SO ) );
243 anIter->InitEx( true );
244 while( anIter->More() ) {
245 _PTR(SObject) valSO ( anIter->Value() );
247 if ( !valSO->ReferencedObject( refSO ) ) {
248 listIO.Append( new SALOME_InteractiveObject(valSO->GetID().c_str(),
249 SC->ComponentDataType().c_str(),
250 valSO->GetName().c_str()) );
257 listIO.Append( anIObject );
261 listIO.Append( anIObject );
264 GEOM_Displayer( anActiveStudy ).Display( listIO, true );
268 //=====================================================================================
269 // function : DisplayGUI::Erase()
270 // purpose : Erase selected GEOM objects
271 //=====================================================================================
272 void DisplayGUI::Erase()
274 SALOME_ListIO listIO;
276 SalomeApp_Application* app = getGeometryGUI()->getApp();
279 SalomeApp_Study* anActiveStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
280 if ( !anActiveStudy ) return;
282 //get SalomeApp selection manager
283 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
284 if ( !aSelMgr ) return;
287 aSelMgr->selectedObjects( aList );
288 SALOME_ListIteratorOfListIO It( aList );
290 SUIT_OverrideCursor();
292 for( ; It.More(); It.Next() ) {
293 Handle(SALOME_InteractiveObject) anIObject = It.Value();
294 if ( anIObject->hasEntry() ) {
295 _PTR(SObject) SO ( anActiveStudy->studyDS()->FindObjectID( anIObject->getEntry() ) );
296 if ( SO && QString(SO->GetID().c_str()) == QString(SO->GetFatherComponent()->GetID().c_str()) ) {
297 _PTR(SComponent) SC ( SO->GetFatherComponent() );
298 // if component is selected
300 _PTR(ChildIterator) anIter ( anActiveStudy->studyDS()->NewChildIterator( SO ) );
301 anIter->InitEx( true );
302 while( anIter->More() ) {
303 _PTR(SObject) valSO ( anIter->Value() );
305 if ( !valSO->ReferencedObject( refSO ) ) {
306 listIO.Append( new SALOME_InteractiveObject(valSO->GetID().c_str(),
307 SC->ComponentDataType().c_str(),
308 valSO->GetName().c_str()) );
315 listIO.Append( anIObject );
319 listIO.Append( anIObject );
323 SUIT_ViewWindow* viewWindow = app->desktop()->activeWindow();
324 bool aIsForced = true;
325 if(viewWindow->getViewManager()->getType() == SVTK_Viewer::Type())
328 GEOM_Displayer(anActiveStudy).Erase( listIO, aIsForced);
329 getGeometryGUI()->getApp()->selectionMgr()->clearSelected();
332 //=====================================================================================
333 // function : DisplayGUI::SetDisplayMode()
334 // purpose : Set display mode for the viewer (current viewer if <viewWindow> - 0 )
335 //=====================================================================================
336 void DisplayGUI::SetDisplayMode( const int mode, SUIT_ViewWindow* viewWindow )
338 SUIT_OverrideCursor();
341 viewWindow = getGeometryGUI()->getApp()->desktop()->activeWindow();
342 if ( viewWindow->getViewManager()->getType() == SVTK_Viewer::Type() ) {
343 SVTK_View* aView = ((SVTK_ViewWindow*)viewWindow)->getView();
344 aView->SetDisplayMode( mode );
345 GeometryGUI::Modified();
347 else if ( viewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() ) {
348 OCCViewer_Viewer* v3d = ((OCCViewer_ViewManager*)(viewWindow->getViewManager()))->getOCCViewer();
349 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
350 AIS_DisplayMode newmode = (mode == 1 ? AIS_Shaded : AIS_WireFrame);
351 AIS_ListOfInteractive List;
352 ic->DisplayedObjects( List );
353 AIS_ListOfInteractive List1;
354 ic->ObjectsInCollector( List1 );
355 List.Append( List1 );
357 AIS_ListIteratorOfListOfInteractive ite( List );
358 while( ite.More() ) {
359 if( ite.Value()->IsInstance( STANDARD_TYPE(GEOM_AISShape) ) ) {
360 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast( ite.Value() );
361 ic->SetDisplayMode( aSh, Standard_Integer( newmode ),true );
366 ic->SetDisplayMode( newmode, Standard_False );
367 GeometryGUI::Modified();
371 //=====================================================================================
372 // function : DisplayGUI::GetDisplayMode()
373 // purpose : Get display mode of the viewer (current viewer if <viewWindow> - 0 )
374 //=====================================================================================
375 int DisplayGUI::GetDisplayMode( SUIT_ViewWindow* viewWindow )
379 viewWindow = getGeometryGUI()->getApp()->desktop()->activeWindow();
380 if ( viewWindow->getViewManager()->getType() == SVTK_Viewer::Type() ) {
381 SVTK_View* aView = ((SVTK_ViewWindow*)viewWindow)->getView();
382 dispMode = aView->GetDisplayMode();
384 else if ( viewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() ) {
385 OCCViewer_Viewer* v3d = ((OCCViewer_ViewManager*)(viewWindow->getViewManager()))->getOCCViewer();
386 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
387 AIS_DisplayMode mode = (AIS_DisplayMode)ic->DisplayMode();
388 dispMode = (mode == AIS_WireFrame ? 0 : 1 );
393 //=====================================================================================
394 // function : DisplayGUI::SetVectorsMode()
395 // purpose : Set vector mode for the viewer
396 //=====================================================================================
397 void DisplayGUI::SetVectorMode( const bool mode, SUIT_ViewWindow* viewWindow )
399 SUIT_OverrideCursor();
402 viewWindow = getGeometryGUI()->getApp()->desktop()->activeWindow();
403 if ( viewWindow->getViewManager()->getType() == SVTK_Viewer::Type() ) {
404 viewWindow->setProperty( "VectorsMode", mode );
405 SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>( viewWindow );
406 vtkActorCollection* allActors = vw->getRenderer()->GetActors();
407 allActors->InitTraversal();
408 while (vtkActor* actor = allActors->GetNextActor()) {
409 if (actor->GetVisibility()) { // only for visible actors
410 GEOM_Actor* aGeomActor = 0;
411 if ( actor->IsA( "GEOM_Actor" ) ) {
412 aGeomActor = GEOM_Actor::SafeDownCast( actor );
414 aGeomActor->SetVectorMode( mode );
418 GeometryGUI::Modified();
420 else if ( viewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() ) {
421 viewWindow->setProperty( "VectorsMode", mode );
422 OCCViewer_Viewer* v3d = ((OCCViewer_ViewManager*)(viewWindow->getViewManager()))->getOCCViewer();
423 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
424 AIS_ListOfInteractive List;
425 ic->DisplayedObjects( List );
426 AIS_ListOfInteractive List1;
427 ic->ObjectsInCollector( List1 );
428 List.Append( List1 );
430 AIS_ListIteratorOfListOfInteractive ite( List );
431 while( ite.More() ) {
432 if( ite.Value()->IsInstance( STANDARD_TYPE(GEOM_AISShape) ) ) {
433 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast( ite.Value() );
434 aSh->SetDisplayVectors(mode);
435 ic->RecomputePrsOnly(ite.Value());
439 GeometryGUI::Modified();
443 //=====================================================================================
444 // function : DisplayGUI::GetVectorMode()
445 // purpose : Get the "show edge direction" mode of the viewer
446 //=====================================================================================
447 int DisplayGUI::GetVectorMode( SUIT_ViewWindow* viewWindow )
450 viewWindow = getGeometryGUI()->getApp()->desktop()->activeWindow();
451 return viewWindow->property( "VectorsMode" ).toBool();
454 //=====================================================================================
455 // function : DisplayGUI::InvertDisplayMode()
456 // purpose : Invert display mode ( shadin <-> wireframe ) for the viewer
457 // (current viewer if <viewWindow> = 0 )
458 //=====================================================================================
459 void DisplayGUI::InvertDisplayMode( SUIT_ViewWindow* viewWindow )
461 SetDisplayMode( 1 - GetDisplayMode( viewWindow ) );
464 //=====================================================================================
465 // function : DisplayGUI::ChangeDisplayMode()
466 // purpose : Set display mode for selected objects in the viewer given
467 // (current viewer if <viewWindow> = 0 )
468 //=====================================================================================
469 void DisplayGUI::ChangeDisplayMode( const int mode, SUIT_ViewWindow* viewWindow )
471 SalomeApp_Application* app = getGeometryGUI()->getApp();
475 viewWindow = app->desktop()->activeWindow();
477 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
478 if ( !aSelMgr ) return;
480 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
485 SUIT_OverrideCursor();
489 if ( viewWindow->getViewManager()->getType() == SVTK_Viewer::Type() ) {
490 SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>( viewWindow );
491 SVTK_View* aView = vw->getView();
492 int mgrId = viewWindow->getViewManager()->getGlobalId();
493 bool vectorMode = false;
495 aSelMgr->selectedObjects( aList );
496 SALOME_ListIteratorOfListIO It( aList );
498 for( ;It.More(); It.Next() ) {
499 SVTK_Viewer* stvkViewer = dynamic_cast<SVTK_Viewer*>(vw->getViewManager()->getViewModel());
501 stvkViewer ? dynamic_cast<SVTK_Prs*>( stvkViewer->CreatePrs( It.Value()->getEntry() ) ) : 0;
502 if ( vtkPrs && !vtkPrs->IsNull() ) {
504 aView->ChangeRepresentationToWireframe( vtkPrs->GetObjects() );
505 else if ( mode == 1 )
506 aView->ChangeRepresentationToSurface( vtkPrs->GetObjects() );
507 else if ( mode == 2 ) {
508 vtkActorCollection* anActors = vtkPrs->GetObjects();
509 anActors->InitTraversal();
510 while (vtkActor* anAct = anActors->GetNextActor()) {
511 GEOM_Actor* aGeomActor = GEOM_Actor::SafeDownCast(anAct);
512 vectorMode = !aGeomActor->GetVectorMode();
513 aGeomActor->SetVectorMode(vectorMode);
516 if(mode == 0 || mode == 1) {
517 aStudy->setObjectProperty(mgrId,It.Value()->getEntry(),DISPLAY_MODE_PROP, mode);
518 } else if (mode == 3) {
519 aStudy->setObjectProperty(mgrId, It.Value()->getEntry(),VECTOR_MODE_PROP , vectorMode);
524 GeometryGUI::Modified();
526 else if ( viewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() ) {
527 OCCViewer_Viewer* v3d = ((OCCViewer_ViewManager*)(viewWindow->getViewManager()))->getOCCViewer();
528 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
530 aSelMgr->selectedObjects( aList );
531 SALOME_ListIteratorOfListIO It( aList );
532 int mgrId = viewWindow->getViewManager()->getGlobalId();
535 for( ;It.More(); It.Next() ) {
536 SOCC_Viewer* soccViewer = (SOCC_Viewer*)(viewWindow->getViewManager()->getViewModel());
537 SOCC_Prs* occPrs = dynamic_cast<SOCC_Prs*>( soccViewer->CreatePrs( It.Value()->getEntry() ) );
538 if ( occPrs && !occPrs->IsNull() ) {
539 AIS_ListOfInteractive shapes; occPrs->GetObjects( shapes );
540 AIS_ListIteratorOfListOfInteractive interIter( shapes );
541 for ( ; interIter.More(); interIter.Next() ) {
543 ic->SetDisplayMode( interIter.Value(), AIS_WireFrame, false );
544 else if ( mode == 1 )
545 ic->SetDisplayMode( interIter.Value(), AIS_Shaded, false );
547 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast( interIter.Value() );
548 if ( !aSh.IsNull() ) {
549 vectorMode = !aSh->isShowVectors();
550 aSh->SetDisplayVectors(vectorMode);
551 ic->RecomputePrsOnly(interIter.Value());
555 if(mode == 0 || mode == 1) {
556 aStudy->setObjectProperty(mgrId, It.Value()->getEntry(),DISPLAY_MODE_PROP, mode);
557 } else if (mode == 2) {
558 aStudy->setObjectProperty(mgrId, It.Value()->getEntry(),VECTOR_MODE_PROP, vectorMode);
562 ic->UpdateCurrentViewer();
563 GeometryGUI::Modified();
567 //=====================================================================================
569 //=====================================================================================
573 __declspec( dllexport )
575 GEOMGUI* GetLibGUI( GeometryGUI* parent )
577 return new DisplayGUI( parent );