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