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 <BRepBuilderAPI_MakeEdge.hxx>
32 #include <Precision.hxx>
34 #include "utilities.h"
35 #include "GEOMImpl_Types.hxx"
37 #include "SUIT_Session.h"
38 #include "SalomeApp_Application.h"
39 #include "LightApp_SelectionMgr.h"
43 //=================================================================================
44 // class : BuildGUI_EdgeDlg()
45 // purpose : Constructs a BuildGUI_EdgeDlg 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 BuildGUI_EdgeDlg::BuildGUI_EdgeDlg(GeometryGUI* theGeometryGUI, QWidget* parent,
51 const char* name, bool modal, WFlags fl)
52 :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize |
53 WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
55 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_BUILD_EDGE")));
56 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
58 setCaption(tr("GEOM_EDGE_TITLE"));
60 /***************************************************************/
61 GroupConstructors->setTitle(tr("GEOM_EDGE"));
62 RadioButton1->setPixmap(image0);
63 RadioButton2->close(TRUE);
64 RadioButton3->close(TRUE);
66 GroupPoints = new DlgRef_2Sel_QTD(this, "GroupPoints");
67 GroupPoints->GroupBox1->setTitle(tr("GEOM_POINTS"));
68 GroupPoints->TextLabel1->setText(tr("GEOM_POINT_I").arg("1"));
69 GroupPoints->TextLabel2->setText(tr("GEOM_POINT_I").arg("2"));
70 GroupPoints->PushButton1->setPixmap(image1);
71 GroupPoints->PushButton2->setPixmap(image1);
73 GroupPoints->LineEdit1->setReadOnly( true );
74 GroupPoints->LineEdit2->setReadOnly( true );
76 Layout1->addWidget(GroupPoints, 2, 0);
77 /***************************************************************/
79 setHelpFileName("edge.htm");
86 //=================================================================================
87 // function : ~BuildGUI_EdgeDlg()
88 // purpose : Destroys the object and frees any allocated resources
89 //=================================================================================
90 BuildGUI_EdgeDlg::~BuildGUI_EdgeDlg()
92 // no need to delete child widgets, Qt does it all for us
96 //=================================================================================
99 //=================================================================================
100 void BuildGUI_EdgeDlg::Init()
103 myEditCurrentArgument = GroupPoints->LineEdit1;
104 GroupPoints->LineEdit1->setReadOnly( true );
105 GroupPoints->LineEdit2->setReadOnly( true );
107 myOkPoint1 = myOkPoint2 = false;
109 globalSelection( GEOM_POINT );
111 /* signals and slots connections */
112 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
113 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
115 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
116 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
118 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
119 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
121 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
122 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
124 initName( tr( "GEOM_EDGE") );
128 //=================================================================================
129 // function : ClickOnOk()
131 //=================================================================================
132 void BuildGUI_EdgeDlg::ClickOnOk()
134 if ( ClickOnApply() )
139 //=================================================================================
140 // function : ClickOnApply()
142 //=================================================================================
143 bool BuildGUI_EdgeDlg::ClickOnApply()
153 //=================================================================================
154 // function : SelectionIntoArgument()
155 // purpose : Called when selection as changed or other case
156 //=================================================================================
157 void BuildGUI_EdgeDlg::SelectionIntoArgument()
160 myEditCurrentArgument->setText("");
162 if(IObjectCount() != 1) {
163 if(myEditCurrentArgument == GroupPoints->LineEdit1)
165 else if(myEditCurrentArgument == GroupPoints->LineEdit2)
171 Standard_Boolean testResult = Standard_False;
172 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult );
177 if(myEditCurrentArgument == GroupPoints->LineEdit1) {
178 myPoint1 = aSelectedObject;
181 else if(myEditCurrentArgument == GroupPoints->LineEdit2) {
182 myPoint2 = aSelectedObject;
186 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
192 //=================================================================================
193 // function : LineEditReturnPressed()
195 //=================================================================================
196 void BuildGUI_EdgeDlg::LineEditReturnPressed()
198 QLineEdit* send = (QLineEdit*)sender();
199 if(send == GroupPoints->LineEdit1 || send == GroupPoints->LineEdit2)
201 myEditCurrentArgument = send;
202 GEOMBase_Skeleton::LineEditReturnPressed();
207 //=================================================================================
208 // function : SetEditCurrentArgument()
210 //=================================================================================
211 void BuildGUI_EdgeDlg::SetEditCurrentArgument()
214 QPushButton* send = (QPushButton*)sender();
217 if(send == GroupPoints->PushButton1) {
218 myEditCurrentArgument = GroupPoints->LineEdit1;
219 globalSelection( GEOM_POINT );
221 else if(send == GroupPoints->PushButton2) {
222 myEditCurrentArgument = GroupPoints->LineEdit2;
223 globalSelection( GEOM_POINT );
226 myEditCurrentArgument->setFocus();
227 SelectionIntoArgument();
231 //=================================================================================
232 // function : ActivateThisDialog()
234 //=================================================================================
235 void BuildGUI_EdgeDlg::ActivateThisDialog()
237 GEOMBase_Skeleton::ActivateThisDialog();
238 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
239 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
240 globalSelection( GEOM_POINT );
245 //=================================================================================
246 // function : enterEvent()
248 //=================================================================================
249 void BuildGUI_EdgeDlg::enterEvent(QEvent* e)
251 if ( !GroupConstructors->isEnabled() )
252 ActivateThisDialog();
255 //=================================================================================
256 // function : createOperation
258 //=================================================================================
259 GEOM::GEOM_IOperations_ptr BuildGUI_EdgeDlg::createOperation()
261 return getGeomEngine()->GetIShapesOperations( getStudyId() );
264 //=================================================================================
265 // function : isValid
267 //=================================================================================
268 bool BuildGUI_EdgeDlg::isValid( QString& )
270 return myOkPoint1 && myOkPoint2;
273 //=================================================================================
274 // function : execute
276 //=================================================================================
277 bool BuildGUI_EdgeDlg::execute( ObjectList& objects )
279 GEOM::GEOM_Object_var anObj;
281 anObj = GEOM::GEOM_IShapesOperations::_narrow( getOperation() )->MakeEdge( myPoint1, myPoint2 );
283 if ( !anObj->_is_nil() )
284 objects.push_back( anObj._retn() );