1 // Copyright (C) 2007-2014 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_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),
65 SUIT_ResourceMgr* aResMgr = myGeomGUI->getApp()->resourceMgr();
66 QPixmap image0 (aResMgr->loadPixmap("GEOM", tr("ICO_DLG_PROJ_ON_CYL")));
67 QPixmap image1 (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
69 setWindowTitle(tr("GEOM_PROJ_ON_CYL_TITLE"));
71 /***************************************************************/
72 mainFrame()->GroupConstructors->setTitle(tr("GEOM_PROJECTION_TITLE"));
73 mainFrame()->RadioButton1->setIcon(image0);
74 mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose);
75 mainFrame()->RadioButton2->close();
76 mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
77 mainFrame()->RadioButton3->close();
79 QGroupBox *aGrpParams =
80 new QGroupBox(tr("GEOM_ARGUMENTS"), centralWidget());
81 QGridLayout *aParamsLayout = new QGridLayout(aGrpParams);
82 QLabel *anObjLbl = new QLabel(tr("GEOM_OBJECT"), aGrpParams);
83 QLabel *aRadiusLbl = new QLabel(tr("GEOM_RADIUS"), aGrpParams);
84 QLabel *aStartAngleLbl =
85 new QLabel(tr("GEOM_PROJ_ON_CYL_START_ANGLE"), aGrpParams);
86 QLabel *anAngleLenLbl =
87 new QLabel(tr("GEOM_PROJ_ON_CYL_LENGTH_ANGLE"), aGrpParams);
89 myObjectName = new QLineEdit(aGrpParams);
90 mySelButton = new QPushButton(aGrpParams);
91 myRadiusSpin = new SalomeApp_DoubleSpinBox(aGrpParams);
92 myStartAngleSpin = new SalomeApp_DoubleSpinBox(aGrpParams);
93 myUseAngleLen = new QCheckBox(aGrpParams);
94 myAngleLenSpin = new SalomeApp_DoubleSpinBox(aGrpParams);
96 myObjectName->setReadOnly(true);
97 mySelButton->setIcon(image1);
98 mySelButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
99 myUseAngleLen->setChecked(false);
101 aParamsLayout->setMargin(9);
102 aParamsLayout->setSpacing(6);
103 aParamsLayout->addWidget(anObjLbl, 0, 1);
104 aParamsLayout->addWidget(mySelButton, 0, 2);
105 aParamsLayout->addWidget(myObjectName, 0, 3);
106 aParamsLayout->addWidget(aRadiusLbl, 1, 1);
107 aParamsLayout->addWidget(myRadiusSpin, 1, 2, 1, 2);
108 aParamsLayout->addWidget(aStartAngleLbl, 2, 1);
109 aParamsLayout->addWidget(myStartAngleSpin, 2, 2, 1, 2);
110 aParamsLayout->addWidget(myUseAngleLen, 3, 0);
111 aParamsLayout->addWidget(anAngleLenLbl, 3, 1);
112 aParamsLayout->addWidget(myAngleLenSpin, 3, 2, 1, 2);
114 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
115 layout->setMargin( 0 ); layout->setSpacing( 6 );
116 layout->addWidget( aGrpParams );
118 /***************************************************************/
120 setHelpFileName("projection_on_cylinder_operation_page.html");
125 //=================================================================================
126 // function : ~TransformationGUI_ProjectionOnCylDlg()
127 // purpose : Destroys the object and frees any allocated resources
128 //=================================================================================
129 TransformationGUI_ProjectionOnCylDlg::~TransformationGUI_ProjectionOnCylDlg()
131 // no need to delete child widgets, Qt does it all for us
134 //=================================================================================
137 //=================================================================================
138 void TransformationGUI_ProjectionOnCylDlg::Init()
140 showOnlyPreviewControl();
142 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
143 double aStep = resMgr->doubleValue("Geometry", "SettingsGeomStep", 100);
144 double aSpecificStep = 5;
145 double aRadius = 100.0;
146 double aStartAngle = 0.;
147 double anAngleLen = 360.;
149 initSpinBox(myRadiusSpin, 0.00001, COORD_MAX, aStep, "length_precision");
150 initSpinBox(myStartAngleSpin, -180., 180., aSpecificStep, "angle_precision");
151 initSpinBox(myAngleLenSpin, 0.00001, COORD_MAX, aSpecificStep, "angle_precision");
153 myRadiusSpin->setValue(aRadius);
154 myStartAngleSpin->setValue(aStartAngle);
155 myAngleLenSpin->setValue(anAngleLen);
157 myObjectName->setText("");
158 myUseAngleLen->setChecked(true);
160 // signals and slots connections
161 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
162 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
164 connect(mySelButton, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
165 connect(myRadiusSpin, SIGNAL(valueChanged(double)), this, SLOT(processPreview()));
166 connect(myStartAngleSpin, SIGNAL(valueChanged(double)), this, SLOT(processPreview()));
167 connect(myAngleLenSpin, SIGNAL(valueChanged(double)), this, SLOT(processPreview()));
168 connect(myUseAngleLen, SIGNAL(clicked()), this, SLOT(SetUseLengthAngle()));
170 connect(myGeomGUI->getApp()->selectionMgr(),SIGNAL(currentSelectionChanged()),
171 this, SLOT(SelectionIntoArgument()));
173 initName(tr("GEOM_PROJECTION_NAME"));
175 buttonOk()->setEnabled(false);
176 buttonApply()->setEnabled(false);
179 SelectionIntoArgument();
182 //=================================================================================
183 // function : ClickOnOk()
185 //=================================================================================
186 void TransformationGUI_ProjectionOnCylDlg::ClickOnOk()
188 setIsApplyAndClose( true );
193 //=================================================================================
194 // function : ClickOnApply()
196 //=================================================================================
197 bool TransformationGUI_ProjectionOnCylDlg::ClickOnApply()
206 //=================================================================================
207 // function : SelectionIntoArgument()
208 // purpose : Called when selection is changed or on dialog initialization or activation
209 //=================================================================================
210 void TransformationGUI_ProjectionOnCylDlg::SelectionIntoArgument()
213 myObj = GEOM::GEOM_Object::_nil();
215 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
216 SALOME_ListIO aSelList;
217 aSelMgr->selectedObjects(aSelList);
219 if (aSelList.Extent() == 1) {
220 // Single object is selected.
221 GEOM::GEOM_Object_var aSelectedObject =
222 GEOMBase::ConvertIOinGEOMObject( aSelList.First() );
224 if (aSelectedObject->_is_nil()) {
226 myObjectName->setText("");
227 buttonOk()->setEnabled(false);
228 buttonApply()->setEnabled(false);
231 myObj = aSelectedObject;
232 myObjectName->setText(GEOMBase::GetName(myObj));
233 buttonOk()->setEnabled(true);
234 buttonApply()->setEnabled(true);
237 // Not a single object is selected.
238 myObjectName->setText("");
239 buttonOk()->setEnabled(false);
240 buttonApply()->setEnabled(false);
246 //=================================================================================
247 // function : SetEditCurrentArgument()
249 //=================================================================================
250 void TransformationGUI_ProjectionOnCylDlg::SetEditCurrentArgument()
252 myObjectName->setFocus();
253 myEditCurrentArgument = myObjectName;
254 SelectionIntoArgument();
257 //=================================================================================
258 // function : SetUseLengthAngle()
260 //=================================================================================
261 void TransformationGUI_ProjectionOnCylDlg::SetUseLengthAngle()
263 myAngleLenSpin->setEnabled(myUseAngleLen->isChecked());
267 //=================================================================================
268 // function : activateSelection
269 // purpose : activate selection of wires or faces
270 //=================================================================================
271 void TransformationGUI_ProjectionOnCylDlg::activateSelection()
273 TColStd_MapOfInteger aMap;
277 globalSelection(aMap);
280 //=================================================================================
281 // function : ActivateThisDialog()
283 //=================================================================================
284 void TransformationGUI_ProjectionOnCylDlg::ActivateThisDialog()
286 GEOMBase_Skeleton::ActivateThisDialog();
287 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
288 this, SLOT( SelectionIntoArgument() ) );
293 //=================================================================================
294 // function : enterEvent()
296 //=================================================================================
297 void TransformationGUI_ProjectionOnCylDlg::enterEvent (QEvent*)
299 if (!mainFrame()->GroupConstructors->isEnabled())
300 ActivateThisDialog();
303 //=================================================================================
304 // function : createOperation
306 //=================================================================================
307 GEOM::GEOM_IOperations_ptr TransformationGUI_ProjectionOnCylDlg::createOperation()
309 return getGeomEngine()->GetITransformOperations(getStudyId());
312 //=================================================================================
313 // function : isValid
315 //=================================================================================
316 bool TransformationGUI_ProjectionOnCylDlg::isValid (QString &msg)
320 if (!myObj->_is_nil() &&
321 myRadiusSpin->isValid(msg, !IsPreview()) &&
322 myStartAngleSpin->isValid(msg, !IsPreview())) {
323 if (myUseAngleLen->isChecked()) {
324 // Check length angle spin.
325 isOk = myAngleLenSpin->isValid(msg, !IsPreview());
327 // Don't check length angle spin.
335 //=================================================================================
336 // function : execute
338 //=================================================================================
339 bool TransformationGUI_ProjectionOnCylDlg::execute (ObjectList& objects)
341 GEOM::GEOM_ITransformOperations_var anOper =
342 GEOM::GEOM_ITransformOperations::_narrow(getOperation());
344 double aRadius = myRadiusSpin->value();
345 double aStartAngle = myStartAngleSpin->value()*M_PI/180.;
346 double aLengthAngle = -1.;
348 if (myUseAngleLen->isChecked()) {
349 aLengthAngle = myAngleLenSpin->value()*M_PI/180.;
352 GEOM::GEOM_Object_var anObj = anOper->MakeProjectionOnCylinder
353 (myObj, aRadius, aStartAngle, aLengthAngle);
355 if (!anObj->_is_nil()) {
357 QStringList aParameters;
358 aParameters << myRadiusSpin->text();
359 aParameters << myStartAngleSpin->text();
360 if (myUseAngleLen->isChecked())
361 aParameters << myAngleLenSpin->text();
362 anObj->SetParameters(aParameters.join(":").toUtf8().constData());
364 objects.push_back(anObj._retn());