]> SALOME platform Git repositories - modules/geom.git/blob - src/AdvancedGUI/AdvancedGUI_SmoothingSurfaceDlg.cxx
Salome HOME
Mantis issue 0022227: Integration request: Building a surface from a cloud of points
[modules/geom.git] / src / AdvancedGUI / AdvancedGUI_SmoothingSurfaceDlg.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21
22 #include "AdvancedGUI_SmoothingSurfaceDlg.h"
23
24 #include <DlgRef.h>
25 #include <GeometryGUI.h>
26 #include <GEOMBase.h>
27
28 #include <SUIT_Session.h>
29 #include <SUIT_ResourceMgr.h>
30 #include <SalomeApp_Application.h>
31 #include <LightApp_SelectionMgr.h>
32
33 // OCCT Includes
34 #include <TopoDS_Shape.hxx>
35 #include <TopoDS.hxx>
36 #include <TopExp.hxx>
37 #include <TColStd_IndexedMapOfInteger.hxx>
38 #include <TopTools_IndexedMapOfShape.hxx>
39
40 #include <GEOMImpl_Types.hxx>
41
42 //=================================================================================
43 // Constructor
44 //=================================================================================
45 AdvancedGUI_SmoothingSurfaceDlg::AdvancedGUI_SmoothingSurfaceDlg (GeometryGUI* theGeometryGUI, QWidget* parent)
46   : GEOMBase_Skeleton(theGeometryGUI, parent, false)
47 {
48   QPixmap imageOp  (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_SMOOTHINGSURFACE_LPOINTS")));
49   QPixmap imageSel (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
50   QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
51
52   setWindowTitle(tr("GEOM_SMOOTHINGSURFACE_TITLE"));
53
54   /***************************************************************/
55   mainFrame()->GroupConstructors->setTitle(tr("GEOM_SMOOTHINGSURFACE"));
56   mainFrame()->RadioButton1->setIcon(imageOp);
57   mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose);
58   mainFrame()->RadioButton2->close();
59   mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
60   mainFrame()->RadioButton3->close();
61
62   GroupPoints = new DlgRef_1Sel( centralWidget() );
63
64   GroupPoints->GroupBox1->setTitle( tr( "GEOM_SMOOTHINGSURFACE_ARG" ) );
65   GroupPoints->TextLabel1->setText( tr( "GEOM_SMOOTHINGSURFACE_ARG_POINTS" ) );
66   GroupPoints->PushButton1->setIcon( image1 );
67   GroupPoints->LineEdit1->setReadOnly( true );
68
69   QVBoxLayout* layout = new QVBoxLayout(centralWidget());
70   layout->setMargin(0); layout->setSpacing(6);
71   layout->addWidget(GroupPoints);
72   /***************************************************************/
73
74   setHelpFileName("create_smoothingsurface_page.html");
75
76   Init();
77 }
78
79 //=================================================================================
80 // Destructor
81 //=================================================================================
82 AdvancedGUI_SmoothingSurfaceDlg::~AdvancedGUI_SmoothingSurfaceDlg()
83 {
84   // no need to delete child widgets, Qt does it all for us
85 }
86
87 //=================================================================================
88 // function : Init()
89 // purpose  :
90 //=================================================================================
91 void AdvancedGUI_SmoothingSurfaceDlg::Init()
92 {
93   // Get setting of step value from file configuration
94   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
95   double step = resMgr->doubleValue("Geometry", "SettingsGeomStep", 100);
96
97   //@@ initialize dialog box widgets here @@//
98
99   // Signal/slot connections
100   connect(buttonOk(),    SIGNAL(clicked()), this, SLOT(ClickOnOk()));
101   connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
102   connect(myGeomGUI,     SIGNAL(SignalDefaultStepValueChanged(double)),
103           this,          SLOT(SetDoubleSpinBoxStep(double)));
104   connect( myGeomGUI->getApp()->selectionMgr(),
105            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
106
107   initName(tr("GEOM_SMOOTHINGSURFACE"));
108   //displayPreview();
109 }
110
111 //=================================================================================
112 // function : ClickOnOk()
113 // purpose  :
114 //=================================================================================
115 void AdvancedGUI_SmoothingSurfaceDlg::ClickOnOk()
116 {
117   if (ClickOnApply())
118     ClickOnCancel();
119 }
120
121 //=================================================================================
122 // function : ClickOnApply()
123 // purpose  :
124 //=================================================================================
125 bool AdvancedGUI_SmoothingSurfaceDlg::ClickOnApply()
126 {
127   if (!onAccept())
128     return false;
129
130   initName();
131
132   return true;
133 }
134
135 //=================================================================================
136 // function : ActivateThisDialog()
137 // purpose  :
138 //=================================================================================
139 void AdvancedGUI_SmoothingSurfaceDlg::ActivateThisDialog()
140 {
141   GEOMBase_Skeleton::ActivateThisDialog();
142   //displayPreview();
143 }
144
145 //=================================================================================
146 // function : enterEvent [REDEFINED]
147 // purpose  :
148 //=================================================================================
149 void AdvancedGUI_SmoothingSurfaceDlg::enterEvent (QEvent*)
150 {
151   if (!mainFrame()->GroupConstructors->isEnabled())
152     ActivateThisDialog();
153 }
154
155 //=================================================================================
156 // function : createOperation
157 // purpose  :
158 //=================================================================================
159 GEOM::GEOM_IOperations_ptr AdvancedGUI_SmoothingSurfaceDlg::createOperation()
160 {
161   return getGeomEngine()->GetIAdvancedOperations(getStudyId());
162 }
163
164 //=================================================================================
165 // function : isValid
166 // purpose  :
167 //=================================================================================
168 bool AdvancedGUI_SmoothingSurfaceDlg::isValid (QString& msg)
169 {
170   bool ok = true;
171
172   //@@ add custom validation actions here @@//
173
174   return ok;
175 }
176
177 //=================================================================================
178 // function : execute
179 // purpose  :
180 //=================================================================================
181 bool AdvancedGUI_SmoothingSurfaceDlg::execute (ObjectList& objects)
182 {
183   bool res = false;
184
185   GEOM::GEOM_Object_var anObj;
186
187   GEOM::GEOM_IAdvancedOperations_var anOper = GEOM::GEOM_IAdvancedOperations::_narrow(getOperation());
188
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();
194
195
196   // call engine function
197   anObj = anOper->MakeSmoothingSurface(points);
198   res = !anObj->_is_nil();
199   if (res && !IsPreview())
200   {
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());
204   }
205   
206   if (res)
207     objects.push_back(anObj._retn());
208
209   return res;
210 }
211
212 //=================================================================================
213 // function : SelectionIntoArgument()
214 // purpose  : Called when selection as changed or other case
215 //=================================================================================
216 void AdvancedGUI_SmoothingSurfaceDlg::SelectionIntoArgument()
217 {
218   QList<GEOM::GeomObjPtr> points = getSelected( TopAbs_VERTEX, -1 );
219   synchronize( myPoints, points );
220   if ( !myPoints.isEmpty()  )
221     GroupPoints->LineEdit1->setText( QString::number( myPoints.count() ) + "_" + tr( "GEOM_POINT" ) + tr( "_S_" ) );
222   else
223     GroupPoints->LineEdit1->setText( "" );
224   processPreview();
225 }
226
227 //=================================================================================
228 // function : SetEditCurrentArgument()
229 // purpose  :
230 //=================================================================================
231 void AdvancedGUI_SmoothingSurfaceDlg::SetEditCurrentArgument()
232 {
233   if ( sender() == GroupPoints->PushButton1 )
234     myEditCurrentArgument = GroupPoints->LineEdit1;
235   myEditCurrentArgument->setFocus();
236   SelectionIntoArgument();
237 }
238
239 void AdvancedGUI_SmoothingSurfaceDlg::synchronize( QList<GEOM::GeomObjPtr>& left, QList<GEOM::GeomObjPtr>& right )
240 {
241   // 1. remove items from the "left" list that are not in the "right" list
242   QMutableListIterator<GEOM::GeomObjPtr> it1( left );
243   while ( it1.hasNext() ) {
244     GEOM::GeomObjPtr o1 = it1.next();
245     bool found = false;
246     QMutableListIterator<GEOM::GeomObjPtr> it2( right );
247     while ( it2.hasNext() && !found )
248       found = o1 == it2.next();
249     if ( !found )
250       it1.remove();
251   }
252   // 2. add items from the "right" list that are not in the "left" list (to keep selection order)
253   it1 = right;
254   while ( it1.hasNext() ) {
255     GEOM::GeomObjPtr o1 = it1.next();
256     bool found = false;
257     QMutableListIterator<GEOM::GeomObjPtr> it2( left );
258     while ( it2.hasNext() && !found )
259       found = o1 == it2.next();
260     if ( !found )
261       left << o1;
262   }
263 }
264