]> SALOME platform Git repositories - modules/geom.git/blob - src/TransformationGUI/TransformationGUI_ProjectionOnCylDlg.cxx
Salome HOME
7c5dd617699e515d1e9fa6509832f3e1b30bb8e7
[modules/geom.git] / src / TransformationGUI / TransformationGUI_ProjectionOnCylDlg.cxx
1 // Copyright (C) 2007-2014  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 {
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")));
68
69   setWindowTitle(tr("GEOM_PROJ_ON_CYL_TITLE"));
70
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();
78
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);
88
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);
95
96   myObjectName->setReadOnly(true);
97   mySelButton->setIcon(image1);
98   mySelButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
99   myUseAngleLen->setChecked(false);
100
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);
113
114   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
115   layout->setMargin( 0 ); layout->setSpacing( 6 );
116   layout->addWidget( aGrpParams );
117
118   /***************************************************************/
119
120   setHelpFileName("projection_on_cylinder_operation_page.html");
121
122   Init();
123 }
124
125 //=================================================================================
126 // function : ~TransformationGUI_ProjectionOnCylDlg()
127 // purpose  : Destroys the object and frees any allocated resources
128 //=================================================================================
129 TransformationGUI_ProjectionOnCylDlg::~TransformationGUI_ProjectionOnCylDlg()
130 {
131   // no need to delete child widgets, Qt does it all for us
132 }
133
134 //=================================================================================
135 // function : Init()
136 // purpose  :
137 //=================================================================================
138 void TransformationGUI_ProjectionOnCylDlg::Init()
139 {
140   showOnlyPreviewControl();
141
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.;
148
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");
152
153   myRadiusSpin->setValue(aRadius);
154   myStartAngleSpin->setValue(aStartAngle);
155   myAngleLenSpin->setValue(anAngleLen);
156
157   myObjectName->setText("");
158   myUseAngleLen->setChecked(true);
159
160   // signals and slots connections
161   connect(buttonOk(),    SIGNAL(clicked()), this, SLOT(ClickOnOk()));
162   connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
163
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()));
169
170   connect(myGeomGUI->getApp()->selectionMgr(),SIGNAL(currentSelectionChanged()),
171           this, SLOT(SelectionIntoArgument()));
172
173   initName(tr("GEOM_PROJECTION_NAME"));
174
175   buttonOk()->setEnabled(false);
176   buttonApply()->setEnabled(false);
177
178   activateSelection();
179   SelectionIntoArgument();
180 }
181
182 //=================================================================================
183 // function : ClickOnOk()
184 // purpose  :
185 //=================================================================================
186 void TransformationGUI_ProjectionOnCylDlg::ClickOnOk()
187 {
188   setIsApplyAndClose( true );
189   if (ClickOnApply())
190     ClickOnCancel();
191 }
192
193 //=================================================================================
194 // function : ClickOnApply()
195 // purpose  :
196 //=================================================================================
197 bool TransformationGUI_ProjectionOnCylDlg::ClickOnApply()
198 {
199   if ( !onAccept() )
200     return false;
201
202   initName();
203   return true;
204 }
205
206 //=================================================================================
207 // function : SelectionIntoArgument()
208 // purpose  : Called when selection is changed or on dialog initialization or activation
209 //=================================================================================
210 void TransformationGUI_ProjectionOnCylDlg::SelectionIntoArgument()
211 {
212   erasePreview();
213   myObj = GEOM::GEOM_Object::_nil();
214
215   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
216   SALOME_ListIO aSelList;
217   aSelMgr->selectedObjects(aSelList);
218
219   if (aSelList.Extent() == 1) {
220     // Single object is selected.
221     GEOM::GEOM_Object_var aSelectedObject =
222       GEOMBase::ConvertIOinGEOMObject( aSelList.First() );
223
224     if (aSelectedObject->_is_nil()) {
225       // Null object.
226       myObjectName->setText("");
227       buttonOk()->setEnabled(false);
228       buttonApply()->setEnabled(false);
229     } else {
230       // Not Null object.
231       myObj = aSelectedObject;
232       myObjectName->setText(GEOMBase::GetName(myObj));
233       buttonOk()->setEnabled(true);
234       buttonApply()->setEnabled(true);
235     }
236   } else {
237     // Not a single object is selected.
238     myObjectName->setText("");
239     buttonOk()->setEnabled(false);
240     buttonApply()->setEnabled(false);
241   }
242
243   processPreview();
244 }
245
246 //=================================================================================
247 // function : SetEditCurrentArgument()
248 // purpose  :
249 //=================================================================================
250 void TransformationGUI_ProjectionOnCylDlg::SetEditCurrentArgument()
251 {
252   myObjectName->setFocus();
253   myEditCurrentArgument = myObjectName;
254   SelectionIntoArgument();
255 }
256
257 //=================================================================================
258 // function : SetUseLengthAngle()
259 // purpose  :
260 //=================================================================================
261 void TransformationGUI_ProjectionOnCylDlg::SetUseLengthAngle()
262 {
263   myAngleLenSpin->setEnabled(myUseAngleLen->isChecked());
264   processPreview();
265 }
266
267 //=================================================================================
268 // function : activateSelection
269 // purpose  : activate selection of wires or faces
270 //=================================================================================
271 void TransformationGUI_ProjectionOnCylDlg::activateSelection()
272 {
273   TColStd_MapOfInteger aMap;
274
275   aMap.Add(GEOM_WIRE);
276   aMap.Add(GEOM_FACE);
277   globalSelection(aMap);
278 }
279
280 //=================================================================================
281 // function : ActivateThisDialog()
282 // purpose  :
283 //=================================================================================
284 void TransformationGUI_ProjectionOnCylDlg::ActivateThisDialog()
285 {
286   GEOMBase_Skeleton::ActivateThisDialog();
287   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
288            this, SLOT( SelectionIntoArgument() ) );
289
290   activateSelection();
291 }
292
293 //=================================================================================
294 // function : enterEvent()
295 // purpose  :
296 //=================================================================================
297 void TransformationGUI_ProjectionOnCylDlg::enterEvent (QEvent*)
298 {
299   if (!mainFrame()->GroupConstructors->isEnabled())
300     ActivateThisDialog();
301 }
302
303 //=================================================================================
304 // function : createOperation
305 // purpose  :
306 //=================================================================================
307 GEOM::GEOM_IOperations_ptr TransformationGUI_ProjectionOnCylDlg::createOperation()
308 {
309   return getGeomEngine()->GetITransformOperations(getStudyId());
310 }
311
312 //=================================================================================
313 // function : isValid
314 // purpose  :
315 //=================================================================================
316 bool TransformationGUI_ProjectionOnCylDlg::isValid (QString &msg)
317 {
318   bool isOk = false;
319
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());
326     } else {
327       // Don't check length angle spin.
328       isOk = true;
329     }
330   }
331
332   return isOk;
333 }
334
335 //=================================================================================
336 // function : execute
337 // purpose  :
338 //=================================================================================
339 bool TransformationGUI_ProjectionOnCylDlg::execute (ObjectList& objects)
340 {
341   GEOM::GEOM_ITransformOperations_var anOper  =
342     GEOM::GEOM_ITransformOperations::_narrow(getOperation());
343
344   double aRadius      = myRadiusSpin->value();
345   double aStartAngle  = myStartAngleSpin->value()*M_PI/180.;
346   double aLengthAngle = -1.;
347
348   if (myUseAngleLen->isChecked()) {
349     aLengthAngle = myAngleLenSpin->value()*M_PI/180.;
350   }
351
352   GEOM::GEOM_Object_var anObj = anOper->MakeProjectionOnCylinder
353     (myObj, aRadius, aStartAngle, aLengthAngle);
354
355   if (!anObj->_is_nil()) {
356     if (!IsPreview()) {
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());
363     }
364     objects.push_back(anObj._retn());
365   }
366
367   return true;
368 }