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