1 // GEOM GEOMGUI : GUI for Geometry component
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : BasicGUI_LineDlg.cxx
25 // Author : Lucien PIGNOLONI
29 #include "BasicGUI_LineDlg.h"
31 #include "SUIT_Desktop.h"
32 #include "SUIT_Session.h"
33 #include "SalomeApp_Application.h"
34 #include "LightApp_SelectionMgr.h"
38 #include "GEOMImpl_Types.hxx"
40 #include "utilities.h"
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)
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")));
57 setCaption(tr("GEOM_LINE_TITLE"));
59 /***************************************************************/
60 GroupConstructors->setTitle(tr("GEOM_LINE"));
61 RadioButton1->setPixmap(image0);
62 RadioButton2->close(TRUE);
63 RadioButton3->close(TRUE);
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);
72 GroupPoints->LineEdit1->setReadOnly( true );
73 GroupPoints->LineEdit2->setReadOnly( true );
75 Layout1->addWidget(GroupPoints, 2, 0);
76 /***************************************************************/
82 //=================================================================================
83 // function : ~BasicGUI_LineDlg()
84 // purpose : Destroys the object and frees any allocated resources
85 //=================================================================================
86 BasicGUI_LineDlg::~BasicGUI_LineDlg()
91 //=================================================================================
94 //=================================================================================
95 void BasicGUI_LineDlg::Init()
98 myEditCurrentArgument = GroupPoints->LineEdit1;
100 myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
102 // myGeometryGUI->SetState( 0 );
103 globalSelection( GEOM_POINT );
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()));
110 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
111 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
113 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
114 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
116 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
117 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
119 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
120 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
122 initName( tr("GEOM_LINE") );
126 //=================================================================================
127 // function : ClickOnOk()
129 //=================================================================================
130 void BasicGUI_LineDlg::ClickOnOk()
132 if ( ClickOnApply() )
136 //=======================================================================
137 // function : ClickOnCancel()
139 //=======================================================================
140 void BasicGUI_LineDlg::ClickOnCancel()
142 GEOMBase_Skeleton::ClickOnCancel();
145 //=================================================================================
146 // function : ClickOnApply()
148 //=================================================================================
149 bool BasicGUI_LineDlg::ClickOnApply()
159 //=================================================================================
160 // function : SelectionIntoArgument()
161 // purpose : Called when selection as changed or other case
162 //=================================================================================
163 void BasicGUI_LineDlg::SelectionIntoArgument()
165 myEditCurrentArgument->setText("");
167 if ( IObjectCount() != 1 )
169 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) myPoint1 = GEOM::GEOM_Object::_nil();
170 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) myPoint2 = GEOM::GEOM_Object::_nil();
175 Standard_Boolean aRes = Standard_False;
176 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), aRes );
177 if ( !CORBA::is_nil( aSelectedObject ) && aRes )
179 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
180 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) myPoint1 = aSelectedObject;
181 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) myPoint2 = aSelectedObject;
188 //=================================================================================
189 // function : SetEditCurrentArgument()
191 //=================================================================================
192 void BasicGUI_LineDlg::SetEditCurrentArgument()
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();
202 //=================================================================================
203 // function : LineEditReturnPressed()
205 //=================================================================================
206 void BasicGUI_LineDlg::LineEditReturnPressed()
208 QLineEdit* send = (QLineEdit*)sender();
209 if ( send == GroupPoints->LineEdit1 ) myEditCurrentArgument = GroupPoints->LineEdit1;
210 else if ( send == GroupPoints->LineEdit2 ) myEditCurrentArgument = GroupPoints->LineEdit2;
212 GEOMBase_Skeleton::LineEditReturnPressed();
216 //=================================================================================
217 // function : ActivateThisDialog()
219 //=================================================================================
220 void BasicGUI_LineDlg::ActivateThisDialog()
222 GEOMBase_Skeleton::ActivateThisDialog();
223 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
224 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
226 // myGeometryGUI->SetState( 0 );
227 globalSelection( GEOM_POINT );
229 myEditCurrentArgument = GroupPoints->LineEdit1;
230 myEditCurrentArgument->setFocus();
232 GroupPoints->LineEdit1->setText( "" );
233 GroupPoints->LineEdit2->setText( "" );
234 myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
237 //=================================================================================
238 // function : DeactivateActiveDialog()
239 // purpose : public slot to deactivate if active
240 //=================================================================================
241 void BasicGUI_LineDlg::DeactivateActiveDialog()
243 // myGeometryGUI->SetState( -1 );
244 GEOMBase_Skeleton::DeactivateActiveDialog();
247 //=================================================================================
248 // function : enterEvent()
250 //=================================================================================
251 void BasicGUI_LineDlg::enterEvent(QEvent* e)
253 if ( !GroupConstructors->isEnabled() )
254 ActivateThisDialog();
257 //=================================================================================
258 // function : createOperation
260 //=================================================================================
261 GEOM::GEOM_IOperations_ptr BasicGUI_LineDlg::createOperation()
263 return myGeometryGUI->GetGeomGen()->GetIBasicOperations( getStudyId() );
266 //=================================================================================
267 // function : isValid
269 //=================================================================================
270 bool BasicGUI_LineDlg::isValid( QString& msg )
272 return !myPoint1->_is_nil() && !myPoint2->_is_nil();
275 //=================================================================================
276 // function : execute
278 //=================================================================================
279 bool BasicGUI_LineDlg::execute( ObjectList& objects )
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() );
287 //=================================================================================
288 // function : closeEvent
290 //=================================================================================
291 void BasicGUI_LineDlg::closeEvent( QCloseEvent* e )
293 // myGeometryGUI->SetState( -1 );
294 GEOMBase_Skeleton::closeEvent( e );