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 getGeometryGUI()->EmitSignalDeactivateDialog();
115 myDisplayGUI->DisplayAll();
118 case 213: // MENU VIEW - DISPLAY ONLY
120 getGeometryGUI()->EmitSignalDeactivateDialog();
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 getGeometryGUI()->EmitSignalDeactivateDialog();
137 myDisplayGUI->Display();
140 case 80311: // POPUP VIEWER - WIREFRAME
142 myDisplayGUI->ChangeDisplayMode( 0 );
145 case 80312: // POPUP VIEWER - SHADING
147 myDisplayGUI->ChangeDisplayMode( 1 );
152 SUIT_Session::session()->activeApplication()->putInfo(tr("GEOM_PRP_COMMAND").arg(theCommandID));
159 //=====================================================================================
160 // function : DisplayGUI::DisplayAll()
161 // purpose : Display all GEOM objects
162 //=====================================================================================
163 void DisplayGUI::DisplayAll()
165 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
166 if ( !appStudy ) return;
167 _PTR(Study) aStudy = appStudy->studyDS();
168 if ( !aStudy ) return;
169 _PTR(SComponent) SC ( aStudy->FindComponent( "GEOM" ) );
173 SALOME_ListIO listIO;
174 _PTR(ChildIterator) anIter ( aStudy->NewChildIterator( SC ) );
175 anIter->InitEx( true );
177 SUIT_OverrideCursor();
179 while( anIter->More() ) {
180 _PTR(SObject) valSO ( anIter->Value() );
182 if ( !valSO->ReferencedObject( refSO ) ) {
183 listIO.Append( new SALOME_InteractiveObject( valSO->GetID().c_str(), SC->ComponentDataType().c_str() ,valSO->GetName().c_str() ) );
187 GEOM_Displayer( appStudy ).Display( listIO, true );
190 //=====================================================================================
191 // function : DisplayGUI::EraseAll()
192 // purpose : Erase all GEOM objects
193 //=====================================================================================
194 void DisplayGUI::EraseAll()
196 SUIT_OverrideCursor();
198 SUIT_Application* app = SUIT_Session::session()->activeApplication();
200 SUIT_ViewWindow* vw = app->desktop()->activeWindow();
202 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
203 SUIT_ViewManager* vman = vw->getViewManager();
204 if ( vman->getType() == OCCViewer_Viewer::Type() ||
205 vman->getType() == SVTK_Viewer::Type() ) {
206 GEOM_Displayer( appStudy ).EraseAll();
212 //=====================================================================================
213 // function : DisplayGUI::DisplayOnly()
214 // purpose : Display selected GEOM objects and erase other
215 //=====================================================================================
216 void DisplayGUI::DisplayOnly()
222 //=====================================================================================
223 // function : DisplayGUI::Display()
224 // purpose : Display selected GEOM objects
225 //=====================================================================================
226 void DisplayGUI::Display()
228 SALOME_ListIO listIO;
230 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
233 SalomeApp_Study* anActiveStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
234 if ( !anActiveStudy ) return;
236 //get SalomeApp selection manager
237 SalomeApp_SelectionMgr* aSelMgr = app->selectionMgr();
238 if ( !aSelMgr ) return;
241 aSelMgr->selectedObjects( aList );
242 SALOME_ListIteratorOfListIO It( aList );
244 SUIT_OverrideCursor();
246 for( ;It.More();It.Next() ) {
247 Handle(SALOME_InteractiveObject) anIObject = It.Value();
248 if ( anIObject->hasEntry() ) {
249 _PTR(SObject) SO ( anActiveStudy->studyDS()->FindObjectID( anIObject->getEntry() ) );
250 if ( SO && QString( SO->GetID().c_str() ) == QString( SO->GetFatherComponent()->GetID().c_str() ) ) {
251 _PTR(SComponent) SC ( SO->GetFatherComponent() );
252 // if component is selected
254 _PTR(ChildIterator) anIter ( anActiveStudy->studyDS()->NewChildIterator( SO ) );
255 anIter->InitEx( true );
256 while( anIter->More() ) {
257 _PTR(SObject) valSO ( anIter->Value() );
259 if ( !valSO->ReferencedObject( refSO ) ) {
260 listIO.Append( new SALOME_InteractiveObject( valSO->GetID().c_str(), SC->ComponentDataType().c_str() ,valSO->GetName().c_str() ) );
267 listIO.Append( anIObject );
271 listIO.Append( anIObject );
274 GEOM_Displayer( anActiveStudy ).Display( listIO, true );
278 //=====================================================================================
279 // function : DisplayGUI::Erase()
280 // purpose : Erase selected GEOM objects
281 //=====================================================================================
282 void DisplayGUI::Erase()
284 SALOME_ListIO listIO;
286 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
289 SalomeApp_Study* anActiveStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
290 if ( !anActiveStudy ) return;
292 //get SalomeApp selection manager
293 SalomeApp_SelectionMgr* aSelMgr = app->selectionMgr();
294 if ( !aSelMgr ) return;
297 aSelMgr->selectedObjects( aList );
298 SALOME_ListIteratorOfListIO It( aList );
300 SUIT_OverrideCursor();
302 for( ;It.More();It.Next() ) {
303 Handle(SALOME_InteractiveObject) anIObject = It.Value();
304 if ( anIObject->hasEntry() ) {
305 _PTR(SObject) SO ( anActiveStudy->studyDS()->FindObjectID( anIObject->getEntry() ) );
306 if ( SO && QString( SO->GetID().c_str() ) == QString( SO->GetFatherComponent()->GetID().c_str() ) ) {
307 _PTR(SComponent) SC ( SO->GetFatherComponent() );
308 // if component is selected
310 _PTR(ChildIterator) anIter ( anActiveStudy->studyDS()->NewChildIterator( SO ) );
311 anIter->InitEx( true );
312 while( anIter->More() ) {
313 _PTR(SObject) valSO ( anIter->Value() );
315 if ( !valSO->ReferencedObject( refSO ) ) {
316 listIO.Append( new SALOME_InteractiveObject( valSO->GetID().c_str(), SC->ComponentDataType().c_str() ,valSO->GetName().c_str() ) );
323 listIO.Append( anIObject );
327 listIO.Append( anIObject );
330 GEOM_Displayer(anActiveStudy).Erase( listIO, true );
331 ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr()->clearSelected();
334 //=====================================================================================
335 // function : DisplayGUI::SetDisplayMode()
336 // purpose : Set display mode for the viewer (current viewer if <viewWindow> - 0 )
337 //=====================================================================================
338 void DisplayGUI::SetDisplayMode( const int mode, SUIT_ViewWindow* viewWindow )
340 SUIT_OverrideCursor();
343 viewWindow = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
344 if ( viewWindow->getViewManager()->getType() == SVTK_Viewer::Type() ) {
345 SVTK_ViewWindow* wnd = dynamic_cast<SVTK_ViewWindow*>( viewWindow );
346 SVTK_RenderWindowInteractor* myRenderInter = wnd ? wnd->getRWInteractor() : 0;
348 myRenderInter->SetDisplayMode( mode );
350 else if ( viewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() ) {
351 OCCViewer_Viewer* v3d = ((OCCViewer_ViewManager*)(viewWindow->getViewManager()))->getOCCViewer();
352 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
353 AIS_DisplayMode newmode = (mode == 1 ? AIS_Shaded : AIS_WireFrame);
354 AIS_ListOfInteractive List;
355 ic->DisplayedObjects( List );
356 AIS_ListOfInteractive List1;
357 ic->ObjectsInCollector( List1 );
358 List.Append( List1 );
360 AIS_ListIteratorOfListOfInteractive ite( List );
361 while( ite.More() ) {
362 if( ite.Value()->IsInstance( STANDARD_TYPE(GEOM_AISShape) ) ) {
363 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast( ite.Value() );
364 ic->SetDisplayMode( aSh, Standard_Integer( newmode ),true );
369 ic->SetDisplayMode( newmode, Standard_False );
373 //=====================================================================================
374 // function : DisplayGUI::GetDisplayMode()
375 // purpose : Get display mode of the viewer (current viewer if <viewWindow> - 0 )
376 //=====================================================================================
377 int DisplayGUI::GetDisplayMode( SUIT_ViewWindow* viewWindow )
381 viewWindow = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
382 if ( viewWindow->getViewManager()->getType() == SVTK_Viewer::Type() ) {
383 SVTK_ViewWindow* wnd = dynamic_cast<SVTK_ViewWindow*>( viewWindow );
384 SVTK_RenderWindowInteractor* myRenderInter = wnd ? wnd->getRWInteractor() : 0;
386 dispMode = myRenderInter->GetDisplayMode();
388 else if ( viewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() ) {
389 OCCViewer_Viewer* v3d = ((OCCViewer_ViewManager*)(viewWindow->getViewManager()))->getOCCViewer();
390 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
391 AIS_DisplayMode mode = (AIS_DisplayMode)ic->DisplayMode();
392 dispMode = (mode == AIS_WireFrame ? 0 : 1 );
397 //=====================================================================================
398 // function : DisplayGUI::InvertDisplayMode()
399 // purpose : Invert display mode ( shadin <-> wireframe ) for the viewer
400 // (current viewer if <viewWindow> = 0 )
401 //=====================================================================================
402 void DisplayGUI::InvertDisplayMode( SUIT_ViewWindow* viewWindow )
404 SetDisplayMode( 1 - GetDisplayMode( viewWindow ) );
407 //=====================================================================================
408 // function : DisplayGUI::ChangeDisplayMode()
409 // purpose : Set display mode for selected objects in the viewer given
410 // (current viewer if <viewWindow> = 0 )
411 //=====================================================================================
412 void DisplayGUI::ChangeDisplayMode( const int mode, SUIT_ViewWindow* viewWindow )
415 viewWindow = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
417 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
420 SalomeApp_SelectionMgr* aSelMgr = app->selectionMgr();
421 if ( !aSelMgr ) return;
423 SUIT_OverrideCursor();
427 if ( viewWindow->getViewManager()->getType() == SVTK_Viewer::Type() ) {
428 SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>( viewWindow );
429 SVTK_RenderWindowInteractor* rwi = vw ? vw->getRWInteractor() : 0;
434 aSelMgr->selectedObjects( aList );
435 SALOME_ListIteratorOfListIO It( aList );
437 for( ;It.More(); It.Next() ) {
438 SVTK_Viewer* stvkViewer = dynamic_cast<SVTK_Viewer*>(vw->getViewManager()->getViewModel());
439 SVTK_Prs* vtkPrs = stvkViewer ? dynamic_cast<SVTK_Prs*>( stvkViewer->CreatePrs( It.Value()->getEntry() ) ) : 0;
440 if ( vtkPrs && !vtkPrs->IsNull() ) {
442 rwi->ChangeRepresentationToWireframe( vtkPrs->GetObjects() );
443 else if ( mode == 1 )
444 rwi->ChangeRepresentationToSurface( vtkPrs->GetObjects() );
449 else if ( viewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() ) {
450 OCCViewer_Viewer* v3d = ((OCCViewer_ViewManager*)(viewWindow->getViewManager()))->getOCCViewer();
451 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
453 aSelMgr->selectedObjects( aList );
454 SALOME_ListIteratorOfListIO It( aList );
456 for( ;It.More(); It.Next() ) {
457 SOCC_Viewer* soccViewer = (SOCC_Viewer*)(viewWindow->getViewManager()->getViewModel());
458 SOCC_Prs* occPrs = dynamic_cast<SOCC_Prs*>( soccViewer->CreatePrs( It.Value()->getEntry() ) );
459 if ( occPrs && !occPrs->IsNull() ) {
460 AIS_ListOfInteractive shapes; occPrs->GetObjects( shapes );
461 AIS_ListIteratorOfListOfInteractive interIter( shapes );
462 for ( ; interIter.More(); interIter.Next() ) {
464 ic->SetDisplayMode( interIter.Value(), AIS_WireFrame, false );
465 else if ( mode == 1 )
466 ic->SetDisplayMode( interIter.Value(), AIS_Shaded, false );
470 ic->UpdateCurrentViewer();
474 //=====================================================================================
476 //=====================================================================================
480 __declspec( dllexport )
482 GEOMGUI* GetLibGUI( GeometryGUI* parent )
484 return DisplayGUI::GetDisplayGUI( parent );