1 // SMESH SMESHGUI : GUI for SMESH component
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : SMESHGUI_CreatePolyhedralVolumeDlg.cxx
25 // Author : Michael ZORIN
29 #include "SMESHGUI_CreatePolyhedralVolumeDlg.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"
42 #include "VTKViewer_ViewFrame.h"
44 #include "QAD_Application.h"
45 #include "QAD_Desktop.h"
46 #include "QAD_MessageBox.h"
47 #include "utilities.h"
49 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
50 #include <TColStd_ListOfInteger.hxx>
51 #include <TColStd_ListIteratorOfListOfInteger.hxx>
54 #include <vtkIdList.h>
55 #include <vtkIntArray.h>
56 #include <vtkCellArray.h>
57 #include <vtkUnsignedCharArray.h>
58 #include <vtkUnstructuredGrid.h>
59 #include <vtkDataSetMapper.h>
62 #include <qapplication.h>
63 #include <qbuttongroup.h>
64 #include <qgroupbox.h>
66 #include <qlineedit.h>
67 #include <qpushbutton.h>
68 #include <qradiobutton.h>
69 #include <qcheckbox.h>
76 #include "SALOMEconfig.h"
77 #include CORBA_SERVER_HEADER(SMESH_Group)
83 class TPolySimulation{
85 QAD_StudyFrame* myStudyFrame;
86 VTKViewer_ViewFrame* myViewFrame;
88 SALOME_Actor *myPreviewActor;
89 vtkDataSetMapper* myMapper;
90 vtkUnstructuredGrid* myGrid;
94 TPolySimulation(QAD_Study* theStudy):
96 myStudyFrame(theStudy->getActiveStudyFrame()),
97 myViewFrame(GetVtkViewFrame(theStudy->getActiveStudyFrame()))
99 myGrid = vtkUnstructuredGrid::New();
101 // Create and display actor
102 myMapper = vtkDataSetMapper::New();
103 myMapper->SetInput( myGrid );
105 myPreviewActor = SALOME_Actor::New();
106 myPreviewActor->PickableOff();
107 myPreviewActor->VisibilityOff();
108 myPreviewActor->SetMapper( myMapper );
110 vtkProperty* aProp = vtkProperty::New();
112 anRGB[0] = GetFloat("SMESH:SettingsFillColorRed", 0)/255.;
113 anRGB[1] = GetFloat("SMESH:SettingsFillColorGreen", 170)/255.;
114 anRGB[2] = GetFloat("SMESH:SettingsFillColorBlue", 255)/255.;
115 aProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
116 myPreviewActor->SetProperty( aProp );
119 vtkProperty* aBackProp = vtkProperty::New();
120 anRGB[0] = GetFloat("SMESH:SettingsBackFaceColorRed", 0)/255.;
121 anRGB[1] = GetFloat("SMESH:SettingsBackFaceColorGreen", 0)/255.;
122 anRGB[2] = GetFloat("SMESH:SettingsBackFaceColorBlue", 255)/255.;
123 aBackProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
124 myPreviewActor->SetBackfaceProperty( aBackProp );
127 myViewFrame->AddActor( myPreviewActor );
132 typedef std::vector<vtkIdType> TVTKIds;
133 void SetPosition(SMESH_Actor* theActor,
135 const TVTKIds& theIds,
138 vtkUnstructuredGrid *aGrid = theActor->GetUnstructuredGrid();
139 myGrid->SetPoints(aGrid->GetPoints());
141 if (theReset) ResetGrid(theReset);
143 vtkIdList *anIds = vtkIdList::New();
145 for (int i = 0, iEnd = theIds.size(); i < iEnd; i++)
146 anIds->InsertId(i,theIds[i]);
148 myGrid->InsertNextCell(theType,anIds);
156 void ResetGrid(bool theReset=true){
157 if (theReset) myGrid->Reset();
160 void SetVisibility(bool theVisibility){
161 myPreviewActor->SetVisibility(theVisibility);
162 RepaintCurrentView();
167 if(FindVtkViewFrame(myStudy,myStudyFrame)){
168 myViewFrame->RemoveActor(myPreviewActor);
170 myPreviewActor->Delete();
172 myMapper->RemoveAllInputs();
181 //=================================================================================
182 // class : SMESHGUI_CreatePolyhedralVolumeDlgDlg()
184 //=================================================================================
185 SMESHGUI_CreatePolyhedralVolumeDlg::SMESHGUI_CreatePolyhedralVolumeDlg( QWidget* parent, const char* name, SALOME_Selection* Sel,
186 bool modal, WFlags fl )
187 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu |
188 Qt::WDestructiveClose)
190 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_SELECT")));
193 setName( "SMESHGUI_CreatePolyhedralVolumeDlg" );
195 setCaption( tr( "SMESH_CREATE_POLYHEDRAL_VOLUME_TITLE" ) );
196 setSizeGripEnabled( TRUE );
197 SMESHGUI_CreatePolyhedralVolumeDlgLayout = new QGridLayout( this );
198 SMESHGUI_CreatePolyhedralVolumeDlgLayout->setSpacing( 6 );
199 SMESHGUI_CreatePolyhedralVolumeDlgLayout->setMargin( 11 );
201 /***************************************************************/
202 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
203 GroupConstructors->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)5, (QSizePolicy::SizeType)0, 0, 0, GroupConstructors->sizePolicy().hasHeightForWidth() ) );
204 GroupConstructors->setTitle( tr( "SMESH_ELEMENTS_TYPE" ) );
205 GroupConstructors->setExclusive( TRUE );
206 GroupConstructors->setColumnLayout(0, Qt::Vertical );
207 GroupConstructors->layout()->setSpacing( 0 );
208 GroupConstructors->layout()->setMargin( 0 );
209 GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
210 GroupConstructorsLayout->setAlignment( Qt::AlignTop );
211 GroupConstructorsLayout->setSpacing( 6 );
212 GroupConstructorsLayout->setMargin( 11 );
213 RadioButton1= new QRadioButton( GroupConstructors, "RadioButton1" );
214 RadioButton1->setText( tr( "MESH_NODE" ) );
215 GroupConstructorsLayout->addWidget( RadioButton1, 0, 0 );
216 RadioButton2= new QRadioButton( GroupConstructors, "RadioButton2" );
217 RadioButton2->setText( tr( "SMESH_FACE" ) );
218 GroupConstructorsLayout->addWidget( RadioButton2, 0, 2 );
219 SMESHGUI_CreatePolyhedralVolumeDlgLayout->addWidget( GroupConstructors, 0, 0 );
221 /***************************************************************/
222 GroupButtons = new QGroupBox( this, "GroupButtons" );
223 GroupButtons->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)7, (QSizePolicy::SizeType)0, 0, 0, GroupButtons->sizePolicy().hasHeightForWidth() ) );
224 GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) );
225 GroupButtons->setTitle( tr( "" ) );
226 GroupButtons->setColumnLayout(0, Qt::Vertical );
227 GroupButtons->layout()->setSpacing( 0 );
228 GroupButtons->layout()->setMargin( 0 );
229 GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
230 GroupButtonsLayout->setAlignment( Qt::AlignTop );
231 GroupButtonsLayout->setSpacing( 6 );
232 GroupButtonsLayout->setMargin( 11 );
233 buttonCancel = new QPushButton( GroupButtons, "cancel" );
234 buttonCancel->setText( tr( "SMESH_BUT_CLOSE" ) );
235 buttonCancel->setAutoDefault( TRUE );
236 GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
237 buttonApply = new QPushButton( GroupButtons, "apply" );
238 buttonApply->setText( tr( "SMESH_BUT_APPLY" ) );
239 buttonApply->setAutoDefault( TRUE );
240 GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
241 QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
242 GroupButtonsLayout->addItem( spacer_9, 0, 2 );
243 buttonOk = new QPushButton( GroupButtons, "ok" );
244 buttonOk->setText( tr( "SMESH_BUT_OK" ) );
245 buttonOk->setAutoDefault( TRUE );
246 buttonOk->setDefault( TRUE );
247 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
248 SMESHGUI_CreatePolyhedralVolumeDlgLayout->addWidget( GroupButtons, 2, 0 );
250 /***************************************************************/
251 GroupContent = new QGroupBox( this, "GroupContent" );
252 GroupContent->setTitle( tr( "SMESH_CONTENT" ) );
253 GroupContent->setColumnLayout(0, Qt::Vertical );
254 GroupContent->layout()->setSpacing( 0 );
255 GroupContent->layout()->setMargin( 0 );
256 GroupContentLayout = new QGridLayout( GroupContent->layout() );
257 GroupContentLayout->setAlignment( Qt::AlignTop );
258 GroupContentLayout->setSpacing( 6 );
259 GroupContentLayout->setMargin( 11 );
261 QFrame* anIds = new QFrame(GroupContent, "anIds");
262 QGridLayout* aLayout = new QGridLayout(anIds, 1, 3);
263 aLayout->setSpacing(6);
264 aLayout->setAutoAdd(false);
266 TextLabelIds = new QLabel( anIds, "TextLabelIds" );
267 TextLabelIds->setText( tr( "SMESH_ID_NODES" ) );
268 TextLabelIds->setFixedWidth(74);
269 aLayout->addWidget( TextLabelIds, 0, 0 );
271 SelectElementsButton = new QPushButton( anIds, "SelectElementsButton" );
272 SelectElementsButton->setText( tr( "" ) );
273 SelectElementsButton->setPixmap( image0 );
274 SelectElementsButton->setToggleButton( FALSE );
275 aLayout->addWidget( SelectElementsButton, 0, 1 );
277 LineEditElements = new QLineEdit( anIds, "LineEditElements" );
278 LineEditElements->setValidator( new SMESHGUI_IdValidator( this, "validator" ));
279 aLayout->addWidget( LineEditElements, 0, 2 );
281 GroupContentLayout->addMultiCellWidget(anIds, 0, 0, 0, 1);
283 myFacesByNodesLabel = new QLabel(GroupContent, "faces by nodes label");
284 myFacesByNodesLabel->setText(tr("FACES_BY_NODES"));
285 GroupContentLayout->addWidget( myFacesByNodesLabel, 1, 0 );
287 myFacesByNodes = new QListBox(GroupContent, "faces by nodes list");
288 myFacesByNodes->setSelectionMode(QListBox::Extended);
289 myFacesByNodes->setMinimumHeight(150);
290 GroupContentLayout->addMultiCellWidget( myFacesByNodes, 2, 4, 0, 0 );
292 AddButton = new QPushButton(GroupContent, "add");
293 AddButton->setText(tr("SMESH_BUT_ADD"));
294 AddButton->setMaximumWidth(85);
295 GroupContentLayout->addWidget( AddButton, 2, 1 );
297 RemoveButton = new QPushButton(GroupContent, "remove");
298 RemoveButton->setText(tr("SMESH_BUT_REMOVE"));
299 RemoveButton->setMaximumWidth(85);
300 GroupContentLayout->addWidget( RemoveButton, 3, 1 );
302 Preview = new QCheckBox( GroupContent, "Preview" );
303 Preview->setText( tr( "SMESH_POLYEDRE_PREVIEW" ) );
304 GroupContentLayout->addWidget( Preview , 5, 0 );
306 SMESHGUI_CreatePolyhedralVolumeDlgLayout->addWidget( GroupContent, 1, 0 );
308 GroupContent->show();
309 RadioButton1->setChecked( TRUE );
312 mySMESHGUI = SMESHGUI::GetSMESHGUI() ;
313 mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
318 //=================================================================================
319 // function : ~SMESHGUI_CreatePolyhedralVolumeDlg()
320 // purpose : Destroys the object and frees any allocated resources
321 //=================================================================================
322 SMESHGUI_CreatePolyhedralVolumeDlg::~SMESHGUI_CreatePolyhedralVolumeDlg()
324 // no need to delete child widgets, Qt does it all for us
328 static bool busy = false;
329 //=================================================================================
332 //=================================================================================
333 void SMESHGUI_CreatePolyhedralVolumeDlg::Init( SALOME_Selection* Sel )
335 myEditCurrentArgument = LineEditElements;
337 mySMESHGUI = SMESHGUI::GetSMESHGUI() ;
338 mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
340 myOkElements = false;
343 mySimulation = new SMESH::TPolySimulation(SMESH::GetActiveStudy());
345 /* signals and slots connections */
346 connect(buttonOk, SIGNAL( clicked() ), SLOT( ClickOnOk() ) );
347 connect(buttonCancel, SIGNAL( clicked() ), SLOT( ClickOnCancel() ) ) ;
348 connect(buttonApply, SIGNAL( clicked() ), SLOT(ClickOnApply() ) );
350 connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
351 connect(SelectElementsButton, SIGNAL( clicked() ), SLOT( SetEditCurrentArgument() ) ) ;
352 connect(LineEditElements, SIGNAL( textChanged(const QString&) ), SLOT(onTextChange(const QString&)));
354 connect(myFacesByNodes, SIGNAL(selectionChanged()), this, SLOT(onListSelectionChanged()));
355 connect(AddButton, SIGNAL(clicked()), this, SLOT(onAdd()));
356 connect(RemoveButton, SIGNAL(clicked()), this, SLOT(onRemove()));
358 connect( mySMESHGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
359 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
360 connect( Preview, SIGNAL(toggled(bool)), this, SLOT(ClickOnPreview(bool)));
361 /* to close dialog if study change */
362 connect( mySMESHGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
364 /* Move widget on the botton right corner of main widget */
366 mySMESHGUI->DefineDlgPosition( this, x, y ) ;
368 this->show() ; /* displays Dialog */
370 ConstructorsClicked(0);
371 SelectionIntoArgument();
375 //=================================================================================
376 // function : ConstructorsClicked()
377 // purpose : Radio button management
378 //=================================================================================
379 void SMESHGUI_CreatePolyhedralVolumeDlg::ConstructorsClicked(int constructorId)
381 disconnect(mySelection, 0, this, 0);
383 mySelection->ClearIObjects();
384 myEditCurrentArgument->clear();
385 myOkElements = false;
386 buttonApply->setEnabled(false);
387 buttonOk->setEnabled(false);
388 mySimulation->SetVisibility(false);
390 switch(constructorId)
395 myActor->SetPointRepresentation(true);
398 SMESH::SetPointRepresentation(true);
399 QAD_Application::getDesktop()->SetSelectionMode(NodeSelection, true);
401 AddButton->setEnabled(false);
402 RemoveButton->setEnabled(false);
403 TextLabelIds->setText( tr( "SMESH_ID_NODES" ) );
404 myFacesByNodesLabel->show();
405 myFacesByNodes->clear();
406 myFacesByNodes->show();
408 RemoveButton->show();
414 SMESH::SetPointRepresentation(false);
415 QAD_Application::getDesktop()->SetSelectionMode(FaceSelection, true);
417 TextLabelIds->setText( tr( "SMESH_ID_FACES" ) );
418 myFacesByNodesLabel->hide();
419 myFacesByNodes->hide();
421 RemoveButton->hide();
427 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
430 //=================================================================================
431 // function : ClickOnPreview()
433 //=================================================================================
434 void SMESHGUI_CreatePolyhedralVolumeDlg::ClickOnPreview(bool theToggled){
435 Preview->setChecked(theToggled);
439 //=================================================================================
440 // function : ClickOnApply()
442 //=================================================================================
443 void SMESHGUI_CreatePolyhedralVolumeDlg::ClickOnApply()
445 if ( myOkElements && !mySMESHGUI->ActiveStudyLocked())
448 if (GetConstructorId() == 0)
450 SMESH::long_array_var anIdsOfNodes = new SMESH::long_array;
451 SMESH::long_array_var aQuantities = new SMESH::long_array;
453 aQuantities->length( myFacesByNodes->count() );
455 TColStd_ListOfInteger aNodesIds;
457 QListBoxItem* anItem;
458 int aNbQuantities = 0;
459 for (anItem = myFacesByNodes->firstItem(); anItem != 0; anItem = anItem->next()) {
460 QStringList anIds = QStringList::split(" ", anItem->text());
461 int aNbNodesInFace = 0;
462 for (QStringList::iterator it = anIds.begin(); it != anIds.end(); ++it, ++aNbNodesInFace)
463 aNodesIds.Append( (*it).toInt() );
465 aQuantities[aNbQuantities++] = aNbNodesInFace;
468 anIdsOfNodes->length(aNodesIds.Extent());
470 int aNbIdsOfNodes = 0;
471 TColStd_ListIteratorOfListOfInteger It;
472 It.Initialize(aNodesIds);
473 for(;It.More();It.Next())
474 anIdsOfNodes[aNbIdsOfNodes++] = It.Value();
477 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
478 QApplication::setOverrideCursor(Qt::waitCursor);
479 aMeshEditor->AddPolyhedralVolume(anIdsOfNodes, aQuantities);
480 QApplication::restoreOverrideCursor();
481 }catch(SALOME::SALOME_Exception& exc){
482 INFOS("Follow exception was cought:\n\t"<<exc.details.text);
483 }catch(std::exception& exc){
484 INFOS("Follow exception was cought:\n\t"<<exc.what());
486 INFOS("Unknown exception was cought !!!");
489 else if (GetConstructorId() == 1)
491 SMESH::long_array_var anIdsOfFaces = new SMESH::long_array;
493 QStringList aListId = QStringList::split( " ", myEditCurrentArgument->text() );
494 anIdsOfFaces->length(aListId.count());
495 for ( int i = 0; i < aListId.count(); i++ )
496 anIdsOfFaces[i] = aListId[i].toInt();
499 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
500 QApplication::setOverrideCursor(Qt::waitCursor);
501 aMeshEditor->AddPolyhedralVolumeByFaces(anIdsOfFaces);
502 QApplication::restoreOverrideCursor();
503 }catch(SALOME::SALOME_Exception& exc){
504 INFOS("Follow exception was cought:\n\t"<<exc.details.text);
505 }catch(std::exception& exc){
506 INFOS("Follow exception was cought:\n\t"<<exc.what());
508 INFOS("Unknown exception was cought !!!");
512 mySelection->ClearIObjects();
513 mySimulation->SetVisibility(false);
515 ConstructorsClicked( GetConstructorId() );
520 //=================================================================================
521 // function : ClickOnOk()
523 //=================================================================================
524 void SMESHGUI_CreatePolyhedralVolumeDlg::ClickOnOk()
531 //=================================================================================
532 // function : ClickOnCancel()
534 //=================================================================================
535 void SMESHGUI_CreatePolyhedralVolumeDlg::ClickOnCancel()
537 mySelection->ClearFilters();
538 mySelection->ClearIObjects();
539 SMESH::SetPointRepresentation(false);
540 mySimulation->SetVisibility(false);
541 QAD_Application::getDesktop()->SetSelectionMode( ActorSelection );
542 disconnect( mySelection, 0, this, 0 );
543 mySMESHGUI->ResetState() ;
547 //=======================================================================
548 //function : onTextChange
550 //=======================================================================
552 void SMESHGUI_CreatePolyhedralVolumeDlg::onTextChange(const QString& theNewText)
557 mySimulation->SetVisibility(false);
559 SMDS_Mesh* aMesh = 0;
561 aMesh = myActor->GetObject()->GetMesh();
563 if (GetConstructorId() == 0)
566 mySelection->ClearIObjects();
567 mySelection->AddIObject( myActor->getIO() );
569 QStringList aListId = QStringList::split( " ", theNewText, false);
571 for ( int i = 0; i < aListId.count(); i++ ) {
572 const SMDS_MeshNode * n = aMesh->FindNode( aListId[ i ].toInt() );
574 if ( mySelection->IsIndexSelected( myActor->getIO(), n->GetID() ))
577 mySelection->AddOrRemoveIndex (myActor->getIO(), n->GetID(), true);
583 bool aNodesOK = false;
584 if (aListId.count() >= 3)
587 allOk = (allOk && aNodesOK);
590 AddButton->setEnabled(true);
592 AddButton->setEnabled(false);
594 if (allOk && !myOkElements)
598 else if (GetConstructorId() == 1)
600 myOkElements = false;
601 buttonOk->setEnabled( false );
602 buttonApply->setEnabled( false );
604 // check entered ids of faces and hilight them
607 mySelection->ClearIObjects();
608 mySelection->AddIObject( myActor->getIO() );
610 aListId = QStringList::split( " ", theNewText, false);
613 for ( int i = 0; i < aListId.count(); i++ ) {
614 const SMDS_MeshElement * e = aMesh->FindElement( aListId[ i ].toInt() );
616 if ( mySelection->IsIndexSelected( myActor->getIO(), e->GetID() ))
617 myOkElements = false;
619 mySelection->AddOrRemoveIndex (myActor->getIO(), e->GetID(), true);
622 myOkElements = false;
626 if ( myOkElements ) {
627 if (aListId.count()>1){
628 buttonOk->setEnabled( true );
629 buttonApply->setEnabled( true );
632 buttonOk->setEnabled( false );
633 buttonApply->setEnabled( false );
642 //=================================================================================
643 // function : SelectionIntoArgument()
644 // purpose : Called when selection as changed or other case
645 //=================================================================================
646 void SMESHGUI_CreatePolyhedralVolumeDlg::SelectionIntoArgument()
652 if (GetConstructorId() == 1 || myFacesByNodes->count() <= 1)
654 myOkElements = false;
655 AddButton->setEnabled(false);
656 buttonOk->setEnabled( false );
657 buttonApply->setEnabled( false );
663 myEditCurrentArgument->setText( "" );
665 if ( !GroupButtons->isEnabled() ) // inactive
668 mySimulation->SetVisibility(false);
672 int nbSel = mySelection->IObjectCount();
677 myMesh = SMESH::GetMeshByIO( mySelection->firstIObject() );
678 if ( myMesh->_is_nil() )
681 myActor = SMESH::FindActorByObject(myMesh);
685 // get selected nodes/faces
686 QString aString = "";
687 switch(GetConstructorId()){
689 int anbNodes = SMESH::GetNameOfSelectedNodes(mySelection, aString);
691 AddButton->setEnabled(true);
695 myEditCurrentArgument->setText( aString );
700 // get selected faces
701 int aNbFaces = SMESH::GetNameOfSelectedElements(mySelection, aString);
705 myEditCurrentArgument->setText( aString );
710 buttonOk->setEnabled( true );
711 buttonApply->setEnabled( true );
720 //=======================================================================
721 //function : displaySimulation
723 //=======================================================================
724 void SMESHGUI_CreatePolyhedralVolumeDlg::displaySimulation()
726 if ( (myOkElements || AddButton->isEnabled()) && GroupButtons->isEnabled() && myActor)
728 SMESH::TPolySimulation::TVTKIds aVTKIds;
729 vtkIdType aType = VTK_CONVEX_POINT_SET ;
730 if (GetConstructorId() == 0){
731 if(!Preview->isChecked()) myActor->SetEntityMode(SMESH_Actor::eFaces);
732 else myActor->SetEntityMode(SMESH_Actor::eVolumes);
733 if (!AddButton->isEnabled()){
734 QListBoxItem* anItem;
735 mySimulation->ResetGrid(true);
736 for (anItem = myFacesByNodes->firstItem(); anItem != 0; anItem = anItem->next()) {
737 QStringList anIds = QStringList::split(" ", anItem->text());
738 SMESH::TPolySimulation::TVTKIds aVTKIds_faces;
739 for (QStringList::iterator it = anIds.begin(); it != anIds.end(); ++it){
740 vtkIdType aId = myActor->GetObject()->GetNodeVTKId( (*it).toInt() ) ;
741 aVTKIds.push_back(aId);
742 aVTKIds_faces.push_back(aId);
744 if(!Preview->isChecked()){
746 mySimulation->SetPosition(myActor, aType, aVTKIds_faces,false);
749 if(Preview->isChecked()){
750 mySimulation->SetPosition(myActor, aType, aVTKIds);
753 // add ids from edit line
754 QStringList anEditIds = QStringList::split( " ", myEditCurrentArgument->text(), false);
755 myActor->SetEntityMode(SMESH_Actor::eFaces);
756 for ( int i = 0; i < anEditIds.count(); i++ )
757 aVTKIds.push_back( myActor->GetObject()->GetNodeVTKId( anEditIds[ i ].toInt() ));
759 mySimulation->SetPosition(myActor, aType, aVTKIds);
761 }else if(GetConstructorId() == 1){
762 SMDS_Mesh* aMesh = 0;
764 aMesh = myActor->GetObject()->GetMesh();
765 if (Preview->isChecked())
766 myActor->SetEntityMode(SMESH_Actor::eVolumes);
768 myActor->SetEntityMode(SMESH_Actor::eFaces);
771 QStringList aListId = QStringList::split( " ", myEditCurrentArgument->text(), false);
772 for ( int i = 0; i < aListId.count(); i++ )
774 const SMDS_MeshElement * anElem = aMesh->FindElement( aListId[ i ].toInt() );
778 SMDS_ElemIteratorPtr anIter = anElem->nodesIterator();
779 SMESH::TPolySimulation::TVTKIds aVTKIds_faces;
780 while( anIter->more() )
781 if ( const SMDS_MeshNode* aNode = (SMDS_MeshNode*)anIter->next() ){
782 vtkIdType aId = myActor->GetObject()->GetNodeVTKId( aNode->GetID() ) ;
783 aVTKIds.push_back(aId);
784 aVTKIds_faces.push_back(aId);
786 if(!Preview->isChecked()){
788 mySimulation->SetPosition(myActor, aType, aVTKIds_faces);
791 if(Preview->isChecked())
792 mySimulation->SetPosition(myActor, aType, aVTKIds);
798 //=================================================================================
799 // function : SetEditCurrentArgument()
801 //=================================================================================
802 void SMESHGUI_CreatePolyhedralVolumeDlg::SetEditCurrentArgument()
804 QPushButton* send = (QPushButton*)sender();
805 if(send == SelectElementsButton) {
806 LineEditElements->setFocus() ;
807 myEditCurrentArgument = LineEditElements;
809 SelectionIntoArgument();
812 //=================================================================================
813 // function : DeactivateActiveDialog()
815 //=================================================================================
816 void SMESHGUI_CreatePolyhedralVolumeDlg::DeactivateActiveDialog()
818 if ( GroupConstructors->isEnabled() ) {
819 GroupConstructors->setEnabled(false) ;
820 GroupContent->setEnabled(false) ;
821 GroupButtons->setEnabled(false) ;
822 mySimulation->SetVisibility(false);
823 mySMESHGUI->ResetState() ;
824 mySMESHGUI->SetActiveDialogBox(0) ;
829 //=================================================================================
830 // function : ActivateThisDialog()
832 //=================================================================================
833 void SMESHGUI_CreatePolyhedralVolumeDlg::ActivateThisDialog()
835 /* Emit a signal to deactivate the active dialog */
836 mySMESHGUI->EmitSignalDeactivateDialog() ;
837 GroupConstructors->setEnabled(true) ;
838 GroupContent->setEnabled(true) ;
839 GroupButtons->setEnabled(true) ;
841 mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
843 QAD_Application::getDesktop()->SetSelectionMode( FaceSelection, true );
844 SelectionIntoArgument();
848 //=================================================================================
849 // function : enterEvent()
851 //=================================================================================
852 void SMESHGUI_CreatePolyhedralVolumeDlg::enterEvent(QEvent* e)
854 if ( GroupConstructors->isEnabled() )
856 ActivateThisDialog() ;
860 //=================================================================================
861 // function : closeEvent()
863 //=================================================================================
864 void SMESHGUI_CreatePolyhedralVolumeDlg::closeEvent( QCloseEvent* e )
866 /* same than click on cancel button */
867 this->ClickOnCancel() ;
871 //=======================================================================
872 //function : hideEvent
873 //purpose : caused by ESC key
874 //=======================================================================
876 void SMESHGUI_CreatePolyhedralVolumeDlg::hideEvent ( QHideEvent * e )
878 if ( !isMinimized() )
883 //=================================================================================
884 // function : GetConstructorId()
886 //=================================================================================
887 int SMESHGUI_CreatePolyhedralVolumeDlg::GetConstructorId()
889 if ( GroupConstructors != NULL && GroupConstructors->selected() != NULL )
890 return GroupConstructors->id( GroupConstructors->selected() );
894 //=================================================================================
895 // function : onAdd()
897 //=================================================================================
898 void SMESHGUI_CreatePolyhedralVolumeDlg::onAdd()
900 int aNbSel = mySelection->IObjectCount();
901 if (aNbSel == 0 || !myActor || myMesh->_is_nil()) return;
905 if ( !(myEditCurrentArgument->text().isEmpty()) )
907 myFacesByNodes->insertItem(myEditCurrentArgument->text());
908 //myFacesByNodes->setSelected(myFacesByNodes->count() - 1, true);
910 myEditCurrentArgument->clear();
911 AddButton->setEnabled(false);
912 RemoveButton->setEnabled(true);
913 buttonOk->setEnabled( true );
914 if(myFacesByNodes->count()>1) buttonApply->setEnabled( true );
917 onListSelectionChanged();
921 //=================================================================================
922 // function : onRemove()
924 //=================================================================================
925 void SMESHGUI_CreatePolyhedralVolumeDlg::onRemove()
928 for (int i = myFacesByNodes->count(); i > 0; i--) {
929 if (myFacesByNodes->isSelected(i-1)) {
930 myFacesByNodes->removeItem(i-1);
933 if (myFacesByNodes->count() < 1){
934 myOkElements = false;
935 RemoveButton->setEnabled(false);
936 buttonOk->setEnabled( false );
937 buttonApply->setEnabled( false );
939 else if (myFacesByNodes->count() == 1){
940 myOkElements = false;
941 buttonOk->setEnabled( false );
942 buttonApply->setEnabled( false );
946 onListSelectionChanged();
949 //=================================================================================
950 // function : onListSelectionChanged()
951 // purpose : Called when selection in element list is changed
952 //=================================================================================
953 void SMESHGUI_CreatePolyhedralVolumeDlg::onListSelectionChanged()
955 if (busy || !myActor) return;
958 mySelection->ClearIObjects();
959 TColStd_MapOfInteger aIndexes;
960 QListBoxItem* anItem;
961 for (anItem = myFacesByNodes->firstItem(); anItem != 0; anItem = anItem->next()) {
962 if (anItem->isSelected()) {
963 QStringList anIds = QStringList::split(" ", anItem->text());
964 for (QStringList::iterator it = anIds.begin(); it != anIds.end(); ++it)
965 aIndexes.Add((*it).toInt());
968 mySelection->AddOrRemoveIndex(myActor->getIO(), aIndexes, false, false);
969 mySelection->AddIObject(myActor->getIO());