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
30 #include "BuildGUI_EdgeDlg.h"
32 #include <BRepBuilderAPI_MakeEdge.hxx>
33 #include <Precision.hxx>
35 //=================================================================================
36 // class : BuildGUI_EdgeDlg()
37 // purpose : Constructs a BuildGUI_EdgeDlg which is a child of 'parent', with the
38 // name 'name' and widget flags set to 'f'.
39 // The dialog will by default be modeless, unless you set 'modal' to
40 // TRUE to construct a modal dialog.
41 //=================================================================================
42 BuildGUI_EdgeDlg::BuildGUI_EdgeDlg(QWidget* parent, const char* name, BuildGUI* theBuildGUI, SALOME_Selection* Sel, bool modal, WFlags fl)
43 :GEOMBase_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
45 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_BUILD_EDGE")));
46 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
48 setCaption(tr("GEOM_EDGE_TITLE"));
50 /***************************************************************/
51 GroupConstructors->setTitle(tr("GEOM_EDGE"));
52 RadioButton1->setPixmap(image0);
53 RadioButton2->close(TRUE);
54 RadioButton3->close(TRUE);
56 GroupPoints = new DlgRef_2Sel_QTD(this, "GroupPoints");
57 GroupPoints->GroupBox1->setTitle(tr("GEOM_POINTS"));
58 GroupPoints->TextLabel1->setText(tr("GEOM_POINT_I").arg("1"));
59 GroupPoints->TextLabel2->setText(tr("GEOM_POINT_I").arg("2"));
60 GroupPoints->PushButton1->setPixmap(image1);
61 GroupPoints->PushButton2->setPixmap(image1);
63 Layout1->addWidget(GroupPoints, 1, 0);
64 /***************************************************************/
67 myBuildGUI = theBuildGUI;
72 //=================================================================================
73 // function : ~BuildGUI_EdgeDlg()
74 // purpose : Destroys the object and frees any allocated resources
75 //=================================================================================
76 BuildGUI_EdgeDlg::~BuildGUI_EdgeDlg()
78 // no need to delete child widgets, Qt does it all for us
82 //=================================================================================
85 //=================================================================================
86 void BuildGUI_EdgeDlg::Init()
89 myEditCurrentArgument = GroupPoints->LineEdit1;
91 myPoint1.SetCoord(0.0, 0.0, 0.0);
92 myPoint2.SetCoord(0.0, 0.0, 0.0);
93 myOkPoint1 = myOkPoint2 = false;
95 /* first filter used */
96 myVertexFilter = new GEOM_ShapeTypeFilter(TopAbs_VERTEX, myGeom);
97 mySelection->AddFilter(myVertexFilter);
99 /* signals and slots connections */
100 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
101 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
103 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
104 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
106 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
107 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
109 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
111 /* displays Dialog */
119 //=================================================================================
120 // function : ClickOnOk()
122 //=================================================================================
123 void BuildGUI_EdgeDlg::ClickOnOk()
125 this->ClickOnApply();
131 //=================================================================================
132 // function : ClickOnApply()
134 //=================================================================================
135 void BuildGUI_EdgeDlg::ClickOnApply()
137 QAD_Application::getDesktop()->putInfo(tr(""));
138 if (mySimulationTopoDs.IsNull())
140 myGeomBase->EraseSimulationShape();
141 mySimulationTopoDs.Nullify();
143 if(myOkPoint1 && myOkPoint2)
144 myBuildGUI->MakeLinearEdgeAndDisplay(myPoint1, myPoint2);
149 //=================================================================================
150 // function : SelectionIntoArgument()
151 // purpose : Called when selection as changed or other case
152 //=================================================================================
153 void BuildGUI_EdgeDlg::SelectionIntoArgument()
155 myGeomBase->EraseSimulationShape();
156 mySimulationTopoDs.Nullify();
157 myEditCurrentArgument->setText("");
158 QString aString = ""; /* name of selection */
160 int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
162 if(myEditCurrentArgument == GroupPoints->LineEdit1)
164 else if(myEditCurrentArgument == GroupPoints->LineEdit2)
171 if(!myGeomBase->GetTopoFromSelection(mySelection, S))
174 if(myEditCurrentArgument == GroupPoints->LineEdit1 && myGeomBase->VertexToPoint(S, myPoint1)) {
175 myEditCurrentArgument->setText(aString);
178 else if(myEditCurrentArgument == GroupPoints->LineEdit2 && myGeomBase->VertexToPoint(S, myPoint2)) {
179 myEditCurrentArgument->setText(aString);
183 if(myOkPoint1 && myOkPoint2 && myPoint1.Distance(myPoint2) > Precision::Confusion())
184 this->MakeEdgeSimulationAndDisplay();
189 //=================================================================================
190 // function : LineEditReturnPressed()
192 //=================================================================================
193 void BuildGUI_EdgeDlg::LineEditReturnPressed()
195 QLineEdit* send = (QLineEdit*)sender();
196 if(send == GroupPoints->LineEdit1)
197 myEditCurrentArgument = GroupPoints->LineEdit1;
198 else if (send == GroupPoints->LineEdit2)
199 myEditCurrentArgument = GroupPoints->LineEdit2;
203 GEOMBase_Skeleton::LineEditReturnPressed();
208 //=================================================================================
209 // function : SetEditCurrentArgument()
211 //=================================================================================
212 void BuildGUI_EdgeDlg::SetEditCurrentArgument()
214 QPushButton* send = (QPushButton*)sender();
215 mySelection->ClearFilters();
217 if(send == GroupPoints->PushButton1) {
218 GroupPoints->LineEdit1->setFocus();
219 myEditCurrentArgument = GroupPoints->LineEdit1;
221 else if(send == GroupPoints->PushButton2) {
222 GroupPoints->LineEdit2->setFocus();
223 myEditCurrentArgument = GroupPoints->LineEdit2;
225 mySelection->AddFilter(myVertexFilter);
226 this->SelectionIntoArgument();
232 //=================================================================================
233 // function : ActivateThisDialog()
235 //=================================================================================
236 void BuildGUI_EdgeDlg::ActivateThisDialog()
238 GEOMBase_Skeleton::ActivateThisDialog();
239 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
240 mySelection->AddFilter(myVertexFilter);
241 if(!mySimulationTopoDs.IsNull())
242 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
247 //=================================================================================
248 // function : enterEvent()
250 //=================================================================================
251 void BuildGUI_EdgeDlg::enterEvent(QEvent* e)
253 if (GroupConstructors->isEnabled())
255 this->ActivateThisDialog();
260 //=================================================================================
261 // function : MakeMirrorSimulationAndDisplay()
262 // purpose : S1 is a shape and S2 a mirror.
263 //=================================================================================
264 void BuildGUI_EdgeDlg::MakeEdgeSimulationAndDisplay()
266 myGeomBase->EraseSimulationShape();
267 mySimulationTopoDs.Nullify();
270 mySimulationTopoDs = BRepBuilderAPI_MakeEdge(myPoint1, myPoint2).Shape();
271 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
273 catch(Standard_Failure) {
274 MESSAGE("Exception catched in MakeEdgeSimulationAndDisplay");