1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_SVX_OBJ3D_HXX
21 #define INCLUDED_SVX_OBJ3D_HXX
23 #include <svx/svdoattr.hxx>
24 #include <svx/svdobj.hxx>
25 #include <svx/def3d.hxx>
26 #include <svx/svdpage.hxx>
27 #include <svx/deflt3d.hxx>
28 #include <vcl/bitmap.hxx>
29 #include <svx/svx3ditems.hxx>
30 #include <svx/xflclit.hxx>
31 #include <svl/itemset.hxx>
32 #include <basegfx/range/b3drange.hxx>
33 #include <basegfx/polygon/b3dpolypolygon.hxx>
34 #include <basegfx/point/b2dpoint.hxx>
35 #include <basegfx/polygon/b2dpolygon.hxx>
36 #include <basegfx/vector/b2enums.hxx>
37 #include <svx/svxdllapi.h>
40 // Forward declaration
48 namespace basegfx
{ class B3DPolyPolygon
; }
49 namespace sdr
{ namespace properties
{
52 class E3dCompoundProperties
;
53 class E3dExtrudeProperties
;
54 class E3dLatheProperties
;
55 class E3dSphereProperties
;
58 /*************************************************************************
60 |* GeoData relevant for undo actions
62 \************************************************************************/
64 class E3DObjGeoData
: public SdrObjGeoData
67 basegfx::B3DRange maLocalBoundVol
; // surrounding volume of the object
68 basegfx::B3DHomMatrix maTransformation
; // lokal transformations
73 /*************************************************************************
75 |* List for 3D objects
77 \************************************************************************/
79 class E3dObjList
: public SdrObjList
81 E3dObjList
&operator=(const E3dObjList
& rSrcList
) SAL_DELETED_FUNCTION
;
85 E3dObjList(SdrModel
* pNewModel
= 0, SdrPage
* pNewPage
= 0, E3dObjList
* pNewUpList
= 0);
86 SVX_DLLPUBLIC
virtual ~E3dObjList();
88 virtual E3dObjList
* Clone() const SAL_OVERRIDE
;
90 virtual void NbcInsertObject(SdrObject
* pObj
, size_t nPos
=SAL_MAX_SIZE
, const SdrInsertReason
* pReason
=NULL
) SAL_OVERRIDE
;
91 virtual void InsertObject(SdrObject
* pObj
, size_t nPos
=SAL_MAX_SIZE
, const SdrInsertReason
* pReason
=NULL
) SAL_OVERRIDE
;
92 virtual SdrObject
* NbcRemoveObject(size_t nObjNum
) SAL_OVERRIDE
;
93 virtual SdrObject
* RemoveObject(size_t nObjNum
) SAL_OVERRIDE
;
96 SVX_DLLPUBLIC
E3dObjList(const E3dObjList
& rSrcList
);
99 /*************************************************************************
101 |* Base class for 3D objects
103 \************************************************************************/
105 class SVX_DLLPUBLIC E3dObject
: public SdrAttrObj
108 // to allow sdr::properties::E3dProperties access to StructureChanged()
109 friend class sdr::properties::E3dProperties
;
111 // Allow everything for E3dObjList and E3dDragMethod
112 friend class E3dObjList
;
113 friend class E3dDragMethod
;
116 virtual sdr::properties::BaseProperties
* CreateObjectSpecificProperties() SAL_OVERRIDE
;
118 E3dObjList maSubList
; // child objects
120 basegfx::B3DRange maLocalBoundVol
; // surrounding volume of the object (from the geometry generation)
121 basegfx::B3DHomMatrix maTransformation
; // local transformation
122 basegfx::B3DHomMatrix maFullTransform
; // global transformation (including. parents)
125 bool mbTfHasChanged
: 1;
126 bool mbIsSelected
: 1;
129 void SetBoundVolInvalid();
132 void SetTransformChanged();
133 virtual void NewObjectInserted(const E3dObject
* p3DObj
);
134 virtual void StructureChanged();
135 basegfx::B3DRange
RecalcBoundVolume() const;
138 // E3dObject is only a helper class (for E3DScene and E3DCompoundObject)
139 // and no instances should be created from anyone, so i move the constructors
142 E3dObject(bool bIsFromChart
);
146 virtual void RecalcSnapRect() SAL_OVERRIDE
;
147 virtual void SetRectsDirty(bool bNotMyself
= false) SAL_OVERRIDE
;
149 virtual ~E3dObject();
151 virtual sal_uInt32
GetObjInventor() const SAL_OVERRIDE
;
152 virtual sal_uInt16
GetObjIdentifier() const SAL_OVERRIDE
;
154 virtual void TakeObjInfo(SdrObjTransformInfoRec
& rInfo
) const SAL_OVERRIDE
;
156 virtual void NbcSetLayer(SdrLayerID nLayer
) SAL_OVERRIDE
;
158 virtual void SetObjList(SdrObjList
* pNewObjList
) SAL_OVERRIDE
;
159 virtual void SetPage(SdrPage
* pNewPage
) SAL_OVERRIDE
;
160 virtual void SetModel(SdrModel
* pNewModel
) SAL_OVERRIDE
;
161 virtual void NbcMove(const Size
& rSize
) SAL_OVERRIDE
;
162 virtual void NbcResize(const Point
& rRef
, const Fraction
& xFact
, const Fraction
& yFact
) SAL_OVERRIDE
;
163 virtual SdrObjList
* GetSubList() const SAL_OVERRIDE
;
165 // Insert 3D object into the group; transfer to other owner!
166 void Insert3DObj(E3dObject
* p3DObj
);
167 void Remove3DObj(E3dObject
* p3DObj
);
169 E3dObject
* GetParentObj() const;
170 virtual E3dScene
* GetScene() const;
172 const basegfx::B3DRange
& GetBoundVolume() const;
173 void InvalidateBoundVolume();
175 // calculate complete transformation including all parents
176 const basegfx::B3DHomMatrix
& GetFullTransform() const;
178 // get and (re)set transformation matrix
179 const basegfx::B3DHomMatrix
& GetTransform() const { return maTransformation
;}
180 virtual void NbcSetTransform(const basegfx::B3DHomMatrix
& rMatrix
);
181 virtual void SetTransform(const basegfx::B3DHomMatrix
& rMatrix
);
183 // 2D rotations, are implemented as a rotation around the Z axis
184 // which is vertical to the screen, plus a shift of the scene.
185 // This means that also the scene (E3dScene) must define this
186 // routine as virtual in its class.
187 virtual void NbcRotate(const Point
& rRef
, long nAngle
, double sn
, double cs
) SAL_OVERRIDE
;
189 // get wireframe polygon for local object. No transform is applied.
190 basegfx::B3DPolyPolygon
CreateWireframe() const;
192 // TakeObjName...() is for the display in the UI, for example "3 frames selected".
193 virtual OUString
TakeObjNameSingul() const SAL_OVERRIDE
;
194 virtual OUString
TakeObjNamePlural() const SAL_OVERRIDE
;
195 virtual E3dObject
* Clone() const SAL_OVERRIDE
;
196 E3dObject
& operator=( const E3dObject
& rObj
);
198 virtual SdrObjGeoData
*NewGeoData() const SAL_OVERRIDE
;
199 virtual void SaveGeoData(SdrObjGeoData
& rGeo
) const SAL_OVERRIDE
;
200 virtual void RestGeoData(const SdrObjGeoData
& rGeo
) SAL_OVERRIDE
;
202 // get/set the selection
203 bool GetSelected() const { return mbIsSelected
; }
204 void SetSelected(bool bNew
);
207 virtual bool IsBreakObjPossible();
208 virtual SdrAttrObj
* GetBreakObj();
211 /*************************************************************************
213 |* Class for all compound objects (Cube, Lathe, Scene, Extrude)
214 |* This class saves some ISA queries and accelerates the behaviour
215 |* significantly, because all the attributes etc. are kept through this.
216 |* The polygons may only keep attributes if they are directly
217 |* subordinated to the scene.
219 \************************************************************************/
221 class SVX_DLLPUBLIC E3dCompoundObject
: public E3dObject
224 // to allow sdr::properties::E3dCompoundProperties access to SetGeometryValid()
225 friend class sdr::properties::E3dCompoundProperties
;
226 friend class sdr::properties::E3dExtrudeProperties
;
227 friend class sdr::properties::E3dLatheProperties
;
228 friend class sdr::properties::E3dSphereProperties
;
231 virtual sdr::properties::BaseProperties
* CreateObjectSpecificProperties() SAL_OVERRIDE
;
233 // material of the object
234 Color aMaterialAmbientColor
;
236 // attributes for geometry creation
237 bool bCreateNormals
: 1;
238 bool bCreateTexture
: 1;
241 void SetDefaultAttributes(E3dDefaultAttributes
& rDefault
);
243 // convert given basegfx::B3DPolyPolygon to screen coor
244 basegfx::B2DPolyPolygon
TransformToScreenCoor(const basegfx::B3DPolyPolygon
& rCandidate
);
250 E3dCompoundObject(E3dDefaultAttributes
& rDefault
);
251 virtual ~E3dCompoundObject();
253 virtual basegfx::B2DPolyPolygon
TakeXorPoly() const SAL_OVERRIDE
;
254 virtual sal_uInt32
GetHdlCount() const SAL_OVERRIDE
;
255 virtual void AddToHdlList(SdrHdlList
& rHdlList
) const SAL_OVERRIDE
;
257 // DoubleSided: sal_True/FALSE
258 bool GetDoubleSided() const
259 { return static_cast<const SfxBoolItem
&>(GetObjectItemSet().Get(SDRATTR_3DOBJ_DOUBLE_SIDED
)).GetValue(); }
261 // NormalsKind: 0 == sal_False/sal_False, 1 == sal_True/sal_False, else == sal_True/TRUE
262 sal_uInt16
GetNormalsKind() const
263 { return static_cast<const Svx3DNormalsKindItem
&>(GetObjectItemSet().Get(SDRATTR_3DOBJ_NORMALS_KIND
)).GetValue(); }
265 // NormalsInvert: sal_True/FALSE
266 bool GetNormalsInvert() const
267 { return static_cast<const SfxBoolItem
&>(GetObjectItemSet().Get(SDRATTR_3DOBJ_NORMALS_INVERT
)).GetValue(); }
269 // TextureProjX: 0 == sal_False/sal_False, 1 == sal_True/sal_False, else == sal_True/TRUE
270 sal_uInt16
GetTextureProjectionX() const
271 { return static_cast<const Svx3DTextureProjectionXItem
&>(GetObjectItemSet().Get(SDRATTR_3DOBJ_TEXTURE_PROJ_X
)).GetValue(); }
273 // TextureProjY: 0 == sal_False/sal_False, 1 == sal_True/sal_False, else == sal_True/TRUE
274 sal_uInt16
GetTextureProjectionY() const
275 { return static_cast<const Svx3DTextureProjectionYItem
&>(GetObjectItemSet().Get(SDRATTR_3DOBJ_TEXTURE_PROJ_Y
)).GetValue(); }
277 // Shadow3D: sal_True/FALSE
278 bool GetShadow3D() const
279 { return static_cast<const SfxBoolItem
&>(GetObjectItemSet().Get(SDRATTR_3DOBJ_SHADOW_3D
)).GetValue(); }
281 // MaterialColor: Color
282 Color
GetMaterialColor() const
283 { return static_cast<const SvxColorItem
&>(GetObjectItemSet().Get(SDRATTR_3DOBJ_MAT_COLOR
)).GetValue(); }
285 // MaterialEmission: Color
286 Color
GetMaterialEmission() const
287 { return static_cast<const SvxColorItem
&>(GetObjectItemSet().Get(SDRATTR_3DOBJ_MAT_EMISSION
)).GetValue(); }
289 // MaterialSpecular: Color
290 Color
GetMaterialSpecular() const
291 { return static_cast<const SvxColorItem
&>(GetObjectItemSet().Get(SDRATTR_3DOBJ_MAT_SPECULAR
)).GetValue(); }
293 // MaterialSpecularIntensity:
294 sal_uInt16
GetMaterialSpecularIntensity() const
295 { return static_cast<const SfxUInt16Item
&>(GetObjectItemSet().Get(SDRATTR_3DOBJ_MAT_SPECULAR_INTENSITY
)).GetValue(); }
297 // TextureFilter: sal_True/FALSE
298 bool GetTextureFilter() const
299 { return static_cast<const SfxBoolItem
&>(GetObjectItemSet().Get(SDRATTR_3DOBJ_TEXTURE_FILTER
)).GetValue(); }
302 // Added extra Item (Bool) for chart2 to be able to show reduced line geometry
303 bool GetReducedLineGeometry() const
304 { return static_cast<const Svx3DReducedLineGeometryItem
&>(GetObjectItemSet().Get(SDRATTR_3DOBJ_REDUCED_LINE_GEOMETRY
)).GetValue(); }
306 virtual sal_uInt16
GetObjIdentifier() const SAL_OVERRIDE
;
307 virtual void RecalcSnapRect() SAL_OVERRIDE
;
309 // set/get parameters for geometry creation
310 bool GetCreateNormals() const { return bCreateNormals
; }
312 bool GetCreateTexture() const { return bCreateTexture
; }
314 virtual E3dCompoundObject
* Clone() const SAL_OVERRIDE
;
316 // material of the object
317 const Color
& GetMaterialAmbientColor() const { return aMaterialAmbientColor
; }
319 bool IsAOrdNumRemapCandidate(E3dScene
*& prScene
) const;
322 #endif // INCLUDED_SVX_OBJ3D_HXX
324 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */