0023024: Update headers of OCCT files
[occt.git] / src / IGESConvGeom / IGESConvGeom_GeomBuilder.cxx
CommitLineData
b311480e 1// Copyright (c) 1999-2012 OPEN CASCADE SAS
2//
3// The content of this file is subject to the Open CASCADE Technology Public
4// License Version 6.5 (the "License"). You may not use the content of this file
5// except in compliance with the License. Please obtain a copy of the License
6// at http://www.opencascade.org and read it completely before using this file.
7//
8// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
9// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
10//
11// The Original Code and all software distributed under the License is
12// distributed on an "AS IS" basis, without warranty of any kind, and the
13// Initial Developer hereby disclaims all such warranties, including without
14// limitation, any warranties of merchantability, fitness for a particular
15// purpose or non-infringement. Please see the License for the specific terms
16// and conditions governing the rights and limitations under the License.
17
7fd59977 18#include <IGESConvGeom_GeomBuilder.ixx>
19#include <TColStd_HArray1OfReal.hxx>
20#include <TColStd_HArray2OfReal.hxx>
21#include <Interface_Translates.hxx>
22#include <Standard_DomainError.hxx>
23#include <gp.hxx>
24
25
26static Standard_Real epsl = 1.E-10;
27static Standard_Real epsa = 1.E-10;
28
29 IGESConvGeom_GeomBuilder::IGESConvGeom_GeomBuilder ()
30 { Clear(); }
31
32
33 void IGESConvGeom_GeomBuilder::Clear ()
34{
35 theXYZ = new TColgp_HSequenceOfXYZ();
36 theVec = new TColgp_HSequenceOfXYZ();
37 gp_Trsf trid; thepos = trid;
38}
39
40 void IGESConvGeom_GeomBuilder::AddXY (const gp_XY& val)
41{
42 gp_XYZ aval (val.X(),val.Y(),0.);
43 theXYZ->Append (aval);
44 aval.SetCoord (0.,0.,0.);
45 theVec->Append (aval);
46}
47
48 void IGESConvGeom_GeomBuilder::AddXYZ (const gp_XYZ& val)
49{
50 theXYZ->Append (val);
51 theVec->Append (gp_XYZ(0.,0.,0.) );
52}
53
54 void IGESConvGeom_GeomBuilder::AddVec (const gp_XYZ& val)
55{
56 if (!theVec->IsEmpty()) theVec->SetValue (theVec->Length(), val);
57}
58
59 Standard_Integer IGESConvGeom_GeomBuilder::NbPoints () const
60{ return theXYZ->Length(); }
61
62 gp_XYZ IGESConvGeom_GeomBuilder::Point (const Standard_Integer num) const
63{ return theXYZ->Value (num); }
64
65 Handle(IGESGeom_CopiousData) IGESConvGeom_GeomBuilder::MakeCopiousData
66 (const Standard_Integer datatype, const Standard_Boolean polyline) const
67{
68 Standard_Integer num, nb = theXYZ->Length();
69 if (datatype < 1 || datatype > 3 || nb == 0 || (polyline && datatype == 3))
70 Standard_DomainError::Raise ("IGESConvGeom_GeomBuilder : MakeCopiousData");
71
72 Standard_Integer nbd = datatype+1; // 1->2 2->3 et 3->6
73 if (datatype == 3) nbd = 6;
74 Handle(TColStd_HArray1OfReal) data = new TColStd_HArray1OfReal (1,nb*nbd);
75 Standard_Real CZ = 0.;
76 for (num = 1; num <= nb; num ++) {
77 const gp_XYZ& pnt = theXYZ->Value(num);
78 data->SetValue ((num-1)*nbd+1 , pnt.X());
79 data->SetValue ((num-1)*nbd+2 , pnt.Y());
80 if (datatype > 1) data->SetValue ((num-1)*nbd+3 , pnt.Z());
81 else CZ += pnt.Z();
82 if (datatype < 3) continue;
83 const gp_XYZ& vec = theVec->Value(num);
84 data->SetValue ((num-1)*nbd+4 , vec.X());
85 data->SetValue ((num-1)*nbd+5 , vec.Y());
86 data->SetValue ((num-1)*nbd+6 , vec.Z());
87 }
88 if (datatype == 1) CZ /= nb;
89
90 Handle(IGESGeom_CopiousData) res = new IGESGeom_CopiousData;
91 res->Init (datatype,CZ,data);
92 res->SetPolyline (polyline);
93 return res;
94}
95
96 Handle(TColgp_HArray1OfXY) IGESConvGeom_GeomBuilder::MakeXY () const
97{
98 Handle(TColgp_HArray1OfXY) res;
99 Standard_Integer num, nb = theXYZ->Length();
100 if (nb == 0) return res;
101 res = new TColgp_HArray1OfXY (1,nb);
102 for (num = 1; num <= nb; num ++) {
103 const gp_XYZ& pnt = theXYZ->Value(num);
104 res->SetValue (num , gp_XY (pnt.X(),pnt.Y()) );
105 }
106 return res;
107}
108
109 Handle(TColgp_HArray1OfXYZ) IGESConvGeom_GeomBuilder::MakeXYZ () const
110{
111 Handle(TColgp_HArray1OfXYZ) res;
112/*
113 Standard_Integer num, nb = theXYZ->Length();
114 if (nb == 0) return res;
115 res = new TColgp_HArray1OfXYZ (1,nb);
116 for (num = 1; num <= nb; num ++) {
117 res->SetValue (num , theXYZ->Value(num) );
118 }
119*/
120 SeqToArray(theXYZ,res,TColgp_HArray1OfXYZ);
121 return res;
122}
123
124
125 gp_Trsf IGESConvGeom_GeomBuilder::Position () const
126 { return thepos; }
127
128 void IGESConvGeom_GeomBuilder::SetPosition (const gp_Trsf& pos)
129 { thepos = pos; }
130
131 void IGESConvGeom_GeomBuilder::SetPosition (const gp_Ax3& pos)
132{
133 gp_Ax3 orig (gp::XOY());
134 gp_Trsf ps;
135 ps.SetTransformation (pos,orig);
136 thepos = ps;
137}
138
139 void IGESConvGeom_GeomBuilder::SetPosition (const gp_Ax2& pos)
140{
141 gp_Ax3 a3(pos);
142 SetPosition (a3);
143}
144
145 void IGESConvGeom_GeomBuilder::SetPosition (const gp_Ax1& pos)
146{
147 const gp_Pnt& p = pos.Location();
148 const gp_Dir& d = pos.Direction();
149 gp_Ax3 a3 (p,d);
150 SetPosition (a3);
151}
152
153 Standard_Boolean IGESConvGeom_GeomBuilder::IsIdentity () const
154{
155 if (thepos.Form() == gp_Identity) return Standard_True;
156// sinon, regarder de plus pres ...
157 if (!IsTranslation()) return Standard_False;
158 if (!thepos.TranslationPart().IsEqual (gp_XYZ(0.,0.,0.),epsl) )
159 return Standard_False;
160 return Standard_True;
161}
162
163 Standard_Boolean IGESConvGeom_GeomBuilder::IsTranslation () const
164{
165 if (thepos.Form() == gp_Identity || thepos.Form() == gp_Translation)
166 return Standard_True;
167// sinon, regarder de plus pres ...
168
169 Standard_Integer i,j;
170 for (i = 1; i <= 3; i ++)
171 for (j = 1; j <= 3; j ++) {
172 Standard_Real cons = (i == j ? 1. : 0.);
173 Standard_Real val = thepos.Value(i,j);
174 if (val > cons + epsa || val < cons - epsa) return Standard_False;
175 }
176 return Standard_True;
177}
178
179 Standard_Boolean IGESConvGeom_GeomBuilder::IsZOnly () const
180{
181 if (!IsTranslation()) return Standard_False;
182 gp_XYZ t = thepos.TranslationPart(); t.SetZ (0.0);
183 if (!t.IsEqual (gp_XYZ(0.,0.,0.),epsl) ) return Standard_False;
184 return Standard_True;
185}
186
187 void IGESConvGeom_GeomBuilder::EvalXYZ
188 (const gp_XYZ& val,
189 Standard_Real& X, Standard_Real& Y, Standard_Real& Z) const
190{
191 val.Coord (X,Y,Z);
192 thepos.Inverted().Transforms (X,Y,Z);
193}
194
195 Handle(IGESGeom_TransformationMatrix)
196 IGESConvGeom_GeomBuilder::MakeTransformation (const Standard_Real unit) const
197{
198 Handle(TColStd_HArray2OfReal) data = new TColStd_HArray2OfReal (1,3,1,4);
199 Standard_Integer i,j;
200 for (i = 1; i <= 3; i ++)
201 for (j = 1; j <= 4; j ++)
202 data->SetValue (i,j, (j == 4 ? thepos.Value(i,j)/unit : thepos.Value(i,j)) );
203 Handle(IGESGeom_TransformationMatrix) rs = new IGESGeom_TransformationMatrix;
204 rs->Init (data);
205 if (thepos.IsNegative()) rs->SetFormNumber(1);
206 return rs;
207}