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