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