/src/libreoffice/svx/source/engine3d/view3d1.cxx
Line | Count | Source (jump to first uncovered line) |
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 | | |
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> |
34 | | |
35 | | void E3dView::ConvertMarkedToPolyObj() |
36 | 0 | { |
37 | 0 | rtl::Reference<SdrObject> pNewObj; |
38 | |
|
39 | 0 | const SdrMarkList& rMarkList = GetMarkedObjectList(); |
40 | 0 | if (rMarkList.GetMarkCount() == 1) |
41 | 0 | { |
42 | 0 | SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj(); |
43 | |
|
44 | 0 | if (pObj) |
45 | 0 | { |
46 | 0 | const E3dScene* pScene = DynCastE3dScene(pObj); |
47 | 0 | if (pScene) |
48 | 0 | { |
49 | 0 | pNewObj = pScene->ConvertToPolyObj(false/*bBezier*/, false/*bLineToArea*/); |
50 | 0 | if (pNewObj) |
51 | 0 | { |
52 | 0 | BegUndo(SvxResId(RID_SVX_3D_UNDO_EXTRUDE)); |
53 | 0 | ReplaceObjectAtView(pObj, *GetSdrPageView(), pNewObj.get()); |
54 | 0 | EndUndo(); |
55 | 0 | } |
56 | 0 | } |
57 | 0 | } |
58 | 0 | } |
59 | |
|
60 | 0 | if (!pNewObj) |
61 | 0 | { |
62 | 0 | SdrView::ConvertMarkedToPolyObj(); |
63 | 0 | } |
64 | 0 | } |
65 | | |
66 | | static void Imp_E3dView_InorderRun3DObjects(const SdrObject& rObj, sal_uInt32& rMask) |
67 | 0 | { |
68 | 0 | if(dynamic_cast< const E3dLatheObj* >(&rObj) != nullptr) |
69 | 0 | { |
70 | 0 | rMask |= 0x0001; |
71 | 0 | } |
72 | 0 | else if(dynamic_cast< const E3dExtrudeObj* >(&rObj) != nullptr) |
73 | 0 | { |
74 | 0 | rMask |= 0x0002; |
75 | 0 | } |
76 | 0 | else if(dynamic_cast< const E3dSphereObj* >(&rObj) != nullptr) |
77 | 0 | { |
78 | 0 | rMask |= 0x0004; |
79 | 0 | } |
80 | 0 | else if(dynamic_cast< const E3dCubeObj* >(&rObj) != nullptr) |
81 | 0 | { |
82 | 0 | rMask |= 0x0008; |
83 | 0 | } |
84 | 0 | else if (rObj.IsGroupObject()) |
85 | 0 | { |
86 | 0 | SdrObjList* pList = rObj.GetSubList(); |
87 | 0 | for (const rtl::Reference<SdrObject>& pChildObj : *pList) |
88 | 0 | Imp_E3dView_InorderRun3DObjects(*pChildObj, rMask); |
89 | 0 | } |
90 | 0 | } |
91 | | |
92 | | SfxItemSet E3dView::Get3DAttributes() const |
93 | 0 | { |
94 | | // Creating itemset with corresponding field |
95 | 0 | SfxItemPool& rPool = GetModel().GetItemPool(); |
96 | 0 | SfxItemSet aSet( |
97 | 0 | rPool, |
98 | 0 | svl::Items<SDRATTR_START, SDRATTR_END, SID_ATTR_3D_INTERN, SID_ATTR_3D_INTERN>); |
99 | |
|
100 | 0 | sal_uInt32 nSelectedItems(0); |
101 | | |
102 | | // get attributes from all selected objects |
103 | 0 | MergeAttrFromMarked(aSet, false); |
104 | | |
105 | | // calc flags for SID_ATTR_3D_INTERN |
106 | 0 | const SdrMarkList& rMarkList = GetMarkedObjectList(); |
107 | 0 | const size_t nMarkCnt(rMarkList.GetMarkCount()); |
108 | |
|
109 | 0 | for(size_t a = 0; a < nMarkCnt; ++a) |
110 | 0 | { |
111 | 0 | SdrObject* pObj = rMarkList.GetMark(a)->GetMarkedSdrObj(); |
112 | 0 | Imp_E3dView_InorderRun3DObjects(*pObj, nSelectedItems); |
113 | 0 | } |
114 | | |
115 | | // Set SID_ATTR_3D_INTERN on the status of the selected objects |
116 | 0 | aSet.Put(SfxUInt32Item(SID_ATTR_3D_INTERN, nSelectedItems)); |
117 | | |
118 | | // maintain default values |
119 | 0 | if(!nSelectedItems) |
120 | 0 | { |
121 | | // Get defaults and apply |
122 | 0 | SfxItemSetFixed<SDRATTR_3D_FIRST, SDRATTR_3D_LAST> aDefaultSet(GetModel().GetItemPool()); |
123 | 0 | GetAttributes(aDefaultSet); |
124 | 0 | aSet.Put(aDefaultSet); |
125 | | |
126 | | // ... but no lines for 3D |
127 | 0 | aSet.Put(XLineStyleItem (css::drawing::LineStyle_NONE)); |
128 | | |
129 | | // new defaults for distance and focal length |
130 | 0 | aSet.Put(makeSvx3DDistanceItem(100)); |
131 | 0 | aSet.Put(makeSvx3DFocalLengthItem(10000)); |
132 | 0 | } |
133 | | |
134 | | // return ItemSet |
135 | 0 | return aSet; |
136 | 0 | } |
137 | | |
138 | | void E3dView::Set3DAttributes( const SfxItemSet& rAttr) |
139 | 0 | { |
140 | 0 | sal_uInt32 nSelectedItems(0); |
141 | | |
142 | | // #i94832# removed usage of E3DModifySceneSnapRectUpdater here. |
143 | | // They are not needed here, they are already handled in SetAttrToMarked |
144 | | |
145 | | // set at selected objects |
146 | 0 | SetAttrToMarked(rAttr, false/*bReplaceAll*/); |
147 | | |
148 | | // old run |
149 | 0 | const SdrMarkList& rMarkList = GetMarkedObjectList(); |
150 | 0 | const size_t nMarkCnt(rMarkList.GetMarkCount()); |
151 | |
|
152 | 0 | for(size_t a = 0; a < nMarkCnt; ++a) |
153 | 0 | { |
154 | 0 | SdrObject* pObj = rMarkList.GetMark(a)->GetMarkedSdrObj(); |
155 | 0 | Imp_E3dView_InorderRun3DObjects(*pObj, nSelectedItems); |
156 | 0 | } |
157 | | |
158 | | // Maintain default values |
159 | 0 | if(!nSelectedItems) |
160 | 0 | { |
161 | | // Set defaults |
162 | 0 | SfxItemSetFixed<SDRATTR_3D_FIRST, SDRATTR_3D_LAST> aDefaultSet(GetModel().GetItemPool()); |
163 | 0 | aDefaultSet.Put(rAttr); |
164 | 0 | SetAttributes(aDefaultSet); |
165 | 0 | } |
166 | 0 | } |
167 | | |
168 | | double E3dView::GetDefaultCamPosZ() |
169 | 0 | { |
170 | 0 | return static_cast<double>(GetModel().GetItemPool().GetUserOrPoolDefaultItem(SDRATTR_3DSCENE_DISTANCE).GetValue()); |
171 | 0 | } |
172 | | |
173 | | double E3dView::GetDefaultCamFocal() |
174 | 0 | { |
175 | 0 | return static_cast<double>(GetModel().GetItemPool().GetUserOrPoolDefaultItem(SDRATTR_3DSCENE_FOCAL_LENGTH).GetValue()); |
176 | 0 | } |
177 | | |
178 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |