1 /** \file 2 * \brief Declaration of interfaces used in Sugiyama framework. 3 * 4 * \author Carsten Gutwenger, Paweł Schmidt 5 * 6 * \par License: 7 * This file is part of the Open Graph Drawing Framework (OGDF). 8 * 9 * \par 10 * Copyright (C)<br> 11 * See README.md in the OGDF root directory for details. 12 * 13 * \par 14 * This program is free software; you can redistribute it and/or 15 * modify it under the terms of the GNU General Public License 16 * Version 2 or 3 as published by the Free Software Foundation; 17 * see the file LICENSE.txt included in the packaging of this file 18 * for details. 19 * 20 * \par 21 * This program is distributed in the hope that it will be useful, 22 * but WITHOUT ANY WARRANTY; without even the implied warranty of 23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 * GNU General Public License for more details. 25 * 26 * \par 27 * You should have received a copy of the GNU General Public 28 * License along with this program; if not, see 29 * http://www.gnu.org/copyleft/gpl.html 30 */ 31 32 #pragma once 33 34 #include <ogdf/basic/Graph.h> 35 #include <ogdf/layered/Hierarchy.h> 36 37 38 namespace ogdf { 39 40 //! Representation of levels in hierarchies. 41 /** 42 * \see Hierarchy, SugiyamaLayout 43 */ 44 class LevelBase 45 { 46 public: 47 // destruction ~LevelBase()48 virtual ~LevelBase() { } 49 50 //! Returns the node at position \p i. 51 virtual const node &operator[](int i) const = 0; 52 53 //! Returns the node at position \p i. 54 virtual node &operator[](int i) = 0; 55 56 //! Returns the number of nodes on this level. 57 virtual int size() const = 0; 58 59 //! Returns the maximal array index (= size()-1). 60 virtual int high() const = 0; 61 }; 62 63 64 65 class OGDF_EXPORT HierarchyLevelsBase { 66 67 public: 68 HierarchyLevelsBase() = default; 69 70 HierarchyLevelsBase(const HierarchyLevelsBase&) = default; 71 HierarchyLevelsBase& operator=(const HierarchyLevelsBase&) = default; 72 73 // destruction ~HierarchyLevelsBase()74 virtual ~HierarchyLevelsBase() { } 75 76 enum class TraversingDir { downward, upward }; 77 78 //! Returns the <i>i</i>-th level. 79 virtual const LevelBase &operator[](int i) const = 0; 80 81 //! Returns the position of node \p v on its level. 82 virtual int pos(node v) const = 0; 83 84 //! Returns the number of levels. 85 virtual int size() const = 0; 86 87 //! Returns the maximal array index of a level (= size()-1). high()88 virtual int high() const { return size() - 1; } 89 90 virtual const Hierarchy &hierarchy() const = 0; 91 92 //! Returns the adjacent nodes of \p v. 93 virtual const Array<node> &adjNodes(node v, TraversingDir dir) const = 0; 94 95 //! Computes the number of crossings between level \p i and \p i+1. 96 int calculateCrossings(int i) const; 97 98 //! Computes the total number of crossings. 99 int calculateCrossings() const; 100 }; 101 102 } 103