Salome HOME
SWP12792: Help pages is connected
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_CreatePolyhedralVolumeDlg.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 //
23 //
24 //  File   : SMESHGUI_CreatePolyhedralVolumeDlg.cxx
25 //  Author : Michael ZORIN
26 //  Module : SMESH
27 //  $Header: 
28
29 #include "SMESHGUI_CreatePolyhedralVolumeDlg.h"
30
31 #include "SMESHGUI.h"
32 #include "SMESHGUI_Utils.h"
33 #include "SMESHGUI_VTKUtils.h"
34 #include "SMESHGUI_MeshUtils.h"
35 #include "SMESHGUI_IdValidator.h"
36 #include "SMESH_ActorUtils.h"
37 #include "SMESHGUI_SpinBox.h"
38 #include "SMESH_Actor.h"
39 #include "SMESH_TypeFilter.hxx"
40 #include "SMDS_Mesh.hxx"
41
42 #include "SUIT_ResourceMgr.h"
43 #include "SUIT_Session.h"
44 #include "SUIT_MessageBox.h"
45
46 #include "SalomeApp_Application.h"
47 #include "SalomeApp_Study.h"
48 #include "SUIT_Desktop.h"
49 #include "SUIT_MessageBox.h"
50 #include "LightApp_Application.h"
51 #include "LightApp_SelectionMgr.h"
52 #include "utilities.h"
53
54 #include "SVTK_ViewWindow.h"
55 #include "SVTK_Selector.h"
56
57 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
58 #include <TColStd_ListOfInteger.hxx>
59 #include <TColStd_ListIteratorOfListOfInteger.hxx>
60
61 #include <vtkCell.h>
62 #include <vtkIdList.h>
63 #include <vtkIntArray.h>
64 #include <vtkCellArray.h>
65 #include <vtkUnsignedCharArray.h>
66 #include <vtkUnstructuredGrid.h>
67 #include <vtkDataSetMapper.h>
68 #include <vtkProperty.h>
69
70 // QT Includes
71 #include <qapplication.h>
72 #include <qbuttongroup.h>
73 #include <qgroupbox.h>
74 #include <qlabel.h>
75 #include <qlineedit.h>
76 #include <qpushbutton.h>
77 #include <qradiobutton.h>
78 #include <qcheckbox.h>
79 #include <qlayout.h>
80 #include <qspinbox.h> 
81 #include <qpixmap.h>
82 #include <qlistbox.h>
83
84 // IDL Headers
85 #include "SALOMEconfig.h"
86 #include CORBA_SERVER_HEADER(SMESH_Group)
87
88 using namespace std;
89
90 namespace SMESH{
91
92 class TPolySimulation{
93     SVTK_ViewWindow* myViewWindow;
94
95     SALOME_Actor *myPreviewActor;
96     vtkDataSetMapper* myMapper;
97     vtkUnstructuredGrid* myGrid;
98
99   public:
100
101     TPolySimulation(SalomeApp_Application* app)
102     {
103       SUIT_ViewManager* mgr = app->activeViewManager();
104       myViewWindow = mgr ? dynamic_cast<SVTK_ViewWindow*>( mgr->getActiveView() ) : NULL;
105
106       myGrid = vtkUnstructuredGrid::New();
107   
108       // Create and display actor
109       myMapper = vtkDataSetMapper::New();
110       myMapper->SetInput( myGrid );
111
112       myPreviewActor = SALOME_Actor::New();
113       myPreviewActor->PickableOff();
114       myPreviewActor->VisibilityOff();
115       myPreviewActor->SetMapper( myMapper );
116       myPreviewActor->SetRepresentation( 3 );
117
118       vtkFloatingPointType anRGB[3];
119       vtkProperty* aProp = vtkProperty::New();
120       GetColor( "SMESH", "selection_element_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 170, 255 ) );
121       aProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
122       myPreviewActor->SetProperty( aProp );
123       vtkFloatingPointType aFactor,aUnits;
124       myPreviewActor->SetResolveCoincidentTopology(true);
125       myPreviewActor->GetPolygonOffsetParameters(aFactor,aUnits);
126       myPreviewActor->SetPolygonOffsetParameters(aFactor,0.2*aUnits);
127       aProp->Delete();
128
129       myViewWindow->AddActor( myPreviewActor );
130       
131     }
132
133
134     typedef std::vector<vtkIdType> TVTKIds;
135     void SetPosition(SMESH_Actor* theActor, 
136                      vtkIdType theType, 
137                      const TVTKIds& theIds,
138                      bool theReset=true)
139     {
140       vtkUnstructuredGrid *aGrid = theActor->GetUnstructuredGrid();
141       myGrid->SetPoints(aGrid->GetPoints());
142
143       ResetGrid(theReset);
144       
145       vtkIdList *anIds = vtkIdList::New();
146
147       for (int i = 0, iEnd = theIds.size(); i < iEnd; i++)
148         anIds->InsertId(i,theIds[i]);
149
150       myGrid->InsertNextCell(theType,anIds);
151       if(theIds.size()!=0){
152         myGrid->InsertNextCell(theType,anIds);
153         myGrid->Modified();
154       }
155         
156       anIds->Delete();
157
158       SetVisibility(true);
159
160     }
161   
162     void ResetGrid(bool theReset=true){
163       if (theReset) myGrid->Reset();
164     }
165
166     void SetVisibility(bool theVisibility){
167       myPreviewActor->SetVisibility(theVisibility);
168       RepaintCurrentView();
169     }
170
171
172     ~TPolySimulation(){
173         if( myViewWindow )
174           myViewWindow->RemoveActor(myPreviewActor);
175
176       myPreviewActor->Delete();
177
178       myMapper->RemoveAllInputs();
179       myMapper->Delete();
180
181       myGrid->Delete();
182     }
183
184   };
185 }
186
187 //=================================================================================
188 // class    : SMESHGUI_CreatePolyhedralVolumeDlgDlg()
189 // purpose  : 
190 //=================================================================================
191 SMESHGUI_CreatePolyhedralVolumeDlg::SMESHGUI_CreatePolyhedralVolumeDlg( SMESHGUI* theModule, const char* name,
192                                                                         bool modal, WFlags fl )
193   : QDialog( SMESH::GetDesktop( theModule ), name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | Qt::WDestructiveClose),
194     mySMESHGUI( theModule ),
195     mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
196 {
197   QPixmap image0( SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap( "SMESH",tr("ICON_SELECT")));
198
199   if ( !name )
200     setName( "SMESHGUI_CreatePolyhedralVolumeDlg" );
201   resize( 300, 185 ); 
202   setCaption( tr( "SMESH_CREATE_POLYHEDRAL_VOLUME_TITLE" ) );
203   setSizeGripEnabled( TRUE );
204   SMESHGUI_CreatePolyhedralVolumeDlgLayout = new QGridLayout( this ); 
205   SMESHGUI_CreatePolyhedralVolumeDlgLayout->setSpacing( 6 );
206   SMESHGUI_CreatePolyhedralVolumeDlgLayout->setMargin( 11 );
207
208   /***************************************************************/
209   GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
210   GroupConstructors->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)5, (QSizePolicy::SizeType)0, 0, 0, GroupConstructors->sizePolicy().hasHeightForWidth() ) );
211   GroupConstructors->setTitle( tr( "SMESH_ELEMENTS_TYPE" ) );
212   GroupConstructors->setExclusive( TRUE );
213   GroupConstructors->setColumnLayout(0, Qt::Vertical );
214   GroupConstructors->layout()->setSpacing( 0 );
215   GroupConstructors->layout()->setMargin( 0 );
216   GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
217   GroupConstructorsLayout->setAlignment( Qt::AlignTop );
218   GroupConstructorsLayout->setSpacing( 6 );
219   GroupConstructorsLayout->setMargin( 11 );
220   RadioButton1= new QRadioButton( GroupConstructors, "RadioButton1" );
221   RadioButton1->setText( tr( "MESH_NODE"  ) );
222   GroupConstructorsLayout->addWidget( RadioButton1, 0, 0 );
223   RadioButton2= new QRadioButton( GroupConstructors, "RadioButton2" );
224   RadioButton2->setText( tr( "SMESH_FACE"  ) );
225   GroupConstructorsLayout->addWidget( RadioButton2, 0, 2  );
226   SMESHGUI_CreatePolyhedralVolumeDlgLayout->addWidget( GroupConstructors, 0, 0 );
227   
228   /***************************************************************/
229   GroupButtons = new QGroupBox( this, "GroupButtons" );
230   GroupButtons->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)7, (QSizePolicy::SizeType)0, 0, 0, GroupButtons->sizePolicy().hasHeightForWidth() ) );
231   GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) ); 
232   GroupButtons->setTitle( tr( ""  ) );
233   GroupButtons->setColumnLayout(0, Qt::Vertical );
234   GroupButtons->layout()->setSpacing( 0 );
235   GroupButtons->layout()->setMargin( 0 );
236   GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
237   GroupButtonsLayout->setAlignment( Qt::AlignTop );
238   GroupButtonsLayout->setSpacing( 6 );
239   GroupButtonsLayout->setMargin( 11 );
240   buttonCancel = new QPushButton( GroupButtons, "cancel" );
241   buttonCancel->setText( tr( "SMESH_BUT_CLOSE"  ) );
242   buttonCancel->setAutoDefault( TRUE );
243   GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
244   buttonApply = new QPushButton( GroupButtons, "apply" );
245   buttonApply->setText( tr( "SMESH_BUT_APPLY"  ) );
246   buttonApply->setAutoDefault( TRUE );
247   GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
248   QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
249   GroupButtonsLayout->addItem( spacer_9, 0, 2 );
250   buttonOk = new QPushButton( GroupButtons, "ok" );
251   buttonOk->setText( tr( "SMESH_BUT_OK"  ) );
252   buttonOk->setAutoDefault( TRUE );
253   buttonOk->setDefault( TRUE );
254   GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
255   buttonHelp = new QPushButton(GroupButtons, "buttonHelp");
256   buttonHelp->setText(tr("SMESH_BUT_HELP" ));
257   buttonHelp->setAutoDefault(TRUE);
258   GroupButtonsLayout->addWidget(buttonHelp, 0, 4);
259
260   SMESHGUI_CreatePolyhedralVolumeDlgLayout->addWidget( GroupButtons, 2, 0 );
261
262   /***************************************************************/
263   GroupContent = new QGroupBox( this, "GroupContent" );
264   GroupContent->setTitle( tr( "SMESH_CONTENT" ) );
265   GroupContent->setColumnLayout(0, Qt::Vertical );
266   GroupContent->layout()->setSpacing( 0 );
267   GroupContent->layout()->setMargin( 0 );
268   GroupContentLayout = new QGridLayout( GroupContent->layout() );
269   GroupContentLayout->setAlignment( Qt::AlignTop );
270   GroupContentLayout->setSpacing( 6 );
271   GroupContentLayout->setMargin( 11 );
272
273   QFrame* anIds = new QFrame(GroupContent, "anIds");
274   QGridLayout* aLayout = new QGridLayout(anIds, 1, 3);
275   aLayout->setSpacing(6);
276   aLayout->setAutoAdd(false);
277   
278   TextLabelIds = new QLabel( anIds, "TextLabelIds" );
279   TextLabelIds->setText( tr( "SMESH_ID_NODES" ) );
280   TextLabelIds->setFixedWidth(74);
281   aLayout->addWidget( TextLabelIds, 0, 0 );
282
283   SelectElementsButton  = new QPushButton( anIds, "SelectElementsButton" );
284   SelectElementsButton->setText( tr( "" ) );
285   SelectElementsButton->setPixmap( image0 );
286   SelectElementsButton->setToggleButton( FALSE );
287   aLayout->addWidget( SelectElementsButton, 0, 1 );
288
289   LineEditElements  = new QLineEdit( anIds, "LineEditElements" );
290   LineEditElements->setValidator( new SMESHGUI_IdValidator( this, "validator" ));
291   aLayout->addWidget( LineEditElements, 0, 2 );
292   
293   GroupContentLayout->addMultiCellWidget(anIds, 0, 0, 0, 1);
294
295   myFacesByNodesLabel = new QLabel(GroupContent, "faces by nodes label");
296   myFacesByNodesLabel->setText(tr("FACES_BY_NODES"));
297   GroupContentLayout->addWidget( myFacesByNodesLabel, 1, 0 );
298
299   myFacesByNodes = new QListBox(GroupContent, "faces by nodes list");
300   myFacesByNodes->setSelectionMode(QListBox::Extended);
301   myFacesByNodes->setMinimumHeight(150);
302   GroupContentLayout->addMultiCellWidget( myFacesByNodes, 2, 4, 0, 0 );
303
304   AddButton = new QPushButton(GroupContent, "add");
305   AddButton->setText(tr("SMESH_BUT_ADD"));
306   AddButton->setMaximumWidth(85);
307   GroupContentLayout->addWidget( AddButton, 2, 1 );
308
309   RemoveButton = new QPushButton(GroupContent, "remove");
310   RemoveButton->setText(tr("SMESH_BUT_REMOVE"));
311   RemoveButton->setMaximumWidth(85);
312   GroupContentLayout->addWidget( RemoveButton, 3, 1 );
313
314   Preview = new QCheckBox( GroupContent, "Preview" );
315   Preview->setText( tr( "SMESH_POLYEDRE_PREVIEW"  ) );
316   GroupContentLayout->addWidget( Preview , 5, 0 );
317
318   mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
319   
320   SMESHGUI_CreatePolyhedralVolumeDlgLayout->addWidget( GroupContent, 1, 0 );
321   
322   GroupContent->show();
323   RadioButton1->setChecked( TRUE );
324  
325   mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
326
327   myHelpFileName = "/files/adding_nodes_and_elements.htm#Adding_polyhedrons?";
328   
329   Init();
330 }
331
332 //=================================================================================
333 // function : ~SMESHGUI_CreatePolyhedralVolumeDlg()
334 // purpose  : Destroys the object and frees any allocated resources
335 //=================================================================================
336 SMESHGUI_CreatePolyhedralVolumeDlg::~SMESHGUI_CreatePolyhedralVolumeDlg()
337 {
338   // no need to delete child widgets, Qt does it all for us
339   delete mySimulation;
340 }
341
342 static bool busy = false;
343 //=================================================================================
344 // function : Init()
345 // purpose  :
346 //=================================================================================
347 void SMESHGUI_CreatePolyhedralVolumeDlg::Init()
348 {
349   myEditCurrentArgument = LineEditElements;
350   mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
351
352   myNbOkElements = 0;
353   myActor = 0;
354
355   mySimulation = new SMESH::TPolySimulation( dynamic_cast<SalomeApp_Application*>( mySMESHGUI->application() ) );
356
357   /* signals and slots connections */
358   connect(buttonOk, SIGNAL( clicked() ),     SLOT( ClickOnOk() ) );
359   connect(buttonCancel, SIGNAL( clicked() ), SLOT( ClickOnCancel() ) ) ;
360   connect(buttonApply, SIGNAL( clicked() ),  SLOT(ClickOnApply() ) );
361   connect(buttonHelp, SIGNAL(clicked()),     SLOT(ClickOnHelp() ) );
362
363   connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
364   connect(SelectElementsButton, SIGNAL( clicked() ), SLOT( SetEditCurrentArgument() ) ) ;
365   connect(LineEditElements, SIGNAL( textChanged(const QString&) ), SLOT(onTextChange(const QString&)));
366
367   connect(myFacesByNodes, SIGNAL(selectionChanged()), this, SLOT(onListSelectionChanged()));
368   connect(AddButton, SIGNAL(clicked()), this, SLOT(onAdd()));
369   connect(RemoveButton, SIGNAL(clicked()), this, SLOT(onRemove()));
370   
371   connect( mySMESHGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
372   connect( mySelectionMgr, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
373   connect( Preview, SIGNAL(toggled(bool)), this, SLOT(ClickOnPreview(bool)));
374   /* to close dialog if study change */
375   connect( mySMESHGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
376   
377   this->show() ; /* displays Dialog */
378
379   ConstructorsClicked(0);
380   SelectionIntoArgument();
381 }
382
383
384 //=================================================================================
385 // function : ConstructorsClicked()
386 // purpose  : Radio button management
387 //=================================================================================
388 void SMESHGUI_CreatePolyhedralVolumeDlg::ConstructorsClicked(int constructorId)
389 {
390   //disconnect(mySelectionMgr, 0, this, 0);
391
392   SALOME_ListIO io;
393   mySelectionMgr->selectedObjects( io );
394   SALOME_ListIO aList;
395   mySelectionMgr->setSelectedObjects( aList );
396   myEditCurrentArgument->clear();
397   myNbOkElements = 0;
398   buttonApply->setEnabled(false);
399   buttonOk->setEnabled(false);
400   mySimulation->SetVisibility(false);
401
402   switch(constructorId)
403     {
404     case 0 :
405       { 
406         if ( myActor ){
407           myActor->SetPointRepresentation(true);
408         }
409         else
410           SMESH::SetPointRepresentation(true);
411         if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
412           aViewWindow->SetSelectionMode(NodeSelection);
413         
414         AddButton->setEnabled(false);
415         RemoveButton->setEnabled(false);
416         TextLabelIds->setText( tr( "SMESH_ID_NODES" ) );
417         myFacesByNodesLabel->show();
418         myFacesByNodes->clear();
419         myFacesByNodes->show();
420         AddButton->show();
421         RemoveButton->show();
422         Preview->show();
423         break;
424       }
425     case 1 :
426       {
427         if( myActor ){
428           myActor->SetPointRepresentation(false);
429         } else {
430           SMESH::SetPointRepresentation(false);
431         }
432         if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
433           aViewWindow->SetSelectionMode(FaceSelection);
434         
435         TextLabelIds->setText( tr( "SMESH_ID_FACES" ) );
436         myFacesByNodesLabel->hide();
437         myFacesByNodes->hide();
438         AddButton->hide();
439         RemoveButton->hide();
440         Preview->show();
441         break;
442       }
443     }
444   
445   //connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
446   mySelectionMgr->setSelectedObjects( io );
447 }
448
449 //=================================================================================
450 // function : ClickOnPreview()
451 // purpose  :
452 //=================================================================================
453 void SMESHGUI_CreatePolyhedralVolumeDlg::ClickOnPreview(bool theToggled){
454   Preview->setChecked(theToggled);
455   displaySimulation();
456 }
457
458 //=================================================================================
459 // function : ClickOnApply()
460 // purpose  :
461 //=================================================================================
462 void SMESHGUI_CreatePolyhedralVolumeDlg::ClickOnApply()
463 {
464   if ( myNbOkElements>0 && !mySMESHGUI->isActiveStudyLocked())
465     {
466       if(checkEditLine(false) == -1) {return;}
467       busy = true;
468       if (GetConstructorId() == 0)
469         {
470           SMESH::long_array_var anIdsOfNodes = new SMESH::long_array;
471           SMESH::long_array_var aQuantities  = new SMESH::long_array;
472
473           aQuantities->length( myFacesByNodes->count() );
474
475           TColStd_ListOfInteger aNodesIds;
476
477           QListBoxItem* anItem;
478           int aNbQuantities = 0;
479           for (anItem = myFacesByNodes->firstItem(); anItem != 0; anItem = anItem->next()) {
480             QStringList anIds = QStringList::split(" ", anItem->text());
481             int aNbNodesInFace = 0;
482             for (QStringList::iterator it = anIds.begin(); it != anIds.end(); ++it, ++aNbNodesInFace)
483               aNodesIds.Append( (*it).toInt() );
484
485             aQuantities[aNbQuantities++] = aNbNodesInFace;
486           }
487
488           anIdsOfNodes->length(aNodesIds.Extent());
489
490           int aNbIdsOfNodes = 0;
491           TColStd_ListIteratorOfListOfInteger It;
492           It.Initialize(aNodesIds);
493           for(;It.More();It.Next())
494             anIdsOfNodes[aNbIdsOfNodes++] = It.Value();
495             
496           try{
497             SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
498             QApplication::setOverrideCursor(Qt::waitCursor);
499             aMeshEditor->AddPolyhedralVolume(anIdsOfNodes, aQuantities);
500             QApplication::restoreOverrideCursor();
501           }catch(SALOME::SALOME_Exception& exc){
502             INFOS("Follow exception was cought:\n\t"<<exc.details.text);
503           }catch(std::exception& exc){
504             INFOS("Follow exception was cought:\n\t"<<exc.what());
505           }catch(...){
506             INFOS("Unknown exception was cought !!!");
507           }
508         }
509       else if (GetConstructorId() == 1)
510         {
511           SMESH::long_array_var anIdsOfFaces = new SMESH::long_array;
512           
513           QStringList aListId = QStringList::split( " ", myEditCurrentArgument->text() );
514           anIdsOfFaces->length(aListId.count());
515           for ( int i = 0; i < aListId.count(); i++ )
516             anIdsOfFaces[i] = aListId[i].toInt();
517           
518           try{
519             SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
520             QApplication::setOverrideCursor(Qt::waitCursor);
521             aMeshEditor->AddPolyhedralVolumeByFaces(anIdsOfFaces);
522             QApplication::restoreOverrideCursor();
523           }catch(SALOME::SALOME_Exception& exc){
524             INFOS("Follow exception was cought:\n\t"<<exc.details.text);
525           }catch(std::exception& exc){
526             INFOS("Follow exception was cought:\n\t"<<exc.what());
527           }catch(...){
528             INFOS("Unknown exception was cought !!!");
529           }
530         }
531       
532       //SALOME_ListIO aList;
533       //mySelectionMgr->setSelectedObjects( aList );
534       SMESH::UpdateView();
535       if( myActor ){
536         unsigned int anEntityMode = myActor->GetEntityMode();
537         myActor->SetEntityMode(SMESH_Actor::eVolumes | anEntityMode);
538       }
539       //ConstructorsClicked( GetConstructorId() );
540       busy = false;
541     }
542 }
543
544 //=================================================================================
545 // function : ClickOnOk()
546 // purpose  :
547 //=================================================================================
548 void SMESHGUI_CreatePolyhedralVolumeDlg::ClickOnOk()
549 {
550   if(checkEditLine(false) == -1) {return;}
551   ClickOnApply() ;
552   ClickOnCancel() ;
553 }
554
555         
556 //=================================================================================
557 // function : ClickOnCancel()
558 // purpose  :
559 //=================================================================================
560 void SMESHGUI_CreatePolyhedralVolumeDlg::ClickOnCancel()
561 {
562   mySelectionMgr->clearFilters();
563   //SALOME_ListIO aList;
564   //mySelectionMgr->setSelectedObjects( aList );
565   SMESH::SetPointRepresentation(false);
566   mySimulation->SetVisibility(false);
567   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
568     aViewWindow->SetSelectionMode( ActorSelection );
569   disconnect( mySelectionMgr, 0, this, 0 );
570   mySMESHGUI->ResetState() ;
571   reject() ;
572 }
573
574 //=================================================================================
575 // function : ClickOnHelp()
576 // purpose  :
577 //=================================================================================
578 void SMESHGUI_CreatePolyhedralVolumeDlg::ClickOnHelp()
579 {
580   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
581   if (app) 
582     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
583   else {
584                 QString platform;
585 #ifdef WIN32
586                 platform = "winapplication";
587 #else
588                 platform = "application";
589 #endif
590     SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
591                            QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
592                            arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(myHelpFileName),
593                            QObject::tr("BUT_OK"));
594   }
595 }
596
597 //=======================================================================
598 //function : onTextChange
599 //purpose  : 
600 //=======================================================================
601
602 void SMESHGUI_CreatePolyhedralVolumeDlg::onTextChange(const QString& theNewText)
603 {
604   if ( busy ) return;
605   if (checkEditLine() == -1) return;
606   busy = true;
607
608   mySimulation->SetVisibility(false);
609
610   SMDS_Mesh* aMesh = 0;
611   if ( myActor )
612     aMesh = myActor->GetObject()->GetMesh();
613
614   if (GetConstructorId() == 0)
615   {
616     if ( aMesh ) {
617       TColStd_MapOfInteger newIndices;
618       
619       QStringList aListId = QStringList::split( " ", theNewText, false);
620       for ( int i = 0; i < aListId.count(); i++ ) {
621         const SMDS_MeshNode * n = aMesh->FindNode( aListId[ i ].toInt() );
622         if ( n ) {
623           newIndices.Add(n->GetID());
624           myNbOkElements++;
625         }
626       }
627       
628       mySelector->AddOrRemoveIndex( myActor->getIO(), newIndices, false );
629       
630       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
631         aViewWindow->highlight( myActor->getIO(), true, true );
632       
633       if ( myNbOkElements>0 && aListId.count()>=3)
634         AddButton->setEnabled(true);
635       else
636         AddButton->setEnabled(false);
637       
638       displaySimulation();
639     }
640   } else if (GetConstructorId() == 1)
641   {
642     myNbOkElements = 0;
643     buttonOk->setEnabled( false );
644     buttonApply->setEnabled( false );
645       
646       // check entered ids of faces and hilight them
647     QStringList aListId;
648     if ( aMesh ) {
649       TColStd_MapOfInteger newIndices;
650       
651       aListId = QStringList::split( " ", theNewText, false);
652
653       for ( int i = 0; i < aListId.count(); i++ ) {
654         const SMDS_MeshElement * e = aMesh->FindElement( aListId[ i ].toInt() );
655         if ( e ) {
656           newIndices.Add(e->GetID());
657           myNbOkElements++;  
658         }
659       }
660
661       mySelector->AddOrRemoveIndex( myActor->getIO(), newIndices, false );
662       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
663         aViewWindow->highlight( myActor->getIO(), true, true );
664       
665       if ( myNbOkElements ) {
666         if (aListId.count()>1){ 
667           buttonOk->setEnabled( true );
668           buttonApply->setEnabled( true );
669         }
670         else{
671           buttonOk->setEnabled( false );
672           buttonApply->setEnabled( false );
673         }
674         if(aListId.count()>1)
675           displaySimulation();
676       }
677     }
678   }
679   busy = false;
680 }
681
682 //=================================================================================
683 // function : SelectionIntoArgument()
684 // purpose  : Called when selection as changed or other case
685 //=================================================================================
686 void SMESHGUI_CreatePolyhedralVolumeDlg::SelectionIntoArgument()
687 {
688   if ( busy ) return;
689   
690   // clear
691   
692   if (GetConstructorId() == 1 || myFacesByNodes->count() <= 1)
693     {
694       myNbOkElements = 0;
695       AddButton->setEnabled(false);
696       buttonOk->setEnabled( false );
697       buttonApply->setEnabled( false );
698     }
699
700   myActor = 0;
701
702   busy = true;
703   myEditCurrentArgument->setText( "" );
704   busy = false;
705   if ( !GroupButtons->isEnabled() ) // inactive
706     return;
707   
708   mySimulation->SetVisibility(false);
709   
710   // get selected mesh
711   
712   SALOME_ListIO selected;
713   mySelectionMgr->selectedObjects( selected );
714   int nbSel = selected.Extent();
715   if(nbSel != 1){
716     return;
717   }
718   
719   myMesh = SMESH::GetMeshByIO( selected.First() );
720   if ( myMesh->_is_nil() )
721     return;
722   
723   myActor = SMESH::FindActorByObject(myMesh);
724   if ( !myActor )
725     return;
726   
727   // get selected nodes/faces
728   QString aString = "";
729   int anbNodes=0,aNbFaces=0;
730   switch(GetConstructorId()){
731   case 0:{
732     anbNodes = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aString);
733     if (anbNodes >= 3)
734       AddButton->setEnabled(true);
735     else if (anbNodes < 3){
736       AddButton->setEnabled(false);
737     }
738     busy = true;
739     myEditCurrentArgument->setText( aString );
740     if (checkEditLine() == -1) {busy = false;return;}
741     busy = false;
742     break;
743   }
744   case 1:{
745     // get selected faces
746     aNbFaces = SMESH::GetNameOfSelectedElements(mySelector, myActor->getIO(), aString);
747     if (aNbFaces<=1){
748       buttonOk->setEnabled( false );
749       buttonApply->setEnabled( false );
750     } else {
751       buttonOk->setEnabled( true );
752       buttonApply->setEnabled( true );
753     }
754     busy = true;
755     myEditCurrentArgument->setText( aString );
756     if (checkEditLine() == -1) {busy = false;return;}
757     busy = false;
758     
759     // OK
760     myNbOkElements = 1;
761     break;
762   }
763   default: return;
764   }
765   if(anbNodes>2 || aNbFaces>1)
766     displaySimulation();
767 }
768
769 /*\brief int SMESHGUI_CreatePolyhedralVolumeDlg::checkEditLine()
770  * Checking of indices in edit line.
771  * If incorecct indices in edit line warning message appear and myEditCurrentArgument remove last index.
772  * \retval 1 - if all ok(or no indices in edit line), -1 - if there are incorrect indices.
773  */
774 int SMESHGUI_CreatePolyhedralVolumeDlg::checkEditLine(bool checkLast)
775 {
776   QString aString = "";
777   SMDS_Mesh* aMesh = 0;
778   
779   if(myMesh->_is_nil()) return 1;
780   if(!myActor){
781     myActor = SMESH::FindActorByObject(myMesh);
782     if(!myActor)
783       return 1;
784   }
785     
786   aMesh = myActor->GetObject()->GetMesh();
787
788   // checking for nodes
789   if (checkLast && myEditCurrentArgument->text().right(1) != QString(" ") ) return 1;
790   QStringList aListId = QStringList::split( " ", myEditCurrentArgument->text() );
791   for ( int i = 0; i < aListId.count(); i++ ){
792     switch (GetConstructorId()){
793     case 0:{ // nodes
794       const SMDS_MeshNode    * aNode = aMesh->FindNode( aListId[ i ].toInt() );
795       if( !aNode ){
796         std::string aWarning;
797         aWarning = "The incorrect indices of nodes!";
798         SUIT_MessageBox::warn1(SMESHGUI::desktop(),
799                                QObject::tr("SMESH_POLYEDRE_CREATE_ERROR"),
800                                QObject::tr(aWarning.c_str()),
801                                QObject::tr("SMESH_BUT_OK"));
802         
803         myEditCurrentArgument->clear();
804         myEditCurrentArgument->setText( aString );
805         return -1;
806       }
807
808       break;
809     }
810     case 1:{ // faces
811       bool aElemIsOK = true;
812       const SMDS_MeshElement * aElem = aMesh->FindElement( aListId[ i ].toInt() );
813       if (!aElem)
814         {
815           aElemIsOK = false;
816         }
817       else
818         {
819           SMDSAbs_ElementType aType = aMesh->GetElementType( aElem->GetID(),true );
820           if (aType != SMDSAbs_Face){
821             aElemIsOK = false;
822           }
823         }
824       if (!aElemIsOK){
825         std::string aWarning;
826         aWarning = "The incorrect indices of faces!";
827         SUIT_MessageBox::warn1(SMESHGUI::desktop(),
828                                QObject::tr("SMESH_POLYEDRE_CREATE_ERROR"),
829                                QObject::tr(aWarning.c_str()),
830                                QObject::tr("SMESH_BUT_OK"));
831         
832         myEditCurrentArgument->clear();
833         myEditCurrentArgument->setText( aString );
834         return -1;
835       }
836       break;
837     }
838     }
839     aString += aListId[ i ] + " "; 
840   }
841
842   return 1;
843 }
844
845 //=======================================================================
846 //function : displaySimulation
847 //purpose  : 
848 //=======================================================================
849 void SMESHGUI_CreatePolyhedralVolumeDlg::displaySimulation()
850 {
851   if ( (myNbOkElements || AddButton->isEnabled()) && GroupButtons->isEnabled() && myActor)
852     {
853       SMESH::TPolySimulation::TVTKIds aVTKIds;
854       vtkIdType aType = VTK_CONVEX_POINT_SET ;
855       SMDS_Mesh* aMesh = 0;
856       if ( myActor ){
857         aMesh = myActor->GetObject()->GetMesh();
858       }
859       if (GetConstructorId() == 0 && aMesh){
860         if (!AddButton->isEnabled()){
861           QListBoxItem* anItem;
862           mySimulation->ResetGrid(true);
863           for (anItem = myFacesByNodes->firstItem(); anItem != 0; anItem = anItem->next()) {
864             QStringList anIds = QStringList::split(" ", anItem->text());
865             SMESH::TPolySimulation::TVTKIds aVTKIds_faces;
866             for (QStringList::iterator it = anIds.begin(); it != anIds.end(); ++it){
867               const SMDS_MeshNode    * aNode = aMesh->FindNode( (*it).toInt() );
868               if (!aNode) continue;
869               vtkIdType aId = myActor->GetObject()->GetNodeVTKId( (*it).toInt() ) ;
870               aVTKIds.push_back(aId);
871               aVTKIds_faces.push_back(aId);
872             }
873             if(!Preview->isChecked()){
874               aType = VTK_POLYGON;
875               mySimulation->SetPosition(myActor, aType, aVTKIds_faces,false);
876             }
877           }
878           if(myFacesByNodes->count() == 0){
879             mySimulation->SetVisibility(false);
880           } else {
881             mySimulation->SetVisibility(true);
882           }
883           if(Preview->isChecked()){
884             mySimulation->SetPosition(myActor, aType, aVTKIds);
885           }
886         } else {
887           // add ids from edit line
888           QStringList anEditIds = QStringList::split( " ", myEditCurrentArgument->text(), false);
889           for ( int i = 0; i < anEditIds.count(); i++ )
890             aVTKIds.push_back( myActor->GetObject()->GetNodeVTKId( anEditIds[ i ].toInt() ));
891           aType = VTK_POLYGON;
892           mySimulation->SetPosition(myActor, aType, aVTKIds);
893         }
894       }else if(GetConstructorId() == 1 && aMesh){
895         QStringList aListId = QStringList::split( " ", myEditCurrentArgument->text(), false);
896         for ( int i = 0; i < aListId.count(); i++ )
897           {
898             const SMDS_MeshElement * anElem = aMesh->FindElement( aListId[ i ].toInt() );
899             if ( !anElem ) continue;
900             SMDSAbs_ElementType aFaceType = aMesh->GetElementType( anElem->GetID(),true );
901             if (aFaceType != SMDSAbs_Face) continue;
902               
903             SMDS_ElemIteratorPtr anIter = anElem->nodesIterator();
904             SMESH::TPolySimulation::TVTKIds aVTKIds_faces;
905             while( anIter->more() )
906                 if ( const SMDS_MeshNode* aNode = (SMDS_MeshNode*)anIter->next() ){
907                   vtkIdType aId = myActor->GetObject()->GetNodeVTKId( aNode->GetID() ) ;
908                   aVTKIds.push_back(aId);
909                   aVTKIds_faces.push_back(aId);
910                 }
911             if(!Preview->isChecked()){
912               aType = VTK_POLYGON;
913               mySimulation->SetPosition(myActor, aType, aVTKIds_faces);
914             }
915           }
916         if(Preview->isChecked())
917           mySimulation->SetPosition(myActor, aType, aVTKIds);
918       }
919       SMESH::UpdateView();
920     }
921 }
922
923 //=================================================================================
924 // function : SetEditCurrentArgument()
925 // purpose  :
926 //=================================================================================
927 void SMESHGUI_CreatePolyhedralVolumeDlg::SetEditCurrentArgument()
928 {
929   QPushButton* send = (QPushButton*)sender();
930   if(send == SelectElementsButton) {
931     LineEditElements->setFocus() ;
932     myEditCurrentArgument = LineEditElements;
933   }
934   SelectionIntoArgument();
935 }
936
937 //=================================================================================
938 // function : DeactivateActiveDialog()
939 // purpose  :
940 //=================================================================================
941 void SMESHGUI_CreatePolyhedralVolumeDlg::DeactivateActiveDialog()
942 {
943   if ( GroupConstructors->isEnabled() ) {
944     GroupConstructors->setEnabled(false) ;
945     GroupContent->setEnabled(false) ;
946     GroupButtons->setEnabled(false) ;
947     mySimulation->SetVisibility(false);
948     mySMESHGUI->ResetState() ;    
949     mySMESHGUI->SetActiveDialogBox(0) ;
950   }
951 }
952
953
954 //=================================================================================
955 // function : ActivateThisDialog()
956 // purpose  :
957 //=================================================================================
958 void SMESHGUI_CreatePolyhedralVolumeDlg::ActivateThisDialog()
959 {
960   /* Emit a signal to deactivate the active dialog */
961   mySMESHGUI->EmitSignalDeactivateDialog() ;   
962   GroupConstructors->setEnabled(true) ;
963   GroupContent->setEnabled(true) ;
964   GroupButtons->setEnabled(true) ;
965   
966   mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
967
968   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
969     aViewWindow->SetSelectionMode( FaceSelection );
970   SelectionIntoArgument();
971 }
972
973
974 //=================================================================================
975 // function : enterEvent()
976 // purpose  :
977 //=================================================================================
978 void SMESHGUI_CreatePolyhedralVolumeDlg::enterEvent(QEvent* e)
979 {
980   if ( GroupConstructors->isEnabled() )
981     return ;  
982   ActivateThisDialog() ;
983 }
984
985
986 //=================================================================================
987 // function : closeEvent()
988 // purpose  :
989 //=================================================================================
990 void SMESHGUI_CreatePolyhedralVolumeDlg::closeEvent( QCloseEvent* e )
991 {
992   /* same than click on cancel button */
993   this->ClickOnCancel() ;
994 }
995
996
997 //=======================================================================
998 //function : hideEvent
999 //purpose  : caused by ESC key
1000 //=======================================================================
1001
1002 void SMESHGUI_CreatePolyhedralVolumeDlg::hideEvent ( QHideEvent * e )
1003 {
1004   if ( !isMinimized() )
1005     ClickOnCancel();
1006 }
1007
1008
1009 //=================================================================================
1010 // function : GetConstructorId()
1011 // purpose  : 
1012 //=================================================================================
1013 int SMESHGUI_CreatePolyhedralVolumeDlg::GetConstructorId()
1014
1015   if ( GroupConstructors != NULL && GroupConstructors->selected() != NULL )
1016     return GroupConstructors->id( GroupConstructors->selected() );
1017   return -1;
1018 }
1019
1020 //=================================================================================
1021 // function : onAdd()
1022 // purpose  :
1023 //=================================================================================
1024 void SMESHGUI_CreatePolyhedralVolumeDlg::onAdd()
1025 {
1026   SALOME_ListIO selected;
1027   mySelectionMgr->selectedObjects( selected );
1028   int aNbSel = selected.Extent();
1029   if (aNbSel == 0 || !myActor || myMesh->_is_nil()) return;
1030   
1031   if (this->checkEditLine(false) == -1) return;
1032
1033   busy = true;
1034   if ( !(myEditCurrentArgument->text().isEmpty()) )
1035     {
1036       myFacesByNodes->insertItem(myEditCurrentArgument->text());
1037       //myFacesByNodes->setSelected(myFacesByNodes->count() - 1, true);
1038       myNbOkElements = 1;
1039       myEditCurrentArgument->clear();
1040       AddButton->setEnabled(false);
1041       buttonOk->setEnabled( true );
1042       if(myFacesByNodes->count()>1) buttonApply->setEnabled( true );
1043     }
1044   busy = false;
1045   onListSelectionChanged();
1046   displaySimulation();
1047 }
1048
1049 //=================================================================================
1050 // function : onRemove()
1051 // purpose  :
1052 //=================================================================================
1053 void SMESHGUI_CreatePolyhedralVolumeDlg::onRemove()
1054 {
1055   busy = true;
1056   for (int i = myFacesByNodes->count(); i > 0; i--) {
1057     if (myFacesByNodes->isSelected(i-1)) {
1058       myFacesByNodes->removeItem(i-1);
1059       myNbOkElements = 1;
1060     }
1061   }
1062   if (myFacesByNodes->count() < 1){
1063     RemoveButton->setEnabled(false);
1064     buttonOk->setEnabled( false );
1065     buttonApply->setEnabled( false );
1066   } 
1067   else if (myFacesByNodes->count() == 1){
1068     buttonOk->setEnabled( false );
1069     buttonApply->setEnabled( false );
1070   }
1071   busy = false;
1072   displaySimulation();
1073 }
1074
1075 //=================================================================================
1076 // function : onListSelectionChanged()
1077 // purpose  : Called when selection in element list is changed
1078 //=================================================================================
1079 void SMESHGUI_CreatePolyhedralVolumeDlg::onListSelectionChanged()
1080 {
1081   if (busy || !myActor) return;
1082   busy = true;
1083   bool isSelected=false;
1084   SALOME_ListIO aList;
1085   mySelectionMgr->setSelectedObjects( aList );
1086   TColStd_MapOfInteger aIndexes;
1087   QListBoxItem* anItem;
1088   for (anItem = myFacesByNodes->firstItem(); anItem != 0; anItem = anItem->next()) {
1089     if (anItem->isSelected()) {
1090       isSelected = true;
1091       QStringList anIds = QStringList::split(" ", anItem->text());
1092       for (QStringList::iterator it = anIds.begin(); it != anIds.end(); ++it)
1093         aIndexes.Add((*it).toInt());
1094     }
1095   }
1096   if(isSelected) RemoveButton->setEnabled(true);
1097   else RemoveButton->setEnabled(false);
1098   mySelector->AddOrRemoveIndex(myActor->getIO(), aIndexes, true );
1099   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1100     aViewWindow->highlight( myActor->getIO(), true, true );
1101   mySelectionMgr->clearFilters(); 
1102   aList.Append( myActor->getIO() );
1103   mySelectionMgr->setSelectedObjects( aList );
1104   
1105   busy = false;
1106 }