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