Test for 0022778: Bug in BRepMesh
[occt.git] / src / StdPrs / StdPrs_Plane.cxx
CommitLineData
b311480e 1// Created on: 1995-07-24
2// Created by: Modelistation
3// Copyright (c) 1995-1999 Matra Datavision
4// Copyright (c) 1999-2012 OPEN CASCADE SAS
5//
6// The content of this file is subject to the Open CASCADE Technology Public
7// License Version 6.5 (the "License"). You may not use the content of this file
8// except in compliance with the License. Please obtain a copy of the License
9// at http://www.opencascade.org and read it completely before using this file.
10//
11// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13//
14// The Original Code and all software distributed under the License is
15// distributed on an "AS IS" basis, without warranty of any kind, and the
16// Initial Developer hereby disclaims all such warranties, including without
17// limitation, any warranties of merchantability, fitness for a particular
18// purpose or non-infringement. Please see the License for the specific terms
19// and conditions governing the rights and limitations under the License.
20
7fd59977 21
22
23#include <StdPrs_Plane.ixx>
24#include <Graphic3d_Array1OfVertex.hxx>
25#include <Graphic3d_Vertex.hxx>
26#include <Graphic3d_Group.hxx>
27#include <Prs3d_Arrow.hxx>
28#include <Prs3d_ArrowAspect.hxx>
29#include <gp_Pnt.hxx>
30#include <gp_Vec.hxx>
31#include <gp_Pln.hxx>
32#include <gp_Dir.hxx>
33#include <Prs3d_LineAspect.hxx>
34#include <Prs3d_PlaneAspect.hxx>
35#include <Prs3d.hxx>
36#include <Geom_Plane.hxx>
37
38
39void StdPrs_Plane::Add (const Handle (Prs3d_Presentation)& aPresentation,
40 const Adaptor3d_Surface& aPlane,
41 const Handle (Prs3d_Drawer)& aDrawer)
42{
43// Prs3d_Root::NewGroup(aPresentation);
44 Handle(Graphic3d_Group) TheGroup = Prs3d_Root::CurrentGroup(aPresentation);
45 if (aPlane.GetType() != GeomAbs_Plane) return;
46 Handle(Geom_Plane) thegeom = new Geom_Plane(aPlane.Plane());
47
48 Handle(Prs3d_PlaneAspect) theaspect = aDrawer->PlaneAspect();
49
50 gp_Pnt p1;
51 Standard_Real Xmax,Ymax;
52 Xmax = Standard_Real(theaspect->PlaneXLength())/2.;
53 Ymax = Standard_Real(theaspect->PlaneYLength())/2.;
54 if (theaspect->DisplayEdges()) {
55 static Graphic3d_Array1OfVertex EdgesArray(1,5);
56 TheGroup->SetPrimitivesAspect(theaspect->EdgesAspect()->Aspect());
57 thegeom->D0(-Xmax,Ymax,p1);
58 EdgesArray(1).SetCoord(p1.X(),p1.Y(),p1.Z());
59 EdgesArray(5).SetCoord(p1.X(),p1.Y(),p1.Z());
60 thegeom->D0(Xmax,Ymax,p1);
61 EdgesArray(2).SetCoord(p1.X(),p1.Y(),p1.Z());
62 thegeom->D0(Xmax,-Ymax,p1);
63 EdgesArray(3).SetCoord(p1.X(),p1.Y(),p1.Z());
64 thegeom->D0(-Xmax,-Ymax,p1);
65 EdgesArray(4).SetCoord(p1.X(),p1.Y(),p1.Z());
66 TheGroup->Polyline(EdgesArray);
67 }
68
69 if (theaspect->DisplayIso()) {
70 static Graphic3d_Array1OfVertex IsoArray(1,2);
71 TheGroup->SetPrimitivesAspect(theaspect->IsoAspect()->Aspect());
72 Standard_Real dist = theaspect->IsoDistance();
73 Standard_Real cur = -Xmax+dist;
74 while (cur+dist/2. <= Xmax) {
75 thegeom->D0(cur,Ymax,p1);
76 IsoArray(1).SetCoord(p1.X(),p1.Y(),p1.Z());
77 thegeom->D0(cur,-Ymax,p1);
78 IsoArray(2).SetCoord(p1.X(),p1.Y(),p1.Z());
79 TheGroup->Polyline(IsoArray);
80 cur += dist;
81 }
82 cur = -Ymax+dist;
83 while (cur+dist/2. < Ymax) {
84 thegeom->D0(Xmax,cur,p1);
85 IsoArray(1).SetCoord(p1.X(),p1.Y(),p1.Z());
86 thegeom->D0(-Xmax,cur,p1);
87 IsoArray(2).SetCoord(p1.X(),p1.Y(),p1.Z());
88 TheGroup->Polyline(IsoArray);
89 cur += dist;
90 }
91 }
92
93 gp_Dir norm = thegeom->Pln().Axis().Direction();
94 gp_Pnt loc;
95 Quantity_Length siz = theaspect->ArrowsSize();
96 Quantity_Length len = theaspect->ArrowsLength();
97 Quantity_PlaneAngle ang = theaspect->ArrowsAngle();
98 gp_Vec trans(norm);
99 trans.Scale(Standard_Real(siz));
100 TheGroup->SetPrimitivesAspect(theaspect->ArrowAspect()->Aspect());
101 Graphic3d_Array1OfVertex ArrowArray(1,2);
102 if (theaspect->DisplayCenterArrow()) {
103 loc = thegeom->Location();
104 p1 = loc.Translated(trans);
105 ArrowArray(1).SetCoord(loc.X(),loc.Y(),loc.Z());
106 ArrowArray(2).SetCoord(p1.X(),p1.Y(),p1.Z());
107 TheGroup->Polyline(ArrowArray);
108 Prs3d_Arrow::Draw(aPresentation,
109 p1,
110 norm,
111 ang,
112 len);
113 }
114 if (theaspect->DisplayEdgesArrows()) {
115 thegeom->D0(-Xmax,-Ymax,loc);
116 p1 = loc.Translated(trans);
117 ArrowArray(1).SetCoord(loc.X(),loc.Y(),loc.Z());
118 ArrowArray(2).SetCoord(p1.X(),p1.Y(),p1.Z());
119 TheGroup->Polyline(ArrowArray);
120 Prs3d_Arrow::Draw(aPresentation,
121 p1,
122 norm,
123 ang,
124 len);
125 thegeom->D0(-Xmax,Ymax,loc);
126 p1 = loc.Translated(trans);
127 ArrowArray(1).SetCoord(loc.X(),loc.Y(),loc.Z());
128 ArrowArray(2).SetCoord(p1.X(),p1.Y(),p1.Z());
129 TheGroup->Polyline(ArrowArray);
130 Prs3d_Arrow::Draw(aPresentation,
131 p1,
132 norm,
133 ang,
134 len);
135 thegeom->D0(Xmax,Ymax,loc);
136 p1 = loc.Translated(trans);
137 ArrowArray(1).SetCoord(loc.X(),loc.Y(),loc.Z());
138 ArrowArray(2).SetCoord(p1.X(),p1.Y(),p1.Z());
139 TheGroup->Polyline(ArrowArray);
140 Prs3d_Arrow::Draw(aPresentation,
141 p1,
142 norm,
143 ang,
144 len);
145 thegeom->D0(Xmax,-Ymax,loc);
146 p1 = loc.Translated(trans);
147 ArrowArray(1).SetCoord(loc.X(),loc.Y(),loc.Z());
148 ArrowArray(2).SetCoord(p1.X(),p1.Y(),p1.Z());
149 TheGroup->Polyline(ArrowArray);
150 Prs3d_Arrow::Draw(aPresentation,
151 p1,
152 norm,
153 ang,
154 len);
155 }
156
157}
158
159Standard_Boolean StdPrs_Plane::Match
160 (const Quantity_Length X,
161 const Quantity_Length Y,
162 const Quantity_Length Z,
163 const Quantity_Length aDistance,
164 const Adaptor3d_Surface& aPlane,
165 const Handle (Prs3d_Drawer)&)
166{
167 if (aPlane.GetType() == GeomAbs_Plane) {
168 gp_Pln theplane = aPlane.Plane();
169 gp_Pnt thepoint (X,Y,Z);
170
171 return (Abs(theplane.Distance(thepoint)) <= aDistance);
172 }
173 else return Standard_False;
174}