1 // Copyright (C) 2007-2021 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, 3, 2);
268 GroupArgumentsLayout->addWidget(PathGrp, 0, 2, 1, 2);
269 GroupArgumentsLayout->addWidget(BasePointGrp, 1, 2, 1, 2);
270 GroupArgumentsLayout->addWidget(AnglesGrp, 2, 2);
271 GroupArgumentsLayout->addWidget(ScalesGrp, 2, 3);
272 GroupArgumentsLayout->addWidget(myPreviewCheckBox, 3, 0);
273 GroupArgumentsLayout->addWidget(MakeGroupsCheck, 3, 1);
274 SelectorWdg->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
275 SelectorWdg->setMinimumWidth(320);
277 /***************************************************************/
278 // common buttons group box
279 GroupButtons = new QGroupBox(this);
280 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
281 GroupButtonsLayout->setSpacing(SPACING); GroupButtonsLayout->setMargin(MARGIN);
283 OkButton = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
284 OkButton->setAutoDefault(true);
285 OkButton->setDefault(true);
287 ApplyButton = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
288 ApplyButton->setAutoDefault(true);
290 CloseButton = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
291 CloseButton->setAutoDefault(true);
293 HelpButton = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
294 HelpButton->setAutoDefault(true);
297 GroupButtonsLayout->addWidget(OkButton);
298 GroupButtonsLayout->addSpacing(10);
299 GroupButtonsLayout->addWidget(ApplyButton);
300 GroupButtonsLayout->addSpacing(10);
301 GroupButtonsLayout->addStretch();
302 GroupButtonsLayout->addWidget(CloseButton);
303 GroupButtonsLayout->addWidget(HelpButton);
305 /***************************************************************/
307 topLayout->addWidget(GroupArguments);
308 topLayout->addWidget(GroupButtons);
310 /***************************************************************/
312 XSpin->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
313 YSpin->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
314 ZSpin->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
315 AngleSpin->RangeStepAndValidator(-180.0, 180.0, 5.0, "angle_precision");
316 ScaleSpin->RangeStepAndValidator(COORD_MIN, COORD_MAX, 1.0, "length_precision");
318 mySelector = SMESH::GetViewWindow( mySMESHGUI )->GetSelector();
320 mySMESHGUI->SetActiveDialogBox(this);
322 myPathMeshFilter = new SMESH_TypeFilter(SMESH::IDSOURCE_EDGE);
324 myHelpFileName = "extrusion_along_path.html";
328 /***************************************************************/
329 // signals-slots connections
330 connect(OkButton, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
331 connect(CloseButton, SIGNAL(clicked()), this, SLOT(reject()));
332 connect(ApplyButton, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
333 connect(HelpButton, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
335 connect(AddAngleButton, SIGNAL(clicked()), this, SLOT(OnAngleAdded()));
336 connect(RemoveAngleButton, SIGNAL(clicked()), this, SLOT(OnAngleRemoved()));
337 connect(AddScaleButton, SIGNAL(clicked()), this, SLOT(OnAngleAdded()));
338 connect(RemoveScaleButton, SIGNAL(clicked()), this, SLOT(OnAngleRemoved()));
340 connect(SelectPathMeshButton, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
341 connect(SelectStartPointButton, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
342 connect(SelectBasePointButton, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
343 connect(BasePointGrp, SIGNAL(toggled(bool)), this, SLOT(SetEditCurrentArgument()));
345 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), SLOT(reject()));
346 connect(mySMESHGUI, SIGNAL(SignalActivatedViewManager()), SLOT(onOpenView()));
347 connect(mySMESHGUI, SIGNAL(SignalCloseView()), SLOT(onCloseView()));
348 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), SLOT(DeactivateActiveDialog()));
349 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(SelectionIntoArgument()));
350 connect(SelectorWdg, SIGNAL(selectionChanged()), this, SLOT(toDisplaySimulation()));
351 connect(SelectorWdg, SIGNAL(selectionChanged()), this, SLOT(CheckIsEnable()));
353 connect(StartPointLineEdit, SIGNAL(textChanged(const QString&)),
354 SLOT(onTextChange(const QString&)));
356 connect(XSpin, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
357 connect(YSpin, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
358 connect(ZSpin, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
359 connect(AddAngleButton, SIGNAL(clicked()), this, SLOT(toDisplaySimulation()));
360 connect(RemoveAngleButton, SIGNAL(clicked()), this, SLOT(toDisplaySimulation()));
361 connect(AddScaleButton, SIGNAL(clicked()), this, SLOT(toDisplaySimulation()));
362 connect(RemoveScaleButton, SIGNAL(clicked()), this, SLOT(toDisplaySimulation()));
363 connect(LinearScalesCheck, SIGNAL(toggled(bool)), this, SLOT(toDisplaySimulation()));
364 connect(LinearAnglesCheck, SIGNAL(toggled(bool)), this, SLOT(toDisplaySimulation()));
365 connect(ScalesGrp, SIGNAL(toggled(bool)), this, SLOT(toDisplaySimulation()));
366 connect(AnglesGrp, SIGNAL(toggled(bool)), this, SLOT(toDisplaySimulation()));
369 //To Connect preview check box
370 connectPreviewControl();
372 AnglesList ->installEventFilter(this);
373 ScalesList ->installEventFilter(this);
374 StartPointLineEdit->installEventFilter(this);
375 XSpin->editor() ->installEventFilter(this);
376 YSpin->editor() ->installEventFilter(this);
377 ZSpin->editor() ->installEventFilter(this);
381 resize( minimumSizeHint() );
384 //=================================================================================
385 // function : ~SMESHGUI_ExtrusionAlongPathDlg()
386 // purpose : destructor
387 //=================================================================================
388 SMESHGUI_ExtrusionAlongPathDlg::~SMESHGUI_ExtrusionAlongPathDlg()
390 // no need to delete child widgets, Qt does it all for us
393 //=================================================================================
395 // purpose : initialization
396 //=================================================================================
397 void SMESHGUI_ExtrusionAlongPathDlg::Init (bool ResetControls)
400 myEditCurrentArgument = 0;
402 myPath = SMESH::SMESH_IDSource::_nil();
404 SelectorWdg->Clear();
405 PathMeshLineEdit->clear();
406 StartPointLineEdit->clear();
409 XSpin->SetValue(0.0);
410 YSpin->SetValue(0.0);
411 ZSpin->SetValue(0.0);
413 AngleSpin->SetValue(45);
414 ScaleSpin->SetValue(2);
415 myPreviewCheckBox->setChecked(false);
416 onDisplaySimulation(false);
418 SetEditCurrentArgument(0);
421 //=================================================================================
422 // function : CheckIsEnable()
423 // purpose : Check whether the Ok and Apply buttons should be enabled or not
424 //=================================================================================
426 void SMESHGUI_ExtrusionAlongPathDlg::CheckIsEnable()
428 bool anIsEnable = SelectorWdg->IsAnythingSelected() && isValuesValid();
430 OkButton->setEnabled(anIsEnable);
431 ApplyButton->setEnabled(anIsEnable);
434 //=================================================================================
435 // function : ClickOnApply()
436 // purpose : Called when user presses <Apply> button
437 //=================================================================================
438 bool SMESHGUI_ExtrusionAlongPathDlg::ClickOnApply()
440 if (SMESHGUI::isStudyLocked())
443 if ( !SelectorWdg->IsAnythingSelected() || myPath->_is_nil() )
449 if (StartPointLineEdit->text().trimmed().isEmpty()) {
454 long aNodeStart = StartPointLineEdit->text().toLong(&bOk);
459 QStringList aParameters;
462 SMESH::double_array_var anAngles = getAngles();
463 for (int i = 0; i < myAnglesList.count(); i++)
464 aParameters << AnglesList->item(i)->text();
467 SMESH::PointStruct aBasePoint;
468 if (BasePointGrp->isChecked()) {
469 aBasePoint.x = XSpin->GetValue();
470 aBasePoint.y = YSpin->GetValue();
471 aBasePoint.z = ZSpin->GetValue();
473 aParameters << XSpin->text();
474 aParameters << YSpin->text();
475 aParameters << ZSpin->text();
478 SMESH::double_array_var aScales = getScales();
479 for (int i = 0; i < myScalesList.count(); i++)
480 aParameters << ScalesList->item(i)->text();
482 bool meshHadNewTypeBefore = true;
484 const bool makeGroups = ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() );
487 SUIT_OverrideCursor wc;
489 SMESH::SMESH_Mesh_var mesh = SelectorWdg->GetMesh();
491 mesh->SetParameters( aParameters.join(":").toUtf8().constData() );
493 SMESH::ListOfIDSources_var nodes = new SMESH::ListOfIDSources();
494 SMESH::ListOfIDSources_var edges = new SMESH::ListOfIDSources();
495 SMESH::ListOfIDSources_var faces = new SMESH::ListOfIDSources();
496 maxSelType = SelectorWdg->GetSelected( nodes, edges, faces );
498 // is it necessary to switch on the next Display Mode?
499 SMESH::ElementType newType = (SMESH::ElementType)( maxSelType + 1 );
500 SMESH::array_of_ElementType_var oldTypes = mesh->GetTypes();
501 meshHadNewTypeBefore = false;
502 for ( size_t i = 0; i < oldTypes->length() && !meshHadNewTypeBefore; ++i )
503 meshHadNewTypeBefore = ( oldTypes[i] >= newType );
505 SMESH::SMESH_MeshEditor_var aMeshEditor = mesh->GetMeshEditor();
506 SMESH::SMESH_MeshEditor::Extrusion_Error retVal;
508 SMESH::ListOfGroups_var groups =
509 aMeshEditor->ExtrusionAlongPathObjects( nodes, edges, faces, myPath,
510 GEOM::GEOM_Object::_nil(),
511 aNodeStart, AnglesGrp->isChecked(),
512 anAngles, LinearAnglesCheck->isChecked(),
513 BasePointGrp->isChecked(), aBasePoint, makeGroups,
514 aScales, LinearScalesCheck->isChecked(), retVal );
518 case SMESH::SMESH_MeshEditor::EXTR_NO_ELEMENTS:
519 SUIT_MessageBox::warning(this,
521 tr("NO_ELEMENTS_SELECTED"));
523 case SMESH::SMESH_MeshEditor::EXTR_PATH_NOT_EDGE:
524 SUIT_MessageBox::warning(this,
526 tr("SELECTED_PATH_IS_NOT_EDGE"));
528 case SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE:
529 SUIT_MessageBox::warning(this,
531 tr("BAD_SHAPE_TYPE"));
533 case SMESH::SMESH_MeshEditor::EXTR_BAD_STARTING_NODE:
534 SUIT_MessageBox::warning(this,
536 tr("EXTR_BAD_STARTING_NODE"));
538 case SMESH::SMESH_MeshEditor::EXTR_BAD_ANGLES_NUMBER:
539 SUIT_MessageBox::warning(this,
541 tr("WRONG_ANGLES_NUMBER"));
543 case SMESH::SMESH_MeshEditor::EXTR_CANT_GET_TANGENT:
544 SUIT_MessageBox::warning(this,
546 tr("CANT_GET_TANGENT"));
548 case SMESH::SMESH_MeshEditor::EXTR_OK:
555 SMESH_Actor* actor = SelectorWdg->GetActor();
556 if ( actor && !meshHadNewTypeBefore )
558 unsigned int aMode = actor->GetEntityMode();
559 switch ( maxSelType ) {
560 case SMESH::NODE: // extrude node -> edges
561 actor->SetRepresentation(SMESH_Actor::eEdge);
562 actor->SetEntityMode( aMode |= SMESH_Actor::eEdges ); break;
563 case SMESH::EDGE: // edge -> faces
564 actor->SetRepresentation(SMESH_Actor::eSurface);
565 actor->SetEntityMode( aMode |= SMESH_Actor::eFaces ); break;
566 case SMESH::FACE: // faces -> volumes
567 actor->SetRepresentation(SMESH_Actor::eSurface);
568 actor->SetEntityMode( aMode |= SMESH_Actor::eVolumes ); break;
572 SMESH::Update( actor->getIO(), actor->GetVisibility() );
574 mySMESHGUI->updateObjBrowser(true); // new groups may appear
576 mySelectionMgr->clearSelected();
577 SelectorWdg->Clear();
579 SMESHGUI::Modified();
583 //=================================================================================
584 // function : ClickOnOk()
585 // purpose : Called when user presses <OK> button
586 //=================================================================================
587 void SMESHGUI_ExtrusionAlongPathDlg::ClickOnOk()
593 //=================================================================================
594 // function : ClickOnHelp()
596 //=================================================================================
597 void SMESHGUI_ExtrusionAlongPathDlg::ClickOnHelp()
599 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
601 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
605 platform = "winapplication";
607 platform = "application";
609 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
610 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
611 arg(app->resourceMgr()->stringValue("ExternalBrowser",
613 arg(myHelpFileName));
617 //=================================================================================
618 // function : reject()
619 // purpose : Called when dialog box is closed
620 //=================================================================================
621 void SMESHGUI_ExtrusionAlongPathDlg::reject()
623 disconnect(mySelectionMgr, 0, this, 0);
624 mySelectionMgr->clearFilters();
625 //mySelectionMgr->clearSelected();
626 if (SMESH::GetCurrentVtkView()) {
627 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
628 SMESH::SetPointRepresentation(false);
629 SMESH::SetPickable();
631 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
632 aViewWindow->SetSelectionMode(ActorSelection);
633 mySMESHGUI->ResetState();
638 //=================================================================================
639 // function : onOpenView()
641 //=================================================================================
642 void SMESHGUI_ExtrusionAlongPathDlg::onOpenView()
645 SMESH::SetPointRepresentation(false);
648 mySelector = SMESH::GetViewWindow( mySMESHGUI )->GetSelector();
649 ActivateThisDialog();
653 //=================================================================================
654 // function : onCloseView()
656 //=================================================================================
657 void SMESHGUI_ExtrusionAlongPathDlg::onCloseView()
659 DeactivateActiveDialog();
663 //=======================================================================
664 // function : onTextChange()
666 //=======================================================================
667 void SMESHGUI_ExtrusionAlongPathDlg::onTextChange (const QString& theNewText)
669 QLineEdit* send = (QLineEdit*)sender();
677 if (send == StartPointLineEdit &&
678 myEditCurrentArgument == StartPointLineEdit)
680 if (!myPath->_is_nil()) {
681 SMESH_Actor* aPathActor = SMESH::FindActorByObject(myPath);
682 SMDS_Mesh* aMesh = aPathActor ? aPathActor->GetObject()->GetMesh() : 0;
685 aList.Append(aPathActor->getIO());
686 mySelectionMgr->setSelectedObjects(aList, false);
689 long ind = theNewText.toLong(&bOk);
691 const SMDS_MeshNode* n = aMesh->FindNode(ind);
693 SVTK_TVtkIDsMap newIndices;
694 newIndices.Add(n->GetID());
695 mySelector->AddOrRemoveIndex( aPathActor->getIO(), newIndices, false );
696 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
697 aViewWindow->highlight( aPathActor->getIO(), true, true );
704 onDisplaySimulation(true);
707 //=================================================================================
708 // function : SelectionIntoArgument()
709 // purpose : Called when selection as changed or other case
710 //=================================================================================
711 void SMESHGUI_ExtrusionAlongPathDlg::SelectionIntoArgument()
715 // return if dialog box is inactive
716 if (!GroupButtons->isEnabled())
719 // selected objects count
720 const SALOME_ListIO& aList = mySelector->StoredIObjects();
721 int nbSel = aList.Extent();
728 const bool isPathDef = ( SelectPathMeshButton->isChecked() ||
729 SelectStartPointButton->isChecked() );
731 if (myEditCurrentArgument == PathMeshLineEdit && isPathDef)
733 // we are now selecting path mesh
735 PathMeshLineEdit->clear();
736 myPath = SMESH::SMESH_IDSource::_nil();
737 StartPointLineEdit->clear();
739 // try to get mesh from selection
740 Handle(SALOME_InteractiveObject) IO = aList.First();
741 myPath = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
742 if( myPath->_is_nil() )
746 SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
747 PathMeshLineEdit->setText(aString);
749 else if (myEditCurrentArgument == StartPointLineEdit && isPathDef )
751 // we are now selecting start point of path
753 StartPointLineEdit->clear();
755 // return if path mesh or path shape is not yet selected
756 if( myPath->_is_nil() )
759 // try to get shape from selection
760 Handle(SALOME_InteractiveObject) IO = aList.First();
762 SMESH_Actor* aPathActor = SMESH::FindActorByObject(myPath);
767 int aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, aPathActor->getIO(), aString);
769 StartPointLineEdit->setText(aString.trimmed());
771 else if ( myEditCurrentArgument == XSpin &&
772 SelectBasePointButton->isChecked() )
774 // we are now selecting base point
775 // reset is not performed here!
777 // return if is not enabled
778 if (!BasePointGrp->isChecked())
781 // try to get shape from selection
782 Handle(SALOME_InteractiveObject) IO = aList.First();
784 // check if geom vertex is selected
785 GEOM::GEOM_Object_var aGeomObj = SMESH::IObjectToInterface<GEOM::GEOM_Object>(IO);
786 TopoDS_Vertex aVertex;
787 if (!aGeomObj->_is_nil()) {
788 if (aGeomObj->IsShape() && GEOMBase::GetShape(aGeomObj, aVertex) && !aVertex.IsNull()) {
789 gp_Pnt aPnt = BRep_Tool::Pnt(aVertex);
790 XSpin->SetValue(aPnt.X());
791 YSpin->SetValue(aPnt.Y());
792 ZSpin->SetValue(aPnt.Z());
797 // check if smesh node is selected
798 SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO(IO);
799 if (aMesh->_is_nil())
803 int aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
804 // return if more than one node is selected
808 SMESH_Actor* aMeshActor = SMESH::FindActorByObject(aMesh);
812 SMDS_Mesh* mesh = aMeshActor->GetObject()->GetMesh();
816 const SMDS_MeshNode* n = mesh->FindNode(aString.toLong());
820 XSpin->SetValue(n->X());
821 YSpin->SetValue(n->Y());
822 ZSpin->SetValue(n->Z());
829 onDisplaySimulation(true);
833 //=================================================================================
834 // function : SetEditCurrentArgument()
836 //=================================================================================
837 void SMESHGUI_ExtrusionAlongPathDlg::SetEditCurrentArgument()
839 QPushButton* send = (QPushButton*)sender();
840 if ( sender() == BasePointGrp )
841 send = SelectBasePointButton;
842 if (send != SelectPathMeshButton &&
843 send != SelectStartPointButton &&
844 send != SelectBasePointButton)
846 SetEditCurrentArgument(send);
849 //=================================================================================
850 // function : SetEditCurrentArgument()
852 //=================================================================================
853 void SMESHGUI_ExtrusionAlongPathDlg::SetEditCurrentArgument (QPushButton* button)
855 disconnect(mySelectionMgr, 0, this, 0);
856 // mySelectionMgr->clearSelected();
857 mySelectionMgr->clearFilters();
858 SMESH::SetPickable();
860 myEditCurrentArgument = 0;
861 if (button == SelectPathMeshButton)
863 myEditCurrentArgument = PathMeshLineEdit;
864 SMESH::SetPointRepresentation(false);
865 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
866 aViewWindow->SetSelectionMode(ActorSelection);
867 mySelectionMgr->installFilter(myPathMeshFilter);
869 else if (button == SelectStartPointButton)
871 myEditCurrentArgument = StartPointLineEdit;
872 if (!myPath->_is_nil()) {
873 SMESH_Actor* aPathActor = SMESH::FindActorByObject(myPath);
875 aPathActor->SetPointRepresentation( true );
876 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
877 aViewWindow->SetSelectionMode(NodeSelection);
878 SMESH::SetPickable(aPathActor);
882 else if (button == SelectBasePointButton)
884 myEditCurrentArgument = XSpin;
885 SMESH::SetPointRepresentation(true);
886 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
887 aViewWindow->SetSelectionMode(NodeSelection);
889 SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter(SMESH::IDSOURCE);
890 SMESH_NumberFilter* aVertexFilter = new SMESH_NumberFilter ("GEOM", TopAbs_SHAPE,
892 QList<SUIT_SelectionFilter*> aListOfFilters;
893 if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
894 if (aVertexFilter) aListOfFilters.append(aVertexFilter);
896 mySelectionMgr->installFilter(new SMESH_LogicalFilter
897 (aListOfFilters, SMESH_LogicalFilter::LO_OR, true));
900 if (myEditCurrentArgument && !myEditCurrentArgument->hasFocus())
901 myEditCurrentArgument->setFocus();
903 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
904 SelectionIntoArgument();
907 //=================================================================================
908 // function : DeactivateActiveDialog()
909 // purpose : Deactivates this dialog
910 //=================================================================================
911 void SMESHGUI_ExtrusionAlongPathDlg::DeactivateActiveDialog()
913 if (GroupButtons->isEnabled())
915 GroupArguments->setEnabled(false);
916 GroupButtons->setEnabled(false);
917 SelectorWdg->setEnabled(false);
918 mySMESHGUI->ResetState();
919 mySMESHGUI->SetActiveDialogBox(0);
923 //=================================================================================
924 // function : ActivateThisDialog()
925 // purpose : Activates this dialog
926 //=================================================================================
927 void SMESHGUI_ExtrusionAlongPathDlg::ActivateThisDialog()
929 // Emit a signal to deactivate the active dialog
930 mySMESHGUI->EmitSignalDeactivateDialog();
931 GroupArguments->setEnabled(true);
932 GroupButtons->setEnabled(true);
933 SelectorWdg->setEnabled(true);
935 mySMESHGUI->SetActiveDialogBox(this);
936 SelectionIntoArgument();
939 //=================================================================================
940 // function : enterEvent()
942 //=================================================================================
943 void SMESHGUI_ExtrusionAlongPathDlg::enterEvent (QEvent*)
945 if ( !GroupButtons->isEnabled() ) {
946 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
947 if ( aViewWindow && !mySelector) {
948 mySelector = aViewWindow->GetSelector();
950 ActivateThisDialog();
954 //=======================================================================
955 // function : OnAngleAdded()
956 // purpose : Called when user adds angle to the list
957 //=======================================================================
958 void SMESHGUI_ExtrusionAlongPathDlg::OnAngleAdded()
960 if ( sender() == AddAngleButton )
963 if( !AngleSpin->isValid( msg, true ) ) {
964 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
965 if ( !msg.isEmpty() )
967 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
970 AnglesList->addItem(AngleSpin->text());
971 myAnglesList.append(AngleSpin->GetValue());
974 if ( sender() == AddScaleButton )
977 if( !ScaleSpin->isValid( msg, true ) ) {
978 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
979 if ( !msg.isEmpty() )
981 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
984 ScalesList->addItem(ScaleSpin->text());
985 myScalesList.append(ScaleSpin->GetValue());
988 updateLinearAngles();
991 //=======================================================================
992 // function : OnAngleRemoved()
993 // purpose : Called when user removes angle(s) from the list
994 //=======================================================================
995 void SMESHGUI_ExtrusionAlongPathDlg::OnAngleRemoved()
999 if ( sender() == RemoveScaleButton )
1001 widget = ScalesList;
1002 list = & myScalesList;
1006 widget = AnglesList;
1007 list = & myAnglesList;
1010 QList<QListWidgetItem*> aList = widget->selectedItems();
1011 QListWidgetItem* anItem;
1012 foreach(anItem, aList) {
1013 list->removeAt( widget->row( anItem ));
1017 updateLinearAngles();
1020 //=================================================================================
1021 // function : eventFilter()
1022 // purpose : event filter ???
1023 //=================================================================================
1024 bool SMESHGUI_ExtrusionAlongPathDlg::eventFilter (QObject* object, QEvent* event)
1026 if (event->type() == QEvent::KeyPress) {
1027 QKeyEvent* ke = (QKeyEvent*)event;
1028 if (object == AnglesList) {
1029 if (ke->key() == Qt::Key_Delete)
1030 RemoveAngleButton->click();
1032 if (object == ScalesList) {
1033 if (ke->key() == Qt::Key_Delete)
1034 RemoveScaleButton->click();
1037 else if (event->type() == QEvent::FocusIn) {
1038 if (object == StartPointLineEdit) {
1039 if (myEditCurrentArgument != StartPointLineEdit)
1040 SetEditCurrentArgument(SelectStartPointButton);
1042 else if (object == XSpin->editor() || object == YSpin->editor() || object == ZSpin->editor()) {
1043 if (myEditCurrentArgument != XSpin)
1044 SetEditCurrentArgument(SelectBasePointButton);
1047 return QDialog::eventFilter(object, event);
1050 //=================================================================================
1051 // function : keyPressEvent()
1053 //=================================================================================
1054 void SMESHGUI_ExtrusionAlongPathDlg::keyPressEvent( QKeyEvent* e )
1056 QDialog::keyPressEvent( e );
1057 if ( e->isAccepted() )
1060 if ( e->key() == Qt::Key_F1 ) {
1066 //=================================================================================
1067 // function : isValid
1069 //=================================================================================
1070 bool SMESHGUI_ExtrusionAlongPathDlg::isValid()
1074 ok = XSpin->isValid( msg, true ) && ok;
1075 ok = YSpin->isValid( msg, true ) && ok;
1076 ok = ZSpin->isValid( msg, true ) && ok;
1079 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1080 if ( !msg.isEmpty() )
1082 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
1088 //=================================================================================
1089 // function : updateLinearAngles
1091 //=================================================================================
1092 void SMESHGUI_ExtrusionAlongPathDlg::updateLinearAngles()
1094 bool enableLinear = true;
1095 for( int row = 0, nbRows = AnglesList->count(); row < nbRows; row++ ) {
1096 if( QListWidgetItem* anItem = AnglesList->item( row ) ) {
1097 enableLinear = false;
1098 anItem->text().toDouble(&enableLinear);
1104 LinearAnglesCheck->setChecked( false );
1105 LinearAnglesCheck->setEnabled( enableLinear );
1107 enableLinear = true;
1108 for( int row = 0, nbRows = ScalesList->count(); row < nbRows; row++ ) {
1109 if( QListWidgetItem* anItem = ScalesList->item( row ) ) {
1110 enableLinear = false;
1111 anItem->text().toDouble(&enableLinear);
1117 LinearScalesCheck->setChecked( false );
1118 LinearScalesCheck->setEnabled( enableLinear );
1121 //=================================================================================
1122 // function : isValuesValid()
1123 // purpose : Return true in case if values entered into dialog are valid
1124 //=================================================================================
1126 bool SMESHGUI_ExtrusionAlongPathDlg::isValuesValid()
1128 if ( myPath->_is_nil() )
1132 long aNodeStart = StartPointLineEdit->text().toLong(&bOk);
1133 if ( !bOk || aNodeStart < 1 )
1136 SMESH::SMESH_Mesh_var mesh = myPath->GetMesh();
1137 if ( mesh->_is_nil() )
1140 SMESH::ElementType type = mesh->GetElementType( aNodeStart, false );
1141 if ( type != SMESH::NODE )
1144 if ( mesh->HasShapeToMesh() )
1146 SMESH::NodePosition_var pos = mesh->GetNodePosition( aNodeStart );
1147 if ( pos->shapeType != GEOM::VERTEX )
1152 SMESH::smIdType_array_var elems = mesh->GetNodeInverseElements( aNodeStart, SMESH::ALL );
1153 if ( elems->length() != 1 ||
1154 mesh->GetElementType( elems[0], true ) != SMESH::EDGE )
1160 //=================================================================================
1161 // function : onDisplaySimulation
1162 // purpose : Show/Hide preview
1163 //=================================================================================
1165 void SMESHGUI_ExtrusionAlongPathDlg::onDisplaySimulation( bool toDisplayPreview )
1167 if ( myPreviewCheckBox->isChecked() && toDisplayPreview ) {
1168 if ( SelectorWdg->IsAnythingSelected() && isValid() && isValuesValid())
1170 // get angles and scales
1171 SMESH::double_array_var anAngles = getAngles();
1172 SMESH::double_array_var aScales = getScales();
1175 SMESH::PointStruct aBasePoint;
1176 if (BasePointGrp->isChecked()) {
1177 aBasePoint.x = XSpin->GetValue();
1178 aBasePoint.y = YSpin->GetValue();
1179 aBasePoint.z = ZSpin->GetValue();
1182 long aNodeStart = StartPointLineEdit->text().toLong(&bOk);
1186 SUIT_OverrideCursor wc;
1188 SMESH::SMESH_MeshEditor::Extrusion_Error retVal;
1189 SMESH::SMESH_Mesh_var mesh = SelectorWdg->GetMesh();
1190 SMESH::SMESH_MeshEditor_var meshEditor = mesh->GetMeshEditPreviewer();
1192 SMESH::ListOfIDSources_var nodes = new SMESH::ListOfIDSources();
1193 SMESH::ListOfIDSources_var edges = new SMESH::ListOfIDSources();
1194 SMESH::ListOfIDSources_var faces = new SMESH::ListOfIDSources();
1195 SelectorWdg->GetSelected( nodes, edges, faces );
1196 const bool makeGroups = false;
1198 SMESH::ListOfGroups_var groups =
1199 meshEditor->ExtrusionAlongPathObjects( nodes, edges, faces, myPath,
1200 GEOM::GEOM_Object::_nil(),
1201 aNodeStart, AnglesGrp->isChecked(),
1202 anAngles, LinearAnglesCheck->isChecked(),
1203 BasePointGrp->isChecked(), aBasePoint,
1205 aScales, LinearScalesCheck->isChecked(),
1208 if( retVal == SMESH::SMESH_MeshEditor::EXTR_OK )
1210 SMESH::MeshPreviewStruct_var aMeshPreviewStruct = meshEditor->GetPreviewData();
1211 mySimulation->SetData( aMeshPreviewStruct.in() );
1232 //=======================================================================
1233 //function : getAngles
1234 //purpose : return CORBA array of angles
1235 //=======================================================================
1237 SMESH::double_array_var SMESHGUI_ExtrusionAlongPathDlg::getAngles()
1239 SMESH::double_array_var anAngles = new SMESH::double_array;
1240 if ( AnglesGrp->isChecked() )
1242 anAngles->length( myAnglesList.count() );
1243 for (int i = 0; i < myAnglesList.count(); i++)
1244 anAngles[ i ] = myAnglesList[ i ] * M_PI / 180.;
1249 //=======================================================================
1250 //function : getScales
1251 //purpose : return CORBA array of scale factors
1252 //=======================================================================
1254 SMESH::double_array_var SMESHGUI_ExtrusionAlongPathDlg::getScales()
1256 SMESH::double_array_var anScales = new SMESH::double_array;
1257 if ( ScalesGrp->isChecked() )
1259 anScales->length( myScalesList.count() );
1260 for (int i = 0; i < myScalesList.count(); i++)
1261 anScales[ i ] = myScalesList[ i ];