b311480e |
1 | // Created on: 1995-07-24 |
2 | // Created by: Modelistation |
3 | // Copyright (c) 1995-1999 Matra Datavision |
973c2be1 |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | // |
973c2be1 |
6 | // This file is part of Open CASCADE Technology software library. |
b311480e |
7 | // |
d5f74e42 |
8 | // This library is free software; you can redistribute it and/or modify it under |
9 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
10 | // by the Free Software Foundation, with special exception defined in the file |
11 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
12 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
b311480e |
16 | |
42cf5bc1 |
17 | |
18 | #include <Adaptor3d_Surface.hxx> |
19 | #include <Geom_Plane.hxx> |
20 | #include <gp_Dir.hxx> |
21 | #include <gp_Pln.hxx> |
22 | #include <gp_Pnt.hxx> |
23 | #include <gp_Vec.hxx> |
b8ddfc2f |
24 | #include <Graphic3d_ArrayOfPolylines.hxx> |
42cf5bc1 |
25 | #include <Graphic3d_ArrayOfSegments.hxx> |
7fd59977 |
26 | #include <Graphic3d_Group.hxx> |
42cf5bc1 |
27 | #include <Graphic3d_Vertex.hxx> |
28 | #include <Prs3d.hxx> |
7fd59977 |
29 | #include <Prs3d_Arrow.hxx> |
30 | #include <Prs3d_ArrowAspect.hxx> |
7fd59977 |
31 | #include <Prs3d_LineAspect.hxx> |
32 | #include <Prs3d_PlaneAspect.hxx> |
42cf5bc1 |
33 | #include <Prs3d_Presentation.hxx> |
34 | #include <StdPrs_Plane.hxx> |
7fd59977 |
35 | |
36 | void StdPrs_Plane::Add (const Handle (Prs3d_Presentation)& aPresentation, |
b8ddfc2f |
37 | const Adaptor3d_Surface& aPlane, |
38 | const Handle (Prs3d_Drawer)& aDrawer) |
7fd59977 |
39 | { |
40 | // Prs3d_Root::NewGroup(aPresentation); |
41 | Handle(Graphic3d_Group) TheGroup = Prs3d_Root::CurrentGroup(aPresentation); |
42 | if (aPlane.GetType() != GeomAbs_Plane) return; |
43 | Handle(Geom_Plane) thegeom = new Geom_Plane(aPlane.Plane()); |
44 | |
45 | Handle(Prs3d_PlaneAspect) theaspect = aDrawer->PlaneAspect(); |
46 | |
47 | gp_Pnt p1; |
48 | Standard_Real Xmax,Ymax; |
b8ddfc2f |
49 | Xmax = 0.5*Standard_Real(theaspect->PlaneXLength()); |
50 | Ymax = 0.5*Standard_Real(theaspect->PlaneYLength()); |
7fd59977 |
51 | if (theaspect->DisplayEdges()) { |
7fd59977 |
52 | TheGroup->SetPrimitivesAspect(theaspect->EdgesAspect()->Aspect()); |
b8ddfc2f |
53 | Handle(Graphic3d_ArrayOfPolylines) aPrims = new Graphic3d_ArrayOfPolylines(5); |
54 | p1 = thegeom->Value(-Xmax,Ymax); |
55 | aPrims->AddVertex(p1); |
56 | aPrims->AddVertex(thegeom->Value( Xmax, Ymax)); |
57 | aPrims->AddVertex(thegeom->Value( Xmax,-Ymax)); |
58 | aPrims->AddVertex(thegeom->Value(-Xmax,-Ymax)); |
59 | aPrims->AddVertex(p1); |
60 | TheGroup->AddPrimitiveArray(aPrims); |
7fd59977 |
61 | } |
62 | |
63 | if (theaspect->DisplayIso()) { |
7fd59977 |
64 | TheGroup->SetPrimitivesAspect(theaspect->IsoAspect()->Aspect()); |
b8ddfc2f |
65 | const Standard_Real dist = theaspect->IsoDistance(); |
66 | const Standard_Integer nbx = Standard_Integer(Abs(2.*Xmax) / dist) - 1; |
67 | const Standard_Integer nby = Standard_Integer(Abs(2.*Ymax) / dist) - 1; |
68 | Handle(Graphic3d_ArrayOfSegments) aPrims = new Graphic3d_ArrayOfSegments(2*(nbx+nby)); |
69 | Standard_Integer i; |
7fd59977 |
70 | Standard_Real cur = -Xmax+dist; |
b8ddfc2f |
71 | for (i = 0; i < nbx; i++, cur += dist) { |
72 | aPrims->AddVertex(thegeom->Value(cur, Ymax)); |
73 | aPrims->AddVertex(thegeom->Value(cur,-Ymax)); |
7fd59977 |
74 | } |
75 | cur = -Ymax+dist; |
b8ddfc2f |
76 | for (i = 0; i < nby; i++, cur += dist) { |
77 | aPrims->AddVertex(thegeom->Value( Xmax,cur)); |
78 | aPrims->AddVertex(thegeom->Value(-Xmax,cur)); |
7fd59977 |
79 | } |
b8ddfc2f |
80 | TheGroup->AddPrimitiveArray(aPrims); |
7fd59977 |
81 | } |
82 | |
83 | gp_Dir norm = thegeom->Pln().Axis().Direction(); |
84 | gp_Pnt loc; |
85 | Quantity_Length siz = theaspect->ArrowsSize(); |
86 | Quantity_Length len = theaspect->ArrowsLength(); |
87 | Quantity_PlaneAngle ang = theaspect->ArrowsAngle(); |
88 | gp_Vec trans(norm); |
89 | trans.Scale(Standard_Real(siz)); |
b8ddfc2f |
90 | |
7fd59977 |
91 | TheGroup->SetPrimitivesAspect(theaspect->ArrowAspect()->Aspect()); |
7fd59977 |
92 | if (theaspect->DisplayCenterArrow()) { |
93 | loc = thegeom->Location(); |
94 | p1 = loc.Translated(trans); |
b8ddfc2f |
95 | Handle(Graphic3d_ArrayOfSegments) aPrims = new Graphic3d_ArrayOfSegments(2); |
96 | aPrims->AddVertex(loc); |
97 | aPrims->AddVertex(p1); |
98 | TheGroup->AddPrimitiveArray(aPrims); |
4ad142d9 |
99 | Prs3d_Arrow::Draw (Prs3d_Root::CurrentGroup (aPresentation), p1, norm, ang, len); |
7fd59977 |
100 | } |
101 | if (theaspect->DisplayEdgesArrows()) { |
b8ddfc2f |
102 | Handle(Graphic3d_ArrayOfSegments) aPrims = new Graphic3d_ArrayOfSegments(8); |
103 | // |
7fd59977 |
104 | thegeom->D0(-Xmax,-Ymax,loc); |
105 | p1 = loc.Translated(trans); |
b8ddfc2f |
106 | aPrims->AddVertex(loc); |
107 | aPrims->AddVertex(p1); |
4ad142d9 |
108 | Prs3d_Arrow::Draw (Prs3d_Root::CurrentGroup (aPresentation), p1, norm, ang, len); |
b8ddfc2f |
109 | // |
7fd59977 |
110 | thegeom->D0(-Xmax,Ymax,loc); |
111 | p1 = loc.Translated(trans); |
b8ddfc2f |
112 | aPrims->AddVertex(loc); |
113 | aPrims->AddVertex(p1); |
4ad142d9 |
114 | Prs3d_Arrow::Draw (Prs3d_Root::CurrentGroup (aPresentation), p1, norm, ang, len); |
b8ddfc2f |
115 | // |
7fd59977 |
116 | thegeom->D0(Xmax,Ymax,loc); |
117 | p1 = loc.Translated(trans); |
b8ddfc2f |
118 | aPrims->AddVertex(loc); |
119 | aPrims->AddVertex(p1); |
4ad142d9 |
120 | Prs3d_Arrow::Draw (Prs3d_Root::CurrentGroup (aPresentation), p1, norm, ang, len); |
b8ddfc2f |
121 | // |
7fd59977 |
122 | thegeom->D0(Xmax,-Ymax,loc); |
123 | p1 = loc.Translated(trans); |
b8ddfc2f |
124 | aPrims->AddVertex(loc); |
125 | aPrims->AddVertex(p1); |
4ad142d9 |
126 | Prs3d_Arrow::Draw (Prs3d_Root::CurrentGroup (aPresentation), p1, norm, ang, len); |
b8ddfc2f |
127 | // |
128 | TheGroup->AddPrimitiveArray(aPrims); |
7fd59977 |
129 | } |
7fd59977 |
130 | } |
131 | |
132 | Standard_Boolean StdPrs_Plane::Match |
133 | (const Quantity_Length X, |
134 | const Quantity_Length Y, |
135 | const Quantity_Length Z, |
136 | const Quantity_Length aDistance, |
137 | const Adaptor3d_Surface& aPlane, |
138 | const Handle (Prs3d_Drawer)&) |
139 | { |
140 | if (aPlane.GetType() == GeomAbs_Plane) { |
141 | gp_Pln theplane = aPlane.Plane(); |
142 | gp_Pnt thepoint (X,Y,Z); |
143 | |
144 | return (Abs(theplane.Distance(thepoint)) <= aDistance); |
145 | } |
146 | else return Standard_False; |
147 | } |