2010-10-12 08:56:41 -05:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2008-01-17 01:06:10 -06:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2008-04-10 09:33:57 -05:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
2008-01-17 01:06:10 -06:00
|
|
|
*
|
2010-02-12 08:01:35 -06:00
|
|
|
* Copyright 2000, 2010 Oracle and/or its affiliates.
|
2008-01-17 01:06:10 -06:00
|
|
|
*
|
2008-04-10 09:33:57 -05:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2008-01-17 01:06:10 -06:00
|
|
|
*
|
2008-04-10 09:33:57 -05:00
|
|
|
* This file is part of OpenOffice.org.
|
2008-01-17 01:06:10 -06:00
|
|
|
*
|
2008-04-10 09:33:57 -05:00
|
|
|
* OpenOffice.org is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License version 3
|
|
|
|
* only, as published by the Free Software Foundation.
|
2008-01-17 01:06:10 -06:00
|
|
|
*
|
2008-04-10 09:33:57 -05:00
|
|
|
* OpenOffice.org is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License version 3 for more details
|
|
|
|
* (a copy is included in the LICENSE file that accompanied this code).
|
2008-01-17 01:06:10 -06:00
|
|
|
*
|
2008-04-10 09:33:57 -05:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* version 3 along with OpenOffice.org. If not, see
|
|
|
|
* <http://www.openoffice.org/license.html>
|
|
|
|
* for a copy of the LGPLv3 License.
|
2008-01-17 01:06:10 -06:00
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
#include <functional>
|
|
|
|
#include <boost/bind.hpp>
|
|
|
|
|
2008-03-05 11:37:58 -06:00
|
|
|
#include <com/sun/star/awt/Point.hpp>
|
|
|
|
#include <com/sun/star/awt/Size.hpp>
|
2008-01-17 01:06:10 -06:00
|
|
|
#include "oox/drawingml/diagram/diagram.hxx"
|
2008-07-22 07:56:39 -05:00
|
|
|
#include "oox/drawingml/fillproperties.hxx"
|
2008-01-17 01:06:10 -06:00
|
|
|
|
2008-03-05 11:37:58 -06:00
|
|
|
using rtl::OUString;
|
|
|
|
using namespace ::com::sun::star;
|
2008-01-17 01:06:10 -06:00
|
|
|
|
|
|
|
namespace oox { namespace drawingml {
|
|
|
|
|
|
|
|
namespace dgm {
|
|
|
|
|
|
|
|
|
|
|
|
void Connection::dump()
|
|
|
|
{
|
2010-10-20 11:31:49 -05:00
|
|
|
OSL_TRACE("dgm: cnx modelId %s, srcId %s, dstId %s",
|
2008-01-17 01:06:10 -06:00
|
|
|
OUSTRING_TO_CSTR( msModelId ),
|
|
|
|
OUSTRING_TO_CSTR( msSourceId ),
|
2010-10-20 11:31:49 -05:00
|
|
|
OUSTRING_TO_CSTR( msDestId ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
Point::Point()
|
|
|
|
: mpShape( new Shape( "com.sun.star.drawing.GraphicObjectShape" ) )
|
|
|
|
, mnType( 0 )
|
|
|
|
{
|
2008-01-17 01:06:10 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void Point::dump()
|
|
|
|
{
|
2010-10-20 11:31:49 -05:00
|
|
|
OSL_TRACE( "dgm: pt cnxId %s, modelId %s",
|
2008-01-17 01:06:10 -06:00
|
|
|
OUSTRING_TO_CSTR( msCnxId ),
|
2010-10-20 11:31:49 -05:00
|
|
|
OUSTRING_TO_CSTR( msModelId ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
void Point::setModelId( const ::rtl::OUString & sModelId )
|
|
|
|
{
|
|
|
|
msModelId = sModelId;
|
|
|
|
mpShape->setName( msModelId );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool PointsTree::addChild( const PointsTreePtr & pChild )
|
|
|
|
{
|
|
|
|
bool added = false;
|
|
|
|
|
|
|
|
OSL_ENSURE( pChild->mpParent.expired(), "can't add, has already a parent" );
|
|
|
|
OSL_ENSURE( mpNode, "has no node" );
|
|
|
|
if( mpNode && pChild->mpParent.expired() )
|
|
|
|
{
|
|
|
|
pChild->mpParent = shared_from_this();
|
|
|
|
maChildrens.push_back( pChild );
|
|
|
|
added = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return added;
|
2008-01-17 01:06:10 -06:00
|
|
|
}
|
|
|
|
|
2010-10-20 11:31:49 -05:00
|
|
|
PointsTreePtr PointsTree::getParent() const
|
|
|
|
{
|
|
|
|
if( !mpParent.expired() )
|
|
|
|
{
|
|
|
|
return mpParent.lock() ;
|
|
|
|
}
|
|
|
|
return PointsTreePtr();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-05 11:37:58 -06:00
|
|
|
} // dgm namespace
|
2008-01-17 01:06:10 -06:00
|
|
|
|
|
|
|
DiagramData::DiagramData()
|
2008-07-22 07:56:39 -05:00
|
|
|
: mpFillProperties( new FillProperties )
|
2008-01-17 01:06:10 -06:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void DiagramData::dump()
|
|
|
|
{
|
|
|
|
OSL_TRACE("Dgm: DiagramData # of cnx: %d", maConnections.size() );
|
|
|
|
std::for_each( maConnections.begin(), maConnections.end(),
|
|
|
|
boost::bind( &dgm::Connection::dump, _1 ) );
|
|
|
|
OSL_TRACE("Dgm: DiagramData # of pt: %d", maPoints.size() );
|
|
|
|
std::for_each( maPoints.begin(), maPoints.end(),
|
|
|
|
boost::bind( &dgm::Point::dump, _1 ) );
|
|
|
|
}
|
|
|
|
|
2010-10-20 11:31:49 -05:00
|
|
|
static void setPosition( const dgm::PointPtr & pPoint, const awt::Point & pt )
|
|
|
|
{
|
|
|
|
ShapePtr pShape = pPoint->getShape();
|
|
|
|
awt::Size sz;
|
|
|
|
sz.Width = 50;
|
|
|
|
sz.Height = 50;
|
|
|
|
pShape->setPosition( pt );
|
|
|
|
pShape->setSize( sz );
|
|
|
|
}
|
|
|
|
|
|
|
|
void DiagramLayout::layout( const dgm::PointsTreePtr & pTree, const awt::Point & pt )
|
2008-03-05 11:37:58 -06:00
|
|
|
{
|
|
|
|
setPosition( pTree->getPoint(), pt );
|
|
|
|
awt::Point nextPt = pt;
|
|
|
|
nextPt.Y += 50;
|
|
|
|
dgm::PointsTree::Childrens::const_iterator iter;
|
2010-12-23 10:33:19 -06:00
|
|
|
for( iter = pTree->beginChild(); iter != pTree->endChild(); ++iter )
|
2008-03-05 11:37:58 -06:00
|
|
|
{
|
|
|
|
layout( *iter, nextPt );
|
|
|
|
nextPt.X += 50;
|
|
|
|
}
|
|
|
|
}
|
2008-01-17 01:06:10 -06:00
|
|
|
|
|
|
|
void Diagram::setData( const DiagramDataPtr & pData)
|
|
|
|
{
|
|
|
|
mpData = pData;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Diagram::setLayout( const DiagramLayoutPtr & pLayout)
|
|
|
|
{
|
|
|
|
mpLayout = pLayout;
|
|
|
|
}
|
|
|
|
|
2010-10-20 11:31:49 -05:00
|
|
|
void Diagram::setQStyles( const DiagramQStylesPtr & pStyles)
|
2008-01-17 01:06:10 -06:00
|
|
|
{
|
2010-10-20 11:31:49 -05:00
|
|
|
mpQStyles = pStyles;
|
2010-10-19 10:04:12 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-20 11:31:49 -05:00
|
|
|
void Diagram::setColors( const DiagramColorsPtr & pColors)
|
|
|
|
{
|
|
|
|
mpColors = pColors;
|
2008-01-17 01:06:10 -06:00
|
|
|
}
|
|
|
|
|
2008-03-05 11:37:58 -06:00
|
|
|
void Diagram::build( )
|
|
|
|
{
|
|
|
|
OSL_TRACE( "building diagram" );
|
|
|
|
typedef std::map< OUString, dgm::PointPtr > PointsMap;
|
|
|
|
PointsMap aPointsMap;
|
|
|
|
dgm::Points::iterator aPointsIter( mpData->getPoints( ).begin() );
|
|
|
|
for( ; aPointsIter != mpData->getPoints( ).end() ; aPointsIter++ )
|
|
|
|
{
|
|
|
|
const OUString & sName((*aPointsIter)->getModelId());
|
|
|
|
if( sName.getLength() > 0 )
|
|
|
|
{
|
|
|
|
aPointsMap[ sName ] = *aPointsIter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef std::map< OUString, dgm::PointsTreePtr > PointsTreeMap;
|
|
|
|
PointsTreeMap aTreeMap;
|
|
|
|
PointsTreeMap aRoots;
|
|
|
|
|
|
|
|
dgm::Connections & aConnections(mpData->getConnections( ) );
|
|
|
|
dgm::Connections::iterator aCnxIter;
|
|
|
|
for( aCnxIter = aConnections.begin(); aCnxIter != aConnections.end(); ++aCnxIter )
|
|
|
|
{
|
|
|
|
OSL_ENSURE( *aCnxIter, "NULL connection found" );
|
|
|
|
if( (*aCnxIter)->mnType != XML_parOf )
|
|
|
|
{
|
|
|
|
// OSL_TRACE( "ignoring relation %s", OUSTRING_TO_CSTR( (*aCnxIter)->msModelId ) );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
dgm::PointPtr pDest;
|
|
|
|
dgm::PointsTreePtr pSource;
|
|
|
|
PointsMap::iterator iterP;
|
|
|
|
OUString & srcId( (*aCnxIter)->msSourceId );
|
|
|
|
OUString & dstId( (*aCnxIter)->msDestId );
|
|
|
|
OSL_TRACE( "connexion %s -> %s", OUSTRING_TO_CSTR( srcId ),
|
|
|
|
OUSTRING_TO_CSTR( dstId ) );
|
|
|
|
|
|
|
|
PointsTreeMap::iterator iterT = aTreeMap.find( srcId );
|
|
|
|
if( iterT != aTreeMap.end() )
|
|
|
|
{
|
|
|
|
pSource = iterT->second;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// this tree node is not found. create it with the source
|
|
|
|
// and make it the root node.
|
|
|
|
iterP = aPointsMap.find( srcId );
|
|
|
|
if( iterP != aPointsMap.end() )
|
|
|
|
{
|
|
|
|
pSource.reset( new dgm::PointsTree( iterP->second ) );
|
|
|
|
aRoots[ srcId ] = pSource;
|
|
|
|
aTreeMap[ srcId ] = pSource;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
OSL_TRACE("parent node not found !");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
iterP = aPointsMap.find( dstId );
|
|
|
|
if( iterP != aPointsMap.end() )
|
|
|
|
{
|
|
|
|
pDest = iterP->second;
|
|
|
|
}
|
|
|
|
OSL_ENSURE( pDest, "destination not found" );
|
|
|
|
OSL_ENSURE( pSource, "source not found" );
|
|
|
|
if(pDest && pSource)
|
|
|
|
{
|
|
|
|
dgm::PointsTreePtr pNode( new dgm::PointsTree( pDest ) );
|
|
|
|
bool added = pSource->addChild( pNode );
|
|
|
|
(void)added;
|
|
|
|
aRoots.erase( dstId );
|
|
|
|
OSL_ENSURE( added, "add child failed" );
|
|
|
|
aTreeMap[ dstId ] = pNode;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// check bounds
|
|
|
|
OSL_ENSURE( aRoots.size() == 1, "more than one root" );
|
2010-10-20 11:31:49 -05:00
|
|
|
// #i92239# roots may be empty
|
|
|
|
if( !aRoots.empty() )
|
2008-03-05 11:37:58 -06:00
|
|
|
{
|
2010-10-20 11:31:49 -05:00
|
|
|
mpRoot = aRoots.begin()->second;
|
|
|
|
OSL_TRACE( "root is %s", OUSTRING_TO_CSTR( mpRoot->getPoint()->getModelId() ) );
|
|
|
|
for( PointsTreeMap::iterator iter = aTreeMap.begin();
|
2010-12-23 10:33:19 -06:00
|
|
|
iter != aTreeMap.end(); ++iter )
|
2008-03-05 11:37:58 -06:00
|
|
|
{
|
2010-10-20 11:31:49 -05:00
|
|
|
if(! iter->second->getParent() )
|
|
|
|
{
|
|
|
|
OSL_TRACE("node without parent %s", OUSTRING_TO_CSTR( iter->first ) );
|
|
|
|
}
|
2008-03-05 11:37:58 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-17 01:06:10 -06:00
|
|
|
|
2008-03-05 11:37:58 -06:00
|
|
|
void Diagram::addTo( const ShapePtr & pParentShape )
|
2008-01-17 01:06:10 -06:00
|
|
|
{
|
|
|
|
dgm::Points & aPoints( mpData->getPoints( ) );
|
2008-03-05 11:37:58 -06:00
|
|
|
dgm::Points::iterator aPointsIter;
|
2010-10-20 11:31:49 -05:00
|
|
|
build( );
|
|
|
|
if( mpRoot.get() )
|
|
|
|
mpLayout->layout( mpRoot, awt::Point( 0, 0 ) );
|
2008-03-05 11:37:58 -06:00
|
|
|
|
|
|
|
for( aPointsIter = aPoints.begin(); aPointsIter != aPoints.end(); ++aPointsIter )
|
|
|
|
{
|
|
|
|
if( ( *aPointsIter )->getType() != XML_node )
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
ShapePtr pShape = ( *aPointsIter )->getShape( );
|
|
|
|
if( pShape->getName( ).getLength() > 0 )
|
|
|
|
{
|
|
|
|
maShapeMap[ pShape->getName( ) ] = pShape;
|
|
|
|
OSL_TRACE( "Dgm: added shape %s to map", OUSTRING_TO_CSTR( pShape->getName() ) );
|
|
|
|
}
|
|
|
|
pParentShape->addChild( pShape );
|
|
|
|
}
|
2008-01-17 01:06:10 -06:00
|
|
|
|
2008-07-22 07:56:39 -05:00
|
|
|
OSL_TRACE( "Dgm: addTo() # of childs %d", pParentShape->getChildren().size() );
|
|
|
|
for( std::vector< ShapePtr >::iterator iter = pParentShape->getChildren().begin();
|
|
|
|
iter != pParentShape->getChildren().end(); ++iter)
|
2008-01-17 01:06:10 -06:00
|
|
|
{
|
|
|
|
OSL_TRACE( "Dgm: shape name %s", OUSTRING_TO_CSTR( (*iter)->getName() ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-03-05 11:37:58 -06:00
|
|
|
OUString Diagram::getLayoutId() const
|
|
|
|
{
|
|
|
|
OUString sLayoutId;
|
|
|
|
if( mpLayout )
|
|
|
|
{
|
|
|
|
sLayoutId = mpLayout->getUniqueId();
|
|
|
|
}
|
|
|
|
return sLayoutId;
|
|
|
|
}
|
|
|
|
|
2008-01-17 01:06:10 -06:00
|
|
|
|
|
|
|
} }
|
2010-10-12 08:56:41 -05:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|