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