]> SALOME platform Git repositories - modules/visu.git/blob - src/VISUGUI/VisuGUI_Tools.cxx
Salome HOME
208b8a1a81bd440b3756c6528645ecd581d4b2b9
[modules/visu.git] / src / VISUGUI / VisuGUI_Tools.cxx
1 //  VISU VISUGUI : GUI of VISU component
2 //
3 //  Copyright (C) 2005  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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
21 //
22 //
23 //
24 //  File   : VisuGUI_Tools.cxx
25 //  Author : Sergey Anikin
26 //  Module : VISU
27
28
29 #include "VisuGUI_Tools.h"
30
31 #include "VISU_Gen_i.hh"
32 #include "VISU_Prs3d_i.hh"
33 #include "VISU_Result_i.hh"
34 #include "VISU_Table_i.hh"
35 #include "VISU_Mesh_i.hh"
36 #include "VISU_ViewManager_i.hh"
37
38 #include "VISU_Actor.h"
39
40 #include "SalomeApp_Module.h"
41 #include "SalomeApp_Study.h"
42 #include "SalomeApp_Application.h"
43 #include "SalomeApp_SelectionMgr.h"
44
45 #include "SALOME_ListIO.hxx"
46 #include "SALOME_ListIteratorOfListIO.hxx"
47
48 #include "SVTK_ViewWindow.h"
49 #include "SVTK_ViewModel.h"
50 #include "SVTK_Functor.h"
51
52 #include "VTKViewer_Algorithm.h"
53
54 #include "SPlot2d_ViewModel.h"
55 #include "Plot2d_ViewFrame.h"
56
57 #include "SUIT_Session.h"
58 #include "SUIT_MessageBox.h"
59
60 #include <vtkRenderer.h>
61 #include <vtkActorCollection.h>
62
63
64 //=============================================================================
65 namespace VISU
66 {
67   SUIT_Desktop*
68   GetDesktop(const CAM_Module* theModule)
69   {
70     return theModule->application()->desktop();
71   }
72
73   SalomeApp_SelectionMgr*
74   GetSelectionMgr(const SalomeApp_Module* theModule)
75   {
76     return theModule->getApp()->selectionMgr();
77   }
78
79   SalomeApp_Study*
80   GetAppStudy(const CAM_Module* theModule)
81   {
82     return
83       dynamic_cast<SalomeApp_Study*>(theModule->application()->activeStudy());
84   }
85
86   _PTR(Study)
87   GetCStudy(const SalomeApp_Study* theStudy)
88   {
89     return theStudy->studyDS();
90   }
91
92   bool
93   IsStudyLocked( _PTR(Study) theStudy )
94   {
95     if( theStudy )
96       return theStudy->GetProperties()->IsLocked();
97     return true;
98   }
99
100   bool
101   CheckLock( _PTR(Study) theStudy )
102   {
103     if(IsStudyLocked(theStudy))
104       throw std::runtime_error(QObject::tr("WRN_STUDY_LOCKED").latin1());
105     return false;
106   }
107
108   VISU_Gen_i*
109   GetVisuGen(const CAM_Module* theModule)
110   {
111     static VISU_Gen_i* aGen = NULL;
112     if(!aGen){
113       SALOME_LifeCycleCORBA aLCC(SalomeApp_Application::namingService());
114       Engines::Component_var aComponent = aLCC.FindOrLoad_Component("FactoryServer","VISU");
115       VISU_Gen_var aVISU = VISU_Gen::_narrow(aComponent);
116       if(!CORBA::is_nil(aVISU)){
117         aGen = VISU_Gen_i::GetVisuGenImpl();
118         aGen->SetCurrentStudy(GetDSStudy(GetCStudy(GetAppStudy(theModule))));
119       }
120     }
121     if(!aGen)
122       throw std::runtime_error(QObject::tr("ERR_CANT_FIND_VISU_COMPONENT").latin1());
123     return aGen;
124   }
125
126   SALOME_MED::MED_Gen_var
127   GetMEDEngine()
128   {
129     static SALOME_MED::MED_Gen_var aGen;
130     if(CORBA::is_nil(aGen)){
131       SALOME_LifeCycleCORBA aLCC(SalomeApp_Application::namingService());
132       Engines::Component_var aComponent = aLCC.FindOrLoad_Component("FactoryServer","MED");
133       aGen = SALOME_MED::MED_Gen::_narrow(aComponent);
134     }
135     if(CORBA::is_nil(aGen))
136       throw std::runtime_error(QObject::tr("ERR_CANT_FIND_MED_COMPONENT").latin1());
137     return aGen;
138   }
139
140
141   VISU::Storable::TRestoringMap getMapOfValue (_PTR(SObject) theSObject)
142   {
143     VISU::Storable::TRestoringMap aMap;
144     if (theSObject) {
145       _PTR(GenericAttribute) anAttr;
146       if (theSObject->FindAttribute(anAttr, "AttributeComment")) {
147         _PTR(AttributeComment) aComment (anAttr);
148         std::string aValue = aComment->Value();
149         QString aString (aValue.c_str());
150         VISU::Storable::StrToMap(aString, aMap);
151       }
152     }
153     return aMap;
154   }
155
156   QString getValue (_PTR(SObject) theSObject, QString theKey)
157   {
158     QString aStr("");
159     VISU::Storable::TRestoringMap aMap = getMapOfValue(theSObject);
160     if (!aMap.empty())
161       aStr = VISU::Storable::FindValue(aMap, theKey.latin1());
162     return aStr;
163   }
164
165   //------------------------------------------------------------
166   // Selection
167   CORBA::Object_var
168   GetSelectedObj(const SalomeApp_Study* theStudy,
169                  const QString& theEntry,
170                  VISU::Storable::TRestoringMap* theMap)
171   {
172     if (!theStudy || theEntry.isEmpty())
173       return CORBA::Object::_nil();
174
175     _PTR(Study) aStudy = GetCStudy(theStudy);
176     _PTR(SObject) aSObject = aStudy->FindObjectID(theEntry.latin1());
177     if (aSObject) {
178       _PTR(GenericAttribute) anAttr;
179       if (theMap && aSObject->FindAttribute(anAttr,"AttributeComment")) {
180         _PTR(AttributeComment) aComment (anAttr);
181         std::string aValue = aComment->Value();
182         QString aString (aValue.c_str());
183         VISU::Storable::StrToMap(aString, *theMap);
184       }
185       return VISU::ClientSObjectToObject(aSObject);
186     }
187     return CORBA::Object::_nil();
188   }
189
190   CORBA::Object_var
191   GetSelectedObj(const SalomeApp_Module* theModule,
192                  Handle(SALOME_InteractiveObject)* theIO,
193                  VISU::Storable::TRestoringMap* theMap)
194   {
195     SalomeApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(theModule);
196     SALOME_ListIO aListIO;
197     aSelectionMgr->selectedObjects(aListIO);
198     SALOME_ListIteratorOfListIO anIter(aListIO);
199     if(anIter.More()){
200       Handle(SALOME_InteractiveObject) anIO = anIter.Value();
201       if(theIO)
202         *theIO = anIO;
203       if(anIO->hasEntry())
204         return GetSelectedObj( GetAppStudy(theModule), anIO->getEntry(), theMap );
205     }
206     return CORBA::Object::_nil();
207   }
208
209   VISU::Prs3d_i*
210   GetPrsToModify(const SalomeApp_Module* theModule,
211                  Handle(SALOME_InteractiveObject)* theIO,
212                  VISU::Storable::TRestoringMap* theMap)
213   {
214     if (CheckLock(GetCStudy(GetAppStudy(theModule))))
215       return NULL;
216
217     CORBA::Object_var anObject = GetSelectedObj(theModule, theIO);
218     if (CORBA::is_nil(anObject))
219       return NULL;
220
221     PortableServer::ServantBase_var aServant = VISU::GetServant(anObject);
222     if (!aServant.in())
223       return NULL;
224
225     return dynamic_cast<VISU::Prs3d_i*>(aServant.in());
226   }
227
228   void
229   Add(SalomeApp_SelectionMgr* theSelectionMgr,
230       const Handle(SALOME_InteractiveObject)& theIO)
231   {
232     SALOME_ListIO aListIO;
233     theSelectionMgr->selectedObjects(aListIO);
234     aListIO.Append(theIO);
235     theSelectionMgr->setSelectedObjects(aListIO);
236   }
237
238   void
239   Remove(SalomeApp_SelectionMgr* theSelectionMgr,
240          const Handle(SALOME_InteractiveObject)& theIO)
241   {
242     if (theIO.IsNull()) return;
243     SALOME_ListIO aListIO, aNewListIO;
244     theSelectionMgr->selectedObjects(aListIO);
245     SALOME_ListIteratorOfListIO anIter (aListIO);
246     for (; anIter.More(); anIter.Next()) {
247       Handle(SALOME_InteractiveObject) anIO = anIter.Value();
248       if (!anIO->isSame(theIO)) {
249         aNewListIO.Append(theIO);
250       }
251     }
252     theSelectionMgr->setSelectedObjects(aNewListIO);
253   }
254
255   /*!
256    * \brief Check, if "Delete" popup-menu can be put on current selection
257    *
258    * \param theModule - is used to access SelectionManager, Study and VISU_Gen
259    * \retval bool - returns TRUE if all currently selected objects are removable
260    */
261   bool
262   IsRemovableSelected (const SalomeApp_Module* theModule)
263   {
264     SalomeApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(theModule);
265     SALOME_ListIO aListIO;
266     aSelectionMgr->selectedObjects(aListIO);
267
268     if (aListIO.Extent() < 1)
269       return false;
270
271     _PTR(Study) aStudy = GetCStudy(GetAppStudy(theModule));
272     if (!aStudy) return false;
273
274     // In some cases single selection can have its own popup-menu item for deletion
275     /*if (aListIO.Extent() == 1) {
276       Handle(SALOME_InteractiveObject) anIO = aListIO.First();
277       _PTR(SObject) aSObject = aStudy->FindObjectID(anIO->getEntry());
278       if (aSObject) {
279         VISU::VISUType aType = (VISU::VISUType)getValue(aSObject, "myType").toInt();
280         if (aType == VISU::TVIEW3D) {
281           return false; // special case
282         }
283       }
284     }*/
285
286     SALOME_ListIteratorOfListIO anIter (aListIO);
287     for (; anIter.More(); anIter.Next()) {
288       Handle(SALOME_InteractiveObject) anIO = anIter.Value();
289       if (anIO->hasEntry()) {
290         _PTR(SObject) aSObject = aStudy->FindObjectID(anIO->getEntry());
291         VISU::Storable::TRestoringMap pMap;
292         if (aSObject) {
293           CORBA::Object_var aCORBAObject = VISU::ClientSObjectToObject(aSObject);
294           if (!CORBA::is_nil(aCORBAObject)) {
295             VISU::RemovableObject_var aRemovableObj = VISU::RemovableObject::_narrow(aCORBAObject);
296             if (CORBA::is_nil(aRemovableObj)) {
297               // Not removable CORBA object
298               return false;
299             }
300           } else {
301             // Can be removed, if lays directly under VISU
302             // (first sub-level) or is a child of such an object
303             string aNAME, aVisuNAME = GetVisuGen(theModule)->ComponentDataType();
304             _PTR(GenericAttribute) anAttr;
305             _PTR(AttributeComment) aComment;
306
307             bool isUnderVISU = false;
308             _PTR(SObject) aFatherSObject = aSObject->GetFather();
309             if (aFatherSObject->FindAttribute(anAttr, "AttributeComment")) {
310               _PTR(AttributeComment) aComment (anAttr);
311               aNAME = aComment->Value();
312               if (aNAME == aVisuNAME) {
313                 isUnderVISU = true;
314               }
315             }
316             if (!isUnderVISU) {
317               // Not directly under VISU component, check father
318               aCORBAObject = VISU::ClientSObjectToObject(aFatherSObject);
319               if (!CORBA::is_nil(aCORBAObject)) {
320                 // Father has IOR
321                 return false;
322               }
323
324               isUnderVISU = false;
325               aFatherSObject = aFatherSObject->GetFather();
326               if (aFatherSObject->FindAttribute(anAttr, "AttributeComment")) {
327                 _PTR(AttributeComment) aComment (anAttr);
328                 aNAME = aComment->Value();
329                 if (aNAME == aVisuNAME) {
330                   isUnderVISU = true;
331                 }
332               }
333               if (!isUnderVISU) {
334                 // Father is not directly under VISU component
335                 return false;
336               }
337             }
338           }
339         }
340       }
341     }
342     return true;
343   }
344
345   //************************************************************
346   // Display/Erase
347
348   void
349   ErasePrs (const SalomeApp_Module* theModule,
350             CORBA::Object_ptr theObject, bool theUpdate)
351   {
352     if (!CORBA::is_nil(theObject)) {
353       VISU::Base_var aBase = VISU::Base::_narrow(theObject);
354       if (CORBA::is_nil(aBase)) return;
355       VISU::VISUType aType = aBase->GetType();
356       switch (aType) {
357       case VISU::TCURVE:
358         {
359           if (VISU::Curve_i* aCurve = dynamic_cast<VISU::Curve_i*>(VISU::GetServant(aBase).in()))
360             PlotCurve(theModule, aCurve, VISU::eErase );
361           break;
362         }
363       case VISU::TCONTAINER:
364         {
365           if (VISU::Container_i* aContainer = dynamic_cast<VISU::Container_i*>(VISU::GetServant(aBase).in()))
366             PlotContainer(theModule, aContainer, VISU::eErase );
367           break;
368         }
369       case VISU::TTABLE:
370         {
371           if (VISU::Table_i* aTable = dynamic_cast<VISU::Table_i*>(VISU::GetServant(aBase).in()))
372             PlotTable(theModule, aTable, VISU::eErase );
373           break;
374         }
375       default:
376         {
377           if (VISU::Prs3d_i* aPrsObject = dynamic_cast<VISU::Prs3d_i*>(VISU::GetServant(aBase).in())) {
378             ErasePrs3d(theModule, aPrsObject);
379             if (theUpdate) {
380               if (SVTK_ViewWindow* vw = GetViewWindow(theModule))
381                 vw->Repaint();
382             }
383           }
384         }
385       } // switch (aType)
386     }
387   }
388
389   void
390   DeleteSObject (SalomeApp_Module* theModule,
391                  _PTR(Study)       theStudy,
392                  _PTR(SObject)     theSObject)
393   {
394     SalomeApp_Study* study = GetAppStudy( theModule );
395     study->deleteReferencesTo( theSObject );
396
397     _PTR(ChildIterator) aChildIter = theStudy->NewChildIterator(theSObject);
398     for (aChildIter->InitEx(true); aChildIter->More(); aChildIter->Next()) {
399       _PTR(SObject) aChildSObject = aChildIter->Value();
400       study->deleteReferencesTo( aChildSObject );
401       CORBA::Object_var aChildObj = VISU::ClientSObjectToObject(aChildSObject);
402       ErasePrs(theModule, aChildObj);
403     }
404
405     CORBA::Object_var anObj = VISU::ClientSObjectToObject(theSObject);
406     if (!CORBA::is_nil(anObj)) {
407       ErasePrs(theModule, anObj);
408
409       VISU::RemovableObject_var aRemovableObject = VISU::RemovableObject::_narrow(anObj);
410       if (!CORBA::is_nil(aRemovableObject)) {
411         aRemovableObject->RemoveFromStudy();
412       }
413     } else {
414       // Remove aSObject together with all its sub-objects
415
416       VISU::RemoveFromStudy(theSObject,
417                             false,  // remove not only IOR attribute, but Object With Children
418                             false); // not Destroy() sub-objects
419     }
420   }
421
422   void
423   DeletePrs3d(SalomeApp_Module* theModule,
424               VISU::Prs3d_i* thePrs,
425               const Handle(SALOME_InteractiveObject)& theIO)
426   {
427     if (!thePrs)
428       return;
429     if (CheckLock(GetCStudy(GetAppStudy(theModule))))
430       return;
431     SALOMEDS::SObject_var aSObject = thePrs->GetSObject();
432     CORBA::String_var anEntry = aSObject->GetID();
433     SalomeApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(theModule);
434     Remove(aSelectionMgr,theIO);
435     TViewWindows aViewWindows = GetViews(theModule);
436     for(int i = 0, iEnd = aViewWindows.size(); i < iEnd; i++){
437       SVTK_ViewWindow* aView = aViewWindows[i];
438       if(VISU_Actor* anActor = FindActor(aView,anEntry.in())){
439         aView->RemoveActor(anActor);
440         anActor->Delete();
441       }
442     }
443     thePrs->RemoveFromStudy();
444   }
445
446   void
447   ErasePrs3d(const SalomeApp_Module* theModule,
448              VISU::Prs3d_i* thePrs)
449   {
450     if ( SVTK_ViewWindow* vw = GetViewWindow( theModule ) ){
451       VISU_Actor* anVISUActor = FindActor( vw, thePrs );
452       if (anVISUActor) {
453         anVISUActor->VisibilityOff();
454       }
455     }
456   }
457
458   //************************************************************
459   // Presentation management
460
461   void
462   ChangeRepresentation (const SalomeApp_Module* theModule,
463                         VISU::PresentationType  theType)
464   {
465     SUIT_ViewWindow* aView = GetActiveView(theModule, SVTK_Viewer::Type());
466     if (!aView) return;
467     SVTK_ViewWindow* vw  = dynamic_cast<SVTK_ViewWindow*>( aView );
468     if( !vw )
469       return;
470
471     Handle(SALOME_InteractiveObject) anIO;
472     CORBA::Object_var anObject = GetSelectedObj(theModule, &anIO);
473     if (CORBA::is_nil(anObject)) return;
474
475     VISU::Base_var aVisuObj = VISU::Base::_narrow(anObject);
476     if (CORBA::is_nil(aVisuObj)) return;
477
478     PortableServer::ServantBase_var aServant = VISU::GetServant(anObject);
479     if (!aServant.in()) return;
480
481     VISU::Prs3d_i* aPrs3d = dynamic_cast<VISU::Prs3d_i*>(aServant.in());
482     if (aPrs3d) {
483       if (VISU_Actor* anActor = GetActor(aPrs3d, vw)) {
484         switch (theType) {
485         case VISU::SHRINK:
486           if (anActor->IsShrunk())
487             anActor->UnShrink();
488           else
489             anActor->SetShrink();
490           break;
491         default:
492           if (VISU::Mesh_i* aMesh = dynamic_cast<VISU::Mesh_i*>(aPrs3d)) {
493             aMesh->SetPresentationType(theType);
494             RecreateActor(theModule, aMesh);
495           } else {
496             anActor->SetRepresentation(theType);
497           }
498         }
499         vw->Repaint();
500       }
501     }
502   }
503
504   //************************************************************
505   // SObject type
506
507   bool
508   CheckTimeStamp(const SalomeApp_Module* theModule,
509                  _PTR(SObject)&          theSObject,
510                  Handle(SALOME_InteractiveObject)* theIO)
511   {
512     Handle(SALOME_InteractiveObject) anIO;
513     CORBA::Object_var anObject = GetSelectedObj(theModule, &anIO);
514     if (theIO)
515       *theIO = anIO;
516     if (!anIO.IsNull() && anIO->hasEntry()){
517       _PTR(Study) aStudy = GetCStudy(GetAppStudy(theModule));
518       theSObject = aStudy->FindObjectID(anIO->getEntry());
519       QString aValue = getValue(theSObject,"myType");
520       if (aValue.toInt() == int(VISU::TTIMESTAMP))
521         return true;
522     }
523     SUIT_MessageBox::warn1(GetDesktop(theModule),
524                            QObject::tr("WRN_VISU"),
525                            QObject::tr("WRN_NO_AVAILABLE_DATA"),
526                            QObject::tr("BUT_OK") );
527     return false;
528   }
529
530   VISU::Result_i*
531   CheckResult(const SalomeApp_Module* theModule,
532               _PTR(SObject)           theSource,
533               VISU::Result_var&       theResult)
534   {
535     _PTR(SObject) aSObj = theSource->GetFather();
536     if (!aSObj)
537       return NULL;
538
539     aSObj = aSObj->GetFather();
540     if (!aSObj)
541       return NULL;
542
543     aSObj = aSObj->GetFather();
544     if (!aSObj)
545       return NULL;
546
547     CORBA::Object_var anObject = VISU::ClientSObjectToObject(aSObj);
548     if (CORBA::is_nil(anObject)) {
549       aSObj = aSObj->GetFather();
550       if (!aSObj)
551         return NULL;
552       anObject = VISU::ClientSObjectToObject(aSObj);
553     }
554
555     if (CORBA::is_nil(anObject))
556       return NULL;
557
558     theResult = VISU::Result::_narrow(anObject);
559     VISU::Result_i* pResult = dynamic_cast<VISU::Result_i*>(VISU::GetServant(anObject).in());
560     if (pResult == NULL)
561       SUIT_MessageBox::warn1(GetDesktop(theModule),
562                              QObject::tr("WRN_VISU"),
563                              QObject::tr("WRN_NO_AVAILABLE_DATA"),
564                              QObject::tr("BUT_OK"));
565     return pResult;
566   }
567
568   //************************************************************
569   // Views
570
571   SUIT_ViewWindow* GetActiveView(const SalomeApp_Module* theModule, QString theType)
572   {
573     if(SalomeApp_Application* anApp = theModule->getApp()){
574       if(SUIT_ViewManager* aViewManager = anApp->activeViewManager()){
575         if (!theType.isNull()) {
576           if (aViewManager->getType() != theType)
577             return 0;
578         }
579         return aViewManager->getActiveView();
580       }
581     }
582     return 0;
583   }
584
585   //************************************************************
586   // VTK View
587
588   TViewWindows
589   GetViews(const SalomeApp_Module* theModule)
590   {
591     TViewWindows aViewWindows;
592     if(SalomeApp_Application* anApp = theModule->getApp()){
593       ViewManagerList aViewManagerList;
594       anApp->viewManagers(SVTK_Viewer::Type(),aViewManagerList);
595       QPtrListIterator<SUIT_ViewManager> anIter(aViewManagerList);
596       while(SUIT_ViewManager* aViewManager = anIter.current()){
597         QPtrVector<SUIT_ViewWindow> aViews = aViewManager->getViews();
598         for(int i = 0, iEnd = aViews.size(); i < iEnd; i++){
599           if(SUIT_ViewWindow* aViewWindow = aViews.at(i))
600             if(SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewWindow))
601               aViewWindows.push_back(aView);
602         }
603         ++anIter;
604       }
605     }
606     return aViewWindows;
607   }
608
609   SVTK_ViewWindow*
610   GetViewWindow(const SalomeApp_Module* theModule, const bool theCreate )
611   {
612     if(SalomeApp_Application* anApp = theModule->getApp()){
613       if(SUIT_ViewManager* aViewManager = anApp->getViewManager( SVTK_Viewer::Type(), theCreate )){
614         if(SUIT_ViewWindow* aViewWindow = aViewManager->getActiveView()){
615           return dynamic_cast<SVTK_ViewWindow*>(aViewWindow);
616         }
617       }
618     }
619     return NULL;
620   }
621
622
623   SVTK_ViewWindow*
624   GetViewWindow()
625   {
626     SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>
627       (SUIT_Session::session()->activeApplication());
628     if (anApp) {
629       if (SUIT_ViewManager* aViewManager = anApp->activeViewManager()) {
630         if (aViewManager->getType() == SVTK_Viewer::Type()) {
631           if (SUIT_ViewWindow* aViewWindow = aViewManager->getActiveView()) {
632             return dynamic_cast<SVTK_ViewWindow*>(aViewWindow);
633           }
634         }
635       }
636     }
637     return NULL;
638   }
639
640   VISU_Actor*
641   PublishInView(const SalomeApp_Module* theModule,
642                 VISU::Prs3d_i* thePrs)
643   {
644     VISU_Actor* aActor = NULL;
645     if(!thePrs)
646       return aActor;
647     if(SVTK_ViewWindow* aView = GetViewWindow(theModule)){
648       QApplication::setOverrideCursor( Qt::waitCursor );
649       try{
650         if(aActor = thePrs->CreateActor())
651           aView->AddActor(aActor);
652       }catch(std::exception& exc){
653         SUIT_MessageBox::warn1(GetDesktop(theModule),
654                                QObject::tr("WRN_VISU"),
655                                QObject::tr("ERR_CANT_CREATE_ACTOR") + ": " + QObject::tr(exc.what()),
656                                QObject::tr("BUT_OK"));
657       }
658       QApplication::restoreOverrideCursor();
659     }
660     return aActor;
661   }
662
663   VISU_Actor*
664   UpdateViewer(const SalomeApp_Module* theModule,
665                VISU::Prs3d_i* thePrs,
666                bool theDispOnly)
667   {
668     SVTK_ViewWindow* vw = GetViewWindow( theModule );
669     if (!vw) return NULL;
670
671     vtkRenderer *aRen = vw->getRenderer();
672     vtkActorCollection *anActColl = aRen->GetActors();
673
674     vtkActor *anActor;
675     VISU_Actor* anVISUActor = NULL;
676     VISU_Actor* aResActor = NULL;
677     for(anActColl->InitTraversal(); (anActor = anActColl->GetNextActor()) != NULL; ){
678       if(!SALOME_Actor::SafeDownCast(anActor))
679         continue;
680       if(anActor->IsA("VISU_Actor")){
681         anVISUActor = VISU_Actor::SafeDownCast(anActor);
682         VISU::Prs3d_i* aPrs = anVISUActor->GetPrs3d();
683         if(aPrs == NULL) continue;
684         if (thePrs == aPrs) {
685           aResActor = anVISUActor->GetParent();
686           thePrs->UpdateActor(aResActor);
687           aResActor->VisibilityOn();
688
689         } else if (theDispOnly) {
690           anVISUActor->GetParent()->VisibilityOff();
691         } else {
692         }
693       } else if (theDispOnly && anActor->GetVisibility()) {
694         anActor->VisibilityOff();
695       } else {
696       }
697     }
698     if (aResActor)
699       return aResActor;
700
701     anVISUActor = PublishInView( theModule, thePrs );
702     return anVISUActor;
703   }
704
705   void
706   RepaintViewWindows (const SalomeApp_Module* theModule,
707                       const Handle(SALOME_InteractiveObject)& theIObject)
708   {
709     TViewWindows aViewWindows;
710     if (SalomeApp_Application* anApp = theModule->getApp()) {
711       ViewManagerList aViewManagerList;
712       anApp->viewManagers(SVTK_Viewer::Type(),aViewManagerList);
713       QPtrListIterator<SUIT_ViewManager> anIter (aViewManagerList);
714       while (SUIT_ViewManager* aViewManager = anIter.current()) {
715         QPtrVector<SUIT_ViewWindow> aViews = aViewManager->getViews();
716         for (int i = 0, iEnd = aViews.size(); i < iEnd; i++) {
717           if (SUIT_ViewWindow* aViewWindow = aViews.at(i)) {
718             if (SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>(aViewWindow)) {
719               if (vw->isVisible(theIObject)) {
720                 vw->getRenderer()->ResetCameraClippingRange();
721                 vw->Repaint();
722                 vw->highlight(theIObject, true, true);
723               }
724             }
725           }
726         }
727         ++anIter;
728       }
729     }
730   }
731
732   VISU_Actor*
733   FindActor(SVTK_ViewWindow* theViewWindow,
734             const char* theEntry)
735   {
736     using namespace VTK;
737     if(vtkRenderer* aRenderer = theViewWindow->getRenderer()){
738       if(vtkActorCollection* aCollection = aRenderer->GetActors()){
739         if(VISU_Actor* anActor = Find<VISU_Actor>(aCollection,TIsSameEntry<VISU_Actor>(theEntry))){
740           return anActor->GetParent();
741         }
742       }
743     }
744     return NULL;
745   }
746
747   VISU_Actor*
748   FindActor(SVTK_ViewWindow* theViewWindow,
749             VISU::Prs3d_i* thePrs)
750   {
751     SALOMEDS::SObject_var aSObject = thePrs->GetSObject();
752     CORBA::String_var anEntry = aSObject->GetID();
753     return FindActor(theViewWindow,anEntry.in());
754   }
755
756   void
757   RecreateActor (const SalomeApp_Module* theModule,
758                  VISU::Prs3d_i* thePrs)
759   {
760     QApplication::setOverrideCursor(Qt::waitCursor);
761     bool isPublished = false;
762
763     SALOMEDS::SObject_var aSObject = thePrs->GetSObject();
764     CORBA::String_var anEntry = aSObject->GetID();
765
766     try {
767       thePrs->Update();
768
769       TViewWindows aViewWindows = GetViews(theModule);
770       for (int i = 0, iEnd = aViewWindows.size(); i < iEnd; i++) {
771         SVTK_ViewWindow* aView = aViewWindows[i];
772         if (VISU_Actor* anActor = FindActor(aView, anEntry.in())) {
773           isPublished = true;
774           thePrs->UpdateActor(anActor);
775         }
776       }
777     } catch (std::runtime_error& ex) {
778       INFOS(ex.what());
779       QApplication::restoreOverrideCursor();
780       SUIT_MessageBox::warn1 (GetDesktop(theModule), QObject::tr("WRN_VISU"),
781                               QObject::tr("ERR_CANT_BUILD_PRESENTATION") + ": " + QObject::tr(ex.what()),
782                               QObject::tr("BUT_OK"));
783
784       TViewWindows aViewWindows = GetViews(theModule);
785       for (int i = 0, iEnd = aViewWindows.size(); i < iEnd; i++) {
786         SVTK_ViewWindow* aView = aViewWindows[i];
787         if (VISU_Actor* anActor = FindActor(aView, anEntry.in())) {
788           aView->RemoveActor(anActor);
789           anActor->Delete();
790         }
791       }
792       return;
793     }
794     QApplication::restoreOverrideCursor();
795
796     if (!isPublished)
797       PublishInView(theModule, thePrs);
798   }
799
800   static bool ComputeVisiblePropBounds(SVTK_ViewWindow* theViewWindow,
801                                       float             allBounds[6], 
802                                       const char*       theActorClassName = "VISU_Actor")
803   {
804     vtkRenderer *aRen = theViewWindow->getRenderer();
805     vtkActorCollection *anActColl = aRen->GetActors(); 
806     vtkProp *prop;
807     float   *bounds;
808     int     somethingVisible = false;
809
810     allBounds[0] = allBounds[2] = allBounds[4] = VTK_LARGE_FLOAT;
811     allBounds[1] = allBounds[3] = allBounds[5] = -VTK_LARGE_FLOAT;
812     // loop through all props
813     for (anActColl->InitTraversal(); (prop = anActColl->GetNextProp()); ) {
814       // if it's invisible, or has no geometry, we can skip the rest 
815       if (prop->GetVisibility() && prop->IsA(theActorClassName)) {
816         bounds = prop->GetBounds();
817         // make sure we haven't got bogus bounds
818         if (bounds != NULL &&
819             bounds[0] > -VTK_LARGE_FLOAT && bounds[1] < VTK_LARGE_FLOAT &&
820             bounds[2] > -VTK_LARGE_FLOAT && bounds[3] < VTK_LARGE_FLOAT &&
821             bounds[4] > -VTK_LARGE_FLOAT && bounds[5] < VTK_LARGE_FLOAT)
822         {
823           somethingVisible = true;
824           if (bounds[0] < allBounds[0]) allBounds[0] = bounds[0]; 
825           if (bounds[1] > allBounds[1]) allBounds[1] = bounds[1]; 
826           if (bounds[2] < allBounds[2]) allBounds[2] = bounds[2]; 
827           if (bounds[3] > allBounds[3]) allBounds[3] = bounds[3]; 
828           if (bounds[4] < allBounds[4]) allBounds[4] = bounds[4]; 
829           if (bounds[5] > allBounds[5]) allBounds[5] = bounds[5]; 
830         }//not bogus
831       }
832     }
833     return somethingVisible;
834   }
835
836   void SetFitAll(SVTK_ViewWindow* theViewWindow)
837   {
838     static float PRECISION = 0.000001;
839     static float DEVIATION = 600;
840     float XYZ_Bnd[6];
841     if (!ComputeVisiblePropBounds(theViewWindow, XYZ_Bnd)) return;
842
843     float absX = XYZ_Bnd[1] - XYZ_Bnd[0];
844     float absY = XYZ_Bnd[3] - XYZ_Bnd[2];
845     float absZ = XYZ_Bnd[5] - XYZ_Bnd[4];
846
847     enum CameraOrient {e3D, eFront, eLeft, eTop};
848     CameraOrient aCameraOrient = e3D;
849     if (absX <= PRECISION) aCameraOrient = eFront;
850     else {
851       if (absY <= PRECISION) aCameraOrient = eLeft;
852       else {
853         if (absZ <= PRECISION) aCameraOrient = eTop;
854         else {
855           // all the three dimensions exceeds precision
856           float dev_abs_XY = absX / absY;
857           float dev_abs_YZ = absY / absZ;
858           float dev_abs_XZ = absX / absZ;
859           if (dev_abs_XY >= DEVIATION || 1./dev_abs_YZ >= DEVIATION)
860             aCameraOrient = eLeft;
861           else {
862             if (1./dev_abs_XY >= DEVIATION || 1./dev_abs_XZ >= DEVIATION)
863               aCameraOrient = eFront;
864             else {
865               if (dev_abs_XZ >= DEVIATION || dev_abs_YZ >= DEVIATION)
866                 aCameraOrient = eTop;
867             }
868           }
869         }
870       }
871     }
872
873     switch (aCameraOrient) {
874     case eFront: theViewWindow->onFrontView(); break;
875     case eLeft:  theViewWindow->onLeftView();  break;
876     case eTop:   theViewWindow->onTopView();   break;
877     case e3D:    theViewWindow->onResetView(); break;
878     }
879     theViewWindow->getRenderer()->ResetCameraClippingRange();
880     theViewWindow->onFitAll();
881   }
882
883   //************************************************************
884   // Plot2d View
885
886   SPlot2d_Viewer*
887   GetPlot2dViewer(const SalomeApp_Module* theModule, const bool theCreate)
888   {
889     if(SalomeApp_Application* anApp = theModule->getApp()){
890       if(SUIT_ViewManager* aViewManager = anApp->getViewManager( Plot2d_Viewer::Type(), theCreate )){
891         return dynamic_cast<SPlot2d_Viewer*>(aViewManager->getViewModel());
892       }
893     }
894     return NULL;
895   }
896
897   // Internal function used by several public functions below
898   void
899   UpdateCurve(VISU::Curve_i* theCurve,
900               Plot2d_ViewFrame* aPlot,
901               SPlot2d_Curve* plotCurve,
902               int theDisplaying)
903   {
904     if ( theDisplaying == VISU::eErase ) {
905       if ( plotCurve )
906         aPlot->eraseCurve( plotCurve, false );
907     }
908     else if ( theDisplaying == VISU::eDisplay || theDisplaying == VISU::eDisplayOnly ) {
909       if ( plotCurve ) {
910         plotCurve->setHorTitle( theCurve->GetHorTitle().c_str() );
911         //plotCurve->setVerTitle( ( theCurve->GetVerTitle().c_str() ) );
912         plotCurve->setVerTitle( theCurve->GetName() );
913         plotCurve->setHorUnits( theCurve->GetHorUnits().c_str() );
914         plotCurve->setVerUnits( theCurve->GetVerUnits().c_str() );
915         double* xList = 0;
916         double* yList = 0;
917         int     nbPoints = theCurve->GetData( xList, yList );
918         if ( nbPoints > 0 && xList && yList ) {
919           plotCurve->setData( xList, yList, nbPoints );
920         }
921         if ( !theCurve->IsAuto() ) {
922           plotCurve->setLine( (Plot2d_Curve::LineType)theCurve->GetLine(), theCurve->GetLineWidth() );
923           plotCurve->setMarker( (Plot2d_Curve::MarkerType)theCurve->GetMarker() );
924           SALOMEDS::Color color = theCurve->GetColor();
925           plotCurve->setColor( QColor( (int)(color.R*255.), (int)(color.G*255.), (int)(color.B*255.) ) );
926         }
927         plotCurve->setAutoAssign( theCurve->IsAuto() );
928         aPlot->displayCurve( plotCurve, false );
929       }
930       else {
931         Plot2d_Curve* crv = theCurve->CreatePresentation();
932         if ( crv ) {
933           aPlot->displayCurve( crv, false );
934           theCurve->SetLine( (VISU::Curve::LineType)crv->getLine(), crv->getLineWidth() );
935           theCurve->SetMarker( (VISU::Curve::MarkerType)crv->getMarker());
936           SALOMEDS::Color newColor;
937           newColor.R = crv->getColor().red()/255.;
938           newColor.G = crv->getColor().green()/255.;
939           newColor.B = crv->getColor().blue()/255.;
940           theCurve->SetColor( newColor );
941           crv->setAutoAssign( theCurve->IsAuto() );
942         }
943       }
944     }
945   }
946
947   void
948   PlotTable(const SalomeApp_Module* theModule,
949             VISU::Table_i* table,
950             int theDisplaying)
951   {
952     SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true ); // create if necessary
953     if ( !aView )
954       return;
955     Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
956     if ( !aPlot )
957       return;
958
959     if ( theDisplaying == VISU::eDisplayOnly )
960       aPlot->EraseAll();
961     QList<Plot2d_Curve> clist;
962     aPlot->getCurves( clist );
963     _PTR(Study) aStudy = GetCStudy( GetAppStudy( theModule ) );
964     _PTR(SObject) TableSO = aStudy->FindObjectID( table->GetEntry().latin1() );
965     if ( TableSO ) {
966       _PTR(ChildIterator) Iter = aStudy->NewChildIterator( TableSO );
967       for ( ; Iter->More(); Iter->Next() ) {
968         CORBA::Object_var childObject = VISU::ClientSObjectToObject( Iter->Value() );
969         if( !CORBA::is_nil( childObject ) ) {
970           CORBA::Object_ptr aCurve = VISU::Curve::_narrow( childObject );
971           if( !CORBA::is_nil( aCurve ) ) {
972             VISU::Curve_i* theCurve = dynamic_cast<VISU::Curve_i*>(VISU::GetServant(aCurve).in());
973             SPlot2d_Curve* plotCurve = 0;
974             SPlot2d_Curve* tmpCurve;
975             for ( int i = 0; i < clist.count(); i++ ) {
976               tmpCurve = dynamic_cast<SPlot2d_Curve*>( clist.at( i ) );
977               if (tmpCurve && tmpCurve->hasIO() &&
978                   !strcmp(tmpCurve->getIO()->getEntry(), theCurve->GetEntry())) {
979                 plotCurve = tmpCurve;
980                 break;
981               }
982             }
983
984             UpdateCurve( theCurve, aPlot, plotCurve, theDisplaying );
985
986             if ( theDisplaying == VISU::eErase && plotCurve ) {
987               clist.remove( plotCurve );
988             }
989           }
990         }
991       }
992       aPlot->Repaint();
993     }
994   }
995
996   void
997   PlotCurve(const SalomeApp_Module* theModule,
998             VISU::Curve_i* theCurve,
999             int theDisplaying)
1000   {
1001     SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true );
1002     if ( !aView )
1003       return;
1004     Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
1005     if ( !aPlot )
1006       return;
1007
1008 //  if ( theDisplaying == VISU::eDisplayOnly )
1009 //    aPlot->EraseAll();
1010     QList<Plot2d_Curve> clist;
1011     aPlot->getCurves( clist );
1012     SPlot2d_Curve* plotCurve = 0;
1013     SPlot2d_Curve* tmpCurve;
1014     for (int i = 0; i < clist.count(); i++) {
1015       tmpCurve = dynamic_cast<SPlot2d_Curve*>(clist.at(i));
1016       if (tmpCurve && tmpCurve->hasIO() &&
1017           !strcmp(tmpCurve->getIO()->getEntry(), theCurve->GetEntry())) {
1018         plotCurve = tmpCurve;
1019       } else if (theDisplaying == VISU::eDisplayOnly) {
1020         aPlot->eraseCurve(clist.at(i));
1021       }
1022     }
1023
1024     UpdateCurve(theCurve, aPlot, plotCurve, theDisplaying);
1025
1026     aPlot->Repaint();
1027   }
1028
1029   void
1030   PlotContainer(const SalomeApp_Module* theModule,
1031                 VISU::Container_i* container,
1032                 int theDisplaying)
1033   {
1034     SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true );
1035     if ( !aView )
1036       return;
1037     Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
1038     if ( !aPlot )
1039       return;
1040
1041     if ( theDisplaying == VISU::eDisplayOnly )
1042       aPlot->EraseAll();
1043     QList<Plot2d_Curve> clist;
1044     aPlot->getCurves( clist );
1045     if ( container->GetNbCurves() > 0 ) {
1046       int nbCurves = container->GetNbCurves();
1047       for ( int k = 1; k <= nbCurves; k++ ) {
1048         VISU::Curve_i* theCurve = container->GetCurve( k );
1049         if ( theCurve && theCurve->IsValid() ) {
1050           SPlot2d_Curve* plotCurve = dynamic_cast<SPlot2d_Curve*>
1051             (aView->getCurveByIO(new SALOME_InteractiveObject (theCurve->GetEntry(), "", "")));
1052
1053           UpdateCurve( theCurve, aPlot, plotCurve, theDisplaying );
1054
1055           if ( plotCurve && theDisplaying == VISU::eErase ) {
1056             clist.remove( plotCurve );
1057           }
1058         }
1059       }
1060     }
1061     aPlot->Repaint();
1062   }
1063
1064   void
1065   CreatePlot(SalomeApp_Module* theModule,
1066              _PTR(SObject) theTableSO)
1067   {
1068     if ( IsSObjectTable(theTableSO) ) {
1069       CORBA::Object_var aTable = VISU::ClientSObjectToObject(theTableSO);
1070       CORBA::Object_var aContainer = GetVisuGen( theModule )->CreateContainer();
1071       if ( !CORBA::is_nil( aTable ) && !CORBA::is_nil( aContainer ) ) {
1072         VISU::Table_i*     pTable     = dynamic_cast<VISU::Table_i*>(VISU::GetServant(aTable).in());
1073         VISU::Container_i* pContainer = dynamic_cast<VISU::Container_i*>(VISU::GetServant(aContainer).in());
1074
1075         if ( pContainer && pTable ) {
1076           for ( int i = 2; i <= pTable->GetNbRows(); i++ ) {
1077             CORBA::Object_var aNewCurve = GetVisuGen( theModule )->CreateCurve( pTable->_this(), 1, i );
1078             if( !CORBA::is_nil( aNewCurve ) ) {
1079               VISU::Curve_i* pCrv = dynamic_cast<VISU::Curve_i*>( VISU::GetServant(aNewCurve).in() );
1080               if ( pCrv ) {
1081                 pContainer->AddCurve( pCrv->_this() );
1082               }
1083             }
1084           }
1085           PlotContainer( theModule, pContainer, VISU::eDisplay );
1086         }
1087       }
1088     }
1089   }
1090
1091   //************************************************************
1092   // Others
1093
1094   void CreateMesh (const SalomeApp_Module* theModule,
1095                     const Handle(SALOME_InteractiveObject)& theIO)
1096   {
1097     _PTR(Study) aStudy = GetCStudy(GetAppStudy(theModule));
1098     //if (CheckLock(aStudy))
1099     //  return;
1100
1101     _PTR(SObject) aResultSObj = aStudy->FindObjectID(theIO->getEntry());
1102
1103     // Get VISU::Result
1104     VISU::Result_var aResult;
1105     VISU::Result_i* pResult = CheckResult(theModule, aResultSObj, aResult);
1106     if (pResult == NULL)
1107       return;
1108
1109     Storable::TRestoringMap aMap = getMapOfValue(aResultSObj);
1110     bool isExist;
1111     string aComment = Storable::FindValue(aMap,"myComment",&isExist).latin1();
1112     if (!isExist)
1113       return;
1114
1115     CORBA::Object_var aMesh;
1116     string aMeshName = Storable::FindValue(aMap,"myMeshName").latin1();
1117 #ifdef CHECKTIME
1118     Utils_Timer timer;
1119     timer.Start();
1120 #endif
1121     if (aComment == "ENTITY") {
1122       VISU::Entity anEntity = (VISU::Entity)Storable::FindValue(aMap,"myId").toInt();
1123       if (VISU::Mesh_i::IsPossible(pResult,aMeshName.c_str(),anEntity))
1124         aMesh = GetVisuGen(theModule)->MeshOnEntity(aResult,aMeshName.c_str(),anEntity);
1125     } else if (aComment == "FAMILY") {
1126       VISU::Entity anEntity = (VISU::Entity)Storable::FindValue(aMap,"myEntityId").toInt();
1127       string aFamilyName = Storable::FindValue(aMap,"myName").latin1();
1128       if (VISU::Mesh_i::IsPossible(pResult,aMeshName.c_str(),anEntity,aFamilyName.c_str()))
1129         aMesh = GetVisuGen(theModule)->FamilyMeshOnEntity
1130           (aResult,aMeshName.c_str(),anEntity,aFamilyName.c_str());
1131     } else if (aComment == "GROUP") {
1132       string aGroupName = Storable::FindValue(aMap,"myName").latin1();
1133       if (VISU::Mesh_i::IsPossible(pResult,aMeshName.c_str(),aGroupName.c_str()))
1134         aMesh = GetVisuGen(theModule)->GroupMesh(aResult,aMeshName.c_str(),aGroupName.c_str());
1135     }
1136 #ifdef CHECKTIME
1137     timer.Stop();
1138     MESSAGE("VisuGUI::CreateMesh() - CREATE MESH");
1139     timer.Show();
1140 #endif
1141
1142     QApplication::restoreOverrideCursor();
1143     VISU::Mesh_i* pPresent = NULL;
1144     if (!CORBA::is_nil(aMesh))
1145       pPresent = dynamic_cast<VISU::Mesh_i*>(VISU::GetServant(aMesh).in());
1146     if (pPresent == NULL) {
1147       SUIT_MessageBox::warn1 (GetDesktop(theModule),
1148                               QObject::tr("WRN_VISU"),
1149                               QObject::tr("ERR_CANT_BUILD_PRESENTATION"),
1150                               QObject::tr("BUT_OK"));
1151       return;
1152     }
1153
1154     if (SVTK_ViewWindow* aView = GetViewWindow(theModule)) {
1155       try {
1156 #ifdef CHECKTIME
1157         Utils_Timer timer;
1158         timer.Start();
1159 #endif
1160         PublishInView(theModule, pPresent);
1161         //aView->onFitAll();
1162         SetFitAll(aView);
1163 #ifdef CHECKTIME
1164         timer.Stop();
1165         MESSAGE("VisuGUI::CreateMesh() - DISPLAY MESH");
1166         timer.Show();
1167 #endif
1168         theModule->application()->putInfo(QObject::tr("INF_DONE"));
1169         // Make "Save" button active
1170         theModule->getApp()->updateActions();
1171       } catch (std::runtime_error& exc) {
1172         INFOS(exc.what());
1173         SUIT_MessageBox::warn1 (GetDesktop(theModule),
1174                                 QObject::tr("WRN_VISU"),
1175                                 QObject::tr("ERR_CANT_CREATE_ACTOR") + ": " + QObject::tr(exc.what()),
1176                                 QObject::tr("BUT_OK"));
1177       }
1178     }
1179   }
1180
1181   // ========================================================================================
1182   // GetPrs3dList: find list of presentations for the given object
1183   // ========================================================================================
1184   std::vector<VISU::Prs3d_i*> GetPrs3dList (const SalomeApp_Module* theModule,
1185                                             const Handle(SALOME_InteractiveObject)& theIO)
1186   {
1187     std::vector<VISU::Prs3d_i*> aList;
1188     if (!theIO.IsNull() && theIO->hasEntry()) {
1189       _PTR(Study) aCStudy = GetCStudy(GetAppStudy(theModule));
1190       _PTR(SObject) aSObject = aCStudy->FindObjectID(theIO->getEntry());
1191       aList = GetPrs3dList(theModule, aSObject);
1192     }
1193     return aList;
1194   }
1195
1196   std::vector<VISU::Prs3d_i*> GetPrs3dList (const SalomeApp_Module* theModule,
1197                                             _PTR(SObject) theObject)
1198   {
1199     std::vector<VISU::Prs3d_i*> aList; int k = 0;
1200     if (!theObject)
1201       return aList;
1202
1203     _PTR(Study) aCStudy = GetCStudy(GetAppStudy(theModule));
1204
1205     CORBA::Object_var aCORBAObject = VISU::ClientSObjectToObject(theObject);
1206     if (!CORBA::is_nil(aCORBAObject)) {
1207       VISU::Base_var aVisuObj = VISU::Base::_narrow(aCORBAObject);
1208       if (!CORBA::is_nil(aVisuObj)) {
1209         VISU::VISUType aType = aVisuObj->GetType();
1210         switch (aType) {
1211         case VISU::TSCALARMAP:
1212         case VISU::TISOSURFACE:
1213         case VISU::TDEFORMEDSHAPE:
1214         case VISU::TCUTPLANES:
1215         case VISU::TCUTLINES:
1216         case VISU::TVECTORS:
1217         case VISU::TSTREAMLINES:
1218         case VISU::TPLOT3D:
1219           {
1220             PortableServer::ServantBase_var aServant = VISU::GetServant(aCORBAObject);
1221             if (aServant.in()) {
1222               VISU::Prs3d_i* aPrsObject = dynamic_cast<VISU::Prs3d_i*>(aServant.in());
1223               aList.resize(k+1);
1224               aList[k] = aPrsObject;
1225               k++;
1226             }
1227           }
1228           break;
1229         case VISU::TFIELD:
1230           {
1231             _PTR(ChildIterator) anIter = aCStudy->NewChildIterator(theObject);
1232             _PTR(SObject) aTimeStamp;
1233             anIter->Next(); // First is reference on support
1234             for (; anIter->More(); anIter->Next()) {
1235               aTimeStamp = anIter->Value();
1236               if (!aTimeStamp) continue;
1237               std::vector<VISU::Prs3d_i*> aSubList = GetPrs3dList(theModule, aTimeStamp);
1238               if (!aSubList.empty()) {
1239                 int n = aSubList.size();
1240                 aList.resize(k+n);
1241                 for (int i = 0; i < n; i++) {
1242                   aList[k] = aSubList[i];
1243                   k++;
1244                 }
1245               }
1246             }
1247           }
1248           break;
1249         }
1250       }
1251     } else {
1252       _PTR(GenericAttribute) anAttr;
1253       if (theObject->FindAttribute(anAttr, "AttributeComment")) {
1254         _PTR(AttributeComment) aComment (anAttr);
1255         string aComm = aComment->Value();
1256         QString strIn (aComm.c_str());
1257         VISU::Storable::TRestoringMap pMap;
1258         VISU::Storable::StrToMap(strIn, pMap);
1259         bool isExist;
1260         VISU::VISUType aType =
1261           (VISU::VISUType)VISU::Storable::FindValue(pMap,"myType",&isExist).toInt();
1262         if (isExist) {
1263           switch (aType) {
1264           case VISU::TFIELD:
1265             {
1266               _PTR(ChildIterator) anIter = aCStudy->NewChildIterator(theObject);
1267               _PTR(SObject) aTimeStamp;
1268               anIter->Next(); // First is reference on support
1269               for (; anIter->More(); anIter->Next()) {
1270                 aTimeStamp = anIter->Value();
1271                 if (!aTimeStamp) continue;
1272                 std::vector<VISU::Prs3d_i*> aSubList = GetPrs3dList(theModule, aTimeStamp);
1273                 if (!aSubList.empty()) {
1274                   int n = aSubList.size();
1275                   aList.resize(k+n);
1276                   for (int i = 0; i < n; i++) {
1277                     aList[k] = aSubList[i];
1278                     k++;
1279                   }
1280                 }
1281               }
1282             }
1283             break;
1284           case VISU::TTIMESTAMP:
1285             {
1286               _PTR(ChildIterator) anIter = aCStudy->NewChildIterator(theObject);
1287               _PTR(SObject) aPrs;
1288               for (; anIter->More(); anIter->Next()) {
1289                 aPrs = anIter->Value();
1290                 if (!aPrs) continue;
1291                 std::vector<VISU::Prs3d_i*> aSubList = GetPrs3dList(theModule, aPrs);
1292                 if (!aSubList.empty()) {
1293                   int n = aSubList.size();
1294                   aList.resize(k+n);
1295                   for (int i = 0; i < n; i++) {
1296                     aList[k] = aSubList[i];
1297                     k++;
1298                   }
1299                 }
1300               }
1301             }
1302             break;
1303           }
1304         }
1305       }
1306     }
1307     return aList;
1308   }
1309 }