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