LibreOffice Module svx (master)  1
scene3d.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_SVX_SCENE3D_HXX
21 #define INCLUDED_SVX_SCENE3D_HXX
22 
23 #include <svx/camera3d.hxx>
24 #include <tools/b3dtrans.hxx>
25 #include <svx/svdpage.hxx>
26 #include <svx/svxdllapi.h>
27 #include <svx/obj3d.hxx>
28 #include <svx/svx3ditems.hxx>
29 #include <memory>
30 
31 namespace sdr { namespace properties {
32  class BaseProperties;
33 }}
34 
35 /*************************************************************************
36 |*
37 |* GeoData relevant for undo actions
38 |*
39 \************************************************************************/
40 
41 class E3DSceneGeoData final : public E3DObjGeoData
42 {
43 public:
45 
47 };
48 
49 class Imp3DDepthRemapper;
50 
51 /*************************************************************************
52 |*
53 |* base class for 3D scenes
54 |*
55 \************************************************************************/
56 
58 {
59 protected:
60  virtual std::unique_ptr<sdr::properties::BaseProperties> CreateObjectSpecificProperties() override;
61  virtual std::unique_ptr<sdr::contact::ViewContact> CreateObjectSpecificViewContact() override;
62 
63  // transformations
66 
67  mutable std::unique_ptr<Imp3DDepthRemapper> mp3DDepthRemapper;
68 
69  // Flag to determine if only selected objects should be drawn
70  bool bDrawOnlySelected : 1;
71 
72  bool mbSkipSettingDirty : 1;
73 
74  void RebuildLists();
75 
76  virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override;
77 
78  void SetDefaultAttributes();
79  void ImpCleanup3DDepthMapper();
80 
81  // protected destructor
82  virtual ~E3dScene() override;
83 
84 public:
85  E3dScene(SdrModel& rSdrModel);
86 
87  virtual void StructureChanged() override;
88 
89  // derived from SdrObjList
90  virtual SdrPage* getSdrPageFromSdrObjList() const override;
91  virtual SdrObject* getSdrObjectFromSdrObjList() const override;
92 
93  // derived from SdrObject
94  virtual SdrObjList* getChildrenOfSdrObject() const override;
95 
96  virtual void SetBoundRectDirty() override;
97 
98  virtual basegfx::B2DPolyPolygon TakeXorPoly() const override;
99 
100  sal_uInt32 RemapOrdNum(sal_uInt32 nOrdNum) const;
101 
102  // Perspective: enum ProjectionType { ProjectionType::Parallel, ProjectionType::Perspective }
104  { return static_cast<ProjectionType>(GetObjectItemSet().Get(SDRATTR_3DSCENE_PERSPECTIVE).GetValue()); }
105 
106  // Distance:
107  double GetDistance() const
108  { return static_cast<double>(GetObjectItemSet().Get(SDRATTR_3DSCENE_DISTANCE).GetValue()); }
109 
110  // Focal length: before cm, now 1/10th mm (*100)
111  double GetFocalLength() const
112  { return GetObjectItemSet().Get(SDRATTR_3DSCENE_FOCAL_LENGTH).GetValue(); }
113 
114  // set flag to draw only selected
115  void SetDrawOnlySelected(bool bNew) { bDrawOnlySelected = bNew; }
116  bool GetDrawOnlySelected() const { return bDrawOnlySelected; }
117  virtual sal_uInt16 GetObjIdentifier() const override;
118 
119  virtual void NbcSetSnapRect(const tools::Rectangle& rRect) override;
120  virtual void NbcMove(const Size& rSize) override;
121  virtual void NbcResize(const Point& rRef, const Fraction& rXFact,
122  const Fraction& rYFact) override;
123  virtual void RecalcSnapRect() override;
124 
125  virtual E3dScene* getRootE3dSceneFromE3dObject() const override;
126  void SetCamera(const Camera3D& rNewCamera);
127  const Camera3D& GetCamera() const { return aCamera; }
128  void removeAllNonSelectedObjects();
129 
130  virtual E3dScene* CloneSdrObject(SdrModel& rTargetModel) const override;
131  E3dScene& operator=(const E3dScene&);
132 
133  virtual SdrObjGeoData *NewGeoData() const override;
134  virtual void SaveGeoData(SdrObjGeoData& rGeo) const override;
135  virtual void RestGeoData(const SdrObjGeoData& rGeo) override;
136 
137  virtual void NbcSetTransform(const basegfx::B3DHomMatrix& rMatrix) override;
138  virtual void SetTransform(const basegfx::B3DHomMatrix& rMatrix) override;
139 
140  virtual void NbcRotate(const Point& rRef, long nAngle, double sn, double cs) override;
141  void RotateScene(const Point& rRef, double sn, double cs);
142 
143  // TakeObjName...() is for the display in the UI, for example "3 frames selected".
144  virtual OUString TakeObjNameSingul() const override;
145  virtual OUString TakeObjNamePlural() const override;
146 
147  // get transformations
148  B3dCamera& GetCameraSet() { return aCameraSet; }
149  const B3dCamera& GetCameraSet() const { return aCameraSet; }
150 
151  // break up
152  virtual bool IsBreakObjPossible() override;
153 
154  // polygon which is built during creation
155  virtual basegfx::B2DPolyPolygon TakeCreatePoly(const SdrDragStat& rDrag) const override;
156 
157  // create moves
158  virtual bool BegCreate(SdrDragStat& rStat) override;
159  virtual bool MovCreate(SdrDragStat& rStat) override; // true=Xor must be repainted
160  virtual bool EndCreate(SdrDragStat& rStat, SdrCreateCmd eCmd) override;
161  virtual bool BckCreate(SdrDragStat& rStat) override;
162  virtual void BrkCreate(SdrDragStat& rStat) override;
163 
164  void SuspendReportingDirtyRects();
165  void ResumeReportingDirtyRects();
166  void SetAllSceneRectsDirty();
167 
168  // set selection from E3dObject (temporary flag for 3D actions)
169  virtual void SetSelected(bool bNew) override;
170 
171  // derived from SdrObjList
172  virtual void NbcInsertObject(SdrObject* pObj, size_t nPos=SAL_MAX_SIZE) override;
173  virtual void InsertObject(SdrObject* pObj, size_t nPos=SAL_MAX_SIZE) override;
174  virtual SdrObject* NbcRemoveObject(size_t nObjNum) override;
175  virtual SdrObject* RemoveObject(size_t nObjNum) override;
176 
177  // needed for group functionality
178  virtual void SetRectsDirty(bool bNotMyself = false, bool bRecursive = true) override;
179  virtual void NbcSetLayer(SdrLayerID nLayer) override;
180 
181  // react on model/page change
182  virtual void handlePageChange(SdrPage* pOldPage, SdrPage* pNewPage) override;
183 
184  virtual SdrObjList* GetSubList() const override;
185  virtual void SetTransformChanged() override;
186 
187 protected:
188  virtual basegfx::B3DRange RecalcBoundVolume() const override;
189 };
190 
191 #endif // INCLUDED_SVX_SCENE3D_HXX
192 
193 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void NbcResize(const Point &rRef, const Fraction &xFact, const Fraction &yFact) override
Definition: obj3d.cxx:158
virtual bool BckCreate(SdrDragStat &rStat)
Definition: svdobj.cxx:1379
virtual basegfx::B2DPolyPolygon TakeXorPoly() const
The Xor-Polygon is required by the View to drag the object.
Definition: svdobj.cxx:1094
const B3dCamera & GetCameraSet() const
Definition: scene3d.hxx:149
virtual OUString TakeObjNameSingul() const override
Definition: obj3d.cxx:395
virtual bool BegCreate(SdrDragStat &rStat)
Every object must be able to create itself interactively.
Definition: svdobj.cxx:1348
virtual void SetTransformChanged()
Definition: obj3d.cxx:339
virtual void handlePageChange(SdrPage *pOldPage, SdrPage *pNewPage)
Definition: svdobj.cxx:476
virtual SdrObjList * getChildrenOfSdrObject() const
Definition: svdobj.cxx:330
ProjectionType
Definition: viewpt3d.hxx:38
Camera3D aCamera
Definition: scene3d.hxx:65
virtual void NbcInsertObject(SdrObject *pObj, size_t nPos=SAL_MAX_SIZE)
Definition: svdpage.cxx:307
virtual void SaveGeoData(SdrObjGeoData &rGeo) const override
Definition: obj3d.cxx:448
virtual void SetBoundRectDirty()
Definition: svdobj.cxx:336
B3dCamera aCameraSet
Definition: scene3d.hxx:64
#define SVX_DLLPUBLIC
Definition: svxdllapi.h:28
virtual void InsertObject(SdrObject *pObj, size_t nPos=SAL_MAX_SIZE)
Definition: svdpage.cxx:358
All geometrical data of an arbitrary object for use in undo/redo.
Definition: svdobj.hxx:226
virtual SdrObjList * GetSubList() const
Definition: svdobj.cxx:674
double GetDistance() const
Definition: scene3d.hxx:107
ProjectionType GetPerspective() const
Definition: scene3d.hxx:103
virtual sal_uInt16 GetObjIdentifier() const override
Definition: obj3d.cxx:124
virtual void BrkCreate(SdrDragStat &rStat)
Definition: svdobj.cxx:1375
std::unique_ptr< Imp3DDepthRemapper > mp3DDepthRemapper
Definition: scene3d.hxx:67
virtual bool EndCreate(SdrDragStat &rStat, SdrCreateCmd eCmd)
Definition: svdobj.cxx:1367
virtual void StructureChanged()
Definition: obj3d.cxx:270
virtual bool IsBreakObjPossible()
Definition: obj3d.cxx:109
const SfxItemSet & GetObjectItemSet() const
Definition: svdobj.cxx:1906
double GetFocalLength() const
Definition: scene3d.hxx:111
#define SDRATTR_3DSCENE_FOCAL_LENGTH
Definition: svddef.hxx:360
void SetDrawOnlySelected(bool bNew)
Definition: scene3d.hxx:115
virtual void NbcRotate(const Point &rRef, long nAngle, double sn, double cs) override
Definition: obj3d.cxx:468
virtual void NbcSetTransform(const basegfx::B3DHomMatrix &rMatrix)
Definition: obj3d.cxx:366
Camera3D aCamera
Definition: scene3d.hxx:44
virtual bool MovCreate(SdrDragStat &rStat)
Definition: svdobj.cxx:1358
#define SDRATTR_3DSCENE_PERSPECTIVE
Definition: svddef.hxx:358
virtual E3dObject * CloneSdrObject(SdrModel &rTargetModel) const override
Definition: obj3d.cxx:416
bool GetDrawOnlySelected() const
Definition: scene3d.hxx:116
virtual basegfx::B3DRange RecalcBoundVolume() const
Definition: obj3d.cxx:300
virtual SdrObject * NbcRemoveObject(size_t nObjNum)
remove from list without delete
Definition: svdpage.cxx:397
Abstract DrawObject.
Definition: svdobj.hxx:312
virtual SdrObject * RemoveObject(size_t nObjNum)
Definition: svdpage.cxx:436
virtual std::unique_ptr< sdr::properties::BaseProperties > CreateObjectSpecificProperties() override
Definition: obj3d.cxx:79
virtual SdrObjGeoData * NewGeoData() const override
A derived class must override these 3 methods if it has own geometric data that must be saved for Und...
Definition: obj3d.cxx:443
#define SDRATTR_3DSCENE_DISTANCE
Definition: svddef.hxx:359
virtual void RestGeoData(const SdrObjGeoData &rGeo) override
Definition: obj3d.cxx:456
virtual void SetTransform(const basegfx::B3DHomMatrix &rMatrix)
Definition: obj3d.cxx:377
virtual std::unique_ptr< sdr::contact::ViewContact > CreateObjectSpecificViewContact()
Definition: svdobj.cxx:266
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
virtual void NbcSetSnapRect(const tools::Rectangle &rRect)
Definition: svdobj.cxx:1629
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
Detects when a stylesheet is changed.
Definition: svdoattr.cxx:103
E3dObject & operator=(const E3dObject &rObj)
Definition: obj3d.cxx:421
virtual SdrPage * getSdrPageFromSdrObjList() const
Definition: svdpage.cxx:146
virtual void NbcMove(const Size &rSize) override
The methods Move, Resize, Rotate, Mirror, Shear, SetSnapRect and SetLogicRect call the corresponding ...
Definition: obj3d.cxx:210
virtual void SetRectsDirty(bool bNotMyself=false, bool bRecursive=true)
Definition: svdobj.cxx:462
A SdrPage contains exactly one SdrObjList and a description of the physical page dimensions (size / m...
Definition: svdpage.hxx:366
virtual void SetSelected(bool bNew)
Definition: obj3d.cxx:100
virtual E3dScene * getRootE3dSceneFromE3dObject() const
Definition: obj3d.cxx:287
SdrCreateCmd
Definition: svdtypes.hxx:27
const Camera3D & GetCamera() const
Definition: scene3d.hxx:127
virtual SdrObject * getSdrObjectFromSdrObjList() const
Definition: svdpage.cxx:152
virtual basegfx::B2DPolyPolygon TakeCreatePoly(const SdrDragStat &rDrag) const
Polygon dragged by the user when creating the object.
Definition: svdobj.cxx:1384
virtual void RecalcSnapRect() override
Snap is not done on the BoundRect but if possible on logic coordinates (i.e.
Definition: obj3d.cxx:263
B3dCamera & GetCameraSet()
Definition: scene3d.hxx:148
virtual OUString TakeObjNamePlural() const override
Definition: obj3d.cxx:411
virtual void NbcSetLayer(SdrLayerID nLayer)
Definition: svdobj.cxx:621