Coverage Report

Created: 2025-07-07 10:01

/src/libreoffice/svx/source/sdr/contact/viewcontactofe3d.cxx
Line
Count
Source (jump to first uncovered line)
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
#include <sdr/contact/viewcontactofe3d.hxx>
21
#include <sdr/contact/viewobjectcontactofe3d.hxx>
22
#include <svx/obj3d.hxx>
23
#include <drawinglayer/primitive2d/embedded3dprimitive2d.hxx>
24
#include <svx/sdr/contact/viewcontactofe3dscene.hxx>
25
#include <svx/scene3d.hxx>
26
#include <drawinglayer/primitive3d/transformprimitive3d.hxx>
27
#include <drawinglayer/attribute/sdrsceneattribute3d.hxx>
28
#include <drawinglayer/attribute/sdrlightingattribute3d.hxx>
29
#include <drawinglayer/attribute/sdrlightattribute3d.hxx>
30
31
namespace {
32
33
const sdr::contact::ViewContactOfE3dScene* tryToFindVCOfE3DScene(
34
    const sdr::contact::ViewContact& rCandidate,
35
    basegfx::B3DHomMatrix& o_rInBetweenObjectTransform)
36
0
{
37
0
    const sdr::contact::ViewContactOfE3dScene* pSceneParent =
38
0
        dynamic_cast< const sdr::contact::ViewContactOfE3dScene* >(rCandidate.GetParentContact());
39
40
0
    if(pSceneParent)
41
0
    {
42
        // each 3d object (including in-between scenes) should have a scene as parent
43
0
        const sdr::contact::ViewContactOfE3dScene* pSceneParentParent =
44
0
            dynamic_cast< const sdr::contact::ViewContactOfE3dScene* >(pSceneParent->GetParentContact());
45
46
0
        if(pSceneParentParent)
47
0
        {
48
            // the parent scene of rCandidate is an in-between scene, call recursively and collect
49
            // the in-between scene's object transformation part in o_rInBetweenObjectTransform
50
0
            const basegfx::B3DHomMatrix& rSceneParentTransform = pSceneParent->GetE3dScene().GetTransform();
51
0
            o_rInBetweenObjectTransform = rSceneParentTransform * o_rInBetweenObjectTransform;
52
0
            return tryToFindVCOfE3DScene(*pSceneParent, o_rInBetweenObjectTransform);
53
0
        }
54
0
        else
55
0
        {
56
            // the parent scene is the outmost scene
57
0
            return pSceneParent;
58
0
        }
59
0
    }
60
61
    // object hierarchy structure is incorrect; no result
62
0
    return nullptr;
63
0
}
64
65
} // end of anonymous namespace
66
67
namespace sdr::contact {
68
69
drawinglayer::primitive2d::Primitive2DContainer ViewContactOfE3d::impCreateWithGivenPrimitive3DContainer(
70
    const drawinglayer::primitive3d::Primitive3DContainer& rxContent3D) const
71
0
{
72
0
    drawinglayer::primitive2d::Primitive2DContainer xRetval;
73
74
0
    if(!rxContent3D.empty())
75
0
    {
76
        // try to get the outmost ViewObjectContactOfE3dScene for this single 3d object,
77
        // the ones on the way there are grouping scenes. Collect the in-between scene's
78
        // transformations to build a correct object transformation for the embedded
79
        // object
80
0
        basegfx::B3DHomMatrix aInBetweenObjectTransform;
81
0
        const ViewContactOfE3dScene* pVCOfE3DScene = tryToFindVCOfE3DScene(*this, aInBetweenObjectTransform);
82
83
0
        if(pVCOfE3DScene)
84
0
        {
85
0
            basegfx::B3DVector aLightNormal;
86
0
            const double fShadowSlant(pVCOfE3DScene->getSdrSceneAttribute().getShadowSlant());
87
0
            const basegfx::B3DRange aAllContentRange = pVCOfE3DScene->getAllContentRange3D();
88
0
            drawinglayer::geometry::ViewInformation3D aViewInformation3D(pVCOfE3DScene->getViewInformation3D());
89
90
0
            if(!pVCOfE3DScene->getSdrLightingAttribute().getLightVector().empty())
91
0
            {
92
                // get light normal from first light and normalize
93
0
                aLightNormal = pVCOfE3DScene->getSdrLightingAttribute().getLightVector()[0].getDirection();
94
0
                aLightNormal.normalize();
95
0
            }
96
97
0
            if(!aInBetweenObjectTransform.isIdentity())
98
0
            {
99
                // if aInBetweenObjectTransform is used, create combined ViewInformation3D which
100
                // contains the correct object transformation for the embedded 3d object
101
0
                aViewInformation3D = drawinglayer::geometry::ViewInformation3D(
102
0
                    aViewInformation3D.getObjectTransformation() * aInBetweenObjectTransform,
103
0
                    aViewInformation3D.getOrientation(),
104
0
                    aViewInformation3D.getProjection(),
105
0
                    aViewInformation3D.getDeviceToView(),
106
0
                    aViewInformation3D.getViewTime(),
107
0
                    aViewInformation3D.getExtendedInformationSequence());
108
0
            }
109
110
            // create embedded 2d primitive and add. LightNormal and ShadowSlant are needed for evtl.
111
            // 3D shadow extraction for correct B2DRange calculation (shadow is part of the object)
112
0
            const drawinglayer::primitive2d::Primitive2DReference xReference(
113
0
                new drawinglayer::primitive2d::Embedded3DPrimitive2D(
114
0
                    rxContent3D,
115
0
                    pVCOfE3DScene->getObjectTransformation(),
116
0
                    std::move(aViewInformation3D),
117
0
                    aLightNormal,
118
0
                    fShadowSlant,
119
0
                    aAllContentRange));
120
121
0
            xRetval = drawinglayer::primitive2d::Primitive2DContainer { xReference };
122
0
        }
123
0
    }
124
125
0
    return xRetval;
126
0
}
127
128
ViewContactOfE3d::ViewContactOfE3d(E3dObject& rSdrObject)
129
10.4k
:   ViewContactOfSdrObj(rSdrObject)
130
10.4k
{
131
10.4k
}
132
133
ViewContactOfE3d::~ViewContactOfE3d()
134
10.4k
{
135
10.4k
}
136
137
drawinglayer::primitive3d::Primitive3DContainer const & ViewContactOfE3d::getVIP3DSWithoutObjectTransform() const
138
0
{
139
    // local up-to-date checks. Create new list and compare.
140
0
    drawinglayer::primitive3d::Primitive3DContainer xNew(createViewIndependentPrimitive3DContainer());
141
142
0
    if(mxViewIndependentPrimitive3DContainer != xNew)
143
0
    {
144
        // has changed, copy content
145
0
        const_cast< ViewContactOfE3d* >(this)->mxViewIndependentPrimitive3DContainer = std::move(xNew);
146
0
    }
147
148
    // return current Primitive2DContainer
149
0
    return mxViewIndependentPrimitive3DContainer;
150
0
}
151
152
drawinglayer::primitive3d::Primitive3DContainer ViewContactOfE3d::getViewIndependentPrimitive3DContainer() const
153
0
{
154
    // get sequence without object transform
155
0
    drawinglayer::primitive3d::Primitive3DContainer xRetval(getVIP3DSWithoutObjectTransform());
156
157
0
    if(!xRetval.empty())
158
0
    {
159
        // add object transform if it's used
160
0
        const basegfx::B3DHomMatrix& rObjectTransform(GetE3dObject().GetTransform());
161
162
0
        if(!rObjectTransform.isIdentity())
163
0
        {
164
0
            const drawinglayer::primitive3d::Primitive3DReference xReference(
165
0
                new drawinglayer::primitive3d::TransformPrimitive3D(
166
0
                    rObjectTransform,
167
0
                    xRetval));
168
169
0
            xRetval = { xReference };
170
0
        }
171
0
    }
172
173
    // return current Primitive2DContainer
174
0
    return xRetval;
175
0
}
176
177
void ViewContactOfE3d::createViewIndependentPrimitive2DSequence(drawinglayer::primitive2d::Primitive2DDecompositionVisitor& rVisitor) const
178
0
{
179
    // also need to create a 2D embedding when the view-independent part is requested,
180
    // see view-dependent part in ViewObjectContactOfE3d::createPrimitive2DSequence
181
    // get 3d primitive vector, isPrimitiveVisible() is done in 3d creator
182
0
    return rVisitor.visit(impCreateWithGivenPrimitive3DContainer(getViewIndependentPrimitive3DContainer()));
183
0
}
184
185
ViewObjectContact& ViewContactOfE3d::CreateObjectSpecificViewObjectContact(ObjectContact& rObjectContact)
186
0
{
187
0
    ViewObjectContact* pRetval = new ViewObjectContactOfE3d(rObjectContact, *this);
188
0
    DBG_ASSERT(pRetval, "ViewContactOfE3d::CreateObjectSpecificViewObjectContact() failed (!)");
189
190
0
    return *pRetval;
191
0
}
192
193
}
194
195
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */