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