summaryrefslogtreecommitdiff
path: root/src/IGESGeom/IGESGeom_CopiousData.cxx
blob: 54dbb5a8036f81b1e6970709bf1851d11d412389 (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
//--------------------------------------------------------------------
//
//  File Name : IGESGeom_CopiousData.cxx
//  Date      :
//  Author    : CKY / Contract Toubro-Larsen
//  Copyright : MATRA-DATAVISION 1993
//
//--------------------------------------------------------------------

#include <IGESGeom_CopiousData.ixx>
#include <Standard_DimensionMismatch.hxx>
#include <gp_XY.hxx>
#include <gp_GTrsf.hxx>
#include <Standard_NullObject.hxx>

    IGESGeom_CopiousData::IGESGeom_CopiousData ()
{
  theDataType = 0;  // to allow Setting Form Number before Init
}


    void IGESGeom_CopiousData::Init
  (const Standard_Integer aDataType,
   const Standard_Real aZPlane,
   const Handle(TColStd_HArray1OfReal)& allData)
{
  // PTV OCC386 crach application while reading So5771b.igs
  if (allData.IsNull())
    Standard_NullObject::Raise("IGESGeom_CopiousData : Init with null data");
  
  if (allData->Lower() != 1) Standard_DimensionMismatch::Raise("IGESGeom_CopiousData : Init");
  theDataType = aDataType;
  theZPlane   = aZPlane;
  theData     = allData;
// FormNumber = DataType + <N>  N=0 -> Set of Points. N=10 : PolyLine
//    or N=62 (DataType=1 only, gives FormNumber=63) : 2D closed path
  InitTypeAndForm(106,FormNumber());
}

    void  IGESGeom_CopiousData::SetPolyline (const Standard_Boolean F)
{
  Standard_Integer newfn = theDataType;
  if (F) newfn += 10;
  InitTypeAndForm(106,newfn);
}

    void  IGESGeom_CopiousData::SetClosedPath2D ()
{
  InitTypeAndForm(106,63);    // et verifier DataType !
}


    Standard_Boolean  IGESGeom_CopiousData::IsPointSet () const
{
  return (FormNumber() < 10);
}

    Standard_Boolean  IGESGeom_CopiousData::IsPolyline () const
{
  return (FormNumber()/10 == 1);
}

    Standard_Boolean  IGESGeom_CopiousData::IsClosedPath2D () const
{
  return (FormNumber() == 63);
}


    Standard_Integer IGESGeom_CopiousData::DataType () const
{
  return theDataType;
}

    Standard_Integer IGESGeom_CopiousData::NbPoints () const
{
  Standard_Integer nbtuples;
  // PTV OCC386 
  if (theData.IsNull())
    nbtuples = 0;
  else
    nbtuples = theData->Length();
  if      (theDataType == 1)    nbtuples /= 2;
  else if (theDataType == 2)    nbtuples /= 3;
  else if (theDataType == 3)    nbtuples /= 6;
  return nbtuples;
}

    Standard_Real  IGESGeom_CopiousData::Data
  (const Standard_Integer nump, const Standard_Integer numdata) const
{
  Standard_Integer numd = 0;
  if      (theDataType == 1) numd = 2*(nump - 1) + numdata;  // 1-2
  else if (theDataType == 2) numd = 3*(nump - 1) + numdata;  // 1-2-3
  else if (theDataType == 3) numd = 6*(nump - 1) + numdata;  // 1-2-3-4-5-6
  return theData->Value(numd);
}

    Standard_Real IGESGeom_CopiousData::ZPlane () const
{
  return theZPlane;
}

    gp_Pnt IGESGeom_CopiousData::Point (const Standard_Integer anIndex) const
{
  Standard_Integer lower = theData->Lower();
  Standard_Integer real_index;
  Standard_Real X=0.,Y=0.,Z=0. ;
  if (theDataType == 1) {
    real_index = lower + 2 * (anIndex-1);
    X = theData->Value(real_index);
    Y = theData->Value(real_index+1);
    Z = theZPlane;
  }

  if (theDataType == 2) {
    real_index = lower + 3 * (anIndex-1);
    X = theData->Value(real_index);
    Y = theData->Value(real_index+1);
    Z = theData->Value(real_index+2);
  }

  if (theDataType == 3) {
    real_index = lower + 6 * (anIndex-1);
    X = theData->Value(real_index);
    Y = theData->Value(real_index+1);
    Z = theData->Value(real_index+2);
  }

  gp_Pnt point(X,Y,Z);
  return point;
}

    gp_Pnt IGESGeom_CopiousData::TransformedPoint
  (const Standard_Integer anIndex) const
{
  if (!HasTransf()) return Point(anIndex);
  gp_XYZ xyz (Point(anIndex).XYZ());
  Location().Transforms(xyz);
  return gp_Pnt(xyz);
}

    gp_Vec IGESGeom_CopiousData::Vector (const Standard_Integer anIndex) const
{
  Standard_Integer lower = theData->Lower();
  Standard_Integer Real_Index;
  if (theDataType != 3) return gp_Vec(0.0, 0.0, 0.0);
  Real_Index = lower + 6*(anIndex-1) +3;
  Standard_Real I = theData->Value(Real_Index);
  Standard_Real J = theData->Value(Real_Index+1);
  Standard_Real K = theData->Value(Real_Index+2);
  return gp_Vec(I, J, K);
}

    gp_Vec IGESGeom_CopiousData::TransformedVector
  (const Standard_Integer anIndex) const
{
  if (!HasTransf()) return Vector (anIndex);
  gp_XYZ xyz (Vector(anIndex).XYZ());
  gp_GTrsf loc = Location();
  loc.SetTranslationPart(gp_XYZ(0.,0.,0.));
  loc.Transforms(xyz);
  return gp_Vec(xyz);
}