Salome HOME
Porting to Qt4.
[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.salome-platform.org/ or email : webmaster.salome@opencascade.com
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 "GeometryGUI.h"
32 #include "GEOMBase.h"
33
34 #include "SUIT_ResourceMgr.h"
35 #include "SUIT_Session.h"
36 #include "SalomeApp_Application.h"
37 #include "LightApp_SelectionMgr.h"
38
39 #include "GEOMImpl_Types.hxx"
40
41 using namespace std;
42
43 //=================================================================================
44 // class    : BasicGUI_LineDlg()
45 // purpose  : Constructs a BasicGUI_LineDlg 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 BasicGUI_LineDlg::BasicGUI_LineDlg(GeometryGUI* theGeometryGUI, QWidget* parent,
51                                    const char* name, bool modal, Qt::WindowFlags fl)
52   :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, Qt::WindowTitleHint | Qt::WindowSystemMenuHint)
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   setWindowTitle(tr("GEOM_LINE_TITLE"));
58
59   /***************************************************************/
60   GroupConstructors->setTitle(tr("GEOM_LINE"));
61   RadioButton1->setIcon(image0);
62   RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
63   RadioButton2->close();
64   RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
65   RadioButton3->close();
66
67   GroupPoints = new Ui::DlgRef_2Sel_QTD();
68   QWidget* aGroupPointsWidget = new QWidget(this);
69   GroupPoints->setupUi(aGroupPointsWidget);
70   aGroupPointsWidget->setObjectName("GroupPoints");
71
72   GroupPoints->GroupBox1->setTitle(tr("GEOM_POINTS"));
73   GroupPoints->TextLabel1->setText(tr("GEOM_POINT_I").arg("1"));
74   GroupPoints->TextLabel2->setText(tr("GEOM_POINT_I").arg("2"));
75   GroupPoints->PushButton1->setIcon(image1);
76   GroupPoints->PushButton2->setIcon(image1);
77
78   GroupPoints->LineEdit1->setReadOnly( true );
79   GroupPoints->LineEdit2->setReadOnly( true );
80
81   gridLayout1->addWidget(aGroupPointsWidget, 2, 0);
82   /***************************************************************/
83
84   setHelpFileName("line.htm");
85
86   Init();
87 }
88
89
90 //=================================================================================
91 // function : ~BasicGUI_LineDlg()
92 // purpose  : Destroys the object and frees any allocated resources
93 //=================================================================================
94 BasicGUI_LineDlg::~BasicGUI_LineDlg()
95 {  
96 }
97
98
99 //=================================================================================
100 // function : Init()
101 // purpose  :
102 //=================================================================================
103 void BasicGUI_LineDlg::Init()
104 {
105   /* init variables */
106   myEditCurrentArgument = GroupPoints->LineEdit1;
107
108   myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
109
110   // myGeomGUI->SetState( 0 );
111   globalSelection( GEOM_POINT );
112         
113   /* signals and slots connections */
114   connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
115   connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
116   connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
117
118   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
119   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
120
121   connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
122   connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
123
124   connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
125   connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
126
127   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
128           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
129   
130   initName( tr("GEOM_LINE").toLatin1().constData() );
131 }
132
133
134 //=================================================================================
135 // function : ClickOnOk()
136 // purpose  :
137 //=================================================================================
138 void BasicGUI_LineDlg::ClickOnOk()
139 {
140   if ( ClickOnApply() )
141     ClickOnCancel();
142 }
143
144 //=======================================================================
145 // function : ClickOnCancel()
146 // purpose  :
147 //=======================================================================
148 void BasicGUI_LineDlg::ClickOnCancel()
149 {
150   GEOMBase_Skeleton::ClickOnCancel();
151 }
152
153 //=================================================================================
154 // function : ClickOnApply()
155 // purpose  :
156 //=================================================================================
157 bool BasicGUI_LineDlg::ClickOnApply()
158 {
159   if ( !onAccept() )
160     return false;
161   
162   initName();
163   return true;
164 }
165
166
167 //=================================================================================
168 // function : SelectionIntoArgument()
169 // purpose  : Called when selection as changed or other case
170 //=================================================================================
171 void BasicGUI_LineDlg::SelectionIntoArgument()
172 {
173   myEditCurrentArgument->setText("");
174
175   if ( IObjectCount() != 1 ) 
176   {
177     if ( myEditCurrentArgument == GroupPoints->LineEdit1 )      myPoint1 = GEOM::GEOM_Object::_nil();
178     else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) myPoint2 = GEOM::GEOM_Object::_nil();
179     return;
180   }
181
182   // nbSel == 1 
183   Standard_Boolean aRes = Standard_False;
184   GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), aRes );
185   if ( !CORBA::is_nil( aSelectedObject ) && aRes )
186   {
187     myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
188     if      ( myEditCurrentArgument == GroupPoints->LineEdit1 ) myPoint1 = aSelectedObject;
189     else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) myPoint2 = aSelectedObject;
190   }
191   
192   displayPreview();
193 }
194
195
196 //=================================================================================
197 // function : SetEditCurrentArgument()
198 // purpose  :
199 //=================================================================================
200 void BasicGUI_LineDlg::SetEditCurrentArgument()
201 {
202   QPushButton* send = (QPushButton*)sender();
203   if      ( send == GroupPoints->PushButton1 ) myEditCurrentArgument = GroupPoints->LineEdit1;
204   else if ( send == GroupPoints->PushButton2 ) myEditCurrentArgument = GroupPoints->LineEdit2;
205   myEditCurrentArgument->setFocus();
206   SelectionIntoArgument();
207 }
208
209
210 //=================================================================================
211 // function : LineEditReturnPressed()
212 // purpose  :
213 //=================================================================================
214 void BasicGUI_LineDlg::LineEditReturnPressed()
215 {
216   QLineEdit* send = (QLineEdit*)sender();
217   if      ( send == GroupPoints->LineEdit1 ) myEditCurrentArgument = GroupPoints->LineEdit1;
218   else if ( send == GroupPoints->LineEdit2 ) myEditCurrentArgument = GroupPoints->LineEdit2;
219   else return;
220   GEOMBase_Skeleton::LineEditReturnPressed();
221 }
222
223
224 //=================================================================================
225 // function : ActivateThisDialog()
226 // purpose  :
227 //=================================================================================
228 void BasicGUI_LineDlg::ActivateThisDialog()
229 {
230   GEOMBase_Skeleton::ActivateThisDialog();
231   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
232           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
233
234   // myGeomGUI->SetState( 0 );
235   globalSelection( GEOM_POINT );
236
237   myEditCurrentArgument = GroupPoints->LineEdit1;
238   myEditCurrentArgument->setFocus();
239
240   GroupPoints->LineEdit1->setText( "" );
241   GroupPoints->LineEdit2->setText( "" );
242   myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
243 }
244
245 //=================================================================================
246 // function : DeactivateActiveDialog()
247 // purpose  : public slot to deactivate if active
248 //=================================================================================
249 void BasicGUI_LineDlg::DeactivateActiveDialog()
250 {
251   // myGeomGUI->SetState( -1 );
252   GEOMBase_Skeleton::DeactivateActiveDialog();
253 }
254
255 //=================================================================================
256 // function : enterEvent()
257 // purpose  :
258 //=================================================================================
259 void BasicGUI_LineDlg::enterEvent(QEvent* e)
260 {
261   if ( !GroupConstructors->isEnabled() )
262     ActivateThisDialog();
263 }
264
265 //=================================================================================
266 // function : createOperation
267 // purpose  :
268 //=================================================================================
269 GEOM::GEOM_IOperations_ptr BasicGUI_LineDlg::createOperation()
270 {
271   return myGeomGUI->GetGeomGen()->GetIBasicOperations( getStudyId() );
272 }
273
274 //=================================================================================
275 // function : isValid
276 // purpose  :
277 //=================================================================================
278 bool BasicGUI_LineDlg::isValid( QString& msg )
279 {
280   return !myPoint1->_is_nil() && !myPoint2->_is_nil();
281 }
282
283 //=================================================================================
284 // function : execute
285 // purpose  :
286 //=================================================================================
287 bool BasicGUI_LineDlg::execute( ObjectList& objects )
288 {
289   GEOM::GEOM_Object_var anObj = GEOM::GEOM_IBasicOperations::_narrow( getOperation() )->MakeLineTwoPnt( myPoint1, myPoint2 );
290   if ( !anObj->_is_nil() )
291     objects.push_back( anObj._retn() );
292   return true;
293 }
294
295 //=================================================================================
296 // function : closeEvent
297 // purpose  :
298 //=================================================================================
299 void BasicGUI_LineDlg::closeEvent( QCloseEvent* e )
300 {
301   GEOMBase_Skeleton::closeEvent( e );
302 }
303