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 && dynamic_cast<const E3dObject* >(pOriginal) != nullptr && dynamic_cast<const E3dScene* >(pOriginal) == nullptr )
38 bOriginalIsGroup = false;
39
40 if(bCloneIsGroup && dynamic_cast<const E3dObject* >(pClone) != nullptr && dynamic_cast<const E3dScene* >(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 SdrObject* pOriginalNode1 = pOriginalEdge->GetConnectedNode(true);
82 SdrObject* pOriginalNode2 = pOriginalEdge->GetConnectedNode(false);
83
84 if(pOriginalNode1)
85 {
86 std::vector<const SdrObject*>::const_iterator it = std::find(maOriginalList.begin(),
87 maOriginalList.end(),
88 pOriginalNode1);
89
90 sal_uInt32 nPos = it - maOriginalList.begin();
91
92 if(it != maOriginalList.end())
93 {
94 SdrObject *cObj = nullptr;
95
96 if (nPos < cloneCount)
97 cObj = GetClone(nPos);
98
99 if(pOriginalEdge->GetConnectedNode(true) != cObj)
100 pCloneEdge->ConnectToNode(true, cObj);
101 }
102 }
103
104 if(pOriginalNode2)
105 {
106 std::vector<const SdrObject*>::const_iterator it = std::find(maOriginalList.begin(),
107 maOriginalList.end(),
108 pOriginalNode2);
109
110 sal_uInt32 nPos = it - maOriginalList.begin();
111
112 if(it != maOriginalList.end())
113 {
114 SdrObject *cObj = nullptr;
115
116 if (nPos < cloneCount)
117 cObj = GetClone(nPos);
118
119 if(pOriginalEdge->GetConnectedNode(false) != cObj)
120 pCloneEdge->ConnectToNode(false, cObj);
121 }
122 }
123 }
124 }
125}
126
127/* 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:470
SdrObject * GetConnectedNode(bool bTail1) const override
Definition: svdoedge.cxx:494
SdrObject * GetObj(size_t nNum) const
Definition: svdpage.cxx:805
size_t GetObjCount() const
Definition: svdpage.cxx:799
Abstract DrawObject.
Definition: svdobj.hxx:261
virtual SdrObjList * GetSubList() const
Definition: svdobj.cxx:743
bool IsGroupObject() const
Definition: svdobj.cxx:738
sal_Int32 nIndex
uno_Any a
sal_uInt16 nPos