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