]> SALOME platform Git repositories - modules/visu.git/blob - src/VISUGUI/VisuGUI_Tools.cxx
Salome HOME
IPAL20982 Regression. Functionality â\80\9cUnshrinkâ\80\9d works incorrectly
[modules/visu.git] / src / VISUGUI / VisuGUI_Tools.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  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.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //  VISU VISUGUI : GUI of VISU component
23 //  File   : VisuGUI_Tools.cxx
24 //  Author : Sergey Anikin
25 //  Module : VISU
26 //
27 #include "VisuGUI_Tools.h"
28 #include "VisuGUI_ViewTools.h"
29 #include "VisuGUI_Prs3dTools.h"
30 #include "VisuGUI_DialogRunner.h"
31
32 #include "VisuGUI.h"
33
34 #include "VISU_Gen_i.hh"
35 #include "VISU_Prs3d_i.hh"
36 #include "VISU_Result_i.hh"
37 #include "VISU_Table_i.hh"
38 //#include "VISU_Mesh_i.hh"
39 #include "VISU_ViewManager_i.hh"
40
41 #include "VISU_Actor.h"
42 #include "VISU_ScalarMapAct.h"
43
44 #include "SalomeApp_Module.h"
45 #include "SalomeApp_Study.h"
46 #include "SalomeApp_Application.h"
47
48 #include "LightApp_DataObject.h"
49 #include "LightApp_SelectionMgr.h"
50
51 //TODO
52 //#include "OB_Browser.h"
53
54 #include "SALOME_ListIO.hxx"
55 #include "SALOME_ListIteratorOfListIO.hxx"
56
57 #include "SVTK_ViewWindow.h"
58 #include "SVTK_Functor.h"
59
60 #include "VTKViewer_Algorithm.h"
61
62 #include "SPlot2d_ViewModel.h"
63 #include "Plot2d_ViewFrame.h"
64 #include "Plot2d_ViewManager.h"
65
66 #include "SUIT_Session.h"
67 #include "SUIT_MessageBox.h"
68 #include "SUIT_Desktop.h"
69 #include "SUIT_ViewWindow.h"
70
71 #include "CAM_DataModel.h"
72
73 #include <vtkRenderer.h>
74 #include <vtkActorCollection.h>
75
76 #include <QString>
77 #include <QSpinBox>
78 #include <QDoubleSpinBox>
79
80 using namespace std;
81
82 //=============================================================================
83 namespace VISU
84 {
85   //------------------------------------------------------------
86   SUIT_Desktop*
87   GetDesktop(const CAM_Module* theModule)
88   {
89     return theModule->application()->desktop();
90   }
91
92   //------------------------------------------------------------
93   LightApp_SelectionMgr*
94   GetSelectionMgr(const SalomeApp_Module* theModule)
95   {
96     return theModule->getApp()->selectionMgr();
97   }
98
99   //------------------------------------------------------------
100   SalomeApp_Study*
101   GetAppStudy(const CAM_Module* theModule)
102   {
103     return
104       dynamic_cast<SalomeApp_Study*>(theModule->application()->activeStudy());
105   }
106
107   //------------------------------------------------------------
108   _PTR(Study)
109   GetCStudy(const SalomeApp_Study* theStudy)
110   {
111     return theStudy->studyDS();
112   }
113
114   //------------------------------------------------------------
115   bool
116   IsStudyLocked( _PTR(Study) theStudy )
117   {
118     if( theStudy )
119       return theStudy->GetProperties()->IsLocked();
120     return true;
121   }
122
123   //------------------------------------------------------------
124   bool
125   CheckLock( _PTR(Study) theStudy,
126              QWidget* theWidget )
127   {
128     if(IsStudyLocked(theStudy)){
129       SUIT_MessageBox::warning(theWidget,
130                                QObject::tr("WRN_VISU_WARNING"),
131                                QObject::tr("WRN_STUDY_LOCKED") );
132         return true;
133     }
134     return false;
135   }
136
137   //------------------------------------------------------------
138   int
139   runAndWait( QDialog* dlg, const bool modal )
140   {
141     VisuGUI_DialogRunner r( dlg );
142     return r.run( modal );
143   }
144
145   //------------------------------------------------------------
146   LightApp_DataObject*
147   FindDataObject(SUIT_DataObject* theDataObject,
148                  const QString& theEntry,
149                  int theLevel)
150   {
151     int aLevel = theDataObject->level() + 2;
152     QString aSourceEntry = theEntry.section(':',0,aLevel);
153     DataObjectList aList;
154     theDataObject->children(aList);
155     DataObjectList::Iterator aDataObjectIter = aList.begin();
156     while( aDataObjectIter!= aList.end() ) {
157       if(LightApp_DataObject* aChildDataObject = dynamic_cast<LightApp_DataObject*>(*aDataObjectIter)){
158         QString anEntry = aChildDataObject->entry();
159         QString aCurrentEntry = anEntry.section(':',0,aLevel);
160         if(aSourceEntry == aCurrentEntry){
161           if(theLevel == aLevel){
162             return aChildDataObject;
163           }else{
164             return FindDataObject(aChildDataObject,theEntry,theLevel);
165           }
166         }
167       }
168       aDataObjectIter++;
169     }
170     return NULL;
171   }
172
173   //------------------------------------------------------------
174   LightApp_DataObject*
175   FindDataObject(CAM_Module* theModule,
176                  _PTR(SObject) theSObject)
177   {
178     CAM_DataModel* aDataModel = theModule->dataModel();
179     CAM_DataObject* aRootDataObject = aDataModel->root();
180     if(_PTR(SComponent) aComponent = theSObject)
181       return dynamic_cast<LightApp_DataObject*>(aRootDataObject);
182
183     int aLevel = theSObject->Depth();
184     std::string anEntry = theSObject->GetID();
185     return FindDataObject(aRootDataObject,anEntry.c_str(),aLevel);
186   }
187
188   //------------------------------------------------------------
189   void
190   UpdateObjBrowser(SalomeApp_Module* theModule,
191                    bool theIsUpdateDataModel,
192                    _PTR(SObject) theSObject)
193   {
194     LightApp_DataObject* aDataObject = NULL;
195     if(theSObject)
196       aDataObject = FindDataObject(theModule,theSObject);
197
198     theModule->updateObjBrowser(theIsUpdateDataModel,aDataObject);
199     theModule->getApp()->updateActions();
200   }
201
202   //------------------------------------------------------------
203   bool
204   IsSObjectTable( _PTR(SObject) theSObject )
205   {
206     if ( theSObject ) {
207       _PTR(GenericAttribute) anAttr;
208       if (theSObject->FindAttribute( anAttr, "AttributeTableOfInteger" ))
209         return true;
210       if (theSObject->FindAttribute( anAttr, "AttributeTableOfReal" ))
211         return true;
212     }
213     return false;
214   }
215
216   //------------------------------------------------------------
217   VISU_Gen_i*
218   GetVisuGen(const CAM_Module* theModule)
219   {
220     static VISU_Gen_i* aGen = NULL;
221     if(!aGen){
222       SALOME_LifeCycleCORBA aLCC(SalomeApp_Application::namingService());
223       Engines::Component_var aComponent = aLCC.FindOrLoad_Component("FactoryServer","VISU");
224       VISU_Gen_var aVISU = VISU_Gen::_narrow(aComponent);
225       if(!CORBA::is_nil(aVISU)){
226         if((aGen = VISU_Gen_i::GetVisuGenImpl()))
227           aGen->SetCurrentStudy(GetDSStudy(GetCStudy(GetAppStudy(theModule))));
228       }
229     }
230     if(!aGen)
231       throw std::runtime_error(QObject::tr("ERR_CANT_FIND_VISU_COMPONENT").toLatin1().data());
232     return aGen;
233   }
234
235   //------------------------------------------------------------
236   SALOME_MED::MED_Gen_var
237   GetMEDEngine()
238   {
239     static SALOME_MED::MED_Gen_var aGen;
240     if(CORBA::is_nil(aGen)){
241       SALOME_LifeCycleCORBA aLCC(SalomeApp_Application::namingService());
242       Engines::Component_var aComponent = aLCC.FindOrLoad_Component("FactoryServer","MED");
243       aGen = SALOME_MED::MED_Gen::_narrow(aComponent);
244     }
245     if(CORBA::is_nil(aGen))
246       throw std::runtime_error(QObject::tr("ERR_CANT_FIND_MED_COMPONENT").toLatin1().data());
247     return aGen;
248   }
249
250
251   //----------------------------------------------------------------------------
252   // Selection
253   TSelectionInfo
254   GetSelectedObjects(const SalomeApp_Module* theModule)
255   {
256     TSelectionInfo aSelectionInfo;
257     const SalomeApp_Study* aStudy = GetAppStudy(theModule);
258     LightApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(theModule);
259     SALOME_ListIO aListIO;
260     aSelectionMgr->selectedObjects(aListIO);
261     SALOME_ListIteratorOfListIO anIter(aListIO);
262     while(anIter.More())
263     {
264       Handle(SALOME_InteractiveObject) anIO = anIter.Value();
265       if(anIO->hasEntry())
266       {
267         TObjectInfo anObjectInfo = GetObjectByEntry(aStudy, anIO->getEntry());
268         if(anObjectInfo.mySObject){
269           TSelectionItem aSelectionItem;
270           aSelectionItem.myObjectInfo = anObjectInfo;
271           aSelectionItem.myIO = anIO;
272           aSelectionInfo.push_back(aSelectionItem);
273         }
274       }
275       anIter.Next(); // MULTIPR fixed
276     }
277     return aSelectionInfo;
278   }
279
280   //----------------------------------------------------------------------------
281   TObjectInfo
282   GetObjectByEntry(const SalomeApp_Study* theStudy,
283                    const std::string& theEntry)
284   {
285     TObjectInfo anObjectInfo;
286     if(!theStudy || theEntry == "")
287       return anObjectInfo;
288
289     _PTR(Study) aStudy = GetCStudy(theStudy);
290     if(_PTR(SObject) aSObject = aStudy->FindObjectID(theEntry)){
291       anObjectInfo.mySObject = aSObject;
292       CORBA::Object_var anObject = ClientSObjectToObject(aSObject);
293       if(VISU::Base_i* aBase = GetServantInterface<VISU::Base_i>(anObject))
294         anObjectInfo.myBase = aBase;
295     }
296     
297     return anObjectInfo;
298   }
299
300
301   //----------------------------------------------------------------------------
302   VISU::Prs3d_i*
303   GetPrs3dToModify(const SalomeApp_Module* theModule,
304                    Base_i* theBase)
305   {
306     if (CheckLock(GetCStudy(GetAppStudy(theModule)), GetDesktop(theModule)))
307       return NULL;
308
309     return GetPrs3dFromBase(theBase);
310   }
311
312   //----------------------------------------------------------------------------
313   VISU::Prs3d_i*
314   GetPrs3dFromBase(Base_i* theBase)
315   {
316     if(theBase && theBase->GetType() == VISU::TCOLOREDPRS3DHOLDER){
317       CORBA::Object_var anObject = theBase->_this();
318       VISU::ColoredPrs3dHolder_var aHolder = VISU::ColoredPrs3dHolder::_narrow(anObject);
319       VISU::Prs3d_var aPrs3d = aHolder->GetDevice();
320       return VISU::GetServantInterface<VISU::Prs3d_i>(aPrs3d);
321     }
322     return dynamic_cast<VISU::Prs3d_i*>(theBase);
323   }
324
325
326   //----------------------------------------------------------------------------
327   bool
328   GetPrs3dSelectionInfo(const SalomeApp_Module* theModule,
329                         VISU::Prs3d_i*& thePrs3d,
330                         SVTK_ViewWindow*& theViewWindow,
331                         VISU_Actor*& thenActor)
332   {
333     VISU::TSelectionInfo aSelectionInfo = VISU::GetSelectedObjects(theModule);
334     if(aSelectionInfo.empty())
335       return false;
336   
337     VISU::TSelectionItem aSelectionItem = aSelectionInfo.front();
338     thePrs3d = GetPrs3dFromBase(aSelectionItem.myObjectInfo.myBase);
339     if(!thePrs3d)
340       return false;
341   
342     theViewWindow = GetActiveViewWindow<SVTK_ViewWindow>(theModule);
343     if(!theViewWindow)
344       return false;
345   
346     thenActor = FindActor(theViewWindow, thePrs3d);
347     if(!thenActor)
348       return false;
349     
350     return true;
351   }
352
353
354   //----------------------------------------------------------------------------
355   void
356   Add(LightApp_SelectionMgr* theSelectionMgr,
357       const Handle(SALOME_InteractiveObject)& theIO)
358   {
359     SALOME_ListIO aListIO;
360     theSelectionMgr->selectedObjects(aListIO);
361     aListIO.Append(theIO);
362     theSelectionMgr->setSelectedObjects(aListIO);
363   }
364
365   //------------------------------------------------------------
366   void
367   Remove(LightApp_SelectionMgr* theSelectionMgr,
368          const Handle(SALOME_InteractiveObject)& theIO)
369   {
370     if (theIO.IsNull()) return;
371     SALOME_ListIO aListIO, aNewListIO;
372     theSelectionMgr->selectedObjects(aListIO);
373     SALOME_ListIteratorOfListIO anIter (aListIO);
374     for (; anIter.More(); anIter.Next()) {
375       Handle(SALOME_InteractiveObject) anIO = anIter.Value();
376       if (!anIO->isSame(theIO)) {
377         aNewListIO.Append(theIO);
378       }
379     }
380     theSelectionMgr->setSelectedObjects(aNewListIO);
381   }
382
383   /*!
384    * \brief Check, if the object can be deleted
385    *
386    * \param theEntry - entry of the object to check
387    * \param theModule - is used to access Study and VISU_Gen
388    * \retval bool - returns TRUE if the object is removable
389    */
390   bool
391   IsRemovable (const std::string theEntry,
392                const SalomeApp_Module* theModule)
393   {
394     // asv : if selected object is a Save Point object selected in object browser - return false
395     if ( QString( theEntry.c_str() ).startsWith( QObject::tr( "SAVE_POINT_DEF_NAME" ) ) )
396       return false;
397
398     _PTR(Study) aStudy = GetCStudy(GetAppStudy(theModule));
399
400     _PTR(SObject) aSObject = aStudy->FindObjectID(theEntry);
401     VISU::Storable::TRestoringMap pMap;
402     if (aSObject) {
403       CORBA::Object_var aCORBAObject = VISU::ClientSObjectToObject(aSObject);
404       if (!CORBA::is_nil(aCORBAObject)) {
405         VISU::RemovableObject_var aRemovableObj = VISU::RemovableObject::_narrow(aCORBAObject);
406         if (CORBA::is_nil(aRemovableObj)) {
407           // Not removable CORBA object
408           return false;
409         }
410       } else {
411         // Can be removed, if lays directly under VISU
412         // (first sub-level) or is a child of such an object
413         string aNAME, aVisuNAME = GetVisuGen(theModule)->ComponentDataType();
414         _PTR(GenericAttribute) anAttr;
415         _PTR(AttributeString) aComment;
416
417         _PTR(SObject) aRefSObject;
418         if (aSObject->ReferencedObject(aRefSObject)) {
419           // It can be a reference on curve, published under a container. IPAL 20317
420           VISU::TObjectInfo aRefObjectInfo = GetObjectByEntry(GetAppStudy(theModule), aRefSObject->GetID());
421           VISU::Base_i* aRefBase = aRefObjectInfo.myBase;
422           if( (aRefBase && aRefBase->GetType() == VISU::TCURVE) || (aRefBase && aRefBase->GetType() == VISU::TMESH) )
423             return true;
424         }
425
426         bool isUnderVISU = false;
427         _PTR(SObject) aFatherSObject = aSObject->GetFather();
428         if (aFatherSObject->FindAttribute(anAttr, "AttributeName")) {
429           // mkr : 24.11.2006 : use AttributeName and module title for correct "Delete"
430           //                    popup item displaying in object browser popup
431           _PTR(AttributeName) aComment (anAttr);
432           aNAME = aComment->Value();
433           QString aVisuTITLE = theModule->getApp()->moduleTitle(aVisuNAME.c_str());
434           if (!aVisuTITLE.compare(aNAME.c_str())) {
435             isUnderVISU = true;
436           }
437         }
438         if (!isUnderVISU) {
439           // Not directly under VISU component, check father
440           aCORBAObject = VISU::ClientSObjectToObject(aFatherSObject);
441           if (!CORBA::is_nil(aCORBAObject)) {
442             // Father has IOR
443             return false;
444           }
445
446           isUnderVISU = false;
447           aFatherSObject = aFatherSObject->GetFather();
448           if (aFatherSObject->FindAttribute(anAttr, "AttributeString")) {
449             _PTR(AttributeString) aComment (anAttr);
450             aNAME = aComment->Value();
451             if (aNAME == aVisuNAME) {
452               isUnderVISU = true;
453             }
454           }
455           if (!isUnderVISU) {
456             // Father is not directly under VISU component
457             return false;
458           }
459         }
460       }
461     }
462     return true;
463   }
464
465   /*!
466    * \brief Check, if "Delete" popup-menu can be put on current selection
467    *
468    * \param theModule - is used to access SelectionManager, Study and VISU_Gen
469    * \retval bool - returns TRUE if all currently selected objects are removable
470    */
471   bool
472   IsRemovableSelected (const SalomeApp_Module* theModule)
473   {
474     LightApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(theModule);
475     SALOME_ListIO aListIO;
476     aSelectionMgr->selectedObjects(aListIO);
477
478     if (aListIO.Extent() < 1)
479       return false;
480
481     _PTR(Study) aStudy = GetCStudy(GetAppStudy(theModule));
482     if (!aStudy) return false;
483
484     SALOME_ListIteratorOfListIO anIter (aListIO);
485     for (; anIter.More(); anIter.Next()) {
486       Handle(SALOME_InteractiveObject) anIO = anIter.Value();
487       if (anIO->hasEntry()) {
488         if (!IsRemovable(anIO->getEntry(), theModule))
489           return false;
490       }
491     }
492     return true;
493   }
494
495   //------------------------------------------------------------
496   void
497   DeleteSObject(VisuGUI* theModule,
498                 _PTR(Study) theStudy,
499                 _PTR(SObject) theSObject)
500   {
501     _PTR(ChildIterator) aChildIter = theStudy->NewChildIterator(theSObject);
502     for (aChildIter->InitEx(true); aChildIter->More(); aChildIter->Next()) {
503       _PTR(SObject) aSObject = aChildIter->Value();
504       TObjectInfo anObjectInfo = GetObjectByEntry(GetAppStudy(theModule), aSObject->GetID());
505       ErasePrs(theModule, anObjectInfo.myBase, /*repaint_view_window = */false);
506     }
507
508     TObjectInfo anObjectInfo = GetObjectByEntry(GetAppStudy(theModule), theSObject->GetID());
509     if(anObjectInfo.myBase){
510       ErasePrs(theModule, anObjectInfo.myBase, /*repaint_view_window = */true);
511
512       CORBA::Object_var anObject = ClientSObjectToObject(theSObject);
513       VISU::RemovableObject_var aRemovableObject = VISU::RemovableObject::_narrow(anObject);
514       if (!CORBA::is_nil(aRemovableObject)) {
515         aRemovableObject->RemoveFromStudy();
516       }
517     } else {
518       // Remove aSObject together with all its sub-objects
519       VISU::RemoveFromStudy(theSObject,
520                             false,  // remove not only IOR attribute, but Object With Children
521                             false); // not Destroy() sub-objects
522     }
523   }
524
525   //------------------------------------------------------------
526   void
527   DeletePrs3d(VisuGUI* theModule,
528               VISU::Prs3d_i* thePrs)
529   {
530     if (!thePrs)
531       return;
532
533     if (CheckLock(GetCStudy(GetAppStudy(theModule)),GetDesktop(theModule)))
534       return;
535
536     if(SVTK_ViewWindow* aViewWindow = GetActiveViewWindow<SVTK_ViewWindow>(theModule))
537       RemoveScalarBarPosition(theModule, aViewWindow, thePrs);
538
539     if(VISU::ColoredPrs3d_i* aColoredPrs3d = dynamic_cast<VISU::ColoredPrs3d_i*>(thePrs)){
540       std::string anEntry = aColoredPrs3d->GetHolderEntry();
541       if(anEntry != ""){
542         VISU::TObjectInfo anObjectInfo = VISU::GetObjectByEntry(GetAppStudy(theModule), anEntry);
543         if(VISU::Base_i* aBase = anObjectInfo.myBase){
544           if(aBase->GetType() == VISU::TCOLOREDPRS3DHOLDER){
545             CORBA::Object_var anObject = aBase->_this();
546             VISU::RemovableObject_var aRemovableObject = VISU::RemovableObject::_narrow(anObject);
547             aRemovableObject->RemoveFromStudy();
548             return;
549           }
550         }
551       }
552     } 
553       
554     thePrs->RemoveFromStudy();
555       
556   }
557
558   //------------------------------------------------------------
559   // Presentation management
560   void
561   ChangeRepresentation (const SalomeApp_Module* theModule,
562                         VISU::PresentationType  theType)
563   {
564     TSelectionInfo aSelectionInfo = GetSelectedObjects(theModule);
565     if(aSelectionInfo.empty())
566       return;
567
568     VISU::Prs3d_i* aPrs3d;
569     VISU::PointMap3d_i* aTable;
570     VISU_Actor* anActor;
571     VISU_ActorBase* anActorBase;
572
573     TSelectionItem aSelectionItem = aSelectionInfo.front();
574     aPrs3d = GetPrs3dFromBase(aSelectionItem.myObjectInfo.myBase);
575     if(!aPrs3d) {
576       aTable = dynamic_cast<VISU::PointMap3d_i*>(aSelectionItem.myObjectInfo.myBase);      
577       if(!aTable)
578         return;
579     }
580
581     SVTK_ViewWindow* aViewWindow = GetActiveViewWindow<SVTK_ViewWindow>(theModule);
582     if(!aViewWindow)
583       return;
584
585     if (aPrs3d) {
586       anActor = FindActor(aViewWindow, aPrs3d);
587       if(!anActor)
588         return;
589     } else {
590       anActorBase = VISU::FindActorBase(aViewWindow, aTable);
591       if(!anActorBase)
592         return;
593     }
594
595     switch (theType) {
596     case VISU::SHRINK:
597       if (aPrs3d) {
598         bool toShrink;
599         if (anActor->IsShrunk()) {
600           anActor->UnShrink();
601           toShrink = false;
602         }
603         else {
604           anActor->SetShrink();
605           toShrink = true;
606         }
607         if (VISU::Mesh_i* aMesh = dynamic_cast<VISU::Mesh_i*>(aPrs3d)) {
608           aMesh->SetShrink(toShrink);
609         }
610       } else if (aTable) {
611         if (anActorBase->IsShrunk())
612           anActorBase->UnShrink();
613         else
614           anActorBase->SetShrink();
615       }
616       break;
617     default:
618       if (aPrs3d) {
619         if (VISU::Mesh_i* aMesh = dynamic_cast<VISU::Mesh_i*>(aPrs3d)) {
620           aMesh->SetPresentationType(theType);
621           RecreateActor(theModule, aMesh);
622         } else {
623           anActor->SetRepresentation(theType);
624         }
625       }
626       else if (aTable) {
627         anActorBase->SetRepresentation(theType);
628       }
629     }
630     aViewWindow->Repaint();
631   }
632
633   //------------------------------------------------------------
634   void
635   SetShading ( const SalomeApp_Module* theModule,
636               bool theOn )
637   {
638     TSelectionInfo aSelectionInfo = GetSelectedObjects(theModule);
639     if(aSelectionInfo.empty())
640       return;
641
642     TSelectionItem aSelectionItem = GetSelectedObjects(theModule).front();
643     VISU::Prs3d_i* aPrs3d = GetPrs3dFromBase(aSelectionItem.myObjectInfo.myBase);
644     if(!aPrs3d)
645       return;
646
647     SVTK_ViewWindow* aViewWindow = GetActiveViewWindow<SVTK_ViewWindow>(theModule);
648     if(!aViewWindow)
649       return;
650
651     VISU_Actor* anActor = FindActor(aViewWindow, aPrs3d);
652     if(!anActor)
653       return;
654
655     if(VISU_ScalarMapAct* aScalarMapActor = dynamic_cast<VISU_ScalarMapAct*>(anActor)){
656       aScalarMapActor->SetShading(theOn);
657       aViewWindow->Repaint();
658     }
659   }
660
661   //------------------------------------------------------------
662   // SObject type
663   bool
664   CheckTimeStamp(const SalomeApp_Module* theModule,
665                  _PTR(SObject)&          theSObject,
666                  Handle(SALOME_InteractiveObject)& theIO,
667                  ColoredPrs3d_i::EPublishInStudyMode& thePublishInStudyMode)
668   {
669     TSelectionInfo aSelectionInfo = GetSelectedObjects(theModule);
670     if(!aSelectionInfo.empty()){
671       TSelectionItem aSelectionItem = aSelectionInfo.front();
672       theIO = aSelectionItem.myIO;
673       theSObject = aSelectionItem.myObjectInfo.mySObject;
674       VISU::VISUType aType = VISU::Storable::SObject2Type(theSObject);
675       if (VISU::TTIMESTAMP == aType){
676         thePublishInStudyMode = ColoredPrs3d_i::EPublishUnderTimeStamp;
677         return true;
678       }
679       if (VISU::TFIELD == aType){
680         thePublishInStudyMode = ColoredPrs3d_i::EPublishIndependently;
681         if(theSObject->FindSubObject(2,theSObject))
682           return true;
683       }
684     }
685     SUIT_MessageBox::warning(GetDesktop(theModule),
686                              QObject::tr("WRN_VISU"),
687                              QObject::tr("WRN_NO_AVAILABLE_DATA") );
688     return false;
689   }
690
691   //------------------------------------------------------------
692   VISU::Result_i*
693   CheckResult(const SalomeApp_Module* theModule,
694               _PTR(SObject)           theSource,
695               VISU::Result_var&       theResult)
696   {
697     if(theSource->Depth() < 3) // Bug of SALOMEDS : can\t get father from root object
698       return NULL;
699       
700     _PTR(SObject) aSObj = theSource->GetFather();
701     if (!aSObj)
702       return NULL;
703
704     aSObj = aSObj->GetFather();
705     if (!aSObj)
706       return NULL;
707
708     aSObj = aSObj->GetFather();
709     if (!aSObj)
710       return NULL;
711
712     CORBA::Object_var anObject = VISU::ClientSObjectToObject(aSObj);
713     if (CORBA::is_nil(anObject)) {
714       aSObj = aSObj->GetFather();
715       if (!aSObj)
716         return NULL;
717       anObject = VISU::ClientSObjectToObject(aSObj);
718     }
719
720     if (CORBA::is_nil(anObject))
721       return NULL;
722
723     theResult = VISU::Result::_narrow(anObject);
724     return dynamic_cast<VISU::Result_i*>(VISU::GetServant(anObject).in());
725   }
726
727   //------------------------------------------------------------
728   // VTK View
729   VISU_Actor*
730   PublishMeshInView(const SalomeApp_Module* theModule,
731                     VISU::Prs3d_i* thePrs,
732                     SVTK_ViewWindow* theViewWindow)
733   {
734     VISU_Actor* aActor = NULL;
735     if (!thePrs || !theViewWindow)
736       return aActor;
737
738     QApplication::setOverrideCursor( Qt::WaitCursor );
739     try {
740       if ((aActor = thePrs->CreateActor()))
741         theViewWindow->AddActor(aActor);
742     } catch(std::exception& exc) {
743       SUIT_MessageBox::warning
744         (GetDesktop(theModule), QObject::tr("WRN_VISU"),
745          QObject::tr("ERR_CANT_CREATE_ACTOR") + ": " + QObject::tr(exc.what()) );
746     }
747     QApplication::restoreOverrideCursor();
748
749     return aActor;
750   }
751
752   //------------------------------------------------------------
753   void
754   RepaintViewWindows (const SalomeApp_Module* theModule,
755                       const Handle(SALOME_InteractiveObject)& theIObject)
756   {
757     TViewWindows aViewWindows;
758     if (SalomeApp_Application* anApp = theModule->getApp()) {
759       ViewManagerList aViewManagerList;
760       anApp->viewManagers(SVTK_Viewer::Type(),aViewManagerList);
761       QList<SUIT_ViewManager*>::Iterator anIter = aViewManagerList.begin();
762       while ( anIter != aViewManagerList.end() )
763       {
764         QVector<SUIT_ViewWindow*> aViews = (*anIter)->getViews();
765         for (int i = 0, iEnd = aViews.size(); i < iEnd; i++) {
766           if (SUIT_ViewWindow* aViewWindow = aViews.at(i)) {
767             if (SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>(aViewWindow)) {
768               if (vw->isVisible(theIObject)) {
769                 vw->getRenderer()->ResetCameraClippingRange();
770                 vw->Repaint();
771                 vw->highlight(theIObject, true, true);
772               }
773             }
774           }
775         }
776         anIter++;
777       }
778     }
779   }
780
781   //------------------------------------------------------------
782   VISU_Actor*
783   FindActor(const SalomeApp_Study* theStudy,
784             SVTK_ViewWindow* theViewWindow,
785             const QString& theEntry)
786   {
787     TObjectInfo anObjectInfo = GetObjectByEntry(theStudy, theEntry.toLatin1().data());
788     VISU::Prs3d_i* aPrs3d = GetPrs3dFromBase(anObjectInfo.myBase);
789     return FindActor(theViewWindow, aPrs3d);
790   }
791
792   //------------------------------------------------------------
793   VISU_ActorBase*
794   FindActorBase(const SalomeApp_Study* theStudy,
795                 SVTK_ViewWindow* theViewWindow,
796                 const QString& theEntry)
797   {
798     TObjectInfo anObjectInfo = GetObjectByEntry(theStudy, theEntry.toLatin1().constData());
799     VISU::PointMap3d_i* aTable = dynamic_cast<VISU::PointMap3d_i*>(anObjectInfo.myBase);
800     return FindActorBase(theViewWindow, aTable);
801   }
802
803   //------------------------------------------------------------
804   void
805   RecreateActor (const SalomeApp_Module* theModule,
806                  VISU::Prs3d_i* thePrs)
807   {
808     QApplication::setOverrideCursor(Qt::WaitCursor);
809
810     SALOMEDS::SObject_var aSObject = thePrs->GetSObject();
811     CORBA::String_var anEntry = aSObject->GetID();
812
813     try {
814       thePrs->UpdateActors();
815     } catch (std::runtime_error& exc) {
816       INFOS(exc.what());
817       QApplication::restoreOverrideCursor();
818       SUIT_MessageBox::warning
819         (GetDesktop(theModule), QObject::tr("WRN_VISU"),
820          QObject::tr("ERR_CANT_BUILD_PRESENTATION") + ": " + QObject::tr(exc.what()) );
821
822       thePrs->RemoveActors();
823       return;
824     }
825     QApplication::restoreOverrideCursor();
826   }
827
828   //------------------------------------------------------------
829   bool
830   ComputeVisiblePropBounds(SVTK_ViewWindow* theViewWindow,
831                            vtkFloatingPointType allBounds[6], 
832                            const char* theActorClassName)
833   {
834     vtkRenderer *aRen = theViewWindow->getRenderer();
835     vtkActorCollection *anActColl = aRen->GetActors(); 
836     vtkProp *prop;
837     vtkFloatingPointType *bounds;
838     int somethingVisible = false;
839
840     allBounds[0] = allBounds[2] = allBounds[4] = VTK_LARGE_FLOAT;
841     allBounds[1] = allBounds[3] = allBounds[5] = -VTK_LARGE_FLOAT;
842     // loop through all props
843     for (anActColl->InitTraversal(); (prop = anActColl->GetNextProp()); ) {
844       // if it's invisible, or has no geometry, we can skip the rest 
845       if (prop->GetVisibility() && prop->IsA(theActorClassName)) {
846         bounds = prop->GetBounds();
847         // make sure we haven't got bogus bounds
848         if (bounds != NULL &&
849             bounds[0] > -VTK_LARGE_FLOAT && bounds[1] < VTK_LARGE_FLOAT &&
850             bounds[2] > -VTK_LARGE_FLOAT && bounds[3] < VTK_LARGE_FLOAT &&
851             bounds[4] > -VTK_LARGE_FLOAT && bounds[5] < VTK_LARGE_FLOAT)
852         {
853           somethingVisible = true;
854           if (bounds[0] < allBounds[0]) allBounds[0] = bounds[0]; 
855           if (bounds[1] > allBounds[1]) allBounds[1] = bounds[1]; 
856           if (bounds[2] < allBounds[2]) allBounds[2] = bounds[2]; 
857           if (bounds[3] > allBounds[3]) allBounds[3] = bounds[3]; 
858           if (bounds[4] < allBounds[4]) allBounds[4] = bounds[4]; 
859           if (bounds[5] > allBounds[5]) allBounds[5] = bounds[5]; 
860         }//not bogus
861       }
862     }
863     return somethingVisible;
864   }
865
866   //------------------------------------------------------------
867   void SetFitAll(SVTK_ViewWindow* theViewWindow)
868   {
869     static vtkFloatingPointType PRECISION = 0.000001;
870     static vtkFloatingPointType DEVIATION = 600;
871     vtkFloatingPointType XYZ_Bnd[6];
872     if (!ComputeVisiblePropBounds(theViewWindow, XYZ_Bnd)) return;
873
874     vtkFloatingPointType absX = XYZ_Bnd[1] - XYZ_Bnd[0];
875     vtkFloatingPointType absY = XYZ_Bnd[3] - XYZ_Bnd[2];
876     vtkFloatingPointType 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           vtkFloatingPointType dev_abs_XY = absX / absY;
888           vtkFloatingPointType dev_abs_YZ = absY / absZ;
889           vtkFloatingPointType 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   //------------------------------------------------------------
929   // Internal function used by several public functions below
930   void
931   UpdateCurve(VISU::Curve_i* theCurve,
932               Plot2d_ViewFrame* aPlot,
933               SPlot2d_Curve* plotCurve,
934               int theDisplaying)
935   {
936     if ( theDisplaying == VISU::eErase ) {
937       if ( plotCurve && aPlot )
938         aPlot->eraseCurve( plotCurve, false );
939     }
940     else if ( theDisplaying == VISU::eDisplay || theDisplaying == VISU::eDisplayOnly ) {
941       if ( plotCurve ) {
942         plotCurve->setHorTitle( theCurve->GetHorTitle().c_str() );
943         //plotCurve->setVerTitle( ( theCurve->GetVerTitle().c_str() ) );
944         plotCurve->setVerTitle( theCurve->GetName().c_str() );
945         plotCurve->setHorUnits( theCurve->GetHorUnits().c_str() );
946         plotCurve->setVerUnits( theCurve->GetVerUnits().c_str() );
947         double* xList = 0;
948         double* yList = 0;
949         QStringList zList;
950         int     nbPoints = theCurve->GetData( xList, yList, zList );
951         if ( nbPoints > 0 && xList && yList ) {
952           plotCurve->setData( xList, yList, nbPoints, zList );
953         }
954         if ( !theCurve->IsAuto() ) {
955           plotCurve->setLine( (Plot2d::LineType)theCurve->GetLine(), theCurve->GetLineWidth() );
956           plotCurve->setMarker( (Plot2d::MarkerType)theCurve->GetMarker() );
957           SALOMEDS::Color color = theCurve->GetColor();
958           plotCurve->setColor( QColor( (int)(color.R*255.), (int)(color.G*255.), (int)(color.B*255.) ) );
959         }
960         plotCurve->setAutoAssign( theCurve->IsAuto() );
961         if( aPlot )
962           aPlot->displayCurve( plotCurve, false );
963       }
964       else {
965         Plot2d_Curve* crv = theCurve->CreatePresentation();
966         if ( crv ) {
967           if( aPlot )
968             aPlot->displayCurve( crv, false );
969           theCurve->SetLine( (VISU::Curve::LineType)crv->getLine(), crv->getLineWidth() );
970           theCurve->SetMarker( (VISU::Curve::MarkerType)crv->getMarker());
971           SALOMEDS::Color newColor;
972           newColor.R = crv->getColor().red()/255.;
973           newColor.G = crv->getColor().green()/255.;
974           newColor.B = crv->getColor().blue()/255.;
975           theCurve->SetColor( newColor );
976           crv->setAutoAssign( theCurve->IsAuto() );
977         }
978       }
979     }
980   }
981
982   //------------------------------------------------------------
983   void
984   PlotTable(const SalomeApp_Module* theModule,
985             VISU::Table_i* table,
986             int theDisplaying)
987   {
988     SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true ); // create if necessary
989     if ( !aView )
990       return;
991     Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
992     if ( !aPlot )
993       return;
994
995     if ( theDisplaying == VISU::eDisplayOnly )
996       aPlot->EraseAll();
997     QList<Plot2d_Curve*> clist;
998     aPlot->getCurves( clist );
999     _PTR(Study) aStudy = GetCStudy( GetAppStudy( theModule ) );
1000     _PTR(SObject) TableSO = aStudy->FindObjectID( table->GetEntry() );
1001     if ( TableSO ) {
1002       _PTR(ChildIterator) Iter = aStudy->NewChildIterator( TableSO );
1003       for ( ; Iter->More(); Iter->Next() ) {
1004         CORBA::Object_var childObject = VISU::ClientSObjectToObject( Iter->Value() );
1005         if( !CORBA::is_nil( childObject ) ) {
1006           CORBA::Object_ptr aCurve = VISU::Curve::_narrow( childObject );
1007           if( !CORBA::is_nil( aCurve ) ) {
1008             VISU::Curve_i* theCurve = dynamic_cast<VISU::Curve_i*>(VISU::GetServant(aCurve).in());
1009             SPlot2d_Curve* plotCurve = 0;
1010             SPlot2d_Curve* tmpCurve;
1011             for ( int i = 0; i < clist.count(); i++ ) {
1012               tmpCurve = dynamic_cast<SPlot2d_Curve*>( clist.at( i ) );
1013               if (tmpCurve && tmpCurve->hasIO() &&
1014                   theCurve->GetEntry() == tmpCurve->getIO()->getEntry()) {
1015                 plotCurve = tmpCurve;
1016                 break;
1017               }
1018             }
1019
1020             UpdateCurve( theCurve, aPlot, plotCurve, theDisplaying );
1021
1022             if ( theDisplaying == VISU::eErase && plotCurve ) {
1023               clist.removeAll(plotCurve );
1024             }
1025           }
1026         }
1027       }
1028       aPlot->Repaint();
1029     }
1030   }
1031
1032   //------------------------------------------------------------
1033   void
1034   PlotCurve(const SalomeApp_Module* theModule,
1035             VISU::Curve_i* theCurve,
1036             int theDisplaying)
1037   {
1038     SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true );
1039     if ( !aView )
1040       return;
1041     Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
1042     if ( !aPlot )
1043       return;
1044
1045 //  if ( theDisplaying == VISU::eDisplayOnly )
1046 //    aPlot->EraseAll();
1047     QList<Plot2d_Curve*> clist;
1048     aPlot->getCurves( clist );
1049     SPlot2d_Curve* plotCurve = 0;
1050     SPlot2d_Curve* tmpCurve;
1051     if(theDisplaying == VISU::eErase) {
1052       // 23.06.2008 skl for IPAL17672
1053       for (int i = 0; i < clist.count(); i++) {
1054         tmpCurve = dynamic_cast<SPlot2d_Curve*>(clist.at(i));
1055         if (tmpCurve && tmpCurve->hasIO() &&
1056             theCurve->GetEntry() == tmpCurve->getIO()->getEntry()) {
1057           plotCurve = tmpCurve;
1058           aPlot->eraseCurve(clist.at(i));
1059           break;
1060         }
1061       }
1062       UpdateCurve(theCurve, aPlot, plotCurve, theDisplaying);
1063     }
1064     else {
1065       for (int i = 0; i < clist.count(); i++) {
1066         tmpCurve = dynamic_cast<SPlot2d_Curve*>(clist.at(i));
1067         if (tmpCurve && tmpCurve->hasIO() &&
1068             theCurve->GetEntry() == tmpCurve->getIO()->getEntry()) {
1069           plotCurve = tmpCurve;
1070         }
1071         else if (theDisplaying == VISU::eDisplayOnly) {
1072           aPlot->eraseCurve(clist.at(i));
1073         }
1074       }
1075       UpdateCurve(theCurve, aPlot, plotCurve, theDisplaying);
1076     }
1077
1078     aPlot->Repaint();
1079   }
1080
1081   //------------------------------------------------------------
1082   void
1083   PlotRemoveCurve(const SalomeApp_Module* theModule,
1084                   VISU::Curve_i* pCrv)
1085   {
1086     QString anEntry = pCrv->GetEntry().c_str();
1087     ViewManagerList pvm_list;
1088     theModule->getApp()->viewManagers( SPlot2d_Viewer::Type(), pvm_list );
1089     ViewManagerList::Iterator pvm_it = pvm_list.begin();
1090     for( ; pvm_it != pvm_list.end(); pvm_it++ ){
1091       Plot2d_ViewManager* pvm = dynamic_cast<Plot2d_ViewManager*>( *pvm_it );
1092       if( pvm ){
1093         SPlot2d_Viewer* aSPlot2d = dynamic_cast<SPlot2d_Viewer*>( pvm->getViewModel() );
1094         if( aSPlot2d ){
1095           Plot2d_ViewFrame* aPlot = aSPlot2d->getActiveViewFrame();
1096           if(aPlot){
1097             QList<Plot2d_Curve*> clist;
1098             aPlot->getCurves( clist );
1099             for (int i = 0; i < clist.count(); i++) {
1100               if(SPlot2d_Curve* plotCurve = dynamic_cast<SPlot2d_Curve*>(clist[i]))
1101                 if(plotCurve->hasIO() && (plotCurve->getIO()->getEntry() == anEntry))
1102                   aPlot->eraseCurve(clist[i]);
1103             }
1104           }
1105         }
1106       }
1107     }
1108   }
1109   
1110   //------------------------------------------------------------
1111   void
1112   PlotContainer(const SalomeApp_Module* theModule,
1113                 VISU::Container_i* container,
1114                 int theDisplaying)
1115   {
1116     SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true );
1117     if ( !aView )
1118       return;
1119     Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
1120     if ( !aPlot )
1121       return;
1122
1123     if ( theDisplaying == VISU::eDisplayOnly )
1124       aPlot->EraseAll();
1125     QList<Plot2d_Curve*> clist;
1126     aPlot->getCurves( clist );
1127     if ( container->GetNbCurves() > 0 ) {
1128       int nbCurves = container->GetNbCurves();
1129       for ( int k = 1; k <= nbCurves; k++ ) {
1130         VISU::Curve_i* theCurve = container->GetCurve( k );
1131         if ( theCurve && theCurve->IsValid() ) {
1132           SPlot2d_Curve* plotCurve = dynamic_cast<SPlot2d_Curve*>
1133             (aView->getCurveByIO(new SALOME_InteractiveObject(theCurve->GetEntry().c_str(), "", "")));
1134
1135           UpdateCurve( theCurve, aPlot, plotCurve, theDisplaying );
1136
1137           if ( plotCurve && theDisplaying == VISU::eErase ) {
1138             clist.removeAll( plotCurve );
1139           }
1140         }
1141       }
1142     }
1143     aPlot->Repaint();
1144     if(GetResourceMgr()->booleanValue("VISU","automatic_fit_all",false)){
1145       aPlot->fitAll();
1146     }
1147     qApp->processEvents();
1148   }
1149
1150   //------------------------------------------------------------
1151   void
1152   CreatePlot(SalomeApp_Module* theModule,
1153              _PTR(SObject) theTableSO)
1154   {
1155     if ( IsSObjectTable(theTableSO) ) {
1156       CORBA::Object_var aTable = VISU::ClientSObjectToObject(theTableSO);
1157       CORBA::Object_var aContainer = GetVisuGen( theModule )->CreateContainer();
1158       if ( !CORBA::is_nil( aTable ) && !CORBA::is_nil( aContainer ) ) {
1159         VISU::Table_i*     pTable     = dynamic_cast<VISU::Table_i*>(VISU::GetServant(aTable).in());
1160         VISU::Container_i* pContainer = dynamic_cast<VISU::Container_i*>(VISU::GetServant(aContainer).in());
1161
1162         if ( pContainer && pTable ) {
1163           for ( int i = 2; i <= pTable->GetNbRows(); i++ ) {
1164             CORBA::Object_var aNewCurve = GetVisuGen( theModule )->CreateCurve( pTable->_this(), 1, i );
1165             if( !CORBA::is_nil( aNewCurve ) ) {
1166               VISU::Curve_i* pCrv = dynamic_cast<VISU::Curve_i*>( VISU::GetServant(aNewCurve).in() );
1167               if ( pCrv ) {
1168                 pContainer->AddCurve( pCrv->_this() );
1169               }
1170             }
1171           }
1172           PlotContainer( theModule, pContainer, VISU::eDisplay );
1173
1174           QString anEntry = pContainer->GetEntry().c_str();
1175           _PTR(Study) aStudy = theTableSO->GetStudy();
1176           _PTR(SObject) aContainerSO = aStudy->FindObjectID(anEntry.toLatin1().data());
1177           _PTR(SObject) aParentSO = aContainerSO->GetFather();
1178           UpdateObjBrowser(theModule,true,aParentSO);
1179         }
1180       }
1181     }
1182   }
1183
1184   //************************************************************
1185   // Others
1186   VISU::Mesh_i*
1187   CreateMesh(VisuGUI* theModule,
1188              const Handle(SALOME_InteractiveObject)& theIO,
1189              SVTK_ViewWindow* theViewWindow)
1190   {  
1191         _PTR(Study) aStudy = GetCStudy(GetAppStudy(theModule));
1192     //if (CheckLock(aStudy))
1193     //  return;
1194
1195     _PTR(SObject) aResultSObj = aStudy->FindObjectID(theIO->getEntry());
1196
1197     // Get VISU::Result
1198     VISU::Result_var aResult;
1199     VISU::Result_i* pResult = CheckResult(theModule, aResultSObj, aResult);
1200     if (pResult == NULL)
1201       return NULL;
1202
1203     Storable::TRestoringMap aMap = Storable::GetStorableMap(aResultSObj);
1204     if (aMap.empty())
1205       return NULL;
1206
1207     CORBA::Object_var aMesh;
1208     string aComment = Storable::FindValue(aMap,"myComment").toLatin1().data();
1209     string aMeshName = Storable::FindValue(aMap,"myMeshName").toLatin1().data();
1210 #ifdef CHECKTIME
1211     Utils_Timer timer;
1212     timer.Start();
1213 #endif
1214     if (aComment == "ENTITY") {
1215       VISU::Entity anEntity = (VISU::Entity)Storable::FindValue(aMap,"myId").toInt();
1216       if (VISU::Mesh_i::IsPossible(pResult,aMeshName.c_str(),anEntity))
1217         aMesh = GetVisuGen(theModule)->MeshOnEntity(aResult,aMeshName.c_str(),anEntity);
1218     } else if (aComment == "FAMILY") {
1219       VISU::Entity anEntity = (VISU::Entity)Storable::FindValue(aMap,"myEntityId").toInt();
1220       string aFamilyName = Storable::FindValue(aMap,"myName").toLatin1().data();
1221       if (VISU::Mesh_i::IsPossible(pResult,aMeshName.c_str(),anEntity,aFamilyName.c_str()))
1222         aMesh = GetVisuGen(theModule)->FamilyMeshOnEntity
1223           (aResult,aMeshName.c_str(),anEntity,aFamilyName.c_str());
1224     } else if (aComment == "GROUP") {
1225       string aGroupName = Storable::FindValue(aMap,"myName").toLatin1().data();
1226       if (VISU::Mesh_i::IsPossible(pResult,aMeshName.c_str(),aGroupName.c_str()))
1227         aMesh = GetVisuGen(theModule)->GroupMesh(aResult,aMeshName.c_str(),aGroupName.c_str());
1228     }
1229 #ifdef CHECKTIME
1230     timer.Stop();
1231     MESSAGE("VisuGUI::CreateMesh() - CREATE MESH");
1232     timer.Show();
1233 #endif
1234
1235     //QApplication::restoreOverrideCursor();
1236     VISU::Mesh_i* pPresent = NULL;
1237     if (!CORBA::is_nil(aMesh))
1238       pPresent = dynamic_cast<VISU::Mesh_i*>(VISU::GetServant(aMesh).in());
1239     if (pPresent == NULL) {
1240       SUIT_MessageBox::warning (GetDesktop(theModule),
1241                                 QObject::tr("WRN_VISU"),
1242                                 QObject::tr("ERR_CANT_BUILD_PRESENTATION") );
1243       return NULL;
1244     }
1245
1246     if (theViewWindow) {
1247       try {
1248 #ifdef CHECKTIME
1249         Utils_Timer timer;
1250         timer.Start();
1251 #endif
1252         if(GetResourceMgr()->booleanValue("VISU","display_only",false)){
1253           const VisuGUI* av = dynamic_cast<const VisuGUI*>(theModule);
1254           if(av)(const_cast<VisuGUI*>(av))->OnEraseAll();
1255         }
1256         PublishMeshInView(theModule, pPresent, theViewWindow);
1257         if(GetResourceMgr()->booleanValue("VISU","automatic_fit_all",false)){
1258           SetFitAll(theViewWindow);
1259         }
1260 #ifdef CHECKTIME
1261         timer.Stop();
1262         MESSAGE("VisuGUI::CreateMesh() - DISPLAY MESH");
1263         timer.Show();
1264 #endif
1265       } catch (std::runtime_error& exc) {
1266         INFOS(exc.what());
1267         SUIT_MessageBox::warning(GetDesktop(theModule), QObject::tr("WRN_VISU"),
1268                                  QObject::tr("ERR_CANT_CREATE_ACTOR") + ": " + QObject::tr(exc.what()) );
1269       }
1270     }
1271
1272     UpdateObjBrowser(theModule, false, aResultSObj);
1273
1274     theModule->application()->putInfo(QObject::tr("INF_DONE"));
1275     // Make "Save" button active
1276     theModule->getApp()->updateActions();
1277     return pPresent;
1278   }
1279
1280   // ========================================================================================
1281   // GetPrs3dList: find list of presentations for the given object
1282   // ========================================================================================
1283   std::vector<VISU::Prs3d_i*> GetPrs3dList (const SalomeApp_Module* theModule,
1284                                             const Handle(SALOME_InteractiveObject)& theIO)
1285   {
1286     std::vector<VISU::Prs3d_i*> aList;
1287     if (!theIO.IsNull() && theIO->hasEntry()) {
1288       _PTR(Study) aCStudy = GetCStudy(GetAppStudy(theModule));
1289       _PTR(SObject) aSObject = aCStudy->FindObjectID(theIO->getEntry());
1290       aList = GetPrs3dList(theModule, aSObject);
1291     }
1292     return aList;
1293   }
1294
1295   std::vector<VISU::Prs3d_i*> GetPrs3dList (const SalomeApp_Module* theModule,
1296                                             _PTR(SObject) theObject)
1297   {
1298     std::vector<VISU::Prs3d_i*> aList; int k = 0;
1299     if (!theObject)
1300       return aList;
1301
1302     _PTR(Study) aCStudy = GetCStudy(GetAppStudy(theModule));
1303
1304     CORBA::Object_var aCORBAObject = VISU::ClientSObjectToObject(theObject);
1305     if (!CORBA::is_nil(aCORBAObject)) {
1306       VISU::Base_var aVisuObj = VISU::Base::_narrow(aCORBAObject);
1307       if (!CORBA::is_nil(aVisuObj)) {
1308         VISU::VISUType aType = aVisuObj->GetType();
1309         switch (aType) {
1310         case VISU::TSCALARMAP:
1311         case VISU::TISOSURFACES:
1312         case VISU::TDEFORMEDSHAPE:
1313         case VISU::TCUTPLANES:
1314         case VISU::TCUTLINES:
1315         case VISU::TVECTORS:
1316         case VISU::TSTREAMLINES:
1317         case VISU::TPLOT3D:
1318         case VISU::TSCALARMAPONDEFORMEDSHAPE:
1319         case VISU::TDEFORMEDSHAPEANDSCALARMAP:
1320         case VISU::TMESH:
1321           {
1322             PortableServer::ServantBase_var aServant = VISU::GetServant(aCORBAObject);
1323             if (aServant.in()) {
1324               VISU::Prs3d_i* aPrsObject = dynamic_cast<VISU::Prs3d_i*>(aServant.in());
1325               aList.resize(k+1);
1326               aList[k] = aPrsObject;
1327               k++;
1328             }
1329           }
1330           break;
1331         case VISU::TFIELD:
1332           {
1333             _PTR(ChildIterator) anIter = aCStudy->NewChildIterator(theObject);
1334             _PTR(SObject) aTimeStamp;
1335             anIter->Next(); // First is reference on support
1336             for (; anIter->More(); anIter->Next()) {
1337               aTimeStamp = anIter->Value();
1338               if (!aTimeStamp) continue;
1339               std::vector<VISU::Prs3d_i*> aSubList = GetPrs3dList(theModule, aTimeStamp);
1340               if (!aSubList.empty()) {
1341                 int n = aSubList.size();
1342                 aList.resize(k+n);
1343                 for (int i = 0; i < n; i++) {
1344                   aList[k] = aSubList[i];
1345                   k++;
1346                 }
1347               }
1348             }
1349           }
1350           break;
1351         }
1352       }
1353     } else {
1354       VISU::VISUType aType = VISU::Storable::SObject2Type(theObject);
1355       switch (aType) {
1356       case VISU::TFIELD: {
1357         _PTR(ChildIterator) anIter = aCStudy->NewChildIterator(theObject);
1358         _PTR(SObject) aTimeStamp;
1359         anIter->Next(); // First is reference on support
1360         for (; anIter->More(); anIter->Next()) {
1361           aTimeStamp = anIter->Value();
1362           if (!aTimeStamp) continue;
1363           std::vector<VISU::Prs3d_i*> aSubList = GetPrs3dList(theModule, aTimeStamp);
1364           if (!aSubList.empty()) {
1365             int n = aSubList.size();
1366             aList.resize(k+n);
1367             for (int i = 0; i < n; i++) {
1368               aList[k] = aSubList[i];
1369               k++;
1370             }
1371           }
1372         }
1373         break;
1374       }
1375       case VISU::TTIMESTAMP: {
1376         _PTR(ChildIterator) anIter = aCStudy->NewChildIterator(theObject);
1377         _PTR(SObject) aPrs;
1378         for (; anIter->More(); anIter->Next()) {
1379           aPrs = anIter->Value();
1380           if (!aPrs) continue;
1381           std::vector<VISU::Prs3d_i*> aSubList = GetPrs3dList(theModule, aPrs);
1382           if (!aSubList.empty()) {
1383             int n = aSubList.size();
1384             aList.resize(k+n);
1385             for (int i = 0; i < n; i++) {
1386               aList[k] = aSubList[i];
1387               k++;
1388             }
1389           }
1390         }
1391         break;
1392       }}
1393     }
1394     return aList;
1395   }
1396
1397   //------------------------------------------------------------
1398   int GetFreePositionOfDefaultScalarBar(VisuGUI* theModule, SVTK_ViewWindow* theViewWindow)
1399   {
1400     int minIndx = 1;
1401     std::set<int> aIndexes;
1402     TViewToPrs3d aMap = theModule->getScalarBarsMap();
1403     TViewToPrs3d::const_iterator aViewToPrsIter = aMap.find(theViewWindow);
1404     if (aViewToPrsIter != aMap.end()) {
1405       TSetPrs3d::const_iterator aPrsIter = (aViewToPrsIter->second).begin();
1406       for (; aPrsIter != (aViewToPrsIter->second).end(); aPrsIter++) {
1407         aIndexes.insert((*aPrsIter).second);
1408       }
1409     }
1410     std::set<int>::const_iterator aIter = aIndexes.begin();
1411     for (int i = 1,length = aIndexes.size(); i <= length; i++) {
1412       std::set<int>::const_iterator aIter = aIndexes.find(i);
1413       if (aIter == aIndexes.end()) { minIndx = i; break; } 
1414       else minIndx = i + 1;
1415     }
1416     return minIndx;
1417   }
1418
1419   //------------------------------------------------------------
1420   void AddScalarBarPosition (VisuGUI* theModule, SVTK_ViewWindow* theViewWindow,
1421                              VISU::Prs3d_i* thePrs3d, int pos)
1422   {
1423     TViewToPrs3d& aMap = theModule->getScalarBarsMap();
1424     TPrs3dToInd aPair; aPair.first = thePrs3d; aPair.second = pos;
1425     aMap[theViewWindow].insert(aPair);
1426   }
1427
1428   //------------------------------------------------------------
1429   void RemoveScalarBarPosition(VisuGUI* theModule, SVTK_ViewWindow* theViewWindow,
1430                                VISU::Prs3d_i* thePrs3d)
1431   {
1432     TViewToPrs3d& aMap = theModule->getScalarBarsMap();
1433     TSetPrs3d::iterator aIter = aMap[theViewWindow].begin();
1434     for (; aIter != aMap[theViewWindow].end(); aIter++)
1435       if ((*aIter).first == thePrs3d) {
1436         aMap[theViewWindow].erase(*aIter);
1437         return;
1438       }
1439   }
1440   //------------------------------------------------------------
1441   void initSpinBox( QSpinBox* spinBox, 
1442                     int min,  int max, int step )
1443   {
1444     spinBox->setRange( min, max );
1445     spinBox->setSingleStep( step );
1446   }
1447   //------------------------------------------------------------
1448   void initSpinBox( QDoubleSpinBox* spinBox, 
1449                     double min,  double max, 
1450                     double step, int decimals )
1451   {
1452     spinBox->setRange( min, max );
1453     spinBox->setSingleStep( step );
1454     spinBox->setDecimals( decimals );
1455   }
1456   //------------------------------------------------------------
1457   bool getClippingPlanesFolder(_PTR(Study) theStudy, _PTR(SObject)& theSObject)
1458   {
1459     _PTR(SComponent) aVisuSO = theStudy->FindComponent("VISU");
1460     if (!aVisuSO) return false;
1461     _PTR(SObject) aFolder = theStudy->FindObject(CLIP_PLANES_FOLDER);
1462     if (!aFolder) {
1463       _PTR(StudyBuilder) aBuilder = theStudy->NewBuilder();
1464       aFolder = aBuilder->NewObject(aVisuSO);
1465       
1466       _PTR(GenericAttribute) anAttr;
1467       anAttr = aBuilder->FindOrCreateAttribute(aFolder,"AttributeName");
1468       _PTR(AttributeName) aName(anAttr);
1469       aName->SetValue(CLIP_PLANES_FOLDER);
1470     }
1471     theSObject = aFolder;
1472     return true;
1473   }
1474 }