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
29 #include "BasicGUI_LineDlg.h"
31 #include <BRepBuilderAPI_MakeEdge.hxx>
32 #include <TopoDS_Compound.hxx>
33 #include <BRep_Builder.hxx>
34 #include <Precision.hxx>
36 #include "utilities.h"
40 //=================================================================================
41 // class : BasicGUI_LineDlg()
42 // purpose : Constructs a BasicGUI_LineDlg which is a child of 'parent', with the
43 // name 'name' and widget flags set to 'f'.
44 // The dialog will by default be modeless, unless you set 'modal' to
45 // TRUE to construct a modal dialog.
46 //=================================================================================
47 BasicGUI_LineDlg::BasicGUI_LineDlg(QWidget* parent, const char* name, BasicGUI* theBasicGUI, SALOME_Selection* Sel, bool modal, WFlags fl)
48 :GEOMBase_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
50 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_DLG_LINE_2P")));
51 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_SELECT")));
53 setCaption(tr("GEOM_LINE_TITLE"));
55 /***************************************************************/
56 GroupConstructors->setTitle(tr("GEOM_LINE"));
57 RadioButton1->setPixmap(image0);
58 RadioButton2->close(TRUE);
59 RadioButton3->close(TRUE);
61 GroupPoints = new DlgRef_2Sel_QTD(this, "GroupPoints");
62 GroupPoints->GroupBox1->setTitle(tr("GEOM_POINTS"));
63 GroupPoints->TextLabel1->setText(tr("GEOM_POINT_I").arg("1"));
64 GroupPoints->TextLabel2->setText(tr("GEOM_POINT_I").arg("2"));
65 GroupPoints->PushButton1->setPixmap(image1);
66 GroupPoints->PushButton2->setPixmap(image1);
68 Layout1->addWidget(GroupPoints, 1, 0);
69 /***************************************************************/
72 myBasicGUI = theBasicGUI;
77 //=================================================================================
78 // function : ~BasicGUI_LineDlg()
79 // purpose : Destroys the object and frees any allocated resources
80 //=================================================================================
81 BasicGUI_LineDlg::~BasicGUI_LineDlg()
83 /* no need to delete child widgets, Qt does it all for us */
87 //=================================================================================
90 //=================================================================================
91 void BasicGUI_LineDlg::Init()
94 myEditCurrentArgument = GroupPoints->LineEdit1;
96 myPoint1.SetCoord(0.0, 0.0, 0.0);
97 myPoint2.SetCoord(0.0, 0.0, 0.0);
98 myOkPoint1 = myOkPoint2 = false;
100 /* Vertices Filter for all arguments */
101 myVertexFilter = new GEOM_ShapeTypeFilter(TopAbs_VERTEX, myGeom);
102 mySelection->AddFilter(myVertexFilter);
104 /* signals and slots connections */
105 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
106 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
108 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
109 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
111 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
112 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
114 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
116 /* displays Dialog */
124 //=================================================================================
125 // function : ClickOnOk()
127 //=================================================================================
128 void BasicGUI_LineDlg::ClickOnOk()
130 this->ClickOnApply();
135 //=================================================================================
136 // function : ClickOnApply()
138 //=================================================================================
139 void BasicGUI_LineDlg::ClickOnApply()
141 buttonApply->setFocus();
142 QAD_Application::getDesktop()->putInfo(tr(""));
143 if (mySimulationTopoDs.IsNull())
145 myGeomBase->EraseSimulationShape();
146 mySimulationTopoDs.Nullify();
148 if(myOkPoint1 && myOkPoint2)
149 myBasicGUI->MakeLineAndDisplay(myPoint1, myPoint2);
154 //=================================================================================
155 // function : SelectionIntoArgument()
156 // purpose : Called when selection as changed or other case
157 //=================================================================================
158 void BasicGUI_LineDlg::SelectionIntoArgument()
160 myGeomBase->EraseSimulationShape();
161 mySimulationTopoDs.Nullify();
162 myEditCurrentArgument->setText("");
163 QString aString = ""; /* name of selection */
165 int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
167 if(myEditCurrentArgument == GroupPoints->LineEdit1)
169 else if(myEditCurrentArgument == GroupPoints->LineEdit2)
176 if(!myGeomBase->GetTopoFromSelection(mySelection, S))
179 if(myEditCurrentArgument == GroupPoints->LineEdit1 && myGeomBase->VertexToPoint(S, myPoint1)) {
180 myEditCurrentArgument->setText(aString);
183 else if(myEditCurrentArgument == GroupPoints->LineEdit2 && myGeomBase->VertexToPoint(S, myPoint2)) {
184 myEditCurrentArgument->setText(aString);
188 if(myOkPoint1 && myOkPoint2 && myPoint1.Distance(myPoint2) > Precision::Confusion())
189 this->MakeLineSimulationAndDisplay();
194 //=================================================================================
195 // function : SetEditCurrentArgument()
197 //=================================================================================
198 void BasicGUI_LineDlg::SetEditCurrentArgument()
200 QPushButton* send = (QPushButton*)sender();
201 mySelection->ClearFilters();
203 if(send == GroupPoints->PushButton1) {
204 GroupPoints->LineEdit1->setFocus();
205 myEditCurrentArgument = GroupPoints->LineEdit1;
207 else if(send == GroupPoints->PushButton2) {
208 GroupPoints->LineEdit2->setFocus();
209 myEditCurrentArgument = GroupPoints->LineEdit2;
211 mySelection->AddFilter(myVertexFilter);
212 this->SelectionIntoArgument();
218 //=================================================================================
219 // function : LineEditReturnPressed()
221 //=================================================================================
222 void BasicGUI_LineDlg::LineEditReturnPressed()
224 QLineEdit* send = (QLineEdit*)sender();
225 if(send == GroupPoints->LineEdit1)
226 myEditCurrentArgument = GroupPoints->LineEdit1;
227 else if(send == GroupPoints->LineEdit2)
228 myEditCurrentArgument = GroupPoints->LineEdit2;
232 GEOMBase_Skeleton::LineEditReturnPressed();
237 //=================================================================================
238 // function : ActivateThisDialog()
240 //=================================================================================
241 void BasicGUI_LineDlg::ActivateThisDialog()
243 GEOMBase_Skeleton::ActivateThisDialog();
244 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
245 mySelection->AddFilter(myVertexFilter);
246 if(!mySimulationTopoDs.IsNull())
247 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
252 //=================================================================================
253 // function : enterEvent()
255 //=================================================================================
256 void BasicGUI_LineDlg::enterEvent(QEvent* e)
258 if(GroupConstructors->isEnabled())
260 this->ActivateThisDialog();
265 //=================================================================================
266 // function : MakeLineSimulationAndDisplay()
267 // purpose : An arrow (cone topology) is added to 'modifiedShape'
268 // : to simulate a vector or an 'oriented line' display. The result is in 'modifiedShape'.
269 // : If an arrow can't be added returns false and 'modifiedShape' isn't modified !
270 //=================================================================================
271 void BasicGUI_LineDlg::MakeLineSimulationAndDisplay()
273 myGeomBase->EraseSimulationShape();
274 mySimulationTopoDs.Nullify();
277 mySimulationTopoDs = BRepBuilderAPI_MakeEdge(myPoint1, myPoint2).Shape();
279 if(myGeomBase->CreateArrowForLinearEdge(mySimulationTopoDs, arrow)) {
280 TopoDS_Compound Comp;
282 B.MakeCompound (Comp);
283 B.Add(Comp, mySimulationTopoDs);
285 mySimulationTopoDs = Comp;
287 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
289 catch(Standard_Failure) {
290 MESSAGE("Exception catched in MakeLineSimulationAndDisplay");