1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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
22 // GEOM GEOMGUI : GUI for Geometry component
23 // File : BuildGUI_EdgeDlg.cxx
24 // Author : Lucien PIGNOLONI
28 #include "BuildGUI_EdgeDlg.h"
30 #include <BRepBuilderAPI_MakeEdge.hxx>
31 #include <Precision.hxx>
33 #include "utilities.h"
34 #include "GEOMImpl_Types.hxx"
36 #include "SUIT_Session.h"
37 #include "SalomeApp_Application.h"
38 #include "LightApp_SelectionMgr.h"
42 //=================================================================================
43 // class : BuildGUI_EdgeDlg()
44 // purpose : Constructs a BuildGUI_EdgeDlg which is a child of 'parent', with the
45 // name 'name' and widget flags set to 'f'.
46 // The dialog will by default be modeless, unless you set 'modal' to
47 // TRUE to construct a modal dialog.
48 //=================================================================================
49 BuildGUI_EdgeDlg::BuildGUI_EdgeDlg(GeometryGUI* theGeometryGUI, QWidget* parent,
50 const char* name, bool modal, WFlags fl)
51 :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize |
52 WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
54 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_BUILD_EDGE")));
55 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
57 setCaption(tr("GEOM_EDGE_TITLE"));
59 /***************************************************************/
60 GroupConstructors->setTitle(tr("GEOM_EDGE"));
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 /***************************************************************/
78 setHelpFileName("create_edge_page.html");
85 //=================================================================================
86 // function : ~BuildGUI_EdgeDlg()
87 // purpose : Destroys the object and frees any allocated resources
88 //=================================================================================
89 BuildGUI_EdgeDlg::~BuildGUI_EdgeDlg()
91 // no need to delete child widgets, Qt does it all for us
95 //=================================================================================
98 //=================================================================================
99 void BuildGUI_EdgeDlg::Init()
102 myEditCurrentArgument = GroupPoints->LineEdit1;
103 GroupPoints->LineEdit1->setReadOnly( true );
104 GroupPoints->LineEdit2->setReadOnly( true );
106 myOkPoint1 = myOkPoint2 = false;
108 globalSelection( GEOM_POINT );
110 /* signals and slots connections */
111 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
112 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
114 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
115 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
117 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
118 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
120 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
121 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
123 initName( tr( "GEOM_EDGE") );
127 //=================================================================================
128 // function : ClickOnOk()
130 //=================================================================================
131 void BuildGUI_EdgeDlg::ClickOnOk()
133 if ( ClickOnApply() )
138 //=================================================================================
139 // function : ClickOnApply()
141 //=================================================================================
142 bool BuildGUI_EdgeDlg::ClickOnApply()
152 //=================================================================================
153 // function : SelectionIntoArgument()
154 // purpose : Called when selection as changed or other case
155 //=================================================================================
156 void BuildGUI_EdgeDlg::SelectionIntoArgument()
159 myEditCurrentArgument->setText("");
161 if(IObjectCount() != 1) {
162 if(myEditCurrentArgument == GroupPoints->LineEdit1)
164 else if(myEditCurrentArgument == GroupPoints->LineEdit2)
170 Standard_Boolean testResult = Standard_False;
171 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult );
176 if(myEditCurrentArgument == GroupPoints->LineEdit1) {
177 myPoint1 = aSelectedObject;
180 else if(myEditCurrentArgument == GroupPoints->LineEdit2) {
181 myPoint2 = aSelectedObject;
185 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
191 //=================================================================================
192 // function : LineEditReturnPressed()
194 //=================================================================================
195 void BuildGUI_EdgeDlg::LineEditReturnPressed()
197 QLineEdit* send = (QLineEdit*)sender();
198 if(send == GroupPoints->LineEdit1 || send == GroupPoints->LineEdit2)
200 myEditCurrentArgument = send;
201 GEOMBase_Skeleton::LineEditReturnPressed();
206 //=================================================================================
207 // function : SetEditCurrentArgument()
209 //=================================================================================
210 void BuildGUI_EdgeDlg::SetEditCurrentArgument()
213 QPushButton* send = (QPushButton*)sender();
216 if(send == GroupPoints->PushButton1) {
217 myEditCurrentArgument = GroupPoints->LineEdit1;
218 globalSelection( GEOM_POINT );
220 else if(send == GroupPoints->PushButton2) {
221 myEditCurrentArgument = GroupPoints->LineEdit2;
222 globalSelection( GEOM_POINT );
225 myEditCurrentArgument->setFocus();
226 SelectionIntoArgument();
230 //=================================================================================
231 // function : ActivateThisDialog()
233 //=================================================================================
234 void BuildGUI_EdgeDlg::ActivateThisDialog()
236 GEOMBase_Skeleton::ActivateThisDialog();
237 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
238 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
239 globalSelection( GEOM_POINT );
244 //=================================================================================
245 // function : enterEvent()
247 //=================================================================================
248 void BuildGUI_EdgeDlg::enterEvent(QEvent* e)
250 if ( !GroupConstructors->isEnabled() )
251 ActivateThisDialog();
254 //=================================================================================
255 // function : createOperation
257 //=================================================================================
258 GEOM::GEOM_IOperations_ptr BuildGUI_EdgeDlg::createOperation()
260 return getGeomEngine()->GetIShapesOperations( getStudyId() );
263 //=================================================================================
264 // function : isValid
266 //=================================================================================
267 bool BuildGUI_EdgeDlg::isValid( QString& )
269 return myOkPoint1 && myOkPoint2;
272 //=================================================================================
273 // function : execute
275 //=================================================================================
276 bool BuildGUI_EdgeDlg::execute( ObjectList& objects )
278 GEOM::GEOM_Object_var anObj;
280 anObj = GEOM::GEOM_IShapesOperations::_narrow( getOperation() )->MakeEdge( myPoint1, myPoint2 );
282 if ( !anObj->_is_nil() )
283 objects.push_back( anObj._retn() );