Salome HOME
Fix of the following issues:
[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 ChangeQuadratic2DRepresentation (const SalomeApp_Module* theModule,
635                                         VISU::Quadratic2DPresentationType  theType)
636   {
637     TSelectionInfo aSelectionInfo = GetSelectedObjects(theModule);
638     if(aSelectionInfo.empty())
639       return;
640     
641     TSelectionItem aSelectionItem = aSelectionInfo.front();
642
643     VISU::Prs3d_i* aPrs3d = GetPrs3dFromBase(aSelectionItem.myObjectInfo.myBase);
644
645     SVTK_ViewWindow* aViewWindow = GetActiveViewWindow<SVTK_ViewWindow>(theModule);
646     
647     if(!aPrs3d || !aViewWindow)
648       return;
649     
650     VISU_Actor *anActor = FindActor(aViewWindow, aPrs3d);
651     if(!anActor)
652       return;
653     
654     if (VISU::Mesh_i* aMesh = dynamic_cast<VISU::Mesh_i*>(aPrs3d)) {
655       aMesh->SetQuadratic2DPresentationType(theType);
656       RecreateActor(theModule, aMesh);
657     } else {
658       switch(theType){
659       case VISU::LINES:
660         anActor->SetQuadratic2DRepresentation(VISU_Actor::eLines);
661         break;
662       case VISU::ARCS:
663         anActor->SetQuadratic2DRepresentation(VISU_Actor::eArcs);
664         break;
665       default:
666         break;
667       }
668     }
669   }
670   
671   //------------------------------------------------------------
672   void
673   SetShading ( const SalomeApp_Module* theModule,
674               bool theOn )
675   {
676     TSelectionInfo aSelectionInfo = GetSelectedObjects(theModule);
677     if(aSelectionInfo.empty())
678       return;
679
680     TSelectionItem aSelectionItem = GetSelectedObjects(theModule).front();
681     VISU::Prs3d_i* aPrs3d = GetPrs3dFromBase(aSelectionItem.myObjectInfo.myBase);
682     if(!aPrs3d)
683       return;
684
685     SVTK_ViewWindow* aViewWindow = GetActiveViewWindow<SVTK_ViewWindow>(theModule);
686     if(!aViewWindow)
687       return;
688
689     VISU_Actor* anActor = FindActor(aViewWindow, aPrs3d);
690     if(!anActor)
691       return;
692
693     if(VISU_ScalarMapAct* aScalarMapActor = dynamic_cast<VISU_ScalarMapAct*>(anActor)){
694       aScalarMapActor->SetShading(theOn);
695       aViewWindow->Repaint();
696     }
697   }
698
699   //------------------------------------------------------------
700   // SObject type
701   bool
702   CheckTimeStamp(const SalomeApp_Module* theModule,
703                  _PTR(SObject)&          theSObject,
704                  Handle(SALOME_InteractiveObject)& theIO,
705                  ColoredPrs3d_i::EPublishInStudyMode& thePublishInStudyMode)
706   {
707     TSelectionInfo aSelectionInfo = GetSelectedObjects(theModule);
708     if(!aSelectionInfo.empty()){
709       TSelectionItem aSelectionItem = aSelectionInfo.front();
710       theIO = aSelectionItem.myIO;
711       theSObject = aSelectionItem.myObjectInfo.mySObject;
712       VISU::VISUType aType = VISU::Storable::SObject2Type(theSObject);
713       if (VISU::TTIMESTAMP == aType){
714         thePublishInStudyMode = ColoredPrs3d_i::EPublishUnderTimeStamp;
715         return true;
716       }
717       if (VISU::TFIELD == aType){
718         thePublishInStudyMode = ColoredPrs3d_i::EPublishIndependently;
719         if(theSObject->FindSubObject(2,theSObject))
720           return true;
721       }
722     }
723     SUIT_MessageBox::warning(GetDesktop(theModule),
724                              QObject::tr("WRN_VISU"),
725                              QObject::tr("WRN_NO_AVAILABLE_DATA") );
726     return false;
727   }
728
729   //------------------------------------------------------------
730   VISU::Result_i*
731   CheckResult(const SalomeApp_Module* theModule,
732               _PTR(SObject)           theSource,
733               VISU::Result_var&       theResult)
734   {
735     if(theSource->Depth() < 3) // Bug of SALOMEDS : can\t get father from root object
736       return NULL;
737       
738     _PTR(SObject) aSObj = theSource->GetFather();
739     if (!aSObj)
740       return NULL;
741
742     aSObj = aSObj->GetFather();
743     if (!aSObj)
744       return NULL;
745
746     aSObj = aSObj->GetFather();
747     if (!aSObj)
748       return NULL;
749
750     CORBA::Object_var anObject = VISU::ClientSObjectToObject(aSObj);
751     if (CORBA::is_nil(anObject)) {
752       aSObj = aSObj->GetFather();
753       if (!aSObj)
754         return NULL;
755       anObject = VISU::ClientSObjectToObject(aSObj);
756     }
757
758     if (CORBA::is_nil(anObject))
759       return NULL;
760
761     theResult = VISU::Result::_narrow(anObject);
762     return dynamic_cast<VISU::Result_i*>(VISU::GetServant(anObject).in());
763   }
764
765   //------------------------------------------------------------
766   // VTK View
767   VISU_Actor*
768   PublishMeshInView(const SalomeApp_Module* theModule,
769                     VISU::Prs3d_i* thePrs,
770                     SVTK_ViewWindow* theViewWindow)
771   {
772     VISU_Actor* aActor = NULL;
773     if (!thePrs || !theViewWindow)
774       return aActor;
775
776     QApplication::setOverrideCursor( Qt::WaitCursor );
777     try {
778       if ((aActor = thePrs->CreateActor()))
779         theViewWindow->AddActor(aActor);
780     } catch(std::exception& exc) {
781       SUIT_MessageBox::warning
782         (GetDesktop(theModule), QObject::tr("WRN_VISU"),
783          QObject::tr("ERR_CANT_CREATE_ACTOR") + ": " + QObject::tr(exc.what()) );
784     }
785     QApplication::restoreOverrideCursor();
786
787     return aActor;
788   }
789
790   //------------------------------------------------------------
791   void
792   RepaintViewWindows (const SalomeApp_Module* theModule,
793                       const Handle(SALOME_InteractiveObject)& theIObject)
794   {
795     TViewWindows aViewWindows;
796     if (SalomeApp_Application* anApp = theModule->getApp()) {
797       ViewManagerList aViewManagerList;
798       anApp->viewManagers(SVTK_Viewer::Type(),aViewManagerList);
799       QList<SUIT_ViewManager*>::Iterator anIter = aViewManagerList.begin();
800       while ( anIter != aViewManagerList.end() )
801       {
802         QVector<SUIT_ViewWindow*> aViews = (*anIter)->getViews();
803         for (int i = 0, iEnd = aViews.size(); i < iEnd; i++) {
804           if (SUIT_ViewWindow* aViewWindow = aViews.at(i)) {
805             if (SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>(aViewWindow)) {
806               if (vw->isVisible(theIObject)) {
807                 vw->getRenderer()->ResetCameraClippingRange();
808                 vw->Repaint();
809                 vw->highlight(theIObject, true, true);
810               }
811             }
812           }
813         }
814         anIter++;
815       }
816     }
817   }
818
819   //------------------------------------------------------------
820   VISU_Actor*
821   FindActor(const SalomeApp_Study* theStudy,
822             SVTK_ViewWindow* theViewWindow,
823             const QString& theEntry)
824   {
825     TObjectInfo anObjectInfo = GetObjectByEntry(theStudy, theEntry.toLatin1().data());
826     VISU::Prs3d_i* aPrs3d = GetPrs3dFromBase(anObjectInfo.myBase);
827     return FindActor(theViewWindow, aPrs3d);
828   }
829
830   //------------------------------------------------------------
831   VISU_ActorBase*
832   FindActorBase(const SalomeApp_Study* theStudy,
833                 SVTK_ViewWindow* theViewWindow,
834                 const QString& theEntry)
835   {
836     TObjectInfo anObjectInfo = GetObjectByEntry(theStudy, theEntry.toLatin1().constData());
837     VISU::PointMap3d_i* aTable = dynamic_cast<VISU::PointMap3d_i*>(anObjectInfo.myBase);
838     return FindActorBase(theViewWindow, aTable);
839   }
840
841   //------------------------------------------------------------
842   void
843   RecreateActor (const SalomeApp_Module* theModule,
844                  VISU::Prs3d_i* thePrs)
845   {
846     QApplication::setOverrideCursor(Qt::WaitCursor);
847
848     SALOMEDS::SObject_var aSObject = thePrs->GetSObject();
849     CORBA::String_var anEntry = aSObject->GetID();
850
851     try {
852       thePrs->UpdateActors();
853     } catch (std::runtime_error& exc) {
854       INFOS(exc.what());
855       QApplication::restoreOverrideCursor();
856       SUIT_MessageBox::warning
857         (GetDesktop(theModule), QObject::tr("WRN_VISU"),
858          QObject::tr("ERR_CANT_BUILD_PRESENTATION") + ": " + QObject::tr(exc.what()) );
859
860       thePrs->RemoveActors();
861       return;
862     }
863     QApplication::restoreOverrideCursor();
864   }
865
866   //------------------------------------------------------------
867   bool
868   ComputeVisiblePropBounds(SVTK_ViewWindow* theViewWindow,
869                            vtkFloatingPointType allBounds[6], 
870                            const char* theActorClassName)
871   {
872     vtkRenderer *aRen = theViewWindow->getRenderer();
873     vtkActorCollection *anActColl = aRen->GetActors(); 
874     vtkProp *prop;
875     vtkFloatingPointType *bounds;
876     int somethingVisible = false;
877
878     allBounds[0] = allBounds[2] = allBounds[4] = VTK_LARGE_FLOAT;
879     allBounds[1] = allBounds[3] = allBounds[5] = -VTK_LARGE_FLOAT;
880     // loop through all props
881     for (anActColl->InitTraversal(); (prop = anActColl->GetNextProp()); ) {
882       // if it's invisible, or has no geometry, we can skip the rest 
883       if (prop->GetVisibility() && prop->IsA(theActorClassName)) {
884         bounds = prop->GetBounds();
885         // make sure we haven't got bogus bounds
886         if (bounds != NULL &&
887             bounds[0] > -VTK_LARGE_FLOAT && bounds[1] < VTK_LARGE_FLOAT &&
888             bounds[2] > -VTK_LARGE_FLOAT && bounds[3] < VTK_LARGE_FLOAT &&
889             bounds[4] > -VTK_LARGE_FLOAT && bounds[5] < VTK_LARGE_FLOAT)
890         {
891           somethingVisible = true;
892           if (bounds[0] < allBounds[0]) allBounds[0] = bounds[0]; 
893           if (bounds[1] > allBounds[1]) allBounds[1] = bounds[1]; 
894           if (bounds[2] < allBounds[2]) allBounds[2] = bounds[2]; 
895           if (bounds[3] > allBounds[3]) allBounds[3] = bounds[3]; 
896           if (bounds[4] < allBounds[4]) allBounds[4] = bounds[4]; 
897           if (bounds[5] > allBounds[5]) allBounds[5] = bounds[5]; 
898         }//not bogus
899       }
900     }
901     return somethingVisible;
902   }
903
904   //------------------------------------------------------------
905   void SetFitAll(SVTK_ViewWindow* theViewWindow)
906   {
907     static vtkFloatingPointType PRECISION = 0.000001;
908     static vtkFloatingPointType DEVIATION = 600;
909     vtkFloatingPointType XYZ_Bnd[6];
910     if (!ComputeVisiblePropBounds(theViewWindow, XYZ_Bnd)) return;
911
912     vtkFloatingPointType absX = XYZ_Bnd[1] - XYZ_Bnd[0];
913     vtkFloatingPointType absY = XYZ_Bnd[3] - XYZ_Bnd[2];
914     vtkFloatingPointType absZ = XYZ_Bnd[5] - XYZ_Bnd[4];
915
916     enum CameraOrient {e3D, eFront, eLeft, eTop};
917     CameraOrient aCameraOrient = e3D;
918     if (absX <= PRECISION) aCameraOrient = eFront;
919     else {
920       if (absY <= PRECISION) aCameraOrient = eLeft;
921       else {
922         if (absZ <= PRECISION) aCameraOrient = eTop;
923         else {
924           // all the three dimensions exceeds precision
925           vtkFloatingPointType dev_abs_XY = absX / absY;
926           vtkFloatingPointType dev_abs_YZ = absY / absZ;
927           vtkFloatingPointType dev_abs_XZ = absX / absZ;
928           if (dev_abs_XY >= DEVIATION || 1./dev_abs_YZ >= DEVIATION)
929             aCameraOrient = eLeft;
930           else {
931             if (1./dev_abs_XY >= DEVIATION || 1./dev_abs_XZ >= DEVIATION)
932               aCameraOrient = eFront;
933             else {
934               if (dev_abs_XZ >= DEVIATION || dev_abs_YZ >= DEVIATION)
935                 aCameraOrient = eTop;
936             }
937           }
938         }
939       }
940     }
941
942     switch (aCameraOrient) {
943     case eFront: theViewWindow->onFrontView(); break;
944     case eLeft:  theViewWindow->onLeftView();  break;
945     case eTop:   theViewWindow->onTopView();   break;
946     case e3D:    theViewWindow->onResetView(); break;
947     }
948     theViewWindow->getRenderer()->ResetCameraClippingRange();
949     theViewWindow->onFitAll();
950   }
951
952   //************************************************************
953   // Plot2d View
954
955   SPlot2d_Viewer*
956   GetPlot2dViewer(const SalomeApp_Module* theModule, const bool theCreate)
957   {
958     if(SalomeApp_Application* anApp = theModule->getApp()){
959       if(SUIT_ViewManager* aViewManager = anApp->getViewManager( Plot2d_Viewer::Type(), theCreate )){
960         return dynamic_cast<SPlot2d_Viewer*>(aViewManager->getViewModel());
961       }
962     }
963     return NULL;
964   }
965
966   //------------------------------------------------------------
967   // Internal function used by several public functions below
968   void
969   UpdateCurve(VISU::Curve_i* theCurve,
970               Plot2d_ViewFrame* aPlot,
971               SPlot2d_Curve* plotCurve,
972               int theDisplaying)
973   {
974     if ( theDisplaying == VISU::eErase ) {
975       if ( plotCurve && aPlot )
976         aPlot->eraseCurve( plotCurve, false );
977     }
978     else if ( theDisplaying == VISU::eDisplay || theDisplaying == VISU::eDisplayOnly ) {
979       if ( plotCurve ) {
980         plotCurve->setHorTitle( theCurve->GetHorTitle().c_str() );
981         //plotCurve->setVerTitle( ( theCurve->GetVerTitle().c_str() ) );
982         plotCurve->setVerTitle( theCurve->GetName().c_str() );
983         plotCurve->setHorUnits( theCurve->GetHorUnits().c_str() );
984         plotCurve->setVerUnits( theCurve->GetVerUnits().c_str() );
985         double* xList = 0;
986         double* yList = 0;
987         QStringList zList;
988         int     nbPoints = theCurve->GetData( xList, yList, zList );
989         if ( nbPoints > 0 && xList && yList ) {
990           plotCurve->setData( xList, yList, nbPoints, zList );
991         }
992         if ( !theCurve->IsAuto() ) {
993           plotCurve->setLine( (Plot2d::LineType)theCurve->GetLine(), theCurve->GetLineWidth() );
994           plotCurve->setMarker( (Plot2d::MarkerType)theCurve->GetMarker() );
995           SALOMEDS::Color color = theCurve->GetColor();
996           plotCurve->setColor( QColor( (int)(color.R*255.), (int)(color.G*255.), (int)(color.B*255.) ) );
997         }
998         plotCurve->setAutoAssign( theCurve->IsAuto() );
999         if( aPlot )
1000           aPlot->displayCurve( plotCurve, false );
1001       }
1002       else {
1003         Plot2d_Curve* crv = theCurve->CreatePresentation();
1004         if ( crv ) {
1005           if( aPlot )
1006             aPlot->displayCurve( crv, false );
1007           theCurve->SetLine( (VISU::Curve::LineType)crv->getLine(), crv->getLineWidth() );
1008           theCurve->SetMarker( (VISU::Curve::MarkerType)crv->getMarker());
1009           SALOMEDS::Color newColor;
1010           newColor.R = crv->getColor().red()/255.;
1011           newColor.G = crv->getColor().green()/255.;
1012           newColor.B = crv->getColor().blue()/255.;
1013           theCurve->SetColor( newColor );
1014           crv->setAutoAssign( theCurve->IsAuto() );
1015         }
1016       }
1017     }
1018   }
1019
1020   //------------------------------------------------------------
1021   void
1022   PlotTable(const SalomeApp_Module* theModule,
1023             VISU::Table_i* table,
1024             int theDisplaying)
1025   {
1026     SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true ); // create if necessary
1027     if ( !aView )
1028       return;
1029     Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
1030     if ( !aPlot )
1031       return;
1032
1033     if ( theDisplaying == VISU::eDisplayOnly )
1034       aPlot->EraseAll();
1035     QList<Plot2d_Curve*> clist;
1036     aPlot->getCurves( clist );
1037     _PTR(Study) aStudy = GetCStudy( GetAppStudy( theModule ) );
1038     _PTR(SObject) TableSO = aStudy->FindObjectID( table->GetEntry() );
1039     if ( TableSO ) {
1040       _PTR(ChildIterator) Iter = aStudy->NewChildIterator( TableSO );
1041       for ( ; Iter->More(); Iter->Next() ) {
1042         CORBA::Object_var childObject = VISU::ClientSObjectToObject( Iter->Value() );
1043         if( !CORBA::is_nil( childObject ) ) {
1044           CORBA::Object_ptr aCurve = VISU::Curve::_narrow( childObject );
1045           if( !CORBA::is_nil( aCurve ) ) {
1046             VISU::Curve_i* theCurve = dynamic_cast<VISU::Curve_i*>(VISU::GetServant(aCurve).in());
1047             SPlot2d_Curve* plotCurve = 0;
1048             SPlot2d_Curve* tmpCurve;
1049             for ( int i = 0; i < clist.count(); i++ ) {
1050               tmpCurve = dynamic_cast<SPlot2d_Curve*>( clist.at( i ) );
1051               if (tmpCurve && tmpCurve->hasIO() &&
1052                   theCurve->GetEntry() == tmpCurve->getIO()->getEntry()) {
1053                 plotCurve = tmpCurve;
1054                 break;
1055               }
1056             }
1057
1058             UpdateCurve( theCurve, aPlot, plotCurve, theDisplaying );
1059
1060             if ( theDisplaying == VISU::eErase && plotCurve ) {
1061               clist.removeAll(plotCurve );
1062             }
1063           }
1064         }
1065       }
1066       aPlot->Repaint();
1067     }
1068   }
1069
1070   //------------------------------------------------------------
1071   void
1072   PlotCurve(const SalomeApp_Module* theModule,
1073             VISU::Curve_i* theCurve,
1074             int theDisplaying)
1075   {
1076     SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true );
1077     if ( !aView )
1078       return;
1079     Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
1080     if ( !aPlot )
1081       return;
1082
1083 //  if ( theDisplaying == VISU::eDisplayOnly )
1084 //    aPlot->EraseAll();
1085     QList<Plot2d_Curve*> clist;
1086     aPlot->getCurves( clist );
1087     SPlot2d_Curve* plotCurve = 0;
1088     SPlot2d_Curve* tmpCurve;
1089     if(theDisplaying == VISU::eErase) {
1090       // 23.06.2008 skl for IPAL17672
1091       for (int i = 0; i < clist.count(); i++) {
1092         tmpCurve = dynamic_cast<SPlot2d_Curve*>(clist.at(i));
1093         if (tmpCurve && tmpCurve->hasIO() &&
1094             theCurve->GetEntry() == tmpCurve->getIO()->getEntry()) {
1095           plotCurve = tmpCurve;
1096           aPlot->eraseCurve(clist.at(i));
1097           break;
1098         }
1099       }
1100       UpdateCurve(theCurve, aPlot, plotCurve, theDisplaying);
1101     }
1102     else {
1103       for (int i = 0; i < clist.count(); i++) {
1104         tmpCurve = dynamic_cast<SPlot2d_Curve*>(clist.at(i));
1105         if (tmpCurve && tmpCurve->hasIO() &&
1106             theCurve->GetEntry() == tmpCurve->getIO()->getEntry()) {
1107           plotCurve = tmpCurve;
1108         }
1109         else if (theDisplaying == VISU::eDisplayOnly) {
1110           aPlot->eraseCurve(clist.at(i));
1111         }
1112       }
1113       UpdateCurve(theCurve, aPlot, plotCurve, theDisplaying);
1114     }
1115
1116     aPlot->Repaint();
1117   }
1118
1119   //------------------------------------------------------------
1120   void
1121   PlotRemoveCurve(const SalomeApp_Module* theModule,
1122                   VISU::Curve_i* pCrv)
1123   {
1124     QString anEntry = pCrv->GetEntry().c_str();
1125     ViewManagerList pvm_list;
1126     theModule->getApp()->viewManagers( SPlot2d_Viewer::Type(), pvm_list );
1127     ViewManagerList::Iterator pvm_it = pvm_list.begin();
1128     for( ; pvm_it != pvm_list.end(); pvm_it++ ){
1129       Plot2d_ViewManager* pvm = dynamic_cast<Plot2d_ViewManager*>( *pvm_it );
1130       if( pvm ){
1131         SPlot2d_Viewer* aSPlot2d = dynamic_cast<SPlot2d_Viewer*>( pvm->getViewModel() );
1132         if( aSPlot2d ){
1133           Plot2d_ViewFrame* aPlot = aSPlot2d->getActiveViewFrame();
1134           if(aPlot){
1135             QList<Plot2d_Curve*> clist;
1136             aPlot->getCurves( clist );
1137             for (int i = 0; i < clist.count(); i++) {
1138               if(SPlot2d_Curve* plotCurve = dynamic_cast<SPlot2d_Curve*>(clist[i]))
1139                 if(plotCurve->hasIO() && (plotCurve->getIO()->getEntry() == anEntry))
1140                   aPlot->eraseCurve(clist[i]);
1141             }
1142           }
1143         }
1144       }
1145     }
1146   }
1147   
1148   //------------------------------------------------------------
1149   void
1150   PlotContainer(const SalomeApp_Module* theModule,
1151                 VISU::Container_i* container,
1152                 int theDisplaying)
1153   {
1154     SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true );
1155     if ( !aView )
1156       return;
1157     Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
1158     if ( !aPlot )
1159       return;
1160
1161     if ( theDisplaying == VISU::eDisplayOnly )
1162       aPlot->EraseAll();
1163     QList<Plot2d_Curve*> clist;
1164     aPlot->getCurves( clist );
1165     if ( container->GetNbCurves() > 0 ) {
1166       int nbCurves = container->GetNbCurves();
1167       for ( int k = 1; k <= nbCurves; k++ ) {
1168         VISU::Curve_i* theCurve = container->GetCurve( k );
1169         if ( theCurve && theCurve->IsValid() ) {
1170           SPlot2d_Curve* plotCurve = dynamic_cast<SPlot2d_Curve*>
1171             (aView->getCurveByIO(new SALOME_InteractiveObject(theCurve->GetEntry().c_str(), "", "")));
1172
1173           UpdateCurve( theCurve, aPlot, plotCurve, theDisplaying );
1174
1175           if ( plotCurve && theDisplaying == VISU::eErase ) {
1176             clist.removeAll( plotCurve );
1177           }
1178         }
1179       }
1180     }
1181     aPlot->Repaint();
1182     if(GetResourceMgr()->booleanValue("VISU","automatic_fit_all",false)){
1183       aPlot->fitAll();
1184     }
1185     qApp->processEvents();
1186   }
1187
1188   //------------------------------------------------------------
1189   void
1190   CreatePlot(SalomeApp_Module* theModule,
1191              _PTR(SObject) theTableSO)
1192   {
1193     if ( IsSObjectTable(theTableSO) ) {
1194       CORBA::Object_var aTable = VISU::ClientSObjectToObject(theTableSO);
1195       CORBA::Object_var aContainer = GetVisuGen( theModule )->CreateContainer();
1196       if ( !CORBA::is_nil( aTable ) && !CORBA::is_nil( aContainer ) ) {
1197         VISU::Table_i*     pTable     = dynamic_cast<VISU::Table_i*>(VISU::GetServant(aTable).in());
1198         VISU::Container_i* pContainer = dynamic_cast<VISU::Container_i*>(VISU::GetServant(aContainer).in());
1199
1200         if ( pContainer && pTable ) {
1201           for ( int i = 2; i <= pTable->GetNbRows(); i++ ) {
1202             CORBA::Object_var aNewCurve = GetVisuGen( theModule )->CreateCurve( pTable->_this(), 1, i );
1203             if( !CORBA::is_nil( aNewCurve ) ) {
1204               VISU::Curve_i* pCrv = dynamic_cast<VISU::Curve_i*>( VISU::GetServant(aNewCurve).in() );
1205               if ( pCrv ) {
1206                 pContainer->AddCurve( pCrv->_this() );
1207               }
1208             }
1209           }
1210           PlotContainer( theModule, pContainer, VISU::eDisplay );
1211
1212           QString anEntry = pContainer->GetEntry().c_str();
1213           _PTR(Study) aStudy = theTableSO->GetStudy();
1214           _PTR(SObject) aContainerSO = aStudy->FindObjectID(anEntry.toLatin1().data());
1215           _PTR(SObject) aParentSO = aContainerSO->GetFather();
1216           UpdateObjBrowser(theModule,true,aParentSO);
1217         }
1218       }
1219     }
1220   }
1221
1222   //************************************************************
1223   // Others
1224   VISU::Mesh_i*
1225   CreateMesh(VisuGUI* theModule,
1226              const Handle(SALOME_InteractiveObject)& theIO,
1227              SVTK_ViewWindow* theViewWindow)
1228   {  
1229         _PTR(Study) aStudy = GetCStudy(GetAppStudy(theModule));
1230     //if (CheckLock(aStudy))
1231     //  return;
1232
1233     _PTR(SObject) aResultSObj = aStudy->FindObjectID(theIO->getEntry());
1234
1235     // Get VISU::Result
1236     VISU::Result_var aResult;
1237     VISU::Result_i* pResult = CheckResult(theModule, aResultSObj, aResult);
1238     if (pResult == NULL)
1239       return NULL;
1240
1241     Storable::TRestoringMap aMap = Storable::GetStorableMap(aResultSObj);
1242     if (aMap.empty())
1243       return NULL;
1244
1245     CORBA::Object_var aMesh;
1246     string aComment = Storable::FindValue(aMap,"myComment").toLatin1().data();
1247     string aMeshName = Storable::FindValue(aMap,"myMeshName").toLatin1().data();
1248 #ifdef CHECKTIME
1249     Utils_Timer timer;
1250     timer.Start();
1251 #endif
1252     if (aComment == "ENTITY") {
1253       VISU::Entity anEntity = (VISU::Entity)Storable::FindValue(aMap,"myId").toInt();
1254       if (VISU::Mesh_i::IsPossible(pResult,aMeshName.c_str(),anEntity))
1255         aMesh = GetVisuGen(theModule)->MeshOnEntity(aResult,aMeshName.c_str(),anEntity);
1256     } else if (aComment == "FAMILY") {
1257       VISU::Entity anEntity = (VISU::Entity)Storable::FindValue(aMap,"myEntityId").toInt();
1258       string aFamilyName = Storable::FindValue(aMap,"myName").toLatin1().data();
1259       if (VISU::Mesh_i::IsPossible(pResult,aMeshName.c_str(),anEntity,aFamilyName.c_str()))
1260         aMesh = GetVisuGen(theModule)->FamilyMeshOnEntity
1261           (aResult,aMeshName.c_str(),anEntity,aFamilyName.c_str());
1262     } else if (aComment == "GROUP") {
1263       string aGroupName = Storable::FindValue(aMap,"myName").toLatin1().data();
1264       if (VISU::Mesh_i::IsPossible(pResult,aMeshName.c_str(),aGroupName.c_str()))
1265         aMesh = GetVisuGen(theModule)->GroupMesh(aResult,aMeshName.c_str(),aGroupName.c_str());
1266     }
1267 #ifdef CHECKTIME
1268     timer.Stop();
1269     MESSAGE("VisuGUI::CreateMesh() - CREATE MESH");
1270     timer.Show();
1271 #endif
1272
1273     //QApplication::restoreOverrideCursor();
1274     VISU::Mesh_i* pPresent = NULL;
1275     if (!CORBA::is_nil(aMesh))
1276       pPresent = dynamic_cast<VISU::Mesh_i*>(VISU::GetServant(aMesh).in());
1277     if (pPresent == NULL) {
1278       SUIT_MessageBox::warning (GetDesktop(theModule),
1279                                 QObject::tr("WRN_VISU"),
1280                                 QObject::tr("ERR_CANT_BUILD_PRESENTATION") );
1281       return NULL;
1282     }
1283
1284     if (theViewWindow) {
1285       try {
1286 #ifdef CHECKTIME
1287         Utils_Timer timer;
1288         timer.Start();
1289 #endif
1290         if(GetResourceMgr()->booleanValue("VISU","display_only",false)){
1291           const VisuGUI* av = dynamic_cast<const VisuGUI*>(theModule);
1292           if(av)(const_cast<VisuGUI*>(av))->OnEraseAll();
1293         }
1294         PublishMeshInView(theModule, pPresent, theViewWindow);
1295         if(GetResourceMgr()->booleanValue("VISU","automatic_fit_all",false)){
1296           SetFitAll(theViewWindow);
1297         }
1298 #ifdef CHECKTIME
1299         timer.Stop();
1300         MESSAGE("VisuGUI::CreateMesh() - DISPLAY MESH");
1301         timer.Show();
1302 #endif
1303       } catch (std::runtime_error& exc) {
1304         INFOS(exc.what());
1305         SUIT_MessageBox::warning(GetDesktop(theModule), QObject::tr("WRN_VISU"),
1306                                  QObject::tr("ERR_CANT_CREATE_ACTOR") + ": " + QObject::tr(exc.what()) );
1307       }
1308     }
1309
1310     UpdateObjBrowser(theModule, false, aResultSObj);
1311
1312     theModule->application()->putInfo(QObject::tr("INF_DONE"));
1313     // Make "Save" button active
1314     theModule->getApp()->updateActions();
1315     return pPresent;
1316   }
1317
1318   // ========================================================================================
1319   // GetPrs3dList: find list of presentations for the given object
1320   // ========================================================================================
1321   std::vector<VISU::Prs3d_i*> GetPrs3dList (const SalomeApp_Module* theModule,
1322                                             const Handle(SALOME_InteractiveObject)& theIO,
1323                                             bool theGP)
1324   {
1325     std::vector<VISU::Prs3d_i*> aList;
1326     if (!theIO.IsNull() && theIO->hasEntry()) {
1327       _PTR(Study) aCStudy = GetCStudy(GetAppStudy(theModule));
1328       _PTR(SObject) aSObject = aCStudy->FindObjectID(theIO->getEntry());
1329       aList = GetPrs3dList(theModule, aSObject, theGP);
1330     }
1331     return aList;
1332   }
1333
1334   std::vector<VISU::Prs3d_i*> GetPrs3dList (const SalomeApp_Module* theModule,
1335                                             _PTR(SObject) theObject,
1336                                             bool theGP)
1337   {
1338     std::vector<VISU::Prs3d_i*> aList; int k = 0;
1339     if (!theObject)
1340       return aList;
1341
1342     _PTR(Study) aCStudy = GetCStudy(GetAppStudy(theModule));
1343
1344     CORBA::Object_var aCORBAObject = VISU::ClientSObjectToObject(theObject);
1345     if (!CORBA::is_nil(aCORBAObject)) {
1346       VISU::Base_var aVisuObj = VISU::Base::_narrow(aCORBAObject);
1347       if (!CORBA::is_nil(aVisuObj)) {
1348         VISU::VISUType aType = aVisuObj->GetType();
1349         switch (aType) {
1350         case VISU::TGAUSSPOINTS:
1351           if ( !theGP ) break;
1352         case VISU::TSCALARMAP:
1353         case VISU::TISOSURFACES:
1354         case VISU::TDEFORMEDSHAPE:
1355         case VISU::TCUTPLANES:
1356         case VISU::TCUTLINES:
1357         case VISU::TVECTORS:
1358         case VISU::TSTREAMLINES:
1359         case VISU::TPLOT3D:
1360         case VISU::TSCALARMAPONDEFORMEDSHAPE:
1361         case VISU::TDEFORMEDSHAPEANDSCALARMAP:
1362         case VISU::TMESH:
1363           {
1364             PortableServer::ServantBase_var aServant = VISU::GetServant(aCORBAObject);
1365             if (aServant.in()) {
1366               VISU::Prs3d_i* aPrsObject = dynamic_cast<VISU::Prs3d_i*>(aServant.in());
1367               aList.resize(k+1);
1368               aList[k] = aPrsObject;
1369               k++;
1370             }
1371           }
1372           break;
1373         case VISU::TFIELD:
1374           {
1375             _PTR(ChildIterator) anIter = aCStudy->NewChildIterator(theObject);
1376             _PTR(SObject) aTimeStamp;
1377             anIter->Next(); // First is reference on support
1378             for (; anIter->More(); anIter->Next()) {
1379               aTimeStamp = anIter->Value();
1380               if (!aTimeStamp) continue;
1381               std::vector<VISU::Prs3d_i*> aSubList = GetPrs3dList(theModule, aTimeStamp);
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           }
1392           break;
1393         }
1394       }
1395     } else {
1396       VISU::VISUType aType = VISU::Storable::SObject2Type(theObject);
1397       switch (aType) {
1398       case VISU::TFIELD: {
1399         _PTR(ChildIterator) anIter = aCStudy->NewChildIterator(theObject);
1400         _PTR(SObject) aTimeStamp;
1401         anIter->Next(); // First is reference on support
1402         for (; anIter->More(); anIter->Next()) {
1403           aTimeStamp = anIter->Value();
1404           if (!aTimeStamp) continue;
1405           std::vector<VISU::Prs3d_i*> aSubList = GetPrs3dList(theModule, aTimeStamp);
1406           if (!aSubList.empty()) {
1407             int n = aSubList.size();
1408             aList.resize(k+n);
1409             for (int i = 0; i < n; i++) {
1410               aList[k] = aSubList[i];
1411               k++;
1412             }
1413           }
1414         }
1415         break;
1416       }
1417       case VISU::TTIMESTAMP: {
1418         _PTR(ChildIterator) anIter = aCStudy->NewChildIterator(theObject);
1419         _PTR(SObject) aPrs;
1420         for (; anIter->More(); anIter->Next()) {
1421           aPrs = anIter->Value();
1422           if (!aPrs) continue;
1423           std::vector<VISU::Prs3d_i*> aSubList = GetPrs3dList(theModule, aPrs);
1424           if (!aSubList.empty()) {
1425             int n = aSubList.size();
1426             aList.resize(k+n);
1427             for (int i = 0; i < n; i++) {
1428               aList[k] = aSubList[i];
1429               k++;
1430             }
1431           }
1432         }
1433         break;
1434       }}
1435     }
1436     return aList;
1437   }
1438
1439   //------------------------------------------------------------
1440   int GetFreePositionOfDefaultScalarBar(VisuGUI* theModule, SVTK_ViewWindow* theViewWindow)
1441   {
1442     int minIndx = 1;
1443     std::set<int> aIndexes;
1444     TViewToPrs3d aMap = theModule->getScalarBarsMap();
1445     TViewToPrs3d::const_iterator aViewToPrsIter = aMap.find(theViewWindow);
1446     if (aViewToPrsIter != aMap.end()) {
1447       TSetPrs3d::const_iterator aPrsIter = (aViewToPrsIter->second).begin();
1448       for (; aPrsIter != (aViewToPrsIter->second).end(); aPrsIter++) {
1449         aIndexes.insert((*aPrsIter).second);
1450       }
1451     }
1452     std::set<int>::const_iterator aIter = aIndexes.begin();
1453     for (int i = 1,length = aIndexes.size(); i <= length; i++) {
1454       std::set<int>::const_iterator aIter = aIndexes.find(i);
1455       if (aIter == aIndexes.end()) { minIndx = i; break; } 
1456       else minIndx = i + 1;
1457     }
1458     return minIndx;
1459   }
1460
1461   //------------------------------------------------------------
1462   void AddScalarBarPosition (VisuGUI* theModule, SVTK_ViewWindow* theViewWindow,
1463                              VISU::Prs3d_i* thePrs3d, int pos)
1464   {
1465     TViewToPrs3d& aMap = theModule->getScalarBarsMap();
1466     TPrs3dToInd aPair; aPair.first = thePrs3d; aPair.second = pos;
1467     aMap[theViewWindow].insert(aPair);
1468   }
1469
1470   //------------------------------------------------------------
1471   void RemoveScalarBarPosition(VisuGUI* theModule, SVTK_ViewWindow* theViewWindow,
1472                                VISU::Prs3d_i* thePrs3d)
1473   {
1474     TViewToPrs3d& aMap = theModule->getScalarBarsMap();
1475     TSetPrs3d::iterator aIter = aMap[theViewWindow].begin();
1476     for (; aIter != aMap[theViewWindow].end(); aIter++)
1477       if ((*aIter).first == thePrs3d) {
1478         aMap[theViewWindow].erase(*aIter);
1479         return;
1480       }
1481   }
1482   //------------------------------------------------------------
1483   void initSpinBox( QSpinBox* spinBox, 
1484                     int min,  int max, int step )
1485   {
1486     spinBox->setRange( min, max );
1487     spinBox->setSingleStep( step );
1488   }
1489   //------------------------------------------------------------
1490   void initSpinBox( QDoubleSpinBox* spinBox, 
1491                     double min,  double max, 
1492                     double step, int decimals )
1493   {
1494     spinBox->setRange( min, max );
1495     spinBox->setSingleStep( step );
1496     spinBox->setDecimals( decimals );
1497   }
1498   //------------------------------------------------------------
1499   bool getClippingPlanesFolder(_PTR(Study) theStudy, _PTR(SObject)& theSObject)
1500   {
1501     _PTR(SComponent) aVisuSO = theStudy->FindComponent("VISU");
1502     if (!aVisuSO) return false;
1503     _PTR(SObject) aFolder = theStudy->FindObject(CLIP_PLANES_FOLDER);
1504     if (!aFolder) {
1505       _PTR(StudyBuilder) aBuilder = theStudy->NewBuilder();
1506       aFolder = aBuilder->NewObject(aVisuSO);
1507       
1508       _PTR(GenericAttribute) anAttr;
1509       anAttr = aBuilder->FindOrCreateAttribute(aFolder,"AttributeName");
1510       _PTR(AttributeName) aName(anAttr);
1511       aName->SetValue(CLIP_PLANES_FOLDER);
1512     }
1513     theSObject = aFolder;
1514     return true;
1515   }
1516 }