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