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