]> SALOME platform Git repositories - modules/geom.git/blob - src/BasicGUI/BasicGUI_ArcDlg.cxx
Salome HOME
Improve reaction of 'Divide edge' dialog on Display of objects
[modules/geom.git] / src / BasicGUI / BasicGUI_ArcDlg.cxx
1 //  GEOM GEOMGUI : GUI for Geometry component
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
21 //
22 //
23 //
24 //  File   : BasicGUI_ArcDlg.cxx
25 //  Author : Lucien PIGNOLONI
26 //  Module : GEOM
27 //  $Header$
28
29 #include "BasicGUI_ArcDlg.h"
30
31 #include "SUIT_Desktop.h"
32 #include "SUIT_Session.h"
33 #include "SalomeApp_Application.h"
34 #include "SalomeApp_SelectionMgr.h"
35
36 #include <qlabel.h>
37
38 #include <BRepBuilderAPI_MakeEdge.hxx>
39 #include <GC_MakeArcOfCircle.hxx>
40 #include <Geom_TrimmedCurve.hxx>
41 #include <Precision.hxx>
42
43 #include "GEOMImpl_Types.hxx"
44
45 #include "utilities.h"
46
47 using namespace std;
48
49 //=================================================================================
50 // class    : BasicGUI_ArcDlg()
51 // purpose  : Constructs a BasicGUI_ArcDlg which is a child of 'parent', with the
52 //            name 'name' and widget flags set to 'f'.
53 //            The dialog will by default be modeless, unless you set 'modal' to
54 //            TRUE to construct a modal dialog.
55 //=================================================================================
56 BasicGUI_ArcDlg::BasicGUI_ArcDlg(GeometryGUI* theGeometryGUI, QWidget* parent,
57                                  const char* name, bool modal, WFlags fl)
58   : GEOMBase_Skeleton(parent, name, modal, WStyle_Customize |
59                       WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu),
60     myGeometryGUI(theGeometryGUI)
61 {
62   QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_ARC")));
63   QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
64
65   setCaption(tr("GEOM_ARC_TITLE"));
66
67   /***************************************************************/
68   GroupConstructors->setTitle(tr("GEOM_ARC"));
69   RadioButton1->setPixmap(image0);
70   RadioButton2->close(TRUE);
71   RadioButton3->close(TRUE);
72
73   Group3Pnts = new DlgRef_3Sel_QTD(this, "Group3Pnts");
74   Group3Pnts->GroupBox1->setTitle(tr("GEOM_POINTS"));
75   Group3Pnts->TextLabel1->setText(tr("GEOM_POINT_I").arg("1"));
76   Group3Pnts->TextLabel2->setText(tr("GEOM_POINT_I").arg("2"));
77   Group3Pnts->TextLabel3->setText(tr("GEOM_POINT_I").arg("3"));
78
79   Group3Pnts->LineEdit1->setReadOnly( true );
80   Group3Pnts->LineEdit2->setReadOnly( true );
81   Group3Pnts->LineEdit3->setReadOnly( true );
82
83   Group3Pnts->PushButton1->setPixmap(image1);
84   Group3Pnts->PushButton2->setPixmap(image1);
85   Group3Pnts->PushButton3->setPixmap(image1);
86
87   Layout1->addWidget( Group3Pnts, 2, 0 );
88
89   Init();
90 }
91
92
93 //=================================================================================
94 // function : ~BasicGUI_ArcDlg()
95 // purpose  : Destroys the object and frees any allocated resources
96 //=================================================================================
97 BasicGUI_ArcDlg::~BasicGUI_ArcDlg()
98 {
99 }
100
101
102 //=================================================================================
103 // function : Init()
104 // purpose  :
105 //=================================================================================
106 void BasicGUI_ArcDlg::Init()
107 {
108   /* init variables */
109   // myGeometryGUI->SetState( 0 );
110   globalSelection( GEOM_POINT );
111
112   myEditCurrentArgument = Group3Pnts->LineEdit1;
113   myEditCurrentArgument->setFocus();
114
115   myPoint1 = myPoint2 = myPoint3 = GEOM::GEOM_Object::_nil();
116
117   /* signals and slots connections */
118   connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
119   connect(myGeometryGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
120   connect(myGeometryGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
121
122   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
123   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
124
125   connect(Group3Pnts->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
126   connect(Group3Pnts->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
127   connect(Group3Pnts->PushButton3, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
128
129   connect(Group3Pnts->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
130   connect(Group3Pnts->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
131   connect(Group3Pnts->LineEdit3, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
132
133   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
134           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
135
136   initName( tr( "GEOM_ARC" ) );
137 }
138
139
140 //=================================================================================
141 // function : ClickOnOk()
142 // purpose  :
143 //=================================================================================
144 void BasicGUI_ArcDlg::ClickOnOk()
145 {
146   if ( ClickOnApply() )
147     ClickOnCancel();
148 }
149
150 //=================================================================================
151 // function : ClickOnCancel()
152 // purpose  :
153 //=================================================================================
154 void BasicGUI_ArcDlg::ClickOnCancel()
155 {
156   GEOMBase_Skeleton::ClickOnCancel();
157 }
158
159 //=================================================================================
160 // function : ClickOnApply()
161 // purpose  :
162 //=================================================================================
163 bool BasicGUI_ArcDlg::ClickOnApply()
164 {
165   if ( !onAccept() )
166     return false;
167
168   initName();
169
170   // reset
171   myPoint1 = myPoint2 = myPoint3 = GEOM::GEOM_Object::_nil();
172   Group3Pnts->LineEdit1->setText( "" );
173   Group3Pnts->LineEdit2->setText( "" );
174   Group3Pnts->LineEdit3->setText( "" );
175   myEditCurrentArgument = Group3Pnts->LineEdit1;
176
177   return true;
178 }
179
180
181 //=================================================================================
182 // function : SelectionIntoArgument()
183 // purpose  : Called when selection as changed or other case
184 //=================================================================================
185 void BasicGUI_ArcDlg::SelectionIntoArgument()
186 {
187   myEditCurrentArgument->setText("");
188
189   if ( IObjectCount() != 1 )
190   {
191     if      ( myEditCurrentArgument == Group3Pnts->LineEdit1 )   myPoint1 = GEOM::GEOM_Object::_nil();
192     else if ( myEditCurrentArgument == Group3Pnts->LineEdit2 )   myPoint2 = GEOM::GEOM_Object::_nil();
193     else if ( myEditCurrentArgument == Group3Pnts->LineEdit3 )   myPoint3 = GEOM::GEOM_Object::_nil();
194     return;
195   }
196
197   // nbSel == 1
198   Standard_Boolean aRes = Standard_False;
199   GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), aRes );
200   if ( !CORBA::is_nil( aSelectedObject ) && aRes )
201   {
202     myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
203     if      ( myEditCurrentArgument == Group3Pnts->LineEdit1 )   myPoint1 = aSelectedObject;
204     else if ( myEditCurrentArgument == Group3Pnts->LineEdit2 )   myPoint2 = aSelectedObject;
205     else if ( myEditCurrentArgument == Group3Pnts->LineEdit3 )   myPoint3 = aSelectedObject;
206   }
207
208   displayPreview();
209 }
210
211
212 //=================================================================================
213 // function : SetEditCurrentArgument()
214 // purpose  :
215 //=================================================================================
216 void BasicGUI_ArcDlg::SetEditCurrentArgument()
217 {
218   QPushButton* send = (QPushButton*)sender();
219
220   if      ( send == Group3Pnts->PushButton1 )   myEditCurrentArgument = Group3Pnts->LineEdit1;
221   else if ( send == Group3Pnts->PushButton2 )   myEditCurrentArgument = Group3Pnts->LineEdit2;
222   else if ( send == Group3Pnts->PushButton3 )   myEditCurrentArgument = Group3Pnts->LineEdit3;
223
224   myEditCurrentArgument->setFocus();
225   SelectionIntoArgument();
226 }
227
228
229 //=================================================================================
230 // function : LineEditReturnPressed()
231 // purpose  :
232 //=================================================================================
233 void BasicGUI_ArcDlg::LineEditReturnPressed()
234 {
235   QLineEdit* send = (QLineEdit*)sender();
236   if ( send == Group3Pnts->LineEdit1 ||
237        send == Group3Pnts->LineEdit2 ||
238        send == Group3Pnts->LineEdit3 )
239   {
240     myEditCurrentArgument = send;
241     GEOMBase_Skeleton::LineEditReturnPressed();
242   }
243 }
244
245
246 //=================================================================================
247 // function : ActivateThisDialog()
248 // purpose  :
249 //=================================================================================
250 void BasicGUI_ArcDlg::ActivateThisDialog()
251 {
252   GEOMBase_Skeleton::ActivateThisDialog();
253   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
254           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
255
256   // myGeometryGUI->SetState( 0 );
257   globalSelection( GEOM_POINT );
258
259   myEditCurrentArgument = Group3Pnts->LineEdit1;
260   myEditCurrentArgument->setFocus();
261
262   Group3Pnts->LineEdit1->setText( "" );
263   Group3Pnts->LineEdit2->setText( "" );
264   Group3Pnts->LineEdit3->setText( "" );
265   myPoint1 = myPoint2 = myPoint3 = GEOM::GEOM_Object::_nil();
266 }
267
268 //=================================================================================
269 // function : DeactivateActiveDialog()
270 // purpose  : public slot to deactivate if active
271 //=================================================================================
272 void BasicGUI_ArcDlg::DeactivateActiveDialog()
273 {
274   // myGeometryGUI->SetState( -1 );
275   GEOMBase_Skeleton::DeactivateActiveDialog();
276 }
277
278 //=================================================================================
279 // function : enterEvent()
280 // purpose  :
281 //=================================================================================
282 void BasicGUI_ArcDlg::enterEvent(QEvent* e)
283 {
284   if ( !GroupConstructors->isEnabled() )
285     ActivateThisDialog();
286 }
287
288 //=================================================================================
289 // function : createOperation
290 // purpose  :
291 //=================================================================================
292 GEOM::GEOM_IOperations_ptr BasicGUI_ArcDlg::createOperation()
293 {
294   return myGeometryGUI->GetGeomGen()->GetICurvesOperations( getStudyId() );
295 }
296
297 //=================================================================================
298 // function : isEqual
299 // purpose  : it may also be needed to check for min distance between gp_Pnt-s...
300 //=================================================================================
301 static bool isEqual( const GEOM::GEOM_Object_var& thePnt1, const GEOM::GEOM_Object_var& thePnt2 )
302 {
303   return thePnt1->_is_equivalent( thePnt2 );
304 }
305
306 //=================================================================================
307 // function : isValid
308 // purpose  :
309 //=================================================================================
310 bool BasicGUI_ArcDlg::isValid( QString& msg )
311 {
312   return !myPoint1->_is_nil() && !myPoint2->_is_nil() && !myPoint3->_is_nil() &&
313     !isEqual( myPoint1, myPoint2 ) && !isEqual( myPoint1, myPoint3 ) && !isEqual( myPoint2, myPoint3 );
314 }
315
316 //=================================================================================
317 // function : execute
318 // purpose  :
319 //=================================================================================
320 bool BasicGUI_ArcDlg::execute( ObjectList& objects )
321 {
322   GEOM::GEOM_Object_var anObj =
323     GEOM::GEOM_ICurvesOperations::_narrow(getOperation())->MakeArc(myPoint1, myPoint2, myPoint3);
324   if ( !anObj->_is_nil() )
325     objects.push_back( anObj._retn() );
326   return true;
327 }
328
329 //=================================================================================
330 // function : closeEvent
331 // purpose  :
332 //=================================================================================
333 void BasicGUI_ArcDlg::closeEvent( QCloseEvent* e )
334 {
335   // myGeometryGUI->SetState( -1 );
336   GEOMBase_Skeleton::closeEvent( e );
337 }