1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: dxfvec.hxx,v $
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 ************************************************************************/
34 #include <tools/gen.hxx>
35 #include <vcl/lineinfo.hxx>
56 DXFLineInfo(const DXFLineInfo
& x
) :
59 nDashCount(x
.nDashCount
),
61 nDotCount(x
.nDotCount
),
63 fDistance(x
.fDistance
) {}
68 //------------------------------------------------------------------------------
69 //---------------------------- DXFVector ---------------------------------------
70 //------------------------------------------------------------------------------
71 // Allgemeiner 3D-Vektor mit double
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;
89 DXFVector
operator * (const DXFVector
& rV
) const;
92 double SProd(const DXFVector
& rV
) const;
94 // Multiplikation mit Skalar:
95 DXFVector
& operator *= (double fs
);
96 DXFVector
operator * (double fs
) 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
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
,
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)
167 // Liefert TRUE, wenn die Matrix ein Linkssystem bildet
169 LineInfo
Transform(const DXFLineInfo
& aDXFLineInfo
) const;
170 // Transform to LineInfo
179 //------------------------------------------------------------------------------
180 //------------------------------- inlines --------------------------------------
181 //------------------------------------------------------------------------------
184 inline DXFVector::DXFVector(double fX
, double fY
, double 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
;
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
;
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
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
;
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
;
258 inline BOOL
DXFVector::operator != (const DXFVector
& rV
) const
260 if (fx
!=rV
.fx
|| fy
!=rV
.fy
|| fz
!=rV
.fz
) return TRUE
;