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