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
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_Constants.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::OpDMWireframe: // MENU VIEW - DISPLAY MODE - WIREFRAME
98 case GEOMOp::OpDMShading: // MENU VIEW - DISPLAY MODE - SHADING
101 case GEOMOp::OpDMShadingWithEdges: // MENU VIEW - DISPLAY MODE - SHADING WITH EDGES
104 case GEOMOp::OpShowAll: // MENU VIEW - SHOW ALL
105 getGeometryGUI()->EmitSignalDeactivateDialog();
108 case GEOMOp::OpShowOnly: // POPUP MENU - SHOW ONLY
109 getGeometryGUI()->EmitSignalDeactivateDialog();
112 case GEOMOp::OpShowOnlyChildren: // POPUP MENU - SHOW ONLY CHILDREN
113 getGeometryGUI()->EmitSignalDeactivateDialog();
114 DisplayOnlyChildren();
116 case GEOMOp::OpHideAll: // MENU VIEW - HIDE ALL
119 case GEOMOp::OpHide: // POPUP MENU - HIDE
122 case GEOMOp::OpShow: // POPUP MENU - SHOW
123 getGeometryGUI()->EmitSignalDeactivateDialog();
126 case GEOMOp::OpSwitchVectors: // MENU VIEW - DISPLAY MODE - SHOW EDGE DIRECTION
127 SetVectorMode(!GetVectorMode());
128 getGeometryGUI()->action( GEOMOp::OpSwitchVectors )->setText
129 ( GetVectorMode() ? tr("MEN_VECTOR_MODE_ON") : tr( "MEN_VECTOR_MODE_OFF" ) );
130 getGeometryGUI()->menuMgr()->update();
132 case GEOMOp::OpWireframe: // POPUP MENU - DISPLAY MODE - WIREFRAME
133 ChangeDisplayMode( 0 );
135 case GEOMOp::OpShading: // POPUP MENU - DISPLAY MODE - SHADING
136 ChangeDisplayMode( 1 );
138 case GEOMOp::OpShadingWithEdges: // POPUP MENU - DISPLAY MODE - SHADING WITH EDGES
139 ChangeDisplayMode( 2 );
141 case GEOMOp::OpTexture: // POPUP MENU - DISPLAY MODE - TEXTURE
142 ChangeDisplayMode( 3 );
144 case GEOMOp::OpVectors: // POPUP MENU - DISPLAY MODE - SHOW EDGE DIRECTION
145 ChangeDisplayMode( 4 );
148 app->putInfo(tr("GEOM_PRP_COMMAND").arg(theCommandID));
151 Sel->setSelectedObjects( selected );
155 //=====================================================================================
156 // function : DisplayGUI::DisplayAll()
157 // purpose : Display all GEOM objects
158 //=====================================================================================
159 void DisplayGUI::DisplayAll()
161 SalomeApp_Application* app = getGeometryGUI()->getApp();
164 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
165 if ( !appStudy ) return;
166 _PTR(Study) aStudy = appStudy->studyDS();
167 if ( !aStudy ) return;
168 _PTR(SComponent) SC ( aStudy->FindComponent( "GEOM" ) );
172 SALOME_ListIO listIO;
173 _PTR(ChildIterator) anIter ( aStudy->NewChildIterator( SC ) );
174 anIter->InitEx( true );
176 SUIT_OverrideCursor();
178 while( anIter->More() ) {
179 _PTR(SObject) valSO ( anIter->Value() );
181 if ( !valSO->ReferencedObject( refSO ) ) {
182 listIO.Append( new SALOME_InteractiveObject(valSO->GetID().c_str(),
183 SC->ComponentDataType().c_str(),
184 valSO->GetName().c_str()) );
188 GEOM_Displayer( appStudy ).Display( listIO, true );
191 //=====================================================================================
192 // function : DisplayGUI::EraseAll()
193 // purpose : Erase all GEOM objects
194 //=====================================================================================
195 void DisplayGUI::EraseAll()
197 SUIT_OverrideCursor();
199 SUIT_Application* app = getGeometryGUI()->getApp();
201 SUIT_ViewWindow* vw = app->desktop()->activeWindow();
203 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
204 SUIT_ViewManager* vman = vw->getViewManager();
205 if ( vman->getType() == OCCViewer_Viewer::Type() ||
206 vman->getType() == SVTK_Viewer::Type() ) {
207 GEOM_Displayer( appStudy ).EraseAll();
213 //=====================================================================================
214 // function : DisplayGUI::DisplayOnly()
215 // purpose : Display selected GEOM objects and erase other
216 //=====================================================================================
217 void DisplayGUI::DisplayOnly()
223 //=====================================================================================
224 // function : DisplayGUI::DisplayOnlyChildren()
225 // purpose : Display only children of selected GEOM objects and erase other
226 //=====================================================================================
227 void DisplayGUI::DisplayOnlyChildren()
231 SALOME_ListIO listIO;
233 SalomeApp_Application* app = getGeometryGUI()->getApp();
236 SalomeApp_Study* anActiveStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
237 if (!anActiveStudy) return;
239 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
240 if (!aSelMgr) return;
244 //aSelMgr->selectedObjects(aList);
245 aSelMgr->selectedObjects(aList, "ObjectBrowser", false);
246 SALOME_ListIteratorOfListIO It (aList);
248 SUIT_OverrideCursor();
250 for (; It.More(); It.Next()) {
251 Handle(SALOME_InteractiveObject) anIObject = It.Value();
252 if (anIObject->hasEntry()) {
253 _PTR(SObject) SO (anActiveStudy->studyDS()->FindObjectID(anIObject->getEntry()));
255 _PTR(SComponent) SC (SO->GetFatherComponent());
256 if (QString(SO->GetID().c_str()) == QString(SO->GetFatherComponent()->GetID().c_str())) {
257 // if component is selected, pass it
260 _PTR(ChildIterator) anIter (anActiveStudy->studyDS()->NewChildIterator(SO));
261 anIter->InitEx(true);
262 while (anIter->More()) {
263 _PTR(SObject) valSO (anIter->Value());
265 if (!valSO->ReferencedObject(refSO)) {
266 listIO.Append(new SALOME_InteractiveObject(valSO->GetID().c_str(),
267 SC->ComponentDataType().c_str(),
268 valSO->GetName().c_str()));
276 GEOM_Displayer(anActiveStudy).Display(listIO, true);
279 //=====================================================================================
280 // function : DisplayGUI::Display()
281 // purpose : Display selected GEOM objects
282 //=====================================================================================
283 void DisplayGUI::Display()
285 SALOME_ListIO listIO;
287 SalomeApp_Application* app = getGeometryGUI()->getApp();
290 SalomeApp_Study* anActiveStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
291 if ( !anActiveStudy ) return;
293 //get SalomeApp selection manager
294 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
295 if ( !aSelMgr ) return;
298 aSelMgr->selectedObjects( aList );
299 SALOME_ListIteratorOfListIO It( aList );
301 SUIT_OverrideCursor();
303 for( ;It.More();It.Next() ) {
304 Handle(SALOME_InteractiveObject) anIObject = It.Value();
305 if ( anIObject->hasEntry() ) {
306 _PTR(SObject) SO ( anActiveStudy->studyDS()->FindObjectID( anIObject->getEntry() ) );
307 if ( SO && QString(SO->GetID().c_str()) == QString(SO->GetFatherComponent()->GetID().c_str()) ) {
308 _PTR(SComponent) SC ( SO->GetFatherComponent() );
309 // if component is selected
311 _PTR(ChildIterator) anIter ( anActiveStudy->studyDS()->NewChildIterator( SO ) );
312 anIter->InitEx( true );
313 while( anIter->More() ) {
314 _PTR(SObject) valSO ( anIter->Value() );
316 if ( !valSO->ReferencedObject( refSO ) ) {
317 listIO.Append( new SALOME_InteractiveObject(valSO->GetID().c_str(),
318 SC->ComponentDataType().c_str(),
319 valSO->GetName().c_str()) );
326 listIO.Append( anIObject );
330 listIO.Append( anIObject );
333 GEOM_Displayer( anActiveStudy ).Display( listIO, true );
337 //=====================================================================================
338 // function : DisplayGUI::Erase()
339 // purpose : Erase selected GEOM objects
340 //=====================================================================================
341 void DisplayGUI::Erase()
343 SALOME_ListIO listIO;
345 SalomeApp_Application* app = getGeometryGUI()->getApp();
348 SalomeApp_Study* anActiveStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
349 if ( !anActiveStudy ) return;
351 //get SalomeApp selection manager
352 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
353 if ( !aSelMgr ) return;
356 aSelMgr->selectedObjects( aList );
357 SALOME_ListIteratorOfListIO It( aList );
359 SUIT_OverrideCursor();
361 for( ; It.More(); It.Next() ) {
362 Handle(SALOME_InteractiveObject) anIObject = It.Value();
363 if ( anIObject->hasEntry() ) {
364 _PTR(SObject) SO ( anActiveStudy->studyDS()->FindObjectID( anIObject->getEntry() ) );
365 if ( SO && QString(SO->GetID().c_str()) == QString(SO->GetFatherComponent()->GetID().c_str()) ) {
366 _PTR(SComponent) SC ( SO->GetFatherComponent() );
367 // if component is selected
369 _PTR(ChildIterator) anIter ( anActiveStudy->studyDS()->NewChildIterator( SO ) );
370 anIter->InitEx( true );
371 while( anIter->More() ) {
372 _PTR(SObject) valSO ( anIter->Value() );
374 if ( !valSO->ReferencedObject( refSO ) ) {
375 listIO.Append( new SALOME_InteractiveObject(valSO->GetID().c_str(),
376 SC->ComponentDataType().c_str(),
377 valSO->GetName().c_str()) );
384 listIO.Append( anIObject );
388 listIO.Append( anIObject );
392 SUIT_ViewWindow* viewWindow = app->desktop()->activeWindow();
393 bool aIsForced = true;
394 if(viewWindow->getViewManager()->getType() == SVTK_Viewer::Type())
397 GEOM_Displayer(anActiveStudy).Erase( listIO, aIsForced);
398 getGeometryGUI()->getApp()->selectionMgr()->clearSelected();
401 //=====================================================================================
402 // function : DisplayGUI::SetDisplayMode()
403 // purpose : Set display mode for the viewer (current viewer if <viewWindow> - 0 )
404 //=====================================================================================
405 void DisplayGUI::SetDisplayMode( const int mode, SUIT_ViewWindow* viewWindow )
407 SUIT_OverrideCursor();
410 viewWindow = getGeometryGUI()->getApp()->desktop()->activeWindow();
411 if ( viewWindow->getViewManager()->getType() == SVTK_Viewer::Type() ) {
412 SVTK_View* aView = ((SVTK_ViewWindow*)viewWindow)->getView();
413 aView->SetDisplayMode( mode );
414 GeometryGUI::Modified();
416 else if ( viewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() ) {
417 OCCViewer_Viewer* v3d = ((OCCViewer_ViewManager*)(viewWindow->getViewManager()))->getOCCViewer();
418 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
420 AIS_DisplayMode newmode;
423 newmode = AIS_WireFrame;
426 newmode = AIS_Shaded;
429 newmode = AIS_DisplayMode( GEOM_AISShape::ShadingWithEdges );
432 newmode = AIS_DisplayMode( GEOM_AISShape::TexturedShape );
438 AIS_ListOfInteractive List;
439 ic->DisplayedObjects( List );
440 AIS_ListOfInteractive List1;
441 ic->ObjectsInCollector( List1 );
442 List.Append( List1 );
444 AIS_ListIteratorOfListOfInteractive ite( List );
445 while( ite.More() ) {
446 if( ite.Value()->IsInstance( STANDARD_TYPE(GEOM_AISShape) ) ) {
447 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast( ite.Value() );
448 if(aSh->isTopLevel()) {
449 aSh->setPrevDisplayMode(Standard_Integer( newmode ));
452 ic->SetDisplayMode( aSh, Standard_Integer( newmode ),true );
458 ic->SetDisplayMode( newmode, Standard_False );
460 GeometryGUI::Modified();
464 //=====================================================================================
465 // function : DisplayGUI::SetVectorsMode()
466 // purpose : Set vector mode for the viewer
467 //=====================================================================================
468 void DisplayGUI::SetVectorMode( const bool mode, SUIT_ViewWindow* viewWindow )
470 SUIT_OverrideCursor();
473 viewWindow = getGeometryGUI()->getApp()->desktop()->activeWindow();
474 if ( viewWindow->getViewManager()->getType() == SVTK_Viewer::Type() ) {
475 viewWindow->setProperty( "VectorsMode", mode );
476 SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>( viewWindow );
477 vtkActorCollection* allActors = vw->getRenderer()->GetActors();
478 allActors->InitTraversal();
479 while (vtkActor* actor = allActors->GetNextActor()) {
480 if (actor->GetVisibility()) { // only for visible actors
481 GEOM_Actor* aGeomActor = 0;
482 if ( actor->IsA( "GEOM_Actor" ) ) {
483 aGeomActor = GEOM_Actor::SafeDownCast( actor );
485 aGeomActor->SetVectorMode( mode );
489 GeometryGUI::Modified();
491 else if ( viewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() ) {
492 viewWindow->setProperty( "VectorsMode", mode );
493 OCCViewer_Viewer* v3d = ((OCCViewer_ViewManager*)(viewWindow->getViewManager()))->getOCCViewer();
494 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
495 AIS_ListOfInteractive List;
496 ic->DisplayedObjects( List );
497 AIS_ListOfInteractive List1;
498 ic->ObjectsInCollector( List1 );
499 List.Append( List1 );
501 AIS_ListIteratorOfListOfInteractive ite( List );
502 while( ite.More() ) {
503 if( ite.Value()->IsInstance( STANDARD_TYPE(GEOM_AISShape) ) ) {
504 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast( ite.Value() );
505 aSh->SetDisplayVectors(mode);
506 ic->RecomputePrsOnly(ite.Value());
510 GeometryGUI::Modified();
514 //=====================================================================================
515 // function : DisplayGUI::GetVectorMode()
516 // purpose : Get the "show edge direction" mode of the viewer
517 //=====================================================================================
518 int DisplayGUI::GetVectorMode( SUIT_ViewWindow* viewWindow )
521 viewWindow = getGeometryGUI()->getApp()->desktop()->activeWindow();
522 return viewWindow->property( "VectorsMode" ).toBool();
525 //=====================================================================================
526 // function : DisplayGUI::ChangeDisplayMode()
527 // purpose : Set display mode for selected objects in the viewer given
528 // (current viewer if <viewWindow> = 0 )
529 //=====================================================================================
530 void DisplayGUI::ChangeDisplayMode( const int mode, SUIT_ViewWindow* viewWindow )
532 SalomeApp_Application* app = getGeometryGUI()->getApp();
536 viewWindow = app->desktop()->activeWindow();
538 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
539 if ( !aSelMgr ) return;
541 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
546 SUIT_OverrideCursor();
550 if ( viewWindow->getViewManager()->getType() == SVTK_Viewer::Type() ) {
551 SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>( viewWindow );
552 SVTK_View* aView = vw->getView();
553 int mgrId = viewWindow->getViewManager()->getGlobalId();
554 bool vectorMode = false;
556 aSelMgr->selectedObjects( aList );
557 SALOME_ListIteratorOfListIO It( aList );
559 for( ;It.More(); It.Next() ) {
560 SVTK_Viewer* stvkViewer = dynamic_cast<SVTK_Viewer*>(vw->getViewManager()->getViewModel());
562 stvkViewer ? dynamic_cast<SVTK_Prs*>( stvkViewer->CreatePrs( It.Value()->getEntry() ) ) : 0;
563 if ( vtkPrs && !vtkPrs->IsNull() ) {
565 aView->ChangeRepresentationToWireframe( vtkPrs->GetObjects() );
566 else if ( mode == 1 )
567 aView->ChangeRepresentationToSurface( vtkPrs->GetObjects() );
568 else if ( mode == 2 )
569 aView->ChangeRepresentationToSurfaceWithEdges( vtkPrs->GetObjects() );
570 else if ( mode == 4 ) {
571 vtkActorCollection* anActors = vtkPrs->GetObjects();
572 anActors->InitTraversal();
573 while (vtkActor* anAct = anActors->GetNextActor()) {
574 GEOM_Actor* aGeomActor = GEOM_Actor::SafeDownCast(anAct);
575 vectorMode = !aGeomActor->GetVectorMode();
576 aGeomActor->SetVectorMode(vectorMode);
579 if(mode == 0 || mode == 1 || mode == 2) {
580 aStudy->setObjectProperty(mgrId,It.Value()->getEntry(),DISPLAY_MODE_PROP, mode);
582 else if (mode == 4) {
583 aStudy->setObjectProperty(mgrId, It.Value()->getEntry(),VECTOR_MODE_PROP, vectorMode);
588 GeometryGUI::Modified();
590 else if ( viewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() ) {
591 OCCViewer_Viewer* v3d = ((OCCViewer_ViewManager*)(viewWindow->getViewManager()))->getOCCViewer();
592 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
594 aSelMgr->selectedObjects( aList );
595 SALOME_ListIteratorOfListIO It( aList );
596 int mgrId = viewWindow->getViewManager()->getGlobalId();
599 for( ;It.More(); It.Next() ) {
600 SOCC_Viewer* soccViewer = (SOCC_Viewer*)(viewWindow->getViewManager()->getViewModel());
601 SOCC_Prs* occPrs = dynamic_cast<SOCC_Prs*>( soccViewer->CreatePrs( It.Value()->getEntry() ) );
602 if ( occPrs && !occPrs->IsNull() ) {
603 AIS_ListOfInteractive shapes; occPrs->GetObjects( shapes );
604 AIS_ListIteratorOfListOfInteractive interIter( shapes );
605 for ( ; interIter.More(); interIter.Next() ) {
606 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast( interIter.Value() );
607 if ( !aSh.IsNull() ) {
608 if(!aSh->isTopLevel()) {
610 ic->SetDisplayMode( interIter.Value(), AIS_WireFrame, false );
611 else if ( mode == 1 )
612 ic->SetDisplayMode( interIter.Value(), AIS_Shaded, false );
613 else if ( mode == 2 )
614 ic->SetDisplayMode( interIter.Value(), GEOM_AISShape::ShadingWithEdges, false );
615 else if ( mode == 3 )
616 ic->SetDisplayMode( interIter.Value(), AIS_ExactHLR, false );
618 aSh->setPrevDisplayMode(mode);
621 vectorMode = !aSh->isShowVectors();
622 aSh->SetDisplayVectors(vectorMode);
623 ic->RecomputePrsOnly(interIter.Value());
627 if(mode == 0 || mode == 1 || mode == 2 || mode == 3) {
628 aStudy->setObjectProperty(mgrId, It.Value()->getEntry(),DISPLAY_MODE_PROP, mode);
630 else if (mode == 4) {
631 aStudy->setObjectProperty(mgrId, It.Value()->getEntry(),VECTOR_MODE_PROP, vectorMode);
635 ic->UpdateCurrentViewer();
636 GeometryGUI::Modified();
640 //=====================================================================================
642 //=====================================================================================
646 __declspec( dllexport )
648 GEOMGUI* GetLibGUI( GeometryGUI* parent )
650 return new DisplayGUI( parent );