1 /** \file 2 * \brief Declares ClusterGraphCopyAttributes, which manages access 3 * on copy of an attributed clustered graph. 4 * 5 * \author Carsten Gutwenger 6 * 7 * \par License: 8 * This file is part of the Open Graph Drawing Framework (OGDF). 9 * 10 * \par 11 * Copyright (C)<br> 12 * See README.md in the OGDF root directory for details. 13 * 14 * \par 15 * This program is free software; you can redistribute it and/or 16 * modify it under the terms of the GNU General Public License 17 * Version 2 or 3 as published by the Free Software Foundation; 18 * see the file LICENSE.txt included in the packaging of this file 19 * for details. 20 * 21 * \par 22 * This program is distributed in the hope that it will be useful, 23 * but WITHOUT ANY WARRANTY; without even the implied warranty of 24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 25 * GNU General Public License for more details. 26 * 27 * \par 28 * You should have received a copy of the GNU General Public 29 * License along with this program; if not, see 30 * http://www.gnu.org/copyleft/gpl.html 31 */ 32 33 #pragma once 34 35 #include <ogdf/layered/ExtendedNestingGraph.h> 36 #include <ogdf/cluster/ClusterGraphAttributes.h> 37 38 39 namespace ogdf { 40 41 /** 42 * \brief Manages access on copy of an attributed clustered graph. 43 * 44 * @ingroup gd-helper 45 */ 46 class OGDF_EXPORT ClusterGraphCopyAttributes { 47 48 const ExtendedNestingGraph *m_pH; 49 ClusterGraphAttributes *m_pACG; 50 NodeArray<double> m_x, m_y; 51 52 public: 53 //! Initializes instance of class ClusterGraphCopyAttributes. ClusterGraphCopyAttributes(const ExtendedNestingGraph & H,ClusterGraphAttributes & ACG)54 ClusterGraphCopyAttributes( 55 const ExtendedNestingGraph &H, 56 ClusterGraphAttributes &ACG) : 57 m_pH(&H), m_pACG(&ACG), m_x(H,0), m_y(H,0) { } 58 ~ClusterGraphCopyAttributes()59 ~ClusterGraphCopyAttributes() { } 60 61 //! Returns corresponding ClusterGraphAttributes. getClusterGraphAttributes()62 const ClusterGraphAttributes &getClusterGraphAttributes() const { return *m_pACG; } 63 64 //! Returns width of node v. getWidth(node v)65 double getWidth(node v) const { 66 node vOrig = m_pH->origNode(v); 67 return (vOrig == nullptr) ? 0.0 : m_pACG->width(vOrig); 68 } 69 70 //! Returns height of node v. getHeight(node v)71 double getHeight(node v) const { 72 node vOrig = m_pH->origNode(v); 73 return (vOrig == nullptr) ? 0.0 : m_pACG->height(vOrig); 74 } 75 76 //! Returns reference to x-coord. of node v. x(node v)77 const double &x(node v) const { 78 return m_x[v]; 79 } 80 81 //! Returns reference to x-coord. of node v. x(node v)82 double &x(node v) { 83 return m_x[v]; 84 } 85 86 //! Returns reference to y-coord. of node v. y(node v)87 const double &y(node v) const { 88 return m_y[v]; 89 } 90 91 //! Returns reference to y-coord. of node v. y(node v)92 double &y(node v) { 93 return m_y[v]; 94 } 95 96 //! Returns coordinate of upper cluster boundary of original cluster \p cOrig. top(cluster cOrig)97 double top(cluster cOrig) const { 98 return m_pACG->y(cOrig); 99 } 100 //! Returns coordinate of lower cluster boundary of original cluster \p cOrig. bottom(cluster cOrig)101 double bottom(cluster cOrig) const { 102 return m_pACG->y(cOrig) + m_pACG->height(cOrig); 103 } 104 105 //! Sets the position of the cluster rectangle for original cluster \p cOrig. setClusterRect(cluster cOrig,double left,double right,double top,double bottom)106 void setClusterRect( 107 cluster cOrig, 108 double left, 109 double right, 110 double top, 111 double bottom) 112 { 113 m_pACG->x (cOrig) = left; 114 m_pACG->y (cOrig) = top; 115 m_pACG->width (cOrig) = right-left; 116 m_pACG->height(cOrig) = bottom-top; 117 } 118 setClusterLeftRight(cluster cOrig,double left,double right)119 void setClusterLeftRight( 120 cluster cOrig, 121 double left, 122 double right) 123 { 124 m_pACG->x (cOrig) = left; 125 m_pACG->width (cOrig) = right-left; 126 } 127 setClusterTopBottom(cluster cOrig,double top,double bottom)128 void setClusterTopBottom( 129 cluster cOrig, 130 double top, 131 double bottom) 132 { 133 m_pACG->y (cOrig) = top; 134 m_pACG->height(cOrig) = bottom-top; 135 } 136 137 //! Sets attributes for the original graph in attributed graph. 138 void transform(); 139 }; 140 141 } 142