TopologyVis.cc
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00023 #include <omnetpp.h>
00024
00025 #include <NodeHandle.h>
00026 #include <GlobalNodeList.h>
00027 #include <GlobalNodeListAccess.h>
00028 #include <PeerInfo.h>
00029
00030 #include "TopologyVis.h"
00031
00032
00033 TopologyVis::TopologyVis()
00034 {
00035 thisTerminal = NULL;
00036 globalNodeList = NULL;
00037 }
00038
00039 void TopologyVis::initVis(cModule* terminal)
00040 {
00041 thisTerminal = terminal;
00042 globalNodeList = GlobalNodeListAccess().get();
00043
00044
00045
00046
00047 thisTerminal->setGateSize("overlayNeighborArrowOut", 1);
00048 thisTerminal->setGateSize("overlayNeighborArrowIn", 1);
00049
00050 }
00051
00052 void TopologyVis::showOverlayNeighborArrow(const NodeHandle& neighbor,
00053 bool flush, const char* displayString)
00054 {
00055 if (!ev.isGUI() || !thisTerminal)
00056 return;
00057
00058 char red[] = "ls=red,1";
00059
00060 if (displayString == NULL)
00061 displayString = red;
00062
00063 cModule* neighborTerminal;
00064
00065
00066 if (flush) {
00067 for (int l = 0; l < thisTerminal->gateSize("overlayNeighborArrowOut"); l++) {
00068 cGate* tempGate =
00069 thisTerminal->gate("overlayNeighborArrowOut", l)->getNextGate();
00070
00071 thisTerminal->gate("overlayNeighborArrowOut", l)->disconnect();
00072 if (tempGate != NULL)
00073 compactGateArray(tempGate->getOwnerModule(), VIS_IN);
00074 }
00075 thisTerminal->setGateSize("overlayNeighborArrowOut" ,0);
00076 }
00077
00078 if (globalNodeList->getPeerInfo(neighbor) == NULL)
00079 return;
00080
00081 neighborTerminal = simulation.getModule(globalNodeList->
00082 getPeerInfo(neighbor)->getModuleID());
00083
00084 if (neighborTerminal == NULL)
00085 return;
00086
00087 if (thisTerminal == neighborTerminal)
00088 return;
00089
00090
00091 for (int i = 0; i < thisTerminal->gateSize("overlayNeighborArrowOut"); i++)
00092 if (thisTerminal->gate("overlayNeighborArrowOut", i)
00093 ->getNextGate() != NULL &&
00094 neighborTerminal == thisTerminal
00095 ->gate("overlayNeighborArrowOut", i)
00096 ->getNextGate()->getOwnerModule())
00097 return;
00098
00099
00100 int i = 0;
00101 if (neighborTerminal->gateSize("overlayNeighborArrowIn") == 0) {
00102 neighborTerminal->setGateSize("overlayNeighborArrowIn", 1);
00103 } else {
00104 for (i = 0; i < neighborTerminal->gateSize("overlayNeighborArrowIn") - 1; i++) {
00105 if (!(neighborTerminal->gate("overlayNeighborArrowIn", i)
00106 ->isConnectedOutside()))
00107 break;
00108 }
00109 if (neighborTerminal->gate("overlayNeighborArrowIn", i)
00110 ->isConnectedOutside()) {
00111 neighborTerminal->setGateSize("overlayNeighborArrowIn", i + 2);
00112 i++;
00113 }
00114 }
00115
00116
00117 int j = 0;
00118 if (thisTerminal->gateSize("overlayNeighborArrowOut") == 0)
00119 thisTerminal->setGateSize("overlayNeighborArrowOut", 1);
00120 else {
00121 for (j = 0; j < (thisTerminal->gateSize("overlayNeighborArrowOut") - 1); j++) {
00122 if (!(thisTerminal->gate("overlayNeighborArrowOut", j)
00123 ->isConnectedOutside()))
00124 break;
00125 }
00126 if (thisTerminal->gate("overlayNeighborArrowOut", j)
00127 ->isConnectedOutside()) {
00128 thisTerminal->setGateSize("overlayNeighborArrowOut", j + 2);
00129 j++;
00130 }
00131 }
00132
00133 thisTerminal->gate("overlayNeighborArrowOut", j)->connectTo(neighborTerminal->gate("overlayNeighborArrowIn", i));
00134
00135 thisTerminal->gate("overlayNeighborArrowOut", j)->setDisplayString(displayString);
00136 }
00137
00138 void TopologyVis::deleteOverlayNeighborArrow(const NodeHandle& neighbor)
00139 {
00140 if (!ev.isGUI() || !thisTerminal)
00141 return;
00142
00143 PeerInfo* peerInfo = globalNodeList->getPeerInfo(neighbor);
00144 if (peerInfo == NULL) {
00145 return;
00146 }
00147
00148 cModule* neighborTerminal = simulation.getModule(peerInfo->getModuleID());
00149 if (neighborTerminal == NULL) {
00150 return;
00151 }
00152
00153
00154 bool compactOut = false;
00155 bool compactIn = false;
00156 for (int i = 0; i < thisTerminal->gateSize("overlayNeighborArrowOut"); i++) {
00157
00158 if (thisTerminal->gate("overlayNeighborArrowOut", i)
00159 ->getNextGate() == NULL) {
00160 compactOut = true;
00161 continue;
00162 }
00163
00164 if (thisTerminal->gate("overlayNeighborArrowOut", i)
00165 ->getNextGate()->getOwnerModule()->getId() == neighborTerminal->getId()) {
00166 thisTerminal->gate("overlayNeighborArrowOut", i)->disconnect();
00167 compactOut = true;
00168 compactIn = true;
00169 }
00170 }
00171
00172
00173 if (compactOut)
00174 compactGateArray(thisTerminal, VIS_OUT);
00175
00176 if (compactIn)
00177 compactGateArray(neighborTerminal, VIS_IN);
00178 }
00179
00180 void TopologyVis::compactGateArray(cModule* terminal,
00181 enum VisDrawDirection dir)
00182 {
00183 const char* gateName = (dir == VIS_OUT ? "overlayNeighborArrowOut"
00184 : "overlayNeighborArrowIn");
00185
00186 for (int j = 0; j < terminal->gateSize(gateName) - 1; j++) {
00187 if (terminal->gate(gateName, j)->isConnectedOutside())
00188 continue;
00189
00190 cGate* tempGate = NULL;
00191 int k = 1;
00192 while ((tempGate == NULL) && ((j + k) != terminal->gateSize(gateName))) {
00193 tempGate = (dir == VIS_OUT ?
00194 terminal->gate(gateName, j + k)->getNextGate() :
00195 terminal->gate(gateName, j + k)->getPreviousGate());
00196 k++;
00197 }
00198
00199 if (tempGate == NULL)
00200 break;
00201
00202 cDisplayString tempDisplayStr;
00203 if (dir == VIS_OUT) {
00204 tempDisplayStr = terminal->gate(gateName, j + k - 1)->getDisplayString();
00205 terminal->gate(gateName, j + k - 1)->disconnect();
00206 terminal->gate(gateName, j)->connectTo(tempGate);
00207 terminal->gate(gateName, j)->setDisplayString(tempDisplayStr.str());
00208 } else {
00209 tempDisplayStr = tempGate->getDisplayString();
00210 tempGate->disconnect();
00211 tempGate->connectTo(terminal->gate(gateName, j));
00212 tempGate->setDisplayString(tempDisplayStr.str());
00213 }
00214 }
00215
00216 int nullGates = 0;
00217 for (int j = 0; j < terminal->gateSize(gateName); j++)
00218 if (!terminal->gate(gateName, j)->isConnectedOutside())
00219 nullGates++;
00220
00221 terminal->setGateSize(gateName, terminal->gateSize(gateName) - nullGates);
00222 }