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, 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>
30 #include <GEOM_Actor.h>
32 #include <SUIT_Desktop.h>
33 #include <SUIT_ViewWindow.h>
34 #include <SUIT_OverrideCursor.h>
36 #include <OCCViewer_ViewManager.h>
37 #include <OCCViewer_ViewModel.h>
39 #include <SALOME_ListIO.hxx>
40 #include <SALOME_ListIteratorOfListIO.hxx>
42 #include <SVTK_ViewWindow.h>
43 #include <SVTK_View.h>
44 #include <SVTK_ViewModel.h>
45 #include <SOCC_ViewModel.h>
49 #include <QtxActionMenuMgr.h>
51 #include <SalomeApp_Application.h>
52 #include <LightApp_SelectionMgr.h>
53 #include <SalomeApp_Study.h>
55 #include <AIS_ListIteratorOfListOfInteractive.hxx>
57 #include <vtkActorCollection.h>
58 #include <vtkRenderer.h>
62 //=======================================================================
63 // function : DisplayGUI::DisplayGUI()
64 // purpose : Constructor
65 //=======================================================================
66 DisplayGUI::DisplayGUI( GeometryGUI* parent ) : GEOMGUI( parent )
70 //=======================================================================
71 // function : DisplayGUI::~DisplayGUI()
72 // purpose : Destructor
73 //=======================================================================
74 DisplayGUI::~DisplayGUI()
79 //=======================================================================
80 // function : DisplayGUI::OnGUIEvent()
81 // purpose : Dispatch menu command
82 //=======================================================================
83 bool DisplayGUI::OnGUIEvent(int theCommandID, SUIT_Desktop* parent)
85 SalomeApp_Application* app = getGeometryGUI()->getApp();
86 if (!app) return false;
88 LightApp_SelectionMgr *Sel = app->selectionMgr();
89 SALOME_ListIO selected;
90 Sel->selectedObjects( selected );
92 switch (theCommandID) {
93 case 211: // MENU VIEW - WIREFRAME/SHADING
96 int newMode = GetDisplayMode();
97 getGeometryGUI()->action( 211 )->setText
98 ( newMode == 1 ? tr( "GEOM_MEN_WIREFRAME" ) : tr("GEOM_MEN_SHADING") );
99 getGeometryGUI()->menuMgr()->update();
102 case 212: // MENU VIEW - DISPLAY ALL
104 getGeometryGUI()->EmitSignalDeactivateDialog();
108 case 213: // MENU VIEW - DISPLAY ONLY
110 getGeometryGUI()->EmitSignalDeactivateDialog();
114 case 214: // MENU VIEW - ERASE ALL
119 case 215: // MENU VIEW - ERASE
124 case 216: // MENU VIEW - DISPLAY
126 getGeometryGUI()->EmitSignalDeactivateDialog();
130 case 218: // MENU VIEW - VECTORS MODE
132 bool mode = GetVectorMode();
133 SetVectorMode(!mode);
134 getGeometryGUI()->action( 218 )->setText
135 ( mode == false ? tr( "MEN_VECTOR_MODE_OFF" ) : tr("MEN_VECTOR_MODE_ON") );
136 getGeometryGUI()->menuMgr()->update();
139 case 80311: // POPUP VIEWER - WIREFRAME
141 ChangeDisplayMode( 0 );
144 case 80312: // POPUP VIEWER - SHADING
146 ChangeDisplayMode( 1 );
149 case 80313: // POPUP VIEWER - VECTORS
151 ChangeDisplayMode( 2 );
156 app->putInfo(tr("GEOM_PRP_COMMAND").arg(theCommandID));
160 Sel->setSelectedObjects( selected );
164 //=====================================================================================
165 // function : DisplayGUI::DisplayAll()
166 // purpose : Display all GEOM objects
167 //=====================================================================================
168 void DisplayGUI::DisplayAll()
170 SalomeApp_Application* app = getGeometryGUI()->getApp();
173 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
174 if ( !appStudy ) return;
175 _PTR(Study) aStudy = appStudy->studyDS();
176 if ( !aStudy ) return;
177 _PTR(SComponent) SC ( aStudy->FindComponent( "GEOM" ) );
181 SALOME_ListIO listIO;
182 _PTR(ChildIterator) anIter ( aStudy->NewChildIterator( SC ) );
183 anIter->InitEx( true );
185 SUIT_OverrideCursor();
187 while( anIter->More() ) {
188 _PTR(SObject) valSO ( anIter->Value() );
190 if ( !valSO->ReferencedObject( refSO ) ) {
191 listIO.Append( new SALOME_InteractiveObject(valSO->GetID().c_str(),
192 SC->ComponentDataType().c_str(),
193 valSO->GetName().c_str()) );
197 GEOM_Displayer( appStudy ).Display( listIO, true );
200 //=====================================================================================
201 // function : DisplayGUI::EraseAll()
202 // purpose : Erase all GEOM objects
203 //=====================================================================================
204 void DisplayGUI::EraseAll()
206 SUIT_OverrideCursor();
208 SUIT_Application* app = getGeometryGUI()->getApp();
210 SUIT_ViewWindow* vw = app->desktop()->activeWindow();
212 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
213 SUIT_ViewManager* vman = vw->getViewManager();
214 if ( vman->getType() == OCCViewer_Viewer::Type() ||
215 vman->getType() == SVTK_Viewer::Type() ) {
216 GEOM_Displayer( appStudy ).EraseAll();
222 //=====================================================================================
223 // function : DisplayGUI::DisplayOnly()
224 // purpose : Display selected GEOM objects and erase other
225 //=====================================================================================
226 void DisplayGUI::DisplayOnly()
232 //=====================================================================================
233 // function : DisplayGUI::Display()
234 // purpose : Display selected GEOM objects
235 //=====================================================================================
236 void DisplayGUI::Display()
238 SALOME_ListIO listIO;
240 SalomeApp_Application* app = getGeometryGUI()->getApp();
243 SalomeApp_Study* anActiveStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
244 if ( !anActiveStudy ) return;
246 //get SalomeApp selection manager
247 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
248 if ( !aSelMgr ) return;
251 aSelMgr->selectedObjects( aList );
252 SALOME_ListIteratorOfListIO It( aList );
254 SUIT_OverrideCursor();
256 for( ;It.More();It.Next() ) {
257 Handle(SALOME_InteractiveObject) anIObject = It.Value();
258 if ( anIObject->hasEntry() ) {
259 _PTR(SObject) SO ( anActiveStudy->studyDS()->FindObjectID( anIObject->getEntry() ) );
260 if ( SO && QString(SO->GetID().c_str()) == QString(SO->GetFatherComponent()->GetID().c_str()) ) {
261 _PTR(SComponent) SC ( SO->GetFatherComponent() );
262 // if component is selected
264 _PTR(ChildIterator) anIter ( anActiveStudy->studyDS()->NewChildIterator( SO ) );
265 anIter->InitEx( true );
266 while( anIter->More() ) {
267 _PTR(SObject) valSO ( anIter->Value() );
269 if ( !valSO->ReferencedObject( refSO ) ) {
270 listIO.Append( new SALOME_InteractiveObject(valSO->GetID().c_str(),
271 SC->ComponentDataType().c_str(),
272 valSO->GetName().c_str()) );
279 listIO.Append( anIObject );
283 listIO.Append( anIObject );
286 GEOM_Displayer( anActiveStudy ).Display( listIO, true );
290 //=====================================================================================
291 // function : DisplayGUI::Erase()
292 // purpose : Erase selected GEOM objects
293 //=====================================================================================
294 void DisplayGUI::Erase()
296 SALOME_ListIO listIO;
298 SalomeApp_Application* app = getGeometryGUI()->getApp();
301 SalomeApp_Study* anActiveStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
302 if ( !anActiveStudy ) return;
304 //get SalomeApp selection manager
305 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
306 if ( !aSelMgr ) return;
309 aSelMgr->selectedObjects( aList );
310 SALOME_ListIteratorOfListIO It( aList );
312 SUIT_OverrideCursor();
314 for( ; It.More(); It.Next() ) {
315 Handle(SALOME_InteractiveObject) anIObject = It.Value();
316 if ( anIObject->hasEntry() ) {
317 _PTR(SObject) SO ( anActiveStudy->studyDS()->FindObjectID( anIObject->getEntry() ) );
318 if ( SO && QString(SO->GetID().c_str()) == QString(SO->GetFatherComponent()->GetID().c_str()) ) {
319 _PTR(SComponent) SC ( SO->GetFatherComponent() );
320 // if component is selected
322 _PTR(ChildIterator) anIter ( anActiveStudy->studyDS()->NewChildIterator( SO ) );
323 anIter->InitEx( true );
324 while( anIter->More() ) {
325 _PTR(SObject) valSO ( anIter->Value() );
327 if ( !valSO->ReferencedObject( refSO ) ) {
328 listIO.Append( new SALOME_InteractiveObject(valSO->GetID().c_str(),
329 SC->ComponentDataType().c_str(),
330 valSO->GetName().c_str()) );
337 listIO.Append( anIObject );
341 listIO.Append( anIObject );
345 SUIT_ViewWindow* viewWindow = app->desktop()->activeWindow();
346 bool aIsForced = true;
347 if(viewWindow->getViewManager()->getType() == SVTK_Viewer::Type())
350 GEOM_Displayer(anActiveStudy).Erase( listIO, aIsForced);
351 getGeometryGUI()->getApp()->selectionMgr()->clearSelected();
354 //=====================================================================================
355 // function : DisplayGUI::SetDisplayMode()
356 // purpose : Set display mode for the viewer (current viewer if <viewWindow> - 0 )
357 //=====================================================================================
358 void DisplayGUI::SetDisplayMode( const int mode, SUIT_ViewWindow* viewWindow )
360 SUIT_OverrideCursor();
363 viewWindow = getGeometryGUI()->getApp()->desktop()->activeWindow();
364 if ( viewWindow->getViewManager()->getType() == SVTK_Viewer::Type() ) {
365 SVTK_View* aView = ((SVTK_ViewWindow*)viewWindow)->getView();
366 aView->SetDisplayMode( mode );
368 else if ( viewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() ) {
369 OCCViewer_Viewer* v3d = ((OCCViewer_ViewManager*)(viewWindow->getViewManager()))->getOCCViewer();
370 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
371 AIS_DisplayMode newmode = (mode == 1 ? AIS_Shaded : AIS_WireFrame);
372 AIS_ListOfInteractive List;
373 ic->DisplayedObjects( List );
374 AIS_ListOfInteractive List1;
375 ic->ObjectsInCollector( List1 );
376 List.Append( List1 );
378 AIS_ListIteratorOfListOfInteractive ite( List );
379 while( ite.More() ) {
380 if( ite.Value()->IsInstance( STANDARD_TYPE(GEOM_AISShape) ) ) {
381 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast( ite.Value() );
382 ic->SetDisplayMode( aSh, Standard_Integer( newmode ),true );
387 ic->SetDisplayMode( newmode, Standard_False );
391 //=====================================================================================
392 // function : DisplayGUI::GetDisplayMode()
393 // purpose : Get display mode of the viewer (current viewer if <viewWindow> - 0 )
394 //=====================================================================================
395 int DisplayGUI::GetDisplayMode( SUIT_ViewWindow* viewWindow )
399 viewWindow = getGeometryGUI()->getApp()->desktop()->activeWindow();
400 if ( viewWindow->getViewManager()->getType() == SVTK_Viewer::Type() ) {
401 SVTK_View* aView = ((SVTK_ViewWindow*)viewWindow)->getView();
402 dispMode = aView->GetDisplayMode();
404 else if ( viewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() ) {
405 OCCViewer_Viewer* v3d = ((OCCViewer_ViewManager*)(viewWindow->getViewManager()))->getOCCViewer();
406 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
407 AIS_DisplayMode mode = (AIS_DisplayMode)ic->DisplayMode();
408 dispMode = (mode == AIS_WireFrame ? 0 : 1 );
413 //=====================================================================================
414 // function : DisplayGUI::SetVectorsMode()
415 // purpose : Set vector mode for the viewer
416 //=====================================================================================
417 void DisplayGUI::SetVectorMode( const bool mode, SUIT_ViewWindow* viewWindow )
419 SUIT_OverrideCursor();
422 viewWindow = getGeometryGUI()->getApp()->desktop()->activeWindow();
423 if ( viewWindow->getViewManager()->getType() == SVTK_Viewer::Type() ) {
424 viewWindow->setCustomData( "VectorsMode", QVariant( mode ) );
425 SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>( viewWindow );
426 vtkActorCollection* allActors = vw->getRenderer()->GetActors();
427 allActors->InitTraversal();
428 while (vtkActor* actor = allActors->GetNextActor()) {
429 if (actor->GetVisibility()) { // only for visible actors
430 GEOM_Actor* aGeomActor = 0;
431 if ( actor->IsA( "GEOM_Actor" ) ) {
432 aGeomActor = GEOM_Actor::SafeDownCast( actor );
434 aGeomActor->SetVectorMode( mode );
439 else if ( viewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() ) {
440 viewWindow->setCustomData( "VectorsMode", QVariant( mode ) );
441 OCCViewer_Viewer* v3d = ((OCCViewer_ViewManager*)(viewWindow->getViewManager()))->getOCCViewer();
442 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
443 AIS_ListOfInteractive List;
444 ic->DisplayedObjects( List );
445 AIS_ListOfInteractive List1;
446 ic->ObjectsInCollector( List1 );
447 List.Append( List1 );
449 AIS_ListIteratorOfListOfInteractive ite( List );
450 while( ite.More() ) {
451 if( ite.Value()->IsInstance( STANDARD_TYPE(GEOM_AISShape) ) ) {
452 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast( ite.Value() );
453 aSh->SetDisplayVectors(mode);
454 ic->RecomputePrsOnly(ite.Value());
461 //=====================================================================================
462 // function : DisplayGUI::GetVectorMode()
463 // purpose : Get the "show edge direction" mode of the viewer
464 //=====================================================================================
465 int DisplayGUI::GetVectorMode( SUIT_ViewWindow* viewWindow )
468 viewWindow = getGeometryGUI()->getApp()->desktop()->activeWindow();
469 return viewWindow->getCustomData( "VectorsMode" ).toBool();
472 //=====================================================================================
473 // function : DisplayGUI::InvertDisplayMode()
474 // purpose : Invert display mode ( shadin <-> wireframe ) for the viewer
475 // (current viewer if <viewWindow> = 0 )
476 //=====================================================================================
477 void DisplayGUI::InvertDisplayMode( SUIT_ViewWindow* viewWindow )
479 SetDisplayMode( 1 - GetDisplayMode( viewWindow ) );
482 //=====================================================================================
483 // function : DisplayGUI::ChangeDisplayMode()
484 // purpose : Set display mode for selected objects in the viewer given
485 // (current viewer if <viewWindow> = 0 )
486 //=====================================================================================
487 void DisplayGUI::ChangeDisplayMode( const int mode, SUIT_ViewWindow* viewWindow )
489 SalomeApp_Application* app = getGeometryGUI()->getApp();
493 viewWindow = app->desktop()->activeWindow();
495 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
496 if ( !aSelMgr ) return;
498 SUIT_OverrideCursor();
502 if ( viewWindow->getViewManager()->getType() == SVTK_Viewer::Type() ) {
503 SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>( viewWindow );
504 SVTK_View* aView = vw->getView();
506 aSelMgr->selectedObjects( aList );
507 SALOME_ListIteratorOfListIO It( aList );
509 for( ;It.More(); It.Next() ) {
510 SVTK_Viewer* stvkViewer = dynamic_cast<SVTK_Viewer*>(vw->getViewManager()->getViewModel());
512 stvkViewer ? dynamic_cast<SVTK_Prs*>( stvkViewer->CreatePrs( It.Value()->getEntry() ) ) : 0;
513 if ( vtkPrs && !vtkPrs->IsNull() ) {
515 aView->ChangeRepresentationToWireframe( vtkPrs->GetObjects() );
516 else if ( mode == 1 )
517 aView->ChangeRepresentationToSurface( vtkPrs->GetObjects() );
518 else if ( mode == 2 ) {
519 vtkActorCollection* anActors = vtkPrs->GetObjects();
520 anActors->InitTraversal();
521 while (vtkActor* anAct = anActors->GetNextActor()) {
522 GEOM_Actor* aGeomActor = GEOM_Actor::SafeDownCast(anAct);
523 aGeomActor->SetVectorMode(!aGeomActor->GetVectorMode());
530 else if ( viewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() ) {
531 OCCViewer_Viewer* v3d = ((OCCViewer_ViewManager*)(viewWindow->getViewManager()))->getOCCViewer();
532 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
534 aSelMgr->selectedObjects( aList );
535 SALOME_ListIteratorOfListIO It( aList );
537 for( ;It.More(); It.Next() ) {
538 SOCC_Viewer* soccViewer = (SOCC_Viewer*)(viewWindow->getViewManager()->getViewModel());
539 SOCC_Prs* occPrs = dynamic_cast<SOCC_Prs*>( soccViewer->CreatePrs( It.Value()->getEntry() ) );
540 if ( occPrs && !occPrs->IsNull() ) {
541 AIS_ListOfInteractive shapes; occPrs->GetObjects( shapes );
542 AIS_ListIteratorOfListOfInteractive interIter( shapes );
543 for ( ; interIter.More(); interIter.Next() ) {
545 ic->SetDisplayMode( interIter.Value(), AIS_WireFrame, false );
546 else if ( mode == 1 )
547 ic->SetDisplayMode( interIter.Value(), AIS_Shaded, false );
549 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast( interIter.Value() );
550 if ( !aSh.IsNull() ) {
551 aSh->SetDisplayVectors(!aSh->isShowVectors());
552 ic->RecomputePrsOnly(interIter.Value());
558 ic->UpdateCurrentViewer();
562 //=====================================================================================
564 //=====================================================================================
568 __declspec( dllexport )
570 GEOMGUI* GetLibGUI( GeometryGUI* parent )
572 return new DisplayGUI( parent );