Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / oox / source / drawingml / diagram / diagramlayoutatoms.hxx
blob91028971473e914eeaab41f1a9f7bac3354c73ff
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_OOX_SOURCE_DRAWINGML_DIAGRAM_DIAGRAMLAYOUTATOMS_HXX
21 #define INCLUDED_OOX_SOURCE_DRAWINGML_DIAGRAM_DIAGRAMLAYOUTATOMS_HXX
23 #include <map>
24 #include <memory>
26 #include <com/sun/star/xml/sax/XFastAttributeList.hpp>
28 #include <oox/drawingml/shape.hxx>
29 #include "diagram.hxx"
31 namespace oox { namespace drawingml {
33 class DiagramLayout;
34 typedef std::shared_ptr< DiagramLayout > DiagramLayoutPtr;
36 // AG_IteratorAttributes
37 struct IteratorAttr
39 IteratorAttr();
41 // not sure this belong here, but wth
42 void loadFromXAttr( const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttributes );
44 std::vector<sal_Int32> maAxis;
45 sal_Int32 mnCnt;
46 bool mbHideLastTrans;
47 sal_Int32 mnPtType;
48 sal_Int32 mnSt;
49 sal_Int32 mnStep;
52 struct ConditionAttr
54 ConditionAttr();
56 // not sure this belong here, but wth
57 void loadFromXAttr( const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttributes );
59 sal_Int32 mnFunc;
60 sal_Int32 mnArg;
61 sal_Int32 mnOp;
62 OUString msVal;
63 sal_Int32 mnVal;
66 struct Constraint
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;
81 typedef std::map<sal_Int32, sal_Int32> LayoutProperty;
82 typedef std::map<OUString, LayoutProperty> LayoutPropertyMap;
84 struct LayoutAtomVisitor;
85 class LayoutAtom;
86 class LayoutNode;
88 typedef std::shared_ptr< LayoutAtom > LayoutAtomPtr;
90 /** abstract Atom for the layout */
91 class LayoutAtom
93 public:
94 LayoutAtom(LayoutNode& rLayoutNode) : mrLayoutNode(rLayoutNode) {}
95 virtual ~LayoutAtom() { }
97 LayoutNode& getLayoutNode()
98 { return mrLayoutNode; }
100 /** visitor acceptance
102 virtual void accept( LayoutAtomVisitor& ) = 0;
104 void setName( const OUString& sName )
105 { msName = sName; }
106 const OUString& getName() const
107 { return msName; }
109 private:
110 void addChild( const LayoutAtomPtr & pNode )
111 { mpChildNodes.push_back( pNode ); }
112 void setParent(const LayoutAtomPtr& pParent) { mpParent = pParent; }
114 public:
115 const std::vector<LayoutAtomPtr>& getChildren() const
116 { return mpChildNodes; }
118 LayoutAtomPtr getParent() const { return mpParent.lock(); }
120 static void connect(const LayoutAtomPtr& pParent, const LayoutAtomPtr& pChild)
122 pParent->addChild(pChild);
123 pChild->setParent(pParent);
126 // dump for debug
127 void dump(int level = 0);
129 protected:
130 LayoutNode& mrLayoutNode;
131 std::vector< LayoutAtomPtr > mpChildNodes;
132 std::weak_ptr<LayoutAtom> mpParent;
133 OUString msName;
136 class ConstraintAtom
137 : public LayoutAtom
139 public:
140 ConstraintAtom(LayoutNode& rLayoutNode) : LayoutAtom(rLayoutNode) {}
141 virtual void accept( LayoutAtomVisitor& ) override;
142 Constraint& getConstraint()
143 { return maConstraint; }
144 void parseConstraint(std::vector<Constraint>& rConstraints, bool bRequireForName) const;
145 private:
146 Constraint maConstraint;
149 class AlgAtom
150 : public LayoutAtom
152 public:
153 AlgAtom(LayoutNode& rLayoutNode) : LayoutAtom(rLayoutNode), mnType(0), maMap() {}
155 typedef std::map<sal_Int32,sal_Int32> ParamMap;
157 virtual void accept( LayoutAtomVisitor& ) override;
159 void setType( sal_Int32 nToken )
160 { mnType = nToken; }
161 void addParam( sal_Int32 nType, sal_Int32 nVal )
162 { maMap[nType]=nVal; }
163 sal_Int32 getVerticalShapesCount(const ShapePtr& rShape);
164 void layoutShape( const ShapePtr& rShape,
165 const std::vector<Constraint>& rConstraints );
167 void setAspectRatio(double fAspectRatio) { mfAspectRatio = fAspectRatio; }
169 double getAspectRatio() const { return mfAspectRatio; }
171 private:
172 sal_Int32 mnType;
173 ParamMap maMap;
174 /// Aspect ratio is not integer, so not part of maMap.
175 double mfAspectRatio = 0;
177 /// Determines the connector shape type for conn algorithm
178 sal_Int32 getConnectorType();
181 typedef std::shared_ptr< AlgAtom > AlgAtomPtr;
183 class ForEachAtom
184 : public LayoutAtom
186 public:
187 explicit ForEachAtom(LayoutNode& rLayoutNode, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttributes);
189 IteratorAttr & iterator()
190 { return maIter; }
191 void setRef(const OUString& rsRef)
192 { msRef = rsRef; }
193 const OUString& getRef() const
194 { return msRef; }
195 virtual void accept( LayoutAtomVisitor& ) override;
196 LayoutAtomPtr getRefAtom();
198 private:
199 IteratorAttr maIter;
200 OUString msRef;
203 typedef std::shared_ptr< ForEachAtom > ForEachAtomPtr;
205 class ConditionAtom
206 : public LayoutAtom
208 public:
209 explicit ConditionAtom(LayoutNode& rLayoutNode, bool isElse, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttributes);
210 virtual void accept( LayoutAtomVisitor& ) override;
211 bool getDecision(const dgm::Point* pPresPoint) const;
213 private:
214 static bool compareResult(sal_Int32 nOperator, sal_Int32 nFirst, sal_Int32 nSecond);
215 sal_Int32 getNodeCount(const dgm::Point* pPresPoint) const;
217 bool const mIsElse;
218 IteratorAttr maIter;
219 ConditionAttr maCond;
222 typedef std::shared_ptr< ConditionAtom > ConditionAtomPtr;
224 /** "choose" statements. Atoms will be tested in order. */
225 class ChooseAtom
226 : public LayoutAtom
228 public:
229 ChooseAtom(LayoutNode& rLayoutNode)
230 : LayoutAtom(rLayoutNode)
232 virtual void accept( LayoutAtomVisitor& ) override;
235 class LayoutNode
236 : public LayoutAtom
238 public:
239 typedef std::map<sal_Int32, OUString> VarMap;
241 LayoutNode(const Diagram& rDgm) : LayoutAtom(*this), mrDgm(rDgm), mnChildOrder(0) {}
242 const Diagram& getDiagram() const
243 { return mrDgm; }
244 virtual void accept( LayoutAtomVisitor& ) override;
245 VarMap & variables()
246 { return mVariables; }
247 void setMoveWith( const OUString & sName )
248 { msMoveWith = sName; }
249 void setStyleLabel( const OUString & sLabel )
250 { msStyleLabel = sLabel; }
251 void setChildOrder( sal_Int32 nOrder )
252 { mnChildOrder = nOrder; }
253 void setExistingShape( const ShapePtr& pShape )
254 { mpExistingShape = pShape; }
255 const ShapePtr& getExistingShape() const
256 { return mpExistingShape; }
257 const std::vector<ShapePtr> & getNodeShapes() const
258 { return mpNodeShapes; }
259 void addNodeShape(const ShapePtr& pShape)
260 { mpNodeShapes.push_back(pShape); }
262 bool setupShape( const ShapePtr& rShape,
263 const dgm::Point* pPresNode ) const;
265 const LayoutNode* getParentLayoutNode() const;
267 private:
268 const Diagram& mrDgm;
269 VarMap mVariables;
270 OUString msMoveWith;
271 OUString msStyleLabel;
272 ShapePtr mpExistingShape;
273 std::vector<ShapePtr> mpNodeShapes;
274 sal_Int32 mnChildOrder;
277 typedef std::shared_ptr< LayoutNode > LayoutNodePtr;
279 class ShapeAtom
280 : public LayoutAtom
282 public:
283 ShapeAtom(LayoutNode& rLayoutNode, const ShapePtr& pShape) : LayoutAtom(rLayoutNode), mpShapeTemplate(pShape) {}
284 virtual void accept( LayoutAtomVisitor& ) override;
285 const ShapePtr& getShapeTemplate() const
286 { return mpShapeTemplate; }
288 private:
289 ShapePtr const mpShapeTemplate;
292 typedef std::shared_ptr< ShapeAtom > ShapeAtomPtr;
296 #endif
298 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */