1 // Copyright (C) 2007-2014 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>
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 aBallProp->SetPointSize(aBallElemSize);
175 myBallPolyData = vtkPolyData::New();
176 myBallPolyData->Allocate();
178 myBallMapper = VTKViewer_PolyDataMapper::New();
179 myBallMapper->SetInputData(myBallPolyData);
180 myBallMapper->SetBallEnabled(true);
182 myBallActor = SALOME_Actor::New();
183 myBallActor->PickableOff();
184 myBallActor->SetVisibility(false);
185 myBallActor->SetProperty(aBallProp);
186 myBallActor->SetMapper(myBallMapper);
189 myVTKViewWindow->AddActor(myBallActor);
192 typedef std::vector<vtkIdType> TVTKIds;
193 void SetPosition (SMESH_Actor* theActor,
197 vtkUnstructuredGrid *aGrid = theActor->GetUnstructuredGrid();
198 myGrid->SetPoints(aGrid->GetPoints());
201 const std::vector<int>& interlace = SMDS_MeshCell::toVtkOrder( VTKCellType( theType ));
202 SMDS_MeshCell::applyInterlace( interlace, theIds );
204 vtkIdList *anIds = vtkIdList::New();
205 for (int i = 0, iEnd = theIds.size(); i < iEnd; i++)
206 anIds->InsertId(i,theIds[i]);
208 myGrid->InsertNextCell(theType,anIds);
213 SetVisibility(true, theActor->GetFacesOriented(), false);
216 void SetBallPosition(SMESH_Actor* theActor,TVTKIds& theIds, double theDiameter) {
217 vtkUnstructuredGrid *aGrid = theActor->GetUnstructuredGrid();
218 myBallPolyData->Reset();
219 myBallPolyData->DeleteCells();
220 myBallPolyData->SetPoints(aGrid->GetPoints());
222 vtkDataArray* aScalars = vtkDataArray::CreateDataArray(VTK_DOUBLE);
223 aScalars->SetNumberOfComponents(1);
224 aScalars->SetNumberOfTuples(theIds.size());
225 myBallPolyData->GetCellData()->SetScalars(aScalars);
228 vtkIdList *anIds = vtkIdList::New();
229 anIds->SetNumberOfIds(1);
230 for (int i = 0, iEnd = theIds.size(); i < iEnd; i++){
231 anIds->InsertId(0,theIds[i]);
232 vtkIdType anId = myBallPolyData->InsertNextCell(VTK_POLY_VERTEX,anIds);
233 double d = theDiameter * theActor->GetBallScale();
234 aScalars->SetTuple(anId,&d);
239 myBallPolyData->Modified();
240 SetVisibility (false, false, true);
243 void SetVisibility (bool theVisibility, bool theShowOrientation = false, bool theShowBalls = false)
245 myPreviewActor->SetVisibility(theVisibility);
246 myFaceOrientation->SetVisibility(theShowOrientation);
247 myBallActor->SetVisibility(theShowBalls);
248 RepaintCurrentView();
252 ~TElementSimulation()
254 myMapper->RemoveAllInputs();
255 myFaceOrientationDataMapper->RemoveAllInputs();
256 myBallMapper->RemoveAllInputs();
258 if (FindVtkViewWindow(myApplication->activeViewManager(), myViewWindow)) {
259 myVTKViewWindow->RemoveActor(myPreviewActor,false,false);
260 myVTKViewWindow->RemoveActor(myFaceOrientation,false,false);
261 myVTKViewWindow->RemoveActor(myBallActor,false,false);
266 myPreviewActor->Delete();
268 myFaceOrientationFilter->Delete();
269 myFaceOrientationDataMapper->Delete();
270 myFaceOrientation->Delete();
272 myBallMapper->Delete();
273 myBallPolyData->Delete();
274 myBallActor->Delete();
279 //=================================================================================
280 // function : SMESHGUI_AddMeshElementDlg()
281 // purpose : constructor
282 //=================================================================================
283 SMESHGUI_AddMeshElementDlg::SMESHGUI_AddMeshElementDlg( SMESHGUI* theModule,
284 SMDSAbs_EntityType ElementType)
285 : QDialog( SMESH::GetDesktop( theModule ) ),
286 mySMESHGUI( theModule ),
287 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
291 setAttribute( Qt::WA_DeleteOnClose, true );
293 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>
294 (SUIT_Session::session()->activeApplication());
296 mySimulation = new SMESH::TElementSimulation (anApp);
297 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
298 myGeomType = ElementType;
299 myElementType = SMDSAbs_Volume;
301 // verify nb nodes and type
303 switch ( myGeomType ) {
306 myElementType = SMDSAbs_0DElement;
308 myHelpFileName = "adding_nodes_and_elements_page.html#adding_0delems_anchor";
310 case SMDSEntity_Ball:
312 myElementType = SMDSAbs_Ball;
314 myHelpFileName = "adding_nodes_and_elements_page.html#adding_ball_anchor";
316 case SMDSEntity_Edge:
318 myElementType = SMDSAbs_Edge;
320 myHelpFileName = "adding_nodes_and_elements_page.html#adding_edges_anchor";
322 case SMDSEntity_Triangle:
324 elemName = "TRIANGLE";
325 myElementType = SMDSAbs_Face;
326 myHelpFileName = "adding_nodes_and_elements_page.html#adding_triangles_anchor";
328 case SMDSEntity_Quadrangle:
330 myElementType = SMDSAbs_Face;
331 elemName = "QUADRANGLE";
332 myHelpFileName = "adding_nodes_and_elements_page.html#adding_quadrangles_anchor";
334 case SMDSEntity_Polygon:
336 myElementType = SMDSAbs_Face;
337 elemName = "POLYGON";
339 myHelpFileName = "adding_nodes_and_elements_page.html#adding_polygons_anchor";
341 case SMDSEntity_Tetra:
344 myHelpFileName = "adding_nodes_and_elements_page.html#adding_tetrahedrons_anchor";
346 case SMDSEntity_Pyramid:
348 elemName = "PYRAMID";
349 myHelpFileName = "adding_nodes_and_elements_page.html#adding_pyramids_anchor";
351 case SMDSEntity_Hexa:
354 myHelpFileName = "adding_nodes_and_elements_page.html#adding_hexahedrons_anchor";
356 case SMDSEntity_Penta:
359 myHelpFileName = "adding_nodes_and_elements_page.html#adding_pentahedrons_anchor";
361 case SMDSEntity_Hexagonal_Prism:
364 myHelpFileName = "adding_nodes_and_elements_page.html#adding_octahedrons_anchor";
369 myHelpFileName = "adding_nodes_and_elements_page.html#adding_edges_anchor";
372 QString iconName = tr(QString("ICON_DLG_%1").arg(elemName).toLatin1().data());
373 QString buttonGrTitle = tr(QString("SMESH_%1").arg(elemName).toLatin1().data());
374 QString caption = tr(QString("SMESH_ADD_%1_TITLE").arg(elemName).toLatin1().data());
375 QString grBoxTitle = tr(QString("SMESH_ADD_%1").arg(elemName).toLatin1().data());
377 QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", iconName));
378 QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
380 setWindowTitle(caption);
381 setSizeGripEnabled(true);
383 QVBoxLayout* aTopLayout = new QVBoxLayout(this);
384 aTopLayout->setSpacing(SPACING);
385 aTopLayout->setMargin(MARGIN);
387 /* Constructor *************************************************/
388 GroupConstructors = new QGroupBox(buttonGrTitle, this);
389 QButtonGroup* ButtonGroup = new QButtonGroup(this);
390 QHBoxLayout* GroupConstructorsLayout = new QHBoxLayout(GroupConstructors);
391 GroupConstructorsLayout->setSpacing(SPACING);
392 GroupConstructorsLayout->setMargin(MARGIN);
394 Constructor1 = new QRadioButton(GroupConstructors);
395 Constructor1->setIcon(image0);
396 Constructor1->setChecked(true);
398 GroupConstructorsLayout->addWidget(Constructor1);
399 ButtonGroup->addButton( Constructor1, 0 );
401 /* Nodes & Reverse *********************************************/
402 GroupC1 = new QGroupBox(grBoxTitle, this);
403 QGridLayout* GroupC1Layout = new QGridLayout(GroupC1);
404 GroupC1Layout->setSpacing(SPACING);
405 GroupC1Layout->setMargin(MARGIN);
407 TextLabelC1A1 = new QLabel(tr("SMESH_ID_NODES"), GroupC1);
408 SelectButtonC1A1 = new QPushButton(GroupC1);
409 SelectButtonC1A1->setIcon(image1);
410 LineEditC1A1 = new QLineEdit(GroupC1);
411 LineEditC1A1->setValidator
412 (new SMESHGUI_IdValidator(this, ( myIsPoly || myNbNodes == 1 ) ? 1000 : myNbNodes));
414 Reverse = (myElementType == SMDSAbs_Face || myElementType == SMDSAbs_Volume ) ? new QCheckBox(tr("SMESH_REVERSE"), GroupC1) : 0;
416 DiameterSpinBox = ( myGeomType == SMDSEntity_Ball ) ? new SMESHGUI_SpinBox(GroupC1) : 0;
417 QLabel* diameterLabel = DiameterSpinBox ? new QLabel( tr("BALL_DIAMETER"),GroupC1) : 0;
419 GroupC1Layout->addWidget(TextLabelC1A1, 0, 0);
420 GroupC1Layout->addWidget(SelectButtonC1A1, 0, 1);
421 GroupC1Layout->addWidget(LineEditC1A1, 0, 2);
423 GroupC1Layout->addWidget(Reverse, 1, 0, 1, 3);
425 if ( DiameterSpinBox ) {
426 GroupC1Layout->addWidget(diameterLabel, 1, 0);
427 GroupC1Layout->addWidget(DiameterSpinBox, 1, 1, 1, 2);
429 DiameterSpinBox->RangeStepAndValidator( 1e-7, 1e+9, 0.1 );
430 DiameterSpinBox->SetValue( 1. );
431 connect( DiameterSpinBox, SIGNAL( valueChanged ( double ) ), this, SLOT( onDiameterChanged( ) ) );
433 /* Add to group ************************************************/
434 GroupGroups = new QGroupBox( tr( "SMESH_ADD_TO_GROUP" ), this );
435 GroupGroups->setCheckable( true );
436 QHBoxLayout* GroupGroupsLayout = new QHBoxLayout(GroupGroups);
437 GroupGroupsLayout->setSpacing(SPACING);
438 GroupGroupsLayout->setMargin(MARGIN);
440 TextLabel_GroupName = new QLabel( tr( "SMESH_GROUP" ), GroupGroups );
441 ComboBox_GroupName = new QComboBox( GroupGroups );
442 ComboBox_GroupName->setEditable( true );
443 ComboBox_GroupName->setInsertPolicy( QComboBox::NoInsert );
445 GroupGroupsLayout->addWidget( TextLabel_GroupName );
446 GroupGroupsLayout->addWidget( ComboBox_GroupName, 1 );
448 /* Apply etc ***************************************************/
449 GroupButtons = new QGroupBox(this);
450 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
451 GroupButtonsLayout->setSpacing(SPACING);
452 GroupButtonsLayout->setMargin(MARGIN);
454 buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
455 buttonOk->setAutoDefault(true);
456 buttonOk->setDefault(true);
457 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
458 buttonApply->setAutoDefault(true);
459 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
460 buttonCancel->setAutoDefault(true);
461 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
462 buttonHelp->setAutoDefault(true);
464 GroupButtonsLayout->addWidget(buttonOk);
465 GroupButtonsLayout->addSpacing(10);
466 GroupButtonsLayout->addWidget(buttonApply);
467 GroupButtonsLayout->addSpacing(10);
468 GroupButtonsLayout->addStretch();
469 GroupButtonsLayout->addWidget(buttonCancel);
470 GroupButtonsLayout->addWidget(buttonHelp);
472 /***************************************************************/
473 aTopLayout->addWidget(GroupConstructors);
474 aTopLayout->addWidget(GroupC1);
475 aTopLayout->addWidget(GroupGroups);
476 aTopLayout->addWidget(GroupButtons);
478 Init(); /* Initialisations */
481 //=================================================================================
482 // function : ~SMESHGUI_AddMeshElementDlg()
483 // purpose : Destroys the object and frees any allocated resources
484 //=================================================================================
485 SMESHGUI_AddMeshElementDlg::~SMESHGUI_AddMeshElementDlg()
490 //=================================================================================
493 //=================================================================================
494 void SMESHGUI_AddMeshElementDlg::Init()
497 Constructor1->setChecked(true);
498 myEditCurrentArgument = LineEditC1A1;
499 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
501 /* reset "Add to group" control */
502 GroupGroups->setChecked( false );
503 //GroupGroups->setVisible( myElementType != SMDSAbs_0DElement );
508 /* signals and slots connections */
509 connect(buttonOk, SIGNAL(clicked()), SLOT(ClickOnOk()));
510 connect(buttonCancel, SIGNAL(clicked()), SLOT(reject()));
511 connect(buttonApply, SIGNAL(clicked()), SLOT(ClickOnApply()));
512 connect(buttonHelp, SIGNAL(clicked()), SLOT(ClickOnHelp()));
514 connect(SelectButtonC1A1,SIGNAL(clicked()), SLOT(SetEditCurrentArgument()));
515 connect(LineEditC1A1, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
516 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()),SLOT(DeactivateActiveDialog()));
517 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(SelectionIntoArgument()));
518 /* to close dialog if study frame change */
519 connect(mySMESHGUI, SIGNAL(SignalStudyFrameChanged()), SLOT(reject()));
520 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), SLOT(reject()));
523 connect(Reverse, SIGNAL(stateChanged(int)), SLOT(CheckBox(int)));
525 // set selection mode
526 SMESH::SetPointRepresentation(true);
528 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
529 aViewWindow->SetSelectionMode( NodeSelection );
533 SelectionIntoArgument();
536 //=================================================================================
537 // function : ClickOnApply()
539 //=================================================================================
540 void SMESHGUI_AddMeshElementDlg::ClickOnApply()
545 if (myNbOkNodes && !mySMESHGUI->isActiveStudyLocked()) {
547 QStringList aListId = myEditCurrentArgument->text().split(" ", QString::SkipEmptyParts);
548 SMESH::long_array_var anArrayOfIndices = new SMESH::long_array;
549 anArrayOfIndices->length(aListId.count());
550 const std::vector<int>& revIndex = SMDS_MeshCell::reverseSmdsOrder( myGeomType );
551 if ( Reverse && Reverse->isChecked() && !revIndex.empty() )
552 for (int i = 0; i < aListId.count(); i++)
553 anArrayOfIndices[i] = aListId[ revIndex[i] ].toInt();
554 else if ( Reverse && Reverse->isChecked() && revIndex.empty() ) // polygon
555 for (int i = 0; i < aListId.count(); i++)
556 anArrayOfIndices[i] = aListId[ aListId.count()-1 - i ].toInt();
558 for (int i = 0; i < aListId.count(); i++)
559 anArrayOfIndices[i] = aListId[ i ].toInt();
561 bool addToGroup = GroupGroups->isChecked();
564 SMESH::SMESH_GroupBase_var aGroup;
567 aGroupName = ComboBox_GroupName->currentText();
568 for ( int i = 1; i <= ComboBox_GroupName->count(); i++ ) {
569 QString aName = ComboBox_GroupName->itemText( i );
570 if ( aGroupName == aName && ( i == ComboBox_GroupName->currentIndex() || idx == 0 ) )
573 if ( idx > 0 && idx <= myGroups.count() ) {
574 SMESH::SMESH_GroupOnGeom_var aGeomGroup = SMESH::SMESH_GroupOnGeom::_narrow( myGroups[idx-1] );
575 if ( !aGeomGroup->_is_nil() ) {
576 int res = SUIT_MessageBox::question( this, tr( "SMESH_WRN_WARNING" ),
577 tr( "MESH_STANDALONE_GRP_CHOSEN" ).arg( aGroupName ),
578 tr( "SMESH_BUT_YES" ), tr( "SMESH_BUT_NO" ), 0, 1 );
579 if ( res == 1 ) return;
581 aGroup = myGroups[idx-1];
585 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
586 SMESH::long_array_var anIdList = new SMESH::long_array;
587 anIdList->length( 1 );
589 const bool onlyNodesInMesh = ( myMesh->NbElements() == 0 );
591 switch (myElementType) {
592 case SMDSAbs_0DElement:
593 anIdList->length( anArrayOfIndices->length() );
594 for ( size_t i = 0; i < anArrayOfIndices->length(); ++i )
595 anIdList[i] = aMeshEditor->Add0DElement(anArrayOfIndices[i]);
598 if ( myGeomType == SMDSEntity_Ball ) {
599 anIdList->length( anArrayOfIndices->length() );
600 for ( size_t i = 0; i < anArrayOfIndices->length(); ++i )
601 anIdList[i] = aMeshEditor->AddBall(anArrayOfIndices[i],
602 DiameterSpinBox->GetValue());
606 anIdList[0] = aMeshEditor->AddEdge(anArrayOfIndices.inout()); break;
609 anIdList[0] = aMeshEditor->AddPolygonalFace(anArrayOfIndices.inout());
611 anIdList[0] = aMeshEditor->AddFace(anArrayOfIndices.inout());
614 anIdList[0] = aMeshEditor->AddVolume(anArrayOfIndices.inout()); break;
617 if ( anIdList[0] > 0 && addToGroup && !aGroupName.isEmpty() ) {
618 SMESH::SMESH_Group_var aGroupUsed;
619 if ( aGroup->_is_nil() ) {
621 aGroupUsed = SMESH::AddGroup( myMesh, (SMESH::ElementType)myElementType, aGroupName );
622 if ( !aGroupUsed->_is_nil() ) {
623 myGroups.append(SMESH::SMESH_GroupBase::_duplicate(aGroupUsed));
624 ComboBox_GroupName->addItem( aGroupName );
628 SMESH::SMESH_GroupOnGeom_var aGeomGroup = SMESH::SMESH_GroupOnGeom::_narrow( aGroup );
629 if ( !aGeomGroup->_is_nil() ) {
630 aGroupUsed = myMesh->ConvertToStandalone( aGeomGroup );
631 if ( !aGroupUsed->_is_nil() && idx > 0 ) {
632 myGroups[idx-1] = SMESH::SMESH_GroupBase::_duplicate(aGroupUsed);
633 SMESHGUI::GetSMESHGUI()->getApp()->updateObjectBrowser();
637 aGroupUsed = SMESH::SMESH_Group::_narrow( aGroup );
640 if ( !aGroupUsed->_is_nil() )
641 aGroupUsed->Add( anIdList.inout() );
644 SALOME_ListIO aList; aList.Append( myActor->getIO() );
645 mySelector->ClearIndex();
646 mySelectionMgr->setSelectedObjects( aList, false );
648 mySimulation->SetVisibility(false);
649 if ( onlyNodesInMesh )
650 myActor->SetRepresentation( SMESH_Actor::eEdge ); // wireframe
653 buttonOk->setEnabled(false);
654 buttonApply->setEnabled(false);
656 myEditCurrentArgument->setText("");
660 SMESHGUI::Modified();
664 //=================================================================================
665 // function : ClickOnOk()
667 //=================================================================================
668 void SMESHGUI_AddMeshElementDlg::ClickOnOk()
674 //=================================================================================
675 // function : reject()
677 //=================================================================================
678 void SMESHGUI_AddMeshElementDlg::reject()
680 mySimulation->SetVisibility(false);
681 SMESH::SetPointRepresentation(false);
682 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
683 aViewWindow->SetSelectionMode( ActorSelection );
684 disconnect(mySelectionMgr, 0, this, 0);
685 mySMESHGUI->ResetState();
689 //=================================================================================
690 // function : ClickOnHelp()
692 //=================================================================================
693 void SMESHGUI_AddMeshElementDlg::ClickOnHelp()
695 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
697 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""),
702 platform = "winapplication";
704 platform = "application";
706 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
707 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
708 arg(app->resourceMgr()->stringValue("ExternalBrowser",
710 arg(myHelpFileName));
714 //=================================================================================
715 // function : onTextChange()
717 //=================================================================================
718 void SMESHGUI_AddMeshElementDlg::onTextChange (const QString& theNewText)
725 buttonOk->setEnabled(false);
726 buttonApply->setEnabled(false);
728 mySimulation->SetVisibility(false);
730 // hilight entered nodes
731 SMDS_Mesh* aMesh = 0;
733 aMesh = myActor->GetObject()->GetMesh();
736 TColStd_MapOfInteger newIndices;
738 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
740 for (int i = 0; i < aListId.count(); i++) {
741 if( const SMDS_MeshNode * n = aMesh->FindNode( aListId[ i ].toInt() ) )
743 newIndices.Add( n->GetID() );
750 mySelector->AddOrRemoveIndex( myActor->getIO(), newIndices, false );
751 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
752 aViewWindow->highlight( myActor->getIO(), true, true );
754 myNbOkNodes = ( allOk && ( myNbNodes == aListId.count() || myNbNodes == 1 ));
758 if ( !allOk || myElementType != SMDSAbs_Face || aListId.count() < 3 )
761 myNbOkNodes = aListId.count();
766 buttonOk->setEnabled(true);
767 buttonApply->setEnabled(true);
774 //=================================================================================
775 // function : SelectionIntoArgument()
776 // purpose : Called when selection has changed
777 //=================================================================================
778 void SMESHGUI_AddMeshElementDlg::SelectionIntoArgument()
787 myEditCurrentArgument->setText("");
790 if (!GroupButtons->isEnabled()) // inactive
793 buttonOk->setEnabled(false);
794 buttonApply->setEnabled(false);
796 mySimulation->SetVisibility(false);
797 // SMESH::SetPointRepresentation(true);
799 QString aCurrentEntry = myEntry;
803 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
805 if (aList.Extent() != 1)
808 Handle(SALOME_InteractiveObject) anIO = aList.First();
809 myEntry = anIO->getEntry();
810 myMesh = SMESH::GetMeshByIO(anIO);
811 if (myMesh->_is_nil())
815 if ( !myMesh->_is_nil() && myEntry != aCurrentEntry ) {
817 ComboBox_GroupName->clear();
818 ComboBox_GroupName->addItem( QString() );
819 SMESH::ListOfGroups aListOfGroups = *myMesh->GetGroups();
820 for ( int i = 0, n = aListOfGroups.length(); i < n; i++ ) {
821 SMESH::SMESH_GroupBase_var aGroup = aListOfGroups[i];
822 if ( !aGroup->_is_nil() && aGroup->GetType() == (SMESH::ElementType)myElementType ) {
823 QString aGroupName( aGroup->GetName() );
824 if ( !aGroupName.isEmpty() ) {
825 myGroups.append(SMESH::SMESH_GroupBase::_duplicate(aGroup));
826 ComboBox_GroupName->addItem( aGroupName );
832 myActor = SMESH::FindActorByEntry(anIO->getEntry());
836 // get selected nodes
837 QString aString = "";
838 int nbNodes = SMESH::GetNameOfSelectedNodes(mySelector,myActor->getIO(),aString);
840 myEditCurrentArgument->setText(aString);
842 if (myIsPoly && myElementType == SMDSAbs_Face && nbNodes >= 3 ) {
844 } else if (myNbNodes != nbNodes && myNbNodes != 1) {
849 myNbOkNodes = nbNodes;
851 buttonOk->setEnabled(true);
852 buttonApply->setEnabled(true);
857 //=================================================================================
858 // function : displaySimulation()
860 //=================================================================================
861 void SMESHGUI_AddMeshElementDlg::displaySimulation()
863 if (myNbOkNodes && GroupButtons->isEnabled()) {
864 SMESH::TElementSimulation::TVTKIds anIds;
865 QStringList aListId = myEditCurrentArgument->text().split(" ", QString::SkipEmptyParts);
866 for (int i = 0; i < aListId.count(); i++)
867 anIds.push_back(myActor->GetObject()->GetNodeVTKId(aListId[ i ].toInt()));
869 if (Reverse && Reverse->isChecked())
871 const std::vector<int>& i = SMDS_MeshCell::reverseSmdsOrder( myGeomType );
872 if ( i.empty() ) // polygon
873 std::reverse( anIds.begin(), anIds.end() );
875 SMDS_MeshCell::applyInterlace( i, anIds );
878 vtkIdType aType = SMDS_MeshCell::toVtkType( myGeomType );
879 if(aType == VTK_POLY_VERTEX) {
880 mySimulation->SetBallPosition(myActor,anIds,DiameterSpinBox->GetValue());
882 mySimulation->SetPosition(myActor,aType,anIds);
888 //=================================================================================
889 // function : SetEditCurrentArgument()
891 //=================================================================================
892 void SMESHGUI_AddMeshElementDlg::SetEditCurrentArgument()
894 QPushButton* send = (QPushButton*)sender();
895 if (send == SelectButtonC1A1) {
896 LineEditC1A1->setFocus();
897 myEditCurrentArgument = LineEditC1A1;
899 SelectionIntoArgument();
902 //=================================================================================
903 // function : DeactivateActiveDialog()
905 //=================================================================================
906 void SMESHGUI_AddMeshElementDlg::DeactivateActiveDialog()
908 if (GroupConstructors->isEnabled()) {
909 GroupConstructors->setEnabled(false);
910 GroupC1->setEnabled(false);
911 GroupButtons->setEnabled(false);
912 mySimulation->SetVisibility(false);
913 mySMESHGUI->ResetState();
914 mySMESHGUI->SetActiveDialogBox(0);
918 //=================================================================================
919 // function : ActivateThisDialog()
921 //=================================================================================
922 void SMESHGUI_AddMeshElementDlg::ActivateThisDialog()
924 /* Emit a signal to deactivate the active dialog */
925 mySMESHGUI->EmitSignalDeactivateDialog();
927 GroupConstructors->setEnabled(true);
928 GroupC1->setEnabled(true);
929 GroupButtons->setEnabled(true);
931 SMESH::SetPointRepresentation(true);
933 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
934 aViewWindow->SetSelectionMode( NodeSelection );
935 SelectionIntoArgument();
938 //=================================================================================
939 // function : enterEvent()
941 //=================================================================================
942 void SMESHGUI_AddMeshElementDlg::enterEvent (QEvent*)
944 if (GroupConstructors->isEnabled())
946 ActivateThisDialog();
949 //=================================================================================
950 // function : CheckBox()
952 //=================================================================================
953 void SMESHGUI_AddMeshElementDlg::CheckBox (int state)
959 mySimulation->SetVisibility(false);
964 //=================================================================================
965 // function : keyPressEvent()
967 //=================================================================================
968 void SMESHGUI_AddMeshElementDlg::keyPressEvent( QKeyEvent* e )
970 QDialog::keyPressEvent( e );
971 if ( e->isAccepted() )
974 if ( e->key() == Qt::Key_F1 ) {
980 //=================================================================================
981 // function : isValid
983 //=================================================================================
984 void SMESHGUI_AddMeshElementDlg::onDiameterChanged(){
988 //=================================================================================
989 // function : isValid
991 //=================================================================================
992 bool SMESHGUI_AddMeshElementDlg::isValid()
994 if( GroupGroups->isChecked() && ComboBox_GroupName->currentText().isEmpty() ) {
995 SUIT_MessageBox::warning( this, tr( "SMESH_WRN_WARNING" ), tr( "GROUP_NAME_IS_EMPTY" ) );