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