1 // Copyright (C) 2013-2021 CEA/DEN, EDF R&D, OPEN CASCADE
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "AdvancedGUI_SmoothingSurfaceDlg.h"
22 #include <SALOMEconfig.h>
23 #include CORBA_SERVER_HEADER(AdvancedGEOM)
26 #include <GeometryGUI.h>
29 #include <SUIT_Session.h>
30 #include <SUIT_ResourceMgr.h>
31 #include <SalomeApp_Application.h>
32 #include <LightApp_SelectionMgr.h>
35 #include <TopoDS_Shape.hxx>
37 #include <TopoDS_Iterator.hxx>
39 #include <TopTools_IndexedMapOfShape.hxx>
41 #include <GEOMImpl_Types.hxx>
43 //=================================================================================
45 //=================================================================================
46 AdvancedGUI_SmoothingSurfaceDlg::AdvancedGUI_SmoothingSurfaceDlg (GeometryGUI* theGeometryGUI, QWidget* parent)
47 : GEOMBase_Skeleton(theGeometryGUI, parent, false),
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" ) ) );
56 setWindowTitle(tr("GEOM_SMOOTHINGSURFACE_TITLE"));
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();
66 GroupPoints = new DlgRef_1Sel( centralWidget() );
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 );
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"));
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);
87 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
88 layout->setMargin(0); layout->setSpacing(6);
89 layout->addWidget(GroupPoints);
90 /***************************************************************/
92 setHelpFileName("create_smoothingsurface_page.html");
97 //=================================================================================
99 //=================================================================================
100 AdvancedGUI_SmoothingSurfaceDlg::~AdvancedGUI_SmoothingSurfaceDlg()
102 // no need to delete child widgets, Qt does it all for us
105 //=================================================================================
108 //=================================================================================
109 void AdvancedGUI_SmoothingSurfaceDlg::Init()
111 // Get setting of step value from file configuration
112 //SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
114 initSpinBox(myDMaxSpin, 0., COORD_MAX, 0.00001, "parametric_precision" );
116 myNbMaxSpin->setValue(2);
117 myDegMaxSpin->setValue(8);
118 myDMaxSpin->setValue(0.);
120 showOnlyPreviewControl();
123 localSelection( TopAbs_VERTEX );
124 //@@ initialize dialog box widgets here @@//
126 // Signal/slot connections
127 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
128 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
129 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)),
130 this, SLOT(SetDoubleSpinBoxStep(double)));
131 connect( myGeomGUI->getApp()->selectionMgr(),
132 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
133 connect(myNbMaxSpin, SIGNAL(valueChanged(const QString&)),
134 this, SLOT(processPreview()) );
135 connect(myDegMaxSpin, SIGNAL(valueChanged(const QString&)),
136 this, SLOT(processPreview()) );
137 connect(myDMaxSpin, SIGNAL(valueChanged(const QString&)),
138 this, SLOT(processPreview()) );
140 initName(tr("GEOM_SMOOTHINGSURFACE"));
142 SelectionIntoArgument();
145 //=================================================================================
146 // function : ClickOnOk()
148 //=================================================================================
149 void AdvancedGUI_SmoothingSurfaceDlg::ClickOnOk()
155 //=================================================================================
156 // function : ClickOnApply()
158 //=================================================================================
159 bool AdvancedGUI_SmoothingSurfaceDlg::ClickOnApply()
166 localSelection( TopAbs_VERTEX );
170 //=================================================================================
171 // function : ActivateThisDialog()
173 //=================================================================================
174 void AdvancedGUI_SmoothingSurfaceDlg::ActivateThisDialog()
176 GEOMBase_Skeleton::ActivateThisDialog();
178 localSelection( TopAbs_VERTEX );
182 //=================================================================================
183 // function : enterEvent [REDEFINED]
185 //=================================================================================
186 void AdvancedGUI_SmoothingSurfaceDlg::enterEvent (QEvent*)
188 if (!mainFrame()->GroupConstructors->isEnabled())
189 ActivateThisDialog();
192 //=================================================================================
193 // function : createOperation
195 //=================================================================================
196 GEOM::GEOM_IOperations_ptr AdvancedGUI_SmoothingSurfaceDlg::createOperation()
198 return getGeomEngine()->GetPluginOperations("AdvancedEngine");
201 //=================================================================================
202 // function : isValid
204 //=================================================================================
205 bool AdvancedGUI_SmoothingSurfaceDlg::isValid (QString& msg)
207 if (myPoints.empty()) {
208 msg += tr("GEOM_SMOOTHINGSURFACE_NO_POINTS");
212 bool ok = myNbMaxSpin->isValid (msg, !IsPreview()) &&
213 myDegMaxSpin->isValid(msg, !IsPreview()) &&
214 myDMaxSpin->isValid (msg, !IsPreview());
219 //=================================================================================
220 // function : execute
222 //=================================================================================
223 bool AdvancedGUI_SmoothingSurfaceDlg::execute (ObjectList& objects)
227 GEOM::GEOM_Object_var anObj;
229 GEOM::IAdvancedOperations_var anOper = GEOM::IAdvancedOperations::_narrow(getOperation());
231 //@@ retrieve input values from the widgets here @@//
232 GEOM::ListOfGO_var points = new GEOM::ListOfGO();
233 points->length( myPoints.count() );
234 for ( int i = 0; i < myPoints.count(); i++ )
235 points[i] = myPoints[i].copy();
237 const int aNbMax = myNbMaxSpin->value();
238 const int aDegMax = myDegMaxSpin->value();
239 const double aDMax = myDMaxSpin->value();
241 // call engine function
242 anObj = anOper->MakeSmoothingSurface(points, aNbMax, aDegMax, aDMax);
243 res = !anObj->_is_nil();
244 if (res && !IsPreview())
246 QStringList aParameters;
247 //@@ put stringified input parameters to the string list here to store in the data model for notebook @@//
248 if ( aParameters.count() > 0 ) anObj->SetParameters(aParameters.join(":").toUtf8().constData());
252 objects.push_back(anObj._retn());
257 //=================================================================================
258 // function : addSubshapesToStudy
259 // purpose : virtual method to add new SubObjects if local selection
260 //=================================================================================
261 void AdvancedGUI_SmoothingSurfaceDlg::addSubshapesToStudy()
263 for ( int i = 0; i < myPoints.count(); i++ )
264 GEOMBase::PublishSubObject( myPoints[i].get() );
268 //=================================================================================
269 // function : getSourceObjects
270 // purpose : virtual method to get source objects
271 //=================================================================================
272 QList<GEOM::GeomObjPtr> AdvancedGUI_SmoothingSurfaceDlg::getSourceObjects()
277 //=================================================================================
278 // function : getNbPoints()
279 // purpose : Returns the number of points in myPoints list.
280 //=================================================================================
281 int AdvancedGUI_SmoothingSurfaceDlg::getNbPoints() const
283 TopTools_IndexedMapOfShape aMap;
285 foreach (GEOM::GeomObjPtr anObj, myPoints) {
288 if(anObj && GEOMBase::GetShape(anObj.get(), aShape) && !aShape.IsNull()) {
289 if (aShape.ShapeType() == TopAbs_VERTEX) {
293 TopExp::MapShapes(aShape, TopAbs_VERTEX, aMap);
298 const int aNbPoints = aMap.Extent();
303 //=================================================================================
304 // function : SelectionIntoArgument()
305 // purpose : Called when selection as changed or other case
306 //=================================================================================
307 void AdvancedGUI_SmoothingSurfaceDlg::SelectionIntoArgument()
309 QList<TopAbs_ShapeEnum> aTypes;
311 aTypes << TopAbs_VERTEX << TopAbs_COMPOUND;
313 QList<GEOM::GeomObjPtr> points = getSelected( aTypes, -1 );
315 // Check the selected compounds if they consist of points only.
316 foreach (GEOM::GeomObjPtr anObj, points) {
319 if(anObj && GEOMBase::GetShape(anObj.get(), aShape) && !aShape.IsNull()) {
320 if (aShape.ShapeType() == TopAbs_COMPOUND) {
321 // Check if the compound contains vertices only.
322 TopoDS_Iterator anIter(aShape);
323 Standard_Boolean isValid = Standard_False;
325 for (; anIter.More(); anIter.Next()) {
326 const TopoDS_Shape &aSubShape = anIter.Value();
328 if (aSubShape.ShapeType() == TopAbs_VERTEX) {
329 isValid = Standard_True;
331 isValid = Standard_False;
348 GEOMBase::Synchronize( myPoints, points );
349 if ( !myPoints.isEmpty() )
350 GroupPoints->LineEdit1->setText( QString::number( getNbPoints() ) + "_" + tr( "GEOM_POINT" ) + tr( "_S_" ) );
352 GroupPoints->LineEdit1->setText( "" );
356 //=================================================================================
357 // function : SetEditCurrentArgument()
359 //=================================================================================
360 void AdvancedGUI_SmoothingSurfaceDlg::SetEditCurrentArgument()
362 if ( sender() == GroupPoints->PushButton1 )
363 myEditCurrentArgument = GroupPoints->LineEdit1;
364 myEditCurrentArgument->setFocus();
366 localSelection( TopAbs_VERTEX );
367 SelectionIntoArgument();