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