xref: /aoo41x/main/sd/source/ui/func/fucon3d.cxx (revision 79aad27f)
1*5b190011SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*5b190011SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*5b190011SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*5b190011SAndrew Rist  * distributed with this work for additional information
6*5b190011SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*5b190011SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*5b190011SAndrew Rist  * "License"); you may not use this file except in compliance
9*5b190011SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*5b190011SAndrew Rist  *
11*5b190011SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*5b190011SAndrew Rist  *
13*5b190011SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*5b190011SAndrew Rist  * software distributed under the License is distributed on an
15*5b190011SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*5b190011SAndrew Rist  * KIND, either express or implied.  See the License for the
17*5b190011SAndrew Rist  * specific language governing permissions and limitations
18*5b190011SAndrew Rist  * under the License.
19*5b190011SAndrew Rist  *
20*5b190011SAndrew Rist  *************************************************************/
21*5b190011SAndrew Rist 
22*5b190011SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sd.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "fucon3d.hxx"
28cdf0e10cSrcweir #include <vcl/waitobj.hxx>
29cdf0e10cSrcweir 
30cdf0e10cSrcweir #include <svx/svxids.hrc>
31cdf0e10cSrcweir #include <svl/aeitem.hxx>
32cdf0e10cSrcweir #include <sfx2/app.hxx>
33cdf0e10cSrcweir #include <sfx2/dispatch.hxx>
34cdf0e10cSrcweir #include <sfx2/viewfrm.hxx>
35cdf0e10cSrcweir #include <tools/poly.hxx>
36cdf0e10cSrcweir 
37cdf0e10cSrcweir #include <math.h>
38cdf0e10cSrcweir #include <svx/globl3d.hxx>
39cdf0e10cSrcweir #include <svx/scene3d.hxx>
40cdf0e10cSrcweir #include <svx/sphere3d.hxx>
41cdf0e10cSrcweir #include <svx/cube3d.hxx>
42cdf0e10cSrcweir #include <svx/lathe3d.hxx>
43cdf0e10cSrcweir #include <svx/camera3d.hxx>
44cdf0e10cSrcweir 
45cdf0e10cSrcweir #include "app.hrc"
46cdf0e10cSrcweir #include "res_bmp.hrc"
47cdf0e10cSrcweir #include "View.hxx"
48cdf0e10cSrcweir #include "Window.hxx"
49cdf0e10cSrcweir #include "ViewShell.hxx"
50cdf0e10cSrcweir #include "drawdoc.hxx"
51cdf0e10cSrcweir #include "ViewShellBase.hxx"
52cdf0e10cSrcweir #include "ToolBarManager.hxx"
53cdf0e10cSrcweir #include <svx/svx3ditems.hxx>
54cdf0e10cSrcweir 
55cdf0e10cSrcweir // #97016#
56cdf0e10cSrcweir #include <svx/polysc3d.hxx>
57cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygontools.hxx>
58cdf0e10cSrcweir 
59cdf0e10cSrcweir namespace sd {
60cdf0e10cSrcweir 
61cdf0e10cSrcweir TYPEINIT1( FuConstruct3dObject, FuConstruct );
62cdf0e10cSrcweir 
63cdf0e10cSrcweir /*************************************************************************
64cdf0e10cSrcweir |*
65cdf0e10cSrcweir |* Konstruktor
66cdf0e10cSrcweir |*
67cdf0e10cSrcweir \************************************************************************/
68cdf0e10cSrcweir 
FuConstruct3dObject(ViewShell * pViewSh,::sd::Window * pWin,::sd::View * pView,SdDrawDocument * pDoc,SfxRequest & rReq)69cdf0e10cSrcweir FuConstruct3dObject::FuConstruct3dObject (
70cdf0e10cSrcweir     ViewShell* 	pViewSh,
71cdf0e10cSrcweir     ::sd::Window*		pWin,
72cdf0e10cSrcweir     ::sd::View*			pView,
73cdf0e10cSrcweir     SdDrawDocument*	pDoc,
74cdf0e10cSrcweir     SfxRequest&		rReq)
75cdf0e10cSrcweir     : FuConstruct(pViewSh, pWin, pView, pDoc, rReq)
76cdf0e10cSrcweir {
77cdf0e10cSrcweir }
78cdf0e10cSrcweir 
Create(ViewShell * pViewSh,::sd::Window * pWin,::sd::View * pView,SdDrawDocument * pDoc,SfxRequest & rReq,bool bPermanent)79cdf0e10cSrcweir FunctionReference FuConstruct3dObject::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq, bool bPermanent )
80cdf0e10cSrcweir {
81cdf0e10cSrcweir 	FuConstruct3dObject* pFunc;
82cdf0e10cSrcweir 	FunctionReference xFunc( pFunc = new FuConstruct3dObject( pViewSh, pWin, pView, pDoc, rReq ) );
83cdf0e10cSrcweir 	xFunc->DoExecute(rReq);
84cdf0e10cSrcweir 	pFunc->SetPermanent(bPermanent);
85cdf0e10cSrcweir 	return xFunc;
86cdf0e10cSrcweir }
87cdf0e10cSrcweir 
DoExecute(SfxRequest & rReq)88cdf0e10cSrcweir void FuConstruct3dObject::DoExecute( SfxRequest& rReq )
89cdf0e10cSrcweir {
90cdf0e10cSrcweir 	FuConstruct::DoExecute( rReq );
91cdf0e10cSrcweir     mpViewShell->GetViewShellBase().GetToolBarManager()->SetToolBar(
92cdf0e10cSrcweir         ToolBarManager::TBG_FUNCTION,
93cdf0e10cSrcweir         ToolBarManager::msDrawingObjectToolBar);
94cdf0e10cSrcweir }
95cdf0e10cSrcweir 
96cdf0e10cSrcweir /*************************************************************************
97cdf0e10cSrcweir |*
98cdf0e10cSrcweir |* MouseButtonDown-event
99cdf0e10cSrcweir |*
100cdf0e10cSrcweir \************************************************************************/
101cdf0e10cSrcweir 
102cdf0e10cSrcweir // #97016#
ImpCreateBasic3DShape()103cdf0e10cSrcweir E3dCompoundObject* FuConstruct3dObject::ImpCreateBasic3DShape()
104cdf0e10cSrcweir {
105cdf0e10cSrcweir 	E3dCompoundObject* p3DObj = NULL;
106cdf0e10cSrcweir 
107cdf0e10cSrcweir 	switch (nSlotId)
108cdf0e10cSrcweir 	{
109cdf0e10cSrcweir 		default:
110cdf0e10cSrcweir 		case SID_3D_CUBE:
111cdf0e10cSrcweir 		{
112cdf0e10cSrcweir 			p3DObj = new E3dCubeObj(
113cdf0e10cSrcweir 				mpView->Get3DDefaultAttributes(),
114cdf0e10cSrcweir 				::basegfx::B3DPoint(-2500, -2500, -2500),
115cdf0e10cSrcweir 				::basegfx::B3DVector(5000, 5000, 5000));
116cdf0e10cSrcweir 			break;
117cdf0e10cSrcweir 		}
118cdf0e10cSrcweir 
119cdf0e10cSrcweir 		case SID_3D_SPHERE:
120cdf0e10cSrcweir 		{
121cdf0e10cSrcweir 			p3DObj = new E3dSphereObj(
122cdf0e10cSrcweir 				mpView->Get3DDefaultAttributes(),
123cdf0e10cSrcweir 				::basegfx::B3DPoint(0, 0, 0),
124cdf0e10cSrcweir 				::basegfx::B3DVector(5000, 5000, 5000));
125cdf0e10cSrcweir 			break;
126cdf0e10cSrcweir 		}
127cdf0e10cSrcweir 
128cdf0e10cSrcweir 		case SID_3D_SHELL:
129cdf0e10cSrcweir 		{
130cdf0e10cSrcweir 			XPolygon aXPoly(Point (0, 1250), 2500, 2500, 0, 900, sal_False);
131cdf0e10cSrcweir 			aXPoly.Scale(5.0, 5.0);
132cdf0e10cSrcweir 
133cdf0e10cSrcweir 			::basegfx::B2DPolygon aB2DPolygon(aXPoly.getB2DPolygon());
134cdf0e10cSrcweir 			if(aB2DPolygon.areControlPointsUsed())
135cdf0e10cSrcweir 			{
136cdf0e10cSrcweir 				aB2DPolygon = ::basegfx::tools::adaptiveSubdivideByAngle(aB2DPolygon);
137cdf0e10cSrcweir 			}
138cdf0e10cSrcweir 			p3DObj = new E3dLatheObj(mpView->Get3DDefaultAttributes(), ::basegfx::B2DPolyPolygon(aB2DPolygon));
139cdf0e10cSrcweir 
140cdf0e10cSrcweir 			// Dies ist ein offenes Objekt, muss daher defaultmaessig
141cdf0e10cSrcweir 			// doppelseitig behandelt werden
142cdf0e10cSrcweir 			p3DObj->SetMergedItem(Svx3DDoubleSidedItem(sal_True));
143cdf0e10cSrcweir 			break;
144cdf0e10cSrcweir 		}
145cdf0e10cSrcweir 
146cdf0e10cSrcweir 		case SID_3D_HALF_SPHERE:
147cdf0e10cSrcweir 		{
148cdf0e10cSrcweir 			XPolygon aXPoly(Point (0, 1250), 2500, 2500, 0, 900, sal_False);
149cdf0e10cSrcweir 			aXPoly.Scale(5.0, 5.0);
150cdf0e10cSrcweir 
151cdf0e10cSrcweir 			aXPoly.Insert(0, Point (2400*5, 1250*5), XPOLY_NORMAL);
152cdf0e10cSrcweir 			aXPoly.Insert(0, Point (2000*5, 1250*5), XPOLY_NORMAL);
153cdf0e10cSrcweir 			aXPoly.Insert(0, Point (1500*5, 1250*5), XPOLY_NORMAL);
154cdf0e10cSrcweir 			aXPoly.Insert(0, Point (1000*5, 1250*5), XPOLY_NORMAL);
155cdf0e10cSrcweir 			aXPoly.Insert(0, Point (500*5, 1250*5), XPOLY_NORMAL);
156cdf0e10cSrcweir 			aXPoly.Insert(0, Point (250*5, 1250*5), XPOLY_NORMAL);
157cdf0e10cSrcweir 			aXPoly.Insert(0, Point (50*5, 1250*5), XPOLY_NORMAL);
158cdf0e10cSrcweir 			aXPoly.Insert(0, Point (0*5, 1250*5), XPOLY_NORMAL);
159cdf0e10cSrcweir 
160cdf0e10cSrcweir 			::basegfx::B2DPolygon aB2DPolygon(aXPoly.getB2DPolygon());
161cdf0e10cSrcweir 			if(aB2DPolygon.areControlPointsUsed())
162cdf0e10cSrcweir 			{
163cdf0e10cSrcweir 				aB2DPolygon = ::basegfx::tools::adaptiveSubdivideByAngle(aB2DPolygon);
164cdf0e10cSrcweir 			}
165cdf0e10cSrcweir 			p3DObj = new E3dLatheObj(mpView->Get3DDefaultAttributes(), ::basegfx::B2DPolyPolygon(aB2DPolygon));
166cdf0e10cSrcweir 			break;
167cdf0e10cSrcweir 		}
168cdf0e10cSrcweir 
169cdf0e10cSrcweir 		case SID_3D_TORUS:
170cdf0e10cSrcweir 		{
171cdf0e10cSrcweir 			::basegfx::B2DPolygon aB2DPolygon(::basegfx::tools::createPolygonFromCircle(::basegfx::B2DPoint(1000.0, 0.0), 500.0));
172cdf0e10cSrcweir 			if(aB2DPolygon.areControlPointsUsed())
173cdf0e10cSrcweir 			{
174cdf0e10cSrcweir 				aB2DPolygon = ::basegfx::tools::adaptiveSubdivideByAngle(aB2DPolygon);
175cdf0e10cSrcweir 			}
176cdf0e10cSrcweir 			p3DObj = new E3dLatheObj(mpView->Get3DDefaultAttributes(), ::basegfx::B2DPolyPolygon(aB2DPolygon));
177cdf0e10cSrcweir 			break;
178cdf0e10cSrcweir 		}
179cdf0e10cSrcweir 
180cdf0e10cSrcweir 		case SID_3D_CYLINDER:
181cdf0e10cSrcweir 		{
182cdf0e10cSrcweir 			::basegfx::B2DPolygon aInnerPoly;
183cdf0e10cSrcweir 
184cdf0e10cSrcweir 			aInnerPoly.append(::basegfx::B2DPoint(0, 1000*5));
185cdf0e10cSrcweir 			aInnerPoly.append(::basegfx::B2DPoint(50*5, 1000*5));
186cdf0e10cSrcweir 			aInnerPoly.append(::basegfx::B2DPoint(100*5, 1000*5));
187cdf0e10cSrcweir 			aInnerPoly.append(::basegfx::B2DPoint(200*5, 1000*5));
188cdf0e10cSrcweir 			aInnerPoly.append(::basegfx::B2DPoint(300*5, 1000*5));
189cdf0e10cSrcweir 			aInnerPoly.append(::basegfx::B2DPoint(400*5, 1000*5));
190cdf0e10cSrcweir 			aInnerPoly.append(::basegfx::B2DPoint(450*5, 1000*5));
191cdf0e10cSrcweir 			aInnerPoly.append(::basegfx::B2DPoint(500*5, 1000*5));
192cdf0e10cSrcweir 			aInnerPoly.append(::basegfx::B2DPoint(500*5, -1000*5));
193cdf0e10cSrcweir 			aInnerPoly.append(::basegfx::B2DPoint(450*5, -1000*5));
194cdf0e10cSrcweir 			aInnerPoly.append(::basegfx::B2DPoint(400*5, -1000*5));
195cdf0e10cSrcweir 			aInnerPoly.append(::basegfx::B2DPoint(300*5, -1000*5));
196cdf0e10cSrcweir 			aInnerPoly.append(::basegfx::B2DPoint(200*5, -1000*5));
197cdf0e10cSrcweir 			aInnerPoly.append(::basegfx::B2DPoint(100*5, -1000*5));
198cdf0e10cSrcweir 			aInnerPoly.append(::basegfx::B2DPoint(50*5, -1000*5));
199cdf0e10cSrcweir 			aInnerPoly.append(::basegfx::B2DPoint(0*5, -1000*5));
200cdf0e10cSrcweir 			aInnerPoly.setClosed(true);
201cdf0e10cSrcweir 
202cdf0e10cSrcweir 			p3DObj = new E3dLatheObj(mpView->Get3DDefaultAttributes(), ::basegfx::B2DPolyPolygon(aInnerPoly));
203cdf0e10cSrcweir 			break;
204cdf0e10cSrcweir 		}
205cdf0e10cSrcweir 
206cdf0e10cSrcweir 		case SID_3D_CONE:
207cdf0e10cSrcweir 		{
208cdf0e10cSrcweir 			::basegfx::B2DPolygon aInnerPoly;
209cdf0e10cSrcweir 
210cdf0e10cSrcweir 			aInnerPoly.append(::basegfx::B2DPoint(0, -1000*5));
211cdf0e10cSrcweir 			aInnerPoly.append(::basegfx::B2DPoint(25*5, -900*5));
212cdf0e10cSrcweir 			aInnerPoly.append(::basegfx::B2DPoint(50*5, -800*5));
213cdf0e10cSrcweir 			aInnerPoly.append(::basegfx::B2DPoint(100*5, -600*5));
214cdf0e10cSrcweir 			aInnerPoly.append(::basegfx::B2DPoint(200*5, -200*5));
215cdf0e10cSrcweir 			aInnerPoly.append(::basegfx::B2DPoint(300*5, 200*5));
216cdf0e10cSrcweir 			aInnerPoly.append(::basegfx::B2DPoint(400*5, 600*5));
217cdf0e10cSrcweir 			aInnerPoly.append(::basegfx::B2DPoint(500*5, 1000*5));
218cdf0e10cSrcweir 			aInnerPoly.append(::basegfx::B2DPoint(400*5, 1000*5));
219cdf0e10cSrcweir 			aInnerPoly.append(::basegfx::B2DPoint(300*5, 1000*5));
220cdf0e10cSrcweir 			aInnerPoly.append(::basegfx::B2DPoint(200*5, 1000*5));
221cdf0e10cSrcweir 			aInnerPoly.append(::basegfx::B2DPoint(100*5, 1000*5));
222cdf0e10cSrcweir 			aInnerPoly.append(::basegfx::B2DPoint(50*5, 1000*5));
223cdf0e10cSrcweir 			aInnerPoly.append(::basegfx::B2DPoint(0*5, 1000*5));
224cdf0e10cSrcweir 			aInnerPoly.setClosed(true);
225cdf0e10cSrcweir 
226cdf0e10cSrcweir 			p3DObj = new E3dLatheObj(mpView->Get3DDefaultAttributes(), ::basegfx::B2DPolyPolygon(aInnerPoly));
227cdf0e10cSrcweir 			break;
228cdf0e10cSrcweir 		}
229cdf0e10cSrcweir 
230cdf0e10cSrcweir 		case SID_3D_PYRAMID:
231cdf0e10cSrcweir 		{
232cdf0e10cSrcweir 			::basegfx::B2DPolygon aInnerPoly;
233cdf0e10cSrcweir 
234cdf0e10cSrcweir 			aInnerPoly.append(::basegfx::B2DPoint(0, -1000*5));
235cdf0e10cSrcweir 			aInnerPoly.append(::basegfx::B2DPoint(25*5, -900*5));
236cdf0e10cSrcweir 			aInnerPoly.append(::basegfx::B2DPoint(50*5, -800*5));
237cdf0e10cSrcweir 			aInnerPoly.append(::basegfx::B2DPoint(100*5, -600*5));
238cdf0e10cSrcweir 			aInnerPoly.append(::basegfx::B2DPoint(200*5, -200*5));
239cdf0e10cSrcweir 			aInnerPoly.append(::basegfx::B2DPoint(300*5, 200*5));
240cdf0e10cSrcweir 			aInnerPoly.append(::basegfx::B2DPoint(400*5, 600*5));
241cdf0e10cSrcweir 			aInnerPoly.append(::basegfx::B2DPoint(500*5, 1000*5));
242cdf0e10cSrcweir 			aInnerPoly.append(::basegfx::B2DPoint(400*5, 1000*5));
243cdf0e10cSrcweir 			aInnerPoly.append(::basegfx::B2DPoint(300*5, 1000*5));
244cdf0e10cSrcweir 			aInnerPoly.append(::basegfx::B2DPoint(200*5, 1000*5));
245cdf0e10cSrcweir 			aInnerPoly.append(::basegfx::B2DPoint(100*5, 1000*5));
246cdf0e10cSrcweir 			aInnerPoly.append(::basegfx::B2DPoint(50*5, 1000*5));
247cdf0e10cSrcweir 			aInnerPoly.append(::basegfx::B2DPoint(0, 1000*5));
248cdf0e10cSrcweir 			aInnerPoly.setClosed(true);
249cdf0e10cSrcweir 
250cdf0e10cSrcweir 			p3DObj = new E3dLatheObj(mpView->Get3DDefaultAttributes(), ::basegfx::B2DPolyPolygon(aInnerPoly));
251cdf0e10cSrcweir 			p3DObj->SetMergedItem(Svx3DHorizontalSegmentsItem(4));
252cdf0e10cSrcweir 			break;
253cdf0e10cSrcweir 		}
254cdf0e10cSrcweir 	}
255cdf0e10cSrcweir 
256cdf0e10cSrcweir 	return p3DObj;
257cdf0e10cSrcweir }
258cdf0e10cSrcweir 
259cdf0e10cSrcweir // #97016#
ImpPrepareBasic3DShape(E3dCompoundObject * p3DObj,E3dScene * pScene)260cdf0e10cSrcweir void FuConstruct3dObject::ImpPrepareBasic3DShape(E3dCompoundObject* p3DObj, E3dScene *pScene)
261cdf0e10cSrcweir {
262cdf0e10cSrcweir 	Camera3D &aCamera  = (Camera3D&) pScene->GetCamera ();
263cdf0e10cSrcweir 
264cdf0e10cSrcweir 	// get transformed BoundVolume of the new object
265cdf0e10cSrcweir 	basegfx::B3DRange aBoundVol;
266cdf0e10cSrcweir 	basegfx::B3DRange aObjVol(p3DObj->GetBoundVolume());
267cdf0e10cSrcweir 	aObjVol.transform(p3DObj->GetTransform());
268cdf0e10cSrcweir 	aBoundVol.expand(aObjVol);
269cdf0e10cSrcweir 	double fDeepth(aBoundVol.getDepth());
270cdf0e10cSrcweir 
271cdf0e10cSrcweir 	aCamera.SetPRP(::basegfx::B3DPoint(0.0, 0.0, 1000.0));
272cdf0e10cSrcweir 	aCamera.SetPosition(::basegfx::B3DPoint(0.0, 0.0, mpView->GetDefaultCamPosZ() + fDeepth / 2));
273cdf0e10cSrcweir 	aCamera.SetFocalLength(mpView->GetDefaultCamFocal());
274cdf0e10cSrcweir 	pScene->SetCamera(aCamera);
275cdf0e10cSrcweir 	basegfx::B3DHomMatrix aTransformation;
276cdf0e10cSrcweir 
277cdf0e10cSrcweir 	switch (nSlotId)
278cdf0e10cSrcweir 	{
279cdf0e10cSrcweir 		case SID_3D_CUBE:
280cdf0e10cSrcweir 		{
281cdf0e10cSrcweir 			aTransformation.rotate(DEG2RAD(20), 0.0, 0.0);
282cdf0e10cSrcweir 		}
283cdf0e10cSrcweir 		break;
284cdf0e10cSrcweir 
285cdf0e10cSrcweir 		case SID_3D_SPHERE:
286cdf0e10cSrcweir 		{
287cdf0e10cSrcweir //				pScene->RotateX(DEG2RAD(60));
288cdf0e10cSrcweir 		}
289cdf0e10cSrcweir 		break;
290cdf0e10cSrcweir 
291cdf0e10cSrcweir 		case SID_3D_SHELL:
292cdf0e10cSrcweir 		case SID_3D_HALF_SPHERE:
293cdf0e10cSrcweir 		{
294cdf0e10cSrcweir 			aTransformation.rotate(DEG2RAD(200), 0.0, 0.0);
295cdf0e10cSrcweir 		}
296cdf0e10cSrcweir 		break;
297cdf0e10cSrcweir 
298cdf0e10cSrcweir 		case SID_3D_CYLINDER:
299cdf0e10cSrcweir 		case SID_3D_CONE:
300cdf0e10cSrcweir 		case SID_3D_PYRAMID:
301cdf0e10cSrcweir 		{
302cdf0e10cSrcweir //				pScene->RotateX(DEG2RAD(25));
303cdf0e10cSrcweir 		}
304cdf0e10cSrcweir 		break;
305cdf0e10cSrcweir 
306cdf0e10cSrcweir 		case SID_3D_TORUS:
307cdf0e10cSrcweir 		{
308cdf0e10cSrcweir //				pScene->RotateX(DEG2RAD(15));
309cdf0e10cSrcweir 			aTransformation.rotate(DEG2RAD(90), 0.0, 0.0);
310cdf0e10cSrcweir 		}
311cdf0e10cSrcweir 		break;
312cdf0e10cSrcweir 
313cdf0e10cSrcweir 		default:
314cdf0e10cSrcweir 		{
315cdf0e10cSrcweir 		}
316cdf0e10cSrcweir 		break;
317cdf0e10cSrcweir 	}
318cdf0e10cSrcweir 
319cdf0e10cSrcweir 	pScene->SetTransform(aTransformation * pScene->GetTransform());
320cdf0e10cSrcweir 
321cdf0e10cSrcweir 	SfxItemSet aAttr (mpViewShell->GetPool());
322cdf0e10cSrcweir 	pScene->SetMergedItemSetAndBroadcast(aAttr);
323cdf0e10cSrcweir }
324cdf0e10cSrcweir 
MouseButtonDown(const MouseEvent & rMEvt)325cdf0e10cSrcweir sal_Bool FuConstruct3dObject::MouseButtonDown(const MouseEvent& rMEvt)
326cdf0e10cSrcweir {
327cdf0e10cSrcweir 	sal_Bool bReturn = FuConstruct::MouseButtonDown(rMEvt);
328cdf0e10cSrcweir 
329cdf0e10cSrcweir 	if ( rMEvt.IsLeft() && !mpView->IsAction() )
330cdf0e10cSrcweir 	{
331cdf0e10cSrcweir 		Point aPnt( mpWindow->PixelToLogic( rMEvt.GetPosPixel() ) );
332cdf0e10cSrcweir 
333cdf0e10cSrcweir 		mpWindow->CaptureMouse();
334cdf0e10cSrcweir 		sal_uInt16 nDrgLog = sal_uInt16 ( mpWindow->PixelToLogic(Size(DRGPIX,0)).Width() );
335cdf0e10cSrcweir 
336cdf0e10cSrcweir 		E3dCompoundObject* p3DObj = NULL;
337cdf0e10cSrcweir 
338cdf0e10cSrcweir 		WaitObject aWait( (Window*)mpViewShell->GetActiveWindow() );
339cdf0e10cSrcweir 
340cdf0e10cSrcweir 		// #97016#
341cdf0e10cSrcweir 		p3DObj = ImpCreateBasic3DShape();
342cdf0e10cSrcweir 		E3dScene* pScene = mpView->SetCurrent3DObj(p3DObj);
343cdf0e10cSrcweir 
344cdf0e10cSrcweir 		// #97016#
345cdf0e10cSrcweir 		ImpPrepareBasic3DShape(p3DObj, pScene);
346cdf0e10cSrcweir 		bReturn = mpView->BegCreatePreparedObject(aPnt, nDrgLog, pScene);
347cdf0e10cSrcweir 
348cdf0e10cSrcweir 		SdrObject* pObj = mpView->GetCreateObj();
349cdf0e10cSrcweir 
350cdf0e10cSrcweir 		if (pObj)
351cdf0e10cSrcweir 		{
352cdf0e10cSrcweir 			SfxItemSet aAttr(mpDoc->GetPool());
353cdf0e10cSrcweir 			SetStyleSheet(aAttr, pObj);
354cdf0e10cSrcweir 
355cdf0e10cSrcweir 			// LineStyle rausnehmen
356cdf0e10cSrcweir 			aAttr.Put(XLineStyleItem (XLINE_NONE));
357cdf0e10cSrcweir 
358cdf0e10cSrcweir 			pObj->SetMergedItemSet(aAttr);
359cdf0e10cSrcweir 		}
360cdf0e10cSrcweir 	}
361cdf0e10cSrcweir 
362cdf0e10cSrcweir 	return bReturn;
363cdf0e10cSrcweir }
364cdf0e10cSrcweir 
365cdf0e10cSrcweir /*************************************************************************
366cdf0e10cSrcweir |*
367cdf0e10cSrcweir |* MouseMove-event
368cdf0e10cSrcweir |*
369cdf0e10cSrcweir \************************************************************************/
370cdf0e10cSrcweir 
MouseMove(const MouseEvent & rMEvt)371cdf0e10cSrcweir sal_Bool FuConstruct3dObject::MouseMove(const MouseEvent& rMEvt)
372cdf0e10cSrcweir {
373cdf0e10cSrcweir 	return FuConstruct::MouseMove(rMEvt);
374cdf0e10cSrcweir }
375cdf0e10cSrcweir 
376cdf0e10cSrcweir /*************************************************************************
377cdf0e10cSrcweir |*
378cdf0e10cSrcweir |* MouseButtonUp-event
379cdf0e10cSrcweir |*
380cdf0e10cSrcweir \************************************************************************/
381cdf0e10cSrcweir 
MouseButtonUp(const MouseEvent & rMEvt)382cdf0e10cSrcweir sal_Bool FuConstruct3dObject::MouseButtonUp(const MouseEvent& rMEvt)
383cdf0e10cSrcweir {
384cdf0e10cSrcweir 	sal_Bool bReturn = sal_False;
385cdf0e10cSrcweir 
386cdf0e10cSrcweir 	if ( mpView->IsCreateObj() && rMEvt.IsLeft() )
387cdf0e10cSrcweir 	{
388cdf0e10cSrcweir 		Point aPnt( mpWindow->PixelToLogic( rMEvt.GetPosPixel() ) );
389cdf0e10cSrcweir 		mpView->EndCreateObj(SDRCREATE_FORCEEND);
390cdf0e10cSrcweir 		bReturn = sal_True;
391cdf0e10cSrcweir 	}
392cdf0e10cSrcweir 
393cdf0e10cSrcweir 	bReturn = FuConstruct::MouseButtonUp(rMEvt) || bReturn;
394cdf0e10cSrcweir 
395cdf0e10cSrcweir 	if (!bPermanent)
396cdf0e10cSrcweir 		mpViewShell->GetViewFrame()->GetDispatcher()->Execute(SID_OBJECT_SELECT, SFX_CALLMODE_ASYNCHRON);
397cdf0e10cSrcweir 
398cdf0e10cSrcweir 	return bReturn;
399cdf0e10cSrcweir }
400cdf0e10cSrcweir 
401cdf0e10cSrcweir /*************************************************************************
402cdf0e10cSrcweir |*
403cdf0e10cSrcweir |* Tastaturereignisse bearbeiten
404cdf0e10cSrcweir |*
405cdf0e10cSrcweir |* Wird ein KeyEvent bearbeitet, so ist der Return-Wert sal_True, andernfalls
406cdf0e10cSrcweir |* sal_False.
407cdf0e10cSrcweir |*
408cdf0e10cSrcweir \************************************************************************/
409cdf0e10cSrcweir 
KeyInput(const KeyEvent & rKEvt)410cdf0e10cSrcweir sal_Bool FuConstruct3dObject::KeyInput(const KeyEvent& rKEvt)
411cdf0e10cSrcweir {
412cdf0e10cSrcweir 	return( FuConstruct::KeyInput(rKEvt) );
413cdf0e10cSrcweir }
414cdf0e10cSrcweir 
415cdf0e10cSrcweir /*************************************************************************
416cdf0e10cSrcweir |*
417cdf0e10cSrcweir |* Function aktivieren
418cdf0e10cSrcweir |*
419cdf0e10cSrcweir \************************************************************************/
420cdf0e10cSrcweir 
Activate()421cdf0e10cSrcweir void FuConstruct3dObject::Activate()
422cdf0e10cSrcweir {
423cdf0e10cSrcweir 	mpView->SetCurrentObj(OBJ_NONE);
424cdf0e10cSrcweir 
425cdf0e10cSrcweir 	FuConstruct::Activate();
426cdf0e10cSrcweir }
427cdf0e10cSrcweir 
428cdf0e10cSrcweir /*************************************************************************
429cdf0e10cSrcweir |*
430cdf0e10cSrcweir |* Function deaktivieren
431cdf0e10cSrcweir |*
432cdf0e10cSrcweir \************************************************************************/
433cdf0e10cSrcweir 
Deactivate()434cdf0e10cSrcweir void FuConstruct3dObject::Deactivate()
435cdf0e10cSrcweir {
436cdf0e10cSrcweir 	FuConstruct::Deactivate();
437cdf0e10cSrcweir }
438cdf0e10cSrcweir 
439cdf0e10cSrcweir // #97016#
CreateDefaultObject(const sal_uInt16 nID,const Rectangle & rRectangle)440cdf0e10cSrcweir SdrObject* FuConstruct3dObject::CreateDefaultObject(const sal_uInt16 nID, const Rectangle& rRectangle)
441cdf0e10cSrcweir {
442cdf0e10cSrcweir 	// case SID_3D_CUBE:
443cdf0e10cSrcweir 	// case SID_3D_SHELL:
444cdf0e10cSrcweir 	// case SID_3D_SPHERE:
445cdf0e10cSrcweir 	// case SID_3D_TORUS:
446cdf0e10cSrcweir 	// case SID_3D_HALF_SPHERE:
447cdf0e10cSrcweir 	// case SID_3D_CYLINDER:
448cdf0e10cSrcweir 	// case SID_3D_CONE:
449cdf0e10cSrcweir 	// case SID_3D_PYRAMID:
450cdf0e10cSrcweir 
451cdf0e10cSrcweir 	E3dCompoundObject* p3DObj = ImpCreateBasic3DShape();
452cdf0e10cSrcweir 
453cdf0e10cSrcweir 	// E3dView::SetCurrent3DObj part
454cdf0e10cSrcweir 	// get transformed BoundVolume of the object
455cdf0e10cSrcweir 	basegfx::B3DRange aObjVol(p3DObj->GetBoundVolume());
456cdf0e10cSrcweir 	aObjVol.transform(p3DObj->GetTransform());
457cdf0e10cSrcweir 	basegfx::B3DRange aVolume(aObjVol);
458cdf0e10cSrcweir 	double fW(aVolume.getWidth());
459cdf0e10cSrcweir 	double fH(aVolume.getHeight());
460cdf0e10cSrcweir 	Rectangle a3DRect(0, 0, (long)fW, (long)fH);
461cdf0e10cSrcweir 	E3dScene* pScene = new E3dPolyScene(mpView->Get3DDefaultAttributes());
462cdf0e10cSrcweir 
463cdf0e10cSrcweir 	// mpView->InitScene(pScene, fW, fH, aVolume.MaxVec().Z() + ((fW + fH) / 4.0));
464cdf0e10cSrcweir 	// copied code from E3dView::InitScene
465cdf0e10cSrcweir 	double fCamZ(aVolume.getMaxZ() + ((fW + fH) / 4.0));
466cdf0e10cSrcweir 	Camera3D aCam(pScene->GetCamera());
467cdf0e10cSrcweir 	aCam.SetAutoAdjustProjection(sal_False);
468cdf0e10cSrcweir 	aCam.SetViewWindow(- fW / 2, - fH / 2, fW, fH);
469cdf0e10cSrcweir 	::basegfx::B3DPoint aLookAt;
470cdf0e10cSrcweir 	double fDefaultCamPosZ = mpView->GetDefaultCamPosZ();
471cdf0e10cSrcweir 	::basegfx::B3DPoint aCamPos(0.0, 0.0, fCamZ < fDefaultCamPosZ ? fDefaultCamPosZ : fCamZ);
472cdf0e10cSrcweir 	aCam.SetPosAndLookAt(aCamPos, aLookAt);
473cdf0e10cSrcweir 	aCam.SetFocalLength(mpView->GetDefaultCamFocal());
474cdf0e10cSrcweir 	aCam.SetDefaults(::basegfx::B3DPoint(0.0, 0.0, fDefaultCamPosZ), aLookAt, mpView->GetDefaultCamFocal());
475cdf0e10cSrcweir 	pScene->SetCamera(aCam);
476cdf0e10cSrcweir 
477cdf0e10cSrcweir 	pScene->Insert3DObj(p3DObj);
478cdf0e10cSrcweir 	pScene->NbcSetSnapRect(a3DRect);
479cdf0e10cSrcweir 	pScene->SetModel(mpDoc);
480cdf0e10cSrcweir 
481cdf0e10cSrcweir 	ImpPrepareBasic3DShape(p3DObj, pScene);
482cdf0e10cSrcweir 
483cdf0e10cSrcweir 	SfxItemSet aAttr(mpDoc->GetPool());
484cdf0e10cSrcweir 	SetStyleSheet(aAttr, p3DObj);
485cdf0e10cSrcweir 	aAttr.Put(XLineStyleItem (XLINE_NONE));
486cdf0e10cSrcweir 	p3DObj->SetMergedItemSet(aAttr);
487cdf0e10cSrcweir 
488cdf0e10cSrcweir 	// make object interactive at once
489cdf0e10cSrcweir 	pScene->SetRectsDirty();
490cdf0e10cSrcweir 
491cdf0e10cSrcweir 	// Take care of restrictions for the rectangle
492cdf0e10cSrcweir 	Rectangle aRect(rRectangle);
493cdf0e10cSrcweir 
494cdf0e10cSrcweir 	switch(nID)
495cdf0e10cSrcweir 	{
496cdf0e10cSrcweir 		case SID_3D_CUBE:
497cdf0e10cSrcweir 		case SID_3D_SPHERE:
498cdf0e10cSrcweir 		case SID_3D_TORUS:
499cdf0e10cSrcweir 		{
500cdf0e10cSrcweir 			// force quadratic
501cdf0e10cSrcweir 			ImpForceQuadratic(aRect);
502cdf0e10cSrcweir 			break;
503cdf0e10cSrcweir 		}
504cdf0e10cSrcweir 
505cdf0e10cSrcweir 		case SID_3D_SHELL:
506cdf0e10cSrcweir 		case SID_3D_HALF_SPHERE:
507cdf0e10cSrcweir 		{
508cdf0e10cSrcweir 			// force horizontal layout
509cdf0e10cSrcweir 			break;
510cdf0e10cSrcweir 		}
511cdf0e10cSrcweir 
512cdf0e10cSrcweir 		case SID_3D_CYLINDER:
513cdf0e10cSrcweir 		case SID_3D_CONE:
514cdf0e10cSrcweir 		case SID_3D_PYRAMID:
515cdf0e10cSrcweir 		{
516cdf0e10cSrcweir 			// force vertical layout
517cdf0e10cSrcweir 			break;
518cdf0e10cSrcweir 		}
519cdf0e10cSrcweir 	}
520cdf0e10cSrcweir 
521cdf0e10cSrcweir 	// #97016#, #98245# use changed rectangle, not original one
522cdf0e10cSrcweir 	pScene->SetLogicRect(aRect);
523cdf0e10cSrcweir 
524cdf0e10cSrcweir 	return pScene;
525cdf0e10cSrcweir }
526cdf0e10cSrcweir 
527cdf0e10cSrcweir } // end of namespace sd
528