1 // Created on: 1995-07-24
2 // Created by: Modelistation
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
18 #include <Adaptor3d_Surface.hxx>
19 #include <Geom_Plane.hxx>
24 #include <Graphic3d_ArrayOfPolylines.hxx>
25 #include <Graphic3d_ArrayOfSegments.hxx>
26 #include <Graphic3d_Group.hxx>
27 #include <Graphic3d_Vertex.hxx>
29 #include <Prs3d_Arrow.hxx>
30 #include <Prs3d_ArrowAspect.hxx>
31 #include <Prs3d_LineAspect.hxx>
32 #include <Prs3d_PlaneAspect.hxx>
33 #include <Prs3d_Presentation.hxx>
34 #include <StdPrs_Plane.hxx>
36 void StdPrs_Plane::Add (const Handle (Prs3d_Presentation)& aPresentation,
37 const Adaptor3d_Surface& aPlane,
38 const Handle (Prs3d_Drawer)& aDrawer)
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());
45 Handle(Prs3d_PlaneAspect) theaspect = aDrawer->PlaneAspect();
48 Standard_Real Xmax,Ymax;
49 Xmax = 0.5*Standard_Real(theaspect->PlaneXLength());
50 Ymax = 0.5*Standard_Real(theaspect->PlaneYLength());
51 if (theaspect->DisplayEdges()) {
52 TheGroup->SetPrimitivesAspect(theaspect->EdgesAspect()->Aspect());
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);
63 if (theaspect->DisplayIso()) {
64 TheGroup->SetPrimitivesAspect(theaspect->IsoAspect()->Aspect());
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));
70 Standard_Real cur = -Xmax+dist;
71 for (i = 0; i < nbx; i++, cur += dist) {
72 aPrims->AddVertex(thegeom->Value(cur, Ymax));
73 aPrims->AddVertex(thegeom->Value(cur,-Ymax));
76 for (i = 0; i < nby; i++, cur += dist) {
77 aPrims->AddVertex(thegeom->Value( Xmax,cur));
78 aPrims->AddVertex(thegeom->Value(-Xmax,cur));
80 TheGroup->AddPrimitiveArray(aPrims);
83 gp_Dir norm = thegeom->Pln().Axis().Direction();
85 Standard_Real siz = theaspect->ArrowsSize();
86 Standard_Real len = theaspect->ArrowsLength();
87 Standard_Real ang = theaspect->ArrowsAngle();
89 trans.Scale(Standard_Real(siz));
91 TheGroup->SetPrimitivesAspect(theaspect->ArrowAspect()->Aspect());
92 if (theaspect->DisplayCenterArrow()) {
93 loc = thegeom->Location();
94 p1 = loc.Translated(trans);
95 Handle(Graphic3d_ArrayOfSegments) aPrims = new Graphic3d_ArrayOfSegments(2);
96 aPrims->AddVertex(loc);
97 aPrims->AddVertex(p1);
98 TheGroup->AddPrimitiveArray(aPrims);
99 Prs3d_Arrow::Draw (Prs3d_Root::CurrentGroup (aPresentation), p1, norm, ang, len);
101 if (theaspect->DisplayEdgesArrows()) {
102 Handle(Graphic3d_ArrayOfSegments) aPrims = new Graphic3d_ArrayOfSegments(8);
104 thegeom->D0(-Xmax,-Ymax,loc);
105 p1 = loc.Translated(trans);
106 aPrims->AddVertex(loc);
107 aPrims->AddVertex(p1);
108 Prs3d_Arrow::Draw (Prs3d_Root::CurrentGroup (aPresentation), p1, norm, ang, len);
110 thegeom->D0(-Xmax,Ymax,loc);
111 p1 = loc.Translated(trans);
112 aPrims->AddVertex(loc);
113 aPrims->AddVertex(p1);
114 Prs3d_Arrow::Draw (Prs3d_Root::CurrentGroup (aPresentation), p1, norm, ang, len);
116 thegeom->D0(Xmax,Ymax,loc);
117 p1 = loc.Translated(trans);
118 aPrims->AddVertex(loc);
119 aPrims->AddVertex(p1);
120 Prs3d_Arrow::Draw (Prs3d_Root::CurrentGroup (aPresentation), p1, norm, ang, len);
122 thegeom->D0(Xmax,-Ymax,loc);
123 p1 = loc.Translated(trans);
124 aPrims->AddVertex(loc);
125 aPrims->AddVertex(p1);
126 Prs3d_Arrow::Draw (Prs3d_Root::CurrentGroup (aPresentation), p1, norm, ang, len);
128 TheGroup->AddPrimitiveArray(aPrims);
132 Standard_Boolean StdPrs_Plane::Match
133 (const Standard_Real X,
134 const Standard_Real Y,
135 const Standard_Real Z,
136 const Standard_Real aDistance,
137 const Adaptor3d_Surface& aPlane,
138 const Handle (Prs3d_Drawer)&)
140 if (aPlane.GetType() == GeomAbs_Plane) {
141 gp_Pln theplane = aPlane.Plane();
142 gp_Pnt thepoint (X,Y,Z);
144 return (Abs(theplane.Distance(thepoint)) <= aDistance);
146 else return Standard_False;