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