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