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
29 #include "RepairGUI_OrientationDlg.h"
31 #include <Precision.hxx>
32 #include <TopoDS_Compound.hxx>
33 #include <BRep_Builder.hxx>
34 #include <BRepBuilderAPI_MakeEdge.hxx>
35 #include <BRepAdaptor_Surface.hxx>
36 #include <TopExp_Explorer.hxx>
38 #include "utilities.h"
42 //=================================================================================
43 // class : RepairGUI_OrientationDlg()
44 // purpose : Constructs a RepairGUI_OrientationDlg which is a child of 'parent', with the
45 // name 'name' and widget flags set to 'f'.
46 // The dialog will by default be modeless, unless you set 'modal' to
47 // TRUE to construct a modal dialog.
48 //=================================================================================
49 RepairGUI_OrientationDlg::RepairGUI_OrientationDlg(QWidget* parent, const char* name, RepairGUI* theRepairGUI, SALOME_Selection* Sel, bool modal, WFlags fl)
50 :GEOMBase_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
52 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_ORIENTATION")));
53 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
55 setCaption(tr("GEOM_ORIENTATION_TITLE"));
57 /***************************************************************/
58 GroupConstructors->setTitle(tr("GEOM_ORIENTATION"));
59 RadioButton1->setPixmap(image0);
60 RadioButton2->close(TRUE);
61 RadioButton3->close(TRUE);
63 GroupPoints = new DlgRef_1Sel1Spin1Check(this, "GroupPoints");
64 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
65 GroupPoints->TextLabel1->setText(tr("GEOM_OBJECT"));
66 GroupPoints->TextLabel2->setText(tr("GEOM_VECTOR_LENGTH"));
67 GroupPoints->CheckButton1->setText(tr("GEOM_ORIENTATION_OPT"));
68 GroupPoints->PushButton1->setPixmap(image1);
70 Layout1->addWidget(GroupPoints, 1, 0);
71 /***************************************************************/
74 myRepairGUI = theRepairGUI;
79 //=================================================================================
80 // function : ~RepairGUI_OrientationDlg()
81 // purpose : Destroys the object and frees any allocated resources
82 //=================================================================================
83 RepairGUI_OrientationDlg::~RepairGUI_OrientationDlg()
85 // no need to delete child widgets, Qt does it all for us
89 //=================================================================================
92 //=================================================================================
93 void RepairGUI_OrientationDlg::Init()
96 myEditCurrentArgument = GroupPoints->LineEdit1;
101 double SpecificStep = 10;
102 /* min, max, step and decimals for spin boxes & initial values */
103 GroupPoints->SpinBox_DX->RangeStepAndValidator(0.001, 999.999, SpecificStep, 3);
104 GroupPoints->SpinBox_DX->SetValue(myLength);
106 /* signals and slots connections */
107 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
108 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
110 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
111 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
113 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
114 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
116 connect(GroupPoints->CheckButton1, SIGNAL(stateChanged(int)), this, SLOT(ReverseAngle(int)));
118 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
120 /* displays Dialog */
128 //=================================================================================
129 // function : ClickOnOk()
131 //=================================================================================
132 void RepairGUI_OrientationDlg::ClickOnOk()
134 this->ClickOnApply();
140 //=================================================================================
141 // function : ClickOnApply()
143 //=================================================================================
144 void RepairGUI_OrientationDlg::ClickOnApply()
146 buttonApply->setFocus();
147 QAD_Application::getDesktop()->putInfo(tr(""));
148 if (mySimulationTopoDs.IsNull())
150 myGeomBase->EraseSimulationShape();
151 mySimulationTopoDs.Nullify();
153 if(myOkShape && GroupPoints->CheckButton1->isChecked()) {
154 myRepairGUI->MakeOrientationChangeAndDisplay(myGeomShape);
155 GroupPoints->CheckButton1->setChecked(FALSE);
161 //=================================================================================
162 // function : SelectionIntoArgument()
163 // purpose : Called when selection as changed or other case
164 //=================================================================================
165 void RepairGUI_OrientationDlg::SelectionIntoArgument()
167 myGeomBase->EraseSimulationShape();
168 mySimulationTopoDs.Nullify();
169 myEditCurrentArgument->setText("");
170 QString aString = ""; /* name of selection */
172 int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
174 if(myEditCurrentArgument == GroupPoints->LineEdit1)
181 Standard_Boolean testResult;
182 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject();
183 if(!myGeomBase->GetTopoFromSelection(mySelection, S))
186 if(myEditCurrentArgument == GroupPoints->LineEdit1) {
187 myGeomShape = myGeomBase->ConvertIOinGEOMShape(IO, testResult);
190 myEditCurrentArgument->setText(aString);
196 this->MakeOrientationSimulationAndDisplay();
201 //=================================================================================
202 // function : LineEditReturnPressed()
204 //=================================================================================
205 void RepairGUI_OrientationDlg::LineEditReturnPressed()
207 QLineEdit* send = (QLineEdit*)sender();
208 if(send == GroupPoints->LineEdit1)
209 myEditCurrentArgument = GroupPoints->LineEdit1;
213 GEOMBase_Skeleton::LineEditReturnPressed();
218 //=================================================================================
219 // function : SetEditCurrentArgument()
221 //=================================================================================
222 void RepairGUI_OrientationDlg::SetEditCurrentArgument()
224 QPushButton* send = (QPushButton*)sender();
226 if(send == GroupPoints->PushButton1) {
227 GroupPoints->LineEdit1->setFocus();
228 myEditCurrentArgument = GroupPoints->LineEdit1;
230 this->SelectionIntoArgument();
236 //=================================================================================
237 // function : ActivateThisDialog()
239 //=================================================================================
240 void RepairGUI_OrientationDlg::ActivateThisDialog()
242 GEOMBase_Skeleton::ActivateThisDialog();
243 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
244 GroupPoints->LineEdit1->setFocus();
245 myEditCurrentArgument = GroupPoints->LineEdit1;
246 if(!mySimulationTopoDs.IsNull())
247 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
252 //=================================================================================
253 // function : enterEvent()
255 //=================================================================================
256 void RepairGUI_OrientationDlg::enterEvent(QEvent* e)
258 if (GroupConstructors->isEnabled())
260 this->ActivateThisDialog();
265 //=================================================================================
266 // function : ValueChangedInSpinBox()
268 //=================================================================================
269 void RepairGUI_OrientationDlg::ValueChangedInSpinBox(double newValue)
273 this->MakeOrientationSimulationAndDisplay();
278 //=================================================================================
279 // function : ReverseOrientation()
281 //=================================================================================
282 void RepairGUI_OrientationDlg::ReverseAngle(int state)
285 this->MakeOrientationSimulationAndDisplay();
290 //==================================================================================
291 // function : MakeOrientationSimulationAndDisplay()
292 // purpose : Create 'aCompound1' and 'aCompound2' each contains edges oriented
293 // : respectively FORWARD and REVERSE for all faces of 'aTopoDS'
294 // : These edges represent normal vectors on faces of 'aTopoDS'
295 // : For a unique edge an arrow is displayed to show its orientation.
296 //==================================================================================
297 void RepairGUI_OrientationDlg::MakeOrientationSimulationAndDisplay()
299 myGeomBase->EraseSimulationShape();
300 mySimulationTopoDs.Nullify();
302 TopoDS_Compound aCompound1, aCompound2;
303 TopoDS_Compound NullComp;
304 BRep_Builder aBuilder1, aBuilder2;
305 aCompound1 = aCompound2 = NullComp;
306 aBuilder1.MakeCompound(aCompound1);
307 aBuilder2.MakeCompound(aCompound2);
313 /* Case of an edge */
314 if(myShape.ShapeType() == TopAbs_EDGE) {
315 /* Try to display a cone simulation shape to show direction of edge */
316 TopoDS_Shape tmpShape = myShape ;
317 if(GroupPoints->CheckButton1->isChecked()) {
318 if(myShape.Orientation() == TopAbs_FORWARD)
319 tmpShape.Orientation(TopAbs_REVERSED);
321 tmpShape.Orientation(TopAbs_FORWARD);
323 if(myGeomBase->CreateArrowForLinearEdge(tmpShape, mySimulationTopoDs))
324 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
330 TopExp_Explorer ex(myShape, TopAbs_FACE);
333 const TopoDS_Face& F = TopoDS::Face(ex.Current());
334 /* find the center of the minmax */
335 BRepAdaptor_Surface SF(F);
336 Standard_Real u, v, x;
338 u = SF.FirstUParameter();
339 x = SF.LastUParameter();
340 if(Precision::IsInfinite(u)) {
341 if(Precision::IsInfinite(x))
346 else if(!Precision::IsInfinite(x))
349 v = SF.FirstVParameter();
350 x = SF.LastVParameter();
351 if(Precision::IsInfinite(v)) {
352 if(Precision::IsInfinite(x))
357 else if(!Precision::IsInfinite(x))
360 SF.D1(u, v, P1, V1, V2);
364 V.Multiply(myLength/x);
366 V.SetCoord(myLength/2.0, 0.0, 0.0);
367 MESSAGE ("Null normal in Orientation " << endl);
371 /* test orientation of each face and displays forward (aCompound1) */
372 if(F.Orientation() == TopAbs_FORWARD)
376 BRepBuilderAPI_MakeEdge anEdge(P1, P2);
377 aBuilder1.Add(aCompound1, anEdge);
380 /* test orientation of each face and displays forward (aCompound2) */
381 if(F.Orientation() == TopAbs_FORWARD)
385 anEdge = BRepBuilderAPI_MakeEdge(P1, P2);
386 aBuilder2.Add(aCompound2, anEdge);
392 /* display simulation compounds */
393 if(test > 0 && GroupPoints->CheckButton1->isChecked())
394 mySimulationTopoDs = aCompound1;
395 else if(test > 0 && !GroupPoints->CheckButton1->isChecked())
396 mySimulationTopoDs = aCompound2;
398 if(!mySimulationTopoDs.IsNull())
399 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
401 catch(Standard_Failure)
402 MESSAGE("Exception catched in MakeOrientationSimulationAndDisplay");