LibreOffice Module svx (master) 1
clonelist.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
20
21// #i13033#
22// New mechanism to hold a list of all original and cloned objects for later
23// re-creating the connections for contained connectors
24#include <clonelist.hxx>
25#include <svx/svdoedge.hxx>
26#include <svx/scene3d.hxx>
27
28void CloneList::AddPair(const SdrObject* pOriginal, SdrObject* pClone)
29{
30 maOriginalList.push_back(pOriginal);
31 maCloneList.push_back(pClone);
32
33 // look for subobjects, too.
34 bool bOriginalIsGroup(pOriginal->IsGroupObject());
35 bool bCloneIsGroup(pClone->IsGroupObject());
36
37 if(bOriginalIsGroup && DynCastE3dObject(pOriginal) != nullptr && DynCastE3dScene(pOriginal) == nullptr )
38 bOriginalIsGroup = false;
39
40 if(bCloneIsGroup && DynCastE3dObject(pClone) != nullptr && DynCastE3dScene(pClone) == nullptr)
41 bCloneIsGroup = false;
42
43 if(!(bOriginalIsGroup && bCloneIsGroup))
44 return;
45
46 const SdrObjList* pOriginalList = pOriginal->GetSubList();
47 SdrObjList* pCloneList = pClone->GetSubList();
48
49 if(pOriginalList && pCloneList
50 && pOriginalList->GetObjCount() == pCloneList->GetObjCount())
51 {
52 for(size_t a = 0; a < pOriginalList->GetObjCount(); ++a)
53 {
54 // recursive call
55 AddPair(pOriginalList->GetObj(a), pCloneList->GetObj(a));
56 }
57 }
58}
59
60const SdrObject* CloneList::GetOriginal(sal_uInt32 nIndex) const
61{
62 return maOriginalList[nIndex];
63}
64
65SdrObject* CloneList::GetClone(sal_uInt32 nIndex) const
66{
67 return maCloneList[nIndex];
68}
69
71{
72 sal_uInt32 cloneCount = maCloneList.size();
73
74 for(size_t a = 0; a < maOriginalList.size(); a++)
75 {
76 const SdrEdgeObj* pOriginalEdge = dynamic_cast<const SdrEdgeObj*>( GetOriginal(a) );
77 SdrEdgeObj* pCloneEdge = dynamic_cast<SdrEdgeObj*>( GetClone(a) );
78
79 if(pOriginalEdge && pCloneEdge)
80 {
81 for (bool bTail1 : { true, false })
82 {
83 SdrObject* pOriginalNode = pOriginalEdge->GetConnectedNode(bTail1);
84 if (pOriginalNode)
85 {
86 std::vector<const SdrObject*>::const_iterator it = std::find(maOriginalList.begin(),
87 maOriginalList.end(),
88 pOriginalNode);
89
90 if(it != maOriginalList.end())
91 {
92 sal_uInt32 nPos = it - maOriginalList.begin();
93 SdrObject *cObj = nullptr;
94
95 if (nPos < cloneCount)
96 cObj = GetClone(nPos);
97
98 if(pOriginalNode != cObj)
99 pCloneEdge->ConnectToNode(bTail1, cObj);
100 }
101 }
102 }
103 }
104 }
105}
106
107/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SdrObject * GetClone(sal_uInt32 nIndex) const
Definition: clonelist.cxx:65
std::vector< SdrObject * > maCloneList
Definition: clonelist.hxx:34
void AddPair(const SdrObject *pOriginal, SdrObject *pClone)
Definition: clonelist.cxx:28
std::vector< const SdrObject * > maOriginalList
Definition: clonelist.hxx:33
const SdrObject * GetOriginal(sal_uInt32 nIndex) const
Definition: clonelist.cxx:60
void CopyConnections() const
Definition: clonelist.cxx:70
Utility class SdrEdgeObj.
Definition: svdoedge.hxx:130
void ConnectToNode(bool bTail1, SdrObject *pObj) override
Definition: svdoedge.cxx:471
SdrObject * GetConnectedNode(bool bTail1) const override
Definition: svdoedge.cxx:495
SdrObject * GetObj(size_t nNum) const
Definition: svdpage.cxx:785
size_t GetObjCount() const
Definition: svdpage.cxx:779
Abstract DrawObject.
Definition: svdobj.hxx:260
virtual SdrObjList * GetSubList() const
Definition: svdobj.cxx:717
bool IsGroupObject() const
Definition: svdobj.cxx:712
sal_Int32 nIndex
uno_Any a
sal_uInt16 nPos
E3dObject * DynCastE3dObject(SdrObject *pObj)
Definition: svdobj.cxx:3205
E3dScene * DynCastE3dScene(SdrObject *pObj)
Definition: svdobj.cxx:3198