1 // Copyright (C) 2007-2014 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, or (at your option) any later version.
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 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
92 if ( !appStudy ) return false;
94 LightApp_SelectionMgr *Sel = app->selectionMgr();
95 SALOME_ListIO selected;
96 Sel->selectedObjects( selected );
98 switch ( theCommandID ) {
99 case GEOMOp::OpDMWireframe: // MENU VIEW - DISPLAY MODE - WIREFRAME
102 case GEOMOp::OpDMShading: // MENU VIEW - DISPLAY MODE - SHADING
105 case GEOMOp::OpDMShadingWithEdges: // MENU VIEW - DISPLAY MODE - SHADING WITH EDGES
108 case GEOMOp::OpDMTexture: // MENU VIEW - DISPLAY MODE - TEXTURE
111 case GEOMOp::OpShowAll: // MENU VIEW - SHOW ALL
112 getGeometryGUI()->EmitSignalDeactivateDialog();
115 case GEOMOp::OpShowOnly: // POPUP MENU - SHOW ONLY
116 getGeometryGUI()->EmitSignalDeactivateDialog();
119 case GEOMOp::OpShowOnlyChildren: // POPUP MENU - SHOW ONLY CHILDREN
120 getGeometryGUI()->EmitSignalDeactivateDialog();
121 DisplayOnlyChildren();
123 case GEOMOp::OpHideAll: // MENU VIEW - HIDE ALL
126 case GEOMOp::OpHide: // POPUP MENU - HIDE
129 case GEOMOp::OpShow: // POPUP MENU - SHOW
130 getGeometryGUI()->EmitSignalDeactivateDialog();
133 case GEOMOp::OpSwitchVectors: // MENU VIEW - DISPLAY MODE - SHOW EDGE DIRECTION
134 SetVectorMode(!GetVectorMode());
135 getGeometryGUI()->action( GEOMOp::OpSwitchVectors )->setText
136 ( GetVectorMode() ? tr("MEN_VECTOR_MODE_ON") : tr( "MEN_VECTOR_MODE_OFF" ) );
137 getGeometryGUI()->menuMgr()->update();
139 case GEOMOp::OpSwitchVertices: // MENU VIEW - DISPLAY MODE - SHOW/HIDE VERTICES
140 SetVerticesMode(!GetVerticesMode());
141 getGeometryGUI()->action( GEOMOp::OpSwitchVertices )->setText
142 ( GetVerticesMode() ? tr("MEN_VERTICES_MODE_ON") : tr( "MEN_VERTICES_MODE_OFF" ) );
143 getGeometryGUI()->menuMgr()->update();
145 case GEOMOp::OpWireframe: // POPUP MENU - DISPLAY MODE - WIREFRAME
146 ChangeDisplayMode( 0 );
148 case GEOMOp::OpShading: // POPUP MENU - DISPLAY MODE - SHADING
149 ChangeDisplayMode( 1 );
151 case GEOMOp::OpShadingWithEdges: // POPUP MENU - DISPLAY MODE - SHADING WITH EDGES
152 ChangeDisplayMode( 2 );
154 case GEOMOp::OpTexture: // POPUP MENU - DISPLAY MODE - TEXTURE
155 ChangeDisplayMode( 3 );
157 case GEOMOp::OpVectors: // POPUP MENU - DISPLAY MODE - SHOW EDGE DIRECTION
158 ChangeDisplayMode( 4 );
160 case GEOMOp::OpVertices: // POPUP MENU - DISPLAY MODE - SHOW VERTICES
161 ChangeDisplayMode( 5 );
164 app->putInfo(tr("GEOM_PRP_COMMAND").arg(theCommandID));
167 Sel->setSelectedObjects( selected );
168 GEOM_Displayer( appStudy ).UpdateColorScale();
172 //=====================================================================================
173 // function : DisplayGUI::DisplayAll()
174 // purpose : Display all GEOM objects
175 //=====================================================================================
176 void DisplayGUI::DisplayAll()
178 SalomeApp_Application* app = getGeometryGUI()->getApp();
181 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
182 if ( !appStudy ) return;
183 _PTR(Study) aStudy = appStudy->studyDS();
184 if ( !aStudy ) return;
185 _PTR(SComponent) SC ( aStudy->FindComponent( "GEOM" ) );
189 SALOME_ListIO listIO;
190 _PTR(ChildIterator) anIter ( aStudy->NewChildIterator( SC ) );
191 anIter->InitEx( true );
193 SUIT_OverrideCursor();
195 while( anIter->More() ) {
196 _PTR(SObject) valSO ( anIter->Value() );
198 if ( !valSO->ReferencedObject( refSO ) ) {
199 listIO.Append( new SALOME_InteractiveObject(valSO->GetID().c_str(),
200 SC->ComponentDataType().c_str(),
201 valSO->GetName().c_str()) );
205 GEOM_Displayer( appStudy ).Display( listIO, true );
208 //=====================================================================================
209 // function : DisplayGUI::EraseAll()
210 // purpose : Erase all GEOM objects
211 //=====================================================================================
212 void DisplayGUI::EraseAll()
214 SUIT_OverrideCursor();
216 SUIT_Application* app = getGeometryGUI()->getApp();
218 SUIT_ViewWindow* vw = app->desktop()->activeWindow();
220 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
221 SUIT_ViewManager* vman = vw->getViewManager();
222 if ( vman->getType() == OCCViewer_Viewer::Type() ||
223 vman->getType() == SVTK_Viewer::Type() ) {
224 GEOM_Displayer( appStudy ).EraseAll(true);
230 //=====================================================================================
231 // function : DisplayGUI::DisplayOnly()
232 // purpose : Display selected GEOM objects and erase other
233 //=====================================================================================
234 void DisplayGUI::DisplayOnly()
240 //=====================================================================================
241 // function : DisplayGUI::DisplayOnlyChildren()
242 // purpose : Display only children of selected GEOM objects and erase other
243 //=====================================================================================
244 void DisplayGUI::DisplayOnlyChildren()
248 SALOME_ListIO listIO;
250 SalomeApp_Application* app = getGeometryGUI()->getApp();
253 SalomeApp_Study* anActiveStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
254 if (!anActiveStudy) return;
256 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
257 if (!aSelMgr) return;
261 //aSelMgr->selectedObjects(aList);
262 aSelMgr->selectedObjects(aList, "ObjectBrowser", false);
263 SALOME_ListIteratorOfListIO It (aList);
265 SUIT_OverrideCursor();
267 for (; It.More(); It.Next()) {
268 Handle(SALOME_InteractiveObject) anIObject = It.Value();
269 if (anIObject->hasEntry()) {
270 _PTR(SObject) SO (anActiveStudy->studyDS()->FindObjectID(anIObject->getEntry()));
272 _PTR(SComponent) SC (SO->GetFatherComponent());
273 if (QString(SO->GetID().c_str()) == QString(SO->GetFatherComponent()->GetID().c_str())) {
274 // if component is selected, pass it
277 _PTR(ChildIterator) anIter (anActiveStudy->studyDS()->NewChildIterator(SO));
278 anIter->InitEx(true);
279 while (anIter->More()) {
280 _PTR(SObject) valSO (anIter->Value());
282 if (!valSO->ReferencedObject(refSO)) {
283 listIO.Append(new SALOME_InteractiveObject(valSO->GetID().c_str(),
284 SC->ComponentDataType().c_str(),
285 valSO->GetName().c_str()));
293 GEOM_Displayer(anActiveStudy).Display(listIO, true);
296 //=====================================================================================
297 // function : DisplayGUI::Display()
298 // purpose : Display selected GEOM objects
299 //=====================================================================================
300 void DisplayGUI::Display()
302 SALOME_ListIO listIO;
304 SalomeApp_Application* app = getGeometryGUI()->getApp();
307 SalomeApp_Study* anActiveStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
308 if ( !anActiveStudy ) return;
310 //get SalomeApp selection manager
311 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
312 if ( !aSelMgr ) return;
315 aSelMgr->selectedObjects( aList );
316 SALOME_ListIteratorOfListIO It( aList );
318 SUIT_OverrideCursor();
320 for( ;It.More();It.Next() ) {
321 Handle(SALOME_InteractiveObject) anIObject = It.Value();
322 if ( anIObject->hasEntry() ) {
323 _PTR(SObject) SO ( anActiveStudy->studyDS()->FindObjectID( anIObject->getEntry() ) );
324 if ( SO && QString(SO->GetID().c_str()) == QString(SO->GetFatherComponent()->GetID().c_str()) ) {
325 _PTR(SComponent) SC ( SO->GetFatherComponent() );
326 // if component is selected
328 _PTR(ChildIterator) anIter ( anActiveStudy->studyDS()->NewChildIterator( SO ) );
329 anIter->InitEx( true );
330 while( anIter->More() ) {
331 _PTR(SObject) valSO ( anIter->Value() );
333 if ( !valSO->ReferencedObject( refSO ) ) {
334 listIO.Append( new SALOME_InteractiveObject(valSO->GetID().c_str(),
335 SC->ComponentDataType().c_str(),
336 valSO->GetName().c_str()) );
343 listIO.Append( anIObject );
347 listIO.Append( anIObject );
350 GEOM_Displayer( anActiveStudy ).Display( listIO, true );
354 //=====================================================================================
355 // function : DisplayGUI::Erase()
356 // purpose : Erase selected GEOM objects
357 //=====================================================================================
358 void DisplayGUI::Erase()
360 SALOME_ListIO listIO;
362 SalomeApp_Application* app = getGeometryGUI()->getApp();
365 SalomeApp_Study* anActiveStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
366 if ( !anActiveStudy ) return;
368 //get SalomeApp selection manager
369 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
370 if ( !aSelMgr ) return;
373 aSelMgr->selectedObjects( aList );
374 SALOME_ListIteratorOfListIO It( aList );
376 SUIT_OverrideCursor();
378 for( ; It.More(); It.Next() ) {
379 Handle(SALOME_InteractiveObject) anIObject = It.Value();
380 if ( anIObject->hasEntry() ) {
381 _PTR(SObject) SO ( anActiveStudy->studyDS()->FindObjectID( anIObject->getEntry() ) );
382 if ( SO && QString(SO->GetID().c_str()) == QString(SO->GetFatherComponent()->GetID().c_str()) ) {
383 _PTR(SComponent) SC ( SO->GetFatherComponent() );
384 // if component is selected
386 _PTR(ChildIterator) anIter ( anActiveStudy->studyDS()->NewChildIterator( SO ) );
387 anIter->InitEx( true );
388 while( anIter->More() ) {
389 _PTR(SObject) valSO ( anIter->Value() );
391 if ( !valSO->ReferencedObject( refSO ) ) {
392 listIO.Append( new SALOME_InteractiveObject(valSO->GetID().c_str(),
393 SC->ComponentDataType().c_str(),
394 valSO->GetName().c_str()) );
401 listIO.Append( anIObject );
405 listIO.Append( anIObject );
409 SUIT_ViewWindow* viewWindow = app->desktop()->activeWindow();
410 bool aIsForced = true;
411 if(viewWindow->getViewManager()->getType() == SVTK_Viewer::Type())
414 GEOM_Displayer(anActiveStudy).Erase( listIO, aIsForced);
415 getGeometryGUI()->getApp()->selectionMgr()->clearSelected();
418 //=====================================================================================
419 // function : DisplayGUI::SetDisplayMode()
420 // purpose : Set display mode for the viewer (current viewer if <viewWindow> - 0 )
421 //=====================================================================================
422 void DisplayGUI::SetDisplayMode( const int mode, SUIT_ViewWindow* viewWindow )
424 SUIT_OverrideCursor();
426 SalomeApp_Application* app = getGeometryGUI()->getApp();
430 viewWindow = app->desktop()->activeWindow();
432 SalomeApp_Study* aStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
433 if ( !aStudy ) return;
435 GEOM_Displayer displayer( aStudy );
437 int mgrId = viewWindow->getViewManager()->getGlobalId();
439 SALOME_ListIO anIOlst;
440 displayer.GetActiveView()->GetVisible( anIOlst );
442 for ( SALOME_ListIteratorOfListIO It( anIOlst ); It.More(); It.Next() ) {
443 Handle( SALOME_InteractiveObject ) io = It.Value();
444 aStudy->setObjectProperty( mgrId, io->getEntry(), GEOM::propertyName( GEOM::DisplayMode ), mode );
445 displayer.Redisplay( io, false );
447 displayer.UpdateViewer();
448 GeometryGUI::Modified();
451 //=====================================================================================
452 // function : DisplayGUI::SetVectorsMode()
453 // purpose : Set vector mode for the viewer
454 //=====================================================================================
455 void DisplayGUI::SetVectorMode( const bool mode, SUIT_ViewWindow* viewWindow )
457 SUIT_OverrideCursor();
459 SalomeApp_Application* app = getGeometryGUI()->getApp();
462 SalomeApp_Study* aStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
463 if ( !aStudy ) return;
466 viewWindow = app->desktop()->activeWindow();
468 GEOM_Displayer displayer( aStudy );
470 viewWindow->setProperty( "VectorsMode", mode );
472 int aMgrId = viewWindow->getViewManager()->getGlobalId();
474 SALOME_ListIO anIOlst;
475 displayer.GetActiveView()->GetVisible( anIOlst );
477 for ( SALOME_ListIteratorOfListIO It( anIOlst ); It.More(); It.Next() ) {
478 Handle( SALOME_InteractiveObject ) io = It.Value();
479 aStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::EdgesDirection ), mode );
480 displayer.Redisplay( io, false );
482 displayer.UpdateViewer();
483 GeometryGUI::Modified();
486 //=====================================================================================
487 // function : DisplayGUI::GetVectorMode()
488 // purpose : Get the "show edge direction" mode of the viewer
489 //=====================================================================================
490 int DisplayGUI::GetVectorMode( SUIT_ViewWindow* viewWindow )
493 viewWindow = getGeometryGUI()->getApp()->desktop()->activeWindow();
494 return viewWindow->property( "VectorsMode" ).toBool();
497 //=====================================================================================
498 // function : DisplayGUI::SetVerticesMode()
499 // purpose : Set vertices mode for the viewer
500 //=====================================================================================
501 void DisplayGUI::SetVerticesMode( const bool mode, SUIT_ViewWindow* viewWindow )
503 SUIT_OverrideCursor();
505 SalomeApp_Application* app = getGeometryGUI()->getApp();
508 SalomeApp_Study* aStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
509 if ( !aStudy ) return;
512 viewWindow = app->desktop()->activeWindow();
514 GEOM_Displayer displayer( aStudy );
516 viewWindow->setProperty( "VerticesMode", mode );
518 int aMgrId = viewWindow->getViewManager()->getGlobalId();
520 SALOME_ListIO anIOlst;
521 displayer.GetActiveView()->GetVisible( anIOlst );
523 for ( SALOME_ListIteratorOfListIO It( anIOlst ); It.More(); It.Next() ) {
524 Handle( SALOME_InteractiveObject ) io = It.Value();
525 aStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::Vertices ), mode );
526 displayer.Redisplay( io, false );
528 displayer.UpdateViewer();
529 GeometryGUI::Modified();
532 //=====================================================================================
533 // function : DisplayGUI::GetVerticesMode()
534 // purpose : Get the "show vertices" mode of the viewer
535 //=====================================================================================
536 int DisplayGUI::GetVerticesMode( SUIT_ViewWindow* viewWindow )
539 viewWindow = getGeometryGUI()->getApp()->desktop()->activeWindow();
540 return viewWindow->property( "VerticesMode" ).toBool();
543 //=====================================================================================
544 // function : DisplayGUI::ChangeDisplayMode()
545 // purpose : Set display mode for selected objects in the viewer given
546 // (current viewer if <viewWindow> = 0 )
547 //=====================================================================================
548 void DisplayGUI::ChangeDisplayMode( const int mode, SUIT_ViewWindow* viewWindow )
550 SalomeApp_Application* app = getGeometryGUI()->getApp();
554 viewWindow = app->desktop()->activeWindow();
556 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
557 if ( !aSelMgr ) return;
559 SalomeApp_Study* aStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
560 if ( !aStudy ) return;
562 SUIT_OverrideCursor();
564 SALOME_ListIO selected;
565 aSelMgr->selectedObjects( selected );
566 if ( selected.IsEmpty() ) return;
568 GEOM_Displayer displayer( aStudy );
570 int mgrId = viewWindow->getViewManager()->getGlobalId();
572 QVariant v = aStudy->getObjectProperty( mgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::EdgesDirection ), QVariant() );
573 bool vectorMode = v.isValid() ? !v.toBool() : false;
574 v = aStudy->getObjectProperty( mgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::Vertices ), QVariant() );
575 bool verticesMode = v.isValid() ? !v.toBool() : false;
577 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
578 Handle( SALOME_InteractiveObject ) io = It.Value();
579 if ( mode == 0 || mode == 1 || mode == 2 || mode == 3 ) {
580 aStudy->setObjectProperty( mgrId, io->getEntry(), GEOM::propertyName( GEOM::DisplayMode ), mode );
582 else if ( mode == 4 ) {
583 aStudy->setObjectProperty( mgrId, io->getEntry(), GEOM::propertyName( GEOM::EdgesDirection ), vectorMode );
585 else if ( mode == 5 ) {
586 aStudy->setObjectProperty( mgrId, io->getEntry(), GEOM::propertyName( GEOM::Vertices ), verticesMode );
588 displayer.Redisplay( io, false );
590 displayer.UpdateViewer();
591 GeometryGUI::Modified();
594 //=====================================================================================
596 //=====================================================================================
600 __declspec( dllexport )
602 GEOMGUI* GetLibGUI( GeometryGUI* parent )
604 return new DisplayGUI( parent );