b311480e |
1 | // Created by: CKY / Contract Toubro-Larsen |
2 | // Copyright (c) 1993-1999 Matra Datavision |
973c2be1 |
3 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
4 | // |
973c2be1 |
5 | // This file is part of Open CASCADE Technology software library. |
7fd59977 |
6 | // |
d5f74e42 |
7 | // This library is free software; you can redistribute it and/or modify it under |
8 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
9 | // by the Free Software Foundation, with special exception defined in the file |
10 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
11 | // distribution for complete text of the license and disclaimer of any warranty. |
7fd59977 |
12 | // |
973c2be1 |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
b311480e |
15 | |
16 | //-------------------------------------------------------------------- |
7fd59977 |
17 | //-------------------------------------------------------------------- |
18 | |
7fd59977 |
19 | #include <gp_GTrsf.hxx> |
42cf5bc1 |
20 | #include <gp_Pnt.hxx> |
21 | #include <gp_Vec.hxx> |
22 | #include <gp_XY.hxx> |
23 | #include <IGESGeom_CopiousData.hxx> |
24 | #include <Standard_DimensionMismatch.hxx> |
7fd59977 |
25 | #include <Standard_NullObject.hxx> |
42cf5bc1 |
26 | #include <Standard_OutOfRange.hxx> |
27 | #include <Standard_Type.hxx> |
7fd59977 |
28 | |
92efcf78 |
29 | IMPLEMENT_STANDARD_RTTIEXT(IGESGeom_CopiousData,IGESData_IGESEntity) |
30 | |
b311480e |
31 | IGESGeom_CopiousData::IGESGeom_CopiousData () |
7fd59977 |
32 | { |
33 | theDataType = 0; // to allow Setting Form Number before Init |
34 | } |
35 | |
36 | |
37 | void IGESGeom_CopiousData::Init |
38 | (const Standard_Integer aDataType, |
39 | const Standard_Real aZPlane, |
40 | const Handle(TColStd_HArray1OfReal)& allData) |
41 | { |
42 | // PTV OCC386 crach application while reading So5771b.igs |
43 | if (allData.IsNull()) |
9775fa61 |
44 | throw Standard_NullObject("IGESGeom_CopiousData : Init with null data"); |
7fd59977 |
45 | |
9775fa61 |
46 | if (allData->Lower() != 1) throw Standard_DimensionMismatch("IGESGeom_CopiousData : Init"); |
7fd59977 |
47 | theDataType = aDataType; |
48 | theZPlane = aZPlane; |
49 | theData = allData; |
50 | // FormNumber = DataType + <N> N=0 -> Set of Points. N=10 : PolyLine |
51 | // or N=62 (DataType=1 only, gives FormNumber=63) : 2D closed path |
52 | InitTypeAndForm(106,FormNumber()); |
53 | } |
54 | |
55 | void IGESGeom_CopiousData::SetPolyline (const Standard_Boolean F) |
56 | { |
57 | Standard_Integer newfn = theDataType; |
58 | if (F) newfn += 10; |
59 | InitTypeAndForm(106,newfn); |
60 | } |
61 | |
62 | void IGESGeom_CopiousData::SetClosedPath2D () |
63 | { |
64 | InitTypeAndForm(106,63); // et verifier DataType ! |
65 | } |
66 | |
67 | |
68 | Standard_Boolean IGESGeom_CopiousData::IsPointSet () const |
69 | { |
70 | return (FormNumber() < 10); |
71 | } |
72 | |
73 | Standard_Boolean IGESGeom_CopiousData::IsPolyline () const |
74 | { |
75 | return (FormNumber()/10 == 1); |
76 | } |
77 | |
78 | Standard_Boolean IGESGeom_CopiousData::IsClosedPath2D () const |
79 | { |
80 | return (FormNumber() == 63); |
81 | } |
82 | |
83 | |
84 | Standard_Integer IGESGeom_CopiousData::DataType () const |
85 | { |
86 | return theDataType; |
87 | } |
88 | |
89 | Standard_Integer IGESGeom_CopiousData::NbPoints () const |
90 | { |
91 | Standard_Integer nbtuples; |
92 | // PTV OCC386 |
93 | if (theData.IsNull()) |
94 | nbtuples = 0; |
95 | else |
96 | nbtuples = theData->Length(); |
97 | if (theDataType == 1) nbtuples /= 2; |
98 | else if (theDataType == 2) nbtuples /= 3; |
99 | else if (theDataType == 3) nbtuples /= 6; |
100 | return nbtuples; |
101 | } |
102 | |
103 | Standard_Real IGESGeom_CopiousData::Data |
104 | (const Standard_Integer nump, const Standard_Integer numdata) const |
105 | { |
106 | Standard_Integer numd = 0; |
107 | if (theDataType == 1) numd = 2*(nump - 1) + numdata; // 1-2 |
108 | else if (theDataType == 2) numd = 3*(nump - 1) + numdata; // 1-2-3 |
109 | else if (theDataType == 3) numd = 6*(nump - 1) + numdata; // 1-2-3-4-5-6 |
110 | return theData->Value(numd); |
111 | } |
112 | |
113 | Standard_Real IGESGeom_CopiousData::ZPlane () const |
114 | { |
115 | return theZPlane; |
116 | } |
117 | |
118 | gp_Pnt IGESGeom_CopiousData::Point (const Standard_Integer anIndex) const |
119 | { |
120 | Standard_Integer lower = theData->Lower(); |
121 | Standard_Integer real_index; |
122 | Standard_Real X=0.,Y=0.,Z=0. ; |
123 | if (theDataType == 1) { |
124 | real_index = lower + 2 * (anIndex-1); |
125 | X = theData->Value(real_index); |
126 | Y = theData->Value(real_index+1); |
127 | Z = theZPlane; |
128 | } |
129 | |
130 | if (theDataType == 2) { |
131 | real_index = lower + 3 * (anIndex-1); |
132 | X = theData->Value(real_index); |
133 | Y = theData->Value(real_index+1); |
134 | Z = theData->Value(real_index+2); |
135 | } |
136 | |
137 | if (theDataType == 3) { |
138 | real_index = lower + 6 * (anIndex-1); |
139 | X = theData->Value(real_index); |
140 | Y = theData->Value(real_index+1); |
141 | Z = theData->Value(real_index+2); |
142 | } |
143 | |
144 | gp_Pnt point(X,Y,Z); |
145 | return point; |
146 | } |
147 | |
148 | gp_Pnt IGESGeom_CopiousData::TransformedPoint |
149 | (const Standard_Integer anIndex) const |
150 | { |
151 | if (!HasTransf()) return Point(anIndex); |
152 | gp_XYZ xyz (Point(anIndex).XYZ()); |
153 | Location().Transforms(xyz); |
154 | return gp_Pnt(xyz); |
155 | } |
156 | |
157 | gp_Vec IGESGeom_CopiousData::Vector (const Standard_Integer anIndex) const |
158 | { |
159 | Standard_Integer lower = theData->Lower(); |
160 | Standard_Integer Real_Index; |
161 | if (theDataType != 3) return gp_Vec(0.0, 0.0, 0.0); |
162 | Real_Index = lower + 6*(anIndex-1) +3; |
163 | Standard_Real I = theData->Value(Real_Index); |
164 | Standard_Real J = theData->Value(Real_Index+1); |
165 | Standard_Real K = theData->Value(Real_Index+2); |
166 | return gp_Vec(I, J, K); |
167 | } |
168 | |
169 | gp_Vec IGESGeom_CopiousData::TransformedVector |
170 | (const Standard_Integer anIndex) const |
171 | { |
172 | if (!HasTransf()) return Vector (anIndex); |
173 | gp_XYZ xyz (Vector(anIndex).XYZ()); |
174 | gp_GTrsf loc = Location(); |
175 | loc.SetTranslationPart(gp_XYZ(0.,0.,0.)); |
176 | loc.Transforms(xyz); |
177 | return gp_Vec(xyz); |
178 | } |