diff options
author | Grzegorz Araminowicz <g.araminowicz@gmail.com> | 2017-07-01 14:10:53 +0200 |
---|---|---|
committer | Jan Holesovsky <kendy@collabora.com> | 2017-07-20 10:03:08 +0200 |
commit | 21f28f94744b4378ba45b1361870592dd7cfabb2 (patch) | |
tree | b3e46c2b387491dc409a8e9f9621ca34a54a42f7 | |
parent | a976fa5f00a81ff0f006a2da73fded3825e0a7c1 (diff) |
SmartArt: add ShapeAtom to store shape template instead of LayoutNode
it allows to load shapes inside choose/if
Change-Id: I8040967d1f769796f6ad6b2d0c7b5ce698f89ee3
-rw-r--r-- | oox/source/drawingml/diagram/diagramlayoutatoms.cxx | 5 | ||||
-rw-r--r-- | oox/source/drawingml/diagram/diagramlayoutatoms.hxx | 21 | ||||
-rwxr-xr-x | oox/source/drawingml/diagram/layoutatomvisitors.cxx | 108 | ||||
-rwxr-xr-x | oox/source/drawingml/diagram/layoutatomvisitors.hxx | 21 | ||||
-rw-r--r-- | oox/source/drawingml/diagram/layoutnodecontext.cxx | 32 |
5 files changed, 142 insertions, 45 deletions
diff --git a/oox/source/drawingml/diagram/diagramlayoutatoms.cxx b/oox/source/drawingml/diagram/diagramlayoutatoms.cxx index d32e2f963b59..daf0edf52c5a 100644 --- a/oox/source/drawingml/diagram/diagramlayoutatoms.cxx +++ b/oox/source/drawingml/diagram/diagramlayoutatoms.cxx @@ -511,6 +511,11 @@ bool LayoutNode::setupShape( const ShapePtr& rShape, const Diagram& rDgm, sal_uI return false; } +void ShapeAtom::accept( LayoutAtomVisitor& rVisitor ) +{ + rVisitor.visit(*this); +} + } } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/oox/source/drawingml/diagram/diagramlayoutatoms.hxx b/oox/source/drawingml/diagram/diagramlayoutatoms.hxx index d5b9fcdf9e29..7a168528c0ec 100644 --- a/oox/source/drawingml/diagram/diagramlayoutatoms.hxx +++ b/oox/source/drawingml/diagram/diagramlayoutatoms.hxx @@ -238,12 +238,8 @@ public: { msStyleLabel = sLabel; } void setChildOrder( sal_Int32 nOrder ) { mnChildOrder = nOrder; } - void setShapeTemplate( const ShapePtr& pShape ) - { mpShapeTemplate = pShape; } void setExistingShape( const ShapePtr& pShape ) { mpExistingShape = pShape; } - const ShapePtr& getShapeTemplate() const - { return mpShapeTemplate; } const ShapePtr& getExistingShape() const { return mpExistingShape; } @@ -255,13 +251,27 @@ private: VarMap mVariables; OUString msMoveWith; OUString msStyleLabel; - ShapePtr mpShapeTemplate; ShapePtr mpExistingShape; sal_Int32 mnChildOrder; }; typedef std::shared_ptr< LayoutNode > LayoutNodePtr; +class ShapeAtom + : public LayoutAtom +{ +public: + ShapeAtom(const ShapePtr& pShape) : mpShapeTemplate(pShape) {} + virtual void accept( LayoutAtomVisitor& ) override; + const ShapePtr& getShapeTemplate() const + { return mpShapeTemplate; } + +private: + ShapePtr mpShapeTemplate; +}; + +typedef std::shared_ptr< ShapeAtom > ShapeAtomPtr; + struct LayoutAtomVisitor { virtual ~LayoutAtomVisitor() {} @@ -271,6 +281,7 @@ struct LayoutAtomVisitor virtual void visit(ConditionAtom& rAtom) = 0; virtual void visit(ChooseAtom& rAtom) = 0; virtual void visit(LayoutNode& rAtom) = 0; + virtual void visit(ShapeAtom& rAtom) = 0; }; } } diff --git a/oox/source/drawingml/diagram/layoutatomvisitors.cxx b/oox/source/drawingml/diagram/layoutatomvisitors.cxx index fd6e9d7b7e1b..ade7e4ccfec9 100755 --- a/oox/source/drawingml/diagram/layoutatomvisitors.cxx +++ b/oox/source/drawingml/diagram/layoutatomvisitors.cxx @@ -94,34 +94,35 @@ void ShapeCreationVisitor::visit(ChooseAtom& rAtom) void ShapeCreationVisitor::visit(LayoutNode& rAtom) { ShapePtr pCurrParent(mpParentShape); - ShapePtr pCurrShape(rAtom.getShapeTemplate()); if (rAtom.getExistingShape()) { rAtom.setupShape(rAtom.getExistingShape(), mrDgm, mnCurrIdx); } - else if( pCurrShape ) + else { - SAL_INFO( - "oox.drawingml", - "processing shape type " - << (pCurrShape->getCustomShapeProperties() - ->getShapePresetType())); - - // TODO(F3): cloned shape shares all properties by reference, - // don't change them! - ShapePtr pClonedShape( - new Shape( pCurrShape )); - - if( rAtom.setupShape(pClonedShape, mrDgm, mnCurrIdx) ) + ShapeTemplateVisitor aTemplateVisitor; + aTemplateVisitor.defaultVisit(rAtom); + ShapePtr pShape = aTemplateVisitor.getShapeCopy(); + + if (pShape) { - pCurrParent->addChild(pClonedShape); - pCurrParent = pClonedShape; + SAL_INFO( + "oox.drawingml", + "processing shape type " + << (pShape->getCustomShapeProperties() + ->getShapePresetType())); + + if (rAtom.setupShape(pShape, mrDgm, mnCurrIdx)) + { + pCurrParent->addChild(pShape); + pCurrParent = pShape; + } + } + else + { + SAL_WARN("oox.drawingml", "ShapeCreationVisitor::visit: no shape set while processing layoutnode named " << rAtom.getName()); } - } - else - { - SAL_WARN("oox.drawingml", "ShapeCreationVisitor::visit: no shape set while processing layoutnode named " << rAtom.getName() ); } // set new parent for children @@ -140,6 +141,63 @@ void ShapeCreationVisitor::visit(LayoutNode& rAtom) aLayoutingVisitor.defaultVisit(rAtom); } +void ShapeCreationVisitor::visit(ShapeAtom& /*rAtom*/) +{ + // stop processing +} + +void ShapeTemplateVisitor::defaultVisit(LayoutAtom& rAtom) +{ + // visit all children, one of them needs to be the layout algorithm + for (const auto& pAtom : rAtom.getChildren()) + pAtom->accept(*this); +} + +void ShapeTemplateVisitor::visit(ConstraintAtom& /*rAtom*/) +{ + // stop processing +} + +void ShapeTemplateVisitor::visit(AlgAtom& /*rAtom*/) +{ + // stop processing +} + +void ShapeTemplateVisitor::visit(ForEachAtom& /*rAtom*/) +{ + // stop processing +} + +void ShapeTemplateVisitor::visit(ConditionAtom& rAtom) +{ + defaultVisit(rAtom); +} + +void ShapeTemplateVisitor::visit(ChooseAtom& rAtom) +{ + defaultVisit(rAtom); +} + +void ShapeTemplateVisitor::visit(LayoutNode& /*rAtom*/) +{ + // stop processing - only traverse Condition/Choose atoms +} + +void ShapeTemplateVisitor::visit(ShapeAtom& rAtom) +{ + if (mpShape) + { + SAL_WARN("oox.drawingml", "multiple shapes encountered inside LayoutNode"); + return; + } + + ShapePtr pCurrShape(rAtom.getShapeTemplate()); + + // TODO(F3): cloned shape shares all properties by reference, + // don't change them! + mpShape.reset(new Shape(pCurrShape)); +} + void ShapeLayoutingVisitor::defaultVisit(LayoutAtom& rAtom) { // visit all children, one of them needs to be the layout algorithm @@ -177,6 +235,11 @@ void ShapeLayoutingVisitor::visit(LayoutNode& /*rAtom*/) // stop processing - only traverse Condition/Choose atoms } +void ShapeLayoutingVisitor::visit(ShapeAtom& /*rAtom*/) +{ + // stop processing +} + void ShallowPresNameVisitor::defaultVisit(LayoutAtom& rAtom) { // visit all children, at least one of them needs to have proper @@ -219,6 +282,11 @@ void ShallowPresNameVisitor::visit(LayoutNode& rAtom) aDataNode->second.size()); } +void ShallowPresNameVisitor::visit(ShapeAtom& /*rAtom*/) +{ + // stop processing +} + } } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/oox/source/drawingml/diagram/layoutatomvisitors.hxx b/oox/source/drawingml/diagram/layoutatomvisitors.hxx index 9353f4ba0a4b..28558f69bb24 100755 --- a/oox/source/drawingml/diagram/layoutatomvisitors.hxx +++ b/oox/source/drawingml/diagram/layoutatomvisitors.hxx @@ -41,6 +41,7 @@ class ShapeCreationVisitor : public LayoutAtomVisitor virtual void visit(ConditionAtom& rAtom) override; virtual void visit(ChooseAtom& rAtom) override; virtual void visit(LayoutNode& rAtom) override; + virtual void visit(ShapeAtom& rAtom) override; public: ShapeCreationVisitor(const ShapePtr& rParentShape, @@ -51,6 +52,24 @@ public: {} }; +class ShapeTemplateVisitor : public LayoutAtomVisitor +{ + ShapePtr mpShape; + + virtual void visit(ConstraintAtom& rAtom) override; + virtual void visit(AlgAtom& rAtom) override; + virtual void visit(ForEachAtom& rAtom) override; + virtual void visit(ConditionAtom& rAtom) override; + virtual void visit(ChooseAtom& rAtom) override; + virtual void visit(LayoutNode& rAtom) override; + virtual void visit(ShapeAtom& rAtom) override; + +public: + void defaultVisit(LayoutAtom& rAtom); + ShapePtr getShapeCopy() const + { return mpShape; } +}; + class ShapeLayoutingVisitor : public LayoutAtomVisitor { ShapePtr mpParentShape; @@ -62,6 +81,7 @@ class ShapeLayoutingVisitor : public LayoutAtomVisitor virtual void visit(ConditionAtom& rAtom) override; virtual void visit(ChooseAtom& rAtom) override; virtual void visit(LayoutNode& rAtom) override; + virtual void visit(ShapeAtom& rAtom) override; public: ShapeLayoutingVisitor(const ShapePtr& rParentShape, @@ -85,6 +105,7 @@ class ShallowPresNameVisitor : public LayoutAtomVisitor virtual void visit(ConditionAtom& rAtom) override; virtual void visit(ChooseAtom& rAtom) override; virtual void visit(LayoutNode& rAtom) override; + virtual void visit(ShapeAtom& rAtom) override; public: explicit ShallowPresNameVisitor(const Diagram& rDgm) : diff --git a/oox/source/drawingml/diagram/layoutnodecontext.cxx b/oox/source/drawingml/diagram/layoutnodecontext.cxx index 5d66de142c96..715e94d72eab 100644 --- a/oox/source/drawingml/diagram/layoutnodecontext.cxx +++ b/oox/source/drawingml/diagram/layoutnodecontext.cxx @@ -246,31 +246,23 @@ LayoutNodeContext::onCreateContext( ::sal_Int32 aElement, } case DGM_TOKEN( shape ): { - LayoutNodePtr pNode(std::dynamic_pointer_cast<LayoutNode>(mpNode)); - if( pNode ) - { - ShapePtr pShape; - - if( rAttribs.hasAttribute( XML_type ) ) - { - pShape.reset( new Shape("com.sun.star.drawing.CustomShape") ); - const sal_Int32 nType(rAttribs.getToken( XML_type, XML_obj )); - pShape->setSubType( nType ); - pShape->getCustomShapeProperties()->setShapePresetType( nType ); - } - else - { - pShape.reset( new Shape("com.sun.star.drawing.GroupShape") ); - } + ShapePtr pShape; - pNode->setShapeTemplate( pShape ); - return new ShapeContext( *this, ShapePtr(), pShape ); + if( rAttribs.hasAttribute( XML_type ) ) + { + pShape.reset( new Shape("com.sun.star.drawing.CustomShape") ); + const sal_Int32 nType(rAttribs.getToken( XML_type, XML_obj )); + pShape->setSubType( nType ); + pShape->getCustomShapeProperties()->setShapePresetType( nType ); } else { - SAL_WARN("oox", "OOX: encountered a shape in a non layoutNode context" ); + pShape.reset( new Shape("com.sun.star.drawing.GroupShape") ); } - break; + + ShapeAtomPtr pAtom( new ShapeAtom(pShape) ); + mpNode->addChild( pAtom ); + return new ShapeContext( *this, ShapePtr(), pShape ); } case DGM_TOKEN( extLst ): return nullptr; |