Salome HOME
Update mail address
[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.salome-platform.org/ or email : webmaster.salome@opencascade.com
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 "LightApp_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(theGeometryGUI, parent, name, modal, WStyle_Customize |
59                       WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
60 {
61   QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_ARC")));
62   QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
63
64   setCaption(tr("GEOM_ARC_TITLE"));
65
66   /***************************************************************/
67   GroupConstructors->setTitle(tr("GEOM_ARC"));
68   RadioButton1->setPixmap(image0);
69   RadioButton2->close(TRUE);
70   RadioButton3->close(TRUE);
71
72   Group3Pnts = new DlgRef_3Sel_QTD(this, "Group3Pnts");
73   Group3Pnts->GroupBox1->setTitle(tr("GEOM_POINTS"));
74   Group3Pnts->TextLabel1->setText(tr("GEOM_POINT_I").arg("1"));
75   Group3Pnts->TextLabel2->setText(tr("GEOM_POINT_I").arg("2"));
76   Group3Pnts->TextLabel3->setText(tr("GEOM_POINT_I").arg("3"));
77
78   Group3Pnts->LineEdit1->setReadOnly( true );
79   Group3Pnts->LineEdit2->setReadOnly( true );
80   Group3Pnts->LineEdit3->setReadOnly( true );
81
82   Group3Pnts->PushButton1->setPixmap(image1);
83   Group3Pnts->PushButton2->setPixmap(image1);
84   Group3Pnts->PushButton3->setPixmap(image1);
85
86   Layout1->addWidget( Group3Pnts, 2, 0 );
87
88   setHelpFileName("arc.htm");
89
90   Init();
91 }
92
93
94 //=================================================================================
95 // function : ~BasicGUI_ArcDlg()
96 // purpose  : Destroys the object and frees any allocated resources
97 //=================================================================================
98 BasicGUI_ArcDlg::~BasicGUI_ArcDlg()
99 {
100 }
101
102
103 //=================================================================================
104 // function : Init()
105 // purpose  :
106 //=================================================================================
107 void BasicGUI_ArcDlg::Init()
108 {
109   /* init variables */
110   // myGeomGUI->SetState( 0 );
111   globalSelection( GEOM_POINT );
112
113   myEditCurrentArgument = Group3Pnts->LineEdit1;
114   myEditCurrentArgument->setFocus();
115
116   myPoint1 = myPoint2 = myPoint3 = GEOM::GEOM_Object::_nil();
117
118   /* signals and slots connections */
119   connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
120   connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
121   connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
122
123   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
124   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
125
126   connect(Group3Pnts->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
127   connect(Group3Pnts->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
128   connect(Group3Pnts->PushButton3, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
129
130   connect(Group3Pnts->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
131   connect(Group3Pnts->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
132   connect(Group3Pnts->LineEdit3, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
133
134   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
135           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
136
137   initName( tr( "GEOM_ARC" ) );
138 }
139
140
141 //=================================================================================
142 // function : ClickOnOk()
143 // purpose  :
144 //=================================================================================
145 void BasicGUI_ArcDlg::ClickOnOk()
146 {
147   if ( ClickOnApply() )
148     ClickOnCancel();
149 }
150
151 //=================================================================================
152 // function : ClickOnCancel()
153 // purpose  :
154 //=================================================================================
155 void BasicGUI_ArcDlg::ClickOnCancel()
156 {
157   GEOMBase_Skeleton::ClickOnCancel();
158 }
159
160 //=================================================================================
161 // function : ClickOnApply()
162 // purpose  :
163 //=================================================================================
164 bool BasicGUI_ArcDlg::ClickOnApply()
165 {
166   if ( !onAccept() )
167     return false;
168
169   initName();
170
171   // reset
172   myPoint1 = myPoint2 = myPoint3 = GEOM::GEOM_Object::_nil();
173   Group3Pnts->LineEdit1->setText( "" );
174   Group3Pnts->LineEdit2->setText( "" );
175   Group3Pnts->LineEdit3->setText( "" );
176   myEditCurrentArgument = Group3Pnts->LineEdit1;
177
178   return true;
179 }
180
181
182 //=================================================================================
183 // function : SelectionIntoArgument()
184 // purpose  : Called when selection as changed or other case
185 //=================================================================================
186 void BasicGUI_ArcDlg::SelectionIntoArgument()
187 {
188   myEditCurrentArgument->setText("");
189
190   if ( IObjectCount() != 1 )
191   {
192     if      ( myEditCurrentArgument == Group3Pnts->LineEdit1 )   myPoint1 = GEOM::GEOM_Object::_nil();
193     else if ( myEditCurrentArgument == Group3Pnts->LineEdit2 )   myPoint2 = GEOM::GEOM_Object::_nil();
194     else if ( myEditCurrentArgument == Group3Pnts->LineEdit3 )   myPoint3 = GEOM::GEOM_Object::_nil();
195     return;
196   }
197
198   // nbSel == 1
199   Standard_Boolean aRes = Standard_False;
200   GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), aRes );
201   if ( !CORBA::is_nil( aSelectedObject ) && aRes )
202   {
203     myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
204     if      ( myEditCurrentArgument == Group3Pnts->LineEdit1 )   myPoint1 = aSelectedObject;
205     else if ( myEditCurrentArgument == Group3Pnts->LineEdit2 )   myPoint2 = aSelectedObject;
206     else if ( myEditCurrentArgument == Group3Pnts->LineEdit3 )   myPoint3 = aSelectedObject;
207   }
208
209   displayPreview();
210 }
211
212
213 //=================================================================================
214 // function : SetEditCurrentArgument()
215 // purpose  :
216 //=================================================================================
217 void BasicGUI_ArcDlg::SetEditCurrentArgument()
218 {
219   QPushButton* send = (QPushButton*)sender();
220
221   if      ( send == Group3Pnts->PushButton1 )   myEditCurrentArgument = Group3Pnts->LineEdit1;
222   else if ( send == Group3Pnts->PushButton2 )   myEditCurrentArgument = Group3Pnts->LineEdit2;
223   else if ( send == Group3Pnts->PushButton3 )   myEditCurrentArgument = Group3Pnts->LineEdit3;
224
225   myEditCurrentArgument->setFocus();
226   SelectionIntoArgument();
227 }
228
229
230 //=================================================================================
231 // function : LineEditReturnPressed()
232 // purpose  :
233 //=================================================================================
234 void BasicGUI_ArcDlg::LineEditReturnPressed()
235 {
236   QLineEdit* send = (QLineEdit*)sender();
237   if ( send == Group3Pnts->LineEdit1 ||
238        send == Group3Pnts->LineEdit2 ||
239        send == Group3Pnts->LineEdit3 )
240   {
241     myEditCurrentArgument = send;
242     GEOMBase_Skeleton::LineEditReturnPressed();
243   }
244 }
245
246
247 //=================================================================================
248 // function : ActivateThisDialog()
249 // purpose  :
250 //=================================================================================
251 void BasicGUI_ArcDlg::ActivateThisDialog()
252 {
253   GEOMBase_Skeleton::ActivateThisDialog();
254   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
255           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
256
257   // myGeomGUI->SetState( 0 );
258   globalSelection( GEOM_POINT );
259
260   myEditCurrentArgument = Group3Pnts->LineEdit1;
261   myEditCurrentArgument->setFocus();
262
263   Group3Pnts->LineEdit1->setText( "" );
264   Group3Pnts->LineEdit2->setText( "" );
265   Group3Pnts->LineEdit3->setText( "" );
266   myPoint1 = myPoint2 = myPoint3 = GEOM::GEOM_Object::_nil();
267 }
268
269 //=================================================================================
270 // function : DeactivateActiveDialog()
271 // purpose  : public slot to deactivate if active
272 //=================================================================================
273 void BasicGUI_ArcDlg::DeactivateActiveDialog()
274 {
275   // myGeomGUI->SetState( -1 );
276   GEOMBase_Skeleton::DeactivateActiveDialog();
277 }
278
279 //=================================================================================
280 // function : enterEvent()
281 // purpose  :
282 //=================================================================================
283 void BasicGUI_ArcDlg::enterEvent(QEvent* e)
284 {
285   if ( !GroupConstructors->isEnabled() )
286     ActivateThisDialog();
287 }
288
289 //=================================================================================
290 // function : createOperation
291 // purpose  :
292 //=================================================================================
293 GEOM::GEOM_IOperations_ptr BasicGUI_ArcDlg::createOperation()
294 {
295   return myGeomGUI->GetGeomGen()->GetICurvesOperations( getStudyId() );
296 }
297
298 //=================================================================================
299 // function : isEqual
300 // purpose  : it may also be needed to check for min distance between gp_Pnt-s...
301 //=================================================================================
302 static bool isEqual( const GEOM::GEOM_Object_var& thePnt1, const GEOM::GEOM_Object_var& thePnt2 )
303 {
304   return thePnt1->_is_equivalent( thePnt2 );
305 }
306
307 //=================================================================================
308 // function : isValid
309 // purpose  :
310 //=================================================================================
311 bool BasicGUI_ArcDlg::isValid( QString& msg )
312 {
313   return !myPoint1->_is_nil() && !myPoint2->_is_nil() && !myPoint3->_is_nil() &&
314     !isEqual( myPoint1, myPoint2 ) && !isEqual( myPoint1, myPoint3 ) && !isEqual( myPoint2, myPoint3 );
315 }
316
317 //=================================================================================
318 // function : execute
319 // purpose  :
320 //=================================================================================
321 bool BasicGUI_ArcDlg::execute( ObjectList& objects )
322 {
323   GEOM::GEOM_Object_var anObj =
324     GEOM::GEOM_ICurvesOperations::_narrow(getOperation())->MakeArc(myPoint1, myPoint2, myPoint3);
325   if ( !anObj->_is_nil() )
326     objects.push_back( anObj._retn() );
327   return true;
328 }
329
330 //=================================================================================
331 // function : closeEvent
332 // purpose  :
333 //=================================================================================
334 void BasicGUI_ArcDlg::closeEvent( QCloseEvent* e )
335 {
336   GEOMBase_Skeleton::closeEvent( e );
337 }