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