]> SALOME platform Git repositories - modules/visu.git/blob - src/VISUGUI/VisuGUI.cxx
Salome HOME
NRI : Update loadPixmap.
[modules/visu.git] / src / VISUGUI / VisuGUI.cxx
1 using namespace std;
2 //  File      : VisuGUI.cxx
3 //  Created   : Wed Aug 01 10:20:18 2001
4 //  Author    : Laurent CORNABE
5 //  Project   : SALOME
6 //  Module    : VISUGUI
7 //  Copyright : PRINCIPIA
8 //  $Header$
9
10 #include "VisuGUI.h"
11 #include "VisuGUI_PhaseDlg.h"
12 #include "VisuGUI_MagnitudeDlg.h"
13 #include "VisuGUI_PhaseMagnitudeDlg.h"
14 #include "VisuGUI_PartialScaDlg.h"
15 #include "VisuGUI_CursorDlg.h"
16 #include "VisuGUI_ScalarBarDlg.h"
17 #include "VisuGUI_SweepPrefDlg.h"
18 #include "VisuGUI_CutPlanesDlg.h"
19 #include "VisuGUI_VectorsDlg.h"
20 #include "VisuGUI_IsoSurfacesDlg.h"
21 #include "VisuGUI_StreamLinesDlg.h"
22 #include "VisuGUI_TimeAnimation.h"
23
24 #include "VisuGUI_Selection.h"
25 #include "VisuGUI_VisuAsDlg.h"
26 #include "VisuGUI_SelVectCompDlg.h"
27 #include "VisuGUI_NonIsometricDlg.h"
28
29 #include "VISU_Gen_i.hh"
30 #include "VISU_Result_i.hh"
31 #include "VISU_Extractor.hxx"
32 #include "VISU_Table_i.hh"
33 #include "VISU_ViewManager_i.hh"
34 #include "VISU_LookupTable.hxx"
35 #include "VISU_ScalarBarActor.hxx"
36
37 #include "SALOMEGUI_ImportOperation.h"
38 #include "SALOMEGUI_QtCatchCorbaException.hxx"
39 #include "utilities.h"
40
41 #include "QAD_Config.h"
42
43 #include "QAD_Settings.h"
44 #include "QAD_Tools.h"
45 #include "QAD_LeftFrame.h"
46 #include "QAD_RightFrame.h"
47 #include "QAD_MessageBox.h"
48 #include "QAD_ObjectBrowser.h"
49 #include "QAD_ObjectBrowserItem.h"
50 #include "QAD_Menus.h"
51 #include "QAD_Resource.h"
52 #include "QAD_ResourceMgr.h"
53 #include "QAD_FileDlg.h"
54 #include "SALOME_Selection.h"
55 #include "SALOMEGUI_NameDlg.h"
56 #include "SALOMEGUI_TableDlg.h"
57 #include "SALOMEGUI_SetupCurveDlg.h"
58 #include "SALOMEGUI_SetValueDlg.h"
59 #include "Plot2d_SetupPlot2dDlg.h"
60 #include "Plot2d_ViewFrame.h"
61 #include "VTKViewer_ViewFrame.h"
62
63 // QT Includes
64 #define  INCLUDE_MENUITEM_DEF
65 #include <qpopupmenu.h>
66 #include <qfont.h>
67 #include <qpainter.h>
68 #include <qstring.h>
69 #include <qapplication.h>
70 #include <qinputdialog.h>  
71 #include <qcolordialog.h>
72 #include <qlabel.h>
73 #include <qspinbox.h>
74 #include <qradiobutton.h>
75 #include <qthread.h>
76 #include <qlistbox.h>
77 #include <qcombobox.h>
78
79 //VRV: porting on Qt 3.0.5
80 #if QT_VERSION >= 0x030005
81 #include <qlistview.h>
82 #endif
83 //VRV: porting on Qt 3.0.5
84 #include <qmessagebox.h>
85
86 #include <med.h>
87 #include CORBA_CLIENT_HEADER(Med_Gen)
88
89 #include <vtkActor.h>
90 #include <vtkCellCenters.h>
91 //#include <vtkOutlineFilter.h>
92 #include <vtkDataSetMapper.h>
93 #include <vtkWarpVector.h>
94 #include <vtkContourFilter.h>
95 #include <vtkCellDataToPointData.h>
96 #include <vtkShrinkFilter.h>
97
98 // Open CASCADE Include
99 #include <TCollection_AsciiString.hxx>
100
101 //#define CHECKTIME
102 #ifdef CHECKTIME
103 #include <OSD_Timer.hxx>
104 #endif
105
106 #ifdef DEBUG
107 static int MYDEBUG = 1;
108 static int MYDEBUGWITHFILES = 0;
109 #else
110 static int MYDEBUG = 0;
111 static int MYDEBUGWITHFILES = 0;
112 #endif
113
114 // unique name visu entity
115 //static bool                   localContext = false;
116 static VisuGUI_Selection        *Selection;
117 static int VISU_POINT_SIZE = 5;
118
119 QAD_Study* VisuGUI::myActiveStudy = NULL;
120 VISU::VISU_Gen_var VisuGUI::myComponent = VISU::VISU_Gen::_nil();
121 SALOMEDS::Study_var VisuGUI::myStudy = SALOMEDS::Study::_nil();
122 SALOMEDS::StudyBuilder_var VisuGUI::myStudyBuilder = SALOMEDS::StudyBuilder::_nil();
123 QAD_Desktop* VisuGUI::myDesktop = NULL;
124
125 QAD_Study* MYActiveStudy = NULL;
126 SALOMEDS::StudyBuilder_var MYStudyBuilder = SALOMEDS::StudyBuilder::_nil();
127 SALOMEDS::Study_var MYStudyDocument = SALOMEDS::Study::_nil();
128
129 const QString ObjectTypes("FIELD VIEW3D MESH TIMESTAMP ENTITY FAMILY GROUP");
130
131
132 class CustomItem : public QCustomMenuItem
133 {
134 public:
135   CustomItem( const QString& s, const QFont& f )
136     : string( s ), font( f ){};
137   ~CustomItem(){}
138   
139   void paint( QPainter* p, const QColorGroup& /*cg*/, bool /*act*/, bool /*enabled*/, int x, int y, int w, int h )
140   {
141     p->setFont ( font );
142     p->drawText( x, y, w, h, AlignHCenter | AlignVCenter | ShowPrefix | DontClip, string );
143   }
144   
145   QSize sizeHint()
146   {
147     return QFontMetrics( font ).size( AlignHCenter | AlignVCenter | ShowPrefix | DontClip,  string );
148   }
149 private:
150   QString string;
151   QFont font;
152 };
153
154 static VisuGUI *visuGUI = 0;
155 static QString PREFIX = QString(getenv("USER")) + "-VISU-";
156
157
158
159 vtkRenderer* VisuGUI::GetRenderer(QAD_Study* theStudy){
160   if (theStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
161     return NULL;
162
163   return ((VTKViewer_ViewFrame*)theStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
164 }
165
166
167 /**
168  * Finds value by given key
169  */
170
171 VISU::Storable::TRestoringMap VisuGUI::getMapOfValue(SALOMEDS::SObject_var theSObject) {
172   VISU::Storable::TRestoringMap aMap;
173   if(!theSObject->_is_nil()){
174     SALOMEDS::GenericAttribute_var anAttr;
175     if (theSObject->FindAttribute(anAttr, "AttributeComment")) {
176       SALOMEDS::AttributeComment_var aComment = SALOMEDS::AttributeComment::_narrow(anAttr);
177       CORBA::String_var aString = aComment->Value();
178       QString strIn(aString.in());
179       VISU::Storable::StrToMap(strIn,aMap);
180     }
181   }
182   return aMap;
183 }
184
185 QString VisuGUI::getValue(SALOMEDS::SObject_var theSObject, QString theKey) {
186   QString aStr("");
187   VISU::Storable::TRestoringMap aMap = getMapOfValue(theSObject);
188   if(!aMap.empty())
189     aStr = VISU::Storable::FindValue(aMap, theKey.latin1());
190   return aStr;
191 }
192
193
194 CORBA::Object_var GetSelectedObj(string& theComment, Handle(SALOME_InteractiveObject)& theIO, QAD_Study* theStudy){
195   SALOME_Selection* Sel = SALOME_Selection::Selection(theStudy->getSelection());
196   if( Sel->IObjectCount() > 0 ) {
197     theIO = Sel->firstIObject();
198     if (theIO->hasEntry()){
199       SALOMEDS::SObject_var aSObject = MYStudyDocument->FindObjectID(theIO->getEntry());
200       if(!aSObject->_is_nil()){
201         SALOMEDS::GenericAttribute_var       anAttr;
202         if (aSObject->FindAttribute(anAttr, "AttributeComment")) {
203           SALOMEDS::AttributeComment_var aComment = SALOMEDS::AttributeComment::_narrow(anAttr);
204           theComment = aComment->Value();
205           QString strIn(theComment.c_str());
206           VISU::Storable::TRestoringMap aMap;
207           VISU::Storable::StrToMap(strIn,aMap);
208           bool isExist;
209           theComment = VISU::Storable::FindValue(aMap,"myComment",&isExist).latin1();
210           if(!isExist) theComment = "NONE";
211         } else {
212           theComment = "NONE";
213         }
214         aSObject->FindAttribute(anAttr, "AttributeIOR");
215         if(!anAttr->_is_nil()){
216           SALOMEDS::AttributeIOR_var anIOR  = SALOMEDS::AttributeIOR::_narrow(anAttr);
217           if(!anIOR->_is_nil()){
218             CORBA::String_var aValue = anIOR->Value();
219             if(strcmp(aValue,"") != 0){
220               CORBA::ORB_var anORB = VISU::GetORB();
221               CORBA::Object_var anObject = anORB->string_to_object(aValue);
222               return anObject;
223             }
224           }
225         }
226       }
227     }
228   }
229   return CORBA::Object::_nil();
230 }
231
232 CORBA::Object_var GetSelectedObj(QAD_Study* theStudy, Handle(SALOME_InteractiveObject)* pIO = NULL,
233                                  VISU::Storable::TRestoringMap* pMap = NULL)
234 {
235   SALOME_Selection* Sel = SALOME_Selection::Selection(theStudy->getSelection());
236   if( Sel->IObjectCount() > 0 ) {
237     Handle(SALOME_InteractiveObject)& anIO = (*pIO) = Sel->firstIObject();
238     if (anIO->hasEntry()){
239       SALOMEDS::Study_var aStudy = theStudy->getStudyDocument();
240       SALOMEDS::SObject_var aSObject = aStudy->FindObjectID(anIO->getEntry());
241       if(!aSObject->_is_nil()){
242         SALOMEDS::GenericAttribute_var anAttr;
243         if (pMap != NULL && aSObject->FindAttribute(anAttr, "AttributeComment")) {
244           SALOMEDS::AttributeComment_var aComment = SALOMEDS::AttributeComment::_narrow(anAttr);
245           string aComm = aComment->Value();
246           QString strIn(aComm.c_str());
247           VISU::Storable::StrToMap(strIn,*pMap);
248         }
249         return VISU::SObjectToObject(aSObject);
250       }
251     }
252   }
253   return CORBA::Object::_nil();
254 }
255
256 int IsTrihedronDisplayed(){
257   QAD_ViewFrame* aViewFrame = MYActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame();
258   VTKViewer_ViewFrame* aVTKViewFrame = dynamic_cast<VTKViewer_ViewFrame*>(aViewFrame);
259   return aVTKViewFrame->isTrihedronDisplayed();
260 }
261
262
263 VTKViewer_ViewFrame* VisuGUI::GetVtkViewFrame(){
264   QAD_ViewFrame* aViewFrame = myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame();
265   return dynamic_cast<VTKViewer_ViewFrame*>(aViewFrame);
266 }
267
268
269 void RepaintCurrentView(){
270   VTKViewer_ViewFrame* vf = VisuGUI::GetVtkViewFrame();
271   if (vf)
272     vf->Repaint();
273
274
275
276 VISU_Actor* GetActorByIO(const Handle(SALOME_InteractiveObject)& theIO, vtkRenderer* theRen) {
277   vtkActorCollection* aActors = theRen->GetActors();
278   vtkActor* anActor;
279   VISU_Actor* aVisuActor;
280   for (aActors->InitTraversal(); (anActor = aActors->GetNextActor())!=NULL;) {
281     if (anActor->IsA("VISU_Actor")) {
282       aVisuActor = VISU_Actor::SafeDownCast(anActor);
283       if (aVisuActor->hasIO()) {
284         if (theIO->isSame(aVisuActor->getIO()))
285           return aVisuActor;
286       }
287     }
288   }
289   return 0;
290 }
291
292 VISU::Base_i* GetSelectedVisuObj(){
293   SALOME_Selection* Sel = SALOME_Selection::Selection(MYActiveStudy->getSelection());
294   SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
295   if(It.More()){
296     Handle(SALOME_InteractiveObject) IObject = It.Value();
297     if (IObject->hasEntry()){
298       SALOMEDS::SObject_var aSObject = MYStudyDocument->FindObjectID(IObject->getEntry());
299       if(!aSObject->_is_nil()){
300         CORBA::Object_var aObject = VISU::SObjectToObject(aSObject);
301         if(!CORBA::is_nil(aObject))
302           return dynamic_cast<VISU::Base_i*>(VISU::GetServant(aObject));
303       }
304     }
305   }
306   return NULL;
307 }
308
309 /**
310  * Returns selected sclalar mode or -1 if it was cancelled
311  */
312 int GetScalarMode(VISU::Result_i* theResult, const char* theFieldName){
313   int aScalarMode = 0;
314 //  const VISU::TField* aField = theResult->GetInput()->GetField(theFieldName);
315 //  if(aField->myNbComp > 1){
316 //    VisuGUI_SelVectCompDlg* SelCompDlg = new VisuGUI_SelVectCompDlg(QAD_Application::getDesktop(), 0, TRUE, 0);
317 //    if(SelCompDlg->exec()){
318 //      aScalarMode = SelCompDlg->whatIsChecked();
319 //    } else {
320 //      aScalarMode = -1;
321 //    }
322 //    delete SelCompDlg;
323 //  }
324   return aScalarMode;
325 }  
326
327
328 VisuGUI::VisuGUI(){
329 }
330
331
332 VisuGUI* VisuGUI::GetOrCreateVisuGUI( QAD_Desktop* desktop ){
333   if(!visuGUI){
334     static VisuGUI VISUGUI;
335     visuGUI = &VISUGUI;
336     Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "VISU");
337     myComponent = VISU::VISU_Gen::_narrow(comp);
338   }
339   /* study may have changed */
340   myDesktop = desktop;
341   myActiveStudy = myDesktop->getActiveStudy();
342   myStudy = myActiveStudy->getStudyDocument(); //Document OCAF de l'etude active
343   myComponent->SetCurrentStudy(myStudy);
344   myStudyBuilder = myStudy->NewBuilder(); 
345
346   MYActiveStudy = myActiveStudy;
347   MYStudyDocument = myStudy;
348   MYStudyBuilder = myStudyBuilder;
349   return visuGUI;
350 }
351
352 /* ********************************************************************************* */
353 /* Function to return VisuGUI object                                                 */
354 /* ********************************************************************************* */
355 VisuGUI* VisuGUI::GetVisuGUI( )
356 {
357         return VisuGUI::GetOrCreateVisuGUI(QAD_Application::getDesktop());
358 }
359
360 /* ==================================================================================== */
361 /* ==================================================================================== */
362 /*                                      ONGUI EVENT                                     */
363 /* ==================================================================================== */
364 /* ==================================================================================== */
365
366 static int isStudyLocked(const SALOMEDS::Study_var& theStudy){
367   return theStudy->GetProperties()->IsLocked();
368 }
369
370 static int checkLock(const SALOMEDS::Study_var& theStudy) {
371   if (isStudyLocked(theStudy)) {
372     QAD_MessageBox::warn1 ( (QWidget*)QAD_Application::getDesktop(),
373                            QObject::tr("WARNING"), 
374                            QObject::tr("WRN_STUDY_LOCKED"),
375                            QObject::tr("BUT_OK") );
376     return true;
377   }
378   return false;
379 }
380
381
382
383 bool VisuGUI::OnGUIEvent(int theCommandID,  QAD_Desktop* parent)
384 {
385   try{
386   VisuGUI::GetOrCreateVisuGUI(parent);
387 // get Visu directories from configuration file. Default values are enabled.
388 /*  if (visuGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK) {  // BugID: SAL931
389     QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("VISU_WARNING"),
390                             tr ("Not available in Non-VTK viewers"),
391                             tr ("VISU_BUT_OK") );
392                             }*/
393   QString VisuInputDir = getVisuInputDir();
394   QString VisuOutputDir = getVisuOutputDir();
395   vtkRenderer *theRenderer = GetRenderer(visuGUI->myActiveStudy);
396
397   //vtkActorCollection* aActors = theRenderer->GetActors();
398   //cout<<"### Actors Nb="<<aActors->GetNumberOfItems()<<endl;
399
400   SALOMEDS::Study_var aStudy = visuGUI->myActiveStudy->getStudyDocument(); //Document OCAF de l'etude active
401   SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
402   SALOMEDS::GenericAttribute_var anAttr;
403   SALOMEDS::AttributeName_var    aName;
404   SALOMEDS::AttributeIOR_var     anIOR;
405
406   switch (theCommandID)
407     {
408         /* ======================================================================================== */
409         /* Define Selection Mode                                                                  */
410         /* ======================================================================================== */
411     case 101:
412     case 102:
413     case 103:
414     case 104:
415       {
416         QApplication::setOverrideCursor( Qt::waitCursor );
417         int mode  = theCommandID - 100; // Point, Edge, Cell, Actor     
418         parent->SetSelectionMode( mode );
419         QApplication::restoreOverrideCursor();
420       }
421       break;
422       
423       /* ======================================================================================== */
424       /* Import Table from file                                                                   */
425       /* ======================================================================================== */
426
427     case 199:
428       {
429         if(checkLock(aStudy)) break;
430         visuGUI->ImportTablesFromFile();
431         break;
432       }
433
434       /* ======================================================================================== */
435       /* Import Mesh from MED, DAT file                                                                   */
436       /* ======================================================================================== */
437
438     case 112:
439       {
440         visuGUI->ImportFromFile();
441         break;
442       }
443
444       /* ======================================================================================== */
445       /* Export results and mesh into a file format                                               */
446       /* ======================================================================================== */
447
448     case 122:
449       {
450         visuGUI->ExportToFile();
451         break;
452       }
453
454       /* ========================================================================================================================= */
455       /* Print to printer (132)  or in file (131)                                                                                  */
456       /* ========================================================================================================================= */
457
458     case 131 :
459     case 132 :
460       {
461         QString prFile;
462         if (theCommandID ==  131) { // save the file
463           prFile = QAD_FileDlg::getFileName(QAD_Application::getDesktop(),
464                                             VisuOutputDir,
465                                             filters[9],
466                                             tr("TIFF File"),
467                                             false);
468           if ( prFile.isEmpty() )
469             break;
470           
471           VisuOutputDir = QAD_Tools::getDirFromPath(prFile); // set VisuOutputDir
472           QAD_CONFIG->addSetting("Visu:OutputDir",VisuOutputDir);
473           
474           visuGUI->PrintRW(prFile, false);
475         } else {
476           prFile=VisuOutputDir+"SalomeVisu.tif"; 
477           visuGUI->PrintRW(prFile, true);
478         }
479         break;
480       }
481                    
482      /* ========================================================================== */
483      /* Visualization of Results :                                                 */
484      /* 4011 : Scalar Map                                                          */
485      /* 4012 : Deformed Shape                                                      */
486      /* 4013 : Vectors                                                             */
487      /* 4014 : Iso-Surfaces                                                        */
488      /* 4015 : Cut Planes                                                          */
489      /* 4016 : Stream Lines                                                        */
490      /* ========================================================================== */
491
492     case 4011 :
493       visuGUI->CreateScalarMap();
494       break;
495     case 4012 :
496       visuGUI->CreateDeformedShape();
497       break;
498     case 4013 :
499       visuGUI->CreateVectors();
500       break;
501     case 4014 :
502       visuGUI->CreateIsoSurfaces();
503       break;
504     case 4015 :
505       visuGUI->CreateCutPlanes();
506       break;
507     case 4016 :
508       visuGUI->CreateStreamLines();
509       break;
510
511       /* ======================================================================================================================= */
512       /* View Scalar Animation (Animation/scalar)                                                                                */
513       /* With Phase                                                                                                              */
514       /* ======================================================================================================================= */
515
516       //case 4021 :
517       //case 4022 :
518       //case 4023 :
519
520       /* ========================================================================================================================= */
521       /* Selection - Cell  by number                                                                                               */
522       /* ========================================================================================================================= */
523
524     case 4111 :
525       {
526         visuGUI->SelectCell();
527         break;
528 /* VSR 12/03/03: see VisuGUI::SelectCell()
529         int TypeMode;
530         VISU_Actor *ActorTmp;
531         string aComment;
532         Handle(SALOME_InteractiveObject) anIO;
533         CORBA::Object_var anObject = GetSelectedObj(aComment,anIO,visuGUI->myActiveStudy);
534         //srn: Added check if anObject is Null, then break
535 //      if(CORBA::is_nil(anObject)) break;
536         
537         VISU::ScalarMap_i* aPrsObject = NULL;
538         if(!CORBA::is_nil(anObject))
539           aPrsObject = dynamic_cast<VISU::ScalarMap_i*>(VISU::GetServant(anObject));
540         if(aPrsObject){
541           //aPrsObject->SetIO(anIO);
542           //ActorTmp = aPrsObject->GetActor();
543           //UpdateViewer(ActorTmp);
544           ActorTmp = visuGUI->UpdateViewer(aPrsObject);
545         } else {
546           ActorTmp = ActorSelected(parent,true,&TypeMode);
547         }
548         if (ActorTmp==NULL)
549                 break;
550        
551         bool ok=FALSE;
552         vtkDataSetMapper *Mapper = (vtkDataSetMapper*) (ActorTmp->GetMapper());
553         Mapper->SetInput(ActorTmp->DataSource);
554         vtkDataSet *Data=Mapper->GetInput();
555         int nbCells=Data->GetNumberOfCells();
556         int selectedCell = QInputDialog::getInteger( tr( "Please choose a cell number" ), tr("Cell selection"), 0, 0, (int)(nbCells), 1, &ok, parent ,"");
557         if (ok && theRenderer)
558                 Selection->HighlightCell(selectedCell , ActorTmp , theRenderer);
559         break;
560 */
561         }
562
563       /* ========================================================================================================================= */
564       /* Selection - Cell - information attribute                                                                                  */
565       /* ========================================================================================================================= */
566
567     case 4112 :
568       {
569         visuGUI->InfoOnCell();
570         break;
571 /* VSR 12/03/03: see VisuGUI::InfoOnCell()
572         int TypeMode;
573         VISU_Actor *ActorTmp;
574         ActorTmp = ActorSelected(parent,true,&TypeMode);
575         if (ActorTmp==NULL)
576                 break;
577        
578         if ((TypeMode == SelectionCell) || (TypeMode == SelectionEdge))
579                 Selection->PickingResults(visuGUI->myActiveStudy,TypeMode,ActorTmp);
580         else
581                 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("WARNING"),
582                     tr ("Not Selected View - Cell Selection Mode"),
583                     tr ("VISU_BUT_OK") );
584         break;
585 */
586         }
587
588       /* ========================================================================================================================= */
589       /* Selection - Point - information number                                                                                    */
590       /* ========================================================================================================================= */
591
592     case 4121 :
593       {
594         visuGUI->SelectPoint();
595         break;
596 /* VSR 12/03/03: see VisuGUI::SelectPoint()
597         int TypeMode;
598         VISU_Actor *ActorTmp;
599         ActorTmp = ActorSelected(parent,true,&TypeMode);
600         if (ActorTmp==NULL)
601                 break;
602         
603         bool ok=FALSE;
604         vtkDataSetMapper *Mapper = (vtkDataSetMapper*) (ActorTmp->GetMapper());
605         Mapper->SetInput(ActorTmp->DataSource);
606         vtkDataSet *Data=Mapper->GetInput();
607         int nbPoints=Data->GetNumberOfPoints();
608         int selectedPoint = QInputDialog::getInteger( tr( "Please choose a Point number" ), tr("Point selection"), 0, 0, (int)(nbPoints-1), 1, &ok, parent ,"");
609         if (ok && theRenderer)
610                 Selection->HighlightPoint(selectedPoint , nbPoints, ActorTmp , theRenderer);
611         break;
612 */
613         }
614
615       /* ========================================================================================================================= */
616       /* Selection - Point - information attribute                                                                                 */
617       /* ========================================================================================================================= */
618
619     case 4122 :
620       {
621         visuGUI->InfoOnPoint();
622         break;
623 /* VSR 12/03/03: see VisuGUI::InfoOnPoint()
624         int TypeMode;
625         VISU_Actor *ActorTmp;
626         ActorTmp = ActorSelected(parent,true,&TypeMode);
627         if (ActorTmp==NULL)
628                 break;
629        
630         if (TypeMode == SelectionPoint)
631                 Selection->PickingResults(visuGUI->myActiveStudy,TypeMode,ActorTmp);
632         else 
633                 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("WARNING"),
634                     tr ("Not Selected View - Point Selection Mode"),
635                     tr ("VISU_BUT_OK") );
636         break;
637 */
638         }
639
640       /* ========================================================================================================================= */
641       /* Selection - Shape                                                                                                         */
642       /* ========================================================================================================================= */
643
644       //case 413 :
645
646       /* ========================================================================================================================= */
647       /* Visualization - Wireframe                                                                                                 */
648       /* ========================================================================================================================= */
649
650     case 4211 :
651       ChangeViewer(parent, theRenderer, true, 1);
652       break;
653
654       /* ========================================================================================================================= */
655       /* Visualization - Surface                                                                                                   */
656       /* ========================================================================================================================= */
657
658     case 4212 :
659       ChangeViewer(parent, theRenderer, true, 2);
660       break;
661
662       /* ========================================================================================================================= */
663       /* Visualization - Points                                                                                                    */
664       /* ========================================================================================================================= */
665
666     case 4213 :
667       ChangeViewer(parent, theRenderer, true, 0);
668       break;
669
670       /* ========================================================================================================================= */
671       /* Visualization - Erase                                                                                                     */
672       /* ========================================================================================================================= */
673
674     case 422 :
675       if (visuGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK)
676         ClearViewer(parent, theRenderer, -1);
677       break;
678
679       /* ========================================================================================================================= */
680       /* Visualization - Global                                                                                                    */
681       /* ========================================================================================================================= */
682
683       //case 423 :
684                    
685       /* ========================================================================================================================= */
686       /* Visualization - Partial                                                                                                   */
687       /* ========================================================================================================================= */
688
689       //case 424 :
690
691       case 430 :
692        {  
693          //Show dialog that allows to select scale function and corresponding scale factor
694          VisuGUI_NonIsometricDlg* m_NonIsoDlg = new VisuGUI_NonIsometricDlg ( QAD_Application::getDesktop(), "m_NonIsoDlg",
695                                                                               FALSE, Qt::WDestructiveClose );
696          m_NonIsoDlg->show();
697          break;
698        }
699
700       /* ============================ */
701       /*  POP-UP OBJECTS BROWSER      */
702       /* ============================ */
703
704     case 900 : // Rename object
705       visuGUI->Rename();
706       break;
707
708                 // ---------------- For Popup in Viewer
709     case 802  : // Erase
710     case 902  : // Erase
711       visuGUI->ErasePrs();
712       break;
713
714     case 803  : // Display only
715     case 903  : // Display only
716       visuGUI->DisplayOnlyPrs();
717       break;
718
719     case 901  : // Display
720       visuGUI->DisplayPrs();
721       break;
722
723     case 8041 : // Object representation : Wireframe
724     case 9041 : // Object representation : Wireframe
725       visuGUI->ChangeRepresentation(WIREFRAME);
726       break;
727
728     case 8042 : // Object representation : Surface
729     case 9042 : // Object representation : Surface
730       visuGUI->ChangeRepresentation(SURFACE);
731       break;
732
733     case 8043 : // Object representation : Points
734     case 9043 : // Object representation : Points
735       visuGUI->ChangeRepresentation(POINTS);
736       break;
737
738     case 8044 : // Object representation : Shrink/Unshrink
739     case 9044 : // Object representation : Shrink/Unshrink
740       visuGUI->ChangeRepresentation(SHRINK);
741       break;
742
743     case 8051 : // Change object color
744     case 9051 : // Change object color
745       visuGUI->ChageColor();
746       break;
747
748     case 8052 : // Change object opacity
749     case 9052 : // Change object opacity
750       visuGUI->ChangeOpacity();
751       break;
752
753     case 8053 : // Change object line width
754     case 9053 : // Change object line width
755       visuGUI->ChangeLines();
756       break;
757
758     case 808  : // Sweep IsoSurfaces or Cutplanes
759     case 908  : // Sweep IsoSurfaces or Cutplanes
760       visuGUI->Sweep();
761       break;
762
763     case 807  : // Modify visualization
764     case 809  : // Return Cell Id
765     case 810  : // Highlight Cell parameter
766                 // ---------------- For Popup in ObjectBrowser
767     case 907  : // Modify visualization
768
769       {
770         int TypeMode;
771         bool InViewer;
772         VISU_Actor *ActorTmp;
773         string aComment;
774         Handle(SALOME_InteractiveObject) anIO;
775         CORBA::Object_var anObject = GetSelectedObj(aComment,anIO,visuGUI->myActiveStudy);
776         VISU::ScalarMap_i* aPrsObject = dynamic_cast<VISU::ScalarMap_i*>(VISU::GetServant(anObject));
777         if(aPrsObject){
778           ActorTmp = visuGUI->UpdateViewer(aPrsObject);
779         } else {
780           if ( ((theCommandID >= 801) && (theCommandID <= 809)) || ((theCommandID >= 8041) && (theCommandID <= 8059)) )
781             InViewer= true;
782           else if ( ((theCommandID >= 901) && (theCommandID <= 909)) || ((theCommandID >= 9041) && (theCommandID <= 9059)) )
783             InViewer = false;
784           
785           ActorTmp = ActorSelected(parent,InViewer,&TypeMode);
786         }
787         if (ActorTmp==NULL)
788                 break;
789         
790
791         if (theCommandID == 809) // return results of object picked, in the message box
792         {
793                 Selection->PickingResults(visuGUI->myActiveStudy,TypeMode,ActorTmp);
794                 MESSAGE("Valeur  : " << Selection->getId())
795         }
796
797         if (theCommandID == 810) // Highlight Cell or point with parameter 
798         {
799                 bool ok=FALSE;
800                 vtkDataSetMapper *Mapper = (vtkDataSetMapper*) (ActorTmp->GetMapper());
801                 Mapper->SetInput(ActorTmp->DataSource);
802                 vtkDataSet *Data=Mapper->GetInput();
803                 if (TypeMode == SelectionPoint)
804                 {
805                         int nbPoints=Data->GetNumberOfPoints();
806                         int selectedPoint = QInputDialog::getInteger( tr( "Please choose a Point number" ), tr("Point selection"), 0, 0, (int)(nbPoints-1), 1, &ok, parent ,"");
807                         if (ok)
808                                 Selection->HighlightPoint(selectedPoint , nbPoints, ActorTmp , theRenderer);
809                 }
810                 if ( (TypeMode == SelectionCell) || (TypeMode == SelectionEdge) )
811                 {
812                         int nbCells=Data->GetNumberOfCells()-1;
813                         int selectedCell = QInputDialog::getInteger( tr( "Please choose a cell number" ), tr("Cell selection"), 0, 0, (int)(nbCells), 1, &ok, parent ,"");
814                         if (ok)
815                                 Selection->HighlightCell(selectedCell , ActorTmp , theRenderer);
816                 }
817         }
818         
819         break;
820      }
821
822 /* ======================================================================================== */
823 /* Preferences for Scalar Bar                                                               */
824 /* ======================================================================================== */
825     case 51:
826       {
827         ChangeScalarBar();
828
829         break;
830       }
831
832 /* ======================================================================================== */
833 /* Preferences for Sweeping                                                               */
834 /* ======================================================================================== */
835     case 52:
836       {
837         SetSweepingPreferences();
838       }
839       break;
840       
841
842     case 113: // Load MED using MED component
843       {
844         if (checkLock(myStudy)) break;
845
846         Engines::Component_var aMedComp = myDesktop->getEngine("FactoryServer", "MED");
847         if (CORBA::is_nil(aMedComp)) return false;
848         Engines::Med_Gen_var aMedGen = Engines::Med_Gen::_narrow(aMedComp);
849         if (CORBA::is_nil(aMedGen)) return false;
850
851         QStringList filtersList ;       
852         
853         filtersList.append( tr("MED_MEN_IMPORT_MED") );
854         filtersList.append( tr("MED_MEN_ALL_FILES") ) ;
855         QString aFileName = QAD_FileDlg::getFileName(myDesktop,
856                                                      "",
857                                              filtersList,
858                                                      tr("MED_MEN_IMPORT"),
859                                                      true);
860         if (!aFileName.isEmpty()) {
861           QApplication::setOverrideCursor( Qt::waitCursor );
862           aMedGen->readStructFileWithFieldType(aFileName.latin1(), myActiveStudy->getTitle());
863           myActiveStudy->updateObjBrowser();
864           QApplication::restoreOverrideCursor();
865         }
866       }
867       break;
868
869     default:
870       QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("VISU_WARNING"),
871                               tr ("Not Yet Implemented"),
872                               tr ("VISU_BUT_OK") );
873       break;
874     }
875   }
876 /*
877   catch(SALOMEDS::GenericAttribute::LockProtection&) {
878     QAD_MessageBox::warn1 ( (QWidget*)QAD_Application::getDesktop(),
879                             QObject::tr("WARNING"), 
880                             QObject::tr("WRN_STUDY_LOCKED"),
881                             QObject::tr("BUT_OK") );
882     return false;
883   }
884 */
885   catch (const SALOME::SALOME_Exception& S_ex) {
886     QtCatchCorbaException(S_ex);
887     return false;
888   }
889   catch(...) {
890     QAD_MessageBox::warn1(QAD_Application::getDesktop(), tr ("VISU_WARNING"),
891                           tr("Unknown exception was caught in VISU module"),
892                           tr("VISU_BUT_OK") );
893     return false;
894   }
895   return true;
896 }
897
898
899 /* ********************************************************************************* */
900 /* Function to find Actor in ObjectBrowser                                           */
901 /* ********************************************************************************* */
902
903 VISU_Actor *VisuGUI::GetActorObjBrowser(SALOMEDS::SObject_var objVisu, vtkRenderer *ren)
904 {
905   SALOMEDS::GenericAttribute_var anAttr;
906   SALOMEDS::AttributeName_var    aName;
907   if ( objVisu->FindAttribute(anAttr, "AttributeName") ) {
908     aName = SALOMEDS::AttributeName::_narrow(anAttr);
909     
910     MESSAGE("GetActor == > Name : " << aName->Value());
911     
912     vtkActorCollection *ac;
913     vtkActor *actor;
914     ac = ren->GetActors();
915     
916     for(ac->InitTraversal();(actor = ac->GetNextActor())!=NULL;) {
917       if (actor->IsA("VISU_Actor")) {
918         VISU_Actor *VISUActor = VISU_Actor::SafeDownCast(actor);
919         if (strcmp(VISUActor->getName(), aName->Value()) == 0)
920           return VISUActor;
921       }
922     }
923   }
924   return NULL;
925 }
926
927
928 /* ********************************************************************************* */
929 /* Function to find Actor in Viewer                                                  */
930 /* ********************************************************************************* */
931
932
933 VISU_Actor *VisuGUI::GetActor(QAD_Desktop* parent, Handle_SALOME_InteractiveObject IO, vtkRenderer *ren)
934 {
935   VisuGUI::GetOrCreateVisuGUI(parent);
936   
937   QString theEntry = IO->getEntry();
938   Standard_CString aComment;
939   Standard_CString Persistent;
940   //Standard_CString aName = IO->getName();
941   VISU_Actor *anActor;
942   result Test;
943   
944   SALOMEDS::Study_var aStudy = visuGUI->myActiveStudy->getStudyDocument();
945   
946   SALOMEDS::SObject_var          objlocal = aStudy->FindObjectID(theEntry.latin1());
947   SALOMEDS::GenericAttribute_var       anAttr;
948   SALOMEDS::AttributeComment_var       aCmnt;
949   SALOMEDS::AttributePersistentRef_var aPRef;
950   
951   if (objlocal->FindAttribute(anAttr, "AttributeComment")) {
952     aCmnt = SALOMEDS::AttributeComment::_narrow(anAttr);
953     aComment = aCmnt->Value();
954   }
955   if (objlocal->FindAttribute(anAttr, "AttributePersistentRef")) {
956     aPRef = SALOMEDS::AttributePersistentRef::_narrow(anAttr);
957     Persistent = aPRef->Value();
958   }
959   
960   vtkActorCollection *aclocal;
961   vtkActor *actorlocal;
962   aclocal = ren->GetActors();
963   
964   // =============================================================================
965   // Test if Actor exists in theRenderer
966   for (aclocal->InitTraversal();(actorlocal = aclocal->GetNextActor())!=NULL;) 
967     {
968       if (actorlocal->IsA("VISU_Actor")) 
969         {
970           anActor = VISU_Actor::SafeDownCast(actorlocal);
971           MESSAGE(" getIO de anActor : " << anActor->getIO())
972             if (anActor->hasIO())
973               {
974                 if (IO->isSame(anActor->getIO()))
975                   {
976                     MESSAGE("isSame IO")
977                       return anActor;
978                   }
979               }
980         }
981     }
982
983   // =============================================================================
984   // If Actor doesn't exist in theRenderer => create same actor in new renderer
985   /*  int nbSf = visuGUI->myActiveStudy->getStudyFramesCount();
986   SALOMEDS::SObject_var TheMeshObject= objlocal->GetFather();
987   for ( int i = 0; i < nbSf; i++ )
988   {
989           QAD_StudyFrame* sf = visuGUI->myActiveStudy->getStudyFrame(i);
990           if ( sf->getTypeView() == VIEW_VTK )
991           {
992             vtkRenderer* aRenderer = ((VTKViewer_ViewFrame*)sf->getRightFrame()->getViewFrame())->getRenderer();
993             vtkActorCollection* ac = aRenderer->GetActors();
994             vtkActor *actor;
995             for(ac->InitTraversal();(actor = ac->GetNextActor())!=NULL;) 
996               {
997                 if (actor->IsA("VISU_Actor")) 
998                   {
999                                 anActor = VISU_Actor::SafeDownCast(actor);
1000                                 if (anActor->hasIO())
1001                                 {
1002                                         if (IO->isSame(anActor->getIO()))
1003                                         {
1004                                                 if (aRenderer != ren)
1005                                                 {
1006                                                         return(visuGUI->DuplicateActor(anActor,IO,objlocal,aComment));
1007                                                 }
1008                                         }
1009                                 }
1010                         }
1011                 }
1012           }
1013           }*/
1014   return NULL;
1015   //return(visuGUI->DuplicateActor(anActor,IO,objlocal,aComment));
1016 }
1017
1018 /* ********************************************************************************** */
1019 /* Function ActorSelected                                                             */
1020 /* To return the Actor selected in Viewer or in ObjectBrowser                         */
1021 /* ********************************************************************************** */
1022
1023 VISU_Actor *VisuGUI::ActorSelected(QAD_Desktop* parent, bool InViewer, int *Mode)
1024 {
1025   VisuGUI::GetOrCreateVisuGUI(parent);
1026   SALOME_Selection *Sel;
1027   QAD_ObjectBrowserItem* item;
1028   VISU_Actor *ActorTmp;
1029   Standard_CString PersRef = "";
1030   Sel = SALOME_Selection::Selection(visuGUI->myActiveStudy->getSelection());
1031   vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)visuGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
1032   
1033
1034
1035   *Mode=Sel->SelectionMode();
1036
1037   SALOMEDS::Study_var                  aStudy = visuGUI->myActiveStudy->getStudyDocument(); //Document OCAF de l'etude active
1038   SALOMEDS::StudyBuilder_var           aStudyBuilder = aStudy->NewBuilder();
1039   //SALOMEDS::SComponent_var             father = aStudy->FindComponent("VISU");
1040   SALOMEDS::GenericAttribute_var       anAttr;
1041   SALOMEDS::AttributeName_var          aName;
1042   SALOMEDS::AttributePersistentRef_var aPRef;
1043   if ( InViewer )
1044   {
1045         if (Sel->IObjectCount()==0)
1046                 return NULL;
1047         SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
1048         Handle(SALOME_InteractiveObject) IObject = It.Value();
1049         ActorTmp=GetActor(parent,IObject,theRenderer);
1050   }
1051   else
1052   {
1053         item = (QAD_ObjectBrowserItem*)(visuGUI->myActiveStudy->getActiveStudyFrame()->getLeftFrame()->getObjectBrowser()->getListView()->currentItem());
1054         if ( item != NULL ) 
1055         {      
1056                 // Test if a selected visu object
1057                 QString theEntry = item->getEntry();
1058  
1059                 MESSAGE("==================== TheEntry : " << theEntry)
1060                 if ( theEntry.isEmpty() ) 
1061                 {
1062                 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("VISU_WARNING"),
1063                                   tr ("Bad Type for Selected Item in Popup Menu"),
1064                                   tr ("VISU_BUT_OK") );
1065                 return NULL;
1066                 }
1067
1068                 SALOMEDS::SObject_var objVisu = aStudy->FindObjectID(theEntry.latin1());
1069                 if (objVisu->FindAttribute(anAttr, "AttributePersistentRef")) {
1070                         aPRef = SALOMEDS::AttributePersistentRef::_narrow(anAttr);
1071                         PersRef = aPRef->Value();
1072                 }
1073
1074                 if ( objVisu->_is_nil() ) 
1075                 {
1076                 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("VISU_WARNING"),
1077                                   tr ("nil object"),
1078                                   tr ("VISU_BUT_OK") );
1079                 return NULL;
1080                 }
1081                 ActorTmp=GetActorObjBrowser(objVisu,theRenderer);
1082         }
1083         else
1084                 return NULL;
1085   }
1086   return (ActorTmp);
1087 }
1088
1089 /* ********************************************************************************** */
1090 /* Function ClearViewer - Erase the actors displayed on the viewer                   */
1091 /* ********************************************************************************** */
1092
1093 void VisuGUI::ClearViewer(QAD_Desktop* parent, vtkRenderer *ren, int TypeOfActor)
1094 {
1095  // TypeOfActor = -1 : All
1096  //             =  1 : VisuActor
1097  //             =  2 : ScalarBarActor
1098  //             =  4 : Other Actor2D
1099
1100  vtkActorCollection *ac;
1101  vtkActor2DCollection *ac2D;
1102  vtkActor *actor;
1103  vtkActor2D *actor2D;
1104   ac = ren->GetActors();
1105   ac2D = ren->GetActors2D();
1106
1107   if(TypeOfActor == -1 || TypeOfActor == 1) {
1108     bool TrhVisible = ((VTKViewer_ViewFrame*)visuGUI->myActiveStudy->
1109                        getActiveStudyFrame()->getRightFrame()->getViewFrame())->isTrihedronDisplayed();
1110     for(ac->InitTraversal();(actor = ac->GetNextActor())!=NULL;) {
1111       if (actor->IsA("VISU_Actor") || actor->IsA("vtkActor") ) 
1112         actor->VisibilityOff();
1113     }
1114     if (TrhVisible) ShowTrihedron(false);
1115   }
1116   
1117   if(TypeOfActor == -1 || TypeOfActor == 2) {
1118     for(ac2D->InitTraversal();(actor2D = ac2D->GetNextActor2D())!=NULL;)
1119                 if (actor2D->IsA("vtkScalarBarActor")) 
1120                         actor2D->VisibilityOff();
1121   }
1122   
1123   if(TypeOfActor == -1 || TypeOfActor == 4) {
1124     for(ac2D->InitTraversal();(actor2D = ac2D->GetNextActor2D())!=NULL;)
1125                 if (!(actor2D->IsA("vtkScalarBarActor")))  // it's a plot2d
1126                 {
1127                         actor2D->VisibilityOff();
1128                         //actor2D->Delete();
1129                 }
1130   }
1131 }
1132
1133 /* ********************************************************************************** */
1134 /* Function ShowTrihedron                                                             */
1135 /* ********************************************************************************** */
1136
1137 void VisuGUI::ShowTrihedron(bool ShowThd){
1138   bool ThdIsVisible = true; 
1139   if( ShowThd && !ThdIsVisible)
1140     ((VTKViewer_ViewFrame*)visuGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->onViewTrihedron();
1141   if( !ShowThd && ThdIsVisible)
1142     ((VTKViewer_ViewFrame*)visuGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->onViewTrihedron();
1143 }
1144
1145 /* ********************************************************************************** */
1146 /* Destructor                                                                         */
1147 /* Clear all tmp files used in VISU                                                   */
1148 /* ********************************************************************************** */
1149
1150 VisuGUI::~VisuGUI(){
1151   MESSAGE("VisuGUI::~VisuGUI");
1152 }
1153                         
1154 /* ********************************************************************************** */
1155 /* Function ChangeViewer                                                              */
1156 /* Change representation of all actors                                                */
1157 /* ********************************************************************************** */
1158
1159 void VisuGUI::ChangeViewer(QAD_Desktop* parent, vtkRenderer *ren, bool ScalarBar, int Type)
1160 {
1161   if (!ren) return;
1162  VisuGUI::GetOrCreateVisuGUI(parent);
1163  vtkActorCollection *ac;
1164  vtkActor *actor;
1165  ac = ren->GetActors();
1166
1167   for(ac->InitTraversal();(actor = ac->GetNextActor())!=NULL;)
1168         actor->GetProperty()->SetRepresentation(Type); 
1169 }
1170
1171
1172 // -----------------------------------------------------------------------------------------
1173 // EVENTS
1174 // -----------------------------------------------------------------------------------------
1175
1176 bool VisuGUI::OnMousePress (QMouseEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame)
1177 {
1178   VisuGUI::GetOrCreateVisuGUI(parent);
1179   return true;
1180 }
1181
1182 // ====================================================================================================================
1183
1184 bool VisuGUI::OnMouseMove (QMouseEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame)
1185 {
1186   VisuGUI::GetOrCreateVisuGUI(parent);
1187   return true;
1188 }
1189
1190 // ===================================================================================================================
1191
1192 bool VisuGUI::OnKeyPress (QKeyEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame)
1193 {
1194   VisuGUI::GetOrCreateVisuGUI(parent);
1195   if (visuGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK) // true = Viewer OCC
1196     return false;
1197
1198   MESSAGE ( "VisuGUI::onKeyPress : " << pe->key() )
1199
1200   switch ( pe->key() )
1201     {
1202     case Key_Escape :
1203       {
1204           MESSAGE("--> Key : Escape")
1205           return true;    
1206       }
1207     default :
1208         return true;
1209         break;
1210    }
1211  return true;
1212 }
1213
1214
1215
1216 //=====================================================================================
1217 // Slot-functions for presentations creation
1218 //=====================================================================================
1219
1220
1221 #define CREATEPRESENTATION(FunctionName)  \
1222  void FunctionName() { \
1223    if (checkLock(myStudy)) return; \
1224    SALOMEDS::SObject_var objVisu;  \
1225    if (!TestObjectBrowser(&objVisu)) return;  \
1226    if(!FunctionName(objVisu)) return; \
1227    visuGUI->myActiveStudy->updateObjBrowser(); \
1228    myDesktop->putInfo("Ready"); \
1229    VTKViewer_ViewFrame* vf = GetVtkViewFrame(); \
1230    if (vf) { \
1231      /*vf->getRenderer()->ResetCameraClippingRange();*/ \
1232      vf->onViewFitAll(); \
1233    } \
1234  } 
1235
1236
1237 CREATEPRESENTATION(VisuGUI::CreateScalarMap);
1238 CREATEPRESENTATION(VisuGUI::CreateDeformedShape);
1239 CREATEPRESENTATION(VisuGUI::CreateVectors);
1240 CREATEPRESENTATION(VisuGUI::CreateIsoSurfaces);
1241 CREATEPRESENTATION(VisuGUI::CreateCutPlanes);
1242 CREATEPRESENTATION(VisuGUI::CreateStreamLines);
1243
1244
1245
1246
1247 //=====================================================================================
1248 // function : setSettings()
1249 // purpose  :
1250 //=====================================================================================
1251 bool VisuGUI::setSettings(QAD_Desktop* parent)
1252 {
1253   VisuGUI::GetOrCreateVisuGUI(parent);
1254   return true;
1255 }
1256
1257 //=====================================================================================
1258 // function : DisplayPrs()
1259 // purpose  :
1260 //=====================================================================================
1261 void VisuGUI::DisplayPrs() {
1262   MESSAGE("VisuGUI::DisplayPrs");
1263   string aComment;
1264   Handle(SALOME_InteractiveObject) anIO;
1265   CORBA::Object_var anObject = GetSelectedObj(aComment, anIO, myActiveStudy);
1266   if ( !CORBA::is_nil( anObject ) ) {
1267     // is it Prs3d object ?
1268     VISU::Prs3d_i* aPrsObject = dynamic_cast<VISU::Prs3d_i*>(VISU::GetServant(anObject));
1269     if(aPrsObject){
1270       MESSAGE("VisuGUI::DisplayPrs : Prs3d object");
1271       UpdateViewer(aPrsObject);
1272       VTKViewer_ViewFrame* vf = GetVtkViewFrame();
1273       if (vf) {
1274         vf->getRenderer()->ResetCameraClippingRange();
1275 #ifdef CHECKTIME
1276   OSD_Timer timer;
1277   timer.Start();
1278 #endif
1279         vf->Repaint();
1280         vf->highlight(anIO, 1);
1281 #ifdef CHECKTIME
1282   timer.Stop();
1283   MESSAGE("Check time on VisuGUI::DisplayPrs - vf->Repaint + vf->highlight");
1284   timer.Show();
1285 #endif
1286       }
1287       return;
1288     }
1289     // is it Curve ?
1290     VISU::Curve_i* aCurve = dynamic_cast<VISU::Curve_i*>(VISU::GetServant(anObject));
1291     if(aCurve){
1292       MESSAGE("VisuGUI::DisplayPrs : Curve object");
1293       PlotCurve(aCurve, VISU::eDisplay );
1294       return;
1295     }
1296     // is it Container ?
1297     VISU::Container_i* aContainer = dynamic_cast<VISU::Container_i*>(VISU::GetServant(anObject));
1298     if(aContainer){
1299       MESSAGE("VisuGUI::DisplayPrs : Container object");
1300       PlotContainer(aContainer, VISU::eDisplay );
1301       return;
1302     }
1303     // is it Table ?
1304     VISU::Table_i* aTable = dynamic_cast<VISU::Table_i*>(VISU::GetServant(anObject));
1305     if(aTable){
1306       MESSAGE("VisuGUI::DisplayPrs : Table object");
1307       PlotTable(aTable, VISU::eDisplay );
1308       return;
1309     }
1310   }
1311 }
1312
1313 //=====================================================================================
1314 // function : DisplayOnlyPrs()
1315 // purpose  :
1316 //=====================================================================================
1317 void VisuGUI::DisplayOnlyPrs() {
1318   MESSAGE("VisuGUI::DisplayOnlyPrs");
1319   string aComment;
1320   Handle(SALOME_InteractiveObject) anIO;
1321   CORBA::Object_var anObject = GetSelectedObj(aComment, anIO, myActiveStudy);
1322   if ( !CORBA::is_nil( anObject ) ) {
1323     // is it Prs3d object ?
1324     VISU::Prs3d_i* aPrsObject = dynamic_cast<VISU::Prs3d_i*>(VISU::GetServant(anObject));
1325     if(aPrsObject){
1326       MESSAGE("VisuGUI::DisplayOnlyPrs : Prs3d object");
1327       UpdateViewer(aPrsObject, true);
1328       VTKViewer_ViewFrame* vf = GetVtkViewFrame();
1329       if (vf) {
1330         vf->getRenderer()->ResetCameraClippingRange();
1331         vf->Repaint();
1332       }
1333       return;
1334     }
1335     // is it Curve ?
1336     VISU::Curve_i* aCurve = dynamic_cast<VISU::Curve_i*>(VISU::GetServant(anObject));
1337     if(aCurve){
1338       MESSAGE("VisuGUI::DisplayOnlyPrs : Curve object");
1339       PlotCurve(aCurve, VISU::eDisplayOnly );
1340       return;
1341     }
1342     // is it Container ?
1343     VISU::Container_i* aContainer = dynamic_cast<VISU::Container_i*>(VISU::GetServant(anObject));
1344     if(aContainer){
1345       MESSAGE("VisuGUI::DisplayOnlyPrs : Container object");
1346       PlotContainer(aContainer, VISU::eDisplayOnly );
1347       return;
1348     }
1349     // is it Table ?
1350     VISU::Table_i* aTable = dynamic_cast<VISU::Table_i*>(VISU::GetServant(anObject));
1351     if(aTable){
1352       MESSAGE("VisuGUI::DisplayOnlyPrs : Table object");
1353       PlotTable(aTable, VISU::eDisplayOnly );
1354       return;
1355     }
1356   }
1357 }
1358
1359 //=====================================================================================
1360 // function : ErasePrs()
1361 // purpose  :
1362 //=====================================================================================
1363 void VisuGUI::ErasePrs() {
1364   MESSAGE("VisuGUI::ErasePrs");
1365   string aComment;
1366   Handle(SALOME_InteractiveObject) anIO;
1367   CORBA::Object_var anObject = GetSelectedObj(aComment, anIO, myActiveStudy);
1368   if ( !CORBA::is_nil( anObject ) ) {
1369     // is it Prs3d object ?
1370     VISU::Prs3d_i* aPrsObject = dynamic_cast<VISU::Prs3d_i*>(VISU::GetServant(anObject));
1371     if(aPrsObject){
1372       MESSAGE("VisuGUI::ErasePrs : Prs3d object");
1373       ErasePrs(aPrsObject);
1374       VTKViewer_ViewFrame* vf = GetVtkViewFrame();
1375       if (vf) {
1376         vf->Repaint();
1377       }
1378     }
1379     // is it Curve ?
1380     VISU::Curve_i* aCurve = dynamic_cast<VISU::Curve_i*>(VISU::GetServant(anObject));
1381     if(aCurve){
1382       MESSAGE("VisuGUI::ErasePrs : Curve object");
1383       PlotCurve(aCurve, VISU::eErase );
1384     }
1385     // is it Container ?
1386     VISU::Container_i* aContainer = dynamic_cast<VISU::Container_i*>(VISU::GetServant(anObject));
1387     if(aContainer){
1388       MESSAGE("VisuGUI::ErasePrs : Container object");
1389       PlotContainer(aContainer, VISU::eErase );
1390     }
1391     // is it Table ?
1392     VISU::Table_i* aTable = dynamic_cast<VISU::Table_i*>(VISU::GetServant(anObject));
1393     if(aTable){
1394       MESSAGE("VisuGUI::ErasePrs : Table object");
1395       PlotTable(aTable, VISU::eErase );
1396     }
1397   }
1398 }
1399
1400
1401 //=====================================================================================
1402 // function : RecreateActor()
1403 // purpose  :
1404 //=====================================================================================
1405 void VisuGUI::RecreateActor(VISU::Prs3d_i* thePrs) {
1406   /*   BEGIN_OF("VisuGUI::RecreateActor");
1407  
1408   VTKViewer_ViewFrame* vf = GetVtkViewFrame();
1409   if (!vf) return;
1410   QApplication::setOverrideCursor( Qt::waitCursor );
1411   vtkRenderer *aRen = vf->getRenderer();
1412   VISU_Actor* anVISUActor = GetActor(thePrs);
1413
1414   if(anVISUActor == NULL){
1415     anVISUActor= thePrs->CreateActor();
1416     anVISUActor->SetVisibility(true);
1417     vf->AddActor(anVISUActor);
1418     if (anVISUActor->HasScalarBar()) {
1419       anVISUActor->getScalarBar()->SetVisibility(true);
1420       aRen->AddActor2D(anVISUActor->getScalarBar());
1421     }
1422   }
1423   vf->Repaint();
1424
1425   QApplication::restoreOverrideCursor();
1426
1427   END_OF("VisuGUI::RecreateActor") */
1428   VTKViewer_ViewFrame* vf = GetVtkViewFrame();
1429   if (!vf) return;
1430
1431   VISU_Actor* anVISUActor = GetActor(thePrs);
1432   int isVisible = false;
1433
1434   QApplication::setOverrideCursor( Qt::waitCursor );
1435   vtkRenderer *aRen = vf->getRenderer();
1436   if (anVISUActor) {
1437     isVisible = anVISUActor->GetVisibility();
1438     Handle(SALOME_InteractiveObject) anIO = anVISUActor->getIO();
1439     if (anVISUActor->HasScalarBar())
1440       aRen->RemoveActor(anVISUActor->getScalarBar());
1441     aRen->RemoveActor(anVISUActor);
1442     anVISUActor->Delete();
1443     anVISUActor = thePrs->CreateActor(anIO);
1444   } else
1445     anVISUActor = thePrs->CreateActor();
1446   QApplication::restoreOverrideCursor();
1447
1448   if (!anVISUActor) return;
1449   anVISUActor->SetVisibility(isVisible);
1450   aRen->AddActor(anVISUActor);
1451   if (anVISUActor->HasScalarBar()) {
1452     anVISUActor->getScalarBar()->SetVisibility(isVisible);
1453     aRen->AddActor2D(anVISUActor->getScalarBar());
1454   }
1455 }
1456
1457
1458 //=====================================================================================
1459 // function : EditPrs()
1460 // purpose  :
1461 //=====================================================================================
1462 #define EDITPRS(PrsName, DlgName)  \
1463     { \
1464       PrsName* aPrsObject = dynamic_cast<PrsName*>(aPrs3d); \
1465       if (aPrsObject) { \
1466         DlgName* aDlg = new DlgName(); \
1467         aDlg->initFromPrsObject(aPrsObject); \
1468         if ( aDlg->exec() )  { \
1469           aDlg->storeToPrsObject(aPrsObject); \
1470           RecreateActor(aPrsObject); \
1471           /*RepaintCurrentView();*/ \
1472           VTKViewer_ViewFrame* vf = GetVtkViewFrame(); \
1473           if (vf) { \
1474             if ( vf->getRenderer()->GetActors()->GetNumberOfItems () > 0 ) { \
1475                  vf->getRenderer()->ResetCameraClippingRange(); \
1476                  vf->onViewFitAll(); \
1477               }\
1478           } \
1479         } \
1480         delete aDlg; \
1481       } \
1482     }
1483
1484
1485 void VisuGUI::EditPrs() {
1486   VISU::Prs3d_i* aPrs3d = GetSelectedPrs();
1487
1488   switch (aPrs3d->GetType()) {
1489   case VISU::TMESH: // Mesh 13
1490     break;
1491
1492   case VISU::TSCALARMAP: // ScalarMap 18
1493     EDITPRS(VISU::ScalarMap_i, VisuGUI_ScalarBarDlg);
1494     break;
1495
1496   case VISU::TDEFORMEDSHAPE: // Deformed Shape 28
1497     EDITPRS(VISU::DeformedShape_i, VisuGUI_MagnitudeDlg);
1498     break;
1499
1500   case VISU::TCUTPLANES: // Cut planes 42
1501     EDITPRS(VISU::CutPlanes_i, VisuGUI_CutPlanesDlg);
1502     break;
1503
1504   case VISU::TISOSURFACE: // Iso surfaces
1505     EDITPRS(VISU::IsoSurfaces_i, VisuGUI_IsoSurfacesDlg);
1506     break;
1507   case VISU::TVECTORS: // Vectors 64
1508     EDITPRS(VISU::Vectors_i, VisuGUI_VectorsDlg);
1509     break;
1510
1511   case VISU::TSTREAMLINES:
1512     EDITPRS(VISU::StreamLines_i, VisuGUI_StreamLinesDlg);
1513   }
1514 }
1515
1516
1517 //=====================================================================================
1518 // function : EditScalarBar()
1519 // purpose  :
1520 //=====================================================================================
1521 void VisuGUI::EditScalarBar() {
1522   VISU::Prs3d_i* aPrs3d = GetSelectedPrs();
1523   VISU::ScalarMap_i* aPrsObject = dynamic_cast<VISU::ScalarMap_i*>(aPrs3d);
1524   if (aPrsObject) {
1525     VisuGUI_ScalarBarDlg* aDlg = new VisuGUI_ScalarBarDlg(false);
1526     aDlg->initFromPrsObject(aPrsObject);
1527     if ( aDlg->exec() )  {
1528       aDlg->storeToPrsObject(aPrsObject);
1529       RecreateActor(aPrsObject);
1530       
1531       VTKViewer_ViewFrame* vf = GetVtkViewFrame();
1532       if (vf)
1533         vf->Repaint();
1534       
1535       if (aDlg->isToSave())
1536         aDlg->storeToResources();
1537     }
1538     delete aDlg;
1539   }
1540   
1541 }
1542
1543
1544 //=====================================================================================
1545 // function : CreateMesh()
1546 // purpose  :
1547 //=====================================================================================
1548 void VisuGUI::CreateMesh() {
1549   
1550   //string aComment;
1551   //Handle(SALOME_InteractiveObject) anIO;    
1552   //CORBA::Object_var anObject = GetSelectedObj(aComment,anIO, VisuGUI::myActiveStudy);
1553   SALOME_Selection* Sel = SALOME_Selection::Selection(myActiveStudy->getSelection());
1554   SALOMEDS::SObject_var aSObject  = myActiveStudy->getStudyDocument()->FindObjectID( Sel->firstIObject()->getEntry() );
1555   
1556   if (checkLock(myStudy)) return;
1557
1558   SALOMEDS::SObject_var aSObj = aSObject->GetFather();
1559   aSObj = aSObj->GetFather();
1560   aSObj = aSObj->GetFather();
1561   CORBA::Object_var anObject = VISU::SObjectToObject(aSObj);
1562   if(CORBA::is_nil(anObject)) {
1563     aSObj = aSObj->GetFather();
1564     anObject = VISU::SObjectToObject(aSObj);
1565     if(CORBA::is_nil(anObject)) return;
1566   }
1567   VISU::Result_var aResult = VISU::Result::_narrow(anObject);
1568   if(CORBA::is_nil(aResult)) return;
1569
1570   VISU::Storable::TRestoringMap aMap;
1571   SALOMEDS::GenericAttribute_var anAttr;
1572   if(aSObject->FindAttribute(anAttr, "AttributeComment")) {
1573     SALOMEDS::AttributeComment_var aComment = SALOMEDS::AttributeComment::_narrow(anAttr);
1574     string aComm = aComment->Value();
1575     QString strIn(aComm.c_str());
1576     VISU::Storable::StrToMap(strIn,aMap);
1577   }
1578   bool isExist;
1579   string aComment = VISU::Storable::FindValue(aMap,"myComment",&isExist).latin1();
1580   if(!isExist) return;
1581   CORBA::Object_var aMesh;
1582   string aMeshName = VISU::Storable::FindValue(aMap,"myMeshName").latin1();
1583   if(aComment == "ENTITY"){
1584     VISU::Entity anEntity = (VISU::Entity)VISU::Storable::FindValue(aMap,"myId").toInt();
1585     aMesh = myComponent->MeshOnEntity(aResult,aMeshName.c_str(),anEntity);
1586   }else if(aComment == "FAMILY"){
1587     VISU::Entity anEntity = (VISU::Entity)VISU::Storable::FindValue(aMap,"myEntityId").toInt();
1588     string aFamilyName = VISU::Storable::FindValue(aMap,"myName").latin1();
1589     aMesh = myComponent->FamilyMeshOnEntity(aResult,aMeshName.c_str(),anEntity,aFamilyName.c_str());
1590   }else if(aComment == "GROUP"){
1591     string aGroupName = VISU::Storable::FindValue(aMap,"myName").latin1();
1592     aMesh = myComponent->GroupMesh(aResult,aMeshName.c_str(),aGroupName.c_str());
1593   }
1594   QApplication::restoreOverrideCursor();
1595   if(CORBA::is_nil(aMesh)) return;
1596
1597   VISU::Mesh_i* pPresent = dynamic_cast<VISU::Mesh_i*>(VISU::GetServant(aMesh));
1598 #ifdef CHECKTIME
1599   OSD_Timer timer;
1600   timer.Start();
1601 #endif
1602   VISU_Actor *anActor = pPresent->CreateActor();
1603   if (! anActor ) return;
1604 #ifdef CHECKTIME
1605   timer.Stop();
1606   MESSAGE("Check time on VisuGUI::CreateMesh - pPresent->CreateActor");
1607   timer.Show();
1608 #endif
1609   if(VTKViewer_ViewFrame* vf = GetVtkViewFrame()){
1610     vtkRenderer *aRenderer = vf->getRenderer();
1611     //visuGUI->ClearViewer(QAD_Application::getDesktop(), aRenderer, -1);
1612     //visuGUI->ShowTrihedron(true);
1613 #ifdef CHECKTIME
1614     OSD_Timer timer;
1615     timer.Start();
1616 #endif
1617     vf->AddActor(anActor);
1618     vf->getRenderer()->AddActor(anActor->EdgeDevice);
1619     vf->getRenderer()->ResetCameraClippingRange();
1620     vf->onViewFitAll();
1621 #ifdef CHECKTIME
1622     timer.Stop();
1623     MESSAGE("Check time on VisuGUI::CreateMesh - vf->AddActor + vf->onViewFitAll");
1624     timer.Show();
1625 #endif
1626   }
1627   myActiveStudy->updateObjBrowser(); //update Object browser
1628   myDesktop->putInfo("Ready");
1629 }
1630
1631
1632 //=====================================================================================
1633 // function : ChangeRepresentation()
1634 // purpose  :
1635 //=====================================================================================
1636
1637 static void ShrinkMesh(VISU_Actor *Actor){
1638   if (!(Actor->IsShrunk)){
1639     vtkDataSetMapper *mapper = (vtkDataSetMapper*) (Actor->GetMapper());
1640     vtkShrinkFilter *shrink = vtkShrinkFilter::New();
1641     shrink->SetInput(mapper->GetInput());
1642     shrink->SetShrinkFactor(0.8);
1643     mapper->SetInput(shrink->GetOutput());
1644     Actor->IsShrunk = true;
1645     shrink->Delete();
1646     Actor->EdgeDevice->VisibilityOff();
1647   }else{
1648     vtkDataSetMapper *mapper = (vtkDataSetMapper*) (Actor->GetMapper());
1649     // mpv: we wish to remove shrink filter only instead of all filters ignore
1650 //     mapper->SetInput(Actor->DataSource);
1651     vtkDataObject* anObject = mapper->GetInput();
1652     vtkSource* aPrevSource = (vtkSource*)mapper;
1653     while(anObject != Actor->DataSource) {
1654       vtkShrinkFilter* aShrink = vtkShrinkFilter::SafeDownCast(anObject->GetSource());
1655       if (aShrink) {
1656         vtkSource* aSource = aShrink->GetInput()->GetSource();
1657         vtkDataObject** Inputs = aPrevSource->GetInputs();
1658         vtkDataObject** Outputs = aSource->GetOutputs();
1659         Outputs[0]->UnRegister(aShrink);
1660         Inputs[0]->UnRegister(aShrink);
1661         Outputs[0]->Register(aPrevSource);
1662         Inputs[0]->Register(aSource);
1663         Inputs[0] = aSource->GetOutputs()[0];
1664         aSource->Modified();
1665         aSource->Update();
1666
1667         mapper->Update();
1668         break;
1669       }
1670       aPrevSource = anObject->GetSource();
1671       anObject = aPrevSource->GetInputs()[0];
1672     }
1673     
1674
1675     Actor->IsShrunk = false;
1676     if ( Actor->GetProperty()->GetRepresentation() == 2 )
1677       Actor->EdgeDevice->VisibilityOn();
1678   }
1679 }
1680
1681 void VisuGUI::ChangeRepresentation(RepresentType theType) {
1682   VISU::Prs3d_i* aPrsObject = GetSelectedPrs();
1683   if(!aPrsObject) return;
1684
1685 #ifdef CHECKTIME
1686   OSD_Timer timer;
1687   timer.Start();
1688 #endif
1689   VISU_Actor* anActor = GetActor(aPrsObject);  
1690   if (!anActor) return;
1691   switch (theType) {
1692   case POINTS:
1693     anActor->EdgeDevice->VisibilityOff();
1694     anActor->GetProperty()->SetRepresentation(0);
1695     anActor->GetProperty()->SetPointSize(VISU_POINT_SIZE);
1696     break;
1697   case WIREFRAME:
1698     anActor->EdgeDevice->VisibilityOff();
1699     anActor->GetProperty()->SetRepresentation(1);
1700     break;
1701   case SURFACE:
1702     if ( !anActor->IsShrunk )
1703       anActor->EdgeDevice->VisibilityOn();
1704     anActor->GetProperty()->SetRepresentation(2);
1705     break;
1706   case SHRINK:
1707     ShrinkMesh(anActor);
1708     break;
1709   }
1710   VTKViewer_ViewFrame* vf = GetVtkViewFrame();
1711   if (vf) 
1712     vf->Repaint();
1713 #ifdef CHECKTIME
1714   timer.Stop();
1715   MESSAGE("Cheking time in VisuGUI::ChangeRepresentation - anActor->GetProperty()->SetRepresentation + vf->Repaint");
1716   timer.Show();
1717 #endif
1718 }
1719
1720 void VisuGUI::MakeWireframe() {
1721   ChangeRepresentation(WIREFRAME);
1722 }
1723
1724
1725 void VisuGUI::MakeSurface() {
1726   ChangeRepresentation(SURFACE);
1727 }
1728
1729
1730 void VisuGUI::MakePoints() {
1731   ChangeRepresentation(POINTS);
1732 }
1733
1734
1735 void VisuGUI::MakeShrink() {
1736   ChangeRepresentation(SHRINK);
1737 }
1738
1739
1740
1741 //=====================================================================================
1742 // functions : Change Propertise
1743 // purpose  :
1744 //=====================================================================================
1745 VISU::Prs3d_i* VisuGUI::GetSelectedPrs() {
1746   string aComment;
1747   Handle(SALOME_InteractiveObject) anIO;
1748   CORBA::Object_var anObject = GetSelectedObj(aComment, anIO, myActiveStudy);
1749   return dynamic_cast<VISU::Prs3d_i*>(VISU::GetServant(anObject));
1750 }
1751
1752 void VisuGUI::ChageColor() {
1753   VISU::Prs3d_i* aPrsObject = GetSelectedPrs();
1754   if(!aPrsObject) return;
1755
1756   VISU_Actor* anActor = GetActor(aPrsObject);  
1757   if (!anActor) return;
1758   NewColor(anActor);
1759 }
1760
1761 void VisuGUI::ChangeOutlineColor() {
1762   VISU::Prs3d_i* aPrsObject = GetSelectedPrs();
1763   if(!aPrsObject) return;
1764
1765   VISU_Actor* anActor = GetActor(aPrsObject);  
1766   if (!anActor) return;
1767   NewOutlineColor(anActor);
1768 }
1769
1770
1771 void VisuGUI::ChangeOpacity() {
1772   VISU::Prs3d_i* aPrsObject = GetSelectedPrs();
1773   if(!aPrsObject) return;
1774
1775   VISU_Actor* anActor = GetActor(aPrsObject);  
1776   if (!anActor) return;
1777   NewOpacity(anActor);
1778 }
1779
1780
1781 void VisuGUI::ChangeLines() {
1782   VISU::Prs3d_i* aPrsObject = GetSelectedPrs();
1783   if(!aPrsObject) return;
1784
1785   VISU_Actor* anActor = GetActor(aPrsObject);  
1786   if (!anActor) return;
1787   NewLinewidth(anActor);
1788 }
1789 void VisuGUI::PlotTable( VISU::Table_i* table, int theDisplaying )
1790 {
1791   VisuGUI::GetOrCreateVisuGUI( QAD_Application::getDesktop() );
1792   if ( table && visuGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_PLOT2D ) {
1793     Plot2d_ViewFrame* aPlot = (Plot2d_ViewFrame*)visuGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame();
1794     if ( theDisplaying == VISU::eDisplayOnly ) 
1795       aPlot->EraseAll();
1796     QList<Plot2d_Curve> clist;
1797     aPlot->getCurves( clist );
1798     SALOMEDS::SObject_var TableSO = visuGUI->myActiveStudy->getStudyDocument()->FindObjectID( table->GetEntry() );
1799     if ( !TableSO->_is_nil() ) {
1800       SALOMEDS::ChildIterator_var Iter = visuGUI->myActiveStudy->getStudyDocument()->NewChildIterator( TableSO );
1801       for ( ; Iter->More(); Iter->Next() ) {
1802         CORBA::Object_var childObject = VISU::SObjectToObject( Iter->Value() );
1803         if( !CORBA::is_nil( childObject ) ) {
1804           CORBA::Object_ptr aCurve = VISU::Curve::_narrow( childObject );
1805           if( !CORBA::is_nil( aCurve ) ) {
1806             VISU::Curve_i* theCurve = dynamic_cast<VISU::Curve_i*>( VISU::GetServant( aCurve ) );
1807             Plot2d_Curve* plotCurve = 0;
1808             for ( int i = 0; i < clist.count(); i++ ) {
1809               if ( clist.at( i )->hasIO() && !strcmp( clist.at( i )->getIO()->getEntry(), theCurve->GetEntry() ) ) {
1810                 plotCurve = clist.at( i );
1811                 break;
1812               }
1813             }
1814             if ( theDisplaying == VISU::eErase ) {
1815               if ( plotCurve ) {
1816                 aPlot->eraseCurve( plotCurve, false );
1817                 clist.remove( plotCurve );
1818               }
1819             }
1820             else if ( theDisplaying == VISU::eDisplay || theDisplaying == VISU::eDisplayOnly ) {
1821               if ( plotCurve ) {
1822                 plotCurve->setHorTitle( strdup( theCurve->GetHorTitle().c_str() ) );
1823                 //plotCurve->setVerTitle( strdup( theCurve->GetVerTitle().c_str() ) );
1824                 plotCurve->setVerTitle( strdup( theCurve->GetName() ) );
1825                 plotCurve->setHorUnits( strdup( theCurve->GetHorUnits().c_str() ) );
1826                 plotCurve->setVerUnits( strdup( theCurve->GetVerUnits().c_str() ) );
1827                 /* - DATA NOT UPDATED */
1828                 if ( !plotCurve->isAutoAssign() ) {
1829                   plotCurve->setLine( (Plot2d_Curve::LineType)theCurve->GetLine(), theCurve->GetLineWidth() );
1830                   plotCurve->setMarker( (Plot2d_Curve::MarkerType)theCurve->GetMarker() ); 
1831                   SALOMEDS::Color color = theCurve->GetColor();
1832                   plotCurve->setColor( QColor( (int)(color.R*255.), (int)(color.G*255.), (int)(color.B*255.) ) );
1833                   plotCurve->setAutoAssign( theCurve->IsAuto() );
1834                 }
1835                 aPlot->displayCurve( plotCurve, false );
1836               }
1837               else {
1838                 Plot2d_Curve* crv = theCurve->CreatePresentation();
1839                 if ( crv )
1840                   aPlot->displayCurve( crv, false );
1841               }
1842             }
1843           }
1844         }
1845       }
1846       aPlot->Repaint();
1847     }
1848   }
1849 }
1850 void VisuGUI::PlotCurve( VISU::Curve_i* theCurve, int theDisplaying )
1851 {
1852   VisuGUI::GetOrCreateVisuGUI( QAD_Application::getDesktop() );
1853   if ( theCurve && visuGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_PLOT2D ) {
1854     Plot2d_ViewFrame* aPlot = (Plot2d_ViewFrame*)visuGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame();
1855 //  if ( theDisplaying == VISU::eDisplayOnly ) 
1856 //    aPlot->EraseAll();
1857     QList<Plot2d_Curve> clist;
1858     aPlot->getCurves( clist );
1859     Plot2d_Curve* plotCurve = 0;
1860     for ( int i = 0; i < clist.count(); i++ ) {
1861       if ( clist.at( i )->hasIO() && !strcmp( clist.at( i )->getIO()->getEntry(), theCurve->GetEntry() ) ) {
1862         plotCurve = clist.at( i );
1863       }
1864       else if ( theDisplaying == VISU::eDisplayOnly ) {
1865         aPlot->eraseCurve( clist.at( i ) );
1866       }
1867     }
1868     if ( theDisplaying == VISU::eErase ) {
1869       if ( plotCurve )
1870         aPlot->eraseCurve( plotCurve, false );
1871     }
1872     else if ( theDisplaying == VISU::eDisplay || theDisplaying == VISU::eDisplayOnly ) {
1873       if ( plotCurve ) {
1874         plotCurve->setHorTitle( strdup( theCurve->GetHorTitle().c_str() ) );
1875         //plotCurve->setVerTitle( strdup( theCurve->GetVerTitle().c_str() ) );
1876         plotCurve->setVerTitle( strdup( theCurve->GetName() ) );
1877         plotCurve->setHorUnits( strdup( theCurve->GetHorUnits().c_str() ) );
1878         plotCurve->setVerUnits( strdup( theCurve->GetVerUnits().c_str() ) );
1879         /* DATA NOT UPDATED */
1880         if ( !plotCurve->isAutoAssign() ) {
1881           plotCurve->setLine( (Plot2d_Curve::LineType)theCurve->GetLine(), theCurve->GetLineWidth() );
1882           plotCurve->setMarker( (Plot2d_Curve::MarkerType)theCurve->GetMarker() ); 
1883           SALOMEDS::Color color = theCurve->GetColor();
1884           plotCurve->setColor( QColor( (int)(color.R*255.), (int)(color.G*255.), (int)(color.B*255.) ) );
1885           plotCurve->setAutoAssign( theCurve->IsAuto() );
1886         }
1887         aPlot->displayCurve( plotCurve, false );
1888       }
1889       else {
1890         Plot2d_Curve* crv = theCurve->CreatePresentation();
1891         if ( crv ) {
1892           aPlot->displayCurve( crv, false );
1893         }
1894       }
1895     }
1896     aPlot->Repaint();
1897   }
1898 }
1899 void VisuGUI::PlotContainer( VISU::Container_i* container, int theDisplaying )
1900 {
1901   VisuGUI::GetOrCreateVisuGUI( QAD_Application::getDesktop() );
1902   if ( container && visuGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_PLOT2D ) {
1903     Plot2d_ViewFrame* aPlot = (Plot2d_ViewFrame*)visuGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame();
1904     if ( theDisplaying == VISU::eDisplayOnly ) 
1905       aPlot->EraseAll();
1906     QList<Plot2d_Curve> clist;
1907     aPlot->getCurves( clist );
1908     if ( container->GetNbCurves() > 0 ) {
1909       int nbCurves = container->GetNbCurves();
1910       for ( int k = 1; k <= nbCurves; k++ ) {
1911         VISU::Curve_i* theCurve = container->GetCurve( k );
1912         if ( theCurve && theCurve->IsValid() ) {
1913           Plot2d_Curve* plotCurve = aPlot->getCurveByIO( new SALOME_InteractiveObject( strdup(theCurve->GetEntry()), "", "" ) );
1914 //        for ( int i = 0; i < clist.count(); i++ ) {
1915 //          if ( clist.at( i )->hasIO() && !strcmp( clist.at( i )->getIO()->getEntry(), theCurve->GetEntry() ) ) {
1916 //            plotCurve = clist.at( i );
1917 //            break;
1918 //          }
1919 //        }
1920           if ( theDisplaying == VISU::eErase ) {
1921             if ( plotCurve ) {
1922               aPlot->eraseCurve( plotCurve, false );
1923               clist.remove( plotCurve );
1924             }
1925           }
1926           else if ( theDisplaying == VISU::eDisplay || theDisplaying == VISU::eDisplayOnly ) {
1927             if ( plotCurve ) {
1928               plotCurve->setHorTitle( strdup( theCurve->GetHorTitle().c_str() ) );
1929               //plotCurve->setVerTitle( strdup( theCurve->GetVerTitle().c_str() ) );
1930               plotCurve->setVerTitle( strdup( theCurve->GetName() ) );
1931               plotCurve->setHorUnits( strdup( theCurve->GetHorUnits().c_str() ) );
1932               plotCurve->setVerUnits( strdup( theCurve->GetVerUnits().c_str() ) );
1933               /* - DATA NOT UPDATED */
1934               if ( !plotCurve->isAutoAssign() ) {
1935                 plotCurve->setLine( (Plot2d_Curve::LineType)theCurve->GetLine(), theCurve->GetLineWidth() );
1936                 plotCurve->setMarker( (Plot2d_Curve::MarkerType)theCurve->GetMarker() ); 
1937                 SALOMEDS::Color color = theCurve->GetColor();
1938                 plotCurve->setColor( QColor( (int)(color.R*255.), (int)(color.G*255.), (int)(color.B*255.) ) );
1939                 plotCurve->setAutoAssign( theCurve->IsAuto() );
1940               }
1941               aPlot->displayCurve( plotCurve, false );
1942             }
1943             else {
1944               Plot2d_Curve* crv = theCurve->CreatePresentation();
1945               if ( crv )
1946                 aPlot->displayCurve( crv, false );
1947             }
1948           }
1949         }
1950       }
1951     }
1952     aPlot->Repaint();
1953   }
1954 }
1955 /*!
1956   Slot : opens Table view : for Table object or SObject with table attribute selected
1957 */
1958 void VisuGUI::ShowTable() {
1959   VisuGUI::GetOrCreateVisuGUI( QAD_Application::getDesktop() );
1960   SALOME_Selection* Sel = SALOME_Selection::Selection( VisuGUI::myActiveStudy->getSelection() );
1961   if( Sel->IObjectCount() !=1 )
1962     return;
1963   string aComment;
1964   Handle(SALOME_InteractiveObject) anIO;    
1965   CORBA::Object_var anObject = GetSelectedObj( aComment, anIO, VisuGUI::myActiveStudy );
1966   SALOMEDS::SObject_var SO;
1967   if ( !CORBA::is_nil( anObject ) ) {
1968     VISU::Base_var aVisuObj = VISU::Base::_narrow(anObject);
1969     if ( !CORBA::is_nil( aVisuObj ) && aVisuObj->GetType() == VISU::TTABLE ) {
1970       CORBA::Object_ptr aTable = VISU::Table::_narrow( anObject );
1971       if( !CORBA::is_nil( aTable ) ) {
1972         VISU::Table_i* table = dynamic_cast<VISU::Table_i*>( VISU::GetServant( aTable ) );
1973         if ( table ) {
1974           SO = VisuGUI::myActiveStudy->getStudyDocument()->FindObjectID( table->GetObjectEntry() );
1975         }
1976       }
1977     } 
1978   } else {
1979     // possibly this is Table SObject
1980     SO = VisuGUI::myActiveStudy->getStudyDocument()->FindObjectID( anIO->getEntry() );
1981   }
1982   SALOMEDS::GenericAttribute_var anAttr;
1983   if ( SO->_is_nil() || ( !SO->FindAttribute( anAttr, "AttributeTableOfInteger" ) 
1984                        && !SO->FindAttribute( anAttr, "AttributeTableOfReal" ) ) ) 
1985     return;
1986   SALOMEGUI_TableDlg* dlg = new SALOMEGUI_TableDlg( QAD_Application::getDesktop(),
1987                                                     SO, 
1988                                                     false );
1989   dlg->show();
1990 }
1991 /*!
1992   Opens dialog box for curves creation. Acts only for selected SObject with table attribute.
1993 */
1994 void VisuGUI::PlotData() {
1995   VisuGUI::GetOrCreateVisuGUI( QAD_Application::getDesktop() );
1996   SALOME_Selection* Sel = SALOME_Selection::Selection( VisuGUI::myActiveStudy->getSelection() );
1997   if( Sel->IObjectCount() !=1 )
1998     return;
1999   string aComment;
2000   Handle(SALOME_InteractiveObject) anIO;    
2001   CORBA::Object_var anObject = GetSelectedObj( aComment, anIO, VisuGUI::myActiveStudy );
2002   SALOMEDS::SObject_var SO;
2003   if ( !CORBA::is_nil( anObject ) ) {
2004     VISU::Base_var aVisuObj = VISU::Base::_narrow(anObject);
2005     if (!CORBA::is_nil(aVisuObj) && aVisuObj->GetType() == VISU::TTABLE) {
2006       // Table (VISU object) is selected
2007       CORBA::Object_ptr aTbl = VISU::Table::_narrow( anObject );
2008       if( !CORBA::is_nil( aTbl ) ) {
2009         VISU::Table_i* table = dynamic_cast<VISU::Table_i*>( VISU::GetServant( aTbl ) );
2010         if ( table ) {
2011           SALOMEDS::GenericAttribute_var anAttr;
2012           SALOMEDS::AttributeName_var    aName;
2013           QString SOName;
2014           SALOMEDS::SObject_var SO = VisuGUI::myActiveStudy->getStudyDocument()->FindObjectID( table->GetObjectEntry() );
2015           if ( !SO->_is_nil() && ( SO->FindAttribute( anAttr, "AttributeTableOfInteger" ) ||
2016                                    SO->FindAttribute( anAttr, "AttributeTableOfReal" ) ) ) {
2017             // get name of SObject
2018             if ( SO->FindAttribute( anAttr, "AttributeName" ) ) {
2019               aName = SALOMEDS::AttributeName::_narrow( anAttr );
2020               SOName = strdup( aName->Value() );
2021             }
2022             Plot2d_SetupPlot2dDlg* dlg = new Plot2d_SetupPlot2dDlg( SO, QAD_Application::getDesktop() );
2023             if ( dlg->exec() == QDialog::Accepted ) {
2024               if ( !isStudyLocked( visuGUI->myActiveStudy->getStudyDocument() ) ) {
2025                 // if study is not locked - create new container, create curves
2026                 // and insert them into container, then plot container if current viewer is of VIEW_PLOT2D type
2027                 int horIndex;
2028                 QValueList<int> verIndices;
2029                 dlg->getCurvesSource( horIndex, verIndices );
2030                 if ( horIndex >= 0 && verIndices.count() > 0 ) { 
2031                   CORBA::Object_var aContainer = myComponent->CreateContainer();
2032                   if( !CORBA::is_nil( aContainer ) ) {
2033                     VISU::Container_i* pContainer = dynamic_cast<VISU::Container_i*>( VISU::GetServant( aContainer ) );
2034                     if ( pContainer ) {
2035                       for ( int i = 0; i < verIndices.count(); i++ ) {
2036                         CORBA::Object_var aNewCurve = myComponent->CreateCurve( table->_this(), horIndex+1, verIndices[i]+1 );
2037                         if( !CORBA::is_nil( aNewCurve ) ) {
2038                           VISU::Curve_i* pCrv = dynamic_cast<VISU::Curve_i*>( VISU::GetServant( aNewCurve ) );
2039                           if ( pCrv ) {
2040                             bool isAuto;
2041                             int  marker, line, lineWidth;
2042                             QColor color;
2043                             if ( dlg->getCurveAttributes( verIndices[i], isAuto, marker, line, lineWidth, color ) && !isAuto ) {
2044                               SALOMEDS::Color c; c.R = color.red()/255.; c.G = color.green()/255.; c.B = color.blue()/255.;
2045                               pCrv->SetColor( c );
2046                               pCrv->SetMarker( ( VISU::Curve::MarkerType )marker );
2047                               pCrv->SetLine( ( VISU::Curve::LineType )line, lineWidth );
2048                             }
2049                             pContainer->AddCurve( pCrv->_this() );
2050                           }
2051                         }
2052                       }
2053                       VisuGUI::myActiveStudy->updateObjBrowser( true );
2054                       PlotContainer( pContainer, VISU::eDisplay );
2055                     }
2056                   }
2057                 }
2058               }
2059               else {
2060                 // if study is locked just get curves info and plot them if current viewer is of VIEW_PLOT2D type
2061                 Plot2d_CurveContainer container;
2062                 dlg->getCurves( container );
2063                 if ( !container.isEmpty() ) {
2064                   ((Plot2d_ViewFrame*)(visuGUI->myActiveStudy->getActiveStudyFrame()->
2065                                        getRightFrame()->getViewFrame()))->displayCurves( container, true );
2066                   ((Plot2d_ViewFrame*)(visuGUI->myActiveStudy->getActiveStudyFrame()->
2067                                        getRightFrame()->getViewFrame()))->setTitle( SOName );
2068                 }
2069               }
2070             }
2071             delete dlg;
2072           }
2073         }
2074       }
2075     }
2076   }
2077   else {
2078     // possibly this is Table SObject
2079     SALOMEDS::GenericAttribute_var anAttr;
2080     SALOMEDS::AttributeName_var    aName;
2081     QString SOName;
2082       
2083     // check if Table SObject is selected
2084     SALOMEDS::SObject_var SO = VisuGUI::myActiveStudy->getStudyDocument()->FindObjectID( Sel->firstIObject()->getEntry() );
2085     if ( !SO->_is_nil() && ( SO->FindAttribute( anAttr, "AttributeTableOfInteger" ) ||
2086                              SO->FindAttribute( anAttr, "AttributeTableOfReal" ) ) ) {
2087       // get name of SObject
2088       if ( SO->FindAttribute( anAttr, "AttributeName" ) ) {
2089         aName = SALOMEDS::AttributeName::_narrow( anAttr );
2090         SOName = strdup( aName->Value() );
2091       }
2092       Plot2d_SetupPlot2dDlg* dlg = new Plot2d_SetupPlot2dDlg( SO, QAD_Application::getDesktop() );
2093       if ( dlg->exec() == QDialog::Accepted ) {
2094         if ( !isStudyLocked( visuGUI->myActiveStudy->getStudyDocument() ) ) {
2095           // if study is not locked - create new table and container objects, create curves
2096           // and insert them into container, then plot container if current viewer is of VIEW_PLOT2D type
2097           int horIndex;
2098           QValueList<int> verIndices;
2099           dlg->getCurvesSource( horIndex, verIndices );
2100           if ( horIndex >= 0 && verIndices.count() > 0 ) { 
2101             CORBA::Object_var aTable = myComponent->CreateTable( SO->GetID() );
2102             CORBA::Object_var aContainer = myComponent->CreateContainer();
2103             if ( !CORBA::is_nil( aTable ) && !CORBA::is_nil( aContainer ) ) {
2104               VISU::Table_i*     pTable     = dynamic_cast<VISU::Table_i*>( VISU::GetServant( aTable ) );
2105               VISU::Container_i* pContainer = dynamic_cast<VISU::Container_i*>( VISU::GetServant( aContainer ) );
2106             
2107               if ( pContainer && pTable ) {
2108                 for ( int i = 0; i < verIndices.count(); i++ ) {
2109                   CORBA::Object_var aNewCurve = myComponent->CreateCurve( pTable->_this(), horIndex+1, verIndices[i]+1 );
2110                   if( !CORBA::is_nil( aNewCurve ) ) {
2111                     VISU::Curve_i* pCrv = dynamic_cast<VISU::Curve_i*>( VISU::GetServant( aNewCurve ) );
2112                     if ( pCrv ) {
2113                       bool isAuto;
2114                       int  marker, line, lineWidth;
2115                       QColor color;
2116                       if ( dlg->getCurveAttributes( verIndices[i], isAuto, marker, line, lineWidth, color ) && !isAuto ) {
2117                         SALOMEDS::Color c; c.R = color.red()/255.; c.G = color.green()/255.; c.B = color.blue()/255.;
2118                         pCrv->SetColor( c );
2119                         pCrv->SetMarker( ( VISU::Curve::MarkerType )marker );
2120                         pCrv->SetLine( ( VISU::Curve::LineType )line, lineWidth );
2121                       }
2122                       pContainer->AddCurve( pCrv->_this() );
2123                     }
2124                   }
2125                 }
2126                 VisuGUI::myActiveStudy->updateObjBrowser( true );
2127                 PlotContainer( pContainer, VISU::eDisplay );
2128               }
2129             }
2130           }
2131         }
2132         else {
2133           // if study is locked just get curves info and plot them if current viewer is of VIEW_PLOT2D type
2134           if ( visuGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_PLOT2D ) {
2135             Plot2d_CurveContainer container;
2136             dlg->getCurves( container );
2137             if ( !container.isEmpty() ) {
2138               ((Plot2d_ViewFrame*)(visuGUI->myActiveStudy->getActiveStudyFrame()->
2139                                    getRightFrame()->getViewFrame()))->displayCurves( container, true );
2140               ((Plot2d_ViewFrame*)(visuGUI->myActiveStudy->getActiveStudyFrame()->
2141                                    getRightFrame()->getViewFrame()))->setTitle( SOName );
2142             }
2143           }
2144         }
2145       }
2146       delete dlg;
2147     }
2148   }
2149 }
2150 /*!
2151   Slot : Opens "Setup curve" dialog to set curve properties : for Curve object selected
2152 */
2153 void VisuGUI::CurveProperties() {
2154   VisuGUI::GetOrCreateVisuGUI( QAD_Application::getDesktop() );
2155   SALOME_Selection* Sel = SALOME_Selection::Selection( VisuGUI::myActiveStudy->getSelection() );
2156   if( Sel->IObjectCount() !=1 )
2157     return;
2158   string aComment;
2159   Handle(SALOME_InteractiveObject) anIO;    
2160   CORBA::Object_var anObject = GetSelectedObj( aComment, anIO, VisuGUI::myActiveStudy );
2161   SALOMEDS::SObject_var SO;
2162   if (CORBA::is_nil( anObject )) return;
2163
2164   VISU::Base_var aVisuObj = VISU::Base::_narrow(anObject);
2165   if (!CORBA::is_nil(aVisuObj) && aVisuObj->GetType() == VISU::TCURVE) {
2166     // Curve object
2167     CORBA::Object_ptr aCurve = VISU::Curve::_narrow( anObject );
2168     if( !CORBA::is_nil( aCurve ) ) {
2169       VISU::Curve_i* curve = dynamic_cast<VISU::Curve_i*>( VISU::GetServant( aCurve ) );
2170       if ( curve && !isStudyLocked( visuGUI->myActiveStudy->getStudyDocument() ) ) {
2171         SALOMEGUI_SetupCurveDlg* dlg = new SALOMEGUI_SetupCurveDlg( QAD_Application::getDesktop() );    
2172         dlg->setLine( (int)curve->GetLine(), curve->GetLineWidth() );
2173         dlg->setMarker( (int)curve->GetMarker() );
2174         SALOMEDS::Color color = curve->GetColor();
2175         dlg->setColor( QColor( (int)(color.R*255.), (int)(color.G*255.), (int)(color.B*255.) ) );
2176         if( dlg->exec() == QDialog::Accepted ) {
2177           curve->SetLine( (VISU::Curve::LineType)dlg->getLine(), dlg->getLineWidth() );
2178           curve->SetMarker( (VISU::Curve::MarkerType)dlg->getMarker());
2179           SALOMEDS::Color newColor;
2180           newColor.R = dlg->getColor().red()/255.;
2181           newColor.G = dlg->getColor().green()/255.;
2182           newColor.B = dlg->getColor().blue()/255.;
2183           curve->SetColor( newColor );
2184           QList<QAD_StudyFrame> sfList = VisuGUI::myActiveStudy->getStudyFrames();
2185           if ( sfList.count() > 0 ) {
2186             QListIterator<QAD_StudyFrame> it( sfList );
2187             for ( ; it.current(); ++it ) {
2188               if ( it.current()->getTypeView() == VIEW_PLOT2D ) {
2189                 Plot2d_ViewFrame* aPlot = (Plot2d_ViewFrame*)it.current()->getRightFrame()->getViewFrame();
2190                 Handle(SALOME_InteractiveObject) IO = aPlot->FindIObject( curve->GetEntry() );
2191                 if ( IO.IsNull() )
2192                   continue;
2193                 Plot2d_Curve* plotCurve = aPlot->getCurveByIO( IO );
2194                 if ( plotCurve ) {
2195                   plotCurve->setLine( (Plot2d_Curve::LineType)dlg->getLine(), dlg->getLineWidth() );
2196                   plotCurve->setMarker( (Plot2d_Curve::MarkerType)dlg->getMarker() );
2197                   plotCurve->setColor( dlg->getColor() );
2198                   aPlot->updateCurve( plotCurve, true );
2199                 }
2200               }
2201             }
2202           }
2203         }
2204       } 
2205     }
2206   }
2207 }
2208
2209
2210 /*!
2211   Slot : Clears container contents : for Container object selected
2212 */
2213 void VisuGUI::ClearContainer() {
2214   VisuGUI::GetOrCreateVisuGUI( QAD_Application::getDesktop() );
2215   SALOME_Selection* Sel = SALOME_Selection::Selection( VisuGUI::myActiveStudy->getSelection() );
2216   if( Sel->IObjectCount() !=1 )
2217     return;
2218   
2219   string aComment;
2220   Handle(SALOME_InteractiveObject) anIO;    
2221   CORBA::Object_var anObject = GetSelectedObj( aComment, anIO, VisuGUI::myActiveStudy );
2222   SALOMEDS::SObject_var SO;
2223   if (CORBA::is_nil( anObject )) return;
2224
2225   VISU::Base_var aVisuObj = VISU::Base::_narrow(anObject);
2226   if (!CORBA::is_nil(aVisuObj) && aVisuObj->GetType() == VISU::TCONTAINER) {
2227     // Container object
2228     CORBA::Object_ptr aCnt = VISU::Container::_narrow( anObject );
2229     if( !CORBA::is_nil( aCnt ) ) {
2230       VISU::Container_i* container = dynamic_cast<VISU::Container_i*>( VISU::GetServant( aCnt ) );
2231       if ( container && container->GetNbCurves() > 0 && !isStudyLocked( visuGUI->myActiveStudy->getStudyDocument() ) ) {
2232         container->Clear();
2233         VisuGUI::myActiveStudy->updateObjBrowser();
2234       }
2235     }
2236   }
2237 }
2238
2239
2240 void VisuGUI::DeletePrs() {
2241   DeletePresentation(GetSelectedPrs());
2242 }
2243
2244 void VisuGUI::SaveViewParams()
2245 {
2246   if (checkLock(myStudy)) return;
2247   VisuGUI::GetOrCreateVisuGUI( QAD_Application::getDesktop() );
2248   SALOME_Selection* Sel = SALOME_Selection::Selection( VisuGUI::myActiveStudy->getSelection() );
2249   if ( Sel->IObjectCount() > 1 || VisuGUI::myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK ) 
2250     return;
2251   // getting view manager
2252   CORBA::Object_var aVM = VisuGUI::myComponent->GetViewManager();
2253   if( CORBA::is_nil( aVM ) )
2254     return;
2255   VISU::ViewManager_i* pVM = dynamic_cast<VISU::ViewManager_i*>( VISU::GetServant( aVM ) );
2256   if ( !pVM )
2257     return;
2258   // getting current 3d view
2259   CORBA::Object_var aView = pVM->GetCurrentView();
2260   if( CORBA::is_nil( aView ) )
2261     return;
2262   VISU::View3D_i* pView = dynamic_cast<VISU::View3D_i*>( VISU::GetServant( aView ) );
2263   if ( !pView )
2264     return;
2265   if ( Sel->IObjectCount()  == 0 ) {
2266     // Save view parameters by new name
2267     pView->SaveViewParams( 0 );
2268     VisuGUI::myActiveStudy->updateObjBrowser( true );
2269   }
2270   else {
2271     // Try to save view parameters by selected object's name
2272     string aComment;
2273     Handle(SALOME_InteractiveObject) anIO;    
2274     CORBA::Object_var anObject = GetSelectedObj( aComment, anIO, VisuGUI::myActiveStudy );
2275 //    QString strIn( aComment.c_str() );
2276 //    VISU::Storable::RestoringMapType aMap;
2277 //    VISU::Storable::StrToMap( strIn,aMap );
2278 //    QString aCmt = VISU::Storable::FindValue( aMap, "myComment" );
2279     if (ObjectTypes.find( aComment.c_str() ) == 6 ) {
2280       pView->SaveViewParams( anIO->getName() );
2281       VisuGUI::myActiveStudy->updateObjBrowser( true );
2282     }
2283   }
2284 }
2285 void VisuGUI::RestoreViewParams()
2286 {
2287   VisuGUI::GetOrCreateVisuGUI( QAD_Application::getDesktop() );
2288   SALOME_Selection* Sel = SALOME_Selection::Selection( VisuGUI::myActiveStudy->getSelection() );
2289   if ( Sel->IObjectCount() > 1 || VisuGUI::myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK ) 
2290     return;
2291   // getting view manager
2292   CORBA::Object_var aVM = VisuGUI::myComponent->GetViewManager();
2293   if( CORBA::is_nil( aVM ) )
2294     return;
2295   VISU::ViewManager_i* pVM = dynamic_cast<VISU::ViewManager_i*>( VISU::GetServant( aVM ) );
2296   if ( !pVM )
2297     return;
2298   // getting current 3d view
2299   CORBA::Object_var aView = pVM->GetCurrentView();
2300   if( CORBA::is_nil( aView ) )
2301     return;
2302   VISU::View3D_i* pView = dynamic_cast<VISU::View3D_i*>( VISU::GetServant( aView ) );
2303   if ( !pView )
2304     return;
2305   string aComment;
2306   Handle(SALOME_InteractiveObject) anIO;    
2307   CORBA::Object_var anObject = GetSelectedObj( aComment, anIO, VisuGUI::myActiveStudy );
2308   QString aCmt = aComment.c_str();
2309   if ( !aCmt.isEmpty() && ObjectTypes.find( aCmt ) == 6 ) {
2310     pView->RestoreViewParams( anIO->getName() );
2311   }
2312 }
2313
2314 //=====================================================================================
2315 // function : DeleteViewParams()
2316 // purpose  :
2317 //=====================================================================================
2318 void VisuGUI::DeleteViewParams() {
2319   VisuGUI::GetOrCreateVisuGUI( QAD_Application::getDesktop() );
2320   SALOME_Selection* Sel = SALOME_Selection::Selection(VisuGUI::myActiveStudy->getSelection());
2321   if( Sel->IObjectCount() > 0 ) {
2322     SALOME_ListIteratorOfListIO aSelectionIterator(Sel->StoredIObjects());
2323     for(;aSelectionIterator.More(); aSelectionIterator.Next()) {
2324       Handle(SALOME_InteractiveObject) anIO = aSelectionIterator.Value();
2325       if (anIO->hasEntry()){
2326         SALOMEDS::SObject_var aSObject = MYStudyDocument->FindObjectID(anIO->getEntry());
2327         if(!aSObject->_is_nil()){
2328           SALOMEDS::GenericAttribute_var anAttr;
2329           if (aSObject->FindAttribute(anAttr, "AttributeComment")) {
2330             SALOMEDS::AttributeComment_var aComment = SALOMEDS::AttributeComment::_narrow(anAttr);
2331             int aType;
2332             // possibly this is view params
2333             QString strIn(aComment->Value());
2334             VISU::Storable::TRestoringMap aMap;
2335             VISU::Storable::StrToMap( strIn, aMap );
2336             QString aCmt;
2337             bool isExist;
2338             aCmt = VISU::Storable::FindValue( aMap, "myComment", &isExist );
2339             if ( isExist ) aType = ObjectTypes.find( aCmt );
2340             if (aType == 6) {
2341               MYStudyDocument->NewBuilder()->RemoveObject(aSObject);
2342               Sel->RemoveIObject(anIO, 0);
2343             }
2344           }
2345         }
2346       }
2347     }
2348   }
2349   VisuGUI::myActiveStudy->updateObjBrowser( true );
2350 }
2351
2352
2353 //=====================================================================================
2354 // function : Sweep()
2355 // purpose  :
2356 //=====================================================================================
2357 void VisuGUI::Sweep() {
2358   VISU::ScalarMap_i* aPrsObject = dynamic_cast<VISU::ScalarMap_i*>(GetSelectedPrs());
2359   if (!aPrsObject) return;
2360
2361   int aTemp=100000;
2362   QString aTempoStr = QAD_CONFIG->getSetting("Visu:SweepTempo");
2363   if ( !aTempoStr.isEmpty() )
2364     aTemp = int(1.E6*(aTempoStr.toFloat()));
2365
2366   int aCycles=1;
2367   QString aCyclesStr = QAD_CONFIG->getSetting("Visu:SweepCycles");
2368   if ( !aCyclesStr.isEmpty() )
2369     aCycles = aCyclesStr.toInt();
2370
2371   int aSteps=40;
2372   QString aStepsStr = QAD_CONFIG->getSetting("Visu:SweepSteps");
2373   if ( !aStepsStr.isEmpty() )
2374     aSteps = aStepsStr.toInt();
2375
2376   VISU_Actor* aActor = GetActor(aPrsObject);
2377   if (!aActor) return;
2378   
2379   if (!aActor->GetVisibility()) {
2380     aActor->VisibilityOn();
2381     if (aActor->HasScalarBar())
2382       aActor->getScalarBar()->VisibilityOn();
2383   }
2384   vtkDataSetMapper* aMapper = (vtkDataSetMapper*) aActor->GetMapper(); 
2385   VISU_LookupTable* aLookupTbl = (VISU_LookupTable*) aMapper->GetLookupTable();
2386
2387   QApplication::setOverrideCursor( Qt::waitCursor );
2388
2389   switch (aPrsObject->GetType()) {
2390   case VISU::TCUTPLANES: // Cut planes 42
2391   case VISU::TSCALARMAP: // ScalarMap 18
2392     for (int j=0 ; j<aCycles; j++) {
2393       for (int i=0 ; i<=aSteps; i++) {
2394         aLookupTbl->SetMapScale(float(i)/float(aSteps));
2395         RepaintCurrentView();
2396         usleep(aTemp);
2397       }
2398     }
2399     break;
2400
2401   case VISU::TDEFORMEDSHAPE: // Deformed Shape 28
2402     {
2403       VISU::DeformedShape_i* aDefPrs = dynamic_cast<VISU::DeformedShape_i*>(aPrsObject);
2404       if (aDefPrs) {
2405         float aScale = aDefPrs->GetScale();
2406         bool isColored = aDefPrs->isColored();
2407         
2408         vtkWarpVector* aWarp = vtkWarpVector::New();
2409         if((VISU::Entity)aDefPrs->GetField()->myEntity == VISU::CELL) {
2410           vtkCellDataToPointData *aFilter = vtkCellDataToPointData::New();
2411           aFilter->SetInput(aDefPrs->GetInput()->GetUnstructuredGridOutput());
2412           aFilter->PassCellDataOn();
2413           aWarp->SetInput(aFilter->GetUnstructuredGridOutput());
2414           aFilter->Delete();
2415         } else
2416           aWarp->SetInput(aDefPrs->GetInput()->GetUnstructuredGridOutput());
2417         for (int j=0 ; j<aCycles; j++) {
2418           for (int i=0 ; i<=aSteps; i++) {
2419             aWarp->SetScaleFactor(aScale*float(i)/float(aSteps));
2420             aMapper->SetInput(aWarp->GetOutput());
2421
2422             if (isColored)
2423               aLookupTbl->SetMapScale(float(i)/float(aSteps));
2424             RepaintCurrentView();
2425             usleep(aTemp);
2426           }
2427         }
2428         aWarp->Delete();
2429       }
2430     }
2431     break;
2432
2433   case VISU::TISOSURFACE: // Iso surfaces
2434     {
2435       VISU::IsoSurfaces_i* aIsoPrs = dynamic_cast<VISU::IsoSurfaces_i*>(aPrsObject);
2436       if (aIsoPrs) {
2437         int nbIso = aIsoPrs->GetNbSurfaces();
2438         if (nbIso <= 1) break;
2439         vtkContourFilter* aContourFilter = vtkContourFilter::New();
2440         if ((VISU::Entity)aIsoPrs->GetField()->myEntity == VISU::CELL) {
2441           vtkCellDataToPointData *aFilter = vtkCellDataToPointData::New();
2442           aFilter->SetInput(aIsoPrs->GetInput()->GetUnstructuredGridOutput());
2443           aFilter->PassCellDataOn();
2444           aContourFilter->SetInput(aFilter->GetOutput());
2445           aFilter->Delete();
2446         } else
2447           aContourFilter->SetInput(aIsoPrs->GetInput()->GetUnstructuredGridOutput());
2448         float aMul;
2449         for (int j=0 ; j<aCycles; j++){
2450           for (int i=0 ; i<aSteps; i++){
2451             aMul = float(i)/float(aSteps);
2452             aLookupTbl->SetMapScale(aMul);
2453             aContourFilter->GenerateValues(nbIso*(i+1)/aSteps,aIsoPrs->GetRangeMin(),aIsoPrs->GetRangeMax());
2454             aMapper->SetInput(aContourFilter->GetOutput());
2455             RepaintCurrentView();
2456             usleep(aTemp);
2457           }
2458         }
2459         aContourFilter->Delete();
2460       }
2461     }
2462     break;
2463   }
2464   QApplication::restoreOverrideCursor();
2465 }
2466
2467
2468
2469 void VisuGUI::TimeAnimation() {
2470   VisuGUI_TimeAnimationDlg* aAnimationDlg = new VisuGUI_TimeAnimationDlg(myStudy);
2471   SALOME_Selection* Sel = SALOME_Selection::Selection( VisuGUI::myActiveStudy->getSelection() );
2472   
2473   bool isDefined = false;
2474   long aNbTimes = 0;
2475   SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
2476   for (; It.More(); It.Next()) {
2477     SALOMEDS::SObject_var aSObject  = myStudy->FindObjectID( It.Value()->getEntry() ); 
2478     if (aSObject->_is_nil()) continue;
2479     if (getValue(aSObject, "myComment") == QString("FIELD")) {
2480       long aNumber = getValue(aSObject, "myNbTimeStamps").toLong();
2481       if (aNumber > 1) {
2482         if (!isDefined) {
2483           aNbTimes = aNumber;
2484           aAnimationDlg->addField(aSObject);
2485           isDefined = true;
2486         } else if (aNbTimes == aNumber) {
2487           aAnimationDlg->addField(aSObject);
2488         }
2489       }
2490     }
2491   }
2492   if (isDefined) aAnimationDlg->show();
2493   else delete aAnimationDlg;
2494 }
2495
2496
2497
2498 void VisuGUI::ImportMedField() {
2499   if (checkLock(myStudy)) return;
2500
2501   VisuGUI::GetOrCreateVisuGUI( QAD_Application::getDesktop() );
2502   SALOME_Selection* Sel = SALOME_Selection::Selection( VisuGUI::myActiveStudy->getSelection() );
2503   SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
2504   QApplication::setOverrideCursor( Qt::waitCursor );
2505   for(;It.More();It.Next()) {
2506     Handle(SALOME_InteractiveObject) anIO = It.Value();
2507     SALOMEDS::SObject_var aSObject = MYStudyDocument->FindObjectID(anIO->getEntry());
2508     if(!aSObject->_is_nil()){
2509       SALOMEDS::GenericAttribute_var anAttr;
2510       aSObject->FindAttribute(anAttr, "AttributeIOR");
2511       if(!anAttr->_is_nil()){
2512         SALOMEDS::AttributeIOR_var anIOR  = SALOMEDS::AttributeIOR::_narrow(anAttr);
2513         if(!anIOR->_is_nil()){
2514           CORBA::String_var aValue = anIOR->Value();
2515           if(strcmp(aValue,"") != 0){
2516             CORBA::ORB_var anORB = VISU::GetORB();
2517             CORBA::Object_var anObject = anORB->string_to_object(aValue);
2518             if ( !CORBA::is_nil( anObject ) ) {
2519               SALOME_MED::FIELD_ptr aField = SALOME_MED::FIELD::_narrow( anObject );
2520               if( !CORBA::is_nil( aField ) ) {
2521                 VisuGUI::myComponent->ImportMed( aField );
2522                 continue;
2523               }
2524               SALOME_MED::MESH_ptr aMesh = SALOME_MED::MESH::_narrow( anObject );
2525               if( !CORBA::is_nil( aMesh ) ) {
2526                 VisuGUI::myComponent->ImportMedMesh( aMesh );
2527                 continue;
2528               }
2529               SALOME_MED::SUPPORT_ptr aSupport = SALOME_MED::SUPPORT::_narrow( anObject );
2530               if( !CORBA::is_nil( aSupport ) ) {
2531                 VisuGUI::myComponent->ImportMedSupport( aSupport );
2532                 continue;
2533               }
2534             }
2535           }
2536         }
2537       }
2538     }
2539   }
2540   VisuGUI::myActiveStudy->updateObjBrowser( true );
2541   QApplication::restoreOverrideCursor();
2542 }
2543 /*
2544 void VisuGUI::ImportMedMesh() {
2545   VisuGUI::GetOrCreateVisuGUI( QAD_Application::getDesktop() );
2546   SALOME_Selection* Sel = SALOME_Selection::Selection( VisuGUI::myActiveStudy->getSelection() );
2547   if ( Sel->IObjectCount() != 1 )
2548     return;
2549   string aComment;
2550   Handle(SALOME_InteractiveObject) anIO;    
2551   CORBA::Object_var anObject = GetSelectedObj( aComment,anIO, VisuGUI::myActiveStudy);
2552   if ( !CORBA::is_nil( anObject ) ) {
2553     SALOME_MED::MESH_ptr aMesh = SALOME_MED::MESH::_narrow( anObject );
2554     if( !CORBA::is_nil( aMesh ) ) {
2555       VisuGUI::myComponent->ImportMedMesh( aMesh );
2556       VisuGUI::myActiveStudy->updateObjBrowser( true );
2557     }
2558     SALOME_MED::SUPPORT_ptr aSupport = SALOME_MED::SUPPORT::_narrow( anObject );
2559     if( !CORBA::is_nil( aSupport ) ) {
2560       VisuGUI::myComponent->ImportMedSupport( aSupport );
2561       VisuGUI::myActiveStudy->updateObjBrowser( true );
2562     }
2563   }
2564 }
2565 */
2566 //=====================================================================================
2567 // functions : Rename()
2568 // purpose  :
2569 //=====================================================================================
2570 void VisuGUI::Rename() {
2571   if (checkLock(myStudy)) return;
2572   VisuGUI::GetOrCreateVisuGUI( QAD_Application::getDesktop() );
2573   SALOME_Selection* Sel = SALOME_Selection::Selection( VisuGUI::myActiveStudy->getSelection() );
2574   if ( Sel->IObjectCount() != 1 )
2575     return;
2576   SALOMEDS::SObject_var aSObj = myStudy->FindObjectID( Sel->firstIObject()->getEntry() );
2577   if( aSObj->_is_nil() ) return;
2578    
2579   //TEST DU PARENT == VISU
2580   SALOMEDS::GenericAttribute_var anAttr;  
2581   SALOMEDS::AttributeName_var    aName;
2582   if ( aSObj->FindAttribute(anAttr, "AttributeName") ) {
2583     aName = SALOMEDS::AttributeName::_narrow( anAttr );
2584     QString Name = SALOMEGUI_NameDlg::getName( QAD_Application::getDesktop(), aName->Value() );
2585     if ( !Name.isEmpty() ) {
2586       QApplication::setOverrideCursor( Qt::waitCursor );
2587       VisuGUI::myActiveStudy->renameIObject( Sel->firstIObject(), Name );
2588       QApplication::restoreOverrideCursor();
2589       
2590       //int TypeMode;  bool InViewer;
2591       //VISU_Actor *ActorTmp = ActorSelected(parent,InViewer,&TypeMode);
2592       //ActorTmp->setName((Standard_CString)Name.latin1());
2593     }
2594   }
2595 }
2596
2597
2598 //=====================================================================================
2599 // function : CopyPresentation()
2600 // purpose  :
2601 //=====================================================================================
2602 void VisuGUI::CopyPresentation(){
2603   if (checkLock(myStudy)) return;
2604   VISU::Prs3d_i* aPrsObject = GetSelectedPrs();
2605   if (!aPrsObject) return;
2606   switch (aPrsObject->GetType()) {
2607   case VISU::TMESH:
2608     {
2609       VISU::Mesh_i* aMeshPrs = dynamic_cast<VISU::Mesh_i*>(aPrsObject);
2610       VISU::Mesh_i* aSameMesh = new VISU::Mesh_i(aMeshPrs->GetResult());
2611       aSameMesh->SameAs(aMeshPrs);
2612       UpdateViewer(aSameMesh, true);
2613     }    
2614     break;
2615    case VISU::TSCALARMAP:
2616     {
2617       VISU::ScalarMap_i* aScalarPrs = dynamic_cast<VISU::ScalarMap_i*>(aPrsObject);
2618       VISU::ScalarMap_i* aSameScalar = new VISU::ScalarMap_i(aScalarPrs->GetResult());
2619       aSameScalar->SameAs(aScalarPrs);
2620       UpdateViewer(aSameScalar, true);
2621     }    
2622     break;
2623    case VISU::TDEFORMEDSHAPE:
2624     {
2625       VISU::DeformedShape_i* aDefPrs = dynamic_cast<VISU::DeformedShape_i*>(aPrsObject);
2626       VISU::DeformedShape_i* aSameDeformed = new VISU::DeformedShape_i(aDefPrs->GetResult());
2627       aSameDeformed->SameAs(aDefPrs);
2628       UpdateViewer(aSameDeformed, true);
2629     }    
2630     break;
2631    case VISU::TCUTPLANES:
2632     {
2633       VISU::CutPlanes_i* aCutPrs = dynamic_cast<VISU::CutPlanes_i*>(aPrsObject);
2634       VISU::CutPlanes_i* aSameCut = new VISU::CutPlanes_i(aCutPrs->GetResult());
2635       aSameCut->SameAs(aCutPrs);
2636       UpdateViewer(aSameCut, true);
2637     }    
2638     break;
2639    case VISU::TISOSURFACE:
2640     {
2641       VISU::IsoSurfaces_i* aIsoPrs = dynamic_cast<VISU::IsoSurfaces_i*>(aPrsObject);
2642       VISU::IsoSurfaces_i* aSameIso = new VISU::IsoSurfaces_i(aIsoPrs->GetResult());
2643       aSameIso->SameAs(aIsoPrs);
2644       UpdateViewer(aSameIso, true);
2645     }    
2646     break;
2647    case VISU::TSTREAMLINES:
2648     {
2649       VISU::StreamLines_i* aLinesPrs = dynamic_cast<VISU::StreamLines_i*>(aPrsObject);
2650       VISU::StreamLines_i* aSameLines = new VISU::StreamLines_i(aLinesPrs->GetResult());
2651       aSameLines->SameAs(aLinesPrs);
2652       UpdateViewer(aSameLines, true);
2653     }    
2654     break;
2655    case VISU::TVECTORS:
2656     {
2657       VISU::Vectors_i* aVectorsPrs = dynamic_cast<VISU::Vectors_i*>(aPrsObject);
2658       VISU::Vectors_i* aSameVectors = new VISU::Vectors_i(aVectorsPrs->GetResult());
2659       aSameVectors->SameAs(aVectorsPrs);
2660       UpdateViewer(aSameVectors, true);
2661     }    
2662     break;
2663  }
2664   myActiveStudy->updateObjBrowser();
2665 }
2666
2667 //=====================================================================================
2668 // function : InfoOnPoint() [ slot ] 
2669 // purpose  :
2670 //=====================================================================================
2671 void VisuGUI::InfoOnPoint()
2672 {
2673   VisuGUI::GetOrCreateVisuGUI(QAD_Application::getDesktop());
2674   if ( visuGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK )
2675     return;
2676   int TypeMode;
2677   VISU_Actor* ActorTmp = ActorSelected( visuGUI->myDesktop, true, &TypeMode );
2678   if ( !ActorTmp )
2679     return;
2680   
2681   if ( TypeMode == SelectionPoint )
2682     Selection->PickingResults( visuGUI->myActiveStudy, TypeMode, ActorTmp );
2683   else 
2684     QAD_MessageBox::warn1( visuGUI->myDesktop, 
2685                            tr ("WARNING"),
2686                            tr ("Not Point selection mode"),
2687                            tr ("VISU_BUT_OK") );
2688 }
2689
2690 //=====================================================================================
2691 // function : InfoOnCell() [ slot ] 
2692 // purpose  :
2693 //=====================================================================================
2694 void VisuGUI::InfoOnCell()
2695 {
2696   VisuGUI::GetOrCreateVisuGUI(QAD_Application::getDesktop());
2697   if ( visuGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK )
2698     return;
2699   int TypeMode;
2700   VISU_Actor* ActorTmp = ActorSelected( visuGUI->myDesktop, true, &TypeMode );
2701   if ( !ActorTmp )
2702     return;
2703   
2704   if ( TypeMode == SelectionCell || TypeMode == SelectionEdge )
2705     Selection->PickingResults( visuGUI->myActiveStudy, TypeMode, ActorTmp );
2706   else
2707     QAD_MessageBox::warn1( visuGUI->myDesktop, 
2708                            tr ("WARNING"),
2709                            tr ("Not Cell/Edge selection mode"),
2710                            tr ("VISU_BUT_OK") );
2711 }
2712
2713 //=====================================================================================
2714 // function : SelectPoint() [ slot ] 
2715 // purpose  :
2716 //=====================================================================================
2717 void VisuGUI::SelectPoint()
2718 {
2719   VisuGUI::GetOrCreateVisuGUI(QAD_Application::getDesktop());
2720   if ( visuGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK )
2721     return;
2722   vtkRenderer* theRenderer = GetRenderer( visuGUI->myActiveStudy );
2723   int TypeMode;
2724   VISU_Actor* ActorTmp = ActorSelected( visuGUI->myDesktop, true, &TypeMode );
2725   if ( !ActorTmp )
2726     return;
2727   if ( TypeMode != SelectionPoint ) {
2728     QAD_MessageBox::warn1( visuGUI->myDesktop, 
2729                            tr ("WARNING"),
2730                            tr ("Not Point selection mode"),
2731                            tr ("VISU_BUT_OK") );
2732     return;
2733   }
2734   
2735   bool ok = FALSE;
2736   vtkDataSetMapper* Mapper = (vtkDataSetMapper*) (ActorTmp->GetMapper());
2737   Mapper->SetInput(ActorTmp->DataSource);
2738   vtkDataSet *Data=Mapper->GetInput();
2739   int nbPoints=Data->GetNumberOfPoints();
2740   int selectedPoint = SALOMEGUI_SetValueDlg::getInteger( tr("Point selection"),
2741                                                          tr("Point number:" ), 
2742                                                          0,
2743                                                          &ok, 
2744                                                          visuGUI->myDesktop );
2745   if ( ok && theRenderer && selectedPoint > 0 && selectedPoint <= nbPoints )
2746     Selection->HighlightPoint( selectedPoint, nbPoints, ActorTmp, theRenderer );
2747 }
2748
2749 //=====================================================================================
2750 // function : SelectCell() [ slot ] 
2751 // purpose  :
2752 //=====================================================================================
2753 void VisuGUI::SelectCell()
2754 {
2755   VisuGUI::GetOrCreateVisuGUI(QAD_Application::getDesktop());
2756   SALOME_Selection* Sel = SALOME_Selection::Selection(visuGUI->myActiveStudy->getSelection());
2757   if ( visuGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK )
2758     return;
2759   vtkRenderer* theRenderer = GetRenderer( visuGUI->myActiveStudy );
2760   int TypeMode=Sel->SelectionMode();
2761   if ( TypeMode != SelectionCell && TypeMode != SelectionEdge ) {
2762     QAD_MessageBox::warn1( visuGUI->myDesktop, 
2763                            tr ("WARNING"),
2764                            tr ("Not Cell/Edge selection mode"),
2765                            tr ("VISU_BUT_OK") );
2766     return;
2767   }
2768   VISU_Actor* ActorTmp;
2769   string aComment;
2770   Handle(SALOME_InteractiveObject) anIO;
2771   CORBA::Object_var anObject = GetSelectedObj(aComment,anIO,visuGUI->myActiveStudy);
2772   //srn: Added check if anObject is Null, then break
2773 //      if(CORBA::is_nil(anObject)) break;
2774         
2775   VISU::Prs3d_i* aPrsObject = NULL;
2776   if(!CORBA::is_nil(anObject))
2777     aPrsObject = dynamic_cast<VISU::Prs3d_i*>(VISU::GetServant(anObject));
2778   if(aPrsObject){
2779     //aPrsObject->SetIO(anIO);
2780     //ActorTmp = aPrsObject->GetActor();
2781     //UpdateViewer(ActorTmp);
2782     ActorTmp = visuGUI->UpdateViewer(aPrsObject);
2783   } else {
2784     ActorTmp = ActorSelected(visuGUI->myDesktop,true,&TypeMode);
2785   }
2786   if (ActorTmp==NULL)
2787     return;
2788     
2789   bool ok=FALSE;
2790   vtkDataSetMapper *Mapper = (vtkDataSetMapper*) (ActorTmp->GetMapper());
2791   Mapper->SetInput(ActorTmp->DataSource);
2792   vtkDataSet *Data=Mapper->GetInput();
2793   int nbCells=Data->GetNumberOfCells();
2794   int selectedCell = SALOMEGUI_SetValueDlg::getInteger( tr("Cell selection"),
2795                                                         tr("Cell number:" ), 
2796                                                         0,
2797                                                         &ok, 
2798                                                         visuGUI->myDesktop );
2799   if ( ok && theRenderer && selectedCell > 0 && selectedCell <= nbCells )
2800   if (ok && theRenderer )
2801     Selection->HighlightCell(selectedCell , ActorTmp , theRenderer);
2802 }
2803
2804 //=====================================================================================
2805 // function : DefinePopup()
2806 // purpose  :
2807 //=====================================================================================
2808 void VisuGUI::DefinePopup( QString & theContext, QString & theParent, QString & theObject )
2809 {
2810   VisuGUI::GetOrCreateVisuGUI(QAD_Application::getDesktop());
2811   theObject = "";
2812   theContext = "";
2813 }
2814
2815
2816 //=====================================================================================
2817 // function : CustomPopup()
2818 // purpose  :
2819 //=====================================================================================
2820 bool VisuGUI::CustomPopup(QAD_Desktop* parent, QPopupMenu* thePopup, const QString & theContext,
2821                           const QString & theParent, const QString & theObject)
2822 {
2823   int isViewer = (theParent.compare("ObjectBrowser") != 0), initId = isViewer? 800: 900;
2824   VisuGUI::GetOrCreateVisuGUI(parent);
2825   QAD_ResourceMgr* rmgr = parent->createResourceManager();
2826
2827   bool isVTKViewer = (visuGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK);
2828   thePopup->clear();
2829
2830   SALOME_Selection* Sel = SALOME_Selection::Selection(VisuGUI::myActiveStudy->getSelection());
2831   if ( Sel->IObjectCount() == 0 ) {
2832     if ( theParent == "Viewer" && isVTKViewer)
2833       // Available only for VTK viewer
2834       thePopup->insertItem( "Save view parameters", visuGUI, SLOT( SaveViewParams() ) );
2835     return false;
2836   }
2837
2838   VISU::Storable::TRestoringMap aMap;
2839   Handle(SALOME_InteractiveObject) anIO;    
2840   CORBA::Object_var anObject = GetSelectedObj(VisuGUI::myActiveStudy,&anIO,&aMap);
2841   bool isExist;
2842   string aComment = VISU::Storable::FindValue(aMap,"myComment",&isExist).latin1();
2843   if(!isExist) aComment = "NONE";
2844   SALOMEDS::GenericAttribute_var anAttr;
2845   
2846   if (!CORBA::is_nil(anObject)) {
2847     VISU::Base_var aVisuObj = VISU::Base::_narrow(anObject);
2848     if (!CORBA::is_nil(aVisuObj)) {
2849       if( Sel->IObjectCount() > 1) return false;
2850
2851       VISU::VISUType aType = aVisuObj->GetType();
2852       MESSAGE("VisuGUI::CustomPopup - VISU object :: "<<aType);
2853       switch (aType) {
2854       case VISU::TVISUGEN:
2855         thePopup->insertItem("Import From File", visuGUI, SLOT(ImportFromFile()));
2856         break;
2857
2858       case VISU::TRESULT:
2859         //thePopup->insertItem("Create Mesh", visuGUI, SLOT(CreateMesh()));    
2860         thePopup->insertItem("Export To File", visuGUI, SLOT(ExportToFile()));    
2861         //thePopup->insertItem("Delete", visuGUI, SLOT(DeletePrs()));
2862         break;
2863         
2864       case VISU::TTABLE:
2865         thePopup->insertItem( "Show Table",    visuGUI, SLOT( ShowTable() ) );
2866         thePopup->insertItem( "Create Curves", visuGUI, SLOT( PlotData() ) );
2867         if ( visuGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_PLOT2D ) {
2868           thePopup->insertItem( "Display",      visuGUI, SLOT( DisplayPrs() ) );
2869           thePopup->insertItem( "Erase",        visuGUI, SLOT( ErasePrs () ) );
2870           thePopup->insertItem( "Display Only", visuGUI, SLOT( DisplayOnlyPrs() ) );
2871         }
2872         break;
2873  
2874       case VISU::TCURVE:
2875         if ( !isStudyLocked( visuGUI->myActiveStudy->getStudyDocument() ) ) 
2876           thePopup->insertItem( "Properties", visuGUI, SLOT( CurveProperties() ) );
2877         if ( visuGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_PLOT2D ) {
2878           if ( visuGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame()->isVisible( anIO ) ) 
2879             thePopup->insertItem( "Erase", visuGUI, SLOT( ErasePrs () ) );
2880           else 
2881             thePopup->insertItem( "Display", visuGUI, SLOT( DisplayPrs() ) );
2882           thePopup->insertItem( "Display Only", visuGUI, SLOT( DisplayOnlyPrs() ) );
2883         }
2884         break;
2885
2886       case VISU::TCONTAINER:
2887         if( !CORBA::is_nil( anObject ) ) {
2888           CORBA::Object_ptr aCnt = VISU::Container::_narrow( anObject );
2889           if( !CORBA::is_nil( aCnt ) ) {
2890             VISU::Container_i* container = dynamic_cast<VISU::Container_i*>( VISU::GetServant( aCnt ) );
2891             if ( container && container->GetNbCurves() > 0 ) {
2892               if ( !isStudyLocked( visuGUI->myActiveStudy->getStudyDocument() ) ) 
2893                 thePopup->insertItem( "Clear", visuGUI, SLOT( ClearContainer() ) );
2894               if ( visuGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_PLOT2D ) {
2895                 thePopup->insertItem( "Display", visuGUI, SLOT( DisplayPrs() ) );
2896                 thePopup->insertItem( "Erase", visuGUI, SLOT( ErasePrs () ) );
2897                 thePopup->insertItem( "Display Only", visuGUI, SLOT( DisplayOnlyPrs() ) );
2898               }
2899             }
2900           }
2901         }
2902         break;
2903
2904       default: // Presentation
2905         {
2906           VISU::Prs3d_i* aPrsObject = dynamic_cast<VISU::Prs3d_i*>(VISU::GetServant(anObject));
2907           if (aPrsObject) {
2908             VISU_Actor* anVISUActor = visuGUI->GetActor(aPrsObject);
2909             if (isVTKViewer) {
2910               // Add Presentation menu
2911               if ((aType != VISU::TSTREAMLINES) && anVISUActor) {
2912                 QPopupMenu* aPresMenu = new QPopupMenu(VisuGUI::myDesktop);
2913                 aPresMenu->insertItem("Wireframe", visuGUI, SLOT(MakeWireframe()));
2914                 aPresMenu->insertItem("Surface", visuGUI, SLOT(MakeSurface()));
2915                 aPresMenu->insertItem("Points", visuGUI, SLOT(MakePoints()));
2916                 if (anVISUActor->IsShrinkable) {
2917                   if (anVISUActor->IsShrunk)
2918                     aPresMenu->insertItem("Unshrink", visuGUI, SLOT(MakeShrink()));
2919                   else
2920                     aPresMenu->insertItem("Shrink", visuGUI, SLOT(MakeShrink()));
2921                 }
2922                 thePopup->insertItem("Representation", aPresMenu);        
2923               }
2924               
2925               // Add Properties
2926               QPopupMenu* aPropMenu = new QPopupMenu(VisuGUI::myDesktop);
2927               if ((aType == VISU::TMESH) || 
2928                   (aType ==  VISU::TDEFORMEDSHAPE) || 
2929                   (aType == VISU::TVECTORS) ||
2930                   (aType == VISU::TSTREAMLINES)) // Mesh, deformed shape, vectors
2931                 aPropMenu->insertItem("Color", visuGUI, SLOT(ChageColor()));
2932               if (aType == VISU::TMESH)
2933                 aPropMenu->insertItem("Outline Color", visuGUI, SLOT(ChangeOutlineColor()));
2934               
2935               if ((aType != VISU::TVECTORS) && (aType != VISU::TSTREAMLINES))
2936                 aPropMenu->insertItem("Opacity", visuGUI, SLOT(ChangeOpacity()));
2937               aPropMenu->insertItem("Line width", visuGUI, SLOT(ChangeLines()));
2938               thePopup->insertItem("Properties", aPropMenu);              
2939               
2940               thePopup->insertSeparator();
2941             }
2942             thePopup->insertItem("Rename...", visuGUI, SLOT(Rename()));
2943             if (aType != VISU::TMESH) {
2944               if (aType != VISU::TSCALARMAP)
2945                 thePopup->insertItem("Edit...", visuGUI, SLOT(EditPrs()));
2946               thePopup->insertItem("Edit Scalar Bar...", visuGUI, SLOT(EditScalarBar()));
2947               
2948               if ((aType != VISU::TVECTORS) && (aType != VISU::TSTREAMLINES) && isVTKViewer)
2949                 thePopup->insertItem("Animate", visuGUI, SLOT(Sweep()));
2950             }
2951             if (isVTKViewer) {
2952               if ( theParent == "Viewer" && 
2953                    ( aType == VISU::TMESH      || 
2954                      aType == VISU::TSCALARMAP || 
2955                      aType == VISU::TDEFORMEDSHAPE ) ) {
2956                 thePopup->insertSeparator();
2957                 if ( Sel->SelectionMode() == SelectionPoint ) {
2958                   thePopup->insertItem("Results at Point", visuGUI, SLOT(InfoOnPoint()));
2959                   thePopup->insertItem("Select a Point",   visuGUI, SLOT(SelectPoint()));
2960                 }
2961                 else if ( Sel->SelectionMode() == SelectionCell || Sel->SelectionMode() == SelectionEdge ) {
2962                   thePopup->insertItem("Results on Cell", visuGUI, SLOT(InfoOnCell()));
2963                   thePopup->insertItem("Select a Cell",  visuGUI, SLOT(SelectCell()));
2964                 }
2965               }
2966               thePopup->insertSeparator();
2967               if (visuGUI->IsDisplayed(aPrsObject) )
2968                 thePopup->insertItem("Hide", visuGUI, SLOT(ErasePrs()));
2969               else
2970                 thePopup->insertItem("Display", visuGUI, SLOT(DisplayPrs()));
2971               
2972               thePopup->insertItem("Display Only", visuGUI, SLOT(DisplayOnlyPrs()));
2973             }
2974             if (aType != VISU::TMESH)
2975               thePopup->insertItem("Delete", visuGUI, SLOT(DeletePrs()));
2976             thePopup->insertSeparator();
2977             thePopup->insertItem("Same As", visuGUI, SLOT(CopyPresentation()));
2978           }
2979         }
2980       }
2981       return false;
2982     }
2983     else {
2984       // possibly this is the MED field/mesh and suppot objects
2985       /*CORBA::Object_var anObj = SALOME_MED::FIELD::_narrow( anObject );
2986       if( !CORBA::is_nil( anObj ) ) {
2987         thePopup->insertItem( "Import Field", visuGUI, SLOT( ImportMedField() ) );
2988         return false;
2989       }
2990       anObj = SALOME_MED::MESH::_narrow( anObject );
2991       if( !CORBA::is_nil( anObj ) ) {
2992         thePopup->insertItem( "Import Mesh", visuGUI, SLOT( ImportMedField() ) );
2993         return false;
2994       }
2995       anObj = SALOME_MED::GROUP::_narrow( anObject );
2996       if( !CORBA::is_nil( anObj ) ) {
2997         thePopup->insertItem( "Import Group", visuGUI, SLOT( ImportMedField() ) );
2998         return false;
2999       }
3000       anObj = SALOME_MED::FAMILY::_narrow( anObject );
3001       if( !CORBA::is_nil( anObj ) ) {
3002         thePopup->insertItem( "Import Family", visuGUI, SLOT( ImportMedField() ) );
3003         return false;
3004       }
3005       anObj = SALOME_MED::SUPPORT::_narrow( anObject );
3006       if( !CORBA::is_nil( anObj ) ) {
3007         thePopup->insertItem( "Import Support", visuGUI, SLOT( ImportMedField() ) );
3008         return false;
3009         }*/
3010     }
3011   }
3012   int aType = ObjectTypes.find( aComment.c_str() );
3013   if(MYDEBUG) MESSAGE("VisuGUI::CustomPopup - aComment = "<<aComment<<"; aType = "<<aType);
3014   SALOMEDS::SObject_var obj  = VisuGUI::myActiveStudy->getStudyDocument()->FindObjectID( Sel->firstIObject()->getEntry() );
3015   if ( aType < 0 ) {
3016     // possibly this is Table SObject
3017     if ( !obj->_is_nil() && ( obj->FindAttribute( anAttr, "AttributeTableOfInteger" ) 
3018                               || obj->FindAttribute( anAttr, "AttributeTableOfReal" ) ) ) {
3019       thePopup->insertItem( "Show Table",    visuGUI, SLOT( ShowTable() ) );
3020       thePopup->insertItem( "Create Curves", visuGUI, SLOT( PlotData() ) );
3021     }
3022     return false;
3023   }
3024   if(aComment == "ENTITY" || aComment == "FAMILY" || aComment == "GROUP")
3025     thePopup->insertItem("Create Presentation", visuGUI, SLOT(CreateMesh()));    
3026   switch (aType) {
3027   case 0:  // Field
3028     if (getValue(obj, "myNbTimeStamps").toLong() > 1)
3029       thePopup->insertItem( "Animation...", visuGUI, SLOT( TimeAnimation() ) );
3030     break;
3031   
3032   case 6: // VIEW3D node
3033     if ( visuGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { 
3034       // Available only for VTK viewer
3035       thePopup->insertItem( "Save view parameters", visuGUI, SLOT( SaveViewParams() ) );
3036       thePopup->insertItem( "Restore view parameters", visuGUI, SLOT( RestoreViewParams() ) );
3037     }
3038     thePopup->insertItem( "Rename...", visuGUI, SLOT( Rename() ) );
3039     thePopup->insertItem("Delete", visuGUI, SLOT(DeleteViewParams()));
3040     break;
3041
3042   //case 13:  // Mesh node
3043   //thePopup->insertItem("Create Presentation", visuGUI, SLOT(CreateMesh()));    
3044   //break;
3045
3046   case 18: { // Timestamp
3047 //     if( isStudyLocked(VisuGUI::myActiveStudy->getStudyDocument()))
3048 //       return false;
3049     int aNunComponent = VISU::Storable::FindValue(aMap,"myNumComponent",&isExist).toInt();
3050     thePopup->insertItem(rmgr->loadPixmap( "VISU", tr("ICON_SCALAR_MAP") ), 
3051                          "Scalar Map...", visuGUI, SLOT(CreateScalarMap()));
3052     thePopup->insertItem(rmgr->loadPixmap( "VISU", tr("ICON_ISO_SURFACES") ),
3053                          "Iso Surfaces...", visuGUI, SLOT(CreateIsoSurfaces()));
3054     thePopup->insertItem(rmgr->loadPixmap( "VISU", tr("ICON_CUT_PLANES") ),
3055                          "Cut Planes...", visuGUI, SLOT(CreateCutPlanes()));
3056     if(aNunComponent > 1){
3057       thePopup->insertItem(rmgr->loadPixmap( "VISU", tr("ICON_DEFORMED_SHAPE") ),
3058                            "Deformed Shape...", visuGUI, SLOT(CreateDeformedShape()));
3059       thePopup->insertItem(rmgr->loadPixmap( "VISU", tr("ICON_VECTORS") ),
3060                            "Vectors...", visuGUI, SLOT(CreateVectors()));
3061       thePopup->insertItem(rmgr->loadPixmap( "VISU", tr("ICON_STREAM_LINES") ),
3062                            "Stream lines...", visuGUI, SLOT(CreateStreamLines()));
3063     }
3064   }
3065   }
3066   return false;
3067 }
3068
3069 //===========================================================================
3070 // BuildPresentation
3071 //===========================================================================
3072 void VisuGUI::BuildPresentation(const Handle(SALOME_InteractiveObject)& theIO)
3073 {
3074   BEGIN_OF("VisuGUI::BuildPresentation");
3075
3076   if (theIO.IsNull()) {
3077     MESSAGE("VisuGUI::BuildPresentation(): null SALOME_InteractiveObject passed");
3078     return;
3079   }
3080
3081    /* Create or retrieve an object VisuGUI */
3082
3083   VisuGUI::GetOrCreateVisuGUI(QAD_Application::getDesktop());
3084
3085   SALOMEDS::Study_var aStudy = visuGUI->myActiveStudy->getStudyDocument();
3086   SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
3087
3088   if ( visuGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK ) return;
3089
3090   vtkRenderer *Renderer = GetRenderer(visuGUI->myActiveStudy);
3091
3092   SALOMEDS::SObject_var aSObj = aStudy -> FindObjectID ( theIO->getEntry() );
3093   SCRUTE(aSObj);
3094   if (aSObj -> _is_nil() ) {
3095     MESSAGE("No SObject for interacative object is found");
3096     return;
3097   }
3098   
3099   CORBA::Object_var anObject = VISU::SObjectToObject(aSObj);
3100   if(!CORBA::is_nil(anObject)) {
3101     
3102     VISU::Prs3d_i* aPrsObject = dynamic_cast<VISU::Prs3d_i*>(VISU::GetServant(anObject));
3103     if ( !aPrsObject ) {
3104       MESSAGE("The object is not VISU::Prs3d_i");
3105       return;
3106     }
3107     VISU_Actor *SelectedActor = visuGUI->GetActor(aPrsObject);
3108     if ( ! SelectedActor )
3109       SelectedActor = aPrsObject -> CreateActor();
3110     SCRUTE(SelectedActor);
3111     if  ( SelectedActor == NULL )   {  
3112       MESSAGE("VisuGUI::BuildPresentation(): actor doesn't exist in Render");
3113       return;
3114     }
3115     VTKViewer_ViewFrame* vf = GetVtkViewFrame();
3116     vf->AddActor(SelectedActor);
3117     if(SelectedActor->HasScalarBar()){
3118       Renderer->AddActor2D(SelectedActor->getScalarBar());
3119     }
3120   }
3121     else {
3122       MESSAGE("CORBA::is_nil(anObject) = true");
3123     }
3124   END_OF("VisuGUI::BuildPresentation");
3125
3126 }
3127
3128 extern "C"
3129 {
3130  
3131   bool OnGUIEvent(int theCommandID, QAD_Desktop* parent)
3132   {
3133     //MESSAGE("VisuGUI::OnGUIEvent "<< theCommandID);
3134     return VisuGUI::OnGUIEvent(theCommandID, parent);
3135   }
3136
3137   bool OnKeyPress (QKeyEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame)
3138   {
3139     MESSAGE("VisuGUI::OnKeyPress ");
3140     return VisuGUI::OnKeyPress (pe, parent, studyFrame);
3141   }
3142
3143   bool OnMousePress (QMouseEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame)
3144   {
3145     //MESSAGE("VisuGUI::OnMousePress ");
3146     return VisuGUI::OnMousePress (pe, parent, studyFrame);
3147   }
3148
3149   bool OnMouseMove (QMouseEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame)
3150   {
3151     //MESSAGE("VisuGUI::OnMouseMove ");
3152     return VisuGUI::OnMouseMove (pe, parent, studyFrame);
3153   }
3154
3155   bool SetSettings ( QAD_Desktop* parent )
3156   {
3157     return VisuGUI::setSettings( parent );
3158   }
3159
3160   bool customPopup ( QAD_Desktop* parent, QPopupMenu* popup, const QString & theContext,
3161                      const QString & theParent, const QString & theObject )
3162   {
3163     return VisuGUI::CustomPopup( parent, popup, theContext, theParent, theObject );
3164   }
3165
3166   void definePopup ( QString & theContext, QString & theParent, QString & theObject )
3167   {
3168     VisuGUI::DefinePopup( theContext, theParent, theObject );
3169   }
3170
3171   bool activeStudyChanged ( QAD_Desktop* parent )
3172   {
3173     //VisuGUI::activeStudyChanged( parent );
3174   }
3175     void buildPresentation ( const Handle(SALOME_InteractiveObject)& theIO )
3176   {
3177     VisuGUI::BuildPresentation(theIO);
3178   }
3179
3180 }
3181
3182 // ====================================================================================================================
3183 // ===================================================================================================================
3184
3185 bool VisuGUI::getObjectRef( QAD_Desktop* parent, SALOMEDS::SObject_ptr obj,
3186                             _CORBA_ObjRef_OUT_arg< SALOMEDS::_objref_SObject, SALOMEDS::SObject_Helper > objres,
3187                             const char* Type) {
3188
3189   VisuGUI::GetOrCreateVisuGUI(parent);
3190   SALOMEDS::Study_var aStudy = visuGUI->myActiveStudy->getStudyDocument();
3191   SALOMEDS::ChildIterator_var it = aStudy->NewChildIterator(obj);
3192   SALOMEDS::SObject_var RefObj;
3193
3194   for (; it->More();it->Next()) {
3195     SALOMEDS::SObject_var Fils = it->Value();
3196
3197     if ( Fils->ReferencedObject( RefObj ) ) {
3198       SALOMEDS::SComponent_var theComponent = RefObj->GetFatherComponent();
3199       Standard_CString nameComponent = theComponent->ComponentDataType();
3200
3201       if ( TCollection_AsciiString(nameComponent).IsEqual(strdup(Type)) ) {
3202         objres = SALOMEDS::SObject::_narrow(RefObj);
3203         return true;
3204       }
3205     }
3206   }
3207   return false;
3208 }
3209
3210 //////////////////////////////////////////////////////////////////////////////////
3211 ////////////////               CHANGE ACTOR COLOR         ////////////////////////
3212 //////////////////////////////////////////////////////////////////////////////////
3213 //////////////////////////////////////////////////////////////////////////////////
3214 // change actor color
3215 // In : Name of Actor
3216 //
3217 //
3218
3219 void VisuGUI::NewColor(VISU_Actor *Actor)
3220 {
3221   float oldcolor[3],newcolor[3];
3222   Actor->GetProperty()->GetColor(oldcolor);
3223   QColor colorold;
3224   colorold = QColor(oldcolor[0]*255, oldcolor[1]*255, oldcolor[2]*255);
3225   QColor colornew = QColorDialog::getColor( colorold, QAD_Application::getDesktop() );
3226
3227   if (!colornew.isValid()) return;
3228
3229   newcolor[0]=colornew.red()/255.;
3230   newcolor[1]=colornew.green()/255.;
3231   newcolor[2]=colornew.blue()/255.;
3232   Actor->GetProperty()->SetColor(newcolor);
3233   if (Actor->getPrs3d())
3234     Actor->getPrs3d()->SetColor(newcolor);
3235 }
3236
3237 void VisuGUI::NewOutlineColor(VISU_Actor *Actor)
3238 {
3239   float oldcolor[3],newcolor[3];
3240   Actor->EdgeDevice->GetProperty()->GetColor(oldcolor);
3241   QColor colorold;
3242   colorold = QColor(oldcolor[0]*255, oldcolor[1]*255, oldcolor[2]*255);
3243   QColor colornew = QColorDialog::getColor( colorold, QAD_Application::getDesktop() );
3244
3245   if (!colornew.isValid()) return;
3246
3247   SALOMEDS::Color aColor;
3248   aColor.R = newcolor[0]=colornew.red()/255.;
3249   aColor.G = newcolor[1]=colornew.green()/255.;
3250   aColor.B = newcolor[2]=colornew.blue()/255.;
3251   Actor->EdgeDevice->GetProperty()->SetColor(newcolor);
3252   if (Actor->getPrs3d())
3253     dynamic_cast<VISU::Mesh_i*>(Actor->getPrs3d())->SetLinkColor(aColor);
3254 }
3255
3256 //////////////////////////////////////////////////////////////////////////////////
3257 ////////////////               CHANGE ACTOR OPACITY       ////////////////////////
3258 //////////////////////////////////////////////////////////////////////////////////
3259 //////////////////////////////////////////////////////////////////////////////////
3260 // change actor opacity
3261 // In : Name of Actor
3262 //
3263 // Use CursorDlg to select a value between 0 and 100
3264 //
3265
3266 void VisuGUI::NewOpacity(VISU_Actor *Actor)
3267 {
3268   
3269   VisuGUI_CursorDlg* CursorDlg = new VisuGUI_CursorDlg(QAD_Application::getDesktop(), tr("Opacity"), TRUE );
3270   
3271   float oldopac,newopac;
3272   int intopac;
3273   CursorDlg->Comment1->setText( tr( "Set value between") );
3274   CursorDlg->Comment2->setText( tr( "0 (transparent) and 100 (opaque)" ) );
3275   oldopac=Actor->GetProperty()->GetOpacity();
3276   intopac=int(oldopac*100.);
3277   CursorDlg->SpinBox1->setMinValue(0);
3278   CursorDlg->SpinBox1->setMaxValue(100);
3279   CursorDlg->SpinBox1->setValue(intopac);
3280   
3281   int ret = CursorDlg->exec();
3282   if (ret == 1)
3283     {
3284       intopac  = CursorDlg->SpinBox1->value() ;
3285       newopac = intopac/100.;
3286       Actor->GetProperty()->SetOpacity(newopac);
3287     }
3288   delete CursorDlg;
3289 }
3290
3291 //////////////////////////////////////////////////////////////////////////////////
3292 ////////////////               CHANGE ACTOR LINEWIDTH     ////////////////////////
3293 //////////////////////////////////////////////////////////////////////////////////
3294 //////////////////////////////////////////////////////////////////////////////////
3295 // change actor linewidth
3296 // In : Name of Actor
3297 //
3298 // Use CursorDlg to select a value between 0 and 10
3299 //
3300
3301 void VisuGUI::NewLinewidth(VISU_Actor *Actor)
3302 {
3303
3304   VisuGUI_CursorDlg* CursorDlg = new VisuGUI_CursorDlg(QAD_Application::getDesktop(), tr("Line Width"), TRUE );
3305   
3306   float oldlwid,newlwid;
3307   int intlwid;
3308   CursorDlg->Comment1->setText("Set value between");
3309   CursorDlg->Comment2->setText("1 (thin) and 10 (thick)");
3310   oldlwid=Actor->GetProperty()->GetLineWidth();
3311   intlwid=int(oldlwid);
3312   CursorDlg->SpinBox1->setMinValue(1);
3313   CursorDlg->SpinBox1->setMaxValue(10);
3314   CursorDlg->SpinBox1->setValue(intlwid);
3315   
3316   int ret = CursorDlg->exec();
3317   if (ret == 1) {
3318     intlwid  = CursorDlg->SpinBox1->value() ;
3319     newlwid = intlwid;
3320     Actor->GetProperty()->SetLineWidth(newlwid);
3321   }
3322   delete CursorDlg;
3323 }
3324
3325 /* ======================================================================================== */
3326 /* Setting parameters for Scalar Bar                                                        */
3327 /* ======================================================================================== */
3328 void VisuGUI::ChangeScalarBar()
3329 {
3330   VisuGUI_ScalarBarDlg* Scbar = new VisuGUI_ScalarBarDlg(TRUE);
3331   Scbar->initFromResources();
3332   int ret = Scbar->exec();
3333   if ( ret )  {
3334     Scbar->storeToResources();
3335   }
3336   delete Scbar;
3337 }
3338
3339 /* ======================================================================================== */
3340 /* Setting parameters for Sweeping                                                        */
3341 /* ======================================================================================== */
3342 void VisuGUI::SetSweepingPreferences()
3343 {
3344         float tempo=0.2;
3345         int cycles=1;
3346         int steps=20;
3347
3348         QString Tempo = QAD_CONFIG->getSetting("Visu:SweepTempo");
3349         if ( !Tempo.isEmpty() )
3350                 tempo = Tempo.toFloat();
3351
3352         QString Cycles = QAD_CONFIG->getSetting("Visu:SweepCycles");
3353         if ( !Cycles.isEmpty() )
3354                 cycles = Cycles.toInt();
3355
3356         QString Steps = QAD_CONFIG->getSetting("Visu:SweepSteps");
3357         if ( !Steps.isEmpty() )
3358                 steps = Steps.toInt();
3359
3360         VisuGUI_SweepPrefDlg* Sweep = new VisuGUI_SweepPrefDlg(QAD_Application::getDesktop(), 0, TRUE, 0);
3361
3362         Sweep->setTimeStep( tempo );
3363         Sweep->setNbCycles( cycles );
3364         Sweep->setNbSteps ( steps );
3365
3366         if ( Sweep->exec() )
3367         {
3368                 tempo  = Sweep->getTimeStep();
3369                 cycles = Sweep->getNbCycles();
3370                 steps  = Sweep->getNbSteps();
3371
3372                 QAD_CONFIG->addSetting("Visu:SweepTempo",  tempo);
3373                 QAD_CONFIG->addSetting("Visu:SweepCycles", cycles);
3374                 QAD_CONFIG->addSetting("Visu:SweepSteps",  steps);
3375         }
3376         delete Sweep;
3377 }
3378
3379 /* ======================================================================================== */
3380 /* Returns Visu input files directory (default is CSF_PATHData)                             */
3381 /* ======================================================================================== */
3382 QString VisuGUI::getVisuInputDir()
3383 {
3384         QString Tmp = QAD_CONFIG->getSetting("Visu:InputDir");
3385         if ( Tmp.isEmpty() )
3386                 Tmp =  QAD_Tools::addSlash(getenv("CSF_PATHData"));
3387         Tmp = QAD_Tools::addSlash(Tmp);
3388         return (Tmp);
3389 }
3390
3391 /* ======================================================================================== */
3392 /* Returns Visu output files directory (default is InputDir)                                */
3393 /* ======================================================================================== */
3394 QString VisuGUI::getVisuOutputDir()
3395 {
3396         QString Tmp = QAD_CONFIG->getSetting("Visu:OutputDir");
3397         if ( Tmp.isEmpty() )
3398         {
3399                 QString Tmp2 = QAD_CONFIG->getSetting("Visu:InputDir");
3400                 if ( Tmp2.isEmpty() )
3401                         Tmp =  QAD_Tools::addSlash(getenv("CSF_PATHData"));
3402                 else
3403                         Tmp = Tmp2;
3404         }
3405         Tmp = QAD_Tools::addSlash(Tmp);
3406         return (Tmp);
3407 }
3408
3409
3410 /* ======================================================================================== */
3411 /* Global Method for Scalar Map                                                  */
3412 /* ======================================================================================== */
3413 VISU::Result_i* VisuGUI::CreatePresent(SALOMEDS::SObject_var theField, VISU::Result_var& theResult){
3414   if(MYDEBUG) MESSAGE("VisuGUI::CreatePresent");
3415   VisuGUI::GetOrCreateVisuGUI( QAD_Application::getDesktop() );
3416   SALOMEDS::SObject_var aSObj = theField->GetFather();
3417   aSObj = aSObj->GetFather();
3418   aSObj = aSObj->GetFather();
3419   aSObj = aSObj->GetFather();
3420   CORBA::Object_var anObject = VISU::SObjectToObject(aSObj);
3421   if(CORBA::is_nil(anObject)) return NULL;
3422   theResult = VISU::Result::_narrow(anObject);
3423   VISU::Result_i* pResult = dynamic_cast<VISU::Result_i*>(VISU::GetServant(anObject));
3424   if(pResult == NULL)
3425     QAD_MessageBox::warn1(QAD_Application::getDesktop(), tr ("VISU_WARNING"),
3426                           tr ("No Available data in selection"),
3427                           tr ("VISU_BUT_OK"));
3428   return pResult;
3429 }
3430
3431 #define CREATEPRS(PRSTYPE, FNAME, FCREATE) \
3432 PRSTYPE* FNAME(SALOMEDS::SObject_var theField, \
3433                const char* theMeshName, VISU::Entity theEntity, \
3434                const char* theFieldName, double theTimeId) {\
3435   VISU::Result_var aResult; \
3436   VISU::Result_i* pResult = CreatePresent(theField,aResult); \
3437   if(pResult){ \
3438     if(PRSTYPE::IsPossible(pResult,theMeshName,(VISU::Entity)theEntity,theFieldName,theTimeId)){ \
3439       QApplication::setOverrideCursor( Qt::waitCursor ); \
3440       VISU::VISU_Gen_var aVisuGen = VISU::GetVisu(); \
3441       CORBA::Object_var anObject =  \
3442         aVisuGen->FCREATE(aResult,theMeshName,theEntity,theFieldName,theTimeId); \
3443       QApplication::restoreOverrideCursor(); \
3444       if(CORBA::is_nil(anObject)) return NULL; \
3445       return dynamic_cast<PRSTYPE*>(VISU::GetServant(anObject)); \
3446     } \
3447   } else { \
3448     QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("VISU_WARNING"), \
3449                             tr ("The presentation can't be builded."), \
3450                             tr ("VISU_BUT_OK") ); \
3451   } \
3452   return NULL; \
3453
3454
3455 CREATEPRS(VISU::ScalarMap_i, VisuGUI::CreateScalarMapPrs, ScalarMapOnField);
3456 CREATEPRS(VISU::DeformedShape_i, VisuGUI::CreateDeformedShapePrs, DeformedShapeOnField);
3457 CREATEPRS(VISU::Vectors_i, VisuGUI::CreateVectorsPrs, VectorsOnField);
3458 CREATEPRS(VISU::IsoSurfaces_i, VisuGUI::CreateIsoSurfacesPrs, IsoSurfacesOnField);
3459 CREATEPRS(VISU::CutPlanes_i, VisuGUI::CreateCutPlanesPrs, CutPlanesOnField);
3460 CREATEPRS(VISU::StreamLines_i, VisuGUI::CreateStreamLinesPrs, StreamLinesOnField);
3461
3462
3463 #define BUILDPRS(TYPE, FCREATE, FNAME, DLGNAME) \
3464 bool FNAME(SALOMEDS::SObject_var theField) { \
3465   VISU::Storable::TRestoringMap aMap = getMapOfValue(theField); \
3466   bool isExist; \
3467   QString aType = VISU::Storable::FindValue(aMap,"myType",&isExist); \
3468   if(!isExist && aType.toInt() != VISU::TTIMESTAMP) return false; \
3469   QString aMeshName = VISU::Storable::FindValue(aMap,"myMeshName",&isExist).latin1(); \
3470   QString anEntity = VISU::Storable::FindValue(aMap,"myEntityId",&isExist).latin1(); \
3471   QString aFieldName = VISU::Storable::FindValue(aMap,"myFieldName",&isExist).latin1(); \
3472   QString aTimeStampId = VISU::Storable::FindValue(aMap,"myTimeStampId",&isExist).latin1(); \
3473   TYPE* pPresent = FCREATE(theField,aMeshName,(VISU::Entity)anEntity.toInt(),aFieldName,aTimeStampId.toDouble()); \
3474   if (pPresent) { \
3475     DLGNAME* aDlg = new DLGNAME(); \
3476     aDlg->initFromPrsObject(pPresent); \
3477     if (aDlg->exec()) { \
3478       aDlg->storeToPrsObject(pPresent); \
3479     } else { \
3480       DeletePresentation(pPresent); \
3481       delete aDlg; \
3482       return false; \
3483     } \
3484     delete aDlg; \
3485     CreateActor(pPresent); \
3486     return true; \
3487   } \
3488   return false; \
3489 }
3490
3491 BUILDPRS(VISU::ScalarMap_i, CreateScalarMapPrs, VisuGUI::CreateScalarMap, VisuGUI_ScalarBarDlg);
3492 BUILDPRS(VISU::DeformedShape_i, CreateDeformedShapePrs, VisuGUI::CreateDeformedShape, VisuGUI_MagnitudeDlg);
3493 BUILDPRS(VISU::Vectors_i, CreateVectorsPrs, VisuGUI::CreateVectors, VisuGUI_VectorsDlg);
3494 BUILDPRS(VISU::IsoSurfaces_i, CreateIsoSurfacesPrs, VisuGUI::CreateIsoSurfaces, VisuGUI_IsoSurfacesDlg);
3495 BUILDPRS(VISU::CutPlanes_i, CreateCutPlanesPrs, VisuGUI::CreateCutPlanes, VisuGUI_CutPlanesDlg);
3496 BUILDPRS(VISU::StreamLines_i, CreateStreamLinesPrs, VisuGUI::CreateStreamLines, VisuGUI_StreamLinesDlg);
3497
3498
3499
3500 /* ======================================================================================== */
3501 /* Global Method to import tables from file */
3502 /* ======================================================================================== */
3503 void VisuGUI::ImportTablesFromFile(){
3504   QStringList flt;
3505   flt.append( "Files (*.xls *.txt *.tab)" );
3506   flt.append( "All Files (*.*)" );
3507   QString aDir = getVisuInputDir();
3508   QString aFile = QAD_FileDlg::getFileName(QAD_Application::getDesktop(),
3509                                            aDir,flt,tr("Import From File"),true);
3510   if(!aFile.isEmpty()){
3511     QAD_Application::getDesktop()->putInfo( "Importing From File " + aFile + "..." );
3512     aDir = QAD_Tools::getDirFromPath(aFile);
3513     QAD_CONFIG->addSetting("Visu:InputDir",aDir);
3514     QApplication::setOverrideCursor( Qt::waitCursor );
3515     QAD_PyInterp* myPyInterp = myActiveStudy->get_PyInterp();
3516     myPyInterp->run("import VisuGUI");
3517     myPyInterp->run("reload(VisuGUI)");
3518     myPyInterp->run("VisuGUI.AddTablesInStudyFromFile('"+aFile+"')");
3519     //     VISU::Result_var aResult = myComponent->ImportFile(aFile.latin1());
3520     //     if(aResult->_is_nil())
3521     //       QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("VISU_WARNING"),
3522     //                        tr ("There is an error in imported file"),
3523     //                        tr ("VISU_BUT_OK") );
3524     //     else
3525     // QAD_Application::getDesktop()->putInfo(aFile+" imported.");
3526     myActiveStudy->updateObjBrowser(); //update Object browser
3527     QApplication::restoreOverrideCursor();
3528   }
3529 }
3530
3531 /* ======================================================================================== */
3532 /* Global Method to import mesh results in MED and DAT format                               */
3533 /* ======================================================================================== */
3534 void VisuGUI::ImportFromFile(){
3535   if (checkLock(myActiveStudy->getStudyDocument())) return;
3536   QStringList flt;
3537   //flt.append( "Exportable Files (*.med *.dat)" );
3538   //flt.append( "Dat Files (*.dat)" );
3539   flt.append( "Med Files (*.med)" );
3540   QString aDir = getVisuInputDir();
3541   QString aFile = QAD_FileDlg::getFileName(QAD_Application::getDesktop(),
3542                                           aDir,flt,tr("Import From File"),true);
3543   if(!aFile.isEmpty()){
3544     QAD_Application::getDesktop()->putInfo( "Importing From File " + aFile + "..." );
3545     aDir = QAD_Tools::getDirFromPath(aFile);
3546     QAD_CONFIG->addSetting("Visu:InputDir",aDir);
3547     QApplication::setOverrideCursor( Qt::waitCursor );
3548     VISU::Result_var aResult = myComponent->ImportFile(aFile.latin1());
3549     if(aResult->_is_nil())
3550       QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("VISU_WARNING"),
3551                              tr ("There is an error in imported file"),
3552                              tr ("VISU_BUT_OK") );
3553     else
3554       QAD_Application::getDesktop()->putInfo(aFile+" imported.");
3555     myActiveStudy->updateObjBrowser(); //update Object browser
3556     QApplication::restoreOverrideCursor();
3557   }
3558 }
3559
3560 void VisuGUI::ExportToFile(){
3561   VISU::Base_i* aBase = GetSelectedVisuObj();
3562   if(aBase != NULL && aBase->GetType() == VISU::TRESULT){
3563     QStringList flt;
3564     flt.append( "Dat Files (*.dat)" );
3565     flt.append( "Med Files (*.med)" );
3566     QString aDir = getVisuOutputDir();
3567     QString aFile = QAD_FileDlg::getFileName(QAD_Application::getDesktop(),
3568                                              aDir,flt,tr("Export To File"),false);
3569     if(!aFile.isEmpty()){
3570       QAD_Application::getDesktop()->putInfo( "Exporting To File " + aFile + "..." );
3571       aDir = QAD_Tools::getDirFromPath(aFile);
3572       QAD_CONFIG->addSetting("Visu:OutputDir",aDir);
3573       if(VISU::Result_i* aResult = dynamic_cast<VISU::Result_i*>(aBase)){
3574         try{
3575           aResult->GetInput()->ToFile(aFile.latin1());
3576           QAD_Application::getDesktop()->putInfo(aFile+" exported.");
3577         }catch(...){
3578           QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("VISU_WARNING"),
3579                                  tr ("There is an error during exporting to file"),
3580                                  tr ("VISU_BUT_OK") );
3581         } 
3582       }
3583     }
3584   }else
3585     QAD_MessageBox::warn1(QAD_Application::getDesktop(), tr ("VISU_WARNING"),
3586                           tr ("No Available data in selection"),
3587                           tr ("VISU_BUT_OK"));
3588 }
3589
3590
3591 /* ======================================================================================== */
3592 /* Find an Actor to be the reference for a new visualization                                */
3593 /* ======================================================================================== */
3594 VISU_Actor *VisuGUI::ReferenceActor(QAD_Desktop* parent)
3595 {
3596   bool exiDS = false, exiVE = false, exiSM = false, exiIS = false, exiCP = false;
3597   int  nbSf  = visuGUI->myActiveStudy->getStudyFramesCount();
3598   int  nbObj = 0;
3599   for ( int i = 0; i < nbSf; i++ ) {
3600     QAD_StudyFrame* sf = visuGUI->myActiveStudy->getStudyFrame(i);
3601     if ( sf->getTypeView() == VIEW_VTK ) {
3602       vtkRenderer* aRenderer = ((VTKViewer_ViewFrame*)sf->getRightFrame()->getViewFrame())->getRenderer();
3603       vtkActorCollection* ac = aRenderer->GetActors();
3604       vtkActor *anActor;
3605       for( ac->InitTraversal(); (anActor = ac->GetNextActor()) != NULL; ) {
3606         if ( anActor->IsA( "VISU_Actor" ) ) {
3607           VISU_Actor *VISUActor = VISU_Actor::SafeDownCast(anActor);
3608           if (VisuGUI_VisuAsDlg::ActorTypeIsValid(VISUActor,-1)) {
3609             //                                          VisuAs->ListObjects->insertItem(VISUActor->getName());
3610             nbObj++;
3611             int test = VISUActor->VisuActorType;
3612             if(test == VisuActorType_DeformedShape)
3613               exiDS=true;
3614             else if(test == VisuActorType_Vectors)
3615               exiVE=true;
3616             else if(test == VisuActorType_ScalarMap)
3617               exiSM=true;
3618             else if(test == VisuActorType_IsoSurfaces)
3619               exiIS=true;
3620             else if(test == VisuActorType_CutPlanes)
3621               exiCP=true;
3622           }
3623         }
3624       }
3625     }
3626   }
3627   
3628   if ( nbObj > 0 ) {
3629     VisuGUI_VisuAsDlg * VisuAs = new VisuGUI_VisuAsDlg(QAD_Application::getDesktop(), 0, true, 0 );
3630     
3631     if(exiDS)
3632       VisuAs->addType( tr( "Deformed Shape" ) );
3633     if(exiVE)
3634       VisuAs->addType( tr( "Vectors" ) );
3635     if(exiSM)
3636       VisuAs->addType( tr( "Scalar Map" ) );
3637     if(exiIS)
3638       VisuAs->addType( tr( "Iso-Surfaces" ) );
3639     if(exiCP)
3640       VisuAs->addType( tr( "Cut Planes" ) );
3641     
3642     if ( VisuAs->exec() ) {
3643       QString nameActor = VisuAs->getObject();
3644       if ( !nameActor.isNull() ) {
3645         MESSAGE("Actor --> "<<nameActor.latin1());
3646         for ( int i = 0; i < nbSf; i++ ) {
3647           QAD_StudyFrame* sf = visuGUI->myActiveStudy->getStudyFrame(i);
3648           if ( sf->getTypeView() == VIEW_VTK ) {
3649             vtkRenderer* aRenderer = ((VTKViewer_ViewFrame*)sf->getRightFrame()->getViewFrame())->getRenderer();
3650             vtkActorCollection* ac = aRenderer->GetActors();
3651             vtkActor *anActor;
3652             for( ac->InitTraversal(); (anActor = ac->GetNextActor()) != NULL; ) {
3653               if ( anActor->IsA( "VISU_Actor" ) ) {
3654                 VISU_Actor *VISUActor = VISU_Actor::SafeDownCast(anActor);
3655                 if (strcmp(VISUActor->getName(),nameActor) == 0)
3656                   return VISUActor;
3657               }
3658             }
3659           }
3660         }
3661       }
3662     }
3663   }
3664   return NULL;
3665 }
3666
3667 /* ======================================================================================== */
3668 /* Test and Read Object Browser before display                                              */
3669 /* ======================================================================================== */
3670 bool VisuGUI::TestObjectBrowser(SALOMEDS::SObject_var *objVisu ){
3671   if(MYDEBUG) MESSAGE("VisuGUI::TestObjectBrowser");
3672   SALOME_Selection* Sel = SALOME_Selection::Selection(myActiveStudy->getSelection());
3673   SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
3674   if(It.More()){
3675     Handle(SALOME_InteractiveObject) IObject = It.Value();
3676     SALOMEDS::Study_var aStudy = visuGUI->myActiveStudy->getStudyDocument(); //Document OCAF de l'etude active
3677     if (IObject->hasEntry()){
3678       *objVisu = aStudy->FindObjectID(IObject->getEntry());
3679       if(!(*objVisu)->_is_nil()) return true;
3680     }
3681   }
3682   QAD_MessageBox::warn1(QAD_Application::getDesktop(), tr ("VISU_WARNING"),
3683                         tr("No Available data in selection"),
3684                         tr("VISU_BUT_OK") );
3685   return false;
3686 }
3687
3688 /* ======================================================================================== */
3689 /* Print the render window                                                                  */
3690 /* ======================================================================================== */
3691 void VisuGUI::PrintRW( QString prFile, bool toPrinter)
3692 {
3693         ((VTKViewer_ViewFrame*)visuGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->Repaint();
3694
3695         vtkRenderWindow *renwin = vtkRenderWindow::New();
3696         vtkRenderWindowInteractor *theInteractor = vtkRenderWindowInteractor::New();
3697         theInteractor = ((VTKViewer_ViewFrame*)visuGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor();
3698         //visuGUI->myActiveStudy->getActiveStudyFrame()->getVTKRWInteractor();
3699         
3700         renwin=theInteractor->GetRenderWindow();
3701         vtkWindowToImageFilter *w2if = vtkWindowToImageFilter::New(); 
3702         vtkTIFFWriter *rttiffw = vtkTIFFWriter::New(); 
3703         w2if->SetInput(renwin);
3704         rttiffw->SetInput(w2if->GetOutput());
3705         rttiffw->SetFileName(prFile); 
3706         rttiffw->Write(); 
3707
3708         if (toPrinter)  // print the file
3709         {
3710                 QString printer = QAD_CONFIG->getSetting("Visu:Printer");
3711                 if (printer.isEmpty())
3712                         printer="kprinter";
3713                 system(printer + " " + prFile);
3714         }
3715 }
3716
3717 /**
3718  * Returns Actor of presentation if it exists
3719  */
3720 VISU_Actor* VisuGUI::GetActor(VISU::Prs3d_i* thePrs){
3721   VTKViewer_ViewFrame* vf = GetVtkViewFrame();
3722   if (!vf) return NULL;
3723   
3724   vtkRenderer *aRen = vf->getRenderer();
3725   vtkActorCollection *anActColl = aRen->GetActors();
3726   vtkActor *anActor;
3727   VISU_Actor* anVISUActor = NULL;
3728   VISU_Actor* aResActor = NULL;
3729   long aSrcAddr = (long) thePrs;
3730   for(anActColl->InitTraversal(); (anActor = anActColl->GetNextActor()) != NULL; ){
3731     if(anActor->IsA("VISU_Actor")){ 
3732       anVISUActor = VISU_Actor::SafeDownCast(anActor);
3733       long aCurrAddr = (long) anVISUActor->getPrs3d();      
3734       if (aSrcAddr == aCurrAddr) {
3735         return anVISUActor;
3736       }
3737     }
3738   }
3739   return NULL;
3740 }
3741
3742 /** 
3743  * Displays only actor of given presentation
3744  * Creates it if it is abcent
3745  */
3746 VISU_Actor* VisuGUI::UpdateViewer(VISU::Prs3d_i* thePrs, bool theDispOnly){
3747   VTKViewer_ViewFrame* vf = GetVtkViewFrame();
3748   if (!vf) return NULL;
3749
3750   vtkRenderer *aRen = vf->getRenderer();
3751   vtkActorCollection *anActColl = aRen->GetActors();
3752
3753   vtkActor *anActor;
3754   VISU_Actor* anVISUActor = NULL;
3755   VISU_Actor* aResActor = NULL;
3756   long aSrcAddr = (long) thePrs;
3757   for(anActColl->InitTraversal(); (anActor = anActColl->GetNextActor()) != NULL; ){
3758     if(anActor->IsA("VISU_Actor")){ 
3759       anVISUActor = VISU_Actor::SafeDownCast(anActor);
3760       long aCurrAddr = (long) anVISUActor->getPrs3d();      
3761       if (aSrcAddr == aCurrAddr) {
3762         aResActor = anVISUActor;
3763         aResActor->VisibilityOn();
3764         if ( aResActor->VisuActorType == VisuActorType_Mesh ) {
3765           if ( aResActor->GetProperty()->GetRepresentation() == 2 && !aResActor->IsShrunk )
3766             aResActor->EdgeDevice->VisibilityOn();
3767           else 
3768             aResActor->EdgeDevice->VisibilityOff();
3769         }
3770         if (aResActor->HasScalarBar())
3771           aResActor->getScalarBar()->VisibilityOn();
3772       } else if (theDispOnly) {
3773         anVISUActor->VisibilityOff();
3774         if ( anVISUActor->VisuActorType == VisuActorType_Mesh) {
3775           anVISUActor->EdgeDevice->VisibilityOff();
3776         }
3777         if (anVISUActor->HasScalarBar())
3778           anVISUActor->getScalarBar()->VisibilityOff();
3779       }
3780     } 
3781   }
3782   if (aResActor) return aResActor;
3783 #ifdef CHECKTIME
3784   OSD_Timer timer;
3785   timer.Start();
3786 #endif
3787   anVISUActor = thePrs->CreateActor();
3788   MESSAGE("UpdateViewer - thePrs->CreateActor() = "<<anVISUActor);
3789   if ( anVISUActor ) {
3790     vf->AddActor(anVISUActor);
3791     if(anVISUActor->HasScalarBar()){
3792       aRen->AddActor2D(anVISUActor->getScalarBar());
3793     }
3794   } else 
3795     QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("VISU_WARNING"),
3796                             tr ("Can't visulize current object"),
3797                             tr ("VISU_BUT_OK") );
3798 #ifdef CHECKTIME
3799   timer.Stop();
3800   MESSAGE("Cheking time in VisuGUI::UpdateViewer - thePrs->CreateActor + vf->AddActor + aRen->AddActor2D");
3801   timer.Show();
3802 #endif
3803   return anVISUActor;
3804 }
3805
3806
3807 /** 
3808  * Returns TRUE if Presentation is displayed                                               
3809  */
3810 bool VisuGUI::IsDisplayed(VISU::Prs3d_i* thePrs) {
3811   VISU_Actor* anVISUActor = GetActor(thePrs);
3812   return (anVISUActor)? anVISUActor->GetVisibility() : false;
3813 }
3814
3815 /** 
3816  * Erases Presentation
3817  */
3818 void VisuGUI::ErasePrs(VISU::Prs3d_i* thePrs) {
3819   myActiveStudy->unHighlightAll();
3820   VISU_Actor* anVISUActor = GetActor(thePrs);
3821   if (anVISUActor) {
3822     anVISUActor->VisibilityOff();
3823     if ( anVISUActor->VisuActorType == VisuActorType_Mesh )
3824       anVISUActor->EdgeDevice->VisibilityOff();
3825     if (anVISUActor->HasScalarBar())
3826       anVISUActor->getScalarBar()->VisibilityOff();
3827   }
3828 }
3829
3830 /**
3831  * Deletes given presentation from Data structure
3832  */
3833 void VisuGUI::DeletePresentation(VISU::Prs3d_i* thePrs) {
3834   if (checkLock(myStudy)) return;
3835   if (!thePrs) return;
3836   
3837   myActiveStudy->unHighlightAll();
3838
3839   vtkActor *anActor;
3840   VISU_Actor* aVISUActor = NULL;
3841   long aSrcAddr = (long) thePrs;
3842   int nbFrames = myActiveStudy->getStudyFramesCount();
3843   QAD_StudyFrame* aFrame;
3844   
3845   for(int i=0; i<nbFrames; i++) {
3846     aFrame = myActiveStudy->getStudyFrame(i);
3847     if(!aFrame || aFrame->getTypeView() != VIEW_VTK) continue;
3848     vtkRenderer* aRen = ((VTKViewer_ViewFrame*)aFrame->getRightFrame()->getViewFrame())->getRenderer();
3849     vtkActorCollection *anActColl = aRen->GetActors();
3850     
3851     for(anActColl->InitTraversal(); (anActor = anActColl->GetNextActor()) != NULL; ){
3852       if(anActor->IsA("VISU_Actor")) { 
3853         aVISUActor = VISU_Actor::SafeDownCast(anActor);
3854         if (aSrcAddr == ((long) aVISUActor->getPrs3d())) {
3855           if (aVISUActor->HasScalarBar())
3856             aRen->RemoveActor(aVISUActor->getScalarBar());
3857           aRen->RemoveActor(aVISUActor);
3858           aVISUActor->EdgeDevice->Delete();
3859           aVISUActor->Delete();
3860           aVISUActor = NULL;
3861         }
3862       }
3863     }
3864   }  
3865   SALOMEDS::SObject_var aSObj = myStudy->FindObjectID(thePrs->GetEntry());
3866   if(aSObj->_is_nil()) return;
3867   myStudyBuilder->RemoveObject(aSObj);
3868   myActiveStudy->updateObjBrowser(); //update Object browser
3869 }
3870
3871 /**
3872  * Creates new actor of presentation
3873  */
3874 void VisuGUI::CreateActor(VISU::Prs3d_i* thePrs) {
3875  if (!thePrs) return;
3876   QApplication::setOverrideCursor( Qt::waitCursor );
3877   VTKViewer_ViewFrame* vf = GetVtkViewFrame();
3878   if (vf) {
3879 #ifdef CHECKTIME
3880     OSD_Timer timer;
3881     timer.Start();
3882 #endif
3883     VISU_Actor* aActor = thePrs->CreateActor();
3884     if ( ! aActor ) {
3885       QApplication::restoreOverrideCursor();
3886       QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("VISU_WARNING"),
3887                              tr ("The presentation can't be visualized.\n Null actor is created."),
3888                              tr ("VISU_BUT_OK") );
3889       return;
3890     }
3891 #ifdef CHECKTIME
3892     timer.Stop();
3893     MESSAGE("Cheking time in VisuGUI::CreateActor - thePrs->CreateActor");
3894     timer.Show();
3895 #endif
3896     vtkRenderer *aRenderer = vf->getRenderer();
3897     //visuGUI->ClearViewer(QAD_Application::getDesktop(), aRenderer, -1);
3898     //visuGUI->ShowTrihedron(true);
3899 #ifdef CHECKTIME
3900     timer.Reset();
3901     timer.Start();
3902 #endif
3903     vf->AddActor(aActor);
3904     if (aActor->HasScalarBar())
3905       aRenderer->AddActor2D(aActor->getScalarBar());
3906 #ifdef CHECKTIME
3907     timer.Stop();
3908     MESSAGE("Cheking time in VisuGUI::CreateActor - vf->AddActor");
3909     timer.Show();
3910 #endif
3911   }
3912   QApplication::restoreOverrideCursor();
3913 }
3914
3915
3916
3917 /* ======================================================================================== */
3918 /* Functions to State of VisuGUI and Dialog Box                                             */
3919 /* ======================================================================================== */
3920
3921 void VisuGUI::SetState(int aState )
3922 {  
3923         this->myState = aState ;  
3924         return ; 
3925 }
3926
3927
3928 void VisuGUI::ResetState()
3929 {  
3930         this->myState = -1 ;  
3931         return ; 
3932 }
3933
3934 void VisuGUI::EmitSignalDeactivateDialog()
3935 {
3936         emit this->SignalDeactivateActiveDialog() ;
3937         return ;
3938 }
3939
3940 void VisuGUI::EmitSignalCloseAllDialogs()
3941 {
3942         emit this->SignalCloseAllDialogs() ;
3943         return ;
3944 }
3945
3946 QDialog* VisuGUI::GetActiveDialogBox()
3947 {
3948         return this->myActiveDialogBox ;
3949 }
3950
3951 void VisuGUI::SetActiveDialogBox(QDialog* aDlg)
3952 {
3953         this->myActiveDialogBox = (QDialog*)aDlg ;
3954         return ;
3955 }
3956
3957 QAD_Study* VisuGUI::GetActiveStudy()
3958 {
3959         return this->myActiveStudy ;
3960 }
3961
3962 QAD_Desktop* VisuGUI::GetDesktop()
3963 {
3964         return this->myDesktop ;
3965 }