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