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