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