]> SALOME platform Git repositories - modules/geom.git/blob - src/AdvancedGUI/AdvancedGUI_SmoothingSurfaceDlg.cxx
Salome HOME
Update copyrights 2014.
[modules/geom.git] / src / AdvancedGUI / AdvancedGUI_SmoothingSurfaceDlg.cxx
1 // Copyright (C) 2013-2014  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "AdvancedGUI_SmoothingSurfaceDlg.h"
21
22 #include <DlgRef.h>
23 #include <GeometryGUI.h>
24 #include <GEOMBase.h>
25
26 #include <SUIT_Session.h>
27 #include <SUIT_ResourceMgr.h>
28 #include <SalomeApp_Application.h>
29 #include <LightApp_SelectionMgr.h>
30
31 // OCCT Includes
32 #include <TopoDS_Shape.hxx>
33 #include <TopoDS.hxx>
34 #include <TopExp.hxx>
35 #include <TColStd_IndexedMapOfInteger.hxx>
36 #include <TopTools_IndexedMapOfShape.hxx>
37
38 #include <GEOMImpl_Types.hxx>
39
40 //=================================================================================
41 // Constructor
42 //=================================================================================
43 AdvancedGUI_SmoothingSurfaceDlg::AdvancedGUI_SmoothingSurfaceDlg (GeometryGUI* theGeometryGUI, QWidget* parent)
44   : GEOMBase_Skeleton(theGeometryGUI, parent, false)
45 {
46   QPixmap imageOp  (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_SMOOTHINGSURFACE_LPOINTS")));
47   QPixmap imageSel (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
48   QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
49
50   setWindowTitle(tr("GEOM_SMOOTHINGSURFACE_TITLE"));
51
52   /***************************************************************/
53   mainFrame()->GroupConstructors->setTitle(tr("GEOM_SMOOTHINGSURFACE"));
54   mainFrame()->RadioButton1->setIcon(imageOp);
55   mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose);
56   mainFrame()->RadioButton2->close();
57   mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
58   mainFrame()->RadioButton3->close();
59
60   GroupPoints = new DlgRef_1Sel( centralWidget() );
61
62   GroupPoints->GroupBox1->setTitle( tr( "GEOM_SMOOTHINGSURFACE_ARG" ) );
63   GroupPoints->TextLabel1->setText( tr( "GEOM_SMOOTHINGSURFACE_ARG_POINTS" ) );
64   GroupPoints->PushButton1->setIcon( image1 );
65   GroupPoints->LineEdit1->setReadOnly( true );
66
67   QVBoxLayout* layout = new QVBoxLayout(centralWidget());
68   layout->setMargin(0); layout->setSpacing(6);
69   layout->addWidget(GroupPoints);
70   /***************************************************************/
71
72   setHelpFileName("create_smoothingsurface_page.html");
73
74   Init();
75 }
76
77 //=================================================================================
78 // Destructor
79 //=================================================================================
80 AdvancedGUI_SmoothingSurfaceDlg::~AdvancedGUI_SmoothingSurfaceDlg()
81 {
82   // no need to delete child widgets, Qt does it all for us
83 }
84
85 //=================================================================================
86 // function : Init()
87 // purpose  :
88 //=================================================================================
89 void AdvancedGUI_SmoothingSurfaceDlg::Init()
90 {
91   // Get setting of step value from file configuration
92   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
93   double step = resMgr->doubleValue("Geometry", "SettingsGeomStep", 100);
94
95   //@@ initialize dialog box widgets here @@//
96
97   // Signal/slot connections
98   connect(buttonOk(),    SIGNAL(clicked()), this, SLOT(ClickOnOk()));
99   connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
100   connect(myGeomGUI,     SIGNAL(SignalDefaultStepValueChanged(double)),
101           this,          SLOT(SetDoubleSpinBoxStep(double)));
102   connect( myGeomGUI->getApp()->selectionMgr(),
103            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
104
105   initName(tr("GEOM_SMOOTHINGSURFACE"));
106   //displayPreview();
107 }
108
109 //=================================================================================
110 // function : ClickOnOk()
111 // purpose  :
112 //=================================================================================
113 void AdvancedGUI_SmoothingSurfaceDlg::ClickOnOk()
114 {
115   if (ClickOnApply())
116     ClickOnCancel();
117 }
118
119 //=================================================================================
120 // function : ClickOnApply()
121 // purpose  :
122 //=================================================================================
123 bool AdvancedGUI_SmoothingSurfaceDlg::ClickOnApply()
124 {
125   if (!onAccept())
126     return false;
127
128   initName();
129
130   return true;
131 }
132
133 //=================================================================================
134 // function : ActivateThisDialog()
135 // purpose  :
136 //=================================================================================
137 void AdvancedGUI_SmoothingSurfaceDlg::ActivateThisDialog()
138 {
139   GEOMBase_Skeleton::ActivateThisDialog();
140   //displayPreview();
141 }
142
143 //=================================================================================
144 // function : enterEvent [REDEFINED]
145 // purpose  :
146 //=================================================================================
147 void AdvancedGUI_SmoothingSurfaceDlg::enterEvent (QEvent*)
148 {
149   if (!mainFrame()->GroupConstructors->isEnabled())
150     ActivateThisDialog();
151 }
152
153 //=================================================================================
154 // function : createOperation
155 // purpose  :
156 //=================================================================================
157 GEOM::GEOM_IOperations_ptr AdvancedGUI_SmoothingSurfaceDlg::createOperation()
158 {
159   //return getGeomEngine()->GetIAdvancedOperations(getStudyId());
160   return getGeomEngine()->GetPluginOperations(getStudyId(), "AdvancedEngine");
161 }
162
163 //=================================================================================
164 // function : isValid
165 // purpose  :
166 //=================================================================================
167 bool AdvancedGUI_SmoothingSurfaceDlg::isValid (QString& msg)
168 {
169   bool ok = true;
170
171   //@@ add custom validation actions here @@//
172
173   return ok;
174 }
175
176 //=================================================================================
177 // function : execute
178 // purpose  :
179 //=================================================================================
180 bool AdvancedGUI_SmoothingSurfaceDlg::execute (ObjectList& objects)
181 {
182   bool res = false;
183
184   GEOM::GEOM_Object_var anObj;
185
186   GEOM::GEOM_IAdvancedOperations_var anOper = GEOM::GEOM_IAdvancedOperations::_narrow(getOperation());
187
188   //@@ retrieve input values from the widgets here @@//
189   GEOM::ListOfGO_var points = new GEOM::ListOfGO();
190   points->length( myPoints.count() );
191   for ( int i = 0; i < myPoints.count(); i++ )
192     points[i] = myPoints[i].copy();
193
194
195   // call engine function
196   anObj = anOper->MakeSmoothingSurface(points);
197   res = !anObj->_is_nil();
198   if (res && !IsPreview())
199   {
200     QStringList aParameters;
201     //@@ put stringified input parameters to the string list here to store in the data model for notebook @@//
202     if ( aParameters.count() > 0 ) anObj->SetParameters(aParameters.join(":").toLatin1().constData());
203   }
204   
205   if (res)
206     objects.push_back(anObj._retn());
207
208   return res;
209 }
210
211 //=================================================================================
212 // function : SelectionIntoArgument()
213 // purpose  : Called when selection as changed or other case
214 //=================================================================================
215 void AdvancedGUI_SmoothingSurfaceDlg::SelectionIntoArgument()
216 {
217   QList<GEOM::GeomObjPtr> points = getSelected( TopAbs_VERTEX, -1 );
218   GEOMBase::Synchronize( myPoints, points );
219   if ( !myPoints.isEmpty()  )
220     GroupPoints->LineEdit1->setText( QString::number( myPoints.count() ) + "_" + tr( "GEOM_POINT" ) + tr( "_S_" ) );
221   else
222     GroupPoints->LineEdit1->setText( "" );
223   processPreview();
224 }
225
226 //=================================================================================
227 // function : SetEditCurrentArgument()
228 // purpose  :
229 //=================================================================================
230 void AdvancedGUI_SmoothingSurfaceDlg::SetEditCurrentArgument()
231 {
232   if ( sender() == GroupPoints->PushButton1 )
233     myEditCurrentArgument = GroupPoints->LineEdit1;
234   myEditCurrentArgument->setFocus();
235   SelectionIntoArgument();
236 }