Salome HOME
f9ed315776ef4f3bd3f03fb83d6ba53238302777
[modules/smesh.git] / src / SMESHGUI / SMESHGUI.cxx
1 //  SMESH SMESHGUI : GUI for SMESH component
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //  File   : SMESHGUI.cxx
23 //  Author : Nicolas REJNERI
24 //  Module : SMESH
25 //  $Header$
26
27 #include "SMESHGUI.h"
28
29 #include "SMESH_Client.hxx"
30 #include "SMESHGUI_NodesDlg.h"
31 #include "SMESHGUI_TransparencyDlg.h"
32 #include "SMESHGUI_ClippingDlg.h"
33 #include "SMESHGUI_GroupDlg.h"
34 #include "SMESHGUI_RemoveNodesDlg.h"
35 #include "SMESHGUI_RemoveElementsDlg.h"
36 #include "SMESHGUI_MeshInfosDlg.h"
37 #include "SMESHGUI_StandardMeshInfosDlg.h"
38 #include "SMESHGUI_WhatIsDlg.h"
39 #include "SMESHGUI_Preferences_ColorDlg.h"
40 #include "SMESHGUI_Preferences_ScalarBarDlg.h"
41 #include "SMESHGUI_Preferences_SelectionDlg.h"
42 #include "SMESHGUI_Hypotheses.h"
43 #include "SMESHGUI_MoveNodesDlg.h"
44 #include "SMESHGUI_AddMeshElementDlg.h"
45 #include "SMESHGUI_AddQuadraticElementDlg.h"
46 #include "SMESHGUI_FilterDlg.h"
47 #include "SMESHGUI_FilterLibraryDlg.h"
48 #include "SMESHGUI_SingleEditDlg.h"
49 #include "SMESHGUI_MultiEditDlg.h"
50 #include "SMESHGUI_GroupOpDlg.h"
51 #include "SMESHGUI_DeleteGroupDlg.h"
52 #include "SMESHGUI_SmoothingDlg.h"
53 #include "SMESHGUI_RenumberingDlg.h"
54 #include "SMESHGUI_ExtrusionDlg.h"
55 #include "SMESHGUI_ExtrusionAlongPathDlg.h"
56 #include "SMESHGUI_RevolutionDlg.h"
57 #include "SMESHGUI_TranslationDlg.h"
58 #include "SMESHGUI_RotationDlg.h"
59 #include "SMESHGUI_SymmetryDlg.h"
60 #include "SMESHGUI_SewingDlg.h"
61 #include "SMESHGUI_EditMeshDlg.h"
62 #include "SMESHGUI_MeshPatternDlg.h"
63 #include "SMESHGUI_Selection.h"
64 #include "SMESHGUI_CreatePolyhedralVolumeDlg.h"
65 #include "SMESHGUI_ConvToQuadOp.h"
66 #include "SMESHGUI_MeshOp.h"
67 #include "SMESHGUI_Displayer.h"
68 #include "SMESHGUI_MakeNodeAtPointDlg.h"
69 #include "SMESHGUI_BuildCompoundDlg.h"
70 #include "SMESHGUI_ComputeDlg.h"
71 #include "SMESHGUI_FileInfoDlg.h"
72
73 #include "SMESHGUI_Utils.h"
74 #include "SMESHGUI_GEOMGenUtils.h"
75 #include "SMESHGUI_MeshUtils.h"
76 #include "SMESHGUI_GroupUtils.h"
77 #include "SMESHGUI_FilterUtils.h"
78 #include "SMESHGUI_PatternUtils.h"
79 #include "SMESHGUI_VTKUtils.h"
80 #include "SMESHGUI_HypothesesUtils.h"
81
82 #include "SMESH_Actor.h"
83 #include "SMESH_Object.h"
84 #include "SMESH_TypeFilter.hxx"
85
86 #include "SalomeApp_Tools.h"
87 #include "SalomeApp_Study.h"
88 #include "SalomeApp_Application.h"
89 #include "SalomeApp_CheckFileDlg.h"
90 #include "SalomeApp_ImportOperation.h"
91
92 #include "LightApp_DataOwner.h"
93 #include "LightApp_Preferences.h"
94 #include "LightApp_VTKSelector.h"
95 #include "LightApp_Operation.h"
96 #include "LightApp_UpdateFlags.h"
97 #include "LightApp_NameDlg.h"
98
99 #include <SVTK_ViewWindow.h>
100 #include <SVTK_ViewModel.h>
101 #include <SVTK_InteractorStyle.h>
102 #include <SVTK_RenderWindowInteractor.h>
103 #include <SVTK_ViewManager.h>
104
105 #include "OB_Browser.h"
106
107 #include "SUIT_Tools.h"
108 #include "SUIT_MessageBox.h"
109 #include "SUIT_ResourceMgr.h"
110 #include "SUIT_FileDlg.h"
111 #include "SUIT_Desktop.h"
112 #include "SUIT_OverrideCursor.h"
113 #include "SUIT_Study.h"
114 #include "SUIT_Session.h"
115
116 #include "QtxPopupMgr.h"
117
118 #include "SALOME_ListIO.hxx"
119 #include "SALOME_ListIteratorOfListIO.hxx"
120 #include "SALOME_InteractiveObject.hxx"
121 #include "SALOME_NamingService.hxx"
122 #include "SALOME_LifeCycleCORBA.hxx"
123
124 #include "SALOMEconfig.h"
125 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
126 #include CORBA_CLIENT_HEADER(SMESH_MeshEditor)
127
128 // QT Includes
129 #define  INCLUDE_MENUITEM_DEF
130 #include <qpopupmenu.h>
131 #include <qstring.h>
132 #include <qwidget.h>
133 #include <qaction.h>
134
135 // BOOST Includes
136 #include <boost/shared_ptr.hpp>
137
138 // VTK Includes
139 #include <vtkRenderer.h>
140 #include <vtkRenderWindow.h>
141 #include <vtkActorCollection.h>
142 #include <vtkScalarBarActor.h>
143 #include <vtkUnstructuredGrid.h>
144
145 #include "utilities.h"
146
147 #include "SALOMEDS_Study.hxx"
148 #include "SALOMEDSClient_StudyBuilder.hxx"
149 #include "SALOMEDSClient_SComponent.hxx"
150
151 #include <Standard_ErrorHandler.hxx>
152
153 using namespace std;
154
155 //namespace{
156   // Declarations
157   //=============================================================
158   void ImportMeshesFromFile(SMESH::SMESH_Gen_ptr theComponentMesh,
159                             int theCommandID);
160
161   void ExportMeshToFile(int theCommandID);
162
163   void SetDisplayMode(int theCommandID);
164
165   void SetDisplayEntity(int theCommandID);
166
167   void Control( int theCommandID );
168
169
170   // Definitions
171   //=============================================================
172   void ImportMeshesFromFile(SMESH::SMESH_Gen_ptr theComponentMesh,
173                             int theCommandID)
174   {
175     QStringList filter;
176     string myExtension;
177
178     if(theCommandID == 113){
179       filter.append(QObject::tr("MED files (*.med)"));
180       filter.append(QObject::tr("All files (*)"));
181     }else if (theCommandID == 112){
182       filter.append(QObject::tr("IDEAS files (*.unv)"));
183     }else if (theCommandID == 111){
184       filter.append(QObject::tr("DAT files (*.dat)"));
185     }
186
187     QString anInitialPath = "";
188     if ( SUIT_FileDlg::getLastVisitedPath().isEmpty() )
189       anInitialPath = QDir::currentDirPath();
190
191     QString filename = SUIT_FileDlg::getFileName(SMESHGUI::desktop(),
192                                                  anInitialPath,
193                                                  filter,
194                                                  QObject::tr("Import mesh"),
195                                                  true);
196     if(!filename.isEmpty()) {
197       SUIT_OverrideCursor wc;
198       _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
199
200       try {
201         SMESH::mesh_array_var aMeshes = new SMESH::mesh_array;
202         switch ( theCommandID ) {
203         case 112:
204           {
205             aMeshes->length( 1 );
206             aMeshes[0] = theComponentMesh->CreateMeshesFromUNV(filename.latin1());
207             break;
208           }
209         case 113:
210           {
211             SMESH::DriverMED_ReadStatus res;
212             aMeshes = theComponentMesh->CreateMeshesFromMED(filename.latin1(),res);
213             if ( res != SMESH::DRS_OK ) {
214               wc.suspend();
215               SUIT_MessageBox::warn1(SMESHGUI::desktop(),
216                                      QObject::tr("SMESH_WRN_WARNING"),
217                                      QObject::tr(QString("SMESH_DRS_%1").arg(res)),
218                                      QObject::tr("SMESH_BUT_OK"));
219               aMeshes->length( 0 );
220               wc.resume();
221             }
222             break;
223           }
224         }
225
226         bool isEmpty = false;
227         for ( int i = 0, iEnd = aMeshes->length(); i < iEnd; i++ ) {
228           _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshes[i] );
229           if ( aMeshSO ) {
230             _PTR(StudyBuilder) aBuilder = aStudy->NewBuilder();
231             _PTR(AttributePixMap) aPixmap = aBuilder->FindOrCreateAttribute( aMeshSO, "AttributePixMap" );
232             aPixmap->SetPixMap("ICON_SMESH_TREE_MESH_IMPORTED");
233             if ( theCommandID == 112 ) // mesh names aren't taken from the file for UNV import
234               SMESH::SetName( aMeshSO, QFileInfo(filename).fileName() );
235           } else
236             isEmpty = true;
237         }
238
239         if ( isEmpty ) {
240           wc.suspend();
241           SUIT_MessageBox::warn1(SMESHGUI::desktop(),
242                                  QObject::tr("SMESH_WRN_WARNING"),
243                                  QObject::tr("SMESH_DRS_EMPTY"),
244                                  QObject::tr("SMESH_BUT_OK"));
245           wc.resume();
246         }
247
248         SMESHGUI::GetSMESHGUI()->updateObjBrowser();
249       }
250       catch (const SALOME::SALOME_Exception& S_ex){
251         wc.suspend();
252         SalomeApp_Tools::QtCatchCorbaException(S_ex);
253         wc.resume();
254       }
255     }
256   }
257
258
259   void ExportMeshToFile( int theCommandID )
260   {
261     LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
262     SALOME_ListIO selected;
263     if( aSel )
264       aSel->selectedObjects( selected );
265
266     if(selected.Extent()){
267       Handle(SALOME_InteractiveObject) anIObject = selected.First();
268       SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIObject);
269       if ( !aMesh->_is_nil() ) {
270         QString aFilter, aTitle = QObject::tr("Export mesh");
271         QMap<QString, SMESH::MED_VERSION> aFilterMap;
272         QMap<QString, int> aFilterMapSTL;
273         switch ( theCommandID ) {
274         case 125:
275         case 122:
276           {
277             if (aMesh->HasDuplicatedGroupNamesMED()) {
278               int aRet = SUIT_MessageBox::warn2
279                 (SMESHGUI::desktop(),
280                  QObject::tr("SMESH_WRN_WARNING"),
281                  QObject::tr("SMESH_EXPORT_MED_DUPLICATED_GRP").arg(anIObject->getName()),
282                  QObject::tr("SMESH_BUT_YES"),  QObject::tr("SMESH_BUT_NO"),
283                  0, 1, 0);
284               if (aRet)
285                 return;
286             }
287             // PAL18696
288             QString v21 (aMesh->GetVersionString(SMESH::MED_V2_1, 2));
289             QString v22 (aMesh->GetVersionString(SMESH::MED_V2_2, 2));
290             aFilterMap.insert( QString("MED ") +  v21 + " (*.med)", SMESH::MED_V2_1 );
291             aFilterMap.insert( QString("MED ") +  v22 + " (*.med)", SMESH::MED_V2_2 );
292           }
293           break;
294         case 124:
295         case 121:
296           aFilter = QObject::tr("DAT files (*.dat)");
297           break;
298         case 126:
299         case 123:
300           {
301             if (aMesh->NbPyramids()) {
302               int aRet = SUIT_MessageBox::warn2
303                 (SMESHGUI::desktop(),
304                  QObject::tr("SMESH_WRN_WARNING"),
305                  QObject::tr("SMESH_EXPORT_UNV").arg(anIObject->getName()),
306                  QObject::tr("SMESH_BUT_YES"),  QObject::tr("SMESH_BUT_NO"),
307                  0, 1, 0);
308               if (aRet)
309                 return;
310             }
311             aFilter = QObject::tr("IDEAS files (*.unv)");
312           }
313           break;
314         case 140:
315         case 141:
316           {
317             // export STL
318             /*
319               there must be check on others mesh elements not equal triangles
320             */
321             if (aMesh->NbTriangles() < 1) {
322               SUIT_MessageBox::warn1
323                 (SMESHGUI::desktop(),
324                  QObject::tr("SMESH_WRN_WARNING"),
325                  QObject::tr("SMESH_EXPORT_STL1").arg(anIObject->getName()),
326                  QObject::tr("SMESH_BUT_OK"));
327               return;
328             }
329             if (!(aMesh->NbElements() - aMesh->NbTriangles())) {
330               int aRet = SUIT_MessageBox::warn2
331                 (SMESHGUI::desktop(),
332                  QObject::tr("SMESH_WRN_WARNING"),
333                  QObject::tr("SMESH_EXPORT_STL2").arg(anIObject->getName()),
334                  QObject::tr("SMESH_BUT_YES"),  QObject::tr("SMESH_BUT_NO"),
335                  0, 1, 0);
336               if (aRet)
337                 return;
338             }
339
340             aFilterMapSTL.insert( QObject::tr("STL ASCII  (*.stl)"), 1 ); // 1 - ASCII mode
341             aFilterMapSTL.insert( QObject::tr("STL Binary (*.stl)"), 0 ); // 0 - Binary mode
342           }
343           break;
344         default:
345           return;
346         }
347
348         QString aFilename;
349         SMESH::MED_VERSION aFormat;
350         // Init the parameter with the default value
351         bool aIsASCII_STL = true;
352         bool toCreateGroups = false;
353         SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
354         if ( resMgr )
355           toCreateGroups = resMgr->booleanValue( "SMESH", "auto_groups", false );
356
357         QString anInitialPath = "";
358         if ( SUIT_FileDlg::getLastVisitedPath().isEmpty() )
359           anInitialPath = QDir::currentDirPath();
360
361         if ( theCommandID != 122 && theCommandID != 125 && theCommandID != 140 && theCommandID != 141)
362           aFilename = SUIT_FileDlg::getFileName(SMESHGUI::desktop(), anInitialPath + QString("/") + anIObject->getName(),
363                                                 aFilter, aTitle, false);
364         else if(theCommandID == 140 || theCommandID == 141) { // Export to STL
365           QStringList filters;
366           QMap<QString, int>::const_iterator it = aFilterMapSTL.begin();
367           for ( ; it != aFilterMapSTL.end(); ++it )
368             filters.push_back( it.key() );
369
370           SUIT_FileDlg* fd = new SUIT_FileDlg( SMESHGUI::desktop(), false, true, true );
371           fd->setCaption( aTitle );
372           fd->setFilters( filters );
373           fd->setSelectedFilter( QObject::tr("STL ASCII  (*.stl)") );
374           if ( !anInitialPath.isEmpty() )
375             fd->setDir( anInitialPath );
376           fd->setSelection(anIObject->getName());
377           bool is_ok = false;
378           while (!is_ok) {
379             fd->exec();
380             aFilename = fd->selectedFile();
381             aIsASCII_STL = (aFilterMapSTL[fd->selectedFilter()]) == 1 ? true: false;
382             is_ok = true;
383           }
384           delete fd;
385         }
386         else { // Export to MED
387           QStringList filters;
388           QString aDefaultFilter;
389           QMap<QString, SMESH::MED_VERSION>::const_iterator it = aFilterMap.begin();
390           for ( ; it != aFilterMap.end(); ++it ) {
391             filters.push_back( it.key() );
392             if (it.data() == SMESH::MED_V2_2)
393               aDefaultFilter = it.key();
394           }
395
396           //SUIT_FileDlg* fd = new SUIT_FileDlg( SMESHGUI::desktop(), false, true, true );
397           SalomeApp_CheckFileDlg* fd = new SalomeApp_CheckFileDlg
398             ( SMESHGUI::desktop(), false, QObject::tr("SMESH_AUTO_GROUPS") ,true, true );
399           fd->setCaption( aTitle );
400           fd->setFilters( filters );
401           //fd->setSelectedFilter( QObject::tr("MED 2.2 (*.med)") );
402           fd->setSelectedFilter(aDefaultFilter);
403           fd->SetChecked(toCreateGroups);
404           if ( !anInitialPath.isEmpty() )
405             fd->setDir( anInitialPath );
406           fd->setSelection(anIObject->getName());
407           bool is_ok = false;
408           while (!is_ok) {
409             fd->exec();
410             aFilename = fd->selectedFile();
411             aFormat = aFilterMap[fd->selectedFilter()];
412             is_ok = true;
413             if ( !aFilename.isEmpty()
414                  && (aMesh->NbPolygons()>0 || aMesh->NbPolyhedrons()>0)
415                  && aFormat==SMESH::MED_V2_1) {
416               int aRet = SUIT_MessageBox::warn2(SMESHGUI::desktop(),
417                                                 QObject::tr("SMESH_WRN_WARNING"),
418                                                 QObject::tr("SMESH_EXPORT_MED_V2_1").arg(anIObject->getName()),
419                                                 QObject::tr("SMESH_BUT_YES"),
420                                                 QObject::tr("SMESH_BUT_NO"),
421                                                 0,1,0);
422               if (aRet) {
423                 is_ok = false;
424               }
425             }
426           }
427           toCreateGroups = fd->IsChecked();
428           delete fd;
429         }
430         if ( !aFilename.isEmpty() ) {
431           // Check whether the file already exists and delete it if yes
432           QFile aFile( aFilename );
433           if ( aFile.exists() )
434             aFile.remove();
435           SUIT_OverrideCursor wc;
436
437           try {
438             bool Renumber = false ;
439             // PAL 14172  : Check of we have to renumber or not from the preferences before export
440             if (resMgr)
441               Renumber= resMgr->booleanValue("SMESH","renumbering");
442             if (Renumber){
443               SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
444               aMeshEditor->RenumberNodes();
445               aMeshEditor->RenumberElements();
446               if ( SMESHGUI::automaticUpdate() )
447                 SMESH::UpdateView();
448               }
449             switch ( theCommandID ) {
450             case 125:
451             case 122:
452               aMesh->ExportToMED( aFilename.latin1(), toCreateGroups, aFormat );
453               break;
454             case 124:
455             case 121:
456               aMesh->ExportDAT( aFilename.latin1() );
457               break;
458             case 126:
459             case 123:
460               aMesh->ExportUNV( aFilename.latin1() );
461               break;
462             case 140:
463             case 141:
464               aMesh->ExportSTL( aFilename.latin1(), aIsASCII_STL );
465               break;
466             default:
467               break;
468             }
469           }
470           catch (const SALOME::SALOME_Exception& S_ex){
471             wc.suspend();
472             SUIT_MessageBox::warn1(SMESHGUI::desktop(),
473                                     QObject::tr("SMESH_WRN_WARNING"),
474                                     QObject::tr("SMESH_EXPORT_FAILED"),
475                                     QObject::tr("SMESH_BUT_OK"));
476             wc.resume();
477           }
478         }
479       }
480     }
481   }
482
483   inline void InverseEntityMode(unsigned int& theOutputMode,
484                                 unsigned int theMode)
485   {
486     bool anIsNotPresent = ~theOutputMode & theMode;
487     if(anIsNotPresent)
488       theOutputMode |= theMode;
489     else
490       theOutputMode &= ~theMode;
491   }
492
493   void SetDisplayEntity(int theCommandID){
494     LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
495     SALOME_ListIO selected;
496     if( aSel )
497       aSel->selectedObjects( selected );
498
499     if(selected.Extent() >= 1){
500       SALOME_ListIteratorOfListIO It( selected );
501       for(; It.More(); It.Next()){
502         Handle(SALOME_InteractiveObject) IObject = It.Value();
503         if(IObject->hasEntry()){
504           if(SMESH_Actor *anActor = SMESH::FindActorByEntry(IObject->getEntry())){
505             unsigned int aMode = anActor->GetEntityMode();
506             switch(theCommandID){
507             case 217:
508               InverseEntityMode(aMode,SMESH_Actor::eEdges);
509               break;
510             case 218:
511               InverseEntityMode(aMode,SMESH_Actor::eFaces);
512               break;
513             case 219:
514               InverseEntityMode(aMode,SMESH_Actor::eVolumes);
515               break;
516             case 220:
517               aMode = SMESH_Actor::eAllEntity;
518               break;
519             }
520             if(aMode)
521               anActor->SetEntityMode(aMode);
522           }
523         }
524       }
525     }
526   }
527
528   void AutoColor(){
529     SALOME_ListIO selected;
530     SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
531     if( !app )
532       return;
533
534     LightApp_SelectionMgr* aSel = app->selectionMgr();
535     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
536     if( !aSel || !appStudy )
537       return;
538
539     aSel->selectedObjects( selected );
540     if( selected.IsEmpty() )
541       return;
542
543     Handle(SALOME_InteractiveObject) anIObject = selected.First();
544
545     _PTR(Study) aStudy = appStudy->studyDS();
546     _PTR(SObject) aMainSObject( aStudy->FindObjectID( anIObject->getEntry() ) );
547     SMESH::SMESH_Mesh_var aMainObject = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIObject);
548     if( aMainObject->_is_nil() )
549       return;
550
551     aMainObject->SetAutoColor( true );
552
553     QValueList<SALOMEDS::Color> aReservedColors;
554
555     SMESH::ListOfGroups aListOfGroups = *aMainObject->GetGroups();
556     for( int i = 0, n = aListOfGroups.length(); i < n; i++ )
557     {
558       SMESH::SMESH_GroupBase_var aGroupObject = aListOfGroups[i];
559       SALOMEDS::Color aCurrentColor = aGroupObject->GetColor();
560
561       SALOMEDS::Color aColor = SMESHGUI::getUniqueColor( aReservedColors );
562       aGroupObject->SetColor( aColor );
563       aReservedColors.append( aColor );
564
565       _PTR(SObject) aGroupSObject = SMESH::FindSObject(aGroupObject);
566       if(SMESH_Actor *anActor = SMESH::FindActorByEntry(aGroupSObject->GetID().c_str()))
567       {
568         if( aGroupObject->GetType() == SMESH::NODE )
569           anActor->SetNodeColor( aColor.R, aColor.G, aColor.B );
570         else if( aGroupObject->GetType() == SMESH::EDGE )
571           anActor->SetEdgeColor( aColor.R, aColor.G, aColor.B );
572         else
573           anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B );
574       }
575     }
576
577     SMESH::RepaintCurrentView();
578   }
579
580   void DisableAutoColor(){
581     LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
582     SALOME_ListIO selected;
583     if( aSel )
584       aSel->selectedObjects( selected );
585
586     if(selected.Extent()){
587       Handle(SALOME_InteractiveObject) anIObject = selected.First();
588       SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIObject);
589       if ( !aMesh->_is_nil() ) {
590         aMesh->SetAutoColor( false );
591       }
592     }
593   }
594
595   void SetDisplayMode(int theCommandID){
596     SALOME_ListIO selected;
597     SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
598     if( !app )
599       return;
600
601     LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
602     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
603     if( !aSel || !appStudy )
604       return;
605
606     _PTR(Study) aStudy = appStudy->studyDS();
607
608     aSel->selectedObjects( selected );
609
610     if(selected.Extent() >= 1){
611       switch(theCommandID){
612       case 1134:{
613         SMESHGUI::GetSMESHGUI()->EmitSignalDeactivateDialog();
614         new SMESHGUI_ClippingDlg( SMESHGUI::GetSMESHGUI(), "", false );
615         return;
616       }
617       case 1133:{
618         SMESHGUI::GetSMESHGUI()->EmitSignalDeactivateDialog();
619         new SMESHGUI_TransparencyDlg( SMESHGUI::GetSMESHGUI(), "", false );
620         return;
621       }}
622       SALOME_ListIteratorOfListIO It( selected );
623       for(; It.More(); It.Next()){
624         Handle(SALOME_InteractiveObject) IObject = It.Value();
625         if(IObject->hasEntry()){
626           if(SMESH_Actor *anActor = SMESH::FindActorByEntry(IObject->getEntry())){
627             switch(theCommandID){
628             case 211:
629               anActor->SetRepresentation(SMESH_Actor::eEdge);
630               break;
631             case 212:
632               anActor->SetRepresentation(SMESH_Actor::eSurface);
633               break;
634             case 213:
635               if(anActor->IsShrunk())
636                 anActor->UnShrink();
637               else
638                 anActor->SetShrink();
639               break;
640             case 215:
641               anActor->SetRepresentation(SMESH_Actor::ePoint);
642               break;
643             case 1132:{
644               vtkFloatingPointType color[3];
645               anActor->GetSufaceColor(color[0], color[1], color[2]);
646               int c0 = int (color[0] * 255);
647               int c1 = int (color[1] * 255);
648               int c2 = int (color[2] * 255);
649               QColor c(c0, c1, c2);
650
651               vtkFloatingPointType edgecolor[3];
652               anActor->GetEdgeColor(edgecolor[0], edgecolor[1], edgecolor[2]);
653               c0 = int (edgecolor[0] * 255);
654               c1 = int (edgecolor[1] * 255);
655               c2 = int (edgecolor[2] * 255);
656               QColor e(c0, c1, c2);
657
658               vtkFloatingPointType backfacecolor[3];
659               anActor->GetBackSufaceColor(backfacecolor[0], backfacecolor[1], backfacecolor[2]);
660               c0 = int (backfacecolor[0] * 255);
661               c1 = int (backfacecolor[1] * 255);
662               c2 = int (backfacecolor[2] * 255);
663               QColor b(c0, c1, c2);
664
665               vtkFloatingPointType nodecolor[3];
666               anActor->GetNodeColor(nodecolor[0], nodecolor[1], nodecolor[2]);
667               c0 = int (nodecolor[0] * 255);
668               c1 = int (nodecolor[1] * 255);
669               c2 = int (nodecolor[2] * 255);
670               QColor n(c0, c1, c2);
671
672               int Edgewidth = (int)anActor->GetLineWidth();
673               if(Edgewidth == 0)
674                 Edgewidth = 1;
675               int intValue = int(anActor->GetNodeSize());
676               vtkFloatingPointType Shrink = anActor->GetShrinkFactor();
677
678               SMESHGUI_Preferences_ColorDlg *aDlg =
679                 new SMESHGUI_Preferences_ColorDlg( SMESHGUI::GetSMESHGUI(), "" );
680               aDlg->SetColor(1, c);
681               aDlg->SetColor(2, e);
682               aDlg->SetColor(3, n);
683               aDlg->SetColor(4, b);
684               aDlg->SetIntValue(1, Edgewidth);
685               aDlg->SetIntValue(2, intValue);
686               aDlg->SetIntValue(3, int(Shrink*100.));
687               if(aDlg->exec()){
688                 QColor color = aDlg->GetColor(1);
689                 QColor edgecolor = aDlg->GetColor(2);
690                 QColor nodecolor = aDlg->GetColor(3);
691                 QColor backfacecolor = aDlg->GetColor(4);
692                 /* actor color and backface color */
693                 anActor->SetSufaceColor(vtkFloatingPointType (color.red()) / 255.,
694                                         vtkFloatingPointType (color.green()) / 255.,
695                                         vtkFloatingPointType (color.blue()) / 255.);
696                 anActor->SetBackSufaceColor(vtkFloatingPointType (backfacecolor.red()) / 255.,
697                                             vtkFloatingPointType (backfacecolor.green()) / 255.,
698                                             vtkFloatingPointType (backfacecolor.blue()) / 255.);
699
700                 /* edge color */
701                 anActor->SetEdgeColor(vtkFloatingPointType (edgecolor.red()) / 255.,
702                                       vtkFloatingPointType (edgecolor.green()) / 255.,
703                                       vtkFloatingPointType (edgecolor.blue()) / 255.);
704
705                 /* Shrink factor and size edges */
706                 anActor->SetShrinkFactor(aDlg->GetIntValue(3) / 100.);
707                 anActor->SetLineWidth(aDlg->GetIntValue(1));
708
709                 /* Nodes color and size */
710                 anActor->SetNodeColor(vtkFloatingPointType (nodecolor.red()) / 255.,
711                                       vtkFloatingPointType (nodecolor.green()) / 255.,
712                                       vtkFloatingPointType (nodecolor.blue()) / 255.);
713                 anActor->SetNodeSize(aDlg->GetIntValue(2));
714
715                 SMESH::SMESH_GroupBase_var aGroupObject = SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IObject);
716                 if( !aGroupObject->_is_nil() )
717                 {
718                   SALOMEDS::Color aColor;
719                   aColor.R = (float)color.red() / 255.0;
720                   aColor.G = (float)color.green() / 255.0;
721                   aColor.B = (float)color.blue() / 255.0;
722                   aGroupObject->SetColor( aColor );
723                 }
724
725                 delete aDlg;
726               }
727               break;
728             }}
729           }
730         }
731       }
732       SMESH::RepaintCurrentView();
733     }
734   }
735
736   void Control( int theCommandID )
737   {
738     LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
739     SALOME_ListIO selected;
740     if( aSel )
741       aSel->selectedObjects( selected );
742
743     if( !selected.IsEmpty() ){
744       Handle(SALOME_InteractiveObject) anIO = selected.First();
745       if(!anIO.IsNull()){
746         QString aTitle;
747         SMESH_Actor::eControl aControl = SMESH_Actor::eNone;
748         if(SMESH_Actor *anActor = SMESH::FindActorByEntry(anIO->getEntry())){
749           switch ( theCommandID ){
750           case 6001:
751             aTitle = QObject::tr( "LENGTH_EDGES" );
752             aControl = SMESH_Actor::eLength;
753             break;
754           case 6018:
755             aTitle = QObject::tr( "LENGTH2D_EDGES" );
756             aControl = SMESH_Actor::eLength2D;
757             break;
758           case 6002:
759             aTitle = QObject::tr( "FREE_EDGES" );
760             aControl = SMESH_Actor::eFreeEdges;
761             break;
762           case 6003:
763             aTitle = QObject::tr( "FREE_BORDERS" );
764             aControl = SMESH_Actor::eFreeBorders;
765             break;
766           case 6004:
767             aTitle = QObject::tr( "MULTI_BORDERS" );
768             aControl = SMESH_Actor::eMultiConnection;
769             break;
770           case 6019:
771             aTitle = QObject::tr( "MULTI2D_BORDERS" );
772             aControl = SMESH_Actor::eMultiConnection2D;
773             break;
774           case 6011:
775             aTitle = QObject::tr( "AREA_ELEMENTS" );
776             aControl = SMESH_Actor::eArea;
777             break;
778           case 6012:
779             aTitle = QObject::tr( "TAPER_ELEMENTS" );
780             aControl = SMESH_Actor::eTaper;
781             break;
782           case 6013:
783             aTitle = QObject::tr( "ASPECTRATIO_ELEMENTS" );
784             aControl = SMESH_Actor::eAspectRatio;
785             break;
786           case 6017:
787             aTitle = QObject::tr( "ASPECTRATIO_3D_ELEMENTS" );
788             aControl = SMESH_Actor::eAspectRatio3D;
789             break;
790           case 6014:
791             aTitle = QObject::tr( "MINIMUMANGLE_ELEMENTS" );
792             aControl = SMESH_Actor::eMinimumAngle;
793             break;
794           case 6015:
795             aTitle = QObject::tr( "WARP_ELEMENTS" );
796             aControl = SMESH_Actor::eWarping;
797             break;
798           case 6016:
799             aTitle = QObject::tr( "SKEW_ELEMENTS" );
800             aControl = SMESH_Actor::eSkew;
801             break;
802           case 6009:
803             aTitle = QObject::tr( "SMESH_VOLUME" );
804             aControl = SMESH_Actor::eVolume3D;
805             break;
806           }
807           anActor->SetControlMode(aControl);
808           anActor->GetScalarBarActor()->SetTitle(aTitle.latin1());
809           SMESH::RepaintCurrentView();
810         }
811       }
812     }
813   }
814
815
816   bool CheckOIType(const Handle(SALOME_InteractiveObject) & theIO,
817                    MeshObjectType                           theType,
818                    const QString                            theInTypeName,
819                    QString &                                theOutTypeName)
820   {
821     SMESH_TypeFilter aTypeFilter( theType );
822     QString entry;
823     if( !theIO.IsNull() )
824     {
825       entry = theIO->getEntry();
826       LightApp_DataOwner owner( entry );
827       if ( aTypeFilter.isOk( &owner )) {
828         theOutTypeName = theInTypeName;
829         return true;
830       }
831     }
832     return false;
833   }
834
835
836   QString CheckTypeObject(const Handle(SALOME_InteractiveObject) & theIO)
837   {
838     _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
839     _PTR(SObject) aSObj = aStudy->FindObjectID(theIO->getEntry());
840     if (aSObj) {
841       _PTR(SComponent) aSComp = aSObj->GetFatherComponent();
842       CORBA::String_var anID = aSComp->GetID().c_str();
843       if (!strcmp(anID.in(),theIO->getEntry()))
844         return "Component";
845     }
846
847     QString aTypeName;
848     if (
849         CheckOIType ( theIO, HYPOTHESIS,    "Hypothesis", aTypeName ) ||
850         CheckOIType ( theIO, ALGORITHM,     "Algorithm",  aTypeName ) ||
851         CheckOIType ( theIO, MESH,          "Mesh",       aTypeName ) ||
852         CheckOIType ( theIO, SUBMESH,       "SubMesh",    aTypeName ) ||
853         CheckOIType ( theIO, GROUP,         "Group",      aTypeName )
854         )
855       return aTypeName;
856
857     return "NoType";
858   }
859
860
861   QString CheckHomogeneousSelection()
862   {
863     //SUIT_Study* aStudy = SMESH::GetActiveStudy();
864     LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
865     SALOME_ListIO selected;
866     if( aSel )
867       aSel->selectedObjects( selected );
868
869     QString RefType = CheckTypeObject(selected.First());
870     SALOME_ListIteratorOfListIO It(selected);
871     for (; It.More(); It.Next())
872       {
873         Handle(SALOME_InteractiveObject) IObject = It.Value();
874         QString Type = CheckTypeObject(IObject);
875         if (Type.compare(RefType) != 0)
876           return "Heterogeneous Selection";
877       }
878
879     return RefType;
880   }
881
882
883   void SMESHGUI::OnEditDelete()
884   {
885     // VSR 17/11/04: check if all objects selected belong to SMESH component --> start
886     LightApp_SelectionMgr* aSel = SMESHGUI::selectionMgr();
887     SALOME_ListIO selected; aSel->selectedObjects( selected, QString::null, false );
888
889     _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
890     _PTR(StudyBuilder) aStudyBuilder = aStudy->NewBuilder();
891     _PTR(GenericAttribute) anAttr;
892     _PTR(AttributeIOR) anIOR;
893
894     int objectCount = 0;
895     QString aParentComponent = QString::null;
896     for( SALOME_ListIteratorOfListIO anIt( selected ); anIt.More(); anIt.Next() )
897     {
898       _PTR(SObject) aSO = aStudy->FindObjectID(anIt.Value()->getEntry());
899       if (aSO) {
900         // check if object is not reference
901         _PTR(SObject) refobj;
902         if ( !aSO->ReferencedObject( refobj ) )
903           objectCount++;
904       }
905
906       QString cur = anIt.Value()->getComponentDataType();
907       if( aParentComponent.isNull() )
908         aParentComponent = cur;
909       else if( !aParentComponent.isEmpty() && aParentComponent!=cur )
910         aParentComponent = "";
911     }
912
913     if ( objectCount == 0 )
914       return; // No Valid Objects Selected
915
916     if ( aParentComponent != SMESHGUI::GetSMESHGUI()->name() )  {
917       SUIT_MessageBox::warn1 ( SMESHGUI::desktop(),
918                               QObject::tr("ERR_ERROR"),
919                               QObject::tr("NON_SMESH_OBJECTS_SELECTED").arg( SMESHGUI::GetSMESHGUI()->moduleName() ),
920                               QObject::tr("BUT_OK") );
921       return;
922     }
923     // VSR 17/11/04: check if all objects selected belong to SMESH component <-- finish
924     if (SUIT_MessageBox::warn2
925         (SMESHGUI::desktop(),
926          QObject::tr("SMESH_WRN_WARNING"),
927          QObject::tr("SMESH_REALLY_DELETE"),
928          QObject::tr("SMESH_BUT_YES"), QObject::tr("SMESH_BUT_NO"), 1, 0, 0) != 1)
929       return;
930
931     SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
932     SUIT_ViewManager* vm = anApp->activeViewManager();
933     int nbSf = vm->getViewsCount();
934
935     SALOME_ListIteratorOfListIO It(selected);
936
937     aStudyBuilder->NewCommand();  // There is a transaction
938     for(; It.More(); It.Next()){ // loop on selected IO's
939       Handle(SALOME_InteractiveObject) IObject = It.Value();
940       if(IObject->hasEntry()) {
941         _PTR(SObject) aSO = aStudy->FindObjectID(IObject->getEntry());
942
943         // disable removal of "SMESH" component object
944         if(aSO->FindAttribute(anAttr, "AttributeIOR")){
945           anIOR = anAttr;
946           if ( !strcmp( (char*)anIOR->Value().c_str(), engineIOR().latin1() ) )
947             continue;
948         }
949
950         _PTR(SObject) refobj;
951         if ( aSO && aSO->ReferencedObject( refobj ) )
952           continue; // skip references 
953
954         // put the whole hierarchy of sub-objects of the selected SO into a list and
955         // then treat them all starting from the deepest objects (at list back)
956
957         list< _PTR(SObject) > listSO;
958         listSO.push_back( aSO );
959         list< _PTR(SObject) >::iterator itSO = listSO.begin();
960         for ( ; itSO != listSO.end(); ++itSO ) {
961           _PTR(ChildIterator) it = aStudy->NewChildIterator( *itSO );
962           for (it->InitEx(false); it->More(); it->Next())
963             listSO.push_back( it->Value() );
964         }
965
966         // treat SO's in the list starting from the back
967
968         list< _PTR(SObject) >::reverse_iterator ritSO = listSO.rbegin();
969         for ( ; ritSO != listSO.rend(); ++ritSO ) {
970           _PTR(SObject) SO = *ritSO;
971           if ( !SO ) continue;
972           string anEntry = SO->GetID();
973
974           /** Erase graphical object **/
975           if(SO->FindAttribute(anAttr, "AttributeIOR")){
976             QPtrVector<SUIT_ViewWindow> aViews = vm->getViews();
977             for(int i = 0; i < nbSf; i++){
978               SUIT_ViewWindow *sf = aViews[i];
979               if(SMESH_Actor* anActor = SMESH::FindActorByEntry(sf,anEntry.c_str())){
980                 SMESH::RemoveActor(sf,anActor);
981               }
982             }
983           }
984
985           /** Remove an object from data structures **/
986           SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow( SMESH::SObjectToObject( SO ));
987           SMESH::SMESH_subMesh_var   aSubMesh = SMESH::SMESH_subMesh::_narrow( SMESH::SObjectToObject( SO ));
988           if ( !aGroup->_is_nil() ) {                          // DELETE GROUP
989             SMESH::SMESH_Mesh_var aMesh = aGroup->GetMesh();
990             aMesh->RemoveGroup( aGroup );
991           }
992           else if ( !aSubMesh->_is_nil() ) {                   // DELETE SUBMESH
993             SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
994             aMesh->RemoveSubMesh( aSubMesh );
995
996             _PTR(SObject) aMeshSO = SMESH::FindSObject(aMesh);
997             if (aMeshSO)
998               SMESH::ModifiedMesh(aMeshSO, false, aMesh->NbNodes()==0);
999           }
1000           else {
1001             IObject = new SALOME_InteractiveObject
1002               ( anEntry.c_str(), engineIOR().latin1(), SO->GetName().c_str() );
1003             QString objType = CheckTypeObject(IObject);
1004             if ( objType == "Hypothesis" || objType == "Algorithm" ) {// DELETE HYPOTHESIS
1005               SMESH::RemoveHypothesisOrAlgorithmOnMesh(IObject);
1006               aStudyBuilder->RemoveObjectWithChildren( SO );
1007             }
1008             else {// default action: remove SObject from the study
1009               // san - it's no use opening a transaction here until UNDO/REDO is provided in SMESH
1010               //SUIT_Operation *op = new SALOMEGUI_ImportOperation(myActiveStudy);
1011               //op->start();
1012               aStudyBuilder->RemoveObjectWithChildren( SO );
1013               //op->finish();
1014             }
1015           }
1016         } /* listSO back loop */
1017       } /* IObject->hasEntry() */
1018     } /* more/next */
1019     aStudyBuilder->CommitCommand();
1020
1021     /* Clear any previous selection */
1022     SALOME_ListIO l1;
1023     aSel->setSelectedObjects( l1 );
1024
1025     SMESHGUI::GetSMESHGUI()->updateObjBrowser();
1026   }
1027 //}
1028
1029 extern "C" {
1030   SMESHGUI_EXPORT CAM_Module* createModule()
1031   {
1032     return new SMESHGUI();
1033   }
1034 }
1035
1036 SMESH::SMESH_Gen_var SMESHGUI::myComponentSMESH = SMESH::SMESH_Gen::_nil();
1037
1038 //=============================================================================
1039 /*!
1040  *
1041  */
1042 //=============================================================================
1043 SMESHGUI::SMESHGUI() :
1044 SalomeApp_Module( "SMESH" )
1045 {
1046   if ( CORBA::is_nil( myComponentSMESH ) )
1047   {
1048     CORBA::Boolean anIsEmbeddedMode;
1049     myComponentSMESH = SMESH_Client::GetSMESHGen(getApp()->orb(),anIsEmbeddedMode);
1050   }
1051
1052   myActiveDialogBox = 0;
1053   myFilterLibraryDlg = 0;
1054   myState = -1;
1055   myDisplayer = 0;
1056
1057   SMESH::GetFilterManager();
1058   SMESH::GetPattern();
1059
1060   /* load resources for all available meshers */
1061   SMESH::InitAvailableHypotheses();
1062 }
1063
1064 //=============================================================================
1065 /*!
1066  *
1067  */
1068 //=============================================================================
1069 SMESHGUI::~SMESHGUI()
1070 {
1071   SMESH::GetFilterManager()->Destroy();
1072   SMESH::GetFilterManager() = SMESH::FilterManager::_nil();
1073 }
1074
1075 //=============================================================================
1076 /*!
1077  *
1078  */
1079 //=============================================================================
1080 LightApp_SelectionMgr* SMESHGUI::selectionMgr()
1081 {
1082   SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
1083   if( anApp )
1084     return dynamic_cast<LightApp_SelectionMgr*>( anApp->selectionMgr() );
1085   else
1086     return 0;
1087 }
1088
1089 bool SMESHGUI::automaticUpdate()
1090 {
1091   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1092   if ( !resMgr )
1093     return false;
1094
1095   return resMgr->booleanValue( "SMESH", "auto_update", false );
1096 }
1097
1098 //=============================================================================
1099 /*!
1100  *
1101  */
1102 //=============================================================================
1103 SUIT_ResourceMgr* SMESHGUI::resourceMgr()
1104 {
1105   return dynamic_cast<SUIT_ResourceMgr*>( SUIT_Session::session()->resourceMgr() );
1106 }
1107
1108 //=============================================================================
1109 /*!
1110  *
1111  */
1112 //=============================================================================
1113 SMESHGUI* SMESHGUI::GetSMESHGUI()
1114 {
1115   SMESHGUI* smeshMod = 0;
1116   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>(SUIT_Session::session()->activeApplication());
1117   if ( app )
1118   {
1119     CAM_Module* module = app->module( "Mesh" );
1120     smeshMod = dynamic_cast<SMESHGUI*>( module );
1121   }
1122
1123   if ( smeshMod && smeshMod->application() && smeshMod->application()->activeStudy() )
1124   {
1125     SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( smeshMod->application()->activeStudy() );
1126     if ( study )
1127     {
1128       _PTR(Study) aStudy = study->studyDS();
1129       if ( aStudy )
1130         GetSMESHGen()->SetCurrentStudy( _CAST(Study,aStudy)->GetStudy() );
1131     }
1132   }
1133
1134   return smeshMod;
1135 }
1136
1137 extern "C"
1138 {
1139   Standard_EXPORT SMESHGUI* GetComponentGUI()
1140   {
1141     return SMESHGUI::GetSMESHGUI();
1142   }
1143 }
1144
1145 //=============================================================================
1146 /*!
1147  *
1148  */
1149 //=============================================================================
1150 void SMESHGUI::SetState(int aState)
1151 {
1152   myState = aState;
1153 }
1154
1155 //=============================================================================
1156 /*!
1157  *
1158  */
1159 //=============================================================================
1160 void SMESHGUI::ResetState()
1161 {
1162   myState = -1;
1163 }
1164
1165 //=============================================================================
1166 /*!
1167  *
1168  */
1169 //=============================================================================
1170 void SMESHGUI::EmitSignalDeactivateDialog()
1171 {
1172   emit SignalDeactivateActiveDialog();
1173 }
1174
1175 //=============================================================================
1176 /*!
1177  *
1178  */
1179 //=============================================================================
1180 void SMESHGUI::EmitSignalStudyFrameChanged()
1181 {
1182   emit SignalStudyFrameChanged();
1183 }
1184
1185 //=============================================================================
1186 /*!
1187  *
1188  */
1189 //=============================================================================
1190 void SMESHGUI::EmitSignalCloseAllDialogs()
1191 {
1192   emit SignalCloseAllDialogs();
1193 }
1194
1195 //=============================================================================
1196 /*!
1197  *
1198  */
1199 //=============================================================================
1200 QDialog *SMESHGUI::GetActiveDialogBox()
1201 {
1202   return myActiveDialogBox;
1203 }
1204
1205 //=============================================================================
1206 /*!
1207  *
1208  */
1209 //=============================================================================
1210 void SMESHGUI::SetActiveDialogBox(QDialog * aDlg)
1211 {
1212   myActiveDialogBox = (QDialog *) aDlg;
1213   return;
1214 }
1215
1216 //=============================================================================
1217 /*!
1218  *
1219  */
1220 //=============================================================================
1221 SUIT_Desktop* SMESHGUI::desktop()
1222 {
1223   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
1224   if( app )
1225     return app->desktop();
1226   else
1227     return 0;
1228 }
1229
1230 //=============================================================================
1231 /*!
1232  *
1233  */
1234 //=============================================================================
1235 SalomeApp_Study* SMESHGUI::activeStudy()
1236 {
1237   SUIT_Application* app = SUIT_Session::session()->activeApplication();
1238   if( app )
1239     return dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1240   else
1241     return NULL;
1242 }
1243
1244 //=============================================================================
1245 /*!
1246  *
1247  */
1248 //=============================================================================
1249 bool SMESHGUI::DefineDlgPosition(QWidget * aDlg, int &x, int &y)
1250 {
1251   /* Here the position is on the bottom right corner - 10 */
1252   // aDlg->resize(QSize().expandedTo(aDlg->minimumSizeHint()));
1253   aDlg->adjustSize();
1254   SUIT_Desktop *PP = desktop();
1255   x = abs(PP->x() + PP->size().width() - aDlg->size().width() - 10);
1256   y = abs(PP->y() + PP->size().height() - aDlg->size().height() - 10);
1257   return true;
1258 }
1259
1260 //=============================================================================
1261 /*!
1262  *
1263  */
1264 //=============================================================================
1265 static int isStudyLocked(_PTR(Study) theStudy){
1266   return theStudy->GetProperties()->IsLocked();
1267 }
1268
1269 static bool checkLock(_PTR(Study) theStudy) {
1270   if (isStudyLocked(theStudy)) {
1271     SUIT_MessageBox::warn1 ( SMESHGUI::desktop(),
1272                            QObject::tr("WRN_WARNING"),
1273                            QObject::tr("WRN_STUDY_LOCKED"),
1274                            QObject::tr("BUT_OK") );
1275     return true;
1276   }
1277   return false;
1278 }
1279
1280 //=======================================================================
1281 //function : CheckActiveStudyLocked
1282 //purpose  :
1283 //=======================================================================
1284
1285 bool SMESHGUI::isActiveStudyLocked()
1286 {
1287   _PTR(Study) aStudy = activeStudy()->studyDS();
1288   return checkLock( aStudy );
1289 }
1290
1291 //=============================================================================
1292 /*!
1293  *
1294  */
1295 //=============================================================================
1296 bool SMESHGUI::OnGUIEvent( int theCommandID )
1297 {
1298   SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( application() );
1299   if( !anApp )
1300     return false;
1301
1302   _PTR(Study) aStudy = SMESH::GetActiveStudyDocument(); //Document OCAF de l'etude active
1303   SUIT_ResourceMgr* mgr = resourceMgr();
1304   if( !mgr )
1305     return false;
1306
1307   if (CORBA::is_nil(GetSMESHGen()->GetCurrentStudy())) {
1308     GetSMESHGen()->SetCurrentStudy(_CAST(Study,aStudy)->GetStudy());
1309   }
1310
1311   SUIT_ViewWindow* view = application()->desktop()->activeWindow();
1312   SVTK_ViewWindow* vtkwnd = dynamic_cast<SVTK_ViewWindow*>( view );
1313
1314   //QAction* act = action( theCommandID );
1315
1316   switch (theCommandID) {
1317   case 33:                                      // DELETE
1318     if(checkLock(aStudy)) break;
1319     OnEditDelete();
1320     break;
1321
1322   case 113:                                     // IMPORT
1323   case 112:
1324   case 111:
1325     {
1326       if(checkLock(aStudy)) break;
1327       ::ImportMeshesFromFile(GetSMESHGen(),theCommandID);
1328       break;
1329     }
1330
1331   case 150:    //MED FILE INFORMATION
1332     {
1333       SALOME_ListIO selected;
1334       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1335       if( aSel )
1336         aSel->selectedObjects( selected );
1337       if( selected.Extent() )
1338       {
1339         Handle(SALOME_InteractiveObject) anIObject = selected.First();
1340         SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIObject);
1341         if ( !aMesh->_is_nil() )
1342         {
1343           SMESHGUI_FileInfoDlg dlg( desktop(), aMesh->GetMEDFileInfo() );
1344           dlg.exec();
1345         }
1346       }
1347       break;
1348     }
1349   case 122:                                     // EXPORT MED
1350   case 121:
1351   case 123:
1352   case 124:
1353   case 125:
1354   case 126:
1355   case 140:
1356   case 141:
1357     {
1358       ::ExportMeshToFile(theCommandID);
1359       break;
1360     }
1361
1362   case 200:                                     // SCALAR BAR
1363     {
1364       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1365       SALOME_ListIO selected;
1366       if( aSel )
1367         aSel->selectedObjects( selected );
1368
1369       if( selected.Extent() ) {
1370         Handle(SALOME_InteractiveObject) anIO = selected.First();
1371         if( anIO->hasEntry() ) {
1372           if( SMESH_Actor* anActor = SMESH::FindActorByEntry( anIO->getEntry() ) ) {
1373             anActor->SetControlMode( SMESH_Actor::eNone );
1374           }
1375         }
1376       }
1377       break;
1378     }
1379   case 201:
1380     {
1381       SMESHGUI_Preferences_ScalarBarDlg::ScalarBarProperties( this );
1382       break;
1383     }
1384
1385     // Auto-color
1386   case 1136:
1387     ::AutoColor();
1388   break;
1389
1390   case 1137:
1391     ::DisableAutoColor();
1392   break;
1393
1394   case 1134: // Clipping
1395   case 1133: // Tranparency
1396   case 1132: // Colors / Size
1397
1398     // Display Mode
1399   case 215: // Nodes
1400   case 213: // Nodes
1401   case 212: // Nodes
1402   case 211: // Nodes
1403     ::SetDisplayMode(theCommandID);
1404   break;
1405
1406     // Display Entity
1407   case 217: // Edges
1408   case 218: // Faces
1409   case 219: // Volumes
1410   case 220: // All Entity
1411     ::SetDisplayEntity(theCommandID);
1412   break;
1413
1414   case 214:                                     // UPDATE
1415     {
1416       if(checkLock(aStudy)) break;
1417       try {
1418 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1419         OCC_CATCH_SIGNALS;
1420 #endif
1421         SMESH::UpdateView();
1422       }
1423       catch (std::bad_alloc) { // PAL16774 (Crash after display of many groups)
1424         SMESH::OnVisuException();
1425       }
1426       catch (...) { // PAL16774 (Crash after display of many groups)
1427         SMESH::OnVisuException();
1428       }
1429
1430       SALOME_ListIO l;
1431       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1432       aSel->selectedObjects( l );
1433       aSel->setSelectedObjects( l );
1434       break;
1435     }
1436
1437   case 300:                                     // ERASE
1438   case 301:                                     // DISPLAY
1439   case 302:                                     // DISPLAY ONLY
1440     {
1441       SMESH::EDisplaing anAction;
1442       switch (theCommandID) {
1443       case 300: anAction = SMESH::eErase; break;
1444       case 301: anAction = SMESH::eDisplay; break;
1445       case 302: anAction = SMESH::eDisplayOnly; break;
1446       }
1447
1448       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1449       SALOME_ListIO sel_objects, to_process;
1450       if (aSel)
1451         aSel->selectedObjects( sel_objects );
1452
1453       if( theCommandID==302 )
1454         startOperation( myEraseAll );
1455
1456       extractContainers( sel_objects, to_process );
1457
1458       try {
1459 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1460         OCC_CATCH_SIGNALS;
1461 #endif
1462         if (vtkwnd) {
1463           SALOME_ListIteratorOfListIO It( to_process );
1464           for (; It.More(); It.Next()) {
1465             Handle(SALOME_InteractiveObject) IOS = It.Value();
1466             if (IOS->hasEntry()) {
1467               if (!SMESH::UpdateView(anAction, IOS->getEntry()))
1468                 break; // PAL16774 (Crash after display of many groups)
1469               if (anAction == SMESH::eDisplayOnly)
1470                 anAction = SMESH::eDisplay;
1471             }
1472           }
1473         }
1474
1475         // PAL13338 + PAL15161 -->
1476         if ( ( theCommandID==301 || theCommandID==302 ) && !checkLock(aStudy))
1477           SMESH::UpdateView();
1478         // PAL13338 + PAL15161 <--
1479       }
1480       catch (...) { // PAL16774 (Crash after display of many groups)
1481         SMESH::OnVisuException();
1482       }
1483
1484       if (anAction == SMESH::eErase) {
1485         SALOME_ListIO l1;
1486         aSel->setSelectedObjects( l1 );
1487       }
1488       else
1489         aSel->setSelectedObjects( to_process );
1490
1491       break;
1492     }
1493
1494   case 400:                                     // NODES
1495     {
1496       if(checkLock(aStudy)) break;
1497
1498       if ( vtkwnd ) {
1499         EmitSignalDeactivateDialog();
1500
1501         new SMESHGUI_NodesDlg(this);
1502       }
1503       else {
1504         SUIT_MessageBox::warn1(desktop(),
1505                               tr("SMESH_WRN_WARNING"),
1506                               tr("SMESH_WRN_VIEWER_VTK"),
1507                               tr("SMESH_BUT_OK"));
1508       }
1509       break;
1510     }
1511
1512   case 2151:  // FILTER
1513   {
1514     if ( vtkwnd )
1515     {
1516       EmitSignalDeactivateDialog();
1517       new SMESHGUI_FilterDlg( this, SMESH::EDGE );
1518     }
1519     break;
1520   }
1521
1522   case 406:                                     // MOVE NODE
1523     {
1524       if ( !vtkwnd )
1525       {
1526         SUIT_MessageBox::warn1( desktop(), tr( "SMESH_WRN_WARNING" ),
1527           tr( "NOT_A_VTK_VIEWER" ),tr( "SMESH_BUT_OK" ) );
1528         break;
1529       }
1530
1531       if(checkLock(aStudy)) break;
1532       new SMESHGUI_MoveNodesDlg(this);
1533       break;
1534     }
1535
1536   case 701:                                     // COMPUTE MESH
1537     {
1538       if (checkLock(aStudy)) break;
1539
1540       startOperation( 701 );
1541     }
1542     break;
1543
1544   case 702:  // Create mesh
1545     startOperation( 702 );
1546     break;
1547   case 703:  // Create sub-mesh
1548     startOperation( 703 );
1549     break;
1550   case 704: // Edit mesh/sub-mesh
1551     startOperation( 704 );
1552     break;
1553   case 710: // Build compound mesh
1554     {
1555       if (checkLock(aStudy)) break;
1556       EmitSignalDeactivateDialog();
1557       new SMESHGUI_BuildCompoundDlg( this );
1558     }
1559     break;
1560
1561   case 407: // DIAGONAL INVERSION
1562   case 408: // Delete diagonal
1563     {
1564       if ( !vtkwnd )
1565       {
1566         SUIT_MessageBox::warn1( desktop(), tr( "SMESH_WRN_WARNING" ),
1567           tr( "NOT_A_VTK_VIEWER" ),tr( "SMESH_BUT_OK" ) );
1568         break;
1569       }
1570
1571       if ( checkLock( aStudy ) )
1572         break;
1573
1574       /*Standard_Boolean aRes;
1575       SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IObject);
1576       if ( aMesh->_is_nil() )
1577       {
1578         SUIT_MessageBox::warn1(GetDesktop(), tr( "SMESH_WRN_WARNING" ),
1579           tr( "SMESH_BAD_SELECTION" ), tr( "SMESH_BUT_OK" ) );
1580         break;
1581       }
1582       */
1583       EmitSignalDeactivateDialog();
1584       if ( theCommandID == 407 )
1585         new SMESHGUI_TrianglesInversionDlg(this);
1586       else
1587         new SMESHGUI_UnionOfTwoTrianglesDlg(this);
1588       break;
1589     }
1590     case 409: // Change orientation
1591     case 410: // Union of triangles
1592     case 411: // Cutting of quadrangles
1593     {
1594       if ( !vtkwnd )
1595       {
1596         SUIT_MessageBox::warn1( desktop(), tr( "SMESH_WRN_WARNING" ),
1597           tr( "NOT_A_VTK_VIEWER" ),tr( "SMESH_BUT_OK" ) );
1598         break;
1599       }
1600
1601       if ( checkLock( aStudy ) )
1602         break;
1603
1604       EmitSignalDeactivateDialog();
1605       SMESHGUI_MultiEditDlg* aDlg = NULL;
1606       if ( theCommandID == 409 )
1607         aDlg = new SMESHGUI_ChangeOrientationDlg(this);
1608       else if ( theCommandID == 410 )
1609         aDlg = new SMESHGUI_UnionOfTrianglesDlg(this);
1610       else
1611         aDlg = new SMESHGUI_CuttingOfQuadsDlg(this);
1612
1613       aDlg->show();
1614       break;
1615     }
1616   case 412: // Smoothing
1617     {
1618       if(checkLock(aStudy)) break;
1619       if( vtkwnd ) {
1620         EmitSignalDeactivateDialog();
1621         new SMESHGUI_SmoothingDlg( this );
1622       }
1623       else {
1624         SUIT_MessageBox::warn1(desktop(),
1625                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1626                               tr("SMESH_BUT_OK"));
1627       }
1628       break;
1629     }
1630   case 413: // Extrusion
1631     {
1632       if (checkLock(aStudy)) break;
1633       if (vtkwnd) {
1634         EmitSignalDeactivateDialog();
1635         new SMESHGUI_ExtrusionDlg ( this );
1636       } else {
1637         SUIT_MessageBox::warn1(desktop(),
1638                                tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1639                                tr("SMESH_BUT_OK"));
1640       }
1641       break;
1642     }
1643   case 414: // Revolution
1644     {
1645       if(checkLock(aStudy)) break;
1646       if( vtkwnd ) {
1647         EmitSignalDeactivateDialog();
1648         new SMESHGUI_RevolutionDlg( this );
1649       }
1650       else {
1651         SUIT_MessageBox::warn1(desktop(),
1652                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1653                               tr("SMESH_BUT_OK"));
1654       }
1655       break;
1656     }
1657   case 415: // Pattern mapping
1658     {
1659       if ( checkLock( aStudy ) )
1660         break;
1661       if ( vtkwnd )
1662       {
1663         EmitSignalDeactivateDialog();
1664         new SMESHGUI_MeshPatternDlg( this );
1665       }
1666       else {
1667         SUIT_MessageBox::warn1(desktop(),
1668                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1669                               tr("SMESH_BUT_OK"));
1670       }
1671       break;
1672     }
1673   case 416: // Extrusion along a path
1674     {
1675       if (checkLock(aStudy)) break;
1676       if (vtkwnd) {
1677         EmitSignalDeactivateDialog();
1678         new SMESHGUI_ExtrusionAlongPathDlg( this );
1679       } else {
1680         SUIT_MessageBox::warn1(desktop(),
1681                                tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1682                                tr("SMESH_BUT_OK"));
1683       }
1684       break;
1685     }
1686   case 417: // Convert mesh to quadratic
1687     {
1688     startOperation( 417 );
1689       /*      if (checkLock(aStudy)) break;
1690       if (vtkwnd) {
1691         EmitSignalDeactivateDialog();
1692         new SMESHGUI_ConvToQuadDlg();
1693       } else {
1694         SUIT_MessageBox::warn1(desktop(),
1695                                tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
1696                                tr("SMESH_BUT_OK"));
1697                                }*/
1698       break;
1699     }
1700   case 801:                                     // CREATE GROUP
1701     {
1702       if ( !vtkwnd )
1703       {
1704         SUIT_MessageBox::warn1( desktop(), tr( "SMESH_WRN_WARNING" ),
1705           tr( "NOT_A_VTK_VIEWER" ),tr( "SMESH_BUT_OK" ) );
1706         break;
1707       }
1708
1709       if(checkLock(aStudy)) break;
1710       EmitSignalDeactivateDialog();
1711       SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_nil();
1712
1713       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1714       SALOME_ListIO selected;
1715       if( aSel )
1716         aSel->selectedObjects( selected );
1717
1718       int nbSel = selected.Extent();
1719       if (nbSel == 1) {
1720         // check if mesh is selected
1721         aMesh = SMESH::GetMeshByIO( selected.First() );
1722       }
1723       SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, "", aMesh);
1724       aDlg->show();
1725       break;
1726     }
1727
1728   case 802:                                     // CONSTRUCT GROUP
1729     {
1730       if ( !vtkwnd )
1731       {
1732         SUIT_MessageBox::warn1( desktop(), tr( "SMESH_WRN_WARNING" ),
1733           tr( "NOT_A_VTK_VIEWER" ),tr( "SMESH_BUT_OK" ) );
1734         break;
1735       }
1736
1737       if(checkLock(aStudy)) break;
1738       EmitSignalDeactivateDialog();
1739
1740       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1741       SALOME_ListIO selected;
1742       if( aSel )
1743         aSel->selectedObjects( selected );
1744
1745       int nbSel = selected.Extent();
1746       if (nbSel == 1) {
1747         // check if submesh is selected
1748         Handle(SALOME_InteractiveObject) IObject = selected.First();
1749         if (IObject->hasEntry()) {
1750           _PTR(SObject) aSObj = aStudy->FindObjectID(IObject->getEntry());
1751           if( aSObj ) {
1752             SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow( SMESH::SObjectToObject( aSObj ) );
1753             if (!aSubMesh->_is_nil()) {
1754               try {
1755                 SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
1756                 // get submesh elements list by types
1757                 SMESH::long_array_var aNodes = aSubMesh->GetElementsByType(SMESH::NODE);
1758                 SMESH::long_array_var aEdges = aSubMesh->GetElementsByType(SMESH::EDGE);
1759                 SMESH::long_array_var aFaces = aSubMesh->GetElementsByType(SMESH::FACE);
1760                 SMESH::long_array_var aVolumes = aSubMesh->GetElementsByType(SMESH::VOLUME);
1761                 // create group for each type o elements
1762                 QString aName = IObject->getName();
1763                 if (aNodes->length() > 0) {
1764                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::NODE, aName + "_Nodes");
1765                   aGroup->Add(aNodes.inout());
1766                 }
1767                 if (aEdges->length() > 0) {
1768                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::EDGE, aName + "_Edges");
1769                   aGroup->Add(aEdges.inout());
1770                 }
1771                 if (aFaces->length() > 0) {
1772                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::FACE, aName + "_Faces");
1773                   aGroup->Add(aFaces.inout());
1774                 }
1775                 if (aVolumes->length() > 0) {
1776                   SMESH::SMESH_Group_var aGroup = SMESH::AddGroup(aMesh, SMESH::VOLUME, aName + "_Volumes");
1777                   aGroup->Add(aVolumes.inout());
1778                 }
1779                 updateObjBrowser();
1780
1781               }
1782               catch(const SALOME::SALOME_Exception & S_ex){
1783                 SalomeApp_Tools::QtCatchCorbaException(S_ex);
1784               }
1785             }
1786           }
1787         }
1788       }
1789       else if(nbSel==0) {
1790         SUIT_MessageBox::warn1(desktop(),
1791                                tr("SMESH_WRN_WARNING"),
1792                                tr("SMESH_WRN_NO_AVAILABLE_DATA"),
1793                                tr("SMESH_BUT_OK"));
1794       }
1795       break;
1796     }
1797
1798   case 803:                                     // EDIT GROUP
1799     {
1800       if ( !vtkwnd )
1801       {
1802         SUIT_MessageBox::warn1( desktop(), tr( "SMESH_WRN_WARNING" ),
1803           tr( "NOT_A_VTK_VIEWER" ),tr( "SMESH_BUT_OK" ) );
1804         break;
1805       }
1806
1807       if(checkLock(aStudy)) break;
1808       EmitSignalDeactivateDialog();
1809
1810       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1811       SALOME_ListIO selected;
1812       if( aSel )
1813         aSel->selectedObjects( selected );
1814
1815       SALOME_ListIteratorOfListIO It (selected);
1816       int nbSelectedGroups = 0;
1817       for ( ; It.More(); It.Next() )
1818       {
1819         SMESH::SMESH_GroupBase_var aGroup =
1820           SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(It.Value());
1821         if (!aGroup->_is_nil()) {
1822           nbSelectedGroups++;
1823           SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, "", aGroup);
1824           aDlg->show();
1825         }
1826       }
1827       if (nbSelectedGroups == 0)
1828         {
1829           SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, "", SMESH::SMESH_GroupBase::_nil());
1830           aDlg->show();
1831         }
1832       break;
1833     }
1834
1835   case 804:                                     // Add elements to group
1836     {
1837       if(checkLock(aStudy)) break;
1838       if (myState == 800) {
1839         SMESHGUI_GroupDlg *aDlg = (SMESHGUI_GroupDlg*) myActiveDialogBox;
1840         if (aDlg) aDlg->onAdd();
1841       }
1842       break;
1843     }
1844
1845   case 805:                                     // Remove elements from group
1846     {
1847       if(checkLock(aStudy)) break;
1848       if (myState == 800) {
1849         SMESHGUI_GroupDlg *aDlg = (SMESHGUI_GroupDlg*) myActiveDialogBox;
1850         if (aDlg) aDlg->onRemove();
1851       }
1852       break;
1853     }
1854
1855     case 810: // Union Groups
1856     case 811: // Intersect groups
1857     case 812: // Cut groups
1858     {
1859       if ( !vtkwnd )
1860       {
1861         SUIT_MessageBox::warn1( desktop(), tr( "SMESH_WRN_WARNING" ),
1862           tr( "NOT_A_VTK_VIEWER" ),tr( "SMESH_BUT_OK" ) );
1863         break;
1864       }
1865
1866       if ( checkLock( aStudy ) )
1867         break;
1868
1869       EmitSignalDeactivateDialog();
1870
1871       int aMode;
1872       if      ( theCommandID == 810 ) aMode = SMESHGUI_GroupOpDlg::UNION;
1873       else if ( theCommandID == 811 ) aMode = SMESHGUI_GroupOpDlg::INTERSECT;
1874       else                            aMode = SMESHGUI_GroupOpDlg::CUT;
1875
1876       ( new SMESHGUI_GroupOpDlg( this, aMode ) )->show();
1877       break;
1878     }
1879
1880     case 813: // Delete groups with their contents
1881     {
1882       if ( !vtkwnd )
1883       {
1884         SUIT_MessageBox::warn1( desktop(), tr( "SMESH_WRN_WARNING" ),
1885           tr( "NOT_A_VTK_VIEWER" ),tr( "SMESH_BUT_OK" ) );
1886         break;
1887       }
1888
1889       if ( checkLock( aStudy ) )
1890         break;
1891
1892       EmitSignalDeactivateDialog();
1893
1894       new SMESHGUI_DeleteGroupDlg( this );
1895       break;
1896     }
1897
1898   case 900:                                     // MESH INFOS
1899     {
1900       EmitSignalDeactivateDialog();
1901       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1902       SALOME_ListIO selected;
1903       if( aSel )
1904         aSel->selectedObjects( selected );
1905
1906       if ( selected.Extent() > 1 ) { // a dlg for each IO
1907         SALOME_ListIO IOs;
1908         SALOME_ListIteratorOfListIO It (selected);
1909         for ( ; It.More(); It.Next() ) {
1910           IOs.Clear(); IOs.Append( It.Value() );
1911           aSel->setSelectedObjects( IOs );
1912           new SMESHGUI_MeshInfosDlg(this, "", false);
1913         }
1914         // restore selection
1915         aSel->setSelectedObjects( selected );
1916       }
1917       else
1918         new SMESHGUI_MeshInfosDlg(this, "", false);
1919       break;
1920     }
1921
1922   case 902:                                     // STANDARD MESH INFOS
1923     {
1924       EmitSignalDeactivateDialog();
1925       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1926       SALOME_ListIO selected;
1927       if( aSel )
1928         aSel->selectedObjects( selected );
1929
1930       if ( selected.Extent() > 1 ) { // a dlg for each IO
1931         SALOME_ListIO IOs;
1932         SALOME_ListIteratorOfListIO It (selected);
1933         for ( ; It.More(); It.Next() ) {
1934           IOs.Clear();
1935           IOs.Append( It.Value() );
1936           aSel->setSelectedObjects( IOs );
1937           new SMESHGUI_StandardMeshInfosDlg( this, "", false);
1938         }
1939         // restore selection
1940         aSel->setSelectedObjects( selected );
1941       }
1942       else
1943         new SMESHGUI_StandardMeshInfosDlg( this, "", false);
1944       break;
1945     }
1946
1947   case 903:                                     // WHAT IS
1948     {
1949       EmitSignalDeactivateDialog();
1950       new SMESHGUI_WhatIsDlg( this, "", false);
1951       break;
1952     }
1953
1954   case 1100:                                    // EDIT HYPOTHESIS
1955     {
1956       if(checkLock(aStudy)) break;
1957
1958       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1959       SALOME_ListIO selected;
1960       if( aSel )
1961         aSel->selectedObjects( selected );
1962
1963       int nbSel = selected.Extent();
1964
1965       if (nbSel == 1) {
1966         Handle(SALOME_InteractiveObject) anIObject = selected.First();
1967         SMESH::SMESH_Hypothesis_var aHypothesis = SMESH::IObjectToInterface<SMESH::SMESH_Hypothesis>(anIObject);
1968
1969         /* Look for all mesh objects that have this hypothesis affected in order to flag as ModifiedMesh */
1970         /* At end below '...->updateObjBrowser(true)' will change icon of mesh objects                   */
1971         /* Warning : however by internal mechanism all subMeshes icons are changed !                     */
1972         if ( !aHypothesis->_is_nil() )
1973         {
1974           CORBA::String_var aHypType = aHypothesis->GetName();
1975           SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHypType);
1976           if (aCreator)
1977             aCreator->edit( aHypothesis.in(), anIObject->getName(), desktop() );
1978           else
1979           {
1980             // report error
1981           }
1982         }
1983       }
1984       updateObjBrowser( true );
1985       break;
1986     }
1987
1988   case 1101:                                    // RENAME
1989     {
1990       if ( checkLock( aStudy ) )
1991         break;
1992
1993       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
1994       SALOME_ListIO selected;
1995       if( aSel )
1996         aSel->selectedObjects( selected );
1997
1998       bool isAny = false; // iss there any appropriate object selected
1999
2000       SALOME_ListIteratorOfListIO It( selected );
2001       for ( ; It.More(); It.Next() )
2002       {
2003         Handle(SALOME_InteractiveObject) IObject = It.Value();
2004         _PTR(SObject) obj = aStudy->FindObjectID( IObject->getEntry() );
2005         _PTR(GenericAttribute) anAttr;
2006         _PTR(AttributeName) aName;
2007         if ( obj )
2008         {
2009           if ( obj->FindAttribute(anAttr, "AttributeName") )
2010           {
2011             aName = anAttr;
2012             QString newName = QString(aName->Value().c_str());
2013
2014             // check type to prevent renaming of inappropriate objects
2015             int aType = SMESHGUI_Selection::type(IObject->getEntry(), aStudy);
2016             if (aType == MESH || aType == GROUP ||
2017                 aType == SUBMESH || aType == SUBMESH_COMPOUND ||
2018                 aType == SUBMESH_SOLID || aType == SUBMESH_FACE ||
2019                 aType == SUBMESH_EDGE || aType == SUBMESH_VERTEX ||
2020                 aType == HYPOTHESIS || aType == ALGORITHM)
2021             {
2022               isAny = true;
2023               newName = LightApp_NameDlg::getName(desktop(), newName);
2024               if ( !newName.isEmpty() )
2025               {
2026                 //old source: aStudy->renameIObject( IObject, newName );
2027                 aName->SetValue( newName.latin1() );
2028
2029                 // if current object is group update group's name
2030                 SMESH::SMESH_GroupBase_var aGroup =
2031                   SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IObject);
2032                 if (!aGroup->_is_nil() )
2033                   aGroup->SetName( newName.latin1() );
2034
2035                 updateObjBrowser();
2036               }
2037             }
2038           }
2039         }
2040       } // for
2041
2042       if (!isAny) {
2043         SUIT_MessageBox::warn1(desktop(),
2044                                QObject::tr("SMESH_WRN_WARNING"),
2045                                QObject::tr("SMESH_WRN_NO_APPROPRIATE_SELECTION"),
2046                                QObject::tr("SMESH_BUT_OK"));
2047       }
2048       break;
2049     }
2050
2051   case 1102:                                    // REMOVE HYPOTHESIS / ALGORITHMS
2052     {
2053       if(checkLock(aStudy)) break;
2054       SUIT_OverrideCursor wc;
2055
2056       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
2057       SALOME_ListIO selected;
2058       if( aSel )
2059         aSel->selectedObjects( selected, QString::null, false );
2060
2061       SALOME_ListIteratorOfListIO It(selected);
2062       for (int i = 0; It.More(); It.Next(), i++) {
2063         Handle(SALOME_InteractiveObject) IObject = It.Value();
2064         SMESH::RemoveHypothesisOrAlgorithmOnMesh(IObject);
2065       }
2066       SALOME_ListIO l1;
2067       aSel->setSelectedObjects( l1 );
2068       updateObjBrowser();
2069       break;
2070     }
2071
2072   case 401:                                     // GEOM::EDGE
2073   case 4021:                                    // TRIANGLE
2074   case 4022:                                    // QUAD
2075   case 4023:                                    // POLYGON
2076   case 4031:                                    // TETRA
2077   case 4032:                                    // HEXA
2078     {
2079       if(checkLock(aStudy)) break;
2080       if ( vtkwnd ) {
2081         EmitSignalDeactivateDialog();
2082         SMDSAbs_ElementType type    = SMDSAbs_Edge;
2083         int                 nbNodes = 2;
2084         switch (theCommandID) {
2085         case 4021:                                      // TRIANGLE
2086           type = SMDSAbs_Face; nbNodes = 3; break;
2087         case 4022:                                      // QUAD
2088           type = SMDSAbs_Face; nbNodes = 4; break;
2089         case 4031:                                      // TETRA
2090           type = SMDSAbs_Volume; nbNodes = 4; break;
2091         case 4023:                                      // POLYGON
2092           type = SMDSAbs_Face; nbNodes = 5; break;     // 5 - identificator for POLYGON
2093         case 4032:                                      // HEXA
2094           type = SMDSAbs_Volume; nbNodes = 8; break;
2095         case 4033:                                      // POLYHEDRE
2096           type = SMDSAbs_Volume; nbNodes = 9; break; // 9 - identificator for POLYHEDRE
2097         default:;
2098         }
2099         new SMESHGUI_AddMeshElementDlg( this, "", type, nbNodes);
2100       }
2101       else {
2102         SUIT_MessageBox::warn1(desktop(),
2103                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2104                               tr("SMESH_BUT_OK"));
2105       }
2106       break;
2107     }
2108   case 4033:                                    // POLYHEDRON
2109     {
2110       if(checkLock(aStudy)) break;
2111       if ( vtkwnd ) {
2112         EmitSignalDeactivateDialog();
2113         new SMESHGUI_CreatePolyhedralVolumeDlg(this, "", FALSE );
2114       }
2115       else {
2116         SUIT_MessageBox::warn1(SMESHGUI::desktop(),
2117                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2118                               tr("SMESH_BUT_OK"));
2119       }
2120       break;
2121     }
2122   case 4034:     // QUADRATIC EDGE
2123   case 4035:     // QUADRATIC TRIANGLE
2124   case 4036:     // QUADRATIC QUADRANGLE
2125   case 4037:     // QUADRATIC TETRAHEDRON
2126   case 4038:     // QUADRATIC PYRAMID
2127   case 4039:     // QUADRATIC PENTAHEDRON
2128   case 4040:     // QUADRATIC HEXAHEDRON
2129     {
2130       if(checkLock(aStudy)) break;
2131       if ( vtkwnd ) {
2132         EmitSignalDeactivateDialog();
2133         int type;
2134
2135         switch (theCommandID) {
2136         case 4034:
2137           type = QUAD_EDGE; break;
2138         case 4035:
2139           type = QUAD_TRIANGLE; break;
2140         case 4036:
2141           type = QUAD_QUADRANGLE; break;
2142         case 4037:
2143           type = QUAD_TETRAHEDRON; break;
2144         case 4038:
2145           type = QUAD_PYRAMID; break;
2146         case 4039:
2147           type = QUAD_PENTAHEDRON; break;
2148         case 4040:
2149           type = QUAD_HEXAHEDRON;
2150           break;
2151         default:;
2152         }
2153          new SMESHGUI_AddQuadraticElementDlg( this, type );
2154       }
2155       else {
2156         SUIT_MessageBox::warn1(SMESHGUI::desktop(),
2157                                tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2158                                tr("SMESH_BUT_OK"));
2159       }
2160       break;
2161     }
2162   case 4041:                                    // REMOVES NODES
2163     {
2164       if(checkLock(aStudy)) break;
2165       if ( vtkwnd ) {
2166         EmitSignalDeactivateDialog();
2167         new SMESHGUI_RemoveNodesDlg(this);
2168       }
2169       else {
2170         SUIT_MessageBox::warn1(desktop(),
2171                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2172                               tr("SMESH_BUT_OK"));
2173       }
2174       break;
2175     }
2176   case 4042:                                    // REMOVES ELEMENTS
2177     {
2178       if(checkLock(aStudy)) break;
2179       if( vtkwnd ) {
2180         EmitSignalDeactivateDialog();
2181         new SMESHGUI_RemoveElementsDlg(this);
2182       }
2183       else
2184         {
2185           SUIT_MessageBox::warn1(desktop(),
2186                                 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2187                                 tr("SMESH_BUT_OK"));
2188         }
2189       break;
2190     }
2191   case 4043: {                                // CLEAR_MESH
2192
2193     if(checkLock(aStudy)) break;
2194     
2195     SALOME_ListIO selected;
2196     if( LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr() )
2197       aSel->selectedObjects( selected );
2198
2199     SUIT_OverrideCursor wc;
2200     SALOME_ListIteratorOfListIO It (selected);
2201     for ( ; It.More(); It.Next() )
2202     {
2203       Handle(SALOME_InteractiveObject) IOS = It.Value();
2204       SMESH::SMESH_Mesh_var aMesh =
2205         SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IOS);
2206       if ( aMesh->_is_nil()) continue;
2207       try {
2208         SMESH::UpdateView(SMESH::eErase, IOS->getEntry());
2209         aMesh->Clear();
2210         _PTR(SObject) aMeshSObj = SMESH::FindSObject(aMesh);
2211         SMESH::ModifiedMesh( aMeshSObj, false, true);
2212         // hide groups and submeshes
2213         _PTR(ChildIterator) anIter =
2214           SMESH::GetActiveStudyDocument()->NewChildIterator( aMeshSObj );
2215         for ( anIter->InitEx(true); anIter->More(); anIter->Next() )
2216         {
2217           _PTR(SObject) so = anIter->Value();
2218           SMESH::UpdateView(SMESH::eErase, so->GetID().c_str());
2219         }
2220       }
2221       catch (const SALOME::SALOME_Exception& S_ex){
2222         wc.suspend();
2223         SalomeApp_Tools::QtCatchCorbaException(S_ex);
2224         wc.resume();
2225       }
2226     }
2227     SMESH::UpdateView();
2228     updateObjBrowser();
2229     break;
2230   }
2231   case 4051:                                    // RENUMBERING NODES
2232     {
2233       if(checkLock(aStudy)) break;
2234       if( vtkwnd ) {
2235         EmitSignalDeactivateDialog();
2236         new SMESHGUI_RenumberingDlg( this, "", 0);
2237       }
2238       else
2239         {
2240           SUIT_MessageBox::warn1(desktop(),
2241                                 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2242                                 tr("SMESH_BUT_OK"));
2243         }
2244       break;
2245     }
2246   case 4052:                                    // RENUMBERING ELEMENTS
2247     {
2248       if(checkLock(aStudy)) break;
2249       if ( vtkwnd ) {
2250         EmitSignalDeactivateDialog();
2251         new SMESHGUI_RenumberingDlg( this, "", 1);
2252       }
2253       else
2254         {
2255           SUIT_MessageBox::warn1(desktop(),
2256                                 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2257                                 tr("SMESH_BUT_OK"));
2258         }
2259       break;
2260     }
2261   case 4061:                                   // TRANSLATION
2262     {
2263       if(checkLock(aStudy)) break;
2264       if ( vtkwnd ) {
2265         EmitSignalDeactivateDialog();
2266         new SMESHGUI_TranslationDlg( this );
2267       }
2268       else {
2269         SUIT_MessageBox::warn1(desktop(),
2270                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2271                               tr("SMESH_BUT_OK"));
2272       }
2273       break;
2274     }
2275   case 4062:                                   // ROTATION
2276     {
2277       if(checkLock(aStudy)) break;
2278       if( vtkwnd ) {
2279         EmitSignalDeactivateDialog();
2280         new SMESHGUI_RotationDlg( this );
2281       }
2282       else {
2283         SUIT_MessageBox::warn1(desktop(),
2284                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2285                               tr("SMESH_BUT_OK"));
2286       }
2287       break;
2288     }
2289   case 4063:                                   // SYMMETRY
2290     {
2291       if(checkLock(aStudy)) break;
2292       if(vtkwnd) {
2293         EmitSignalDeactivateDialog();
2294         new SMESHGUI_SymmetryDlg( this );
2295       }
2296       else {
2297         SUIT_MessageBox::warn1(desktop(),
2298                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2299                               tr("SMESH_BUT_OK"));
2300       }
2301       break;
2302     }
2303   case 4064:                                   // SEWING
2304     {
2305       if(checkLock(aStudy)) break;
2306       if(vtkwnd) {
2307         EmitSignalDeactivateDialog();
2308         new SMESHGUI_SewingDlg( this );
2309       }
2310       else {
2311         SUIT_MessageBox::warn1(desktop(),
2312                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2313                               tr("SMESH_BUT_OK"));
2314       }
2315       break;
2316     }
2317   case 4065:                                   // MERGE NODES
2318     {
2319       if(checkLock(aStudy)) break;
2320       if(vtkwnd) {
2321         EmitSignalDeactivateDialog();
2322         new SMESHGUI_EditMeshDlg( this, 0 );
2323       }
2324       else {
2325         SUIT_MessageBox::warn1(desktop(),
2326                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2327                               tr("SMESH_BUT_OK"));
2328       }
2329       break;
2330     }
2331   case 4066:                                   // MERGE EQUAL ELEMENTS
2332     {
2333       if (checkLock(aStudy)) break;
2334       if (vtkwnd) {
2335         EmitSignalDeactivateDialog();
2336         new SMESHGUI_EditMeshDlg( this, 1 );
2337       } else {
2338         SUIT_MessageBox::warn1(desktop(),
2339                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2340                               tr("SMESH_BUT_OK"));
2341       }
2342       break;
2343     }
2344
2345   case 4067: // MAKE MESH PASS THROUGH POINT
2346     startOperation( 4067 );
2347     break;
2348
2349   case 5105: // Library of selection filters
2350   {
2351     static QValueList<int> aTypes;
2352     if ( aTypes.isEmpty() )
2353     {
2354       aTypes.append( SMESH::NODE );
2355       aTypes.append( SMESH::EDGE );
2356       aTypes.append( SMESH::FACE );
2357       aTypes.append( SMESH::VOLUME );
2358     }
2359     if (!myFilterLibraryDlg)
2360       myFilterLibraryDlg = new SMESHGUI_FilterLibraryDlg( this, SMESH::GetDesktop( this ), aTypes, SMESHGUI_FilterLibraryDlg::EDIT );
2361     else if (myFilterLibraryDlg->isHidden())
2362       myFilterLibraryDlg->Init( aTypes, SMESHGUI_FilterLibraryDlg::EDIT );
2363     myFilterLibraryDlg->raise();
2364   }
2365   break;
2366
2367   case 6017:                                    // CONTROLS
2368   case 6016:
2369   case 6015:
2370   case 6014:
2371   case 6013:
2372   case 6012:
2373   case 6011:
2374   case 6001:
2375   case 6018:
2376   case 6019:
2377   case 6002:
2378   case 6003:
2379   case 6004:
2380   case 6009:
2381     if ( vtkwnd ) {
2382
2383       LightApp_SelectionMgr* mgr = selectionMgr();
2384       SALOME_ListIO selected; mgr->selectedObjects( selected );
2385
2386       if ( selected.Extent() == 1 && selected.First()->hasEntry() ) {
2387         _PTR(SObject) SO = aStudy->FindObjectID( selected.First()->getEntry() );
2388         if ( SO ) {
2389           CORBA::Object_var aObject = SMESH::SObjectToObject( SO );
2390           SMESH::SMESH_Mesh_var      aMesh    = SMESH::SMESH_Mesh::_narrow( aObject );
2391           SMESH::SMESH_subMesh_var   aSubMesh = SMESH::SMESH_subMesh::_narrow( aObject );
2392           SMESH::SMESH_GroupBase_var aGroup   = SMESH::SMESH_GroupBase::_narrow( aObject );
2393           if ( !aMesh->_is_nil() || !aSubMesh->_is_nil() || !aGroup->_is_nil() ) {
2394             ::Control( theCommandID );
2395             break;
2396           }
2397         }
2398       }
2399       SUIT_MessageBox::warn1(desktop(),
2400                             tr( "SMESH_WRN_WARNING" ),
2401                             tr( "SMESH_BAD_SELECTION" ),
2402                             tr( "SMESH_BUT_OK" ) );
2403       break;
2404     }
2405     else {
2406       SUIT_MessageBox::warn1(desktop(),
2407                             tr( "SMESH_WRN_WARNING" ),
2408                             tr( "NOT_A_VTK_VIEWER" ),
2409                             tr( "SMESH_BUT_OK" ) );
2410     }
2411     break;
2412   case 9010:
2413     {
2414       LightApp_SelectionMgr* mgr = selectionMgr();
2415       SALOME_ListIO selected; mgr->selectedObjects( selected );
2416
2417       SALOME_ListIteratorOfListIO it(selected);
2418       for(; it.More(); it.Next()) {
2419         Handle(SALOME_InteractiveObject) anIObject = it.Value();
2420         if(anIObject->hasEntry()) {
2421           if(SMESH_Actor *anActor = SMESH::FindActorByEntry(anIObject->getEntry())){
2422             anActor->SetPointsLabeled( !anActor->GetPointsLabeled() );
2423           }
2424         }
2425       }
2426       break;
2427     }
2428   case 9011:
2429     {
2430       LightApp_SelectionMgr* mgr = selectionMgr();
2431       SALOME_ListIO selected; mgr->selectedObjects( selected );
2432
2433       if (selected.Extent() == 1)       {
2434         Handle(SALOME_InteractiveObject) anIObject = selected.First();
2435         if(anIObject->hasEntry())
2436           if(SMESH_Actor *anActor = SMESH::FindActorByEntry(anIObject->getEntry())){
2437             anActor->SetCellsLabeled( !anActor->GetCellsLabeled() );
2438           }
2439       }
2440       break;
2441     }
2442   }
2443
2444   anApp->updateActions(); //SRN: To update a Save button in the toolbar
2445   //updateObjBrowser();
2446   return true;
2447 }
2448
2449 //=============================================================================
2450 /*!
2451  *
2452  */
2453 //=============================================================================
2454 bool SMESHGUI::OnMousePress( QMouseEvent * pe, SUIT_ViewWindow * wnd )
2455 {
2456   return false;
2457 }
2458
2459 //=============================================================================
2460 /*!
2461  *
2462  */
2463 //=============================================================================
2464 bool SMESHGUI::OnMouseMove( QMouseEvent * pe, SUIT_ViewWindow * wnd )
2465 {
2466   return true;
2467 }
2468
2469 //=============================================================================
2470 /*!
2471  *
2472  */
2473 //=============================================================================
2474 bool SMESHGUI::OnKeyPress( QKeyEvent * pe, SUIT_ViewWindow * wnd )
2475 {
2476   return true;
2477 }
2478
2479 //=============================================================================
2480 /*! Method:  BuildPresentation(const Handle(SALOME_InteractiveObject)& theIO)
2481  *  Purpose: ensures that the actor for the given <theIO> exists in the active VTK view
2482  */
2483 //=============================================================================
2484 void SMESHGUI::BuildPresentation( const Handle(SALOME_InteractiveObject) & theIO,
2485                                   SUIT_ViewWindow* wnd )
2486 {
2487   if(theIO->hasEntry()){
2488     //SUIT_ViewWindow* wnd = SMESH::GetActiveWindow();
2489     SMESH::UpdateView(wnd,SMESH::eDisplay,theIO->getEntry());
2490   }
2491 }
2492
2493 //=======================================================================
2494 // function : createSMESHAction
2495 // purpose  :
2496 //=======================================================================
2497 void SMESHGUI::createSMESHAction( const int id, const QString& po_id, const QString& icon_id, const int key, const bool toggle  )
2498 {
2499   QIconSet icon;
2500   QWidget* parent = application()->desktop();
2501   SUIT_ResourceMgr* resMgr = resourceMgr();
2502   QPixmap pix;
2503   if ( icon_id.length() )
2504     pix = resMgr->loadPixmap( "SMESH", tr( icon_id ) );
2505   else
2506     pix = resMgr->loadPixmap( "SMESH", tr( QString( "ICO_" )+po_id ), false );
2507   if ( !pix.isNull() )
2508     icon = QIconSet( pix );
2509
2510   QString tooltip    = tr( QString( "TOP_" )+po_id ),
2511           menu       = tr( QString( "MEN_" )+po_id ),
2512           status_bar = tr( QString( "STB_" )+po_id );
2513
2514   createAction( id, tooltip, icon, menu, status_bar, key, parent, toggle, this, SLOT( OnGUIEvent() )  );
2515 }
2516
2517 //=======================================================================
2518 // function : createPopupItem
2519 // purpose  :
2520 //=======================================================================
2521 void SMESHGUI::createPopupItem( const int id,
2522                                 const QString& clients,
2523                                 const QString& types,
2524                                 const QString& theRule,
2525                                 const int pId )
2526 {
2527   int parentId = pId;
2528   if( pId!=-1 )
2529     parentId = popupMgr()->actionId( action( pId ) );
2530
2531   if( !popupMgr()->contains( popupMgr()->actionId( action( id ) ) ) )
2532     popupMgr()->insert( action( id ), parentId, 0 );
2533
2534   QChar lc = QtxPopupMgr::Selection::defEquality();
2535   QString rule = "(%1) and (%2) and (%3)";
2536   rule = rule.arg( QString( "%1>0" ).arg( QtxPopupMgr::Selection::defSelCountParam() ) );
2537   if( clients.isEmpty() )
2538     rule = rule.arg( QString( "true" ) );
2539   else
2540     rule = rule.arg( QString( "%1client in {%2}" ).arg( lc ).arg( clients ) );
2541   rule = rule.arg( QString( "%1type in {%2}" ).arg( lc ).arg( types ) );
2542   rule += theRule;
2543
2544   bool cont = myRules.contains( id );
2545   if( cont )
2546     rule = QString( "%1 or (%2)" ).arg( myRules[ id ] ).arg( rule );
2547
2548   popupMgr()->setRule( action( id ), rule, true );
2549   myRules[ id ] = QString( cont ? "%1" : "(%1)" ).arg( rule );
2550 }
2551
2552 //=======================================================================
2553 // function : initialize
2554 // purpose  :
2555 //=======================================================================
2556 void SMESHGUI::initialize( CAM_Application* app )
2557 {
2558   SalomeApp_Module::initialize( app );
2559
2560 //   SUIT_ResourceMgr* mgr = app->resourceMgr();
2561 //   if ( mgr )
2562   /* Automatic Update flag */
2563 //     myAutomaticUpdate = mgr->booleanValue( "SMESH", "AutomaticUpdate", myAutomaticUpdate );
2564
2565   // ----- create actions --------------
2566
2567   createSMESHAction(  111, "DAT", "", (CTRL+Key_B) );
2568   createSMESHAction(  112, "UNV", "", (CTRL+Key_U) );
2569   createSMESHAction(  113, "MED", "", (CTRL+Key_M) );
2570   createSMESHAction(  114, "NUM" );
2571   createSMESHAction(  121, "DAT" );
2572   createSMESHAction(  122, "MED" );
2573   createSMESHAction(  123, "UNV" );
2574   createSMESHAction(  140, "STL" );
2575   createSMESHAction(  124, "EXPORT_DAT" );
2576   createSMESHAction(  125, "EXPORT_MED" );
2577   createSMESHAction(  126, "EXPORT_UNV" );
2578   createSMESHAction(  141, "EXPORT_STL" );
2579   createSMESHAction(  150, "FILE_INFO" );
2580   createSMESHAction(   33, "DELETE",          "ICON_DELETE", Key_Delete );
2581   createSMESHAction( 5105, "SEL_FILTER_LIB" );
2582   createSMESHAction(  701, "COMPUTE",         "ICON_COMPUTE" );
2583   createSMESHAction(  702, "CREATE_MESH",     "ICON_DLG_INIT_MESH" );
2584   createSMESHAction(  703, "CREATE_SUBMESH",  "ICON_DLG_ADD_SUBMESH" );
2585   createSMESHAction(  704, "EDIT_MESHSUBMESH","ICON_DLG_EDIT_MESH" );
2586   createSMESHAction(  710, "BUILD_COMPOUND",  "ICON_BUILD_COMPOUND" );
2587   createSMESHAction(  801, "CREATE_GROUP",    "ICON_SMESH_TREE_GROUP" );
2588   createSMESHAction(  802, "CONSTRUCT_GROUP", "ICON_CONSTRUCT_GROUP" );
2589   createSMESHAction(  803, "EDIT_GROUP",      "ICON_EDIT_GROUP" );
2590   createSMESHAction(  804, "ADD" );
2591   createSMESHAction(  805, "REMOVE" );
2592   createSMESHAction(  810, "UN_GROUP",        "ICON_UNION" );
2593   createSMESHAction(  811, "INT_GROUP",       "ICON_INTERSECT" );
2594   createSMESHAction(  812, "CUT_GROUP",       "ICON_CUT" );
2595   createSMESHAction(  813, "DEL_GROUP",       "ICON_DEL_GROUP" );
2596   createSMESHAction(  900, "ADV_INFO",        "ICON_ADV_INFO" );
2597   createSMESHAction(  902, "STD_INFO",        "ICON_STD_INFO" );
2598   createSMESHAction(  903, "WHAT_IS",         "ICON_WHAT_IS" );
2599   createSMESHAction( 6001, "LENGTH",          "ICON_LENGTH" ,       0, true );
2600   createSMESHAction( 6002, "FREE_EDGE",       "ICON_FREE_EDGE" ,    0, true );
2601   createSMESHAction( 6003, "FREE_BORDER",     "ICON_FREE_EDGE_2D" , 0, true );
2602   createSMESHAction( 6004, "CONNECTION",      "ICON_CONNECTION" ,   0, true );
2603   createSMESHAction( 6011, "AREA",            "ICON_AREA" ,         0, true );
2604   createSMESHAction( 6012, "TAPER",           "ICON_TAPER" ,        0, true );
2605   createSMESHAction( 6013, "ASPECT",          "ICON_ASPECT" ,       0, true );
2606   createSMESHAction( 6014, "MIN_ANG",         "ICON_ANGLE" ,        0, true );
2607   createSMESHAction( 6015, "WARP",            "ICON_WARP" ,         0, true );
2608   createSMESHAction( 6016, "SKEW",            "ICON_SKEW",          0, true );
2609   createSMESHAction( 6017, "ASPECT_3D",       "ICON_ASPECT_3D",     0, true );
2610   createSMESHAction( 6018, "LENGTH_2D",       "ICON_LENGTH_2D",     0, true );
2611   createSMESHAction( 6019, "CONNECTION_2D",   "ICON_CONNECTION_2D", 0, true );
2612   createSMESHAction( 6009, "VOLUME_3D",       "ICON_VOLUME_3D",     0, true );
2613   createSMESHAction(  400, "NODE",            "ICON_DLG_NODE" );
2614   createSMESHAction(  401, "EDGE",            "ICON_DLG_EDGE" );
2615   createSMESHAction( 4021, "TRIANGLE",        "ICON_DLG_TRIANGLE" );
2616   createSMESHAction( 4022, "QUAD",            "ICON_DLG_QUADRANGLE" );
2617   createSMESHAction( 4023, "POLYGON",         "ICON_DLG_POLYGON" );
2618   createSMESHAction( 4031, "TETRA",           "ICON_DLG_TETRAS" );
2619   createSMESHAction( 4032, "HEXA",            "ICON_DLG_HEXAS" );
2620   createSMESHAction( 4041, "REMOVE_NODES",    "ICON_DLG_REM_NODE" );
2621   createSMESHAction( 4042, "REMOVE_ELEMENTS", "ICON_DLG_REM_ELEMENT" );
2622   createSMESHAction( 4043, "CLEAR_MESH"    ,  "ICON_CLEAR_MESH" );
2623   createSMESHAction( 4051, "RENUM_NODES",     "ICON_DLG_RENUMBERING_NODES" );
2624   createSMESHAction( 4052, "RENUM_ELEMENTS",  "ICON_DLG_RENUMBERING_ELEMENTS" );
2625   createSMESHAction( 4061, "TRANS",           "ICON_SMESH_TRANSLATION_VECTOR" );
2626   createSMESHAction( 4062, "ROT",             "ICON_DLG_MESH_ROTATION" );
2627   createSMESHAction( 4063, "SYM",             "ICON_SMESH_SYMMETRY_PLANE" );
2628   createSMESHAction( 4064, "SEW",             "ICON_SMESH_SEWING_FREEBORDERS" );
2629   createSMESHAction( 4065, "MERGE",           "ICON_SMESH_MERGE_NODES" );
2630   createSMESHAction( 4066, "MERGE_ELEMENTS",  "ICON_DLG_MERGE_ELEMENTS" );
2631   createSMESHAction( 4067, "MESH_THROU_POINT","ICON_DLG_MESH_THROU_POINT" );
2632   createSMESHAction(  406, "MOVE",            "ICON_DLG_MOVE_NODE" );
2633   createSMESHAction(  407, "INV",             "ICON_DLG_MESH_DIAGONAL" );
2634   createSMESHAction(  408, "UNION2",          "ICON_UNION2TRI" );
2635   createSMESHAction(  409, "ORIENT",          "ICON_DLG_MESH_ORIENTATION" );
2636   createSMESHAction(  410, "UNION",           "ICON_UNIONTRI" );
2637   createSMESHAction(  411, "CUT",             "ICON_CUTQUAD" );
2638   createSMESHAction(  412, "SMOOTH",          "ICON_DLG_SMOOTHING" );
2639   createSMESHAction(  413, "EXTRUSION",       "ICON_EXTRUSION" );
2640   createSMESHAction(  414, "REVOLUTION",      "ICON_REVOLUTION" );
2641   createSMESHAction(  415, "MAP",             "ICON_MAP" );
2642   createSMESHAction(  416, "EXTRUSION_ALONG", "ICON_EXTRUSION_ALONG" );
2643   createSMESHAction(  417, "CONV_TO_QUAD",    "ICON_CONV_TO_QUAD" );
2644   createSMESHAction(  200, "RESET" );
2645   createSMESHAction(  201, "SCALAR_BAR_PROP" );
2646   createSMESHAction(  211, "WIRE",           "ICON_WIRE", 0, true );
2647   createSMESHAction(  212, "SHADE",          "ICON_SHADE", 0, true );
2648   createSMESHAction(  213, "SHRINK",         "ICON_SHRINK", 0, true );
2649   createSMESHAction(  214, "UPDATE",         "ICON_UPDATE" );
2650   createSMESHAction(  215, "NODES",          "ICON_POINTS", 0, true );
2651   createSMESHAction(  217, "EDGES",          "ICON_DLG_EDGE", 0, true );
2652   createSMESHAction(  218, "FACES",          "ICON_DLG_TRIANGLE", 0, true );
2653   createSMESHAction(  219, "VOLUMES",        "ICON_DLG_TETRAS", 0, true );
2654   createSMESHAction(  220, "ALL" );
2655   createSMESHAction( 1100, "EDIT_HYPO" );
2656   createSMESHAction( 1101, "RENAME", "", Key_F2 );
2657   createSMESHAction( 1102, "UNASSIGN" );
2658   createSMESHAction( 9010, "NUM_NODES", "", 0, true );
2659   createSMESHAction( 9011, "NUM_ELEMENTS", "", 0, true );
2660   createSMESHAction( 1131, "DISPMODE" );
2661   createSMESHAction( 1132, "COLORS" );
2662   createSMESHAction( 1133, "TRANSP" );
2663   createSMESHAction( 1134, "CLIP" );
2664   createSMESHAction( 1135, "DISP_ENT" );
2665   createSMESHAction( 1136, "AUTO_COLOR" );
2666   createSMESHAction( 1137, "DISABLE_AUTO_COLOR" );
2667   createSMESHAction( 2000, "CTRL" );
2668
2669   createSMESHAction( 300, "ERASE" );
2670   createSMESHAction( 301, "DISPLAY" );
2671   createSMESHAction( 302, "DISPLAY_ONLY" );
2672   createSMESHAction( 4033, "POLYHEDRON", "ICON_DLG_POLYHEDRON" );
2673   createSMESHAction( 4034, "QUADRATIC_EDGE", "ICON_DLG_QUADRATIC_EDGE" );
2674   createSMESHAction( 4035, "QUADRATIC_TRIANGLE", "ICON_DLG_QUADRATIC_TRIANGLE" );
2675   createSMESHAction( 4036, "QUADRATIC_QUADRANGLE", "ICON_DLG_QUADRATIC_QUADRANGLE" );
2676   createSMESHAction( 4037, "QUADRATIC_TETRAHEDRON", "ICON_DLG_QUADRATIC_TETRAHEDRON" );
2677   createSMESHAction( 4038, "QUADRATIC_PYRAMID", "ICON_DLG_QUADRATIC_PYRAMID" );
2678   createSMESHAction( 4039, "QUADRATIC_PENTAHEDRON", "ICON_DLG_QUADRATIC_PENTAHEDRON" );
2679   createSMESHAction( 4040, "QUADRATIC_HEXAHEDRON", "ICON_DLG_QUADRATIC_HEXAHEDRON" );
2680
2681   // ----- create menu --------------
2682   int fileId   = createMenu( tr( "MEN_FILE" ),   -1,  1 ),
2683       editId   = createMenu( tr( "MEN_EDIT" ),   -1,  3 ),
2684       toolsId  = createMenu( tr( "MEN_TOOLS" ),  -1,  5, 50 ),
2685       meshId   = createMenu( tr( "MEN_MESH" ),   -1, 70, 10 ),
2686       ctrlId   = createMenu( tr( "MEN_CTRL" ),   -1, 60, 10 ),
2687       modifyId = createMenu( tr( "MEN_MODIFY" ), -1, 40, 10 ),
2688       viewId   = createMenu( tr( "MEN_VIEW" ),   -1,  2 );
2689
2690   createMenu( separator(), fileId );
2691
2692   int importId = createMenu( tr( "MEN_IMPORT" ), fileId, 11, 10 ),
2693       exportId = createMenu( tr( "MEN_EXPORT" ), fileId, 12, 10 ),
2694       addId    = createMenu( tr( "MEN_ADD" ),    modifyId, 402 ),
2695       removeId = createMenu( tr( "MEN_REMOVE" ), modifyId, 403 ),
2696       renumId  = createMenu( tr( "MEN_RENUM" ),  modifyId, 404 ),
2697       transfId = createMenu( tr( "MEN_TRANSF" ), modifyId, 405 );
2698
2699   createMenu( 111, importId, -1 );
2700   createMenu( 112, importId, -1 );
2701   createMenu( 113, importId, -1 );
2702
2703   createMenu( 121, exportId, -1 );
2704   createMenu( 122, exportId, -1 );
2705   createMenu( 123, exportId, -1 );
2706   createMenu( 140, exportId, -1 ); // export to stl STL
2707
2708   createMenu( separator(), fileId, 10 );
2709
2710   createMenu( 33, editId, -1 );
2711
2712   createMenu( 5105, toolsId, -1 );
2713
2714   createMenu( 702, meshId, -1 ); // "Mesh" menu
2715   createMenu( 703, meshId, -1 );
2716   createMenu( 704, meshId, -1 );
2717   createMenu( 710, meshId, -1 );
2718   createMenu( separator(), meshId, -1 );
2719   createMenu( 701, meshId, -1 );
2720   createMenu( separator(), meshId, -1 );
2721   createMenu( 801, meshId, -1 );
2722   createMenu( 802, meshId, -1 );
2723   createMenu( 803, meshId, -1 );
2724   createMenu( separator(), meshId, -1 );
2725   createMenu( 810, meshId, -1 );
2726   createMenu( 811, meshId, -1 );
2727   createMenu( 812, meshId, -1 );
2728   createMenu( separator(), meshId, -1 );
2729   createMenu( 813, meshId, -1 );
2730   createMenu( separator(), meshId, -1 );
2731   createMenu( 900, meshId, -1 );
2732   createMenu( 902, meshId, -1 );
2733   createMenu( 903, meshId, -1 );
2734   createMenu( separator(), meshId, -1 );
2735
2736   createMenu( 6003, ctrlId, -1 );
2737   createMenu( 6001, ctrlId, -1 );
2738   createMenu( 6004, ctrlId, -1 );
2739   createMenu( separator(), ctrlId, -1 );
2740   createMenu( 6002, ctrlId, -1 );
2741   createMenu( 6018, ctrlId, -1 );
2742   createMenu( 6019, ctrlId, -1 );
2743   createMenu( 6011, ctrlId, -1 );
2744   createMenu( 6012, ctrlId, -1 );
2745   createMenu( 6013, ctrlId, -1 );
2746   createMenu( 6014, ctrlId, -1 );
2747   createMenu( 6015, ctrlId, -1 );
2748   createMenu( 6016, ctrlId, -1 );
2749   createMenu( separator(), ctrlId, -1 );
2750   createMenu( 6017, ctrlId, -1 );
2751   createMenu( 6009, ctrlId, -1 );
2752   createMenu( separator(), ctrlId, -1 );
2753
2754   createMenu( 400, addId, -1 );
2755   createMenu( 401, addId, -1 );
2756   createMenu( 4021, addId, -1 );
2757   createMenu( 4022, addId, -1 );
2758   createMenu( 4023, addId, -1 );
2759   createMenu( 4031, addId, -1 );
2760   createMenu( 4032, addId, -1 );
2761   createMenu( 4033, addId, -1 );
2762   createMenu( separator(), addId, -1 );
2763   createMenu( 4034, addId, -1 );
2764   createMenu( 4035, addId, -1 );
2765   createMenu( 4036, addId, -1 );
2766   createMenu( 4037, addId, -1 );
2767   createMenu( 4038, addId, -1 );
2768   createMenu( 4039, addId, -1 );
2769   createMenu( 4040, addId, -1 );
2770
2771   createMenu( 4041, removeId, -1 );
2772   createMenu( 4042, removeId, -1 );
2773   createMenu( 4043, removeId, -1 );
2774
2775   createMenu( 4051, renumId, -1 );
2776   createMenu( 4052, renumId, -1 );
2777
2778   createMenu( 4061, transfId, -1 );
2779   createMenu( 4062, transfId, -1 );
2780   createMenu( 4063, transfId, -1 );
2781   createMenu( 4064, transfId, -1 );
2782   createMenu( 4065, transfId, -1 );
2783   createMenu( 4066, transfId, -1 );
2784
2785   createMenu( 406, modifyId, -1 );
2786   createMenu( 4067,modifyId, -1 );
2787   createMenu( 407, modifyId, -1 );
2788   createMenu( 408, modifyId, -1 );
2789   createMenu( 409, modifyId, -1 );
2790   createMenu( 410, modifyId, -1 );
2791   createMenu( 411, modifyId, -1 );
2792   createMenu( 412, modifyId, -1 );
2793   createMenu( 413, modifyId, -1 );
2794   createMenu( 416, modifyId, -1 );
2795   createMenu( 414, modifyId, -1 );
2796   createMenu( 415, modifyId, -1 );
2797   createMenu( 417, modifyId, -1 );
2798
2799   createMenu( 214, viewId, -1 );
2800
2801   // ----- create toolbars --------------
2802   int meshTb     = createTool( tr( "TB_MESH" ) ),
2803       ctrlTb     = createTool( tr( "TB_CTRL" ) ),
2804       addRemTb   = createTool( tr( "TB_ADD_REMOVE" ) ),
2805       modifyTb   = createTool( tr( "TB_MODIFY" ) ),
2806       dispModeTb = createTool( tr( "TB_DISP_MODE" ) );
2807
2808   createTool( 702, meshTb );
2809   createTool( 703, meshTb );
2810   createTool( 704, meshTb );
2811   createTool( 710, meshTb );
2812   createTool( separator(), meshTb );
2813   createTool( 701, meshTb );
2814   createTool( separator(), meshTb );
2815   createTool( 801, meshTb );
2816   createTool( 802, meshTb );
2817   createTool( 803, meshTb );
2818   createTool( separator(), meshTb );
2819   createTool( 900, meshTb );
2820   createTool( 902, meshTb );
2821   createTool( 903, meshTb );
2822   createTool( separator(), meshTb );
2823
2824   createTool( 6001, ctrlTb );
2825   createTool( 6003, ctrlTb );
2826   createTool( 6004, ctrlTb );
2827   createTool( separator(), ctrlTb );
2828   createTool( 6002, ctrlTb );
2829   createTool( 6018, ctrlTb );
2830   createTool( 6019, ctrlTb );
2831   createTool( 6011, ctrlTb );
2832   createTool( 6012, ctrlTb );
2833   createTool( 6013, ctrlTb );
2834   createTool( 6014, ctrlTb );
2835   createTool( 6015, ctrlTb );
2836   createTool( 6016, ctrlTb );
2837   createTool( separator(), ctrlTb );
2838   createTool( 6017, ctrlTb );
2839   createTool( 6009, ctrlTb );
2840   createTool( separator(), ctrlTb );
2841
2842   createTool( 400, addRemTb );
2843   createTool( 401, addRemTb );
2844   createTool( 4021, addRemTb );
2845   createTool( 4022, addRemTb );
2846   createTool( 4023, addRemTb );
2847   createTool( 4031, addRemTb );
2848   createTool( 4032, addRemTb );
2849   createTool( 4033, addRemTb );
2850   createTool( separator(), addRemTb );
2851   createTool( 4034, addRemTb );
2852   createTool( 4035, addRemTb );
2853   createTool( 4036, addRemTb );
2854   createTool( 4037, addRemTb );
2855   createTool( 4038, addRemTb );
2856   createTool( 4039, addRemTb );
2857   createTool( 4040, addRemTb );
2858   createTool( separator(), addRemTb );
2859   createTool( 4041, addRemTb );
2860   createTool( 4042, addRemTb );
2861   createTool( 4043, addRemTb );
2862   createTool( separator(), addRemTb );
2863   createTool( 4051, addRemTb );
2864   createTool( 4052, addRemTb );
2865   createTool( separator(), addRemTb );
2866   createTool( 4061, addRemTb );
2867   createTool( 4062, addRemTb );
2868   createTool( 4063, addRemTb );
2869   createTool( 4064, addRemTb );
2870   createTool( 4065, addRemTb );
2871   createTool( 4066, addRemTb );
2872   createTool( separator(), addRemTb );
2873
2874   createTool( 406, modifyTb );
2875   createTool( 4067,modifyTb );
2876   createTool( 407, modifyTb );
2877   createTool( 408, modifyTb );
2878   createTool( 409, modifyTb );
2879   createTool( 410, modifyTb );
2880   createTool( 411, modifyTb );
2881   createTool( 412, modifyTb );
2882   createTool( 413, modifyTb );
2883   createTool( 416, modifyTb );
2884   createTool( 414, modifyTb );
2885   createTool( 415, modifyTb );
2886   createTool( 417, modifyTb );
2887
2888   createTool( 214, dispModeTb );
2889
2890
2891   myRules.clear();
2892   QString OB = "'ObjectBrowser'",
2893           View = "'" + SVTK_Viewer::Type() + "'",
2894           pat = "'%1'",
2895           mesh    = pat.arg( SMESHGUI_Selection::typeName( MESH ) ),
2896           group   = pat.arg( SMESHGUI_Selection::typeName( GROUP ) ),
2897           hypo    = pat.arg( SMESHGUI_Selection::typeName( HYPOTHESIS ) ),
2898           algo    = pat.arg( SMESHGUI_Selection::typeName( ALGORITHM ) ),
2899           elems   = QString( "'%1' '%2' '%3' '%4' '%5' '%6'" ).
2900                        arg( SMESHGUI_Selection::typeName( SUBMESH_VERTEX ) ).
2901                        arg( SMESHGUI_Selection::typeName( SUBMESH_EDGE ) ).
2902                        arg( SMESHGUI_Selection::typeName( SUBMESH_FACE ) ).
2903                        arg( SMESHGUI_Selection::typeName( SUBMESH_SOLID ) ).
2904                        arg( SMESHGUI_Selection::typeName( SUBMESH_COMPOUND ) ).
2905                        arg( SMESHGUI_Selection::typeName( SUBMESH ) ),
2906           subMesh = elems,
2907           mesh_group = mesh + " " + subMesh + " " + group,
2908           hyp_alg = hypo + " " + algo;
2909
2910   // popup for object browser
2911
2912   createPopupItem( 150, OB, mesh, "&& selcount=1 && isImported" );      // FILE INFORMATION
2913   
2914   createPopupItem( 704, OB, mesh, "&& isComputable");      // EDIT_MESHSUBMESH
2915   createPopupItem( 704, OB, subMesh, "&& isComputable" );  // EDIT_MESHSUBMESH
2916   createPopupItem( 803, OB, group );                       // EDIT_GROUP
2917   popupMgr()->insert( separator(), -1, 0 );
2918   createPopupItem( 701, OB, mesh, "&& isComputable" );     // COMPUTE
2919   createPopupItem( 214, OB, mesh_group );                  // UPDATE
2920   createPopupItem( 900, OB, mesh_group );                  // ADV_INFO
2921   createPopupItem( 902, OB, mesh );                        // STD_INFO
2922   createPopupItem( 903, OB, mesh_group );                  // WHAT_IS
2923   popupMgr()->insert( separator(), -1, 0 );
2924   createPopupItem( 801, OB, mesh );                        // CREATE_GROUP
2925   createPopupItem( 802, OB, subMesh );                     // CONSTRUCT_GROUP
2926   popupMgr()->insert( separator(), -1, 0 );
2927   createPopupItem( 1100, OB, hypo);                        // EDIT HYPOTHESIS
2928   createPopupItem( 1102, OB, hyp_alg ); // REMOVE HYPOTHESIS / ALGORITHMS
2929   createPopupItem( 1101, OB, mesh_group + " " + hyp_alg ); // RENAME
2930   popupMgr()->insert( separator(), -1, 0 );
2931   createPopupItem( 4043, OB, mesh );                       // CLEAR_MESH
2932   popupMgr()->insert( separator(), -1, 0 );
2933
2934   QString         nbSelected = QtxPopupMgr::Selection::defSelCountParam();
2935   QString only_one_non_empty = QString( " && %1=1 && numberOfNodes>0" ).arg( nbSelected );
2936
2937   createPopupItem( 125, OB, mesh, only_one_non_empty );   // EXPORT_MED
2938   createPopupItem( 126, OB, mesh, only_one_non_empty );   // EXPORT_UNV
2939   createPopupItem( 141, OB, mesh, only_one_non_empty );   // EXPORT_STL
2940   //createPopupItem( 33, OB, subMesh + " " + group );       // DELETE
2941   createPopupItem(  33, OB, mesh_group + " " + hyp_alg ); // DELETE
2942   popupMgr()->insert( separator(), -1, 0 );
2943
2944   // popup for viewer
2945   createPopupItem( 803, View, group ); // EDIT_GROUP
2946   createPopupItem( 804, View, elems ); // ADD
2947   createPopupItem( 805, View, elems ); // REMOVE
2948   popupMgr()->insert( separator(), -1, 0 );
2949   createPopupItem( 214, View, mesh_group ); // UPDATE
2950   createPopupItem( 900, View, mesh_group ); // ADV_INFO
2951   createPopupItem( 902, View, mesh );       // STD_INFO
2952   createPopupItem( 903, View, mesh_group ); // WHAT_IS
2953   popupMgr()->insert( separator(), -1, 0 );
2954
2955   createPopupItem( 1136, OB + " " + View, mesh, "&& (not isAutoColor)" ); // AUTO_COLOR
2956   createPopupItem( 1137, OB + " " + View, mesh, "&& isAutoColor" );       // DISABLE_AUTO_COLOR
2957   popupMgr()->insert( separator(), -1, 0 );
2958
2959   int anId;
2960   QString
2961     isInvisible("not( isVisible )"),
2962     isEmpty("numberOfNodes = 0"),
2963     isNotEmpty("numberOfNodes <> 0"),
2964
2965     // has nodes, edges, etc in VISIBLE! actor
2966     hasNodes("(numberOfNodes > 0 )"),//&& isVisible)"),
2967     hasElems("(count( elemTypes ) > 0)"),
2968     hasDifferentElems("(count( elemTypes ) > 1)"),
2969     hasEdges("({'Edge'} in elemTypes)"),
2970     hasFaces("({'Face'} in elemTypes)"),
2971     hasVolumes("({'Volume'} in elemTypes)");
2972
2973   QString lc = QtxPopupMgr::Selection::defEquality();
2974   QString aClient = QString( "%1client in {%2}" ).arg( lc ).arg( "'VTKViewer'" );
2975   QString aType = QString( "%1type in {%2}" ).arg( QtxPopupMgr::Selection::defEquality() );
2976   aType = aType.arg( mesh_group );
2977   QString aMeshInVTK = aClient + "&&" + aType;
2978
2979   aClient = "($client in {'VTKViewer' 'ObjectBrowser'})";
2980   QString anActiveVTK = QString("activeView = '%1'").arg(SVTK_Viewer::Type());
2981   QString aSelCount = QString( "%1 > 0" ).arg( QtxPopupMgr::Selection::defSelCountParam() );
2982
2983   //-------------------------------------------------
2984   // Numbering
2985   //-------------------------------------------------
2986   anId = popupMgr()->insert( tr( "MEN_NUM" ), -1, -1 );
2987
2988   popupMgr()->insert( action( 9010 ), anId, -1 );
2989   popupMgr()->setRule( action( 9010 ), aMeshInVTK + "&& isVisible &&" + hasNodes, true );
2990   popupMgr()->setRule( action( 9010 ), "{'Point'} in labeledTypes", false );
2991
2992   popupMgr()->insert( action( 9011 ), anId, -1 );
2993   popupMgr()->setRule( action( 9011 ), aMeshInVTK + "&& isVisible &&" + hasElems, true );
2994   popupMgr()->setRule( action( 9011 ), "{'Cell'} in labeledTypes", false );
2995
2996   popupMgr()->insert( separator(), -1, -1 );
2997
2998   //-------------------------------------------------
2999   // Display Mode
3000   //-------------------------------------------------
3001   anId = popupMgr()->insert( tr( "MEN_DISPMODE" ), -1, -1 );
3002
3003   popupMgr()->insert( action( 211 ), anId, -1 ); // WIRE
3004   popupMgr()->setRule( action( 211 ), aMeshInVTK + "&&" + hasElems, true );
3005   popupMgr()->setRule( action( 211 ), "displayMode = 'eEdge'", false );
3006
3007   popupMgr()->insert( action( 212 ), anId, -1 ); // SHADE
3008   popupMgr()->setRule( action( 212 ),aMeshInVTK+ "&& (" + hasFaces + "||" + hasVolumes + ")",true);
3009   popupMgr()->setRule( action( 212 ), "displayMode = 'eSurface'", false );
3010
3011   popupMgr()->insert( action( 215 ), anId, -1 ); // POINTS
3012   popupMgr()->setRule( action( 215 ), aMeshInVTK + "&&" + hasNodes, true );
3013   popupMgr()->setRule( action( 215 ), "displayMode = 'ePoint'", false );
3014
3015   popupMgr()->insert( separator(), anId, -1 );
3016
3017   popupMgr()->insert( action( 213 ), anId, -1 ); // SHRINK
3018   popupMgr()->setRule( action( 213 ), aMeshInVTK + "&& shrinkMode <> 'IsNotShrinkable' && displayMode <> 'ePoint'",true);
3019   popupMgr()->setRule( action( 213 ), "shrinkMode = 'IsShrunk'", false );
3020
3021   //-------------------------------------------------
3022   // Display Entity
3023   //-------------------------------------------------
3024   QString aDiffElemsInVTK = aMeshInVTK + "&&" + hasDifferentElems;
3025
3026   anId = popupMgr()->insert( tr( "MEN_DISP_ENT" ), -1, -1 );
3027
3028   popupMgr()->insert( action( 217 ), anId, -1 ); // EDGES
3029   popupMgr()->setRule( action( 217 ), aDiffElemsInVTK + "&& isVisible &&" + hasEdges, true );
3030   popupMgr()->setRule( action( 217 ), "{'Edge'} in entityMode", false );
3031
3032   popupMgr()->insert( action( 218 ), anId, -1 ); // FACES
3033   popupMgr()->setRule( action( 218 ), aDiffElemsInVTK + "&& isVisible &&" + hasFaces, true );
3034   popupMgr()->setRule( action( 218 ), "{'Face'} in entityMode", false );
3035
3036   popupMgr()->insert( action( 219 ), anId, -1 ); // VOLUMES
3037   popupMgr()->setRule( action( 219 ), aDiffElemsInVTK + "&& isVisible &&" + hasVolumes, true );
3038   popupMgr()->setRule( action( 219 ), "{'Volume'} in entityMode", false );
3039
3040   popupMgr()->insert( separator(), anId, -1 );
3041
3042   popupMgr()->insert( action( 220 ), anId, -1 ); // ALL
3043   popupMgr()->setRule( action( 220 ), aDiffElemsInVTK + "&& isVisible && not( elemTypes in entityMode )", true );
3044
3045   //-------------------------------------------------
3046   // Color / Size
3047   //-------------------------------------------------
3048   popupMgr()->insert( action( 1132 ), -1, -1 );
3049   popupMgr()->setRule( action( 1132 ), aMeshInVTK + "&& isVisible", true );
3050
3051   //-------------------------------------------------
3052   // Transparency
3053   //-------------------------------------------------
3054   popupMgr()->insert( action( 1133 ), -1, -1 );
3055   popupMgr()->setRule( action( 1133 ), aMeshInVTK + "&& isVisible", true );
3056
3057   //-------------------------------------------------
3058   // Clipping
3059   //-------------------------------------------------
3060   popupMgr()->insert( action( 1134 ), -1, -1 );
3061   popupMgr()->setRule( action( 1134 ), aMeshInVTK + "&& isVisible", true );
3062
3063   popupMgr()->insert( separator(), -1, -1 );
3064
3065   //-------------------------------------------------
3066   // Controls
3067   //-------------------------------------------------
3068   QString
3069     aMeshInVtkHasEdges = aMeshInVTK + "&&" + hasEdges,
3070     aMeshInVtkHasFaces = aMeshInVTK + "&&" + hasFaces,
3071     aMeshInVtkHasVolumes = aMeshInVTK + "&&" + hasVolumes;
3072
3073   anId = popupMgr()->insert( tr( "MEN_CTRL" ), -1, -1 );
3074
3075   popupMgr()->insert( action( 200 ), anId, -1 ); // RESET
3076   popupMgr()->setRule( action( 200 ), aMeshInVTK + "&& controlMode <> 'eNone'", true );
3077
3078   popupMgr()->insert( separator(), anId, -1 );
3079
3080   popupMgr()->insert( action( 6003 ), anId, -1 ); // FREE_BORDER
3081   popupMgr()->setRule( action( 6003 ), aMeshInVtkHasEdges, true );
3082   popupMgr()->setRule( action( 6003 ), "controlMode = 'eFreeBorders'", false );
3083
3084   popupMgr()->insert( action( 6001 ), anId, -1 ); // LENGTH
3085   popupMgr()->setRule( action( 6001 ), aMeshInVtkHasEdges, true );
3086   popupMgr()->setRule( action( 6001 ), "controlMode = 'eLength'", false );
3087
3088   popupMgr()->insert( action( 6004 ), anId, -1 ); // CONNECTION
3089   popupMgr()->setRule( action( 6004 ), aMeshInVtkHasEdges, true );
3090   popupMgr()->setRule( action( 6004 ), "controlMode = 'eMultiConnection'", false );
3091
3092   popupMgr()->insert( separator(), anId, -1 );
3093
3094   popupMgr()->insert( action( 6002 ), anId, -1 ); // FREE_EDGE
3095   popupMgr()->setRule( action( 6002 ), aMeshInVtkHasFaces, true );
3096   popupMgr()->setRule( action( 6002 ), "controlMode = 'eFreeEdges'", false );
3097
3098   popupMgr()->insert( action( 6018 ), anId, -1 ); // LENGTH_2D
3099   popupMgr()->setRule( action( 6018 ), aMeshInVtkHasFaces, true );
3100   popupMgr()->setRule( action( 6018 ), "controlMode = 'eLength2D'", false );
3101
3102   popupMgr()->insert( action( 6019 ), anId, -1 ); // CONNECTION_2D
3103   popupMgr()->setRule( action( 6019 ), aMeshInVtkHasFaces, true );
3104   popupMgr()->setRule( action( 6019 ), "controlMode = 'eMultiConnection2D'", false );
3105
3106   popupMgr()->insert( action( 6011 ), anId, -1 ); // AREA
3107   popupMgr()->setRule( action( 6011 ), aMeshInVtkHasFaces, true );
3108   popupMgr()->setRule( action( 6011 ), "controlMode = 'eArea'", false );
3109
3110   popupMgr()->insert( action( 6012 ), anId, -1 ); // TAPER
3111   popupMgr()->setRule( action( 6012 ), aMeshInVtkHasFaces, true );
3112   popupMgr()->setRule( action( 6012 ), "controlMode = 'eTaper'", false );
3113
3114   popupMgr()->insert( action( 6013 ), anId, -1 ); // ASPECT
3115   popupMgr()->setRule( action( 6013 ), aMeshInVtkHasFaces, true );
3116   popupMgr()->setRule( action( 6013 ), "controlMode = 'eAspectRatio'", false );
3117
3118   popupMgr()->insert( action( 6014 ), anId, -1 ); // MIN_ANG
3119   popupMgr()->setRule( action( 6014 ), aMeshInVtkHasFaces, true );
3120   popupMgr()->setRule( action( 6014 ), "controlMode = 'eMinimumAngle'", false );
3121
3122   popupMgr()->insert( action( 6015 ), anId, -1 ); // WARP
3123   popupMgr()->setRule( action( 6015 ), aMeshInVtkHasFaces, true );
3124   popupMgr()->setRule( action( 6015 ), "controlMode = 'eWarping'", false );
3125
3126   popupMgr()->insert( action( 6016 ), anId, -1 ); // SKEW
3127   popupMgr()->setRule( action( 6016 ), aMeshInVtkHasFaces, true );
3128   popupMgr()->setRule( action( 6016 ), "controlMode = 'eSkew'", false );
3129
3130   popupMgr()->insert( separator(), anId, -1 );
3131
3132   popupMgr()->insert( action( 6017 ), anId, -1 ); // ASPECT_3D
3133   popupMgr()->setRule( action( 6017 ), aMeshInVtkHasVolumes, true );
3134   popupMgr()->setRule( action( 6017 ), "controlMode = 'eAspectRatio3D'", false );
3135
3136   popupMgr()->insert ( action( 6009 ), anId, -1 ); // VOLUME_3D
3137   popupMgr()->setRule( action( 6009 ), aMeshInVtkHasVolumes, true );
3138   popupMgr()->setRule( action( 6009 ), "controlMode = 'eVolume3D'", false );
3139
3140   popupMgr()->insert( separator(), anId, -1 );
3141
3142   popupMgr()->insert( action( 201 ), anId, -1 ); // SCALAR_BAR_PROP
3143   popupMgr()->setRule( action( 201 ), aMeshInVTK + "&& controlMode <> 'eNone'", true );
3144
3145   popupMgr()->insert( separator(), -1, -1 );
3146
3147   //-------------------------------------------------
3148   // Display / Erase
3149   //-------------------------------------------------
3150   QString aRule = "$component={'SMESH'} and ( type='Component' or (" + aClient + " and " +
3151     aType + " and " + aSelCount + " and " + anActiveVTK + " and " + isNotEmpty + " %1 ) )";
3152   popupMgr()->insert( action( 301 ), -1, -1 ); // DISPLAY
3153   popupMgr()->setRule( action( 301 ), aRule.arg( "and (not isVisible)" ), true);
3154
3155   popupMgr()->insert( action( 300 ), -1, -1 ); // ERASE
3156   popupMgr()->setRule( action( 300 ), aRule.arg( "and isVisible" ), true );
3157
3158   popupMgr()->insert( action( 302 ), -1, -1 ); // DISPLAY_ONLY
3159   popupMgr()->setRule( action( 302 ), aRule.arg( "" ), true );
3160
3161   popupMgr()->insert( separator(), -1, -1 );
3162
3163   connect( application(), SIGNAL( viewManagerActivated( SUIT_ViewManager* ) ),
3164            this, SLOT( onViewManagerActivated( SUIT_ViewManager* ) ) );
3165 }
3166
3167 //================================================================================
3168 /*!
3169  * \brief Return true if SMESH or GEOM objects are selected.
3170  * Is called form LightApp_Module::activateModule() which clear selection if
3171  * not isSelectionCompatible()
3172  */
3173 //================================================================================
3174
3175 bool SMESHGUI::isSelectionCompatible()
3176 {
3177   bool isCompatible = true;
3178   SALOME_ListIO selected;
3179   if ( LightApp_SelectionMgr *Sel = selectionMgr() )
3180     Sel->selectedObjects( selected );
3181
3182   SALOME_ListIteratorOfListIO It( selected );
3183   for ( ; isCompatible && It.More(); It.Next())
3184     isCompatible =
3185       ( strcmp("GEOM", It.Value()->getComponentDataType()) == 0 ) ||
3186       ( strcmp("SMESH", It.Value()->getComponentDataType()) == 0 );
3187
3188   return isCompatible;
3189 }
3190
3191 bool SMESHGUI::activateModule( SUIT_Study* study )
3192 {
3193   bool res = SalomeApp_Module::activateModule( study );
3194
3195   setMenuShown( true );
3196   setToolShown( true );
3197
3198   // Reset actions accelerator keys
3199   action(111)->setAccel(QKeySequence(CTRL + Key_B)); // Import DAT
3200   action(112)->setAccel(QKeySequence(CTRL + Key_U)); // Import UNV
3201   action(113)->setAccel(QKeySequence(CTRL + Key_M)); // Import MED
3202
3203   action(  33)->setEnabled(true); // Delete: Key_Delete
3204   action(1101)->setEnabled(true); // Rename: Key_F2
3205
3206   return res;
3207 }
3208
3209 bool SMESHGUI::deactivateModule( SUIT_Study* study )
3210 {
3211   setMenuShown( false );
3212   setToolShown( false );
3213
3214   EmitSignalCloseAllDialogs();
3215
3216   // Unset actions accelerator keys
3217   action(111)->setAccel(QKeySequence()); // Import DAT
3218   action(112)->setAccel(QKeySequence()); // Import UNV
3219   action(113)->setAccel(QKeySequence()); // Import MED
3220
3221   action(  33)->setEnabled(false); // Delete: Key_Delete
3222   action(1101)->setEnabled(false); // Rename: Key_F2
3223
3224   return SalomeApp_Module::deactivateModule( study );
3225 }
3226
3227 void SMESHGUI::studyClosed( SUIT_Study* s )
3228 {
3229   SMESH::RemoveVisuData( s->id() );
3230   SalomeApp_Module::studyClosed( s );
3231 }
3232
3233 void SMESHGUI::OnGUIEvent()
3234 {
3235   const QObject* obj = sender();
3236   if ( !obj || !obj->inherits( "QAction" ) )
3237     return;
3238   int id = actionId((QAction*)obj);
3239   if ( id != -1 )
3240     OnGUIEvent( id );
3241 }
3242
3243 SMESH::SMESH_Gen_var SMESHGUI::GetSMESHGen()
3244 {
3245   _PTR(Study) aStudy = SMESH::GetActiveStudyDocument(); //Document OCAF de l'etude active
3246   if ( CORBA::is_nil( myComponentSMESH ) )
3247     {
3248       SMESHGUI aGUI; //SRN BugID: IPAL9186: Create an instance of SMESHGUI to initialize myComponentSMESH
3249       if ( aStudy )
3250         aGUI.myComponentSMESH->SetCurrentStudy(_CAST(Study,aStudy)->GetStudy());
3251       return aGUI.myComponentSMESH;
3252     }
3253   if ( aStudy )
3254     myComponentSMESH->SetCurrentStudy(_CAST(Study,aStudy)->GetStudy());
3255   return myComponentSMESH;
3256 }
3257
3258 QString SMESHGUI::engineIOR() const
3259 {
3260   CORBA::ORB_var anORB = getApp()->orb();
3261   CORBA::String_var anIOR = anORB->object_to_string(GetSMESHGen());
3262   return QString( anIOR.in() );
3263 }
3264
3265 void SMESHGUI::contextMenuPopup( const QString& client, QPopupMenu* menu, QString& title )
3266 {
3267   SMESHGUI_Selection sel;
3268   sel.init( client, selectionMgr() );
3269   popupMgr()->updatePopup( menu, &sel );
3270
3271   SALOME_ListIO lst;
3272   selectionMgr()->selectedObjects( lst );
3273   if ( ( client == "OCCViewer" || client == "VTKViewer" ) && lst.Extent() == 1 ) {
3274     Handle(SALOME_InteractiveObject) io = lst.First();
3275     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( application()->activeStudy() );
3276     _PTR(Study) study = appStudy->studyDS();
3277     _PTR(SObject) obj = study->FindObjectID( io->getEntry() );
3278     if ( obj ) {
3279       QString aName = QString( obj->GetName().c_str() );
3280       while ( aName.at( aName.length() - 1 ) == ' ' ) // Remove extraspaces in Name of Popup
3281           aName.remove( (aName.length() - 1), 1 );
3282       title = aName;
3283     }
3284   }
3285 }
3286
3287 void SMESHGUI::windows( QMap<int, int>& aMap ) const
3288 {
3289   aMap.insert( SalomeApp_Application::WT_ObjectBrowser, Qt::DockLeft );
3290   aMap.insert( SalomeApp_Application::WT_PyConsole, Qt::DockBottom );
3291 }
3292
3293 void SMESHGUI::viewManagers( QStringList& list ) const
3294 {
3295   list.append( SVTK_Viewer::Type() );
3296 }
3297
3298 void SMESHGUI::onViewManagerActivated( SUIT_ViewManager* mgr )
3299 {
3300   if ( dynamic_cast<SVTK_ViewManager*>( mgr ) )
3301     SMESH::UpdateSelectionProp( this );
3302 }
3303
3304 void SMESHGUI::createPreferences()
3305 {
3306   int genTab = addPreference( tr( "PREF_TAB_GENERAL" ) );
3307
3308   int updateGroup = addPreference( tr( "PREF_GROUP_UPDATE" ), genTab );
3309   addPreference( tr( "PREF_AUTO_UPDATE" ), updateGroup, LightApp_Preferences::Bool, "SMESH", "auto_update" );
3310
3311   int qaGroup = addPreference( tr( "PREF_GROUP_QUALITY" ), genTab );
3312   addPreference( tr( "PREF_DISPLAY_ENTITY" ), qaGroup, LightApp_Preferences::Bool, "SMESH", "display_entity" );
3313   addPreference( tr( "PREF_PRECISION_USE" ), qaGroup, LightApp_Preferences::Bool, "SMESH", "use_precision" );
3314
3315   int precGroup = addPreference( tr( "PREF_GROUP_PRECISION" ), genTab );
3316   setPreferenceProperty( precGroup, "columns", 1 );
3317
3318   int prec = addPreference( tr( "PREF_PRECISION_VALUE" ), precGroup, LightApp_Preferences::IntSpin, "SMESH", "controls_precision" );
3319
3320   setPreferenceProperty( prec, "min", 0 );
3321   setPreferenceProperty( prec, "max", 16 );
3322
3323   int dispgroup = addPreference( tr( "PREF_DISPLAY_MODE" ), genTab );
3324   int dispmode = addPreference( tr( "PREF_DISPLAY_MODE" ), dispgroup, LightApp_Preferences::Selector, "SMESH", "display_mode" );
3325   QStringList modes;
3326   modes.append( "Wireframe" );
3327   modes.append( "Shading" );
3328   modes.append( "Nodes" );
3329   modes.append( "Shrink" );
3330   QValueList<QVariant> indices;
3331   indices.append( 0 );
3332   indices.append( 1 );
3333   indices.append( 2 );
3334   indices.append( 3 );
3335   setPreferenceProperty( dispmode, "strings", modes );
3336   setPreferenceProperty( dispmode, "indexes", indices );
3337
3338   int exportgroup = addPreference( tr( "PREF_GROUP_EXPORT" ), genTab );
3339   addPreference( tr( "PREF_AUTO_GROUPS" ), exportgroup, LightApp_Preferences::Bool, "SMESH", "auto_groups" );
3340   addPreference( tr( "PREF_RENUMBER" ), exportgroup, LightApp_Preferences::Bool, "SMESH", "renumbering" );
3341
3342   int meshTab = addPreference( tr( "PREF_TAB_MESH" ) );
3343   int nodeGroup = addPreference( tr( "PREF_GROUP_NODES" ), meshTab );
3344
3345   addPreference( tr( "PREF_COLOR" ), nodeGroup, LightApp_Preferences::Color, "SMESH", "node_color" );
3346   int nodeSz = addPreference( tr( "PREF_SIZE" ), nodeGroup, LightApp_Preferences::IntSpin, "SMESH", "node_size" );
3347
3348   setPreferenceProperty( nodeSz, "min", 1 );
3349   setPreferenceProperty( nodeSz, "max", 5 );
3350
3351   int elemGroup = addPreference( tr( "PREF_GROUP_ELEMENTS" ), meshTab );
3352
3353   addPreference( tr( "PREF_FILL" ), elemGroup, LightApp_Preferences::Color, "SMESH", "fill_color" );
3354   addPreference( tr( "PREF_OUTLINE" ), elemGroup, LightApp_Preferences::Color, "SMESH", "outline_color" );
3355   addPreference( tr( "PREF_BACKFACE" ), elemGroup, LightApp_Preferences::Color, "SMESH", "backface_color" );
3356   addPreference( "", elemGroup, LightApp_Preferences::Space );
3357
3358   int elemW = addPreference( tr( "PREF_WIDTH" ), elemGroup, LightApp_Preferences::IntSpin, "SMESH", "element_width" );
3359   int shrink = addPreference( tr( "PREF_SHRINK_COEFF" ), elemGroup, LightApp_Preferences::IntSpin, "SMESH", "shrink_coeff" );
3360
3361   setPreferenceProperty( elemW, "min", 1 );
3362   setPreferenceProperty( elemW, "max", 5 );
3363
3364   setPreferenceProperty( shrink, "min", 0 );
3365   setPreferenceProperty( shrink, "max", 100 );
3366
3367   int selTab = addPreference( tr( "PREF_TAB_SELECTION" ) );
3368
3369   int selGroup = addPreference( tr( "PREF_GROUP_SELECTION" ), selTab );
3370
3371   addPreference( tr( "PREF_OBJECT_COLOR" ), selGroup, LightApp_Preferences::Color, "SMESH", "selection_object_color" );
3372   addPreference( tr( "PREF_ELEMENT_COLOR" ), selGroup, LightApp_Preferences::Color, "SMESH", "selection_element_color" );
3373   int selW = addPreference( tr( "PREF_WIDTH" ), selGroup, LightApp_Preferences::IntSpin, "SMESH", "selection_width" );
3374
3375   setPreferenceProperty( selW, "min", 1 );
3376   setPreferenceProperty( selW, "max", 5 );
3377
3378   int preGroup = addPreference( tr( "PREF_GROUP_PRESELECTION" ), selTab );
3379
3380   addPreference( tr( "PREF_HIGHLIGHT_COLOR" ), preGroup, LightApp_Preferences::Color, "SMESH", "highlight_color" );
3381   int preW = addPreference( tr( "PREF_WIDTH" ), preGroup, LightApp_Preferences::IntSpin, "SMESH", "highlight_width" );
3382
3383   setPreferenceProperty( preW, "min", 1 );
3384   setPreferenceProperty( preW, "max", 5 );
3385
3386   int precSelGroup = addPreference( tr( "PREF_GROUP_PRECISION" ), selTab );
3387
3388   addPreference( tr( "PREF_NODES" ), precSelGroup, LightApp_Preferences::Double, "SMESH", "selection_precision_node" );
3389   addPreference( tr( "PREF_ELEMENTS" ), precSelGroup, LightApp_Preferences::Double, "SMESH", "selection_precision_element" );
3390   addPreference( tr( "PREF_OBJECTS" ), precSelGroup, LightApp_Preferences::Double, "SMESH", "selection_precision_object" );
3391
3392   int sbarTab = addPreference( tr( "SMESH_SCALARBAR" ) );
3393   int fontGr = addPreference( tr( "SMESH_FONT_SCALARBAR" ), sbarTab );
3394
3395   int tfont = addPreference( tr( "SMESH_TITLE" ), fontGr, LightApp_Preferences::Font, "SMESH", "scalar_bar_title_font" );
3396   addPreference( tr( "PREF_TITLE_COLOR" ), fontGr, LightApp_Preferences::Color, "SMESH", "scalar_bar_title_color" );
3397   int lfont = addPreference( tr( "SMESH_LABELS" ), fontGr, LightApp_Preferences::Font, "SMESH", "scalar_bar_label_font" );
3398   addPreference( tr( "PREF_LABELS_COLOR" ), fontGr, LightApp_Preferences::Color, "SMESH", "scalar_bar_label_color" );
3399
3400   QStringList fam;
3401   fam.append( tr( "SMESH_FONT_ARIAL" ) );
3402   fam.append( tr( "SMESH_FONT_COURIER" ) );
3403   fam.append( tr( "SMESH_FONT_TIMES" ) );
3404   int wflag = ( QtxListResourceEdit::FontItem::All & ( ~( QtxListResourceEdit::FontItem::Size | QtxListResourceEdit::FontItem::UserSize ) ) );
3405
3406   setPreferenceProperty( tfont, "families", fam );
3407   setPreferenceProperty( tfont, "system", false );
3408   setPreferenceProperty( tfont, "widget_flags", wflag );
3409   setPreferenceProperty( lfont, "families", fam );
3410   setPreferenceProperty( lfont, "system", false );
3411   setPreferenceProperty( lfont, "widget_flags", wflag );
3412
3413   int colorsLabelsGr = addPreference( tr( "SMESH_LABELS_COLORS_SCALARBAR" ), sbarTab );
3414
3415   int numcol = addPreference( tr( "SMESH_NUMBEROFCOLORS" ), colorsLabelsGr, LightApp_Preferences::IntSpin, "SMESH", "scalar_bar_num_colors" );
3416   setPreferenceProperty( numcol, "min", 2 );
3417   setPreferenceProperty( numcol, "max", 256 );
3418
3419   int numlab = addPreference( tr( "SMESH_NUMBEROFLABELS" ), colorsLabelsGr, LightApp_Preferences::IntSpin, "SMESH", "scalar_bar_num_labels" );
3420   setPreferenceProperty( numlab, "min", 2 );
3421   setPreferenceProperty( numlab, "max", 65 );
3422
3423   int orientGr = addPreference( tr( "SMESH_ORIENTATION" ), sbarTab );
3424   int orient = addPreference( tr( "SMESH_ORIENTATION" ), orientGr, LightApp_Preferences::Selector, "SMESH", "scalar_bar_orientation" );
3425   QStringList orients;
3426   orients.append( tr( "SMESH_VERTICAL" ) );
3427   orients.append( tr( "SMESH_HORIZONTAL" ) );
3428   indices.clear(); indices.append( 0 ); indices.append( 1 );
3429   setPreferenceProperty( orient, "strings", orients );
3430   setPreferenceProperty( orient, "indexes", indices );
3431
3432   int posVSizeGr = addPreference( tr( "SMESH_POSITION_SIZE_SCALARBAR" ) + " " + tr( "SMESH_VERTICAL" ), sbarTab );
3433   int xv = addPreference( tr( "SMESH_X_SCALARBAR" ), posVSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_vertical_x" );
3434   int yv = addPreference( tr( "SMESH_Y_SCALARBAR" ), posVSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_vertical_y" );
3435   int wv = addPreference( tr( "SMESH_WIDTH" ), posVSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_vertical_width" );
3436   int hv = addPreference( tr( "SMESH_HEIGHT" ), posVSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_vertical_height" );
3437   setPreferenceProperty( xv, "step", 0.1 );
3438   setPreferenceProperty( xv, "min", 0.0 );
3439   setPreferenceProperty( xv, "max", 1.0 );
3440   setPreferenceProperty( yv, "step", 0.1 );
3441   setPreferenceProperty( yv, "min", 0.0 );
3442   setPreferenceProperty( yv, "max", 1.0 );
3443   setPreferenceProperty( wv, "step", 0.1 );
3444   setPreferenceProperty( wv, "min", 0.0 );
3445   setPreferenceProperty( wv, "max", 1.0 );
3446   setPreferenceProperty( hv, "min", 0.0 );
3447   setPreferenceProperty( hv, "max", 1.0 );
3448   setPreferenceProperty( hv, "step", 0.1 );
3449
3450   int posHSizeGr = addPreference( tr( "SMESH_POSITION_SIZE_SCALARBAR" ) + " " + tr( "SMESH_HORIZONTAL" ), sbarTab );
3451   int xh = addPreference( tr( "SMESH_X_SCALARBAR" ), posHSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_horizontal_x" );
3452   int yh = addPreference( tr( "SMESH_Y_SCALARBAR" ), posHSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_horizontal_y" );
3453   int wh = addPreference( tr( "SMESH_WIDTH" ), posHSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_horizontal_width" );
3454   int hh = addPreference( tr( "SMESH_HEIGHT" ), posHSizeGr, LightApp_Preferences::DblSpin, "SMESH", "scalar_bar_horizontal_height" );
3455   setPreferenceProperty( xv, "min", 0.0 );
3456   setPreferenceProperty( xv, "max", 1.0 );
3457   setPreferenceProperty( xv, "step", 0.1 );
3458   setPreferenceProperty( xh, "min", 0.0 );
3459   setPreferenceProperty( xh, "max", 1.0 );
3460   setPreferenceProperty( xh, "step", 0.1 );
3461   setPreferenceProperty( yh, "min", 0.0 );
3462   setPreferenceProperty( yh, "max", 1.0 );
3463   setPreferenceProperty( yh, "step", 0.1 );
3464   setPreferenceProperty( wh, "min", 0.0 );
3465   setPreferenceProperty( wh, "max", 1.0 );
3466   setPreferenceProperty( wh, "step", 0.1 );
3467   setPreferenceProperty( hh, "min", 0.0 );
3468   setPreferenceProperty( hh, "max", 1.0 );
3469   setPreferenceProperty( hh, "step", 0.1 );
3470 }
3471
3472 void SMESHGUI::preferencesChanged( const QString& sect, const QString& name )
3473 {
3474   if( sect=="SMESH" ){
3475     float sbX1,sbY1,sbW,sbH;
3476     float aTol = 1.00000009999999;
3477     std::string aWarning;
3478     SUIT_ResourceMgr* aResourceMgr = SMESH::GetResourceMgr(this);
3479     if( name=="selection_object_color" || name=="selection_element_color" ||
3480         name=="selection_width" || name=="highlight_color" || name=="highlight_width" ||
3481         name=="selection_precision_node" || name=="selection_precision_element" ||
3482         name=="selection_precision_object")
3483       SMESH::UpdateSelectionProp( this );
3484     else if (name == QString("scalar_bar_vertical_x") || name == QString("scalar_bar_vertical_width")){
3485       sbX1 = aResourceMgr->doubleValue("SMESH", "scalar_bar_vertical_x", sbX1);
3486       sbW = aResourceMgr->doubleValue("SMESH", "scalar_bar_vertical_width", sbW);
3487       if(sbX1+sbW > aTol){
3488         aWarning = "Origin and Size Vertical: X+Width > 1\n";
3489         sbX1=0.01;
3490         sbW=0.05;
3491         aResourceMgr->setValue("SMESH", "scalar_bar_vertical_x", sbX1);
3492         aResourceMgr->setValue("SMESH", "scalar_bar_vertical_width", sbW);
3493       }
3494     }
3495     else if(name == QString("scalar_bar_vertical_y") || name == QString("scalar_bar_vertical_height")){
3496       sbY1 = aResourceMgr->doubleValue("SMESH", "scalar_bar_vertical_y", sbY1);
3497       sbH = aResourceMgr->doubleValue("SMESH", "scalar_bar_vertical_height",sbH);
3498       if(sbY1+sbH > aTol){
3499         aWarning = "Origin and Size Vertical: Y+Height > 1\n";
3500         aResourceMgr->setValue("SMESH", "scalar_bar_vertical_y", sbY1);
3501         aResourceMgr->setValue("SMESH", "scalar_bar_vertical_height",sbH);
3502       }
3503     }
3504     else if(name ==  QString("scalar_bar_horizontal_x") || name ==  QString("scalar_bar_horizontal_width")){
3505       sbX1 = aResourceMgr->doubleValue("SMESH", "scalar_bar_horizontal_x", sbX1);
3506       sbW = aResourceMgr->doubleValue("SMESH", "scalar_bar_horizontal_width", sbW);
3507       if(sbX1+sbW > aTol){
3508         aWarning = "Origin and Size Horizontal: X+Width > 1\n";
3509         sbX1=0.01;
3510         sbW=0.05;
3511         aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_x", sbX1);
3512         aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_width", sbW);
3513       }
3514     }
3515     else if(name ==  QString("scalar_bar_horizontal_y") || name ==  QString("scalar_bar_horizontal_height")){
3516       sbY1 = aResourceMgr->doubleValue("SMESH", "scalar_bar_horizontal_y", sbY1);
3517       sbH = aResourceMgr->doubleValue("SMESH", "scalar_bar_horizontal_height",sbH);
3518       if(sbY1+sbH > aTol){
3519         aWarning = "Origin and Size Horizontal: Y+Height > 1\n";
3520         sbY1=0.01;
3521         sbH=0.05;
3522         aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_y", sbY1);
3523         aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_height",sbH);
3524       }
3525     }
3526
3527     if(aWarning.size() != 0){
3528       aWarning += "The default values are applied instead.";
3529       SUIT_MessageBox::warn1(SMESHGUI::desktop(),
3530                              QObject::tr("SMESH_ERR_SCALARBAR_PARAMS"),
3531                              QObject::tr(aWarning.c_str()),
3532                              QObject::tr("SMESH_BUT_OK"));
3533     }
3534   }
3535 }
3536
3537 //================================================================================
3538 /*!
3539  * \brief Update something in accordance with update flags
3540   * \param theFlags - update flags
3541 *
3542 * Update viewer or/and object browser etc. in accordance with update flags ( see
3543 * LightApp_UpdateFlags enumeration ).
3544 */
3545 //================================================================================
3546 void SMESHGUI::update( const int flags )
3547 {
3548   if ( flags & UF_Viewer | flags & UF_Forced )
3549     SMESH::UpdateView();
3550   else
3551     SalomeApp_Module::update( flags );
3552 }
3553
3554 //================================================================================
3555 /*!
3556  * \brief Set default selection mode
3557 *
3558 * SLOT called when operation commited. Sets default selection mode
3559 */
3560 //================================================================================
3561 void SMESHGUI::onOperationCommited( SUIT_Operation* )
3562 {
3563   SVTK_ViewWindow* vtkWnd =
3564     dynamic_cast<SVTK_ViewWindow*>( application()->desktop()->activeWindow() );
3565   if ( vtkWnd )
3566     vtkWnd->SetSelectionMode( ActorSelection );
3567 }
3568
3569 //================================================================================
3570 /*!
3571  * \brief Set default selection mode
3572 *
3573 * SLOT called when operation aborted. Sets default selection mode
3574 */
3575 //================================================================================
3576 void SMESHGUI::onOperationAborted( SUIT_Operation* )
3577 {
3578   SVTK_ViewWindow* vtkWnd =
3579     dynamic_cast<SVTK_ViewWindow*>( application()->desktop()->activeWindow() );
3580   if ( vtkWnd )
3581     vtkWnd->SetSelectionMode( ActorSelection );
3582 }
3583
3584 //================================================================================
3585 /*!
3586  * \brief Creates operation with given identifier
3587   * \param id - identifier of operation to be started
3588   * \return Pointer on created operation or NULL if operation is not created
3589 *
3590 * Virtual method redefined from the base class creates operation with given id.
3591 * It is called called automatically from startOperation method of base class.
3592 */
3593 //================================================================================
3594 LightApp_Operation* SMESHGUI::createOperation( const int id ) const
3595 {
3596   LightApp_Operation* op = 0;
3597   // to do : create operation here
3598   switch( id )
3599   {
3600     case 701: // Compute mesh
3601       op = new SMESHGUI_ComputeOp();
3602     break;
3603     case 702: // Create mesh
3604       op = new SMESHGUI_MeshOp( true, true );
3605     break;
3606     case 703: // Create sub-mesh
3607       op = new SMESHGUI_MeshOp( true, false );
3608     break;
3609     case 704: // Edit mesh/sub-mesh
3610       op = new SMESHGUI_MeshOp( false );
3611     break;
3612     case 417: //convert to quadratic
3613       op = new SMESHGUI_ConvToQuadOp();
3614     break;
3615     case 4067: // make mesh pass through point
3616       op = new SMESHGUI_MakeNodeAtPointOp();
3617       break;
3618     default:
3619     break;
3620   }
3621
3622   if( !op )
3623     op = SalomeApp_Module::createOperation( id );
3624   return op;
3625 }
3626
3627 //================================================================================
3628 /*!
3629  * \brief Stops current operations and starts a given one
3630   * \param id - The id of the operation to start
3631  */
3632 //================================================================================
3633
3634 void SMESHGUI::switchToOperation(int id)
3635 {
3636   if ( _PTR(Study) aStudy = SMESH::GetActiveStudyDocument() )
3637     activeStudy()->abortAllOperations();
3638   startOperation( id );
3639 }
3640
3641 LightApp_Displayer* SMESHGUI::displayer()
3642 {
3643   if( !myDisplayer )
3644     myDisplayer = new SMESHGUI_Displayer( getApp() );
3645   return myDisplayer;
3646 }
3647
3648 SALOMEDS::Color SMESHGUI::getUniqueColor( const QValueList<SALOMEDS::Color>& theReservedColors )
3649 {
3650   int aHue = -1;
3651   int aTolerance = 64;
3652   int anIterations = 0;
3653   int aPeriod = 5;
3654
3655   while( 1 )
3656   {
3657     anIterations++;
3658     if( anIterations % aPeriod == 0 )
3659     {
3660       aTolerance /= 2;
3661       if( aTolerance < 1 )
3662         break;
3663     }
3664     //cout << "Iteration N" << anIterations << " (tolerance=" << aTolerance << ")"<< endl;
3665
3666     aHue = (int)( 360.0 * rand() / RAND_MAX );
3667     //cout << "Hue = " << aHue << endl;
3668
3669     //cout << "Auto colors : ";
3670     bool ok = true;
3671     QValueList<SALOMEDS::Color>::const_iterator it = theReservedColors.constBegin();
3672     QValueList<SALOMEDS::Color>::const_iterator itEnd = theReservedColors.constEnd();
3673     for( ; it != itEnd; ++it )
3674     {
3675       SALOMEDS::Color anAutoColor = *it;
3676       QColor aQColor( (int)( anAutoColor.R * 255.0 ), (int)( anAutoColor.G * 255.0 ), (int)( anAutoColor.B * 255.0 ) );
3677
3678       int h, s, v;
3679       aQColor.getHsv( &h, &s, &v );
3680       //cout << h << " ";
3681       if( abs( h - aHue ) < aTolerance )
3682       {
3683         ok = false;
3684         //cout << "break (diff = " << abs( h - aHue ) << ")";
3685         break;
3686       }
3687     }
3688     //cout << endl;
3689
3690     if( ok )
3691       break;
3692   }
3693
3694   //cout << "Hue of the returned color = " << aHue << endl;
3695   QColor aColor;
3696   aColor.setHsv( aHue, 255, 255 );
3697
3698   SALOMEDS::Color aSColor;
3699   aSColor.R = (double)aColor.red() / 255.0;
3700   aSColor.G = (double)aColor.green() / 255.0;
3701   aSColor.B = (double)aColor.blue() / 255.0;
3702
3703   return aSColor;
3704 }