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.salome-platform.org/ or email : webmaster.salome@opencascade.com
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 "SUIT_ResourceMgr.h"
43 #include "SUIT_Session.h"
44 #include "SUIT_MessageBox.h"
46 #include "SalomeApp_Application.h"
47 #include "SalomeApp_Study.h"
48 #include "SUIT_Desktop.h"
49 #include "SUIT_MessageBox.h"
50 #include "LightApp_Application.h"
51 #include "LightApp_SelectionMgr.h"
52 #include "utilities.h"
54 #include "SVTK_ViewWindow.h"
55 #include "SVTK_Selector.h"
57 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
58 #include <TColStd_ListOfInteger.hxx>
59 #include <TColStd_ListIteratorOfListOfInteger.hxx>
62 #include <vtkIdList.h>
63 #include <vtkIntArray.h>
64 #include <vtkCellArray.h>
65 #include <vtkUnsignedCharArray.h>
66 #include <vtkUnstructuredGrid.h>
67 #include <vtkDataSetMapper.h>
68 #include <vtkProperty.h>
71 #include <qapplication.h>
72 #include <qbuttongroup.h>
73 #include <qgroupbox.h>
75 #include <qlineedit.h>
76 #include <qpushbutton.h>
77 #include <qradiobutton.h>
78 #include <qcheckbox.h>
85 #include "SALOMEconfig.h"
86 #include CORBA_SERVER_HEADER(SMESH_Group)
87 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
93 class TPolySimulation{
94 SVTK_ViewWindow* myViewWindow;
96 SALOME_Actor *myPreviewActor;
97 vtkDataSetMapper* myMapper;
98 vtkUnstructuredGrid* myGrid;
102 TPolySimulation(SalomeApp_Application* app)
104 SUIT_ViewManager* mgr = app->activeViewManager();
105 myViewWindow = mgr ? dynamic_cast<SVTK_ViewWindow*>( mgr->getActiveView() ) : NULL;
107 myGrid = vtkUnstructuredGrid::New();
109 // Create and display actor
110 myMapper = vtkDataSetMapper::New();
111 myMapper->SetInput( myGrid );
113 myPreviewActor = SALOME_Actor::New();
114 myPreviewActor->PickableOff();
115 myPreviewActor->VisibilityOff();
116 myPreviewActor->SetMapper( myMapper );
117 myPreviewActor->SetRepresentation( 3 );
119 vtkFloatingPointType anRGB[3];
120 vtkProperty* aProp = vtkProperty::New();
121 GetColor( "SMESH", "selection_element_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 170, 255 ) );
122 aProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
123 myPreviewActor->SetProperty( aProp );
124 vtkFloatingPointType aFactor,aUnits;
125 myPreviewActor->SetResolveCoincidentTopology(true);
126 myPreviewActor->GetPolygonOffsetParameters(aFactor,aUnits);
127 myPreviewActor->SetPolygonOffsetParameters(aFactor,0.2*aUnits);
130 myViewWindow->AddActor( myPreviewActor );
135 typedef std::vector<vtkIdType> TVTKIds;
136 void SetPosition(SMESH_Actor* theActor,
138 const TVTKIds& theIds,
141 vtkUnstructuredGrid *aGrid = theActor->GetUnstructuredGrid();
142 myGrid->SetPoints(aGrid->GetPoints());
146 vtkIdList *anIds = vtkIdList::New();
148 for (int i = 0, iEnd = theIds.size(); i < iEnd; i++)
149 anIds->InsertId(i,theIds[i]);
151 myGrid->InsertNextCell(theType,anIds);
152 if(theIds.size()!=0){
153 myGrid->InsertNextCell(theType,anIds);
163 void ResetGrid(bool theReset=true){
164 if (theReset) myGrid->Reset();
167 void SetVisibility(bool theVisibility){
168 myPreviewActor->SetVisibility(theVisibility);
169 RepaintCurrentView();
175 myViewWindow->RemoveActor(myPreviewActor);
177 myPreviewActor->Delete();
179 myMapper->RemoveAllInputs();
188 //=================================================================================
189 // class : SMESHGUI_CreatePolyhedralVolumeDlgDlg()
191 //=================================================================================
192 SMESHGUI_CreatePolyhedralVolumeDlg::SMESHGUI_CreatePolyhedralVolumeDlg( SMESHGUI* theModule, const char* name,
193 bool modal, WFlags fl )
194 : QDialog( SMESH::GetDesktop( theModule ), name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | Qt::WDestructiveClose),
195 mySMESHGUI( theModule ),
196 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
198 QPixmap image0( SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap( "SMESH",tr("ICON_SELECT")));
201 setName( "SMESHGUI_CreatePolyhedralVolumeDlg" );
203 setCaption( tr( "SMESH_CREATE_POLYHEDRAL_VOLUME_TITLE" ) );
204 setSizeGripEnabled( TRUE );
205 SMESHGUI_CreatePolyhedralVolumeDlgLayout = new QGridLayout( this );
206 SMESHGUI_CreatePolyhedralVolumeDlgLayout->setSpacing( 6 );
207 SMESHGUI_CreatePolyhedralVolumeDlgLayout->setMargin( 11 );
209 /***************************************************************/
210 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
211 GroupConstructors->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)5, (QSizePolicy::SizeType)0, 0, 0, GroupConstructors->sizePolicy().hasHeightForWidth() ) );
212 GroupConstructors->setTitle( tr( "SMESH_ELEMENTS_TYPE" ) );
213 GroupConstructors->setExclusive( TRUE );
214 GroupConstructors->setColumnLayout(0, Qt::Vertical );
215 GroupConstructors->layout()->setSpacing( 0 );
216 GroupConstructors->layout()->setMargin( 0 );
217 GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
218 GroupConstructorsLayout->setAlignment( Qt::AlignTop );
219 GroupConstructorsLayout->setSpacing( 6 );
220 GroupConstructorsLayout->setMargin( 11 );
221 RadioButton1= new QRadioButton( GroupConstructors, "RadioButton1" );
222 RadioButton1->setText( tr( "MESH_NODE" ) );
223 GroupConstructorsLayout->addWidget( RadioButton1, 0, 0 );
224 RadioButton2= new QRadioButton( GroupConstructors, "RadioButton2" );
225 RadioButton2->setText( tr( "SMESH_FACE" ) );
226 GroupConstructorsLayout->addWidget( RadioButton2, 0, 2 );
227 SMESHGUI_CreatePolyhedralVolumeDlgLayout->addWidget( GroupConstructors, 0, 0 );
229 /***************************************************************/
230 GroupButtons = new QGroupBox( this, "GroupButtons" );
231 GroupButtons->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)7, (QSizePolicy::SizeType)0, 0, 0, GroupButtons->sizePolicy().hasHeightForWidth() ) );
232 GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) );
233 GroupButtons->setTitle( tr( "" ) );
234 GroupButtons->setColumnLayout(0, Qt::Vertical );
235 GroupButtons->layout()->setSpacing( 0 );
236 GroupButtons->layout()->setMargin( 0 );
237 GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
238 GroupButtonsLayout->setAlignment( Qt::AlignTop );
239 GroupButtonsLayout->setSpacing( 6 );
240 GroupButtonsLayout->setMargin( 11 );
241 buttonCancel = new QPushButton( GroupButtons, "cancel" );
242 buttonCancel->setText( tr( "SMESH_BUT_CLOSE" ) );
243 buttonCancel->setAutoDefault( TRUE );
244 GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
245 buttonApply = new QPushButton( GroupButtons, "apply" );
246 buttonApply->setText( tr( "SMESH_BUT_APPLY" ) );
247 buttonApply->setAutoDefault( TRUE );
248 GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
249 QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
250 GroupButtonsLayout->addItem( spacer_9, 0, 2 );
251 buttonOk = new QPushButton( GroupButtons, "ok" );
252 buttonOk->setText( tr( "SMESH_BUT_OK" ) );
253 buttonOk->setAutoDefault( TRUE );
254 buttonOk->setDefault( TRUE );
255 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
256 buttonHelp = new QPushButton(GroupButtons, "buttonHelp");
257 buttonHelp->setText(tr("SMESH_BUT_HELP" ));
258 buttonHelp->setAutoDefault(TRUE);
259 GroupButtonsLayout->addWidget(buttonHelp, 0, 4);
261 SMESHGUI_CreatePolyhedralVolumeDlgLayout->addWidget( GroupButtons, 2, 0 );
263 /***************************************************************/
264 GroupContent = new QGroupBox( this, "GroupContent" );
265 GroupContent->setTitle( tr( "SMESH_CONTENT" ) );
266 GroupContent->setColumnLayout(0, Qt::Vertical );
267 GroupContent->layout()->setSpacing( 0 );
268 GroupContent->layout()->setMargin( 0 );
269 GroupContentLayout = new QGridLayout( GroupContent->layout() );
270 GroupContentLayout->setAlignment( Qt::AlignTop );
271 GroupContentLayout->setSpacing( 6 );
272 GroupContentLayout->setMargin( 11 );
274 QFrame* anIds = new QFrame(GroupContent, "anIds");
275 QGridLayout* aLayout = new QGridLayout(anIds, 1, 3);
276 aLayout->setSpacing(6);
277 aLayout->setAutoAdd(false);
279 TextLabelIds = new QLabel( anIds, "TextLabelIds" );
280 TextLabelIds->setText( tr( "SMESH_ID_NODES" ) );
281 TextLabelIds->setFixedWidth(74);
282 aLayout->addWidget( TextLabelIds, 0, 0 );
284 SelectElementsButton = new QPushButton( anIds, "SelectElementsButton" );
285 SelectElementsButton->setText( tr( "" ) );
286 SelectElementsButton->setPixmap( image0 );
287 SelectElementsButton->setToggleButton( FALSE );
288 aLayout->addWidget( SelectElementsButton, 0, 1 );
290 LineEditElements = new QLineEdit( anIds, "LineEditElements" );
291 LineEditElements->setValidator( new SMESHGUI_IdValidator( this, "validator" ));
292 aLayout->addWidget( LineEditElements, 0, 2 );
294 GroupContentLayout->addMultiCellWidget(anIds, 0, 0, 0, 1);
296 myFacesByNodesLabel = new QLabel(GroupContent, "faces by nodes label");
297 myFacesByNodesLabel->setText(tr("FACES_BY_NODES"));
298 GroupContentLayout->addWidget( myFacesByNodesLabel, 1, 0 );
300 myFacesByNodes = new QListBox(GroupContent, "faces by nodes list");
301 myFacesByNodes->setSelectionMode(QListBox::Extended);
302 myFacesByNodes->setMinimumHeight(150);
303 GroupContentLayout->addMultiCellWidget( myFacesByNodes, 2, 4, 0, 0 );
305 AddButton = new QPushButton(GroupContent, "add");
306 AddButton->setText(tr("SMESH_BUT_ADD"));
307 AddButton->setMaximumWidth(85);
308 GroupContentLayout->addWidget( AddButton, 2, 1 );
310 RemoveButton = new QPushButton(GroupContent, "remove");
311 RemoveButton->setText(tr("SMESH_BUT_REMOVE"));
312 RemoveButton->setMaximumWidth(85);
313 GroupContentLayout->addWidget( RemoveButton, 3, 1 );
315 Preview = new QCheckBox( GroupContent, "Preview" );
316 Preview->setText( tr( "SMESH_POLYEDRE_PREVIEW" ) );
317 GroupContentLayout->addWidget( Preview , 5, 0 );
319 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
321 SMESHGUI_CreatePolyhedralVolumeDlgLayout->addWidget( GroupContent, 1, 0 );
323 GroupContent->show();
324 RadioButton1->setChecked( TRUE );
326 mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
328 myHelpFileName = "/files/adding_nodes_and_elements.htm#Adding_polyhedrons";
333 //=================================================================================
334 // function : ~SMESHGUI_CreatePolyhedralVolumeDlg()
335 // purpose : Destroys the object and frees any allocated resources
336 //=================================================================================
337 SMESHGUI_CreatePolyhedralVolumeDlg::~SMESHGUI_CreatePolyhedralVolumeDlg()
339 // no need to delete child widgets, Qt does it all for us
343 static bool busy = false;
344 //=================================================================================
347 //=================================================================================
348 void SMESHGUI_CreatePolyhedralVolumeDlg::Init()
350 myEditCurrentArgument = LineEditElements;
351 mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
356 mySimulation = new SMESH::TPolySimulation( dynamic_cast<SalomeApp_Application*>( mySMESHGUI->application() ) );
358 /* signals and slots connections */
359 connect(buttonOk, SIGNAL( clicked() ), SLOT( ClickOnOk() ) );
360 connect(buttonCancel, SIGNAL( clicked() ), SLOT( ClickOnCancel() ) ) ;
361 connect(buttonApply, SIGNAL( clicked() ), SLOT(ClickOnApply() ) );
362 connect(buttonHelp, SIGNAL(clicked()), SLOT(ClickOnHelp() ) );
364 connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
365 connect(SelectElementsButton, SIGNAL( clicked() ), SLOT( SetEditCurrentArgument() ) ) ;
366 connect(LineEditElements, SIGNAL( textChanged(const QString&) ), SLOT(onTextChange(const QString&)));
368 connect(myFacesByNodes, SIGNAL(selectionChanged()), this, SLOT(onListSelectionChanged()));
369 connect(AddButton, SIGNAL(clicked()), this, SLOT(onAdd()));
370 connect(RemoveButton, SIGNAL(clicked()), this, SLOT(onRemove()));
372 connect( mySMESHGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
373 connect( mySelectionMgr, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
374 connect( Preview, SIGNAL(toggled(bool)), this, SLOT(ClickOnPreview(bool)));
375 /* to close dialog if study change */
376 connect( mySMESHGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
378 this->show() ; /* displays Dialog */
380 ConstructorsClicked(0);
381 SelectionIntoArgument();
385 //=================================================================================
386 // function : ConstructorsClicked()
387 // purpose : Radio button management
388 //=================================================================================
389 void SMESHGUI_CreatePolyhedralVolumeDlg::ConstructorsClicked(int constructorId)
391 //disconnect(mySelectionMgr, 0, this, 0);
394 mySelectionMgr->selectedObjects( io );
396 mySelectionMgr->setSelectedObjects( aList );
397 myEditCurrentArgument->clear();
399 buttonApply->setEnabled(false);
400 buttonOk->setEnabled(false);
401 mySimulation->SetVisibility(false);
403 switch(constructorId)
408 myActor->SetPointRepresentation(true);
411 SMESH::SetPointRepresentation(true);
412 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
413 aViewWindow->SetSelectionMode(NodeSelection);
415 AddButton->setEnabled(false);
416 RemoveButton->setEnabled(false);
417 TextLabelIds->setText( tr( "SMESH_ID_NODES" ) );
418 myFacesByNodesLabel->show();
419 myFacesByNodes->clear();
420 myFacesByNodes->show();
422 RemoveButton->show();
429 myActor->SetPointRepresentation(false);
431 SMESH::SetPointRepresentation(false);
433 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
434 aViewWindow->SetSelectionMode(FaceSelection);
436 TextLabelIds->setText( tr( "SMESH_ID_FACES" ) );
437 myFacesByNodesLabel->hide();
438 myFacesByNodes->hide();
440 RemoveButton->hide();
446 //connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
447 mySelectionMgr->setSelectedObjects( io );
450 //=================================================================================
451 // function : ClickOnPreview()
453 //=================================================================================
454 void SMESHGUI_CreatePolyhedralVolumeDlg::ClickOnPreview(bool theToggled){
455 Preview->setChecked(theToggled);
459 //=================================================================================
460 // function : ClickOnApply()
462 //=================================================================================
463 void SMESHGUI_CreatePolyhedralVolumeDlg::ClickOnApply()
465 if ( myNbOkElements>0 && !mySMESHGUI->isActiveStudyLocked())
467 if(checkEditLine(false) == -1) {return;}
469 if (GetConstructorId() == 0)
471 SMESH::long_array_var anIdsOfNodes = new SMESH::long_array;
472 SMESH::long_array_var aQuantities = new SMESH::long_array;
474 aQuantities->length( myFacesByNodes->count() );
476 TColStd_ListOfInteger aNodesIds;
478 QListBoxItem* anItem;
479 int aNbQuantities = 0;
480 for (anItem = myFacesByNodes->firstItem(); anItem != 0; anItem = anItem->next()) {
481 QStringList anIds = QStringList::split(" ", anItem->text());
482 int aNbNodesInFace = 0;
483 for (QStringList::iterator it = anIds.begin(); it != anIds.end(); ++it, ++aNbNodesInFace)
484 aNodesIds.Append( (*it).toInt() );
486 aQuantities[aNbQuantities++] = aNbNodesInFace;
489 anIdsOfNodes->length(aNodesIds.Extent());
491 int aNbIdsOfNodes = 0;
492 TColStd_ListIteratorOfListOfInteger It;
493 It.Initialize(aNodesIds);
494 for(;It.More();It.Next())
495 anIdsOfNodes[aNbIdsOfNodes++] = It.Value();
498 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
499 QApplication::setOverrideCursor(Qt::waitCursor);
500 aMeshEditor->AddPolyhedralVolume(anIdsOfNodes, aQuantities);
501 QApplication::restoreOverrideCursor();
502 }catch(SALOME::SALOME_Exception& exc){
503 INFOS("Follow exception was cought:\n\t"<<exc.details.text);
504 }catch(std::exception& exc){
505 INFOS("Follow exception was cought:\n\t"<<exc.what());
507 INFOS("Unknown exception was cought !!!");
510 else if (GetConstructorId() == 1)
512 SMESH::long_array_var anIdsOfFaces = new SMESH::long_array;
514 QStringList aListId = QStringList::split( " ", myEditCurrentArgument->text() );
515 anIdsOfFaces->length(aListId.count());
516 for ( int i = 0; i < aListId.count(); i++ )
517 anIdsOfFaces[i] = aListId[i].toInt();
520 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
521 QApplication::setOverrideCursor(Qt::waitCursor);
522 aMeshEditor->AddPolyhedralVolumeByFaces(anIdsOfFaces);
523 QApplication::restoreOverrideCursor();
524 }catch(SALOME::SALOME_Exception& exc){
525 INFOS("Follow exception was cought:\n\t"<<exc.details.text);
526 }catch(std::exception& exc){
527 INFOS("Follow exception was cought:\n\t"<<exc.what());
529 INFOS("Unknown exception was cought !!!");
533 //SALOME_ListIO aList;
534 //mySelectionMgr->setSelectedObjects( aList );
537 unsigned int anEntityMode = myActor->GetEntityMode();
538 myActor->SetEntityMode(SMESH_Actor::eVolumes | anEntityMode);
540 //ConstructorsClicked( GetConstructorId() );
545 //=================================================================================
546 // function : ClickOnOk()
548 //=================================================================================
549 void SMESHGUI_CreatePolyhedralVolumeDlg::ClickOnOk()
551 if(checkEditLine(false) == -1) {return;}
557 //=================================================================================
558 // function : ClickOnCancel()
560 //=================================================================================
561 void SMESHGUI_CreatePolyhedralVolumeDlg::ClickOnCancel()
563 mySelectionMgr->clearFilters();
564 //SALOME_ListIO aList;
565 //mySelectionMgr->setSelectedObjects( aList );
566 SMESH::SetPointRepresentation(false);
567 mySimulation->SetVisibility(false);
568 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
569 aViewWindow->SetSelectionMode( ActorSelection );
570 disconnect( mySelectionMgr, 0, this, 0 );
571 mySMESHGUI->ResetState() ;
575 //=================================================================================
576 // function : ClickOnHelp()
578 //=================================================================================
579 void SMESHGUI_CreatePolyhedralVolumeDlg::ClickOnHelp()
581 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
583 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
585 SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
586 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
587 arg(app->resourceMgr()->stringValue("ExternalBrowser", "application")).arg(myHelpFileName),
588 QObject::tr("BUT_OK"));
592 //=======================================================================
593 //function : onTextChange
595 //=======================================================================
597 void SMESHGUI_CreatePolyhedralVolumeDlg::onTextChange(const QString& theNewText)
600 if (checkEditLine() == -1) return;
603 mySimulation->SetVisibility(false);
605 SMDS_Mesh* aMesh = 0;
607 aMesh = myActor->GetObject()->GetMesh();
609 if (GetConstructorId() == 0)
612 TColStd_MapOfInteger newIndices;
614 QStringList aListId = QStringList::split( " ", theNewText, false);
615 for ( int i = 0; i < aListId.count(); i++ ) {
616 const SMDS_MeshNode * n = aMesh->FindNode( aListId[ i ].toInt() );
618 newIndices.Add(n->GetID());
623 mySelector->AddOrRemoveIndex( myActor->getIO(), newIndices, false );
625 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
626 aViewWindow->highlight( myActor->getIO(), true, true );
628 if ( myNbOkElements>0 && aListId.count()>=3)
629 AddButton->setEnabled(true);
631 AddButton->setEnabled(false);
635 } else if (GetConstructorId() == 1)
638 buttonOk->setEnabled( false );
639 buttonApply->setEnabled( false );
641 // check entered ids of faces and hilight them
644 TColStd_MapOfInteger newIndices;
646 aListId = QStringList::split( " ", theNewText, false);
648 for ( int i = 0; i < aListId.count(); i++ ) {
649 const SMDS_MeshElement * e = aMesh->FindElement( aListId[ i ].toInt() );
651 newIndices.Add(e->GetID());
656 mySelector->AddOrRemoveIndex( myActor->getIO(), newIndices, false );
657 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
658 aViewWindow->highlight( myActor->getIO(), true, true );
660 if ( myNbOkElements ) {
661 if (aListId.count()>1){
662 buttonOk->setEnabled( true );
663 buttonApply->setEnabled( true );
666 buttonOk->setEnabled( false );
667 buttonApply->setEnabled( false );
669 if(aListId.count()>1)
677 //=================================================================================
678 // function : SelectionIntoArgument()
679 // purpose : Called when selection as changed or other case
680 //=================================================================================
681 void SMESHGUI_CreatePolyhedralVolumeDlg::SelectionIntoArgument()
687 if (GetConstructorId() == 1 || myFacesByNodes->count() <= 1)
690 AddButton->setEnabled(false);
691 buttonOk->setEnabled( false );
692 buttonApply->setEnabled( false );
698 myEditCurrentArgument->setText( "" );
700 if ( !GroupButtons->isEnabled() ) // inactive
703 mySimulation->SetVisibility(false);
707 SALOME_ListIO selected;
708 mySelectionMgr->selectedObjects( selected );
709 int nbSel = selected.Extent();
714 myMesh = SMESH::GetMeshByIO( selected.First() );
715 if ( myMesh->_is_nil() )
718 myActor = SMESH::FindActorByObject(myMesh);
722 // get selected nodes/faces
723 QString aString = "";
724 int anbNodes=0,aNbFaces=0;
725 switch(GetConstructorId()){
727 anbNodes = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aString);
729 AddButton->setEnabled(true);
730 else if (anbNodes < 3){
731 AddButton->setEnabled(false);
734 myEditCurrentArgument->setText( aString );
735 if (checkEditLine() == -1) {busy = false;return;}
740 // get selected faces
741 aNbFaces = SMESH::GetNameOfSelectedElements(mySelector, myActor->getIO(), aString);
743 buttonOk->setEnabled( false );
744 buttonApply->setEnabled( false );
746 buttonOk->setEnabled( true );
747 buttonApply->setEnabled( true );
750 myEditCurrentArgument->setText( aString );
751 if (checkEditLine() == -1) {busy = false;return;}
760 if(anbNodes>2 || aNbFaces>1)
764 /*\brief int SMESHGUI_CreatePolyhedralVolumeDlg::checkEditLine()
765 * Checking of indices in edit line.
766 * If incorecct indices in edit line warning message appear and myEditCurrentArgument remove last index.
767 * \retval 1 - if all ok(or no indices in edit line), -1 - if there are incorrect indices.
769 int SMESHGUI_CreatePolyhedralVolumeDlg::checkEditLine(bool checkLast)
771 QString aString = "";
772 SMDS_Mesh* aMesh = 0;
774 if(myMesh->_is_nil()) return 1;
776 myActor = SMESH::FindActorByObject(myMesh);
781 aMesh = myActor->GetObject()->GetMesh();
783 // checking for nodes
784 if (checkLast && myEditCurrentArgument->text().right(1) != QString(" ") ) return 1;
785 QStringList aListId = QStringList::split( " ", myEditCurrentArgument->text() );
786 for ( int i = 0; i < aListId.count(); i++ ){
787 switch (GetConstructorId()){
789 const SMDS_MeshNode * aNode = aMesh->FindNode( aListId[ i ].toInt() );
791 std::string aWarning;
792 aWarning = "The incorrect indices of nodes!";
793 SUIT_MessageBox::warn1(SMESHGUI::desktop(),
794 QObject::tr("SMESH_POLYEDRE_CREATE_ERROR"),
795 QObject::tr(aWarning.c_str()),
796 QObject::tr("SMESH_BUT_OK"));
798 myEditCurrentArgument->clear();
799 myEditCurrentArgument->setText( aString );
806 bool aElemIsOK = true;
807 const SMDS_MeshElement * aElem = aMesh->FindElement( aListId[ i ].toInt() );
814 SMDSAbs_ElementType aType = aMesh->GetElementType( aElem->GetID(),true );
815 if (aType != SMDSAbs_Face){
820 std::string aWarning;
821 aWarning = "The incorrect indices of faces!";
822 SUIT_MessageBox::warn1(SMESHGUI::desktop(),
823 QObject::tr("SMESH_POLYEDRE_CREATE_ERROR"),
824 QObject::tr(aWarning.c_str()),
825 QObject::tr("SMESH_BUT_OK"));
827 myEditCurrentArgument->clear();
828 myEditCurrentArgument->setText( aString );
834 aString += aListId[ i ] + " ";
840 //=======================================================================
841 //function : displaySimulation
843 //=======================================================================
844 void SMESHGUI_CreatePolyhedralVolumeDlg::displaySimulation()
846 if ( (myNbOkElements || AddButton->isEnabled()) && GroupButtons->isEnabled() && myActor)
848 SMESH::TPolySimulation::TVTKIds aVTKIds;
849 vtkIdType aType = VTK_CONVEX_POINT_SET ;
850 SMDS_Mesh* aMesh = 0;
852 aMesh = myActor->GetObject()->GetMesh();
854 if (GetConstructorId() == 0 && aMesh){
855 if (!AddButton->isEnabled()){
856 QListBoxItem* anItem;
857 mySimulation->ResetGrid(true);
858 for (anItem = myFacesByNodes->firstItem(); anItem != 0; anItem = anItem->next()) {
859 QStringList anIds = QStringList::split(" ", anItem->text());
860 SMESH::TPolySimulation::TVTKIds aVTKIds_faces;
861 for (QStringList::iterator it = anIds.begin(); it != anIds.end(); ++it){
862 const SMDS_MeshNode * aNode = aMesh->FindNode( (*it).toInt() );
863 if (!aNode) continue;
864 vtkIdType aId = myActor->GetObject()->GetNodeVTKId( (*it).toInt() ) ;
865 aVTKIds.push_back(aId);
866 aVTKIds_faces.push_back(aId);
868 if(!Preview->isChecked()){
870 mySimulation->SetPosition(myActor, aType, aVTKIds_faces,false);
873 if(myFacesByNodes->count() == 0){
874 mySimulation->SetVisibility(false);
876 mySimulation->SetVisibility(true);
878 if(Preview->isChecked()){
879 mySimulation->SetPosition(myActor, aType, aVTKIds);
882 // add ids from edit line
883 QStringList anEditIds = QStringList::split( " ", myEditCurrentArgument->text(), false);
884 for ( int i = 0; i < anEditIds.count(); i++ )
885 aVTKIds.push_back( myActor->GetObject()->GetNodeVTKId( anEditIds[ i ].toInt() ));
887 mySimulation->SetPosition(myActor, aType, aVTKIds);
889 }else if(GetConstructorId() == 1 && aMesh){
890 QStringList aListId = QStringList::split( " ", myEditCurrentArgument->text(), false);
891 for ( int i = 0; i < aListId.count(); i++ )
893 const SMDS_MeshElement * anElem = aMesh->FindElement( aListId[ i ].toInt() );
894 if ( !anElem ) continue;
895 SMDSAbs_ElementType aFaceType = aMesh->GetElementType( anElem->GetID(),true );
896 if (aFaceType != SMDSAbs_Face) continue;
898 SMDS_ElemIteratorPtr anIter = anElem->nodesIterator();
899 SMESH::TPolySimulation::TVTKIds aVTKIds_faces;
900 while( anIter->more() )
901 if ( const SMDS_MeshNode* aNode = (SMDS_MeshNode*)anIter->next() ){
902 vtkIdType aId = myActor->GetObject()->GetNodeVTKId( aNode->GetID() ) ;
903 aVTKIds.push_back(aId);
904 aVTKIds_faces.push_back(aId);
906 if(!Preview->isChecked()){
908 mySimulation->SetPosition(myActor, aType, aVTKIds_faces);
911 if(Preview->isChecked())
912 mySimulation->SetPosition(myActor, aType, aVTKIds);
918 //=================================================================================
919 // function : SetEditCurrentArgument()
921 //=================================================================================
922 void SMESHGUI_CreatePolyhedralVolumeDlg::SetEditCurrentArgument()
924 QPushButton* send = (QPushButton*)sender();
925 if(send == SelectElementsButton) {
926 LineEditElements->setFocus() ;
927 myEditCurrentArgument = LineEditElements;
929 SelectionIntoArgument();
932 //=================================================================================
933 // function : DeactivateActiveDialog()
935 //=================================================================================
936 void SMESHGUI_CreatePolyhedralVolumeDlg::DeactivateActiveDialog()
938 if ( GroupConstructors->isEnabled() ) {
939 GroupConstructors->setEnabled(false) ;
940 GroupContent->setEnabled(false) ;
941 GroupButtons->setEnabled(false) ;
942 mySimulation->SetVisibility(false);
943 mySMESHGUI->ResetState() ;
944 mySMESHGUI->SetActiveDialogBox(0) ;
949 //=================================================================================
950 // function : ActivateThisDialog()
952 //=================================================================================
953 void SMESHGUI_CreatePolyhedralVolumeDlg::ActivateThisDialog()
955 /* Emit a signal to deactivate the active dialog */
956 mySMESHGUI->EmitSignalDeactivateDialog() ;
957 GroupConstructors->setEnabled(true) ;
958 GroupContent->setEnabled(true) ;
959 GroupButtons->setEnabled(true) ;
961 mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
963 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
964 aViewWindow->SetSelectionMode( FaceSelection );
965 SelectionIntoArgument();
969 //=================================================================================
970 // function : enterEvent()
972 //=================================================================================
973 void SMESHGUI_CreatePolyhedralVolumeDlg::enterEvent(QEvent* e)
975 if ( GroupConstructors->isEnabled() )
977 ActivateThisDialog() ;
981 //=================================================================================
982 // function : closeEvent()
984 //=================================================================================
985 void SMESHGUI_CreatePolyhedralVolumeDlg::closeEvent( QCloseEvent* e )
987 /* same than click on cancel button */
988 this->ClickOnCancel() ;
992 //=======================================================================
993 //function : hideEvent
994 //purpose : caused by ESC key
995 //=======================================================================
997 void SMESHGUI_CreatePolyhedralVolumeDlg::hideEvent ( QHideEvent * e )
999 if ( !isMinimized() )
1004 //=================================================================================
1005 // function : GetConstructorId()
1007 //=================================================================================
1008 int SMESHGUI_CreatePolyhedralVolumeDlg::GetConstructorId()
1010 if ( GroupConstructors != NULL && GroupConstructors->selected() != NULL )
1011 return GroupConstructors->id( GroupConstructors->selected() );
1015 //=================================================================================
1016 // function : onAdd()
1018 //=================================================================================
1019 void SMESHGUI_CreatePolyhedralVolumeDlg::onAdd()
1021 SALOME_ListIO selected;
1022 mySelectionMgr->selectedObjects( selected );
1023 int aNbSel = selected.Extent();
1024 if (aNbSel == 0 || !myActor || myMesh->_is_nil()) return;
1026 if (this->checkEditLine(false) == -1) return;
1029 if ( !(myEditCurrentArgument->text().isEmpty()) )
1031 myFacesByNodes->insertItem(myEditCurrentArgument->text());
1032 //myFacesByNodes->setSelected(myFacesByNodes->count() - 1, true);
1034 myEditCurrentArgument->clear();
1035 AddButton->setEnabled(false);
1036 buttonOk->setEnabled( true );
1037 if(myFacesByNodes->count()>1) buttonApply->setEnabled( true );
1040 onListSelectionChanged();
1041 displaySimulation();
1044 //=================================================================================
1045 // function : onRemove()
1047 //=================================================================================
1048 void SMESHGUI_CreatePolyhedralVolumeDlg::onRemove()
1051 for (int i = myFacesByNodes->count(); i > 0; i--) {
1052 if (myFacesByNodes->isSelected(i-1)) {
1053 myFacesByNodes->removeItem(i-1);
1057 if (myFacesByNodes->count() < 1){
1058 RemoveButton->setEnabled(false);
1059 buttonOk->setEnabled( false );
1060 buttonApply->setEnabled( false );
1062 else if (myFacesByNodes->count() == 1){
1063 buttonOk->setEnabled( false );
1064 buttonApply->setEnabled( false );
1067 displaySimulation();
1070 //=================================================================================
1071 // function : onListSelectionChanged()
1072 // purpose : Called when selection in element list is changed
1073 //=================================================================================
1074 void SMESHGUI_CreatePolyhedralVolumeDlg::onListSelectionChanged()
1076 if (busy || !myActor) return;
1078 bool isSelected=false;
1079 SALOME_ListIO aList;
1080 mySelectionMgr->setSelectedObjects( aList );
1081 TColStd_MapOfInteger aIndexes;
1082 QListBoxItem* anItem;
1083 for (anItem = myFacesByNodes->firstItem(); anItem != 0; anItem = anItem->next()) {
1084 if (anItem->isSelected()) {
1086 QStringList anIds = QStringList::split(" ", anItem->text());
1087 for (QStringList::iterator it = anIds.begin(); it != anIds.end(); ++it)
1088 aIndexes.Add((*it).toInt());
1091 if(isSelected) RemoveButton->setEnabled(true);
1092 else RemoveButton->setEnabled(false);
1093 mySelector->AddOrRemoveIndex(myActor->getIO(), aIndexes, true );
1094 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1095 aViewWindow->highlight( myActor->getIO(), true, true );
1096 mySelectionMgr->clearFilters();
1097 aList.Append( myActor->getIO() );
1098 mySelectionMgr->setSelectedObjects( aList );
1103 //=================================================================================
1104 // function : keyPressEvent()
1106 //=================================================================================
1107 void SMESHGUI_CreatePolyhedralVolumeDlg::keyPressEvent( QKeyEvent* e )
1109 QDialog::keyPressEvent( e );
1110 if ( e->isAccepted() )
1113 if ( e->key() == Key_F1 )