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