1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 // MARKER(update_precomp.py): autogen include statement, do not remove 23 #include "precompiled_xmloff.hxx" 24 25 #include <comphelper/extract.hxx> 26 #include "ximp3dobject.hxx" 27 #include <xmloff/XMLShapeStyleContext.hxx> 28 #include <xmloff/xmluconv.hxx> 29 #include <com/sun/star/beans/XPropertySet.hpp> 30 #include <com/sun/star/drawing/PointSequenceSequence.hpp> 31 #include <com/sun/star/drawing/PointSequence.hpp> 32 #include "xexptran.hxx" 33 #include <com/sun/star/drawing/PolyPolygonBezierCoords.hpp> 34 #include <xmloff/families.hxx> 35 #include "ximpstyl.hxx" 36 #include <xmloff/xmltoken.hxx> 37 #include <com/sun/star/drawing/PolyPolygonShape3D.hpp> 38 #include <com/sun/star/drawing/DoubleSequence.hpp> 39 #include <basegfx/polygon/b2dpolypolygon.hxx> 40 #include <basegfx/polygon/b2dpolypolygontools.hxx> 41 #include <basegfx/polygon/b3dpolypolygontools.hxx> 42 43 using ::rtl::OUString; 44 using ::rtl::OUStringBuffer; 45 46 using namespace ::com::sun::star; 47 48 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 49 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 50 51 TYPEINIT1( SdXML3DObjectContext, SdXMLShapeContext ); 52 53 SdXML3DObjectContext::SdXML3DObjectContext( 54 SvXMLImport& rImport, 55 sal_uInt16 nPrfx, 56 const OUString& rLocalName, 57 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList, 58 uno::Reference< drawing::XShapes >& rShapes, 59 sal_Bool bTemporaryShape) 60 : SdXMLShapeContext( rImport, nPrfx, rLocalName, xAttrList, rShapes, bTemporaryShape ), 61 mbSetTransform( sal_False ) 62 { 63 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0; 64 for(sal_Int16 i=0; i < nAttrCount; i++) 65 { 66 OUString sAttrName = xAttrList->getNameByIndex( i ); 67 OUString aLocalName; 68 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName ); 69 OUString sValue = xAttrList->getValueByIndex( i ); 70 const SvXMLTokenMap& rAttrTokenMap = GetImport().GetShapeImport()->Get3DObjectAttrTokenMap(); 71 72 switch(rAttrTokenMap.Get(nPrefix, aLocalName)) 73 { 74 case XML_TOK_3DOBJECT_DRAWSTYLE_NAME: 75 { 76 maDrawStyleName = sValue; 77 break; 78 } 79 case XML_TOK_3DOBJECT_TRANSFORM: 80 { 81 SdXMLImExTransform3D aTransform(sValue, GetImport().GetMM100UnitConverter()); 82 if(aTransform.NeedsAction()) 83 mbSetTransform = aTransform.GetFullHomogenTransform(mxHomMat); 84 break; 85 } 86 } 87 } 88 } 89 90 ////////////////////////////////////////////////////////////////////////////// 91 92 SdXML3DObjectContext::~SdXML3DObjectContext() 93 { 94 } 95 96 ////////////////////////////////////////////////////////////////////////////// 97 98 void SdXML3DObjectContext::StartElement(const uno::Reference< xml::sax::XAttributeList>& xAttrList) 99 { 100 uno::Reference< beans::XPropertySet > xPropSet(mxShape, uno::UNO_QUERY); 101 if(xPropSet.is()) 102 { 103 // set parameters 104 if(mbSetTransform) 105 { 106 uno::Any aAny; 107 aAny <<= mxHomMat; 108 xPropSet->setPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("D3DTransformMatrix")), aAny); 109 } 110 111 // call parent 112 SdXMLShapeContext::StartElement(xAttrList); 113 } 114 } 115 116 ////////////////////////////////////////////////////////////////////////////// 117 118 void SdXML3DObjectContext::EndElement() 119 { 120 // call parent 121 SdXMLShapeContext::EndElement(); 122 } 123 124 ////////////////////////////////////////////////////////////////////////////// 125 /* 126 void SdXML3DObjectContext::AddShape(uno::Reference< drawing::XShape >& xShape) 127 { 128 if(xShape.is() && mxShapes.is()) 129 { 130 // set shape local 131 mxShape = xShape; 132 133 // add new shape to parent 134 mxShapes->add( xShape ); 135 } 136 } 137 */ 138 ////////////////////////////////////////////////////////////////////////////// 139 /* 140 void SdXML3DObjectContext::SetStyle() 141 { 142 // set style on shape 143 if(maDrawStyleName.getLength() && mxShape.is()) 144 { 145 const SvXMLStyleContext* pStyle = 0L; 146 sal_Bool bAutoStyle(sal_False); 147 148 if(GetImport().GetShapeImport()->GetAutoStylesContext()) 149 pStyle = GetImport().GetShapeImport()->GetAutoStylesContext()->FindStyleChildContext( 150 XML_STYLE_FAMILY_SD_GRAPHICS_ID, maDrawStyleName); 151 152 if(pStyle) 153 bAutoStyle = sal_True; 154 155 if(!pStyle && GetImport().GetShapeImport()->GetStylesContext()) 156 pStyle = GetImport().GetShapeImport()->GetStylesContext()-> 157 FindStyleChildContext(XML_STYLE_FAMILY_SD_GRAPHICS_ID, maDrawStyleName); 158 159 if(pStyle && pStyle->ISA(XMLShapeStyleContext)) 160 { 161 uno::Reference< beans::XPropertySet > xPropSet(mxShape, uno::UNO_QUERY); 162 if(xPropSet.is()) 163 { 164 XMLShapeStyleContext* pDocStyle = (XMLShapeStyleContext*)pStyle; 165 166 if(pDocStyle->GetStyle().is()) 167 { 168 // set style on object 169 uno::Any aAny; 170 aAny <<= pDocStyle->GetStyle(); 171 xPropSet->setPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("Style")), aAny); 172 } 173 174 if(bAutoStyle) 175 { 176 // set PropertySet on object 177 pDocStyle->FillPropertySet(xPropSet); 178 } 179 } 180 } 181 } 182 } 183 */ 184 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 185 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 186 187 TYPEINIT1( SdXML3DCubeObjectShapeContext, SdXML3DObjectContext); 188 189 SdXML3DCubeObjectShapeContext::SdXML3DCubeObjectShapeContext( 190 SvXMLImport& rImport, 191 sal_uInt16 nPrfx, 192 const OUString& rLocalName, 193 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList, 194 uno::Reference< drawing::XShapes >& rShapes, 195 sal_Bool bTemporaryShape) 196 : SdXML3DObjectContext( rImport, nPrfx, rLocalName, xAttrList, rShapes, bTemporaryShape ), 197 maMinEdge(-2500.0, -2500.0, -2500.0), 198 maMaxEdge(2500.0, 2500.0, 2500.0), 199 mbMinEdgeUsed(sal_False), 200 mbMaxEdgeUsed(sal_False) 201 { 202 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0; 203 for(sal_Int16 i=0; i < nAttrCount; i++) 204 { 205 OUString sAttrName = xAttrList->getNameByIndex( i ); 206 OUString aLocalName; 207 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName ); 208 OUString sValue = xAttrList->getValueByIndex( i ); 209 const SvXMLTokenMap& rAttrTokenMap = GetImport().GetShapeImport()->Get3DCubeObjectAttrTokenMap(); 210 211 switch(rAttrTokenMap.Get(nPrefix, aLocalName)) 212 { 213 case XML_TOK_3DCUBEOBJ_MINEDGE: 214 { 215 ::basegfx::B3DVector aNewVec; 216 GetImport().GetMM100UnitConverter().convertB3DVector(aNewVec, sValue); 217 218 if(aNewVec != maMinEdge) 219 { 220 maMinEdge = aNewVec; 221 mbMinEdgeUsed = sal_True; 222 } 223 break; 224 } 225 case XML_TOK_3DCUBEOBJ_MAXEDGE: 226 { 227 ::basegfx::B3DVector aNewVec; 228 GetImport().GetMM100UnitConverter().convertB3DVector(aNewVec, sValue); 229 230 if(aNewVec != maMaxEdge) 231 { 232 maMaxEdge = aNewVec; 233 mbMaxEdgeUsed = sal_True; 234 } 235 break; 236 } 237 } 238 } 239 } 240 241 ////////////////////////////////////////////////////////////////////////////// 242 243 SdXML3DCubeObjectShapeContext::~SdXML3DCubeObjectShapeContext() 244 { 245 } 246 247 ////////////////////////////////////////////////////////////////////////////// 248 249 void SdXML3DCubeObjectShapeContext::StartElement(const uno::Reference< xml::sax::XAttributeList>& xAttrList) 250 { 251 // create shape 252 AddShape( "com.sun.star.drawing.Shape3DCubeObject" ); 253 if(mxShape.is()) 254 { 255 // add, set style and properties from base shape 256 SetStyle(); 257 SdXML3DObjectContext::StartElement(xAttrList); 258 259 // set local parameters on shape 260 uno::Reference< beans::XPropertySet > xPropSet(mxShape, uno::UNO_QUERY); 261 if(xPropSet.is()) 262 { 263 // set parameters 264 drawing::Position3D aPosition3D; 265 drawing::Direction3D aDirection3D; 266 267 // convert from min, max to size to be set 268 maMaxEdge = maMaxEdge - maMinEdge; 269 270 aPosition3D.PositionX = maMinEdge.getX(); 271 aPosition3D.PositionY = maMinEdge.getY(); 272 aPosition3D.PositionZ = maMinEdge.getZ(); 273 274 aDirection3D.DirectionX = maMaxEdge.getX(); 275 aDirection3D.DirectionY = maMaxEdge.getY(); 276 aDirection3D.DirectionZ = maMaxEdge.getZ(); 277 278 uno::Any aAny; 279 aAny <<= aPosition3D; 280 xPropSet->setPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("D3DPosition")), aAny); 281 aAny <<= aDirection3D; 282 xPropSet->setPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("D3DSize")), aAny); 283 } 284 } 285 } 286 287 ////////////////////////////////////////////////////////////////////////////// 288 289 void SdXML3DCubeObjectShapeContext::EndElement() 290 { 291 // call parent 292 SdXML3DObjectContext::EndElement(); 293 } 294 295 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 296 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 297 298 TYPEINIT1( SdXML3DSphereObjectShapeContext, SdXML3DObjectContext); 299 300 SdXML3DSphereObjectShapeContext::SdXML3DSphereObjectShapeContext( 301 SvXMLImport& rImport, 302 sal_uInt16 nPrfx, 303 const OUString& rLocalName, 304 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList, 305 uno::Reference< drawing::XShapes >& rShapes, 306 sal_Bool bTemporaryShape) 307 : SdXML3DObjectContext( rImport, nPrfx, rLocalName, xAttrList, rShapes, bTemporaryShape ), 308 maCenter(0.0, 0.0, 0.0), 309 maSize(5000.0, 5000.0, 5000.0), 310 mbCenterUsed(sal_False), 311 mbSizeUsed(sal_False) 312 { 313 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0; 314 for(sal_Int16 i=0; i < nAttrCount; i++) 315 { 316 OUString sAttrName = xAttrList->getNameByIndex( i ); 317 OUString aLocalName; 318 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName ); 319 OUString sValue = xAttrList->getValueByIndex( i ); 320 const SvXMLTokenMap& rAttrTokenMap = GetImport().GetShapeImport()->Get3DSphereObjectAttrTokenMap(); 321 322 switch(rAttrTokenMap.Get(nPrefix, aLocalName)) 323 { 324 case XML_TOK_3DSPHEREOBJ_CENTER: 325 { 326 ::basegfx::B3DVector aNewVec; 327 GetImport().GetMM100UnitConverter().convertB3DVector(aNewVec, sValue); 328 329 if(aNewVec != maCenter) 330 { 331 maCenter = aNewVec; 332 mbCenterUsed = sal_True; 333 } 334 break; 335 } 336 case XML_TOK_3DSPHEREOBJ_SIZE: 337 { 338 ::basegfx::B3DVector aNewVec; 339 GetImport().GetMM100UnitConverter().convertB3DVector(aNewVec, sValue); 340 341 if(aNewVec != maSize) 342 { 343 maSize = aNewVec; 344 mbSizeUsed = sal_True; 345 } 346 break; 347 } 348 } 349 } 350 } 351 352 ////////////////////////////////////////////////////////////////////////////// 353 354 SdXML3DSphereObjectShapeContext::~SdXML3DSphereObjectShapeContext() 355 { 356 } 357 358 ////////////////////////////////////////////////////////////////////////////// 359 360 void SdXML3DSphereObjectShapeContext::StartElement(const uno::Reference< xml::sax::XAttributeList>& xAttrList) 361 { 362 // create shape 363 AddShape( "com.sun.star.drawing.Shape3DSphereObject" ); 364 if(mxShape.is()) 365 { 366 // add, set style and properties from base shape 367 SetStyle(); 368 SdXML3DObjectContext::StartElement(xAttrList); 369 370 // set local parameters on shape 371 uno::Reference< beans::XPropertySet > xPropSet(mxShape, uno::UNO_QUERY); 372 if(xPropSet.is()) 373 { 374 // set parameters 375 drawing::Position3D aPosition3D; 376 drawing::Direction3D aDirection3D; 377 378 aPosition3D.PositionX = maCenter.getX(); 379 aPosition3D.PositionY = maCenter.getY(); 380 aPosition3D.PositionZ = maCenter.getZ(); 381 382 aDirection3D.DirectionX = maSize.getX(); 383 aDirection3D.DirectionY = maSize.getY(); 384 aDirection3D.DirectionZ = maSize.getZ(); 385 386 uno::Any aAny; 387 aAny <<= aPosition3D; 388 xPropSet->setPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("D3DPosition")), aAny); 389 aAny <<= aDirection3D; 390 xPropSet->setPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("D3DSize")), aAny); 391 } 392 } 393 } 394 395 ////////////////////////////////////////////////////////////////////////////// 396 397 void SdXML3DSphereObjectShapeContext::EndElement() 398 { 399 // call parent 400 SdXML3DObjectContext::EndElement(); 401 } 402 403 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 404 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 405 406 TYPEINIT1( SdXML3DPolygonBasedShapeContext, SdXML3DObjectContext ); 407 408 SdXML3DPolygonBasedShapeContext::SdXML3DPolygonBasedShapeContext( 409 SvXMLImport& rImport, 410 sal_uInt16 nPrfx, 411 const OUString& rLocalName, 412 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList, 413 uno::Reference< drawing::XShapes >& rShapes, 414 sal_Bool bTemporaryShape) 415 : SdXML3DObjectContext( rImport, nPrfx, rLocalName, xAttrList, rShapes, bTemporaryShape ) 416 { 417 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0; 418 for(sal_Int16 i=0; i < nAttrCount; i++) 419 { 420 OUString sAttrName = xAttrList->getNameByIndex( i ); 421 OUString aLocalName; 422 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName ); 423 OUString sValue = xAttrList->getValueByIndex( i ); 424 const SvXMLTokenMap& rAttrTokenMap = GetImport().GetShapeImport()->Get3DPolygonBasedAttrTokenMap(); 425 426 switch(rAttrTokenMap.Get(nPrefix, aLocalName)) 427 { 428 case XML_TOK_3DPOLYGONBASED_VIEWBOX: 429 { 430 maViewBox = sValue; 431 break; 432 } 433 case XML_TOK_3DPOLYGONBASED_D: 434 { 435 maPoints = sValue; 436 break; 437 } 438 } 439 } 440 } 441 442 ////////////////////////////////////////////////////////////////////////////// 443 444 SdXML3DPolygonBasedShapeContext::~SdXML3DPolygonBasedShapeContext() 445 { 446 } 447 448 ////////////////////////////////////////////////////////////////////////////// 449 450 void SdXML3DPolygonBasedShapeContext::StartElement(const uno::Reference< xml::sax::XAttributeList>& xAttrList) 451 { 452 uno::Reference< beans::XPropertySet > xPropSet(mxShape, uno::UNO_QUERY); 453 454 if(xPropSet.is()) 455 { 456 // set parameters 457 if(maPoints.getLength() && maViewBox.getLength()) 458 { 459 // import 2d PolyPolygon from svg:d 460 basegfx::B2DPolyPolygon aPolyPolygon; 461 462 if(basegfx::tools::importFromSvgD(aPolyPolygon, maPoints, true, 0)) 463 { 464 // convert to 3D PolyPolygon 465 const basegfx::B3DPolyPolygon aB3DPolyPolygon( 466 basegfx::tools::createB3DPolyPolygonFromB2DPolyPolygon( 467 aPolyPolygon)); 468 469 // convert to UNO API class PolyPolygonShape3D 470 drawing::PolyPolygonShape3D xPolyPolygon3D; 471 basegfx::tools::B3DPolyPolygonToUnoPolyPolygonShape3D( 472 aB3DPolyPolygon, 473 xPolyPolygon3D); 474 475 // set polygon data 476 uno::Any aAny; 477 aAny <<= xPolyPolygon3D; 478 xPropSet->setPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("D3DPolyPolygon3D")), aAny); 479 } 480 else 481 { 482 OSL_ENSURE(false, "Error on importing svg:d for 3D PolyPolygon (!)"); 483 } 484 } 485 486 // call parent 487 SdXML3DObjectContext::StartElement(xAttrList); 488 } 489 } 490 491 ////////////////////////////////////////////////////////////////////////////// 492 493 void SdXML3DPolygonBasedShapeContext::EndElement() 494 { 495 // call parent 496 SdXML3DObjectContext::EndElement(); 497 } 498 499 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 500 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 501 502 TYPEINIT1( SdXML3DLatheObjectShapeContext, SdXML3DPolygonBasedShapeContext); 503 504 SdXML3DLatheObjectShapeContext::SdXML3DLatheObjectShapeContext( 505 SvXMLImport& rImport, 506 sal_uInt16 nPrfx, 507 const OUString& rLocalName, 508 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList, 509 uno::Reference< drawing::XShapes >& rShapes, 510 sal_Bool bTemporaryShape) 511 : SdXML3DPolygonBasedShapeContext( rImport, nPrfx, rLocalName, xAttrList, rShapes, bTemporaryShape ) 512 { 513 } 514 515 ////////////////////////////////////////////////////////////////////////////// 516 517 SdXML3DLatheObjectShapeContext::~SdXML3DLatheObjectShapeContext() 518 { 519 } 520 521 ////////////////////////////////////////////////////////////////////////////// 522 523 void SdXML3DLatheObjectShapeContext::StartElement(const uno::Reference< xml::sax::XAttributeList>& xAttrList) 524 { 525 // create shape 526 AddShape( "com.sun.star.drawing.Shape3DLatheObject" ); 527 if(mxShape.is()) 528 { 529 // add, set style and properties from base shape 530 SetStyle(); 531 SdXML3DPolygonBasedShapeContext::StartElement(xAttrList); 532 } 533 } 534 535 ////////////////////////////////////////////////////////////////////////////// 536 537 void SdXML3DLatheObjectShapeContext::EndElement() 538 { 539 // call parent 540 SdXML3DPolygonBasedShapeContext::EndElement(); 541 } 542 543 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 544 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 545 546 TYPEINIT1( SdXML3DExtrudeObjectShapeContext, SdXML3DPolygonBasedShapeContext); 547 548 SdXML3DExtrudeObjectShapeContext::SdXML3DExtrudeObjectShapeContext( 549 SvXMLImport& rImport, 550 sal_uInt16 nPrfx, 551 const OUString& rLocalName, 552 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList, 553 uno::Reference< drawing::XShapes >& rShapes, 554 sal_Bool bTemporaryShape) 555 : SdXML3DPolygonBasedShapeContext( rImport, nPrfx, rLocalName, xAttrList, rShapes, bTemporaryShape ) 556 { 557 } 558 559 ////////////////////////////////////////////////////////////////////////////// 560 561 SdXML3DExtrudeObjectShapeContext::~SdXML3DExtrudeObjectShapeContext() 562 { 563 } 564 565 ////////////////////////////////////////////////////////////////////////////// 566 567 void SdXML3DExtrudeObjectShapeContext::StartElement(const uno::Reference< xml::sax::XAttributeList>& xAttrList) 568 { 569 AddShape( "com.sun.star.drawing.Shape3DExtrudeObject" ); 570 if(mxShape.is()) 571 { 572 // add, set style and properties from base shape 573 SetStyle(); 574 SdXML3DPolygonBasedShapeContext::StartElement(xAttrList); 575 } 576 } 577 578 ////////////////////////////////////////////////////////////////////////////// 579 580 void SdXML3DExtrudeObjectShapeContext::EndElement() 581 { 582 // call parent 583 SdXML3DPolygonBasedShapeContext::EndElement(); 584 } 585 586 // EOF 587