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