Update ooo320-m1
[ooovba.git] / goodies / source / filter.vcl / idxf / dxfvec.hxx
blobf25a60387fb6567788c8eceda1c1fca16d834660
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: dxfvec.hxx,v $
10 * $Revision: 1.3 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef _DXFVEC_HXX
32 #define _DXFVEC_HXX
34 #include <tools/gen.hxx>
35 #include <vcl/lineinfo.hxx>
37 class DXFLineInfo {
38 public:
39 LineStyle eStyle;
40 double fWidth;
41 sal_Int32 nDashCount;
42 double fDashLen;
43 sal_Int32 nDotCount;
44 double fDotLen;
45 double fDistance;
47 DXFLineInfo() :
48 eStyle(LINE_SOLID),
49 fWidth(0),
50 nDashCount(0),
51 fDashLen(0),
52 nDotCount(0),
53 fDotLen(0),
54 fDistance(0) {}
56 DXFLineInfo(const DXFLineInfo& x) :
57 eStyle(x.eStyle),
58 fWidth(x.fWidth),
59 nDashCount(x.nDashCount),
60 fDashLen(x.fDashLen),
61 nDotCount(x.nDotCount),
62 fDotLen(x.fDotLen),
63 fDistance(x.fDistance) {}
68 //------------------------------------------------------------------------------
69 //---------------------------- DXFVector ---------------------------------------
70 //------------------------------------------------------------------------------
71 // Allgemeiner 3D-Vektor mit double
73 class DXFVector {
75 public:
77 double fx,fy,fz; // public ! - Warum nicht ?
79 inline DXFVector(double fX=0.0, double fY=0.0, double fZ=0.0);
80 inline DXFVector(const DXFVector & rV);
82 // Addition/Subtraktion:
83 DXFVector & operator += (const DXFVector & rV);
84 DXFVector operator + (const DXFVector & rV) const;
85 DXFVector & operator -= (const DXFVector & rV);
86 DXFVector operator - (const DXFVector & rV) const;
88 // Vektorprodukt
89 DXFVector operator * (const DXFVector & rV) const;
91 // Skalarprodukt:
92 double SProd(const DXFVector & rV) const;
94 // Multiplikation mit Skalar:
95 DXFVector & operator *= (double fs);
96 DXFVector operator * (double fs) const;
98 // Laenge:
99 double Abs() const;
101 // Vektor gleicher Richtung und der Laenge 1:
102 DXFVector Unit() const;
104 // Aequivalenz oder nicht:
105 BOOL operator == (const DXFVector & rV) const;
106 BOOL operator != (const DXFVector & rV) const;
109 //------------------------------------------------------------------------------
110 //---------------------------- DXFTransform ------------------------------------
111 //------------------------------------------------------------------------------
112 // Eine Transformationsmatrix, spezialisiert auf unser Problem
114 class DXFTransform {
116 public:
118 DXFTransform();
119 // Zielkoordinate = Quellkoordinate
121 DXFTransform(double fScaleX, double fScaleY, double fScaleZ,
122 const DXFVector & rShift);
123 // Zielkoordinate = Verschoben(Skaliert(Quellkoorinate))
125 DXFTransform(double fScaleX, double fScaleY, double fScaleZ,
126 double fRotAngle,
127 const DXFVector & rShift);
128 // Zielkoordinate = Verschoben(Gedreht(Skaliert(Quellkoorinate)))
129 // Drehung geshieht um die Z-Achse, fRotAngle in Grad.
131 DXFTransform(const DXFVector & rExtrusion);
132 // Transformation "ECS->WCS" per "Entity Extrusion Direction"
133 // und dem "Arbitrary Axis Algorithm"
134 // (Siehe DXF-Docu von AutoDesk)
136 DXFTransform(const DXFVector & rViewDir, const DXFVector & rViewTarget);
137 // Transformation Objektraum->Bildraum anhand von Richtung und
138 // Zielpunkt eines ViewPort.
139 // (siehe DXF-Docu von AutoDesk: VPORT)
141 DXFTransform(const DXFTransform & rT1, const DXFTransform & rT2);
142 // Zielkoordinate = rT2(rT1(Quellkoorinate))
145 void Transform(const DXFVector & rSrc, DXFVector & rTgt) const;
146 // Transformation DXFVector nach DXFVector
148 void Transform(const DXFVector & rSrc, Point & rTgt) const;
149 // Transformation DXFVector nach SvPoint
151 void TransDir(const DXFVector & rSrc, DXFVector & rTgt) const;
152 // Transformation eines relativen Vektors (also kein Verschiebung)
154 BOOL TransCircleToEllipse(double fRadius, double & rEx, double & rEy) const;
155 // Versucht, einen Kreis (in der XY-Ebene) zu transformieren, so dass eine
156 // ausgerichtete Ellipse entsteht. Wenn das nicht geht, weil Ellipse
157 // in belibieger Lage entstehen wuerde, wird FALSE geliefert.
158 // (Der Mittelpunkt wird hiermit nicht transformiert, nehme Transform(..))
160 ULONG TransLineWidth(double fW) const;
161 // Transformiert die Liniendicke (so gut es geht)
163 double CalcRotAngle() const;
164 // Ermittelt den Rotationswinkel um die Z-Achse (in Grad)
166 BOOL Mirror() const;
167 // Liefert TRUE, wenn die Matrix ein Linkssystem bildet
169 LineInfo Transform(const DXFLineInfo& aDXFLineInfo) const;
170 // Transform to LineInfo
172 private:
173 DXFVector aMX;
174 DXFVector aMY;
175 DXFVector aMZ;
176 DXFVector aMP;
179 //------------------------------------------------------------------------------
180 //------------------------------- inlines --------------------------------------
181 //------------------------------------------------------------------------------
184 inline DXFVector::DXFVector(double fX, double fY, double fZ)
186 fx=fX; fy=fY; fz=fZ;
190 inline DXFVector::DXFVector(const DXFVector & rV)
192 fx=rV.fx; fy=rV.fy; fz=rV.fz;
196 inline DXFVector & DXFVector::operator += (const DXFVector & rV)
198 fx+=rV.fx; fy+=rV.fy; fz+=rV.fz;
199 return *this;
203 inline DXFVector DXFVector::operator + (const DXFVector & rV) const
205 return DXFVector(fx+rV.fx, fy+rV.fy, fz+rV.fz);
209 inline DXFVector & DXFVector::operator -= (const DXFVector & rV)
211 fx-=rV.fx; fy-=rV.fy; fz-=rV.fz;
212 return *this;
216 inline DXFVector DXFVector::operator - (const DXFVector & rV) const
218 return DXFVector(fx-rV.fx, fy-rV.fy, fz-rV.fz);
222 inline DXFVector DXFVector::operator * (const DXFVector & rV) const
224 return DXFVector(
225 fy * rV.fz - fz * rV.fy,
226 fz * rV.fx - fx * rV.fz,
227 fx * rV.fy - fy * rV.fx
232 inline double DXFVector::SProd(const DXFVector & rV) const
234 return fx*rV.fx + fy*rV.fy + fz*rV.fz;
238 inline DXFVector & DXFVector::operator *= (double fs)
240 fx*=fs; fy*=fs; fz*=fs;
241 return *this;
245 inline DXFVector DXFVector::operator * (double fs) const
247 return DXFVector(fx*fs,fy*fs,fz*fs);
251 inline BOOL DXFVector::operator == (const DXFVector & rV) const
253 if (fx==rV.fx && fy==rV.fy && fz==rV.fz) return TRUE;
254 else return FALSE;
258 inline BOOL DXFVector::operator != (const DXFVector & rV) const
260 if (fx!=rV.fx || fy!=rV.fy || fz!=rV.fz) return TRUE;
261 else return FALSE;
264 #endif