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::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 
57 class SVXCORE_DLLPUBLIC E3dScene final : public E3dObject, public SdrObjList
58 {
59  virtual std::unique_ptr<sdr::properties::BaseProperties> CreateObjectSpecificProperties() override;
60  virtual std::unique_ptr<sdr::contact::ViewContact> CreateObjectSpecificViewContact() override;
61 
62  // transformations
65 
66  mutable std::unique_ptr<Imp3DDepthRemapper> mp3DDepthRemapper;
67 
68  // Flag to determine if only selected objects should be drawn
69  bool bDrawOnlySelected : 1;
70 
71  bool mbSkipSettingDirty : 1;
72 
73  void RebuildLists();
74 
75  virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override;
76 
77  void SetDefaultAttributes();
78  void ImpCleanup3DDepthMapper();
79 
80  // protected destructor
81  virtual ~E3dScene() override;
82 
83 public:
84  E3dScene(SdrModel& rSdrModel);
85  E3dScene(SdrModel& rSdrModel, E3dScene const &);
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 SdrObjKind 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 
132  virtual std::unique_ptr<SdrObjGeoData> NewGeoData() const override;
133  virtual void SaveGeoData(SdrObjGeoData& rGeo) const override;
134  virtual void RestoreGeoData(const SdrObjGeoData& rGeo) override;
135 
136  virtual void NbcSetTransform(const basegfx::B3DHomMatrix& rMatrix) override;
137  virtual void SetTransform(const basegfx::B3DHomMatrix& rMatrix) override;
138 
139  virtual void NbcRotate(const Point& rRef, Degree100 nAngle, double sn, double cs) override;
140  void RotateScene(const Point& rRef, double sn, double cs);
141 
142  // TakeObjName...() is for the display in the UI, for example "3 frames selected".
143  virtual OUString TakeObjNameSingul() const override;
144  virtual OUString TakeObjNamePlural() const override;
145 
146  // get transformations
147  B3dCamera& GetCameraSet() { return aCameraSet; }
148  const B3dCamera& GetCameraSet() const { return aCameraSet; }
149 
150  // break up
151  virtual bool IsBreakObjPossible() override;
152 
153  // polygon which is built during creation
154  virtual basegfx::B2DPolyPolygon TakeCreatePoly(const SdrDragStat& rDrag) const override;
155 
156  // create moves
157  virtual bool BegCreate(SdrDragStat& rStat) override;
158  virtual bool MovCreate(SdrDragStat& rStat) override; // true=Xor must be repainted
159  virtual bool EndCreate(SdrDragStat& rStat, SdrCreateCmd eCmd) override;
160  virtual bool BckCreate(SdrDragStat& rStat) override;
161  virtual void BrkCreate(SdrDragStat& rStat) override;
162 
163  void SuspendReportingDirtyRects();
164  void ResumeReportingDirtyRects();
165  void SetAllSceneRectsDirty();
166 
167  // set selection from E3dObject (temporary flag for 3D actions)
168  virtual void SetSelected(bool bNew) override;
169 
170  // derived from SdrObjList
171  virtual void NbcInsertObject(SdrObject* pObj, size_t nPos=SAL_MAX_SIZE) override;
172  virtual void InsertObject(SdrObject* pObj, size_t nPos=SAL_MAX_SIZE) override;
173  virtual SdrObject* NbcRemoveObject(size_t nObjNum) override;
174  virtual SdrObject* RemoveObject(size_t nObjNum) override;
175 
176  // needed for group functionality
177  virtual void SetRectsDirty(bool bNotMyself = false, bool bRecursive = true) override;
178  virtual void NbcSetLayer(SdrLayerID nLayer) override;
179 
180  // react on model/page change
181  virtual void handlePageChange(SdrPage* pOldPage, SdrPage* pNewPage) override;
182 
183  virtual SdrObjList* GetSubList() const override;
184  virtual void SetTransformChanged() override;
185 
186 private:
187  virtual basegfx::B3DRange RecalcBoundVolume() const override;
188 };
189 
190 #endif // INCLUDED_SVX_SCENE3D_HXX
191 
192 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void NbcResize(const Point &rRef, const Fraction &xFact, const Fraction &yFact) override
Definition: obj3d.cxx:149
virtual bool BckCreate(SdrDragStat &rStat)
Definition: svdobj.cxx:1414
virtual basegfx::B2DPolyPolygon TakeXorPoly() const
The Xor-Polygon is required by the View to drag the object.
Definition: svdobj.cxx:1129
const B3dCamera & GetCameraSet() const
Definition: scene3d.hxx:148
virtual OUString TakeObjNameSingul() const override
Definition: obj3d.cxx:389
virtual bool BegCreate(SdrDragStat &rStat)
Every object must be able to create itself interactively.
Definition: svdobj.cxx:1383
virtual void SetTransformChanged()
Definition: obj3d.cxx:333
virtual void handlePageChange(SdrPage *pOldPage, SdrPage *pNewPage)
Definition: svdobj.cxx:526
virtual SdrObjList * getChildrenOfSdrObject() const
Definition: svdobj.cxx:310
ProjectionType
Definition: viewpt3d.hxx:38
virtual void RestoreGeoData(const SdrObjGeoData &rGeo) override
Definition: obj3d.cxx:425
Camera3D aCamera
Definition: scene3d.hxx:64
virtual void NbcInsertObject(SdrObject *pObj, size_t nPos=SAL_MAX_SIZE)
Definition: svdpage.cxx:287
virtual void SaveGeoData(SdrObjGeoData &rGeo) const override
Definition: obj3d.cxx:417
virtual void SetBoundRectDirty()
Definition: svdobj.cxx:316
B3dCamera aCameraSet
Definition: scene3d.hxx:63
virtual void InsertObject(SdrObject *pObj, size_t nPos=SAL_MAX_SIZE)
Definition: svdpage.cxx:338
All geometrical data of an arbitrary object for use in undo/redo.
Definition: svdobj.hxx:172
virtual SdrObjList * GetSubList() const
Definition: svdobj.cxx:750
SdrObjKind
Definition: svdobjkind.hxx:24
double GetDistance() const
Definition: scene3d.hxx:107
ProjectionType GetPerspective() const
Definition: scene3d.hxx:103
constexpr TypedWhichId< SfxUInt32Item > SDRATTR_3DSCENE_DISTANCE(SDRATTR_3DSCENE_FIRST+1)
virtual void BrkCreate(SdrDragStat &rStat)
Definition: svdobj.cxx:1410
virtual SdrObjKind GetObjIdentifier() const override
Definition: obj3d.cxx:115
std::unique_ptr< Imp3DDepthRemapper > mp3DDepthRemapper
Definition: scene3d.hxx:66
virtual bool EndCreate(SdrDragStat &rStat, SdrCreateCmd eCmd)
Definition: svdobj.cxx:1402
virtual void StructureChanged()
Definition: obj3d.cxx:261
virtual bool IsBreakObjPossible()
Definition: obj3d.cxx:100
const SfxItemSet & GetObjectItemSet() const
Definition: svdobj.cxx:1976
double GetFocalLength() const
Definition: scene3d.hxx:111
void SetDrawOnlySelected(bool bNew)
Definition: scene3d.hxx:115
virtual void NbcRotate(const Point &rRef, Degree100 nAngle, double sn, double cs) override
Definition: obj3d.cxx:437
virtual void NbcSetTransform(const basegfx::B3DHomMatrix &rMatrix)
Definition: obj3d.cxx:360
Camera3D aCamera
Definition: scene3d.hxx:44
virtual bool MovCreate(SdrDragStat &rStat)
Definition: svdobj.cxx:1393
virtual E3dObject * CloneSdrObject(SdrModel &rTargetModel) const override
Definition: obj3d.cxx:407
bool GetDrawOnlySelected() const
Definition: scene3d.hxx:116
virtual basegfx::B3DRange RecalcBoundVolume() const
Definition: obj3d.cxx:291
virtual SdrObject * NbcRemoveObject(size_t nObjNum)
remove from list without delete
Definition: svdpage.cxx:377
virtual std::unique_ptr< 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:412
constexpr TypedWhichId< Svx3DPerspectiveItem > SDRATTR_3DSCENE_PERSPECTIVE(SDRATTR_3DSCENE_FIRST+0)
Abstract DrawObject.
Definition: svdobj.hxx:258
virtual SdrObject * RemoveObject(size_t nObjNum)
Definition: svdpage.cxx:416
virtual std::unique_ptr< sdr::properties::BaseProperties > CreateObjectSpecificProperties() override
Definition: obj3d.cxx:47
virtual void SetTransform(const basegfx::B3DHomMatrix &rMatrix)
Definition: obj3d.cxx:371
virtual std::unique_ptr< sdr::contact::ViewContact > CreateObjectSpecificViewContact()
Definition: svdobj.cxx:246
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
virtual void NbcSetSnapRect(const tools::Rectangle &rRect)
Definition: svdobj.cxx:1674
constexpr TypedWhichId< SfxUInt32Item > SDRATTR_3DSCENE_FOCAL_LENGTH(SDRATTR_3DSCENE_FIRST+2)
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
Detects when a stylesheet is changed.
Definition: svdoattr.cxx:61
#define SVXCORE_DLLPUBLIC
Definition: svxdllapi.h:35
virtual SdrPage * getSdrPageFromSdrObjList() const
Definition: svdpage.cxx:126
virtual void NbcMove(const Size &rSize) override
The methods Move, Resize, Rotate, Mirror, Shear, SetSnapRect and SetLogicRect call the corresponding ...
Definition: obj3d.cxx:201
virtual void SetRectsDirty(bool bNotMyself=false, bool bRecursive=true)
Definition: svdobj.cxx:512
A SdrPage contains exactly one SdrObjList and a description of the physical page dimensions (size / m...
Definition: svdpage.hxx:365
virtual void SetSelected(bool bNew)
Definition: obj3d.cxx:91
virtual E3dScene * getRootE3dSceneFromE3dObject() const
Definition: obj3d.cxx:278
SdrCreateCmd
Definition: svdtypes.hxx:26
const Camera3D & GetCamera() const
Definition: scene3d.hxx:127
virtual SdrObject * getSdrObjectFromSdrObjList() const
Definition: svdpage.cxx:132
virtual basegfx::B2DPolyPolygon TakeCreatePoly(const SdrDragStat &rDrag) const
Polygon dragged by the user when creating the object.
Definition: svdobj.cxx:1419
virtual void RecalcSnapRect() override
Snap is not done on the BoundRect but if possible on logic coordinates (i.e.
Definition: obj3d.cxx:254
B3dCamera & GetCameraSet()
Definition: scene3d.hxx:147
virtual OUString TakeObjNamePlural() const override
Definition: obj3d.cxx:402
virtual void NbcSetLayer(SdrLayerID nLayer)
Definition: svdobj.cxx:697