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 : BuildGUI_EdgeDlg.cxx
25 // Author : Lucien PIGNOLONI
29 #include "BuildGUI_EdgeDlg.h"
31 #include "GeometryGUI.h"
34 #include "GEOMImpl_Types.hxx"
36 #include "SUIT_ResourceMgr.h"
37 #include "SUIT_Session.h"
38 #include "SalomeApp_Application.h"
39 #include "LightApp_SelectionMgr.h"
41 //=================================================================================
42 // class : BuildGUI_EdgeDlg()
43 // purpose : Constructs a BuildGUI_EdgeDlg which is a child of 'parent', with the
44 // name 'name' and widget flags set to 'f'.
45 // The dialog will by default be modeless, unless you set 'modal' to
46 // TRUE to construct a modal dialog.
47 //=================================================================================
48 BuildGUI_EdgeDlg::BuildGUI_EdgeDlg(GeometryGUI* theGeometryGUI, QWidget* parent,
49 const char* name, bool modal, Qt::WindowFlags fl)
50 :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, Qt::WindowTitleHint | Qt::WindowSystemMenuHint)
52 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_BUILD_EDGE")));
53 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
55 setWindowTitle(tr("GEOM_EDGE_TITLE"));
57 /***************************************************************/
58 GroupConstructors->setTitle(tr("GEOM_EDGE"));
59 RadioButton1->setIcon(image0);
60 RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
61 RadioButton2->close();
62 RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
63 RadioButton3->close();
65 GroupPoints = new Ui::DlgRef_2Sel_QTD();
66 QWidget* aGroupPointsWidget = new QWidget(this);
67 GroupPoints->setupUi(aGroupPointsWidget);
68 aGroupPointsWidget->setObjectName("GroupPoints");
70 GroupPoints->GroupBox1->setTitle(tr("GEOM_POINTS"));
71 GroupPoints->TextLabel1->setText(tr("GEOM_POINT_I").arg("1"));
72 GroupPoints->TextLabel2->setText(tr("GEOM_POINT_I").arg("2"));
73 GroupPoints->PushButton1->setIcon(image1);
74 GroupPoints->PushButton2->setIcon(image1);
76 GroupPoints->LineEdit1->setReadOnly( true );
77 GroupPoints->LineEdit2->setReadOnly( true );
79 gridLayout1->addWidget(aGroupPointsWidget, 2, 0);
80 /***************************************************************/
82 setHelpFileName("edge.htm");
89 //=================================================================================
90 // function : ~BuildGUI_EdgeDlg()
91 // purpose : Destroys the object and frees any allocated resources
92 //=================================================================================
93 BuildGUI_EdgeDlg::~BuildGUI_EdgeDlg()
95 // no need to delete child widgets, Qt does it all for us
99 //=================================================================================
102 //=================================================================================
103 void BuildGUI_EdgeDlg::Init()
106 myEditCurrentArgument = GroupPoints->LineEdit1;
107 GroupPoints->LineEdit1->setReadOnly( true );
108 GroupPoints->LineEdit2->setReadOnly( true );
110 myOkPoint1 = myOkPoint2 = false;
112 globalSelection( GEOM_POINT );
114 /* signals and slots connections */
115 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
116 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
118 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
119 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
121 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
122 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
124 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
125 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
127 initName( tr( "GEOM_EDGE").toStdString().c_str() );
131 //=================================================================================
132 // function : ClickOnOk()
134 //=================================================================================
135 void BuildGUI_EdgeDlg::ClickOnOk()
137 if ( ClickOnApply() )
142 //=================================================================================
143 // function : ClickOnApply()
145 //=================================================================================
146 bool BuildGUI_EdgeDlg::ClickOnApply()
156 //=================================================================================
157 // function : SelectionIntoArgument()
158 // purpose : Called when selection as changed or other case
159 //=================================================================================
160 void BuildGUI_EdgeDlg::SelectionIntoArgument()
163 myEditCurrentArgument->setText("");
165 if(IObjectCount() != 1) {
166 if(myEditCurrentArgument == GroupPoints->LineEdit1)
168 else if(myEditCurrentArgument == GroupPoints->LineEdit2)
174 Standard_Boolean testResult = Standard_False;
175 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult );
180 if(myEditCurrentArgument == GroupPoints->LineEdit1) {
181 myPoint1 = aSelectedObject;
184 else if(myEditCurrentArgument == GroupPoints->LineEdit2) {
185 myPoint2 = aSelectedObject;
189 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
195 //=================================================================================
196 // function : LineEditReturnPressed()
198 //=================================================================================
199 void BuildGUI_EdgeDlg::LineEditReturnPressed()
201 QLineEdit* send = (QLineEdit*)sender();
202 if(send == GroupPoints->LineEdit1 || send == GroupPoints->LineEdit2)
204 myEditCurrentArgument = send;
205 GEOMBase_Skeleton::LineEditReturnPressed();
210 //=================================================================================
211 // function : SetEditCurrentArgument()
213 //=================================================================================
214 void BuildGUI_EdgeDlg::SetEditCurrentArgument()
217 QPushButton* send = (QPushButton*)sender();
220 if(send == GroupPoints->PushButton1) {
221 myEditCurrentArgument = GroupPoints->LineEdit1;
222 globalSelection( GEOM_POINT );
224 else if(send == GroupPoints->PushButton2) {
225 myEditCurrentArgument = GroupPoints->LineEdit2;
226 globalSelection( GEOM_POINT );
229 myEditCurrentArgument->setFocus();
230 SelectionIntoArgument();
234 //=================================================================================
235 // function : ActivateThisDialog()
237 //=================================================================================
238 void BuildGUI_EdgeDlg::ActivateThisDialog()
240 GEOMBase_Skeleton::ActivateThisDialog();
241 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
242 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
243 globalSelection( GEOM_POINT );
248 //=================================================================================
249 // function : enterEvent()
251 //=================================================================================
252 void BuildGUI_EdgeDlg::enterEvent(QEvent* e)
254 if ( !GroupConstructors->isEnabled() )
255 ActivateThisDialog();
258 //=================================================================================
259 // function : createOperation
261 //=================================================================================
262 GEOM::GEOM_IOperations_ptr BuildGUI_EdgeDlg::createOperation()
264 return getGeomEngine()->GetIShapesOperations( getStudyId() );
267 //=================================================================================
268 // function : isValid
270 //=================================================================================
271 bool BuildGUI_EdgeDlg::isValid( QString& )
273 return myOkPoint1 && myOkPoint2;
276 //=================================================================================
277 // function : execute
279 //=================================================================================
280 bool BuildGUI_EdgeDlg::execute( ObjectList& objects )
282 GEOM::GEOM_Object_var anObj;
284 anObj = GEOM::GEOM_IShapesOperations::_narrow( getOperation() )->MakeEdge( myPoint1, myPoint2 );
286 if ( !anObj->_is_nil() )
287 objects.push_back( anObj._retn() );