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)
47 QPixmap imageOp (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_SMOOTHINGSURFACE_LPOINTS")));
48 QPixmap imageSel (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
49 QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
51 setWindowTitle(tr("GEOM_SMOOTHINGSURFACE_TITLE"));
53 /***************************************************************/
54 mainFrame()->GroupConstructors->setTitle(tr("GEOM_SMOOTHINGSURFACE"));
55 mainFrame()->RadioButton1->setIcon(imageOp);
56 mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose);
57 mainFrame()->RadioButton2->close();
58 mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
59 mainFrame()->RadioButton3->close();
61 GroupPoints = new DlgRef_1Sel( centralWidget() );
63 GroupPoints->GroupBox1->setTitle( tr( "GEOM_SMOOTHINGSURFACE_ARG" ) );
64 GroupPoints->TextLabel1->setText( tr( "GEOM_SMOOTHINGSURFACE_ARG_POINTS" ) );
65 GroupPoints->PushButton1->setIcon( image1 );
66 GroupPoints->LineEdit1->setReadOnly( true );
68 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
69 layout->setMargin(0); layout->setSpacing(6);
70 layout->addWidget(GroupPoints);
71 /***************************************************************/
73 setHelpFileName("create_smoothingsurface_page.html");
78 //=================================================================================
80 //=================================================================================
81 AdvancedGUI_SmoothingSurfaceDlg::~AdvancedGUI_SmoothingSurfaceDlg()
83 // no need to delete child widgets, Qt does it all for us
86 //=================================================================================
89 //=================================================================================
90 void AdvancedGUI_SmoothingSurfaceDlg::Init()
92 // Get setting of step value from file configuration
93 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
94 double step = resMgr->doubleValue("Geometry", "SettingsGeomStep", 100);
96 //@@ initialize dialog box widgets here @@//
98 // Signal/slot connections
99 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
100 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
101 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)),
102 this, SLOT(SetDoubleSpinBoxStep(double)));
103 connect( myGeomGUI->getApp()->selectionMgr(),
104 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
106 initName(tr("GEOM_SMOOTHINGSURFACE"));
110 //=================================================================================
111 // function : ClickOnOk()
113 //=================================================================================
114 void AdvancedGUI_SmoothingSurfaceDlg::ClickOnOk()
120 //=================================================================================
121 // function : ClickOnApply()
123 //=================================================================================
124 bool AdvancedGUI_SmoothingSurfaceDlg::ClickOnApply()
134 //=================================================================================
135 // function : ActivateThisDialog()
137 //=================================================================================
138 void AdvancedGUI_SmoothingSurfaceDlg::ActivateThisDialog()
140 GEOMBase_Skeleton::ActivateThisDialog();
144 //=================================================================================
145 // function : enterEvent [REDEFINED]
147 //=================================================================================
148 void AdvancedGUI_SmoothingSurfaceDlg::enterEvent (QEvent*)
150 if (!mainFrame()->GroupConstructors->isEnabled())
151 ActivateThisDialog();
154 //=================================================================================
155 // function : createOperation
157 //=================================================================================
158 GEOM::GEOM_IOperations_ptr AdvancedGUI_SmoothingSurfaceDlg::createOperation()
160 //return getGeomEngine()->GetIAdvancedOperations(getStudyId());
161 return getGeomEngine()->GetPluginOperations(getStudyId(), "AdvancedEngine");
164 //=================================================================================
165 // function : isValid
167 //=================================================================================
168 bool AdvancedGUI_SmoothingSurfaceDlg::isValid (QString& msg)
172 //@@ add custom validation actions here @@//
177 //=================================================================================
178 // function : execute
180 //=================================================================================
181 bool AdvancedGUI_SmoothingSurfaceDlg::execute (ObjectList& objects)
185 GEOM::GEOM_Object_var anObj;
187 GEOM::GEOM_IAdvancedOperations_var anOper = GEOM::GEOM_IAdvancedOperations::_narrow(getOperation());
189 //@@ retrieve input values from the widgets here @@//
190 GEOM::ListOfGO_var points = new GEOM::ListOfGO();
191 points->length( myPoints.count() );
192 for ( int i = 0; i < myPoints.count(); i++ )
193 points[i] = myPoints[i].copy();
196 // call engine function
197 anObj = anOper->MakeSmoothingSurface(points);
198 res = !anObj->_is_nil();
199 if (res && !IsPreview())
201 QStringList aParameters;
202 //@@ put stringified input parameters to the string list here to store in the data model for notebook @@//
203 if ( aParameters.count() > 0 ) anObj->SetParameters(aParameters.join(":").toLatin1().constData());
207 objects.push_back(anObj._retn());
212 //=================================================================================
213 // function : getNbPoints()
214 // purpose : Returns the number of points in myPoints list.
215 //=================================================================================
216 int AdvancedGUI_SmoothingSurfaceDlg::getNbPoints() const
218 TopTools_IndexedMapOfShape aMap;
220 foreach (GEOM::GeomObjPtr anObj, myPoints) {
223 if(anObj && GEOMBase::GetShape(anObj.get(), aShape) && !aShape.IsNull()) {
224 if (aShape.ShapeType() == TopAbs_VERTEX) {
228 TopExp::MapShapes(aShape, TopAbs_VERTEX, aMap);
233 const int aNbPoints = aMap.Extent();
238 //=================================================================================
239 // function : SelectionIntoArgument()
240 // purpose : Called when selection as changed or other case
241 //=================================================================================
242 void AdvancedGUI_SmoothingSurfaceDlg::SelectionIntoArgument()
244 QList<TopAbs_ShapeEnum> aTypes;
246 aTypes << TopAbs_VERTEX << TopAbs_COMPOUND;
248 QList<GEOM::GeomObjPtr> points = getSelected( aTypes, -1 );
250 // Check the selected compounds if they consist of points only.
251 foreach (GEOM::GeomObjPtr anObj, points) {
254 if(anObj && GEOMBase::GetShape(anObj.get(), aShape) && !aShape.IsNull()) {
255 if (aShape.ShapeType() == TopAbs_COMPOUND) {
256 // Check if the compound contains vertices only.
257 TopoDS_Iterator anIter(aShape);
258 Standard_Boolean isValid = Standard_False;
260 for (; anIter.More(); anIter.Next()) {
261 const TopoDS_Shape &aSubShape = anIter.Value();
263 if (aSubShape.ShapeType() == TopAbs_VERTEX) {
264 isValid = Standard_True;
266 isValid = Standard_False;
283 GEOMBase::Synchronize( myPoints, points );
284 if ( !myPoints.isEmpty() )
285 GroupPoints->LineEdit1->setText( QString::number( getNbPoints() ) + "_" + tr( "GEOM_POINT" ) + tr( "_S_" ) );
287 GroupPoints->LineEdit1->setText( "" );
291 //=================================================================================
292 // function : SetEditCurrentArgument()
294 //=================================================================================
295 void AdvancedGUI_SmoothingSurfaceDlg::SetEditCurrentArgument()
297 if ( sender() == GroupPoints->PushButton1 )
298 myEditCurrentArgument = GroupPoints->LineEdit1;
299 myEditCurrentArgument->setFocus();
300 SelectionIntoArgument();