Salome HOME
0022289: EDF 2623 GEOM: Make "MakePipeWithDifferentsSections" available from GUI...
[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   return getGeomEngine()->GetPluginOperations(getStudyId(), "AdvancedEngine");
163 }
164
165 //=================================================================================
166 // function : isValid
167 // purpose  :
168 //=================================================================================
169 bool AdvancedGUI_SmoothingSurfaceDlg::isValid (QString& msg)
170 {
171   bool ok = true;
172
173   //@@ add custom validation actions here @@//
174
175   return ok;
176 }
177
178 //=================================================================================
179 // function : execute
180 // purpose  :
181 //=================================================================================
182 bool AdvancedGUI_SmoothingSurfaceDlg::execute (ObjectList& objects)
183 {
184   bool res = false;
185
186   GEOM::GEOM_Object_var anObj;
187
188   GEOM::GEOM_IAdvancedOperations_var anOper = GEOM::GEOM_IAdvancedOperations::_narrow(getOperation());
189
190   //@@ retrieve input values from the widgets here @@//
191   GEOM::ListOfGO_var points = new GEOM::ListOfGO();
192   points->length( myPoints.count() );
193   for ( int i = 0; i < myPoints.count(); i++ )
194     points[i] = myPoints[i].copy();
195
196
197   // call engine function
198   anObj = anOper->MakeSmoothingSurface(points);
199   res = !anObj->_is_nil();
200   if (res && !IsPreview())
201   {
202     QStringList aParameters;
203     //@@ put stringified input parameters to the string list here to store in the data model for notebook @@//
204     if ( aParameters.count() > 0 ) anObj->SetParameters(aParameters.join(":").toLatin1().constData());
205   }
206   
207   if (res)
208     objects.push_back(anObj._retn());
209
210   return res;
211 }
212
213 //=================================================================================
214 // function : SelectionIntoArgument()
215 // purpose  : Called when selection as changed or other case
216 //=================================================================================
217 void AdvancedGUI_SmoothingSurfaceDlg::SelectionIntoArgument()
218 {
219   QList<GEOM::GeomObjPtr> points = getSelected( TopAbs_VERTEX, -1 );
220   GEOMBase::Synchronize( myPoints, points );
221   if ( !myPoints.isEmpty()  )
222     GroupPoints->LineEdit1->setText( QString::number( myPoints.count() ) + "_" + tr( "GEOM_POINT" ) + tr( "_S_" ) );
223   else
224     GroupPoints->LineEdit1->setText( "" );
225   processPreview();
226 }
227
228 //=================================================================================
229 // function : SetEditCurrentArgument()
230 // purpose  :
231 //=================================================================================
232 void AdvancedGUI_SmoothingSurfaceDlg::SetEditCurrentArgument()
233 {
234   if ( sender() == GroupPoints->PushButton1 )
235     myEditCurrentArgument = GroupPoints->LineEdit1;
236   myEditCurrentArgument->setFocus();
237   SelectionIntoArgument();
238 }