LibreOffice Module svx (master) 1
polygn3d.cxx
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#include <polygn3d.hxx>
21#include <svx/svdobjkind.hxx>
26
27// DrawContact section
28std::unique_ptr<sdr::contact::ViewContact> E3dPolygonObj::CreateObjectSpecificViewContact()
29{
30 return std::make_unique<sdr::contact::ViewContactOfE3dPolygon>(*this);
31}
32
33E3dPolygonObj::E3dPolygonObj(SdrModel& rSdrModel, const basegfx::B3DPolyPolygon& rPolyPoly3D)
34 : E3dCompoundObject(rSdrModel)
35 , bLineOnly(true)
36{
37 // Set geometry
38 SetPolyPolygon3D(rPolyPoly3D);
39
40 // Create default normals
41 CreateDefaultNormals();
42
43 // Create default texture coordinates
44 CreateDefaultTexture();
45}
46
47E3dPolygonObj::E3dPolygonObj(SdrModel& rSdrModel)
48 : E3dCompoundObject(rSdrModel)
49 , bLineOnly(false)
50{
51 // Create no geometry
52}
53
54E3dPolygonObj::E3dPolygonObj(SdrModel& rSdrModel, E3dPolygonObj const& rSource)
55 : E3dCompoundObject(rSdrModel, rSource)
56 , bLineOnly(false)
57{
58 // Create no geometry
59
60 aPolyPoly3D = rSource.aPolyPoly3D;
61 aPolyNormals3D = rSource.aPolyNormals3D;
62 aPolyTexture2D = rSource.aPolyTexture2D;
63 bLineOnly = rSource.bLineOnly;
64}
65
66void E3dPolygonObj::CreateDefaultNormals()
67{
68 basegfx::B3DPolyPolygon aPolyNormals;
69
70 // Create a complete tools::PolyPolygon with the plane normal
71 for (sal_uInt32 a(0); a < aPolyPoly3D.count(); a++)
72 {
73 // Find source polygon
74 const basegfx::B3DPolygon aPolygon(aPolyPoly3D.getB3DPolygon(a));
75
76 // Creating a new polygon for the normal
77 basegfx::B3DPolygon aNormals;
78
79 // Get normal (and invert)
80 basegfx::B3DVector aNormal(-aPolygon.getNormal());
81
82 // Fill new polygon
83 for (sal_uInt32 b(0); b < aPolygon.count(); b++)
84 {
85 aNormals.append(aNormal);
86 }
87
88 // Insert new polygon into the PolyPolygon
89 aPolyNormals.append(aNormals);
90 }
91
92 // Set default normal
93 SetPolyNormals3D(aPolyNormals);
94}
95
96void E3dPolygonObj::CreateDefaultTexture()
97{
98 basegfx::B2DPolyPolygon aPolyTexture;
99 // Create a complete tools::PolyPolygon with the texture coordinates
100 // The texture coordinates extend over X,Y and Z
101 // on the whole extreme values in the range 0.0 .. 1.0
102 for (sal_uInt32 a(0); a < aPolyPoly3D.count(); a++)
103 {
104 // Find source polygon
105 const basegfx::B3DPolygon& aPolygon(aPolyPoly3D.getB3DPolygon(a));
106
107 // Determine the total size of the object
109
110 // Get normal
111 basegfx::B3DVector aNormal(aPolygon.getNormal());
112 aNormal.setX(fabs(aNormal.getX()));
113 aNormal.setY(fabs(aNormal.getY()));
114 aNormal.setZ(fabs(aNormal.getZ()));
115
116 // Decide which coordinates should be used as a source for the mapping
117 sal_uInt16 nSourceMode = 0;
118
119 // Determine the greatest degree of freedom
120 if (aNormal.getX() <= aNormal.getY() || aNormal.getX() <= aNormal.getZ())
121 {
122 if (aNormal.getY() > aNormal.getZ())
123 {
124 // Y is the largest, use X,Z as mapping
125 nSourceMode = 1;
126 }
127 else
128 {
129 // Z is the largest, use X,Y as mapping
130 nSourceMode = 2;
131 }
132 }
133
134 // Create new polygon for texture coordinates
135 basegfx::B2DPolygon aTexture;
136
137 // Fill new polygon
138 for (sal_uInt32 b(0); b < aPolygon.count(); b++)
139 {
141 const basegfx::B3DPoint aCandidate(aPolygon.getB3DPoint(b));
142
143 switch (nSourceMode)
144 {
145 case 0: //Source is Y,Z
146 if (aVolume.getHeight())
147 aTex.setX((aCandidate.getY() - aVolume.getMinY()) / aVolume.getHeight());
148 if (aVolume.getDepth())
149 aTex.setY((aCandidate.getZ() - aVolume.getMinZ()) / aVolume.getDepth());
150 break;
151
152 case 1: // Source is X,Z
153 if (aVolume.getWidth())
154 aTex.setX((aCandidate.getX() - aVolume.getMinX()) / aVolume.getWidth());
155 if (aVolume.getDepth())
156 aTex.setY((aCandidate.getZ() - aVolume.getMinZ()) / aVolume.getDepth());
157 break;
158
159 case 2: // Source is X,Y
160 if (aVolume.getWidth())
161 aTex.setX((aCandidate.getX() - aVolume.getMinX()) / aVolume.getWidth());
162 if (aVolume.getHeight())
163 aTex.setY((aCandidate.getY() - aVolume.getMinY()) / aVolume.getHeight());
164 break;
165 }
166
167 aTexture.append(aTex);
168 }
169
170 // Insert new polygon into the PolyPolygon
171 aPolyTexture.append(aTexture);
172 }
173
174 // Set default Texture coordinates
175 SetPolyTexture2D(aPolyTexture);
176}
177
178E3dPolygonObj::~E3dPolygonObj() {}
179
180SdrObjKind E3dPolygonObj::GetObjIdentifier() const { return SdrObjKind::E3D_Polygon; }
181
182void E3dPolygonObj::SetPolyPolygon3D(const basegfx::B3DPolyPolygon& rNewPolyPoly3D)
183{
184 if (aPolyPoly3D != rNewPolyPoly3D)
185 {
186 // New PolyPolygon; copying
187 aPolyPoly3D = rNewPolyPoly3D;
188
189 // Create new geometry
190 ActionChanged();
191 }
192}
193
194void E3dPolygonObj::SetPolyNormals3D(const basegfx::B3DPolyPolygon& rNewPolyNormals3D)
195{
196 if (aPolyNormals3D != rNewPolyNormals3D)
197 {
198 // New PolyPolygon; copying
199 aPolyNormals3D = rNewPolyNormals3D;
200
201 // Create new geometry
202 ActionChanged();
203 }
204}
205
206void E3dPolygonObj::SetPolyTexture2D(const basegfx::B2DPolyPolygon& rNewPolyTexture2D)
207{
208 if (aPolyTexture2D != rNewPolyTexture2D)
209 {
210 // New PolyPolygon; copying
211 aPolyTexture2D = rNewPolyTexture2D;
212
213 // Create new geometry
214 ActionChanged();
215 }
216}
217
218// Convert the object into a group object consisting of 6 polygons
219
220SdrObjectUniquePtr E3dPolygonObj::DoConvertToPolyObj(bool /*bBezier*/, bool /*bAddText*/) const
221{
222 return nullptr;
223}
224
225E3dPolygonObj* E3dPolygonObj::CloneSdrObject(SdrModel& rTargetModel) const
226{
227 return new E3dPolygonObj(rTargetModel, *this);
228}
229
230void E3dPolygonObj::SetLineOnly(bool bNew)
231{
232 if (bNew != bLineOnly)
233 {
234 bLineOnly = bNew;
235 ActionChanged();
236 }
237}
238
239/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void append(const B2DPolygon &rPolygon, sal_uInt32 nCount=1)
void append(const basegfx::B2DPoint &rPoint, sal_uInt32 nCount)
void append(const B3DPolygon &rPolygon, sal_uInt32 nCount=1)
void append(const B3DPoint &rPoint, sal_uInt32 nCount=1)
void setY(TYPE fY)
void setX(TYPE fX)
uno_Any a
B2DRange getRange(const B2DPolygon &rCandidate)
std::unique_ptr< SdrObject, SdrObjectFreeOp > SdrObjectUniquePtr
Definition: svdobj.hxx:98
SdrObjKind
Definition: svdobjkind.hxx:25