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_ViewWindow.h"
44 #include "SUIT_ResourceMgr.h"
46 #include "SalomeApp_Application.h"
47 #include "SalomeApp_Study.h"
48 #include "SUIT_Desktop.h"
49 #include "SUIT_MessageBox.h"
50 #include "SalomeApp_SelectionMgr.h"
51 #include "utilities.h"
53 #include "SVTK_ViewWindow.h"
54 #include "SVTK_Selector.h"
56 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
57 #include <TColStd_ListOfInteger.hxx>
58 #include <TColStd_ListIteratorOfListOfInteger.hxx>
61 #include <vtkIdList.h>
62 #include <vtkIntArray.h>
63 #include <vtkCellArray.h>
64 #include <vtkUnsignedCharArray.h>
65 #include <vtkUnstructuredGrid.h>
66 #include <vtkDataSetMapper.h>
69 #include <qapplication.h>
70 #include <qbuttongroup.h>
71 #include <qgroupbox.h>
73 #include <qlineedit.h>
74 #include <qpushbutton.h>
75 #include <qradiobutton.h>
76 #include <qcheckbox.h>
83 #include "SALOMEconfig.h"
84 #include CORBA_SERVER_HEADER(SMESH_Group)
90 class TPolySimulation{
91 SVTK_ViewWindow* myViewWindow;
93 SALOME_Actor *myPreviewActor;
94 vtkDataSetMapper* myMapper;
95 vtkUnstructuredGrid* myGrid;
99 TPolySimulation(SalomeApp_Application* app)
101 SUIT_ViewManager* mgr = app->activeViewManager();
102 myViewWindow = mgr ? dynamic_cast<SVTK_ViewWindow*>( mgr->getActiveView() ) : NULL;
104 myGrid = vtkUnstructuredGrid::New();
106 // Create and display actor
107 myMapper = vtkDataSetMapper::New();
108 myMapper->SetInput( myGrid );
110 myPreviewActor = SALOME_Actor::New();
111 myPreviewActor->PickableOff();
112 myPreviewActor->VisibilityOff();
113 myPreviewActor->SetMapper( myMapper );
115 vtkProperty* aProp = vtkProperty::New();
117 anRGB[0] = GetFloat("SMESH:SettingsFillColorRed", 0)/255.;
118 anRGB[1] = GetFloat("SMESH:SettingsFillColorGreen", 170)/255.;
119 anRGB[2] = GetFloat("SMESH:SettingsFillColorBlue", 255)/255.;
120 aProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
121 myPreviewActor->SetProperty( aProp );
124 vtkProperty* aBackProp = vtkProperty::New();
125 anRGB[0] = GetFloat("SMESH:SettingsBackFaceColorRed", 0)/255.;
126 anRGB[1] = GetFloat("SMESH:SettingsBackFaceColorGreen", 0)/255.;
127 anRGB[2] = GetFloat("SMESH:SettingsBackFaceColorBlue", 255)/255.;
128 aBackProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
129 myPreviewActor->SetBackfaceProperty( aBackProp );
132 myViewWindow->AddActor( myPreviewActor );
137 typedef std::vector<vtkIdType> TVTKIds;
138 void SetPosition(SMESH_Actor* theActor,
140 const TVTKIds& theIds,
143 vtkUnstructuredGrid *aGrid = theActor->GetUnstructuredGrid();
144 myGrid->SetPoints(aGrid->GetPoints());
146 if (theReset) ResetGrid(theReset);
148 vtkIdList *anIds = vtkIdList::New();
150 for (int i = 0, iEnd = theIds.size(); i < iEnd; i++)
151 anIds->InsertId(i,theIds[i]);
153 myGrid->InsertNextCell(theType,anIds);
154 if(theIds.size()!=0){
155 myGrid->InsertNextCell(theType,anIds);
165 void ResetGrid(bool theReset=true){
166 if (theReset) myGrid->Reset();
169 void SetVisibility(bool theVisibility){
170 myPreviewActor->SetVisibility(theVisibility);
171 RepaintCurrentView();
177 myViewWindow->RemoveActor(myPreviewActor);
179 myPreviewActor->Delete();
181 myMapper->RemoveAllInputs();
190 //=================================================================================
191 // class : SMESHGUI_CreatePolyhedralVolumeDlgDlg()
193 //=================================================================================
194 SMESHGUI_CreatePolyhedralVolumeDlg::SMESHGUI_CreatePolyhedralVolumeDlg( SMESHGUI* theModule, const char* name,
195 bool modal, WFlags fl )
196 : QDialog( SMESH::GetDesktop( theModule ), name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | Qt::WDestructiveClose),
197 mySMESHGUI( theModule ),
198 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
199 myViewWindow( SMESH::GetViewWindow( theModule ) ),
200 mySelector( myViewWindow->GetSelector() )
202 QPixmap image0( SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap( "SMESH",tr("ICON_SELECT")));
205 setName( "SMESHGUI_CreatePolyhedralVolumeDlg" );
207 setCaption( tr( "SMESH_CREATE_POLYHEDRAL_VOLUME_TITLE" ) );
208 setSizeGripEnabled( TRUE );
209 SMESHGUI_CreatePolyhedralVolumeDlgLayout = new QGridLayout( this );
210 SMESHGUI_CreatePolyhedralVolumeDlgLayout->setSpacing( 6 );
211 SMESHGUI_CreatePolyhedralVolumeDlgLayout->setMargin( 11 );
213 /***************************************************************/
214 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
215 GroupConstructors->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)5, (QSizePolicy::SizeType)0, 0, 0, GroupConstructors->sizePolicy().hasHeightForWidth() ) );
216 GroupConstructors->setTitle( tr( "SMESH_ELEMENTS_TYPE" ) );
217 GroupConstructors->setExclusive( TRUE );
218 GroupConstructors->setColumnLayout(0, Qt::Vertical );
219 GroupConstructors->layout()->setSpacing( 0 );
220 GroupConstructors->layout()->setMargin( 0 );
221 GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
222 GroupConstructorsLayout->setAlignment( Qt::AlignTop );
223 GroupConstructorsLayout->setSpacing( 6 );
224 GroupConstructorsLayout->setMargin( 11 );
225 RadioButton1= new QRadioButton( GroupConstructors, "RadioButton1" );
226 RadioButton1->setText( tr( "MESH_NODE" ) );
227 GroupConstructorsLayout->addWidget( RadioButton1, 0, 0 );
228 RadioButton2= new QRadioButton( GroupConstructors, "RadioButton2" );
229 RadioButton2->setText( tr( "SMESH_FACE" ) );
230 GroupConstructorsLayout->addWidget( RadioButton2, 0, 2 );
231 SMESHGUI_CreatePolyhedralVolumeDlgLayout->addWidget( GroupConstructors, 0, 0 );
233 /***************************************************************/
234 GroupButtons = new QGroupBox( this, "GroupButtons" );
235 GroupButtons->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)7, (QSizePolicy::SizeType)0, 0, 0, GroupButtons->sizePolicy().hasHeightForWidth() ) );
236 GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) );
237 GroupButtons->setTitle( tr( "" ) );
238 GroupButtons->setColumnLayout(0, Qt::Vertical );
239 GroupButtons->layout()->setSpacing( 0 );
240 GroupButtons->layout()->setMargin( 0 );
241 GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
242 GroupButtonsLayout->setAlignment( Qt::AlignTop );
243 GroupButtonsLayout->setSpacing( 6 );
244 GroupButtonsLayout->setMargin( 11 );
245 buttonCancel = new QPushButton( GroupButtons, "cancel" );
246 buttonCancel->setText( tr( "SMESH_BUT_CLOSE" ) );
247 buttonCancel->setAutoDefault( TRUE );
248 GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
249 buttonApply = new QPushButton( GroupButtons, "apply" );
250 buttonApply->setText( tr( "SMESH_BUT_APPLY" ) );
251 buttonApply->setAutoDefault( TRUE );
252 GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
253 QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
254 GroupButtonsLayout->addItem( spacer_9, 0, 2 );
255 buttonOk = new QPushButton( GroupButtons, "ok" );
256 buttonOk->setText( tr( "SMESH_BUT_OK" ) );
257 buttonOk->setAutoDefault( TRUE );
258 buttonOk->setDefault( TRUE );
259 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
260 SMESHGUI_CreatePolyhedralVolumeDlgLayout->addWidget( GroupButtons, 2, 0 );
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 );
273 QFrame* anIds = new QFrame(GroupContent, "anIds");
274 QGridLayout* aLayout = new QGridLayout(anIds, 1, 3);
275 aLayout->setSpacing(6);
276 aLayout->setAutoAdd(false);
278 TextLabelIds = new QLabel( anIds, "TextLabelIds" );
279 TextLabelIds->setText( tr( "SMESH_ID_NODES" ) );
280 TextLabelIds->setFixedWidth(74);
281 aLayout->addWidget( TextLabelIds, 0, 0 );
283 SelectElementsButton = new QPushButton( anIds, "SelectElementsButton" );
284 SelectElementsButton->setText( tr( "" ) );
285 SelectElementsButton->setPixmap( image0 );
286 SelectElementsButton->setToggleButton( FALSE );
287 aLayout->addWidget( SelectElementsButton, 0, 1 );
289 LineEditElements = new QLineEdit( anIds, "LineEditElements" );
290 LineEditElements->setValidator( new SMESHGUI_IdValidator( this, "validator" ));
291 aLayout->addWidget( LineEditElements, 0, 2 );
293 GroupContentLayout->addMultiCellWidget(anIds, 0, 0, 0, 1);
295 myFacesByNodesLabel = new QLabel(GroupContent, "faces by nodes label");
296 myFacesByNodesLabel->setText(tr("FACES_BY_NODES"));
297 GroupContentLayout->addWidget( myFacesByNodesLabel, 1, 0 );
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 );
304 AddButton = new QPushButton(GroupContent, "add");
305 AddButton->setText(tr("SMESH_BUT_ADD"));
306 AddButton->setMaximumWidth(85);
307 GroupContentLayout->addWidget( AddButton, 2, 1 );
309 RemoveButton = new QPushButton(GroupContent, "remove");
310 RemoveButton->setText(tr("SMESH_BUT_REMOVE"));
311 RemoveButton->setMaximumWidth(85);
312 GroupContentLayout->addWidget( RemoveButton, 3, 1 );
314 Preview = new QCheckBox( GroupContent, "Preview" );
315 Preview->setText( tr( "SMESH_POLYEDRE_PREVIEW" ) );
316 GroupContentLayout->addWidget( Preview , 5, 0 );
318 SMESHGUI_CreatePolyhedralVolumeDlgLayout->addWidget( GroupContent, 1, 0 );
320 GroupContent->show();
321 RadioButton1->setChecked( TRUE );
323 mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
328 //=================================================================================
329 // function : ~SMESHGUI_CreatePolyhedralVolumeDlg()
330 // purpose : Destroys the object and frees any allocated resources
331 //=================================================================================
332 SMESHGUI_CreatePolyhedralVolumeDlg::~SMESHGUI_CreatePolyhedralVolumeDlg()
334 // no need to delete child widgets, Qt does it all for us
338 static bool busy = false;
339 //=================================================================================
342 //=================================================================================
343 void SMESHGUI_CreatePolyhedralVolumeDlg::Init()
345 myEditCurrentArgument = LineEditElements;
346 mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
351 mySimulation = new SMESH::TPolySimulation( dynamic_cast<SalomeApp_Application*>( mySMESHGUI->application() ) );
353 /* signals and slots connections */
354 connect(buttonOk, SIGNAL( clicked() ), SLOT( ClickOnOk() ) );
355 connect(buttonCancel, SIGNAL( clicked() ), SLOT( ClickOnCancel() ) ) ;
356 connect(buttonApply, SIGNAL( clicked() ), SLOT(ClickOnApply() ) );
358 connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
359 connect(SelectElementsButton, SIGNAL( clicked() ), SLOT( SetEditCurrentArgument() ) ) ;
360 connect(LineEditElements, SIGNAL( textChanged(const QString&) ), SLOT(onTextChange(const QString&)));
362 connect(myFacesByNodes, SIGNAL(selectionChanged()), this, SLOT(onListSelectionChanged()));
363 connect(AddButton, SIGNAL(clicked()), this, SLOT(onAdd()));
364 connect(RemoveButton, SIGNAL(clicked()), this, SLOT(onRemove()));
366 connect( mySMESHGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
367 connect( mySelectionMgr, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
368 connect( Preview, SIGNAL(toggled(bool)), this, SLOT(ClickOnPreview(bool)));
369 /* to close dialog if study change */
370 connect( mySMESHGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
372 /* Move widget on the botton right corner of main widget */
374 mySMESHGUI->DefineDlgPosition( this, x, y ) ;
376 this->show() ; /* displays Dialog */
378 ConstructorsClicked(0);
379 SelectionIntoArgument();
383 //=================================================================================
384 // function : ConstructorsClicked()
385 // purpose : Radio button management
386 //=================================================================================
387 void SMESHGUI_CreatePolyhedralVolumeDlg::ConstructorsClicked(int constructorId)
389 //disconnect(mySelectionMgr, 0, this, 0);
392 mySelectionMgr->setSelectedObjects( aList );
393 myEditCurrentArgument->clear();
395 buttonApply->setEnabled(false);
396 buttonOk->setEnabled(false);
397 mySimulation->SetVisibility(false);
399 switch(constructorId)
404 myActor->SetPointRepresentation(true);
405 myActor->SetEntityMode(SMESH_Actor::eVolumes);
406 myActor->SetRepresentation(SMESH_Actor::eSurface);
409 SMESH::SetPointRepresentation(true);
410 myViewWindow->SetSelectionMode(NodeSelection);
412 AddButton->setEnabled(false);
413 RemoveButton->setEnabled(false);
414 TextLabelIds->setText( tr( "SMESH_ID_NODES" ) );
415 myFacesByNodesLabel->show();
416 myFacesByNodes->clear();
417 myFacesByNodes->show();
419 RemoveButton->show();
426 myActor->SetPointRepresentation(false);
427 myActor->SetEntityMode(SMESH_Actor::eFaces);
428 myActor->SetEntityMode(SMESH_Actor::eVolumes);
429 myActor->SetRepresentation(SMESH_Actor::eSurface);
431 SMESH::SetPointRepresentation(false);
433 myViewWindow->SetSelectionMode(FaceSelection);
435 TextLabelIds->setText( tr( "SMESH_ID_FACES" ) );
436 myFacesByNodesLabel->hide();
437 myFacesByNodes->hide();
439 RemoveButton->hide();
445 //connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
448 //=================================================================================
449 // function : ClickOnPreview()
451 //=================================================================================
452 void SMESHGUI_CreatePolyhedralVolumeDlg::ClickOnPreview(bool theToggled){
453 Preview->setChecked(theToggled);
457 //=================================================================================
458 // function : ClickOnApply()
460 //=================================================================================
461 void SMESHGUI_CreatePolyhedralVolumeDlg::ClickOnApply()
463 if ( myNbOkElements>0 && !mySMESHGUI->isActiveStudyLocked())
466 if (GetConstructorId() == 0)
468 SMESH::long_array_var anIdsOfNodes = new SMESH::long_array;
469 SMESH::long_array_var aQuantities = new SMESH::long_array;
471 aQuantities->length( myFacesByNodes->count() );
473 TColStd_ListOfInteger aNodesIds;
475 QListBoxItem* anItem;
476 int aNbQuantities = 0;
477 for (anItem = myFacesByNodes->firstItem(); anItem != 0; anItem = anItem->next()) {
478 QStringList anIds = QStringList::split(" ", anItem->text());
479 int aNbNodesInFace = 0;
480 for (QStringList::iterator it = anIds.begin(); it != anIds.end(); ++it, ++aNbNodesInFace)
481 aNodesIds.Append( (*it).toInt() );
483 aQuantities[aNbQuantities++] = aNbNodesInFace;
486 anIdsOfNodes->length(aNodesIds.Extent());
488 int aNbIdsOfNodes = 0;
489 TColStd_ListIteratorOfListOfInteger It;
490 It.Initialize(aNodesIds);
491 for(;It.More();It.Next())
492 anIdsOfNodes[aNbIdsOfNodes++] = It.Value();
495 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
496 QApplication::setOverrideCursor(Qt::waitCursor);
497 aMeshEditor->AddPolyhedralVolume(anIdsOfNodes, aQuantities);
498 QApplication::restoreOverrideCursor();
499 }catch(SALOME::SALOME_Exception& exc){
500 INFOS("Follow exception was cought:\n\t"<<exc.details.text);
501 }catch(std::exception& exc){
502 INFOS("Follow exception was cought:\n\t"<<exc.what());
504 INFOS("Unknown exception was cought !!!");
507 else if (GetConstructorId() == 1)
509 SMESH::long_array_var anIdsOfFaces = new SMESH::long_array;
511 QStringList aListId = QStringList::split( " ", myEditCurrentArgument->text() );
512 anIdsOfFaces->length(aListId.count());
513 for ( int i = 0; i < aListId.count(); i++ )
514 anIdsOfFaces[i] = aListId[i].toInt();
517 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
518 QApplication::setOverrideCursor(Qt::waitCursor);
519 aMeshEditor->AddPolyhedralVolumeByFaces(anIdsOfFaces);
520 QApplication::restoreOverrideCursor();
521 }catch(SALOME::SALOME_Exception& exc){
522 INFOS("Follow exception was cought:\n\t"<<exc.details.text);
523 }catch(std::exception& exc){
524 INFOS("Follow exception was cought:\n\t"<<exc.what());
526 INFOS("Unknown exception was cought !!!");
531 mySelectionMgr->setSelectedObjects( aList );
532 mySimulation->SetVisibility(false);
534 ConstructorsClicked( GetConstructorId() );
539 //=================================================================================
540 // function : ClickOnOk()
542 //=================================================================================
543 void SMESHGUI_CreatePolyhedralVolumeDlg::ClickOnOk()
550 //=================================================================================
551 // function : ClickOnCancel()
553 //=================================================================================
554 void SMESHGUI_CreatePolyhedralVolumeDlg::ClickOnCancel()
556 mySelectionMgr->clearFilters();
558 mySelectionMgr->setSelectedObjects( aList );
559 SMESH::SetPointRepresentation(false);
560 mySimulation->SetVisibility(false);
561 myViewWindow->SetSelectionMode( ActorSelection );
562 disconnect( mySelectionMgr, 0, this, 0 );
563 mySMESHGUI->ResetState() ;
567 //=======================================================================
568 //function : onTextChange
570 //=======================================================================
572 void SMESHGUI_CreatePolyhedralVolumeDlg::onTextChange(const QString& theNewText)
577 mySimulation->SetVisibility(false);
579 SMDS_Mesh* aMesh = 0;
581 aMesh = myActor->GetObject()->GetMesh();
583 if (GetConstructorId() == 0)
586 SALOME_ListIO aList; aList.Append( myActor->getIO() );
587 mySelectionMgr->setSelectedObjects( aList );
589 TColStd_IndexedMapOfInteger selectedIndices;
590 TColStd_MapOfInteger newIndices;
591 mySelector->GetIndex( myActor->getIO(), selectedIndices);
593 QStringList aListId = QStringList::split( " ", theNewText, false);
594 for ( int i = 0; i < aListId.count(); i++ ) {
595 const SMDS_MeshNode * n = aMesh->FindNode( aListId[ i ].toInt() );
597 if (selectedIndices.Add(n->GetID()))
598 newIndices.Add(n->GetID());
603 if (newIndices.Extent() > 0){
604 mySelector->AddOrRemoveIndex( myActor->getIO(), newIndices, true );
605 myViewWindow->highlight( myActor->getIO(), true, true );
608 if ( myNbOkElements>0 && aListId.count()>=3)
609 AddButton->setEnabled(true);
611 AddButton->setEnabled(false);
615 } else if (GetConstructorId() == 1)
618 buttonOk->setEnabled( false );
619 buttonApply->setEnabled( false );
621 // check entered ids of faces and hilight them
624 SALOME_ListIO aList; aList.Append( myActor->getIO() );
625 mySelectionMgr->setSelectedObjects( aList );
627 TColStd_IndexedMapOfInteger selectedIndices;
628 TColStd_MapOfInteger newIndices;
629 mySelector->GetIndex( myActor->getIO(), selectedIndices);
631 aListId = QStringList::split( " ", theNewText, false);
633 for ( int i = 0; i < aListId.count(); i++ ) {
634 const SMDS_MeshElement * e = aMesh->FindElement( aListId[ i ].toInt() );
636 if (selectedIndices.Add(e->GetID()))
637 newIndices.Add(e->GetID());
642 if (newIndices.Extent() > 0){
643 mySelector->AddOrRemoveIndex( myActor->getIO(), newIndices, true );
644 myViewWindow->highlight( myActor->getIO(), true, true );
647 if ( myNbOkElements ) {
648 if (aListId.count()>1){
649 buttonOk->setEnabled( true );
650 buttonApply->setEnabled( true );
653 buttonOk->setEnabled( false );
654 buttonApply->setEnabled( false );
663 //=================================================================================
664 // function : SelectionIntoArgument()
665 // purpose : Called when selection as changed or other case
666 //=================================================================================
667 void SMESHGUI_CreatePolyhedralVolumeDlg::SelectionIntoArgument()
673 if (GetConstructorId() == 1 || myFacesByNodes->count() <= 1)
676 AddButton->setEnabled(false);
677 buttonOk->setEnabled( false );
678 buttonApply->setEnabled( false );
684 myEditCurrentArgument->setText( "" );
686 if ( !GroupButtons->isEnabled() ) // inactive
689 mySimulation->SetVisibility(false);
693 SALOME_ListIO selected;
694 mySelectionMgr->selectedObjects( selected );
695 int nbSel = selected.Extent();
700 myMesh = SMESH::GetMeshByIO( selected.First() );
701 if ( myMesh->_is_nil() )
704 myActor = SMESH::FindActorByObject(myMesh);
708 // get selected nodes/faces
709 QString aString = "";
710 switch(GetConstructorId()){
712 int anbNodes = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aString);
714 AddButton->setEnabled(true);
715 else if (anbNodes < 3){
716 AddButton->setEnabled(false);
719 myEditCurrentArgument->setText( aString );
724 // get selected faces
725 int aNbFaces = SMESH::GetNameOfSelectedElements(mySelector, myActor->getIO(), aString);
727 buttonOk->setEnabled( false );
728 buttonApply->setEnabled( false );
730 buttonOk->setEnabled( true );
731 buttonApply->setEnabled( true );
734 myEditCurrentArgument->setText( aString );
747 //=======================================================================
748 //function : displaySimulation
750 //=======================================================================
751 void SMESHGUI_CreatePolyhedralVolumeDlg::displaySimulation()
753 if ( (myNbOkElements || AddButton->isEnabled()) && GroupButtons->isEnabled() && myActor)
755 SMESH::TPolySimulation::TVTKIds aVTKIds;
756 vtkIdType aType = VTK_CONVEX_POINT_SET ;
757 if (GetConstructorId() == 0){
758 if(!Preview->isChecked()) myActor->SetEntityMode(SMESH_Actor::eFaces);
759 else myActor->SetEntityMode(SMESH_Actor::eVolumes);
760 if (!AddButton->isEnabled()){
761 QListBoxItem* anItem;
762 mySimulation->ResetGrid(true);
763 for (anItem = myFacesByNodes->firstItem(); anItem != 0; anItem = anItem->next()) {
764 QStringList anIds = QStringList::split(" ", anItem->text());
765 SMESH::TPolySimulation::TVTKIds aVTKIds_faces;
766 for (QStringList::iterator it = anIds.begin(); it != anIds.end(); ++it){
767 vtkIdType aId = myActor->GetObject()->GetNodeVTKId( (*it).toInt() ) ;
768 aVTKIds.push_back(aId);
769 aVTKIds_faces.push_back(aId);
771 if(!Preview->isChecked()){
773 mySimulation->SetPosition(myActor, aType, aVTKIds_faces,false);
776 if(myFacesByNodes->count() == 0){
777 mySimulation->SetVisibility(false);
779 mySimulation->SetVisibility(true);
781 if(Preview->isChecked()){
782 mySimulation->SetPosition(myActor, aType, aVTKIds);
785 // add ids from edit line
786 QStringList anEditIds = QStringList::split( " ", myEditCurrentArgument->text(), false);
787 myActor->SetEntityMode(SMESH_Actor::eFaces);
788 for ( int i = 0; i < anEditIds.count(); i++ )
789 aVTKIds.push_back( myActor->GetObject()->GetNodeVTKId( anEditIds[ i ].toInt() ));
791 mySimulation->SetPosition(myActor, aType, aVTKIds);
793 }else if(GetConstructorId() == 1){
794 SMDS_Mesh* aMesh = 0;
796 aMesh = myActor->GetObject()->GetMesh();
797 if (Preview->isChecked())
798 myActor->SetEntityMode(SMESH_Actor::eVolumes);
800 myActor->SetEntityMode(SMESH_Actor::eFaces);
803 QStringList aListId = QStringList::split( " ", myEditCurrentArgument->text(), false);
804 for ( int i = 0; i < aListId.count(); i++ )
806 const SMDS_MeshElement * anElem = aMesh->FindElement( aListId[ i ].toInt() );
810 SMDS_ElemIteratorPtr anIter = anElem->nodesIterator();
811 SMESH::TPolySimulation::TVTKIds aVTKIds_faces;
812 while( anIter->more() )
813 if ( const SMDS_MeshNode* aNode = (SMDS_MeshNode*)anIter->next() ){
814 vtkIdType aId = myActor->GetObject()->GetNodeVTKId( aNode->GetID() ) ;
815 aVTKIds.push_back(aId);
816 aVTKIds_faces.push_back(aId);
818 if(!Preview->isChecked()){
820 mySimulation->SetPosition(myActor, aType, aVTKIds_faces);
823 if(Preview->isChecked())
824 mySimulation->SetPosition(myActor, aType, aVTKIds);
831 //=================================================================================
832 // function : SetEditCurrentArgument()
834 //=================================================================================
835 void SMESHGUI_CreatePolyhedralVolumeDlg::SetEditCurrentArgument()
837 QPushButton* send = (QPushButton*)sender();
838 if(send == SelectElementsButton) {
839 LineEditElements->setFocus() ;
840 myEditCurrentArgument = LineEditElements;
842 SelectionIntoArgument();
845 //=================================================================================
846 // function : DeactivateActiveDialog()
848 //=================================================================================
849 void SMESHGUI_CreatePolyhedralVolumeDlg::DeactivateActiveDialog()
851 if ( GroupConstructors->isEnabled() ) {
852 GroupConstructors->setEnabled(false) ;
853 GroupContent->setEnabled(false) ;
854 GroupButtons->setEnabled(false) ;
855 mySimulation->SetVisibility(false);
856 mySMESHGUI->ResetState() ;
857 mySMESHGUI->SetActiveDialogBox(0) ;
862 //=================================================================================
863 // function : ActivateThisDialog()
865 //=================================================================================
866 void SMESHGUI_CreatePolyhedralVolumeDlg::ActivateThisDialog()
868 /* Emit a signal to deactivate the active dialog */
869 mySMESHGUI->EmitSignalDeactivateDialog() ;
870 GroupConstructors->setEnabled(true) ;
871 GroupContent->setEnabled(true) ;
872 GroupButtons->setEnabled(true) ;
874 mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
876 myViewWindow->SetSelectionMode( FaceSelection );
877 SelectionIntoArgument();
881 //=================================================================================
882 // function : enterEvent()
884 //=================================================================================
885 void SMESHGUI_CreatePolyhedralVolumeDlg::enterEvent(QEvent* e)
887 if ( GroupConstructors->isEnabled() )
889 ActivateThisDialog() ;
893 //=================================================================================
894 // function : closeEvent()
896 //=================================================================================
897 void SMESHGUI_CreatePolyhedralVolumeDlg::closeEvent( QCloseEvent* e )
899 /* same than click on cancel button */
900 this->ClickOnCancel() ;
904 //=======================================================================
905 //function : hideEvent
906 //purpose : caused by ESC key
907 //=======================================================================
909 void SMESHGUI_CreatePolyhedralVolumeDlg::hideEvent ( QHideEvent * e )
911 if ( !isMinimized() )
916 //=================================================================================
917 // function : GetConstructorId()
919 //=================================================================================
920 int SMESHGUI_CreatePolyhedralVolumeDlg::GetConstructorId()
922 if ( GroupConstructors != NULL && GroupConstructors->selected() != NULL )
923 return GroupConstructors->id( GroupConstructors->selected() );
927 //=================================================================================
928 // function : onAdd()
930 //=================================================================================
931 void SMESHGUI_CreatePolyhedralVolumeDlg::onAdd()
933 SALOME_ListIO selected;
934 mySelectionMgr->selectedObjects( selected );
935 int aNbSel = selected.Extent();
936 if (aNbSel == 0 || !myActor || myMesh->_is_nil()) return;
940 if ( !(myEditCurrentArgument->text().isEmpty()) )
942 myFacesByNodes->insertItem(myEditCurrentArgument->text());
943 //myFacesByNodes->setSelected(myFacesByNodes->count() - 1, true);
945 myEditCurrentArgument->clear();
946 AddButton->setEnabled(false);
947 buttonOk->setEnabled( true );
948 if(myFacesByNodes->count()>1) buttonApply->setEnabled( true );
951 onListSelectionChanged();
955 //=================================================================================
956 // function : onRemove()
958 //=================================================================================
959 void SMESHGUI_CreatePolyhedralVolumeDlg::onRemove()
962 for (int i = myFacesByNodes->count(); i > 0; i--) {
963 if (myFacesByNodes->isSelected(i-1)) {
964 myFacesByNodes->removeItem(i-1);
968 if (myFacesByNodes->count() < 1){
969 RemoveButton->setEnabled(false);
970 buttonOk->setEnabled( false );
971 buttonApply->setEnabled( false );
973 else if (myFacesByNodes->count() == 1){
974 buttonOk->setEnabled( false );
975 buttonApply->setEnabled( false );
981 //=================================================================================
982 // function : onListSelectionChanged()
983 // purpose : Called when selection in element list is changed
984 //=================================================================================
985 void SMESHGUI_CreatePolyhedralVolumeDlg::onListSelectionChanged()
987 if (busy || !myActor) return;
989 bool isSelected=false;
991 mySelectionMgr->setSelectedObjects( aList );
992 TColStd_MapOfInteger aIndexes;
993 QListBoxItem* anItem;
994 for (anItem = myFacesByNodes->firstItem(); anItem != 0; anItem = anItem->next()) {
995 if (anItem->isSelected()) {
997 QStringList anIds = QStringList::split(" ", anItem->text());
998 for (QStringList::iterator it = anIds.begin(); it != anIds.end(); ++it)
999 aIndexes.Add((*it).toInt());
1002 if(isSelected) RemoveButton->setEnabled(true);
1003 else RemoveButton->setEnabled(false);
1004 mySelector->AddOrRemoveIndex(myActor->getIO(), aIndexes, true );
1005 myViewWindow->highlight( myActor->getIO(), true, true );
1006 mySelectionMgr->clearFilters();
1007 aList.Append( myActor->getIO() );
1008 mySelectionMgr->setSelectedObjects( aList );