b311480e |
1 | // Copyright (c) 1995-1999 Matra Datavision |
973c2be1 |
2 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
3 | // |
973c2be1 |
4 | // This file is part of Open CASCADE Technology software library. |
b311480e |
5 | // |
d5f74e42 |
6 | // This library is free software; you can redistribute it and/or modify it under |
7 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
8 | // by the Free Software Foundation, with special exception defined in the file |
9 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
10 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
11 | // |
973c2be1 |
12 | // Alternatively, this file may be used under the terms of Open CASCADE |
13 | // commercial license or contractual agreement. |
7fd59977 |
14 | |
7fd59977 |
15 | |
42cf5bc1 |
16 | #include <AppParCurves_MultiPoint.hxx> |
17 | #include <gp_Pnt.hxx> |
18 | #include <gp_Pnt2d.hxx> |
19 | #include <MMgt_TShared.hxx> |
20 | #include <Standard_DimensionError.hxx> |
7fd59977 |
21 | #include <Standard_OutOfRange.hxx> |
42cf5bc1 |
22 | #include <TColgp_HArray1OfPnt.hxx> |
23 | #include <TColgp_HArray1OfPnt2d.hxx> |
7fd59977 |
24 | |
c5f3a425 |
25 | #define tabPoint Handle(TColgp_HArray1OfPnt)::DownCast (ttabPoint) |
26 | #define tabPoint2d Handle(TColgp_HArray1OfPnt2d)::DownCast (ttabPoint2d) |
7fd59977 |
27 | |
28 | AppParCurves_MultiPoint::AppParCurves_MultiPoint() {} |
29 | |
30 | |
31 | AppParCurves_MultiPoint::AppParCurves_MultiPoint (const Standard_Integer NbPoles, |
32 | const Standard_Integer NbPoles2d) |
33 | { |
34 | nbP = NbPoles; |
35 | nbP2d = NbPoles2d; |
36 | if (nbP != 0) { |
37 | Handle(TColgp_HArray1OfPnt) tab3d = |
38 | new TColgp_HArray1OfPnt(1, NbPoles); |
39 | ttabPoint = tab3d; |
40 | } |
41 | if (nbP2d != 0) { |
42 | Handle(TColgp_HArray1OfPnt2d) tab2d = |
43 | new TColgp_HArray1OfPnt2d(1, NbPoles2d); |
44 | ttabPoint2d = tab2d; |
45 | } |
46 | } |
47 | |
48 | |
49 | |
50 | AppParCurves_MultiPoint::AppParCurves_MultiPoint(const TColgp_Array1OfPnt& tabP) |
51 | { |
52 | nbP2d = 0; |
53 | nbP = tabP.Length(); |
54 | Handle(TColgp_HArray1OfPnt) tab3d = |
55 | new TColgp_HArray1OfPnt(1, nbP); |
56 | ttabPoint = tab3d; |
57 | Standard_Integer Lower = tabP.Lower(); |
58 | TColgp_Array1OfPnt& P3d = tabPoint->ChangeArray1(); |
59 | for (Standard_Integer i = 1; i <= tabP.Length(); i++) { |
60 | P3d.SetValue(i, tabP.Value(Lower+i-1)); |
61 | } |
62 | } |
63 | |
64 | |
65 | |
66 | AppParCurves_MultiPoint::AppParCurves_MultiPoint(const TColgp_Array1OfPnt2d& tabP2d) |
67 | { |
68 | nbP = 0; |
69 | nbP2d = tabP2d.Length(); |
70 | Handle(TColgp_HArray1OfPnt2d) tab2d = |
71 | new TColgp_HArray1OfPnt2d(1, nbP2d); |
72 | ttabPoint2d = tab2d; |
73 | Standard_Integer Lower = tabP2d.Lower(); |
74 | TColgp_Array1OfPnt2d& P2d = tabPoint2d->ChangeArray1(); |
75 | for (Standard_Integer i = 1; i <= nbP2d; i++) { |
76 | P2d.SetValue(i, tabP2d.Value(Lower+i-1)); |
77 | } |
78 | } |
79 | |
80 | |
81 | AppParCurves_MultiPoint::AppParCurves_MultiPoint(const TColgp_Array1OfPnt& tabP, |
82 | const TColgp_Array1OfPnt2d& tabP2d) |
83 | { |
84 | nbP = tabP.Length(); |
85 | nbP2d = tabP2d.Length(); |
86 | Handle(TColgp_HArray1OfPnt) t3d = |
87 | new TColgp_HArray1OfPnt(1, nbP); |
88 | ttabPoint = t3d; |
89 | |
90 | Handle(TColgp_HArray1OfPnt2d) t2d = |
91 | new TColgp_HArray1OfPnt2d(1, nbP2d); |
92 | ttabPoint2d = t2d; |
93 | |
94 | TColgp_Array1OfPnt& P3d = tabPoint->ChangeArray1(); |
95 | Standard_Integer i, Lower = tabP.Lower(); |
96 | for (i = 1; i <= nbP; i++) { |
97 | P3d.SetValue(i, tabP.Value(Lower+i-1)); |
98 | } |
99 | Lower = tabP2d.Lower(); |
100 | TColgp_Array1OfPnt2d& P2d = tabPoint2d->ChangeArray1(); |
101 | for (i = 1; i <= nbP2d; i++) { |
102 | P2d.SetValue(i, tabP2d.Value(Lower+i-1)); |
103 | } |
104 | } |
105 | |
6da30ff1 |
106 | AppParCurves_MultiPoint::~AppParCurves_MultiPoint() |
107 | { |
108 | } |
7fd59977 |
109 | |
110 | void AppParCurves_MultiPoint::Transform(const Standard_Integer CuIndex, |
111 | const Standard_Real x, |
112 | const Standard_Real dx, |
113 | const Standard_Real y, |
114 | const Standard_Real dy, |
115 | const Standard_Real z, |
116 | const Standard_Real dz) |
117 | { |
9775fa61 |
118 | if (Dimension(CuIndex) != 3) throw Standard_OutOfRange(); |
7fd59977 |
119 | |
120 | gp_Pnt P, newP; |
121 | P = Point(CuIndex); |
122 | newP.SetCoord(x + P.X()*dx, y + P.Y()*dy, z + P.Z()*dz); |
123 | tabPoint->SetValue(CuIndex, newP); |
124 | } |
125 | |
126 | |
127 | void AppParCurves_MultiPoint::Transform2d(const Standard_Integer CuIndex, |
128 | const Standard_Real x, |
129 | const Standard_Real dx, |
130 | const Standard_Real y, |
131 | const Standard_Real dy) |
132 | { |
9775fa61 |
133 | if (Dimension(CuIndex) != 2) throw Standard_OutOfRange(); |
7fd59977 |
134 | |
135 | gp_Pnt2d P, newP; |
136 | P = Point2d(CuIndex); |
137 | newP.SetCoord(x + P.X()*dx, y + P.Y()*dy); |
138 | SetPoint2d(CuIndex, newP); |
139 | } |
140 | |
141 | |
142 | |
143 | |
144 | |
145 | void AppParCurves_MultiPoint::SetPoint (const Standard_Integer Index, |
146 | const gp_Pnt& Point) { |
147 | Standard_OutOfRange_Raise_if((Index <= 0) || (Index > nbP), ""); |
148 | tabPoint->SetValue(Index, Point); |
149 | } |
150 | |
151 | |
152 | const gp_Pnt& AppParCurves_MultiPoint::Point (const Standard_Integer Index) const |
153 | { |
154 | Standard_OutOfRange_Raise_if((Index <= 0) || (Index > nbP), ""); |
155 | return tabPoint->Value(Index); |
156 | } |
157 | |
158 | |
159 | |
160 | void AppParCurves_MultiPoint::SetPoint2d (const Standard_Integer Index, |
161 | const gp_Pnt2d& Point) |
162 | { |
163 | Standard_OutOfRange_Raise_if((Index <= nbP) || (Index > nbP+nbP2d), ""); |
164 | tabPoint2d->SetValue(Index-nbP, Point); |
165 | } |
166 | |
167 | |
168 | const gp_Pnt2d& AppParCurves_MultiPoint::Point2d (const Standard_Integer Index) const |
169 | { |
170 | Standard_OutOfRange_Raise_if((Index <= nbP) || (Index > nbP+nbP2d), ""); |
171 | return tabPoint2d->Value(Index-nbP); |
172 | } |
173 | |
174 | |
175 | |
176 | |
177 | |
178 | void AppParCurves_MultiPoint::Dump(Standard_OStream& o) const |
179 | { |
180 | o << "AppParCurves_MultiPoint dump:" << endl; |
7a8c6a36 |
181 | const Standard_Integer aNbPnts3D = NbPoints(), |
182 | aNbPnts2D = NbPoints2d(); |
183 | o << "It contains " << aNbPnts3D << " 3d points and " << aNbPnts2D <<" 2d points." << endl; |
184 | |
185 | if(aNbPnts3D > 0) |
186 | { |
187 | for(Standard_Integer i = tabPoint->Lower(); i <= tabPoint->Upper(); i++) |
188 | { |
189 | o << "3D-Point #" << i << endl; |
190 | |
191 | o << " Pole x = " << (tabPoint->Value(i)/*->Point(j)*/).X() << endl; |
192 | o << " Pole y = " << (tabPoint->Value(i)/*->Point(j)*/).Y() << endl; |
193 | o << " Pole z = " << (tabPoint->Value(i)/*->Point(j)*/).Z() << endl; |
7fd59977 |
194 | } |
7a8c6a36 |
195 | } |
196 | |
197 | if(aNbPnts2D > 0) |
198 | { |
199 | for(Standard_Integer i = tabPoint2d->Lower(); i <= tabPoint2d->Upper(); i++) |
200 | { |
201 | o << "2D-Point #" << i << endl; |
202 | |
203 | o << " Pole x = " << (tabPoint2d->Value(i)/*->Point2d(j)*/).X() << endl; |
204 | o << " Pole y = " << (tabPoint2d->Value(i)/*->Point2d(j)*/).Y() << endl; |
205 | } |
206 | } |
7fd59977 |
207 | } |