Salome HOME
ae81504074ebac116fb5076b892c48b5443e4b96
[modules/geom.git] / src / BuildGUI / BuildGUI_EdgeDlg.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   : BuildGUI_EdgeDlg.cxx
25 //  Author : Lucien PIGNOLONI
26 //  Module : GEOM
27 //  $Header$
28
29 #include "BuildGUI_EdgeDlg.h"
30
31 #include <BRepBuilderAPI_MakeEdge.hxx>
32 #include <Precision.hxx>
33
34 #include "utilities.h"
35 #include "GEOMImpl_Types.hxx"
36
37 #include "SUIT_Session.h"
38 #include "SalomeApp_Application.h"
39 #include "SalomeApp_SelectionMgr.h"
40
41 #include <qlabel.h>
42
43 //=================================================================================
44 // class    : BuildGUI_EdgeDlg()
45 // purpose  : Constructs a BuildGUI_EdgeDlg which is a child of 'parent', with the 
46 //            name 'name' and widget flags set to 'f'.
47 //            The dialog will by default be modeless, unless you set 'modal' to
48 //            TRUE to construct a modal dialog.
49 //=================================================================================
50 BuildGUI_EdgeDlg::BuildGUI_EdgeDlg(QWidget* parent, const char* name, bool modal, WFlags fl)
51   :GEOMBase_Skeleton(parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
52 {
53   QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_BUILD_EDGE")));
54   QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
55
56   setCaption(tr("GEOM_EDGE_TITLE"));
57
58   /***************************************************************/
59   GroupConstructors->setTitle(tr("GEOM_EDGE"));
60   RadioButton1->setPixmap(image0);
61   RadioButton2->close(TRUE);
62   RadioButton3->close(TRUE);
63
64   GroupPoints = new DlgRef_2Sel_QTD(this, "GroupPoints");
65   GroupPoints->GroupBox1->setTitle(tr("GEOM_POINTS"));
66   GroupPoints->TextLabel1->setText(tr("GEOM_POINT_I").arg("1"));
67   GroupPoints->TextLabel2->setText(tr("GEOM_POINT_I").arg("2"));
68   GroupPoints->PushButton1->setPixmap(image1);
69   GroupPoints->PushButton2->setPixmap(image1);
70   
71   GroupPoints->LineEdit1->setReadOnly( true );
72   GroupPoints->LineEdit2->setReadOnly( true );
73
74   Layout1->addWidget(GroupPoints, 2, 0);
75   /***************************************************************/
76
77   /* Initialisations */
78   Init();
79 }
80
81
82 //=================================================================================
83 // function : ~BuildGUI_EdgeDlg()
84 // purpose  : Destroys the object and frees any allocated resources
85 //=================================================================================
86 BuildGUI_EdgeDlg::~BuildGUI_EdgeDlg()
87 {
88     // no need to delete child widgets, Qt does it all for us
89 }
90
91
92 //=================================================================================
93 // function : Init()
94 // purpose  :
95 //=================================================================================
96 void BuildGUI_EdgeDlg::Init()
97 {
98   /* init variables */
99   myEditCurrentArgument = GroupPoints->LineEdit1;
100   GroupPoints->LineEdit1->setReadOnly( true );
101   GroupPoints->LineEdit2->setReadOnly( true );
102
103   myOkPoint1 = myOkPoint2 = false;
104
105   globalSelection( GEOM_POINT );
106
107   /* signals and slots connections */
108   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
109   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
110
111   connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
112   connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
113
114   connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
115   connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
116   
117   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
118           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
119
120   initName( tr( "GEOM_EDGE") );
121 }
122
123
124 //=================================================================================
125 // function : ClickOnOk()
126 // purpose  :
127 //=================================================================================
128 void BuildGUI_EdgeDlg::ClickOnOk()
129 {
130   if ( ClickOnApply() )
131     ClickOnCancel();
132 }
133
134
135 //=================================================================================
136 // function : ClickOnApply()
137 // purpose  :
138 //=================================================================================
139 bool BuildGUI_EdgeDlg::ClickOnApply()
140 {
141   if ( !onAccept() )
142     return false;
143
144   initName();
145   return true;
146 }
147
148
149 //=================================================================================
150 // function : SelectionIntoArgument()
151 // purpose  : Called when selection as changed or other case
152 //=================================================================================
153 void BuildGUI_EdgeDlg::SelectionIntoArgument()
154 {
155   erasePreview();
156   myEditCurrentArgument->setText("");
157   
158   if(IObjectCount() != 1) {
159     if(myEditCurrentArgument == GroupPoints->LineEdit1)
160       myOkPoint1 = false;
161     else if(myEditCurrentArgument == GroupPoints->LineEdit2)
162       myOkPoint2 = false;
163     return;
164   }
165   
166   // nbSel == 1
167   Standard_Boolean testResult = Standard_False;
168   GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult );
169   
170   if(!testResult)
171     return;
172
173   if(myEditCurrentArgument == GroupPoints->LineEdit1) {
174     myPoint1 = aSelectedObject;
175     myOkPoint1 = true;
176   }
177   else if(myEditCurrentArgument == GroupPoints->LineEdit2) {
178     myPoint2 = aSelectedObject;
179     myOkPoint2 = true;
180   }
181   
182   myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
183   
184   displayPreview();
185 }
186
187
188 //=================================================================================
189 // function : LineEditReturnPressed()
190 // purpose  :
191 //=================================================================================
192 void BuildGUI_EdgeDlg::LineEditReturnPressed()
193 {
194   QLineEdit* send = (QLineEdit*)sender();
195   if(send == GroupPoints->LineEdit1 || send == GroupPoints->LineEdit2)
196     {
197       myEditCurrentArgument = send;
198       GEOMBase_Skeleton::LineEditReturnPressed();
199     }
200 }
201
202
203 //=================================================================================
204 // function : SetEditCurrentArgument()
205 // purpose  :
206 //=================================================================================
207 void BuildGUI_EdgeDlg::SetEditCurrentArgument()
208 {
209   
210   QPushButton* send = (QPushButton*)sender();
211   globalSelection();
212
213   if(send == GroupPoints->PushButton1) {
214     myEditCurrentArgument = GroupPoints->LineEdit1;
215     globalSelection( GEOM_POINT );
216   }
217   else if(send == GroupPoints->PushButton2) {
218     myEditCurrentArgument = GroupPoints->LineEdit2;
219     globalSelection( GEOM_POINT );
220   }
221   
222   myEditCurrentArgument->setFocus();
223   SelectionIntoArgument();
224 }
225
226
227 //=================================================================================
228 // function : ActivateThisDialog()
229 // purpose  :
230 //=================================================================================
231 void BuildGUI_EdgeDlg::ActivateThisDialog()
232 {
233   GEOMBase_Skeleton::ActivateThisDialog();
234   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
235           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
236   globalSelection( GEOM_POINT );
237   displayPreview();
238 }
239
240
241 //=================================================================================
242 // function : enterEvent()
243 // purpose  :
244 //=================================================================================
245 void BuildGUI_EdgeDlg::enterEvent(QEvent* e)
246 {
247   if ( !GroupConstructors->isEnabled() )
248     ActivateThisDialog();
249 }
250
251 //=================================================================================
252 // function : createOperation
253 // purpose  :
254 //=================================================================================
255 GEOM::GEOM_IOperations_ptr BuildGUI_EdgeDlg::createOperation()
256 {
257   return getGeomEngine()->GetIShapesOperations( getStudyId() );
258 }
259
260 //=================================================================================
261 // function : isValid
262 // purpose  :
263 //=================================================================================
264 bool BuildGUI_EdgeDlg::isValid( QString& )
265 {
266   return myOkPoint1 && myOkPoint2;
267 }
268
269 //=================================================================================
270 // function : execute
271 // purpose  :
272 //=================================================================================
273 bool BuildGUI_EdgeDlg::execute( ObjectList& objects )
274 {
275   GEOM::GEOM_Object_var anObj;
276
277   anObj = GEOM::GEOM_IShapesOperations::_narrow( getOperation() )->MakeEdge( myPoint1, myPoint2 );
278
279   if ( !anObj->_is_nil() )
280     objects.push_back( anObj._retn() );
281
282   return true;
283 }