1 // Copyright (C) 2007-2013 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
23 // SMESH SMESHGUI : GUI for SMESH component
24 // File : SMESHGUI_CreatePolyhedralVolumeDlg.cxx
25 // Author : Michael ZORIN, Open CASCADE S.A.S.
28 #include "SMESHGUI_CreatePolyhedralVolumeDlg.h"
31 #include "SMESHGUI_Utils.h"
32 #include "SMESHGUI_VTKUtils.h"
33 #include "SMESHGUI_MeshUtils.h"
34 #include "SMESHGUI_GroupUtils.h"
35 #include "SMESHGUI_IdValidator.h"
37 #include <SMESH_Actor.h>
38 #include <SMESH_ActorUtils.h>
39 #include <SMDS_Mesh.hxx>
41 // SALOME GUI includes
42 #include <SUIT_Desktop.h>
43 #include <SUIT_ResourceMgr.h>
44 #include <SUIT_Session.h>
45 #include <SUIT_MessageBox.h>
46 #include <SUIT_ViewManager.h>
47 #include <SUIT_OverrideCursor.h>
49 #include <SalomeApp_Application.h>
50 #include <LightApp_SelectionMgr.h>
52 #include <SVTK_ViewWindow.h>
55 #include <TColStd_ListOfInteger.hxx>
56 #include <TColStd_ListIteratorOfListOfInteger.hxx>
60 #include <vtkIdList.h>
61 #include <vtkUnstructuredGrid.h>
62 #include <vtkDataSetMapper.h>
63 #include <vtkProperty.h>
66 #include <QApplication>
67 #include <QButtonGroup>
72 #include <QPushButton>
73 #include <QRadioButton>
75 #include <QHBoxLayout>
76 #include <QVBoxLayout>
77 #include <QGridLayout>
78 #include <QListWidget>
82 #include <SALOMEconfig.h>
83 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
92 SVTK_ViewWindow* myViewWindow;
94 SALOME_Actor *myPreviewActor;
95 vtkDataSetMapper* myMapper;
96 vtkUnstructuredGrid* myGrid;
100 TPolySimulation(SalomeApp_Application* app)
102 SUIT_ViewManager* mgr = app->activeViewManager();
103 myViewWindow = mgr ? dynamic_cast<SVTK_ViewWindow*>( mgr->getActiveView() ) : NULL;
105 myGrid = vtkUnstructuredGrid::New();
107 // Create and display actor
108 myMapper = vtkDataSetMapper::New();
109 myMapper->SetInputData( myGrid );
111 myPreviewActor = SALOME_Actor::New();
112 myPreviewActor->PickableOff();
113 myPreviewActor->VisibilityOff();
114 myPreviewActor->SetMapper( myMapper );
115 myPreviewActor->SetRepresentation( 3 );
118 vtkProperty* aProp = vtkProperty::New();
119 GetColor( "SMESH", "selection_element_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 170, 255 ) );
120 aProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
121 myPreviewActor->SetProperty( aProp );
122 double aFactor,aUnits;
123 myPreviewActor->SetResolveCoincidentTopology(true);
124 myPreviewActor->GetPolygonOffsetParameters(aFactor,aUnits);
125 myPreviewActor->SetPolygonOffsetParameters(aFactor,0.2*aUnits);
128 myViewWindow->AddActor( myPreviewActor );
133 typedef std::vector<vtkIdType> TVTKIds;
134 void SetPosition(SMESH_Actor* theActor,
136 const TVTKIds& theIds,
139 vtkUnstructuredGrid *aGrid = theActor->GetUnstructuredGrid();
140 myGrid->SetPoints(aGrid->GetPoints());
144 vtkIdList *anIds = vtkIdList::New();
146 for (int i = 0, iEnd = theIds.size(); i < iEnd; i++)
147 anIds->InsertId(i,theIds[i]);
149 myGrid->InsertNextCell(theType,anIds);
150 if(theIds.size()!=0){
151 myGrid->InsertNextCell(theType,anIds);
161 void ResetGrid(bool theReset=true){
162 if (theReset) myGrid->Reset();
165 void SetVisibility(bool theVisibility){
166 myPreviewActor->SetVisibility(theVisibility);
167 RepaintCurrentView();
173 myViewWindow->RemoveActor(myPreviewActor);
175 myPreviewActor->Delete();
177 myMapper->RemoveAllInputs();
186 //=================================================================================
187 // class : SMESHGUI_CreatePolyhedralVolumeDlgDlg()
189 //=================================================================================
190 SMESHGUI_CreatePolyhedralVolumeDlg::SMESHGUI_CreatePolyhedralVolumeDlg( SMESHGUI* theModule )
191 : QDialog( SMESH::GetDesktop( theModule ) ),
192 mySMESHGUI( theModule ),
193 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
195 QPixmap image0( SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap( "SMESH",tr("ICON_SELECT")));
198 setAttribute(Qt::WA_DeleteOnClose, true);
199 setWindowTitle( tr( "SMESH_CREATE_POLYHEDRAL_VOLUME_TITLE" ) );
200 setSizeGripEnabled( true );
202 QVBoxLayout* topLayout = new QVBoxLayout( this );
203 topLayout->setSpacing( SPACING );
204 topLayout->setMargin( MARGIN );
206 /***************************************************************/
207 ConstructorsBox = new QGroupBox(tr( "SMESH_ELEMENTS_TYPE" ), this);
208 GroupConstructors = new QButtonGroup(this);
209 QHBoxLayout* ConstructorsBoxLayout = new QHBoxLayout( ConstructorsBox );
210 ConstructorsBoxLayout->setSpacing( SPACING );
211 ConstructorsBoxLayout->setMargin( MARGIN );
213 RadioButton1 = new QRadioButton( tr( "MESH_NODE" ), ConstructorsBox );
214 RadioButton2 = new QRadioButton( tr( "SMESH_FACE" ), ConstructorsBox );
216 ConstructorsBoxLayout->addWidget( RadioButton1 );
217 ConstructorsBoxLayout->addWidget( RadioButton2 );
218 GroupConstructors->addButton(RadioButton1, 0);
219 GroupConstructors->addButton(RadioButton2, 1);
221 /***************************************************************/
222 GroupContent = new QGroupBox( tr( "SMESH_CONTENT" ), this );
223 QGridLayout* GroupContentLayout = new QGridLayout( GroupContent );
224 GroupContentLayout->setSpacing( SPACING );
225 GroupContentLayout->setMargin( MARGIN );
227 TextLabelIds = new QLabel( tr( "SMESH_ID_NODES" ), GroupContent );
228 SelectElementsButton = new QPushButton( GroupContent );
229 SelectElementsButton->setIcon( image0 );
230 LineEditElements = new QLineEdit( GroupContent );
231 LineEditElements->setValidator( new SMESHGUI_IdValidator( this ) );
233 myFacesByNodesLabel = new QLabel( tr( "FACES_BY_NODES" ), GroupContent );
234 myFacesByNodes = new QListWidget( GroupContent);
235 myFacesByNodes->setSelectionMode( QListWidget::ExtendedSelection );
236 myFacesByNodes->setMinimumHeight( 150);
238 AddButton = new QPushButton( tr( "SMESH_BUT_ADD" ), GroupContent );
239 RemoveButton = new QPushButton( tr( "SMESH_BUT_REMOVE" ), GroupContent );
241 Preview = new QCheckBox( tr( "SMESH_POLYEDRE_PREVIEW" ), GroupContent );
243 GroupContentLayout->addWidget( TextLabelIds, 0, 0 );
244 GroupContentLayout->addWidget( SelectElementsButton, 0, 1 );
245 GroupContentLayout->addWidget( LineEditElements, 0, 2, 1, 2 );
246 GroupContentLayout->addWidget( myFacesByNodesLabel, 1, 0 );
247 GroupContentLayout->addWidget( myFacesByNodes, 2, 0, 3, 3 );
248 GroupContentLayout->addWidget( AddButton, 2, 3 );
249 GroupContentLayout->addWidget( RemoveButton, 3, 3 );
250 GroupContentLayout->addWidget( Preview, 5, 0, 1, 4 );
252 /***************************************************************/
253 GroupGroups = new QGroupBox( tr( "SMESH_ADD_TO_GROUP" ), this );
254 GroupGroups->setCheckable( true );
255 QHBoxLayout* GroupGroupsLayout = new QHBoxLayout(GroupGroups);
256 GroupGroupsLayout->setSpacing(SPACING);
257 GroupGroupsLayout->setMargin(MARGIN);
259 TextLabel_GroupName = new QLabel( tr( "SMESH_GROUP" ), GroupGroups );
260 ComboBox_GroupName = new QComboBox( GroupGroups );
261 ComboBox_GroupName->setEditable( true );
262 ComboBox_GroupName->setInsertPolicy( QComboBox::NoInsert );
264 GroupGroupsLayout->addWidget( TextLabel_GroupName );
265 GroupGroupsLayout->addWidget( ComboBox_GroupName, 1 );
267 /***************************************************************/
268 GroupButtons = new QGroupBox( this );
269 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout( GroupButtons );
270 GroupButtonsLayout->setSpacing( SPACING );
271 GroupButtonsLayout->setMargin( MARGIN );
273 buttonOk = new QPushButton( tr( "SMESH_BUT_APPLY_AND_CLOSE" ), GroupButtons );
274 buttonOk->setAutoDefault( true );
275 buttonOk->setDefault( true );
276 buttonApply = new QPushButton( tr( "SMESH_BUT_APPLY" ), GroupButtons );
277 buttonApply->setAutoDefault( true );
278 buttonCancel = new QPushButton( tr( "SMESH_BUT_CLOSE" ), GroupButtons );
279 buttonCancel->setAutoDefault( true );
280 buttonHelp = new QPushButton( tr("SMESH_BUT_HELP" ), GroupButtons );
281 buttonHelp->setAutoDefault(true);
283 GroupButtonsLayout->addWidget( buttonOk );
284 GroupButtonsLayout->addSpacing( 10 );
285 GroupButtonsLayout->addWidget( buttonApply );
286 GroupButtonsLayout->addSpacing( 10 );
287 GroupButtonsLayout->addStretch();
288 GroupButtonsLayout->addWidget( buttonCancel );
289 GroupButtonsLayout->addWidget( buttonHelp);
291 /***************************************************************/
292 topLayout->addWidget( ConstructorsBox );
293 topLayout->addWidget( GroupContent );
294 topLayout->addWidget( GroupGroups );
295 topLayout->addWidget( GroupButtons );
297 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
299 RadioButton1->setChecked( true );
301 mySMESHGUI->SetActiveDialogBox( (QDialog*)this );
303 myHelpFileName = "adding_nodes_and_elements_page.html#adding_polyhedrons_anchor";
308 //=================================================================================
309 // function : ~SMESHGUI_CreatePolyhedralVolumeDlg()
310 // purpose : Destroys the object and frees any allocated resources
311 //=================================================================================
312 SMESHGUI_CreatePolyhedralVolumeDlg::~SMESHGUI_CreatePolyhedralVolumeDlg()
317 static bool busy = false;
319 //=================================================================================
322 //=================================================================================
323 void SMESHGUI_CreatePolyhedralVolumeDlg::Init()
325 myEditCurrentArgument = LineEditElements;
326 mySMESHGUI->SetActiveDialogBox( (QDialog*)this );
328 /* reset "Add to group" control */
329 GroupGroups->setChecked( false );
334 mySimulation = new SMESH::TPolySimulation( dynamic_cast<SalomeApp_Application*>( mySMESHGUI->application() ) );
336 /* signals and slots connections */
337 connect(buttonOk, SIGNAL( clicked() ), SLOT( ClickOnOk() ) );
338 connect(buttonCancel, SIGNAL( clicked() ), SLOT( reject() ) );
339 connect(buttonApply, SIGNAL( clicked() ), SLOT( ClickOnApply() ) );
340 connect(buttonHelp, SIGNAL( clicked() ), SLOT( ClickOnHelp() ) );
342 connect(GroupConstructors, SIGNAL(buttonClicked(int) ), SLOT( ConstructorsClicked(int) ) );
343 connect(SelectElementsButton, SIGNAL( clicked() ), SLOT( SetEditCurrentArgument() ) );
344 connect(LineEditElements, SIGNAL( textChanged(const QString&) ), SLOT(onTextChange(const QString&)));
346 connect(myFacesByNodes, SIGNAL(itemSelectionChanged()), this, SLOT(onListSelectionChanged()));
347 connect(AddButton, SIGNAL(clicked()), this, SLOT(onAdd()));
348 connect(RemoveButton, SIGNAL(clicked()), this, SLOT(onRemove()));
350 connect( mySMESHGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) );
351 connect( mySelectionMgr, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
352 connect( Preview, SIGNAL(toggled(bool)), this, SLOT(ClickOnPreview(bool)));
353 /* to close dialog if study change */
354 connect( mySMESHGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( reject() ) );
356 ConstructorsClicked(0);
357 SelectionIntoArgument();
361 //=================================================================================
362 // function : ConstructorsClicked()
363 // purpose : Radio button management
364 //=================================================================================
365 void SMESHGUI_CreatePolyhedralVolumeDlg::ConstructorsClicked(int constructorId)
367 //disconnect(mySelectionMgr, 0, this, 0);
370 mySelectionMgr->selectedObjects( io );
372 mySelectionMgr->setSelectedObjects( aList );
373 myEditCurrentArgument->clear();
375 buttonApply->setEnabled(false);
376 buttonOk->setEnabled(false);
377 mySimulation->SetVisibility(false);
379 switch(constructorId)
384 myActor->SetPointRepresentation(true);
387 SMESH::SetPointRepresentation(true);
388 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
389 aViewWindow->SetSelectionMode(NodeSelection);
391 AddButton->setEnabled(false);
392 RemoveButton->setEnabled(false);
393 TextLabelIds->setText( tr( "SMESH_ID_NODES" ) );
394 myFacesByNodesLabel->show();
395 myFacesByNodes->clear();
396 myFacesByNodes->show();
398 RemoveButton->show();
405 myActor->SetPointRepresentation(false);
407 SMESH::SetPointRepresentation(false);
409 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
410 aViewWindow->SetSelectionMode(FaceSelection);
412 TextLabelIds->setText( tr( "SMESH_ID_FACES" ) );
413 myFacesByNodesLabel->hide();
414 myFacesByNodes->hide();
416 RemoveButton->hide();
422 //connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
423 mySelectionMgr->setSelectedObjects( io );
425 QApplication::instance()->processEvents();
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()
448 if ( myNbOkElements>0 && !mySMESHGUI->isActiveStudyLocked())
450 if(checkEditLine(false) == -1) {return;}
454 bool addToGroup = GroupGroups->isChecked();
457 SMESH::SMESH_GroupBase_var aGroup;
460 aGroupName = ComboBox_GroupName->currentText();
461 for ( int i = 1; i <= ComboBox_GroupName->count(); i++ ) {
462 QString aName = ComboBox_GroupName->itemText( i );
463 if ( aGroupName == aName && ( i == ComboBox_GroupName->currentIndex() || idx == 0 ) )
466 if ( idx > 0 && idx <= myGroups.count() ) {
467 SMESH::SMESH_GroupOnGeom_var aGeomGroup = SMESH::SMESH_GroupOnGeom::_narrow( myGroups[idx-1] );
468 if ( !aGeomGroup->_is_nil() ) {
469 int res = SUIT_MessageBox::question( this, tr( "SMESH_WRN_WARNING" ),
470 tr( "MESH_STANDALONE_GRP_CHOSEN" ).arg( aGroupName ),
471 tr( "SMESH_BUT_YES" ), tr( "SMESH_BUT_NO" ), 0, 1 );
472 if ( res == 1 ) return;
474 aGroup = myGroups[idx-1];
478 if (GetConstructorId() == 0)
480 SMESH::long_array_var anIdsOfNodes = new SMESH::long_array;
481 SMESH::long_array_var aQuantities = new SMESH::long_array;
483 aQuantities->length( myFacesByNodes->count() );
485 TColStd_ListOfInteger aNodesIds;
487 int aNbQuantities = 0;
488 for (int i = 0; i < myFacesByNodes->count(); i++ ) {
489 QStringList anIds = myFacesByNodes->item(i)->text().split( " ", QString::SkipEmptyParts );
490 for (QStringList::iterator it = anIds.begin(); it != anIds.end(); ++it)
491 aNodesIds.Append( (*it).toInt() );
493 aQuantities[aNbQuantities++] = anIds.count();
496 anIdsOfNodes->length(aNodesIds.Extent());
498 int aNbIdsOfNodes = 0;
499 TColStd_ListIteratorOfListOfInteger It;
500 It.Initialize(aNodesIds);
501 for( ;It.More();It.Next())
502 anIdsOfNodes[aNbIdsOfNodes++] = It.Value();
505 SUIT_OverrideCursor aWaitCursor;
506 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
507 anElemId = aMeshEditor->AddPolyhedralVolume(anIdsOfNodes, aQuantities);
508 }catch(SALOME::SALOME_Exception& exc){
509 INFOS("Follow exception was cought:\n\t"<<exc.details.text);
510 }catch(std::exception& exc){
511 INFOS("Follow exception was cought:\n\t"<<exc.what());
513 INFOS("Unknown exception was cought !!!");
516 else if (GetConstructorId() == 1)
518 SMESH::long_array_var anIdsOfFaces = new SMESH::long_array;
520 QStringList aListId = myEditCurrentArgument->text().split( " ", QString::SkipEmptyParts );
521 anIdsOfFaces->length(aListId.count());
522 for ( int i = 0; i < aListId.count(); i++ )
523 anIdsOfFaces[i] = aListId[i].toInt();
526 SUIT_OverrideCursor aWaitCursor;
527 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
528 anElemId = aMeshEditor->AddPolyhedralVolumeByFaces(anIdsOfFaces);
529 }catch(SALOME::SALOME_Exception& exc){
530 INFOS("Follow exception was cought:\n\t"<<exc.details.text);
531 }catch(std::exception& exc){
532 INFOS("Follow exception was cought:\n\t"<<exc.what());
534 INFOS("Unknown exception was cought !!!");
538 if ( anElemId != -1 && addToGroup && !aGroupName.isEmpty() ) {
539 SMESH::SMESH_Group_var aGroupUsed;
540 if ( aGroup->_is_nil() ) {
542 aGroupUsed = SMESH::AddGroup( myMesh, SMESH::VOLUME, aGroupName );
543 if ( !aGroupUsed->_is_nil() ) {
544 myGroups.append(SMESH::SMESH_GroupBase::_duplicate(aGroupUsed));
545 ComboBox_GroupName->addItem( aGroupName );
549 SMESH::SMESH_GroupOnGeom_var aGeomGroup = SMESH::SMESH_GroupOnGeom::_narrow( aGroup );
550 if ( !aGeomGroup->_is_nil() ) {
551 aGroupUsed = myMesh->ConvertToStandalone( aGeomGroup );
552 if ( !aGroupUsed->_is_nil() && idx > 0 ) {
553 myGroups[idx-1] = SMESH::SMESH_GroupBase::_duplicate(aGroupUsed);
554 SMESHGUI::GetSMESHGUI()->getApp()->updateObjectBrowser();
558 aGroupUsed = SMESH::SMESH_Group::_narrow( aGroup );
561 if ( !aGroupUsed->_is_nil() ) {
562 SMESH::long_array_var anIdList = new SMESH::long_array;
563 anIdList->length( 1 );
564 anIdList[0] = anElemId;
565 aGroupUsed->Add( anIdList.inout() );
569 //SALOME_ListIO aList;
570 //mySelectionMgr->setSelectedObjects( aList );
573 unsigned int anEntityMode = myActor->GetEntityMode();
574 myActor->SetEntityMode(SMESH_Actor::eVolumes | anEntityMode);
576 //ConstructorsClicked( GetConstructorId() );
579 SMESHGUI::Modified();
581 myFacesByNodes->clear();
584 //=================================================================================
585 // function : ClickOnOk()
587 //=================================================================================
588 void SMESHGUI_CreatePolyhedralVolumeDlg::ClickOnOk()
590 if(checkEditLine(false) == -1) {return;}
596 //=================================================================================
597 // function : reject()
599 //=================================================================================
600 void SMESHGUI_CreatePolyhedralVolumeDlg::reject()
602 mySelectionMgr->clearFilters();
603 //SALOME_ListIO aList;
604 //mySelectionMgr->setSelectedObjects( aList );
605 SMESH::SetPointRepresentation(false);
606 mySimulation->SetVisibility(false);
607 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
608 aViewWindow->SetSelectionMode( ActorSelection );
609 disconnect( mySelectionMgr, 0, this, 0 );
610 mySMESHGUI->ResetState();
614 //=================================================================================
615 // function : ClickOnHelp()
617 //=================================================================================
618 void SMESHGUI_CreatePolyhedralVolumeDlg::ClickOnHelp()
620 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
622 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
626 platform = "winapplication";
628 platform = "application";
630 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
631 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
632 arg(app->resourceMgr()->stringValue("ExternalBrowser",
634 arg(myHelpFileName));
638 //=======================================================================
639 //function : onTextChange
641 //=======================================================================
643 void SMESHGUI_CreatePolyhedralVolumeDlg::onTextChange(const QString& theNewText)
646 if (checkEditLine() == -1) return;
649 mySimulation->SetVisibility(false);
651 SMDS_Mesh* aMesh = 0;
653 aMesh = myActor->GetObject()->GetMesh();
655 if (GetConstructorId() == 0)
658 TColStd_MapOfInteger newIndices;
660 QStringList aListId = theNewText.split( " ", QString::SkipEmptyParts );
661 for ( int i = 0; i < aListId.count(); i++ ) {
662 const SMDS_MeshNode * n = aMesh->FindNode( aListId[ i ].toInt() );
664 newIndices.Add(n->GetID());
669 mySelector->AddOrRemoveIndex( myActor->getIO(), newIndices, false );
671 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
672 aViewWindow->highlight( myActor->getIO(), true, true );
674 if ( myNbOkElements>0 && aListId.count()>=3)
675 AddButton->setEnabled(true);
677 AddButton->setEnabled(false);
681 } else if (GetConstructorId() == 1)
684 buttonOk->setEnabled( false );
685 buttonApply->setEnabled( false );
687 // check entered ids of faces and hilight them
690 TColStd_MapOfInteger newIndices;
692 aListId = theNewText.split( " ", QString::SkipEmptyParts );
694 for ( int i = 0; i < aListId.count(); i++ ) {
695 const SMDS_MeshElement * e = aMesh->FindElement( aListId[ i ].toInt() );
697 newIndices.Add(e->GetID());
702 mySelector->AddOrRemoveIndex( myActor->getIO(), newIndices, false );
703 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
704 aViewWindow->highlight( myActor->getIO(), true, true );
706 if ( myNbOkElements ) {
707 if (aListId.count()>1){
708 buttonOk->setEnabled( true );
709 buttonApply->setEnabled( true );
712 buttonOk->setEnabled( false );
713 buttonApply->setEnabled( false );
715 if(aListId.count()>1)
723 //=================================================================================
724 // function : SelectionIntoArgument()
725 // purpose : Called when selection as changed or other case
726 //=================================================================================
727 void SMESHGUI_CreatePolyhedralVolumeDlg::SelectionIntoArgument()
733 if (GetConstructorId() == 1 || myFacesByNodes->count() <= 1)
736 AddButton->setEnabled(false);
737 buttonOk->setEnabled( false );
738 buttonApply->setEnabled( false );
744 myEditCurrentArgument->setText( "" );
746 if ( !GroupButtons->isEnabled() ) // inactive
749 mySimulation->SetVisibility(false);
751 QString aCurrentEntry = myEntry;
755 SALOME_ListIO selected;
756 mySelectionMgr->selectedObjects( selected );
757 int nbSel = selected.Extent();
762 myEntry = selected.First()->getEntry();
763 myMesh = SMESH::GetMeshByIO( selected.First() );
764 if ( myMesh->_is_nil() )
768 if ( !myMesh->_is_nil() && myEntry != aCurrentEntry ) {
770 ComboBox_GroupName->clear();
771 ComboBox_GroupName->addItem( QString() );
772 SMESH::ListOfGroups aListOfGroups = *myMesh->GetGroups();
773 for ( int i = 0, n = aListOfGroups.length(); i < n; i++ ) {
774 SMESH::SMESH_GroupBase_var aGroup = aListOfGroups[i];
775 if ( !aGroup->_is_nil() && aGroup->GetType() == SMESH::VOLUME ) {
776 QString aGroupName( aGroup->GetName() );
777 if ( !aGroupName.isEmpty() ) {
778 myGroups.append(SMESH::SMESH_GroupBase::_duplicate(aGroup));
779 ComboBox_GroupName->addItem( aGroupName );
785 myActor = SMESH::FindActorByObject(myMesh);
789 // get selected nodes/faces
790 QString aString = "";
791 int anbNodes=0,aNbFaces=0;
792 switch(GetConstructorId()){
794 anbNodes = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aString);
796 AddButton->setEnabled(true);
797 else if (anbNodes < 3){
798 AddButton->setEnabled(false);
801 myEditCurrentArgument->setText( aString );
802 if (checkEditLine() == -1) {busy = false;return;}
807 // get selected faces
808 aNbFaces = SMESH::GetNameOfSelectedElements(mySelector, myActor->getIO(), aString);
810 buttonOk->setEnabled( false );
811 buttonApply->setEnabled( false );
813 buttonOk->setEnabled( true );
814 buttonApply->setEnabled( true );
817 myEditCurrentArgument->setText( aString );
818 if (checkEditLine() == -1) {busy = false;return;}
827 if(anbNodes>2 || aNbFaces>1)
831 /*\brief int SMESHGUI_CreatePolyhedralVolumeDlg::checkEditLine()
832 * Checking of indices in edit line.
833 * If incorecct indices in edit line warning message appear and myEditCurrentArgument remove last index.
834 * \retval 1 - if all ok(or no indices in edit line), -1 - if there are incorrect indices.
836 int SMESHGUI_CreatePolyhedralVolumeDlg::checkEditLine(bool checkLast)
838 QString aString = "";
839 SMDS_Mesh* aMesh = 0;
841 if(myMesh->_is_nil()) return 1;
843 myActor = SMESH::FindActorByObject(myMesh);
848 aMesh = myActor->GetObject()->GetMesh();
850 // checking for nodes
851 if (checkLast && myEditCurrentArgument->text().right(1) != QString(" ") ) return 1;
852 QStringList aListId = myEditCurrentArgument->text().split( " ", QString::SkipEmptyParts );
853 for ( int i = 0; i < aListId.count(); i++ ){
854 switch (GetConstructorId()){
856 const SMDS_MeshNode * aNode = aMesh->FindNode( aListId[ i ].toInt() );
858 SUIT_MessageBox::warning(this,
859 tr("SMESH_POLYEDRE_CREATE_ERROR"),
860 tr("The incorrect indices of nodes!"));
862 myEditCurrentArgument->clear();
863 myEditCurrentArgument->setText( aString );
870 bool aElemIsOK = true;
871 const SMDS_MeshElement * aElem = aMesh->FindElement( aListId[ i ].toInt() );
878 SMDSAbs_ElementType aType = aMesh->GetElementType( aElem->GetID(),true );
879 if (aType != SMDSAbs_Face){
884 SUIT_MessageBox::warning(this,
885 tr("SMESH_POLYEDRE_CREATE_ERROR"),
886 tr("The incorrect indices of faces!"));
888 myEditCurrentArgument->clear();
889 myEditCurrentArgument->setText( aString );
895 aString += aListId[ i ] + " ";
901 //=======================================================================
902 //function : displaySimulation
904 //=======================================================================
905 void SMESHGUI_CreatePolyhedralVolumeDlg::displaySimulation()
907 if ( (myNbOkElements || AddButton->isEnabled()) && GroupButtons->isEnabled() && myActor)
909 SMESH::TPolySimulation::TVTKIds aVTKIds;
910 vtkIdType aType = VTK_CONVEX_POINT_SET;
911 SMDS_Mesh* aMesh = 0;
913 aMesh = myActor->GetObject()->GetMesh();
915 if (GetConstructorId() == 0 && aMesh){
916 if (!AddButton->isEnabled()){
917 mySimulation->ResetGrid(true);
918 for (int i = 0; i < myFacesByNodes->count(); i++) {
919 QStringList anIds = myFacesByNodes->item(i)->text().split( " ", QString::SkipEmptyParts );
920 SMESH::TPolySimulation::TVTKIds aVTKIds_faces;
921 for (QStringList::iterator it = anIds.begin(); it != anIds.end(); ++it){
922 const SMDS_MeshNode* aNode = aMesh->FindNode( (*it).toInt() );
923 if (!aNode) continue;
924 vtkIdType aId = myActor->GetObject()->GetNodeVTKId( (*it).toInt() );
925 aVTKIds.push_back(aId);
926 aVTKIds_faces.push_back(aId);
928 if(!Preview->isChecked()){
930 mySimulation->SetPosition(myActor, aType, aVTKIds_faces,false);
933 if(myFacesByNodes->count() == 0){
934 mySimulation->SetVisibility(false);
936 mySimulation->SetVisibility(true);
938 if(Preview->isChecked()){
939 mySimulation->SetPosition(myActor, aType, aVTKIds);
942 // add ids from edit line
943 QStringList anEditIds = myEditCurrentArgument->text().split( " ", QString::SkipEmptyParts );
944 for ( int i = 0; i < anEditIds.count(); i++ )
945 aVTKIds.push_back( myActor->GetObject()->GetNodeVTKId( anEditIds[ i ].toInt() ));
947 mySimulation->SetPosition(myActor, aType, aVTKIds);
949 }else if(GetConstructorId() == 1 && aMesh){
950 QStringList aListId = myEditCurrentArgument->text().split( " ", QString::SkipEmptyParts );
951 for ( int i = 0; i < aListId.count(); i++ )
953 const SMDS_MeshElement * anElem = aMesh->FindElement( aListId[ i ].toInt() );
954 if ( !anElem ) continue;
955 SMDSAbs_ElementType aFaceType = aMesh->GetElementType( anElem->GetID(),true );
956 if (aFaceType != SMDSAbs_Face) continue;
958 SMDS_ElemIteratorPtr anIter = anElem->nodesIterator();
959 SMESH::TPolySimulation::TVTKIds aVTKIds_faces;
960 while( anIter->more() )
961 if ( const SMDS_MeshNode* aNode = (SMDS_MeshNode*)anIter->next() ){
962 vtkIdType aId = myActor->GetObject()->GetNodeVTKId( aNode->GetID() );
963 aVTKIds.push_back(aId);
964 aVTKIds_faces.push_back(aId);
966 if(!Preview->isChecked()){
968 mySimulation->SetPosition(myActor, aType, aVTKIds_faces);
971 if(Preview->isChecked())
972 mySimulation->SetPosition(myActor, aType, aVTKIds);
978 //=================================================================================
979 // function : SetEditCurrentArgument()
981 //=================================================================================
982 void SMESHGUI_CreatePolyhedralVolumeDlg::SetEditCurrentArgument()
984 QPushButton* send = (QPushButton*)sender();
985 if(send == SelectElementsButton) {
986 LineEditElements->setFocus();
987 myEditCurrentArgument = LineEditElements;
989 SelectionIntoArgument();
992 //=================================================================================
993 // function : DeactivateActiveDialog()
995 //=================================================================================
996 void SMESHGUI_CreatePolyhedralVolumeDlg::DeactivateActiveDialog()
998 if ( ConstructorsBox->isEnabled() ) {
999 ConstructorsBox->setEnabled(false);
1000 GroupContent->setEnabled(false);
1001 GroupButtons->setEnabled(false);
1002 mySimulation->SetVisibility(false);
1003 mySMESHGUI->ResetState();
1004 mySMESHGUI->SetActiveDialogBox(0);
1009 //=================================================================================
1010 // function : ActivateThisDialog()
1012 //=================================================================================
1013 void SMESHGUI_CreatePolyhedralVolumeDlg::ActivateThisDialog()
1015 /* Emit a signal to deactivate the active dialog */
1016 mySMESHGUI->EmitSignalDeactivateDialog();
1017 ConstructorsBox->setEnabled(true);
1018 GroupContent->setEnabled(true);
1019 GroupButtons->setEnabled(true);
1021 mySMESHGUI->SetActiveDialogBox( (QDialog*)this );
1023 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1024 aViewWindow->SetSelectionMode( FaceSelection );
1025 SelectionIntoArgument();
1029 //=================================================================================
1030 // function : enterEvent()
1032 //=================================================================================
1033 void SMESHGUI_CreatePolyhedralVolumeDlg::enterEvent(QEvent* e)
1035 if ( ConstructorsBox->isEnabled() )
1037 ActivateThisDialog();
1040 //=================================================================================
1041 // function : GetConstructorId()
1043 //=================================================================================
1044 int SMESHGUI_CreatePolyhedralVolumeDlg::GetConstructorId()
1046 return GroupConstructors->checkedId();
1049 //=================================================================================
1050 // function : onAdd()
1052 //=================================================================================
1053 void SMESHGUI_CreatePolyhedralVolumeDlg::onAdd()
1055 SALOME_ListIO selected;
1056 mySelectionMgr->selectedObjects( selected );
1057 int aNbSel = selected.Extent();
1058 if (aNbSel == 0 || !myActor || myMesh->_is_nil()) return;
1060 if (checkEditLine(false) == -1) return;
1063 if ( !(myEditCurrentArgument->text().isEmpty()) )
1065 myFacesByNodes->addItem(myEditCurrentArgument->text());
1066 //myFacesByNodes->setSelected(myFacesByNodes->count() - 1, true);
1068 myEditCurrentArgument->clear();
1069 AddButton->setEnabled(false);
1070 buttonApply->setEnabled( myFacesByNodes->count() > 1 );
1071 buttonOk->setEnabled( myFacesByNodes->count() > 1 );
1074 onListSelectionChanged();
1075 displaySimulation();
1078 //=================================================================================
1079 // function : onRemove()
1081 //=================================================================================
1082 void SMESHGUI_CreatePolyhedralVolumeDlg::onRemove()
1085 QList<QListWidgetItem*> selItems = myFacesByNodes->selectedItems();
1086 QListWidgetItem* anItem;
1088 if ( selItems.count() > 0 ) myNbOkElements = 1;
1090 foreach( anItem, selItems )
1093 RemoveButton->setEnabled( myFacesByNodes->count() > 0 );
1094 buttonOk->setEnabled( myFacesByNodes->count() > 1 );
1095 buttonApply->setEnabled( myFacesByNodes->count() > 1 );
1098 displaySimulation();
1101 //=================================================================================
1102 // function : onListSelectionChanged()
1103 // purpose : Called when selection in element list is changed
1104 //=================================================================================
1105 void SMESHGUI_CreatePolyhedralVolumeDlg::onListSelectionChanged()
1107 if (busy || !myActor) return;
1110 SALOME_ListIO aList;
1111 mySelectionMgr->setSelectedObjects( aList );
1112 TColStd_MapOfInteger aIndexes;
1114 QList<QListWidgetItem*> selItems = myFacesByNodes->selectedItems();
1115 QListWidgetItem* anItem;
1116 foreach( anItem, selItems ) {
1117 QStringList anIds = anItem->text().split( " ", QString::SkipEmptyParts );
1118 for (QStringList::iterator it = anIds.begin(); it != anIds.end(); ++it)
1119 aIndexes.Add((*it).toInt());
1121 RemoveButton->setEnabled(selItems.count() > 0);
1122 mySelector->AddOrRemoveIndex(myActor->getIO(), aIndexes, true );
1123 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1124 aViewWindow->highlight( myActor->getIO(), true, true );
1125 mySelectionMgr->clearFilters();
1126 aList.Append( myActor->getIO() );
1127 mySelectionMgr->setSelectedObjects( aList );
1132 //=================================================================================
1133 // function : keyPressEvent()
1135 //=================================================================================
1136 void SMESHGUI_CreatePolyhedralVolumeDlg::keyPressEvent( QKeyEvent* e )
1138 QDialog::keyPressEvent( e );
1139 if ( e->isAccepted() )
1142 if ( e->key() == Qt::Key_F1 ) {
1148 //=================================================================================
1149 // function : isValid
1151 //=================================================================================
1152 bool SMESHGUI_CreatePolyhedralVolumeDlg::isValid()
1154 if( GroupGroups->isChecked() && ComboBox_GroupName->currentText().isEmpty() ) {
1155 SUIT_MessageBox::warning( this, tr( "SMESH_WRN_WARNING" ), tr( "GROUP_NAME_IS_EMPTY" ) );