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