]> SALOME platform Git repositories - modules/geom.git/blob - src/AdvancedGUI/AdvancedGUI_SmoothingSurfaceDlg.cxx
Salome HOME
Merge remote-tracking branch 'origin/master' into rnc/t_shape_plugin
[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 <SALOMEconfig.h>
23 #include CORBA_SERVER_HEADER(AdvancedGEOM)
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 <TopoDS_Iterator.hxx>
38 #include <TopExp.hxx>
39 #include <TopTools_IndexedMapOfShape.hxx>
40
41 #include <GEOMImpl_Types.hxx>
42
43 //=================================================================================
44 // Constructor
45 //=================================================================================
46 AdvancedGUI_SmoothingSurfaceDlg::AdvancedGUI_SmoothingSurfaceDlg (GeometryGUI* theGeometryGUI, QWidget* parent)
47   : GEOMBase_Skeleton(theGeometryGUI, parent, false),
48     myNbMaxSpin(0),
49     myDegMaxSpin(0),
50     myDMaxSpin(0)
51 {
52   QPixmap imageOp  (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_SMOOTHINGSURFACE_LPOINTS")));
53   QPixmap imageSel (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
54   QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
55
56   setWindowTitle(tr("GEOM_SMOOTHINGSURFACE_TITLE"));
57
58   /***************************************************************/
59   mainFrame()->GroupConstructors->setTitle(tr("GEOM_SMOOTHINGSURFACE"));
60   mainFrame()->RadioButton1->setIcon(imageOp);
61   mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose);
62   mainFrame()->RadioButton2->close();
63   mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
64   mainFrame()->RadioButton3->close();
65
66   GroupPoints = new DlgRef_1Sel( centralWidget() );
67
68   GroupPoints->GroupBox1->setTitle( tr( "GEOM_SMOOTHINGSURFACE_ARG" ) );
69   GroupPoints->TextLabel1->setText( tr( "GEOM_SMOOTHINGSURFACE_ARG_POINTS" ) );
70   GroupPoints->PushButton1->setIcon( image1 );
71   GroupPoints->LineEdit1->setReadOnly( true );
72
73   QLabel *aNbMax  = new QLabel(tr("GEOM_SMOOTHINGSURFACE_ARG_NB_MAX"));
74   QLabel *aDegMax = new QLabel(tr("GEOM_SMOOTHINGSURFACE_ARG_DEG_MAX"));
75   QLabel *aDMax   = new QLabel(tr("GEOM_SMOOTHINGSURFACE_ARG_D_MAX"));
76
77   myNbMaxSpin  = new SalomeApp_IntSpinBox(0, 1000, 1, 0, true, true);
78   myDegMaxSpin = new SalomeApp_IntSpinBox(0, 1000, 1, 0, true, true);
79   myDMaxSpin   = new SalomeApp_DoubleSpinBox;
80   GroupPoints->gridLayout1->addWidget(aNbMax,       1, 0);
81   GroupPoints->gridLayout1->addWidget(aDegMax,      2, 0);
82   GroupPoints->gridLayout1->addWidget(aDMax,        3, 0);
83   GroupPoints->gridLayout1->addWidget(myNbMaxSpin,  1, 1, 1, 2);
84   GroupPoints->gridLayout1->addWidget(myDegMaxSpin, 2, 1, 1, 2);
85   GroupPoints->gridLayout1->addWidget(myDMaxSpin,   3, 1, 1, 2);
86
87   QVBoxLayout* layout = new QVBoxLayout(centralWidget());
88   layout->setMargin(0); layout->setSpacing(6);
89   layout->addWidget(GroupPoints);
90   /***************************************************************/
91
92   setHelpFileName("create_smoothingsurface_page.html");
93
94   Init();
95 }
96
97 //=================================================================================
98 // Destructor
99 //=================================================================================
100 AdvancedGUI_SmoothingSurfaceDlg::~AdvancedGUI_SmoothingSurfaceDlg()
101 {
102   // no need to delete child widgets, Qt does it all for us
103 }
104
105 //=================================================================================
106 // function : Init()
107 // purpose  :
108 //=================================================================================
109 void AdvancedGUI_SmoothingSurfaceDlg::Init()
110 {
111   // Get setting of step value from file configuration
112   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
113
114   initSpinBox(myDMaxSpin, 0., COORD_MAX, 0.00001, "parametric_precision" );
115
116   myNbMaxSpin->setValue(2);
117   myDegMaxSpin->setValue(8);
118   myDMaxSpin->setValue(0.);
119
120   showOnlyPreviewControl();
121
122   //@@ initialize dialog box widgets here @@//
123
124   // Signal/slot connections
125   connect(buttonOk(),    SIGNAL(clicked()), this, SLOT(ClickOnOk()));
126   connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
127   connect(myGeomGUI,     SIGNAL(SignalDefaultStepValueChanged(double)),
128           this,          SLOT(SetDoubleSpinBoxStep(double)));
129   connect( myGeomGUI->getApp()->selectionMgr(),
130            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
131   connect(myNbMaxSpin, SIGNAL(valueChanged(const QString&)),
132           this, SLOT(processPreview()) );
133   connect(myDegMaxSpin, SIGNAL(valueChanged(const QString&)),
134           this, SLOT(processPreview()) );
135   connect(myDMaxSpin, SIGNAL(valueChanged(const QString&)),
136           this, SLOT(processPreview()) );
137  
138   initName(tr("GEOM_SMOOTHINGSURFACE"));
139   //displayPreview();
140   SelectionIntoArgument();
141 }
142
143 //=================================================================================
144 // function : ClickOnOk()
145 // purpose  :
146 //=================================================================================
147 void AdvancedGUI_SmoothingSurfaceDlg::ClickOnOk()
148 {
149   if (ClickOnApply())
150     ClickOnCancel();
151 }
152
153 //=================================================================================
154 // function : ClickOnApply()
155 // purpose  :
156 //=================================================================================
157 bool AdvancedGUI_SmoothingSurfaceDlg::ClickOnApply()
158 {
159   if (!onAccept())
160     return false;
161
162   initName();
163
164   return true;
165 }
166
167 //=================================================================================
168 // function : ActivateThisDialog()
169 // purpose  :
170 //=================================================================================
171 void AdvancedGUI_SmoothingSurfaceDlg::ActivateThisDialog()
172 {
173   GEOMBase_Skeleton::ActivateThisDialog();
174   //displayPreview();
175 }
176
177 //=================================================================================
178 // function : enterEvent [REDEFINED]
179 // purpose  :
180 //=================================================================================
181 void AdvancedGUI_SmoothingSurfaceDlg::enterEvent (QEvent*)
182 {
183   if (!mainFrame()->GroupConstructors->isEnabled())
184     ActivateThisDialog();
185 }
186
187 //=================================================================================
188 // function : createOperation
189 // purpose  :
190 //=================================================================================
191 GEOM::GEOM_IOperations_ptr AdvancedGUI_SmoothingSurfaceDlg::createOperation()
192 {
193   return getGeomEngine()->GetPluginOperations(getStudyId(), "AdvancedEngine");
194 }
195
196 //=================================================================================
197 // function : isValid
198 // purpose  :
199 //=================================================================================
200 bool AdvancedGUI_SmoothingSurfaceDlg::isValid (QString& msg)
201 {
202   if (myPoints.empty()) {
203     msg += tr("GEOM_SMOOTHINGSURFACE_NO_POINTS");
204     return false;
205   }
206
207   bool ok = myNbMaxSpin->isValid (msg, !IsPreview()) &&
208             myDegMaxSpin->isValid(msg, !IsPreview()) &&
209             myDMaxSpin->isValid  (msg, !IsPreview());
210
211   return ok;
212 }
213
214 //=================================================================================
215 // function : execute
216 // purpose  :
217 //=================================================================================
218 bool AdvancedGUI_SmoothingSurfaceDlg::execute (ObjectList& objects)
219 {
220   bool res = false;
221
222   GEOM::GEOM_Object_var anObj;
223
224   GEOM::IAdvancedOperations_var anOper = GEOM::IAdvancedOperations::_narrow(getOperation());
225
226   //@@ retrieve input values from the widgets here @@//
227   GEOM::ListOfGO_var points = new GEOM::ListOfGO();
228   points->length( myPoints.count() );
229   for ( int i = 0; i < myPoints.count(); i++ )
230     points[i] = myPoints[i].copy();
231
232   const int    aNbMax  = myNbMaxSpin->value();
233   const int    aDegMax = myDegMaxSpin->value();
234   const double aDMax   = myDMaxSpin->value();
235
236   // call engine function
237   anObj = anOper->MakeSmoothingSurface(points, aNbMax, aDegMax, aDMax);
238   res = !anObj->_is_nil();
239   if (res && !IsPreview())
240   {
241     QStringList aParameters;
242     //@@ put stringified input parameters to the string list here to store in the data model for notebook @@//
243     if ( aParameters.count() > 0 ) anObj->SetParameters(aParameters.join(":").toLatin1().constData());
244   }
245   
246   if (res)
247     objects.push_back(anObj._retn());
248
249   return res;
250 }
251
252 //=================================================================================
253 // function : getNbPoints()
254 // purpose  : Returns the number of points in myPoints list.
255 //=================================================================================
256 int AdvancedGUI_SmoothingSurfaceDlg::getNbPoints() const
257 {
258   TopTools_IndexedMapOfShape aMap;
259
260   foreach (GEOM::GeomObjPtr anObj, myPoints) {
261     TopoDS_Shape aShape;
262
263     if(anObj && GEOMBase::GetShape(anObj.get(), aShape) && !aShape.IsNull()) {
264       if (aShape.ShapeType() == TopAbs_VERTEX) {
265         aMap.Add(aShape);
266       } else {
267         // Compound.
268         TopExp::MapShapes(aShape, TopAbs_VERTEX, aMap);
269       }
270     }
271   }
272
273   const int aNbPoints = aMap.Extent();
274
275   return aNbPoints;
276 }
277
278 //=================================================================================
279 // function : SelectionIntoArgument()
280 // purpose  : Called when selection as changed or other case
281 //=================================================================================
282 void AdvancedGUI_SmoothingSurfaceDlg::SelectionIntoArgument()
283 {
284   QList<TopAbs_ShapeEnum> aTypes;
285
286   aTypes << TopAbs_VERTEX << TopAbs_COMPOUND;
287
288   QList<GEOM::GeomObjPtr> points = getSelected( aTypes, -1 );
289
290   // Check the selected compounds if they consist of points only.
291   foreach (GEOM::GeomObjPtr anObj, points) {
292     TopoDS_Shape aShape;
293
294     if(anObj && GEOMBase::GetShape(anObj.get(), aShape) && !aShape.IsNull()) {
295       if (aShape.ShapeType() == TopAbs_COMPOUND) {
296         // Check if the compound contains vertices only.
297         TopoDS_Iterator anIter(aShape);
298         Standard_Boolean isValid = Standard_False;
299
300         for (; anIter.More(); anIter.Next()) {
301           const TopoDS_Shape &aSubShape = anIter.Value();
302
303           if (aSubShape.ShapeType() == TopAbs_VERTEX) {
304             isValid = Standard_True;
305           } else {
306             isValid = Standard_False;
307             break;
308           }
309         }
310
311         if (!isValid) {
312           points.clear();
313           break;
314         }
315       }
316     } else {
317       // NEVERREACHED
318       points.clear();
319       break;
320     }
321   }
322
323   GEOMBase::Synchronize( myPoints, points );
324   if ( !myPoints.isEmpty()  )
325     GroupPoints->LineEdit1->setText( QString::number( getNbPoints() ) + "_" + tr( "GEOM_POINT" ) + tr( "_S_" ) );
326   else
327     GroupPoints->LineEdit1->setText( "" );
328   processPreview();
329 }
330
331 //=================================================================================
332 // function : SetEditCurrentArgument()
333 // purpose  :
334 //=================================================================================
335 void AdvancedGUI_SmoothingSurfaceDlg::SetEditCurrentArgument()
336 {
337   if ( sender() == GroupPoints->PushButton1 )
338     myEditCurrentArgument = GroupPoints->LineEdit1;
339   myEditCurrentArgument->setFocus();
340   SelectionIntoArgument();
341 }