Salome HOME
20ea65bfd697e68099b7067ad5d3293b1a2bb62d
[modules/geom.git] / src / AdvancedGUI / AdvancedGUI_DividedCylinderDlg.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 #include "AdvancedGUI_DividedCylinderDlg.h"
24
25 #include <DlgRef.h>
26 #include <GeometryGUI.h>
27 #include <GEOMBase.h>
28
29 #include <SUIT_Session.h>
30 #include <SUIT_ResourceMgr.h>
31 #include <SalomeApp_Application.h>
32 #include <LightApp_SelectionMgr.h>
33
34 // OCCT Includes
35 #include <TopoDS_Shape.hxx>
36 #include <TopoDS.hxx>
37 #include <TopExp.hxx>
38 #include <TopTools_IndexedMapOfShape.hxx>
39
40 #include <GEOMImpl_Types.hxx>
41
42 //=================================================================================
43 // Constructor
44 //=================================================================================
45 AdvancedGUI_DividedCylinderDlg::AdvancedGUI_DividedCylinderDlg (GeometryGUI* theGeometryGUI, QWidget* parent)
46   : GEOMBase_Skeleton(theGeometryGUI, parent, false)
47 {
48   QPixmap imageOp  (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_DIVIDEDCYLINDER_R_H")));
49   QPixmap imageSel (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
50
51   setWindowTitle(tr("GEOM_DIVIDEDCYLINDER_TITLE"));
52
53   /***************************************************************/
54   mainFrame()->GroupConstructors->setTitle(tr("GEOM_DIVIDEDCYLINDER"));
55   mainFrame()->RadioButton1->setIcon(imageOp);
56   mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose);
57   mainFrame()->RadioButton2->close();
58   mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
59   mainFrame()->RadioButton3->close();
60
61   GroupParams = new DlgRef_2Spin(centralWidget());
62   GroupParams->GroupBox1->setTitle(tr("GEOM_BOX_OBJ"));
63   GroupParams->TextLabel1->setText(tr("GEOM_RADIUS"));
64   GroupParams->TextLabel2->setText(tr("GEOM_HEIGHT"));
65   
66   GroupPattern = new DlgRef_3Radio(centralWidget());
67   GroupPattern->GroupBox1->setTitle(tr("GEOM_PATTERN"));
68   GroupPattern->RadioButton1->setText(tr("GEOM_SQUARE"));
69   GroupPattern->RadioButton2->setText(tr("GEOM_HEXAGON"));
70   GroupPattern->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
71   GroupPattern->RadioButton3->close();
72
73   QVBoxLayout* layout = new QVBoxLayout(centralWidget());
74   layout->setMargin(0); layout->setSpacing(6);
75   layout->addWidget(GroupParams);
76   layout->addWidget(GroupPattern);
77   /***************************************************************/
78
79   setHelpFileName("create_dividedcylinder_page.html");
80
81   Init();
82 }
83
84 //=================================================================================
85 // Destructor
86 //=================================================================================
87 AdvancedGUI_DividedCylinderDlg::~AdvancedGUI_DividedCylinderDlg()
88 {
89   // no need to delete child widgets, Qt does it all for us
90 }
91
92 //=================================================================================
93 // function : Init()
94 // purpose  :
95 //=================================================================================
96 void AdvancedGUI_DividedCylinderDlg::Init()
97 {
98   // Get setting of step value from file configuration
99   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
100   double step = resMgr->doubleValue("Geometry", "SettingsGeomStep", 100);
101
102   // min, max, step and decimals for spin boxes & initial values
103   initSpinBox(GroupParams->SpinBox_DX, 0.00001, COORD_MAX, step, "length_precision" );
104   initSpinBox(GroupParams->SpinBox_DY, 0.00001, COORD_MAX, step, "length_precision" );
105   
106   // init variables
107   double aRadius = 100;
108   double aHeight = 300;
109   GroupParams->SpinBox_DX->setValue(aRadius);
110   GroupParams->SpinBox_DY->setValue(aHeight);
111   
112   GroupPattern->RadioButton1->setChecked(true);
113   myPattern = GEOM::SQUARE;
114
115   // Signal/slot connections
116   connect(buttonOk(),    SIGNAL(clicked()), this, SLOT(ClickOnOk()));
117   connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
118   connect(myGeomGUI,     SIGNAL(SignalDefaultStepValueChanged(double)),
119           this,          SLOT(SetDoubleSpinBoxStep(double)));
120   
121   connect(GroupParams->SpinBox_DX,     SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
122   connect(GroupParams->SpinBox_DY,     SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
123   
124   connect(GroupPattern->RadioButton1,  SIGNAL(clicked()),            this, SLOT(RadioButtonClicked()));
125   connect(GroupPattern->RadioButton2,  SIGNAL(clicked()),            this, SLOT(RadioButtonClicked()));
126
127   initName(tr("GEOM_DIVIDEDCYLINDER"));
128   
129   resize(minimumSizeHint());
130   displayPreview(true);
131 }
132
133 //=================================================================================
134 // function : SetDoubleSpinBoxStep()
135 // purpose  : Double spin box management
136 //=================================================================================
137 void AdvancedGUI_DividedCylinderDlg::SetDoubleSpinBoxStep (double /*step*/)
138 {
139   //@@ set double spin box step for all spin boxes here @@//
140 }
141
142 //=================================================================================
143 // function : RadioButtonClicked()
144 // purpose  : Radio button management
145 //=================================================================================
146 void AdvancedGUI_DividedCylinderDlg::RadioButtonClicked()
147
148   QRadioButton* send = (QRadioButton*)sender();
149   
150   // Division pattern
151   if (send == GroupPattern->RadioButton1)
152     myPattern = GEOM::SQUARE;
153   else if (send == GroupPattern->RadioButton2)
154     myPattern = GEOM::HEXAGON;
155   
156   displayPreview(true);
157 }
158
159 //=================================================================================
160 // function : ClickOnOk()
161 // purpose  :
162 //=================================================================================
163 void AdvancedGUI_DividedCylinderDlg::ClickOnOk()
164 {
165   if (ClickOnApply())
166     ClickOnCancel();
167 }
168
169 //=================================================================================
170 // function : ClickOnApply()
171 // purpose  :
172 //=================================================================================
173 bool AdvancedGUI_DividedCylinderDlg::ClickOnApply()
174 {
175   if (!onAccept())
176     return false;
177
178   initName();
179
180   return true;
181 }
182
183 //=================================================================================
184 // function : ActivateThisDialog()
185 // purpose  :
186 //=================================================================================
187 void AdvancedGUI_DividedCylinderDlg::ActivateThisDialog()
188 {
189   GEOMBase_Skeleton::ActivateThisDialog();
190   displayPreview(true);
191 }
192
193 //=================================================================================
194 // function : enterEvent [REDEFINED]
195 // purpose  :
196 //=================================================================================
197 void AdvancedGUI_DividedCylinderDlg::enterEvent (QEvent*)
198 {
199   if (!mainFrame()->GroupConstructors->isEnabled())
200     ActivateThisDialog();
201 }
202
203 //=================================================================================
204 // function : ValueChangedInSpinBox()
205 // purpose  :
206 //=================================================================================
207 void AdvancedGUI_DividedCylinderDlg::ValueChangedInSpinBox()
208 {
209   //@@ connect custom spin boxes or other widget to this slot in the Init() method for automatic preview update @@//
210   displayPreview(true);
211 }
212
213 //=================================================================================
214 // function : createOperation
215 // purpose  :
216 //=================================================================================
217 GEOM::GEOM_IOperations_ptr AdvancedGUI_DividedCylinderDlg::createOperation()
218 {
219   return getGeomEngine()->GetPluginOperations("AdvancedEngine");
220 }
221
222 //=================================================================================
223 // function : isValid
224 // purpose  :
225 //=================================================================================
226 bool AdvancedGUI_DividedCylinderDlg::isValid (QString& /*msg*/)
227 {
228   bool ok = true;
229
230   //@@ add custom validation actions here @@//
231
232   return ok;
233 }
234
235 //=================================================================================
236 // function : execute
237 // purpose  :
238 //=================================================================================
239 bool AdvancedGUI_DividedCylinderDlg::execute (ObjectList& objects)
240 {
241   bool res = false;
242
243   GEOM::GEOM_Object_var anObj;
244
245   GEOM::IAdvancedOperations_var anOper = GEOM::IAdvancedOperations::_narrow(getOperation());
246
247   //@@ retrieve input values from the widgets here @@//
248   CORBA::Double theR = GroupParams->SpinBox_DX->value();
249   CORBA::Double theH = GroupParams->SpinBox_DY->value();
250
251   // call engine function
252   anObj = anOper->MakeDividedCylinder(theR, theH, myPattern);
253   res = !anObj->_is_nil();
254   if (res && !IsPreview())
255   {
256     QStringList aParameters;
257     aParameters << GroupParams->SpinBox_DX->text(); // R parameter
258     aParameters << GroupParams->SpinBox_DY->text(); // H parameter
259     if ( aParameters.count() > 0 ) anObj->SetParameters(aParameters.join(":").toUtf8().constData());
260   }
261   
262   if (res)
263     objects.push_back(anObj._retn());
264
265   return res;
266 }