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 : BasicGUI_LineDlg.cxx
25 // Author : Lucien PIGNOLONI
30 #include "BasicGUI_LineDlg.h"
32 #include <BRepBuilderAPI_MakeEdge.hxx>
33 #include <TopoDS_Compound.hxx>
34 #include <BRep_Builder.hxx>
35 #include <Precision.hxx>
37 //=================================================================================
38 // class : BasicGUI_LineDlg()
39 // purpose : Constructs a BasicGUI_LineDlg which is a child of 'parent', with the
40 // name 'name' and widget flags set to 'f'.
41 // The dialog will by default be modeless, unless you set 'modal' to
42 // TRUE to construct a modal dialog.
43 //=================================================================================
44 BasicGUI_LineDlg::BasicGUI_LineDlg(QWidget* parent, const char* name, BasicGUI* theBasicGUI, SALOME_Selection* Sel, bool modal, WFlags fl)
45 :GEOMBase_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
47 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_DLG_LINE_2P")));
48 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_SELECT")));
50 setCaption(tr("GEOM_LINE_TITLE"));
52 /***************************************************************/
53 GroupConstructors->setTitle(tr("GEOM_LINE"));
54 RadioButton1->setPixmap(image0);
55 RadioButton2->close(TRUE);
56 RadioButton3->close(TRUE);
58 GroupPoints = new DlgRef_2Sel_QTD(this, "GroupPoints");
59 GroupPoints->GroupBox1->setTitle(tr("GEOM_POINTS"));
60 GroupPoints->TextLabel1->setText(tr("GEOM_POINT_I").arg("1"));
61 GroupPoints->TextLabel2->setText(tr("GEOM_POINT_I").arg("2"));
62 GroupPoints->PushButton1->setPixmap(image1);
63 GroupPoints->PushButton2->setPixmap(image1);
65 Layout1->addWidget(GroupPoints, 1, 0);
66 /***************************************************************/
69 myBasicGUI = theBasicGUI;
74 //=================================================================================
75 // function : ~BasicGUI_LineDlg()
76 // purpose : Destroys the object and frees any allocated resources
77 //=================================================================================
78 BasicGUI_LineDlg::~BasicGUI_LineDlg()
80 /* no need to delete child widgets, Qt does it all for us */
84 //=================================================================================
87 //=================================================================================
88 void BasicGUI_LineDlg::Init()
91 myEditCurrentArgument = GroupPoints->LineEdit1;
93 myPoint1.SetCoord(0.0, 0.0, 0.0);
94 myPoint2.SetCoord(0.0, 0.0, 0.0);
95 myOkPoint1 = myOkPoint2 = false;
97 /* Vertices Filter for all arguments */
98 myVertexFilter = new GEOM_ShapeTypeFilter(TopAbs_VERTEX, myGeom);
99 mySelection->AddFilter(myVertexFilter);
101 /* signals and slots connections */
102 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
103 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
105 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
106 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
108 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
109 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
111 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
113 /* displays Dialog */
121 //=================================================================================
122 // function : ClickOnOk()
124 //=================================================================================
125 void BasicGUI_LineDlg::ClickOnOk()
127 this->ClickOnApply();
132 //=================================================================================
133 // function : ClickOnApply()
135 //=================================================================================
136 void BasicGUI_LineDlg::ClickOnApply()
138 QAD_Application::getDesktop()->putInfo(tr(""));
139 if (mySimulationTopoDs.IsNull())
141 myGeomBase->EraseSimulationShape();
142 mySimulationTopoDs.Nullify();
144 if(myOkPoint1 && myOkPoint2)
145 myBasicGUI->MakeLineAndDisplay(myPoint1, myPoint2);
150 //=================================================================================
151 // function : SelectionIntoArgument()
152 // purpose : Called when selection as changed or other case
153 //=================================================================================
154 void BasicGUI_LineDlg::SelectionIntoArgument()
156 myGeomBase->EraseSimulationShape();
157 mySimulationTopoDs.Nullify();
158 myEditCurrentArgument->setText("");
159 QString aString = ""; /* name of selection */
161 int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
163 if(myEditCurrentArgument == GroupPoints->LineEdit1)
165 else if(myEditCurrentArgument == GroupPoints->LineEdit2)
172 if(!myGeomBase->GetTopoFromSelection(mySelection, S))
175 if(myEditCurrentArgument == GroupPoints->LineEdit1 && myGeomBase->VertexToPoint(S, myPoint1)) {
176 myEditCurrentArgument->setText(aString);
179 else if(myEditCurrentArgument == GroupPoints->LineEdit2 && myGeomBase->VertexToPoint(S, myPoint2)) {
180 myEditCurrentArgument->setText(aString);
184 if(myOkPoint1 && myOkPoint2 && myPoint1.Distance(myPoint2) > Precision::Confusion())
185 this->MakeLineSimulationAndDisplay();
190 //=================================================================================
191 // function : SetEditCurrentArgument()
193 //=================================================================================
194 void BasicGUI_LineDlg::SetEditCurrentArgument()
196 QPushButton* send = (QPushButton*)sender();
197 mySelection->ClearFilters();
199 if(send == GroupPoints->PushButton1) {
200 GroupPoints->LineEdit1->setFocus();
201 myEditCurrentArgument = GroupPoints->LineEdit1;
203 else if(send == GroupPoints->PushButton2) {
204 GroupPoints->LineEdit2->setFocus();
205 myEditCurrentArgument = GroupPoints->LineEdit2;
207 mySelection->AddFilter(myVertexFilter);
208 this->SelectionIntoArgument();
214 //=================================================================================
215 // function : LineEditReturnPressed()
217 //=================================================================================
218 void BasicGUI_LineDlg::LineEditReturnPressed()
220 QLineEdit* send = (QLineEdit*)sender();
221 if(send == GroupPoints->LineEdit1)
222 myEditCurrentArgument = GroupPoints->LineEdit1;
223 else if(send == GroupPoints->LineEdit2)
224 myEditCurrentArgument = GroupPoints->LineEdit2;
228 GEOMBase_Skeleton::LineEditReturnPressed();
233 //=================================================================================
234 // function : ActivateThisDialog()
236 //=================================================================================
237 void BasicGUI_LineDlg::ActivateThisDialog()
239 GEOMBase_Skeleton::ActivateThisDialog();
240 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
241 mySelection->AddFilter(myVertexFilter);
242 if(!mySimulationTopoDs.IsNull())
243 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
248 //=================================================================================
249 // function : enterEvent()
251 //=================================================================================
252 void BasicGUI_LineDlg::enterEvent(QEvent* e)
254 if(GroupConstructors->isEnabled())
256 this->ActivateThisDialog();
261 //=================================================================================
262 // function : MakeLineSimulationAndDisplay()
263 // purpose : An arrow (cone topology) is added to 'modifiedShape'
264 // : to simulate a vector or an 'oriented line' display. The result is in 'modifiedShape'.
265 // : If an arrow can't be added returns false and 'modifiedShape' isn't modified !
266 //=================================================================================
267 void BasicGUI_LineDlg::MakeLineSimulationAndDisplay()
269 myGeomBase->EraseSimulationShape();
270 mySimulationTopoDs.Nullify();
273 mySimulationTopoDs = BRepBuilderAPI_MakeEdge(myPoint1, myPoint2).Shape();
275 if(myGeomBase->CreateArrowForLinearEdge(mySimulationTopoDs, arrow)) {
276 TopoDS_Compound Comp;
278 B.MakeCompound (Comp);
279 B.Add(Comp, mySimulationTopoDs);
281 mySimulationTopoDs = Comp;
283 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
285 catch(Standard_Failure) {
286 MESSAGE("Exception catched in MakeLineSimulationAndDisplay");