Line data Source code
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 "svx/svdstr.hrc"
22 : #include "svdglob.hxx"
23 : #include "svx/svditer.hxx"
24 :
25 : #include <stdlib.h>
26 : #include <svx/globl3d.hxx>
27 : #include <svx/svdpage.hxx>
28 : #include <svl/style.hxx>
29 : #include <svx/scene3d.hxx>
30 : #include <svx/e3dundo.hxx>
31 : #include <svx/svdtrans.hxx>
32 : #include <svx/svxids.hrc>
33 : #include <editeng/colritem.hxx>
34 : #include <svx/e3ditem.hxx>
35 : #include <svx/xlntrit.hxx>
36 : #include <svx/xfltrit.hxx>
37 : #include <svx/svx3ditems.hxx>
38 : #include <svl/whiter.hxx>
39 : #include <svx/xflftrit.hxx>
40 : #include <sdr/properties/e3dsceneproperties.hxx>
41 : #include <svx/sdr/contact/viewcontactofe3dscene.hxx>
42 : #include <svx/svddrag.hxx>
43 : #include <helperminimaldepth3d.hxx>
44 : #include <algorithm>
45 : #include <drawinglayer/geometry/viewinformation3d.hxx>
46 : #include <basegfx/polygon/b2dpolypolygontools.hxx>
47 : #include <svx/e3dsceneupdater.hxx>
48 : #include <svx/svdmodel.hxx>
49 :
50 :
51 :
52 : class ImpRemap3DDepth
53 : {
54 : sal_uInt32 mnOrdNum;
55 : double mfMinimalDepth;
56 :
57 : // bit field
58 : bool mbIsScene : 1;
59 :
60 : public:
61 : ImpRemap3DDepth(sal_uInt32 nOrdNum, double fMinimalDepth);
62 : ImpRemap3DDepth(sal_uInt32 nOrdNum);
63 : ~ImpRemap3DDepth();
64 :
65 : // for ::std::sort
66 : bool operator<(const ImpRemap3DDepth& rComp) const;
67 :
68 0 : sal_uInt32 GetOrdNum() const { return mnOrdNum; }
69 0 : bool IsScene() const { return mbIsScene; }
70 : };
71 :
72 0 : ImpRemap3DDepth::ImpRemap3DDepth(sal_uInt32 nOrdNum, double fMinimalDepth)
73 : : mnOrdNum(nOrdNum),
74 : mfMinimalDepth(fMinimalDepth),
75 0 : mbIsScene(false)
76 : {
77 0 : }
78 :
79 0 : ImpRemap3DDepth::ImpRemap3DDepth(sal_uInt32 nOrdNum)
80 : : mnOrdNum(nOrdNum),
81 : mfMinimalDepth(0.0),
82 0 : mbIsScene(true)
83 : {
84 0 : }
85 :
86 0 : ImpRemap3DDepth::~ImpRemap3DDepth()
87 : {
88 0 : }
89 :
90 0 : bool ImpRemap3DDepth::operator<(const ImpRemap3DDepth& rComp) const
91 : {
92 0 : if(IsScene())
93 : {
94 0 : return false;
95 : }
96 : else
97 : {
98 0 : if(rComp.IsScene())
99 : {
100 0 : return true;
101 : }
102 : else
103 : {
104 0 : return mfMinimalDepth < rComp.mfMinimalDepth;
105 : }
106 : }
107 : }
108 :
109 : // typedefs for a vector of ImpRemap3DDepths
110 : typedef ::std::vector< ImpRemap3DDepth > ImpRemap3DDepthVector;
111 :
112 :
113 :
114 : class Imp3DDepthRemapper
115 : {
116 : ImpRemap3DDepthVector maVector;
117 :
118 : public:
119 : Imp3DDepthRemapper(E3dScene& rScene);
120 : ~Imp3DDepthRemapper();
121 :
122 : sal_uInt32 RemapOrdNum(sal_uInt32 nOrdNum) const;
123 : };
124 :
125 0 : Imp3DDepthRemapper::Imp3DDepthRemapper(E3dScene& rScene)
126 : {
127 : // only called when rScene.GetSubList() and nObjCount > 1L
128 0 : SdrObjList* pList = rScene.GetSubList();
129 0 : const size_t nObjCount(pList->GetObjCount());
130 :
131 0 : for(size_t a = 0; a < nObjCount; ++a)
132 : {
133 0 : SdrObject* pCandidate = pList->GetObj(a);
134 :
135 0 : if(pCandidate)
136 : {
137 0 : if(pCandidate->ISA(E3dCompoundObject))
138 : {
139 : // single 3d object, calc depth
140 0 : const double fMinimalDepth(getMinimalDepthInViewCoordinates(static_cast< const E3dCompoundObject& >(*pCandidate)));
141 0 : ImpRemap3DDepth aEntry(a, fMinimalDepth);
142 0 : maVector.push_back(aEntry);
143 : }
144 : else
145 : {
146 : // scene, use standard entry for scene
147 0 : ImpRemap3DDepth aEntry(a);
148 0 : maVector.push_back(aEntry);
149 : }
150 : }
151 : }
152 :
153 : // now, we need to sort the maVector by it's members minimal depth. The
154 : // smaller, the nearer to the viewer.
155 0 : ::std::sort(maVector.begin(), maVector.end());
156 0 : }
157 :
158 0 : Imp3DDepthRemapper::~Imp3DDepthRemapper()
159 : {
160 0 : }
161 :
162 0 : sal_uInt32 Imp3DDepthRemapper::RemapOrdNum(sal_uInt32 nOrdNum) const
163 : {
164 0 : if(nOrdNum < maVector.size())
165 : {
166 0 : nOrdNum = maVector[(maVector.size() - 1) - nOrdNum].GetOrdNum();
167 : }
168 :
169 0 : return nOrdNum;
170 : }
171 :
172 :
173 : // BaseProperties section
174 :
175 1406 : sdr::properties::BaseProperties* E3dScene::CreateObjectSpecificProperties()
176 : {
177 1406 : return new sdr::properties::E3dSceneProperties(*this);
178 : }
179 :
180 :
181 : // DrawContact section
182 :
183 1406 : sdr::contact::ViewContact* E3dScene::CreateObjectSpecificViewContact()
184 : {
185 1406 : return new sdr::contact::ViewContactOfE3dScene(*this);
186 : }
187 :
188 :
189 :
190 1336135 : TYPEINIT1(E3dScene, E3dObject);
191 :
192 1406 : E3dScene::E3dScene()
193 : : E3dObject(),
194 : aCamera(basegfx::B3DPoint(0.0, 0.0, 4.0), basegfx::B3DPoint()),
195 : mp3DDepthRemapper(0L),
196 1406 : bDrawOnlySelected(false)
197 : {
198 : // Set defaults
199 1406 : E3dDefaultAttributes aDefault;
200 1406 : SetDefaultAttributes(aDefault);
201 1406 : }
202 :
203 0 : E3dScene::E3dScene(E3dDefaultAttributes& rDefault)
204 : : E3dObject(),
205 : aCamera(basegfx::B3DPoint(0.0, 0.0, 4.0), basegfx::B3DPoint()),
206 : mp3DDepthRemapper(0L),
207 0 : bDrawOnlySelected(false)
208 : {
209 : // Set defaults
210 0 : SetDefaultAttributes(rDefault);
211 0 : }
212 :
213 1406 : void E3dScene::SetDefaultAttributes(E3dDefaultAttributes& /*rDefault*/)
214 : {
215 : // For WIN95/NT turn off the FP-Exceptions
216 : #if defined(WNT)
217 : _control87( _MCW_EM, _MCW_EM );
218 : #endif
219 :
220 : // Set defaults
221 1406 : aCamera.SetViewWindow(-2, -2, 4, 4);
222 1406 : aCameraSet.SetDeviceRectangle(-2, 2, -2, 2);
223 1406 : aCamera.SetDeviceWindow(Rectangle(0, 0, 10, 10));
224 1406 : Rectangle aRect(0, 0, 10, 10);
225 1406 : aCameraSet.SetViewportRectangle(aRect);
226 :
227 : // set defaults for Camera from ItemPool
228 1406 : aCamera.SetProjection(GetPerspective());
229 1406 : basegfx::B3DPoint aActualPosition(aCamera.GetPosition());
230 1406 : double fNew = GetDistance();
231 :
232 1406 : if(fabs(fNew - aActualPosition.getZ()) > 1.0)
233 : {
234 1406 : aCamera.SetPosition( basegfx::B3DPoint( aActualPosition.getX(), aActualPosition.getY(), fNew) );
235 : }
236 :
237 1406 : fNew = GetFocalLength() / 100.0;
238 1406 : aCamera.SetFocalLength(fNew);
239 1406 : }
240 :
241 2812 : E3dScene::~E3dScene()
242 : {
243 1406 : ImpCleanup3DDepthMapper();
244 1406 : }
245 :
246 0 : basegfx::B2DPolyPolygon E3dScene::TakeXorPoly() const
247 : {
248 0 : const sdr::contact::ViewContactOfE3dScene& rVCScene = static_cast< sdr::contact::ViewContactOfE3dScene& >(GetViewContact());
249 0 : const drawinglayer::geometry::ViewInformation3D aViewInfo3D(rVCScene.getViewInformation3D());
250 0 : const basegfx::B3DPolyPolygon aCubePolyPolygon(CreateWireframe());
251 :
252 : basegfx::B2DPolyPolygon aRetval(basegfx::tools::createB2DPolyPolygonFromB3DPolyPolygon(aCubePolyPolygon,
253 0 : aViewInfo3D.getObjectToView()));
254 0 : aRetval.transform(rVCScene.getObjectTransformation());
255 :
256 0 : return aRetval;
257 : }
258 :
259 102844 : void E3dScene::ImpCleanup3DDepthMapper()
260 : {
261 102844 : if(mp3DDepthRemapper)
262 : {
263 0 : delete mp3DDepthRemapper;
264 0 : mp3DDepthRemapper = 0L;
265 : }
266 102844 : }
267 :
268 0 : sal_uInt32 E3dScene::RemapOrdNum(sal_uInt32 nNewOrdNum) const
269 : {
270 0 : if(!mp3DDepthRemapper)
271 : {
272 0 : const size_t nObjCount(GetSubList() ? GetSubList()->GetObjCount() : 0);
273 :
274 0 : if(nObjCount > 1)
275 : {
276 0 : ((E3dScene*)this)->mp3DDepthRemapper = new Imp3DDepthRemapper((E3dScene&)(*this));
277 : }
278 : }
279 :
280 0 : if(mp3DDepthRemapper)
281 : {
282 0 : return mp3DDepthRemapper->RemapOrdNum(nNewOrdNum);
283 : }
284 :
285 0 : return nNewOrdNum;
286 : }
287 :
288 0 : sal_uInt16 E3dScene::GetObjIdentifier() const
289 : {
290 0 : return E3D_SCENE_ID;
291 : }
292 :
293 10928 : void E3dScene::SetBoundRectDirty()
294 : {
295 10928 : E3dScene* pScene = GetScene();
296 :
297 10928 : if(pScene == this)
298 : {
299 : // avoid resetting aOutRect which in case of a 3D scene used as 2d object
300 : // is model data,not re-creatable view data
301 : }
302 : else
303 : {
304 : // if not the outmost scene it is used as group in 3d, call parent
305 4153 : E3dObject::SetBoundRectDirty();
306 : }
307 10928 : }
308 :
309 3287 : void E3dScene::NbcSetSnapRect(const Rectangle& rRect)
310 : {
311 3287 : SetRectsDirty();
312 3287 : E3dObject::NbcSetSnapRect(rRect);
313 3287 : aCamera.SetDeviceWindow(rRect);
314 3287 : aCameraSet.SetViewportRectangle((Rectangle&)rRect);
315 :
316 3287 : ImpCleanup3DDepthMapper();
317 3287 : }
318 :
319 144 : void E3dScene::NbcMove(const Size& rSize)
320 : {
321 144 : Rectangle aNewSnapRect = GetSnapRect();
322 144 : MoveRect(aNewSnapRect, rSize);
323 144 : NbcSetSnapRect(aNewSnapRect);
324 144 : }
325 :
326 0 : void E3dScene::NbcResize(const Point& rRef, const Fraction& rXFact,
327 : const Fraction& rYFact)
328 : {
329 0 : Rectangle aNewSnapRect = GetSnapRect();
330 0 : ResizeRect(aNewSnapRect, rRef, rXFact, rYFact);
331 0 : NbcSetSnapRect(aNewSnapRect);
332 0 : }
333 :
334 : // Set new camera, and thus mark the scene and if possible the bound volume
335 : // as changed
336 :
337 1459 : void E3dScene::SetCamera(const Camera3D& rNewCamera)
338 : {
339 : // Set old camera
340 1459 : aCamera = rNewCamera;
341 1459 : static_cast<sdr::properties::E3dSceneProperties&>(GetProperties()).SetSceneItemsFromCamera();
342 :
343 1459 : SetRectsDirty();
344 :
345 : // Fill new camera from old
346 1459 : Camera3D& rCam = (Camera3D&)GetCamera();
347 :
348 : // Turn off ratio
349 1459 : if(rCam.GetAspectMapping() == AS_NO_MAPPING)
350 1459 : GetCameraSet().SetRatio(0.0);
351 :
352 : // Set Imaging geometry
353 1459 : basegfx::B3DPoint aVRP(rCam.GetViewPoint());
354 2918 : basegfx::B3DVector aVPN(aVRP - rCam.GetVRP());
355 2918 : basegfx::B3DVector aVUV(rCam.GetVUV());
356 :
357 : // use SetViewportValues() to set VRP, VPN and VUV as vectors, too.
358 : // Else these values would not be exported/imported correctly.
359 1459 : GetCameraSet().SetViewportValues(aVRP, aVPN, aVUV);
360 :
361 : // Set perspective
362 1459 : GetCameraSet().SetPerspective(rCam.GetProjection() == PR_PERSPECTIVE);
363 1459 : GetCameraSet().SetViewportRectangle((Rectangle&)rCam.GetDeviceWindow());
364 :
365 2918 : ImpCleanup3DDepthMapper();
366 1459 : }
367 :
368 0 : void E3dScene::NewObjectInserted(const E3dObject* p3DObj)
369 : {
370 0 : E3dObject::NewObjectInserted(p3DObj);
371 :
372 0 : if ( p3DObj == this )
373 0 : return;
374 :
375 0 : ImpCleanup3DDepthMapper();
376 : }
377 :
378 : // Inform parent of changes of a child
379 :
380 92864 : void E3dScene::StructureChanged()
381 : {
382 92864 : E3dObject::StructureChanged();
383 :
384 92864 : if(!GetModel() || !GetModel()->isLocked())
385 : {
386 : // #i123539# optimization for 3D chart object generation: do not reset
387 : // already calculated scene projection data every time an object gets
388 : // initialized
389 0 : SetRectsDirty();
390 : }
391 :
392 92864 : ImpCleanup3DDepthMapper();
393 92864 : }
394 :
395 : // Determine the overall scene object
396 :
397 240941 : E3dScene* E3dScene::GetScene() const
398 : {
399 240941 : if(GetParentObj())
400 181163 : return GetParentObj()->GetScene();
401 : else
402 59778 : return (E3dScene*)this;
403 : }
404 :
405 0 : void E3dScene::removeAllNonSelectedObjects()
406 : {
407 0 : E3DModifySceneSnapRectUpdater aUpdater(this);
408 :
409 0 : for(size_t a = 0; a < maSubList.GetObjCount(); ++a)
410 : {
411 0 : SdrObject* pObj = maSubList.GetObj(a);
412 :
413 0 : if(pObj)
414 : {
415 0 : bool bRemoveObject(false);
416 :
417 0 : if(pObj->ISA(E3dScene))
418 : {
419 0 : E3dScene* pScene = static_cast<E3dScene*>(pObj);
420 :
421 : // iterate over this sub-scene
422 0 : pScene->removeAllNonSelectedObjects();
423 :
424 : // check object count. Empty scenes can be deleted
425 0 : const size_t nObjCount(pScene->GetSubList() ? pScene->GetSubList()->GetObjCount() : 0);
426 :
427 0 : if(!nObjCount)
428 : {
429 : // all objects removed, scene can be removed, too
430 0 : bRemoveObject = true;
431 : }
432 : }
433 0 : else if(pObj->ISA(E3dCompoundObject))
434 : {
435 0 : E3dCompoundObject* pCompound = static_cast<E3dCompoundObject*>(pObj);
436 :
437 0 : if(!pCompound->GetSelected())
438 : {
439 0 : bRemoveObject = true;
440 : }
441 : }
442 :
443 0 : if(bRemoveObject)
444 : {
445 0 : maSubList.NbcRemoveObject(pObj->GetOrdNum());
446 0 : a--;
447 0 : SdrObject::Free(pObj);
448 : }
449 : }
450 0 : }
451 0 : }
452 :
453 0 : E3dScene* E3dScene::Clone() const
454 : {
455 0 : return CloneHelper< E3dScene >();
456 : }
457 :
458 0 : E3dScene& E3dScene::operator=(const E3dScene& rObj)
459 : {
460 0 : if( this == &rObj )
461 0 : return *this;
462 0 : E3dObject::operator=(rObj);
463 :
464 0 : const E3dScene& r3DObj = (const E3dScene&) rObj;
465 0 : aCamera = r3DObj.aCamera;
466 :
467 0 : aCameraSet = r3DObj.aCameraSet;
468 0 : static_cast<sdr::properties::E3dSceneProperties&>(GetProperties()).SetSceneItemsFromCamera();
469 :
470 0 : InvalidateBoundVolume();
471 0 : RebuildLists();
472 0 : SetRectsDirty();
473 :
474 0 : ImpCleanup3DDepthMapper();
475 :
476 : // #i101941#
477 : // After a Scene as model object is cloned, the used
478 : // ViewContactOfE3dScene is created and partially used
479 : // to calculate Bound/SnapRects, but - since quite some
480 : // values are buffered at the VC - not really well
481 : // initialized. It would be possible to always watch for
482 : // preconditions of buffered data, but this would be expensive
483 : // and would create a lot of short living data structures.
484 : // It is currently better to flush that data, e.g. by using
485 : // ActionChanged at the VC which will for this class
486 : // flush that cached data and initalize it's valid reconstruction
487 0 : GetViewContact().ActionChanged();
488 0 : return *this;
489 : }
490 :
491 : // Rebuild Light- and label- object lists rebuild (after loading, allocation)
492 :
493 0 : void E3dScene::RebuildLists()
494 : {
495 : // first delete
496 0 : SdrLayerID nCurrLayerID = GetLayer();
497 :
498 0 : SdrObjListIter a3DIterator(maSubList, IM_FLAT);
499 :
500 : // then examine all the objects in the scene
501 0 : while ( a3DIterator.IsMore() )
502 : {
503 0 : E3dObject* p3DObj = static_cast<E3dObject*>(a3DIterator.Next());
504 0 : p3DObj->NbcSetLayer(nCurrLayerID);
505 0 : NewObjectInserted(p3DObj);
506 0 : }
507 0 : }
508 :
509 0 : SdrObjGeoData *E3dScene::NewGeoData() const
510 : {
511 0 : return new E3DSceneGeoData;
512 : }
513 :
514 0 : void E3dScene::SaveGeoData(SdrObjGeoData& rGeo) const
515 : {
516 0 : E3dObject::SaveGeoData (rGeo);
517 :
518 0 : static_cast<E3DSceneGeoData &>(rGeo).aCamera = aCamera;
519 0 : }
520 :
521 0 : void E3dScene::RestGeoData(const SdrObjGeoData& rGeo)
522 : {
523 : // #i94832# removed E3DModifySceneSnapRectUpdater here.
524 : // It should not be needed, is already part of E3dObject::RestGeoData
525 0 : E3dObject::RestGeoData (rGeo);
526 0 : SetCamera (static_cast<const E3DSceneGeoData &>(rGeo).aCamera);
527 0 : }
528 :
529 : // Something was changed in the style sheet, so change scene
530 :
531 0 : void E3dScene::Notify(SfxBroadcaster &rBC, const SfxHint &rHint)
532 : {
533 0 : SetRectsDirty();
534 0 : E3dObject::Notify(rBC, rHint);
535 0 : }
536 :
537 0 : void E3dScene::RotateScene (const Point& rRef, long /*nWink*/, double sn, double cs)
538 : {
539 0 : Point UpperLeft, LowerRight, Center, NewCenter;
540 :
541 0 : UpperLeft = aOutRect.TopLeft();
542 0 : LowerRight = aOutRect.BottomRight();
543 :
544 0 : long dxOutRectHalf = labs(UpperLeft.X() - LowerRight.X());
545 0 : dxOutRectHalf /= 2;
546 0 : long dyOutRectHalf = labs(UpperLeft.Y() - LowerRight.Y());
547 0 : dyOutRectHalf /= 2;
548 :
549 : // Only the center is moved. The corners are moved by NbcMove. For the
550 : // rotation a cartesian coordinate system is used in which the pivot
551 : // point is the origin, and the y-axis increases upward, the X-axis to
552 : // the right. This must be especially noted for the Y-values.
553 : // (When considering a flat piece of paper the Y-axis pointing downwards
554 0 : Center.X() = (UpperLeft.X() + dxOutRectHalf) - rRef.X();
555 0 : Center.Y() = -((UpperLeft.Y() + dyOutRectHalf) - rRef.Y());
556 : // A few special cases has to be dealt with first (n * 90 degrees n integer)
557 0 : if (sn==1.0 && cs==0.0) { // 90deg
558 0 : NewCenter.X() = -Center.Y();
559 0 : NewCenter.Y() = -Center.X();
560 0 : } else if (sn==0.0 && cs==-1.0) { // 180deg
561 0 : NewCenter.X() = -Center.X();
562 0 : NewCenter.Y() = -Center.Y();
563 0 : } else if (sn==-1.0 && cs==0.0) { // 270deg
564 0 : NewCenter.X() = Center.Y();
565 0 : NewCenter.Y() = -Center.X();
566 : }
567 : else // Here it is rotated to any angle in the mathematically
568 : // positive direction!
569 : { // xnew = x * cos(alpha) - y * sin(alpha)
570 : // ynew = x * sin(alpha) + y * cos(alpha)
571 : // Bottom Right is not rotated: the pages of aOutRect must
572 : // remain parallel to the coordinate axes.
573 0 : NewCenter.X() = (long) (Center.X() * cs - Center.Y() * sn);
574 0 : NewCenter.Y() = (long) (Center.X() * sn + Center.Y() * cs);
575 : }
576 :
577 0 : Size Differenz;
578 0 : Point DiffPoint = (NewCenter - Center);
579 0 : Differenz.Width() = DiffPoint.X();
580 0 : Differenz.Height() = -DiffPoint.Y(); // Note that the Y-axis is counted ad positive downward.
581 0 : NbcMove (Differenz); // Actually executes the coordinate transformation.
582 0 : }
583 :
584 0 : OUString E3dScene::TakeObjNameSingul() const
585 : {
586 0 : OUStringBuffer sName(ImpGetResStr(STR_ObjNameSingulScene3d));
587 :
588 0 : OUString aName(GetName());
589 0 : if (!aName.isEmpty())
590 : {
591 0 : sName.append(' ');
592 0 : sName.append('\'');
593 0 : sName.append(aName);
594 0 : sName.append('\'');
595 : }
596 0 : return sName.makeStringAndClear();
597 : }
598 :
599 0 : OUString E3dScene::TakeObjNamePlural() const
600 : {
601 0 : return ImpGetResStr(STR_ObjNamePluralScene3d);
602 : }
603 :
604 : // The NbcRotate routine overloads the one of the SdrObject. The idea is
605 : // to be able to rotate the scene relative to the position of the scene
606 : // and then the objects in the scene
607 :
608 195 : void E3dScene::NbcSetTransform(const basegfx::B3DHomMatrix& rMatrix)
609 : {
610 195 : if(maTransformation != rMatrix)
611 : {
612 : // call parent
613 195 : E3dObject::NbcSetTransform(rMatrix);
614 : }
615 195 : }
616 :
617 1624 : void E3dScene::SetTransform(const basegfx::B3DHomMatrix& rMatrix)
618 : {
619 1624 : if(rMatrix != maTransformation)
620 : {
621 : // call parent
622 195 : E3dObject::SetTransform(rMatrix);
623 : }
624 1624 : }
625 :
626 0 : void E3dScene::NbcRotate(const Point& rRef, long nWink, double sn, double cs)
627 : {
628 : // So currently the glue points are defined relative to the scene aOutRect.
629 : // Before turning the glue points are defined relative to the page. They
630 : // take no part in the rotation of the scene. To ensure this, there is the
631 : // SetGlueReallyAbsolute(sal_True);
632 :
633 : // So that was the scene, now the objects used in the scene
634 : // 3D objects, if there is only one it can still have multiple surfaces but
635 : // the surfaces do not hve to be connected. This allows you to access child
636 : // objects. So going through the entire list and rotate around the Z axis
637 : // through the enter of aOutRect's (Steiner's theorem), so RotateZ
638 :
639 0 : RotateScene (rRef, nWink, sn, cs); // Rotates the scene
640 0 : double fWinkelInRad = nWink/100.0 * F_PI180;
641 :
642 0 : basegfx::B3DHomMatrix aRotation;
643 0 : aRotation.rotate(0.0, 0.0, fWinkelInRad);
644 0 : NbcSetTransform(aRotation * GetTransform());
645 :
646 0 : SetRectsDirty(); // This forces a recalculation of all BoundRects
647 0 : NbcRotateGluePoints(rRef,nWink,sn,cs); // Rotate the glue points (who still
648 : // have coordinates relative to the
649 : // original page)
650 0 : SetGlueReallyAbsolute(false); // from now they are again relative to BoundRect (that is defined as aOutRect)
651 0 : SetRectsDirty();
652 0 : }
653 :
654 1955 : void E3dScene::RecalcSnapRect()
655 : {
656 1955 : E3dScene* pScene = GetScene();
657 :
658 1955 : if(pScene == this)
659 : {
660 : // The Scene is used as a 2D-Objekt, take the SnapRect from the
661 : // 2D Display settings
662 586 : Camera3D& rCam = (Camera3D&)pScene->GetCamera();
663 586 : maSnapRect = rCam.GetDeviceWindow();
664 : }
665 : else
666 : {
667 : // The Scene itself is a member of another scene, get the SnapRect
668 : // as a composite object
669 1369 : E3dObject::RecalcSnapRect();
670 : }
671 1955 : }
672 :
673 0 : bool E3dScene::IsBreakObjPossible()
674 : {
675 : // Break scene, if all members are able to break
676 0 : SdrObjListIter a3DIterator(maSubList, IM_DEEPWITHGROUPS);
677 :
678 0 : while ( a3DIterator.IsMore() )
679 : {
680 0 : E3dObject* pObj = static_cast<E3dObject*>(a3DIterator.Next());
681 : DBG_ASSERT(pObj->ISA(E3dObject), "only 3D objects are allowed in scenes!");
682 0 : if(!pObj->IsBreakObjPossible())
683 0 : return false;
684 : }
685 :
686 0 : return true;
687 : }
688 :
689 0 : basegfx::B2DPolyPolygon E3dScene::TakeCreatePoly(const SdrDragStat& /*rDrag*/) const
690 : {
691 0 : return TakeXorPoly();
692 : }
693 :
694 0 : bool E3dScene::BegCreate(SdrDragStat& rStat)
695 : {
696 0 : rStat.SetOrtho4Possible();
697 0 : Rectangle aRect1(rStat.GetStart(), rStat.GetNow());
698 0 : aRect1.Justify();
699 0 : rStat.SetActionRect(aRect1);
700 0 : NbcSetSnapRect(aRect1);
701 0 : return true;
702 : }
703 :
704 0 : bool E3dScene::MovCreate(SdrDragStat& rStat)
705 : {
706 0 : Rectangle aRect1;
707 0 : rStat.TakeCreateRect(aRect1);
708 0 : aRect1.Justify();
709 0 : rStat.SetActionRect(aRect1);
710 0 : NbcSetSnapRect(aRect1);
711 0 : SetBoundRectDirty();
712 0 : bSnapRectDirty=true;
713 0 : return true;
714 : }
715 :
716 0 : bool E3dScene::EndCreate(SdrDragStat& rStat, SdrCreateCmd eCmd)
717 : {
718 0 : Rectangle aRect1;
719 0 : rStat.TakeCreateRect(aRect1);
720 0 : aRect1.Justify();
721 0 : NbcSetSnapRect(aRect1);
722 0 : SetRectsDirty();
723 0 : return (eCmd==SDRCREATE_FORCEEND || rStat.GetPointAnz()>=2);
724 : }
725 :
726 0 : bool E3dScene::BckCreate(SdrDragStat& /*rStat*/)
727 : {
728 0 : return false;
729 : }
730 :
731 0 : void E3dScene::BrkCreate(SdrDragStat& /*rStat*/)
732 : {
733 651 : }
734 :
735 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|