Salome HOME
Issue 0020336: [CEA 339] specifying a cut line with 2 points
[modules/visu.git] / src / VISUGUI / VisuGUI_Selection.cxx
1 //  Copyright (C) 2007-2008  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.
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 //  VISU VISUGUI : GUI of VISU component
23 //  File   : VisuGUI_Selection.cxx
24 //  Author : Sergey Anikin 
25 //  Module : VISU
26 //
27 #include "VisuGUI_Selection.h"
28
29 #include "VisuGUI_ViewTools.h"
30 #include "VisuGUI_Tools.h"
31
32 #include "VISU_Result_i.hh"
33 #include "VISU_Gen_i.hh"
34
35 #include "VISU_Actor.h"
36 #include "VISU_ScalarMapAct.h"
37 #include "VISU_GaussPtsAct.h"
38
39 #include "SalomeApp_Study.h"
40 #include "LightApp_Study.h"
41 #include "LightApp_Displayer.h"
42
43 using namespace VISU;
44
45 //////////////////////////////////////////////////
46 // Class: VisuGUI_Selection
47 //////////////////////////////////////////////////
48
49
50 //---------------------------------------------------------------
51 QVariant VisuGUI_Selection::parameter( const int ind, const QString& p ) const
52 {
53   QVariant val( LightApp_Selection::parameter( ind, p ) );
54   if ( !val.isValid() ) {
55     if      ( p == "type"           ) val = QVariant( type( ind ) );
56     else if ( p == "nbComponents"   ) val = QVariant( nbComponents( ind ) );
57     else if ( p == "medEntity"   ) val = QVariant( medEntity( ind ) );
58     else if ( p == "medSource"   ) val = QVariant( medSource( ind ) );
59     else if ( p == "representation" ) val = QVariant( representation( ind ) );
60     else if ( p == "nbTimeStamps"   ) val = QVariant( nbTimeStamps( ind ) );
61     else if ( p == "nbChildren"     ) val = QVariant( nbChildren( ind ) );
62     else if ( p == "nbNamedChildren") val = QVariant( nbNamedChildren( ind ) );
63     else if ( p == "isVisible"      ) val = QVariant( isVisible( ind ) );
64     else if ( p == "isShrunk"       ) val = QVariant( isShrunk( ind ) );
65     else if ( p == "hasActor"       ) val = QVariant( hasActor( ind ) );
66     else if ( p == "isShading"      ) val = QVariant( isShading( ind ) );
67     else if ( p == "isScalarMapAct" ) val = QVariant( isScalarMapAct( ind ) );
68     else if ( p == "isGaussPtsAct" ) val = QVariant( isGaussPtsAct( ind ) );
69     else if ( p == "isVisuComponent") val = QVariant( isVisuComponent( ind ) );
70     else if ( p == "fullResolution"   ) val = QVariant( fullResolution( ind ) );
71     else if ( p == "mediumResolution"   ) val = QVariant( mediumResolution( ind ) );
72     else if ( p == "lowResolution"   ) val = QVariant( lowResolution( ind ) );
73     else if ( p == "resolutionState"   ) val = QVariant( resolutionState( ind ) );
74     else if ( p == "isThereAreVisibleCurves" ) val = QVariant( findDisplayedCurves( ind, false ) );
75     else if ( p == "isThereAreHiddenCurves" ) val = QVariant( findDisplayedCurves( ind, true ) );
76     else if ( p == "hasCurves"      ) val = QVariant( hasCurves( ind ) );
77     else if ( p == "isPlot2dViewer"      ) val = QVariant( Plot2dViewerType( ind ) );
78     else if ( p == "isValuesLabeled"  ) val = QVariant( isValuesLabeled( ind ) );
79     else if ( p == "isScalarBarVisible" ) val = QVariant( isScalarBarVisible( ind ) );
80     else if ( p == "quadratic2DMode" ) val = QVariant( quadratic2DMode(ind) );
81   }
82
83   return val;
84 }
85
86
87 //---------------------------------------------------------------
88 // Macro for converting VISU enumeration items into corresponding strings
89 #define ENUM2STRING( x, y ) \
90   case y: \
91     x = QString( #y ); \
92     break
93
94 QString VisuGUI_Selection::type( const int ind ) const
95 {
96   QString aResStr;
97   SalomeApp_Study* aStudy = GetStudy();
98   if ( !aStudy )
99     return aResStr;
100
101   VISU::TObjectInfo anObjectInfo = VISU::GetObjectByEntry(aStudy, (const char*)entry( ind ).toLatin1());
102   VISU::Storable::TRestoringMap aMap = VISU::Storable::GetStorableMap(anObjectInfo.mySObject);
103
104   VISU::Base_i* aBase = anObjectInfo.myBase;
105   if(aBase){
106     VISU::VISUType aType = aBase->GetType();
107     if(aType == VISU::TCOLOREDPRS3DHOLDER){
108       CORBA::Object_var anObject = ClientSObjectToObject(anObjectInfo.mySObject);
109       VISU::ColoredPrs3dHolder_var aHolder = VISU::ColoredPrs3dHolder::_narrow(anObject);
110       aType = aHolder->GetPrsType();
111     }
112     switch (aType) {
113       ENUM2STRING( aResStr, VISU::TVISUGEN );
114       ENUM2STRING( aResStr, VISU::TRESULT );
115       ENUM2STRING( aResStr, VISU::TTABLE );
116       ENUM2STRING( aResStr, VISU::TCURVE );
117       ENUM2STRING( aResStr, VISU::TCONTAINER );
118       ENUM2STRING( aResStr, VISU::TMESH );
119       ENUM2STRING( aResStr, VISU::TSCALARMAP );
120       ENUM2STRING( aResStr, VISU::TISOSURFACES );
121       ENUM2STRING( aResStr, VISU::TDEFORMEDSHAPE );
122       ENUM2STRING( aResStr, VISU::TSCALARMAPONDEFORMEDSHAPE );
123       ENUM2STRING( aResStr, VISU::TCUTPLANES );
124       ENUM2STRING( aResStr, VISU::TCUTLINES );
125       ENUM2STRING( aResStr, VISU::TCUTSEGMENT );
126       ENUM2STRING( aResStr, VISU::TVECTORS );
127       ENUM2STRING( aResStr, VISU::TSTREAMLINES );
128       ENUM2STRING( aResStr, VISU::TPLOT3D );
129       ENUM2STRING( aResStr, VISU::TANIMATION );
130       ENUM2STRING( aResStr, VISU::TPOINTMAP3D );
131     }
132   }
133
134   if(aResStr.isNull()){
135     VISU::VISUType aType = VISU::Storable::RestoringMap2Type(aMap);
136     switch (aType) {
137       ENUM2STRING( aResStr, VISU::TENTITY );
138       ENUM2STRING( aResStr, VISU::TFAMILY );
139       ENUM2STRING( aResStr, VISU::TGROUP );
140       ENUM2STRING( aResStr, VISU::TVIEW3D );
141       ENUM2STRING( aResStr, VISU::TFIELD );
142       ENUM2STRING( aResStr, VISU::TTIMESTAMP );
143     }
144   }
145
146   if(aResStr.isNull()){
147     bool anIsExist;
148     QString aVal = VISU::Storable::FindValue(aMap, "myComment", &anIsExist);
149     if ( anIsExist && aVal != "MESH" )
150       aResStr = "VISU::T" + aVal;
151   }
152
153   return aResStr;
154 }
155
156
157 //---------------------------------------------------------------
158 QString VisuGUI_Selection::nbComponents( const int ind ) const
159 {
160   QString aResStr;
161   SalomeApp_Study* aStudy = GetStudy();
162   if ( !aStudy )
163     return aResStr;
164
165   VISU::TObjectInfo anObjectInfo = VISU::GetObjectByEntry(aStudy, (const char*)entry( ind ).toLatin1());
166   VISU::Storable::TRestoringMap aMap = VISU::Storable::GetStorableMap(anObjectInfo.mySObject);
167
168   bool isExist;
169   QString aVal = VISU::Storable::FindValue(aMap,"myNumComponent",&isExist);
170   if ( isExist )
171     aResStr = aVal;
172   return aResStr;
173 }
174
175
176 //---------------------------------------------------------------
177 QString VisuGUI_Selection::resolutions( const int ind ) const
178 {
179   QString aResStr;
180   SalomeApp_Study* aStudy = GetStudy();
181   if ( !aStudy )
182     return aResStr;
183
184   VISU::TObjectInfo anObjectInfo = VISU::GetObjectByEntry(aStudy, entry( ind ).toLatin1().data());
185   VISU::Storable::TRestoringMap aMap = VISU::Storable::GetStorableMap(anObjectInfo.mySObject);
186
187   bool isExist;
188   QString aVal = VISU::Storable::FindValue(aMap,"myResolutions",&isExist);
189   if ( isExist )
190     aResStr = aVal;
191
192   return aResStr;
193 }
194
195
196 //---------------------------------------------------------------
197 QString VisuGUI_Selection::resolution( const int ind, char theResoltuion ) const
198 {
199   QString aResStr;
200
201   QString aResolutions = resolutions( ind );
202   if(aResolutions.isEmpty())
203     return aResStr;
204   
205   if(aResolutions.indexOf(theResoltuion) != -1)
206     aResStr = "1";
207   else
208     aResStr = "0";
209
210   return aResStr;
211 }
212
213
214 //---------------------------------------------------------------
215 QString VisuGUI_Selection::fullResolution( const int ind ) const
216 {
217   return resolution( ind, 'F');
218 }
219
220
221 //---------------------------------------------------------------
222 QString VisuGUI_Selection::mediumResolution( const int ind ) const
223 {
224   return resolution( ind, 'M');
225 }
226
227
228 //---------------------------------------------------------------
229 QString VisuGUI_Selection::lowResolution( const int ind ) const
230 {
231   return resolution( ind, 'L');
232 }
233
234
235 //---------------------------------------------------------------
236 QString VisuGUI_Selection::resolutionState( const int ind ) const
237 {
238   QString aResStr;
239   SalomeApp_Study* aStudy = GetStudy();
240   if ( !aStudy )
241     return aResStr;
242
243   VISU::TObjectInfo anObjectInfo = VISU::GetObjectByEntry(aStudy, entry( ind ).toLatin1().data());
244   VISU::Storable::TRestoringMap aMap = VISU::Storable::GetStorableMap(anObjectInfo.mySObject);
245
246   bool isExist;
247   QString aVal = VISU::Storable::FindValue(aMap,"myState",&isExist);
248   if ( isExist ) {
249     if ( aVal.toInt() == VISU::Result::FULL )
250       aResStr = "F";
251     if ( aVal.toInt() == VISU::Result::MEDIUM )
252       aResStr = "M";
253     if ( aVal.toInt() == VISU::Result::LOW )
254       aResStr = "L";
255     if ( aVal.toInt() == VISU::Result::HIDDEN )
256       aResStr = "H";
257   }
258
259   return aResStr;
260 }
261
262
263 //---------------------------------------------------------------
264 QString VisuGUI_Selection::medEntity( const int ind ) const
265 {
266   SalomeApp_Study* aStudy = GetStudy();
267   if ( !aStudy )
268     return QString();
269
270   VISU::TObjectInfo anObjectInfo = VISU::GetObjectByEntry(aStudy, (const char*)entry( ind ).toLatin1());
271   VISU::Storable::TRestoringMap aMap = VISU::Storable::GetStorableMap(anObjectInfo.mySObject);
272
273   bool isExist;
274   QString aVal = VISU::Storable::FindValue(aMap,"myEntityId",&isExist);
275   if ( isExist ) {
276     using namespace VISU;
277     TEntity anEntityId = TEntity(aVal.toInt());
278     switch(anEntityId){
279     case NODE_ENTITY :
280       return "NODE_ENTITY";
281     case EDGE_ENTITY :
282       return "EDGE_ENTITY";
283     case FACE_ENTITY :
284       return "FACE_ENTITY";
285     case CELL_ENTITY :
286       return "CELL_ENTITY";
287     default:
288       return QString();
289     }
290   }
291   return QString();
292 }
293
294 QString VisuGUI_Selection::medSource( const int ind ) const
295 {
296   _PTR(Study) aStudyDS = GetStudy()->studyDS();
297   if(_PTR(SObject) aSObject = aStudyDS->FindObjectID((const char*)entry(ind).toLatin1())){
298     VISU::Result_var aRes;
299     if(VISU::Result_i* aResult = CheckResult(myModule,aSObject,aRes)){
300       using namespace VISU;
301       Result_i::ECreationId aCreationId = aResult->GetCreationId();
302       switch(aCreationId){
303       case Result_i::eImportFile :
304         return "eImportFile";
305       case Result_i::eCopyAndImportFile :
306         return "eCopyAndImportFile";
307       case Result_i::eImportMed :
308         return "eImportMed";
309       case Result_i::eImportMedField :
310         return "eImportMedField";
311       default:
312         return QString();
313       }      
314     }
315   }
316   return QString();
317 }
318
319 QString VisuGUI_Selection::nbTimeStamps( const int ind ) const
320 {
321   QString aResStr;
322   SalomeApp_Study* aStudy = GetStudy();
323   if ( !aStudy )
324     return aResStr;
325
326   VISU::TObjectInfo anObjectInfo = VISU::GetObjectByEntry(aStudy, (const char*)entry( ind ).toLatin1());
327   VISU::Storable::TRestoringMap aMap = VISU::Storable::GetStorableMap(anObjectInfo.mySObject);
328
329   bool isExist;
330   const QString& aVal = VISU::Storable::FindValue(aMap,"myNbTimeStamps",&isExist);
331   if ( isExist )
332     aResStr = aVal;
333   return aResStr;
334 }
335
336
337 //----------------------------------------------------------------------------
338 template<class TPopupFunctor>
339 struct TPopupDispatcher
340 {
341   QString
342   operator()(const SalomeApp_Module* theModule, 
343              const QString& theEntry)
344   {
345     if(SUIT_ViewManager* aViewManager = theModule->getApp()->activeViewManager()){
346       QString aType = aViewManager->getType();
347       TPopupFunctor aFunctor;
348       if(aType == SVTK_Viewer::Type())
349         return aFunctor.template Get<SVTK_Viewer>(theModule, theEntry);
350       //else if(aType == VVTK_Viewer::Type())
351       //return aFunctor.template Get<VVTK_Viewer>(theModule, theEntry);
352     }
353     return QString();
354   }    
355 };
356
357
358 //----------------------------------------------------------------------------
359 template<class TViewer>
360 bool
361 GetPrs3dSelectionInfo(const SalomeApp_Module* theModule,
362                       const QString& theEntry,
363                       VISU::Prs3d_i*& thePrs3d,
364                       SVTK_ViewWindow*& theViewWindow,
365                       VISU_Actor*& thenActor)
366 {
367   VISU::TObjectInfo anObjectInfo = VISU::GetObjectByEntry(GetAppStudy(theModule), (const char*)theEntry.toLatin1());
368   thePrs3d = GetPrs3dFromBase(anObjectInfo.myBase);
369   if(!thePrs3d)
370     return false;
371   
372   typedef typename TViewer::TViewWindow TViewWindow;
373   theViewWindow = GetActiveViewWindow<TViewWindow>(theModule);
374   if(!theViewWindow)
375     return false;
376   
377   thenActor = FindActor(theViewWindow, thePrs3d);
378   if(!thenActor)
379     return false;
380   
381   return true;
382 }
383
384
385 //----------------------------------------------------------------------------
386 struct TViewFunctor
387 {
388   template<class TViewer>
389   QString
390   Get(const SalomeApp_Module* theModule, 
391       const QString& theEntry)
392   {
393     VISU_Actor* anActor = NULL;
394     VISU::Prs3d_i* aPrs3d = NULL;
395     VISU_ActorBase* anActorBase = NULL;
396     VISU::PointMap3d_i* aPointMap3d = NULL;
397     SVTK_ViewWindow* aViewWindow = NULL;
398     if(GetPrs3dSelectionInfo<TViewer>(theModule, theEntry, aPrs3d, aViewWindow, anActor))
399       return get(aPrs3d, aViewWindow, anActor);
400     else {
401       aViewWindow = GetActiveViewWindow<SVTK_ViewWindow>(theModule);
402       VISU::TSelectionInfo aSelectionInfo = VISU::GetSelectedObjects(theModule);
403       if ( aSelectionInfo.empty() )
404         return QString();
405       VISU::TSelectionItem aSelectionItem = aSelectionInfo.front();
406       aPointMap3d = dynamic_cast<VISU::PointMap3d_i*>(aSelectionItem.myObjectInfo.myBase);
407       anActorBase = VISU::FindActorBase(aViewWindow, aPointMap3d);
408       return getPointMap(aPointMap3d, aViewWindow, anActorBase);
409     }
410   }
411   
412   QString
413   virtual
414   get(VISU::Prs3d_i* thePrs3d,
415       SVTK_ViewWindow* theViewWindow,
416       VISU_Actor* theActor)
417   {
418     return QString();
419   }
420
421   QString
422   virtual
423   getPointMap(VISU::PointMap3d_i* thePrs3d,
424               SVTK_ViewWindow* theViewWindow,
425               VISU_ActorBase* theActor)
426   {
427     return QString();
428   }
429 };
430
431
432 //----------------------------------------------------------------------------
433 struct TGetRepesentationFunctor: TViewFunctor
434 {
435   QString
436   virtual
437   get(VISU::Prs3d_i* thePrs3d,
438       SVTK_ViewWindow* theViewWindow,
439       VISU_Actor* theActor)
440   {
441     QString aResStr;
442     switch (theActor->GetRepresentation()) {
443       ENUM2STRING( aResStr, VISU::POINT );
444       ENUM2STRING( aResStr, VISU::WIREFRAME );
445       ENUM2STRING( aResStr, VISU::SHADED );
446       ENUM2STRING( aResStr, VISU::INSIDEFRAME );
447       ENUM2STRING( aResStr, VISU::SURFACEFRAME );
448       ENUM2STRING( aResStr, VISU::FEATURE_EDGES );
449     }
450     return aResStr;
451   }
452
453   QString
454   virtual
455   getPointMap(VISU::PointMap3d_i* thePrs3d,
456               SVTK_ViewWindow* theViewWindow,
457               VISU_ActorBase* theActorBase)
458   {
459     QString aResStr = "";
460     if (theActorBase) {
461       switch (theActorBase->GetRepresentation()) {
462         ENUM2STRING( aResStr, VISU::WIREFRAME ); // = 1
463         ENUM2STRING( aResStr, VISU::SHADED ); // = 2
464       }
465     }
466     return aResStr;
467   }
468 };
469
470 QString VisuGUI_Selection::representation( const int ind ) const
471 {
472   return TPopupDispatcher<TGetRepesentationFunctor>()(myModule, entry(ind));
473 }
474
475 //----------------------------------------------------------------------------
476 SalomeApp_Study* VisuGUI_Selection::GetStudy() const
477   
478 {
479   LightApp_Study* aLightStudy = const_cast<LightApp_Study*>( study() );
480   return dynamic_cast<SalomeApp_Study*>( aLightStudy );
481 }
482
483 //----------------------------------------------------------------------------
484 int VisuGUI_Selection::nbChild( const int ind, const bool named ) const
485 {
486   int cnt = 0;
487   SalomeApp_Study* aSStudy = GetStudy();
488   if ( !aSStudy )
489     return cnt;
490   _PTR(Study) aStudy =  GetCStudy( aSStudy );
491   if ( aStudy ){
492     _PTR(SObject) SO = aStudy->FindObjectID( (const char*)entry( ind ).toLatin1() );
493     if ( SO ){
494       for ( _PTR(ChildIterator) Iter = aStudy->NewChildIterator( SO ); Iter->More(); Iter->Next() ) {
495         _PTR(SObject) refSO;
496         if ( !Iter->Value()->ReferencedObject( refSO ) && ( !named || Iter->Value()->GetName().size() ) )
497           cnt++;
498       }
499     }
500   }
501   return cnt;
502 }
503
504 //----------------------------------------------------------------------------
505 int VisuGUI_Selection::nbChildren( const int ind ) const
506 {
507   return nbChild( ind, false );
508 }
509
510 //----------------------------------------------------------------------------
511 int VisuGUI_Selection::nbNamedChildren( const int ind ) const
512 {
513   return nbChild( ind, true );
514 }
515
516
517 //----------------------------------------------------------------------------
518 struct TIsVisibleFunctor: TViewFunctor
519 {
520   QString
521   virtual
522   get(VISU::Prs3d_i* thePrs3d,
523       SVTK_ViewWindow* theViewWindow,
524       VISU_Actor* theActor)
525   {
526     return theActor->GetVisibility() ? "true" : "false";
527   }
528 };
529
530 QString VisuGUI_Selection::isVisible( const int ind ) const
531 {
532   return TPopupDispatcher<TIsVisibleFunctor>()(myModule, entry(ind));
533 }
534
535
536 //----------------------------------------------------------------------------
537 struct TIsShrunkFunctor: TViewFunctor
538 {
539   QString
540   virtual
541   get(VISU::Prs3d_i* thePrs3d,
542       SVTK_ViewWindow* theViewWindow,
543       VISU_Actor* theActor)
544   {
545     return theActor->IsShrunk() ? "1" : "0";
546   }
547
548   QString
549   virtual
550   getPointMap(VISU::PointMap3d_i* thePointMap,
551               SVTK_ViewWindow* theViewWindow,
552               VISU_ActorBase* theActorBase)
553   {
554     if (theActorBase)
555       return theActorBase->IsShrunk() ? "1" : "0";
556     else return "0";
557   }
558 };
559
560 QString VisuGUI_Selection::isShrunk( const int ind ) const
561 {
562   return TPopupDispatcher<TIsShrunkFunctor>()(myModule, entry(ind));
563 }
564
565
566 //----------------------------------------------------------------------------
567 bool VisuGUI_Selection::hasActor( const int ind ) const
568 {
569   return !representation( ind ).isEmpty();
570 }
571
572
573 //----------------------------------------------------------------------------
574 struct TIsShadingFunctor: TViewFunctor
575 {
576   QString
577   virtual
578   get(VISU::Prs3d_i* thePrs3d,
579       SVTK_ViewWindow* theViewWindow,
580       VISU_Actor* theActor)
581   {
582     if(VISU_ScalarMapAct* anActor = dynamic_cast<VISU_ScalarMapAct*>(theActor))
583       return anActor->IsShading() ? "1" : "0";
584     return QString();
585   }
586 };
587
588 QString VisuGUI_Selection::isShading( const int ind ) const
589 {
590   return TPopupDispatcher<TIsShadingFunctor>()(myModule, entry(ind));
591 }
592
593
594 //----------------------------------------------------------------------------
595 struct TIsScalarMapActFunctor: TViewFunctor
596 {
597   QString
598   virtual
599   get(VISU::Prs3d_i* thePrs3d,
600       SVTK_ViewWindow* theViewWindow,
601       VISU_Actor* theActor)
602   {
603     return dynamic_cast<VISU_ScalarMapAct*>(theActor)? "1" : "0";
604   }
605 };
606
607
608 //---------------------------------------------------------------
609 QString VisuGUI_Selection::isScalarMapAct( const int ind ) const
610 {
611   return TPopupDispatcher<TIsScalarMapActFunctor>()(myModule, entry(ind));
612 }
613
614 //----------------------------------------------------------------------------
615 struct TIsGaussPtsActFunctor: TViewFunctor
616 {
617   QString
618   virtual
619   get(VISU::Prs3d_i* thePrs3d,
620       SVTK_ViewWindow* theViewWindow,
621       VISU_Actor* theActor)
622   {
623     return dynamic_cast<VISU_GaussPtsAct*>(theActor)? "1" : "0";
624   }
625 };
626
627
628 //---------------------------------------------------------------
629 QString VisuGUI_Selection::isGaussPtsAct( const int ind ) const
630 {
631   return TPopupDispatcher<TIsGaussPtsActFunctor>()(myModule, entry(ind));
632 }
633
634 //----------------------------------------------------------------------------
635 bool VisuGUI_Selection::isVisuComponent( const int ind ) const
636 {
637   SalomeApp_Study* study = GetStudy();
638   if ( !study )
639     return false;
640   
641   _PTR(SObject) obj = study->studyDS()->FindObjectID( (const char*)entry( ind ).toLatin1() );
642   if ( !obj )
643     return false;
644   CORBA::Object_var anObj = VISU::ClientSObjectToObject( obj );
645   if( CORBA::is_nil( anObj ) )
646     return false;
647
648   return dynamic_cast<VISU::VISU_Gen_i*>( VISU::GetServant( anObj ).in() );
649 }
650
651 //---------------------------------------------------------------------------
652 bool VisuGUI_Selection::findDisplayedCurves( const int ind, bool findHidden ) const
653 {
654   // findHidden == false - find at least one Visible curve in the childs of ind
655   // findHidden == true - find at least one Hidden curve in the childs of ind
656   SalomeApp_Study* aSStudy = GetStudy();
657   if ( !aSStudy )
658     return false;
659
660   QString entryId;
661   _PTR(Study) aStudy = GetCStudy( aSStudy );
662   if ( aStudy ){
663     _PTR(SObject) SO = aStudy->FindObjectID( (const char*) entry( ind ).toLatin1() );
664     if ( SO ){
665       for ( _PTR(ChildIterator) Iter = aStudy->NewChildIterator( SO ); Iter->More(); Iter->Next() ) {
666         _PTR(SObject) refSO;
667         if ( Iter->Value()->ReferencedObject(refSO) )
668           entryId = refSO->GetID().c_str();
669         else
670           entryId = Iter->Value()->GetID().c_str();
671
672         LightApp_Displayer* displayer = LightApp_Displayer::FindDisplayer( myModule->moduleName(), false );
673         if ( displayer->IsDisplayed( entryId ) && findHidden == false )
674           return true;
675         else if ( !displayer->IsDisplayed( entryId ) && findHidden == true )
676           return true;
677       }
678     }
679   }
680   return false;
681 }
682
683 //---------------------------------------------------------------------------
684 bool VisuGUI_Selection::hasCurves( const int ind ) const
685 {
686   SalomeApp_Study* aSStudy = GetStudy();
687   if ( !aSStudy )
688     return false;
689
690   QString entryId;
691   _PTR(Study) aStudy = GetCStudy( aSStudy );
692   if ( aStudy ){
693     _PTR(SObject) SO = aStudy->FindObjectID( (const char*) entry( ind ).toLatin1() );
694     if ( SO ){
695       for ( _PTR(ChildIterator) Iter = aStudy->NewChildIterator( SO ); Iter->More(); Iter->Next() ) {
696         _PTR(SObject) refSO;
697         if ( Iter->Value()->ReferencedObject(refSO) ) {
698           // reference on curve
699         }
700         else
701           refSO = Iter->Value();
702
703         CORBA::Object_var aCORBAObject = VISU::ClientSObjectToObject(refSO);
704         if(!CORBA::is_nil(aCORBAObject)){
705           PortableServer::ServantBase_var aServant = VISU::GetServant(aCORBAObject);
706           if(dynamic_cast<VISU::Curve_i*>(aServant.in()))
707             return true;
708         }
709       }
710     }
711   }
712   return false;
713 }
714
715 //---------------------------------------------------------------------------
716 bool VisuGUI_Selection::Plot2dViewerType( const int ind ) const
717 {
718   QString viewerType;
719   SUIT_Session* session = SUIT_Session::session();
720   if(  SUIT_Application* app = session->activeApplication() )
721     if( LightApp_Application* sApp = dynamic_cast<LightApp_Application*>( app ) )
722       if( SUIT_ViewManager* vman = sApp->activeViewManager() )
723         if( SUIT_ViewModel* vmod = vman->getViewModel() ) {
724           viewerType = vmod->getType();
725           if (viewerType ==SPlot2d_Viewer::Type())
726             return true;
727         }
728   return false;
729 }
730
731 //----------------------------------------------------------------------------
732 struct TIsValuesLabeled : TViewFunctor
733 {
734   QString
735   virtual
736   get(VISU::Prs3d_i* thePrs3d,
737       SVTK_ViewWindow* theViewWindow,
738       VISU_Actor* theActor)
739   {
740     return theActor && theActor->GetValuesLabeled() ? "true" : "false";
741   }
742 };
743
744 QString VisuGUI_Selection::isValuesLabeled( const int ind ) const
745 {
746   return TPopupDispatcher<TIsValuesLabeled>()(myModule, entry(ind));
747 }
748
749 //----------------------------------------------------------------------------
750 struct TIsScalarBarVisibleFunctor: TViewFunctor
751 {
752   QString
753   virtual
754   get(VISU::Prs3d_i* thePrs3d,
755       SVTK_ViewWindow* theViewWindow,
756       VISU_Actor* theActor)
757   {
758     if(VISU_ScalarMapAct* anActor = dynamic_cast<VISU_ScalarMapAct*>(theActor))
759       return anActor->GetBarVisibility() ? "true" : "false";
760     else if ( VISU_GaussPtsAct* anActor = dynamic_cast<VISU_GaussPtsAct*>(theActor))
761       return anActor->GetBarVisibility() ? "true" : "false";
762     return QString();
763   }
764 };
765
766 bool VisuGUI_Selection::isScalarBarVisible( const int ind ) const
767 {
768   return TPopupDispatcher<TIsScalarBarVisibleFunctor>()(myModule, entry(ind)) == "true";
769 }
770
771 struct TGetQuadratic2DRepresentation: TViewFunctor
772 {
773   QString virtual get (VISU::Prs3d_i* thePrs3d,
774                        SVTK_ViewWindow* theViewWindow,
775                        VISU_Actor* theActor)
776   {
777     if(theActor->GetQuadratic2DRepresentation() == VISU_Actor::eLines)
778       return "VISU::LINES";
779     else if (theActor->GetQuadratic2DRepresentation() == VISU_Actor::eArcs)
780       return "VISU::ARCS";
781     
782     return QString();
783   }
784 };
785
786
787 QString VisuGUI_Selection::quadratic2DMode( const int ind) const
788 {
789   return TPopupDispatcher<TGetQuadratic2DRepresentation>()(myModule, entry(ind));
790 }