INET Framework for OMNeT++/OMNEST
inet::visualizer::LineManager Class Reference

#include <LineManager.h>

Classes

class  CacheEntry
 
class  ModuleLine
 
class  ModulePath
 

Public Member Functions

void addModuleLine (const ModuleLine *moduleLine)
 
void removeModuleLine (const ModuleLine *moduleLine)
 
void addModulePath (const ModulePath *modulePath)
 
void removeModulePath (const ModulePath *modulePath)
 
Coord getLineShift (int sourceModuleId, int destinationModuleId, const Coord &sourcePosition, const Coord &destinationPosition, const char *shiftMode, int shiftOffset)
 

Static Public Member Functions

static LineManagergetLineManager (const cCanvas *canvas)
 

Protected Member Functions

std::pair< int, int > getKey (int fromModuleId, int toModuleId)
 
void updateOffsets (int fromModuleId, int toModuleId)
 
void updateOffsets (const ModuleLine *moduleLine)
 
void updateOffsets (const ModulePath *modulePath)
 

Static Protected Member Functions

static bool compareModuleLines (const ModuleLine *moduleLine1, const ModuleLine *moduleLine2)
 
static bool compareModulePaths (std::pair< const ModulePath *, int > element1, std::pair< const ModulePath *, int > element2)
 

Protected Attributes

std::map< std::pair< int, int >, CacheEntrycacheEntries
 

Static Protected Attributes

static std::map< const cCanvas *, LineManagerlineManagers
 

Member Function Documentation

void inet::visualizer::LineManager::addModuleLine ( const ModuleLine moduleLine)

Referenced by inet::visualizer::LinkCanvasVisualizerBase::addLinkVisualization(), and inet::visualizer::RoutingTableCanvasVisualizer::addRouteVisualization().

71 {
72  auto key = getKey(moduleLine->sourceModuleId, moduleLine->destinationModuleId);
73  auto& cacheEntry = cacheEntries[key];
74  cacheEntry.moduleLines.push_back(moduleLine);
75  updateOffsets(moduleLine);
76 }
std::map< std::pair< int, int >, CacheEntry > cacheEntries
Definition: LineManager.h:57
std::pair< int, int > getKey(int fromModuleId, int toModuleId)
Definition: LineManager.h:62
void updateOffsets(int fromModuleId, int toModuleId)
Definition: LineManager.cc:46
void inet::visualizer::LineManager::addModulePath ( const ModulePath modulePath)

Referenced by inet::visualizer::PathCanvasVisualizerBase::addPathVisualization().

87 {
88  for (int index = 1; index < modulePath->moduleIds.size(); index++) {
89  auto key = getKey(modulePath->moduleIds[index - 1], modulePath->moduleIds[index]);
90  auto value = std::pair<const ModulePath *, int>(modulePath, index - 1);
91  auto& cacheEntry = cacheEntries[key];
92  cacheEntry.modulePaths.push_back(value);
93  }
94  updateOffsets(modulePath);
95 }
std::map< std::pair< int, int >, CacheEntry > cacheEntries
Definition: LineManager.h:57
std::pair< int, int > getKey(int fromModuleId, int toModuleId)
Definition: LineManager.h:62
void updateOffsets(int fromModuleId, int toModuleId)
Definition: LineManager.cc:46
bool inet::visualizer::LineManager::compareModuleLines ( const ModuleLine moduleLine1,
const ModuleLine moduleLine2 
)
staticprotected

Referenced by updateOffsets().

33 {
34  auto v1 = moduleLine1->sourceModuleId < moduleLine1->destinationModuleId ? moduleLine1->shiftPriority : moduleLine1->shiftPriority;
35  auto v2 = moduleLine2->sourceModuleId < moduleLine2->destinationModuleId ? moduleLine2->shiftPriority : -moduleLine2->shiftPriority;
36  return v1 < v2;
37 }
bool inet::visualizer::LineManager::compareModulePaths ( std::pair< const ModulePath *, int >  element1,
std::pair< const ModulePath *, int >  element2 
)
staticprotected

Referenced by updateOffsets().

40 {
41  auto v1 = element1.first->moduleIds[element1.second] < element1.first->moduleIds[element1.second + 1] ? element1.first->shiftPriority : -element1.first->shiftPriority;
42  auto v2 = element2.first->moduleIds[element2.second] < element2.first->moduleIds[element2.second + 1] ? element2.first->shiftPriority : -element2.first->shiftPriority;
43  return v1 < v2;
44 }
std::pair<int, int> inet::visualizer::LineManager::getKey ( int  fromModuleId,
int  toModuleId 
)
inlineprotected

Referenced by addModuleLine(), addModulePath(), getLineShift(), removeModuleLine(), removeModulePath(), and updateOffsets().

62  {
63  return fromModuleId < toModuleId ? std::pair<int, int>(fromModuleId, toModuleId) : std::pair<int, int>(toModuleId, fromModuleId);
64  }
LineManager * inet::visualizer::LineManager::getLineManager ( const cCanvas *  canvas)
static

Referenced by inet::visualizer::RoutingTableVisualizerBase::initialize(), inet::visualizer::LinkVisualizerBase::initialize(), and inet::visualizer::PathVisualizerBase::initialize().

28 {
29  return &lineManagers[canvas];
30 }
static std::map< const cCanvas *, LineManager > lineManagers
Definition: LineManager.h:59
Coord inet::visualizer::LineManager::getLineShift ( int  sourceModuleId,
int  destinationModuleId,
const Coord sourcePosition,
const Coord destinationPosition,
const char *  shiftMode,
int  shiftOffset 
)

Referenced by inet::visualizer::LinkCanvasVisualizerBase::refreshDisplay(), inet::visualizer::RoutingTableCanvasVisualizer::refreshDisplay(), and inet::visualizer::PathCanvasVisualizerBase::refreshDisplay().

109 {
110  auto sign = *shiftMode;
111  if (sign == '+' || sign == '-')
112  shiftMode++;
113  Coord shift;
114  if (!strcmp("none", shiftMode))
115  return Coord::ZERO;
116  else if (!strcmp("normal", shiftMode)) {
117  auto direction = sourceModuleId < destinationModuleId ? destinationPosition - sourcePosition : sourcePosition - destinationPosition;
118  direction.normalize();
119  shift = Coord(-direction.y, direction.x, 0);
120  }
121  else if (!strcmp("x", shiftMode))
122  shift = Coord::X_AXIS;
123  else if (!strcmp("y", shiftMode))
124  shift = Coord::Y_AXIS;
125  else if (!strcmp("z", shiftMode))
126  shift = Coord::Z_AXIS;
127  else
128  throw cRuntimeError("Unknown shift mode: %s", shiftMode);
129  if (sign == '+')
130  shift *= shiftOffset;
131  else if (sign == '-')
132  shift *= -shiftOffset;
133  else {
134  auto& cacheEntry = cacheEntries[getKey(sourceModuleId, destinationModuleId)];
135  auto count = cacheEntry.moduleLines.size() + cacheEntry.modulePaths.size();
136  shift *= (double)shiftOffset - ((double)count - 1) / 2;
137  }
138  return shift;
139 }
static const Coord X_AXIS
Definition: Coord.h:42
int sign(double i)
Returns 1 if the parameter is greater or equal to zero, -1 otherwise.
Definition: INETMath.h:146
int count(const std::vector< T > &v, const T &a)
Definition: stlutils.h:58
static const Coord Y_AXIS
Definition: Coord.h:43
static const Coord Z_AXIS
Definition: Coord.h:44
std::map< std::pair< int, int >, CacheEntry > cacheEntries
Definition: LineManager.h:57
std::pair< int, int > getKey(int fromModuleId, int toModuleId)
Definition: LineManager.h:62
void normalize()
Updates the length of this position vector to be 1.
Definition: Coord.h:234
static const Coord ZERO
Definition: Coord.h:41
void inet::visualizer::LineManager::removeModuleLine ( const ModuleLine moduleLine)

Referenced by inet::visualizer::LinkCanvasVisualizerBase::removeLinkVisualization(), and inet::visualizer::RoutingTableCanvasVisualizer::removeRouteVisualization().

79 {
80  auto key = getKey(moduleLine->sourceModuleId, moduleLine->destinationModuleId);
81  auto& cacheEntry = cacheEntries[key];
82  cacheEntry.moduleLines.erase(std::remove(cacheEntry.moduleLines.begin(), cacheEntry.moduleLines.end(), moduleLine), cacheEntry.moduleLines.end());
83  updateOffsets(moduleLine);
84 }
void remove(std::vector< T > &v, const A &a)
Definition: stlutils.h:91
std::map< std::pair< int, int >, CacheEntry > cacheEntries
Definition: LineManager.h:57
std::pair< int, int > getKey(int fromModuleId, int toModuleId)
Definition: LineManager.h:62
void updateOffsets(int fromModuleId, int toModuleId)
Definition: LineManager.cc:46
void inet::visualizer::LineManager::removeModulePath ( const ModulePath modulePath)

Referenced by inet::visualizer::PathCanvasVisualizerBase::removePathVisualization().

98 {
99  for (int index = 1; index < modulePath->moduleIds.size(); index++) {
100  auto key = getKey(modulePath->moduleIds[index - 1], modulePath->moduleIds[index]);
101  auto value = std::pair<const ModulePath *, int>(modulePath, index - 1);
102  auto& cacheEntry = cacheEntries[key];
103  cacheEntry.modulePaths.erase(std::remove(cacheEntry.modulePaths.begin(), cacheEntry.modulePaths.end(), value), cacheEntry.modulePaths.end());
104  }
105  updateOffsets(modulePath);
106 }
void remove(std::vector< T > &v, const A &a)
Definition: stlutils.h:91
std::map< std::pair< int, int >, CacheEntry > cacheEntries
Definition: LineManager.h:57
std::pair< int, int > getKey(int fromModuleId, int toModuleId)
Definition: LineManager.h:62
void updateOffsets(int fromModuleId, int toModuleId)
Definition: LineManager.cc:46
void inet::visualizer::LineManager::updateOffsets ( int  fromModuleId,
int  toModuleId 
)
protected

Referenced by addModuleLine(), addModulePath(), removeModuleLine(), removeModulePath(), and updateOffsets().

47 {
48  auto key = getKey(fromModuleId, toModuleId);
49  auto& cacheEntry = cacheEntries[key];
50  std::sort(cacheEntry.moduleLines.begin(), cacheEntry.moduleLines.end(), compareModuleLines);
51  std::sort(cacheEntry.modulePaths.begin(), cacheEntry.modulePaths.end(), compareModulePaths);
52  int shiftOffset = 0;
53  for (auto& moduleLine : cacheEntry.moduleLines)
54  moduleLine->shiftOffset = shiftOffset++;
55  for (auto& element : cacheEntry.modulePaths)
56  element.first->shiftOffsets[element.second] = shiftOffset++;
57 }
static bool compareModuleLines(const ModuleLine *moduleLine1, const ModuleLine *moduleLine2)
Definition: LineManager.cc:32
static bool compareModulePaths(std::pair< const ModulePath *, int > element1, std::pair< const ModulePath *, int > element2)
Definition: LineManager.cc:39
std::map< std::pair< int, int >, CacheEntry > cacheEntries
Definition: LineManager.h:57
std::pair< int, int > getKey(int fromModuleId, int toModuleId)
Definition: LineManager.h:62
void sort(std::vector< T > &v)
Definition: stlutils.h:112
void inet::visualizer::LineManager::updateOffsets ( const ModuleLine moduleLine)
protected
60 {
61  updateOffsets(moduleLine->sourceModuleId, moduleLine->destinationModuleId);
62 }
void updateOffsets(int fromModuleId, int toModuleId)
Definition: LineManager.cc:46
void inet::visualizer::LineManager::updateOffsets ( const ModulePath modulePath)
protected
65 {
66  for (int index = 1; index < modulePath->moduleIds.size(); index++)
67  updateOffsets(modulePath->moduleIds[index - 1], modulePath->moduleIds[index]);
68 }
void updateOffsets(int fromModuleId, int toModuleId)
Definition: LineManager.cc:46

Member Data Documentation

std::map<std::pair<int, int>, CacheEntry> inet::visualizer::LineManager::cacheEntries
protected
std::map< const cCanvas *, LineManager > inet::visualizer::LineManager::lineManagers
staticprotected

Referenced by getLineManager().


The documentation for this class was generated from the following files: