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