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 "GEOMImpl_Types.hxx"
37 #include "SUIT_Session.h"
38 #include "SalomeApp_Application.h"
39 #include "SalomeApp_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(QWidget* parent, const char* name, bool modal, WFlags fl)
51 :GEOMBase_Skeleton(parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
53 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_BUILD_EDGE")));
54 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
56 setCaption(tr("GEOM_EDGE_TITLE"));
58 /***************************************************************/
59 GroupConstructors->setTitle(tr("GEOM_EDGE"));
60 RadioButton1->setPixmap(image0);
61 RadioButton2->close(TRUE);
62 RadioButton3->close(TRUE);
64 GroupPoints = new DlgRef_2Sel_QTD(this, "GroupPoints");
65 GroupPoints->GroupBox1->setTitle(tr("GEOM_POINTS"));
66 GroupPoints->TextLabel1->setText(tr("GEOM_POINT_I").arg("1"));
67 GroupPoints->TextLabel2->setText(tr("GEOM_POINT_I").arg("2"));
68 GroupPoints->PushButton1->setPixmap(image1);
69 GroupPoints->PushButton2->setPixmap(image1);
71 GroupPoints->LineEdit1->setReadOnly( true );
72 GroupPoints->LineEdit2->setReadOnly( true );
74 Layout1->addWidget(GroupPoints, 2, 0);
75 /***************************************************************/
82 //=================================================================================
83 // function : ~BuildGUI_EdgeDlg()
84 // purpose : Destroys the object and frees any allocated resources
85 //=================================================================================
86 BuildGUI_EdgeDlg::~BuildGUI_EdgeDlg()
88 // no need to delete child widgets, Qt does it all for us
92 //=================================================================================
95 //=================================================================================
96 void BuildGUI_EdgeDlg::Init()
99 myEditCurrentArgument = GroupPoints->LineEdit1;
100 GroupPoints->LineEdit1->setReadOnly( true );
101 GroupPoints->LineEdit2->setReadOnly( true );
103 myOkPoint1 = myOkPoint2 = false;
105 globalSelection( GEOM_POINT );
107 /* signals and slots connections */
108 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
109 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
111 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
112 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
114 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
115 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
117 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
118 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
120 initName( tr( "GEOM_EDGE") );
124 //=================================================================================
125 // function : ClickOnOk()
127 //=================================================================================
128 void BuildGUI_EdgeDlg::ClickOnOk()
130 if ( ClickOnApply() )
135 //=================================================================================
136 // function : ClickOnApply()
138 //=================================================================================
139 bool BuildGUI_EdgeDlg::ClickOnApply()
149 //=================================================================================
150 // function : SelectionIntoArgument()
151 // purpose : Called when selection as changed or other case
152 //=================================================================================
153 void BuildGUI_EdgeDlg::SelectionIntoArgument()
156 myEditCurrentArgument->setText("");
158 if(IObjectCount() != 1) {
159 if(myEditCurrentArgument == GroupPoints->LineEdit1)
161 else if(myEditCurrentArgument == GroupPoints->LineEdit2)
167 Standard_Boolean testResult = Standard_False;
168 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult );
173 if(myEditCurrentArgument == GroupPoints->LineEdit1) {
174 myPoint1 = aSelectedObject;
177 else if(myEditCurrentArgument == GroupPoints->LineEdit2) {
178 myPoint2 = aSelectedObject;
182 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
188 //=================================================================================
189 // function : LineEditReturnPressed()
191 //=================================================================================
192 void BuildGUI_EdgeDlg::LineEditReturnPressed()
194 QLineEdit* send = (QLineEdit*)sender();
195 if(send == GroupPoints->LineEdit1 || send == GroupPoints->LineEdit2)
197 myEditCurrentArgument = send;
198 GEOMBase_Skeleton::LineEditReturnPressed();
203 //=================================================================================
204 // function : SetEditCurrentArgument()
206 //=================================================================================
207 void BuildGUI_EdgeDlg::SetEditCurrentArgument()
210 QPushButton* send = (QPushButton*)sender();
213 if(send == GroupPoints->PushButton1) {
214 myEditCurrentArgument = GroupPoints->LineEdit1;
215 globalSelection( GEOM_POINT );
217 else if(send == GroupPoints->PushButton2) {
218 myEditCurrentArgument = GroupPoints->LineEdit2;
219 globalSelection( GEOM_POINT );
222 myEditCurrentArgument->setFocus();
223 SelectionIntoArgument();
227 //=================================================================================
228 // function : ActivateThisDialog()
230 //=================================================================================
231 void BuildGUI_EdgeDlg::ActivateThisDialog()
233 GEOMBase_Skeleton::ActivateThisDialog();
234 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
235 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
236 globalSelection( GEOM_POINT );
241 //=================================================================================
242 // function : enterEvent()
244 //=================================================================================
245 void BuildGUI_EdgeDlg::enterEvent(QEvent* e)
247 if ( !GroupConstructors->isEnabled() )
248 ActivateThisDialog();
251 //=================================================================================
252 // function : createOperation
254 //=================================================================================
255 GEOM::GEOM_IOperations_ptr BuildGUI_EdgeDlg::createOperation()
257 return getGeomEngine()->GetIShapesOperations( getStudyId() );
260 //=================================================================================
261 // function : isValid
263 //=================================================================================
264 bool BuildGUI_EdgeDlg::isValid( QString& )
266 return myOkPoint1 && myOkPoint2;
269 //=================================================================================
270 // function : execute
272 //=================================================================================
273 bool BuildGUI_EdgeDlg::execute( ObjectList& objects )
275 GEOM::GEOM_Object_var anObj;
277 anObj = GEOM::GEOM_IShapesOperations::_narrow( getOperation() )->MakeEdge( myPoint1, myPoint2 );
279 if ( !anObj->_is_nil() )
280 objects.push_back( anObj._retn() );