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