1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305
|
/*
* $Revision: 2564 $
*
* last checkin:
* $Author: gutwenger $
* $Date: 2012-07-07 00:03:48 +0200 (Sa, 07. Jul 2012) $
***************************************************************/
/** \file
* \brief Provide an interface for edge label information
*
* \author Karsten Klein
*
* \par License:
* This file is part of the Open Graph Drawing Framework (OGDF).
*
* \par
* Copyright (C)<br>
* See README.txt in the root directory of the OGDF installation for details.
*
* \par
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* Version 2 or 3 as published by the Free Software Foundation;
* see the file LICENSE.txt included in the packaging of this file
* for details.
*
* \par
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* \par
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
* \see http://www.gnu.org/copyleft/gpl.html
***************************************************************/
#ifdef _MSC_VER
#pragma once
#endif
#ifndef OGDF_E_LABEL_INTERFACE_H
#define OGDF_E_LABEL_INTERFACE_H
#include <ogdf/orthogonal/OrthoLayout.h>
#include <ogdf/basic/GridLayout.h>
#include <ogdf/basic/GridLayoutMapped.h>
#include <ogdf/planarity/PlanRepUML.h>
namespace ogdf {
//********************************************************
// the available labels
// the five basic labels are not allowed to be changed,
// cause they have a special meaning/position, insert
// other labels between mult1/End2
enum eLabelType {
elEnd1 = 0,
elMult1,
elName,
elEnd2,
elMult2,
elNumLabels //!< the number of available labels at an edge
};
enum eUsedLabels {
lEnd1 = (1 << elEnd1), // 1
lMult1 = (1 << elMult1), // 2
lName = (1 << elName), // 4
lEnd2 = (1 << elEnd2), // 8
lMult2 = (1 << elMult2), // 16
lAll = (1 << elNumLabels) -1, // 31
};
//*************************************
// the basic single label defining class
// holds info about all labels for one edge
template <class coordType>
class OGDF_EXPORT EdgeLabel
{
public:
//construction and destruction
EdgeLabel() { m_edge = 0; m_usedLabels = 0; }
//bit pattern 2^labelenumpos bitwise
EdgeLabel(edge e, int usedLabels = lAll) : m_usedLabels(usedLabels), m_edge(e)
{
for(int i = 0; i < elNumLabels; i++)
{
//zu testzwecken randoms
m_xSize[i] = double(randomNumber(5,13))/50.0; //1
m_ySize[i] = double(randomNumber(3,7))/50.0; //1
m_xPos[i] = 0;
m_yPos[i] = 0;
}
}
// Construction with specification of label sizes in arrays of length labelnum
EdgeLabel(edge e, coordType w[], coordType h[], int usedLabels = lAll) : m_usedLabels(usedLabels), m_edge(e)
{
for(int i = 0; i < elNumLabels; i++)
{
m_xSize[i] = w[i];
m_ySize[i] = h[i];
m_xPos[i] = 0;
m_yPos[i] = 0;
}
}
EdgeLabel(edge e, coordType w, coordType h, int usedLabels) : m_usedLabels(usedLabels), m_edge(e)
{
for (int i = 0; i < elNumLabels; i++)
if (m_usedLabels & (1 << i)) {
m_xPos[i] = 0.0;
m_yPos[i] = 0.0;
m_xSize[i] = w;
m_ySize[i] = h;
}
}
//copy constructor
EdgeLabel(const EdgeLabel& rhs) : m_usedLabels(rhs.m_usedLabels), m_edge(rhs.m_edge)
{
for(int i = 0; i < elNumLabels; i++)
{
m_xPos[i] = rhs.m_xPos[i];
m_yPos[i] = rhs.m_yPos[i];
m_xSize[i] = rhs.m_xSize[i];
m_ySize[i] = rhs.m_ySize[i];
}
}//copy con
~EdgeLabel() { }
//assignment
EdgeLabel& operator=(const EdgeLabel& rhs)
{
if (this != &rhs)
{
m_usedLabels = rhs.m_usedLabels;
m_edge = rhs.m_edge;
int i;
for(i = 0; i < elNumLabels; i++)
{
m_xPos[i] = rhs.m_xPos[i];
m_yPos[i] = rhs.m_yPos[i];
m_xSize[i] = rhs.m_xSize[i];
m_ySize[i] = rhs.m_ySize[i];
}
}
return *this;
}//assignment
EdgeLabel& operator|=(const EdgeLabel& rhs)
{
if (m_edge) {
OGDF_ASSERT(m_edge == rhs.m_edge);
}
else
m_edge = rhs.m_edge;
if (this != &rhs)
{
m_usedLabels |= rhs.m_usedLabels;
for (int i = 0; i < elNumLabels; i++)
if (rhs.m_usedLabels & (1 << i)) {
m_xPos[i] = rhs.m_xPos[i];
m_yPos[i] = rhs.m_yPos[i];
m_xSize[i] = rhs.m_xSize[i];
m_ySize[i] = rhs.m_ySize[i];
}
}
return *this;
}
//set
void setX(eLabelType elt, coordType x) { m_xPos[elt] = x; }
void setY(eLabelType elt, coordType y) { m_yPos[elt] = y; }
void setHeight(eLabelType elt, coordType h) { m_ySize[elt] = h; }
void setWidth(eLabelType elt, coordType w) { m_xSize[elt] = w; }
void setEdge(edge e) { m_edge = e; }
void addType(eLabelType elt) { m_usedLabels |= (1<<elt); }
//get
coordType getX(eLabelType elt) const { return m_xPos[elt]; }
coordType getY(eLabelType elt) const { return m_yPos[elt]; }
coordType getWidth(eLabelType elt) const { return m_xSize[elt]; }
coordType getHeight(eLabelType elt) const { return m_ySize[elt]; }
edge theEdge() const { return m_edge; }
bool usedLabel(eLabelType elt) const {
return ( ( m_usedLabels & (1 << elt) ) > 0 );
}
int &usedLabel() { return m_usedLabels; }
private:
//the positions of the labels
coordType m_xPos[elNumLabels];
coordType m_yPos[elNumLabels];
//the input label sizes
coordType m_xSize[elNumLabels];
coordType m_ySize[elNumLabels];
//which labels have to be placed bit pattern 2^labelenumpos bitwise
int m_usedLabels; //1 = only name, 5 = name and end2, ...
//the edge of heaven
edge m_edge;
//the label text
//String m_string;
};//edgelabel
//*********************
//Interface to algorithm
template <class coordType>
class ELabelInterface
{
public:
//constructor
ELabelInterface(PlanRepUML& pru)
{
//the PRU should not work with real world data but with
//normalized integer values
m_distDefault = 2;
m_minFeatDist = 1;
m_labels.init(pru.original());
m_ug = 0;
//temporary
edge e;
forall_edges(e, pru.original())
setLabel(e, EdgeLabel<coordType>(e, 0));
}
//constructor on GraphAttributes
ELabelInterface(GraphAttributes& uml) : m_ug(¨)
{
//the GraphAttributes should work on real world data,
//which can be floats or ints
m_distDefault = 0.002;
m_minFeatDist = 0.003;
m_labels.init(uml.constGraph());
//temporary
edge e;
forall_edges(e, uml.constGraph())
setLabel(e, EdgeLabel<coordType>(e, 0));
}
GraphAttributes& graph() { return *m_ug; }
//set new EdgeLabel
void setLabel(const edge &e, const EdgeLabel<coordType>& el) {
m_labels[e] = el;
}
void addLabel(const edge &e, const EdgeLabel<coordType>& el) {
m_labels[e] |= el;
}
//get info about current EdgeLabel
EdgeLabel<coordType>& getLabel(edge e) { return m_labels[e]; }
coordType getWidth(edge e, eLabelType elt) {
return m_labels[e].getWidth(elt);
}
coordType getHeight(edge e, eLabelType elt) {
return m_labels[e].getHeight(elt);
}
//get general information
coordType& minFeatDist() { return m_minFeatDist; }
coordType& distDefault() { return m_distDefault; }
private:
EdgeArray<EdgeLabel<coordType> > m_labels; //holds all labels for original edges
//the base graph
GraphAttributes* m_ug;
coordType m_distDefault; //default distance label/edge for positioner
coordType m_minFeatDist; //min Distance label/feature in candidate posit.
};//ELabelInterface
}//end namespace
#endif
|