Salome HOME
c0e015ded56db194a0dba192c8f973b4e0988dd0
[modules/geom.git] / src / TransformationGUI / TransformationGUI_ProjectionOnCylDlg.cxx
1 // Copyright (C) 2007-2023  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File   : TransformationGUI_ProjectionOnCylDlg.cxx
25 // Author : Sergey KHROMOV, Open CASCADE S.A.S.
26
27 #include "TransformationGUI_ProjectionOnCylDlg.h"
28
29 #include <GeometryGUI.h>
30 #include <GEOMBase.h>
31 #include <GEOMImpl_Types.hxx>
32
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>
38
39 #include <QCheckBox>
40 #include <QGridLayout>
41 #include <QGroupBox>
42 #include <QLineEdit>
43 #include <QPushButton>
44 #include <QRadioButton>
45
46 #include <TColStd_MapOfInteger.hxx>
47
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),
58     myObjectName      (0),
59     mySelButton       (0),
60     myRadiusSpin      (0),
61     myStartAngleSpin  (0),
62     myUseAngleLen     (0),
63     myAngleLenSpin    (0),
64     myAngleRotSpin    (0)
65 {
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")));
69
70   setWindowTitle(tr("GEOM_PROJ_ON_CYL_TITLE"));
71
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();
79
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);
91
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);
99
100   myObjectName->setReadOnly(true);
101   mySelButton->setIcon(image1);
102   mySelButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
103   myUseAngleLen->setChecked(false);
104
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);
119
120   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
121   layout->setMargin( 0 ); layout->setSpacing( 6 );
122   layout->addWidget( aGrpParams );
123
124   /***************************************************************/
125
126   setHelpFileName("projection_on_cylinder_operation_page.html");
127
128   Init();
129 }
130
131 //=================================================================================
132 // function : ~TransformationGUI_ProjectionOnCylDlg()
133 // purpose  : Destroys the object and frees any allocated resources
134 //=================================================================================
135 TransformationGUI_ProjectionOnCylDlg::~TransformationGUI_ProjectionOnCylDlg()
136 {
137   // no need to delete child widgets, Qt does it all for us
138 }
139
140 //=================================================================================
141 // function : Init()
142 // purpose  :
143 //=================================================================================
144 void TransformationGUI_ProjectionOnCylDlg::Init()
145 {
146   showOnlyPreviewControl();
147
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.;
155
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");
160
161   myRadiusSpin->setValue(aRadius);
162   myStartAngleSpin->setValue(aStartAngle);
163   myAngleLenSpin->setValue(anAngleLen);
164   myAngleRotSpin->setValue(aRotAngle);
165
166   myObjectName->setText("");
167   myUseAngleLen->setChecked(true);
168
169   // signals and slots connections
170   connect(buttonOk(),    SIGNAL(clicked()), this, SLOT(ClickOnOk()));
171   connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
172
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()));
179
180   connect(myGeomGUI->getApp()->selectionMgr(),SIGNAL(currentSelectionChanged()),
181           this, SLOT(SelectionIntoArgument()));
182
183   initName(tr("GEOM_PROJECTION_NAME"));
184
185   buttonOk()->setEnabled(false);
186   buttonApply()->setEnabled(false);
187
188   activateSelection();
189   SelectionIntoArgument();
190 }
191
192 //=================================================================================
193 // function : ClickOnOk()
194 // purpose  :
195 //=================================================================================
196 void TransformationGUI_ProjectionOnCylDlg::ClickOnOk()
197 {
198   setIsApplyAndClose( true );
199   if (ClickOnApply())
200     ClickOnCancel();
201 }
202
203 //=================================================================================
204 // function : ClickOnApply()
205 // purpose  :
206 //=================================================================================
207 bool TransformationGUI_ProjectionOnCylDlg::ClickOnApply()
208 {
209   if ( !onAccept() )
210     return false;
211
212   initName();
213   return true;
214 }
215
216 //=================================================================================
217 // function : SelectionIntoArgument()
218 // purpose  : Called when selection is changed or on dialog initialization or activation
219 //=================================================================================
220 void TransformationGUI_ProjectionOnCylDlg::SelectionIntoArgument()
221 {
222   erasePreview();
223   myObj = GEOM::GEOM_Object::_nil();
224
225   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
226   SALOME_ListIO aSelList;
227   aSelMgr->selectedObjects(aSelList);
228
229   if (aSelList.Extent() == 1) {
230     // Single object is selected.
231     GEOM::GEOM_Object_var aSelectedObject =
232       GEOMBase::ConvertIOinGEOMObject( aSelList.First() );
233
234     if (aSelectedObject->_is_nil()) {
235       // Null object.
236       myObjectName->setText("");
237       buttonOk()->setEnabled(false);
238       buttonApply()->setEnabled(false);
239     } else {
240       // Not Null object.
241       myObj = aSelectedObject;
242       myObjectName->setText(GEOMBase::GetName(myObj));
243       buttonOk()->setEnabled(true);
244       buttonApply()->setEnabled(true);
245     }
246   } else {
247     // Not a single object is selected.
248     myObjectName->setText("");
249     buttonOk()->setEnabled(false);
250     buttonApply()->setEnabled(false);
251   }
252
253   processPreview();
254 }
255
256 //=================================================================================
257 // function : SetEditCurrentArgument()
258 // purpose  :
259 //=================================================================================
260 void TransformationGUI_ProjectionOnCylDlg::SetEditCurrentArgument()
261 {
262   myObjectName->setFocus();
263   myEditCurrentArgument = myObjectName;
264   SelectionIntoArgument();
265 }
266
267 //=================================================================================
268 // function : SetUseLengthAngle()
269 // purpose  :
270 //=================================================================================
271 void TransformationGUI_ProjectionOnCylDlg::SetUseLengthAngle()
272 {
273   myAngleLenSpin->setEnabled(myUseAngleLen->isChecked());
274   processPreview();
275 }
276
277 //=================================================================================
278 // function : activateSelection
279 // purpose  : activate selection of wires or faces
280 //=================================================================================
281 void TransformationGUI_ProjectionOnCylDlg::activateSelection()
282 {
283   TColStd_MapOfInteger aMap;
284
285   aMap.Add(GEOM_WIRE);
286   aMap.Add(GEOM_FACE);
287   globalSelection(aMap);
288 }
289
290 //=================================================================================
291 // function : ActivateThisDialog()
292 // purpose  :
293 //=================================================================================
294 void TransformationGUI_ProjectionOnCylDlg::ActivateThisDialog()
295 {
296   GEOMBase_Skeleton::ActivateThisDialog();
297   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
298            this, SLOT( SelectionIntoArgument() ) );
299
300   activateSelection();
301 }
302
303 //=================================================================================
304 // function : enterEvent()
305 // purpose  :
306 //=================================================================================
307 void TransformationGUI_ProjectionOnCylDlg::enterEvent (QEvent*)
308 {
309   if (!mainFrame()->GroupConstructors->isEnabled())
310     ActivateThisDialog();
311 }
312
313 //=================================================================================
314 // function : createOperation
315 // purpose  :
316 //=================================================================================
317 GEOM::GEOM_IOperations_ptr TransformationGUI_ProjectionOnCylDlg::createOperation()
318 {
319   return getGeomEngine()->GetITransformOperations();
320 }
321
322 //=================================================================================
323 // function : isValid
324 // purpose  :
325 //=================================================================================
326 bool TransformationGUI_ProjectionOnCylDlg::isValid (QString &msg)
327 {
328   bool isOk = false;
329
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());
337     } else {
338       // Don't check length angle spin.
339       isOk = true;
340     }
341   }
342
343   return isOk;
344 }
345
346 //=================================================================================
347 // function : execute
348 // purpose  :
349 //=================================================================================
350 bool TransformationGUI_ProjectionOnCylDlg::execute (ObjectList& objects)
351 {
352   GEOM::GEOM_ITransformOperations_var anOper  =
353     GEOM::GEOM_ITransformOperations::_narrow(getOperation());
354
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.;
359
360   if (myUseAngleLen->isChecked()) {
361     aLengthAngle = myAngleLenSpin->value()*M_PI/180.;
362   }
363
364   GEOM::GEOM_Object_var anObj = anOper->MakeProjectionOnCylinder
365     (myObj, aRadius, aStartAngle, aLengthAngle, aRotAngle);
366
367   if (!anObj->_is_nil()) {
368     if (!IsPreview()) {
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());
376     }
377     objects.push_back(anObj._retn());
378   }
379
380   return true;
381 }