1 // Copyright (C) 2007-2021 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>
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::OpDMTexture: // MENU VIEW - DISPLAY MODE - TEXTURE
107 case GEOMOp::OpShowAll: // MENU VIEW - SHOW ALL
108 getGeometryGUI()->EmitSignalDeactivateDialog();
111 case GEOMOp::OpShowOnly: // POPUP MENU - SHOW ONLY
112 getGeometryGUI()->EmitSignalDeactivateDialog();
115 case GEOMOp::OpShowOnlyChildren: // POPUP MENU - SHOW ONLY CHILDREN
116 getGeometryGUI()->EmitSignalDeactivateDialog();
117 DisplayOnlyChildren();
119 case GEOMOp::OpHideAll: // MENU VIEW - HIDE ALL
122 case GEOMOp::OpHide: // POPUP MENU - HIDE
125 case GEOMOp::OpShow: // POPUP MENU - SHOW
126 getGeometryGUI()->EmitSignalDeactivateDialog();
129 case GEOMOp::OpSwitchVectors: // MENU VIEW - DISPLAY MODE - SHOW EDGE DIRECTION
130 SetVectorMode(!GetVectorMode());
131 getGeometryGUI()->action( GEOMOp::OpSwitchVectors )->setText
132 ( GetVectorMode() ? tr("MEN_VECTOR_MODE_ON") : tr( "MEN_VECTOR_MODE_OFF" ) );
133 getGeometryGUI()->menuMgr()->update();
135 case GEOMOp::OpSwitchVertices: // MENU VIEW - DISPLAY MODE - SHOW/HIDE VERTICES
136 SetVerticesMode(!GetVerticesMode());
137 getGeometryGUI()->action( GEOMOp::OpSwitchVertices )->setText
138 ( GetVerticesMode() ? tr("MEN_VERTICES_MODE_ON") : tr( "MEN_VERTICES_MODE_OFF" ) );
139 getGeometryGUI()->menuMgr()->update();
141 case GEOMOp::OpSwitchName: // MENU VIEW - DISPLAY MODE - SHOW/HIDE NAME
142 SetNameMode(!GetNameMode());
143 getGeometryGUI()->action( GEOMOp::OpSwitchName )->setText
144 ( GetNameMode() ? tr("MEN_NAME_MODE_ON") : tr( "MEN_NAME_MODE_OFF" ) );
145 getGeometryGUI()->menuMgr()->update();
147 case GEOMOp::OpWireframe: // POPUP MENU - DISPLAY MODE - WIREFRAME
148 ChangeDisplayMode( 0 );
150 case GEOMOp::OpShading: // POPUP MENU - DISPLAY MODE - SHADING
151 ChangeDisplayMode( 1 );
153 case GEOMOp::OpShadingWithEdges: // POPUP MENU - DISPLAY MODE - SHADING WITH EDGES
154 ChangeDisplayMode( 2 );
156 case GEOMOp::OpTexture: // POPUP MENU - DISPLAY MODE - TEXTURE
157 ChangeDisplayMode( 3 );
159 case GEOMOp::OpVectors: // POPUP MENU - DISPLAY MODE - SHOW EDGE DIRECTION
160 ChangeDisplayMode( 4 );
162 case GEOMOp::OpVertices: // POPUP MENU - DISPLAY MODE - SHOW VERTICES
163 ChangeDisplayMode( 5 );
165 case GEOMOp::OpShowName: // POPUP MENU - DISPLAY MODE - SHOW NAME
166 ChangeDisplayMode( 6 );
169 app->putInfo(tr("GEOM_PRP_COMMAND").arg(theCommandID));
172 Sel->setSelectedObjects( selected );
173 GEOM_Displayer().UpdateColorScale();
177 //=====================================================================================
178 // function : DisplayGUI::DisplayAll()
179 // purpose : Display all GEOM objects
180 //=====================================================================================
181 void DisplayGUI::DisplayAll()
183 _PTR(Study) aStudy = SalomeApp_Application::getStudy();
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 wc;
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().Display( listIO, true );
208 //=====================================================================================
209 // function : DisplayGUI::EraseAll()
210 // purpose : Erase all GEOM objects
211 //=====================================================================================
212 void DisplayGUI::EraseAll()
214 SUIT_OverrideCursor wc;
216 SUIT_Application* app = getGeometryGUI()->getApp();
218 SUIT_ViewWindow* vw = app->desktop()->activeWindow();
220 SUIT_ViewManager* vman = vw->getViewManager();
221 if ( vman->getType() == OCCViewer_Viewer::Type() ||
222 vman->getType() == SVTK_Viewer::Type() ) {
223 GEOM_Displayer().EraseAll(true);
229 //=====================================================================================
230 // function : DisplayGUI::DisplayOnly()
231 // purpose : Display selected GEOM objects and erase other
232 //=====================================================================================
233 void DisplayGUI::DisplayOnly()
239 //=====================================================================================
240 // function : DisplayGUI::DisplayOnlyChildren()
241 // purpose : Display only children of selected GEOM objects and erase other
242 //=====================================================================================
243 void DisplayGUI::DisplayOnlyChildren()
247 SALOME_ListIO listIO;
249 SalomeApp_Application* app = getGeometryGUI()->getApp();
252 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
255 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
256 if (!aSelMgr) return;
260 //aSelMgr->selectedObjects(aList);
261 aSelMgr->selectedObjects(aList, "ObjectBrowser", false);
262 SALOME_ListIteratorOfListIO It (aList);
264 SUIT_OverrideCursor wc;
266 for (; It.More(); It.Next()) {
267 Handle(SALOME_InteractiveObject) anIObject = It.Value();
268 if (anIObject->hasEntry()) {
269 _PTR(SObject) SO (aStudy->studyDS()->FindObjectID(anIObject->getEntry()));
271 _PTR(SComponent) SC (SO->GetFatherComponent());
272 if (QString(SO->GetID().c_str()) == QString(SO->GetFatherComponent()->GetID().c_str())) {
273 // if component is selected, pass it
276 _PTR(ChildIterator) anIter (aStudy->studyDS()->NewChildIterator(SO));
277 anIter->InitEx(true);
278 while (anIter->More()) {
279 _PTR(SObject) valSO (anIter->Value());
281 if (!valSO->ReferencedObject(refSO)) {
282 listIO.Append(new SALOME_InteractiveObject(valSO->GetID().c_str(),
283 SC->ComponentDataType().c_str(),
284 valSO->GetName().c_str()));
292 GEOM_Displayer().Display(listIO, true);
295 //=====================================================================================
296 // function : DisplayGUI::Display()
297 // purpose : Display selected GEOM objects
298 //=====================================================================================
299 void DisplayGUI::Display()
301 SALOME_ListIO listIO;
303 SalomeApp_Application* app = getGeometryGUI()->getApp();
306 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
307 if ( !aStudy ) return;
309 //get SalomeApp selection manager
310 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
311 if ( !aSelMgr ) return;
314 aSelMgr->selectedObjects( aList );
315 SALOME_ListIteratorOfListIO It( aList );
317 SUIT_OverrideCursor wc;
319 for( ;It.More();It.Next() ) {
320 Handle(SALOME_InteractiveObject) anIObject = It.Value();
321 if ( anIObject->hasEntry() ) {
322 _PTR(SObject) SO ( aStudy->studyDS()->FindObjectID( anIObject->getEntry() ) );
323 if ( SO && QString(SO->GetID().c_str()) == QString(SO->GetFatherComponent()->GetID().c_str()) ) {
324 _PTR(SComponent) SC ( SO->GetFatherComponent() );
325 // if component is selected
327 _PTR(ChildIterator) anIter ( aStudy->studyDS()->NewChildIterator( SO ) );
328 anIter->InitEx( true );
329 while( anIter->More() ) {
330 _PTR(SObject) valSO ( anIter->Value() );
332 if ( !valSO->ReferencedObject( refSO ) ) {
333 listIO.Append( new SALOME_InteractiveObject(valSO->GetID().c_str(),
334 SC->ComponentDataType().c_str(),
335 valSO->GetName().c_str()) );
342 listIO.Append( anIObject );
346 listIO.Append( anIObject );
349 GEOM_Displayer().Display( listIO, true );
353 //=====================================================================================
354 // function : DisplayGUI::Erase()
355 // purpose : Erase selected GEOM objects
356 //=====================================================================================
357 void DisplayGUI::Erase()
359 SALOME_ListIO listIO;
361 SalomeApp_Application* app = getGeometryGUI()->getApp();
364 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
365 if ( !aStudy ) return;
367 //get SalomeApp selection manager
368 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
369 if ( !aSelMgr ) return;
372 aSelMgr->selectedObjects( aList );
373 SALOME_ListIteratorOfListIO It( aList );
375 SUIT_OverrideCursor wc;
377 for( ; It.More(); It.Next() ) {
378 Handle(SALOME_InteractiveObject) anIObject = It.Value();
379 if ( anIObject->hasEntry() ) {
380 _PTR(SObject) SO ( aStudy->studyDS()->FindObjectID( anIObject->getEntry() ) );
381 if ( SO && QString(SO->GetID().c_str()) == QString(SO->GetFatherComponent()->GetID().c_str()) ) {
382 _PTR(SComponent) SC ( SO->GetFatherComponent() );
383 // if component is selected
385 _PTR(ChildIterator) anIter ( aStudy->studyDS()->NewChildIterator( SO ) );
386 anIter->InitEx( true );
387 while( anIter->More() ) {
388 _PTR(SObject) valSO ( anIter->Value() );
390 if ( !valSO->ReferencedObject( refSO ) ) {
391 listIO.Append( new SALOME_InteractiveObject(valSO->GetID().c_str(),
392 SC->ComponentDataType().c_str(),
393 valSO->GetName().c_str()) );
400 listIO.Append( anIObject );
404 listIO.Append( anIObject );
408 SUIT_ViewWindow* viewWindow = app->desktop()->activeWindow();
409 bool aIsForced = true;
410 if(viewWindow->getViewManager()->getType() == SVTK_Viewer::Type())
413 GEOM_Displayer().Erase( listIO, aIsForced);
414 getGeometryGUI()->getApp()->selectionMgr()->clearSelected();
417 //=====================================================================================
418 // function : DisplayGUI::SetDisplayMode()
419 // purpose : Set display mode for the viewer (current viewer if <viewWindow> - 0 )
420 //=====================================================================================
421 void DisplayGUI::SetDisplayMode( const int mode, SUIT_ViewWindow* viewWindow )
423 SUIT_OverrideCursor wc;
425 SalomeApp_Application* app = getGeometryGUI()->getApp();
429 viewWindow = app->desktop()->activeWindow();
431 SalomeApp_Study* aStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
432 if ( !aStudy ) return;
434 GEOM_Displayer displayer;
436 int mgrId = viewWindow->getViewManager()->getGlobalId();
438 SALOME_View* window = displayer.GetActiveView();
439 if ( !window ) return;
441 SALOME_ListIO anIOlst;
442 window->GetVisible( anIOlst );
444 for ( SALOME_ListIteratorOfListIO It( anIOlst ); It.More(); It.Next() ) {
445 Handle( SALOME_InteractiveObject ) io = It.Value();
446 aStudy->setObjectProperty( mgrId, io->getEntry(), GEOM::propertyName( GEOM::DisplayMode ), mode );
447 displayer.Redisplay( io, false );
449 displayer.UpdateViewer();
450 GeometryGUI::Modified();
453 //=====================================================================================
454 // function : DisplayGUI::SetVectorsMode()
455 // purpose : Set vector mode for the viewer
456 //=====================================================================================
457 void DisplayGUI::SetVectorMode( const bool mode, SUIT_ViewWindow* viewWindow )
459 SUIT_OverrideCursor wc;
461 SalomeApp_Application* app = getGeometryGUI()->getApp();
464 SalomeApp_Study* aStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
465 if ( !aStudy ) return;
468 viewWindow = app->desktop()->activeWindow();
470 GEOM_Displayer displayer;
472 viewWindow->setProperty( "VectorsMode", mode );
474 int aMgrId = viewWindow->getViewManager()->getGlobalId();
476 SALOME_View* window = displayer.GetActiveView();
477 if ( !window ) return;
479 SALOME_ListIO anIOlst;
480 window->GetVisible( anIOlst );
482 for ( SALOME_ListIteratorOfListIO It( anIOlst ); It.More(); It.Next() ) {
483 Handle( SALOME_InteractiveObject ) io = It.Value();
484 aStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::EdgesDirection ), mode );
485 displayer.Redisplay( io, false );
487 displayer.UpdateViewer();
488 GeometryGUI::Modified();
491 //=====================================================================================
492 // function : DisplayGUI::GetVectorMode()
493 // purpose : Get the "show edge direction" mode of the viewer
494 //=====================================================================================
495 int DisplayGUI::GetVectorMode( SUIT_ViewWindow* viewWindow )
498 viewWindow = getGeometryGUI()->getApp()->desktop()->activeWindow();
499 return viewWindow->property( "VectorsMode" ).toBool();
502 //=====================================================================================
503 // function : DisplayGUI::SetVerticesMode()
504 // purpose : Set vertices mode for the viewer
505 //=====================================================================================
506 void DisplayGUI::SetVerticesMode( const bool mode, SUIT_ViewWindow* viewWindow )
508 SUIT_OverrideCursor wc;
510 SalomeApp_Application* app = getGeometryGUI()->getApp();
513 SalomeApp_Study* aStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
514 if ( !aStudy ) return;
517 viewWindow = app->desktop()->activeWindow();
519 GEOM_Displayer displayer;
521 viewWindow->setProperty( "VerticesMode", mode );
523 int aMgrId = viewWindow->getViewManager()->getGlobalId();
525 SALOME_View* window = displayer.GetActiveView();
526 if ( !window ) return;
528 SALOME_ListIO anIOlst;
529 window->GetVisible( anIOlst );
531 for ( SALOME_ListIteratorOfListIO It( anIOlst ); It.More(); It.Next() ) {
532 Handle( SALOME_InteractiveObject ) io = It.Value();
533 aStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::Vertices ), mode );
534 displayer.Redisplay( io, false );
536 displayer.UpdateViewer();
537 GeometryGUI::Modified();
540 //=====================================================================================
541 // function : DisplayGUI::GetVerticesMode()
542 // purpose : Get the "show vertices" mode of the viewer
543 //=====================================================================================
544 int DisplayGUI::GetVerticesMode( SUIT_ViewWindow* viewWindow )
547 viewWindow = getGeometryGUI()->getApp()->desktop()->activeWindow();
548 return viewWindow->property( "VerticesMode" ).toBool();
551 //=====================================================================================
552 // function : DisplayGUI::SetNameMode()
553 // purpose : Set name mode for the viewer
554 //=====================================================================================
555 void DisplayGUI::SetNameMode( const bool mode, SUIT_ViewWindow* viewWindow )
557 SUIT_OverrideCursor();
559 SalomeApp_Application* app = getGeometryGUI()->getApp();
562 SalomeApp_Study* aStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
563 if ( !aStudy ) return;
566 viewWindow = app->desktop()->activeWindow();
568 viewWindow->setProperty( "NameMode", mode );
570 GEOM_Displayer displayer;
572 int aMgrId = viewWindow->getViewManager()->getGlobalId();
574 SALOME_View* window = displayer.GetActiveView();
575 if ( !window ) return;
577 SALOME_ListIO anIOlst;
578 window->GetVisible( anIOlst );
580 for ( SALOME_ListIteratorOfListIO It( anIOlst ); It.More(); It.Next() ) {
581 Handle( SALOME_InteractiveObject ) io = It.Value();
582 aStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::ShowName ), mode );
583 displayer.Redisplay( io, false );
585 displayer.UpdateViewer();
586 GeometryGUI::Modified();
589 //=====================================================================================
590 // function : DisplayGUI::GetNameMode()
591 // purpose : Get the "show name" mode of the viewer
592 //=====================================================================================
593 int DisplayGUI::GetNameMode( SUIT_ViewWindow* viewWindow )
596 viewWindow = getGeometryGUI()->getApp()->desktop()->activeWindow();
597 return viewWindow->property( "NameMode" ).toBool();
600 //=====================================================================================
601 // function : DisplayGUI::ChangeDisplayMode()
602 // purpose : Set display mode for selected objects in the viewer given
603 // (current viewer if <viewWindow> = 0 )
604 //=====================================================================================
605 void DisplayGUI::ChangeDisplayMode( const int mode, SUIT_ViewWindow* viewWindow )
607 SalomeApp_Application* app = getGeometryGUI()->getApp();
611 viewWindow = app->desktop()->activeWindow();
613 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
614 if ( !aSelMgr ) return;
616 SalomeApp_Study* aStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
617 if ( !aStudy ) return;
619 SUIT_OverrideCursor wc;
621 SALOME_ListIO selected;
622 aSelMgr->selectedObjects( selected );
623 if ( selected.IsEmpty() ) return;
625 GEOM_Displayer displayer;
627 int mgrId = viewWindow->getViewManager()->getGlobalId();
629 QVariant v = aStudy->getObjectProperty( mgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::EdgesDirection ), QVariant() );
630 bool vectorMode = v.isValid() ? !v.toBool() : false;
631 v = aStudy->getObjectProperty( mgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::Vertices ), QVariant() );
632 bool verticesMode = v.isValid() ? !v.toBool() : false;
633 v = aStudy->getObjectProperty( mgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::ShowName ), QVariant() );
634 bool nameMode = v.isValid() ? !v.toBool() : false;
636 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
637 Handle( SALOME_InteractiveObject ) io = It.Value();
638 if ( mode == 0 || mode == 1 || mode == 2 || mode == 3 ) {
639 aStudy->setObjectProperty( mgrId, io->getEntry(), GEOM::propertyName( GEOM::DisplayMode ), mode );
641 else if ( mode == 4 ) {
642 aStudy->setObjectProperty( mgrId, io->getEntry(), GEOM::propertyName( GEOM::EdgesDirection ), vectorMode );
644 else if ( mode == 5 ) {
645 aStudy->setObjectProperty( mgrId, io->getEntry(), GEOM::propertyName( GEOM::Vertices ), verticesMode );
647 else if ( mode == 6 ) {
648 aStudy->setObjectProperty( mgrId, io->getEntry(), GEOM::propertyName( GEOM::ShowName ), nameMode );
650 displayer.Redisplay( io, false );
652 displayer.UpdateViewer();
653 GeometryGUI::Modified();
656 //=====================================================================================
658 //=====================================================================================
662 __declspec( dllexport )
664 GEOMGUI* GetLibGUI( GeometryGUI* parent )
666 return new DisplayGUI( parent );