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