Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / svx / source / engine3d / view3d1.cxx
blobbc5cfbaf5116ef97a623f24ee8dd893c0ff3cf9e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
21 #include <svl/itempool.hxx>
22 #include <svx/svdmodel.hxx>
23 #include <svx/svxids.hrc>
24 #include <svx/strings.hrc>
25 #include <svx/dialmgr.hxx>
26 #include <svx/lathe3d.hxx>
27 #include <svx/scene3d.hxx>
28 #include <svx/sphere3d.hxx>
29 #include <extrud3d.hxx>
30 #include <svx/view3d.hxx>
31 #include <svx/cube3d.hxx>
32 #include <svx/xlineit0.hxx>
33 #include <com/sun/star/drawing/LineStyle.hpp>
35 void E3dView::ConvertMarkedToPolyObj()
37 rtl::Reference<SdrObject> pNewObj;
39 if (GetMarkedObjectCount() == 1)
41 SdrObject* pObj = GetMarkedObjectByIndex(0);
43 if (pObj)
45 const E3dScene* pScene = DynCastE3dScene(pObj);
46 if (pScene)
48 pNewObj = pScene->ConvertToPolyObj(false/*bBezier*/, false/*bLineToArea*/);
49 if (pNewObj)
51 BegUndo(SvxResId(RID_SVX_3D_UNDO_EXTRUDE));
52 ReplaceObjectAtView(pObj, *GetSdrPageView(), pNewObj.get());
53 EndUndo();
59 if (!pNewObj)
61 SdrView::ConvertMarkedToPolyObj();
65 static void Imp_E3dView_InorderRun3DObjects(const SdrObject* pObj, sal_uInt32& rMask)
67 if(dynamic_cast< const E3dLatheObj* >(pObj) != nullptr)
69 rMask |= 0x0001;
71 else if(dynamic_cast< const E3dExtrudeObj* >(pObj) != nullptr)
73 rMask |= 0x0002;
75 else if(dynamic_cast< const E3dSphereObj* >(pObj) != nullptr)
77 rMask |= 0x0004;
79 else if(dynamic_cast< const E3dCubeObj* >(pObj) != nullptr)
81 rMask |= 0x0008;
83 else if(pObj->IsGroupObject())
85 SdrObjList* pList = pObj->GetSubList();
86 for(size_t a = 0; a < pList->GetObjCount(); ++a)
87 Imp_E3dView_InorderRun3DObjects(pList->GetObj(a), rMask);
91 SfxItemSet E3dView::Get3DAttributes() const
93 // Creating itemset with corresponding field
94 SfxItemPool& rPool = GetModel().GetItemPool();
95 SfxItemSet aSet(
96 rPool,
97 svl::Items<SDRATTR_START, SDRATTR_END, SID_ATTR_3D_INTERN, SID_ATTR_3D_INTERN>);
99 sal_uInt32 nSelectedItems(0);
101 // get attributes from all selected objects
102 MergeAttrFromMarked(aSet, false);
104 // calc flags for SID_ATTR_3D_INTERN
105 const SdrMarkList& rMarkList = GetMarkedObjectList();
106 const size_t nMarkCnt(rMarkList.GetMarkCount());
108 for(size_t a = 0; a < nMarkCnt; ++a)
110 SdrObject* pObj = GetMarkedObjectByIndex(a);
111 Imp_E3dView_InorderRun3DObjects(pObj, nSelectedItems);
114 // Set SID_ATTR_3D_INTERN on the status of the selected objects
115 aSet.Put(SfxUInt32Item(SID_ATTR_3D_INTERN, nSelectedItems));
117 // maintain default values
118 if(!nSelectedItems)
120 // Get defaults and apply
121 SfxItemSetFixed<SDRATTR_3D_FIRST, SDRATTR_3D_LAST> aDefaultSet(GetModel().GetItemPool());
122 GetAttributes(aDefaultSet);
123 aSet.Put(aDefaultSet);
125 // ... but no lines for 3D
126 aSet.Put(XLineStyleItem (css::drawing::LineStyle_NONE));
128 // new defaults for distance and focal length
129 aSet.Put(makeSvx3DDistanceItem(100));
130 aSet.Put(makeSvx3DFocalLengthItem(10000));
133 // return ItemSet
134 return aSet;
137 void E3dView::Set3DAttributes( const SfxItemSet& rAttr)
139 sal_uInt32 nSelectedItems(0);
141 // #i94832# removed usage of E3DModifySceneSnapRectUpdater here.
142 // They are not needed here, they are already handled in SetAttrToMarked
144 // set at selected objects
145 SetAttrToMarked(rAttr, false/*bReplaceAll*/);
147 // old run
148 const SdrMarkList& rMarkList = GetMarkedObjectList();
149 const size_t nMarkCnt(rMarkList.GetMarkCount());
151 for(size_t a = 0; a < nMarkCnt; ++a)
153 SdrObject* pObj = GetMarkedObjectByIndex(a);
154 Imp_E3dView_InorderRun3DObjects(pObj, nSelectedItems);
157 // Maintain default values
158 if(!nSelectedItems)
160 // Set defaults
161 SfxItemSetFixed<SDRATTR_3D_FIRST, SDRATTR_3D_LAST> aDefaultSet(GetModel().GetItemPool());
162 aDefaultSet.Put(rAttr);
163 SetAttributes(aDefaultSet);
167 double E3dView::GetDefaultCamPosZ()
169 return static_cast<double>(GetModel().GetItemPool().GetDefaultItem(SDRATTR_3DSCENE_DISTANCE).GetValue());
172 double E3dView::GetDefaultCamFocal()
174 return static_cast<double>(GetModel().GetItemPool().GetDefaultItem(SDRATTR_3DSCENE_FOCAL_LENGTH).GetValue());
177 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */