1 /** \file 2 * \brief Declaration of interface hierarchy layout algorithms 3 * (3. phase of Sugiyama). 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/Hierarchy.h> 36 #include <ogdf/basic/GraphAttributes.h> 37 #include <ogdf/layered/CrossingMinInterfaces.h> 38 39 namespace ogdf { 40 41 42 /** 43 * \brief Interface of hierarchy layout algorithms. 44 * 45 * \see SugiyamaLayout 46 */ 47 class OGDF_EXPORT HierarchyLayoutModule { 48 public: 49 //! Initializes a hierarchy layout module. HierarchyLayoutModule()50 HierarchyLayoutModule() { } 51 ~HierarchyLayoutModule()52 virtual ~HierarchyLayoutModule() { } 53 54 /** 55 * \brief Computes a hierarchy layout of \p levels in \p GA 56 * @param levels is the input hierarchy. 57 * @param GA is assigned the hierarchy layout. 58 */ call(const HierarchyLevelsBase & levels,GraphAttributes & GA)59 void call(const HierarchyLevelsBase &levels, GraphAttributes &GA) { 60 GraphAttributes AGC(levels.hierarchy()); 61 doCall(levels,AGC); 62 AGC.transferToOriginal(GA); 63 } 64 65 #if 0 66 /** 67 *\brief Computes a hierarchy layout of \p H in \p AG. 68 * @param H is the input hierarchy. 69 * @param AG is assigned the hierarchy layout. 70 */ 71 void call(Hierarchy& H, GraphAttributes &AG) { 72 GraphAttributes AGC(H); 73 doCall(H,AGC); 74 HierarchyLayoutModule::dynLayerDistance(AGC, H); 75 HierarchyLayoutModule::addBends(AGC, H); 76 AGC.transferToOriginal(AG); 77 } 78 79 /** 80 * \brief Computes a hierarchy layout of \p H in \p AG. 81 * @param H is the input hierarchy. 82 * @param AG is assigned the hierarchy layout. 83 * @param AGC is GraphAttributes init. with H and AG 84 */ 85 void call(const Hierarchy& H, GraphAttributes &, GraphAttributes &AGC) { 86 doCall(H,AGC); 87 } 88 89 //! Adds bends to edges for avoiding crossings with nodes. 90 static void addBends(GraphAttributes &AGC, HierarchyLevels &levels); 91 #endif 92 93 static void dynLayerDistance(GraphAttributes &AGC, HierarchyLevelsBase &levels); 94 95 private: 96 97 //! after calling, ci (cj) contains the number of nodes of level i (j=i-1) which overlap the edge (s,t) 98 static void overlap(GraphAttributes &AGC, HierarchyLevelsBase &levels, node s, node t, int i, int &ci, int &cj); 99 100 protected: 101 //! Returns the \p GA width of node \p v or 0 if it is a dummy node in the hierarchy of \p levels. getWidth(const GraphAttributes & GA,const HierarchyLevelsBase & levels,node v)102 static inline double getWidth(const GraphAttributes &GA, const HierarchyLevelsBase &levels, node v) { 103 const GraphCopy &GC = levels.hierarchy(); 104 return GC.isDummy(v) ? 0.0 : GA.width(v); 105 } 106 107 //! Returns the \p GA height of node \p v or 0 if it is a dummy node in the hierarchy of \p levels. getHeight(const GraphAttributes & GA,const HierarchyLevelsBase & levels,node v)108 static inline double getHeight(const GraphAttributes &GA, const HierarchyLevelsBase &levels, node v) { 109 const GraphCopy &GC = levels.hierarchy(); 110 return GC.isDummy(v) ? 0.0 : GA.height(v); 111 } 112 113 /** 114 * \brief Implements the actual algorithm call. 115 * 116 * Must be implemented by derived classes. 117 * 118 * @param levels is the input hierarchy. 119 * @param AGC has to be assigned the hierarchy layout. 120 */ 121 virtual void doCall(const HierarchyLevelsBase &levels, GraphAttributes &AGC) = 0; 122 123 OGDF_MALLOC_NEW_DELETE 124 125 }; 126 127 } 128