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"
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();
122 //@@ initialize dialog box widgets here @@//
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()) );
138 initName(tr("GEOM_SMOOTHINGSURFACE"));
140 SelectionIntoArgument();
143 //=================================================================================
144 // function : ClickOnOk()
146 //=================================================================================
147 void AdvancedGUI_SmoothingSurfaceDlg::ClickOnOk()
153 //=================================================================================
154 // function : ClickOnApply()
156 //=================================================================================
157 bool AdvancedGUI_SmoothingSurfaceDlg::ClickOnApply()
167 //=================================================================================
168 // function : ActivateThisDialog()
170 //=================================================================================
171 void AdvancedGUI_SmoothingSurfaceDlg::ActivateThisDialog()
173 GEOMBase_Skeleton::ActivateThisDialog();
177 //=================================================================================
178 // function : enterEvent [REDEFINED]
180 //=================================================================================
181 void AdvancedGUI_SmoothingSurfaceDlg::enterEvent (QEvent*)
183 if (!mainFrame()->GroupConstructors->isEnabled())
184 ActivateThisDialog();
187 //=================================================================================
188 // function : createOperation
190 //=================================================================================
191 GEOM::GEOM_IOperations_ptr AdvancedGUI_SmoothingSurfaceDlg::createOperation()
193 return getGeomEngine()->GetPluginOperations(getStudyId(), "AdvancedEngine");
196 //=================================================================================
197 // function : isValid
199 //=================================================================================
200 bool AdvancedGUI_SmoothingSurfaceDlg::isValid (QString& msg)
202 if (myPoints.empty()) {
203 msg += tr("GEOM_SMOOTHINGSURFACE_NO_POINTS");
207 bool ok = myNbMaxSpin->isValid (msg, !IsPreview()) &&
208 myDegMaxSpin->isValid(msg, !IsPreview()) &&
209 myDMaxSpin->isValid (msg, !IsPreview());
214 //=================================================================================
215 // function : execute
217 //=================================================================================
218 bool AdvancedGUI_SmoothingSurfaceDlg::execute (ObjectList& objects)
222 GEOM::GEOM_Object_var anObj;
224 GEOM::IAdvancedOperations_var anOper = GEOM::IAdvancedOperations::_narrow(getOperation());
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();
232 const int aNbMax = myNbMaxSpin->value();
233 const int aDegMax = myDegMaxSpin->value();
234 const double aDMax = myDMaxSpin->value();
236 // call engine function
237 anObj = anOper->MakeSmoothingSurface(points, aNbMax, aDegMax, aDMax);
238 res = !anObj->_is_nil();
239 if (res && !IsPreview())
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());
247 objects.push_back(anObj._retn());
252 //=================================================================================
253 // function : getNbPoints()
254 // purpose : Returns the number of points in myPoints list.
255 //=================================================================================
256 int AdvancedGUI_SmoothingSurfaceDlg::getNbPoints() const
258 TopTools_IndexedMapOfShape aMap;
260 foreach (GEOM::GeomObjPtr anObj, myPoints) {
263 if(anObj && GEOMBase::GetShape(anObj.get(), aShape) && !aShape.IsNull()) {
264 if (aShape.ShapeType() == TopAbs_VERTEX) {
268 TopExp::MapShapes(aShape, TopAbs_VERTEX, aMap);
273 const int aNbPoints = aMap.Extent();
278 //=================================================================================
279 // function : SelectionIntoArgument()
280 // purpose : Called when selection as changed or other case
281 //=================================================================================
282 void AdvancedGUI_SmoothingSurfaceDlg::SelectionIntoArgument()
284 QList<TopAbs_ShapeEnum> aTypes;
286 aTypes << TopAbs_VERTEX << TopAbs_COMPOUND;
288 QList<GEOM::GeomObjPtr> points = getSelected( aTypes, -1 );
290 // Check the selected compounds if they consist of points only.
291 foreach (GEOM::GeomObjPtr anObj, points) {
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;
300 for (; anIter.More(); anIter.Next()) {
301 const TopoDS_Shape &aSubShape = anIter.Value();
303 if (aSubShape.ShapeType() == TopAbs_VERTEX) {
304 isValid = Standard_True;
306 isValid = Standard_False;
323 GEOMBase::Synchronize( myPoints, points );
324 if ( !myPoints.isEmpty() )
325 GroupPoints->LineEdit1->setText( QString::number( getNbPoints() ) + "_" + tr( "GEOM_POINT" ) + tr( "_S_" ) );
327 GroupPoints->LineEdit1->setText( "" );
331 //=================================================================================
332 // function : SetEditCurrentArgument()
334 //=================================================================================
335 void AdvancedGUI_SmoothingSurfaceDlg::SetEditCurrentArgument()
337 if ( sender() == GroupPoints->PushButton1 )
338 myEditCurrentArgument = GroupPoints->LineEdit1;
339 myEditCurrentArgument->setFocus();
340 SelectionIntoArgument();