summaryrefslogtreecommitdiff
path: root/src/DrawDim/DrawDim_Angle.cxx
blob: e35027ee9b9a1b85c6c962ffb5be2a514368d383 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
// File:	DrawDim_Angle.cxx
// Created:	Tue May 28 12:36:20 1996
// Author:	Denis PASCAL
//		<dp@zerox>


#include <DrawDim_Angle.ixx>
#include <DrawDim.hxx>

#include <BRepAdaptor_Surface.hxx>
#include <BRep_Tool.hxx>
#include <ElCLib.hxx>
#include <ElSLib.hxx>
#include <gp_Pnt.hxx>
#include <gp_Pln.hxx>
#include <gp_Lin.hxx>
#include <gp_Dir.hxx>
#include <gp_Ax1.hxx>
#include <TopoDS.hxx>
#include <IntAna_QuadQuadGeo.hxx>
#include <Precision.hxx>
#include <TopExp_Explorer.hxx>
#include <TopoDS_Vertex.hxx> 
#include <IntAna_QuadQuadGeo.hxx>

//=======================================================================
//function : DrawDim_Angle
//purpose  : 
//=======================================================================

DrawDim_Angle::DrawDim_Angle(const TopoDS_Face& plane1, const TopoDS_Face& plane2)
{
  myPlane1 = plane1;
  myPlane2 = plane2;
}

//=======================================================================
//function : Plane1
//purpose  : 
//=======================================================================

const TopoDS_Face& DrawDim_Angle::Plane1() const 
{
  return myPlane1;
}

//=======================================================================
//function : Plane1
//purpose  : 
//=======================================================================

void DrawDim_Angle::Plane1(const TopoDS_Face& plane)
{
  myPlane1 = plane;
}

//=======================================================================
//function : Plane2
//purpose  : 
//=======================================================================

const TopoDS_Face& DrawDim_Angle::Plane2() const 
{  
  return myPlane2;
}

//=======================================================================
//function : Plane2
//purpose  : 
//=======================================================================

void DrawDim_Angle::Plane2(const TopoDS_Face& plane)
{
  myPlane2 = plane;
}


//=======================================================================
//function : DrawOn
//purpose  : 
//=======================================================================

void DrawDim_Angle::DrawOn(Draw_Display& ) const 
{

  // input
  TopoDS_Shape myFShape = myPlane1;
  TopoDS_Shape mySShape = myPlane2;  
  Standard_Real myVal = GetValue();
  gp_Ax1 myAxis;


  // output
#ifdef DEB
  gp_Dir myDirAttach;
#endif
  gp_Pnt myFAttach;
  gp_Pnt mySAttach;
  gp_Pnt myPosition(0.,0.,0.);
  gp_Pnt myCenter;
  gp_Dir myFDir;
  gp_Dir mySDir;
  Standard_Boolean myAutomaticPosition = Standard_True;
  


  // calcul de myAxis
  gp_Pln pln1, pln2;
  if (!DrawDim::Pln(myPlane1,pln1)) return;
  if (!DrawDim::Pln(myPlane2,pln2)) return; 
  IntAna_QuadQuadGeo ip (pln1,pln2,Precision::Confusion(), Precision::Angular());
  if (!ip.IsDone()) return;
  ip.Line(1);
  
  //Handle(Geom_Surface) curve1 = BRep_Tool::Surface(myPlane1);
  //Handle(Geom_PlaneLine) line1 = Handle(Geom_Line)::DownCast(curve1);    
  


//=======================================================================
//function : ComputeTwoFacesAngle
//purpose  : 
//=======================================================================

// void AIS_AngleDimension::ComputeTwoFacesAngle(const Handle(Prs3d_Presentation)& aPresentation)
// {
  // Recuperation des plans
 
  gp_Pnt curpos;
  gp_Ax1 AxePos = myAxis;      
  gp_Dir theAxisDir = AxePos.Direction();
  gp_Lin theaxis= gp_Lin (myAxis);
      
  if (myAutomaticPosition) {
    TopExp_Explorer explo1(myFShape,TopAbs_VERTEX);
    Standard_Real curdist = 0;
    while  (explo1.More()) {
      TopoDS_Vertex vertref = TopoDS::Vertex(explo1.Current());
      gp_Pnt curpt = BRep_Tool::Pnt(vertref);
      if (theaxis.Distance(curpt) > curdist) {
	curdist = theaxis.Distance(curpt);
	myFAttach = BRep_Tool::Pnt(vertref);
      }
      explo1.Next();
    }
    curpos = myFAttach.Rotated(AxePos,myVal/2.);
    myCenter = ElCLib::Value(ElCLib::Parameter(theaxis,curpos),theaxis);
    Standard_Real thedista = myCenter.Distance(myFAttach);
    if (thedista > Precision::Confusion()) {
      curpos.Scale(myCenter,1.05);
    }
    myPosition = curpos;
    myAutomaticPosition = Standard_True;      
  }
  else {
    curpos = myPosition;
    //myFAttach  = le point de myFShape le plus proche de curpos (sauf si c'est un point sur l'axe)
    Standard_Real dist = RealLast(); 
    TopExp_Explorer explo1(myFShape,TopAbs_VERTEX);
    gp_Pnt  AxePosition = AxePos.Location();
    gp_Vec  AxeVector (theAxisDir);
    gp_XYZ  AxeXYZ  = AxeVector.XYZ();
    while (explo1.More()) {
      gp_Pnt curpt = BRep_Tool::Pnt(TopoDS::Vertex(explo1.Current()));
      gp_Vec curvec (AxePosition, curpt);
      gp_XYZ curXYZ = curvec.XYZ();
      gp_XYZ Norm (curXYZ.Crossed(AxeXYZ));
      if (Norm.Modulus() > gp::Resolution()) {
	Standard_Real curdist = curpos.Distance (curpt);
	if (curdist < dist) {
	  myFAttach = curpt;
	  dist = curdist;
	}
      }
      explo1.Next();
    }
    myCenter = ElCLib::Value(ElCLib::Parameter(theaxis,myFAttach),theaxis);
  }

  mySAttach = myFAttach.Rotated(AxePos,myVal);
      
  gp_Vec FVec (myCenter, myFAttach);
  myFDir.SetXYZ (FVec.XYZ());
  gp_Vec SVec (myCenter, mySAttach);
  mySDir.SetXYZ (SVec.XYZ());

  if (!myAutomaticPosition) {
    //Projection de la position sur le plan defini par  myFDir mySDir et de normale  theAxisDir
    gp_Pln aPln (myCenter, theAxisDir);
    Standard_Real U,V;
    ElSLib::Parameters (aPln, curpos, U, V);
    curpos = ElSLib::Value (U, V, aPln);
  }

  // DISPLAY
  // Add (myVal, myText,myCenter,myFAttach,mySAttach,myFDir,mySDir,theAxisDir,curpos)

          
}