]> SALOME platform Git repositories - modules/geom.git/blob - src/EntityGUI/EntityGUI_IsolineDlg.cxx
Salome HOME
Build with native prerequsites
[modules/geom.git] / src / EntityGUI / EntityGUI_IsolineDlg.cxx
1 // Copyright (C) 2007-2020  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 // GEOM GEOMGUI : GUI for Geometry component
21 // File   : EntityGUI_IsolineDlg.cxx
22
23 #include "EntityGUI_IsolineDlg.h"
24 #include <GeometryGUI.h>
25 #include <DlgRef.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 #include <QButtonGroup> 
34
35
36 //=================================================================================
37 // class    : EntityGUI_IsolineDlg
38 // purpose  : 
39 //=================================================================================
40 EntityGUI_IsolineDlg::EntityGUI_IsolineDlg (GeometryGUI     *theGeometryGUI,
41                                             QWidget         *parent,
42                                             bool             modal,
43                                             Qt::WindowFlags  fl)
44   : GEOMBase_Skeleton (theGeometryGUI, parent, modal, fl),
45     myRBGroup         (0)
46 {
47   QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICO_ISOLINE")));
48   QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
49   QPixmap image2(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICO_ISOLINE_V")));
50
51   setWindowTitle(tr("GEOM_ISOLINE_TITLE"));
52
53   /***************************************************************/
54
55   mainFrame()->GroupConstructors->setTitle(tr("GEOM_ISOLINE"));
56   mainFrame()->RadioButton1->setIcon(image0);
57   mainFrame()->RadioButton2->close();
58   mainFrame()->RadioButton3->close();
59
60   // Construct a group.
61   myGroup = new DlgRef_3Radio1Sel1Spin(centralWidget());
62   myGroup->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
63   myGroup->TextLabel1->setText(tr("GEOM_FACE"));
64   myGroup->PushButton1->setIcon(image1);
65   myGroup->LineEdit1->setReadOnly(true);
66   myGroup->RadioButton1->setIcon(image0);
67   myGroup->RadioButton2->setIcon(image2);
68   myGroup->RadioButton1->setText(tr("GEOM_ISOLINE_U"));
69   myGroup->RadioButton2->setText(tr("GEOM_ISOLINE_V"));
70   myGroup->RadioButton3->hide();
71   myGroup->TextLabel2->setText(tr("GEOM_PARAMETER"));
72
73   QVBoxLayout* layout = new QVBoxLayout(centralWidget());
74   layout->setMargin(0); layout->setSpacing(6);
75   layout->addWidget(myGroup);
76
77   myRBGroup = new QButtonGroup( this );
78   myRBGroup->addButton( myGroup->RadioButton1, 0 );
79   myRBGroup->addButton( myGroup->RadioButton2, 1 );
80
81   setHelpFileName("create_isoline_page.html");
82
83   Init();
84 }
85
86 //=================================================================================
87 // function : ~EntityGUI_IsolineDlg()
88 // purpose  : 
89 //=================================================================================
90 EntityGUI_IsolineDlg::~EntityGUI_IsolineDlg()
91 {
92 }
93
94 //=================================================================================
95 // function : Init()
96 // purpose  :
97 //=================================================================================
98 void EntityGUI_IsolineDlg::Init()
99 {
100   /* min, max, step and decimals for spin box */
101   initSpinBox(myGroup->SpinBox_DX, 0., 1., 0.1, "parametric_precision");
102   myGroup->SpinBox_DX->setValue(0.5);
103   myGroup->RadioButton1->setChecked(true);
104
105   initName(mainFrame()->GroupConstructors->title());
106
107   connect(myGroup->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditFace()));
108   connect(myGroup->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
109
110   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), this,  SLOT(SetDoubleSpinBoxStep(double)));
111   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
112           this, SLOT(SelectionIntoArgument()));
113
114   /* signals and slots connections */
115   connect(myGeomGUI,     SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
116   connect(myGeomGUI,     SIGNAL(SignalCloseAllDialogs()),        this, SLOT(ClickOnCancel()));
117   connect(buttonOk(),    SIGNAL(clicked()), this, SLOT(ClickOnOk()));
118   connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
119   connect(myRBGroup,     SIGNAL(buttonClicked(int)), this, SLOT(TypeChanged(int)));
120
121   myGroup->PushButton1->click();
122   SelectionIntoArgument();
123   resize(100,100);
124 }
125
126 //=================================================================================
127 // function : SelectionIntoArgument
128 // purpose  : Called when selection is changed
129 //=================================================================================
130 void EntityGUI_IsolineDlg::SelectionIntoArgument()
131 {
132   myGroup->LineEdit1->setText("");
133   myFace.nullify();
134
135   GEOM::GeomObjPtr aSelectedObject = getSelected( TopAbs_SHAPE );
136   TopoDS_Shape aShape;
137
138   if ( aSelectedObject && GEOMBase::GetShape( aSelectedObject.get(), aShape ) && !aShape.IsNull() ) {
139     if (aShape.ShapeType() == TopAbs_FACE) {
140       QString aName = GEOMBase::GetName( aSelectedObject.get() );
141       myGroup->LineEdit1->setText( aName );
142
143       // clear selection
144       disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
145       myGeomGUI->getApp()->selectionMgr()->clearSelected();
146       connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
147               this, SLOT(SelectionIntoArgument()));
148
149       myFace = aSelectedObject;
150     }
151   }
152
153   displayPreview(true);
154 }
155
156 //=================================================================================
157 // function : ActivateThisDialog
158 // purpose  :
159 //=================================================================================
160 void EntityGUI_IsolineDlg::ActivateThisDialog()
161 {
162   GEOMBase_Skeleton::ActivateThisDialog();
163
164   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
165            this, SLOT( SelectionIntoArgument() ) );
166   SetEditFace();
167   SelectionIntoArgument();
168 }
169
170 //=================================================================================
171 // function : enterEvent()
172 // purpose  :
173 //=================================================================================
174 void EntityGUI_IsolineDlg::enterEvent (QEvent*)
175 {
176   if (!mainFrame()->GroupConstructors->isEnabled())
177     ActivateThisDialog();
178 }
179
180 //=================================================================================
181 // function : TypeChanged
182 // purpose  :
183 //=================================================================================
184 void EntityGUI_IsolineDlg::TypeChanged(int)
185 {
186   displayPreview(true);
187 }
188
189 //=================================================================================
190 // function : createOperation
191 // purpose  :
192 //=================================================================================
193 GEOM::GEOM_IOperations_ptr EntityGUI_IsolineDlg::createOperation()
194 {
195   return myGeomGUI->GetGeomGen()->GetICurvesOperations();
196 }
197
198 //=================================================================================
199 // function : isValid
200 // purpose  :
201 //=================================================================================
202 bool EntityGUI_IsolineDlg::isValid (QString& msg)
203 {
204   return myFace;
205 }
206
207 //=================================================================================
208 // function : execute
209 // purpose  :
210 //=================================================================================
211 bool EntityGUI_IsolineDlg::execute (ObjectList& objects)
212 {
213   GEOM::GEOM_ICurvesOperations_var anOper = GEOM::GEOM_ICurvesOperations::_narrow(getOperation());
214   GEOM::GEOM_Object_var anObj = anOper->MakeIsoline
215     (myFace.get(), myGroup->RadioButton1->isChecked(), myGroup->SpinBox_DX->value());
216
217   if (!anObj->_is_nil())
218     objects.push_back(anObj._retn());
219
220   return true;
221 }
222
223 //=================================================================================
224 // function : addSubshapesToStudy()
225 // purpose  : Double spin box management
226 //=================================================================================
227 void EntityGUI_IsolineDlg::addSubshapesToStudy()
228 {
229   GEOMBase::PublishSubObject(myFace.get());
230 }
231
232 //=================================================================================
233 // function : SetDoubleSpinBoxStep()
234 // purpose  : Double spin box management
235 //=================================================================================
236 void EntityGUI_IsolineDlg::SetDoubleSpinBoxStep (double step)
237 {
238   myGroup->SpinBox_DX->setSingleStep(step);
239 }
240
241 //=================================================================================
242 // function : ClickOnOk()
243 // purpose  :
244 //=================================================================================
245 void EntityGUI_IsolineDlg::ClickOnOk()
246 {
247   setIsApplyAndClose( true );
248
249   if (ClickOnApply())
250     ClickOnCancel();
251 }
252
253 //=================================================================================
254 // function : ClickOnApply()
255 // purpose  :
256 //=================================================================================
257 bool EntityGUI_IsolineDlg::ClickOnApply()
258 {
259   if (!onAccept())
260     return false;
261
262   initName();
263   // activate selection and connect selection manager
264   myGroup->PushButton1->click();
265   return true;
266 }
267
268 //=================================================================================
269 // function : SetEditFace
270 // purpose  :
271 //=================================================================================
272 void EntityGUI_IsolineDlg::SetEditFace()
273 {
274   myGroup->LineEdit1->setFocus();
275   myGroup->PushButton1->setDown(true);
276 }
277
278 //=================================================================================
279 // function : ValueChangedInSpinBox
280 // purpose  :
281 //=================================================================================
282 void EntityGUI_IsolineDlg::ValueChangedInSpinBox(double newValue)
283 {
284   displayPreview(true);
285 }
286
287 //=================================================================================
288 // function : getSourceObjects
289 // purpose  : virtual method to get source objects
290 //=================================================================================
291 QList<GEOM::GeomObjPtr> EntityGUI_IsolineDlg::getSourceObjects()
292 {
293   QList<GEOM::GeomObjPtr> res;
294   res << myFace;
295   return res;
296 }