1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 #ifndef _DXFVEC_HXX
25 #define _DXFVEC_HXX
26
27 #include <tools/gen.hxx>
28 #include <vcl/lineinfo.hxx>
29
30 class DXFLineInfo {
31 public:
32 LineStyle eStyle;
33 double fWidth;
34 sal_Int32 nDashCount;
35 double fDashLen;
36 sal_Int32 nDotCount;
37 double fDotLen;
38 double fDistance;
39
DXFLineInfo()40 DXFLineInfo() :
41 eStyle(LINE_SOLID),
42 fWidth(0),
43 nDashCount(0),
44 fDashLen(0),
45 nDotCount(0),
46 fDotLen(0),
47 fDistance(0) {}
48
DXFLineInfo(const DXFLineInfo & x)49 DXFLineInfo(const DXFLineInfo& x) :
50 eStyle(x.eStyle),
51 fWidth(x.fWidth),
52 nDashCount(x.nDashCount),
53 fDashLen(x.fDashLen),
54 nDotCount(x.nDotCount),
55 fDotLen(x.fDotLen),
56 fDistance(x.fDistance) {}
57
58 };
59
60
61 //------------------------------------------------------------------------------
62 //---------------------------- DXFVector ---------------------------------------
63 //------------------------------------------------------------------------------
64 // Allgemeiner 3D-Vektor mit double
65
66 class DXFVector {
67
68 public:
69
70 double fx,fy,fz; // public ! - Warum nicht ?
71
72 inline DXFVector(double fX=0.0, double fY=0.0, double fZ=0.0);
73 inline DXFVector(const DXFVector & rV);
74
75 // Addition/Subtraktion:
76 DXFVector & operator += (const DXFVector & rV);
77 DXFVector operator + (const DXFVector & rV) const;
78 DXFVector & operator -= (const DXFVector & rV);
79 DXFVector operator - (const DXFVector & rV) const;
80
81 // Vektorprodukt
82 DXFVector operator * (const DXFVector & rV) const;
83
84 // Skalarprodukt:
85 double SProd(const DXFVector & rV) const;
86
87 // Multiplikation mit Skalar:
88 DXFVector & operator *= (double fs);
89 DXFVector operator * (double fs) const;
90
91 // Laenge:
92 double Abs() const;
93
94 // Vektor gleicher Richtung und der Laenge 1:
95 DXFVector Unit() const;
96
97 // Aequivalenz oder nicht:
98 sal_Bool operator == (const DXFVector & rV) const;
99 sal_Bool operator != (const DXFVector & rV) const;
100 };
101
102 //------------------------------------------------------------------------------
103 //---------------------------- DXFTransform ------------------------------------
104 //------------------------------------------------------------------------------
105 // Eine Transformationsmatrix, spezialisiert auf unser Problem
106
107 class DXFTransform {
108
109 public:
110
111 DXFTransform();
112 // Zielkoordinate = Quellkoordinate
113
114 DXFTransform(double fScaleX, double fScaleY, double fScaleZ,
115 const DXFVector & rShift);
116 // Zielkoordinate = Verschoben(Skaliert(Quellkoorinate))
117
118 DXFTransform(double fScaleX, double fScaleY, double fScaleZ,
119 double fRotAngle,
120 const DXFVector & rShift);
121 // Zielkoordinate = Verschoben(Gedreht(Skaliert(Quellkoorinate)))
122 // Drehung geshieht um die Z-Achse, fRotAngle in Grad.
123
124 DXFTransform(const DXFVector & rExtrusion);
125 // Transformation "ECS->WCS" per "Entity Extrusion Direction"
126 // und dem "Arbitrary Axis Algorithm"
127 // (Siehe DXF-Docu von AutoDesk)
128
129 DXFTransform(const DXFVector & rViewDir, const DXFVector & rViewTarget);
130 // Transformation Objektraum->Bildraum anhand von Richtung und
131 // Zielpunkt eines ViewPort.
132 // (siehe DXF-Docu von AutoDesk: VPORT)
133
134 DXFTransform(const DXFTransform & rT1, const DXFTransform & rT2);
135 // Zielkoordinate = rT2(rT1(Quellkoorinate))
136
137
138 void Transform(const DXFVector & rSrc, DXFVector & rTgt) const;
139 // Transformation DXFVector nach DXFVector
140
141 void Transform(const DXFVector & rSrc, Point & rTgt) const;
142 // Transformation DXFVector nach SvPoint
143
144 void TransDir(const DXFVector & rSrc, DXFVector & rTgt) const;
145 // Transformation eines relativen Vektors (also kein Verschiebung)
146
147 sal_Bool TransCircleToEllipse(double fRadius, double & rEx, double & rEy) const;
148 // Versucht, einen Kreis (in der XY-Ebene) zu transformieren, so dass eine
149 // ausgerichtete Ellipse entsteht. Wenn das nicht geht, weil Ellipse
150 // in belibieger Lage entstehen wuerde, wird sal_False geliefert.
151 // (Der Mittelpunkt wird hiermit nicht transformiert, nehme Transform(..))
152
153 sal_uLong TransLineWidth(double fW) const;
154 // Transformiert die Liniendicke (so gut es geht)
155
156 double CalcRotAngle() const;
157 // Ermittelt den Rotationswinkel um die Z-Achse (in Grad)
158
159 sal_Bool Mirror() const;
160 // Liefert sal_True, wenn die Matrix ein Linkssystem bildet
161
162 LineInfo Transform(const DXFLineInfo& aDXFLineInfo) const;
163 // Transform to LineInfo
164
165 private:
166 DXFVector aMX;
167 DXFVector aMY;
168 DXFVector aMZ;
169 DXFVector aMP;
170 };
171
172 //------------------------------------------------------------------------------
173 //------------------------------- inlines --------------------------------------
174 //------------------------------------------------------------------------------
175
176
DXFVector(double fX,double fY,double fZ)177 inline DXFVector::DXFVector(double fX, double fY, double fZ)
178 {
179 fx=fX; fy=fY; fz=fZ;
180 }
181
182
DXFVector(const DXFVector & rV)183 inline DXFVector::DXFVector(const DXFVector & rV)
184 {
185 fx=rV.fx; fy=rV.fy; fz=rV.fz;
186 }
187
188
operator +=(const DXFVector & rV)189 inline DXFVector & DXFVector::operator += (const DXFVector & rV)
190 {
191 fx+=rV.fx; fy+=rV.fy; fz+=rV.fz;
192 return *this;
193 }
194
195
operator +(const DXFVector & rV) const196 inline DXFVector DXFVector::operator + (const DXFVector & rV) const
197 {
198 return DXFVector(fx+rV.fx, fy+rV.fy, fz+rV.fz);
199 }
200
201
operator -=(const DXFVector & rV)202 inline DXFVector & DXFVector::operator -= (const DXFVector & rV)
203 {
204 fx-=rV.fx; fy-=rV.fy; fz-=rV.fz;
205 return *this;
206 }
207
208
operator -(const DXFVector & rV) const209 inline DXFVector DXFVector::operator - (const DXFVector & rV) const
210 {
211 return DXFVector(fx-rV.fx, fy-rV.fy, fz-rV.fz);
212 }
213
214
operator *(const DXFVector & rV) const215 inline DXFVector DXFVector::operator * (const DXFVector & rV) const
216 {
217 return DXFVector(
218 fy * rV.fz - fz * rV.fy,
219 fz * rV.fx - fx * rV.fz,
220 fx * rV.fy - fy * rV.fx
221 );
222 }
223
224
SProd(const DXFVector & rV) const225 inline double DXFVector::SProd(const DXFVector & rV) const
226 {
227 return fx*rV.fx + fy*rV.fy + fz*rV.fz;
228 }
229
230
operator *=(double fs)231 inline DXFVector & DXFVector::operator *= (double fs)
232 {
233 fx*=fs; fy*=fs; fz*=fs;
234 return *this;
235 }
236
237
operator *(double fs) const238 inline DXFVector DXFVector::operator * (double fs) const
239 {
240 return DXFVector(fx*fs,fy*fs,fz*fs);
241 }
242
243
operator ==(const DXFVector & rV) const244 inline sal_Bool DXFVector::operator == (const DXFVector & rV) const
245 {
246 if (fx==rV.fx && fy==rV.fy && fz==rV.fz) return sal_True;
247 else return sal_False;
248 }
249
250
operator !=(const DXFVector & rV) const251 inline sal_Bool DXFVector::operator != (const DXFVector & rV) const
252 {
253 if (fx!=rV.fx || fy!=rV.fy || fz!=rV.fz) return sal_True;
254 else return sal_False;
255 }
256
257 #endif
258