0023258: Missing parenthesis
[occt.git] / src / IGESGeom / IGESGeom_CopiousData.cxx
1 // Created by: CKY / Contract Toubro-Larsen
2 // Copyright (c) 1993-1999 Matra Datavision
3 // Copyright (c) 1999-2012 OPEN CASCADE SAS
4 //
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
9 //
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12 //
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
19
20 //--------------------------------------------------------------------
21 //--------------------------------------------------------------------
22
23 #include <IGESGeom_CopiousData.ixx>
24 #include <Standard_DimensionMismatch.hxx>
25 #include <gp_XY.hxx>
26 #include <gp_GTrsf.hxx>
27 #include <Standard_NullObject.hxx>
28
29 IGESGeom_CopiousData::IGESGeom_CopiousData ()
30 {
31   theDataType = 0;  // to allow Setting Form Number before Init
32 }
33
34
35     void IGESGeom_CopiousData::Init
36   (const Standard_Integer aDataType,
37    const Standard_Real aZPlane,
38    const Handle(TColStd_HArray1OfReal)& allData)
39 {
40   // PTV OCC386 crach application while reading So5771b.igs
41   if (allData.IsNull())
42     Standard_NullObject::Raise("IGESGeom_CopiousData : Init with null data");
43   
44   if (allData->Lower() != 1) Standard_DimensionMismatch::Raise("IGESGeom_CopiousData : Init");
45   theDataType = aDataType;
46   theZPlane   = aZPlane;
47   theData     = allData;
48 // FormNumber = DataType + <N>  N=0 -> Set of Points. N=10 : PolyLine
49 //    or N=62 (DataType=1 only, gives FormNumber=63) : 2D closed path
50   InitTypeAndForm(106,FormNumber());
51 }
52
53     void  IGESGeom_CopiousData::SetPolyline (const Standard_Boolean F)
54 {
55   Standard_Integer newfn = theDataType;
56   if (F) newfn += 10;
57   InitTypeAndForm(106,newfn);
58 }
59
60     void  IGESGeom_CopiousData::SetClosedPath2D ()
61 {
62   InitTypeAndForm(106,63);    // et verifier DataType !
63 }
64
65
66     Standard_Boolean  IGESGeom_CopiousData::IsPointSet () const
67 {
68   return (FormNumber() < 10);
69 }
70
71     Standard_Boolean  IGESGeom_CopiousData::IsPolyline () const
72 {
73   return (FormNumber()/10 == 1);
74 }
75
76     Standard_Boolean  IGESGeom_CopiousData::IsClosedPath2D () const
77 {
78   return (FormNumber() == 63);
79 }
80
81
82     Standard_Integer IGESGeom_CopiousData::DataType () const
83 {
84   return theDataType;
85 }
86
87     Standard_Integer IGESGeom_CopiousData::NbPoints () const
88 {
89   Standard_Integer nbtuples;
90   // PTV OCC386 
91   if (theData.IsNull())
92     nbtuples = 0;
93   else
94     nbtuples = theData->Length();
95   if      (theDataType == 1)    nbtuples /= 2;
96   else if (theDataType == 2)    nbtuples /= 3;
97   else if (theDataType == 3)    nbtuples /= 6;
98   return nbtuples;
99 }
100
101     Standard_Real  IGESGeom_CopiousData::Data
102   (const Standard_Integer nump, const Standard_Integer numdata) const
103 {
104   Standard_Integer numd = 0;
105   if      (theDataType == 1) numd = 2*(nump - 1) + numdata;  // 1-2
106   else if (theDataType == 2) numd = 3*(nump - 1) + numdata;  // 1-2-3
107   else if (theDataType == 3) numd = 6*(nump - 1) + numdata;  // 1-2-3-4-5-6
108   return theData->Value(numd);
109 }
110
111     Standard_Real IGESGeom_CopiousData::ZPlane () const
112 {
113   return theZPlane;
114 }
115
116     gp_Pnt IGESGeom_CopiousData::Point (const Standard_Integer anIndex) const
117 {
118   Standard_Integer lower = theData->Lower();
119   Standard_Integer real_index;
120   Standard_Real X=0.,Y=0.,Z=0. ;
121   if (theDataType == 1) {
122     real_index = lower + 2 * (anIndex-1);
123     X = theData->Value(real_index);
124     Y = theData->Value(real_index+1);
125     Z = theZPlane;
126   }
127
128   if (theDataType == 2) {
129     real_index = lower + 3 * (anIndex-1);
130     X = theData->Value(real_index);
131     Y = theData->Value(real_index+1);
132     Z = theData->Value(real_index+2);
133   }
134
135   if (theDataType == 3) {
136     real_index = lower + 6 * (anIndex-1);
137     X = theData->Value(real_index);
138     Y = theData->Value(real_index+1);
139     Z = theData->Value(real_index+2);
140   }
141
142   gp_Pnt point(X,Y,Z);
143   return point;
144 }
145
146     gp_Pnt IGESGeom_CopiousData::TransformedPoint
147   (const Standard_Integer anIndex) const
148 {
149   if (!HasTransf()) return Point(anIndex);
150   gp_XYZ xyz (Point(anIndex).XYZ());
151   Location().Transforms(xyz);
152   return gp_Pnt(xyz);
153 }
154
155     gp_Vec IGESGeom_CopiousData::Vector (const Standard_Integer anIndex) const
156 {
157   Standard_Integer lower = theData->Lower();
158   Standard_Integer Real_Index;
159   if (theDataType != 3) return gp_Vec(0.0, 0.0, 0.0);
160   Real_Index = lower + 6*(anIndex-1) +3;
161   Standard_Real I = theData->Value(Real_Index);
162   Standard_Real J = theData->Value(Real_Index+1);
163   Standard_Real K = theData->Value(Real_Index+2);
164   return gp_Vec(I, J, K);
165 }
166
167     gp_Vec IGESGeom_CopiousData::TransformedVector
168   (const Standard_Integer anIndex) const
169 {
170   if (!HasTransf()) return Vector (anIndex);
171   gp_XYZ xyz (Vector(anIndex).XYZ());
172   gp_GTrsf loc = Location();
173   loc.SetTranslationPart(gp_XYZ(0.,0.,0.));
174   loc.Transforms(xyz);
175   return gp_Vec(xyz);
176 }