]> SALOME platform Git repositories - modules/geom.git/blob - src/DisplayGUI/DisplayGUI.cxx
Salome HOME
0022777: [CEA 1291] Display the name of an object in the 3D View
[modules/geom.git] / src / DisplayGUI / DisplayGUI.cxx
1 // Copyright (C) 2007-2015  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   case GEOMOp::OpShowName:       // POPUP MENU - DISPLAY MODE - SHOW NAME
168     ChangeDisplayMode( 6 );
169     break;
170   default:
171     app->putInfo(tr("GEOM_PRP_COMMAND").arg(theCommandID));
172     break;
173   }
174   Sel->setSelectedObjects( selected );
175   GEOM_Displayer( appStudy ).UpdateColorScale();
176   return true;
177 }
178
179 //=====================================================================================
180 // function : DisplayGUI::DisplayAll()
181 // purpose  : Display all GEOM objects
182 //=====================================================================================
183 void DisplayGUI::DisplayAll()
184 {
185   SalomeApp_Application* app = getGeometryGUI()->getApp();
186   if ( !app ) return;
187
188   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
189   if ( !appStudy ) return;
190   _PTR(Study) aStudy = appStudy->studyDS();
191   if ( !aStudy ) return;
192   _PTR(SComponent) SC ( aStudy->FindComponent( "GEOM" ) );
193   if ( !SC )
194     return;
195
196   SALOME_ListIO listIO;
197   _PTR(ChildIterator) anIter ( aStudy->NewChildIterator( SC ) );
198   anIter->InitEx( true );
199
200   SUIT_OverrideCursor wc;
201
202   while( anIter->More() ) {
203     _PTR(SObject) valSO ( anIter->Value() );
204     _PTR(SObject) refSO;
205     if ( !valSO->ReferencedObject( refSO ) ) {
206       listIO.Append( new SALOME_InteractiveObject(valSO->GetID().c_str(),
207                                                   SC->ComponentDataType().c_str(),
208                                                   valSO->GetName().c_str()) );
209     } 
210     anIter->Next();
211   }
212   GEOM_Displayer( appStudy ).Display( listIO, true );
213 }
214
215 //=====================================================================================
216 // function : DisplayGUI::EraseAll()
217 // purpose  : Erase all GEOM objects
218 //=====================================================================================
219 void DisplayGUI::EraseAll()
220 {
221   SUIT_OverrideCursor wc;
222
223   SUIT_Application* app = getGeometryGUI()->getApp();
224   if ( app ) {
225     SUIT_ViewWindow* vw = app->desktop()->activeWindow();
226     if ( vw ) {
227       SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
228       SUIT_ViewManager* vman = vw->getViewManager();
229       if ( vman->getType() == OCCViewer_Viewer::Type() || 
230            vman->getType() == SVTK_Viewer::Type() ) {
231         GEOM_Displayer( appStudy ).EraseAll(true);
232       }
233     }
234   }
235 }
236
237 //=====================================================================================
238 // function : DisplayGUI::DisplayOnly()
239 // purpose  : Display selected GEOM objects and erase other
240 //=====================================================================================
241 void DisplayGUI::DisplayOnly()
242 {
243   EraseAll();
244   Display();
245 }
246
247 //=====================================================================================
248 // function : DisplayGUI::DisplayOnlyChildren()
249 // purpose  : Display only children of selected GEOM objects and erase other
250 //=====================================================================================
251 void DisplayGUI::DisplayOnlyChildren()
252 {
253   EraseAll();
254
255   SALOME_ListIO listIO;
256
257   SalomeApp_Application* app = getGeometryGUI()->getApp();
258   if (!app) return;
259
260   SalomeApp_Study* anActiveStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
261   if (!anActiveStudy) return;
262
263   LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
264   if (!aSelMgr) return;
265
266   // get selection
267   SALOME_ListIO aList;
268   //aSelMgr->selectedObjects(aList);
269   aSelMgr->selectedObjects(aList, "ObjectBrowser", false);
270   SALOME_ListIteratorOfListIO It (aList);
271
272   SUIT_OverrideCursor wc;
273
274   for (; It.More(); It.Next()) {
275     Handle(SALOME_InteractiveObject) anIObject = It.Value();
276     if (anIObject->hasEntry()) {
277       _PTR(SObject) SO (anActiveStudy->studyDS()->FindObjectID(anIObject->getEntry()));
278       if (SO) {
279         _PTR(SComponent) SC (SO->GetFatherComponent());
280         if (QString(SO->GetID().c_str()) == QString(SO->GetFatherComponent()->GetID().c_str())) {
281           // if component is selected, pass it
282         }
283         else {
284           _PTR(ChildIterator) anIter (anActiveStudy->studyDS()->NewChildIterator(SO));
285           anIter->InitEx(true);
286           while (anIter->More()) {
287             _PTR(SObject) valSO (anIter->Value());
288             _PTR(SObject) refSO;
289             if (!valSO->ReferencedObject(refSO)) {
290               listIO.Append(new SALOME_InteractiveObject(valSO->GetID().c_str(),
291                                                          SC->ComponentDataType().c_str(),
292                                                          valSO->GetName().c_str()));
293             }
294             anIter->Next();
295           }
296         }
297       }
298     }
299   }
300   GEOM_Displayer(anActiveStudy).Display(listIO, true);
301 }
302
303 //=====================================================================================
304 // function : DisplayGUI::Display()
305 // purpose  : Display selected GEOM objects
306 //=====================================================================================
307 void DisplayGUI::Display()
308 {
309   SALOME_ListIO listIO;
310
311   SalomeApp_Application* app = getGeometryGUI()->getApp();
312   if ( !app ) return;
313
314   SalomeApp_Study* anActiveStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
315   if ( !anActiveStudy ) return;
316
317   //get SalomeApp selection manager
318   LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
319   if ( !aSelMgr ) return;
320
321   SALOME_ListIO aList;
322   aSelMgr->selectedObjects( aList );
323   SALOME_ListIteratorOfListIO It( aList );
324
325   SUIT_OverrideCursor wc;
326
327   for( ;It.More();It.Next() ) {
328     Handle(SALOME_InteractiveObject) anIObject = It.Value();
329     if ( anIObject->hasEntry() ) {
330       _PTR(SObject) SO ( anActiveStudy->studyDS()->FindObjectID( anIObject->getEntry() ) );
331       if ( SO && QString(SO->GetID().c_str()) == QString(SO->GetFatherComponent()->GetID().c_str()) ) {
332         _PTR(SComponent) SC ( SO->GetFatherComponent() );
333         // if component is selected
334         listIO.Clear();
335         _PTR(ChildIterator) anIter ( anActiveStudy->studyDS()->NewChildIterator( SO ) );
336         anIter->InitEx( true );
337         while( anIter->More() ) {
338           _PTR(SObject) valSO ( anIter->Value() );
339           _PTR(SObject) refSO;
340           if ( !valSO->ReferencedObject( refSO ) ) {
341             listIO.Append( new SALOME_InteractiveObject(valSO->GetID().c_str(),
342                                                         SC->ComponentDataType().c_str(),
343                                                         valSO->GetName().c_str()) );
344           }
345           anIter->Next();
346         }
347         break;
348       }
349       else {
350         listIO.Append( anIObject );
351       }
352     }
353     else {
354       listIO.Append( anIObject );
355     }
356   }
357   GEOM_Displayer( anActiveStudy ).Display( listIO, true );
358 }
359
360
361 //=====================================================================================
362 // function : DisplayGUI::Erase()
363 // purpose  : Erase selected GEOM objects
364 //=====================================================================================
365 void DisplayGUI::Erase()
366 {
367   SALOME_ListIO listIO;
368
369   SalomeApp_Application* app = getGeometryGUI()->getApp();
370   if ( !app ) return;
371
372   SalomeApp_Study* anActiveStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
373   if ( !anActiveStudy ) return;
374
375   //get SalomeApp selection manager
376   LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
377   if ( !aSelMgr ) return;
378
379   SALOME_ListIO aList;
380   aSelMgr->selectedObjects( aList );
381   SALOME_ListIteratorOfListIO It( aList );
382
383   SUIT_OverrideCursor wc;
384
385   for( ; It.More(); It.Next() ) {
386     Handle(SALOME_InteractiveObject) anIObject = It.Value();
387     if ( anIObject->hasEntry() ) {
388       _PTR(SObject) SO ( anActiveStudy->studyDS()->FindObjectID( anIObject->getEntry() ) );
389       if ( SO && QString(SO->GetID().c_str()) == QString(SO->GetFatherComponent()->GetID().c_str()) ) {
390         _PTR(SComponent) SC ( SO->GetFatherComponent() );
391         // if component is selected
392         listIO.Clear();
393         _PTR(ChildIterator) anIter ( anActiveStudy->studyDS()->NewChildIterator( SO ) );
394         anIter->InitEx( true );
395         while( anIter->More() ) {
396           _PTR(SObject) valSO ( anIter->Value() );
397           _PTR(SObject) refSO;
398           if ( !valSO->ReferencedObject( refSO ) ) {
399             listIO.Append( new SALOME_InteractiveObject(valSO->GetID().c_str(),
400                                                         SC->ComponentDataType().c_str(),
401                                                         valSO->GetName().c_str()) );
402           }
403           anIter->Next();
404         }
405         break;
406       }
407       else {
408         listIO.Append( anIObject );
409       }
410     }
411     else {
412       listIO.Append( anIObject );
413     }
414   }
415
416   SUIT_ViewWindow* viewWindow = app->desktop()->activeWindow();
417   bool aIsForced = true;
418   if(viewWindow->getViewManager()->getType() == SVTK_Viewer::Type())
419     aIsForced = false;
420
421   GEOM_Displayer(anActiveStudy).Erase( listIO, aIsForced);
422   getGeometryGUI()->getApp()->selectionMgr()->clearSelected();
423 }
424
425 //=====================================================================================
426 // function : DisplayGUI::SetDisplayMode()
427 // purpose  : Set display mode for the viewer (current viewer if <viewWindow> - 0 )
428 //=====================================================================================
429 void DisplayGUI::SetDisplayMode( const int mode, SUIT_ViewWindow* viewWindow )
430 {
431   SUIT_OverrideCursor wc;
432
433   SalomeApp_Application* app = getGeometryGUI()->getApp();
434   if ( !app ) return;
435
436   if ( !viewWindow ) 
437     viewWindow = app->desktop()->activeWindow();
438
439   SalomeApp_Study* aStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
440   if ( !aStudy ) return;
441
442   GEOM_Displayer displayer( aStudy );
443
444   int mgrId = viewWindow->getViewManager()->getGlobalId();
445
446   SALOME_ListIO anIOlst;
447   displayer.GetActiveView()->GetVisible( anIOlst );
448
449   for ( SALOME_ListIteratorOfListIO It( anIOlst ); It.More(); It.Next() ) {
450     Handle( SALOME_InteractiveObject ) io = It.Value();
451     aStudy->setObjectProperty( mgrId, io->getEntry(), GEOM::propertyName( GEOM::DisplayMode ), mode );
452     displayer.Redisplay( io, false );
453   }
454   displayer.UpdateViewer();
455   GeometryGUI::Modified();
456 }
457
458 //=====================================================================================
459 // function : DisplayGUI::SetVectorsMode()
460 // purpose  : Set vector mode for the viewer
461 //=====================================================================================
462 void DisplayGUI::SetVectorMode( const bool mode, SUIT_ViewWindow* viewWindow )
463 {
464   SUIT_OverrideCursor wc;
465
466   SalomeApp_Application* app = getGeometryGUI()->getApp();
467   if ( !app ) return;
468
469   SalomeApp_Study* aStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
470   if ( !aStudy ) return;
471
472   if ( !viewWindow ) 
473     viewWindow = app->desktop()->activeWindow();
474
475   GEOM_Displayer displayer( aStudy );
476
477   viewWindow->setProperty( "VectorsMode", mode );
478
479   int aMgrId = viewWindow->getViewManager()->getGlobalId();
480
481   SALOME_ListIO anIOlst;
482   displayer.GetActiveView()->GetVisible( anIOlst );
483
484   for ( SALOME_ListIteratorOfListIO It( anIOlst ); It.More(); It.Next() ) {
485     Handle( SALOME_InteractiveObject ) io = It.Value();
486     aStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::EdgesDirection ), mode );
487     displayer.Redisplay( io, false );
488   }
489   displayer.UpdateViewer();
490   GeometryGUI::Modified();
491 }
492
493 //=====================================================================================
494 // function : DisplayGUI::GetVectorMode()
495 // purpose  : Get the "show edge direction" mode of the viewer
496 //=====================================================================================
497 int DisplayGUI::GetVectorMode( SUIT_ViewWindow* viewWindow )
498 {
499   if ( !viewWindow ) 
500     viewWindow = getGeometryGUI()->getApp()->desktop()->activeWindow();
501   return viewWindow->property( "VectorsMode" ).toBool();
502 }
503
504 //=====================================================================================
505 // function : DisplayGUI::SetVerticesMode()
506 // purpose  : Set vertices mode for the viewer
507 //=====================================================================================
508 void DisplayGUI::SetVerticesMode( const bool mode, SUIT_ViewWindow* viewWindow )
509 {
510   SUIT_OverrideCursor wc;
511
512   SalomeApp_Application* app = getGeometryGUI()->getApp();
513   if ( !app ) return;
514
515   SalomeApp_Study* aStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
516   if ( !aStudy ) return;
517
518   if ( !viewWindow ) 
519     viewWindow = app->desktop()->activeWindow();
520
521   GEOM_Displayer displayer( aStudy );
522
523   viewWindow->setProperty( "VerticesMode", mode );
524
525   int aMgrId = viewWindow->getViewManager()->getGlobalId();
526
527   SALOME_ListIO anIOlst;
528   displayer.GetActiveView()->GetVisible( anIOlst );
529
530   for ( SALOME_ListIteratorOfListIO It( anIOlst ); It.More(); It.Next() ) {
531     Handle( SALOME_InteractiveObject ) io = It.Value();
532     aStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::Vertices ), mode );
533     displayer.Redisplay( io, false );
534   }
535   displayer.UpdateViewer();
536   GeometryGUI::Modified();
537 }
538
539 //=====================================================================================
540 // function : DisplayGUI::GetVerticesMode()
541 // purpose  : Get the "show vertices" mode of the viewer
542 //=====================================================================================
543 int DisplayGUI::GetVerticesMode( SUIT_ViewWindow* viewWindow )
544 {
545   if ( !viewWindow ) 
546     viewWindow = getGeometryGUI()->getApp()->desktop()->activeWindow();
547   return viewWindow->property( "VerticesMode" ).toBool();
548 }
549
550 //=====================================================================================
551 // function : DisplayGUI::SetNameMode()
552 // purpose  : Set name mode for the viewer
553 //=====================================================================================
554 void DisplayGUI::SetNameMode( const bool mode, SUIT_ViewWindow* viewWindow )
555 {
556   SUIT_OverrideCursor();
557
558   SalomeApp_Application* app = getGeometryGUI()->getApp();
559   if ( !app ) return;
560
561   SalomeApp_Study* aStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
562   if ( !aStudy ) return;
563
564   if ( !viewWindow )
565     viewWindow = app->desktop()->activeWindow();
566
567   viewWindow->setProperty( "NameMode", mode );
568
569   GEOM_Displayer displayer( aStudy );
570
571   int aMgrId = viewWindow->getViewManager()->getGlobalId();
572
573   SALOME_ListIO anIOlst;
574   displayer.GetActiveView()->GetVisible( anIOlst );
575
576   for ( SALOME_ListIteratorOfListIO It( anIOlst ); It.More(); It.Next() ) {
577     Handle( SALOME_InteractiveObject ) io = It.Value();
578     aStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::ShowName ), mode );
579     displayer.Redisplay( io, false );
580   }
581   displayer.UpdateViewer();
582   GeometryGUI::Modified();
583 }
584
585 //=====================================================================================
586 // function : DisplayGUI::GetNameMode()
587 // purpose  : Get the "show name" mode of the viewer
588 //=====================================================================================
589 int DisplayGUI::GetNameMode( SUIT_ViewWindow* viewWindow )
590 {
591   if ( !viewWindow )
592     viewWindow = getGeometryGUI()->getApp()->desktop()->activeWindow();
593   return viewWindow->property( "NameMode" ).toBool();
594 }
595
596 //=====================================================================================
597 // function : DisplayGUI::ChangeDisplayMode()
598 // purpose  : Set display mode for selected objects in the viewer given
599 //            (current viewer if <viewWindow> = 0 )
600 //=====================================================================================
601 void DisplayGUI::ChangeDisplayMode( const int mode, SUIT_ViewWindow* viewWindow )
602 {
603   SalomeApp_Application* app = getGeometryGUI()->getApp();
604   if ( !app ) return;
605
606   if ( !viewWindow ) 
607     viewWindow = app->desktop()->activeWindow();
608
609   LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
610   if ( !aSelMgr ) return;
611
612   SalomeApp_Study* aStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
613   if ( !aStudy ) return;
614
615   SUIT_OverrideCursor wc;
616
617   SALOME_ListIO selected;
618   aSelMgr->selectedObjects( selected );
619   if ( selected.IsEmpty() ) return;
620
621   GEOM_Displayer displayer( aStudy );
622
623   int mgrId = viewWindow->getViewManager()->getGlobalId();
624
625   QVariant v = aStudy->getObjectProperty( mgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::EdgesDirection ), QVariant() );
626   bool vectorMode =  v.isValid() ? !v.toBool() : false;
627   v = aStudy->getObjectProperty( mgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::Vertices ), QVariant() );
628   bool verticesMode =  v.isValid() ? !v.toBool() : false;
629   v = aStudy->getObjectProperty( mgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::ShowName ), QVariant() );
630   bool nameMode =  v.isValid() ? !v.toBool() : false;
631
632   for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
633     Handle( SALOME_InteractiveObject ) io = It.Value();
634     if ( mode == 0 || mode == 1 || mode == 2 || mode == 3 ) {
635       aStudy->setObjectProperty( mgrId, io->getEntry(), GEOM::propertyName( GEOM::DisplayMode ), mode );
636     }
637     else if ( mode == 4 ) {
638       aStudy->setObjectProperty( mgrId, io->getEntry(), GEOM::propertyName( GEOM::EdgesDirection ), vectorMode );
639     }
640     else if ( mode == 5 ) {
641       aStudy->setObjectProperty( mgrId, io->getEntry(), GEOM::propertyName( GEOM::Vertices ), verticesMode );
642     }
643     else if ( mode == 6 ) {
644       aStudy->setObjectProperty( mgrId, io->getEntry(), GEOM::propertyName( GEOM::ShowName ), nameMode );
645     }
646     displayer.Redisplay( io, false );
647   }
648   displayer.UpdateViewer();
649   GeometryGUI::Modified();
650 }
651
652 //=====================================================================================
653 // EXPORTED METHODS
654 //=====================================================================================
655 extern "C"
656 {
657 #ifdef WIN32
658   __declspec( dllexport )
659 #endif
660   GEOMGUI* GetLibGUI( GeometryGUI* parent )
661   {
662     return new DisplayGUI( parent );
663   }
664 }