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