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