1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 #include "layoutatomvisitorbase.hxx"
22 #include <sal/log.hxx>
24 using namespace ::com::sun::star
;
25 using namespace ::com::sun::star::uno
;
27 namespace oox
{ namespace drawingml
{
29 void LayoutAtomVisitorBase::defaultVisit(LayoutAtom
const& rAtom
)
31 for (const auto& pAtom
: rAtom
.getChildren())
35 void LayoutAtomVisitorBase::visit(ChooseAtom
& rAtom
)
37 for (const auto& pChild
: rAtom
.getChildren())
39 const ConditionAtomPtr pCond
= std::dynamic_pointer_cast
<ConditionAtom
>(pChild
);
40 if (pCond
&& pCond
->getDecision(mpCurrentNode
))
42 SAL_INFO("oox.drawingml", "Entering if node: " << pCond
->getName());
49 void LayoutAtomVisitorBase::visit(ConditionAtom
& rAtom
)
54 void LayoutAtomVisitorBase::visit(ForEachAtom
& rAtom
)
56 if (!rAtom
.getRef().isEmpty())
58 if (LayoutAtomPtr pRefAtom
= rAtom
.getRefAtom())
59 pRefAtom
->accept(*this);
63 if (rAtom
.iterator().mbHideLastTrans
&& !rAtom
.iterator().maAxis
.empty() && rAtom
.iterator().maAxis
[0] == XML_followSib
)
65 // If last transition is hidden and the axis is the follow sibling,
66 // then the last atom should not be visited.
67 if (mnCurrIdx
+ mnCurrStep
>= mnCurrCnt
)
71 sal_Int32 nChildren
= 1;
72 // Approximate the non-assistant type with the node type.
73 if (rAtom
.iterator().mnPtType
== XML_node
|| rAtom
.iterator().mnPtType
== XML_nonAsst
)
75 // count child data nodes - check all child Atoms for "name"
76 // attribute that is contained in diagram's
77 // getPointsPresNameMap()
78 ShallowPresNameVisitor
aVisitor(mrDgm
, mpCurrentNode
);
79 for (const auto& pAtom
: rAtom
.getChildren())
80 pAtom
->accept(aVisitor
);
81 nChildren
= aVisitor
.getCount();
84 const sal_Int32 nCnt
= std::min(
86 rAtom
.iterator().mnCnt
==-1 ? nChildren
: rAtom
.iterator().mnCnt
);
88 const sal_Int32 nOldIdx
= mnCurrIdx
;
89 const sal_Int32 nOldStep
= mnCurrStep
;
90 const sal_Int32 nOldCnt
= mnCurrCnt
;
91 const sal_Int32 nStep
= rAtom
.iterator().mnStep
;
94 for( mnCurrIdx
=0; mnCurrIdx
<nCnt
&& nStep
>0; mnCurrIdx
+=nStep
)
96 // TODO there is likely some conditions
97 for (const auto& pAtom
: rAtom
.getChildren())
103 mnCurrStep
= nOldStep
;
107 void LayoutAtomVisitorBase::visit(LayoutNode
& rAtom
)
109 // TODO: deduplicate code in descendants
111 // stop processing if it's not a child of previous LayoutNode
113 const DiagramData::PointsNameMap::const_iterator aDataNode
114 = mrDgm
.getData()->getPointsPresNameMap().find(rAtom
.getName());
115 if (aDataNode
== mrDgm
.getData()->getPointsPresNameMap().end()
116 || mnCurrIdx
>= static_cast<sal_Int32
>(aDataNode
->second
.size()))
119 const dgm::Point
* pNewNode
= aDataNode
->second
.at(mnCurrIdx
);
120 if (!mpCurrentNode
|| !pNewNode
)
123 bool bIsChild
= false;
124 for (const auto& aConnection
: mrDgm
.getData()->getConnections())
125 if (aConnection
.msSourceId
== mpCurrentNode
->msModelId
126 && aConnection
.msDestId
== pNewNode
->msModelId
)
132 const dgm::Point
* pPreviousNode
= mpCurrentNode
;
133 mpCurrentNode
= pNewNode
;
137 mpCurrentNode
= pPreviousNode
;
140 void ShallowPresNameVisitor::visit(ConstraintAtom
& /*rAtom*/)
145 void ShallowPresNameVisitor::visit(AlgAtom
& /*rAtom*/)
150 void ShallowPresNameVisitor::visit(ForEachAtom
& rAtom
)
155 void ShallowPresNameVisitor::visit(LayoutNode
& rAtom
)
157 DiagramData::PointsNameMap::const_iterator aDataNode
=
158 mrDgm
.getData()->getPointsPresNameMap().find(rAtom
.getName());
159 if( aDataNode
!= mrDgm
.getData()->getPointsPresNameMap().end() )
160 mnCnt
= std::max(mnCnt
,
161 aDataNode
->second
.size());
164 void ShallowPresNameVisitor::visit(ShapeAtom
& /*rAtom*/)
171 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */