]> SALOME platform Git repositories - modules/visu.git/blob - src/VISUGUI/VisuGUI_Tools.cxx
Salome HOME
1b80eb979b5b6d417b76943734c6baeaa7d9f6e0
[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("VISU_WARNING"),
262                            QObject::tr("WRN_NO_AVAILABLE_DATA"),
263                            QObject::tr("VISU_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("VISU_WARNING"),
303                              QObject::tr("WRN_NO_AVAILABLE_DATA"),
304                              QObject::tr("VISU_BUT_OK"));
305     return pResult;
306   }
307
308   SVTK_ViewWindow*
309   GetViewWindow(const SalomeApp_Module* theModule)
310   {
311     if(SalomeApp_Application* anApp = theModule->getApp()){
312       if(SUIT_ViewManager* aViewManager = anApp->getViewManager( SVTK_Viewer::Type(), true )){
313         if(SUIT_ViewWindow* aViewWindow = aViewManager->getActiveView()){
314           return dynamic_cast<SVTK_ViewWindow*>(aViewWindow);
315         }
316       }
317     }
318     return NULL;
319   }
320
321   SVTK_ViewWindow*
322   GetViewWindow()
323   {
324     SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>
325       (SUIT_Session::session()->activeApplication());
326     if (anApp) {
327       if (SUIT_ViewManager* aViewManager = anApp->activeViewManager()) {
328         if (aViewManager->getType() == SVTK_Viewer::Type()) {
329           if (SUIT_ViewWindow* aViewWindow = aViewManager->getActiveView()) {
330             return dynamic_cast<SVTK_ViewWindow*>(aViewWindow);
331           }
332         }
333       }
334     }
335     return NULL;
336   }
337
338   TViewWindows
339   GetViews(const SalomeApp_Module* theModule)
340   {
341     TViewWindows aViewWindows;
342     if(SalomeApp_Application* anApp = theModule->getApp()){
343       ViewManagerList aViewManagerList;
344       anApp->viewManagers(SVTK_Viewer::Type(),aViewManagerList);
345       QPtrListIterator<SUIT_ViewManager> anIter(aViewManagerList);
346       while(SUIT_ViewManager* aViewManager = anIter.current()){
347         QPtrVector<SUIT_ViewWindow> aViews = aViewManager->getViews();
348         for(int i = 0, iEnd = aViews.size(); i < iEnd; i++){
349           if(SUIT_ViewWindow* aViewWindow = aViews.at(i))
350             if(SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewWindow))
351               aViewWindows.push_back(aView);
352         }
353         ++anIter;
354       }
355     }
356     return aViewWindows;
357   }
358
359   VISU_Actor* 
360   PublishInView(const SalomeApp_Module* theModule,
361                 VISU::Prs3d_i* thePrs)
362   {
363     VISU_Actor* aActor = NULL;
364     if(!thePrs)
365       return aActor;
366     if(SVTK_ViewWindow* aView = GetViewWindow(theModule)){
367       QApplication::setOverrideCursor( Qt::waitCursor );
368       if(aActor = thePrs->CreateActor()){
369         aView->AddActor(aActor);
370       }
371       QApplication::restoreOverrideCursor();
372     }
373     return aActor;
374   }
375
376   VISU_Actor* 
377   UpdateViewer(const SalomeApp_Module* theModule,
378                VISU::Prs3d_i* thePrs, 
379                bool theDispOnly)
380   {
381     SVTK_ViewWindow* vw = GetViewWindow( theModule );
382     if (!vw) return NULL;
383
384     vtkRenderer *aRen = vw->getRenderer();
385     vtkActorCollection *anActColl = aRen->GetActors();
386
387     vtkActor *anActor;
388     VISU_Actor* anVISUActor = NULL;
389     VISU_Actor* aResActor = NULL;
390     for(anActColl->InitTraversal(); (anActor = anActColl->GetNextActor()) != NULL; ){
391       if(!SALOME_Actor::SafeDownCast(anActor))
392         continue;
393       if(anActor->IsA("VISU_Actor")){ 
394         anVISUActor = VISU_Actor::SafeDownCast(anActor);
395         VISU::Prs3d_i* aPrs = anVISUActor->GetPrs3d();      
396         if(aPrs == NULL) continue;
397         if (thePrs == aPrs) {
398           aResActor = anVISUActor->GetParent();
399           thePrs->UpdateActor(aResActor);
400           aResActor->VisibilityOn();
401           
402         } else if (theDispOnly) {
403           anVISUActor->GetParent()->VisibilityOff();
404         } else {
405         }
406       } else if (theDispOnly && anActor->GetVisibility()) {
407         anActor->VisibilityOff();
408       } else {
409       } 
410     }
411     if (aResActor) 
412       return aResActor;
413
414     anVISUActor = PublishInView( theModule, thePrs );
415     return anVISUActor;
416   }
417
418   VISU_Actor*
419   FindActor(SVTK_ViewWindow* theViewWindow,
420             const char* theEntry)
421   {
422     using namespace VTK;
423     if(vtkRenderer* aRenderer = theViewWindow->getRenderer()){
424       if(vtkActorCollection* aCollection = aRenderer->GetActors()){
425         if(VISU_Actor* anActor = Find<VISU_Actor>(aCollection,TIsSameEntry<VISU_Actor>(theEntry))){
426           return anActor->GetParent();
427         }
428       }
429     }
430     return NULL;
431   }
432
433   VISU_Actor*
434   FindActor(SVTK_ViewWindow* theViewWindow,
435             VISU::Prs3d_i* thePrs)
436   {
437     SALOMEDS::SObject_var aSObject = thePrs->GetSObject();
438     CORBA::String_var anEntry = aSObject->GetID();
439     return FindActor(theViewWindow,anEntry.in());
440   }
441
442   void
443   Add(SalomeApp_SelectionMgr* theSelectionMgr,
444       const Handle(SALOME_InteractiveObject)& theIO)
445   {
446     SALOME_ListIO aListIO;
447     theSelectionMgr->selectedObjects(aListIO);
448     aListIO.Append(theIO);
449     theSelectionMgr->setSelectedObjects(aListIO);
450   }
451
452   void
453   Remove(SalomeApp_SelectionMgr* theSelectionMgr,
454          const Handle(SALOME_InteractiveObject)& theIO)
455   {
456     SALOME_ListIO aListIO;
457     theSelectionMgr->selectedObjects(aListIO);
458     SALOME_ListIteratorOfListIO anIter(aListIO);
459     while(anIter.More()){
460       Handle(SALOME_InteractiveObject) anIO = anIter.Value();
461       if(anIO->isSame(theIO)){
462         aListIO.Remove(anIter);
463       }
464       anIter.Next();
465     }
466     theSelectionMgr->setSelectedObjects(aListIO);
467   }
468
469   void
470   DeletePrs3d(SalomeApp_Module* theModule,
471               VISU::Prs3d_i* thePrs,
472               const Handle(SALOME_InteractiveObject)& theIO)
473   {
474     if(!thePrs)
475       return;
476     if(CheckLock(GetCStudy(GetAppStudy(theModule))))
477       return;
478     SALOMEDS::SObject_var aSObject = thePrs->GetSObject();
479     CORBA::String_var anEntry = aSObject->GetID();
480     SalomeApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(theModule);
481     Remove(aSelectionMgr,theIO);
482     TViewWindows aViewWindows = GetViews(theModule);
483     for(int i = 0, iEnd = aViewWindows.size(); i < iEnd; i++){
484       SVTK_ViewWindow* aView = aViewWindows[i];
485       if(VISU_Actor* anActor = FindActor(aView,anEntry.in())){
486         aView->RemoveActor(anActor);
487         anActor->Delete();
488       }
489     }
490     thePrs->RemoveFromStudy();
491     theModule->updateObjBrowser(); //update Object browser
492   }
493
494   void
495   ErasePrs3d(SalomeApp_Module* theModule,
496              VISU::Prs3d_i* thePrs)
497   {
498     if ( SVTK_ViewWindow* vw = GetViewWindow( theModule ) ){
499       VISU_Actor* anVISUActor = FindActor( vw, thePrs );
500       if (anVISUActor) {
501         anVISUActor->VisibilityOff();
502       }
503     }
504   }
505
506   SPlot2d_Viewer*
507   GetPlot2dViewer(const SalomeApp_Module* theModule)
508   {
509     if(SalomeApp_Application* anApp = theModule->getApp()){
510       if(SUIT_ViewManager* aViewManager = anApp->getViewManager( Plot2d_Viewer::Type(), true )){
511         return dynamic_cast<SPlot2d_Viewer*>(aViewManager->getViewModel());
512       }
513     }
514     return NULL;
515   }
516
517   // Internal function used by several public functions below
518   void
519   UpdateCurve(VISU::Curve_i* theCurve,
520               Plot2d_ViewFrame* aPlot,
521               SPlot2d_Curve* plotCurve,
522               int theDisplaying)
523   {
524     if ( theDisplaying == VISU::eErase ) {
525       if ( plotCurve )
526         aPlot->eraseCurve( plotCurve, false );
527     }
528     else if ( theDisplaying == VISU::eDisplay || theDisplaying == VISU::eDisplayOnly ) {
529       if ( plotCurve ) {
530         plotCurve->setHorTitle( theCurve->GetHorTitle().c_str() );
531         //plotCurve->setVerTitle( ( theCurve->GetVerTitle().c_str() ) );
532         plotCurve->setVerTitle( theCurve->GetName() );
533         plotCurve->setHorUnits( theCurve->GetHorUnits().c_str() );
534         plotCurve->setVerUnits( theCurve->GetVerUnits().c_str() );
535         double* xList = 0;
536         double* yList = 0;
537         int     nbPoints = theCurve->GetData( xList, yList );
538         if ( nbPoints > 0 && xList && yList ) {
539           plotCurve->setData( xList, yList, nbPoints );
540         }
541         if ( !theCurve->IsAuto() ) {
542           plotCurve->setLine( (Plot2d_Curve::LineType)theCurve->GetLine(), theCurve->GetLineWidth() );
543           plotCurve->setMarker( (Plot2d_Curve::MarkerType)theCurve->GetMarker() ); 
544           SALOMEDS::Color color = theCurve->GetColor();
545           plotCurve->setColor( QColor( (int)(color.R*255.), (int)(color.G*255.), (int)(color.B*255.) ) );
546         }
547         plotCurve->setAutoAssign( theCurve->IsAuto() );
548         aPlot->displayCurve( plotCurve, false );
549       }
550       else {
551         Plot2d_Curve* crv = theCurve->CreatePresentation();
552         if ( crv ) {
553           aPlot->displayCurve( crv, false );
554           theCurve->SetLine( (VISU::Curve::LineType)crv->getLine(), crv->getLineWidth() );
555           theCurve->SetMarker( (VISU::Curve::MarkerType)crv->getMarker());
556           SALOMEDS::Color newColor;
557           newColor.R = crv->getColor().red()/255.;
558           newColor.G = crv->getColor().green()/255.;
559           newColor.B = crv->getColor().blue()/255.;
560           theCurve->SetColor( newColor );
561           crv->setAutoAssign( theCurve->IsAuto() );
562         }
563       }
564     }
565   }
566
567   void                                 
568   PlotTable(const SalomeApp_Module* theModule, 
569             VISU::Table_i* table, 
570             int theDisplaying)
571   {
572     SPlot2d_Viewer* aView = GetPlot2dViewer( theModule );
573     if ( !aView )
574       return;
575     Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
576     if ( !aPlot )
577       return;
578
579     if ( theDisplaying == VISU::eDisplayOnly ) 
580       aPlot->EraseAll();
581     QList<Plot2d_Curve> clist;
582     aPlot->getCurves( clist );
583     _PTR(Study) aStudy = GetCStudy( GetAppStudy( theModule ) );
584     _PTR(SObject) TableSO = aStudy->FindObjectID( table->GetEntry() );
585     if ( TableSO ) {
586       _PTR(ChildIterator) Iter = aStudy->NewChildIterator( TableSO );
587       for ( ; Iter->More(); Iter->Next() ) {
588         CORBA::Object_var childObject = VISU::ClientSObjectToObject( Iter->Value() );
589         if( !CORBA::is_nil( childObject ) ) {
590           CORBA::Object_ptr aCurve = VISU::Curve::_narrow( childObject );
591           if( !CORBA::is_nil( aCurve ) ) {
592             VISU::Curve_i* theCurve = dynamic_cast<VISU::Curve_i*>(VISU::GetServant(aCurve).in());
593             SPlot2d_Curve* plotCurve = 0;
594             SPlot2d_Curve* tmpCurve;
595             for ( int i = 0; i < clist.count(); i++ ) {
596               tmpCurve = dynamic_cast<SPlot2d_Curve*>( clist.at( i ) );
597               if ( tmpCurve && tmpCurve->hasIO() && !strcmp( tmpCurve->getIO()->getEntry(), theCurve->GetEntry() ) ) {
598                 plotCurve = tmpCurve;
599                 break;
600               }
601             }
602
603             UpdateCurve( theCurve, aPlot, plotCurve, theDisplaying );
604
605             if ( theDisplaying == VISU::eErase && plotCurve ) {
606               clist.remove( plotCurve );
607             }
608           }
609         }
610       }
611       aPlot->Repaint();
612     }
613   }
614
615   void
616   PlotCurve(const SalomeApp_Module* theModule, 
617             VISU::Curve_i* theCurve, 
618             int theDisplaying)
619   {
620     SPlot2d_Viewer* aView = GetPlot2dViewer( theModule );
621     if ( !aView )
622       return;
623     Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
624     if ( !aPlot )
625       return;
626
627 //  if ( theDisplaying == VISU::eDisplayOnly ) 
628 //    aPlot->EraseAll();
629     QList<Plot2d_Curve> clist;
630     aPlot->getCurves( clist );
631     SPlot2d_Curve* plotCurve = 0;
632     SPlot2d_Curve* tmpCurve;
633     for ( int i = 0; i < clist.count(); i++ ) {
634       tmpCurve = dynamic_cast<SPlot2d_Curve*>( clist.at( i ) );
635       if ( tmpCurve && tmpCurve->hasIO() && !strcmp( tmpCurve->getIO()->getEntry(), theCurve->GetEntry() ) ) {
636         plotCurve = tmpCurve;
637       }
638       else if ( theDisplaying == VISU::eDisplayOnly ) {
639         aPlot->eraseCurve( clist.at( i ) );
640       }
641     }
642
643     UpdateCurve( theCurve, aPlot, plotCurve, theDisplaying );
644
645     aPlot->Repaint();
646   }
647
648   void
649   PlotContainer(const SalomeApp_Module* theModule, 
650                 VISU::Container_i* container, 
651                 int theDisplaying)
652   {
653     SPlot2d_Viewer* aView = GetPlot2dViewer( theModule );
654     if ( !aView )
655       return;
656     Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
657     if ( !aPlot )
658       return;
659
660     if ( theDisplaying == VISU::eDisplayOnly ) 
661       aPlot->EraseAll();
662     QList<Plot2d_Curve> clist;
663     aPlot->getCurves( clist );
664     if ( container->GetNbCurves() > 0 ) {
665       int nbCurves = container->GetNbCurves();
666       for ( int k = 1; k <= nbCurves; k++ ) {
667         VISU::Curve_i* theCurve = container->GetCurve( k );
668         if ( theCurve && theCurve->IsValid() ) {
669           SPlot2d_Curve* plotCurve = dynamic_cast<SPlot2d_Curve*>( aView->getCurveByIO( new SALOME_InteractiveObject( theCurve->GetEntry(), "", "" ) ) );
670           
671           UpdateCurve( theCurve, aPlot, plotCurve, theDisplaying );
672
673           if ( plotCurve && theDisplaying == VISU::eErase ) {
674             clist.remove( plotCurve );
675           }
676         }
677       }
678     }
679     aPlot->Repaint();
680   }
681 }