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::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::OpWireframe: // POPUP MENU - DISPLAY MODE - WIREFRAME
140 ChangeDisplayMode( 0 );
142 case GEOMOp::OpShading: // POPUP MENU - DISPLAY MODE - SHADING
143 ChangeDisplayMode( 1 );
145 case GEOMOp::OpShadingWithEdges: // POPUP MENU - DISPLAY MODE - SHADING WITH EDGES
146 ChangeDisplayMode( 2 );
148 case GEOMOp::OpTexture: // POPUP MENU - DISPLAY MODE - TEXTURE
149 ChangeDisplayMode( 3 );
151 case GEOMOp::OpVectors: // POPUP MENU - DISPLAY MODE - SHOW EDGE DIRECTION
152 ChangeDisplayMode( 4 );
155 app->putInfo(tr("GEOM_PRP_COMMAND").arg(theCommandID));
158 Sel->setSelectedObjects( selected );
159 GEOM_Displayer( appStudy ).UpdateColorScale();
163 //=====================================================================================
164 // function : DisplayGUI::DisplayAll()
165 // purpose : Display all GEOM objects
166 //=====================================================================================
167 void DisplayGUI::DisplayAll()
169 SalomeApp_Application* app = getGeometryGUI()->getApp();
172 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
173 if ( !appStudy ) return;
174 _PTR(Study) aStudy = appStudy->studyDS();
175 if ( !aStudy ) return;
176 _PTR(SComponent) SC ( aStudy->FindComponent( "GEOM" ) );
180 SALOME_ListIO listIO;
181 _PTR(ChildIterator) anIter ( aStudy->NewChildIterator( SC ) );
182 anIter->InitEx( true );
184 SUIT_OverrideCursor();
186 while( anIter->More() ) {
187 _PTR(SObject) valSO ( anIter->Value() );
189 if ( !valSO->ReferencedObject( refSO ) ) {
190 listIO.Append( new SALOME_InteractiveObject(valSO->GetID().c_str(),
191 SC->ComponentDataType().c_str(),
192 valSO->GetName().c_str()) );
196 GEOM_Displayer( appStudy ).Display( listIO, true );
199 //=====================================================================================
200 // function : DisplayGUI::EraseAll()
201 // purpose : Erase all GEOM objects
202 //=====================================================================================
203 void DisplayGUI::EraseAll()
205 SUIT_OverrideCursor();
207 SUIT_Application* app = getGeometryGUI()->getApp();
209 SUIT_ViewWindow* vw = app->desktop()->activeWindow();
211 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
212 SUIT_ViewManager* vman = vw->getViewManager();
213 if ( vman->getType() == OCCViewer_Viewer::Type() ||
214 vman->getType() == SVTK_Viewer::Type() ) {
215 GEOM_Displayer( appStudy ).EraseAll(true);
221 //=====================================================================================
222 // function : DisplayGUI::DisplayOnly()
223 // purpose : Display selected GEOM objects and erase other
224 //=====================================================================================
225 void DisplayGUI::DisplayOnly()
231 //=====================================================================================
232 // function : DisplayGUI::DisplayOnlyChildren()
233 // purpose : Display only children of selected GEOM objects and erase other
234 //=====================================================================================
235 void DisplayGUI::DisplayOnlyChildren()
239 SALOME_ListIO listIO;
241 SalomeApp_Application* app = getGeometryGUI()->getApp();
244 SalomeApp_Study* anActiveStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
245 if (!anActiveStudy) return;
247 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
248 if (!aSelMgr) return;
252 //aSelMgr->selectedObjects(aList);
253 aSelMgr->selectedObjects(aList, "ObjectBrowser", false);
254 SALOME_ListIteratorOfListIO It (aList);
256 SUIT_OverrideCursor();
258 for (; It.More(); It.Next()) {
259 Handle(SALOME_InteractiveObject) anIObject = It.Value();
260 if (anIObject->hasEntry()) {
261 _PTR(SObject) SO (anActiveStudy->studyDS()->FindObjectID(anIObject->getEntry()));
263 _PTR(SComponent) SC (SO->GetFatherComponent());
264 if (QString(SO->GetID().c_str()) == QString(SO->GetFatherComponent()->GetID().c_str())) {
265 // if component is selected, pass it
268 _PTR(ChildIterator) anIter (anActiveStudy->studyDS()->NewChildIterator(SO));
269 anIter->InitEx(true);
270 while (anIter->More()) {
271 _PTR(SObject) valSO (anIter->Value());
273 if (!valSO->ReferencedObject(refSO)) {
274 listIO.Append(new SALOME_InteractiveObject(valSO->GetID().c_str(),
275 SC->ComponentDataType().c_str(),
276 valSO->GetName().c_str()));
284 GEOM_Displayer(anActiveStudy).Display(listIO, true);
287 //=====================================================================================
288 // function : DisplayGUI::Display()
289 // purpose : Display selected GEOM objects
290 //=====================================================================================
291 void DisplayGUI::Display()
293 SALOME_ListIO listIO;
295 SalomeApp_Application* app = getGeometryGUI()->getApp();
298 SalomeApp_Study* anActiveStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
299 if ( !anActiveStudy ) return;
301 //get SalomeApp selection manager
302 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
303 if ( !aSelMgr ) return;
306 aSelMgr->selectedObjects( aList );
307 SALOME_ListIteratorOfListIO It( aList );
309 SUIT_OverrideCursor();
311 for( ;It.More();It.Next() ) {
312 Handle(SALOME_InteractiveObject) anIObject = It.Value();
313 if ( anIObject->hasEntry() ) {
314 _PTR(SObject) SO ( anActiveStudy->studyDS()->FindObjectID( anIObject->getEntry() ) );
315 if ( SO && QString(SO->GetID().c_str()) == QString(SO->GetFatherComponent()->GetID().c_str()) ) {
316 _PTR(SComponent) SC ( SO->GetFatherComponent() );
317 // if component is selected
319 _PTR(ChildIterator) anIter ( anActiveStudy->studyDS()->NewChildIterator( SO ) );
320 anIter->InitEx( true );
321 while( anIter->More() ) {
322 _PTR(SObject) valSO ( anIter->Value() );
324 if ( !valSO->ReferencedObject( refSO ) ) {
325 listIO.Append( new SALOME_InteractiveObject(valSO->GetID().c_str(),
326 SC->ComponentDataType().c_str(),
327 valSO->GetName().c_str()) );
334 listIO.Append( anIObject );
338 listIO.Append( anIObject );
341 GEOM_Displayer( anActiveStudy ).Display( listIO, true );
345 //=====================================================================================
346 // function : DisplayGUI::Erase()
347 // purpose : Erase selected GEOM objects
348 //=====================================================================================
349 void DisplayGUI::Erase()
351 SALOME_ListIO listIO;
353 SalomeApp_Application* app = getGeometryGUI()->getApp();
356 SalomeApp_Study* anActiveStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
357 if ( !anActiveStudy ) return;
359 //get SalomeApp selection manager
360 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
361 if ( !aSelMgr ) return;
364 aSelMgr->selectedObjects( aList );
365 SALOME_ListIteratorOfListIO It( aList );
367 SUIT_OverrideCursor();
369 for( ; It.More(); It.Next() ) {
370 Handle(SALOME_InteractiveObject) anIObject = It.Value();
371 if ( anIObject->hasEntry() ) {
372 _PTR(SObject) SO ( anActiveStudy->studyDS()->FindObjectID( anIObject->getEntry() ) );
373 if ( SO && QString(SO->GetID().c_str()) == QString(SO->GetFatherComponent()->GetID().c_str()) ) {
374 _PTR(SComponent) SC ( SO->GetFatherComponent() );
375 // if component is selected
377 _PTR(ChildIterator) anIter ( anActiveStudy->studyDS()->NewChildIterator( SO ) );
378 anIter->InitEx( true );
379 while( anIter->More() ) {
380 _PTR(SObject) valSO ( anIter->Value() );
382 if ( !valSO->ReferencedObject( refSO ) ) {
383 listIO.Append( new SALOME_InteractiveObject(valSO->GetID().c_str(),
384 SC->ComponentDataType().c_str(),
385 valSO->GetName().c_str()) );
392 listIO.Append( anIObject );
396 listIO.Append( anIObject );
400 SUIT_ViewWindow* viewWindow = app->desktop()->activeWindow();
401 bool aIsForced = true;
402 if(viewWindow->getViewManager()->getType() == SVTK_Viewer::Type())
405 GEOM_Displayer(anActiveStudy).Erase( listIO, aIsForced);
406 getGeometryGUI()->getApp()->selectionMgr()->clearSelected();
409 //=====================================================================================
410 // function : DisplayGUI::SetDisplayMode()
411 // purpose : Set display mode for the viewer (current viewer if <viewWindow> - 0 )
412 //=====================================================================================
413 void DisplayGUI::SetDisplayMode( const int mode, SUIT_ViewWindow* viewWindow )
415 SUIT_OverrideCursor();
417 SalomeApp_Application* app = getGeometryGUI()->getApp();
421 viewWindow = app->desktop()->activeWindow();
423 SalomeApp_Study* aStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
424 if ( !aStudy ) return;
426 GEOM_Displayer displayer( aStudy );
428 int mgrId = viewWindow->getViewManager()->getGlobalId();
430 SALOME_ListIO anIOlst;
431 displayer.GetActiveView()->GetVisible( anIOlst );
433 for ( SALOME_ListIteratorOfListIO It( anIOlst ); It.More(); It.Next() ) {
434 Handle( SALOME_InteractiveObject ) io = It.Value();
435 aStudy->setObjectProperty( mgrId, io->getEntry(), GEOM::propertyName( GEOM::DisplayMode ), mode );
436 displayer.Redisplay( io, false );
438 displayer.UpdateViewer();
439 GeometryGUI::Modified();
442 //=====================================================================================
443 // function : DisplayGUI::SetVectorsMode()
444 // purpose : Set vector mode for the viewer
445 //=====================================================================================
446 void DisplayGUI::SetVectorMode( const bool mode, SUIT_ViewWindow* viewWindow )
448 SUIT_OverrideCursor();
450 SalomeApp_Application* app = getGeometryGUI()->getApp();
453 SalomeApp_Study* aStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
454 if ( !aStudy ) return;
457 viewWindow = app->desktop()->activeWindow();
459 GEOM_Displayer displayer( aStudy );
461 viewWindow->setProperty( "VectorsMode", mode );
463 int aMgrId = viewWindow->getViewManager()->getGlobalId();
465 SALOME_ListIO anIOlst;
466 displayer.GetActiveView()->GetVisible( anIOlst );
468 for ( SALOME_ListIteratorOfListIO It( anIOlst ); It.More(); It.Next() ) {
469 Handle( SALOME_InteractiveObject ) io = It.Value();
470 aStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::EdgesDirection ), mode );
471 displayer.Redisplay( io, false );
473 displayer.UpdateViewer();
474 GeometryGUI::Modified();
477 //=====================================================================================
478 // function : DisplayGUI::GetVectorMode()
479 // purpose : Get the "show edge direction" mode of the viewer
480 //=====================================================================================
481 int DisplayGUI::GetVectorMode( SUIT_ViewWindow* viewWindow )
484 viewWindow = getGeometryGUI()->getApp()->desktop()->activeWindow();
485 return viewWindow->property( "VectorsMode" ).toBool();
488 //=====================================================================================
489 // function : DisplayGUI::ChangeDisplayMode()
490 // purpose : Set display mode for selected objects in the viewer given
491 // (current viewer if <viewWindow> = 0 )
492 //=====================================================================================
493 void DisplayGUI::ChangeDisplayMode( const int mode, SUIT_ViewWindow* viewWindow )
495 SalomeApp_Application* app = getGeometryGUI()->getApp();
499 viewWindow = app->desktop()->activeWindow();
501 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
502 if ( !aSelMgr ) return;
504 SalomeApp_Study* aStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
505 if ( !aStudy ) return;
507 SUIT_OverrideCursor();
509 SALOME_ListIO selected;
510 aSelMgr->selectedObjects( selected );
511 if ( selected.IsEmpty() ) return;
513 GEOM_Displayer displayer( aStudy );
515 int mgrId = viewWindow->getViewManager()->getGlobalId();
517 QVariant v = aStudy->getObjectProperty( mgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::EdgesDirection ), QVariant() );
518 bool vectorMode = v.isValid() ? !v.toBool() : false;
520 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
521 Handle( SALOME_InteractiveObject ) io = It.Value();
522 if ( mode == 0 || mode == 1 || mode == 2 || mode == 3 ) {
523 aStudy->setObjectProperty( mgrId, io->getEntry(), GEOM::propertyName( GEOM::DisplayMode ), mode );
525 else if ( mode == 4 ) {
526 aStudy->setObjectProperty( mgrId, io->getEntry(), GEOM::propertyName( GEOM::EdgesDirection ), vectorMode );
528 displayer.Redisplay( io, false );
530 displayer.UpdateViewer();
531 GeometryGUI::Modified();
534 //=====================================================================================
536 //=====================================================================================
540 __declspec( dllexport )
542 GEOMGUI* GetLibGUI( GeometryGUI* parent )
544 return new DisplayGUI( parent );