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 : 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 "QAD_Desktop.h"
36 #include "GEOMImpl_Types.hxx"
38 //=================================================================================
39 // class : BuildGUI_EdgeDlg()
40 // purpose : Constructs a BuildGUI_EdgeDlg which is a child of 'parent', with the
41 // name 'name' and widget flags set to 'f'.
42 // The dialog will by default be modeless, unless you set 'modal' to
43 // TRUE to construct a modal dialog.
44 //=================================================================================
45 BuildGUI_EdgeDlg::BuildGUI_EdgeDlg(QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl)
46 :GEOMBase_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
48 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_BUILD_EDGE")));
49 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
51 setCaption(tr("GEOM_EDGE_TITLE"));
53 /***************************************************************/
54 GroupConstructors->setTitle(tr("GEOM_EDGE"));
55 RadioButton1->setPixmap(image0);
56 RadioButton2->close(TRUE);
57 RadioButton3->close(TRUE);
59 GroupPoints = new DlgRef_2Sel_QTD(this, "GroupPoints");
60 GroupPoints->GroupBox1->setTitle(tr("GEOM_POINTS"));
61 GroupPoints->TextLabel1->setText(tr("GEOM_POINT_I").arg("1"));
62 GroupPoints->TextLabel2->setText(tr("GEOM_POINT_I").arg("2"));
63 GroupPoints->PushButton1->setPixmap(image1);
64 GroupPoints->PushButton2->setPixmap(image1);
66 GroupPoints->LineEdit1->setReadOnly( true );
67 GroupPoints->LineEdit2->setReadOnly( true );
69 Layout1->addWidget(GroupPoints, 2, 0);
70 /***************************************************************/
77 //=================================================================================
78 // function : ~BuildGUI_EdgeDlg()
79 // purpose : Destroys the object and frees any allocated resources
80 //=================================================================================
81 BuildGUI_EdgeDlg::~BuildGUI_EdgeDlg()
83 // no need to delete child widgets, Qt does it all for us
87 //=================================================================================
90 //=================================================================================
91 void BuildGUI_EdgeDlg::Init()
94 myEditCurrentArgument = GroupPoints->LineEdit1;
95 GroupPoints->LineEdit1->setReadOnly( true );
96 GroupPoints->LineEdit2->setReadOnly( true );
98 myOkPoint1 = myOkPoint2 = false;
100 globalSelection( GEOM_POINT );
102 /* signals and slots connections */
103 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
104 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
106 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
107 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
109 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
110 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
112 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
114 initName( tr( "GEOM_EDGE") );
118 //=================================================================================
119 // function : ClickOnOk()
121 //=================================================================================
122 void BuildGUI_EdgeDlg::ClickOnOk()
124 if ( ClickOnApply() )
129 //=================================================================================
130 // function : ClickOnApply()
132 //=================================================================================
133 bool BuildGUI_EdgeDlg::ClickOnApply()
143 //=================================================================================
144 // function : SelectionIntoArgument()
145 // purpose : Called when selection as changed or other case
146 //=================================================================================
147 void BuildGUI_EdgeDlg::SelectionIntoArgument()
150 myEditCurrentArgument->setText("");
152 if(mySelection->IObjectCount() != 1) {
153 if(myEditCurrentArgument == GroupPoints->LineEdit1)
155 else if(myEditCurrentArgument == GroupPoints->LineEdit2)
161 Standard_Boolean testResult = Standard_False;
162 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(mySelection->firstIObject(), testResult );
167 if(myEditCurrentArgument == GroupPoints->LineEdit1) {
168 myPoint1 = aSelectedObject;
171 else if(myEditCurrentArgument == GroupPoints->LineEdit2) {
172 myPoint2 = aSelectedObject;
176 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
182 //=================================================================================
183 // function : LineEditReturnPressed()
185 //=================================================================================
186 void BuildGUI_EdgeDlg::LineEditReturnPressed()
188 QLineEdit* send = (QLineEdit*)sender();
189 if(send == GroupPoints->LineEdit1 || send == GroupPoints->LineEdit2)
191 myEditCurrentArgument = send;
192 GEOMBase_Skeleton::LineEditReturnPressed();
197 //=================================================================================
198 // function : SetEditCurrentArgument()
200 //=================================================================================
201 void BuildGUI_EdgeDlg::SetEditCurrentArgument()
204 QPushButton* send = (QPushButton*)sender();
207 if(send == GroupPoints->PushButton1) {
208 myEditCurrentArgument = GroupPoints->LineEdit1;
209 globalSelection( GEOM_POINT );
211 else if(send == GroupPoints->PushButton2) {
212 myEditCurrentArgument = GroupPoints->LineEdit2;
213 globalSelection( GEOM_POINT );
216 myEditCurrentArgument->setFocus();
217 SelectionIntoArgument();
221 //=================================================================================
222 // function : ActivateThisDialog()
224 //=================================================================================
225 void BuildGUI_EdgeDlg::ActivateThisDialog()
227 GEOMBase_Skeleton::ActivateThisDialog();
228 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
229 globalSelection( GEOM_POINT );
234 //=================================================================================
235 // function : enterEvent()
237 //=================================================================================
238 void BuildGUI_EdgeDlg::enterEvent(QEvent* e)
240 if ( !GroupConstructors->isEnabled() )
241 ActivateThisDialog();
244 //=================================================================================
245 // function : createOperation
247 //=================================================================================
248 GEOM::GEOM_IOperations_ptr BuildGUI_EdgeDlg::createOperation()
250 return getGeomEngine()->GetIShapesOperations( getStudyId() );
253 //=================================================================================
254 // function : isValid
256 //=================================================================================
257 bool BuildGUI_EdgeDlg::isValid( QString& )
259 return myOkPoint1 && myOkPoint2;
262 //=================================================================================
263 // function : execute
265 //=================================================================================
266 bool BuildGUI_EdgeDlg::execute( ObjectList& objects )
268 GEOM::GEOM_Object_var anObj;
270 anObj = GEOM::GEOM_IShapesOperations::_narrow( getOperation() )->MakeEdge( myPoint1, myPoint2 );
272 if ( !anObj->_is_nil() )
273 objects.push_back( anObj._retn() );