b311480e |
1 | // Created on: 1997-01-03 |
2 | // Created by: Flore Lantheaume |
3 | // Copyright (c) 1997-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. |
7fd59977 |
16 | |
7fd59977 |
17 | |
42cf5bc1 |
18 | #include <DsgPrs_IdenticPresentation.hxx> |
19 | #include <ElCLib.hxx> |
20 | #include <gp_Ax2.hxx> |
21 | #include <gp_Dir.hxx> |
22 | #include <gp_Elips.hxx> |
23 | #include <gp_Pnt.hxx> |
24 | #include <gp_Vec.hxx> |
25 | #include <Graphic3d_ArrayOfPoints.hxx> |
b8ddfc2f |
26 | #include <Graphic3d_ArrayOfPolylines.hxx> |
42cf5bc1 |
27 | #include <Graphic3d_ArrayOfSegments.hxx> |
7fd59977 |
28 | #include <Graphic3d_AspectLine3d.hxx> |
42cf5bc1 |
29 | #include <Graphic3d_AspectMarker3d.hxx> |
30 | #include <Graphic3d_Group.hxx> |
31 | #include <Precision.hxx> |
a6eb515f |
32 | #include <Prs3d_DimensionAspect.hxx> |
42cf5bc1 |
33 | #include <Prs3d_LineAspect.hxx> |
34 | #include <Prs3d_Presentation.hxx> |
7fd59977 |
35 | #include <Prs3d_Text.hxx> |
7fd59977 |
36 | #include <TCollection_AsciiString.hxx> |
42cf5bc1 |
37 | #include <TCollection_ExtendedString.hxx> |
7fd59977 |
38 | |
39 | void DsgPrs_IdenticPresentation::Add( const Handle(Prs3d_Presentation)& aPresentation, |
40 | const Handle(Prs3d_Drawer)& aDrawer, |
41 | const TCollection_ExtendedString& aText, |
42 | const gp_Pnt& aPntAttach, |
43 | const gp_Pnt& aPntOffset) |
44 | { |
a6eb515f |
45 | Handle(Prs3d_DimensionAspect) LA = aDrawer->DimensionAspect(); |
7fd59977 |
46 | Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect()); |
47 | |
b8ddfc2f |
48 | Handle(Graphic3d_ArrayOfSegments) aPrims = new Graphic3d_ArrayOfSegments(2); |
49 | aPrims->AddVertex(aPntAttach); |
50 | aPrims->AddVertex(aPntOffset); |
51 | Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(aPrims); |
7fd59977 |
52 | |
7fd59977 |
53 | Prs3d_Root::NewGroup(aPresentation); |
54 | Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect()); |
b6472664 |
55 | Quantity_Color aColor = LA->LineAspect()->Aspect()->Color(); |
a577aaab |
56 | Handle(Graphic3d_AspectMarker3d) aMarkerAsp = new Graphic3d_AspectMarker3d (Aspect_TOM_O, aColor, 1.0); |
57 | Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect (aMarkerAsp); |
58 | Handle(Graphic3d_ArrayOfPoints) anArrayOfPoints = new Graphic3d_ArrayOfPoints (1); |
59 | anArrayOfPoints->AddVertex (aPntAttach.X(), aPntAttach.Y(), aPntAttach.Z()); |
60 | Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray (anArrayOfPoints); |
7fd59977 |
61 | |
62 | // texte |
4ad142d9 |
63 | Prs3d_Text::Draw (Prs3d_Root::CurrentGroup (aPresentation), LA->TextAspect(), aText, aPntOffset); |
7fd59977 |
64 | } |
65 | |
66 | |
7fd59977 |
67 | void DsgPrs_IdenticPresentation::Add( const Handle(Prs3d_Presentation)& aPresentation, |
68 | const Handle(Prs3d_Drawer)& aDrawer, |
69 | const TCollection_ExtendedString& aText, |
70 | const gp_Pnt& aFAttach, |
71 | const gp_Pnt& aSAttach, |
72 | const gp_Pnt& aPntOffset) |
73 | { |
a6eb515f |
74 | Handle(Prs3d_DimensionAspect) LA = aDrawer->DimensionAspect(); |
7fd59977 |
75 | Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect()); |
76 | |
b8ddfc2f |
77 | Handle(Graphic3d_ArrayOfSegments) aPrims = new Graphic3d_ArrayOfSegments(4); |
7fd59977 |
78 | |
b8ddfc2f |
79 | aPrims->AddVertex(aFAttach); |
80 | aPrims->AddVertex(aSAttach); |
7fd59977 |
81 | |
82 | // trait joignant aPntOffset |
7fd59977 |
83 | gp_Vec v1(aFAttach, aSAttach); |
84 | gp_Vec v2(aSAttach, aPntOffset); |
b8ddfc2f |
85 | |
86 | aPrims->AddVertex(aPntOffset); |
87 | if ( !v1.IsParallel(v2, Precision::Angular())) |
88 | { |
7fd59977 |
89 | // on joint aPntOffset a son projete |
90 | gp_Lin ll(aFAttach, gp_Dir(v1)); |
b8ddfc2f |
91 | aPrims->AddVertex(ElCLib::Value(ElCLib::Parameter(ll,aPntOffset ), ll)); |
7fd59977 |
92 | } |
b8ddfc2f |
93 | else |
94 | aPrims->AddVertex(aSAttach); |
95 | |
96 | Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(aPrims); |
7fd59977 |
97 | |
98 | // texte |
4ad142d9 |
99 | Prs3d_Text::Draw (Prs3d_Root::CurrentGroup (aPresentation), LA->TextAspect(), aText, aPntOffset); |
7fd59977 |
100 | } |
101 | |
102 | |
7fd59977 |
103 | void DsgPrs_IdenticPresentation::Add(const Handle(Prs3d_Presentation)& aPresentation, |
104 | const Handle(Prs3d_Drawer)& aDrawer, |
105 | const TCollection_ExtendedString& aText, |
106 | const gp_Ax2& theAxe, |
107 | const gp_Pnt& aCenter, |
108 | const gp_Pnt& aFAttach, |
109 | const gp_Pnt& aSAttach, |
110 | const gp_Pnt& aPntOffset) |
111 | { |
a6eb515f |
112 | Handle(Prs3d_DimensionAspect) LA = aDrawer->DimensionAspect(); |
7fd59977 |
113 | Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect()); |
114 | |
115 | gp_Ax2 ax = theAxe; |
116 | ax.SetLocation(aCenter); |
117 | Standard_Real rad = aCenter.Distance(aFAttach); |
118 | gp_Circ CC(ax,rad ); |
119 | Standard_Real pFAttach = ElCLib::Parameter(CC, aFAttach); |
120 | Standard_Real pSAttach = ElCLib::Parameter(CC, aSAttach); |
121 | Standard_Real alpha = pSAttach - pFAttach; |
b8ddfc2f |
122 | if ( alpha < 0 ) alpha += 2. * M_PI; |
123 | const Standard_Integer nb = (Standard_Integer )( 50. * alpha / M_PI); |
124 | const Standard_Integer nbp = Max (4, nb); |
125 | const Standard_Real dteta = alpha/(nbp-1); |
7fd59977 |
126 | |
b8ddfc2f |
127 | Handle(Graphic3d_ArrayOfPolylines) aPrims; |
7fd59977 |
128 | |
129 | // trait joignant aPntOffset |
b8ddfc2f |
130 | if ( Abs((aPntOffset.Distance(aCenter) - rad )) >= Precision::Confusion() ) |
131 | { |
132 | aPrims = new Graphic3d_ArrayOfPolylines(nbp+2,2); |
133 | aPrims->AddBound(2); |
134 | aPrims->AddVertex(aPntOffset); |
135 | aPrims->AddVertex(ElCLib::Value(ElCLib::Parameter(CC,aPntOffset ), CC)); |
136 | aPrims->AddBound(nbp); |
7fd59977 |
137 | } |
b8ddfc2f |
138 | else |
139 | aPrims = new Graphic3d_ArrayOfPolylines(nbp); |
140 | |
141 | for (Standard_Integer i = 1; i<=nbp; i++) |
142 | aPrims->AddVertex(ElCLib::Value(pFAttach + dteta*(i-1),CC)); |
143 | |
144 | Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(aPrims); |
7fd59977 |
145 | |
146 | // texte |
4ad142d9 |
147 | Prs3d_Text::Draw (Prs3d_Root::CurrentGroup (aPresentation), LA->TextAspect(), aText, aPntOffset); |
7fd59977 |
148 | } |
149 | |
150 | // jfa 16/10/2000 |
151 | void DsgPrs_IdenticPresentation::Add(const Handle(Prs3d_Presentation)& aPresentation, |
152 | const Handle(Prs3d_Drawer)& aDrawer, |
153 | const TCollection_ExtendedString& aText, |
154 | const gp_Ax2& theAxe, |
155 | const gp_Pnt& aCenter, |
156 | const gp_Pnt& aFAttach, |
157 | const gp_Pnt& aSAttach, |
158 | const gp_Pnt& aPntOffset, |
159 | const gp_Pnt& aPntOnCirc) |
160 | { |
a6eb515f |
161 | Handle(Prs3d_DimensionAspect) LA = aDrawer->DimensionAspect(); |
7fd59977 |
162 | Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect()); |
163 | |
164 | gp_Ax2 ax = theAxe; |
165 | ax.SetLocation(aCenter); |
166 | Standard_Real rad = aCenter.Distance(aFAttach); |
167 | gp_Circ CC(ax,rad ); |
b8ddfc2f |
168 | Standard_Real pFAttach = ElCLib::Parameter(CC, aFAttach); |
169 | Standard_Real pSAttach = ElCLib::Parameter(CC, aSAttach); |
7fd59977 |
170 | Standard_Real alpha = pSAttach - pFAttach; |
b8ddfc2f |
171 | if ( alpha < 0 ) alpha += 2. * M_PI; |
172 | const Standard_Integer nb = (Standard_Integer)( 50. * alpha / M_PI); |
173 | const Standard_Integer nbp = Max (4, nb); |
174 | const Standard_Real dteta = alpha/(nbp-1); |
175 | |
176 | Handle(Graphic3d_ArrayOfPolylines) aPrims; |
7fd59977 |
177 | |
7fd59977 |
178 | // trait joignant aPntOffset |
7fd59977 |
179 | if ( aPntOffset.Distance(aPntOnCirc) >= Precision::Confusion() ) |
b8ddfc2f |
180 | { |
181 | aPrims = new Graphic3d_ArrayOfPolylines(nbp+2,2); |
182 | aPrims->AddBound(2); |
183 | aPrims->AddVertex(aPntOffset); |
184 | aPrims->AddVertex(aPntOnCirc); |
185 | aPrims->AddBound(nbp); |
186 | } |
187 | else |
188 | aPrims = new Graphic3d_ArrayOfPolylines(nbp); |
189 | |
190 | for (Standard_Integer i = 1; i<=nbp; i++) |
191 | aPrims->AddVertex(ElCLib::Value(pFAttach + dteta*(i-1),CC)); |
192 | |
193 | Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(aPrims); |
7fd59977 |
194 | |
195 | // texte |
4ad142d9 |
196 | Prs3d_Text::Draw (Prs3d_Root::CurrentGroup (aPresentation), LA->TextAspect(), aText, aPntOffset); |
7fd59977 |
197 | } |
198 | // jfa 16/10/2000 end |
199 | |
200 | // jfa 10/10/2000 |
201 | void DsgPrs_IdenticPresentation::Add(const Handle(Prs3d_Presentation)& aPresentation, |
202 | const Handle(Prs3d_Drawer)& aDrawer, |
203 | const TCollection_ExtendedString& aText, |
204 | const gp_Elips& anEllipse, |
205 | const gp_Pnt& aFAttach, |
206 | const gp_Pnt& aSAttach, |
207 | const gp_Pnt& aPntOffset, |
208 | const gp_Pnt& aPntOnElli) |
209 | { |
a6eb515f |
210 | Handle(Prs3d_DimensionAspect) LA = aDrawer->DimensionAspect(); |
7fd59977 |
211 | Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect()); |
212 | |
213 | Standard_Real pFAttach = ElCLib::Parameter(anEllipse, aFAttach); |
214 | Standard_Real pSAttach = ElCLib::Parameter(anEllipse, aSAttach); |
215 | Standard_Real alpha = pSAttach - pFAttach; |
b8ddfc2f |
216 | if ( alpha < 0 ) alpha += 2. * M_PI; |
217 | const Standard_Integer nb = (Standard_Integer)(50.0*alpha/M_PI); |
218 | const Standard_Integer nbp = Max (4, nb); |
219 | const Standard_Real dteta = alpha/(nbp-1); |
7fd59977 |
220 | |
b8ddfc2f |
221 | Handle(Graphic3d_ArrayOfPolylines) aPrims; |
7fd59977 |
222 | |
223 | // trait joignant aPntOffset |
7fd59977 |
224 | if ( ! aPntOnElli.IsEqual(aPntOffset, Precision::Confusion()) ) |
b8ddfc2f |
225 | { |
226 | aPrims = new Graphic3d_ArrayOfPolylines(nbp+2,2); |
227 | aPrims->AddBound(2); |
228 | aPrims->AddVertex(aPntOffset); |
229 | aPrims->AddVertex(aPntOnElli); |
230 | aPrims->AddBound(nbp); |
231 | } |
232 | else |
233 | aPrims = new Graphic3d_ArrayOfPolylines(nbp); |
234 | |
235 | for (Standard_Integer i = 1; i<=nbp; i++) |
236 | aPrims->AddVertex(ElCLib::Value(pFAttach + dteta*(i-1),anEllipse)); |
237 | |
238 | Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(aPrims); |
7fd59977 |
239 | |
240 | // texte |
4ad142d9 |
241 | Prs3d_Text::Draw (Prs3d_Root::CurrentGroup (aPresentation), LA->TextAspect(), aText, aPntOffset); |
7fd59977 |
242 | } |
243 | // jfa 10/10/2000 end |