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