Files
libreoffice/svx/source/engine3d/polygn3d.cxx

241 lines
6.9 KiB
C++
Raw Normal View History

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
re-base on ALv2 code. Includes: Patch contributed by Christian Lippka impress212: #i113063# patch: dubios self assign in svx/source/dialog/framelink.cxx http://svn.apache.org/viewvc?view=revision&revision=1167619 Patches contributed by Mathias Bauer gnumake4 work variously http://svn.apache.org/viewvc?view=revision&revision=1394707 http://svn.apache.org/viewvc?view=revision&revision=1394326 cws mba34issues01: #i117712#: fix several resource errors introduced by IAccessible2 implementation http://svn.apache.org/viewvc?view=revision&revision=1172343 cws mba34issues01: #i117719#: use correct resource ID http://svn.apache.org/viewvc?view=revision&revision=1172351 Patch contributed by Andre Fischer Do not add targets for junit tests when junit is disabled. http://svn.apache.org/viewvc?view=revision&revision=1241508 Patches contributed by Armin Le-Grand #118804# corrected GraphicExporter behaviour on shortcut when pixel graphic is requested http://svn.apache.org/viewvc?view=revision&revision=1240195 fix for #118525#: Using primitives for chart sub-geometry visualisation http://svn.apache.org/viewvc?view=revision&revision=1226879 #118485# - Styles for OLEs are not saved. http://svn.apache.org/viewvc?view=revision&revision=1182166 #118524: apply patch, followup fixes to 118485 http://svn.apache.org/viewvc?view=revision&revision=1186077 13f79535-47bb-0310-9956-ffa450edef68 Patch contributed by Regina Henschel linecap: Reintegrating finished LineCap feature http://svn.apache.org/viewvc?view=revision&revision=1232507 Patch contributed by Wang Lei (leiw) #i118760# split the first table cell vertically, then undo&redo, the Presentation app will crash http://svn.apache.org/viewvc?view=revision&revision=1301361 cleanup globlmn hacks, undo dependent fixmes.
2012-11-21 22:06:52 +00:00
/*
* This file is part of the LibreOffice project.
2000-09-18 16:07:07 +00:00
*
re-base on ALv2 code. Includes: Patch contributed by Christian Lippka impress212: #i113063# patch: dubios self assign in svx/source/dialog/framelink.cxx http://svn.apache.org/viewvc?view=revision&revision=1167619 Patches contributed by Mathias Bauer gnumake4 work variously http://svn.apache.org/viewvc?view=revision&revision=1394707 http://svn.apache.org/viewvc?view=revision&revision=1394326 cws mba34issues01: #i117712#: fix several resource errors introduced by IAccessible2 implementation http://svn.apache.org/viewvc?view=revision&revision=1172343 cws mba34issues01: #i117719#: use correct resource ID http://svn.apache.org/viewvc?view=revision&revision=1172351 Patch contributed by Andre Fischer Do not add targets for junit tests when junit is disabled. http://svn.apache.org/viewvc?view=revision&revision=1241508 Patches contributed by Armin Le-Grand #118804# corrected GraphicExporter behaviour on shortcut when pixel graphic is requested http://svn.apache.org/viewvc?view=revision&revision=1240195 fix for #118525#: Using primitives for chart sub-geometry visualisation http://svn.apache.org/viewvc?view=revision&revision=1226879 #118485# - Styles for OLEs are not saved. http://svn.apache.org/viewvc?view=revision&revision=1182166 #118524: apply patch, followup fixes to 118485 http://svn.apache.org/viewvc?view=revision&revision=1186077 13f79535-47bb-0310-9956-ffa450edef68 Patch contributed by Regina Henschel linecap: Reintegrating finished LineCap feature http://svn.apache.org/viewvc?view=revision&revision=1232507 Patch contributed by Wang Lei (leiw) #i118760# split the first table cell vertically, then undo&redo, the Presentation app will crash http://svn.apache.org/viewvc?view=revision&revision=1301361 cleanup globlmn hacks, undo dependent fixmes.
2012-11-21 22:06:52 +00:00
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
2000-09-18 16:07:07 +00:00
*
re-base on ALv2 code. Includes: Patch contributed by Christian Lippka impress212: #i113063# patch: dubios self assign in svx/source/dialog/framelink.cxx http://svn.apache.org/viewvc?view=revision&revision=1167619 Patches contributed by Mathias Bauer gnumake4 work variously http://svn.apache.org/viewvc?view=revision&revision=1394707 http://svn.apache.org/viewvc?view=revision&revision=1394326 cws mba34issues01: #i117712#: fix several resource errors introduced by IAccessible2 implementation http://svn.apache.org/viewvc?view=revision&revision=1172343 cws mba34issues01: #i117719#: use correct resource ID http://svn.apache.org/viewvc?view=revision&revision=1172351 Patch contributed by Andre Fischer Do not add targets for junit tests when junit is disabled. http://svn.apache.org/viewvc?view=revision&revision=1241508 Patches contributed by Armin Le-Grand #118804# corrected GraphicExporter behaviour on shortcut when pixel graphic is requested http://svn.apache.org/viewvc?view=revision&revision=1240195 fix for #118525#: Using primitives for chart sub-geometry visualisation http://svn.apache.org/viewvc?view=revision&revision=1226879 #118485# - Styles for OLEs are not saved. http://svn.apache.org/viewvc?view=revision&revision=1182166 #118524: apply patch, followup fixes to 118485 http://svn.apache.org/viewvc?view=revision&revision=1186077 13f79535-47bb-0310-9956-ffa450edef68 Patch contributed by Regina Henschel linecap: Reintegrating finished LineCap feature http://svn.apache.org/viewvc?view=revision&revision=1232507 Patch contributed by Wang Lei (leiw) #i118760# split the first table cell vertically, then undo&redo, the Presentation app will crash http://svn.apache.org/viewvc?view=revision&revision=1301361 cleanup globlmn hacks, undo dependent fixmes.
2012-11-21 22:06:52 +00:00
* This file incorporates work covered by the following license notice:
2000-09-18 16:07:07 +00:00
*
re-base on ALv2 code. Includes: Patch contributed by Christian Lippka impress212: #i113063# patch: dubios self assign in svx/source/dialog/framelink.cxx http://svn.apache.org/viewvc?view=revision&revision=1167619 Patches contributed by Mathias Bauer gnumake4 work variously http://svn.apache.org/viewvc?view=revision&revision=1394707 http://svn.apache.org/viewvc?view=revision&revision=1394326 cws mba34issues01: #i117712#: fix several resource errors introduced by IAccessible2 implementation http://svn.apache.org/viewvc?view=revision&revision=1172343 cws mba34issues01: #i117719#: use correct resource ID http://svn.apache.org/viewvc?view=revision&revision=1172351 Patch contributed by Andre Fischer Do not add targets for junit tests when junit is disabled. http://svn.apache.org/viewvc?view=revision&revision=1241508 Patches contributed by Armin Le-Grand #118804# corrected GraphicExporter behaviour on shortcut when pixel graphic is requested http://svn.apache.org/viewvc?view=revision&revision=1240195 fix for #118525#: Using primitives for chart sub-geometry visualisation http://svn.apache.org/viewvc?view=revision&revision=1226879 #118485# - Styles for OLEs are not saved. http://svn.apache.org/viewvc?view=revision&revision=1182166 #118524: apply patch, followup fixes to 118485 http://svn.apache.org/viewvc?view=revision&revision=1186077 13f79535-47bb-0310-9956-ffa450edef68 Patch contributed by Regina Henschel linecap: Reintegrating finished LineCap feature http://svn.apache.org/viewvc?view=revision&revision=1232507 Patch contributed by Wang Lei (leiw) #i118760# split the first table cell vertically, then undo&redo, the Presentation app will crash http://svn.apache.org/viewvc?view=revision&revision=1301361 cleanup globlmn hacks, undo dependent fixmes.
2012-11-21 22:06:52 +00:00
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
2000-09-18 16:07:07 +00:00
#include <svx/polygn3d.hxx>
#include <svx/svdpage.hxx>
#include "svx/globl3d.hxx"
#include <basegfx/point/b3dpoint.hxx>
#include <sdr/contact/viewcontactofe3dpolygon.hxx>
#include <basegfx/polygon/b3dpolygon.hxx>
#include <basegfx/polygon/b3dpolygontools.hxx>
2000-09-18 16:07:07 +00:00
TYPEINIT1(E3dPolygonObj, E3dCompoundObject);
2011-04-07 15:47:21 +03:00
// DrawContact section
sdr::contact::ViewContact* E3dPolygonObj::CreateObjectSpecificViewContact()
{
return new sdr::contact::ViewContactOfE3dPolygon(*this);
}
2000-09-18 16:07:07 +00:00
E3dPolygonObj::E3dPolygonObj(
E3dDefaultAttributes& rDefault,
const basegfx::B3DPolyPolygon& rPolyPoly3D,
bool bLinOnly)
2000-09-18 16:07:07 +00:00
: E3dCompoundObject(rDefault),
bLineOnly(bLinOnly)
{
2011-04-07 15:47:21 +03:00
// Set geometry
2000-09-18 16:07:07 +00:00
SetPolyPolygon3D(rPolyPoly3D);
2011-04-07 15:47:21 +03:00
// Create default normals
2000-09-18 16:07:07 +00:00
CreateDefaultNormals();
2011-04-07 15:47:21 +03:00
// Create default texture coordinates
2000-09-18 16:07:07 +00:00
CreateDefaultTexture();
}
E3dPolygonObj::E3dPolygonObj()
: E3dCompoundObject(),
bLineOnly(false) // added missing initialisation
2000-09-18 16:07:07 +00:00
{
2011-04-07 15:47:21 +03:00
// Create no geometry
2000-09-18 16:07:07 +00:00
}
void E3dPolygonObj::CreateDefaultNormals()
{
basegfx::B3DPolyPolygon aPolyNormals;
2000-09-18 16:07:07 +00:00
// Create a complete tools::PolyPolygon with the plane normal
for(sal_uInt32 a(0L); a < aPolyPoly3D.count(); a++)
2000-09-18 16:07:07 +00:00
{
2011-04-07 15:47:21 +03:00
// Find source polygon
const basegfx::B3DPolygon aPolygon(aPolyPoly3D.getB3DPolygon(a));
2000-09-18 16:07:07 +00:00
2011-04-07 15:47:21 +03:00
// Creating a new polygon for the normal
basegfx::B3DPolygon aNormals;
2000-09-18 16:07:07 +00:00
2011-04-07 15:47:21 +03:00
// Get normal (and invert)
basegfx::B3DVector aNormal(-aPolygon.getNormal());
2000-09-18 16:07:07 +00:00
2011-04-07 15:47:21 +03:00
// Fill new polygon
for(sal_uInt32 b(0L); b < aPolygon.count(); b++)
{
aNormals.append(aNormal);
}
2000-09-18 16:07:07 +00:00
2011-04-07 15:47:21 +03:00
// Insert new polygon into the PolyPolygon
aPolyNormals.append(aNormals);
2000-09-18 16:07:07 +00:00
}
2011-04-07 15:47:21 +03:00
// Set default normal
2000-09-18 16:07:07 +00:00
SetPolyNormals3D(aPolyNormals);
}
void E3dPolygonObj::CreateDefaultTexture()
{
basegfx::B2DPolyPolygon aPolyTexture;
// Create a complete tools::PolyPolygon with the texture coordinates
2011-04-07 15:47:21 +03:00
// The texture coordinates extend over X,Y and Z
// on the whole extreme values in the range 0.0 .. 1.0
for(sal_uInt32 a(0L); a < aPolyPoly3D.count(); a++)
2000-09-18 16:07:07 +00:00
{
2011-04-07 15:47:21 +03:00
// Find source polygon
const basegfx::B3DPolygon& aPolygon(aPolyPoly3D.getB3DPolygon(a));
2000-09-18 16:07:07 +00:00
2011-04-07 15:47:21 +03:00
// Determine the total size of the object
2008-10-17 08:40:10 +00:00
basegfx::B3DRange aVolume(basegfx::tools::getRange(aPolygon));
2000-09-18 16:07:07 +00:00
2011-04-07 15:47:21 +03:00
// Get normal
basegfx::B3DVector aNormal(aPolygon.getNormal());
aNormal.setX(fabs(aNormal.getX()));
aNormal.setY(fabs(aNormal.getY()));
aNormal.setZ(fabs(aNormal.getZ()));
2000-09-18 16:07:07 +00:00
2011-04-07 15:47:21 +03:00
// Decide which coordinates should be used as a source for the mapping
sal_uInt16 nSourceMode = 0;
2000-09-18 16:07:07 +00:00
2011-04-07 15:47:21 +03:00
// Determine the greatest degree of freedom
if(!(aNormal.getX() > aNormal.getY() && aNormal.getX() > aNormal.getZ()))
2000-09-18 16:07:07 +00:00
{
if(aNormal.getY() > aNormal.getZ())
2000-09-18 16:07:07 +00:00
{
2011-04-07 15:47:21 +03:00
// Y is the largest, use X,Z as mapping
2000-09-18 16:07:07 +00:00
nSourceMode = 1;
}
else
{
2011-04-07 15:47:21 +03:00
// Z is the largest, use X,Y as mapping
2000-09-18 16:07:07 +00:00
nSourceMode = 2;
}
}
2011-04-07 15:47:21 +03:00
// Create new polygon for texture coordinates
basegfx::B2DPolygon aTexture;
2011-04-07 15:47:21 +03:00
// Fill new polygon
for(sal_uInt32 b(0L); b < aPolygon.count(); b++)
2000-09-18 16:07:07 +00:00
{
basegfx::B2DPoint aTex;
const basegfx::B3DPoint aCandidate(aPolygon.getB3DPoint(b));
2000-09-18 16:07:07 +00:00
switch(nSourceMode)
{
2011-04-07 15:47:21 +03:00
case 0: //Source is Y,Z
if(aVolume.getHeight())
aTex.setX((aCandidate.getY() - aVolume.getMinY()) / aVolume.getHeight());
if(aVolume.getDepth())
aTex.setY((aCandidate.getZ() - aVolume.getMinZ()) / aVolume.getDepth());
2000-09-18 16:07:07 +00:00
break;
2011-04-07 15:47:21 +03:00
case 1: // Source is X,Z
if(aVolume.getWidth())
aTex.setX((aCandidate.getX() - aVolume.getMinX()) / aVolume.getWidth());
if(aVolume.getDepth())
aTex.setY((aCandidate.getZ() - aVolume.getMinZ()) / aVolume.getDepth());
2000-09-18 16:07:07 +00:00
break;
2011-04-07 15:47:21 +03:00
case 2: // Source is X,Y
if(aVolume.getWidth())
aTex.setX((aCandidate.getX() - aVolume.getMinX()) / aVolume.getWidth());
if(aVolume.getHeight())
aTex.setY((aCandidate.getY() - aVolume.getMinY()) / aVolume.getHeight());
2000-09-18 16:07:07 +00:00
break;
}
aTexture.append(aTex);
2000-09-18 16:07:07 +00:00
}
2011-04-07 15:47:21 +03:00
// Insert new polygon into the PolyPolygon
aPolyTexture.append(aTexture);
2000-09-18 16:07:07 +00:00
}
2011-04-07 15:47:21 +03:00
// Set default Texture coordinates
SetPolyTexture2D(aPolyTexture);
2000-09-18 16:07:07 +00:00
}
E3dPolygonObj::~E3dPolygonObj()
{
}
sal_uInt16 E3dPolygonObj::GetObjIdentifier() const
2000-09-18 16:07:07 +00:00
{
return E3D_POLYGONOBJ_ID;
}
void E3dPolygonObj::SetPolyPolygon3D(const basegfx::B3DPolyPolygon& rNewPolyPoly3D)
2000-09-18 16:07:07 +00:00
{
if ( aPolyPoly3D != rNewPolyPoly3D )
{
2011-04-07 15:47:21 +03:00
// New PolyPolygon; copying
2000-09-18 16:07:07 +00:00
aPolyPoly3D = rNewPolyPoly3D;
2011-04-07 15:47:21 +03:00
// Create new geometry
2008-10-17 08:40:10 +00:00
ActionChanged();
2000-09-18 16:07:07 +00:00
}
}
void E3dPolygonObj::SetPolyNormals3D(const basegfx::B3DPolyPolygon& rNewPolyNormals3D)
2000-09-18 16:07:07 +00:00
{
if ( aPolyNormals3D != rNewPolyNormals3D )
{
2011-04-07 15:47:21 +03:00
// New PolyPolygon; copying
2000-09-18 16:07:07 +00:00
aPolyNormals3D = rNewPolyNormals3D;
2011-04-07 15:47:21 +03:00
// Create new geometry
2008-10-17 08:40:10 +00:00
ActionChanged();
2000-09-18 16:07:07 +00:00
}
}
void E3dPolygonObj::SetPolyTexture2D(const basegfx::B2DPolyPolygon& rNewPolyTexture2D)
2000-09-18 16:07:07 +00:00
{
if ( aPolyTexture2D != rNewPolyTexture2D )
2000-09-18 16:07:07 +00:00
{
2011-04-07 15:47:21 +03:00
// New PolyPolygon; copying
aPolyTexture2D = rNewPolyTexture2D;
2000-09-18 16:07:07 +00:00
2011-04-07 15:47:21 +03:00
// Create new geometry
2008-10-17 08:40:10 +00:00
ActionChanged();
2000-09-18 16:07:07 +00:00
}
}
2011-04-07 15:47:21 +03:00
// Convert the object into a group object consisting of 6 polygons
2000-09-18 16:07:07 +00:00
SdrObject *E3dPolygonObj::DoConvertToPolyObj(bool /*bBezier*/, bool /*bAddText*/) const
2000-09-18 16:07:07 +00:00
{
return NULL;
}
E3dPolygonObj* E3dPolygonObj::Clone() const
2000-09-18 16:07:07 +00:00
{
return CloneHelper< E3dPolygonObj >();
2000-09-18 16:07:07 +00:00
}
void E3dPolygonObj::SetLineOnly(bool bNew)
2000-09-18 16:07:07 +00:00
{
if(bNew != bLineOnly)
{
bLineOnly = bNew;
2008-10-17 08:40:10 +00:00
ActionChanged();
2000-09-18 16:07:07 +00:00
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */