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.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : DisplayGUI.cxx
23 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
26 #include "DisplayGUI.h"
27 #include <GeometryGUI.h>
28 #include <GEOM_Displayer.h>
29 #include <GEOM_AISShape.hxx>
31 #include <SUIT_Desktop.h>
32 #include <SUIT_ViewWindow.h>
33 #include <SUIT_OverrideCursor.h>
35 #include <OCCViewer_ViewManager.h>
36 #include <OCCViewer_ViewModel.h>
38 #include <SALOME_ListIO.hxx>
39 #include <SALOME_ListIteratorOfListIO.hxx>
41 #include <SVTK_ViewWindow.h>
42 #include <SVTK_View.h>
43 #include <SVTK_ViewModel.h>
44 #include <SOCC_ViewModel.h>
48 #include <QtxActionMenuMgr.h>
50 #include <SalomeApp_Application.h>
51 #include <LightApp_SelectionMgr.h>
52 #include <SalomeApp_Study.h>
54 #include <AIS_ListIteratorOfListOfInteractive.hxx>
58 //=======================================================================
59 // function : DisplayGUI::DisplayGUI()
60 // purpose : Constructor
61 //=======================================================================
62 DisplayGUI::DisplayGUI( GeometryGUI* parent ) : GEOMGUI( parent )
66 //=======================================================================
67 // function : DisplayGUI::~DisplayGUI()
68 // purpose : Destructor
69 //=======================================================================
70 DisplayGUI::~DisplayGUI()
75 //=======================================================================
76 // function : DisplayGUI::OnGUIEvent()
77 // purpose : Dispatch menu command
78 //=======================================================================
79 bool DisplayGUI::OnGUIEvent(int theCommandID, SUIT_Desktop* parent)
81 SalomeApp_Application* app = getGeometryGUI()->getApp();
82 if (!app) return false;
84 LightApp_SelectionMgr *Sel = app->selectionMgr();
85 SALOME_ListIO selected;
86 Sel->selectedObjects( selected );
88 switch (theCommandID) {
89 case 211: // MENU VIEW - WIREFRAME/SHADING
92 int newMode = GetDisplayMode();
93 getGeometryGUI()->action( 211 )->setText
94 ( newMode == 1 ? tr( "GEOM_MEN_WIREFRAME" ) : tr("GEOM_MEN_SHADING") );
95 getGeometryGUI()->menuMgr()->update();
98 case 212: // MENU VIEW - DISPLAY ALL
100 getGeometryGUI()->EmitSignalDeactivateDialog();
104 case 213: // MENU VIEW - DISPLAY ONLY
106 getGeometryGUI()->EmitSignalDeactivateDialog();
110 case 214: // MENU VIEW - ERASE ALL
115 case 215: // MENU VIEW - ERASE
120 case 216: // MENU VIEW - DISPLAY
122 getGeometryGUI()->EmitSignalDeactivateDialog();
126 case 80311: // POPUP VIEWER - WIREFRAME
128 ChangeDisplayMode( 0 );
131 case 80312: // POPUP VIEWER - SHADING
133 ChangeDisplayMode( 1 );
138 app->putInfo(tr("GEOM_PRP_COMMAND").arg(theCommandID));
142 Sel->setSelectedObjects( selected );
146 //=====================================================================================
147 // function : DisplayGUI::DisplayAll()
148 // purpose : Display all GEOM objects
149 //=====================================================================================
150 void DisplayGUI::DisplayAll()
152 SalomeApp_Application* app = getGeometryGUI()->getApp();
155 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
156 if ( !appStudy ) return;
157 _PTR(Study) aStudy = appStudy->studyDS();
158 if ( !aStudy ) return;
159 _PTR(SComponent) SC ( aStudy->FindComponent( "GEOM" ) );
163 SALOME_ListIO listIO;
164 _PTR(ChildIterator) anIter ( aStudy->NewChildIterator( SC ) );
165 anIter->InitEx( true );
167 SUIT_OverrideCursor();
169 while( anIter->More() ) {
170 _PTR(SObject) valSO ( anIter->Value() );
172 if ( !valSO->ReferencedObject( refSO ) ) {
173 listIO.Append( new SALOME_InteractiveObject(valSO->GetID().c_str(),
174 SC->ComponentDataType().c_str(),
175 valSO->GetName().c_str()) );
179 GEOM_Displayer( appStudy ).Display( listIO, true );
182 //=====================================================================================
183 // function : DisplayGUI::EraseAll()
184 // purpose : Erase all GEOM objects
185 //=====================================================================================
186 void DisplayGUI::EraseAll()
188 SUIT_OverrideCursor();
190 SUIT_Application* app = getGeometryGUI()->getApp();
192 SUIT_ViewWindow* vw = app->desktop()->activeWindow();
194 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
195 SUIT_ViewManager* vman = vw->getViewManager();
196 if ( vman->getType() == OCCViewer_Viewer::Type() ||
197 vman->getType() == SVTK_Viewer::Type() ) {
198 GEOM_Displayer( appStudy ).EraseAll();
204 //=====================================================================================
205 // function : DisplayGUI::DisplayOnly()
206 // purpose : Display selected GEOM objects and erase other
207 //=====================================================================================
208 void DisplayGUI::DisplayOnly()
214 //=====================================================================================
215 // function : DisplayGUI::Display()
216 // purpose : Display selected GEOM objects
217 //=====================================================================================
218 void DisplayGUI::Display()
220 SALOME_ListIO listIO;
222 SalomeApp_Application* app = getGeometryGUI()->getApp();
225 SalomeApp_Study* anActiveStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
226 if ( !anActiveStudy ) return;
228 //get SalomeApp selection manager
229 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
230 if ( !aSelMgr ) return;
233 aSelMgr->selectedObjects( aList );
234 SALOME_ListIteratorOfListIO It( aList );
236 SUIT_OverrideCursor();
238 for( ;It.More();It.Next() ) {
239 Handle(SALOME_InteractiveObject) anIObject = It.Value();
240 if ( anIObject->hasEntry() ) {
241 _PTR(SObject) SO ( anActiveStudy->studyDS()->FindObjectID( anIObject->getEntry() ) );
242 if ( SO && QString(SO->GetID().c_str()) == QString(SO->GetFatherComponent()->GetID().c_str()) ) {
243 _PTR(SComponent) SC ( SO->GetFatherComponent() );
244 // if component is selected
246 _PTR(ChildIterator) anIter ( anActiveStudy->studyDS()->NewChildIterator( SO ) );
247 anIter->InitEx( true );
248 while( anIter->More() ) {
249 _PTR(SObject) valSO ( anIter->Value() );
251 if ( !valSO->ReferencedObject( refSO ) ) {
252 listIO.Append( new SALOME_InteractiveObject(valSO->GetID().c_str(),
253 SC->ComponentDataType().c_str(),
254 valSO->GetName().c_str()) );
261 listIO.Append( anIObject );
265 listIO.Append( anIObject );
268 GEOM_Displayer( anActiveStudy ).Display( listIO, true );
272 //=====================================================================================
273 // function : DisplayGUI::Erase()
274 // purpose : Erase selected GEOM objects
275 //=====================================================================================
276 void DisplayGUI::Erase()
278 SALOME_ListIO listIO;
280 SalomeApp_Application* app = getGeometryGUI()->getApp();
283 SalomeApp_Study* anActiveStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
284 if ( !anActiveStudy ) return;
286 //get SalomeApp selection manager
287 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
288 if ( !aSelMgr ) return;
291 aSelMgr->selectedObjects( aList );
292 SALOME_ListIteratorOfListIO It( aList );
294 SUIT_OverrideCursor();
296 for( ; It.More(); It.Next() ) {
297 Handle(SALOME_InteractiveObject) anIObject = It.Value();
298 if ( anIObject->hasEntry() ) {
299 _PTR(SObject) SO ( anActiveStudy->studyDS()->FindObjectID( anIObject->getEntry() ) );
300 if ( SO && QString(SO->GetID().c_str()) == QString(SO->GetFatherComponent()->GetID().c_str()) ) {
301 _PTR(SComponent) SC ( SO->GetFatherComponent() );
302 // if component is selected
304 _PTR(ChildIterator) anIter ( anActiveStudy->studyDS()->NewChildIterator( SO ) );
305 anIter->InitEx( true );
306 while( anIter->More() ) {
307 _PTR(SObject) valSO ( anIter->Value() );
309 if ( !valSO->ReferencedObject( refSO ) ) {
310 listIO.Append( new SALOME_InteractiveObject(valSO->GetID().c_str(),
311 SC->ComponentDataType().c_str(),
312 valSO->GetName().c_str()) );
319 listIO.Append( anIObject );
323 listIO.Append( anIObject );
326 GEOM_Displayer(anActiveStudy).Erase( listIO, true );
327 getGeometryGUI()->getApp()->selectionMgr()->clearSelected();
330 //=====================================================================================
331 // function : DisplayGUI::SetDisplayMode()
332 // purpose : Set display mode for the viewer (current viewer if <viewWindow> - 0 )
333 //=====================================================================================
334 void DisplayGUI::SetDisplayMode( const int mode, SUIT_ViewWindow* viewWindow )
336 SUIT_OverrideCursor();
339 viewWindow = getGeometryGUI()->getApp()->desktop()->activeWindow();
340 if ( viewWindow->getViewManager()->getType() == SVTK_Viewer::Type() ) {
341 SVTK_View* aView = ((SVTK_ViewWindow*)viewWindow)->getView();
342 aView->SetDisplayMode( mode );
344 else if ( viewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() ) {
345 OCCViewer_Viewer* v3d = ((OCCViewer_ViewManager*)(viewWindow->getViewManager()))->getOCCViewer();
346 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
347 AIS_DisplayMode newmode = (mode == 1 ? AIS_Shaded : AIS_WireFrame);
348 AIS_ListOfInteractive List;
349 ic->DisplayedObjects( List );
350 AIS_ListOfInteractive List1;
351 ic->ObjectsInCollector( List1 );
352 List.Append( List1 );
354 AIS_ListIteratorOfListOfInteractive ite( List );
355 while( ite.More() ) {
356 if( ite.Value()->IsInstance( STANDARD_TYPE(GEOM_AISShape) ) ) {
357 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast( ite.Value() );
358 ic->SetDisplayMode( aSh, Standard_Integer( newmode ),true );
363 ic->SetDisplayMode( newmode, Standard_False );
367 //=====================================================================================
368 // function : DisplayGUI::GetDisplayMode()
369 // purpose : Get display mode of the viewer (current viewer if <viewWindow> - 0 )
370 //=====================================================================================
371 int DisplayGUI::GetDisplayMode( SUIT_ViewWindow* viewWindow )
375 viewWindow = getGeometryGUI()->getApp()->desktop()->activeWindow();
376 if ( viewWindow->getViewManager()->getType() == SVTK_Viewer::Type() ) {
377 SVTK_View* aView = ((SVTK_ViewWindow*)viewWindow)->getView();
378 dispMode = aView->GetDisplayMode();
380 else if ( viewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() ) {
381 OCCViewer_Viewer* v3d = ((OCCViewer_ViewManager*)(viewWindow->getViewManager()))->getOCCViewer();
382 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
383 AIS_DisplayMode mode = (AIS_DisplayMode)ic->DisplayMode();
384 dispMode = (mode == AIS_WireFrame ? 0 : 1 );
389 //=====================================================================================
390 // function : DisplayGUI::InvertDisplayMode()
391 // purpose : Invert display mode ( shadin <-> wireframe ) for the viewer
392 // (current viewer if <viewWindow> = 0 )
393 //=====================================================================================
394 void DisplayGUI::InvertDisplayMode( SUIT_ViewWindow* viewWindow )
396 SetDisplayMode( 1 - GetDisplayMode( viewWindow ) );
399 //=====================================================================================
400 // function : DisplayGUI::ChangeDisplayMode()
401 // purpose : Set display mode for selected objects in the viewer given
402 // (current viewer if <viewWindow> = 0 )
403 //=====================================================================================
404 void DisplayGUI::ChangeDisplayMode( const int mode, SUIT_ViewWindow* viewWindow )
406 SalomeApp_Application* app = getGeometryGUI()->getApp();
410 viewWindow = app->desktop()->activeWindow();
412 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
413 if ( !aSelMgr ) return;
415 SUIT_OverrideCursor();
419 if ( viewWindow->getViewManager()->getType() == SVTK_Viewer::Type() ) {
420 SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>( viewWindow );
421 SVTK_View* aView = vw->getView();
423 aSelMgr->selectedObjects( aList );
424 SALOME_ListIteratorOfListIO It( aList );
426 for( ;It.More(); It.Next() ) {
427 SVTK_Viewer* stvkViewer = dynamic_cast<SVTK_Viewer*>(vw->getViewManager()->getViewModel());
429 stvkViewer ? dynamic_cast<SVTK_Prs*>( stvkViewer->CreatePrs( It.Value()->getEntry() ) ) : 0;
430 if ( vtkPrs && !vtkPrs->IsNull() ) {
432 aView->ChangeRepresentationToWireframe( vtkPrs->GetObjects() );
433 else if ( mode == 1 )
434 aView->ChangeRepresentationToSurface( vtkPrs->GetObjects() );
439 else if ( viewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() ) {
440 OCCViewer_Viewer* v3d = ((OCCViewer_ViewManager*)(viewWindow->getViewManager()))->getOCCViewer();
441 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
443 aSelMgr->selectedObjects( aList );
444 SALOME_ListIteratorOfListIO It( aList );
446 for( ;It.More(); It.Next() ) {
447 SOCC_Viewer* soccViewer = (SOCC_Viewer*)(viewWindow->getViewManager()->getViewModel());
448 SOCC_Prs* occPrs = dynamic_cast<SOCC_Prs*>( soccViewer->CreatePrs( It.Value()->getEntry() ) );
449 if ( occPrs && !occPrs->IsNull() ) {
450 AIS_ListOfInteractive shapes; occPrs->GetObjects( shapes );
451 AIS_ListIteratorOfListOfInteractive interIter( shapes );
452 for ( ; interIter.More(); interIter.Next() ) {
454 ic->SetDisplayMode( interIter.Value(), AIS_WireFrame, false );
455 else if ( mode == 1 )
456 ic->SetDisplayMode( interIter.Value(), AIS_Shaded, false );
460 ic->UpdateCurrentViewer();
464 //=====================================================================================
466 //=====================================================================================
470 __declspec( dllexport )
472 GEOMGUI* GetLibGUI( GeometryGUI* parent )
474 return new DisplayGUI( parent );