LibreOffice Module oox (master) 1
diagramlayoutatoms.hxx
Go to the documentation of this file.
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#ifndef INCLUDED_OOX_SOURCE_DRAWINGML_DIAGRAM_DIAGRAMLAYOUTATOMS_HXX
21#define INCLUDED_OOX_SOURCE_DRAWINGML_DIAGRAM_DIAGRAMLAYOUTATOMS_HXX
22
23#include <map>
24#include <memory>
25
26#include <com/sun/star/xml/sax/XFastAttributeList.hpp>
27#include <utility>
28
29#include "diagram.hxx"
30
31namespace oox::drawingml {
32
33class DiagramLayout;
34typedef std::shared_ptr< DiagramLayout > DiagramLayoutPtr;
35
36// AG_IteratorAttributes
38{
40
41 // not sure this belong here, but wth
42 void loadFromXAttr( const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttributes );
43
44 std::vector<sal_Int32> maAxis;
45 sal_Int32 mnCnt;
47 sal_Int32 mnPtType;
48 sal_Int32 mnSt;
49 sal_Int32 mnStep;
50};
51
53{
55
56 // not sure this belong here, but wth
57 void loadFromXAttr( const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttributes );
58
59 OUString msVal;
60 sal_Int32 mnFunc;
61 sal_Int32 mnArg;
62 sal_Int32 mnOp;
63 sal_Int32 mnVal;
64};
65
68{
69 OUString msForName;
70 OUString msRefForName;
71 double mfFactor;
72 double mfValue;
73 sal_Int32 mnFor;
74 sal_Int32 mnPointType;
75 sal_Int32 mnType;
76 sal_Int32 mnRefFor;
77 sal_Int32 mnRefType;
78 sal_Int32 mnRefPointType;
79 sal_Int32 mnOperator;
80};
81
83struct Rule
84{
85 OUString msForName;
86};
87
88typedef std::map<sal_Int32, sal_Int32> LayoutProperty;
89typedef std::map<OUString, LayoutProperty> LayoutPropertyMap;
90
92class LayoutAtom;
93class LayoutNode;
94
95typedef std::shared_ptr< LayoutAtom > LayoutAtomPtr;
96
99{
100public:
101 LayoutAtom(LayoutNode& rLayoutNode) : mrLayoutNode(rLayoutNode) {}
102 virtual ~LayoutAtom() { }
103
105 { return mrLayoutNode; }
106
109 virtual void accept( LayoutAtomVisitor& ) = 0;
110
111 void setName( const OUString& sName )
112 { msName = sName; }
113 const OUString& getName() const
114 { return msName; }
115
116private:
117 void addChild( const LayoutAtomPtr & pNode )
118 { mpChildNodes.push_back( pNode ); }
119 void setParent(const LayoutAtomPtr& pParent) { mpParent = pParent; }
120
121public:
122 const std::vector<LayoutAtomPtr>& getChildren() const
123 { return mpChildNodes; }
124
125 LayoutAtomPtr getParent() const { return mpParent.lock(); }
126
127 static void connect(const LayoutAtomPtr& pParent, const LayoutAtomPtr& pChild)
128 {
129 pParent->addChild(pChild);
130 pChild->setParent(pParent);
131 }
132
133 // dump for debug
134 void dump(int level = 0);
135
136protected:
138 std::vector< LayoutAtomPtr > mpChildNodes;
139 std::weak_ptr<LayoutAtom> mpParent;
140 OUString msName;
141};
142
144 : public LayoutAtom
145{
146public:
147 ConstraintAtom(LayoutNode& rLayoutNode) : LayoutAtom(rLayoutNode) {}
148 virtual void accept( LayoutAtomVisitor& ) override;
150 { return maConstraint; }
151 void parseConstraint(std::vector<Constraint>& rConstraints, bool bRequireForName) const;
152private:
154};
155
158 : public LayoutAtom
159{
160public:
161 RuleAtom(LayoutNode& rLayoutNode) : LayoutAtom(rLayoutNode) {}
162 virtual void accept( LayoutAtomVisitor& ) override;
164 { return maRule; }
165 void parseRule(std::vector<Rule>& rRules) const;
166private:
168};
169
171 : public LayoutAtom
172{
173public:
174 AlgAtom(LayoutNode& rLayoutNode) : LayoutAtom(rLayoutNode), mnType(0), maMap() {}
175
176 typedef std::map<sal_Int32,sal_Int32> ParamMap;
177
178 virtual void accept( LayoutAtomVisitor& ) override;
179
180 void setType( sal_Int32 nToken )
181 { mnType = nToken; }
182 const ParamMap& getMap() const { return maMap; }
183 void addParam( sal_Int32 nType, sal_Int32 nVal )
184 { maMap[nType]=nVal; }
185 sal_Int32 getVerticalShapesCount(const ShapePtr& rShape);
186 void layoutShape( const ShapePtr& rShape,
187 const std::vector<Constraint>& rConstraints,
188 const std::vector<Rule>& rRules );
189
190 void setAspectRatio(double fAspectRatio) { mfAspectRatio = fAspectRatio; }
191
192 double getAspectRatio() const { return mfAspectRatio; }
193
194private:
195 sal_Int32 mnType;
198 double mfAspectRatio = 0;
199
201 sal_Int32 getConnectorType();
202};
203
204typedef std::shared_ptr< AlgAtom > AlgAtomPtr;
205
208{
209public:
210 static void layoutShapeChildren(const AlgAtom& rAlg, const ShapePtr& rShape,
211 const std::vector<Constraint>& rConstraints);
212};
213
219{
220public:
221 static void layoutShapeChildren(const ShapePtr& rShape);
222};
223
228{
229public:
230 static void layoutShapeChildren(AlgAtom& rAlg, const ShapePtr& rShape,
231 const std::vector<Constraint>& rConstraints);
232
233private:
241 static void applyConstraintToLayout(const Constraint& rConstraint,
242 LayoutPropertyMap& rProperties);
243
248 static bool inferFromLayoutProperty(const LayoutProperty& rMap, sal_Int32 nRefType,
249 sal_Int32& rValue);
250};
251
253 : public LayoutAtom
254{
255public:
256 explicit ForEachAtom(LayoutNode& rLayoutNode, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttributes);
257
259 { return maIter; }
260 void setRef(const OUString& rsRef)
261 { msRef = rsRef; }
262 const OUString& getRef() const
263 { return msRef; }
264 virtual void accept( LayoutAtomVisitor& ) override;
266
267private:
269 OUString msRef;
270};
271
272typedef std::shared_ptr< ForEachAtom > ForEachAtomPtr;
273
275 : public LayoutAtom
276{
277public:
278 explicit ConditionAtom(LayoutNode& rLayoutNode, bool isElse, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttributes);
279 virtual void accept( LayoutAtomVisitor& ) override;
280 bool getDecision(const svx::diagram::Point* pPresPoint) const;
281
282private:
283 static bool compareResult(sal_Int32 nOperator, sal_Int32 nFirst, sal_Int32 nSecond);
284 sal_Int32 getNodeCount(const svx::diagram::Point* pPresPoint) const;
285
289};
290
291typedef std::shared_ptr< ConditionAtom > ConditionAtomPtr;
292
295 : public LayoutAtom
296{
297public:
298 ChooseAtom(LayoutNode& rLayoutNode)
299 : LayoutAtom(rLayoutNode)
300 {}
301 virtual void accept( LayoutAtomVisitor& ) override;
302};
303
305 : public LayoutAtom
306{
307public:
308 typedef std::map<sal_Int32, OUString> VarMap;
309
311 : LayoutAtom(*this)
312 , mrDgm(rDgm)
313 , mnChildOrder(0)
314 {
315 }
316 Diagram& getDiagram() { return mrDgm; }
317 virtual void accept( LayoutAtomVisitor& ) override;
319 { return mVariables; }
320 void setMoveWith( const OUString & sName )
321 { msMoveWith = sName; }
322 void setStyleLabel( const OUString & sLabel )
323 { msStyleLabel = sLabel; }
324 void setChildOrder( sal_Int32 nOrder )
325 { mnChildOrder = nOrder; }
326 sal_Int32 getChildOrder() const { return mnChildOrder; }
327 void setExistingShape( const ShapePtr& pShape )
328 { mpExistingShape = pShape; }
330 { return mpExistingShape; }
331 const std::vector<ShapePtr> & getNodeShapes() const
332 { return mpNodeShapes; }
333 void addNodeShape(const ShapePtr& pShape)
334 { mpNodeShapes.push_back(pShape); }
335
336 bool setupShape( const ShapePtr& rShape,
337 const svx::diagram::Point* pPresNode,
338 sal_Int32 nCurrIdx ) const;
339
340 const LayoutNode* getParentLayoutNode() const;
341
342private:
345 OUString msMoveWith;
346 OUString msStyleLabel;
348 std::vector<ShapePtr> mpNodeShapes;
349 sal_Int32 mnChildOrder;
350};
351
352typedef std::shared_ptr< LayoutNode > LayoutNodePtr;
353
355 : public LayoutAtom
356{
357public:
358 ShapeAtom(LayoutNode& rLayoutNode, ShapePtr pShape) : LayoutAtom(rLayoutNode), mpShapeTemplate(std::move(pShape)) {}
359 virtual void accept( LayoutAtomVisitor& ) override;
361 { return mpShapeTemplate; }
362
363private:
365};
366
367typedef std::shared_ptr< ShapeAtom > ShapeAtomPtr;
368
369}
370
371#endif
372
373/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void accept(LayoutAtomVisitor &) override
visitor acceptance
void setType(sal_Int32 nToken)
void layoutShape(const ShapePtr &rShape, const std::vector< Constraint > &rConstraints, const std::vector< Rule > &rRules)
AlgAtom(LayoutNode &rLayoutNode)
const ParamMap & getMap() const
void setAspectRatio(double fAspectRatio)
std::map< sal_Int32, sal_Int32 > ParamMap
sal_Int32 getVerticalShapesCount(const ShapePtr &rShape)
void addParam(sal_Int32 nType, sal_Int32 nVal)
double mfAspectRatio
Aspect ratio is not integer, so not part of maMap.
sal_Int32 getConnectorType()
Determines the connector shape type for conn algorithm.
virtual void accept(LayoutAtomVisitor &) override
visitor acceptance
ChooseAtom(LayoutNode &rLayoutNode)
Specifies the size and position for all child layout nodes.
static void applyConstraintToLayout(const Constraint &rConstraint, LayoutPropertyMap &rProperties)
Apply rConstraint to the rProperties shared layout state.
static bool inferFromLayoutProperty(const LayoutProperty &rMap, sal_Int32 nRefType, sal_Int32 &rValue)
Decides if a certain reference type (e.g.
static void layoutShapeChildren(AlgAtom &rAlg, const ShapePtr &rShape, const std::vector< Constraint > &rConstraints)
bool getDecision(const svx::diagram::Point *pPresPoint) const
virtual void accept(LayoutAtomVisitor &) override
visitor acceptance
sal_Int32 getNodeCount(const svx::diagram::Point *pPresPoint) const
static bool compareResult(sal_Int32 nOperator, sal_Int32 nFirst, sal_Int32 nSecond)
ConditionAtom(LayoutNode &rLayoutNode, bool isElse, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttributes)
virtual void accept(LayoutAtomVisitor &) override
visitor acceptance
ConstraintAtom(LayoutNode &rLayoutNode)
void parseConstraint(std::vector< Constraint > &rConstraints, bool bRequireForName) const
const OUString & getRef() const
virtual void accept(LayoutAtomVisitor &) override
visitor acceptance
void setRef(const OUString &rsRef)
ForEachAtom(LayoutNode &rLayoutNode, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttributes)
abstract Atom for the layout
void setName(const OUString &sName)
std::vector< LayoutAtomPtr > mpChildNodes
std::weak_ptr< LayoutAtom > mpParent
LayoutAtom(LayoutNode &rLayoutNode)
const std::vector< LayoutAtomPtr > & getChildren() const
LayoutAtomPtr getParent() const
static void connect(const LayoutAtomPtr &pParent, const LayoutAtomPtr &pChild)
const OUString & getName() const
virtual void accept(LayoutAtomVisitor &)=0
visitor acceptance
void addChild(const LayoutAtomPtr &pNode)
void setParent(const LayoutAtomPtr &pParent)
void setStyleLabel(const OUString &sLabel)
const LayoutNode * getParentLayoutNode() const
void setChildOrder(sal_Int32 nOrder)
void setExistingShape(const ShapePtr &pShape)
const std::vector< ShapePtr > & getNodeShapes() const
std::map< sal_Int32, OUString > VarMap
std::vector< ShapePtr > mpNodeShapes
void setMoveWith(const OUString &sName)
const ShapePtr & getExistingShape() const
bool setupShape(const ShapePtr &rShape, const svx::diagram::Point *pPresNode, sal_Int32 nCurrIdx) const
void addNodeShape(const ShapePtr &pShape)
virtual void accept(LayoutAtomVisitor &) override
visitor acceptance
Lays out child layout nodes along a vertical path and works with the trapezoid shape to create a pyra...
static void layoutShapeChildren(const ShapePtr &rShape)
Represents one <dgm:rule> element.
RuleAtom(LayoutNode &rLayoutNode)
void parseRule(std::vector< Rule > &rRules) const
virtual void accept(LayoutAtomVisitor &) override
visitor acceptance
virtual void accept(LayoutAtomVisitor &) override
visitor acceptance
const ShapePtr & getShapeTemplate() const
ShapeAtom(LayoutNode &rLayoutNode, ShapePtr pShape)
Finds optimal grid to layout children that have fixed aspect ratio.
static void layoutShapeChildren(const AlgAtom &rAlg, const ShapePtr &rShape, const std::vector< Constraint > &rConstraints)
OString sName
Definition: drawingml.cxx:4451
std::shared_ptr< ShapeAtom > ShapeAtomPtr
std::shared_ptr< ConditionAtom > ConditionAtomPtr
std::shared_ptr< Shape > ShapePtr
std::shared_ptr< AlgAtom > AlgAtomPtr
std::shared_ptr< LayoutAtom > LayoutAtomPtr
std::shared_ptr< LayoutNode > LayoutNodePtr
std::map< OUString, LayoutProperty > LayoutPropertyMap
std::shared_ptr< DiagramLayout > DiagramLayoutPtr
std::map< sal_Int32, sal_Int32 > LayoutProperty
std::shared_ptr< ForEachAtom > ForEachAtomPtr
DefTokenId nToken
QPRO_FUNC_TYPE nType
void loadFromXAttr(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttributes)
Constraints allow you to specify an ideal (or starting point) size for each shape.
std::vector< sal_Int32 > maAxis
void loadFromXAttr(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttributes)
Rules allow you to specify what to do when constraints can't be fully satisfied.