LibreOffice Module oox (master) 1
layoutatomvisitors.cxx
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
21
23
24#include <sal/log.hxx>
25
26using namespace ::com::sun::star;
27using namespace ::com::sun::star::uno;
28using namespace ::com::sun::star::xml::sax;
29using namespace ::oox::core;
30
31namespace oox::drawingml
32{
34{
35 // stop processing
36}
37
39{
40 // stop processing
41}
42
44{
45 if (meLookFor == ALGORITHM)
46 {
47 mpParentShape->setAspectRatio(rAtom.getAspectRatio());
48 mpParentShape->setVerticalShapesCount(rAtom.getVerticalShapesCount(mpParentShape));
49 }
50}
51
53{
55 return;
56
57 // stop processing if it's not a child of previous LayoutNode
58
59 const DiagramData::PointsNameMap::const_iterator aDataNode
60 = mrDgm.getData()->getPointsPresNameMap().find(rAtom.getName());
61 if (aDataNode == mrDgm.getData()->getPointsPresNameMap().end()
62 || mnCurrIdx >= static_cast<sal_Int32>(aDataNode->second.size()))
63 return;
64
65 const svx::diagram::Point* pNewNode = aDataNode->second.at(mnCurrIdx);
66 if (!mpCurrentNode || !pNewNode)
67 return;
68
69 bool bIsChild = false;
70 for (const auto& aConnection : mrDgm.getData()->getConnections())
71 if (aConnection.msSourceId == mpCurrentNode->msModelId
72 && aConnection.msDestId == pNewNode->msModelId)
73 bIsChild = true;
74
75 if (!bIsChild)
76 return;
77
78 ShapePtr pCurrParent(mpParentShape);
79
80 if (rAtom.getExistingShape())
81 {
82 // reuse existing shape
83 ShapePtr pShape = rAtom.getExistingShape();
84 if (rAtom.setupShape(pShape, pNewNode, mnCurrIdx))
85 {
86 pShape->setInternalName(rAtom.getName());
87 rAtom.addNodeShape(pShape);
88 mrDgm.getLayout()->getPresPointShapeMap()[pNewNode] = pShape;
89 }
90 }
91 else
92 {
93 ShapeTemplateVisitor aTemplateVisitor(mrDgm, pNewNode);
94 aTemplateVisitor.defaultVisit(rAtom);
95 ShapePtr pShape = aTemplateVisitor.getShapeCopy();
96
97 if (pShape)
98 {
99 SAL_INFO("oox.drawingml",
100 "processing shape type "
101 << (pShape->getCustomShapeProperties()->getShapePresetType()));
102
103 if (rAtom.setupShape(pShape, pNewNode, mnCurrIdx))
104 {
105 pShape->setInternalName(rAtom.getName());
106 pCurrParent->addChild(pShape);
107 pCurrParent = pShape;
108 rAtom.addNodeShape(pShape);
109 mrDgm.getLayout()->getPresPointShapeMap()[pNewNode] = pShape;
110 }
111 }
112 else
113 {
114 SAL_WARN("oox.drawingml",
115 "ShapeCreationVisitor::visit: no shape set while processing layoutnode named "
116 << rAtom.getName());
117 }
118 }
119
120 const svx::diagram::Point* pPreviousNode = mpCurrentNode;
121 mpCurrentNode = pNewNode;
122
123 // set new parent for children
124 ShapePtr pPreviousParent(mpParentShape);
125 mpParentShape = pCurrParent;
126
127 // process children
129 defaultVisit(rAtom);
130
132 defaultVisit(rAtom);
134
135 // restore parent
136 mpParentShape = pPreviousParent;
137 mpCurrentNode = pPreviousNode;
138}
139
141{
142 // stop processing
143}
144
146{
147 // stop processing
148}
149
151{
152 // stop processing
153}
154
156{
157 // stop processing
158}
159
161{
162 // stop processing
163}
164
166{
167 // stop processing - only traverse Condition/Choose atoms
168}
169
171{
172 if (mpShape)
173 {
174 SAL_WARN("oox.drawingml", "multiple shapes encountered inside LayoutNode");
175 return;
176 }
177
178 const ShapePtr& pCurrShape(rAtom.getShapeTemplate());
179
180 // TODO(F3): cloned shape shares all properties by reference,
181 // don't change them!
182 mpShape = std::make_shared<Shape>(pCurrShape);
183 // Fill properties have to be changed as sometimes only the presentation node contains the blip
184 // fill, unshare those.
185 mpShape->cloneFillProperties();
186
187 // add/set ModelID from current node to allow later association
188 if (mpCurrentNode)
189 mpShape->setDiagramDataModelID(mpCurrentNode->msModelId);
190}
191
193{
194 if (meLookFor == CONSTRAINT)
195 rAtom.parseConstraint(maConstraints, /*bRequireForName=*/true);
196}
197
199{
200 if (meLookFor == RULE)
201 rAtom.parseRule(maRules);
202}
203
205{
206 if (meLookFor == ALGORITHM)
207 {
209 = rAtom.getLayoutNode().getDiagram().getLayout()->getPresPointShapeMap();
210 auto pShape = aMap.find(mpCurrentNode);
211 if (pShape != aMap.end())
212 rAtom.layoutShape(pShape->second, maConstraints, maRules);
213 }
214}
215
217{
218 if (meLookFor != LAYOUT_NODE)
219 return;
220
221 // stop processing if it's not a child of previous LayoutNode
222
223 const DiagramData::PointsNameMap::const_iterator aDataNode
224 = mrDgm.getData()->getPointsPresNameMap().find(rAtom.getName());
225 if (aDataNode == mrDgm.getData()->getPointsPresNameMap().end()
226 || mnCurrIdx >= static_cast<sal_Int32>(aDataNode->second.size()))
227 return;
228
229 const svx::diagram::Point* pNewNode = aDataNode->second.at(mnCurrIdx);
230 if (!mpCurrentNode || !pNewNode)
231 return;
232
233 bool bIsChild = false;
234 for (const auto& aConnection : mrDgm.getData()->getConnections())
235 if (aConnection.msSourceId == mpCurrentNode->msModelId
236 && aConnection.msDestId == pNewNode->msModelId)
237 bIsChild = true;
238
239 if (!bIsChild)
240 return;
241
242 size_t nParentConstraintsNumber = maConstraints.size();
243
244 const svx::diagram::Point* pPreviousNode = mpCurrentNode;
245 mpCurrentNode = pNewNode;
246
247 // process alg atoms first, nested layout nodes afterwards
249 defaultVisit(rAtom);
250 meLookFor = RULE;
251 defaultVisit(rAtom);
253 defaultVisit(rAtom);
255 defaultVisit(rAtom);
256
257 mpCurrentNode = pPreviousNode;
258
259 // delete added constraints, keep parent constraints
260 maConstraints.erase(maConstraints.begin() + nParentConstraintsNumber, maConstraints.end());
261}
262
264{
265 // stop processing
266}
267}
268
269/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void layoutShape(const ShapePtr &rShape, const std::vector< Constraint > &rConstraints, const std::vector< Rule > &rRules)
sal_Int32 getVerticalShapesCount(const ShapePtr &rShape)
void parseConstraint(std::vector< Constraint > &rConstraints, bool bRequireForName) const
const OoxDiagramDataPtr & getData() const
const DiagramLayoutPtr & getLayout() const
enum oox::drawingml::LayoutAtomVisitorBase::@1 meLookFor
void defaultVisit(LayoutAtom const &rAtom)
const OUString & getName() const
const ShapePtr & getExistingShape() const
bool setupShape(const ShapePtr &rShape, const svx::diagram::Point *pPresNode, sal_Int32 nCurrIdx) const
void addNodeShape(const ShapePtr &pShape)
Represents one <dgm:rule> element.
void parseRule(std::vector< Rule > &rRules) const
const ShapePtr & getShapeTemplate() const
virtual void visit(ConstraintAtom &rAtom) override
virtual void visit(ConstraintAtom &rAtom) override
virtual void visit(ConstraintAtom &rAtom) override
#define SAL_WARN(area, stream)
#define SAL_INFO(area, stream)
std::shared_ptr< Shape > ShapePtr
std::map< const svx::diagram::Point *, ShapePtr > PresPointShapeMap
HashMap_OWString_Interface aMap