Integration of OCCT 6.5.0 from SVN
[occt.git] / src / Prs3d / Prs3d_Line.gxx
CommitLineData
7fd59977 1#include <Graphic3d_Array1OfVertex.hxx>
2#include <Graphic3d_Vertex.hxx>
3#include <Graphic3d_Group.hxx>
4#include <Prs3d_Arrow.hxx>
5#include <Prs3d_ArrowAspect.hxx>
6#include <gp_Pnt.hxx>
7#include <gp_Dir.hxx>
8#include <Prs3d_LineAspect.hxx>
9#include <Prs3d.hxx>
10
11static void DrawLine (const anyLine& aLine,
12 const Handle(Graphic3d_Group)& aGroup) {
13
14 Standard_Integer Count=0;
15 Quantity_Length x,y,z;
16
17 Standard_Integer Lower = LineTool::Lower(aLine);
18 Standard_Integer Upper = LineTool::Upper(aLine);
19
20 Graphic3d_Array1OfVertex VertexArray(1,Upper-Lower+1);
21
22 for (Standard_Integer i=Lower;i<=Upper;i++){
23 LineTool::Coord(aLine,i,x,y,z);
24 VertexArray(++Count).SetCoord(x,y,z);
25 }
26 aGroup->Polyline(VertexArray);
27}
28
29void Prs3d_Line::Add (const Handle (Prs3d_Presentation)& aPresentation,
30 const anyLine& aLine,
31 const Handle (Prs3d_Drawer)& aDrawer){
32
33// Prs3d_Root::NewGroup(aPresentation);
34 Handle(Graphic3d_Group) TheGroup = Prs3d_Root::CurrentGroup(aPresentation);
35 TheGroup->SetPrimitivesAspect(aDrawer->LineAspect()->Aspect());
36 DrawLine(aLine,TheGroup);
37 if (aDrawer->LineArrowDraw()) {
38 Standard_Integer Lower = LineTool::Lower(aLine);
39 Standard_Integer Upper = LineTool::Upper(aLine);
40 if ( Upper > Lower ){
41 Quantity_Length x1,y1,z1,x2,y2,z2;
42 LineTool::Coord(aLine,Upper-1,x1,y1,z1);
43 LineTool::Coord(aLine,Upper,x2,y2,z2);
44
45 Prs3d_Arrow::Draw(aPresentation,
46 gp_Pnt(x2,y2,z2),
47 gp_Dir(x2-x1,y2-y1,z2-z1),
48 aDrawer->ArrowAspect()->Angle(),
49 aDrawer->ArrowAspect()->Length());
50 }
51 }
52}
53void Prs3d_Line::Add (const Handle (Prs3d_Presentation)& aPresentation,
54 const anyLine& aLine){
55
56
57 DrawLine (aLine,Prs3d_Root::CurrentGroup(aPresentation));
58
59}
60
61Standard_Integer Prs3d_Line::Pick
62 (const Quantity_Length X,
63 const Quantity_Length Y,
64 const Quantity_Length Z,
65 const Quantity_Length aDistance,
66 const anyLine& aLine,
67 const Handle (Prs3d_Drawer)& aDrawer,
68 const Prs3d_TypeOfLinePicking TypeOfPicking){
69
70
71 Standard_Integer Lower = LineTool::Lower(aLine);
72 Standard_Integer Upper = LineTool::Upper(aLine);
73
74 Standard_Integer num = 0;
75 Quantity_Length X1,Y1,Z1,X2,Y2,Z2,dist;
76
77 Standard_Real DistMin = RealLast();
78
79 for (Standard_Integer i=Lower;i<=Upper;i++){
80 LineTool::Coord(aLine,i,X2,Y2,Z2);
81 switch (TypeOfPicking) {
82 case Prs3d_TOLP_Point: {
83 dist = Abs(X-X2)+Abs(Y-Y2)+ Abs(Z-Z2);
84 if(dist < aDistance) {
85 if (dist < DistMin) {
86 DistMin = dist;
87 num = i;
88 }
89 }
90 }
91 break;
92 case Prs3d_TOLP_Segment: {
93 if (i > 1) {
94 if (Prs3d::MatchSegment
95 (X,Y,Z,aDistance,gp_Pnt(X1,Y1,Z1),gp_Pnt(X2,Y2,Z2),dist)){
96 if(dist < aDistance) {
97 if (dist < DistMin) {
98 DistMin = dist;
99 num = i;
100 }
101 }
102 }
103 }
104 X1=X2;Y1=Y2;Z1=Z2;
105 }
106 break;
107 }
108 }
109 return num;
110}