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:
44     Camera3D                    aCamera;
45 
E3DSceneGeoData()46     E3DSceneGeoData() {}
47 };
48 
49 class Imp3DDepthRemapper;
50 
51 /*************************************************************************
52 |*
53 |* base class for 3D scenes
54 |*
55 \************************************************************************/
56 
57 class SVX_DLLPUBLIC E3dScene : public E3dObject, public SdrObjList
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
64     B3dCamera                   aCameraSet;
65     Camera3D                    aCamera;
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 }
GetPerspective() const103     ProjectionType GetPerspective() const
104         { return static_cast<ProjectionType>(GetObjectItemSet().Get(SDRATTR_3DSCENE_PERSPECTIVE).GetValue()); }
105 
106     // Distance:
GetDistance() const107     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)
GetFocalLength() const111     double GetFocalLength() const
112         { return GetObjectItemSet().Get(SDRATTR_3DSCENE_FOCAL_LENGTH).GetValue(); }
113 
114     // set flag to draw only selected
SetDrawOnlySelected(bool bNew)115     void SetDrawOnlySelected(bool bNew) { bDrawOnlySelected = bNew; }
GetDrawOnlySelected() const116     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);
GetCamera() const127     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
GetCameraSet()148     B3dCamera& GetCameraSet() { return aCameraSet; }
GetCameraSet() const149     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: */
194