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