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::OpTexture: // POPUP MENU - DISPLAY MODE - TEXTURE
132 ChangeDisplayMode( 3 );
134 case GEOMOp::OpVectors: // POPUP MENU - DISPLAY MODE - SHOW EDGE DIRECTION
135 ChangeDisplayMode( 2 );
138 app->putInfo(tr("GEOM_PRP_COMMAND").arg(theCommandID));
141 Sel->setSelectedObjects( selected );
145 //=====================================================================================
146 // function : DisplayGUI::DisplayAll()
147 // purpose : Display all GEOM objects
148 //=====================================================================================
149 void DisplayGUI::DisplayAll()
151 SalomeApp_Application* app = getGeometryGUI()->getApp();
154 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
155 if ( !appStudy ) return;
156 _PTR(Study) aStudy = appStudy->studyDS();
157 if ( !aStudy ) return;
158 _PTR(SComponent) SC ( aStudy->FindComponent( "GEOM" ) );
162 SALOME_ListIO listIO;
163 _PTR(ChildIterator) anIter ( aStudy->NewChildIterator( SC ) );
164 anIter->InitEx( true );
166 SUIT_OverrideCursor();
168 while( anIter->More() ) {
169 _PTR(SObject) valSO ( anIter->Value() );
171 if ( !valSO->ReferencedObject( refSO ) ) {
172 listIO.Append( new SALOME_InteractiveObject(valSO->GetID().c_str(),
173 SC->ComponentDataType().c_str(),
174 valSO->GetName().c_str()) );
178 GEOM_Displayer( appStudy ).Display( listIO, true );
181 //=====================================================================================
182 // function : DisplayGUI::EraseAll()
183 // purpose : Erase all GEOM objects
184 //=====================================================================================
185 void DisplayGUI::EraseAll()
187 SUIT_OverrideCursor();
189 SUIT_Application* app = getGeometryGUI()->getApp();
191 SUIT_ViewWindow* vw = app->desktop()->activeWindow();
193 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
194 SUIT_ViewManager* vman = vw->getViewManager();
195 if ( vman->getType() == OCCViewer_Viewer::Type() ||
196 vman->getType() == SVTK_Viewer::Type() ) {
197 GEOM_Displayer( appStudy ).EraseAll();
203 //=====================================================================================
204 // function : DisplayGUI::DisplayOnly()
205 // purpose : Display selected GEOM objects and erase other
206 //=====================================================================================
207 void DisplayGUI::DisplayOnly()
213 //=====================================================================================
214 // function : DisplayGUI::Display()
215 // purpose : Display selected GEOM objects
216 //=====================================================================================
217 void DisplayGUI::Display()
219 SALOME_ListIO listIO;
221 SalomeApp_Application* app = getGeometryGUI()->getApp();
224 SalomeApp_Study* anActiveStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
225 if ( !anActiveStudy ) return;
227 //get SalomeApp selection manager
228 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
229 if ( !aSelMgr ) return;
232 aSelMgr->selectedObjects( aList );
233 SALOME_ListIteratorOfListIO It( aList );
235 SUIT_OverrideCursor();
237 for( ;It.More();It.Next() ) {
238 Handle(SALOME_InteractiveObject) anIObject = It.Value();
239 if ( anIObject->hasEntry() ) {
240 _PTR(SObject) SO ( anActiveStudy->studyDS()->FindObjectID( anIObject->getEntry() ) );
241 if ( SO && QString(SO->GetID().c_str()) == QString(SO->GetFatherComponent()->GetID().c_str()) ) {
242 _PTR(SComponent) SC ( SO->GetFatherComponent() );
243 // if component is selected
245 _PTR(ChildIterator) anIter ( anActiveStudy->studyDS()->NewChildIterator( SO ) );
246 anIter->InitEx( true );
247 while( anIter->More() ) {
248 _PTR(SObject) valSO ( anIter->Value() );
250 if ( !valSO->ReferencedObject( refSO ) ) {
251 listIO.Append( new SALOME_InteractiveObject(valSO->GetID().c_str(),
252 SC->ComponentDataType().c_str(),
253 valSO->GetName().c_str()) );
260 listIO.Append( anIObject );
264 listIO.Append( anIObject );
267 GEOM_Displayer( anActiveStudy ).Display( listIO, true );
271 //=====================================================================================
272 // function : DisplayGUI::Erase()
273 // purpose : Erase selected GEOM objects
274 //=====================================================================================
275 void DisplayGUI::Erase()
277 SALOME_ListIO listIO;
279 SalomeApp_Application* app = getGeometryGUI()->getApp();
282 SalomeApp_Study* anActiveStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
283 if ( !anActiveStudy ) return;
285 //get SalomeApp selection manager
286 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
287 if ( !aSelMgr ) return;
290 aSelMgr->selectedObjects( aList );
291 SALOME_ListIteratorOfListIO It( aList );
293 SUIT_OverrideCursor();
295 for( ; It.More(); It.Next() ) {
296 Handle(SALOME_InteractiveObject) anIObject = It.Value();
297 if ( anIObject->hasEntry() ) {
298 _PTR(SObject) SO ( anActiveStudy->studyDS()->FindObjectID( anIObject->getEntry() ) );
299 if ( SO && QString(SO->GetID().c_str()) == QString(SO->GetFatherComponent()->GetID().c_str()) ) {
300 _PTR(SComponent) SC ( SO->GetFatherComponent() );
301 // if component is selected
303 _PTR(ChildIterator) anIter ( anActiveStudy->studyDS()->NewChildIterator( SO ) );
304 anIter->InitEx( true );
305 while( anIter->More() ) {
306 _PTR(SObject) valSO ( anIter->Value() );
308 if ( !valSO->ReferencedObject( refSO ) ) {
309 listIO.Append( new SALOME_InteractiveObject(valSO->GetID().c_str(),
310 SC->ComponentDataType().c_str(),
311 valSO->GetName().c_str()) );
318 listIO.Append( anIObject );
322 listIO.Append( anIObject );
326 SUIT_ViewWindow* viewWindow = app->desktop()->activeWindow();
327 bool aIsForced = true;
328 if(viewWindow->getViewManager()->getType() == SVTK_Viewer::Type())
331 GEOM_Displayer(anActiveStudy).Erase( listIO, aIsForced);
332 getGeometryGUI()->getApp()->selectionMgr()->clearSelected();
335 //=====================================================================================
336 // function : DisplayGUI::SetDisplayMode()
337 // purpose : Set display mode for the viewer (current viewer if <viewWindow> - 0 )
338 //=====================================================================================
339 void DisplayGUI::SetDisplayMode( const int mode, SUIT_ViewWindow* viewWindow )
341 SUIT_OverrideCursor();
344 viewWindow = getGeometryGUI()->getApp()->desktop()->activeWindow();
345 if ( viewWindow->getViewManager()->getType() == SVTK_Viewer::Type() ) {
346 SVTK_View* aView = ((SVTK_ViewWindow*)viewWindow)->getView();
347 aView->SetDisplayMode( mode );
348 GeometryGUI::Modified();
350 else if ( viewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() ) {
351 OCCViewer_Viewer* v3d = ((OCCViewer_ViewManager*)(viewWindow->getViewManager()))->getOCCViewer();
352 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
353 AIS_DisplayMode newmode = (mode == 1 ? AIS_Shaded : AIS_WireFrame);
354 AIS_ListOfInteractive List;
355 ic->DisplayedObjects( List );
356 AIS_ListOfInteractive List1;
357 ic->ObjectsInCollector( List1 );
358 List.Append( List1 );
360 AIS_ListIteratorOfListOfInteractive ite( List );
361 while( ite.More() ) {
362 if( ite.Value()->IsInstance( STANDARD_TYPE(GEOM_AISShape) ) ) {
363 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast( ite.Value() );
364 ic->SetDisplayMode( aSh, Standard_Integer( newmode ),true );
369 ic->SetDisplayMode( newmode, Standard_False );
370 GeometryGUI::Modified();
374 //=====================================================================================
375 // function : DisplayGUI::GetDisplayMode()
376 // purpose : Get display mode of the viewer (current viewer if <viewWindow> - 0 )
377 //=====================================================================================
378 int DisplayGUI::GetDisplayMode( SUIT_ViewWindow* viewWindow )
382 viewWindow = getGeometryGUI()->getApp()->desktop()->activeWindow();
383 if ( viewWindow->getViewManager()->getType() == SVTK_Viewer::Type() ) {
384 SVTK_View* aView = ((SVTK_ViewWindow*)viewWindow)->getView();
385 dispMode = aView->GetDisplayMode();
387 else if ( viewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() ) {
388 OCCViewer_Viewer* v3d = ((OCCViewer_ViewManager*)(viewWindow->getViewManager()))->getOCCViewer();
389 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
390 AIS_DisplayMode mode = (AIS_DisplayMode)ic->DisplayMode();
391 dispMode = (mode == AIS_WireFrame ? 0 : 1 );
396 //=====================================================================================
397 // function : DisplayGUI::SetVectorsMode()
398 // purpose : Set vector mode for the viewer
399 //=====================================================================================
400 void DisplayGUI::SetVectorMode( const bool mode, SUIT_ViewWindow* viewWindow )
402 SUIT_OverrideCursor();
405 viewWindow = getGeometryGUI()->getApp()->desktop()->activeWindow();
406 if ( viewWindow->getViewManager()->getType() == SVTK_Viewer::Type() ) {
407 viewWindow->setProperty( "VectorsMode", mode );
408 SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>( viewWindow );
409 vtkActorCollection* allActors = vw->getRenderer()->GetActors();
410 allActors->InitTraversal();
411 while (vtkActor* actor = allActors->GetNextActor()) {
412 if (actor->GetVisibility()) { // only for visible actors
413 GEOM_Actor* aGeomActor = 0;
414 if ( actor->IsA( "GEOM_Actor" ) ) {
415 aGeomActor = GEOM_Actor::SafeDownCast( actor );
417 aGeomActor->SetVectorMode( mode );
421 GeometryGUI::Modified();
423 else if ( viewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() ) {
424 viewWindow->setProperty( "VectorsMode", mode );
425 OCCViewer_Viewer* v3d = ((OCCViewer_ViewManager*)(viewWindow->getViewManager()))->getOCCViewer();
426 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
427 AIS_ListOfInteractive List;
428 ic->DisplayedObjects( List );
429 AIS_ListOfInteractive List1;
430 ic->ObjectsInCollector( List1 );
431 List.Append( List1 );
433 AIS_ListIteratorOfListOfInteractive ite( List );
434 while( ite.More() ) {
435 if( ite.Value()->IsInstance( STANDARD_TYPE(GEOM_AISShape) ) ) {
436 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast( ite.Value() );
437 aSh->SetDisplayVectors(mode);
438 ic->RecomputePrsOnly(ite.Value());
442 GeometryGUI::Modified();
446 //=====================================================================================
447 // function : DisplayGUI::GetVectorMode()
448 // purpose : Get the "show edge direction" mode of the viewer
449 //=====================================================================================
450 int DisplayGUI::GetVectorMode( SUIT_ViewWindow* viewWindow )
453 viewWindow = getGeometryGUI()->getApp()->desktop()->activeWindow();
454 return viewWindow->property( "VectorsMode" ).toBool();
457 //=====================================================================================
458 // function : DisplayGUI::InvertDisplayMode()
459 // purpose : Invert display mode ( shadin <-> wireframe ) for the viewer
460 // (current viewer if <viewWindow> = 0 )
461 //=====================================================================================
462 void DisplayGUI::InvertDisplayMode( SUIT_ViewWindow* viewWindow )
464 SetDisplayMode( 1 - GetDisplayMode( viewWindow ) );
467 //=====================================================================================
468 // function : DisplayGUI::ChangeDisplayMode()
469 // purpose : Set display mode for selected objects in the viewer given
470 // (current viewer if <viewWindow> = 0 )
471 //=====================================================================================
472 void DisplayGUI::ChangeDisplayMode( const int mode, SUIT_ViewWindow* viewWindow )
474 SalomeApp_Application* app = getGeometryGUI()->getApp();
478 viewWindow = app->desktop()->activeWindow();
480 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
481 if ( !aSelMgr ) return;
483 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
488 SUIT_OverrideCursor();
492 if ( viewWindow->getViewManager()->getType() == SVTK_Viewer::Type() ) {
493 SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>( viewWindow );
494 SVTK_View* aView = vw->getView();
495 int mgrId = viewWindow->getViewManager()->getGlobalId();
496 bool vectorMode = false;
498 aSelMgr->selectedObjects( aList );
499 SALOME_ListIteratorOfListIO It( aList );
501 for( ;It.More(); It.Next() ) {
502 SVTK_Viewer* stvkViewer = dynamic_cast<SVTK_Viewer*>(vw->getViewManager()->getViewModel());
504 stvkViewer ? dynamic_cast<SVTK_Prs*>( stvkViewer->CreatePrs( It.Value()->getEntry() ) ) : 0;
505 if ( vtkPrs && !vtkPrs->IsNull() ) {
507 aView->ChangeRepresentationToWireframe( vtkPrs->GetObjects() );
508 else if ( mode == 1 )
509 aView->ChangeRepresentationToSurface( vtkPrs->GetObjects() );
510 else if ( mode == 2 ) {
511 vtkActorCollection* anActors = vtkPrs->GetObjects();
512 anActors->InitTraversal();
513 while (vtkActor* anAct = anActors->GetNextActor()) {
514 GEOM_Actor* aGeomActor = GEOM_Actor::SafeDownCast(anAct);
515 vectorMode = !aGeomActor->GetVectorMode();
516 aGeomActor->SetVectorMode(vectorMode);
519 if(mode == 0 || mode == 1) {
520 aStudy->setObjectProperty(mgrId,It.Value()->getEntry(),DISPLAY_MODE_PROP, mode);
522 else if (mode == 3) {
523 aStudy->setObjectProperty(mgrId, It.Value()->getEntry(),VECTOR_MODE_PROP , vectorMode);
528 GeometryGUI::Modified();
530 else if ( viewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() ) {
531 OCCViewer_Viewer* v3d = ((OCCViewer_ViewManager*)(viewWindow->getViewManager()))->getOCCViewer();
532 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
534 aSelMgr->selectedObjects( aList );
535 SALOME_ListIteratorOfListIO It( aList );
536 int mgrId = viewWindow->getViewManager()->getGlobalId();
539 for( ;It.More(); It.Next() ) {
540 SOCC_Viewer* soccViewer = (SOCC_Viewer*)(viewWindow->getViewManager()->getViewModel());
541 SOCC_Prs* occPrs = dynamic_cast<SOCC_Prs*>( soccViewer->CreatePrs( It.Value()->getEntry() ) );
542 if ( occPrs && !occPrs->IsNull() ) {
543 AIS_ListOfInteractive shapes; occPrs->GetObjects( shapes );
544 AIS_ListIteratorOfListOfInteractive interIter( shapes );
545 for ( ; interIter.More(); interIter.Next() ) {
547 ic->SetDisplayMode( interIter.Value(), AIS_WireFrame, false );
548 else if ( mode == 1 )
549 ic->SetDisplayMode( interIter.Value(), AIS_Shaded, false );
550 else if ( mode == 3 )
551 ic->SetDisplayMode( interIter.Value(), AIS_ExactHLR, false );
552 else if (mode == 2 ) {
553 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast( interIter.Value() );
554 if ( !aSh.IsNull() ) {
555 vectorMode = !aSh->isShowVectors();
556 aSh->SetDisplayVectors(vectorMode);
557 ic->RecomputePrsOnly(interIter.Value());
561 if(mode == 0 || mode == 1) {
562 aStudy->setObjectProperty(mgrId, It.Value()->getEntry(),DISPLAY_MODE_PROP, mode);
563 } else if (mode == 2) {
564 aStudy->setObjectProperty(mgrId, It.Value()->getEntry(),VECTOR_MODE_PROP, vectorMode);
568 ic->UpdateCurrentViewer();
569 GeometryGUI::Modified();
573 //=====================================================================================
575 //=====================================================================================
579 __declspec( dllexport )
581 GEOMGUI* GetLibGUI( GeometryGUI* parent )
583 return new DisplayGUI( parent );