]> SALOME platform Git repositories - modules/geom.git/blob - src/AdvancedGUI/AdvancedGUI_SmoothingSurfaceDlg.cxx
Salome HOME
Merge branch V7_3_1_BR
[modules/geom.git] / src / AdvancedGUI / AdvancedGUI_SmoothingSurfaceDlg.cxx
1 // Copyright (C) 2013-2014  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "AdvancedGUI_SmoothingSurfaceDlg.h"
21
22 #include <DlgRef.h>
23 #include <GeometryGUI.h>
24 #include <GEOMBase.h>
25
26 #include <SUIT_Session.h>
27 #include <SUIT_ResourceMgr.h>
28 #include <SalomeApp_Application.h>
29 #include <LightApp_SelectionMgr.h>
30
31 // OCCT Includes
32 #include <TopoDS_Shape.hxx>
33 #include <TopoDS.hxx>
34 #include <TopoDS_Iterator.hxx>
35 #include <TopExp.hxx>
36 #include <TColStd_IndexedMapOfInteger.hxx>
37 #include <TopTools_IndexedMapOfShape.hxx>
38
39 #include <GEOMImpl_Types.hxx>
40
41 //=================================================================================
42 // Constructor
43 //=================================================================================
44 AdvancedGUI_SmoothingSurfaceDlg::AdvancedGUI_SmoothingSurfaceDlg (GeometryGUI* theGeometryGUI, QWidget* parent)
45   : GEOMBase_Skeleton(theGeometryGUI, parent, false),
46     myNbMaxSpin(0),
47     myDegMaxSpin(0),
48     myDMaxSpin(0)
49 {
50   QPixmap imageOp  (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_SMOOTHINGSURFACE_LPOINTS")));
51   QPixmap imageSel (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
52   QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
53
54   setWindowTitle(tr("GEOM_SMOOTHINGSURFACE_TITLE"));
55
56   /***************************************************************/
57   mainFrame()->GroupConstructors->setTitle(tr("GEOM_SMOOTHINGSURFACE"));
58   mainFrame()->RadioButton1->setIcon(imageOp);
59   mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose);
60   mainFrame()->RadioButton2->close();
61   mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
62   mainFrame()->RadioButton3->close();
63
64   GroupPoints = new DlgRef_1Sel( centralWidget() );
65
66   GroupPoints->GroupBox1->setTitle( tr( "GEOM_SMOOTHINGSURFACE_ARG" ) );
67   GroupPoints->TextLabel1->setText( tr( "GEOM_SMOOTHINGSURFACE_ARG_POINTS" ) );
68   GroupPoints->PushButton1->setIcon( image1 );
69   GroupPoints->LineEdit1->setReadOnly( true );
70
71   QLabel *aNbMax  = new QLabel(tr("GEOM_SMOOTHINGSURFACE_ARG_NB_MAX"));
72   QLabel *aDegMax = new QLabel(tr("GEOM_SMOOTHINGSURFACE_ARG_DEG_MAX"));
73   QLabel *aDMax   = new QLabel(tr("GEOM_SMOOTHINGSURFACE_ARG_D_MAX"));
74
75   myNbMaxSpin  = new SalomeApp_IntSpinBox(0, 1000, 1, 0, true, true);
76   myDegMaxSpin = new SalomeApp_IntSpinBox(0, 1000, 1, 0, true, true);
77   myDMaxSpin   = new SalomeApp_DoubleSpinBox;
78   GroupPoints->gridLayout1->addWidget(aNbMax,       1, 0);
79   GroupPoints->gridLayout1->addWidget(aDegMax,      2, 0);
80   GroupPoints->gridLayout1->addWidget(aDMax,        3, 0);
81   GroupPoints->gridLayout1->addWidget(myNbMaxSpin,  1, 1, 1, 2);
82   GroupPoints->gridLayout1->addWidget(myDegMaxSpin, 2, 1, 1, 2);
83   GroupPoints->gridLayout1->addWidget(myDMaxSpin,   3, 1, 1, 2);
84
85   QVBoxLayout* layout = new QVBoxLayout(centralWidget());
86   layout->setMargin(0); layout->setSpacing(6);
87   layout->addWidget(GroupPoints);
88   /***************************************************************/
89
90   setHelpFileName("create_smoothingsurface_page.html");
91
92   Init();
93 }
94
95 //=================================================================================
96 // Destructor
97 //=================================================================================
98 AdvancedGUI_SmoothingSurfaceDlg::~AdvancedGUI_SmoothingSurfaceDlg()
99 {
100   // no need to delete child widgets, Qt does it all for us
101 }
102
103 //=================================================================================
104 // function : Init()
105 // purpose  :
106 //=================================================================================
107 void AdvancedGUI_SmoothingSurfaceDlg::Init()
108 {
109   // Get setting of step value from file configuration
110   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
111
112   initSpinBox(myDMaxSpin, 0., COORD_MAX, 0.00001, "parametric_precision" );
113
114   myNbMaxSpin->setValue(2);
115   myDegMaxSpin->setValue(8);
116   myDMaxSpin->setValue(0.);
117
118   //@@ initialize dialog box widgets here @@//
119
120   // Signal/slot connections
121   connect(buttonOk(),    SIGNAL(clicked()), this, SLOT(ClickOnOk()));
122   connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
123   connect(myGeomGUI,     SIGNAL(SignalDefaultStepValueChanged(double)),
124           this,          SLOT(SetDoubleSpinBoxStep(double)));
125   connect( myGeomGUI->getApp()->selectionMgr(),
126            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
127   connect(myNbMaxSpin, SIGNAL(valueChanged(const QString&)),
128           this, SLOT(processPreview()) );
129   connect(myDegMaxSpin, SIGNAL(valueChanged(const QString&)),
130           this, SLOT(processPreview()) );
131   connect(myDMaxSpin, SIGNAL(valueChanged(const QString&)),
132           this, SLOT(processPreview()) );
133  
134   initName(tr("GEOM_SMOOTHINGSURFACE"));
135   //displayPreview();
136 }
137
138 //=================================================================================
139 // function : ClickOnOk()
140 // purpose  :
141 //=================================================================================
142 void AdvancedGUI_SmoothingSurfaceDlg::ClickOnOk()
143 {
144   if (ClickOnApply())
145     ClickOnCancel();
146 }
147
148 //=================================================================================
149 // function : ClickOnApply()
150 // purpose  :
151 //=================================================================================
152 bool AdvancedGUI_SmoothingSurfaceDlg::ClickOnApply()
153 {
154   if (!onAccept())
155     return false;
156
157   initName();
158
159   return true;
160 }
161
162 //=================================================================================
163 // function : ActivateThisDialog()
164 // purpose  :
165 //=================================================================================
166 void AdvancedGUI_SmoothingSurfaceDlg::ActivateThisDialog()
167 {
168   GEOMBase_Skeleton::ActivateThisDialog();
169   //displayPreview();
170 }
171
172 //=================================================================================
173 // function : enterEvent [REDEFINED]
174 // purpose  :
175 //=================================================================================
176 void AdvancedGUI_SmoothingSurfaceDlg::enterEvent (QEvent*)
177 {
178   if (!mainFrame()->GroupConstructors->isEnabled())
179     ActivateThisDialog();
180 }
181
182 //=================================================================================
183 // function : createOperation
184 // purpose  :
185 //=================================================================================
186 GEOM::GEOM_IOperations_ptr AdvancedGUI_SmoothingSurfaceDlg::createOperation()
187 {
188   //return getGeomEngine()->GetIAdvancedOperations(getStudyId());
189   return getGeomEngine()->GetPluginOperations(getStudyId(), "AdvancedEngine");
190 }
191
192 //=================================================================================
193 // function : isValid
194 // purpose  :
195 //=================================================================================
196 bool AdvancedGUI_SmoothingSurfaceDlg::isValid (QString& msg)
197 {
198   if (myPoints.empty()) {
199     msg += tr("GEOM_SMOOTHINGSURFACE_NO_POINTS");
200     return false;
201   }
202
203   bool ok = myNbMaxSpin->isValid (msg, !IsPreview()) &&
204             myDegMaxSpin->isValid(msg, !IsPreview()) &&
205             myDMaxSpin->isValid  (msg, !IsPreview());
206
207   return ok;
208 }
209
210 //=================================================================================
211 // function : execute
212 // purpose  :
213 //=================================================================================
214 bool AdvancedGUI_SmoothingSurfaceDlg::execute (ObjectList& objects)
215 {
216   bool res = false;
217
218   GEOM::GEOM_Object_var anObj;
219
220   GEOM::GEOM_IAdvancedOperations_var anOper = GEOM::GEOM_IAdvancedOperations::_narrow(getOperation());
221
222   //@@ retrieve input values from the widgets here @@//
223   GEOM::ListOfGO_var points = new GEOM::ListOfGO();
224   points->length( myPoints.count() );
225   for ( int i = 0; i < myPoints.count(); i++ )
226     points[i] = myPoints[i].copy();
227
228   const int    aNbMax  = myNbMaxSpin->value();
229   const int    aDegMax = myDegMaxSpin->value();
230   const double aDMax   = myDMaxSpin->value();
231
232   // call engine function
233   anObj = anOper->MakeSmoothingSurface(points, aNbMax, aDegMax, aDMax);
234   res = !anObj->_is_nil();
235   if (res && !IsPreview())
236   {
237     QStringList aParameters;
238     //@@ put stringified input parameters to the string list here to store in the data model for notebook @@//
239     if ( aParameters.count() > 0 ) anObj->SetParameters(aParameters.join(":").toLatin1().constData());
240   }
241   
242   if (res)
243     objects.push_back(anObj._retn());
244
245   return res;
246 }
247
248 //=================================================================================
249 // function : getNbPoints()
250 // purpose  : Returns the number of points in myPoints list.
251 //=================================================================================
252 int AdvancedGUI_SmoothingSurfaceDlg::getNbPoints() const
253 {
254   TopTools_IndexedMapOfShape aMap;
255
256   foreach (GEOM::GeomObjPtr anObj, myPoints) {
257     TopoDS_Shape aShape;
258
259     if(anObj && GEOMBase::GetShape(anObj.get(), aShape) && !aShape.IsNull()) {
260       if (aShape.ShapeType() == TopAbs_VERTEX) {
261         aMap.Add(aShape);
262       } else {
263         // Compound.
264         TopExp::MapShapes(aShape, TopAbs_VERTEX, aMap);
265       }
266     }
267   }
268
269   const int aNbPoints = aMap.Extent();
270
271   return aNbPoints;
272 }
273
274 //=================================================================================
275 // function : SelectionIntoArgument()
276 // purpose  : Called when selection as changed or other case
277 //=================================================================================
278 void AdvancedGUI_SmoothingSurfaceDlg::SelectionIntoArgument()
279 {
280   QList<TopAbs_ShapeEnum> aTypes;
281
282   aTypes << TopAbs_VERTEX << TopAbs_COMPOUND;
283
284   QList<GEOM::GeomObjPtr> points = getSelected( aTypes, -1 );
285
286   // Check the selected compounds if they consist of points only.
287   foreach (GEOM::GeomObjPtr anObj, points) {
288     TopoDS_Shape aShape;
289
290     if(anObj && GEOMBase::GetShape(anObj.get(), aShape) && !aShape.IsNull()) {
291       if (aShape.ShapeType() == TopAbs_COMPOUND) {
292         // Check if the compound contains vertices only.
293         TopoDS_Iterator anIter(aShape);
294         Standard_Boolean isValid = Standard_False;
295
296         for (; anIter.More(); anIter.Next()) {
297           const TopoDS_Shape &aSubShape = anIter.Value();
298
299           if (aSubShape.ShapeType() == TopAbs_VERTEX) {
300             isValid = Standard_True;
301           } else {
302             isValid = Standard_False;
303             break;
304           }
305         }
306
307         if (!isValid) {
308           points.clear();
309           break;
310         }
311       }
312     } else {
313       // NEVERREACHED
314       points.clear();
315       break;
316     }
317   }
318
319   GEOMBase::Synchronize( myPoints, points );
320   if ( !myPoints.isEmpty()  )
321     GroupPoints->LineEdit1->setText( QString::number( getNbPoints() ) + "_" + tr( "GEOM_POINT" ) + tr( "_S_" ) );
322   else
323     GroupPoints->LineEdit1->setText( "" );
324   processPreview();
325 }
326
327 //=================================================================================
328 // function : SetEditCurrentArgument()
329 // purpose  :
330 //=================================================================================
331 void AdvancedGUI_SmoothingSurfaceDlg::SetEditCurrentArgument()
332 {
333   if ( sender() == GroupPoints->PushButton1 )
334     myEditCurrentArgument = GroupPoints->LineEdit1;
335   myEditCurrentArgument->setFocus();
336   SelectionIntoArgument();
337 }