xref: /trunk/main/svx/source/engine3d/view3d1.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_svx.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <tools/shl.hxx>
32*cdf0e10cSrcweir #include "svx/svditer.hxx"
33*cdf0e10cSrcweir #include <svx/svdpool.hxx>
34*cdf0e10cSrcweir #include <svx/svdmodel.hxx>
35*cdf0e10cSrcweir #include <svx/svxids.hrc>
36*cdf0e10cSrcweir #include <svx/xtable.hxx>
37*cdf0e10cSrcweir #include <svx/fmview.hxx>
38*cdf0e10cSrcweir #include <svx/dialogs.hrc>
39*cdf0e10cSrcweir #include <svx/dialmgr.hxx>
40*cdf0e10cSrcweir #include "svx/globl3d.hxx"
41*cdf0e10cSrcweir #include <svx/obj3d.hxx>
42*cdf0e10cSrcweir #include <svx/polysc3d.hxx>
43*cdf0e10cSrcweir #include <svx/e3ditem.hxx>
44*cdf0e10cSrcweir #include <editeng/colritem.hxx>
45*cdf0e10cSrcweir #include <svx/lathe3d.hxx>
46*cdf0e10cSrcweir #include <svx/sphere3d.hxx>
47*cdf0e10cSrcweir #include <svx/extrud3d.hxx>
48*cdf0e10cSrcweir #include <svx/e3dundo.hxx>
49*cdf0e10cSrcweir #include <svx/view3d.hxx>
50*cdf0e10cSrcweir #include <svx/cube3d.hxx>
51*cdf0e10cSrcweir #include <svx/xflclit.hxx>
52*cdf0e10cSrcweir #include <svx/svdogrp.hxx>
53*cdf0e10cSrcweir #include <svx/e3dsceneupdater.hxx>
54*cdf0e10cSrcweir 
55*cdf0e10cSrcweir /*************************************************************************
56*cdf0e10cSrcweir |*
57*cdf0e10cSrcweir |* Konvertierung in Polygone
58*cdf0e10cSrcweir |*
59*cdf0e10cSrcweir \************************************************************************/
60*cdf0e10cSrcweir 
61*cdf0e10cSrcweir void E3dView::ConvertMarkedToPolyObj(sal_Bool bLineToArea)
62*cdf0e10cSrcweir {
63*cdf0e10cSrcweir     SdrObject* pNewObj = NULL;
64*cdf0e10cSrcweir 
65*cdf0e10cSrcweir     if (GetMarkedObjectCount() == 1)
66*cdf0e10cSrcweir     {
67*cdf0e10cSrcweir         SdrObject* pObj = GetMarkedObjectByIndex(0);
68*cdf0e10cSrcweir 
69*cdf0e10cSrcweir         if (pObj && pObj->ISA(E3dPolyScene))
70*cdf0e10cSrcweir         {
71*cdf0e10cSrcweir             sal_Bool bBezier = sal_False;
72*cdf0e10cSrcweir             pNewObj = ((E3dPolyScene*) pObj)->ConvertToPolyObj(bBezier, bLineToArea);
73*cdf0e10cSrcweir 
74*cdf0e10cSrcweir             if (pNewObj)
75*cdf0e10cSrcweir             {
76*cdf0e10cSrcweir                 BegUndo(SVX_RESSTR(RID_SVX_3D_UNDO_EXTRUDE));
77*cdf0e10cSrcweir                 ReplaceObjectAtView(pObj, *GetSdrPageView(), pNewObj);
78*cdf0e10cSrcweir                 EndUndo();
79*cdf0e10cSrcweir             }
80*cdf0e10cSrcweir         }
81*cdf0e10cSrcweir     }
82*cdf0e10cSrcweir 
83*cdf0e10cSrcweir     if (!pNewObj)
84*cdf0e10cSrcweir     {
85*cdf0e10cSrcweir         SdrView::ConvertMarkedToPolyObj(bLineToArea);
86*cdf0e10cSrcweir     }
87*cdf0e10cSrcweir }
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir /*************************************************************************
90*cdf0e10cSrcweir |*
91*cdf0e10cSrcweir |* Get3DAttributes
92*cdf0e10cSrcweir |*
93*cdf0e10cSrcweir \************************************************************************/
94*cdf0e10cSrcweir 
95*cdf0e10cSrcweir void Imp_E3dView_InorderRun3DObjects(const SdrObject* pObj, sal_uInt32& rMask)
96*cdf0e10cSrcweir {
97*cdf0e10cSrcweir     if(pObj->ISA(E3dLatheObj))
98*cdf0e10cSrcweir     {
99*cdf0e10cSrcweir         rMask |= 0x0001;
100*cdf0e10cSrcweir     }
101*cdf0e10cSrcweir     else if(pObj->ISA(E3dExtrudeObj))
102*cdf0e10cSrcweir     {
103*cdf0e10cSrcweir         rMask |= 0x0002;
104*cdf0e10cSrcweir     }
105*cdf0e10cSrcweir     else if(pObj->ISA(E3dSphereObj))
106*cdf0e10cSrcweir     {
107*cdf0e10cSrcweir         rMask |= 0x0004;
108*cdf0e10cSrcweir     }
109*cdf0e10cSrcweir     else if(pObj->ISA(E3dCubeObj))
110*cdf0e10cSrcweir     {
111*cdf0e10cSrcweir         rMask |= 0x0008;
112*cdf0e10cSrcweir     }
113*cdf0e10cSrcweir     else if(pObj->IsGroupObject())
114*cdf0e10cSrcweir     {
115*cdf0e10cSrcweir         SdrObjList* pList = pObj->GetSubList();
116*cdf0e10cSrcweir         for(sal_uInt32 a(0); a < pList->GetObjCount(); a++)
117*cdf0e10cSrcweir             Imp_E3dView_InorderRun3DObjects(pList->GetObj(a), rMask);
118*cdf0e10cSrcweir     }
119*cdf0e10cSrcweir }
120*cdf0e10cSrcweir 
121*cdf0e10cSrcweir SfxItemSet E3dView::Get3DAttributes(E3dScene* pInScene, sal_Bool /*bOnly3DAttr*/) const
122*cdf0e10cSrcweir {
123*cdf0e10cSrcweir     // ItemSet mit entspr. Bereich anlegen
124*cdf0e10cSrcweir     SfxItemSet aSet(
125*cdf0e10cSrcweir         pMod->GetItemPool(),
126*cdf0e10cSrcweir         SDRATTR_START,      SDRATTR_END,
127*cdf0e10cSrcweir         SID_ATTR_3D_INTERN, SID_ATTR_3D_INTERN,
128*cdf0e10cSrcweir         0, 0);
129*cdf0e10cSrcweir 
130*cdf0e10cSrcweir     sal_uInt32 nSelectedItems(0L);
131*cdf0e10cSrcweir 
132*cdf0e10cSrcweir     if(pInScene)
133*cdf0e10cSrcweir     {
134*cdf0e10cSrcweir         // special scene
135*cdf0e10cSrcweir         aSet.Put(pInScene->GetMergedItemSet());
136*cdf0e10cSrcweir     }
137*cdf0e10cSrcweir     else
138*cdf0e10cSrcweir     {
139*cdf0e10cSrcweir         // get attributes from all selected objects
140*cdf0e10cSrcweir         MergeAttrFromMarked(aSet, sal_False);
141*cdf0e10cSrcweir 
142*cdf0e10cSrcweir         // calc flags for SID_ATTR_3D_INTERN
143*cdf0e10cSrcweir         const SdrMarkList& rMarkList = GetMarkedObjectList();
144*cdf0e10cSrcweir         sal_uInt32 nMarkCnt(rMarkList.GetMarkCount());
145*cdf0e10cSrcweir 
146*cdf0e10cSrcweir         for(sal_uInt32 a(0); a < nMarkCnt; a++)
147*cdf0e10cSrcweir         {
148*cdf0e10cSrcweir             SdrObject* pObj = GetMarkedObjectByIndex(a);
149*cdf0e10cSrcweir             Imp_E3dView_InorderRun3DObjects(pObj, nSelectedItems);
150*cdf0e10cSrcweir         }
151*cdf0e10cSrcweir     }
152*cdf0e10cSrcweir 
153*cdf0e10cSrcweir     // setze SID_ATTR_3D_INTERN auf den Status der selektierten Objekte
154*cdf0e10cSrcweir     aSet.Put(SfxUInt32Item(SID_ATTR_3D_INTERN, nSelectedItems));
155*cdf0e10cSrcweir 
156*cdf0e10cSrcweir     // DefaultValues pflegen
157*cdf0e10cSrcweir     if(!nSelectedItems  && !pInScene)
158*cdf0e10cSrcweir     {
159*cdf0e10cSrcweir         // Defaults holen und hinzufuegen
160*cdf0e10cSrcweir         SfxItemSet aDefaultSet(pMod->GetItemPool(), SDRATTR_3D_FIRST, SDRATTR_3D_LAST);
161*cdf0e10cSrcweir         GetAttributes(aDefaultSet);
162*cdf0e10cSrcweir         aSet.Put(aDefaultSet);
163*cdf0e10cSrcweir 
164*cdf0e10cSrcweir         // ... aber keine Linien fuer 3D
165*cdf0e10cSrcweir         aSet.Put(XLineStyleItem (XLINE_NONE));
166*cdf0e10cSrcweir 
167*cdf0e10cSrcweir         // #84061# new defaults for distance and focal length
168*cdf0e10cSrcweir         aSet.Put(Svx3DDistanceItem(100));
169*cdf0e10cSrcweir         aSet.Put(Svx3DFocalLengthItem(10000));
170*cdf0e10cSrcweir     }
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir     // ItemSet zurueckgeben
173*cdf0e10cSrcweir     return(aSet);
174*cdf0e10cSrcweir }
175*cdf0e10cSrcweir 
176*cdf0e10cSrcweir /*************************************************************************
177*cdf0e10cSrcweir |*
178*cdf0e10cSrcweir |* Set3DAttributes:
179*cdf0e10cSrcweir |*
180*cdf0e10cSrcweir \************************************************************************/
181*cdf0e10cSrcweir 
182*cdf0e10cSrcweir void E3dView::Set3DAttributes( const SfxItemSet& rAttr, E3dScene* pInScene, sal_Bool bReplaceAll)
183*cdf0e10cSrcweir {
184*cdf0e10cSrcweir     sal_uInt32 nSelectedItems(0L);
185*cdf0e10cSrcweir 
186*cdf0e10cSrcweir     if(pInScene)
187*cdf0e10cSrcweir     {
188*cdf0e10cSrcweir         //pInScene->SetItemSetAndBroadcast(rAttr, bReplaceAll);
189*cdf0e10cSrcweir         pInScene->SetMergedItemSetAndBroadcast(rAttr, bReplaceAll);
190*cdf0e10cSrcweir     }
191*cdf0e10cSrcweir     else
192*cdf0e10cSrcweir     {
193*cdf0e10cSrcweir         // #i94832# removed usage of E3DModifySceneSnapRectUpdater here.
194*cdf0e10cSrcweir         // They are not needed here, they are already handled in SetAttrToMarked
195*cdf0e10cSrcweir 
196*cdf0e10cSrcweir         // set at selected objects
197*cdf0e10cSrcweir         SetAttrToMarked(rAttr, bReplaceAll);
198*cdf0e10cSrcweir 
199*cdf0e10cSrcweir         // old run
200*cdf0e10cSrcweir         const SdrMarkList& rMarkList = GetMarkedObjectList();
201*cdf0e10cSrcweir         const sal_uInt32 nMarkCnt(rMarkList.GetMarkCount());
202*cdf0e10cSrcweir 
203*cdf0e10cSrcweir         for(sal_uInt32 a(0); a < nMarkCnt; a++)
204*cdf0e10cSrcweir         {
205*cdf0e10cSrcweir             SdrObject* pObj = GetMarkedObjectByIndex(a);
206*cdf0e10cSrcweir             Imp_E3dView_InorderRun3DObjects(pObj, nSelectedItems);
207*cdf0e10cSrcweir         }
208*cdf0e10cSrcweir     }
209*cdf0e10cSrcweir 
210*cdf0e10cSrcweir     // DefaultValues pflegen
211*cdf0e10cSrcweir     if(!nSelectedItems && !pInScene)
212*cdf0e10cSrcweir     {
213*cdf0e10cSrcweir         // Defaults setzen
214*cdf0e10cSrcweir         SfxItemSet aDefaultSet(pMod->GetItemPool(), SDRATTR_3D_FIRST, SDRATTR_3D_LAST);
215*cdf0e10cSrcweir         aDefaultSet.Put(rAttr);
216*cdf0e10cSrcweir         SetAttributes(aDefaultSet);
217*cdf0e10cSrcweir 
218*cdf0e10cSrcweir     }
219*cdf0e10cSrcweir }
220*cdf0e10cSrcweir 
221*cdf0e10cSrcweir double E3dView::GetDefaultCamPosZ()
222*cdf0e10cSrcweir {
223*cdf0e10cSrcweir     return (double)((const SfxUInt32Item&)pMod->GetItemPool().GetDefaultItem(SDRATTR_3DSCENE_DISTANCE)).GetValue();
224*cdf0e10cSrcweir }
225*cdf0e10cSrcweir 
226*cdf0e10cSrcweir double E3dView::GetDefaultCamFocal()
227*cdf0e10cSrcweir {
228*cdf0e10cSrcweir     return (double)((const SfxUInt32Item&)pMod->GetItemPool().GetDefaultItem(SDRATTR_3DSCENE_FOCAL_LENGTH)).GetValue();
229*cdf0e10cSrcweir }
230*cdf0e10cSrcweir 
231