Salome HOME
Issue 0020755: EDF 1279 MESH : 'Mesh to Pass Through a Point' enhancement
[modules/smesh.git] / src / SMESHGUI / SMESHGUI.cxx
1 //  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 // SMESH SMESHGUI : GUI for SMESH component
24 // File   : SMESHGUI.cxx
25 // Author : Nicolas REJNERI, Open CASCADE S.A.S.
26 // SMESH includes
27 //
28 #include "SMESHGUI.h"
29 #include "SMESHGUI_AddMeshElementDlg.h"
30 #include "SMESHGUI_AddQuadraticElementDlg.h"
31 #include "SMESHGUI_BuildCompoundDlg.h"
32 #include "SMESHGUI_ClippingDlg.h"
33 #include "SMESHGUI_ComputeDlg.h"
34 #include "SMESHGUI_ConvToQuadOp.h"
35 #include "SMESHGUI_CreatePolyhedralVolumeDlg.h"
36 #include "SMESHGUI_DeleteGroupDlg.h"
37 #include "SMESHGUI_Displayer.h"
38 #include "SMESHGUI_EditMeshDlg.h"
39 #include "SMESHGUI_ExtrusionAlongPathDlg.h"
40 #include "SMESHGUI_ExtrusionDlg.h"
41 #include "SMESHGUI_FileInfoDlg.h"
42 #include "SMESHGUI_FileValidator.h"
43 #include "SMESHGUI_FilterDlg.h"
44 #include "SMESHGUI_FilterLibraryDlg.h"
45 #include "SMESHGUI_FindElemByPointDlg.h"
46 #include "SMESHGUI_GroupDlg.h"
47 #include "SMESHGUI_GroupOnShapeDlg.h"
48 #include "SMESHGUI_GroupOpDlg.h"
49 #include "SMESHGUI_Hypotheses.h"
50 #include "SMESHGUI_Make2DFrom3DOp.h"
51 #include "SMESHGUI_MakeNodeAtPointDlg.h"
52 #include "SMESHGUI_MeshInfosDlg.h"
53 #include "SMESHGUI_MeshOp.h"
54 #include "SMESHGUI_MeshOrderOp.h"
55 #include "SMESHGUI_MeshPatternDlg.h"
56 #include "SMESHGUI_MultiEditDlg.h"
57 #include "SMESHGUI_NodesDlg.h"
58 #include "SMESHGUI_Preferences_ColorDlg.h"
59 #include "SMESHGUI_Preferences_ScalarBarDlg.h"
60 #include "SMESHGUI_RemoveElementsDlg.h"
61 #include "SMESHGUI_RemoveNodesDlg.h"
62 #include "SMESHGUI_RenumberingDlg.h"
63 #include "SMESHGUI_RevolutionDlg.h"
64 #include "SMESHGUI_RotationDlg.h"
65 #include "SMESHGUI_Selection.h"
66 #include "SMESHGUI_SewingDlg.h"
67 #include "SMESHGUI_SingleEditDlg.h"
68 #include "SMESHGUI_SmoothingDlg.h"
69 #include "SMESHGUI_StandardMeshInfosDlg.h"
70 #include "SMESHGUI_SymmetryDlg.h"
71 #include "SMESHGUI_TranslationDlg.h"
72 #include "SMESHGUI_ScaleDlg.h"
73 #include "SMESHGUI_TransparencyDlg.h"
74 #include "SMESHGUI_WhatIsDlg.h"
75
76 #include "SMESHGUI_Utils.h"
77 #include "SMESHGUI_MeshUtils.h"
78 #include "SMESHGUI_GroupUtils.h"
79 #include "SMESHGUI_FilterUtils.h"
80 #include "SMESHGUI_PatternUtils.h"
81 #include "SMESHGUI_VTKUtils.h"
82 #include "SMESHGUI_HypothesesUtils.h"
83
84 #include <SMESH_Client.hxx>
85 #include <SMESH_Actor.h>
86 #include <SMESH_TypeFilter.hxx>
87
88 // SALOME GUI includes
89 #include <SalomeApp_Tools.h>
90 #include <SalomeApp_Study.h>
91 #include <SalomeApp_Application.h>
92 #include <SalomeApp_CheckFileDlg.h>
93
94 #include <LightApp_DataOwner.h>
95 #include <LightApp_Preferences.h>
96 #include <LightApp_SelectionMgr.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_ViewManager.h>
103
104 #include <VTKViewer_Algorithm.h>
105
106 #include <SUIT_MessageBox.h>
107 #include <SUIT_ResourceMgr.h>
108 #include <SUIT_FileDlg.h>
109 #include <SUIT_Desktop.h>
110 #include <SUIT_OverrideCursor.h>
111 #include <SUIT_Session.h>
112
113 #include <QtxPopupMgr.h>
114 #include <QtxFontEdit.h>
115
116 #include <SALOME_ListIO.hxx>
117 #include <SALOME_ListIteratorOfListIO.hxx>
118
119 // IDL includes
120 #include <SALOMEconfig.h>
121 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
122 #include CORBA_CLIENT_HEADER(SMESH_MeshEditor)
123
124 // Qt includes
125 // #define       INCLUDE_MENUITEM_DEF // VSR commented ????????
126 #include <QMenu>
127
128 // BOOST includes
129 #include <boost/shared_ptr.hpp>
130
131 // VTK includes
132 #include <vtkScalarBarActor.h>
133 #include <vtkCamera.h>
134 #include <vtkRenderer.h>
135 #include <vtkPlane.h>
136
137 // SALOME KERNEL includes
138 #include <SALOMEDS_Study.hxx>
139 #include <SALOMEDSClient_StudyBuilder.hxx>
140 #include <SALOMEDSClient_SComponent.hxx>
141 #include <SALOMEDSClient_ClientFactory.hxx>
142 #include <SALOMEDSClient_IParameters.hxx>
143
144 // OCCT includes
145 #include <Standard_ErrorHandler.hxx>
146 #include <NCollection_DataMap.hxx>
147
148 //namespace{
149   // Declarations
150   //=============================================================
151   void ImportMeshesFromFile(SMESH::SMESH_Gen_ptr theComponentMesh,
152                             int theCommandID);
153
154   void ExportMeshToFile(int theCommandID);
155
156   void SetDisplayMode(int theCommandID, SMESHGUI_StudyId2MarkerMap& theMarkerMap);
157
158   void SetDisplayEntity(int theCommandID);
159
160   void Control( int theCommandID );
161
162
163   // Definitions
164   //=============================================================
165   void ImportMeshesFromFile( SMESH::SMESH_Gen_ptr theComponentMesh,
166                              int theCommandID )
167   {
168     QStringList filter;
169     std::string myExtension;
170
171     if ( theCommandID == 113 ) {
172       filter.append( QObject::tr( "MED files (*.med)" ) );
173       filter.append( QObject::tr( "All files (*)" ) );
174     }
175     else if ( theCommandID == 112 ) {
176       filter.append( QObject::tr( "IDEAS files (*.unv)" ) );
177     }
178     else if ( theCommandID == 111 ) {
179       filter.append( QObject::tr( "DAT files (*.dat)" ) );
180     }
181
182     QString anInitialPath = "";
183     if ( SUIT_FileDlg::getLastVisitedPath().isEmpty() )
184       anInitialPath = QDir::currentPath();
185
186     QStringList filenames = SUIT_FileDlg::getOpenFileNames( SMESHGUI::desktop(),
187                                                             anInitialPath,
188                                                             filter,
189                                                             QObject::tr( "SMESH_IMPORT_MESH" ) );
190     if ( filenames.count() > 0 ) {
191       SUIT_OverrideCursor wc;
192       _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
193
194       QStringList errors;
195       bool isEmpty = false;
196       for ( QStringList::ConstIterator it = filenames.begin(); it != filenames.end(); ++it ) {
197         QString filename = *it;
198         SMESH::mesh_array_var aMeshes = new SMESH::mesh_array;
199         try {
200           switch ( theCommandID ) {
201           case 111:
202             {
203               // DAT format (currently unsupported)
204               errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
205                              arg( QObject::tr( "SMESH_ERR_NOT_SUPPORTED_FORMAT" ) ) );
206               break;
207             }
208           case 112:
209             {
210               // UNV format
211               aMeshes->length( 1 );
212               aMeshes[0] = theComponentMesh->CreateMeshesFromUNV( filename.toLatin1().constData() );
213               if ( aMeshes[0]->_is_nil() )
214                 errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
215                                arg( QObject::tr( "SMESH_ERR_UNKNOWN_IMPORT_ERROR" ) ) );
216               break;
217             }
218           case 113:
219             {
220               // MED format
221               SMESH::DriverMED_ReadStatus res;
222               aMeshes = theComponentMesh->CreateMeshesFromMED( filename.toLatin1().constData(), res );
223               if ( res != SMESH::DRS_OK ) {
224                 errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
225                                arg( QObject::tr( QString( "SMESH_DRS_%1" ).arg( res ).toLatin1().data() ) ) );
226               }
227               break;
228             }
229           }
230         }
231         catch ( const SALOME::SALOME_Exception& S_ex ) {
232           errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
233                          arg( QObject::tr( "SMESH_ERR_UNKNOWN_IMPORT_ERROR" ) ) );
234         }
235
236         for ( int i = 0, iEnd = aMeshes->length(); i < iEnd; i++ ) {
237           _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshes[i] );
238           if ( aMeshSO ) {
239             _PTR(StudyBuilder) aBuilder = aStudy->NewBuilder();
240             _PTR(AttributePixMap) aPixmap = aBuilder->FindOrCreateAttribute( aMeshSO, "AttributePixMap" );
241             aPixmap->SetPixMap( "ICON_SMESH_TREE_MESH_IMPORTED" );
242             if ( theCommandID == 112 ) // mesh names aren't taken from the file for UNV import
243               SMESH::SetName( aMeshSO, QFileInfo(filename).fileName() );
244           }
245           else {
246             isEmpty = true;
247           }
248         }
249       }
250
251       // update Object browser
252       SMESHGUI::GetSMESHGUI()->updateObjBrowser();
253
254       // show Error message box if there were errors
255       if ( errors.count() > 0 ) {
256         SUIT_MessageBox::critical( SMESHGUI::desktop(),
257                                    QObject::tr( "SMESH_ERROR" ),
258                                    QObject::tr( "SMESH_IMPORT_ERRORS" ) + "\n" + errors.join( "\n" ) );
259       }
260
261       // show warning message box, if some imported mesh is empty
262       if ( isEmpty ) {
263           SUIT_MessageBox::warning( SMESHGUI::desktop(),
264                                     QObject::tr( "SMESH_WRN_WARNING" ),
265                                     QObject::tr( "SMESH_DRS_SOME_EMPTY" ) );
266       }
267     }
268   }
269
270   void ExportMeshToFile( int theCommandID )
271   {
272     LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
273     SALOME_ListIO selected;
274     if( aSel )
275       aSel->selectedObjects( selected );
276
277     // actually, the following condition can't be met (added for insurance)
278     if( selected.Extent() == 0 ||
279         selected.Extent() > 1 && theCommandID != 122 && theCommandID != 125 )
280       return;
281
282     bool hasDuplicatedMeshNames = false;
283     QList< QPair< SMESH::SMESH_Mesh_var, QString > > aMeshList;
284     QList< QPair< SMESH::SMESH_Mesh_var, QString > >::iterator aMeshIter;
285     SALOME_ListIteratorOfListIO It( selected );
286     for( ; It.More(); It.Next() ) {
287       Handle(SALOME_InteractiveObject) anIObject = It.Value();
288       SMESH::SMESH_Mesh_var aMeshItem = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>( anIObject );
289       if ( aMeshItem->_is_nil() ) {
290         SUIT_MessageBox::warning( SMESHGUI::desktop(),
291                                   QObject::tr( "SMESH_WRN_WARNING" ),
292                                   QObject::tr( "SMESH_BAD_MESH_SELECTION" ));
293         return;
294       }
295
296       QString aMeshName = anIObject->getName();
297
298       // check for duplications
299       for( aMeshIter = aMeshList.begin(); aMeshIter != aMeshList.end(); aMeshIter++ ) {
300         if( aMeshName == (*aMeshIter).second ) {
301           hasDuplicatedMeshNames = true;
302           break;
303         }
304       }
305
306       aMeshList.append( QPair< SMESH::SMESH_Mesh_var, QString >( aMeshItem, aMeshName ) );
307     }
308
309     if( hasDuplicatedMeshNames ) {
310       int aRet = SUIT_MessageBox::warning(SMESHGUI::desktop(),
311                                           QObject::tr("SMESH_WRN_WARNING"),
312                                           QObject::tr("SMESH_EXPORT_MED_DUPLICATED_MESH_NAMES"),
313                                           QObject::tr("SMESH_BUT_YES"),
314                                           QObject::tr("SMESH_BUT_NO"), 0, 1);
315       if (aRet != 0)
316         return;
317     }
318
319     aMeshIter = aMeshList.begin();
320     SMESH::SMESH_Mesh_var aMesh = (*aMeshIter).first;
321     QString aMeshName = (*aMeshIter).second;
322
323     QList<SALOMEDS::Color> aReservedColors;
324
325     QString aFilter, aTitle = QObject::tr("Export mesh");
326     QMap<QString, SMESH::MED_VERSION> aFilterMap;
327     QMap<QString, int> aFilterMapSTL;
328     switch ( theCommandID ) {
329     case 125:
330     case 122:
331       {
332         for( aMeshIter = aMeshList.begin(); aMeshIter != aMeshList.end(); aMeshIter++ ) {
333           SMESH::SMESH_Mesh_var aMeshItem = (*aMeshIter).first;
334           if (aMeshItem->HasDuplicatedGroupNamesMED()) {
335             int aRet = SUIT_MessageBox::warning
336               (SMESHGUI::desktop(),
337                QObject::tr("SMESH_WRN_WARNING"),
338                QObject::tr("SMESH_EXPORT_MED_DUPLICATED_GRP").arg((*aMeshIter).second),
339                QObject::tr("SMESH_BUT_YES"),
340                QObject::tr("SMESH_BUT_NO"), 0, 1);
341             if (aRet != 0)
342               return;
343           }
344         }
345         // PAL18696
346         QString v21 (aMesh->GetVersionString(SMESH::MED_V2_1, 2));
347         QString v22 (aMesh->GetVersionString(SMESH::MED_V2_2, 2));
348         aFilterMap.insert( QString("MED ") +  v21 + " (*.med)", SMESH::MED_V2_1 );
349         aFilterMap.insert( QString("MED ") +  v22 + " (*.med)", SMESH::MED_V2_2 );
350       }
351       break;
352     case 124:
353     case 121:
354       aFilter = QObject::tr("DAT files (*.dat)");
355       break;
356     case 126:
357     case 123:
358       {
359         if (aMesh->NbPyramids()) {
360           int aRet = SUIT_MessageBox::warning
361             (SMESHGUI::desktop(),
362              QObject::tr("SMESH_WRN_WARNING"),
363              QObject::tr("SMESH_EXPORT_UNV").arg(aMeshName),
364              QObject::tr("SMESH_BUT_YES"),
365              QObject::tr("SMESH_BUT_NO"), 0, 1);
366           if (aRet != 0)
367             return;
368         }
369         aFilter = QObject::tr("IDEAS files (*.unv)");
370       }
371       break;
372     case 140:
373     case 141:
374       {
375         // export STL
376         /*
377           there must be check on others mesh elements not equal triangles
378         */
379         if (aMesh->NbTriangles() < 1) {
380           SUIT_MessageBox::warning
381             (SMESHGUI::desktop(),
382              QObject::tr("SMESH_WRN_WARNING"),
383              QObject::tr("SMESH_EXPORT_STL1").arg(aMeshName));
384           return;
385         }
386         if (!(aMesh->NbElements() - aMesh->NbTriangles())) {
387           int aRet = SUIT_MessageBox::warning
388             (SMESHGUI::desktop(),
389              QObject::tr("SMESH_WRN_WARNING"),
390              QObject::tr("SMESH_EXPORT_STL2").arg(aMeshName),
391              QObject::tr("SMESH_BUT_YES"),
392              QObject::tr("SMESH_BUT_NO"), 0, 1);
393           if (aRet != 0)
394             return;
395         }
396
397         aFilterMapSTL.insert( QObject::tr("STL ASCII (*.stl)"), 1 ); // 1 - ASCII mode
398         aFilterMapSTL.insert( QObject::tr("STL Binary (*.stl)"), 0 ); // 0 - Binary mode
399       }
400       break;
401     default:
402       return;
403     }
404
405     QString aFilename;
406     SMESH::MED_VERSION aFormat;
407     // Init the parameter with the default value
408     bool aIsASCII_STL = true;
409     bool toCreateGroups = false;
410     SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
411     if ( resMgr )
412       toCreateGroups = resMgr->booleanValue( "SMESH", "auto_groups", false );
413     bool toOverwrite = true;
414
415     QString anInitialPath = "";
416     if ( SUIT_FileDlg::getLastVisitedPath().isEmpty() )
417       anInitialPath = QDir::currentPath();
418
419     if ( theCommandID != 122 && theCommandID != 125 && theCommandID != 140 && theCommandID != 141) {
420       if ( anInitialPath.isEmpty() ) anInitialPath = SUIT_FileDlg::getLastVisitedPath();
421       aFilename = SUIT_FileDlg::getFileName(SMESHGUI::desktop(), anInitialPath + QString("/") + aMeshName,
422                                             aFilter, aTitle, false);
423     }
424     else if(theCommandID == 140 || theCommandID == 141) { // Export to STL
425       QStringList filters;
426       QMap<QString, int>::const_iterator it = aFilterMapSTL.begin();
427       for ( ; it != aFilterMapSTL.end(); ++it )
428         filters.push_back( it.key() );
429
430       SUIT_FileDlg* fd = new SUIT_FileDlg( SMESHGUI::desktop(), false, true, true );
431       fd->setWindowTitle( aTitle );
432       fd->setNameFilters( filters );
433       fd->selectNameFilter( QObject::tr("STL ASCII (*.stl)") );
434       if ( !anInitialPath.isEmpty() )
435         fd->setDirectory( anInitialPath );
436       fd->selectFile(aMeshName);
437       bool is_ok = false;
438       while (!is_ok) {
439         if ( fd->exec() )
440           aFilename = fd->selectedFile();
441         aIsASCII_STL = (aFilterMapSTL[fd->selectedNameFilter()]) == 1 ? true: false;
442         is_ok = true;
443       }
444       delete fd;
445     }
446     else { // Export to MED
447       QStringList filters;
448       QString aDefaultFilter;
449       QMap<QString, SMESH::MED_VERSION>::const_iterator it = aFilterMap.begin();
450       for ( ; it != aFilterMap.end(); ++it ) {
451         filters.push_back( it.key() );
452         if (it.value() == SMESH::MED_V2_2)
453           aDefaultFilter = it.key();
454       }
455
456       //SUIT_FileDlg* fd = new SUIT_FileDlg( SMESHGUI::desktop(), false, true, true );
457       SalomeApp_CheckFileDlg* fd = new SalomeApp_CheckFileDlg
458         ( SMESHGUI::desktop(), false, QObject::tr("SMESH_AUTO_GROUPS"), true, true );
459       fd->setWindowTitle( aTitle );
460       fd->setNameFilters( filters );
461       //fd->setSelectedNameFilter( QObject::tr("MED 2.2 (*.med)") );
462       fd->selectNameFilter(aDefaultFilter);
463       fd->SetChecked(toCreateGroups);
464       if ( !anInitialPath.isEmpty() )
465         fd->setDirectory( anInitialPath );
466       fd->selectFile(aMeshName);
467
468       SMESHGUI_FileValidator* fv = new SMESHGUI_FileValidator( fd );
469       fd->setValidator( fv );
470
471       bool is_ok = false;
472       while (!is_ok) {
473         if ( fd->exec() )
474           aFilename = fd->selectedFile();
475         else {
476           aFilename = QString::null;
477           break;
478         }
479         aFormat = aFilterMap[fd->selectedNameFilter()];
480         toOverwrite = fv->isOverwrite();
481         is_ok = true;
482         if ( !aFilename.isEmpty() ) {
483           for( aMeshIter = aMeshList.begin(); aMeshIter != aMeshList.end(); aMeshIter++ ) {
484             SMESH::SMESH_Mesh_var aMeshItem = (*aMeshIter).first;
485             if( (aMeshItem->NbPolygons()>0 || aMeshItem->NbPolyhedrons()>0)
486                 && aFormat==SMESH::MED_V2_1) {
487               int aRet = SUIT_MessageBox::warning(SMESHGUI::desktop(),
488                                                   QObject::tr("SMESH_WRN_WARNING"),
489                                                   QObject::tr("SMESH_EXPORT_MED_V2_1").arg((*aMeshIter).second),
490                                                   QObject::tr("SMESH_BUT_YES"),
491                                                   QObject::tr("SMESH_BUT_NO"), 0, 1);
492               if (aRet != 0) {
493                 is_ok = false;
494                 break;
495               }
496             }
497           }
498           if( !toOverwrite ) {
499             SMESH::MED_VERSION aVersion = SMESH::MED_V2_1;
500             bool isVersionOk = SMESHGUI::GetSMESHGen()->GetMEDVersion( aFilename.toLatin1().constData(), aVersion );
501             if( !isVersionOk || aVersion != aFormat ) {
502               int aRet = SUIT_MessageBox::warning(SMESHGUI::desktop(),
503                                                   QObject::tr("SMESH_WRN_WARNING"),
504                                                   QObject::tr("SMESH_EXPORT_MED_VERSION_COLLISION").arg(aFilename),
505                                                   QObject::tr("SMESH_BUT_YES"),
506                                                   QObject::tr("SMESH_BUT_NO"), 0, 1);
507               if (aRet == 0)
508                 toOverwrite = true;
509               else
510                 is_ok = false;
511             }
512
513             QStringList aMeshNamesCollisionList;
514             SMESH::string_array_var aMeshNames = SMESHGUI::GetSMESHGen()->GetMeshNames( aFilename.toLatin1().constData() );
515             for( int i = 0, n = aMeshNames->length(); i < n; i++ ) {
516               QString anExistingMeshName( aMeshNames[ i ] );
517               for( aMeshIter = aMeshList.begin(); aMeshIter != aMeshList.end(); aMeshIter++ ) {
518                 QString anExportMeshName = (*aMeshIter).second;
519                 if( anExportMeshName == anExistingMeshName ) {
520                   aMeshNamesCollisionList.append( anExportMeshName );
521                   break;
522                 }
523               }
524             }
525
526             if( !aMeshNamesCollisionList.isEmpty() ) {
527               QString aMeshNamesCollisionString = aMeshNamesCollisionList.join( ", " );
528               int aRet = SUIT_MessageBox::warning(SMESHGUI::desktop(),
529                                                   QObject::tr("SMESH_WRN_WARNING"),
530                                                   QObject::tr("SMESH_EXPORT_MED_MESH_NAMES_COLLISION").arg(aMeshNamesCollisionString),
531                                                   QObject::tr("SMESH_BUT_YES"),
532                                                   QObject::tr("SMESH_BUT_NO"),
533                                                   QObject::tr("SMESH_BUT_CANCEL"), 0, 2);
534               if (aRet == 0)
535                 toOverwrite = true;
536               else if (aRet == 2)
537                 is_ok = false;
538             }
539           }
540         }
541       }
542       toCreateGroups = fd->IsChecked();
543       delete fd;
544     }
545     if ( !aFilename.isEmpty() ) {
546       // Check whether the file already exists and delete it if yes
547       QFile aFile( aFilename );
548       if ( aFile.exists() && toOverwrite )
549         aFile.remove();
550       SUIT_OverrideCursor wc;
551
552       try {
553         bool Renumber = false;
554         // PAL 14172  : Check of we have to renumber or not from the preferences before export
555         if (resMgr)
556           Renumber= resMgr->booleanValue("SMESH","renumbering");
557         if (Renumber){
558           SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
559           aMeshEditor->RenumberNodes();
560           aMeshEditor->RenumberElements();
561           if ( SMESHGUI::automaticUpdate() )
562             SMESH::UpdateView();
563         }
564         switch ( theCommandID ) {
565         case 125:
566         case 122: {
567             int aMeshIndex = 0;
568             for( aMeshIter = aMeshList.begin(); aMeshIter != aMeshList.end(); aMeshIter++, aMeshIndex++ ) {
569               SMESH::SMESH_Mesh_var aMeshItem = (*aMeshIter).first;
570               if( !aMeshItem->_is_nil() )
571                 aMeshItem->ExportToMEDX( aFilename.toLatin1().data(), toCreateGroups, aFormat, toOverwrite && aMeshIndex == 0 );
572             }
573           }
574           break;
575         case 124:
576         case 121:
577           aMesh->ExportDAT( aFilename.toLatin1().data() );
578           break;
579         case 126:
580         case 123:
581           aMesh->ExportUNV( aFilename.toLatin1().data() );
582           break;
583         case 140:
584         case 141:
585           aMesh->ExportSTL( aFilename.toLatin1().data(), aIsASCII_STL );
586           break;
587         default:
588           break;
589         }
590       }
591       catch (const SALOME::SALOME_Exception& S_ex){
592         wc.suspend();
593         SUIT_MessageBox::warning(SMESHGUI::desktop(),
594                                  QObject::tr("SMESH_WRN_WARNING"),
595                                  QObject::tr("SMESH_EXPORT_FAILED"));
596         wc.resume();
597       }
598     }
599   }
600
601   inline void InverseEntityMode(unsigned int& theOutputMode,
602                                 unsigned int theMode)
603   {
604     bool anIsNotPresent = ~theOutputMode & theMode;
605     if(anIsNotPresent)
606       theOutputMode |= theMode;
607     else
608       theOutputMode &= ~theMode;
609   }
610
611   void SetDisplayEntity(int theCommandID){
612     LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
613     SALOME_ListIO selected;
614     if( aSel )
615       aSel->selectedObjects( selected );
616
617     if(selected.Extent() >= 1){
618       SALOME_ListIteratorOfListIO It( selected );
619       for( ; It.More(); It.Next()){
620         Handle(SALOME_InteractiveObject) IObject = It.Value();
621         if(IObject->hasEntry()){
622           if(SMESH_Actor *anActor = SMESH::FindActorByEntry(IObject->getEntry())){
623             unsigned int aMode = anActor->GetEntityMode();
624             switch(theCommandID){
625             case 216:
626               InverseEntityMode(aMode,SMESH_Actor::e0DElements);
627               break;
628             case 217:
629               InverseEntityMode(aMode,SMESH_Actor::eEdges);
630               break;
631             case 218:
632               InverseEntityMode(aMode,SMESH_Actor::eFaces);
633               break;
634             case 219:
635               InverseEntityMode(aMode,SMESH_Actor::eVolumes);
636               break;
637             case 220:
638               aMode = SMESH_Actor::eAllEntity;
639               break;
640             }
641             if(aMode)
642               anActor->SetEntityMode(aMode);
643           }
644         }
645       }
646     }
647   }
648
649   void AutoColor(){
650     SALOME_ListIO selected;
651     SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
652     if( !app )
653       return;
654
655     LightApp_SelectionMgr* aSel = app->selectionMgr();
656     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
657     if( !aSel || !appStudy )
658       return;
659
660     aSel->selectedObjects( selected );
661     if( selected.IsEmpty() )
662       return;
663
664     Handle(SALOME_InteractiveObject) anIObject = selected.First();
665
666     _PTR(Study) aStudy = appStudy->studyDS();
667     _PTR(SObject) aMainSObject( aStudy->FindObjectID( anIObject->getEntry() ) );
668     SMESH::SMESH_Mesh_var aMainObject = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIObject);
669     if( aMainObject->_is_nil() )
670       return;
671
672     aMainObject->SetAutoColor( true );
673
674     QList<SALOMEDS::Color> aReservedColors;
675
676     SMESH::ListOfGroups aListOfGroups = *aMainObject->GetGroups();
677     for( int i = 0, n = aListOfGroups.length(); i < n; i++ )
678     {
679       SMESH::SMESH_GroupBase_var aGroupObject = aListOfGroups[i];
680       SALOMEDS::Color aCurrentColor = aGroupObject->GetColor();
681
682       SALOMEDS::Color aColor = SMESHGUI::getUniqueColor( aReservedColors );
683       aGroupObject->SetColor( aColor );
684       aReservedColors.append( aColor );
685
686       _PTR(SObject) aGroupSObject = SMESH::FindSObject(aGroupObject);
687       if (aGroupSObject) {
688         if(SMESH_Actor *anActor = SMESH::FindActorByEntry(aGroupSObject->GetID().c_str())) {
689           if( aGroupObject->GetType() == SMESH::NODE )
690             anActor->SetNodeColor( aColor.R, aColor.G, aColor.B );
691           else if( aGroupObject->GetType() == SMESH::EDGE )
692             anActor->SetEdgeColor( aColor.R, aColor.G, aColor.B );
693           else if( aGroupObject->GetType() == SMESH::ELEM0D )
694             anActor->Set0DColor( aColor.R, aColor.G, aColor.B );
695           else
696             anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B );
697         }
698       }
699     }
700
701     SMESH::RepaintCurrentView();
702   }
703
704   void DisableAutoColor(){
705     LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
706     SALOME_ListIO selected;
707     if( aSel )
708       aSel->selectedObjects( selected );
709
710     if(selected.Extent()){
711       Handle(SALOME_InteractiveObject) anIObject = selected.First();
712       SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIObject);
713       if ( !aMesh->_is_nil() ) {
714         aMesh->SetAutoColor( false );
715       }
716     }
717   }
718
719   void SetDisplayMode(int theCommandID, SMESHGUI_StudyId2MarkerMap& theMarkerMap){
720     SALOME_ListIO selected;
721     SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
722     if( !app )
723       return;
724
725     LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
726     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
727     if( !aSel || !appStudy )
728       return;
729
730     _PTR(Study) aStudy = appStudy->studyDS();
731
732     aSel->selectedObjects( selected );
733
734     if(selected.Extent() >= 1){
735       switch(theCommandID){
736       case 1134:{
737         SMESHGUI::GetSMESHGUI()->EmitSignalDeactivateDialog();
738         (new SMESHGUI_ClippingDlg( SMESHGUI::GetSMESHGUI() ))->show();
739         return;
740       }
741       case 1133:{
742         SMESHGUI::GetSMESHGUI()->EmitSignalDeactivateDialog();
743         (new SMESHGUI_TransparencyDlg( SMESHGUI::GetSMESHGUI() ))->show();
744         return;
745       }}
746       SALOME_ListIteratorOfListIO It( selected );
747       for( ; It.More(); It.Next()){
748         Handle(SALOME_InteractiveObject) IObject = It.Value();
749         if(IObject->hasEntry()){
750           if(SMESH_Actor *anActor = SMESH::FindActorByEntry(IObject->getEntry())){
751             switch(theCommandID){
752             case 211:
753               anActor->SetRepresentation(SMESH_Actor::eEdge);
754               break;
755             case 212:
756               anActor->SetRepresentation(SMESH_Actor::eSurface);
757               break;
758             case 213:
759               if(anActor->IsShrunk())
760                 anActor->UnShrink();
761               else
762                 anActor->SetShrink();
763               break;
764             case 215:
765               anActor->SetRepresentation(SMESH_Actor::ePoint);
766               break;
767             case 231:
768               if(anActor->GetQuadratic2DRepresentation() != SMESH_Actor::eLines)
769                 anActor->SetQuadratic2DRepresentation(SMESH_Actor::eLines);
770               break;
771             case 232:
772               if(anActor->GetQuadratic2DRepresentation() != SMESH_Actor::eArcs)
773                 anActor->SetQuadratic2DRepresentation(SMESH_Actor::eArcs);
774               break;
775             case 1132:{
776               vtkFloatingPointType color[3];
777               anActor->GetSufaceColor(color[0], color[1], color[2]);
778               int c0 = int (color[0] * 255);
779               int c1 = int (color[1] * 255);
780               int c2 = int (color[2] * 255);
781               QColor c(c0, c1, c2);
782
783               vtkFloatingPointType edgecolor[3];
784               anActor->GetEdgeColor(edgecolor[0], edgecolor[1], edgecolor[2]);
785               c0 = int (edgecolor[0] * 255);
786               c1 = int (edgecolor[1] * 255);
787               c2 = int (edgecolor[2] * 255);
788               QColor e(c0, c1, c2);
789
790               vtkFloatingPointType backfacecolor[3];
791               anActor->GetBackSufaceColor(backfacecolor[0], backfacecolor[1], backfacecolor[2]);
792               c0 = int (backfacecolor[0] * 255);
793               c1 = int (backfacecolor[1] * 255);
794               c2 = int (backfacecolor[2] * 255);
795               QColor b(c0, c1, c2);
796
797               vtkFloatingPointType nodecolor[3];
798               anActor->GetNodeColor(nodecolor[0], nodecolor[1], nodecolor[2]);
799               c0 = int (nodecolor[0] * 255);
800               c1 = int (nodecolor[1] * 255);
801               c2 = int (nodecolor[2] * 255);
802               QColor n(c0, c1, c2);
803
804               vtkFloatingPointType color0D[3];
805               anActor->Get0DColor(color0D[0], color0D[1], color0D[2]);
806               c0 = int (color0D[0] * 255);
807               c1 = int (color0D[1] * 255);
808               c2 = int (color0D[2] * 255);
809               QColor c0D(c0, c1, c2);
810
811               int size0D = (int)anActor->Get0DSize();
812               if(size0D == 0)
813                 size0D = 1;
814               int Edgewidth = (int)anActor->GetLineWidth();
815               if(Edgewidth == 0)
816                 Edgewidth = 1;
817               vtkFloatingPointType Shrink = anActor->GetShrinkFactor();
818
819               vtkFloatingPointType faces_orientation_color[3];
820               anActor->GetFacesOrientationColor(faces_orientation_color);
821               c0 = int (faces_orientation_color[0] * 255);
822               c1 = int (faces_orientation_color[1] * 255);
823               c2 = int (faces_orientation_color[2] * 255);
824               QColor o(c0, c1, c2);
825
826               vtkFloatingPointType faces_orientation_scale = anActor->GetFacesOrientationScale();
827               bool faces_orientation_3dvectors = anActor->GetFacesOrientation3DVectors();
828
829               SMESHGUI_Preferences_ColorDlg *aDlg =
830                 new SMESHGUI_Preferences_ColorDlg( SMESHGUI::GetSMESHGUI() );
831               aDlg->SetColor(1, c);
832               aDlg->SetColor(2, e);
833               aDlg->SetColor(3, n);
834               aDlg->SetColor(4, b);
835               aDlg->SetColor(5, c0D);
836               aDlg->SetColor(6, o);
837               aDlg->SetIntValue(1, Edgewidth);
838               aDlg->SetIntValue(2, int(Shrink*100.));
839               aDlg->SetIntValue(3, size0D);
840               aDlg->SetDoubleValue(1, faces_orientation_scale);
841               aDlg->SetBooleanValue(1, faces_orientation_3dvectors);
842
843               aDlg->setCustomMarkerMap( theMarkerMap[ aStudy->StudyId() ] );
844
845               VTK::MarkerType aMarkerTypeCurrent = anActor->GetMarkerType();
846               VTK::MarkerScale aMarkerScaleCurrent = anActor->GetMarkerScale();
847               int aMarkerTextureCurrent = anActor->GetMarkerTexture();
848               if( aMarkerTypeCurrent != VTK::MT_USER )
849                 aDlg->setStandardMarker( aMarkerTypeCurrent, aMarkerScaleCurrent );
850               else
851                 aDlg->setCustomMarker( aMarkerTextureCurrent );
852
853               if(aDlg->exec()){
854                 QColor color = aDlg->GetColor(1);
855                 QColor edgecolor = aDlg->GetColor(2);
856                 QColor nodecolor = aDlg->GetColor(3);
857                 QColor backfacecolor = aDlg->GetColor(4);
858                 QColor color0D = aDlg->GetColor(5);
859                 QColor faces_orientation_color = aDlg->GetColor(6);
860                 /* actor color and backface color */
861                 anActor->SetSufaceColor(vtkFloatingPointType (color.red()) / 255.,
862                                         vtkFloatingPointType (color.green()) / 255.,
863                                         vtkFloatingPointType (color.blue()) / 255.);
864                 anActor->SetBackSufaceColor(vtkFloatingPointType (backfacecolor.red()) / 255.,
865                                             vtkFloatingPointType (backfacecolor.green()) / 255.,
866                                             vtkFloatingPointType (backfacecolor.blue()) / 255.);
867
868                 /* edge color */
869                 anActor->SetEdgeColor(vtkFloatingPointType (edgecolor.red()) / 255.,
870                                       vtkFloatingPointType (edgecolor.green()) / 255.,
871                                       vtkFloatingPointType (edgecolor.blue()) / 255.);
872
873                 /* Shrink factor and size edges */
874                 anActor->SetShrinkFactor(aDlg->GetIntValue(2) / 100.);
875                 anActor->SetLineWidth(aDlg->GetIntValue(1));
876
877                 /* Nodes color and size */
878                 anActor->SetNodeColor(vtkFloatingPointType (nodecolor.red()) / 255.,
879                                       vtkFloatingPointType (nodecolor.green()) / 255.,
880                                       vtkFloatingPointType (nodecolor.blue()) / 255.);
881
882                 /* 0D elements */
883                 anActor->Set0DColor(vtkFloatingPointType (color0D.red()) / 255.,
884                                     vtkFloatingPointType (color0D.green()) / 255.,
885                                     vtkFloatingPointType (color0D.blue()) / 255.);
886                 anActor->Set0DSize(aDlg->GetIntValue(3));
887
888                 /* Faces orientation */
889                 vtkFloatingPointType c[3] = {vtkFloatingPointType(faces_orientation_color.redF()),
890                                              vtkFloatingPointType(faces_orientation_color.greenF()),
891                                              vtkFloatingPointType(faces_orientation_color.blueF())};
892                 anActor->SetFacesOrientationColor(c);
893                 anActor->SetFacesOrientationScale(aDlg->GetDoubleValue(1));
894                 anActor->SetFacesOrientation3DVectors(aDlg->GetBooleanValue(1));
895
896                 /* Point marker */
897                 theMarkerMap[ aStudy->StudyId() ] = aDlg->getCustomMarkerMap();
898
899                 VTK::MarkerType aMarkerTypeNew = aDlg->getMarkerType();
900                 VTK::MarkerScale aMarkerScaleNew = aDlg->getStandardMarkerScale();
901                 int aMarkerTextureNew = aDlg->getCustomMarkerID();
902                 if( aMarkerTypeNew != VTK::MT_USER )
903                   anActor->SetMarkerStd( aMarkerTypeNew, aMarkerScaleNew );
904                 else {
905                   const VTK::MarkerMap& aMarkerMap = theMarkerMap[ aStudy->StudyId() ];
906                   VTK::MarkerMap::const_iterator anIter = aMarkerMap.find( aMarkerTextureNew );
907                   if( anIter != aMarkerMap.end() )
908                     anActor->SetMarkerTexture( aMarkerTextureNew, anIter->second.second );
909                 }
910
911                 SMESH::SMESH_GroupBase_var aGroupObject = SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IObject);
912                 if( !aGroupObject->_is_nil() )
913                 {
914                   SMESH::ElementType anElementType = aGroupObject->GetType();
915                   QColor aColor;
916                   switch( anElementType )
917                   {
918                     case SMESH::NODE: aColor = nodecolor; break;
919                     case SMESH::EDGE: aColor = edgecolor; break;
920                     default: aColor = color; break;
921                   }
922
923                   SALOMEDS::Color aGroupColor;
924                   aGroupColor.R = (float)aColor.red() / 255.0;
925                   aGroupColor.G = (float)aColor.green() / 255.0;
926                   aGroupColor.B = (float)aColor.blue() / 255.0;
927                   aGroupObject->SetColor( aGroupColor );
928                 }
929
930                 delete aDlg;
931               }
932               break;
933             }}
934           }
935         }
936       }
937       SMESH::RepaintCurrentView();
938     }
939   }
940
941   void Control( int theCommandID )
942   {
943     LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
944     SALOME_ListIO selected;
945     if( aSel )
946       aSel->selectedObjects( selected );
947
948     if( !selected.IsEmpty() ){
949       Handle(SALOME_InteractiveObject) anIO = selected.First();
950       if(!anIO.IsNull()){
951         QString aTitle;
952         SMESH_Actor::eControl aControl = SMESH_Actor::eNone;
953         if(SMESH_Actor *anActor = SMESH::FindActorByEntry(anIO->getEntry())){
954           switch ( theCommandID ){
955           case 6001:
956             aTitle = QObject::tr( "LENGTH_EDGES" );
957             aControl = SMESH_Actor::eLength;
958             break;
959           case 6018:
960             aTitle = QObject::tr( "LENGTH2D_EDGES" );
961             aControl = SMESH_Actor::eLength2D;
962             break;
963           case 6002:
964             aTitle = QObject::tr( "FREE_EDGES" );
965             aControl = SMESH_Actor::eFreeEdges;
966             break;
967           case 6003:
968             aTitle = QObject::tr( "FREE_BORDERS" );
969             aControl = SMESH_Actor::eFreeBorders;
970             break;
971           case 6004:
972             aTitle = QObject::tr( "MULTI_BORDERS" );
973             aControl = SMESH_Actor::eMultiConnection;
974             break;
975           case 6005:
976             aTitle = QObject::tr( "FREE_NODES" );
977             aControl = SMESH_Actor::eFreeNodes;
978             break;
979           case 6019:
980             aTitle = QObject::tr( "MULTI2D_BORDERS" );
981             aControl = SMESH_Actor::eMultiConnection2D;
982             break;
983           case 6011:
984             aTitle = QObject::tr( "AREA_ELEMENTS" );
985             aControl = SMESH_Actor::eArea;
986             break;
987           case 6012:
988             aTitle = QObject::tr( "TAPER_ELEMENTS" );
989             aControl = SMESH_Actor::eTaper;
990             break;
991           case 6013:
992             aTitle = QObject::tr( "ASPECTRATIO_ELEMENTS" );
993             aControl = SMESH_Actor::eAspectRatio;
994             break;
995           case 6017:
996             aTitle = QObject::tr( "ASPECTRATIO_3D_ELEMENTS" );
997             aControl = SMESH_Actor::eAspectRatio3D;
998             break;
999           case 6014:
1000             aTitle = QObject::tr( "MINIMUMANGLE_ELEMENTS" );
1001             aControl = SMESH_Actor::eMinimumAngle;
1002             break;
1003           case 6015:
1004             aTitle = QObject::tr( "WARP_ELEMENTS" );
1005             aControl = SMESH_Actor::eWarping;
1006             break;
1007           case 6016:
1008             aTitle = QObject::tr( "SKEW_ELEMENTS" );
1009             aControl = SMESH_Actor::eSkew;
1010             break;
1011           case 6009:
1012             aTitle = QObject::tr( "SMESH_VOLUME" );
1013             aControl = SMESH_Actor::eVolume3D;
1014             break;
1015           case 6021:
1016             aTitle = QObject::tr( "FREE_FACES" );
1017             aControl = SMESH_Actor::eFreeFaces;
1018             break;
1019           }
1020           anActor->SetControlMode(aControl);
1021           anActor->GetScalarBarActor()->SetTitle(aTitle.toLatin1().data());
1022           SMESH::RepaintCurrentView();
1023         }
1024       }
1025     }
1026   }
1027
1028
1029   bool CheckOIType(const Handle(SALOME_InteractiveObject) & theIO,
1030                    MeshObjectType                           theType,
1031                    const QString                            theInTypeName,
1032                    QString &                                theOutTypeName)
1033   {
1034     SMESH_TypeFilter aTypeFilter( theType );
1035     QString entry;
1036     if( !theIO.IsNull() )
1037     {
1038       entry = theIO->getEntry();
1039       LightApp_DataOwner owner( entry );
1040       if ( aTypeFilter.isOk( &owner )) {
1041         theOutTypeName = theInTypeName;
1042         return true;
1043       }
1044     }
1045     return false;
1046   }
1047
1048
1049   QString CheckTypeObject(const Handle(SALOME_InteractiveObject) & theIO)
1050   {
1051     _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1052     _PTR(SObject) aSObj = aStudy->FindObjectID(theIO->getEntry());
1053     if (aSObj) {
1054       _PTR(SComponent) aSComp = aSObj->GetFatherComponent();
1055       CORBA::String_var anID = aSComp->GetID().c_str();
1056       if (!strcmp(anID.in(),theIO->getEntry()))
1057         return "Component";
1058     }
1059
1060     QString aTypeName;
1061     if (
1062         CheckOIType ( theIO, HYPOTHESIS,    "Hypothesis", aTypeName ) ||
1063         CheckOIType ( theIO, ALGORITHM,     "Algorithm",  aTypeName ) ||
1064         CheckOIType ( theIO, MESH,          "Mesh",       aTypeName ) ||
1065         CheckOIType ( theIO, SUBMESH,       "SubMesh",    aTypeName ) ||
1066         CheckOIType ( theIO, GROUP,         "Group",      aTypeName )
1067         )
1068       return aTypeName;
1069
1070     return "NoType";
1071   }
1072
1073
1074   QString CheckHomogeneousSelection()
1075   {
1076     //SUIT_Study* aStudy = SMESH::GetActiveStudy();
1077     LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1078     SALOME_ListIO selected;
1079     if( aSel )
1080       aSel->selectedObjects( selected );
1081
1082     QString RefType = CheckTypeObject(selected.First());
1083     SALOME_ListIteratorOfListIO It(selected);
1084     for ( ; It.More(); It.Next())
1085       {
1086         Handle(SALOME_InteractiveObject) IObject = It.Value();
1087         QString Type = CheckTypeObject(IObject);
1088         if (Type.compare(RefType) != 0)
1089           return "Heterogeneous Selection";
1090       }
1091
1092     return RefType;
1093   }
1094
1095
1096   void SMESHGUI::OnEditDelete()
1097   {
1098     // VSR 17/11/04: check if all objects selected belong to SMESH component --> start
1099     LightApp_SelectionMgr* aSel = SMESHGUI::selectionMgr();
1100     SALOME_ListIO selected; aSel->selectedObjects( selected, QString::null, false );
1101
1102     _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1103     _PTR(StudyBuilder) aStudyBuilder = aStudy->NewBuilder();
1104     _PTR(GenericAttribute) anAttr;
1105     _PTR(AttributeIOR) anIOR;
1106
1107     int objectCount = 0;
1108     QString aNameList;
1109     QString aParentComponent = QString::null;
1110     Handle(SALOME_InteractiveObject) anIO;
1111     for( SALOME_ListIteratorOfListIO anIt( selected ); anIt.More(); anIt.Next() )
1112     {
1113       anIO = anIt.Value();
1114       QString cur = anIO->getComponentDataType();
1115       _PTR(SObject) aSO = aStudy->FindObjectID(anIO->getEntry());
1116       if (aSO) {
1117         // check if object is reference
1118         _PTR(SObject) aRefSObj;
1119         aNameList.append("\n    - ");
1120         if ( aSO->ReferencedObject( aRefSObj ) ) {
1121           QString aRefName = QString::fromStdString ( aRefSObj->GetName() );
1122           aNameList.append( aRefName );
1123           cur = QString::fromStdString ( aRefSObj->GetFatherComponent()->ComponentDataType() );
1124         }
1125         else
1126           aNameList.append(anIO->getName());
1127         objectCount++;
1128       }
1129
1130       if( aParentComponent.isNull() )
1131         aParentComponent = cur;
1132       else if( !aParentComponent.isEmpty() && aParentComponent!=cur )
1133         aParentComponent = "";
1134     }
1135
1136     if ( objectCount == 0 )
1137       return; // No Valid Objects Selected
1138
1139     if ( aParentComponent != SMESHGUI::GetSMESHGUI()->name() )  {
1140       SUIT_MessageBox::warning( SMESHGUI::desktop(),
1141                                 QObject::tr("ERR_ERROR"),
1142                                 QObject::tr("NON_SMESH_OBJECTS_SELECTED").arg( SMESHGUI::GetSMESHGUI()->moduleName() ) );
1143       return;
1144     }
1145     // VSR 17/11/04: check if all objects selected belong to SMESH component <-- finish
1146     if (SUIT_MessageBox::warning
1147         (SMESHGUI::desktop(),
1148          QObject::tr("SMESH_WRN_WARNING"),
1149          QObject::tr("SMESH_REALLY_DELETE").arg( objectCount ).arg( aNameList ),
1150          SUIT_MessageBox::Yes | SUIT_MessageBox::No,
1151          SUIT_MessageBox::Yes) != SUIT_MessageBox::Yes)
1152       return;
1153
1154     SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
1155     SUIT_ViewManager* vm = anApp->activeViewManager();
1156     int nbSf = vm->getViewsCount();
1157
1158     SALOME_ListIteratorOfListIO It(selected);
1159
1160     aStudyBuilder->NewCommand();  // There is a transaction
1161     for( ; It.More(); It.Next()){ // loop on selected IO's
1162       Handle(SALOME_InteractiveObject) IObject = It.Value();
1163       if(IObject->hasEntry()) {
1164         _PTR(SObject) aSO = aStudy->FindObjectID(IObject->getEntry());
1165
1166         // disable removal of "SMESH" component object
1167         if(aSO->FindAttribute(anAttr, "AttributeIOR")){
1168           anIOR = anAttr;
1169           if ( engineIOR() == anIOR->Value().c_str() )
1170             continue;
1171         }
1172         //Check the referenced object
1173         _PTR(SObject) aRefSObject;
1174         if ( aSO && aSO->ReferencedObject( aRefSObject ) )
1175           aSO = aRefSObject; // Delete main Object instead of reference
1176
1177         // put the whole hierarchy of sub-objects of the selected SO into a list and
1178         // then treat them all starting from the deepest objects (at list back)
1179
1180         std::list< _PTR(SObject) > listSO;
1181         listSO.push_back( aSO );
1182         std::list< _PTR(SObject) >::iterator itSO = listSO.begin();
1183         for ( ; itSO != listSO.end(); ++itSO ) {
1184           _PTR(ChildIterator) it = aStudy->NewChildIterator( *itSO );
1185           for (it->InitEx(false); it->More(); it->Next())
1186             listSO.push_back( it->Value() );
1187         }
1188
1189         // treat SO's in the list starting from the back
1190
1191         std::list< _PTR(SObject) >::reverse_iterator ritSO = listSO.rbegin();
1192         for ( ; ritSO != listSO.rend(); ++ritSO ) {
1193           _PTR(SObject) SO = *ritSO;
1194           if ( !SO ) continue;
1195           std::string anEntry = SO->GetID();
1196
1197           /** Erase graphical object **/
1198           if(SO->FindAttribute(anAttr, "AttributeIOR")){
1199             QVector<SUIT_ViewWindow*> aViews = vm->getViews();
1200             for(int i = 0; i < nbSf; i++){
1201               SUIT_ViewWindow *sf = aViews[i];
1202               if(SMESH_Actor* anActor = SMESH::FindActorByEntry(sf,anEntry.c_str())){
1203                 SMESH::RemoveActor(sf,anActor);
1204               }
1205             }
1206           }
1207
1208           /** Remove an object from data structures **/
1209           SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow( SMESH::SObjectToObject( SO ));
1210           SMESH::SMESH_subMesh_var   aSubMesh = SMESH::SMESH_subMesh::_narrow( SMESH::SObjectToObject( SO ));
1211           if ( !aGroup->_is_nil() ) {                          // DELETE GROUP
1212             SMESH::SMESH_Mesh_var aMesh = aGroup->GetMesh();
1213             aMesh->RemoveGroup( aGroup );
1214           }
1215           else if ( !aSubMesh->_is_nil() ) {                   // DELETE SUBMESH
1216             SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
1217             aMesh->RemoveSubMesh( aSubMesh );
1218
1219             _PTR(SObject) aMeshSO = SMESH::FindSObject(aMesh);
1220             if (aMeshSO)
1221               SMESH::ModifiedMesh(aMeshSO, false, aMesh->NbNodes()==0);
1222           }
1223           else {
1224             IObject = new SALOME_InteractiveObject
1225               ( anEntry.c_str(), engineIOR().toLatin1().data(), SO->GetName().c_str() );
1226             QString objType = CheckTypeObject(IObject);
1227             if ( objType == "Hypothesis" || objType == "Algorithm" ) {// DELETE HYPOTHESIS
1228               SMESH::RemoveHypothesisOrAlgorithmOnMesh(IObject);
1229               aStudyBuilder->RemoveObjectWithChildren( SO );
1230             }
1231             else {// default action: remove SObject from the study
1232               // san - it's no use opening a transaction here until UNDO/REDO is provided in SMESH
1233               //SUIT_Operation *op = new SALOMEGUI_ImportOperation(myActiveStudy);
1234               //op->start();
1235               aStudyBuilder->RemoveObjectWithChildren( SO );
1236               //op->finish();
1237             }
1238           }
1239         } /* listSO back loop */
1240       } /* IObject->hasEntry() */
1241     } /* more/next */
1242     aStudyBuilder->CommitCommand();
1243
1244     /* Clear any previous selection */
1245     SALOME_ListIO l1;
1246     aSel->setSelectedObjects( l1 );
1247
1248     SMESHGUI::GetSMESHGUI()->updateObjBrowser();
1249   }
1250 //}
1251
1252 extern "C" {
1253   SMESHGUI_EXPORT CAM_Module* createModule()
1254   {
1255     return new SMESHGUI();
1256   }
1257 }
1258
1259 SMESH::SMESH_Gen_var SMESHGUI::myComponentSMESH = SMESH::SMESH_Gen::_nil();
1260
1261 //=============================================================================
1262 /*!
1263  *
1264  */
1265 //=============================================================================
1266 SMESHGUI::SMESHGUI() :
1267 SalomeApp_Module( "SMESH" ),
1268 LightApp_Module( "SMESH" )
1269 {
1270   if ( CORBA::is_nil( myComponentSMESH ) )
1271   {
1272     CORBA::Boolean anIsEmbeddedMode;
1273     myComponentSMESH = SMESH_Client::GetSMESHGen(getApp()->orb(),anIsEmbeddedMode);
1274
1275     //  0019923: EDF 765 SMESH : default values of hypothesis
1276     SUIT_ResourceMgr* aResourceMgr = SMESH::GetResourceMgr(this);
1277     int nbSeg = aResourceMgr->integerValue( "SMESH", "segmentation", 10 );
1278     myComponentSMESH->SetBoundaryBoxSegmentation( nbSeg );
1279     nbSeg = aResourceMgr->integerValue( "SMESH", "nb_segments_per_edge", 15 );
1280     myComponentSMESH->SetDefaultNbSegments( nbSeg );
1281   }
1282
1283   myActiveDialogBox = 0;
1284   myFilterLibraryDlg = 0;
1285   myState = -1;
1286   myDisplayer = 0;
1287
1288   SMESH::GetFilterManager();
1289   SMESH::GetPattern();
1290
1291   /* load resources for all available meshers */
1292   SMESH::InitAvailableHypotheses();
1293 }
1294
1295 //=============================================================================
1296 /*!
1297  *
1298  */
1299 //=============================================================================
1300 SMESHGUI::~SMESHGUI()
1301 {
1302   SMESH::GetFilterManager()->Destroy();
1303   SMESH::GetFilterManager() = SMESH::FilterManager::_nil();
1304 }
1305
1306 //=============================================================================
1307 /*!
1308  *
1309  */
1310 //=============================================================================
1311 LightApp_SelectionMgr* SMESHGUI::selectionMgr()
1312 {
1313   SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
1314   if( anApp )
1315     return dynamic_cast<LightApp_SelectionMgr*>( anApp->selectionMgr() );
1316   else
1317     return 0;
1318 }
1319
1320 bool SMESHGUI::automaticUpdate()
1321 {
1322   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1323   if ( !resMgr )
1324     return false;
1325
1326   return resMgr->booleanValue( "SMESH", "auto_update", false );
1327 }
1328
1329 //=============================================================================
1330 /*!
1331  *
1332  */
1333 //=============================================================================
1334 SUIT_ResourceMgr* SMESHGUI::resourceMgr()
1335 {
1336   return dynamic_cast<SUIT_ResourceMgr*>( SUIT_Session::session()->resourceMgr() );
1337 }
1338
1339 //=============================================================================
1340 /*!
1341  *
1342  */
1343 //=============================================================================
1344 SMESHGUI* SMESHGUI::GetSMESHGUI()
1345 {
1346   SMESHGUI* smeshMod = 0;
1347   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>(SUIT_Session::session()->activeApplication());
1348   if ( app )
1349   {
1350     CAM_Module* module = app->module( "Mesh" );
1351     smeshMod = dynamic_cast<SMESHGUI*>( module );
1352   }
1353
1354   if ( smeshMod && smeshMod->application() && smeshMod->application()->activeStudy() )
1355   {
1356     SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( smeshMod->application()->activeStudy() );
1357     if ( study )
1358     {
1359       _PTR(Study) aStudy = study->studyDS();
1360       if ( aStudy )
1361         GetSMESHGen()->SetCurrentStudy( _CAST(Study,aStudy)->GetStudy() );
1362     }
1363   }
1364
1365   return smeshMod;
1366 }
1367
1368 extern "C"
1369 {
1370   Standard_EXPORT SMESHGUI* GetComponentGUI()
1371   {
1372     return SMESHGUI::GetSMESHGUI();
1373   }
1374 }
1375
1376 //=============================================================================
1377 /*!
1378  *
1379  */
1380 //=============================================================================
1381 void SMESHGUI::SetState(int aState)
1382 {
1383   myState = aState;
1384 }
1385
1386 //=============================================================================
1387 /*!
1388  *
1389  */
1390 //=============================================================================
1391 void SMESHGUI::ResetState()
1392 {
1393   myState = -1;
1394 }
1395
1396 //=============================================================================
1397 /*!
1398  *
1399  */
1400 //=============================================================================
1401 void SMESHGUI::EmitSignalDeactivateDialog()
1402 {
1403   emit SignalDeactivateActiveDialog();
1404 }
1405
1406 //=============================================================================
1407 /*!
1408  *
1409  */
1410 //=============================================================================
1411 void SMESHGUI::EmitSignalStudyFrameChanged()
1412 {
1413   emit SignalStudyFrameChanged();
1414 }
1415
1416 //=============================================================================
1417 /*!
1418  *
1419  */
1420 //=============================================================================
1421 void SMESHGUI::EmitSignalCloseAllDialogs()
1422 {
1423   emit SignalCloseAllDialogs();
1424 }
1425
1426 //=============================================================================
1427 /*!
1428  *
1429  */
1430 //=============================================================================
1431 void SMESHGUI::EmitSignalVisibilityChanged()
1432 {
1433   emit SignalVisibilityChanged();
1434 }
1435
1436 //=============================================================================
1437 /*!
1438  *
1439  */
1440 //=============================================================================
1441 QDialog *SMESHGUI::GetActiveDialogBox()
1442 {
1443   return myActiveDialogBox;
1444 }
1445
1446 //=============================================================================
1447 /*!
1448  *
1449  */
1450 //=============================================================================
1451 void SMESHGUI::SetActiveDialogBox(QDialog * aDlg)
1452 {
1453   myActiveDialogBox = (QDialog *) aDlg;
1454   return;
1455 }
1456
1457 //=============================================================================
1458 /*!
1459  *
1460  */
1461 //=============================================================================
1462 SUIT_Desktop* SMESHGUI::desktop()
1463 {
1464   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
1465   if( app )
1466     return app->desktop();
1467   else
1468     return 0;
1469 }
1470
1471 //=============================================================================
1472 /*!
1473  *
1474  */
1475 //=============================================================================
1476 SalomeApp_Study* SMESHGUI::activeStudy()
1477 {
1478   SUIT_Application* app = SUIT_Session::session()->activeApplication();
1479   if( app )
1480     return dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1481   else
1482     return NULL;
1483 }
1484
1485 //=============================================================================
1486 /*!
1487  *
1488  */
1489 //=============================================================================
1490 void SMESHGUI::Modified( bool theIsUpdateActions )
1491 {
1492   if( SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() ) ) {
1493     if( SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() ) ) {
1494       appStudy->Modified();
1495       if( theIsUpdateActions )
1496         app->updateActions();
1497     }
1498   }
1499 }
1500
1501 //=============================================================================
1502 /*!
1503  *
1504  */
1505 //=============================================================================
1506 bool SMESHGUI::DefineDlgPosition(QWidget * aDlg, int &x, int &y)
1507 {
1508   /* Here the position is on the bottom right corner - 10 */
1509   // aDlg->resize(QSize().expandedTo(aDlg->minimumSizeHint()));
1510   aDlg->adjustSize();
1511   SUIT_Desktop *PP = desktop();
1512   x = abs(PP->x() + PP->size().width() - aDlg->size().width() - 10);
1513   y = abs(PP->y() + PP->size().height() - aDlg->size().height() - 10);
1514   return true;
1515 }
1516
1517 //=============================================================================
1518 /*!
1519  *
1520  */
1521 //=============================================================================
1522 static int isStudyLocked(_PTR(Study) theStudy){
1523   return theStudy->GetProperties()->IsLocked();
1524 }
1525
1526 static bool checkLock(_PTR(Study) theStudy) {
1527   if (isStudyLocked(theStudy)) {
1528     SUIT_MessageBox::warning( SMESHGUI::desktop(),
1529                               QObject::tr("WRN_WARNING"),
1530                               QObject::tr("WRN_STUDY_LOCKED") );
1531     return true;
1532   }
1533   return false;
1534 }
1535
1536 //=======================================================================
1537 //function : CheckActiveStudyLocked
1538 //purpose  :
1539 //=======================================================================
1540
1541 bool SMESHGUI::isActiveStudyLocked()
1542 {
1543   _PTR(Study) aStudy = activeStudy()->studyDS();
1544   return checkLock( aStudy );
1545 }
1546
1547 //=============================================================================
1548 /*!
1549  *
1550  */
1551 //=============================================================================
1552 bool SMESHGUI::OnGUIEvent( int theCommandID )
1553 {
1554   SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( application() );
1555   if( !anApp )
1556     return false;
1557
1558   _PTR(Study) aStudy = SMESH::GetActiveStudyDocument(); //Document OCAF de l'etude active
1559   SUIT_ResourceMgr* mgr = resourceMgr();
1560   if( !mgr )
1561     return false;
1562
1563   if (CORBA::is_nil(GetSMESHGen()->GetCurrentStudy())) {
1564     GetSMESHGen()->SetCurrentStudy(_CAST(Study,aStudy)->GetStudy());
1565   }
1566
1567   SUIT_ViewWindow* view = application()->desktop()->activeWindow();
1568   SVTK_ViewWindow* vtkwnd = dynamic_cast<SVTK_ViewWindow*>( view );
1569
1570   //QAction* act = action( theCommandID );
1571
1572   switch (theCommandID) {
1573   case 33:                                      // DELETE
1574     if(checkLock(aStudy)) break;
1575     OnEditDelete();
1576     break;
1577
1578   case 113:                                     // IMPORT
1579   case 112:
1580   case 111:
1581     {
1582       if(checkLock(aStudy)) break;
1583       ::ImportMeshesFromFile(GetSMESHGen(),theCommandID);
1584       break;
1585     }
1586
1587   case 150:    //MED FILE INFORMATION
1588     {
1589       SALOME_ListIO selected;
1590       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1591       if( aSel )
1592         aSel->selectedObjects( selected );
1593       if( selected.Extent() )
1594       {
1595         Handle(SALOME_InteractiveObject) anIObject = selected.First();
1596         SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIObject);
1597         if ( !aMesh->_is_nil() )
1598         {
1599           SMESHGUI_FileInfoDlg dlg( desktop(), aMesh->GetMEDFileInfo() );
1600           dlg.exec();
1601         }
1602       }
1603       break;
1604     }
1605
1606   case 122:                                     // EXPORT MED
1607   case 121:
1608   case 123:
1609   case 124:
1610   case 125:
1611   case 126:
1612   case 140:
1613   case 141:
1614     {
1615       ::ExportMeshToFile(theCommandID);
1616       break;
1617     }
1618
1619   case 200:                                     // SCALAR BAR
1620     {
1621       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1622       SALOME_ListIO selected;
1623       if( aSel )
1624         aSel->selectedObjects( selected );
1625
1626       if( selected.Extent() ) {
1627         Handle(SALOME_InteractiveObject) anIO = selected.First();
1628         if( anIO->hasEntry() ) {
1629           if( SMESH_Actor* anActor = SMESH::FindActorByEntry( anIO->getEntry() ) ) {
1630             anActor->SetControlMode( SMESH_Actor::eNone );
1631           }
1632         }
1633       }
1634       break;
1635     }
1636   case 201:
1637     {
1638       SMESHGUI_Preferences_ScalarBarDlg::ScalarBarProperties( this );
1639       break;
1640     }
1641
1642     // Auto-color
1643   case 1136:
1644     ::AutoColor();
1645   break;
1646
1647   case 1137:
1648     ::DisableAutoColor();
1649   break;
1650
1651   case 1134: // Clipping
1652   case 1133: // Tranparency
1653   case 1132: // Colors / Size
1654
1655     // Display Mode
1656   case 215: // Nodes
1657   case 213: // Nodes
1658   case 212: // Nodes
1659   case 211: // Nodes
1660     ::SetDisplayMode(theCommandID, myMarkerMap);
1661   break;
1662
1663   //2D quadratic representation
1664   case 231:
1665   case 232:
1666     ::SetDisplayMode(theCommandID, myMarkerMap);
1667   break;
1668   
1669   // Display Entity
1670   case 216: // 0D elements
1671   case 217: // Edges
1672   case 218: // Faces
1673   case 219: // Volumes
1674   case 220: // All Entity
1675     ::SetDisplayEntity(theCommandID);
1676   break;
1677
1678   case 221: // Orientation of faces
1679     {
1680       LightApp_SelectionMgr* mgr = selectionMgr();
1681       SALOME_ListIO selected; mgr->selectedObjects( selected );
1682
1683       SALOME_ListIteratorOfListIO it(selected);
1684       for( ; it.More(); it.Next()) {
1685         Handle(SALOME_InteractiveObject) anIObject = it.Value();
1686         if(anIObject->hasEntry()) {
1687           if(SMESH_Actor *anActor = SMESH::FindActorByEntry(anIObject->getEntry())){
1688             anActor->SetFacesOriented( !anActor->GetFacesOriented() );
1689           }
1690         }
1691       }
1692       break;
1693     }
1694
1695   case 214:                                     // UPDATE
1696     {
1697       if(checkLock(aStudy)) break;
1698       try {
1699 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1700         OCC_CATCH_SIGNALS;
1701 #endif
1702         SMESH::UpdateView();
1703       }
1704       catch (std::bad_alloc) { // PAL16774 (Crash after display of many groups)
1705         SMESH::OnVisuException();
1706       }
1707       catch (...) { // PAL16774 (Crash after display of many groups)
1708         SMESH::OnVisuException();
1709       }
1710
1711       SALOME_ListIO l;
1712       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1713       aSel->selectedObjects( l );
1714       aSel->setSelectedObjects( l );
1715       break;
1716     }
1717
1718   case 300:                                     // ERASE
1719   case 301:                                     // DISPLAY
1720   case 302:                                     // DISPLAY ONLY
1721     {
1722       SMESH::EDisplaing anAction;
1723       switch (theCommandID) {
1724       case 300: anAction = SMESH::eErase; break;
1725       case 301: anAction = SMESH::eDisplay; break;
1726       case 302: anAction = SMESH::eDisplayOnly; break;
1727       }
1728
1729       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1730       SALOME_ListIO sel_objects, to_process;
1731       if (aSel)
1732         aSel->selectedObjects( sel_objects );
1733
1734       if( theCommandID==302 )
1735         startOperation( myEraseAll );
1736
1737       extractContainers( sel_objects, to_process );
1738
1739       try {
1740 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1741         OCC_CATCH_SIGNALS;
1742 #endif
1743         if (vtkwnd) {
1744           SALOME_ListIteratorOfListIO It( to_process );
1745           for ( ; It.More(); It.Next()) {
1746             Handle(SALOME_InteractiveObject) IOS = It.Value();
1747             if (IOS->hasEntry()) {
1748               if (!SMESH::UpdateView(anAction, IOS->getEntry())) {
1749                 SMESHGUI::GetSMESHGUI()->EmitSignalVisibilityChanged();
1750                 break; // PAL16774 (Crash after display of many groups)
1751               }
1752               if (anAction == SMESH::eDisplayOnly)
1753                 anAction = SMESH::eDisplay;
1754             }
1755           }
1756         }
1757
1758         // PAL13338 + PAL15161 -->
1759         if ( ( theCommandID==301 || theCommandID==302 ) && !checkLock(aStudy)) {
1760           SMESH::UpdateView();
1761           SMESHGUI::GetSMESHGUI()->EmitSignalVisibilityChanged();
1762         }
1763         // PAL13338 + PAL15161 <--
1764       }
1765       catch (...) { // PAL16774 (Crash after display of many groups)
1766         SMESH::OnVisuException();
1767       }
1768
1769       if (anAction == SMESH::eErase) {
1770         SALOME_ListIO l1;
1771         aSel->setSelectedObjects( l1 );
1772       }
1773       else
1774         aSel->setSelectedObjects( to_process );
1775       
1776       break;
1777     }
1778
1779   case 4000:                                    // NODES
1780     {
1781       if(checkLock(aStudy)) break;
1782
1783       if ( vtkwnd ) {
1784         EmitSignalDeactivateDialog();
1785
1786         ( new SMESHGUI_NodesDlg( this ) )->show();
1787       }
1788       else {
1789         SUIT_MessageBox::warning(desktop(),
1790                                  tr("SMESH_WRN_WARNING"),
1791                                  tr("SMESH_WRN_VIEWER_VTK"));
1792       }
1793       break;
1794     }
1795
1796   case 2151:  // FILTER
1797   {
1798     if ( vtkwnd )
1799     {
1800       EmitSignalDeactivateDialog();
1801       ( new SMESHGUI_FilterDlg( this, SMESH::EDGE ) )->show();
1802     }
1803     break;
1804   }
1805
1806   case 701:                                     // COMPUTE MESH
1807   case 711:                                     // PRECOMPUTE MESH
1808   case 712:                                     // EVALUATE MESH
1809   case 713:                                     // MESH ORDER
1810     {
1811       if (checkLock(aStudy)) break;
1812       startOperation( theCommandID );
1813     }
1814     break;
1815
1816   case 702: // Create mesh
1817   case 703: // Create sub-mesh
1818   case 704: // Edit mesh/sub-mesh
1819     startOperation( theCommandID );
1820     break;
1821   case 710: // Build compound mesh
1822     {
1823       if (checkLock(aStudy)) break;
1824       EmitSignalDeactivateDialog();
1825       ( new SMESHGUI_BuildCompoundDlg( this ) )->show();
1826     }
1827     break;
1828
1829   case 407: // DIAGONAL INVERSION
1830   case 408: // Delete diagonal
1831     {
1832       if ( !vtkwnd )
1833       {
1834         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),
1835                                   tr( "NOT_A_VTK_VIEWER" ) );
1836         break;
1837       }
1838
1839       if ( checkLock( aStudy ) )
1840         break;
1841
1842       /*Standard_Boolean aRes;
1843       SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IObject);
1844       if ( aMesh->_is_nil() )
1845       {
1846         SUIT_MessageBox::warning(GetDesktop(), tr( "SMESH_WRN_WARNING" ),
1847           tr( "SMESH_BAD_SELECTION" ) );
1848         break;
1849       }
1850       */
1851       EmitSignalDeactivateDialog();
1852       if ( theCommandID == 407 )
1853         ( new SMESHGUI_TrianglesInversionDlg( this ) )->show();
1854       else
1855         ( new SMESHGUI_UnionOfTwoTrianglesDlg( this ) )->show();
1856       break;
1857     }
1858   case 409: // Change orientation
1859   case 410: // Union of triangles
1860   case 411: // Cutting of quadrangles
1861   case 419: // Splitting volumes into tetrahedra
1862     {
1863       if ( !vtkwnd )
1864       {
1865         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),
1866                                   tr( "NOT_A_VTK_VIEWER" ) );
1867         break;
1868       }
1869
1870       if ( checkLock( aStudy ) )
1871         break;
1872
1873       EmitSignalDeactivateDialog();
1874       SMESHGUI_MultiEditDlg* aDlg = NULL;
1875       if ( theCommandID == 409 )
1876         aDlg = new SMESHGUI_ChangeOrientationDlg(this);
1877       else if ( theCommandID == 410 )
1878         aDlg = new SMESHGUI_UnionOfTrianglesDlg(this);
1879       else if ( theCommandID == 419 )
1880         aDlg = new SMESHGUI_CuttingIntoTetraDlg(this);
1881       else
1882         aDlg = new SMESHGUI_CuttingOfQuadsDlg(this);
1883
1884       aDlg->show();
1885       break;
1886     }
1887   case 412: // Smoothing
1888     {
1889       if(checkLock(aStudy)) break;
1890       if( vtkwnd ) {
1891         EmitSignalDeactivateDialog();
1892         ( new SMESHGUI_SmoothingDlg( this ) )->show();
1893       }
1894       else {
1895         SUIT_MessageBox::warning(desktop(),
1896                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
1897       }
1898       break;
1899     }
1900   case 413: // Extrusion
1901     {
1902       if (checkLock(aStudy)) break;
1903       if (vtkwnd) {
1904         EmitSignalDeactivateDialog();
1905         ( new SMESHGUI_ExtrusionDlg ( this ) )->show();
1906       } else {
1907         SUIT_MessageBox::warning(desktop(),
1908                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
1909       }
1910       break;
1911     }
1912   case 414: // Revolution
1913     {
1914       if(checkLock(aStudy)) break;
1915       if( vtkwnd ) {
1916         EmitSignalDeactivateDialog();
1917         ( new SMESHGUI_RevolutionDlg( this ) )->show();
1918       }
1919       else {
1920         SUIT_MessageBox::warning(desktop(),
1921                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
1922       }
1923       break;
1924     }
1925   case 415: // Pattern mapping
1926     {
1927       if ( checkLock( aStudy ) )
1928         break;
1929       if ( vtkwnd )
1930       {
1931         EmitSignalDeactivateDialog();
1932         ( new SMESHGUI_MeshPatternDlg( this ) )->show();
1933       }
1934       else {
1935         SUIT_MessageBox::warning(desktop(),
1936                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
1937       }
1938       break;
1939     }
1940   case 416: // Extrusion along a path
1941     {
1942       if (checkLock(aStudy)) break;
1943       if (vtkwnd) {
1944         EmitSignalDeactivateDialog();
1945         ( new SMESHGUI_ExtrusionAlongPathDlg( this ) )->show();
1946       } else {
1947         SUIT_MessageBox::warning(desktop(),
1948                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
1949       }
1950       break;
1951     }
1952   case 417: // Convert mesh to quadratic
1953     {
1954     startOperation( 417 );
1955       /*      if (checkLock(aStudy)) break;
1956       if (vtkwnd) {
1957         EmitSignalDeactivateDialog();
1958         new SMESHGUI_ConvToQuadDlg();
1959       } else {
1960         SUIT_MessageBox::warning(desktop(),
1961                                tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
1962                                }*/
1963       break;
1964     }
1965   case 418: // create 2D mesh from 3D
1966     {
1967       startOperation( 418 );
1968       break;
1969     }
1970   case 806:                                     // CREATE GEO GROUP
1971     {
1972       startOperation( 806 );
1973       break;
1974     }
1975   case 801:                                     // CREATE GROUP
1976     {
1977       if ( !vtkwnd )
1978       {
1979         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),
1980                                   tr( "NOT_A_VTK_VIEWER" ) );
1981         break;
1982       }
1983
1984       if(checkLock(aStudy)) break;
1985       EmitSignalDeactivateDialog();
1986       SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_nil();
1987
1988       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1989       SALOME_ListIO selected;
1990       if( aSel )
1991         aSel->selectedObjects( selected );
1992
1993       int nbSel = selected.Extent();
1994       if (nbSel == 1) {
1995         // check if mesh is selected
1996         aMesh = SMESH::GetMeshByIO( selected.First() );
1997       }
1998       SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, aMesh);
1999       aDlg->show();
2000       break;
2001     }
2002
2003   case 802:                                     // CONSTRUCT GROUP
2004     {
2005       if ( !vtkwnd )
2006       {
2007         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),
2008                                   tr( "NOT_A_VTK_VIEWER" ) );
2009         break;
2010       }
2011
2012       if(checkLock(aStudy)) break;
2013       EmitSignalDeactivateDialog();
2014
2015       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2016       SALOME_ListIO selected;
2017       if( aSel )
2018         aSel->selectedObjects( selected );
2019
2020       int nbSel = selected.Extent();
2021       if (nbSel == 1) {
2022         // check if submesh is selected
2023         Handle(SALOME_InteractiveObject) IObject = selected.First();
2024         if (IObject->hasEntry()) {
2025           _PTR(SObject) aSObj = aStudy->FindObjectID(IObject->getEntry());
2026           if( aSObj ) {
2027             SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow( SMESH::SObjectToObject( aSObj ) );
2028             if (!aSubMesh->_is_nil()) {
2029               try {
2030                 SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
2031                 // get submesh elements list by types
2032                 SMESH::long_array_var aNodes = aSubMesh->GetElementsByType(SMESH::NODE);
2033                 SMESH::long_array_var aEdges = aSubMesh->GetElementsByType(SMESH::EDGE);
2034                 SMESH::long_array_var aFaces = aSubMesh->GetElementsByType(SMESH::FACE);
2035                 SMESH::long_array_var aVolumes = aSubMesh->GetElementsByType(SMESH::VOLUME);
2036                 // create group for each type o elements
2037                 QString aName = IObject->getName();
2038                 if (aNodes->length() > 0) {
2039                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::NODE, aName + "_Nodes");
2040                   aGroup->Add(aNodes.inout());
2041                 }
2042                 if (aEdges->length() > 0) {
2043                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::EDGE, aName + "_Edges");
2044                   aGroup->Add(aEdges.inout());
2045                 }
2046                 if (aFaces->length() > 0) {
2047                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::FACE, aName + "_Faces");
2048                   aGroup->Add(aFaces.inout());
2049                 }
2050                 if (aVolumes->length() > 0) {
2051                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::VOLUME, aName + "_Volumes");
2052                   aGroup->Add(aVolumes.inout());
2053                 }
2054                 updateObjBrowser();
2055
2056               }
2057               catch(const SALOME::SALOME_Exception & S_ex){
2058                 SalomeApp_Tools::QtCatchCorbaException(S_ex);
2059               }
2060             }
2061           }
2062         }
2063       }
2064       else if(nbSel==0) {
2065         SUIT_MessageBox::warning(desktop(),
2066                                  tr("SMESH_WRN_WARNING"),
2067                                  tr("SMESH_WRN_NO_AVAILABLE_DATA"));
2068       }
2069       break;
2070     }
2071
2072   case 803:                                     // EDIT GROUP
2073     {
2074       if ( !vtkwnd )
2075       {
2076         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),
2077                                   tr( "NOT_A_VTK_VIEWER" ) );
2078         break;
2079       }
2080
2081       if(checkLock(aStudy)) break;
2082       EmitSignalDeactivateDialog();
2083
2084       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2085       SALOME_ListIO selected;
2086       if( aSel )
2087         aSel->selectedObjects( selected );
2088
2089       SALOME_ListIteratorOfListIO It (selected);
2090       int nbSelectedGroups = 0;
2091       for ( ; It.More(); It.Next() )
2092       {
2093         SMESH::SMESH_GroupBase_var aGroup =
2094           SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(It.Value());
2095         if (!aGroup->_is_nil()) {
2096           nbSelectedGroups++;
2097           SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, aGroup);
2098           aDlg->show();
2099         }
2100       }
2101       if (nbSelectedGroups == 0)
2102         {
2103           SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, SMESH::SMESH_GroupBase::_nil());
2104           aDlg->show();
2105         }
2106       break;
2107     }
2108
2109   case 804:                                     // Add elements to group
2110     {
2111       if(checkLock(aStudy)) break;
2112       if (myState == 800) {
2113         SMESHGUI_GroupDlg *aDlg = (SMESHGUI_GroupDlg*) myActiveDialogBox;
2114         if (aDlg) aDlg->onAdd();
2115       }
2116       break;
2117     }
2118
2119   case 805:                                     // Remove elements from group
2120     {
2121       if(checkLock(aStudy)) break;
2122       if (myState == 800) {
2123         SMESHGUI_GroupDlg *aDlg = (SMESHGUI_GroupDlg*) myActiveDialogBox;
2124         if (aDlg) aDlg->onRemove();
2125       }
2126       break;
2127     }
2128
2129   case 815:                                     // Edit GEOM GROUP as standalone
2130     {
2131       if ( !vtkwnd )
2132       {
2133         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),
2134                                   tr( "NOT_A_VTK_VIEWER" ) );
2135         break;
2136       }
2137
2138       if(checkLock(aStudy)) break;
2139       EmitSignalDeactivateDialog();
2140
2141       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2142       SALOME_ListIO selected;
2143       if( aSel )
2144         aSel->selectedObjects( selected );
2145
2146       SALOME_ListIteratorOfListIO It (selected);
2147       for ( ; It.More(); It.Next() )
2148       {
2149         SMESH::SMESH_GroupOnGeom_var aGroup =
2150           SMESH::IObjectToInterface<SMESH::SMESH_GroupOnGeom>(It.Value());
2151         if (!aGroup->_is_nil()) {
2152           SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, aGroup, true );
2153           aDlg->show();
2154         }
2155       }
2156       break;
2157     }
2158
2159     case 810: // Union Groups
2160     case 811: // Intersect groups
2161     case 812: // Cut groups
2162     {
2163       if ( !vtkwnd )
2164       {
2165         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),
2166                                   tr( "NOT_A_VTK_VIEWER" ) );
2167         break;
2168       }
2169
2170       if ( checkLock( aStudy ) )
2171         break;
2172
2173       EmitSignalDeactivateDialog();
2174
2175       SMESHGUI_GroupOpDlg* aDlg = 0;
2176       if ( theCommandID == 810 )
2177         aDlg = new SMESHGUI_UnionGroupsDlg( this );
2178       else if ( theCommandID == 811 )
2179         aDlg = new SMESHGUI_IntersectGroupsDlg( this );
2180       else
2181         aDlg = new SMESHGUI_CutGroupsDlg( this );
2182
2183       aDlg->show();
2184
2185       break;
2186     }
2187
2188     case 814: // Create groups of entities from existing groups of superior dimensions
2189     {
2190       if ( checkLock( aStudy ) )
2191         break;
2192
2193       EmitSignalDeactivateDialog();
2194       SMESHGUI_GroupOpDlg* aDlg = new SMESHGUI_DimGroupDlg( this );
2195       aDlg->show();
2196
2197       break;
2198     }
2199
2200     case 813: // Delete groups with their contents
2201     {
2202       if ( !vtkwnd )
2203       {
2204         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),
2205                                   tr( "NOT_A_VTK_VIEWER" ) );
2206         break;
2207       }
2208
2209       if ( checkLock( aStudy ) )
2210         break;
2211
2212       EmitSignalDeactivateDialog();
2213
2214       ( new SMESHGUI_DeleteGroupDlg( this ) )->show();
2215       break;
2216     }
2217
2218   case 900:                                     // MESH INFOS
2219     {
2220       EmitSignalDeactivateDialog();
2221       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2222       SALOME_ListIO selected;
2223       if( aSel )
2224         aSel->selectedObjects( selected );
2225
2226       if ( selected.Extent() > 1 ) { // a dlg for each IO
2227         SALOME_ListIO IOs;
2228         SALOME_ListIteratorOfListIO It (selected);
2229         for ( ; It.More(); It.Next() ) {
2230           IOs.Clear(); IOs.Append( It.Value() );
2231           aSel->setSelectedObjects( IOs );
2232           ( new SMESHGUI_MeshInfosDlg( this ) )->show();
2233         }
2234         // restore selection
2235         aSel->setSelectedObjects( selected );
2236       }
2237       else
2238         ( new SMESHGUI_MeshInfosDlg( this ) )->show();
2239       break;
2240     }
2241
2242   case 902:                                     // STANDARD MESH INFOS
2243     {
2244       EmitSignalDeactivateDialog();
2245       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2246       SALOME_ListIO selected;
2247       if( aSel )
2248         aSel->selectedObjects( selected );
2249
2250       if ( selected.Extent() > 1 ) { // a dlg for each IO
2251         SALOME_ListIO IOs;
2252         SALOME_ListIteratorOfListIO It (selected);
2253         for ( ; It.More(); It.Next() ) {
2254           IOs.Clear();
2255           IOs.Append( It.Value() );
2256           aSel->setSelectedObjects( IOs );
2257           ( new SMESHGUI_StandardMeshInfosDlg( this ) )->show();
2258         }
2259         // restore selection
2260         aSel->setSelectedObjects( selected );
2261       }
2262       else
2263         ( new SMESHGUI_StandardMeshInfosDlg( this ) )->show();
2264       break;
2265     }
2266
2267   case 903:                                     // WHAT IS
2268     {
2269       EmitSignalDeactivateDialog();
2270       ( new SMESHGUI_WhatIsDlg( this ) )->show();
2271       break;
2272     }
2273
2274   case 904:                                     // FIND ELEM
2275     {
2276       startOperation( theCommandID );
2277       break;
2278     }
2279
2280   case 1100:                                    // EDIT HYPOTHESIS
2281     {
2282       if(checkLock(aStudy)) break;
2283
2284       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2285       SALOME_ListIO selected;
2286       if( aSel )
2287         aSel->selectedObjects( selected );
2288
2289       int nbSel = selected.Extent();
2290
2291       if (nbSel == 1) {
2292         Handle(SALOME_InteractiveObject) anIObject = selected.First();
2293         SMESH::SMESH_Hypothesis_var aHypothesis = SMESH::IObjectToInterface<SMESH::SMESH_Hypothesis>(anIObject);
2294
2295         /* Look for all mesh objects that have this hypothesis affected in order to flag as ModifiedMesh */
2296         /* At end below '...->updateObjBrowser(true)' will change icon of mesh objects                   */
2297         /* Warning : however by internal mechanism all subMeshes icons are changed !                     */
2298         if ( !aHypothesis->_is_nil() )
2299         {
2300           // BUG 0020378
2301           //SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHypothesis->GetName());
2302           SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHypothesis->GetName());
2303           if (aCreator) {
2304             aCreator->edit( aHypothesis.in(), anIObject->getName(), desktop(), this, SLOT( onHypothesisEdit( int ) ) );
2305           }
2306           else
2307           {
2308             // report error
2309           }
2310         }
2311       }
2312       break;
2313     }
2314
2315   case 1101:                                    // RENAME
2316     {
2317       if ( checkLock( aStudy ) )
2318         break;
2319
2320       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2321       SALOME_ListIO selected;
2322       if( aSel )
2323         aSel->selectedObjects( selected );
2324
2325       bool isAny = false; // is there any appropriate object selected
2326
2327       SALOME_ListIteratorOfListIO It( selected );
2328       for ( ; It.More(); It.Next() )
2329       {
2330         Handle(SALOME_InteractiveObject) IObject = It.Value();
2331         _PTR(SObject) obj = aStudy->FindObjectID( IObject->getEntry() );
2332         _PTR(GenericAttribute) anAttr;
2333         _PTR(AttributeName) aName;
2334         if ( obj )
2335         {
2336           if ( obj->FindAttribute(anAttr, "AttributeName") )
2337           {
2338             aName = anAttr;
2339             QString newName = QString(aName->Value().c_str());
2340
2341             // check type to prevent renaming of inappropriate objects
2342             int aType = SMESHGUI_Selection::type(IObject->getEntry(), aStudy);
2343             if (aType == MESH || aType == GROUP ||
2344                 aType == SUBMESH || aType == SUBMESH_COMPOUND ||
2345                 aType == SUBMESH_SOLID || aType == SUBMESH_FACE ||
2346                 aType == SUBMESH_EDGE || aType == SUBMESH_VERTEX ||
2347                 aType == HYPOTHESIS || aType == ALGORITHM)
2348             {
2349               isAny = true;
2350               newName = LightApp_NameDlg::getName(desktop(), newName);
2351               if ( !newName.isEmpty() )
2352               {
2353                 SMESHGUI::GetSMESHGen()->SetName(obj->GetIOR().c_str(), newName.toLatin1().data());
2354
2355                 // update name of group object and its actor
2356                 SMESH::SMESH_GroupBase_var aGroupObject = SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IObject);
2357                 if( !aGroupObject->_is_nil() )
2358                 {
2359                   aGroupObject->SetName( newName.toLatin1().data() );
2360                   if ( SMESH_Actor *anActor = SMESH::FindActorByEntry( IObject->getEntry() ) )
2361                     anActor->setName( newName.toLatin1().data() );
2362                 }
2363
2364                 updateObjBrowser();
2365               }
2366             }
2367           }
2368         }
2369       } // for
2370
2371       if (!isAny) {
2372         SUIT_MessageBox::warning(desktop(),
2373                                  QObject::tr("SMESH_WRN_WARNING"),
2374                                  QObject::tr("SMESH_WRN_NO_APPROPRIATE_SELECTION"));
2375       }
2376       break;
2377     }
2378
2379   case 1102:                                    // REMOVE HYPOTHESIS / ALGORITHMS
2380     {
2381       if(checkLock(aStudy)) break;
2382       SUIT_OverrideCursor wc;
2383
2384       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2385       SALOME_ListIO selected;
2386       if( aSel )
2387         aSel->selectedObjects( selected, QString::null, false );
2388
2389       SALOME_ListIteratorOfListIO It(selected);
2390       for (int i = 0; It.More(); It.Next(), i++) {
2391         Handle(SALOME_InteractiveObject) IObject = It.Value();
2392         SMESH::RemoveHypothesisOrAlgorithmOnMesh(IObject);
2393       }
2394       SALOME_ListIO l1;
2395       aSel->setSelectedObjects( l1 );
2396       updateObjBrowser();
2397       break;
2398     }
2399
2400   case 4009:                                    // ELEM0D
2401   case 4010:                                    // GEOM::EDGE
2402   case 4021:                                    // TRIANGLE
2403   case 4022:                                    // QUAD
2404   case 4023:                                    // POLYGON
2405   case 4031:                                    // TETRA
2406   case 4032:                                    // HEXA
2407     {
2408       if(checkLock(aStudy)) break;
2409       if ( vtkwnd ) {
2410         EmitSignalDeactivateDialog();
2411         SMDSAbs_ElementType type    = SMDSAbs_Edge;
2412         int                 nbNodes = 2;
2413         switch (theCommandID) {
2414         case 4009:                                      // ELEM0D
2415           type = SMDSAbs_0DElement; nbNodes = 1; break;
2416         case 4021:                                      // TRIANGLE
2417           type = SMDSAbs_Face; nbNodes = 3; break;
2418         case 4022:                                      // QUAD
2419           type = SMDSAbs_Face; nbNodes = 4; break;
2420         case 4031:                                      // TETRA
2421           type = SMDSAbs_Volume; nbNodes = 4; break;
2422         case 4023:                                      // POLYGON
2423           type = SMDSAbs_Face; nbNodes = 5; break;     // 5 - identificator for POLYGON
2424         case 4032:                                      // HEXA
2425           type = SMDSAbs_Volume; nbNodes = 8; break;
2426         case 4033:                                      // POLYHEDRE
2427           type = SMDSAbs_Volume; nbNodes = 9; break; // 9 - identificator for POLYHEDRE
2428         default:;
2429         }
2430         ( new SMESHGUI_AddMeshElementDlg( this, type, nbNodes ) )->show();
2431       }
2432       else {
2433         SUIT_MessageBox::warning(desktop(),
2434                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2435       }
2436       break;
2437     }
2438   case 4033:                                    // POLYHEDRON
2439     {
2440       if(checkLock(aStudy)) break;
2441       if ( vtkwnd ) {
2442         EmitSignalDeactivateDialog();
2443         ( new SMESHGUI_CreatePolyhedralVolumeDlg( this ) )->show();
2444       }
2445       else {
2446         SUIT_MessageBox::warning(SMESHGUI::desktop(),
2447                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2448       }
2449       break;
2450     }
2451   case 4034:     // QUADRATIC EDGE
2452   case 4035:     // QUADRATIC TRIANGLE
2453   case 4036:     // QUADRATIC QUADRANGLE
2454   case 4037:     // QUADRATIC TETRAHEDRON
2455   case 4038:     // QUADRATIC PYRAMID
2456   case 4039:     // QUADRATIC PENTAHEDRON
2457   case 4040:     // QUADRATIC HEXAHEDRON
2458     {
2459       if(checkLock(aStudy)) break;
2460       if ( vtkwnd ) {
2461         EmitSignalDeactivateDialog();
2462         int type;
2463
2464         switch (theCommandID) {
2465         case 4034:
2466           type = QUAD_EDGE; break;
2467         case 4035:
2468           type = QUAD_TRIANGLE; break;
2469         case 4036:
2470           type = QUAD_QUADRANGLE; break;
2471         case 4037:
2472           type = QUAD_TETRAHEDRON; break;
2473         case 4038:
2474           type = QUAD_PYRAMID; break;
2475         case 4039:
2476           type = QUAD_PENTAHEDRON; break;
2477         case 4040:
2478           type = QUAD_HEXAHEDRON;
2479           break;
2480         default:;
2481         }
2482          ( new SMESHGUI_AddQuadraticElementDlg( this, type ) )->show();
2483       }
2484       else {
2485         SUIT_MessageBox::warning(SMESHGUI::desktop(),
2486                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2487       }
2488       break;
2489     }
2490   case 4041:                                    // REMOVES NODES
2491     {
2492       if(checkLock(aStudy)) break;
2493       if ( vtkwnd ) {
2494         EmitSignalDeactivateDialog();
2495         ( new SMESHGUI_RemoveNodesDlg( this ) )->show();
2496       }
2497       else {
2498         SUIT_MessageBox::warning(SMESHGUI::desktop(),
2499                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2500       }
2501       break;
2502     }
2503   case 4042:                                    // REMOVES ELEMENTS
2504     {
2505       if(checkLock(aStudy)) break;
2506       if( vtkwnd ) {
2507         EmitSignalDeactivateDialog();
2508         ( new SMESHGUI_RemoveElementsDlg( this ) )->show();
2509       }
2510       else
2511         {
2512           SUIT_MessageBox::warning(SMESHGUI::desktop(),
2513                                    tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2514         }
2515       break;
2516     }
2517   case 4043: {                                // CLEAR_MESH
2518
2519     if(checkLock(aStudy)) break;
2520
2521     SALOME_ListIO selected;
2522     if( LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr() )
2523       aSel->selectedObjects( selected );
2524
2525     SUIT_OverrideCursor wc;
2526     SALOME_ListIteratorOfListIO It (selected);
2527     for ( ; It.More(); It.Next() )
2528     {
2529       Handle(SALOME_InteractiveObject) IOS = It.Value();
2530       SMESH::SMESH_Mesh_var aMesh =
2531         SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IOS);
2532       if ( aMesh->_is_nil()) continue;
2533       try {
2534         SMESH::UpdateView(SMESH::eErase, IOS->getEntry());
2535         aMesh->Clear();
2536         _PTR(SObject) aMeshSObj = SMESH::FindSObject(aMesh);
2537         SMESH::ModifiedMesh( aMeshSObj, false, true);
2538         // hide groups and submeshes
2539         _PTR(ChildIterator) anIter =
2540           SMESH::GetActiveStudyDocument()->NewChildIterator( aMeshSObj );
2541         for ( anIter->InitEx(true); anIter->More(); anIter->Next() )
2542         {
2543           _PTR(SObject) so = anIter->Value();
2544           SMESH::UpdateView(SMESH::eErase, so->GetID().c_str());
2545         }
2546       }
2547       catch (const SALOME::SALOME_Exception& S_ex){
2548         wc.suspend();
2549         SalomeApp_Tools::QtCatchCorbaException(S_ex);
2550         wc.resume();
2551       }
2552     }
2553     SMESH::UpdateView();
2554     updateObjBrowser();
2555     break;
2556   }
2557   case 4051:                                    // RENUMBERING NODES
2558     {
2559       if(checkLock(aStudy)) break;
2560       if( vtkwnd ) {
2561         EmitSignalDeactivateDialog();
2562         ( new SMESHGUI_RenumberingDlg( this, 0 ) )->show();
2563       }
2564       else
2565         {
2566           SUIT_MessageBox::warning(SMESHGUI::desktop(),
2567                                    tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2568         }
2569       break;
2570     }
2571   case 4052:                                    // RENUMBERING ELEMENTS
2572     {
2573       if(checkLock(aStudy)) break;
2574       if ( vtkwnd ) {
2575         EmitSignalDeactivateDialog();
2576         ( new SMESHGUI_RenumberingDlg( this, 1 ) )->show();
2577       }
2578       else
2579         {
2580           SUIT_MessageBox::warning(SMESHGUI::desktop(),
2581                                    tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2582         }
2583       break;
2584     }
2585   case 4061:                                   // TRANSLATION
2586     {
2587       if(checkLock(aStudy)) break;
2588       if ( vtkwnd ) {
2589         EmitSignalDeactivateDialog();
2590         ( new SMESHGUI_TranslationDlg( this ) )->show();
2591       }
2592       else {
2593         SUIT_MessageBox::warning(SMESHGUI::desktop(),
2594                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2595       }
2596       break;
2597     }
2598   case 4062:                                   // ROTATION
2599     {
2600       if(checkLock(aStudy)) break;
2601       if( vtkwnd ) {
2602         EmitSignalDeactivateDialog();
2603         ( new SMESHGUI_RotationDlg( this ) )->show();
2604       }
2605       else {
2606         SUIT_MessageBox::warning(SMESHGUI::desktop(),
2607                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2608       }
2609       break;
2610     }
2611   case 4063:                                   // SYMMETRY
2612     {
2613       if(checkLock(aStudy)) break;
2614       if(vtkwnd) {
2615         EmitSignalDeactivateDialog();
2616         ( new SMESHGUI_SymmetryDlg( this ) )->show();
2617       }
2618       else {
2619         SUIT_MessageBox::warning(SMESHGUI::desktop(),
2620                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2621       }
2622       break;
2623     }
2624   case 4064:                                   // SEWING
2625     {
2626       if(checkLock(aStudy)) break;
2627       if(vtkwnd) {
2628         EmitSignalDeactivateDialog();
2629         ( new SMESHGUI_SewingDlg( this ) )->show();
2630       }
2631       else {
2632         SUIT_MessageBox::warning(SMESHGUI::desktop(),
2633                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2634       }
2635       break;
2636     }
2637   case 4065:                                   // MERGE NODES
2638     {
2639       if(checkLock(aStudy)) break;
2640       if(vtkwnd) {
2641         EmitSignalDeactivateDialog();
2642         ( new SMESHGUI_EditMeshDlg( this, 0 ) )->show();
2643       }
2644       else {
2645         SUIT_MessageBox::warning(SMESHGUI::desktop(),
2646                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2647       }
2648       break;
2649     }
2650   case 4066:                                   // MERGE EQUAL ELEMENTS
2651     {
2652       if (checkLock(aStudy)) break;
2653       if (vtkwnd) {
2654         EmitSignalDeactivateDialog();
2655         ( new SMESHGUI_EditMeshDlg( this, 1 ) )->show();
2656       } else {
2657         SUIT_MessageBox::warning(SMESHGUI::desktop(),
2658                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2659       }
2660       break;
2661     }
2662
2663   case 4067: // MAKE MESH PASS THROUGH POINT
2664     startOperation( 4067 );
2665     break;
2666
2667   case 4068: // SCALE
2668     {
2669       if(checkLock(aStudy)) break;
2670       if ( vtkwnd ) {
2671         EmitSignalDeactivateDialog();
2672         ( new SMESHGUI_ScaleDlg( this ) )->show();
2673       }
2674       else {
2675         SUIT_MessageBox::warning(SMESHGUI::desktop(),
2676                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2677       }
2678       break;
2679     }
2680
2681   case 5105: // Library of selection filters
2682   {
2683     static QList<int> aTypes;
2684     if ( aTypes.isEmpty() )
2685     {
2686       aTypes.append( SMESH::NODE );
2687       aTypes.append( SMESH::EDGE );
2688       aTypes.append( SMESH::FACE );
2689       aTypes.append( SMESH::VOLUME );
2690     }
2691     if (!myFilterLibraryDlg)
2692       myFilterLibraryDlg = new SMESHGUI_FilterLibraryDlg( this, SMESH::GetDesktop( this ), aTypes, SMESHGUI_FilterLibraryDlg::EDIT );
2693     else if (myFilterLibraryDlg->isHidden())
2694       myFilterLibraryDlg->Init( aTypes, SMESHGUI_FilterLibraryDlg::EDIT );
2695     myFilterLibraryDlg->raise();
2696   }
2697   break;
2698
2699   case 6017:                                    // CONTROLS
2700   case 6016:
2701   case 6015:
2702   case 6014:
2703   case 6013:
2704   case 6012:
2705   case 6011:
2706   case 6001:
2707   case 6018:
2708   case 6019:
2709   case 6002:
2710   case 6003:
2711   case 6004:
2712   case 6005:
2713   case 6009:
2714   case 6021:
2715     if ( vtkwnd ) {
2716
2717       LightApp_SelectionMgr* mgr = selectionMgr();
2718       SALOME_ListIO selected; mgr->selectedObjects( selected );
2719
2720       if ( selected.Extent() == 1 && selected.First()->hasEntry() ) {
2721         _PTR(SObject) SO = aStudy->FindObjectID( selected.First()->getEntry() );
2722         if ( SO ) {
2723           CORBA::Object_var aObject = SMESH::SObjectToObject( SO );
2724           SMESH::SMESH_Mesh_var      aMesh    = SMESH::SMESH_Mesh::_narrow( aObject );
2725           SMESH::SMESH_subMesh_var   aSubMesh = SMESH::SMESH_subMesh::_narrow( aObject );
2726           SMESH::SMESH_GroupBase_var aGroup   = SMESH::SMESH_GroupBase::_narrow( aObject );
2727           if ( !aMesh->_is_nil() || !aSubMesh->_is_nil() || !aGroup->_is_nil() ) {
2728             ::Control( theCommandID );
2729             break;
2730           }
2731         }
2732       }
2733       SUIT_MessageBox::warning(desktop(),
2734                                tr( "SMESH_WRN_WARNING" ),
2735                                tr( "SMESH_BAD_SELECTION" ) );
2736       break;
2737     }
2738     else {
2739       SUIT_MessageBox::warning(desktop(),
2740                                tr( "SMESH_WRN_WARNING" ),
2741                                tr( "NOT_A_VTK_VIEWER" ) );
2742     }
2743     break;
2744   case 9010:
2745     {
2746       LightApp_SelectionMgr* mgr = selectionMgr();
2747       SALOME_ListIO selected; mgr->selectedObjects( selected );
2748
2749       SALOME_ListIteratorOfListIO it(selected);
2750       for( ; it.More(); it.Next()) {
2751         Handle(SALOME_InteractiveObject) anIObject = it.Value();
2752         if(anIObject->hasEntry()) {
2753           if(SMESH_Actor *anActor = SMESH::FindActorByEntry(anIObject->getEntry())){
2754             anActor->SetPointsLabeled( !anActor->GetPointsLabeled() );
2755           }
2756         }
2757       }
2758       break;
2759     }
2760   case 9011:
2761     {
2762       LightApp_SelectionMgr* mgr = selectionMgr();
2763       SALOME_ListIO selected; mgr->selectedObjects( selected );
2764
2765       if (selected.Extent() == 1)       {
2766         Handle(SALOME_InteractiveObject) anIObject = selected.First();
2767         if(anIObject->hasEntry())
2768           if(SMESH_Actor *anActor = SMESH::FindActorByEntry(anIObject->getEntry())){
2769             anActor->SetCellsLabeled( !anActor->GetCellsLabeled() );
2770           }
2771       }
2772       break;
2773     }
2774   }
2775
2776   anApp->updateActions(); //SRN: To update a Save button in the toolbar
2777   //updateObjBrowser();
2778   return true;
2779 }
2780
2781 //=============================================================================
2782 /*!
2783  *
2784  */
2785 //=============================================================================
2786 bool SMESHGUI::OnMousePress( QMouseEvent * pe, SUIT_ViewWindow * wnd )
2787 {
2788   return false;
2789 }
2790
2791 //=============================================================================
2792 /*!
2793  *
2794  */
2795 //=============================================================================
2796 bool SMESHGUI::OnMouseMove( QMouseEvent * pe, SUIT_ViewWindow * wnd )
2797 {
2798   return true;
2799 }
2800
2801 //=============================================================================
2802 /*!
2803  *
2804  */
2805 //=============================================================================
2806 bool SMESHGUI::OnKeyPress( QKeyEvent * pe, SUIT_ViewWindow * wnd )
2807 {
2808   return true;
2809 }
2810
2811 //=============================================================================
2812 /*! Method:  BuildPresentation(const Handle(SALOME_InteractiveObject)& theIO)
2813  *  Purpose: ensures that the actor for the given <theIO> exists in the active VTK view
2814  */
2815 //=============================================================================
2816 void SMESHGUI::BuildPresentation( const Handle(SALOME_InteractiveObject) & theIO,
2817                                   SUIT_ViewWindow* wnd )
2818 {
2819   if(theIO->hasEntry()){
2820     //SUIT_ViewWindow* wnd = SMESH::GetActiveWindow();
2821     SMESH::UpdateView(wnd,SMESH::eDisplay,theIO->getEntry());
2822   }
2823 }
2824
2825 //=======================================================================
2826 // function : createSMESHAction
2827 // purpose  :
2828 //=======================================================================
2829 void SMESHGUI::createSMESHAction( const int id, const QString& po_id, const QString& icon_id, const int key, const bool toggle  )
2830 {
2831   QIcon icon;
2832   QWidget* parent = application()->desktop();
2833   SUIT_ResourceMgr* resMgr = resourceMgr();
2834   QPixmap pix;
2835   if ( !icon_id.isEmpty() )
2836     pix = resMgr->loadPixmap( "SMESH", tr( icon_id.toLatin1().data() ) );
2837   else
2838     pix = resMgr->loadPixmap( "SMESH", tr( QString( "ICO_%1" ).arg( po_id ).toLatin1().data() ), false );
2839   if ( !pix.isNull() )
2840     icon = QIcon( pix );
2841
2842   QString tooltip    = tr( QString( "TOP_%1" ).arg( po_id ).toLatin1().data() ),
2843           menu       = tr( QString( "MEN_%1" ).arg( po_id ).toLatin1().data() ),
2844           status_bar = tr( QString( "STB_%1" ).arg( po_id ).toLatin1().data() );
2845
2846   createAction( id, tooltip, icon, menu, status_bar, key, parent, toggle, this, SLOT( OnGUIEvent() )  );
2847 }
2848
2849 //=======================================================================
2850 // function : createPopupItem
2851 // purpose  :
2852 //=======================================================================
2853 void SMESHGUI::createPopupItem( const int id,
2854                                 const QString& clients,
2855                                 const QString& types,
2856                                 const QString& theRule,
2857                                 const int pId )
2858 {
2859   int parentId = pId;
2860   if( pId!=-1 )
2861     parentId = popupMgr()->actionId( action( pId ) );
2862
2863   if( !popupMgr()->contains( popupMgr()->actionId( action( id ) ) ) )
2864     popupMgr()->insert( action( id ), parentId, 0 );
2865
2866   QString lc = "$";        // VSR : instead of QtxPopupSelection::defEquality();
2867   QString dc = "selcount"; // VSR : insetad of QtxPopupSelection::defSelCountParam()
2868   QString rule = "(%1) and (%2) and (%3)";
2869   rule = rule.arg( QString( "%1>0" ).arg( dc ) );
2870   if( clients.isEmpty() )
2871     rule = rule.arg( QString( "true" ) );
2872   else
2873     rule = rule.arg( QString( "%1client in {%2}" ).arg( lc ).arg( clients ) );
2874   rule = rule.arg( QString( "%1type in {%2}" ).arg( lc ).arg( types ) );
2875   rule += theRule;
2876
2877   bool cont = myRules.contains( id );
2878   if( cont )
2879     rule = QString( "%1 or (%2)" ).arg( myRules[ id ] ).arg( rule );
2880
2881   popupMgr()->setRule( action( id ), rule, QtxPopupMgr::VisibleRule );
2882   myRules[ id ] = QString( cont ? "%1" : "(%1)" ).arg( rule );
2883 }
2884
2885 //=======================================================================
2886 // function : initialize
2887 // purpose  :
2888 //=======================================================================
2889 void SMESHGUI::initialize( CAM_Application* app )
2890 {
2891   SalomeApp_Module::initialize( app );
2892
2893 //   SUIT_ResourceMgr* mgr = app->resourceMgr();
2894 //   if ( mgr )
2895   /* Automatic Update flag */
2896 //     myAutomaticUpdate = mgr->booleanValue( "SMESH", "AutomaticUpdate", myAutomaticUpdate );
2897
2898   // ----- create actions --------------
2899
2900   createSMESHAction(  111, "DAT", "", (Qt::CTRL+Qt::Key_B) );
2901   createSMESHAction(  112, "UNV", "", (Qt::CTRL+Qt::Key_U) );
2902   createSMESHAction(  113, "MED", "", (Qt::CTRL+Qt::Key_M) );
2903   createSMESHAction(  114, "NUM" );
2904   createSMESHAction(  121, "DAT" );
2905   createSMESHAction(  122, "MED" );
2906   createSMESHAction(  123, "UNV" );
2907   createSMESHAction(  140, "STL" );
2908   createSMESHAction(  124, "EXPORT_DAT" );
2909   createSMESHAction(  125, "EXPORT_MED" );
2910   createSMESHAction(  126, "EXPORT_UNV" );
2911   createSMESHAction(  141, "EXPORT_STL" );
2912   createSMESHAction(  150, "FILE_INFO" );
2913   createSMESHAction(   33, "DELETE",          "ICON_DELETE", Qt::Key_Delete );
2914   createSMESHAction( 5105, "SEL_FILTER_LIB" );
2915   createSMESHAction(  701, "COMPUTE",         "ICON_COMPUTE" );
2916   createSMESHAction(  702, "CREATE_MESH",     "ICON_DLG_INIT_MESH" );
2917   createSMESHAction(  703, "CREATE_SUBMESH",  "ICON_DLG_ADD_SUBMESH" );
2918   createSMESHAction(  704, "EDIT_MESHSUBMESH","ICON_DLG_EDIT_MESH" );
2919   createSMESHAction(  710, "BUILD_COMPOUND",  "ICON_BUILD_COMPOUND" );
2920   createSMESHAction(  711, "PRECOMPUTE",      "ICON_PRECOMPUTE" );
2921   createSMESHAction(  712, "EVALUATE",        "ICON_COMPUTE" );
2922   createSMESHAction(  713, "MESH_ORDER",      "ICON_COMPUTE" );
2923   createSMESHAction(  806, "CREATE_GEO_GROUP","ICON_CREATE_GEO_GROUP" );
2924   createSMESHAction(  801, "CREATE_GROUP",    "ICON_CREATE_GROUP" );
2925   createSMESHAction(  802, "CONSTRUCT_GROUP", "ICON_CONSTRUCT_GROUP" );
2926   createSMESHAction(  803, "EDIT_GROUP",      "ICON_EDIT_GROUP" );
2927   createSMESHAction(  815, "EDIT_GEOMGROUP_AS_GROUP", "ICON_EDIT_GROUP" );
2928   createSMESHAction(  804, "ADD" );
2929   createSMESHAction(  805, "REMOVE" );
2930   createSMESHAction(  810, "UN_GROUP",        "ICON_UNION" );
2931   createSMESHAction(  811, "INT_GROUP",       "ICON_INTERSECT" );
2932   createSMESHAction(  812, "CUT_GROUP",       "ICON_CUT" );
2933   createSMESHAction(  814, "UNDERLYING_ELEMS","ICON_UNDERLYING_ELEMS" );
2934   createSMESHAction(  813, "DEL_GROUP",       "ICON_DEL_GROUP" );
2935   createSMESHAction(  900, "ADV_INFO",        "ICON_ADV_INFO" );
2936   createSMESHAction(  902, "STD_INFO",        "ICON_STD_INFO" );
2937   createSMESHAction(  903, "WHAT_IS",         "ICON_WHAT_IS" );
2938   createSMESHAction(  904, "FIND_ELEM",       "ICON_FIND_ELEM" );
2939   createSMESHAction( 6001, "LENGTH",          "ICON_LENGTH",        0, true );
2940   createSMESHAction( 6002, "FREE_EDGE",       "ICON_FREE_EDGE",     0, true );
2941   createSMESHAction( 6021, "FREE_FACES",      "ICON_FREE_FACES",    0, true );
2942   createSMESHAction( 6003, "FREE_BORDER",     "ICON_FREE_EDGE_2D",  0, true );
2943   createSMESHAction( 6004, "CONNECTION",      "ICON_CONNECTION",    0, true );
2944   createSMESHAction( 6005, "FREE_NODE",       "ICON_FREE_NODE",     0, true );
2945   createSMESHAction( 6011, "AREA",            "ICON_AREA",          0, true );
2946   createSMESHAction( 6012, "TAPER",           "ICON_TAPER",         0, true );
2947   createSMESHAction( 6013, "ASPECT",          "ICON_ASPECT",        0, true );
2948   createSMESHAction( 6014, "MIN_ANG",         "ICON_ANGLE",         0, true );
2949   createSMESHAction( 6015, "WARP",            "ICON_WARP",          0, true );
2950   createSMESHAction( 6016, "SKEW",            "ICON_SKEW",          0, true );
2951   createSMESHAction( 6017, "ASPECT_3D",       "ICON_ASPECT_3D",     0, true );
2952   createSMESHAction( 6018, "LENGTH_2D",       "ICON_LENGTH_2D",     0, true );
2953   createSMESHAction( 6019, "CONNECTION_2D",   "ICON_CONNECTION_2D", 0, true );
2954   createSMESHAction( 6009, "VOLUME_3D",       "ICON_VOLUME_3D",     0, true );
2955   createSMESHAction( 4000, "NODE",            "ICON_DLG_NODE" );
2956   createSMESHAction( 4009, "ELEM0D",          "ICON_DLG_ELEM0D" );
2957   createSMESHAction( 4010, "EDGE",            "ICON_DLG_EDGE" );
2958   createSMESHAction( 4021, "TRIANGLE",        "ICON_DLG_TRIANGLE" );
2959   createSMESHAction( 4022, "QUAD",            "ICON_DLG_QUADRANGLE" );
2960   createSMESHAction( 4023, "POLYGON",         "ICON_DLG_POLYGON" );
2961   createSMESHAction( 4031, "TETRA",           "ICON_DLG_TETRAS" );
2962   createSMESHAction( 4032, "HEXA",            "ICON_DLG_HEXAS" );
2963   createSMESHAction( 4041, "REMOVE_NODES",    "ICON_DLG_REM_NODE" );
2964   createSMESHAction( 4042, "REMOVE_ELEMENTS", "ICON_DLG_REM_ELEMENT" );
2965   createSMESHAction( 4043, "CLEAR_MESH"    ,  "ICON_CLEAR_MESH" );
2966   createSMESHAction( 4051, "RENUM_NODES",     "ICON_DLG_RENUMBERING_NODES" );
2967   createSMESHAction( 4052, "RENUM_ELEMENTS",  "ICON_DLG_RENUMBERING_ELEMENTS" );
2968   createSMESHAction( 4061, "TRANS",           "ICON_SMESH_TRANSLATION_VECTOR" );
2969   createSMESHAction( 4062, "ROT",             "ICON_DLG_MESH_ROTATION" );
2970   createSMESHAction( 4063, "SYM",             "ICON_SMESH_SYMMETRY_PLANE" );
2971   createSMESHAction( 4064, "SEW",             "ICON_SMESH_SEWING_FREEBORDERS" );
2972   createSMESHAction( 4065, "MERGE",           "ICON_SMESH_MERGE_NODES" );
2973   createSMESHAction( 4066, "MERGE_ELEMENTS",  "ICON_DLG_MERGE_ELEMENTS" );
2974   createSMESHAction( 4067, "MESH_THROU_POINT","ICON_DLG_MOVE_NODE" );
2975   createSMESHAction( 4068, "SCALE",           "ICON_DLG_MESH_SCALE" );
2976   createSMESHAction(  407, "INV",             "ICON_DLG_MESH_DIAGONAL" );
2977   createSMESHAction(  408, "UNION2",          "ICON_UNION2TRI" );
2978   createSMESHAction(  409, "ORIENT",          "ICON_DLG_MESH_ORIENTATION" );
2979   createSMESHAction(  410, "UNION",           "ICON_UNIONTRI" );
2980   createSMESHAction(  411, "CUT",             "ICON_CUTQUAD" );
2981   createSMESHAction(  412, "SMOOTH",          "ICON_DLG_SMOOTHING" );
2982   createSMESHAction(  413, "EXTRUSION",       "ICON_EXTRUSION" );
2983   createSMESHAction(  414, "REVOLUTION",      "ICON_REVOLUTION" );
2984   createSMESHAction(  415, "MAP",             "ICON_MAP" );
2985   createSMESHAction(  416, "EXTRUSION_ALONG", "ICON_EXTRUSION_ALONG" );
2986   createSMESHAction(  417, "CONV_TO_QUAD",    "ICON_CONV_TO_QUAD" );
2987   createSMESHAction(  418, "2D_FROM_3D",      "ICON_2D_FROM_3D" );
2988   createSMESHAction(  419, "SPLIT_TO_TETRA",  "ICON_SPLIT_TO_TETRA" );
2989   createSMESHAction(  200, "RESET" );
2990   createSMESHAction(  201, "SCALAR_BAR_PROP" );
2991   createSMESHAction(  211, "WIRE",           "ICON_WIRE", 0, true );
2992   createSMESHAction(  212, "SHADE",          "ICON_SHADE", 0, true );
2993   createSMESHAction(  213, "SHRINK",         "ICON_SHRINK", 0, true );
2994   createSMESHAction(  214, "UPDATE",         "ICON_UPDATE" );
2995   createSMESHAction(  215, "NODES",          "ICON_POINTS", 0, true );
2996   createSMESHAction(  216, "ELEMS0D",        "ICON_DLG_ELEM0D", 0, true );
2997   createSMESHAction(  217, "EDGES",          "ICON_DLG_EDGE", 0, true );
2998   createSMESHAction(  218, "FACES",          "ICON_DLG_TRIANGLE", 0, true );
2999   createSMESHAction(  219, "VOLUMES",        "ICON_DLG_TETRAS", 0, true );
3000   createSMESHAction(  220, "ALL" );
3001   createSMESHAction(  221, "FACE_ORIENTATION", "", 0, true );
3002
3003   createSMESHAction(  231, "LINE_REPRESENTATION", "", 0, true );
3004   createSMESHAction(  232, "ARC_REPRESENTATION", "", 0, true );
3005
3006   createSMESHAction( 1100, "EDIT_HYPO" );
3007   createSMESHAction( 1101, "RENAME", "", Qt::Key_F2 );
3008   createSMESHAction( 1102, "UNASSIGN" );
3009   createSMESHAction( 9010, "NUM_NODES", "", 0, true );
3010   createSMESHAction( 9011, "NUM_ELEMENTS", "", 0, true );
3011   createSMESHAction( 1131, "DISPMODE" );
3012   createSMESHAction( 1132, "COLORS" );
3013   createSMESHAction( 1133, "TRANSP" );
3014   createSMESHAction( 1134, "CLIP" );
3015   createSMESHAction( 1135, "DISP_ENT" );
3016   createSMESHAction( 1136, "AUTO_COLOR" );
3017   createSMESHAction( 1137, "DISABLE_AUTO_COLOR" );
3018   createSMESHAction( 2000, "CTRL" );
3019
3020   createSMESHAction( 300, "ERASE" );
3021   createSMESHAction( 301, "DISPLAY" );
3022   createSMESHAction( 302, "DISPLAY_ONLY" );
3023   createSMESHAction( 4033, "POLYHEDRON", "ICON_DLG_POLYHEDRON" );
3024   createSMESHAction( 4034, "QUADRATIC_EDGE", "ICON_DLG_QUADRATIC_EDGE" );
3025   createSMESHAction( 4035, "QUADRATIC_TRIANGLE", "ICON_DLG_QUADRATIC_TRIANGLE" );
3026   createSMESHAction( 4036, "QUADRATIC_QUADRANGLE", "ICON_DLG_QUADRATIC_QUADRANGLE" );
3027   createSMESHAction( 4037, "QUADRATIC_TETRAHEDRON", "ICON_DLG_QUADRATIC_TETRAHEDRON" );
3028   createSMESHAction( 4038, "QUADRATIC_PYRAMID", "ICON_DLG_QUADRATIC_PYRAMID" );
3029   createSMESHAction( 4039, "QUADRATIC_PENTAHEDRON", "ICON_DLG_QUADRATIC_PENTAHEDRON" );
3030   createSMESHAction( 4040, "QUADRATIC_HEXAHEDRON", "ICON_DLG_QUADRATIC_HEXAHEDRON" );
3031
3032   // ----- create menu --------------
3033   int fileId   = createMenu( tr( "MEN_FILE" ),   -1,  1 ),
3034       editId   = createMenu( tr( "MEN_EDIT" ),   -1,  3 ),
3035       toolsId  = createMenu( tr( "MEN_TOOLS" ),  -1,  5, 50 ),
3036       meshId   = createMenu( tr( "MEN_MESH" ),   -1, 70, 10 ),
3037       ctrlId   = createMenu( tr( "MEN_CTRL" ),   -1, 60, 10 ),
3038       modifyId = createMenu( tr( "MEN_MODIFY" ), -1, 40, 10 ),
3039       viewId   = createMenu( tr( "MEN_VIEW" ),   -1,  2 );
3040
3041   createMenu( separator(), fileId );
3042
3043   int importId = createMenu( tr( "MEN_IMPORT" ), fileId, -1, 10 ),
3044       exportId = createMenu( tr( "MEN_EXPORT" ), fileId, -1, 10 ),
3045       addId    = createMenu( tr( "MEN_ADD" ),    modifyId, 402 ),
3046       removeId = createMenu( tr( "MEN_REMOVE" ), modifyId, 403 ),
3047       renumId  = createMenu( tr( "MEN_RENUM" ),  modifyId, 404 ),
3048       transfId = createMenu( tr( "MEN_TRANSF" ), modifyId, 405 );
3049
3050   createMenu( 111, importId, -1 );
3051   createMenu( 112, importId, -1 );
3052   createMenu( 113, importId, -1 );
3053
3054   createMenu( 121, exportId, -1 );
3055   createMenu( 122, exportId, -1 );
3056   createMenu( 123, exportId, -1 );
3057   createMenu( 140, exportId, -1 ); // export to stl STL
3058
3059   createMenu( separator(), fileId, 10 );
3060
3061   createMenu( 33, editId, -1 );
3062
3063   createMenu( 5105, toolsId, -1 );
3064
3065   createMenu( 702, meshId, -1 ); // "Mesh" menu
3066   createMenu( 703, meshId, -1 );
3067   createMenu( 704, meshId, -1 );
3068   createMenu( 710, meshId, -1 );
3069   createMenu( separator(), meshId, -1 );
3070   createMenu( 701, meshId, -1 );
3071   createMenu( 711, meshId, -1 );
3072   createMenu( 712, meshId, -1 );
3073   createMenu( 713, meshId, -1 );
3074   createMenu( separator(), meshId, -1 );
3075   createMenu( 801, meshId, -1 );
3076   createMenu( 806, meshId, -1 );
3077   createMenu( 802, meshId, -1 );
3078   createMenu( 803, meshId, -1 );
3079   createMenu( 815, meshId, -1 );
3080   createMenu( separator(), meshId, -1 );
3081   createMenu( 810, meshId, -1 );
3082   createMenu( 811, meshId, -1 );
3083   createMenu( 812, meshId, -1 );
3084   createMenu( separator(), meshId, -1 );
3085   createMenu( 814, meshId, -1 );
3086   createMenu( separator(), meshId, -1 );
3087   createMenu( 813, meshId, -1 );
3088   createMenu( separator(), meshId, -1 );
3089   createMenu( 900, meshId, -1 );
3090   createMenu( 902, meshId, -1 );
3091   createMenu( 903, meshId, -1 );
3092   createMenu( 904, meshId, -1 );
3093   createMenu( separator(), meshId, -1 );
3094
3095   createMenu( 6003, ctrlId, -1 );
3096   createMenu( 6001, ctrlId, -1 );
3097   createMenu( 6004, ctrlId, -1 );
3098   createMenu( separator(), ctrlId, -1 );
3099   createMenu( 6005, ctrlId, -1 );
3100   createMenu( 6002, ctrlId, -1 );
3101   createMenu( 6018, ctrlId, -1 );
3102   createMenu( 6019, ctrlId, -1 );
3103   createMenu( 6011, ctrlId, -1 );
3104   createMenu( 6012, ctrlId, -1 );
3105   createMenu( 6013, ctrlId, -1 );
3106   createMenu( 6014, ctrlId, -1 );
3107   createMenu( 6015, ctrlId, -1 );
3108   createMenu( 6016, ctrlId, -1 );
3109   createMenu( separator(), ctrlId, -1 );
3110   createMenu( 6017, ctrlId, -1 );
3111   createMenu( 6009, ctrlId, -1 );
3112   createMenu( 6021, ctrlId, -1 );
3113   createMenu( separator(), ctrlId, -1 );
3114
3115   createMenu( 4000, addId, -1 );
3116   createMenu( 4009, addId, -1 );
3117   createMenu( 4010, addId, -1 );
3118   createMenu( 4021, addId, -1 );
3119   createMenu( 4022, addId, -1 );
3120   createMenu( 4023, addId, -1 );
3121   createMenu( 4031, addId, -1 );
3122   createMenu( 4032, addId, -1 );
3123   createMenu( 4033, addId, -1 );
3124   createMenu( separator(), addId, -1 );
3125   createMenu( 4034, addId, -1 );
3126   createMenu( 4035, addId, -1 );
3127   createMenu( 4036, addId, -1 );
3128   createMenu( 4037, addId, -1 );
3129   createMenu( 4038, addId, -1 );
3130   createMenu( 4039, addId, -1 );
3131   createMenu( 4040, addId, -1 );
3132
3133   createMenu( 4041, removeId, -1 );
3134   createMenu( 4042, removeId, -1 );
3135   createMenu( 4043, removeId, -1 );
3136
3137   createMenu( 4051, renumId, -1 );
3138   createMenu( 4052, renumId, -1 );
3139
3140   createMenu( 4061, transfId, -1 );
3141   createMenu( 4062, transfId, -1 );
3142   createMenu( 4063, transfId, -1 );
3143   createMenu( 4064, transfId, -1 );
3144   createMenu( 4065, transfId, -1 );
3145   createMenu( 4066, transfId, -1 );
3146   createMenu( 4068, transfId, -1 );
3147
3148   createMenu( 4067,modifyId, -1 );
3149   createMenu( 407, modifyId, -1 );
3150   createMenu( 408, modifyId, -1 );
3151   createMenu( 409, modifyId, -1 );
3152   createMenu( 410, modifyId, -1 );
3153   createMenu( 411, modifyId, -1 );
3154   createMenu( 419, modifyId, -1 );
3155   createMenu( 412, modifyId, -1 );
3156   createMenu( 413, modifyId, -1 );
3157   createMenu( 416, modifyId, -1 );
3158   createMenu( 414, modifyId, -1 );
3159   createMenu( 415, modifyId, -1 );
3160   createMenu( 417, modifyId, -1 );
3161   createMenu( 418, modifyId, -1 );
3162
3163   createMenu( 214, viewId, -1 );
3164
3165   // ----- create toolbars --------------
3166   int meshTb     = createTool( tr( "TB_MESH" ) ),
3167       ctrlTb     = createTool( tr( "TB_CTRL" ) ),
3168       addRemTb   = createTool( tr( "TB_ADD_REMOVE" ) ),
3169       modifyTb   = createTool( tr( "TB_MODIFY" ) ),
3170       dispModeTb = createTool( tr( "TB_DISP_MODE" ) );
3171
3172   createTool( 702, meshTb );
3173   createTool( 703, meshTb );
3174   createTool( 704, meshTb );
3175   createTool( 710, meshTb );
3176   createTool( separator(), meshTb );
3177   createTool( 701, meshTb );
3178   createTool( 711, meshTb );
3179   createTool( 712, meshTb );
3180   createTool( 713, meshTb );
3181   createTool( separator(), meshTb );
3182   createTool( 801, meshTb );
3183   createTool( 806, meshTb );
3184   createTool( 802, meshTb );
3185   createTool( 803, meshTb );
3186   //createTool( 815, meshTb );
3187   createTool( separator(), meshTb );
3188   createTool( 900, meshTb );
3189   createTool( 902, meshTb );
3190   createTool( 903, meshTb );
3191   createTool( 904, meshTb );
3192   createTool( separator(), meshTb );
3193
3194   createTool( 6001, ctrlTb );
3195   createTool( 6003, ctrlTb );
3196   createTool( 6004, ctrlTb );
3197   createTool( separator(), ctrlTb );
3198   createTool( 6005, ctrlTb );
3199   createTool( 6002, ctrlTb );
3200   createTool( 6018, ctrlTb );
3201   createTool( 6019, ctrlTb );
3202   createTool( 6011, ctrlTb );
3203   createTool( 6012, ctrlTb );
3204   createTool( 6013, ctrlTb );
3205   createTool( 6014, ctrlTb );
3206   createTool( 6015, ctrlTb );
3207   createTool( 6016, ctrlTb );
3208   createTool( separator(), ctrlTb );
3209   createTool( 6017, ctrlTb );
3210   createTool( 6009, ctrlTb );
3211   createTool( 6021, ctrlTb );
3212   createTool( separator(), ctrlTb );
3213
3214   createTool( 4000, addRemTb );
3215   createTool( 4009, addRemTb );
3216   createTool( 4010, addRemTb );
3217   createTool( 4021, addRemTb );
3218   createTool( 4022, addRemTb );
3219   createTool( 4023, addRemTb );
3220   createTool( 4031, addRemTb );
3221   createTool( 4032, addRemTb );
3222   createTool( 4033, addRemTb );
3223   createTool( separator(), addRemTb );
3224   createTool( 4034, addRemTb );
3225   createTool( 4035, addRemTb );
3226   createTool( 4036, addRemTb );
3227   createTool( 4037, addRemTb );
3228   createTool( 4038, addRemTb );
3229   createTool( 4039, addRemTb );
3230   createTool( 4040, addRemTb );
3231   createTool( separator(), addRemTb );
3232   createTool( 4041, addRemTb );
3233   createTool( 4042, addRemTb );
3234   createTool( 4043, addRemTb );
3235   createTool( separator(), addRemTb );
3236   createTool( 4051, addRemTb );
3237   createTool( 4052, addRemTb );
3238   createTool( separator(), addRemTb );
3239   createTool( 4061, addRemTb );
3240   createTool( 4062, addRemTb );
3241   createTool( 4063, addRemTb );
3242   createTool( 4064, addRemTb );
3243   createTool( 4065, addRemTb );
3244   createTool( 4066, addRemTb );
3245   createTool( 4068, addRemTb );
3246   createTool( separator(), addRemTb );
3247
3248   createTool( 4067,modifyTb );
3249   createTool( 407, modifyTb );
3250   createTool( 408, modifyTb );
3251   createTool( 409, modifyTb );
3252   createTool( 410, modifyTb );
3253   createTool( 411, modifyTb );
3254   createTool( 419, modifyTb );
3255   createTool( 412, modifyTb );
3256   createTool( 413, modifyTb );
3257   createTool( 416, modifyTb );
3258   createTool( 414, modifyTb );
3259   createTool( 415, modifyTb );
3260   createTool( 417, modifyTb );
3261   createTool( 418, modifyTb );
3262
3263   createTool( 214, dispModeTb );
3264
3265   QString lc = "$";        // VSR : instead of QtxPopupSelection::defEquality();
3266   QString dc = "selcount"; // VSR : instead of QtxPopupSelection::defSelCountParam()
3267
3268   myRules.clear();
3269   QString OB = "'ObjectBrowser'",
3270           View = "'" + SVTK_Viewer::Type() + "'",
3271           pat = "'%1'",
3272           mesh    = pat.arg( SMESHGUI_Selection::typeName( MESH ) ),
3273           group   = pat.arg( SMESHGUI_Selection::typeName( GROUP ) ),
3274           hypo    = pat.arg( SMESHGUI_Selection::typeName( HYPOTHESIS ) ),
3275           algo    = pat.arg( SMESHGUI_Selection::typeName( ALGORITHM ) ),
3276           elems   = QString( "'%1' '%2' '%3' '%4' '%5' '%6'" ).
3277                        arg( SMESHGUI_Selection::typeName( SUBMESH_VERTEX ) ).
3278                        arg( SMESHGUI_Selection::typeName( SUBMESH_EDGE ) ).
3279                        arg( SMESHGUI_Selection::typeName( SUBMESH_FACE ) ).
3280                        arg( SMESHGUI_Selection::typeName( SUBMESH_SOLID ) ).
3281                        arg( SMESHGUI_Selection::typeName( SUBMESH_COMPOUND ) ).
3282                        arg( SMESHGUI_Selection::typeName( SUBMESH ) ),
3283           subMesh = elems,
3284           mesh_group = mesh + " " + subMesh + " " + group,
3285           hyp_alg = hypo + " " + algo;
3286
3287   // popup for object browser
3288   QString
3289     isInvisible("not( isVisible )"),
3290     isEmpty("numberOfNodes = 0"),
3291     isNotEmpty("numberOfNodes <> 0"),
3292
3293     // has nodes, edges, etc in VISIBLE! actor
3294     hasNodes("(numberOfNodes > 0 )"),//&& isVisible)"),
3295     hasElems("(count( elemTypes ) > 0)"),
3296     hasDifferentElems("(count( elemTypes ) > 1)"),
3297     hasElems0d("({'Elem0d'} in elemTypes)"),
3298     hasEdges("({'Edge'} in elemTypes)"),
3299     hasFaces("({'Face'} in elemTypes)"),
3300     hasVolumes("({'Volume'} in elemTypes)");
3301
3302   createPopupItem( 150, OB, mesh, "&& selcount=1 && isImported" );      // FILE INFORMATION
3303   createPopupItem( 703, OB, mesh, "&& isComputable");      // CREATE_SUBMESH
3304   //createPopupItem( 703, OB, subMesh, "&& isComputable" );  // CREATE_SUBMESH
3305   createPopupItem( 704, OB, mesh, "&& isComputable");      // EDIT_MESHSUBMESH
3306   createPopupItem( 704, OB, subMesh, "&& isComputable" );  // EDIT_MESHSUBMESH
3307   createPopupItem( 803, OB, group );                       // EDIT_GROUP
3308   createPopupItem( 815, OB, group, "&& groupType = 'GroupOnGeom'" ); // EDIT_GROUP
3309
3310   popupMgr()->insert( separator(), -1, 0 );
3311   createPopupItem( 701, OB, mesh, "&& isComputable" );     // COMPUTE
3312   createPopupItem( 711, OB, mesh, "&& isComputable && isPreComputable" ); // PRECOMPUTE
3313   createPopupItem( 712, OB, mesh, "&& isComputable" );     // EVALUATE
3314   createPopupItem( 713, OB, mesh, "&& isComputable" );     // MESH ORDER
3315   createPopupItem( 214, OB, mesh_group );                  // UPDATE
3316   createPopupItem( 900, OB, mesh_group );                  // ADV_INFO
3317   createPopupItem( 902, OB, mesh );                        // STD_INFO
3318   createPopupItem( 903, OB, mesh_group );                  // WHAT_IS
3319   createPopupItem( 904, OB, mesh_group );                  // FIND_ELEM
3320   popupMgr()->insert( separator(), -1, 0 );
3321   createPopupItem( 801, OB, mesh );                        // CREATE_GROUP
3322   createPopupItem( 806, OB, mesh );                        // CREATE_GEO_GROUP
3323   createPopupItem( 802, OB, subMesh );                     // CONSTRUCT_GROUP
3324   popupMgr()->insert( separator(), -1, 0 );
3325   createPopupItem( 1100, OB, hypo);                        // EDIT HYPOTHESIS
3326   createPopupItem( 1102, OB, hyp_alg ); // REMOVE HYPOTHESIS / ALGORITHMS
3327   createPopupItem( 1101, OB, mesh_group + " " + hyp_alg ); // RENAME
3328   popupMgr()->insert( separator(), -1, 0 );
3329   createPopupItem( 4043, OB, mesh );                       // CLEAR_MESH
3330   popupMgr()->insert( separator(), -1, 0 );
3331   createPopupItem( 417, OB, mesh/*, "&& " + hasElems*/);       // convert to quadratic
3332   createPopupItem( 418, OB, mesh/*, "&& " + hasVolumes*/);     // create 2D mesh on 3D
3333   popupMgr()->insert( separator(), -1, 0 );
3334
3335   QString only_one_non_empty = QString( " && %1=1 && numberOfNodes>0" ).arg( dc );
3336   QString multiple_non_empty = QString( " && %1>0 && numberOfNodes>0" ).arg( dc );
3337
3338   createPopupItem( 125, OB, mesh, multiple_non_empty );   // EXPORT_MED
3339   createPopupItem( 126, OB, mesh, only_one_non_empty );   // EXPORT_UNV
3340   createPopupItem( 141, OB, mesh, only_one_non_empty );   // EXPORT_STL
3341   //createPopupItem( 33, OB, subMesh + " " + group );       // DELETE
3342   createPopupItem(  33, OB, mesh_group + " " + hyp_alg ); // DELETE
3343   popupMgr()->insert( separator(), -1, 0 );
3344
3345   // popup for viewer
3346   createPopupItem( 803, View, group ); // EDIT_GROUP
3347   createPopupItem( 804, View, elems ); // ADD
3348   createPopupItem( 805, View, elems ); // REMOVE
3349
3350   popupMgr()->insert( separator(), -1, 0 );
3351   createPopupItem( 214, View, mesh_group ); // UPDATE
3352   createPopupItem( 900, View, mesh_group ); // ADV_INFO
3353   createPopupItem( 902, View, mesh );       // STD_INFO
3354   createPopupItem( 903, View, mesh_group ); // WHAT_IS
3355   createPopupItem( 904, View, mesh_group ); // FIND_ELEM
3356   popupMgr()->insert( separator(), -1, 0 );
3357
3358   createPopupItem( 1136, OB + " " + View, mesh, "&& (not isAutoColor)" ); // AUTO_COLOR
3359   createPopupItem( 1137, OB + " " + View, mesh, "&& isAutoColor" );       // DISABLE_AUTO_COLOR
3360   popupMgr()->insert( separator(), -1, 0 );
3361
3362   int anId;
3363   QString aClient = QString( "%1client in {%2}" ).arg( lc ).arg( "'VTKViewer'" );
3364   QString aType = QString( "%1type in {%2}" ).arg( lc );
3365   aType = aType.arg( mesh_group );
3366   QString aMeshInVTK = aClient + "&&" + aType;
3367
3368   aClient = "($client in {'VTKViewer' 'ObjectBrowser'})";
3369   QString anActiveVTK = QString("activeView = '%1'").arg(SVTK_Viewer::Type());
3370   QString aSelCount = QString( "%1 > 0" ).arg( dc );
3371
3372   //-------------------------------------------------
3373   // Numbering
3374   //-------------------------------------------------
3375   anId = popupMgr()->insert( tr( "MEN_NUM" ), -1, -1 );
3376
3377   popupMgr()->insert( action( 9010 ), anId, -1 );
3378   popupMgr()->setRule( action( 9010 ), aMeshInVTK + "&& isVisible &&" + hasNodes, QtxPopupMgr::VisibleRule );
3379   popupMgr()->setRule( action( 9010 ), "{'Point'} in labeledTypes", QtxPopupMgr::ToggleRule );
3380
3381   popupMgr()->insert( action( 9011 ), anId, -1 );
3382   popupMgr()->setRule( action( 9011 ), aMeshInVTK + "&& isVisible &&" + hasElems, QtxPopupMgr::VisibleRule );
3383   popupMgr()->setRule( action( 9011 ), "{'Cell'} in labeledTypes", QtxPopupMgr::ToggleRule );
3384
3385   popupMgr()->insert( separator(), -1, -1 );
3386
3387   //-------------------------------------------------
3388   // Display Mode
3389   //-------------------------------------------------
3390   anId = popupMgr()->insert( tr( "MEN_DISPMODE" ), -1, -1 );
3391
3392   popupMgr()->insert( action( 211 ), anId, -1 ); // WIRE
3393   popupMgr()->setRule( action( 211 ), aMeshInVTK + "&&" + hasElems, QtxPopupMgr::VisibleRule );
3394   popupMgr()->setRule( action( 211 ), "displayMode = 'eEdge'", QtxPopupMgr::ToggleRule );
3395
3396   popupMgr()->insert( action( 212 ), anId, -1 ); // SHADE
3397   popupMgr()->setRule( action( 212 ),aMeshInVTK+ "&& (" + hasFaces + "||" + hasVolumes + ")", QtxPopupMgr::VisibleRule);
3398   popupMgr()->setRule( action( 212 ), "displayMode = 'eSurface'", QtxPopupMgr::ToggleRule );
3399
3400   popupMgr()->insert( action( 215 ), anId, -1 ); // POINTS
3401   popupMgr()->setRule( action( 215 ), aMeshInVTK + "&&" + hasNodes, QtxPopupMgr::VisibleRule );
3402   popupMgr()->setRule( action( 215 ), "displayMode = 'ePoint'", QtxPopupMgr::ToggleRule );
3403
3404   popupMgr()->insert( separator(), anId, -1 );
3405
3406   popupMgr()->insert( action( 213 ), anId, -1 ); // SHRINK
3407   popupMgr()->setRule( action( 213 ), aMeshInVTK + "&& shrinkMode <> 'IsNotShrinkable' && displayMode <> 'ePoint'", QtxPopupMgr::VisibleRule);
3408   popupMgr()->setRule( action( 213 ), "shrinkMode = 'IsShrunk'", QtxPopupMgr::ToggleRule );
3409
3410   //-------------------------------------------------
3411   // Display Entity
3412   //-------------------------------------------------
3413   QString aDiffElemsInVTK = aMeshInVTK + "&&" + hasDifferentElems;
3414
3415   anId = popupMgr()->insert( tr( "MEN_DISP_ENT" ), -1, -1 );
3416
3417   popupMgr()->insert( action(216), anId, -1 ); // ELEMS 0D
3418   popupMgr()->setRule(action(216), aDiffElemsInVTK + "&& isVisible &&" + hasElems0d, QtxPopupMgr::VisibleRule);
3419   popupMgr()->setRule(action(216), "{'Elem0d'} in entityMode", QtxPopupMgr::ToggleRule);
3420
3421   popupMgr()->insert( action( 217 ), anId, -1 ); // EDGES
3422   popupMgr()->setRule( action( 217 ), aDiffElemsInVTK + "&& isVisible &&" + hasEdges, QtxPopupMgr::VisibleRule );
3423   popupMgr()->setRule( action( 217 ), "{'Edge'} in entityMode", QtxPopupMgr::ToggleRule );
3424
3425   popupMgr()->insert( action( 218 ), anId, -1 ); // FACES
3426   popupMgr()->setRule( action( 218 ), aDiffElemsInVTK + "&& isVisible &&" + hasFaces, QtxPopupMgr::VisibleRule );
3427   popupMgr()->setRule( action( 218 ), "{'Face'} in entityMode", QtxPopupMgr::ToggleRule );
3428
3429   popupMgr()->insert( action( 219 ), anId, -1 ); // VOLUMES
3430   popupMgr()->setRule( action( 219 ), aDiffElemsInVTK + "&& isVisible &&" + hasVolumes, QtxPopupMgr::VisibleRule );
3431   popupMgr()->setRule( action( 219 ), "{'Volume'} in entityMode", QtxPopupMgr::ToggleRule );
3432
3433   popupMgr()->insert( separator(), anId, -1 );
3434
3435   popupMgr()->insert( action( 220 ), anId, -1 ); // ALL
3436   popupMgr()->setRule( action( 220 ), aDiffElemsInVTK + "&& isVisible && not( elemTypes in entityMode )", QtxPopupMgr::VisibleRule );
3437
3438
3439   //-------------------------------------------------
3440   // Representation of the 2D Quadratic elements
3441   //-------------------------------------------------  
3442   anId = popupMgr()->insert( tr( "MEN_QUADRATIC_REPRESENT" ), -1, -1 );
3443   popupMgr()->insert( action( 231 ), anId, -1 ); // LINE REPRESENTATION
3444   popupMgr()->setRule( action( 231 ), aMeshInVTK + "and isVisible",QtxPopupMgr::VisibleRule );
3445   popupMgr()->setRule( action( 231 ), "quadratic2DMode = 'eLines'", QtxPopupMgr::ToggleRule );
3446   
3447   popupMgr()->insert( action( 232 ), anId, -1 ); // ARC REPRESENTATION
3448   popupMgr()->setRule( action( 232 ), aMeshInVTK + "and isVisible", QtxPopupMgr::VisibleRule );
3449   popupMgr()->setRule( action( 232 ), "quadratic2DMode = 'eArcs'", QtxPopupMgr::ToggleRule );
3450
3451   //-------------------------------------------------
3452   // Orientation of faces
3453   //-------------------------------------------------
3454   popupMgr()->insert( action( 221 ), -1, -1 );
3455   popupMgr()->setRule( action( 221 ), aMeshInVTK + "&& isVisible", QtxPopupMgr::VisibleRule);
3456   popupMgr()->setRule( action( 221 ), "facesOrientationMode = 'IsOriented'", QtxPopupMgr::ToggleRule );
3457
3458   //-------------------------------------------------
3459   // Color / Size
3460   //-------------------------------------------------
3461   popupMgr()->insert( action( 1132 ), -1, -1 );
3462   popupMgr()->setRule( action( 1132 ), aMeshInVTK + "&& isVisible", QtxPopupMgr::VisibleRule );
3463
3464   //-------------------------------------------------
3465   // Transparency
3466   //-------------------------------------------------
3467   popupMgr()->insert( action( 1133 ), -1, -1 );
3468   popupMgr()->setRule( action( 1133 ), aMeshInVTK + "&& isVisible", QtxPopupMgr::VisibleRule );
3469
3470   //-------------------------------------------------
3471   // Clipping
3472   //-------------------------------------------------
3473   popupMgr()->insert( action( 1134 ), -1, -1 );
3474   popupMgr()->setRule( action( 1134 ), aMeshInVTK + "&& selcount=1 && isVisible", QtxPopupMgr::VisibleRule );
3475
3476   popupMgr()->insert( separator(), -1, -1 );
3477
3478   //-------------------------------------------------
3479   // Controls
3480   //-------------------------------------------------
3481   QString
3482     aMeshInVtkHasNodes = aMeshInVTK + "&&" + hasNodes,
3483     aMeshInVtkHasEdges = aMeshInVTK + "&&" + hasEdges,
3484     aMeshInVtkHasFaces = aMeshInVTK + "&&" + hasFaces,
3485     aMeshInVtkHasVolumes = aMeshInVTK + "&&" + hasVolumes;
3486
3487   anId = popupMgr()->insert( tr( "MEN_CTRL" ), -1, -1 );
3488   
3489   popupMgr()->insert( action( 200 ), anId, -1 ); // RESET
3490   popupMgr()->setRule( action( 200 ), aMeshInVTK + "&& controlMode <> 'eNone'", QtxPopupMgr::VisibleRule );
3491
3492   popupMgr()->insert( separator(), anId, -1 );
3493
3494   popupMgr()->insert( action( 6003 ), anId, -1 ); // FREE_BORDER
3495   popupMgr()->setRule( action( 6003 ), aMeshInVtkHasEdges, QtxPopupMgr::VisibleRule );
3496   popupMgr()->setRule( action( 6003 ), "controlMode = 'eFreeBorders'", QtxPopupMgr::ToggleRule );
3497
3498   popupMgr()->insert( action( 6001 ), anId, -1 ); // LENGTH
3499   popupMgr()->setRule( action( 6001 ), aMeshInVtkHasEdges, QtxPopupMgr::VisibleRule );
3500   popupMgr()->setRule( action( 6001 ), "controlMode = 'eLength'", QtxPopupMgr::ToggleRule );
3501
3502   popupMgr()->insert( action( 6004 ), anId, -1 ); // CONNECTION
3503   popupMgr()->setRule( action( 6004 ), aMeshInVtkHasEdges, QtxPopupMgr::VisibleRule );
3504   popupMgr()->setRule( action( 6004 ), "controlMode = 'eMultiConnection'", QtxPopupMgr::ToggleRule );
3505
3506   popupMgr()->insert( separator(), anId, -1 );
3507
3508   popupMgr()->insert( action( 6005 ), anId, -1 ); // FREE_NODE
3509   popupMgr()->setRule( action( 6005 ), aMeshInVtkHasNodes, QtxPopupMgr::VisibleRule );
3510   popupMgr()->setRule( action( 6005 ), "controlMode = 'eFreeNodes'", QtxPopupMgr::ToggleRule );
3511
3512   popupMgr()->insert( action( 6002 ), anId, -1 ); // FREE_EDGE
3513   popupMgr()->setRule( action( 6002 ), aMeshInVtkHasEdges, QtxPopupMgr::VisibleRule );
3514   popupMgr()->setRule( action( 6002 ), "controlMode = 'eFreeEdges'", QtxPopupMgr::ToggleRule );
3515
3516   popupMgr()->insert( action( 6018 ), anId, -1 ); // LENGTH_2D
3517   popupMgr()->setRule( action( 6018 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
3518   popupMgr()->setRule( action( 6018 ), "controlMode = 'eLength2D'", QtxPopupMgr::ToggleRule );
3519
3520   popupMgr()->insert( action( 6019 ), anId, -1 ); // CONNECTION_2D
3521   popupMgr()->setRule( action( 6019 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
3522   popupMgr()->setRule( action( 6019 ), "controlMode = 'eMultiConnection2D'", QtxPopupMgr::ToggleRule );
3523
3524   popupMgr()->insert( action( 6011 ), anId, -1 ); // AREA
3525   popupMgr()->setRule( action( 6011 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
3526   popupMgr()->setRule( action( 6011 ), "controlMode = 'eArea'", QtxPopupMgr::ToggleRule );
3527
3528   popupMgr()->insert( action( 6012 ), anId, -1 ); // TAPER
3529   popupMgr()->setRule( action( 6012 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
3530   popupMgr()->setRule( action( 6012 ), "controlMode = 'eTaper'", QtxPopupMgr::ToggleRule );
3531
3532   popupMgr()->insert( action( 6013 ), anId, -1 ); // ASPECT
3533   popupMgr()->setRule( action( 6013 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
3534   popupMgr()->setRule( action( 6013 ), "controlMode = 'eAspectRatio'", QtxPopupMgr::ToggleRule );
3535
3536   popupMgr()->insert( action( 6014 ), anId, -1 ); // MIN_ANG
3537   popupMgr()->setRule( action( 6014 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
3538   popupMgr()->setRule( action( 6014 ), "controlMode = 'eMinimumAngle'", QtxPopupMgr::ToggleRule );
3539
3540   popupMgr()->insert( action( 6015 ), anId, -1 ); // WARP
3541   popupMgr()->setRule( action( 6015 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
3542   popupMgr()->setRule( action( 6015 ), "controlMode = 'eWarping'", QtxPopupMgr::ToggleRule );
3543
3544   popupMgr()->insert( action( 6016 ), anId, -1 ); // SKEW
3545   popupMgr()->setRule( action( 6016 ), aMeshInVtkHasFaces, QtxPopupMgr::VisibleRule );
3546   popupMgr()->setRule( action( 6016 ), "controlMode = 'eSkew'", QtxPopupMgr::ToggleRule );
3547
3548   popupMgr()->insert( separator(), anId, -1 );
3549
3550   popupMgr()->insert( action( 6017 ), anId, -1 ); // ASPECT_3D
3551   popupMgr()->setRule( action( 6017 ), aMeshInVtkHasVolumes, QtxPopupMgr::VisibleRule );
3552   popupMgr()->setRule( action( 6017 ), "controlMode = 'eAspectRatio3D'", QtxPopupMgr::ToggleRule );
3553
3554   popupMgr()->insert ( action( 6009 ), anId, -1 ); // VOLUME_3D
3555   popupMgr()->setRule( action( 6009 ), aMeshInVtkHasVolumes, QtxPopupMgr::VisibleRule );
3556   popupMgr()->setRule( action( 6009 ), "controlMode = 'eVolume3D'", QtxPopupMgr::ToggleRule );
3557
3558   popupMgr()->insert( action( 6021 ), anId, -1 ); // FREE_FACE
3559   popupMgr()->setRule( action( 6021 ), aMeshInVtkHasFaces /*aMeshInVtkHasVolumes*/,
3560                                        QtxPopupMgr::VisibleRule );
3561   popupMgr()->setRule( action( 6021 ), "controlMode = 'eFreeFaces'", QtxPopupMgr::ToggleRule );
3562
3563   popupMgr()->insert( separator(), anId, -1 );
3564
3565   popupMgr()->insert( action( 201 ), anId, -1 ); // SCALAR_BAR_PROP
3566   popupMgr()->setRule( action( 201 ), aMeshInVTK + "&& controlMode <> 'eNone'", QtxPopupMgr::VisibleRule );
3567
3568   popupMgr()->insert( separator(), -1, -1 );
3569   
3570   //-------------------------------------------------
3571   // Display / Erase
3572   //-------------------------------------------------
3573   QString aRule = "$component={'SMESH'} and ( type='Component' or (" + aClient + " and " +
3574     aType + " and " + aSelCount + " and " + anActiveVTK + " and " + isNotEmpty + " %1 ) )";
3575   popupMgr()->insert( action( 301 ), -1, -1 ); // DISPLAY
3576   popupMgr()->setRule( action( 301 ), aRule.arg( "and (not isVisible)" ), QtxPopupMgr::VisibleRule );
3577
3578   popupMgr()->insert( action( 300 ), -1, -1 ); // ERASE
3579   popupMgr()->setRule( action( 300 ), aRule.arg( "and isVisible" ), QtxPopupMgr::VisibleRule );
3580
3581   popupMgr()->insert( action( 302 ), -1, -1 ); // DISPLAY_ONLY
3582   popupMgr()->setRule( action( 302 ), aRule.arg( "" ), QtxPopupMgr::VisibleRule );
3583
3584   popupMgr()->insert( separator(), -1, -1 );
3585
3586   connect( application(), SIGNAL( viewManagerActivated( SUIT_ViewManager* ) ),
3587            this, SLOT( onViewManagerActivated( SUIT_ViewManager* ) ) );
3588 }
3589
3590 //================================================================================
3591 /*!
3592  * \brief Return true if SMESH or GEOM objects are selected.
3593  * Is called form LightApp_Module::activateModule() which clear selection if
3594  * not isSelectionCompatible()
3595  */
3596 //================================================================================
3597
3598 bool SMESHGUI::isSelectionCompatible()
3599 {
3600   bool isCompatible = true;
3601   SALOME_ListIO selected;
3602   if ( LightApp_SelectionMgr *Sel = selectionMgr() )
3603     Sel->selectedObjects( selected );
3604
3605   SALOME_ListIteratorOfListIO It( selected );
3606   for ( ; isCompatible && It.More(); It.Next())
3607     isCompatible =
3608       ( strcmp("GEOM", It.Value()->getComponentDataType()) == 0 ) ||
3609       ( strcmp("SMESH", It.Value()->getComponentDataType()) == 0 );
3610
3611   return isCompatible;
3612 }
3613
3614
3615 bool SMESHGUI::reusableOperation( const int id )
3616 {
3617   // compute, evaluate and precompute are not reusable operations
3618   return ( id == 701 || id == 711 || id == 712 ) ? false : SalomeApp_Module::reusableOperation( id );
3619
3620
3621 bool SMESHGUI::activateModule( SUIT_Study* study )
3622 {
3623   bool res = SalomeApp_Module::activateModule( study );
3624
3625   setMenuShown( true );
3626   setToolShown( true );
3627
3628   // Reset actions accelerator keys
3629   action(111)->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_B)); // Import DAT
3630   action(112)->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_U)); // Import UNV
3631   action(113)->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_M)); // Import MED
3632
3633   action(  33)->setEnabled(true); // Delete: Key_Delete
3634   action(1101)->setEnabled(true); // Rename: Key_F2
3635
3636   //  0020210. Make SMESH_Gen update meshes at switching GEOM->SMESH
3637   GetSMESHGen()->SetCurrentStudy(SALOMEDS::Study::_nil());
3638   if ( SalomeApp_Study* s = dynamic_cast<SalomeApp_Study*>( study ))
3639     if ( _PTR(Study) aStudy = s->studyDS()) {
3640       GetSMESHGen()->SetCurrentStudy( _CAST(Study,aStudy)->GetStudy() );
3641       updateObjBrowser(); // objects can be removed
3642     }
3643
3644   return res;
3645 }
3646
3647 bool SMESHGUI::deactivateModule( SUIT_Study* study )
3648 {
3649   setMenuShown( false );
3650   setToolShown( false );
3651
3652   EmitSignalCloseAllDialogs();
3653
3654   // Unset actions accelerator keys
3655   action(111)->setShortcut(QKeySequence()); // Import DAT
3656   action(112)->setShortcut(QKeySequence()); // Import UNV
3657   action(113)->setShortcut(QKeySequence()); // Import MED
3658
3659   action(  33)->setEnabled(false); // Delete: Key_Delete
3660   action(1101)->setEnabled(false); // Rename: Key_F2
3661
3662   return SalomeApp_Module::deactivateModule( study );
3663 }
3664
3665 void SMESHGUI::studyClosed( SUIT_Study* s )
3666 {
3667   SMESH::RemoveVisuData( s->id() );
3668   SalomeApp_Module::studyClosed( s );
3669 }
3670
3671 void SMESHGUI::OnGUIEvent()
3672 {
3673   const QObject* obj = sender();
3674   if ( !obj || !obj->inherits( "QAction" ) )
3675     return;
3676   int id = actionId((QAction*)obj);
3677   if ( id != -1 )
3678     OnGUIEvent( id );
3679 }
3680
3681 SMESH::SMESH_Gen_var SMESHGUI::GetSMESHGen()
3682 {
3683   _PTR(Study) aStudy = SMESH::GetActiveStudyDocument(); //Document OCAF de l'etude active
3684   if ( CORBA::is_nil( myComponentSMESH ) )
3685     {
3686       SMESHGUI aGUI; //SRN BugID: IPAL9186: Create an instance of SMESHGUI to initialize myComponentSMESH
3687       if ( aStudy )
3688         aGUI.myComponentSMESH->SetCurrentStudy(_CAST(Study,aStudy)->GetStudy());
3689       return aGUI.myComponentSMESH;
3690     }
3691   if ( aStudy )
3692     myComponentSMESH->SetCurrentStudy(_CAST(Study,aStudy)->GetStudy());
3693   return myComponentSMESH;
3694 }
3695
3696 QString SMESHGUI::engineIOR() const
3697 {
3698   CORBA::ORB_var anORB = getApp()->orb();
3699   CORBA::String_var anIOR = anORB->object_to_string(GetSMESHGen());
3700   return QString( anIOR.in() );
3701 }
3702
3703 void SMESHGUI::contextMenuPopup( const QString& client, QMenu* menu, QString& title )
3704 {
3705   SalomeApp_Module::contextMenuPopup( client, menu, title );
3706   SALOME_ListIO lst;
3707   selectionMgr()->selectedObjects( lst );
3708   if ( ( client == "OCCViewer" || client == "VTKViewer" ) && lst.Extent() == 1 ) {
3709     Handle(SALOME_InteractiveObject) io = lst.First();
3710     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( application()->activeStudy() );
3711     _PTR(Study) study = appStudy->studyDS();
3712     _PTR(SObject) obj = study->FindObjectID( io->getEntry() );
3713     if ( obj ) {
3714       QString aName = QString( obj->GetName().c_str() );
3715       while ( aName.at( aName.length() - 1 ) == ' ' ) // Remove extraspaces in Name of Popup
3716           aName.remove( (aName.length() - 1), 1 );
3717       title = aName;
3718     }
3719   }
3720 }
3721
3722 LightApp_Selection* SMESHGUI::createSelection() const
3723 {
3724   return new SMESHGUI_Selection();
3725 }
3726
3727 void SMESHGUI::windows( QMap<int, int>& aMap ) const
3728 {
3729   aMap.insert( SalomeApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
3730   aMap.insert( SalomeApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
3731 }
3732
3733 void SMESHGUI::viewManagers( QStringList& list ) const
3734 {
3735   list.append( SVTK_Viewer::Type() );
3736 }
3737
3738 void SMESHGUI::onViewManagerActivated( SUIT_ViewManager* mgr )
3739 {
3740   if ( dynamic_cast<SVTK_ViewManager*>( mgr ) )
3741     SMESH::UpdateSelectionProp( this );
3742 }
3743
3744 void SMESHGUI::createPreferences()
3745 {
3746   // General tab ------------------------------------------------------------------------
3747   int genTab = addPreference( tr( "PREF_TAB_GENERAL" ) );
3748
3749   int updateGroup = addPreference( tr( "PREF_GROUP_UPDATE" ), genTab );
3750   addPreference( tr( "PREF_AUTO_UPDATE" ), updateGroup, LightApp_Preferences::Bool, "SMESH", "auto_update" );
3751
3752   int qaGroup = addPreference( tr( "PREF_GROUP_QUALITY" ), genTab );
3753   setPreferenceProperty( qaGroup, "columns", 2 );
3754   addPreference( tr( "PREF_DISPLAY_ENTITY" ), qaGroup, LightApp_Preferences::Bool, "SMESH", "display_entity" );
3755   addPreference( tr( "PREF_PRECISION_USE" ), qaGroup, LightApp_Preferences::Bool, "SMESH", "use_precision" );
3756   int prec = addPreference( tr( "PREF_PRECISION_VALUE" ), qaGroup, LightApp_Preferences::IntSpin, "SMESH", "controls_precision" );
3757   setPreferenceProperty( prec, "min", 0 );
3758   setPreferenceProperty( prec, "max", 16 );
3759
3760   int dispgroup = addPreference( tr( "PREF_DISPLAY_MODE" ), genTab );
3761   setPreferenceProperty( dispgroup, "columns", 2 );
3762   int dispmode = addPreference( tr( "PREF_DISPLAY_MODE" ), dispgroup, LightApp_Preferences::Selector, "SMESH", "display_mode" );
3763   QStringList modes;
3764   modes.append( "Wireframe" );
3765   modes.append( "Shading" );
3766   modes.append( "Nodes" );
3767   modes.append( "Shrink" );
3768   QList<QVariant> indices;
3769   indices.append( 0 );
3770   indices.append( 1 );
3771   indices.append( 2 );
3772   indices.append( 3 );
3773   setPreferenceProperty( dispmode, "strings", modes );
3774   setPreferenceProperty( dispmode, "indexes", indices );
3775
3776   int arcgroup = addPreference( tr( "QUADRATIC_REPRESENT_MODE" ), genTab );
3777   setPreferenceProperty( arcgroup, "columns", 2 );
3778   int quadraticmode = addPreference( tr( "QUADRATIC_REPRESENT_MODE" ), arcgroup, LightApp_Preferences::Selector, "SMESH", "quadratic_mode" );
3779   QStringList quadraticModes;
3780   quadraticModes.append("Lines");
3781   quadraticModes.append("Arcs");
3782   indices.clear();
3783   indices.append( 0 );
3784   indices.append( 1 );
3785   setPreferenceProperty( quadraticmode, "strings", quadraticModes );
3786   setPreferenceProperty( quadraticmode, "indexes", indices );
3787
3788   int maxAngle = addPreference( tr( "MAX_ARC_ANGLE" ), arcgroup, LightApp_Preferences::IntSpin,
3789                               "SMESH", "max_angle" );
3790   setPreferenceProperty( maxAngle, "min", 1 );
3791   setPreferenceProperty( maxAngle, "max", 90 );
3792   
3793   
3794
3795   int exportgroup = addPreference( tr( "PREF_GROUP_EXPORT" ), genTab );
3796   setPreferenceProperty( exportgroup, "columns", 2 );
3797   addPreference( tr( "PREF_AUTO_GROUPS" ), exportgroup, LightApp_Preferences::Bool, "SMESH", "auto_groups" );
3798   addPreference( tr( "PREF_RENUMBER" ), exportgroup, LightApp_Preferences::Bool, "SMESH", "renumbering" );
3799
3800   int computeGroup = addPreference( tr( "PREF_GROUP_COMPUTE" ), genTab );
3801   setPreferenceProperty( computeGroup, "columns", 2 );
3802   int notifyMode = addPreference( tr( "PREF_NOTIFY_MODE" ), computeGroup, LightApp_Preferences::Selector, "SMESH", "show_result_notification" );
3803   modes.clear();
3804   modes.append( "Never" );
3805   modes.append( "Errors only" );
3806   modes.append( "Always" );
3807   indices.clear();
3808   indices.append( 0 );
3809   indices.append( 1 );
3810   indices.append( 2 );
3811   setPreferenceProperty( notifyMode, "strings", modes );
3812   setPreferenceProperty( notifyMode, "indexes", indices );
3813
3814   int segGroup = addPreference( tr( "PREF_GROUP_SEGMENT_LENGTH" ), genTab );
3815   setPreferenceProperty( segGroup, "columns", 2 );
3816   int segLen = addPreference( tr( "PREF_SEGMENT_LENGTH" ), segGroup, LightApp_Preferences::IntSpin,
3817                               "SMESH", "segmentation" );
3818   setPreferenceProperty( segLen, "min", 1 );
3819   setPreferenceProperty( segLen, "max", 10000000 );
3820   int nbSeg = addPreference( tr( "PREF_NB_SEGMENTS" ), segGroup, LightApp_Preferences::IntSpin,
3821                              "SMESH", "nb_segments_per_edge" );
3822   setPreferenceProperty( nbSeg, "min", 1 );
3823   setPreferenceProperty( nbSeg, "max", 10000000 );
3824   
3825   // Quantities with individual precision settings
3826   int precGroup = addPreference( tr( "SMESH_PREF_GROUP_PRECISION" ), genTab );
3827   setPreferenceProperty( precGroup, "columns", 2 );
3828   
3829   const int nbQuantities = 6;
3830   int precs[nbQuantities], ii = 0;
3831   precs[ii++] = addPreference( tr( "SMESH_PREF_length_precision" ), precGroup,
3832                             LightApp_Preferences::IntSpin, "SMESH", "length_precision" );  
3833   precs[ii++] = addPreference( tr( "SMESH_PREF_angle_precision" ), precGroup,
3834                             LightApp_Preferences::IntSpin, "SMESH", "angle_precision" );
3835   precs[ii++] = addPreference( tr( "SMESH_PREF_len_tol_precision" ), precGroup,
3836                             LightApp_Preferences::IntSpin, "SMESH", "len_tol_precision" );
3837   precs[ii++] = addPreference( tr( "SMESH_PREF_parametric_precision" ), precGroup,
3838                             LightApp_Preferences::IntSpin, "SMESH", "parametric_precision" );
3839   precs[ii++] = addPreference( tr( "SMESH_PREF_area_precision" ), precGroup,
3840                             LightApp_Preferences::IntSpin, "SMESH", "area_precision" );
3841   precs[ii  ] = addPreference( tr( "SMESH_PREF_vol_precision" ), precGroup,
3842                             LightApp_Preferences::IntSpin, "SMESH", "vol_precision" );  
3843   
3844   // Set property for precision value for spinboxes
3845   for ( ii = 0; ii < nbQuantities; ii++ ){
3846     setPreferenceProperty( precs[ii], "min", -14 );
3847     setPreferenceProperty( precs[ii], "max", 14 );
3848     setPreferenceProperty( precs[ii], "precision", 2 );
3849   }   
3850
3851   // Mesh tab ------------------------------------------------------------------------
3852   int meshTab = addPreference( tr( "PREF_TAB_MESH" ) );
3853   int nodeGroup = addPreference( tr( "PREF_GROUP_NODES" ), meshTab );
3854   setPreferenceProperty( nodeGroup, "columns", 3 );
3855
3856   addPreference( tr( "PREF_COLOR" ), nodeGroup, LightApp_Preferences::Color, "SMESH", "node_color" );
3857
3858   int typeOfMarker = addPreference( tr( "PREF_TYPE_OF_MARKER" ), nodeGroup, LightApp_Preferences::Selector, "SMESH", "type_of_marker" );
3859
3860   SUIT_ResourceMgr* aResourceMgr = SMESH::GetResourceMgr(this);
3861   QList<QVariant> aMarkerTypeIndicesList;
3862   QList<QVariant> aMarkerTypeIconsList;
3863   for ( int i = VTK::MT_POINT; i < VTK::MT_USER; i++ ) {
3864     QString icoFile = QString( "ICON_VERTEX_MARKER_%1" ).arg( i );
3865     QPixmap pixmap = aResourceMgr->loadPixmap( "VTKViewer", tr( qPrintable( icoFile ) ) );
3866     aMarkerTypeIndicesList << i;
3867     aMarkerTypeIconsList << pixmap;
3868   }
3869   setPreferenceProperty( typeOfMarker, "indexes", aMarkerTypeIndicesList );
3870   setPreferenceProperty( typeOfMarker, "icons",   aMarkerTypeIconsList );
3871
3872   int markerScale = addPreference( tr( "PREF_MARKER_SCALE" ), nodeGroup, LightApp_Preferences::Selector, "SMESH", "marker_scale" );
3873
3874   QList<QVariant> aMarkerScaleIndicesList;
3875   QStringList     aMarkerScaleValuesList;
3876   for ( int i = VTK::MS_10; i <= VTK::MS_70; i++ ) {
3877     aMarkerScaleIndicesList << i;
3878     aMarkerScaleValuesList  << QString::number( (i-(int)VTK::MS_10)*0.5 + 1.0 );
3879   }
3880   setPreferenceProperty( markerScale, "strings", aMarkerScaleValuesList );
3881   setPreferenceProperty( markerScale, "indexes", aMarkerScaleIndicesList );
3882
3883   int elemGroup = addPreference( tr( "PREF_GROUP_ELEMENTS" ), meshTab );
3884   setPreferenceProperty( elemGroup, "columns", 2 );
3885
3886   addPreference( tr( "PREF_FILL"     ), elemGroup, LightApp_Preferences::Color, "SMESH", "fill_color" );
3887   addPreference( tr( "PREF_OUTLINE"  ), elemGroup, LightApp_Preferences::Color, "SMESH", "outline_color" );
3888   addPreference( tr( "PREF_BACKFACE" ), elemGroup, LightApp_Preferences::Color, "SMESH", "backface_color" );
3889   addPreference( tr( "PREF_COLOR_0D" ), elemGroup, LightApp_Preferences::Color, "SMESH", "elem0d_color" );
3890
3891   //int sp = addPreference( "", elemGroup, LightApp_Preferences::Space );
3892   //setPreferenceProperty( sp, "hstretch", 0 );
3893   //setPreferenceProperty( sp, "vstretch", 0 );
3894
3895   int size0d = addPreference(tr("PREF_SIZE_0D"), elemGroup,
3896                              LightApp_Preferences::IntSpin, "SMESH", "elem0d_size");
3897   int sp = addPreference( "", elemGroup, LightApp_Preferences::Space );
3898   int elemW  = addPreference(tr("PREF_WIDTH"), elemGroup,
3899                              LightApp_Preferences::IntSpin, "SMESH", "element_width");
3900   int shrink = addPreference(tr("PREF_SHRINK_COEFF"), elemGroup,
3901                              LightApp_Preferences::IntSpin, "SMESH", "shrink_coeff");
3902
3903   setPreferenceProperty( size0d, "min", 1 );
3904   setPreferenceProperty( size0d, "max", 10 );
3905
3906   setPreferenceProperty( sp, "hstretch", 0 );
3907   setPreferenceProperty( sp, "vstretch", 0 );
3908
3909   setPreferenceProperty( elemW, "min", 1 );
3910   setPreferenceProperty( elemW, "max", 5 );
3911
3912   setPreferenceProperty( shrink, "min", 0 );
3913   setPreferenceProperty( shrink, "max", 100 );
3914
3915   int orientGroup = addPreference( tr( "PREF_GROUP_FACES_ORIENTATION" ), meshTab );
3916   setPreferenceProperty( orientGroup, "columns", 1 );
3917
3918   addPreference( tr( "PREF_ORIENTATION_COLOR" ), orientGroup, LightApp_Preferences::Color, "SMESH", "orientation_color" );
3919   int orientScale = addPreference( tr( "PREF_ORIENTATION_SCALE" ), orientGroup, LightApp_Preferences::DblSpin, "SMESH", "orientation_scale" );
3920
3921   setPreferenceProperty( orientScale, "min", 0.05 );
3922   setPreferenceProperty( orientScale, "max", 0.5 );
3923   setPreferenceProperty( orientScale, "step", 0.05 );
3924
3925   addPreference( tr( "PREF_ORIENTATION_3D_VECTORS" ), orientGroup, LightApp_Preferences::Bool, "SMESH", "orientation_3d_vectors" );
3926
3927   // Selection tab ------------------------------------------------------------------------
3928   int selTab = addPreference( tr( "PREF_TAB_SELECTION" ) );
3929
3930   int selGroup = addPreference( tr( "PREF_GROUP_SELECTION" ), selTab );
3931   setPreferenceProperty( selGroup, "columns", 2 );
3932
3933   addPreference( tr( "PREF_OBJECT_COLOR" ), selGroup, LightApp_Preferences::Color, "SMESH", "selection_object_color" );
3934   addPreference( tr( "PREF_ELEMENT_COLOR" ), selGroup, LightApp_Preferences::Color, "SMESH", "selection_element_color" );
3935   int selW = addPreference( tr( "PREF_WIDTH" ), selGroup, LightApp_Preferences::IntSpin, "SMESH", "selection_width" );
3936
3937   setPreferenceProperty( selW, "min", 1 );
3938   setPreferenceProperty( selW, "max", 5 );
3939
3940   int preGroup = addPreference( tr( "PREF_GROUP_PRESELECTION" ), selTab );
3941   setPreferenceProperty( preGroup, "columns", 2 );
3942
3943   addPreference( tr( "PREF_HIGHLIGHT_COLOR" ), preGroup, LightApp_Preferences::Color, "SMESH", "highlight_color" );
3944   int preW = addPreference( tr( "PREF_WIDTH" ), preGroup, LightApp_Preferences::IntSpin, "SMESH", "highlight_width" );
3945
3946   setPreferenceProperty( preW, "min", 1 );
3947   setPreferenceProperty( preW, "max", 5 );
3948
3949   int precSelGroup = addPreference( tr( "PREF_GROUP_PRECISION" ), selTab );
3950   setPreferenceProperty( precSelGroup, "columns", 2 );
3951
3952   addPreference( tr( "PREF_NODES" ), precSelGroup, LightApp_Preferences::Double, "SMESH", "selection_precision_node" );
3953   addPreference( tr( "PREF_ELEMENTS" ), precSelGroup, LightApp_Preferences::Double, "SMESH", "selection_precision_element" );
3954   addPreference( tr( "PREF_OBJECTS" ), precSelGroup, LightApp_Preferences::Double, "SMESH", "selection_precision_object" );
3955
3956   // Scalar Bar tab ------------------------------------------------------------------------
3957   int sbarTab = addPreference( tr( "SMESH_SCALARBAR" ) );
3958   int fontGr = addPreference( tr( "SMESH_FONT_SCALARBAR" ), sbarTab );
3959   setPreferenceProperty( fontGr, "columns", 2 );
3960
3961   addVtkFontPref( tr( "SMESH_TITLE" ), fontGr, "scalar_bar_title_font" );
3962   addPreference( tr( "PREF_TITLE_COLOR" ), fontGr, LightApp_Preferences::Color, "SMESH", "scalar_bar_title_color" );
3963
3964   addVtkFontPref( tr( "SMESH_LABELS" ), fontGr, "scalar_bar_label_font" );
3965   addPreference( tr( "PREF_LABELS_COLOR" ), fontGr, LightApp_Preferences::Color, "SMESH", "scalar_bar_label_color" );
3966
3967   int colorsLabelsGr = addPreference( tr( "SMESH_LABELS_COLORS_SCALARBAR" ), sbarTab );
3968   setPreferenceProperty( colorsLabelsGr, "columns", 2 );
3969
3970   int numcol = addPreference( tr( "SMESH_NUMBEROFCOLORS" ), colorsLabelsGr, LightApp_Preferences::IntSpin, "SMESH", "scalar_bar_num_colors" );
3971   setPreferenceProperty( numcol, "min", 2 );
3972   setPreferenceProperty( numcol, "max", 256 );
3973
3974   int numlab = addPreference( tr( "SMESH_NUMBEROFLABELS" ), colorsLabelsGr, LightApp_Preferences::IntSpin, "SMESH", "scalar_bar_num_labels" );
3975   setPreferenceProperty( numlab, "min", 2 );
3976   setPreferenceProperty( numlab, "max", 65 );
3977
3978   int orientGr = addPreference( tr( "SMESH_ORIENTATION" ), sbarTab );
3979   setPreferenceProperty( orientGr, "columns", 2 );
3980   int orient = addPreference( tr( "SMESH_ORIENTATION" ), orientGr, LightApp_Preferences::Selector, "SMESH", "scalar_bar_orientation" );
3981   QStringList orients;
3982   orients.append( tr( "SMESH_VERTICAL" ) );
3983   orients.append( tr( "SMESH_HORIZONTAL" ) );
3984   indices.clear(); indices.append( 0 ); indices.append( 1 );
3985   setPreferenceProperty( orient, "strings", orients );
3986   setPreferenceProperty( orient, "indexes", indices );
3987
3988   int posVSizeGr = addPreference( tr( "SMESH_POSITION_SIZE_SCALARBAR" ) + " " + tr( "SMESH_VERTICAL" ), sbarTab );
3989   setPreferenceProperty( posVSizeGr, "columns", 2 );
3990   int xv = addPreference( tr( "SMESH_X_SCALARBAR" ), posVSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_vertical_x" );
3991   int yv = addPreference( tr( "SMESH_Y_SCALARBAR" ), posVSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_vertical_y" );
3992   int wv = addPreference( tr( "SMESH_WIDTH" ), posVSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_vertical_width" );
3993   int hv = addPreference( tr( "SMESH_HEIGHT" ), posVSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_vertical_height" );
3994   setPreferenceProperty( xv, "step", 0.1 );
3995   setPreferenceProperty( xv, "min", 0.0 );
3996   setPreferenceProperty( xv, "max", 1.0 );
3997   setPreferenceProperty( yv, "step", 0.1 );
3998   setPreferenceProperty( yv, "min", 0.0 );
3999   setPreferenceProperty( yv, "max", 1.0 );
4000   setPreferenceProperty( wv, "step", 0.1 );
4001   setPreferenceProperty( wv, "min", 0.0 );
4002   setPreferenceProperty( wv, "max", 1.0 );
4003   setPreferenceProperty( hv, "min", 0.0 );
4004   setPreferenceProperty( hv, "max", 1.0 );
4005   setPreferenceProperty( hv, "step", 0.1 );
4006
4007   int posHSizeGr = addPreference( tr( "SMESH_POSITION_SIZE_SCALARBAR" ) + " " + tr( "SMESH_HORIZONTAL" ), sbarTab );
4008   setPreferenceProperty( posHSizeGr, "columns", 2 );
4009   int xh = addPreference( tr( "SMESH_X_SCALARBAR" ), posHSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_horizontal_x" );
4010   int yh = addPreference( tr( "SMESH_Y_SCALARBAR" ), posHSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_horizontal_y" );
4011   int wh = addPreference( tr( "SMESH_WIDTH" ), posHSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_horizontal_width" );
4012   int hh = addPreference( tr( "SMESH_HEIGHT" ), posHSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_horizontal_height" );
4013   setPreferenceProperty( xv, "min", 0.0 );
4014   setPreferenceProperty( xv, "max", 1.0 );
4015   setPreferenceProperty( xv, "step", 0.1 );
4016   setPreferenceProperty( xh, "min", 0.0 );
4017   setPreferenceProperty( xh, "max", 1.0 );
4018   setPreferenceProperty( xh, "step", 0.1 );
4019   setPreferenceProperty( yh, "min", 0.0 );
4020   setPreferenceProperty( yh, "max", 1.0 );
4021   setPreferenceProperty( yh, "step", 0.1 );
4022   setPreferenceProperty( wh, "min", 0.0 );
4023   setPreferenceProperty( wh, "max", 1.0 );
4024   setPreferenceProperty( wh, "step", 0.1 );
4025   setPreferenceProperty( hh, "min", 0.0 );
4026   setPreferenceProperty( hh, "max", 1.0 );
4027   setPreferenceProperty( hh, "step", 0.1 );
4028 }
4029
4030 void SMESHGUI::preferencesChanged( const QString& sect, const QString& name )
4031 {
4032   if( sect=="SMESH" ) {
4033     float sbX1,sbY1,sbW,sbH;
4034     float aTol = 1.00000009999999;
4035     std::string aWarning;
4036     SUIT_ResourceMgr* aResourceMgr = SMESH::GetResourceMgr(this);
4037     if( name=="selection_object_color" || name=="selection_element_color" ||
4038         name=="selection_width" || name=="highlight_color" || name=="highlight_width" ||
4039         name=="selection_precision_node" || name=="selection_precision_element" ||
4040         name=="selection_precision_object")
4041       SMESH::UpdateSelectionProp( this );
4042     else if (name == QString("scalar_bar_vertical_x") || name == QString("scalar_bar_vertical_width")){
4043       sbX1 = aResourceMgr->doubleValue("SMESH", "scalar_bar_vertical_x", sbX1);
4044       sbW = aResourceMgr->doubleValue("SMESH", "scalar_bar_vertical_width", sbW);
4045       if(sbX1+sbW > aTol){
4046         aWarning = "Origin and Size Vertical: X+Width > 1\n";
4047         sbX1=0.01;
4048         sbW=0.08;
4049         aResourceMgr->setValue("SMESH", "scalar_bar_vertical_x", sbX1);
4050         aResourceMgr->setValue("SMESH", "scalar_bar_vertical_width", sbW);
4051       }
4052     }
4053     else if(name == QString("scalar_bar_vertical_y") || name == QString("scalar_bar_vertical_height")){
4054       sbY1 = aResourceMgr->doubleValue("SMESH", "scalar_bar_vertical_y", sbY1);
4055       sbH = aResourceMgr->doubleValue("SMESH", "scalar_bar_vertical_height",sbH);
4056       if(sbY1+sbH > aTol){
4057         aWarning = "Origin and Size Vertical: Y+Height > 1\n";
4058         aResourceMgr->setValue("SMESH", "scalar_bar_vertical_y", sbY1);
4059         aResourceMgr->setValue("SMESH", "scalar_bar_vertical_height",sbH);
4060       }
4061     }
4062     else if(name ==  QString("scalar_bar_horizontal_x") || name ==  QString("scalar_bar_horizontal_width")){
4063       sbX1 = aResourceMgr->doubleValue("SMESH", "scalar_bar_horizontal_x", sbX1);
4064       sbW = aResourceMgr->doubleValue("SMESH", "scalar_bar_horizontal_width", sbW);
4065       if(sbX1+sbW > aTol){
4066         aWarning = "Origin and Size Horizontal: X+Width > 1\n";
4067         sbX1=0.1;
4068         sbW=0.08;
4069         aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_x", sbX1);
4070         aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_width", sbW);
4071       }
4072     }
4073     else if(name ==  QString("scalar_bar_horizontal_y") || name ==  QString("scalar_bar_horizontal_height")){
4074       sbY1 = aResourceMgr->doubleValue("SMESH", "scalar_bar_horizontal_y", sbY1);
4075       sbH = aResourceMgr->doubleValue("SMESH", "scalar_bar_horizontal_height",sbH);
4076       if(sbY1+sbH > aTol){
4077         aWarning = "Origin and Size Horizontal: Y+Height > 1\n";
4078         sbY1=0.01;
4079         sbH=0.08;
4080         aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_y", sbY1);
4081         aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_height",sbH);
4082       }
4083     }
4084     else if ( name == "segmentation" ) {
4085       int nbSeg = aResourceMgr->integerValue( "SMESH", "segmentation", 10 );
4086       myComponentSMESH->SetBoundaryBoxSegmentation( nbSeg );
4087     }
4088     else if ( name == "nb_segments_per_edge" ) {
4089       int nbSeg = aResourceMgr->integerValue( "SMESH", "nb_segments_per_edge", 15 );
4090       myComponentSMESH->SetDefaultNbSegments( nbSeg );
4091     }
4092
4093     if(aWarning.size() != 0){
4094       aWarning += "The default values are applied instead.";
4095       SUIT_MessageBox::warning(SMESHGUI::desktop(),
4096                                QObject::tr("SMESH_ERR_SCALARBAR_PARAMS"),
4097                                QObject::tr(aWarning.c_str()));
4098     }
4099   }
4100 }
4101
4102 //================================================================================
4103 /*!
4104  * \brief Update something in accordance with update flags
4105   * \param theFlags - update flags
4106 *
4107 * Update viewer or/and object browser etc. in accordance with update flags ( see
4108 * LightApp_UpdateFlags enumeration ).
4109 */
4110 //================================================================================
4111 void SMESHGUI::update( const int flags )
4112 {
4113   if ( flags & UF_Viewer | flags & UF_Forced )
4114     SMESH::UpdateView();
4115   else
4116     SalomeApp_Module::update( flags );
4117 }
4118
4119 //================================================================================
4120 /*!
4121  * \brief Set default selection mode
4122 *
4123 * SLOT called when operation commited. Sets default selection mode
4124 */
4125 //================================================================================
4126 void SMESHGUI::onOperationCommited( SUIT_Operation* )
4127 {
4128   SVTK_ViewWindow* vtkWnd =
4129     dynamic_cast<SVTK_ViewWindow*>( application()->desktop()->activeWindow() );
4130   if ( vtkWnd )
4131     vtkWnd->SetSelectionMode( ActorSelection );
4132 }
4133
4134 //================================================================================
4135 /*!
4136  * \brief Set default selection mode
4137 *
4138 * SLOT called when operation aborted. Sets default selection mode
4139 */
4140 //================================================================================
4141 void SMESHGUI::onOperationAborted( SUIT_Operation* )
4142 {
4143   SVTK_ViewWindow* vtkWnd =
4144     dynamic_cast<SVTK_ViewWindow*>( application()->desktop()->activeWindow() );
4145   if ( vtkWnd )
4146     vtkWnd->SetSelectionMode( ActorSelection );
4147 }
4148
4149 //================================================================================
4150 /*!
4151  * \brief Creates operation with given identifier
4152   * \param id - identifier of operation to be started
4153   * \return Pointer on created operation or NULL if operation is not created
4154 *
4155 * Virtual method redefined from the base class creates operation with given id.
4156 * It is called called automatically from startOperation method of base class.
4157 */
4158 //================================================================================
4159 LightApp_Operation* SMESHGUI::createOperation( const int id ) const
4160 {
4161   LightApp_Operation* op = 0;
4162   // to do : create operation here
4163   switch( id )
4164   {
4165     case 417: //convert to quadratic
4166       op = new SMESHGUI_ConvToQuadOp();
4167     break;
4168     case 418: // create 2D mesh as boundary on 3D
4169       op = new SMESHGUI_Make2DFrom3DOp();
4170     break;
4171     case 701: // Compute mesh
4172       op = new SMESHGUI_ComputeOp();
4173     break;
4174     case 702: // Create mesh
4175       op = new SMESHGUI_MeshOp( true, true );
4176     break;
4177     case 703: // Create sub-mesh
4178       op = new SMESHGUI_MeshOp( true, false );
4179     break;
4180     case 704: // Edit mesh/sub-mesh
4181       op = new SMESHGUI_MeshOp( false );
4182     break;
4183     case 711: // Precompute mesh
4184       op = new SMESHGUI_PrecomputeOp();
4185     break;
4186     case 712: // Evaluate mesh
4187       op = new SMESHGUI_EvaluateOp();
4188     break;
4189     case 713: // Evaluate mesh
4190       op = new SMESHGUI_MeshOrderOp();
4191     break;
4192     case 806: // Create group on geom
4193       op = new SMESHGUI_GroupOnShapeOp();
4194       break;
4195     case 904: // Find element
4196       op = new SMESHGUI_FindElemByPointOp();
4197       break;
4198     case 4067: // make mesh pass through point
4199       op = new SMESHGUI_MakeNodeAtPointOp();
4200       break;
4201     default:
4202     break;
4203   }
4204
4205   if( !op )
4206     op = SalomeApp_Module::createOperation( id );
4207   return op;
4208 }
4209
4210 //================================================================================
4211 /*!
4212  * \brief Stops current operations and starts a given one
4213   * \param id - The id of the operation to start
4214  */
4215 //================================================================================
4216
4217 void SMESHGUI::switchToOperation(int id)
4218 {
4219   if ( _PTR(Study) aStudy = SMESH::GetActiveStudyDocument() )
4220     activeStudy()->abortAllOperations();
4221   startOperation( id );
4222 }
4223
4224 LightApp_Displayer* SMESHGUI::displayer()
4225 {
4226   if( !myDisplayer )
4227     myDisplayer = new SMESHGUI_Displayer( getApp() );
4228   return myDisplayer;
4229 }
4230
4231 SALOMEDS::Color SMESHGUI::getUniqueColor( const QList<SALOMEDS::Color>& theReservedColors )
4232 {
4233   int aHue = -1;
4234   int aTolerance = 64;
4235   int anIterations = 0;
4236   int aPeriod = 5;
4237
4238   while( 1 )
4239   {
4240     anIterations++;
4241     if( anIterations % aPeriod == 0 )
4242     {
4243       aTolerance /= 2;
4244       if( aTolerance < 1 )
4245         break;
4246     }
4247     //cout << "Iteration N" << anIterations << " (tolerance=" << aTolerance << ")"<< endl;
4248
4249     aHue = (int)( 360.0 * rand() / RAND_MAX );
4250     //cout << "Hue = " << aHue << endl;
4251
4252     //cout << "Auto colors : ";
4253     bool ok = true;
4254     QList<SALOMEDS::Color>::const_iterator it = theReservedColors.constBegin();
4255     QList<SALOMEDS::Color>::const_iterator itEnd = theReservedColors.constEnd();
4256     for( ; it != itEnd; ++it )
4257     {
4258       SALOMEDS::Color anAutoColor = *it;
4259       QColor aQColor( (int)( anAutoColor.R * 255.0 ), (int)( anAutoColor.G * 255.0 ), (int)( anAutoColor.B * 255.0 ) );
4260
4261       int h, s, v;
4262       aQColor.getHsv( &h, &s, &v );
4263       //cout << h << " ";
4264       if( abs( h - aHue ) < aTolerance )
4265       {
4266         ok = false;
4267         //cout << "break (diff = " << abs( h - aHue ) << ")";
4268         break;
4269       }
4270     }
4271     //cout << endl;
4272
4273     if( ok )
4274       break;
4275   }
4276
4277   //cout << "Hue of the returned color = " << aHue << endl;
4278   QColor aColor;
4279   aColor.setHsv( aHue, 255, 255 );
4280
4281   SALOMEDS::Color aSColor;
4282   aSColor.R = (double)aColor.red() / 255.0;
4283   aSColor.G = (double)aColor.green() / 255.0;
4284   aSColor.B = (double)aColor.blue() / 255.0;
4285
4286   return aSColor;
4287 }
4288
4289 const char gSeparator = '_'; // character used to separate parameter names
4290 const char gDigitsSep = ':'; // character used to separate numeric parameter values (color = r:g:b)
4291 const char gPathSep   = '|'; // character used to separate paths
4292
4293 /*!
4294  * \brief Store visual parameters
4295  *
4296  * This method is called just before the study document is saved.
4297  * Store visual parameters in AttributeParameter attribue(s)
4298  */
4299 void SMESHGUI::storeVisualParameters (int savePoint)
4300 {
4301   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(application()->activeStudy());
4302   if (!appStudy || !appStudy->studyDS())
4303     return;
4304   _PTR(Study) studyDS = appStudy->studyDS();
4305
4306   // componentName is used for encoding of entries when storing them in IParameters
4307   std::string componentName = myComponentSMESH->ComponentDataType();
4308   //_PTR(SComponent) aSComponent = studyDS->FindComponent("SMESH");
4309   //if (!aSComponent) return;
4310
4311   // IParameters
4312   _PTR(AttributeParameter) ap = studyDS->GetModuleParameters("Interface Applicative",
4313                                                              componentName.c_str(),
4314                                                              savePoint);
4315   _PTR(IParameters) ip = ClientFactory::getIParameters(ap);
4316
4317   // store map of custom markers
4318   const VTK::MarkerMap& aMarkerMap = myMarkerMap[ studyDS->StudyId() ];
4319   if( !aMarkerMap.empty() )
4320   {
4321     VTK::MarkerMap::const_iterator anIter = aMarkerMap.begin();
4322     for( ; anIter != aMarkerMap.end(); anIter++ )
4323     {
4324       int anId = anIter->first;
4325       VTK::MarkerData aMarkerData = anIter->second;
4326       std::string aMarkerFileName = aMarkerData.first;
4327       VTK::MarkerTexture aMarkerTexture = aMarkerData.second;
4328       if( aMarkerTexture.size() < 3 )
4329         continue; // should contain at least width, height and the first value
4330
4331       QString aPropertyName( "texture" );
4332       aPropertyName += gSeparator;
4333       aPropertyName += QString::number( anId );
4334
4335       QString aPropertyValue = aMarkerFileName.c_str();
4336       aPropertyValue += gPathSep;
4337
4338       VTK::MarkerTexture::const_iterator aTextureIter = aMarkerTexture.begin();
4339       ushort aWidth = *aTextureIter++;
4340       ushort aHeight = *aTextureIter++;
4341       aPropertyValue += QString::number( aWidth ); aPropertyValue += gDigitsSep;
4342       aPropertyValue += QString::number( aHeight ); aPropertyValue += gDigitsSep;
4343       for( ; aTextureIter != aMarkerTexture.end(); aTextureIter++ )
4344         aPropertyValue += QString::number( *aTextureIter );
4345
4346       ip->setProperty( aPropertyName.toStdString(), aPropertyValue.toStdString() );
4347     }
4348   }
4349
4350   // viewers counters are used for storing view_numbers in IParameters
4351   int vtkViewers = 0;
4352
4353   // main cycle to store parameters of displayed objects
4354   QList<SUIT_ViewManager*> lst;
4355   QList<SUIT_ViewManager*>::Iterator it;
4356   getApp()->viewManagers(lst);
4357   for (it = lst.begin(); it != lst.end(); it++)
4358   {
4359     SUIT_ViewManager* vman = *it;
4360     QString vType = vman->getType();
4361
4362     // saving VTK actors properties
4363     if (vType == SVTK_Viewer::Type())
4364     {
4365       QVector<SUIT_ViewWindow*> views = vman->getViews();
4366       for (int i = 0, iEnd = vman->getViewsCount(); i < iEnd; i++)
4367       {
4368         if (SVTK_ViewWindow* vtkView = dynamic_cast<SVTK_ViewWindow*>(views[i]))
4369         {
4370           VTK::ActorCollectionCopy aCopy(vtkView->getRenderer()->GetActors());
4371           vtkActorCollection* allActors = aCopy.GetActors();
4372           allActors->InitTraversal();
4373           while (vtkActor* actor = allActors->GetNextActor())
4374           {
4375             if (actor->GetVisibility()) // store only visible actors
4376             {
4377               SMESH_Actor* aSmeshActor = 0;
4378               if (actor->IsA("SMESH_Actor"))
4379                 aSmeshActor = SMESH_Actor::SafeDownCast(actor);
4380               if (aSmeshActor && aSmeshActor->hasIO())
4381               {
4382                 Handle(SALOME_InteractiveObject) io = aSmeshActor->getIO();
4383                 if (io->hasEntry())
4384                 {
4385                   // entry is "encoded" = it does NOT contain component adress,
4386                   // since it is a subject to change on next component loading
4387                   std::string entry = ip->encodeEntry(io->getEntry(), componentName);
4388
4389                   std::string param, vtkParam = vType.toLatin1().data();
4390                   vtkParam += gSeparator;
4391                   vtkParam += QString::number(vtkViewers).toLatin1().data();
4392                   vtkParam += gSeparator;
4393
4394                   // Visibility
4395                   param = vtkParam + "Visibility";
4396                   ip->setParameter(entry, param, "On");
4397
4398                   // Representation
4399                   param = vtkParam + "Representation";
4400                   ip->setParameter(entry, param, QString::number
4401                                    ((int)aSmeshActor->GetRepresentation()).toLatin1().data());
4402
4403                   // IsShrunk
4404                   param = vtkParam + "IsShrunk";
4405                   ip->setParameter(entry, param, QString::number
4406                                    ((int)aSmeshActor->IsShrunk()).toLatin1().data());
4407
4408                   // Displayed entities
4409                   unsigned int aMode = aSmeshActor->GetEntityMode();
4410                   bool isE = aMode & SMESH_Actor::eEdges;
4411                   bool isF = aMode & SMESH_Actor::eFaces;
4412                   bool isV = aMode & SMESH_Actor::eVolumes;
4413
4414                   QString modeStr ("e");
4415                   modeStr += gDigitsSep; modeStr += QString::number(isE);
4416                   modeStr += gDigitsSep; modeStr += "f";
4417                   modeStr += gDigitsSep; modeStr += QString::number(isF);
4418                   modeStr += gDigitsSep; modeStr += "v";
4419                   modeStr += gDigitsSep; modeStr += QString::number(isV);
4420
4421                   param = vtkParam + "Entities";
4422                   ip->setParameter(entry, param, modeStr.toLatin1().data());
4423
4424                   // Colors (surface:edge:)
4425                   vtkFloatingPointType r, g, b;
4426
4427                   aSmeshActor->GetSufaceColor(r, g, b);
4428                   QString colorStr ("surface");
4429                   colorStr += gDigitsSep; colorStr += QString::number(r);
4430                   colorStr += gDigitsSep; colorStr += QString::number(g);
4431                   colorStr += gDigitsSep; colorStr += QString::number(b);
4432
4433                   aSmeshActor->GetBackSufaceColor(r, g, b);
4434                   colorStr += gDigitsSep; colorStr += "backsurface";
4435                   colorStr += gDigitsSep; colorStr += QString::number(r);
4436                   colorStr += gDigitsSep; colorStr += QString::number(g);
4437                   colorStr += gDigitsSep; colorStr += QString::number(b);
4438
4439                   aSmeshActor->GetEdgeColor(r, g, b);
4440                   colorStr += gDigitsSep; colorStr += "edge";
4441                   colorStr += gDigitsSep; colorStr += QString::number(r);
4442                   colorStr += gDigitsSep; colorStr += QString::number(g);
4443                   colorStr += gDigitsSep; colorStr += QString::number(b);
4444
4445                   aSmeshActor->GetNodeColor(r, g, b);
4446                   colorStr += gDigitsSep; colorStr += "node";
4447                   colorStr += gDigitsSep; colorStr += QString::number(r);
4448                   colorStr += gDigitsSep; colorStr += QString::number(g);
4449                   colorStr += gDigitsSep; colorStr += QString::number(b);
4450
4451                   param = vtkParam + "Colors";
4452                   ip->setParameter(entry, param, colorStr.toLatin1().data());
4453
4454                   // Sizes of lines and points
4455                   QString sizeStr ("line");
4456                   sizeStr += gDigitsSep; sizeStr += QString::number((int)aSmeshActor->GetLineWidth());
4457                   sizeStr += gDigitsSep; sizeStr += "shrink";
4458                   sizeStr += gDigitsSep; sizeStr += QString::number(aSmeshActor->GetShrinkFactor());
4459
4460                   param = vtkParam + "Sizes";
4461                   ip->setParameter(entry, param, sizeStr.toLatin1().data());
4462
4463                   // Point marker
4464                   QString markerStr;
4465
4466                   VTK::MarkerType aMarkerType = aSmeshActor->GetMarkerType();
4467                   if( aMarkerType == VTK::MT_USER ) {
4468                     markerStr += "custom";
4469                     markerStr += gDigitsSep;
4470                     markerStr += QString::number( aSmeshActor->GetMarkerTexture() );
4471                   }
4472                   else {
4473                     markerStr += "std";
4474                     markerStr += gDigitsSep;
4475                     markerStr += QString::number( (int)aMarkerType );
4476                     markerStr += gDigitsSep;
4477                     markerStr += QString::number( (int)aSmeshActor->GetMarkerScale() );
4478                   }
4479
4480                   param = vtkParam + "PointMarker";
4481                   ip->setParameter(entry, param, markerStr.toLatin1().data());
4482
4483                   // Opacity
4484                   param = vtkParam + "Opacity";
4485                   ip->setParameter(entry, param,
4486                                    QString::number(aSmeshActor->GetOpacity()).toLatin1().data());
4487
4488                   // Clipping
4489                   param = vtkParam + "ClippingPlane";
4490                   int nPlanes = aSmeshActor->GetNumberOfClippingPlanes();
4491                   if (!nPlanes)
4492                     ip->setParameter(entry, param, "Off");
4493                   for (int ipl = 0; ipl < nPlanes; ipl++) {
4494                     //vtkPlane* plane = aSmeshActor->GetClippingPlane(ipl);
4495                     SMESH::Orientation anOrientation;
4496                     double aDistance;
4497                     vtkFloatingPointType anAngle[2];
4498                     SMESHGUI_ClippingDlg::GetPlaneParam(aSmeshActor, ipl, anOrientation, aDistance, anAngle);
4499                     std::string planeValue = QString::number((int)anOrientation).toLatin1().data();
4500                     planeValue += gDigitsSep; planeValue += QString::number(aDistance).toLatin1().data();
4501                     planeValue += gDigitsSep; planeValue += QString::number(anAngle[0]).toLatin1().data();
4502                     planeValue += gDigitsSep; planeValue += QString::number(anAngle[1]).toLatin1().data();
4503
4504                     ip->setParameter(entry, param + QString::number(ipl+1).toLatin1().data(), planeValue);
4505                   }
4506                 } // if (io->hasEntry())
4507               } // SMESH_Actor && hasIO
4508             } // isVisible
4509           } // while.. actors traversal
4510         } // if (vtkView)
4511       } // for (views)
4512       vtkViewers++;
4513     } // if (SVTK view model)
4514   } // for (viewManagers)
4515 }
4516
4517 /*!
4518  * \brief Restore visual parameters
4519  *
4520  * This method is called after the study document is opened.
4521  * Restore visual parameters from AttributeParameter attribue(s)
4522  */
4523 void SMESHGUI::restoreVisualParameters (int savePoint)
4524 {
4525   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(application()->activeStudy());
4526   if (!appStudy || !appStudy->studyDS())
4527     return;
4528   _PTR(Study) studyDS = appStudy->studyDS();
4529
4530   // componentName is used for encoding of entries when storing them in IParameters
4531   std::string componentName = myComponentSMESH->ComponentDataType();
4532   //_PTR(SComponent) aSComponent = studyDS->FindComponent("GEOM");
4533   //if (!aSComponent) return;
4534
4535   // IParameters
4536   _PTR(AttributeParameter) ap = studyDS->GetModuleParameters("Interface Applicative",
4537                                                              componentName.c_str(),
4538                                                              savePoint);
4539   _PTR(IParameters) ip = ClientFactory::getIParameters(ap);
4540
4541   // restore map of custom markers
4542   VTK::MarkerMap& aMarkerMap = myMarkerMap[ studyDS->StudyId() ];
4543
4544   std::vector<std::string> properties = ip->getProperties();
4545   for (std::vector<std::string>::iterator propIt = properties.begin(); propIt != properties.end(); ++propIt)
4546   {
4547     std::string property = *propIt;
4548     QString aPropertyName( property.c_str() );
4549     QString aPropertyValue( ip->getProperty( property ).c_str() );
4550
4551     QStringList aPropertyNameList = aPropertyName.split( gSeparator, QString::SkipEmptyParts );
4552     if( aPropertyNameList.size() != 2 )
4553       continue;
4554
4555     int anId = 0;
4556     bool ok = false;
4557     if( aPropertyNameList[0] == "texture" )
4558       anId = aPropertyNameList[1].toInt( &ok );
4559
4560     if( !ok || anId < 1 )
4561       continue;
4562
4563     QStringList aPropertyValueList = aPropertyValue.split( gPathSep, QString::SkipEmptyParts );
4564     if( aPropertyValueList.size() != 2 )
4565       continue;
4566
4567     std::string aMarkerFileName = aPropertyValueList[0].toStdString();
4568     QString aMarkerTextureString = aPropertyValueList[1];
4569     QStringList aMarkerTextureStringList = aMarkerTextureString.split( gDigitsSep, QString::SkipEmptyParts );
4570     if( aMarkerTextureStringList.size() != 3 )
4571       continue;
4572
4573     ok = false;
4574     ushort aWidth = aMarkerTextureStringList[0].toUShort( &ok );
4575     if( !ok )
4576       continue;
4577
4578     ok = false;
4579     ushort aHeight = aMarkerTextureStringList[1].toUShort( &ok );
4580     if( !ok )
4581       continue;
4582
4583     VTK::MarkerTexture aMarkerTexture;
4584     aMarkerTexture.push_back( aWidth );
4585     aMarkerTexture.push_back( aHeight );
4586
4587     QString aMarkerTextureData = aMarkerTextureStringList[2];
4588     for( int i = 0, n = aMarkerTextureData.length(); i < n; i++ )
4589     {
4590       QChar aChar = aMarkerTextureData.at( i );
4591       if( aChar.isDigit() )
4592         aMarkerTexture.push_back( aChar.digitValue() );
4593     }
4594
4595     aMarkerMap[ anId ] = VTK::MarkerData( aMarkerFileName, aMarkerTexture );
4596   }
4597
4598   std::vector<std::string> entries = ip->getEntries();
4599
4600   for (std::vector<std::string>::iterator entIt = entries.begin(); entIt != entries.end(); ++entIt)
4601   {
4602     // entry is a normal entry - it should be "decoded" (setting base adress of component)
4603     QString entry (ip->decodeEntry(*entIt).c_str());
4604
4605     // Check that the entry corresponds to a real object in the Study
4606     // as the object may be deleted or modified after the visual state is saved.
4607     _PTR(SObject) so = studyDS->FindObjectID(entry.toLatin1().data());
4608     if (!so) continue; //Skip the not existent entry
4609
4610     std::vector<std::string> paramNames = ip->getAllParameterNames( *entIt );
4611     std::vector<std::string> paramValues = ip->getAllParameterValues( *entIt );
4612
4613     std::vector<std::string>::iterator namesIt = paramNames.begin();
4614     std::vector<std::string>::iterator valuesIt = paramValues.begin();
4615
4616     // actors are stored in a map after displaying of them for
4617     // quicker access in the future: map < viewID to actor >
4618     NCollection_DataMap<int, SMESH_Actor*> vtkActors;
4619
4620     for (; namesIt != paramNames.end(); ++namesIt, ++valuesIt)
4621     {
4622       // visual parameters are stored in strings as follows: ViewerType_ViewIndex_ParamName.
4623       // '_' is used as separator and should not be used in viewer type or parameter names.
4624       QStringList lst = QString((*namesIt).c_str()).split(gSeparator, QString::SkipEmptyParts);
4625       if (lst.size() != 3)
4626         continue;
4627
4628       QString viewerTypStr = lst[0];
4629       QString viewIndexStr = lst[1];
4630       QString paramNameStr = lst[2];
4631
4632       bool ok;
4633       int viewIndex = viewIndexStr.toUInt(&ok);
4634       if (!ok) // bad conversion of view index to integer
4635         continue;
4636
4637       // viewers
4638       if (viewerTypStr == SVTK_Viewer::Type())
4639       {
4640         SMESH_Actor* aSmeshActor = 0;
4641         if (vtkActors.IsBound(viewIndex))
4642           aSmeshActor = vtkActors.Find(viewIndex);
4643
4644         if (paramNameStr == "Visibility")
4645         {
4646           if (!aSmeshActor && displayer())
4647           {
4648             QList<SUIT_ViewManager*> lst;
4649             getApp()->viewManagers(viewerTypStr, lst);
4650
4651             // SVTK ViewManager always has 1 ViewWindow, so view index is index of view manager
4652             if (viewIndex >= 0 && viewIndex < lst.count()) {
4653               SUIT_ViewManager* vman = lst.at(viewIndex);
4654               SUIT_ViewModel* vmodel = vman->getViewModel();
4655               // SVTK view model can be casted to SALOME_View
4656               displayer()->Display(entry, true, dynamic_cast<SALOME_View*>(vmodel));
4657
4658               // store displayed actor in a temporary map for quicker
4659               // access later when restoring other parameters
4660               SVTK_ViewWindow* vtkView = (SVTK_ViewWindow*) vman->getActiveView();
4661               vtkRenderer* Renderer = vtkView->getRenderer();
4662               VTK::ActorCollectionCopy aCopy(Renderer->GetActors());
4663               vtkActorCollection* theActors = aCopy.GetActors();
4664               theActors->InitTraversal();
4665               bool isFound = false;
4666               vtkActor *ac = theActors->GetNextActor();
4667               for (; ac != NULL && !isFound; ac = theActors->GetNextActor()) {
4668                 if (ac->IsA("SMESH_Actor")) {
4669                   SMESH_Actor* aGeomAc = SMESH_Actor::SafeDownCast(ac);
4670                   if (aGeomAc->hasIO()) {
4671                     Handle(SALOME_InteractiveObject) io =
4672                       Handle(SALOME_InteractiveObject)::DownCast(aGeomAc->getIO());
4673                     if (io->hasEntry() && strcmp(io->getEntry(), entry.toLatin1().data()) == 0) {
4674                       isFound = true;
4675                       vtkActors.Bind(viewIndex, aGeomAc);
4676                     }
4677                   }
4678                 }
4679               }
4680             }
4681           }
4682         } // if (paramNameStr == "Visibility")
4683         else
4684         {
4685           // the rest properties "work" with SMESH_Actor
4686           if (aSmeshActor)
4687           {
4688             QString val ((*valuesIt).c_str());
4689
4690             // Representation
4691             if (paramNameStr == "Representation") {
4692               aSmeshActor->SetRepresentation((SMESH_Actor::EReperesent)val.toInt());
4693             }
4694             // IsShrunk
4695             else if (paramNameStr == "IsShrunk") {
4696               if (val.toInt()) {
4697                 if (!aSmeshActor->IsShrunk())
4698                   aSmeshActor->SetShrink();
4699               }
4700               else {
4701                 if (aSmeshActor->IsShrunk())
4702                   aSmeshActor->UnShrink();
4703               }
4704             }
4705             // Displayed entities
4706             else if (paramNameStr == "Entities") {
4707               QStringList mode = val.split(gDigitsSep, QString::SkipEmptyParts);
4708               if (mode.count() == 6) {
4709                 if (mode[0] != "e" || mode[2]  != "f" || mode[4] != "v") {
4710                   MESSAGE("Invalid order of data in Entities, must be: "
4711                           "e:0/1:f:0/1:v:0/1");
4712                 }
4713                 else {
4714                   unsigned int aMode = aSmeshActor->GetEntityMode();
4715                   unsigned int aNewMode =
4716                     (int(SMESH_Actor::eEdges  ) * mode[1].toInt()) |
4717                     (int(SMESH_Actor::eFaces  ) * mode[3].toInt()) |
4718                     (int(SMESH_Actor::eVolumes) * mode[5].toInt());
4719                   if (aNewMode != aMode)
4720                     aSmeshActor->SetEntityMode(aNewMode);
4721                 }
4722               }
4723             }
4724             // Colors
4725             else if (paramNameStr == "Colors") {
4726               QStringList colors = val.split(gDigitsSep, QString::SkipEmptyParts);
4727               if (colors.count() == 16) {
4728                 if (colors[0] != "surface" || colors[4]  != "backsurface" ||
4729                     colors[8] != "edge"    || colors[12] != "node") {
4730                   MESSAGE("Invalid order of data in Colors, must be: "
4731                           "surface:r:g:b:backsurface:r:g:b:edge:r:g:b:node:r:g:b");
4732                 }
4733                 else {
4734                   aSmeshActor->SetSufaceColor(colors[1].toFloat(), colors[2].toFloat(), colors[3].toFloat());
4735                   aSmeshActor->SetBackSufaceColor(colors[5].toFloat(), colors[6].toFloat(), colors[7].toFloat());
4736                   aSmeshActor->SetEdgeColor(colors[9].toFloat(), colors[10].toFloat(), colors[11].toFloat());
4737                   aSmeshActor->SetNodeColor(colors[13].toFloat(), colors[14].toFloat(), colors[15].toFloat());
4738                 }
4739               }
4740             }
4741             // Sizes of lines and points
4742             else if (paramNameStr == "Sizes") {
4743               QStringList sizes = val.split(gDigitsSep, QString::SkipEmptyParts);
4744               if (sizes.count() == 4) {
4745                 if (sizes[0] != "line" || sizes[2] != "shrink") {
4746                   MESSAGE("Invalid order of data in Sizes, must be: "
4747                           "line:int:shrink:float");
4748                 }
4749                 else {
4750                   aSmeshActor->SetLineWidth(sizes[1].toInt());
4751                   aSmeshActor->SetShrinkFactor(sizes[3].toFloat());
4752                 }
4753               }
4754               else if (sizes.count() == 6) { // just to support old format
4755                 if (sizes[0] != "line" || sizes[2]  != "node" || sizes[4] != "shrink") {
4756                   MESSAGE("Invalid order of data in Sizes, must be: "
4757                           "line:int:node:int:shrink:float");
4758                 }
4759                 else {
4760                   aSmeshActor->SetLineWidth(sizes[1].toInt());
4761                   //aSmeshActor->SetNodeSize(sizes[3].toInt()); // made obsolete
4762                   aSmeshActor->SetShrinkFactor(sizes[5].toFloat());
4763                 }
4764               }
4765             }
4766             // Point marker
4767             else if (paramNameStr == "PointMarker") {
4768               QStringList data = val.split(gDigitsSep, QString::SkipEmptyParts);
4769               if( data.count() >= 2 ) {
4770                 bool ok = false;
4771                 int aParam1 = data[1].toInt( &ok );
4772                 if( ok ) {
4773                   if( data[0] == "std" && data.count() == 3 ) {
4774                     int aParam2 = data[2].toInt( &ok );
4775                     aSmeshActor->SetMarkerStd( (VTK::MarkerType)aParam1, (VTK::MarkerScale)aParam2 );
4776                   }
4777                   else if( data[0] == "custom" ) {
4778                     VTK::MarkerMap::const_iterator markerIt = aMarkerMap.find( aParam1 );
4779                     if( markerIt != aMarkerMap.end() ) {
4780                       VTK::MarkerData aMarkerData = markerIt->second;
4781                       aSmeshActor->SetMarkerTexture( aParam1, aMarkerData.second );
4782                     }
4783                   }
4784                 }
4785               }
4786             }
4787             // Opacity
4788             else if (paramNameStr == "Opacity") {
4789               aSmeshActor->SetOpacity(val.toFloat());
4790             }
4791             // Clipping
4792             else if (paramNameStr.startsWith("ClippingPlane")) {
4793               cout << "$$$ ClippingPlane 1" << endl;
4794               if (paramNameStr == "ClippingPlane1" || val == "Off")
4795                 aSmeshActor->RemoveAllClippingPlanes();
4796               if (val != "Off") {
4797                 cout << "$$$ ClippingPlane 2" << endl;
4798                 QStringList vals = val.split(gDigitsSep, QString::SkipEmptyParts);
4799                 if (vals.count() == 4) { // format check: 4 values
4800                   cout << "$$$ ClippingPlane 3" << endl;
4801                   SMESH::Orientation anOrientation = (SMESH::Orientation)vals[0].toInt();
4802                   double aDistance = vals[1].toFloat();
4803                   vtkFloatingPointType anAngle[2];
4804                   anAngle[0] = vals[2].toFloat();
4805                   anAngle[1] = vals[3].toFloat();
4806
4807                   QList<SUIT_ViewManager*> lst;
4808                   getApp()->viewManagers(viewerTypStr, lst);
4809                   // SVTK ViewManager always has 1 ViewWindow, so view index is index of view manager
4810                   if (viewIndex >= 0 && viewIndex < lst.count()) {
4811                     SUIT_ViewManager* vman = lst.at(viewIndex);
4812                     SVTK_ViewWindow* vtkView = (SVTK_ViewWindow*) vman->getActiveView();
4813                     SMESHGUI_ClippingDlg::AddPlane(aSmeshActor, vtkView,
4814                                                    anOrientation, aDistance, anAngle);
4815                   }
4816                 }
4817               }
4818             }
4819           } // if (aSmeshActor)
4820         } // other parameters than Visibility
4821       }
4822     } // for names/parameters iterator
4823   } // for entries iterator
4824
4825   // update all VTK views
4826   QList<SUIT_ViewManager*> lst;
4827   getApp()->viewManagers(lst);
4828   for (QList<SUIT_ViewManager*>::Iterator it = lst.begin(); it != lst.end(); it++) {
4829     SUIT_ViewModel* vmodel = (*it)->getViewModel();
4830     if (vmodel && vmodel->getType() == SVTK_Viewer::Type()) {
4831       SVTK_ViewWindow* vtkView = (SVTK_ViewWindow*) (*it)->getActiveView();
4832       vtkView->getRenderer()->ResetCameraClippingRange();
4833       vtkView->Repaint();
4834     }
4835   }
4836 }
4837
4838 /*!
4839   \brief Adds preferences for dfont of VTK viewer
4840   \param label label
4841   \param pIf group identifier
4842   \param param parameter
4843   \return identifier of preferences
4844 */
4845 int SMESHGUI::addVtkFontPref( const QString& label, const int pId, const QString& param )
4846 {
4847   int tfont = addPreference( label, pId, LightApp_Preferences::Font, "VISU", param );
4848   
4849   setPreferenceProperty( tfont, "mode", QtxFontEdit::Custom );
4850
4851   QStringList fam;
4852   fam.append( tr( "SMESH_FONT_ARIAL" ) );
4853   fam.append( tr( "SMESH_FONT_COURIER" ) );
4854   fam.append( tr( "SMESH_FONT_TIMES" ) );
4855
4856   setPreferenceProperty( tfont, "fonts", fam );
4857
4858   int f = QtxFontEdit::Family | QtxFontEdit::Bold | QtxFontEdit::Italic | QtxFontEdit::Shadow;
4859   setPreferenceProperty( tfont, "features", f );
4860
4861   return tfont;
4862 }
4863
4864 /*!
4865   \brief Actions after hypothesis edition
4866   Updates object browser after hypothesis edition
4867 */
4868 void SMESHGUI::onHypothesisEdit( int result )
4869 {
4870   if( result == 1 )
4871     SMESHGUI::Modified();
4872   updateObjBrowser( true );
4873 }