1 // Copyright (C) 2007-2015 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 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
91 if ( !appStudy ) return false;
93 LightApp_SelectionMgr *Sel = app->selectionMgr();
94 SALOME_ListIO selected;
95 Sel->selectedObjects( selected );
97 switch ( theCommandID ) {
98 case GEOMOp::OpDMWireframe: // MENU VIEW - DISPLAY MODE - WIREFRAME
101 case GEOMOp::OpDMShading: // MENU VIEW - DISPLAY MODE - SHADING
104 case GEOMOp::OpDMShadingWithEdges: // MENU VIEW - DISPLAY MODE - SHADING WITH EDGES
107 case GEOMOp::OpDMTexture: // MENU VIEW - DISPLAY MODE - TEXTURE
110 case GEOMOp::OpShowAll: // MENU VIEW - SHOW ALL
111 getGeometryGUI()->EmitSignalDeactivateDialog();
114 case GEOMOp::OpShowOnly: // POPUP MENU - SHOW ONLY
115 getGeometryGUI()->EmitSignalDeactivateDialog();
118 case GEOMOp::OpShowOnlyChildren: // POPUP MENU - SHOW ONLY CHILDREN
119 getGeometryGUI()->EmitSignalDeactivateDialog();
120 DisplayOnlyChildren();
122 case GEOMOp::OpHideAll: // MENU VIEW - HIDE ALL
125 case GEOMOp::OpHide: // POPUP MENU - HIDE
128 case GEOMOp::OpShow: // POPUP MENU - SHOW
129 getGeometryGUI()->EmitSignalDeactivateDialog();
132 case GEOMOp::OpSwitchVectors: // MENU VIEW - DISPLAY MODE - SHOW EDGE DIRECTION
133 SetVectorMode(!GetVectorMode());
134 getGeometryGUI()->action( GEOMOp::OpSwitchVectors )->setText
135 ( GetVectorMode() ? tr("MEN_VECTOR_MODE_ON") : tr( "MEN_VECTOR_MODE_OFF" ) );
136 getGeometryGUI()->menuMgr()->update();
138 case GEOMOp::OpSwitchVertices: // MENU VIEW - DISPLAY MODE - SHOW/HIDE VERTICES
139 SetVerticesMode(!GetVerticesMode());
140 getGeometryGUI()->action( GEOMOp::OpSwitchVertices )->setText
141 ( GetVerticesMode() ? tr("MEN_VERTICES_MODE_ON") : tr( "MEN_VERTICES_MODE_OFF" ) );
142 getGeometryGUI()->menuMgr()->update();
144 case GEOMOp::OpWireframe: // POPUP MENU - DISPLAY MODE - WIREFRAME
145 ChangeDisplayMode( 0 );
147 case GEOMOp::OpShading: // POPUP MENU - DISPLAY MODE - SHADING
148 ChangeDisplayMode( 1 );
150 case GEOMOp::OpShadingWithEdges: // POPUP MENU - DISPLAY MODE - SHADING WITH EDGES
151 ChangeDisplayMode( 2 );
153 case GEOMOp::OpTexture: // POPUP MENU - DISPLAY MODE - TEXTURE
154 ChangeDisplayMode( 3 );
156 case GEOMOp::OpVectors: // POPUP MENU - DISPLAY MODE - SHOW EDGE DIRECTION
157 ChangeDisplayMode( 4 );
159 case GEOMOp::OpVertices: // POPUP MENU - DISPLAY MODE - SHOW VERTICES
160 ChangeDisplayMode( 5 );
163 app->putInfo(tr("GEOM_PRP_COMMAND").arg(theCommandID));
166 Sel->setSelectedObjects( selected );
167 GEOM_Displayer( appStudy ).UpdateColorScale();
171 //=====================================================================================
172 // function : DisplayGUI::DisplayAll()
173 // purpose : Display all GEOM objects
174 //=====================================================================================
175 void DisplayGUI::DisplayAll()
177 SalomeApp_Application* app = getGeometryGUI()->getApp();
180 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
181 if ( !appStudy ) return;
182 _PTR(Study) aStudy = appStudy->studyDS();
183 if ( !aStudy ) return;
184 _PTR(SComponent) SC ( aStudy->FindComponent( "GEOM" ) );
188 SALOME_ListIO listIO;
189 _PTR(ChildIterator) anIter ( aStudy->NewChildIterator( SC ) );
190 anIter->InitEx( true );
192 SUIT_OverrideCursor wc;
194 while( anIter->More() ) {
195 _PTR(SObject) valSO ( anIter->Value() );
197 if ( !valSO->ReferencedObject( refSO ) ) {
198 listIO.Append( new SALOME_InteractiveObject(valSO->GetID().c_str(),
199 SC->ComponentDataType().c_str(),
200 valSO->GetName().c_str()) );
204 GEOM_Displayer( appStudy ).Display( listIO, true );
207 //=====================================================================================
208 // function : DisplayGUI::EraseAll()
209 // purpose : Erase all GEOM objects
210 //=====================================================================================
211 void DisplayGUI::EraseAll()
213 SUIT_OverrideCursor wc;
215 SUIT_Application* app = getGeometryGUI()->getApp();
217 SUIT_ViewWindow* vw = app->desktop()->activeWindow();
219 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
220 SUIT_ViewManager* vman = vw->getViewManager();
221 if ( vman->getType() == OCCViewer_Viewer::Type() ||
222 vman->getType() == SVTK_Viewer::Type() ) {
223 GEOM_Displayer( appStudy ).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* anActiveStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
253 if (!anActiveStudy) return;
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 (anActiveStudy->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 (anActiveStudy->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(anActiveStudy).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* anActiveStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
307 if ( !anActiveStudy ) 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 ( anActiveStudy->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 ( anActiveStudy->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( anActiveStudy ).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* anActiveStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
365 if ( !anActiveStudy ) 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 ( anActiveStudy->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 ( anActiveStudy->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(anActiveStudy).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( aStudy );
436 int mgrId = viewWindow->getViewManager()->getGlobalId();
438 SALOME_ListIO anIOlst;
439 displayer.GetActiveView()->GetVisible( anIOlst );
441 for ( SALOME_ListIteratorOfListIO It( anIOlst ); It.More(); It.Next() ) {
442 Handle( SALOME_InteractiveObject ) io = It.Value();
443 aStudy->setObjectProperty( mgrId, io->getEntry(), GEOM::propertyName( GEOM::DisplayMode ), mode );
444 displayer.Redisplay( io, false );
446 displayer.UpdateViewer();
447 GeometryGUI::Modified();
450 //=====================================================================================
451 // function : DisplayGUI::SetVectorsMode()
452 // purpose : Set vector mode for the viewer
453 //=====================================================================================
454 void DisplayGUI::SetVectorMode( const bool mode, SUIT_ViewWindow* viewWindow )
456 SUIT_OverrideCursor wc;
458 SalomeApp_Application* app = getGeometryGUI()->getApp();
461 SalomeApp_Study* aStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
462 if ( !aStudy ) return;
465 viewWindow = app->desktop()->activeWindow();
467 GEOM_Displayer displayer( aStudy );
469 viewWindow->setProperty( "VectorsMode", mode );
471 int aMgrId = viewWindow->getViewManager()->getGlobalId();
473 SALOME_ListIO anIOlst;
474 displayer.GetActiveView()->GetVisible( anIOlst );
476 for ( SALOME_ListIteratorOfListIO It( anIOlst ); It.More(); It.Next() ) {
477 Handle( SALOME_InteractiveObject ) io = It.Value();
478 aStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::EdgesDirection ), mode );
479 displayer.Redisplay( io, false );
481 displayer.UpdateViewer();
482 GeometryGUI::Modified();
485 //=====================================================================================
486 // function : DisplayGUI::GetVectorMode()
487 // purpose : Get the "show edge direction" mode of the viewer
488 //=====================================================================================
489 int DisplayGUI::GetVectorMode( SUIT_ViewWindow* viewWindow )
492 viewWindow = getGeometryGUI()->getApp()->desktop()->activeWindow();
493 return viewWindow->property( "VectorsMode" ).toBool();
496 //=====================================================================================
497 // function : DisplayGUI::SetVerticesMode()
498 // purpose : Set vertices mode for the viewer
499 //=====================================================================================
500 void DisplayGUI::SetVerticesMode( const bool mode, SUIT_ViewWindow* viewWindow )
502 SUIT_OverrideCursor wc;
504 SalomeApp_Application* app = getGeometryGUI()->getApp();
507 SalomeApp_Study* aStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
508 if ( !aStudy ) return;
511 viewWindow = app->desktop()->activeWindow();
513 GEOM_Displayer displayer( aStudy );
515 viewWindow->setProperty( "VerticesMode", mode );
517 int aMgrId = viewWindow->getViewManager()->getGlobalId();
519 SALOME_ListIO anIOlst;
520 displayer.GetActiveView()->GetVisible( anIOlst );
522 for ( SALOME_ListIteratorOfListIO It( anIOlst ); It.More(); It.Next() ) {
523 Handle( SALOME_InteractiveObject ) io = It.Value();
524 aStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::Vertices ), mode );
525 displayer.Redisplay( io, false );
527 displayer.UpdateViewer();
528 GeometryGUI::Modified();
531 //=====================================================================================
532 // function : DisplayGUI::GetVerticesMode()
533 // purpose : Get the "show vertices" mode of the viewer
534 //=====================================================================================
535 int DisplayGUI::GetVerticesMode( SUIT_ViewWindow* viewWindow )
538 viewWindow = getGeometryGUI()->getApp()->desktop()->activeWindow();
539 return viewWindow->property( "VerticesMode" ).toBool();
542 //=====================================================================================
543 // function : DisplayGUI::ChangeDisplayMode()
544 // purpose : Set display mode for selected objects in the viewer given
545 // (current viewer if <viewWindow> = 0 )
546 //=====================================================================================
547 void DisplayGUI::ChangeDisplayMode( const int mode, SUIT_ViewWindow* viewWindow )
549 SalomeApp_Application* app = getGeometryGUI()->getApp();
553 viewWindow = app->desktop()->activeWindow();
555 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
556 if ( !aSelMgr ) return;
558 SalomeApp_Study* aStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
559 if ( !aStudy ) return;
561 SUIT_OverrideCursor wc;
563 SALOME_ListIO selected;
564 aSelMgr->selectedObjects( selected );
565 if ( selected.IsEmpty() ) return;
567 GEOM_Displayer displayer( aStudy );
569 int mgrId = viewWindow->getViewManager()->getGlobalId();
571 QVariant v = aStudy->getObjectProperty( mgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::EdgesDirection ), QVariant() );
572 bool vectorMode = v.isValid() ? !v.toBool() : false;
573 v = aStudy->getObjectProperty( mgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::Vertices ), QVariant() );
574 bool verticesMode = v.isValid() ? !v.toBool() : false;
576 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
577 Handle( SALOME_InteractiveObject ) io = It.Value();
578 if ( mode == 0 || mode == 1 || mode == 2 || mode == 3 ) {
579 aStudy->setObjectProperty( mgrId, io->getEntry(), GEOM::propertyName( GEOM::DisplayMode ), mode );
581 else if ( mode == 4 ) {
582 aStudy->setObjectProperty( mgrId, io->getEntry(), GEOM::propertyName( GEOM::EdgesDirection ), vectorMode );
584 else if ( mode == 5 ) {
585 aStudy->setObjectProperty( mgrId, io->getEntry(), GEOM::propertyName( GEOM::Vertices ), verticesMode );
587 displayer.Redisplay( io, false );
589 displayer.UpdateViewer();
590 GeometryGUI::Modified();
593 //=====================================================================================
595 //=====================================================================================
599 __declspec( dllexport )
601 GEOMGUI* GetLibGUI( GeometryGUI* parent )
603 return new DisplayGUI( parent );