1 // Copyright (C) 2007-2013 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_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::OpShowAll: // MENU VIEW - SHOW ALL
109 getGeometryGUI()->EmitSignalDeactivateDialog();
112 case GEOMOp::OpShowOnly: // POPUP MENU - SHOW ONLY
113 getGeometryGUI()->EmitSignalDeactivateDialog();
116 case GEOMOp::OpShowOnlyChildren: // POPUP MENU - SHOW ONLY CHILDREN
117 getGeometryGUI()->EmitSignalDeactivateDialog();
118 DisplayOnlyChildren();
120 case GEOMOp::OpHideAll: // MENU VIEW - HIDE ALL
123 case GEOMOp::OpHide: // POPUP MENU - HIDE
126 case GEOMOp::OpShow: // POPUP MENU - SHOW
127 getGeometryGUI()->EmitSignalDeactivateDialog();
130 case GEOMOp::OpSwitchVectors: // MENU VIEW - DISPLAY MODE - SHOW EDGE DIRECTION
131 SetVectorMode(!GetVectorMode());
132 getGeometryGUI()->action( GEOMOp::OpSwitchVectors )->setText
133 ( GetVectorMode() ? tr("MEN_VECTOR_MODE_ON") : tr( "MEN_VECTOR_MODE_OFF" ) );
134 getGeometryGUI()->menuMgr()->update();
136 case GEOMOp::OpWireframe: // POPUP MENU - DISPLAY MODE - WIREFRAME
137 ChangeDisplayMode( 0 );
139 case GEOMOp::OpShading: // POPUP MENU - DISPLAY MODE - SHADING
140 ChangeDisplayMode( 1 );
142 case GEOMOp::OpShadingWithEdges: // POPUP MENU - DISPLAY MODE - SHADING WITH EDGES
143 ChangeDisplayMode( 2 );
145 case GEOMOp::OpTexture: // POPUP MENU - DISPLAY MODE - TEXTURE
146 ChangeDisplayMode( 3 );
148 case GEOMOp::OpVectors: // POPUP MENU - DISPLAY MODE - SHOW EDGE DIRECTION
149 ChangeDisplayMode( 4 );
152 app->putInfo(tr("GEOM_PRP_COMMAND").arg(theCommandID));
155 Sel->setSelectedObjects( selected );
156 GEOM_Displayer( appStudy ).UpdateColorScale();
160 //=====================================================================================
161 // function : DisplayGUI::DisplayAll()
162 // purpose : Display all GEOM objects
163 //=====================================================================================
164 void DisplayGUI::DisplayAll()
166 SalomeApp_Application* app = getGeometryGUI()->getApp();
169 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
170 if ( !appStudy ) return;
171 _PTR(Study) aStudy = appStudy->studyDS();
172 if ( !aStudy ) return;
173 _PTR(SComponent) SC ( aStudy->FindComponent( "GEOM" ) );
177 SALOME_ListIO listIO;
178 _PTR(ChildIterator) anIter ( aStudy->NewChildIterator( SC ) );
179 anIter->InitEx( true );
181 SUIT_OverrideCursor();
183 while( anIter->More() ) {
184 _PTR(SObject) valSO ( anIter->Value() );
186 if ( !valSO->ReferencedObject( refSO ) ) {
187 listIO.Append( new SALOME_InteractiveObject(valSO->GetID().c_str(),
188 SC->ComponentDataType().c_str(),
189 valSO->GetName().c_str()) );
193 GEOM_Displayer( appStudy ).Display( listIO, true );
196 //=====================================================================================
197 // function : DisplayGUI::EraseAll()
198 // purpose : Erase all GEOM objects
199 //=====================================================================================
200 void DisplayGUI::EraseAll()
202 SUIT_OverrideCursor();
204 SUIT_Application* app = getGeometryGUI()->getApp();
206 SUIT_ViewWindow* vw = app->desktop()->activeWindow();
208 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
209 SUIT_ViewManager* vman = vw->getViewManager();
210 if ( vman->getType() == OCCViewer_Viewer::Type() ||
211 vman->getType() == SVTK_Viewer::Type() ) {
212 GEOM_Displayer( appStudy ).EraseAll(true);
218 //=====================================================================================
219 // function : DisplayGUI::DisplayOnly()
220 // purpose : Display selected GEOM objects and erase other
221 //=====================================================================================
222 void DisplayGUI::DisplayOnly()
228 //=====================================================================================
229 // function : DisplayGUI::DisplayOnlyChildren()
230 // purpose : Display only children of selected GEOM objects and erase other
231 //=====================================================================================
232 void DisplayGUI::DisplayOnlyChildren()
236 SALOME_ListIO listIO;
238 SalomeApp_Application* app = getGeometryGUI()->getApp();
241 SalomeApp_Study* anActiveStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
242 if (!anActiveStudy) return;
244 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
245 if (!aSelMgr) return;
249 //aSelMgr->selectedObjects(aList);
250 aSelMgr->selectedObjects(aList, "ObjectBrowser", false);
251 SALOME_ListIteratorOfListIO It (aList);
253 SUIT_OverrideCursor();
255 for (; It.More(); It.Next()) {
256 Handle(SALOME_InteractiveObject) anIObject = It.Value();
257 if (anIObject->hasEntry()) {
258 _PTR(SObject) SO (anActiveStudy->studyDS()->FindObjectID(anIObject->getEntry()));
260 _PTR(SComponent) SC (SO->GetFatherComponent());
261 if (QString(SO->GetID().c_str()) == QString(SO->GetFatherComponent()->GetID().c_str())) {
262 // if component is selected, pass it
265 _PTR(ChildIterator) anIter (anActiveStudy->studyDS()->NewChildIterator(SO));
266 anIter->InitEx(true);
267 while (anIter->More()) {
268 _PTR(SObject) valSO (anIter->Value());
270 if (!valSO->ReferencedObject(refSO)) {
271 listIO.Append(new SALOME_InteractiveObject(valSO->GetID().c_str(),
272 SC->ComponentDataType().c_str(),
273 valSO->GetName().c_str()));
281 GEOM_Displayer(anActiveStudy).Display(listIO, true);
284 //=====================================================================================
285 // function : DisplayGUI::Display()
286 // purpose : Display selected GEOM objects
287 //=====================================================================================
288 void DisplayGUI::Display()
290 SALOME_ListIO listIO;
292 SalomeApp_Application* app = getGeometryGUI()->getApp();
295 SalomeApp_Study* anActiveStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
296 if ( !anActiveStudy ) return;
298 //get SalomeApp selection manager
299 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
300 if ( !aSelMgr ) return;
303 aSelMgr->selectedObjects( aList );
304 SALOME_ListIteratorOfListIO It( aList );
306 SUIT_OverrideCursor();
308 for( ;It.More();It.Next() ) {
309 Handle(SALOME_InteractiveObject) anIObject = It.Value();
310 if ( anIObject->hasEntry() ) {
311 _PTR(SObject) SO ( anActiveStudy->studyDS()->FindObjectID( anIObject->getEntry() ) );
312 if ( SO && QString(SO->GetID().c_str()) == QString(SO->GetFatherComponent()->GetID().c_str()) ) {
313 _PTR(SComponent) SC ( SO->GetFatherComponent() );
314 // if component is selected
316 _PTR(ChildIterator) anIter ( anActiveStudy->studyDS()->NewChildIterator( SO ) );
317 anIter->InitEx( true );
318 while( anIter->More() ) {
319 _PTR(SObject) valSO ( anIter->Value() );
321 if ( !valSO->ReferencedObject( refSO ) ) {
322 listIO.Append( new SALOME_InteractiveObject(valSO->GetID().c_str(),
323 SC->ComponentDataType().c_str(),
324 valSO->GetName().c_str()) );
331 listIO.Append( anIObject );
335 listIO.Append( anIObject );
338 GEOM_Displayer( anActiveStudy ).Display( listIO, true );
342 //=====================================================================================
343 // function : DisplayGUI::Erase()
344 // purpose : Erase selected GEOM objects
345 //=====================================================================================
346 void DisplayGUI::Erase()
348 SALOME_ListIO listIO;
350 SalomeApp_Application* app = getGeometryGUI()->getApp();
353 SalomeApp_Study* anActiveStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
354 if ( !anActiveStudy ) return;
356 //get SalomeApp selection manager
357 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
358 if ( !aSelMgr ) return;
361 aSelMgr->selectedObjects( aList );
362 SALOME_ListIteratorOfListIO It( aList );
364 SUIT_OverrideCursor();
366 for( ; It.More(); It.Next() ) {
367 Handle(SALOME_InteractiveObject) anIObject = It.Value();
368 if ( anIObject->hasEntry() ) {
369 _PTR(SObject) SO ( anActiveStudy->studyDS()->FindObjectID( anIObject->getEntry() ) );
370 if ( SO && QString(SO->GetID().c_str()) == QString(SO->GetFatherComponent()->GetID().c_str()) ) {
371 _PTR(SComponent) SC ( SO->GetFatherComponent() );
372 // if component is selected
374 _PTR(ChildIterator) anIter ( anActiveStudy->studyDS()->NewChildIterator( SO ) );
375 anIter->InitEx( true );
376 while( anIter->More() ) {
377 _PTR(SObject) valSO ( anIter->Value() );
379 if ( !valSO->ReferencedObject( refSO ) ) {
380 listIO.Append( new SALOME_InteractiveObject(valSO->GetID().c_str(),
381 SC->ComponentDataType().c_str(),
382 valSO->GetName().c_str()) );
389 listIO.Append( anIObject );
393 listIO.Append( anIObject );
397 SUIT_ViewWindow* viewWindow = app->desktop()->activeWindow();
398 bool aIsForced = true;
399 if(viewWindow->getViewManager()->getType() == SVTK_Viewer::Type())
402 GEOM_Displayer(anActiveStudy).Erase( listIO, aIsForced);
403 getGeometryGUI()->getApp()->selectionMgr()->clearSelected();
406 //=====================================================================================
407 // function : DisplayGUI::SetDisplayMode()
408 // purpose : Set display mode for the viewer (current viewer if <viewWindow> - 0 )
409 //=====================================================================================
410 void DisplayGUI::SetDisplayMode( const int mode, SUIT_ViewWindow* viewWindow )
412 SUIT_OverrideCursor();
414 SalomeApp_Application* app = getGeometryGUI()->getApp();
418 viewWindow = app->desktop()->activeWindow();
420 SalomeApp_Study* aStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
421 if ( !aStudy ) return;
423 GEOM_Displayer displayer( aStudy );
425 int mgrId = viewWindow->getViewManager()->getGlobalId();
427 SALOME_ListIO anIOlst;
428 displayer.GetActiveView()->GetVisible( anIOlst );
430 for ( SALOME_ListIteratorOfListIO It( anIOlst ); It.More(); It.Next() ) {
431 Handle( SALOME_InteractiveObject ) io = It.Value();
432 aStudy->setObjectProperty( mgrId, io->getEntry(), GEOM::propertyName( GEOM::DisplayMode ), mode );
433 displayer.Redisplay( io, false );
435 displayer.UpdateViewer();
436 GeometryGUI::Modified();
439 //=====================================================================================
440 // function : DisplayGUI::SetVectorsMode()
441 // purpose : Set vector mode for the viewer
442 //=====================================================================================
443 void DisplayGUI::SetVectorMode( const bool mode, SUIT_ViewWindow* viewWindow )
445 SUIT_OverrideCursor();
447 SalomeApp_Application* app = getGeometryGUI()->getApp();
450 SalomeApp_Study* aStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
451 if ( !aStudy ) return;
454 viewWindow = app->desktop()->activeWindow();
456 GEOM_Displayer displayer( aStudy );
458 viewWindow->setProperty( "VectorsMode", mode );
460 int aMgrId = viewWindow->getViewManager()->getGlobalId();
462 SALOME_ListIO anIOlst;
463 displayer.GetActiveView()->GetVisible( anIOlst );
465 for ( SALOME_ListIteratorOfListIO It( anIOlst ); It.More(); It.Next() ) {
466 Handle( SALOME_InteractiveObject ) io = It.Value();
467 aStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::EdgesDirection ), mode );
468 displayer.Redisplay( io, false );
470 displayer.UpdateViewer();
471 GeometryGUI::Modified();
474 //=====================================================================================
475 // function : DisplayGUI::GetVectorMode()
476 // purpose : Get the "show edge direction" mode of the viewer
477 //=====================================================================================
478 int DisplayGUI::GetVectorMode( SUIT_ViewWindow* viewWindow )
481 viewWindow = getGeometryGUI()->getApp()->desktop()->activeWindow();
482 return viewWindow->property( "VectorsMode" ).toBool();
485 //=====================================================================================
486 // function : DisplayGUI::ChangeDisplayMode()
487 // purpose : Set display mode for selected objects in the viewer given
488 // (current viewer if <viewWindow> = 0 )
489 //=====================================================================================
490 void DisplayGUI::ChangeDisplayMode( const int mode, SUIT_ViewWindow* viewWindow )
492 SalomeApp_Application* app = getGeometryGUI()->getApp();
496 viewWindow = app->desktop()->activeWindow();
498 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
499 if ( !aSelMgr ) return;
501 SalomeApp_Study* aStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
502 if ( !aStudy ) return;
504 SUIT_OverrideCursor();
506 SALOME_ListIO selected;
507 aSelMgr->selectedObjects( selected );
508 if ( selected.IsEmpty() ) return;
510 GEOM_Displayer displayer( aStudy );
512 int mgrId = viewWindow->getViewManager()->getGlobalId();
514 QVariant v = aStudy->getObjectProperty( mgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::EdgesDirection ), QVariant() );
515 bool vectorMode = v.isValid() ? !v.toBool() : false;
517 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
518 Handle( SALOME_InteractiveObject ) io = It.Value();
519 if ( mode == 0 || mode == 1 || mode == 2 || mode == 3 ) {
520 aStudy->setObjectProperty( mgrId, io->getEntry(), GEOM::propertyName( GEOM::DisplayMode ), mode );
522 else if ( mode == 4 ) {
523 aStudy->setObjectProperty( mgrId, io->getEntry(), GEOM::propertyName( GEOM::EdgesDirection ), vectorMode );
525 displayer.Redisplay( io, false );
527 displayer.UpdateViewer();
528 GeometryGUI::Modified();
531 //=====================================================================================
533 //=====================================================================================
537 __declspec( dllexport )
539 GEOMGUI* GetLibGUI( GeometryGUI* parent )
541 return new DisplayGUI( parent );