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, Open CASCADE S.A.S.
26 #include "BuildGUI_EdgeDlg.h"
29 #include <GeometryGUI.h>
32 #include <SUIT_Session.h>
33 #include <SUIT_ResourceMgr.h>
34 #include <SalomeApp_Application.h>
35 #include <LightApp_SelectionMgr.h>
37 #include <GEOMImpl_Types.hxx>
39 //=================================================================================
40 // class : BuildGUI_EdgeDlg()
41 // purpose : Constructs a BuildGUI_EdgeDlg which is a child of 'parent', with the
42 // name 'name' and widget flags set to 'f'.
43 // The dialog will by default be modeless, unless you set 'modal' to
44 // TRUE to construct a modal dialog.
45 //=================================================================================
46 BuildGUI_EdgeDlg::BuildGUI_EdgeDlg (GeometryGUI* theGeometryGUI, QWidget* parent)
47 : GEOMBase_Skeleton(theGeometryGUI, parent)
49 QPixmap image0 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_BUILD_EDGE")));
50 QPixmap image1 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
52 setWindowTitle(tr("GEOM_EDGE_TITLE"));
54 /***************************************************************/
55 mainFrame()->GroupConstructors->setTitle(tr("GEOM_EDGE"));
56 mainFrame()->RadioButton1->setIcon(image0);
57 mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose);
58 mainFrame()->RadioButton2->close();
59 mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
60 mainFrame()->RadioButton3->close();
62 GroupPoints = new DlgRef_2Sel(centralWidget());
64 GroupPoints->GroupBox1->setTitle(tr("GEOM_POINTS"));
65 GroupPoints->TextLabel1->setText(tr("GEOM_POINT_I").arg(1));
66 GroupPoints->TextLabel2->setText(tr("GEOM_POINT_I").arg(2));
67 GroupPoints->PushButton1->setIcon(image1);
68 GroupPoints->PushButton2->setIcon(image1);
70 GroupPoints->LineEdit1->setReadOnly(true);
71 GroupPoints->LineEdit2->setReadOnly(true);
73 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
74 layout->setMargin(0); layout->setSpacing(6);
75 layout->addWidget(GroupPoints);
76 /***************************************************************/
78 setHelpFileName("create_edge_page.html");
84 //=================================================================================
85 // function : ~BuildGUI_EdgeDlg()
86 // purpose : Destroys the object and frees any allocated resources
87 //=================================================================================
88 BuildGUI_EdgeDlg::~BuildGUI_EdgeDlg()
90 // no need to delete child widgets, Qt does it all for us
93 //=================================================================================
96 //=================================================================================
97 void BuildGUI_EdgeDlg::Init()
100 GroupPoints->LineEdit1->setReadOnly(true);
101 GroupPoints->LineEdit2->setReadOnly(true);
103 GroupPoints->LineEdit1->setText("");
104 GroupPoints->LineEdit2->setText("");
105 myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
106 myOkPoint1 = myOkPoint2 = false;
108 // signals and slots connections
109 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
110 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
112 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
113 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
115 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
116 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
118 initName(tr("GEOM_EDGE"));
120 GroupPoints->PushButton1->click();
121 SelectionIntoArgument();
124 //=================================================================================
125 // function : ClickOnOk()
127 //=================================================================================
128 void BuildGUI_EdgeDlg::ClickOnOk()
134 //=================================================================================
135 // function : ClickOnApply()
137 //=================================================================================
138 bool BuildGUI_EdgeDlg::ClickOnApply()
144 // activate selection and connect selection manager
145 GroupPoints->PushButton1->click();
149 //=================================================================================
150 // function : SelectionIntoArgument()
151 // purpose : Called when selection is changed or on dialog initialization or activation
152 //=================================================================================
153 void BuildGUI_EdgeDlg::SelectionIntoArgument()
156 myEditCurrentArgument->setText("");
158 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
159 SALOME_ListIO aSelList;
160 aSelMgr->selectedObjects(aSelList);
162 if (aSelList.Extent() != 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(aSelList.First(), testResult);
173 if (!testResult || aSelectedObject->_is_nil())
176 myEditCurrentArgument->setText(GEOMBase::GetName(aSelectedObject));
179 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
180 myGeomGUI->getApp()->selectionMgr()->clearSelected();
181 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
182 this, SLOT(SelectionIntoArgument()));
184 if (myEditCurrentArgument == GroupPoints->LineEdit1) {
185 myPoint1 = aSelectedObject;
188 GroupPoints->PushButton2->click();
190 else if (myEditCurrentArgument == GroupPoints->LineEdit2) {
191 myPoint2 = aSelectedObject;
194 GroupPoints->PushButton1->click();
200 //=================================================================================
201 // function : SetEditCurrentArgument()
203 //=================================================================================
204 void BuildGUI_EdgeDlg::SetEditCurrentArgument()
206 QPushButton* send = (QPushButton*)sender();
207 //globalSelection();//??
209 if (send == GroupPoints->PushButton1) {
210 myEditCurrentArgument = GroupPoints->LineEdit1;
211 GroupPoints->PushButton2->setDown(false);
212 GroupPoints->LineEdit2->setEnabled(false);
214 else if (send == GroupPoints->PushButton2) {
215 myEditCurrentArgument = GroupPoints->LineEdit2;
216 GroupPoints->PushButton1->setDown(false);
217 GroupPoints->LineEdit1->setEnabled(false);
221 myEditCurrentArgument->setEnabled(true);
222 myEditCurrentArgument->setFocus();
223 // after setFocus(), because it will be setDown(false) when loses focus
226 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
227 globalSelection(GEOM_POINT);
228 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
229 this, SLOT(SelectionIntoArgument()));
231 // seems we need it only to avoid preview disappearing, caused by selection mode change
235 //=================================================================================
236 // function : LineEditReturnPressed()
238 //=================================================================================
239 void BuildGUI_EdgeDlg::LineEditReturnPressed()
241 QLineEdit* send = (QLineEdit*)sender();
242 if (send == GroupPoints->LineEdit1 || send == GroupPoints->LineEdit2) {
243 myEditCurrentArgument = send;
244 GEOMBase_Skeleton::LineEditReturnPressed();
248 //=================================================================================
249 // function : ActivateThisDialog()
251 //=================================================================================
252 void BuildGUI_EdgeDlg::ActivateThisDialog()
254 GEOMBase_Skeleton::ActivateThisDialog();
256 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
257 this, SLOT( SelectionIntoArgument() ) );
262 //=================================================================================
263 // function : enterEvent()
265 //=================================================================================
266 void BuildGUI_EdgeDlg::enterEvent (QEvent*)
268 if (!mainFrame()->GroupConstructors->isEnabled())
269 ActivateThisDialog();
272 //=================================================================================
273 // function : createOperation
275 //=================================================================================
276 GEOM::GEOM_IOperations_ptr BuildGUI_EdgeDlg::createOperation()
278 return getGeomEngine()->GetIShapesOperations(getStudyId());
281 //=================================================================================
282 // function : isValid
284 //=================================================================================
285 bool BuildGUI_EdgeDlg::isValid (QString&)
287 return myOkPoint1 && myOkPoint2;
290 //=================================================================================
291 // function : execute
293 //=================================================================================
294 bool BuildGUI_EdgeDlg::execute (ObjectList& objects)
296 GEOM::GEOM_Object_var anObj;
298 anObj = GEOM::GEOM_IShapesOperations::_narrow(getOperation())->MakeEdge(myPoint1, myPoint2);
300 if (!anObj->_is_nil())
301 objects.push_back(anObj._retn());