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 <OCCViewer_ViewManager.h>
39 #include <OCCViewer_ViewModel.h>
40 #include <OCCViewer_ViewWindow.h>
42 #include <SALOME_ListIteratorOfListIO.hxx>
44 #include <SVTK_ViewWindow.h>
45 #include <SVTK_RenderWindowInteractor.h>
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 getGeometryGUI()->action( 211 )->setMenuText( newMode == 1 ? tr( "GEOM_MEN_WIREFRAME" ) : tr("GEOM_MEN_SHADING") );
107 getGeometryGUI()->menuMgr()->update();
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() == SVTK_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() == SVTK_Viewer::Type() ) {
342 SVTK_ViewWindow* wnd = dynamic_cast<SVTK_ViewWindow*>( viewWindow );
343 SVTK_RenderWindowInteractor* myRenderInter = wnd ? wnd->getRWInteractor() : 0;
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() == SVTK_Viewer::Type() ) {
380 SVTK_ViewWindow* wnd = dynamic_cast<SVTK_ViewWindow*>( viewWindow );
381 SVTK_RenderWindowInteractor* myRenderInter = wnd ? wnd->getRWInteractor() : 0;
383 dispMode = myRenderInter->GetDisplayMode();
385 else if ( viewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() ) {
386 OCCViewer_Viewer* v3d = ((OCCViewer_ViewManager*)(viewWindow->getViewManager()))->getOCCViewer();
387 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
388 AIS_DisplayMode mode = (AIS_DisplayMode)ic->DisplayMode();
389 dispMode = (mode == AIS_WireFrame ? 0 : 1 );
394 //=====================================================================================
395 // function : DisplayGUI::InvertDisplayMode()
396 // purpose : Invert display mode ( shadin <-> wireframe ) for the viewer
397 // (current viewer if <viewWindow> = 0 )
398 //=====================================================================================
399 void DisplayGUI::InvertDisplayMode( SUIT_ViewWindow* viewWindow )
401 SetDisplayMode( 1 - GetDisplayMode( viewWindow ) );
404 //=====================================================================================
405 // function : DisplayGUI::ChangeDisplayMode()
406 // purpose : Set display mode for selected objects in the viewer given
407 // (current viewer if <viewWindow> = 0 )
408 //=====================================================================================
409 void DisplayGUI::ChangeDisplayMode( const int mode, SUIT_ViewWindow* viewWindow )
412 viewWindow = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
414 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
417 SalomeApp_SelectionMgr* aSelMgr = app->selectionMgr();
418 if ( !aSelMgr ) return;
420 SUIT_OverrideCursor();
424 if ( viewWindow->getViewManager()->getType() == SVTK_Viewer::Type() ) {
425 SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>( viewWindow );
426 SVTK_RenderWindowInteractor* rwi = vw ? vw->getRWInteractor() : 0;
431 aSelMgr->selectedObjects( aList );
432 SALOME_ListIteratorOfListIO It( aList );
434 for( ;It.More(); It.Next() ) {
435 SVTK_Viewer* stvkViewer = dynamic_cast<SVTK_Viewer*>(vw->getViewManager()->getViewModel());
436 SVTK_Prs* vtkPrs = stvkViewer ? dynamic_cast<SVTK_Prs*>( stvkViewer->CreatePrs( It.Value()->getEntry() ) ) : 0;
437 if ( vtkPrs && !vtkPrs->IsNull() ) {
439 rwi->ChangeRepresentationToWireframe( vtkPrs->GetObjects() );
440 else if ( mode == 1 )
441 rwi->ChangeRepresentationToSurface( vtkPrs->GetObjects() );
446 else if ( viewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() ) {
447 OCCViewer_Viewer* v3d = ((OCCViewer_ViewManager*)(viewWindow->getViewManager()))->getOCCViewer();
448 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
450 aSelMgr->selectedObjects( aList );
451 SALOME_ListIteratorOfListIO It( aList );
453 for( ;It.More(); It.Next() ) {
454 SOCC_Viewer* soccViewer = (SOCC_Viewer*)(viewWindow->getViewManager()->getViewModel());
455 SOCC_Prs* occPrs = dynamic_cast<SOCC_Prs*>( soccViewer->CreatePrs( It.Value()->getEntry() ) );
456 if ( occPrs && !occPrs->IsNull() ) {
457 AIS_ListOfInteractive shapes; occPrs->GetObjects( shapes );
458 AIS_ListIteratorOfListOfInteractive interIter( shapes );
459 for ( ; interIter.More(); interIter.Next() ) {
461 ic->SetDisplayMode( interIter.Value(), AIS_WireFrame, false );
462 else if ( mode == 1 )
463 ic->SetDisplayMode( interIter.Value(), AIS_Shaded, false );
467 ic->UpdateCurrentViewer();
471 //=====================================================================================
473 //=====================================================================================
477 __declspec( dllexport )
479 GEOMGUI* GetLibGUI( GeometryGUI* parent )
481 return DisplayGUI::GetDisplayGUI( parent );