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