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