1 // Copyright (c) 1999-2012 OPEN CASCADE SAS
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.
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.
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.
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>
26 static Standard_Real epsl = 1.E-10;
27 static Standard_Real epsa = 1.E-10;
29 IGESConvGeom_GeomBuilder::IGESConvGeom_GeomBuilder ()
33 void IGESConvGeom_GeomBuilder::Clear ()
35 theXYZ = new TColgp_HSequenceOfXYZ();
36 theVec = new TColgp_HSequenceOfXYZ();
37 gp_Trsf trid; thepos = trid;
40 void IGESConvGeom_GeomBuilder::AddXY (const gp_XY& val)
42 gp_XYZ aval (val.X(),val.Y(),0.);
43 theXYZ->Append (aval);
44 aval.SetCoord (0.,0.,0.);
45 theVec->Append (aval);
48 void IGESConvGeom_GeomBuilder::AddXYZ (const gp_XYZ& val)
51 theVec->Append (gp_XYZ(0.,0.,0.) );
54 void IGESConvGeom_GeomBuilder::AddVec (const gp_XYZ& val)
56 if (!theVec->IsEmpty()) theVec->SetValue (theVec->Length(), val);
59 Standard_Integer IGESConvGeom_GeomBuilder::NbPoints () const
60 { return theXYZ->Length(); }
62 gp_XYZ IGESConvGeom_GeomBuilder::Point (const Standard_Integer num) const
63 { return theXYZ->Value (num); }
65 Handle(IGESGeom_CopiousData) IGESConvGeom_GeomBuilder::MakeCopiousData
66 (const Standard_Integer datatype, const Standard_Boolean polyline) const
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");
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());
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());
88 if (datatype == 1) CZ /= nb;
90 Handle(IGESGeom_CopiousData) res = new IGESGeom_CopiousData;
91 res->Init (datatype,CZ,data);
92 res->SetPolyline (polyline);
96 Handle(TColgp_HArray1OfXY) IGESConvGeom_GeomBuilder::MakeXY () const
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()) );
109 Handle(TColgp_HArray1OfXYZ) IGESConvGeom_GeomBuilder::MakeXYZ () const
111 Handle(TColgp_HArray1OfXYZ) res;
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) );
120 SeqToArray(theXYZ,res,TColgp_HArray1OfXYZ);
125 gp_Trsf IGESConvGeom_GeomBuilder::Position () const
128 void IGESConvGeom_GeomBuilder::SetPosition (const gp_Trsf& pos)
131 void IGESConvGeom_GeomBuilder::SetPosition (const gp_Ax3& pos)
133 gp_Ax3 orig (gp::XOY());
135 ps.SetTransformation (pos,orig);
139 void IGESConvGeom_GeomBuilder::SetPosition (const gp_Ax2& pos)
145 void IGESConvGeom_GeomBuilder::SetPosition (const gp_Ax1& pos)
147 const gp_Pnt& p = pos.Location();
148 const gp_Dir& d = pos.Direction();
153 Standard_Boolean IGESConvGeom_GeomBuilder::IsIdentity () const
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;
163 Standard_Boolean IGESConvGeom_GeomBuilder::IsTranslation () const
165 if (thepos.Form() == gp_Identity || thepos.Form() == gp_Translation)
166 return Standard_True;
167 // sinon, regarder de plus pres ...
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;
176 return Standard_True;
179 Standard_Boolean IGESConvGeom_GeomBuilder::IsZOnly () const
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;
187 void IGESConvGeom_GeomBuilder::EvalXYZ
189 Standard_Real& X, Standard_Real& Y, Standard_Real& Z) const
192 thepos.Inverted().Transforms (X,Y,Z);
195 Handle(IGESGeom_TransformationMatrix)
196 IGESConvGeom_GeomBuilder::MakeTransformation (const Standard_Real unit) const
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;
205 if (thepos.IsNegative()) rs->SetFormNumber(1);