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