]> SALOME platform Git repositories - modules/geom.git/blob - src/BasicGUI/BasicGUI_LineDlg.cxx
Salome HOME
SMH: Merged GEOM (NEWGUI, HEAD, POLYWORK)
[modules/geom.git] / src / BasicGUI / BasicGUI_LineDlg.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   : BasicGUI_LineDlg.cxx
25 //  Author : Lucien PIGNOLONI
26 //  Module : GEOM
27 //  $Header$
28
29 #include "BasicGUI_LineDlg.h"
30
31 #include "SUIT_Desktop.h"
32 #include "SUIT_Session.h"
33 #include "SalomeApp_Application.h"
34 #include "SalomeApp_SelectionMgr.h"
35
36 #include <qlabel.h>
37
38 #include "GEOMImpl_Types.hxx"
39
40 #include "utilities.h"
41
42 using namespace std;
43
44 //=================================================================================
45 // class    : BasicGUI_LineDlg()
46 // purpose  : Constructs a BasicGUI_LineDlg which is a child of 'parent', with the 
47 //            name 'name' and widget flags set to 'f'.
48 //            The dialog will by default be modeless, unless you set 'modal' to
49 //            TRUE to construct a modal dialog.
50 //=================================================================================
51 BasicGUI_LineDlg::BasicGUI_LineDlg(GeometryGUI* theGeometryGUI, QWidget* parent, const char* name, bool modal, WFlags fl)
52   :GEOMBase_Skeleton(parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu), myGeometryGUI(theGeometryGUI)
53 {
54   QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM",tr("ICON_DLG_LINE_2P")));
55   QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM",tr("ICON_SELECT")));
56
57   setCaption(tr("GEOM_LINE_TITLE"));
58
59   /***************************************************************/
60   GroupConstructors->setTitle(tr("GEOM_LINE"));
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   Init();
79 }
80
81
82 //=================================================================================
83 // function : ~BasicGUI_LineDlg()
84 // purpose  : Destroys the object and frees any allocated resources
85 //=================================================================================
86 BasicGUI_LineDlg::~BasicGUI_LineDlg()
87 {  
88 }
89
90
91 //=================================================================================
92 // function : Init()
93 // purpose  :
94 //=================================================================================
95 void BasicGUI_LineDlg::Init()
96 {
97   /* init variables */
98   myEditCurrentArgument = GroupPoints->LineEdit1;
99
100   myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
101
102   // myGeometryGUI->SetState( 0 );
103   globalSelection( GEOM_POINT );
104         
105   /* signals and slots connections */
106   connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
107   connect(myGeometryGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
108   connect(myGeometryGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
109
110   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
111   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
112
113   connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
114   connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
115
116   connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
117   connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
118
119   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
120           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
121   
122   initName( tr("GEOM_LINE") );
123 }
124
125
126 //=================================================================================
127 // function : ClickOnOk()
128 // purpose  :
129 //=================================================================================
130 void BasicGUI_LineDlg::ClickOnOk()
131 {
132   if ( ClickOnApply() )
133     ClickOnCancel();
134 }
135
136 //=======================================================================
137 // function : ClickOnCancel()
138 // purpose  :
139 //=======================================================================
140 void BasicGUI_LineDlg::ClickOnCancel()
141 {
142   GEOMBase_Skeleton::ClickOnCancel();
143 }
144
145 //=================================================================================
146 // function : ClickOnApply()
147 // purpose  :
148 //=================================================================================
149 bool BasicGUI_LineDlg::ClickOnApply()
150 {
151   if ( !onAccept() )
152     return false;
153   
154   initName();
155   return true;
156 }
157
158
159 //=================================================================================
160 // function : SelectionIntoArgument()
161 // purpose  : Called when selection as changed or other case
162 //=================================================================================
163 void BasicGUI_LineDlg::SelectionIntoArgument()
164 {
165   myEditCurrentArgument->setText("");
166
167   if ( IObjectCount() != 1 ) 
168   {
169     if ( myEditCurrentArgument == GroupPoints->LineEdit1 )      myPoint1 = GEOM::GEOM_Object::_nil();
170     else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) myPoint2 = GEOM::GEOM_Object::_nil();
171     return;
172   }
173
174   // nbSel == 1 
175   Standard_Boolean aRes = Standard_False;
176   GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), aRes );
177   if ( !CORBA::is_nil( aSelectedObject ) && aRes )
178   {
179     myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
180     if      ( myEditCurrentArgument == GroupPoints->LineEdit1 ) myPoint1 = aSelectedObject;
181     else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) myPoint2 = aSelectedObject;
182   }
183   
184   displayPreview();
185 }
186
187
188 //=================================================================================
189 // function : SetEditCurrentArgument()
190 // purpose  :
191 //=================================================================================
192 void BasicGUI_LineDlg::SetEditCurrentArgument()
193 {
194   QPushButton* send = (QPushButton*)sender();
195   if      ( send == GroupPoints->PushButton1 ) myEditCurrentArgument = GroupPoints->LineEdit1;
196   else if ( send == GroupPoints->PushButton2 ) myEditCurrentArgument = GroupPoints->LineEdit2;
197   myEditCurrentArgument->setFocus();
198   SelectionIntoArgument();
199 }
200
201
202 //=================================================================================
203 // function : LineEditReturnPressed()
204 // purpose  :
205 //=================================================================================
206 void BasicGUI_LineDlg::LineEditReturnPressed()
207 {
208   QLineEdit* send = (QLineEdit*)sender();
209   if      ( send == GroupPoints->LineEdit1 ) myEditCurrentArgument = GroupPoints->LineEdit1;
210   else if ( send == GroupPoints->LineEdit2 ) myEditCurrentArgument = GroupPoints->LineEdit2;
211   else return;
212   GEOMBase_Skeleton::LineEditReturnPressed();
213 }
214
215
216 //=================================================================================
217 // function : ActivateThisDialog()
218 // purpose  :
219 //=================================================================================
220 void BasicGUI_LineDlg::ActivateThisDialog()
221 {
222   GEOMBase_Skeleton::ActivateThisDialog();
223   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
224           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
225
226   // myGeometryGUI->SetState( 0 );
227   globalSelection( GEOM_POINT );
228
229   myEditCurrentArgument = GroupPoints->LineEdit1;
230   myEditCurrentArgument->setFocus();
231
232   GroupPoints->LineEdit1->setText( "" );
233   GroupPoints->LineEdit2->setText( "" );
234   myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
235 }
236
237 //=================================================================================
238 // function : DeactivateActiveDialog()
239 // purpose  : public slot to deactivate if active
240 //=================================================================================
241 void BasicGUI_LineDlg::DeactivateActiveDialog()
242 {
243   // myGeometryGUI->SetState( -1 );
244   GEOMBase_Skeleton::DeactivateActiveDialog();
245 }
246
247 //=================================================================================
248 // function : enterEvent()
249 // purpose  :
250 //=================================================================================
251 void BasicGUI_LineDlg::enterEvent(QEvent* e)
252 {
253   if ( !GroupConstructors->isEnabled() )
254     ActivateThisDialog();
255 }
256
257 //=================================================================================
258 // function : createOperation
259 // purpose  :
260 //=================================================================================
261 GEOM::GEOM_IOperations_ptr BasicGUI_LineDlg::createOperation()
262 {
263   return myGeometryGUI->GetGeomGen()->GetIBasicOperations( getStudyId() );
264 }
265
266 //=================================================================================
267 // function : isValid
268 // purpose  :
269 //=================================================================================
270 bool BasicGUI_LineDlg::isValid( QString& msg )
271 {
272   return !myPoint1->_is_nil() && !myPoint2->_is_nil();
273 }
274
275 //=================================================================================
276 // function : execute
277 // purpose  :
278 //=================================================================================
279 bool BasicGUI_LineDlg::execute( ObjectList& objects )
280 {
281   GEOM::GEOM_Object_var anObj = GEOM::GEOM_IBasicOperations::_narrow( getOperation() )->MakeLineTwoPnt( myPoint1, myPoint2 );
282   if ( !anObj->_is_nil() )
283     objects.push_back( anObj._retn() );
284   return true;
285 }
286
287 //=================================================================================
288 // function : closeEvent
289 // purpose  :
290 //=================================================================================
291 void BasicGUI_LineDlg::closeEvent( QCloseEvent* e )
292 {
293   // myGeometryGUI->SetState( -1 );
294   GEOMBase_Skeleton::closeEvent( e );
295 }
296