]> SALOME platform Git repositories - modules/visu.git/blob - src/VISUGUI/VisuGUI_Tools.cxx
Salome HOME
PAL10445 - incorrect deletion of references in VISU
[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       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     LightApp_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(LightApp_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(LightApp_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     LightApp_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       ErasePrs(theModule, aChildObj);
403     }
404
405     CORBA::Object_var anObj = VISU::ClientSObjectToObject(theSObject);
406     if (!CORBA::is_nil(anObj)) {
407       ErasePrs(theModule, anObj);
408
409       VISU::RemovableObject_var aRemovableObject = VISU::RemovableObject::_narrow(anObj);
410       if (!CORBA::is_nil(aRemovableObject)) {
411         aRemovableObject->RemoveFromStudy();
412       }
413     } else {
414       // Remove aSObject together with all its sub-objects
415
416       VISU::RemoveFromStudy(theSObject,
417                             false,  // remove not only IOR attribute, but Object With Children
418                             false); // not Destroy() sub-objects
419     }
420   }
421
422   void
423   DeletePrs3d(SalomeApp_Module* theModule,
424               VISU::Prs3d_i* thePrs,
425               const Handle(SALOME_InteractiveObject)& theIO)
426   {
427     if (!thePrs)
428       return;
429     if (CheckLock(GetCStudy(GetAppStudy(theModule))))
430       return;
431     SALOMEDS::SObject_var aSObject = thePrs->GetSObject();
432     CORBA::String_var anEntry = aSObject->GetID();
433     LightApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(theModule);
434     Remove(aSelectionMgr,theIO);
435     TViewWindows aViewWindows = GetViews(theModule);
436     for(int i = 0, iEnd = aViewWindows.size(); i < iEnd; i++){
437       SVTK_ViewWindow* aView = aViewWindows[i];
438       if(VISU_Actor* anActor = FindActor(aView,anEntry.in())){
439         aView->RemoveActor(anActor);
440         anActor->Delete();
441       }
442     }
443     thePrs->RemoveFromStudy();
444   }
445
446   void
447   ErasePrs3d(const SalomeApp_Module* theModule,
448              VISU::Prs3d_i* thePrs)
449   {
450     if ( SVTK_ViewWindow* vw = GetViewWindow( theModule ) ){
451       VISU_Actor* anVISUActor = FindActor( vw, thePrs );
452       if (anVISUActor) {
453         anVISUActor->VisibilityOff();
454       }
455     }
456   }
457
458   //************************************************************
459   // Presentation management
460
461   void
462   ChangeRepresentation (const SalomeApp_Module* theModule,
463                         VISU::PresentationType  theType)
464   {
465     SUIT_ViewWindow* aView = GetActiveView(theModule, SVTK_Viewer::Type());
466     if (!aView) return;
467     SVTK_ViewWindow* vw  = dynamic_cast<SVTK_ViewWindow*>( aView );
468     if( !vw )
469       return;
470
471     Handle(SALOME_InteractiveObject) anIO;
472     CORBA::Object_var anObject = GetSelectedObj(theModule, &anIO);
473     if (CORBA::is_nil(anObject)) return;
474
475     VISU::Base_var aVisuObj = VISU::Base::_narrow(anObject);
476     if (CORBA::is_nil(aVisuObj)) return;
477
478     PortableServer::ServantBase_var aServant = VISU::GetServant(anObject);
479     if (!aServant.in()) return;
480
481     VISU::Prs3d_i* aPrs3d = dynamic_cast<VISU::Prs3d_i*>(aServant.in());
482     if (aPrs3d) {
483       if (VISU_Actor* anActor = GetActor(aPrs3d, vw)) {
484         switch (theType) {
485         case VISU::SHRINK:
486           if (anActor->IsShrunk())
487             anActor->UnShrink();
488           else
489             anActor->SetShrink();
490           break;
491         default:
492           if (VISU::Mesh_i* aMesh = dynamic_cast<VISU::Mesh_i*>(aPrs3d)) {
493             aMesh->SetPresentationType(theType);
494             RecreateActor(theModule, aMesh);
495           } else {
496             anActor->SetRepresentation(theType);
497           }
498         }
499         vw->Repaint();
500       }
501     }
502   }
503   
504   void
505   SetShading ( const SalomeApp_Module* theModule,
506               bool theOn )
507   {
508     SUIT_ViewWindow* aView = GetActiveView(theModule, SVTK_Viewer::Type());
509     if (!aView) return;
510     SVTK_ViewWindow* vw  = dynamic_cast<SVTK_ViewWindow*>( aView );
511     if( !vw )
512       return;
513     
514     Handle(SALOME_InteractiveObject) anIO;
515     CORBA::Object_var anObject = GetSelectedObj(theModule, &anIO);
516     if (CORBA::is_nil(anObject)) return;
517
518     VISU::Base_var aVisuObj = VISU::Base::_narrow(anObject);
519     if (CORBA::is_nil(aVisuObj)) return;
520
521     PortableServer::ServantBase_var aServant = VISU::GetServant(anObject);
522     if (!aServant.in()) return;
523
524     VISU::Prs3d_i* aPrs3d = dynamic_cast<VISU::Prs3d_i*>(aServant.in());
525     if (aPrs3d) {
526       if (VISU_Actor* anActor = GetActor(aPrs3d, vw)) {
527         if ( VISU_ScalarMapAct* aScalarMapActor = dynamic_cast<VISU_ScalarMapAct*>(anActor) )
528           aScalarMapActor->SetShading( theOn );
529       }
530       vw->Repaint();
531     }
532   }
533
534   //************************************************************
535   // SObject type
536
537   bool
538   CheckTimeStamp(const SalomeApp_Module* theModule,
539                  _PTR(SObject)&          theSObject,
540                  Handle(SALOME_InteractiveObject)* theIO)
541   {
542     Handle(SALOME_InteractiveObject) anIO;
543     CORBA::Object_var anObject = GetSelectedObj(theModule, &anIO);
544     if (theIO)
545       *theIO = anIO;
546     if (!anIO.IsNull() && anIO->hasEntry()){
547       _PTR(Study) aStudy = GetCStudy(GetAppStudy(theModule));
548       theSObject = aStudy->FindObjectID(anIO->getEntry());
549       QString aValue = getValue(theSObject,"myType");
550       if (aValue.toInt() == int(VISU::TTIMESTAMP))
551         return true;
552     }
553     SUIT_MessageBox::warn1(GetDesktop(theModule),
554                            QObject::tr("WRN_VISU"),
555                            QObject::tr("WRN_NO_AVAILABLE_DATA"),
556                            QObject::tr("BUT_OK") );
557     return false;
558   }
559
560   VISU::Result_i*
561   CheckResult(const SalomeApp_Module* theModule,
562               _PTR(SObject)           theSource,
563               VISU::Result_var&       theResult)
564   {
565     _PTR(SObject) aSObj = theSource->GetFather();
566     if (!aSObj)
567       return NULL;
568
569     aSObj = aSObj->GetFather();
570     if (!aSObj)
571       return NULL;
572
573     aSObj = aSObj->GetFather();
574     if (!aSObj)
575       return NULL;
576
577     CORBA::Object_var anObject = VISU::ClientSObjectToObject(aSObj);
578     if (CORBA::is_nil(anObject)) {
579       aSObj = aSObj->GetFather();
580       if (!aSObj)
581         return NULL;
582       anObject = VISU::ClientSObjectToObject(aSObj);
583     }
584
585     if (CORBA::is_nil(anObject))
586       return NULL;
587
588     theResult = VISU::Result::_narrow(anObject);
589     VISU::Result_i* pResult = dynamic_cast<VISU::Result_i*>(VISU::GetServant(anObject).in());
590     if (pResult == NULL)
591       SUIT_MessageBox::warn1(GetDesktop(theModule),
592                              QObject::tr("WRN_VISU"),
593                              QObject::tr("WRN_NO_AVAILABLE_DATA"),
594                              QObject::tr("BUT_OK"));
595     return pResult;
596   }
597
598   //************************************************************
599   // Views
600
601   SUIT_ViewWindow* GetActiveView(const SalomeApp_Module* theModule, QString theType)
602   {
603     if(SalomeApp_Application* anApp = theModule->getApp()){
604       if(SUIT_ViewManager* aViewManager = anApp->activeViewManager()){
605         if (!theType.isNull()) {
606           if (aViewManager->getType() != theType)
607             return 0;
608         }
609         return aViewManager->getActiveView();
610       }
611     }
612     return 0;
613   }
614
615   //************************************************************
616   // VTK View
617
618   TViewWindows
619   GetViews(const SalomeApp_Module* theModule)
620   {
621     TViewWindows aViewWindows;
622     if(SalomeApp_Application* anApp = theModule->getApp()){
623       ViewManagerList aViewManagerList;
624       anApp->viewManagers(SVTK_Viewer::Type(),aViewManagerList);
625       QPtrListIterator<SUIT_ViewManager> anIter(aViewManagerList);
626       while(SUIT_ViewManager* aViewManager = anIter.current()){
627         QPtrVector<SUIT_ViewWindow> aViews = aViewManager->getViews();
628         for(int i = 0, iEnd = aViews.size(); i < iEnd; i++){
629           if(SUIT_ViewWindow* aViewWindow = aViews.at(i))
630             if(SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewWindow))
631               aViewWindows.push_back(aView);
632         }
633         ++anIter;
634       }
635     }
636     return aViewWindows;
637   }
638
639   SVTK_ViewWindow*
640   GetViewWindow( const SalomeApp_Module* theModule, const bool theCreate )
641   {
642     if (SalomeApp_Application* anApp = theModule->getApp())
643     {
644       SVTK_ViewWindow* wnd = dynamic_cast<SVTK_ViewWindow*>(anApp->desktop()->activeWindow());
645       if( wnd )
646         return wnd;
647       else
648       {
649         SUIT_ViewManager* aViewManager = anApp->getViewManager( SVTK_Viewer::Type(), theCreate );
650         return dynamic_cast<SVTK_ViewWindow*>( aViewManager->getActiveView() );
651       }
652     }
653     return NULL;
654   }
655
656   /*SVTK_ViewWindow*
657   GetViewWindow(const SalomeApp_Module* theModule, const bool theCreate )
658   {
659     if(SalomeApp_Application* anApp = theModule->getApp()){
660       if(SUIT_ViewManager* aViewManager = anApp->getViewManager( SVTK_Viewer::Type(), theCreate )){
661         if(SUIT_ViewWindow* aViewWindow = aViewManager->getActiveView()){
662           return dynamic_cast<SVTK_ViewWindow*>(aViewWindow);
663         }
664       }
665     }
666     return NULL;
667   }*/
668
669
670   SVTK_ViewWindow*
671   GetViewWindow()
672   {
673     SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>
674       (SUIT_Session::session()->activeApplication());
675     if (anApp) {
676       if (SUIT_ViewManager* aViewManager = anApp->activeViewManager()) {
677         if (aViewManager->getType() == SVTK_Viewer::Type()) {
678           if (SUIT_ViewWindow* aViewWindow = aViewManager->getActiveView()) {
679             return dynamic_cast<SVTK_ViewWindow*>(aViewWindow);
680           }
681         }
682       }
683     }
684     return NULL;
685   }
686
687   VISU_Actor*
688   PublishInView(const SalomeApp_Module* theModule,
689                 VISU::Prs3d_i* thePrs)
690   {
691     VISU_Actor* aActor = NULL;
692     if(!thePrs)
693       return aActor;
694     if(SVTK_ViewWindow* aView = GetViewWindow(theModule)){
695       QApplication::setOverrideCursor( Qt::waitCursor );
696       try{
697         if(aActor = thePrs->CreateActor())
698           aView->AddActor(aActor);
699       }catch(std::exception& exc){
700         SUIT_MessageBox::warn1(GetDesktop(theModule),
701                                QObject::tr("WRN_VISU"),
702                                QObject::tr("ERR_CANT_CREATE_ACTOR") + ": " + QObject::tr(exc.what()),
703                                QObject::tr("BUT_OK"));
704       }
705       QApplication::restoreOverrideCursor();
706     }
707     return aActor;
708   }
709
710   VISU_Actor*
711   UpdateViewer(const SalomeApp_Module* theModule,
712                VISU::Prs3d_i* thePrs,
713                bool theDispOnly)
714   {
715     SVTK_ViewWindow* vw = GetViewWindow( theModule );
716     if (!vw) return NULL;
717
718     vtkRenderer *aRen = vw->getRenderer();
719     vtkActorCollection *anActColl = aRen->GetActors();
720
721     vtkActor *anActor;
722     VISU_Actor* anVISUActor = NULL;
723     VISU_Actor* aResActor = NULL;
724     for(anActColl->InitTraversal(); (anActor = anActColl->GetNextActor()) != NULL; ){
725       if(!SALOME_Actor::SafeDownCast(anActor))
726         continue;
727       if(anActor->IsA("VISU_Actor")){
728         anVISUActor = VISU_Actor::SafeDownCast(anActor);
729         VISU::Prs3d_i* aPrs = anVISUActor->GetPrs3d();
730         if(aPrs == NULL) continue;
731         if (thePrs == aPrs) {
732           aResActor = anVISUActor->GetParent();
733           try {
734             thePrs->UpdateActor(aResActor);
735             aResActor->VisibilityOn();
736           } catch (std::runtime_error& ex) {
737             aResActor->VisibilityOff();
738             INFOS(ex.what());
739             SUIT_MessageBox::warn1(GetDesktop(theModule), QObject::tr("WRN_VISU"),
740                                    QObject::tr("ERR_CANT_CREATE_ACTOR") + ": " + QObject::tr(ex.what()),
741                                    QObject::tr("BUT_OK"));
742           }
743         } else if (theDispOnly) {
744           anVISUActor->GetParent()->VisibilityOff();
745         } else {
746         }
747       } else if (theDispOnly && anActor->GetVisibility()) {
748         anActor->VisibilityOff();
749       } else {
750       }
751     }
752     if (aResActor)
753       return aResActor;
754
755     //anVISUActor = PublishInView( theModule, thePrs );
756     return anVISUActor;
757   }
758
759   void
760   RepaintViewWindows (const SalomeApp_Module* theModule,
761                       const Handle(SALOME_InteractiveObject)& theIObject)
762   {
763     TViewWindows aViewWindows;
764     if (SalomeApp_Application* anApp = theModule->getApp()) {
765       ViewManagerList aViewManagerList;
766       anApp->viewManagers(SVTK_Viewer::Type(),aViewManagerList);
767       QPtrListIterator<SUIT_ViewManager> anIter (aViewManagerList);
768       while (SUIT_ViewManager* aViewManager = anIter.current()) {
769         QPtrVector<SUIT_ViewWindow> aViews = aViewManager->getViews();
770         for (int i = 0, iEnd = aViews.size(); i < iEnd; i++) {
771           if (SUIT_ViewWindow* aViewWindow = aViews.at(i)) {
772             if (SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>(aViewWindow)) {
773               if (vw->isVisible(theIObject)) {
774                 vw->getRenderer()->ResetCameraClippingRange();
775                 vw->Repaint();
776                 vw->highlight(theIObject, true, true);
777               }
778             }
779           }
780         }
781         ++anIter;
782       }
783     }
784   }
785
786   VISU_Actor*
787   FindActor(SVTK_ViewWindow* theViewWindow,
788             const char* theEntry)
789   {
790     using namespace VTK;
791     if(vtkRenderer* aRenderer = theViewWindow->getRenderer()){
792       if(vtkActorCollection* aCollection = aRenderer->GetActors()){
793         if(VISU_Actor* anActor = Find<VISU_Actor>(aCollection,TIsSameEntry<VISU_Actor>(theEntry))){
794           return anActor->GetParent();
795         }
796       }
797     }
798     return NULL;
799   }
800
801   VISU_Actor*
802   FindActor(SVTK_ViewWindow* theViewWindow,
803             VISU::Prs3d_i* thePrs)
804   {
805     SALOMEDS::SObject_var aSObject = thePrs->GetSObject();
806     CORBA::String_var anEntry = aSObject->GetID();
807     return FindActor(theViewWindow,anEntry.in());
808   }
809
810   void
811   RecreateActor (const SalomeApp_Module* theModule,
812                  VISU::Prs3d_i* thePrs)
813   {
814     QApplication::setOverrideCursor(Qt::waitCursor);
815     bool isPublished = false;
816
817     SALOMEDS::SObject_var aSObject = thePrs->GetSObject();
818     CORBA::String_var anEntry = aSObject->GetID();
819
820     try {
821       thePrs->Update();
822
823       TViewWindows aViewWindows = GetViews(theModule);
824       for (int i = 0, iEnd = aViewWindows.size(); i < iEnd; i++) {
825         SVTK_ViewWindow* aView = aViewWindows[i];
826         if (VISU_Actor* anActor = FindActor(aView, anEntry.in())) {
827           isPublished = true;
828           thePrs->UpdateActor(anActor);
829         }
830       }
831     } catch (std::runtime_error& ex) {
832       INFOS(ex.what());
833       QApplication::restoreOverrideCursor();
834       SUIT_MessageBox::warn1 (GetDesktop(theModule), QObject::tr("WRN_VISU"),
835                               QObject::tr("ERR_CANT_BUILD_PRESENTATION") + ": " + QObject::tr(ex.what()),
836                               QObject::tr("BUT_OK"));
837
838       TViewWindows aViewWindows = GetViews(theModule);
839       for (int i = 0, iEnd = aViewWindows.size(); i < iEnd; i++) {
840         SVTK_ViewWindow* aView = aViewWindows[i];
841         if (VISU_Actor* anActor = FindActor(aView, anEntry.in())) {
842           aView->RemoveActor(anActor);
843           anActor->Delete();
844         }
845       }
846       return;
847     }
848     QApplication::restoreOverrideCursor();
849
850     if (!isPublished)
851       PublishInView(theModule, thePrs);
852   }
853
854   static bool ComputeVisiblePropBounds(SVTK_ViewWindow* theViewWindow,
855                                       float             allBounds[6], 
856                                       const char*       theActorClassName = "VISU_Actor")
857   {
858     vtkRenderer *aRen = theViewWindow->getRenderer();
859     vtkActorCollection *anActColl = aRen->GetActors(); 
860     vtkProp *prop;
861     float   *bounds;
862     int     somethingVisible = false;
863
864     allBounds[0] = allBounds[2] = allBounds[4] = VTK_LARGE_FLOAT;
865     allBounds[1] = allBounds[3] = allBounds[5] = -VTK_LARGE_FLOAT;
866     // loop through all props
867     for (anActColl->InitTraversal(); (prop = anActColl->GetNextProp()); ) {
868       // if it's invisible, or has no geometry, we can skip the rest 
869       if (prop->GetVisibility() && prop->IsA(theActorClassName)) {
870         bounds = prop->GetBounds();
871         // make sure we haven't got bogus bounds
872         if (bounds != NULL &&
873             bounds[0] > -VTK_LARGE_FLOAT && bounds[1] < VTK_LARGE_FLOAT &&
874             bounds[2] > -VTK_LARGE_FLOAT && bounds[3] < VTK_LARGE_FLOAT &&
875             bounds[4] > -VTK_LARGE_FLOAT && bounds[5] < VTK_LARGE_FLOAT)
876         {
877           somethingVisible = true;
878           if (bounds[0] < allBounds[0]) allBounds[0] = bounds[0]; 
879           if (bounds[1] > allBounds[1]) allBounds[1] = bounds[1]; 
880           if (bounds[2] < allBounds[2]) allBounds[2] = bounds[2]; 
881           if (bounds[3] > allBounds[3]) allBounds[3] = bounds[3]; 
882           if (bounds[4] < allBounds[4]) allBounds[4] = bounds[4]; 
883           if (bounds[5] > allBounds[5]) allBounds[5] = bounds[5]; 
884         }//not bogus
885       }
886     }
887     return somethingVisible;
888   }
889
890   void SetFitAll(SVTK_ViewWindow* theViewWindow)
891   {
892     static float PRECISION = 0.000001;
893     static float DEVIATION = 600;
894     float XYZ_Bnd[6];
895     if (!ComputeVisiblePropBounds(theViewWindow, XYZ_Bnd)) return;
896
897     float absX = XYZ_Bnd[1] - XYZ_Bnd[0];
898     float absY = XYZ_Bnd[3] - XYZ_Bnd[2];
899     float absZ = XYZ_Bnd[5] - XYZ_Bnd[4];
900
901     enum CameraOrient {e3D, eFront, eLeft, eTop};
902     CameraOrient aCameraOrient = e3D;
903     if (absX <= PRECISION) aCameraOrient = eFront;
904     else {
905       if (absY <= PRECISION) aCameraOrient = eLeft;
906       else {
907         if (absZ <= PRECISION) aCameraOrient = eTop;
908         else {
909           // all the three dimensions exceeds precision
910           float dev_abs_XY = absX / absY;
911           float dev_abs_YZ = absY / absZ;
912           float dev_abs_XZ = absX / absZ;
913           if (dev_abs_XY >= DEVIATION || 1./dev_abs_YZ >= DEVIATION)
914             aCameraOrient = eLeft;
915           else {
916             if (1./dev_abs_XY >= DEVIATION || 1./dev_abs_XZ >= DEVIATION)
917               aCameraOrient = eFront;
918             else {
919               if (dev_abs_XZ >= DEVIATION || dev_abs_YZ >= DEVIATION)
920                 aCameraOrient = eTop;
921             }
922           }
923         }
924       }
925     }
926
927     switch (aCameraOrient) {
928     case eFront: theViewWindow->onFrontView(); break;
929     case eLeft:  theViewWindow->onLeftView();  break;
930     case eTop:   theViewWindow->onTopView();   break;
931     case e3D:    theViewWindow->onResetView(); break;
932     }
933     theViewWindow->getRenderer()->ResetCameraClippingRange();
934     theViewWindow->onFitAll();
935   }
936
937   //************************************************************
938   // Plot2d View
939
940   SPlot2d_Viewer*
941   GetPlot2dViewer(const SalomeApp_Module* theModule, const bool theCreate)
942   {
943     if(SalomeApp_Application* anApp = theModule->getApp()){
944       if(SUIT_ViewManager* aViewManager = anApp->getViewManager( Plot2d_Viewer::Type(), theCreate )){
945         return dynamic_cast<SPlot2d_Viewer*>(aViewManager->getViewModel());
946       }
947     }
948     return NULL;
949   }
950
951   // Internal function used by several public functions below
952   void
953   UpdateCurve(VISU::Curve_i* theCurve,
954               Plot2d_ViewFrame* aPlot,
955               SPlot2d_Curve* plotCurve,
956               int theDisplaying)
957   {
958     if ( theDisplaying == VISU::eErase ) {
959       if ( plotCurve && aPlot )
960         aPlot->eraseCurve( plotCurve, false );
961     }
962     else if ( theDisplaying == VISU::eDisplay || theDisplaying == VISU::eDisplayOnly ) {
963       if ( plotCurve ) {
964         plotCurve->setHorTitle( theCurve->GetHorTitle().c_str() );
965         //plotCurve->setVerTitle( ( theCurve->GetVerTitle().c_str() ) );
966         plotCurve->setVerTitle( theCurve->GetName() );
967         plotCurve->setHorUnits( theCurve->GetHorUnits().c_str() );
968         plotCurve->setVerUnits( theCurve->GetVerUnits().c_str() );
969         double* xList = 0;
970         double* yList = 0;
971         int     nbPoints = theCurve->GetData( xList, yList );
972         if ( nbPoints > 0 && xList && yList ) {
973           plotCurve->setData( xList, yList, nbPoints );
974         }
975         if ( !theCurve->IsAuto() ) {
976           plotCurve->setLine( (Plot2d_Curve::LineType)theCurve->GetLine(), theCurve->GetLineWidth() );
977           plotCurve->setMarker( (Plot2d_Curve::MarkerType)theCurve->GetMarker() );
978           SALOMEDS::Color color = theCurve->GetColor();
979           plotCurve->setColor( QColor( (int)(color.R*255.), (int)(color.G*255.), (int)(color.B*255.) ) );
980         }
981         plotCurve->setAutoAssign( theCurve->IsAuto() );
982         if( aPlot )
983           aPlot->displayCurve( plotCurve, false );
984       }
985       else {
986         Plot2d_Curve* crv = theCurve->CreatePresentation();
987         if ( crv ) {
988           if( aPlot )
989             aPlot->displayCurve( crv, false );
990           theCurve->SetLine( (VISU::Curve::LineType)crv->getLine(), crv->getLineWidth() );
991           theCurve->SetMarker( (VISU::Curve::MarkerType)crv->getMarker());
992           SALOMEDS::Color newColor;
993           newColor.R = crv->getColor().red()/255.;
994           newColor.G = crv->getColor().green()/255.;
995           newColor.B = crv->getColor().blue()/255.;
996           theCurve->SetColor( newColor );
997           crv->setAutoAssign( theCurve->IsAuto() );
998         }
999       }
1000     }
1001   }
1002
1003   void
1004   PlotTable(const SalomeApp_Module* theModule,
1005             VISU::Table_i* table,
1006             int theDisplaying)
1007   {
1008     SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true ); // create if necessary
1009     if ( !aView )
1010       return;
1011     Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
1012     if ( !aPlot )
1013       return;
1014
1015     if ( theDisplaying == VISU::eDisplayOnly )
1016       aPlot->EraseAll();
1017     QList<Plot2d_Curve> clist;
1018     aPlot->getCurves( clist );
1019     _PTR(Study) aStudy = GetCStudy( GetAppStudy( theModule ) );
1020     _PTR(SObject) TableSO = aStudy->FindObjectID( table->GetEntry().latin1() );
1021     if ( TableSO ) {
1022       _PTR(ChildIterator) Iter = aStudy->NewChildIterator( TableSO );
1023       for ( ; Iter->More(); Iter->Next() ) {
1024         CORBA::Object_var childObject = VISU::ClientSObjectToObject( Iter->Value() );
1025         if( !CORBA::is_nil( childObject ) ) {
1026           CORBA::Object_ptr aCurve = VISU::Curve::_narrow( childObject );
1027           if( !CORBA::is_nil( aCurve ) ) {
1028             VISU::Curve_i* theCurve = dynamic_cast<VISU::Curve_i*>(VISU::GetServant(aCurve).in());
1029             SPlot2d_Curve* plotCurve = 0;
1030             SPlot2d_Curve* tmpCurve;
1031             for ( int i = 0; i < clist.count(); i++ ) {
1032               tmpCurve = dynamic_cast<SPlot2d_Curve*>( clist.at( i ) );
1033               if (tmpCurve && tmpCurve->hasIO() &&
1034                   !strcmp(tmpCurve->getIO()->getEntry(), theCurve->GetEntry())) {
1035                 plotCurve = tmpCurve;
1036                 break;
1037               }
1038             }
1039
1040             UpdateCurve( theCurve, aPlot, plotCurve, theDisplaying );
1041
1042             if ( theDisplaying == VISU::eErase && plotCurve ) {
1043               clist.remove( plotCurve );
1044             }
1045           }
1046         }
1047       }
1048       aPlot->Repaint();
1049     }
1050   }
1051
1052   void
1053   PlotCurve(const SalomeApp_Module* theModule,
1054             VISU::Curve_i* theCurve,
1055             int theDisplaying)
1056   {
1057     SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true );
1058     if ( !aView )
1059       return;
1060     Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
1061     if ( !aPlot )
1062       return;
1063
1064 //  if ( theDisplaying == VISU::eDisplayOnly )
1065 //    aPlot->EraseAll();
1066     QList<Plot2d_Curve> clist;
1067     aPlot->getCurves( clist );
1068     SPlot2d_Curve* plotCurve = 0;
1069     SPlot2d_Curve* tmpCurve;
1070     for (int i = 0; i < clist.count(); i++) {
1071       tmpCurve = dynamic_cast<SPlot2d_Curve*>(clist.at(i));
1072       if (tmpCurve && tmpCurve->hasIO() &&
1073           !strcmp(tmpCurve->getIO()->getEntry(), theCurve->GetEntry())) {
1074         plotCurve = tmpCurve;
1075       } else if (theDisplaying == VISU::eDisplayOnly) {
1076         aPlot->eraseCurve(clist.at(i));
1077       }
1078     }
1079
1080     UpdateCurve(theCurve, aPlot, plotCurve, theDisplaying);
1081
1082     aPlot->Repaint();
1083   }
1084
1085   void
1086   PlotContainer(const SalomeApp_Module* theModule,
1087                 VISU::Container_i* container,
1088                 int theDisplaying)
1089   {
1090     SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true );
1091     if ( !aView )
1092       return;
1093     Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
1094     if ( !aPlot )
1095       return;
1096
1097     if ( theDisplaying == VISU::eDisplayOnly )
1098       aPlot->EraseAll();
1099     QList<Plot2d_Curve> clist;
1100     aPlot->getCurves( clist );
1101     if ( container->GetNbCurves() > 0 ) {
1102       int nbCurves = container->GetNbCurves();
1103       for ( int k = 1; k <= nbCurves; k++ ) {
1104         VISU::Curve_i* theCurve = container->GetCurve( k );
1105         if ( theCurve && theCurve->IsValid() ) {
1106           SPlot2d_Curve* plotCurve = dynamic_cast<SPlot2d_Curve*>
1107             (aView->getCurveByIO(new SALOME_InteractiveObject (theCurve->GetEntry(), "", "")));
1108
1109           UpdateCurve( theCurve, aPlot, plotCurve, theDisplaying );
1110
1111           if ( plotCurve && theDisplaying == VISU::eErase ) {
1112             clist.remove( plotCurve );
1113           }
1114         }
1115       }
1116     }
1117     aPlot->Repaint();
1118   }
1119
1120   void
1121   CreatePlot(SalomeApp_Module* theModule,
1122              _PTR(SObject) theTableSO)
1123   {
1124     if ( IsSObjectTable(theTableSO) ) {
1125       CORBA::Object_var aTable = VISU::ClientSObjectToObject(theTableSO);
1126       CORBA::Object_var aContainer = GetVisuGen( theModule )->CreateContainer();
1127       if ( !CORBA::is_nil( aTable ) && !CORBA::is_nil( aContainer ) ) {
1128         VISU::Table_i*     pTable     = dynamic_cast<VISU::Table_i*>(VISU::GetServant(aTable).in());
1129         VISU::Container_i* pContainer = dynamic_cast<VISU::Container_i*>(VISU::GetServant(aContainer).in());
1130
1131         if ( pContainer && pTable ) {
1132           for ( int i = 2; i <= pTable->GetNbRows(); i++ ) {
1133             CORBA::Object_var aNewCurve = GetVisuGen( theModule )->CreateCurve( pTable->_this(), 1, i );
1134             if( !CORBA::is_nil( aNewCurve ) ) {
1135               VISU::Curve_i* pCrv = dynamic_cast<VISU::Curve_i*>( VISU::GetServant(aNewCurve).in() );
1136               if ( pCrv ) {
1137                 pContainer->AddCurve( pCrv->_this() );
1138               }
1139             }
1140           }
1141           PlotContainer( theModule, pContainer, VISU::eDisplay );
1142         }
1143       }
1144     }
1145   }
1146
1147   //************************************************************
1148   // Others
1149
1150   void CreateMesh (const SalomeApp_Module* theModule,
1151                     const Handle(SALOME_InteractiveObject)& theIO)
1152   {
1153     _PTR(Study) aStudy = GetCStudy(GetAppStudy(theModule));
1154     //if (CheckLock(aStudy))
1155     //  return;
1156
1157     _PTR(SObject) aResultSObj = aStudy->FindObjectID(theIO->getEntry());
1158
1159     // Get VISU::Result
1160     VISU::Result_var aResult;
1161     VISU::Result_i* pResult = CheckResult(theModule, aResultSObj, aResult);
1162     if (pResult == NULL)
1163       return;
1164
1165     Storable::TRestoringMap aMap = getMapOfValue(aResultSObj);
1166     bool isExist;
1167     string aComment = Storable::FindValue(aMap,"myComment",&isExist).latin1();
1168     if (!isExist)
1169       return;
1170
1171     CORBA::Object_var aMesh;
1172     string aMeshName = Storable::FindValue(aMap,"myMeshName").latin1();
1173 #ifdef CHECKTIME
1174     Utils_Timer timer;
1175     timer.Start();
1176 #endif
1177     if (aComment == "ENTITY") {
1178       VISU::Entity anEntity = (VISU::Entity)Storable::FindValue(aMap,"myId").toInt();
1179       if (VISU::Mesh_i::IsPossible(pResult,aMeshName.c_str(),anEntity))
1180         aMesh = GetVisuGen(theModule)->MeshOnEntity(aResult,aMeshName.c_str(),anEntity);
1181     } else if (aComment == "FAMILY") {
1182       VISU::Entity anEntity = (VISU::Entity)Storable::FindValue(aMap,"myEntityId").toInt();
1183       string aFamilyName = Storable::FindValue(aMap,"myName").latin1();
1184       if (VISU::Mesh_i::IsPossible(pResult,aMeshName.c_str(),anEntity,aFamilyName.c_str()))
1185         aMesh = GetVisuGen(theModule)->FamilyMeshOnEntity
1186           (aResult,aMeshName.c_str(),anEntity,aFamilyName.c_str());
1187     } else if (aComment == "GROUP") {
1188       string aGroupName = Storable::FindValue(aMap,"myName").latin1();
1189       if (VISU::Mesh_i::IsPossible(pResult,aMeshName.c_str(),aGroupName.c_str()))
1190         aMesh = GetVisuGen(theModule)->GroupMesh(aResult,aMeshName.c_str(),aGroupName.c_str());
1191     }
1192 #ifdef CHECKTIME
1193     timer.Stop();
1194     MESSAGE("VisuGUI::CreateMesh() - CREATE MESH");
1195     timer.Show();
1196 #endif
1197
1198     QApplication::restoreOverrideCursor();
1199     VISU::Mesh_i* pPresent = NULL;
1200     if (!CORBA::is_nil(aMesh))
1201       pPresent = dynamic_cast<VISU::Mesh_i*>(VISU::GetServant(aMesh).in());
1202     if (pPresent == NULL) {
1203       SUIT_MessageBox::warn1 (GetDesktop(theModule),
1204                               QObject::tr("WRN_VISU"),
1205                               QObject::tr("ERR_CANT_BUILD_PRESENTATION"),
1206                               QObject::tr("BUT_OK"));
1207       return;
1208     }
1209
1210     if (SVTK_ViewWindow* aView = GetViewWindow(theModule)) {
1211       try {
1212 #ifdef CHECKTIME
1213         Utils_Timer timer;
1214         timer.Start();
1215 #endif
1216         PublishInView(theModule, pPresent);
1217         //aView->onFitAll();
1218         SetFitAll(aView);
1219 #ifdef CHECKTIME
1220         timer.Stop();
1221         MESSAGE("VisuGUI::CreateMesh() - DISPLAY MESH");
1222         timer.Show();
1223 #endif
1224         theModule->application()->putInfo(QObject::tr("INF_DONE"));
1225         // Make "Save" button active
1226         theModule->getApp()->updateActions();
1227       } catch (std::runtime_error& exc) {
1228         INFOS(exc.what());
1229         SUIT_MessageBox::warn1 (GetDesktop(theModule),
1230                                 QObject::tr("WRN_VISU"),
1231                                 QObject::tr("ERR_CANT_CREATE_ACTOR") + ": " + QObject::tr(exc.what()),
1232                                 QObject::tr("BUT_OK"));
1233       }
1234     }
1235   }
1236
1237   // ========================================================================================
1238   // GetPrs3dList: find list of presentations for the given object
1239   // ========================================================================================
1240   std::vector<VISU::Prs3d_i*> GetPrs3dList (const SalomeApp_Module* theModule,
1241                                             const Handle(SALOME_InteractiveObject)& theIO)
1242   {
1243     std::vector<VISU::Prs3d_i*> aList;
1244     if (!theIO.IsNull() && theIO->hasEntry()) {
1245       _PTR(Study) aCStudy = GetCStudy(GetAppStudy(theModule));
1246       _PTR(SObject) aSObject = aCStudy->FindObjectID(theIO->getEntry());
1247       aList = GetPrs3dList(theModule, aSObject);
1248     }
1249     return aList;
1250   }
1251
1252   std::vector<VISU::Prs3d_i*> GetPrs3dList (const SalomeApp_Module* theModule,
1253                                             _PTR(SObject) theObject)
1254   {
1255     std::vector<VISU::Prs3d_i*> aList; int k = 0;
1256     if (!theObject)
1257       return aList;
1258
1259     _PTR(Study) aCStudy = GetCStudy(GetAppStudy(theModule));
1260
1261     CORBA::Object_var aCORBAObject = VISU::ClientSObjectToObject(theObject);
1262     if (!CORBA::is_nil(aCORBAObject)) {
1263       VISU::Base_var aVisuObj = VISU::Base::_narrow(aCORBAObject);
1264       if (!CORBA::is_nil(aVisuObj)) {
1265         VISU::VISUType aType = aVisuObj->GetType();
1266         switch (aType) {
1267         case VISU::TSCALARMAP:
1268         case VISU::TISOSURFACE:
1269         case VISU::TDEFORMEDSHAPE:
1270         case VISU::TCUTPLANES:
1271         case VISU::TCUTLINES:
1272         case VISU::TVECTORS:
1273         case VISU::TSTREAMLINES:
1274         case VISU::TPLOT3D:
1275           {
1276             PortableServer::ServantBase_var aServant = VISU::GetServant(aCORBAObject);
1277             if (aServant.in()) {
1278               VISU::Prs3d_i* aPrsObject = dynamic_cast<VISU::Prs3d_i*>(aServant.in());
1279               aList.resize(k+1);
1280               aList[k] = aPrsObject;
1281               k++;
1282             }
1283           }
1284           break;
1285         case VISU::TFIELD:
1286           {
1287             _PTR(ChildIterator) anIter = aCStudy->NewChildIterator(theObject);
1288             _PTR(SObject) aTimeStamp;
1289             anIter->Next(); // First is reference on support
1290             for (; anIter->More(); anIter->Next()) {
1291               aTimeStamp = anIter->Value();
1292               if (!aTimeStamp) continue;
1293               std::vector<VISU::Prs3d_i*> aSubList = GetPrs3dList(theModule, aTimeStamp);
1294               if (!aSubList.empty()) {
1295                 int n = aSubList.size();
1296                 aList.resize(k+n);
1297                 for (int i = 0; i < n; i++) {
1298                   aList[k] = aSubList[i];
1299                   k++;
1300                 }
1301               }
1302             }
1303           }
1304           break;
1305         }
1306       }
1307     } else {
1308       _PTR(GenericAttribute) anAttr;
1309       if (theObject->FindAttribute(anAttr, "AttributeComment")) {
1310         _PTR(AttributeComment) aComment (anAttr);
1311         string aComm = aComment->Value();
1312         QString strIn (aComm.c_str());
1313         VISU::Storable::TRestoringMap pMap;
1314         VISU::Storable::StrToMap(strIn, pMap);
1315         bool isExist;
1316         VISU::VISUType aType =
1317           (VISU::VISUType)VISU::Storable::FindValue(pMap,"myType",&isExist).toInt();
1318         if (isExist) {
1319           switch (aType) {
1320           case VISU::TFIELD:
1321             {
1322               _PTR(ChildIterator) anIter = aCStudy->NewChildIterator(theObject);
1323               _PTR(SObject) aTimeStamp;
1324               anIter->Next(); // First is reference on support
1325               for (; anIter->More(); anIter->Next()) {
1326                 aTimeStamp = anIter->Value();
1327                 if (!aTimeStamp) continue;
1328                 std::vector<VISU::Prs3d_i*> aSubList = GetPrs3dList(theModule, aTimeStamp);
1329                 if (!aSubList.empty()) {
1330                   int n = aSubList.size();
1331                   aList.resize(k+n);
1332                   for (int i = 0; i < n; i++) {
1333                     aList[k] = aSubList[i];
1334                     k++;
1335                   }
1336                 }
1337               }
1338             }
1339             break;
1340           case VISU::TTIMESTAMP:
1341             {
1342               _PTR(ChildIterator) anIter = aCStudy->NewChildIterator(theObject);
1343               _PTR(SObject) aPrs;
1344               for (; anIter->More(); anIter->Next()) {
1345                 aPrs = anIter->Value();
1346                 if (!aPrs) continue;
1347                 std::vector<VISU::Prs3d_i*> aSubList = GetPrs3dList(theModule, aPrs);
1348                 if (!aSubList.empty()) {
1349                   int n = aSubList.size();
1350                   aList.resize(k+n);
1351                   for (int i = 0; i < n; i++) {
1352                     aList[k] = aSubList[i];
1353                     k++;
1354                   }
1355                 }
1356               }
1357             }
1358             break;
1359           }
1360         }
1361       }
1362     }
1363     return aList;
1364   }
1365 }