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 : RepairGUI_OrientationDlg.cxx
25 // Author : Lucien PIGNOLONI
30 #include "RepairGUI_OrientationDlg.h"
32 #include <Precision.hxx>
33 #include <TopoDS_Compound.hxx>
34 #include <BRep_Builder.hxx>
35 #include <BRepBuilderAPI_MakeEdge.hxx>
36 #include <BRepAdaptor_Surface.hxx>
37 #include <TopExp_Explorer.hxx>
39 //=================================================================================
40 // class : RepairGUI_OrientationDlg()
41 // purpose : Constructs a RepairGUI_OrientationDlg 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 RepairGUI_OrientationDlg::RepairGUI_OrientationDlg(QWidget* parent, const char* name, RepairGUI* theRepairGUI, SALOME_Selection* Sel, bool modal, WFlags fl)
47 :GEOMBase_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
49 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_ORIENTATION")));
50 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
52 setCaption(tr("GEOM_ORIENTATION_TITLE"));
54 /***************************************************************/
55 GroupConstructors->setTitle(tr("GEOM_ORIENTATION"));
56 RadioButton1->setPixmap(image0);
57 RadioButton2->close(TRUE);
58 RadioButton3->close(TRUE);
60 GroupPoints = new DlgRef_1Sel1Spin1Check(this, "GroupPoints");
61 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
62 GroupPoints->TextLabel1->setText(tr("GEOM_OBJECT"));
63 GroupPoints->TextLabel2->setText(tr("GEOM_VECTOR_LENGTH"));
64 GroupPoints->CheckButton1->setText(tr("GEOM_ORIENTATION_OPT"));
65 GroupPoints->PushButton1->setPixmap(image1);
67 Layout1->addWidget(GroupPoints, 1, 0);
68 /***************************************************************/
71 myRepairGUI = theRepairGUI;
76 //=================================================================================
77 // function : ~RepairGUI_OrientationDlg()
78 // purpose : Destroys the object and frees any allocated resources
79 //=================================================================================
80 RepairGUI_OrientationDlg::~RepairGUI_OrientationDlg()
82 // no need to delete child widgets, Qt does it all for us
86 //=================================================================================
89 //=================================================================================
90 void RepairGUI_OrientationDlg::Init()
93 myEditCurrentArgument = GroupPoints->LineEdit1;
98 double SpecificStep = 10;
99 /* min, max, step and decimals for spin boxes & initial values */
100 GroupPoints->SpinBox_DX->RangeStepAndValidator(0.001, 999.999, SpecificStep, 3);
101 GroupPoints->SpinBox_DX->SetValue(myLength);
103 /* signals and slots connections */
104 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
105 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
107 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
108 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
110 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
111 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
113 connect(GroupPoints->CheckButton1, SIGNAL(stateChanged(int)), this, SLOT(ReverseAngle(int)));
115 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
117 /* displays Dialog */
125 //=================================================================================
126 // function : ClickOnOk()
128 //=================================================================================
129 void RepairGUI_OrientationDlg::ClickOnOk()
131 this->ClickOnApply();
137 //=================================================================================
138 // function : ClickOnApply()
140 //=================================================================================
141 void RepairGUI_OrientationDlg::ClickOnApply()
143 buttonApply->setFocus();
144 QAD_Application::getDesktop()->putInfo(tr(""));
145 if (mySimulationTopoDs.IsNull())
147 myGeomBase->EraseSimulationShape();
148 mySimulationTopoDs.Nullify();
150 if(myOkShape && GroupPoints->CheckButton1->isChecked()) {
151 myRepairGUI->MakeOrientationChangeAndDisplay(myGeomShape);
152 GroupPoints->CheckButton1->setChecked(FALSE);
158 //=================================================================================
159 // function : SelectionIntoArgument()
160 // purpose : Called when selection as changed or other case
161 //=================================================================================
162 void RepairGUI_OrientationDlg::SelectionIntoArgument()
164 myGeomBase->EraseSimulationShape();
165 mySimulationTopoDs.Nullify();
166 myEditCurrentArgument->setText("");
167 QString aString = ""; /* name of selection */
169 int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
171 if(myEditCurrentArgument == GroupPoints->LineEdit1)
178 Standard_Boolean testResult;
179 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject();
180 if(!myGeomBase->GetTopoFromSelection(mySelection, S))
183 if(myEditCurrentArgument == GroupPoints->LineEdit1) {
184 myGeomShape = myGeomBase->ConvertIOinGEOMShape(IO, testResult);
187 myEditCurrentArgument->setText(aString);
193 this->MakeOrientationSimulationAndDisplay();
198 //=================================================================================
199 // function : LineEditReturnPressed()
201 //=================================================================================
202 void RepairGUI_OrientationDlg::LineEditReturnPressed()
204 QLineEdit* send = (QLineEdit*)sender();
205 if(send == GroupPoints->LineEdit1)
206 myEditCurrentArgument = GroupPoints->LineEdit1;
210 GEOMBase_Skeleton::LineEditReturnPressed();
215 //=================================================================================
216 // function : SetEditCurrentArgument()
218 //=================================================================================
219 void RepairGUI_OrientationDlg::SetEditCurrentArgument()
221 QPushButton* send = (QPushButton*)sender();
223 if(send == GroupPoints->PushButton1) {
224 GroupPoints->LineEdit1->setFocus();
225 myEditCurrentArgument = GroupPoints->LineEdit1;
227 this->SelectionIntoArgument();
233 //=================================================================================
234 // function : ActivateThisDialog()
236 //=================================================================================
237 void RepairGUI_OrientationDlg::ActivateThisDialog()
239 GEOMBase_Skeleton::ActivateThisDialog();
240 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
241 GroupPoints->LineEdit1->setFocus();
242 myEditCurrentArgument = GroupPoints->LineEdit1;
243 if(!mySimulationTopoDs.IsNull())
244 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
249 //=================================================================================
250 // function : enterEvent()
252 //=================================================================================
253 void RepairGUI_OrientationDlg::enterEvent(QEvent* e)
255 if (GroupConstructors->isEnabled())
257 this->ActivateThisDialog();
262 //=================================================================================
263 // function : ValueChangedInSpinBox()
265 //=================================================================================
266 void RepairGUI_OrientationDlg::ValueChangedInSpinBox(double newValue)
270 this->MakeOrientationSimulationAndDisplay();
275 //=================================================================================
276 // function : ReverseOrientation()
278 //=================================================================================
279 void RepairGUI_OrientationDlg::ReverseAngle(int state)
282 this->MakeOrientationSimulationAndDisplay();
287 //==================================================================================
288 // function : MakeOrientationSimulationAndDisplay()
289 // purpose : Create 'aCompound1' and 'aCompound2' each contains edges oriented
290 // : respectively FORWARD and REVERSE for all faces of 'aTopoDS'
291 // : These edges represent normal vectors on faces of 'aTopoDS'
292 // : For a unique edge an arrow is displayed to show its orientation.
293 //==================================================================================
294 void RepairGUI_OrientationDlg::MakeOrientationSimulationAndDisplay()
296 myGeomBase->EraseSimulationShape();
297 mySimulationTopoDs.Nullify();
299 TopoDS_Compound aCompound1, aCompound2;
300 TopoDS_Compound NullComp;
301 BRep_Builder aBuilder1, aBuilder2;
302 aCompound1 = aCompound2 = NullComp;
303 aBuilder1.MakeCompound(aCompound1);
304 aBuilder2.MakeCompound(aCompound2);
310 /* Case of an edge */
311 if(myShape.ShapeType() == TopAbs_EDGE) {
312 /* Try to display a cone simulation shape to show direction of edge */
313 TopoDS_Shape tmpShape = myShape ;
314 if(GroupPoints->CheckButton1->isChecked()) {
315 if(myShape.Orientation() == TopAbs_FORWARD)
316 tmpShape.Orientation(TopAbs_REVERSED);
318 tmpShape.Orientation(TopAbs_FORWARD);
320 if(myGeomBase->CreateArrowForLinearEdge(tmpShape, mySimulationTopoDs))
321 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
327 TopExp_Explorer ex(myShape, TopAbs_FACE);
330 const TopoDS_Face& F = TopoDS::Face(ex.Current());
331 /* find the center of the minmax */
332 BRepAdaptor_Surface SF(F);
333 Standard_Real u, v, x;
335 u = SF.FirstUParameter();
336 x = SF.LastUParameter();
337 if(Precision::IsInfinite(u)) {
338 if(Precision::IsInfinite(x))
343 else if(!Precision::IsInfinite(x))
346 v = SF.FirstVParameter();
347 x = SF.LastVParameter();
348 if(Precision::IsInfinite(v)) {
349 if(Precision::IsInfinite(x))
354 else if(!Precision::IsInfinite(x))
357 SF.D1(u, v, P1, V1, V2);
361 V.Multiply(myLength/x);
363 V.SetCoord(myLength/2.0, 0.0, 0.0);
364 MESSAGE ("Null normal in Orientation " << endl);
368 /* test orientation of each face and displays forward (aCompound1) */
369 if(F.Orientation() == TopAbs_FORWARD)
373 BRepBuilderAPI_MakeEdge anEdge(P1, P2);
374 aBuilder1.Add(aCompound1, anEdge);
377 /* test orientation of each face and displays forward (aCompound2) */
378 if(F.Orientation() == TopAbs_FORWARD)
382 anEdge = BRepBuilderAPI_MakeEdge(P1, P2);
383 aBuilder2.Add(aCompound2, anEdge);
389 /* display simulation compounds */
390 if(test > 0 && GroupPoints->CheckButton1->isChecked())
391 mySimulationTopoDs = aCompound1;
392 else if(test > 0 && !GroupPoints->CheckButton1->isChecked())
393 mySimulationTopoDs = aCompound2;
395 if(!mySimulationTopoDs.IsNull())
396 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
398 catch(Standard_Failure)
399 MESSAGE("Exception catched in MakeOrientationSimulationAndDisplay");