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