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