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