LCOV - code coverage report
Current view: top level - svx/source/sdr/contact - viewcontactofe3d.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 21 56 37.5 %
Date: 2012-08-25 Functions: 5 9 55.6 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 22 132 16.7 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : 
      30                 :            : #include <svx/sdr/contact/viewcontactofe3d.hxx>
      31                 :            : #include <svx/sdr/contact/viewobjectcontactofe3d.hxx>
      32                 :            : #include <svx/obj3d.hxx>
      33                 :            : #include <drawinglayer/primitive2d/embedded3dprimitive2d.hxx>
      34                 :            : #include <svx/sdr/contact/viewcontactofe3dscene.hxx>
      35                 :            : #include <svx/scene3d.hxx>
      36                 :            : #include <drawinglayer/primitive3d/transformprimitive3d.hxx>
      37                 :            : #include <drawinglayer/attribute/sdrsceneattribute3d.hxx>
      38                 :            : #include <drawinglayer/attribute/sdrlightingattribute3d.hxx>
      39                 :            : #include <drawinglayer/attribute/sdrlightattribute3d.hxx>
      40                 :            : #include <drawinglayer/attribute/sdrlineattribute.hxx>
      41                 :            : 
      42                 :            : //////////////////////////////////////////////////////////////////////////////
      43                 :            : 
      44                 :            : namespace
      45                 :            : {
      46                 :          0 :     const sdr::contact::ViewContactOfE3dScene* tryToFindVCOfE3DScene(
      47                 :            :         const sdr::contact::ViewContact& rCandidate,
      48                 :            :         basegfx::B3DHomMatrix& o_rInBetweenObjectTransform)
      49                 :            :     {
      50                 :            :         const sdr::contact::ViewContactOfE3dScene* pSceneParent =
      51         [ #  # ]:          0 :             dynamic_cast< const sdr::contact::ViewContactOfE3dScene* >(rCandidate.GetParentContact());
      52                 :            : 
      53         [ #  # ]:          0 :         if(pSceneParent)
      54                 :            :         {
      55                 :            :             // each 3d object (including in-between scenes) should have a scene as parent
      56                 :            :             const sdr::contact::ViewContactOfE3dScene* pSceneParentParent =
      57         [ #  # ]:          0 :                 dynamic_cast< const sdr::contact::ViewContactOfE3dScene* >(pSceneParent->GetParentContact());
      58                 :            : 
      59         [ #  # ]:          0 :             if(pSceneParentParent)
      60                 :            :             {
      61                 :            :                 // the parent scene of rCandidate is a in-between scene, call recursively and collect
      62                 :            :                 // the in-between scene's object transformation part in o_rInBetweenObjectTransform
      63                 :          0 :                 const basegfx::B3DHomMatrix& rSceneParentTransform = pSceneParent->GetE3dScene().GetTransform();
      64         [ #  # ]:          0 :                 o_rInBetweenObjectTransform = rSceneParentTransform * o_rInBetweenObjectTransform;
      65                 :          0 :                 return tryToFindVCOfE3DScene(*pSceneParent, o_rInBetweenObjectTransform);
      66                 :            :             }
      67                 :            :             else
      68                 :            :             {
      69                 :            :                 // the parent scene is the outmost scene
      70                 :          0 :                 return pSceneParent;
      71                 :            :             }
      72                 :            :         }
      73                 :            : 
      74                 :            :         // object hierarchy structure is incorrect; no result
      75                 :          0 :         return 0;
      76                 :            :     }
      77                 :            : } // end of anonymous namespace
      78                 :            : 
      79                 :            : //////////////////////////////////////////////////////////////////////////////
      80                 :            : 
      81                 :            : namespace sdr
      82                 :            : {
      83                 :            :     namespace contact
      84                 :            :     {
      85                 :          0 :         drawinglayer::primitive2d::Primitive2DSequence ViewContactOfE3d::impCreateWithGivenPrimitive3DSequence(
      86                 :            :             const drawinglayer::primitive3d::Primitive3DSequence& rxContent3D) const
      87                 :            :         {
      88                 :          0 :             drawinglayer::primitive2d::Primitive2DSequence xRetval;
      89                 :            : 
      90         [ #  # ]:          0 :             if(rxContent3D.hasElements())
      91                 :            :             {
      92                 :            :                 // try to get the outmost ViewObjectContactOfE3dScene for this single 3d object,
      93                 :            :                 // the ones on the way there are grouping scenes. Collect the in-between scene's
      94                 :            :                 // transformations to build a correct object transformation for the embedded
      95                 :            :                 // object
      96         [ #  # ]:          0 :                 basegfx::B3DHomMatrix aInBetweenObjectTransform;
      97         [ #  # ]:          0 :                 const ViewContactOfE3dScene* pVCOfE3DScene = tryToFindVCOfE3DScene(*this, aInBetweenObjectTransform);
      98                 :            : 
      99         [ #  # ]:          0 :                 if(pVCOfE3DScene)
     100                 :            :                 {
     101                 :          0 :                     basegfx::B3DVector aLightNormal;
     102 [ #  # ][ #  # ]:          0 :                     const double fShadowSlant(pVCOfE3DScene->getSdrSceneAttribute().getShadowSlant());
     103         [ #  # ]:          0 :                     const basegfx::B3DRange& rAllContentRange = pVCOfE3DScene->getAllContentRange3D();
     104 [ #  # ][ #  # ]:          0 :                     drawinglayer::geometry::ViewInformation3D aViewInformation3D(pVCOfE3DScene->getViewInformation3D());
     105                 :            : 
     106 [ #  # ][ #  # ]:          0 :                     if(pVCOfE3DScene->getSdrLightingAttribute().getLightVector().size())
                 [ #  # ]
     107                 :            :                     {
     108                 :            :                         // get light normal from first light and normalize
     109 [ #  # ][ #  # ]:          0 :                         aLightNormal = pVCOfE3DScene->getSdrLightingAttribute().getLightVector()[0].getDirection();
         [ #  # ][ #  # ]
                 [ #  # ]
     110         [ #  # ]:          0 :                         aLightNormal.normalize();
     111                 :            :                     }
     112                 :            : 
     113 [ #  # ][ #  # ]:          0 :                     if(!aInBetweenObjectTransform.isIdentity())
     114                 :            :                     {
     115                 :            :                         // if aInBetweenObjectTransform is used, create combined ViewInformation3D which
     116                 :            :                         // contains the correct object transformation for the embedded 3d object
     117                 :            :                         aViewInformation3D = drawinglayer::geometry::ViewInformation3D(
     118         [ #  # ]:          0 :                             aViewInformation3D.getObjectTransformation() * aInBetweenObjectTransform,
     119         [ #  # ]:          0 :                             aViewInformation3D.getOrientation(),
     120         [ #  # ]:          0 :                             aViewInformation3D.getProjection(),
     121         [ #  # ]:          0 :                             aViewInformation3D.getDeviceToView(),
     122                 :            :                             aViewInformation3D.getViewTime(),
     123 [ #  # ][ #  # ]:          0 :                             aViewInformation3D.getExtendedInformationSequence());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     124                 :            :                     }
     125                 :            : 
     126                 :            :                     // create embedded 2d primitive and add. LightNormal and ShadowSlant are needed for evtl.
     127                 :            :                     // 3D shadow extraction for correct B2DRange calculation (shadow is part of the object)
     128                 :            :                     const drawinglayer::primitive2d::Primitive2DReference xReference(
     129                 :            :                         new drawinglayer::primitive2d::Embedded3DPrimitive2D(
     130                 :            :                             rxContent3D,
     131                 :            :                             pVCOfE3DScene->getObjectTransformation(),
     132                 :            :                             aViewInformation3D,
     133                 :            :                             aLightNormal,
     134                 :            :                             fShadowSlant,
     135 [ #  # ][ #  # ]:          0 :                             rAllContentRange));
         [ #  # ][ #  # ]
     136                 :            : 
     137 [ #  # ][ #  # ]:          0 :                     xRetval = drawinglayer::primitive2d::Primitive2DSequence(&xReference, 1);
         [ #  # ][ #  # ]
     138         [ #  # ]:          0 :                 }
     139                 :            :             }
     140                 :            : 
     141                 :          0 :             return xRetval;
     142                 :            :         }
     143                 :            : 
     144                 :       1939 :         ViewContactOfE3d::ViewContactOfE3d(E3dObject& rSdrObject)
     145         [ +  - ]:       1939 :         :   ViewContactOfSdrObj(rSdrObject)
     146                 :            :         {
     147                 :       1939 :         }
     148                 :            : 
     149         [ +  - ]:       1939 :         ViewContactOfE3d::~ViewContactOfE3d()
     150                 :            :         {
     151         [ -  + ]:       1939 :         }
     152                 :            : 
     153                 :      13391 :         drawinglayer::primitive3d::Primitive3DSequence ViewContactOfE3d::getVIP3DSWithoutObjectTransform() const
     154                 :            :         {
     155                 :            :             // local up-to-date checks. Create new list and compare.
     156         [ +  - ]:      13391 :             drawinglayer::primitive3d::Primitive3DSequence xNew(createViewIndependentPrimitive3DSequence());
     157                 :            : 
     158 [ +  - ][ +  + ]:      13391 :             if(!drawinglayer::primitive3d::arePrimitive3DSequencesEqual(mxViewIndependentPrimitive3DSequence, xNew))
     159                 :            :             {
     160                 :            :                 // has changed, copy content
     161         [ +  - ]:       3873 :                 const_cast< ViewContactOfE3d* >(this)->mxViewIndependentPrimitive3DSequence = xNew;
     162                 :            :             }
     163                 :            : 
     164                 :            :             // return current Primitive2DSequence
     165 [ +  - ][ +  - ]:      13391 :             return mxViewIndependentPrimitive3DSequence;
     166                 :            :         }
     167                 :            : 
     168                 :      13391 :         drawinglayer::primitive3d::Primitive3DSequence ViewContactOfE3d::getViewIndependentPrimitive3DSequence() const
     169                 :            :         {
     170                 :            :             // get sequence without object transform
     171                 :      13391 :             drawinglayer::primitive3d::Primitive3DSequence xRetval(getVIP3DSWithoutObjectTransform());
     172                 :            : 
     173         [ +  - ]:      13391 :             if(xRetval.hasElements())
     174                 :            :             {
     175                 :            :                 // add object transform if it's used
     176         [ +  - ]:      13391 :                 const basegfx::B3DHomMatrix& rObjectTransform(GetE3dObject().GetTransform());
     177                 :            : 
     178 [ +  - ][ +  + ]:      13391 :                 if(!rObjectTransform.isIdentity())
     179                 :            :                 {
     180                 :            :                     const drawinglayer::primitive3d::Primitive3DReference xReference(
     181                 :            :                         new drawinglayer::primitive3d::TransformPrimitive3D(
     182                 :            :                             rObjectTransform,
     183 [ +  - ][ +  - ]:       1687 :                             xRetval));
                 [ +  - ]
     184                 :            : 
     185 [ +  - ][ +  - ]:       1687 :                     xRetval = drawinglayer::primitive3d::Primitive3DSequence(&xReference, 1);
                 [ +  - ]
     186                 :            :                 }
     187                 :            :             }
     188                 :            : 
     189                 :            :             // return current Primitive2DSequence
     190                 :      13391 :             return xRetval;
     191                 :            :         }
     192                 :            : 
     193                 :          0 :         drawinglayer::primitive2d::Primitive2DSequence ViewContactOfE3d::createViewIndependentPrimitive2DSequence() const
     194                 :            :         {
     195                 :            :             // also need to create a 2D embedding when the view-independent part is requested,
     196                 :            :             // see view-dependent part in ViewObjectContactOfE3d::createPrimitive2DSequence
     197                 :            :             // get 3d primitive vector, isPrimitiveVisible() is done in 3d creator
     198         [ #  # ]:          0 :             return impCreateWithGivenPrimitive3DSequence(getViewIndependentPrimitive3DSequence());
     199                 :            :         }
     200                 :            : 
     201                 :        537 :         ViewObjectContact& ViewContactOfE3d::CreateObjectSpecificViewObjectContact(ObjectContact& rObjectContact)
     202                 :            :         {
     203         [ +  - ]:        537 :             ViewObjectContact* pRetval = new ViewObjectContactOfE3d(rObjectContact, *this);
     204                 :            :             DBG_ASSERT(pRetval, "ViewContactOfE3d::CreateObjectSpecificViewObjectContact() failed (!)");
     205                 :            : 
     206                 :        537 :             return *pRetval;
     207                 :            :         }
     208                 :            :     } // end of namespace contact
     209                 :            : } // end of namespace sdr
     210                 :            : 
     211                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10