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