Test for 0022778: Bug in BRepMesh
[occt.git] / src / Prs3d / Prs3d_Line.gxx
CommitLineData
b311480e 1// Copyright (c) 1995-1999 Matra Datavision
2// Copyright (c) 1999-2012 OPEN CASCADE SAS
3//
4// The content of this file is subject to the Open CASCADE Technology Public
5// License Version 6.5 (the "License"). You may not use the content of this file
6// except in compliance with the License. Please obtain a copy of the License
7// at http://www.opencascade.org and read it completely before using this file.
8//
9// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
10// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
11//
12// The Original Code and all software distributed under the License is
13// distributed on an "AS IS" basis, without warranty of any kind, and the
14// Initial Developer hereby disclaims all such warranties, including without
15// limitation, any warranties of merchantability, fitness for a particular
16// purpose or non-infringement. Please see the License for the specific terms
17// and conditions governing the rights and limitations under the License.
18
7fd59977 19#include <Graphic3d_Array1OfVertex.hxx>
20#include <Graphic3d_Vertex.hxx>
21#include <Graphic3d_Group.hxx>
22#include <Prs3d_Arrow.hxx>
23#include <Prs3d_ArrowAspect.hxx>
24#include <gp_Pnt.hxx>
25#include <gp_Dir.hxx>
26#include <Prs3d_LineAspect.hxx>
27#include <Prs3d.hxx>
28
29static void DrawLine (const anyLine& aLine,
30 const Handle(Graphic3d_Group)& aGroup) {
31
32 Standard_Integer Count=0;
33 Quantity_Length x,y,z;
34
35 Standard_Integer Lower = LineTool::Lower(aLine);
36 Standard_Integer Upper = LineTool::Upper(aLine);
37
38 Graphic3d_Array1OfVertex VertexArray(1,Upper-Lower+1);
39
40 for (Standard_Integer i=Lower;i<=Upper;i++){
41 LineTool::Coord(aLine,i,x,y,z);
42 VertexArray(++Count).SetCoord(x,y,z);
43 }
44 aGroup->Polyline(VertexArray);
45}
46
47void Prs3d_Line::Add (const Handle (Prs3d_Presentation)& aPresentation,
48 const anyLine& aLine,
49 const Handle (Prs3d_Drawer)& aDrawer){
50
51// Prs3d_Root::NewGroup(aPresentation);
52 Handle(Graphic3d_Group) TheGroup = Prs3d_Root::CurrentGroup(aPresentation);
53 TheGroup->SetPrimitivesAspect(aDrawer->LineAspect()->Aspect());
54 DrawLine(aLine,TheGroup);
55 if (aDrawer->LineArrowDraw()) {
56 Standard_Integer Lower = LineTool::Lower(aLine);
57 Standard_Integer Upper = LineTool::Upper(aLine);
58 if ( Upper > Lower ){
59 Quantity_Length x1,y1,z1,x2,y2,z2;
60 LineTool::Coord(aLine,Upper-1,x1,y1,z1);
61 LineTool::Coord(aLine,Upper,x2,y2,z2);
62
63 Prs3d_Arrow::Draw(aPresentation,
64 gp_Pnt(x2,y2,z2),
65 gp_Dir(x2-x1,y2-y1,z2-z1),
66 aDrawer->ArrowAspect()->Angle(),
67 aDrawer->ArrowAspect()->Length());
68 }
69 }
70}
71void Prs3d_Line::Add (const Handle (Prs3d_Presentation)& aPresentation,
72 const anyLine& aLine){
73
74
75 DrawLine (aLine,Prs3d_Root::CurrentGroup(aPresentation));
76
77}
78
79Standard_Integer Prs3d_Line::Pick
80 (const Quantity_Length X,
81 const Quantity_Length Y,
82 const Quantity_Length Z,
83 const Quantity_Length aDistance,
84 const anyLine& aLine,
85 const Handle (Prs3d_Drawer)& aDrawer,
86 const Prs3d_TypeOfLinePicking TypeOfPicking){
87
88
89 Standard_Integer Lower = LineTool::Lower(aLine);
90 Standard_Integer Upper = LineTool::Upper(aLine);
91
92 Standard_Integer num = 0;
93 Quantity_Length X1,Y1,Z1,X2,Y2,Z2,dist;
94
95 Standard_Real DistMin = RealLast();
96
97 for (Standard_Integer i=Lower;i<=Upper;i++){
98 LineTool::Coord(aLine,i,X2,Y2,Z2);
99 switch (TypeOfPicking) {
100 case Prs3d_TOLP_Point: {
101 dist = Abs(X-X2)+Abs(Y-Y2)+ Abs(Z-Z2);
102 if(dist < aDistance) {
103 if (dist < DistMin) {
104 DistMin = dist;
105 num = i;
106 }
107 }
108 }
109 break;
110 case Prs3d_TOLP_Segment: {
111 if (i > 1) {
112 if (Prs3d::MatchSegment
113 (X,Y,Z,aDistance,gp_Pnt(X1,Y1,Z1),gp_Pnt(X2,Y2,Z2),dist)){
114 if(dist < aDistance) {
115 if (dist < DistMin) {
116 DistMin = dist;
117 num = i;
118 }
119 }
120 }
121 }
122 X1=X2;Y1=Y2;Z1=Z2;
123 }
124 break;
125 }
126 }
127 return num;
128}