1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // GEOM GEOMGUI : GUI for Geometry component
23 // File : DisplayGUI.cxx
24 // Author : Vadim SANDLER
28 #include "DisplayGUI.h"
29 #include "GeometryGUI.h"
30 #include "GEOM_Displayer.h"
32 #include <SUIT_Desktop.h>
33 #include <SUIT_Session.h>
34 #include <SUIT_ViewWindow.h>
35 #include <SUIT_OverrideCursor.h>
37 #include <OCCViewer_ViewManager.h>
38 #include <OCCViewer_ViewModel.h>
39 #include <OCCViewer_ViewWindow.h>
41 #include <SALOME_ListIteratorOfListIO.hxx>
43 #include <SVTK_ViewWindow.h>
44 #include <SVTK_View.h>
45 #include <SVTK_ViewModel.h>
46 #include <SOCC_ViewModel.h>
50 #include <QtxActionMenuMgr.h>
52 #include <SalomeApp_Application.h>
53 #include <LightApp_SelectionMgr.h>
54 #include <SalomeApp_Study.h>
56 #include <AIS_ListIteratorOfListOfInteractive.hxx>
61 //=======================================================================
62 // function : DisplayGUI::DisplayGUI()
63 // purpose : Constructor
64 //=======================================================================
65 DisplayGUI::DisplayGUI( GeometryGUI* parent ) : GEOMGUI( parent )
69 //=======================================================================
70 // function : DisplayGUI::~DisplayGUI()
71 // purpose : Destructor
72 //=======================================================================
73 DisplayGUI::~DisplayGUI()
78 //=======================================================================
79 // function : DisplayGUI::OnGUIEvent()
80 // purpose : Dispatch menu command
81 //=======================================================================
82 bool DisplayGUI::OnGUIEvent(int theCommandID, SUIT_Desktop* parent)
84 SalomeApp_Application* app = getGeometryGUI()->getApp();
85 if (!app) return false;
87 LightApp_SelectionMgr *Sel = app->selectionMgr();
88 SALOME_ListIO selected;
89 Sel->selectedObjects( selected );
91 switch (theCommandID) {
92 case 211: // MENU VIEW - WIREFRAME/SHADING
95 int newMode = GetDisplayMode();
96 getGeometryGUI()->action( 211 )->setMenuText
97 ( newMode == 1 ? tr( "GEOM_MEN_WIREFRAME" ) : tr("GEOM_MEN_SHADING") );
98 getGeometryGUI()->menuMgr()->update();
101 case 212: // MENU VIEW - DISPLAY ALL
103 getGeometryGUI()->EmitSignalDeactivateDialog();
107 case 213: // MENU VIEW - DISPLAY ONLY
109 getGeometryGUI()->EmitSignalDeactivateDialog();
113 case 214: // MENU VIEW - ERASE ALL
118 case 215: // MENU VIEW - ERASE
123 case 216: // MENU VIEW - DISPLAY
125 getGeometryGUI()->EmitSignalDeactivateDialog();
129 case 80311: // POPUP VIEWER - WIREFRAME
131 ChangeDisplayMode( 0 );
134 case 80312: // POPUP VIEWER - SHADING
136 ChangeDisplayMode( 1 );
141 app->putInfo(tr("GEOM_PRP_COMMAND").arg(theCommandID));
145 Sel->setSelectedObjects( selected );
149 //=====================================================================================
150 // function : DisplayGUI::DisplayAll()
151 // purpose : Display all GEOM objects
152 //=====================================================================================
153 void DisplayGUI::DisplayAll()
155 SalomeApp_Application* app = getGeometryGUI()->getApp();
158 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
159 if ( !appStudy ) return;
160 _PTR(Study) aStudy = appStudy->studyDS();
161 if ( !aStudy ) return;
162 _PTR(SComponent) SC ( aStudy->FindComponent( "GEOM" ) );
166 SALOME_ListIO listIO;
167 _PTR(ChildIterator) anIter ( aStudy->NewChildIterator( SC ) );
168 anIter->InitEx( true );
170 SUIT_OverrideCursor();
172 while( anIter->More() ) {
173 _PTR(SObject) valSO ( anIter->Value() );
175 if ( !valSO->ReferencedObject( refSO ) ) {
176 listIO.Append( new SALOME_InteractiveObject(valSO->GetID().c_str(),
177 SC->ComponentDataType().c_str(),
178 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 = getGeometryGUI()->getApp();
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() == SVTK_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 = getGeometryGUI()->getApp();
228 SalomeApp_Study* anActiveStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
229 if ( !anActiveStudy ) return;
231 //get SalomeApp selection manager
232 LightApp_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(),
256 SC->ComponentDataType().c_str(),
257 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 = getGeometryGUI()->getApp();
286 SalomeApp_Study* anActiveStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
287 if ( !anActiveStudy ) return;
289 //get SalomeApp selection manager
290 LightApp_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(),
314 SC->ComponentDataType().c_str(),
315 valSO->GetName().c_str()) );
322 listIO.Append( anIObject );
326 listIO.Append( anIObject );
330 SUIT_ViewWindow* viewWindow = app->desktop()->activeWindow();
331 bool aIsForced = true;
332 if(viewWindow->getViewManager()->getType() == SVTK_Viewer::Type())
335 GEOM_Displayer(anActiveStudy).Erase( listIO, aIsForced);
336 getGeometryGUI()->getApp()->selectionMgr()->clearSelected();
339 //=====================================================================================
340 // function : DisplayGUI::SetDisplayMode()
341 // purpose : Set display mode for the viewer (current viewer if <viewWindow> - 0 )
342 //=====================================================================================
343 void DisplayGUI::SetDisplayMode( const int mode, SUIT_ViewWindow* viewWindow )
345 SUIT_OverrideCursor();
348 viewWindow = getGeometryGUI()->getApp()->desktop()->activeWindow();
349 if ( viewWindow->getViewManager()->getType() == SVTK_Viewer::Type() ) {
350 SVTK_View* aView = ((SVTK_ViewWindow*)viewWindow)->getView();
351 aView->SetDisplayMode( mode );
353 else if ( viewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() ) {
354 OCCViewer_Viewer* v3d = ((OCCViewer_ViewManager*)(viewWindow->getViewManager()))->getOCCViewer();
355 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
356 AIS_DisplayMode newmode = (mode == 1 ? AIS_Shaded : AIS_WireFrame);
357 AIS_ListOfInteractive List;
358 ic->DisplayedObjects( List );
359 AIS_ListOfInteractive List1;
360 ic->ObjectsInCollector( List1 );
361 List.Append( List1 );
363 AIS_ListIteratorOfListOfInteractive ite( List );
364 while( ite.More() ) {
365 if( ite.Value()->IsInstance( STANDARD_TYPE(GEOM_AISShape) ) ) {
366 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast( ite.Value() );
367 ic->SetDisplayMode( aSh, Standard_Integer( newmode ),true );
372 ic->SetDisplayMode( newmode, Standard_False );
376 //=====================================================================================
377 // function : DisplayGUI::GetDisplayMode()
378 // purpose : Get display mode of the viewer (current viewer if <viewWindow> - 0 )
379 //=====================================================================================
380 int DisplayGUI::GetDisplayMode( SUIT_ViewWindow* viewWindow )
384 viewWindow = getGeometryGUI()->getApp()->desktop()->activeWindow();
385 if ( viewWindow->getViewManager()->getType() == SVTK_Viewer::Type() ) {
386 SVTK_View* aView = ((SVTK_ViewWindow*)viewWindow)->getView();
387 dispMode = aView->GetDisplayMode();
389 else if ( viewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() ) {
390 OCCViewer_Viewer* v3d = ((OCCViewer_ViewManager*)(viewWindow->getViewManager()))->getOCCViewer();
391 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
392 AIS_DisplayMode mode = (AIS_DisplayMode)ic->DisplayMode();
393 dispMode = (mode == AIS_WireFrame ? 0 : 1 );
398 //=====================================================================================
399 // function : DisplayGUI::InvertDisplayMode()
400 // purpose : Invert display mode ( shadin <-> wireframe ) for the viewer
401 // (current viewer if <viewWindow> = 0 )
402 //=====================================================================================
403 void DisplayGUI::InvertDisplayMode( SUIT_ViewWindow* viewWindow )
405 SetDisplayMode( 1 - GetDisplayMode( viewWindow ) );
408 //=====================================================================================
409 // function : DisplayGUI::ChangeDisplayMode()
410 // purpose : Set display mode for selected objects in the viewer given
411 // (current viewer if <viewWindow> = 0 )
412 //=====================================================================================
413 void DisplayGUI::ChangeDisplayMode( const int mode, SUIT_ViewWindow* viewWindow )
415 SalomeApp_Application* app = getGeometryGUI()->getApp();
419 viewWindow = app->desktop()->activeWindow();
421 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
422 if ( !aSelMgr ) return;
424 SUIT_OverrideCursor();
428 if ( viewWindow->getViewManager()->getType() == SVTK_Viewer::Type() ) {
429 SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>( viewWindow );
430 SVTK_View* aView = vw->getView();
432 aSelMgr->selectedObjects( aList );
433 SALOME_ListIteratorOfListIO It( aList );
435 for( ;It.More(); It.Next() ) {
436 SVTK_Viewer* stvkViewer = dynamic_cast<SVTK_Viewer*>(vw->getViewManager()->getViewModel());
438 stvkViewer ? dynamic_cast<SVTK_Prs*>( stvkViewer->CreatePrs( It.Value()->getEntry() ) ) : 0;
439 if ( vtkPrs && !vtkPrs->IsNull() ) {
441 aView->ChangeRepresentationToWireframe( vtkPrs->GetObjects() );
442 else if ( mode == 1 )
443 aView->ChangeRepresentationToSurface( vtkPrs->GetObjects() );
448 else if ( viewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() ) {
449 OCCViewer_Viewer* v3d = ((OCCViewer_ViewManager*)(viewWindow->getViewManager()))->getOCCViewer();
450 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
452 aSelMgr->selectedObjects( aList );
453 SALOME_ListIteratorOfListIO It( aList );
455 for( ;It.More(); It.Next() ) {
456 SOCC_Viewer* soccViewer = (SOCC_Viewer*)(viewWindow->getViewManager()->getViewModel());
457 SOCC_Prs* occPrs = dynamic_cast<SOCC_Prs*>( soccViewer->CreatePrs( It.Value()->getEntry() ) );
458 if ( occPrs && !occPrs->IsNull() ) {
459 AIS_ListOfInteractive shapes; occPrs->GetObjects( shapes );
460 AIS_ListIteratorOfListOfInteractive interIter( shapes );
461 for ( ; interIter.More(); interIter.Next() ) {
463 ic->SetDisplayMode( interIter.Value(), AIS_WireFrame, false );
464 else if ( mode == 1 )
465 ic->SetDisplayMode( interIter.Value(), AIS_Shaded, false );
469 ic->UpdateCurrentViewer();
473 //=====================================================================================
475 //=====================================================================================
478 GEOM_DISPLAYGUI_EXPORT
479 GEOMGUI* GetLibGUI( GeometryGUI* parent )
481 return new DisplayGUI( parent );