1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // SMESH SMESHGUI : GUI for SMESH component
23 // File : SMESHGUI_CreatePolyhedralVolumeDlg.cxx
24 // Author : Michael ZORIN
28 #include "SMESHGUI_CreatePolyhedralVolumeDlg.h"
31 #include "SMESHGUI_Utils.h"
32 #include "SMESHGUI_VTKUtils.h"
33 #include "SMESHGUI_MeshUtils.h"
34 #include "SMESHGUI_IdValidator.h"
35 #include "SMESH_ActorUtils.h"
36 #include "SMESHGUI_SpinBox.h"
37 #include "SMESH_Actor.h"
38 #include "SMESH_TypeFilter.hxx"
39 #include "SMDS_Mesh.hxx"
41 #include "SUIT_ResourceMgr.h"
42 #include "SUIT_Session.h"
43 #include "SUIT_MessageBox.h"
45 #include "SalomeApp_Application.h"
46 #include "SalomeApp_Study.h"
47 #include "SUIT_Desktop.h"
48 #include "SUIT_MessageBox.h"
49 #include "LightApp_Application.h"
50 #include "LightApp_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>
67 #include <vtkProperty.h>
70 #include <qapplication.h>
71 #include <qbuttongroup.h>
72 #include <qgroupbox.h>
74 #include <qlineedit.h>
75 #include <qpushbutton.h>
76 #include <qradiobutton.h>
77 #include <qcheckbox.h>
84 #include "SALOMEconfig.h"
85 #include CORBA_SERVER_HEADER(SMESH_Group)
86 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
92 class TPolySimulation{
93 SVTK_ViewWindow* myViewWindow;
95 SALOME_Actor *myPreviewActor;
96 vtkDataSetMapper* myMapper;
97 vtkUnstructuredGrid* myGrid;
101 TPolySimulation(SalomeApp_Application* app)
103 SUIT_ViewManager* mgr = app->activeViewManager();
104 myViewWindow = mgr ? dynamic_cast<SVTK_ViewWindow*>( mgr->getActiveView() ) : NULL;
106 myGrid = vtkUnstructuredGrid::New();
108 // Create and display actor
109 myMapper = vtkDataSetMapper::New();
110 myMapper->SetInput( myGrid );
112 myPreviewActor = SALOME_Actor::New();
113 myPreviewActor->PickableOff();
114 myPreviewActor->VisibilityOff();
115 myPreviewActor->SetMapper( myMapper );
116 myPreviewActor->SetRepresentation( 3 );
118 vtkFloatingPointType anRGB[3];
119 vtkProperty* aProp = vtkProperty::New();
120 GetColor( "SMESH", "selection_element_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 170, 255 ) );
121 aProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
122 myPreviewActor->SetProperty( aProp );
123 vtkFloatingPointType aFactor,aUnits;
124 myPreviewActor->SetResolveCoincidentTopology(true);
125 myPreviewActor->GetPolygonOffsetParameters(aFactor,aUnits);
126 myPreviewActor->SetPolygonOffsetParameters(aFactor,0.2*aUnits);
129 myViewWindow->AddActor( myPreviewActor );
134 typedef std::vector<vtkIdType> TVTKIds;
135 void SetPosition(SMESH_Actor* theActor,
137 const TVTKIds& theIds,
140 vtkUnstructuredGrid *aGrid = theActor->GetUnstructuredGrid();
141 myGrid->SetPoints(aGrid->GetPoints());
145 vtkIdList *anIds = vtkIdList::New();
147 for (int i = 0, iEnd = theIds.size(); i < iEnd; i++)
148 anIds->InsertId(i,theIds[i]);
150 myGrid->InsertNextCell(theType,anIds);
151 if(theIds.size()!=0){
152 myGrid->InsertNextCell(theType,anIds);
162 void ResetGrid(bool theReset=true){
163 if (theReset) myGrid->Reset();
166 void SetVisibility(bool theVisibility){
167 myPreviewActor->SetVisibility(theVisibility);
168 RepaintCurrentView();
174 myViewWindow->RemoveActor(myPreviewActor);
176 myPreviewActor->Delete();
178 myMapper->RemoveAllInputs();
187 //=================================================================================
188 // class : SMESHGUI_CreatePolyhedralVolumeDlgDlg()
190 //=================================================================================
191 SMESHGUI_CreatePolyhedralVolumeDlg::SMESHGUI_CreatePolyhedralVolumeDlg( SMESHGUI* theModule, const char* name,
192 bool modal, WFlags fl )
193 : QDialog( SMESH::GetDesktop( theModule ), name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | Qt::WDestructiveClose),
194 mySMESHGUI( theModule ),
195 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
197 QPixmap image0( SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap( "SMESH",tr("ICON_SELECT")));
200 setName( "SMESHGUI_CreatePolyhedralVolumeDlg" );
202 setCaption( tr( "SMESH_CREATE_POLYHEDRAL_VOLUME_TITLE" ) );
203 setSizeGripEnabled( TRUE );
204 SMESHGUI_CreatePolyhedralVolumeDlgLayout = new QGridLayout( this );
205 SMESHGUI_CreatePolyhedralVolumeDlgLayout->setSpacing( 6 );
206 SMESHGUI_CreatePolyhedralVolumeDlgLayout->setMargin( 11 );
208 /***************************************************************/
209 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
210 GroupConstructors->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)5, (QSizePolicy::SizeType)0, 0, 0, GroupConstructors->sizePolicy().hasHeightForWidth() ) );
211 GroupConstructors->setTitle( tr( "SMESH_ELEMENTS_TYPE" ) );
212 GroupConstructors->setExclusive( TRUE );
213 GroupConstructors->setColumnLayout(0, Qt::Vertical );
214 GroupConstructors->layout()->setSpacing( 0 );
215 GroupConstructors->layout()->setMargin( 0 );
216 GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
217 GroupConstructorsLayout->setAlignment( Qt::AlignTop );
218 GroupConstructorsLayout->setSpacing( 6 );
219 GroupConstructorsLayout->setMargin( 11 );
220 RadioButton1= new QRadioButton( GroupConstructors, "RadioButton1" );
221 RadioButton1->setText( tr( "MESH_NODE" ) );
222 GroupConstructorsLayout->addWidget( RadioButton1, 0, 0 );
223 RadioButton2= new QRadioButton( GroupConstructors, "RadioButton2" );
224 RadioButton2->setText( tr( "SMESH_FACE" ) );
225 GroupConstructorsLayout->addWidget( RadioButton2, 0, 2 );
226 SMESHGUI_CreatePolyhedralVolumeDlgLayout->addWidget( GroupConstructors, 0, 0 );
228 /***************************************************************/
229 GroupButtons = new QGroupBox( this, "GroupButtons" );
230 GroupButtons->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)7, (QSizePolicy::SizeType)0, 0, 0, GroupButtons->sizePolicy().hasHeightForWidth() ) );
231 GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) );
232 GroupButtons->setTitle( tr( "" ) );
233 GroupButtons->setColumnLayout(0, Qt::Vertical );
234 GroupButtons->layout()->setSpacing( 0 );
235 GroupButtons->layout()->setMargin( 0 );
236 GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
237 GroupButtonsLayout->setAlignment( Qt::AlignTop );
238 GroupButtonsLayout->setSpacing( 6 );
239 GroupButtonsLayout->setMargin( 11 );
240 buttonCancel = new QPushButton( GroupButtons, "cancel" );
241 buttonCancel->setText( tr( "SMESH_BUT_CLOSE" ) );
242 buttonCancel->setAutoDefault( TRUE );
243 GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
244 buttonApply = new QPushButton( GroupButtons, "apply" );
245 buttonApply->setText( tr( "SMESH_BUT_APPLY" ) );
246 buttonApply->setAutoDefault( TRUE );
247 GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
248 QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
249 GroupButtonsLayout->addItem( spacer_9, 0, 2 );
250 buttonOk = new QPushButton( GroupButtons, "ok" );
251 buttonOk->setText( tr( "SMESH_BUT_APPLY_AND_CLOSE" ) );
252 buttonOk->setAutoDefault( TRUE );
253 buttonOk->setDefault( TRUE );
254 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
255 buttonHelp = new QPushButton(GroupButtons, "buttonHelp");
256 buttonHelp->setText(tr("SMESH_BUT_HELP" ));
257 buttonHelp->setAutoDefault(TRUE);
258 GroupButtonsLayout->addWidget(buttonHelp, 0, 4);
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 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
320 SMESHGUI_CreatePolyhedralVolumeDlgLayout->addWidget( GroupContent, 1, 0 );
322 GroupContent->show();
323 RadioButton1->setChecked( TRUE );
325 mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
327 myHelpFileName = "adding_nodes_and_elements_page.html#adding_polyhedrons_anchor";
332 //=================================================================================
333 // function : ~SMESHGUI_CreatePolyhedralVolumeDlg()
334 // purpose : Destroys the object and frees any allocated resources
335 //=================================================================================
336 SMESHGUI_CreatePolyhedralVolumeDlg::~SMESHGUI_CreatePolyhedralVolumeDlg()
338 // no need to delete child widgets, Qt does it all for us
342 static bool busy = false;
343 //=================================================================================
346 //=================================================================================
347 void SMESHGUI_CreatePolyhedralVolumeDlg::Init()
349 myEditCurrentArgument = LineEditElements;
350 mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
355 mySimulation = new SMESH::TPolySimulation( dynamic_cast<SalomeApp_Application*>( mySMESHGUI->application() ) );
357 /* signals and slots connections */
358 connect(buttonOk, SIGNAL( clicked() ), SLOT( ClickOnOk() ) );
359 connect(buttonCancel, SIGNAL( clicked() ), SLOT( ClickOnCancel() ) ) ;
360 connect(buttonApply, SIGNAL( clicked() ), SLOT(ClickOnApply() ) );
361 connect(buttonHelp, SIGNAL(clicked()), SLOT(ClickOnHelp() ) );
363 connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
364 connect(SelectElementsButton, SIGNAL( clicked() ), SLOT( SetEditCurrentArgument() ) ) ;
365 connect(LineEditElements, SIGNAL( textChanged(const QString&) ), SLOT(onTextChange(const QString&)));
367 connect(myFacesByNodes, SIGNAL(selectionChanged()), this, SLOT(onListSelectionChanged()));
368 connect(AddButton, SIGNAL(clicked()), this, SLOT(onAdd()));
369 connect(RemoveButton, SIGNAL(clicked()), this, SLOT(onRemove()));
371 connect( mySMESHGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
372 connect( mySelectionMgr, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
373 connect( Preview, SIGNAL(toggled(bool)), this, SLOT(ClickOnPreview(bool)));
374 /* to close dialog if study change */
375 connect( mySMESHGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
377 this->show() ; /* displays Dialog */
379 ConstructorsClicked(0);
380 SelectionIntoArgument();
384 //=================================================================================
385 // function : ConstructorsClicked()
386 // purpose : Radio button management
387 //=================================================================================
388 void SMESHGUI_CreatePolyhedralVolumeDlg::ConstructorsClicked(int constructorId)
390 //disconnect(mySelectionMgr, 0, this, 0);
393 mySelectionMgr->selectedObjects( io );
395 mySelectionMgr->setSelectedObjects( aList );
396 myEditCurrentArgument->clear();
398 buttonApply->setEnabled(false);
399 buttonOk->setEnabled(false);
400 mySimulation->SetVisibility(false);
402 switch(constructorId)
407 myActor->SetPointRepresentation(true);
410 SMESH::SetPointRepresentation(true);
411 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
412 aViewWindow->SetSelectionMode(NodeSelection);
414 AddButton->setEnabled(false);
415 RemoveButton->setEnabled(false);
416 TextLabelIds->setText( tr( "SMESH_ID_NODES" ) );
417 myFacesByNodesLabel->show();
418 myFacesByNodes->clear();
419 myFacesByNodes->show();
421 RemoveButton->show();
428 myActor->SetPointRepresentation(false);
430 SMESH::SetPointRepresentation(false);
432 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
433 aViewWindow->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()));
446 mySelectionMgr->setSelectedObjects( io );
449 //=================================================================================
450 // function : ClickOnPreview()
452 //=================================================================================
453 void SMESHGUI_CreatePolyhedralVolumeDlg::ClickOnPreview(bool theToggled){
454 Preview->setChecked(theToggled);
458 //=================================================================================
459 // function : ClickOnApply()
461 //=================================================================================
462 void SMESHGUI_CreatePolyhedralVolumeDlg::ClickOnApply()
464 if ( myNbOkElements>0 && !mySMESHGUI->isActiveStudyLocked())
466 if(checkEditLine(false) == -1) {return;}
468 if (GetConstructorId() == 0)
470 SMESH::long_array_var anIdsOfNodes = new SMESH::long_array;
471 SMESH::long_array_var aQuantities = new SMESH::long_array;
473 aQuantities->length( myFacesByNodes->count() );
475 TColStd_ListOfInteger aNodesIds;
477 QListBoxItem* anItem;
478 int aNbQuantities = 0;
479 for (anItem = myFacesByNodes->firstItem(); anItem != 0; anItem = anItem->next()) {
480 QStringList anIds = QStringList::split(" ", anItem->text());
481 int aNbNodesInFace = 0;
482 for (QStringList::iterator it = anIds.begin(); it != anIds.end(); ++it, ++aNbNodesInFace)
483 aNodesIds.Append( (*it).toInt() );
485 aQuantities[aNbQuantities++] = aNbNodesInFace;
488 anIdsOfNodes->length(aNodesIds.Extent());
490 int aNbIdsOfNodes = 0;
491 TColStd_ListIteratorOfListOfInteger It;
492 It.Initialize(aNodesIds);
493 for(;It.More();It.Next())
494 anIdsOfNodes[aNbIdsOfNodes++] = It.Value();
497 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
498 QApplication::setOverrideCursor(Qt::waitCursor);
499 aMeshEditor->AddPolyhedralVolume(anIdsOfNodes, aQuantities);
500 QApplication::restoreOverrideCursor();
501 }catch(SALOME::SALOME_Exception& exc){
502 INFOS("Follow exception was cought:\n\t"<<exc.details.text);
503 }catch(std::exception& exc){
504 INFOS("Follow exception was cought:\n\t"<<exc.what());
506 INFOS("Unknown exception was cought !!!");
509 else if (GetConstructorId() == 1)
511 SMESH::long_array_var anIdsOfFaces = new SMESH::long_array;
513 QStringList aListId = QStringList::split( " ", myEditCurrentArgument->text() );
514 anIdsOfFaces->length(aListId.count());
515 for ( int i = 0; i < aListId.count(); i++ )
516 anIdsOfFaces[i] = aListId[i].toInt();
519 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
520 QApplication::setOverrideCursor(Qt::waitCursor);
521 aMeshEditor->AddPolyhedralVolumeByFaces(anIdsOfFaces);
522 QApplication::restoreOverrideCursor();
523 }catch(SALOME::SALOME_Exception& exc){
524 INFOS("Follow exception was cought:\n\t"<<exc.details.text);
525 }catch(std::exception& exc){
526 INFOS("Follow exception was cought:\n\t"<<exc.what());
528 INFOS("Unknown exception was cought !!!");
532 //SALOME_ListIO aList;
533 //mySelectionMgr->setSelectedObjects( aList );
536 unsigned int anEntityMode = myActor->GetEntityMode();
537 myActor->SetEntityMode(SMESH_Actor::eVolumes | anEntityMode);
539 //ConstructorsClicked( GetConstructorId() );
544 //=================================================================================
545 // function : ClickOnOk()
547 //=================================================================================
548 void SMESHGUI_CreatePolyhedralVolumeDlg::ClickOnOk()
550 if(checkEditLine(false) == -1) {return;}
556 //=================================================================================
557 // function : ClickOnCancel()
559 //=================================================================================
560 void SMESHGUI_CreatePolyhedralVolumeDlg::ClickOnCancel()
562 mySelectionMgr->clearFilters();
563 //SALOME_ListIO aList;
564 //mySelectionMgr->setSelectedObjects( aList );
565 SMESH::SetPointRepresentation(false);
566 mySimulation->SetVisibility(false);
567 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
568 aViewWindow->SetSelectionMode( ActorSelection );
569 disconnect( mySelectionMgr, 0, this, 0 );
570 mySMESHGUI->ResetState() ;
574 //=================================================================================
575 // function : ClickOnHelp()
577 //=================================================================================
578 void SMESHGUI_CreatePolyhedralVolumeDlg::ClickOnHelp()
580 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
582 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
586 platform = "winapplication";
588 platform = "application";
590 SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
591 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
592 arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(myHelpFileName),
593 QObject::tr("BUT_OK"));
597 //=======================================================================
598 //function : onTextChange
600 //=======================================================================
602 void SMESHGUI_CreatePolyhedralVolumeDlg::onTextChange(const QString& theNewText)
605 if (checkEditLine() == -1) return;
608 mySimulation->SetVisibility(false);
610 SMDS_Mesh* aMesh = 0;
612 aMesh = myActor->GetObject()->GetMesh();
614 if (GetConstructorId() == 0)
617 TColStd_MapOfInteger newIndices;
619 QStringList aListId = QStringList::split( " ", theNewText, false);
620 for ( int i = 0; i < aListId.count(); i++ ) {
621 const SMDS_MeshNode * n = aMesh->FindNode( aListId[ i ].toInt() );
623 newIndices.Add(n->GetID());
628 mySelector->AddOrRemoveIndex( myActor->getIO(), newIndices, false );
630 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
631 aViewWindow->highlight( myActor->getIO(), true, true );
633 if ( myNbOkElements>0 && aListId.count()>=3)
634 AddButton->setEnabled(true);
636 AddButton->setEnabled(false);
640 } else if (GetConstructorId() == 1)
643 buttonOk->setEnabled( false );
644 buttonApply->setEnabled( false );
646 // check entered ids of faces and hilight them
649 TColStd_MapOfInteger newIndices;
651 aListId = QStringList::split( " ", theNewText, false);
653 for ( int i = 0; i < aListId.count(); i++ ) {
654 const SMDS_MeshElement * e = aMesh->FindElement( aListId[ i ].toInt() );
656 newIndices.Add(e->GetID());
661 mySelector->AddOrRemoveIndex( myActor->getIO(), newIndices, false );
662 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
663 aViewWindow->highlight( myActor->getIO(), true, true );
665 if ( myNbOkElements ) {
666 if (aListId.count()>1){
667 buttonOk->setEnabled( true );
668 buttonApply->setEnabled( true );
671 buttonOk->setEnabled( false );
672 buttonApply->setEnabled( false );
674 if(aListId.count()>1)
682 //=================================================================================
683 // function : SelectionIntoArgument()
684 // purpose : Called when selection as changed or other case
685 //=================================================================================
686 void SMESHGUI_CreatePolyhedralVolumeDlg::SelectionIntoArgument()
692 if (GetConstructorId() == 1 || myFacesByNodes->count() <= 1)
695 AddButton->setEnabled(false);
696 buttonOk->setEnabled( false );
697 buttonApply->setEnabled( false );
703 myEditCurrentArgument->setText( "" );
705 if ( !GroupButtons->isEnabled() ) // inactive
708 mySimulation->SetVisibility(false);
712 SALOME_ListIO selected;
713 mySelectionMgr->selectedObjects( selected );
714 int nbSel = selected.Extent();
719 myMesh = SMESH::GetMeshByIO( selected.First() );
720 if ( myMesh->_is_nil() )
723 myActor = SMESH::FindActorByObject(myMesh);
727 // get selected nodes/faces
728 QString aString = "";
729 int anbNodes=0,aNbFaces=0;
730 switch(GetConstructorId()){
732 anbNodes = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aString);
734 AddButton->setEnabled(true);
735 else if (anbNodes < 3){
736 AddButton->setEnabled(false);
739 myEditCurrentArgument->setText( aString );
740 if (checkEditLine() == -1) {busy = false;return;}
745 // get selected faces
746 aNbFaces = SMESH::GetNameOfSelectedElements(mySelector, myActor->getIO(), aString);
748 buttonOk->setEnabled( false );
749 buttonApply->setEnabled( false );
751 buttonOk->setEnabled( true );
752 buttonApply->setEnabled( true );
755 myEditCurrentArgument->setText( aString );
756 if (checkEditLine() == -1) {busy = false;return;}
765 if(anbNodes>2 || aNbFaces>1)
769 /*\brief int SMESHGUI_CreatePolyhedralVolumeDlg::checkEditLine()
770 * Checking of indices in edit line.
771 * If incorecct indices in edit line warning message appear and myEditCurrentArgument remove last index.
772 * \retval 1 - if all ok(or no indices in edit line), -1 - if there are incorrect indices.
774 int SMESHGUI_CreatePolyhedralVolumeDlg::checkEditLine(bool checkLast)
776 QString aString = "";
777 SMDS_Mesh* aMesh = 0;
779 if(myMesh->_is_nil()) return 1;
781 myActor = SMESH::FindActorByObject(myMesh);
786 aMesh = myActor->GetObject()->GetMesh();
788 // checking for nodes
789 if (checkLast && myEditCurrentArgument->text().right(1) != QString(" ") ) return 1;
790 QStringList aListId = QStringList::split( " ", myEditCurrentArgument->text() );
791 for ( int i = 0; i < aListId.count(); i++ ){
792 switch (GetConstructorId()){
794 const SMDS_MeshNode * aNode = aMesh->FindNode( aListId[ i ].toInt() );
796 std::string aWarning;
797 aWarning = "The incorrect indices of nodes!";
798 SUIT_MessageBox::warn1(SMESHGUI::desktop(),
799 QObject::tr("SMESH_POLYEDRE_CREATE_ERROR"),
800 QObject::tr(aWarning.c_str()),
801 QObject::tr("SMESH_BUT_OK"));
803 myEditCurrentArgument->clear();
804 myEditCurrentArgument->setText( aString );
811 bool aElemIsOK = true;
812 const SMDS_MeshElement * aElem = aMesh->FindElement( aListId[ i ].toInt() );
819 SMDSAbs_ElementType aType = aMesh->GetElementType( aElem->GetID(),true );
820 if (aType != SMDSAbs_Face){
825 std::string aWarning;
826 aWarning = "The incorrect indices of faces!";
827 SUIT_MessageBox::warn1(SMESHGUI::desktop(),
828 QObject::tr("SMESH_POLYEDRE_CREATE_ERROR"),
829 QObject::tr(aWarning.c_str()),
830 QObject::tr("SMESH_BUT_OK"));
832 myEditCurrentArgument->clear();
833 myEditCurrentArgument->setText( aString );
839 aString += aListId[ i ] + " ";
845 //=======================================================================
846 //function : displaySimulation
848 //=======================================================================
849 void SMESHGUI_CreatePolyhedralVolumeDlg::displaySimulation()
851 if ( (myNbOkElements || AddButton->isEnabled()) && GroupButtons->isEnabled() && myActor)
853 SMESH::TPolySimulation::TVTKIds aVTKIds;
854 vtkIdType aType = VTK_CONVEX_POINT_SET ;
855 SMDS_Mesh* aMesh = 0;
857 aMesh = myActor->GetObject()->GetMesh();
859 if (GetConstructorId() == 0 && aMesh){
860 if (!AddButton->isEnabled()){
861 QListBoxItem* anItem;
862 mySimulation->ResetGrid(true);
863 for (anItem = myFacesByNodes->firstItem(); anItem != 0; anItem = anItem->next()) {
864 QStringList anIds = QStringList::split(" ", anItem->text());
865 SMESH::TPolySimulation::TVTKIds aVTKIds_faces;
866 for (QStringList::iterator it = anIds.begin(); it != anIds.end(); ++it){
867 const SMDS_MeshNode * aNode = aMesh->FindNode( (*it).toInt() );
868 if (!aNode) continue;
869 vtkIdType aId = myActor->GetObject()->GetNodeVTKId( (*it).toInt() ) ;
870 aVTKIds.push_back(aId);
871 aVTKIds_faces.push_back(aId);
873 if(!Preview->isChecked()){
875 mySimulation->SetPosition(myActor, aType, aVTKIds_faces,false);
878 if(myFacesByNodes->count() == 0){
879 mySimulation->SetVisibility(false);
881 mySimulation->SetVisibility(true);
883 if(Preview->isChecked()){
884 mySimulation->SetPosition(myActor, aType, aVTKIds);
887 // add ids from edit line
888 QStringList anEditIds = QStringList::split( " ", myEditCurrentArgument->text(), false);
889 for ( int i = 0; i < anEditIds.count(); i++ )
890 aVTKIds.push_back( myActor->GetObject()->GetNodeVTKId( anEditIds[ i ].toInt() ));
892 mySimulation->SetPosition(myActor, aType, aVTKIds);
894 }else if(GetConstructorId() == 1 && aMesh){
895 QStringList aListId = QStringList::split( " ", myEditCurrentArgument->text(), false);
896 for ( int i = 0; i < aListId.count(); i++ )
898 const SMDS_MeshElement * anElem = aMesh->FindElement( aListId[ i ].toInt() );
899 if ( !anElem ) continue;
900 SMDSAbs_ElementType aFaceType = aMesh->GetElementType( anElem->GetID(),true );
901 if (aFaceType != SMDSAbs_Face) continue;
903 SMDS_ElemIteratorPtr anIter = anElem->nodesIterator();
904 SMESH::TPolySimulation::TVTKIds aVTKIds_faces;
905 while( anIter->more() )
906 if ( const SMDS_MeshNode* aNode = (SMDS_MeshNode*)anIter->next() ){
907 vtkIdType aId = myActor->GetObject()->GetNodeVTKId( aNode->GetID() ) ;
908 aVTKIds.push_back(aId);
909 aVTKIds_faces.push_back(aId);
911 if(!Preview->isChecked()){
913 mySimulation->SetPosition(myActor, aType, aVTKIds_faces);
916 if(Preview->isChecked())
917 mySimulation->SetPosition(myActor, aType, aVTKIds);
923 //=================================================================================
924 // function : SetEditCurrentArgument()
926 //=================================================================================
927 void SMESHGUI_CreatePolyhedralVolumeDlg::SetEditCurrentArgument()
929 QPushButton* send = (QPushButton*)sender();
930 if(send == SelectElementsButton) {
931 LineEditElements->setFocus() ;
932 myEditCurrentArgument = LineEditElements;
934 SelectionIntoArgument();
937 //=================================================================================
938 // function : DeactivateActiveDialog()
940 //=================================================================================
941 void SMESHGUI_CreatePolyhedralVolumeDlg::DeactivateActiveDialog()
943 if ( GroupConstructors->isEnabled() ) {
944 GroupConstructors->setEnabled(false) ;
945 GroupContent->setEnabled(false) ;
946 GroupButtons->setEnabled(false) ;
947 mySimulation->SetVisibility(false);
948 mySMESHGUI->ResetState() ;
949 mySMESHGUI->SetActiveDialogBox(0) ;
954 //=================================================================================
955 // function : ActivateThisDialog()
957 //=================================================================================
958 void SMESHGUI_CreatePolyhedralVolumeDlg::ActivateThisDialog()
960 /* Emit a signal to deactivate the active dialog */
961 mySMESHGUI->EmitSignalDeactivateDialog() ;
962 GroupConstructors->setEnabled(true) ;
963 GroupContent->setEnabled(true) ;
964 GroupButtons->setEnabled(true) ;
966 mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
968 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
969 aViewWindow->SetSelectionMode( FaceSelection );
970 SelectionIntoArgument();
974 //=================================================================================
975 // function : enterEvent()
977 //=================================================================================
978 void SMESHGUI_CreatePolyhedralVolumeDlg::enterEvent(QEvent* e)
980 if ( GroupConstructors->isEnabled() )
982 ActivateThisDialog() ;
986 //=================================================================================
987 // function : closeEvent()
989 //=================================================================================
990 void SMESHGUI_CreatePolyhedralVolumeDlg::closeEvent( QCloseEvent* e )
992 /* same than click on cancel button */
993 this->ClickOnCancel() ;
997 //=======================================================================
998 //function : hideEvent
999 //purpose : caused by ESC key
1000 //=======================================================================
1002 void SMESHGUI_CreatePolyhedralVolumeDlg::hideEvent ( QHideEvent * e )
1004 if ( !isMinimized() )
1009 //=================================================================================
1010 // function : GetConstructorId()
1012 //=================================================================================
1013 int SMESHGUI_CreatePolyhedralVolumeDlg::GetConstructorId()
1015 if ( GroupConstructors != NULL && GroupConstructors->selected() != NULL )
1016 return GroupConstructors->id( GroupConstructors->selected() );
1020 //=================================================================================
1021 // function : onAdd()
1023 //=================================================================================
1024 void SMESHGUI_CreatePolyhedralVolumeDlg::onAdd()
1026 SALOME_ListIO selected;
1027 mySelectionMgr->selectedObjects( selected );
1028 int aNbSel = selected.Extent();
1029 if (aNbSel == 0 || !myActor || myMesh->_is_nil()) return;
1031 if (this->checkEditLine(false) == -1) return;
1034 if ( !(myEditCurrentArgument->text().isEmpty()) )
1036 myFacesByNodes->insertItem(myEditCurrentArgument->text());
1037 //myFacesByNodes->setSelected(myFacesByNodes->count() - 1, true);
1039 myEditCurrentArgument->clear();
1040 AddButton->setEnabled(false);
1041 buttonOk->setEnabled( true );
1042 if(myFacesByNodes->count()>1) buttonApply->setEnabled( true );
1045 onListSelectionChanged();
1046 displaySimulation();
1049 //=================================================================================
1050 // function : onRemove()
1052 //=================================================================================
1053 void SMESHGUI_CreatePolyhedralVolumeDlg::onRemove()
1056 for (int i = myFacesByNodes->count(); i > 0; i--) {
1057 if (myFacesByNodes->isSelected(i-1)) {
1058 myFacesByNodes->removeItem(i-1);
1062 if (myFacesByNodes->count() < 1){
1063 RemoveButton->setEnabled(false);
1064 buttonOk->setEnabled( false );
1065 buttonApply->setEnabled( false );
1067 else if (myFacesByNodes->count() == 1){
1068 buttonOk->setEnabled( false );
1069 buttonApply->setEnabled( false );
1072 displaySimulation();
1075 //=================================================================================
1076 // function : onListSelectionChanged()
1077 // purpose : Called when selection in element list is changed
1078 //=================================================================================
1079 void SMESHGUI_CreatePolyhedralVolumeDlg::onListSelectionChanged()
1081 if (busy || !myActor) return;
1083 bool isSelected=false;
1084 SALOME_ListIO aList;
1085 mySelectionMgr->setSelectedObjects( aList );
1086 TColStd_MapOfInteger aIndexes;
1087 QListBoxItem* anItem;
1088 for (anItem = myFacesByNodes->firstItem(); anItem != 0; anItem = anItem->next()) {
1089 if (anItem->isSelected()) {
1091 QStringList anIds = QStringList::split(" ", anItem->text());
1092 for (QStringList::iterator it = anIds.begin(); it != anIds.end(); ++it)
1093 aIndexes.Add((*it).toInt());
1096 if(isSelected) RemoveButton->setEnabled(true);
1097 else RemoveButton->setEnabled(false);
1098 mySelector->AddOrRemoveIndex(myActor->getIO(), aIndexes, true );
1099 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1100 aViewWindow->highlight( myActor->getIO(), true, true );
1101 mySelectionMgr->clearFilters();
1102 aList.Append( myActor->getIO() );
1103 mySelectionMgr->setSelectedObjects( aList );
1108 //=================================================================================
1109 // function : keyPressEvent()
1111 //=================================================================================
1112 void SMESHGUI_CreatePolyhedralVolumeDlg::keyPressEvent( QKeyEvent* e )
1114 QDialog::keyPressEvent( e );
1115 if ( e->isAccepted() )
1118 if ( e->key() == Key_F1 )