summaryrefslogtreecommitdiff
path: root/src/IGESConvGeom/IGESConvGeom_GeomBuilder.cxx
blob: 2e40cc9a8cac4456039a2299c556a884d8870e07 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#include <IGESConvGeom_GeomBuilder.ixx>
#include <TColStd_HArray1OfReal.hxx>
#include <TColStd_HArray2OfReal.hxx>
#include <Interface_Translates.hxx>
#include <Standard_DomainError.hxx>
#include <gp.hxx>


static Standard_Real epsl = 1.E-10;
static Standard_Real epsa = 1.E-10;

    IGESConvGeom_GeomBuilder::IGESConvGeom_GeomBuilder ()
      {  Clear();  }


    void  IGESConvGeom_GeomBuilder::Clear ()
{
  theXYZ = new TColgp_HSequenceOfXYZ();
  theVec = new TColgp_HSequenceOfXYZ();
  gp_Trsf trid;  thepos = trid;
}

    void  IGESConvGeom_GeomBuilder::AddXY  (const gp_XY&  val)
{
  gp_XYZ aval (val.X(),val.Y(),0.);
  theXYZ->Append (aval);
  aval.SetCoord (0.,0.,0.);
  theVec->Append (aval);
}

    void  IGESConvGeom_GeomBuilder::AddXYZ (const gp_XYZ& val)
{
  theXYZ->Append (val);
  theVec->Append (gp_XYZ(0.,0.,0.) );
}

    void  IGESConvGeom_GeomBuilder::AddVec (const gp_XYZ& val)
{
  if (!theVec->IsEmpty()) theVec->SetValue (theVec->Length(), val);
}

    Standard_Integer  IGESConvGeom_GeomBuilder::NbPoints () const
{  return theXYZ->Length();  }

    gp_XYZ  IGESConvGeom_GeomBuilder::Point (const Standard_Integer num) const
{  return theXYZ->Value (num);  }

    Handle(IGESGeom_CopiousData)  IGESConvGeom_GeomBuilder::MakeCopiousData
  (const Standard_Integer datatype, const Standard_Boolean polyline) const
{
  Standard_Integer num, nb = theXYZ->Length();
  if (datatype < 1 || datatype > 3 || nb == 0 || (polyline && datatype == 3))
    Standard_DomainError::Raise ("IGESConvGeom_GeomBuilder : MakeCopiousData");

  Standard_Integer nbd = datatype+1;  // 1->2  2->3   et   3->6
  if (datatype == 3) nbd = 6;
  Handle(TColStd_HArray1OfReal) data = new TColStd_HArray1OfReal (1,nb*nbd);
  Standard_Real CZ = 0.;
  for (num = 1; num <= nb; num ++) {
    const gp_XYZ& pnt = theXYZ->Value(num);
    data->SetValue ((num-1)*nbd+1 , pnt.X());
    data->SetValue ((num-1)*nbd+2 , pnt.Y());
    if (datatype > 1) data->SetValue ((num-1)*nbd+3 , pnt.Z());
    else CZ += pnt.Z();
    if (datatype < 3) continue;
    const gp_XYZ& vec = theVec->Value(num);
    data->SetValue ((num-1)*nbd+4 , vec.X());
    data->SetValue ((num-1)*nbd+5 , vec.Y());
    data->SetValue ((num-1)*nbd+6 , vec.Z());
  }
  if (datatype == 1) CZ /= nb;

  Handle(IGESGeom_CopiousData) res = new IGESGeom_CopiousData;
  res->Init (datatype,CZ,data);
  res->SetPolyline (polyline);
  return res;
}

    Handle(TColgp_HArray1OfXY)   IGESConvGeom_GeomBuilder::MakeXY  () const
{
  Handle(TColgp_HArray1OfXY) res;
  Standard_Integer num, nb = theXYZ->Length();
  if (nb == 0) return res;
  res = new TColgp_HArray1OfXY (1,nb);
  for (num = 1; num <= nb; num ++) {
    const gp_XYZ& pnt = theXYZ->Value(num);
    res->SetValue (num , gp_XY (pnt.X(),pnt.Y()) );
  }
  return res;
}

    Handle(TColgp_HArray1OfXYZ)  IGESConvGeom_GeomBuilder::MakeXYZ () const
{
  Handle(TColgp_HArray1OfXYZ) res;
/*
  Standard_Integer num, nb = theXYZ->Length();
  if (nb == 0) return res;
  res = new TColgp_HArray1OfXYZ (1,nb);
  for (num = 1; num <= nb; num ++) {
    res->SetValue (num , theXYZ->Value(num) );
  }
*/
  SeqToArray(theXYZ,res,TColgp_HArray1OfXYZ);
  return res;
}


    gp_Trsf  IGESConvGeom_GeomBuilder::Position () const
      {  return thepos;  }

    void  IGESConvGeom_GeomBuilder::SetPosition (const gp_Trsf& pos)
      {  thepos = pos;  }

    void  IGESConvGeom_GeomBuilder::SetPosition (const gp_Ax3&  pos)
{
  gp_Ax3 orig (gp::XOY());
  gp_Trsf ps;
  ps.SetTransformation (pos,orig);
  thepos = ps;
}

    void  IGESConvGeom_GeomBuilder::SetPosition (const gp_Ax2&  pos)
{
  gp_Ax3 a3(pos);
  SetPosition (a3);
}

    void  IGESConvGeom_GeomBuilder::SetPosition (const gp_Ax1&  pos)
{
  const gp_Pnt& p = pos.Location();
  const gp_Dir& d = pos.Direction();
  gp_Ax3 a3 (p,d);
  SetPosition (a3);
}

    Standard_Boolean  IGESConvGeom_GeomBuilder::IsIdentity () const
{
  if (thepos.Form() == gp_Identity) return Standard_True;
//   sinon, regarder de plus pres  ...
  if (!IsTranslation()) return Standard_False;
  if (!thepos.TranslationPart().IsEqual (gp_XYZ(0.,0.,0.),epsl) )
    return Standard_False;
  return Standard_True;
}

    Standard_Boolean  IGESConvGeom_GeomBuilder::IsTranslation () const
{
  if (thepos.Form() == gp_Identity || thepos.Form() == gp_Translation)
    return Standard_True;
//   sinon, regarder de plus pres  ...

  Standard_Integer i,j;
  for (i = 1; i <= 3; i ++)
    for (j = 1; j <= 3; j ++) {
      Standard_Real cons = (i == j ? 1. : 0.);
      Standard_Real val  = thepos.Value(i,j);
      if (val > cons + epsa || val < cons - epsa) return Standard_False;
    }
  return Standard_True;
}

    Standard_Boolean  IGESConvGeom_GeomBuilder::IsZOnly () const
{
  if (!IsTranslation()) return Standard_False;
  gp_XYZ t = thepos.TranslationPart();  t.SetZ (0.0);
  if (!t.IsEqual (gp_XYZ(0.,0.,0.),epsl) ) return Standard_False;
  return Standard_True;
}

    void  IGESConvGeom_GeomBuilder::EvalXYZ
  (const gp_XYZ& val,
   Standard_Real& X, Standard_Real& Y, Standard_Real& Z) const
{
  val.Coord (X,Y,Z);
  thepos.Inverted().Transforms (X,Y,Z);
}

    Handle(IGESGeom_TransformationMatrix)
  IGESConvGeom_GeomBuilder::MakeTransformation (const Standard_Real unit) const
{
  Handle(TColStd_HArray2OfReal) data = new TColStd_HArray2OfReal (1,3,1,4);
  Standard_Integer i,j;
  for (i = 1; i <= 3; i ++)
    for (j = 1; j <= 4; j ++)
      data->SetValue (i,j, (j == 4 ? thepos.Value(i,j)/unit : thepos.Value(i,j)) );
  Handle(IGESGeom_TransformationMatrix) rs = new IGESGeom_TransformationMatrix;
  rs->Init (data);
  if (thepos.IsNegative()) rs->SetFormNumber(1);
  return rs;
}