]> SALOME platform Git repositories - modules/geom.git/blob - src/AdvancedGUI/AdvancedGUI_DividedDiskDlg.cxx
Salome HOME
Missing files
[modules/geom.git] / src / AdvancedGUI / AdvancedGUI_DividedDiskDlg.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_DividedDiskDlg.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_DividedDiskDlg::AdvancedGUI_DividedDiskDlg (GeometryGUI* theGeometryGUI, QWidget* parent)
46   : GEOMBase_Skeleton(theGeometryGUI, parent, false)
47 {
48   QPixmap imageOp  (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_DIVIDEDDISK_R_RATIO")));
49   QPixmap imageSel (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
50
51   setWindowTitle(tr("GEOM_DIVIDEDDISK_TITLE"));
52
53   /***************************************************************/
54   mainFrame()->GroupConstructors->setTitle(tr("GEOM_DIVIDEDDISK"));
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_1Spin(centralWidget());
62   //@@ setup dialog box layout here @@//
63
64   QVBoxLayout* layout = new QVBoxLayout(centralWidget());
65   layout->setMargin(0); layout->setSpacing(6);
66   layout->addWidget(GroupParams);
67   /***************************************************************/
68
69   setHelpFileName("create_divideddisk_page.html");
70
71   Init();
72 }
73
74 //=================================================================================
75 // Destructor
76 //=================================================================================
77 AdvancedGUI_DividedDiskDlg::~AdvancedGUI_DividedDiskDlg()
78 {
79   // no need to delete child widgets, Qt does it all for us
80 }
81
82 //=================================================================================
83 // function : Init()
84 // purpose  :
85 //=================================================================================
86 void AdvancedGUI_DividedDiskDlg::Init()
87 {
88   // Get setting of step value from file configuration
89   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
90   double step = resMgr->doubleValue("Geometry", "SettingsGeomStep", 100);
91
92   // min, max, step and decimals for spin boxes & initial values
93   initSpinBox(GroupParams->SpinBox_DX, 0.00001, COORD_MAX, step, "length_precision" );
94   GroupParams->SpinBox_DX->setValue(100);
95
96   // Signal/slot connections
97   connect(buttonOk(),    SIGNAL(clicked()), this, SLOT(ClickOnOk()));
98   connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
99   connect(myGeomGUI,     SIGNAL(SignalDefaultStepValueChanged(double)),
100           this,          SLOT(SetDoubleSpinBoxStep(double)));
101
102   connect(GroupParams->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
103
104   initName(tr("GEOM_DIVIDEDDISK"));
105   
106   resize(minimumSizeHint());
107   displayPreview(true);
108 }
109
110 //=================================================================================
111 // function : SetDoubleSpinBoxStep()
112 // purpose  : Double spin box management
113 //=================================================================================
114 void AdvancedGUI_DividedDiskDlg::SetDoubleSpinBoxStep (double step)
115 {
116   //@@ set double spin box step for all spin boxes here @@//
117 }
118
119 //=================================================================================
120 // function : ClickOnOk()
121 // purpose  :
122 //=================================================================================
123 void AdvancedGUI_DividedDiskDlg::ClickOnOk()
124 {
125   if (ClickOnApply())
126     ClickOnCancel();
127 }
128
129 //=================================================================================
130 // function : ClickOnApply()
131 // purpose  :
132 //=================================================================================
133 bool AdvancedGUI_DividedDiskDlg::ClickOnApply()
134 {
135   if (!onAccept())
136     return false;
137
138   initName();
139
140   return true;
141 }
142
143 //=================================================================================
144 // function : ActivateThisDialog()
145 // purpose  :
146 //=================================================================================
147 void AdvancedGUI_DividedDiskDlg::ActivateThisDialog()
148 {
149   GEOMBase_Skeleton::ActivateThisDialog();
150   displayPreview(true);
151 }
152
153 //=================================================================================
154 // function : enterEvent [REDEFINED]
155 // purpose  :
156 //=================================================================================
157 void AdvancedGUI_DividedDiskDlg::enterEvent (QEvent*)
158 {
159   if (!mainFrame()->GroupConstructors->isEnabled())
160     ActivateThisDialog();
161 }
162
163 //=================================================================================
164 // function : ValueChangedInSpinBox()
165 // purpose  :
166 //=================================================================================
167 void AdvancedGUI_DividedDiskDlg::ValueChangedInSpinBox()
168 {
169   //@@ connect custom spin boxes or other widget to this slot in the Init() method for automatic preview update @@//
170   displayPreview(true);
171 }
172
173 //=================================================================================
174 // function : createOperation
175 // purpose  :
176 //=================================================================================
177 GEOM::GEOM_IOperations_ptr AdvancedGUI_DividedDiskDlg::createOperation()
178 {
179   return getGeomEngine()->GetIAdvancedOperations(getStudyId());
180 }
181
182 //=================================================================================
183 // function : isValid
184 // purpose  :
185 //=================================================================================
186 bool AdvancedGUI_DividedDiskDlg::isValid (QString& msg)
187 {
188   bool ok = true;
189
190   //@@ add custom validation actions here @@//
191
192   return ok;
193 }
194
195 //=================================================================================
196 // function : execute
197 // purpose  :
198 //=================================================================================
199 bool AdvancedGUI_DividedDiskDlg::execute (ObjectList& objects)
200 {
201   bool res = false;
202
203   GEOM::GEOM_Object_var anObj;
204
205   GEOM::GEOM_IAdvancedOperations_var anOper = GEOM::GEOM_IAdvancedOperations::_narrow(getOperation());
206
207   //@@ retrieve input values from the widgets here @@//
208   CORBA::Double theR = GroupParams->SpinBox_DX->value(); //@@ init parameter value from dialog box @@;
209   CORBA::Double theRatio = 50; //@@ init parameter value from dialog box @@;
210
211   // call engine function
212   anObj = anOper->MakeDividedDisk(theR, theRatio);
213   res = !anObj->_is_nil();
214   if (res && !IsPreview())
215   {
216     QStringList aParameters;
217     //@@ put stringified input parameters to the string list here to store in the data model for notebook @@//
218     //aParameters << @@ stringified parameter value @@; // R parameter
219     //aParameters << @@ stringified parameter value @@; // Ratio parameter
220     if ( aParameters.count() > 0 ) anObj->SetParameters(aParameters.join(":").toLatin1().constData());
221   }
222   
223   if (res)
224     objects.push_back(anObj._retn());
225
226   return res;
227 }