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 );
327 SUIT_ViewWindow* viewWindow = app->desktop()->activeWindow();
328 bool aIsForced = true;
329 if(viewWindow->getViewManager()->getType() == SVTK_Viewer::Type())
332 GEOM_Displayer(anActiveStudy).Erase( listIO, aIsForced);
333 getGeometryGUI()->getApp()->selectionMgr()->clearSelected();
336 //=====================================================================================
337 // function : DisplayGUI::SetDisplayMode()
338 // purpose : Set display mode for the viewer (current viewer if <viewWindow> - 0 )
339 //=====================================================================================
340 void DisplayGUI::SetDisplayMode( const int mode, SUIT_ViewWindow* viewWindow )
342 SUIT_OverrideCursor();
345 viewWindow = getGeometryGUI()->getApp()->desktop()->activeWindow();
346 if ( viewWindow->getViewManager()->getType() == SVTK_Viewer::Type() ) {
347 SVTK_View* aView = ((SVTK_ViewWindow*)viewWindow)->getView();
348 aView->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 = getGeometryGUI()->getApp()->desktop()->activeWindow();
382 if ( viewWindow->getViewManager()->getType() == SVTK_Viewer::Type() ) {
383 SVTK_View* aView = ((SVTK_ViewWindow*)viewWindow)->getView();
384 dispMode = aView->GetDisplayMode();
386 else if ( viewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() ) {
387 OCCViewer_Viewer* v3d = ((OCCViewer_ViewManager*)(viewWindow->getViewManager()))->getOCCViewer();
388 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
389 AIS_DisplayMode mode = (AIS_DisplayMode)ic->DisplayMode();
390 dispMode = (mode == AIS_WireFrame ? 0 : 1 );
395 //=====================================================================================
396 // function : DisplayGUI::InvertDisplayMode()
397 // purpose : Invert display mode ( shadin <-> wireframe ) for the viewer
398 // (current viewer if <viewWindow> = 0 )
399 //=====================================================================================
400 void DisplayGUI::InvertDisplayMode( SUIT_ViewWindow* viewWindow )
402 SetDisplayMode( 1 - GetDisplayMode( viewWindow ) );
405 //=====================================================================================
406 // function : DisplayGUI::ChangeDisplayMode()
407 // purpose : Set display mode for selected objects in the viewer given
408 // (current viewer if <viewWindow> = 0 )
409 //=====================================================================================
410 void DisplayGUI::ChangeDisplayMode( const int mode, SUIT_ViewWindow* viewWindow )
412 SalomeApp_Application* app = getGeometryGUI()->getApp();
416 viewWindow = app->desktop()->activeWindow();
418 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
419 if ( !aSelMgr ) return;
421 SUIT_OverrideCursor();
425 if ( viewWindow->getViewManager()->getType() == SVTK_Viewer::Type() ) {
426 SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>( viewWindow );
427 SVTK_View* aView = vw->getView();
429 aSelMgr->selectedObjects( aList );
430 SALOME_ListIteratorOfListIO It( aList );
432 for( ;It.More(); It.Next() ) {
433 SVTK_Viewer* stvkViewer = dynamic_cast<SVTK_Viewer*>(vw->getViewManager()->getViewModel());
435 stvkViewer ? dynamic_cast<SVTK_Prs*>( stvkViewer->CreatePrs( It.Value()->getEntry() ) ) : 0;
436 if ( vtkPrs && !vtkPrs->IsNull() ) {
438 aView->ChangeRepresentationToWireframe( vtkPrs->GetObjects() );
439 else if ( mode == 1 )
440 aView->ChangeRepresentationToSurface( vtkPrs->GetObjects() );
445 else if ( viewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() ) {
446 OCCViewer_Viewer* v3d = ((OCCViewer_ViewManager*)(viewWindow->getViewManager()))->getOCCViewer();
447 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
449 aSelMgr->selectedObjects( aList );
450 SALOME_ListIteratorOfListIO It( aList );
452 for( ;It.More(); It.Next() ) {
453 SOCC_Viewer* soccViewer = (SOCC_Viewer*)(viewWindow->getViewManager()->getViewModel());
454 SOCC_Prs* occPrs = dynamic_cast<SOCC_Prs*>( soccViewer->CreatePrs( It.Value()->getEntry() ) );
455 if ( occPrs && !occPrs->IsNull() ) {
456 AIS_ListOfInteractive shapes; occPrs->GetObjects( shapes );
457 AIS_ListIteratorOfListOfInteractive interIter( shapes );
458 for ( ; interIter.More(); interIter.Next() ) {
460 ic->SetDisplayMode( interIter.Value(), AIS_WireFrame, false );
461 else if ( mode == 1 )
462 ic->SetDisplayMode( interIter.Value(), AIS_Shaded, false );
466 ic->UpdateCurrentViewer();
470 //=====================================================================================
472 //=====================================================================================
476 __declspec( dllexport )
478 GEOMGUI* GetLibGUI( GeometryGUI* parent )
480 return new DisplayGUI( parent );