| 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 | |
| 24 | AppParCurves_MultiPoint::AppParCurves_MultiPoint() {} |
| 25 | |
| 26 | |
| 27 | AppParCurves_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 | |
| 46 | AppParCurves_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 | |
| 62 | AppParCurves_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 | |
| 77 | AppParCurves_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 | |
| 102 | void AppParCurves_MultiPoint::Delete() |
| 103 | {} |
| 104 | |
| 105 | void AppParCurves_MultiPoint::Transform(const Standard_Integer CuIndex, |
| 106 | const Standard_Real x, |
| 107 | const Standard_Real dx, |
| 108 | const Standard_Real y, |
| 109 | const Standard_Real dy, |
| 110 | const Standard_Real z, |
| 111 | const Standard_Real dz) |
| 112 | { |
| 113 | if (Dimension(CuIndex) != 3) Standard_OutOfRange::Raise(); |
| 114 | |
| 115 | gp_Pnt P, newP; |
| 116 | P = Point(CuIndex); |
| 117 | newP.SetCoord(x + P.X()*dx, y + P.Y()*dy, z + P.Z()*dz); |
| 118 | tabPoint->SetValue(CuIndex, newP); |
| 119 | } |
| 120 | |
| 121 | |
| 122 | void AppParCurves_MultiPoint::Transform2d(const Standard_Integer CuIndex, |
| 123 | const Standard_Real x, |
| 124 | const Standard_Real dx, |
| 125 | const Standard_Real y, |
| 126 | const Standard_Real dy) |
| 127 | { |
| 128 | if (Dimension(CuIndex) != 2) Standard_OutOfRange::Raise(); |
| 129 | |
| 130 | gp_Pnt2d P, newP; |
| 131 | P = Point2d(CuIndex); |
| 132 | newP.SetCoord(x + P.X()*dx, y + P.Y()*dy); |
| 133 | SetPoint2d(CuIndex, newP); |
| 134 | } |
| 135 | |
| 136 | |
| 137 | |
| 138 | |
| 139 | |
| 140 | void AppParCurves_MultiPoint::SetPoint (const Standard_Integer Index, |
| 141 | const gp_Pnt& Point) { |
| 142 | Standard_OutOfRange_Raise_if((Index <= 0) || (Index > nbP), ""); |
| 143 | tabPoint->SetValue(Index, Point); |
| 144 | } |
| 145 | |
| 146 | |
| 147 | const gp_Pnt& AppParCurves_MultiPoint::Point (const Standard_Integer Index) const |
| 148 | { |
| 149 | Standard_OutOfRange_Raise_if((Index <= 0) || (Index > nbP), ""); |
| 150 | return tabPoint->Value(Index); |
| 151 | } |
| 152 | |
| 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 | tabPoint2d->SetValue(Index-nbP, Point); |
| 160 | } |
| 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 | return tabPoint2d->Value(Index-nbP); |
| 167 | } |
| 168 | |
| 169 | |
| 170 | |
| 171 | |
| 172 | |
| 173 | void AppParCurves_MultiPoint::Dump(Standard_OStream& o) const |
| 174 | { |
| 175 | o << "AppParCurves_MultiPoint dump:" << endl; |
| 176 | o << "It contains " << NbPoints() << " 3d points and " << NbPoints2d() <<" 2d points." << endl; |
| 177 | /* |
| 178 | if (Dimension(i) == 3) { |
| 179 | for (Standard_Integer j = 1; j <= tabPoint->Length(); j++) { |
| 180 | o << " Pole No. " << j << ": " << endl; |
| 181 | o << " Pole x = " << (tabPoint->Value(i)->Point(j)).X() << endl; |
| 182 | o << " Pole y = " << (tabPoint->Value(i)->Point(j)).Y() << endl; |
| 183 | o << " Pole z = " << (tabPoint->Value(i)->Point(j)).Z() << endl; |
| 184 | } |
| 185 | } |
| 186 | else { |
| 187 | for (Standard_Integer j = 1; j <= tabPoint->Length(); j++) { |
| 188 | o << " Pole No. " << j << ": " << endl; |
| 189 | o << " Pole x = " << (tabPoint->Value(i)->Point2d(j)).X() << endl; |
| 190 | o << " Pole y = " << (tabPoint->Value(i)->Point2d(j)).Y() << endl; |
| 191 | } |
| 192 | */ |
| 193 | } |