Salome HOME
first update of those files to administrate the integration of Netgen in the
[modules/smesh.git] / src / SMESHGUI / SMESHGUI.cxx
1 //  SMESH SMESHGUI : GUI for SMESH 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   : SMESHGUI.cxx
25 //  Author : Nicolas REJNERI
26 //  Module : SMESH
27 //  $Header$
28
29 using namespace std;
30 #include "SMESHGUI.h"
31 #include "SMESHGUI_AddHypothesisDlg.h"
32 #include "SMESHGUI_AddAlgorithmDlg.h"
33 #include "SMESHGUI_InitMeshDlg.h"
34 #include "SMESHGUI_LocalLengthDlg.h"
35 #include "SMESHGUI_NbSegmentsDlg.h"
36 #include "SMESHGUI_AddSubMeshDlg.h"
37 #include "SMESHGUI_NodesDlg.h"
38 #include "SMESHGUI_TransparencyDlg.h"
39 #include "SMESHGUI_RemoveNodesDlg.h"
40 #include "SMESHGUI_RemoveElementsDlg.h"
41 #include "SMESHGUI_MeshInfosDlg.h"
42 #include "SMESHGUI_Preferences_ColorDlg.h"
43 #include "SMESHGUI_MaxElementAreaDlg.h"
44 #include "SMESHGUI_MaxElementVolumeDlg.h"
45 #include "SMESHGUI_Preferences_ScalarBarDlg.h"
46 #include "SMESHGUI_EditScalarBarDlg.h"
47 #include "SMESHGUI_aParameterDlg.h"
48 #include "SMESHGUI_ComputeScalarValue.h"
49 #include "SMESHGUI_MoveNodesDlg.h"
50 #include "SMESHGUI_OrientationElementsDlg.h"
51 #include "SMESHGUI_DiagonalInversionDlg.h"
52 #include "SMESHGUI_EdgesConnectivityDlg.h"
53 #include "SMESHGUI_AddFaceDlg.h"
54 #include "SMESHGUI_AddEdgeDlg.h"
55 #include "SMESHGUI_AddVolumeDlg.h"
56 #include "SMESHGUI_EditHypothesesDlg.h"
57
58 #include "SMESH_Grid.h"
59
60 // SALOME Includes
61 #include "Utils_ORB_INIT.hxx"
62 #include "Utils_SINGLETON.hxx"
63
64 #include "QAD.h"
65 #include "QAD_Tools.h"
66 #include "QAD_Config.h"
67 #include "QAD_Settings.h"
68 #include "QAD_RightFrame.h"
69 #include "QAD_MessageBox.h"   
70 #include "QAD_Resource.h"
71 #include "QAD_FileDlg.h"
72 #include "SALOMEGUI_Desktop.h"
73 #include "SALOMEGUI_NameDlg.h"
74
75 #include "OCCViewer_ViewPort.h"
76 #include "OCCViewer_ViewPort3d.h"
77 #include "OCCViewer_Viewer3d.h"
78
79 #include "GEOM_Client.hxx"
80 #include "GEOM_InteractiveObject.hxx"
81
82 #include "SALOME_NamingService.hxx"
83 #include "SALOME_ListIteratorOfListIO.hxx"
84 #include "SALOME_InteractiveObject.hxx"
85
86 #include "SALOMEGUI_ImportOperation.h"
87 #include "SALOMEGUI_QtCatchCorbaException.hxx"
88 #include "utilities.h"
89
90 #include "SMDS_Mesh.hxx"
91 #include "SMESHDS_Document.hxx"
92 #include "Document_Reader.h"
93 #include "Document_Writer.h"
94 #include "Mesh_Reader.h"
95 #include "Mesh_Writer.h"
96
97 #include "DriverDAT_R_SMESHDS_Document.h"
98 #include "DriverMED_R_SMESHDS_Document.h"
99 #include "DriverUNV_R_SMESHDS_Document.h"
100 #include "DriverDAT_W_SMESHDS_Document.h"
101 #include "DriverMED_W_SMESHDS_Document.h"
102 #include "DriverUNV_W_SMESHDS_Document.h"
103 #include "DriverDAT_R_SMESHDS_Mesh.h"
104 #include "DriverMED_R_SMESHDS_Mesh.h"
105 #include "DriverUNV_R_SMESHDS_Mesh.h"
106 #include "DriverDAT_W_SMESHDS_Mesh.h"
107 #include "DriverMED_W_SMESHDS_Mesh.h"
108 #include "DriverUNV_W_SMESHDS_Mesh.h"
109
110 // QT Includes
111 #define  INCLUDE_MENUITEM_DEF
112 #include <qapplication.h>
113 #include <qlineedit.h>
114 #include <qmenudata.h>
115 #include <qmenubar.h>
116 #include <qpopupmenu.h>
117 #include <qfont.h>
118 #include <qstring.h>
119 #include <qcheckbox.h>
120 #include <qcolordialog.h>
121 #include <qmessagebox.h>
122 #include <qspinbox.h>
123 #include <qlist.h>
124 #include <qwidget.h> 
125 #include <qevent.h> 
126 #include <qradiobutton.h> 
127
128 // VTK Includes
129 #include "VTKViewer_Common.h"
130 #include "VTKViewer_ViewFrame.h"
131 #include <vtkLegendBoxActor.h>
132 #include <vtkFeatureEdges.h>
133
134
135 // Open CASCADE Includes
136 #include <gp_Pnt.hxx>
137 #include <gp_Vec.hxx>
138
139 static GEOM_Client      ShapeReader;
140 static SMESHGUI*        smeshGUI = 0;
141 static CORBA::ORB_var   _orb;
142
143
144 //=============================================================================
145 /*!
146  *
147  */
148 //=============================================================================
149 class CustomItem : public QCustomMenuItem
150 {
151 public:
152   CustomItem( const QString& s, const QFont& f )
153     : string( s ), font( f ){};
154   ~CustomItem(){}
155   
156   void paint( QPainter* p, const QColorGroup& /*cg*/, bool /*act*/, bool /*enabled*/, int x, int y, int w, int h )
157   {
158     p->setFont ( font );
159     p->drawText( x, y, w, h, AlignHCenter | AlignVCenter | ShowPrefix | DontClip, string );
160   }
161   
162   QSize sizeHint()
163   {
164     return QFontMetrics( font ).size( AlignHCenter | AlignVCenter | ShowPrefix | DontClip,  string );
165   }
166 private:
167   QString string;
168   QFont font;
169 };
170
171 //=============================================================================
172 /*!
173  *
174  */
175 //=============================================================================
176 SMESHGUI::SMESHGUI() :
177   QObject()
178 {
179 }
180
181 //=============================================================================
182 /*!
183  *
184  */
185 //=============================================================================
186 SMESHGUI::~SMESHGUI()
187 {
188 }
189
190
191 //=============================================================================
192 /*!
193  *
194  */
195 //=============================================================================
196 SMESHGUI* SMESHGUI::GetSMESHGUI( )
197 {
198   return smeshGUI;
199 }
200
201 //=============================================================================
202 /*!
203  *
204  */
205 //=============================================================================
206 SMESHGUI* SMESHGUI::GetOrCreateSMESHGUI( QAD_Desktop* desktop )
207 {
208   if( smeshGUI == 0 ) {
209     setOrb();
210     smeshGUI = new SMESHGUI;
211     smeshGUI->myActiveDialogBox = 0 ;
212     smeshGUI->myState = -1 ;
213     smeshGUI->myDesktop = desktop ; 
214     smeshGUI->myActiveStudy = desktop->getActiveStudy();
215
216     Engines::Component_var comp = desktop->getEngine("FactoryServer", "SMESH");
217     smeshGUI->myComponentMesh = SMESH::SMESH_Gen::_narrow(comp);
218     
219     Engines::Component_var comp1 = desktop->getEngine("FactoryServer", "GEOM");    
220     smeshGUI->myComponentGeom = GEOM::GEOM_Gen::_narrow(comp1);
221       
222     /* GetCurrentStudy */
223     smeshGUI->myStudyId = smeshGUI->myActiveStudy->getStudyId();
224     
225     smeshGUI->myComponentGeom->GetCurrentStudy( smeshGUI->myStudyId );
226     //    smeshGUI->myComponentGeom->NbLabels();
227     
228     smeshGUI->myStudy = smeshGUI->myActiveStudy->getStudyDocument();
229     
230     smeshGUI->myStudyAPI = SMESHGUI_StudyAPI(smeshGUI->myStudy, smeshGUI->myComponentMesh);
231
232     smeshGUI->myDocument = new SMESHDS_Document(1);//NBU
233
234     smeshGUI->mySimulationActors = vtkActorCollection::New();
235     smeshGUI->mySimulationActors2D = vtkActor2DCollection::New();
236   } else {
237     /* study may have changed */
238     smeshGUI->myActiveStudy = desktop->getActiveStudy();
239     smeshGUI->myStudyAPI.Update(smeshGUI->myComponentMesh);
240   }
241   
242   /* Automatic Update */
243   if ( desktop->menuBar()->isItemChecked(1001) )
244     smeshGUI->myAutomaticUpdate = true;
245   else 
246     smeshGUI->myAutomaticUpdate = false;
247
248   return smeshGUI;
249 }
250
251 //=============================================================================
252 /*!
253  *
254  */
255 //=============================================================================
256 void SMESHGUI::SetState(int aState )
257 {  this->myState = aState ;  return ; }
258
259
260 //=============================================================================
261 /*!
262  *
263  */
264 //=============================================================================
265 void SMESHGUI::ResetState()
266 {  this->myState = -1 ;  return ; }
267
268
269 //=============================================================================
270 /*!
271  *
272  */
273 //=============================================================================
274 void SMESHGUI::EmitSignalDeactivateDialog()
275 {
276   emit this->SignalDeactivateActiveDialog() ;
277   return ;
278 }
279
280 //=============================================================================
281 /*!
282  *
283  */
284 //=============================================================================
285 void SMESHGUI::EmitSignalCloseAllDialogs()
286 {
287   emit this->SignalCloseAllDialogs() ;
288   return ;
289 }
290
291
292 //=============================================================================
293 /*!
294  *
295  */
296 //=============================================================================
297 QDialog* SMESHGUI::GetActiveDialogBox()
298 {
299   return this->myActiveDialogBox ;
300 }
301
302 //=============================================================================
303 /*!
304  *
305  */
306 //=============================================================================
307 void SMESHGUI::SetActiveDialogBox(QDialog* aDlg)
308 {
309   this->myActiveDialogBox = (QDialog*)aDlg ;
310   return ;
311 }
312
313
314 //=============================================================================
315 /*!
316  *
317  */
318 //=============================================================================
319 QAD_Study* SMESHGUI::GetActiveStudy()
320 {
321   return this->myActiveStudy ;
322 }
323
324
325 //=============================================================================
326 /*!
327  *
328  */
329 //=============================================================================
330 SALOMEDS::Study_ptr SMESHGUI::GetStudy()
331 {
332   return SALOMEDS::Study::_narrow( myStudy );
333 }
334
335 //=============================================================================
336 /*!
337  *
338  */
339 //=============================================================================
340 SMESHGUI_StudyAPI SMESHGUI::GetStudyAPI()
341 {
342   return myStudyAPI;
343 }
344
345 //=============================================================================
346 /*!
347  *
348  */
349 //=============================================================================
350 QAD_Desktop* SMESHGUI::GetDesktop()
351 {
352   return this->myDesktop ;
353 }
354
355 //=============================================================================
356 /*!
357  *
358  */
359 //=============================================================================
360 vtkScalarBarActor* SMESHGUI::GetScalarBar()
361 {
362   vtkRenderer* aRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
363   vtkActor2DCollection* actor2DList = aRenderer->GetActors2D();
364   actor2DList->InitTraversal();
365   vtkActor2D* aActor2d =  actor2DList->GetNextActor2D();
366   while (aActor2d != NULL) {
367     if (aActor2d->IsA("vtkScalarBarActor"))
368       return vtkScalarBarActor::SafeDownCast(aActor2d);
369     actor2DList->GetNextActor2D();
370   }
371   return NULL;
372 }
373
374 //=============================================================================
375 /*!
376  *
377  */
378 //=============================================================================
379 void SMESHGUI::activeStudyChanged( QAD_Desktop* parent )
380 {
381   MESSAGE ("SMESHGUI::activeStudyChanged init.")
382   /* Create or retrieve an object SMESHGUI */
383   SMESHGUI::GetOrCreateSMESHGUI(parent); 
384   if(smeshGUI != 0) {  
385     smeshGUI->EmitSignalCloseAllDialogs() ;
386     MESSAGE( "Active study changed : SMESHGUI nullified" << endl ) ;
387     smeshGUI = 0 ;
388   }
389
390   //smeshGUI->SetSettings( parent ); //DCQ : Pb. Multi-Etudes
391   MESSAGE ("SMESHGUI::activeStudyChanged done.")
392   return ;
393 }
394
395 //=============================================================================
396 /*!
397  *
398  */
399 //=============================================================================
400 bool SMESHGUI::DefineDlgPosition(QWidget* aDlg, int& x, int& y)
401 {
402   /* Here the position is on the bottom right corner - 10 */
403   QAD_Desktop* PP = QAD_Application::getDesktop() ;
404   x = abs ( PP->x() + PP->size().width()  - aDlg->size().width()  - 10 ) ;
405   y = abs ( PP->y() + PP->size().height() - aDlg->size().height() - 10 ) ;
406   return true ;  
407 }
408
409
410 //=============================================================================
411 /*!
412  *
413  */
414 //=============================================================================
415 void SMESHGUI::EraseSimulationActors()
416 {
417   if ( myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) {  //VTK
418     vtkRenderer* theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
419     vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
420
421     if ( mySimulationActors != NULL ) {
422
423       mySimulationActors->InitTraversal();
424       vtkActor *ac = mySimulationActors->GetNextActor();
425       while(!(ac==NULL)) {
426         theRenderer->RemoveActor(ac);
427         ac = mySimulationActors->GetNextActor();
428       }
429       mySimulationActors->RemoveAllItems();
430     }
431     if ( mySimulationActors2D != NULL ) {
432       mySimulationActors2D->InitTraversal();
433       vtkActor2D *ac = mySimulationActors2D->GetNextActor2D();
434       while(!(ac==NULL)) {
435         theRenderer->RemoveActor2D(ac);
436         ac = mySimulationActors2D->GetNextActor2D();
437       }
438       mySimulationActors2D->RemoveAllItems();
439     }
440     renWin->Render();
441   }
442 }
443
444 //=============================================================================
445 /*!
446  *
447  */
448 //=============================================================================
449 SMESH::SMESH_Mesh_ptr SMESHGUI::InitMesh( GEOM::GEOM_Shape_ptr aShape, QString NameMesh )
450 {
451   try {
452     if ( !myComponentMesh->_is_nil() && !aShape->_is_nil() ) {
453       SMESH::SMESH_Mesh_var aMesh = myComponentMesh->Init( myComponentGeom, myStudyId, aShape);
454
455       if ( !aMesh->_is_nil() ) {
456         SALOMEDS::SObject_var SM = myStudyAPI.AddNewMesh ( aMesh );
457         myStudyAPI.SetName( SM, NameMesh );
458           
459         // GEOM::GEOM_Shape has non-empty StudyShapeId only after AddInStudy operation,
460         // not after loading from file, so let's use more reliable way to retrieve SObject
461         Standard_CString ShapeIOR = _orb->object_to_string(aShape);
462         SALOMEDS::SObject_var SObject = myStudy->FindObjectIOR(ShapeIOR);
463         if ( !SObject->_is_nil() && !SM->_is_nil() ) {
464           myStudyAPI.SetShape( SM, SObject );
465         }
466         return SMESH::SMESH_Mesh::_narrow(aMesh);
467       }
468     }
469   }
470   catch  (const SALOME::SALOME_Exception& S_ex) {
471     QtCatchCorbaException(S_ex);
472   }
473   myActiveStudy->updateObjBrowser(true);
474   return SMESH::SMESH_Mesh::_nil();
475 }
476
477 //=============================================================================
478 /*!
479  *
480  */
481 //=============================================================================
482 SMESH::SMESH_subMesh_ptr SMESHGUI::AddSubMesh( SMESH::SMESH_Mesh_ptr aMesh, GEOM::GEOM_Shape_ptr aShape, QString NameMesh )
483 {
484   try {
485     SMESH::SMESH_subMesh_var aSubMesh = aMesh->GetElementsOnShape(aShape);
486     SALOMEDS::SObject_var SO_Mesh = myStudyAPI.FindMesh(aMesh);
487     Standard_CString ShapeIOR = _orb->object_to_string(aShape);
488     SALOMEDS::SObject_var SO_GeomShape = myStudy->FindObjectIOR(ShapeIOR);
489     
490     if ( !SO_GeomShape->_is_nil() && !SO_Mesh->_is_nil() && !aSubMesh->_is_nil() && !aMesh->_is_nil() ) {
491       SALOMEDS::SObject_var SO = myStudyAPI.AddSubMeshOnShape(SO_Mesh, SO_GeomShape, aSubMesh, aShape->ShapeType() );
492       myStudyAPI.SetName(SO, NameMesh);
493     
494       SMESH_Actor* amesh = SMESH_Actor::New();
495       Handle(SALOME_InteractiveObject) IO = new SALOME_InteractiveObject(SO->GetID(),
496                                                                          "MESH",
497                                                                          strdup(NameMesh));
498       amesh->setIO( IO );
499       amesh->setName( strdup(NameMesh) );
500       DisplayActor(amesh, false);
501       return SMESH::SMESH_subMesh::_narrow( aSubMesh );
502     }
503   }
504   catch  (const SALOME::SALOME_Exception& S_ex) {
505     QtCatchCorbaException(S_ex);
506   }
507   myActiveStudy->updateObjBrowser(true);
508   return SMESH::SMESH_subMesh::_nil();
509 }
510
511
512 //=============================================================================
513 /*!
514  *
515  */
516 //=============================================================================
517 SMESH::SMESH_Hypothesis_ptr SMESHGUI::CreateHypothesis( QString TypeHypothesis, 
518                                                         QString NameHypothesis )
519 {
520   SMESH::SMESH_Hypothesis_var Hyp;
521   try {
522     Hyp = myComponentMesh->CreateHypothesis( TypeHypothesis, myStudyId );
523     if ( !Hyp->_is_nil() ) {
524       SALOMEDS::SObject_var SHyp = myStudyAPI.AddNewHypothesis( Hyp );
525       myStudyAPI.SetName( SHyp, NameHypothesis);
526     }
527   }
528   catch  (const SALOME::SALOME_Exception& S_ex) {
529     QtCatchCorbaException(S_ex);
530   }
531
532   return SMESH::SMESH_Hypothesis::_narrow( Hyp );
533 }
534
535 //=============================================================================
536 /*!
537  *
538  */
539 //=============================================================================
540 void SMESHGUI::AddHypothesisOnMesh( SMESH::SMESH_Mesh_ptr aMesh, SMESH::SMESH_Hypothesis_ptr aHyp )
541 {
542   if ( !aMesh->_is_nil() ) {
543     QApplication::setOverrideCursor( Qt::waitCursor );
544     SALOMEDS::SObject_var SM = myStudyAPI.FindMesh( aMesh );
545     GEOM::GEOM_Shape_var aShape = myStudyAPI.GetShapeOnMeshOrSubMesh( SM );
546     try {
547       bool res = aMesh->AddHypothesis( aShape, aHyp );
548       if (res) {
549         SALOMEDS::SObject_var SH = myStudyAPI.FindHypothesisOrAlgorithms( aHyp );
550         if ( !SM->_is_nil() && !SH->_is_nil() ) {
551           myStudyAPI.SetHypothesis( SM, SH );
552           myStudyAPI.ModifiedMesh( SM, false );
553         }
554         QApplication::restoreOverrideCursor();
555       } else {
556         QApplication::restoreOverrideCursor();
557         QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
558                                 tr ("SMESH_WRN_HYPOTHESIS_ALREADYEXIST"), tr ("SMESH_BUT_YES") );
559       }
560     }
561     catch  (const SALOME::SALOME_Exception& S_ex) {
562       QtCatchCorbaException(S_ex);
563     }
564   }
565   myActiveStudy->updateObjBrowser(true);
566   QApplication::restoreOverrideCursor();
567 }
568
569 //=============================================================================
570 /*!
571  *
572  */
573 //=============================================================================
574 void SMESHGUI::RemoveHypothesisOrAlgorithmOnMesh( const Handle(SALOME_InteractiveObject)& IObject )
575 {
576   if ( IObject->hasReference() ) {
577     SMESH::SMESH_Hypothesis_var anHyp;
578     SALOMEDS::SObject_var SO_Hypothesis = smeshGUI->myStudy->FindObjectID(IObject->getEntry() );
579     SALOMEDS::GenericAttribute_var anAttr;
580     SALOMEDS::AttributeIOR_var     anIOR;
581
582     if ( !SO_Hypothesis->_is_nil() ) {
583       QApplication::setOverrideCursor( Qt::waitCursor );
584       if (SO_Hypothesis->FindAttribute(anAttr, "AttributeIOR")) {
585         anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
586         anHyp = SMESH::SMESH_Hypothesis::_narrow( _orb->string_to_object(anIOR->Value()) );
587       }
588
589       SALOMEDS::SObject_var SO_Applied_Hypothesis = smeshGUI->myStudy->FindObjectID(IObject->getReference());
590       if ( !SO_Applied_Hypothesis->_is_nil() ) {
591         SALOMEDS::SObject_var MorSM = smeshGUI->myStudyAPI.GetMeshOrSubmesh( SO_Applied_Hypothesis );
592         if ( !MorSM->_is_nil() ) {
593           smeshGUI->myStudyAPI.ModifiedMesh( MorSM, false );
594
595           GEOM::GEOM_Shape_var aShape = smeshGUI->myStudyAPI.GetShapeOnMeshOrSubMesh( MorSM );
596           if ( !aShape->_is_nil() ) {
597             if (MorSM->FindAttribute(anAttr, "AttributeIOR")) {
598               anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
599               SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow( _orb->string_to_object(anIOR->Value()) );
600               SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow( _orb->string_to_object(anIOR->Value()) );
601               if ( !aMesh->_is_nil() ) {
602                 bool res = aMesh->RemoveHypothesis( aShape, anHyp );
603                 if ( !res ) {
604                   QApplication::restoreOverrideCursor();
605                   QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
606                                           tr ("SMESH_WRN_HYPOTHESIS_NOTEXIST"), tr ("SMESH_BUT_YES") );
607                 }
608               } else if ( !aSubMesh->_is_nil() ) {
609                 aMesh = aSubMesh->GetFather();
610                 if ( !aMesh->_is_nil() ) {
611                   bool res = aMesh->RemoveHypothesis( aShape, anHyp );
612                   if ( !res ) {
613                     QApplication::restoreOverrideCursor();
614                     QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
615                                             tr ("SMESH_WRN_HYPOTHESIS_NOTEXIST"), tr ("SMESH_BUT_YES") );
616                   }
617                 }
618               }
619               if ( myAutomaticUpdate ) {
620                 SMESH_Actor* Mesh = smeshGUI->ReadScript(aMesh);
621                 if ( Mesh != NULL ) {
622 #ifdef TRACE
623                   Dump( Mesh );
624 #endif
625                   DisplayActor( Mesh );
626                   DisplayEdges( Mesh ); 
627                   smeshGUI->ChangeRepresentation( Mesh, Mesh->getDisplayMode() );
628                 }
629               }
630             }
631           }
632         }
633         smeshGUI->myStudyAPI.UnSetHypothesis( SO_Applied_Hypothesis );
634       }
635     }    
636   } else if ( IObject->hasEntry() ) {
637     MESSAGE ( "IObject entry " << IObject->getEntry() )    
638   }
639   QApplication::restoreOverrideCursor();
640 }
641
642 //=============================================================================
643 /*!
644  *
645  */
646 //=============================================================================
647 void SMESHGUI::RemoveHypothesisOrAlgorithmOnMesh( SALOMEDS::SObject_ptr MorSM, SMESH::SMESH_Hypothesis_ptr anHyp )
648 {
649   SALOMEDS::SObject_var             AHR, aRef;
650   SALOMEDS::GenericAttribute_var    anAttr;
651   SALOMEDS::AttributeIOR_var        anIOR;
652
653   if ( !MorSM->_is_nil() ) {
654     GEOM::GEOM_Shape_var aShape = smeshGUI->myStudyAPI.GetShapeOnMeshOrSubMesh( MorSM );
655     if ( !aShape->_is_nil() ) {
656       if (MorSM->FindAttribute(anAttr, "AttributeIOR")) {
657         anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
658         SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow( _orb->string_to_object(anIOR->Value()) );
659         SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow( _orb->string_to_object(anIOR->Value()) );
660         if ( !aMesh->_is_nil() ) {
661           bool res = aMesh->RemoveHypothesis( aShape, anHyp );
662           if ( !res ) {
663             QApplication::restoreOverrideCursor();
664             QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
665                                     tr ("SMESH_WRN_HYPOTHESIS_NOTEXIST"), tr ("SMESH_BUT_YES") );
666           }
667         } else if ( !aSubMesh->_is_nil() ) {
668           aMesh = aSubMesh->GetFather();
669           if ( !aMesh->_is_nil() ) {
670             bool res = aMesh->RemoveHypothesis( aShape, anHyp );
671             if ( !res ) {
672               QApplication::restoreOverrideCursor();
673               QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
674                                       tr ("SMESH_WRN_HYPOTHESIS_NOTEXIST"), tr ("SMESH_BUT_YES") );
675             }
676           }
677         }
678         if ( myAutomaticUpdate ) {
679           SMESH_Actor* Mesh = smeshGUI->ReadScript(aMesh);
680           if ( Mesh != NULL ) {
681 #ifdef TRACE
682             Dump( Mesh );
683 #endif
684             DisplayActor( Mesh );
685             DisplayEdges( Mesh ); 
686             // smeshGUI->ChangeRepresentation( Mesh, Mesh->getDisplayMode() );
687           }
688         }
689       }
690     }
691
692     if ( MorSM->FindSubObject (2, AHR)) {
693       SALOMEDS::ChildIterator_var it = myStudy->NewChildIterator(AHR);
694       for (; it->More();it->Next()) {
695         SALOMEDS::SObject_var Obj = it->Value();
696         if ( Obj->ReferencedObject(aRef) ) {
697           if (aRef->FindAttribute(anAttr, "AttributeIOR")) {
698             anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
699             if ( strcmp( anIOR->Value(), _orb->object_to_string(anHyp) ) == 0 ) {
700               smeshGUI->myStudyAPI.UnSetHypothesis( Obj );
701               break;
702             }
703           }
704         }
705       }
706     }
707     if ( MorSM->FindSubObject (3, AHR)) {
708       SALOMEDS::ChildIterator_var it = myStudy->NewChildIterator(AHR);
709       for (; it->More();it->Next()) {
710         SALOMEDS::SObject_var Obj = it->Value();
711         if ( Obj->ReferencedObject(aRef) ) {
712           if (aRef->FindAttribute(anAttr, "AttributeIOR")) {
713             anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
714             if ( strcmp( anIOR->Value(), _orb->object_to_string(anHyp) ) == 0 ) {
715               smeshGUI->myStudyAPI.UnSetAlgorithm( Obj );
716               break;
717             }
718           }
719         }
720       }
721     }    
722    smeshGUI->myStudyAPI.ModifiedMesh( MorSM, false );
723   } 
724   QApplication::restoreOverrideCursor();
725 }
726
727 //=============================================================================
728 /*!
729  *
730  */
731 //=============================================================================
732 void SMESHGUI::AddAlgorithmOnMesh( SMESH::SMESH_Mesh_ptr aMesh, SMESH::SMESH_Hypothesis_ptr aHyp )
733 {
734   if ( !aMesh->_is_nil() ) {
735     QApplication::setOverrideCursor( Qt::waitCursor );
736     SALOMEDS::SObject_var SM = myStudyAPI.FindMesh( aMesh );
737     GEOM::GEOM_Shape_var aShape = myStudyAPI.GetShapeOnMeshOrSubMesh( SM );
738     try {
739       bool res = aMesh->AddHypothesis( aShape, aHyp );
740       if (res) {
741         SALOMEDS::SObject_var SH = myStudyAPI.FindHypothesisOrAlgorithms( aHyp );
742         if ( !SM->_is_nil() && !SH->_is_nil() ) { 
743           myStudyAPI.SetAlgorithms( SM, SH );    
744           myStudyAPI.ModifiedMesh( SM, false );
745         }
746       } else {
747         QApplication::restoreOverrideCursor();
748         QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
749                                 tr ("SMESH_WRN_ALGORITHM_ALREADYEXIST"), tr ("SMESH_BUT_YES") );
750       }
751     }
752     catch  (const SALOME::SALOME_Exception& S_ex) {
753       QtCatchCorbaException(S_ex);
754     }
755   }
756   myActiveStudy->updateObjBrowser(true);
757   QApplication::restoreOverrideCursor();
758 }
759
760 //=============================================================================
761 /*!
762  *
763  */
764 //=============================================================================
765 void SMESHGUI::AddHypothesisOnSubMesh( SMESH::SMESH_subMesh_ptr aSubMesh, SMESH::SMESH_Hypothesis_ptr aHyp )
766 {
767   if ( !aSubMesh->_is_nil() ) {
768     QApplication::setOverrideCursor( Qt::waitCursor );
769     try {
770       SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
771       SALOMEDS::SObject_var SsubM = myStudyAPI.FindSubMesh( aSubMesh );
772       GEOM::GEOM_Shape_var aShape = myStudyAPI.GetShapeOnMeshOrSubMesh( SsubM );
773       if ( !aMesh->_is_nil() ) {
774         bool res = aMesh->AddHypothesis( aShape, aHyp );
775         if (res) {      
776           SALOMEDS::SObject_var SH = myStudyAPI.FindHypothesisOrAlgorithms( aHyp );
777           if ( !SsubM->_is_nil() && !SH->_is_nil() ) {
778             myStudyAPI.SetHypothesis( SsubM, SH );
779             myStudyAPI.ModifiedMesh( SsubM, false );
780           }
781         } else {
782           QApplication::restoreOverrideCursor();
783           QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
784                                   tr ("SMESH_WRN_HYPOTHESIS_ALREADYEXIST"), tr ("SMESH_BUT_YES") );
785         }
786       }
787     }
788     catch  (const SALOME::SALOME_Exception& S_ex) {
789       QtCatchCorbaException(S_ex);
790     }
791   }
792   myActiveStudy->updateObjBrowser(true);
793   QApplication::restoreOverrideCursor();
794 }
795
796 //=============================================================================
797 /*!
798  *
799  */
800 //=============================================================================
801 void SMESHGUI::AddAlgorithmOnSubMesh( SMESH::SMESH_subMesh_ptr aSubMesh, SMESH::SMESH_Hypothesis_ptr aHyp )
802 {
803   if ( !aSubMesh->_is_nil() ) {
804     QApplication::setOverrideCursor( Qt::waitCursor );
805     try {
806       SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
807       SALOMEDS::SObject_var SsubM = myStudyAPI.FindSubMesh( aSubMesh );
808       GEOM::GEOM_Shape_var aShape = myStudyAPI.GetShapeOnMeshOrSubMesh( SsubM );
809       if ( !aMesh->_is_nil() ) {
810         bool res = aMesh->AddHypothesis( aShape, aHyp );
811         if (res) {
812           SALOMEDS::SObject_var SH = myStudyAPI.FindHypothesisOrAlgorithms( aHyp );
813           if ( !SsubM->_is_nil() && !SH->_is_nil() ) {
814             myStudyAPI.SetAlgorithms( SsubM, SH ); 
815             myStudyAPI.ModifiedMesh( SsubM, false );
816           }
817         } else {
818           QApplication::restoreOverrideCursor();
819           QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
820                                   tr ("SMESH_WRN_ALGORITHM_ALREADYEXIST"), tr ("SMESH_BUT_YES") );
821         }
822       }
823     }
824     catch  (const SALOME::SALOME_Exception& S_ex) {
825       QtCatchCorbaException(S_ex);
826     }
827   }
828   myActiveStudy->updateObjBrowser(true);
829   QApplication::restoreOverrideCursor();
830 }
831
832 //=============================================================================
833 /*!
834  *
835  */
836 //=============================================================================
837 void SMESHGUI::CreateAlgorithm( QString TypeAlgo, QString NameAlgo )
838 {
839   SMESH::SMESH_Hypothesis_var Hyp;
840   try {
841     if ( TypeAlgo.compare("Regular_1D") == 0 )
842       Hyp = myComponentMesh->CreateHypothesis( TypeAlgo, myStudyId );
843     else if ( TypeAlgo.compare("MEFISTO_2D") == 0 )
844       Hyp = myComponentMesh->CreateHypothesis( TypeAlgo, myStudyId );
845     else if ( TypeAlgo.compare("Quadrangle_2D") == 0 )
846       Hyp = myComponentMesh->CreateHypothesis( TypeAlgo, myStudyId );
847     else if ( TypeAlgo.compare("Hexa_3D") == 0 )
848       Hyp = myComponentMesh->CreateHypothesis( TypeAlgo, myStudyId );
849     else if ( TypeAlgo.compare("Tetra_3D") == 0 )
850       Hyp = myComponentMesh->CreateHypothesis( TypeAlgo, myStudyId );
851     
852     if ( !Hyp->_is_nil() ) {
853       SALOMEDS::SObject_var SHyp = myStudyAPI.AddNewAlgorithms( Hyp );
854       myStudyAPI.SetName( SHyp, NameAlgo);
855     }
856   }
857   catch  (const SALOME::SALOME_Exception& S_ex) {
858     QtCatchCorbaException(S_ex);
859   }
860   myActiveStudy->updateObjBrowser(true);
861 }
862
863
864 //=============================================================================
865 /*!
866  *
867  */
868 //=============================================================================
869 void SMESHGUI::CreateLocalLength( QString TypeHypothesis, QString NameHypothesis, double Length )
870 {
871   QApplication::setOverrideCursor( Qt::waitCursor );
872   try {
873     SMESH::SMESH_Hypothesis_var Hyp = SMESH::SMESH_Hypothesis::_narrow( CreateHypothesis( TypeHypothesis, NameHypothesis ) );
874     SMESH::SMESH_LocalLength_var LL = SMESH::SMESH_LocalLength::_narrow( Hyp );
875     if ( !LL->_is_nil() )
876       LL->SetLength( Length );
877   }
878   catch  (const SALOME::SALOME_Exception& S_ex) {
879     QtCatchCorbaException(S_ex);
880   }
881   myActiveStudy->updateObjBrowser(true);
882   QApplication::restoreOverrideCursor();
883 }
884
885 //=============================================================================
886 /*!
887  *
888  */
889 //=============================================================================
890 void SMESHGUI::CreateMaxElementArea( QString TypeHypothesis, QString NameHypothesis, double MaxArea )
891 {
892   QApplication::setOverrideCursor( Qt::waitCursor );
893   try {
894     SMESH::SMESH_Hypothesis_var Hyp = SMESH::SMESH_Hypothesis::_narrow( CreateHypothesis( TypeHypothesis, NameHypothesis  ) );
895     SMESH::SMESH_MaxElementArea_var MaxElArea = SMESH::SMESH_MaxElementArea::_narrow( Hyp );
896     if ( !MaxElArea->_is_nil() )
897       MaxElArea->SetMaxElementArea( MaxArea );
898   }
899   catch  (SALOME::SALOME_Exception& S_ex) {
900     QtCatchCorbaException(S_ex);
901   } 
902
903   myActiveStudy->updateObjBrowser(true);
904   QApplication::restoreOverrideCursor();
905 }
906
907 //=============================================================================
908 /*!
909  *
910  */
911 //=============================================================================
912 void SMESHGUI::CreateMaxElementVolume( QString TypeHypothesis, QString NameHypothesis, double MaxVolume )
913 {
914   QApplication::setOverrideCursor( Qt::waitCursor );
915   try {
916     SMESH::SMESH_Hypothesis_var Hyp = SMESH::SMESH_Hypothesis::_narrow( CreateHypothesis( TypeHypothesis, NameHypothesis  ) );
917     SMESH::SMESH_MaxElementVolume_var MaxElVolume = SMESH::SMESH_MaxElementVolume::_narrow( Hyp );
918     if ( !MaxElVolume->_is_nil() )
919       MaxElVolume->SetMaxElementVolume( MaxVolume );
920   }
921   catch  (const SALOME::SALOME_Exception& S_ex) {
922     QtCatchCorbaException(S_ex);
923   } 
924   myActiveStudy->updateObjBrowser(true);
925   QApplication::restoreOverrideCursor();
926 }
927
928 //=============================================================================
929 /*!
930  *
931  */
932 //=============================================================================
933 void SMESHGUI::CreateNbSegments( QString TypeHypothesis, QString NameHypothesis, double nbSegments )
934 {
935   QApplication::setOverrideCursor( Qt::waitCursor );
936   try {
937     SMESH::SMESH_Hypothesis_var Hyp = SMESH::SMESH_Hypothesis::_narrow( CreateHypothesis( TypeHypothesis, NameHypothesis  ) );
938     SMESH::SMESH_NumberOfSegments_var NbS = SMESH::SMESH_NumberOfSegments::_narrow( Hyp );
939     if ( !NbS->_is_nil() )
940       NbS->SetNumberOfSegments( nbSegments );
941   }
942   catch  (const SALOME::SALOME_Exception& S_ex) {
943     QtCatchCorbaException(S_ex);
944   } 
945   myActiveStudy->updateObjBrowser(true);
946   QApplication::restoreOverrideCursor();
947 }
948
949 //=============================================================================
950 /*!
951  *
952  */
953 //=============================================================================
954 int SMESHGUI::GetNameOfSelectedIObjects( SALOME_Selection* Sel, QString& aName )
955 {
956   int nbSel = Sel->IObjectCount() ;
957   if ( nbSel == 1 ) {
958     Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
959     aName = IObject->getName();
960   } else {
961     aName = tr( "SMESH_OBJECTS_SELECTED" ).arg( nbSel );
962   }
963   return nbSel;
964 }
965
966 //=============================================================================
967 /*!
968  *
969  */
970 //=============================================================================
971 int SMESHGUI::GetNameOfSelectedNodes( SALOME_Selection* Sel, QString& aName )
972 {
973   int nbNodes = 0;
974   int nbSel = Sel->IObjectCount() ;
975   if ( nbSel == 1 ) {
976     Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
977     if ( !IObject->hasEntry() )
978       return -1;
979
980     Standard_Boolean res;
981     SMESH_Actor* ac = FindActorByEntry( IObject->getEntry(), res, true );
982     if ( !res )
983       return -1;
984
985     TColStd_MapOfInteger MapIndex;
986     Sel->GetIndex( IObject, MapIndex );
987     TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
988     aName = " ";
989     nbNodes = MapIndex.Extent();
990     for ( ; ite.More(); ite.Next() ) {
991       aName = aName + QString("%1").arg(ac->GetIdSMESHDSNode(ite.Key())) + " ";
992     }
993   } else {
994     aName = "";
995   }
996   return nbNodes;
997 }
998
999 //=============================================================================
1000 /*!
1001  *
1002  */
1003 //=============================================================================
1004 int SMESHGUI::GetNameOfSelectedElements( SALOME_Selection* Sel, QString& aName )
1005 {
1006   int nbElements = 0;
1007   int nbSel = Sel->IObjectCount() ;
1008   if ( nbSel == 1 ) {
1009     Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
1010     if ( !IObject->hasEntry() )
1011       return -1;
1012
1013     Standard_Boolean res;
1014     SMESH_Actor* ac = FindActorByEntry( IObject->getEntry(), res, true );
1015     if ( !res )
1016       return -1;
1017
1018     TColStd_MapOfInteger MapIndex;
1019     Sel->GetIndex( IObject, MapIndex );
1020     TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
1021     aName = " ";
1022     nbElements = MapIndex.Extent();
1023     MESSAGE("GetNameOfSelectedElements(): number = " << nbElements);
1024     for ( ; ite.More(); ite.Next() ) {
1025       int idVTK = ite.Key();
1026       MESSAGE("GetNameOfSelectedElements(): VTK Id = " << idVTK);
1027       aName = aName + QString("%1").arg(ac->GetIdSMESHDSElement(idVTK)) + " ";
1028     }
1029   } else {
1030     aName = "";
1031   }
1032   return nbElements;
1033 }
1034
1035
1036 //=============================================================================
1037 /*!
1038  *
1039  */
1040 //=============================================================================
1041 int SMESHGUI::GetNameOfSelectedEdges( SALOME_Selection* Sel, QString& aName )
1042 {
1043   int nbElements = 0;
1044   int nbSel = Sel->IObjectCount() ;
1045   if ( nbSel == 1 ) {
1046     Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
1047     if ( !IObject->hasEntry() )
1048       return -1;
1049
1050     Standard_Boolean res;
1051     SMESH_Actor* ac = FindActorByEntry( IObject->getEntry(), res, true );
1052     if ( !res )
1053       return -1;
1054
1055     TColStd_MapOfInteger MapIndex;
1056     Sel->GetIndex( IObject, MapIndex );
1057     TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
1058     aName = " ";
1059     nbElements = MapIndex.Extent();
1060     for ( ; ite.More(); ite.Next() ) {
1061       aName = aName + QString("%1").arg(ite.Key()) + " ";
1062     }
1063   } else {
1064     aName = "";
1065   }
1066   return nbElements;
1067 }
1068
1069
1070 //=============================================================================
1071 /*!
1072  *
1073  */
1074 //=============================================================================
1075 SMESH_Actor* SMESHGUI::FindActorByEntry(QString entry, 
1076                                         Standard_Boolean& testResult,
1077                                         bool onlyInActiveView)
1078 {
1079   int nbSf = myActiveStudy->getStudyFramesCount();
1080   for ( int i = 0; i < nbSf; i++ ) {
1081     QAD_StudyFrame* sf = myActiveStudy->getStudyFrame(i);
1082     if ( sf->getTypeView() == VIEW_VTK ) {
1083       vtkRenderer* Renderer = ((VTKViewer_ViewFrame*)sf->getRightFrame()->getViewFrame())->getRenderer();
1084       vtkActorCollection* theActors = Renderer->GetActors();
1085       theActors->InitTraversal();
1086       vtkActor *ac = theActors->GetNextActor();
1087       while(!(ac==NULL)) {
1088         if ( ac->IsA("SMESH_Actor") ) {
1089           SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( ac );
1090           if ( anActor->hasIO() ) {
1091             Handle(SALOME_InteractiveObject) IO = anActor->getIO();
1092             if ( strcmp( IO->getEntry(), entry ) == 0 ) {
1093               if ( onlyInActiveView ) {
1094                 if ( sf == myActiveStudy->getActiveStudyFrame() ) {
1095                   testResult = true;
1096                   return anActor;
1097                 }
1098               } else {
1099                 testResult = true;
1100                 return anActor;
1101               }
1102             }
1103           }
1104         }
1105         ac = theActors->GetNextActor();
1106       }
1107     }
1108   }
1109
1110   MESSAGE ( " Actor Not Found " )
1111   testResult = false;
1112   return SMESH_Actor::New();
1113 }
1114
1115 //=============================================================================
1116 /*!
1117  *
1118  */
1119 //=============================================================================
1120 SMESH_Actor* SMESHGUI::FindActor(SMESH::SMESH_Mesh_ptr aMesh, 
1121                                  Standard_Boolean& testResult,
1122                                  bool onlyInActiveView)
1123 {
1124   SALOMEDS::SObject_var SM = myStudyAPI.FindMesh( aMesh );
1125   if ( SM->_is_nil() ) {
1126     MESSAGE ( " Actor Not Found " )
1127     
1128     testResult = false;
1129     return SMESH_Actor::New();
1130   }
1131
1132   return FindActorByEntry( SM->GetID(), testResult, onlyInActiveView);
1133 }
1134
1135 //=============================================================================
1136 /*!
1137  *
1138  */
1139 //=============================================================================
1140 SMESH::SMESH_Mesh_ptr SMESHGUI::ConvertIOinMesh(const Handle(SALOME_InteractiveObject)& IO, 
1141                                                 Standard_Boolean& testResult)
1142 {
1143   SMESH::SMESH_Mesh_var aMesh;
1144   testResult = false ;
1145
1146   /* case SObject */
1147   if ( IO->hasEntry() ) {
1148     SALOMEDS::SObject_var obj = myStudy->FindObjectID( IO->getEntry() );
1149     SALOMEDS::GenericAttribute_var anAttr;
1150     SALOMEDS::AttributeIOR_var     anIOR;
1151     if ( !obj->_is_nil() ) {
1152        if (obj->FindAttribute(anAttr, "AttributeIOR")) {
1153          anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1154          aMesh = SMESH::SMESH_Mesh::_narrow( _orb->string_to_object(anIOR->Value()) );
1155          if ( !aMesh->_is_nil() ) {
1156            testResult = true ;
1157            return SMESH::SMESH_Mesh::_duplicate( aMesh );
1158          }
1159        }
1160     }
1161   } 
1162   return SMESH::SMESH_Mesh::_nil();
1163 }
1164
1165 //=============================================================================
1166 /*!
1167  *
1168  */
1169 //=============================================================================
1170 SMESH::SMESH_subMesh_ptr SMESHGUI::ConvertIOinSubMesh(const Handle(SALOME_InteractiveObject)& IO, 
1171                                                       Standard_Boolean& testResult)
1172 {
1173   SMESH::SMESH_subMesh_var aSubMesh;
1174   testResult = false ;
1175
1176   /* case SObject */
1177   if ( IO->hasEntry() ) {
1178     SALOMEDS::SObject_var obj = myStudy->FindObjectID( IO->getEntry() );
1179     SALOMEDS::GenericAttribute_var anAttr;
1180     SALOMEDS::AttributeIOR_var     anIOR;
1181     if ( !obj->_is_nil() ) {
1182        if (obj->FindAttribute(anAttr, "AttributeIOR")) {
1183          anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1184          aSubMesh = SMESH::SMESH_subMesh::_narrow( _orb->string_to_object(anIOR->Value()) );
1185          if ( !aSubMesh->_is_nil() ) {
1186            testResult = true ;
1187            return SMESH::SMESH_subMesh::_duplicate( aSubMesh );
1188          }
1189        }
1190     }
1191   } 
1192   return SMESH::SMESH_subMesh::_nil();
1193 }
1194
1195 //=============================================================================
1196 /*!
1197  *
1198  */
1199 //=============================================================================
1200 SMESH::SMESH_Hypothesis_ptr SMESHGUI::ConvertIOinSMESHHypothesis( const Handle(SALOME_InteractiveObject)& IO, 
1201                                                                   Standard_Boolean& testResult )
1202 {
1203   SMESH::SMESH_Hypothesis_var aHyp ;
1204   testResult = false ;
1205
1206   /* case SObject */
1207   if ( IO->hasEntry() ) {
1208     SALOMEDS::SObject_var obj = myStudy->FindObjectID( IO->getEntry() );
1209     SALOMEDS::GenericAttribute_var anAttr;
1210     SALOMEDS::AttributeIOR_var     anIOR;
1211     if ( !obj->_is_nil() ) {
1212        if (obj->FindAttribute(anAttr, "AttributeIOR")) {
1213          anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1214          aHyp = SMESH::SMESH_Hypothesis::_narrow( _orb->string_to_object(anIOR->Value()));
1215          if ( !aHyp->_is_nil() ) {
1216            testResult = true ;
1217            return SMESH::SMESH_Hypothesis::_duplicate( aHyp );
1218          }
1219        }
1220     }
1221   } 
1222   return SMESH::SMESH_Hypothesis::_nil();
1223 }
1224
1225
1226
1227 //=============================================================================
1228 /*!
1229  *
1230  */
1231 //=============================================================================
1232 GEOM::GEOM_Shape_ptr SMESHGUI::ConvertIOinGEOMShape( const Handle(SALOME_InteractiveObject)& IO, 
1233                                                Standard_Boolean& testResult )
1234 {
1235   GEOM::GEOM_Shape_var aShape ;
1236   testResult = false ;
1237
1238   /* case SObject */
1239   if ( IO->hasEntry() ) {
1240     SALOMEDS::SObject_var obj = myStudy->FindObjectID( IO->getEntry() );
1241     SALOMEDS::GenericAttribute_var anAttr;
1242     SALOMEDS::AttributeIOR_var     anIOR;
1243     if ( !obj->_is_nil() ) {
1244        if (obj->FindAttribute(anAttr, "AttributeIOR")) {
1245          anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1246          aShape = myComponentGeom->GetIORFromString(anIOR->Value()) ;
1247          if ( !aShape->_is_nil() ) {
1248            testResult = true ;
1249            return GEOM::GEOM_Shape::_duplicate( aShape );
1250          }
1251        }
1252     }
1253   }
1254   return GEOM::GEOM_Shape::_nil();
1255 }
1256
1257
1258 //=============================================================================
1259 /*!
1260  *
1261  */
1262 //=============================================================================
1263 void SMESHGUI::SetViewMode(int commandId)
1264 {
1265   SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
1266   int nbSel = Sel->IObjectCount();
1267   if ( nbSel >= 1 ) {
1268     SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
1269     for ( ; It.More(); It.Next() ) {
1270       Handle(SALOME_InteractiveObject) IObject = It.Value();
1271       if ( IObject->hasEntry() ) {
1272         Standard_Boolean res;
1273         SMESH_Actor* ac = FindActorByEntry( IObject->getEntry(), res, true );
1274         if ( res ) {
1275           switch (commandId) {
1276           case 211: {
1277             ChangeRepresentation( ac, 0 );
1278             break;
1279           }
1280           case 212: {
1281             ChangeRepresentation( ac, 1 );
1282             break;
1283           }
1284           case 213: {
1285             ChangeRepresentation( ac, 2 );
1286             break;
1287           }
1288           case 1132: {
1289             ChangeRepresentation( ac, 3 );
1290             break;
1291           }
1292           }
1293         }
1294       }
1295     }
1296     if ( commandId == 1133 ) {
1297       ChangeRepresentation( SMESH_Actor::New(), 4 );
1298     }
1299   }
1300 }
1301
1302 //=============================================================================
1303 /*!
1304  *
1305  */
1306 //=============================================================================
1307 void SMESHGUI::ChangeRepresentation( SMESH_Actor* ac, int type )
1308 {
1309   if (ac->DataSource == NULL && type != 4 )
1310     return;
1311
1312   if ( type != 4 ) {
1313     if ( ac->getMapper() == NULL ) {
1314       return;
1315     }
1316   }
1317   switch (type) {
1318   case 0 : {
1319     QApplication::setOverrideCursor( Qt::waitCursor );
1320     if (ac->getDisplayMode()==2) {
1321       vtkDataSetMapper* meshMapper = (vtkDataSetMapper*) (ac->getMapper());
1322       meshMapper->SetInput(ac->DataSource);
1323     }
1324     ac->setDisplayMode(0);
1325     ac->GetProperty()->SetRepresentationToWireframe();
1326     //    ac->SetActorProperty( ac->GetProperty() );
1327     QApplication::restoreOverrideCursor();
1328     break;
1329   }
1330   case 1 : {
1331     QApplication::setOverrideCursor( Qt::waitCursor );
1332     if (ac->getDisplayMode()==2) {
1333       vtkDataSetMapper* meshMapper = (vtkDataSetMapper*) (ac->getMapper());
1334       meshMapper->SetInput(ac->DataSource);
1335     }
1336     ac->setDisplayMode(1);
1337     ac->GetProperty()->SetRepresentationToSurface();
1338     QApplication::restoreOverrideCursor();
1339     //    ac->SetActorProperty( ac->GetProperty() );
1340     break;
1341   }
1342   case 2 : {
1343     //    if (!(ac->getDisplayMode()==2)) {
1344     //    ChangeRepresentation(ac, 1);
1345     QApplication::setOverrideCursor( Qt::waitCursor );
1346     ac->setDisplayMode(2);
1347     vtkDataSetMapper* meshMapper = (vtkDataSetMapper*) (ac->getMapper());
1348     meshMapper->SetInput(ac->DataSource);
1349     vtkShrinkFilter *shrink = vtkShrinkFilter::New();
1350     shrink->SetInput(meshMapper->GetInput());
1351     shrink->SetShrinkFactor(ac->GetShrinkFactor());
1352     
1353     meshMapper->SetInput( shrink->GetOutput() );
1354     ac->SetMapper( meshMapper );
1355     QApplication::restoreOverrideCursor();
1356     //    }
1357     break;
1358   }
1359   case 3:
1360     {
1361       float color[3];
1362       float edgecolor[3];
1363       float backfacecolor[3];
1364       float nodecolor[3];
1365       ac->GetColor(color[0],color[1],color[2]);
1366       QColor c(color[0]*255,color[1]*255,color[2]*255);
1367       ac->GetEdgeColor(edgecolor[0],edgecolor[1],edgecolor[2]);
1368       QColor e(edgecolor[0]*255,edgecolor[1]*255,edgecolor[2]*255);
1369       ac->GetBackfaceProperty()->GetColor(backfacecolor);
1370       QColor b(backfacecolor[0]*255,backfacecolor[1]*255,backfacecolor[2]*255);
1371       ac->GetNodeColor(nodecolor[0], nodecolor[1], nodecolor[2] ) ;
1372       QColor n(nodecolor[0]*255, nodecolor[1]*255, nodecolor[2]*255 ) ;
1373
1374       int Edgewidth = (int)ac->EdgeDevice->GetProperty()->GetLineWidth();
1375       if ( Edgewidth == 0 )
1376         Edgewidth = 1;
1377       int intValue = ac->GetNodeSize() ;
1378       float Shrink = ac->GetShrinkFactor();
1379  
1380       SMESHGUI_Preferences_ColorDlg *aDlg = new SMESHGUI_Preferences_ColorDlg( QAD_Application::getDesktop(), "" ) ;
1381       aDlg->SetColor(1,c);
1382       aDlg->SetColor(2,e);
1383       aDlg->SetColor(3,n);
1384       aDlg->SetColor(4,b);
1385       aDlg->SetIntValue(1,Edgewidth);
1386       aDlg->SetIntValue(2,intValue);
1387       aDlg->SetIntValue(3,int(Shrink*100.));
1388
1389       if ( aDlg->exec() ) {
1390         QApplication::setOverrideCursor( Qt::waitCursor );
1391         QColor color = aDlg->GetColor(1);
1392         QColor edgecolor = aDlg->GetColor(2);
1393         QColor nodecolor = aDlg->GetColor(3);
1394         QColor backfacecolor = aDlg->GetColor(4);
1395         /* actor color and backface color */
1396         ac->GetProperty()->SetColor(float(color.red())/255.,float(color.green())/255.,float(color.blue())/255.);
1397         ac->SetColor(float(color.red())/255.,float(color.green())/255.,float(color.blue())/255.);
1398         ac->GetBackfaceProperty()->SetColor(float(backfacecolor.red())/255.,float(backfacecolor.green())/255.,float(backfacecolor.blue())/255.);
1399
1400         /* edge color */
1401         ac->EdgeDevice->GetProperty()->SetColor(float(edgecolor.red())/255.,
1402                                                 float(edgecolor.green())/255.,
1403                                                 float(edgecolor.blue())/255.);
1404         ac->EdgeShrinkDevice->GetProperty()->SetColor(float(edgecolor.red())/255.,
1405                                                       float(edgecolor.green())/255.,
1406                                                       float(edgecolor.blue())/255.);
1407         ac->SetEdgeColor(float(edgecolor.red())/255.,
1408                          float(edgecolor.green())/255.,
1409                          float(edgecolor.blue())/255.);
1410
1411         /* Shrink factor and size edges */
1412         ac->SetShrinkFactor( aDlg->GetIntValue(3)/100. );
1413         ac->EdgeDevice->GetProperty()->SetLineWidth( aDlg->GetIntValue(1) );    
1414         ac->EdgeShrinkDevice->GetProperty()->SetLineWidth( aDlg->GetIntValue(1) );
1415
1416         /* Nodes color and size */
1417         ac->SetNodeColor(float(nodecolor.red())/255.,
1418                          float(nodecolor.green())/255.,
1419                          float(nodecolor.blue())/255.);
1420         ac->SetNodeSize(aDlg->GetIntValue(2)) ;
1421         
1422         if (ac->getDisplayMode()==2) {
1423           vtkDataSetMapper* meshMapper = (vtkDataSetMapper*) (ac->getMapper());
1424           meshMapper->SetInput(ac->DataSource);
1425           vtkShrinkFilter *shrink = vtkShrinkFilter::New();
1426           shrink->SetInput(meshMapper->GetInput());
1427           shrink->SetShrinkFactor(ac->GetShrinkFactor());
1428           
1429           meshMapper->SetInput( shrink->GetOutput() );
1430           ac->SetMapper( meshMapper );
1431         }
1432       }
1433       delete aDlg;
1434       QApplication::restoreOverrideCursor();
1435       break;
1436     }
1437   case 4:
1438     {
1439       EmitSignalDeactivateDialog() ;
1440       SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
1441       SMESHGUI_TransparencyDlg *aDlg = new SMESHGUI_TransparencyDlg( QAD_Application::getDesktop(), "", Sel) ;
1442       break;
1443     }
1444   case 5: {
1445     QApplication::setOverrideCursor( Qt::waitCursor );
1446     ac->GetProperty()->SetRepresentationToPoints();
1447     QApplication::restoreOverrideCursor();
1448     break;
1449   }
1450   }
1451
1452   QApplication::setOverrideCursor( Qt::waitCursor );
1453   if ( myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
1454     vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
1455     theRenderer->Render();
1456   }
1457   QApplication::restoreOverrideCursor();
1458 }
1459
1460 //=============================================================================
1461 /*!
1462  *
1463  */
1464 //=============================================================================
1465 void SMESHGUI::UpdateView()
1466 {
1467   if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK) 
1468     return;
1469
1470   vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
1471   theRenderer->Render();
1472 }
1473
1474 //=============================================================================
1475 /*!
1476  *
1477  */
1478 //=============================================================================
1479 void SMESHGUI::DisplayActor(SMESH_Actor* ac, bool visibility)
1480 {
1481   if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK) 
1482     return;
1483
1484   MESSAGE("DisplayActor(): DataSource = " << ac->DataSource);
1485
1486   vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
1487   vtkActorCollection* theActors = theRenderer->GetActors();
1488   theActors->InitTraversal();
1489   if ( theActors->IsItemPresent(ac) == 0 ) {
1490     vtkProperty* prop = vtkProperty::New();
1491     prop->SetColor( QAD_CONFIG->getSetting("SMESH:SettingsFillColorRed").toFloat()/255., 
1492                     QAD_CONFIG->getSetting("SMESH:SettingsFillColorGreen").toFloat()/255.,
1493                     QAD_CONFIG->getSetting("SMESH:SettingsFillColorBlue").toFloat()/255. ) ;
1494
1495     prop->SetPointSize( QAD_CONFIG->getSetting("SMESH:SettingsNodesSize").toInt());
1496     prop->SetLineWidth( QAD_CONFIG->getSetting("SMESH:SettingsWidth").toInt() );
1497     ac->SetProperty( prop );
1498     ac->SetColor( QAD_CONFIG->getSetting("SMESH:SettingsFillColorRed").toFloat()/255., 
1499                   QAD_CONFIG->getSetting("SMESH:SettingsFillColorGreen").toFloat()/255.,
1500                   QAD_CONFIG->getSetting("SMESH:SettingsFillColorBlue").toFloat()/255. );
1501
1502     //    prop->BackfaceCullingOn();
1503     vtkProperty* backprop = vtkProperty::New();
1504     backprop->SetColor( QAD_CONFIG->getSetting("SMESH:SettingsBackFaceColorRed").toFloat()/255., 
1505                         QAD_CONFIG->getSetting("SMESH:SettingsBackFaceColorGreen").toFloat()/255.,
1506                         QAD_CONFIG->getSetting("SMESH:SettingsBackFaceColorBlue").toFloat()/255. ) ;
1507     ac->SetBackfaceProperty(backprop);
1508
1509     int intValue = QAD_CONFIG->getSetting("SMESH:SettingsShrinkCoeff").toInt();
1510     if (intValue == 0 )
1511       intValue = 80;       
1512     ac->SetShrinkFactor( intValue/100. );
1513
1514     ac->GetMapper()->SetResolveCoincidentTopologyToShiftZBuffer();
1515     ac->GetMapper()->SetResolveCoincidentTopologyZShift(0.02);
1516
1517     QString DisplayMode = QAD_CONFIG->getSetting("SMESH:DisplayMode");
1518     if ( DisplayMode.compare("Wireframe") == 0 ){
1519       ac->setDisplayMode(0);
1520       ChangeRepresentation( ac, 0 );
1521     } else if ( DisplayMode.compare("Shading") == 0 ){
1522       ac->setDisplayMode(1);
1523       ChangeRepresentation( ac, 1 );
1524     } else if ( DisplayMode.compare("Shrink") == 0 ) {
1525       ac->setDisplayMode(2);
1526       ChangeRepresentation( ac, 2 );
1527     }
1528     theRenderer->AddActor(ac);
1529   } else {
1530     if (ac->GetMapper())
1531       ac->GetMapper()->Update();
1532   }
1533  
1534 //  if ( visibility )
1535   ac->SetVisibility(visibility);
1536 //    ac->VisibilityOn();
1537 //  else
1538 //    ac->VisibilityOff();
1539
1540   vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
1541   renWin->Render();
1542 }
1543
1544 //=============================================================================
1545 /*!
1546  *
1547  */
1548 //=============================================================================
1549 void SMESHGUI::EraseActor(SMESH_Actor* ac)
1550 {
1551   if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK) 
1552     return;
1553
1554   vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
1555
1556   //NRI- : 02/12/2002 : Fixed bugId 882
1557   //  ac->EdgeDevice->VisibilityOff();
1558   //  ac->EdgeShrinkDevice->VisibilityOff();
1559   //  ac->VisibilityOff();
1560   ac->SetVisibility( false );
1561
1562   theRenderer->Render();
1563 }
1564
1565 //=============================================================================
1566 /*!
1567  *
1568  */
1569 //=============================================================================
1570 bool SMESHGUI::AddActorInSelection(SMESH_Actor* ac)
1571 {
1572   SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
1573   Sel->ClearIObjects();
1574   if ( ac->hasIO() )
1575     return Sel->AddIObject( ac->getIO() );
1576   else
1577     return -1;
1578 }
1579
1580 //=============================================================================
1581 /*!
1582  *
1583  */
1584 //=============================================================================
1585 QString SMESHGUI::CheckHomogeneousSelection()
1586 {
1587   SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
1588   /* copy the list */
1589   SALOME_ListIO List;
1590   SALOME_ListIteratorOfListIO Itinit( Sel->StoredIObjects() );
1591   for (; Itinit.More(); Itinit.Next()) {
1592     List.Append(Itinit.Value());
1593   }
1594
1595   QString RefType = CheckTypeObject( Sel->firstIObject() );
1596   SALOME_ListIteratorOfListIO It( List );
1597   for (; It.More(); It.Next()) {
1598     Handle(SALOME_InteractiveObject) IObject = It.Value();
1599     QString Type = CheckTypeObject( IObject );
1600     if ( Type.compare( RefType ) != 0 )
1601       return "Heterogeneous Selection";
1602   }
1603
1604   Sel->ClearIObjects();
1605   SALOME_ListIteratorOfListIO It1( List );
1606   for(;It1.More();It1.Next()) {
1607     int res = Sel->AddIObject( It1.Value() );
1608     if ( res == -1 )
1609       myActiveStudy->highlight( It1.Value(), false );
1610     if ( res == 0 )
1611       myActiveStudy->highlight( It1.Value(), true );
1612   }
1613   return RefType;
1614 }
1615
1616 //=============================================================================
1617 /*!
1618  *
1619  */
1620 //=============================================================================
1621 QString SMESHGUI::CheckTypeObject(const Handle(SALOME_InteractiveObject)& IO)
1622 {
1623   SALOMEDS::SObject_var sobj = smeshGUI->myActiveStudy->getStudyDocument()->FindObjectID(IO->getEntry());
1624   if (!sobj->_is_nil()) {
1625     SALOMEDS::SComponent_var scomp = sobj->GetFatherComponent();
1626     if (strcmp(scomp->GetID(), IO->getEntry()) == 0) { // component is selected
1627       return "Component";
1628     }
1629   }
1630
1631   SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
1632   Sel->ClearIObjects();
1633
1634   Handle(SMESH_TypeFilter) aHypFilter = new SMESH_TypeFilter( HYPOTHESIS );
1635   Handle(SMESH_TypeFilter) anAlgoFilter = new SMESH_TypeFilter( ALGORITHM );
1636   Handle(SMESH_TypeFilter) aMeshFilter = new SMESH_TypeFilter( MESH );
1637   Handle(SMESH_TypeFilter) aSubMeshFilter = new SMESH_TypeFilter( SUBMESH );
1638   Handle(SMESH_TypeFilter) aMeshOrSubMeshFilter = new SMESH_TypeFilter( MESHorSUBMESH );
1639   Handle(SMESH_TypeFilter) aSubMeshVextexFilter = new SMESH_TypeFilter( SUBMESH_VERTEX );
1640   Handle(SMESH_TypeFilter) aSubMeshEdgeFilter = new SMESH_TypeFilter( SUBMESH_EDGE );
1641   Handle(SMESH_TypeFilter) aSubMeshFaceFilter = new SMESH_TypeFilter( SUBMESH_FACE );
1642   Handle(SMESH_TypeFilter) aSubMeshSolidFilter = new SMESH_TypeFilter( SUBMESH_SOLID );
1643   Handle(SMESH_TypeFilter) aSubMeshCompoundFilter = new SMESH_TypeFilter( SUBMESH_COMPOUND );
1644   
1645   Sel->AddFilter(aHypFilter);
1646   if ( Sel->AddIObject( IO ) != -1 ) {
1647     Sel->ClearFilters();
1648     return "Hypothesis";
1649   } 
1650
1651   Sel->ClearFilters();
1652   Sel->AddFilter(anAlgoFilter);
1653   if ( Sel->AddIObject( IO ) != -1 ) {
1654     Sel->ClearFilters();
1655     return "Algorithm";
1656   } 
1657
1658   Sel->ClearFilters();
1659   Sel->AddFilter(aMeshFilter);
1660   if ( Sel->AddIObject( IO ) != -1 ) {
1661     Sel->ClearFilters();
1662     return "Mesh";
1663   } 
1664
1665   Sel->ClearFilters();
1666   Sel->AddFilter(aSubMeshFilter);
1667   if ( Sel->AddIObject( IO ) != -1 ) {
1668     Sel->ClearFilters();
1669     return "SubMesh";
1670   } 
1671  
1672   Sel->ClearFilters();
1673   Sel->AddFilter(aSubMeshVextexFilter);
1674   if ( Sel->AddIObject( IO ) != -1 ) {
1675     Sel->ClearFilters();
1676     return "SubMeshVertex";
1677   } 
1678  
1679   Sel->ClearFilters();
1680   Sel->AddFilter(aSubMeshEdgeFilter);
1681   if ( Sel->AddIObject( IO ) != -1 ){
1682     Sel->ClearFilters();
1683     return "SubMeshEdge";
1684   } 
1685   
1686   Sel->ClearFilters();
1687   Sel->AddFilter(aSubMeshFaceFilter);
1688   if ( Sel->AddIObject( IO ) != -1 ) {
1689     Sel->ClearFilters();
1690     return "SubMeshFace";
1691   } 
1692   
1693   Sel->ClearFilters();
1694   Sel->AddFilter(aSubMeshSolidFilter);
1695   if ( Sel->AddIObject( IO ) != -1 ) {
1696     Sel->ClearFilters();
1697     return "SubMeshSolid";
1698   } 
1699   
1700   Sel->ClearFilters();
1701   Sel->AddFilter(aSubMeshCompoundFilter);
1702   if ( Sel->AddIObject( IO ) != -1 ) {
1703     Sel->ClearFilters();
1704     return "SubMeshCompound";
1705   } 
1706   
1707   Sel->ClearFilters();
1708   Sel->AddIObject( IO );
1709   return "NoType";
1710 }
1711
1712 //=============================================================================
1713 /*!
1714  *
1715  */
1716 //=============================================================================
1717 bool SMESHGUI::OnGUIEvent(int theCommandID,     QAD_Desktop* parent)
1718 {
1719   /* Create or retrieve an object SMESHGUI */
1720   SMESHGUI::GetOrCreateSMESHGUI(parent);
1721
1722   // NRI : Temporary added
1723   if ( smeshGUI->myStudy->GetProperties()->IsLocked() ) {
1724     return false;
1725   }
1726   //NRI
1727
1728   //  QAD_Viewer3d* v3d;
1729   OCCViewer_Viewer3d* v3d;
1730   
1731   Handle(AIS_InteractiveContext) ic;
1732   vtkRenderer* Renderer;
1733   vtkRenderWindow* RenWin;
1734
1735   if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_OCC ) {
1736     v3d =((OCCViewer_ViewFrame*)smeshGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer(); 
1737     ic = v3d->getAISContext();
1738   } else if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) {
1739     Renderer = ((VTKViewer_ViewFrame*)smeshGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
1740     RenWin = Renderer->GetRenderWindow();
1741   }
1742
1743   switch (theCommandID)
1744     {
1745     case 33: // DELETE
1746       smeshGUI->OnEditDelete();
1747       break;
1748
1749     case 113: // IMPORT
1750     case 112:
1751     case 111: 
1752       {
1753         Import_Document(parent,theCommandID);//NBU
1754         //Import_Mesh(parent,theCommandID);
1755         break;
1756       }
1757
1758     case 122: // EXPORT MED
1759     case 121:
1760     case 123:
1761       {
1762         Export_Mesh(parent, theCommandID);
1763         break;
1764       }
1765
1766     case 200: // SCALAR BAR
1767       {
1768         smeshGUI->DisplayScalarBar(false);
1769         break;
1770       }
1771     case 201:
1772       {
1773         SMESHGUI_EditScalarBarDlg *aDlg = new SMESHGUI_EditScalarBarDlg( parent, "", false ) ;
1774         aDlg->show();
1775         break;
1776       }
1777     case 202:
1778       {
1779         smeshGUI->DisplayScalarBar( true );
1780         break;
1781       }      
1782
1783     case 1133: // DISPLAY MODE : WireFrame, Surface, Shrink
1784     case 1132:
1785     case 213:
1786     case 212:
1787     case 211:
1788       {
1789         smeshGUI->SetViewMode(theCommandID);
1790         break;
1791       }
1792       
1793     case 214 : // UPDATE
1794       {
1795         smeshGUI->Update();
1796         break;
1797       }
1798  
1799     case 300 : // ERASE
1800       {
1801         SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
1802         if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
1803           // VTK
1804           SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
1805           for(;It.More();It.Next()) {
1806             Handle(SALOME_InteractiveObject) IOS = It.Value();
1807             if ( IOS->hasEntry() ) {
1808               Standard_Boolean res;
1809               SMESH_Actor *ac = smeshGUI->FindActorByEntry(IOS->getEntry(), res, true );
1810               if ( res ) smeshGUI->EraseActor( ac );
1811             }
1812           }
1813         }
1814         Sel->ClearIObjects();
1815         smeshGUI->myActiveStudy->updateObjBrowser( true );
1816       }
1817      
1818     case 301 : // DISPLAY
1819       {
1820         if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
1821           // VTK
1822           QApplication::setOverrideCursor( Qt::waitCursor );
1823           SALOMEDS::SObject_var fatherSF = 
1824             smeshGUI->myStudy->FindObjectID(smeshGUI->myActiveStudy->getActiveStudyFrame()->entry());
1825
1826           SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
1827           SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
1828           
1829           for(;It.More();It.Next()) {
1830             Handle(SALOME_InteractiveObject) IObject = It.Value();
1831             if ( IObject->hasEntry() ) {
1832               Standard_Boolean res;
1833               SMESH_Actor *ac = smeshGUI->FindActorByEntry(IObject->getEntry(), res, true );
1834               if ( res ) {
1835                 smeshGUI->DisplayActor( ac, true );
1836                 smeshGUI->DisplayEdges( ac ); 
1837                 smeshGUI->ChangeRepresentation( ac, ac->getDisplayMode() );
1838               }
1839             }
1840           }
1841           QApplication::restoreOverrideCursor();
1842         }
1843         break;
1844       }
1845
1846     case 302 : // DISPLAY ONLY
1847       {
1848         if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) {
1849           QApplication::setOverrideCursor( Qt::waitCursor );
1850           vtkActorCollection* theActors = Renderer->GetActors();
1851           theActors->InitTraversal();
1852           vtkActor *ac = theActors->GetNextActor();
1853           while(!(ac==NULL)) {
1854             if ( ac->IsA("SMESH_Actor") ) {
1855               SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( ac );
1856               if(!anActor->isHighlighted()) {
1857                 //anActor->VisibilityOff();
1858                 //NRI- : 02/12/2002 : Fixed bugId 882
1859                 //              anActor->EdgeDevice->VisibilityOff();
1860                 //              anActor->EdgeShrinkDevice->VisibilityOff();
1861                 anActor->SetVisibility( false );
1862               }
1863             }
1864             ac = theActors->GetNextActor();
1865           }
1866
1867           // Display selection
1868           SALOMEDS::SObject_var fatherSF = smeshGUI->myStudy->FindObjectID(smeshGUI->myActiveStudy->getActiveStudyFrame()->entry());
1869           
1870           SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
1871           SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
1872           
1873           for(;It.More();It.Next()) {
1874             Handle(SALOME_InteractiveObject) IObject = It.Value();
1875             SALOMEDS::SObject_var obj = smeshGUI->myStudy->FindObjectID( IObject->getEntry() );
1876             
1877             VTKViewer_RenderWindowInteractor* myRenderInter= ((VTKViewer_ViewFrame*)smeshGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor();
1878             //      vtkQGLRenderWindowInteractor* myRenderInter= smeshGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getVTKView()->getRWInteractor();
1879             
1880             if(myRenderInter->isInViewer(IObject)) {
1881               if ( IObject->hasEntry() ) {
1882                 Standard_Boolean res;
1883                 SMESH_Actor *ac = smeshGUI->FindActorByEntry(IObject->getEntry(), res, true );
1884                 if ( res ) {
1885                   smeshGUI->DisplayActor( ac, true );
1886                   smeshGUI->DisplayEdges( ac ); 
1887                   smeshGUI->ChangeRepresentation( ac, ac->getDisplayMode() );
1888                 }
1889               }
1890             }
1891           }
1892           smeshGUI->myActiveStudy->updateObjBrowser( true );
1893           QApplication::restoreOverrideCursor();
1894         }
1895         break;
1896       }
1897
1898     case 400: // NODES
1899       {
1900         if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
1901           smeshGUI->EmitSignalDeactivateDialog() ;
1902           SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
1903           Sel->ClearIObjects();
1904           smeshGUI->myDesktop->SetSelectionMode(1, true);
1905           parent->menuBar()->setItemChecked(9010, false );
1906           parent->menuBar()->setItemChecked(9011, false );
1907           smeshGUI->ViewNodes();
1908           SMESHGUI_NodesDlg *aDlg = new SMESHGUI_NodesDlg( parent, "", Sel ) ;
1909         } else {
1910           QApplication::restoreOverrideCursor();
1911             QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
1912                                    tr ("SMESH_WRN_VIEWER_VTK"), tr ("SMESH_BUT_YES") );
1913         }
1914         break;
1915       }
1916
1917     case 405: // MOVE NODE
1918       {
1919           smeshGUI->myDesktop->SetSelectionMode(1, true);
1920           SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
1921           SMESHGUI_MoveNodesDlg *aDlg = new SMESHGUI_MoveNodesDlg( parent, "", Sel ) ;
1922           break;
1923       }
1924
1925     case 701: // COMPUTE MESH 
1926       {
1927         if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
1928           SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
1929           int nbSel = Sel->IObjectCount();
1930           if ( nbSel != 1 ) {
1931             QApplication::restoreOverrideCursor();
1932             break;
1933           }
1934
1935           SMESH::SMESH_Mesh_var aM;
1936           SMESH::SMESH_subMesh_var aSubM;
1937           Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
1938           if ( IObject->hasEntry() ) {
1939             SALOMEDS::SObject_var aMorSM = smeshGUI->myStudy->FindObjectID( IObject->getEntry() );
1940             SALOMEDS::GenericAttribute_var anAttr;
1941             SALOMEDS::AttributeIOR_var     anIOR;
1942             if ( !aMorSM->_is_nil() ) {
1943               if (aMorSM->FindAttribute(anAttr, "AttributeIOR") ) {
1944                 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1945                 MESSAGE( "SMESHGUI::OnGUIEvent - Compute mesh : IOR = " << anIOR->Value() )
1946                 CORBA::Object_var cobj;
1947                 try {
1948                   cobj = _orb->string_to_object(anIOR->Value());
1949                   if ( CORBA::is_nil(cobj) ) {
1950                     MESSAGE( "SMESHGUI::OnGUIEvent - Compute mesh : nil object" )
1951                   }
1952                 }
1953                 catch(CORBA::COMM_FAILURE& ex) {
1954                   MESSAGE( "SMESHGUI::OnGUIEvent - Compute mesh : exception (1)" )
1955                 }
1956                 aM = SMESH::SMESH_Mesh::_narrow(cobj);
1957                 //aM = SMESH::SMESH_Mesh::_narrow( _orb->string_to_object(anIOR->Value()) );
1958                 aSubM = SMESH::SMESH_subMesh::_narrow( _orb->string_to_object(anIOR->Value()) );
1959                 if ( !aM->_is_nil() ) {
1960                   GEOM::GEOM_Shape_var refShape = smeshGUI->myStudyAPI.GetShapeOnMeshOrSubMesh(aMorSM);
1961                   if ( !refShape->_is_nil() ) {
1962                     bool compute = smeshGUI->myComponentMesh->IsReadyToCompute(aM, refShape);
1963                     if ( !compute ) {
1964                       QApplication::restoreOverrideCursor();
1965                       QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
1966                                               tr ("SMESH_WRN_MISSING_PARAMETERS"), tr ("SMESH_BUT_YES") );
1967                       break;
1968                     }
1969                     try {
1970                       smeshGUI->myComponentMesh->Compute( aM, refShape);
1971                       smeshGUI->myStudyAPI.ModifiedMesh( aMorSM, true );
1972                       // TO Do : change icon of all submeshes
1973                     }
1974                     catch  (const SALOME::SALOME_Exception& S_ex) {
1975                       QtCatchCorbaException(S_ex);
1976                     }
1977                   }
1978                 } else if ( !aSubM->_is_nil() ) {
1979                   aM = aSubM->GetFather();
1980                   GEOM::GEOM_Shape_var refShape = smeshGUI->myStudyAPI.GetShapeOnMeshOrSubMesh(aMorSM);
1981                   if ( !refShape->_is_nil() ) {
1982                     bool compute = smeshGUI->myComponentMesh->IsReadyToCompute(aM, refShape);
1983                     if ( !compute ) {
1984                       QApplication::restoreOverrideCursor();
1985                       QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
1986                                               tr ("SMESH_WRN_MISSING_PARAMETERS"), tr ("SMESH_BUT_YES") );
1987                       break;
1988                     }
1989                     try {
1990                       smeshGUI->myComponentMesh->Compute( aM, refShape);
1991                       smeshGUI->myStudyAPI.ModifiedMesh( aMorSM, true );
1992                       // TO Do : change icon of all submeshes
1993                     }
1994                     catch  (const SALOME::SALOME_Exception& S_ex) {
1995                       QtCatchCorbaException(S_ex);
1996                     }
1997                   }
1998                 }
1999               }
2000             }
2001           }
2002
2003           // Check whether the actor for the mesh exists at least in one view
2004           Standard_Boolean res;
2005           SMESH_Actor* ac = smeshGUI->FindActorByEntry(IObject->getEntry(), res, false);
2006           if (!res)
2007             smeshGUI->InitActor( aM );
2008           else {
2009             // Check whether the actor belongs to the active view
2010             VTKViewer_RenderWindowInteractor* rwInter = 
2011               ((VTKViewer_ViewFrame*)smeshGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor();
2012
2013             // The actor belongs to inactive view -> create a copy and add it in the active view
2014             if (!rwInter->isInViewer(IObject)) {
2015               SMESH_Actor* acCopy = SMESH_Actor::New();
2016               acCopy->ShallowCopy(ac);
2017
2018               smeshGUI->DisplayActor( acCopy, false );
2019             }
2020           }
2021
2022           if ( smeshGUI->myAutomaticUpdate ) {
2023             SMESH_Actor* Mesh = smeshGUI->ReadScript(aM);
2024             if ( Mesh != NULL ) {
2025 #ifdef TRACE
2026               Dump( Mesh );
2027 #endif
2028               smeshGUI->DisplayActor( Mesh, true );
2029               smeshGUI->DisplayEdges( Mesh, true );    
2030               smeshGUI->ChangeRepresentation( Mesh, Mesh->getDisplayMode() );
2031             }
2032           }
2033         } else {
2034           QApplication::restoreOverrideCursor();
2035           QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
2036                                   tr ("SMESH_WRN_VIEWER_VTK"), tr ("SMESH_BUT_YES") );
2037         }
2038         QApplication::restoreOverrideCursor();
2039         break;
2040       }
2041
2042     case 702: // ADD SUB MESH 
2043       {
2044         if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
2045           smeshGUI->EmitSignalDeactivateDialog() ;
2046           SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2047           SMESHGUI_AddSubMeshDlg *aDlg = new SMESHGUI_AddSubMeshDlg( parent, "", Sel ) ;
2048         } else {
2049           QApplication::restoreOverrideCursor();
2050           QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
2051                                    tr ("SMESH_WRN_VIEWER_VTK"), tr ("SMESH_BUT_YES") );
2052         }
2053         break;
2054       }
2055     
2056     case 703: // INIT MESH 
2057       {
2058         smeshGUI->EmitSignalDeactivateDialog() ;
2059         SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2060         SMESHGUI_InitMeshDlg *aDlg = new SMESHGUI_InitMeshDlg( parent, "", Sel ) ;
2061         break;
2062       }
2063
2064     case 704: // EDIT Hypothesis 
2065       {
2066         smeshGUI->EmitSignalDeactivateDialog() ;
2067         SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2068         SMESHGUI_EditHypothesesDlg *aDlg = new SMESHGUI_EditHypothesesDlg( parent, "", Sel ) ;
2069         break;
2070       }
2071
2072     case 705: //  EDIT Global Hypothesis
2073       {
2074         smeshGUI->EmitSignalDeactivateDialog() ;
2075         SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2076         SMESHGUI_EditHypothesesDlg *aDlg = new SMESHGUI_EditHypothesesDlg( parent, "", Sel ) ;
2077         break;
2078       }
2079
2080     case 706: //  EDIT Local Hypothesis
2081       {
2082         smeshGUI->EmitSignalDeactivateDialog() ;
2083         SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2084         SMESHGUI_EditHypothesesDlg *aDlg = new SMESHGUI_EditHypothesesDlg( parent, "", Sel ) ;
2085         break;
2086       }
2087
2088     case 806: // ORIENTATION ELEMENTS
2089       {
2090         smeshGUI->EmitSignalDeactivateDialog() ;
2091         SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2092         smeshGUI->myDesktop->SetSelectionMode(3, true);
2093         SMESHGUI_OrientationElementsDlg *aDlg = new SMESHGUI_OrientationElementsDlg( parent, "", Sel ) ;
2094         break;
2095       }
2096
2097     case 807: // DIAGONAL INVERSION
2098       {
2099         smeshGUI->EmitSignalDeactivateDialog() ;
2100         SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2101         Sel->ClearIObjects();
2102         smeshGUI->myDesktop->SetSelectionMode(2, true);
2103         SMESHGUI_DiagonalInversionDlg *aDlg = new SMESHGUI_DiagonalInversionDlg( parent, "", Sel ) ;
2104         break;
2105       }
2106      
2107     case 900: // MESH INFOS
2108       {
2109         smeshGUI->EmitSignalDeactivateDialog() ;
2110         SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2111         SMESHGUI_MeshInfosDlg *aDlg = new SMESHGUI_MeshInfosDlg( parent, "", Sel ) ;
2112         break;
2113       }
2114       
2115     case 1001: // AUTOMATIC UPDATE PREFERENCES
2116       {
2117         parent->menuBar()->setItemChecked(1001, !parent->menuBar()->isItemChecked(1001) );
2118         if ( parent->menuBar()->isItemChecked(1001) ) {
2119           QAD_CONFIG->addSetting("SMESH:AutomaticUpdate","true");
2120           smeshGUI->myAutomaticUpdate = true;     
2121         } else {
2122           QAD_CONFIG->addSetting("SMESH:AutomaticUpdate","false");
2123           smeshGUI->myAutomaticUpdate = false;
2124         }
2125         break;
2126       }
2127        
2128     case 1003: // MESH PREFERENCES
2129       {
2130         smeshGUI->SetDisplaySettings();
2131         break;
2132       }
2133       
2134     case 1005:
2135       {
2136         QString Bold = QAD_CONFIG->getSetting("ScalarBar:Bold");
2137         QString Italic = QAD_CONFIG->getSetting("ScalarBar:Italic");
2138         QString Shadow = QAD_CONFIG->getSetting("ScalarBar:Shadow");    
2139         QString FontFamily = QAD_CONFIG->getSetting("ScalarBar:FontFamily");
2140         QString Orientation = QAD_CONFIG->getSetting("ScalarBar:Orientation");
2141         float Width = QAD_CONFIG->getSetting("ScalarBar:Width").toFloat();  
2142         float Height = QAD_CONFIG->getSetting("ScalarBar:Height").toFloat();
2143         int NumberOfLabels = QAD_CONFIG->getSetting("ScalarBar:NumberOfLabels").toInt();
2144         int NumberOfColors = QAD_CONFIG->getSetting("ScalarBar:NumberOfColors").toInt();
2145
2146         if ( Width == 0 ) Width = 0.17;
2147         if ( Height == 0 ) Height = 0.8;
2148         if ( NumberOfLabels == 0 ) NumberOfLabels = 5;
2149         if ( NumberOfColors == 0) NumberOfColors = 64;
2150
2151         SMESHGUI_Preferences_ScalarBarDlg *aDlg = new SMESHGUI_Preferences_ScalarBarDlg( parent, "", true) ;
2152
2153         if ( Bold.compare("true") == 0 ) 
2154           aDlg->Bold->setChecked(true); else aDlg->Bold->setChecked(false);
2155         if ( Italic.compare("true") == 0 ) 
2156           aDlg->Italic->setChecked(true); else aDlg->Italic->setChecked(false);
2157         if ( Shadow.compare("true") == 0 ) 
2158           aDlg->Shadow->setChecked(true); else aDlg->Shadow->setChecked(false);
2159
2160         if ( Orientation.compare("Horizontal") == 0 ) 
2161           aDlg->RadioHoriz->setChecked(true); else aDlg->RadioVert->setChecked(true);
2162
2163         int NbItems = aDlg->ComboBox1->count();
2164         int i = 0;
2165         aDlg->ComboBox1->setCurrentItem( i );
2166         while ( i < NbItems ) {
2167           if ( FontFamily.compare( aDlg->ComboBox1->text( i ) ) == 0 )
2168             aDlg->ComboBox1->setCurrentItem( i );
2169           i++;
2170         }
2171         
2172         aDlg->LineEditWidth->setText( QString("%1").arg(Width) );
2173         aDlg->LineEditHeight->setText( QString("%1").arg(Height) );
2174
2175         aDlg->SpinBoxLabels->setValue( NumberOfLabels );
2176         aDlg->SpinBoxColors->setValue( NumberOfColors );
2177         
2178         aDlg->show();
2179         if ( aDlg->result() ) {
2180           if ( aDlg->RadioHoriz->isChecked() )
2181             Orientation = "Horizontal"; else Orientation = "Vertical";
2182           if ( aDlg->Bold->isChecked() )
2183             Bold = "true"; else Bold = "false";
2184           if ( aDlg->Italic->isChecked() )
2185             Italic = "true"; else Italic = "false";
2186           if ( aDlg->Shadow->isChecked() )
2187             Shadow = "true"; else Shadow = "false";
2188                         
2189           FontFamily = aDlg->ComboBox1->currentText();
2190           Width = aDlg->LineEditWidth->text().toFloat();
2191           Height = aDlg->LineEditHeight->text().toFloat();
2192           NumberOfColors = aDlg->SpinBoxColors->text().toInt();
2193           NumberOfLabels = aDlg->SpinBoxLabels->text().toInt();
2194
2195           
2196           vtkScalarBarActor* aScalarBar = smeshGUI->GetScalarBar();
2197           if ( aScalarBar != NULL ) {
2198             smeshGUI->SetSettingsScalarBar(aScalarBar, Bold, Italic, Shadow, 
2199                                            FontFamily, Orientation,
2200                                            Width, Height, NumberOfColors, NumberOfLabels);
2201           }
2202           
2203           QAD_CONFIG->addSetting("ScalarBar:Bold", Bold);
2204           QAD_CONFIG->addSetting("ScalarBar:Italic", Italic);
2205           QAD_CONFIG->addSetting("ScalarBar:Shadow", Shadow);    
2206           QAD_CONFIG->addSetting("ScalarBar:FontFamily", FontFamily);
2207           QAD_CONFIG->addSetting("ScalarBar:Orientation", Orientation);
2208           QAD_CONFIG->addSetting("ScalarBar:Width", Width);
2209           QAD_CONFIG->addSetting("ScalarBar:Height", Height);
2210           QAD_CONFIG->addSetting("ScalarBar:NumberOfLabels", NumberOfLabels);
2211           QAD_CONFIG->addSetting("ScalarBar:NumberOfColors", NumberOfColors);
2212         }
2213         break;
2214       }
2215       
2216     case 1100: // EDIT HYPOTHESIS
2217       {
2218         SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2219         int nbSel = Sel->IObjectCount() ;
2220
2221         if ( nbSel == 1 ) {
2222           Standard_Boolean res;
2223           SMESH::SMESH_Hypothesis_var Hyp = smeshGUI->ConvertIOinSMESHHypothesis( Sel->firstIObject(), res );
2224
2225           /* Look for all mesh objects that have this hupothesis affected in order to flag as ModifiedMesh */
2226           /* At end below '...->updateObjBrowser(true)' will change icon of mesh objects                   */
2227           /* Warning : however by internal mechanism all subMeshes icons are changed !                     */
2228           SALOMEDS::Study::ListOfSObject_var listSOmesh = smeshGUI->GetMeshesUsingAlgoOrHypothesis( Hyp) ;
2229
2230           if ( res ) {
2231             QString Name = Hyp->GetName();
2232             
2233             if ( Name.compare("LocalLength") == 0 ) {
2234               SMESH::SMESH_LocalLength_var LL = SMESH::SMESH_LocalLength::_narrow( Hyp );
2235               double beforeLength = LL->GetLength() ;
2236               double Length = smeshGUI->Parameter( res, 
2237                                                    beforeLength,
2238                                                    tr("SMESH_LOCAL_LENGTH_HYPOTHESIS"), 
2239                                                    tr("SMESH_VALUE"), 
2240                                                    1.0E-5, 1E6, 6 ) ;
2241               if ( res && Length != beforeLength ) {
2242                 LL->SetLength( Length );
2243                 for( int i=0; i<listSOmesh->length(); i++ ) {
2244                   smeshGUI->GetStudyAPI().ModifiedMesh( listSOmesh[i], false ) ;
2245                 }
2246                 break;
2247               }
2248               
2249             } else if ( Name.compare("NumberOfSegments") == 0 ) {
2250               SMESH::SMESH_NumberOfSegments_var NOS = SMESH::SMESH_NumberOfSegments::_narrow( Hyp );
2251               int beforeNbSeg = NOS->GetNumberOfSegments() ;
2252               int NbSeg = smeshGUI->Parameter( res,
2253                                                beforeNbSeg, 
2254                                                tr("SMESH_NB_SEGMENTS_HYPOTHESIS"), 
2255                                                tr("SMESH_VALUE"), 
2256                                                1, 1000000 ) ;
2257
2258               if ( res && NbSeg != beforeNbSeg ) {
2259                 NOS->SetNumberOfSegments( NbSeg );
2260                 for( int i=0; i<listSOmesh->length(); i++ ) {             
2261                   SALOMEDS::SObject_var SO = listSOmesh[i] ;
2262                   smeshGUI->GetStudyAPI().ModifiedMesh( listSOmesh[i], false ) ;
2263                 }
2264                 break;
2265               }
2266               
2267             } else if ( Name.compare("MaxElementArea") == 0 ) {
2268               SMESH::SMESH_MaxElementArea_var MEA = SMESH::SMESH_MaxElementArea::_narrow( Hyp );
2269               double beforeMaxArea = MEA->GetMaxElementArea() ;
2270               double MaxArea = smeshGUI->Parameter( res,
2271                                                     beforeMaxArea,
2272                                                     tr("SMESH_MAX_ELEMENT_AREA_HYPOTHESIS"), 
2273                                                     tr("SMESH_VALUE"), 
2274                                                     1.0E-5, 1E6, 6 ) ;
2275               if ( res && MaxArea != beforeMaxArea ) {
2276                 MEA->SetMaxElementArea( MaxArea );
2277                 for( int i=0; i<listSOmesh->length(); i++ ) {
2278                   smeshGUI->GetStudyAPI().ModifiedMesh( listSOmesh[i], false ) ;
2279                 }
2280                 break;
2281               }
2282               
2283             }  else if ( Name.compare("MaxElementVolume") == 0 ) {
2284               SMESH::SMESH_MaxElementVolume_var MEV = SMESH::SMESH_MaxElementVolume::_narrow( Hyp );
2285               double beforeMaxVolume = MEV->GetMaxElementVolume() ;
2286               double MaxVolume = smeshGUI->Parameter( res, 
2287                                                       beforeMaxVolume,
2288                                                       tr("SMESH_MAX_ELEMENT_VOLUME_HYPOTHESIS"), 
2289                                                       tr("SMESH_VALUE"), 
2290                                                       1.0E-5, 1E6, 6 ) ;
2291               if ( res && MaxVolume != beforeMaxVolume ) {
2292                 MEV->SetMaxElementVolume( MaxVolume );
2293                 for( int i=0; i<listSOmesh->length(); i++ ) {
2294                   smeshGUI->GetStudyAPI().ModifiedMesh( listSOmesh[i], false ) ;
2295                 }
2296                 break;
2297               }
2298               
2299             } else if ( Name.compare("Regular_1D") == 0 ) {
2300             } else if ( Name.compare("MEFISTO_2D") == 0 ) {
2301             } else {
2302             }
2303             
2304           }
2305         }
2306         break;
2307       }
2308       
2309     case 1101: // RENAME
2310       {
2311         SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2312         SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
2313         for ( ; It.More(); It.Next() ) {
2314           Handle(SALOME_InteractiveObject) IObject = It.Value();
2315
2316           SALOMEDS::SObject_var obj = smeshGUI->myStudy->FindObjectID( IObject->getEntry() );
2317           SALOMEDS::GenericAttribute_var anAttr;
2318           SALOMEDS::AttributeName_var    aName;
2319           if ( !obj->_is_nil() ) {
2320             if (obj->FindAttribute(anAttr, "AttributeName")) {
2321               aName = SALOMEDS::AttributeName::_narrow(anAttr);
2322               QString newName = QString( aName->Value() );
2323               newName = SALOMEGUI_NameDlg::getName( QAD_Application::getDesktop(), newName);
2324               if ( !newName.isEmpty() ) {
2325                 QApplication::setOverrideCursor( Qt::waitCursor );
2326                 smeshGUI->myActiveStudy->renameIObject( IObject, newName );
2327               }
2328               QApplication::restoreOverrideCursor();
2329             }
2330           }
2331         }
2332         break;
2333       }  
2334
2335     case 1102: // REMOVE HYPOTHESIS / ALGORITHMS
2336       {
2337         QApplication::setOverrideCursor( Qt::waitCursor );
2338         SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2339         SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
2340         for ( int i=0; It.More(); It.Next(), i++ ) {
2341           Handle(SALOME_InteractiveObject) IObject = It.Value();
2342           smeshGUI->RemoveHypothesisOrAlgorithmOnMesh( IObject );
2343         }
2344         Sel->ClearIObjects();
2345         smeshGUI->myActiveStudy->updateObjBrowser( true );
2346         QApplication::restoreOverrideCursor();
2347         break;
2348       }
2349  
2350     case 401: // GEOM::EDGE
2351       {
2352         if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
2353           smeshGUI->EmitSignalDeactivateDialog() ;
2354           SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2355           Sel->ClearIObjects();
2356           smeshGUI->myDesktop->SetSelectionMode(1, true);
2357           parent->menuBar()->setItemChecked(9010, false );
2358           parent->menuBar()->setItemChecked(9011, false );
2359           smeshGUI->ViewNodes();
2360           SMESHGUI_AddEdgeDlg *aDlg = new SMESHGUI_AddEdgeDlg( parent, "", Sel ) ;
2361         } else {
2362           QApplication::restoreOverrideCursor();
2363             QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
2364                                    tr ("SMESH_WRN_VIEWER_VTK"), tr ("SMESH_BUT_YES") );
2365         }
2366         break;
2367       }
2368     case 4021: // TRIANGLE
2369       {
2370         if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
2371           smeshGUI->EmitSignalDeactivateDialog() ;
2372           SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2373           Sel->ClearIObjects();
2374           smeshGUI->myDesktop->SetSelectionMode(1, true);
2375           parent->menuBar()->setItemChecked(9010, false );
2376           parent->menuBar()->setItemChecked(9011, false );
2377           smeshGUI->ViewNodes();
2378           SMESHGUI_AddFaceDlg *aDlg = new SMESHGUI_AddFaceDlg( parent, "", Sel, 3 ) ;
2379         } else {
2380           QApplication::restoreOverrideCursor();
2381             QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
2382                                    tr ("SMESH_WRN_VIEWER_VTK"), tr ("SMESH_BUT_YES") );
2383         }
2384         break;
2385       }
2386     case 4022: // QUAD
2387       {
2388         if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
2389           smeshGUI->EmitSignalDeactivateDialog() ;
2390           SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2391           Sel->ClearIObjects();
2392           smeshGUI->myDesktop->SetSelectionMode(1, true);
2393           parent->menuBar()->setItemChecked(9010, false );
2394           parent->menuBar()->setItemChecked(9011, false );
2395           smeshGUI->ViewNodes();
2396           SMESHGUI_AddFaceDlg *aDlg = new SMESHGUI_AddFaceDlg( parent, "", Sel, 4 ) ;
2397         } else {
2398           QApplication::restoreOverrideCursor();
2399             QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
2400                                    tr ("SMESH_WRN_VIEWER_VTK"), tr ("SMESH_BUT_YES") );
2401         }
2402         break;
2403       }
2404     case 4031: // TETRA
2405       {
2406         if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
2407           smeshGUI->EmitSignalDeactivateDialog() ;
2408           SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2409           Sel->ClearIObjects();
2410           smeshGUI->myDesktop->SetSelectionMode(1, true);
2411           parent->menuBar()->setItemChecked(9010, false );
2412           parent->menuBar()->setItemChecked(9011, false );
2413           smeshGUI->ViewNodes();
2414           SMESHGUI_AddVolumeDlg *aDlg = new SMESHGUI_AddVolumeDlg( parent, "", Sel, 4 ) ;
2415         } else {
2416           QApplication::restoreOverrideCursor();
2417             QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
2418                                    tr ("SMESH_WRN_VIEWER_VTK"), tr ("SMESH_BUT_YES") );
2419         }
2420         break;
2421       }
2422     case 4032: // HEXA
2423       {
2424         if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
2425           smeshGUI->EmitSignalDeactivateDialog() ;
2426           SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2427           Sel->ClearIObjects();
2428           smeshGUI->myDesktop->SetSelectionMode(1, true);
2429           parent->menuBar()->setItemChecked(9010, false );
2430           parent->menuBar()->setItemChecked(9011, false );
2431           smeshGUI->ViewNodes();
2432           SMESHGUI_AddVolumeDlg *aDlg = new SMESHGUI_AddVolumeDlg( parent, "", Sel, 8 ) ;
2433         } else {
2434           QApplication::restoreOverrideCursor();
2435             QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
2436                                    tr ("SMESH_WRN_VIEWER_VTK"), tr ("SMESH_BUT_YES") );
2437         }
2438         break;
2439       }
2440
2441     case 4041: // REMOVES NODES
2442       {
2443         if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
2444           smeshGUI->EmitSignalDeactivateDialog() ;
2445           SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2446           Sel->ClearIObjects();
2447           smeshGUI->myDesktop->SetSelectionMode(1, true);
2448           parent->menuBar()->setItemChecked(9010, false );
2449           parent->menuBar()->setItemChecked(9011, false );
2450           smeshGUI->ViewNodes();
2451           SMESHGUI_RemoveNodesDlg *aDlg = new SMESHGUI_RemoveNodesDlg( parent, "", Sel ) ;
2452         } else {
2453           QApplication::restoreOverrideCursor();
2454             QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
2455                                    tr ("SMESH_WRN_VIEWER_VTK"), tr ("SMESH_BUT_YES") );
2456         }
2457         break;
2458       }
2459     case 4042: // REMOVES ELEMENTS
2460       {
2461         if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
2462           smeshGUI->EmitSignalDeactivateDialog() ;
2463           SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2464           Sel->ClearIObjects();
2465           smeshGUI->myDesktop->SetSelectionMode(3, true);
2466           SMESHGUI_RemoveElementsDlg *aDlg = new SMESHGUI_RemoveElementsDlg( parent, "", Sel ) ;        
2467         } else {
2468           QApplication::restoreOverrideCursor();
2469             QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
2470                                    tr ("SMESH_WRN_VIEWER_VTK"), tr ("SMESH_BUT_YES") );
2471         }
2472         break;
2473       }
2474
2475     case 5000: // HYPOTHESIS - ALGO
2476       {
2477         smeshGUI->CreateAlgorithm("Regular_1D","Wire Discretisation");  
2478         break;
2479       }
2480     case 5010: 
2481       {
2482         smeshGUI->CreateAlgorithm("MEFISTO_2D","Triangle (Mefisto)");
2483         break;
2484       }
2485     case 5011: 
2486       {
2487         smeshGUI->CreateAlgorithm("Quadrangle_2D","Quadrangle (Mapping)");      
2488         break;
2489       }
2490     case 5020: 
2491       {
2492         smeshGUI->CreateAlgorithm("Hexa_3D","Hexahedral (i,j,k)");      
2493         break;
2494       }
2495     case 5021: 
2496       {
2497         smeshGUI->CreateAlgorithm("Tetra_3D","Tetrahedral (Netgen)");   
2498         break;
2499       }
2500
2501     case 5030: // HYPOTHESIS - LOCAL LENGTH
2502       {
2503         smeshGUI->EmitSignalDeactivateDialog() ;
2504         SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2505         SMESHGUI_LocalLengthDlg *aDlg = new SMESHGUI_LocalLengthDlg( parent, "" ) ;
2506         break;
2507       }
2508     case 5031: // HYPOTHESIS - NB SEGMENTS
2509       {
2510         smeshGUI->EmitSignalDeactivateDialog() ;
2511         SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2512         SMESHGUI_NbSegmentsDlg *aDlg = new SMESHGUI_NbSegmentsDlg( parent, "" ) ;
2513         break;
2514       }
2515
2516     case 5032: // HYPOTHESIS - MAX ELEMENT AREA
2517       {
2518         smeshGUI->EmitSignalDeactivateDialog() ;
2519         SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2520         SMESHGUI_MaxElementAreaDlg *aDlg = new SMESHGUI_MaxElementAreaDlg( parent, "" ) ;
2521         break;
2522       }
2523
2524     case 5033: // HYPOTHESIS - MAX ELEMENT VOLUME
2525       {
2526         smeshGUI->EmitSignalDeactivateDialog() ;
2527         SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2528         SMESHGUI_MaxElementVolumeDlg *aDlg = new SMESHGUI_MaxElementVolumeDlg( parent, "" ) ;
2529         break;
2530       }
2531
2532     case 6016: // CONTROLS 
2533     case 6015:
2534     case 6014:
2535     case 6013:
2536     case 6012:
2537     case 6011:
2538     case 6001:
2539       {
2540         SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2541         int nbSel = Sel->IObjectCount();
2542         if ( nbSel != 1 )
2543           break;
2544         smeshGUI->Control(theCommandID);
2545         break;
2546       }
2547       
2548     case 6002:
2549       {
2550         if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
2551           SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2552           SMESHGUI_EdgesConnectivityDlg *Dlg = new SMESHGUI_EdgesConnectivityDlg( parent, "", Sel ) ;
2553         } else {
2554           QApplication::restoreOverrideCursor();
2555           QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
2556                                  tr ("SMESH_WRN_VIEWER_VTK"), tr ("SMESH_BUT_YES") );
2557         }
2558         break;
2559       }
2560
2561     case 9010:
2562       {
2563         if ( !parent->menuBar()->isItemChecked(9010) ) {
2564           QApplication::setOverrideCursor( Qt::waitCursor );
2565           parent->menuBar()->setItemChecked(9011, false );
2566           
2567           smeshGUI->EraseSimulationActors();
2568           smeshGUI->mySimulationActors2D = vtkActor2DCollection::New();
2569
2570           SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2571           int nbSel = Sel->IObjectCount() ;
2572           if ( nbSel == 1 ) {
2573             Standard_Boolean res;
2574             SMESH_Actor* MeshActor = smeshGUI->FindActorByEntry(Sel->firstIObject()->getEntry(), res, true);
2575             if ( res ) {
2576               parent->menuBar()->setItemChecked(9010, !parent->menuBar()->isItemChecked(9010) );
2577
2578               // It's necessary to display SMDS IDs instead of VTK ones, so 
2579               // vtkIdFilter is unacceptable here. We have to do it manually :(
2580               vtkUnstructuredGrid* ptGrid = vtkUnstructuredGrid::New();
2581               ptGrid->CopyStructure(MeshActor->DataSource);
2582
2583               int numPts = MeshActor->DataSource->GetNumberOfPoints();
2584
2585               // Loop over points and generate ids
2586               vtkIntArray *ptIds = vtkIntArray::New();
2587               ptIds->SetNumberOfValues(numPts);
2588
2589               for (int id=0; id < numPts; id++) {
2590                 int idSMDS = MeshActor->GetIdSMESHDSNode(id);
2591                 ptIds->SetValue(id, idSMDS);
2592               }
2593
2594 // mpv porting vtk4.2.2
2595               //              vtkScalars* newScalars = vtkScalars::New();
2596               //              newScalars->SetData(ptIds);
2597               //              ptGrid->GetPointData()->SetScalars(newScalars);
2598               ptGrid->GetPointData()->SetScalars(ptIds);
2599               //              newScalars->Delete();
2600 // mpv
2601               ptIds->Delete();
2602               
2603               vtkMaskPoints* mask = vtkMaskPoints::New();
2604               mask->SetInput(ptGrid);
2605               mask->SetOnRatio( 1 );
2606               //            mask->SetMaximumNumberOfPoints( 50 );
2607               //            mask->RandomModeOn();
2608               
2609               vtkSelectVisiblePoints* visPts = vtkSelectVisiblePoints::New();
2610               visPts->SetInput(mask->GetOutput());
2611               visPts->SetRenderer(((VTKViewer_ViewFrame*)smeshGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer());
2612               //visPts->SetSelectInvisible(1);
2613               visPts->SelectInvisibleOff();
2614               visPts->SetTolerance(0.1);
2615             
2616               vtkLabeledDataMapper* ldm = vtkLabeledDataMapper::New();
2617               ldm->SetInput(visPts->GetOutput());
2618               ldm->SetLabelFormat("%g");
2619               ldm->SetLabelModeToLabelScalars();
2620               //ldm->SetLabelModeToLabelFieldData();
2621               
2622               ldm->SetFontFamilyToTimes();
2623               ldm->SetFontSize(6 * parent->font().pointSize() / 5);
2624               ldm->SetBold(1);
2625               ldm->SetItalic(0);
2626               ldm->SetShadow(0);
2627               
2628               vtkActor2D* pointLabels = vtkActor2D::New();
2629               pointLabels->SetMapper(ldm);
2630               pointLabels->GetProperty()->SetColor(0,1,0);
2631               
2632               visPts->Delete();
2633               ldm->Delete();
2634               smeshGUI->mySimulationActors2D->AddItem( pointLabels );
2635               ((VTKViewer_ViewFrame*)smeshGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer()->AddActor2D( pointLabels );
2636             }
2637           } 
2638         } else {
2639           QApplication::setOverrideCursor( Qt::waitCursor );
2640           parent->menuBar()->setItemChecked(9010, !parent->menuBar()->isItemChecked(9010) );
2641           smeshGUI->EraseSimulationActors();
2642           smeshGUI->ScalarVisibilityOff();
2643         }
2644         QApplication::restoreOverrideCursor();
2645         break;
2646       }
2647     case 9011:
2648       { 
2649         if ( !parent->menuBar()->isItemChecked(9011) ) {
2650           QApplication::setOverrideCursor( Qt::waitCursor );
2651           parent->menuBar()->setItemChecked(9010, false );
2652
2653           smeshGUI->EraseSimulationActors();
2654           smeshGUI->mySimulationActors2D = vtkActor2DCollection::New();
2655
2656           SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2657           int nbSel = Sel->IObjectCount() ;
2658           if ( nbSel == 1 ) {
2659             Standard_Boolean res;
2660             SMESH_Actor* MeshActor = smeshGUI->FindActorByEntry(Sel->firstIObject()->getEntry(), res, true);
2661             if ( res ) {
2662               parent->menuBar()->setItemChecked(9011, !parent->menuBar()->isItemChecked(9011) );
2663
2664               // It's necessary to display SMDS IDs instead of VTK ones, so 
2665               // vtkIdFilter is unacceptable here. We have to do it manually :(
2666               vtkUnstructuredGrid* elGrid = vtkUnstructuredGrid::New();
2667               elGrid->CopyStructure(MeshActor->DataSource);
2668
2669               int numCells = MeshActor->DataSource->GetNumberOfCells();
2670
2671               // Loop over points and generate ids
2672               vtkIntArray *cellIds = vtkIntArray::New();
2673               cellIds->SetNumberOfValues(numCells);
2674
2675               for (int id=0; id < numCells; id++) {
2676                 int idSMDS = MeshActor->GetIdSMESHDSElement(id);
2677                 cellIds->SetValue(id, idSMDS);
2678               }
2679
2680 // mpv porting vk4.2.2
2681               //              vtkScalars* newScalars = vtkScalars::New();
2682               //              newScalars->SetData(cellIds);
2683               elGrid->GetCellData()->SetScalars(cellIds);
2684               //              elGrid->GetCellData()->SetScalars(newScalars);
2685               //              newScalars->Delete();
2686 //mpv
2687
2688               cellIds->Delete();
2689             
2690               vtkCellCenters* cc = vtkCellCenters::New();
2691               cc->SetInput(elGrid);
2692
2693               vtkSelectVisiblePoints* visCells = vtkSelectVisiblePoints::New();
2694               visCells->SetInput(cc->GetOutput());
2695               visCells->SetRenderer(((VTKViewer_ViewFrame*)smeshGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer());
2696               visCells->SelectInvisibleOff();
2697               visCells->SetTolerance(0.1);
2698               //            visCells->SetSelectInvisible(1);
2699             
2700               vtkLabeledDataMapper* ldm = vtkLabeledDataMapper::New();
2701               ldm->SetInput(visCells->GetOutput());
2702               ldm->SetLabelFormat("%g");
2703               ldm->SetLabelModeToLabelScalars();
2704             
2705               ldm->SetFontFamilyToTimes();
2706               ldm->SetFontSize(6 * parent->font().pointSize() / 5);
2707               ldm->SetBold(1);
2708               ldm->SetItalic(0);
2709               ldm->SetShadow(0);
2710             
2711               vtkActor2D* cellLabels = vtkActor2D::New();
2712               cellLabels->SetMapper(ldm);
2713               cellLabels->GetProperty()->SetColor(1,0,0);
2714             
2715               cc->Delete();
2716               visCells->Delete();
2717               ldm->Delete();
2718               smeshGUI->mySimulationActors2D->AddItem( cellLabels );
2719               ((VTKViewer_ViewFrame*)smeshGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer()->AddActor2D( cellLabels );
2720             }
2721           } 
2722         } else {
2723           QApplication::setOverrideCursor( Qt::waitCursor );
2724           parent->menuBar()->setItemChecked(9011, !parent->menuBar()->isItemChecked(9011) );
2725           smeshGUI->EraseSimulationActors();
2726           smeshGUI->ScalarVisibilityOff();
2727         }
2728         QApplication::restoreOverrideCursor();
2729         break;
2730       }
2731
2732     case 10001: // DISPLAY MODE PREFERENCE
2733       {
2734         parent->menuBar()->setItemChecked(10001, !parent->menuBar()->isItemChecked(10001) );
2735         parent->menuBar()->setItemChecked(10002, false );
2736         parent->menuBar()->setItemChecked(10003, false );
2737         QAD_CONFIG->addSetting("SMESH:DisplayMode", "Wireframe");
2738         break;
2739       }
2740     case 10002:
2741       {
2742         parent->menuBar()->setItemChecked(10002, !parent->menuBar()->isItemChecked(10002) );
2743         parent->menuBar()->setItemChecked(10001, false );
2744         parent->menuBar()->setItemChecked(10003, false );
2745         QAD_CONFIG->addSetting("SMESH:DisplayMode", "Shading");
2746         break;
2747       }
2748     case 10003:
2749       {
2750         parent->menuBar()->setItemChecked(10003, !parent->menuBar()->isItemChecked(10003) );
2751         parent->menuBar()->setItemChecked(10002, false );
2752         parent->menuBar()->setItemChecked(10001, false );
2753         QAD_CONFIG->addSetting("SMESH:DisplayMode", "Shrink");
2754         break;
2755       }
2756
2757     }
2758   
2759   smeshGUI->myActiveStudy->updateObjBrowser(true);
2760   return true ;
2761 }
2762
2763
2764 //=============================================================================
2765 /*! function : GetMeshesUsingAlgoOrHypothesis()
2766  *  purpose  : return a list of Study objects (mesh kind) that have 'AlgoOrHyp' affected.
2767  *           : However is supposed here that father of father of an hypothesis is a Mesh Object.
2768  */
2769 //=============================================================================      
2770 SALOMEDS::Study::ListOfSObject* SMESHGUI::GetMeshesUsingAlgoOrHypothesis( SMESH::SMESH_Hypothesis_ptr AlgoOrHyp ) 
2771 {
2772   SALOMEDS::Study::ListOfSObject_var listSOmesh = new SALOMEDS::Study::ListOfSObject ;
2773   listSOmesh->length(0) ;
2774   unsigned int index = 0 ;
2775   if( !AlgoOrHyp->_is_nil() ) {
2776     SALOMEDS::SObject_var SO_Hypothesis = smeshGUI->GetStudyAPI().FindHypothesisOrAlgorithms( AlgoOrHyp );
2777     if( !SO_Hypothesis->_is_nil() ) {
2778       SALOMEDS::Study::ListOfSObject_var listSO = smeshGUI->myStudy->FindDependances(SO_Hypothesis) ;
2779       for( unsigned int i=0; i<listSO->length(); i++ ) {
2780         SALOMEDS::SObject_var SO = listSO[i] ;
2781         if( !SO->_is_nil() ) {
2782           SALOMEDS::SObject_var SOfatherFather = SO->GetFather()->GetFather() ;
2783           if( !SOfatherFather->_is_nil() ) {
2784             index++ ;
2785             listSOmesh->length(index) ;
2786             listSOmesh[index-1] = SOfatherFather ;
2787           }
2788         }
2789       }
2790     }
2791   }
2792   return listSOmesh._retn() ;
2793 }
2794
2795
2796 //=============================================================================
2797 /*!
2798  *
2799  */
2800 //=============================================================================
2801 void SMESHGUI::Import_Mesh(QAD_Desktop* parent, int theCommandID)
2802 {
2803   QString filter;
2804   string myExtension;
2805   Mesh_Reader* myReader;
2806   
2807   if (theCommandID==113) {
2808     filter = tr("MED files (*.med)");
2809     myExtension = string("MED");
2810     myReader = new DriverMED_R_SMESHDS_Mesh;
2811   }
2812   else if (theCommandID==112) {
2813     filter = tr("IDEAS files (*.unv)");
2814     myExtension = string("UNV");
2815   }
2816   else if (theCommandID==111) {
2817     filter = tr("DAT files (*.dat)");
2818     myExtension = string("MED");
2819     myReader = new DriverDAT_R_SMESHDS_Mesh;
2820   }
2821
2822   QString filename = QAD_FileDlg::getFileName(parent,
2823                                               "",
2824                                               filter,
2825                                               tr("Import mesh"),
2826                                               true);
2827   if ( !filename.isEmpty() ) {
2828     QApplication::setOverrideCursor( Qt::waitCursor );
2829     string myClass = string("SMESHDS_Mesh");
2830 //    Mesh_Reader* myReader = SMESHDriver::GetMeshReader(myExtension, myClass);
2831     
2832     int myMeshId = (smeshGUI->myDocument)->NewMesh();
2833     SMDS_Mesh* myMesh = (smeshGUI->myDocument)->GetMesh(myMeshId);
2834
2835     myReader->SetFile(string(filename.latin1()));
2836     myReader->SetMesh(myMesh);
2837     myReader->SetMeshId(myMeshId);
2838     myReader->Read();
2839
2840     QApplication::restoreOverrideCursor();
2841   }
2842 }
2843   
2844 //=============================================================================
2845 /*!
2846  *
2847  */
2848 //=============================================================================
2849 void SMESHGUI::Export_Mesh(QAD_Desktop* parent, int theCommandID)
2850 {
2851   SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2852   int nbSel = Sel->IObjectCount() ;
2853   if ( nbSel == 1 ) {
2854     Standard_Boolean res;
2855     Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
2856     SMESH::SMESH_Mesh_var aMesh = smeshGUI->ConvertIOinMesh( IObject, res );
2857     if ( res ) {
2858       if (theCommandID==122) { // EXPORT MED
2859         QString filename = QAD_FileDlg::getFileName(parent,
2860                                                     "",
2861                                                     tr("MED files (*.med)"),
2862                                                     tr("Export mesh"),
2863                                                     false);
2864         if ( !filename.isEmpty() ) {
2865           QApplication::setOverrideCursor( Qt::waitCursor );
2866           aMesh->ExportMED( filename.latin1() );
2867           QApplication::restoreOverrideCursor();
2868         }
2869       }
2870       else if (theCommandID==121) { // EXPORT DAT
2871         QString filename = QAD_FileDlg::getFileName(parent,
2872                                                     "",
2873                                                     tr("DAT files (*.dat)"),
2874                                                     tr("Export mesh"),
2875                                                     false);
2876         if ( !filename.isEmpty() ) {
2877           QApplication::setOverrideCursor( Qt::waitCursor );
2878           aMesh->ExportDAT( filename.latin1() );
2879           QApplication::restoreOverrideCursor();
2880         }
2881       }
2882       else if (theCommandID==123) { // EXPORT UNV
2883         QString filename = QAD_FileDlg::getFileName(parent,
2884                                                     "",
2885                                                     tr("IDEAS files (*.unv)"),
2886                                                     tr("Export mesh"),
2887                                                     false);
2888         if ( !filename.isEmpty() ) {
2889           QApplication::setOverrideCursor( Qt::waitCursor );
2890           aMesh->ExportUNV( filename.latin1() );
2891           QApplication::restoreOverrideCursor();
2892         }
2893         else 
2894           aMesh->ExportDAT( filename.latin1() );
2895
2896         QApplication::restoreOverrideCursor();
2897
2898         if ( IObject->hasEntry() )
2899           {
2900         MESSAGE("---");
2901             SALOMEDS::SObject_var SO = smeshGUI->myStudy->FindObjectID( IObject->getEntry() );
2902             SALOMEDS::GenericAttribute_var anAttr;
2903             SALOMEDS::AttributeComment_var    aFileName;
2904             SALOMEDS::StudyBuilder_var aStudyBuilder = smeshGUI->myStudy->NewBuilder();
2905             anAttr = aStudyBuilder->FindOrCreateAttribute(SO, "AttributeComment");
2906             aFileName = SALOMEDS::AttributeComment::_narrow(anAttr);
2907             aFileName->SetValue(filename.latin1());
2908           }
2909       }
2910     }
2911   }
2912 }
2913   
2914 //=============================================================================
2915 /*!
2916  *
2917  */
2918 //=============================================================================
2919 void SMESHGUI::Import_Document(QAD_Desktop* parent, int theCommandID)
2920 {
2921   QString filter;
2922   string myExtension;
2923   Document_Reader* myReader;
2924
2925   if (theCommandID==113) {
2926     filter = tr("MED files (*.med)");
2927     myExtension = string("MED");
2928     myReader = new DriverMED_R_SMESHDS_Document;
2929   }
2930   else if (theCommandID==112) {
2931     filter = tr("IDEAS files (*.unv)");
2932     myExtension = string("UNV");
2933     myReader = new DriverUNV_R_SMESHDS_Document;
2934   }
2935   else if (theCommandID==111) {
2936     filter = tr("DAT files (*.dat)");
2937     myExtension = string("DAT");
2938     myReader = new DriverDAT_R_SMESHDS_Document;
2939   }
2940
2941   QString filename = QAD_FileDlg::getFileName(parent,
2942                                               "",
2943                                               filter,
2944                                               tr("Import document"),
2945                                               true);
2946   if ( !filename.isEmpty() ) {
2947     QApplication::setOverrideCursor( Qt::waitCursor );
2948     string myClass = string("SMESHDS_Document");
2949 //    Document_Reader* myReader = SMESHDriver::GetDocumentReader(myExtension, myClass);
2950         SMESHDS_Document* newDocument = new SMESHDS_Document(1);
2951
2952     myReader->SetFile(string(filename.latin1()));
2953     myReader->SetDocument(smeshGUI->myDocument);
2954     myReader->Read();
2955     QApplication::restoreOverrideCursor();
2956   }
2957 }
2958   
2959 void SMESHGUI::Export_Document(QAD_Desktop* parent, int theCommandID)
2960 {
2961   QString filter;
2962   Document_Writer* myWriter;
2963   string myExtension;
2964
2965   if (theCommandID==122) {
2966     filter = tr("MED files (*.med)");
2967     myExtension = string("MED");
2968     myWriter = new DriverMED_W_SMESHDS_Document;
2969   }
2970   else if (theCommandID==121) {
2971     filter = tr("DAT files (*.dat)");
2972     myExtension = string("DAT");
2973     myWriter = new DriverDAT_W_SMESHDS_Document;
2974   } else if (theCommandID==123) {
2975     filter = tr("IDEAS files (*.unv)");
2976     myExtension = string("UNV");
2977     myWriter = new DriverUNV_W_SMESHDS_Document;
2978   }
2979
2980   QString filename = QAD_FileDlg::getFileName(parent,
2981                                               "",
2982                                               filter,
2983                                               tr("Export document"),
2984                                               false);
2985   if ( !filename.isEmpty() ) {
2986     QApplication::setOverrideCursor( Qt::waitCursor );
2987     string myClass = string("SMESHDS_Document");
2988     //Document_Writer* myWriter = SMESHDriver::GetDocumentWriter(myExtension, myClass);
2989
2990     myWriter->SetFile(string(filename.latin1()));
2991     myWriter->SetDocument(smeshGUI->myDocument);
2992
2993     //StudyContextStruct* myStudyContext = _impl.GetStudyContext(myStudyId);
2994     //Handle(SMESHDS_Document) myDocument = myStudyContext->myDocument;
2995     //myWriter->SetDocument(myDocument);
2996
2997     myWriter->Write();
2998     QApplication::restoreOverrideCursor();
2999   }
3000 }
3001   
3002 //=============================================================================
3003 /*!
3004  *
3005  */
3006 //=============================================================================
3007 bool SMESHGUI::OnMousePress(QMouseEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame)
3008 {
3009   SMESHGUI::GetOrCreateSMESHGUI(parent);
3010   return false ;
3011 }
3012
3013
3014 //=============================================================================
3015 /*!
3016  *
3017  */
3018 //=============================================================================
3019 bool SMESHGUI::OnMouseMove (QMouseEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame)
3020 {
3021   SMESHGUI::GetOrCreateSMESHGUI(parent);
3022
3023   return true;
3024 }
3025
3026
3027 //=============================================================================
3028 /*!
3029  *
3030  */
3031 //=============================================================================
3032 bool SMESHGUI::OnKeyPress (QKeyEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame)
3033 {
3034   SMESHGUI::GetOrCreateSMESHGUI(parent);
3035
3036   return true ;
3037 }
3038
3039
3040 //=============================================================================
3041 /*!
3042  *
3043  */
3044 //=============================================================================
3045 bool SMESHGUI::SetSettings( QAD_Desktop* parent )
3046 {
3047   SMESHGUI::GetOrCreateSMESHGUI(parent);
3048
3049   /* Display mode */
3050   QString DisplayMode = QAD_CONFIG->getSetting("SMESH:DisplayMode");
3051   if ( DisplayMode.compare("") == 0 ) {
3052     DisplayMode = "Shading";
3053     QAD_CONFIG->addSetting("SMESH:DisplayMode","Shading");
3054   }
3055
3056   if ( DisplayMode.compare("Wireframe") == 0 ){
3057     parent->menuBar()->setItemChecked(10003, false );
3058     parent->menuBar()->setItemChecked(10002, false );
3059     parent->menuBar()->setItemChecked(10001, true );
3060   } else if ( DisplayMode.compare("Shading") == 0 ){
3061     parent->menuBar()->setItemChecked(10003, false );
3062     parent->menuBar()->setItemChecked(10002, true );
3063     parent->menuBar()->setItemChecked(10001, false );
3064   } else if ( DisplayMode.compare("Shrink") == 0 ) {
3065     parent->menuBar()->setItemChecked(10003, true );
3066     parent->menuBar()->setItemChecked(10002, false );
3067     parent->menuBar()->setItemChecked(10001, false );
3068   }
3069
3070   /* Automatic Update */
3071   QString AutoUpdate = QAD_CONFIG->getSetting("SMESH:AutomaticUpdate");
3072   if ( AutoUpdate.compare("true") == 0 ) {
3073     parent->menuBar()->setItemChecked(1001, true );
3074     smeshGUI->myAutomaticUpdate = true;
3075   } else {
3076     parent->menuBar()->setItemChecked(1001, false );
3077     smeshGUI->myAutomaticUpdate = false;
3078   }
3079
3080   /* menus disable */
3081   parent->menuBar()->setItemEnabled( 11, false); // IMPORT
3082    
3083   return true;
3084 }
3085
3086
3087 //=============================================================================
3088 /*!
3089  *
3090  */
3091 //=============================================================================
3092 void SMESHGUI::DefinePopup( QString & theContext, QString & theParent, QString & theObject )
3093 {
3094   /* Create or retrieve an object SMESHGUI */
3095   SMESHGUI::GetOrCreateSMESHGUI(QAD_Application::getDesktop());
3096
3097   // NRI : Temporary added
3098   //  if ( smeshGUI->myStudy->GetProperties()->IsLocked() ) {
3099   //    theObject = "NothingSelected";
3100   //    theContext = "NothingSelected";
3101   //  }
3102   // NRI
3103
3104   SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
3105   int nbSel = Sel->IObjectCount();
3106   if (nbSel == 0) {
3107     if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
3108       vtkScalarBarActor* aScalarBar = smeshGUI->GetScalarBar();
3109       if ((aScalarBar != NULL) && (aScalarBar->GetVisibility() == 1) ) {
3110         theObject = "ScalarBar";
3111         theContext = "";
3112       } else {
3113         theObject = "NothingSelected";
3114         theContext = "NothingSelected";
3115       }
3116     } else {
3117       theObject = "NothingSelected";
3118       theContext = "NothingSelected";
3119     }
3120   } else if (nbSel == 1 ) {
3121     theObject = smeshGUI->CheckTypeObject( Sel->firstIObject() ); 
3122     theContext = "";
3123   } else {
3124     theObject = smeshGUI->CheckHomogeneousSelection();
3125     theContext = "";
3126   }
3127 }
3128
3129 //=============================================================================
3130 /*!
3131  *
3132  */
3133 //=============================================================================
3134 bool SMESHGUI::CustomPopup( QAD_Desktop* parent,
3135                            QPopupMenu* popup,
3136                            const QString& theContext,
3137                            const QString& theParent,
3138                            const QString& theObject )
3139 {
3140   // Popup should be customized for any viewer since some meaningless commands may be present in the popup
3141   //if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK) //Test du type de viewer true=OCC false=VTK
3142   //  return false;
3143   /* Create or retrieve an object SMESHGUI */
3144   SMESHGUI::GetOrCreateSMESHGUI(parent);
3145
3146   // NRI : Temporary added
3147   //  if ( smeshGUI->myStudy->GetProperties()->IsLocked() ) {
3148   //    return false;
3149   //  }
3150   // NRI
3151
3152   SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
3153   QAD_StudyFrame* studyFrame = smeshGUI->myActiveStudy->getActiveStudyFrame();
3154   int nbSel = Sel->IObjectCount();
3155   
3156   if (nbSel == 0) { 
3157     if (studyFrame->getTypeView() != VIEW_VTK)
3158       popup->clear();
3159     return false;
3160   } else if (nbSel == 1 ) {
3161     QString parentComp = ((SALOMEGUI_Desktop*)parent)->getComponentFromSelection();
3162     // First check type of active viewer (VTK required)
3163     if (/*studyFrame->getTypeView() != VIEW_VTK ||*/ parentComp != parent->getActiveComponent())
3164       {
3165       //MESSAGE("CustomPopup(): VTK viewer required, removing all SMESH-specific popup menu items")
3166       while (1) {
3167         int id = popup->idAt(0);
3168         if (id <= QAD_TopLabel_Popup_ID)
3169           popup->removeItemAt(0);
3170         else
3171           break;
3172       }
3173       if (theObject.compare("Component") == 0) {
3174         popup->removeItem(QAD_DisplayOnly_Popup_ID);
3175       }
3176       return false;
3177     }
3178
3179     // Remove common popup items for Submesh, Hypothesis and Algorithm
3180     if (theObject.compare("SubMesh") == 0 ||
3181         theObject.compare("Hypothesis") == 0 ||
3182         theObject.compare("Algorithm") == 0 ) {
3183       popup->removeItem(QAD_Display_Popup_ID);
3184       popup->removeItem(QAD_DisplayOnly_Popup_ID);
3185       popup->removeItem(QAD_Erase_Popup_ID);
3186       int id = popup->idAt(popup->count()-1); // last item
3187       if (id < 0 && id != -1) popup->removeItem(id); // separator
3188     }
3189
3190     if (theObject.compare("Component") == 0) {
3191       popup->removeItem(QAD_DisplayOnly_Popup_ID);
3192       return true;
3193     }
3194
3195     int id = QAD_TopLabel_Popup_ID;//popup->idAt(0);
3196     QFont f = QApplication::font();
3197     f.setBold( TRUE );
3198         
3199     Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
3200     
3201     if ( theParent.compare("Viewer")==0 ) {
3202       if (popup->idAt(0) == id) {
3203         popup->removeItem(id);
3204         popup->insertItem( new CustomItem ( QString(IObject->getName()), f ), id, 0 );
3205       }
3206       
3207       Standard_Boolean res;
3208       SMESH_Actor* ac = smeshGUI->FindActorByEntry( IObject->getEntry(), res, false );
3209       if ( res && studyFrame->getTypeView() == VIEW_VTK) {
3210         VTKViewer_RenderWindowInteractor* myRenderInter= 
3211           ((VTKViewer_ViewFrame*)studyFrame->getRightFrame()->getViewFrame())->getRWInteractor();
3212         if ( myRenderInter->isVisible( IObject ) ) {
3213           popup->removeItem(QAD_Display_Popup_ID);
3214         } else {
3215           popup->removeItem(QAD_Erase_Popup_ID);
3216         }
3217       } else {
3218         popup->removeItem(QAD_Erase_Popup_ID);
3219         if (!res) {// mesh not computed -> can't display it
3220           popup->removeItem(QAD_Display_Popup_ID);
3221           popup->removeItem(QAD_DisplayOnly_Popup_ID);
3222           popup->removeItemAt(popup->count() - 1);//separator
3223         }
3224       }
3225     } else if ( theParent.compare("ObjectBrowser")==0 ) {
3226       if (theObject.compare("Mesh") == 0 ||
3227           theObject.compare("SubMesh") == 0 ||
3228           theObject.compare("Hypothesis") == 0 ||
3229           theObject.compare("Algorithm") == 0 ) {
3230         popup->removeItemAt(0); 
3231       } else {
3232         if (popup->idAt(0) == id) {
3233           popup->removeItem(id);
3234           popup->removeItemAt(0);//separator
3235         }
3236       }
3237
3238       Standard_Boolean res;
3239       SMESH_Actor* ac = smeshGUI->FindActorByEntry( IObject->getEntry(), res, false );
3240       if ( res && studyFrame->getTypeView() == VIEW_VTK ) {
3241         VTKViewer_RenderWindowInteractor* myRenderInter= 
3242           ((VTKViewer_ViewFrame*)studyFrame->getRightFrame()->getViewFrame())->getRWInteractor();
3243         if ( myRenderInter->isVisible( IObject ) ) {
3244           popup->removeItem(QAD_Display_Popup_ID);
3245         } else {
3246           popup->removeItem(QAD_Erase_Popup_ID);
3247         }
3248       } else {
3249         if (theObject.compare("Mesh") == 0 ||
3250             theObject.compare("SubMesh") == 0 ||
3251             theObject.compare("Hypothesis") == 0 ||
3252             theObject.compare("Algorithm") == 0 ) {
3253         } else {
3254           popup->removeItem(QAD_Erase_Popup_ID);
3255           if (!res) {// mesh not computed -> can't display it
3256             popup->removeItem(QAD_Display_Popup_ID);
3257             popup->removeItem(QAD_DisplayOnly_Popup_ID);
3258             popup->removeItemAt(popup->count() - 1);//separator
3259           }
3260         }
3261       }
3262     }
3263   } else {
3264     QString parentComp = ((SALOMEGUI_Desktop*)parent)->getComponentFromSelection();
3265     QAD_StudyFrame* studyFrame = smeshGUI->myActiveStudy->getActiveStudyFrame();
3266     if (/*studyFrame->getTypeView() != VIEW_VTK ||*/ parentComp != parent->getActiveComponent())
3267     {
3268       //MESSAGE("CustomPopup(): VTK viewer required, removing all SMESH-specific popup menu items")
3269       while (1) {
3270         int id = popup->idAt(0);
3271         if (id <= QAD_TopLabel_Popup_ID && id != -1)
3272           popup->removeItemAt(0);
3273         else
3274           break;
3275       }
3276       if (parentComp.isNull()) { // objects from several components are selected
3277         popup->removeItem(QAD_DisplayOnly_Popup_ID);    
3278         popup->removeItem(QAD_Display_Popup_ID);
3279         popup->removeItem(QAD_Erase_Popup_ID);
3280         int id = popup->idAt(popup->count()-1); // last item
3281         if (id < 0 && id != -1) popup->removeItem(id); // separator
3282       }
3283       return false;
3284     }
3285
3286     QString type =  smeshGUI->CheckHomogeneousSelection();
3287     if ( type.compare("Heterogeneous Selection") != 0 ) {
3288       int id = QAD_TopLabel_Popup_ID;//popup->idAt(0);
3289       QFont f = QApplication::font();
3290       f.setBold( TRUE );
3291       popup->removeItem(id);
3292       popup->insertItem( new CustomItem ( QString("%1 ").arg(nbSel) + type + " (s) ", f), id, 0  );
3293     }
3294   }
3295   return false;
3296 }
3297
3298 //=============================================================================
3299 /*! Method:  BuildPresentation(const Handle(SALOME_InteractiveObject)& theIO)
3300  *  Purpose: ensures that the actor for the given <theIO> exists in the active VTK view
3301  */
3302 //=============================================================================
3303 void SMESHGUI::BuildPresentation(const Handle(SALOME_InteractiveObject)& theIO)
3304 {
3305   /* Create or retrieve an object SMESHGUI */
3306   SMESHGUI::GetOrCreateSMESHGUI(QAD_Application::getDesktop());
3307   
3308   QAD_StudyFrame* activeFrame = smeshGUI->myActiveStudy->getActiveStudyFrame();
3309   if (activeFrame->getTypeView() == VIEW_VTK) {
3310     // VTK
3311     SALOMEDS::SObject_var fatherSF = 
3312       smeshGUI->myStudy->FindObjectID(activeFrame->entry());
3313     
3314     SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
3315     SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
3316     
3317 //    for(;It.More();It.Next()) {
3318 //      Handle(SALOME_InteractiveObject) IObject = It.Value();
3319       Handle(SALOME_InteractiveObject) IObject = theIO;
3320       if ( IObject->hasEntry() ) {
3321         // Look for the actor in all views
3322         Standard_Boolean res;
3323         SMESH_Actor *ac = smeshGUI->FindActorByEntry(IObject->getEntry(), res, false);
3324
3325         // Actor not found at all -> mesh is not computed -> do nothing!!!
3326         if ( !res ) {
3327           /*SMESH::SMESH_Mesh_var aM;
3328           SALOMEDS::SObject_var aMorSM = smeshGUI->myStudy->FindObjectID( IObject->getEntry() );
3329           SALOMEDS::SObject_var father = aMorSM->GetFather();
3330           SALOMEDS::SObject_var fatherComp = aMorSM->GetFatherComponent();
3331           
3332           // Non-displayable objects (Hypo, Algo) have tags < 3 or have a father different from component
3333           if (aMorSM->Tag() < 3 || strcmp(father->GetID(), fatherComp->GetID()) != 0)
3334             continue;
3335
3336           SALOMEDS::GenericAttribute_var anAttr;
3337           SALOMEDS::AttributeIOR_var     anIOR;
3338           if ( !aMorSM->_is_nil() ) {
3339             if (aMorSM->FindAttribute(anAttr, "AttributeIOR") ) {
3340               anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
3341               aM = SMESH::SMESH_Mesh::_narrow( _orb->string_to_object(anIOR->Value()) );
3342             }
3343           }
3344
3345           if (!aM->_is_nil()) {
3346             smeshGUI->InitActor(aM);
3347             ac = smeshGUI->ReadScript(aM);
3348           }
3349
3350           if (ac) {
3351             smeshGUI->DisplayActor( ac, true );
3352             smeshGUI->DisplayEdges( ac ); 
3353             smeshGUI->ChangeRepresentation( ac, ac->getDisplayMode() );
3354           }*/
3355 //        continue;
3356         } else { // The actor exists in some view
3357           // Check whether the actor belongs to the active view
3358           VTKViewer_RenderWindowInteractor* rwInter = 
3359             ((VTKViewer_ViewFrame*)activeFrame->getRightFrame()->getViewFrame())->getRWInteractor();
3360
3361           // The actor belongs to inactive view -> create a copy and display it in the active view
3362           if (!rwInter->isInViewer(IObject)) {
3363             SMESH_Actor* acCopy = SMESH_Actor::New();
3364             acCopy->ShallowCopy(ac);
3365             ac = acCopy;
3366           }
3367           smeshGUI->DisplayActor( ac, false );
3368           smeshGUI->DisplayEdges( ac ); 
3369           smeshGUI->ChangeRepresentation( ac, ac->getDisplayMode() );
3370         }
3371       }
3372 //    }
3373   } else {
3374     MESSAGE("BuildPresentation() must not be called while non-VTK view is active")
3375   }
3376 }
3377
3378 //=============================================================================
3379 /*!
3380  *
3381  */
3382 //=============================================================================
3383 void SMESHGUI::setOrb()
3384 {
3385   try {
3386     ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance();
3387     ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting());
3388     _orb = init( 0 , 0 );
3389   } catch (...) {
3390     INFOS("internal error : orb not found");
3391     _orb = 0;
3392   }
3393   ASSERT(! CORBA::is_nil(_orb));
3394 }
3395
3396
3397 //=============================================================================
3398 /*!
3399  *
3400  */
3401 //=============================================================================
3402 SMESH_Actor* SMESHGUI::ReadScript(SMESH::SMESH_Mesh_ptr aMesh)
3403 {
3404   SMESH_Actor* MeshActor;
3405   if ( !aMesh->_is_nil() ) {
3406     Standard_Boolean result;
3407     MeshActor = FindActor(aMesh, result, true);
3408     if ( result ) {
3409       SMESH::log_array_var aSeq = aMesh->GetLog(true);
3410       
3411       if (aSeq->length() == 0) {
3412         MESSAGE("ReadScript(): log is empty")
3413         return MeshActor;
3414       }
3415
3416       for (unsigned int ind = 0; ind < aSeq->length();ind++) {
3417         switch ( aSeq[ind].commandType )
3418           {
3419           case SMESH::ADD_NODE :
3420             {
3421               AddNodes( MeshActor, aSeq[ind].number, aSeq[ind].coords, aSeq[ind].indexes );
3422               break;
3423             }
3424           case SMESH::ADD_EDGE :
3425             {
3426               //              AddEdges( MeshActor, aSeq[ind].number, aSeq[ind].coords, aSeq[ind].indexes );
3427               break;
3428             }
3429           case SMESH::ADD_TRIANGLE :
3430             {
3431               AddTriangles( MeshActor, aSeq[ind].number, aSeq[ind].coords, aSeq[ind].indexes );
3432               break;
3433             }
3434           case SMESH::ADD_QUADRANGLE :
3435             {
3436               AddQuadrangles( MeshActor, aSeq[ind].number, aSeq[ind].coords, aSeq[ind].indexes );
3437               break;
3438             }
3439           case SMESH::ADD_TETRAHEDRON :
3440             {
3441               AddTetras( MeshActor, aSeq[ind].number, aSeq[ind].coords, aSeq[ind].indexes );
3442               break;
3443             }
3444           case SMESH::ADD_PYRAMID :
3445             {
3446               break;
3447             }
3448           case SMESH::ADD_PRISM :
3449             {
3450               break;
3451             }
3452           case SMESH::ADD_HEXAHEDRON :
3453             {
3454               AddHexaedres( MeshActor, aSeq[ind].number, aSeq[ind].coords, aSeq[ind].indexes );
3455               break;
3456             }
3457           case SMESH::REMOVE_NODE :
3458             {
3459               RemoveNodes( MeshActor, aSeq[ind].number, aSeq[ind].coords, aSeq[ind].indexes );
3460               break;
3461             }
3462           case SMESH::REMOVE_ELEMENT :
3463             {
3464               RemoveElements( MeshActor, aSeq[ind].number, aSeq[ind].coords, aSeq[ind].indexes );
3465               break;
3466             }
3467           }
3468       }
3469       return MeshActor;
3470     }
3471   }
3472   return NULL;
3473 }
3474
3475
3476 //=============================================================================
3477 /*!
3478  *
3479  */
3480 //=============================================================================
3481 void SMESHGUI::Dump(SMESH_Actor* Mactor)
3482 {
3483   vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
3484   vtkPoints *Pts = ugrid->GetPoints();
3485   int nbPts = Pts->GetNumberOfPoints();
3486   int nbCells = ugrid->GetNumberOfCells();
3487
3488   FILE *In;
3489   int i,j;
3490   In = fopen("/tmp/dumpMesh","w+");
3491   fprintf(In,"%d %d\n",nbPts,nbCells);
3492   for ( int i = 0; i < nbPts; i++ ) {
3493     float *p = ugrid->GetPoint(i);
3494     fprintf(In,"%d %e %e %e\n",i, p[0], p[1], p[2] );
3495   }
3496
3497   for ( int i = 0; i < nbCells; i++ ) {
3498     fprintf(In,"%d %d",i,ugrid->GetCell(i)->GetCellType());
3499     vtkIdList *Id = ugrid->GetCell(i)->GetPointIds();
3500     for (j=0; j<Id->GetNumberOfIds(); j++) {
3501       fprintf(In," %d",Id->GetId(j));
3502     }
3503     fprintf(In,"\n");
3504   }
3505   fclose(In);
3506 }
3507
3508
3509 //=============================================================================
3510 /*!
3511  *
3512  */
3513 //=============================================================================
3514 void SMESHGUI::AddNodes( SMESH_Actor* Mactor, int number, 
3515                          const SMESH::double_array& coords,
3516                          const SMESH::long_array& indexes)
3517 {
3518   QApplication::setOverrideCursor( Qt::waitCursor );
3519   if ( Mactor->GetMapper() == NULL ) {
3520     vtkPoints    *Pts = vtkPoints::New();
3521     SMESH_Grid *ugrid = SMESH_Grid::New();
3522     ugrid->Allocate();
3523
3524     int i = 1;
3525     int j = 1;
3526     while ( i <= number ) {
3527       int idVTK = Pts->InsertNextPoint( coords[j-1], coords[j], coords[j+1] );
3528       //Mactor->AddNode( indexes[i-1], idVTK );
3529       ugrid->AddNode( indexes[i-1], idVTK );
3530       i++;
3531       j = j + 3;
3532     }
3533     //vtkUnstructuredGrid *ugrid = vtkUnstructuredGrid::New();
3534     ugrid->SetPoints(Pts);
3535     vtkDataSetMapper * PtsMapper = vtkDataSetMapper::New();
3536     PtsMapper->SetInput( ugrid );
3537     Mactor->DataSource = PtsMapper->GetInput();
3538     Mactor->SetMapper(PtsMapper);
3539   } else {
3540     //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
3541     SMESH_Grid* ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
3542     int i = 1;
3543     int j = 1;
3544     while ( i <= number ) {
3545       int idVTK = ugrid->GetPoints()->InsertNextPoint( coords[j-1], coords[j], coords[j+1] );
3546       ugrid->AddNode( indexes[i-1], idVTK );
3547       i++;
3548       j = j + 3;
3549     }
3550     vtkDataSetMapper *PtsMapper = vtkDataSetMapper::New();
3551     PtsMapper->SetInput( ugrid );
3552     Mactor->DataSource = PtsMapper->GetInput();
3553     Mactor->SetMapper(PtsMapper);
3554   }
3555   QApplication::restoreOverrideCursor();
3556 }
3557
3558 //=============================================================================
3559 /*!
3560  *
3561  */
3562 //=============================================================================
3563 void SMESHGUI::AddNode(SMESH_Actor* Mactor, int idnode, float x, float y, float z)
3564 {
3565   QApplication::setOverrideCursor( Qt::waitCursor );
3566   MESSAGE ( "SMESHGUI::AddNode " << idnode << " : " << x << ";" << y << ";" << z )
3567   if ( Mactor->GetMapper() == NULL ) {
3568     vtkPoints *Pts = vtkPoints::New();
3569     int idVTK = Pts->InsertNextPoint( x, y, z );
3570     //Mactor->AddNode( idnode, idVTK );
3571     //vtkUnstructuredGrid *ugrid = vtkUnstructuredGrid::New();
3572     SMESH_Grid *ugrid = SMESH_Grid::New();
3573     ugrid->Allocate();
3574     ugrid->AddNode( idnode, idVTK );
3575     ugrid->SetPoints(Pts);
3576     vtkDataSetMapper * PtsMapper = vtkDataSetMapper::New();
3577     PtsMapper->SetInput( ugrid );
3578     Mactor->DataSource = PtsMapper->GetInput();
3579     Mactor->SetMapper(PtsMapper);
3580   } else {
3581     //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
3582     SMESH_Grid *ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
3583     int idVTK = ugrid->GetPoints()->InsertNextPoint( x, y, z );
3584     //Mactor->AddNode( idnode, idVTK );
3585     ugrid->AddNode( idnode, idVTK );
3586     vtkDataSetMapper *PtsMapper = vtkDataSetMapper::New();
3587     PtsMapper->SetInput( ugrid );
3588     Mactor->DataSource = PtsMapper->GetInput();
3589     Mactor->SetMapper(PtsMapper);
3590   }
3591   QApplication::restoreOverrideCursor();
3592 }
3593
3594 //=============================================================================
3595 /*!
3596  *
3597  */
3598 //=============================================================================
3599 void SMESHGUI::RemoveNode(SMESH_Actor* Mactor, int idnode)
3600 {
3601   MESSAGE ( " OLD RemoveNode method " )
3602 //   int id = Mactor->GetIdVTKNode( idnode );
3603 //    MESSAGE ( " RemoveNode id VTK " << id )
3604 //    if ( Mactor->GetMapper() != NULL ) {
3605 //      vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
3606 //      vtkUnstructuredGrid* newUgrid = vtkUnstructuredGrid::New();
3607 //      vtkPoints *Pts = ugrid->GetPoints();
3608 //      vtkPoints *newPts = vtkPoints::New();
3609 //      int nbPts = Pts->GetNumberOfPoints();
3610 //      bool findPt = false;
3611 //      for ( int i = 0; i < nbPts; i++ ) {
3612 //        if ( id != i ) {
3613 //      if ( !findPt)
3614 //        newPts->InsertPoint(i, Pts->GetPoint(i) );
3615 //      else
3616 //        newPts->InsertPoint(i-1, Pts->GetPoint(i) );
3617 //        } else {
3618 //      findPt = true;
3619 //      Mactor->RemoveNode( idnode );
3620 //        }
3621 //      }
3622
3623 //      newUgrid->SetPoints(newPts);
3624 //      int nbCells = ugrid->GetNumberOfCells();
3625 //      for ( int i = 0; i < nbCells; i++ ) {
3626 //        vtkIdList *Ids = ugrid->GetCell(i)->GetPointIds();
3627 //        vtkIdList *newIds = vtkIdList::New();
3628 //        int nbIds = Ids->GetNumberOfIds();
3629 //        newIds->SetNumberOfIds(nbIds);
3630 //        for ( int j = 0; j < nbIds; j++ ) {
3631 //      int theid = Ids->GetId(j);
3632 //      if ( theid > id ) {
3633 //        newIds->SetId( j, theid-1 );
3634 //      } else
3635 //        newIds->SetId( j, theid );
3636 //        }
3637 //        int idSMDSel = Mactor->GetIdSMESHDSElement( i );
3638 //        Mactor->RemoveElement( idSMDSel, false );
3639 //        int idVTKel = newUgrid->InsertNextCell( ugrid->GetCell(i)->GetCellType(), newIds );
3640 //        Mactor->AddElement( idSMDSel, idVTKel );
3641 //      }
3642
3643
3644 //      vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
3645 //      Mapper->SetInput( newUgrid );
3646 //      Mactor->DataSource = Mapper->GetInput();
3647 //      Mactor->SetMapper(Mapper);
3648
3649 //      UpdateView();
3650 //    }
3651 }
3652
3653 //=============================================================================
3654 /*!
3655  *
3656  */
3657 //=============================================================================
3658 void SMESHGUI::RemoveNodes(SMESH_Actor* Mactor, int number, 
3659                            const SMESH::double_array& coords, const SMESH::long_array& indexes)
3660 {
3661   QApplication::setOverrideCursor( Qt::waitCursor );
3662   int i = 1;
3663   while ( i <= number ) {
3664     Mactor->RemoveNode( indexes[i-1] );
3665     i++;
3666   }
3667
3668   TColStd_DataMapOfIntegerInteger newMapVTKNodes;
3669   TColStd_DataMapOfIntegerInteger newMapSMESHDSNodes;
3670   TColStd_DataMapOfIntegerInteger MapOldNodesToNewNodes;
3671
3672   if ( Mactor->GetMapper() != NULL ) {
3673     SMESH_Grid *ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
3674     SMESH_Grid *newUgrid = SMESH_Grid::New();
3675     newUgrid->CopyMaps(ugrid);
3676
3677     vtkPoints *Pts = ugrid->GetPoints();
3678     vtkPoints *newPts = vtkPoints::New();
3679     int nbPts = Pts->GetNumberOfPoints();
3680     int j = 0;
3681     for ( int i = 0; i < nbPts; i++ ) {
3682       int idSMESHDSNode = Mactor->GetIdSMESHDSNode(i);
3683       if ( idSMESHDSNode != -1 ) {
3684         newPts->InsertPoint(j, Pts->GetPoint(i) );
3685
3686         newMapVTKNodes.Bind(j, idSMESHDSNode);
3687         newMapSMESHDSNodes.Bind(idSMESHDSNode, j);
3688
3689         MapOldNodesToNewNodes.Bind(i,j);
3690         j++;
3691       }
3692     }
3693
3694     newUgrid->SetIdsVTKNode(newMapVTKNodes); 
3695     newUgrid->SetIdsSMESHDSNode(newMapSMESHDSNodes); 
3696     newUgrid->SetPoints(newPts);
3697
3698     TColStd_DataMapOfIntegerInteger newMapElementSMDStoVTK;
3699     TColStd_DataMapOfIntegerInteger newMapElementVTKtoSMDS;
3700
3701     int nbCells = ugrid->GetNumberOfCells();
3702     for ( int i = 0; i < nbCells; i++ ) {
3703       vtkIdList *Ids = ugrid->GetCell(i)->GetPointIds();
3704       vtkIdList *newIds = vtkIdList::New();
3705       int nbIds = Ids->GetNumberOfIds();
3706       newIds->SetNumberOfIds(nbIds);
3707       bool isGood = true;
3708       for ( int j = 0; j < nbIds; j++ ) {
3709         int theid = Ids->GetId(j);
3710         if ( MapOldNodesToNewNodes.IsBound( theid ) ) {
3711           newIds->SetId( j, MapOldNodesToNewNodes.Find( theid ) );
3712         } else {
3713           isGood = false;
3714           break;
3715         }
3716       }
3717
3718       // Filtering out cells based on non-existing nodes
3719       if (isGood) {
3720         int idSMDSel = Mactor->GetIdSMESHDSElement( i );
3721         int idVTKel = newUgrid->InsertNextCell( ugrid->GetCell(i)->GetCellType(), newIds );
3722
3723         newMapElementSMDStoVTK.Bind(idSMDSel, idVTKel);
3724         newMapElementVTKtoSMDS.Bind(idVTKel, idSMDSel);
3725       }
3726     }
3727
3728     newUgrid->SetIdsVTKElement(newMapElementVTKtoSMDS);
3729     newUgrid->SetIdsSMESHDSElement(newMapElementSMDStoVTK);
3730     
3731     // Copy new data to the old DatSource: keep the single DataSource for all actors
3732     ugrid->DeepCopy(newUgrid);
3733
3734     vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
3735     Mapper->SetInput( ugrid );
3736     Mactor->SetMapper(Mapper);
3737     
3738     // Commented to avoid multiple viewer updates when called by ReadScript()
3739     //UpdateView();
3740
3741   }
3742   QApplication::restoreOverrideCursor();
3743 }
3744
3745 //=============================================================================
3746 /*!
3747  *
3748  */
3749 //=============================================================================
3750 void SMESHGUI::RemoveNodes(SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex)
3751 {
3752   QApplication::setOverrideCursor( Qt::waitCursor );
3753   Standard_Boolean result;
3754   SMESH_Actor* ac = FindActor( aMesh, result, true );
3755   if ( result ) {
3756     SMESH::long_array_var anArrayOfIdeces = new  SMESH::long_array;
3757     anArrayOfIdeces->length(MapIndex.Extent());
3758     TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
3759     int i = 0;
3760     for ( ; ite.More(); ite.Next() ) {
3761       //      MESSAGE ( " RemoveNode : id " << ac->GetIdSMESHDSNode(ite.Key()) )
3762       anArrayOfIdeces[i] = ac->GetIdSMESHDSNode(ite.Key());
3763       i++;
3764     }
3765     SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
3766     aMeshEditor->RemoveNodes(anArrayOfIdeces);
3767
3768   }
3769   if ( myAutomaticUpdate ) {
3770     SMESH_Actor* Mesh = smeshGUI->ReadScript(aMesh);
3771     if ( Mesh != NULL ) {
3772       smeshGUI->DisplayActor( Mesh );
3773       smeshGUI->DisplayEdges( Mesh );
3774       smeshGUI->ChangeRepresentation( Mesh, Mesh->getDisplayMode() );
3775       AddActorInSelection( Mesh );
3776     }
3777   }
3778   QApplication::restoreOverrideCursor();
3779 }
3780
3781 //=============================================================================
3782 /*!
3783  *
3784  */
3785 //=============================================================================
3786 void SMESHGUI::RemoveElement(SMESH_Actor* Mactor, int idelement)
3787 {
3788   MESSAGE ( " OLD RemoveElement method " )
3789 //    int id = Mactor->GetIdVTKElement( idelement );
3790 //    MESSAGE ( " RemoveElement id VTK : " << id )
3791 //    if ( Mactor->GetMapper() != NULL ) {
3792 //      vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
3793 //      vtkUnstructuredGrid* newUgrid = vtkUnstructuredGrid::New();
3794     
3795 //      int nbCells = ugrid->GetNumberOfCells();
3796 //      for ( int i = 0; i < nbCells; i++ ) {
3797 //        if ( id != i ) {
3798 //      newUgrid->InsertNextCell( ugrid->GetCell(i)->GetCellType(), 
3799 //                                ugrid->GetCell(i)->GetPointIds() );
3800 //        } else
3801 //      Mactor->RemoveElement( idelement );
3802 //      }
3803 //      newUgrid->SetPoints(ugrid->GetPoints());
3804     
3805 //      vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
3806 //      Mapper->SetInput( newUgrid );
3807 //      Mactor->DataSource = Mapper->GetInput();
3808 //      Mactor->SetMapper(Mapper);
3809     
3810 //      UpdateView();
3811 //    }
3812 }
3813
3814 //=============================================================================
3815 /*!
3816  *
3817  */
3818 //=============================================================================
3819 void SMESHGUI::RemoveElements(SMESH_Actor* Mactor, int number, 
3820                               const SMESH::double_array& coords, const SMESH::long_array& indexes)
3821 {
3822   QApplication::setOverrideCursor( Qt::waitCursor );
3823   int i = 1;
3824   while ( i <= number ) {
3825     Mactor->RemoveElement( indexes[i-1] );
3826     i++;
3827   }
3828   TColStd_DataMapOfIntegerInteger newMapElementSMDStoVTK;
3829   TColStd_DataMapOfIntegerInteger newMapElementVTKtoSMDS;
3830
3831   if ( Mactor->GetMapper() != NULL ) {
3832     SMESH_Grid*    ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
3833     SMESH_Grid* newUgrid = SMESH_Grid::New();
3834     newUgrid->CopyMaps(ugrid);
3835
3836     int nbCells = ugrid->GetNumberOfCells();
3837     for ( int i = 0; i < nbCells; i++ ) {
3838       int idSMESHDSElement = Mactor->GetIdSMESHDSElement(i);
3839       if ( idSMESHDSElement != -1 ) {
3840         int newId = newUgrid->InsertNextCell( ugrid->GetCell(i)->GetCellType(), 
3841                                               ugrid->GetCell(i)->GetPointIds() );
3842         newMapElementSMDStoVTK.Bind(idSMESHDSElement, newId);
3843         newMapElementVTKtoSMDS.Bind(newId, idSMESHDSElement);
3844       }
3845     }
3846
3847     newUgrid->SetIdsVTKElement(newMapElementVTKtoSMDS);
3848     newUgrid->SetIdsSMESHDSElement(newMapElementSMDStoVTK);
3849
3850     newUgrid->SetPoints(ugrid->GetPoints());
3851
3852     // Copy new data to the old DatSource: keep the single DataSource for all actors
3853     ugrid->DeepCopy(newUgrid);
3854     
3855     vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
3856     Mapper->SetInput( ugrid );
3857     Mactor->SetMapper(Mapper);
3858
3859     // Commented to avoid multiple viewer updates when called by ReadScript()
3860     //UpdateView();
3861   }
3862   QApplication::restoreOverrideCursor();
3863 }
3864
3865 //=============================================================================
3866 /*!
3867  *
3868  */
3869 //=============================================================================
3870 void SMESHGUI::RemoveElements(SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex)
3871 {
3872   QApplication::setOverrideCursor( Qt::waitCursor );
3873   Standard_Boolean result;
3874   SMESH_Actor* ac = FindActor( aMesh, result, true );
3875   if ( result ) {
3876     SMESH::long_array_var anArrayOfIdeces = new  SMESH::long_array;
3877     anArrayOfIdeces->length(MapIndex.Extent());
3878     TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
3879     int i = 0;
3880     for ( ; ite.More(); ite.Next() ) {
3881       //      MESSAGE ( " RemoveElement : id " << ite.Key() << "," << ac->GetIdSMESHDSElement(ite.Key()) )
3882       anArrayOfIdeces[i] = ac->GetIdSMESHDSElement(ite.Key());
3883       i++;
3884     }
3885
3886     SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
3887     aMeshEditor->RemoveElements(anArrayOfIdeces);
3888   }
3889     
3890   if ( myAutomaticUpdate ) {
3891     SMESH_Actor* Mesh = smeshGUI->ReadScript(aMesh);
3892     if ( Mesh != NULL ) {
3893       smeshGUI->DisplayActor( Mesh );
3894       smeshGUI->DisplayEdges( Mesh );
3895       smeshGUI->ChangeRepresentation( Mesh, Mesh->getDisplayMode() );
3896       AddActorInSelection( Mesh );
3897 #ifdef TRACE
3898       Dump( Mesh );
3899 #endif
3900     }
3901   }
3902   QApplication::restoreOverrideCursor();
3903 }
3904
3905
3906 //=============================================================================
3907 /*!
3908  *
3909  */
3910 //=============================================================================
3911 void SMESHGUI::OrientationElements(SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex)
3912 {
3913   if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK) 
3914     return;
3915
3916   vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
3917   Standard_Boolean result;
3918   SMESH_Actor* ac = FindActor( aMesh, result, true );
3919   if ( result ) {
3920     //vtkUnstructuredGrid* UGrid = vtkUnstructuredGrid::New();
3921     SMESH_Grid*   UGrid = SMESH_Grid::New();
3922     SMESH_Grid* oldGrid = SMESH_Grid::SafeDownCast(ac->DataSource);
3923     UGrid->CopyMaps(oldGrid);
3924
3925     vtkGeometryFilter *gf = vtkGeometryFilter::New();
3926     gf->SetInput( ac->DataSource );
3927
3928     vtkPolyDataMapper *Mapper = vtkPolyDataMapper::New();
3929     Mapper->SetInput( gf->GetOutput() );
3930     Mapper->Update();
3931
3932     TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
3933     for ( ; ite.More(); ite.Next() ) {
3934        Mapper->GetInput()->ReverseCell( ite.Key() );
3935     }
3936
3937     UGrid->SetPoints( Mapper->GetInput()->GetPoints() );
3938     int nbCells = Mapper->GetInput()->GetNumberOfCells();
3939     for ( int i = 0; i < nbCells; i++ ) {
3940       UGrid->InsertNextCell( Mapper->GetInput()->GetCellType(i), Mapper->GetInput()->GetCell(i)->GetPointIds() );
3941     }
3942
3943     // Copy new data to the old DatSource: keep the single DataSource for all actors
3944     oldGrid->DeepCopy(UGrid);
3945
3946     vtkDataSetMapper *NewMapper = vtkDataSetMapper::New();
3947     //NewMapper->SetInput( UGrid );
3948     NewMapper->SetInput( oldGrid );
3949     NewMapper->Update();
3950
3951     //ac->DataSource = NewMapper->GetInput();
3952     ac->SetMapper( NewMapper );
3953   }
3954   vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
3955   renWin->Render();
3956   QApplication::restoreOverrideCursor();
3957 }
3958
3959
3960 //=============================================================================
3961 /*!
3962  *
3963  */
3964 //=============================================================================
3965 void SMESHGUI::DiagonalInversion(SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex)
3966 {
3967   if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK) 
3968     return;
3969
3970   QApplication::setOverrideCursor( Qt::waitCursor );
3971   vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();  
3972   Standard_Boolean result;
3973
3974   SMESH_Actor* ac = FindActor( aMesh, result, true );
3975   if ( result ) {
3976     //vtkUnstructuredGrid* UGrid = vtkUnstructuredGrid::New();
3977     SMESH_Grid* UGrid = SMESH_Grid::New();
3978     vtkGeometryFilter *gf = vtkGeometryFilter::New();
3979     gf->SetInput( ac->DataSource );
3980     
3981     vtkExtractEdges *edges = vtkExtractEdges::New();
3982     edges->SetInput( ac->DataSource );
3983
3984     vtkPolyDataMapper *Mapper = vtkPolyDataMapper::New();
3985     Mapper->SetInput( edges->GetOutput() );
3986     Mapper->Update();
3987
3988     int nb = Mapper->GetInput()->GetNumberOfCells();
3989     //MESSAGE ( "nb : " << nb )
3990
3991     TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
3992     for ( ; ite.More(); ite.Next() ) {
3993       vtkCell* StartEdge = Mapper->GetInput()->GetCell(ite.Key());
3994       //MESSAGE( "DCQ : Edge Id = " << ite.Key())
3995       int CellType = StartEdge->GetCellType();
3996       //MESSAGE( "DCQ : Cell Type = " << CellType)
3997       int nbPoints = StartEdge->GetNumberOfPoints();
3998
3999       //MESSAGE( "DCQ : Nb Point = " << nbPoints)
4000       if ( nbPoints == 2 ) {
4001         vtkUnstructuredGrid* StartUGrid = vtkUnstructuredGrid::SafeDownCast( ac->DataSource );
4002         
4003         vtkIdList *IdCells =  vtkIdList::New();
4004         vtkIdList *IdPoints = StartEdge->GetPointIds();
4005         float p1[3];
4006         float p2[3];
4007         
4008         Mapper->GetInput()->GetPoints()->GetPoint(IdPoints->GetId(0),p1);
4009         Mapper->GetInput()->GetPoints()->GetPoint(IdPoints->GetId(1),p2);
4010
4011         int idp1 = StartUGrid->FindPoint(p1);
4012         int idp2 = StartUGrid->FindPoint(p2);
4013
4014         StartUGrid->GetPointCells( idp1, IdCells );
4015         
4016         //MESSAGE ( " pt 0 : " << IdPoints->GetId(0) )
4017         //MESSAGE ( " pt 1 : " << IdPoints->GetId(1) )
4018
4019         //MESSAGE ( " pt 0 : " << idp1 )
4020         //MESSAGE ( " pt 1 : " << idp2 )
4021
4022         vtkIdList *IdPts = vtkIdList::New();
4023         if (IdCells->GetNumberOfIds() >= 2) {
4024           int nbCells = IdCells->GetNumberOfIds();
4025           //MESSAGE ( " nbCells : " << nbCells )
4026           for (int j=0; j<nbCells; j++) {
4027             StartUGrid->GetCellPoints( IdCells->GetId(j), IdPts );
4028             if ( IdPts->IsId( idp2 ) == -1 ) {
4029               IdCells->DeleteId( IdCells->GetId(j) );
4030             }
4031           }
4032         
4033
4034           //MESSAGE ( " IdCells " << IdCells->GetNumberOfIds() )
4035
4036           vtkIdList *IdPts0 = vtkIdList::New();
4037           vtkIdList *IdPts1 = vtkIdList::New();
4038
4039           if (IdCells->GetNumberOfIds() == 2) {
4040             StartUGrid->GetCellPoints( IdCells->GetId(0), IdPts0 );
4041             StartUGrid->GetCellPoints( IdCells->GetId(1), IdPts1 );
4042             
4043             //Create new faces
4044             TColStd_MapOfInteger EndMapIndex;
4045             for (int j = 0; j < 3; j++ ) {
4046               if ( IdPts0->GetId(j) != idp1 && IdPts0->GetId(j) != idp2 ) {
4047                 EndMapIndex.Add( IdPts0->GetId(j) );
4048               }
4049               if ( IdPts1->GetId(j) != idp1 && IdPts1->GetId(j) != idp2 ) {
4050                 EndMapIndex.Add( IdPts1->GetId(j) );
4051               }
4052             }
4053
4054             bool MyAU = myAutomaticUpdate ;
4055             myAutomaticUpdate = false ;
4056
4057             EndMapIndex.Add( idp1 );
4058             TColStd_MapIteratorOfMapOfInteger ite1( EndMapIndex );
4059             int i = 1;
4060             while ( ite1.More() ) {
4061               if ( ite1.Key() == idp1 )
4062                 break;
4063               i++;
4064               ite1.Next();
4065             }
4066             bool reverse1 = ( i == 2 );
4067             this->AddFace( aMesh, EndMapIndex, reverse1 );
4068             
4069             EndMapIndex.Remove( idp1 );
4070             EndMapIndex.Add( idp2 );
4071             TColStd_MapIteratorOfMapOfInteger ite2( EndMapIndex );
4072             i = 1;
4073             while ( ite2.More() ) {
4074               if ( ite2.Key() == idp2 )
4075                 break;
4076               i++;
4077               ite2.Next();
4078             }
4079             bool reverse2 = ( i == 2 );
4080             this->AddFace( aMesh, EndMapIndex, !(reverse1 == reverse2) );
4081             
4082             myAutomaticUpdate = MyAU ;
4083             //MESSAGE ( " myAutomaticUpdate = " << MyAU )
4084             Mapper->Update();
4085             //Remove old faces
4086             TColStd_MapOfInteger StartMapIndex;
4087             StartMapIndex.Add( IdCells->GetId(0) );
4088             StartMapIndex.Add( IdCells->GetId(1) );
4089             this->RemoveElements( aMesh, StartMapIndex );
4090             
4091             Mapper->Update();
4092           } 
4093         }
4094       }
4095     }
4096     
4097     //      UGrid->SetPoints( Mapper->GetInput()->GetPoints() );
4098     //      int nbCells = Mapper->GetInput()->GetNumberOfCells();
4099     //      for ( int i = 0; i < nbCells; i++ ) {
4100     //        UGrid->InsertNextCell( Mapper->GetInput()->GetCellType(i), Mapper->GetInput()->GetCell(i)->GetPointIds() );
4101     //      }
4102     
4103     //      vtkDataSetMapper *NewMapper = vtkDataSetMapper::New();
4104     //      NewMapper->SetInput( UGrid );
4105     //      NewMapper->Update();
4106     
4107     //      ac->DataSource = NewMapper->GetInput();
4108     //      ac->SetMapper( NewMapper );
4109   }
4110   vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
4111   renWin->Render();
4112   QApplication::restoreOverrideCursor();
4113 }
4114
4115
4116 //=============================================================================
4117 /*!
4118  *
4119  */
4120 //=============================================================================
4121 void SMESHGUI::AddEdges( SMESH_Actor* Mactor, int number, 
4122                          const SMESH::double_array& coords, const SMESH::long_array& indexes)
4123 {
4124   QApplication::setOverrideCursor( Qt::waitCursor );
4125   //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4126   SMESH_Grid* ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
4127   int i = 1;
4128   int j = 1;
4129   while ( i <= number ) {
4130     vtkIdList *Ids = vtkIdList::New();
4131     Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j] ) );
4132     Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+1] ) );
4133     int id = ugrid->InsertNextCell(VTK_LINE, Ids);
4134     Mactor->AddElement( indexes[j-1], id );
4135     i++;
4136     j = j + 3;
4137   }
4138   vtkDataSetMapper *EdgeMapper = vtkDataSetMapper::New();
4139   EdgeMapper->SetInput( ugrid );
4140   Mactor->DataSource = EdgeMapper->GetInput();
4141   Mactor->SetMapper(EdgeMapper);
4142   QApplication::restoreOverrideCursor();
4143 }
4144
4145 //=============================================================================
4146 /*!
4147  *
4148  */
4149 //=============================================================================
4150 void SMESHGUI::AddEdge(SMESH_Actor* Mactor, int idedge, int idnode1, int idnode2) 
4151 {
4152   QApplication::setOverrideCursor( Qt::waitCursor );
4153   MESSAGE ( "SMESHGUI::AddEdge " << idedge << " : " << idnode1 << ";" << idnode2 )
4154   vtkIdList *Ids = vtkIdList::New();
4155   Ids->InsertNextId( Mactor->GetIdVTKNode( idnode1 ) );
4156   Ids->InsertNextId( Mactor->GetIdVTKNode( idnode2 ) );
4157
4158   //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4159   SMESH_Grid* ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
4160   int id = ugrid->InsertNextCell(VTK_LINE, Ids);
4161   Mactor->AddElement( idedge, id );
4162   
4163   MESSAGE ( " Edge VTK id " << id )
4164
4165   vtkDataSetMapper *EdgeMapper = vtkDataSetMapper::New();
4166   EdgeMapper->SetInput( ugrid );
4167   Mactor->DataSource = EdgeMapper->GetInput();
4168   Mactor->SetMapper(EdgeMapper);
4169   QApplication::restoreOverrideCursor();
4170 }
4171
4172 //=============================================================================
4173 /*!
4174  *
4175  */
4176 //=============================================================================
4177 void SMESHGUI::AddTriangles( SMESH_Actor* Mactor, int number, 
4178                              const SMESH::double_array& coords, const SMESH::long_array& indexes)
4179 {
4180   QApplication::setOverrideCursor( Qt::waitCursor );
4181   //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4182   SMESH_Grid* ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
4183   int i = 1;
4184   int j = 1;
4185   while ( i <= number ) {
4186     vtkIdList *Ids = vtkIdList::New();
4187     Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j] ) );
4188     Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+1] ) );
4189     Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+2] ) );
4190     int id = ugrid->InsertNextCell(VTK_TRIANGLE, Ids);
4191     Mactor->AddElement( indexes[j-1], id );
4192     i++;
4193     j = j + 4;
4194   }
4195   vtkDataSetMapper *TriMapper = vtkDataSetMapper::New();
4196   TriMapper->SetInput( ugrid );
4197   Mactor->DataSource = TriMapper->GetInput();
4198   Mactor->SetMapper(TriMapper);
4199   QApplication::restoreOverrideCursor();
4200 }
4201 void SMESHGUI::AddTriangle(SMESH_Actor* Mactor, int idtri, int idnode1, int idnode2, int idnode3) 
4202 {
4203   QApplication::setOverrideCursor( Qt::waitCursor );
4204   vtkIdList *Ids = vtkIdList::New();
4205   Ids->InsertNextId( Mactor->GetIdVTKNode( idnode1 ) );
4206   Ids->InsertNextId( Mactor->GetIdVTKNode( idnode2 ) );
4207   Ids->InsertNextId( Mactor->GetIdVTKNode( idnode3 ) );
4208
4209   //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4210   SMESH_Grid* ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
4211   int id = ugrid->InsertNextCell(VTK_TRIANGLE, Ids);
4212   Mactor->AddElement( idtri, id );
4213
4214   vtkDataSetMapper *TriMapper = vtkDataSetMapper::New();
4215   TriMapper->SetInput( ugrid );
4216   Mactor->DataSource = TriMapper->GetInput();
4217   Mactor->SetMapper(TriMapper);
4218   QApplication::restoreOverrideCursor();
4219 }
4220
4221 //=============================================================================
4222 /*!
4223  *
4224  */
4225 //=============================================================================
4226 void SMESHGUI::AddQuadrangles( SMESH_Actor* Mactor, int number, 
4227                                const SMESH::double_array& coords, const SMESH::long_array& indexes)
4228 {
4229   QApplication::setOverrideCursor( Qt::waitCursor );
4230   //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4231   SMESH_Grid* ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
4232   int i = 1;
4233   int j = 1;
4234   while ( i <= number ) {
4235     vtkIdList *Ids = vtkIdList::New();
4236     Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j] ) );
4237     Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+1] ) );
4238     Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+2] ) );
4239     Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+3] ) );
4240     int id = ugrid->InsertNextCell(VTK_QUAD, Ids);
4241     Mactor->AddElement( indexes[j-1], id );
4242     i++;
4243     j = j + 5;
4244   }
4245   vtkDataSetMapper *QuadMapper = vtkDataSetMapper::New();
4246   QuadMapper->SetInput( ugrid );
4247   Mactor->DataSource = QuadMapper->GetInput();
4248   Mactor->SetMapper(QuadMapper);
4249   QApplication::restoreOverrideCursor();
4250 }
4251
4252
4253 //=============================================================================
4254 /*!
4255  *
4256  */
4257 //=============================================================================
4258 void SMESHGUI::AddQuadrangle(SMESH_Actor* Mactor, int idquad, int idnode1, int idnode2, 
4259                              int idnode3, int idnode4) 
4260 {
4261   QApplication::setOverrideCursor( Qt::waitCursor );
4262   vtkIdList *Ids = vtkIdList::New();
4263   Ids->InsertNextId( Mactor->GetIdVTKNode( idnode1 ) );
4264   Ids->InsertNextId( Mactor->GetIdVTKNode( idnode2 ) );
4265   Ids->InsertNextId( Mactor->GetIdVTKNode( idnode3 ) );
4266   Ids->InsertNextId( Mactor->GetIdVTKNode( idnode4 ) );
4267
4268   //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4269   SMESH_Grid* ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
4270   int id = ugrid->InsertNextCell(VTK_QUAD, Ids);
4271   Mactor->AddElement( idquad, id );
4272
4273   vtkDataSetMapper *QuadMapper = vtkDataSetMapper::New();
4274   QuadMapper->SetInput( ugrid );
4275   Mactor->DataSource = QuadMapper->GetInput();
4276   Mactor->SetMapper(QuadMapper);
4277   QApplication::restoreOverrideCursor();
4278 }
4279
4280
4281 //=============================================================================
4282 /*!
4283  *
4284  */
4285 //=============================================================================
4286 void SMESHGUI::AddTetras( SMESH_Actor* Mactor, int number, 
4287                                const SMESH::double_array& coords, const SMESH::long_array& indexes)
4288 {
4289   QApplication::setOverrideCursor( Qt::waitCursor );
4290   //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4291     SMESH_Grid* ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
4292   int i = 1;
4293   int j = 1;
4294   while ( i <= number ) {
4295     vtkIdList *Ids = vtkIdList::New();
4296     Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j] ) );
4297     Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+1] ) );
4298     Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+2] ) );
4299     Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+3] ) );
4300     int id = ugrid->InsertNextCell(VTK_TETRA, Ids);
4301     Mactor->AddElement( indexes[j-1], id );
4302     i++;
4303     j = j + 5;
4304   }
4305   vtkDataSetMapper *TetraMapper = vtkDataSetMapper::New();
4306   TetraMapper->SetInput( ugrid );
4307   Mactor->DataSource = TetraMapper->GetInput();
4308   Mactor->SetMapper(TetraMapper);
4309   QApplication::restoreOverrideCursor();
4310 }
4311
4312
4313 //=============================================================================
4314 /*!
4315  *
4316  */
4317 //=============================================================================
4318 void SMESHGUI::AddTetra(SMESH_Actor* Mactor, int idtetra, int idnode1, int idnode2, 
4319                         int idnode3, int idnode4) 
4320 {
4321   QApplication::setOverrideCursor( Qt::waitCursor );
4322   MESSAGE ( "SMESHGUI::AddTetra " << idtetra << " : " << idnode1 << ";" << idnode2  
4323             << ";" << idnode3 << ";" << idnode4 )
4324   vtkIdList *Ids = vtkIdList::New();
4325   Ids->InsertNextId( Mactor->GetIdVTKNode( idnode1 ) );
4326   Ids->InsertNextId( Mactor->GetIdVTKNode( idnode2 ) );
4327   Ids->InsertNextId( Mactor->GetIdVTKNode( idnode3 ) );
4328   Ids->InsertNextId( Mactor->GetIdVTKNode( idnode4 ) );
4329
4330   //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4331   SMESH_Grid* ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
4332   int id = ugrid->InsertNextCell(VTK_TETRA, Ids);
4333   Mactor->AddElement( idtetra, id );
4334   
4335   MESSAGE ( " Tetra VTK id " << id )
4336
4337   vtkDataSetMapper *TetraMapper = vtkDataSetMapper::New();
4338   TetraMapper->SetInput( ugrid );
4339   Mactor->DataSource = TetraMapper->GetInput();
4340   Mactor->SetMapper(TetraMapper);
4341   QApplication::restoreOverrideCursor();
4342 }
4343
4344
4345 //=============================================================================
4346 /*!
4347  *
4348  */
4349 //=============================================================================
4350 void SMESHGUI::AddHexaedres( SMESH_Actor* Mactor, int number, 
4351                                const SMESH::double_array& coords, const SMESH::long_array& indexes)
4352 {
4353   QApplication::setOverrideCursor( Qt::waitCursor );
4354   //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4355   SMESH_Grid* ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
4356   int i = 1;
4357   int j = 1;
4358   while ( i <= number ) {
4359     vtkIdList *Ids = vtkIdList::New();
4360     Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j] ) );
4361     Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+1] ) );
4362     Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+2] ) );
4363     Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+3] ) );
4364     Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+4] ) );
4365     Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+5] ) );
4366     Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+6] ) );
4367     Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+7] ) );
4368     int id = ugrid->InsertNextCell(VTK_HEXAHEDRON, Ids);
4369     Mactor->AddElement( indexes[j-1], id );
4370     i++;
4371     j = j + 9;
4372   }
4373   vtkDataSetMapper *HexaMapper = vtkDataSetMapper::New();
4374   HexaMapper->SetInput( ugrid );
4375   Mactor->DataSource = HexaMapper->GetInput();
4376   Mactor->SetMapper(HexaMapper);
4377   QApplication::restoreOverrideCursor();
4378 }
4379
4380
4381 //=============================================================================
4382 /*!
4383  *
4384  */
4385 //=============================================================================
4386 void SMESHGUI::AddHexaedre(SMESH_Actor* Mactor, int idhexa, int idnode1, int idnode2, 
4387                            int idnode3, int idnode4, int idnode5, int idnode6, int idnode7, int idnode8) 
4388 {
4389   QApplication::setOverrideCursor( Qt::waitCursor );
4390   MESSAGE ( "SMESHGUI::AddHexaedre " << idhexa << " : " << idnode1 << ";" << idnode2  
4391             << ";" << idnode3 << ";" << idnode4 << ";" << idnode5 << ";" << idnode6
4392             << ";" << idnode7 << ";" << idnode8)
4393
4394   vtkIdList *Ids = vtkIdList::New();
4395   Ids->InsertNextId( Mactor->GetIdVTKNode( idnode1 ) );
4396   Ids->InsertNextId( Mactor->GetIdVTKNode( idnode2 ) );
4397   Ids->InsertNextId( Mactor->GetIdVTKNode( idnode3 ) );
4398   Ids->InsertNextId( Mactor->GetIdVTKNode( idnode4 ) );
4399   Ids->InsertNextId( Mactor->GetIdVTKNode( idnode5 ) );
4400   Ids->InsertNextId( Mactor->GetIdVTKNode( idnode6 ) );
4401   Ids->InsertNextId( Mactor->GetIdVTKNode( idnode7 ) );
4402   Ids->InsertNextId( Mactor->GetIdVTKNode( idnode8 ) );
4403
4404   //vtkUnstructuredGrid *ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4405   SMESH_Grid* ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
4406   int id = ugrid->InsertNextCell(VTK_HEXAHEDRON, Ids);
4407   Mactor->AddElement( idhexa, id );
4408   
4409   MESSAGE ( " Hexa VTK id " << id )
4410
4411   vtkDataSetMapper *HexaMapper = vtkDataSetMapper::New();
4412   HexaMapper->SetInput( ugrid );
4413   Mactor->DataSource = HexaMapper->GetInput();
4414   Mactor->SetMapper(HexaMapper);
4415   QApplication::restoreOverrideCursor();
4416 }
4417
4418 //=====================================================================================
4419 // EXPORTED METHODS
4420 //=====================================================================================
4421 extern "C"
4422 {
4423   bool OnGUIEvent(int theCommandID, QAD_Desktop* parent)
4424   {
4425     return SMESHGUI::OnGUIEvent(theCommandID, parent);
4426   }
4427
4428   bool OnKeyPress (QKeyEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame)
4429   {
4430     return SMESHGUI::OnKeyPress (pe, parent, studyFrame);
4431   }
4432
4433   bool OnMousePress (QMouseEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame)
4434   {
4435     return SMESHGUI::OnMousePress (pe, parent, studyFrame);
4436   }
4437
4438   bool OnMouseMove (QMouseEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame)
4439   {
4440     return SMESHGUI::OnMouseMove (pe, parent, studyFrame);
4441   }
4442
4443   bool SetSettings ( QAD_Desktop* parent )
4444   {
4445     return SMESHGUI::SetSettings( parent );
4446   }
4447
4448   bool customPopup ( QAD_Desktop* parent, QPopupMenu* popup, const QString & theContext,
4449                      const QString & theParent, const QString & theObject )
4450   {
4451      return SMESHGUI::CustomPopup( parent, popup, theContext, theParent, theObject );
4452   }
4453
4454   void definePopup ( QString & theContext, QString & theParent, QString & theObject )
4455   {
4456     SMESHGUI::DefinePopup( theContext, theParent, theObject );
4457   }
4458   
4459   bool activeStudyChanged ( QAD_Desktop* parent )
4460   {
4461     SMESHGUI::activeStudyChanged( parent );
4462   }
4463
4464   void buildPresentation ( const Handle(SALOME_InteractiveObject)& theIO )
4465   {
4466     SMESHGUI::BuildPresentation(theIO);
4467   }
4468
4469   void supportedViewType(int* buffer, int bufferSize)
4470   {
4471     if (!buffer || !bufferSize) return;
4472     buffer[0] = (int)VIEW_VTK;
4473   }
4474
4475 }
4476
4477
4478 //=============================================================================
4479 /*!
4480  *
4481  */
4482 //=============================================================================
4483 void SMESHGUI::ViewNodes()
4484 {
4485   if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK) 
4486     return;
4487
4488   EraseSimulationActors();
4489   mySimulationActors = vtkActorCollection::New();
4490   vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
4491   vtkActorCollection* theActors = theRenderer->GetActors();
4492   theActors->InitTraversal();
4493   vtkActor *ac = theActors->GetNextActor();
4494   while(!(ac==NULL)) {
4495     if ( ac->IsA("SMESH_Actor") ) {
4496       SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( ac );
4497       if ( anActor->GetVisibility() == 1 ) {
4498         vtkGeometryFilter *gf = vtkGeometryFilter::New();
4499         gf->SetInput( anActor->DataSource );
4500         vtkMaskPoints *verts = vtkMaskPoints::New();
4501         verts->SetInput(gf->GetOutput());
4502         verts->GenerateVerticesOn();
4503         verts->SetOnRatio(1);
4504       
4505         vtkPolyDataMapper *vertMapper = vtkPolyDataMapper::New();
4506         vertMapper->SetInput(verts->GetOutput());
4507         vertMapper->ScalarVisibilityOff();
4508       
4509         vtkActor *vertActor = vtkActor::New();
4510         vertActor->SetMapper(vertMapper);
4511
4512         float r, g , b ;
4513         anActor->GetNodeColor(r, g, b ) ;
4514         vertActor->GetProperty()->SetColor( r, g, b ) ;
4515
4516         vertActor->GetProperty()->SetPointSize( anActor->GetNodeSize() );
4517
4518         vertActor->PickableOff();
4519
4520         mySimulationActors->AddItem( vertActor );
4521         theRenderer->AddActor( vertActor );
4522       }
4523     }
4524     ac = theActors->GetNextActor();
4525   }
4526   
4527   vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
4528   renWin->Render();
4529 }
4530
4531
4532 //=============================================================================
4533 /*!
4534  *
4535  */
4536 //=============================================================================
4537 void SMESHGUI::Control(int theCommandID)
4538 {
4539   if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK) 
4540     return;
4541
4542   QApplication::setOverrideCursor( Qt::waitCursor );
4543   DisplayScalarBar( false );
4544
4545 // mpv porting vtk 4.2.2
4546 //  vtkScalars *scalars = vtkScalars::New();
4547   vtkIntArray *scalars = vtkIntArray::New();
4548   scalars->SetNumberOfComponents(1);
4549
4550   vtkDataSetMapper* meshMapper = 0;
4551   SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
4552   int nbSel = Sel->IObjectCount();
4553   Standard_Boolean result;
4554   Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
4555   SMESH_Actor* MeshActor = FindActorByEntry(IObject->getEntry(), result, true);
4556
4557   // Mesh may be not updated after Compute
4558   if (!MeshActor->DataSource || !MeshActor->GetMapper()) {
4559     QApplication::restoreOverrideCursor();
4560     return;
4561   }
4562
4563   bool ValidateScalars = false;
4564   if ( result ) {
4565     QString type;
4566     switch (theCommandID)
4567       {
4568       case 6001: //Length Edges
4569         {
4570           type = tr( "SMESH_CONTROL_LENGTH_EDGES");
4571           meshMapper = (vtkDataSetMapper*)MeshActor->EdgeDevice->GetMapper();
4572           vtkUnstructuredGrid* grid = (vtkUnstructuredGrid*)meshMapper->GetInput();
4573           MESSAGE ( " init minimum length " << grid->GetNumberOfCells() )
4574           for (int i=0; i<grid->GetNumberOfCells(); i++ ) {
4575             vtkCell* cell = grid->GetCell(i);
4576             float len = SMESHGUI_ComputeScalarValue::LengthEdges(cell);
4577             if (len == 0) continue;
4578             else {
4579               ValidateScalars = true;
4580 // mpv porting vtk 4.2.2
4581 //            scalars->InsertScalar(i,len);
4582               scalars->InsertTuple1(i,len);
4583             }
4584           }
4585           if (ValidateScalars && (MeshActor->getDisplayMode()!=0))
4586             ChangeRepresentation( MeshActor, 1 );// limitation; in Wireframe, colored edges are not visible
4587           break;
4588         }
4589       case 6011: // Area Elements
4590         {
4591           type = tr( "SMESH_CONTROL_AREA_ELEMENTS");
4592           for (int i=0; i< MeshActor->GetMapper()->GetInput()->GetNumberOfCells(); i++ ) {
4593             vtkCell* cell = MeshActor->GetMapper()->GetInput()->GetCell(i);
4594             float area = SMESHGUI_ComputeScalarValue::AreaElements(cell);
4595             if (area == 0) continue;
4596             else {
4597               ValidateScalars = true;
4598 // mpv porting vtk 4.2.2
4599 //            scalars->InsertScalar(i,area);
4600               scalars->InsertTuple1(i,area);
4601             }
4602           }
4603           if (ValidateScalars && (MeshActor->getDisplayMode()!=1))
4604             ChangeRepresentation( MeshActor, 1 );
4605           break;
4606         }
4607       case 6012: // Taper
4608         {
4609           type = tr( "SMESH_CONTROL_TAPER_ELEMENTS");
4610           for (int i=0; i< MeshActor->DataSource->GetNumberOfCells(); i++ ) {
4611             vtkCell* cell = MeshActor->DataSource->GetCell(i);
4612             float taper = SMESHGUI_ComputeScalarValue::Taper(cell);
4613             if (taper == 0) continue;
4614             else {
4615               ValidateScalars = true;
4616 // mpv porting vtk 4.2.2
4617 //            scalars->InsertScalar(i,taper);
4618               scalars->InsertTuple1(i,taper);
4619             }
4620           }
4621           break;
4622         }
4623       case 6013: // Aspect ratio
4624         {
4625           type = tr( "SMESH_CONTROL_ASPECTRATIO_ELEMENTS");
4626           for (int i=0; i<MeshActor->DataSource->GetNumberOfCells(); i++ ) {
4627             vtkCell* cell = MeshActor->DataSource->GetCell(i);
4628             float aspect = SMESHGUI_ComputeScalarValue::AspectRatio(cell);
4629             if (aspect == 0) continue;
4630             else {
4631               ValidateScalars = true;
4632 // mpv porting vtk 4.2.2
4633 //            scalars->InsertScalar(i,aspect);
4634               scalars->InsertTuple1(i,aspect);
4635             }
4636           }
4637           if (ValidateScalars && (MeshActor->getDisplayMode()!=1))
4638             ChangeRepresentation( MeshActor, 1 );
4639           break;
4640         }
4641       case 6014: // Minimum angle
4642         {
4643           type = tr( "SMESH_CONTROL_MINIMUMANGLE_ELEMENTS");
4644           for (int i=0; i<MeshActor->DataSource->GetNumberOfCells(); i++ ) {
4645             vtkCell* cell = MeshActor->DataSource->GetCell(i);
4646             float angle = SMESHGUI_ComputeScalarValue::MinimumAngle(cell);
4647             if (angle == 0) continue;
4648             else {
4649               ValidateScalars = true;
4650 // mpv porting vtk 4.2.2
4651 //            scalars->InsertScalar(i,angle);
4652               scalars->InsertTuple1(i,angle);
4653             }
4654           }
4655           if (ValidateScalars && (MeshActor->getDisplayMode()!=1))
4656             ChangeRepresentation( MeshActor, 1 );
4657           break;
4658         }
4659       case 6015: // Warp
4660         {
4661           type = tr( "SMESH_CONTROL_WARP_ELEMENTS");
4662           for (int i=0; i<MeshActor->DataSource->GetNumberOfCells(); i++ ) {
4663             vtkCell* cell = MeshActor->DataSource->GetCell(i);
4664             float Warp = SMESHGUI_ComputeScalarValue::Warp(cell);
4665             if (Warp == 0) continue;
4666             else {
4667               ValidateScalars = true;
4668 // mpv porting vtk 4.2.2
4669 //            scalars->InsertScalar(i,Warp);
4670               scalars->InsertTuple1(i,Warp);
4671             }
4672           }
4673           break;
4674         }
4675       case 6016: // Skew
4676         {
4677           type = tr( "SMESH_CONTROL_SKEW_ELEMENTS");
4678           for (int i=0; i<MeshActor->DataSource->GetNumberOfCells(); i++ ) {
4679             vtkCell* cell = MeshActor->DataSource->GetCell(i);
4680             float angle = SMESHGUI_ComputeScalarValue::Skew(cell);
4681             if (angle == 0) continue;
4682             else {
4683               ValidateScalars = true;
4684 // mpv porting vtk 4.2.2
4685 //            scalars->InsertScalar(i,angle);
4686               scalars->InsertTuple1(i,angle);
4687             }
4688           }
4689           break;
4690         }
4691       }
4692
4693     if ( !ValidateScalars ) {
4694       QApplication::restoreOverrideCursor();
4695       return;
4696     }
4697
4698     float range[2];
4699     scalars->GetRange(range);
4700
4701     vtkLookupTable* wat = vtkLookupTable::New();
4702     wat->SetRange( range );
4703     wat->Build();
4704
4705     scalars->SetLookupTable(wat);
4706
4707     if (!meshMapper) meshMapper = (vtkDataSetMapper*) (MeshActor->getMapper());
4708     meshMapper->SetScalarModeToUseCellData();
4709     meshMapper->GetInput()->GetCellData()->SetScalars(scalars);
4710     meshMapper->SetScalarRange( range );
4711     meshMapper->ScalarVisibilityOn();
4712
4713     vtkScalarBarActor* aScalarBar = GetScalarBar();
4714     if ( aScalarBar == NULL ) {
4715       aScalarBar = vtkScalarBarActor::New();
4716       QString Bold = QAD_CONFIG->getSetting("ScalarBar:Bold");
4717       QString Italic = QAD_CONFIG->getSetting("ScalarBar:Italic");
4718       QString Shadow = QAD_CONFIG->getSetting("ScalarBar:Shadow");    
4719       QString FontFamily = QAD_CONFIG->getSetting("ScalarBar:FontFamily");
4720       QString Orientation = QAD_CONFIG->getSetting("ScalarBar:Orientation");
4721       float Width = QAD_CONFIG->getSetting("ScalarBar:Width").toFloat();  
4722       float Height = QAD_CONFIG->getSetting("ScalarBar:Height").toFloat();
4723       int NumberOfLabels = QAD_CONFIG->getSetting("ScalarBar:NumberOfLabels").toInt();
4724       int NumberOfColors = QAD_CONFIG->getSetting("ScalarBar:NumberOfColors").toInt();
4725       
4726       SetSettingsScalarBar(aScalarBar, Bold, Italic, Shadow, FontFamily, Orientation,
4727                            Width, Height, NumberOfColors, NumberOfLabels);
4728       vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
4729       theRenderer->AddActor2D(aScalarBar);
4730     }  
4731     aScalarBar->SetLookupTable( wat );
4732     aScalarBar->SetTitle( type.latin1() );
4733
4734     scalars->Delete();
4735     //    wat->Delete();
4736     DisplayScalarBar( true );
4737   }
4738   QApplication::restoreOverrideCursor();
4739 }
4740
4741
4742 //=============================================================================
4743 /*!
4744  *
4745  */
4746 //=============================================================================
4747 void SMESHGUI::SetSettingsScalarBar(vtkScalarBarActor* theScalarBar,
4748                                     QString Bold, QString Italic,
4749                                     QString Shadow, QString FontFamily, 
4750                                     QString Orientation, float Width, float Height, 
4751                                     int NbColors, int NbLabels  )
4752 {
4753   if ( Bold.isNull() || Bold.isEmpty() || (Bold.compare( "true" ) == 0) )
4754    theScalarBar->BoldOn();
4755   else
4756     theScalarBar->BoldOff();
4757
4758   if ( Italic.isNull() || Italic.isEmpty() || (Italic.compare( "true" ) == 0) )
4759     theScalarBar->ItalicOn();
4760   else
4761     theScalarBar->ItalicOff();
4762   
4763   if ( Shadow.isNull() || Shadow.isEmpty() || (Shadow.compare( "true" ) == 0) )
4764     theScalarBar->ShadowOn();
4765   else
4766     theScalarBar->ShadowOff();
4767     
4768   if ( FontFamily.compare( "Arial" ) == 0 )
4769     theScalarBar->SetFontFamilyToArial();
4770   else if ( FontFamily.compare( "Courier" ) == 0 )
4771     theScalarBar->SetFontFamilyToCourier();
4772   else if ( FontFamily.compare( "Times" ) == 0 )
4773     theScalarBar->SetFontFamilyToTimes();
4774   else
4775     theScalarBar->SetFontFamilyToArial();
4776
4777   if ( Orientation.isNull() || Orientation.isEmpty() || (Orientation.compare( "Vertical" ) == 0) )
4778     theScalarBar->SetOrientationToVertical();
4779   else
4780     theScalarBar->SetOrientationToHorizontal();
4781    
4782   
4783   theScalarBar->SetWidth((Width == 0)? 0.17 : Width);
4784   theScalarBar->SetHeight((Height == 0)? 0.8 : Height);
4785
4786   theScalarBar->SetNumberOfLabels((NbLabels == 0)? 5 : NbLabels); 
4787   theScalarBar->SetMaximumNumberOfColors((NbColors == 0)? 64 : NbColors);
4788 }
4789
4790
4791 //=============================================================================
4792 /*!
4793  *
4794  */
4795 //=============================================================================
4796 void SMESHGUI::DisplayScalarBar(bool visibility)
4797 {
4798   if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK) 
4799     return;
4800
4801   vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
4802   vtkScalarBarActor* aScalarBar = GetScalarBar();
4803
4804   if ( aScalarBar == NULL ) {
4805     MESSAGE("myScalarBar is NULL");
4806     return;
4807   }
4808
4809   if ( visibility )
4810     aScalarBar->VisibilityOn();
4811   else {
4812     aScalarBar->VisibilityOff();
4813     //Turn off mesh coloring (influences on all views)
4814     vtkActorCollection* actorList=theRenderer->GetActors();
4815     actorList->InitTraversal();
4816     vtkActor *ac = actorList->GetNextActor();
4817     while(ac!=NULL) {
4818       if (ac->GetMapper() != NULL) {
4819         ac->GetMapper()->ScalarVisibilityOff();
4820       }
4821       ac = actorList->GetNextActor();
4822     }
4823     // Turn off ScalarBar in all views
4824     /*QList<QAD_StudyFrame> aFrames = myActiveStudy->getStudyFrames();
4825     for ( QAD_StudyFrame* aFrame = aFrames.first(); aFrame; aFrame = aFrames.next() ) {
4826       if (aFrame->getTypeView() == VIEW_VTK) {
4827         vtkRenderer *aRenderer = ((VTKViewer_ViewFrame*) aFrame->getRightFrame()->getViewFrame())->getRenderer();
4828         vtkActor2DCollection* actor2DList = aRenderer->GetActors2D();
4829         actor2DList->InitTraversal();
4830         vtkActor2D* aActor2d =  actor2DList->GetNextActor2D();
4831         while (aActor2d != NULL) {
4832           if (aActor2d->IsA("vtkScalarBarActor")) {
4833             aActor2d->VisibilityOff();
4834             break;
4835           }
4836           actor2DList->GetNextActor2D();
4837         }
4838       }
4839     }*/
4840   }
4841   myActiveStudy->update3dViewers();
4842 }
4843
4844
4845 //=============================================================================
4846 /*!
4847  *
4848  */
4849 //=============================================================================
4850 void SMESHGUI::UpdateScalarBar(float MinRange, float MaxRange)
4851 {
4852   vtkScalarBarActor* aScalarBar = GetScalarBar();
4853   if ( aScalarBar == NULL ) {
4854     MESSAGE("myScalarBar is NULL");
4855     return;
4856   }  
4857   DisplayScalarBar(false); 
4858   
4859   aScalarBar->GetLookupTable()->SetRange(MinRange, MaxRange);
4860   vtkRenderer *aRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
4861   vtkActorCollection* aActorList = aRenderer->GetActors();
4862   aActorList->InitTraversal();
4863   vtkActor *aActor = aActorList->GetNextActor();
4864   while(aActor != NULL) {
4865     if (aActor->IsA("SMESH_Actor")) {
4866       SMESH_Actor* aMeshActor = SMESH_Actor::SafeDownCast(aActor); 
4867       vtkDataSetMapper* aMeshMapper = (vtkDataSetMapper*) (aMeshActor->getMapper());
4868       if ((aMeshMapper != NULL)) {
4869         aMeshMapper->SetScalarRange( MinRange, MaxRange );
4870         aMeshMapper->ScalarVisibilityOn();
4871       }
4872     }
4873     aActor = aActorList->GetNextActor();
4874   }
4875   DisplayScalarBar(true); 
4876 }
4877
4878
4879 //=============================================================================
4880 /*!
4881  *
4882  */
4883 //=============================================================================
4884 void SMESHGUI::SetDisplaySettings() 
4885 {
4886   EmitSignalDeactivateDialog() ;
4887   SMESHGUI_Preferences_ColorDlg *aDlg = new SMESHGUI_Preferences_ColorDlg( QAD_Application::getDesktop(), "") ;
4888   
4889   QString SCr = QAD_CONFIG->getSetting("SMESH:SettingsFillColorRed");
4890   QString SCg = QAD_CONFIG->getSetting("SMESH:SettingsFillColorGreen");
4891   QString SCb = QAD_CONFIG->getSetting("SMESH:SettingsFillColorBlue");
4892   QColor color = QColor (SCr.toInt(), SCg.toInt(), SCb.toInt());
4893   aDlg->SetColor(1,color);
4894
4895   SCr = QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorRed");
4896   SCg = QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorGreen");
4897   SCb = QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorBlue");
4898   color = QColor (SCr.toInt(), SCg.toInt(), SCb.toInt());
4899   aDlg->SetColor(2,color);
4900
4901   SCr = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorRed");
4902   SCg = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorGreen");
4903   SCb = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorBlue");
4904   color = QColor (SCr.toInt(), SCg.toInt(), SCb.toInt());
4905   aDlg->SetColor(3,color);
4906
4907   QString SBr = QAD_CONFIG->getSetting("SMESH:SettingsBackFaceColorRed");
4908   QString SBg = QAD_CONFIG->getSetting("SMESH:SettingsBackFaceColorGreen");
4909   QString SBb = QAD_CONFIG->getSetting("SMESH:SettingsBackFaceColorBlue");
4910   color = QColor (SBr.toInt(), SBg.toInt(), SBb.toInt());
4911   aDlg->SetColor(4,color);
4912
4913   QString intValue = QAD_CONFIG->getSetting("SMESH:SettingsWidth");
4914   aDlg->SetIntValue(1,intValue.toInt());
4915   intValue = QAD_CONFIG->getSetting("SMESH:SettingsNodesSize");
4916   aDlg->SetIntValue(2,intValue.toInt());
4917   intValue = QAD_CONFIG->getSetting("SMESH:SettingsShrinkCoeff");
4918   aDlg->SetIntValue(3,intValue.toInt());
4919   
4920   if ( aDlg->exec() ) {
4921     QColor colorFill = aDlg->GetColor( 1 );
4922     QAD_CONFIG->addSetting("SMESH:SettingsFillColorRed",   colorFill.red());
4923     QAD_CONFIG->addSetting("SMESH:SettingsFillColorGreen", colorFill.green());
4924     QAD_CONFIG->addSetting("SMESH:SettingsFillColorBlue",  colorFill.blue());
4925     
4926     QColor colorOutline = aDlg->GetColor( 2 );
4927     QAD_CONFIG->addSetting("SMESH:SettingsOutlineColorRed",   colorOutline.red());
4928     QAD_CONFIG->addSetting("SMESH:SettingsOutlineColorGreen", colorOutline.green());
4929     QAD_CONFIG->addSetting("SMESH:SettingsOutlineColorBlue",  colorOutline.blue());
4930     
4931     QColor colorNode = aDlg->GetColor( 3 );
4932     QAD_CONFIG->addSetting("SMESH:SettingsNodeColorRed",   colorNode.red());
4933     QAD_CONFIG->addSetting("SMESH:SettingsNodeColorGreen", colorNode.green());
4934     QAD_CONFIG->addSetting("SMESH:SettingsNodeColorBlue",  colorNode.blue());
4935     
4936     QColor colorBackFace = aDlg->GetColor( 4 );
4937     QAD_CONFIG->addSetting("SMESH:SettingsBackFaceColorRed",   colorBackFace.red());
4938     QAD_CONFIG->addSetting("SMESH:SettingsBackFaceColorGreen", colorBackFace.green());
4939     QAD_CONFIG->addSetting("SMESH:SettingsBackFaceColorBlue",  colorBackFace.blue());
4940
4941     int width = aDlg->GetIntValue( 1 );
4942     QAD_CONFIG->addSetting("SMESH:SettingsWidth", width);
4943
4944     int nodes_size = aDlg->GetIntValue( 2 );
4945     QAD_CONFIG->addSetting("SMESH:SettingsNodesSize", nodes_size);
4946
4947     int shrink_coeff = aDlg->GetIntValue( 3 );
4948     QAD_CONFIG->addSetting("SMESH:SettingsShrinkCoeff", shrink_coeff);
4949   }
4950
4951   delete aDlg;
4952 }
4953
4954 //=======================================================================
4955 // function : Parameter()
4956 // purpose  : return a parameter (double) from a dialog box
4957 //
4958 //  aValue     : is a double used as a default value displayed
4959 //  aLabel     : is the title for aValue1
4960 //  aTitle     : is the main title
4961 //  bottom     : maximum value to be entered
4962 //  top        : minimum value to be entered
4963 //  decimals   : number of decimals
4964 //=======================================================================
4965 double SMESHGUI::Parameter( Standard_Boolean& res,
4966                             const double      aValue,
4967                             const char*       aLabel,
4968                             const char*       aTitle,
4969                             const double      bottom,
4970                             const double      top,
4971                             const int         decimals )
4972 {
4973   SMESHGUI_aParameterDlg* Dialog =
4974     new SMESHGUI_aParameterDlg( QAD_Application::getDesktop(),
4975                                 aTitle,
4976                                 aLabel,
4977                                 bottom, top, decimals,
4978                                 TRUE );
4979   Dialog->setValue( aValue );
4980   double X = 0.0;
4981   res = ( Dialog->exec() == QDialog::Accepted );
4982   if ( res )
4983     X = Dialog->getDblValue();
4984   return X;
4985 }
4986
4987 //=======================================================================
4988 // function : Parameter()
4989 // purpose  : return a parameter (int) from a dialog box
4990 //
4991 //  aValue     : is a int used as a default value displayed
4992 //  aLabel     : is the title for aValue1
4993 //  aTitle     : is the main title
4994 //  bottom     : maximum value to be entered
4995 //  top        : minimum value to be entered
4996 //=======================================================================
4997 int SMESHGUI::Parameter( Standard_Boolean& res,
4998                          const int         aValue,
4999                          const char*       aLabel,
5000                          const char*       aTitle,
5001                          const int         bottom,
5002                          const int         top )
5003 {
5004   SMESHGUI_aParameterDlg* Dialog =
5005     new SMESHGUI_aParameterDlg( QAD_Application::getDesktop(),
5006                                 aTitle,
5007                                 aLabel,
5008                                 bottom, top,
5009                                 TRUE );
5010   Dialog->setValue( aValue );
5011   int X = 0;
5012   res = ( Dialog->exec() == QDialog::Accepted );
5013   if ( res )
5014     X = Dialog->getIntValue();
5015   return X;
5016 }
5017
5018 //=============================================================================
5019 /*!
5020  *
5021  */
5022 //=============================================================================
5023 void SMESHGUI::DisplayEdges(SMESH_Actor* ac, bool visibility)
5024 {
5025   if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK) 
5026     return;
5027   if (ac->DataSource == NULL || ac->GetMapper() == NULL)
5028     return;
5029
5030   vtkGeometryFilter *gf = vtkGeometryFilter::New();
5031   gf->SetInput(ac->DataSource);
5032   vtkFeatureEdges *edges = vtkFeatureEdges::New();
5033   edges->SetInput(gf->GetOutput());
5034   edges->BoundaryEdgesOn();
5035   edges->ManifoldEdgesOn();
5036
5037   vtkPolyDataMapper *edgeMapper = vtkPolyDataMapper::New();
5038   edgeMapper->SetInput(edges->GetOutput());
5039   edgeMapper->ScalarVisibilityOff();
5040   
5041   vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5042   vtkActorCollection* actorList=theRenderer->GetActors();
5043
5044   int test=actorList->IsItemPresent(ac->EdgeDevice);
5045   if (test==0) { 
5046     vtkProperty* prop = vtkProperty::New();
5047     prop->SetColor( QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorRed").toFloat()/255., 
5048                     QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorGreen").toFloat()/255.,
5049                     QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorBlue").toFloat()/255. ) ;
5050     prop->SetPointSize(QAD_CONFIG->getSetting("SMESH:SettingsNodesSize").toInt());
5051     prop->SetLineWidth( QAD_CONFIG->getSetting("SMESH:SettingsWidth").toInt() );
5052     ac->EdgeDevice->SetProperty(prop);
5053     ac->SetEdgeColor( QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorRed").toFloat()/255., 
5054                       QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorGreen").toFloat()/255.,
5055                       QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorBlue").toFloat()/255. );
5056     ac->EdgeDevice->SetMapper(edgeMapper);
5057     
5058     theRenderer->AddActor(ac->EdgeDevice);
5059   } else {
5060     ac->EdgeDevice->SetMapper(edgeMapper);
5061     edgeMapper->Update();
5062   }
5063   
5064   vtkShrinkFilter *shrink = vtkShrinkFilter::New();
5065   shrink->SetInput(ac->DataSource);
5066   shrink->SetShrinkFactor(ac->GetShrinkFactor());
5067   vtkGeometryFilter *Shrinkgf = vtkGeometryFilter::New();
5068   Shrinkgf->SetInput( shrink->GetOutput() );
5069   vtkFeatureEdges *ShrinkEdges = vtkFeatureEdges::New();
5070   ShrinkEdges->SetInput(Shrinkgf->GetOutput());
5071   ShrinkEdges->BoundaryEdgesOn();
5072   ShrinkEdges->ManifoldEdgesOn();
5073
5074   vtkPolyDataMapper *ShrinkEdgeMapper = vtkPolyDataMapper::New();
5075   ShrinkEdgeMapper->SetInput(ShrinkEdges->GetOutput());
5076   ShrinkEdgeMapper->ScalarVisibilityOff();
5077
5078   test=actorList->IsItemPresent(ac->EdgeShrinkDevice);
5079   if (test==0) { 
5080     vtkProperty* prop = vtkProperty::New();
5081     prop->SetColor( QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorRed").toFloat()/255., 
5082                     QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorGreen").toFloat()/255.,
5083                     QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorBlue").toFloat()/255. ) ;
5084     prop->SetPointSize(QAD_CONFIG->getSetting("SMESH:SettingsNodesSize").toInt());
5085     prop->SetLineWidth( QAD_CONFIG->getSetting("SMESH:SettingsWidth").toInt() );
5086     ac->EdgeShrinkDevice->SetProperty(prop);
5087     ac->SetEdgeColor( QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorRed").toFloat()/255., 
5088                       QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorGreen").toFloat()/255.,
5089                       QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorBlue").toFloat()/255. );
5090     ac->EdgeShrinkDevice->SetMapper(ShrinkEdgeMapper);
5091     
5092     theRenderer->AddActor(ac->EdgeShrinkDevice);
5093   } else {
5094     ac->EdgeShrinkDevice->SetMapper(ShrinkEdgeMapper);
5095     ShrinkEdgeMapper->Update();
5096   }
5097
5098   vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
5099   renWin->Render();
5100 }
5101
5102
5103 //=============================================================================
5104 /*!
5105  *
5106  */
5107 //=============================================================================
5108 void SMESHGUI::InitActor(SMESH::SMESH_Mesh_ptr aMesh)
5109 {
5110   SALOMEDS::SObject_var aSO_M = myStudyAPI.FindMesh( aMesh );
5111   SALOMEDS::GenericAttribute_var anAttr;
5112   SALOMEDS::AttributeName_var    aName;
5113   if ( !aSO_M->_is_nil() ) {
5114     if (aSO_M->FindAttribute(anAttr, "AttributeName") ) {
5115       aName = SALOMEDS::AttributeName::_narrow(anAttr);
5116       Standard_Boolean result;
5117       SMESH_Actor* MeshActor = smeshGUI->FindActorByEntry(aSO_M->GetID(), result, true);
5118       if ( !result ) {
5119         SMESH_Actor* amesh = SMESH_Actor::New();
5120         Handle(SALOME_InteractiveObject) IO = new SALOME_InteractiveObject(aSO_M->GetID(),
5121                                                                            "MESH",
5122                                                                            aName->Value());
5123         amesh->setIO( IO );
5124         amesh->setName( aName->Value() );
5125         DisplayActor(amesh, false);
5126       }
5127     }
5128   }
5129 }
5130
5131
5132 //=============================================================================
5133 /*!
5134  *
5135  */
5136 //=============================================================================
5137 void SMESHGUI::Update()
5138 {
5139   if ( myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
5140     vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5141     
5142     SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
5143     int nbSel = Sel->IObjectCount();
5144     if ( nbSel == 0 ) {
5145       vtkActorCollection* actorList=theRenderer->GetActors();
5146       actorList->InitTraversal();
5147       vtkActor *ac = actorList->GetNextActor();
5148       while(!(ac==NULL)) {
5149         if ( ac->IsA("SMESH_Actor") ) {
5150           SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( ac );
5151           if ( anActor->hasIO() ) {
5152             Handle(SALOME_InteractiveObject) IO = anActor->getIO();
5153             Update( IO );
5154           }
5155         }
5156         ac = actorList->GetNextActor();
5157       }
5158     } else {
5159       SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
5160       for ( ; It.More(); It.Next() ) {
5161         Handle(SALOME_InteractiveObject) IO = It.Value();
5162         Update( IO );
5163       }
5164     }
5165     vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
5166     renWin->Render();
5167   }
5168   QApplication::restoreOverrideCursor();
5169 }
5170
5171
5172 //=============================================================================
5173 /*!
5174  *
5175  */
5176 //=============================================================================
5177 void SMESHGUI::Update(const Handle(SALOME_InteractiveObject)& IO)
5178 {
5179   if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK) 
5180     return;
5181
5182   if ( IO->hasEntry() ) {
5183     Standard_Boolean res;
5184     SMESH::SMESH_Mesh_var aMesh = ConvertIOinMesh( IO, res );
5185     if ( res ) {
5186       SMESH_Actor* ac = FindActorByEntry( IO->getEntry(), res, false );
5187       if ( res ) {
5188         // Check whether the actor belongs to the active view
5189         VTKViewer_RenderWindowInteractor* rwInter = 
5190           ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor();
5191
5192         // The actor belongs to inactive view -> create a copy and display it in the active view
5193         if (!rwInter->isInViewer(IO)) {
5194           SMESH_Actor* acCopy = SMESH_Actor::New();
5195           acCopy->ShallowCopy(ac);
5196
5197           smeshGUI->DisplayActor( acCopy, false );
5198         }
5199         ac = ReadScript( aMesh );
5200         if ( ac != NULL ) {
5201 #ifdef TRACE
5202           Dump( ac );
5203 #endif
5204           DisplayActor( ac );
5205           DisplayEdges( ac );
5206           smeshGUI->ChangeRepresentation( ac, ac->getDisplayMode() );
5207         }
5208       }
5209     }
5210   }
5211 }
5212
5213
5214 //=============================================================================
5215 /*!
5216  *
5217  */
5218 //=============================================================================
5219 vtkActor* SMESHGUI::SimulationMoveNode(SMESH_Actor* Mactor, int idnode)
5220 {
5221   if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK) 
5222     return NULL;
5223
5224   mySimulationActors = vtkActorCollection::New();
5225   vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5226
5227   vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
5228   vtkIdList *IdCells =  vtkIdList::New();
5229   ugrid->GetPointCells( idnode, IdCells );
5230
5231   vtkPoints *Pts = vtkPoints::New();
5232   Pts = ugrid->GetPoints();
5233
5234   vtkUnstructuredGrid *ugridSimulation = vtkUnstructuredGrid::New();
5235   ugridSimulation->SetPoints( Pts );
5236   vtkIdList *IdPts =  vtkIdList::New();
5237   for (int j=0; j<IdCells->GetNumberOfIds(); j++) {
5238     ugrid->GetCellPoints( IdCells->GetId(j), IdPts );
5239     ugridSimulation->InsertNextCell( ugrid->GetCellType( IdCells->GetId(j) ), IdPts );
5240   }
5241
5242   vtkProperty* prop = vtkProperty::New();
5243   prop->SetColor( 1., 0., 0. );
5244   prop->SetRepresentationToWireframe();
5245   
5246   int Edgewidth = (int)Mactor->EdgeDevice->GetProperty()->GetLineWidth();
5247   if ( Edgewidth == 0 )
5248     Edgewidth = 1;
5249   prop->SetLineWidth( Edgewidth+1 );
5250
5251   vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
5252   Mapper->SetInput( ugridSimulation );
5253   vtkActor* ac = vtkActor::New();
5254   ac->SetMapper( Mapper );
5255   ac->SetProperty( prop );
5256
5257   ac->GetMapper()->SetResolveCoincidentTopologyToShiftZBuffer();
5258   ac->GetMapper()->SetResolveCoincidentTopologyZShift(0.02);
5259
5260   mySimulationActors->AddItem( ac );
5261   theRenderer->AddActor( ac );
5262   
5263   vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
5264   renWin->Render();
5265
5266   return ac;
5267 }
5268
5269
5270 //=============================================================================
5271 /*!
5272  *
5273  */
5274 //=============================================================================
5275 void SMESHGUI::DisplaySimulationNode( SMESH::SMESH_Mesh_ptr aMesh, float x, float y, float z)
5276 {
5277   if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK) 
5278     return;
5279
5280   EraseSimulationActors();
5281   mySimulationActors = vtkActorCollection::New();
5282   vtkRenderer* theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5283   Standard_Boolean result;
5284   SMESH_Actor* ac = FindActor( aMesh, result, true );
5285
5286   if ( result ) {
5287     vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( ac->DataSource );
5288     vtkUnstructuredGrid* newugrid = vtkUnstructuredGrid::New();
5289
5290     vtkPoints *Pts = ugrid->GetPoints();
5291     vtkPoints *newPts = vtkPoints::New();
5292     int nbPts = Pts->GetNumberOfPoints();
5293     for ( int i = 0; i < nbPts; i++ ) {
5294       newPts->InsertPoint(i, Pts->GetPoint(i) );
5295     }
5296
5297     newugrid->SetPoints(newPts);
5298     newugrid->GetPoints()->InsertNextPoint( x, y, z );
5299     
5300     vtkMaskPoints* verts = vtkMaskPoints::New();
5301     verts->SetInput(newugrid);
5302     verts->SetGenerateVertices(1);
5303     verts->SetOnRatio(1);
5304    
5305     vtkPolyDataMapper* vertMapper = vtkPolyDataMapper::New();
5306     vertMapper->SetInput( verts->GetOutput() );
5307     vertMapper->ScalarVisibilityOff();
5308
5309     vtkActor* node = vtkActor::New();
5310     node->SetMapper( vertMapper );
5311
5312     QString SCr = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorRed");
5313     QString SCg = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorGreen");
5314     QString SCb = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorBlue");
5315     QColor nodecolor(SCr.toInt(), SCg.toInt(), SCb.toInt());
5316     if ( !nodecolor.isValid() )
5317       nodecolor = QColor(0.,1.,0.);
5318
5319     node->GetProperty()->SetColor( float(nodecolor.red())/255.,
5320                                    float(nodecolor.green())/255.,
5321                                    float(nodecolor.blue())/255.);
5322
5323     int intValue = QAD_CONFIG->getSetting("SMESH:SettingsNodesSize").toInt();
5324     if ( intValue < 1 )
5325       intValue == 1;
5326     
5327     node->GetProperty()->SetPointSize( intValue );
5328
5329     node->VisibilityOn();
5330
5331     mySimulationActors->AddItem( node );
5332     theRenderer->AddActor(node);
5333   }
5334
5335   vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
5336   renWin->Render(); 
5337 }
5338
5339 //=============================================================================
5340 /*!
5341  *
5342  */
5343 //=============================================================================
5344 void SMESHGUI::DisplaySimulationMoveNode( vtkActor* ac, int idnode, float x, float y, float z)
5345 {
5346   if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK) 
5347     return;
5348
5349   vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5350   float *pt  = ac->GetMapper()->GetInput()->GetPoint(idnode);
5351   pt[0] = x; pt[1] = y; pt[2] = z;
5352
5353   ac->GetMapper()->ImmediateModeRenderingOn();
5354   ac->GetProperty()->SetRepresentationToWireframe();
5355
5356   vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
5357
5358   renWin->Render(); 
5359 }
5360
5361
5362 //=============================================================================
5363 /*!
5364  *
5365  */
5366 //=============================================================================
5367 void SMESHGUI::MoveNode( SMESH::SMESH_Mesh_ptr aMesh, int idnode, float x, float y, float z)
5368 {
5369   Standard_Boolean result;
5370
5371   SMESH_Actor* MeshActor = FindActor(aMesh, result, true);
5372   if ( result ) {
5373   }
5374 }
5375
5376
5377 //=============================================================================
5378 /*!
5379  *
5380  */
5381 //=============================================================================
5382 void SMESHGUI::ScalarVisibilityOff()
5383 {
5384   if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK) 
5385     return;
5386
5387   vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5388   vtkActorCollection* actorList=theRenderer->GetActors();
5389
5390   actorList->InitTraversal();
5391   vtkActor *ac = actorList->GetNextActor();
5392   while(!(ac==NULL)) {
5393     if ( ac->IsA("SMESH_Actor") ) {
5394       SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( ac );
5395       if ( anActor->GetVisibility() == 1 ) {
5396         vtkDataSetMapper* meshMapper = (vtkDataSetMapper*) (anActor->getMapper());
5397         meshMapper->ScalarVisibilityOff();
5398         meshMapper->SetInput( anActor->DataSource );
5399         ChangeRepresentation( anActor, anActor->getDisplayMode() );
5400       }
5401     }
5402     ac = actorList->GetNextActor();
5403   }
5404
5405   theRenderer->Render();
5406 }
5407
5408
5409 //=============================================================================
5410 /*!
5411  *
5412  */
5413 //=============================================================================
5414 void SMESHGUI::DisplaySimulationEdge( SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex )
5415 {
5416   if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK) 
5417     return;
5418
5419   EraseSimulationActors();
5420   mySimulationActors = vtkActorCollection::New();
5421   vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5422   Standard_Boolean result;
5423   SMESH_Actor* ac = FindActor( aMesh, result, true );
5424   if ( result ) {
5425     TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
5426     int idNodes[2];
5427     int pts[2];
5428     int i = 0;
5429     vtkIdList *Ids = vtkIdList::New();
5430     for ( ; ite.More(); ite.Next() ) {
5431       idNodes[i] = ite.Key();
5432       i++;
5433     }
5434     
5435     Ids->InsertId( 0, idNodes[0] );
5436     pts[0] = idNodes[0];
5437     Ids->InsertId( 1, idNodes[1] );
5438     pts[1] = idNodes[1];
5439
5440     vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( ac->DataSource );
5441     vtkUnstructuredGrid* newugrid = vtkUnstructuredGrid::New();
5442     newugrid->SetPoints( ugrid->GetPoints() ) ;
5443     newugrid->InsertNextCell(VTK_LINE, 2, pts);
5444
5445     vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
5446     Mapper->SetInput( newugrid );
5447     Mapper->Update();
5448
5449     vtkActor* edge = vtkActor::New();
5450     edge->SetMapper( Mapper );
5451     edge->SetProperty( ac->GetProperty() );
5452     edge->SetBackfaceProperty( ac->GetBackfaceProperty() );
5453     edge->VisibilityOn();
5454     mySimulationActors->AddItem( edge );
5455     theRenderer->AddActor(edge);
5456   }
5457
5458   vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
5459   renWin->Render();
5460 }
5461
5462
5463 //=============================================================================
5464 /*!
5465  *
5466  */
5467 //=============================================================================
5468 void SMESHGUI::DisplaySimulationTriangle( SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex, bool reverse )
5469 {
5470   if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK) 
5471     return;
5472
5473   EraseSimulationActors();
5474   mySimulationActors = vtkActorCollection::New();
5475   vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5476   Standard_Boolean result;
5477   SMESH_Actor* ac = FindActor( aMesh, result, true );
5478   if ( result ) {
5479     TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
5480     int idNodes[3];
5481     int pts[3];
5482     int i = 0;
5483     vtkIdList *Ids = vtkIdList::New();
5484     for ( ; ite.More(); ite.Next() ) {
5485       idNodes[i] = ite.Key();
5486       i++;
5487     }
5488     
5489     if ( reverse ) {
5490       Ids->InsertId( 0, idNodes[2] );
5491       pts[0] = idNodes[2];
5492       Ids->InsertId( 1, idNodes[1] );   
5493       pts[1] = idNodes[1];
5494       Ids->InsertId( 2, idNodes[0] );
5495       pts[2] = idNodes[0];
5496     } else {
5497       Ids->InsertId( 0, idNodes[0] );
5498       pts[0] = idNodes[0];
5499       Ids->InsertId( 1, idNodes[1] );
5500       pts[1] = idNodes[1];
5501       Ids->InsertId( 2, idNodes[2] );  
5502       pts[2] = idNodes[2];     
5503     }
5504     vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( ac->DataSource );
5505     vtkUnstructuredGrid* newugrid = vtkUnstructuredGrid::New();
5506     newugrid->SetPoints( ugrid->GetPoints() ) ;
5507     newugrid->InsertNextCell(VTK_TRIANGLE, 3, pts);
5508
5509     vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
5510     Mapper->SetInput( newugrid );
5511     Mapper->Update();
5512
5513     vtkActor* tri = vtkActor::New();
5514     tri->SetMapper( Mapper );
5515     tri->SetProperty( ac->GetProperty() );
5516     tri->SetBackfaceProperty( ac->GetBackfaceProperty() );
5517     tri->VisibilityOn();
5518     mySimulationActors->AddItem( tri );
5519     theRenderer->AddActor(tri);
5520   }
5521
5522   vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
5523   renWin->Render();
5524 }
5525
5526
5527 //=============================================================================
5528 /*!
5529  *
5530  */
5531 //=============================================================================
5532 void SMESHGUI::DisplaySimulationQuadrangle( SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex, bool reverse )
5533 {
5534   if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK) 
5535     return;
5536
5537   EraseSimulationActors();
5538   mySimulationActors = vtkActorCollection::New();
5539   vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5540   Standard_Boolean result;
5541   SMESH_Actor* ac = FindActor( aMesh, result, true );
5542
5543   vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( ac->DataSource );
5544   
5545   if ( result ) {
5546     TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
5547     int i = 0;
5548     int idNodes[4];
5549     vtkIdList *Ids = vtkIdList::New();
5550     for ( ; ite.More(); ite.Next() ) {
5551       idNodes[i] = ite.Key();
5552       i++;
5553     }
5554
5555     float *p0 = ugrid->GetPoint(idNodes[0]);
5556     float *p1 = ugrid->GetPoint(idNodes[1]);
5557     float *p2 = ugrid->GetPoint(idNodes[2]);
5558     float *p3 = ugrid->GetPoint(idNodes[3]);
5559
5560     gp_Pnt P0(p0[0],p0[1],p0[2]);
5561
5562     gp_Vec V1( P0, gp_Pnt(p1[0],p1[1],p1[2]) );
5563     gp_Vec V2( P0, gp_Pnt(p2[0],p2[1],p2[2]) );
5564     gp_Vec V3( P0, gp_Pnt(p3[0],p3[1],p3[2]) );
5565
5566     gp_Vec Cross1 = V1 ^ V2;
5567     gp_Vec Cross2 = V2 ^ V3;
5568
5569     int tmp;
5570     if ( Cross1.Dot(Cross2) < 0 ) {
5571       V1 = gp_Vec(P0, gp_Pnt(p2[0],p2[1],p2[2]) );
5572       V2 = gp_Vec(P0, gp_Pnt(p1[0],p1[1],p1[2]) );
5573       Cross1 = V1 ^ V2;
5574       Cross2 = V2 ^ V3;
5575       
5576       if ( Cross1.Dot(Cross2) < 0 ) {
5577         tmp = idNodes[2];
5578         idNodes[2] = idNodes[3];
5579         idNodes[3] = tmp;         
5580       } else {
5581         tmp = idNodes[1];
5582         idNodes[1] = idNodes[2];
5583         idNodes[2] = tmp;
5584       }
5585     }
5586
5587     if ( reverse ) {
5588       Ids->InsertId( 0, idNodes[3] );
5589       Ids->InsertId( 1, idNodes[2] );   
5590       Ids->InsertId( 2, idNodes[1] );
5591       Ids->InsertId( 3, idNodes[0] );
5592     } else {
5593       Ids->InsertId( 0, idNodes[0] );
5594       Ids->InsertId( 1, idNodes[1] );
5595       Ids->InsertId( 2, idNodes[2] );  
5596       Ids->InsertId( 3, idNodes[3] );  
5597     }
5598
5599     //    vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( ac->DataSource );
5600     vtkUnstructuredGrid* newugrid = vtkUnstructuredGrid::New();
5601     newugrid->SetPoints( ugrid->GetPoints() ) ;
5602     newugrid->InsertNextCell(VTK_QUAD, Ids);
5603
5604     vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
5605     Mapper->SetInput( newugrid );
5606     Mapper->Update();
5607
5608     vtkActor* quad = vtkActor::New();
5609     quad->SetMapper( Mapper );
5610     quad->SetProperty( ac->GetProperty() );
5611     quad->SetBackfaceProperty( ac->GetBackfaceProperty() );
5612     quad->VisibilityOn();
5613     mySimulationActors->AddItem( quad );
5614     theRenderer->AddActor(quad);
5615   }
5616   vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
5617   renWin->Render();
5618 }
5619
5620
5621 //=============================================================================
5622 /*!
5623  *
5624  */
5625 //=============================================================================
5626 void SMESHGUI::DisplaySimulationTetra( SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex )
5627 {
5628   if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK) 
5629     return;
5630
5631   EraseSimulationActors();
5632   mySimulationActors = vtkActorCollection::New();
5633   vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5634   Standard_Boolean result;
5635   SMESH_Actor* ac = FindActor( aMesh, result, true );
5636   if ( result ) {
5637     TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
5638     int i = 0;
5639     int idNodes[4];
5640     vtkIdList *Ids = vtkIdList::New();
5641     for ( ; ite.More(); ite.Next() ) {
5642       idNodes[i] = ite.Key();
5643       i++;
5644     }
5645     
5646     Ids->InsertId( 0, idNodes[0] );
5647     Ids->InsertId( 1, idNodes[1] );
5648     Ids->InsertId( 2, idNodes[2] );  
5649     Ids->InsertId( 3, idNodes[3] );  
5650
5651     vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( ac->DataSource );
5652     vtkUnstructuredGrid* newugrid = vtkUnstructuredGrid::New();
5653     newugrid->SetPoints( ugrid->GetPoints() ) ;
5654     newugrid->InsertNextCell(VTK_TETRA, Ids);
5655
5656     vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
5657     Mapper->SetInput( newugrid );
5658     Mapper->Update();
5659
5660     vtkActor* tetra = vtkActor::New();
5661     tetra->SetMapper( Mapper );
5662     tetra->SetProperty( ac->GetProperty() );
5663     tetra->SetBackfaceProperty( ac->GetBackfaceProperty() );
5664     tetra->VisibilityOn();
5665     mySimulationActors->AddItem( tetra );
5666     theRenderer->AddActor(tetra);
5667   }
5668   vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
5669   renWin->Render();
5670 }
5671
5672
5673 //=============================================================================
5674 /*!
5675  *
5676  */
5677 //=============================================================================
5678 void SMESHGUI::DisplaySimulationHexa( SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex )
5679 {
5680   if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK) 
5681     return;
5682
5683   EraseSimulationActors();
5684   mySimulationActors = vtkActorCollection::New();
5685   vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5686   Standard_Boolean result;
5687   SMESH_Actor* ac = FindActor( aMesh, result, true );
5688   if ( result ) {
5689     TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
5690     int i = 0;
5691     int idNodes[8];
5692     vtkIdList *Ids = vtkIdList::New();
5693     for ( ; ite.More(); ite.Next() ) {
5694       idNodes[i] = ite.Key();
5695       i++;
5696     }
5697     
5698     Ids->InsertId( 0, idNodes[0] );
5699     Ids->InsertId( 1, idNodes[1] );
5700     Ids->InsertId( 2, idNodes[2] );  
5701     Ids->InsertId( 3, idNodes[3] );  
5702     Ids->InsertId( 4, idNodes[4] );
5703     Ids->InsertId( 5, idNodes[5] );
5704     Ids->InsertId( 6, idNodes[6] );  
5705     Ids->InsertId( 7, idNodes[7] );  
5706
5707     vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( ac->DataSource );
5708     vtkUnstructuredGrid* newugrid = vtkUnstructuredGrid::New();
5709     newugrid->SetPoints( ugrid->GetPoints() ) ;
5710     newugrid->InsertNextCell(VTK_HEXAHEDRON, Ids);
5711
5712     vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
5713     Mapper->SetInput( newugrid );
5714     Mapper->Update();
5715
5716     vtkActor* hexa = vtkActor::New();
5717     hexa->SetMapper( Mapper );
5718     hexa->SetProperty( ac->GetProperty() );
5719     hexa->SetBackfaceProperty( ac->GetBackfaceProperty() );
5720     hexa->VisibilityOn();
5721     mySimulationActors->AddItem( hexa );
5722     theRenderer->AddActor(hexa);
5723   }
5724   vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
5725   renWin->Render();
5726 }
5727
5728
5729 //=============================================================================
5730 /*!
5731  *
5732  */
5733 //=============================================================================
5734 void SMESHGUI::AddFace( SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex, bool reverse )
5735 {  
5736   QApplication::setOverrideCursor( Qt::waitCursor );
5737   Standard_Boolean result;
5738   SMESH_Actor* ac = FindActor( aMesh, result, true );
5739   if ( result ) {
5740     TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
5741     SMESH::long_array_var anArrayOfIdeces = new  SMESH::long_array;
5742     anArrayOfIdeces->length(MapIndex.Extent());
5743     
5744     int i = 0;
5745     for ( ; ite.More(); ite.Next() ) {
5746       anArrayOfIdeces[i] = ac->GetIdSMESHDSNode(ite.Key());
5747       i++;
5748     }
5749
5750     int tmp;
5751     if ( MapIndex.Extent() == 4 ) {
5752       int idNodes[4];
5753       int i = 0;
5754       TColStd_MapIteratorOfMapOfInteger ite1( MapIndex );
5755       for ( ; ite1.More(); ite1.Next() ) {
5756         idNodes[i] = ite1.Key();
5757         i++;
5758       }
5759       
5760       vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( ac->DataSource );
5761       float *p0 = ugrid->GetPoint(idNodes[0]);
5762       float *p1 = ugrid->GetPoint(idNodes[1]);
5763       float *p2 = ugrid->GetPoint(idNodes[2]);
5764       float *p3 = ugrid->GetPoint(idNodes[3]);
5765
5766       gp_Pnt P0(p0[0],p0[1],p0[2]);
5767
5768       gp_Vec V1( P0, gp_Pnt(p1[0],p1[1],p1[2]) );
5769       gp_Vec V2( P0, gp_Pnt(p2[0],p2[1],p2[2]) );
5770       gp_Vec V3( P0, gp_Pnt(p3[0],p3[1],p3[2]) );
5771
5772       gp_Vec Cross1 = V1 ^ V2;
5773       gp_Vec Cross2 = V2 ^ V3;
5774
5775       if ( Cross1.Dot(Cross2) < 0 ) {
5776
5777         V1 = gp_Vec(P0, gp_Pnt(p2[0],p2[1],p2[2]) );
5778         V2 = gp_Vec(P0, gp_Pnt(p1[0],p1[1],p1[2]) );
5779         Cross1 = V1 ^ V2;
5780         Cross2 = V2 ^ V3;
5781         
5782         if ( Cross1.Dot(Cross2) < 0 ) {
5783           tmp = anArrayOfIdeces[2];
5784           anArrayOfIdeces[2] = anArrayOfIdeces[3];
5785           anArrayOfIdeces[3] = tmp;       
5786         } else {
5787           tmp = anArrayOfIdeces[1];
5788           anArrayOfIdeces[1] = anArrayOfIdeces[2];
5789           anArrayOfIdeces[2] = tmp;
5790         }
5791       }
5792     }
5793
5794     //    int tmp;
5795     if ( reverse ) {
5796       for (i=0; i < (MapIndex.Extent()/2); i++) {
5797         tmp = anArrayOfIdeces[i];
5798         anArrayOfIdeces[i] = anArrayOfIdeces[MapIndex.Extent()-i-1];
5799         anArrayOfIdeces[MapIndex.Extent()-i-1] = tmp;
5800       }
5801     }
5802     SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
5803     aMeshEditor->AddFace(anArrayOfIdeces);
5804   }
5805   if ( myAutomaticUpdate ) {
5806     SMESH_Actor* Mesh = smeshGUI->ReadScript(aMesh);
5807     if ( Mesh != NULL ) {
5808       smeshGUI->DisplayActor( Mesh );
5809       smeshGUI->DisplayEdges( Mesh );
5810       smeshGUI->ChangeRepresentation( Mesh, Mesh->getDisplayMode() );
5811       AddActorInSelection( Mesh );
5812     }
5813   }
5814   QApplication::restoreOverrideCursor();
5815 }
5816
5817
5818 //=============================================================================
5819 /*!
5820  *
5821  */
5822 //=============================================================================
5823 void SMESHGUI::AddVolume( SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex )
5824 {  
5825   QApplication::setOverrideCursor( Qt::waitCursor );
5826   Standard_Boolean result;
5827   SMESH_Actor* ac = FindActor( aMesh, result, true );
5828   if ( result ) {
5829     TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
5830     SMESH::long_array_var anArrayOfIdeces = new  SMESH::long_array;
5831     anArrayOfIdeces->length(MapIndex.Extent());
5832     
5833     int i = 0;
5834     for ( ; ite.More(); ite.Next() ) {
5835       anArrayOfIdeces[i] = ac->GetIdSMESHDSNode(ite.Key());
5836       i++;
5837     }
5838
5839     SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
5840     aMeshEditor->AddVolume(anArrayOfIdeces);
5841   }
5842   if ( myAutomaticUpdate ) {
5843     SMESH_Actor* Mesh = smeshGUI->ReadScript(aMesh);
5844     if ( Mesh != NULL ) {
5845       smeshGUI->DisplayActor( Mesh );
5846       smeshGUI->DisplayEdges( Mesh );
5847       smeshGUI->ChangeRepresentation( Mesh, Mesh->getDisplayMode() );
5848       AddActorInSelection( Mesh );
5849     }
5850   }
5851   QApplication::restoreOverrideCursor();
5852 }
5853
5854
5855 //=============================================================================
5856 /*!
5857  *
5858  */
5859 //=============================================================================
5860 void SMESHGUI::AddEdge( SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex )
5861 {  
5862   QApplication::setOverrideCursor( Qt::waitCursor );
5863   Standard_Boolean result;
5864   SMESH_Actor* ac = FindActor( aMesh, result, true );
5865   if ( result ) {
5866     TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
5867     SMESH::long_array_var anArrayOfIdeces = new  SMESH::long_array;
5868     anArrayOfIdeces->length(MapIndex.Extent());
5869     
5870     int i = 0;
5871     for ( ; ite.More(); ite.Next() ) {
5872       anArrayOfIdeces[i] = ac->GetIdSMESHDSNode(ite.Key());
5873       i++;
5874     }
5875
5876     SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
5877     aMeshEditor->AddEdge(anArrayOfIdeces);
5878   }
5879   if ( myAutomaticUpdate ) {
5880     SMESH_Actor* Mesh = smeshGUI->ReadScript(aMesh);
5881     if ( Mesh != NULL ) {
5882       smeshGUI->DisplayActor( Mesh );
5883       smeshGUI->DisplayEdges( Mesh );
5884       smeshGUI->ChangeRepresentation( Mesh, Mesh->getDisplayMode() );
5885       AddActorInSelection( Mesh );
5886     }
5887   }
5888   QApplication::restoreOverrideCursor();
5889 }
5890
5891 //=============================================================================
5892 /*!
5893  *
5894  */
5895 //=============================================================================
5896 void SMESHGUI::AddNode( SMESH::SMESH_Mesh_ptr aMesh, float x, float y, float z)
5897 {  
5898   QApplication::setOverrideCursor( Qt::waitCursor );
5899   Standard_Boolean result;
5900   SMESH_Actor* ac = FindActor( aMesh, result, true );
5901   if ( result ) {
5902     SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
5903     aMeshEditor->AddNode(x,y,z);
5904   
5905     if ( myAutomaticUpdate ) {
5906       SMESH_Actor* Mesh = smeshGUI->ReadScript(aMesh);
5907       if ( Mesh != NULL ) {
5908         smeshGUI->DisplayActor( Mesh );
5909         smeshGUI->DisplayEdges( Mesh );
5910         smeshGUI->ChangeRepresentation( Mesh, Mesh->getDisplayMode() );
5911         AddActorInSelection( Mesh );
5912       }
5913     }
5914   }
5915   QApplication::restoreOverrideCursor();
5916 }
5917
5918 //=============================================================================
5919 /*!
5920  *
5921  */
5922 //=============================================================================
5923 void SMESHGUI::DisplayEdgesConnectivityLegendBox(vtkActor *ac)
5924 {
5925   if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK) 
5926     return;
5927
5928   EraseSimulationActors();
5929   mySimulationActors2D = vtkActor2DCollection::New();
5930
5931   vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5932
5933   vtkGlyphSource2D *gs2 = vtkGlyphSource2D::New();
5934   gs2->SetGlyphTypeToTriangle();
5935   gs2->FilledOff();
5936
5937   vtkLegendBoxActor *legend = vtkLegendBoxActor::New();
5938   legend->GetPositionCoordinate()->SetValue(0.025, 0.025, 0.);
5939   legend->GetPosition2Coordinate()->SetValue(0.3, 0.3, 0.); //relative to Position
5940
5941   legend->SetNumberOfEntries(4);
5942   legend->SetEntryString( 0, tr( "SMESH_BOUNDARYEDGES" ) );
5943   legend->SetEntrySymbol( 0, gs2->GetOutput() );
5944   legend->SetEntryColor(0, ac->GetMapper()->GetLookupTable()->GetColor(0.) );
5945   legend->SetEntryString( 1,  tr( "SMESH_MANIFOLDEDGES" ) );
5946   legend->SetEntrySymbol( 1, gs2->GetOutput() );
5947   legend->SetEntryColor(1, ac->GetMapper()->GetLookupTable()->GetColor(0.666667) );
5948   legend->SetEntryString( 2, tr( "SMESH_NONMANIFOLDEDGES" ) );
5949   legend->SetEntrySymbol( 2, gs2->GetOutput() );
5950   legend->SetEntryColor(2, ac->GetMapper()->GetLookupTable()->GetColor(0.222222) );
5951   legend->SetEntryString( 3, tr( "SMESH_FEATUREEDGES" ) );
5952   legend->SetEntrySymbol( 3, gs2->GetOutput() );
5953   legend->SetEntryColor(3, ac->GetMapper()->GetLookupTable()->GetColor(0.444444) );
5954   legend->SetPadding( 5 );
5955   //  legend->GetProperty()->SetColor();
5956
5957   mySimulationActors2D->AddItem( legend );
5958   theRenderer->AddActor2D( legend );
5959
5960   // Update the view
5961   myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame()->Repaint();
5962 }
5963
5964 //===============================================================================
5965 // function : OnEditDelete()
5966 // purpose  :
5967 //===============================================================================
5968 void SMESHGUI::OnEditDelete()
5969 {
5970   if ( QAD_MessageBox::warn2
5971        ( QAD_Application::getDesktop(),
5972          tr ("SMESH_WRN_WARNING"),
5973          tr ("SMESH_REALLY_DELETE"),
5974          tr ("SMESH_BUT_YES"), tr ("SMESH_BUT_NO"), 1, 0, 0 ) != 1 )
5975     return;
5976   
5977   int nbSf = myActiveStudy->getStudyFramesCount();
5978     
5979   Standard_Boolean found;
5980   SALOMEDS::Study_var aStudy = myActiveStudy->getStudyDocument();
5981   SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
5982   SALOMEDS::GenericAttribute_var anAttr;
5983   SALOMEDS::AttributeIOR_var     anIOR;
5984   
5985   SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
5986   SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
5987   for(;It.More();It.Next()) {
5988     Handle(SALOME_InteractiveObject) IObject = It.Value();
5989     if ( IObject->hasEntry() ) {
5990       SALOMEDS::SObject_var SO = myStudy->FindObjectID( IObject->getEntry() );
5991       
5992       /* Erase child graphical objects */
5993       SALOMEDS::ChildIterator_var it = aStudy->NewChildIterator(SO);
5994       for (; it->More();it->Next()) {
5995         SALOMEDS::SObject_var CSO= it->Value();
5996         if (CSO->FindAttribute(anAttr, "AttributeIOR") ) {
5997           anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
5998
5999           for ( int i = 0; i < nbSf; i++ ) {
6000             QAD_StudyFrame* sf = myActiveStudy->getStudyFrame(i);
6001             if ( sf->getTypeView() == VIEW_VTK ) {
6002               vtkRenderer* Renderer = ((VTKViewer_ViewFrame*)smeshGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
6003               SMESH_Actor* ac = smeshGUI->FindActorByEntry( CSO->GetID(), found, false );
6004               if ( found ) {
6005                 Renderer->RemoveActor(ac->EdgeDevice);
6006                 Renderer->RemoveActor(ac->EdgeShrinkDevice);
6007                 Renderer->RemoveActor(ac);
6008               }
6009             }
6010           }
6011         }
6012       }
6013       
6014       /* Erase main graphical object */
6015       for ( int i = 0; i < nbSf; i++ ) {
6016         QAD_StudyFrame* sf = myActiveStudy->getStudyFrame(i);
6017         if ( sf->getTypeView() == VIEW_VTK ) {
6018           vtkRenderer* Renderer = ((VTKViewer_ViewFrame*)smeshGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
6019           VTKViewer_RenderWindowInteractor* myRenderInter= ((VTKViewer_ViewFrame*)sf->getRightFrame()->getViewFrame())->getRWInteractor();
6020           SMESH_Actor* ac = smeshGUI->FindActorByEntry( IObject->getEntry(), found, false );
6021           if (found) {
6022             Renderer->RemoveActor(ac->EdgeDevice);
6023             Renderer->RemoveActor(ac->EdgeShrinkDevice);
6024           }
6025           myRenderInter->Remove( IObject );
6026         }
6027       }
6028       
6029       /* Erase objects in Study */
6030       SALOMEDS::SObject_var obj = myStudy->FindObjectID( IObject->getEntry() );
6031       if ( !obj->_is_nil() ) {
6032         QAD_Operation* op = new SALOMEGUI_ImportOperation( myActiveStudy );
6033         op->start();
6034         aStudyBuilder->RemoveObject(obj);
6035         op->finish();
6036       }
6037
6038     } /* IObject->hasEntry() */
6039   }   /* more/next           */
6040
6041   /* Clear any previous selection */
6042   Sel->ClearIObjects() ; 
6043   myActiveStudy->updateObjBrowser();
6044 }