LibreOffice Module svx (master) 1
viewcontactofe3dscene.cxx
Go to the documentation of this file.
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
31
32using namespace com::sun::star;
33
34namespace {
35
36// pActiveVC is only true if ghosted is still activated and maybe needs to be switched off in this path
37void createSubPrimitive3DVector(
38 const sdr::contact::ViewContact& rCandidate,
41 const SdrLayerIDSet* pVisibleSdrLayerIDSet,
42 const bool bTestSelectedVisibility)
43{
44 const sdr::contact::ViewContactOfE3dScene* pViewContactOfE3dScene = dynamic_cast< const sdr::contact::ViewContactOfE3dScene* >(&rCandidate);
45
46 if(pViewContactOfE3dScene)
47 {
48 const sal_uInt32 nChildrenCount(rCandidate.GetObjectCount());
49
50 if(nChildrenCount)
51 {
52 // provide new collection sequences
55
56 // add children recursively
57 for(sal_uInt32 a(0); a < nChildrenCount; a++)
58 {
59 createSubPrimitive3DVector(
60 rCandidate.GetViewContact(a),
61 aNewAllTarget,
62 o_pVisibleTarget ? &aNewVisibleTarget : nullptr,
63 pVisibleSdrLayerIDSet,
64 bTestSelectedVisibility);
65 }
66
67 // create transform primitive for the created content combining content and transformtion
69 pViewContactOfE3dScene->GetE3dScene().GetTransform(),
70 aNewAllTarget));
71
72 // add created content to all target
73 o_rAllTarget.push_back(xReference);
74
75 // add created content to visible target if exists
76 if(o_pVisibleTarget)
77 {
78 o_pVisibleTarget->push_back(xReference);
79 }
80 }
81 }
82 else
83 {
84 // access view independent representation of rCandidate
85 const sdr::contact::ViewContactOfE3d* pViewContactOfE3d = dynamic_cast< const sdr::contact::ViewContactOfE3d* >(&rCandidate);
86
87 if(pViewContactOfE3d)
88 {
90
91 if(!xPrimitive3DSeq.empty())
92 {
93 // add to all target vector
94 o_rAllTarget.append(xPrimitive3DSeq);
95
96 if(o_pVisibleTarget)
97 {
98 // test visibility. Primitive is visible when both tests are true (AND)
99 bool bVisible(true);
100
101 if(pVisibleSdrLayerIDSet)
102 {
103 // test layer visibility
104 const E3dObject& rE3dObject = pViewContactOfE3d->GetE3dObject();
105 const SdrLayerID aLayerID(rE3dObject.GetLayer());
106
107 bVisible = pVisibleSdrLayerIDSet->IsSet(aLayerID);
108 }
109
110 if(bVisible && bTestSelectedVisibility)
111 {
112 // test selected visibility (see 3D View's DrawMarkedObj implementation)
113 const E3dObject& rE3dObject = pViewContactOfE3d->GetE3dObject();
114
115 bVisible = rE3dObject.GetSelected();
116 }
117
118 if (bVisible)
119 {
120 // add to visible target vector
121 o_pVisibleTarget->append(xPrimitive3DSeq);
122 }
123 }
124 }
125 }
126 }
127}
128
129}
130
131namespace sdr::contact {
132
133// Create an Object-Specific ViewObjectContact, set ViewContact and
134// ObjectContact. Always needs to return something.
136{
137 ViewObjectContact* pRetval = new ViewObjectContactOfE3dScene(rObjectContact, *this);
138 DBG_ASSERT(pRetval, "ViewContactOfE3dScene::CreateObjectSpecificViewObjectContact() failed (!)");
139
140 return *pRetval;
141}
142
144: ViewContactOfSdrObj(rScene)
145{
146}
147
149{
150 basegfx::B3DHomMatrix aTransformation;
151 basegfx::B3DHomMatrix aOrientation;
152 basegfx::B3DHomMatrix aProjection;
153 basegfx::B3DHomMatrix aDeviceToView;
154
155 // create transformation (scene as group's transformation)
156 // For historical reasons, the outmost scene's transformation is handles as part of the
157 // view transformation. This means that the BoundRect of the contained 3D Objects is
158 // without that transformation and makes it necessary to NOT add the first scene to the
159 // Primitive3DContainer of contained objects.
160 {
161 aTransformation = GetE3dScene().GetTransform();
162 }
163
164 // create orientation (world to camera coordinate system)
165 {
166 // calculate orientation from VRP, VPN and VUV
167 const B3dCamera& rSceneCamera = GetE3dScene().GetCameraSet();
168 const basegfx::B3DPoint& aVRP(rSceneCamera.GetVRP());
169 const basegfx::B3DVector& aVPN(rSceneCamera.GetVPN());
170 const basegfx::B3DVector& aVUV(rSceneCamera.GetVUV());
171
172 aOrientation.orientation(aVRP, aVPN, aVUV);
173 }
174
175 // create projection (camera coordinate system to relative 2d where X,Y and Z are [0.0 .. 1.0])
176 {
177 const basegfx::B3DHomMatrix aWorldToCamera(aOrientation * aTransformation);
178 basegfx::B3DRange aCameraRange(rContentRange);
179 aCameraRange.transform(aWorldToCamera);
180
181 // remember Z-Values, but change orientation
182 const double fMinZ(-aCameraRange.getMaxZ());
183 const double fMaxZ(-aCameraRange.getMinZ());
184
185 // construct temporary matrix from world to device. Use unit values here to measure expansion
186 basegfx::B3DHomMatrix aWorldToDevice(aWorldToCamera);
188
189 if(css::drawing::ProjectionMode_PERSPECTIVE == rSdrSceneAttribute.getProjectionMode())
190 {
191 aWorldToDevice.frustum(-1.0, 1.0, -1.0, 1.0, fMinZ, fMaxZ);
192 }
193 else
194 {
195 aWorldToDevice.ortho(-1.0, 1.0, -1.0, 1.0, fMinZ, fMaxZ);
196 }
197
198 // create B3DRange in device. This will create the real used ranges
199 // in camera space. Do not use the Z-Values, though.
200 basegfx::B3DRange aDeviceRange(rContentRange);
201 aDeviceRange.transform(aWorldToDevice);
202
203 // set projection
204 if(css::drawing::ProjectionMode_PERSPECTIVE == rSdrSceneAttribute.getProjectionMode())
205 {
206 aProjection.frustum(
207 aDeviceRange.getMinX(), aDeviceRange.getMaxX(),
208 aDeviceRange.getMinY(), aDeviceRange.getMaxY(),
209 fMinZ, fMaxZ);
210 }
211 else
212 {
213 aProjection.ortho(
214 aDeviceRange.getMinX(), aDeviceRange.getMaxX(),
215 aDeviceRange.getMinY(), aDeviceRange.getMaxY(),
216 fMinZ, fMaxZ);
217 }
218 }
219
220 // create device to view transform
221 {
222 // create standard deviceToView projection for geometry
223 // input is [-1.0 .. 1.0] in X,Y and Z. bring to [0.0 .. 1.0]. Also
224 // necessary to flip Y due to screen orientation
225 // Z is not needed, but will also be brought to [0.0 .. 1.0]
226 aDeviceToView.scale(0.5, -0.5, 0.5);
227 aDeviceToView.translate(0.5, 0.5, 0.5);
228 }
229
230 const uno::Sequence< beans::PropertyValue > aEmptyProperties;
232 aTransformation, aOrientation, aProjection,
233 aDeviceToView, 0.0, aEmptyProperties);
234}
235
237{
238 // create 2d Object Transformation from relative point in 2d scene to world
239 const tools::Rectangle aRectangle(GetE3dScene().GetSnapRect());
240
241 maObjectTransformation.set(0, 0, aRectangle.getOpenWidth());
242 maObjectTransformation.set(1, 1, aRectangle.getOpenHeight());
243 maObjectTransformation.set(0, 2, aRectangle.Left());
244 maObjectTransformation.set(1, 2, aRectangle.Top());
245}
246
248{
249 const SfxItemSet& rItemSet = GetE3dScene().GetMergedItemSet();
251}
252
254{
255 const SfxItemSet& rItemSet = GetE3dScene().GetMergedItemSet();
257}
258
260 const SdrLayerIDSet* pLayerVisibility) const
261{
263 const sal_uInt32 nChildrenCount(GetObjectCount());
264
265 if(nChildrenCount)
266 {
267 // create 3d scene primitive with visible content tested against rLayerVisibility
270 const bool bTestLayerVisibility(nullptr != pLayerVisibility);
271 const bool bTestSelectedVisibility(GetE3dScene().GetDrawOnlySelected());
272 const bool bTestVisibility(bTestLayerVisibility || bTestSelectedVisibility);
273
274 // add children recursively. Do NOT start with (*this), this would create
275 // a 3D transformPrimitive for the start scene. While this is theoretically not
276 // a bad thing, for historical reasons the transformation of the outmost scene
277 // is seen as part of the ViewTransformation (see text in createViewInformation3D)
278 for(sal_uInt32 a(0); a < nChildrenCount; a++)
279 {
280 createSubPrimitive3DVector(
282 aAllSequence,
283 bTestLayerVisibility ? &aVisibleSequence : nullptr,
284 bTestLayerVisibility ? pLayerVisibility : nullptr,
285 bTestSelectedVisibility);
286 }
287
288 const size_t nAllSize(!aAllSequence.empty() ? aAllSequence.size() : 0);
289 const size_t nVisibleSize(!aVisibleSequence.empty() ? aVisibleSequence.size() : 0);
290
291 if((bTestVisibility && nVisibleSize) || nAllSize)
292 {
293 // for getting the 3D range using getB3DRangeFromPrimitive3DContainer a ViewInformation3D
294 // needs to be given for evtl. decompositions. At the same time createViewInformation3D
295 // currently is based on creating the target-ViewInformation3D using a given range. To
296 // get the true range, use a neutral ViewInformation3D here. This leaves all matrices
297 // on identity and the time on 0.0.
298 const uno::Sequence< beans::PropertyValue > aEmptyProperties;
299 const drawinglayer::geometry::ViewInformation3D aNeutralViewInformation3D(aEmptyProperties);
300 const basegfx::B3DRange aContentRange(aAllSequence.getB3DRange(aNeutralViewInformation3D));
301
302 // create 2d primitive 3dscene with generated sub-list from collector
305 bTestVisibility ? aVisibleSequence : aAllSequence,
309 getViewInformation3D(aContentRange)));
310
312 }
313 }
314
315 // always append an invisible outline for the cases where no visible content exists
316 xRetval.push_back(
319
320 return xRetval;
321}
322
324{
325 if(GetObjectCount())
326 {
327 // create a default ScenePrimitive2D (without visibility test of members)
328 rVisitor.visit(createScenePrimitive2DSequence(nullptr));
329 }
330}
331
333{
334 // call parent
336
337 // mark locally cached values as invalid
342}
343
345{
347 {
348 // this version will create the content range on demand locally and thus is less
349 // performant than the other one. Since the information is buffered the planned
350 // behaviour is that the version with the given range is used initially.
352
353 if(aContentRange.isEmpty())
354 {
355 // empty scene, no 3d action should be necessary. Prepare some
356 // fallback size
357 OSL_FAIL("No need to get ViewInformation3D from an empty scene (!)");
358 aContentRange.expand(basegfx::B3DPoint(-100.0, -100.0, -100.0));
359 aContentRange.expand(basegfx::B3DPoint( 100.0, 100.0, 100.0));
360 }
361
362 const_cast < ViewContactOfE3dScene* >(this)->createViewInformation3D(aContentRange);
363 }
364
365 return maViewInformation3D;
366}
367
369{
371 {
372 const_cast < ViewContactOfE3dScene* >(this)->createViewInformation3D(rContentRange);
373 }
374
375 return maViewInformation3D;
376}
377
379{
381 {
382 const_cast < ViewContactOfE3dScene* >(this)->createObjectTransformation();
383 }
384
386}
387
389{
391 {
392 const_cast < ViewContactOfE3dScene* >(this)->createSdrSceneAttribute();
393 }
394
395 return maSdrSceneAttribute;
396}
397
399{
401 {
402 const_cast < ViewContactOfE3dScene* >(this)->createSdrLightingAttribute();
403 }
404
406}
407
409{
411 const sal_uInt32 nChildrenCount(GetObjectCount());
412
413 // add children recursively. Do NOT start with (*this), this would create
414 // a 3D transformPrimitive for the start scene. While this is theoretically not
415 // a bad thing, for historical reasons the transformation of the outmost scene
416 // is seen as part of the ViewTransformation (see text in createViewInformation3D)
417 for(sal_uInt32 a(0); a < nChildrenCount; a++)
418 {
419 createSubPrimitive3DVector(GetViewContact(a), aAllPrimitive3DContainer, nullptr, nullptr, false);
420 }
421
422 return aAllPrimitive3DContainer;
423}
424
426{
428 basegfx::B3DRange aAllContentRange3D;
429
430 if(!xAllSequence.empty())
431 {
432 // for getting the 3D range using getB3DRangeFromPrimitive3DContainer a ViewInformation3D
433 // needs to be given for evtl. decompositions. Use a neutral ViewInformation3D here. This
434 // leaves all matrices on identity and the time on 0.0.
435 const uno::Sequence< beans::PropertyValue > aEmptyProperties;
436 const drawinglayer::geometry::ViewInformation3D aNeutralViewInformation3D(aEmptyProperties);
437
438 aAllContentRange3D = xAllSequence.getB3DRange(aNeutralViewInformation3D);
439 }
440
441 return aAllContentRange3D;
442}
443
444}
445
446/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const basegfx::B3DPoint & GetVRP() const
const basegfx::B3DVector & GetVPN() const
const basegfx::B3DVector & GetVUV() const
const basegfx::B3DHomMatrix & GetTransform() const
Definition: obj3d.hxx:112
bool GetSelected() const
Definition: obj3d.hxx:135
B3dCamera & GetCameraSet()
Definition: scene3d.hxx:145
bool IsSet(SdrLayerID a) const
Definition: svdsob.hxx:69
const SfxItemSet & GetMergedItemSet() const
Definition: svdobj.cxx:1974
virtual SdrLayerID GetLayer() const
Definition: svdobj.cxx:645
void set(sal_uInt16 nRow, sal_uInt16 nColumn, double fValue)
bool isIdentity() const
void orientation(const B3DPoint &rVRP=B3DPoint(0.0, 0.0, 1.0), B3DVector aVPN=B3DVector(0.0, 0.0, 1.0), B3DVector aVUV=B3DVector(0.0, 1.0, 0.0))
void ortho(double fLeft=-1.0, double fRight=1.0, double fBottom=-1.0, double fTop=1.0, double fNear=0.0, double fFar=1.0)
void translate(double fX, double fY, double fZ)
void scale(double fX, double fY, double fZ)
void frustum(double fLeft=-1.0, double fRight=1.0, double fBottom=-1.0, double fTop=1.0, double fNear=0.001, double fFar=1.0)
double getMinZ() const
BASEGFX_DLLPUBLIC void transform(const B3DHomMatrix &rMatrix)
double getMaxZ() const
double getMinX() const
bool isEmpty() const
void expand(const B3DTuple &rTuple)
double getMinY() const
double getMaxX() const
double getMaxY() const
css::drawing::ProjectionMode getProjectionMode() const
virtual void visit(const Primitive2DReference &)=0
basegfx::B3DRange getB3DRange(const geometry::ViewInformation3D &aViewInformation) const
void append(const Primitive3DContainer &rSource)
virtual ViewObjectContact & CreateObjectSpecificViewObjectContact(ObjectContact &rObjectContact) override
const drawinglayer::geometry::ViewInformation3D & getViewInformation3D() const
const drawinglayer::attribute::SdrSceneAttribute & getSdrSceneAttribute() const
virtual void createViewIndependentPrimitive2DSequence(drawinglayer::primitive2d::Primitive2DDecompositionVisitor &rVisitor) const override
drawinglayer::attribute::SdrSceneAttribute maSdrSceneAttribute
const drawinglayer::attribute::SdrLightingAttribute & getSdrLightingAttribute() const
basegfx::B3DRange getAllContentRange3D() const
drawinglayer::attribute::SdrLightingAttribute maSdrLightingAttribute
void createViewInformation3D(const ::basegfx::B3DRange &rContentRange)
drawinglayer::geometry::ViewInformation3D maViewInformation3D
drawinglayer::primitive2d::Primitive2DContainer createScenePrimitive2DSequence(const SdrLayerIDSet *pLayerVisibility) const
drawinglayer::primitive3d::Primitive3DContainer getAllPrimitive3DContainer() const
const basegfx::B2DHomMatrix & getObjectTransformation() const
drawinglayer::primitive3d::Primitive3DContainer getViewIndependentPrimitive3DContainer() const
const E3dObject & GetE3dObject() const
virtual ViewContact & GetViewContact(sal_uInt32 nIndex) const override
virtual sal_uInt32 GetObjectCount() const override
virtual ViewContact & GetViewContact(sal_uInt32 nIndex) const
virtual sal_uInt32 GetObjectCount() const
constexpr tools::Long Top() const
tools::Long getOpenHeight() const
tools::Long getOpenWidth() const
constexpr tools::Long Left() const
#define DBG_ASSERT(sCon, aError)
uno_Any a
attribute::SdrSceneAttribute createNewSdrSceneAttribute(const SfxItemSet &rSet)
Primitive2DReference createHiddenGeometryPrimitives2D(const basegfx::B2DHomMatrix &rMatrix)
attribute::SdrLightingAttribute createNewSdrLightingAttribute(const SfxItemSet &rSet)
css::uno::Reference< css::graphic::XPrimitive3D > Primitive3DReference
bool bVisible