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