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