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