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 "QAD_RightFrame.h"
34 #include "QAD_WaitCursor.h"
35 #include "QAD_Desktop.h"
36 #include "VTKViewer_ViewFrame.h"
37 #include "VTKViewer_RenderWindowInteractor.h"
38 #include "OCCViewer_ViewFrame.h"
39 #include "OCCViewer_Viewer3d.h"
40 #include "SALOME_ListIteratorOfListIO.hxx"
41 #include "VTKViewer_Prs.h"
42 #include "OCCViewer_Prs.h"
44 #include <AIS_ListIteratorOfListOfInteractive.hxx>
48 DisplayGUI* DisplayGUI::myGUIObject = 0;
50 //=======================================================================
51 // function : DisplayGUI::GetDisplayGUI()
52 // purpose : Get the only DisplayGUI object [ static ]
53 //=======================================================================
54 DisplayGUI* DisplayGUI::GetDisplayGUI()
56 if ( myGUIObject == 0 ) {
57 // init DisplayGUI only once
58 myGUIObject = new DisplayGUI();
63 //=======================================================================
64 // function : DisplayGUI::DisplayGUI()
65 // purpose : Constructor
66 //=======================================================================
67 DisplayGUI::DisplayGUI() : GEOMGUI()
72 //=======================================================================
73 // function : DisplayGUI::~DisplayGUI()
74 // purpose : Destructor
75 //=======================================================================
76 DisplayGUI::~DisplayGUI()
81 //=======================================================================
82 // function : DisplayGUI::OnGUIEvent()
83 // purpose : Dispatch menu command
84 //=======================================================================
85 bool DisplayGUI::OnGUIEvent(int theCommandID, QAD_Desktop* parent)
87 DisplayGUI* myDisplayGUI = GetDisplayGUI();
89 switch (theCommandID) {
90 case 211: // MENU VIEW - WIREFRAME/SHADING
92 myDisplayGUI->InvertDisplayMode();
93 int newMode = myDisplayGUI->GetDisplayMode();
94 QAD_Application::getDesktop()->menuBar()->changeItem( 211, newMode == 1 ? tr( "GEOM_MEN_WIREFRAME" ) : tr("GEOM_MEN_SHADING") );
97 case 212: // MENU VIEW - DISPLAY ALL
99 myDisplayGUI->DisplayAll();
102 case 213: // MENU VIEW - DISPLAY ONLY
104 myDisplayGUI->DisplayOnly();
107 case 214: // MENU VIEW - ERASE ALL
109 myDisplayGUI->EraseAll();
112 case 215: // MENU VIEW - ERASE
114 myDisplayGUI->Erase();
117 case 216: // MENU VIEW - DISPLAY
119 myDisplayGUI->Display();
122 case 80311: // POPUP VIEWER - WIREFRAME
124 myDisplayGUI->ChangeDisplayMode( 0 );
127 case 80312: // POPUP VIEWER - SHADING
129 myDisplayGUI->ChangeDisplayMode( 1 );
134 parent->putInfo(tr("GEOM_PRP_COMMAND").arg(theCommandID));
141 //=====================================================================================
142 // function : DisplayGUI::DisplayAll()
143 // purpose : Display all GEOM objects
144 //=====================================================================================
145 void DisplayGUI::DisplayAll()
148 SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
149 SALOMEDS::SComponent_var SC = aStudy->FindComponent( "GEOM" );
153 SALOME_ListIO listIO;
154 SALOMEDS::ChildIterator_var anIter = aStudy->NewChildIterator( SC );
155 anIter->InitEx( true );
156 while( anIter->More() ) {
157 SALOMEDS::SObject_var valSO = anIter->Value();
158 SALOMEDS::SObject_var refSO;
159 if ( !valSO->ReferencedObject( refSO ) ) {
160 listIO.Append( new SALOME_InteractiveObject( valSO->GetID(), SC->ComponentDataType() ,valSO->GetName()) );
164 GEOM_Displayer().Display( listIO, true );
167 //=====================================================================================
168 // function : DisplayGUI::EraseAll()
169 // purpose : Erase all GEOM objects
170 //=====================================================================================
171 void DisplayGUI::EraseAll()
174 QAD_ViewFrame* vf = QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame();
175 if ( vf->getTypeView() == VIEW_OCC || vf->getTypeView() == VIEW_VTK )
179 //=====================================================================================
180 // function : DisplayGUI::DisplayOnly()
181 // purpose : Display selected GEOM objects and erase other
182 //=====================================================================================
183 void DisplayGUI::DisplayOnly()
189 //=====================================================================================
190 // function : DisplayGUI::Display()
191 // purpose : Display selected GEOM objects
192 //=====================================================================================
193 void DisplayGUI::Display()
196 SALOME_ListIO listIO;
198 QAD_Study* anActiveStudy = QAD_Application::getDesktop()->getActiveStudy();
199 SALOME_Selection* Sel = SALOME_Selection::Selection( anActiveStudy->getSelection() );
200 SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
201 for( ;It.More();It.Next() ) {
202 Handle(SALOME_InteractiveObject) anIObject = It.Value();
203 if ( anIObject->hasEntry() ) {
204 SALOMEDS::SObject_var SO = anActiveStudy->getStudyDocument()->FindObjectID( anIObject->getEntry() );
205 if ( !SO->_is_nil() && QString( SO->GetID() ) == QString( SO->GetFatherComponent()->GetID() ) ) {
206 SALOMEDS::SComponent_var SC = SO->GetFatherComponent();
207 // if component is selected
209 SALOMEDS::ChildIterator_var anIter = anActiveStudy->getStudyDocument()->NewChildIterator( SO );
210 anIter->InitEx( true );
211 while( anIter->More() ) {
212 SALOMEDS::SObject_var valSO = anIter->Value();
213 SALOMEDS::SObject_var refSO;
214 if ( !valSO->ReferencedObject( refSO ) ) {
215 listIO.Append( new SALOME_InteractiveObject( valSO->GetID(), SC->ComponentDataType() ,valSO->GetName()) );
222 listIO.Append( anIObject );
226 listIO.Append( anIObject );
229 GEOM_Displayer().Display( listIO, true );
233 //=====================================================================================
234 // function : DisplayGUI::Erase()
235 // purpose : Erase selected GEOM objects
236 //=====================================================================================
237 void DisplayGUI::Erase()
240 SALOME_ListIO listIO;
242 QAD_Study* anActiveStudy = QAD_Application::getDesktop()->getActiveStudy();
243 SALOME_Selection* Sel = SALOME_Selection::Selection( anActiveStudy->getSelection() );
244 SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
245 for( ;It.More();It.Next() ) {
246 Handle(SALOME_InteractiveObject) anIObject = It.Value();
247 if ( anIObject->hasEntry() ) {
248 SALOMEDS::SObject_var SO = anActiveStudy->getStudyDocument()->FindObjectID( anIObject->getEntry() );
249 if ( !SO->_is_nil() && QString( SO->GetID() ) == QString( SO->GetFatherComponent()->GetID() ) ) {
250 SALOMEDS::SComponent_var SC = SO->GetFatherComponent();
251 // if component is selected
253 SALOMEDS::ChildIterator_var anIter = anActiveStudy->getStudyDocument()->NewChildIterator( SO );
254 anIter->InitEx( true );
255 while( anIter->More() ) {
256 SALOMEDS::SObject_var valSO = anIter->Value();
257 SALOMEDS::SObject_var refSO;
258 if ( !valSO->ReferencedObject( refSO ) ) {
259 listIO.Append( new SALOME_InteractiveObject( valSO->GetID(), SC->ComponentDataType() ,valSO->GetName()) );
266 listIO.Append( anIObject );
270 listIO.Append( anIObject );
273 GEOM_Displayer().Erase( listIO, true );
274 Sel->ClearIObjects();
277 //=====================================================================================
278 // function : DisplayGUI::SetDisplayMode()
279 // purpose : Set display mode for the viewer (current viewer if <viewFrame> - 0 )
280 //=====================================================================================
281 void DisplayGUI::SetDisplayMode( const int mode, QAD_ViewFrame* viewFrame )
285 viewFrame = QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame();
286 if( viewFrame->getTypeView() == VIEW_VTK ) {
287 VTKViewer_RenderWindowInteractor* myRenderInter= ((VTKViewer_ViewFrame*)viewFrame)->getRWInteractor();
288 myRenderInter->SetDisplayMode( mode );
290 else if( viewFrame->getTypeView() == VIEW_OCC ) {
291 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)viewFrame)->getViewer();
292 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
293 AIS_DisplayMode newmode = (mode == 1 ? AIS_Shaded : AIS_WireFrame);
294 AIS_ListOfInteractive List;
295 ic->DisplayedObjects( List );
296 AIS_ListOfInteractive List1;
297 ic->ObjectsInCollector( List1 );
298 List.Append( List1 );
300 AIS_ListIteratorOfListOfInteractive ite( List );
301 while( ite.More() ) {
302 if( ite.Value()->IsInstance( STANDARD_TYPE(GEOM_AISShape) ) ) {
303 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast( ite.Value() );
304 ic->SetDisplayMode( aSh, Standard_Integer( newmode ),true );
309 ic->SetDisplayMode( newmode, Standard_False );
313 //=====================================================================================
314 // function : DisplayGUI::GetDisplayMode()
315 // purpose : Get display mode of the viewer (current viewer if <viewFrame> - 0 )
316 //=====================================================================================
317 int DisplayGUI::GetDisplayMode( QAD_ViewFrame* viewFrame )
321 viewFrame = QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame();
322 if( viewFrame->getTypeView() == VIEW_VTK) {
323 VTKViewer_RenderWindowInteractor* myRenderInter= ((VTKViewer_ViewFrame*)viewFrame)->getRWInteractor();
324 dispMode = myRenderInter->GetDisplayMode();
326 else if( viewFrame->getTypeView() == VIEW_OCC) {
327 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)viewFrame)->getViewer();
328 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
329 AIS_DisplayMode mode = (AIS_DisplayMode)ic->DisplayMode();
330 dispMode = (mode == AIS_WireFrame ? 0 : 1 );
335 //=====================================================================================
336 // function : DisplayGUI::InvertDisplayMode()
337 // purpose : Invert display mode ( shadin <-> wireframe ) for the viewer
338 // (current viewer if <viewFrame> = 0 )
339 //=====================================================================================
340 void DisplayGUI::InvertDisplayMode( QAD_ViewFrame* viewFrame )
342 SetDisplayMode( 1 - GetDisplayMode( viewFrame ) );
345 //=====================================================================================
346 // function : DisplayGUI::ChangeDisplayMode()
347 // purpose : Set display mode for selected objects in the viewer given
348 // (current viewer if <viewFrame> = 0 )
349 //=====================================================================================
350 void DisplayGUI::ChangeDisplayMode( const int mode, QAD_ViewFrame* viewFrame )
354 viewFrame = QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame();
355 SALOME_Selection* Sel = SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection());
356 if ( viewFrame->getTypeView() == VIEW_VTK ) {
357 VTKViewer_RenderWindowInteractor* myRenderInter = ((VTKViewer_ViewFrame*)viewFrame)->getRWInteractor();
358 SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
359 for( ;It.More(); It.Next() ) {
360 VTKViewer_Prs* vtkPrs = dynamic_cast<VTKViewer_Prs*>( viewFrame->CreatePrs( It.Value()->getEntry() ) );
361 if ( vtkPrs && !vtkPrs->IsNull() ) {
363 myRenderInter->ChangeRepresentationToWireframe( vtkPrs->GetObjects() );
364 else if ( mode == 1 )
365 myRenderInter->ChangeRepresentationToSurface( vtkPrs->GetObjects() );
368 myRenderInter->Render();
370 else if ( viewFrame->getTypeView() == VIEW_OCC ) {
371 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)viewFrame)->getViewer();
372 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
373 SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
374 for( ;It.More(); It.Next() ) {
375 OCCViewer_Prs* occPrs = dynamic_cast<OCCViewer_Prs*>( viewFrame->CreatePrs( It.Value()->getEntry() ) );
376 if ( occPrs && !occPrs->IsNull() ) {
377 AIS_ListOfInteractive shapes; occPrs->GetObjects( shapes );
378 AIS_ListIteratorOfListOfInteractive interIter( shapes );
379 for ( ; interIter.More(); interIter.Next() ) {
381 ic->SetDisplayMode( interIter.Value(), AIS_WireFrame, false );
382 else if ( mode == 1 )
383 ic->SetDisplayMode( interIter.Value(), AIS_Shaded, false );
387 ic->UpdateCurrentViewer();
391 //=====================================================================================
393 //=====================================================================================
398 return DisplayGUI::GetDisplayGUI();