0030679: Attached model hangs most of OCCT common functionality
[occt.git] / src / AppParCurves / AppParCurves_MultiPoint.cxx
CommitLineData
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>
25e59720 19#include <Standard_Transient.hxx>
42cf5bc1 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
28AppParCurves_MultiPoint::AppParCurves_MultiPoint() {}
29
30
31AppParCurves_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
50AppParCurves_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
66AppParCurves_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
81AppParCurves_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 106AppParCurves_MultiPoint::~AppParCurves_MultiPoint()
107{
108}
7fd59977 109
110void 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
127void 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
7fd59977 141void AppParCurves_MultiPoint::SetPoint (const Standard_Integer Index,
142 const gp_Pnt& Point) {
2d2b3d53 143 Standard_OutOfRange_Raise_if ((Index <= 0) || (Index > nbP),
144 "AppParCurves_MultiPoint::SetPoint() - wrong index");
7fd59977 145 tabPoint->SetValue(Index, Point);
146}
147
7fd59977 148const gp_Pnt& AppParCurves_MultiPoint::Point (const Standard_Integer Index) const
149{
2d2b3d53 150 Standard_OutOfRange_Raise_if ((Index <= 0) || (Index > nbP),
151 "AppParCurves_MultiPoint::Point() - wrong index");
7fd59977 152 return tabPoint->Value(Index);
153}
7fd59977 154
155void AppParCurves_MultiPoint::SetPoint2d (const Standard_Integer Index,
156 const gp_Pnt2d& Point)
157 {
2d2b3d53 158 Standard_OutOfRange_Raise_if ((Index <= nbP) || (Index > nbP+nbP2d),
159 "AppParCurves_MultiPoint::SetPoint2d() - wrong index");
7fd59977 160 tabPoint2d->SetValue(Index-nbP, Point);
161}
162
7fd59977 163const gp_Pnt2d& AppParCurves_MultiPoint::Point2d (const Standard_Integer Index) const
164{
2d2b3d53 165 Standard_OutOfRange_Raise_if ((Index <= nbP) || (Index > nbP+nbP2d),
166 "AppParCurves_MultiPoint::Point2d() - wrong index");
7fd59977 167 return tabPoint2d->Value(Index-nbP);
168}
7fd59977 169
170void AppParCurves_MultiPoint::Dump(Standard_OStream& o) const
171{
172 o << "AppParCurves_MultiPoint dump:" << endl;
7a8c6a36 173 const Standard_Integer aNbPnts3D = NbPoints(),
174 aNbPnts2D = NbPoints2d();
175 o << "It contains " << aNbPnts3D << " 3d points and " << aNbPnts2D <<" 2d points." << endl;
176
177 if(aNbPnts3D > 0)
178 {
179 for(Standard_Integer i = tabPoint->Lower(); i <= tabPoint->Upper(); i++)
180 {
181 o << "3D-Point #" << i << endl;
182
183 o << " Pole x = " << (tabPoint->Value(i)/*->Point(j)*/).X() << endl;
184 o << " Pole y = " << (tabPoint->Value(i)/*->Point(j)*/).Y() << endl;
185 o << " Pole z = " << (tabPoint->Value(i)/*->Point(j)*/).Z() << endl;
7fd59977 186 }
7a8c6a36 187 }
188
189 if(aNbPnts2D > 0)
190 {
191 for(Standard_Integer i = tabPoint2d->Lower(); i <= tabPoint2d->Upper(); i++)
192 {
193 o << "2D-Point #" << i << endl;
194
195 o << " Pole x = " << (tabPoint2d->Value(i)/*->Point2d(j)*/).X() << endl;
196 o << " Pole y = " << (tabPoint2d->Value(i)/*->Point2d(j)*/).Y() << endl;
197 }
198 }
7fd59977 199}