1 // GEOM GEOMGUI : GUI for Geometry component
3 // Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : DisplayGUI.cxx
25 // Author : Vadim SANDLER
29 #include "DisplayGUI.h"
30 #include "GeometryGUI.h"
31 #include "GEOM_Displayer.h"
33 #include <SUIT_Desktop.h>
34 #include <SUIT_Session.h>
35 #include <SUIT_ViewWindow.h>
36 #include <SUIT_OverrideCursor.h>
38 #include <VTKViewer_ViewWindow.h>
39 #include <VTKViewer_RenderWindowInteractor.h>
40 #include <OCCViewer_ViewManager.h>
41 #include <OCCViewer_ViewModel.h>
42 #include <OCCViewer_ViewWindow.h>
44 #include <SALOME_ListIteratorOfListIO.hxx>
46 #include <SVTK_ViewWindow.h>
47 #include <SVTK_RenderWindowInteractor.h>
48 #include <SVTK_ViewModel.h>
49 #include <SOCC_ViewModel.h>
53 #include <SalomeApp_Application.h>
54 #include <SalomeApp_SelectionMgr.h>
55 #include <SalomeApp_Study.h>
57 #include <AIS_ListIteratorOfListOfInteractive.hxx>
62 DisplayGUI* DisplayGUI::myGUIObject = 0;
64 //=======================================================================
65 // function : DisplayGUI::GetDisplayGUI()
66 // purpose : Get the only DisplayGUI object [ static ]
67 //=======================================================================
68 DisplayGUI* DisplayGUI::GetDisplayGUI( GeometryGUI* parent )
70 if ( myGUIObject == 0 ) {
71 // init DisplayGUI only once
72 myGUIObject = new DisplayGUI( parent );
77 //=======================================================================
78 // function : DisplayGUI::DisplayGUI()
79 // purpose : Constructor
80 //=======================================================================
81 DisplayGUI::DisplayGUI( GeometryGUI* parent ) : GEOMGUI( parent )
86 //=======================================================================
87 // function : DisplayGUI::~DisplayGUI()
88 // purpose : Destructor
89 //=======================================================================
90 DisplayGUI::~DisplayGUI()
95 //=======================================================================
96 // function : DisplayGUI::OnGUIEvent()
97 // purpose : Dispatch menu command
98 //=======================================================================
99 bool DisplayGUI::OnGUIEvent(int theCommandID, SUIT_Desktop* parent)
101 DisplayGUI* myDisplayGUI = GetDisplayGUI( getGeometryGUI() );
103 switch (theCommandID) {
104 case 211: // MENU VIEW - WIREFRAME/SHADING
106 myDisplayGUI->InvertDisplayMode();
107 int newMode = myDisplayGUI->GetDisplayMode();
108 SUIT_Session::session()->activeApplication()->desktop()->menuBar()->
109 changeItem( 211, newMode == 1 ? tr( "GEOM_MEN_WIREFRAME" ) : tr("GEOM_MEN_SHADING") );
112 case 212: // MENU VIEW - DISPLAY ALL
114 myDisplayGUI->DisplayAll();
117 case 213: // MENU VIEW - DISPLAY ONLY
119 myDisplayGUI->DisplayOnly();
122 case 214: // MENU VIEW - ERASE ALL
124 myDisplayGUI->EraseAll();
127 case 215: // MENU VIEW - ERASE
129 myDisplayGUI->Erase();
132 case 216: // MENU VIEW - DISPLAY
134 myDisplayGUI->Display();
137 case 80311: // POPUP VIEWER - WIREFRAME
139 myDisplayGUI->ChangeDisplayMode( 0 );
142 case 80312: // POPUP VIEWER - SHADING
144 myDisplayGUI->ChangeDisplayMode( 1 );
149 SUIT_Session::session()->activeApplication()->putInfo(tr("GEOM_PRP_COMMAND").arg(theCommandID));
156 //=====================================================================================
157 // function : DisplayGUI::DisplayAll()
158 // purpose : Display all GEOM objects
159 //=====================================================================================
160 void DisplayGUI::DisplayAll()
162 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
163 if ( !appStudy ) return;
164 _PTR(Study) aStudy = appStudy->studyDS();
165 if ( !aStudy ) return;
166 _PTR(SComponent) SC ( aStudy->FindComponent( "GEOM" ) );
170 SALOME_ListIO listIO;
171 _PTR(ChildIterator) anIter ( aStudy->NewChildIterator( SC ) );
172 anIter->InitEx( true );
174 SUIT_OverrideCursor();
176 while( anIter->More() ) {
177 _PTR(SObject) valSO ( anIter->Value() );
179 if ( !valSO->ReferencedObject( refSO ) ) {
180 listIO.Append( new SALOME_InteractiveObject( valSO->GetID().c_str(), SC->ComponentDataType().c_str() ,valSO->GetName().c_str() ) );
184 GEOM_Displayer( appStudy ).Display( listIO, true );
187 //=====================================================================================
188 // function : DisplayGUI::EraseAll()
189 // purpose : Erase all GEOM objects
190 //=====================================================================================
191 void DisplayGUI::EraseAll()
193 SUIT_OverrideCursor();
195 SUIT_Application* app = SUIT_Session::session()->activeApplication();
197 SUIT_ViewWindow* vw = app->desktop()->activeWindow();
199 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
200 SUIT_ViewManager* vman = vw->getViewManager();
201 if ( vman->getType() == OCCViewer_Viewer::Type() ||
202 vman->getType() == VTKViewer_Viewer::Type() ) {
203 GEOM_Displayer( appStudy ).EraseAll();
209 //=====================================================================================
210 // function : DisplayGUI::DisplayOnly()
211 // purpose : Display selected GEOM objects and erase other
212 //=====================================================================================
213 void DisplayGUI::DisplayOnly()
219 //=====================================================================================
220 // function : DisplayGUI::Display()
221 // purpose : Display selected GEOM objects
222 //=====================================================================================
223 void DisplayGUI::Display()
225 SALOME_ListIO listIO;
227 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
230 SalomeApp_Study* anActiveStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
231 if ( !anActiveStudy ) return;
233 //get SalomeApp selection manager
234 SalomeApp_SelectionMgr* aSelMgr = app->selectionMgr();
235 if ( !aSelMgr ) return;
238 aSelMgr->selectedObjects( aList );
239 SALOME_ListIteratorOfListIO It( aList );
241 SUIT_OverrideCursor();
243 for( ;It.More();It.Next() ) {
244 Handle(SALOME_InteractiveObject) anIObject = It.Value();
245 if ( anIObject->hasEntry() ) {
246 _PTR(SObject) SO ( anActiveStudy->studyDS()->FindObjectID( anIObject->getEntry() ) );
247 if ( SO && QString( SO->GetID().c_str() ) == QString( SO->GetFatherComponent()->GetID().c_str() ) ) {
248 _PTR(SComponent) SC ( SO->GetFatherComponent() );
249 // if component is selected
251 _PTR(ChildIterator) anIter ( anActiveStudy->studyDS()->NewChildIterator( SO ) );
252 anIter->InitEx( true );
253 while( anIter->More() ) {
254 _PTR(SObject) valSO ( anIter->Value() );
256 if ( !valSO->ReferencedObject( refSO ) ) {
257 listIO.Append( new SALOME_InteractiveObject( valSO->GetID().c_str(), SC->ComponentDataType().c_str() ,valSO->GetName().c_str() ) );
264 listIO.Append( anIObject );
268 listIO.Append( anIObject );
271 GEOM_Displayer( anActiveStudy ).Display( listIO, true );
275 //=====================================================================================
276 // function : DisplayGUI::Erase()
277 // purpose : Erase selected GEOM objects
278 //=====================================================================================
279 void DisplayGUI::Erase()
281 SALOME_ListIO listIO;
283 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
286 SalomeApp_Study* anActiveStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
287 if ( !anActiveStudy ) return;
289 //get SalomeApp selection manager
290 SalomeApp_SelectionMgr* aSelMgr = app->selectionMgr();
291 if ( !aSelMgr ) return;
294 aSelMgr->selectedObjects( aList );
295 SALOME_ListIteratorOfListIO It( aList );
297 SUIT_OverrideCursor();
299 for( ;It.More();It.Next() ) {
300 Handle(SALOME_InteractiveObject) anIObject = It.Value();
301 if ( anIObject->hasEntry() ) {
302 _PTR(SObject) SO ( anActiveStudy->studyDS()->FindObjectID( anIObject->getEntry() ) );
303 if ( SO && QString( SO->GetID().c_str() ) == QString( SO->GetFatherComponent()->GetID().c_str() ) ) {
304 _PTR(SComponent) SC ( SO->GetFatherComponent() );
305 // if component is selected
307 _PTR(ChildIterator) anIter ( anActiveStudy->studyDS()->NewChildIterator( SO ) );
308 anIter->InitEx( true );
309 while( anIter->More() ) {
310 _PTR(SObject) valSO ( anIter->Value() );
312 if ( !valSO->ReferencedObject( refSO ) ) {
313 listIO.Append( new SALOME_InteractiveObject( valSO->GetID().c_str(), SC->ComponentDataType().c_str() ,valSO->GetName().c_str() ) );
320 listIO.Append( anIObject );
324 listIO.Append( anIObject );
327 GEOM_Displayer(anActiveStudy).Erase( listIO, true );
328 ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr()->clearSelected();
331 //=====================================================================================
332 // function : DisplayGUI::SetDisplayMode()
333 // purpose : Set display mode for the viewer (current viewer if <viewWindow> - 0 )
334 //=====================================================================================
335 void DisplayGUI::SetDisplayMode( const int mode, SUIT_ViewWindow* viewWindow )
337 SUIT_OverrideCursor();
340 viewWindow = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
341 if ( viewWindow->getViewManager()->getType() == VTKViewer_Viewer::Type() ) {
342 VTKViewer_RenderWindowInteractor* myRenderInter= ((VTKViewer_ViewWindow*)viewWindow)->getRWInteractor();
343 myRenderInter->SetDisplayMode( mode );
345 else if ( viewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() ) {
346 OCCViewer_Viewer* v3d = ((OCCViewer_ViewManager*)(viewWindow->getViewManager()))->getOCCViewer();
347 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
348 AIS_DisplayMode newmode = (mode == 1 ? AIS_Shaded : AIS_WireFrame);
349 AIS_ListOfInteractive List;
350 ic->DisplayedObjects( List );
351 AIS_ListOfInteractive List1;
352 ic->ObjectsInCollector( List1 );
353 List.Append( List1 );
355 AIS_ListIteratorOfListOfInteractive ite( List );
356 while( ite.More() ) {
357 if( ite.Value()->IsInstance( STANDARD_TYPE(GEOM_AISShape) ) ) {
358 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast( ite.Value() );
359 ic->SetDisplayMode( aSh, Standard_Integer( newmode ),true );
364 ic->SetDisplayMode( newmode, Standard_False );
368 //=====================================================================================
369 // function : DisplayGUI::GetDisplayMode()
370 // purpose : Get display mode of the viewer (current viewer if <viewWindow> - 0 )
371 //=====================================================================================
372 int DisplayGUI::GetDisplayMode( SUIT_ViewWindow* viewWindow )
376 viewWindow = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
377 if ( viewWindow->getViewManager()->getType() == VTKViewer_Viewer::Type() ) {
378 VTKViewer_RenderWindowInteractor* myRenderInter= ((VTKViewer_ViewWindow*)viewWindow)->getRWInteractor();
379 dispMode = myRenderInter->GetDisplayMode();
381 else if ( viewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() ) {
382 OCCViewer_Viewer* v3d = ((OCCViewer_ViewManager*)(viewWindow->getViewManager()))->getOCCViewer();
383 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
384 AIS_DisplayMode mode = (AIS_DisplayMode)ic->DisplayMode();
385 dispMode = (mode == AIS_WireFrame ? 0 : 1 );
390 //=====================================================================================
391 // function : DisplayGUI::InvertDisplayMode()
392 // purpose : Invert display mode ( shadin <-> wireframe ) for the viewer
393 // (current viewer if <viewWindow> = 0 )
394 //=====================================================================================
395 void DisplayGUI::InvertDisplayMode( SUIT_ViewWindow* viewWindow )
397 SetDisplayMode( 1 - GetDisplayMode( viewWindow ) );
400 //=====================================================================================
401 // function : DisplayGUI::ChangeDisplayMode()
402 // purpose : Set display mode for selected objects in the viewer given
403 // (current viewer if <viewWindow> = 0 )
404 //=====================================================================================
405 void DisplayGUI::ChangeDisplayMode( const int mode, SUIT_ViewWindow* viewWindow )
408 viewWindow = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
410 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
413 SalomeApp_SelectionMgr* aSelMgr = app->selectionMgr();
414 if ( !aSelMgr ) return;
416 SUIT_OverrideCursor();
420 if ( viewWindow->getViewManager()->getType() == VTKViewer_Viewer::Type() ) {
421 SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>( viewWindow );
422 SVTK_RenderWindowInteractor* rwi = vw->getRWInteractor();
424 aSelMgr->selectedObjects( aList );
425 SALOME_ListIteratorOfListIO It( aList );
427 for( ;It.More(); It.Next() ) {
428 SVTK_Viewer* stvkViewer = (SVTK_Viewer*)(vw->getViewManager()->getViewModel());
429 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( stvkViewer->CreatePrs( It.Value()->getEntry() ) );
430 if ( vtkPrs && !vtkPrs->IsNull() ) {
432 rwi->ChangeRepresentationToWireframe( vtkPrs->GetObjects() );
433 else if ( mode == 1 )
434 rwi->ChangeRepresentationToSurface( vtkPrs->GetObjects() );
439 else if ( viewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() ) {
440 OCCViewer_Viewer* v3d = ((OCCViewer_ViewManager*)(viewWindow->getViewManager()))->getOCCViewer();
441 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
443 aSelMgr->selectedObjects( aList );
444 SALOME_ListIteratorOfListIO It( aList );
446 for( ;It.More(); It.Next() ) {
447 SOCC_Viewer* soccViewer = (SOCC_Viewer*)(viewWindow->getViewManager()->getViewModel());
448 SOCC_Prs* occPrs = dynamic_cast<SOCC_Prs*>( soccViewer->CreatePrs( It.Value()->getEntry() ) );
449 if ( occPrs && !occPrs->IsNull() ) {
450 AIS_ListOfInteractive shapes; occPrs->GetObjects( shapes );
451 AIS_ListIteratorOfListOfInteractive interIter( shapes );
452 for ( ; interIter.More(); interIter.Next() ) {
454 ic->SetDisplayMode( interIter.Value(), AIS_WireFrame, false );
455 else if ( mode == 1 )
456 ic->SetDisplayMode( interIter.Value(), AIS_Shaded, false );
460 ic->UpdateCurrentViewer();
464 //=====================================================================================
466 //=====================================================================================
469 GEOMGUI* GetLibGUI( GeometryGUI* parent )
471 return DisplayGUI::GetDisplayGUI( parent );