]> SALOME platform Git repositories - modules/geom.git/blob - src/BasicGUI/BasicGUI_EllipseDlg.cxx
Salome HOME
NPAL18111: Bad shape build by partition.
[modules/geom.git] / src / BasicGUI / BasicGUI_EllipseDlg.cxx
1 //  GEOM GEOMGUI : GUI for Geometry component
2 //
3 //  Copyright (C) 2003  OPEN CASCADE 
4 // 
5 //  This library is free software; you can redistribute it and/or 
6 //  modify it under the terms of the GNU Lesser General Public 
7 //  License as published by the Free Software Foundation; either 
8 //  version 2.1 of the License. 
9 // 
10 //  This library is distributed in the hope that it will be useful, 
11 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
12 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
13 //  Lesser General Public License for more details. 
14 // 
15 //  You should have received a copy of the GNU Lesser General Public 
16 //  License along with this library; if not, write to the Free Software 
17 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
18 // 
19 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 //
21 //
22 //
23 //  File   : BasicGUI_EllipseDlg.cxx
24 //  Author : Nicolas REJNERI
25 //  Module : GEOM
26 //  $Header$
27
28 #include "BasicGUI_EllipseDlg.h"
29
30 #include "SUIT_Desktop.h"
31 #include "SUIT_Session.h"
32 #include "SalomeApp_Application.h"
33 #include "LightApp_SelectionMgr.h"
34
35 #include <TColStd_IndexedMapOfInteger.hxx>
36 #include <TopTools_IndexedMapOfShape.hxx>
37 #include <TopoDS_Shape.hxx>
38 #include <TopoDS_Edge.hxx>
39 #include <TopoDS.hxx>
40 #include <TopExp.hxx>
41
42 #include <qlabel.h>
43
44 #include "GEOMImpl_Types.hxx"
45
46 #include "utilities.h"
47
48 using namespace std;
49
50 //=================================================================================
51 // class    : BasicGUI_EllipseDlg()
52 // purpose  : Constructs a BasicGUI_EllipseDlg which is a child of 'parent', with the 
53 //            name 'name' and widget flags set to 'f'.
54 //            The dialog will by default be modeless, unless you set 'modal' to
55 //            TRUE to construct a modal dialog.
56 //=================================================================================
57 BasicGUI_EllipseDlg::BasicGUI_EllipseDlg(GeometryGUI* theGeometryGUI, QWidget* parent,
58                                          const char* name, bool modal, WFlags fl)
59   :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize |
60                      WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
61 {
62   QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_ELLIPSE_PV")));
63   QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
64
65   setCaption(tr("GEOM_ELLIPSE_TITLE"));
66
67   /***************************************************************/
68   GroupConstructors->setTitle(tr("GEOM_ELLIPSE"));
69   RadioButton1->setPixmap(image0);
70   RadioButton2->close(TRUE);
71   RadioButton3->close(TRUE);
72
73   GroupPoints = new DlgRef_2Sel2Spin(this, "GroupPoints");
74   GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
75   GroupPoints->TextLabel1->setText(tr("GEOM_CENTER"));
76   GroupPoints->TextLabel2->setText(tr("GEOM_VECTOR"));
77   GroupPoints->TextLabel3->setText(tr("GEOM_RADIUS_MAJOR"));
78   GroupPoints->TextLabel4->setText(tr("GEOM_RADIUS_MINOR"));
79   GroupPoints->PushButton1->setPixmap(image1);
80   GroupPoints->PushButton2->setPixmap(image1);
81
82   GroupPoints->LineEdit1->setReadOnly( true );
83   GroupPoints->LineEdit2->setReadOnly( true );
84
85   Layout1->addWidget(GroupPoints, 2, 0);
86   /***************************************************************/
87
88   setHelpFileName("ellipse.htm");
89
90   Init();
91 }
92
93
94 //=================================================================================
95 // function : ~BasicGUI_EllipseDlg()
96 // purpose  : Destroys the object and frees any allocated resources
97 //=================================================================================
98 BasicGUI_EllipseDlg::~BasicGUI_EllipseDlg()
99 {
100 }
101
102
103 //=================================================================================
104 // function : Init()
105 // purpose  :
106 //=================================================================================
107 void BasicGUI_EllipseDlg::Init()
108 {
109   /* init variables */
110   myEditCurrentArgument = GroupPoints->LineEdit1;
111   //  globalSelection( GEOM_POINT );
112   localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX); //Select Vertex on All Shapes
113
114   myPoint = myDir = GEOM::GEOM_Object::_nil();
115
116   // myGeomGUI->SetState( 0 );
117
118   /* Get setting of step value from file configuration */
119   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
120   double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100);
121   
122   double aMajorR( 200. ), aMinorR( 100. );
123
124   /* min, max, step and decimals for spin boxes & initial values */
125   GroupPoints->SpinBox_DX->RangeStepAndValidator( 0.001, COORD_MAX, step, DBL_DIGITS_DISPLAY );
126   GroupPoints->SpinBox_DY->RangeStepAndValidator( 0.001, COORD_MAX, step, DBL_DIGITS_DISPLAY );
127   GroupPoints->SpinBox_DX->SetValue( aMajorR );
128   GroupPoints->SpinBox_DY->SetValue( aMinorR );
129
130   /* signals and slots connections */
131   connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
132   connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
133   connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
134
135   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
136   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
137
138   connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
139   connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
140
141   connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
142   connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
143
144   connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
145   connect(GroupPoints->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
146
147   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
148   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DY, SLOT(SetStep(double)));
149   
150   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
151           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
152
153   initName( tr( "GEOM_ELLIPSE" ) );
154 }
155
156
157 //=================================================================================
158 // function : ClickOnOk()
159 // purpose  :
160 //=================================================================================
161 void BasicGUI_EllipseDlg::ClickOnOk()
162 {
163   if ( ClickOnApply() )
164     ClickOnCancel();
165 }
166
167
168 //=================================================================================
169 // function : ClickOnApply()
170 // purpose  :
171 //=================================================================================
172 bool BasicGUI_EllipseDlg::ClickOnApply()
173 {
174   if ( !onAccept() )
175     return false;
176
177   initName();
178
179   // reset
180   myPoint = myDir = GEOM::GEOM_Object::_nil();
181   GroupPoints->LineEdit1->setText( "" );
182   GroupPoints->LineEdit2->setText( "" );
183   myEditCurrentArgument = GroupPoints->LineEdit1;
184   globalSelection( GEOM_POINT );
185   
186   return true;
187 }
188
189 //=======================================================================
190 // function : ClickOnCancel()
191 // purpose  :
192 //=======================================================================
193 void BasicGUI_EllipseDlg::ClickOnCancel()
194 {
195   GEOMBase_Skeleton::ClickOnCancel();
196 }
197
198 //=================================================================================
199 // function : SelectionIntoArgument()
200 // purpose  : Called when selection as changed or other case
201 //=================================================================================
202 void BasicGUI_EllipseDlg::SelectionIntoArgument()
203 {
204   myEditCurrentArgument->setText("");
205
206   if ( IObjectCount() != 1 )  
207   {
208     if      ( myEditCurrentArgument == GroupPoints->LineEdit1 ) myPoint = GEOM::GEOM_Object::_nil();
209     else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) myDir   = GEOM::GEOM_Object::_nil();
210     return;
211   }
212
213   Standard_Boolean aRes = Standard_False;
214   GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), aRes );
215   if ( !CORBA::is_nil( aSelectedObject ) && aRes )
216   {  
217     myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
218     // Get Selected object if selected subshape
219     TopoDS_Shape aShape;
220     if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() )
221       {
222         LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
223         TColStd_IndexedMapOfInteger aMap;
224         aSelMgr->GetIndexes( firstIObject(), aMap );
225         if ( aMap.Extent() == 1 )
226           {
227             GEOM::GEOM_IShapesOperations_var aShapesOp =
228               getGeomEngine()->GetIShapesOperations( getStudyId() );
229             int anIndex = aMap( 1 );
230             TopTools_IndexedMapOfShape aShapes;
231             TopExp::MapShapes( aShape, aShapes );
232             aShape = aShapes.FindKey( anIndex );
233             aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
234             aSelMgr->clearSelected();
235           }
236       }
237     if      ( myEditCurrentArgument == GroupPoints->LineEdit1 ) myPoint = aSelectedObject;
238     else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) myDir   = aSelectedObject;
239   }
240
241   displayPreview();
242 }
243
244
245 //=================================================================================
246 // function : SetEditCurrentArgument()
247 // purpose  :
248 //=================================================================================
249 void BasicGUI_EllipseDlg::SetEditCurrentArgument()
250 {
251   QPushButton* send = (QPushButton*)sender();
252
253   if      ( send == GroupPoints->PushButton1 ) myEditCurrentArgument = GroupPoints->LineEdit1;
254   else if ( send == GroupPoints->PushButton2 ) myEditCurrentArgument = GroupPoints->LineEdit2;
255   
256   myEditCurrentArgument->setFocus();
257   if ( myEditCurrentArgument == GroupPoints->LineEdit2 )
258     localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE);
259   else
260     localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
261   SelectionIntoArgument();
262 }
263
264 //=================================================================================
265 // function : LineEditReturnPressed()
266 // purpose  :
267 //=================================================================================
268 void BasicGUI_EllipseDlg::LineEditReturnPressed()
269 {
270   QLineEdit* send = (QLineEdit*)sender();
271   if ( send == GroupPoints->LineEdit1 ||
272        send == GroupPoints->LineEdit2 )
273   {
274     myEditCurrentArgument = send;
275     GEOMBase_Skeleton::LineEditReturnPressed();
276   }
277 }
278
279
280 //=================================================================================
281 // function : ActivateThisDialog()
282 // purpose  :
283 //=================================================================================
284 void BasicGUI_EllipseDlg::ActivateThisDialog()
285 {
286   GEOMBase_Skeleton::ActivateThisDialog();
287   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
288           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
289   
290   GroupPoints->LineEdit1->setFocus();
291   myEditCurrentArgument = GroupPoints->LineEdit1;
292
293   GroupPoints->LineEdit1->setText( "" );
294   GroupPoints->LineEdit2->setText( "" );
295
296   myPoint = myDir = GEOM::GEOM_Object::_nil();
297   globalSelection( GEOM_POINT );
298 }
299
300 //=================================================================================
301 // function : DeactivateActiveDialog()
302 // purpose  : public slot to deactivate if active
303 //=================================================================================
304 void BasicGUI_EllipseDlg::DeactivateActiveDialog()
305 {
306   // myGeomGUI->SetState( -1 );
307   GEOMBase_Skeleton::DeactivateActiveDialog();
308 }
309
310 //=================================================================================
311 // function : enterEvent()
312 // purpose  :
313 //=================================================================================
314 void BasicGUI_EllipseDlg::enterEvent(QEvent* e)
315 {
316   if ( !GroupConstructors->isEnabled() )
317     ActivateThisDialog();
318 }
319
320 //=================================================================================
321 // function : ValueChangedInSpinBox()
322 // purpose  :
323 //=================================================================================
324 void BasicGUI_EllipseDlg::ValueChangedInSpinBox(double newValue)
325 {
326   displayPreview();
327 }
328
329 //=================================================================================
330 // function : createOperation
331 // purpose  :
332 //=================================================================================
333 GEOM::GEOM_IOperations_ptr BasicGUI_EllipseDlg::createOperation()
334 {
335   return myGeomGUI->GetGeomGen()->GetICurvesOperations( getStudyId() );
336 }
337
338 //=================================================================================
339 // function : isValid
340 // purpose  :
341 //=================================================================================
342 bool BasicGUI_EllipseDlg::isValid( QString& msg )
343 {
344   double aMajorR = GroupPoints->SpinBox_DX->GetValue();
345   double aMinorR = GroupPoints->SpinBox_DY->GetValue();
346   if ( aMajorR < aMinorR )
347   {
348         msg = tr( "GEOM_ELLIPSE_ERROR_1" );
349         return false;
350   }
351   return !myPoint->_is_nil() && !myDir->_is_nil();
352 }
353
354 //=================================================================================
355 // function : execute
356 // purpose  :
357 //=================================================================================
358 bool BasicGUI_EllipseDlg::execute( ObjectList& objects )
359 {
360   double aMajorR = GroupPoints->SpinBox_DX->GetValue();
361   double aMinorR = GroupPoints->SpinBox_DY->GetValue();
362   GEOM::GEOM_Object_var anObj = GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakeEllipse( myPoint, myDir, aMajorR, aMinorR );
363
364   if ( !anObj->_is_nil() )
365     objects.push_back( anObj._retn() );
366
367   return true;
368 }
369
370 //=================================================================================
371 // function : closeEvent
372 // purpose  :
373 //=================================================================================
374 void BasicGUI_EllipseDlg::closeEvent( QCloseEvent* e )
375 {
376   GEOMBase_Skeleton::closeEvent( e );
377 }
378