Salome HOME
IPAL53091: 'Scale of Marker' lists are different in Preferences and Properties dialogs
[modules/smesh.git] / src / SMESHGUI / SMESHGUI.cxx
1 // Copyright (C) 2007-2016  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, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //  File   : SMESHGUI.cxx
23 //  Author : Nicolas REJNERI, Open CASCADE S.A.S.
24
25 #include <Standard_math.hxx>  // E.A. must be included before Python.h to fix compilation on windows
26 #ifdef HAVE_FINITE
27 #undef HAVE_FINITE            // VSR: avoid compilation warning on Linux : "HAVE_FINITE" redefined
28 #endif
29 #include "Python.h"
30
31 //  SMESH includes
32 #include "SMESHGUI.h"
33 #include "SMESHGUI_Add0DElemsOnAllNodesDlg.h"
34 #include "SMESHGUI_AddMeshElementDlg.h"
35 #include "SMESHGUI_AddQuadraticElementDlg.h"
36 #include "SMESHGUI_BuildCompoundDlg.h"
37 #include "SMESHGUI_ClippingDlg.h"
38 #include "SMESHGUI_ComputeDlg.h"
39 #include "SMESHGUI_ConvToQuadOp.h"
40 #include "SMESHGUI_CopyMeshDlg.h"
41 #include "SMESHGUI_CreatePolyhedralVolumeDlg.h"
42 #include "SMESHGUI_DeleteGroupDlg.h"
43 #include "SMESHGUI_Displayer.h"
44 #include "SMESHGUI_DuplicateNodesDlg.h"
45 #include "SMESHGUI_ExtrusionAlongPathDlg.h"
46 #include "SMESHGUI_ExtrusionDlg.h"
47 #include "SMESHGUI_FieldSelectorWdg.h"
48 #include "SMESHGUI_FileInfoDlg.h"
49 #include "SMESHGUI_FileValidator.h"
50 #include "SMESHGUI_FilterDlg.h"
51 #include "SMESHGUI_FilterLibraryDlg.h"
52 #include "SMESHGUI_FindElemByPointDlg.h"
53 #include "SMESHGUI_GroupDlg.h"
54 #include "SMESHGUI_GroupOnShapeDlg.h"
55 #include "SMESHGUI_GroupOpDlg.h"
56 #include "SMESHGUI_Hypotheses.h"
57 #include "SMESHGUI_Make2DFrom3DOp.h"
58 #include "SMESHGUI_MakeNodeAtPointDlg.h"
59 #include "SMESHGUI_Measurements.h"
60 #include "SMESHGUI_MergeDlg.h"
61 #include "SMESHGUI_MeshInfo.h"
62 #include "SMESHGUI_MeshOp.h"
63 #include "SMESHGUI_MeshOrderOp.h"
64 #include "SMESHGUI_MeshPatternDlg.h"
65 #include "SMESHGUI_MultiEditDlg.h"
66 #include "SMESHGUI_NodesDlg.h"
67 #include "SMESHGUI_Operations.h"
68 #include "SMESHGUI_Preferences_ScalarBarDlg.h"
69 #include "SMESHGUI_PropertiesDlg.h"
70 #include "SMESHGUI_RemoveElementsDlg.h"
71 #include "SMESHGUI_RemoveNodesDlg.h"
72 #include "SMESHGUI_RenumberingDlg.h"
73 #include "SMESHGUI_ReorientFacesDlg.h"
74 #include "SMESHGUI_RevolutionDlg.h"
75 #include "SMESHGUI_RotationDlg.h"
76 #include "SMESHGUI_ScaleDlg.h"
77 #include "SMESHGUI_Selection.h"
78 #include "SMESHGUI_SewingDlg.h"
79 #include "SMESHGUI_SingleEditDlg.h"
80 #include "SMESHGUI_SmoothingDlg.h"
81 #include "SMESHGUI_SymmetryDlg.h"
82 #include "SMESHGUI_TranslationDlg.h"
83 #include "SMESHGUI_TransparencyDlg.h"
84 #include "SMESHGUI_DisplayEntitiesDlg.h"
85 #include "SMESHGUI_SplitBiQuad.h"
86
87 #include "SMESHGUI_FilterUtils.h"
88 #include "SMESHGUI_GEOMGenUtils.h"
89 #include "SMESHGUI_GroupUtils.h"
90 #include "SMESHGUI_HypothesesUtils.h"
91 #include "SMESHGUI_MeshUtils.h"
92 #include "SMESHGUI_PatternUtils.h"
93 #include "SMESHGUI_Utils.h"
94 #include "SMESHGUI_VTKUtils.h"
95
96 #include "SMESH_version.h"
97
98 #include "SMESH_ControlsDef.hxx"
99 #include "SMESH_Actor.h"
100 #include "SMESH_ActorUtils.h"
101 #include "SMESH_Client.hxx"
102 #include "SMESH_ScalarBarActor.h"
103 #include "SMESH_TypeFilter.hxx"
104
105 // SALOME GUI includes
106 #include <SalomeApp_Application.h>
107 #include <SalomeApp_CheckFileDlg.h>
108 #include <SalomeApp_DataObject.h>
109 #include <SalomeApp_Study.h>
110 #include <SalomeApp_Tools.h>
111
112 #include <LightApp_DataOwner.h>
113 #include <LightApp_NameDlg.h>
114 #include <LightApp_Preferences.h>
115 #include <LightApp_SelectionMgr.h>
116 #include <LightApp_UpdateFlags.h>
117
118 #include <SVTK_ViewManager.h>
119 #include <SVTK_ViewModel.h>
120 #include <SVTK_ViewWindow.h>
121
122 #include <VTKViewer_Algorithm.h>
123
124 #include <SUIT_Desktop.h>
125 #include <SUIT_FileDlg.h>
126 #include <SUIT_MessageBox.h>
127 #include <SUIT_OverrideCursor.h>
128 #include <SUIT_ResourceMgr.h>
129 #include <SUIT_Session.h>
130
131 #include <QtxPopupMgr.h>
132 #include <QtxFontEdit.h>
133
134 #include <SALOME_ListIO.hxx>
135
136 #ifndef DISABLE_PLOT2DVIEWER
137 #include <SPlot2d_ViewModel.h>
138 #include <SPlot2d_Histogram.h>
139 #endif
140
141 // IDL includes
142 #include <SALOMEconfig.h>
143 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
144 #include CORBA_CLIENT_HEADER(SMESH_MeshEditor)
145 #include CORBA_CLIENT_HEADER(SMESH_Measurements)
146
147 // Qt includes
148 // #define       INCLUDE_MENUITEM_DEF // VSR commented ????????
149 #include <QApplication>
150 #include <QMenu>
151 #include <QTextStream>
152 #include <QListView>
153 #include <QTreeView>
154
155 // BOOST includes
156 #include <boost/shared_ptr.hpp>
157
158 // VTK includes
159 #include <vtkCallbackCommand.h>
160 #include <vtkCamera.h>
161 #include <vtkLookupTable.h>
162 #include <vtkPlane.h>
163 #include <vtkRenderer.h>
164
165 // SALOME KERNEL includes
166 #include <SALOMEDSClient_ClientFactory.hxx>
167 #include <SALOMEDSClient_IParameters.hxx>
168 #include <SALOMEDSClient_SComponent.hxx>
169 #include <SALOMEDSClient_StudyBuilder.hxx>
170 #include <SALOMEDS_Study.hxx>
171 #include <SALOMEDS_SObject.hxx>
172 #include "utilities.h"
173
174 // OCCT includes
175 #include <Standard_ErrorHandler.hxx>
176 #include <NCollection_DataMap.hxx>
177 #include <NCollection_DoubleMap.hxx>
178
179 #include <Basics_Utils.hxx>
180
181 // Below macro, when uncommented, switches on simplified (more performant) algorithm
182 // of auto-color picking up
183 #define SIMPLE_AUTOCOLOR
184
185 namespace
186 {
187   // Declarations
188   //=============================================================
189   void ImportMeshesFromFile(SMESH::SMESH_Gen_ptr theComponentMesh,
190                             int                  theCommandID);
191
192   void ExportMeshToFile(int theCommandID);
193
194   void SetDisplayMode(int theCommandID, SMESHGUI_StudyId2MarkerMap& theMarkerMap);
195
196   void SetDisplayEntity(int theCommandID);
197
198   int ActionToControl( int theID, bool theReversed = false );
199
200   void Control( int theCommandID );
201
202   // Definitions
203   //================================================================================
204   /*!
205    * \brief Reads meshes from file
206    */
207   //================================================================================
208
209   void ImportMeshesFromFile( SMESH::SMESH_Gen_ptr theComponentMesh,
210                              int                  theCommandID )
211   {
212     QStringList filter;
213     std::string myExtension;
214
215     if ( theCommandID == SMESHOp::OpImportMED ) {
216       filter.append( QObject::tr( "MED_FILES_FILTER" ) + " (*.*med)" );
217       filter.append( QObject::tr( "ALL_FILES_FILTER" ) + " (*)" );
218     }
219     else if ( theCommandID == SMESHOp::OpImportUNV ) {
220       filter.append( QObject::tr( "IDEAS_FILES_FILTER" ) + " (*.unv)" );
221     }
222     else if ( theCommandID == SMESHOp::OpImportDAT ) {
223       filter.append( QObject::tr( "DAT_FILES_FILTER" ) + " (*.dat)" );
224     }
225     else if ( theCommandID == SMESHOp::OpImportSTL ) {
226       filter.append( QObject::tr( "STL_FILES_FILTER" ) + " (*.stl)" );
227     }
228   #ifdef WITH_CGNS
229     else if ( theCommandID == SMESHOp::OpImportCGNS ) {
230       filter.append( QObject::tr( "CGNS_FILES_FILTER" ) + " (*.cgns)" );
231     }
232   #endif
233     else if ( theCommandID == SMESHOp::OpImportSAUV ) {
234       filter.append( QObject::tr( "SAUV files (*.sauv*)" ) );
235       filter.append( QObject::tr( "All files (*)" ) );
236     }
237     else if ( theCommandID == SMESHOp::OpImportGMF ) {
238       filter.append( QObject::tr( "GMF_ASCII_FILES_FILTER" ) + " (*.mesh)"  );
239       filter.append( QObject::tr( "GMF_BINARY_FILES_FILTER") + " (*.meshb)" );
240     }
241
242     QString anInitialPath = "";
243     if ( SUIT_FileDlg::getLastVisitedPath().isEmpty() )
244       anInitialPath = QDir::currentPath();
245
246     QStringList filenames;
247     bool toCreateGroups = true;
248
249     // if ( theCommandID == SMESHOp::OpImportGMF ) { // GMF
250     //   SalomeApp_CheckFileDlg* fd = new SalomeApp_CheckFileDlg
251     //     ( SMESHGUI::desktop(), true, QObject::tr("SMESH_REQUIRED_GROUPS"), true, true );
252     //   fd->setWindowTitle( QObject::tr( "SMESH_IMPORT_MESH" ) );
253     //   fd->setNameFilters( filter );
254     //   fd->SetChecked( true );
255     //   if ( fd->exec() )
256     //     filenames << fd->selectedFile();
257     //   toCreateGroups = fd->IsChecked();
258
259     //   delete fd;
260     // }
261     // else
262     {
263       filenames = SUIT_FileDlg::getOpenFileNames( SMESHGUI::desktop(),
264                                                   anInitialPath,
265                                                   filter,
266                                                   QObject::tr( "SMESH_IMPORT_MESH" ) );
267     }
268     if ( filenames.count() > 0 ) {
269       SUIT_OverrideCursor wc;
270       _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
271
272       QStringList errors;
273       QStringList anEntryList;
274       bool isEmpty = false;
275       for ( QStringList::ConstIterator it = filenames.begin(); it != filenames.end(); ++it ) {
276         QString filename = *it;
277         SMESH::mesh_array_var aMeshes = new SMESH::mesh_array;
278         try {
279           switch ( theCommandID ) {
280           case SMESHOp::OpImportDAT:
281             {
282               // DAT format (currently unsupported)
283               errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
284                              arg( QObject::tr( "SMESH_ERR_NOT_SUPPORTED_FORMAT" ) ) );
285               break;
286             }
287           case SMESHOp::OpImportUNV:
288             {
289               // UNV format
290               aMeshes->length( 1 );
291               aMeshes[0] = theComponentMesh->CreateMeshesFromUNV( filename.toUtf8().constData() );
292               if ( aMeshes[0]->_is_nil() )
293                 errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
294                                arg( QObject::tr( "SMESH_ERR_UNKNOWN_IMPORT_ERROR" ) ) );
295               break;
296             }
297           case SMESHOp::OpImportMED:
298             {
299               // MED format
300               SMESH::DriverMED_ReadStatus res;
301               aMeshes = theComponentMesh->CreateMeshesFromMED( filename.toUtf8().constData(), res );
302               if ( res != SMESH::DRS_OK ) {
303                 errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
304                                arg( QObject::tr( QString( "SMESH_DRS_%1" ).arg( res ).toLatin1().data() ) ) );
305               }
306               break;
307             }
308           case SMESHOp::OpImportSTL:
309             {
310               // STL format
311               aMeshes->length( 1 );
312               aMeshes[0] = theComponentMesh->CreateMeshesFromSTL( filename.toUtf8().constData() );
313               if ( aMeshes[0]->_is_nil() ) {
314                 errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
315                                arg( QObject::tr( "SMESH_ERR_UNKNOWN_IMPORT_ERROR" ) ) );
316               }
317               break;
318             }
319         #ifdef WITH_CGNS
320           case SMESHOp::OpImportCGNS:
321             {
322               // CGNS format
323               SMESH::DriverMED_ReadStatus res;
324               aMeshes = theComponentMesh->CreateMeshesFromCGNS( filename.toUtf8().constData(), res );
325               if ( res != SMESH::DRS_OK ) {
326                 errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
327                                arg( QObject::tr( QString( "SMESH_DRS_%1" ).arg( res ).toLatin1().data() ) ) );
328               }
329               break;
330             }
331         #endif
332           case SMESHOp::OpImportSAUV:
333             {
334               // SAUV format
335               SMESH::DriverMED_ReadStatus res;
336               aMeshes = theComponentMesh->CreateMeshesFromSAUV( filename.toUtf8().constData(), res );
337               if ( res != SMESH::DRS_OK ) {
338                 errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
339                                arg( QObject::tr( QString( "SMESH_DRS_%1" ).arg( res ).toLatin1().data() ) ) );
340               }
341               break;
342             }
343           case SMESHOp::OpImportGMF:
344             {
345               // GMF format
346               SMESH::ComputeError_var res;
347               aMeshes->length( 1 );
348               aMeshes[0] = theComponentMesh->CreateMeshesFromGMF( filename.toUtf8().constData(),
349                                                                   toCreateGroups,
350                                                                   res.out() );
351               if ( res->code != SMESH::DRS_OK ) {
352                 errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
353                                arg( QObject::tr( QString( "SMESH_DRS_%1" ).arg( res->code ).toLatin1().data() ) ) );
354                 if ( strlen( res->comment.in() ) > 0 ) {
355                   errors.back() += ": ";
356                   errors.back() += res->comment.in();
357                 }
358               }
359               break;
360             }
361           }
362         }
363         catch ( const SALOME::SALOME_Exception& S_ex ) {
364           errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
365                          arg( QObject::tr( "SMESH_ERR_UNKNOWN_IMPORT_ERROR" ) ) );
366         }
367
368         for ( int i = 0, iEnd = aMeshes->length(); i < iEnd; i++ ) {
369           _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshes[i] );
370           if ( aMeshSO ) {
371             _PTR(StudyBuilder) aBuilder = aStudy->NewBuilder();
372             _PTR(AttributePixMap) aPixmap = aBuilder->FindOrCreateAttribute( aMeshSO, "AttributePixMap" );
373             aPixmap->SetPixMap( "ICON_SMESH_TREE_MESH_IMPORTED" );
374             if ( theCommandID == SMESHOp::OpImportUNV ) // mesh names aren't taken from the file for UNV import
375               SMESH::SetName( aMeshSO, QFileInfo(filename).fileName() );
376
377             anEntryList.append( aMeshSO->GetID().c_str() );
378           }
379           else {
380             isEmpty = true;
381           }
382         }
383       }
384
385       // update Object browser
386       SMESHGUI::GetSMESHGUI()->updateObjBrowser();
387
388       // browse to the published meshes
389       if( LightApp_Application* anApp =
390           dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
391         anApp->browseObjects( anEntryList );
392
393       // show Error message box if there were errors
394       if ( errors.count() > 0 ) {
395         SUIT_MessageBox::critical( SMESHGUI::desktop(),
396                                    QObject::tr( "SMESH_ERROR" ),
397                                    QObject::tr( "SMESH_IMPORT_ERRORS" ) + "\n" + errors.join( "\n" ) );
398       }
399
400       // show warning message box, if some imported mesh is empty
401       if ( isEmpty ) {
402           SUIT_MessageBox::warning( SMESHGUI::desktop(),
403                                     QObject::tr( "SMESH_WRN_WARNING" ),
404                                     QObject::tr( "SMESH_DRS_SOME_EMPTY" ) );
405       }
406     }
407   }
408
409   //================================================================================
410   /*!
411    * \brief Export selected meshes or groups into a file
412    */
413   //================================================================================
414
415   void ExportMeshToFile( int theCommandID )
416   {
417     LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
418     SALOME_ListIO selected;
419     if( aSel )
420       aSel->selectedObjects( selected );
421
422     const bool isDAT = ( theCommandID == SMESHOp::OpExportDAT ||
423                          theCommandID == SMESHOp::OpPopupExportDAT );
424     const bool isMED = ( theCommandID == SMESHOp::OpExportMED ||
425                          theCommandID == SMESHOp::OpPopupExportMED );
426     const bool isUNV = ( theCommandID == SMESHOp::OpExportUNV ||
427                          theCommandID == SMESHOp::OpPopupExportUNV );
428     const bool isSTL = ( theCommandID == SMESHOp::OpExportSTL ||
429                          theCommandID == SMESHOp::OpPopupExportSTL );
430 #ifdef WITH_CGNS
431     const bool isCGNS= ( theCommandID == SMESHOp::OpExportCGNS ||
432                          theCommandID == SMESHOp::OpPopupExportCGNS );
433 #else
434     const bool isCGNS= false;
435 #endif
436     const bool isSAUV= ( theCommandID == SMESHOp::OpExportSAUV ||
437                          theCommandID == SMESHOp::OpPopupExportSAUV );
438     const bool isGMF = ( theCommandID == SMESHOp::OpExportGMF ||
439                          theCommandID == SMESHOp::OpPopupExportGMF );
440
441     const bool multiMeshSupported = ( isMED || isCGNS ); // file can hold several meshes
442     if ( selected.Extent() == 0 || ( selected.Extent() > 1 && !multiMeshSupported ))
443       return;
444
445     // get mesh object from selection and check duplication of their names
446     bool hasDuplicatedMeshNames = false;
447     QList< QPair< SMESH::SMESH_IDSource_var, QString > >           aMeshList;
448     QList< QPair< SMESH::SMESH_IDSource_var, QString > >::iterator aMeshIter;
449     SALOME_ListIteratorOfListIO It( selected );
450     for( ; It.More(); It.Next() )
451     {
452       Handle(SALOME_InteractiveObject) anIObject = It.Value();
453       SMESH::SMESH_IDSource_var aMeshItem =
454         SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(anIObject);
455       if ( aMeshItem->_is_nil() ) {
456         SUIT_MessageBox::warning( SMESHGUI::desktop(),
457                                   QObject::tr( "SMESH_WRN_WARNING" ),
458                                   QObject::tr( "SMESH_BAD_MESH_SELECTION" ));
459         return;
460       }
461
462       QString aMeshName = anIObject->getName();
463
464       // check for name duplications
465       if ( !hasDuplicatedMeshNames )
466         for( aMeshIter = aMeshList.begin(); aMeshIter != aMeshList.end(); aMeshIter++ ) {
467           if( aMeshName == (*aMeshIter).second ) {
468             hasDuplicatedMeshNames = true;
469             break;
470           }
471         }
472
473       aMeshList.append( QPair< SMESH::SMESH_IDSource_var, QString >( aMeshItem, aMeshName ) );
474     }
475
476     if( hasDuplicatedMeshNames && isMED ) {
477       int aRet = SUIT_MessageBox::warning(SMESHGUI::desktop(),
478                                           QObject::tr("SMESH_WRN_WARNING"),
479                                           QObject::tr("SMESH_EXPORT_MED_DUPLICATED_MESH_NAMES"),
480                                           QObject::tr("SMESH_BUT_YES"),
481                                           QObject::tr("SMESH_BUT_NO"), 0, 1);
482       if (aRet != 0)
483         return;
484     }
485
486     aMeshIter = aMeshList.begin();
487     SMESH::SMESH_IDSource_var aMeshOrGroup = (*aMeshIter).first;
488     SMESH::SMESH_Mesh_var            aMesh = aMeshOrGroup->GetMesh();
489     QString                      aMeshName = (*aMeshIter).second;
490
491     if ( isMED || isCGNS || isSAUV ) // formats where group names must be unique
492     {
493       // check for equal group names within each mesh
494       for( aMeshIter = aMeshList.begin(); aMeshIter != aMeshList.end(); aMeshIter++ ) {
495         SMESH::SMESH_Mesh_var aMeshItem = SMESH::SMESH_Mesh::_narrow( (*aMeshIter).first );
496         if ( !aMeshItem->_is_nil() && aMeshItem->HasDuplicatedGroupNamesMED()) {
497           int aRet = SUIT_MessageBox::warning
498             (SMESHGUI::desktop(),
499              QObject::tr("SMESH_WRN_WARNING"),
500              QObject::tr("SMESH_EXPORT_MED_DUPLICATED_GRP").arg((*aMeshIter).second),
501              QObject::tr("SMESH_BUT_YES"),
502              QObject::tr("SMESH_BUT_NO"), 0, 1);
503           if (aRet != 0)
504             return;
505         }
506       }
507     }
508     
509     // Warn the user about presence of not supported elements
510     QString format;
511     std::vector< SMESH::EntityType > notSupportedElemTypes, presentNotSupported;
512     if ( isDAT )
513     {
514       format = "DAT";
515       notSupportedElemTypes.push_back( SMESH::Entity_0D );
516       notSupportedElemTypes.push_back( SMESH::Entity_Ball );
517     }
518     else if ( isUNV )
519     {
520       format = "UNV";
521       notSupportedElemTypes.push_back( SMESH::Entity_Polygon );
522       notSupportedElemTypes.push_back( SMESH::Entity_Quad_Polygon );
523       notSupportedElemTypes.push_back( SMESH::Entity_Polyhedra );
524       notSupportedElemTypes.push_back( SMESH::Entity_Quad_Polyhedra );
525       notSupportedElemTypes.push_back( SMESH::Entity_Pyramid );
526       notSupportedElemTypes.push_back( SMESH::Entity_Hexagonal_Prism );
527       notSupportedElemTypes.push_back( SMESH::Entity_0D );
528       notSupportedElemTypes.push_back( SMESH::Entity_Ball );
529     }
530     else if ( isSTL )
531     {
532       format = "STL";
533       notSupportedElemTypes.push_back( SMESH::Entity_Edge );
534       notSupportedElemTypes.push_back( SMESH::Entity_Quad_Edge );
535       notSupportedElemTypes.push_back( SMESH::Entity_0D );
536       notSupportedElemTypes.push_back( SMESH::Entity_Ball );
537     }
538     else if ( isCGNS )
539     {
540       format = "CGNS";
541       notSupportedElemTypes.push_back( SMESH::Entity_Ball );
542     }
543     else if ( isSAUV )
544     {
545       format = "SAUV";
546       notSupportedElemTypes.push_back( SMESH::Entity_Ball );
547       notSupportedElemTypes.push_back( SMESH::Entity_BiQuad_Triangle );
548       notSupportedElemTypes.push_back( SMESH::Entity_BiQuad_Quadrangle );
549       notSupportedElemTypes.push_back( SMESH::Entity_TriQuad_Hexa );
550       notSupportedElemTypes.push_back( SMESH::Entity_Hexagonal_Prism );
551       notSupportedElemTypes.push_back( SMESH::Entity_Polygon );
552       notSupportedElemTypes.push_back( SMESH::Entity_Quad_Polygon );
553       notSupportedElemTypes.push_back( SMESH::Entity_Polyhedra );
554     }
555     else if ( isGMF )
556     {
557       format = "GMF";
558       notSupportedElemTypes.push_back( SMESH::Entity_0D );
559       notSupportedElemTypes.push_back( SMESH::Entity_Polygon );
560       notSupportedElemTypes.push_back( SMESH::Entity_Quad_Polygon );
561       notSupportedElemTypes.push_back( SMESH::Entity_Quad_Pyramid );
562       notSupportedElemTypes.push_back( SMESH::Entity_Quad_Penta );
563       notSupportedElemTypes.push_back( SMESH::Entity_Hexagonal_Prism );
564       notSupportedElemTypes.push_back( SMESH::Entity_Polyhedra );
565       notSupportedElemTypes.push_back( SMESH::Entity_Quad_Polyhedra );
566       notSupportedElemTypes.push_back( SMESH::Entity_Ball );
567     }
568     if ( ! notSupportedElemTypes.empty() )
569     {
570       SMESH::long_array_var nbElems = aMeshOrGroup->GetMeshInfo();
571       for ( size_t iType = 0; iType < notSupportedElemTypes.size(); ++iType )
572         if ( nbElems[ notSupportedElemTypes[ iType ]] > 0 )
573           presentNotSupported.push_back( notSupportedElemTypes[ iType ]);
574     }
575     if ( !presentNotSupported.empty() )
576     {
577       QString typeNames;
578       const char* typeMsg[] = {
579         "SMESH_NODES", "SMESH_ELEMS0D","SMESH_EDGES","SMESH_QUADRATIC_EDGES",
580         "SMESH_TRIANGLES", "SMESH_QUADRATIC_TRIANGLES", "SMESH_BIQUADRATIC_TRIANGLES",
581         "SMESH_QUADRANGLES","SMESH_QUADRATIC_QUADRANGLES", "SMESH_BIQUADRATIC_QUADRANGLES",
582         "SMESH_POLYGONS","SMESH_QUADRATIC_POLYGONS",
583         "SMESH_TETRAHEDRA","SMESH_QUADRATIC_TETRAHEDRONS","SMESH_PYRAMIDS",
584         "SMESH_QUADRATIC_PYRAMIDS","SMESH_HEXAHEDRA","SMESH_QUADRATIC_HEXAHEDRONS",
585         "SMESH_TRIQUADRATIC_HEXAHEDRONS","SMESH_PENTAHEDRA","SMESH_QUADRATIC_PENTAHEDRONS",
586         "SMESH_OCTAHEDRA","SMESH_POLYEDRONS","SMESH_QUADRATIC_POLYEDRONS","SMESH_BALLS"
587       };
588       // is typeMsg complete? (compilation failure mains that enum SMDSAbs_EntityType changed)
589       int nbTypes = sizeof( typeMsg ) / sizeof( const char* );
590       int _assert[( nbTypes == SMESH::Entity_Last ) ? 1 : -1 ]; _assert[0]=1;
591
592       QString andStr = " " + QObject::tr("SMESH_AND") + " ", comma(", ");
593       for ( size_t iType = 0; iType < presentNotSupported.size(); ++iType ) {
594         typeNames += QObject::tr( typeMsg[ presentNotSupported[ iType ]]);
595         if ( iType != presentNotSupported.size() - 1 )
596           typeNames += ( iType == presentNotSupported.size() - 2 ) ? andStr : comma;
597       }
598       int aRet = SUIT_MessageBox::warning
599         (SMESHGUI::desktop(),
600          QObject::tr("SMESH_WRN_WARNING"),
601          QObject::tr("EXPORT_NOT_SUPPORTED").arg(aMeshName).arg(format).arg(typeNames),
602          QObject::tr("SMESH_BUT_YES"),
603          QObject::tr("SMESH_BUT_NO"), 0, 1);
604       if (aRet != 0)
605         return;
606     }
607
608     // Get parameters of export operation
609
610     QString            aFilename;
611     SMESH::MED_VERSION aFormat;
612     // Init the parameters with the default values
613     bool aIsASCII_STL   = true;
614     bool toCreateGroups = false;
615     SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
616     if ( resMgr )
617       toCreateGroups = resMgr->booleanValue( "SMESH", "auto_groups", false );
618     bool toOverwrite  = true;
619     bool toFindOutDim = true;
620
621     QString aFilter, aTitle = QObject::tr("SMESH_EXPORT_MESH");
622     QString anInitialPath = "";
623     if ( SUIT_FileDlg::getLastVisitedPath().isEmpty() )
624       anInitialPath = QDir::currentPath();
625
626     QList< QPair< GEOM::ListOfFields_var, QString > > aFieldList;
627
628     // Get a file name to write in and additional otions
629     if ( isUNV || isDAT || isGMF ) // Export w/o options
630     {
631       if ( isUNV )
632         aFilter = QObject::tr( "IDEAS_FILES_FILTER" ) + " (*.unv)";
633       else if ( isDAT )
634         aFilter = QObject::tr( "DAT_FILES_FILTER" ) + " (*.dat)";
635       else if ( isGMF )
636         aFilter = QObject::tr( "GMF_ASCII_FILES_FILTER" ) + " (*.mesh)" +
637           ";;" +  QObject::tr( "GMF_BINARY_FILES_FILTER" )  + " (*.meshb)";
638      if ( anInitialPath.isEmpty() ) anInitialPath = SUIT_FileDlg::getLastVisitedPath();
639       aFilename = SUIT_FileDlg::getFileName(SMESHGUI::desktop(),
640                                             anInitialPath + QString("/") + aMeshName,
641                                             aFilter, aTitle, false);
642     }
643     else if ( isCGNS )// Export to CGNS
644     {
645       SUIT_FileDlg* fd = new SUIT_FileDlg( SMESHGUI::desktop(), false, true, true );
646       fd->setWindowTitle( aTitle );
647       fd->setNameFilter( QObject::tr( "CGNS_FILES_FILTER" ) + " (*.cgns)" );
648       if ( !anInitialPath.isEmpty() )
649         fd->setDirectory( anInitialPath );
650       fd->selectFile(aMeshName);
651       SMESHGUI_FileValidator* fv = new SMESHGUI_FileValidator( fd );
652       fd->setValidator( fv );
653
654       if ( fd->exec() )
655         aFilename = fd->selectedFile();
656       toOverwrite = fv->isOverwrite();
657
658       delete fd;
659     }
660     else if ( isSTL ) // Export to STL
661     {
662       QMap<QString, int> aFilterMap;
663       aFilterMap.insert( QObject::tr( "STL_ASCII_FILES_FILTER" ) + " (*.stl)", 1 );
664       aFilterMap.insert( QObject::tr( "STL_BIN_FILES_FILTER" )   + " (*.stl)", 0 );
665
666       QStringList filters;
667       QMap<QString, int>::const_iterator it = aFilterMap.begin();
668       for ( ; it != aFilterMap.end(); ++it )
669         filters.push_back( it.key() );
670
671       SUIT_FileDlg* fd = new SUIT_FileDlg( SMESHGUI::desktop(), false, true, true );
672       fd->setWindowTitle( aTitle );
673       fd->setNameFilters( filters );
674       fd->selectNameFilter( QObject::tr( "STL_ASCII_FILES_FILTER" ) + " (*.stl)" );
675       if ( !anInitialPath.isEmpty() )
676         fd->setDirectory( anInitialPath );
677       fd->selectFile(aMeshName);
678       bool is_ok = false;
679       while (!is_ok) {
680         if ( fd->exec() )
681           aFilename = fd->selectedFile();
682         aIsASCII_STL = (aFilterMap[fd->selectedNameFilter()]) == 1 ? true: false;
683         is_ok = true;
684       }
685       delete fd;
686     }
687     else if ( isMED || isSAUV ) // Export to MED or SAUV
688     {
689       QMap<QString, SMESH::MED_VERSION> aFilterMap;
690       //QString v21 (aMesh->GetVersionString(SMESH::MED_V2_1, 2));
691       if ( isMED ) {
692         QString v22 (aMesh->GetVersionString(SMESH::MED_V2_2, 2));
693         //aFilterMap.insert( QObject::tr( "MED_VX_FILES_FILTER" ).arg( v21 ) + " (*.med)", SMESH::MED_V2_1 );
694         aFilterMap.insert( QObject::tr( "MED_VX_FILES_FILTER" ).arg( v22 ) + " (*.med)", SMESH::MED_V2_2 );
695       }
696       else { // isSAUV
697         aFilterMap.insert("All files (*)", SMESH::MED_V2_1 );
698         aFilterMap.insert("SAUV files (*.sauv)", SMESH::MED_V2_2 );
699         aFilterMap.insert("SAUV files (*.sauve)", SMESH::MED_V2_1 );
700       }
701
702       QStringList filters;
703       QString aDefaultFilter;
704       QMap<QString, SMESH::MED_VERSION>::const_iterator it = aFilterMap.begin();
705       for ( ; it != aFilterMap.end(); ++it ) {
706         filters.push_back( it.key() );
707         if (it.value() == SMESH::MED_V2_2)
708           aDefaultFilter = it.key();
709       }
710       QStringList checkBoxes;
711       checkBoxes << QObject::tr("SMESH_AUTO_GROUPS") << QObject::tr("SMESH_AUTO_DIM");
712
713       SMESHGUI_FieldSelectorWdg* fieldSelWdg = new SMESHGUI_FieldSelectorWdg();
714       QList< QWidget* > wdgList;
715       if ( fieldSelWdg->GetAllFeilds( aMeshList, aFieldList ))
716         wdgList.append( fieldSelWdg );
717
718       SalomeApp_CheckFileDlg* fd =
719         new SalomeApp_CheckFileDlg ( SMESHGUI::desktop(), false, checkBoxes, true, true, wdgList );
720       fd->setWindowTitle( aTitle );
721       fd->setNameFilters( filters );
722       fd->selectNameFilter( aDefaultFilter );
723       fd->SetChecked( toCreateGroups, 0 );
724       fd->SetChecked( toFindOutDim,   1 );
725       if ( !anInitialPath.isEmpty() )
726         fd->setDirectory( anInitialPath );
727       fd->selectFile(aMeshName);
728       
729       
730       QListView *lview = fd->findChild<QListView*>("listView");
731       if( lview ) {
732         lview->setMinimumHeight(200);
733       }
734       QTreeView *tview = fd->findChild<QTreeView*>("treeView");
735       if( tview ) {
736         tview->setMinimumHeight(200);
737       }
738
739       SMESHGUI_FileValidator* fv = new SMESHGUI_FileValidator( fd );
740       fd->setValidator( fv );
741
742       bool is_ok = false;
743       while (!is_ok) {
744         if ( fd->exec() )
745           aFilename = fd->selectedFile();
746         else {
747           aFilename = QString::null;
748           break;
749         }
750         aFormat = aFilterMap[fd->selectedNameFilter()];
751         toOverwrite = fv->isOverwrite();
752         is_ok = true;
753         if ( !aFilename.isEmpty() ) {
754           // med-2.1 does not support poly elements
755           if ( aFormat==SMESH::MED_V2_1 )
756             for( aMeshIter = aMeshList.begin(); aMeshIter != aMeshList.end(); aMeshIter++ ) {
757               SMESH::SMESH_IDSource_var aMeshItem = (*aMeshIter).first;
758               SMESH::long_array_var nbElems = aMeshItem->GetMeshInfo();
759               if ( nbElems[ SMESH::Entity_Polygon   ] + nbElems[ SMESH::Entity_Quad_Polygon   ] +
760                    nbElems[ SMESH::Entity_Polyhedra ] + nbElems[ SMESH::Entity_Quad_Polyhedra ])
761               {
762                 int aRet = SUIT_MessageBox::warning(SMESHGUI::desktop(),
763                                                     QObject::tr("SMESH_WRN_WARNING"),
764                                                     QObject::tr("SMESH_EXPORT_MED_V2_1").arg((*aMeshIter).second),
765                                                     QObject::tr("SMESH_BUT_YES"),
766                                                     QObject::tr("SMESH_BUT_NO"), 0, 1);
767                 if (aRet != 0) {
768                   is_ok = false;
769                   break;
770                 }
771               }
772             }
773           if( !toOverwrite ) {
774             // can't append to an existing using other format
775             SMESH::MED_VERSION aVersion = SMESH::MED_V2_1;
776             bool isVersionOk = SMESHGUI::GetSMESHGen()->GetMEDVersion( aFilename.toUtf8().constData(), aVersion );
777             if( !isVersionOk || aVersion != aFormat ) {
778               int aRet = SUIT_MessageBox::warning(SMESHGUI::desktop(),
779                                                   QObject::tr("SMESH_WRN_WARNING"),
780                                                   QObject::tr("SMESH_EXPORT_MED_VERSION_COLLISION").arg(aFilename),
781                                                   QObject::tr("SMESH_BUT_YES"),
782                                                   QObject::tr("SMESH_BUT_NO"), 0, 1);
783               if (aRet == 0)
784                 toOverwrite = true;
785               else
786                 is_ok = false;
787             }
788
789             QStringList aMeshNamesCollisionList;
790             SMESH::string_array_var aMeshNames = SMESHGUI::GetSMESHGen()->GetMeshNames( aFilename.toUtf8().constData() );
791             for( int i = 0, n = aMeshNames->length(); i < n; i++ ) {
792               QString anExistingMeshName( aMeshNames[ i ] );
793               for( aMeshIter = aMeshList.begin(); aMeshIter != aMeshList.end(); aMeshIter++ ) {
794                 QString anExportMeshName = (*aMeshIter).second;
795                 if( anExportMeshName == anExistingMeshName ) {
796                   aMeshNamesCollisionList.append( anExportMeshName );
797                   break;
798                 }
799               }
800             }
801             if( !aMeshNamesCollisionList.isEmpty() ) {
802               QString aMeshNamesCollisionString = aMeshNamesCollisionList.join( ", " );
803               int aRet = SUIT_MessageBox::warning(SMESHGUI::desktop(),
804                                                   QObject::tr("SMESH_WRN_WARNING"),
805                                                   QObject::tr("SMESH_EXPORT_MED_MESH_NAMES_COLLISION").arg(aMeshNamesCollisionString),
806                                                   QObject::tr("SMESH_BUT_YES"),
807                                                   QObject::tr("SMESH_BUT_NO"),
808                                                   QObject::tr("SMESH_BUT_CANCEL"), 0, 2);
809               if (aRet == 0)
810                 toOverwrite = true;
811               else if (aRet == 2)
812                 is_ok = false;
813             }
814           }
815         }
816       }
817       toCreateGroups = fd->IsChecked(0);
818       toFindOutDim   = fd->IsChecked(1);
819       fieldSelWdg->GetSelectedFeilds();
820       if ( !fieldSelWdg->parent() )
821         delete fieldSelWdg;
822       delete fd;
823     }
824     else
825     {
826       return;
827     }
828
829     // Perform export
830
831     if ( !aFilename.isEmpty() ) {
832       // Check whether the file already exists and delete it if yes
833       QFile aFile( aFilename );
834       if ( aFile.exists() && toOverwrite )
835         aFile.remove();
836       SUIT_OverrideCursor wc;
837
838       try {
839         // Renumbering is not needed since SMDS redesign in V6.2.0 (Nov 2010)
840 //         bool Renumber = false;
841 //         // PAL 14172  : Check of we have to renumber or not from the preferences before export
842 //         if (resMgr)
843 //           Renumber= resMgr->booleanValue("renumbering");
844 //         if (Renumber){
845 //           SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
846 //           aMeshEditor->RenumberNodes();
847 //           aMeshEditor->RenumberElements();
848 //           if ( SMESHGUI::automaticUpdate() )
849 //             SMESH::UpdateView();
850 //         }
851         if ( isMED )
852         {
853           aMeshIter = aMeshList.begin();
854           for( int aMeshIndex = 0; aMeshIter != aMeshList.end(); aMeshIter++, aMeshIndex++ )
855           {
856             SMESH::SMESH_IDSource_var aMeshOrGroup = (*aMeshIter).first;
857             SMESH::SMESH_Mesh_var        aMeshItem = aMeshOrGroup->GetMesh();
858             const GEOM::ListOfFields&       fields = aFieldList[ aMeshIndex ].first.in();
859             const QString&            geoAssFields = aFieldList[ aMeshIndex ].second;
860             const bool                   hasFields = ( fields.length() || !geoAssFields.isEmpty() );
861             if ( !hasFields && aMeshOrGroup->_is_equivalent( aMeshItem ))
862               aMeshItem->ExportToMEDX( aFilename.toUtf8().data(), toCreateGroups,
863                                        aFormat, toOverwrite && aMeshIndex == 0, toFindOutDim );
864             else
865               aMeshItem->ExportPartToMED( aMeshOrGroup, aFilename.toUtf8().data(), toCreateGroups,
866                                           aFormat, toOverwrite && aMeshIndex == 0, toFindOutDim,
867                                           fields, geoAssFields.toLatin1().data() );
868           }
869         }
870         else if ( isSAUV )
871         {
872           for( aMeshIter = aMeshList.begin(); aMeshIter != aMeshList.end(); aMeshIter++ )
873           {
874             SMESH::SMESH_Mesh_var aMeshItem = SMESH::SMESH_Mesh::_narrow( (*aMeshIter).first );
875             if( !aMeshItem->_is_nil() )
876               aMeshItem->ExportSAUV( aFilename.toUtf8().data(), toCreateGroups );
877           }
878         }
879         else if ( isDAT )
880         {
881           if ( aMeshOrGroup->_is_equivalent( aMesh ))
882             aMesh->ExportDAT( aFilename.toUtf8().data() );
883           else
884             aMesh->ExportPartToDAT( aMeshOrGroup, aFilename.toUtf8().data() );
885         }
886         else if ( isUNV )
887         {
888           if ( aMeshOrGroup->_is_equivalent( aMesh ))
889             aMesh->ExportUNV( aFilename.toUtf8().data() );
890           else
891             aMesh->ExportPartToUNV( aMeshOrGroup, aFilename.toUtf8().data() );
892         }
893         else if ( isSTL )
894         {
895           if ( aMeshOrGroup->_is_equivalent( aMesh ))
896             aMesh->ExportSTL( aFilename.toUtf8().data(), aIsASCII_STL );
897           else
898             aMesh->ExportPartToSTL( aMeshOrGroup, aFilename.toUtf8().data(), aIsASCII_STL );
899         }
900         else if ( isCGNS )
901         {
902           aMeshIter = aMeshList.begin();
903           for( int aMeshIndex = 0; aMeshIter != aMeshList.end(); aMeshIter++, aMeshIndex++ )
904           {
905             SMESH::SMESH_IDSource_var aMeshOrGroup = (*aMeshIter).first;
906             SMESH::SMESH_Mesh_var        aMeshItem = aMeshOrGroup->GetMesh();
907             aMeshItem->ExportCGNS( aMeshOrGroup,
908                                    aFilename.toUtf8().data(),
909                                    toOverwrite && aMeshIndex == 0 );
910           }
911         }
912         else if ( isGMF )
913         {
914           toCreateGroups = true;
915           aMesh->ExportGMF( aMeshOrGroup, aFilename.toUtf8().data(), toCreateGroups );
916         }
917       }
918       catch (const SALOME::SALOME_Exception& S_ex){
919         wc.suspend();
920         SUIT_MessageBox::warning(SMESHGUI::desktop(),
921                                  QObject::tr("SMESH_WRN_WARNING"),
922                                  QObject::tr("SMESH_EXPORT_FAILED"));
923         wc.resume();
924       }
925     }
926   }
927
928   inline void InverseEntityMode(unsigned int& theOutputMode,
929                                 unsigned int  theMode)
930   {
931     bool anIsNotPresent = ~theOutputMode & theMode;
932     if(anIsNotPresent)
933       theOutputMode |= theMode;
934     else
935       theOutputMode &= ~theMode;
936   }
937
938   void SetDisplayEntity(int theCommandID)
939   {
940     LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
941     SALOME_ListIO selected;
942     if ( aSel )
943       aSel->selectedObjects( selected );
944
945     if ( selected.Extent() >= 1 ) {
946       SALOME_ListIteratorOfListIO It( selected );
947       for( ; It.More(); It.Next()){
948         Handle(SALOME_InteractiveObject) IObject = It.Value();
949         if(IObject->hasEntry()){
950           if(SMESH_Actor *anActor = SMESH::FindActorByEntry(IObject->getEntry())){
951             unsigned int aMode = anActor->GetEntityMode();
952             switch(theCommandID){
953             case SMESHOp::OpDE0DElements: InverseEntityMode(aMode,SMESH_Actor::e0DElements); break;
954             case SMESHOp::OpDEEdges:      InverseEntityMode(aMode,SMESH_Actor::eEdges); break;
955             case SMESHOp::OpDEFaces:      InverseEntityMode(aMode,SMESH_Actor::eFaces); break;
956             case SMESHOp::OpDEVolumes:    InverseEntityMode(aMode,SMESH_Actor::eVolumes); break;
957             case SMESHOp::OpDEBalls:      InverseEntityMode(aMode,SMESH_Actor::eBallElem); break;
958             case SMESHOp::OpDEAllEntity:  aMode = SMESH_Actor::eAllEntity; break;
959             }
960             if(aMode)
961               anActor->SetEntityMode(aMode);
962           }
963         }
964       }
965     }
966   }
967
968   void AutoColor()
969   {
970     SalomeApp_Application* app =
971       dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
972     if ( !app )
973       return;
974
975     LightApp_SelectionMgr* aSel = app->selectionMgr();
976     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
977     if ( !aSel || !appStudy )
978       return;
979
980     SALOME_ListIO selected;
981     aSel->selectedObjects( selected );
982     if ( selected.IsEmpty() )
983       return;
984
985     Handle(SALOME_InteractiveObject) anIObject = selected.First();
986
987     _PTR(Study)         aStudy = appStudy->studyDS();
988     _PTR(SObject) aMainSObject = aStudy->FindObjectID( anIObject->getEntry() );
989     SMESH::SMESH_Mesh_var aMainObject = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIObject);
990     if ( aMainObject->_is_nil() )
991       return;
992
993     SUIT_OverrideCursor wc;
994
995     aMainObject->SetAutoColor( true ); // mesh groups are re-colored here
996
997     QList<SALOMEDS::Color> aReservedColors;
998
999     SMESH::ListOfGroups aListOfGroups = *aMainObject->GetGroups();
1000     for ( int i = 0, n = aListOfGroups.length(); i < n; i++ )
1001     {
1002       SMESH::SMESH_GroupBase_var aGroupObject = aListOfGroups[i];
1003
1004 #ifdef SIMPLE_AUTOCOLOR   // simplified algorithm for auto-colors
1005       SALOMEDS::Color aColor = SMESHGUI::getPredefinedUniqueColor();
1006 #else                     // old algorithm  for auto-colors
1007       SALOMEDS::Color aColor = SMESHGUI::getUniqueColor( aReservedColors );
1008       aReservedColors.append( aColor );
1009 #endif                    // SIMPLE_AUTOCOLOR
1010       aGroupObject->SetColor( aColor );
1011
1012       _PTR(SObject) aGroupSObject = SMESH::FindSObject(aGroupObject);
1013       if ( aGroupSObject ) {
1014         QColor c;
1015         int delta;
1016         if ( SMESH_Actor *anActor = SMESH::FindActorByEntry(aGroupSObject->GetID().c_str())) {
1017           switch ( aGroupObject->GetType ()) {
1018           case SMESH::NODE:
1019             anActor->SetNodeColor( aColor.R, aColor.G, aColor.B ); break;
1020           case SMESH::EDGE:
1021             anActor->SetEdgeColor( aColor.R, aColor.G, aColor.B ); break;
1022           case SMESH::ELEM0D:
1023             anActor->Set0DColor( aColor.R, aColor.G, aColor.B ); break;
1024           case SMESH::BALL:
1025             anActor->SetBallColor( aColor.R, aColor.G, aColor.B ); break;
1026           case SMESH::VOLUME:
1027             SMESH::GetColor("SMESH", "volume_color", c, delta, "255,0,170|-100");
1028             anActor->SetVolumeColor( aColor.R, aColor.G, aColor.B, delta ); break;
1029           case SMESH::FACE:
1030           default:
1031             SMESH::GetColor("SMESH", "fill_color", c, delta, "0,170,255|-100");
1032             anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B, delta );
1033           }
1034         }
1035       }
1036     }
1037
1038     SMESH::RepaintCurrentView();
1039   }
1040
1041   void OverallMeshQuality()
1042   {
1043     SMESHGUI::GetSMESHGUI()->EmitSignalDeactivateDialog();
1044     LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1045     SALOME_ListIO selected;
1046     if( aSel )
1047       aSel->selectedObjects( selected );
1048
1049     if ( selected.IsEmpty() ) return;
1050     SALOME_ListIteratorOfListIO It( selected );
1051     for ( ; It.More(); It.Next() ) {
1052       SMESHGUI_CtrlInfoDlg* ctrlDlg = new SMESHGUI_CtrlInfoDlg( SMESHGUI::desktop() );
1053       ctrlDlg->showInfo( It.Value() );
1054       ctrlDlg->show();
1055     }
1056   }
1057
1058   QString functorToString( SMESH::Controls::FunctorPtr f )
1059   {
1060     QString type = QObject::tr( "UNKNOWN_CONTROL" );
1061     if ( dynamic_cast< SMESH::Controls::Volume* >( f.get() ) )
1062       type = QObject::tr( "VOLUME_3D_ELEMENTS" );
1063     else if ( dynamic_cast< SMESH::Controls::MaxElementLength2D* >( f.get() ) )
1064       type = QObject::tr( "MAX_ELEMENT_LENGTH_2D" );
1065     else if ( dynamic_cast< SMESH::Controls::MaxElementLength3D* >( f.get() ) )
1066       type = QObject::tr( "MAX_ELEMENT_LENGTH_3D" );
1067     else if ( dynamic_cast< SMESH::Controls::MinimumAngle* >( f.get() ) )
1068       type = QObject::tr( "MINIMUMANGLE_ELEMENTS" );
1069     else if ( dynamic_cast< SMESH::Controls::AspectRatio* >( f.get() ) )
1070       type = QObject::tr( "ASPECTRATIO_ELEMENTS" );
1071     else if ( dynamic_cast< SMESH::Controls::AspectRatio3D* >( f.get() ) )
1072       type = QObject::tr( "ASPECTRATIO_3D_ELEMENTS" );
1073     else if ( dynamic_cast< SMESH::Controls::Warping* >( f.get() ) )
1074       type = QObject::tr( "WARP_ELEMENTS" );
1075     else if ( dynamic_cast< SMESH::Controls::Taper* >( f.get() ) )
1076       type = QObject::tr( "TAPER_ELEMENTS" );
1077     else if ( dynamic_cast< SMESH::Controls::Skew* >( f.get() ) )
1078       type = QObject::tr( "SKEW_ELEMENTS" );
1079     else if ( dynamic_cast< SMESH::Controls::Area* >( f.get() ) )
1080       type = QObject::tr( "AREA_ELEMENTS" );
1081     else if ( dynamic_cast< SMESH::Controls::Length* >( f.get() ) )
1082       type = QObject::tr( "LENGTH_EDGES" );
1083     else if ( dynamic_cast< SMESH::Controls::Length2D* >( f.get() ) )
1084       type = QObject::tr( "LENGTH2D_EDGES" );
1085     else if ( dynamic_cast< SMESH::Controls::MultiConnection* >( f.get() ) )
1086       type = QObject::tr( "MULTI_BORDERS" );
1087     else if ( dynamic_cast< SMESH::Controls::MultiConnection2D* >( f.get() ) )
1088       type = QObject::tr( "MULTI2D_BORDERS" );
1089     else if ( dynamic_cast< SMESH::Controls::FreeNodes* >( f.get() ) )
1090       type = QObject::tr( "FREE_NODES" );
1091     else if ( dynamic_cast< SMESH::Controls::FreeEdges* >( f.get() ) )
1092       type = QObject::tr( "FREE_EDGES" );
1093     else if ( dynamic_cast< SMESH::Controls::FreeBorders* >( f.get() ) )
1094       type = QObject::tr( "FREE_BORDERS" );
1095     else if ( dynamic_cast< SMESH::Controls::FreeFaces* >( f.get() ) )
1096       type = QObject::tr( "FREE_FACES" );
1097     else if ( dynamic_cast< SMESH::Controls::BareBorderVolume* >( f.get() ) )
1098       type = QObject::tr( "BARE_BORDER_VOLUME" );
1099     else if ( dynamic_cast< SMESH::Controls::BareBorderFace* >( f.get() ) )
1100       type = QObject::tr( "BARE_BORDER_FACE" );
1101     else if ( dynamic_cast< SMESH::Controls::OverConstrainedVolume* >( f.get() ) )
1102       type = QObject::tr( "OVER_CONSTRAINED_VOLUME" );
1103     else if ( dynamic_cast< SMESH::Controls::OverConstrainedFace* >( f.get() ) )
1104       type = QObject::tr( "OVER_CONSTRAINED_FACE" );
1105     else if ( dynamic_cast< SMESH::Controls::CoincidentNodes* >( f.get() ) )
1106       type = QObject::tr( "EQUAL_NODE" );
1107     else if ( dynamic_cast< SMESH::Controls::CoincidentElements1D* >( f.get() ) )
1108       type = QObject::tr( "EQUAL_EDGE" );
1109     else if ( dynamic_cast< SMESH::Controls::CoincidentElements2D* >( f.get() ) )
1110       type = QObject::tr( "EQUAL_FACE" );
1111     else if ( dynamic_cast< SMESH::Controls::CoincidentElements3D* >( f.get() ) )
1112       type = QObject::tr( "EQUAL_VOLUME" );
1113     return type;
1114   }
1115
1116   void SaveDistribution()
1117   {
1118     LightApp_SelectionMgr* aSel = SMESHGUI::selectionMgr();
1119     SALOME_ListIO selected;
1120     if ( aSel )
1121       aSel->selectedObjects( selected );
1122
1123     if ( selected.Extent() == 1 ) {
1124       Handle(SALOME_InteractiveObject) anIO = selected.First();
1125       if ( anIO->hasEntry() ) {
1126         SMESH_Actor* anActor = SMESH::FindActorByEntry( anIO->getEntry() );
1127         if ( anActor &&
1128              anActor->GetScalarBarActor() &&
1129              anActor->GetControlMode() != SMESH_Actor::eNone )
1130         {
1131           SMESH_ScalarBarActor* aScalarBarActor = anActor->GetScalarBarActor();
1132           SMESH::Controls::FunctorPtr aFunctor = anActor->GetFunctor();
1133           if ( aScalarBarActor && aFunctor ) {
1134             SMESH::Controls::NumericalFunctor* aNumFun =
1135               dynamic_cast<SMESH::Controls::NumericalFunctor*>( aFunctor.get() );
1136             if ( aNumFun ) {
1137               std::vector<int> elements;
1138               SMESH::SMESH_Mesh_var mesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIO);
1139               if ( mesh->_is_nil() ) {
1140                 SMESH::SMESH_IDSource_var idSource =
1141                   SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(anIO);
1142                 if ( !idSource->_is_nil() )
1143                 {
1144                   SMESH::long_array_var ids = idSource->GetIDs();
1145                   elements.resize( ids->length() );
1146                   for ( unsigned i = 0; i < elements.size(); ++i )
1147                     elements[i] = ids[i];
1148                 }
1149               }
1150               int nbIntervals = aScalarBarActor->GetMaximumNumberOfColors();
1151               vtkLookupTable* lookupTable =
1152                 static_cast<vtkLookupTable*>(aScalarBarActor->GetLookupTable());
1153               double * minmax = lookupTable->GetRange();
1154               bool isLogarithmic = lookupTable->GetScale() == VTK_SCALE_LOG10;
1155               std::vector<int>    nbEvents;
1156               std::vector<double> funValues;
1157               aNumFun->GetHistogram( nbIntervals, nbEvents, funValues,
1158                                      elements, minmax, isLogarithmic );
1159               QString anInitialPath = "";
1160               if ( SUIT_FileDlg::getLastVisitedPath().isEmpty() )
1161                 anInitialPath = QDir::currentPath();
1162               QString aMeshName = anIO->getName();
1163               QStringList filter;
1164               filter.append( QObject::tr( "TEXT_FILES_FILTER" ) + " (*.txt)" );
1165               filter.append( QObject::tr( "ALL_FILES_FILTER" ) + " (*)" );
1166               QString aFilename = anInitialPath + "/" + aMeshName + "_" +
1167                 functorToString( aFunctor ).toLower().simplified().replace( QRegExp( " |-" ), "_" ) + ".txt";
1168               aFilename = SUIT_FileDlg::getFileName( SMESHGUI::desktop(),
1169                                                      aFilename,
1170                                                      filter,
1171                                                      QObject::tr( "SMESH_SAVE_DISTRIBUTION" ),
1172                                                      false );
1173               if ( !aFilename.isEmpty() ) {
1174                 QFile f( aFilename );
1175                 if ( f.open( QFile::WriteOnly | QFile::Truncate ) ) {
1176                   QTextStream out( &f );
1177                   out << "# Mesh: " << aMeshName << endl;
1178                   out << "# Control: " << functorToString( aFunctor ) << endl;
1179                   out << "#" << endl;
1180                   out.setFieldWidth( 10 );
1181                   for ( int i = 0; i < (int)qMin( nbEvents.size(), funValues.size()-1 ); i++ )
1182                     out << funValues[i] << "\t" << funValues[i+1] << "\t" << nbEvents[i] << endl;
1183                   f.close();
1184                 }
1185               }
1186             }
1187           }
1188         }
1189       }
1190     }
1191   }
1192
1193   void ShowElement( int theCommandID )
1194   {
1195     LightApp_SelectionMgr* aSel = SMESHGUI::selectionMgr();
1196     SALOME_ListIO selected;
1197     if ( aSel )
1198       aSel->selectedObjects( selected );
1199
1200     if ( selected.Extent() == 1 ) {
1201       Handle(SALOME_InteractiveObject) anIO = selected.First();
1202       if ( anIO->hasEntry() ) {
1203         SMESH_Actor* anActor = SMESH::FindActorByEntry( anIO->getEntry() );
1204         if ( anActor &&
1205              anActor->GetScalarBarActor() &&
1206              anActor->GetControlMode() != SMESH_Actor::eNone )
1207         {
1208           SMESH_ScalarBarActor *aScalarBarActor = anActor->GetScalarBarActor();
1209           if ( theCommandID == SMESHOp::OpShowDistribution ) {
1210             aScalarBarActor->SetDistributionVisibility(!aScalarBarActor->GetDistributionVisibility());
1211           }
1212           else if ( theCommandID == SMESHOp::OpShowScalarBar ) {
1213             aScalarBarActor->SetVisibility( !aScalarBarActor->GetVisibility());
1214           }
1215         }
1216       }
1217     }
1218   }
1219
1220 #ifndef DISABLE_PLOT2DVIEWER
1221   void PlotDistribution()
1222   {
1223     SalomeApp_Application* app =
1224       dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
1225     if( !app )
1226       return;
1227
1228     LightApp_SelectionMgr* aSel = SMESHGUI::selectionMgr();
1229     SALOME_ListIO selected;
1230     if ( aSel )
1231       aSel->selectedObjects( selected );
1232
1233     if ( selected.Extent() == 1 ) {
1234       Handle(SALOME_InteractiveObject) anIO = selected.First();
1235       if ( anIO->hasEntry() ) {
1236         //Find Actor by entry before getting Plot2d viewer,
1237         //because after call getViewManager( Plot2d_Viewer::Type(), true ) active window is Plot2d Viewer
1238         SMESH_Actor* anActor = SMESH::FindActorByEntry( anIO->getEntry() );
1239
1240         SUIT_ViewManager* aViewManager =
1241           app->getViewManager( Plot2d_Viewer::Type(), true ); // create if necessary
1242         if( !aViewManager )
1243           return;
1244
1245         SPlot2d_Viewer* aView = dynamic_cast<SPlot2d_Viewer*>(aViewManager->getViewModel());
1246         if ( !aView )
1247           return;
1248
1249         Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame();
1250         if ( !aPlot )
1251           return;
1252
1253         if ( anActor && anActor->GetControlMode() != SMESH_Actor::eNone )
1254         {
1255           SPlot2d_Histogram* aHistogram = anActor->UpdatePlot2Histogram();
1256           QString functorName = functorToString( anActor->GetFunctor());
1257           QString aHistogramName("%1 : %2");
1258           aHistogramName = aHistogramName.arg(anIO->getName()).arg(functorName);
1259           aHistogram->setName(aHistogramName);
1260           aHistogram->setHorTitle(functorName);
1261           aHistogram->setVerTitle(QObject::tr("DISTRIBUTION_NB_ENT"));
1262           aPlot->displayObject(aHistogram, true);
1263         }
1264       }
1265     }
1266   }
1267 #endif //DISABLE_PLOT2DVIEWER
1268
1269   void DisableAutoColor()
1270   {
1271     LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1272     SALOME_ListIO selected;
1273     if ( aSel )
1274       aSel->selectedObjects( selected );
1275
1276     if ( selected.Extent() ) {
1277       Handle(SALOME_InteractiveObject) anIObject = selected.First();
1278       SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIObject);
1279       if ( !aMesh->_is_nil() ) {
1280         aMesh->SetAutoColor( false );
1281       }
1282     }
1283   }
1284
1285   void sortChildren()
1286   {
1287     LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1288     SALOME_ListIO selected;
1289     if ( aSel ) {
1290       aSel->selectedObjects( selected );
1291       if ( selected.Extent() )
1292       {
1293         Handle(SALOME_InteractiveObject) anIObject = selected.First();
1294         _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1295         _PTR(SObject) aSObj = aStudy->FindObjectID(anIObject->getEntry());
1296         if (aSObj) {
1297           if ( aStudy->GetUseCaseBuilder()->SortChildren( aSObj, true/*AscendingOrder*/ ) ) {
1298             SMESHGUI::GetSMESHGUI()->updateObjBrowser();
1299           }
1300         }
1301       }
1302     }
1303   }
1304
1305   void SetDisplayMode(int theCommandID, SMESHGUI_StudyId2MarkerMap& theMarkerMap)
1306   {
1307     SALOME_ListIO selected;
1308     SalomeApp_Application* app =
1309       dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
1310     if ( !app )
1311       return;
1312
1313     LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1314     SalomeApp_Study*   appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1315     if ( !aSel || !appStudy )
1316       return;
1317
1318     if ( theCommandID == SMESHOp::OpClipping ) { // Clipping dialog can be activated without selection
1319       if ( SMESHGUI* aModule = SMESHGUI::GetSMESHGUI() ) {
1320         aModule->EmitSignalDeactivateDialog();
1321         if( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( aModule ) )
1322           (new SMESHGUI_ClippingDlg( aModule, aViewWindow ))->show();
1323       }
1324       return;
1325     }
1326
1327     _PTR(Study) aStudy = appStudy->studyDS();
1328
1329     aSel->selectedObjects( selected );
1330
1331     if ( selected.Extent() >= 1 )
1332     {
1333       switch ( theCommandID ) {
1334       case SMESHOp::OpTransparency:
1335       {
1336         SMESHGUI::GetSMESHGUI()->EmitSignalDeactivateDialog();
1337         (new SMESHGUI_TransparencyDlg( SMESHGUI::GetSMESHGUI() ))->show();
1338         return;
1339       }
1340       case SMESHOp::OpProperties:
1341       {
1342         double color[3];
1343         QColor faceColor, edgeColor, nodeColor, elem0dColor, ballColor;
1344         QColor orientationColor, outlineColor, volumeColor;
1345         int deltaF = 0, deltaV = 0;
1346         int elem0dSize   = 1;
1347         //int ballSize     = 1;
1348         double ballScale = 1.0;
1349         int edgeWidth    = 1;
1350         int outlineWidth = 1;
1351         double shrinkCoef = 0.0;
1352         double orientationScale = 0.0;
1353         bool orientation3d = false;
1354         VTK::MarkerType markerType = VTK::MT_NONE;
1355         VTK::MarkerScale markerScale = VTK::MS_NONE;
1356         int markerId = 0;
1357         bool hasNodes = false;
1358         int presentEntities = 0;
1359         bool firstTime  = true;
1360
1361         SALOME_ListIteratorOfListIO It( selected );
1362         for ( ; It.More(); It.Next() ) {
1363           Handle(SALOME_InteractiveObject) IObject = It.Value();
1364           if ( !IObject->hasEntry() ) continue;
1365           SMESH_Actor* anActor = SMESH::FindActorByEntry( IObject->getEntry() );
1366           if ( !anActor || !anActor->GetObject() ) continue;
1367
1368           if ( firstTime ) {
1369             // nodes: color, marker
1370             anActor->GetNodeColor( color[0], color[1], color[2] );
1371             nodeColor.setRgbF( color[0], color[1], color[2] );
1372             markerType  = anActor->GetMarkerType();
1373             markerScale = anActor->GetMarkerScale();
1374             markerId    = anActor->GetMarkerTexture();
1375             // edges: color, width
1376             anActor->GetEdgeColor( color[0], color[1], color[2] );
1377             edgeColor.setRgbF( color[0], color[1], color[2] );
1378             edgeWidth = qMax( (int)anActor->GetLineWidth(), 1 ); // minimum allowed width is 1
1379             // faces: front color, back color (delta)
1380             anActor->GetSufaceColor( color[0], color[1], color[2], deltaF );
1381             faceColor.setRgbF( color[0], color[1], color[2] );
1382             // faces: front color, back color (delta)
1383             anActor->GetVolumeColor( color[0], color[1], color[2], deltaV );
1384             volumeColor.setRgbF( color[0], color[1], color[2] );
1385             // 0d elements: color, size
1386             anActor->Get0DColor( color[0], color[1], color[2] );
1387             elem0dColor.setRgbF( color[0], color[1], color[2] );
1388             elem0dSize = qMax( (int)anActor->Get0DSize(), 1 ); // minimum allowed size is 1
1389             // balls: color, size
1390             anActor->GetBallColor( color[0], color[1], color[2] );
1391             ballColor.setRgbF( color[0], color[1], color[2] );
1392             //ballSize = qMax( (int)anActor->GetBallSize(), 1 ); // minimum allowed size is 1
1393             ballScale = qMax( (double)anActor->GetBallScale(), 1e-2 ); // minimum allowed scale is 1e-2
1394             // outlines: color
1395             anActor->GetOutlineColor( color[0], color[1], color[2] );
1396             outlineColor.setRgbF( color[0], color[1], color[2] );
1397             outlineWidth = qMax( (int)anActor->GetOutlineWidth(), 1 ); // minimum allowed width is 1
1398             // orientation vectors: color, scale, 3d flag
1399             anActor->GetFacesOrientationColor( color[0], color[1], color[2] );
1400             orientationColor.setRgbF( color[0], color[1], color[2] );
1401             orientationScale = anActor->GetFacesOrientationScale();
1402             orientation3d = anActor->GetFacesOrientation3DVectors();
1403             // shrink factor
1404             shrinkCoef = anActor->GetShrinkFactor();
1405           }
1406
1407           firstTime = false; // we only take properties from first object (for performance reasons)
1408
1409           if ( !hasNodes )
1410             hasNodes = anActor->GetObject()->GetNbEntities( SMDSAbs_Node );
1411           if ( !(presentEntities & SMESH_Actor::eEdges) && anActor->GetObject()->GetNbEntities( SMDSAbs_Edge ) )
1412             presentEntities = presentEntities | SMESH_Actor::eEdges;
1413           if ( !(presentEntities & SMESH_Actor::eFaces) && anActor->GetObject()->GetNbEntities( SMDSAbs_Face ) )
1414             presentEntities = presentEntities | SMESH_Actor::eFaces;
1415           if ( !(presentEntities & SMESH_Actor::eVolumes) && anActor->GetObject()->GetNbEntities( SMDSAbs_Volume ) )
1416             presentEntities = presentEntities | SMESH_Actor::eVolumes;
1417           if ( !(presentEntities & SMESH_Actor::e0DElements) && anActor->GetObject()->GetNbEntities( SMDSAbs_0DElement ) )
1418             presentEntities = presentEntities | SMESH_Actor::e0DElements;
1419           if ( !(presentEntities & SMESH_Actor::eBallElem) && anActor->GetObject()->GetNbEntities( SMDSAbs_Ball ) )
1420             presentEntities = presentEntities | SMESH_Actor::eBallElem;
1421           
1422           // as we know that all types of elements are present, we can exit the loop
1423           if ( presentEntities == SMESH_Actor::eAllEntity )
1424             break;
1425         }
1426
1427         SMESHGUI_PropertiesDlg dlg( theMarkerMap[ aStudy->StudyId() ], SMESHGUI::desktop() );
1428         // nodes: color, marker
1429         dlg.setNodeColor( nodeColor );
1430         if( markerType != VTK::MT_USER )
1431           dlg.setNodeMarker( markerType, markerScale );
1432         else
1433           dlg.setNodeCustomMarker( markerId );
1434         // edges: color, line width
1435         dlg.setEdgeColor( edgeColor );
1436         dlg.setEdgeWidth( edgeWidth );
1437         // faces: front color, back color
1438         dlg.setFaceColor( faceColor, deltaF );
1439         // volumes: normal color, reversed color
1440         dlg.setVolumeColor( volumeColor, deltaV );
1441         // outlines: color, line width
1442         dlg.setOutlineColor( outlineColor );
1443         dlg.setOutlineWidth( outlineWidth );
1444         // 0d elements: color, size
1445         dlg.setElem0dColor( elem0dColor );
1446         dlg.setElem0dSize( elem0dSize );
1447         // balls: color, size
1448         dlg.setBallColor( ballColor );
1449         //dlg.setBallSize( ballSize );
1450         dlg.setBallScale( ballScale );
1451         // orientation: color, scale, 3d flag
1452         dlg.setOrientationColor( orientationColor );
1453         dlg.setOrientationSize( int( orientationScale * 100. ) );
1454         dlg.setOrientation3d( orientation3d );
1455         // shrink: scale factor
1456         dlg.setShrinkCoef( int( shrinkCoef * 100. ) );
1457         // hide unused controls
1458         dlg.showControls( presentEntities, hasNodes );
1459         
1460         if ( dlg.exec() ) {
1461           nodeColor        = dlg.nodeColor();
1462           markerType       = dlg.nodeMarkerType();
1463           markerScale      = dlg.nodeMarkerScale();
1464           markerId         = dlg.nodeMarkerId();
1465           edgeColor        = dlg.edgeColor();
1466           edgeWidth        = dlg.edgeWidth();
1467           faceColor        = dlg.faceColor();
1468           deltaF           = dlg.faceColorDelta();
1469           volumeColor      = dlg.volumeColor();
1470           deltaV           = dlg.volumeColorDelta();
1471           outlineColor     = dlg.outlineColor();
1472           outlineWidth     = dlg.outlineWidth();
1473           elem0dColor      = dlg.elem0dColor();
1474           elem0dSize       = dlg.elem0dSize();
1475           ballColor        = dlg.ballColor();
1476          // ballSize         = dlg.ballSize();
1477           ballScale        = dlg.ballScale();
1478           orientationColor = dlg.orientationColor();
1479           orientationScale = dlg.orientationSize() / 100.;
1480           orientation3d    = dlg.orientation3d();
1481           shrinkCoef       = dlg.shrinkCoef() / 100.;
1482
1483           // store point markers map that might be changed by the user
1484           theMarkerMap[ aStudy->StudyId() ] = dlg.customMarkers();
1485
1486           // set properties from dialog box to the presentations
1487           SALOME_ListIteratorOfListIO It( selected );
1488           for ( ; It.More(); It.Next() ) {
1489             Handle(SALOME_InteractiveObject) IObject = It.Value();
1490             if ( !IObject->hasEntry() ) continue;
1491             SMESH_Actor* anActor = SMESH::FindActorByEntry( IObject->getEntry() );
1492             if ( !anActor ) continue;
1493             
1494             // nodes: color, marker
1495             anActor->SetNodeColor( nodeColor.redF(), nodeColor.greenF(), nodeColor.blueF() );
1496             if ( markerType != VTK::MT_USER ) {
1497               anActor->SetMarkerStd( markerType, markerScale );
1498             }
1499             else {
1500               const VTK::MarkerMap& markerMap = theMarkerMap[ aStudy->StudyId() ];
1501               VTK::MarkerMap::const_iterator iter = markerMap.find( markerId );
1502               if ( iter != markerMap.end() )
1503                 anActor->SetMarkerTexture( markerId, iter->second.second );
1504             }
1505             // volumes: normal color, reversed color (delta)
1506             anActor->SetVolumeColor( volumeColor.redF(), volumeColor.greenF(), volumeColor.blueF(), deltaV );
1507             // faces: front color, back color (delta)
1508             anActor->SetSufaceColor( faceColor.redF(), faceColor.greenF(), faceColor.blueF(), deltaF );
1509             // edges: color, width
1510             anActor->SetEdgeColor( edgeColor.redF(), edgeColor.greenF(), edgeColor.blueF() );
1511             anActor->SetLineWidth( edgeWidth );
1512             // outlines: color
1513             anActor->SetOutlineColor( outlineColor.redF(), outlineColor.greenF(), outlineColor.blueF() );
1514             anActor->SetOutlineWidth( outlineWidth );
1515             // 0D elements: color, size
1516             anActor->Set0DColor( elem0dColor.redF(), elem0dColor.greenF(), elem0dColor.blueF() );
1517             anActor->Set0DSize( elem0dSize );
1518             // balls: color, size
1519             anActor->SetBallColor( ballColor.redF(), ballColor.greenF(), ballColor.blueF() );
1520             // anActor->SetBallSize( ballSize );
1521             anActor->SetBallScale( ballScale );
1522             // orientation: color, scale, 3d flag
1523             anActor->SetFacesOrientationColor( orientationColor.redF(), orientationColor.greenF(), orientationColor.blueF() );
1524             anActor->SetFacesOrientationScale( orientationScale );
1525             anActor->SetFacesOrientation3DVectors( orientation3d );
1526             // shrink factor
1527             anActor->SetShrinkFactor( shrinkCoef );
1528
1529             // for groups, set also proper color
1530             SMESH::SMESH_GroupBase_var aGroupObject = SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IObject);
1531             if ( !aGroupObject->_is_nil() ) {
1532               SMESH::ElementType anElementType = aGroupObject->GetType();
1533               QColor aColor;
1534               switch( anElementType ) {
1535               case SMESH::NODE:
1536                 aColor = nodeColor; break;
1537               case SMESH::EDGE:
1538                 aColor = edgeColor; break;
1539               case SMESH::FACE: 
1540                 aColor = faceColor; break;
1541               case SMESH::VOLUME:
1542                 aColor = volumeColor; break;
1543               case SMESH::ELEM0D: 
1544                 aColor = elem0dColor; break;
1545               case SMESH::BALL: 
1546                 aColor = ballColor; break;
1547               default: break;
1548               }
1549               
1550               if ( aColor.isValid() ) {
1551                 SALOMEDS::Color aGroupColor;
1552                 aGroupColor.R = aColor.redF();
1553                 aGroupColor.G = aColor.greenF();
1554                 aGroupColor.B = aColor.blueF();
1555                 aGroupObject->SetColor( aGroupColor );
1556               }
1557             } // if ( !aGroupObject->_is_nil() )
1558           } // for ( ; It.More(); It.Next() )
1559           SMESH::RepaintCurrentView();
1560         } // if ( dlg.exec() )
1561         return;
1562       } // case SMESHOp::OpProperties:
1563       } // switch(theCommandID)
1564       SALOME_ListIteratorOfListIO It( selected );
1565       for( ; It.More(); It.Next()){
1566         Handle(SALOME_InteractiveObject) IObject = It.Value();
1567         if(IObject->hasEntry()){
1568           if(SMESH_Actor *anActor = SMESH::FindActorByEntry(IObject->getEntry())){
1569             switch(theCommandID){
1570             case SMESHOp::OpDMWireframe:
1571               anActor->SetRepresentation(SMESH_Actor::eEdge);
1572               break;
1573             case SMESHOp::OpDMShading:
1574               anActor->SetRepresentation(SMESH_Actor::eSurface);
1575               break;
1576             case SMESHOp::OpDMShrink:
1577               if(anActor->IsShrunk())
1578                 anActor->UnShrink();
1579               else
1580                 anActor->SetShrink();
1581               break;
1582             case SMESHOp::OpDMNodes:
1583               anActor->SetRepresentation(SMESH_Actor::ePoint);
1584               break;
1585             case SMESHOp::OpRepresentationLines:
1586               if(anActor->GetQuadratic2DRepresentation() != SMESH_Actor::eLines)
1587                 anActor->SetQuadratic2DRepresentation(SMESH_Actor::eLines);
1588               break;
1589             case SMESHOp::OpRepresentationArcs:
1590               if(anActor->GetQuadratic2DRepresentation() != SMESH_Actor::eArcs)
1591                 anActor->SetQuadratic2DRepresentation(SMESH_Actor::eArcs);
1592               break;
1593             }
1594           }
1595         }
1596       }
1597       SMESH::RepaintCurrentView();
1598     }
1599   }
1600
1601   int ActionToControl( int theID, bool theReversed )
1602   {
1603     NCollection_DoubleMap<int,int> ActionControl;
1604     ActionControl.Bind( 0,                                SMESH_Actor::eNone );
1605     ActionControl.Bind( SMESHOp::OpFreeNode,              SMESH_Actor::eFreeNodes );
1606     ActionControl.Bind( SMESHOp::OpEqualNode,             SMESH_Actor::eCoincidentNodes );
1607     ActionControl.Bind( SMESHOp::OpFreeEdge,              SMESH_Actor::eFreeEdges );
1608     ActionControl.Bind( SMESHOp::OpFreeBorder,            SMESH_Actor::eFreeBorders );
1609     ActionControl.Bind( SMESHOp::OpLength,                SMESH_Actor::eLength );
1610     ActionControl.Bind( SMESHOp::OpConnection,            SMESH_Actor::eMultiConnection );
1611     ActionControl.Bind( SMESHOp::OpEqualEdge,             SMESH_Actor::eCoincidentElems1D );
1612     ActionControl.Bind( SMESHOp::OpFreeFace,              SMESH_Actor::eFreeFaces );
1613     ActionControl.Bind( SMESHOp::OpBareBorderFace,        SMESH_Actor::eBareBorderFace );
1614     ActionControl.Bind( SMESHOp::OpOverConstrainedFace,   SMESH_Actor::eOverConstrainedFace );
1615     ActionControl.Bind( SMESHOp::OpLength2D,              SMESH_Actor::eLength2D );
1616     ActionControl.Bind( SMESHOp::OpConnection2D,          SMESH_Actor::eMultiConnection2D );
1617     ActionControl.Bind( SMESHOp::OpArea,                  SMESH_Actor::eArea );
1618     ActionControl.Bind( SMESHOp::OpTaper,                 SMESH_Actor::eTaper );
1619     ActionControl.Bind( SMESHOp::OpAspectRatio,           SMESH_Actor::eAspectRatio );
1620     ActionControl.Bind( SMESHOp::OpMinimumAngle,          SMESH_Actor::eMinimumAngle );
1621     ActionControl.Bind( SMESHOp::OpWarpingAngle,          SMESH_Actor::eWarping );
1622     ActionControl.Bind( SMESHOp::OpSkew,                  SMESH_Actor::eSkew );
1623     ActionControl.Bind( SMESHOp::OpMaxElementLength2D,    SMESH_Actor::eMaxElementLength2D );
1624     ActionControl.Bind( SMESHOp::OpEqualFace,             SMESH_Actor::eCoincidentElems2D );
1625     ActionControl.Bind( SMESHOp::OpAspectRatio3D,         SMESH_Actor::eAspectRatio3D );
1626     ActionControl.Bind( SMESHOp::OpVolume,                SMESH_Actor::eVolume3D );
1627     ActionControl.Bind( SMESHOp::OpMaxElementLength3D,    SMESH_Actor::eMaxElementLength3D );
1628     ActionControl.Bind( SMESHOp::OpBareBorderVolume,      SMESH_Actor::eBareBorderVolume );
1629     ActionControl.Bind( SMESHOp::OpOverConstrainedVolume, SMESH_Actor::eOverConstrainedVolume );
1630     ActionControl.Bind( SMESHOp::OpEqualVolume,           SMESH_Actor::eCoincidentElems3D );
1631
1632     return theReversed ? ActionControl.Find2( theID ) : ActionControl.Find1( theID );
1633   }
1634
1635   void Control( int theCommandID )
1636   {
1637     SMESH_Actor::eControl aControl = SMESH_Actor::eControl( ActionToControl( theCommandID ) );
1638     _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1639     LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1640     SALOME_ListIO selected;
1641     if ( aSel )
1642       aSel->selectedObjects( selected );
1643
1644     if ( !selected.IsEmpty() ) {
1645       SALOME_ListIteratorOfListIO It(selected);
1646       for ( ; It.More(); It.Next())
1647       {
1648         Handle(SALOME_InteractiveObject) anIO = It.Value();
1649         if(!anIO.IsNull()){
1650           _PTR(SObject) SO = aStudy->FindObjectID( It.Value()->getEntry() );
1651           if ( SO ) {
1652             CORBA::Object_var          aObject  = SMESH::SObjectToObject( SO );
1653             SMESH::SMESH_Mesh_var      aMesh    = SMESH::SMESH_Mesh::_narrow( aObject );
1654             SMESH::SMESH_subMesh_var   aSubMesh = SMESH::SMESH_subMesh::_narrow( aObject );
1655             SMESH::SMESH_GroupBase_var aGroup   = SMESH::SMESH_GroupBase::_narrow( aObject );
1656             if ( !aMesh->_is_nil() || !aSubMesh->_is_nil() || !aGroup->_is_nil() ) {
1657               if ( SMESH_Actor *anActor = SMESH::FindActorByEntry(anIO->getEntry()) ) {
1658                 anActor->SetControlMode(aControl);
1659                 anActor->GetScalarBarActor()->SetTitle( functorToString( anActor->GetFunctor() ).toLatin1().constData() );
1660                 SMESH::RepaintCurrentView();
1661 #ifndef DISABLE_PLOT2DVIEWER
1662                 if ( anActor->GetPlot2Histogram() ) {
1663                   SPlot2d_Histogram* aHistogram = anActor->UpdatePlot2Histogram();
1664                   QString functorName = functorToString( anActor->GetFunctor() );
1665                   QString aHistogramName("%1 : %2");
1666                   aHistogramName = aHistogramName.arg( anIO->getName() ).arg( functorName );
1667                   aHistogram->setName( aHistogramName );
1668                   aHistogram->setHorTitle( functorName );
1669                   SMESH::ProcessIn2DViewers( anActor );
1670                 }
1671 #endif
1672               }
1673             }
1674           }
1675         }
1676       }
1677     }
1678   }
1679
1680
1681   bool CheckOIType(const Handle(SALOME_InteractiveObject) & theIO,
1682                    SMESH::MeshObjectType                    theType,
1683                    const QString                            theInTypeName,
1684                    QString &                                theOutTypeName)
1685   {
1686     SMESH_TypeFilter aTypeFilter( theType );
1687     QString entry;
1688     if ( !theIO.IsNull() )
1689     {
1690       entry = theIO->getEntry();
1691       LightApp_DataOwner owner( entry );
1692       if ( aTypeFilter.isOk( &owner )) {
1693         theOutTypeName = theInTypeName;
1694         return true;
1695       }
1696     }
1697     return false;
1698   }
1699
1700
1701   QString CheckTypeObject(const Handle(SALOME_InteractiveObject) & theIO)
1702   {
1703     _PTR(Study)  aStudy = SMESH::GetActiveStudyDocument();
1704     _PTR(SObject) aSObj = aStudy->FindObjectID(theIO->getEntry());
1705     if (aSObj) {
1706       _PTR(SComponent) aSComp = aSObj->GetFatherComponent();
1707       CORBA::String_var  anID = aSComp->GetID().c_str();
1708       if ( !strcmp(anID.in(),theIO->getEntry()) )
1709         return "Component";
1710     }
1711
1712     QString aTypeName;
1713     if (
1714         CheckOIType ( theIO, SMESH::HYPOTHESIS,    "Hypothesis", aTypeName ) ||
1715         CheckOIType ( theIO, SMESH::ALGORITHM,     "Algorithm",  aTypeName ) ||
1716         CheckOIType ( theIO, SMESH::MESH,          "Mesh",       aTypeName ) ||
1717         CheckOIType ( theIO, SMESH::SUBMESH,       "SubMesh",    aTypeName ) ||
1718         CheckOIType ( theIO, SMESH::GROUP,         "Group",      aTypeName )
1719         )
1720       return aTypeName;
1721
1722     return "NoType";
1723   }
1724
1725
1726   QString CheckHomogeneousSelection()
1727   {
1728     LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1729     SALOME_ListIO selected;
1730     if ( aSel )
1731       aSel->selectedObjects( selected );
1732
1733     QString RefType = CheckTypeObject(selected.First());
1734     SALOME_ListIteratorOfListIO It(selected);
1735     for ( ; It.More(); It.Next())
1736     {
1737       Handle(SALOME_InteractiveObject) IObject = It.Value();
1738       QString Type = CheckTypeObject(IObject);
1739       if ( Type.compare(RefType) != 0 )
1740         return "Heterogeneous Selection";
1741     }
1742
1743     return RefType;
1744   }
1745
1746   uint randomize( uint size )
1747   {
1748     static bool initialized = false;
1749     if ( !initialized ) {
1750       qsrand( QDateTime::currentDateTime().toTime_t() );
1751       initialized = true;
1752     }
1753     uint v = qrand();
1754     v = uint( (double)( v ) / RAND_MAX * size );
1755     v = qMax( uint(0), qMin ( v, size-1 ) );
1756     return v;
1757   }
1758   
1759 } //namespace
1760
1761 void SMESHGUI::OnEditDelete()
1762 {
1763   // VSR 17/11/04: check if all objects selected belong to SMESH component --> start
1764   LightApp_SelectionMgr* aSel = SMESHGUI::selectionMgr();
1765   SALOME_ListIO selected; aSel->selectedObjects( selected, QString::null, false );
1766
1767   _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1768   _PTR(StudyBuilder) aStudyBuilder = aStudy->NewBuilder();
1769   _PTR(GenericAttribute) anAttr;
1770   _PTR(AttributeIOR) anIOR;
1771
1772   int objectCount = 0;
1773   QString aNameList;
1774   QString aParentComponent = QString::null;
1775   Handle(SALOME_InteractiveObject) anIO;
1776   for( SALOME_ListIteratorOfListIO anIt( selected ); anIt.More(); anIt.Next() )
1777   {
1778     anIO = anIt.Value();
1779     QString cur = anIO->getComponentDataType();
1780     _PTR(SObject) aSO = aStudy->FindObjectID(anIO->getEntry());
1781     if (aSO) {
1782       // check if object is reference
1783       _PTR(SObject) aRefSObj;
1784       aNameList.append("\n    - ");
1785       if ( aSO->ReferencedObject( aRefSObj ) ) {
1786         QString aRefName = QString::fromStdString ( aRefSObj->GetName() );
1787         aNameList.append( aRefName );
1788         cur = QString::fromStdString ( aRefSObj->GetFatherComponent()->ComponentDataType() );
1789       }
1790       else
1791         aNameList.append(anIO->getName());
1792       objectCount++;
1793     }
1794
1795     if( aParentComponent.isNull() )
1796       aParentComponent = cur;
1797     else if( !aParentComponent.isEmpty() && aParentComponent!=cur )
1798       aParentComponent = "";
1799   }
1800
1801   if ( objectCount == 0 )
1802     return; // No Valid Objects Selected
1803
1804   if ( aParentComponent != SMESHGUI::GetSMESHGUI()->name() )  {
1805     SUIT_MessageBox::warning( SMESHGUI::desktop(),
1806                               QObject::tr("ERR_ERROR"),
1807                               QObject::tr("NON_SMESH_OBJECTS_SELECTED").arg( SMESHGUI::GetSMESHGUI()->moduleName() ) );
1808     return;
1809   }
1810   // VSR 17/11/04: check if all objects selected belong to SMESH component <-- finish
1811   if (SUIT_MessageBox::warning
1812       (SMESHGUI::desktop(),
1813        QObject::tr("SMESH_WRN_WARNING"),
1814        QObject::tr("SMESH_REALLY_DELETE").arg( objectCount ).arg( aNameList ),
1815        SUIT_MessageBox::Yes | SUIT_MessageBox::No,
1816        SUIT_MessageBox::Yes) != SUIT_MessageBox::Yes)
1817     return;
1818
1819   SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
1820
1821   // Put the whole hierarchy of sub-objects of the selected SO's into a list and
1822   // then treat them all starting from the deepest objects (at list back)
1823   std::list< _PTR(SObject) > listSO;
1824   SALOME_ListIteratorOfListIO It(selected);
1825   for( ; It.More(); It.Next()) // loop on selected IO's
1826   {
1827     Handle(SALOME_InteractiveObject) IObject = It.Value();
1828     if(IObject->hasEntry()) {
1829       _PTR(SObject) aSO = aStudy->FindObjectID(IObject->getEntry());
1830
1831       // disable removal of "SMESH" component object
1832       if(aSO->FindAttribute(anAttr, "AttributeIOR")){
1833         anIOR = anAttr;
1834         if ( engineIOR() == anIOR->Value().c_str() )
1835           continue;
1836       }
1837       //Check the referenced object
1838       _PTR(SObject) aRefSObject;
1839       if ( aSO && aSO->ReferencedObject( aRefSObject ) )
1840         aSO = aRefSObject; // Delete main Object instead of reference
1841
1842       listSO.push_back( aSO );
1843       std::list< _PTR(SObject) >::iterator itSO = --listSO.end();
1844       for ( ; itSO != listSO.end(); ++itSO ) {
1845         _PTR(ChildIterator) it = aStudy->NewChildIterator( *itSO );
1846         for (it->InitEx(false); it->More(); it->Next())
1847           listSO.push_back( it->Value() );
1848       }
1849     }
1850   }
1851   // Check if none of objects to delete is referred from outside
1852   std::list< _PTR(SObject) >::reverse_iterator ritSO;
1853   for ( ritSO = listSO.rbegin(); ritSO != listSO.rend(); ++ritSO )
1854   {
1855     _PTR(SObject) SO = *ritSO;
1856     if ( !SO ) continue;
1857     std::vector<_PTR(SObject)> aReferences = aStudy->FindDependances( *ritSO  );
1858     for (size_t i = 0; i < aReferences.size(); i++) {
1859       _PTR(SComponent) aComponent = aReferences[i]->GetFatherComponent();
1860       std::string type = aComponent->ComponentDataType();
1861       if ( type != "SMESH" )
1862       {
1863         SUIT_MessageBox::warning( anApp->desktop(),
1864                                   QObject::tr("WRN_WARNING"),
1865                                   QObject::tr("DEP_OBJECT") );
1866         return; // outside SMESH, there is an object depending on a SMESH object
1867       }
1868     }
1869   }
1870
1871   // Call mesh->Clear() to prevent loading mesh from file caused by hypotheses removal
1872   for( It.Initialize( selected ); It.More(); It.Next()) // loop on selected IO's
1873   {
1874     Handle(SALOME_InteractiveObject) IObject = It.Value();
1875     SMESH::SMESH_Mesh_var mesh = SMESH::IObjectToInterface< SMESH::SMESH_Mesh >( IObject );
1876     if ( !mesh->_is_nil() )
1877       mesh->Clear();
1878   }
1879
1880   // Treat SO's in the list starting from the back
1881   aStudyBuilder->NewCommand();  // There is a transaction
1882   for ( ritSO = listSO.rbegin(); ritSO != listSO.rend(); ++ritSO )
1883   {
1884     _PTR(SObject) SO = *ritSO;
1885     if ( !SO ) continue;
1886     std::string anEntry = SO->GetID();
1887
1888     /** Erase graphical object and remove all its data **/
1889     if(SO->FindAttribute(anAttr, "AttributeIOR")) {
1890       SMESH::RemoveVisualObjectWithActors( anEntry.c_str(), true);
1891     }
1892     /** Remove an object from data structures **/
1893     SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow( SMESH::SObjectToObject( SO ));
1894     SMESH::SMESH_subMesh_var   aSubMesh = SMESH::SMESH_subMesh::_narrow( SMESH::SObjectToObject( SO ));
1895     if ( !aGroup->_is_nil() ) {                          // DELETE GROUP
1896       SMESH::SMESH_Mesh_var aMesh = aGroup->GetMesh();
1897       aMesh->RemoveGroup( aGroup );
1898     }
1899     else if ( !aSubMesh->_is_nil() ) {                   // DELETE SUBMESH
1900       SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
1901       aMesh->RemoveSubMesh( aSubMesh );
1902
1903       _PTR(SObject) aMeshSO = SMESH::FindSObject(aMesh);
1904       if (aMeshSO)
1905         SMESH::ModifiedMesh(aMeshSO, false, aMesh->NbNodes()==0);
1906     }
1907     else {
1908       Handle(SALOME_InteractiveObject) IObject = new SALOME_InteractiveObject
1909         ( anEntry.c_str(), engineIOR().toLatin1().data(), SO->GetName().c_str() );
1910       QString objType = CheckTypeObject(IObject);
1911       if ( objType == "Hypothesis" || objType == "Algorithm" ) {// DELETE HYPOTHESIS
1912         SMESH::RemoveHypothesisOrAlgorithmOnMesh(IObject);
1913         aStudyBuilder->RemoveObjectWithChildren( SO );
1914       }
1915       else {// default action: remove SObject from the study
1916         // san - it's no use opening a transaction here until UNDO/REDO is provided in SMESH
1917         //SUIT_Operation *op = new SALOMEGUI_ImportOperation(myActiveStudy);
1918         //op->start();
1919         aStudyBuilder->RemoveObjectWithChildren( SO );
1920         //op->finish();
1921       }
1922     }
1923   } /* listSO back loop */
1924
1925   aStudyBuilder->CommitCommand();
1926
1927   /* Clear any previous selection */
1928   SALOME_ListIO l1;
1929   aSel->setSelectedObjects( l1 );
1930
1931   SMESHGUI::GetSMESHGUI()->updateObjBrowser();
1932 }
1933
1934 extern "C" {
1935   SMESHGUI_EXPORT CAM_Module* createModule()
1936   {
1937     return new SMESHGUI();
1938   }
1939
1940   SMESHGUI_EXPORT  char* getModuleVersion() {
1941     return (char*)SMESH_VERSION_STR;
1942   }
1943 }
1944
1945 SMESH::SMESH_Gen_var SMESHGUI::myComponentSMESH = SMESH::SMESH_Gen::_nil();
1946
1947 //=============================================================================
1948 /*!
1949  *
1950  */
1951 //=============================================================================
1952 SMESHGUI::SMESHGUI() :
1953 SalomeApp_Module( "SMESH" )
1954 {
1955   if ( CORBA::is_nil( myComponentSMESH ) )
1956   {
1957     CORBA::Boolean anIsEmbeddedMode;
1958     myComponentSMESH = SMESH_Client::GetSMESHGen(getApp()->orb(),anIsEmbeddedMode);
1959     MESSAGE("-------------------------------> anIsEmbeddedMode=" << anIsEmbeddedMode);
1960
1961     //  0019923: EDF 765 SMESH : default values of hypothesis
1962     SUIT_ResourceMgr* aResourceMgr = SMESH::GetResourceMgr(this);
1963     int nbSeg = aResourceMgr->integerValue( "SMESH", "segmentation", 10 );
1964     myComponentSMESH->SetBoundaryBoxSegmentation( nbSeg );
1965     nbSeg = aResourceMgr->integerValue( "SMESH", "nb_segments_per_edge", 15 );
1966     myComponentSMESH->SetDefaultNbSegments( nbSeg );
1967
1968     const char* options[] = { "historical_python_dump", "forget_mesh_on_hyp_modif", "default_grp_color" };
1969     for ( size_t i = 0; i < sizeof(options)/sizeof(char*); ++i )
1970       if ( aResourceMgr->hasValue( "SMESH", options[i] ))
1971       {
1972         QString val = aResourceMgr->stringValue( "SMESH", options[i] );
1973         myComponentSMESH->SetOption( options[i], val.toLatin1().constData() );
1974       }
1975   }
1976
1977   myActiveDialogBox = 0;
1978   myFilterLibraryDlg = 0;
1979   myState = -1;
1980   myDisplayer = 0;
1981
1982   myEventCallbackCommand = vtkCallbackCommand::New();
1983   myEventCallbackCommand->Delete();
1984   myEventCallbackCommand->SetClientData( this );
1985   myEventCallbackCommand->SetCallback( SMESHGUI::ProcessEvents );
1986   myPriority = 0.0;
1987
1988   /* load resources for all available meshers */
1989   SMESH::InitAvailableHypotheses();
1990 }
1991
1992 //=============================================================================
1993 /*!
1994  *
1995  */
1996 //=============================================================================
1997 SMESHGUI::~SMESHGUI()
1998 {
1999 }
2000
2001 //=============================================================================
2002 /*!
2003  *
2004  */
2005 //=============================================================================
2006 LightApp_SelectionMgr* SMESHGUI::selectionMgr()
2007 {
2008   SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
2009   if( anApp )
2010     return dynamic_cast<LightApp_SelectionMgr*>( anApp->selectionMgr() );
2011   else
2012     return 0;
2013 }
2014
2015 //=============================================================================
2016 /*!
2017  *
2018  */
2019 //=============================================================================
2020 bool SMESHGUI::automaticUpdate(unsigned int requestedSize, bool* limitExceeded)
2021 {
2022   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2023   if ( !resMgr )
2024     return false;
2025
2026   bool autoUpdate  = resMgr->booleanValue( "SMESH", "auto_update",  false );
2027   long updateLimit = resMgr->integerValue( "SMESH", "update_limit", 500000 );
2028   bool exceeded = updateLimit > 0 && requestedSize > updateLimit;
2029   if ( limitExceeded ) *limitExceeded = autoUpdate && exceeded;
2030   return autoUpdate && !exceeded;
2031 }
2032
2033 //=============================================================================
2034 /*!
2035  *
2036  */
2037 //=============================================================================
2038 bool SMESHGUI::automaticUpdate( SMESH::SMESH_IDSource_ptr theMesh,
2039                                 int* entities, bool* limitExceeded, int* hidden, long* nbElements )
2040 {
2041   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2042   if ( !resMgr )
2043     return false;
2044
2045   bool autoUpdate  = resMgr->booleanValue( "SMESH", "auto_update", false );
2046   long updateLimit = resMgr->integerValue( "SMESH", "update_limit", 500000 );
2047   bool incrementalLimit = resMgr->booleanValue( "SMESH", "incremental_limit", false );
2048
2049   SMESH::long_array_var info = theMesh->GetMeshInfo();
2050   long nbOdElems = info[SMDSEntity_0D];
2051   long nbEdges   = info[SMDSEntity_Edge] + info[SMDSEntity_Quad_Edge];
2052   long nbFaces   = info[SMDSEntity_Triangle]   + info[SMDSEntity_Quad_Triangle]   + info[SMDSEntity_BiQuad_Triangle] + 
2053                    info[SMDSEntity_Quadrangle] + info[SMDSEntity_Quad_Quadrangle] + info[SMDSEntity_BiQuad_Quadrangle] + 
2054                    info[SMDSEntity_Polygon] + info[SMDSEntity_Quad_Polygon];
2055   long nbVolumes = info[SMDSEntity_Tetra]   + info[SMDSEntity_Quad_Tetra] + 
2056                    info[SMDSEntity_Hexa]    + info[SMDSEntity_Quad_Hexa] + info[SMDSEntity_TriQuad_Hexa] + 
2057                    info[SMDSEntity_Pyramid] + info[SMDSEntity_Quad_Pyramid] + 
2058                    info[SMDSEntity_Penta]   + info[SMDSEntity_Quad_Penta] + 
2059                    info[SMDSEntity_Polyhedra] + 
2060                    info[SMDSEntity_Hexagonal_Prism];
2061   long nbBalls   = info[SMDSEntity_Ball];
2062
2063   long requestedSize = nbOdElems + nbBalls + nbEdges + nbFaces + nbVolumes;
2064   *nbElements = requestedSize;
2065   
2066   *entities = SMESH_Actor::eAllEntity;
2067   *hidden   = 0;
2068
2069   bool exceeded = updateLimit > 0 && requestedSize > updateLimit;
2070
2071   if ( limitExceeded ) *limitExceeded = autoUpdate && exceeded;
2072
2073   if ( incrementalLimit ) {
2074     long total     = 0;
2075
2076     if ( nbOdElems > 0 ) {
2077       if ( total + nbOdElems > updateLimit ) {
2078         *entities = *entities & ~SMESH_Actor::e0DElements;
2079         *hidden = *hidden | SMESH_Actor::e0DElements;
2080       }
2081       else
2082         exceeded = false;
2083     }
2084     total += nbOdElems;
2085
2086     if ( nbEdges > 0 ) {
2087       if ( total + nbEdges > updateLimit ) {
2088         *entities = *entities & ~SMESH_Actor::eEdges;
2089         *hidden = *hidden | SMESH_Actor::eEdges;
2090       }
2091       else
2092         exceeded = false;
2093     }
2094     total += nbEdges;
2095
2096     if ( nbFaces > 0 ) {
2097       if ( total + nbFaces > updateLimit ) {
2098         *entities = *entities & ~SMESH_Actor::eFaces;
2099         *hidden = *hidden | SMESH_Actor::eFaces;
2100       }
2101       else
2102         exceeded = false;
2103     }
2104     total += nbFaces;
2105
2106     if ( nbVolumes > 0 ) {
2107       if ( total + nbVolumes > updateLimit ) {
2108         *entities = *entities & ~SMESH_Actor::eVolumes;
2109         *hidden = *hidden | SMESH_Actor::eVolumes;
2110       }
2111       else
2112         exceeded = false;
2113     }
2114     total += nbVolumes;
2115
2116     if ( nbBalls > 0 ) {
2117       if ( total + nbBalls > updateLimit ) {
2118         *entities = *entities & ~SMESH_Actor::eBallElem;
2119         *hidden = *hidden | SMESH_Actor::eBallElem;
2120       }
2121       else
2122         exceeded = false;
2123     }
2124     total += nbBalls;
2125   }
2126
2127   return autoUpdate && !exceeded;
2128 }
2129
2130 //=============================================================================
2131 /*!
2132  *
2133  */
2134 //=============================================================================
2135 SUIT_ResourceMgr* SMESHGUI::resourceMgr()
2136 {
2137   return dynamic_cast<SUIT_ResourceMgr*>( SUIT_Session::session()->resourceMgr() );
2138 }
2139
2140 //=============================================================================
2141 /*!
2142  *
2143  */
2144 //=============================================================================
2145 SMESHGUI* SMESHGUI::GetSMESHGUI()
2146 {
2147   SMESHGUI* smeshMod = 0;
2148   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>(SUIT_Session::session()->activeApplication());
2149   if ( app )
2150   {
2151     CAM_Module* module = app->module( "Mesh" );
2152     smeshMod = dynamic_cast<SMESHGUI*>( module );
2153   }
2154
2155   if ( smeshMod && smeshMod->application() && smeshMod->application()->activeStudy() )
2156   {
2157     SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( smeshMod->application()->activeStudy() );
2158     if ( study )
2159     {
2160       _PTR(Study) aStudy = study->studyDS();
2161       if ( aStudy )
2162         GetSMESHGen()->SetCurrentStudy( _CAST(Study,aStudy)->GetStudy() );
2163     }
2164   }
2165
2166   return smeshMod;
2167 }
2168
2169 extern "C"
2170 {
2171   Standard_EXPORT SMESHGUI* GetComponentGUI()
2172   {
2173     return SMESHGUI::GetSMESHGUI();
2174   }
2175 }
2176
2177 //=============================================================================
2178 /*!
2179  *
2180  */
2181 //=============================================================================
2182 void SMESHGUI::SetState(int aState)
2183 {
2184   myState = aState;
2185 }
2186
2187 //=============================================================================
2188 /*!
2189  *
2190  */
2191 //=============================================================================
2192 void SMESHGUI::ResetState()
2193 {
2194   myState = -1;
2195 }
2196
2197 //=============================================================================
2198 /*!
2199  *
2200  */
2201 //=============================================================================
2202 void SMESHGUI::EmitSignalDeactivateDialog()
2203 {
2204   emit SignalDeactivateActiveDialog();
2205 }
2206
2207 //=============================================================================
2208 /*!
2209  *
2210  */
2211 //=============================================================================
2212 void SMESHGUI::EmitSignalStudyFrameChanged()
2213 {
2214   emit SignalStudyFrameChanged();
2215 }
2216
2217 //=============================================================================
2218 /*!
2219  *
2220  */
2221 //=============================================================================
2222 void SMESHGUI::EmitSignalCloseAllDialogs()
2223 {
2224   emit SignalCloseAllDialogs();
2225 }
2226
2227 //=============================================================================
2228 /*!
2229  *
2230  */
2231 //=============================================================================
2232 void SMESHGUI::EmitSignalVisibilityChanged()
2233 {
2234   emit SignalVisibilityChanged();
2235 }
2236
2237 //=============================================================================
2238 /*!
2239  *
2240  */
2241 //=============================================================================
2242 void SMESHGUI::EmitSignalCloseView()
2243 {
2244   emit SignalCloseView();
2245 }
2246
2247 //=============================================================================
2248 /*!
2249  *
2250  */
2251 //=============================================================================
2252 void SMESHGUI::EmitSignalActivatedViewManager()
2253 {
2254   emit SignalActivatedViewManager();
2255 }
2256
2257 //=============================================================================
2258 /*!
2259  *
2260  */
2261 //=============================================================================
2262 QDialog *SMESHGUI::GetActiveDialogBox()
2263 {
2264   return myActiveDialogBox;
2265 }
2266
2267 //=============================================================================
2268 /*!
2269  *
2270  */
2271 //=============================================================================
2272 void SMESHGUI::SetActiveDialogBox(QDialog * aDlg)
2273 {
2274   myActiveDialogBox = (QDialog *) aDlg;
2275   return;
2276 }
2277
2278 //=============================================================================
2279 /*!
2280  *
2281  */
2282 //=============================================================================
2283 SUIT_Desktop* SMESHGUI::desktop()
2284 {
2285   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
2286   if( app )
2287     return app->desktop();
2288   else
2289     return 0;
2290 }
2291
2292 //=============================================================================
2293 /*!
2294  *
2295  */
2296 //=============================================================================
2297 SalomeApp_Study* SMESHGUI::activeStudy()
2298 {
2299   SUIT_Application* app = SUIT_Session::session()->activeApplication();
2300   if( app )
2301     return dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2302   else
2303     return NULL;
2304 }
2305
2306 //=============================================================================
2307 /*!
2308  *
2309  */
2310 //=============================================================================
2311 void SMESHGUI::Modified( bool theIsUpdateActions )
2312 {
2313   if( SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() ) ) {
2314     if( SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() ) ) {
2315       appStudy->Modified();
2316       if( theIsUpdateActions )
2317         app->updateActions();
2318     }
2319   }
2320 }
2321
2322 //=============================================================================
2323 /*!
2324  *
2325  */
2326 //=============================================================================
2327 bool SMESHGUI::DefineDlgPosition(QWidget * aDlg, int &x, int &y)
2328 {
2329   /* Here the position is on the bottom right corner - 10 */
2330   // aDlg->resize(QSize().expandedTo(aDlg->minimumSizeHint()));
2331   aDlg->adjustSize();
2332   SUIT_Desktop *PP = desktop();
2333   x = abs(PP->x() + PP->size().width() - aDlg->size().width() - 10);
2334   y = abs(PP->y() + PP->size().height() - aDlg->size().height() - 10);
2335   return true;
2336 }
2337
2338 //=============================================================================
2339 /*!
2340  *
2341  */
2342 //=============================================================================
2343 static int isStudyLocked(_PTR(Study) theStudy){
2344   return theStudy->GetProperties()->IsLocked();
2345 }
2346
2347 static bool checkLock(_PTR(Study) theStudy) {
2348   if (isStudyLocked(theStudy)) {
2349     SUIT_MessageBox::warning( SMESHGUI::desktop(),
2350                               QObject::tr("WRN_WARNING"),
2351                               QObject::tr("WRN_STUDY_LOCKED") );
2352     return true;
2353   }
2354   return false;
2355 }
2356
2357 //=======================================================================
2358 //function : CheckActiveStudyLocked
2359 //purpose  :
2360 //=======================================================================
2361
2362 bool SMESHGUI::isActiveStudyLocked()
2363 {
2364   _PTR(Study) aStudy = activeStudy()->studyDS();
2365   return checkLock( aStudy );
2366 }
2367
2368 //=============================================================================
2369 /*!
2370  *
2371  */
2372 //=============================================================================
2373 bool SMESHGUI::OnGUIEvent( int theCommandID )
2374 {
2375   SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( application() );
2376   if( !anApp )
2377     return false;
2378
2379   _PTR(Study) aStudy = SMESH::GetActiveStudyDocument(); //Document OCAF de l'etude active
2380   SUIT_ResourceMgr* mgr = resourceMgr();
2381   if( !mgr )
2382     return false;
2383
2384   if (CORBA::is_nil(GetSMESHGen()->GetCurrentStudy())) {
2385     GetSMESHGen()->SetCurrentStudy(_CAST(Study,aStudy)->GetStudy());
2386   }
2387
2388   SUIT_ViewWindow* view = application()->desktop()->activeWindow();
2389   SVTK_ViewWindow* vtkwnd = dynamic_cast<SVTK_ViewWindow*>( view );
2390
2391   //QAction* act = action( theCommandID );
2392
2393   switch (theCommandID) {
2394   case SMESHOp::OpDelete:
2395     if(checkLock(aStudy)) break;
2396     OnEditDelete();
2397     break;
2398   case SMESHOp::OpImportDAT:
2399   case SMESHOp::OpImportUNV:
2400   case SMESHOp::OpImportMED:
2401   case SMESHOp::OpImportSTL:
2402 #ifdef WITH_CGNS
2403   case SMESHOp::OpImportCGNS:
2404 #endif
2405   case SMESHOp::OpImportSAUV:
2406   case SMESHOp::OpImportGMF:
2407     {
2408       if(checkLock(aStudy)) break;
2409       ::ImportMeshesFromFile(GetSMESHGen(),theCommandID);
2410       break;
2411     }
2412
2413   case SMESHOp::OpFileInformation:
2414     {
2415       SALOME_ListIO selected;
2416       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2417       if( aSel )
2418         aSel->selectedObjects( selected );
2419       if( selected.Extent() )
2420       {
2421         Handle(SALOME_InteractiveObject) anIObject = selected.First();
2422         SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIObject);
2423         if ( !aMesh->_is_nil() )
2424         {
2425           SMESHGUI_FileInfoDlg dlg( desktop(), aMesh->GetMEDFileInfo() );
2426           dlg.exec();
2427         }
2428       }
2429       break;
2430     }
2431   case SMESHOp::OpExportDAT:
2432   case SMESHOp::OpExportMED:
2433   case SMESHOp::OpExportUNV:
2434   case SMESHOp::OpExportSTL:
2435 #ifdef WITH_CGNS
2436   case SMESHOp::OpExportCGNS:
2437 #endif
2438   case SMESHOp::OpExportSAUV:
2439   case SMESHOp::OpExportGMF:
2440   case SMESHOp::OpPopupExportDAT:
2441   case SMESHOp::OpPopupExportMED:
2442   case SMESHOp::OpPopupExportUNV:
2443   case SMESHOp::OpPopupExportSTL:
2444 #ifdef WITH_CGNS
2445   case SMESHOp::OpPopupExportCGNS:
2446 #endif
2447   case SMESHOp::OpPopupExportSAUV:
2448   case SMESHOp::OpPopupExportGMF:
2449     {
2450       ::ExportMeshToFile(theCommandID);
2451       break;
2452     }
2453
2454   case SMESHOp::OpReset:                      // SCALAR BAR
2455     {
2456       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2457       SALOME_ListIO selected;
2458       if( aSel )
2459         aSel->selectedObjects( selected );
2460
2461       SALOME_ListIteratorOfListIO it(selected);
2462       for( ; it.More(); it.Next()) {
2463         Handle(SALOME_InteractiveObject) anIO = it.Value();
2464         if( anIO->hasEntry() ) {
2465           if( SMESH_Actor* anActor = SMESH::FindActorByEntry( anIO->getEntry() ) ) {
2466             anActor->SetControlMode( SMESH_Actor::eNone );
2467 #ifndef DISABLE_PLOT2DVIEWER
2468             SMESH::ProcessIn2DViewers(anActor,SMESH::RemoveFrom2dViewer);
2469 #endif
2470           }
2471         }
2472       }
2473       SMESH::UpdateView();
2474       break;
2475     }
2476   case SMESHOp::OpScalarBarProperties:
2477     {
2478       SMESHGUI_Preferences_ScalarBarDlg::ScalarBarProperties( this );
2479       break;
2480     }
2481   case SMESHOp::OpShowScalarBar:
2482     {
2483       // show/hide scalar bar
2484       ::ShowElement(theCommandID);
2485       break;
2486     }
2487   case SMESHOp::OpSaveDistribution:
2488     {
2489       // dump control distribution data to the text file
2490       ::SaveDistribution();
2491       break;
2492     }
2493
2494   case SMESHOp::OpShowDistribution:
2495     {
2496       // show/hide distribution
2497       ::ShowElement(theCommandID);
2498       break;
2499     }
2500
2501 #ifndef DISABLE_PLOT2DVIEWER
2502   case SMESHOp::OpPlotDistribution:
2503     {
2504       // plot distribution
2505       ::PlotDistribution();
2506       break;
2507     }
2508 #endif
2509
2510     // Auto-color
2511   case SMESHOp::OpAutoColor:
2512     ::AutoColor();
2513   break;
2514
2515   case SMESHOp::OpDisableAutoColor:
2516     ::DisableAutoColor();
2517   break;
2518
2519   case SMESHOp::OpClipping:
2520   case SMESHOp::OpTransparency:
2521   case SMESHOp::OpProperties: // Display preferences (colors, shrink size, line width, ...)
2522
2523     // Display Mode
2524   case SMESHOp::OpDMWireframe:
2525   case SMESHOp::OpDMShading:
2526   case SMESHOp::OpDMNodes:
2527   case SMESHOp::OpDMShrink:
2528     ::SetDisplayMode(theCommandID, myMarkerMap);
2529   break;
2530
2531   //2D quadratic representation
2532   case SMESHOp::OpRepresentationLines:
2533   case SMESHOp::OpRepresentationArcs:
2534     ::SetDisplayMode(theCommandID, myMarkerMap);
2535   break;
2536
2537   // Display Entity
2538   case SMESHOp::OpDE0DElements:
2539   case SMESHOp::OpDEEdges:
2540   case SMESHOp::OpDEFaces:
2541   case SMESHOp::OpDEVolumes:
2542   case SMESHOp::OpDEBalls:
2543   case SMESHOp::OpDEAllEntity:
2544     ::SetDisplayEntity(theCommandID);
2545   break;
2546
2547   // Choose entities to be displayed
2548   case SMESHOp::OpDEChoose:
2549     {
2550       ( new SMESHGUI_DisplayEntitiesDlg( SMESHGUI::desktop() ) )->exec();
2551       break;
2552     }
2553
2554   case SMESHOp::OpOrientationOnFaces:
2555     {
2556       LightApp_SelectionMgr* mgr = selectionMgr();
2557       SALOME_ListIO selected; mgr->selectedObjects( selected );
2558
2559       SALOME_ListIteratorOfListIO it(selected);
2560       for( ; it.More(); it.Next()) {
2561         Handle(SALOME_InteractiveObject) anIObject = it.Value();
2562         if(anIObject->hasEntry()) {
2563           if(SMESH_Actor *anActor = SMESH::FindActorByEntry(anIObject->getEntry())){
2564             anActor->SetFacesOriented( !anActor->GetFacesOriented() );
2565           }
2566         }
2567       }
2568       break;
2569     }
2570
2571   case SMESHOp::OpUpdate:
2572     {
2573       if(checkLock(aStudy)) break;
2574       SUIT_OverrideCursor wc;
2575       try {
2576 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
2577         OCC_CATCH_SIGNALS;
2578 #endif
2579         SMESH::UpdateView();
2580       }
2581       catch (std::bad_alloc) { // PAL16774 (Crash after display of many groups)
2582         SMESH::OnVisuException();
2583       }
2584       catch (...) { // PAL16774 (Crash after display of many groups)
2585         SMESH::OnVisuException();
2586       }
2587
2588       SALOME_ListIO l;
2589       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2590       aSel->selectedObjects( l );
2591       aSel->setSelectedObjects( l );
2592       break;
2593     }
2594
2595   case SMESHOp::OpHide:
2596   case SMESHOp::OpShow:
2597   case SMESHOp::OpShowOnly:
2598     {
2599       SMESH::EDisplaing anAction;
2600       switch (theCommandID) {
2601       case SMESHOp::OpHide:     anAction = SMESH::eErase; break;
2602       case SMESHOp::OpShow:     anAction = SMESH::eDisplay; break;
2603       case SMESHOp::OpShowOnly: anAction = SMESH::eDisplayOnly; break;
2604       }
2605
2606       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2607       SALOME_ListIO sel_objects, to_process;
2608       if (aSel)
2609         aSel->selectedObjects( sel_objects );
2610
2611       if ( theCommandID==SMESHOp::OpShowOnly )
2612       {
2613         MESSAGE("anAction = SMESH::eDisplayOnly");
2614         startOperation( myEraseAll );
2615       }
2616
2617       extractContainers( sel_objects, to_process );
2618
2619       try {
2620 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
2621         OCC_CATCH_SIGNALS;
2622 #endif
2623         if (vtkwnd) {
2624           SALOME_ListIteratorOfListIO It( to_process );
2625           for ( ; It.More(); It.Next())
2626           {
2627             Handle(SALOME_InteractiveObject) IOS = It.Value();
2628             if ( IOS->hasEntry() )
2629             {
2630               if ( !SMESH::UpdateView( anAction, IOS->getEntry() )) {
2631                 SMESHGUI::GetSMESHGUI()->EmitSignalVisibilityChanged();
2632                 break; // PAL16774 (Crash after display of many groups)
2633               }
2634               if (anAction == SMESH::eDisplayOnly)
2635                 anAction = SMESH::eDisplay;
2636             }
2637           }
2638         }
2639
2640         // PAL13338 + PAL15161 -->
2641         if ( ( theCommandID==SMESHOp::OpShow || theCommandID==SMESHOp::OpShowOnly ) && !checkLock(aStudy)) {
2642           MESSAGE("anAction = SMESH::eDisplayOnly");
2643           SMESH::UpdateView();
2644           SMESHGUI::GetSMESHGUI()->EmitSignalVisibilityChanged();
2645         }
2646         // PAL13338 + PAL15161 <--
2647       }
2648       catch (...) { // PAL16774 (Crash after display of many groups)
2649         SMESH::OnVisuException();
2650       }
2651
2652       if (anAction == SMESH::eErase) {
2653         MESSAGE("anAction == SMESH::eErase");
2654         SALOME_ListIO l1;
2655         aSel->setSelectedObjects( l1 );
2656       }
2657       else
2658         aSel->setSelectedObjects( to_process );
2659
2660       break;
2661     }
2662
2663   case SMESHOp::OpNode:
2664     {
2665       if(checkLock(aStudy)) break;
2666
2667       if ( vtkwnd ) {
2668         EmitSignalDeactivateDialog();
2669
2670         ( new SMESHGUI_NodesDlg( this ) )->show();
2671       }
2672       else {
2673         SUIT_MessageBox::warning(desktop(),
2674                                  tr("SMESH_WRN_WARNING"),
2675                                  tr("SMESH_WRN_VIEWER_VTK"));
2676       }
2677       break;
2678     }
2679
2680   case SMESHOp::OpCreateMesh:
2681   case SMESHOp::OpCreateSubMesh:
2682   case SMESHOp::OpEditMeshOrSubMesh:
2683   case SMESHOp::OpCompute:
2684   case SMESHOp::OpPreCompute:
2685   case SMESHOp::OpEvaluate:
2686   case SMESHOp::OpMeshOrder:
2687     startOperation( theCommandID );
2688     break;
2689   case SMESHOp::OpCopyMesh:
2690     {
2691       if (checkLock(aStudy)) break;
2692       EmitSignalDeactivateDialog();
2693       ( new SMESHGUI_CopyMeshDlg( this ) )->show();
2694     }
2695     break;
2696   case SMESHOp::OpBuildCompoundMesh:
2697     {
2698       if (checkLock(aStudy)) break;
2699       EmitSignalDeactivateDialog();
2700       ( new SMESHGUI_BuildCompoundDlg( this ) )->show();
2701     }
2702     break;
2703
2704   case SMESHOp::OpDiagonalInversion:
2705   case SMESHOp::OpUnionOfTwoTriangle:
2706     {
2707       if ( !vtkwnd )
2708       {
2709         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),
2710                                   tr( "NOT_A_VTK_VIEWER" ) );
2711         break;
2712       }
2713
2714       if ( checkLock( aStudy ) )
2715         break;
2716
2717       /*Standard_Boolean aRes;
2718       SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IObject);
2719       if ( aMesh->_is_nil() )
2720       {
2721         SUIT_MessageBox::warning(GetDesktop(), tr( "SMESH_WRN_WARNING" ),
2722           tr( "SMESH_BAD_SELECTION" ) );
2723         break;
2724       }
2725       */
2726       EmitSignalDeactivateDialog();
2727       if ( theCommandID == SMESHOp::OpDiagonalInversion )
2728         ( new SMESHGUI_TrianglesInversionDlg( this ) )->show();
2729       else
2730         ( new SMESHGUI_UnionOfTwoTrianglesDlg( this ) )->show();
2731       break;
2732     }
2733   case SMESHOp::OpOrientation:
2734   case SMESHOp::OpUnionOfTriangles:
2735   case SMESHOp::OpCuttingOfQuadrangles:
2736   case SMESHOp::OpSplitVolumes:
2737     {
2738       if ( !vtkwnd )
2739       {
2740         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),
2741                                   tr( "NOT_A_VTK_VIEWER" ) );
2742         break;
2743       }
2744
2745       if ( checkLock( aStudy ) )
2746         break;
2747
2748       EmitSignalDeactivateDialog();
2749       SMESHGUI_MultiEditDlg* aDlg = NULL;
2750       if ( theCommandID == SMESHOp::OpOrientation )
2751         aDlg = new SMESHGUI_ChangeOrientationDlg(this);
2752       else if ( theCommandID == SMESHOp::OpUnionOfTriangles )
2753         aDlg = new SMESHGUI_UnionOfTrianglesDlg(this);
2754       else if ( theCommandID == SMESHOp::OpSplitVolumes )
2755         aDlg = new SMESHGUI_SplitVolumesDlg(this);
2756       else
2757         aDlg = new SMESHGUI_CuttingOfQuadsDlg(this);
2758
2759       aDlg->show();
2760       break;
2761     }
2762   case SMESHOp::OpSmoothing:
2763     {
2764       if(checkLock(aStudy)) break;
2765       if( vtkwnd ) {
2766         EmitSignalDeactivateDialog();
2767         ( new SMESHGUI_SmoothingDlg( this ) )->show();
2768       }
2769       else {
2770         SUIT_MessageBox::warning(desktop(),
2771                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2772       }
2773       break;
2774     }
2775   case SMESHOp::OpExtrusion:
2776     {
2777       if (checkLock(aStudy)) break;
2778       if (vtkwnd) {
2779         EmitSignalDeactivateDialog();
2780         ( new SMESHGUI_ExtrusionDlg ( this ) )->show();
2781       } else {
2782         SUIT_MessageBox::warning(desktop(),
2783                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2784       }
2785       break;
2786     }
2787   case SMESHOp::OpExtrusionAlongAPath:
2788     {
2789       if (checkLock(aStudy)) break;
2790       if (vtkwnd) {
2791         EmitSignalDeactivateDialog();
2792         ( new SMESHGUI_ExtrusionAlongPathDlg( this ) )->show();
2793       } else {
2794         SUIT_MessageBox::warning(desktop(),
2795                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2796       }
2797       break;
2798     }
2799   case SMESHOp::OpRevolution:
2800     {
2801       if(checkLock(aStudy)) break;
2802       if( vtkwnd ) {
2803         EmitSignalDeactivateDialog();
2804         ( new SMESHGUI_RevolutionDlg( this ) )->show();
2805       }
2806       else {
2807         SUIT_MessageBox::warning(desktop(),
2808                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2809       }
2810       break;
2811     }
2812   case SMESHOp::OpPatternMapping:
2813     {
2814       if ( checkLock( aStudy ) )
2815         break;
2816       if ( vtkwnd )
2817       {
2818         EmitSignalDeactivateDialog();
2819         ( new SMESHGUI_MeshPatternDlg( this ) )->show();
2820       }
2821       else {
2822         SUIT_MessageBox::warning(desktop(),
2823                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
2824       }
2825       break;
2826     }
2827   case SMESHOp::OpSplitBiQuadratic:
2828   case SMESHOp::OpConvertMeshToQuadratic:
2829   case SMESHOp::OpCreateBoundaryElements: // create 2D mesh from 3D
2830   case SMESHOp::OpReorientFaces:
2831   case SMESHOp::OpCreateGeometryGroup:
2832     {
2833       startOperation( theCommandID );
2834       break;
2835     }
2836   case SMESHOp::OpCreateGroup:
2837     {
2838       if ( !vtkwnd )
2839       {
2840         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),
2841                                   tr( "NOT_A_VTK_VIEWER" ) );
2842         break;
2843       }
2844
2845       if(checkLock(aStudy)) break;
2846       EmitSignalDeactivateDialog();
2847       SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_nil();
2848
2849       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2850       SALOME_ListIO selected;
2851       if( aSel )
2852         aSel->selectedObjects( selected );
2853
2854       int nbSel = selected.Extent();
2855       if (nbSel == 1) {
2856         // check if mesh is selected
2857         aMesh = SMESH::GetMeshByIO( selected.First() );
2858       }
2859       SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, aMesh);
2860       aDlg->show();
2861       break;
2862     }
2863
2864   case SMESHOp::OpConstructGroup:
2865     {
2866       if ( !vtkwnd )
2867       {
2868         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),
2869                                   tr( "NOT_A_VTK_VIEWER" ) );
2870         break;
2871       }
2872
2873       if(checkLock(aStudy)) break;
2874       EmitSignalDeactivateDialog();
2875
2876       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2877       SALOME_ListIO selected;
2878       if( aSel )
2879         aSel->selectedObjects( selected );
2880
2881       int nbSel = selected.Extent();
2882       if (nbSel == 1) {
2883         // check if submesh is selected
2884         Handle(SALOME_InteractiveObject) IObject = selected.First();
2885         if (IObject->hasEntry()) {
2886           _PTR(SObject) aSObj = aStudy->FindObjectID(IObject->getEntry());
2887           if( aSObj ) {
2888             SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow( SMESH::SObjectToObject( aSObj ) );
2889             if (!aSubMesh->_is_nil()) {
2890               try {
2891                 SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
2892                 // get submesh elements list by types
2893                 SMESH::long_array_var aNodes = aSubMesh->GetElementsByType(SMESH::NODE);
2894                 SMESH::long_array_var aEdges = aSubMesh->GetElementsByType(SMESH::EDGE);
2895                 SMESH::long_array_var aFaces = aSubMesh->GetElementsByType(SMESH::FACE);
2896                 SMESH::long_array_var aVolumes = aSubMesh->GetElementsByType(SMESH::VOLUME);
2897                 // create group for each type o elements
2898                 QString aName = IObject->getName();
2899                 QStringList anEntryList;
2900                 if (aNodes->length() > 0) {
2901                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::NODE, aName + "_Nodes");
2902                   aGroup->Add(aNodes.inout());
2903                   if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( aGroup ) )
2904                     anEntryList.append( aSObject->GetID().c_str() );
2905                 }
2906                 if (aEdges->length() > 0) {
2907                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::EDGE, aName + "_Edges");
2908                   aGroup->Add(aEdges.inout());
2909                   if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( aGroup ) )
2910                     anEntryList.append( aSObject->GetID().c_str() );
2911                 }
2912                 if (aFaces->length() > 0) {
2913                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::FACE, aName + "_Faces");
2914                   aGroup->Add(aFaces.inout());
2915                   if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( aGroup ) )
2916                     anEntryList.append( aSObject->GetID().c_str() );
2917                 }
2918                 if (aVolumes->length() > 0) {
2919                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::VOLUME, aName + "_Volumes");
2920                   aGroup->Add(aVolumes.inout());
2921                   if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( aGroup ) )
2922                     anEntryList.append( aSObject->GetID().c_str() );
2923                 }
2924                 updateObjBrowser();
2925                 anApp->browseObjects( anEntryList );
2926               }
2927               catch(const SALOME::SALOME_Exception & S_ex){
2928                 SalomeApp_Tools::QtCatchCorbaException(S_ex);
2929               }
2930             }
2931           }
2932         }
2933       }
2934       else if(nbSel==0) {
2935         SUIT_MessageBox::warning(desktop(),
2936                                  tr("SMESH_WRN_WARNING"),
2937                                  tr("SMESH_WRN_NO_AVAILABLE_DATA"));
2938       }
2939       break;
2940     }
2941
2942   case SMESHOp::OpEditGroup:
2943     {
2944       if ( !vtkwnd )
2945       {
2946         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),
2947                                   tr( "NOT_A_VTK_VIEWER" ) );
2948         break;
2949       }
2950
2951       if(checkLock(aStudy)) break;
2952       EmitSignalDeactivateDialog();
2953
2954       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2955       SALOME_ListIO selected;
2956       if( aSel )
2957         aSel->selectedObjects( selected );
2958
2959       SALOME_ListIteratorOfListIO It (selected);
2960       int nbSelectedGroups = 0;
2961       for ( ; It.More(); It.Next() )
2962       {
2963         SMESH::SMESH_GroupBase_var aGroup =
2964           SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(It.Value());
2965         if (!aGroup->_is_nil()) {
2966           nbSelectedGroups++;
2967           SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, aGroup);
2968           aDlg->show();
2969         }
2970       }
2971       if (nbSelectedGroups == 0)
2972         {
2973           SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, SMESH::SMESH_GroupBase::_nil());
2974           aDlg->show();
2975         }
2976       break;
2977     }
2978
2979   case SMESHOp::OpAddElemGroupPopup:     // Add elements to group
2980     {
2981       if(checkLock(aStudy)) break;
2982       if (myState == 800) {
2983         SMESHGUI_GroupDlg *aDlg = (SMESHGUI_GroupDlg*) myActiveDialogBox;
2984         if (aDlg) aDlg->onAdd();
2985       }
2986       break;
2987     }
2988
2989   case SMESHOp::OpRemoveElemGroupPopup:  // Remove elements from group
2990     {
2991       if(checkLock(aStudy)) break;
2992       if (myState == 800) {
2993         SMESHGUI_GroupDlg *aDlg = (SMESHGUI_GroupDlg*) myActiveDialogBox;
2994         if (aDlg) aDlg->onRemove();
2995       }
2996       break;
2997     }
2998
2999   case SMESHOp::OpEditGeomGroupAsGroup:
3000     {
3001       if ( !vtkwnd )
3002       {
3003         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),
3004                                   tr( "NOT_A_VTK_VIEWER" ) );
3005         break;
3006       }
3007
3008       if(checkLock(aStudy)) break;
3009       EmitSignalDeactivateDialog();
3010
3011       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
3012       SALOME_ListIO selected;
3013       if( aSel )
3014         aSel->selectedObjects( selected );
3015
3016       SALOME_ListIteratorOfListIO It (selected);
3017       for ( ; It.More(); It.Next() )
3018       {
3019         SMESH::SMESH_GroupOnGeom_var aGroup =
3020           SMESH::IObjectToInterface<SMESH::SMESH_GroupOnGeom>(It.Value());
3021         if (!aGroup->_is_nil()) {
3022           SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, aGroup, true );
3023           aDlg->show();
3024         }
3025         else
3026         {
3027           SMESH::SMESH_GroupOnFilter_var aGroup =
3028             SMESH::IObjectToInterface<SMESH::SMESH_GroupOnFilter>(It.Value());
3029           if (!aGroup->_is_nil()) {
3030             SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, aGroup, true );
3031             aDlg->show();
3032           }
3033         }
3034       }
3035       break;
3036     }
3037
3038     case SMESHOp::OpUnionGroups:
3039     case SMESHOp::OpIntersectGroups:
3040     case SMESHOp::OpCutGroups:
3041     {
3042       if ( !vtkwnd )
3043       {
3044         SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),
3045                                   tr( "NOT_A_VTK_VIEWER" ) );
3046         break;
3047       }
3048
3049       if ( checkLock( aStudy ) )
3050         break;
3051
3052       EmitSignalDeactivateDialog();
3053
3054       SMESHGUI_GroupOpDlg* aDlg = 0;
3055       if ( theCommandID == SMESHOp::OpUnionGroups )
3056         aDlg = new SMESHGUI_UnionGroupsDlg( this );
3057       else if ( theCommandID == SMESHOp::OpIntersectGroups )
3058         aDlg = new SMESHGUI_IntersectGroupsDlg( this );
3059       else
3060         aDlg = new SMESHGUI_CutGroupsDlg( this );
3061
3062       aDlg->show();
3063
3064       break;
3065     }
3066