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