xref: /AOO41X/main/svx/source/engine3d/view3d1.cxx (revision f6e50924346d0b8c0b07c91832a97665dd718b0c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_svx.hxx"
26 
27 #include <tools/shl.hxx>
28 #include "svx/svditer.hxx"
29 #include <svx/svdpool.hxx>
30 #include <svx/svdmodel.hxx>
31 #include <svx/svxids.hrc>
32 #include <svx/xtable.hxx>
33 #include <svx/fmview.hxx>
34 #include <svx/dialogs.hrc>
35 #include <svx/dialmgr.hxx>
36 #include "svx/globl3d.hxx"
37 #include <svx/obj3d.hxx>
38 #include <svx/polysc3d.hxx>
39 #include <svx/e3ditem.hxx>
40 #include <editeng/colritem.hxx>
41 #include <svx/lathe3d.hxx>
42 #include <svx/sphere3d.hxx>
43 #include <svx/extrud3d.hxx>
44 #include <svx/e3dundo.hxx>
45 #include <svx/view3d.hxx>
46 #include <svx/cube3d.hxx>
47 #include <svx/xflclit.hxx>
48 #include <svx/svdogrp.hxx>
49 #include <svx/e3dsceneupdater.hxx>
50 
51 /*************************************************************************
52 |*
53 |* Konvertierung in Polygone
54 |*
55 \************************************************************************/
56 
ConvertMarkedToPolyObj(sal_Bool bLineToArea)57 void E3dView::ConvertMarkedToPolyObj(sal_Bool bLineToArea)
58 {
59     SdrObject* pNewObj = NULL;
60 
61     if (GetMarkedObjectCount() == 1)
62     {
63         SdrObject* pObj = GetMarkedObjectByIndex(0);
64 
65         if (pObj && pObj->ISA(E3dPolyScene))
66         {
67             sal_Bool bBezier = sal_False;
68             pNewObj = ((E3dPolyScene*) pObj)->ConvertToPolyObj(bBezier, bLineToArea);
69 
70             if (pNewObj)
71             {
72                 BegUndo(SVX_RESSTR(RID_SVX_3D_UNDO_EXTRUDE));
73                 ReplaceObjectAtView(pObj, *GetSdrPageView(), pNewObj);
74                 EndUndo();
75             }
76         }
77     }
78 
79     if (!pNewObj)
80     {
81         SdrView::ConvertMarkedToPolyObj(bLineToArea);
82     }
83 }
84 
85 /*************************************************************************
86 |*
87 |* Get3DAttributes
88 |*
89 \************************************************************************/
90 
Imp_E3dView_InorderRun3DObjects(const SdrObject * pObj,sal_uInt32 & rMask)91 void Imp_E3dView_InorderRun3DObjects(const SdrObject* pObj, sal_uInt32& rMask)
92 {
93     if(pObj->ISA(E3dLatheObj))
94     {
95         rMask |= 0x0001;
96     }
97     else if(pObj->ISA(E3dExtrudeObj))
98     {
99         rMask |= 0x0002;
100     }
101     else if(pObj->ISA(E3dSphereObj))
102     {
103         rMask |= 0x0004;
104     }
105     else if(pObj->ISA(E3dCubeObj))
106     {
107         rMask |= 0x0008;
108     }
109     else if(pObj->IsGroupObject())
110     {
111         SdrObjList* pList = pObj->GetSubList();
112         for(sal_uInt32 a(0); a < pList->GetObjCount(); a++)
113             Imp_E3dView_InorderRun3DObjects(pList->GetObj(a), rMask);
114     }
115 }
116 
Get3DAttributes(E3dScene * pInScene,sal_Bool) const117 SfxItemSet E3dView::Get3DAttributes(E3dScene* pInScene, sal_Bool /*bOnly3DAttr*/) const
118 {
119     // ItemSet mit entspr. Bereich anlegen
120     SfxItemSet aSet(
121         pMod->GetItemPool(),
122         SDRATTR_START,      SDRATTR_END,
123         SID_ATTR_3D_INTERN, SID_ATTR_3D_INTERN,
124         0, 0);
125 
126     sal_uInt32 nSelectedItems(0L);
127 
128     if(pInScene)
129     {
130         // special scene
131         aSet.Put(pInScene->GetMergedItemSet());
132     }
133     else
134     {
135         // get attributes from all selected objects
136         MergeAttrFromMarked(aSet, sal_False);
137 
138         // calc flags for SID_ATTR_3D_INTERN
139         const SdrMarkList& rMarkList = GetMarkedObjectList();
140         sal_uInt32 nMarkCnt(rMarkList.GetMarkCount());
141 
142         for(sal_uInt32 a(0); a < nMarkCnt; a++)
143         {
144             SdrObject* pObj = GetMarkedObjectByIndex(a);
145             Imp_E3dView_InorderRun3DObjects(pObj, nSelectedItems);
146         }
147     }
148 
149     // setze SID_ATTR_3D_INTERN auf den Status der selektierten Objekte
150     aSet.Put(SfxUInt32Item(SID_ATTR_3D_INTERN, nSelectedItems));
151 
152     // DefaultValues pflegen
153     if(!nSelectedItems  && !pInScene)
154     {
155         // Defaults holen und hinzufuegen
156         SfxItemSet aDefaultSet(pMod->GetItemPool(), SDRATTR_3D_FIRST, SDRATTR_3D_LAST);
157         GetAttributes(aDefaultSet);
158         aSet.Put(aDefaultSet);
159 
160         // ... aber keine Linien fuer 3D
161         aSet.Put(XLineStyleItem (XLINE_NONE));
162 
163         // #84061# new defaults for distance and focal length
164         aSet.Put(Svx3DDistanceItem(100));
165         aSet.Put(Svx3DFocalLengthItem(10000));
166     }
167 
168     // ItemSet zurueckgeben
169     return(aSet);
170 }
171 
172 /*************************************************************************
173 |*
174 |* Set3DAttributes:
175 |*
176 \************************************************************************/
177 
Set3DAttributes(const SfxItemSet & rAttr,E3dScene * pInScene,sal_Bool bReplaceAll)178 void E3dView::Set3DAttributes( const SfxItemSet& rAttr, E3dScene* pInScene, sal_Bool bReplaceAll)
179 {
180     sal_uInt32 nSelectedItems(0L);
181 
182     if(pInScene)
183     {
184         //pInScene->SetItemSetAndBroadcast(rAttr, bReplaceAll);
185         pInScene->SetMergedItemSetAndBroadcast(rAttr, bReplaceAll);
186     }
187     else
188     {
189         // #i94832# removed usage of E3DModifySceneSnapRectUpdater here.
190         // They are not needed here, they are already handled in SetAttrToMarked
191 
192         // set at selected objects
193         SetAttrToMarked(rAttr, bReplaceAll);
194 
195         // old run
196         const SdrMarkList& rMarkList = GetMarkedObjectList();
197         const sal_uInt32 nMarkCnt(rMarkList.GetMarkCount());
198 
199         for(sal_uInt32 a(0); a < nMarkCnt; a++)
200         {
201             SdrObject* pObj = GetMarkedObjectByIndex(a);
202             Imp_E3dView_InorderRun3DObjects(pObj, nSelectedItems);
203         }
204     }
205 
206     // DefaultValues pflegen
207     if(!nSelectedItems && !pInScene)
208     {
209         // Defaults setzen
210         SfxItemSet aDefaultSet(pMod->GetItemPool(), SDRATTR_3D_FIRST, SDRATTR_3D_LAST);
211         aDefaultSet.Put(rAttr);
212         SetAttributes(aDefaultSet);
213 
214     }
215 }
216 
GetDefaultCamPosZ()217 double E3dView::GetDefaultCamPosZ()
218 {
219     return (double)((const SfxUInt32Item&)pMod->GetItemPool().GetDefaultItem(SDRATTR_3DSCENE_DISTANCE)).GetValue();
220 }
221 
GetDefaultCamFocal()222 double E3dView::GetDefaultCamFocal()
223 {
224     return (double)((const SfxUInt32Item&)pMod->GetItemPool().GetDefaultItem(SDRATTR_3DSCENE_FOCAL_LENGTH)).GetValue();
225 }
226 
227