1 // Copyright (C) 2007-2012 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
22 // GEOM GEOMGUI : GUI for Geometry component
23 // File : DisplayGUI.cxx
24 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
26 #include "DisplayGUI.h"
27 #include <GeometryGUI.h>
28 #include "GeometryGUI_Operations.h"
29 #include <GEOM_Constants.h>
30 #include <GEOM_Displayer.h>
31 #include <GEOM_AISShape.hxx>
32 #include <GEOM_Actor.h>
34 #include <SUIT_Desktop.h>
35 #include <SUIT_ViewWindow.h>
36 #include <SUIT_OverrideCursor.h>
38 #include <OCCViewer_ViewManager.h>
39 #include <OCCViewer_ViewModel.h>
41 #include <SALOME_ListIO.hxx>
42 #include <SALOME_ListIteratorOfListIO.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::OpShowAll: // MENU VIEW - SHOW ALL
105 getGeometryGUI()->EmitSignalDeactivateDialog();
108 case GEOMOp::OpShowOnly: // POPUP MENU - SHOW ONLY
109 getGeometryGUI()->EmitSignalDeactivateDialog();
112 case GEOMOp::OpShowOnlyChildren: // POPUP MENU - SHOW ONLY CHILDREN
113 getGeometryGUI()->EmitSignalDeactivateDialog();
114 DisplayOnlyChildren();
116 case GEOMOp::OpHideAll: // MENU VIEW - HIDE ALL
119 case GEOMOp::OpHide: // POPUP MENU - HIDE
122 case GEOMOp::OpShow: // POPUP MENU - SHOW
123 getGeometryGUI()->EmitSignalDeactivateDialog();
126 case GEOMOp::OpSwitchVectors: // MENU VIEW - DISPLAY MODE - SHOW EDGE DIRECTION
127 SetVectorMode(!GetVectorMode());
128 getGeometryGUI()->action( GEOMOp::OpSwitchVectors )->setText
129 ( GetVectorMode() ? tr("MEN_VECTOR_MODE_ON") : tr( "MEN_VECTOR_MODE_OFF" ) );
130 getGeometryGUI()->menuMgr()->update();
132 case GEOMOp::OpWireframe: // POPUP MENU - DISPLAY MODE - WIREFRAME
133 ChangeDisplayMode( 0 );
135 case GEOMOp::OpShading: // POPUP MENU - DISPLAY MODE - SHADING
136 ChangeDisplayMode( 1 );
138 case GEOMOp::OpShadingWithEdges: // POPUP MENU - DISPLAY MODE - SHADING WITH EDGES
139 ChangeDisplayMode( 2 );
141 case GEOMOp::OpTexture: // POPUP MENU - DISPLAY MODE - TEXTURE
142 ChangeDisplayMode( 3 );
144 case GEOMOp::OpVectors: // POPUP MENU - DISPLAY MODE - SHOW EDGE DIRECTION
145 ChangeDisplayMode( 4 );
148 app->putInfo(tr("GEOM_PRP_COMMAND").arg(theCommandID));
151 Sel->setSelectedObjects( selected );
155 //=====================================================================================
156 // function : DisplayGUI::DisplayAll()
157 // purpose : Display all GEOM objects
158 //=====================================================================================
159 void DisplayGUI::DisplayAll()
161 SalomeApp_Application* app = getGeometryGUI()->getApp();
164 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
165 if ( !appStudy ) return;
166 _PTR(Study) aStudy = appStudy->studyDS();
167 if ( !aStudy ) return;
168 _PTR(SComponent) SC ( aStudy->FindComponent( "GEOM" ) );
172 SALOME_ListIO listIO;
173 _PTR(ChildIterator) anIter ( aStudy->NewChildIterator( SC ) );
174 anIter->InitEx( true );
176 SUIT_OverrideCursor();
178 while( anIter->More() ) {
179 _PTR(SObject) valSO ( anIter->Value() );
181 if ( !valSO->ReferencedObject( refSO ) ) {
182 listIO.Append( new SALOME_InteractiveObject(valSO->GetID().c_str(),
183 SC->ComponentDataType().c_str(),
184 valSO->GetName().c_str()) );
188 GEOM_Displayer( appStudy ).Display( listIO, true );
191 //=====================================================================================
192 // function : DisplayGUI::EraseAll()
193 // purpose : Erase all GEOM objects
194 //=====================================================================================
195 void DisplayGUI::EraseAll()
197 SUIT_OverrideCursor();
199 SUIT_Application* app = getGeometryGUI()->getApp();
201 SUIT_ViewWindow* vw = app->desktop()->activeWindow();
203 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
204 SUIT_ViewManager* vman = vw->getViewManager();
205 if ( vman->getType() == OCCViewer_Viewer::Type() ||
206 vman->getType() == SVTK_Viewer::Type() ) {
207 GEOM_Displayer( appStudy ).EraseAll(true);
213 //=====================================================================================
214 // function : DisplayGUI::DisplayOnly()
215 // purpose : Display selected GEOM objects and erase other
216 //=====================================================================================
217 void DisplayGUI::DisplayOnly()
223 //=====================================================================================
224 // function : DisplayGUI::DisplayOnlyChildren()
225 // purpose : Display only children of selected GEOM objects and erase other
226 //=====================================================================================
227 void DisplayGUI::DisplayOnlyChildren()
231 SALOME_ListIO listIO;
233 SalomeApp_Application* app = getGeometryGUI()->getApp();
236 SalomeApp_Study* anActiveStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
237 if (!anActiveStudy) return;
239 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
240 if (!aSelMgr) return;
244 //aSelMgr->selectedObjects(aList);
245 aSelMgr->selectedObjects(aList, "ObjectBrowser", false);
246 SALOME_ListIteratorOfListIO It (aList);
248 SUIT_OverrideCursor();
250 for (; It.More(); It.Next()) {
251 Handle(SALOME_InteractiveObject) anIObject = It.Value();
252 if (anIObject->hasEntry()) {
253 _PTR(SObject) SO (anActiveStudy->studyDS()->FindObjectID(anIObject->getEntry()));
255 _PTR(SComponent) SC (SO->GetFatherComponent());
256 if (QString(SO->GetID().c_str()) == QString(SO->GetFatherComponent()->GetID().c_str())) {
257 // if component is selected, pass it
260 _PTR(ChildIterator) anIter (anActiveStudy->studyDS()->NewChildIterator(SO));
261 anIter->InitEx(true);
262 while (anIter->More()) {
263 _PTR(SObject) valSO (anIter->Value());
265 if (!valSO->ReferencedObject(refSO)) {
266 listIO.Append(new SALOME_InteractiveObject(valSO->GetID().c_str(),
267 SC->ComponentDataType().c_str(),
268 valSO->GetName().c_str()));
276 GEOM_Displayer(anActiveStudy).Display(listIO, true);
279 //=====================================================================================
280 // function : DisplayGUI::Display()
281 // purpose : Display selected GEOM objects
282 //=====================================================================================
283 void DisplayGUI::Display()
285 SALOME_ListIO listIO;
287 SalomeApp_Application* app = getGeometryGUI()->getApp();
290 SalomeApp_Study* anActiveStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
291 if ( !anActiveStudy ) return;
293 //get SalomeApp selection manager
294 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
295 if ( !aSelMgr ) return;
298 aSelMgr->selectedObjects( aList );
299 SALOME_ListIteratorOfListIO It( aList );
301 SUIT_OverrideCursor();
303 for( ;It.More();It.Next() ) {
304 Handle(SALOME_InteractiveObject) anIObject = It.Value();
305 if ( anIObject->hasEntry() ) {
306 _PTR(SObject) SO ( anActiveStudy->studyDS()->FindObjectID( anIObject->getEntry() ) );
307 if ( SO && QString(SO->GetID().c_str()) == QString(SO->GetFatherComponent()->GetID().c_str()) ) {
308 _PTR(SComponent) SC ( SO->GetFatherComponent() );
309 // if component is selected
311 _PTR(ChildIterator) anIter ( anActiveStudy->studyDS()->NewChildIterator( SO ) );
312 anIter->InitEx( true );
313 while( anIter->More() ) {
314 _PTR(SObject) valSO ( anIter->Value() );
316 if ( !valSO->ReferencedObject( refSO ) ) {
317 listIO.Append( new SALOME_InteractiveObject(valSO->GetID().c_str(),
318 SC->ComponentDataType().c_str(),
319 valSO->GetName().c_str()) );
326 listIO.Append( anIObject );
330 listIO.Append( anIObject );
333 GEOM_Displayer( anActiveStudy ).Display( listIO, true );
337 //=====================================================================================
338 // function : DisplayGUI::Erase()
339 // purpose : Erase selected GEOM objects
340 //=====================================================================================
341 void DisplayGUI::Erase()
343 SALOME_ListIO listIO;
345 SalomeApp_Application* app = getGeometryGUI()->getApp();
348 SalomeApp_Study* anActiveStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
349 if ( !anActiveStudy ) return;
351 //get SalomeApp selection manager
352 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
353 if ( !aSelMgr ) return;
356 aSelMgr->selectedObjects( aList );
357 SALOME_ListIteratorOfListIO It( aList );
359 SUIT_OverrideCursor();
361 for( ; It.More(); It.Next() ) {
362 Handle(SALOME_InteractiveObject) anIObject = It.Value();
363 if ( anIObject->hasEntry() ) {
364 _PTR(SObject) SO ( anActiveStudy->studyDS()->FindObjectID( anIObject->getEntry() ) );
365 if ( SO && QString(SO->GetID().c_str()) == QString(SO->GetFatherComponent()->GetID().c_str()) ) {
366 _PTR(SComponent) SC ( SO->GetFatherComponent() );
367 // if component is selected
369 _PTR(ChildIterator) anIter ( anActiveStudy->studyDS()->NewChildIterator( SO ) );
370 anIter->InitEx( true );
371 while( anIter->More() ) {
372 _PTR(SObject) valSO ( anIter->Value() );
374 if ( !valSO->ReferencedObject( refSO ) ) {
375 listIO.Append( new SALOME_InteractiveObject(valSO->GetID().c_str(),
376 SC->ComponentDataType().c_str(),
377 valSO->GetName().c_str()) );
384 listIO.Append( anIObject );
388 listIO.Append( anIObject );
392 SUIT_ViewWindow* viewWindow = app->desktop()->activeWindow();
393 bool aIsForced = true;
394 if(viewWindow->getViewManager()->getType() == SVTK_Viewer::Type())
397 GEOM_Displayer(anActiveStudy).Erase( listIO, aIsForced);
398 getGeometryGUI()->getApp()->selectionMgr()->clearSelected();
401 //=====================================================================================
402 // function : DisplayGUI::SetDisplayMode()
403 // purpose : Set display mode for the viewer (current viewer if <viewWindow> - 0 )
404 //=====================================================================================
405 void DisplayGUI::SetDisplayMode( const int mode, SUIT_ViewWindow* viewWindow )
407 SUIT_OverrideCursor();
409 SalomeApp_Application* app = getGeometryGUI()->getApp();
413 viewWindow = app->desktop()->activeWindow();
415 SalomeApp_Study* aStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
416 if ( !aStudy ) return;
418 GEOM_Displayer displayer( aStudy );
420 int mgrId = viewWindow->getViewManager()->getGlobalId();
422 SALOME_ListIO anIOlst;
423 displayer.GetActiveView()->GetVisible( anIOlst );
425 for ( SALOME_ListIteratorOfListIO It( anIOlst ); It.More(); It.Next() ) {
426 Handle( SALOME_InteractiveObject ) io = It.Value();
427 aStudy->setObjectProperty( mgrId, io->getEntry(), GEOM::propertyName( GEOM::DisplayMode ), mode );
428 displayer.Redisplay( io, false );
430 displayer.UpdateViewer();
431 GeometryGUI::Modified();
434 //=====================================================================================
435 // function : DisplayGUI::SetVectorsMode()
436 // purpose : Set vector mode for the viewer
437 //=====================================================================================
438 void DisplayGUI::SetVectorMode( const bool mode, SUIT_ViewWindow* viewWindow )
440 SUIT_OverrideCursor();
442 SalomeApp_Application* app = getGeometryGUI()->getApp();
445 SalomeApp_Study* aStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
446 if ( !aStudy ) return;
449 viewWindow = app->desktop()->activeWindow();
451 GEOM_Displayer displayer( aStudy );
453 viewWindow->setProperty( "VectorsMode", mode );
455 int aMgrId = viewWindow->getViewManager()->getGlobalId();
457 SALOME_ListIO anIOlst;
458 displayer.GetActiveView()->GetVisible( anIOlst );
460 for ( SALOME_ListIteratorOfListIO It( anIOlst ); It.More(); It.Next() ) {
461 Handle( SALOME_InteractiveObject ) io = It.Value();
462 aStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::EdgesDirection ), mode );
463 displayer.Redisplay( io, false );
465 displayer.UpdateViewer();
466 GeometryGUI::Modified();
469 //=====================================================================================
470 // function : DisplayGUI::GetVectorMode()
471 // purpose : Get the "show edge direction" mode of the viewer
472 //=====================================================================================
473 int DisplayGUI::GetVectorMode( SUIT_ViewWindow* viewWindow )
476 viewWindow = getGeometryGUI()->getApp()->desktop()->activeWindow();
477 return viewWindow->property( "VectorsMode" ).toBool();
480 //=====================================================================================
481 // function : DisplayGUI::ChangeDisplayMode()
482 // purpose : Set display mode for selected objects in the viewer given
483 // (current viewer if <viewWindow> = 0 )
484 //=====================================================================================
485 void DisplayGUI::ChangeDisplayMode( const int mode, SUIT_ViewWindow* viewWindow )
487 SalomeApp_Application* app = getGeometryGUI()->getApp();
491 viewWindow = app->desktop()->activeWindow();
493 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
494 if ( !aSelMgr ) return;
496 SalomeApp_Study* aStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
497 if ( !aStudy ) return;
499 SUIT_OverrideCursor();
501 SALOME_ListIO selected;
502 aSelMgr->selectedObjects( selected );
503 if ( selected.IsEmpty() ) return;
505 GEOM_Displayer displayer( aStudy );
507 int mgrId = viewWindow->getViewManager()->getGlobalId();
509 QVariant v = aStudy->getObjectProperty( mgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::EdgesDirection ), QVariant() );
510 bool vectorMode = v.isValid() ? !v.toBool() : false;
512 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
513 Handle( SALOME_InteractiveObject ) io = It.Value();
514 if ( mode == 0 || mode == 1 || mode == 2 || mode == 3 ) {
515 aStudy->setObjectProperty( mgrId, io->getEntry(), GEOM::propertyName( GEOM::DisplayMode ), mode );
517 else if ( mode == 4 ) {
518 aStudy->setObjectProperty( mgrId, io->getEntry(), GEOM::propertyName( GEOM::EdgesDirection ), vectorMode );
520 displayer.Redisplay( io, false );
522 displayer.UpdateViewer();
523 GeometryGUI::Modified();
526 //=====================================================================================
528 //=====================================================================================
532 __declspec( dllexport )
534 GEOMGUI* GetLibGUI( GeometryGUI* parent )
536 return new DisplayGUI( parent );