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