0030675: Visualization - remove redundant proxy classes in hierarchy of PrsMgr_Presen...
[occt.git] / src / DrawDim / DrawDim_Angle.cxx
CommitLineData
b311480e 1// Created on: 1996-05-28
2// Created by: Denis PASCAL
3// Copyright (c) 1996-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 8// This library is free software; you can redistribute it and/or modify it under
9// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 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.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
7fd59977 17
7fd59977 18#include <BRep_Tool.hxx>
42cf5bc1 19#include <BRepAdaptor_Surface.hxx>
20#include <Draw_Display.hxx>
21#include <DrawDim.hxx>
22#include <DrawDim_Angle.hxx>
7fd59977 23#include <ElCLib.hxx>
24#include <ElSLib.hxx>
7fd59977 25#include <gp_Ax1.hxx>
42cf5bc1 26#include <gp_Dir.hxx>
27#include <gp_Lin.hxx>
28#include <gp_Pln.hxx>
29#include <gp_Pnt.hxx>
7fd59977 30#include <IntAna_QuadQuadGeo.hxx>
31#include <Precision.hxx>
42cf5bc1 32#include <Standard_Type.hxx>
7fd59977 33#include <TopExp_Explorer.hxx>
42cf5bc1 34#include <TopoDS.hxx>
35#include <TopoDS_Face.hxx>
36#include <TopoDS_Vertex.hxx>
7fd59977 37
92efcf78 38IMPLEMENT_STANDARD_RTTIEXT(DrawDim_Angle,DrawDim_Dimension)
39
7fd59977 40//=======================================================================
41//function : DrawDim_Angle
42//purpose :
43//=======================================================================
7fd59977 44DrawDim_Angle::DrawDim_Angle(const TopoDS_Face& plane1, const TopoDS_Face& plane2)
45{
46 myPlane1 = plane1;
47 myPlane2 = plane2;
48}
49
50//=======================================================================
51//function : Plane1
52//purpose :
53//=======================================================================
54
55const TopoDS_Face& DrawDim_Angle::Plane1() const
56{
57 return myPlane1;
58}
59
60//=======================================================================
61//function : Plane1
62//purpose :
63//=======================================================================
64
65void DrawDim_Angle::Plane1(const TopoDS_Face& plane)
66{
67 myPlane1 = plane;
68}
69
70//=======================================================================
71//function : Plane2
72//purpose :
73//=======================================================================
74
75const TopoDS_Face& DrawDim_Angle::Plane2() const
76{
77 return myPlane2;
78}
79
80//=======================================================================
81//function : Plane2
82//purpose :
83//=======================================================================
84
85void DrawDim_Angle::Plane2(const TopoDS_Face& plane)
86{
87 myPlane2 = plane;
88}
89
90
91//=======================================================================
92//function : DrawOn
93//purpose :
94//=======================================================================
95
96void DrawDim_Angle::DrawOn(Draw_Display& ) const
97{
98
99 // input
100 TopoDS_Shape myFShape = myPlane1;
101 TopoDS_Shape mySShape = myPlane2;
102 Standard_Real myVal = GetValue();
103 gp_Ax1 myAxis;
104
105
106 // output
7fd59977 107 gp_Pnt myFAttach;
108 gp_Pnt mySAttach;
109 gp_Pnt myPosition(0.,0.,0.);
110 gp_Pnt myCenter;
111 gp_Dir myFDir;
112 gp_Dir mySDir;
113 Standard_Boolean myAutomaticPosition = Standard_True;
7fd59977 114
0d969553 115 // calculation of myAxis
7fd59977 116 gp_Pln pln1, pln2;
117 if (!DrawDim::Pln(myPlane1,pln1)) return;
118 if (!DrawDim::Pln(myPlane2,pln2)) return;
119 IntAna_QuadQuadGeo ip (pln1,pln2,Precision::Confusion(), Precision::Angular());
120 if (!ip.IsDone()) return;
7fd59977 121
122 gp_Pnt curpos;
123 gp_Ax1 AxePos = myAxis;
124 gp_Dir theAxisDir = AxePos.Direction();
125 gp_Lin theaxis= gp_Lin (myAxis);
126
127 if (myAutomaticPosition) {
128 TopExp_Explorer explo1(myFShape,TopAbs_VERTEX);
129 Standard_Real curdist = 0;
130 while (explo1.More()) {
131 TopoDS_Vertex vertref = TopoDS::Vertex(explo1.Current());
132 gp_Pnt curpt = BRep_Tool::Pnt(vertref);
133 if (theaxis.Distance(curpt) > curdist) {
134 curdist = theaxis.Distance(curpt);
135 myFAttach = BRep_Tool::Pnt(vertref);
136 }
137 explo1.Next();
138 }
139 curpos = myFAttach.Rotated(AxePos,myVal/2.);
140 myCenter = ElCLib::Value(ElCLib::Parameter(theaxis,curpos),theaxis);
141 Standard_Real thedista = myCenter.Distance(myFAttach);
142 if (thedista > Precision::Confusion()) {
143 curpos.Scale(myCenter,1.05);
144 }
145 myPosition = curpos;
146 myAutomaticPosition = Standard_True;
147 }
148 else {
149 curpos = myPosition;
0d969553 150 //myFAttach = the point of myFShape closest to curpos (except for the case when this is a point on the axis)
7fd59977 151 Standard_Real dist = RealLast();
152 TopExp_Explorer explo1(myFShape,TopAbs_VERTEX);
153 gp_Pnt AxePosition = AxePos.Location();
154 gp_Vec AxeVector (theAxisDir);
155 gp_XYZ AxeXYZ = AxeVector.XYZ();
156 while (explo1.More()) {
157 gp_Pnt curpt = BRep_Tool::Pnt(TopoDS::Vertex(explo1.Current()));
158 gp_Vec curvec (AxePosition, curpt);
159 gp_XYZ curXYZ = curvec.XYZ();
160 gp_XYZ Norm (curXYZ.Crossed(AxeXYZ));
6e6cd5d9 161
7fd59977 162 if (Norm.Modulus() > gp::Resolution()) {
163 Standard_Real curdist = curpos.Distance (curpt);
164 if (curdist < dist) {
165 myFAttach = curpt;
166 dist = curdist;
167 }
168 }
169 explo1.Next();
170 }
171 myCenter = ElCLib::Value(ElCLib::Parameter(theaxis,myFAttach),theaxis);
172 }
173
174 mySAttach = myFAttach.Rotated(AxePos,myVal);
175
176 gp_Vec FVec (myCenter, myFAttach);
177 myFDir.SetXYZ (FVec.XYZ());
178 gp_Vec SVec (myCenter, mySAttach);
179 mySDir.SetXYZ (SVec.XYZ());
180
181 if (!myAutomaticPosition) {
0d969553 182 //Projection of the position on the plane defined by myFDir mySDir and normal theAxisDir
7fd59977 183 gp_Pln aPln (myCenter, theAxisDir);
184 Standard_Real U,V;
185 ElSLib::Parameters (aPln, curpos, U, V);
186 curpos = ElSLib::Value (U, V, aPln);
187 }
188
189 // DISPLAY
190 // Add (myVal, myText,myCenter,myFAttach,mySAttach,myFDir,mySDir,theAxisDir,curpos)
191
192
193}
194
195
196
197
198
199
200
201
202