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>
28 #include <Prs3d_Arrow.hxx>
29 #include <Prs3d_ArrowAspect.hxx>
30 #include <Prs3d_LineAspect.hxx>
31 #include <Prs3d_PlaneAspect.hxx>
32 #include <Prs3d_Presentation.hxx>
33 #include <StdPrs_Plane.hxx>
35 void StdPrs_Plane::Add (const Handle (Prs3d_Presentation)& aPresentation,
36 const Adaptor3d_Surface& aPlane,
37 const Handle (Prs3d_Drawer)& aDrawer)
39 // aPresentation->NewGroup();
40 Handle(Graphic3d_Group) TheGroup = aPresentation->CurrentGroup();
41 if (aPlane.GetType() != GeomAbs_Plane) return;
42 Handle(Geom_Plane) thegeom = new Geom_Plane(aPlane.Plane());
44 Handle(Prs3d_PlaneAspect) theaspect = aDrawer->PlaneAspect();
47 Standard_Real Xmax,Ymax;
48 Xmax = 0.5*Standard_Real(theaspect->PlaneXLength());
49 Ymax = 0.5*Standard_Real(theaspect->PlaneYLength());
50 if (theaspect->DisplayEdges()) {
51 TheGroup->SetPrimitivesAspect(theaspect->EdgesAspect()->Aspect());
52 Handle(Graphic3d_ArrayOfPolylines) aPrims = new Graphic3d_ArrayOfPolylines(5);
53 p1 = thegeom->Value(-Xmax,Ymax);
54 aPrims->AddVertex(p1);
55 aPrims->AddVertex(thegeom->Value( Xmax, Ymax));
56 aPrims->AddVertex(thegeom->Value( Xmax,-Ymax));
57 aPrims->AddVertex(thegeom->Value(-Xmax,-Ymax));
58 aPrims->AddVertex(p1);
59 TheGroup->AddPrimitiveArray(aPrims);
62 if (theaspect->DisplayIso()) {
63 TheGroup->SetPrimitivesAspect(theaspect->IsoAspect()->Aspect());
64 const Standard_Real dist = theaspect->IsoDistance();
65 const Standard_Integer nbx = Standard_Integer(Abs(2.*Xmax) / dist) - 1;
66 const Standard_Integer nby = Standard_Integer(Abs(2.*Ymax) / dist) - 1;
67 Handle(Graphic3d_ArrayOfSegments) aPrims = new Graphic3d_ArrayOfSegments(2*(nbx+nby));
69 Standard_Real cur = -Xmax+dist;
70 for (i = 0; i < nbx; i++, cur += dist) {
71 aPrims->AddVertex(thegeom->Value(cur, Ymax));
72 aPrims->AddVertex(thegeom->Value(cur,-Ymax));
75 for (i = 0; i < nby; i++, cur += dist) {
76 aPrims->AddVertex(thegeom->Value( Xmax,cur));
77 aPrims->AddVertex(thegeom->Value(-Xmax,cur));
79 TheGroup->AddPrimitiveArray(aPrims);
82 gp_Dir norm = thegeom->Pln().Axis().Direction();
84 Standard_Real siz = theaspect->ArrowsSize();
85 Standard_Real len = theaspect->ArrowsLength();
86 Standard_Real ang = theaspect->ArrowsAngle();
88 trans.Scale(Standard_Real(siz));
90 TheGroup->SetPrimitivesAspect(theaspect->ArrowAspect()->Aspect());
91 if (theaspect->DisplayCenterArrow()) {
92 loc = thegeom->Location();
93 p1 = loc.Translated(trans);
94 Handle(Graphic3d_ArrayOfSegments) aPrims = new Graphic3d_ArrayOfSegments(2);
95 aPrims->AddVertex(loc);
96 aPrims->AddVertex(p1);
97 TheGroup->AddPrimitiveArray(aPrims);
98 Prs3d_Arrow::Draw (aPresentation->CurrentGroup(), p1, norm, ang, len);
100 if (theaspect->DisplayEdgesArrows()) {
101 Handle(Graphic3d_ArrayOfSegments) aPrims = new Graphic3d_ArrayOfSegments(8);
103 thegeom->D0(-Xmax,-Ymax,loc);
104 p1 = loc.Translated(trans);
105 aPrims->AddVertex(loc);
106 aPrims->AddVertex(p1);
107 Prs3d_Arrow::Draw (aPresentation->CurrentGroup(), p1, norm, ang, len);
109 thegeom->D0(-Xmax,Ymax,loc);
110 p1 = loc.Translated(trans);
111 aPrims->AddVertex(loc);
112 aPrims->AddVertex(p1);
113 Prs3d_Arrow::Draw (aPresentation->CurrentGroup(), p1, norm, ang, len);
115 thegeom->D0(Xmax,Ymax,loc);
116 p1 = loc.Translated(trans);
117 aPrims->AddVertex(loc);
118 aPrims->AddVertex(p1);
119 Prs3d_Arrow::Draw (aPresentation->CurrentGroup(), p1, norm, ang, len);
121 thegeom->D0(Xmax,-Ymax,loc);
122 p1 = loc.Translated(trans);
123 aPrims->AddVertex(loc);
124 aPrims->AddVertex(p1);
125 Prs3d_Arrow::Draw (aPresentation->CurrentGroup(), p1, norm, ang, len);
127 TheGroup->AddPrimitiveArray(aPrims);
131 Standard_Boolean StdPrs_Plane::Match
132 (const Standard_Real X,
133 const Standard_Real Y,
134 const Standard_Real Z,
135 const Standard_Real aDistance,
136 const Adaptor3d_Surface& aPlane,
137 const Handle (Prs3d_Drawer)&)
139 if (aPlane.GetType() == GeomAbs_Plane) {
140 gp_Pln theplane = aPlane.Plane();
141 gp_Pnt thepoint (X,Y,Z);
143 return (Abs(theplane.Distance(thepoint)) <= aDistance);
145 else return Standard_False;