0030537: Visualization - wrapping text in font text formatter
[occt.git] / src / StdPrs / StdPrs_Plane.cxx
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
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
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>
24 #include <Graphic3d_ArrayOfPolylines.hxx>
25 #include <Graphic3d_ArrayOfSegments.hxx>
26 #include <Graphic3d_Group.hxx>
27 #include <Prs3d.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>
34
35 void StdPrs_Plane::Add (const Handle (Prs3d_Presentation)& aPresentation,
36                         const Adaptor3d_Surface&           aPlane,
37                         const Handle (Prs3d_Drawer)&       aDrawer)
38 {
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());
43
44   Handle(Prs3d_PlaneAspect) theaspect = aDrawer->PlaneAspect();
45
46   gp_Pnt p1;
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);
60   }
61
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));
68     Standard_Integer i;
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));
73     }
74     cur = -Ymax+dist;
75     for (i = 0; i < nby; i++, cur += dist) {
76       aPrims->AddVertex(thegeom->Value( Xmax,cur));
77       aPrims->AddVertex(thegeom->Value(-Xmax,cur));
78     }
79     TheGroup->AddPrimitiveArray(aPrims);
80   }
81
82   gp_Dir norm = thegeom->Pln().Axis().Direction();
83   gp_Pnt loc;
84   Standard_Real siz = theaspect->ArrowsSize();
85   Standard_Real len = theaspect->ArrowsLength();
86   Standard_Real ang = theaspect->ArrowsAngle();
87   gp_Vec trans(norm);
88   trans.Scale(Standard_Real(siz));
89
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);
99   }
100   if (theaspect->DisplayEdgesArrows()) {
101     Handle(Graphic3d_ArrayOfSegments) aPrims = new Graphic3d_ArrayOfSegments(8);
102     //
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);
108     //
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);
114     //
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);
120     //
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);
126     //
127     TheGroup->AddPrimitiveArray(aPrims);
128   }
129 }
130
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)&)
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 }