Integration of OCCT 6.5.0 from SVN
[occt.git] / src / StdPrs / StdPrs_Plane.cxx
1 // File:        StdPrs_Plane.cxx
2 // Created:     Mon Jul 24 16:42:41 1995
3 // Author:      Modelistation
4 //              <model@metrox>
5
6
7 #include <StdPrs_Plane.ixx>
8 #include <Graphic3d_Array1OfVertex.hxx>
9 #include <Graphic3d_Vertex.hxx>
10 #include <Graphic3d_Group.hxx>
11 #include <Prs3d_Arrow.hxx>
12 #include <Prs3d_ArrowAspect.hxx>
13 #include <gp_Pnt.hxx>
14 #include <gp_Vec.hxx>
15 #include <gp_Pln.hxx>
16 #include <gp_Dir.hxx>
17 #include <Prs3d_LineAspect.hxx>
18 #include <Prs3d_PlaneAspect.hxx>
19 #include <Prs3d.hxx>
20 #include <Geom_Plane.hxx>
21
22
23 void StdPrs_Plane::Add (const Handle (Prs3d_Presentation)& aPresentation,
24                         const Adaptor3d_Surface&             aPlane,
25                         const Handle (Prs3d_Drawer)&       aDrawer)
26 {
27 //  Prs3d_Root::NewGroup(aPresentation);    
28   Handle(Graphic3d_Group) TheGroup = Prs3d_Root::CurrentGroup(aPresentation);
29   if (aPlane.GetType() != GeomAbs_Plane) return;
30   Handle(Geom_Plane) thegeom = new Geom_Plane(aPlane.Plane());
31
32   Handle(Prs3d_PlaneAspect) theaspect = aDrawer->PlaneAspect();
33
34   gp_Pnt p1;
35   Standard_Real Xmax,Ymax;
36   Xmax = Standard_Real(theaspect->PlaneXLength())/2.;
37   Ymax = Standard_Real(theaspect->PlaneYLength())/2.;
38   if (theaspect->DisplayEdges()) {
39     static Graphic3d_Array1OfVertex EdgesArray(1,5);
40     TheGroup->SetPrimitivesAspect(theaspect->EdgesAspect()->Aspect());
41     thegeom->D0(-Xmax,Ymax,p1);
42     EdgesArray(1).SetCoord(p1.X(),p1.Y(),p1.Z());
43     EdgesArray(5).SetCoord(p1.X(),p1.Y(),p1.Z());
44     thegeom->D0(Xmax,Ymax,p1);
45     EdgesArray(2).SetCoord(p1.X(),p1.Y(),p1.Z());
46     thegeom->D0(Xmax,-Ymax,p1);
47     EdgesArray(3).SetCoord(p1.X(),p1.Y(),p1.Z());
48     thegeom->D0(-Xmax,-Ymax,p1);
49     EdgesArray(4).SetCoord(p1.X(),p1.Y(),p1.Z());
50     TheGroup->Polyline(EdgesArray);
51   }
52
53   if (theaspect->DisplayIso()) {
54     static Graphic3d_Array1OfVertex IsoArray(1,2);
55     TheGroup->SetPrimitivesAspect(theaspect->IsoAspect()->Aspect());
56     Standard_Real dist = theaspect->IsoDistance();
57     Standard_Real cur = -Xmax+dist;
58     while (cur+dist/2. <= Xmax) {
59       thegeom->D0(cur,Ymax,p1);
60       IsoArray(1).SetCoord(p1.X(),p1.Y(),p1.Z());
61       thegeom->D0(cur,-Ymax,p1);
62       IsoArray(2).SetCoord(p1.X(),p1.Y(),p1.Z());
63       TheGroup->Polyline(IsoArray);
64       cur += dist;
65     }
66     cur = -Ymax+dist;
67     while (cur+dist/2. < Ymax) {
68       thegeom->D0(Xmax,cur,p1);
69       IsoArray(1).SetCoord(p1.X(),p1.Y(),p1.Z());
70       thegeom->D0(-Xmax,cur,p1);
71       IsoArray(2).SetCoord(p1.X(),p1.Y(),p1.Z());
72       TheGroup->Polyline(IsoArray);
73       cur += dist;
74     }
75   }
76
77   gp_Dir norm = thegeom->Pln().Axis().Direction();
78   gp_Pnt loc;
79   Quantity_Length siz = theaspect->ArrowsSize();
80   Quantity_Length len = theaspect->ArrowsLength();
81   Quantity_PlaneAngle ang = theaspect->ArrowsAngle();
82   gp_Vec trans(norm);
83   trans.Scale(Standard_Real(siz));
84   TheGroup->SetPrimitivesAspect(theaspect->ArrowAspect()->Aspect());
85   Graphic3d_Array1OfVertex ArrowArray(1,2);
86   if (theaspect->DisplayCenterArrow()) {
87     loc = thegeom->Location();
88     p1 = loc.Translated(trans);
89     ArrowArray(1).SetCoord(loc.X(),loc.Y(),loc.Z());
90     ArrowArray(2).SetCoord(p1.X(),p1.Y(),p1.Z());
91     TheGroup->Polyline(ArrowArray);
92     Prs3d_Arrow::Draw(aPresentation,
93                       p1,
94                       norm,
95                       ang,
96                       len);
97   }
98   if (theaspect->DisplayEdgesArrows()) {
99     thegeom->D0(-Xmax,-Ymax,loc);
100     p1 = loc.Translated(trans);
101     ArrowArray(1).SetCoord(loc.X(),loc.Y(),loc.Z());
102     ArrowArray(2).SetCoord(p1.X(),p1.Y(),p1.Z());
103     TheGroup->Polyline(ArrowArray);
104     Prs3d_Arrow::Draw(aPresentation,
105                       p1,
106                       norm,
107                       ang,
108                       len);
109     thegeom->D0(-Xmax,Ymax,loc);
110     p1 = loc.Translated(trans);
111     ArrowArray(1).SetCoord(loc.X(),loc.Y(),loc.Z());
112     ArrowArray(2).SetCoord(p1.X(),p1.Y(),p1.Z());
113     TheGroup->Polyline(ArrowArray);
114     Prs3d_Arrow::Draw(aPresentation,
115                       p1,
116                       norm,
117                       ang,
118                       len);
119     thegeom->D0(Xmax,Ymax,loc);
120     p1 = loc.Translated(trans);
121     ArrowArray(1).SetCoord(loc.X(),loc.Y(),loc.Z());
122     ArrowArray(2).SetCoord(p1.X(),p1.Y(),p1.Z());
123     TheGroup->Polyline(ArrowArray);
124     Prs3d_Arrow::Draw(aPresentation,
125                       p1,
126                       norm,
127                       ang,
128                       len);
129     thegeom->D0(Xmax,-Ymax,loc);
130     p1 = loc.Translated(trans);
131     ArrowArray(1).SetCoord(loc.X(),loc.Y(),loc.Z());
132     ArrowArray(2).SetCoord(p1.X(),p1.Y(),p1.Z());
133     TheGroup->Polyline(ArrowArray);
134     Prs3d_Arrow::Draw(aPresentation,
135                       p1,
136                       norm,
137                       ang,
138                       len);
139   }
140   
141 }
142
143 Standard_Boolean StdPrs_Plane::Match
144   (const Quantity_Length X,
145    const Quantity_Length Y,
146    const Quantity_Length Z,
147    const Quantity_Length aDistance,
148    const Adaptor3d_Surface& aPlane,
149    const Handle (Prs3d_Drawer)&)
150 {
151   if (aPlane.GetType() == GeomAbs_Plane) {  
152     gp_Pln theplane = aPlane.Plane();
153     gp_Pnt thepoint (X,Y,Z);
154     
155     return (Abs(theplane.Distance(thepoint)) <= aDistance);
156   }
157   else return Standard_False;
158 }