1 // Copyright (C) 2007-2024 CEA, EDF, 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_ProjectionOnCylDlg.cxx
25 // Author : Sergey KHROMOV, Open CASCADE S.A.S.
27 #include "TransformationGUI_ProjectionOnCylDlg.h"
29 #include <GeometryGUI.h>
31 #include <GEOMImpl_Types.hxx>
33 #include <SUIT_Session.h>
34 #include <SUIT_ResourceMgr.h>
35 #include <SalomeApp_Application.h>
36 #include <SalomeApp_DoubleSpinBox.h>
37 #include <LightApp_SelectionMgr.h>
40 #include <QGridLayout>
43 #include <QPushButton>
44 #include <QRadioButton>
46 #include <TColStd_MapOfInteger.hxx>
48 //=================================================================================
49 // class : TransformationGUI_ProjectionOnCylDlg()
50 // purpose : Constructs a TransformationGUI_ProjectionOnCylDlg which is
51 // a child of 'parent', with the name 'name' and widget flags set to
52 // 'f'. The dialog will by default be modeless, unless you set
53 // 'modal' to TRUE to construct a modal dialog.
54 //=================================================================================
55 TransformationGUI_ProjectionOnCylDlg::TransformationGUI_ProjectionOnCylDlg
56 (GeometryGUI* theGeometryGUI, QWidget* parent, bool modal, Qt::WindowFlags fl)
57 : GEOMBase_Skeleton (theGeometryGUI, parent, modal, fl),
66 SUIT_ResourceMgr* aResMgr = myGeomGUI->getApp()->resourceMgr();
67 QPixmap image0 (aResMgr->loadPixmap("GEOM", tr("ICO_DLG_PROJ_ON_CYL")));
68 QPixmap image1 (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
70 setWindowTitle(tr("GEOM_PROJ_ON_CYL_TITLE"));
72 /***************************************************************/
73 mainFrame()->GroupConstructors->setTitle(tr("GEOM_PROJECTION_TITLE"));
74 mainFrame()->RadioButton1->setIcon(image0);
75 mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose);
76 mainFrame()->RadioButton2->close();
77 mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
78 mainFrame()->RadioButton3->close();
80 QGroupBox *aGrpParams =
81 new QGroupBox(tr("GEOM_ARGUMENTS"), centralWidget());
82 QGridLayout *aParamsLayout = new QGridLayout(aGrpParams);
83 QLabel *anObjLbl = new QLabel(tr("GEOM_OBJECT"), aGrpParams);
84 QLabel *aRadiusLbl = new QLabel(tr("GEOM_RADIUS"), aGrpParams);
85 QLabel *aStartAngleLbl =
86 new QLabel(tr("GEOM_PROJ_ON_CYL_START_ANGLE"), aGrpParams);
87 QLabel *anAngleLenLbl =
88 new QLabel(tr("GEOM_PROJ_ON_CYL_LENGTH_ANGLE"), aGrpParams);
89 QLabel *anAngleRotLbl =
90 new QLabel(tr("GEOM_PROJ_ON_CYL_ROTATION_ANGLE"), aGrpParams);
92 myObjectName = new QLineEdit(aGrpParams);
93 mySelButton = new QPushButton(aGrpParams);
94 myRadiusSpin = new SalomeApp_DoubleSpinBox(aGrpParams);
95 myStartAngleSpin = new SalomeApp_DoubleSpinBox(aGrpParams);
96 myUseAngleLen = new QCheckBox(aGrpParams);
97 myAngleLenSpin = new SalomeApp_DoubleSpinBox(aGrpParams);
98 myAngleRotSpin = new SalomeApp_DoubleSpinBox(aGrpParams);
100 myObjectName->setReadOnly(true);
101 mySelButton->setIcon(image1);
102 mySelButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
103 myUseAngleLen->setChecked(false);
105 aParamsLayout->setMargin(9);
106 aParamsLayout->setSpacing(6);
107 aParamsLayout->addWidget(anObjLbl, 0, 1);
108 aParamsLayout->addWidget(mySelButton, 0, 2);
109 aParamsLayout->addWidget(myObjectName, 0, 3);
110 aParamsLayout->addWidget(aRadiusLbl, 1, 1);
111 aParamsLayout->addWidget(myRadiusSpin, 1, 2, 1, 2);
112 aParamsLayout->addWidget(aStartAngleLbl, 2, 1);
113 aParamsLayout->addWidget(myStartAngleSpin, 2, 2, 1, 2);
114 aParamsLayout->addWidget(myUseAngleLen, 3, 0);
115 aParamsLayout->addWidget(anAngleLenLbl, 3, 1);
116 aParamsLayout->addWidget(myAngleLenSpin, 3, 2, 1, 2);
117 aParamsLayout->addWidget(anAngleRotLbl, 4, 1);
118 aParamsLayout->addWidget(myAngleRotSpin, 4, 2, 1, 2);
120 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
121 layout->setMargin( 0 ); layout->setSpacing( 6 );
122 layout->addWidget( aGrpParams );
124 /***************************************************************/
126 setHelpFileName("projection_on_cylinder_operation_page.html");
131 //=================================================================================
132 // function : ~TransformationGUI_ProjectionOnCylDlg()
133 // purpose : Destroys the object and frees any allocated resources
134 //=================================================================================
135 TransformationGUI_ProjectionOnCylDlg::~TransformationGUI_ProjectionOnCylDlg()
137 // no need to delete child widgets, Qt does it all for us
140 //=================================================================================
143 //=================================================================================
144 void TransformationGUI_ProjectionOnCylDlg::Init()
146 showOnlyPreviewControl();
148 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
149 double aStep = resMgr->doubleValue("Geometry", "SettingsGeomStep", 100);
150 double aSpecificStep = 5;
151 double aRadius = 100.0;
152 double aStartAngle = 0.;
153 double anAngleLen = 360.;
154 double aRotAngle = 0.;
156 initSpinBox(myRadiusSpin, 0.00001, COORD_MAX, aStep, "length_precision");
157 initSpinBox(myStartAngleSpin, -180., 180., aSpecificStep, "angle_precision");
158 initSpinBox(myAngleLenSpin, 0.00001, COORD_MAX, aSpecificStep, "angle_precision");
159 initSpinBox(myAngleRotSpin, -180., 180., aSpecificStep, "angle_precision");
161 myRadiusSpin->setValue(aRadius);
162 myStartAngleSpin->setValue(aStartAngle);
163 myAngleLenSpin->setValue(anAngleLen);
164 myAngleRotSpin->setValue(aRotAngle);
166 myObjectName->setText("");
167 myUseAngleLen->setChecked(true);
169 // signals and slots connections
170 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
171 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
173 connect(mySelButton, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
174 connect(myRadiusSpin, SIGNAL(valueChanged(double)), this, SLOT(processPreview()));
175 connect(myStartAngleSpin, SIGNAL(valueChanged(double)), this, SLOT(processPreview()));
176 connect(myAngleLenSpin, SIGNAL(valueChanged(double)), this, SLOT(processPreview()));
177 connect(myAngleRotSpin, SIGNAL(valueChanged(double)), this, SLOT(processPreview()));
178 connect(myUseAngleLen, SIGNAL(clicked()), this, SLOT(SetUseLengthAngle()));
180 connect(myGeomGUI->getApp()->selectionMgr(),SIGNAL(currentSelectionChanged()),
181 this, SLOT(SelectionIntoArgument()));
183 initName(tr("GEOM_PROJECTION_NAME"));
185 buttonOk()->setEnabled(false);
186 buttonApply()->setEnabled(false);
189 SelectionIntoArgument();
192 //=================================================================================
193 // function : ClickOnOk()
195 //=================================================================================
196 void TransformationGUI_ProjectionOnCylDlg::ClickOnOk()
198 setIsApplyAndClose( true );
203 //=================================================================================
204 // function : ClickOnApply()
206 //=================================================================================
207 bool TransformationGUI_ProjectionOnCylDlg::ClickOnApply()
216 //=================================================================================
217 // function : SelectionIntoArgument()
218 // purpose : Called when selection is changed or on dialog initialization or activation
219 //=================================================================================
220 void TransformationGUI_ProjectionOnCylDlg::SelectionIntoArgument()
223 myObj = GEOM::GEOM_Object::_nil();
225 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
226 SALOME_ListIO aSelList;
227 aSelMgr->selectedObjects(aSelList);
229 if (aSelList.Extent() == 1) {
230 // Single object is selected.
231 GEOM::GEOM_Object_var aSelectedObject =
232 GEOMBase::ConvertIOinGEOMObject( aSelList.First() );
234 if (aSelectedObject->_is_nil()) {
236 myObjectName->setText("");
237 buttonOk()->setEnabled(false);
238 buttonApply()->setEnabled(false);
241 myObj = aSelectedObject;
242 myObjectName->setText(GEOMBase::GetName(myObj));
243 buttonOk()->setEnabled(true);
244 buttonApply()->setEnabled(true);
247 // Not a single object is selected.
248 myObjectName->setText("");
249 buttonOk()->setEnabled(false);
250 buttonApply()->setEnabled(false);
256 //=================================================================================
257 // function : SetEditCurrentArgument()
259 //=================================================================================
260 void TransformationGUI_ProjectionOnCylDlg::SetEditCurrentArgument()
262 myObjectName->setFocus();
263 myEditCurrentArgument = myObjectName;
264 SelectionIntoArgument();
267 //=================================================================================
268 // function : SetUseLengthAngle()
270 //=================================================================================
271 void TransformationGUI_ProjectionOnCylDlg::SetUseLengthAngle()
273 myAngleLenSpin->setEnabled(myUseAngleLen->isChecked());
277 //=================================================================================
278 // function : activateSelection
279 // purpose : activate selection of wires or faces
280 //=================================================================================
281 void TransformationGUI_ProjectionOnCylDlg::activateSelection()
283 TColStd_MapOfInteger aMap;
287 globalSelection(aMap);
290 //=================================================================================
291 // function : ActivateThisDialog()
293 //=================================================================================
294 void TransformationGUI_ProjectionOnCylDlg::ActivateThisDialog()
296 GEOMBase_Skeleton::ActivateThisDialog();
297 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
298 this, SLOT( SelectionIntoArgument() ) );
303 //=================================================================================
304 // function : enterEvent()
306 //=================================================================================
307 void TransformationGUI_ProjectionOnCylDlg::enterEvent (QEvent*)
309 if (!mainFrame()->GroupConstructors->isEnabled())
310 ActivateThisDialog();
313 //=================================================================================
314 // function : createOperation
316 //=================================================================================
317 GEOM::GEOM_IOperations_ptr TransformationGUI_ProjectionOnCylDlg::createOperation()
319 return getGeomEngine()->GetITransformOperations();
322 //=================================================================================
323 // function : isValid
325 //=================================================================================
326 bool TransformationGUI_ProjectionOnCylDlg::isValid (QString &msg)
330 if (!myObj->_is_nil() &&
331 myRadiusSpin->isValid(msg, !IsPreview()) &&
332 myStartAngleSpin->isValid(msg, !IsPreview()) &&
333 myAngleRotSpin->isValid(msg, !IsPreview())) {
334 if (myUseAngleLen->isChecked()) {
335 // Check length angle spin.
336 isOk = myAngleLenSpin->isValid(msg, !IsPreview());
338 // Don't check length angle spin.
346 //=================================================================================
347 // function : execute
349 //=================================================================================
350 bool TransformationGUI_ProjectionOnCylDlg::execute (ObjectList& objects)
352 GEOM::GEOM_ITransformOperations_var anOper =
353 GEOM::GEOM_ITransformOperations::_narrow(getOperation());
355 double aRadius = myRadiusSpin->value();
356 double aStartAngle = myStartAngleSpin->value()*M_PI/180.;
357 double aRotAngle = myAngleRotSpin->value()*M_PI/180.;
358 double aLengthAngle = -1.;
360 if (myUseAngleLen->isChecked()) {
361 aLengthAngle = myAngleLenSpin->value()*M_PI/180.;
364 GEOM::GEOM_Object_var anObj = anOper->MakeProjectionOnCylinder
365 (myObj, aRadius, aStartAngle, aLengthAngle, aRotAngle);
367 if (!anObj->_is_nil()) {
369 QStringList aParameters;
370 aParameters << myRadiusSpin->text();
371 aParameters << myStartAngleSpin->text();
372 if (myUseAngleLen->isChecked())
373 aParameters << myAngleLenSpin->text();
374 aParameters << myAngleRotSpin->text();
375 anObj->SetParameters(aParameters.join(":").toUtf8().constData());
377 objects.push_back(anObj._retn());