973c2be1 |
1 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
2 | // |
973c2be1 |
3 | // This file is part of Open CASCADE Technology software library. |
b311480e |
4 | // |
d5f74e42 |
5 | // This library is free software; you can redistribute it and/or modify it under |
6 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
7 | // by the Free Software Foundation, with special exception defined in the file |
8 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
9 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
10 | // |
973c2be1 |
11 | // Alternatively, this file may be used under the terms of Open CASCADE |
12 | // commercial license or contractual agreement. |
b311480e |
13 | |
7fd59977 |
14 | #include <IGESConvGeom_GeomBuilder.ixx> |
15 | #include <TColStd_HArray1OfReal.hxx> |
16 | #include <TColStd_HArray2OfReal.hxx> |
17 | #include <Interface_Translates.hxx> |
18 | #include <Standard_DomainError.hxx> |
19 | #include <gp.hxx> |
20 | |
21 | |
22 | static Standard_Real epsl = 1.E-10; |
23 | static Standard_Real epsa = 1.E-10; |
24 | |
25 | IGESConvGeom_GeomBuilder::IGESConvGeom_GeomBuilder () |
26 | { Clear(); } |
27 | |
28 | |
29 | void IGESConvGeom_GeomBuilder::Clear () |
30 | { |
31 | theXYZ = new TColgp_HSequenceOfXYZ(); |
32 | theVec = new TColgp_HSequenceOfXYZ(); |
33 | gp_Trsf trid; thepos = trid; |
34 | } |
35 | |
36 | void IGESConvGeom_GeomBuilder::AddXY (const gp_XY& val) |
37 | { |
38 | gp_XYZ aval (val.X(),val.Y(),0.); |
39 | theXYZ->Append (aval); |
40 | aval.SetCoord (0.,0.,0.); |
41 | theVec->Append (aval); |
42 | } |
43 | |
44 | void IGESConvGeom_GeomBuilder::AddXYZ (const gp_XYZ& val) |
45 | { |
46 | theXYZ->Append (val); |
47 | theVec->Append (gp_XYZ(0.,0.,0.) ); |
48 | } |
49 | |
50 | void IGESConvGeom_GeomBuilder::AddVec (const gp_XYZ& val) |
51 | { |
52 | if (!theVec->IsEmpty()) theVec->SetValue (theVec->Length(), val); |
53 | } |
54 | |
55 | Standard_Integer IGESConvGeom_GeomBuilder::NbPoints () const |
56 | { return theXYZ->Length(); } |
57 | |
58 | gp_XYZ IGESConvGeom_GeomBuilder::Point (const Standard_Integer num) const |
59 | { return theXYZ->Value (num); } |
60 | |
61 | Handle(IGESGeom_CopiousData) IGESConvGeom_GeomBuilder::MakeCopiousData |
62 | (const Standard_Integer datatype, const Standard_Boolean polyline) const |
63 | { |
64 | Standard_Integer num, nb = theXYZ->Length(); |
65 | if (datatype < 1 || datatype > 3 || nb == 0 || (polyline && datatype == 3)) |
66 | Standard_DomainError::Raise ("IGESConvGeom_GeomBuilder : MakeCopiousData"); |
67 | |
68 | Standard_Integer nbd = datatype+1; // 1->2 2->3 et 3->6 |
69 | if (datatype == 3) nbd = 6; |
70 | Handle(TColStd_HArray1OfReal) data = new TColStd_HArray1OfReal (1,nb*nbd); |
71 | Standard_Real CZ = 0.; |
72 | for (num = 1; num <= nb; num ++) { |
73 | const gp_XYZ& pnt = theXYZ->Value(num); |
74 | data->SetValue ((num-1)*nbd+1 , pnt.X()); |
75 | data->SetValue ((num-1)*nbd+2 , pnt.Y()); |
76 | if (datatype > 1) data->SetValue ((num-1)*nbd+3 , pnt.Z()); |
77 | else CZ += pnt.Z(); |
78 | if (datatype < 3) continue; |
79 | const gp_XYZ& vec = theVec->Value(num); |
80 | data->SetValue ((num-1)*nbd+4 , vec.X()); |
81 | data->SetValue ((num-1)*nbd+5 , vec.Y()); |
82 | data->SetValue ((num-1)*nbd+6 , vec.Z()); |
83 | } |
84 | if (datatype == 1) CZ /= nb; |
85 | |
86 | Handle(IGESGeom_CopiousData) res = new IGESGeom_CopiousData; |
87 | res->Init (datatype,CZ,data); |
88 | res->SetPolyline (polyline); |
89 | return res; |
90 | } |
91 | |
92 | Handle(TColgp_HArray1OfXY) IGESConvGeom_GeomBuilder::MakeXY () const |
93 | { |
94 | Handle(TColgp_HArray1OfXY) res; |
95 | Standard_Integer num, nb = theXYZ->Length(); |
96 | if (nb == 0) return res; |
97 | res = new TColgp_HArray1OfXY (1,nb); |
98 | for (num = 1; num <= nb; num ++) { |
99 | const gp_XYZ& pnt = theXYZ->Value(num); |
100 | res->SetValue (num , gp_XY (pnt.X(),pnt.Y()) ); |
101 | } |
102 | return res; |
103 | } |
104 | |
105 | Handle(TColgp_HArray1OfXYZ) IGESConvGeom_GeomBuilder::MakeXYZ () const |
106 | { |
107 | Handle(TColgp_HArray1OfXYZ) res; |
108 | /* |
109 | Standard_Integer num, nb = theXYZ->Length(); |
110 | if (nb == 0) return res; |
111 | res = new TColgp_HArray1OfXYZ (1,nb); |
112 | for (num = 1; num <= nb; num ++) { |
113 | res->SetValue (num , theXYZ->Value(num) ); |
114 | } |
115 | */ |
116 | SeqToArray(theXYZ,res,TColgp_HArray1OfXYZ); |
117 | return res; |
118 | } |
119 | |
120 | |
121 | gp_Trsf IGESConvGeom_GeomBuilder::Position () const |
122 | { return thepos; } |
123 | |
124 | void IGESConvGeom_GeomBuilder::SetPosition (const gp_Trsf& pos) |
125 | { thepos = pos; } |
126 | |
127 | void IGESConvGeom_GeomBuilder::SetPosition (const gp_Ax3& pos) |
128 | { |
129 | gp_Ax3 orig (gp::XOY()); |
130 | gp_Trsf ps; |
131 | ps.SetTransformation (pos,orig); |
132 | thepos = ps; |
133 | } |
134 | |
135 | void IGESConvGeom_GeomBuilder::SetPosition (const gp_Ax2& pos) |
136 | { |
137 | gp_Ax3 a3(pos); |
138 | SetPosition (a3); |
139 | } |
140 | |
141 | void IGESConvGeom_GeomBuilder::SetPosition (const gp_Ax1& pos) |
142 | { |
143 | const gp_Pnt& p = pos.Location(); |
144 | const gp_Dir& d = pos.Direction(); |
145 | gp_Ax3 a3 (p,d); |
146 | SetPosition (a3); |
147 | } |
148 | |
149 | Standard_Boolean IGESConvGeom_GeomBuilder::IsIdentity () const |
150 | { |
151 | if (thepos.Form() == gp_Identity) return Standard_True; |
152 | // sinon, regarder de plus pres ... |
153 | if (!IsTranslation()) return Standard_False; |
154 | if (!thepos.TranslationPart().IsEqual (gp_XYZ(0.,0.,0.),epsl) ) |
155 | return Standard_False; |
156 | return Standard_True; |
157 | } |
158 | |
159 | Standard_Boolean IGESConvGeom_GeomBuilder::IsTranslation () const |
160 | { |
161 | if (thepos.Form() == gp_Identity || thepos.Form() == gp_Translation) |
162 | return Standard_True; |
163 | // sinon, regarder de plus pres ... |
164 | |
165 | Standard_Integer i,j; |
166 | for (i = 1; i <= 3; i ++) |
167 | for (j = 1; j <= 3; j ++) { |
168 | Standard_Real cons = (i == j ? 1. : 0.); |
169 | Standard_Real val = thepos.Value(i,j); |
170 | if (val > cons + epsa || val < cons - epsa) return Standard_False; |
171 | } |
172 | return Standard_True; |
173 | } |
174 | |
175 | Standard_Boolean IGESConvGeom_GeomBuilder::IsZOnly () const |
176 | { |
177 | if (!IsTranslation()) return Standard_False; |
178 | gp_XYZ t = thepos.TranslationPart(); t.SetZ (0.0); |
179 | if (!t.IsEqual (gp_XYZ(0.,0.,0.),epsl) ) return Standard_False; |
180 | return Standard_True; |
181 | } |
182 | |
183 | void IGESConvGeom_GeomBuilder::EvalXYZ |
184 | (const gp_XYZ& val, |
185 | Standard_Real& X, Standard_Real& Y, Standard_Real& Z) const |
186 | { |
187 | val.Coord (X,Y,Z); |
188 | thepos.Inverted().Transforms (X,Y,Z); |
189 | } |
190 | |
191 | Handle(IGESGeom_TransformationMatrix) |
192 | IGESConvGeom_GeomBuilder::MakeTransformation (const Standard_Real unit) const |
193 | { |
194 | Handle(TColStd_HArray2OfReal) data = new TColStd_HArray2OfReal (1,3,1,4); |
195 | Standard_Integer i,j; |
196 | for (i = 1; i <= 3; i ++) |
197 | for (j = 1; j <= 4; j ++) |
198 | data->SetValue (i,j, (j == 4 ? thepos.Value(i,j)/unit : thepos.Value(i,j)) ); |
199 | Handle(IGESGeom_TransformationMatrix) rs = new IGESGeom_TransformationMatrix; |
200 | rs->Init (data); |
201 | if (thepos.IsNegative()) rs->SetFormNumber(1); |
202 | return rs; |
203 | } |