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.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 // File : BasicGUI_LineDlg.cxx
25 // Author : Lucien PIGNOLONI
29 #include "BasicGUI_LineDlg.h"
31 #include "GeometryGUI.h"
34 #include "SUIT_ResourceMgr.h"
35 #include "SUIT_Session.h"
36 #include "SalomeApp_Application.h"
37 #include "LightApp_SelectionMgr.h"
39 #include "GEOMImpl_Types.hxx"
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)
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 setWindowTitle(tr("GEOM_LINE_TITLE"));
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();
67 GroupPoints = new Ui::DlgRef_2Sel_QTD();
68 QWidget* aGroupPointsWidget = new QWidget(this);
69 GroupPoints->setupUi(aGroupPointsWidget);
70 aGroupPointsWidget->setObjectName("GroupPoints");
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);
78 GroupPoints->LineEdit1->setReadOnly( true );
79 GroupPoints->LineEdit2->setReadOnly( true );
81 gridLayout1->addWidget(aGroupPointsWidget, 2, 0);
82 /***************************************************************/
84 setHelpFileName("line.htm");
90 //=================================================================================
91 // function : ~BasicGUI_LineDlg()
92 // purpose : Destroys the object and frees any allocated resources
93 //=================================================================================
94 BasicGUI_LineDlg::~BasicGUI_LineDlg()
99 //=================================================================================
102 //=================================================================================
103 void BasicGUI_LineDlg::Init()
106 myEditCurrentArgument = GroupPoints->LineEdit1;
108 myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
110 // myGeomGUI->SetState( 0 );
111 globalSelection( GEOM_POINT );
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()));
118 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
119 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
121 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
122 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
124 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
125 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
127 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
128 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
130 initName( tr("GEOM_LINE").toLatin1().constData() );
134 //=================================================================================
135 // function : ClickOnOk()
137 //=================================================================================
138 void BasicGUI_LineDlg::ClickOnOk()
140 if ( ClickOnApply() )
144 //=======================================================================
145 // function : ClickOnCancel()
147 //=======================================================================
148 void BasicGUI_LineDlg::ClickOnCancel()
150 GEOMBase_Skeleton::ClickOnCancel();
153 //=================================================================================
154 // function : ClickOnApply()
156 //=================================================================================
157 bool BasicGUI_LineDlg::ClickOnApply()
167 //=================================================================================
168 // function : SelectionIntoArgument()
169 // purpose : Called when selection as changed or other case
170 //=================================================================================
171 void BasicGUI_LineDlg::SelectionIntoArgument()
173 myEditCurrentArgument->setText("");
175 if ( IObjectCount() != 1 )
177 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) myPoint1 = GEOM::GEOM_Object::_nil();
178 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) myPoint2 = GEOM::GEOM_Object::_nil();
183 Standard_Boolean aRes = Standard_False;
184 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), aRes );
185 if ( !CORBA::is_nil( aSelectedObject ) && aRes )
187 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
188 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) myPoint1 = aSelectedObject;
189 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) myPoint2 = aSelectedObject;
196 //=================================================================================
197 // function : SetEditCurrentArgument()
199 //=================================================================================
200 void BasicGUI_LineDlg::SetEditCurrentArgument()
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();
210 //=================================================================================
211 // function : LineEditReturnPressed()
213 //=================================================================================
214 void BasicGUI_LineDlg::LineEditReturnPressed()
216 QLineEdit* send = (QLineEdit*)sender();
217 if ( send == GroupPoints->LineEdit1 ) myEditCurrentArgument = GroupPoints->LineEdit1;
218 else if ( send == GroupPoints->LineEdit2 ) myEditCurrentArgument = GroupPoints->LineEdit2;
220 GEOMBase_Skeleton::LineEditReturnPressed();
224 //=================================================================================
225 // function : ActivateThisDialog()
227 //=================================================================================
228 void BasicGUI_LineDlg::ActivateThisDialog()
230 GEOMBase_Skeleton::ActivateThisDialog();
231 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
232 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
234 // myGeomGUI->SetState( 0 );
235 globalSelection( GEOM_POINT );
237 myEditCurrentArgument = GroupPoints->LineEdit1;
238 myEditCurrentArgument->setFocus();
240 GroupPoints->LineEdit1->setText( "" );
241 GroupPoints->LineEdit2->setText( "" );
242 myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
245 //=================================================================================
246 // function : DeactivateActiveDialog()
247 // purpose : public slot to deactivate if active
248 //=================================================================================
249 void BasicGUI_LineDlg::DeactivateActiveDialog()
251 // myGeomGUI->SetState( -1 );
252 GEOMBase_Skeleton::DeactivateActiveDialog();
255 //=================================================================================
256 // function : enterEvent()
258 //=================================================================================
259 void BasicGUI_LineDlg::enterEvent(QEvent* e)
261 if ( !GroupConstructors->isEnabled() )
262 ActivateThisDialog();
265 //=================================================================================
266 // function : createOperation
268 //=================================================================================
269 GEOM::GEOM_IOperations_ptr BasicGUI_LineDlg::createOperation()
271 return myGeomGUI->GetGeomGen()->GetIBasicOperations( getStudyId() );
274 //=================================================================================
275 // function : isValid
277 //=================================================================================
278 bool BasicGUI_LineDlg::isValid( QString& msg )
280 return !myPoint1->_is_nil() && !myPoint2->_is_nil();
283 //=================================================================================
284 // function : execute
286 //=================================================================================
287 bool BasicGUI_LineDlg::execute( ObjectList& objects )
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() );
295 //=================================================================================
296 // function : closeEvent
298 //=================================================================================
299 void BasicGUI_LineDlg::closeEvent( QCloseEvent* e )
301 GEOMBase_Skeleton::closeEvent( e );