3779d7523968e70d15aa6246da3744ec873b3d91
[occt.git] / src / AppParCurves / AppParCurves_MultiPoint.cxx
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
16 #include <AppParCurves_MultiPoint.hxx>
17 #include <gp_Pnt.hxx>
18 #include <gp_Pnt2d.hxx>
19 #include <Standard_Transient.hxx>
20 #include <Standard_DimensionError.hxx>
21 #include <Standard_OutOfRange.hxx>
22 #include <TColgp_HArray1OfPnt.hxx>
23 #include <TColgp_HArray1OfPnt2d.hxx>
24
25 #define tabPoint   Handle(TColgp_HArray1OfPnt)::DownCast (ttabPoint)
26 #define tabPoint2d Handle(TColgp_HArray1OfPnt2d)::DownCast (ttabPoint2d)
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
106 AppParCurves_MultiPoint::~AppParCurves_MultiPoint()
107 {
108 }
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 {
118   if (Dimension(CuIndex) != 3) throw Standard_OutOfRange();
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 {
133   if (Dimension(CuIndex) != 2) throw Standard_OutOfRange();
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 void AppParCurves_MultiPoint::SetPoint (const Standard_Integer Index, 
142                                         const gp_Pnt&          Point) {
143   Standard_OutOfRange_Raise_if ((Index <= 0) || (Index > nbP),
144                                 "AppParCurves_MultiPoint::SetPoint() - wrong index");
145   tabPoint->SetValue(Index, Point);
146 }
147
148 const gp_Pnt& AppParCurves_MultiPoint::Point (const Standard_Integer Index) const 
149 {
150   Standard_OutOfRange_Raise_if ((Index <= 0) || (Index > nbP),
151                                 "AppParCurves_MultiPoint::Point() - wrong index");
152   return tabPoint->Value(Index);
153 }
154
155 void AppParCurves_MultiPoint::SetPoint2d (const Standard_Integer Index, 
156                                           const gp_Pnt2d& Point)
157  {
158   Standard_OutOfRange_Raise_if ((Index <= nbP) || (Index > nbP+nbP2d),
159                                 "AppParCurves_MultiPoint::SetPoint2d() - wrong index");
160   tabPoint2d->SetValue(Index-nbP, Point);
161 }
162
163 const gp_Pnt2d& AppParCurves_MultiPoint::Point2d (const Standard_Integer Index) const 
164 {
165   Standard_OutOfRange_Raise_if ((Index <= nbP) || (Index > nbP+nbP2d),
166                                 "AppParCurves_MultiPoint::Point2d() - wrong index");
167   return tabPoint2d->Value(Index-nbP);
168 }
169
170 void AppParCurves_MultiPoint::Dump(Standard_OStream& o) const
171 {
172   o << "AppParCurves_MultiPoint dump:" << std::endl;
173   const Standard_Integer  aNbPnts3D = NbPoints(),
174                           aNbPnts2D = NbPoints2d();
175   o << "It contains " << aNbPnts3D << " 3d points and " << aNbPnts2D <<" 2d points." << std::endl;
176   
177   if(aNbPnts3D > 0)
178   {
179     for(Standard_Integer i = tabPoint->Lower(); i <= tabPoint->Upper(); i++)
180     {
181       o << "3D-Point #" << i << std::endl;
182
183       o << " Pole x = " << (tabPoint->Value(i)/*->Point(j)*/).X() << std::endl;
184       o << " Pole y = " << (tabPoint->Value(i)/*->Point(j)*/).Y() << std::endl;
185       o << " Pole z = " << (tabPoint->Value(i)/*->Point(j)*/).Z() << std::endl;
186     }
187   }
188   
189   if(aNbPnts2D > 0)
190   {
191     for(Standard_Integer i = tabPoint2d->Lower(); i <= tabPoint2d->Upper(); i++)
192     {
193       o << "2D-Point #" << i << std::endl;
194
195       o << " Pole x = " << (tabPoint2d->Value(i)/*->Point2d(j)*/).X() << std::endl;
196       o << " Pole y = " << (tabPoint2d->Value(i)/*->Point2d(j)*/).Y() << std::endl;
197     }
198   }
199 }