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