1 // Copyright (C) 2007-2022 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, or (at your option) any later version.
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_GroupUtils.h"
32 #include "SMESHGUI_IdValidator.h"
33 #include "SMESHGUI_MeshUtils.h"
34 #include "SMESHGUI_SpinBox.h"
35 #include "SMESHGUI_Utils.h"
36 #include "SMESHGUI_VTKUtils.h"
38 #include <SMESH_Actor.h>
39 #include <SMESH_ActorUtils.h>
40 #include <SMESH_FaceOrientationFilter.h>
41 #include <SMDS_Mesh.hxx>
43 // SALOME GUI includes
44 #include <SUIT_Desktop.h>
45 #include <SUIT_Session.h>
46 #include <SUIT_ResourceMgr.h>
47 #include <SUIT_MessageBox.h>
48 #include <SUIT_ViewManager.h>
49 #include <LightApp_SelectionMgr.h>
50 #include <SALOME_ListIO.hxx>
51 #include <SalomeApp_Application.h>
52 #include <SVTK_ViewModel.h>
53 #include <SVTK_ViewWindow.h>
54 #include <VTKViewer_PolyDataMapper.h>
55 #include <SVTK_Renderer.h>
60 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
63 #include <TColStd_MapOfInteger.hxx>
67 #include <vtkIdList.h>
68 #include <vtkUnstructuredGrid.h>
69 #include <vtkDataSetMapper.h>
70 #include <vtkPolyDataMapper.h>
71 #include <vtkProperty.h>
72 #include <vtkCellData.h>
79 #include <QPushButton>
80 #include <QRadioButton>
81 #include <QHBoxLayout>
82 #include <QVBoxLayout>
83 #include <QGridLayout>
87 #include <QButtonGroup>
94 class TElementSimulation
96 SalomeApp_Application* myApplication;
97 SUIT_ViewWindow* myViewWindow;
98 SVTK_ViewWindow* myVTKViewWindow;
100 SALOME_Actor* myPreviewActor;
101 vtkDataSetMapper* myMapper;
102 vtkUnstructuredGrid* myGrid;
104 SALOME_Actor* myBallActor;
105 VTKViewer_PolyDataMapper* myBallMapper;
106 vtkPolyData* myBallPolyData;
108 SALOME_Actor* myFaceOrientation;
109 vtkPolyDataMapper* myFaceOrientationDataMapper;
110 SMESH_FaceOrientationFilter* myFaceOrientationFilter;
113 TElementSimulation (SalomeApp_Application* theApplication)
115 myApplication = theApplication;
116 SUIT_ViewManager* mgr = theApplication->activeViewManager();
118 myViewWindow = mgr->getActiveView();
119 myVTKViewWindow = GetVtkViewWindow(myViewWindow);
121 myGrid = vtkUnstructuredGrid::New();
123 // Create and display actor
124 myMapper = vtkDataSetMapper::New();
125 myMapper->SetInputData(myGrid);
127 myPreviewActor = SALOME_Actor::New();
128 myPreviewActor->PickableOff();
129 myPreviewActor->VisibilityOff();
130 myPreviewActor->SetMapper(myMapper);
135 vtkProperty* aProp = vtkProperty::New();
136 SMESH::GetColor( "SMESH", "preview_color", ffc, delta, "0, 255, 0|-100" ) ;
137 aProp->SetColor( ffc.red() / 255. , ffc.green() / 255. , ffc.blue() / 255. );
138 myPreviewActor->SetProperty( aProp );
141 vtkProperty* aBackProp = vtkProperty::New();
142 bfc = Qtx::mainColorToSecondary(ffc, delta);
143 aBackProp->SetColor( bfc.red() / 255. , bfc.green() / 255. , bfc.blue() / 255. );
144 myPreviewActor->SetBackfaceProperty( aBackProp );
147 myVTKViewWindow->AddActor(myPreviewActor);
149 // Orientation of faces
150 myFaceOrientationFilter = SMESH_FaceOrientationFilter::New();
151 myFaceOrientationFilter->SetInputData(myGrid);
153 myFaceOrientationDataMapper = vtkPolyDataMapper::New();
154 myFaceOrientationDataMapper->SetInputConnection(myFaceOrientationFilter->GetOutputPort());
156 myFaceOrientation = SALOME_Actor::New();
157 myFaceOrientation->PickableOff();
158 myFaceOrientation->VisibilityOff();
159 myFaceOrientation->SetMapper(myFaceOrientationDataMapper);
161 vtkProperty* anOrientationProp = vtkProperty::New();
163 GetColor( "SMESH", "orientation_color", anRGB[0], anRGB[1], anRGB[2], QColor( 255, 255, 255 ) );
164 anOrientationProp->SetColor( anRGB[0], anRGB[1], anRGB[2] );
165 myFaceOrientation->SetProperty( anOrientationProp );
166 anOrientationProp->Delete();
167 myVTKViewWindow->AddActor(myFaceOrientation);
169 // Preview for the balls
170 vtkProperty* aBallProp = vtkProperty::New();
171 aBallProp->SetColor(ffc.red() / 255. , ffc.green() / 255. , ffc.blue() / 255.);
172 //double aBallElemSize = SMESH::GetFloat("SMESH:ball_elem_size",10);
173 double aBallElemSize = SMESH::GetFloat("SMESH:ball_elem_diameter",1);
174 aBallProp->SetPointSize(aBallElemSize);
176 myBallPolyData = vtkPolyData::New();
177 myBallPolyData->Allocate();
179 myBallMapper = VTKViewer_PolyDataMapper::New();
180 myBallMapper->SetInputData(myBallPolyData);
181 myBallMapper->SetBallEnabled(true);
183 myBallActor = SALOME_Actor::New();
184 myBallActor->PickableOff();
185 myBallActor->SetVisibility(false);
186 myBallActor->SetProperty(aBallProp);
187 myBallActor->SetMapper(myBallMapper);
190 myVTKViewWindow->AddActor(myBallActor);
193 typedef std::vector<vtkIdType> TVTKIds;
194 void SetPosition (SMESH_Actor* theActor,
198 vtkUnstructuredGrid *aGrid = theActor->GetUnstructuredGrid();
199 myGrid->SetPoints(aGrid->GetPoints());
202 const std::vector<int>& interlace = SMDS_MeshCell::toVtkOrder( VTKCellType( theType ));
203 SMDS_MeshCell::applyInterlace( interlace, theIds );
205 vtkIdList *anIds = vtkIdList::New();
206 for (int i = 0, iEnd = theIds.size(); i < iEnd; i++)
207 anIds->InsertId(i,theIds[i]);
209 myGrid->InsertNextCell(theType,anIds);
214 SetVisibility(true, theActor->GetFacesOriented(), false);
217 void SetBallPosition(SMESH_Actor* theActor,TVTKIds& theIds, double theDiameter)
219 vtkUnstructuredGrid *aGrid = theActor->GetUnstructuredGrid();
220 myBallPolyData->SetPoints(NULL);
221 myBallPolyData->Reset();
222 myBallPolyData->DeleteCells();
223 myBallPolyData->SetPoints(aGrid->GetPoints());
225 vtkDataArray* aScalars = vtkDataArray::CreateDataArray(VTK_DOUBLE);
226 aScalars->SetNumberOfComponents(1);
227 aScalars->SetNumberOfTuples(theIds.size());
228 myBallPolyData->GetCellData()->SetScalars(aScalars);
231 vtkIdList *anIds = vtkIdList::New();
232 anIds->SetNumberOfIds(1);
233 for (int i = 0, iEnd = theIds.size(); i < iEnd; i++){
234 anIds->InsertId(0,theIds[i]);
235 vtkIdType anId = myBallPolyData->InsertNextCell(VTK_POLY_VERTEX,anIds);
236 double d = theDiameter * theActor->GetBallScale();
237 aScalars->SetTuple(anId,&d);
242 myBallPolyData->Modified();
243 SetVisibility (false, false, true);
246 void SetVisibility (bool theVisibility, bool theShowOrientation = false, bool theShowBalls = false)
248 myPreviewActor->SetVisibility(theVisibility);
249 myFaceOrientation->SetVisibility(theShowOrientation);
250 myBallActor->SetVisibility(theShowBalls);
251 RepaintCurrentView();
255 ~TElementSimulation()
257 myMapper->RemoveAllInputs();
258 myFaceOrientationDataMapper->RemoveAllInputs();
259 myBallMapper->RemoveAllInputs();
261 if (FindVtkViewWindow(myApplication->activeViewManager(), myViewWindow)) {
262 myVTKViewWindow->RemoveActor(myPreviewActor,false,false);
263 myVTKViewWindow->RemoveActor(myFaceOrientation,false,false);
264 myVTKViewWindow->RemoveActor(myBallActor,false,false);
269 myPreviewActor->Delete();
271 myFaceOrientationFilter->Delete();
272 myFaceOrientationDataMapper->Delete();
273 myFaceOrientation->Delete();
275 myBallMapper->Delete();
276 myBallPolyData->Delete();
277 myBallActor->Delete();
282 //=================================================================================
283 // function : SMESHGUI_AddMeshElementDlg()
284 // purpose : constructor
285 //=================================================================================
286 SMESHGUI_AddMeshElementDlg::SMESHGUI_AddMeshElementDlg( SMESHGUI* theModule,
287 SMDSAbs_EntityType ElementType)
288 : QDialog( SMESH::GetDesktop( theModule ) ),
289 mySMESHGUI( theModule ),
290 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
294 setAttribute( Qt::WA_DeleteOnClose, true );
296 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>
297 (SUIT_Session::session()->activeApplication());
299 mySimulation = new SMESH::TElementSimulation (anApp);
300 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
301 myGeomType = ElementType;
302 myElementType = SMDSAbs_Volume;
304 // verify nb nodes and type
306 switch ( myGeomType ) {
309 myElementType = SMDSAbs_0DElement;
311 myHelpFileName = "adding_nodes_and_elements.html#adding-0delems-anchor";
313 case SMDSEntity_Ball:
315 myElementType = SMDSAbs_Ball;
317 myHelpFileName = "adding_nodes_and_elements.html#adding-balls-anchor";
319 case SMDSEntity_Edge:
321 myElementType = SMDSAbs_Edge;
323 myHelpFileName = "adding_nodes_and_elements.html#adding-edges-anchor";
325 case SMDSEntity_Triangle:
327 elemName = "TRIANGLE";
328 myElementType = SMDSAbs_Face;
329 myHelpFileName = "adding_nodes_and_elements.html#adding-triangles-anchor";
331 case SMDSEntity_Quadrangle:
333 myElementType = SMDSAbs_Face;
334 elemName = "QUADRANGLE";
335 myHelpFileName = "adding_nodes_and_elements.html#adding-quadrangles-anchor";
337 case SMDSEntity_Polygon:
339 myElementType = SMDSAbs_Face;
340 elemName = "POLYGON";
342 myHelpFileName = "adding_nodes_and_elements.html#adding-polygons-anchor";
344 case SMDSEntity_Tetra:
347 myHelpFileName = "adding_nodes_and_elements.html#adding-tetrahedrons-anchor";
349 case SMDSEntity_Pyramid:
351 elemName = "PYRAMID";
352 myHelpFileName = "adding_nodes_and_elements.html#adding-pyramids-anchor";
354 case SMDSEntity_Hexa:
357 myHelpFileName = "adding_nodes_and_elements.html#adding-hexahedrons-anchor";
359 case SMDSEntity_Penta:
362 myHelpFileName = "adding_nodes_and_elements.html#adding-pentahedrons-anchor";
364 case SMDSEntity_Hexagonal_Prism:
367 myHelpFileName = "adding_nodes_and_elements.html#adding-octahedrons-anchor";
372 myHelpFileName = "adding_nodes_and_elements.html#adding-edges-anchor";
375 QString iconName = tr(QString("ICON_DLG_%1").arg(elemName).toLatin1().data());
376 QString buttonGrTitle = tr(QString("SMESH_%1").arg(elemName).toLatin1().data());
377 QString caption = tr(QString("SMESH_ADD_%1_TITLE").arg(elemName).toLatin1().data());
378 QString grBoxTitle = tr(QString("SMESH_ADD_%1").arg(elemName).toLatin1().data());
380 QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", iconName));
381 QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
383 setWindowTitle(caption);
384 setSizeGripEnabled(true);
386 QVBoxLayout* aTopLayout = new QVBoxLayout(this);
387 aTopLayout->setSpacing(SPACING);
388 aTopLayout->setMargin(MARGIN);
390 /* Constructor *************************************************/
391 GroupConstructors = new QGroupBox(buttonGrTitle, this);
392 QButtonGroup* ButtonGroup = new QButtonGroup(this);
393 QHBoxLayout* GroupConstructorsLayout = new QHBoxLayout(GroupConstructors);
394 GroupConstructorsLayout->setSpacing(SPACING);
395 GroupConstructorsLayout->setMargin(MARGIN);
397 Constructor1 = new QRadioButton(GroupConstructors);
398 Constructor1->setIcon(image0);
399 Constructor1->setChecked(true);
401 GroupConstructorsLayout->addWidget(Constructor1);
402 ButtonGroup->addButton( Constructor1, 0 );
404 /* Nodes & Reverse *********************************************/
405 GroupC1 = new QGroupBox(grBoxTitle, this);
406 QGridLayout* GroupC1Layout = new QGridLayout(GroupC1);
407 GroupC1Layout->setSpacing(SPACING);
408 GroupC1Layout->setMargin(MARGIN);
410 TextLabelC1A1 = new QLabel(tr("SMESH_ID_NODES"), GroupC1);
411 SelectButtonC1A1 = new QPushButton(GroupC1);
412 SelectButtonC1A1->setIcon(image1);
413 LineEditC1A1 = new QLineEdit(GroupC1);
414 LineEditC1A1->setValidator
415 (new SMESHGUI_IdValidator(this, ( myIsPoly || myNbNodes == 1 ) ? 1000 : myNbNodes));
417 ReverseOrDulicate = (myElementType == SMDSAbs_Face || myElementType == SMDSAbs_Volume ) ? new QCheckBox(tr("SMESH_REVERSE"), GroupC1) : 0;
418 if ( myElementType == SMDSAbs_0DElement )
419 ReverseOrDulicate = new QCheckBox(tr("SMESH_DUPLICATE_0D"), GroupC1);
421 DiameterSpinBox = ( myGeomType == SMDSEntity_Ball ) ? new SMESHGUI_SpinBox(GroupC1) : 0;
422 QLabel* diameterLabel = DiameterSpinBox ? new QLabel( tr("BALL_DIAMETER"),GroupC1) : 0;
424 GroupC1Layout->addWidget(TextLabelC1A1, 0, 0);
425 GroupC1Layout->addWidget(SelectButtonC1A1, 0, 1);
426 GroupC1Layout->addWidget(LineEditC1A1, 0, 2);
427 if ( ReverseOrDulicate ) {
428 GroupC1Layout->addWidget(ReverseOrDulicate, 1, 0, 1, 3);
430 if ( DiameterSpinBox ) {
431 GroupC1Layout->addWidget(diameterLabel, 1, 0);
432 GroupC1Layout->addWidget(DiameterSpinBox, 1, 1, 1, 2);
434 DiameterSpinBox->RangeStepAndValidator( 1e-7, 1e+9, 0.1 );
435 DiameterSpinBox->SetValue( SMESH::GetFloat("SMESH:ball_elem_diameter", 1) );
436 connect( DiameterSpinBox, SIGNAL( valueChanged ( double ) ), this, SLOT( onDiameterChanged( ) ) );
438 /* Add to group ************************************************/
439 GroupGroups = new QGroupBox( tr( "SMESH_ADD_TO_GROUP" ), this );
440 GroupGroups->setCheckable( true );
441 QHBoxLayout* GroupGroupsLayout = new QHBoxLayout(GroupGroups);
442 GroupGroupsLayout->setSpacing(SPACING);
443 GroupGroupsLayout->setMargin(MARGIN);
445 TextLabel_GroupName = new QLabel( tr( "SMESH_GROUP" ), GroupGroups );
446 ComboBox_GroupName = new QComboBox( GroupGroups );
447 ComboBox_GroupName->setEditable( true );
448 ComboBox_GroupName->setInsertPolicy( QComboBox::NoInsert );
450 GroupGroupsLayout->addWidget( TextLabel_GroupName );
451 GroupGroupsLayout->addWidget( ComboBox_GroupName, 1 );
453 /* Apply etc ***************************************************/
454 GroupButtons = new QGroupBox(this);
455 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
456 GroupButtonsLayout->setSpacing(SPACING);
457 GroupButtonsLayout->setMargin(MARGIN);
459 buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
460 buttonOk->setAutoDefault(true);
461 buttonOk->setDefault(true);
462 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
463 buttonApply->setAutoDefault(true);
464 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
465 buttonCancel->setAutoDefault(true);
466 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
467 buttonHelp->setAutoDefault(true);
469 GroupButtonsLayout->addWidget(buttonOk);
470 GroupButtonsLayout->addSpacing(10);
471 GroupButtonsLayout->addWidget(buttonApply);
472 GroupButtonsLayout->addSpacing(10);
473 GroupButtonsLayout->addStretch();
474 GroupButtonsLayout->addWidget(buttonCancel);
475 GroupButtonsLayout->addWidget(buttonHelp);
477 /***************************************************************/
478 aTopLayout->addWidget(GroupConstructors);
479 aTopLayout->addWidget(GroupC1);
480 aTopLayout->addWidget(GroupGroups);
481 aTopLayout->addWidget(GroupButtons);
483 Init(); /* Initialisations */
486 //=================================================================================
487 // function : ~SMESHGUI_AddMeshElementDlg()
488 // purpose : Destroys the object and frees any allocated resources
489 //=================================================================================
490 SMESHGUI_AddMeshElementDlg::~SMESHGUI_AddMeshElementDlg()
495 //=================================================================================
498 //=================================================================================
499 void SMESHGUI_AddMeshElementDlg::Init()
502 Constructor1->setChecked(true);
503 myEditCurrentArgument = LineEditC1A1;
504 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
506 /* reset "Add to group" control */
507 GroupGroups->setChecked( false );
508 //GroupGroups->setVisible( myElementType != SMDSAbs_0DElement );
513 /* signals and slots connections */
514 connect(buttonOk, SIGNAL(clicked()), SLOT(ClickOnOk()));
515 connect(buttonCancel, SIGNAL(clicked()), SLOT(reject()));
516 connect(buttonApply, SIGNAL(clicked()), SLOT(ClickOnApply()));
517 connect(buttonHelp, SIGNAL(clicked()), SLOT(ClickOnHelp()));
519 connect(SelectButtonC1A1,SIGNAL(clicked()), SLOT(SetEditCurrentArgument()));
520 connect(LineEditC1A1, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
521 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()),SLOT(DeactivateActiveDialog()));
523 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(SelectionIntoArgument()));
524 /* to close dialog if study frame change */
525 connect(mySMESHGUI, SIGNAL(SignalStudyFrameChanged()), SLOT(reject()));
526 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), SLOT(reject()));
527 connect(mySMESHGUI, SIGNAL(SignalActivatedViewManager()), SLOT(onOpenView()));
528 connect(mySMESHGUI, SIGNAL(SignalCloseView()), SLOT(onCloseView()));
530 if (ReverseOrDulicate)
531 connect(ReverseOrDulicate, SIGNAL(stateChanged(int)), SLOT(CheckBox(int)));
533 // set selection mode
534 SMESH::SetPointRepresentation(true);
536 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
537 aViewWindow->SetSelectionMode( NodeSelection );
541 SelectionIntoArgument();
544 //=================================================================================
545 // function : ClickOnApply()
547 //=================================================================================
548 void SMESHGUI_AddMeshElementDlg::ClickOnApply()
553 if (myNbOkNodes && !SMESHGUI::isStudyLocked()) {
555 QStringList aListId = myEditCurrentArgument->text().split(" ", QString::SkipEmptyParts);
556 SMESH::smIdType_array_var anArrayOfIndices = new SMESH::smIdType_array;
557 anArrayOfIndices->length(aListId.count());
558 const std::vector<int>& revIndex = SMDS_MeshCell::reverseSmdsOrder( myGeomType );
559 if ( ReverseOrDulicate && ReverseOrDulicate->isChecked() && (int)revIndex.size() == aListId.count() )
560 for (int i = 0; i < aListId.count(); i++)
561 anArrayOfIndices[i] = aListId[ revIndex[i] ].toInt();
562 else if ( ReverseOrDulicate && ReverseOrDulicate->isChecked() && revIndex.empty() ) // polygon
563 for (int i = 0; i < aListId.count(); i++)
564 anArrayOfIndices[i] = aListId[ aListId.count()-1 - i ].toInt();
566 for (int i = 0; i < aListId.count(); i++)
567 anArrayOfIndices[i] = aListId[ i ].toInt();
569 bool addToGroup = GroupGroups->isChecked();
572 SMESH::SMESH_GroupBase_var aGroup;
575 aGroupName = ComboBox_GroupName->currentText();
576 for ( int i = 1; i <= ComboBox_GroupName->count(); i++ ) {
577 QString aName = ComboBox_GroupName->itemText( i );
578 if ( aGroupName == aName && ( i == ComboBox_GroupName->currentIndex() || idx == 0 ) )
581 if ( idx > 0 && idx <= myGroups.count() ) {
582 SMESH::SMESH_GroupOnGeom_var aGeomGroup = SMESH::SMESH_GroupOnGeom::_narrow( myGroups[idx-1] );
583 if ( !aGeomGroup->_is_nil() ) {
584 int res = SUIT_MessageBox::question( this, tr( "SMESH_WRN_WARNING" ),
585 tr( "MESH_STANDALONE_GRP_CHOSEN" ).arg( aGroupName ),
586 tr( "SMESH_BUT_YES" ), tr( "SMESH_BUT_NO" ), 0, 1 );
587 if ( res == 1 ) return;
589 SMESH::SMESH_GroupOnFilter_var aFilterGroup = SMESH::SMESH_GroupOnFilter::_narrow( myGroups[idx-1] );
590 if ( !aFilterGroup->_is_nil() ) {
591 int res = SUIT_MessageBox::question( this, tr( "SMESH_WRN_WARNING" ),
592 tr( "MESH_FILTER_GRP_CHOSEN" ).arg( aGroupName ),
593 tr( "SMESH_BUT_YES" ), tr( "SMESH_BUT_NO" ), 0, 1 );
594 if ( res == 1 ) return;
596 aGroup = myGroups[idx-1];
600 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
601 SMESH::smIdType_array_var anIdList = new SMESH::smIdType_array;
602 anIdList->length( 1 );
604 smIdType nbElemsBefore = 0;
606 switch (myElementType) {
607 case SMDSAbs_0DElement: {
608 bool duplicateElements = ReverseOrDulicate->isChecked();
609 nbElemsBefore = myMesh->Nb0DElements();
610 anIdList->length( anArrayOfIndices->length() );
611 for ( size_t i = 0; i < anArrayOfIndices->length(); ++i )
612 anIdList[i] = aMeshEditor->Add0DElement(anArrayOfIndices[i], duplicateElements);
614 SMESH::smIdType nbAdded = myMesh->Nb0DElements() - nbElemsBefore;
615 if ( !duplicateElements && nbAdded < anArrayOfIndices->length() )
616 SUIT_MessageBox::information(SMESHGUI::desktop(),
617 tr("SMESH_INFORMATION"),
618 tr("NB_ADDED").arg( nbAdded ));
622 if ( myGeomType == SMDSEntity_Ball ) {
623 nbElemsBefore = myMesh->NbBalls();
624 anIdList->length( anArrayOfIndices->length() );
625 for ( size_t i = 0; i < anArrayOfIndices->length(); ++i )
626 anIdList[i] = aMeshEditor->AddBall(anArrayOfIndices[i],
627 DiameterSpinBox->GetValue());
631 nbElemsBefore = myMesh->NbEdges();
632 anIdList[0] = aMeshEditor->AddEdge(anArrayOfIndices.inout()); break;
634 nbElemsBefore = myMesh->NbFaces();
636 anIdList[0] = aMeshEditor->AddPolygonalFace(anArrayOfIndices.inout());
638 anIdList[0] = aMeshEditor->AddFace(anArrayOfIndices.inout());
641 nbElemsBefore = myMesh->NbVolumes();
642 anIdList[0] = aMeshEditor->AddVolume(anArrayOfIndices.inout()); break;
645 if ( anIdList[0] > 0 && addToGroup && !aGroupName.isEmpty() ) {
646 SMESH::SMESH_Group_var aGroupUsed;
647 if ( aGroup->_is_nil() ) {
649 aGroupUsed = SMESH::AddGroup( myMesh, (SMESH::ElementType)myElementType, aGroupName );
650 if ( !aGroupUsed->_is_nil() ) {
651 myGroups.append(SMESH::SMESH_GroupBase::_duplicate(aGroupUsed));
652 ComboBox_GroupName->addItem( aGroupName );
656 SMESH::SMESH_GroupOnGeom_var aGeomGroup = SMESH::SMESH_GroupOnGeom::_narrow( aGroup );
657 SMESH::SMESH_GroupOnFilter_var aFilterGroup = SMESH::SMESH_GroupOnFilter::_narrow( aGroup );
658 if ( !aGeomGroup->_is_nil() ) {
659 aGroupUsed = myMesh->ConvertToStandalone( aGeomGroup );
660 if ( !aGroupUsed->_is_nil() && idx > 0 ) {
661 myGroups[idx-1] = SMESH::SMESH_GroupBase::_duplicate(aGroupUsed);
662 SMESHGUI::GetSMESHGUI()->getApp()->updateObjectBrowser();
665 else if ( !aFilterGroup->_is_nil() ) {
666 aGroupUsed = myMesh->ConvertToStandalone( aFilterGroup );
667 if ( !aGroupUsed->_is_nil() && idx > 0 ) {
668 myGroups[idx-1] = SMESH::SMESH_GroupBase::_duplicate(aGroupUsed);
669 SMESHGUI::GetSMESHGUI()->getApp()->updateObjectBrowser();
673 aGroupUsed = SMESH::SMESH_Group::_narrow( aGroup );
676 if ( !aGroupUsed->_is_nil() )
677 aGroupUsed->Add( anIdList.inout() );
680 SALOME_ListIO aList; aList.Append( myActor->getIO() );
681 mySelector->ClearIndex();
682 mySelectionMgr->setSelectedObjects( aList, false );
684 mySimulation->SetVisibility(false);
686 if ( nbElemsBefore == 0 )
688 // 1st element of the type has been added, update actor to show this entity
689 unsigned int aMode = myActor->GetEntityMode();
690 switch ( myElementType ) {
692 myActor->SetRepresentation(SMESH_Actor::eEdge);
693 myActor->SetEntityMode( aMode |= SMESH_Actor::eEdges ); break;
695 myActor->SetRepresentation(SMESH_Actor::eSurface);
696 myActor->SetEntityMode( aMode |= SMESH_Actor::eFaces ); break;
698 myActor->SetRepresentation(SMESH_Actor::eSurface);
699 myActor->SetEntityMode( aMode |= SMESH_Actor::eVolumes ); break;
704 buttonOk->setEnabled(false);
705 buttonApply->setEnabled(false);
707 myEditCurrentArgument->setText("");
711 SMESHGUI::Modified();
715 //=================================================================================
716 // function : ClickOnOk()
718 //=================================================================================
719 void SMESHGUI_AddMeshElementDlg::ClickOnOk()
725 //=================================================================================
726 // function : reject()
728 //=================================================================================
729 void SMESHGUI_AddMeshElementDlg::reject()
731 mySimulation->SetVisibility(false);
732 SMESH::SetPointRepresentation(false);
733 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
734 aViewWindow->SetSelectionMode( ActorSelection );
735 disconnect(mySelectionMgr, 0, this, 0);
736 mySMESHGUI->ResetState();
740 //=================================================================================
741 // function : ClickOnHelp()
743 //=================================================================================
744 void SMESHGUI_AddMeshElementDlg::ClickOnHelp()
746 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
748 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""),
753 platform = "winapplication";
755 platform = "application";
757 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
758 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
759 arg(app->resourceMgr()->stringValue("ExternalBrowser",
761 arg(myHelpFileName));
765 //=================================================================================
766 // function : onTextChange()
768 //=================================================================================
769 void SMESHGUI_AddMeshElementDlg::onTextChange (const QString& theNewText)
776 buttonOk->setEnabled(false);
777 buttonApply->setEnabled(false);
779 mySimulation->SetVisibility(false);
781 // highlight entered nodes
782 SMDS_Mesh* aMesh = 0;
784 aMesh = myActor->GetObject()->GetMesh();
787 SVTK_TVtkIDsMap newIndices;
789 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
791 for (int i = 0; i < aListId.count(); i++) {
792 if( const SMDS_MeshNode * n = aMesh->FindNode( aListId[ i ].toInt() ) )
794 newIndices.Add( n->GetID() );
801 mySelector->AddOrRemoveIndex( myActor->getIO(), newIndices, false );
802 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
803 aViewWindow->highlight( myActor->getIO(), true, true );
805 myNbOkNodes = ( allOk && ( myNbNodes == aListId.count() || myNbNodes == 1 ));
809 if ( !allOk || myElementType != SMDSAbs_Face || aListId.count() < 3 )
812 myNbOkNodes = aListId.count();
817 buttonOk->setEnabled(true);
818 buttonApply->setEnabled(true);
825 //=================================================================================
826 // function : SelectionIntoArgument()
827 // purpose : Called when selection has changed
828 //=================================================================================
829 void SMESHGUI_AddMeshElementDlg::SelectionIntoArgument()
838 myEditCurrentArgument->setText("");
841 if (!GroupButtons->isEnabled()) // inactive
844 buttonOk->setEnabled(false);
845 buttonApply->setEnabled(false);
847 mySimulation->SetVisibility(false);
848 // SMESH::SetPointRepresentation(true);
850 QString aCurrentEntry = myEntry;
854 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
856 if (aList.Extent() != 1)
859 Handle(SALOME_InteractiveObject) anIO = aList.First();
860 myEntry = anIO->getEntry();
861 myMesh = SMESH::GetMeshByIO(anIO);
862 if (myMesh->_is_nil())
866 if ( !myMesh->_is_nil() && myEntry != aCurrentEntry ) {
868 ComboBox_GroupName->clear();
869 ComboBox_GroupName->addItem( QString() );
870 SMESH::ListOfGroups aListOfGroups = *myMesh->GetGroups();
871 for ( int i = 0, n = aListOfGroups.length(); i < n; i++ ) {
872 SMESH::SMESH_GroupBase_var aGroup = aListOfGroups[i];
873 if ( !aGroup->_is_nil() && aGroup->GetType() == (SMESH::ElementType)myElementType ) {
874 QString aGroupName( aGroup->GetName() );
875 if ( !aGroupName.isEmpty() ) {
876 myGroups.append(SMESH::SMESH_GroupBase::_duplicate(aGroup));
877 ComboBox_GroupName->addItem( aGroupName );
883 myActor = SMESH::FindActorByEntry(anIO->getEntry());
887 // get selected nodes
888 QString aString = "";
889 int nbNodes = SMESH::GetNameOfSelectedNodes(mySelector,myActor->getIO(),aString);
891 myEditCurrentArgument->setText(aString);
893 if (myIsPoly && myElementType == SMDSAbs_Face && nbNodes >= 3 ) {
895 } else if (myNbNodes != nbNodes && myNbNodes != 1) {
900 myNbOkNodes = nbNodes;
902 buttonOk->setEnabled(true);
903 buttonApply->setEnabled(true);
908 //=================================================================================
909 // function : displaySimulation()
911 //=================================================================================
912 void SMESHGUI_AddMeshElementDlg::displaySimulation()
914 if (myNbOkNodes && GroupButtons->isEnabled()) {
915 SMESH::TElementSimulation::TVTKIds anIds;
916 QStringList aListId = myEditCurrentArgument->text().split(" ", QString::SkipEmptyParts);
917 for (int i = 0; i < aListId.count(); i++)
918 anIds.push_back(myActor->GetObject()->GetNodeVTKId(aListId[ i ].toInt()));
920 if (ReverseOrDulicate && ReverseOrDulicate->isChecked())
922 const std::vector<int>& i = SMDS_MeshCell::reverseSmdsOrder( myGeomType );
923 if ( i.size() != anIds.size() ) // polygon
924 std::reverse( anIds.begin(), anIds.end() );
926 SMDS_MeshCell::applyInterlace( i, anIds );
929 vtkIdType aType = SMDS_MeshCell::toVtkType( myGeomType );
930 if(aType == VTK_POLY_VERTEX) {
931 mySimulation->SetBallPosition(myActor,anIds,DiameterSpinBox->GetValue());
933 mySimulation->SetPosition(myActor,aType,anIds);
939 //=================================================================================
940 // function : SetEditCurrentArgument()
942 //=================================================================================
943 void SMESHGUI_AddMeshElementDlg::SetEditCurrentArgument()
945 QPushButton* send = (QPushButton*)sender();
946 if (send == SelectButtonC1A1) {
947 LineEditC1A1->setFocus();
948 myEditCurrentArgument = LineEditC1A1;
950 SelectionIntoArgument();
953 //=================================================================================
954 // function : DeactivateActiveDialog()
956 //=================================================================================
957 void SMESHGUI_AddMeshElementDlg::DeactivateActiveDialog()
959 if (GroupConstructors->isEnabled()) {
960 GroupConstructors->setEnabled(false);
961 GroupC1->setEnabled(false);
962 GroupButtons->setEnabled(false);
963 mySimulation->SetVisibility(false);
964 mySMESHGUI->ResetState();
965 mySMESHGUI->SetActiveDialogBox(0);
969 //=================================================================================
970 // function : ActivateThisDialog()
972 //=================================================================================
973 void SMESHGUI_AddMeshElementDlg::ActivateThisDialog()
975 /* Emit a signal to deactivate the active dialog */
976 mySMESHGUI->EmitSignalDeactivateDialog();
978 GroupConstructors->setEnabled(true);
979 GroupC1->setEnabled(true);
980 GroupButtons->setEnabled(true);
982 SMESH::SetPointRepresentation(true);
984 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
985 aViewWindow->SetSelectionMode( NodeSelection );
986 SelectionIntoArgument();
989 //=================================================================================
990 // function : enterEvent()
992 //=================================================================================
993 void SMESHGUI_AddMeshElementDlg::enterEvent (QEvent*)
995 if ( !GroupConstructors->isEnabled() ) {
996 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
997 if ( aViewWindow && !mySelector && !mySimulation) {
998 mySelector = aViewWindow->GetSelector();
999 mySimulation = new SMESH::TElementSimulation(
1000 dynamic_cast<SalomeApp_Application*>( mySMESHGUI->application() ) );
1002 ActivateThisDialog();
1006 //=================================================================================
1007 // function : CheckBox()
1009 //=================================================================================
1010 void SMESHGUI_AddMeshElementDlg::CheckBox (int state)
1016 mySimulation->SetVisibility(false);
1017 displaySimulation();
1021 //=================================================================================
1022 // function : keyPressEvent()
1024 //=================================================================================
1025 void SMESHGUI_AddMeshElementDlg::keyPressEvent( QKeyEvent* e )
1027 QDialog::keyPressEvent( e );
1028 if ( e->isAccepted() )
1031 if ( e->key() == Qt::Key_F1 ) {
1037 //=================================================================================
1038 // function : onDiameterChanged()
1040 //=================================================================================
1041 void SMESHGUI_AddMeshElementDlg::onDiameterChanged(){
1042 displaySimulation();
1045 //=================================================================================
1046 // function : onOpenView()
1048 //=================================================================================
1049 void SMESHGUI_AddMeshElementDlg::onOpenView()
1051 if ( mySelector && mySimulation ) {
1052 mySimulation->SetVisibility(false);
1053 SMESH::SetPointRepresentation(false);
1056 mySelector = SMESH::GetViewWindow( mySMESHGUI )->GetSelector();
1057 mySimulation = new SMESH::TElementSimulation(
1058 dynamic_cast<SalomeApp_Application*>( mySMESHGUI->application() ) );
1059 ActivateThisDialog();
1063 //=================================================================================
1064 // function : onCloseView()
1066 //=================================================================================
1067 void SMESHGUI_AddMeshElementDlg::onCloseView()
1069 DeactivateActiveDialog();
1071 delete mySimulation;
1075 //=================================================================================
1076 // function : isValid()
1078 //=================================================================================
1079 bool SMESHGUI_AddMeshElementDlg::isValid()
1081 if( GroupGroups->isChecked() && ComboBox_GroupName->currentText().isEmpty() ) {
1082 SUIT_MessageBox::warning( this, tr( "SMESH_WRN_WARNING" ), tr( "GROUP_NAME_IS_EMPTY" ) );