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
22 // File : SMESHGUI_CreatePolyhedralVolumeDlg.cxx
23 // Author : Michael ZORIN, Open CASCADE S.A.S.
27 #include "SMESHGUI_CreatePolyhedralVolumeDlg.h"
30 #include "SMESHGUI_Utils.h"
31 #include "SMESHGUI_VTKUtils.h"
32 #include "SMESHGUI_MeshUtils.h"
33 #include "SMESHGUI_IdValidator.h"
35 #include <SMESH_Actor.h>
36 #include <SMESH_ActorUtils.h>
37 #include <SMDS_Mesh.hxx>
39 // SALOME GUI includes
40 #include <SUIT_Desktop.h>
41 #include <SUIT_ResourceMgr.h>
42 #include <SUIT_Session.h>
43 #include <SUIT_MessageBox.h>
44 #include <SUIT_ViewManager.h>
46 #include <SalomeApp_Application.h>
47 #include <LightApp_SelectionMgr.h>
49 #include <SVTK_ViewWindow.h>
52 #include <TColStd_ListOfInteger.hxx>
53 #include <TColStd_ListIteratorOfListOfInteger.hxx>
57 #include <vtkIdList.h>
58 #include <vtkUnstructuredGrid.h>
59 #include <vtkDataSetMapper.h>
60 #include <vtkProperty.h>
63 #include <QApplication>
64 #include <QButtonGroup>
68 #include <QPushButton>
69 #include <QRadioButton>
71 #include <QHBoxLayout>
72 #include <QVBoxLayout>
73 #include <QGridLayout>
74 #include <QListWidget>
78 #include <SALOMEconfig.h>
79 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
88 SVTK_ViewWindow* myViewWindow;
90 SALOME_Actor *myPreviewActor;
91 vtkDataSetMapper* myMapper;
92 vtkUnstructuredGrid* myGrid;
96 TPolySimulation(SalomeApp_Application* app)
98 SUIT_ViewManager* mgr = app->activeViewManager();
99 myViewWindow = mgr ? dynamic_cast<SVTK_ViewWindow*>( mgr->getActiveView() ) : NULL;
101 myGrid = vtkUnstructuredGrid::New();
103 // Create and display actor
104 myMapper = vtkDataSetMapper::New();
105 myMapper->SetInput( myGrid );
107 myPreviewActor = SALOME_Actor::New();
108 myPreviewActor->PickableOff();
109 myPreviewActor->VisibilityOff();
110 myPreviewActor->SetMapper( myMapper );
111 myPreviewActor->SetRepresentation( 3 );
113 vtkFloatingPointType anRGB[3];
114 vtkProperty* aProp = vtkProperty::New();
115 GetColor( "SMESH", "selection_element_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 170, 255 ) );
116 aProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
117 myPreviewActor->SetProperty( aProp );
118 vtkFloatingPointType aFactor,aUnits;
119 myPreviewActor->SetResolveCoincidentTopology(true);
120 myPreviewActor->GetPolygonOffsetParameters(aFactor,aUnits);
121 myPreviewActor->SetPolygonOffsetParameters(aFactor,0.2*aUnits);
124 myViewWindow->AddActor( myPreviewActor );
129 typedef std::vector<vtkIdType> TVTKIds;
130 void SetPosition(SMESH_Actor* theActor,
132 const TVTKIds& theIds,
135 vtkUnstructuredGrid *aGrid = theActor->GetUnstructuredGrid();
136 myGrid->SetPoints(aGrid->GetPoints());
140 vtkIdList *anIds = vtkIdList::New();
142 for (int i = 0, iEnd = theIds.size(); i < iEnd; i++)
143 anIds->InsertId(i,theIds[i]);
145 myGrid->InsertNextCell(theType,anIds);
146 if(theIds.size()!=0){
147 myGrid->InsertNextCell(theType,anIds);
157 void ResetGrid(bool theReset=true){
158 if (theReset) myGrid->Reset();
161 void SetVisibility(bool theVisibility){
162 myPreviewActor->SetVisibility(theVisibility);
163 RepaintCurrentView();
169 myViewWindow->RemoveActor(myPreviewActor);
171 myPreviewActor->Delete();
173 myMapper->RemoveAllInputs();
182 //=================================================================================
183 // class : SMESHGUI_CreatePolyhedralVolumeDlgDlg()
185 //=================================================================================
186 SMESHGUI_CreatePolyhedralVolumeDlg::SMESHGUI_CreatePolyhedralVolumeDlg( SMESHGUI* theModule )
187 : QDialog( SMESH::GetDesktop( theModule ) ),
188 mySMESHGUI( theModule ),
189 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
191 QPixmap image0( SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap( "SMESH",tr("ICON_SELECT")));
194 setAttribute(Qt::WA_DeleteOnClose, true);
195 setWindowTitle( tr( "SMESH_CREATE_POLYHEDRAL_VOLUME_TITLE" ) );
196 setSizeGripEnabled( true );
198 QVBoxLayout* topLayout = new QVBoxLayout( this );
199 topLayout->setSpacing( SPACING );
200 topLayout->setMargin( MARGIN );
202 /***************************************************************/
203 ConstructorsBox = new QGroupBox(tr( "SMESH_ELEMENTS_TYPE" ), this);
204 GroupConstructors = new QButtonGroup(this);
205 QHBoxLayout* ConstructorsBoxLayout = new QHBoxLayout( ConstructorsBox );
206 ConstructorsBoxLayout->setSpacing( SPACING );
207 ConstructorsBoxLayout->setMargin( MARGIN );
209 RadioButton1 = new QRadioButton( tr( "MESH_NODE" ), ConstructorsBox );
210 RadioButton2 = new QRadioButton( tr( "SMESH_FACE" ), ConstructorsBox );
212 ConstructorsBoxLayout->addWidget( RadioButton1 );
213 ConstructorsBoxLayout->addWidget( RadioButton2 );
214 GroupConstructors->addButton(RadioButton1, 0);
215 GroupConstructors->addButton(RadioButton2, 1);
217 /***************************************************************/
218 GroupContent = new QGroupBox( tr( "SMESH_CONTENT" ), this );
219 QGridLayout* GroupContentLayout = new QGridLayout( GroupContent );
220 GroupContentLayout->setSpacing( SPACING );
221 GroupContentLayout->setMargin( MARGIN );
223 TextLabelIds = new QLabel( tr( "SMESH_ID_NODES" ), GroupContent );
224 SelectElementsButton = new QPushButton( GroupContent );
225 SelectElementsButton->setIcon( image0 );
226 LineEditElements = new QLineEdit( GroupContent );
227 LineEditElements->setValidator( new SMESHGUI_IdValidator( this ) );
229 myFacesByNodesLabel = new QLabel( tr( "FACES_BY_NODES" ), GroupContent );
230 myFacesByNodes = new QListWidget( GroupContent);
231 myFacesByNodes->setSelectionMode( QListWidget::ExtendedSelection );
232 myFacesByNodes->setMinimumHeight( 150);
234 AddButton = new QPushButton( tr( "SMESH_BUT_ADD" ), GroupContent );
235 RemoveButton = new QPushButton( tr( "SMESH_BUT_REMOVE" ), GroupContent );
237 Preview = new QCheckBox( tr( "SMESH_POLYEDRE_PREVIEW" ), GroupContent );
239 GroupContentLayout->addWidget( TextLabelIds, 0, 0 );
240 GroupContentLayout->addWidget( SelectElementsButton, 0, 1 );
241 GroupContentLayout->addWidget( LineEditElements, 0, 2, 1, 2 );
242 GroupContentLayout->addWidget( myFacesByNodesLabel, 1, 0 );
243 GroupContentLayout->addWidget( myFacesByNodes, 2, 0, 3, 3 );
244 GroupContentLayout->addWidget( AddButton, 2, 3 );
245 GroupContentLayout->addWidget( RemoveButton, 3, 3 );
246 GroupContentLayout->addWidget( Preview, 5, 0, 1, 4 );
248 /***************************************************************/
249 GroupButtons = new QGroupBox( this );
250 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout( GroupButtons );
251 GroupButtonsLayout->setSpacing( SPACING );
252 GroupButtonsLayout->setMargin( MARGIN );
254 buttonOk = new QPushButton( tr( "SMESH_BUT_OK" ), GroupButtons );
255 buttonOk->setAutoDefault( true );
256 buttonOk->setDefault( true );
257 buttonApply = new QPushButton( tr( "SMESH_BUT_APPLY" ), GroupButtons );
258 buttonApply->setAutoDefault( true );
259 buttonCancel = new QPushButton( tr( "SMESH_BUT_CLOSE" ), GroupButtons );
260 buttonCancel->setAutoDefault( true );
261 buttonHelp = new QPushButton( tr("SMESH_BUT_HELP" ), GroupButtons );
262 buttonHelp->setAutoDefault(true);
264 GroupButtonsLayout->addWidget( buttonOk );
265 GroupButtonsLayout->addSpacing( 10 );
266 GroupButtonsLayout->addWidget( buttonApply );
267 GroupButtonsLayout->addSpacing( 10 );
268 GroupButtonsLayout->addStretch();
269 GroupButtonsLayout->addWidget( buttonCancel );
270 GroupButtonsLayout->addWidget( buttonHelp);
272 /***************************************************************/
273 topLayout->addWidget( ConstructorsBox );
274 topLayout->addWidget( GroupContent );
275 topLayout->addWidget( GroupButtons );
277 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
279 RadioButton1->setChecked( true );
281 mySMESHGUI->SetActiveDialogBox( (QDialog*)this );
283 myHelpFileName = "adding_nodes_and_elements_page.html#adding_polyhedrons_anchor";
288 //=================================================================================
289 // function : ~SMESHGUI_CreatePolyhedralVolumeDlg()
290 // purpose : Destroys the object and frees any allocated resources
291 //=================================================================================
292 SMESHGUI_CreatePolyhedralVolumeDlg::~SMESHGUI_CreatePolyhedralVolumeDlg()
297 static bool busy = false;
299 //=================================================================================
302 //=================================================================================
303 void SMESHGUI_CreatePolyhedralVolumeDlg::Init()
305 myEditCurrentArgument = LineEditElements;
306 mySMESHGUI->SetActiveDialogBox( (QDialog*)this );
311 mySimulation = new SMESH::TPolySimulation( dynamic_cast<SalomeApp_Application*>( mySMESHGUI->application() ) );
313 /* signals and slots connections */
314 connect(buttonOk, SIGNAL( clicked() ), SLOT( ClickOnOk() ) );
315 connect(buttonCancel, SIGNAL( clicked() ), SLOT( ClickOnCancel() ) );
316 connect(buttonApply, SIGNAL( clicked() ), SLOT( ClickOnApply() ) );
317 connect(buttonHelp, SIGNAL( clicked() ), SLOT( ClickOnHelp() ) );
319 connect(GroupConstructors, SIGNAL(buttonClicked(int) ), SLOT( ConstructorsClicked(int) ) );
320 connect(SelectElementsButton, SIGNAL( clicked() ), SLOT( SetEditCurrentArgument() ) );
321 connect(LineEditElements, SIGNAL( textChanged(const QString&) ), SLOT(onTextChange(const QString&)));
323 connect(myFacesByNodes, SIGNAL(selectionChanged()), this, SLOT(onListSelectionChanged()));
324 connect(AddButton, SIGNAL(clicked()), this, SLOT(onAdd()));
325 connect(RemoveButton, SIGNAL(clicked()), this, SLOT(onRemove()));
327 connect( mySMESHGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) );
328 connect( mySelectionMgr, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
329 connect( Preview, SIGNAL(toggled(bool)), this, SLOT(ClickOnPreview(bool)));
330 /* to close dialog if study change */
331 connect( mySMESHGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) );
333 ConstructorsClicked(0);
334 SelectionIntoArgument();
338 //=================================================================================
339 // function : ConstructorsClicked()
340 // purpose : Radio button management
341 //=================================================================================
342 void SMESHGUI_CreatePolyhedralVolumeDlg::ConstructorsClicked(int constructorId)
344 //disconnect(mySelectionMgr, 0, this, 0);
347 mySelectionMgr->selectedObjects( io );
349 mySelectionMgr->setSelectedObjects( aList );
350 myEditCurrentArgument->clear();
352 buttonApply->setEnabled(false);
353 buttonOk->setEnabled(false);
354 mySimulation->SetVisibility(false);
356 switch(constructorId)
361 myActor->SetPointRepresentation(true);
364 SMESH::SetPointRepresentation(true);
365 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
366 aViewWindow->SetSelectionMode(NodeSelection);
368 AddButton->setEnabled(false);
369 RemoveButton->setEnabled(false);
370 TextLabelIds->setText( tr( "SMESH_ID_NODES" ) );
371 myFacesByNodesLabel->show();
372 myFacesByNodes->clear();
373 myFacesByNodes->show();
375 RemoveButton->show();
382 myActor->SetPointRepresentation(false);
384 SMESH::SetPointRepresentation(false);
386 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
387 aViewWindow->SetSelectionMode(FaceSelection);
389 TextLabelIds->setText( tr( "SMESH_ID_FACES" ) );
390 myFacesByNodesLabel->hide();
391 myFacesByNodes->hide();
393 RemoveButton->hide();
399 //connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
400 mySelectionMgr->setSelectedObjects( io );
402 QApplication::instance()->processEvents();
404 resize( minimumSize() );
407 //=================================================================================
408 // function : ClickOnPreview()
410 //=================================================================================
411 void SMESHGUI_CreatePolyhedralVolumeDlg::ClickOnPreview(bool theToggled){
412 Preview->setChecked(theToggled);
416 //=================================================================================
417 // function : ClickOnApply()
419 //=================================================================================
420 void SMESHGUI_CreatePolyhedralVolumeDlg::ClickOnApply()
422 if ( myNbOkElements>0 && !mySMESHGUI->isActiveStudyLocked())
424 if(checkEditLine(false) == -1) {return;}
426 if (GetConstructorId() == 0)
428 SMESH::long_array_var anIdsOfNodes = new SMESH::long_array;
429 SMESH::long_array_var aQuantities = new SMESH::long_array;
431 aQuantities->length( myFacesByNodes->count() );
433 TColStd_ListOfInteger aNodesIds;
435 int aNbQuantities = 0;
436 for (int i = 0; i < myFacesByNodes->count(); i++ ) {
437 QStringList anIds = myFacesByNodes->item(i)->text().split( " ", QString::SkipEmptyParts );
438 for (QStringList::iterator it = anIds.begin(); it != anIds.end(); ++it)
439 aNodesIds.Append( (*it).toInt() );
441 aQuantities[aNbQuantities++] = anIds.count();
444 anIdsOfNodes->length(aNodesIds.Extent());
446 int aNbIdsOfNodes = 0;
447 TColStd_ListIteratorOfListOfInteger It;
448 It.Initialize(aNodesIds);
449 for( ;It.More();It.Next())
450 anIdsOfNodes[aNbIdsOfNodes++] = It.Value();
453 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
454 QApplication::setOverrideCursor(Qt::WaitCursor);
455 aMeshEditor->AddPolyhedralVolume(anIdsOfNodes, aQuantities);
456 QApplication::restoreOverrideCursor();
457 }catch(SALOME::SALOME_Exception& exc){
458 INFOS("Follow exception was cought:\n\t"<<exc.details.text);
459 }catch(std::exception& exc){
460 INFOS("Follow exception was cought:\n\t"<<exc.what());
462 INFOS("Unknown exception was cought !!!");
465 else if (GetConstructorId() == 1)
467 SMESH::long_array_var anIdsOfFaces = new SMESH::long_array;
469 QStringList aListId = myEditCurrentArgument->text().split( " ", QString::SkipEmptyParts );
470 anIdsOfFaces->length(aListId.count());
471 for ( int i = 0; i < aListId.count(); i++ )
472 anIdsOfFaces[i] = aListId[i].toInt();
475 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
476 QApplication::setOverrideCursor(Qt::WaitCursor);
477 aMeshEditor->AddPolyhedralVolumeByFaces(anIdsOfFaces);
478 QApplication::restoreOverrideCursor();
479 }catch(SALOME::SALOME_Exception& exc){
480 INFOS("Follow exception was cought:\n\t"<<exc.details.text);
481 }catch(std::exception& exc){
482 INFOS("Follow exception was cought:\n\t"<<exc.what());
484 INFOS("Unknown exception was cought !!!");
488 //SALOME_ListIO aList;
489 //mySelectionMgr->setSelectedObjects( aList );
492 unsigned int anEntityMode = myActor->GetEntityMode();
493 myActor->SetEntityMode(SMESH_Actor::eVolumes | anEntityMode);
495 //ConstructorsClicked( GetConstructorId() );
500 //=================================================================================
501 // function : ClickOnOk()
503 //=================================================================================
504 void SMESHGUI_CreatePolyhedralVolumeDlg::ClickOnOk()
506 if(checkEditLine(false) == -1) {return;}
512 //=================================================================================
513 // function : ClickOnCancel()
515 //=================================================================================
516 void SMESHGUI_CreatePolyhedralVolumeDlg::ClickOnCancel()
518 mySelectionMgr->clearFilters();
519 //SALOME_ListIO aList;
520 //mySelectionMgr->setSelectedObjects( aList );
521 SMESH::SetPointRepresentation(false);
522 mySimulation->SetVisibility(false);
523 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
524 aViewWindow->SetSelectionMode( ActorSelection );
525 disconnect( mySelectionMgr, 0, this, 0 );
526 mySMESHGUI->ResetState();
530 //=================================================================================
531 // function : ClickOnHelp()
533 //=================================================================================
534 void SMESHGUI_CreatePolyhedralVolumeDlg::ClickOnHelp()
536 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
538 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
542 platform = "winapplication";
544 platform = "application";
546 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
547 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
548 arg(app->resourceMgr()->stringValue("ExternalBrowser",
550 arg(myHelpFileName));
554 //=======================================================================
555 //function : onTextChange
557 //=======================================================================
559 void SMESHGUI_CreatePolyhedralVolumeDlg::onTextChange(const QString& theNewText)
562 if (checkEditLine() == -1) return;
565 mySimulation->SetVisibility(false);
567 SMDS_Mesh* aMesh = 0;
569 aMesh = myActor->GetObject()->GetMesh();
571 if (GetConstructorId() == 0)
574 TColStd_MapOfInteger newIndices;
576 QStringList aListId = theNewText.split( " ", QString::SkipEmptyParts );
577 for ( int i = 0; i < aListId.count(); i++ ) {
578 const SMDS_MeshNode * n = aMesh->FindNode( aListId[ i ].toInt() );
580 newIndices.Add(n->GetID());
585 mySelector->AddOrRemoveIndex( myActor->getIO(), newIndices, false );
587 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
588 aViewWindow->highlight( myActor->getIO(), true, true );
590 if ( myNbOkElements>0 && aListId.count()>=3)
591 AddButton->setEnabled(true);
593 AddButton->setEnabled(false);
597 } else if (GetConstructorId() == 1)
600 buttonOk->setEnabled( false );
601 buttonApply->setEnabled( false );
603 // check entered ids of faces and hilight them
606 TColStd_MapOfInteger newIndices;
608 aListId = theNewText.split( " ", QString::SkipEmptyParts );
610 for ( int i = 0; i < aListId.count(); i++ ) {
611 const SMDS_MeshElement * e = aMesh->FindElement( aListId[ i ].toInt() );
613 newIndices.Add(e->GetID());
618 mySelector->AddOrRemoveIndex( myActor->getIO(), newIndices, false );
619 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
620 aViewWindow->highlight( myActor->getIO(), true, true );
622 if ( myNbOkElements ) {
623 if (aListId.count()>1){
624 buttonOk->setEnabled( true );
625 buttonApply->setEnabled( true );
628 buttonOk->setEnabled( false );
629 buttonApply->setEnabled( false );
631 if(aListId.count()>1)
639 //=================================================================================
640 // function : SelectionIntoArgument()
641 // purpose : Called when selection as changed or other case
642 //=================================================================================
643 void SMESHGUI_CreatePolyhedralVolumeDlg::SelectionIntoArgument()
649 if (GetConstructorId() == 1 || myFacesByNodes->count() <= 1)
652 AddButton->setEnabled(false);
653 buttonOk->setEnabled( false );
654 buttonApply->setEnabled( false );
660 myEditCurrentArgument->setText( "" );
662 if ( !GroupButtons->isEnabled() ) // inactive
665 mySimulation->SetVisibility(false);
669 SALOME_ListIO selected;
670 mySelectionMgr->selectedObjects( selected );
671 int nbSel = selected.Extent();
676 myMesh = SMESH::GetMeshByIO( selected.First() );
677 if ( myMesh->_is_nil() )
680 myActor = SMESH::FindActorByObject(myMesh);
684 // get selected nodes/faces
685 QString aString = "";
686 int anbNodes=0,aNbFaces=0;
687 switch(GetConstructorId()){
689 anbNodes = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aString);
691 AddButton->setEnabled(true);
692 else if (anbNodes < 3){
693 AddButton->setEnabled(false);
696 myEditCurrentArgument->setText( aString );
697 if (checkEditLine() == -1) {busy = false;return;}
702 // get selected faces
703 aNbFaces = SMESH::GetNameOfSelectedElements(mySelector, myActor->getIO(), aString);
705 buttonOk->setEnabled( false );
706 buttonApply->setEnabled( false );
708 buttonOk->setEnabled( true );
709 buttonApply->setEnabled( true );
712 myEditCurrentArgument->setText( aString );
713 if (checkEditLine() == -1) {busy = false;return;}
722 if(anbNodes>2 || aNbFaces>1)
726 /*\brief int SMESHGUI_CreatePolyhedralVolumeDlg::checkEditLine()
727 * Checking of indices in edit line.
728 * If incorecct indices in edit line warning message appear and myEditCurrentArgument remove last index.
729 * \retval 1 - if all ok(or no indices in edit line), -1 - if there are incorrect indices.
731 int SMESHGUI_CreatePolyhedralVolumeDlg::checkEditLine(bool checkLast)
733 QString aString = "";
734 SMDS_Mesh* aMesh = 0;
736 if(myMesh->_is_nil()) return 1;
738 myActor = SMESH::FindActorByObject(myMesh);
743 aMesh = myActor->GetObject()->GetMesh();
745 // checking for nodes
746 if (checkLast && myEditCurrentArgument->text().right(1) != QString(" ") ) return 1;
747 QStringList aListId = myEditCurrentArgument->text().split( " ", QString::SkipEmptyParts );
748 for ( int i = 0; i < aListId.count(); i++ ){
749 switch (GetConstructorId()){
751 const SMDS_MeshNode * aNode = aMesh->FindNode( aListId[ i ].toInt() );
753 SUIT_MessageBox::warning(this,
754 tr("SMESH_POLYEDRE_CREATE_ERROR"),
755 tr("The incorrect indices of nodes!"));
757 myEditCurrentArgument->clear();
758 myEditCurrentArgument->setText( aString );
765 bool aElemIsOK = true;
766 const SMDS_MeshElement * aElem = aMesh->FindElement( aListId[ i ].toInt() );
773 SMDSAbs_ElementType aType = aMesh->GetElementType( aElem->GetID(),true );
774 if (aType != SMDSAbs_Face){
779 SUIT_MessageBox::warning(this,
780 tr("SMESH_POLYEDRE_CREATE_ERROR"),
781 tr("The incorrect indices of faces!"));
783 myEditCurrentArgument->clear();
784 myEditCurrentArgument->setText( aString );
790 aString += aListId[ i ] + " ";
796 //=======================================================================
797 //function : displaySimulation
799 //=======================================================================
800 void SMESHGUI_CreatePolyhedralVolumeDlg::displaySimulation()
802 if ( (myNbOkElements || AddButton->isEnabled()) && GroupButtons->isEnabled() && myActor)
804 SMESH::TPolySimulation::TVTKIds aVTKIds;
805 vtkIdType aType = VTK_CONVEX_POINT_SET;
806 SMDS_Mesh* aMesh = 0;
808 aMesh = myActor->GetObject()->GetMesh();
810 if (GetConstructorId() == 0 && aMesh){
811 if (!AddButton->isEnabled()){
812 mySimulation->ResetGrid(true);
813 for (int i = 0; i < myFacesByNodes->count(); i++) {
814 QStringList anIds = myFacesByNodes->item(i)->text().split( " ", QString::SkipEmptyParts );
815 SMESH::TPolySimulation::TVTKIds aVTKIds_faces;
816 for (QStringList::iterator it = anIds.begin(); it != anIds.end(); ++it){
817 const SMDS_MeshNode* aNode = aMesh->FindNode( (*it).toInt() );
818 if (!aNode) continue;
819 vtkIdType aId = myActor->GetObject()->GetNodeVTKId( (*it).toInt() );
820 aVTKIds.push_back(aId);
821 aVTKIds_faces.push_back(aId);
823 if(!Preview->isChecked()){
825 mySimulation->SetPosition(myActor, aType, aVTKIds_faces,false);
828 if(myFacesByNodes->count() == 0){
829 mySimulation->SetVisibility(false);
831 mySimulation->SetVisibility(true);
833 if(Preview->isChecked()){
834 mySimulation->SetPosition(myActor, aType, aVTKIds);
837 // add ids from edit line
838 QStringList anEditIds = myEditCurrentArgument->text().split( " ", QString::SkipEmptyParts );
839 for ( int i = 0; i < anEditIds.count(); i++ )
840 aVTKIds.push_back( myActor->GetObject()->GetNodeVTKId( anEditIds[ i ].toInt() ));
842 mySimulation->SetPosition(myActor, aType, aVTKIds);
844 }else if(GetConstructorId() == 1 && aMesh){
845 QStringList aListId = myEditCurrentArgument->text().split( " ", QString::SkipEmptyParts );
846 for ( int i = 0; i < aListId.count(); i++ )
848 const SMDS_MeshElement * anElem = aMesh->FindElement( aListId[ i ].toInt() );
849 if ( !anElem ) continue;
850 SMDSAbs_ElementType aFaceType = aMesh->GetElementType( anElem->GetID(),true );
851 if (aFaceType != SMDSAbs_Face) continue;
853 SMDS_ElemIteratorPtr anIter = anElem->nodesIterator();
854 SMESH::TPolySimulation::TVTKIds aVTKIds_faces;
855 while( anIter->more() )
856 if ( const SMDS_MeshNode* aNode = (SMDS_MeshNode*)anIter->next() ){
857 vtkIdType aId = myActor->GetObject()->GetNodeVTKId( aNode->GetID() );
858 aVTKIds.push_back(aId);
859 aVTKIds_faces.push_back(aId);
861 if(!Preview->isChecked()){
863 mySimulation->SetPosition(myActor, aType, aVTKIds_faces);
866 if(Preview->isChecked())
867 mySimulation->SetPosition(myActor, aType, aVTKIds);
873 //=================================================================================
874 // function : SetEditCurrentArgument()
876 //=================================================================================
877 void SMESHGUI_CreatePolyhedralVolumeDlg::SetEditCurrentArgument()
879 QPushButton* send = (QPushButton*)sender();
880 if(send == SelectElementsButton) {
881 LineEditElements->setFocus();
882 myEditCurrentArgument = LineEditElements;
884 SelectionIntoArgument();
887 //=================================================================================
888 // function : DeactivateActiveDialog()
890 //=================================================================================
891 void SMESHGUI_CreatePolyhedralVolumeDlg::DeactivateActiveDialog()
893 if ( ConstructorsBox->isEnabled() ) {
894 ConstructorsBox->setEnabled(false);
895 GroupContent->setEnabled(false);
896 GroupButtons->setEnabled(false);
897 mySimulation->SetVisibility(false);
898 mySMESHGUI->ResetState();
899 mySMESHGUI->SetActiveDialogBox(0);
904 //=================================================================================
905 // function : ActivateThisDialog()
907 //=================================================================================
908 void SMESHGUI_CreatePolyhedralVolumeDlg::ActivateThisDialog()
910 /* Emit a signal to deactivate the active dialog */
911 mySMESHGUI->EmitSignalDeactivateDialog();
912 ConstructorsBox->setEnabled(true);
913 GroupContent->setEnabled(true);
914 GroupButtons->setEnabled(true);
916 mySMESHGUI->SetActiveDialogBox( (QDialog*)this );
918 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
919 aViewWindow->SetSelectionMode( FaceSelection );
920 SelectionIntoArgument();
924 //=================================================================================
925 // function : enterEvent()
927 //=================================================================================
928 void SMESHGUI_CreatePolyhedralVolumeDlg::enterEvent(QEvent* e)
930 if ( ConstructorsBox->isEnabled() )
932 ActivateThisDialog();
936 //=================================================================================
937 // function : closeEvent()
939 //=================================================================================
940 void SMESHGUI_CreatePolyhedralVolumeDlg::closeEvent( QCloseEvent* e )
942 /* same than click on cancel button */
947 //=======================================================================
948 //function : hideEvent
949 //purpose : caused by ESC key
950 //=======================================================================
952 void SMESHGUI_CreatePolyhedralVolumeDlg::hideEvent ( QHideEvent * e )
954 if ( !isMinimized() )
959 //=================================================================================
960 // function : GetConstructorId()
962 //=================================================================================
963 int SMESHGUI_CreatePolyhedralVolumeDlg::GetConstructorId()
965 return GroupConstructors->checkedId();
968 //=================================================================================
969 // function : onAdd()
971 //=================================================================================
972 void SMESHGUI_CreatePolyhedralVolumeDlg::onAdd()
974 SALOME_ListIO selected;
975 mySelectionMgr->selectedObjects( selected );
976 int aNbSel = selected.Extent();
977 if (aNbSel == 0 || !myActor || myMesh->_is_nil()) return;
979 if (checkEditLine(false) == -1) return;
982 if ( !(myEditCurrentArgument->text().isEmpty()) )
984 myFacesByNodes->addItem(myEditCurrentArgument->text());
985 //myFacesByNodes->setSelected(myFacesByNodes->count() - 1, true);
987 myEditCurrentArgument->clear();
988 AddButton->setEnabled(false);
989 buttonOk->setEnabled( true );
990 if(myFacesByNodes->count()>1) buttonApply->setEnabled( true );
993 onListSelectionChanged();
997 //=================================================================================
998 // function : onRemove()
1000 //=================================================================================
1001 void SMESHGUI_CreatePolyhedralVolumeDlg::onRemove()
1004 QList<QListWidgetItem*> selItems = myFacesByNodes->selectedItems();
1005 QListWidgetItem* anItem;
1007 if ( selItems.count() > 0 ) myNbOkElements = 1;
1009 foreach( anItem, selItems )
1012 RemoveButton->setEnabled( myFacesByNodes->count() > 0 );
1013 buttonOk->setEnabled( myFacesByNodes->count() > 1 );
1014 buttonApply->setEnabled( myFacesByNodes->count() > 1 );
1017 displaySimulation();
1020 //=================================================================================
1021 // function : onListSelectionChanged()
1022 // purpose : Called when selection in element list is changed
1023 //=================================================================================
1024 void SMESHGUI_CreatePolyhedralVolumeDlg::onListSelectionChanged()
1026 if (busy || !myActor) return;
1029 SALOME_ListIO aList;
1030 mySelectionMgr->setSelectedObjects( aList );
1031 TColStd_MapOfInteger aIndexes;
1033 QList<QListWidgetItem*> selItems = myFacesByNodes->selectedItems();
1034 QListWidgetItem* anItem;
1035 foreach( anItem, selItems ) {
1036 QStringList anIds = anItem->text().split( " ", QString::SkipEmptyParts );
1037 for (QStringList::iterator it = anIds.begin(); it != anIds.end(); ++it)
1038 aIndexes.Add((*it).toInt());
1040 RemoveButton->setEnabled(selItems.count() > 0);
1041 mySelector->AddOrRemoveIndex(myActor->getIO(), aIndexes, true );
1042 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1043 aViewWindow->highlight( myActor->getIO(), true, true );
1044 mySelectionMgr->clearFilters();
1045 aList.Append( myActor->getIO() );
1046 mySelectionMgr->setSelectedObjects( aList );
1051 //=================================================================================
1052 // function : keyPressEvent()
1054 //=================================================================================
1055 void SMESHGUI_CreatePolyhedralVolumeDlg::keyPressEvent( QKeyEvent* e )
1057 QDialog::keyPressEvent( e );
1058 if ( e->isAccepted() )
1061 if ( e->key() == Qt::Key_F1 ) {