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 INCLUDED_FILTER_SOURCE_GRAPHICFILTER_IDXF_DXFVEC_HXX
21 : #define INCLUDED_FILTER_SOURCE_GRAPHICFILTER_IDXF_DXFVEC_HXX
22 :
23 : #include <sal/types.h>
24 : #include <vcl/lineinfo.hxx>
25 :
26 : class Point;
27 :
28 : class DXFLineInfo {
29 : public:
30 : LineStyle eStyle;
31 : double fWidth;
32 : sal_Int32 nDashCount;
33 : double fDashLen;
34 : sal_Int32 nDotCount;
35 : double fDotLen;
36 : double fDistance;
37 :
38 0 : DXFLineInfo() :
39 : eStyle(LINE_SOLID),
40 : fWidth(0),
41 : nDashCount(0),
42 : fDashLen(0),
43 : nDotCount(0),
44 : fDotLen(0),
45 0 : fDistance(0) {}
46 :
47 : DXFLineInfo(const DXFLineInfo& x) :
48 : eStyle(x.eStyle),
49 : fWidth(x.fWidth),
50 : nDashCount(x.nDashCount),
51 : fDashLen(x.fDashLen),
52 : nDotCount(x.nDotCount),
53 : fDotLen(x.fDotLen),
54 : fDistance(x.fDistance) {}
55 :
56 : };
57 :
58 :
59 :
60 : //---------------------------- DXFVector ---------------------------------------
61 :
62 : // common 3D vector with doubles
63 :
64 : class DXFVector {
65 :
66 : public:
67 :
68 : double fx,fy,fz; // public ! - why not?
69 :
70 : inline DXFVector(double fX=0.0, double fY=0.0, double fZ=0.0);
71 : inline DXFVector(const DXFVector & rV);
72 :
73 : // summation/subtraktion:
74 : DXFVector & operator += (const DXFVector & rV);
75 : DXFVector operator + (const DXFVector & rV) const;
76 : DXFVector & operator -= (const DXFVector & rV);
77 : DXFVector operator - (const DXFVector & rV) const;
78 :
79 : // vector product
80 : DXFVector operator * (const DXFVector & rV) const;
81 :
82 : // skalar product:
83 : double SProd(const DXFVector & rV) const;
84 :
85 : // multiplication with scalar:
86 : DXFVector & operator *= (double fs);
87 : DXFVector operator * (double fs) const;
88 :
89 : // length:
90 : double Abs() const;
91 :
92 : // vector with same direction and a length of 1:
93 : DXFVector Unit() const;
94 :
95 : // equivalence or net:
96 : sal_Bool operator == (const DXFVector & rV) const;
97 : sal_Bool operator != (const DXFVector & rV) const;
98 : };
99 :
100 :
101 : //---------------------------- DXFTransform ------------------------------------
102 :
103 : // a transformation matrice specialized for our problem
104 :
105 : class DXFTransform {
106 :
107 : public:
108 :
109 : DXFTransform();
110 : // destination coordinate = source coordinate
111 :
112 : DXFTransform(double fScaleX, double fScaleY, double fScaleZ,
113 : const DXFVector & rShift);
114 : // dest coordinate = translate(scale(source coordinate))
115 :
116 : DXFTransform(double fScaleX, double fScaleY, double fScaleZ,
117 : double fRotAngle,
118 : const DXFVector & rShift);
119 : // dest coordinate = translate(rotate(scale(source coordinate)))
120 : // rotation around z-axis, fRotAngle in degrees.
121 :
122 : DXFTransform(const DXFVector & rExtrusion);
123 : // Transformation "ECS->WCS" via "Entity Extrusion Direction"
124 : // ant the "Arbitrary Axis Algorithm"
125 : // (See DXF-Docu from AutoDesk)
126 :
127 : DXFTransform(const DXFVector & rViewDir, const DXFVector & rViewTarget);
128 : // Transformation object space->picture space on the basis of direction
129 : // destination point of a viewport
130 : // (See DXF-Docu from AutoDesk: VPORT)
131 :
132 : DXFTransform(const DXFTransform & rT1, const DXFTransform & rT2);
133 : // destination coordinate = rT2(rT1(source coordinate))
134 :
135 :
136 : void Transform(const DXFVector & rSrc, DXFVector & rTgt) const;
137 : // Transformation from DXFVector to DXFVector
138 :
139 : void Transform(const DXFVector & rSrc, Point & rTgt) const;
140 : // Transformation from DXFVector to SvPoint
141 :
142 : void TransDir(const DXFVector & rSrc, DXFVector & rTgt) const;
143 : // Transformation of a relative vector (so no translation)
144 :
145 : sal_Bool TransCircleToEllipse(double fRadius, double & rEx, double & rEy) const;
146 : // Attemp to transform a circle (in xy plane) so that it results
147 : // in an aligned ellipse. If the does not work because a ellipse of
148 : // arbitrary position would be created, sal_False is returned.
149 : // (The center point will not be transformed, use Transform(..))
150 :
151 : sal_uInt32 TransLineWidth(double fW) const;
152 : // Transforms the thickness of a line (as good as possible)
153 :
154 : double CalcRotAngle() const;
155 : // Calculates the rotation angle around z-axis (in degrees)
156 :
157 : sal_Bool Mirror() const;
158 : // Returns sal_True, if the matrice represents a left-handed coordinate system
159 :
160 : LineInfo Transform(const DXFLineInfo& aDXFLineInfo) const;
161 : // Transform to LineInfo
162 :
163 : private:
164 : DXFVector aMX;
165 : DXFVector aMY;
166 : DXFVector aMZ;
167 : DXFVector aMP;
168 : };
169 :
170 :
171 : //------------------------------- inlines --------------------------------------
172 :
173 :
174 :
175 0 : inline DXFVector::DXFVector(double fX, double fY, double fZ)
176 : {
177 0 : fx=fX; fy=fY; fz=fZ;
178 0 : }
179 :
180 :
181 0 : inline DXFVector::DXFVector(const DXFVector & rV)
182 : {
183 0 : fx=rV.fx; fy=rV.fy; fz=rV.fz;
184 0 : }
185 :
186 :
187 0 : inline DXFVector & DXFVector::operator += (const DXFVector & rV)
188 : {
189 0 : fx+=rV.fx; fy+=rV.fy; fz+=rV.fz;
190 0 : return *this;
191 : }
192 :
193 :
194 0 : inline DXFVector DXFVector::operator + (const DXFVector & rV) const
195 : {
196 0 : return DXFVector(fx+rV.fx, fy+rV.fy, fz+rV.fz);
197 : }
198 :
199 :
200 : inline DXFVector & DXFVector::operator -= (const DXFVector & rV)
201 : {
202 : fx-=rV.fx; fy-=rV.fy; fz-=rV.fz;
203 : return *this;
204 : }
205 :
206 :
207 0 : inline DXFVector DXFVector::operator - (const DXFVector & rV) const
208 : {
209 0 : return DXFVector(fx-rV.fx, fy-rV.fy, fz-rV.fz);
210 : }
211 :
212 :
213 0 : inline DXFVector DXFVector::operator * (const DXFVector & rV) const
214 : {
215 : return DXFVector(
216 0 : fy * rV.fz - fz * rV.fy,
217 0 : fz * rV.fx - fx * rV.fz,
218 0 : fx * rV.fy - fy * rV.fx
219 0 : );
220 : }
221 :
222 :
223 0 : inline double DXFVector::SProd(const DXFVector & rV) const
224 : {
225 0 : return fx*rV.fx + fy*rV.fy + fz*rV.fz;
226 : }
227 :
228 :
229 0 : inline DXFVector & DXFVector::operator *= (double fs)
230 : {
231 0 : fx*=fs; fy*=fs; fz*=fs;
232 0 : return *this;
233 : }
234 :
235 :
236 0 : inline DXFVector DXFVector::operator * (double fs) const
237 : {
238 0 : return DXFVector(fx*fs,fy*fs,fz*fs);
239 : }
240 :
241 :
242 0 : inline sal_Bool DXFVector::operator == (const DXFVector & rV) const
243 : {
244 0 : if (fx==rV.fx && fy==rV.fy && fz==rV.fz) return sal_True;
245 0 : else return sal_False;
246 : }
247 :
248 :
249 : inline sal_Bool DXFVector::operator != (const DXFVector & rV) const
250 : {
251 : if (fx!=rV.fx || fy!=rV.fy || fz!=rV.fz) return sal_True;
252 : else return sal_False;
253 : }
254 :
255 : #endif
256 :
257 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|