LCOV - code coverage report
Current view: top level - xmloff/source/draw - ximp3dobject.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 0 207 0.0 %
Date: 2014-04-11 Functions: 0 60 0.0 %
Legend: Lines: hit not hit

          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 <comphelper/extract.hxx>
      21             : #include "ximp3dobject.hxx"
      22             : #include <xmloff/XMLShapeStyleContext.hxx>
      23             : #include <xmloff/xmluconv.hxx>
      24             : #include <com/sun/star/beans/XPropertySet.hpp>
      25             : #include <com/sun/star/drawing/PointSequenceSequence.hpp>
      26             : #include <com/sun/star/drawing/PointSequence.hpp>
      27             : #include "xexptran.hxx"
      28             : #include <com/sun/star/drawing/PolyPolygonBezierCoords.hpp>
      29             : #include <xmloff/families.hxx>
      30             : #include "ximpstyl.hxx"
      31             : #include <xmloff/xmltoken.hxx>
      32             : #include <com/sun/star/drawing/PolyPolygonShape3D.hpp>
      33             : #include <com/sun/star/drawing/DoubleSequence.hpp>
      34             : #include <basegfx/polygon/b2dpolypolygon.hxx>
      35             : #include <basegfx/polygon/b2dpolypolygontools.hxx>
      36             : #include <basegfx/polygon/b3dpolypolygontools.hxx>
      37             : 
      38             : using namespace ::com::sun::star;
      39             : 
      40           0 : TYPEINIT1( SdXML3DObjectContext, SdXMLShapeContext );
      41             : 
      42           0 : SdXML3DObjectContext::SdXML3DObjectContext(
      43             :     SvXMLImport& rImport,
      44             :     sal_uInt16 nPrfx,
      45             :     const OUString& rLocalName,
      46             :     const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList,
      47             :     uno::Reference< drawing::XShapes >& rShapes,
      48             :     sal_Bool bTemporaryShape)
      49             : :   SdXMLShapeContext( rImport, nPrfx, rLocalName, xAttrList, rShapes, bTemporaryShape ),
      50           0 :     mbSetTransform( sal_False )
      51             : {
      52           0 :     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
      53           0 :     for(sal_Int16 i=0; i < nAttrCount; i++)
      54             :     {
      55           0 :         OUString sAttrName = xAttrList->getNameByIndex( i );
      56           0 :         OUString aLocalName;
      57           0 :         sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
      58           0 :         OUString sValue = xAttrList->getValueByIndex( i );
      59           0 :         const SvXMLTokenMap& rAttrTokenMap = GetImport().GetShapeImport()->Get3DObjectAttrTokenMap();
      60             : 
      61           0 :         switch(rAttrTokenMap.Get(nPrefix, aLocalName))
      62             :         {
      63             :             case XML_TOK_3DOBJECT_DRAWSTYLE_NAME:
      64             :             {
      65           0 :                 maDrawStyleName = sValue;
      66           0 :                 break;
      67             :             }
      68             :             case XML_TOK_3DOBJECT_TRANSFORM:
      69             :             {
      70           0 :                 SdXMLImExTransform3D aTransform(sValue, GetImport().GetMM100UnitConverter());
      71           0 :                 if(aTransform.NeedsAction())
      72           0 :                     mbSetTransform = aTransform.GetFullHomogenTransform(mxHomMat);
      73           0 :                 break;
      74             :             }
      75             :         }
      76           0 :     }
      77           0 : }
      78             : 
      79           0 : SdXML3DObjectContext::~SdXML3DObjectContext()
      80             : {
      81           0 : }
      82             : 
      83           0 : void SdXML3DObjectContext::StartElement(const uno::Reference< xml::sax::XAttributeList>& xAttrList)
      84             : {
      85           0 :     uno::Reference< beans::XPropertySet > xPropSet(mxShape, uno::UNO_QUERY);
      86           0 :     if(xPropSet.is())
      87             :     {
      88             :         // set parameters
      89           0 :         if(mbSetTransform)
      90             :         {
      91           0 :             uno::Any aAny;
      92           0 :             aAny <<= mxHomMat;
      93           0 :             xPropSet->setPropertyValue("D3DTransformMatrix", aAny);
      94             :         }
      95             : 
      96             :         // call parent
      97           0 :         SdXMLShapeContext::StartElement(xAttrList);
      98           0 :     }
      99           0 : }
     100             : 
     101           0 : void SdXML3DObjectContext::EndElement()
     102             : {
     103             :     // call parent
     104           0 :     SdXMLShapeContext::EndElement();
     105           0 : }
     106             : 
     107           0 : TYPEINIT1( SdXML3DCubeObjectShapeContext, SdXML3DObjectContext);
     108             : 
     109           0 : SdXML3DCubeObjectShapeContext::SdXML3DCubeObjectShapeContext(
     110             :     SvXMLImport& rImport,
     111             :     sal_uInt16 nPrfx,
     112             :     const OUString& rLocalName,
     113             :     const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList,
     114             :     uno::Reference< drawing::XShapes >& rShapes,
     115             :     sal_Bool bTemporaryShape)
     116             : :   SdXML3DObjectContext( rImport, nPrfx, rLocalName, xAttrList, rShapes, bTemporaryShape ),
     117             :     maMinEdge(-2500.0, -2500.0, -2500.0),
     118             :     maMaxEdge(2500.0, 2500.0, 2500.0),
     119             :     mbMinEdgeUsed(sal_False),
     120           0 :     mbMaxEdgeUsed(sal_False)
     121             : {
     122           0 :     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
     123           0 :     for(sal_Int16 i=0; i < nAttrCount; i++)
     124             :     {
     125           0 :         OUString sAttrName = xAttrList->getNameByIndex( i );
     126           0 :         OUString aLocalName;
     127           0 :         sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
     128           0 :         OUString sValue = xAttrList->getValueByIndex( i );
     129           0 :         const SvXMLTokenMap& rAttrTokenMap = GetImport().GetShapeImport()->Get3DCubeObjectAttrTokenMap();
     130             : 
     131           0 :         switch(rAttrTokenMap.Get(nPrefix, aLocalName))
     132             :         {
     133             :             case XML_TOK_3DCUBEOBJ_MINEDGE:
     134             :             {
     135           0 :                 ::basegfx::B3DVector aNewVec;
     136           0 :                 GetImport().GetMM100UnitConverter().convertB3DVector(aNewVec, sValue);
     137             : 
     138           0 :                 if(aNewVec != maMinEdge)
     139             :                 {
     140           0 :                     maMinEdge = aNewVec;
     141           0 :                     mbMinEdgeUsed = sal_True;
     142             :                 }
     143           0 :                 break;
     144             :             }
     145             :             case XML_TOK_3DCUBEOBJ_MAXEDGE:
     146             :             {
     147           0 :                 ::basegfx::B3DVector aNewVec;
     148           0 :                 GetImport().GetMM100UnitConverter().convertB3DVector(aNewVec, sValue);
     149             : 
     150           0 :                 if(aNewVec != maMaxEdge)
     151             :                 {
     152           0 :                     maMaxEdge = aNewVec;
     153           0 :                     mbMaxEdgeUsed = sal_True;
     154             :                 }
     155           0 :                 break;
     156             :             }
     157             :         }
     158           0 :     }
     159           0 : }
     160             : 
     161           0 : SdXML3DCubeObjectShapeContext::~SdXML3DCubeObjectShapeContext()
     162             : {
     163           0 : }
     164             : 
     165           0 : void SdXML3DCubeObjectShapeContext::StartElement(const uno::Reference< xml::sax::XAttributeList>& xAttrList)
     166             : {
     167             :     // create shape
     168           0 :     AddShape( "com.sun.star.drawing.Shape3DCubeObject" );
     169           0 :     if(mxShape.is())
     170             :     {
     171             :         // add, set style and properties from base shape
     172           0 :         SetStyle();
     173           0 :         SdXML3DObjectContext::StartElement(xAttrList);
     174             : 
     175             :         // set local parameters on shape
     176           0 :         uno::Reference< beans::XPropertySet > xPropSet(mxShape, uno::UNO_QUERY);
     177           0 :         if(xPropSet.is())
     178             :         {
     179             :             // set parameters
     180           0 :             drawing::Position3D aPosition3D;
     181           0 :             drawing::Direction3D aDirection3D;
     182             : 
     183             :             // convert from min, max to size to be set
     184           0 :             maMaxEdge = maMaxEdge - maMinEdge;
     185             : 
     186           0 :             aPosition3D.PositionX = maMinEdge.getX();
     187           0 :             aPosition3D.PositionY = maMinEdge.getY();
     188           0 :             aPosition3D.PositionZ = maMinEdge.getZ();
     189             : 
     190           0 :             aDirection3D.DirectionX = maMaxEdge.getX();
     191           0 :             aDirection3D.DirectionY = maMaxEdge.getY();
     192           0 :             aDirection3D.DirectionZ = maMaxEdge.getZ();
     193             : 
     194           0 :             uno::Any aAny;
     195           0 :             aAny <<= aPosition3D;
     196           0 :             xPropSet->setPropertyValue("D3DPosition", aAny);
     197           0 :             aAny <<= aDirection3D;
     198           0 :             xPropSet->setPropertyValue("D3DSize", aAny);
     199           0 :         }
     200             :     }
     201           0 : }
     202             : 
     203           0 : void SdXML3DCubeObjectShapeContext::EndElement()
     204             : {
     205             :     // call parent
     206           0 :     SdXML3DObjectContext::EndElement();
     207           0 : }
     208             : 
     209           0 : TYPEINIT1( SdXML3DSphereObjectShapeContext, SdXML3DObjectContext);
     210             : 
     211           0 : SdXML3DSphereObjectShapeContext::SdXML3DSphereObjectShapeContext(
     212             :     SvXMLImport& rImport,
     213             :     sal_uInt16 nPrfx,
     214             :     const OUString& rLocalName,
     215             :     const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList,
     216             :     uno::Reference< drawing::XShapes >& rShapes,
     217             :     sal_Bool bTemporaryShape)
     218             : :   SdXML3DObjectContext( rImport, nPrfx, rLocalName, xAttrList, rShapes, bTemporaryShape ),
     219             :     maCenter(0.0, 0.0, 0.0),
     220             :     maSize(5000.0, 5000.0, 5000.0),
     221             :     mbCenterUsed(sal_False),
     222           0 :     mbSizeUsed(sal_False)
     223             : {
     224           0 :     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
     225           0 :     for(sal_Int16 i=0; i < nAttrCount; i++)
     226             :     {
     227           0 :         OUString sAttrName = xAttrList->getNameByIndex( i );
     228           0 :         OUString aLocalName;
     229           0 :         sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
     230           0 :         OUString sValue = xAttrList->getValueByIndex( i );
     231           0 :         const SvXMLTokenMap& rAttrTokenMap = GetImport().GetShapeImport()->Get3DSphereObjectAttrTokenMap();
     232             : 
     233           0 :         switch(rAttrTokenMap.Get(nPrefix, aLocalName))
     234             :         {
     235             :             case XML_TOK_3DSPHEREOBJ_CENTER:
     236             :             {
     237           0 :                 ::basegfx::B3DVector aNewVec;
     238           0 :                 GetImport().GetMM100UnitConverter().convertB3DVector(aNewVec, sValue);
     239             : 
     240           0 :                 if(aNewVec != maCenter)
     241             :                 {
     242           0 :                     maCenter = aNewVec;
     243           0 :                     mbCenterUsed = sal_True;
     244             :                 }
     245           0 :                 break;
     246             :             }
     247             :             case XML_TOK_3DSPHEREOBJ_SIZE:
     248             :             {
     249           0 :                 ::basegfx::B3DVector aNewVec;
     250           0 :                 GetImport().GetMM100UnitConverter().convertB3DVector(aNewVec, sValue);
     251             : 
     252           0 :                 if(aNewVec != maSize)
     253             :                 {
     254           0 :                     maSize = aNewVec;
     255           0 :                     mbSizeUsed = sal_True;
     256             :                 }
     257           0 :                 break;
     258             :             }
     259             :         }
     260           0 :     }
     261           0 : }
     262             : 
     263           0 : SdXML3DSphereObjectShapeContext::~SdXML3DSphereObjectShapeContext()
     264             : {
     265           0 : }
     266             : 
     267           0 : void SdXML3DSphereObjectShapeContext::StartElement(const uno::Reference< xml::sax::XAttributeList>& xAttrList)
     268             : {
     269             :     // create shape
     270           0 :     AddShape( "com.sun.star.drawing.Shape3DSphereObject" );
     271           0 :     if(mxShape.is())
     272             :     {
     273             :         // add, set style and properties from base shape
     274           0 :         SetStyle();
     275           0 :         SdXML3DObjectContext::StartElement(xAttrList);
     276             : 
     277             :         // set local parameters on shape
     278           0 :         uno::Reference< beans::XPropertySet > xPropSet(mxShape, uno::UNO_QUERY);
     279           0 :         if(xPropSet.is())
     280             :         {
     281             :             // set parameters
     282           0 :             drawing::Position3D aPosition3D;
     283           0 :             drawing::Direction3D aDirection3D;
     284             : 
     285           0 :             aPosition3D.PositionX = maCenter.getX();
     286           0 :             aPosition3D.PositionY = maCenter.getY();
     287           0 :             aPosition3D.PositionZ = maCenter.getZ();
     288             : 
     289           0 :             aDirection3D.DirectionX = maSize.getX();
     290           0 :             aDirection3D.DirectionY = maSize.getY();
     291           0 :             aDirection3D.DirectionZ = maSize.getZ();
     292             : 
     293           0 :             uno::Any aAny;
     294           0 :             aAny <<= aPosition3D;
     295           0 :             xPropSet->setPropertyValue("D3DPosition", aAny);
     296           0 :             aAny <<= aDirection3D;
     297           0 :             xPropSet->setPropertyValue("D3DSize", aAny);
     298           0 :         }
     299             :     }
     300           0 : }
     301             : 
     302           0 : void SdXML3DSphereObjectShapeContext::EndElement()
     303             : {
     304             :     // call parent
     305           0 :     SdXML3DObjectContext::EndElement();
     306           0 : }
     307             : 
     308           0 : TYPEINIT1( SdXML3DPolygonBasedShapeContext, SdXML3DObjectContext );
     309             : 
     310           0 : SdXML3DPolygonBasedShapeContext::SdXML3DPolygonBasedShapeContext(
     311             :     SvXMLImport& rImport,
     312             :     sal_uInt16 nPrfx,
     313             :     const OUString& rLocalName,
     314             :     const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList,
     315             :     uno::Reference< drawing::XShapes >& rShapes,
     316             :     sal_Bool bTemporaryShape)
     317           0 : :   SdXML3DObjectContext( rImport, nPrfx, rLocalName, xAttrList, rShapes, bTemporaryShape )
     318             : {
     319           0 :     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
     320           0 :     for(sal_Int16 i=0; i < nAttrCount; i++)
     321             :     {
     322           0 :         OUString sAttrName = xAttrList->getNameByIndex( i );
     323           0 :         OUString aLocalName;
     324           0 :         sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
     325           0 :         OUString sValue = xAttrList->getValueByIndex( i );
     326           0 :         const SvXMLTokenMap& rAttrTokenMap = GetImport().GetShapeImport()->Get3DPolygonBasedAttrTokenMap();
     327             : 
     328           0 :         switch(rAttrTokenMap.Get(nPrefix, aLocalName))
     329             :         {
     330             :             case XML_TOK_3DPOLYGONBASED_VIEWBOX:
     331             :             {
     332           0 :                 maViewBox = sValue;
     333           0 :                 break;
     334             :             }
     335             :             case XML_TOK_3DPOLYGONBASED_D:
     336             :             {
     337           0 :                 maPoints = sValue;
     338           0 :                 break;
     339             :             }
     340             :         }
     341           0 :     }
     342           0 : }
     343             : 
     344           0 : SdXML3DPolygonBasedShapeContext::~SdXML3DPolygonBasedShapeContext()
     345             : {
     346           0 : }
     347             : 
     348           0 : void SdXML3DPolygonBasedShapeContext::StartElement(const uno::Reference< xml::sax::XAttributeList>& xAttrList)
     349             : {
     350           0 :     uno::Reference< beans::XPropertySet > xPropSet(mxShape, uno::UNO_QUERY);
     351             : 
     352           0 :     if(xPropSet.is())
     353             :     {
     354             :         // set parameters
     355           0 :         if(!maPoints.isEmpty() && !maViewBox.isEmpty())
     356             :         {
     357             :             // import 2d PolyPolygon from svg:d
     358           0 :             basegfx::B2DPolyPolygon aPolyPolygon;
     359             : 
     360           0 :             if(basegfx::tools::importFromSvgD(aPolyPolygon, maPoints, GetImport().needFixPositionAfterZ(), 0))
     361             :             {
     362             :                 // convert to 3D PolyPolygon
     363             :                 const basegfx::B3DPolyPolygon aB3DPolyPolygon(
     364             :                     basegfx::tools::createB3DPolyPolygonFromB2DPolyPolygon(
     365           0 :                         aPolyPolygon));
     366             : 
     367             :                 // convert to UNO API class PolyPolygonShape3D
     368           0 :                 drawing::PolyPolygonShape3D xPolyPolygon3D;
     369             :                 basegfx::tools::B3DPolyPolygonToUnoPolyPolygonShape3D(
     370             :                     aB3DPolyPolygon,
     371           0 :                     xPolyPolygon3D);
     372             : 
     373             :                 // set polygon data
     374           0 :                 uno::Any aAny;
     375           0 :                 aAny <<= xPolyPolygon3D;
     376           0 :                 xPropSet->setPropertyValue(OUString("D3DPolyPolygon3D"), aAny);
     377             :             }
     378             :             else
     379             :             {
     380             :                 OSL_ENSURE(false, "Error on importing svg:d for 3D PolyPolygon (!)");
     381           0 :             }
     382             :         }
     383             : 
     384             :         // call parent
     385           0 :         SdXML3DObjectContext::StartElement(xAttrList);
     386           0 :     }
     387           0 : }
     388             : 
     389           0 : void SdXML3DPolygonBasedShapeContext::EndElement()
     390             : {
     391             :     // call parent
     392           0 :     SdXML3DObjectContext::EndElement();
     393           0 : }
     394             : 
     395           0 : TYPEINIT1( SdXML3DLatheObjectShapeContext, SdXML3DPolygonBasedShapeContext);
     396             : 
     397           0 : SdXML3DLatheObjectShapeContext::SdXML3DLatheObjectShapeContext(
     398             :     SvXMLImport& rImport,
     399             :     sal_uInt16 nPrfx,
     400             :     const OUString& rLocalName,
     401             :     const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList,
     402             :     uno::Reference< drawing::XShapes >& rShapes,
     403             :     sal_Bool bTemporaryShape)
     404           0 : :   SdXML3DPolygonBasedShapeContext( rImport, nPrfx, rLocalName, xAttrList, rShapes, bTemporaryShape )
     405             : {
     406           0 : }
     407             : 
     408           0 : SdXML3DLatheObjectShapeContext::~SdXML3DLatheObjectShapeContext()
     409             : {
     410           0 : }
     411             : 
     412           0 : void SdXML3DLatheObjectShapeContext::StartElement(const uno::Reference< xml::sax::XAttributeList>& xAttrList)
     413             : {
     414             :     // create shape
     415           0 :     AddShape( "com.sun.star.drawing.Shape3DLatheObject" );
     416           0 :     if(mxShape.is())
     417             :     {
     418             :         // add, set style and properties from base shape
     419           0 :         SetStyle();
     420           0 :         SdXML3DPolygonBasedShapeContext::StartElement(xAttrList);
     421             :     }
     422           0 : }
     423             : 
     424           0 : void SdXML3DLatheObjectShapeContext::EndElement()
     425             : {
     426             :     // call parent
     427           0 :     SdXML3DPolygonBasedShapeContext::EndElement();
     428           0 : }
     429             : 
     430           0 : TYPEINIT1( SdXML3DExtrudeObjectShapeContext, SdXML3DPolygonBasedShapeContext);
     431             : 
     432           0 : SdXML3DExtrudeObjectShapeContext::SdXML3DExtrudeObjectShapeContext(
     433             :     SvXMLImport& rImport,
     434             :     sal_uInt16 nPrfx,
     435             :     const OUString& rLocalName,
     436             :     const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList,
     437             :     uno::Reference< drawing::XShapes >& rShapes,
     438             :     sal_Bool bTemporaryShape)
     439           0 : :   SdXML3DPolygonBasedShapeContext( rImport, nPrfx, rLocalName, xAttrList, rShapes, bTemporaryShape )
     440             : {
     441           0 : }
     442             : 
     443           0 : SdXML3DExtrudeObjectShapeContext::~SdXML3DExtrudeObjectShapeContext()
     444             : {
     445           0 : }
     446             : 
     447           0 : void SdXML3DExtrudeObjectShapeContext::StartElement(const uno::Reference< xml::sax::XAttributeList>& xAttrList)
     448             : {
     449           0 :     AddShape( "com.sun.star.drawing.Shape3DExtrudeObject" );
     450           0 :     if(mxShape.is())
     451             :     {
     452             :         // add, set style and properties from base shape
     453           0 :         SetStyle();
     454           0 :         SdXML3DPolygonBasedShapeContext::StartElement(xAttrList);
     455             :     }
     456           0 : }
     457             : 
     458           0 : void SdXML3DExtrudeObjectShapeContext::EndElement()
     459             : {
     460             :     // call parent
     461           0 :     SdXML3DPolygonBasedShapeContext::EndElement();
     462           0 : }
     463             : 
     464             : // EOF
     465             : 
     466             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10