1 // Copyright (C) 2013-2014 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"
23 #include <GeometryGUI.h>
26 #include <SUIT_Session.h>
27 #include <SUIT_ResourceMgr.h>
28 #include <SalomeApp_Application.h>
29 #include <LightApp_SelectionMgr.h>
32 #include <TopoDS_Shape.hxx>
34 #include <TopoDS_Iterator.hxx>
36 #include <TColStd_IndexedMapOfInteger.hxx>
37 #include <TopTools_IndexedMapOfShape.hxx>
39 #include <GEOMImpl_Types.hxx>
41 //=================================================================================
43 //=================================================================================
44 AdvancedGUI_SmoothingSurfaceDlg::AdvancedGUI_SmoothingSurfaceDlg (GeometryGUI* theGeometryGUI, QWidget* parent)
45 : GEOMBase_Skeleton(theGeometryGUI, parent, false),
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" ) ) );
54 setWindowTitle(tr("GEOM_SMOOTHINGSURFACE_TITLE"));
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();
64 GroupPoints = new DlgRef_1Sel( centralWidget() );
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 );
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"));
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);
85 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
86 layout->setMargin(0); layout->setSpacing(6);
87 layout->addWidget(GroupPoints);
88 /***************************************************************/
90 setHelpFileName("create_smoothingsurface_page.html");
95 //=================================================================================
97 //=================================================================================
98 AdvancedGUI_SmoothingSurfaceDlg::~AdvancedGUI_SmoothingSurfaceDlg()
100 // no need to delete child widgets, Qt does it all for us
103 //=================================================================================
106 //=================================================================================
107 void AdvancedGUI_SmoothingSurfaceDlg::Init()
109 // Get setting of step value from file configuration
110 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
112 initSpinBox(myDMaxSpin, 0., COORD_MAX, 0.00001, "parametric_precision" );
114 myNbMaxSpin->setValue(2);
115 myDegMaxSpin->setValue(8);
116 myDMaxSpin->setValue(0.);
118 showOnlyPreviewControl();
120 //@@ initialize dialog box widgets here @@//
122 // Signal/slot connections
123 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
124 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
125 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)),
126 this, SLOT(SetDoubleSpinBoxStep(double)));
127 connect( myGeomGUI->getApp()->selectionMgr(),
128 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
129 connect(myNbMaxSpin, SIGNAL(valueChanged(const QString&)),
130 this, SLOT(processPreview()) );
131 connect(myDegMaxSpin, SIGNAL(valueChanged(const QString&)),
132 this, SLOT(processPreview()) );
133 connect(myDMaxSpin, SIGNAL(valueChanged(const QString&)),
134 this, SLOT(processPreview()) );
136 initName(tr("GEOM_SMOOTHINGSURFACE"));
138 SelectionIntoArgument();
141 //=================================================================================
142 // function : ClickOnOk()
144 //=================================================================================
145 void AdvancedGUI_SmoothingSurfaceDlg::ClickOnOk()
151 //=================================================================================
152 // function : ClickOnApply()
154 //=================================================================================
155 bool AdvancedGUI_SmoothingSurfaceDlg::ClickOnApply()
165 //=================================================================================
166 // function : ActivateThisDialog()
168 //=================================================================================
169 void AdvancedGUI_SmoothingSurfaceDlg::ActivateThisDialog()
171 GEOMBase_Skeleton::ActivateThisDialog();
175 //=================================================================================
176 // function : enterEvent [REDEFINED]
178 //=================================================================================
179 void AdvancedGUI_SmoothingSurfaceDlg::enterEvent (QEvent*)
181 if (!mainFrame()->GroupConstructors->isEnabled())
182 ActivateThisDialog();
185 //=================================================================================
186 // function : createOperation
188 //=================================================================================
189 GEOM::GEOM_IOperations_ptr AdvancedGUI_SmoothingSurfaceDlg::createOperation()
191 //return getGeomEngine()->GetIAdvancedOperations(getStudyId());
192 return getGeomEngine()->GetPluginOperations(getStudyId(), "AdvancedEngine");
195 //=================================================================================
196 // function : isValid
198 //=================================================================================
199 bool AdvancedGUI_SmoothingSurfaceDlg::isValid (QString& msg)
201 if (myPoints.empty()) {
202 msg += tr("GEOM_SMOOTHINGSURFACE_NO_POINTS");
206 bool ok = myNbMaxSpin->isValid (msg, !IsPreview()) &&
207 myDegMaxSpin->isValid(msg, !IsPreview()) &&
208 myDMaxSpin->isValid (msg, !IsPreview());
213 //=================================================================================
214 // function : execute
216 //=================================================================================
217 bool AdvancedGUI_SmoothingSurfaceDlg::execute (ObjectList& objects)
221 GEOM::GEOM_Object_var anObj;
223 GEOM::GEOM_IAdvancedOperations_var anOper = GEOM::GEOM_IAdvancedOperations::_narrow(getOperation());
225 //@@ retrieve input values from the widgets here @@//
226 GEOM::ListOfGO_var points = new GEOM::ListOfGO();
227 points->length( myPoints.count() );
228 for ( int i = 0; i < myPoints.count(); i++ )
229 points[i] = myPoints[i].copy();
231 const int aNbMax = myNbMaxSpin->value();
232 const int aDegMax = myDegMaxSpin->value();
233 const double aDMax = myDMaxSpin->value();
235 // call engine function
236 anObj = anOper->MakeSmoothingSurface(points, aNbMax, aDegMax, aDMax);
237 res = !anObj->_is_nil();
238 if (res && !IsPreview())
240 QStringList aParameters;
241 //@@ put stringified input parameters to the string list here to store in the data model for notebook @@//
242 if ( aParameters.count() > 0 ) anObj->SetParameters(aParameters.join(":").toLatin1().constData());
246 objects.push_back(anObj._retn());
251 //=================================================================================
252 // function : getNbPoints()
253 // purpose : Returns the number of points in myPoints list.
254 //=================================================================================
255 int AdvancedGUI_SmoothingSurfaceDlg::getNbPoints() const
257 TopTools_IndexedMapOfShape aMap;
259 foreach (GEOM::GeomObjPtr anObj, myPoints) {
262 if(anObj && GEOMBase::GetShape(anObj.get(), aShape) && !aShape.IsNull()) {
263 if (aShape.ShapeType() == TopAbs_VERTEX) {
267 TopExp::MapShapes(aShape, TopAbs_VERTEX, aMap);
272 const int aNbPoints = aMap.Extent();
277 //=================================================================================
278 // function : SelectionIntoArgument()
279 // purpose : Called when selection as changed or other case
280 //=================================================================================
281 void AdvancedGUI_SmoothingSurfaceDlg::SelectionIntoArgument()
283 QList<TopAbs_ShapeEnum> aTypes;
285 aTypes << TopAbs_VERTEX << TopAbs_COMPOUND;
287 QList<GEOM::GeomObjPtr> points = getSelected( aTypes, -1 );
289 // Check the selected compounds if they consist of points only.
290 foreach (GEOM::GeomObjPtr anObj, points) {
293 if(anObj && GEOMBase::GetShape(anObj.get(), aShape) && !aShape.IsNull()) {
294 if (aShape.ShapeType() == TopAbs_COMPOUND) {
295 // Check if the compound contains vertices only.
296 TopoDS_Iterator anIter(aShape);
297 Standard_Boolean isValid = Standard_False;
299 for (; anIter.More(); anIter.Next()) {
300 const TopoDS_Shape &aSubShape = anIter.Value();
302 if (aSubShape.ShapeType() == TopAbs_VERTEX) {
303 isValid = Standard_True;
305 isValid = Standard_False;
322 GEOMBase::Synchronize( myPoints, points );
323 if ( !myPoints.isEmpty() )
324 GroupPoints->LineEdit1->setText( QString::number( getNbPoints() ) + "_" + tr( "GEOM_POINT" ) + tr( "_S_" ) );
326 GroupPoints->LineEdit1->setText( "" );
330 //=================================================================================
331 // function : SetEditCurrentArgument()
333 //=================================================================================
334 void AdvancedGUI_SmoothingSurfaceDlg::SetEditCurrentArgument()
336 if ( sender() == GroupPoints->PushButton1 )
337 myEditCurrentArgument = GroupPoints->LineEdit1;
338 myEditCurrentArgument->setFocus();
339 SelectionIntoArgument();