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