summaryrefslogtreecommitdiff
path: root/src/AIS/AIS_ConcentricRelation.cxx
blob: 83fa5dacb12c9221549f03066bc32dea11995602 (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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
// File:	AIS_ConcentricRelation.cdl
// Created:	Tue Dec  5 15:09:04 1996
// Author:	Flore Lantheaume/Odile Olivier
//              <ODL>

#include <Standard_NotImplemented.hxx>

#include <AIS_ConcentricRelation.ixx>

#include <SelectMgr_EntityOwner.hxx>
#include <Select3D_SensitiveCircle.hxx>
#include <Select3D_SensitiveSegment.hxx>

#include <DsgPrs_ConcentricPresentation.hxx>

#include <TopoDS.hxx>

#include <BRepAdaptor_Curve.hxx>

#include <GeomAbs_CurveType.hxx>
#include <Geom_Circle.hxx>
#include <gp_Dir.hxx>
#include <gp_Vec.hxx>
#include <gp_Ax2.hxx>
#include <gp_Ax1.hxx>
#include <gp_Pnt.hxx>
#include <gp_Pln.hxx>

#include <TopoDS_Vertex.hxx>
#include <AIS.hxx>

//=======================================================================
//function : Constructor
//purpose  : 
//=======================================================================

AIS_ConcentricRelation::AIS_ConcentricRelation(
	const TopoDS_Shape& aFShape, 
	const TopoDS_Shape& aSShape, 
	const Handle(Geom_Plane)& aPlane)
{
  myFShape = aFShape;
  mySShape = aSShape;
  myPlane = aPlane;
  myDir = aPlane->Pln().Axis().Direction();
}

//=======================================================================
//function : Compute
//purpose  : 
//=======================================================================
void AIS_ConcentricRelation::Compute(const Handle(PrsMgr_PresentationManager3d)&, 
				     const Handle(Prs3d_Presentation)& aPresentation, 
				     const Standard_Integer)
{
  aPresentation->Clear();

  TopAbs_ShapeEnum type2(mySShape.ShapeType());
  aPresentation->SetInfiniteState(Standard_True);
  switch (myFShape.ShapeType()) {
  case TopAbs_EDGE: 
    {
      if (type2 == TopAbs_EDGE) ComputeTwoEdgesConcentric(aPresentation);
      else if (type2 == TopAbs_VERTEX) ComputeEdgeVertexConcentric(aPresentation);
    }
  break;
  
  case TopAbs_VERTEX: 
    {
      if (type2 == TopAbs_VERTEX) ComputeTwoVerticesConcentric(aPresentation);
      else if (type2 == TopAbs_EDGE) ComputeEdgeVertexConcentric(aPresentation);      
    }
  break;
  default: {return;}
  }  
}

void AIS_ConcentricRelation::Compute(const Handle_Prs3d_Projector& aProjector, const Handle_Geom_Transformation& aTransformation, const Handle_Prs3d_Presentation& aPresentation)
{
// Standard_NotImplemented::Raise("AIS_ConcentricRelation::Compute(const Handle_Prs3d_Projector&, const Handle_Geom_Transformation&, const Handle_Prs3d_Presentation&)");
  PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation ) ;
}

//=======================================================================
//function : ComputeTwoEdgesConcentric
//purpose  : 
//=======================================================================
void AIS_ConcentricRelation::ComputeEdgeVertexConcentric(const Handle(Prs3d_Presentation)& aPresentation)
{
  TopoDS_Edge E;
  TopoDS_Vertex V;
  if (myFShape.ShapeType() == TopAbs_EDGE) {
    E = TopoDS::Edge(myFShape);
    V = TopoDS::Vertex(mySShape);
  }
  else {
    E = TopoDS::Edge(myFShape);
    V = TopoDS::Vertex(mySShape);
  }
  gp_Pnt p1,p2;
  Handle(Geom_Curve) C;
  Handle(Geom_Curve) extCurv;
  Standard_Boolean isInfinite;
  Standard_Boolean isOnPlanEdge, isOnPlanVertex;
  if (!AIS::ComputeGeometry(E,C,p1,p2,extCurv,isInfinite,isOnPlanEdge,myPlane)) return;
  gp_Pnt P;
  AIS::ComputeGeometry(V,P, myPlane, isOnPlanVertex);

  const Handle(Geom_Circle)& CIRCLE = (Handle(Geom_Circle)&) C;
  myCenter = CIRCLE->Location();
  myRad = Min(CIRCLE->Radius()/5.,15.);
  gp_Dir vec(p1.XYZ() - myCenter.XYZ() );
  gp_Vec vectrans(vec);
  myPnt = myCenter.Translated(vectrans.Multiplied(myRad));
  DsgPrs_ConcentricPresentation::Add(aPresentation,myDrawer,myCenter,myRad,myDir,myPnt);
  if (!isOnPlanEdge) AIS::ComputeProjEdgePresentation(aPresentation,myDrawer,E,CIRCLE,p1,p2);
  if (!isOnPlanVertex) AIS::ComputeProjVertexPresentation(aPresentation,myDrawer,V,P);
}

//=======================================================================
//function : ComputeTwoEdgesConcentric
//purpose  : 
//=======================================================================
void AIS_ConcentricRelation::ComputeTwoVerticesConcentric(const Handle(Prs3d_Presentation)& aPresentation)
{
  TopoDS_Vertex V1,V2;
  V1 = TopoDS::Vertex(myFShape);
  V2 = TopoDS::Vertex(myFShape);  
  Standard_Boolean isOnPlanVertex1(Standard_True),isOnPlanVertex2(Standard_True);
  gp_Pnt P1,P2;
  AIS::ComputeGeometry(V1,P1, myPlane,isOnPlanVertex1);
  AIS::ComputeGeometry(V2,P2, myPlane,isOnPlanVertex2);
  myCenter = P1;
  myRad    = 15.;
  gp_Dir vec(myPlane->Pln().Position().XDirection());
  gp_Vec vectrans(vec);
  myPnt = myCenter.Translated(vectrans.Multiplied(myRad));
  DsgPrs_ConcentricPresentation::Add(aPresentation,myDrawer,myCenter,myRad,myDir,myPnt);
  if (!isOnPlanVertex1) AIS::ComputeProjVertexPresentation(aPresentation,myDrawer,V1,P1);
  if (!isOnPlanVertex1) AIS::ComputeProjVertexPresentation(aPresentation,myDrawer,V2,P2);
}

//=======================================================================
//function : ComputeTwoEdgesConcentric
//purpose  : 
//=======================================================================
void AIS_ConcentricRelation::ComputeTwoEdgesConcentric(const Handle(Prs3d_Presentation)& aPresentation)
{
  BRepAdaptor_Curve curv1(TopoDS::Edge(myFShape));
  BRepAdaptor_Curve curv2(TopoDS::Edge(mySShape));
  
  gp_Pnt ptat11,ptat12,ptat21,ptat22;
  Handle(Geom_Curve) geom1,geom2;
  Standard_Boolean isInfinite1,isInfinite2;
  Handle(Geom_Curve) extCurv;
  if (!AIS::ComputeGeometry(TopoDS::Edge(myFShape),
			    TopoDS::Edge(mySShape),
			    myExtShape,
			    geom1,
			    geom2,
			    ptat11,
			    ptat12,
			    ptat21,
			    ptat22,
			    extCurv,
			    isInfinite1,isInfinite2,
			    myPlane)) {
    return;
  }
  
  const Handle(Geom_Circle)& gcirc1 = (Handle(Geom_Circle)&) geom1;
  const Handle(Geom_Circle)& gcirc2 = (Handle(Geom_Circle)&) geom2;
  
  myCenter = gcirc1->Location();
  
  // choose the radius equal to 1/5 of the smallest radius of 
  // 2 circles. Limit is imposed ( 0.02 by chance)
  Standard_Real rad1 = gcirc1->Radius();
  Standard_Real rad2 = gcirc2->Radius();
  myRad = (rad1 > rad2 ) ? rad2 : rad1;
  myRad /= 5;
  if (myRad > 15.) myRad =15.;
  
  
  //Calculate a point of circle of radius myRad
  gp_Dir vec(ptat11.XYZ() - myCenter.XYZ() );
  gp_Vec vectrans(vec);
  myPnt = myCenter.Translated(vectrans.Multiplied(myRad));
  
  DsgPrs_ConcentricPresentation::Add(aPresentation,
				     myDrawer,
				     myCenter,
				     myRad,
				     myDir,
				     myPnt);
  if ( (myExtShape != 0) &&  !extCurv.IsNull()) {
    gp_Pnt pf, pl;
    if ( myExtShape == 1 ) {
      if (!isInfinite1) {
	pf = ptat11; 
	pl = ptat12;
      }
      ComputeProjEdgePresentation(aPresentation,TopoDS::Edge(myFShape),gcirc1,pf,pl);
    }
    else {
      if (!isInfinite2) {
	pf = ptat21; 
	pl = ptat22;
      }
      ComputeProjEdgePresentation(aPresentation,TopoDS::Edge(mySShape),gcirc2,pf,pl);
    }
  }
}

//=======================================================================
//function : Compute
//purpose  : to avoid warning
//=======================================================================

void AIS_ConcentricRelation::Compute(const Handle(Prs3d_Projector)&, 
				     const Handle(Prs3d_Presentation)&)
{
}

//=======================================================================
//function : Compute
//purpose  : to avoid warning
//=======================================================================

void AIS_ConcentricRelation::Compute(const Handle(PrsMgr_PresentationManager2d)&, 
				     const Handle(Graphic2d_GraphicObject)&,
				     const Standard_Integer)
{
}

//=======================================================================
//function : ComputeSelection
//purpose  : 
//=======================================================================

void AIS_ConcentricRelation::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection, 
					      const Standard_Integer)
{
  Handle(SelectMgr_EntityOwner) own = new SelectMgr_EntityOwner(this,7);
  
  //Creation of 2 sensitive circles
     // the greater
  gp_Ax2 ax(myCenter, myDir);
  Handle(Geom_Circle) Circ = new Geom_Circle(ax, myRad) ;
  Handle(Select3D_SensitiveCircle) 
    sensit = new Select3D_SensitiveCircle (own,
					   Circ);
  aSelection->Add(sensit);
     // the smaller
  Circ->SetRadius(myRad/2);
  sensit = new Select3D_SensitiveCircle (own,
					 Circ);
  aSelection->Add(sensit);

  //Creation of 2 segments sensitive for the cross
  Handle(Select3D_SensitiveSegment) seg;
  gp_Pnt otherPnt = myPnt.Mirrored(myCenter);
  seg = new Select3D_SensitiveSegment(own,
				      otherPnt,
				      myPnt);
  aSelection->Add(seg);

  gp_Ax1 RotateAxis(myCenter, myDir);
  gp_Pnt FPnt = myCenter.Rotated(RotateAxis, PI/2);
  gp_Pnt SPnt = myCenter.Rotated(RotateAxis, -PI/2);
  seg = new Select3D_SensitiveSegment(own,
				      FPnt,
				      SPnt);
  aSelection->Add(seg);

}