0031687: Draw Harness, ViewerTest - extend command vrenderparams with option updating...
[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
d533dafb 28AppParCurves_MultiPoint::AppParCurves_MultiPoint()
29: nbP(0),
30 nbP2d(0)
31{
32}
7fd59977 33
34
35AppParCurves_MultiPoint::AppParCurves_MultiPoint (const Standard_Integer NbPoles,
36 const Standard_Integer NbPoles2d)
37{
38 nbP = NbPoles;
39 nbP2d = NbPoles2d;
40 if (nbP != 0) {
41 Handle(TColgp_HArray1OfPnt) tab3d =
42 new TColgp_HArray1OfPnt(1, NbPoles);
43 ttabPoint = tab3d;
44 }
45 if (nbP2d != 0) {
46 Handle(TColgp_HArray1OfPnt2d) tab2d =
47 new TColgp_HArray1OfPnt2d(1, NbPoles2d);
48 ttabPoint2d = tab2d;
49 }
50}
51
52
53
54AppParCurves_MultiPoint::AppParCurves_MultiPoint(const TColgp_Array1OfPnt& tabP)
55{
56 nbP2d = 0;
57 nbP = tabP.Length();
58 Handle(TColgp_HArray1OfPnt) tab3d =
59 new TColgp_HArray1OfPnt(1, nbP);
60 ttabPoint = tab3d;
61 Standard_Integer Lower = tabP.Lower();
62 TColgp_Array1OfPnt& P3d = tabPoint->ChangeArray1();
63 for (Standard_Integer i = 1; i <= tabP.Length(); i++) {
64 P3d.SetValue(i, tabP.Value(Lower+i-1));
65 }
66}
67
68
69
70AppParCurves_MultiPoint::AppParCurves_MultiPoint(const TColgp_Array1OfPnt2d& tabP2d)
71{
72 nbP = 0;
73 nbP2d = tabP2d.Length();
74 Handle(TColgp_HArray1OfPnt2d) tab2d =
75 new TColgp_HArray1OfPnt2d(1, nbP2d);
76 ttabPoint2d = tab2d;
77 Standard_Integer Lower = tabP2d.Lower();
78 TColgp_Array1OfPnt2d& P2d = tabPoint2d->ChangeArray1();
79 for (Standard_Integer i = 1; i <= nbP2d; i++) {
80 P2d.SetValue(i, tabP2d.Value(Lower+i-1));
81 }
82}
83
84
85AppParCurves_MultiPoint::AppParCurves_MultiPoint(const TColgp_Array1OfPnt& tabP,
86 const TColgp_Array1OfPnt2d& tabP2d)
87{
88 nbP = tabP.Length();
89 nbP2d = tabP2d.Length();
90 Handle(TColgp_HArray1OfPnt) t3d =
91 new TColgp_HArray1OfPnt(1, nbP);
92 ttabPoint = t3d;
93
94 Handle(TColgp_HArray1OfPnt2d) t2d =
95 new TColgp_HArray1OfPnt2d(1, nbP2d);
96 ttabPoint2d = t2d;
97
98 TColgp_Array1OfPnt& P3d = tabPoint->ChangeArray1();
99 Standard_Integer i, Lower = tabP.Lower();
100 for (i = 1; i <= nbP; i++) {
101 P3d.SetValue(i, tabP.Value(Lower+i-1));
102 }
103 Lower = tabP2d.Lower();
104 TColgp_Array1OfPnt2d& P2d = tabPoint2d->ChangeArray1();
105 for (i = 1; i <= nbP2d; i++) {
106 P2d.SetValue(i, tabP2d.Value(Lower+i-1));
107 }
108}
109
6da30ff1 110AppParCurves_MultiPoint::~AppParCurves_MultiPoint()
111{
112}
7fd59977 113
114void AppParCurves_MultiPoint::Transform(const Standard_Integer CuIndex,
115 const Standard_Real x,
116 const Standard_Real dx,
117 const Standard_Real y,
118 const Standard_Real dy,
119 const Standard_Real z,
120 const Standard_Real dz)
121{
9775fa61 122 if (Dimension(CuIndex) != 3) throw Standard_OutOfRange();
7fd59977 123
124 gp_Pnt P, newP;
125 P = Point(CuIndex);
126 newP.SetCoord(x + P.X()*dx, y + P.Y()*dy, z + P.Z()*dz);
127 tabPoint->SetValue(CuIndex, newP);
128}
129
130
131void AppParCurves_MultiPoint::Transform2d(const Standard_Integer CuIndex,
132 const Standard_Real x,
133 const Standard_Real dx,
134 const Standard_Real y,
135 const Standard_Real dy)
136{
9775fa61 137 if (Dimension(CuIndex) != 2) throw Standard_OutOfRange();
7fd59977 138
139 gp_Pnt2d P, newP;
140 P = Point2d(CuIndex);
141 newP.SetCoord(x + P.X()*dx, y + P.Y()*dy);
142 SetPoint2d(CuIndex, newP);
143}
144
7fd59977 145void AppParCurves_MultiPoint::SetPoint (const Standard_Integer Index,
146 const gp_Pnt& Point) {
2d2b3d53 147 Standard_OutOfRange_Raise_if ((Index <= 0) || (Index > nbP),
148 "AppParCurves_MultiPoint::SetPoint() - wrong index");
7fd59977 149 tabPoint->SetValue(Index, Point);
150}
151
7fd59977 152const gp_Pnt& AppParCurves_MultiPoint::Point (const Standard_Integer Index) const
153{
2d2b3d53 154 Standard_OutOfRange_Raise_if ((Index <= 0) || (Index > nbP),
155 "AppParCurves_MultiPoint::Point() - wrong index");
7fd59977 156 return tabPoint->Value(Index);
157}
7fd59977 158
159void AppParCurves_MultiPoint::SetPoint2d (const Standard_Integer Index,
160 const gp_Pnt2d& Point)
161 {
2d2b3d53 162 Standard_OutOfRange_Raise_if ((Index <= nbP) || (Index > nbP+nbP2d),
163 "AppParCurves_MultiPoint::SetPoint2d() - wrong index");
7fd59977 164 tabPoint2d->SetValue(Index-nbP, Point);
165}
166
7fd59977 167const gp_Pnt2d& AppParCurves_MultiPoint::Point2d (const Standard_Integer Index) const
168{
2d2b3d53 169 Standard_OutOfRange_Raise_if ((Index <= nbP) || (Index > nbP+nbP2d),
170 "AppParCurves_MultiPoint::Point2d() - wrong index");
7fd59977 171 return tabPoint2d->Value(Index-nbP);
172}
7fd59977 173
174void AppParCurves_MultiPoint::Dump(Standard_OStream& o) const
175{
04232180 176 o << "AppParCurves_MultiPoint dump:" << std::endl;
7a8c6a36 177 const Standard_Integer aNbPnts3D = NbPoints(),
178 aNbPnts2D = NbPoints2d();
04232180 179 o << "It contains " << aNbPnts3D << " 3d points and " << aNbPnts2D <<" 2d points." << std::endl;
7a8c6a36 180
181 if(aNbPnts3D > 0)
182 {
183 for(Standard_Integer i = tabPoint->Lower(); i <= tabPoint->Upper(); i++)
184 {
04232180 185 o << "3D-Point #" << i << std::endl;
7a8c6a36 186
04232180 187 o << " Pole x = " << (tabPoint->Value(i)/*->Point(j)*/).X() << std::endl;
188 o << " Pole y = " << (tabPoint->Value(i)/*->Point(j)*/).Y() << std::endl;
189 o << " Pole z = " << (tabPoint->Value(i)/*->Point(j)*/).Z() << std::endl;
7fd59977 190 }
7a8c6a36 191 }
192
193 if(aNbPnts2D > 0)
194 {
195 for(Standard_Integer i = tabPoint2d->Lower(); i <= tabPoint2d->Upper(); i++)
196 {
04232180 197 o << "2D-Point #" << i << std::endl;
7a8c6a36 198
04232180 199 o << " Pole x = " << (tabPoint2d->Value(i)/*->Point2d(j)*/).X() << std::endl;
200 o << " Pole y = " << (tabPoint2d->Value(i)/*->Point2d(j)*/).Y() << std::endl;
7a8c6a36 201 }
202 }
7fd59977 203}