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 "QAD_Desktop.h"
33 #include "GEOMImpl_Types.hxx"
35 #include "utilities.h"
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)
49 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_DLG_LINE_2P")));
50 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_SELECT")));
52 setCaption(tr("GEOM_LINE_TITLE"));
54 /***************************************************************/
55 GroupConstructors->setTitle(tr("GEOM_LINE"));
56 RadioButton1->setPixmap(image0);
57 RadioButton2->close(TRUE);
58 RadioButton3->close(TRUE);
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);
67 GroupPoints->LineEdit1->setReadOnly( true );
68 GroupPoints->LineEdit2->setReadOnly( true );
70 Layout1->addWidget(GroupPoints, 2, 0);
71 /***************************************************************/
77 //=================================================================================
78 // function : ~BasicGUI_LineDlg()
79 // purpose : Destroys the object and frees any allocated resources
80 //=================================================================================
81 BasicGUI_LineDlg::~BasicGUI_LineDlg()
86 //=================================================================================
89 //=================================================================================
90 void BasicGUI_LineDlg::Init()
93 myEditCurrentArgument = GroupPoints->LineEdit1;
95 myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
97 myGeomGUI->SetState( 0 );
98 globalSelection( GEOM_POINT );
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()));
105 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
106 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
108 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
109 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
111 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
112 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
114 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
116 initName( tr("GEOM_LINE") );
120 //=================================================================================
121 // function : ClickOnOk()
123 //=================================================================================
124 void BasicGUI_LineDlg::ClickOnOk()
126 if ( ClickOnApply() )
130 //=======================================================================
131 // function : ClickOnCancel()
133 //=======================================================================
134 void BasicGUI_LineDlg::ClickOnCancel()
136 GEOMBase_Skeleton::ClickOnCancel();
139 //=================================================================================
140 // function : ClickOnApply()
142 //=================================================================================
143 bool BasicGUI_LineDlg::ClickOnApply()
153 //=================================================================================
154 // function : SelectionIntoArgument()
155 // purpose : Called when selection as changed or other case
156 //=================================================================================
157 void BasicGUI_LineDlg::SelectionIntoArgument()
159 myEditCurrentArgument->setText("");
161 if ( mySelection->IObjectCount() != 1 )
163 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) myPoint1 = GEOM::GEOM_Object::_nil();
164 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) myPoint2 = GEOM::GEOM_Object::_nil();
169 Standard_Boolean aRes = Standard_False;
170 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( mySelection->firstIObject(), aRes );
171 if ( !CORBA::is_nil( aSelectedObject ) && aRes )
173 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
174 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) myPoint1 = aSelectedObject;
175 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) myPoint2 = aSelectedObject;
182 //=================================================================================
183 // function : SetEditCurrentArgument()
185 //=================================================================================
186 void BasicGUI_LineDlg::SetEditCurrentArgument()
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();
196 //=================================================================================
197 // function : LineEditReturnPressed()
199 //=================================================================================
200 void BasicGUI_LineDlg::LineEditReturnPressed()
202 QLineEdit* send = (QLineEdit*)sender();
203 if ( send == GroupPoints->LineEdit1 ) myEditCurrentArgument = GroupPoints->LineEdit1;
204 else if ( send == GroupPoints->LineEdit2 ) myEditCurrentArgument = GroupPoints->LineEdit2;
206 GEOMBase_Skeleton::LineEditReturnPressed();
210 //=================================================================================
211 // function : ActivateThisDialog()
213 //=================================================================================
214 void BasicGUI_LineDlg::ActivateThisDialog()
216 GEOMBase_Skeleton::ActivateThisDialog();
217 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
219 myGeomGUI->SetState( 0 );
220 globalSelection( GEOM_POINT );
222 myEditCurrentArgument = GroupPoints->LineEdit1;
223 myEditCurrentArgument->setFocus();
225 GroupPoints->LineEdit1->setText( "" );
226 GroupPoints->LineEdit2->setText( "" );
227 myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
230 //=================================================================================
231 // function : DeactivateActiveDialog()
232 // purpose : public slot to deactivate if active
233 //=================================================================================
234 void BasicGUI_LineDlg::DeactivateActiveDialog()
236 myGeomGUI->SetState( -1 );
237 GEOMBase_Skeleton::DeactivateActiveDialog();
240 //=================================================================================
241 // function : enterEvent()
243 //=================================================================================
244 void BasicGUI_LineDlg::enterEvent(QEvent* e)
246 if ( !GroupConstructors->isEnabled() )
247 ActivateThisDialog();
250 //=================================================================================
251 // function : createOperation
253 //=================================================================================
254 GEOM::GEOM_IOperations_ptr BasicGUI_LineDlg::createOperation()
256 return getGeomEngine()->GetIBasicOperations( getStudyId() );
259 //=================================================================================
260 // function : isValid
262 //=================================================================================
263 bool BasicGUI_LineDlg::isValid( QString& msg )
265 return !myPoint1->_is_nil() && !myPoint2->_is_nil();
268 //=================================================================================
269 // function : execute
271 //=================================================================================
272 bool BasicGUI_LineDlg::execute( ObjectList& objects )
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() );
280 //=================================================================================
281 // function : closeEvent
283 //=================================================================================
284 void BasicGUI_LineDlg::closeEvent( QCloseEvent* e )
286 myGeomGUI->SetState( -1 );
287 GEOMBase_Skeleton::closeEvent( e );