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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : SMESHGUI_ExtrusionAlongPathDlg.cxx
25 // Author : Vadim SANDLER
29 #include "SMESHGUI_ExtrusionAlongPathDlg.h"
32 #include "SMESHGUI_Utils.h"
33 #include "SMESHGUI_VTKUtils.h"
34 #include "SMESHGUI_MeshUtils.h"
35 #include "SMESHGUI_SpinBox.h"
36 #include "SMESHGUI_IdValidator.h"
38 #include "SMESH_Actor.h"
39 #include "SMESH_TypeFilter.hxx"
40 #include "SMESH_NumberFilter.hxx"
41 #include "SMESH_LogicalFilter.hxx"
43 #include "SMDS_Mesh.hxx"
47 #include "SUIT_ResourceMgr.h"
48 #include "SUIT_OverrideCursor.h"
49 #include "SUIT_Desktop.h"
50 #include "SUIT_MessageBox.h"
51 #include "SUIT_Session.h"
53 #include "SalomeApp_Application.h"
55 #include "SVTK_ViewModel.h"
56 #include "SVTK_ViewWindow.h"
57 #include "SVTK_Selector.h"
58 #include "SVTK_Selection.h"
59 #include "SALOME_ListIO.hxx"
61 #include "utilities.h"
64 #include <BRep_Tool.hxx>
65 #include <TopoDS_Shape.hxx>
67 #include <TopoDS_Vertex.hxx>
69 #include <TColStd_MapOfInteger.hxx>
70 #include <TColStd_IndexedMapOfInteger.hxx>
73 #include <qapplication.h>
74 #include <qbuttongroup.h>
75 #include <qgroupbox.h>
77 #include <qlineedit.h>
78 #include <qpushbutton.h>
79 #include <qtoolbutton.h>
80 #include <qradiobutton.h>
81 #include <qcheckbox.h>
84 #include <qvalidator.h>
89 #include "SALOMEconfig.h"
90 #include CORBA_SERVER_HEADER(SMESH_Group)
94 //=================================================================================
95 // function : SMESHGUI_ExtrusionAlongPathDlg()
96 // purpose : constructor
97 //=================================================================================
98 SMESHGUI_ExtrusionAlongPathDlg::SMESHGUI_ExtrusionAlongPathDlg( SMESHGUI* theModule,
100 : QDialog( SMESH::GetDesktop( theModule ), "SMESHGUI_ExtrusionAlongPathDlg", modal,
101 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | Qt::WDestructiveClose),
102 mySMESHGUI( theModule ),
103 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
105 SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( mySMESHGUI );
106 QPixmap edgeImage ( mgr->loadPixmap("SMESH", tr("ICON_DLG_EDGE")));
107 QPixmap faceImage ( mgr->loadPixmap("SMESH", tr("ICON_DLG_TRIANGLE")));
108 QPixmap selectImage ( mgr->loadPixmap("SMESH", tr("ICON_SELECT")));
109 QPixmap addImage ( mgr->loadPixmap("SMESH", tr("ICON_APPEND")));
110 QPixmap removeImage ( mgr->loadPixmap("SMESH", tr("ICON_REMOVE")));
114 setCaption(tr("EXTRUSION_ALONG_PATH"));
115 setSizeGripEnabled(TRUE);
117 QGridLayout* topLayout = new QGridLayout(this);
118 topLayout->setSpacing(6);
119 topLayout->setMargin(11);
121 /***************************************************************/
122 // Elements type group box (1d / 2d elements)
123 GroupConstructors = new QButtonGroup(tr("SMESH_EXTRUSION"), this);
124 GroupConstructors->setColumnLayout(0, Qt::Vertical);
125 GroupConstructors->layout()->setSpacing(0);
126 GroupConstructors->layout()->setMargin(0);
127 QGridLayout* GroupConstructorsLayout = new QGridLayout(GroupConstructors->layout());
128 GroupConstructorsLayout->setAlignment(Qt::AlignTop);
129 GroupConstructorsLayout->setSpacing(6); GroupConstructorsLayout->setMargin(11);
131 Elements1dRB = new QRadioButton(GroupConstructors);
132 Elements1dRB->setPixmap(edgeImage);
133 Elements2dRB = new QRadioButton(GroupConstructors);
134 Elements2dRB->setPixmap(faceImage);
135 Elements1dRB->setChecked(true);
138 GroupConstructorsLayout->addWidget(Elements1dRB, 0, 0);
139 GroupConstructorsLayout->addWidget(Elements2dRB, 0, 2);
141 /***************************************************************/
142 // Arguments group box
143 GroupArguments = new QGroupBox(tr("EXTRUSION_1D"), this);
144 GroupArguments->setColumnLayout(0, Qt::Vertical);
145 GroupArguments->layout()->setSpacing(0); GroupArguments->layout()->setMargin(0);
146 QGridLayout* GroupArgumentsLayout = new QGridLayout(GroupArguments->layout());
147 GroupArgumentsLayout->setAlignment(Qt::AlignTop);
148 GroupArgumentsLayout->setSpacing(6); GroupArgumentsLayout->setMargin(11);
150 // Controls for elements selection
151 ElementsLab = new QLabel(tr("SMESH_ID_ELEMENTS"), GroupArguments);
153 SelectElementsButton = new QToolButton(GroupArguments);
154 SelectElementsButton->setPixmap(selectImage);
156 ElementsLineEdit = new QLineEdit(GroupArguments);
157 ElementsLineEdit->setValidator(new SMESHGUI_IdValidator(this));
159 // Controls for the whole mesh selection
160 MeshCheck = new QCheckBox(tr("SMESH_SELECT_WHOLE_MESH"), GroupArguments);
162 // Controls for path selection
163 PathGrp = new QGroupBox(tr("SMESH_PATH"), GroupArguments);
164 PathGrp->setColumnLayout(0, Qt::Vertical);
165 PathGrp->layout()->setSpacing(0); PathGrp->layout()->setMargin(0);
166 QGridLayout* PathGrpLayout = new QGridLayout(PathGrp->layout());
167 PathGrpLayout->setAlignment(Qt::AlignTop);
168 PathGrpLayout->setSpacing(6); PathGrpLayout->setMargin(11);
170 // Controls for path mesh selection
171 PathMeshLab = new QLabel(tr("SMESH_PATH_MESH"), PathGrp);
173 SelectPathMeshButton = new QToolButton(PathGrp);
174 SelectPathMeshButton->setPixmap(selectImage);
176 PathMeshLineEdit = new QLineEdit(PathGrp);
177 PathMeshLineEdit->setReadOnly(true);
179 // Controls for path shape selection
180 PathShapeLab = new QLabel(tr("SMESH_PATH_SHAPE"), PathGrp);
182 SelectPathShapeButton = new QToolButton(PathGrp);
183 SelectPathShapeButton->setPixmap(selectImage);
185 PathShapeLineEdit = new QLineEdit(PathGrp);
186 PathShapeLineEdit->setReadOnly(true);
188 // Controls for path starting point selection
189 StartPointLab = new QLabel(tr("SMESH_PATH_START"), PathGrp);
191 SelectStartPointButton = new QToolButton(PathGrp);
192 SelectStartPointButton->setPixmap(selectImage);
194 StartPointLineEdit = new QLineEdit(PathGrp);
195 StartPointLineEdit->setValidator(new QIntValidator(this));
198 PathGrpLayout->addWidget(PathMeshLab, 0, 0);
199 PathGrpLayout->addWidget(SelectPathMeshButton, 0, 1);
200 PathGrpLayout->addWidget(PathMeshLineEdit, 0, 2);
201 PathGrpLayout->addWidget(PathShapeLab, 1, 0);
202 PathGrpLayout->addWidget(SelectPathShapeButton, 1, 1);
203 PathGrpLayout->addWidget(PathShapeLineEdit, 1, 2);
204 PathGrpLayout->addWidget(StartPointLab, 2, 0);
205 PathGrpLayout->addWidget(SelectStartPointButton, 2, 1);
206 PathGrpLayout->addWidget(StartPointLineEdit, 2, 2);
208 // Controls for base point defining
209 BasePointCheck = new QCheckBox(tr("SMESH_USE_BASE_POINT"), GroupArguments);
211 BasePointGrp = new QGroupBox(tr("SMESH_BASE_POINT"), GroupArguments);
212 BasePointGrp->setColumnLayout(0, Qt::Vertical);
213 BasePointGrp->layout()->setSpacing(0); BasePointGrp->layout()->setMargin(0);
214 QGridLayout* BasePointGrpLayout = new QGridLayout(BasePointGrp->layout());
215 BasePointGrpLayout->setAlignment(Qt::AlignTop);
216 BasePointGrpLayout->setSpacing(6); BasePointGrpLayout->setMargin(11);
218 SelectBasePointButton = new QToolButton(BasePointGrp);
219 SelectBasePointButton->setPixmap(selectImage);
221 XLab = new QLabel(tr("SMESH_X"), BasePointGrp);
222 XSpin = new SMESHGUI_SpinBox(BasePointGrp);
223 YLab = new QLabel(tr("SMESH_Y"), BasePointGrp);
224 YSpin = new SMESHGUI_SpinBox(BasePointGrp);
225 ZLab = new QLabel(tr("SMESH_Z"), BasePointGrp);
226 ZSpin = new SMESHGUI_SpinBox(BasePointGrp);
229 BasePointGrpLayout->addWidget(SelectBasePointButton, 0, 0);
230 BasePointGrpLayout->addWidget(XLab, 0, 1);
231 BasePointGrpLayout->addWidget(XSpin, 0, 2);
232 BasePointGrpLayout->addWidget(YLab, 0, 3);
233 BasePointGrpLayout->addWidget(YSpin, 0, 4);
234 BasePointGrpLayout->addWidget(ZLab, 0, 5);
235 BasePointGrpLayout->addWidget(ZSpin, 0, 6);
237 // Controls for angles defining
238 AnglesCheck = new QCheckBox(tr("SMESH_USE_ANGLES"), GroupArguments);
240 AnglesGrp = new QGroupBox(tr("SMESH_ANGLES"), GroupArguments);
241 AnglesGrp->setColumnLayout(0, Qt::Vertical);
242 AnglesGrp->layout()->setSpacing(0); AnglesGrp->layout()->setMargin(0);
243 QGridLayout* AnglesGrpLayout = new QGridLayout(AnglesGrp->layout());
244 AnglesGrpLayout->setAlignment(Qt::AlignTop);
245 AnglesGrpLayout->setSpacing(6); AnglesGrpLayout->setMargin(11);
247 AnglesList = new QListBox(AnglesGrp);
248 AnglesList->setSelectionMode(QListBox::Extended);
250 AddAngleButton = new QToolButton(AnglesGrp);
251 AddAngleButton->setPixmap(addImage);
253 RemoveAngleButton = new QToolButton(AnglesGrp);
254 RemoveAngleButton->setPixmap(removeImage);
256 AngleSpin = new SMESHGUI_SpinBox(AnglesGrp);
259 QVBoxLayout* bLayout = new QVBoxLayout();
260 bLayout->addWidget(AddAngleButton);
261 bLayout->addSpacing(6);
262 bLayout->addWidget(RemoveAngleButton);
263 bLayout->addStretch();
264 AnglesGrpLayout->addMultiCellWidget(AnglesList, 0, 1, 0, 0);
265 AnglesGrpLayout->addMultiCellLayout(bLayout, 0, 1, 1, 1);
266 AnglesGrpLayout->addWidget( AngleSpin, 0, 2 );
267 AnglesGrpLayout->setRowStretch(1, 10);
270 GroupArgumentsLayout->addWidget( ElementsLab, 0, 0 );
271 GroupArgumentsLayout->addWidget( SelectElementsButton, 0, 1 );
272 GroupArgumentsLayout->addWidget( ElementsLineEdit, 0, 2 );
273 GroupArgumentsLayout->addMultiCellWidget(MeshCheck, 1, 1, 0, 2);
274 GroupArgumentsLayout->addMultiCellWidget(PathGrp, 2, 2, 0, 2);
275 GroupArgumentsLayout->addWidget( BasePointCheck, 3, 0 );
276 GroupArgumentsLayout->addMultiCellWidget(BasePointGrp, 3, 4, 1, 2);
277 GroupArgumentsLayout->addWidget( AnglesCheck, 5, 0 );
278 GroupArgumentsLayout->addMultiCellWidget(AnglesGrp, 5, 6, 1, 2);
279 GroupArgumentsLayout->setRowStretch(6, 10);
281 /***************************************************************/
282 // common buttons group box
283 GroupButtons = new QGroupBox(this);
284 GroupButtons->setColumnLayout(0, Qt::Vertical);
285 GroupButtons->layout()->setSpacing(0);
286 GroupButtons->layout()->setMargin(0);
287 QGridLayout* GroupButtonsLayout = new QGridLayout(GroupButtons->layout());
288 GroupButtonsLayout->setAlignment(Qt::AlignTop);
289 GroupButtonsLayout->setSpacing(6); GroupButtonsLayout->setMargin(11);
291 OkButton = new QPushButton(tr("SMESH_BUT_OK"), GroupButtons);
292 OkButton->setAutoDefault(true);
293 OkButton->setDefault(true);
295 ApplyButton = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
296 ApplyButton->setAutoDefault(true);
298 CloseButton = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
299 CloseButton->setAutoDefault(true);
301 HelpButton = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
302 HelpButton->setAutoDefault(true);
305 GroupButtonsLayout->addWidget(OkButton, 0, 0);
306 GroupButtonsLayout->addWidget(ApplyButton, 0, 1);
307 GroupButtonsLayout->addWidget(CloseButton, 0, 3);
308 GroupButtonsLayout->addWidget(HelpButton, 0, 4);
309 GroupButtonsLayout->addColSpacing(2, 10);
310 GroupButtonsLayout->setColStretch(2, 10);
312 /***************************************************************/
314 topLayout->addWidget(GroupConstructors, 0, 0);
315 topLayout->addWidget(GroupArguments, 1, 0);
316 topLayout->addWidget(GroupButtons, 2, 0);
318 /***************************************************************/
320 XSpin->RangeStepAndValidator(-999999.999, +999999.999, 10.0, 3);
321 YSpin->RangeStepAndValidator(-999999.999, +999999.999, 10.0, 3);
322 ZSpin->RangeStepAndValidator(-999999.999, +999999.999, 10.0, 3);
323 AngleSpin->RangeStepAndValidator(-999999.999, +999999.999, 5.0, 3);
325 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
327 mySMESHGUI->SetActiveDialogBox(this);
329 // Costruction of the logical filter for the elements: mesh/sub-mesh/group
330 SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
331 SMESH_TypeFilter* aSmeshGroupFilter = new SMESH_TypeFilter (GROUP);
333 QPtrList<SUIT_SelectionFilter> aListOfFilters;
334 if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
335 if (aSmeshGroupFilter) aListOfFilters.append(aSmeshGroupFilter);
337 myElementsFilter = new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR);
338 myPathMeshFilter = new SMESH_TypeFilter (MESH);
340 myHelpFileName = "extrusion_along_a_path.htm";
344 /***************************************************************/
345 // signals-slots connections
346 connect(OkButton, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
347 connect(CloseButton, SIGNAL(clicked()), this, SLOT(reject()));
348 connect(ApplyButton, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
349 connect(HelpButton, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
351 connect(AddAngleButton, SIGNAL(clicked()), this, SLOT(OnAngleAdded()));
352 connect(RemoveAngleButton, SIGNAL(clicked()), this, SLOT(OnAngleRemoved()));
354 connect(GroupConstructors, SIGNAL(clicked(int)), SLOT(ConstructorsClicked(int)));
356 connect(SelectElementsButton, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
357 connect(SelectPathMeshButton, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
358 connect(SelectPathShapeButton, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
359 connect(SelectStartPointButton, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
360 connect(SelectBasePointButton, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
362 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
363 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
364 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(reject()));
366 connect(ElementsLineEdit, SIGNAL(textChanged(const QString&)),
367 SLOT(onTextChange(const QString&)));
368 connect(StartPointLineEdit, SIGNAL(textChanged(const QString&)),
369 SLOT(onTextChange(const QString&)));
371 connect(MeshCheck, SIGNAL(toggled(bool)), SLOT(onSelectMesh()));
372 connect(AnglesCheck, SIGNAL(toggled(bool)), SLOT(onAnglesCheck()));
373 connect(BasePointCheck, SIGNAL(toggled(bool)), SLOT(onBasePointCheck()));
375 AnglesList->installEventFilter(this);
376 ElementsLineEdit->installEventFilter(this);
377 StartPointLineEdit->installEventFilter(this);
378 XSpin->editor()->installEventFilter(this);
379 YSpin->editor()->installEventFilter(this);
380 ZSpin->editor()->installEventFilter(this);
382 /***************************************************************/
384 this->show(); // displays Dialog
387 //=================================================================================
388 // function : ~SMESHGUI_ExtrusionAlongPathDlg()
389 // purpose : destructor
390 //=================================================================================
391 SMESHGUI_ExtrusionAlongPathDlg::~SMESHGUI_ExtrusionAlongPathDlg()
393 // no need to delete child widgets, Qt does it all for us
396 //=================================================================================
398 // purpose : initialization
399 //=================================================================================
400 void SMESHGUI_ExtrusionAlongPathDlg::Init (bool ResetControls)
403 myEditCurrentArgument = 0;
405 myMesh = SMESH::SMESH_Mesh::_nil();
406 myIDSource = SMESH::SMESH_IDSource::_nil();
408 myPathMesh = SMESH::SMESH_Mesh::_nil();
409 myPathShape = GEOM::GEOM_Object::_nil();
411 ElementsLineEdit->clear();
412 PathMeshLineEdit->clear();
413 PathShapeLineEdit->clear();
414 StartPointLineEdit->clear();
417 XSpin->SetValue(0.0);
418 YSpin->SetValue(0.0);
419 ZSpin->SetValue(0.0);
421 AngleSpin->SetValue(45);
422 MeshCheck->setChecked(false);
423 ConstructorsClicked(0);
428 SetEditCurrentArgument(0);
431 //=================================================================================
432 // function : ConstructorsClicked()
433 // purpose : Called when user changes type of elements (1d / 2d)
434 //=================================================================================
435 void SMESHGUI_ExtrusionAlongPathDlg::ConstructorsClicked (int type)
437 if (myType == type) return;
439 disconnect(mySelectionMgr, 0, this, 0);
442 GroupArguments->setTitle(tr("EXTRUSION_1D"));
444 GroupArguments->setTitle(tr("EXTRUSION_2D"));
446 // clear elements ID list
447 if (!MeshCheck->isChecked()) {
448 ElementsLineEdit->clear();
450 // set selection mode if necessary
451 if (myEditCurrentArgument == ElementsLineEdit) {
452 mySelectionMgr->clearSelected();
453 mySelectionMgr->clearFilters();
454 SMESH::SetPickable();
456 SMESH::SetPointRepresentation(false);
457 if (MeshCheck->isChecked()) {
458 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
459 aViewWindow->SetSelectionMode(ActorSelection);
460 mySelectionMgr->installFilter(myElementsFilter);
464 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
465 aViewWindow->SetSelectionMode(EdgeSelection);
469 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
470 aViewWindow->SetSelectionMode(FaceSelection);
474 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
479 //=================================================================================
480 // function : ClickOnApply()
481 // purpose : Called when user presses <Apply> button
482 //=================================================================================
483 bool SMESHGUI_ExtrusionAlongPathDlg::ClickOnApply()
485 if (mySMESHGUI->isActiveStudyLocked())
488 if (myMesh->_is_nil() || MeshCheck->isChecked() && myIDSource->_is_nil() ||
489 !myMeshActor || myPathMesh->_is_nil() || myPathShape->_is_nil())
492 SMESH::long_array_var anElementsId = new SMESH::long_array;
494 if (MeshCheck->isChecked()) {
495 // If "Select whole mesh, submesh or group" check box is on ->
496 // get all elements of the required type from the object selected
498 // if MESH object is selected
499 if (!CORBA::is_nil(SMESH::SMESH_Mesh::_narrow(myIDSource))) {
501 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow(myIDSource);
502 // get IDs from mesh...
503 if (Elements1dRB->isChecked())
505 anElementsId = aMesh->GetElementsByType(SMESH::EDGE);
506 else if (Elements2dRB->isChecked()) {
507 anElementsId = aMesh->GetElementsByType(SMESH::FACE);
510 // SUBMESH is selected
511 if (!CORBA::is_nil(SMESH::SMESH_subMesh::_narrow(myIDSource))) {
513 SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow(myIDSource);
514 // get IDs from submesh
515 if (Elements1dRB->isChecked())
517 anElementsId = aSubMesh->GetElementsByType(SMESH::EDGE);
518 else if (Elements2dRB->isChecked())
520 anElementsId = aSubMesh->GetElementsByType(SMESH::FACE);
523 if (!CORBA::is_nil(SMESH::SMESH_GroupBase::_narrow(myIDSource))) {
525 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow(myIDSource);
526 // get IDs from group
527 // 1d elements or 2d elements
528 if (Elements1dRB->isChecked() && aGroup->GetType() == SMESH::EDGE ||
529 Elements2dRB->isChecked() && aGroup->GetType() == SMESH::FACE)
530 anElementsId = aGroup->GetListOfID();
533 // If "Select whole mesh, submesh or group" check box is off ->
534 // use only elements of given type selected by user
536 SMDS_Mesh* aMesh = myMeshActor->GetObject()->GetMesh();
538 QStringList aListElementsId = QStringList::split(" ", ElementsLineEdit->text(), false);
539 anElementsId = new SMESH::long_array;
540 anElementsId->length(aListElementsId.count());
543 for (int i = 0; i < aListElementsId.count(); i++) {
544 long ind = aListElementsId[ i ].toLong(&bOk);
546 const SMDS_MeshElement* e = aMesh->FindElement(ind);
548 bool typeMatch = Elements1dRB->isChecked() && e->GetType() == SMDSAbs_Edge ||
549 Elements2dRB->isChecked() && e->GetType() == SMDSAbs_Face;
551 anElementsId[ j++ ] = ind;
555 anElementsId->length(j);
559 if (anElementsId->length() <= 0) {
563 if (StartPointLineEdit->text().stripWhiteSpace().isEmpty()) {
568 long aNodeStart = StartPointLineEdit->text().toLong(&bOk);
574 SMESH::double_array_var anAngles = new SMESH::double_array;
575 if (AnglesCheck->isChecked()) {
576 anAngles->length(AnglesList->count());
579 for (int i = 0; i < AnglesList->count(); i++) {
580 double angle = AnglesList->text(i).toDouble(&bOk);
582 anAngles[ j++ ] = angle*PI/180;
588 SMESH::PointStruct aBasePoint;
589 if (BasePointCheck->isChecked()) {
590 aBasePoint.x = XSpin->GetValue();
591 aBasePoint.y = YSpin->GetValue();
592 aBasePoint.z = ZSpin->GetValue();
596 SUIT_OverrideCursor wc;
597 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
598 SMESH::SMESH_MeshEditor::Extrusion_Error retVal =
599 aMeshEditor->ExtrusionAlongPath(anElementsId.inout(), myPathMesh, myPathShape, aNodeStart,
600 AnglesCheck->isChecked(), anAngles.inout(),
601 BasePointCheck->isChecked(), aBasePoint);
606 case SMESH::SMESH_MeshEditor::EXTR_NO_ELEMENTS:
607 SUIT_MessageBox::warn1(SMESHGUI::desktop(),
609 tr("NO_ELEMENTS_SELECTED"),
612 case SMESH::SMESH_MeshEditor::EXTR_PATH_NOT_EDGE:
613 SUIT_MessageBox::warn1(SMESHGUI::desktop(),
615 tr("SELECTED_PATH_IS_NOT_EDGE"),
618 case SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE:
619 SUIT_MessageBox::warn1(SMESHGUI::desktop(),
621 tr("BAD_SHAPE_TYPE"),
624 case SMESH::SMESH_MeshEditor::EXTR_BAD_STARTING_NODE:
625 SUIT_MessageBox::warn1(SMESHGUI::desktop(),
627 tr("EXTR_BAD_STARTING_NODE"),
630 case SMESH::SMESH_MeshEditor::EXTR_BAD_ANGLES_NUMBER:
631 SUIT_MessageBox::warn1(SMESHGUI::desktop(),
633 tr("WRONG_ANGLES_NUMBER"),
636 case SMESH::SMESH_MeshEditor::EXTR_CANT_GET_TANGENT:
637 SUIT_MessageBox::warn1(SMESHGUI::desktop(),
639 tr("CANT_GET_TANGENT"),
642 case SMESH::SMESH_MeshEditor::EXTR_OK:
649 //mySelectionMgr->clearSelected();
650 SMESH::Update( myMeshActor->getIO(), myMeshActor->GetVisibility() );
651 //SMESH::UpdateView();
653 ConstructorsClicked(GetConstructorId());
657 //=================================================================================
658 // function : ClickOnOk()
659 // purpose : Called when user presses <OK> button
660 //=================================================================================
661 void SMESHGUI_ExtrusionAlongPathDlg::ClickOnOk()
667 //=================================================================================
668 // function : ClickOnHelp()
670 //=================================================================================
671 void SMESHGUI_ExtrusionAlongPathDlg::ClickOnHelp()
673 SalomeApp_Application* app = (SalomeApp_Application*)(SUIT_Session::session()->activeApplication());
675 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
677 SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
678 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
679 arg(app->resourceMgr()->stringValue("ExternalBrowser", "application")).arg(myHelpFileName),
680 QObject::tr("BUT_OK"));
684 //=================================================================================
685 // function : reject()
686 // purpose : Called when dialog box is closed
687 //=================================================================================
688 void SMESHGUI_ExtrusionAlongPathDlg::reject()
690 disconnect(mySelectionMgr, 0, this, 0);
691 mySelectionMgr->clearFilters();
692 //mySelectionMgr->clearSelected();
693 SMESH::SetPickable(); // ???
694 SMESH::SetPointRepresentation(false);
695 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
696 aViewWindow->SetSelectionMode(ActorSelection);
697 mySMESHGUI->ResetState();
701 //=======================================================================
702 // function : onTextChange()
704 //=======================================================================
705 void SMESHGUI_ExtrusionAlongPathDlg::onTextChange (const QString& theNewText)
707 QLineEdit* send = (QLineEdit*)sender();
715 if (send != StartPointLineEdit && send != ElementsLineEdit)
716 send = ElementsLineEdit;
718 if (send == ElementsLineEdit && myEditCurrentArgument == ElementsLineEdit) {
719 // hilight entered elements
720 SMDS_Mesh* aMesh = 0;
722 aMesh = myMeshActor->GetObject()->GetMesh();
725 //mySelectionMgr->clearSelected();
726 //mySelectionMgr->AddIObject(myMeshActor->getIO());
728 aList.Append(myMeshActor->getIO());
729 mySelectionMgr->setSelectedObjects(aList, false);
731 QStringList aListId = QStringList::split(" ", theNewText, false);
733 const Handle(SALOME_InteractiveObject)& anIO = myMeshActor->getIO();
734 TColStd_MapOfInteger newIndices;
735 for (int i = 0; i < aListId.count(); i++) {
736 long ind = aListId[ i ].toLong(&bOk);
738 const SMDS_MeshElement* e = aMesh->FindElement(ind);
740 // check also type of element
741 bool typeMatch = Elements1dRB->isChecked() && e->GetType() == SMDSAbs_Edge ||
742 Elements2dRB->isChecked() && e->GetType() == SMDSAbs_Face;
744 newIndices.Add(e->GetID());
748 mySelector->AddOrRemoveIndex(anIO, newIndices, false);
749 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
750 aViewWindow->highlight( anIO, true, true );
752 } else if (send == StartPointLineEdit &&
753 myEditCurrentArgument == StartPointLineEdit) {
754 if (!myPathMesh->_is_nil()) {
755 SMESH_Actor* aPathActor = SMESH::FindActorByObject(myPathMesh);
756 SMDS_Mesh* aMesh = 0;
758 aMesh = aPathActor->GetObject()->GetMesh();
760 //mySelectionMgr->clearSelected();
761 //mySelectionMgr->AddIObject(aPathActor->getIO());
763 aList.Append(aPathActor->getIO());
764 mySelectionMgr->setSelectedObjects(aList, false);
767 long ind = theNewText.toLong(&bOk);
769 const SMDS_MeshNode* n = aMesh->FindNode(ind);
771 //if (!mySelectionMgr->IsIndexSelected(aPathActor->getIO(), n->GetID())) {
772 TColStd_MapOfInteger newIndices;
773 newIndices.Add(n->GetID());
774 mySelector->AddOrRemoveIndex( aPathActor->getIO(), newIndices, false );
775 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
776 aViewWindow->highlight( aPathActor->getIO(), true, true );
784 //=================================================================================
785 // function : SelectionIntoArgument()
786 // purpose : Called when selection as changed or other case
787 //=================================================================================
788 void SMESHGUI_ExtrusionAlongPathDlg::SelectionIntoArgument()
792 // return if dialog box is inactive
793 if (!GroupButtons->isEnabled())
796 // selected objects count
797 const SALOME_ListIO& aList = mySelector->StoredIObjects();
798 int nbSel = aList.Extent();
805 if (myEditCurrentArgument == ElementsLineEdit) {
806 // we are now selecting mesh elements (or whole mesh/submesh/group)
808 ElementsLineEdit->clear();
809 myMesh = SMESH::SMESH_Mesh::_nil();
810 myIDSource = SMESH::SMESH_IDSource::_nil();
813 // try to get mesh from selection
814 Handle(SALOME_InteractiveObject) IO = aList.First();
815 myMesh = SMESH::GetMeshByIO(IO);
816 if (myMesh->_is_nil())
819 myMeshActor = SMESH::FindActorByObject(myMesh);
823 if (MeshCheck->isChecked()) {
824 // If "Select whole mesh, submesh or group" check box is on ->
825 // get ID source and put it's name to the edit box
827 SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
829 myIDSource = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
830 ElementsLineEdit->setText(aString);
832 // If "Select whole mesh, submesh or group" check box is off ->
833 // try to get selected elements IDs
835 //int aNbUnits = SMESH::GetNameOfSelectedElements(mySelectionMgr, aString);
836 SMESH::GetNameOfSelectedElements(mySelector, myMeshActor->getIO(), aString);
837 ElementsLineEdit->setText(aString);
839 } else if (myEditCurrentArgument == PathMeshLineEdit) {
840 // we are now selecting path mesh
842 PathMeshLineEdit->clear();
843 myPathMesh = SMESH::SMESH_Mesh::_nil();
844 PathShapeLineEdit->clear();
845 myPathShape = GEOM::GEOM_Object::_nil();
846 StartPointLineEdit->clear();
848 // try to get mesh from selection
849 Handle(SALOME_InteractiveObject) IO = aList.First();
850 myPathMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO);
851 if(myPathMesh->_is_nil())
855 SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
856 PathMeshLineEdit->setText(aString);
857 } else if (myEditCurrentArgument == PathShapeLineEdit) {
858 // we are now selecting path mesh
860 PathShapeLineEdit->clear();
861 myPathShape = GEOM::GEOM_Object::_nil();
862 StartPointLineEdit->clear();
864 // return if path mesh is not yet selected
865 if (myPathMesh->_is_nil())
868 // try to get shape from selection
869 Handle(SALOME_InteractiveObject) IO = aList.First();
870 myPathShape = SMESH::IObjectToInterface<GEOM::GEOM_Object>(IO);
871 if (myPathShape->_is_nil())
875 SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
876 PathShapeLineEdit->setText(aString);
877 } else if (myEditCurrentArgument == StartPointLineEdit) {
878 // we are now selecting start point of path
880 StartPointLineEdit->clear();
882 // return if path mesh or path shape is not yet selected
883 if (myPathMesh->_is_nil() || myPathShape->_is_nil())
886 // try to get shape from selection
887 Handle(SALOME_InteractiveObject) IO = aList.First();
889 SMESH_Actor* aPathActor = SMESH::FindActorByObject(myPathMesh);
894 int aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, aPathActor->getIO(), aString);
896 StartPointLineEdit->setText(aString.stripWhiteSpace());
898 } else if (myEditCurrentArgument == XSpin) {
899 // we are now selecting base point
900 // reset is not performed here!
902 // return if is not enabled
903 if (!BasePointGrp->isEnabled())
906 // try to get shape from selection
907 Handle(SALOME_InteractiveObject) IO = aList.First();
909 // check if geom vertex is selected
910 GEOM::GEOM_Object_var aGeomObj = SMESH::IObjectToInterface<GEOM::GEOM_Object>(IO);
911 TopoDS_Vertex aVertex;
912 if (!aGeomObj->_is_nil()) {
913 if (aGeomObj->IsShape() && GEOMBase::GetShape(aGeomObj, aVertex) && !aVertex.IsNull()) {
914 gp_Pnt aPnt = BRep_Tool::Pnt(aVertex);
915 XSpin->SetValue(aPnt.X());
916 YSpin->SetValue(aPnt.Y());
917 ZSpin->SetValue(aPnt.Z());
922 // check if smesh node is selected
923 SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO(IO);
924 if (aMesh->_is_nil())
928 int aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, myMeshActor->getIO(), aString);
929 // return if more than one node is selected
933 SMESH_Actor* aMeshActor = SMESH::FindActorByObject(aMesh);
937 SMDS_Mesh* mesh = aMeshActor->GetObject()->GetMesh();
941 const SMDS_MeshNode* n = mesh->FindNode(aString.toLong());
945 XSpin->SetValue(n->X());
946 YSpin->SetValue(n->Y());
947 ZSpin->SetValue(n->Z());
951 //=================================================================================
952 // function : SetEditCurrentArgument()
954 //=================================================================================
955 void SMESHGUI_ExtrusionAlongPathDlg::SetEditCurrentArgument()
957 QToolButton* send = (QToolButton*)sender();
958 if (send != SelectElementsButton &&
959 send != SelectPathMeshButton &&
960 send != SelectPathShapeButton &&
961 send != SelectStartPointButton &&
962 send != SelectBasePointButton)
964 SetEditCurrentArgument(send);
967 //=================================================================================
968 // function : SetEditCurrentArgument()
970 //=================================================================================
971 void SMESHGUI_ExtrusionAlongPathDlg::SetEditCurrentArgument (QToolButton* button)
973 disconnect(mySelectionMgr, 0, this, 0);
974 mySelectionMgr->clearSelected();
975 mySelectionMgr->clearFilters();
976 SMESH::SetPickable();
978 if (button == SelectElementsButton) {
979 myEditCurrentArgument = ElementsLineEdit;
980 SMESH::SetPointRepresentation(false);
981 if (MeshCheck->isChecked()) {
982 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
983 aViewWindow->SetSelectionMode(ActorSelection);
984 mySelectionMgr->installFilter(myElementsFilter);
986 if (Elements1dRB->isChecked())
988 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
989 aViewWindow->SetSelectionMode(EdgeSelection);
991 else if (Elements2dRB->isChecked())
993 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
994 aViewWindow->SetSelectionMode(FaceSelection);
997 } else if (button == SelectPathMeshButton) {
998 myEditCurrentArgument = PathMeshLineEdit;
999 SMESH::SetPointRepresentation(false);
1000 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1001 aViewWindow->SetSelectionMode(ActorSelection);
1002 mySelectionMgr->installFilter(myPathMeshFilter);
1004 else if (button == SelectPathShapeButton) {
1005 myEditCurrentArgument = PathShapeLineEdit;
1006 SMESH::SetPointRepresentation(false);
1007 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1008 aViewWindow->SetSelectionMode(ActorSelection);
1010 if (!myPathMesh->_is_nil()) {
1011 GEOM::GEOM_Object_var aMainShape = myPathMesh->GetShapeToMesh();
1012 SMESH_Actor* aPathActor = SMESH::FindActorByObject(myPathMesh);
1014 if (!aMainShape->_is_nil() && aPathActor)
1015 mySelectionMgr->installFilter(new SMESH_NumberFilter ("GEOM", TopAbs_SHAPE, -1,
1016 TopAbs_EDGE, aMainShape));
1017 //SMESH::SetPickable(aPathActor);
1020 else if (button == SelectStartPointButton) {
1021 myEditCurrentArgument = StartPointLineEdit;
1022 if (!myPathMesh->_is_nil()) {
1023 SMESH_Actor* aPathActor = SMESH::FindActorByObject(myPathMesh);
1025 SMESH::SetPointRepresentation(true);
1026 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1027 aViewWindow->SetSelectionMode(NodeSelection);
1028 SMESH::SetPickable(aPathActor);
1032 else if (button == SelectBasePointButton) {
1033 myEditCurrentArgument = XSpin;
1034 SMESH::SetPointRepresentation(true);
1035 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1036 aViewWindow->SetSelectionMode(NodeSelection);
1038 SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter(MESHorSUBMESH);
1039 SMESH_TypeFilter* aSmeshGroupFilter = new SMESH_TypeFilter(GROUP);
1040 SMESH_NumberFilter* aVertexFilter = new SMESH_NumberFilter ("GEOM", TopAbs_SHAPE,
1042 QPtrList<SUIT_SelectionFilter> aListOfFilters;
1043 if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
1044 if (aSmeshGroupFilter) aListOfFilters.append(aSmeshGroupFilter);
1045 if (aVertexFilter) aListOfFilters.append(aVertexFilter);
1047 mySelectionMgr->installFilter(new SMESH_LogicalFilter
1048 (aListOfFilters, SMESH_LogicalFilter::LO_OR));
1051 if (myEditCurrentArgument && !myEditCurrentArgument->hasFocus())
1052 myEditCurrentArgument->setFocus();
1054 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
1055 SelectionIntoArgument();
1058 //=================================================================================
1059 // function : DeactivateActiveDialog()
1060 // purpose : Deactivates this dialog
1061 //=================================================================================
1062 void SMESHGUI_ExtrusionAlongPathDlg::DeactivateActiveDialog()
1064 if (GroupConstructors->isEnabled()) {
1065 GroupConstructors->setEnabled(false);
1066 GroupArguments->setEnabled(false);
1067 GroupButtons->setEnabled(false);
1068 mySMESHGUI->ResetState();
1069 mySMESHGUI->SetActiveDialogBox(0);
1073 //=================================================================================
1074 // function : ActivateThisDialog()
1075 // purpose : Activates this dialog
1076 //=================================================================================
1077 void SMESHGUI_ExtrusionAlongPathDlg::ActivateThisDialog()
1079 // Emit a signal to deactivate the active dialog
1080 mySMESHGUI->EmitSignalDeactivateDialog();
1081 GroupConstructors->setEnabled(true);
1082 GroupArguments->setEnabled(true);
1083 GroupButtons->setEnabled(true);
1085 mySMESHGUI->SetActiveDialogBox(this);
1087 ConstructorsClicked(GetConstructorId());
1088 SelectionIntoArgument();
1091 //=================================================================================
1092 // function : enterEvent()
1093 // purpose : Mouse enter event
1094 //=================================================================================
1095 void SMESHGUI_ExtrusionAlongPathDlg::enterEvent (QEvent*)
1097 if (!GroupConstructors->isEnabled())
1098 ActivateThisDialog();
1101 //=======================================================================
1102 // function : onSelectMesh()
1104 //=======================================================================
1105 void SMESHGUI_ExtrusionAlongPathDlg::onSelectMesh()
1107 bool toSelectMesh = MeshCheck->isChecked();
1109 ElementsLineEdit->setReadOnly(toSelectMesh);
1110 ElementsLab->setText(toSelectMesh ? tr("SMESH_NAME") : tr("SMESH_ID_ELEMENTS"));
1111 ElementsLineEdit->clear();
1113 SetEditCurrentArgument(SelectElementsButton);
1116 //=================================================================================
1117 // function : GetConstructorId()
1119 //=================================================================================
1120 int SMESHGUI_ExtrusionAlongPathDlg::GetConstructorId()
1122 if (GroupConstructors != NULL && GroupConstructors->selected() != NULL)
1123 return GroupConstructors->id(GroupConstructors->selected());
1127 //=======================================================================
1128 // function : onAnglesCheck()
1129 // purpose : called when "Use Angles" check box is switched
1130 //=======================================================================
1131 void SMESHGUI_ExtrusionAlongPathDlg::onAnglesCheck()
1133 AnglesGrp->setEnabled(AnglesCheck->isChecked());
1136 //=======================================================================
1137 // function : onBasePointCheck()
1138 // purpose : called when "Use Base Point" check box is switched
1139 //=======================================================================
1140 void SMESHGUI_ExtrusionAlongPathDlg::onBasePointCheck()
1142 BasePointGrp->setEnabled(BasePointCheck->isChecked());
1145 //=======================================================================
1146 // function : OnAngleAdded()
1147 // purpose : Called when user adds angle to the list
1148 //=======================================================================
1149 void SMESHGUI_ExtrusionAlongPathDlg::OnAngleAdded()
1151 AnglesList->insertItem(QString::number(AngleSpin->GetValue()));
1154 //=======================================================================
1155 // function : OnAngleRemoved()
1156 // purpose : Called when user removes angle(s) from the list
1157 //=======================================================================
1158 void SMESHGUI_ExtrusionAlongPathDlg::OnAngleRemoved()
1160 QList<QListBoxItem> aList;
1161 aList.setAutoDelete(false);
1162 for (int i = 0; i < AnglesList->count(); i++)
1163 if (AnglesList->isSelected(i))
1164 aList.append(AnglesList->item(i));
1166 for (int i = 0; i < aList.count(); i++)
1170 //=================================================================================
1171 // function : eventFilter()
1172 // purpose : event filter ???
1173 //=================================================================================
1174 bool SMESHGUI_ExtrusionAlongPathDlg::eventFilter (QObject* object, QEvent* event)
1176 if (event->type() == QEvent::KeyPress) {
1177 QKeyEvent* ke = (QKeyEvent*)event;
1178 if (object == AnglesList) {
1179 if (ke->key() == Key_Delete)
1183 else if (event->type() == QEvent::FocusIn) {
1184 if (object == ElementsLineEdit) {
1185 if (myEditCurrentArgument != ElementsLineEdit)
1186 SetEditCurrentArgument(SelectElementsButton);
1188 else if (object == StartPointLineEdit) {
1189 if (myEditCurrentArgument != StartPointLineEdit)
1190 SetEditCurrentArgument(SelectStartPointButton);
1192 else if (object == XSpin->editor() || object == YSpin->editor() || object == ZSpin->editor()) {
1193 if (myEditCurrentArgument != XSpin)
1194 SetEditCurrentArgument(SelectBasePointButton);
1197 return QDialog::eventFilter(object, event);