1 // Copyright (C) 2007-2015 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 // GEOM GEOMGUI : GUI for Geometry component
24 // File : TransformationGUI_ExtensionDlg.cxx
25 // Author : Sergey KHROMOV, Open CASCADE S.A.S.
27 #include "TransformationGUI_ExtensionDlg.h"
29 #include <GeometryGUI.h>
30 #include <GEOMImpl_Types.hxx>
32 #include <SalomeApp_Application.h>
33 #include <SalomeApp_DoubleSpinBox.h>
34 #include <SUIT_ResourceMgr.h>
35 #include <SUIT_Session.h>
36 #include <LightApp_SelectionMgr.h>
38 #include <TColStd_MapOfInteger.hxx>
40 #include <QApplication>
41 #include <QGridLayout>
45 #include <QPushButton>
46 #include <QRadioButton>
49 //=================================================================================
50 // class : TransformationGUI_ExtensionDlg
52 //=================================================================================
53 TransformationGUI_ExtensionDlg::TransformationGUI_ExtensionDlg
54 (GeometryGUI* theGeometryGUI, QWidget* parent,
55 bool modal, Qt::WindowFlags fl)
56 : GEOMBase_Skeleton(theGeometryGUI, parent, modal, fl),
69 QPixmap image0 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
70 QPixmap image1 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_EXTEND_EDGE")));
71 QPixmap image2 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_EXTEND_FACE")));
73 setWindowTitle(tr("GEOM_EXTENSION_TITLE"));
75 /***************************************************************/
76 mainFrame()->GroupConstructors->setTitle(tr ("GEOM_EXTENSION"));
77 mainFrame()->RadioButton1->setIcon(image1);
78 mainFrame()->RadioButton2->setIcon(image2);
79 mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
80 mainFrame()->RadioButton3->close();
82 QGroupBox *aGrp = new QGroupBox(tr("GEOM_ARGUMENTS"));
84 myObjLbl = new QLabel;
85 myUMinLbl = new QLabel;
86 myUMaxLbl = new QLabel;
87 myVMinLbl = new QLabel;
88 myVMaxLbl = new QLabel;
89 mySelButton = new QPushButton;
90 myEditObjName = new QLineEdit;
91 myUMinSpinBox = new SalomeApp_DoubleSpinBox;
92 myUMaxSpinBox = new SalomeApp_DoubleSpinBox;
93 myVMinSpinBox = new SalomeApp_DoubleSpinBox;
94 myVMaxSpinBox = new SalomeApp_DoubleSpinBox;
96 myVMinLbl->setText(tr("GEOM_EXTENSION_MIN_V"));
97 myVMaxLbl->setText(tr("GEOM_EXTENSION_MAX_V"));
98 mySelButton->setIcon(image0);
100 QGridLayout *aGrpLayout = new QGridLayout(aGrp);
102 aGrpLayout->setMargin(9);
103 aGrpLayout->setSpacing(6);
104 aGrpLayout->addWidget(myObjLbl, 0, 0);
105 aGrpLayout->addWidget(myUMinLbl, 1, 0);
106 aGrpLayout->addWidget(myUMaxLbl, 2, 0);
107 aGrpLayout->addWidget(myVMinLbl, 3, 0);
108 aGrpLayout->addWidget(myVMaxLbl, 4, 0);
109 aGrpLayout->addWidget(mySelButton, 0, 1);
110 aGrpLayout->addWidget(myEditObjName, 0, 2);
111 aGrpLayout->addWidget(myUMinSpinBox, 1, 1, 1, 2);
112 aGrpLayout->addWidget(myUMaxSpinBox, 2, 1, 1, 2);
113 aGrpLayout->addWidget(myVMinSpinBox, 3, 1, 1, 2);
114 aGrpLayout->addWidget(myVMaxSpinBox, 4, 1, 1, 2);
118 myVMinSpinBox->hide();
119 myVMaxSpinBox->hide();
121 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
122 layout->setMargin(0); layout->setSpacing(6);
123 layout->addWidget(aGrp);
124 /***************************************************************/
126 setHelpFileName("extension_operation_page.html");
128 /* Initialisations */
132 //=================================================================================
133 // function : ~GenerationGUI_FillingDlg()
134 // purpose : Destroys the object and frees any allocated resources
135 //=================================================================================
136 TransformationGUI_ExtensionDlg::~TransformationGUI_ExtensionDlg()
138 // no need to delete child widgets, Qt does it all for us
141 //=================================================================================
144 //=================================================================================
145 void TransformationGUI_ExtensionDlg::Init()
148 showOnlyPreviewControl();
149 myEditCurrentArgument = myEditObjName;
152 /* min, max, step and decimals for spin boxes & initial values */
153 initSpinBox(myUMinSpinBox, -MAX_NUMBER, MAX_NUMBER, aStep, "parametric_precision");
154 initSpinBox(myUMaxSpinBox, -MAX_NUMBER, MAX_NUMBER, aStep, "parametric_precision");
155 initSpinBox(myVMinSpinBox, -MAX_NUMBER, MAX_NUMBER, aStep, "parametric_precision");
156 initSpinBox(myVMaxSpinBox, -MAX_NUMBER, MAX_NUMBER, aStep, "parametric_precision");
158 myUMinSpinBox->setValue(0.);
159 myUMaxSpinBox->setValue(1.);
160 myVMinSpinBox->setValue(0.);
161 myVMaxSpinBox->setValue(1.);
163 /* signals and slots connections */
164 connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
165 connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
167 connect(this, SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
169 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
170 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
171 connect(mySelButton, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
173 connect(myUMinSpinBox, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
174 connect(myUMaxSpinBox, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
175 connect(myVMinSpinBox, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
176 connect(myVMaxSpinBox, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
178 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), this, SLOT(SetDoubleSpinBoxStep(double)));
180 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
181 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
183 initName(tr("GEOM_EXTENSION_EDGE_NAME"));
186 ConstructorsClicked(0);
189 //=================================================================================
190 // function : SetDoubleSpinBoxStep()
191 // purpose : Double spin box management
192 //=================================================================================
193 void TransformationGUI_ExtensionDlg::SetDoubleSpinBoxStep(double step)
195 myUMinSpinBox->setSingleStep(step);
196 myUMaxSpinBox->setSingleStep(step);
197 myVMinSpinBox->setSingleStep(step);
198 myVMaxSpinBox->setSingleStep(step);
201 //=================================================================================
202 // function : ConstructorsClicked()
203 // purpose : Radio button management
204 //=================================================================================
205 void TransformationGUI_ExtensionDlg::ConstructorsClicked (int constructorId)
207 switch (constructorId) {
208 case 0: // Extend edge
210 TColStd_MapOfInteger aMap;
213 globalSelection(aMap);
215 myObjLbl->setText(tr("GEOM_EDGE"));
216 myUMinLbl->setText(tr("GEOM_EXTENSION_MIN"));
217 myUMaxLbl->setText(tr("GEOM_EXTENSION_MAX"));
220 myVMinSpinBox->hide();
221 myVMaxSpinBox->hide();
223 initName(tr("GEOM_EXTENSION_EDGE_NAME"));
227 case 1: // Extend face
229 TColStd_MapOfInteger aMap;
232 globalSelection(aMap);
234 myObjLbl->setText(tr("GEOM_FACE"));
235 myUMinLbl->setText(tr("GEOM_EXTENSION_MIN_U"));
236 myUMaxLbl->setText(tr("GEOM_EXTENSION_MAX_U"));
239 myVMinSpinBox->show();
240 myVMaxSpinBox->show();
242 initName(tr("GEOM_EXTENSION_FACE_NAME"));
251 qApp->processEvents();
253 resize(minimumSizeHint());
255 SelectionIntoArgument();
258 //=================================================================================
259 // function : ClickOnOk()
261 //=================================================================================
262 void TransformationGUI_ExtensionDlg::ClickOnOk()
264 setIsApplyAndClose(true);
269 //=================================================================================
270 // function : ClickOnApply()
272 //=================================================================================
273 bool TransformationGUI_ExtensionDlg::ClickOnApply()
283 //=================================================================================
284 // function : SelectionIntoArgument()
285 // purpose : Called when selection as changed or other case
286 //=================================================================================
287 void TransformationGUI_ExtensionDlg::SelectionIntoArgument()
290 myEditCurrentArgument->setText("");
292 if (myEditCurrentArgument == myEditObjName) {
293 const TopAbs_ShapeEnum aType =
294 getConstructorId() == 0 ? TopAbs_EDGE: TopAbs_FACE;
295 GEOM::GeomObjPtr aSelectedObject = getSelected(aType);
297 if (aSelectedObject) {
298 myEditCurrentArgument->setText(GEOMBase::GetName(aSelectedObject.get()));
299 myBase = aSelectedObject;
308 //=================================================================================
309 // function : SetEditCurrentArgument()
311 //=================================================================================
312 void TransformationGUI_ExtensionDlg::SetEditCurrentArgument()
314 QPushButton* send = (QPushButton*)sender();
316 if (send == mySelButton) {
317 myEditObjName->setFocus();
318 myEditCurrentArgument = myEditObjName;
319 SelectionIntoArgument();
323 //=================================================================================
324 // function : ActivateThisDialog()
326 //=================================================================================
327 void TransformationGUI_ExtensionDlg::ActivateThisDialog()
329 GEOMBase_Skeleton::ActivateThisDialog();
330 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
331 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
333 ConstructorsClicked(getConstructorId());
336 //=================================================================================
337 // function : enterEvent()
339 //=================================================================================
340 void TransformationGUI_ExtensionDlg::enterEvent(QEvent*)
342 if (!mainFrame()->GroupConstructors->isEnabled())
343 ActivateThisDialog();
346 //=================================================================================
347 // function : ValueChangedInSpinBox()
349 //=================================================================================
350 void TransformationGUI_ExtensionDlg::ValueChangedInSpinBox(double newValue)
355 //=================================================================================
356 // function : createOperation
358 //=================================================================================
359 GEOM::GEOM_IOperations_ptr TransformationGUI_ExtensionDlg::createOperation()
361 return getGeomEngine()->GetIShapesOperations(getStudyId());
364 //=================================================================================
365 // function : isValid
367 //=================================================================================
368 bool TransformationGUI_ExtensionDlg::isValid(QString& msg)
370 bool ok = (myUMinSpinBox->isValid(msg, !IsPreview()) &&
371 myUMaxSpinBox->isValid(msg, !IsPreview()) &&
372 myVMinSpinBox->isValid(msg, !IsPreview()) &&
373 myVMaxSpinBox->isValid(msg, !IsPreview()) &&
378 //=================================================================================
379 // function : execute
381 //=================================================================================
382 bool TransformationGUI_ExtensionDlg::execute(ObjectList& objects)
385 GEOM::GEOM_IShapesOperations_var anOper =
386 GEOM::GEOM_IShapesOperations::_narrow(getOperation());
387 GEOM::GEOM_Object_var anObj;
389 switch (getConstructorId()) {
391 anObj = anOper->ExtendEdge(myBase.get(), myUMinSpinBox->value(),
392 myUMaxSpinBox->value());
396 anObj = anOper->ExtendFace(myBase.get(), myUMinSpinBox->value(),
397 myUMaxSpinBox->value(),
398 myVMinSpinBox->value(),
399 myVMaxSpinBox->value());
406 if (!anObj->_is_nil()) {
407 objects.push_back(anObj._retn());