Salome HOME
Update copyright: 2016
[modules/geom.git] / src / DisplayGUI / DisplayGUI.cxx
1 // Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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, or (at your option) any later version.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File   : DisplayGUI.cxx
25 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
26
27 #include "DisplayGUI.h"
28 #include <GeometryGUI.h>
29 #include "GeometryGUI_Operations.h"
30 #include <GEOM_Constants.h>
31 #include <GEOM_Displayer.h>
32 #include <GEOM_AISShape.hxx>
33 #include <GEOM_Actor.h>
34
35 #include <SUIT_Desktop.h>
36 #include <SUIT_ViewWindow.h>
37 #include <SUIT_OverrideCursor.h>
38
39 #include <OCCViewer_ViewManager.h>
40 #include <OCCViewer_ViewModel.h>
41
42 #include <SALOME_ListIO.hxx>
43
44 #include <SVTK_ViewWindow.h>
45 #include <SVTK_View.h>
46 #include <SVTK_ViewModel.h>
47 #include <SOCC_ViewModel.h>
48 #include <SVTK_Prs.h>
49 #include <SOCC_Prs.h>
50
51 #include <QtxActionMenuMgr.h>
52
53 #include <SalomeApp_Application.h>
54 #include <LightApp_SelectionMgr.h>
55 #include <SalomeApp_Study.h>
56
57 #include <AIS_ListIteratorOfListOfInteractive.hxx>
58
59 #include <vtkActorCollection.h>
60 #include <vtkRenderer.h>
61
62 #include <QAction>
63
64 //=======================================================================
65 // function : DisplayGUI::DisplayGUI()
66 // purpose  : Constructor
67 //=======================================================================
68 DisplayGUI::DisplayGUI( GeometryGUI* parent ) : GEOMGUI( parent )
69 {
70 }
71
72 //=======================================================================
73 // function : DisplayGUI::~DisplayGUI()
74 // purpose  : Destructor
75 //=======================================================================
76 DisplayGUI::~DisplayGUI()
77 {
78 }
79
80
81 //=======================================================================
82 // function : DisplayGUI::OnGUIEvent()
83 // purpose  : Dispatch menu command
84 //=======================================================================
85 bool DisplayGUI::OnGUIEvent(int theCommandID, SUIT_Desktop* parent)
86 {
87   SalomeApp_Application* app = getGeometryGUI()->getApp();
88   if (!app) return false;
89
90   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
91   if ( !appStudy ) return false;
92
93   LightApp_SelectionMgr *Sel = app->selectionMgr();
94   SALOME_ListIO selected;
95   Sel->selectedObjects( selected );
96
97   switch ( theCommandID ) {
98   case GEOMOp::OpDMWireframe:         // MENU VIEW - DISPLAY MODE - WIREFRAME
99     SetDisplayMode( 0 );
100     break;
101   case GEOMOp::OpDMShading:           // MENU VIEW - DISPLAY MODE - SHADING
102     SetDisplayMode( 1 );
103     break;
104   case GEOMOp::OpDMShadingWithEdges:  // MENU VIEW - DISPLAY MODE - SHADING WITH EDGES
105     SetDisplayMode( 2 );
106     break;
107   case GEOMOp::OpDMTexture:           // MENU VIEW - DISPLAY MODE - TEXTURE
108     SetDisplayMode( 3 );
109     break;
110   case GEOMOp::OpShowAll:        // MENU VIEW - SHOW ALL
111     getGeometryGUI()->EmitSignalDeactivateDialog();
112     DisplayAll();
113     break;
114   case GEOMOp::OpShowOnly:       // POPUP MENU - SHOW ONLY
115     getGeometryGUI()->EmitSignalDeactivateDialog();
116     DisplayOnly();
117     break;
118   case GEOMOp::OpShowOnlyChildren: // POPUP MENU - SHOW ONLY CHILDREN
119     getGeometryGUI()->EmitSignalDeactivateDialog();
120     DisplayOnlyChildren();
121     break;
122   case GEOMOp::OpHideAll:        // MENU VIEW - HIDE ALL
123     EraseAll();
124     break;
125   case GEOMOp::OpHide:           // POPUP MENU - HIDE
126     Erase();
127     break;
128   case GEOMOp::OpShow:           // POPUP MENU - SHOW
129     getGeometryGUI()->EmitSignalDeactivateDialog();
130     Display();
131     break;
132   case GEOMOp::OpSwitchVectors:  // MENU VIEW - DISPLAY MODE - SHOW EDGE DIRECTION
133     SetVectorMode(!GetVectorMode());
134     getGeometryGUI()->action( GEOMOp::OpSwitchVectors )->setText
135       ( GetVectorMode() ? tr("MEN_VECTOR_MODE_ON") : tr( "MEN_VECTOR_MODE_OFF" ) );
136     getGeometryGUI()->menuMgr()->update();
137     break;
138   case GEOMOp::OpSwitchVertices:  // MENU VIEW - DISPLAY MODE - SHOW/HIDE VERTICES
139     SetVerticesMode(!GetVerticesMode());
140     getGeometryGUI()->action( GEOMOp::OpSwitchVertices )->setText
141       ( GetVerticesMode() ? tr("MEN_VERTICES_MODE_ON") : tr( "MEN_VERTICES_MODE_OFF" ) );
142     getGeometryGUI()->menuMgr()->update();
143     break;
144   case GEOMOp::OpSwitchName:  // MENU VIEW - DISPLAY MODE - SHOW/HIDE NAME
145     SetNameMode(!GetNameMode());
146     getGeometryGUI()->action( GEOMOp::OpSwitchName )->setText
147       ( GetNameMode() ? tr("MEN_NAME_MODE_ON") : tr( "MEN_NAME_MODE_OFF" ) );
148     getGeometryGUI()->menuMgr()->update();
149     break;
150   case GEOMOp::OpWireframe:      // POPUP MENU - DISPLAY MODE - WIREFRAME
151     ChangeDisplayMode( 0 );
152     break;
153   case GEOMOp::OpShading:        // POPUP MENU - DISPLAY MODE - SHADING
154     ChangeDisplayMode( 1 );
155     break;
156   case GEOMOp::OpShadingWithEdges: // POPUP MENU - DISPLAY MODE - SHADING WITH EDGES
157     ChangeDisplayMode( 2 );
158     break;
159   case GEOMOp::OpTexture:        // POPUP MENU - DISPLAY MODE - TEXTURE
160     ChangeDisplayMode( 3 );
161     break;
162   case GEOMOp::OpVectors:        // POPUP MENU - DISPLAY MODE - SHOW EDGE DIRECTION
163     ChangeDisplayMode( 4 );
164     break;
165   case GEOMOp::OpVertices:       // POPUP MENU - DISPLAY MODE - SHOW VERTICES
166     ChangeDisplayMode( 5 );
167     break;
168   case GEOMOp::OpShowName:       // POPUP MENU - DISPLAY MODE - SHOW NAME
169     ChangeDisplayMode( 6 );
170     break;
171   default:
172     app->putInfo(tr("GEOM_PRP_COMMAND").arg(theCommandID));
173     break;
174   }
175   Sel->setSelectedObjects( selected );
176   GEOM_Displayer( appStudy ).UpdateColorScale();
177   return true;
178 }
179
180 //=====================================================================================
181 // function : DisplayGUI::DisplayAll()
182 // purpose  : Display all GEOM objects
183 //=====================================================================================
184 void DisplayGUI::DisplayAll()
185 {
186   SalomeApp_Application* app = getGeometryGUI()->getApp();
187   if ( !app ) return;
188
189   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
190   if ( !appStudy ) return;
191   _PTR(Study) aStudy = appStudy->studyDS();
192   if ( !aStudy ) return;
193   _PTR(SComponent) SC ( aStudy->FindComponent( "GEOM" ) );
194   if ( !SC )
195     return;
196
197   SALOME_ListIO listIO;
198   _PTR(ChildIterator) anIter ( aStudy->NewChildIterator( SC ) );
199   anIter->InitEx( true );
200
201   SUIT_OverrideCursor wc;
202
203   while( anIter->More() ) {
204     _PTR(SObject) valSO ( anIter->Value() );
205     _PTR(SObject) refSO;
206     if ( !valSO->ReferencedObject( refSO ) ) {
207       listIO.Append( new SALOME_InteractiveObject(valSO->GetID().c_str(),
208                                                   SC->ComponentDataType().c_str(),
209                                                   valSO->GetName().c_str()) );
210     } 
211     anIter->Next();
212   }
213   GEOM_Displayer( appStudy ).Display( listIO, true );
214 }
215
216 //=====================================================================================
217 // function : DisplayGUI::EraseAll()
218 // purpose  : Erase all GEOM objects
219 //=====================================================================================
220 void DisplayGUI::EraseAll()
221 {
222   SUIT_OverrideCursor wc;
223
224   SUIT_Application* app = getGeometryGUI()->getApp();
225   if ( app ) {
226     SUIT_ViewWindow* vw = app->desktop()->activeWindow();
227     if ( vw ) {
228       SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
229       SUIT_ViewManager* vman = vw->getViewManager();
230       if ( vman->getType() == OCCViewer_Viewer::Type() || 
231            vman->getType() == SVTK_Viewer::Type() ) {
232         GEOM_Displayer( appStudy ).EraseAll(true);
233       }
234     }
235   }
236 }
237
238 //=====================================================================================
239 // function : DisplayGUI::DisplayOnly()
240 // purpose  : Display selected GEOM objects and erase other
241 //=====================================================================================
242 void DisplayGUI::DisplayOnly()
243 {
244   EraseAll();
245   Display();
246 }
247
248 //=====================================================================================
249 // function : DisplayGUI::DisplayOnlyChildren()
250 // purpose  : Display only children of selected GEOM objects and erase other
251 //=====================================================================================
252 void DisplayGUI::DisplayOnlyChildren()
253 {
254   EraseAll();
255
256   SALOME_ListIO listIO;
257
258   SalomeApp_Application* app = getGeometryGUI()->getApp();
259   if (!app) return;
260
261   SalomeApp_Study* anActiveStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
262   if (!anActiveStudy) return;
263
264   LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
265   if (!aSelMgr) return;
266
267   // get selection
268   SALOME_ListIO aList;
269   //aSelMgr->selectedObjects(aList);
270   aSelMgr->selectedObjects(aList, "ObjectBrowser", false);
271   SALOME_ListIteratorOfListIO It (aList);
272
273   SUIT_OverrideCursor wc;
274
275   for (; It.More(); It.Next()) {
276     Handle(SALOME_InteractiveObject) anIObject = It.Value();
277     if (anIObject->hasEntry()) {
278       _PTR(SObject) SO (anActiveStudy->studyDS()->FindObjectID(anIObject->getEntry()));
279       if (SO) {
280         _PTR(SComponent) SC (SO->GetFatherComponent());
281         if (QString(SO->GetID().c_str()) == QString(SO->GetFatherComponent()->GetID().c_str())) {
282           // if component is selected, pass it
283         }
284         else {
285           _PTR(ChildIterator) anIter (anActiveStudy->studyDS()->NewChildIterator(SO));
286           anIter->InitEx(true);
287           while (anIter->More()) {
288             _PTR(SObject) valSO (anIter->Value());
289             _PTR(SObject) refSO;
290             if (!valSO->ReferencedObject(refSO)) {
291               listIO.Append(new SALOME_InteractiveObject(valSO->GetID().c_str(),
292                                                          SC->ComponentDataType().c_str(),
293                                                          valSO->GetName().c_str()));
294             }
295             anIter->Next();
296           }
297         }
298       }
299     }
300   }
301   GEOM_Displayer(anActiveStudy).Display(listIO, true);
302 }
303
304 //=====================================================================================
305 // function : DisplayGUI::Display()
306 // purpose  : Display selected GEOM objects
307 //=====================================================================================
308 void DisplayGUI::Display()
309 {
310   SALOME_ListIO listIO;
311
312   SalomeApp_Application* app = getGeometryGUI()->getApp();
313   if ( !app ) return;
314
315   SalomeApp_Study* anActiveStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
316   if ( !anActiveStudy ) return;
317
318   //get SalomeApp selection manager
319   LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
320   if ( !aSelMgr ) return;
321
322   SALOME_ListIO aList;
323   aSelMgr->selectedObjects( aList );
324   SALOME_ListIteratorOfListIO It( aList );
325
326   SUIT_OverrideCursor wc;
327
328   for( ;It.More();It.Next() ) {
329     Handle(SALOME_InteractiveObject) anIObject = It.Value();
330     if ( anIObject->hasEntry() ) {
331       _PTR(SObject) SO ( anActiveStudy->studyDS()->FindObjectID( anIObject->getEntry() ) );
332       if ( SO && QString(SO->GetID().c_str()) == QString(SO->GetFatherComponent()->GetID().c_str()) ) {
333         _PTR(SComponent) SC ( SO->GetFatherComponent() );
334         // if component is selected
335         listIO.Clear();
336         _PTR(ChildIterator) anIter ( anActiveStudy->studyDS()->NewChildIterator( SO ) );
337         anIter->InitEx( true );
338         while( anIter->More() ) {
339           _PTR(SObject) valSO ( anIter->Value() );
340           _PTR(SObject) refSO;
341           if ( !valSO->ReferencedObject( refSO ) ) {
342             listIO.Append( new SALOME_InteractiveObject(valSO->GetID().c_str(),
343                                                         SC->ComponentDataType().c_str(),
344                                                         valSO->GetName().c_str()) );
345           }
346           anIter->Next();
347         }
348         break;
349       }
350       else {
351         listIO.Append( anIObject );
352       }
353     }
354     else {
355       listIO.Append( anIObject );
356     }
357   }
358   GEOM_Displayer( anActiveStudy ).Display( listIO, true );
359 }
360
361
362 //=====================================================================================
363 // function : DisplayGUI::Erase()
364 // purpose  : Erase selected GEOM objects
365 //=====================================================================================
366 void DisplayGUI::Erase()
367 {
368   SALOME_ListIO listIO;
369
370   SalomeApp_Application* app = getGeometryGUI()->getApp();
371   if ( !app ) return;
372
373   SalomeApp_Study* anActiveStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
374   if ( !anActiveStudy ) return;
375
376   //get SalomeApp selection manager
377   LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
378   if ( !aSelMgr ) return;
379
380   SALOME_ListIO aList;
381   aSelMgr->selectedObjects( aList );
382   SALOME_ListIteratorOfListIO It( aList );
383
384   SUIT_OverrideCursor wc;
385
386   for( ; It.More(); It.Next() ) {
387     Handle(SALOME_InteractiveObject) anIObject = It.Value();
388     if ( anIObject->hasEntry() ) {
389       _PTR(SObject) SO ( anActiveStudy->studyDS()->FindObjectID( anIObject->getEntry() ) );
390       if ( SO && QString(SO->GetID().c_str()) == QString(SO->GetFatherComponent()->GetID().c_str()) ) {
391         _PTR(SComponent) SC ( SO->GetFatherComponent() );
392         // if component is selected
393         listIO.Clear();
394         _PTR(ChildIterator) anIter ( anActiveStudy->studyDS()->NewChildIterator( SO ) );
395         anIter->InitEx( true );
396         while( anIter->More() ) {
397           _PTR(SObject) valSO ( anIter->Value() );
398           _PTR(SObject) refSO;
399           if ( !valSO->ReferencedObject( refSO ) ) {
400             listIO.Append( new SALOME_InteractiveObject(valSO->GetID().c_str(),
401                                                         SC->ComponentDataType().c_str(),
402                                                         valSO->GetName().c_str()) );
403           }
404           anIter->Next();
405         }
406         break;
407       }
408       else {
409         listIO.Append( anIObject );
410       }
411     }
412     else {
413       listIO.Append( anIObject );
414     }
415   }
416
417   SUIT_ViewWindow* viewWindow = app->desktop()->activeWindow();
418   bool aIsForced = true;
419   if(viewWindow->getViewManager()->getType() == SVTK_Viewer::Type())
420     aIsForced = false;
421
422   GEOM_Displayer(anActiveStudy).Erase( listIO, aIsForced);
423   getGeometryGUI()->getApp()->selectionMgr()->clearSelected();
424 }
425
426 //=====================================================================================
427 // function : DisplayGUI::SetDisplayMode()
428 // purpose  : Set display mode for the viewer (current viewer if <viewWindow> - 0 )
429 //=====================================================================================
430 void DisplayGUI::SetDisplayMode( const int mode, SUIT_ViewWindow* viewWindow )
431 {
432   SUIT_OverrideCursor wc;
433
434   SalomeApp_Application* app = getGeometryGUI()->getApp();
435   if ( !app ) return;
436
437   if ( !viewWindow ) 
438     viewWindow = app->desktop()->activeWindow();
439
440   SalomeApp_Study* aStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
441   if ( !aStudy ) return;
442
443   GEOM_Displayer displayer( aStudy );
444
445   int mgrId = viewWindow->getViewManager()->getGlobalId();
446
447   SALOME_View* window = displayer.GetActiveView();
448   if ( !window ) return;
449
450   SALOME_ListIO anIOlst;
451   window->GetVisible( anIOlst );
452
453   for ( SALOME_ListIteratorOfListIO It( anIOlst ); It.More(); It.Next() ) {
454     Handle( SALOME_InteractiveObject ) io = It.Value();
455     aStudy->setObjectProperty( mgrId, io->getEntry(), GEOM::propertyName( GEOM::DisplayMode ), mode );
456     displayer.Redisplay( io, false );
457   }
458   displayer.UpdateViewer();
459   GeometryGUI::Modified();
460 }
461
462 //=====================================================================================
463 // function : DisplayGUI::SetVectorsMode()
464 // purpose  : Set vector mode for the viewer
465 //=====================================================================================
466 void DisplayGUI::SetVectorMode( const bool mode, SUIT_ViewWindow* viewWindow )
467 {
468   SUIT_OverrideCursor wc;
469
470   SalomeApp_Application* app = getGeometryGUI()->getApp();
471   if ( !app ) return;
472
473   SalomeApp_Study* aStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
474   if ( !aStudy ) return;
475
476   if ( !viewWindow ) 
477     viewWindow = app->desktop()->activeWindow();
478
479   GEOM_Displayer displayer( aStudy );
480
481   viewWindow->setProperty( "VectorsMode", mode );
482
483   int aMgrId = viewWindow->getViewManager()->getGlobalId();
484
485   SALOME_View* window = displayer.GetActiveView();
486   if ( !window ) return;
487
488   SALOME_ListIO anIOlst;
489   window->GetVisible( anIOlst );
490
491   for ( SALOME_ListIteratorOfListIO It( anIOlst ); It.More(); It.Next() ) {
492     Handle( SALOME_InteractiveObject ) io = It.Value();
493     aStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::EdgesDirection ), mode );
494     displayer.Redisplay( io, false );
495   }
496   displayer.UpdateViewer();
497   GeometryGUI::Modified();
498 }
499
500 //=====================================================================================
501 // function : DisplayGUI::GetVectorMode()
502 // purpose  : Get the "show edge direction" mode of the viewer
503 //=====================================================================================
504 int DisplayGUI::GetVectorMode( SUIT_ViewWindow* viewWindow )
505 {
506   if ( !viewWindow ) 
507     viewWindow = getGeometryGUI()->getApp()->desktop()->activeWindow();
508   return viewWindow->property( "VectorsMode" ).toBool();
509 }
510
511 //=====================================================================================
512 // function : DisplayGUI::SetVerticesMode()
513 // purpose  : Set vertices mode for the viewer
514 //=====================================================================================
515 void DisplayGUI::SetVerticesMode( const bool mode, SUIT_ViewWindow* viewWindow )
516 {
517   SUIT_OverrideCursor wc;
518
519   SalomeApp_Application* app = getGeometryGUI()->getApp();
520   if ( !app ) return;
521
522   SalomeApp_Study* aStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
523   if ( !aStudy ) return;
524
525   if ( !viewWindow ) 
526     viewWindow = app->desktop()->activeWindow();
527
528   GEOM_Displayer displayer( aStudy );
529
530   viewWindow->setProperty( "VerticesMode", mode );
531
532   int aMgrId = viewWindow->getViewManager()->getGlobalId();
533
534   SALOME_View* window = displayer.GetActiveView();
535   if ( !window ) return;
536
537   SALOME_ListIO anIOlst;
538   window->GetVisible( anIOlst );
539
540   for ( SALOME_ListIteratorOfListIO It( anIOlst ); It.More(); It.Next() ) {
541     Handle( SALOME_InteractiveObject ) io = It.Value();
542     aStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::Vertices ), mode );
543     displayer.Redisplay( io, false );
544   }
545   displayer.UpdateViewer();
546   GeometryGUI::Modified();
547 }
548
549 //=====================================================================================
550 // function : DisplayGUI::GetVerticesMode()
551 // purpose  : Get the "show vertices" mode of the viewer
552 //=====================================================================================
553 int DisplayGUI::GetVerticesMode( SUIT_ViewWindow* viewWindow )
554 {
555   if ( !viewWindow ) 
556     viewWindow = getGeometryGUI()->getApp()->desktop()->activeWindow();
557   return viewWindow->property( "VerticesMode" ).toBool();
558 }
559
560 //=====================================================================================
561 // function : DisplayGUI::SetNameMode()
562 // purpose  : Set name mode for the viewer
563 //=====================================================================================
564 void DisplayGUI::SetNameMode( const bool mode, SUIT_ViewWindow* viewWindow )
565 {
566   SUIT_OverrideCursor();
567
568   SalomeApp_Application* app = getGeometryGUI()->getApp();
569   if ( !app ) return;
570
571   SalomeApp_Study* aStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
572   if ( !aStudy ) return;
573
574   if ( !viewWindow )
575     viewWindow = app->desktop()->activeWindow();
576
577   viewWindow->setProperty( "NameMode", mode );
578
579   GEOM_Displayer displayer( aStudy );
580
581   int aMgrId = viewWindow->getViewManager()->getGlobalId();
582
583   SALOME_View* window = displayer.GetActiveView();
584   if ( !window ) return;
585
586   SALOME_ListIO anIOlst;
587   window->GetVisible( anIOlst );
588
589   for ( SALOME_ListIteratorOfListIO It( anIOlst ); It.More(); It.Next() ) {
590     Handle( SALOME_InteractiveObject ) io = It.Value();
591     aStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::ShowName ), mode );
592     displayer.Redisplay( io, false );
593   }
594   displayer.UpdateViewer();
595   GeometryGUI::Modified();
596 }
597
598 //=====================================================================================
599 // function : DisplayGUI::GetNameMode()
600 // purpose  : Get the "show name" mode of the viewer
601 //=====================================================================================
602 int DisplayGUI::GetNameMode( SUIT_ViewWindow* viewWindow )
603 {
604   if ( !viewWindow )
605     viewWindow = getGeometryGUI()->getApp()->desktop()->activeWindow();
606   return viewWindow->property( "NameMode" ).toBool();
607 }
608
609 //=====================================================================================
610 // function : DisplayGUI::ChangeDisplayMode()
611 // purpose  : Set display mode for selected objects in the viewer given
612 //            (current viewer if <viewWindow> = 0 )
613 //=====================================================================================
614 void DisplayGUI::ChangeDisplayMode( const int mode, SUIT_ViewWindow* viewWindow )
615 {
616   SalomeApp_Application* app = getGeometryGUI()->getApp();
617   if ( !app ) return;
618
619   if ( !viewWindow ) 
620     viewWindow = app->desktop()->activeWindow();
621
622   LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
623   if ( !aSelMgr ) return;
624
625   SalomeApp_Study* aStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
626   if ( !aStudy ) return;
627
628   SUIT_OverrideCursor wc;
629
630   SALOME_ListIO selected;
631   aSelMgr->selectedObjects( selected );
632   if ( selected.IsEmpty() ) return;
633
634   GEOM_Displayer displayer( aStudy );
635
636   int mgrId = viewWindow->getViewManager()->getGlobalId();
637
638   QVariant v = aStudy->getObjectProperty( mgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::EdgesDirection ), QVariant() );
639   bool vectorMode =  v.isValid() ? !v.toBool() : false;
640   v = aStudy->getObjectProperty( mgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::Vertices ), QVariant() );
641   bool verticesMode =  v.isValid() ? !v.toBool() : false;
642   v = aStudy->getObjectProperty( mgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::ShowName ), QVariant() );
643   bool nameMode =  v.isValid() ? !v.toBool() : false;
644
645   for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
646     Handle( SALOME_InteractiveObject ) io = It.Value();
647     if ( mode == 0 || mode == 1 || mode == 2 || mode == 3 ) {
648       aStudy->setObjectProperty( mgrId, io->getEntry(), GEOM::propertyName( GEOM::DisplayMode ), mode );
649     }
650     else if ( mode == 4 ) {
651       aStudy->setObjectProperty( mgrId, io->getEntry(), GEOM::propertyName( GEOM::EdgesDirection ), vectorMode );
652     }
653     else if ( mode == 5 ) {
654       aStudy->setObjectProperty( mgrId, io->getEntry(), GEOM::propertyName( GEOM::Vertices ), verticesMode );
655     }
656     else if ( mode == 6 ) {
657       aStudy->setObjectProperty( mgrId, io->getEntry(), GEOM::propertyName( GEOM::ShowName ), nameMode );
658     }
659     displayer.Redisplay( io, false );
660   }
661   displayer.UpdateViewer();
662   GeometryGUI::Modified();
663 }
664
665 //=====================================================================================
666 // EXPORTED METHODS
667 //=====================================================================================
668 extern "C"
669 {
670 #ifdef WIN32
671   __declspec( dllexport )
672 #endif
673   GEOMGUI* GetLibGUI( GeometryGUI* parent )
674   {
675     return new DisplayGUI( parent );
676   }
677 }