Salome HOME
Bug 9282: Order of commands
[modules/visu.git] / src / VISUGUI / VisuGUI_Tools.cxx
1 //  VISU VISUGUI : GUI of VISU component
2 //
3 //  Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
21 //
22 //
23 //
24 //  File   : VisuGUI_Tools.cxx
25 //  Author : Sergey Anikin
26 //  Module : VISU
27
28
29 #include "VisuGUI_Tools.h"
30
31 #include "VISU_Gen_i.hh"
32 #include "VISU_Prs3d_i.hh"
33 #include "VISU_Result_i.hh"
34 #include "VISU_Table_i.hh"
35 #include "VISU_ViewManager_i.hh"
36 #include "VISU_Actor.h"
37
38 #include "SalomeApp_Module.h"
39 #include "SalomeApp_Study.h"
40 #include "SalomeApp_Application.h"
41 #include "SalomeApp_SelectionMgr.h"
42
43 #include "SALOME_ListIO.hxx"
44 #include "SALOME_ListIteratorOfListIO.hxx"
45
46 #include "SVTK_ViewWindow.h"
47 #include "SVTK_ViewModel.h"
48 #include "SVTK_Functor.h"
49
50 #include "VTKViewer_Algorithm.h"
51
52 #include "SPlot2d_ViewModel.h"
53 #include "Plot2d_ViewFrame.h"
54
55 #include "SUIT_Session.h"
56 #include "SUIT_MessageBox.h"
57
58 #include <vtkRenderer.h>
59 #include <vtkActorCollection.h>
60
61
62 //=============================================================================
63 namespace VISU
64 {
65   SUIT_Desktop*
66   GetDesktop(const CAM_Module* theModule)
67   {
68     return theModule->application()->desktop();
69   }
70
71   SalomeApp_SelectionMgr*
72   GetSelectionMgr(const SalomeApp_Module* theModule)
73   {
74     return theModule->getApp()->selectionMgr();
75   }
76
77   SalomeApp_Study*
78   GetAppStudy(const CAM_Module* theModule)
79   {
80     return
81       dynamic_cast<SalomeApp_Study*>(theModule->application()->activeStudy());
82   }
83
84   _PTR(Study)
85   GetCStudy(const SalomeApp_Study* theStudy)
86   {
87     return theStudy->studyDS();
88   }
89
90   SALOMEDS::StudyManager_var
91   GetStudyManager()
92   {
93     static SALOMEDS::StudyManager_var aStudyManager;
94     if(CORBA::is_nil(aStudyManager)){
95       SALOME_NamingService *aNamingService = SalomeApp_Application::namingService();
96       CORBA::Object_var anObject = aNamingService->Resolve("/myStudyManager");
97       aStudyManager = SALOMEDS::StudyManager::_narrow(anObject);
98     }
99     return aStudyManager;
100   }
101
102   bool
103   IsStudyLocked( _PTR(Study) theStudy )
104   {
105     if( theStudy )
106       return theStudy->GetProperties()->IsLocked();
107     return true;
108   }
109
110   bool
111   CheckLock( _PTR(Study) theStudy )
112   {
113     if(IsStudyLocked(theStudy))
114       throw std::runtime_error(QObject::tr("WRN_STUDY_LOCKED").latin1());
115     return false;
116   }
117
118   VISU_Gen_i*
119   GetVisuGen(const CAM_Module* theModule)
120   {
121     static VISU_Gen_i* aGen = NULL;
122     if(!aGen){
123       SALOME_LifeCycleCORBA aLCC(SalomeApp_Application::namingService());
124       Engines::Component_var aComponent = aLCC.FindOrLoad_Component("FactoryServer","VISU");
125       VISU_Gen_var aVISU = VISU_Gen::_narrow(aComponent);
126       if(!CORBA::is_nil(aVISU)){
127         aGen = VISU_Gen_i::GetVisuGenImpl();
128         aGen->SetCurrentStudy(GetDSStudy(GetCStudy(GetAppStudy(theModule))));
129       }
130     }
131     if(!aGen)
132       throw std::runtime_error(QObject::tr("ERR_CANT_FIND_VISU_COMPONENT").latin1());
133     return aGen;
134   }
135
136   SALOME_MED::MED_Gen_var
137   GetMEDEngine()
138   {
139     static SALOME_MED::MED_Gen_var aGen;
140     if(CORBA::is_nil(aGen)){
141       SALOME_LifeCycleCORBA aLCC(SalomeApp_Application::namingService());
142       Engines::Component_var aComponent = aLCC.FindOrLoad_Component("FactoryServer","MED");
143       aGen = SALOME_MED::MED_Gen::_narrow(aComponent);
144     }
145     if(CORBA::is_nil(aGen))
146       throw std::runtime_error(QObject::tr("ERR_CANT_FIND_MED_COMPONENT").latin1());
147     return aGen;
148   }
149
150   CORBA::Object_var
151   GetSelectedObj(const SalomeApp_Study* theStudy,
152                  const QString& theEntry,
153                  VISU::Storable::TRestoringMap* theMap)
154   {
155     if ( !theStudy || theEntry.isEmpty() )
156       return CORBA::Object::_nil();
157
158     SALOMEDS::Study_var aStudy = GetDSStudy(GetCStudy( theStudy ));
159     SALOMEDS::SObject_var aSObject = aStudy->FindObjectID( theEntry.latin1() );
160     if(!aSObject->_is_nil()){
161       SALOMEDS::GenericAttribute_var anAttr;
162       if(theMap && aSObject->FindAttribute(anAttr,"AttributeComment")){
163         SALOMEDS::AttributeComment_var aComment = SALOMEDS::AttributeComment::_narrow(anAttr);
164         std::string aValue = aComment->Value();
165         QString aString(aValue.c_str());
166         VISU::Storable::StrToMap(aString,*theMap);
167       }
168       return VISU::SObjectToObject(aSObject);
169     }
170     return CORBA::Object::_nil();
171   }
172
173   CORBA::Object_var
174   GetSelectedObj(const SalomeApp_Module* theModule,
175                  Handle(SALOME_InteractiveObject)* theIO,
176                  VISU::Storable::TRestoringMap* theMap)
177   {
178     SalomeApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(theModule);
179     SALOME_ListIO aListIO;
180     aSelectionMgr->selectedObjects(aListIO);
181     SALOME_ListIteratorOfListIO anIter(aListIO);
182     if(anIter.More()){
183       Handle(SALOME_InteractiveObject) anIO = anIter.Value();
184       if(theIO)
185         *theIO = anIO;
186       if(anIO->hasEntry())
187         return GetSelectedObj( GetAppStudy(theModule), anIO->getEntry(), theMap );
188     }
189     return CORBA::Object::_nil();
190   }
191
192   VISU::Storable::TRestoringMap
193   getMapOfValue(SALOMEDS::SObject_var theSObject)
194   {
195     VISU::Storable::TRestoringMap aMap;
196     if(!theSObject->_is_nil()){
197       SALOMEDS::GenericAttribute_var anAttr;
198       if (theSObject->FindAttribute(anAttr, "AttributeComment")) {
199         SALOMEDS::AttributeComment_var aComment = SALOMEDS::AttributeComment::_narrow(anAttr);
200         CORBA::String_var aValue = aComment->Value();
201         QString aString(aValue.in());
202         VISU::Storable::StrToMap(aString,aMap);
203       }
204     }
205     return aMap;
206   }
207
208   QString
209   getValue(SALOMEDS::SObject_var theSObject,
210            QString theKey)
211   {
212     QString aStr("");
213     VISU::Storable::TRestoringMap aMap = getMapOfValue(theSObject);
214     if(!aMap.empty())
215       aStr = VISU::Storable::FindValue(aMap,theKey.latin1());
216     return aStr;
217   }
218
219   VISU::Storable::TRestoringMap getMapOfValue (_PTR(SObject) theSObject)
220   {
221     VISU::Storable::TRestoringMap aMap;
222     if (theSObject) {
223       _PTR(GenericAttribute) anAttr;
224       if (theSObject->FindAttribute(anAttr, "AttributeComment")) {
225         _PTR(AttributeComment) aComment (anAttr);
226         std::string aValue = aComment->Value();
227         QString aString (aValue.c_str());
228         VISU::Storable::StrToMap(aString, aMap);
229       }
230     }
231     return aMap;
232   }
233
234   QString getValue (_PTR(SObject) theSObject, QString theKey)
235   {
236     QString aStr("");
237     VISU::Storable::TRestoringMap aMap = getMapOfValue(theSObject);
238     if (!aMap.empty())
239       aStr = VISU::Storable::FindValue(aMap, theKey.latin1());
240     return aStr;
241   }
242
243
244   bool
245   CheckTimeStamp(const SalomeApp_Module* theModule,
246                  SALOMEDS::SObject_var& theSObject,
247                  Handle(SALOME_InteractiveObject)* theIO)
248   {
249     Handle(SALOME_InteractiveObject) anIO;
250     CORBA::Object_var anObject = GetSelectedObj(theModule,&anIO);
251     if(theIO)
252       *theIO = anIO;
253     if(!anIO.IsNull() && anIO->hasEntry()){
254       SALOMEDS::Study_var aStudy = GetDSStudy(GetCStudy(GetAppStudy(theModule)));
255       theSObject = aStudy->FindObjectID(anIO->getEntry());
256       QString aValue = getValue(theSObject,"myType");
257       if(aValue.toInt() == int(VISU::TTIMESTAMP))
258         return true;
259     }
260     SUIT_MessageBox::warn1(GetDesktop(theModule),
261                            QObject::tr("WRN_VISU"),
262                            QObject::tr("WRN_NO_AVAILABLE_DATA"),
263                            QObject::tr("BUT_OK") );
264     return false;
265   }
266
267
268   VISU::Result_i*
269   CheckResult(const SalomeApp_Module* theModule,
270               SALOMEDS::SObject_var theSource,
271               VISU::Result_var& theResult)
272   {
273     SALOMEDS::SObject_var aSObj;
274
275     aSObj = theSource->GetFather();
276     if (CORBA::is_nil(aSObj))
277       return NULL;
278
279     aSObj = aSObj->GetFather();
280     if (CORBA::is_nil(aSObj))
281       return NULL;
282
283     aSObj = aSObj->GetFather();
284     if (CORBA::is_nil(aSObj))
285       return NULL;
286
287     CORBA::Object_var anObject = VISU::SObjectToObject(aSObj);
288     if (CORBA::is_nil(anObject)) {
289       aSObj = aSObj->GetFather();
290       if (CORBA::is_nil(aSObj))
291         return NULL;
292       anObject = VISU::SObjectToObject(aSObj);
293     }
294
295     if (CORBA::is_nil(anObject))
296       return NULL;
297
298     theResult = VISU::Result::_narrow(anObject);
299     VISU::Result_i* pResult = dynamic_cast<VISU::Result_i*>(VISU::GetServant(anObject).in());
300     if(pResult == NULL)
301       SUIT_MessageBox::warn1(GetDesktop(theModule),
302                              QObject::tr("WRN_VISU"),
303                              QObject::tr("WRN_NO_AVAILABLE_DATA"),
304                              QObject::tr("BUT_OK"));
305     return pResult;
306   }
307
308   SVTK_ViewWindow*
309   GetViewWindow(const SalomeApp_Module* theModule, const bool theCreate )
310   {
311     if(SalomeApp_Application* anApp = theModule->getApp()){
312       if(SUIT_ViewManager* aViewManager = anApp->getViewManager( SVTK_Viewer::Type(), theCreate )){
313         if(SUIT_ViewWindow* aViewWindow = aViewManager->getActiveView()){
314           return dynamic_cast<SVTK_ViewWindow*>(aViewWindow);
315         }
316       }
317     }
318     return NULL;
319   }
320
321
322   //************************************************************
323   SUIT_ViewWindow* GetActiveView(const SalomeApp_Module* theModule, QString theType)
324   {
325     if(SalomeApp_Application* anApp = theModule->getApp()){
326       if(SUIT_ViewManager* aViewManager = anApp->activeViewManager()){
327         if (!theType.isNull()) {
328           if (aViewManager->getType() != theType)
329             return 0;
330         }
331         return aViewManager->getActiveView();
332       }
333     }
334     return 0;
335   }
336
337
338   //************************************************************
339   SVTK_ViewWindow*
340   GetViewWindow()
341   {
342     SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>
343       (SUIT_Session::session()->activeApplication());
344     if (anApp) {
345       if (SUIT_ViewManager* aViewManager = anApp->activeViewManager()) {
346         if (aViewManager->getType() == SVTK_Viewer::Type()) {
347           if (SUIT_ViewWindow* aViewWindow = aViewManager->getActiveView()) {
348             return dynamic_cast<SVTK_ViewWindow*>(aViewWindow);
349           }
350         }
351       }
352     }
353     return NULL;
354   }
355
356   TViewWindows
357   GetViews(const SalomeApp_Module* theModule)
358   {
359     TViewWindows aViewWindows;
360     if(SalomeApp_Application* anApp = theModule->getApp()){
361       ViewManagerList aViewManagerList;
362       anApp->viewManagers(SVTK_Viewer::Type(),aViewManagerList);
363       QPtrListIterator<SUIT_ViewManager> anIter(aViewManagerList);
364       while(SUIT_ViewManager* aViewManager = anIter.current()){
365         QPtrVector<SUIT_ViewWindow> aViews = aViewManager->getViews();
366         for(int i = 0, iEnd = aViews.size(); i < iEnd; i++){
367           if(SUIT_ViewWindow* aViewWindow = aViews.at(i))
368             if(SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewWindow))
369               aViewWindows.push_back(aView);
370         }
371         ++anIter;
372       }
373     }
374     return aViewWindows;
375   }
376
377   VISU_Actor* 
378   PublishInView(const SalomeApp_Module* theModule,
379                 VISU::Prs3d_i* thePrs)
380   {
381     VISU_Actor* aActor = NULL;
382     if(!thePrs)
383       return aActor;
384     if(SVTK_ViewWindow* aView = GetViewWindow(theModule)){
385       QApplication::setOverrideCursor( Qt::waitCursor );
386       if(aActor = thePrs->CreateActor()){
387         aView->AddActor(aActor);
388       }
389       QApplication::restoreOverrideCursor();
390     }
391     return aActor;
392   }
393
394   VISU_Actor* 
395   UpdateViewer(const SalomeApp_Module* theModule,
396                VISU::Prs3d_i* thePrs, 
397                bool theDispOnly)
398   {
399     SVTK_ViewWindow* vw = GetViewWindow( theModule );
400     if (!vw) return NULL;
401
402     vtkRenderer *aRen = vw->getRenderer();
403     vtkActorCollection *anActColl = aRen->GetActors();
404
405     vtkActor *anActor;
406     VISU_Actor* anVISUActor = NULL;
407     VISU_Actor* aResActor = NULL;
408     for(anActColl->InitTraversal(); (anActor = anActColl->GetNextActor()) != NULL; ){
409       if(!SALOME_Actor::SafeDownCast(anActor))
410         continue;
411       if(anActor->IsA("VISU_Actor")){ 
412         anVISUActor = VISU_Actor::SafeDownCast(anActor);
413         VISU::Prs3d_i* aPrs = anVISUActor->GetPrs3d();      
414         if(aPrs == NULL) continue;
415         if (thePrs == aPrs) {
416           aResActor = anVISUActor->GetParent();
417           thePrs->UpdateActor(aResActor);
418           aResActor->VisibilityOn();
419           
420         } else if (theDispOnly) {
421           anVISUActor->GetParent()->VisibilityOff();
422         } else {
423         }
424       } else if (theDispOnly && anActor->GetVisibility()) {
425         anActor->VisibilityOff();
426       } else {
427       } 
428     }
429     if (aResActor) 
430       return aResActor;
431
432     anVISUActor = PublishInView( theModule, thePrs );
433     return anVISUActor;
434   }
435
436   VISU_Actor*
437   FindActor(SVTK_ViewWindow* theViewWindow,
438             const char* theEntry)
439   {
440     using namespace VTK;
441     if(vtkRenderer* aRenderer = theViewWindow->getRenderer()){
442       if(vtkActorCollection* aCollection = aRenderer->GetActors()){
443         if(VISU_Actor* anActor = Find<VISU_Actor>(aCollection,TIsSameEntry<VISU_Actor>(theEntry))){
444           return anActor->GetParent();
445         }
446       }
447     }
448     return NULL;
449   }
450
451   VISU_Actor*
452   FindActor(SVTK_ViewWindow* theViewWindow,
453             VISU::Prs3d_i* thePrs)
454   {
455     SALOMEDS::SObject_var aSObject = thePrs->GetSObject();
456     CORBA::String_var anEntry = aSObject->GetID();
457     return FindActor(theViewWindow,anEntry.in());
458   }
459
460   void
461   RecreateActor (const SalomeApp_Module* theModule,
462                  VISU::Prs3d_i* thePrs)
463   {
464     QApplication::setOverrideCursor(Qt::waitCursor);
465
466     SALOMEDS::SObject_var aSObject = thePrs->GetSObject();
467     CORBA::String_var anEntry = aSObject->GetID();
468
469     try {
470       thePrs->Update();
471
472       TViewWindows aViewWindows = GetViews(theModule);
473       for (int i = 0, iEnd = aViewWindows.size(); i < iEnd; i++) {
474         SVTK_ViewWindow* aView = aViewWindows[i];
475         if (VISU_Actor* anActor = FindActor(aView, anEntry.in())) {
476           thePrs->UpdateActor(anActor);
477         }
478       }
479     } catch (std::runtime_error& ex) {
480       INFOS(ex.what());
481       QApplication::restoreOverrideCursor();
482       SUIT_MessageBox::warn1 (GetDesktop(theModule), QObject::tr("WRN_VISU"), 
483                               QObject::tr("ERR_CANT_BUILD_PRESENTATION") + " " + QObject::tr(ex.what()), 
484                               QObject::tr("BUT_OK"));
485
486       TViewWindows aViewWindows = GetViews(theModule);
487       for (int i = 0, iEnd = aViewWindows.size(); i < iEnd; i++) {
488         SVTK_ViewWindow* aView = aViewWindows[i];
489         if (VISU_Actor* anActor = FindActor(aView, anEntry.in())) {
490           aView->RemoveActor(anActor);
491           anActor->Delete();
492         }
493       }
494       return;
495     }
496     QApplication::restoreOverrideCursor();
497   }
498
499   void
500   Add(SalomeApp_SelectionMgr* theSelectionMgr,
501       const Handle(SALOME_InteractiveObject)& theIO)
502   {
503     SALOME_ListIO aListIO;
504     theSelectionMgr->selectedObjects(aListIO);
505     aListIO.Append(theIO);
506     theSelectionMgr->setSelectedObjects(aListIO);
507   }
508
509   void
510   Remove(SalomeApp_SelectionMgr* theSelectionMgr,
511          const Handle(SALOME_InteractiveObject)& theIO)
512   {
513     if (theIO.IsNull()) return;
514     SALOME_ListIO aListIO, aNewListIO;
515     theSelectionMgr->selectedObjects(aListIO);
516     SALOME_ListIteratorOfListIO anIter (aListIO);
517     for (; anIter.More(); anIter.Next()) {
518       Handle(SALOME_InteractiveObject) anIO = anIter.Value();
519       if (!anIO->isSame(theIO)) {
520         aNewListIO.Append(theIO);
521       }
522     }
523     theSelectionMgr->setSelectedObjects(aNewListIO);
524   }
525
526   void
527   DeletePrs3d(SalomeApp_Module* theModule,
528               VISU::Prs3d_i* thePrs,
529               const Handle(SALOME_InteractiveObject)& theIO)
530   {
531     if(!thePrs)
532       return;
533     if(CheckLock(GetCStudy(GetAppStudy(theModule))))
534       return;
535     SALOMEDS::SObject_var aSObject = thePrs->GetSObject();
536     CORBA::String_var anEntry = aSObject->GetID();
537     SalomeApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(theModule);
538     Remove(aSelectionMgr,theIO);
539     TViewWindows aViewWindows = GetViews(theModule);
540     for(int i = 0, iEnd = aViewWindows.size(); i < iEnd; i++){
541       SVTK_ViewWindow* aView = aViewWindows[i];
542       if(VISU_Actor* anActor = FindActor(aView,anEntry.in())){
543         aView->RemoveActor(anActor);
544         anActor->Delete();
545       }
546     }
547     thePrs->RemoveFromStudy();
548     theModule->updateObjBrowser(); //update Object browser
549   }
550
551   void
552   ErasePrs3d(SalomeApp_Module* theModule,
553              VISU::Prs3d_i* thePrs)
554   {
555     if ( SVTK_ViewWindow* vw = GetViewWindow( theModule ) ){
556       VISU_Actor* anVISUActor = FindActor( vw, thePrs );
557       if (anVISUActor) {
558         anVISUActor->VisibilityOff();
559       }
560     }
561   }
562
563   SPlot2d_Viewer*
564   GetPlot2dViewer(const SalomeApp_Module* theModule, const bool theCreate)
565   {
566     if(SalomeApp_Application* anApp = theModule->getApp()){
567       if(SUIT_ViewManager* aViewManager = anApp->getViewManager( Plot2d_Viewer::Type(), theCreate )){
568         return dynamic_cast<SPlot2d_Viewer*>(aViewManager->getViewModel());
569       }
570     }
571     return NULL;
572   }
573
574   // Internal function used by several public functions below
575   void
576   UpdateCurve(VISU::Curve_i* theCurve,
577               Plot2d_ViewFrame* aPlot,
578               SPlot2d_Curve* plotCurve,
579               int theDisplaying)
580   {
581     if ( theDisplaying == VISU::eErase ) {
582       if ( plotCurve )
583         aPlot->eraseCurve( plotCurve, false );
584     }
585     else if ( theDisplaying == VISU::eDisplay || theDisplaying == VISU::eDisplayOnly ) {
586       if ( plotCurve ) {
587         plotCurve->setHorTitle( theCurve->GetHorTitle().c_str() );
588         //plotCurve->setVerTitle( ( theCurve->GetVerTitle().c_str() ) );
589         plotCurve->setVerTitle( theCurve->GetName() );
590         plotCurve->setHorUnits( theCurve->GetHorUnits().c_str() );
591         plotCurve->setVerUnits( theCurve->GetVerUnits().c_str() );
592         double* xList = 0;
593         double* yList = 0;
594         int     nbPoints = theCurve->GetData( xList, yList );
595         if ( nbPoints > 0 && xList && yList ) {
596           plotCurve->setData( xList, yList, nbPoints );
597         }
598         if ( !theCurve->IsAuto() ) {
599           plotCurve->setLine( (Plot2d_Curve::LineType)theCurve->GetLine(), theCurve->GetLineWidth() );
600           plotCurve->setMarker( (Plot2d_Curve::MarkerType)theCurve->GetMarker() ); 
601           SALOMEDS::Color color = theCurve->GetColor();
602           plotCurve->setColor( QColor( (int)(color.R*255.), (int)(color.G*255.), (int)(color.B*255.) ) );
603         }
604         plotCurve->setAutoAssign( theCurve->IsAuto() );
605         aPlot->displayCurve( plotCurve, false );
606       }
607       else {
608         Plot2d_Curve* crv = theCurve->CreatePresentation();
609         if ( crv ) {
610           aPlot->displayCurve( crv, false );
611           theCurve->SetLine( (VISU::Curve::LineType)crv->getLine(), crv->getLineWidth() );
612           theCurve->SetMarker( (VISU::Curve::MarkerType)crv->getMarker());
613           SALOMEDS::Color newColor;
614           newColor.R = crv->getColor().red()/255.;
615           newColor.G = crv->getColor().green()/255.;
616           newColor.B = crv->getColor().blue()/255.;
617           theCurve->SetColor( newColor );
618           crv->setAutoAssign( theCurve->IsAuto() );
619         }
620       }
621     }
622   }
623
624   void                                 
625   PlotTable(const SalomeApp_Module* theModule, 
626             VISU::Table_i* table, 
627             int theDisplaying)
628   {
629     SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true ); // create if necessary
630     if ( !aView )
631       return;
632     Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
633     if ( !aPlot )
634       return;
635
636     if ( theDisplaying == VISU::eDisplayOnly ) 
637       aPlot->EraseAll();
638     QList<Plot2d_Curve> clist;
639     aPlot->getCurves( clist );
640     _PTR(Study) aStudy = GetCStudy( GetAppStudy( theModule ) );
641     _PTR(SObject) TableSO = aStudy->FindObjectID( table->GetEntry().latin1() );
642     if ( TableSO ) {
643       _PTR(ChildIterator) Iter = aStudy->NewChildIterator( TableSO );
644       for ( ; Iter->More(); Iter->Next() ) {
645         CORBA::Object_var childObject = VISU::ClientSObjectToObject( Iter->Value() );
646         if( !CORBA::is_nil( childObject ) ) {
647           CORBA::Object_ptr aCurve = VISU::Curve::_narrow( childObject );
648           if( !CORBA::is_nil( aCurve ) ) {
649             VISU::Curve_i* theCurve = dynamic_cast<VISU::Curve_i*>(VISU::GetServant(aCurve).in());
650             SPlot2d_Curve* plotCurve = 0;
651             SPlot2d_Curve* tmpCurve;
652             for ( int i = 0; i < clist.count(); i++ ) {
653               tmpCurve = dynamic_cast<SPlot2d_Curve*>( clist.at( i ) );
654               if ( tmpCurve && tmpCurve->hasIO() && !strcmp( tmpCurve->getIO()->getEntry(), theCurve->GetEntry() ) ) {
655                 plotCurve = tmpCurve;
656                 break;
657               }
658             }
659
660             UpdateCurve( theCurve, aPlot, plotCurve, theDisplaying );
661
662             if ( theDisplaying == VISU::eErase && plotCurve ) {
663               clist.remove( plotCurve );
664             }
665           }
666         }
667       }
668       aPlot->Repaint();
669     }
670   }
671
672   void
673   PlotCurve(const SalomeApp_Module* theModule, 
674             VISU::Curve_i* theCurve, 
675             int theDisplaying)
676   {
677     SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true );
678     if ( !aView )
679       return;
680     Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
681     if ( !aPlot )
682       return;
683
684 //  if ( theDisplaying == VISU::eDisplayOnly ) 
685 //    aPlot->EraseAll();
686     QList<Plot2d_Curve> clist;
687     aPlot->getCurves( clist );
688     SPlot2d_Curve* plotCurve = 0;
689     SPlot2d_Curve* tmpCurve;
690     for ( int i = 0; i < clist.count(); i++ ) {
691       tmpCurve = dynamic_cast<SPlot2d_Curve*>( clist.at( i ) );
692       if ( tmpCurve && tmpCurve->hasIO() && !strcmp( tmpCurve->getIO()->getEntry(), theCurve->GetEntry() ) ) {
693         plotCurve = tmpCurve;
694       }
695       else if ( theDisplaying == VISU::eDisplayOnly ) {
696         aPlot->eraseCurve( clist.at( i ) );
697       }
698     }
699
700     UpdateCurve( theCurve, aPlot, plotCurve, theDisplaying );
701
702     aPlot->Repaint();
703   }
704
705   void
706   PlotContainer(const SalomeApp_Module* theModule, 
707                 VISU::Container_i* container, 
708                 int theDisplaying)
709   {
710     SPlot2d_Viewer* aView = GetPlot2dViewer( theModule, true );
711     if ( !aView )
712       return;
713     Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
714     if ( !aPlot )
715       return;
716
717     if ( theDisplaying == VISU::eDisplayOnly ) 
718       aPlot->EraseAll();
719     QList<Plot2d_Curve> clist;
720     aPlot->getCurves( clist );
721     if ( container->GetNbCurves() > 0 ) {
722       int nbCurves = container->GetNbCurves();
723       for ( int k = 1; k <= nbCurves; k++ ) {
724         VISU::Curve_i* theCurve = container->GetCurve( k );
725         if ( theCurve && theCurve->IsValid() ) {
726           SPlot2d_Curve* plotCurve = dynamic_cast<SPlot2d_Curve*>( aView->getCurveByIO( new SALOME_InteractiveObject( theCurve->GetEntry(), "", "" ) ) );
727           
728           UpdateCurve( theCurve, aPlot, plotCurve, theDisplaying );
729
730           if ( plotCurve && theDisplaying == VISU::eErase ) {
731             clist.remove( plotCurve );
732           }
733         }
734       }
735     }
736     aPlot->Repaint();
737   }
738
739   void
740   CreatePlot(SalomeApp_Module* theModule,
741              _PTR(SObject) theTableSO)
742   {
743     if ( IsSObjectTable(theTableSO) ) {
744       CORBA::Object_var aTable = VISU::ClientSObjectToObject(theTableSO);
745       CORBA::Object_var aContainer = GetVisuGen( theModule )->CreateContainer();
746       if ( !CORBA::is_nil( aTable ) && !CORBA::is_nil( aContainer ) ) {
747         VISU::Table_i*     pTable     = dynamic_cast<VISU::Table_i*>( VISU::GetServant(aTable).in() );
748         VISU::Container_i* pContainer = dynamic_cast<VISU::Container_i*>( VISU::GetServant(aContainer).in() );
749       
750         if ( pContainer && pTable ) {
751           for ( int i = 2; i <= pTable->GetNbRows(); i++ ) {
752             CORBA::Object_var aNewCurve = GetVisuGen( theModule )->CreateCurve( pTable->_this(), 1, i );
753             if( !CORBA::is_nil( aNewCurve ) ) {
754               VISU::Curve_i* pCrv = dynamic_cast<VISU::Curve_i*>( VISU::GetServant(aNewCurve).in() );
755               if ( pCrv ) {
756                 pContainer->AddCurve( pCrv->_this() );
757               }
758             }
759           }
760           theModule->updateObjBrowser();
761           PlotContainer( theModule, pContainer, VISU::eDisplay );
762         }
763       }
764     }
765   }
766 }