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 getGeometryGUI()->action( 211 )->setMenuText( newMode == 1 ? tr( "GEOM_MEN_WIREFRAME" ) : tr("GEOM_MEN_SHADING") );
109 getGeometryGUI()->menuMgr()->update();
110 // SUIT_Session::session()->activeApplication()->desktop()->menuBar()->
111 // changeItem( 211, newMode == 1 ? tr( "GEOM_MEN_WIREFRAME" ) : tr("GEOM_MEN_SHADING") );
114 case 212: // MENU VIEW - DISPLAY ALL
116 myDisplayGUI->DisplayAll();
119 case 213: // MENU VIEW - DISPLAY ONLY
121 myDisplayGUI->DisplayOnly();
124 case 214: // MENU VIEW - ERASE ALL
126 myDisplayGUI->EraseAll();
129 case 215: // MENU VIEW - ERASE
131 myDisplayGUI->Erase();
134 case 216: // MENU VIEW - DISPLAY
136 myDisplayGUI->Display();
139 case 80311: // POPUP VIEWER - WIREFRAME
141 myDisplayGUI->ChangeDisplayMode( 0 );
144 case 80312: // POPUP VIEWER - SHADING
146 myDisplayGUI->ChangeDisplayMode( 1 );
151 SUIT_Session::session()->activeApplication()->putInfo(tr("GEOM_PRP_COMMAND").arg(theCommandID));
158 //=====================================================================================
159 // function : DisplayGUI::DisplayAll()
160 // purpose : Display all GEOM objects
161 //=====================================================================================
162 void DisplayGUI::DisplayAll()
164 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->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(), SC->ComponentDataType().c_str() ,valSO->GetName().c_str() ) );
186 GEOM_Displayer( appStudy ).Display( listIO, true );
189 //=====================================================================================
190 // function : DisplayGUI::EraseAll()
191 // purpose : Erase all GEOM objects
192 //=====================================================================================
193 void DisplayGUI::EraseAll()
195 SUIT_OverrideCursor();
197 SUIT_Application* app = SUIT_Session::session()->activeApplication();
199 SUIT_ViewWindow* vw = app->desktop()->activeWindow();
201 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
202 SUIT_ViewManager* vman = vw->getViewManager();
203 if ( vman->getType() == OCCViewer_Viewer::Type() ||
204 vman->getType() == VTKViewer_Viewer::Type() ) {
205 GEOM_Displayer( appStudy ).EraseAll();
211 //=====================================================================================
212 // function : DisplayGUI::DisplayOnly()
213 // purpose : Display selected GEOM objects and erase other
214 //=====================================================================================
215 void DisplayGUI::DisplayOnly()
221 //=====================================================================================
222 // function : DisplayGUI::Display()
223 // purpose : Display selected GEOM objects
224 //=====================================================================================
225 void DisplayGUI::Display()
227 SALOME_ListIO listIO;
229 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
232 SalomeApp_Study* anActiveStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
233 if ( !anActiveStudy ) return;
235 //get SalomeApp selection manager
236 SalomeApp_SelectionMgr* aSelMgr = app->selectionMgr();
237 if ( !aSelMgr ) return;
240 aSelMgr->selectedObjects( aList );
241 SALOME_ListIteratorOfListIO It( aList );
243 SUIT_OverrideCursor();
245 for( ;It.More();It.Next() ) {
246 Handle(SALOME_InteractiveObject) anIObject = It.Value();
247 if ( anIObject->hasEntry() ) {
248 _PTR(SObject) SO ( anActiveStudy->studyDS()->FindObjectID( anIObject->getEntry() ) );
249 if ( SO && QString( SO->GetID().c_str() ) == QString( SO->GetFatherComponent()->GetID().c_str() ) ) {
250 _PTR(SComponent) SC ( SO->GetFatherComponent() );
251 // if component is selected
253 _PTR(ChildIterator) anIter ( anActiveStudy->studyDS()->NewChildIterator( SO ) );
254 anIter->InitEx( true );
255 while( anIter->More() ) {
256 _PTR(SObject) valSO ( anIter->Value() );
258 if ( !valSO->ReferencedObject( refSO ) ) {
259 listIO.Append( new SALOME_InteractiveObject( valSO->GetID().c_str(), SC->ComponentDataType().c_str() ,valSO->GetName().c_str() ) );
266 listIO.Append( anIObject );
270 listIO.Append( anIObject );
273 GEOM_Displayer( anActiveStudy ).Display( listIO, true );
277 //=====================================================================================
278 // function : DisplayGUI::Erase()
279 // purpose : Erase selected GEOM objects
280 //=====================================================================================
281 void DisplayGUI::Erase()
283 SALOME_ListIO listIO;
285 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
288 SalomeApp_Study* anActiveStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
289 if ( !anActiveStudy ) return;
291 //get SalomeApp selection manager
292 SalomeApp_SelectionMgr* aSelMgr = app->selectionMgr();
293 if ( !aSelMgr ) return;
296 aSelMgr->selectedObjects( aList );
297 SALOME_ListIteratorOfListIO It( aList );
299 SUIT_OverrideCursor();
301 for( ;It.More();It.Next() ) {
302 Handle(SALOME_InteractiveObject) anIObject = It.Value();
303 if ( anIObject->hasEntry() ) {
304 _PTR(SObject) SO ( anActiveStudy->studyDS()->FindObjectID( anIObject->getEntry() ) );
305 if ( SO && QString( SO->GetID().c_str() ) == QString( SO->GetFatherComponent()->GetID().c_str() ) ) {
306 _PTR(SComponent) SC ( SO->GetFatherComponent() );
307 // if component is selected
309 _PTR(ChildIterator) anIter ( anActiveStudy->studyDS()->NewChildIterator( SO ) );
310 anIter->InitEx( true );
311 while( anIter->More() ) {
312 _PTR(SObject) valSO ( anIter->Value() );
314 if ( !valSO->ReferencedObject( refSO ) ) {
315 listIO.Append( new SALOME_InteractiveObject( valSO->GetID().c_str(), SC->ComponentDataType().c_str() ,valSO->GetName().c_str() ) );
322 listIO.Append( anIObject );
326 listIO.Append( anIObject );
329 GEOM_Displayer(anActiveStudy).Erase( listIO, true );
330 ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr()->clearSelected();
333 //=====================================================================================
334 // function : DisplayGUI::SetDisplayMode()
335 // purpose : Set display mode for the viewer (current viewer if <viewWindow> - 0 )
336 //=====================================================================================
337 void DisplayGUI::SetDisplayMode( const int mode, SUIT_ViewWindow* viewWindow )
339 SUIT_OverrideCursor();
342 viewWindow = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
343 if ( viewWindow->getViewManager()->getType() == VTKViewer_Viewer::Type() ) {
344 VTKViewer_RenderWindowInteractor* myRenderInter= ((VTKViewer_ViewWindow*)viewWindow)->getRWInteractor();
345 myRenderInter->SetDisplayMode( mode );
347 else if ( viewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() ) {
348 OCCViewer_Viewer* v3d = ((OCCViewer_ViewManager*)(viewWindow->getViewManager()))->getOCCViewer();
349 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
350 AIS_DisplayMode newmode = (mode == 1 ? AIS_Shaded : AIS_WireFrame);
351 AIS_ListOfInteractive List;
352 ic->DisplayedObjects( List );
353 AIS_ListOfInteractive List1;
354 ic->ObjectsInCollector( List1 );
355 List.Append( List1 );
357 AIS_ListIteratorOfListOfInteractive ite( List );
358 while( ite.More() ) {
359 if( ite.Value()->IsInstance( STANDARD_TYPE(GEOM_AISShape) ) ) {
360 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast( ite.Value() );
361 ic->SetDisplayMode( aSh, Standard_Integer( newmode ),true );
366 ic->SetDisplayMode( newmode, Standard_False );
370 //=====================================================================================
371 // function : DisplayGUI::GetDisplayMode()
372 // purpose : Get display mode of the viewer (current viewer if <viewWindow> - 0 )
373 //=====================================================================================
374 int DisplayGUI::GetDisplayMode( SUIT_ViewWindow* viewWindow )
378 viewWindow = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
379 if ( viewWindow->getViewManager()->getType() == VTKViewer_Viewer::Type() ) {
380 VTKViewer_RenderWindowInteractor* myRenderInter= ((VTKViewer_ViewWindow*)viewWindow)->getRWInteractor();
381 dispMode = myRenderInter->GetDisplayMode();
383 else if ( viewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() ) {
384 OCCViewer_Viewer* v3d = ((OCCViewer_ViewManager*)(viewWindow->getViewManager()))->getOCCViewer();
385 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
386 AIS_DisplayMode mode = (AIS_DisplayMode)ic->DisplayMode();
387 dispMode = (mode == AIS_WireFrame ? 0 : 1 );
392 //=====================================================================================
393 // function : DisplayGUI::InvertDisplayMode()
394 // purpose : Invert display mode ( shadin <-> wireframe ) for the viewer
395 // (current viewer if <viewWindow> = 0 )
396 //=====================================================================================
397 void DisplayGUI::InvertDisplayMode( SUIT_ViewWindow* viewWindow )
399 SetDisplayMode( 1 - GetDisplayMode( viewWindow ) );
402 //=====================================================================================
403 // function : DisplayGUI::ChangeDisplayMode()
404 // purpose : Set display mode for selected objects in the viewer given
405 // (current viewer if <viewWindow> = 0 )
406 //=====================================================================================
407 void DisplayGUI::ChangeDisplayMode( const int mode, SUIT_ViewWindow* viewWindow )
410 viewWindow = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
412 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
415 SalomeApp_SelectionMgr* aSelMgr = app->selectionMgr();
416 if ( !aSelMgr ) return;
418 SUIT_OverrideCursor();
422 if ( viewWindow->getViewManager()->getType() == VTKViewer_Viewer::Type() ) {
423 SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>( viewWindow );
424 SVTK_RenderWindowInteractor* rwi = vw->getRWInteractor();
426 aSelMgr->selectedObjects( aList );
427 SALOME_ListIteratorOfListIO It( aList );
429 for( ;It.More(); It.Next() ) {
430 SVTK_Viewer* stvkViewer = (SVTK_Viewer*)(vw->getViewManager()->getViewModel());
431 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( stvkViewer->CreatePrs( It.Value()->getEntry() ) );
432 if ( vtkPrs && !vtkPrs->IsNull() ) {
434 rwi->ChangeRepresentationToWireframe( vtkPrs->GetObjects() );
435 else if ( mode == 1 )
436 rwi->ChangeRepresentationToSurface( vtkPrs->GetObjects() );
441 else if ( viewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() ) {
442 OCCViewer_Viewer* v3d = ((OCCViewer_ViewManager*)(viewWindow->getViewManager()))->getOCCViewer();
443 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
445 aSelMgr->selectedObjects( aList );
446 SALOME_ListIteratorOfListIO It( aList );
448 for( ;It.More(); It.Next() ) {
449 SOCC_Viewer* soccViewer = (SOCC_Viewer*)(viewWindow->getViewManager()->getViewModel());
450 SOCC_Prs* occPrs = dynamic_cast<SOCC_Prs*>( soccViewer->CreatePrs( It.Value()->getEntry() ) );
451 if ( occPrs && !occPrs->IsNull() ) {
452 AIS_ListOfInteractive shapes; occPrs->GetObjects( shapes );
453 AIS_ListIteratorOfListOfInteractive interIter( shapes );
454 for ( ; interIter.More(); interIter.Next() ) {
456 ic->SetDisplayMode( interIter.Value(), AIS_WireFrame, false );
457 else if ( mode == 1 )
458 ic->SetDisplayMode( interIter.Value(), AIS_Shaded, false );
462 ic->UpdateCurrentViewer();
466 //=====================================================================================
468 //=====================================================================================
472 __declspec( dllexport )
474 GEOMGUI* GetLibGUI( GeometryGUI* parent )
476 return DisplayGUI::GetDisplayGUI( parent );