Salome HOME
4x, 5x : Selection with rectangle is impossible for mesh elements if Submesh or Group...
[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 aParentComponent = QString::null;
925     for( SALOME_ListIteratorOfListIO anIt( selected ); anIt.More(); anIt.Next() )
926     {
927       _PTR(SObject) aSO = aStudy->FindObjectID(anIt.Value()->getEntry());
928       if (aSO) {
929         // check if object is not reference
930         _PTR(SObject) refobj;
931         if ( !aSO->ReferencedObject( refobj ) )
932           objectCount++;
933       }
934
935       QString cur = anIt.Value()->getComponentDataType();
936       if( aParentComponent.isNull() )
937         aParentComponent = cur;
938       else if( !aParentComponent.isEmpty() && aParentComponent!=cur )
939         aParentComponent = "";
940     }
941
942     if ( objectCount == 0 )
943       return; // No Valid Objects Selected
944
945     if ( aParentComponent != SMESHGUI::GetSMESHGUI()->name() )  {
946       SUIT_MessageBox::warn1 ( SMESHGUI::desktop(),
947                               QObject::tr("ERR_ERROR"),
948                               QObject::tr("NON_SMESH_OBJECTS_SELECTED").arg( SMESHGUI::GetSMESHGUI()->moduleName() ),
949                               QObject::tr("BUT_OK") );
950       return;
951     }
952     // VSR 17/11/04: check if all objects selected belong to SMESH component <-- finish
953     if (SUIT_MessageBox::warn2
954         (SMESHGUI::desktop(),
955          QObject::tr("SMESH_WRN_WARNING"),
956          QObject::tr("SMESH_REALLY_DELETE"),
957          QObject::tr("SMESH_BUT_YES"), QObject::tr("SMESH_BUT_NO"), 1, 0, 0) != 1)
958       return;
959
960     SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
961     SUIT_ViewManager* vm = anApp->activeViewManager();
962     int nbSf = vm->getViewsCount();
963
964     SALOME_ListIteratorOfListIO It(selected);
965
966     aStudyBuilder->NewCommand();  // There is a transaction
967     for(; It.More(); It.Next()){ // loop on selected IO's
968       Handle(SALOME_InteractiveObject) IObject = It.Value();
969       if(IObject->hasEntry()) {
970         _PTR(SObject) aSO = aStudy->FindObjectID(IObject->getEntry());
971
972         // disable removal of "SMESH" component object
973         if(aSO->FindAttribute(anAttr, "AttributeIOR")){
974           anIOR = anAttr;
975           if ( !strcmp( (char*)anIOR->Value().c_str(), engineIOR().latin1() ) )
976             continue;
977         }
978
979         _PTR(SObject) refobj;
980         if ( aSO && aSO->ReferencedObject( refobj ) )
981           continue; // skip references 
982
983         // put the whole hierarchy of sub-objects of the selected SO into a list and
984         // then treat them all starting from the deepest objects (at list back)
985
986         list< _PTR(SObject) > listSO;
987         listSO.push_back( aSO );
988         list< _PTR(SObject) >::iterator itSO = listSO.begin();
989         for ( ; itSO != listSO.end(); ++itSO ) {
990           _PTR(ChildIterator) it = aStudy->NewChildIterator( *itSO );
991           for (it->InitEx(false); it->More(); it->Next())
992             listSO.push_back( it->Value() );
993         }
994
995         // treat SO's in the list starting from the back
996
997         list< _PTR(SObject) >::reverse_iterator ritSO = listSO.rbegin();
998         for ( ; ritSO != listSO.rend(); ++ritSO ) {
999           _PTR(SObject) SO = *ritSO;
1000           if ( !SO ) continue;
1001           string anEntry = SO->GetID();
1002
1003           /** Erase graphical object **/
1004           if(SO->FindAttribute(anAttr, "AttributeIOR")){
1005             QPtrVector<SUIT_ViewWindow> aViews = vm->getViews();
1006             for(int i = 0; i < nbSf; i++){
1007               SUIT_ViewWindow *sf = aViews[i];
1008               if(SMESH_Actor* anActor = SMESH::FindActorByEntry(sf,anEntry.c_str())){
1009                 SMESH::RemoveActor(sf,anActor);
1010               }
1011             }
1012           }
1013
1014           /** Remove an object from data structures **/
1015           SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow( SMESH::SObjectToObject( SO ));
1016           SMESH::SMESH_subMesh_var   aSubMesh = SMESH::SMESH_subMesh::_narrow( SMESH::SObjectToObject( SO ));
1017           if ( !aGroup->_is_nil() ) {                          // DELETE GROUP
1018             SMESH::SMESH_Mesh_var aMesh = aGroup->GetMesh();
1019             aMesh->RemoveGroup( aGroup );
1020           }
1021           else if ( !aSubMesh->_is_nil() ) {                   // DELETE SUBMESH
1022             SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
1023             aMesh->RemoveSubMesh( aSubMesh );
1024
1025             _PTR(SObject) aMeshSO = SMESH::FindSObject(aMesh);
1026             if (aMeshSO)
1027               SMESH::ModifiedMesh(aMeshSO, false, aMesh->NbNodes()==0);
1028           }
1029           else {
1030             IObject = new SALOME_InteractiveObject
1031               ( anEntry.c_str(), engineIOR().latin1(), SO->GetName().c_str() );
1032             QString objType = CheckTypeObject(IObject);
1033             if ( objType == "Hypothesis" || objType == "Algorithm" ) {// DELETE HYPOTHESIS
1034               SMESH::RemoveHypothesisOrAlgorithmOnMesh(IObject);
1035               aStudyBuilder->RemoveObjectWithChildren( SO );
1036             }
1037             else {// default action: remove SObject from the study
1038               // san - it's no use opening a transaction here until UNDO/REDO is provided in SMESH
1039               //SUIT_Operation *op = new SALOMEGUI_ImportOperation(myActiveStudy);
1040               //op->start();
1041               aStudyBuilder->RemoveObjectWithChildren( SO );
1042               //op->finish();
1043             }
1044           }
1045         } /* listSO back loop */
1046       } /* IObject->hasEntry() */
1047     } /* more/next */
1048     aStudyBuilder->CommitCommand();
1049
1050     /* Clear any previous selection */
1051     SALOME_ListIO l1;
1052     aSel->setSelectedObjects( l1 );
1053
1054     SMESHGUI::GetSMESHGUI()->updateObjBrowser();
1055   }
1056 //}
1057
1058 extern "C" {
1059   SMESHGUI_EXPORT CAM_Module* createModule()
1060   {
1061     return new SMESHGUI();
1062   }
1063 }
1064
1065 SMESH::SMESH_Gen_var SMESHGUI::myComponentSMESH = SMESH::SMESH_Gen::_nil();
1066
1067 //=============================================================================
1068 /*!
1069  *
1070  */
1071 //=============================================================================
1072 SMESHGUI::SMESHGUI() :
1073 SalomeApp_Module( "SMESH" )
1074 {
1075   if ( CORBA::is_nil( myComponentSMESH ) )
1076   {
1077     CORBA::Boolean anIsEmbeddedMode;
1078     myComponentSMESH = SMESH_Client::GetSMESHGen(getApp()->orb(),anIsEmbeddedMode);
1079   }
1080
1081   myActiveDialogBox = 0;
1082   myFilterLibraryDlg = 0;
1083   myState = -1;
1084   myDisplayer = 0;
1085
1086   SMESH::GetFilterManager();
1087   SMESH::GetPattern();
1088
1089   /* load resources for all available meshers */
1090   SMESH::InitAvailableHypotheses();
1091 }
1092
1093 //=============================================================================
1094 /*!
1095  *
1096  */
1097 //=============================================================================
1098 SMESHGUI::~SMESHGUI()
1099 {
1100   SMESH::GetFilterManager()->Destroy();
1101   SMESH::GetFilterManager() = SMESH::FilterManager::_nil();
1102 }
1103
1104 //=============================================================================
1105 /*!
1106  *
1107  */
1108 //=============================================================================
1109 LightApp_SelectionMgr* SMESHGUI::selectionMgr()
1110 {
1111   SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
1112   if( anApp )
1113     return dynamic_cast<LightApp_SelectionMgr*>( anApp->selectionMgr() );
1114   else
1115     return 0;
1116 }
1117
1118 bool SMESHGUI::automaticUpdate()
1119 {
1120   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1121   if ( !resMgr )
1122     return false;
1123
1124   return resMgr->booleanValue( "SMESH", "auto_update", false );
1125 }
1126
1127 //=============================================================================
1128 /*!
1129  *
1130  */
1131 //=============================================================================
1132 SUIT_ResourceMgr* SMESHGUI::resourceMgr()
1133 {
1134   return dynamic_cast<SUIT_ResourceMgr*>( SUIT_Session::session()->resourceMgr() );
1135 }
1136
1137 //=============================================================================
1138 /*!
1139  *
1140  */
1141 //=============================================================================
1142 SMESHGUI* SMESHGUI::GetSMESHGUI()
1143 {
1144   SMESHGUI* smeshMod = 0;
1145   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>(SUIT_Session::session()->activeApplication());
1146   if ( app )
1147   {
1148     CAM_Module* module = app->module( "Mesh" );
1149     smeshMod = dynamic_cast<SMESHGUI*>( module );
1150   }
1151
1152   if ( smeshMod && smeshMod->application() && smeshMod->application()->activeStudy() )
1153   {
1154     SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( smeshMod->application()->activeStudy() );
1155     if ( study )
1156     {
1157       _PTR(Study) aStudy = study->studyDS();
1158       if ( aStudy )
1159         GetSMESHGen()->SetCurrentStudy( _CAST(Study,aStudy)->GetStudy() );
1160     }
1161   }
1162
1163   return smeshMod;
1164 }
1165
1166 extern "C"
1167 {
1168   Standard_EXPORT SMESHGUI* GetComponentGUI()
1169   {
1170     return SMESHGUI::GetSMESHGUI();
1171   }
1172 }
1173
1174 //=============================================================================
1175 /*!
1176  *
1177  */
1178 //=============================================================================
1179 void SMESHGUI::SetState(int aState)
1180 {
1181   myState = aState;
1182 }
1183
1184 //=============================================================================
1185 /*!
1186  *
1187  */
1188 //=============================================================================
1189 void SMESHGUI::ResetState()
1190 {
1191   myState = -1;
1192 }
1193
1194 //=============================================================================
1195 /*!
1196  *
1197  */
1198 //=============================================================================
1199 void SMESHGUI::EmitSignalDeactivateDialog()
1200 {
1201   emit SignalDeactivateActiveDialog();
1202 }
1203
1204 //=============================================================================
1205 /*!
1206  *
1207  */
1208 //=============================================================================
1209 void SMESHGUI::EmitSignalStudyFrameChanged()
1210 {
1211   emit SignalStudyFrameChanged();
1212 }
1213
1214 //=============================================================================
1215 /*!
1216  *
1217  */
1218 //=============================================================================
1219 void SMESHGUI::EmitSignalCloseAllDialogs()
1220 {
1221   emit SignalCloseAllDialogs();
1222 }
1223
1224 //=============================================================================
1225 /*!
1226  *
1227  */
1228 //=============================================================================
1229 QDialog *SMESHGUI::GetActiveDialogBox()
1230 {
1231   return myActiveDialogBox;
1232 }
1233
1234 //=============================================================================
1235 /*!
1236  *
1237  */
1238 //=============================================================================
1239 void SMESHGUI::SetActiveDialogBox(QDialog * aDlg)
1240 {
1241   myActiveDialogBox = (QDialog *) aDlg;
1242   return;
1243 }
1244
1245 //=============================================================================
1246 /*!
1247  *
1248  */
1249 //=============================================================================
1250 SUIT_Desktop* SMESHGUI::desktop()
1251 {
1252   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
1253   if( app )
1254     return app->desktop();
1255   else
1256     return 0;
1257 }
1258
1259 //=============================================================================
1260 /*!
1261  *
1262  */
1263 //=============================================================================
1264 SalomeApp_Study* SMESHGUI::activeStudy()
1265 {
1266   SUIT_Application* app = SUIT_Session::session()->activeApplication();
1267   if( app )
1268     return dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1269   else
1270     return NULL;
1271 }
1272
1273 //=============================================================================
1274 /*!
1275  *
1276  */
1277 //=============================================================================
1278 bool SMESHGUI::DefineDlgPosition(QWidget * aDlg, int &x, int &y)
1279 {
1280   /* Here the position is on the bottom right corner - 10 */
1281   // aDlg->resize(QSize().expandedTo(aDlg->minimumSizeHint()));
1282   aDlg->adjustSize();
1283   SUIT_Desktop *PP = desktop();
1284   x = abs(PP->x() + PP->size().width() - aDlg->size().width() - 10);
1285   y = abs(PP->y() + PP->size().height() - aDlg->size().height() - 10);
1286   return true;
1287 }
1288
1289 //=============================================================================
1290 /*!
1291  *
1292  */
1293 //=============================================================================
1294 static int isStudyLocked(_PTR(Study) theStudy){
1295   return theStudy->GetProperties()->IsLocked();
1296 }
1297
1298 static bool checkLock(_PTR(Study) theStudy) {
1299   if (isStudyLocked(theStudy)) {
1300     SUIT_MessageBox::warn1 ( SMESHGUI::desktop(),
1301                            QObject::tr("WRN_WARNING"),
1302                            QObject::tr("WRN_STUDY_LOCKED"),
1303                            QObject::tr("BUT_OK") );
1304     return true;
1305   }
1306   return false;
1307 }
1308
1309 //=======================================================================
1310 //function : CheckActiveStudyLocked
1311 //purpose  :
1312 //=======================================================================
1313
1314 bool SMESHGUI::isActiveStudyLocked()
1315 {
1316   _PTR(Study) aStudy = activeStudy()->studyDS();
1317   return checkLock( aStudy );
1318 }
1319
1320 //=============================================================================
1321 /*!
1322  *
1323  */
1324 //=============================================================================
1325 bool SMESHGUI::OnGUIEvent( int theCommandID )
1326 {
1327   SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( application() );
1328   if( !anApp )
1329     return false;
1330
1331   _PTR(Study) aStudy = SMESH::GetActiveStudyDocument(); //Document OCAF de l'etude active
1332   SUIT_ResourceMgr* mgr = resourceMgr();
1333   if( !mgr )
1334     return false;
1335
1336   if (CORBA::is_nil(GetSMESHGen()->GetCurrentStudy())) {
1337     GetSMESHGen()->SetCurrentStudy(_CAST(Study,aStudy)->GetStudy());
1338   }
1339
1340   SUIT_ViewWindow* view = application()->desktop()->activeWindow();
1341   SVTK_ViewWindow* vtkwnd = dynamic_cast<SVTK_ViewWindow*>( view );
1342
1343   //QAction* act = action( theCommandID );
1344
1345   switch (theCommandID) {
1346   case 33:                                      // DELETE
1347     if(checkLock(aStudy)) break;
1348     OnEditDelete();
1349     break;
1350
1351   case 113:                                     // IMPORT
1352   case 112:
1353   case 111:
1354     {
1355       if(checkLock(aStudy)) break;
1356       ::ImportMeshesFromFile(GetSMESHGen(),theCommandID);
1357       break;
1358     }
1359
1360   case 150:    //MED FILE INFORMATION
1361     {
1362       SALOME_ListIO selected;
1363       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1364       if( aSel )
1365         aSel->selectedObjects( selected );
1366       if( selected.Extent() )
1367       {
1368         Handle(SALOME_InteractiveObject) anIObject = selected.First();
1369         SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIObject);
1370         if ( !aMesh->_is_nil() )
1371         {
1372           SMESHGUI_FileInfoDlg dlg( desktop(), aMesh->GetMEDFileInfo() );
1373           dlg.exec();
1374         }
1375       }
1376       break;
1377     }
1378   case 122:                                     // EXPORT MED
1379   case 121:
1380   case 123:
1381   case 124:
1382   case 125:
1383   case 126:
1384   case 140:
1385   case 141:
1386     {
1387       ::ExportMeshToFile(theCommandID);
1388       break;
1389     }
1390
1391   case 200:                                     // SCALAR BAR
1392     {
1393       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1394       SALOME_ListIO selected;
1395       if( aSel )
1396         aSel->selectedObjects( selected );
1397
1398       if( selected.Extent() ) {
1399         Handle(SALOME_InteractiveObject) anIO = selected.First();
1400         if( anIO->hasEntry() ) {
1401           if( SMESH_Actor* anActor = SMESH::FindActorByEntry( anIO->getEntry() ) ) {
1402             anActor->SetControlMode( SMESH_Actor::eNone );
1403           }
1404         }
1405       }
1406       break;
1407     }
1408   case 201:
1409     {
1410       SMESHGUI_Preferences_ScalarBarDlg::ScalarBarProperties( this );
1411       break;
1412     }
1413
1414     // Auto-color
1415   case 1136:
1416     ::AutoColor();
1417   break;
1418
1419   case 1137:
1420     ::DisableAutoColor();
1421   break;
1422
1423   case 1134: // Clipping
1424   case 1133: // Tranparency
1425   case 1132: // Colors / Size
1426
1427     // Display Mode
1428   case 215: // Nodes
1429   case 213: // Nodes
1430   case 212: // Nodes
1431   case 211: // Nodes
1432     ::SetDisplayMode(theCommandID);
1433   break;
1434
1435     // Display Entity
1436   case 217: // Edges
1437   case 218: // Faces
1438   case 219: // Volumes
1439   case 220: // All Entity
1440     ::SetDisplayEntity(theCommandID);
1441   break;
1442
1443   case 214:                                     // UPDATE
1444     {
1445       if(checkLock(aStudy)) break;
1446       try {
1447 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1448         OCC_CATCH_SIGNALS;
1449 #endif
1450         SMESH::UpdateView();
1451       }
1452       catch (std::bad_alloc) { // PAL16774 (Crash after display of many groups)
1453         SMESH::OnVisuException();
1454       }
1455       catch (...) { // PAL16774 (Crash after display of many groups)
1456         SMESH::OnVisuException();
1457       }
1458
1459       SALOME_ListIO l;
1460       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1461       aSel->selectedObjects( l );
1462       aSel->setSelectedObjects( l );
1463       break;
1464     }
1465
1466   case 300:                                     // ERASE
1467   case 301:                                     // DISPLAY
1468   case 302:                                     // DISPLAY ONLY
1469     {
1470       SMESH::EDisplaing anAction;
1471       switch (theCommandID) {
1472       case 300: anAction = SMESH::eErase; break;
1473       case 301: anAction = SMESH::eDisplay; break;
1474       case 302: anAction = SMESH::eDisplayOnly; break;
1475       }
1476
1477       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1478       SALOME_ListIO sel_objects, to_process;
1479       if (aSel)
1480         aSel->selectedObjects( sel_objects );
1481
1482       if( theCommandID==302 )
1483         startOperation( myEraseAll );
1484
1485       extractContainers( sel_objects, to_process );
1486
1487       try {
1488 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1489         OCC_CATCH_SIGNALS;
1490 #endif
1491         if (vtkwnd) {
1492           SALOME_ListIteratorOfListIO It( to_process );
1493           for (; It.More(); It.Next()) {
1494             Handle(SALOME_InteractiveObject) IOS = It.Value();
1495             if (IOS->hasEntry()) {
1496               if (!SMESH::UpdateView(anAction, IOS->getEntry()))
1497                 break; // PAL16774 (Crash after display of many groups)
1498               if (anAction == SMESH::eDisplayOnly)
1499                 anAction = SMESH::eDisplay;
1500             }
1501           }
1502         }
1503
1504         // PAL13338 + PAL15161 -->
1505         if ( ( theCommandID==301 || theCommandID==302 ) && !checkLock(aStudy))
1506           SMESH::UpdateView();
1507         // PAL13338 + PAL15161 <--
1508       }
1509       catch (...) { // PAL16774 (Crash after display of many groups)
1510         SMESH::OnVisuException();
1511       }
1512
1513       if (anAction == SMESH::eErase) {
1514         SALOME_ListIO l1;
1515         aSel->setSelectedObjects( l1 );
1516       }
1517       else
1518         aSel->setSelectedObjects( to_process );
1519
1520       break;
1521     }
1522
1523   case 400:                                     // NODES
1524     {
1525       if(checkLock(aStudy)) break;
1526
1527       if ( vtkwnd ) {
1528         EmitSignalDeactivateDialog();
1529
1530         new SMESHGUI_NodesDlg(this);
1531       }
1532       else {
1533         SUIT_MessageBox::warn1(desktop(),
1534                               tr("SMESH_WRN_WARNING"),
1535                               tr("SMESH_WRN_VIEWER_VTK"),
1536                               tr("SMESH_BUT_OK"));
1537       }
1538       break;
1539     }
1540
1541   case 2151:  // FILTER
1542   {
1543     if ( vtkwnd )
1544     {
1545       EmitSignalDeactivateDialog();
1546       new SMESHGUI_FilterDlg( this, SMESH::EDGE );
1547     }
1548     break;
1549   }
1550
1551   case 406:                                     // MOVE NODE
1552     {
1553       if ( !vtkwnd )
1554       {
1555         SUIT_MessageBox::warn1( desktop(), tr( "SMESH_WRN_WARNING" ),
1556           tr( "NOT_A_VTK_VIEWER" ),tr( "SMESH_BUT_OK" ) );
1557         break;
1558       }
1559
1560       if(checkLock(aStudy)) break;
1561       new SMESHGUI_MoveNodesDlg(this);
1562       break;
1563     }
1564
1565   case 701:                                     // COMPUTE MESH
1566     {
1567       if (checkLock(aStudy)) break;
1568
1569       startOperation( 701 );
1570     }
1571     break;
1572
1573   case 702:  // Create mesh
1574     startOperation( 702 );
1575     break;
1576   case 703:  // Create sub-mesh
1577     startOperation( 703 );
1578     break;
1579   case 704: // Edit mesh/sub-mesh
1580     startOperation( 704 );
1581     break;
1582   case 710: // Build compound mesh
1583     {
1584       if (checkLock(aStudy)) break;
1585       EmitSignalDeactivateDialog();
1586       new SMESHGUI_BuildCompoundDlg( this );
1587     }
1588     break;
1589
1590   case 407: // DIAGONAL INVERSION
1591   case 408: // Delete diagonal
1592     {
1593       if ( !vtkwnd )
1594       {
1595         SUIT_MessageBox::warn1( desktop(), tr( "SMESH_WRN_WARNING" ),
1596           tr( "NOT_A_VTK_VIEWER" ),tr( "SMESH_BUT_OK" ) );
1597         break;
1598       }
1599
1600       if ( checkLock( aStudy ) )
1601         break;
1602
1603       /*Standard_Boolean aRes;
1604       SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IObject);
1605       if ( aMesh->_is_nil() )
1606       {
1607         SUIT_MessageBox::warn1(GetDesktop(), tr( "SMESH_WRN_WARNING" ),
1608           tr( "SMESH_BAD_SELECTION" ), tr( "SMESH_BUT_OK" ) );
1609         break;
1610       }
1611       */
1612       EmitSignalDeactivateDialog();
1613       if ( theCommandID == 407 )
1614         new SMESHGUI_TrianglesInversionDlg(this);
1615       else
1616         new SMESHGUI_UnionOfTwoTrianglesDlg(this);
1617       break;
1618     }
1619     case 409: // Change orientation
1620     case 410: // Union of triangles
1621     case 411: // Cutting of quadrangles
1622     {
1623       if ( !vtkwnd )
1624       {
1625         SUIT_MessageBox::warn1( desktop(), tr( "SMESH_WRN_WARNING" ),
1626           tr( "NOT_A_VTK_VIEWER" ),tr( "SMESH_BUT_OK" ) );
1627         break;
1628       }
1629
1630       if ( checkLock( aStudy ) )
1631         break;
1632
1633       EmitSignalDeactivateDialog();
1634       SMESHGUI_MultiEditDlg* aDlg = NULL;
1635       if ( theCommandID == 409 )
1636         aDlg = new SMESHGUI_ChangeOrientationDlg(this);
1637       else if ( theCommandID == 410 )
1638         aDlg = new SMESHGUI_UnionOfTrianglesDlg(this);
1639       else
1640         aDlg = new SMESHGUI_CuttingOfQuadsDlg(this);
1641
1642       aDlg->show();
1643       break;
1644     }
1645   case 412: // Smoothing
1646     {
1647       if(checkLock(aStudy)) break;
1648       if( vtkwnd ) {
1649         EmitSignalDeactivateDialog();
1650         new SMESHGUI_SmoothingDlg( this );
1651       }
1652       else {
1653         SUIT_MessageBox::warn1(desktop(),
1654                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1655                               tr("SMESH_BUT_OK"));
1656       }
1657       break;
1658     }
1659   case 413: // Extrusion
1660     {
1661       if (checkLock(aStudy)) break;
1662       if (vtkwnd) {
1663         EmitSignalDeactivateDialog();
1664         new SMESHGUI_ExtrusionDlg ( this );
1665       } else {
1666         SUIT_MessageBox::warn1(desktop(),
1667                                tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1668                                tr("SMESH_BUT_OK"));
1669       }
1670       break;
1671     }
1672   case 414: // Revolution
1673     {
1674       if(checkLock(aStudy)) break;
1675       if( vtkwnd ) {
1676         EmitSignalDeactivateDialog();
1677         new SMESHGUI_RevolutionDlg( this );
1678       }
1679       else {
1680         SUIT_MessageBox::warn1(desktop(),
1681                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1682                               tr("SMESH_BUT_OK"));
1683       }
1684       break;
1685     }
1686   case 415: // Pattern mapping
1687     {
1688       if ( checkLock( aStudy ) )
1689         break;
1690       if ( vtkwnd )
1691       {
1692         EmitSignalDeactivateDialog();
1693         new SMESHGUI_MeshPatternDlg( this );
1694       }
1695       else {
1696         SUIT_MessageBox::warn1(desktop(),
1697                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1698                               tr("SMESH_BUT_OK"));
1699       }
1700       break;
1701     }
1702   case 416: // Extrusion along a path
1703     {
1704       if (checkLock(aStudy)) break;
1705       if (vtkwnd) {
1706         EmitSignalDeactivateDialog();
1707         new SMESHGUI_ExtrusionAlongPathDlg( this );
1708       } else {
1709         SUIT_MessageBox::warn1(desktop(),
1710                                tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1711                                tr("SMESH_BUT_OK"));
1712       }
1713       break;
1714     }
1715   case 417: // Convert mesh to quadratic
1716     {
1717     startOperation( 417 );
1718       /*      if (checkLock(aStudy)) break;
1719       if (vtkwnd) {
1720         EmitSignalDeactivateDialog();
1721         new SMESHGUI_ConvToQuadDlg();
1722       } else {
1723         SUIT_MessageBox::warn1(desktop(),
1724                                tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1725                                tr("SMESH_BUT_OK"));
1726                                }*/
1727       break;
1728     }
1729   case 806:                                     // CREATE GEO GROUP
1730     {
1731       startOperation( 806 );
1732       break;
1733     }
1734   case 801:                                     // CREATE GROUP
1735     {
1736       if ( !vtkwnd )
1737       {
1738         SUIT_MessageBox::warn1( desktop(), tr( "SMESH_WRN_WARNING" ),
1739           tr( "NOT_A_VTK_VIEWER" ),tr( "SMESH_BUT_OK" ) );
1740         break;
1741       }
1742
1743       if(checkLock(aStudy)) break;
1744       EmitSignalDeactivateDialog();
1745       SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_nil();
1746
1747       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1748       SALOME_ListIO selected;
1749       if( aSel )
1750         aSel->selectedObjects( selected );
1751
1752       int nbSel = selected.Extent();
1753       if (nbSel == 1) {
1754         // check if mesh is selected
1755         aMesh = SMESH::GetMeshByIO( selected.First() );
1756       }
1757       SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, "", aMesh);
1758       aDlg->show();
1759       break;
1760     }
1761
1762   case 802:                                     // CONSTRUCT GROUP
1763     {
1764       if ( !vtkwnd )
1765       {
1766         SUIT_MessageBox::warn1( desktop(), tr( "SMESH_WRN_WARNING" ),
1767           tr( "NOT_A_VTK_VIEWER" ),tr( "SMESH_BUT_OK" ) );
1768         break;
1769       }
1770
1771       if(checkLock(aStudy)) break;
1772       EmitSignalDeactivateDialog();
1773
1774       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1775       SALOME_ListIO selected;
1776       if( aSel )
1777         aSel->selectedObjects( selected );
1778
1779       int nbSel = selected.Extent();
1780       if (nbSel == 1) {
1781         // check if submesh is selected
1782         Handle(SALOME_InteractiveObject) IObject = selected.First();
1783         if (IObject->hasEntry()) {
1784           _PTR(SObject) aSObj = aStudy->FindObjectID(IObject->getEntry());
1785           if( aSObj ) {
1786             SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow( SMESH::SObjectToObject( aSObj ) );
1787             if (!aSubMesh->_is_nil()) {
1788               try {
1789                 SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
1790                 // get submesh elements list by types
1791                 SMESH::long_array_var aNodes = aSubMesh->GetElementsByType(SMESH::NODE);
1792                 SMESH::long_array_var aEdges = aSubMesh->GetElementsByType(SMESH::EDGE);
1793                 SMESH::long_array_var aFaces = aSubMesh->GetElementsByType(SMESH::FACE);
1794                 SMESH::long_array_var aVolumes = aSubMesh->GetElementsByType(SMESH::VOLUME);
1795                 // create group for each type o elements
1796                 QString aName = IObject->getName();
1797                 if (aNodes->length() > 0) {
1798                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::NODE, aName + "_Nodes");
1799                   aGroup->Add(aNodes.inout());
1800                 }
1801                 if (aEdges->length() > 0) {
1802                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::EDGE, aName + "_Edges");
1803                   aGroup->Add(aEdges.inout());
1804                 }
1805                 if (aFaces->length() > 0) {
1806                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::FACE, aName + "_Faces");
1807                   aGroup->Add(aFaces.inout());
1808                 }
1809                 if (aVolumes->length() > 0) {
1810                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::VOLUME, aName + "_Volumes");
1811                   aGroup->Add(aVolumes.inout());
1812                 }
1813                 updateObjBrowser();
1814
1815               }
1816               catch(const SALOME::SALOME_Exception & S_ex){
1817                 SalomeApp_Tools::QtCatchCorbaException(S_ex);
1818               }
1819             }
1820           }
1821         }
1822       }
1823       else if(nbSel==0) {
1824         SUIT_MessageBox::warn1(desktop(),
1825                                tr("SMESH_WRN_WARNING"),
1826                                tr("SMESH_WRN_NO_AVAILABLE_DATA"),
1827                                tr("SMESH_BUT_OK"));
1828       }
1829       break;
1830     }
1831
1832   case 803:                                     // EDIT GROUP
1833     {
1834       if ( !vtkwnd )
1835       {
1836         SUIT_MessageBox::warn1( desktop(), tr( "SMESH_WRN_WARNING" ),
1837           tr( "NOT_A_VTK_VIEWER" ),tr( "SMESH_BUT_OK" ) );
1838         break;
1839       }
1840
1841       if(checkLock(aStudy)) break;
1842       EmitSignalDeactivateDialog();
1843
1844       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1845       SALOME_ListIO selected;
1846       if( aSel )
1847         aSel->selectedObjects( selected );
1848
1849       SALOME_ListIteratorOfListIO It (selected);
1850       int nbSelectedGroups = 0;
1851       for ( ; It.More(); It.Next() )
1852       {
1853         SMESH::SMESH_GroupBase_var aGroup =
1854           SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(It.Value());
1855         if (!aGroup->_is_nil()) {
1856           nbSelectedGroups++;
1857           SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, "", aGroup);
1858           aDlg->show();
1859         }
1860       }
1861       if (nbSelectedGroups == 0)
1862         {
1863           SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, "", SMESH::SMESH_GroupBase::_nil());
1864           aDlg->show();
1865         }
1866       break;
1867     }
1868
1869   case 804:                                     // Add elements to group
1870     {
1871       if(checkLock(aStudy)) break;
1872       if (myState == 800) {
1873         SMESHGUI_GroupDlg *aDlg = (SMESHGUI_GroupDlg*) myActiveDialogBox;
1874         if (aDlg) aDlg->onAdd();
1875       }
1876       break;
1877     }
1878
1879   case 805:                                     // Remove elements from group
1880     {
1881       if(checkLock(aStudy)) break;
1882       if (myState == 800) {
1883         SMESHGUI_GroupDlg *aDlg = (SMESHGUI_GroupDlg*) myActiveDialogBox;
1884         if (aDlg) aDlg->onRemove();
1885       }
1886       break;
1887     }
1888
1889     case 810: // Union Groups
1890     case 811: // Intersect groups
1891     case 812: // Cut groups
1892     {
1893       if ( !vtkwnd )
1894       {
1895         SUIT_MessageBox::warn1( desktop(), tr( "SMESH_WRN_WARNING" ),
1896           tr( "NOT_A_VTK_VIEWER" ),tr( "SMESH_BUT_OK" ) );
1897         break;
1898       }
1899
1900       if ( checkLock( aStudy ) )
1901         break;
1902
1903       EmitSignalDeactivateDialog();
1904
1905       int aMode;
1906       if      ( theCommandID == 810 ) aMode = SMESHGUI_GroupOpDlg::UNION;
1907       else if ( theCommandID == 811 ) aMode = SMESHGUI_GroupOpDlg::INTERSECT;
1908       else                            aMode = SMESHGUI_GroupOpDlg::CUT;
1909
1910       ( new SMESHGUI_GroupOpDlg( this, aMode ) )->show();
1911       break;
1912     }
1913
1914     case 813: // Delete groups with their contents
1915     {
1916       if ( !vtkwnd )
1917       {
1918         SUIT_MessageBox::warn1( desktop(), tr( "SMESH_WRN_WARNING" ),
1919           tr( "NOT_A_VTK_VIEWER" ),tr( "SMESH_BUT_OK" ) );
1920         break;
1921       }
1922
1923       if ( checkLock( aStudy ) )
1924         break;
1925
1926       EmitSignalDeactivateDialog();
1927
1928       new SMESHGUI_DeleteGroupDlg( this );
1929       break;
1930     }
1931
1932   case 900:                                     // MESH INFOS
1933     {
1934       EmitSignalDeactivateDialog();
1935       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1936       SALOME_ListIO selected;
1937       if( aSel )
1938         aSel->selectedObjects( selected );
1939
1940       if ( selected.Extent() > 1 ) { // a dlg for each IO
1941         SALOME_ListIO IOs;
1942         SALOME_ListIteratorOfListIO It (selected);
1943         for ( ; It.More(); It.Next() ) {
1944           IOs.Clear(); IOs.Append( It.Value() );
1945           aSel->setSelectedObjects( IOs );
1946           new SMESHGUI_MeshInfosDlg(this, "", false);
1947         }
1948         // restore selection
1949         aSel->setSelectedObjects( selected );
1950       }
1951       else
1952         new SMESHGUI_MeshInfosDlg(this, "", false);
1953       break;
1954     }
1955
1956   case 902:                                     // STANDARD MESH INFOS
1957     {
1958       EmitSignalDeactivateDialog();
1959       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1960       SALOME_ListIO selected;
1961       if( aSel )
1962         aSel->selectedObjects( selected );
1963
1964       if ( selected.Extent() > 1 ) { // a dlg for each IO
1965         SALOME_ListIO IOs;
1966         SALOME_ListIteratorOfListIO It (selected);
1967         for ( ; It.More(); It.Next() ) {
1968           IOs.Clear();
1969           IOs.Append( It.Value() );
1970           aSel->setSelectedObjects( IOs );
1971           new SMESHGUI_StandardMeshInfosDlg( this, "", false);
1972         }
1973         // restore selection
1974         aSel->setSelectedObjects( selected );
1975       }
1976       else
1977         new SMESHGUI_StandardMeshInfosDlg( this, "", false);
1978       break;
1979     }
1980
1981   case 903:                                     // WHAT IS
1982     {
1983       EmitSignalDeactivateDialog();
1984       new SMESHGUI_WhatIsDlg( this, "", false);
1985       break;
1986     }
1987
1988   case 1100:                                    // EDIT HYPOTHESIS
1989     {
1990       if(checkLock(aStudy)) break;
1991
1992       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1993       SALOME_ListIO selected;
1994       if( aSel )
1995         aSel->selectedObjects( selected );
1996
1997       int nbSel = selected.Extent();
1998
1999       if (nbSel == 1) {
2000         Handle(SALOME_InteractiveObject) anIObject = selected.First();
2001         SMESH::SMESH_Hypothesis_var aHypothesis = SMESH::IObjectToInterface<SMESH::SMESH_Hypothesis>(anIObject);
2002
2003         /* Look for all mesh objects that have this hypothesis affected in order to flag as ModifiedMesh */
2004         /* At end below '...->updateObjBrowser(true)' will change icon of mesh objects                   */
2005         /* Warning : however by internal mechanism all subMeshes icons are changed !                     */
2006         if ( !aHypothesis->_is_nil() )
2007         {
2008           CORBA::String_var aHypType = aHypothesis->GetName();
2009           SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHypType);
2010           if (aCreator)
2011             aCreator->edit( aHypothesis.in(), anIObject->getName(), desktop() );
2012           else
2013           {
2014             // report error
2015           }
2016         }
2017       }
2018       updateObjBrowser( true );
2019       break;
2020     }
2021
2022   case 1101:                                    // RENAME
2023     {
2024       if ( checkLock( aStudy ) )
2025         break;
2026
2027       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2028       SALOME_ListIO selected;
2029       if( aSel )
2030         aSel->selectedObjects( selected );
2031
2032       bool isAny = false; // iss there any appropriate object selected
2033
2034       SALOME_ListIteratorOfListIO It( selected );
2035       for ( ; It.More(); It.Next() )
2036       {
2037         Handle(SALOME_InteractiveObject) IObject = It.Value();
2038         _PTR(SObject) obj = aStudy->FindObjectID( IObject->getEntry() );
2039         _PTR(GenericAttribute) anAttr;
2040         _PTR(AttributeName) aName;
2041         if ( obj )
2042         {
2043           if ( obj->FindAttribute(anAttr, "AttributeName") )
2044           {
2045             aName = anAttr;
2046             QString newName = QString(aName->Value().c_str());
2047
2048             // check type to prevent renaming of inappropriate objects
2049             int aType = SMESHGUI_Selection::type(IObject->getEntry(), aStudy);
2050             if (aType == MESH || aType == GROUP ||
2051                 aType == SUBMESH || aType == SUBMESH_COMPOUND ||
2052                 aType == SUBMESH_SOLID || aType == SUBMESH_FACE ||
2053                 aType == SUBMESH_EDGE || aType == SUBMESH_VERTEX ||
2054                 aType == HYPOTHESIS || aType == ALGORITHM)
2055             {
2056               isAny = true;
2057               newName = LightApp_NameDlg::getName(desktop(), newName);
2058               if ( !newName.isEmpty() )
2059               {
2060                 //old source: aStudy->renameIObject( IObject, newName );
2061                 aName->SetValue( newName.latin1() );
2062
2063                 // if current object is group update group's name
2064                 SMESH::SMESH_GroupBase_var aGroup =
2065                   SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IObject);
2066                 if (!aGroup->_is_nil() )
2067                   aGroup->SetName( newName.latin1() );
2068
2069                 updateObjBrowser();
2070               }
2071             }
2072           }
2073         }
2074       } // for
2075
2076       if (!isAny) {
2077         SUIT_MessageBox::warn1(desktop(),
2078                                QObject::tr("SMESH_WRN_WARNING"),
2079                                QObject::tr("SMESH_WRN_NO_APPROPRIATE_SELECTION"),
2080                                QObject::tr("SMESH_BUT_OK"));
2081       }
2082       break;
2083     }
2084
2085   case 1102:                                    // REMOVE HYPOTHESIS / ALGORITHMS
2086     {
2087       if(checkLock(aStudy)) break;
2088       SUIT_OverrideCursor wc;
2089
2090       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2091       SALOME_ListIO selected;
2092       if( aSel )
2093         aSel->selectedObjects( selected, QString::null, false );
2094
2095       SALOME_ListIteratorOfListIO It(selected);
2096       for (int i = 0; It.More(); It.Next(), i++) {
2097         Handle(SALOME_InteractiveObject) IObject = It.Value();
2098         SMESH::RemoveHypothesisOrAlgorithmOnMesh(IObject);
2099       }
2100       SALOME_ListIO l1;
2101       aSel->setSelectedObjects( l1 );
2102       updateObjBrowser();
2103       break;
2104     }
2105
2106   case 401:                                     // GEOM::EDGE
2107   case 4021:                                    // TRIANGLE
2108   case 4022:                                    // QUAD
2109   case 4023:                                    // POLYGON
2110   case 4031:                                    // TETRA
2111   case 4032:                                    // HEXA
2112     {
2113       if(checkLock(aStudy)) break;
2114       if ( vtkwnd ) {
2115         EmitSignalDeactivateDialog();
2116         SMDSAbs_ElementType type    = SMDSAbs_Edge;
2117         int                 nbNodes = 2;
2118         switch (theCommandID) {
2119         case 4021:                                      // TRIANGLE
2120           type = SMDSAbs_Face; nbNodes = 3; break;
2121         case 4022:                                      // QUAD
2122           type = SMDSAbs_Face; nbNodes = 4; break;
2123         case 4031:                                      // TETRA
2124           type = SMDSAbs_Volume; nbNodes = 4; break;
2125         case 4023:                                      // POLYGON
2126           type = SMDSAbs_Face; nbNodes = 5; break;     // 5 - identificator for POLYGON
2127         case 4032:                                      // HEXA
2128           type = SMDSAbs_Volume; nbNodes = 8; break;
2129         case 4033:                                      // POLYHEDRE
2130           type = SMDSAbs_Volume; nbNodes = 9; break; // 9 - identificator for POLYHEDRE
2131         default:;
2132         }
2133         new SMESHGUI_AddMeshElementDlg( this, "", type, nbNodes);
2134       }
2135       else {
2136         SUIT_MessageBox::warn1(desktop(),
2137                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2138                               tr("SMESH_BUT_OK"));
2139       }
2140       break;
2141     }
2142   case 4033:                                    // POLYHEDRON
2143     {
2144       if(checkLock(aStudy)) break;
2145       if ( vtkwnd ) {
2146         EmitSignalDeactivateDialog();
2147         new SMESHGUI_CreatePolyhedralVolumeDlg(this, "", FALSE );
2148       }
2149       else {
2150         SUIT_MessageBox::warn1(SMESHGUI::desktop(),
2151                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2152                               tr("SMESH_BUT_OK"));
2153       }
2154       break;
2155     }
2156   case 4034:     // QUADRATIC EDGE
2157   case 4035:     // QUADRATIC TRIANGLE
2158   case 4036:     // QUADRATIC QUADRANGLE
2159   case 4037:     // QUADRATIC TETRAHEDRON
2160   case 4038:     // QUADRATIC PYRAMID
2161   case 4039:     // QUADRATIC PENTAHEDRON
2162   case 4040:     // QUADRATIC HEXAHEDRON
2163     {
2164       if(checkLock(aStudy)) break;
2165       if ( vtkwnd ) {
2166         EmitSignalDeactivateDialog();
2167         int type;
2168
2169         switch (theCommandID) {
2170         case 4034:
2171           type = QUAD_EDGE; break;
2172         case 4035:
2173           type = QUAD_TRIANGLE; break;
2174         case 4036:
2175           type = QUAD_QUADRANGLE; break;
2176         case 4037:
2177           type = QUAD_TETRAHEDRON; break;
2178         case 4038:
2179           type = QUAD_PYRAMID; break;
2180         case 4039:
2181           type = QUAD_PENTAHEDRON; break;
2182         case 4040:
2183           type = QUAD_HEXAHEDRON;
2184           break;
2185         default:;
2186         }
2187          new SMESHGUI_AddQuadraticElementDlg( this, type );
2188       }
2189       else {
2190         SUIT_MessageBox::warn1(SMESHGUI::desktop(),
2191                                tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2192                                tr("SMESH_BUT_OK"));
2193       }
2194       break;
2195     }
2196   case 4041:                                    // REMOVES NODES
2197     {
2198       if(checkLock(aStudy)) break;
2199       if ( vtkwnd ) {
2200         EmitSignalDeactivateDialog();
2201         new SMESHGUI_RemoveNodesDlg(this);
2202       }
2203       else {
2204         SUIT_MessageBox::warn1(desktop(),
2205                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2206                               tr("SMESH_BUT_OK"));
2207       }
2208       break;
2209     }
2210   case 4042:                                    // REMOVES ELEMENTS
2211     {
2212       if(checkLock(aStudy)) break;
2213       if( vtkwnd ) {
2214         EmitSignalDeactivateDialog();
2215         new SMESHGUI_RemoveElementsDlg(this);
2216       }
2217       else
2218         {
2219           SUIT_MessageBox::warn1(desktop(),
2220                                 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2221                                 tr("SMESH_BUT_OK"));
2222         }
2223       break;
2224     }
2225   case 4043: {                                // CLEAR_MESH
2226
2227     if(checkLock(aStudy)) break;
2228     
2229     SALOME_ListIO selected;
2230     if( LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr() )
2231       aSel->selectedObjects( selected );
2232
2233     SUIT_OverrideCursor wc;
2234     SALOME_ListIteratorOfListIO It (selected);
2235     for ( ; It.More(); It.Next() )
2236     {
2237       Handle(SALOME_InteractiveObject) IOS = It.Value();
2238       SMESH::SMESH_Mesh_var aMesh =
2239         SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IOS);
2240       if ( aMesh->_is_nil()) continue;
2241       try {
2242         SMESH::UpdateView(SMESH::eErase, IOS->getEntry());
2243         aMesh->Clear();
2244         _PTR(SObject) aMeshSObj = SMESH::FindSObject(aMesh);
2245         SMESH::ModifiedMesh( aMeshSObj, false, true);
2246         // hide groups and submeshes
2247         _PTR(ChildIterator) anIter =
2248           SMESH::GetActiveStudyDocument()->NewChildIterator( aMeshSObj );
2249         for ( anIter->InitEx(true); anIter->More(); anIter->Next() )
2250         {
2251           _PTR(SObject) so = anIter->Value();
2252           SMESH::UpdateView(SMESH::eErase, so->GetID().c_str());
2253         }
2254       }
2255       catch (const SALOME::SALOME_Exception& S_ex){
2256         wc.suspend();
2257         SalomeApp_Tools::QtCatchCorbaException(S_ex);
2258         wc.resume();
2259       }
2260     }
2261     SMESH::UpdateView();
2262     updateObjBrowser();
2263     break;
2264   }
2265   case 4051:                                    // RENUMBERING NODES
2266     {
2267       if(checkLock(aStudy)) break;
2268       if( vtkwnd ) {
2269         EmitSignalDeactivateDialog();
2270         new SMESHGUI_RenumberingDlg( this, "", 0);
2271       }
2272       else
2273         {
2274           SUIT_MessageBox::warn1(desktop(),
2275                                 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2276                                 tr("SMESH_BUT_OK"));
2277         }
2278       break;
2279     }
2280   case 4052:                                    // RENUMBERING ELEMENTS
2281     {
2282       if(checkLock(aStudy)) break;
2283       if ( vtkwnd ) {
2284         EmitSignalDeactivateDialog();
2285         new SMESHGUI_RenumberingDlg( this, "", 1);
2286       }
2287       else
2288         {
2289           SUIT_MessageBox::warn1(desktop(),
2290                                 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2291                                 tr("SMESH_BUT_OK"));
2292         }
2293       break;
2294     }
2295   case 4061:                                   // TRANSLATION
2296     {
2297       if(checkLock(aStudy)) break;
2298       if ( vtkwnd ) {
2299         EmitSignalDeactivateDialog();
2300         new SMESHGUI_TranslationDlg( this );
2301       }
2302       else {
2303         SUIT_MessageBox::warn1(desktop(),
2304                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2305                               tr("SMESH_BUT_OK"));
2306       }
2307       break;
2308     }
2309   case 4062:                                   // ROTATION
2310     {
2311       if(checkLock(aStudy)) break;
2312       if( vtkwnd ) {
2313         EmitSignalDeactivateDialog();
2314         new SMESHGUI_RotationDlg( this );
2315       }
2316       else {
2317         SUIT_MessageBox::warn1(desktop(),
2318                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2319                               tr("SMESH_BUT_OK"));
2320       }
2321       break;
2322     }
2323   case 4063:                                   // SYMMETRY
2324     {
2325       if(checkLock(aStudy)) break;
2326       if(vtkwnd) {
2327         EmitSignalDeactivateDialog();
2328         new SMESHGUI_SymmetryDlg( this );
2329       }
2330       else {
2331         SUIT_MessageBox::warn1(desktop(),
2332                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2333                               tr("SMESH_BUT_OK"));
2334       }
2335       break;
2336     }
2337   case 4064:                                   // SEWING
2338     {
2339       if(checkLock(aStudy)) break;
2340       if(vtkwnd) {
2341         EmitSignalDeactivateDialog();
2342         new SMESHGUI_SewingDlg( this );
2343       }
2344       else {
2345         SUIT_MessageBox::warn1(desktop(),
2346                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2347                               tr("SMESH_BUT_OK"));
2348       }
2349       break;
2350     }
2351   case 4065:                                   // MERGE NODES
2352     {
2353       if(checkLock(aStudy)) break;
2354       if(vtkwnd) {
2355         EmitSignalDeactivateDialog();
2356         new SMESHGUI_EditMeshDlg( this, 0 );
2357       }
2358       else {
2359         SUIT_MessageBox::warn1(desktop(),
2360                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2361                               tr("SMESH_BUT_OK"));
2362       }
2363       break;
2364     }
2365   case 4066:                                   // MERGE EQUAL ELEMENTS
2366     {
2367       if (checkLock(aStudy)) break;
2368       if (vtkwnd) {
2369         EmitSignalDeactivateDialog();
2370         new SMESHGUI_EditMeshDlg( this, 1 );
2371       } else {
2372         SUIT_MessageBox::warn1(desktop(),
2373                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2374                               tr("SMESH_BUT_OK"));
2375       }
2376       break;
2377     }
2378
2379   case 4067: // MAKE MESH PASS THROUGH POINT
2380     startOperation( 4067 );
2381     break;
2382
2383   case 5105: // Library of selection filters
2384   {
2385     static QValueList<int> aTypes;
2386     if ( aTypes.isEmpty() )
2387     {
2388       aTypes.append( SMESH::NODE );
2389       aTypes.append( SMESH::EDGE );
2390       aTypes.append( SMESH::FACE );
2391       aTypes.append( SMESH::VOLUME );
2392     }
2393     if (!myFilterLibraryDlg)
2394       myFilterLibraryDlg = new SMESHGUI_FilterLibraryDlg( this, SMESH::GetDesktop( this ), aTypes, SMESHGUI_FilterLibraryDlg::EDIT );
2395     else if (myFilterLibraryDlg->isHidden())
2396       myFilterLibraryDlg->Init( aTypes, SMESHGUI_FilterLibraryDlg::EDIT );
2397     myFilterLibraryDlg->raise();
2398   }
2399   break;
2400
2401   case 6017:                                    // CONTROLS
2402   case 6016:
2403   case 6015:
2404   case 6014:
2405   case 6013:
2406   case 6012:
2407   case 6011:
2408   case 6001:
2409   case 6018:
2410   case 6019:
2411   case 6002:
2412   case 6003:
2413   case 6004:
2414   case 6009:
2415     if ( vtkwnd ) {
2416
2417       LightApp_SelectionMgr* mgr = selectionMgr();
2418       SALOME_ListIO selected; mgr->selectedObjects( selected );
2419
2420       if ( selected.Extent() == 1 && selected.First()->hasEntry() ) {
2421         _PTR(SObject) SO = aStudy->FindObjectID( selected.First()->getEntry() );
2422         if ( SO ) {
2423           CORBA::Object_var aObject = SMESH::SObjectToObject( SO );
2424           SMESH::SMESH_Mesh_var      aMesh    = SMESH::SMESH_Mesh::_narrow( aObject );
2425           SMESH::SMESH_subMesh_var   aSubMesh = SMESH::SMESH_subMesh::_narrow( aObject );
2426           SMESH::SMESH_GroupBase_var aGroup   = SMESH::SMESH_GroupBase::_narrow( aObject );
2427           if ( !aMesh->_is_nil() || !aSubMesh->_is_nil() || !aGroup->_is_nil() ) {
2428             ::Control( theCommandID );
2429             break;
2430           }
2431         }
2432       }
2433       SUIT_MessageBox::warn1(desktop(),
2434                             tr( "SMESH_WRN_WARNING" ),
2435                             tr( "SMESH_BAD_SELECTION" ),
2436                             tr( "SMESH_BUT_OK" ) );
2437       break;
2438     }
2439     else {
2440       SUIT_MessageBox::warn1(desktop(),
2441                             tr( "SMESH_WRN_WARNING" ),
2442                             tr( "NOT_A_VTK_VIEWER" ),
2443                             tr( "SMESH_BUT_OK" ) );
2444     }
2445     break;
2446   case 9010:
2447     {
2448       LightApp_SelectionMgr* mgr = selectionMgr();
2449       SALOME_ListIO selected; mgr->selectedObjects( selected );
2450
2451       SALOME_ListIteratorOfListIO it(selected);
2452       for(; it.More(); it.Next()) {
2453         Handle(SALOME_InteractiveObject) anIObject = it.Value();
2454         if(anIObject->hasEntry()) {
2455           if(SMESH_Actor *anActor = SMESH::FindActorByEntry(anIObject->getEntry())){
2456             anActor->SetPointsLabeled( !anActor->GetPointsLabeled() );
2457           }
2458         }
2459       }
2460       break;
2461     }
2462   case 9011:
2463     {
2464       LightApp_SelectionMgr* mgr = selectionMgr();
2465       SALOME_ListIO selected; mgr->selectedObjects( selected );
2466
2467       if (selected.Extent() == 1)       {
2468         Handle(SALOME_InteractiveObject) anIObject = selected.First();
2469         if(anIObject->hasEntry())
2470           if(SMESH_Actor *anActor = SMESH::FindActorByEntry(anIObject->getEntry())){
2471             anActor->SetCellsLabeled( !anActor->GetCellsLabeled() );
2472           }
2473       }
2474       break;
2475     }
2476   }
2477
2478   anApp->updateActions(); //SRN: To update a Save button in the toolbar
2479   //updateObjBrowser();
2480   return true;
2481 }
2482
2483 //=============================================================================
2484 /*!
2485  *
2486  */
2487 //=============================================================================
2488 bool SMESHGUI::OnMousePress( QMouseEvent * pe, SUIT_ViewWindow * wnd )
2489 {
2490   return false;
2491 }
2492
2493 //=============================================================================
2494 /*!
2495  *
2496  */
2497 //=============================================================================
2498 bool SMESHGUI::OnMouseMove( QMouseEvent * pe, SUIT_ViewWindow * wnd )
2499 {
2500   return true;
2501 }
2502
2503 //=============================================================================
2504 /*!
2505  *
2506  */
2507 //=============================================================================
2508 bool SMESHGUI::OnKeyPress( QKeyEvent * pe, SUIT_ViewWindow * wnd )
2509 {
2510   return true;
2511 }
2512
2513 //=============================================================================
2514 /*! Method:  BuildPresentation(const Handle(SALOME_InteractiveObject)& theIO)
2515  *  Purpose: ensures that the actor for the given <theIO> exists in the active VTK view
2516  */
2517 //=============================================================================
2518 void SMESHGUI::BuildPresentation( const Handle(SALOME_InteractiveObject) & theIO,
2519                                   SUIT_ViewWindow* wnd )
2520 {
2521   if(theIO->hasEntry()){
2522     //SUIT_ViewWindow* wnd = SMESH::GetActiveWindow();
2523     SMESH::UpdateView(wnd,SMESH::eDisplay,theIO->getEntry());
2524   }
2525 }
2526
2527 //=======================================================================
2528 // function : createSMESHAction
2529 // purpose  :
2530 //=======================================================================
2531 void SMESHGUI::createSMESHAction( const int id, const QString& po_id, const QString& icon_id, const int key, const bool toggle  )
2532 {
2533   QIconSet icon;
2534   QWidget* parent = application()->desktop();
2535   SUIT_ResourceMgr* resMgr = resourceMgr();
2536   QPixmap pix;
2537   if ( icon_id.length() )
2538     pix = resMgr->loadPixmap( "SMESH", tr( icon_id ) );
2539   else
2540     pix = resMgr->loadPixmap( "SMESH", tr( QString( "ICO_" )+po_id ), false );
2541   if ( !pix.isNull() )
2542     icon = QIconSet( pix );
2543
2544   QString tooltip    = tr( QString( "TOP_" )+po_id ),
2545           menu       = tr( QString( "MEN_" )+po_id ),
2546           status_bar = tr( QString( "STB_" )+po_id );
2547
2548   createAction( id, tooltip, icon, menu, status_bar, key, parent, toggle, this, SLOT( OnGUIEvent() )  );
2549 }
2550
2551 //=======================================================================
2552 // function : createPopupItem
2553 // purpose  :
2554 //=======================================================================
2555 void SMESHGUI::createPopupItem( const int id,
2556                                 const QString& clients,
2557                                 const QString& types,
2558                                 const QString& theRule,
2559                                 const int pId )
2560 {
2561   int parentId = pId;
2562   if( pId!=-1 )
2563     parentId = popupMgr()->actionId( action( pId ) );
2564
2565   if( !popupMgr()->contains( popupMgr()->actionId( action( id ) ) ) )
2566     popupMgr()->insert( action( id ), parentId, 0 );
2567
2568   QChar lc = QtxPopupMgr::Selection::defEquality();
2569   QString rule = "(%1) and (%2) and (%3)";
2570   rule = rule.arg( QString( "%1>0" ).arg( QtxPopupMgr::Selection::defSelCountParam() ) );
2571   if( clients.isEmpty() )
2572     rule = rule.arg( QString( "true" ) );
2573   else
2574     rule = rule.arg( QString( "%1client in {%2}" ).arg( lc ).arg( clients ) );
2575   rule = rule.arg( QString( "%1type in {%2}" ).arg( lc ).arg( types ) );
2576   rule += theRule;
2577
2578   bool cont = myRules.contains( id );
2579   if( cont )
2580     rule = QString( "%1 or (%2)" ).arg( myRules[ id ] ).arg( rule );
2581
2582   popupMgr()->setRule( action( id ), rule, true );
2583   myRules[ id ] = QString( cont ? "%1" : "(%1)" ).arg( rule );
2584 }
2585
2586 //=======================================================================
2587 // function : initialize
2588 // purpose  :
2589 //=======================================================================
2590 void SMESHGUI::initialize( CAM_Application* app )
2591 {
2592   SalomeApp_Module::initialize( app );
2593
2594 //   SUIT_ResourceMgr* mgr = app->resourceMgr();
2595 //   if ( mgr )
2596   /* Automatic Update flag */
2597 //     myAutomaticUpdate = mgr->booleanValue( "SMESH", "AutomaticUpdate", myAutomaticUpdate );
2598
2599   // ----- create actions --------------
2600
2601   createSMESHAction(  111, "DAT", "", (CTRL+Key_B) );
2602   createSMESHAction(  112, "UNV", "", (CTRL+Key_U) );
2603   createSMESHAction(  113, "MED", "", (CTRL+Key_M) );
2604   createSMESHAction(  114, "NUM" );
2605   createSMESHAction(  121, "DAT" );
2606   createSMESHAction(  122, "MED" );
2607   createSMESHAction(  123, "UNV" );
2608   createSMESHAction(  140, "STL" );
2609   createSMESHAction(  124, "EXPORT_DAT" );
2610   createSMESHAction(  125, "EXPORT_MED" );
2611   createSMESHAction(  126, "EXPORT_UNV" );
2612   createSMESHAction(  141, "EXPORT_STL" );
2613   createSMESHAction(  150, "FILE_INFO" );
2614   createSMESHAction(   33, "DELETE",          "ICON_DELETE", Key_Delete );
2615   createSMESHAction( 5105, "SEL_FILTER_LIB" );
2616   createSMESHAction(  701, "COMPUTE",         "ICON_COMPUTE" );
2617   createSMESHAction(  702, "CREATE_MESH",     "ICON_DLG_INIT_MESH" );
2618   createSMESHAction(  703, "CREATE_SUBMESH",  "ICON_DLG_ADD_SUBMESH" );
2619   createSMESHAction(  704, "EDIT_MESHSUBMESH","ICON_DLG_EDIT_MESH" );
2620   createSMESHAction(  710, "BUILD_COMPOUND",  "ICON_BUILD_COMPOUND" );
2621   createSMESHAction(  806, "CREATE_GEO_GROUP","ICON_GEO_GROUP" );
2622   createSMESHAction(  801, "CREATE_GROUP",    "ICON_SMESH_TREE_GROUP" );
2623   createSMESHAction(  802, "CONSTRUCT_GROUP", "ICON_CONSTRUCT_GROUP" );
2624   createSMESHAction(  803, "EDIT_GROUP",      "ICON_EDIT_GROUP" );
2625   createSMESHAction(  804, "ADD" );
2626   createSMESHAction(  805, "REMOVE" );
2627   createSMESHAction(  810, "UN_GROUP",        "ICON_UNION" );
2628   createSMESHAction(  811, "INT_GROUP",       "ICON_INTERSECT" );
2629   createSMESHAction(  812, "CUT_GROUP",       "ICON_CUT" );
2630   createSMESHAction(  813, "DEL_GROUP",       "ICON_DEL_GROUP" );
2631   createSMESHAction(  900, "ADV_INFO",        "ICON_ADV_INFO" );
2632   createSMESHAction(  902, "STD_INFO",        "ICON_STD_INFO" );
2633   createSMESHAction(  903, "WHAT_IS",         "ICON_WHAT_IS" );
2634   createSMESHAction( 6001, "LENGTH",          "ICON_LENGTH" ,       0, true );
2635   createSMESHAction( 6002, "FREE_EDGE",       "ICON_FREE_EDGE" ,    0, true );
2636   createSMESHAction( 6003, "FREE_BORDER",     "ICON_FREE_EDGE_2D" , 0, true );
2637   createSMESHAction( 6004, "CONNECTION",      "ICON_CONNECTION" ,   0, true );
2638   createSMESHAction( 6011, "AREA",            "ICON_AREA" ,         0, true );
2639   createSMESHAction( 6012, "TAPER",           "ICON_TAPER" ,        0, true );
2640   createSMESHAction( 6013, "ASPECT",          "ICON_ASPECT" ,       0, true );
2641   createSMESHAction( 6014, "MIN_ANG",         "ICON_ANGLE" ,        0, true );
2642   createSMESHAction( 6015, "WARP",            "ICON_WARP" ,         0, true );
2643   createSMESHAction( 6016, "SKEW",            "ICON_SKEW",          0, true );
2644   createSMESHAction( 6017, "ASPECT_3D",       "ICON_ASPECT_3D",     0, true );
2645   createSMESHAction( 6018, "LENGTH_2D",       "ICON_LENGTH_2D",     0, true );
2646   createSMESHAction( 6019, "CONNECTION_2D",   "ICON_CONNECTION_2D", 0, true );
2647   createSMESHAction( 6009, "VOLUME_3D",       "ICON_VOLUME_3D",     0, true );
2648   createSMESHAction(  400, "NODE",            "ICON_DLG_NODE" );
2649   createSMESHAction(  401, "EDGE",            "ICON_DLG_EDGE" );
2650   createSMESHAction( 4021, "TRIANGLE",        "ICON_DLG_TRIANGLE" );
2651   createSMESHAction( 4022, "QUAD",            "ICON_DLG_QUADRANGLE" );
2652   createSMESHAction( 4023, "POLYGON",         "ICON_DLG_POLYGON" );
2653   createSMESHAction( 4031, "TETRA",           "ICON_DLG_TETRAS" );
2654   createSMESHAction( 4032, "HEXA",            "ICON_DLG_HEXAS" );
2655   createSMESHAction( 4041, "REMOVE_NODES",    "ICON_DLG_REM_NODE" );
2656   createSMESHAction( 4042, "REMOVE_ELEMENTS", "ICON_DLG_REM_ELEMENT" );
2657   createSMESHAction( 4043, "CLEAR_MESH"    ,  "ICON_CLEAR_MESH" );
2658   createSMESHAction( 4051, "RENUM_NODES",     "ICON_DLG_RENUMBERING_NODES" );
2659   createSMESHAction( 4052, "RENUM_ELEMENTS",  "ICON_DLG_RENUMBERING_ELEMENTS" );
2660   createSMESHAction( 4061, "TRANS",           "ICON_SMESH_TRANSLATION_VECTOR" );
2661   createSMESHAction( 4062, "ROT",             "ICON_DLG_MESH_ROTATION" );
2662   createSMESHAction( 4063, "SYM",             "ICON_SMESH_SYMMETRY_PLANE" );
2663   createSMESHAction( 4064, "SEW",             "ICON_SMESH_SEWING_FREEBORDERS" );
2664   createSMESHAction( 4065, "MERGE",           "ICON_SMESH_MERGE_NODES" );
2665   createSMESHAction( 4066, "MERGE_ELEMENTS",  "ICON_DLG_MERGE_ELEMENTS" );
2666   createSMESHAction( 4067, "MESH_THROU_POINT","ICON_DLG_MESH_THROU_POINT" );
2667   createSMESHAction(  406, "MOVE",            "ICON_DLG_MOVE_NODE" );
2668   createSMESHAction(  407, "INV",             "ICON_DLG_MESH_DIAGONAL" );
2669   createSMESHAction(  408, "UNION2",          "ICON_UNION2TRI" );
2670   createSMESHAction(  409, "ORIENT",          "ICON_DLG_MESH_ORIENTATION" );
2671   createSMESHAction(  410, "UNION",           "ICON_UNIONTRI" );
2672   createSMESHAction(  411, "CUT",             "ICON_CUTQUAD" );
2673   createSMESHAction(  412, "SMOOTH",          "ICON_DLG_SMOOTHING" );
2674   createSMESHAction(  413, "EXTRUSION",       "ICON_EXTRUSION" );
2675   createSMESHAction(  414, "REVOLUTION",      "ICON_REVOLUTION" );
2676   createSMESHAction(  415, "MAP",             "ICON_MAP" );
2677   createSMESHAction(  416, "EXTRUSION_ALONG", "ICON_EXTRUSION_ALONG" );
2678   createSMESHAction(  417, "CONV_TO_QUAD",    "ICON_CONV_TO_QUAD" );
2679   createSMESHAction(  200, "RESET" );
2680   createSMESHAction(  201, "SCALAR_BAR_PROP" );
2681   createSMESHAction(  211, "WIRE",           "ICON_WIRE", 0, true );
2682   createSMESHAction(  212, "SHADE",          "ICON_SHADE", 0, true );
2683   createSMESHAction(  213, "SHRINK",         "ICON_SHRINK", 0, true );
2684   createSMESHAction(  214, "UPDATE",         "ICON_UPDATE" );
2685   createSMESHAction(  215, "NODES",          "ICON_POINTS", 0, true );
2686   createSMESHAction(  217, "EDGES",          "ICON_DLG_EDGE", 0, true );
2687   createSMESHAction(  218, "FACES",          "ICON_DLG_TRIANGLE", 0, true );
2688   createSMESHAction(  219, "VOLUMES",        "ICON_DLG_TETRAS", 0, true );
2689   createSMESHAction(  220, "ALL" );
2690   createSMESHAction( 1100, "EDIT_HYPO" );
2691   createSMESHAction( 1101, "RENAME", "", Key_F2 );
2692   createSMESHAction( 1102, "UNASSIGN" );
2693   createSMESHAction( 9010, "NUM_NODES", "", 0, true );
2694   createSMESHAction( 9011, "NUM_ELEMENTS", "", 0, true );
2695   createSMESHAction( 1131, "DISPMODE" );
2696   createSMESHAction( 1132, "COLORS" );
2697   createSMESHAction( 1133, "TRANSP" );
2698   createSMESHAction( 1134, "CLIP" );
2699   createSMESHAction( 1135, "DISP_ENT" );
2700   createSMESHAction( 1136, "AUTO_COLOR" );
2701   createSMESHAction( 1137, "DISABLE_AUTO_COLOR" );
2702   createSMESHAction( 2000, "CTRL" );
2703
2704   createSMESHAction( 300, "ERASE" );
2705   createSMESHAction( 301, "DISPLAY" );
2706   createSMESHAction( 302, "DISPLAY_ONLY" );
2707   createSMESHAction( 4033, "POLYHEDRON", "ICON_DLG_POLYHEDRON" );
2708   createSMESHAction( 4034, "QUADRATIC_EDGE", "ICON_DLG_QUADRATIC_EDGE" );
2709   createSMESHAction( 4035, "QUADRATIC_TRIANGLE", "ICON_DLG_QUADRATIC_TRIANGLE" );
2710   createSMESHAction( 4036, "QUADRATIC_QUADRANGLE", "ICON_DLG_QUADRATIC_QUADRANGLE" );
2711   createSMESHAction( 4037, "QUADRATIC_TETRAHEDRON", "ICON_DLG_QUADRATIC_TETRAHEDRON" );
2712   createSMESHAction( 4038, "QUADRATIC_PYRAMID", "ICON_DLG_QUADRATIC_PYRAMID" );
2713   createSMESHAction( 4039, "QUADRATIC_PENTAHEDRON", "ICON_DLG_QUADRATIC_PENTAHEDRON" );
2714   createSMESHAction( 4040, "QUADRATIC_HEXAHEDRON", "ICON_DLG_QUADRATIC_HEXAHEDRON" );
2715
2716   // ----- create menu --------------
2717   int fileId   = createMenu( tr( "MEN_FILE" ),   -1,  1 ),
2718       editId   = createMenu( tr( "MEN_EDIT" ),   -1,  3 ),
2719       toolsId  = createMenu( tr( "MEN_TOOLS" ),  -1,  5, 50 ),
2720       meshId   = createMenu( tr( "MEN_MESH" ),   -1, 70, 10 ),
2721       ctrlId   = createMenu( tr( "MEN_CTRL" ),   -1, 60, 10 ),
2722       modifyId = createMenu( tr( "MEN_MODIFY" ), -1, 40, 10 ),
2723       viewId   = createMenu( tr( "MEN_VIEW" ),   -1,  2 );
2724
2725   createMenu( separator(), fileId );
2726
2727   int importId = createMenu( tr( "MEN_IMPORT" ), fileId, 11, 10 ),
2728       exportId = createMenu( tr( "MEN_EXPORT" ), fileId, 12, 10 ),
2729       addId    = createMenu( tr( "MEN_ADD" ),    modifyId, 402 ),
2730       removeId = createMenu( tr( "MEN_REMOVE" ), modifyId, 403 ),
2731       renumId  = createMenu( tr( "MEN_RENUM" ),  modifyId, 404 ),
2732       transfId = createMenu( tr( "MEN_TRANSF" ), modifyId, 405 );
2733
2734   createMenu( 111, importId, -1 );
2735   createMenu( 112, importId, -1 );
2736   createMenu( 113, importId, -1 );
2737
2738   createMenu( 121, exportId, -1 );
2739   createMenu( 122, exportId, -1 );
2740   createMenu( 123, exportId, -1 );
2741   createMenu( 140, exportId, -1 ); // export to stl STL
2742
2743   createMenu( separator(), fileId, 10 );
2744
2745   createMenu( 33, editId, -1 );
2746
2747   createMenu( 5105, toolsId, -1 );
2748
2749   createMenu( 702, meshId, -1 ); // "Mesh" menu
2750   createMenu( 703, meshId, -1 );
2751   createMenu( 704, meshId, -1 );
2752   createMenu( 710, meshId, -1 );
2753   createMenu( separator(), meshId, -1 );
2754   createMenu( 701, meshId, -1 );
2755   createMenu( separator(), meshId, -1 );
2756   createMenu( 801, meshId, -1 );
2757   createMenu( 806, meshId, -1 );
2758   createMenu( 802, meshId, -1 );
2759   createMenu( 803, meshId, -1 );
2760   createMenu( separator(), meshId, -1 );
2761   createMenu( 810, meshId, -1 );
2762   createMenu( 811, meshId, -1 );
2763   createMenu( 812, meshId, -1 );
2764   createMenu( separator(), meshId, -1 );
2765   createMenu( 813, meshId, -1 );
2766   createMenu( separator(), meshId, -1 );
2767   createMenu( 900, meshId, -1 );
2768   createMenu( 902, meshId, -1 );
2769   createMenu( 903, meshId, -1 );
2770   createMenu( separator(), meshId, -1 );
2771
2772   createMenu( 6003, ctrlId, -1 );
2773   createMenu( 6001, ctrlId, -1 );
2774   createMenu( 6004, ctrlId, -1 );
2775   createMenu( separator(), ctrlId, -1 );
2776   createMenu( 6002, ctrlId, -1 );
2777   createMenu( 6018, ctrlId, -1 );
2778   createMenu( 6019, ctrlId, -1 );
2779   createMenu( 6011, ctrlId, -1 );
2780   createMenu( 6012, ctrlId, -1 );
2781   createMenu( 6013, ctrlId, -1 );
2782   createMenu( 6014, ctrlId, -1 );
2783   createMenu( 6015, ctrlId, -1 );
2784   createMenu( 6016, ctrlId, -1 );
2785   createMenu( separator(), ctrlId, -1 );
2786   createMenu( 6017, ctrlId, -1 );
2787   createMenu( 6009, ctrlId, -1 );
2788   createMenu( separator(), ctrlId, -1 );
2789
2790   createMenu( 400, addId, -1 );
2791   createMenu( 401, addId, -1 );
2792   createMenu( 4021, addId, -1 );
2793   createMenu( 4022, addId, -1 );
2794   createMenu( 4023, addId, -1 );
2795   createMenu( 4031, addId, -1 );
2796   createMenu( 4032, addId, -1 );
2797   createMenu( 4033, addId, -1 );
2798   createMenu( separator(), addId, -1 );
2799   createMenu( 4034, addId, -1 );
2800   createMenu( 4035, addId, -1 );
2801   createMenu( 4036, addId, -1 );
2802   createMenu( 4037, addId, -1 );
2803   createMenu( 4038, addId, -1 );
2804   createMenu( 4039, addId, -1 );
2805   createMenu( 4040, addId, -1 );
2806
2807   createMenu( 4041, removeId, -1 );
2808   createMenu( 4042, removeId, -1 );
2809   createMenu( 4043, removeId, -1 );
2810
2811   createMenu( 4051, renumId, -1 );
2812   createMenu( 4052, renumId, -1 );
2813
2814   createMenu( 4061, transfId, -1 );
2815   createMenu( 4062, transfId, -1 );
2816   createMenu( 4063, transfId, -1 );
2817   createMenu( 4064, transfId, -1 );
2818   createMenu( 4065, transfId, -1 );
2819   createMenu( 4066, transfId, -1 );
2820
2821   createMenu( 406, modifyId, -1 );
2822   createMenu( 4067,modifyId, -1 );
2823   createMenu( 407, modifyId, -1 );
2824   createMenu( 408, modifyId, -1 );
2825   createMenu( 409, modifyId, -1 );
2826   createMenu( 410, modifyId, -1 );
2827   createMenu( 411, modifyId, -1 );
2828   createMenu( 412, modifyId, -1 );
2829   createMenu( 413, modifyId, -1 );
2830   createMenu( 416, modifyId, -1 );
2831   createMenu( 414, modifyId, -1 );
2832   createMenu( 415, modifyId, -1 );
2833   createMenu( 417, modifyId, -1 );
2834
2835   createMenu( 214, viewId, -1 );
2836
2837   // ----- create toolbars --------------
2838   int meshTb     = createTool( tr( "TB_MESH" ) ),
2839       ctrlTb     = createTool( tr( "TB_CTRL" ) ),
2840       addRemTb   = createTool( tr( "TB_ADD_REMOVE" ) ),
2841       modifyTb   = createTool( tr( "TB_MODIFY" ) ),
2842       dispModeTb = createTool( tr( "TB_DISP_MODE" ) );
2843
2844   createTool( 702, meshTb );
2845   createTool( 703, meshTb );
2846   createTool( 704, meshTb );
2847   createTool( 710, meshTb );
2848   createTool( separator(), meshTb );
2849   createTool( 701, meshTb );
2850   createTool( separator(), meshTb );
2851   createTool( 801, meshTb );
2852   createTool( 806, meshTb );
2853   createTool( 802, meshTb );
2854   createTool( 803, meshTb );
2855   createTool( separator(), meshTb );
2856   createTool( 900, meshTb );
2857   createTool( 902, meshTb );
2858   createTool( 903, meshTb );
2859   createTool( separator(), meshTb );
2860
2861   createTool( 6001, ctrlTb );
2862   createTool( 6003, ctrlTb );
2863   createTool( 6004, ctrlTb );
2864   createTool( separator(), ctrlTb );
2865   createTool( 6002, ctrlTb );
2866   createTool( 6018, ctrlTb );
2867   createTool( 6019, ctrlTb );
2868   createTool( 6011, ctrlTb );
2869   createTool( 6012, ctrlTb );
2870   createTool( 6013, ctrlTb );
2871   createTool( 6014, ctrlTb );
2872   createTool( 6015, ctrlTb );
2873   createTool( 6016, ctrlTb );
2874   createTool( separator(), ctrlTb );
2875   createTool( 6017, ctrlTb );
2876   createTool( 6009, ctrlTb );
2877   createTool( separator(), ctrlTb );
2878
2879   createTool( 400, addRemTb );
2880   createTool( 401, addRemTb );
2881   createTool( 4021, addRemTb );
2882   createTool( 4022, addRemTb );
2883   createTool( 4023, addRemTb );
2884   createTool( 4031, addRemTb );
2885   createTool( 4032, addRemTb );
2886   createTool( 4033, addRemTb );
2887   createTool( separator(), addRemTb );
2888   createTool( 4034, addRemTb );
2889   createTool( 4035, addRemTb );
2890   createTool( 4036, addRemTb );
2891   createTool( 4037, addRemTb );
2892   createTool( 4038, addRemTb );
2893   createTool( 4039, addRemTb );
2894   createTool( 4040, addRemTb );
2895   createTool( separator(), addRemTb );
2896   createTool( 4041, addRemTb );
2897   createTool( 4042, addRemTb );
2898   createTool( 4043, addRemTb );
2899   createTool( separator(), addRemTb );
2900   createTool( 4051, addRemTb );
2901   createTool( 4052, addRemTb );
2902   createTool( separator(), addRemTb );
2903   createTool( 4061, addRemTb );
2904   createTool( 4062, addRemTb );
2905   createTool( 4063, addRemTb );
2906   createTool( 4064, addRemTb );
2907   createTool( 4065, addRemTb );
2908   createTool( 4066, addRemTb );
2909   createTool( separator(), addRemTb );
2910
2911   createTool( 406, modifyTb );
2912   createTool( 4067,modifyTb );
2913   createTool( 407, modifyTb );
2914   createTool( 408, modifyTb );
2915   createTool( 409, modifyTb );
2916   createTool( 410, modifyTb );
2917   createTool( 411, modifyTb );
2918   createTool( 412, modifyTb );
2919   createTool( 413, modifyTb );
2920   createTool( 416, modifyTb );
2921   createTool( 414, modifyTb );
2922   createTool( 415, modifyTb );
2923   createTool( 417, modifyTb );
2924
2925   createTool( 214, dispModeTb );
2926
2927
2928   myRules.clear();
2929   QString OB = "'ObjectBrowser'",
2930           View = "'" + SVTK_Viewer::Type() + "'",
2931           pat = "'%1'",
2932           mesh    = pat.arg( SMESHGUI_Selection::typeName( MESH ) ),
2933           group   = pat.arg( SMESHGUI_Selection::typeName( GROUP ) ),
2934           hypo    = pat.arg( SMESHGUI_Selection::typeName( HYPOTHESIS ) ),
2935           algo    = pat.arg( SMESHGUI_Selection::typeName( ALGORITHM ) ),
2936           elems   = QString( "'%1' '%2' '%3' '%4' '%5' '%6'" ).
2937                        arg( SMESHGUI_Selection::typeName( SUBMESH_VERTEX ) ).
2938                        arg( SMESHGUI_Selection::typeName( SUBMESH_EDGE ) ).
2939                        arg( SMESHGUI_Selection::typeName( SUBMESH_FACE ) ).
2940                        arg( SMESHGUI_Selection::typeName( SUBMESH_SOLID ) ).
2941                        arg( SMESHGUI_Selection::typeName( SUBMESH_COMPOUND ) ).
2942                        arg( SMESHGUI_Selection::typeName( SUBMESH ) ),
2943           subMesh = elems,
2944           mesh_group = mesh + " " + subMesh + " " + group,
2945           hyp_alg = hypo + " " + algo;
2946
2947   // popup for object browser
2948
2949   createPopupItem( 150, OB, mesh, "&& selcount=1 && isImported" );      // FILE INFORMATION
2950   
2951   createPopupItem( 704, OB, mesh, "&& isComputable");      // EDIT_MESHSUBMESH
2952   createPopupItem( 704, OB, subMesh, "&& isComputable" );  // EDIT_MESHSUBMESH
2953   createPopupItem( 803, OB, group );                       // EDIT_GROUP
2954   popupMgr()->insert( separator(), -1, 0 );
2955   createPopupItem( 701, OB, mesh, "&& isComputable" );     // COMPUTE
2956   createPopupItem( 214, OB, mesh_group );                  // UPDATE
2957   createPopupItem( 900, OB, mesh_group );                  // ADV_INFO
2958   createPopupItem( 902, OB, mesh );                        // STD_INFO
2959   createPopupItem( 903, OB, mesh_group );                  // WHAT_IS
2960   popupMgr()->insert( separator(), -1, 0 );
2961   createPopupItem( 801, OB, mesh );                        // CREATE_GROUP
2962   createPopupItem( 806, OB, mesh );                        // CREATE_GEO_GROUP
2963   createPopupItem( 802, OB, subMesh );                     // CONSTRUCT_GROUP
2964   popupMgr()->insert( separator(), -1, 0 );
2965   createPopupItem( 1100, OB, hypo);                        // EDIT HYPOTHESIS
2966   createPopupItem( 1102, OB, hyp_alg ); // REMOVE HYPOTHESIS / ALGORITHMS
2967   createPopupItem( 1101, OB, mesh_group + " " + hyp_alg ); // RENAME
2968   popupMgr()->insert( separator(), -1, 0 );
2969   createPopupItem( 4043, OB, mesh );                       // CLEAR_MESH
2970   popupMgr()->insert( separator(), -1, 0 );
2971
2972   QString         nbSelected = QtxPopupMgr::Selection::defSelCountParam();
2973   QString only_one_non_empty = QString( " && %1=1 && numberOfNodes>0" ).arg( nbSelected );
2974
2975   createPopupItem( 125, OB, mesh, only_one_non_empty );   // EXPORT_MED
2976   createPopupItem( 126, OB, mesh, only_one_non_empty );   // EXPORT_UNV
2977   createPopupItem( 141, OB, mesh, only_one_non_empty );   // EXPORT_STL
2978   //createPopupItem( 33, OB, subMesh + " " + group );       // DELETE
2979   createPopupItem(  33, OB, mesh_group + " " + hyp_alg ); // DELETE
2980   popupMgr()->insert( separator(), -1, 0 );
2981
2982   // popup for viewer
2983   createPopupItem( 803, View, group ); // EDIT_GROUP
2984   createPopupItem( 804, View, elems ); // ADD
2985   createPopupItem( 805, View, elems ); // REMOVE
2986   popupMgr()->insert( separator(), -1, 0 );
2987   createPopupItem( 214, View, mesh_group ); // UPDATE
2988   createPopupItem( 900, View, mesh_group ); // ADV_INFO
2989   createPopupItem( 902, View, mesh );       // STD_INFO
2990   createPopupItem( 903, View, mesh_group ); // WHAT_IS
2991   popupMgr()->insert( separator(), -1, 0 );
2992
2993   createPopupItem( 1136, OB + " " + View, mesh, "&& (not isAutoColor)" ); // AUTO_COLOR
2994   createPopupItem( 1137, OB + " " + View, mesh, "&& isAutoColor" );       // DISABLE_AUTO_COLOR
2995   popupMgr()->insert( separator(), -1, 0 );
2996
2997   int anId;
2998   QString
2999     isInvisible("not( isVisible )"),
3000     isEmpty("numberOfNodes = 0"),
3001     isNotEmpty("numberOfNodes <> 0"),
3002
3003     // has nodes, edges, etc in VISIBLE! actor
3004     hasNodes("(numberOfNodes > 0 )"),//&& isVisible)"),
3005     hasElems("(count( elemTypes ) > 0)"),
3006     hasDifferentElems("(count( elemTypes ) > 1)"),
3007     hasEdges("({'Edge'} in elemTypes)"),
3008     hasFaces("({'Face'} in elemTypes)"),
3009     hasVolumes("({'Volume'} in elemTypes)");
3010
3011   QString lc = QtxPopupMgr::Selection::defEquality();
3012   QString aClient = QString( "%1client in {%2}" ).arg( lc ).arg( "'VTKViewer'" );
3013   QString aType = QString( "%1type in {%2}" ).arg( QtxPopupMgr::Selection::defEquality() );
3014   aType = aType.arg( mesh_group );
3015   QString aMeshInVTK = aClient + "&&" + aType;
3016
3017   aClient = "($client in {'VTKViewer' 'ObjectBrowser'})";
3018   QString anActiveVTK = QString("activeView = '%1'").arg(SVTK_Viewer::Type());
3019   QString aSelCount = QString( "%1 > 0" ).arg( QtxPopupMgr::Selection::defSelCountParam() );
3020
3021   //-------------------------------------------------
3022   // Numbering
3023   //-------------------------------------------------
3024   anId = popupMgr()->insert( tr( "MEN_NUM" ), -1, -1 );
3025
3026   popupMgr()->insert( action( 9010 ), anId, -1 );
3027   popupMgr()->setRule( action( 9010 ), aMeshInVTK + "&& isVisible &&" + hasNodes, true );
3028   popupMgr()->setRule( action( 9010 ), "{'Point'} in labeledTypes", false );
3029
3030   popupMgr()->insert( action( 9011 ), anId, -1 );
3031   popupMgr()->setRule( action( 9011 ), aMeshInVTK + "&& isVisible &&" + hasElems, true );
3032   popupMgr()->setRule( action( 9011 ), "{'Cell'} in labeledTypes", false );
3033
3034   popupMgr()->insert( separator(), -1, -1 );
3035
3036   //-------------------------------------------------
3037   // Display Mode
3038   //-------------------------------------------------
3039   anId = popupMgr()->insert( tr( "MEN_DISPMODE" ), -1, -1 );
3040
3041   popupMgr()->insert( action( 211 ), anId, -1 ); // WIRE
3042   popupMgr()->setRule( action( 211 ), aMeshInVTK + "&&" + hasElems, true );
3043   popupMgr()->setRule( action( 211 ), "displayMode = 'eEdge'", false );
3044
3045   popupMgr()->insert( action( 212 ), anId, -1 ); // SHADE
3046   popupMgr()->setRule( action( 212 ),aMeshInVTK+ "&& (" + hasFaces + "||" + hasVolumes + ")",true);
3047   popupMgr()->setRule( action( 212 ), "displayMode = 'eSurface'", false );
3048
3049   popupMgr()->insert( action( 215 ), anId, -1 ); // POINTS
3050   popupMgr()->setRule( action( 215 ), aMeshInVTK + "&&" + hasNodes, true );
3051   popupMgr()->setRule( action( 215 ), "displayMode = 'ePoint'", false );
3052
3053   popupMgr()->insert( separator(), anId, -1 );
3054
3055   popupMgr()->insert( action( 213 ), anId, -1 ); // SHRINK
3056   popupMgr()->setRule( action( 213 ), aMeshInVTK + "&& shrinkMode <> 'IsNotShrinkable' && displayMode <> 'ePoint'",true);
3057   popupMgr()->setRule( action( 213 ), "shrinkMode = 'IsShrunk'", false );
3058
3059   //-------------------------------------------------
3060   // Display Entity
3061   //-------------------------------------------------
3062   QString aDiffElemsInVTK = aMeshInVTK + "&&" + hasDifferentElems;
3063
3064   anId = popupMgr()->insert( tr( "MEN_DISP_ENT" ), -1, -1 );
3065
3066   popupMgr()->insert( action( 217 ), anId, -1 ); // EDGES
3067   popupMgr()->setRule( action( 217 ), aDiffElemsInVTK + "&& isVisible &&" + hasEdges, true );
3068   popupMgr()->setRule( action( 217 ), "{'Edge'} in entityMode", false );
3069
3070   popupMgr()->insert( action( 218 ), anId, -1 ); // FACES
3071   popupMgr()->setRule( action( 218 ), aDiffElemsInVTK + "&& isVisible &&" + hasFaces, true );
3072   popupMgr()->setRule( action( 218 ), "{'Face'} in entityMode", false );
3073
3074   popupMgr()->insert( action( 219 ), anId, -1 ); // VOLUMES
3075   popupMgr()->setRule( action( 219 ), aDiffElemsInVTK + "&& isVisible &&" + hasVolumes, true );
3076   popupMgr()->setRule( action( 219 ), "{'Volume'} in entityMode", false );
3077
3078   popupMgr()->insert( separator(), anId, -1 );
3079
3080   popupMgr()->insert( action( 220 ), anId, -1 ); // ALL
3081   popupMgr()->setRule( action( 220 ), aDiffElemsInVTK + "&& isVisible && not( elemTypes in entityMode )", true );
3082
3083   //-------------------------------------------------
3084   // Color / Size
3085   //-------------------------------------------------
3086   popupMgr()->insert( action( 1132 ), -1, -1 );
3087   popupMgr()->setRule( action( 1132 ), aMeshInVTK + "&& isVisible", true );
3088
3089   //-------------------------------------------------
3090   // Transparency
3091   //-------------------------------------------------
3092   popupMgr()->insert( action( 1133 ), -1, -1 );
3093   popupMgr()->setRule( action( 1133 ), aMeshInVTK + "&& isVisible", true );
3094
3095   //-------------------------------------------------
3096   // Clipping
3097   //-------------------------------------------------
3098   popupMgr()->insert( action( 1134 ), -1, -1 );
3099   popupMgr()->setRule( action( 1134 ), aMeshInVTK + "&& isVisible", true );
3100
3101   popupMgr()->insert( separator(), -1, -1 );
3102
3103   //-------------------------------------------------
3104   // Controls
3105   //-------------------------------------------------
3106   QString
3107     aMeshInVtkHasEdges = aMeshInVTK + "&&" + hasEdges,
3108     aMeshInVtkHasFaces = aMeshInVTK + "&&" + hasFaces,
3109     aMeshInVtkHasVolumes = aMeshInVTK + "&&" + hasVolumes;
3110
3111   anId = popupMgr()->insert( tr( "MEN_CTRL" ), -1, -1 );
3112
3113   popupMgr()->insert( action( 200 ), anId, -1 ); // RESET
3114   popupMgr()->setRule( action( 200 ), aMeshInVTK + "&& controlMode <> 'eNone'", true );
3115
3116   popupMgr()->insert( separator(), anId, -1 );
3117
3118   popupMgr()->insert( action( 6003 ), anId, -1 ); // FREE_BORDER
3119   popupMgr()->setRule( action( 6003 ), aMeshInVtkHasEdges, true );
3120   popupMgr()->setRule( action( 6003 ), "controlMode = 'eFreeBorders'", false );
3121
3122   popupMgr()->insert( action( 6001 ), anId, -1 ); // LENGTH
3123   popupMgr()->setRule( action( 6001 ), aMeshInVtkHasEdges, true );
3124   popupMgr()->setRule( action( 6001 ), "controlMode = 'eLength'", false );
3125
3126   popupMgr()->insert( action( 6004 ), anId, -1 ); // CONNECTION
3127   popupMgr()->setRule( action( 6004 ), aMeshInVtkHasEdges, true );
3128   popupMgr()->setRule( action( 6004 ), "controlMode = 'eMultiConnection'", false );
3129
3130   popupMgr()->insert( separator(), anId, -1 );
3131
3132   popupMgr()->insert( action( 6002 ), anId, -1 ); // FREE_EDGE
3133   popupMgr()->setRule( action( 6002 ), aMeshInVtkHasFaces, true );
3134   popupMgr()->setRule( action( 6002 ), "controlMode = 'eFreeEdges'", false );
3135
3136   popupMgr()->insert( action( 6018 ), anId, -1 ); // LENGTH_2D
3137   popupMgr()->setRule( action( 6018 ), aMeshInVtkHasFaces, true );
3138   popupMgr()->setRule( action( 6018 ), "controlMode = 'eLength2D'", false );
3139
3140   popupMgr()->insert( action( 6019 ), anId, -1 ); // CONNECTION_2D
3141   popupMgr()->setRule( action( 6019 ), aMeshInVtkHasFaces, true );
3142   popupMgr()->setRule( action( 6019 ), "controlMode = 'eMultiConnection2D'", false );
3143
3144   popupMgr()->insert( action( 6011 ), anId, -1 ); // AREA
3145   popupMgr()->setRule( action( 6011 ), aMeshInVtkHasFaces, true );
3146   popupMgr()->setRule( action( 6011 ), "controlMode = 'eArea'", false );
3147
3148   popupMgr()->insert( action( 6012 ), anId, -1 ); // TAPER
3149   popupMgr()->setRule( action( 6012 ), aMeshInVtkHasFaces, true );
3150   popupMgr()->setRule( action( 6012 ), "controlMode = 'eTaper'", false );
3151
3152   popupMgr()->insert( action( 6013 ), anId, -1 ); // ASPECT
3153   popupMgr()->setRule( action( 6013 ), aMeshInVtkHasFaces, true );
3154   popupMgr()->setRule( action( 6013 ), "controlMode = 'eAspectRatio'", false );
3155
3156   popupMgr()->insert( action( 6014 ), anId, -1 ); // MIN_ANG
3157   popupMgr()->setRule( action( 6014 ), aMeshInVtkHasFaces, true );
3158   popupMgr()->setRule( action( 6014 ), "controlMode = 'eMinimumAngle'", false );
3159
3160   popupMgr()->insert( action( 6015 ), anId, -1 ); // WARP
3161   popupMgr()->setRule( action( 6015 ), aMeshInVtkHasFaces, true );
3162   popupMgr()->setRule( action( 6015 ), "controlMode = 'eWarping'", false );
3163
3164   popupMgr()->insert( action( 6016 ), anId, -1 ); // SKEW
3165   popupMgr()->setRule( action( 6016 ), aMeshInVtkHasFaces, true );
3166   popupMgr()->setRule( action( 6016 ), "controlMode = 'eSkew'", false );
3167
3168   popupMgr()->insert( separator(), anId, -1 );
3169
3170   popupMgr()->insert( action( 6017 ), anId, -1 ); // ASPECT_3D
3171   popupMgr()->setRule( action( 6017 ), aMeshInVtkHasVolumes, true );
3172   popupMgr()->setRule( action( 6017 ), "controlMode = 'eAspectRatio3D'", false );
3173
3174   popupMgr()->insert ( action( 6009 ), anId, -1 ); // VOLUME_3D
3175   popupMgr()->setRule( action( 6009 ), aMeshInVtkHasVolumes, true );
3176   popupMgr()->setRule( action( 6009 ), "controlMode = 'eVolume3D'", false );
3177
3178   popupMgr()->insert( separator(), anId, -1 );
3179
3180   popupMgr()->insert( action( 201 ), anId, -1 ); // SCALAR_BAR_PROP
3181   popupMgr()->setRule( action( 201 ), aMeshInVTK + "&& controlMode <> 'eNone'", true );
3182
3183   popupMgr()->insert( separator(), -1, -1 );
3184
3185   //-------------------------------------------------
3186   // Display / Erase
3187   //-------------------------------------------------
3188   QString aRule = "$component={'SMESH'} and ( type='Component' or (" + aClient + " and " +
3189     aType + " and " + aSelCount + " and " + anActiveVTK + " and " + isNotEmpty + " %1 ) )";
3190   popupMgr()->insert( action( 301 ), -1, -1 ); // DISPLAY
3191   popupMgr()->setRule( action( 301 ), aRule.arg( "and (not isVisible)" ), true);
3192
3193   popupMgr()->insert( action( 300 ), -1, -1 ); // ERASE
3194   popupMgr()->setRule( action( 300 ), aRule.arg( "and isVisible" ), true );
3195
3196   popupMgr()->insert( action( 302 ), -1, -1 ); // DISPLAY_ONLY
3197   popupMgr()->setRule( action( 302 ), aRule.arg( "" ), true );
3198
3199   popupMgr()->insert( separator(), -1, -1 );
3200
3201   connect( application(), SIGNAL( viewManagerActivated( SUIT_ViewManager* ) ),
3202            this, SLOT( onViewManagerActivated( SUIT_ViewManager* ) ) );
3203 }
3204
3205 //================================================================================
3206 /*!
3207  * \brief Return true if SMESH or GEOM objects are selected.
3208  * Is called form LightApp_Module::activateModule() which clear selection if
3209  * not isSelectionCompatible()
3210  */
3211 //================================================================================
3212
3213 bool SMESHGUI::isSelectionCompatible()
3214 {
3215   bool isCompatible = true;
3216   SALOME_ListIO selected;
3217   if ( LightApp_SelectionMgr *Sel = selectionMgr() )
3218     Sel->selectedObjects( selected );
3219
3220   SALOME_ListIteratorOfListIO It( selected );
3221   for ( ; isCompatible && It.More(); It.Next())
3222     isCompatible =
3223       ( strcmp("GEOM", It.Value()->getComponentDataType()) == 0 ) ||
3224       ( strcmp("SMESH", It.Value()->getComponentDataType()) == 0 );
3225
3226   return isCompatible;
3227 }
3228
3229 bool SMESHGUI::activateModule( SUIT_Study* study )
3230 {
3231   bool res = SalomeApp_Module::activateModule( study );
3232
3233   setMenuShown( true );
3234   setToolShown( true );
3235
3236   // Reset actions accelerator keys
3237   action(111)->setAccel(QKeySequence(CTRL + Key_B)); // Import DAT
3238   action(112)->setAccel(QKeySequence(CTRL + Key_U)); // Import UNV
3239   action(113)->setAccel(QKeySequence(CTRL + Key_M)); // Import MED
3240
3241   action(  33)->setEnabled(true); // Delete: Key_Delete
3242   action(1101)->setEnabled(true); // Rename: Key_F2
3243
3244   return res;
3245 }
3246
3247 bool SMESHGUI::deactivateModule( SUIT_Study* study )
3248 {
3249   setMenuShown( false );
3250   setToolShown( false );
3251
3252   EmitSignalCloseAllDialogs();
3253
3254   // Unset actions accelerator keys
3255   action(111)->setAccel(QKeySequence()); // Import DAT
3256   action(112)->setAccel(QKeySequence()); // Import UNV
3257   action(113)->setAccel(QKeySequence()); // Import MED
3258
3259   action(  33)->setEnabled(false); // Delete: Key_Delete
3260   action(1101)->setEnabled(false); // Rename: Key_F2
3261
3262   return SalomeApp_Module::deactivateModule( study );
3263 }
3264
3265 void SMESHGUI::studyClosed( SUIT_Study* s )
3266 {
3267   SMESH::RemoveVisuData( s->id() );
3268   SalomeApp_Module::studyClosed( s );
3269 }
3270
3271 void SMESHGUI::OnGUIEvent()
3272 {
3273   const QObject* obj = sender();
3274   if ( !obj || !obj->inherits( "QAction" ) )
3275     return;
3276   int id = actionId((QAction*)obj);
3277   if ( id != -1 )
3278     OnGUIEvent( id );
3279 }
3280
3281 SMESH::SMESH_Gen_var SMESHGUI::GetSMESHGen()
3282 {
3283   _PTR(Study) aStudy = SMESH::GetActiveStudyDocument(); //Document OCAF de l'etude active
3284   if ( CORBA::is_nil( myComponentSMESH ) )
3285     {
3286       SMESHGUI aGUI; //SRN BugID: IPAL9186: Create an instance of SMESHGUI to initialize myComponentSMESH
3287       if ( aStudy )
3288         aGUI.myComponentSMESH->SetCurrentStudy(_CAST(Study,aStudy)->GetStudy());
3289       return aGUI.myComponentSMESH;
3290     }
3291   if ( aStudy )
3292     myComponentSMESH->SetCurrentStudy(_CAST(Study,aStudy)->GetStudy());
3293   return myComponentSMESH;
3294 }
3295
3296 QString SMESHGUI::engineIOR() const
3297 {
3298   CORBA::ORB_var anORB = getApp()->orb();
3299   CORBA::String_var anIOR = anORB->object_to_string(GetSMESHGen());
3300   return QString( anIOR.in() );
3301 }
3302
3303 void SMESHGUI::contextMenuPopup( const QString& client, QPopupMenu* menu, QString& title )
3304 {
3305   SMESHGUI_Selection sel;
3306   sel.init( client, selectionMgr() );
3307   popupMgr()->updatePopup( menu, &sel );
3308
3309   SALOME_ListIO lst;
3310   selectionMgr()->selectedObjects( lst );
3311   if ( ( client == "OCCViewer" || client == "VTKViewer" ) && lst.Extent() == 1 ) {
3312     Handle(SALOME_InteractiveObject) io = lst.First();
3313     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( application()->activeStudy() );
3314     _PTR(Study) study = appStudy->studyDS();
3315     _PTR(SObject) obj = study->FindObjectID( io->getEntry() );
3316     if ( obj ) {
3317       QString aName = QString( obj->GetName().c_str() );
3318       while ( aName.at( aName.length() - 1 ) == ' ' ) // Remove extraspaces in Name of Popup
3319           aName.remove( (aName.length() - 1), 1 );
3320       title = aName;
3321     }
3322   }
3323 }
3324
3325 void SMESHGUI::windows( QMap<int, int>& aMap ) const
3326 {
3327   aMap.insert( SalomeApp_Application::WT_ObjectBrowser, Qt::DockLeft );
3328   aMap.insert( SalomeApp_Application::WT_PyConsole, Qt::DockBottom );
3329 }
3330
3331 void SMESHGUI::viewManagers( QStringList& list ) const
3332 {
3333   list.append( SVTK_Viewer::Type() );
3334 }
3335
3336 void SMESHGUI::onViewManagerActivated( SUIT_ViewManager* mgr )
3337 {
3338   if ( dynamic_cast<SVTK_ViewManager*>( mgr ) )
3339     SMESH::UpdateSelectionProp( this );
3340 }
3341
3342 void SMESHGUI::createPreferences()
3343 {
3344   int genTab = addPreference( tr( "PREF_TAB_GENERAL" ) );
3345
3346   int updateGroup = addPreference( tr( "PREF_GROUP_UPDATE" ), genTab );
3347   addPreference( tr( "PREF_AUTO_UPDATE" ), updateGroup, LightApp_Preferences::Bool, "SMESH", "auto_update" );
3348
3349   int qaGroup = addPreference( tr( "PREF_GROUP_QUALITY" ), genTab );
3350   addPreference( tr( "PREF_DISPLAY_ENTITY" ), qaGroup, LightApp_Preferences::Bool, "SMESH", "display_entity" );
3351   addPreference( tr( "PREF_PRECISION_USE" ), qaGroup, LightApp_Preferences::Bool, "SMESH", "use_precision" );
3352
3353   int precGroup = addPreference( tr( "PREF_GROUP_PRECISION" ), genTab );
3354   setPreferenceProperty( precGroup, "columns", 1 );
3355
3356   int prec = addPreference( tr( "PREF_PRECISION_VALUE" ), precGroup, LightApp_Preferences::IntSpin, "SMESH", "controls_precision" );
3357
3358   setPreferenceProperty( prec, "min", 0 );
3359   setPreferenceProperty( prec, "max", 16 );
3360
3361   int dispgroup = addPreference( tr( "PREF_DISPLAY_MODE" ), genTab );
3362   int dispmode = addPreference( tr( "PREF_DISPLAY_MODE" ), dispgroup, LightApp_Preferences::Selector, "SMESH", "display_mode" );
3363   QStringList modes;
3364   modes.append( "Wireframe" );
3365   modes.append( "Shading" );
3366   modes.append( "Nodes" );
3367   modes.append( "Shrink" );
3368   QValueList<QVariant> indices;
3369   indices.append( 0 );
3370   indices.append( 1 );
3371   indices.append( 2 );
3372   indices.append( 3 );
3373   setPreferenceProperty( dispmode, "strings", modes );
3374   setPreferenceProperty( dispmode, "indexes", indices );
3375
3376   int exportgroup = addPreference( tr( "PREF_GROUP_EXPORT" ), genTab );
3377   addPreference( tr( "PREF_AUTO_GROUPS" ), exportgroup, LightApp_Preferences::Bool, "SMESH", "auto_groups" );
3378   addPreference( tr( "PREF_RENUMBER" ), exportgroup, LightApp_Preferences::Bool, "SMESH", "renumbering" );
3379
3380   int meshTab = addPreference( tr( "PREF_TAB_MESH" ) );
3381   int nodeGroup = addPreference( tr( "PREF_GROUP_NODES" ), meshTab );
3382
3383   addPreference( tr( "PREF_COLOR" ), nodeGroup, LightApp_Preferences::Color, "SMESH", "node_color" );
3384   int nodeSz = addPreference( tr( "PREF_SIZE" ), nodeGroup, LightApp_Preferences::IntSpin, "SMESH", "node_size" );
3385
3386   setPreferenceProperty( nodeSz, "min", 1 );
3387   setPreferenceProperty( nodeSz, "max", 5 );
3388
3389   int elemGroup = addPreference( tr( "PREF_GROUP_ELEMENTS" ), meshTab );
3390
3391   addPreference( tr( "PREF_FILL" ), elemGroup, LightApp_Preferences::Color, "SMESH", "fill_color" );
3392   addPreference( tr( "PREF_OUTLINE" ), elemGroup, LightApp_Preferences::Color, "SMESH", "outline_color" );
3393   addPreference( tr( "PREF_BACKFACE" ), elemGroup, LightApp_Preferences::Color, "SMESH", "backface_color" );
3394   addPreference( "", elemGroup, LightApp_Preferences::Space );
3395
3396   int elemW = addPreference( tr( "PREF_WIDTH" ), elemGroup, LightApp_Preferences::IntSpin, "SMESH", "element_width" );
3397   int shrink = addPreference( tr( "PREF_SHRINK_COEFF" ), elemGroup, LightApp_Preferences::IntSpin, "SMESH", "shrink_coeff" );
3398
3399   setPreferenceProperty( elemW, "min", 1 );
3400   setPreferenceProperty( elemW, "max", 5 );
3401
3402   setPreferenceProperty( shrink, "min", 0 );
3403   setPreferenceProperty( shrink, "max", 100 );
3404
3405   int selTab = addPreference( tr( "PREF_TAB_SELECTION" ) );
3406
3407   int selGroup = addPreference( tr( "PREF_GROUP_SELECTION" ), selTab );
3408
3409   addPreference( tr( "PREF_OBJECT_COLOR" ), selGroup, LightApp_Preferences::Color, "SMESH", "selection_object_color" );
3410   addPreference( tr( "PREF_ELEMENT_COLOR" ), selGroup, LightApp_Preferences::Color, "SMESH", "selection_element_color" );
3411   int selW = addPreference( tr( "PREF_WIDTH" ), selGroup, LightApp_Preferences::IntSpin, "SMESH", "selection_width" );
3412
3413   setPreferenceProperty( selW, "min", 1 );
3414   setPreferenceProperty( selW, "max", 5 );
3415
3416   int preGroup = addPreference( tr( "PREF_GROUP_PRESELECTION" ), selTab );
3417
3418   addPreference( tr( "PREF_HIGHLIGHT_COLOR" ), preGroup, LightApp_Preferences::Color, "SMESH", "highlight_color" );
3419   int preW = addPreference( tr( "PREF_WIDTH" ), preGroup, LightApp_Preferences::IntSpin, "SMESH", "highlight_width" );
3420
3421   setPreferenceProperty( preW, "min", 1 );
3422   setPreferenceProperty( preW, "max", 5 );
3423
3424   int precSelGroup = addPreference( tr( "PREF_GROUP_PRECISION" ), selTab );
3425
3426   addPreference( tr( "PREF_NODES" ), precSelGroup, LightApp_Preferences::Double, "SMESH", "selection_precision_node" );
3427   addPreference( tr( "PREF_ELEMENTS" ), precSelGroup, LightApp_Preferences::Double, "SMESH", "selection_precision_element" );
3428   addPreference( tr( "PREF_OBJECTS" ), precSelGroup, LightApp_Preferences::Double, "SMESH", "selection_precision_object" );
3429
3430   int sbarTab = addPreference( tr( "SMESH_SCALARBAR" ) );
3431   int fontGr = addPreference( tr( "SMESH_FONT_SCALARBAR" ), sbarTab );
3432
3433   int tfont = addPreference( tr( "SMESH_TITLE" ), fontGr, LightApp_Preferences::Font, "SMESH", "scalar_bar_title_font" );
3434   addPreference( tr( "PREF_TITLE_COLOR" ), fontGr, LightApp_Preferences::Color, "SMESH", "scalar_bar_title_color" );
3435   int lfont = addPreference( tr( "SMESH_LABELS" ), fontGr, LightApp_Preferences::Font, "SMESH", "scalar_bar_label_font" );
3436   addPreference( tr( "PREF_LABELS_COLOR" ), fontGr, LightApp_Preferences::Color, "SMESH", "scalar_bar_label_color" );
3437
3438   QStringList fam;
3439   fam.append( tr( "SMESH_FONT_ARIAL" ) );
3440   fam.append( tr( "SMESH_FONT_COURIER" ) );
3441   fam.append( tr( "SMESH_FONT_TIMES" ) );
3442   int wflag = ( QtxListResourceEdit::FontItem::All & ( ~( QtxListResourceEdit::FontItem::Size | QtxListResourceEdit::FontItem::UserSize ) ) );
3443
3444   setPreferenceProperty( tfont, "families", fam );
3445   setPreferenceProperty( tfont, "system", false );
3446   setPreferenceProperty( tfont, "widget_flags", wflag );
3447   setPreferenceProperty( lfont, "families", fam );
3448   setPreferenceProperty( lfont, "system", false );
3449   setPreferenceProperty( lfont, "widget_flags", wflag );
3450
3451   int colorsLabelsGr = addPreference( tr( "SMESH_LABELS_COLORS_SCALARBAR" ), sbarTab );
3452
3453   int numcol = addPreference( tr( "SMESH_NUMBEROFCOLORS" ), colorsLabelsGr, LightApp_Preferences::IntSpin, "SMESH", "scalar_bar_num_colors" );
3454   setPreferenceProperty( numcol, "min", 2 );
3455   setPreferenceProperty( numcol, "max", 256 );
3456
3457   int numlab = addPreference( tr( "SMESH_NUMBEROFLABELS" ), colorsLabelsGr, LightApp_Preferences::IntSpin, "SMESH", "scalar_bar_num_labels" );
3458   setPreferenceProperty( numlab, "min", 2 );
3459   setPreferenceProperty( numlab, "max", 65 );
3460
3461   int orientGr = addPreference( tr( "SMESH_ORIENTATION" ), sbarTab );
3462   int orient = addPreference( tr( "SMESH_ORIENTATION" ), orientGr, LightApp_Preferences::Selector, "SMESH", "scalar_bar_orientation" );
3463   QStringList orients;
3464   orients.append( tr( "SMESH_VERTICAL" ) );
3465   orients.append( tr( "SMESH_HORIZONTAL" ) );
3466   indices.clear(); indices.append( 0 ); indices.append( 1 );
3467   setPreferenceProperty( orient, "strings", orients );
3468   setPreferenceProperty( orient, "indexes", indices );
3469
3470   int posVSizeGr = addPreference( tr( "SMESH_POSITION_SIZE_SCALARBAR" ) + " " + tr( "SMESH_VERTICAL" ), sbarTab );
3471   int xv = addPreference( tr( "SMESH_X_SCALARBAR" ), posVSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_vertical_x" );
3472   int yv = addPreference( tr( "SMESH_Y_SCALARBAR" ), posVSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_vertical_y" );
3473   int wv = addPreference( tr( "SMESH_WIDTH" ), posVSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_vertical_width" );
3474   int hv = addPreference( tr( "SMESH_HEIGHT" ), posVSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_vertical_height" );
3475   setPreferenceProperty( xv, "step", 0.1 );
3476   setPreferenceProperty( xv, "min", 0.0 );
3477   setPreferenceProperty( xv, "max", 1.0 );
3478   setPreferenceProperty( yv, "step", 0.1 );
3479   setPreferenceProperty( yv, "min", 0.0 );
3480   setPreferenceProperty( yv, "max", 1.0 );
3481   setPreferenceProperty( wv, "step", 0.1 );
3482   setPreferenceProperty( wv, "min", 0.0 );
3483   setPreferenceProperty( wv, "max", 1.0 );
3484   setPreferenceProperty( hv, "min", 0.0 );
3485   setPreferenceProperty( hv, "max", 1.0 );
3486   setPreferenceProperty( hv, "step", 0.1 );
3487
3488   int posHSizeGr = addPreference( tr( "SMESH_POSITION_SIZE_SCALARBAR" ) + " " + tr( "SMESH_HORIZONTAL" ), sbarTab );
3489   int xh = addPreference( tr( "SMESH_X_SCALARBAR" ), posHSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_horizontal_x" );
3490   int yh = addPreference( tr( "SMESH_Y_SCALARBAR" ), posHSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_horizontal_y" );
3491   int wh = addPreference( tr( "SMESH_WIDTH" ), posHSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_horizontal_width" );
3492   int hh = addPreference( tr( "SMESH_HEIGHT" ), posHSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_horizontal_height" );
3493   setPreferenceProperty( xv, "min", 0.0 );
3494   setPreferenceProperty( xv, "max", 1.0 );
3495   setPreferenceProperty( xv, "step", 0.1 );
3496   setPreferenceProperty( xh, "min", 0.0 );
3497   setPreferenceProperty( xh, "max", 1.0 );
3498   setPreferenceProperty( xh, "step", 0.1 );
3499   setPreferenceProperty( yh, "min", 0.0 );
3500   setPreferenceProperty( yh, "max", 1.0 );
3501   setPreferenceProperty( yh, "step", 0.1 );
3502   setPreferenceProperty( wh, "min", 0.0 );
3503   setPreferenceProperty( wh, "max", 1.0 );
3504   setPreferenceProperty( wh, "step", 0.1 );
3505   setPreferenceProperty( hh, "min", 0.0 );
3506   setPreferenceProperty( hh, "max", 1.0 );
3507   setPreferenceProperty( hh, "step", 0.1 );
3508 }
3509
3510 void SMESHGUI::preferencesChanged( const QString& sect, const QString& name )
3511 {
3512   if( sect=="SMESH" ){
3513     float sbX1,sbY1,sbW,sbH;
3514     float aTol = 1.00000009999999;
3515     std::string aWarning;
3516     SUIT_ResourceMgr* aResourceMgr = SMESH::GetResourceMgr(this);
3517     if( name=="selection_object_color" || name=="selection_element_color" ||
3518         name=="selection_width" || name=="highlight_color" || name=="highlight_width" ||
3519         name=="selection_precision_node" || name=="selection_precision_element" ||
3520         name=="selection_precision_object")
3521       SMESH::UpdateSelectionProp( this );
3522     else if (name == QString("scalar_bar_vertical_x") || name == QString("scalar_bar_vertical_width")){
3523       sbX1 = aResourceMgr->doubleValue("SMESH", "scalar_bar_vertical_x", sbX1);
3524       sbW = aResourceMgr->doubleValue("SMESH", "scalar_bar_vertical_width", sbW);
3525       if(sbX1+sbW > aTol){
3526         aWarning = "Origin and Size Vertical: X+Width > 1\n";
3527         sbX1=0.01;
3528         sbW=0.05;
3529         aResourceMgr->setValue("SMESH", "scalar_bar_vertical_x", sbX1);
3530         aResourceMgr->setValue("SMESH", "scalar_bar_vertical_width", sbW);
3531       }
3532     }
3533     else if(name == QString("scalar_bar_vertical_y") || name == QString("scalar_bar_vertical_height")){
3534       sbY1 = aResourceMgr->doubleValue("SMESH", "scalar_bar_vertical_y", sbY1);
3535       sbH = aResourceMgr->doubleValue("SMESH", "scalar_bar_vertical_height",sbH);
3536       if(sbY1+sbH > aTol){
3537         aWarning = "Origin and Size Vertical: Y+Height > 1\n";
3538         aResourceMgr->setValue("SMESH", "scalar_bar_vertical_y", sbY1);
3539         aResourceMgr->setValue("SMESH", "scalar_bar_vertical_height",sbH);
3540       }
3541     }
3542     else if(name ==  QString("scalar_bar_horizontal_x") || name ==  QString("scalar_bar_horizontal_width")){
3543       sbX1 = aResourceMgr->doubleValue("SMESH", "scalar_bar_horizontal_x", sbX1);
3544       sbW = aResourceMgr->doubleValue("SMESH", "scalar_bar_horizontal_width", sbW);
3545       if(sbX1+sbW > aTol){
3546         aWarning = "Origin and Size Horizontal: X+Width > 1\n";
3547         sbX1=0.01;
3548         sbW=0.05;
3549         aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_x", sbX1);
3550         aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_width", sbW);
3551       }
3552     }
3553     else if(name ==  QString("scalar_bar_horizontal_y") || name ==  QString("scalar_bar_horizontal_height")){
3554       sbY1 = aResourceMgr->doubleValue("SMESH", "scalar_bar_horizontal_y", sbY1);
3555       sbH = aResourceMgr->doubleValue("SMESH", "scalar_bar_horizontal_height",sbH);
3556       if(sbY1+sbH > aTol){
3557         aWarning = "Origin and Size Horizontal: Y+Height > 1\n";
3558         sbY1=0.01;
3559         sbH=0.05;
3560         aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_y", sbY1);
3561         aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_height",sbH);
3562       }
3563     }
3564
3565     if(aWarning.size() != 0){
3566       aWarning += "The default values are applied instead.";
3567       SUIT_MessageBox::warn1(SMESHGUI::desktop(),
3568                              QObject::tr("SMESH_ERR_SCALARBAR_PARAMS"),
3569                              QObject::tr(aWarning.c_str()),
3570                              QObject::tr("SMESH_BUT_OK"));
3571     }
3572   }
3573 }
3574
3575 //================================================================================
3576 /*!
3577  * \brief Update something in accordance with update flags
3578   * \param theFlags - update flags
3579 *
3580 * Update viewer or/and object browser etc. in accordance with update flags ( see
3581 * LightApp_UpdateFlags enumeration ).
3582 */
3583 //================================================================================
3584 void SMESHGUI::update( const int flags )
3585 {
3586   if ( flags & UF_Viewer | flags & UF_Forced )
3587     SMESH::UpdateView();
3588   else
3589     SalomeApp_Module::update( flags );
3590 }
3591
3592 //================================================================================
3593 /*!
3594  * \brief Set default selection mode
3595 *
3596 * SLOT called when operation commited. Sets default selection mode
3597 */
3598 //================================================================================
3599 void SMESHGUI::onOperationCommited( SUIT_Operation* )
3600 {
3601   SVTK_ViewWindow* vtkWnd =
3602     dynamic_cast<SVTK_ViewWindow*>( application()->desktop()->activeWindow() );
3603   if ( vtkWnd )
3604     vtkWnd->SetSelectionMode( ActorSelection );
3605 }
3606
3607 //================================================================================
3608 /*!
3609  * \brief Set default selection mode
3610 *
3611 * SLOT called when operation aborted. Sets default selection mode
3612 */
3613 //================================================================================
3614 void SMESHGUI::onOperationAborted( SUIT_Operation* )
3615 {
3616   SVTK_ViewWindow* vtkWnd =
3617     dynamic_cast<SVTK_ViewWindow*>( application()->desktop()->activeWindow() );
3618   if ( vtkWnd )
3619     vtkWnd->SetSelectionMode( ActorSelection );
3620 }
3621
3622 //================================================================================
3623 /*!
3624  * \brief Creates operation with given identifier
3625   * \param id - identifier of operation to be started
3626   * \return Pointer on created operation or NULL if operation is not created
3627 *
3628 * Virtual method redefined from the base class creates operation with given id.
3629 * It is called called automatically from startOperation method of base class.
3630 */
3631 //================================================================================
3632 LightApp_Operation* SMESHGUI::createOperation( const int id ) const
3633 {
3634   LightApp_Operation* op = 0;
3635   // to do : create operation here
3636   switch( id )
3637   {
3638     case 701: // Compute mesh
3639       op = new SMESHGUI_ComputeOp();
3640     break;
3641     case 702: // Create mesh
3642       op = new SMESHGUI_MeshOp( true, true );
3643     break;
3644     case 703: // Create sub-mesh
3645       op = new SMESHGUI_MeshOp( true, false );
3646     break;
3647     case 704: // Edit mesh/sub-mesh
3648       op = new SMESHGUI_MeshOp( false );
3649     break;
3650     case 806: // Create group on geom
3651       op = new SMESHGUI_GroupOnShapeOp();
3652       break;
3653     case 417: //convert to quadratic
3654       op = new SMESHGUI_ConvToQuadOp();
3655     break;
3656     case 4067: // make mesh pass through point
3657       op = new SMESHGUI_MakeNodeAtPointOp();
3658       break;
3659     default:
3660     break;
3661   }
3662
3663   if( !op )
3664     op = SalomeApp_Module::createOperation( id );
3665   return op;
3666 }
3667
3668 //================================================================================
3669 /*!
3670  * \brief Stops current operations and starts a given one
3671   * \param id - The id of the operation to start
3672  */
3673 //================================================================================
3674
3675 void SMESHGUI::switchToOperation(int id)
3676 {
3677   if ( _PTR(Study) aStudy = SMESH::GetActiveStudyDocument() )
3678     activeStudy()->abortAllOperations();
3679   startOperation( id );
3680 }
3681
3682 LightApp_Displayer* SMESHGUI::displayer()
3683 {
3684   if( !myDisplayer )
3685     myDisplayer = new SMESHGUI_Displayer( getApp() );
3686   return myDisplayer;
3687 }
3688
3689 SALOMEDS::Color SMESHGUI::getUniqueColor( const QValueList<SALOMEDS::Color>& theReservedColors )
3690 {
3691   int aHue = -1;
3692   int aTolerance = 64;
3693   int anIterations = 0;
3694   int aPeriod = 5;
3695
3696   while( 1 )
3697   {
3698     anIterations++;
3699     if( anIterations % aPeriod == 0 )
3700     {
3701       aTolerance /= 2;
3702       if( aTolerance < 1 )
3703         break;
3704     }
3705     //cout << "Iteration N" << anIterations << " (tolerance=" << aTolerance << ")"<< endl;
3706
3707     aHue = (int)( 360.0 * rand() / RAND_MAX );
3708     //cout << "Hue = " << aHue << endl;
3709
3710     //cout << "Auto colors : ";
3711     bool ok = true;
3712     QValueList<SALOMEDS::Color>::const_iterator it = theReservedColors.constBegin();
3713     QValueList<SALOMEDS::Color>::const_iterator itEnd = theReservedColors.constEnd();
3714     for( ; it != itEnd; ++it )
3715     {
3716       SALOMEDS::Color anAutoColor = *it;
3717       QColor aQColor( (int)( anAutoColor.R * 255.0 ), (int)( anAutoColor.G * 255.0 ), (int)( anAutoColor.B * 255.0 ) );
3718
3719       int h, s, v;
3720       aQColor.getHsv( &h, &s, &v );
3721       //cout << h << " ";
3722       if( abs( h - aHue ) < aTolerance )
3723       {
3724         ok = false;
3725         //cout << "break (diff = " << abs( h - aHue ) << ")";
3726         break;
3727       }
3728     }
3729     //cout << endl;
3730
3731     if( ok )
3732       break;
3733   }
3734
3735   //cout << "Hue of the returned color = " << aHue << endl;
3736   QColor aColor;
3737   aColor.setHsv( aHue, 255, 255 );
3738
3739   SALOMEDS::Color aSColor;
3740   aSColor.R = (double)aColor.red() / 255.0;
3741   aSColor.G = (double)aColor.green() / 255.0;
3742   aSColor.B = (double)aColor.blue() / 255.0;
3743
3744   return aSColor;
3745 }