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