]> SALOME platform Git repositories - modules/geom.git/blob - src/AdvancedGUI/AdvancedGUI_DividedCylinderDlg.cxx
Salome HOME
EDF 2281 : missing translations, doc and pictures
[modules/geom.git] / src / AdvancedGUI / AdvancedGUI_DividedCylinderDlg.cxx
1 //  Copyright (C) 2007-2008  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 #include "AdvancedGUI_DividedCylinderDlg.h"
23
24 #include <DlgRef.h>
25 #include <GeometryGUI.h>
26 #include <GEOMBase.h>
27
28 #include <SUIT_Session.h>
29 #include <SUIT_ResourceMgr.h>
30 #include <SalomeApp_Application.h>
31 #include <LightApp_SelectionMgr.h>
32
33 // OCCT Includes
34 #include <TopoDS_Shape.hxx>
35 #include <TopoDS.hxx>
36 #include <TopExp.hxx>
37 #include <TColStd_IndexedMapOfInteger.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   QVBoxLayout* layout = new QVBoxLayout(centralWidget());
67   layout->setMargin(0); layout->setSpacing(6);
68   layout->addWidget(GroupParams);
69   /***************************************************************/
70
71   setHelpFileName("create_dividedcylinder_page.html");
72
73   Init();
74 }
75
76 //=================================================================================
77 // Destructor
78 //=================================================================================
79 AdvancedGUI_DividedCylinderDlg::~AdvancedGUI_DividedCylinderDlg()
80 {
81   // no need to delete child widgets, Qt does it all for us
82 }
83
84 //=================================================================================
85 // function : Init()
86 // purpose  :
87 //=================================================================================
88 void AdvancedGUI_DividedCylinderDlg::Init()
89 {
90   // Get setting of step value from file configuration
91   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
92   double step = resMgr->doubleValue("Geometry", "SettingsGeomStep", 100);
93
94   // min, max, step and decimals for spin boxes & initial values
95   initSpinBox(GroupParams->SpinBox_DX, 0.00001, COORD_MAX, step, "length_precision" );
96   initSpinBox(GroupParams->SpinBox_DY, 0.00001, COORD_MAX, step, "length_precision" );
97   
98   // init variables
99   double aRadius = 100;
100   double aHeight = 300;
101   GroupParams->SpinBox_DX->setValue(aRadius);
102   GroupParams->SpinBox_DY->setValue(aHeight);
103
104   // Signal/slot connections
105   connect(buttonOk(),    SIGNAL(clicked()), this, SLOT(ClickOnOk()));
106   connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
107   connect(myGeomGUI,     SIGNAL(SignalDefaultStepValueChanged(double)),
108           this,          SLOT(SetDoubleSpinBoxStep(double)));
109   
110   connect(GroupParams->SpinBox_DX,     SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
111   connect(GroupParams->SpinBox_DY,     SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
112
113   initName(tr("GEOM_DIVIDEDCYLINDER"));
114   
115   resize(minimumSizeHint());
116   displayPreview(true);
117 }
118
119 //=================================================================================
120 // function : SetDoubleSpinBoxStep()
121 // purpose  : Double spin box management
122 //=================================================================================
123 void AdvancedGUI_DividedCylinderDlg::SetDoubleSpinBoxStep (double step)
124 {
125   //@@ set double spin box step for all spin boxes here @@//
126 }
127
128 //=================================================================================
129 // function : ClickOnOk()
130 // purpose  :
131 //=================================================================================
132 void AdvancedGUI_DividedCylinderDlg::ClickOnOk()
133 {
134   if (ClickOnApply())
135     ClickOnCancel();
136 }
137
138 //=================================================================================
139 // function : ClickOnApply()
140 // purpose  :
141 //=================================================================================
142 bool AdvancedGUI_DividedCylinderDlg::ClickOnApply()
143 {
144   if (!onAccept())
145     return false;
146
147   initName();
148
149   return true;
150 }
151
152 //=================================================================================
153 // function : ActivateThisDialog()
154 // purpose  :
155 //=================================================================================
156 void AdvancedGUI_DividedCylinderDlg::ActivateThisDialog()
157 {
158   GEOMBase_Skeleton::ActivateThisDialog();
159   displayPreview(true);
160 }
161
162 //=================================================================================
163 // function : enterEvent [REDEFINED]
164 // purpose  :
165 //=================================================================================
166 void AdvancedGUI_DividedCylinderDlg::enterEvent (QEvent*)
167 {
168   if (!mainFrame()->GroupConstructors->isEnabled())
169     ActivateThisDialog();
170 }
171
172 //=================================================================================
173 // function : ValueChangedInSpinBox()
174 // purpose  :
175 //=================================================================================
176 void AdvancedGUI_DividedCylinderDlg::ValueChangedInSpinBox()
177 {
178   //@@ connect custom spin boxes or other widget to this slot in the Init() method for automatic preview update @@//
179   displayPreview(true);
180 }
181
182 //=================================================================================
183 // function : createOperation
184 // purpose  :
185 //=================================================================================
186 GEOM::GEOM_IOperations_ptr AdvancedGUI_DividedCylinderDlg::createOperation()
187 {
188   return getGeomEngine()->GetIAdvancedOperations(getStudyId());
189 }
190
191 //=================================================================================
192 // function : isValid
193 // purpose  :
194 //=================================================================================
195 bool AdvancedGUI_DividedCylinderDlg::isValid (QString& msg)
196 {
197   bool ok = true;
198
199   //@@ add custom validation actions here @@//
200
201   return ok;
202 }
203
204 //=================================================================================
205 // function : execute
206 // purpose  :
207 //=================================================================================
208 bool AdvancedGUI_DividedCylinderDlg::execute (ObjectList& objects)
209 {
210   bool res = false;
211
212   GEOM::GEOM_Object_var anObj;
213
214   GEOM::GEOM_IAdvancedOperations_var anOper = GEOM::GEOM_IAdvancedOperations::_narrow(getOperation());
215
216   //@@ retrieve input values from the widgets here @@//
217   CORBA::Double theR = GroupParams->SpinBox_DX->value();
218   CORBA::Double theH = GroupParams->SpinBox_DY->value();
219
220   // call engine function
221   anObj = anOper->MakeDividedCylinder(theR, theH);
222   res = !anObj->_is_nil();
223   if (res && !IsPreview())
224   {
225     QStringList aParameters;
226     aParameters << GroupParams->SpinBox_DX->text(); // R parameter
227     aParameters << GroupParams->SpinBox_DY->text(); // H parameter
228     if ( aParameters.count() > 0 ) anObj->SetParameters(aParameters.join(":").toLatin1().constData());
229   }
230   
231   if (res)
232     objects.push_back(anObj._retn());
233
234   return res;
235 }