]> SALOME platform Git repositories - modules/visu.git/blob - src/VISUGUI/VisuGUI_Tools.cxx
Salome HOME
4748228c14b6503032c31862c1c168916063e586
[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 && theModule->application() ? theModule->application()->desktop() : 0;
90   }
91
92   //------------------------------------------------------------
93   LightApp_SelectionMgr*
94   GetSelectionMgr(const SalomeApp_Module* theModule)
95   {
96     return theModule && theModule->getApp() ? theModule->getApp()->selectionMgr() : 0;
97   }
98
99   //------------------------------------------------------------
100   SalomeApp_Study*
101   GetAppStudy(const CAM_Module* theModule)
102   {
103     return theModule && theModule->application() ? 
104       dynamic_cast<SalomeApp_Study*>(theModule->application()->activeStudy()) : 0;
105   }
106
107   //------------------------------------------------------------
108   _PTR(Study)
109   GetCStudy(const SalomeApp_Study* theStudy)
110   {
111     return theStudy ? theStudy->studyDS() : _PTR(Study)();
112   }
113
114   //------------------------------------------------------------
115   bool
116   IsStudyLocked( _PTR(Study) theStudy )
117   {
118     return theStudy ? theStudy->GetProperties()->IsLocked() : true;
119   }
120
121   //------------------------------------------------------------
122   bool
123   CheckLock( _PTR(Study) theStudy,
124              QWidget* theWidget )
125   {
126     if(IsStudyLocked(theStudy)){
127       SUIT_MessageBox::warning(theWidget,
128                                QObject::tr("WRN_VISU_WARNING"),
129                                QObject::tr("WRN_STUDY_LOCKED") );
130         return true;
131     }
132     return false;
133   }
134
135   //------------------------------------------------------------
136   int
137   runAndWait( QDialog* dlg, const bool modal )
138   {
139     VisuGUI_DialogRunner r( dlg );
140     return r.run( modal );
141   }
142
143   //------------------------------------------------------------
144   LightApp_DataObject*
145   FindDataObject(SUIT_DataObject* theDataObject,
146                  const QString& theEntry,
147                  int theLevel)
148   {
149     int aLevel = theDataObject->level() + 2;
150     QString aSourceEntry = theEntry.section(':',0,aLevel);
151     DataObjectList aList;
152     theDataObject->children(aList);
153     DataObjectList::Iterator aDataObjectIter = aList.begin();
154     while( aDataObjectIter!= aList.end() ) {
155       if(LightApp_DataObject* aChildDataObject = dynamic_cast<LightApp_DataObject*>(*aDataObjectIter)){
156         QString anEntry = aChildDataObject->entry();
157         QString aCurrentEntry = anEntry.section(':',0,aLevel);
158         if(aSourceEntry == aCurrentEntry){
159           if(theLevel == aLevel){
160             return aChildDataObject;
161           }else{
162             return FindDataObject(aChildDataObject,theEntry,theLevel);
163           }
164         }
165       }
166       aDataObjectIter++;
167     }
168     return NULL;
169   }
170
171   //------------------------------------------------------------
172   LightApp_DataObject*
173   FindDataObject(CAM_Module* theModule,
174                  _PTR(SObject) theSObject)
175   {
176     CAM_DataModel* aDataModel = theModule->dataModel();
177     CAM_DataObject* aRootDataObject = aDataModel->root();
178     if(_PTR(SComponent) aComponent = theSObject)
179       return dynamic_cast<LightApp_DataObject*>(aRootDataObject);
180
181     int aLevel = theSObject->Depth();
182     std::string anEntry = theSObject->GetID();
183     return FindDataObject(aRootDataObject,anEntry.c_str(),aLevel);
184   }
185
186   //------------------------------------------------------------
187   void
188   UpdateObjBrowser(SalomeApp_Module* theModule,
189                    bool theIsUpdateDataModel,
190                    _PTR(SObject) theSObject)
191   {
192     LightApp_DataObject* aDataObject = NULL;
193     if(theSObject)
194       aDataObject = FindDataObject(theModule,theSObject);
195
196     theModule->updateObjBrowser(theIsUpdateDataModel,aDataObject);
197     theModule->getApp()->updateActions();
198   }
199
200   //------------------------------------------------------------
201   bool
202   IsSObjectTable( _PTR(SObject) theSObject )
203   {
204     if ( theSObject ) {
205       _PTR(GenericAttribute) anAttr;
206       if (theSObject->FindAttribute( anAttr, "AttributeTableOfInteger" ))
207         return true;
208       if (theSObject->FindAttribute( anAttr, "AttributeTableOfReal" ))
209         return true;
210     }
211     return false;
212   }
213
214   //------------------------------------------------------------
215   VISU_Gen_i*
216   GetVisuGen(const CAM_Module* theModule)
217   {
218     static VISU_Gen_i* aGen = NULL;
219     if(!aGen){
220       SALOME_LifeCycleCORBA aLCC(SalomeApp_Application::namingService());
221       Engines::Component_var aComponent = aLCC.FindOrLoad_Component("FactoryServer","VISU");
222       VISU_Gen_var aVISU = VISU_Gen::_narrow(aComponent);
223       if(!CORBA::is_nil(aVISU)){
224         if((aGen = VISU_Gen_i::GetVisuGenImpl()))
225           aGen->SetCurrentStudy(GetDSStudy(GetCStudy(GetAppStudy(theModule))));
226       }
227     }
228     if(!aGen)
229       throw std::runtime_error(QObject::tr("ERR_CANT_FIND_VISU_COMPONENT").toLatin1().data());
230     return aGen;
231   }
232
233   //------------------------------------------------------------
234   SALOME_MED::MED_Gen_var
235   GetMEDEngine()
236   {
237     static SALOME_MED::MED_Gen_var aGen;
238     if(CORBA::is_nil(aGen)){
239       SALOME_LifeCycleCORBA aLCC(SalomeApp_Application::namingService());
240       Engines::Component_var aComponent = aLCC.FindOrLoad_Component("FactoryServer","MED");
241       aGen = SALOME_MED::MED_Gen::_narrow(aComponent);
242     }
243     if(CORBA::is_nil(aGen))
244       throw std::runtime_error(QObject::tr("ERR_CANT_FIND_MED_COMPONENT").toLatin1().data());
245     return aGen;
246   }
247
248
249   //----------------------------------------------------------------------------
250   // Selection
251   TSelectionInfo
252   GetSelectedObjects(const SalomeApp_Module* theModule)
253   {
254     TSelectionInfo aSelectionInfo;
255     const SalomeApp_Study* aStudy = GetAppStudy(theModule);
256     LightApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(theModule);
257     if ( aStudy && aSelectionMgr ) {
258       SALOME_ListIO aListIO;
259       aSelectionMgr->selectedObjects(aListIO);
260       SALOME_ListIteratorOfListIO anIter(aListIO);
261       while(anIter.More())
262       {
263         Handle(SALOME_InteractiveObject) anIO = anIter.Value();
264         if(anIO->hasEntry())
265         {
266           TObjectInfo anObjectInfo = GetObjectByEntry(aStudy, anIO->getEntry());
267           if(anObjectInfo.mySObject){
268             TSelectionItem aSelectionItem;
269             aSelectionItem.myObjectInfo = anObjectInfo;
270             aSelectionItem.myIO = anIO;
271             aSelectionInfo.push_back(aSelectionItem);
272           }
273         }
274         anIter.Next(); // MULTIPR fixed
275       }
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     VTK::ActorCollectionCopy aCopy(aRen->GetActors());
874     vtkActorCollection *anActColl = aCopy.GetActors(); 
875     vtkProp *prop;
876     vtkFloatingPointType *bounds;
877     int somethingVisible = false;
878
879     allBounds[0] = allBounds[2] = allBounds[4] = VTK_LARGE_FLOAT;
880     allBounds[1] = allBounds[3] = allBounds[5] = -VTK_LARGE_FLOAT;
881     // loop through all props
882     for (anActColl->InitTraversal(); (prop = anActColl->GetNextProp()); ) {
883       // if it's invisible, or has no geometry, we can skip the rest 
884       if (prop->GetVisibility() && prop->IsA(theActorClassName)) {
885         bounds = prop->GetBounds();
886         // make sure we haven't got bogus bounds
887         if (bounds != NULL &&
888             bounds[0] > -VTK_LARGE_FLOAT && bounds[1] < VTK_LARGE_FLOAT &&
889             bounds[2] > -VTK_LARGE_FLOAT && bounds[3] < VTK_LARGE_FLOAT &&
890             bounds[4] > -VTK_LARGE_FLOAT && bounds[5] < VTK_LARGE_FLOAT)
891         {
892           somethingVisible = true;
893           if (bounds[0] < allBounds[0]) allBounds[0] = bounds[0]; 
894           if (bounds[1] > allBounds[1]) allBounds[1] = bounds[1]; 
895           if (bounds[2] < allBounds[2]) allBounds[2] = bounds[2]; 
896           if (bounds[3] > allBounds[3]) allBounds[3] = bounds[3]; 
897           if (bounds[4] < allBounds[4]) allBounds[4] = bounds[4]; 
898           if (bounds[5] > allBounds[5]) allBounds[5] = bounds[5]; 
899         }//not bogus
900       }
901     }
902     return somethingVisible;
903   }
904
905   //------------------------------------------------------------
906   void SetFitAll(SVTK_ViewWindow* theViewWindow)
907   {
908     static vtkFloatingPointType PRECISION = 0.000001;
909     static vtkFloatingPointType DEVIATION = 600;
910     vtkFloatingPointType XYZ_Bnd[6];
911     if (!ComputeVisiblePropBounds(theViewWindow, XYZ_Bnd)) return;
912
913     vtkFloatingPointType absX = XYZ_Bnd[1] - XYZ_Bnd[0];
914     vtkFloatingPointType absY = XYZ_Bnd[3] - XYZ_Bnd[2];
915     vtkFloatingPointType absZ = XYZ_Bnd[5] - XYZ_Bnd[4];
916
917     enum CameraOrient {e3D, eFront, eLeft, eTop};
918     CameraOrient aCameraOrient = e3D;
919     if (absX <= PRECISION) aCameraOrient = eFront;
920     else {
921       if (absY <= PRECISION) aCameraOrient = eLeft;
922       else {
923         if (absZ <= PRECISION) aCameraOrient = eTop;
924         else {
925           // all the three dimensions exceeds precision
926           vtkFloatingPointType dev_abs_XY = absX / absY;
927           vtkFloatingPointType dev_abs_YZ = absY / absZ;
928           vtkFloatingPointType dev_abs_XZ = absX / absZ;
929           if (dev_abs_XY >= DEVIATION || 1./dev_abs_YZ >= DEVIATION)
930             aCameraOrient = eLeft;
931           else {
932             if (1./dev_abs_XY >= DEVIATION || 1./dev_abs_XZ >= DEVIATION)
933               aCameraOrient = eFront;
934             else {
935               if (dev_abs_XZ >= DEVIATION || dev_abs_YZ >= DEVIATION)
936                 aCameraOrient = eTop;
937             }
938           }
939         }
940       }
941     }
942
943     switch (aCameraOrient) {
944     case eFront: theViewWindow->onFrontView(); break;
945     case eLeft:  theViewWindow->onLeftView();  break;
946     case eTop:   theViewWindow->onTopView();   break;
947     case e3D:    theViewWindow->onResetView(); break;
948     }
949     theViewWindow->getRenderer()->ResetCameraClippingRange();
950     theViewWindow->onFitAll();
951   }
952
953   //************************************************************
954   // Plot2d View
955
956   SPlot2d_Viewer*
957   GetPlot2dViewer(const SalomeApp_Module* theModule, const bool theCreate)
958   {
959     if(SalomeApp_Application* anApp = theModule->getApp()){
960       if(SUIT_ViewManager* aViewManager = anApp->getViewManager( Plot2d_Viewer::Type(), theCreate )){
961         return dynamic_cast<SPlot2d_Viewer*>(aViewManager->getViewModel());
962       }
963     }
964     return NULL;
965   }
966
967   //------------------------------------------------------------
968   // Internal function used by several public functions below
969   void
970   UpdateCurve(VISU::Curve_i* theCurve,
971               Plot2d_ViewFrame* aPlot,
972               SPlot2d_Curve* plotCurve,
973               int theDisplaying)
974   {
975     if ( theDisplaying == VISU::eErase ) {
976       if ( plotCurve && aPlot )
977         aPlot->eraseCurve( plotCurve, false );
978     }
979     else if ( theDisplaying == VISU::eDisplay || theDisplaying == VISU::eDisplayOnly ) {
980       if ( plotCurve ) {
981         plotCurve->setHorTitle( theCurve->GetHorTitle().c_str() );
982         //plotCurve->setVerTitle( ( theCurve->GetVerTitle().c_str() ) );
983         plotCurve->setVerTitle( theCurve->GetName().c_str() );
984         plotCurve->setHorUnits( theCurve->GetHorUnits().c_str() );
985         plotCurve->setVerUnits( theCurve->GetVerUnits().c_str() );
986         double* xList = 0;
987         double* yList = 0;
988         QStringList zList;
989         int     nbPoints = theCurve->GetData( xList, yList, zList );
990         if ( nbPoints > 0 && xList && yList ) {
991           plotCurve->setData( xList, yList, nbPoints, zList );
992         }
993         if ( !theCurve->IsAuto() ) {
994           plotCurve->setLine( (Plot2d::LineType)theCurve->GetLine(), theCurve->GetLineWidth() );
995           plotCurve->setMarker( (Plot2d::MarkerType)theCurve->GetMarker() );
996           SALOMEDS::Color color = theCurve->GetColor();
997           plotCurve->setColor( QColor( (int)(color.R*255.), (int)(color.G*255.), (int)(color.B*255.) ) );
998         }
999         plotCurve->setAutoAssign( theCurve->IsAuto() );
1000         if( aPlot )
1001           aPlot->displayCurve( plotCurve, false );
1002       }
1003       else {
1004         Plot2d_Curve* crv = theCurve->CreatePresentation();
1005         if ( crv ) {
1006           if( aPlot )
1007             aPlot->displayCurve( crv, false );
1008           theCurve->SetLine( (VISU::Curve::LineType)crv->getLine(), crv->getLineWidth() );
1009           theCurve->SetMarker( (VISU::Curve::MarkerType)crv->getMarker());
1010           SALOMEDS::Color newColor;
1011           newColor.R = crv->getColor().red()/255.;
1012           newColor.G = crv->getColor().green()/255.;
1013           newColor.B = crv->getColor().blue()/255.;
1014           theCurve->SetColor( newColor );
1015           crv->setAutoAssign( theCurve->IsAuto() );
1016         }
1017       }
1018     }
1019   }
1020
1021   //------------------------------------------------------------
1022   void
1023   PlotTable(const SalomeApp_Module* theModule,
1024             VISU::Table_i* table,
1025             int theDisplaying)
1026   {
1027     SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true ); // create if necessary
1028     if ( !aView )
1029       return;
1030     Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
1031     if ( !aPlot )
1032       return;
1033
1034     if ( theDisplaying == VISU::eDisplayOnly )
1035       aPlot->EraseAll();
1036     QList<Plot2d_Curve*> clist;
1037     aPlot->getCurves( clist );
1038     _PTR(Study) aStudy = GetCStudy( GetAppStudy( theModule ) );
1039     _PTR(SObject) TableSO = aStudy->FindObjectID( table->GetEntry() );
1040     if ( TableSO ) {
1041       _PTR(ChildIterator) Iter = aStudy->NewChildIterator( TableSO );
1042       for ( ; Iter->More(); Iter->Next() ) {
1043         CORBA::Object_var childObject = VISU::ClientSObjectToObject( Iter->Value() );
1044         if( !CORBA::is_nil( childObject ) ) {
1045           CORBA::Object_ptr aCurve = VISU::Curve::_narrow( childObject );
1046           if( !CORBA::is_nil( aCurve ) ) {
1047             VISU::Curve_i* theCurve = dynamic_cast<VISU::Curve_i*>(VISU::GetServant(aCurve).in());
1048             SPlot2d_Curve* plotCurve = 0;
1049             SPlot2d_Curve* tmpCurve;
1050             for ( int i = 0; i < clist.count(); i++ ) {
1051               tmpCurve = dynamic_cast<SPlot2d_Curve*>( clist.at( i ) );
1052               if (tmpCurve && tmpCurve->hasIO() &&
1053                   theCurve->GetEntry() == tmpCurve->getIO()->getEntry()) {
1054                 plotCurve = tmpCurve;
1055                 break;
1056               }
1057             }
1058
1059             UpdateCurve( theCurve, aPlot, plotCurve, theDisplaying );
1060
1061             if ( theDisplaying == VISU::eErase && plotCurve ) {
1062               clist.removeAll(plotCurve );
1063             }
1064           }
1065         }
1066       }
1067       aPlot->Repaint();
1068     }
1069   }
1070
1071   //------------------------------------------------------------
1072   void
1073   PlotCurve(const SalomeApp_Module* theModule,
1074             VISU::Curve_i* theCurve,
1075             int theDisplaying)
1076   {
1077     SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true );
1078     if ( !aView )
1079       return;
1080     Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
1081     if ( !aPlot )
1082       return;
1083
1084 //  if ( theDisplaying == VISU::eDisplayOnly )
1085 //    aPlot->EraseAll();
1086     QList<Plot2d_Curve*> clist;
1087     aPlot->getCurves( clist );
1088     SPlot2d_Curve* plotCurve = 0;
1089     SPlot2d_Curve* tmpCurve;
1090     if(theDisplaying == VISU::eErase) {
1091       // 23.06.2008 skl for IPAL17672
1092       for (int i = 0; i < clist.count(); i++) {
1093         tmpCurve = dynamic_cast<SPlot2d_Curve*>(clist.at(i));
1094         if (tmpCurve && tmpCurve->hasIO() &&
1095             theCurve->GetEntry() == tmpCurve->getIO()->getEntry()) {
1096           plotCurve = tmpCurve;
1097           aPlot->eraseCurve(clist.at(i));
1098           break;
1099         }
1100       }
1101       UpdateCurve(theCurve, aPlot, plotCurve, theDisplaying);
1102     }
1103     else {
1104       for (int i = 0; i < clist.count(); i++) {
1105         tmpCurve = dynamic_cast<SPlot2d_Curve*>(clist.at(i));
1106         if (tmpCurve && tmpCurve->hasIO() &&
1107             theCurve->GetEntry() == tmpCurve->getIO()->getEntry()) {
1108           plotCurve = tmpCurve;
1109         }
1110         else if (theDisplaying == VISU::eDisplayOnly) {
1111           aPlot->eraseCurve(clist.at(i));
1112         }
1113       }
1114       UpdateCurve(theCurve, aPlot, plotCurve, theDisplaying);
1115     }
1116
1117     aPlot->Repaint();
1118   }
1119
1120   //------------------------------------------------------------
1121   void
1122   PlotRemoveCurve(const SalomeApp_Module* theModule,
1123                   VISU::Curve_i* pCrv)
1124   {
1125     QString anEntry = pCrv->GetEntry().c_str();
1126     ViewManagerList pvm_list;
1127     theModule->getApp()->viewManagers( SPlot2d_Viewer::Type(), pvm_list );
1128     ViewManagerList::Iterator pvm_it = pvm_list.begin();
1129     for( ; pvm_it != pvm_list.end(); pvm_it++ ){
1130       Plot2d_ViewManager* pvm = dynamic_cast<Plot2d_ViewManager*>( *pvm_it );
1131       if( pvm ){
1132         SPlot2d_Viewer* aSPlot2d = dynamic_cast<SPlot2d_Viewer*>( pvm->getViewModel() );
1133         if( aSPlot2d ){
1134           Plot2d_ViewFrame* aPlot = aSPlot2d->getActiveViewFrame();
1135           if(aPlot){
1136             QList<Plot2d_Curve*> clist;
1137             aPlot->getCurves( clist );
1138             for (int i = 0; i < clist.count(); i++) {
1139               if(SPlot2d_Curve* plotCurve = dynamic_cast<SPlot2d_Curve*>(clist[i]))
1140                 if(plotCurve->hasIO() && (plotCurve->getIO()->getEntry() == anEntry))
1141                   aPlot->eraseCurve(clist[i]);
1142             }
1143           }
1144         }
1145       }
1146     }
1147   }
1148   
1149   //------------------------------------------------------------
1150   void
1151   PlotContainer(const SalomeApp_Module* theModule,
1152                 VISU::Container_i* container,
1153                 int theDisplaying)
1154   {
1155     SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true );
1156     if ( !aView )
1157       return;
1158     Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
1159     if ( !aPlot )
1160       return;
1161
1162     if ( theDisplaying == VISU::eDisplayOnly )
1163       aPlot->EraseAll();
1164     QList<Plot2d_Curve*> clist;
1165     aPlot->getCurves( clist );
1166     if ( container->GetNbCurves() > 0 ) {
1167       int nbCurves = container->GetNbCurves();
1168       for ( int k = 1; k <= nbCurves; k++ ) {
1169         VISU::Curve_i* theCurve = container->GetCurve( k );
1170         if ( theCurve && theCurve->IsValid() ) {
1171           SPlot2d_Curve* plotCurve = dynamic_cast<SPlot2d_Curve*>
1172             (aView->getCurveByIO(new SALOME_InteractiveObject(theCurve->GetEntry().c_str(), "", "")));
1173
1174           UpdateCurve( theCurve, aPlot, plotCurve, theDisplaying );
1175
1176           if ( plotCurve && theDisplaying == VISU::eErase ) {
1177             clist.removeAll( plotCurve );
1178           }
1179         }
1180       }
1181     }
1182     aPlot->Repaint();
1183     if(GetResourceMgr()->booleanValue("VISU","automatic_fit_all",false)){
1184       aPlot->fitAll();
1185     }
1186     qApp->processEvents();
1187   }
1188
1189   //------------------------------------------------------------
1190   void
1191   CreatePlot(SalomeApp_Module* theModule,
1192              _PTR(SObject) theTableSO)
1193   {
1194     if ( IsSObjectTable(theTableSO) ) {
1195       CORBA::Object_var aTable = VISU::ClientSObjectToObject(theTableSO);
1196       CORBA::Object_var aContainer = GetVisuGen( theModule )->CreateContainer();
1197       if ( !CORBA::is_nil( aTable ) && !CORBA::is_nil( aContainer ) ) {
1198         VISU::Table_i*     pTable     = dynamic_cast<VISU::Table_i*>(VISU::GetServant(aTable).in());
1199         VISU::Container_i* pContainer = dynamic_cast<VISU::Container_i*>(VISU::GetServant(aContainer).in());
1200
1201         if ( pContainer && pTable ) {
1202           for ( int i = 2; i <= pTable->GetNbRows(); i++ ) {
1203             CORBA::Object_var aNewCurve = GetVisuGen( theModule )->CreateCurve( pTable->_this(), 1, i );
1204             if( !CORBA::is_nil( aNewCurve ) ) {
1205               VISU::Curve_i* pCrv = dynamic_cast<VISU::Curve_i*>( VISU::GetServant(aNewCurve).in() );
1206               if ( pCrv ) {
1207                 pContainer->AddCurve( pCrv->_this() );
1208               }
1209             }
1210           }
1211           PlotContainer( theModule, pContainer, VISU::eDisplay );
1212
1213           QString anEntry = pContainer->GetEntry().c_str();
1214           _PTR(Study) aStudy = theTableSO->GetStudy();
1215           _PTR(SObject) aContainerSO = aStudy->FindObjectID(anEntry.toLatin1().data());
1216           _PTR(SObject) aParentSO = aContainerSO->GetFather();
1217           UpdateObjBrowser(theModule,true,aParentSO);
1218         }
1219       }
1220     }
1221   }
1222
1223   //************************************************************
1224   // Others
1225   VISU::Mesh_i*
1226   CreateMesh(VisuGUI* theModule,
1227              const Handle(SALOME_InteractiveObject)& theIO,
1228              SVTK_ViewWindow* theViewWindow)
1229   {  
1230         _PTR(Study) aStudy = GetCStudy(GetAppStudy(theModule));
1231     //if (CheckLock(aStudy))
1232     //  return;
1233
1234     _PTR(SObject) aResultSObj = aStudy->FindObjectID(theIO->getEntry());
1235
1236     // Get VISU::Result
1237     VISU::Result_var aResult;
1238     VISU::Result_i* pResult = CheckResult(theModule, aResultSObj, aResult);
1239     if (pResult == NULL)
1240       return NULL;
1241
1242     Storable::TRestoringMap aMap = Storable::GetStorableMap(aResultSObj);
1243     if (aMap.empty())
1244       return NULL;
1245
1246     CORBA::Object_var aMesh;
1247     string aComment = Storable::FindValue(aMap,"myComment").toLatin1().data();
1248     string aMeshName = Storable::FindValue(aMap,"myMeshName").toLatin1().data();
1249 #ifdef CHECKTIME
1250     Utils_Timer timer;
1251     timer.Start();
1252 #endif
1253     if (aComment == "ENTITY") {
1254       VISU::Entity anEntity = (VISU::Entity)Storable::FindValue(aMap,"myId").toInt();
1255       if (VISU::Mesh_i::IsPossible(pResult,aMeshName.c_str(),anEntity))
1256         aMesh = GetVisuGen(theModule)->MeshOnEntity(aResult,aMeshName.c_str(),anEntity);
1257     } else if (aComment == "FAMILY") {
1258       VISU::Entity anEntity = (VISU::Entity)Storable::FindValue(aMap,"myEntityId").toInt();
1259       string aFamilyName = Storable::FindValue(aMap,"myName").toLatin1().data();
1260       if (VISU::Mesh_i::IsPossible(pResult,aMeshName.c_str(),anEntity,aFamilyName.c_str()))
1261         aMesh = GetVisuGen(theModule)->FamilyMeshOnEntity
1262           (aResult,aMeshName.c_str(),anEntity,aFamilyName.c_str());
1263     } else if (aComment == "GROUP") {
1264       string aGroupName = Storable::FindValue(aMap,"myName").toLatin1().data();
1265       if (VISU::Mesh_i::IsPossible(pResult,aMeshName.c_str(),aGroupName.c_str()))
1266         aMesh = GetVisuGen(theModule)->GroupMesh(aResult,aMeshName.c_str(),aGroupName.c_str());
1267     }
1268 #ifdef CHECKTIME
1269     timer.Stop();
1270     MESSAGE("VisuGUI::CreateMesh() - CREATE MESH");
1271     timer.Show();
1272 #endif
1273
1274     //QApplication::restoreOverrideCursor();
1275     VISU::Mesh_i* pPresent = NULL;
1276     if (!CORBA::is_nil(aMesh))
1277       pPresent = dynamic_cast<VISU::Mesh_i*>(VISU::GetServant(aMesh).in());
1278     if (pPresent == NULL) {
1279       SUIT_MessageBox::warning (GetDesktop(theModule),
1280                                 QObject::tr("WRN_VISU"),
1281                                 QObject::tr("ERR_CANT_BUILD_PRESENTATION") );
1282       return NULL;
1283     }
1284
1285     if (theViewWindow) {
1286       try {
1287 #ifdef CHECKTIME
1288         Utils_Timer timer;
1289         timer.Start();
1290 #endif
1291         if(GetResourceMgr()->booleanValue("VISU","display_only",false)){
1292           const VisuGUI* av = dynamic_cast<const VisuGUI*>(theModule);
1293           if(av)(const_cast<VisuGUI*>(av))->OnEraseAll();
1294         }
1295         PublishMeshInView(theModule, pPresent, theViewWindow);
1296         if(GetResourceMgr()->booleanValue("VISU","automatic_fit_all",false)){
1297           SetFitAll(theViewWindow);
1298         }
1299 #ifdef CHECKTIME
1300         timer.Stop();
1301         MESSAGE("VisuGUI::CreateMesh() - DISPLAY MESH");
1302         timer.Show();
1303 #endif
1304       } catch (std::runtime_error& exc) {
1305         INFOS(exc.what());
1306         SUIT_MessageBox::warning(GetDesktop(theModule), QObject::tr("WRN_VISU"),
1307                                  QObject::tr("ERR_CANT_CREATE_ACTOR") + ": " + QObject::tr(exc.what()) );
1308       }
1309     }
1310
1311     UpdateObjBrowser(theModule, false, aResultSObj);
1312
1313     theModule->application()->putInfo(QObject::tr("INF_DONE"));
1314     // Make "Save" button active
1315     theModule->getApp()->updateActions();
1316     return pPresent;
1317   }
1318
1319   // ========================================================================================
1320   // GetPrs3dList: find list of presentations for the given object
1321   // ========================================================================================
1322   std::vector<VISU::Prs3d_i*> GetPrs3dList (const SalomeApp_Module* theModule,
1323                                             const Handle(SALOME_InteractiveObject)& theIO,
1324                                             bool theGP)
1325   {
1326     std::vector<VISU::Prs3d_i*> aList;
1327     if (!theIO.IsNull() && theIO->hasEntry()) {
1328       _PTR(Study) aCStudy = GetCStudy(GetAppStudy(theModule));
1329       _PTR(SObject) aSObject = aCStudy->FindObjectID(theIO->getEntry());
1330       aList = GetPrs3dList(theModule, aSObject, theGP);
1331     }
1332     return aList;
1333   }
1334
1335   std::vector<VISU::Prs3d_i*> GetPrs3dList (const SalomeApp_Module* theModule,
1336                                             _PTR(SObject) theObject,
1337                                             bool theGP)
1338   {
1339     std::vector<VISU::Prs3d_i*> aList; int k = 0;
1340     if (!theObject)
1341       return aList;
1342
1343     _PTR(Study) aCStudy = GetCStudy(GetAppStudy(theModule));
1344
1345     CORBA::Object_var aCORBAObject = VISU::ClientSObjectToObject(theObject);
1346     if (!CORBA::is_nil(aCORBAObject)) {
1347       VISU::Base_var aVisuObj = VISU::Base::_narrow(aCORBAObject);
1348       if (!CORBA::is_nil(aVisuObj)) {
1349         VISU::VISUType aType = aVisuObj->GetType();
1350         switch (aType) {
1351         case VISU::TGAUSSPOINTS:
1352           if ( !theGP ) break;
1353         case VISU::TSCALARMAP:
1354         case VISU::TISOSURFACES:
1355         case VISU::TDEFORMEDSHAPE:
1356         case VISU::TCUTPLANES:
1357         case VISU::TCUTLINES:
1358         case VISU::TCUTSEGMENT:
1359         case VISU::TVECTORS:
1360         case VISU::TSTREAMLINES:
1361         case VISU::TPLOT3D:
1362         case VISU::TSCALARMAPONDEFORMEDSHAPE:
1363         case VISU::TDEFORMEDSHAPEANDSCALARMAP:
1364         case VISU::TMESH:
1365           {
1366             PortableServer::ServantBase_var aServant = VISU::GetServant(aCORBAObject);
1367             if (aServant.in()) {
1368               VISU::Prs3d_i* aPrsObject = dynamic_cast<VISU::Prs3d_i*>(aServant.in());
1369               aList.resize(k+1);
1370               aList[k] = aPrsObject;
1371               k++;
1372             }
1373           }
1374           break;
1375         case VISU::TFIELD:
1376           {
1377             _PTR(ChildIterator) anIter = aCStudy->NewChildIterator(theObject);
1378             _PTR(SObject) aTimeStamp;
1379             anIter->Next(); // First is reference on support
1380             for (; anIter->More(); anIter->Next()) {
1381               aTimeStamp = anIter->Value();
1382               if (!aTimeStamp) continue;
1383               std::vector<VISU::Prs3d_i*> aSubList = GetPrs3dList(theModule, aTimeStamp);
1384               if (!aSubList.empty()) {
1385                 int n = aSubList.size();
1386                 aList.resize(k+n);
1387                 for (int i = 0; i < n; i++) {
1388                   aList[k] = aSubList[i];
1389                   k++;
1390                 }
1391               }
1392             }
1393           }
1394           break;
1395         }
1396       }
1397     } else {
1398       VISU::VISUType aType = VISU::Storable::SObject2Type(theObject);
1399       switch (aType) {
1400       case VISU::TFIELD: {
1401         _PTR(ChildIterator) anIter = aCStudy->NewChildIterator(theObject);
1402         _PTR(SObject) aTimeStamp;
1403         anIter->Next(); // First is reference on support
1404         for (; anIter->More(); anIter->Next()) {
1405           aTimeStamp = anIter->Value();
1406           if (!aTimeStamp) continue;
1407           std::vector<VISU::Prs3d_i*> aSubList = GetPrs3dList(theModule, aTimeStamp);
1408           if (!aSubList.empty()) {
1409             int n = aSubList.size();
1410             aList.resize(k+n);
1411             for (int i = 0; i < n; i++) {
1412               aList[k] = aSubList[i];
1413               k++;
1414             }
1415           }
1416         }
1417         break;
1418       }
1419       case VISU::TTIMESTAMP: {
1420         _PTR(ChildIterator) anIter = aCStudy->NewChildIterator(theObject);
1421         _PTR(SObject) aPrs;
1422         for (; anIter->More(); anIter->Next()) {
1423           aPrs = anIter->Value();
1424           if (!aPrs) continue;
1425           std::vector<VISU::Prs3d_i*> aSubList = GetPrs3dList(theModule, aPrs);
1426           if (!aSubList.empty()) {
1427             int n = aSubList.size();
1428             aList.resize(k+n);
1429             for (int i = 0; i < n; i++) {
1430               aList[k] = aSubList[i];
1431               k++;
1432             }
1433           }
1434         }
1435         break;
1436       }}
1437     }
1438     return aList;
1439   }
1440
1441   //------------------------------------------------------------
1442   int GetFreePositionOfDefaultScalarBar(VisuGUI* theModule, SVTK_ViewWindow* theViewWindow)
1443   {
1444     int minIndx = 1;
1445     std::set<int> aIndexes;
1446     TViewToPrs3d aMap = theModule->getScalarBarsMap();
1447     TViewToPrs3d::const_iterator aViewToPrsIter = aMap.find(theViewWindow);
1448     if (aViewToPrsIter != aMap.end()) {
1449       TSetPrs3d::const_iterator aPrsIter = (aViewToPrsIter->second).begin();
1450       for (; aPrsIter != (aViewToPrsIter->second).end(); aPrsIter++) {
1451         aIndexes.insert((*aPrsIter).second);
1452       }
1453     }
1454     std::set<int>::const_iterator aIter = aIndexes.begin();
1455     for (int i = 1,length = aIndexes.size(); i <= length; i++) {
1456       std::set<int>::const_iterator aIter = aIndexes.find(i);
1457       if (aIter == aIndexes.end()) { minIndx = i; break; } 
1458       else minIndx = i + 1;
1459     }
1460     return minIndx;
1461   }
1462
1463   //------------------------------------------------------------
1464   void AddScalarBarPosition (VisuGUI* theModule, SVTK_ViewWindow* theViewWindow,
1465                              VISU::Prs3d_i* thePrs3d, int pos)
1466   {
1467     TViewToPrs3d& aMap = theModule->getScalarBarsMap();
1468     TPrs3dToInd aPair; aPair.first = thePrs3d; aPair.second = pos;
1469     aMap[theViewWindow].insert(aPair);
1470   }
1471
1472   //------------------------------------------------------------
1473   void RemoveScalarBarPosition(VisuGUI* theModule, SVTK_ViewWindow* theViewWindow,
1474                                VISU::Prs3d_i* thePrs3d)
1475   {
1476     TViewToPrs3d& aMap = theModule->getScalarBarsMap();
1477     TSetPrs3d::iterator aIter = aMap[theViewWindow].begin();
1478     for (; aIter != aMap[theViewWindow].end(); aIter++)
1479       if ((*aIter).first == thePrs3d) {
1480         aMap[theViewWindow].erase(*aIter);
1481         return;
1482       }
1483   }
1484   //------------------------------------------------------------
1485   void initSpinBox( QSpinBox* spinBox, 
1486                     int min,  int max, int step )
1487   {
1488     spinBox->setRange( min, max );
1489     spinBox->setSingleStep( step );
1490   }
1491   //------------------------------------------------------------
1492   void initSpinBox( QDoubleSpinBox* spinBox, 
1493                     double min,  double max, 
1494                     double step, int decimals )
1495   {
1496     spinBox->setRange( min, max );
1497     spinBox->setSingleStep( step );
1498     spinBox->setDecimals( decimals );
1499   }
1500   //------------------------------------------------------------
1501   bool getClippingPlanesFolder(_PTR(Study) theStudy, _PTR(SObject)& theSObject)
1502   {
1503     _PTR(SComponent) aVisuSO = theStudy->FindComponent("VISU");
1504     if (!aVisuSO) return false;
1505     _PTR(SObject) aFolder = theStudy->FindObject(CLIP_PLANES_FOLDER);
1506     if (!aFolder) {
1507       _PTR(StudyBuilder) aBuilder = theStudy->NewBuilder();
1508       aFolder = aBuilder->NewObject(aVisuSO);
1509       
1510       _PTR(GenericAttribute) anAttr;
1511       anAttr = aBuilder->FindOrCreateAttribute(aFolder,"AttributeName");
1512       _PTR(AttributeName) aName(anAttr);
1513       aName->SetValue(CLIP_PLANES_FOLDER);
1514     }
1515     theSObject = aFolder;
1516     return true;
1517   }
1518 }