1 // Copyright (C) 2007-2012 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_AddMeshElementDlg.cxx
25 // Author : Nicolas REJNERI, Open CASCADE S.A.S.
28 #include "SMESHGUI_AddMeshElementDlg.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 <SMESH_FaceOrientationFilter.h>
40 #include <SMDS_Mesh.hxx>
43 #include <SUIT_Desktop.h>
44 #include <SUIT_Session.h>
45 #include <SUIT_ResourceMgr.h>
46 #include <SUIT_MessageBox.h>
47 #include <SUIT_ViewManager.h>
48 #include <LightApp_SelectionMgr.h>
49 #include <SALOME_ListIO.hxx>
50 #include <SalomeApp_Application.h>
51 #include <SVTK_ViewModel.h>
52 #include <SVTK_ViewWindow.h>
55 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
58 #include <TColStd_MapOfInteger.hxx>
62 #include <vtkIdList.h>
63 #include <vtkUnstructuredGrid.h>
64 #include <vtkDataSetMapper.h>
65 #include <vtkPolyDataMapper.h>
66 #include <vtkProperty.h>
73 #include <QPushButton>
74 #include <QRadioButton>
75 #include <QHBoxLayout>
76 #include <QVBoxLayout>
77 #include <QGridLayout>
81 #include <QButtonGroup>
88 class TElementSimulation
90 SalomeApp_Application* myApplication;
91 SUIT_ViewWindow* myViewWindow;
92 SVTK_ViewWindow* myVTKViewWindow;
94 SALOME_Actor* myPreviewActor;
95 vtkDataSetMapper* myMapper;
96 vtkUnstructuredGrid* myGrid;
98 SALOME_Actor* myFaceOrientation;
99 vtkPolyDataMapper* myFaceOrientationDataMapper;
100 SMESH_FaceOrientationFilter* myFaceOrientationFilter;
103 TElementSimulation (SalomeApp_Application* theApplication)
105 myApplication = theApplication;
106 SUIT_ViewManager* mgr = theApplication->activeViewManager();
108 myViewWindow = mgr->getActiveView();
109 myVTKViewWindow = GetVtkViewWindow(myViewWindow);
111 myGrid = vtkUnstructuredGrid::New();
113 // Create and display actor
114 myMapper = vtkDataSetMapper::New();
115 myMapper->SetInput(myGrid);
117 myPreviewActor = SALOME_Actor::New();
118 myPreviewActor->PickableOff();
119 myPreviewActor->VisibilityOff();
120 myPreviewActor->SetMapper(myMapper);
122 vtkFloatingPointType anRGB[3];
123 vtkProperty* aProp = vtkProperty::New();
124 GetColor( "SMESH", "fill_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 170, 255 ) );
125 aProp->SetColor( anRGB[0], anRGB[1], anRGB[2] );
126 myPreviewActor->SetProperty( aProp );
129 vtkProperty* aBackProp = vtkProperty::New();
130 GetColor( "SMESH", "backface_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 0, 255 ) );
131 aBackProp->SetColor( anRGB[0], anRGB[1], anRGB[2] );
132 myPreviewActor->SetBackfaceProperty( aBackProp );
135 myVTKViewWindow->AddActor(myPreviewActor);
137 // Orientation of faces
138 myFaceOrientationFilter = SMESH_FaceOrientationFilter::New();
139 myFaceOrientationFilter->SetInput(myGrid);
141 myFaceOrientationDataMapper = vtkPolyDataMapper::New();
142 myFaceOrientationDataMapper->SetInput(myFaceOrientationFilter->GetOutput());
144 myFaceOrientation = SALOME_Actor::New();
145 myFaceOrientation->PickableOff();
146 myFaceOrientation->VisibilityOff();
147 myFaceOrientation->SetMapper(myFaceOrientationDataMapper);
149 vtkProperty* anOrientationProp = vtkProperty::New();
150 GetColor( "SMESH", "orientation_color", anRGB[0], anRGB[1], anRGB[2], QColor( 255, 255, 255 ) );
151 anOrientationProp->SetColor( anRGB[0], anRGB[1], anRGB[2] );
152 myFaceOrientation->SetProperty( anOrientationProp );
153 anOrientationProp->Delete();
155 myVTKViewWindow->AddActor(myFaceOrientation);
158 typedef std::vector<vtkIdType> TVTKIds;
159 void SetPosition (SMESH_Actor* theActor,
163 vtkUnstructuredGrid *aGrid = theActor->GetUnstructuredGrid();
164 myGrid->SetPoints(aGrid->GetPoints());
167 const std::vector<int>& interlace = SMDS_MeshCell::toVtkOrder( VTKCellType( theType ));
168 SMDS_MeshCell::applyInterlace( interlace, theIds );
170 vtkIdList *anIds = vtkIdList::New();
171 for (int i = 0, iEnd = theIds.size(); i < iEnd; i++)
172 anIds->InsertId(i,theIds[i]);
174 myGrid->InsertNextCell(theType,anIds);
179 SetVisibility(true, theActor->GetFacesOriented());
183 void SetVisibility (bool theVisibility, bool theShowOrientation = false)
185 myPreviewActor->SetVisibility(theVisibility);
186 myFaceOrientation->SetVisibility(theShowOrientation);
187 RepaintCurrentView();
191 ~TElementSimulation()
193 if (FindVtkViewWindow(myApplication->activeViewManager(), myViewWindow)) {
194 myVTKViewWindow->RemoveActor(myPreviewActor);
195 myVTKViewWindow->RemoveActor(myFaceOrientation);
197 myPreviewActor->Delete();
198 myFaceOrientation->Delete();
200 myMapper->RemoveAllInputs();
203 myFaceOrientationFilter->Delete();
205 myFaceOrientationDataMapper->RemoveAllInputs();
206 myFaceOrientationDataMapper->Delete();
213 //=================================================================================
214 // function : SMESHGUI_AddMeshElementDlg()
215 // purpose : constructor
216 //=================================================================================
217 SMESHGUI_AddMeshElementDlg::SMESHGUI_AddMeshElementDlg( SMESHGUI* theModule,
218 SMDSAbs_EntityType ElementType)
219 : QDialog( SMESH::GetDesktop( theModule ) ),
220 mySMESHGUI( theModule ),
221 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
225 setAttribute( Qt::WA_DeleteOnClose, true );
227 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>
228 (SUIT_Session::session()->activeApplication());
230 mySimulation = new SMESH::TElementSimulation (anApp);
231 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
232 myGeomType = ElementType;
233 myElementType = SMDSAbs_Volume;
235 // verify nb nodes and type
237 switch ( myGeomType ) {
240 myElementType = SMDSAbs_0DElement;
242 myHelpFileName = "adding_nodes_and_elements_page.html#adding_0delems_anchor";
244 case SMDSEntity_Edge:
246 myElementType = SMDSAbs_Edge;
248 myHelpFileName = "adding_nodes_and_elements_page.html#adding_edges_anchor";
250 case SMDSEntity_Triangle:
252 elemName = "TRIANGLE";
253 myElementType = SMDSAbs_Face;
254 myHelpFileName = "adding_nodes_and_elements_page.html#adding_triangles_anchor";
256 case SMDSEntity_Quadrangle:
258 myElementType = SMDSAbs_Face;
259 elemName = "QUADRANGLE";
260 myHelpFileName = "adding_nodes_and_elements_page.html#adding_quadrangles_anchor";
262 case SMDSEntity_Polygon:
264 myElementType = SMDSAbs_Face;
265 elemName = "POLYGON";
267 myHelpFileName = "adding_nodes_and_elements_page.html#adding_polygons_anchor";
269 case SMDSEntity_Tetra:
272 myHelpFileName = "adding_nodes_and_elements_page.html#adding_tetrahedrons_anchor";
274 case SMDSEntity_Pyramid:
276 elemName = "PYRAMID";
277 myHelpFileName = "adding_nodes_and_elements_page.html#adding_pyramids_anchor";
279 case SMDSEntity_Hexa:
282 myHelpFileName = "adding_nodes_and_elements_page.html#adding_hexahedrons_anchor";
284 case SMDSEntity_Penta:
287 myHelpFileName = "adding_nodes_and_elements_page.html#adding_pentahedrons_anchor";
289 case SMDSEntity_Hexagonal_Prism:
292 myHelpFileName = "adding_nodes_and_elements_page.html#adding_octahedrons_anchor";
297 myHelpFileName = "adding_nodes_and_elements_page.html#adding_edges_anchor";
300 QString iconName = tr(QString("ICON_DLG_%1").arg(elemName).toLatin1().data());
301 QString buttonGrTitle = tr(QString("SMESH_%1").arg(elemName).toLatin1().data());
302 QString caption = tr(QString("SMESH_ADD_%1_TITLE").arg(elemName).toLatin1().data());
303 QString grBoxTitle = tr(QString("SMESH_ADD_%1").arg(elemName).toLatin1().data());
305 QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", iconName));
306 QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
308 setWindowTitle(caption);
309 setSizeGripEnabled(true);
311 QVBoxLayout* aTopLayout = new QVBoxLayout(this);
312 aTopLayout->setSpacing(SPACING);
313 aTopLayout->setMargin(MARGIN);
315 /***************************************************************/
316 GroupConstructors = new QGroupBox(buttonGrTitle, this);
317 QButtonGroup* ButtonGroup = new QButtonGroup(this);
318 QHBoxLayout* GroupConstructorsLayout = new QHBoxLayout(GroupConstructors);
319 GroupConstructorsLayout->setSpacing(SPACING);
320 GroupConstructorsLayout->setMargin(MARGIN);
322 Constructor1 = new QRadioButton(GroupConstructors);
323 Constructor1->setIcon(image0);
324 Constructor1->setChecked(true);
326 GroupConstructorsLayout->addWidget(Constructor1);
327 ButtonGroup->addButton( Constructor1, 0 );
329 /***************************************************************/
330 GroupC1 = new QGroupBox(grBoxTitle, this);
331 QGridLayout* GroupC1Layout = new QGridLayout(GroupC1);
332 GroupC1Layout->setSpacing(SPACING);
333 GroupC1Layout->setMargin(MARGIN);
335 TextLabelC1A1 = new QLabel(tr("SMESH_ID_NODES"), GroupC1);
336 SelectButtonC1A1 = new QPushButton(GroupC1);
337 SelectButtonC1A1->setIcon(image1);
338 LineEditC1A1 = new QLineEdit(GroupC1);
339 LineEditC1A1->setValidator(new SMESHGUI_IdValidator(this, myIsPoly ? 1000 : myNbNodes));
341 Reverse = (myElementType == SMDSAbs_Face || myElementType == SMDSAbs_Volume ) ? new QCheckBox(tr("SMESH_REVERSE"), GroupC1) : 0;
343 GroupC1Layout->addWidget(TextLabelC1A1, 0, 0);
344 GroupC1Layout->addWidget(SelectButtonC1A1, 0, 1);
345 GroupC1Layout->addWidget(LineEditC1A1, 0, 2);
346 if ( Reverse ) GroupC1Layout->addWidget(Reverse, 1, 0, 1, 3);
348 /***************************************************************/
349 GroupGroups = new QGroupBox( tr( "SMESH_ADD_TO_GROUP" ), this );
350 GroupGroups->setCheckable( true );
351 QHBoxLayout* GroupGroupsLayout = new QHBoxLayout(GroupGroups);
352 GroupGroupsLayout->setSpacing(SPACING);
353 GroupGroupsLayout->setMargin(MARGIN);
355 TextLabel_GroupName = new QLabel( tr( "SMESH_GROUP" ), GroupGroups );
356 ComboBox_GroupName = new QComboBox( GroupGroups );
357 ComboBox_GroupName->setEditable( true );
358 ComboBox_GroupName->setInsertPolicy( QComboBox::NoInsert );
360 GroupGroupsLayout->addWidget( TextLabel_GroupName );
361 GroupGroupsLayout->addWidget( ComboBox_GroupName, 1 );
363 /***************************************************************/
364 GroupButtons = new QGroupBox(this);
365 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
366 GroupButtonsLayout->setSpacing(SPACING);
367 GroupButtonsLayout->setMargin(MARGIN);
369 buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
370 buttonOk->setAutoDefault(true);
371 buttonOk->setDefault(true);
372 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
373 buttonApply->setAutoDefault(true);
374 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
375 buttonCancel->setAutoDefault(true);
376 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
377 buttonHelp->setAutoDefault(true);
379 GroupButtonsLayout->addWidget(buttonOk);
380 GroupButtonsLayout->addSpacing(10);
381 GroupButtonsLayout->addWidget(buttonApply);
382 GroupButtonsLayout->addSpacing(10);
383 GroupButtonsLayout->addStretch();
384 GroupButtonsLayout->addWidget(buttonCancel);
385 GroupButtonsLayout->addWidget(buttonHelp);
387 /***************************************************************/
388 aTopLayout->addWidget(GroupConstructors);
389 aTopLayout->addWidget(GroupC1);
390 aTopLayout->addWidget(GroupGroups);
391 aTopLayout->addWidget(GroupButtons);
393 Init(); /* Initialisations */
396 //=================================================================================
397 // function : ~SMESHGUI_AddMeshElementDlg()
398 // purpose : Destroys the object and frees any allocated resources
399 //=================================================================================
400 SMESHGUI_AddMeshElementDlg::~SMESHGUI_AddMeshElementDlg()
405 //=================================================================================
408 //=================================================================================
409 void SMESHGUI_AddMeshElementDlg::Init()
412 Constructor1->setChecked(true);
413 myEditCurrentArgument = LineEditC1A1;
414 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
416 /* reset "Add to group" control */
417 GroupGroups->setChecked( false );
418 GroupGroups->setVisible( myElementType != SMDSAbs_0DElement );
423 /* signals and slots connections */
424 connect(buttonOk, SIGNAL(clicked()), SLOT(ClickOnOk()));
425 connect(buttonCancel, SIGNAL(clicked()), SLOT(ClickOnCancel()));
426 connect(buttonApply, SIGNAL(clicked()), SLOT(ClickOnApply()));
427 connect(buttonHelp, SIGNAL(clicked()), SLOT(ClickOnHelp()));
429 connect(SelectButtonC1A1, SIGNAL(clicked()), SLOT(SetEditCurrentArgument()));
430 connect(LineEditC1A1, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
431 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), SLOT(DeactivateActiveDialog()));
432 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(SelectionIntoArgument()));
433 /* to close dialog if study frame change */
434 connect(mySMESHGUI, SIGNAL (SignalStudyFrameChanged()), SLOT(ClickOnCancel()));
435 connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), SLOT(ClickOnCancel()));
438 connect(Reverse, SIGNAL(stateChanged(int)), SLOT(CheckBox(int)));
440 // set selection mode
441 SMESH::SetPointRepresentation(true);
443 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
444 aViewWindow->SetSelectionMode( NodeSelection );
448 SelectionIntoArgument();
451 //=================================================================================
452 // function : ClickOnApply()
454 //=================================================================================
455 void SMESHGUI_AddMeshElementDlg::ClickOnApply()
460 if (myNbOkNodes && !mySMESHGUI->isActiveStudyLocked()) {
462 SMESH::long_array_var anArrayOfIndices = new SMESH::long_array;
463 anArrayOfIndices->length(myNbNodes);
464 QStringList aListId = myEditCurrentArgument->text().split(" ", QString::SkipEmptyParts);
465 const std::vector<int>& revIndex = SMDS_MeshCell::reverseSmdsOrder( myGeomType );
466 if ( Reverse && Reverse->isChecked() && !revIndex.empty() )
467 for (int i = 0; i < aListId.count(); i++)
468 anArrayOfIndices[i] = aListId[ revIndex[i] ].toInt();
469 else if ( Reverse && Reverse->isChecked() && revIndex.empty() ) // polygon
470 for (int i = 0; i < aListId.count(); i++)
471 anArrayOfIndices[i] = aListId[ aListId.count()-1 - i ].toInt();
473 for (int i = 0; i < aListId.count(); i++)
474 anArrayOfIndices[i] = aListId[ i ].toInt();
476 bool addToGroup = GroupGroups->isChecked();
479 SMESH::SMESH_GroupBase_var aGroup;
482 aGroupName = ComboBox_GroupName->currentText();
483 for ( int i = 1; i < ComboBox_GroupName->count(); i++ ) {
484 QString aName = ComboBox_GroupName->itemText( i );
485 if ( aGroupName == aName && ( i == ComboBox_GroupName->currentIndex() || idx == 0 ) )
488 if ( idx > 0 && idx < myGroups.count() ) {
489 SMESH::SMESH_GroupOnGeom_var aGeomGroup = SMESH::SMESH_GroupOnGeom::_narrow( myGroups[idx-1] );
490 if ( !aGeomGroup->_is_nil() ) {
491 int res = SUIT_MessageBox::question( this, tr( "SMESH_WRN_WARNING" ),
492 tr( "MESH_STANDALONE_GRP_CHOSEN" ).arg( aGroupName ),
493 tr( "SMESH_BUT_YES" ), tr( "SMESH_BUT_NO" ), 0, 1 );
494 if ( res == 1 ) return;
496 aGroup = myGroups[idx-1];
501 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
502 switch (myElementType) {
503 case SMDSAbs_0DElement:
504 anElemId = aMeshEditor->Add0DElement(anArrayOfIndices[0]); break;
506 anElemId = aMeshEditor->AddEdge(anArrayOfIndices.inout()); break;
509 anElemId = aMeshEditor->AddPolygonalFace(anArrayOfIndices.inout());
511 anElemId = aMeshEditor->AddFace(anArrayOfIndices.inout());
514 anElemId = aMeshEditor->AddVolume(anArrayOfIndices.inout()); break;
517 if ( anElemId != -1 && addToGroup && !aGroupName.isEmpty() ) {
518 SMESH::SMESH_Group_var aGroupUsed;
519 if ( aGroup->_is_nil() ) {
521 aGroupUsed = SMESH::AddGroup( myMesh, (SMESH::ElementType)myElementType, aGroupName );
522 if ( !aGroupUsed->_is_nil() ) {
523 myGroups.append(SMESH::SMESH_GroupBase::_duplicate(aGroupUsed));
524 ComboBox_GroupName->addItem( aGroupName );
528 SMESH::SMESH_GroupOnGeom_var aGeomGroup = SMESH::SMESH_GroupOnGeom::_narrow( aGroup );
529 if ( !aGeomGroup->_is_nil() ) {
530 aGroupUsed = myMesh->ConvertToStandalone( aGeomGroup );
531 if ( !aGroupUsed->_is_nil() && idx > 0 ) {
532 myGroups[idx-1] = SMESH::SMESH_GroupBase::_duplicate(aGroupUsed);
533 SMESHGUI::GetSMESHGUI()->getApp()->updateObjectBrowser();
537 aGroupUsed = SMESH::SMESH_Group::_narrow( aGroup );
540 if ( !aGroupUsed->_is_nil() ) {
541 SMESH::long_array_var anIdList = new SMESH::long_array;
542 anIdList->length( 1 );
543 anIdList[0] = anElemId;
544 aGroupUsed->Add( anIdList.inout() );
548 SALOME_ListIO aList; aList.Append( myActor->getIO() );
549 mySelector->ClearIndex();
550 mySelectionMgr->setSelectedObjects( aList, false );
553 mySimulation->SetVisibility(false);
555 buttonOk->setEnabled(false);
556 buttonApply->setEnabled(false);
558 myEditCurrentArgument->setText("");
562 SMESHGUI::Modified();
566 //=================================================================================
567 // function : ClickOnOk()
569 //=================================================================================
570 void SMESHGUI_AddMeshElementDlg::ClickOnOk()
576 //=================================================================================
577 // function : ClickOnCancel()
579 //=================================================================================
580 void SMESHGUI_AddMeshElementDlg::ClickOnCancel()
582 //mySelectionMgr->clearSelected();
583 mySimulation->SetVisibility(false);
584 SMESH::SetPointRepresentation(false);
585 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
586 aViewWindow->SetSelectionMode( ActorSelection );
587 disconnect(mySelectionMgr, 0, this, 0);
588 mySMESHGUI->ResetState();
592 //=================================================================================
593 // function : ClickOnHelp()
595 //=================================================================================
596 void SMESHGUI_AddMeshElementDlg::ClickOnHelp()
598 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
600 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""),
605 platform = "winapplication";
607 platform = "application";
609 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
610 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
611 arg(app->resourceMgr()->stringValue("ExternalBrowser",
613 arg(myHelpFileName));
617 //=================================================================================
618 // function : onTextChange()
620 //=================================================================================
621 void SMESHGUI_AddMeshElementDlg::onTextChange (const QString& theNewText)
628 buttonOk->setEnabled(false);
629 buttonApply->setEnabled(false);
631 mySimulation->SetVisibility(false);
633 // hilight entered nodes
634 SMDS_Mesh* aMesh = 0;
636 aMesh = myActor->GetObject()->GetMesh();
639 TColStd_MapOfInteger newIndices;
641 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
643 for (int i = 0; i < aListId.count(); i++) {
644 if( const SMDS_MeshNode * n = aMesh->FindNode( aListId[ i ].toInt() ) )
646 newIndices.Add( n->GetID() );
653 mySelector->AddOrRemoveIndex( myActor->getIO(), newIndices, false );
654 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
655 aViewWindow->highlight( myActor->getIO(), true, true );
657 myNbOkNodes = ( allOk && myNbNodes == aListId.count() );
661 if ( !allOk || myElementType != SMDSAbs_Face || aListId.count() < 3 )
664 myNbOkNodes = aListId.count();
669 buttonOk->setEnabled(true);
670 buttonApply->setEnabled(true);
677 //=================================================================================
678 // function : SelectionIntoArgument()
679 // purpose : Called when selection has changed
680 //=================================================================================
681 void SMESHGUI_AddMeshElementDlg::SelectionIntoArgument()
690 myEditCurrentArgument->setText("");
693 if (!GroupButtons->isEnabled()) // inactive
696 buttonOk->setEnabled(false);
697 buttonApply->setEnabled(false);
699 mySimulation->SetVisibility(false);
700 // SMESH::SetPointRepresentation(true);
702 QString aCurrentEntry = myEntry;
706 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
708 if (aList.Extent() != 1)
711 Handle(SALOME_InteractiveObject) anIO = aList.First();
712 myEntry = anIO->getEntry();
713 myMesh = SMESH::GetMeshByIO(anIO);
714 if (myMesh->_is_nil())
718 if ( !myMesh->_is_nil() && myEntry != aCurrentEntry ) {
720 ComboBox_GroupName->clear();
721 ComboBox_GroupName->addItem( QString() );
722 SMESH::ListOfGroups aListOfGroups = *myMesh->GetGroups();
723 for ( int i = 0, n = aListOfGroups.length(); i < n; i++ ) {
724 SMESH::SMESH_GroupBase_var aGroup = aListOfGroups[i];
725 if ( !aGroup->_is_nil() && aGroup->GetType() == (SMESH::ElementType)myElementType ) {
726 QString aGroupName( aGroup->GetName() );
727 if ( !aGroupName.isEmpty() ) {
728 myGroups.append(SMESH::SMESH_GroupBase::_duplicate(aGroup));
729 ComboBox_GroupName->addItem( aGroupName );
735 myActor = SMESH::FindActorByEntry(anIO->getEntry());
739 // get selected nodes
740 QString aString = "";
741 int nbNodes = SMESH::GetNameOfSelectedNodes(mySelector,myActor->getIO(),aString);
743 myEditCurrentArgument->setText(aString);
745 if (myIsPoly && myElementType == SMDSAbs_Face && nbNodes >= 3 ) {
747 } else if (myNbNodes != nbNodes) {
752 myNbOkNodes = nbNodes;
754 buttonOk->setEnabled(true);
755 buttonApply->setEnabled(true);
760 //=================================================================================
761 // function : displaySimulation()
763 //=================================================================================
764 void SMESHGUI_AddMeshElementDlg::displaySimulation()
766 if (myNbOkNodes && GroupButtons->isEnabled()) {
767 SMESH::TElementSimulation::TVTKIds anIds;
768 QStringList aListId = myEditCurrentArgument->text().split(" ", QString::SkipEmptyParts);
769 for (int i = 0; i < aListId.count(); i++)
770 anIds.push_back(myActor->GetObject()->GetNodeVTKId(aListId[ i ].toInt()));
772 if (Reverse && Reverse->isChecked())
774 const std::vector<int>& i = SMDS_MeshCell::reverseSmdsOrder( myGeomType );
775 if ( i.empty() ) // polygon
776 std::reverse( anIds.begin(), anIds.end() );
778 SMDS_MeshCell::applyInterlace( i, anIds );
781 vtkIdType aType = SMDS_MeshCell::toVtkType( myGeomType );
782 mySimulation->SetPosition(myActor,aType,anIds);
787 //=================================================================================
788 // function : SetEditCurrentArgument()
790 //=================================================================================
791 void SMESHGUI_AddMeshElementDlg::SetEditCurrentArgument()
793 QPushButton* send = (QPushButton*)sender();
794 if (send == SelectButtonC1A1) {
795 LineEditC1A1->setFocus();
796 myEditCurrentArgument = LineEditC1A1;
798 SelectionIntoArgument();
801 //=================================================================================
802 // function : DeactivateActiveDialog()
804 //=================================================================================
805 void SMESHGUI_AddMeshElementDlg::DeactivateActiveDialog()
807 if (GroupConstructors->isEnabled()) {
808 GroupConstructors->setEnabled(false);
809 GroupC1->setEnabled(false);
810 GroupButtons->setEnabled(false);
811 mySimulation->SetVisibility(false);
812 mySMESHGUI->ResetState();
813 mySMESHGUI->SetActiveDialogBox(0);
817 //=================================================================================
818 // function : ActivateThisDialog()
820 //=================================================================================
821 void SMESHGUI_AddMeshElementDlg::ActivateThisDialog()
823 /* Emit a signal to deactivate the active dialog */
824 mySMESHGUI->EmitSignalDeactivateDialog();
826 GroupConstructors->setEnabled(true);
827 GroupC1->setEnabled(true);
828 GroupButtons->setEnabled(true);
830 SMESH::SetPointRepresentation(true);
832 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
833 aViewWindow->SetSelectionMode( NodeSelection );
834 SelectionIntoArgument();
837 //=================================================================================
838 // function : enterEvent()
840 //=================================================================================
841 void SMESHGUI_AddMeshElementDlg::enterEvent (QEvent*)
843 if (GroupConstructors->isEnabled())
845 ActivateThisDialog();
848 //=================================================================================
849 // function : closeEvent()
851 //=================================================================================
852 void SMESHGUI_AddMeshElementDlg::closeEvent (QCloseEvent*)
854 /* same than click on cancel button */
858 //=================================================================================
859 // function : hideEvent()
860 // purpose : caused by ESC key
861 //=================================================================================
862 void SMESHGUI_AddMeshElementDlg::hideEvent (QHideEvent*)
868 //=================================================================================
869 // function : CheckBox()
871 //=================================================================================
872 void SMESHGUI_AddMeshElementDlg::CheckBox (int state)
878 mySimulation->SetVisibility(false);
883 //=================================================================================
884 // function : keyPressEvent()
886 //=================================================================================
887 void SMESHGUI_AddMeshElementDlg::keyPressEvent( QKeyEvent* e )
889 QDialog::keyPressEvent( e );
890 if ( e->isAccepted() )
893 if ( e->key() == Qt::Key_F1 ) {
899 //=================================================================================
900 // function : isValid
902 //=================================================================================
903 bool SMESHGUI_AddMeshElementDlg::isValid()
905 if( GroupGroups->isChecked() && ComboBox_GroupName->currentText().isEmpty() ) {
906 SUIT_MessageBox::warning( this, tr( "SMESH_WRN_WARNING" ), tr( "GROUP_NAME_IS_EMPTY" ) );