Salome HOME
Item Delete in pop-up of link on hypotheses or algorithm doesn't work.
[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.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //  File   : SMESHGUI.cxx
23 //  Author : Nicolas REJNERI
24 //  Module : SMESH
25 //  $Header$
26
27 #include "SMESHGUI.h"
28
29 #include "SMESH_Client.hxx"
30 #include "SMESHGUI_NodesDlg.h"
31 #include "SMESHGUI_TransparencyDlg.h"
32 #include "SMESHGUI_ClippingDlg.h"
33 #include "SMESHGUI_GroupDlg.h"
34 #include "SMESHGUI_RemoveNodesDlg.h"
35 #include "SMESHGUI_RemoveElementsDlg.h"
36 #include "SMESHGUI_MeshInfosDlg.h"
37 #include "SMESHGUI_StandardMeshInfosDlg.h"
38 #include "SMESHGUI_WhatIsDlg.h"
39 #include "SMESHGUI_Preferences_ColorDlg.h"
40 #include "SMESHGUI_Preferences_ScalarBarDlg.h"
41 #include "SMESHGUI_Preferences_SelectionDlg.h"
42 #include "SMESHGUI_Hypotheses.h"
43 #include "SMESHGUI_MoveNodesDlg.h"
44 #include "SMESHGUI_AddMeshElementDlg.h"
45 #include "SMESHGUI_AddQuadraticElementDlg.h"
46 #include "SMESHGUI_FilterDlg.h"
47 #include "SMESHGUI_FilterLibraryDlg.h"
48 #include "SMESHGUI_SingleEditDlg.h"
49 #include "SMESHGUI_MultiEditDlg.h"
50 #include "SMESHGUI_GroupOpDlg.h"
51 #include "SMESHGUI_DeleteGroupDlg.h"
52 #include "SMESHGUI_SmoothingDlg.h"
53 #include "SMESHGUI_RenumberingDlg.h"
54 #include "SMESHGUI_ExtrusionDlg.h"
55 #include "SMESHGUI_ExtrusionAlongPathDlg.h"
56 #include "SMESHGUI_RevolutionDlg.h"
57 #include "SMESHGUI_TranslationDlg.h"
58 #include "SMESHGUI_RotationDlg.h"
59 #include "SMESHGUI_SymmetryDlg.h"
60 #include "SMESHGUI_SewingDlg.h"
61 #include "SMESHGUI_EditMeshDlg.h"
62 #include "SMESHGUI_MeshPatternDlg.h"
63 #include "SMESHGUI_Selection.h"
64 #include "SMESHGUI_CreatePolyhedralVolumeDlg.h"
65 #include "SMESHGUI_ConvToQuadOp.h"
66 #include "SMESHGUI_MeshOp.h"
67 #include "SMESHGUI_Displayer.h"
68 #include "SMESHGUI_MakeNodeAtPointDlg.h"
69 #include "SMESHGUI_BuildCompoundDlg.h"
70 #include "SMESHGUI_ComputeDlg.h"
71 #include "SMESHGUI_FileInfoDlg.h"
72 #include "SMESHGUI_GroupOnShapeDlg.h"
73
74 #include "SMESHGUI_Utils.h"
75 #include "SMESHGUI_GEOMGenUtils.h"
76 #include "SMESHGUI_MeshUtils.h"
77 #include "SMESHGUI_GroupUtils.h"
78 #include "SMESHGUI_FilterUtils.h"
79 #include "SMESHGUI_PatternUtils.h"
80 #include "SMESHGUI_VTKUtils.h"
81 #include "SMESHGUI_HypothesesUtils.h"
82
83 #include "SMESH_Actor.h"
84 #include "SMESH_Object.h"
85 #include "SMESH_TypeFilter.hxx"
86
87 #include "SalomeApp_Tools.h"
88 #include "SalomeApp_Study.h"
89 #include "SalomeApp_Application.h"
90 #include "SalomeApp_CheckFileDlg.h"
91 #include "SalomeApp_ImportOperation.h"
92
93 #include "LightApp_DataOwner.h"
94 #include "LightApp_Preferences.h"
95 #include "LightApp_VTKSelector.h"
96 #include "LightApp_Operation.h"
97 #include "LightApp_UpdateFlags.h"
98 #include "LightApp_NameDlg.h"
99
100 #include <SVTK_ViewWindow.h>
101 #include <SVTK_ViewModel.h>
102 #include <SVTK_InteractorStyle.h>
103 #include <SVTK_RenderWindowInteractor.h>
104 #include <SVTK_ViewManager.h>
105
106 #include "OB_Browser.h"
107
108 #include "SUIT_Tools.h"
109 #include "SUIT_MessageBox.h"
110 #include "SUIT_ResourceMgr.h"
111 #include "SUIT_FileDlg.h"
112 #include "SUIT_Desktop.h"
113 #include "SUIT_OverrideCursor.h"
114 #include "SUIT_Study.h"
115 #include "SUIT_Session.h"
116
117 #include "QtxPopupMgr.h"
118
119 #include "SALOME_ListIO.hxx"
120 #include "SALOME_ListIteratorOfListIO.hxx"
121 #include "SALOME_InteractiveObject.hxx"
122 #include "SALOME_NamingService.hxx"
123 #include "SALOME_LifeCycleCORBA.hxx"
124
125 #include "SALOMEconfig.h"
126 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
127 #include CORBA_CLIENT_HEADER(SMESH_MeshEditor)
128
129 // QT Includes
130 #define  INCLUDE_MENUITEM_DEF
131 #include <qpopupmenu.h>
132 #include <qstring.h>
133 #include <qwidget.h>
134 #include <qaction.h>
135
136 // BOOST Includes
137 #include <boost/shared_ptr.hpp>
138
139 // VTK Includes
140 #include <vtkRenderer.h>
141 #include <vtkRenderWindow.h>
142 #include <vtkActorCollection.h>
143 #include <vtkScalarBarActor.h>
144 #include <vtkUnstructuredGrid.h>
145
146 #include "utilities.h"
147
148 #include "SALOMEDS_Study.hxx"
149 #include "SALOMEDSClient_StudyBuilder.hxx"
150 #include "SALOMEDSClient_SComponent.hxx"
151
152 #include <Standard_ErrorHandler.hxx>
153
154 using namespace std;
155
156 //namespace{
157   // Declarations
158   //=============================================================
159   void ImportMeshesFromFile(SMESH::SMESH_Gen_ptr theComponentMesh,
160                             int theCommandID);
161
162   void ExportMeshToFile(int theCommandID);
163
164   void SetDisplayMode(int theCommandID);
165
166   void SetDisplayEntity(int theCommandID);
167
168   void Control( int theCommandID );
169
170
171   // Definitions
172   //=============================================================
173   void ImportMeshesFromFile( SMESH::SMESH_Gen_ptr theComponentMesh,
174                              int theCommandID )
175   {
176     QStringList filter;
177     string myExtension;
178
179     if ( theCommandID == 113 ) {
180       filter.append( QObject::tr( "MED files (*.med)" ) );
181       filter.append( QObject::tr( "All files (*)" ) );
182     }
183     else if ( theCommandID == 112 ) {
184       filter.append( QObject::tr( "IDEAS files (*.unv)" ) );
185     }
186     else if ( theCommandID == 111 ) {
187       filter.append( QObject::tr( "DAT files (*.dat)" ) );
188     }
189
190     QString anInitialPath = "";
191     if ( SUIT_FileDlg::getLastVisitedPath().isEmpty() )
192       anInitialPath = QDir::currentDirPath();
193
194     QStringList filenames = SUIT_FileDlg::getOpenFileNames( SMESHGUI::desktop(),
195                                                             anInitialPath,
196                                                             filter,
197                                                             QObject::tr( "SMESH_IMPORT_MESH" ) );
198     if ( filenames.count() > 0 ) {
199       SUIT_OverrideCursor wc;
200       _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
201
202       QStringList errors;
203       bool isEmpty = false;
204       for ( QStringList::ConstIterator it = filenames.begin(); it != filenames.end(); ++it ) {
205         QString filename = *it;
206         SMESH::mesh_array_var aMeshes = new SMESH::mesh_array;
207         try {
208           switch ( theCommandID ) {
209           case 111:
210             {
211               // DAT format (currently unsupported)
212               errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
213                              arg( QObject::tr( "SMESH_ERR_NOT_SUPPORTED_FORMAT" ) ) );
214               break;
215             }
216           case 112:
217             {
218               // UNV format
219               aMeshes->length( 1 );
220               aMeshes[0] = theComponentMesh->CreateMeshesFromUNV( filename.latin1() );
221               if ( aMeshes[0]->_is_nil() )
222                 errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
223                                arg( QObject::tr( "SMESH_ERR_UNKNOWN_IMPORT_ERROR" ) ) );
224               break;
225             }
226           case 113:
227             {
228               // MED format
229               SMESH::DriverMED_ReadStatus res;
230               aMeshes = theComponentMesh->CreateMeshesFromMED( filename.latin1(), res );
231               if ( res != SMESH::DRS_OK ) {
232                 errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
233                                arg( QObject::tr( QString( "SMESH_DRS_%1" ).arg( res ) ) ) );
234               }
235               break;
236             }
237           }
238         }
239         catch ( const SALOME::SALOME_Exception& S_ex ) {
240           errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
241                          arg( QObject::tr( "SMESH_ERR_UNKNOWN_IMPORT_ERROR" ) ) );
242         }
243
244         for ( int i = 0, iEnd = aMeshes->length(); i < iEnd; i++ ) {
245           _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshes[i] );
246           if ( aMeshSO ) {
247             _PTR(StudyBuilder) aBuilder = aStudy->NewBuilder();
248             _PTR(AttributePixMap) aPixmap = aBuilder->FindOrCreateAttribute( aMeshSO, "AttributePixMap" );
249             aPixmap->SetPixMap( "ICON_SMESH_TREE_MESH_IMPORTED" );
250             if ( theCommandID == 112 ) // mesh names aren't taken from the file for UNV import
251               SMESH::SetName( aMeshSO, QFileInfo(filename).fileName() );
252           }
253           else {
254             isEmpty = true;
255           }
256         }
257       }
258
259       // update Object browser
260       SMESHGUI::GetSMESHGUI()->updateObjBrowser();
261       
262       // show Error message box if there were errors
263       if ( errors.count() > 0 ) {
264         SUIT_MessageBox::error1( SMESHGUI::desktop(),
265                                  QObject::tr( "SMESH_ERROR" ),
266                                  QObject::tr( "SMESH_IMPORT_ERRORS" ) + "\n" + errors.join( "\n" ),
267                                  QObject::tr( "SMESH_BUT_OK" ) );
268       }
269       
270       // show warning message box, if some imported mesh is empty
271       if ( isEmpty ) {
272           SUIT_MessageBox::warn1( SMESHGUI::desktop(),
273                                   QObject::tr( "SMESH_WRN_WARNING" ),
274                                   QObject::tr( "SMESH_DRS_SOME_EMPTY" ),
275                                   QObject::tr( "SMESH_BUT_OK" ) );
276       }
277     }
278   }
279
280   void ExportMeshToFile( int theCommandID )
281   {
282     LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
283     SALOME_ListIO selected;
284     if( aSel )
285       aSel->selectedObjects( selected );
286
287     SMESH::SMESH_Mesh_var aMesh;
288     if(selected.Extent() == 1)
289       aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(selected.First());
290     if ( aMesh->_is_nil() ) {
291       SUIT_MessageBox::warn1( SMESHGUI::desktop(),
292                               QObject::tr( "SMESH_WRN_WARNING" ),
293                               QObject::tr( "SMESH_BAD_MESH_SELECTION" ),
294                               QObject::tr( "SMESH_BUT_OK" ) );
295       return;
296     }
297
298     Handle(SALOME_InteractiveObject) anIObject = selected.First();
299     QString aFilter, aTitle = QObject::tr("Export mesh");
300     QMap<QString, SMESH::MED_VERSION> aFilterMap;
301     QMap<QString, int> aFilterMapSTL;
302     switch ( theCommandID ) {
303     case 125:
304     case 122:
305       {
306         if (aMesh->HasDuplicatedGroupNamesMED()) {
307           int aRet = SUIT_MessageBox::warn2
308             (SMESHGUI::desktop(),
309              QObject::tr("SMESH_WRN_WARNING"),
310              QObject::tr("SMESH_EXPORT_MED_DUPLICATED_GRP").arg(anIObject->getName()),
311              QObject::tr("SMESH_BUT_YES"),  QObject::tr("SMESH_BUT_NO"),
312              0, 1, 0);
313           if (aRet)
314             return;
315         }
316         // PAL18696
317         QString v21 (aMesh->GetVersionString(SMESH::MED_V2_1, 2));
318         QString v22 (aMesh->GetVersionString(SMESH::MED_V2_2, 2));
319         aFilterMap.insert( QString("MED ") +  v21 + " (*.med)", SMESH::MED_V2_1 );
320         aFilterMap.insert( QString("MED ") +  v22 + " (*.med)", SMESH::MED_V2_2 );
321       }
322       break;
323     case 124:
324     case 121:
325       aFilter = QObject::tr("DAT files (*.dat)");
326       break;
327     case 126:
328     case 123:
329       {
330         if (aMesh->NbPyramids()) {
331           int aRet = SUIT_MessageBox::warn2
332             (SMESHGUI::desktop(),
333              QObject::tr("SMESH_WRN_WARNING"),
334              QObject::tr("SMESH_EXPORT_UNV").arg(anIObject->getName()),
335              QObject::tr("SMESH_BUT_YES"),  QObject::tr("SMESH_BUT_NO"),
336              0, 1, 0);
337           if (aRet)
338             return;
339         }
340         aFilter = QObject::tr("IDEAS files (*.unv)");
341       }
342       break;
343     case 140:
344     case 141:
345       {
346         // export STL
347         /*
348           there must be check on others mesh elements not equal triangles
349         */
350         if (aMesh->NbTriangles() < 1) {
351           SUIT_MessageBox::warn1
352             (SMESHGUI::desktop(),
353              QObject::tr("SMESH_WRN_WARNING"),
354              QObject::tr("SMESH_EXPORT_STL1").arg(anIObject->getName()),
355              QObject::tr("SMESH_BUT_OK"));
356           return;
357         }
358         if (!(aMesh->NbElements() - aMesh->NbTriangles())) {
359           int aRet = SUIT_MessageBox::warn2
360             (SMESHGUI::desktop(),
361              QObject::tr("SMESH_WRN_WARNING"),
362              QObject::tr("SMESH_EXPORT_STL2").arg(anIObject->getName()),
363              QObject::tr("SMESH_BUT_YES"),  QObject::tr("SMESH_BUT_NO"),
364              0, 1, 0);
365           if (aRet)
366             return;
367         }
368
369         aFilterMapSTL.insert( QObject::tr("STL ASCII  (*.stl)"), 1 ); // 1 - ASCII mode
370         aFilterMapSTL.insert( QObject::tr("STL Binary (*.stl)"), 0 ); // 0 - Binary mode
371       }
372       break;
373     default:
374       return;
375     }
376
377     QString aFilename;
378     SMESH::MED_VERSION aFormat;
379     // Init the parameter with the default value
380     bool aIsASCII_STL = true;
381     bool toCreateGroups = false;
382     SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
383     if ( resMgr )
384       toCreateGroups = resMgr->booleanValue( "SMESH", "auto_groups", false );
385
386     QString anInitialPath = "";
387     if ( SUIT_FileDlg::getLastVisitedPath().isEmpty() )
388       anInitialPath = QDir::currentDirPath();
389
390     if ( theCommandID != 122 && theCommandID != 125 && theCommandID != 140 && theCommandID != 141) {
391       if ( anInitialPath.isEmpty() ) anInitialPath = SUIT_FileDlg::getLastVisitedPath();
392       aFilename = SUIT_FileDlg::getFileName(SMESHGUI::desktop(), anInitialPath + QString("/") + anIObject->getName(),
393                                             aFilter, aTitle, false);
394     }
395     else if(theCommandID == 140 || theCommandID == 141) { // Export to STL
396       QStringList filters;
397       QMap<QString, int>::const_iterator it = aFilterMapSTL.begin();
398       for ( ; it != aFilterMapSTL.end(); ++it )
399         filters.push_back( it.key() );
400
401       SUIT_FileDlg* fd = new SUIT_FileDlg( SMESHGUI::desktop(), false, true, true );
402       fd->setCaption( aTitle );
403       fd->setFilters( filters );
404       fd->setSelectedFilter( QObject::tr("STL ASCII  (*.stl)") );
405       if ( !anInitialPath.isEmpty() )
406         fd->setDir( anInitialPath );
407       fd->setSelection(anIObject->getName());
408       bool is_ok = false;
409       while (!is_ok) {
410         fd->exec();
411         aFilename = fd->selectedFile();
412         aIsASCII_STL = (aFilterMapSTL[fd->selectedFilter()]) == 1 ? true: false;
413         is_ok = true;
414       }
415       delete fd;
416     }
417     else { // Export to MED
418       QStringList filters;
419       QString aDefaultFilter;
420       QMap<QString, SMESH::MED_VERSION>::const_iterator it = aFilterMap.begin();
421       for ( ; it != aFilterMap.end(); ++it ) {
422         filters.push_back( it.key() );
423         if (it.data() == SMESH::MED_V2_2)
424           aDefaultFilter = it.key();
425       }
426
427       //SUIT_FileDlg* fd = new SUIT_FileDlg( SMESHGUI::desktop(), false, true, true );
428       SalomeApp_CheckFileDlg* fd = new SalomeApp_CheckFileDlg
429         ( SMESHGUI::desktop(), false, QObject::tr("SMESH_AUTO_GROUPS") ,true, true );
430       fd->setCaption( aTitle );
431       fd->setFilters( filters );
432       //fd->setSelectedFilter( QObject::tr("MED 2.2 (*.med)") );
433       fd->setSelectedFilter(aDefaultFilter);
434       fd->SetChecked(toCreateGroups);
435       if ( !anInitialPath.isEmpty() )
436         fd->setDir( anInitialPath );
437       fd->setSelection(anIObject->getName());
438       bool is_ok = false;
439       while (!is_ok) {
440         fd->exec();
441         aFilename = fd->selectedFile();
442         aFormat = aFilterMap[fd->selectedFilter()];
443         is_ok = true;
444         if ( !aFilename.isEmpty()
445              && (aMesh->NbPolygons()>0 || aMesh->NbPolyhedrons()>0)
446              && aFormat==SMESH::MED_V2_1) {
447           int aRet = SUIT_MessageBox::warn2(SMESHGUI::desktop(),
448                                             QObject::tr("SMESH_WRN_WARNING"),
449                                             QObject::tr("SMESH_EXPORT_MED_V2_1").arg(anIObject->getName()),
450                                             QObject::tr("SMESH_BUT_YES"),
451                                             QObject::tr("SMESH_BUT_NO"),
452                                             0,1,0);
453           if (aRet) {
454             is_ok = false;
455           }
456         }
457       }
458       toCreateGroups = fd->IsChecked();
459       delete fd;
460     }
461     if ( !aFilename.isEmpty() ) {
462       // Check whether the file already exists and delete it if yes
463       QFile aFile( aFilename );
464       if ( aFile.exists() )
465         aFile.remove();
466       SUIT_OverrideCursor wc;
467
468       try {
469         bool Renumber = false ;
470         // PAL 14172  : Check of we have to renumber or not from the preferences before export
471         if (resMgr)
472           Renumber= resMgr->booleanValue("SMESH","renumbering");
473         if (Renumber){
474           SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
475           aMeshEditor->RenumberNodes();
476           aMeshEditor->RenumberElements();
477           if ( SMESHGUI::automaticUpdate() )
478             SMESH::UpdateView();
479         }
480         switch ( theCommandID ) {
481         case 125:
482         case 122:
483           aMesh->ExportToMED( aFilename.latin1(), toCreateGroups, aFormat );
484           break;
485         case 124:
486         case 121:
487           aMesh->ExportDAT( aFilename.latin1() );
488           break;
489         case 126:
490         case 123:
491           aMesh->ExportUNV( aFilename.latin1() );
492           break;
493         case 140:
494         case 141:
495           aMesh->ExportSTL( aFilename.latin1(), aIsASCII_STL );
496           break;
497         default:
498           break;
499         }
500       }
501       catch (const SALOME::SALOME_Exception& S_ex){
502         wc.suspend();
503         SUIT_MessageBox::warn1(SMESHGUI::desktop(),
504                                QObject::tr("SMESH_WRN_WARNING"),
505                                QObject::tr("SMESH_EXPORT_FAILED"),
506                                QObject::tr("SMESH_BUT_OK"));
507         wc.resume();
508       }
509     }
510   }
511
512   inline void InverseEntityMode(unsigned int& theOutputMode,
513                                 unsigned int theMode)
514   {
515     bool anIsNotPresent = ~theOutputMode & theMode;
516     if(anIsNotPresent)
517       theOutputMode |= theMode;
518     else
519       theOutputMode &= ~theMode;
520   }
521
522   void SetDisplayEntity(int theCommandID){
523     LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
524     SALOME_ListIO selected;
525     if( aSel )
526       aSel->selectedObjects( selected );
527
528     if(selected.Extent() >= 1){
529       SALOME_ListIteratorOfListIO It( selected );
530       for(; It.More(); It.Next()){
531         Handle(SALOME_InteractiveObject) IObject = It.Value();
532         if(IObject->hasEntry()){
533           if(SMESH_Actor *anActor = SMESH::FindActorByEntry(IObject->getEntry())){
534             unsigned int aMode = anActor->GetEntityMode();
535             switch(theCommandID){
536             case 217:
537               InverseEntityMode(aMode,SMESH_Actor::eEdges);
538               break;
539             case 218:
540               InverseEntityMode(aMode,SMESH_Actor::eFaces);
541               break;
542             case 219:
543               InverseEntityMode(aMode,SMESH_Actor::eVolumes);
544               break;
545             case 220:
546               aMode = SMESH_Actor::eAllEntity;
547               break;
548             }
549             if(aMode)
550               anActor->SetEntityMode(aMode);
551           }
552         }
553       }
554     }
555   }
556
557   void AutoColor(){
558     SALOME_ListIO selected;
559     SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
560     if( !app )
561       return;
562
563     LightApp_SelectionMgr* aSel = app->selectionMgr();
564     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
565     if( !aSel || !appStudy )
566       return;
567
568     aSel->selectedObjects( selected );
569     if( selected.IsEmpty() )
570       return;
571
572     Handle(SALOME_InteractiveObject) anIObject = selected.First();
573
574     _PTR(Study) aStudy = appStudy->studyDS();
575     _PTR(SObject) aMainSObject( aStudy->FindObjectID( anIObject->getEntry() ) );
576     SMESH::SMESH_Mesh_var aMainObject = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIObject);
577     if( aMainObject->_is_nil() )
578       return;
579
580     aMainObject->SetAutoColor( true );
581
582     QValueList<SALOMEDS::Color> aReservedColors;
583
584     SMESH::ListOfGroups aListOfGroups = *aMainObject->GetGroups();
585     for( int i = 0, n = aListOfGroups.length(); i < n; i++ )
586     {
587       SMESH::SMESH_GroupBase_var aGroupObject = aListOfGroups[i];
588       SALOMEDS::Color aCurrentColor = aGroupObject->GetColor();
589
590       SALOMEDS::Color aColor = SMESHGUI::getUniqueColor( aReservedColors );
591       aGroupObject->SetColor( aColor );
592       aReservedColors.append( aColor );
593
594       _PTR(SObject) aGroupSObject = SMESH::FindSObject(aGroupObject);
595       if(SMESH_Actor *anActor = SMESH::FindActorByEntry(aGroupSObject->GetID().c_str()))
596       {
597         if( aGroupObject->GetType() == SMESH::NODE )
598           anActor->SetNodeColor( aColor.R, aColor.G, aColor.B );
599         else if( aGroupObject->GetType() == SMESH::EDGE )
600           anActor->SetEdgeColor( aColor.R, aColor.G, aColor.B );
601         else
602           anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B );
603       }
604     }
605
606     SMESH::RepaintCurrentView();
607   }
608
609   void DisableAutoColor(){
610     LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
611     SALOME_ListIO selected;
612     if( aSel )
613       aSel->selectedObjects( selected );
614
615     if(selected.Extent()){
616       Handle(SALOME_InteractiveObject) anIObject = selected.First();
617       SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIObject);
618       if ( !aMesh->_is_nil() ) {
619         aMesh->SetAutoColor( false );
620       }
621     }
622   }
623
624   void SetDisplayMode(int theCommandID){
625     SALOME_ListIO selected;
626     SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
627     if( !app )
628       return;
629
630     LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
631     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
632     if( !aSel || !appStudy )
633       return;
634
635     _PTR(Study) aStudy = appStudy->studyDS();
636
637     aSel->selectedObjects( selected );
638
639     if(selected.Extent() >= 1){
640       switch(theCommandID){
641       case 1134:{
642         SMESHGUI::GetSMESHGUI()->EmitSignalDeactivateDialog();
643         new SMESHGUI_ClippingDlg( SMESHGUI::GetSMESHGUI(), "", false );
644         return;
645       }
646       case 1133:{
647         SMESHGUI::GetSMESHGUI()->EmitSignalDeactivateDialog();
648         new SMESHGUI_TransparencyDlg( SMESHGUI::GetSMESHGUI(), "", false );
649         return;
650       }}
651       SALOME_ListIteratorOfListIO It( selected );
652       for(; It.More(); It.Next()){
653         Handle(SALOME_InteractiveObject) IObject = It.Value();
654         if(IObject->hasEntry()){
655           if(SMESH_Actor *anActor = SMESH::FindActorByEntry(IObject->getEntry())){
656             switch(theCommandID){
657             case 211:
658               anActor->SetRepresentation(SMESH_Actor::eEdge);
659               break;
660             case 212:
661               anActor->SetRepresentation(SMESH_Actor::eSurface);
662               break;
663             case 213:
664               if(anActor->IsShrunk())
665                 anActor->UnShrink();
666               else
667                 anActor->SetShrink();
668               break;
669             case 215:
670               anActor->SetRepresentation(SMESH_Actor::ePoint);
671               break;
672             case 1132:{
673               vtkFloatingPointType color[3];
674               anActor->GetSufaceColor(color[0], color[1], color[2]);
675               int c0 = int (color[0] * 255);
676               int c1 = int (color[1] * 255);
677               int c2 = int (color[2] * 255);
678               QColor c(c0, c1, c2);
679
680               vtkFloatingPointType edgecolor[3];
681               anActor->GetEdgeColor(edgecolor[0], edgecolor[1], edgecolor[2]);
682               c0 = int (edgecolor[0] * 255);
683               c1 = int (edgecolor[1] * 255);
684               c2 = int (edgecolor[2] * 255);
685               QColor e(c0, c1, c2);
686
687               vtkFloatingPointType backfacecolor[3];
688               anActor->GetBackSufaceColor(backfacecolor[0], backfacecolor[1], backfacecolor[2]);
689               c0 = int (backfacecolor[0] * 255);
690               c1 = int (backfacecolor[1] * 255);
691               c2 = int (backfacecolor[2] * 255);
692               QColor b(c0, c1, c2);
693
694               vtkFloatingPointType nodecolor[3];
695               anActor->GetNodeColor(nodecolor[0], nodecolor[1], nodecolor[2]);
696               c0 = int (nodecolor[0] * 255);
697               c1 = int (nodecolor[1] * 255);
698               c2 = int (nodecolor[2] * 255);
699               QColor n(c0, c1, c2);
700
701               int Edgewidth = (int)anActor->GetLineWidth();
702               if(Edgewidth == 0)
703                 Edgewidth = 1;
704               int intValue = int(anActor->GetNodeSize());
705               vtkFloatingPointType Shrink = anActor->GetShrinkFactor();
706
707               SMESHGUI_Preferences_ColorDlg *aDlg =
708                 new SMESHGUI_Preferences_ColorDlg( SMESHGUI::GetSMESHGUI(), "" );
709               aDlg->SetColor(1, c);
710               aDlg->SetColor(2, e);
711               aDlg->SetColor(3, n);
712               aDlg->SetColor(4, b);
713               aDlg->SetIntValue(1, Edgewidth);
714               aDlg->SetIntValue(2, intValue);
715               aDlg->SetIntValue(3, int(Shrink*100.));
716               if(aDlg->exec()){
717                 QColor color = aDlg->GetColor(1);
718                 QColor edgecolor = aDlg->GetColor(2);
719                 QColor nodecolor = aDlg->GetColor(3);
720                 QColor backfacecolor = aDlg->GetColor(4);
721                 /* actor color and backface color */
722                 anActor->SetSufaceColor(vtkFloatingPointType (color.red()) / 255.,
723                                         vtkFloatingPointType (color.green()) / 255.,
724                                         vtkFloatingPointType (color.blue()) / 255.);
725                 anActor->SetBackSufaceColor(vtkFloatingPointType (backfacecolor.red()) / 255.,
726                                             vtkFloatingPointType (backfacecolor.green()) / 255.,
727                                             vtkFloatingPointType (backfacecolor.blue()) / 255.);
728
729                 /* edge color */
730                 anActor->SetEdgeColor(vtkFloatingPointType (edgecolor.red()) / 255.,
731                                       vtkFloatingPointType (edgecolor.green()) / 255.,
732                                       vtkFloatingPointType (edgecolor.blue()) / 255.);
733
734                 /* Shrink factor and size edges */
735                 anActor->SetShrinkFactor(aDlg->GetIntValue(3) / 100.);
736                 anActor->SetLineWidth(aDlg->GetIntValue(1));
737
738                 /* Nodes color and size */
739                 anActor->SetNodeColor(vtkFloatingPointType (nodecolor.red()) / 255.,
740                                       vtkFloatingPointType (nodecolor.green()) / 255.,
741                                       vtkFloatingPointType (nodecolor.blue()) / 255.);
742                 anActor->SetNodeSize(aDlg->GetIntValue(2));
743
744                 SMESH::SMESH_GroupBase_var aGroupObject = SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IObject);
745                 if( !aGroupObject->_is_nil() )
746                 {
747                   SALOMEDS::Color aColor;
748                   aColor.R = (float)color.red() / 255.0;
749                   aColor.G = (float)color.green() / 255.0;
750                   aColor.B = (float)color.blue() / 255.0;
751                   aGroupObject->SetColor( aColor );
752                 }
753
754                 delete aDlg;
755               }
756               break;
757             }}
758           }
759         }
760       }
761       SMESH::RepaintCurrentView();
762     }
763   }
764
765   void Control( int theCommandID )
766   {
767     LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
768     SALOME_ListIO selected;
769     if( aSel )
770       aSel->selectedObjects( selected );
771
772     if( !selected.IsEmpty() ){
773       Handle(SALOME_InteractiveObject) anIO = selected.First();
774       if(!anIO.IsNull()){
775         QString aTitle;
776         SMESH_Actor::eControl aControl = SMESH_Actor::eNone;
777         if(SMESH_Actor *anActor = SMESH::FindActorByEntry(anIO->getEntry())){
778           switch ( theCommandID ){
779           case 6001:
780             aTitle = QObject::tr( "LENGTH_EDGES" );
781             aControl = SMESH_Actor::eLength;
782             break;
783           case 6018:
784             aTitle = QObject::tr( "LENGTH2D_EDGES" );
785             aControl = SMESH_Actor::eLength2D;
786             break;
787           case 6002:
788             aTitle = QObject::tr( "FREE_EDGES" );
789             aControl = SMESH_Actor::eFreeEdges;
790             break;
791           case 6003:
792             aTitle = QObject::tr( "FREE_BORDERS" );
793             aControl = SMESH_Actor::eFreeBorders;
794             break;
795           case 6004:
796             aTitle = QObject::tr( "MULTI_BORDERS" );
797             aControl = SMESH_Actor::eMultiConnection;
798             break;
799           case 6019:
800             aTitle = QObject::tr( "MULTI2D_BORDERS" );
801             aControl = SMESH_Actor::eMultiConnection2D;
802             break;
803           case 6011:
804             aTitle = QObject::tr( "AREA_ELEMENTS" );
805             aControl = SMESH_Actor::eArea;
806             break;
807           case 6012:
808             aTitle = QObject::tr( "TAPER_ELEMENTS" );
809             aControl = SMESH_Actor::eTaper;
810             break;
811           case 6013:
812             aTitle = QObject::tr( "ASPECTRATIO_ELEMENTS" );
813             aControl = SMESH_Actor::eAspectRatio;
814             break;
815           case 6017:
816             aTitle = QObject::tr( "ASPECTRATIO_3D_ELEMENTS" );
817             aControl = SMESH_Actor::eAspectRatio3D;
818             break;
819           case 6014:
820             aTitle = QObject::tr( "MINIMUMANGLE_ELEMENTS" );
821             aControl = SMESH_Actor::eMinimumAngle;
822             break;
823           case 6015:
824             aTitle = QObject::tr( "WARP_ELEMENTS" );
825             aControl = SMESH_Actor::eWarping;
826             break;
827           case 6016:
828             aTitle = QObject::tr( "SKEW_ELEMENTS" );
829             aControl = SMESH_Actor::eSkew;
830             break;
831           case 6009:
832             aTitle = QObject::tr( "SMESH_VOLUME" );
833             aControl = SMESH_Actor::eVolume3D;
834             break;
835           }
836           anActor->SetControlMode(aControl);
837           anActor->GetScalarBarActor()->SetTitle(aTitle.latin1());
838           SMESH::RepaintCurrentView();
839         }
840       }
841     }
842   }
843
844
845   bool CheckOIType(const Handle(SALOME_InteractiveObject) & theIO,
846                    MeshObjectType                           theType,
847                    const QString                            theInTypeName,
848                    QString &                                theOutTypeName)
849   {
850     SMESH_TypeFilter aTypeFilter( theType );
851     QString entry;
852     if( !theIO.IsNull() )
853     {
854       entry = theIO->getEntry();
855       LightApp_DataOwner owner( entry );
856       if ( aTypeFilter.isOk( &owner )) {
857         theOutTypeName = theInTypeName;
858         return true;
859       }
860     }
861     return false;
862   }
863
864
865   QString CheckTypeObject(const Handle(SALOME_InteractiveObject) & theIO)
866   {
867     _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
868     _PTR(SObject) aSObj = aStudy->FindObjectID(theIO->getEntry());
869     if (aSObj) {
870       _PTR(SComponent) aSComp = aSObj->GetFatherComponent();
871       CORBA::String_var anID = aSComp->GetID().c_str();
872       if (!strcmp(anID.in(),theIO->getEntry()))
873         return "Component";
874     }
875
876     QString aTypeName;
877     if (
878         CheckOIType ( theIO, HYPOTHESIS,    "Hypothesis", aTypeName ) ||
879         CheckOIType ( theIO, ALGORITHM,     "Algorithm",  aTypeName ) ||
880         CheckOIType ( theIO, MESH,          "Mesh",       aTypeName ) ||
881         CheckOIType ( theIO, SUBMESH,       "SubMesh",    aTypeName ) ||
882         CheckOIType ( theIO, GROUP,         "Group",      aTypeName )
883         )
884       return aTypeName;
885
886     return "NoType";
887   }
888
889
890   QString CheckHomogeneousSelection()
891   {
892     //SUIT_Study* aStudy = SMESH::GetActiveStudy();
893     LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
894     SALOME_ListIO selected;
895     if( aSel )
896       aSel->selectedObjects( selected );
897
898     QString RefType = CheckTypeObject(selected.First());
899     SALOME_ListIteratorOfListIO It(selected);
900     for (; It.More(); It.Next())
901       {
902         Handle(SALOME_InteractiveObject) IObject = It.Value();
903         QString Type = CheckTypeObject(IObject);
904         if (Type.compare(RefType) != 0)
905           return "Heterogeneous Selection";
906       }
907
908     return RefType;
909   }
910
911
912   void SMESHGUI::OnEditDelete()
913   {
914     // VSR 17/11/04: check if all objects selected belong to SMESH component --> start
915     LightApp_SelectionMgr* aSel = SMESHGUI::selectionMgr();
916     SALOME_ListIO selected; aSel->selectedObjects( selected, QString::null, false );
917
918     _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
919     _PTR(StudyBuilder) aStudyBuilder = aStudy->NewBuilder();
920     _PTR(GenericAttribute) anAttr;
921     _PTR(AttributeIOR) anIOR;
922
923     int objectCount = 0;
924     QString aNameList;
925     QString aParentComponent = QString::null;
926     Handle(SALOME_InteractiveObject) anIO;
927     for( SALOME_ListIteratorOfListIO anIt( selected ); anIt.More(); anIt.Next() )
928     {
929       anIO = anIt.Value();
930       QString cur = anIt.Value()->getComponentDataType();
931       _PTR(SObject) aSO = aStudy->FindObjectID(anIO->getEntry());
932       if (aSO) {
933         // check if object is reference
934         _PTR(SObject) aRefSObj;
935         aNameList.append("\n    - ");
936         if ( aSO->ReferencedObject( aRefSObj ) ) {
937           QString aRefName = aRefSObj->GetName();
938           aNameList.append( aRefName );
939           cur = aRefSObj->GetFatherComponent()->ComponentDataType();
940         }
941         else
942           aNameList.append(anIO->getName());
943         objectCount++;
944       }
945
946       if( aParentComponent.isNull() )
947         aParentComponent = cur;
948       else if( !aParentComponent.isEmpty() && aParentComponent!=cur )
949         aParentComponent = "";
950     }
951
952     if ( objectCount == 0 )
953       return; // No Valid Objects Selected
954
955     if ( aParentComponent != SMESHGUI::GetSMESHGUI()->name() )  {
956       SUIT_MessageBox::warn1 ( SMESHGUI::desktop(),
957                               QObject::tr("ERR_ERROR"),
958                               QObject::tr("NON_SMESH_OBJECTS_SELECTED").arg( SMESHGUI::GetSMESHGUI()->moduleName() ),
959                               QObject::tr("BUT_OK") );
960       return;
961     }
962     // VSR 17/11/04: check if all objects selected belong to SMESH component <-- finish
963     if (SUIT_MessageBox::warn2
964         (SMESHGUI::desktop(),
965          QObject::tr("SMESH_WRN_WARNING"),
966          QObject::tr("SMESH_REALLY_DELETE").arg( objectCount ).arg( aNameList ),
967          QObject::tr("SMESH_BUT_YES"), QObject::tr("SMESH_BUT_NO"), 1, 0, 0) != 1)
968       return;
969
970     SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
971     SUIT_ViewManager* vm = anApp->activeViewManager();
972     int nbSf = vm->getViewsCount();
973
974     SALOME_ListIteratorOfListIO It(selected);
975
976     aStudyBuilder->NewCommand();  // There is a transaction
977     for(; It.More(); It.Next()){ // loop on selected IO's
978       Handle(SALOME_InteractiveObject) IObject = It.Value();
979       if(IObject->hasEntry()) {
980         _PTR(SObject) aSO = aStudy->FindObjectID(IObject->getEntry());
981
982         // disable removal of "SMESH" component object
983         if(aSO->FindAttribute(anAttr, "AttributeIOR")){
984           anIOR = anAttr;
985           if ( !strcmp( (char*)anIOR->Value().c_str(), engineIOR().latin1() ) )
986             continue;
987         }
988         //Check the referenced object
989         _PTR(SObject) refobj;
990         if ( aSO && aSO->ReferencedObject( refobj ) )
991           aSO = refobj; // Delete main Object instead of reference
992
993         // put the whole hierarchy of sub-objects of the selected SO into a list and
994         // then treat them all starting from the deepest objects (at list back)
995
996         list< _PTR(SObject) > listSO;
997         listSO.push_back( aSO );
998         list< _PTR(SObject) >::iterator itSO = listSO.begin();
999         for ( ; itSO != listSO.end(); ++itSO ) {
1000           _PTR(ChildIterator) it = aStudy->NewChildIterator( *itSO );
1001           for (it->InitEx(false); it->More(); it->Next())
1002             listSO.push_back( it->Value() );
1003         }
1004
1005         // treat SO's in the list starting from the back
1006
1007         list< _PTR(SObject) >::reverse_iterator ritSO = listSO.rbegin();
1008         for ( ; ritSO != listSO.rend(); ++ritSO ) {
1009           _PTR(SObject) SO = *ritSO;
1010           if ( !SO ) continue;
1011           string anEntry = SO->GetID();
1012
1013           /** Erase graphical object **/
1014           if(SO->FindAttribute(anAttr, "AttributeIOR")){
1015             QPtrVector<SUIT_ViewWindow> aViews = vm->getViews();
1016             for(int i = 0; i < nbSf; i++){
1017               SUIT_ViewWindow *sf = aViews[i];
1018               if(SMESH_Actor* anActor = SMESH::FindActorByEntry(sf,anEntry.c_str())){
1019                 SMESH::RemoveActor(sf,anActor);
1020               }
1021             }
1022           }
1023
1024           /** Remove an object from data structures **/
1025           SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow( SMESH::SObjectToObject( SO ));
1026           SMESH::SMESH_subMesh_var   aSubMesh = SMESH::SMESH_subMesh::_narrow( SMESH::SObjectToObject( SO ));
1027           if ( !aGroup->_is_nil() ) {                          // DELETE GROUP
1028             SMESH::SMESH_Mesh_var aMesh = aGroup->GetMesh();
1029             aMesh->RemoveGroup( aGroup );
1030           }
1031           else if ( !aSubMesh->_is_nil() ) {                   // DELETE SUBMESH
1032             SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
1033             aMesh->RemoveSubMesh( aSubMesh );
1034
1035             _PTR(SObject) aMeshSO = SMESH::FindSObject(aMesh);
1036             if (aMeshSO)
1037               SMESH::ModifiedMesh(aMeshSO, false, aMesh->NbNodes()==0);
1038           }
1039           else {
1040             IObject = new SALOME_InteractiveObject
1041               ( anEntry.c_str(), engineIOR().latin1(), SO->GetName().c_str() );
1042             QString objType = CheckTypeObject(IObject);
1043             if ( objType == "Hypothesis" || objType == "Algorithm" ) {// DELETE HYPOTHESIS
1044               SMESH::RemoveHypothesisOrAlgorithmOnMesh(IObject);
1045               aStudyBuilder->RemoveObjectWithChildren( SO );
1046             }
1047             else {// default action: remove SObject from the study
1048               // san - it's no use opening a transaction here until UNDO/REDO is provided in SMESH
1049               //SUIT_Operation *op = new SALOMEGUI_ImportOperation(myActiveStudy);
1050               //op->start();
1051               aStudyBuilder->RemoveObjectWithChildren( SO );
1052               //op->finish();
1053             }
1054           }
1055         } /* listSO back loop */
1056       } /* IObject->hasEntry() */
1057     } /* more/next */
1058     aStudyBuilder->CommitCommand();
1059
1060     /* Clear any previous selection */
1061     SALOME_ListIO l1;
1062     aSel->setSelectedObjects( l1 );
1063
1064     SMESHGUI::GetSMESHGUI()->updateObjBrowser();
1065   }
1066 //}
1067
1068 extern "C" {
1069   SMESHGUI_EXPORT CAM_Module* createModule()
1070   {
1071     return new SMESHGUI();
1072   }
1073 }
1074
1075 SMESH::SMESH_Gen_var SMESHGUI::myComponentSMESH = SMESH::SMESH_Gen::_nil();
1076
1077 //=============================================================================
1078 /*!
1079  *
1080  */
1081 //=============================================================================
1082 SMESHGUI::SMESHGUI() :
1083 SalomeApp_Module( "SMESH" )
1084 {
1085   if ( CORBA::is_nil( myComponentSMESH ) )
1086   {
1087     CORBA::Boolean anIsEmbeddedMode;
1088     myComponentSMESH = SMESH_Client::GetSMESHGen(getApp()->orb(),anIsEmbeddedMode);
1089   }
1090
1091   myActiveDialogBox = 0;
1092   myFilterLibraryDlg = 0;
1093   myState = -1;
1094   myDisplayer = 0;
1095
1096   SMESH::GetFilterManager();
1097   SMESH::GetPattern();
1098
1099   /* load resources for all available meshers */
1100   SMESH::InitAvailableHypotheses();
1101 }
1102
1103 //=============================================================================
1104 /*!
1105  *
1106  */
1107 //=============================================================================
1108 SMESHGUI::~SMESHGUI()
1109 {
1110   SMESH::GetFilterManager()->Destroy();
1111   SMESH::GetFilterManager() = SMESH::FilterManager::_nil();
1112 }
1113
1114 //=============================================================================
1115 /*!
1116  *
1117  */
1118 //=============================================================================
1119 LightApp_SelectionMgr* SMESHGUI::selectionMgr()
1120 {
1121   SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
1122   if( anApp )
1123     return dynamic_cast<LightApp_SelectionMgr*>( anApp->selectionMgr() );
1124   else
1125     return 0;
1126 }
1127
1128 bool SMESHGUI::automaticUpdate()
1129 {
1130   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1131   if ( !resMgr )
1132     return false;
1133
1134   return resMgr->booleanValue( "SMESH", "auto_update", false );
1135 }
1136
1137 //=============================================================================
1138 /*!
1139  *
1140  */
1141 //=============================================================================
1142 SUIT_ResourceMgr* SMESHGUI::resourceMgr()
1143 {
1144   return dynamic_cast<SUIT_ResourceMgr*>( SUIT_Session::session()->resourceMgr() );
1145 }
1146
1147 //=============================================================================
1148 /*!
1149  *
1150  */
1151 //=============================================================================
1152 SMESHGUI* SMESHGUI::GetSMESHGUI()
1153 {
1154   SMESHGUI* smeshMod = 0;
1155   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>(SUIT_Session::session()->activeApplication());
1156   if ( app )
1157   {
1158     CAM_Module* module = app->module( "Mesh" );
1159     smeshMod = dynamic_cast<SMESHGUI*>( module );
1160   }
1161
1162   if ( smeshMod && smeshMod->application() && smeshMod->application()->activeStudy() )
1163   {
1164     SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( smeshMod->application()->activeStudy() );
1165     if ( study )
1166     {
1167       _PTR(Study) aStudy = study->studyDS();
1168       if ( aStudy )
1169         GetSMESHGen()->SetCurrentStudy( _CAST(Study,aStudy)->GetStudy() );
1170     }
1171   }
1172
1173   return smeshMod;
1174 }
1175
1176 extern "C"
1177 {
1178   Standard_EXPORT SMESHGUI* GetComponentGUI()
1179   {
1180     return SMESHGUI::GetSMESHGUI();
1181   }
1182 }
1183
1184 //=============================================================================
1185 /*!
1186  *
1187  */
1188 //=============================================================================
1189 void SMESHGUI::SetState(int aState)
1190 {
1191   myState = aState;
1192 }
1193
1194 //=============================================================================
1195 /*!
1196  *
1197  */
1198 //=============================================================================
1199 void SMESHGUI::ResetState()
1200 {
1201   myState = -1;
1202 }
1203
1204 //=============================================================================
1205 /*!
1206  *
1207  */
1208 //=============================================================================
1209 void SMESHGUI::EmitSignalDeactivateDialog()
1210 {
1211   emit SignalDeactivateActiveDialog();
1212 }
1213
1214 //=============================================================================
1215 /*!
1216  *
1217  */
1218 //=============================================================================
1219 void SMESHGUI::EmitSignalStudyFrameChanged()
1220 {
1221   emit SignalStudyFrameChanged();
1222 }
1223
1224 //=============================================================================
1225 /*!
1226  *
1227  */
1228 //=============================================================================
1229 void SMESHGUI::EmitSignalCloseAllDialogs()
1230 {
1231   emit SignalCloseAllDialogs();
1232 }
1233
1234 //=============================================================================
1235 /*!
1236  *
1237  */
1238 //=============================================================================
1239 QDialog *SMESHGUI::GetActiveDialogBox()
1240 {
1241   return myActiveDialogBox;
1242 }
1243
1244 //=============================================================================
1245 /*!
1246  *
1247  */
1248 //=============================================================================
1249 void SMESHGUI::SetActiveDialogBox(QDialog * aDlg)
1250 {
1251   myActiveDialogBox = (QDialog *) aDlg;
1252   return;
1253 }
1254
1255 //=============================================================================
1256 /*!
1257  *
1258  */
1259 //=============================================================================
1260 SUIT_Desktop* SMESHGUI::desktop()
1261 {
1262   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
1263   if( app )
1264     return app->desktop();
1265   else
1266     return 0;
1267 }
1268
1269 //=============================================================================
1270 /*!
1271  *
1272  */
1273 //=============================================================================
1274 SalomeApp_Study* SMESHGUI::activeStudy()
1275 {
1276   SUIT_Application* app = SUIT_Session::session()->activeApplication();
1277   if( app )
1278     return dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1279   else
1280     return NULL;
1281 }
1282
1283 //=============================================================================
1284 /*!
1285  *
1286  */
1287 //=============================================================================
1288 bool SMESHGUI::DefineDlgPosition(QWidget * aDlg, int &x, int &y)
1289 {
1290   /* Here the position is on the bottom right corner - 10 */
1291   // aDlg->resize(QSize().expandedTo(aDlg->minimumSizeHint()));
1292   aDlg->adjustSize();
1293   SUIT_Desktop *PP = desktop();
1294   x = abs(PP->x() + PP->size().width() - aDlg->size().width() - 10);
1295   y = abs(PP->y() + PP->size().height() - aDlg->size().height() - 10);
1296   return true;
1297 }
1298
1299 //=============================================================================
1300 /*!
1301  *
1302  */
1303 //=============================================================================
1304 static int isStudyLocked(_PTR(Study) theStudy){
1305   return theStudy->GetProperties()->IsLocked();
1306 }
1307
1308 static bool checkLock(_PTR(Study) theStudy) {
1309   if (isStudyLocked(theStudy)) {
1310     SUIT_MessageBox::warn1 ( SMESHGUI::desktop(),
1311                            QObject::tr("WRN_WARNING"),
1312                            QObject::tr("WRN_STUDY_LOCKED"),
1313                            QObject::tr("BUT_OK") );
1314     return true;
1315   }
1316   return false;
1317 }
1318
1319 //=======================================================================
1320 //function : CheckActiveStudyLocked
1321 //purpose  :
1322 //=======================================================================
1323
1324 bool SMESHGUI::isActiveStudyLocked()
1325 {
1326   _PTR(Study) aStudy = activeStudy()->studyDS();
1327   return checkLock( aStudy );
1328 }
1329
1330 //=============================================================================
1331 /*!
1332  *
1333  */
1334 //=============================================================================
1335 bool SMESHGUI::OnGUIEvent( int theCommandID )
1336 {
1337   SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( application() );
1338   if( !anApp )
1339     return false;
1340
1341   _PTR(Study) aStudy = SMESH::GetActiveStudyDocument(); //Document OCAF de l'etude active
1342   SUIT_ResourceMgr* mgr = resourceMgr();
1343   if( !mgr )
1344     return false;
1345
1346   if (CORBA::is_nil(GetSMESHGen()->GetCurrentStudy())) {
1347     GetSMESHGen()->SetCurrentStudy(_CAST(Study,aStudy)->GetStudy());
1348   }
1349
1350   SUIT_ViewWindow* view = application()->desktop()->activeWindow();
1351   SVTK_ViewWindow* vtkwnd = dynamic_cast<SVTK_ViewWindow*>( view );
1352
1353   //QAction* act = action( theCommandID );
1354
1355   switch (theCommandID) {
1356   case 33:                                      // DELETE
1357     if(checkLock(aStudy)) break;
1358     OnEditDelete();
1359     break;
1360
1361   case 113:                                     // IMPORT
1362   case 112:
1363   case 111:
1364     {
1365       if(checkLock(aStudy)) break;
1366       ::ImportMeshesFromFile(GetSMESHGen(),theCommandID);
1367       break;
1368     }
1369
1370   case 150:    //MED FILE INFORMATION
1371     {
1372       SALOME_ListIO selected;
1373       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1374       if( aSel )
1375         aSel->selectedObjects( selected );
1376       if( selected.Extent() )
1377       {
1378         Handle(SALOME_InteractiveObject) anIObject = selected.First();
1379         SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIObject);
1380         if ( !aMesh->_is_nil() )
1381         {
1382           SMESHGUI_FileInfoDlg dlg( desktop(), aMesh->GetMEDFileInfo() );
1383           dlg.exec();
1384         }
1385       }
1386       break;
1387     }
1388   case 122:                                     // EXPORT MED
1389   case 121:
1390   case 123:
1391   case 124:
1392   case 125:
1393   case 126:
1394   case 140:
1395   case 141:
1396     {
1397       ::ExportMeshToFile(theCommandID);
1398       break;
1399     }
1400
1401   case 200:                                     // SCALAR BAR
1402     {
1403       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1404       SALOME_ListIO selected;
1405       if( aSel )
1406         aSel->selectedObjects( selected );
1407
1408       if( selected.Extent() ) {
1409         Handle(SALOME_InteractiveObject) anIO = selected.First();
1410         if( anIO->hasEntry() ) {
1411           if( SMESH_Actor* anActor = SMESH::FindActorByEntry( anIO->getEntry() ) ) {
1412             anActor->SetControlMode( SMESH_Actor::eNone );
1413           }
1414         }
1415       }
1416       break;
1417     }
1418   case 201:
1419     {
1420       SMESHGUI_Preferences_ScalarBarDlg::ScalarBarProperties( this );
1421       break;
1422     }
1423
1424     // Auto-color
1425   case 1136:
1426     ::AutoColor();
1427   break;
1428
1429   case 1137:
1430     ::DisableAutoColor();
1431   break;
1432
1433   case 1134: // Clipping
1434   case 1133: // Tranparency
1435   case 1132: // Colors / Size
1436
1437     // Display Mode
1438   case 215: // Nodes
1439   case 213: // Nodes
1440   case 212: // Nodes
1441   case 211: // Nodes
1442     ::SetDisplayMode(theCommandID);
1443   break;
1444
1445     // Display Entity
1446   case 217: // Edges
1447   case 218: // Faces
1448   case 219: // Volumes
1449   case 220: // All Entity
1450     ::SetDisplayEntity(theCommandID);
1451   break;
1452
1453   case 214:                                     // UPDATE
1454     {
1455       if(checkLock(aStudy)) break;
1456       try {
1457 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1458         OCC_CATCH_SIGNALS;
1459 #endif
1460         SMESH::UpdateView();
1461       }
1462       catch (std::bad_alloc) { // PAL16774 (Crash after display of many groups)
1463         SMESH::OnVisuException();
1464       }
1465       catch (...) { // PAL16774 (Crash after display of many groups)
1466         SMESH::OnVisuException();
1467       }
1468
1469       SALOME_ListIO l;
1470       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1471       aSel->selectedObjects( l );
1472       aSel->setSelectedObjects( l );
1473       break;
1474     }
1475
1476   case 300:                                     // ERASE
1477   case 301:                                     // DISPLAY
1478   case 302:                                     // DISPLAY ONLY
1479     {
1480       SMESH::EDisplaing anAction;
1481       switch (theCommandID) {
1482       case 300: anAction = SMESH::eErase; break;
1483       case 301: anAction = SMESH::eDisplay; break;
1484       case 302: anAction = SMESH::eDisplayOnly; break;
1485       }
1486
1487       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1488       SALOME_ListIO sel_objects, to_process;
1489       if (aSel)
1490         aSel->selectedObjects( sel_objects );
1491
1492       if( theCommandID==302 )
1493         startOperation( myEraseAll );
1494
1495       extractContainers( sel_objects, to_process );
1496
1497       try {
1498 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1499         OCC_CATCH_SIGNALS;
1500 #endif
1501         if (vtkwnd) {
1502           SALOME_ListIteratorOfListIO It( to_process );
1503           for (; It.More(); It.Next()) {
1504             Handle(SALOME_InteractiveObject) IOS = It.Value();
1505             if (IOS->hasEntry()) {
1506               if (!SMESH::UpdateView(anAction, IOS->getEntry()))
1507                 break; // PAL16774 (Crash after display of many groups)
1508               if (anAction == SMESH::eDisplayOnly)
1509                 anAction = SMESH::eDisplay;
1510             }
1511           }
1512         }
1513
1514         // PAL13338 + PAL15161 -->
1515         if ( ( theCommandID==301 || theCommandID==302 ) && !checkLock(aStudy))
1516           SMESH::UpdateView();
1517         // PAL13338 + PAL15161 <--
1518       }
1519       catch (...) { // PAL16774 (Crash after display of many groups)
1520         SMESH::OnVisuException();
1521       }
1522
1523       if (anAction == SMESH::eErase) {
1524         SALOME_ListIO l1;
1525         aSel->setSelectedObjects( l1 );
1526       }
1527       else
1528         aSel->setSelectedObjects( to_process );
1529
1530       break;
1531     }
1532
1533   case 400:                                     // NODES
1534     {
1535       if(checkLock(aStudy)) break;
1536
1537       if ( vtkwnd ) {
1538         EmitSignalDeactivateDialog();
1539
1540         new SMESHGUI_NodesDlg(this);
1541       }
1542       else {
1543         SUIT_MessageBox::warn1(desktop(),
1544                               tr("SMESH_WRN_WARNING"),
1545                               tr("SMESH_WRN_VIEWER_VTK"),
1546                               tr("SMESH_BUT_OK"));
1547       }
1548       break;
1549     }
1550
1551   case 2151:  // FILTER
1552   {
1553     if ( vtkwnd )
1554     {
1555       EmitSignalDeactivateDialog();
1556       new SMESHGUI_FilterDlg( this, SMESH::EDGE );
1557     }
1558     break;
1559   }
1560
1561   case 406:                                     // MOVE NODE
1562     {
1563       if ( !vtkwnd )
1564       {
1565         SUIT_MessageBox::warn1( desktop(), tr( "SMESH_WRN_WARNING" ),
1566           tr( "NOT_A_VTK_VIEWER" ),tr( "SMESH_BUT_OK" ) );
1567         break;
1568       }
1569
1570       if(checkLock(aStudy)) break;
1571       new SMESHGUI_MoveNodesDlg(this);
1572       break;
1573     }
1574
1575   case 701:                                     // COMPUTE MESH
1576     {
1577       if (checkLock(aStudy)) break;
1578
1579       startOperation( 701 );
1580     }
1581     break;
1582
1583   case 702:  // Create mesh
1584     startOperation( 702 );
1585     break;
1586   case 703:  // Create sub-mesh
1587     startOperation( 703 );
1588     break;
1589   case 704: // Edit mesh/sub-mesh
1590     startOperation( 704 );
1591     break;
1592   case 710: // Build compound mesh
1593     {
1594       if (checkLock(aStudy)) break;
1595       EmitSignalDeactivateDialog();
1596       new SMESHGUI_BuildCompoundDlg( this );
1597     }
1598     break;
1599
1600   case 407: // DIAGONAL INVERSION
1601   case 408: // Delete diagonal
1602     {
1603       if ( !vtkwnd )
1604       {
1605         SUIT_MessageBox::warn1( desktop(), tr( "SMESH_WRN_WARNING" ),
1606           tr( "NOT_A_VTK_VIEWER" ),tr( "SMESH_BUT_OK" ) );
1607         break;
1608       }
1609
1610       if ( checkLock( aStudy ) )
1611         break;
1612
1613       /*Standard_Boolean aRes;
1614       SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IObject);
1615       if ( aMesh->_is_nil() )
1616       {
1617         SUIT_MessageBox::warn1(GetDesktop(), tr( "SMESH_WRN_WARNING" ),
1618           tr( "SMESH_BAD_SELECTION" ), tr( "SMESH_BUT_OK" ) );
1619         break;
1620       }
1621       */
1622       EmitSignalDeactivateDialog();
1623       if ( theCommandID == 407 )
1624         new SMESHGUI_TrianglesInversionDlg(this);
1625       else
1626         new SMESHGUI_UnionOfTwoTrianglesDlg(this);
1627       break;
1628     }
1629     case 409: // Change orientation
1630     case 410: // Union of triangles
1631     case 411: // Cutting of quadrangles
1632     {
1633       if ( !vtkwnd )
1634       {
1635         SUIT_MessageBox::warn1( desktop(), tr( "SMESH_WRN_WARNING" ),
1636           tr( "NOT_A_VTK_VIEWER" ),tr( "SMESH_BUT_OK" ) );
1637         break;
1638       }
1639
1640       if ( checkLock( aStudy ) )
1641         break;
1642
1643       EmitSignalDeactivateDialog();
1644       SMESHGUI_MultiEditDlg* aDlg = NULL;
1645       if ( theCommandID == 409 )
1646         aDlg = new SMESHGUI_ChangeOrientationDlg(this);
1647       else if ( theCommandID == 410 )
1648         aDlg = new SMESHGUI_UnionOfTrianglesDlg(this);
1649       else
1650         aDlg = new SMESHGUI_CuttingOfQuadsDlg(this);
1651
1652       aDlg->show();
1653       break;
1654     }
1655   case 412: // Smoothing
1656     {
1657       if(checkLock(aStudy)) break;
1658       if( vtkwnd ) {
1659         EmitSignalDeactivateDialog();
1660         new SMESHGUI_SmoothingDlg( this );
1661       }
1662       else {
1663         SUIT_MessageBox::warn1(desktop(),
1664                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1665                               tr("SMESH_BUT_OK"));
1666       }
1667       break;
1668     }
1669   case 413: // Extrusion
1670     {
1671       if (checkLock(aStudy)) break;
1672       if (vtkwnd) {
1673         EmitSignalDeactivateDialog();
1674         new SMESHGUI_ExtrusionDlg ( this );
1675       } else {
1676         SUIT_MessageBox::warn1(desktop(),
1677                                tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1678                                tr("SMESH_BUT_OK"));
1679       }
1680       break;
1681     }
1682   case 414: // Revolution
1683     {
1684       if(checkLock(aStudy)) break;
1685       if( vtkwnd ) {
1686         EmitSignalDeactivateDialog();
1687         new SMESHGUI_RevolutionDlg( this );
1688       }
1689       else {
1690         SUIT_MessageBox::warn1(desktop(),
1691                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1692                               tr("SMESH_BUT_OK"));
1693       }
1694       break;
1695     }
1696   case 415: // Pattern mapping
1697     {
1698       if ( checkLock( aStudy ) )
1699         break;
1700       if ( vtkwnd )
1701       {
1702         EmitSignalDeactivateDialog();
1703         new SMESHGUI_MeshPatternDlg( this );
1704       }
1705       else {
1706         SUIT_MessageBox::warn1(desktop(),
1707                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1708                               tr("SMESH_BUT_OK"));
1709       }
1710       break;
1711     }
1712   case 416: // Extrusion along a path
1713     {
1714       if (checkLock(aStudy)) break;
1715       if (vtkwnd) {
1716         EmitSignalDeactivateDialog();
1717         new SMESHGUI_ExtrusionAlongPathDlg( this );
1718       } else {
1719         SUIT_MessageBox::warn1(desktop(),
1720                                tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1721                                tr("SMESH_BUT_OK"));
1722       }
1723       break;
1724     }
1725   case 417: // Convert mesh to quadratic
1726     {
1727     startOperation( 417 );
1728       /*      if (checkLock(aStudy)) break;
1729       if (vtkwnd) {
1730         EmitSignalDeactivateDialog();
1731         new SMESHGUI_ConvToQuadDlg();
1732       } else {
1733         SUIT_MessageBox::warn1(desktop(),
1734                                tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1735                                tr("SMESH_BUT_OK"));
1736                                }*/
1737       break;
1738     }
1739   case 806:                                     // CREATE GEO GROUP
1740     {
1741       startOperation( 806 );
1742       break;
1743     }
1744   case 801:                                     // CREATE GROUP
1745     {
1746       if ( !vtkwnd )
1747       {
1748         SUIT_MessageBox::warn1( desktop(), tr( "SMESH_WRN_WARNING" ),
1749           tr( "NOT_A_VTK_VIEWER" ),tr( "SMESH_BUT_OK" ) );
1750         break;
1751       }
1752
1753       if(checkLock(aStudy)) break;
1754       EmitSignalDeactivateDialog();
1755       SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_nil();
1756
1757       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1758       SALOME_ListIO selected;
1759       if( aSel )
1760         aSel->selectedObjects( selected );
1761
1762       int nbSel = selected.Extent();
1763       if (nbSel == 1) {
1764         // check if mesh is selected
1765         aMesh = SMESH::GetMeshByIO( selected.First() );
1766       }
1767       SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, "", aMesh);
1768       aDlg->show();
1769       break;
1770     }
1771
1772   case 802:                                     // CONSTRUCT GROUP
1773     {
1774       if ( !vtkwnd )
1775       {
1776         SUIT_MessageBox::warn1( desktop(), tr( "SMESH_WRN_WARNING" ),
1777           tr( "NOT_A_VTK_VIEWER" ),tr( "SMESH_BUT_OK" ) );
1778         break;
1779       }
1780
1781       if(checkLock(aStudy)) break;
1782       EmitSignalDeactivateDialog();
1783
1784       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1785       SALOME_ListIO selected;
1786       if( aSel )
1787         aSel->selectedObjects( selected );
1788
1789       int nbSel = selected.Extent();
1790       if (nbSel == 1) {
1791         // check if submesh is selected
1792         Handle(SALOME_InteractiveObject) IObject = selected.First();
1793         if (IObject->hasEntry()) {
1794           _PTR(SObject) aSObj = aStudy->FindObjectID(IObject->getEntry());
1795           if( aSObj ) {
1796             SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow( SMESH::SObjectToObject( aSObj ) );
1797             if (!aSubMesh->_is_nil()) {
1798               try {
1799                 SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
1800                 // get submesh elements list by types
1801                 SMESH::long_array_var aNodes = aSubMesh->GetElementsByType(SMESH::NODE);
1802                 SMESH::long_array_var aEdges = aSubMesh->GetElementsByType(SMESH::EDGE);
1803                 SMESH::long_array_var aFaces = aSubMesh->GetElementsByType(SMESH::FACE);
1804                 SMESH::long_array_var aVolumes = aSubMesh->GetElementsByType(SMESH::VOLUME);
1805                 // create group for each type o elements
1806                 QString aName = IObject->getName();
1807                 if (aNodes->length() > 0) {
1808                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::NODE, aName + "_Nodes");
1809                   aGroup->Add(aNodes.inout());
1810                 }
1811                 if (aEdges->length() > 0) {
1812                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::EDGE, aName + "_Edges");
1813                   aGroup->Add(aEdges.inout());
1814                 }
1815                 if (aFaces->length() > 0) {
1816                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::FACE, aName + "_Faces");
1817                   aGroup->Add(aFaces.inout());
1818                 }
1819                 if (aVolumes->length() > 0) {
1820                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::VOLUME, aName + "_Volumes");
1821                   aGroup->Add(aVolumes.inout());
1822                 }
1823                 updateObjBrowser();
1824
1825               }
1826               catch(const SALOME::SALOME_Exception & S_ex){
1827                 SalomeApp_Tools::QtCatchCorbaException(S_ex);
1828               }
1829             }
1830           }
1831         }
1832       }
1833       else if(nbSel==0) {
1834         SUIT_MessageBox::warn1(desktop(),
1835                                tr("SMESH_WRN_WARNING"),
1836                                tr("SMESH_WRN_NO_AVAILABLE_DATA"),
1837                                tr("SMESH_BUT_OK"));
1838       }
1839       break;
1840     }
1841
1842   case 803:                                     // EDIT GROUP
1843     {
1844       if ( !vtkwnd )
1845       {
1846         SUIT_MessageBox::warn1( desktop(), tr( "SMESH_WRN_WARNING" ),
1847           tr( "NOT_A_VTK_VIEWER" ),tr( "SMESH_BUT_OK" ) );
1848         break;
1849       }
1850
1851       if(checkLock(aStudy)) break;
1852       EmitSignalDeactivateDialog();
1853
1854       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1855       SALOME_ListIO selected;
1856       if( aSel )
1857         aSel->selectedObjects( selected );
1858
1859       SALOME_ListIteratorOfListIO It (selected);
1860       int nbSelectedGroups = 0;
1861       for ( ; It.More(); It.Next() )
1862       {
1863         SMESH::SMESH_GroupBase_var aGroup =
1864           SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(It.Value());
1865         if (!aGroup->_is_nil()) {
1866           nbSelectedGroups++;
1867           SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, "", aGroup);
1868           aDlg->show();
1869         }
1870       }
1871       if (nbSelectedGroups == 0)
1872         {
1873           SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, "", SMESH::SMESH_GroupBase::_nil());
1874           aDlg->show();
1875         }
1876       break;
1877     }
1878
1879   case 804:                                     // Add elements to group
1880     {
1881       if(checkLock(aStudy)) break;
1882       if (myState == 800) {
1883         SMESHGUI_GroupDlg *aDlg = (SMESHGUI_GroupDlg*) myActiveDialogBox;
1884         if (aDlg) aDlg->onAdd();
1885       }
1886       break;
1887     }
1888
1889   case 805:                                     // Remove elements from group
1890     {
1891       if(checkLock(aStudy)) break;
1892       if (myState == 800) {
1893         SMESHGUI_GroupDlg *aDlg = (SMESHGUI_GroupDlg*) myActiveDialogBox;
1894         if (aDlg) aDlg->onRemove();
1895       }
1896       break;
1897     }
1898
1899     case 810: // Union Groups
1900     case 811: // Intersect groups
1901     case 812: // Cut groups
1902     {
1903       if ( !vtkwnd )
1904       {
1905         SUIT_MessageBox::warn1( desktop(), tr( "SMESH_WRN_WARNING" ),
1906           tr( "NOT_A_VTK_VIEWER" ),tr( "SMESH_BUT_OK" ) );
1907         break;
1908       }
1909
1910       if ( checkLock( aStudy ) )
1911         break;
1912
1913       EmitSignalDeactivateDialog();
1914
1915       int aMode;
1916       if      ( theCommandID == 810 ) aMode = SMESHGUI_GroupOpDlg::UNION;
1917       else if ( theCommandID == 811 ) aMode = SMESHGUI_GroupOpDlg::INTERSECT;
1918       else                            aMode = SMESHGUI_GroupOpDlg::CUT;
1919
1920       ( new SMESHGUI_GroupOpDlg( this, aMode ) )->show();
1921       break;
1922     }
1923
1924     case 813: // Delete groups with their contents
1925     {
1926       if ( !vtkwnd )
1927       {
1928         SUIT_MessageBox::warn1( desktop(), tr( "SMESH_WRN_WARNING" ),
1929           tr( "NOT_A_VTK_VIEWER" ),tr( "SMESH_BUT_OK" ) );
1930         break;
1931       }
1932
1933       if ( checkLock( aStudy ) )
1934         break;
1935
1936       EmitSignalDeactivateDialog();
1937
1938       new SMESHGUI_DeleteGroupDlg( this );
1939       break;
1940     }
1941
1942   case 900:                                     // MESH INFOS
1943     {
1944       EmitSignalDeactivateDialog();
1945       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1946       SALOME_ListIO selected;
1947       if( aSel )
1948         aSel->selectedObjects( selected );
1949
1950       if ( selected.Extent() > 1 ) { // a dlg for each IO
1951         SALOME_ListIO IOs;
1952         SALOME_ListIteratorOfListIO It (selected);
1953         for ( ; It.More(); It.Next() ) {
1954           IOs.Clear(); IOs.Append( It.Value() );
1955           aSel->setSelectedObjects( IOs );
1956           new SMESHGUI_MeshInfosDlg(this, "", false);
1957         }
1958         // restore selection
1959         aSel->setSelectedObjects( selected );
1960       }
1961       else
1962         new SMESHGUI_MeshInfosDlg(this, "", false);
1963       break;
1964     }
1965
1966   case 902:                                     // STANDARD MESH INFOS
1967     {
1968       EmitSignalDeactivateDialog();
1969       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1970       SALOME_ListIO selected;
1971       if( aSel )
1972         aSel->selectedObjects( selected );
1973
1974       if ( selected.Extent() > 1 ) { // a dlg for each IO
1975         SALOME_ListIO IOs;
1976         SALOME_ListIteratorOfListIO It (selected);
1977         for ( ; It.More(); It.Next() ) {
1978           IOs.Clear();
1979           IOs.Append( It.Value() );
1980           aSel->setSelectedObjects( IOs );
1981           new SMESHGUI_StandardMeshInfosDlg( this, "", false);
1982         }
1983         // restore selection
1984         aSel->setSelectedObjects( selected );
1985       }
1986       else
1987         new SMESHGUI_StandardMeshInfosDlg( this, "", false);
1988       break;
1989     }
1990
1991   case 903:                                     // WHAT IS
1992     {
1993       EmitSignalDeactivateDialog();
1994       new SMESHGUI_WhatIsDlg( this, "", false);
1995       break;
1996     }
1997
1998   case 1100:                                    // EDIT HYPOTHESIS
1999     {
2000       if(checkLock(aStudy)) break;
2001
2002       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2003       SALOME_ListIO selected;
2004       if( aSel )
2005         aSel->selectedObjects( selected );
2006
2007       int nbSel = selected.Extent();
2008
2009       if (nbSel == 1) {
2010         Handle(SALOME_InteractiveObject) anIObject = selected.First();
2011         SMESH::SMESH_Hypothesis_var aHypothesis = SMESH::IObjectToInterface<SMESH::SMESH_Hypothesis>(anIObject);
2012
2013         /* Look for all mesh objects that have this hypothesis affected in order to flag as ModifiedMesh */
2014         /* At end below '...->updateObjBrowser(true)' will change icon of mesh objects                   */
2015         /* Warning : however by internal mechanism all subMeshes icons are changed !                     */
2016         if ( !aHypothesis->_is_nil() )
2017         {
2018           CORBA::String_var aHypType = aHypothesis->GetName();
2019           SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHypType);
2020           if (aCreator)
2021             aCreator->edit( aHypothesis.in(), anIObject->getName(), desktop() );
2022           else
2023           {
2024             // report error
2025           }
2026         }
2027       }
2028       updateObjBrowser( true );
2029       break;
2030     }
2031
2032   case 1101:                                    // RENAME
2033     {
2034       if ( checkLock( aStudy ) )
2035         break;
2036
2037       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2038       SALOME_ListIO selected;
2039       if( aSel )
2040         aSel->selectedObjects( selected );
2041
2042       bool isAny = false; // iss there any appropriate object selected
2043
2044       SALOME_ListIteratorOfListIO It( selected );
2045       for ( ; It.More(); It.Next() )
2046       {
2047         Handle(SALOME_InteractiveObject) IObject = It.Value();
2048         _PTR(SObject) obj = aStudy->FindObjectID( IObject->getEntry() );
2049         _PTR(GenericAttribute) anAttr;
2050         _PTR(AttributeName) aName;
2051         if ( obj )
2052         {
2053           if ( obj->FindAttribute(anAttr, "AttributeName") )
2054           {
2055             aName = anAttr;
2056             QString newName = QString(aName->Value().c_str());
2057
2058             // check type to prevent renaming of inappropriate objects
2059             int aType = SMESHGUI_Selection::type(IObject->getEntry(), aStudy);
2060             if (aType == MESH || aType == GROUP ||
2061                 aType == SUBMESH || aType == SUBMESH_COMPOUND ||
2062                 aType == SUBMESH_SOLID || aType == SUBMESH_FACE ||
2063                 aType == SUBMESH_EDGE || aType == SUBMESH_VERTEX ||
2064                 aType == HYPOTHESIS || aType == ALGORITHM)
2065             {
2066               isAny = true;
2067               newName = LightApp_NameDlg::getName(desktop(), newName);
2068               if ( !newName.isEmpty() )
2069               {
2070                 //old source: aStudy->renameIObject( IObject, newName );
2071                 aName->SetValue( newName.latin1() );
2072
2073                 // if current object is group update group's name
2074                 SMESH::SMESH_GroupBase_var aGroup =
2075                   SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IObject);
2076                 if (!aGroup->_is_nil() )
2077                   aGroup->SetName( newName.latin1() );
2078
2079                 updateObjBrowser();
2080               }
2081             }
2082           }
2083         }
2084       } // for
2085
2086       if (!isAny) {
2087         SUIT_MessageBox::warn1(desktop(),
2088                                QObject::tr("SMESH_WRN_WARNING"),
2089                                QObject::tr("SMESH_WRN_NO_APPROPRIATE_SELECTION"),
2090                                QObject::tr("SMESH_BUT_OK"));
2091       }
2092       break;
2093     }
2094
2095   case 1102:                                    // REMOVE HYPOTHESIS / ALGORITHMS
2096     {
2097       if(checkLock(aStudy)) break;
2098       SUIT_OverrideCursor wc;
2099
2100       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2101       SALOME_ListIO selected;
2102       if( aSel )
2103         aSel->selectedObjects( selected, QString::null, false );
2104
2105       SALOME_ListIteratorOfListIO It(selected);
2106       for (int i = 0; It.More(); It.Next(), i++) {
2107         Handle(SALOME_InteractiveObject) IObject = It.Value();
2108         SMESH::RemoveHypothesisOrAlgorithmOnMesh(IObject);
2109       }
2110       SALOME_ListIO l1;
2111       aSel->setSelectedObjects( l1 );
2112       updateObjBrowser();
2113       break;
2114     }
2115
2116   case 401:                                     // GEOM::EDGE
2117   case 4021:                                    // TRIANGLE
2118   case 4022:                                    // QUAD
2119   case 4023:                                    // POLYGON
2120   case 4031:                                    // TETRA
2121   case 4032:                                    // HEXA
2122     {
2123       if(checkLock(aStudy)) break;
2124       if ( vtkwnd ) {
2125         EmitSignalDeactivateDialog();
2126         SMDSAbs_ElementType type    = SMDSAbs_Edge;
2127         int                 nbNodes = 2;
2128         switch (theCommandID) {
2129         case 4021:                                      // TRIANGLE
2130           type = SMDSAbs_Face; nbNodes = 3; break;
2131         case 4022:                                      // QUAD
2132           type = SMDSAbs_Face; nbNodes = 4; break;
2133         case 4031:                                      // TETRA
2134           type = SMDSAbs_Volume; nbNodes = 4; break;
2135         case 4023:                                      // POLYGON
2136           type = SMDSAbs_Face; nbNodes = 5; break;     // 5 - identificator for POLYGON
2137         case 4032:                                      // HEXA
2138           type = SMDSAbs_Volume; nbNodes = 8; break;
2139         case 4033:                                      // POLYHEDRE
2140           type = SMDSAbs_Volume; nbNodes = 9; break; // 9 - identificator for POLYHEDRE
2141         default:;
2142         }
2143         new SMESHGUI_AddMeshElementDlg( this, "", type, nbNodes);
2144       }
2145       else {
2146         SUIT_MessageBox::warn1(desktop(),
2147                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2148                               tr("SMESH_BUT_OK"));
2149       }
2150       break;
2151     }
2152   case 4033:                                    // POLYHEDRON
2153     {
2154       if(checkLock(aStudy)) break;
2155       if ( vtkwnd ) {
2156         EmitSignalDeactivateDialog();
2157         new SMESHGUI_CreatePolyhedralVolumeDlg(this, "", FALSE );
2158       }
2159       else {
2160         SUIT_MessageBox::warn1(SMESHGUI::desktop(),
2161                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2162                               tr("SMESH_BUT_OK"));
2163       }
2164       break;
2165     }
2166   case 4034:     // QUADRATIC EDGE
2167   case 4035:     // QUADRATIC TRIANGLE
2168   case 4036:     // QUADRATIC QUADRANGLE
2169   case 4037:     // QUADRATIC TETRAHEDRON
2170   case 4038:     // QUADRATIC PYRAMID
2171   case 4039:     // QUADRATIC PENTAHEDRON
2172   case 4040:     // QUADRATIC HEXAHEDRON
2173     {
2174       if(checkLock(aStudy)) break;
2175       if ( vtkwnd ) {
2176         EmitSignalDeactivateDialog();
2177         int type;
2178
2179         switch (theCommandID) {
2180         case 4034:
2181           type = QUAD_EDGE; break;
2182         case 4035:
2183           type = QUAD_TRIANGLE; break;
2184         case 4036:
2185           type = QUAD_QUADRANGLE; break;
2186         case 4037:
2187           type = QUAD_TETRAHEDRON; break;
2188         case 4038:
2189           type = QUAD_PYRAMID; break;
2190         case 4039:
2191           type = QUAD_PENTAHEDRON; break;
2192         case 4040:
2193           type = QUAD_HEXAHEDRON;
2194           break;
2195         default:;
2196         }
2197          new SMESHGUI_AddQuadraticElementDlg( this, type );
2198       }
2199       else {
2200         SUIT_MessageBox::warn1(SMESHGUI::desktop(),
2201                                tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2202                                tr("SMESH_BUT_OK"));
2203       }
2204       break;
2205     }
2206   case 4041:                                    // REMOVES NODES
2207     {
2208       if(checkLock(aStudy)) break;
2209       if ( vtkwnd ) {
2210         EmitSignalDeactivateDialog();
2211         new SMESHGUI_RemoveNodesDlg(this);
2212       }
2213       else {
2214         SUIT_MessageBox::warn1(desktop(),
2215                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2216                               tr("SMESH_BUT_OK"));
2217       }
2218       break;
2219     }
2220   case 4042:                                    // REMOVES ELEMENTS
2221     {
2222       if(checkLock(aStudy)) break;
2223       if( vtkwnd ) {
2224         EmitSignalDeactivateDialog();
2225         new SMESHGUI_RemoveElementsDlg(this);
2226       }
2227       else
2228         {
2229           SUIT_MessageBox::warn1(desktop(),
2230                                 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2231                                 tr("SMESH_BUT_OK"));
2232         }
2233       break;
2234     }
2235   case 4043: {                                // CLEAR_MESH
2236
2237     if(checkLock(aStudy)) break;
2238     
2239     SALOME_ListIO selected;
2240     if( LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr() )
2241       aSel->selectedObjects( selected );
2242
2243     SUIT_OverrideCursor wc;
2244     SALOME_ListIteratorOfListIO It (selected);
2245     for ( ; It.More(); It.Next() )
2246     {
2247       Handle(SALOME_InteractiveObject) IOS = It.Value();
2248       SMESH::SMESH_Mesh_var aMesh =
2249         SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IOS);
2250       if ( aMesh->_is_nil()) continue;
2251       try {
2252         SMESH::UpdateView(SMESH::eErase, IOS->getEntry());
2253         aMesh->Clear();
2254         _PTR(SObject) aMeshSObj = SMESH::FindSObject(aMesh);
2255         SMESH::ModifiedMesh( aMeshSObj, false, true);
2256         // hide groups and submeshes
2257         _PTR(ChildIterator) anIter =
2258           SMESH::GetActiveStudyDocument()->NewChildIterator( aMeshSObj );
2259         for ( anIter->InitEx(true); anIter->More(); anIter->Next() )
2260         {
2261           _PTR(SObject) so = anIter->Value();
2262           SMESH::UpdateView(SMESH::eErase, so->GetID().c_str());
2263         }
2264       }
2265       catch (const SALOME::SALOME_Exception& S_ex){
2266         wc.suspend();
2267         SalomeApp_Tools::QtCatchCorbaException(S_ex);
2268         wc.resume();
2269       }
2270     }
2271     SMESH::UpdateView();
2272     updateObjBrowser();
2273     break;
2274   }
2275   case 4051:                                    // RENUMBERING NODES
2276     {
2277       if(checkLock(aStudy)) break;
2278       if( vtkwnd ) {
2279         EmitSignalDeactivateDialog();
2280         new SMESHGUI_RenumberingDlg( this, "", 0);
2281       }
2282       else
2283         {
2284           SUIT_MessageBox::warn1(desktop(),
2285                                 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2286                                 tr("SMESH_BUT_OK"));
2287         }
2288       break;
2289     }
2290   case 4052:                                    // RENUMBERING ELEMENTS
2291     {
2292       if(checkLock(aStudy)) break;
2293       if ( vtkwnd ) {
2294         EmitSignalDeactivateDialog();
2295         new SMESHGUI_RenumberingDlg( this, "", 1);
2296       }
2297       else
2298         {
2299           SUIT_MessageBox::warn1(desktop(),
2300                                 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2301                                 tr("SMESH_BUT_OK"));
2302         }
2303       break;
2304     }
2305   case 4061:                                   // TRANSLATION
2306     {
2307       if(checkLock(aStudy)) break;
2308       if ( vtkwnd ) {
2309         EmitSignalDeactivateDialog();
2310         new SMESHGUI_TranslationDlg( this );
2311       }
2312       else {
2313         SUIT_MessageBox::warn1(desktop(),
2314                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2315                               tr("SMESH_BUT_OK"));
2316       }
2317       break;
2318     }
2319   case 4062:                                   // ROTATION
2320     {
2321       if(checkLock(aStudy)) break;
2322       if( vtkwnd ) {
2323         EmitSignalDeactivateDialog();
2324         new SMESHGUI_RotationDlg( this );
2325       }
2326       else {
2327         SUIT_MessageBox::warn1(desktop(),
2328                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2329                               tr("SMESH_BUT_OK"));
2330       }
2331       break;
2332     }
2333   case 4063:                                   // SYMMETRY
2334     {
2335       if(checkLock(aStudy)) break;
2336       if(vtkwnd) {
2337         EmitSignalDeactivateDialog();
2338         new SMESHGUI_SymmetryDlg( this );
2339       }
2340       else {
2341         SUIT_MessageBox::warn1(desktop(),
2342                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2343                               tr("SMESH_BUT_OK"));
2344       }
2345       break;
2346     }
2347   case 4064:                                   // SEWING
2348     {
2349       if(checkLock(aStudy)) break;
2350       if(vtkwnd) {
2351         EmitSignalDeactivateDialog();
2352         new SMESHGUI_SewingDlg( this );
2353       }
2354       else {
2355         SUIT_MessageBox::warn1(desktop(),
2356                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2357                               tr("SMESH_BUT_OK"));
2358       }
2359       break;
2360     }
2361   case 4065:                                   // MERGE NODES
2362     {
2363       if(checkLock(aStudy)) break;
2364       if(vtkwnd) {
2365         EmitSignalDeactivateDialog();
2366         new SMESHGUI_EditMeshDlg( this, 0 );
2367       }
2368       else {
2369         SUIT_MessageBox::warn1(desktop(),
2370                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2371                               tr("SMESH_BUT_OK"));
2372       }
2373       break;
2374     }
2375   case 4066:                                   // MERGE EQUAL ELEMENTS
2376     {
2377       if (checkLock(aStudy)) break;
2378       if (vtkwnd) {
2379         EmitSignalDeactivateDialog();
2380         new SMESHGUI_EditMeshDlg( this, 1 );
2381       } else {
2382         SUIT_MessageBox::warn1(desktop(),
2383                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2384                               tr("SMESH_BUT_OK"));
2385       }
2386       break;
2387     }
2388
2389   case 4067: // MAKE MESH PASS THROUGH POINT
2390     startOperation( 4067 );
2391     break;
2392
2393   case 5105: // Library of selection filters
2394   {
2395     static QValueList<int> aTypes;
2396     if ( aTypes.isEmpty() )
2397     {
2398       aTypes.append( SMESH::NODE );
2399       aTypes.append( SMESH::EDGE );
2400       aTypes.append( SMESH::FACE );
2401       aTypes.append( SMESH::VOLUME );
2402     }
2403     if (!myFilterLibraryDlg)
2404       myFilterLibraryDlg = new SMESHGUI_FilterLibraryDlg( this, SMESH::GetDesktop( this ), aTypes, SMESHGUI_FilterLibraryDlg::EDIT );
2405     else if (myFilterLibraryDlg->isHidden())
2406       myFilterLibraryDlg->Init( aTypes, SMESHGUI_FilterLibraryDlg::EDIT );
2407     myFilterLibraryDlg->raise();
2408   }
2409   break;
2410
2411   case 6017:                                    // CONTROLS
2412   case 6016:
2413   case 6015:
2414   case 6014:
2415   case 6013:
2416   case 6012:
2417   case 6011:
2418   case 6001:
2419   case 6018:
2420   case 6019:
2421   case 6002:
2422   case 6003:
2423   case 6004:
2424   case 6009:
2425     if ( vtkwnd ) {
2426
2427       LightApp_SelectionMgr* mgr = selectionMgr();
2428       SALOME_ListIO selected; mgr->selectedObjects( selected );
2429
2430       if ( selected.Extent() == 1 && selected.First()->hasEntry() ) {
2431         _PTR(SObject) SO = aStudy->FindObjectID( selected.First()->getEntry() );
2432         if ( SO ) {
2433           CORBA::Object_var aObject = SMESH::SObjectToObject( SO );
2434           SMESH::SMESH_Mesh_var      aMesh    = SMESH::SMESH_Mesh::_narrow( aObject );
2435           SMESH::SMESH_subMesh_var   aSubMesh = SMESH::SMESH_subMesh::_narrow( aObject );
2436           SMESH::SMESH_GroupBase_var aGroup   = SMESH::SMESH_GroupBase::_narrow( aObject );
2437           if ( !aMesh->_is_nil() || !aSubMesh->_is_nil() || !aGroup->_is_nil() ) {
2438             ::Control( theCommandID );
2439             break;
2440           }
2441         }
2442       }
2443       SUIT_MessageBox::warn1(desktop(),
2444                             tr( "SMESH_WRN_WARNING" ),
2445                             tr( "SMESH_BAD_SELECTION" ),
2446                             tr( "SMESH_BUT_OK" ) );
2447       break;
2448     }
2449     else {
2450       SUIT_MessageBox::warn1(desktop(),
2451                             tr( "SMESH_WRN_WARNING" ),
2452                             tr( "NOT_A_VTK_VIEWER" ),
2453                             tr( "SMESH_BUT_OK" ) );
2454     }
2455     break;
2456   case 9010:
2457     {
2458       LightApp_SelectionMgr* mgr = selectionMgr();
2459       SALOME_ListIO selected; mgr->selectedObjects( selected );
2460
2461       SALOME_ListIteratorOfListIO it(selected);
2462       for(; it.More(); it.Next()) {
2463         Handle(SALOME_InteractiveObject) anIObject = it.Value();
2464         if(anIObject->hasEntry()) {
2465           if(SMESH_Actor *anActor = SMESH::FindActorByEntry(anIObject->getEntry())){
2466             anActor->SetPointsLabeled( !anActor->GetPointsLabeled() );
2467           }
2468         }
2469       }
2470       break;
2471     }
2472   case 9011:
2473     {
2474       LightApp_SelectionMgr* mgr = selectionMgr();
2475       SALOME_ListIO selected; mgr->selectedObjects( selected );
2476
2477       if (selected.Extent() == 1)       {
2478         Handle(SALOME_InteractiveObject) anIObject = selected.First();
2479         if(anIObject->hasEntry())
2480           if(SMESH_Actor *anActor = SMESH::FindActorByEntry(anIObject->getEntry())){
2481             anActor->SetCellsLabeled( !anActor->GetCellsLabeled() );
2482           }
2483       }
2484       break;
2485     }
2486   }
2487
2488   anApp->updateActions(); //SRN: To update a Save button in the toolbar
2489   //updateObjBrowser();
2490   return true;
2491 }
2492
2493 //=============================================================================
2494 /*!
2495  *
2496  */
2497 //=============================================================================
2498 bool SMESHGUI::OnMousePress( QMouseEvent * pe, SUIT_ViewWindow * wnd )
2499 {
2500   return false;
2501 }
2502
2503 //=============================================================================
2504 /*!
2505  *
2506  */
2507 //=============================================================================
2508 bool SMESHGUI::OnMouseMove( QMouseEvent * pe, SUIT_ViewWindow * wnd )
2509 {
2510   return true;
2511 }
2512
2513 //=============================================================================
2514 /*!
2515  *
2516  */
2517 //=============================================================================
2518 bool SMESHGUI::OnKeyPress( QKeyEvent * pe, SUIT_ViewWindow * wnd )
2519 {
2520   return true;
2521 }
2522
2523 //=============================================================================
2524 /*! Method:  BuildPresentation(const Handle(SALOME_InteractiveObject)& theIO)
2525  *  Purpose: ensures that the actor for the given <theIO> exists in the active VTK view
2526  */
2527 //=============================================================================
2528 void SMESHGUI::BuildPresentation( const Handle(SALOME_InteractiveObject) & theIO,
2529                                   SUIT_ViewWindow* wnd )
2530 {
2531   if(theIO->hasEntry()){
2532     //SUIT_ViewWindow* wnd = SMESH::GetActiveWindow();
2533     SMESH::UpdateView(wnd,SMESH::eDisplay,theIO->getEntry());
2534   }
2535 }
2536
2537 //=======================================================================
2538 // function : createSMESHAction
2539 // purpose  :
2540 //=======================================================================
2541 void SMESHGUI::createSMESHAction( const int id, const QString& po_id, const QString& icon_id, const int key, const bool toggle  )
2542 {
2543   QIconSet icon;
2544   QWidget* parent = application()->desktop();
2545   SUIT_ResourceMgr* resMgr = resourceMgr();
2546   QPixmap pix;
2547   if ( icon_id.length() )
2548     pix = resMgr->loadPixmap( "SMESH", tr( icon_id ) );
2549   else
2550     pix = resMgr->loadPixmap( "SMESH", tr( QString( "ICO_" )+po_id ), false );
2551   if ( !pix.isNull() )
2552     icon = QIconSet( pix );
2553
2554   QString tooltip    = tr( QString( "TOP_" )+po_id ),
2555           menu       = tr( QString( "MEN_" )+po_id ),
2556           status_bar = tr( QString( "STB_" )+po_id );
2557
2558   createAction( id, tooltip, icon, menu, status_bar, key, parent, toggle, this, SLOT( OnGUIEvent() )  );
2559 }
2560
2561 //=======================================================================
2562 // function : createPopupItem
2563 // purpose  :
2564 //=======================================================================
2565 void SMESHGUI::createPopupItem( const int id,
2566                                 const QString& clients,
2567                                 const QString& types,
2568                                 const QString& theRule,
2569                                 const int pId )
2570 {
2571   int parentId = pId;
2572   if( pId!=-1 )
2573     parentId = popupMgr()->actionId( action( pId ) );
2574
2575   if( !popupMgr()->contains( popupMgr()->actionId( action( id ) ) ) )
2576     popupMgr()->insert( action( id ), parentId, 0 );
2577
2578   QChar lc = QtxPopupMgr::Selection::defEquality();
2579   QString rule = "(%1) and (%2) and (%3)";
2580   rule = rule.arg( QString( "%1>0" ).arg( QtxPopupMgr::Selection::defSelCountParam() ) );
2581   if( clients.isEmpty() )
2582     rule = rule.arg( QString( "true" ) );
2583   else
2584     rule = rule.arg( QString( "%1client in {%2}" ).arg( lc ).arg( clients ) );
2585   rule = rule.arg( QString( "%1type in {%2}" ).arg( lc ).arg( types ) );
2586   rule += theRule;
2587
2588   bool cont = myRules.contains( id );
2589   if( cont )
2590     rule = QString( "%1 or (%2)" ).arg( myRules[ id ] ).arg( rule );
2591
2592   popupMgr()->setRule( action( id ), rule, true );
2593   myRules[ id ] = QString( cont ? "%1" : "(%1)" ).arg( rule );
2594 }
2595
2596 //=======================================================================
2597 // function : initialize
2598 // purpose  :
2599 //=======================================================================
2600 void SMESHGUI::initialize( CAM_Application* app )
2601 {
2602   SalomeApp_Module::initialize( app );
2603
2604 //   SUIT_ResourceMgr* mgr = app->resourceMgr();
2605 //   if ( mgr )
2606   /* Automatic Update flag */
2607 //     myAutomaticUpdate = mgr->booleanValue( "SMESH", "AutomaticUpdate", myAutomaticUpdate );
2608
2609   // ----- create actions --------------
2610
2611   createSMESHAction(  111, "DAT", "", (CTRL+Key_B) );
2612   createSMESHAction(  112, "UNV", "", (CTRL+Key_U) );
2613   createSMESHAction(  113, "MED", "", (CTRL+Key_M) );
2614   createSMESHAction(  114, "NUM" );
2615   createSMESHAction(  121, "DAT" );
2616   createSMESHAction(  122, "MED" );
2617   createSMESHAction(  123, "UNV" );
2618   createSMESHAction(  140, "STL" );
2619   createSMESHAction(  124, "EXPORT_DAT" );
2620   createSMESHAction(  125, "EXPORT_MED" );
2621   createSMESHAction(  126, "EXPORT_UNV" );
2622   createSMESHAction(  141, "EXPORT_STL" );
2623   createSMESHAction(  150, "FILE_INFO" );
2624   createSMESHAction(   33, "DELETE",          "ICON_DELETE", Key_Delete );
2625   createSMESHAction( 5105, "SEL_FILTER_LIB" );
2626   createSMESHAction(  701, "COMPUTE",         "ICON_COMPUTE" );
2627   createSMESHAction(  702, "CREATE_MESH",     "ICON_DLG_INIT_MESH" );
2628   createSMESHAction(  703, "CREATE_SUBMESH",  "ICON_DLG_ADD_SUBMESH" );
2629   createSMESHAction(  704, "EDIT_MESHSUBMESH","ICON_DLG_EDIT_MESH" );
2630   createSMESHAction(  710, "BUILD_COMPOUND",  "ICON_BUILD_COMPOUND" );
2631   createSMESHAction(  806, "CREATE_GEO_GROUP","ICON_GEO_GROUP" );
2632   createSMESHAction(  801, "CREATE_GROUP",    "ICON_SMESH_TREE_GROUP" );
2633   createSMESHAction(  802, "CONSTRUCT_GROUP", "ICON_CONSTRUCT_GROUP" );
2634   createSMESHAction(  803, "EDIT_GROUP",      "ICON_EDIT_GROUP" );
2635   createSMESHAction(  804, "ADD" );
2636   createSMESHAction(  805, "REMOVE" );
2637   createSMESHAction(  810, "UN_GROUP",        "ICON_UNION" );
2638   createSMESHAction(  811, "INT_GROUP",       "ICON_INTERSECT" );
2639   createSMESHAction(  812, "CUT_GROUP",       "ICON_CUT" );
2640   createSMESHAction(  813, "DEL_GROUP",       "ICON_DEL_GROUP" );
2641   createSMESHAction(  900, "ADV_INFO",        "ICON_ADV_INFO" );
2642   createSMESHAction(  902, "STD_INFO",        "ICON_STD_INFO" );
2643   createSMESHAction(  903, "WHAT_IS",         "ICON_WHAT_IS" );
2644   createSMESHAction( 6001, "LENGTH",          "ICON_LENGTH" ,       0, true );
2645   createSMESHAction( 6002, "FREE_EDGE",       "ICON_FREE_EDGE" ,    0, true );
2646   createSMESHAction( 6003, "FREE_BORDER",     "ICON_FREE_EDGE_2D" , 0, true );
2647   createSMESHAction( 6004, "CONNECTION",      "ICON_CONNECTION" ,   0, true );
2648   createSMESHAction( 6011, "AREA",            "ICON_AREA" ,         0, true );
2649   createSMESHAction( 6012, "TAPER",           "ICON_TAPER" ,        0, true );
2650   createSMESHAction( 6013, "ASPECT",          "ICON_ASPECT" ,       0, true );
2651   createSMESHAction( 6014, "MIN_ANG",         "ICON_ANGLE" ,        0, true );
2652   createSMESHAction( 6015, "WARP",            "ICON_WARP" ,         0, true );
2653   createSMESHAction( 6016, "SKEW",            "ICON_SKEW",          0, true );
2654   createSMESHAction( 6017, "ASPECT_3D",       "ICON_ASPECT_3D",     0, true );
2655   createSMESHAction( 6018, "LENGTH_2D",       "ICON_LENGTH_2D",     0, true );
2656   createSMESHAction( 6019, "CONNECTION_2D",   "ICON_CONNECTION_2D", 0, true );
2657   createSMESHAction( 6009, "VOLUME_3D",       "ICON_VOLUME_3D",     0, true );
2658   createSMESHAction(  400, "NODE",            "ICON_DLG_NODE" );
2659   createSMESHAction(  401, "EDGE",            "ICON_DLG_EDGE" );
2660   createSMESHAction( 4021, "TRIANGLE",        "ICON_DLG_TRIANGLE" );
2661   createSMESHAction( 4022, "QUAD",            "ICON_DLG_QUADRANGLE" );
2662   createSMESHAction( 4023, "POLYGON",         "ICON_DLG_POLYGON" );
2663   createSMESHAction( 4031, "TETRA",           "ICON_DLG_TETRAS" );
2664   createSMESHAction( 4032, "HEXA",            "ICON_DLG_HEXAS" );
2665   createSMESHAction( 4041, "REMOVE_NODES",    "ICON_DLG_REM_NODE" );
2666   createSMESHAction( 4042, "REMOVE_ELEMENTS", "ICON_DLG_REM_ELEMENT" );
2667   createSMESHAction( 4043, "CLEAR_MESH"    ,  "ICON_CLEAR_MESH" );
2668   createSMESHAction( 4051, "RENUM_NODES",     "ICON_DLG_RENUMBERING_NODES" );
2669   createSMESHAction( 4052, "RENUM_ELEMENTS",  "ICON_DLG_RENUMBERING_ELEMENTS" );
2670   createSMESHAction( 4061, "TRANS",           "ICON_SMESH_TRANSLATION_VECTOR" );
2671   createSMESHAction( 4062, "ROT",             "ICON_DLG_MESH_ROTATION" );
2672   createSMESHAction( 4063, "SYM",             "ICON_SMESH_SYMMETRY_PLANE" );
2673   createSMESHAction( 4064, "SEW",             "ICON_SMESH_SEWING_FREEBORDERS" );
2674   createSMESHAction( 4065, "MERGE",           "ICON_SMESH_MERGE_NODES" );
2675   createSMESHAction( 4066, "MERGE_ELEMENTS",  "ICON_DLG_MERGE_ELEMENTS" );
2676   createSMESHAction( 4067, "MESH_THROU_POINT","ICON_DLG_MESH_THROU_POINT" );
2677   createSMESHAction(  406, "MOVE",            "ICON_DLG_MOVE_NODE" );
2678   createSMESHAction(  407, "INV",             "ICON_DLG_MESH_DIAGONAL" );
2679   createSMESHAction(  408, "UNION2",          "ICON_UNION2TRI" );
2680   createSMESHAction(  409, "ORIENT",          "ICON_DLG_MESH_ORIENTATION" );
2681   createSMESHAction(  410, "UNION",           "ICON_UNIONTRI" );
2682   createSMESHAction(  411, "CUT",             "ICON_CUTQUAD" );
2683   createSMESHAction(  412, "SMOOTH",          "ICON_DLG_SMOOTHING" );
2684   createSMESHAction(  413, "EXTRUSION",       "ICON_EXTRUSION" );
2685   createSMESHAction(  414, "REVOLUTION",      "ICON_REVOLUTION" );
2686   createSMESHAction(  415, "MAP",             "ICON_MAP" );
2687   createSMESHAction(  416, "EXTRUSION_ALONG", "ICON_EXTRUSION_ALONG" );
2688   createSMESHAction(  417, "CONV_TO_QUAD",    "ICON_CONV_TO_QUAD" );
2689   createSMESHAction(  200, "RESET" );
2690   createSMESHAction(  201, "SCALAR_BAR_PROP" );
2691   createSMESHAction(  211, "WIRE",           "ICON_WIRE", 0, true );
2692   createSMESHAction(  212, "SHADE",          "ICON_SHADE", 0, true );
2693   createSMESHAction(  213, "SHRINK",         "ICON_SHRINK", 0, true );
2694   createSMESHAction(  214, "UPDATE",         "ICON_UPDATE" );
2695   createSMESHAction(  215, "NODES",          "ICON_POINTS", 0, true );
2696   createSMESHAction(  217, "EDGES",          "ICON_DLG_EDGE", 0, true );
2697   createSMESHAction(  218, "FACES",          "ICON_DLG_TRIANGLE", 0, true );
2698   createSMESHAction(  219, "VOLUMES",        "ICON_DLG_TETRAS", 0, true );
2699   createSMESHAction(  220, "ALL" );
2700   createSMESHAction( 1100, "EDIT_HYPO" );
2701   createSMESHAction( 1101, "RENAME", "", Key_F2 );
2702   createSMESHAction( 1102, "UNASSIGN" );
2703   createSMESHAction( 9010, "NUM_NODES", "", 0, true );
2704   createSMESHAction( 9011, "NUM_ELEMENTS", "", 0, true );
2705   createSMESHAction( 1131, "DISPMODE" );
2706   createSMESHAction( 1132, "COLORS" );
2707   createSMESHAction( 1133, "TRANSP" );
2708   createSMESHAction( 1134, "CLIP" );
2709   createSMESHAction( 1135, "DISP_ENT" );
2710   createSMESHAction( 1136, "AUTO_COLOR" );
2711   createSMESHAction( 1137, "DISABLE_AUTO_COLOR" );
2712   createSMESHAction( 2000, "CTRL" );
2713
2714   createSMESHAction( 300, "ERASE" );
2715   createSMESHAction( 301, "DISPLAY" );
2716   createSMESHAction( 302, "DISPLAY_ONLY" );
2717   createSMESHAction( 4033, "POLYHEDRON", "ICON_DLG_POLYHEDRON" );
2718   createSMESHAction( 4034, "QUADRATIC_EDGE", "ICON_DLG_QUADRATIC_EDGE" );
2719   createSMESHAction( 4035, "QUADRATIC_TRIANGLE", "ICON_DLG_QUADRATIC_TRIANGLE" );
2720   createSMESHAction( 4036, "QUADRATIC_QUADRANGLE", "ICON_DLG_QUADRATIC_QUADRANGLE" );
2721   createSMESHAction( 4037, "QUADRATIC_TETRAHEDRON", "ICON_DLG_QUADRATIC_TETRAHEDRON" );
2722   createSMESHAction( 4038, "QUADRATIC_PYRAMID", "ICON_DLG_QUADRATIC_PYRAMID" );
2723   createSMESHAction( 4039, "QUADRATIC_PENTAHEDRON", "ICON_DLG_QUADRATIC_PENTAHEDRON" );
2724   createSMESHAction( 4040, "QUADRATIC_HEXAHEDRON", "ICON_DLG_QUADRATIC_HEXAHEDRON" );
2725
2726   // ----- create menu --------------
2727   int fileId   = createMenu( tr( "MEN_FILE" ),   -1,  1 ),
2728       editId   = createMenu( tr( "MEN_EDIT" ),   -1,  3 ),
2729       toolsId  = createMenu( tr( "MEN_TOOLS" ),  -1,  5, 50 ),
2730       meshId   = createMenu( tr( "MEN_MESH" ),   -1, 70, 10 ),
2731       ctrlId   = createMenu( tr( "MEN_CTRL" ),   -1, 60, 10 ),
2732       modifyId = createMenu( tr( "MEN_MODIFY" ), -1, 40, 10 ),
2733       viewId   = createMenu( tr( "MEN_VIEW" ),   -1,  2 );
2734
2735   createMenu( separator(), fileId );
2736
2737   int importId = createMenu( tr( "MEN_IMPORT" ), fileId, 11, 10 ),
2738       exportId = createMenu( tr( "MEN_EXPORT" ), fileId, 12, 10 ),
2739       addId    = createMenu( tr( "MEN_ADD" ),    modifyId, 402 ),
2740       removeId = createMenu( tr( "MEN_REMOVE" ), modifyId, 403 ),
2741       renumId  = createMenu( tr( "MEN_RENUM" ),  modifyId, 404 ),
2742       transfId = createMenu( tr( "MEN_TRANSF" ), modifyId, 405 );
2743
2744   createMenu( 111, importId, -1 );
2745   createMenu( 112, importId, -1 );
2746   createMenu( 113, importId, -1 );
2747
2748   createMenu( 121, exportId, -1 );
2749   createMenu( 122, exportId, -1 );
2750   createMenu( 123, exportId, -1 );
2751   createMenu( 140, exportId, -1 ); // export to stl STL
2752
2753   createMenu( separator(), fileId, 10 );
2754
2755   createMenu( 33, editId, -1 );
2756
2757   createMenu( 5105, toolsId, -1 );
2758
2759   createMenu( 702, meshId, -1 ); // "Mesh" menu
2760   createMenu( 703, meshId, -1 );
2761   createMenu( 704, meshId, -1 );
2762   createMenu( 710, meshId, -1 );
2763   createMenu( separator(), meshId, -1 );
2764   createMenu( 701, meshId, -1 );
2765   createMenu( separator(), meshId, -1 );
2766   createMenu( 801, meshId, -1 );
2767   createMenu( 806, meshId, -1 );
2768   createMenu( 802, meshId, -1 );
2769   createMenu( 803, meshId, -1 );
2770   createMenu( separator(), meshId, -1 );
2771   createMenu( 810, meshId, -1 );
2772   createMenu( 811, meshId, -1 );
2773   createMenu( 812, meshId, -1 );
2774   createMenu( separator(), meshId, -1 );
2775   createMenu( 813, meshId, -1 );
2776   createMenu( separator(), meshId, -1 );
2777   createMenu( 900, meshId, -1 );
2778   createMenu( 902, meshId, -1 );
2779   createMenu( 903, meshId, -1 );
2780   createMenu( separator(), meshId, -1 );
2781
2782   createMenu( 6003, ctrlId, -1 );
2783   createMenu( 6001, ctrlId, -1 );
2784   createMenu( 6004, ctrlId, -1 );
2785   createMenu( separator(), ctrlId, -1 );
2786   createMenu( 6002, ctrlId, -1 );
2787   createMenu( 6018, ctrlId, -1 );
2788   createMenu( 6019, ctrlId, -1 );
2789   createMenu( 6011, ctrlId, -1 );
2790   createMenu( 6012, ctrlId, -1 );
2791   createMenu( 6013, ctrlId, -1 );
2792   createMenu( 6014, ctrlId, -1 );
2793   createMenu( 6015, ctrlId, -1 );
2794   createMenu( 6016, ctrlId, -1 );
2795   createMenu( separator(), ctrlId, -1 );
2796   createMenu( 6017, ctrlId, -1 );
2797   createMenu( 6009, ctrlId, -1 );
2798   createMenu( separator(), ctrlId, -1 );
2799
2800   createMenu( 400, addId, -1 );
2801   createMenu( 401, addId, -1 );
2802   createMenu( 4021, addId, -1 );
2803   createMenu( 4022, addId, -1 );
2804   createMenu( 4023, addId, -1 );
2805   createMenu( 4031, addId, -1 );
2806   createMenu( 4032, addId, -1 );
2807   createMenu( 4033, addId, -1 );
2808   createMenu( separator(), addId, -1 );
2809   createMenu( 4034, addId, -1 );
2810   createMenu( 4035, addId, -1 );
2811   createMenu( 4036, addId, -1 );
2812   createMenu( 4037, addId, -1 );
2813   createMenu( 4038, addId, -1 );
2814   createMenu( 4039, addId, -1 );
2815   createMenu( 4040, addId, -1 );
2816
2817   createMenu( 4041, removeId, -1 );
2818   createMenu( 4042, removeId, -1 );
2819   createMenu( 4043, removeId, -1 );
2820
2821   createMenu( 4051, renumId, -1 );
2822   createMenu( 4052, renumId, -1 );
2823
2824   createMenu( 4061, transfId, -1 );
2825   createMenu( 4062, transfId, -1 );
2826   createMenu( 4063, transfId, -1 );
2827   createMenu( 4064, transfId, -1 );
2828   createMenu( 4065, transfId, -1 );
2829   createMenu( 4066, transfId, -1 );
2830
2831   createMenu( 406, modifyId, -1 );
2832   createMenu( 4067,modifyId, -1 );
2833   createMenu( 407, modifyId, -1 );
2834   createMenu( 408, modifyId, -1 );
2835   createMenu( 409, modifyId, -1 );
2836   createMenu( 410, modifyId, -1 );
2837   createMenu( 411, modifyId, -1 );
2838   createMenu( 412, modifyId, -1 );
2839   createMenu( 413, modifyId, -1 );
2840   createMenu( 416, modifyId, -1 );
2841   createMenu( 414, modifyId, -1 );
2842   createMenu( 415, modifyId, -1 );
2843   createMenu( 417, modifyId, -1 );
2844
2845   createMenu( 214, viewId, -1 );
2846
2847   // ----- create toolbars --------------
2848   int meshTb     = createTool( tr( "TB_MESH" ) ),
2849       ctrlTb     = createTool( tr( "TB_CTRL" ) ),
2850       addRemTb   = createTool( tr( "TB_ADD_REMOVE" ) ),
2851       modifyTb   = createTool( tr( "TB_MODIFY" ) ),
2852       dispModeTb = createTool( tr( "TB_DISP_MODE" ) );
2853
2854   createTool( 702, meshTb );
2855   createTool( 703, meshTb );
2856   createTool( 704, meshTb );
2857   createTool( 710, meshTb );
2858   createTool( separator(), meshTb );
2859   createTool( 701, meshTb );
2860   createTool( separator(), meshTb );
2861   createTool( 801, meshTb );
2862   createTool( 806, meshTb );
2863   createTool( 802, meshTb );
2864   createTool( 803, meshTb );
2865   createTool( separator(), meshTb );
2866   createTool( 900, meshTb );
2867   createTool( 902, meshTb );
2868   createTool( 903, meshTb );
2869   createTool( separator(), meshTb );
2870
2871   createTool( 6001, ctrlTb );
2872   createTool( 6003, ctrlTb );
2873   createTool( 6004, ctrlTb );
2874   createTool( separator(), ctrlTb );
2875   createTool( 6002, ctrlTb );
2876   createTool( 6018, ctrlTb );
2877   createTool( 6019, ctrlTb );
2878   createTool( 6011, ctrlTb );
2879   createTool( 6012, ctrlTb );
2880   createTool( 6013, ctrlTb );
2881   createTool( 6014, ctrlTb );
2882   createTool( 6015, ctrlTb );
2883   createTool( 6016, ctrlTb );
2884   createTool( separator(), ctrlTb );
2885   createTool( 6017, ctrlTb );
2886   createTool( 6009, ctrlTb );
2887   createTool( separator(), ctrlTb );
2888
2889   createTool( 400, addRemTb );
2890   createTool( 401, addRemTb );
2891   createTool( 4021, addRemTb );
2892   createTool( 4022, addRemTb );
2893   createTool( 4023, addRemTb );
2894   createTool( 4031, addRemTb );
2895   createTool( 4032, addRemTb );
2896   createTool( 4033, addRemTb );
2897   createTool( separator(), addRemTb );
2898   createTool( 4034, addRemTb );
2899   createTool( 4035, addRemTb );
2900   createTool( 4036, addRemTb );
2901   createTool( 4037, addRemTb );
2902   createTool( 4038, addRemTb );
2903   createTool( 4039, addRemTb );
2904   createTool( 4040, addRemTb );
2905   createTool( separator(), addRemTb );
2906   createTool( 4041, addRemTb );
2907   createTool( 4042, addRemTb );
2908   createTool( 4043, addRemTb );
2909   createTool( separator(), addRemTb );
2910   createTool( 4051, addRemTb );
2911   createTool( 4052, addRemTb );
2912   createTool( separator(), addRemTb );
2913   createTool( 4061, addRemTb );
2914   createTool( 4062, addRemTb );
2915   createTool( 4063, addRemTb );
2916   createTool( 4064, addRemTb );
2917   createTool( 4065, addRemTb );
2918   createTool( 4066, addRemTb );
2919   createTool( separator(), addRemTb );
2920
2921   createTool( 406, modifyTb );
2922   createTool( 4067,modifyTb );
2923   createTool( 407, modifyTb );
2924   createTool( 408, modifyTb );
2925   createTool( 409, modifyTb );
2926   createTool( 410, modifyTb );
2927   createTool( 411, modifyTb );
2928   createTool( 412, modifyTb );
2929   createTool( 413, modifyTb );
2930   createTool( 416, modifyTb );
2931   createTool( 414, modifyTb );
2932   createTool( 415, modifyTb );
2933   createTool( 417, modifyTb );
2934
2935   createTool( 214, dispModeTb );
2936
2937
2938   myRules.clear();
2939   QString OB = "'ObjectBrowser'",
2940           View = "'" + SVTK_Viewer::Type() + "'",
2941           pat = "'%1'",
2942           mesh    = pat.arg( SMESHGUI_Selection::typeName( MESH ) ),
2943           group   = pat.arg( SMESHGUI_Selection::typeName( GROUP ) ),
2944           hypo    = pat.arg( SMESHGUI_Selection::typeName( HYPOTHESIS ) ),
2945           algo    = pat.arg( SMESHGUI_Selection::typeName( ALGORITHM ) ),
2946           elems   = QString( "'%1' '%2' '%3' '%4' '%5' '%6'" ).
2947                        arg( SMESHGUI_Selection::typeName( SUBMESH_VERTEX ) ).
2948                        arg( SMESHGUI_Selection::typeName( SUBMESH_EDGE ) ).
2949                        arg( SMESHGUI_Selection::typeName( SUBMESH_FACE ) ).
2950                        arg( SMESHGUI_Selection::typeName( SUBMESH_SOLID ) ).
2951                        arg( SMESHGUI_Selection::typeName( SUBMESH_COMPOUND ) ).
2952                        arg( SMESHGUI_Selection::typeName( SUBMESH ) ),
2953           subMesh = elems,
2954           mesh_group = mesh + " " + subMesh + " " + group,
2955           hyp_alg = hypo + " " + algo;
2956
2957   // popup for object browser
2958
2959   createPopupItem( 150, OB, mesh, "&& selcount=1 && isImported" );      // FILE INFORMATION
2960   
2961   createPopupItem( 704, OB, mesh, "&& isComputable");      // EDIT_MESHSUBMESH
2962   createPopupItem( 704, OB, subMesh, "&& isComputable" );  // EDIT_MESHSUBMESH
2963   createPopupItem( 803, OB, group );                       // EDIT_GROUP
2964   popupMgr()->insert( separator(), -1, 0 );
2965   createPopupItem( 701, OB, mesh, "&& isComputable" );     // COMPUTE
2966   createPopupItem( 214, OB, mesh_group );                  // UPDATE
2967   createPopupItem( 900, OB, mesh_group );                  // ADV_INFO
2968   createPopupItem( 902, OB, mesh );                        // STD_INFO
2969   createPopupItem( 903, OB, mesh_group );                  // WHAT_IS
2970   popupMgr()->insert( separator(), -1, 0 );
2971   createPopupItem( 801, OB, mesh );                        // CREATE_GROUP
2972   createPopupItem( 806, OB, mesh );                        // CREATE_GEO_GROUP
2973   createPopupItem( 802, OB, subMesh );                     // CONSTRUCT_GROUP
2974   popupMgr()->insert( separator(), -1, 0 );
2975   createPopupItem( 1100, OB, hypo);                        // EDIT HYPOTHESIS
2976   createPopupItem( 1102, OB, hyp_alg ); // REMOVE HYPOTHESIS / ALGORITHMS
2977   createPopupItem( 1101, OB, mesh_group + " " + hyp_alg ); // RENAME
2978   popupMgr()->insert( separator(), -1, 0 );
2979   createPopupItem( 4043, OB, mesh );                       // CLEAR_MESH
2980   popupMgr()->insert( separator(), -1, 0 );
2981
2982   QString         nbSelected = QtxPopupMgr::Selection::defSelCountParam();
2983   QString only_one_non_empty = QString( " && %1=1 && numberOfNodes>0" ).arg( nbSelected );
2984
2985   createPopupItem( 125, OB, mesh, only_one_non_empty );   // EXPORT_MED
2986   createPopupItem( 126, OB, mesh, only_one_non_empty );   // EXPORT_UNV
2987   createPopupItem( 141, OB, mesh, only_one_non_empty );   // EXPORT_STL
2988   //createPopupItem( 33, OB, subMesh + " " + group );       // DELETE
2989   createPopupItem(  33, OB, mesh_group + " " + hyp_alg ); // DELETE
2990   popupMgr()->insert( separator(), -1, 0 );
2991
2992   // popup for viewer
2993   createPopupItem( 803, View, group ); // EDIT_GROUP
2994   createPopupItem( 804, View, elems ); // ADD
2995   createPopupItem( 805, View, elems ); // REMOVE
2996   popupMgr()->insert( separator(), -1, 0 );
2997   createPopupItem( 214, View, mesh_group ); // UPDATE
2998   createPopupItem( 900, View, mesh_group ); // ADV_INFO
2999   createPopupItem( 902, View, mesh );       // STD_INFO
3000   createPopupItem( 903, View, mesh_group ); // WHAT_IS
3001   popupMgr()->insert( separator(), -1, 0 );
3002
3003   createPopupItem( 1136, OB + " " + View, mesh, "&& (not isAutoColor)" ); // AUTO_COLOR
3004   createPopupItem( 1137, OB + " " + View, mesh, "&& isAutoColor" );       // DISABLE_AUTO_COLOR
3005   popupMgr()->insert( separator(), -1, 0 );
3006
3007   int anId;
3008   QString
3009     isInvisible("not( isVisible )"),
3010     isEmpty("numberOfNodes = 0"),
3011     isNotEmpty("numberOfNodes <> 0"),
3012
3013     // has nodes, edges, etc in VISIBLE! actor
3014     hasNodes("(numberOfNodes > 0 )"),//&& isVisible)"),
3015     hasElems("(count( elemTypes ) > 0)"),
3016     hasDifferentElems("(count( elemTypes ) > 1)"),
3017     hasEdges("({'Edge'} in elemTypes)"),
3018     hasFaces("({'Face'} in elemTypes)"),
3019     hasVolumes("({'Volume'} in elemTypes)");
3020
3021   QString lc = QtxPopupMgr::Selection::defEquality();
3022   QString aClient = QString( "%1client in {%2}" ).arg( lc ).arg( "'VTKViewer'" );
3023   QString aType = QString( "%1type in {%2}" ).arg( QtxPopupMgr::Selection::defEquality() );
3024   aType = aType.arg( mesh_group );
3025   QString aMeshInVTK = aClient + "&&" + aType;
3026
3027   aClient = "($client in {'VTKViewer' 'ObjectBrowser'})";
3028   QString anActiveVTK = QString("activeView = '%1'").arg(SVTK_Viewer::Type());
3029   QString aSelCount = QString( "%1 > 0" ).arg( QtxPopupMgr::Selection::defSelCountParam() );
3030
3031   //-------------------------------------------------
3032   // Numbering
3033   //-------------------------------------------------
3034   anId = popupMgr()->insert( tr( "MEN_NUM" ), -1, -1 );
3035
3036   popupMgr()->insert( action( 9010 ), anId, -1 );
3037   popupMgr()->setRule( action( 9010 ), aMeshInVTK + "&& isVisible &&" + hasNodes, true );
3038   popupMgr()->setRule( action( 9010 ), "{'Point'} in labeledTypes", false );
3039
3040   popupMgr()->insert( action( 9011 ), anId, -1 );
3041   popupMgr()->setRule( action( 9011 ), aMeshInVTK + "&& isVisible &&" + hasElems, true );
3042   popupMgr()->setRule( action( 9011 ), "{'Cell'} in labeledTypes", false );
3043
3044   popupMgr()->insert( separator(), -1, -1 );
3045
3046   //-------------------------------------------------
3047   // Display Mode
3048   //-------------------------------------------------
3049   anId = popupMgr()->insert( tr( "MEN_DISPMODE" ), -1, -1 );
3050
3051   popupMgr()->insert( action( 211 ), anId, -1 ); // WIRE
3052   popupMgr()->setRule( action( 211 ), aMeshInVTK + "&&" + hasElems, true );
3053   popupMgr()->setRule( action( 211 ), "displayMode = 'eEdge'", false );
3054
3055   popupMgr()->insert( action( 212 ), anId, -1 ); // SHADE
3056   popupMgr()->setRule( action( 212 ),aMeshInVTK+ "&& (" + hasFaces + "||" + hasVolumes + ")",true);
3057   popupMgr()->setRule( action( 212 ), "displayMode = 'eSurface'", false );
3058
3059   popupMgr()->insert( action( 215 ), anId, -1 ); // POINTS
3060   popupMgr()->setRule( action( 215 ), aMeshInVTK + "&&" + hasNodes, true );
3061   popupMgr()->setRule( action( 215 ), "displayMode = 'ePoint'", false );
3062
3063   popupMgr()->insert( separator(), anId, -1 );
3064
3065   popupMgr()->insert( action( 213 ), anId, -1 ); // SHRINK
3066   popupMgr()->setRule( action( 213 ), aMeshInVTK + "&& shrinkMode <> 'IsNotShrinkable' && displayMode <> 'ePoint'",true);
3067   popupMgr()->setRule( action( 213 ), "shrinkMode = 'IsShrunk'", false );
3068
3069   //-------------------------------------------------
3070   // Display Entity
3071   //-------------------------------------------------
3072   QString aDiffElemsInVTK = aMeshInVTK + "&&" + hasDifferentElems;
3073
3074   anId = popupMgr()->insert( tr( "MEN_DISP_ENT" ), -1, -1 );
3075
3076   popupMgr()->insert( action( 217 ), anId, -1 ); // EDGES
3077   popupMgr()->setRule( action( 217 ), aDiffElemsInVTK + "&& isVisible &&" + hasEdges, true );
3078   popupMgr()->setRule( action( 217 ), "{'Edge'} in entityMode", false );
3079
3080   popupMgr()->insert( action( 218 ), anId, -1 ); // FACES
3081   popupMgr()->setRule( action( 218 ), aDiffElemsInVTK + "&& isVisible &&" + hasFaces, true );
3082   popupMgr()->setRule( action( 218 ), "{'Face'} in entityMode", false );
3083
3084   popupMgr()->insert( action( 219 ), anId, -1 ); // VOLUMES
3085   popupMgr()->setRule( action( 219 ), aDiffElemsInVTK + "&& isVisible &&" + hasVolumes, true );
3086   popupMgr()->setRule( action( 219 ), "{'Volume'} in entityMode", false );
3087
3088   popupMgr()->insert( separator(), anId, -1 );
3089
3090   popupMgr()->insert( action( 220 ), anId, -1 ); // ALL
3091   popupMgr()->setRule( action( 220 ), aDiffElemsInVTK + "&& isVisible && not( elemTypes in entityMode )", true );
3092
3093   //-------------------------------------------------
3094   // Color / Size
3095   //-------------------------------------------------
3096   popupMgr()->insert( action( 1132 ), -1, -1 );
3097   popupMgr()->setRule( action( 1132 ), aMeshInVTK + "&& isVisible", true );
3098
3099   //-------------------------------------------------
3100   // Transparency
3101   //-------------------------------------------------
3102   popupMgr()->insert( action( 1133 ), -1, -1 );
3103   popupMgr()->setRule( action( 1133 ), aMeshInVTK + "&& isVisible", true );
3104
3105   //-------------------------------------------------
3106   // Clipping
3107   //-------------------------------------------------
3108   popupMgr()->insert( action( 1134 ), -1, -1 );
3109   popupMgr()->setRule( action( 1134 ), aMeshInVTK + "&& isVisible", true );
3110
3111   popupMgr()->insert( separator(), -1, -1 );
3112
3113   //-------------------------------------------------
3114   // Controls
3115   //-------------------------------------------------
3116   QString
3117     aMeshInVtkHasEdges = aMeshInVTK + "&&" + hasEdges,
3118     aMeshInVtkHasFaces = aMeshInVTK + "&&" + hasFaces,
3119     aMeshInVtkHasVolumes = aMeshInVTK + "&&" + hasVolumes;
3120
3121   anId = popupMgr()->insert( tr( "MEN_CTRL" ), -1, -1 );
3122
3123   popupMgr()->insert( action( 200 ), anId, -1 ); // RESET
3124   popupMgr()->setRule( action( 200 ), aMeshInVTK + "&& controlMode <> 'eNone'", true );
3125
3126   popupMgr()->insert( separator(), anId, -1 );
3127
3128   popupMgr()->insert( action( 6003 ), anId, -1 ); // FREE_BORDER
3129   popupMgr()->setRule( action( 6003 ), aMeshInVtkHasEdges, true );
3130   popupMgr()->setRule( action( 6003 ), "controlMode = 'eFreeBorders'", false );
3131
3132   popupMgr()->insert( action( 6001 ), anId, -1 ); // LENGTH
3133   popupMgr()->setRule( action( 6001 ), aMeshInVtkHasEdges, true );
3134   popupMgr()->setRule( action( 6001 ), "controlMode = 'eLength'", false );
3135
3136   popupMgr()->insert( action( 6004 ), anId, -1 ); // CONNECTION
3137   popupMgr()->setRule( action( 6004 ), aMeshInVtkHasEdges, true );
3138   popupMgr()->setRule( action( 6004 ), "controlMode = 'eMultiConnection'", false );
3139
3140   popupMgr()->insert( separator(), anId, -1 );
3141
3142   popupMgr()->insert( action( 6002 ), anId, -1 ); // FREE_EDGE
3143   popupMgr()->setRule( action( 6002 ), aMeshInVtkHasFaces, true );
3144   popupMgr()->setRule( action( 6002 ), "controlMode = 'eFreeEdges'", false );
3145
3146   popupMgr()->insert( action( 6018 ), anId, -1 ); // LENGTH_2D
3147   popupMgr()->setRule( action( 6018 ), aMeshInVtkHasFaces, true );
3148   popupMgr()->setRule( action( 6018 ), "controlMode = 'eLength2D'", false );
3149
3150   popupMgr()->insert( action( 6019 ), anId, -1 ); // CONNECTION_2D
3151   popupMgr()->setRule( action( 6019 ), aMeshInVtkHasFaces, true );
3152   popupMgr()->setRule( action( 6019 ), "controlMode = 'eMultiConnection2D'", false );
3153
3154   popupMgr()->insert( action( 6011 ), anId, -1 ); // AREA
3155   popupMgr()->setRule( action( 6011 ), aMeshInVtkHasFaces, true );
3156   popupMgr()->setRule( action( 6011 ), "controlMode = 'eArea'", false );
3157
3158   popupMgr()->insert( action( 6012 ), anId, -1 ); // TAPER
3159   popupMgr()->setRule( action( 6012 ), aMeshInVtkHasFaces, true );
3160   popupMgr()->setRule( action( 6012 ), "controlMode = 'eTaper'", false );
3161
3162   popupMgr()->insert( action( 6013 ), anId, -1 ); // ASPECT
3163   popupMgr()->setRule( action( 6013 ), aMeshInVtkHasFaces, true );
3164   popupMgr()->setRule( action( 6013 ), "controlMode = 'eAspectRatio'", false );
3165
3166   popupMgr()->insert( action( 6014 ), anId, -1 ); // MIN_ANG
3167   popupMgr()->setRule( action( 6014 ), aMeshInVtkHasFaces, true );
3168   popupMgr()->setRule( action( 6014 ), "controlMode = 'eMinimumAngle'", false );
3169
3170   popupMgr()->insert( action( 6015 ), anId, -1 ); // WARP
3171   popupMgr()->setRule( action( 6015 ), aMeshInVtkHasFaces, true );
3172   popupMgr()->setRule( action( 6015 ), "controlMode = 'eWarping'", false );
3173
3174   popupMgr()->insert( action( 6016 ), anId, -1 ); // SKEW
3175   popupMgr()->setRule( action( 6016 ), aMeshInVtkHasFaces, true );
3176   popupMgr()->setRule( action( 6016 ), "controlMode = 'eSkew'", false );
3177
3178   popupMgr()->insert( separator(), anId, -1 );
3179
3180   popupMgr()->insert( action( 6017 ), anId, -1 ); // ASPECT_3D
3181   popupMgr()->setRule( action( 6017 ), aMeshInVtkHasVolumes, true );
3182   popupMgr()->setRule( action( 6017 ), "controlMode = 'eAspectRatio3D'", false );
3183
3184   popupMgr()->insert ( action( 6009 ), anId, -1 ); // VOLUME_3D
3185   popupMgr()->setRule( action( 6009 ), aMeshInVtkHasVolumes, true );
3186   popupMgr()->setRule( action( 6009 ), "controlMode = 'eVolume3D'", false );
3187
3188   popupMgr()->insert( separator(), anId, -1 );
3189
3190   popupMgr()->insert( action( 201 ), anId, -1 ); // SCALAR_BAR_PROP
3191   popupMgr()->setRule( action( 201 ), aMeshInVTK + "&& controlMode <> 'eNone'", true );
3192
3193   popupMgr()->insert( separator(), -1, -1 );
3194
3195   //-------------------------------------------------
3196   // Display / Erase
3197   //-------------------------------------------------
3198   QString aRule = "$component={'SMESH'} and ( type='Component' or (" + aClient + " and " +
3199     aType + " and " + aSelCount + " and " + anActiveVTK + " and " + isNotEmpty + " %1 ) )";
3200   popupMgr()->insert( action( 301 ), -1, -1 ); // DISPLAY
3201   popupMgr()->setRule( action( 301 ), aRule.arg( "and (not isVisible)" ), true);
3202
3203   popupMgr()->insert( action( 300 ), -1, -1 ); // ERASE
3204   popupMgr()->setRule( action( 300 ), aRule.arg( "and isVisible" ), true );
3205
3206   popupMgr()->insert( action( 302 ), -1, -1 ); // DISPLAY_ONLY
3207   popupMgr()->setRule( action( 302 ), aRule.arg( "" ), true );
3208
3209   popupMgr()->insert( separator(), -1, -1 );
3210
3211   connect( application(), SIGNAL( viewManagerActivated( SUIT_ViewManager* ) ),
3212            this, SLOT( onViewManagerActivated( SUIT_ViewManager* ) ) );
3213 }
3214
3215 //================================================================================
3216 /*!
3217  * \brief Return true if SMESH or GEOM objects are selected.
3218  * Is called form LightApp_Module::activateModule() which clear selection if
3219  * not isSelectionCompatible()
3220  */
3221 //================================================================================
3222
3223 bool SMESHGUI::isSelectionCompatible()
3224 {
3225   bool isCompatible = true;
3226   SALOME_ListIO selected;
3227   if ( LightApp_SelectionMgr *Sel = selectionMgr() )
3228     Sel->selectedObjects( selected );
3229
3230   SALOME_ListIteratorOfListIO It( selected );
3231   for ( ; isCompatible && It.More(); It.Next())
3232     isCompatible =
3233       ( strcmp("GEOM", It.Value()->getComponentDataType()) == 0 ) ||
3234       ( strcmp("SMESH", It.Value()->getComponentDataType()) == 0 );
3235
3236   return isCompatible;
3237 }
3238
3239 bool SMESHGUI::activateModule( SUIT_Study* study )
3240 {
3241   bool res = SalomeApp_Module::activateModule( study );
3242
3243   setMenuShown( true );
3244   setToolShown( true );
3245
3246   // Reset actions accelerator keys
3247   action(111)->setAccel(QKeySequence(CTRL + Key_B)); // Import DAT
3248   action(112)->setAccel(QKeySequence(CTRL + Key_U)); // Import UNV
3249   action(113)->setAccel(QKeySequence(CTRL + Key_M)); // Import MED
3250
3251   action(  33)->setEnabled(true); // Delete: Key_Delete
3252   action(1101)->setEnabled(true); // Rename: Key_F2
3253
3254   return res;
3255 }
3256
3257 bool SMESHGUI::deactivateModule( SUIT_Study* study )
3258 {
3259   setMenuShown( false );
3260   setToolShown( false );
3261
3262   EmitSignalCloseAllDialogs();
3263
3264   // Unset actions accelerator keys
3265   action(111)->setAccel(QKeySequence()); // Import DAT
3266   action(112)->setAccel(QKeySequence()); // Import UNV
3267   action(113)->setAccel(QKeySequence()); // Import MED
3268
3269   action(  33)->setEnabled(false); // Delete: Key_Delete
3270   action(1101)->setEnabled(false); // Rename: Key_F2
3271
3272   return SalomeApp_Module::deactivateModule( study );
3273 }
3274
3275 void SMESHGUI::studyClosed( SUIT_Study* s )
3276 {
3277   SMESH::RemoveVisuData( s->id() );
3278   SalomeApp_Module::studyClosed( s );
3279 }
3280
3281 void SMESHGUI::OnGUIEvent()
3282 {
3283   const QObject* obj = sender();
3284   if ( !obj || !obj->inherits( "QAction" ) )
3285     return;
3286   int id = actionId((QAction*)obj);
3287   if ( id != -1 )
3288     OnGUIEvent( id );
3289 }
3290
3291 SMESH::SMESH_Gen_var SMESHGUI::GetSMESHGen()
3292 {
3293   _PTR(Study) aStudy = SMESH::GetActiveStudyDocument(); //Document OCAF de l'etude active
3294   if ( CORBA::is_nil( myComponentSMESH ) )
3295     {
3296       SMESHGUI aGUI; //SRN BugID: IPAL9186: Create an instance of SMESHGUI to initialize myComponentSMESH
3297       if ( aStudy )
3298         aGUI.myComponentSMESH->SetCurrentStudy(_CAST(Study,aStudy)->GetStudy());
3299       return aGUI.myComponentSMESH;
3300     }
3301   if ( aStudy )
3302     myComponentSMESH->SetCurrentStudy(_CAST(Study,aStudy)->GetStudy());
3303   return myComponentSMESH;
3304 }
3305
3306 QString SMESHGUI::engineIOR() const
3307 {
3308   CORBA::ORB_var anORB = getApp()->orb();
3309   CORBA::String_var anIOR = anORB->object_to_string(GetSMESHGen());
3310   return QString( anIOR.in() );
3311 }
3312
3313 void SMESHGUI::contextMenuPopup( const QString& client, QPopupMenu* menu, QString& title )
3314 {
3315   SMESHGUI_Selection sel;
3316   sel.init( client, selectionMgr() );
3317   popupMgr()->updatePopup( menu, &sel );
3318
3319   SALOME_ListIO lst;
3320   selectionMgr()->selectedObjects( lst );
3321   if ( ( client == "OCCViewer" || client == "VTKViewer" ) && lst.Extent() == 1 ) {
3322     Handle(SALOME_InteractiveObject) io = lst.First();
3323     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( application()->activeStudy() );
3324     _PTR(Study) study = appStudy->studyDS();
3325     _PTR(SObject) obj = study->FindObjectID( io->getEntry() );
3326     if ( obj ) {
3327       QString aName = QString( obj->GetName().c_str() );
3328       while ( aName.at( aName.length() - 1 ) == ' ' ) // Remove extraspaces in Name of Popup
3329           aName.remove( (aName.length() - 1), 1 );
3330       title = aName;
3331     }
3332   }
3333 }
3334
3335 void SMESHGUI::windows( QMap<int, int>& aMap ) const
3336 {
3337   aMap.insert( SalomeApp_Application::WT_ObjectBrowser, Qt::DockLeft );
3338   aMap.insert( SalomeApp_Application::WT_PyConsole, Qt::DockBottom );
3339 }
3340
3341 void SMESHGUI::viewManagers( QStringList& list ) const
3342 {
3343   list.append( SVTK_Viewer::Type() );
3344 }
3345
3346 void SMESHGUI::onViewManagerActivated( SUIT_ViewManager* mgr )
3347 {
3348   if ( dynamic_cast<SVTK_ViewManager*>( mgr ) )
3349     SMESH::UpdateSelectionProp( this );
3350 }
3351
3352 void SMESHGUI::createPreferences()
3353 {
3354   int genTab = addPreference( tr( "PREF_TAB_GENERAL" ) );
3355
3356   int updateGroup = addPreference( tr( "PREF_GROUP_UPDATE" ), genTab );
3357   addPreference( tr( "PREF_AUTO_UPDATE" ), updateGroup, LightApp_Preferences::Bool, "SMESH", "auto_update" );
3358
3359   int qaGroup = addPreference( tr( "PREF_GROUP_QUALITY" ), genTab );
3360   addPreference( tr( "PREF_DISPLAY_ENTITY" ), qaGroup, LightApp_Preferences::Bool, "SMESH", "display_entity" );
3361   addPreference( tr( "PREF_PRECISION_USE" ), qaGroup, LightApp_Preferences::Bool, "SMESH", "use_precision" );
3362
3363   int precGroup = addPreference( tr( "PREF_GROUP_PRECISION" ), genTab );
3364   setPreferenceProperty( precGroup, "columns", 1 );
3365
3366   int prec = addPreference( tr( "PREF_PRECISION_VALUE" ), precGroup, LightApp_Preferences::IntSpin, "SMESH", "controls_precision" );
3367
3368   setPreferenceProperty( prec, "min", 0 );
3369   setPreferenceProperty( prec, "max", 16 );
3370
3371   int dispgroup = addPreference( tr( "PREF_DISPLAY_MODE" ), genTab );
3372   int dispmode = addPreference( tr( "PREF_DISPLAY_MODE" ), dispgroup, LightApp_Preferences::Selector, "SMESH", "display_mode" );
3373   QStringList modes;
3374   modes.append( "Wireframe" );
3375   modes.append( "Shading" );
3376   modes.append( "Nodes" );
3377   modes.append( "Shrink" );
3378   QValueList<QVariant> indices;
3379   indices.append( 0 );
3380   indices.append( 1 );
3381   indices.append( 2 );
3382   indices.append( 3 );
3383   setPreferenceProperty( dispmode, "strings", modes );
3384   setPreferenceProperty( dispmode, "indexes", indices );
3385
3386   int exportgroup = addPreference( tr( "PREF_GROUP_EXPORT" ), genTab );
3387   addPreference( tr( "PREF_AUTO_GROUPS" ), exportgroup, LightApp_Preferences::Bool, "SMESH", "auto_groups" );
3388   addPreference( tr( "PREF_RENUMBER" ), exportgroup, LightApp_Preferences::Bool, "SMESH", "renumbering" );
3389
3390   int meshTab = addPreference( tr( "PREF_TAB_MESH" ) );
3391   int nodeGroup = addPreference( tr( "PREF_GROUP_NODES" ), meshTab );
3392
3393   addPreference( tr( "PREF_COLOR" ), nodeGroup, LightApp_Preferences::Color, "SMESH", "node_color" );
3394   int nodeSz = addPreference( tr( "PREF_SIZE" ), nodeGroup, LightApp_Preferences::IntSpin, "SMESH", "node_size" );
3395
3396   setPreferenceProperty( nodeSz, "min", 1 );
3397   setPreferenceProperty( nodeSz, "max", 5 );
3398
3399   int elemGroup = addPreference( tr( "PREF_GROUP_ELEMENTS" ), meshTab );
3400
3401   addPreference( tr( "PREF_FILL" ), elemGroup, LightApp_Preferences::Color, "SMESH", "fill_color" );
3402   addPreference( tr( "PREF_OUTLINE" ), elemGroup, LightApp_Preferences::Color, "SMESH", "outline_color" );
3403   addPreference( tr( "PREF_BACKFACE" ), elemGroup, LightApp_Preferences::Color, "SMESH", "backface_color" );
3404   addPreference( "", elemGroup, LightApp_Preferences::Space );
3405
3406   int elemW = addPreference( tr( "PREF_WIDTH" ), elemGroup, LightApp_Preferences::IntSpin, "SMESH", "element_width" );
3407   int shrink = addPreference( tr( "PREF_SHRINK_COEFF" ), elemGroup, LightApp_Preferences::IntSpin, "SMESH", "shrink_coeff" );
3408
3409   setPreferenceProperty( elemW, "min", 1 );
3410   setPreferenceProperty( elemW, "max", 5 );
3411
3412   setPreferenceProperty( shrink, "min", 0 );
3413   setPreferenceProperty( shrink, "max", 100 );
3414
3415   int selTab = addPreference( tr( "PREF_TAB_SELECTION" ) );
3416
3417   int selGroup = addPreference( tr( "PREF_GROUP_SELECTION" ), selTab );
3418
3419   addPreference( tr( "PREF_OBJECT_COLOR" ), selGroup, LightApp_Preferences::Color, "SMESH", "selection_object_color" );
3420   addPreference( tr( "PREF_ELEMENT_COLOR" ), selGroup, LightApp_Preferences::Color, "SMESH", "selection_element_color" );
3421   int selW = addPreference( tr( "PREF_WIDTH" ), selGroup, LightApp_Preferences::IntSpin, "SMESH", "selection_width" );
3422
3423   setPreferenceProperty( selW, "min", 1 );
3424   setPreferenceProperty( selW, "max", 5 );
3425
3426   int preGroup = addPreference( tr( "PREF_GROUP_PRESELECTION" ), selTab );
3427
3428   addPreference( tr( "PREF_HIGHLIGHT_COLOR" ), preGroup, LightApp_Preferences::Color, "SMESH", "highlight_color" );
3429   int preW = addPreference( tr( "PREF_WIDTH" ), preGroup, LightApp_Preferences::IntSpin, "SMESH", "highlight_width" );
3430
3431   setPreferenceProperty( preW, "min", 1 );
3432   setPreferenceProperty( preW, "max", 5 );
3433
3434   int precSelGroup = addPreference( tr( "PREF_GROUP_PRECISION" ), selTab );
3435
3436   addPreference( tr( "PREF_NODES" ), precSelGroup, LightApp_Preferences::Double, "SMESH", "selection_precision_node" );
3437   addPreference( tr( "PREF_ELEMENTS" ), precSelGroup, LightApp_Preferences::Double, "SMESH", "selection_precision_element" );
3438   addPreference( tr( "PREF_OBJECTS" ), precSelGroup, LightApp_Preferences::Double, "SMESH", "selection_precision_object" );
3439
3440   int sbarTab = addPreference( tr( "SMESH_SCALARBAR" ) );
3441   int fontGr = addPreference( tr( "SMESH_FONT_SCALARBAR" ), sbarTab );
3442
3443   int tfont = addPreference( tr( "SMESH_TITLE" ), fontGr, LightApp_Preferences::Font, "SMESH", "scalar_bar_title_font" );
3444   addPreference( tr( "PREF_TITLE_COLOR" ), fontGr, LightApp_Preferences::Color, "SMESH", "scalar_bar_title_color" );
3445   int lfont = addPreference( tr( "SMESH_LABELS" ), fontGr, LightApp_Preferences::Font, "SMESH", "scalar_bar_label_font" );
3446   addPreference( tr( "PREF_LABELS_COLOR" ), fontGr, LightApp_Preferences::Color, "SMESH", "scalar_bar_label_color" );
3447
3448   QStringList fam;
3449   fam.append( tr( "SMESH_FONT_ARIAL" ) );
3450   fam.append( tr( "SMESH_FONT_COURIER" ) );
3451   fam.append( tr( "SMESH_FONT_TIMES" ) );
3452   int wflag = ( QtxListResourceEdit::FontItem::All & ( ~( QtxListResourceEdit::FontItem::Size | QtxListResourceEdit::FontItem::UserSize ) ) );
3453
3454   setPreferenceProperty( tfont, "families", fam );
3455   setPreferenceProperty( tfont, "system", false );
3456   setPreferenceProperty( tfont, "widget_flags", wflag );
3457   setPreferenceProperty( lfont, "families", fam );
3458   setPreferenceProperty( lfont, "system", false );
3459   setPreferenceProperty( lfont, "widget_flags", wflag );
3460
3461   int colorsLabelsGr = addPreference( tr( "SMESH_LABELS_COLORS_SCALARBAR" ), sbarTab );
3462
3463   int numcol = addPreference( tr( "SMESH_NUMBEROFCOLORS" ), colorsLabelsGr, LightApp_Preferences::IntSpin, "SMESH", "scalar_bar_num_colors" );
3464   setPreferenceProperty( numcol, "min", 2 );
3465   setPreferenceProperty( numcol, "max", 256 );
3466
3467   int numlab = addPreference( tr( "SMESH_NUMBEROFLABELS" ), colorsLabelsGr, LightApp_Preferences::IntSpin, "SMESH", "scalar_bar_num_labels" );
3468   setPreferenceProperty( numlab, "min", 2 );
3469   setPreferenceProperty( numlab, "max", 65 );
3470
3471   int orientGr = addPreference( tr( "SMESH_ORIENTATION" ), sbarTab );
3472   int orient = addPreference( tr( "SMESH_ORIENTATION" ), orientGr, LightApp_Preferences::Selector, "SMESH", "scalar_bar_orientation" );
3473   QStringList orients;
3474   orients.append( tr( "SMESH_VERTICAL" ) );
3475   orients.append( tr( "SMESH_HORIZONTAL" ) );
3476   indices.clear(); indices.append( 0 ); indices.append( 1 );
3477   setPreferenceProperty( orient, "strings", orients );
3478   setPreferenceProperty( orient, "indexes", indices );
3479
3480   int posVSizeGr = addPreference( tr( "SMESH_POSITION_SIZE_SCALARBAR" ) + " " + tr( "SMESH_VERTICAL" ), sbarTab );
3481   int xv = addPreference( tr( "SMESH_X_SCALARBAR" ), posVSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_vertical_x" );
3482   int yv = addPreference( tr( "SMESH_Y_SCALARBAR" ), posVSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_vertical_y" );
3483   int wv = addPreference( tr( "SMESH_WIDTH" ), posVSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_vertical_width" );
3484   int hv = addPreference( tr( "SMESH_HEIGHT" ), posVSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_vertical_height" );
3485   setPreferenceProperty( xv, "step", 0.1 );
3486   setPreferenceProperty( xv, "min", 0.0 );
3487   setPreferenceProperty( xv, "max", 1.0 );
3488   setPreferenceProperty( yv, "step", 0.1 );
3489   setPreferenceProperty( yv, "min", 0.0 );
3490   setPreferenceProperty( yv, "max", 1.0 );
3491   setPreferenceProperty( wv, "step", 0.1 );
3492   setPreferenceProperty( wv, "min", 0.0 );
3493   setPreferenceProperty( wv, "max", 1.0 );
3494   setPreferenceProperty( hv, "min", 0.0 );
3495   setPreferenceProperty( hv, "max", 1.0 );
3496   setPreferenceProperty( hv, "step", 0.1 );
3497
3498   int posHSizeGr = addPreference( tr( "SMESH_POSITION_SIZE_SCALARBAR" ) + " " + tr( "SMESH_HORIZONTAL" ), sbarTab );
3499   int xh = addPreference( tr( "SMESH_X_SCALARBAR" ), posHSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_horizontal_x" );
3500   int yh = addPreference( tr( "SMESH_Y_SCALARBAR" ), posHSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_horizontal_y" );
3501   int wh = addPreference( tr( "SMESH_WIDTH" ), posHSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_horizontal_width" );
3502   int hh = addPreference( tr( "SMESH_HEIGHT" ), posHSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_horizontal_height" );
3503   setPreferenceProperty( xv, "min", 0.0 );
3504   setPreferenceProperty( xv, "max", 1.0 );
3505   setPreferenceProperty( xv, "step", 0.1 );
3506   setPreferenceProperty( xh, "min", 0.0 );
3507   setPreferenceProperty( xh, "max", 1.0 );
3508   setPreferenceProperty( xh, "step", 0.1 );
3509   setPreferenceProperty( yh, "min", 0.0 );
3510   setPreferenceProperty( yh, "max", 1.0 );
3511   setPreferenceProperty( yh, "step", 0.1 );
3512   setPreferenceProperty( wh, "min", 0.0 );
3513   setPreferenceProperty( wh, "max", 1.0 );
3514   setPreferenceProperty( wh, "step", 0.1 );
3515   setPreferenceProperty( hh, "min", 0.0 );
3516   setPreferenceProperty( hh, "max", 1.0 );
3517   setPreferenceProperty( hh, "step", 0.1 );
3518 }
3519
3520 void SMESHGUI::preferencesChanged( const QString& sect, const QString& name )
3521 {
3522   if( sect=="SMESH" ){
3523     float sbX1,sbY1,sbW,sbH;
3524     float aTol = 1.00000009999999;
3525     std::string aWarning;
3526     SUIT_ResourceMgr* aResourceMgr = SMESH::GetResourceMgr(this);
3527     if( name=="selection_object_color" || name=="selection_element_color" ||
3528         name=="selection_width" || name=="highlight_color" || name=="highlight_width" ||
3529         name=="selection_precision_node" || name=="selection_precision_element" ||
3530         name=="selection_precision_object")
3531       SMESH::UpdateSelectionProp( this );
3532     else if (name == QString("scalar_bar_vertical_x") || name == QString("scalar_bar_vertical_width")){
3533       sbX1 = aResourceMgr->doubleValue("SMESH", "scalar_bar_vertical_x", sbX1);
3534       sbW = aResourceMgr->doubleValue("SMESH", "scalar_bar_vertical_width", sbW);
3535       if(sbX1+sbW > aTol){
3536         aWarning = "Origin and Size Vertical: X+Width > 1\n";
3537         sbX1=0.01;
3538         sbW=0.05;
3539         aResourceMgr->setValue("SMESH", "scalar_bar_vertical_x", sbX1);
3540         aResourceMgr->setValue("SMESH", "scalar_bar_vertical_width", sbW);
3541       }
3542     }
3543     else if(name == QString("scalar_bar_vertical_y") || name == QString("scalar_bar_vertical_height")){
3544       sbY1 = aResourceMgr->doubleValue("SMESH", "scalar_bar_vertical_y", sbY1);
3545       sbH = aResourceMgr->doubleValue("SMESH", "scalar_bar_vertical_height",sbH);
3546       if(sbY1+sbH > aTol){
3547         aWarning = "Origin and Size Vertical: Y+Height > 1\n";
3548         aResourceMgr->setValue("SMESH", "scalar_bar_vertical_y", sbY1);
3549         aResourceMgr->setValue("SMESH", "scalar_bar_vertical_height",sbH);
3550       }
3551     }
3552     else if(name ==  QString("scalar_bar_horizontal_x") || name ==  QString("scalar_bar_horizontal_width")){
3553       sbX1 = aResourceMgr->doubleValue("SMESH", "scalar_bar_horizontal_x", sbX1);
3554       sbW = aResourceMgr->doubleValue("SMESH", "scalar_bar_horizontal_width", sbW);
3555       if(sbX1+sbW > aTol){
3556         aWarning = "Origin and Size Horizontal: X+Width > 1\n";
3557         sbX1=0.01;
3558         sbW=0.05;
3559         aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_x", sbX1);
3560         aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_width", sbW);
3561       }
3562     }
3563     else if(name ==  QString("scalar_bar_horizontal_y") || name ==  QString("scalar_bar_horizontal_height")){
3564       sbY1 = aResourceMgr->doubleValue("SMESH", "scalar_bar_horizontal_y", sbY1);
3565       sbH = aResourceMgr->doubleValue("SMESH", "scalar_bar_horizontal_height",sbH);
3566       if(sbY1+sbH > aTol){
3567         aWarning = "Origin and Size Horizontal: Y+Height > 1\n";
3568         sbY1=0.01;
3569         sbH=0.05;
3570         aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_y", sbY1);
3571         aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_height",sbH);
3572       }
3573     }
3574
3575     if(aWarning.size() != 0){
3576       aWarning += "The default values are applied instead.";
3577       SUIT_MessageBox::warn1(SMESHGUI::desktop(),
3578                              QObject::tr("SMESH_ERR_SCALARBAR_PARAMS"),
3579                              QObject::tr(aWarning.c_str()),
3580                              QObject::tr("SMESH_BUT_OK"));
3581     }
3582   }
3583 }
3584
3585 //================================================================================
3586 /*!
3587  * \brief Update something in accordance with update flags
3588   * \param theFlags - update flags
3589 *
3590 * Update viewer or/and object browser etc. in accordance with update flags ( see
3591 * LightApp_UpdateFlags enumeration ).
3592 */
3593 //================================================================================
3594 void SMESHGUI::update( const int flags )
3595 {
3596   if ( flags & UF_Viewer | flags & UF_Forced )
3597     SMESH::UpdateView();
3598   else
3599     SalomeApp_Module::update( flags );
3600 }
3601
3602 //================================================================================
3603 /*!
3604  * \brief Set default selection mode
3605 *
3606 * SLOT called when operation commited. Sets default selection mode
3607 */
3608 //================================================================================
3609 void SMESHGUI::onOperationCommited( SUIT_Operation* )
3610 {
3611   SVTK_ViewWindow* vtkWnd =
3612     dynamic_cast<SVTK_ViewWindow*>( application()->desktop()->activeWindow() );
3613   if ( vtkWnd )
3614     vtkWnd->SetSelectionMode( ActorSelection );
3615 }
3616
3617 //================================================================================
3618 /*!
3619  * \brief Set default selection mode
3620 *
3621 * SLOT called when operation aborted. Sets default selection mode
3622 */
3623 //================================================================================
3624 void SMESHGUI::onOperationAborted( SUIT_Operation* )
3625 {
3626   SVTK_ViewWindow* vtkWnd =
3627     dynamic_cast<SVTK_ViewWindow*>( application()->desktop()->activeWindow() );
3628   if ( vtkWnd )
3629     vtkWnd->SetSelectionMode( ActorSelection );
3630 }
3631
3632 //================================================================================
3633 /*!
3634  * \brief Creates operation with given identifier
3635   * \param id - identifier of operation to be started
3636   * \return Pointer on created operation or NULL if operation is not created
3637 *
3638 * Virtual method redefined from the base class creates operation with given id.
3639 * It is called called automatically from startOperation method of base class.
3640 */
3641 //================================================================================
3642 LightApp_Operation* SMESHGUI::createOperation( const int id ) const
3643 {
3644   LightApp_Operation* op = 0;
3645   // to do : create operation here
3646   switch( id )
3647   {
3648     case 701: // Compute mesh
3649       op = new SMESHGUI_ComputeOp();
3650     break;
3651     case 702: // Create mesh
3652       op = new SMESHGUI_MeshOp( true, true );
3653     break;
3654     case 703: // Create sub-mesh
3655       op = new SMESHGUI_MeshOp( true, false );
3656     break;
3657     case 704: // Edit mesh/sub-mesh
3658       op = new SMESHGUI_MeshOp( false );
3659     break;
3660     case 806: // Create group on geom
3661       op = new SMESHGUI_GroupOnShapeOp();
3662       break;
3663     case 417: //convert to quadratic
3664       op = new SMESHGUI_ConvToQuadOp();
3665     break;
3666     case 4067: // make mesh pass through point
3667       op = new SMESHGUI_MakeNodeAtPointOp();
3668       break;
3669     default:
3670     break;
3671   }
3672
3673   if( !op )
3674     op = SalomeApp_Module::createOperation( id );
3675   return op;
3676 }
3677
3678 //================================================================================
3679 /*!
3680  * \brief Stops current operations and starts a given one
3681   * \param id - The id of the operation to start
3682  */
3683 //================================================================================
3684
3685 void SMESHGUI::switchToOperation(int id)
3686 {
3687   if ( _PTR(Study) aStudy = SMESH::GetActiveStudyDocument() )
3688     activeStudy()->abortAllOperations();
3689   startOperation( id );
3690 }
3691
3692 LightApp_Displayer* SMESHGUI::displayer()
3693 {
3694   if( !myDisplayer )
3695     myDisplayer = new SMESHGUI_Displayer( getApp() );
3696   return myDisplayer;
3697 }
3698
3699 SALOMEDS::Color SMESHGUI::getUniqueColor( const QValueList<SALOMEDS::Color>& theReservedColors )
3700 {
3701   int aHue = -1;
3702   int aTolerance = 64;
3703   int anIterations = 0;
3704   int aPeriod = 5;
3705
3706   while( 1 )
3707   {
3708     anIterations++;
3709     if( anIterations % aPeriod == 0 )
3710     {
3711       aTolerance /= 2;
3712       if( aTolerance < 1 )
3713         break;
3714     }
3715     //cout << "Iteration N" << anIterations << " (tolerance=" << aTolerance << ")"<< endl;
3716
3717     aHue = (int)( 360.0 * rand() / RAND_MAX );
3718     //cout << "Hue = " << aHue << endl;
3719
3720     //cout << "Auto colors : ";
3721     bool ok = true;
3722     QValueList<SALOMEDS::Color>::const_iterator it = theReservedColors.constBegin();
3723     QValueList<SALOMEDS::Color>::const_iterator itEnd = theReservedColors.constEnd();
3724     for( ; it != itEnd; ++it )
3725     {
3726       SALOMEDS::Color anAutoColor = *it;
3727       QColor aQColor( (int)( anAutoColor.R * 255.0 ), (int)( anAutoColor.G * 255.0 ), (int)( anAutoColor.B * 255.0 ) );
3728
3729       int h, s, v;
3730       aQColor.getHsv( &h, &s, &v );
3731       //cout << h << " ";
3732       if( abs( h - aHue ) < aTolerance )
3733       {
3734         ok = false;
3735         //cout << "break (diff = " << abs( h - aHue ) << ")";
3736         break;
3737       }
3738     }
3739     //cout << endl;
3740
3741     if( ok )
3742       break;
3743   }
3744
3745   //cout << "Hue of the returned color = " << aHue << endl;
3746   QColor aColor;
3747   aColor.setHsv( aHue, 255, 255 );
3748
3749   SALOMEDS::Color aSColor;
3750   aSColor.R = (double)aColor.red() / 255.0;
3751   aSColor.G = (double)aColor.green() / 255.0;
3752   aSColor.B = (double)aColor.blue() / 255.0;
3753
3754   return aSColor;
3755 }