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