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