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