1 // Created on: 1996-05-28
2 // Created by: Denis PASCAL
3 // Copyright (c) 1996-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and / or modify it
9 // under the terms of the GNU Lesser General Public version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #include <DrawDim_Angle.ixx>
18 #include <DrawDim.hxx>
20 #include <BRepAdaptor_Surface.hxx>
21 #include <BRep_Tool.hxx>
30 #include <IntAna_QuadQuadGeo.hxx>
31 #include <Precision.hxx>
32 #include <TopExp_Explorer.hxx>
33 #include <TopoDS_Vertex.hxx>
34 #include <IntAna_QuadQuadGeo.hxx>
36 //=======================================================================
37 //function : DrawDim_Angle
39 //=======================================================================
41 DrawDim_Angle::DrawDim_Angle(const TopoDS_Face& plane1, const TopoDS_Face& plane2)
47 //=======================================================================
50 //=======================================================================
52 const TopoDS_Face& DrawDim_Angle::Plane1() const
57 //=======================================================================
60 //=======================================================================
62 void DrawDim_Angle::Plane1(const TopoDS_Face& plane)
67 //=======================================================================
70 //=======================================================================
72 const TopoDS_Face& DrawDim_Angle::Plane2() const
77 //=======================================================================
80 //=======================================================================
82 void DrawDim_Angle::Plane2(const TopoDS_Face& plane)
88 //=======================================================================
91 //=======================================================================
93 void DrawDim_Angle::DrawOn(Draw_Display& ) const
97 TopoDS_Shape myFShape = myPlane1;
98 TopoDS_Shape mySShape = myPlane2;
99 Standard_Real myVal = GetValue();
109 gp_Pnt myPosition(0.,0.,0.);
113 Standard_Boolean myAutomaticPosition = Standard_True;
117 // calculation of myAxis
119 if (!DrawDim::Pln(myPlane1,pln1)) return;
120 if (!DrawDim::Pln(myPlane2,pln2)) return;
121 IntAna_QuadQuadGeo ip (pln1,pln2,Precision::Confusion(), Precision::Angular());
122 if (!ip.IsDone()) return;
128 //Handle(Geom_Surface) curve1 = BRep_Tool::Surface(myPlane1);
129 //Handle(Geom_PlaneLine) line1 = Handle(Geom_Line)::DownCast(curve1);
133 //=======================================================================
134 //function : ComputeTwoFacesAngle
136 //=======================================================================
138 // void AIS_AngleDimension::ComputeTwoFacesAngle(const Handle(Prs3d_Presentation)& aPresentation)
143 gp_Ax1 AxePos = myAxis;
144 gp_Dir theAxisDir = AxePos.Direction();
145 gp_Lin theaxis= gp_Lin (myAxis);
147 if (myAutomaticPosition) {
148 TopExp_Explorer explo1(myFShape,TopAbs_VERTEX);
149 Standard_Real curdist = 0;
150 while (explo1.More()) {
151 TopoDS_Vertex vertref = TopoDS::Vertex(explo1.Current());
152 gp_Pnt curpt = BRep_Tool::Pnt(vertref);
153 if (theaxis.Distance(curpt) > curdist) {
154 curdist = theaxis.Distance(curpt);
155 myFAttach = BRep_Tool::Pnt(vertref);
159 curpos = myFAttach.Rotated(AxePos,myVal/2.);
160 myCenter = ElCLib::Value(ElCLib::Parameter(theaxis,curpos),theaxis);
161 Standard_Real thedista = myCenter.Distance(myFAttach);
162 if (thedista > Precision::Confusion()) {
163 curpos.Scale(myCenter,1.05);
166 myAutomaticPosition = Standard_True;
170 //myFAttach = the point of myFShape closest to curpos (except for the case when this is a point on the axis)
171 Standard_Real dist = RealLast();
172 TopExp_Explorer explo1(myFShape,TopAbs_VERTEX);
173 gp_Pnt AxePosition = AxePos.Location();
174 gp_Vec AxeVector (theAxisDir);
175 gp_XYZ AxeXYZ = AxeVector.XYZ();
176 while (explo1.More()) {
177 gp_Pnt curpt = BRep_Tool::Pnt(TopoDS::Vertex(explo1.Current()));
178 gp_Vec curvec (AxePosition, curpt);
179 gp_XYZ curXYZ = curvec.XYZ();
180 gp_XYZ Norm (curXYZ.Crossed(AxeXYZ));
182 if (Norm.Modulus() > gp::Resolution()) {
183 Standard_Real curdist = curpos.Distance (curpt);
184 if (curdist < dist) {
191 myCenter = ElCLib::Value(ElCLib::Parameter(theaxis,myFAttach),theaxis);
194 mySAttach = myFAttach.Rotated(AxePos,myVal);
196 gp_Vec FVec (myCenter, myFAttach);
197 myFDir.SetXYZ (FVec.XYZ());
198 gp_Vec SVec (myCenter, mySAttach);
199 mySDir.SetXYZ (SVec.XYZ());
201 if (!myAutomaticPosition) {
202 //Projection of the position on the plane defined by myFDir mySDir and normal theAxisDir
203 gp_Pln aPln (myCenter, theAxisDir);
205 ElSLib::Parameters (aPln, curpos, U, V);
206 curpos = ElSLib::Value (U, V, aPln);
210 // Add (myVal, myText,myCenter,myFAttach,mySAttach,myFDir,mySDir,theAxisDir,curpos)