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_ViewModel.h>
47 #include <SOCC_ViewModel.h>
51 #include <SalomeApp_Application.h>
52 #include <SalomeApp_SelectionMgr.h>
53 #include <SalomeApp_Study.h>
55 #include <AIS_ListIteratorOfListOfInteractive.hxx>
60 DisplayGUI* DisplayGUI::myGUIObject = 0;
62 //=======================================================================
63 // function : DisplayGUI::GetDisplayGUI()
64 // purpose : Get the only DisplayGUI object [ static ]
65 //=======================================================================
66 DisplayGUI* DisplayGUI::GetDisplayGUI( GeometryGUI* parent )
68 if ( myGUIObject == 0 ) {
69 // init DisplayGUI only once
70 myGUIObject = new DisplayGUI( parent );
75 //=======================================================================
76 // function : DisplayGUI::DisplayGUI()
77 // purpose : Constructor
78 //=======================================================================
79 DisplayGUI::DisplayGUI( GeometryGUI* parent ) : GEOMGUI( parent )
84 //=======================================================================
85 // function : DisplayGUI::~DisplayGUI()
86 // purpose : Destructor
87 //=======================================================================
88 DisplayGUI::~DisplayGUI()
93 //=======================================================================
94 // function : DisplayGUI::OnGUIEvent()
95 // purpose : Dispatch menu command
96 //=======================================================================
97 bool DisplayGUI::OnGUIEvent(int theCommandID, SUIT_Desktop* parent)
99 DisplayGUI* myDisplayGUI = GetDisplayGUI( getGeometryGUI() );
101 switch (theCommandID) {
102 case 211: // MENU VIEW - WIREFRAME/SHADING
104 myDisplayGUI->InvertDisplayMode();
105 int newMode = myDisplayGUI->GetDisplayMode();
106 SUIT_Session::session()->activeApplication()->desktop()->menuBar()->
107 changeItem( 211, newMode == 1 ? tr( "GEOM_MEN_WIREFRAME" ) : tr("GEOM_MEN_SHADING") );
110 case 212: // MENU VIEW - DISPLAY ALL
112 myDisplayGUI->DisplayAll();
115 case 213: // MENU VIEW - DISPLAY ONLY
117 myDisplayGUI->DisplayOnly();
120 case 214: // MENU VIEW - ERASE ALL
122 myDisplayGUI->EraseAll();
125 case 215: // MENU VIEW - ERASE
127 myDisplayGUI->Erase();
130 case 216: // MENU VIEW - DISPLAY
132 myDisplayGUI->Display();
135 case 80311: // POPUP VIEWER - WIREFRAME
137 myDisplayGUI->ChangeDisplayMode( 0 );
140 case 80312: // POPUP VIEWER - SHADING
142 myDisplayGUI->ChangeDisplayMode( 1 );
147 SUIT_Session::session()->activeApplication()->putInfo(tr("GEOM_PRP_COMMAND").arg(theCommandID));
154 //=====================================================================================
155 // function : DisplayGUI::DisplayAll()
156 // purpose : Display all GEOM objects
157 //=====================================================================================
158 void DisplayGUI::DisplayAll()
160 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
161 if ( !appStudy ) return;
162 _PTR(Study) aStudy = appStudy->studyDS();
163 if ( !aStudy ) return;
164 _PTR(SComponent) SC ( aStudy->FindComponent( "GEOM" ) );
168 SALOME_ListIO listIO;
169 _PTR(ChildIterator) anIter ( aStudy->NewChildIterator( SC ) );
170 anIter->InitEx( true );
172 SUIT_OverrideCursor();
174 while( anIter->More() ) {
175 _PTR(SObject) valSO ( anIter->Value() );
177 if ( !valSO->ReferencedObject( refSO ) ) {
178 listIO.Append( new SALOME_InteractiveObject( valSO->GetID().c_str(), SC->ComponentDataType().c_str() ,valSO->GetName().c_str() ) );
182 GEOM_Displayer( appStudy ).Display( listIO, true );
185 //=====================================================================================
186 // function : DisplayGUI::EraseAll()
187 // purpose : Erase all GEOM objects
188 //=====================================================================================
189 void DisplayGUI::EraseAll()
191 SUIT_OverrideCursor();
193 SUIT_Application* app = SUIT_Session::session()->activeApplication();
195 SUIT_ViewWindow* vw = app->desktop()->activeWindow();
197 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
198 SUIT_ViewManager* vman = vw->getViewManager();
199 if ( vman->getType() == OCCViewer_Viewer::Type() ||
200 vman->getType() == VTKViewer_Viewer::Type() ) {
201 GEOM_Displayer( appStudy ).EraseAll();
207 //=====================================================================================
208 // function : DisplayGUI::DisplayOnly()
209 // purpose : Display selected GEOM objects and erase other
210 //=====================================================================================
211 void DisplayGUI::DisplayOnly()
217 //=====================================================================================
218 // function : DisplayGUI::Display()
219 // purpose : Display selected GEOM objects
220 //=====================================================================================
221 void DisplayGUI::Display()
223 SALOME_ListIO listIO;
225 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
228 SalomeApp_Study* anActiveStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
229 if ( !anActiveStudy ) return;
231 //get SalomeApp selection manager
232 SalomeApp_SelectionMgr* aSelMgr = app->selectionMgr();
233 if ( !aSelMgr ) return;
236 aSelMgr->selectedObjects( aList );
237 SALOME_ListIteratorOfListIO It( aList );
239 SUIT_OverrideCursor();
241 for( ;It.More();It.Next() ) {
242 Handle(SALOME_InteractiveObject) anIObject = It.Value();
243 if ( anIObject->hasEntry() ) {
244 _PTR(SObject) SO ( anActiveStudy->studyDS()->FindObjectID( anIObject->getEntry() ) );
245 if ( SO && QString( SO->GetID().c_str() ) == QString( SO->GetFatherComponent()->GetID().c_str() ) ) {
246 _PTR(SComponent) SC ( SO->GetFatherComponent() );
247 // if component is selected
249 _PTR(ChildIterator) anIter ( anActiveStudy->studyDS()->NewChildIterator( SO ) );
250 anIter->InitEx( true );
251 while( anIter->More() ) {
252 _PTR(SObject) valSO ( anIter->Value() );
254 if ( !valSO->ReferencedObject( refSO ) ) {
255 listIO.Append( new SALOME_InteractiveObject( valSO->GetID().c_str(), SC->ComponentDataType().c_str() ,valSO->GetName().c_str() ) );
262 listIO.Append( anIObject );
266 listIO.Append( anIObject );
269 GEOM_Displayer( anActiveStudy ).Display( listIO, true );
273 //=====================================================================================
274 // function : DisplayGUI::Erase()
275 // purpose : Erase selected GEOM objects
276 //=====================================================================================
277 void DisplayGUI::Erase()
279 SALOME_ListIO listIO;
281 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
284 SalomeApp_Study* anActiveStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
285 if ( !anActiveStudy ) return;
287 //get SalomeApp selection manager
288 SalomeApp_SelectionMgr* aSelMgr = app->selectionMgr();
289 if ( !aSelMgr ) return;
292 aSelMgr->selectedObjects( aList );
293 SALOME_ListIteratorOfListIO It( aList );
295 SUIT_OverrideCursor();
297 for( ;It.More();It.Next() ) {
298 Handle(SALOME_InteractiveObject) anIObject = It.Value();
299 if ( anIObject->hasEntry() ) {
300 _PTR(SObject) SO ( anActiveStudy->studyDS()->FindObjectID( anIObject->getEntry() ) );
301 if ( SO && QString( SO->GetID().c_str() ) == QString( SO->GetFatherComponent()->GetID().c_str() ) ) {
302 _PTR(SComponent) SC ( SO->GetFatherComponent() );
303 // if component is selected
305 _PTR(ChildIterator) anIter ( anActiveStudy->studyDS()->NewChildIterator( SO ) );
306 anIter->InitEx( true );
307 while( anIter->More() ) {
308 _PTR(SObject) valSO ( anIter->Value() );
310 if ( !valSO->ReferencedObject( refSO ) ) {
311 listIO.Append( new SALOME_InteractiveObject( valSO->GetID().c_str(), SC->ComponentDataType().c_str() ,valSO->GetName().c_str() ) );
318 listIO.Append( anIObject );
322 listIO.Append( anIObject );
325 GEOM_Displayer(anActiveStudy).Erase( listIO, true );
326 ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr()->clearSelected();
329 //=====================================================================================
330 // function : DisplayGUI::SetDisplayMode()
331 // purpose : Set display mode for the viewer (current viewer if <viewWindow> - 0 )
332 //=====================================================================================
333 void DisplayGUI::SetDisplayMode( const int mode, SUIT_ViewWindow* viewWindow )
335 SUIT_OverrideCursor();
338 viewWindow = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
339 if ( viewWindow->getViewManager()->getType() == VTKViewer_Viewer::Type() ) {
340 VTKViewer_RenderWindowInteractor* myRenderInter= ((VTKViewer_ViewWindow*)viewWindow)->getRWInteractor();
341 myRenderInter->SetDisplayMode( mode );
343 else if ( viewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() ) {
344 OCCViewer_Viewer* v3d = ((OCCViewer_ViewManager*)(viewWindow->getViewManager()))->getOCCViewer();
345 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
346 AIS_DisplayMode newmode = (mode == 1 ? AIS_Shaded : AIS_WireFrame);
347 AIS_ListOfInteractive List;
348 ic->DisplayedObjects( List );
349 AIS_ListOfInteractive List1;
350 ic->ObjectsInCollector( List1 );
351 List.Append( List1 );
353 AIS_ListIteratorOfListOfInteractive ite( List );
354 while( ite.More() ) {
355 if( ite.Value()->IsInstance( STANDARD_TYPE(GEOM_AISShape) ) ) {
356 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast( ite.Value() );
357 ic->SetDisplayMode( aSh, Standard_Integer( newmode ),true );
362 ic->SetDisplayMode( newmode, Standard_False );
366 //=====================================================================================
367 // function : DisplayGUI::GetDisplayMode()
368 // purpose : Get display mode of the viewer (current viewer if <viewWindow> - 0 )
369 //=====================================================================================
370 int DisplayGUI::GetDisplayMode( SUIT_ViewWindow* viewWindow )
374 viewWindow = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
375 if ( viewWindow->getViewManager()->getType() == VTKViewer_Viewer::Type() ) {
376 VTKViewer_RenderWindowInteractor* myRenderInter= ((VTKViewer_ViewWindow*)viewWindow)->getRWInteractor();
377 dispMode = myRenderInter->GetDisplayMode();
379 else if ( viewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() ) {
380 OCCViewer_Viewer* v3d = ((OCCViewer_ViewManager*)(viewWindow->getViewManager()))->getOCCViewer();
381 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
382 AIS_DisplayMode mode = (AIS_DisplayMode)ic->DisplayMode();
383 dispMode = (mode == AIS_WireFrame ? 0 : 1 );
388 //=====================================================================================
389 // function : DisplayGUI::InvertDisplayMode()
390 // purpose : Invert display mode ( shadin <-> wireframe ) for the viewer
391 // (current viewer if <viewWindow> = 0 )
392 //=====================================================================================
393 void DisplayGUI::InvertDisplayMode( SUIT_ViewWindow* viewWindow )
395 SetDisplayMode( 1 - GetDisplayMode( viewWindow ) );
398 //=====================================================================================
399 // function : DisplayGUI::ChangeDisplayMode()
400 // purpose : Set display mode for selected objects in the viewer given
401 // (current viewer if <viewWindow> = 0 )
402 //=====================================================================================
403 void DisplayGUI::ChangeDisplayMode( const int mode, SUIT_ViewWindow* viewWindow )
406 viewWindow = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
408 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
411 SalomeApp_SelectionMgr* aSelMgr = app->selectionMgr();
412 if ( !aSelMgr ) return;
414 SUIT_OverrideCursor();
418 if ( viewWindow->getViewManager()->getType() == VTKViewer_Viewer::Type() ) {
419 VTKViewer_RenderWindowInteractor* myRenderInter = ((VTKViewer_ViewWindow*)viewWindow)->getRWInteractor();
421 aSelMgr->selectedObjects( aList );
422 SALOME_ListIteratorOfListIO It( aList );
424 for( ;It.More(); It.Next() ) {
425 SVTK_Viewer* stvkViewer = (SVTK_Viewer*)(viewWindow->getViewManager()->getViewModel());
426 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( stvkViewer->CreatePrs( It.Value()->getEntry() ) );
427 if ( vtkPrs && !vtkPrs->IsNull() ) {
429 myRenderInter->ChangeRepresentationToWireframe( vtkPrs->GetObjects() );
430 else if ( mode == 1 )
431 myRenderInter->ChangeRepresentationToSurface( vtkPrs->GetObjects() );
434 myRenderInter->Render();
436 else if ( viewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() ) {
437 OCCViewer_Viewer* v3d = ((OCCViewer_ViewManager*)(viewWindow->getViewManager()))->getOCCViewer();
438 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
440 aSelMgr->selectedObjects( aList );
441 SALOME_ListIteratorOfListIO It( aList );
443 for( ;It.More(); It.Next() ) {
444 SOCC_Viewer* soccViewer = (SOCC_Viewer*)(viewWindow->getViewManager()->getViewModel());
445 SOCC_Prs* occPrs = dynamic_cast<SOCC_Prs*>( soccViewer->CreatePrs( It.Value()->getEntry() ) );
446 if ( occPrs && !occPrs->IsNull() ) {
447 AIS_ListOfInteractive shapes; occPrs->GetObjects( shapes );
448 AIS_ListIteratorOfListOfInteractive interIter( shapes );
449 for ( ; interIter.More(); interIter.Next() ) {
451 ic->SetDisplayMode( interIter.Value(), AIS_WireFrame, false );
452 else if ( mode == 1 )
453 ic->SetDisplayMode( interIter.Value(), AIS_Shaded, false );
457 ic->UpdateCurrentViewer();
461 //=====================================================================================
463 //=====================================================================================
466 GEOMGUI* GetLibGUI( GeometryGUI* parent )
468 return DisplayGUI::GetDisplayGUI( parent );