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"
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, BuildGUI* theBuildGUI, 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 Layout1->addWidget(GroupPoints, 1, 0);
67 /***************************************************************/
70 myBuildGUI = theBuildGUI;
75 //=================================================================================
76 // function : ~BuildGUI_EdgeDlg()
77 // purpose : Destroys the object and frees any allocated resources
78 //=================================================================================
79 BuildGUI_EdgeDlg::~BuildGUI_EdgeDlg()
81 // no need to delete child widgets, Qt does it all for us
85 //=================================================================================
88 //=================================================================================
89 void BuildGUI_EdgeDlg::Init()
92 myEditCurrentArgument = GroupPoints->LineEdit1;
94 myPoint1.SetCoord(0.0, 0.0, 0.0);
95 myPoint2.SetCoord(0.0, 0.0, 0.0);
96 myOkPoint1 = myOkPoint2 = false;
98 /* first filter used */
99 myVertexFilter = new GEOM_ShapeTypeFilter(TopAbs_VERTEX, myGeom);
100 mySelection->AddFilter(myVertexFilter);
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 /* displays Dialog */
122 //=================================================================================
123 // function : ClickOnOk()
125 //=================================================================================
126 void BuildGUI_EdgeDlg::ClickOnOk()
128 this->ClickOnApply();
134 //=================================================================================
135 // function : ClickOnApply()
137 //=================================================================================
138 void BuildGUI_EdgeDlg::ClickOnApply()
140 QAD_Application::getDesktop()->putInfo(tr(""));
141 if (mySimulationTopoDs.IsNull())
143 myGeomBase->EraseSimulationShape();
144 mySimulationTopoDs.Nullify();
146 if(myOkPoint1 && myOkPoint2)
147 myBuildGUI->MakeLinearEdgeAndDisplay(myPoint1, myPoint2);
152 //=================================================================================
153 // function : SelectionIntoArgument()
154 // purpose : Called when selection as changed or other case
155 //=================================================================================
156 void BuildGUI_EdgeDlg::SelectionIntoArgument()
158 myGeomBase->EraseSimulationShape();
159 mySimulationTopoDs.Nullify();
160 myEditCurrentArgument->setText("");
161 QString aString = ""; /* name of selection */
163 int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
165 if(myEditCurrentArgument == GroupPoints->LineEdit1)
167 else if(myEditCurrentArgument == GroupPoints->LineEdit2)
174 if(!myGeomBase->GetTopoFromSelection(mySelection, S))
177 if(myEditCurrentArgument == GroupPoints->LineEdit1 && myGeomBase->VertexToPoint(S, myPoint1)) {
178 myEditCurrentArgument->setText(aString);
181 else if(myEditCurrentArgument == GroupPoints->LineEdit2 && myGeomBase->VertexToPoint(S, myPoint2)) {
182 myEditCurrentArgument->setText(aString);
186 if(myOkPoint1 && myOkPoint2 && myPoint1.Distance(myPoint2) > Precision::Confusion())
187 this->MakeEdgeSimulationAndDisplay();
192 //=================================================================================
193 // function : LineEditReturnPressed()
195 //=================================================================================
196 void BuildGUI_EdgeDlg::LineEditReturnPressed()
198 QLineEdit* send = (QLineEdit*)sender();
199 if(send == GroupPoints->LineEdit1)
200 myEditCurrentArgument = GroupPoints->LineEdit1;
201 else if (send == GroupPoints->LineEdit2)
202 myEditCurrentArgument = GroupPoints->LineEdit2;
206 GEOMBase_Skeleton::LineEditReturnPressed();
211 //=================================================================================
212 // function : SetEditCurrentArgument()
214 //=================================================================================
215 void BuildGUI_EdgeDlg::SetEditCurrentArgument()
217 QPushButton* send = (QPushButton*)sender();
218 mySelection->ClearFilters();
220 if(send == GroupPoints->PushButton1) {
221 GroupPoints->LineEdit1->setFocus();
222 myEditCurrentArgument = GroupPoints->LineEdit1;
224 else if(send == GroupPoints->PushButton2) {
225 GroupPoints->LineEdit2->setFocus();
226 myEditCurrentArgument = GroupPoints->LineEdit2;
228 mySelection->AddFilter(myVertexFilter);
229 this->SelectionIntoArgument();
235 //=================================================================================
236 // function : ActivateThisDialog()
238 //=================================================================================
239 void BuildGUI_EdgeDlg::ActivateThisDialog()
241 GEOMBase_Skeleton::ActivateThisDialog();
242 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
243 mySelection->AddFilter(myVertexFilter);
244 if(!mySimulationTopoDs.IsNull())
245 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
250 //=================================================================================
251 // function : enterEvent()
253 //=================================================================================
254 void BuildGUI_EdgeDlg::enterEvent(QEvent* e)
256 if (GroupConstructors->isEnabled())
258 this->ActivateThisDialog();
263 //=================================================================================
264 // function : MakeMirrorSimulationAndDisplay()
265 // purpose : S1 is a shape and S2 a mirror.
266 //=================================================================================
267 void BuildGUI_EdgeDlg::MakeEdgeSimulationAndDisplay()
269 myGeomBase->EraseSimulationShape();
270 mySimulationTopoDs.Nullify();
273 mySimulationTopoDs = BRepBuilderAPI_MakeEdge(myPoint1, myPoint2).Shape();
274 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
276 catch(Standard_Failure) {
277 MESSAGE("Exception catched in MakeEdgeSimulationAndDisplay");