1 // Copyright (C) 2007-2020 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_ExtrusionAlongPathDlg.cxx
25 // Author : Vadim SANDLER, Open CASCADE S.A.S.
28 #include "SMESHGUI_ExtrusionAlongPathDlg.h"
31 #include "SMESHGUI_ExtrusionDlg.h" // for SMESHGUI_3TypesSelector
32 #include "SMESHGUI_FilterDlg.h"
33 #include "SMESHGUI_IdValidator.h"
34 #include "SMESHGUI_MeshEditPreview.h"
35 #include "SMESHGUI_MeshUtils.h"
36 #include "SMESHGUI_SpinBox.h"
37 #include "SMESHGUI_Utils.h"
38 #include "SMESHGUI_VTKUtils.h"
40 #include <SMESH_Actor.h>
41 #include <SMESH_TypeFilter.hxx>
42 #include <SMESH_NumberFilter.hxx>
43 #include <SMESH_LogicalFilter.hxx>
45 #include <SMDS_Mesh.hxx>
47 // SALOME GEOM includes
50 // SALOME GUI includes
51 #include <SUIT_ResourceMgr.h>
52 #include <SUIT_OverrideCursor.h>
53 #include <SUIT_Desktop.h>
54 #include <SUIT_MessageBox.h>
55 #include <SUIT_Session.h>
56 #include <LightApp_Application.h>
57 #include <LightApp_SelectionMgr.h>
58 #include <SVTK_ViewWindow.h>
61 #include <BRep_Tool.hxx>
62 #include <TopoDS_Vertex.hxx>
64 #include <TColStd_MapOfInteger.hxx>
67 #include <QButtonGroup>
71 #include <QPushButton>
72 #include <QToolButton>
73 #include <QRadioButton>
75 #include <QListWidget>
76 #include <QVBoxLayout>
77 #include <QHBoxLayout>
78 #include <QGridLayout>
82 #include <SALOMEconfig.h>
83 #include CORBA_SERVER_HEADER(SMESH_Group)
84 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
89 class SMESHGUI_ExtrusionAlongPathDlg::SetBusy
92 SetBusy( SMESHGUI_ExtrusionAlongPathDlg* _dlg )
100 myDlg->myBusy = false;
104 SMESHGUI_ExtrusionAlongPathDlg* myDlg;
107 //=================================================================================
108 // function : SMESHGUI_ExtrusionAlongPathDlg()
109 // purpose : constructor
110 //=================================================================================
111 SMESHGUI_ExtrusionAlongPathDlg::SMESHGUI_ExtrusionAlongPathDlg( SMESHGUI* theModule )
112 : SMESHGUI_PreviewDlg( theModule ),
113 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
115 SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( mySMESHGUI );
116 QPixmap selectImage ( mgr->loadPixmap("SMESH", tr("ICON_SELECT")));
117 QPixmap addImage ( mgr->loadPixmap("SMESH", tr("ICON_APPEND")));
118 QPixmap removeImage ( mgr->loadPixmap("SMESH", tr("ICON_REMOVE")));
121 setAttribute( Qt::WA_DeleteOnClose, true );
122 setWindowTitle(tr("EXTRUSION_ALONG_PATH"));
123 setSizeGripEnabled(true);
125 QVBoxLayout* topLayout = new QVBoxLayout(this);
126 topLayout->setSpacing(SPACING);
127 topLayout->setMargin(MARGIN);
129 /***************************************************************/
130 // Arguments group box
131 GroupArguments = new QGroupBox(tr("SMESH_EXTRUSION"), this);
132 QGridLayout* GroupArgumentsLayout = new QGridLayout(GroupArguments);
133 GroupArgumentsLayout->setSpacing(SPACING); GroupArgumentsLayout->setMargin(MARGIN);
135 myIdValidator = new SMESHGUI_IdValidator(this);
137 // Controls for elements selection
138 SelectorWdg = new SMESHGUI_3TypesSelector( GroupArguments );
140 // Controls for path selection
141 PathGrp = new QGroupBox(tr("SMESH_PATH"), GroupArguments);
142 QGridLayout* PathGrpLayout = new QGridLayout(PathGrp);
143 PathGrpLayout->setSpacing(SPACING); PathGrpLayout->setMargin(MARGIN);
145 // Controls for path mesh selection
146 QLabel* PathMeshLab = new QLabel(tr("SMESH_PATH_MESH"), PathGrp);
148 SelectPathMeshButton = new QPushButton(PathGrp);
149 SelectPathMeshButton->setIcon(selectImage);
150 SelectPathMeshButton->setCheckable(true);
152 PathMeshLineEdit = new QLineEdit(PathGrp);
153 PathMeshLineEdit->setReadOnly(true);
155 // Controls for path starting point selection
156 QLabel* StartPointLab = new QLabel(tr("SMESH_PATH_START"), PathGrp);
158 SelectStartPointButton = new QPushButton(PathGrp);
159 SelectStartPointButton->setIcon(selectImage);
160 SelectStartPointButton->setCheckable(true);
162 StartPointLineEdit = new QLineEdit(PathGrp);
163 StartPointLineEdit->setValidator(new QIntValidator(this));
166 PathGrpLayout->addWidget(PathMeshLab, 0, 0);
167 PathGrpLayout->addWidget(SelectPathMeshButton, 0, 1);
168 PathGrpLayout->addWidget(PathMeshLineEdit, 0, 2);
169 PathGrpLayout->addWidget(StartPointLab, 1, 0);
170 PathGrpLayout->addWidget(SelectStartPointButton, 1, 1);
171 PathGrpLayout->addWidget(StartPointLineEdit, 1, 2);
173 BasePointGrp = new QGroupBox(tr("SMESH_BASE_POINT"), GroupArguments);
174 BasePointGrp->setCheckable(true);
175 BasePointGrp->setChecked(false);
176 QHBoxLayout* BasePointGrpLayout = new QHBoxLayout(BasePointGrp);
177 BasePointGrpLayout->setSpacing(SPACING); BasePointGrpLayout->setMargin(MARGIN);
179 SelectBasePointButton = new QPushButton(BasePointGrp);
180 SelectBasePointButton->setIcon(selectImage);
181 SelectBasePointButton->setCheckable(true);
183 SelectorWdg->GetButtonGroup()->addButton( SelectPathMeshButton );
184 SelectorWdg->GetButtonGroup()->addButton( SelectStartPointButton );
185 SelectorWdg->GetButtonGroup()->addButton( SelectBasePointButton );
187 QLabel* XLab = new QLabel(tr("SMESH_X"), BasePointGrp);
188 XSpin = new SMESHGUI_SpinBox(BasePointGrp);
189 QLabel* YLab = new QLabel(tr("SMESH_Y"), BasePointGrp);
190 YSpin = new SMESHGUI_SpinBox(BasePointGrp);
191 QLabel* ZLab = new QLabel(tr("SMESH_Z"), BasePointGrp);
192 ZSpin = new SMESHGUI_SpinBox(BasePointGrp);
195 BasePointGrpLayout->addWidget(SelectBasePointButton);
196 BasePointGrpLayout->addWidget(XLab);
197 BasePointGrpLayout->addWidget(XSpin);
198 BasePointGrpLayout->addWidget(YLab);
199 BasePointGrpLayout->addWidget(YSpin);
200 BasePointGrpLayout->addWidget(ZLab);
201 BasePointGrpLayout->addWidget(ZSpin);
204 AnglesGrp = new QGroupBox(tr("SMESH_ANGLES"), GroupArguments);
205 AnglesGrp->setCheckable(true);
206 AnglesGrp->setChecked(false);
207 QGridLayout* AnglesGrpLayout = new QGridLayout(AnglesGrp);
208 AnglesGrpLayout->setSpacing(SPACING); AnglesGrpLayout->setMargin(MARGIN);
210 AnglesList = new QListWidget(AnglesGrp);
211 AnglesList->setSelectionMode(QListWidget::ExtendedSelection);
213 AddAngleButton = new QToolButton(AnglesGrp);
214 AddAngleButton->setIcon(addImage);
216 RemoveAngleButton = new QToolButton(AnglesGrp);
217 RemoveAngleButton->setIcon(removeImage);
219 AngleSpin = new SMESHGUI_SpinBox(AnglesGrp);
221 LinearAnglesCheck = new QCheckBox(tr("LINEAR_ANGLES"), AnglesGrp);
223 AnglesGrpLayout->addWidget(AnglesList, 0, 0, 4, 1);
224 AnglesGrpLayout->addWidget(AddAngleButton, 0, 1);
225 AnglesGrpLayout->addWidget(RemoveAngleButton, 2, 1);
226 AnglesGrpLayout->addWidget(AngleSpin, 0, 2);
227 AnglesGrpLayout->addWidget(LinearAnglesCheck, 4, 0, 1, 3);
228 AnglesGrpLayout->setRowMinimumHeight(1, 10);
229 AnglesGrpLayout->setRowStretch(3, 10);
232 ScalesGrp = new QGroupBox(tr("SMESH_SCALES"), GroupArguments);
233 ScalesGrp->setCheckable(true);
234 ScalesGrp->setChecked(false);
235 QGridLayout* ScalesGrpLayout = new QGridLayout(ScalesGrp);
236 ScalesGrpLayout->setSpacing(SPACING); ScalesGrpLayout->setMargin(MARGIN);
238 ScalesList = new QListWidget(ScalesGrp);
239 ScalesList->setSelectionMode(QListWidget::ExtendedSelection);
241 AddScaleButton = new QToolButton(ScalesGrp);
242 AddScaleButton->setIcon(addImage);
244 RemoveScaleButton = new QToolButton(ScalesGrp);
245 RemoveScaleButton->setIcon(removeImage);
247 ScaleSpin = new SMESHGUI_SpinBox(ScalesGrp);
249 LinearScalesCheck = new QCheckBox(tr("LINEAR_SCALES"), ScalesGrp);
251 ScalesGrpLayout->addWidget(ScalesList, 0, 0, 4, 1);
252 ScalesGrpLayout->addWidget(AddScaleButton, 0, 1);
253 ScalesGrpLayout->addWidget(RemoveScaleButton, 2, 1);
254 ScalesGrpLayout->addWidget(ScaleSpin, 0, 2);
255 ScalesGrpLayout->addWidget(LinearScalesCheck, 4, 0, 1, 3);
256 ScalesGrpLayout->setRowMinimumHeight(1, 10);
257 ScalesGrpLayout->setRowStretch(3, 10);
259 // CheckBox for groups generation
260 MakeGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
261 MakeGroupsCheck->setChecked(true);
264 myPreviewCheckBox = new QCheckBox(tr("PREVIEW"), GroupArguments);
267 GroupArgumentsLayout->addWidget(SelectorWdg, 0, 0, 1, 2);
268 GroupArgumentsLayout->addWidget(PathGrp, 1, 0, 1, 2);
269 GroupArgumentsLayout->addWidget(BasePointGrp, 2, 0, 1, 2);
270 GroupArgumentsLayout->addWidget(AnglesGrp, 3, 0);
271 GroupArgumentsLayout->addWidget(ScalesGrp, 3, 1);
272 GroupArgumentsLayout->addWidget(myPreviewCheckBox, 4, 0);
273 GroupArgumentsLayout->addWidget(MakeGroupsCheck, 5, 0);
275 /***************************************************************/
276 // common buttons group box
277 GroupButtons = new QGroupBox(this);
278 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
279 GroupButtonsLayout->setSpacing(SPACING); GroupButtonsLayout->setMargin(MARGIN);
281 OkButton = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
282 OkButton->setAutoDefault(true);
283 OkButton->setDefault(true);
285 ApplyButton = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
286 ApplyButton->setAutoDefault(true);
288 CloseButton = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
289 CloseButton->setAutoDefault(true);
291 HelpButton = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
292 HelpButton->setAutoDefault(true);
295 GroupButtonsLayout->addWidget(OkButton);
296 GroupButtonsLayout->addSpacing(10);
297 GroupButtonsLayout->addWidget(ApplyButton);
298 GroupButtonsLayout->addSpacing(10);
299 GroupButtonsLayout->addStretch();
300 GroupButtonsLayout->addWidget(CloseButton);
301 GroupButtonsLayout->addWidget(HelpButton);
303 /***************************************************************/
305 topLayout->addWidget(GroupArguments);
306 topLayout->addWidget(GroupButtons);
308 /***************************************************************/
310 XSpin->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
311 YSpin->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
312 ZSpin->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
313 AngleSpin->RangeStepAndValidator(-180.0, 180.0, 5.0, "angle_precision");
314 ScaleSpin->RangeStepAndValidator(COORD_MIN, COORD_MAX, 1.0, "length_precision");
316 mySelector = SMESH::GetViewWindow( mySMESHGUI )->GetSelector();
318 mySMESHGUI->SetActiveDialogBox(this);
320 myPathMeshFilter = new SMESH_TypeFilter(SMESH::IDSOURCE_EDGE);
322 myHelpFileName = "extrusion_along_path.html";
326 /***************************************************************/
327 // signals-slots connections
328 connect(OkButton, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
329 connect(CloseButton, SIGNAL(clicked()), this, SLOT(reject()));
330 connect(ApplyButton, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
331 connect(HelpButton, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
333 connect(AddAngleButton, SIGNAL(clicked()), this, SLOT(OnAngleAdded()));
334 connect(RemoveAngleButton, SIGNAL(clicked()), this, SLOT(OnAngleRemoved()));
335 connect(AddScaleButton, SIGNAL(clicked()), this, SLOT(OnAngleAdded()));
336 connect(RemoveScaleButton, SIGNAL(clicked()), this, SLOT(OnAngleRemoved()));
338 connect(SelectPathMeshButton, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
339 connect(SelectStartPointButton, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
340 connect(SelectBasePointButton, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
341 connect(BasePointGrp, SIGNAL(toggled(bool)), this, SLOT(SetEditCurrentArgument()));
343 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), SLOT(reject()));
344 connect(mySMESHGUI, SIGNAL(SignalActivatedViewManager()), SLOT(onOpenView()));
345 connect(mySMESHGUI, SIGNAL(SignalCloseView()), SLOT(onCloseView()));
346 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), SLOT(DeactivateActiveDialog()));
347 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(SelectionIntoArgument()));
348 connect(SelectorWdg, SIGNAL(selectionChanged()), this, SLOT(toDisplaySimulation()));
349 connect(SelectorWdg, SIGNAL(selectionChanged()), this, SLOT(CheckIsEnable()));
351 connect(StartPointLineEdit, SIGNAL(textChanged(const QString&)),
352 SLOT(onTextChange(const QString&)));
354 connect(XSpin, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
355 connect(YSpin, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
356 connect(ZSpin, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
357 connect(AddAngleButton, SIGNAL(clicked()), this, SLOT(toDisplaySimulation()));
358 connect(RemoveAngleButton, SIGNAL(clicked()), this, SLOT(toDisplaySimulation()));
359 connect(AddScaleButton, SIGNAL(clicked()), this, SLOT(toDisplaySimulation()));
360 connect(RemoveScaleButton, SIGNAL(clicked()), this, SLOT(toDisplaySimulation()));
361 connect(LinearScalesCheck, SIGNAL(toggled(bool)), this, SLOT(toDisplaySimulation()));
362 connect(LinearAnglesCheck, SIGNAL(toggled(bool)), this, SLOT(toDisplaySimulation()));
363 connect(ScalesGrp, SIGNAL(toggled(bool)), this, SLOT(toDisplaySimulation()));
364 connect(AnglesGrp, SIGNAL(toggled(bool)), this, SLOT(toDisplaySimulation()));
367 //To Connect preview check box
368 connectPreviewControl();
370 AnglesList ->installEventFilter(this);
371 ScalesList ->installEventFilter(this);
372 StartPointLineEdit->installEventFilter(this);
373 XSpin->editor() ->installEventFilter(this);
374 YSpin->editor() ->installEventFilter(this);
375 ZSpin->editor() ->installEventFilter(this);
379 resize( minimumSizeHint() );
382 //=================================================================================
383 // function : ~SMESHGUI_ExtrusionAlongPathDlg()
384 // purpose : destructor
385 //=================================================================================
386 SMESHGUI_ExtrusionAlongPathDlg::~SMESHGUI_ExtrusionAlongPathDlg()
388 // no need to delete child widgets, Qt does it all for us
391 //=================================================================================
393 // purpose : initialization
394 //=================================================================================
395 void SMESHGUI_ExtrusionAlongPathDlg::Init (bool ResetControls)
398 myEditCurrentArgument = 0;
400 myPath = SMESH::SMESH_IDSource::_nil();
402 SelectorWdg->Clear();
403 PathMeshLineEdit->clear();
404 StartPointLineEdit->clear();
407 XSpin->SetValue(0.0);
408 YSpin->SetValue(0.0);
409 ZSpin->SetValue(0.0);
411 AngleSpin->SetValue(45);
412 ScaleSpin->SetValue(2);
413 myPreviewCheckBox->setChecked(false);
414 onDisplaySimulation(false);
416 SetEditCurrentArgument(0);
419 //=================================================================================
420 // function : CheckIsEnable()
421 // purpose : Check whether the Ok and Apply buttons should be enabled or not
422 //=================================================================================
424 void SMESHGUI_ExtrusionAlongPathDlg::CheckIsEnable()
426 bool anIsEnable = SelectorWdg->IsAnythingSelected() && isValuesValid();
428 OkButton->setEnabled(anIsEnable);
429 ApplyButton->setEnabled(anIsEnable);
432 //=================================================================================
433 // function : ClickOnApply()
434 // purpose : Called when user presses <Apply> button
435 //=================================================================================
436 bool SMESHGUI_ExtrusionAlongPathDlg::ClickOnApply()
438 if (SMESHGUI::isStudyLocked())
441 if ( !SelectorWdg->IsAnythingSelected() || myPath->_is_nil() )
447 if (StartPointLineEdit->text().trimmed().isEmpty()) {
452 long aNodeStart = StartPointLineEdit->text().toLong(&bOk);
457 QStringList aParameters;
460 SMESH::double_array_var anAngles = getAngles();
461 for (int i = 0; i < myAnglesList.count(); i++)
462 aParameters << AnglesList->item(i)->text();
465 SMESH::PointStruct aBasePoint;
466 if (BasePointGrp->isChecked()) {
467 aBasePoint.x = XSpin->GetValue();
468 aBasePoint.y = YSpin->GetValue();
469 aBasePoint.z = ZSpin->GetValue();
471 aParameters << XSpin->text();
472 aParameters << YSpin->text();
473 aParameters << ZSpin->text();
476 SMESH::double_array_var aScales = getScales();
477 for (int i = 0; i < myScalesList.count(); i++)
478 aParameters << ScalesList->item(i)->text();
480 bool meshHadNewTypeBefore = true;
482 const bool makeGroups = ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() );
485 SUIT_OverrideCursor wc;
487 SMESH::SMESH_Mesh_var mesh = SelectorWdg->GetMesh();
489 mesh->SetParameters( aParameters.join(":").toUtf8().constData() );
491 SMESH::ListOfIDSources_var nodes = new SMESH::ListOfIDSources();
492 SMESH::ListOfIDSources_var edges = new SMESH::ListOfIDSources();
493 SMESH::ListOfIDSources_var faces = new SMESH::ListOfIDSources();
494 maxSelType = SelectorWdg->GetSelected( nodes, edges, faces );
496 // is it necessary to switch on the next Display Mode?
497 SMESH::ElementType newType = (SMESH::ElementType)( maxSelType + 1 );
498 SMESH::array_of_ElementType_var oldTypes = mesh->GetTypes();
499 meshHadNewTypeBefore = false;
500 for ( size_t i = 0; i < oldTypes->length() && !meshHadNewTypeBefore; ++i )
501 meshHadNewTypeBefore = ( oldTypes[i] >= newType );
503 SMESH::SMESH_MeshEditor_var aMeshEditor = mesh->GetMeshEditor();
504 SMESH::SMESH_MeshEditor::Extrusion_Error retVal;
506 SMESH::ListOfGroups_var groups =
507 aMeshEditor->ExtrusionAlongPathObjects( nodes, edges, faces, myPath,
508 GEOM::GEOM_Object::_nil(),
509 aNodeStart, AnglesGrp->isChecked(),
510 anAngles, LinearAnglesCheck->isChecked(),
511 BasePointGrp->isChecked(), aBasePoint, makeGroups,
512 aScales, LinearScalesCheck->isChecked(), retVal );
516 case SMESH::SMESH_MeshEditor::EXTR_NO_ELEMENTS:
517 SUIT_MessageBox::warning(this,
519 tr("NO_ELEMENTS_SELECTED"));
521 case SMESH::SMESH_MeshEditor::EXTR_PATH_NOT_EDGE:
522 SUIT_MessageBox::warning(this,
524 tr("SELECTED_PATH_IS_NOT_EDGE"));
526 case SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE:
527 SUIT_MessageBox::warning(this,
529 tr("BAD_SHAPE_TYPE"));
531 case SMESH::SMESH_MeshEditor::EXTR_BAD_STARTING_NODE:
532 SUIT_MessageBox::warning(this,
534 tr("EXTR_BAD_STARTING_NODE"));
536 case SMESH::SMESH_MeshEditor::EXTR_BAD_ANGLES_NUMBER:
537 SUIT_MessageBox::warning(this,
539 tr("WRONG_ANGLES_NUMBER"));
541 case SMESH::SMESH_MeshEditor::EXTR_CANT_GET_TANGENT:
542 SUIT_MessageBox::warning(this,
544 tr("CANT_GET_TANGENT"));
546 case SMESH::SMESH_MeshEditor::EXTR_OK:
553 SMESH_Actor* actor = SelectorWdg->GetActor();
554 if ( actor && !meshHadNewTypeBefore )
556 unsigned int aMode = actor->GetEntityMode();
557 switch ( maxSelType ) {
558 case SMESH::NODE: // extrude node -> edges
559 actor->SetRepresentation(SMESH_Actor::eEdge);
560 actor->SetEntityMode( aMode |= SMESH_Actor::eEdges ); break;
561 case SMESH::EDGE: // edge -> faces
562 actor->SetRepresentation(SMESH_Actor::eSurface);
563 actor->SetEntityMode( aMode |= SMESH_Actor::eFaces ); break;
564 case SMESH::FACE: // faces -> volumes
565 actor->SetRepresentation(SMESH_Actor::eSurface);
566 actor->SetEntityMode( aMode |= SMESH_Actor::eVolumes ); break;
570 SMESH::Update( actor->getIO(), actor->GetVisibility() );
572 mySMESHGUI->updateObjBrowser(true); // new groups may appear
574 mySelectionMgr->clearSelected();
575 SelectorWdg->Clear();
577 SMESHGUI::Modified();
581 //=================================================================================
582 // function : ClickOnOk()
583 // purpose : Called when user presses <OK> button
584 //=================================================================================
585 void SMESHGUI_ExtrusionAlongPathDlg::ClickOnOk()
591 //=================================================================================
592 // function : ClickOnHelp()
594 //=================================================================================
595 void SMESHGUI_ExtrusionAlongPathDlg::ClickOnHelp()
597 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
599 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
603 platform = "winapplication";
605 platform = "application";
607 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
608 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
609 arg(app->resourceMgr()->stringValue("ExternalBrowser",
611 arg(myHelpFileName));
615 //=================================================================================
616 // function : reject()
617 // purpose : Called when dialog box is closed
618 //=================================================================================
619 void SMESHGUI_ExtrusionAlongPathDlg::reject()
621 disconnect(mySelectionMgr, 0, this, 0);
622 mySelectionMgr->clearFilters();
623 //mySelectionMgr->clearSelected();
624 if (SMESH::GetCurrentVtkView()) {
625 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
626 SMESH::SetPointRepresentation(false);
627 SMESH::SetPickable();
629 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
630 aViewWindow->SetSelectionMode(ActorSelection);
631 mySMESHGUI->ResetState();
636 //=================================================================================
637 // function : onOpenView()
639 //=================================================================================
640 void SMESHGUI_ExtrusionAlongPathDlg::onOpenView()
643 SMESH::SetPointRepresentation(false);
646 mySelector = SMESH::GetViewWindow( mySMESHGUI )->GetSelector();
647 ActivateThisDialog();
651 //=================================================================================
652 // function : onCloseView()
654 //=================================================================================
655 void SMESHGUI_ExtrusionAlongPathDlg::onCloseView()
657 DeactivateActiveDialog();
661 //=======================================================================
662 // function : onTextChange()
664 //=======================================================================
665 void SMESHGUI_ExtrusionAlongPathDlg::onTextChange (const QString& theNewText)
667 QLineEdit* send = (QLineEdit*)sender();
675 if (send == StartPointLineEdit &&
676 myEditCurrentArgument == StartPointLineEdit)
678 if (!myPath->_is_nil()) {
679 SMESH_Actor* aPathActor = SMESH::FindActorByObject(myPath);
680 SMDS_Mesh* aMesh = aPathActor ? aPathActor->GetObject()->GetMesh() : 0;
683 aList.Append(aPathActor->getIO());
684 mySelectionMgr->setSelectedObjects(aList, false);
687 long ind = theNewText.toLong(&bOk);
689 const SMDS_MeshNode* n = aMesh->FindNode(ind);
691 TColStd_MapOfInteger newIndices;
692 newIndices.Add(n->GetID());
693 mySelector->AddOrRemoveIndex( aPathActor->getIO(), newIndices, false );
694 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
695 aViewWindow->highlight( aPathActor->getIO(), true, true );
702 onDisplaySimulation(true);
705 //=================================================================================
706 // function : SelectionIntoArgument()
707 // purpose : Called when selection as changed or other case
708 //=================================================================================
709 void SMESHGUI_ExtrusionAlongPathDlg::SelectionIntoArgument()
713 // return if dialog box is inactive
714 if (!GroupButtons->isEnabled())
717 // selected objects count
718 const SALOME_ListIO& aList = mySelector->StoredIObjects();
719 int nbSel = aList.Extent();
726 const bool isPathDef = ( SelectPathMeshButton->isChecked() ||
727 SelectStartPointButton->isChecked() );
729 if (myEditCurrentArgument == PathMeshLineEdit && isPathDef)
731 // we are now selecting path mesh
733 PathMeshLineEdit->clear();
734 myPath = SMESH::SMESH_IDSource::_nil();
735 StartPointLineEdit->clear();
737 // try to get mesh from selection
738 Handle(SALOME_InteractiveObject) IO = aList.First();
739 myPath = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
740 if( myPath->_is_nil() )
744 SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
745 PathMeshLineEdit->setText(aString);
747 else if (myEditCurrentArgument == StartPointLineEdit && isPathDef )
749 // we are now selecting start point of path
751 StartPointLineEdit->clear();
753 // return if path mesh or path shape is not yet selected
754 if( myPath->_is_nil() )
757 // try to get shape from selection
758 Handle(SALOME_InteractiveObject) IO = aList.First();
760 SMESH_Actor* aPathActor = SMESH::FindActorByObject(myPath);
765 int aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, aPathActor->getIO(), aString);
767 StartPointLineEdit->setText(aString.trimmed());
769 else if ( myEditCurrentArgument == XSpin &&
770 SelectBasePointButton->isChecked() )
772 // we are now selecting base point
773 // reset is not performed here!
775 // return if is not enabled
776 if (!BasePointGrp->isChecked())
779 // try to get shape from selection
780 Handle(SALOME_InteractiveObject) IO = aList.First();
782 // check if geom vertex is selected
783 GEOM::GEOM_Object_var aGeomObj = SMESH::IObjectToInterface<GEOM::GEOM_Object>(IO);
784 TopoDS_Vertex aVertex;
785 if (!aGeomObj->_is_nil()) {
786 if (aGeomObj->IsShape() && GEOMBase::GetShape(aGeomObj, aVertex) && !aVertex.IsNull()) {
787 gp_Pnt aPnt = BRep_Tool::Pnt(aVertex);
788 XSpin->SetValue(aPnt.X());
789 YSpin->SetValue(aPnt.Y());
790 ZSpin->SetValue(aPnt.Z());
795 // check if smesh node is selected
796 SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO(IO);
797 if (aMesh->_is_nil())
801 int aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
802 // return if more than one node is selected
806 SMESH_Actor* aMeshActor = SMESH::FindActorByObject(aMesh);
810 SMDS_Mesh* mesh = aMeshActor->GetObject()->GetMesh();
814 const SMDS_MeshNode* n = mesh->FindNode(aString.toLong());
818 XSpin->SetValue(n->X());
819 YSpin->SetValue(n->Y());
820 ZSpin->SetValue(n->Z());
827 onDisplaySimulation(true);
831 //=================================================================================
832 // function : SetEditCurrentArgument()
834 //=================================================================================
835 void SMESHGUI_ExtrusionAlongPathDlg::SetEditCurrentArgument()
837 QPushButton* send = (QPushButton*)sender();
838 if ( sender() == BasePointGrp )
839 send = SelectBasePointButton;
840 if (send != SelectPathMeshButton &&
841 send != SelectStartPointButton &&
842 send != SelectBasePointButton)
844 SetEditCurrentArgument(send);
847 //=================================================================================
848 // function : SetEditCurrentArgument()
850 //=================================================================================
851 void SMESHGUI_ExtrusionAlongPathDlg::SetEditCurrentArgument (QPushButton* button)
853 disconnect(mySelectionMgr, 0, this, 0);
854 // mySelectionMgr->clearSelected();
855 mySelectionMgr->clearFilters();
856 SMESH::SetPickable();
858 myEditCurrentArgument = 0;
859 if (button == SelectPathMeshButton)
861 myEditCurrentArgument = PathMeshLineEdit;
862 SMESH::SetPointRepresentation(false);
863 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
864 aViewWindow->SetSelectionMode(ActorSelection);
865 mySelectionMgr->installFilter(myPathMeshFilter);
867 else if (button == SelectStartPointButton)
869 myEditCurrentArgument = StartPointLineEdit;
870 if (!myPath->_is_nil()) {
871 SMESH_Actor* aPathActor = SMESH::FindActorByObject(myPath);
873 aPathActor->SetPointRepresentation( true );
874 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
875 aViewWindow->SetSelectionMode(NodeSelection);
876 SMESH::SetPickable(aPathActor);
880 else if (button == SelectBasePointButton)
882 myEditCurrentArgument = XSpin;
883 SMESH::SetPointRepresentation(true);
884 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
885 aViewWindow->SetSelectionMode(NodeSelection);
887 SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter(SMESH::IDSOURCE);
888 SMESH_NumberFilter* aVertexFilter = new SMESH_NumberFilter ("GEOM", TopAbs_SHAPE,
890 QList<SUIT_SelectionFilter*> aListOfFilters;
891 if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
892 if (aVertexFilter) aListOfFilters.append(aVertexFilter);
894 mySelectionMgr->installFilter(new SMESH_LogicalFilter
895 (aListOfFilters, SMESH_LogicalFilter::LO_OR, true));
898 if (myEditCurrentArgument && !myEditCurrentArgument->hasFocus())
899 myEditCurrentArgument->setFocus();
901 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
902 SelectionIntoArgument();
905 //=================================================================================
906 // function : DeactivateActiveDialog()
907 // purpose : Deactivates this dialog
908 //=================================================================================
909 void SMESHGUI_ExtrusionAlongPathDlg::DeactivateActiveDialog()
911 if (GroupButtons->isEnabled())
913 GroupArguments->setEnabled(false);
914 GroupButtons->setEnabled(false);
915 SelectorWdg->setEnabled(false);
916 mySMESHGUI->ResetState();
917 mySMESHGUI->SetActiveDialogBox(0);
921 //=================================================================================
922 // function : ActivateThisDialog()
923 // purpose : Activates this dialog
924 //=================================================================================
925 void SMESHGUI_ExtrusionAlongPathDlg::ActivateThisDialog()
927 // Emit a signal to deactivate the active dialog
928 mySMESHGUI->EmitSignalDeactivateDialog();
929 GroupArguments->setEnabled(true);
930 GroupButtons->setEnabled(true);
931 SelectorWdg->setEnabled(true);
933 mySMESHGUI->SetActiveDialogBox(this);
934 SelectionIntoArgument();
937 //=================================================================================
938 // function : enterEvent()
940 //=================================================================================
941 void SMESHGUI_ExtrusionAlongPathDlg::enterEvent (QEvent*)
943 if ( !GroupButtons->isEnabled() ) {
944 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
945 if ( aViewWindow && !mySelector) {
946 mySelector = aViewWindow->GetSelector();
948 ActivateThisDialog();
952 //=======================================================================
953 // function : OnAngleAdded()
954 // purpose : Called when user adds angle to the list
955 //=======================================================================
956 void SMESHGUI_ExtrusionAlongPathDlg::OnAngleAdded()
958 if ( sender() == AddAngleButton )
961 if( !AngleSpin->isValid( msg, true ) ) {
962 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
963 if ( !msg.isEmpty() )
965 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
968 AnglesList->addItem(AngleSpin->text());
969 myAnglesList.append(AngleSpin->GetValue());
972 if ( sender() == AddScaleButton )
975 if( !ScaleSpin->isValid( msg, true ) ) {
976 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
977 if ( !msg.isEmpty() )
979 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
982 ScalesList->addItem(ScaleSpin->text());
983 myScalesList.append(ScaleSpin->GetValue());
986 updateLinearAngles();
989 //=======================================================================
990 // function : OnAngleRemoved()
991 // purpose : Called when user removes angle(s) from the list
992 //=======================================================================
993 void SMESHGUI_ExtrusionAlongPathDlg::OnAngleRemoved()
997 if ( sender() == RemoveScaleButton )
1000 list = & myScalesList;
1004 widget = AnglesList;
1005 list = & myAnglesList;
1008 QList<QListWidgetItem*> aList = widget->selectedItems();
1009 QListWidgetItem* anItem;
1010 foreach(anItem, aList) {
1011 list->removeAt( widget->row( anItem ));
1015 updateLinearAngles();
1018 //=================================================================================
1019 // function : eventFilter()
1020 // purpose : event filter ???
1021 //=================================================================================
1022 bool SMESHGUI_ExtrusionAlongPathDlg::eventFilter (QObject* object, QEvent* event)
1024 if (event->type() == QEvent::KeyPress) {
1025 QKeyEvent* ke = (QKeyEvent*)event;
1026 if (object == AnglesList) {
1027 if (ke->key() == Qt::Key_Delete)
1028 RemoveAngleButton->click();
1030 if (object == ScalesList) {
1031 if (ke->key() == Qt::Key_Delete)
1032 RemoveScaleButton->click();
1035 else if (event->type() == QEvent::FocusIn) {
1036 if (object == StartPointLineEdit) {
1037 if (myEditCurrentArgument != StartPointLineEdit)
1038 SetEditCurrentArgument(SelectStartPointButton);
1040 else if (object == XSpin->editor() || object == YSpin->editor() || object == ZSpin->editor()) {
1041 if (myEditCurrentArgument != XSpin)
1042 SetEditCurrentArgument(SelectBasePointButton);
1045 return QDialog::eventFilter(object, event);
1048 //=================================================================================
1049 // function : keyPressEvent()
1051 //=================================================================================
1052 void SMESHGUI_ExtrusionAlongPathDlg::keyPressEvent( QKeyEvent* e )
1054 QDialog::keyPressEvent( e );
1055 if ( e->isAccepted() )
1058 if ( e->key() == Qt::Key_F1 ) {
1064 //=================================================================================
1065 // function : isValid
1067 //=================================================================================
1068 bool SMESHGUI_ExtrusionAlongPathDlg::isValid()
1072 ok = XSpin->isValid( msg, true ) && ok;
1073 ok = YSpin->isValid( msg, true ) && ok;
1074 ok = ZSpin->isValid( msg, true ) && ok;
1077 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1078 if ( !msg.isEmpty() )
1080 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
1086 //=================================================================================
1087 // function : updateLinearAngles
1089 //=================================================================================
1090 void SMESHGUI_ExtrusionAlongPathDlg::updateLinearAngles()
1092 bool enableLinear = true;
1093 for( int row = 0, nbRows = AnglesList->count(); row < nbRows; row++ ) {
1094 if( QListWidgetItem* anItem = AnglesList->item( row ) ) {
1095 enableLinear = false;
1096 anItem->text().toDouble(&enableLinear);
1102 LinearAnglesCheck->setChecked( false );
1103 LinearAnglesCheck->setEnabled( enableLinear );
1105 enableLinear = true;
1106 for( int row = 0, nbRows = ScalesList->count(); row < nbRows; row++ ) {
1107 if( QListWidgetItem* anItem = ScalesList->item( row ) ) {
1108 enableLinear = false;
1109 anItem->text().toDouble(&enableLinear);
1115 LinearScalesCheck->setChecked( false );
1116 LinearScalesCheck->setEnabled( enableLinear );
1119 //=================================================================================
1120 // function : isValuesValid()
1121 // purpose : Return true in case if values entered into dialog are valid
1122 //=================================================================================
1124 bool SMESHGUI_ExtrusionAlongPathDlg::isValuesValid()
1126 if ( myPath->_is_nil() )
1130 long aNodeStart = StartPointLineEdit->text().toLong(&bOk);
1131 if ( !bOk || aNodeStart < 1 )
1134 SMESH::SMESH_Mesh_var mesh = myPath->GetMesh();
1135 if ( mesh->_is_nil() )
1138 SMESH::ElementType type = mesh->GetElementType( aNodeStart, false );
1139 if ( type != SMESH::NODE )
1142 if ( mesh->HasShapeToMesh() )
1144 SMESH::NodePosition_var pos = mesh->GetNodePosition( aNodeStart );
1145 if ( pos->shapeType != GEOM::VERTEX )
1150 SMESH::long_array_var elems = mesh->GetNodeInverseElements( aNodeStart, SMESH::ALL );
1151 if ( elems->length() != 1 ||
1152 mesh->GetElementType( elems[0], true ) != SMESH::EDGE )
1158 //=================================================================================
1159 // function : onDisplaySimulation
1160 // purpose : Show/Hide preview
1161 //=================================================================================
1163 void SMESHGUI_ExtrusionAlongPathDlg::onDisplaySimulation( bool toDisplayPreview )
1165 if ( myPreviewCheckBox->isChecked() && toDisplayPreview ) {
1166 if ( SelectorWdg->IsAnythingSelected() && isValid() && isValuesValid())
1168 // get angles and scales
1169 SMESH::double_array_var anAngles = getAngles();
1170 SMESH::double_array_var aScales = getScales();
1173 SMESH::PointStruct aBasePoint;
1174 if (BasePointGrp->isChecked()) {
1175 aBasePoint.x = XSpin->GetValue();
1176 aBasePoint.y = YSpin->GetValue();
1177 aBasePoint.z = ZSpin->GetValue();
1180 long aNodeStart = StartPointLineEdit->text().toLong(&bOk);
1184 SUIT_OverrideCursor wc;
1186 SMESH::SMESH_MeshEditor::Extrusion_Error retVal;
1187 SMESH::SMESH_Mesh_var mesh = SelectorWdg->GetMesh();
1188 SMESH::SMESH_MeshEditor_var meshEditor = mesh->GetMeshEditPreviewer();
1190 SMESH::ListOfIDSources_var nodes = new SMESH::ListOfIDSources();
1191 SMESH::ListOfIDSources_var edges = new SMESH::ListOfIDSources();
1192 SMESH::ListOfIDSources_var faces = new SMESH::ListOfIDSources();
1193 SelectorWdg->GetSelected( nodes, edges, faces );
1194 const bool makeGroups = false;
1196 SMESH::ListOfGroups_var groups =
1197 meshEditor->ExtrusionAlongPathObjects( nodes, edges, faces, myPath,
1198 GEOM::GEOM_Object::_nil(),
1199 aNodeStart, AnglesGrp->isChecked(),
1200 anAngles, LinearAnglesCheck->isChecked(),
1201 BasePointGrp->isChecked(), aBasePoint,
1203 aScales, LinearScalesCheck->isChecked(),
1206 if( retVal == SMESH::SMESH_MeshEditor::EXTR_OK )
1208 SMESH::MeshPreviewStruct_var aMeshPreviewStruct = meshEditor->GetPreviewData();
1209 mySimulation->SetData( aMeshPreviewStruct.in() );
1230 //=======================================================================
1231 //function : getAngles
1232 //purpose : return CORBA array of angles
1233 //=======================================================================
1235 SMESH::double_array_var SMESHGUI_ExtrusionAlongPathDlg::getAngles()
1237 SMESH::double_array_var anAngles = new SMESH::double_array;
1238 if ( AnglesGrp->isChecked() )
1240 anAngles->length( myAnglesList.count() );
1241 for (int i = 0; i < myAnglesList.count(); i++)
1242 anAngles[ i ] = myAnglesList[ i ] * M_PI / 180.;
1247 //=======================================================================
1248 //function : getScales
1249 //purpose : return CORBA array of scale factors
1250 //=======================================================================
1252 SMESH::double_array_var SMESHGUI_ExtrusionAlongPathDlg::getScales()
1254 SMESH::double_array_var anScales = new SMESH::double_array;
1255 if ( ScalesGrp->isChecked() )
1257 anScales->length( myScalesList.count() );
1258 for (int i = 0; i < myScalesList.count(); i++)
1259 anScales[ i ] = myScalesList[ i ];