📄 node.cc
字号:
return ((x_-x) * (x_-x) + (y_-y) * (y_-y));}void Node::size(double s){ size_ = s; update_bb();}// We don't need one update_bb() for every derived class because their// sizes are all based on 0.5*size_. Otherwise we'll have to do update_bb// individuallyvoid Node::update_bb(){ double off = 0.5 * size_ + NodeMarkScale * size_; // thick circles if (nMark_ > 0) off += nMark_ * NodeMarkScale * size_; /*XXX*/ bb_.xmin = x_ - off; bb_.ymin = y_ - off; bb_.xmax = x_ + off; bb_.ymax = y_ + off;}const char* Node::info() const{ static char text[128]; sprintf(text, "Node: %s (%g, %g)", label_, x(), y()); return (text);}//----------------------------------------------------------------------// const char * // Node::property()// - returns a string of property types and values for the node // object//----------------------------------------------------------------------const char * Node::property() { static char text[256]; char *p; rgb * color; color = Paint::instance()->paint_to_rgb(paint_); // object type and id p = text; sprintf(text, "{\"Node: %d\" nn_ title \"Node %d\"} ", nn_, nn_); // node size p = &text[strlen(text)]; sprintf(p, "{Size size_ text %.1f} ", size_); // node color p = &text[strlen(text)]; sprintf(p, "{Color color color %s} ", color->colorname); // label if it exists p = &text[strlen(text)]; if (dlabel_) { sprintf(p, "{Label dlabel_ text %s} ", dlabel_); } else { sprintf(p, "{Label dlabel_ text } "); } if (movement_list.head()) { } return(text);}const char* Node::getname() const{ static char text[128]; sprintf(text, "n %s", label_); return (text);}void Node::monitor(Monitor *m, double /*now*/, char *result, int /*len*/){ monitor_=m; sprintf(result, "Node: %s", label_); return;}void Node::add_link(Edge* e){ movement_list.clear(); e->next_ = links_; links_ = e;}void Node::delete_link(Edge* e) { Edge *h, *k; h = links_; for (k = links_; k != 0; k = k->next_) { if (k->src() == e->src() && k->dst() == e->dst()) { if (k == links_) { links_ = k->next_; break; } else { h->next_ = k->next_; break; } } h = k; } }void Node::add_agent(Agent* a){ a->next_ = agents_; agents_ = a;}void Node::delete_agent(Agent* r){ /*given a agent, remove it from a node's agent list*/ Agent *ta1, *ta2; ta1=agents_; ta2=agents_; while ((ta1!=r)&&(ta1!=NULL)) { ta2=ta1; ta1=ta1->next(); } if (ta1==r) { ta2->next(ta1->next()); if (ta1==agents_) agents_=ta1->next(); }}Agent *Node::find_agent(char *name) const{ Agent *ta=NULL; ta=agents_; while (ta!=NULL) { if (strcmp(ta->name(), name)==0) return ta; ta=ta->next(); } return NULL;}void Node::add_route(Route* r){ r->next_ = routes_; routes_ = r;}void Node::delete_route(Route* r){ /*given a route, remove it from a node's route list*/ Route *tr1, *tr2; tr1=routes_; tr2=routes_; while ((tr1!=r)&&(tr1!=NULL)) { tr2=tr1; tr1=tr1->next(); } if (tr1==r) { tr2->next(tr1->next()); if (tr1==routes_) routes_=tr1->next(); } if (routes_!=NULL) { /*need to reposition routes on this edge*/ Edge *e=tr1->edge(); int ctr=0; for (tr2=routes_;tr2!=NULL;tr2=tr2->next()) if (tr2->edge()==e) tr2->place(e->x0(), e->y0(), ctr++); }}Route *Node::find_route(Edge *e, int group, int pktsrc, int oif) const{ Route *tr=NULL; tr=routes_; while (tr!=NULL) { if (tr->matching_route(e, group, pktsrc, oif)==1) return tr; tr=tr->next(); } return NULL;}void Node::place_route(Route *r){ if (r->node() != this) return; if (r->marked() == 0) { r->place(r->edge()->x0(), r->edge()->y0()); r->mark(1); }}// Used when topology is relayoutvoid Node::place_all_routes(){ Route *tr = routes_; while (tr != NULL) { place_route(tr); tr = tr->next(); }}// Clear mark on routes so we can replace themvoid Node::clear_routes(){ Route *tr = routes_; while (tr != NULL) { tr->mark(0); tr = tr->next(); }}int Node::no_of_routes(Edge *e) const{ Route *tr=routes_; int no_of_routes=0; while (tr!=NULL) { if (tr->edge()==e) no_of_routes++; tr=tr->next(); } return no_of_routes; }voidNode::label(const char* name, int anchor) { delete []label_; label_ = new char[strlen(name) + 1]; strcpy(label_, name); anchor_ = anchor;}void Node::lcolor(const char* name){ if (name[0] == 0) { if (lcolor_) { delete []lcolor_; lcolor_ = 0; } return; } if (lcolor_) delete []lcolor_; lcolor_ = new char[strlen(name) + 1]; strcpy(lcolor_, name);}void Node::dlabel(const char* name){ if (name[0] == 0) { if (dlabel_) { delete []dlabel_; dlabel_ = 0; } return; } if (dlabel_) delete []dlabel_; dlabel_ = new char[strlen(name) + 1]; strcpy(dlabel_, name);}//----------------------------------------------------------------------// void// Node::dcolor(const char* name)//----------------------------------------------------------------------void Node::dcolor(const char* name) { if (name[0] == 0) { if (dcolor_) { delete []dcolor_; dcolor_ = 0; } return; } if (dcolor_) delete []dcolor_; dcolor_ = new char[strlen(name) + 1]; strcpy(dcolor_, name);}//----------------------------------------------------------------------//----------------------------------------------------------------------voidNode::ncolor(const char* name) { if (name[0] == 0) { if (ncolor_) { delete []ncolor_; ncolor_ = 0; } return; } if (ncolor_) delete []ncolor_; ncolor_ = new char[strlen(name) + 1]; strcpy(ncolor_, name);}void Node::direction(const char* name){ if (name[0] == 0) { if (direction_) { direction_ = 0; } return; } if (!strcmp(name, "EAST")) direction_ = 1; else if (!strcmp(name, "SOUTH")) direction_ = 2; else if (!strcmp(name, "WEST")) direction_ = 3; else if (!strcmp(name, "NORTH")) direction_ = 4; else direction_ = 0;}void Node::add_sess_queue(unsigned int, Queue *q){ if (queue_ != NULL) // Currently we only allow one queue per node return; queue_ = q; queue_->place(size_*0.5, x_+size_*.05, y_+size_*0.5);}//----------------------------------------------------------------------//----------------------------------------------------------------------char * Node::getTclScript() { return tcl_script_;}//----------------------------------------------------------------------//----------------------------------------------------------------------char * Node::getTclScriptLabel() { return tcl_script_label_;}//----------------------------------------------------------------------//----------------------------------------------------------------------void Node::setTclScript(const char * label, const char * script) { if (tcl_script_label_) { delete [] tcl_script_label_; } tcl_script_label_ = new char[strlen(label)]; strcpy(tcl_script_label_, label); if (tcl_script_) { delete [] tcl_script_; } tcl_script_ = new char[strlen(script)]; strcpy(tcl_script_, script);}//----------------------------------------------------------------------// int// Node::command(int argc, const char * const * argv)// - Interface between tcl and c//----------------------------------------------------------------------intNode::command(int argc, const char * const * argv) { double start_x, start_y, destination_x, destination_y; double speed, start_time, destination_time; if (!strcmp(argv[1], "addMovement")) { // $node addMovement time x y speed // - time is time of start of movement // - x,y is destination location // - speed is how fast the node is travelling start_time = strtod(argv[2],NULL); destination_x = strtod(argv[3],NULL); destination_y = strtod(argv[4],NULL); speed = strtod(argv[5],NULL); // We need to calculate at what time we reach // destination x,y start_x = x(); // intial x,y values should have been set for start_y = y(); // node before add the Movement positions if (movement_list.head()) { movement_list.getPositionAt(start_time, start_x, start_y); } else { addMovementDestination(start_x, start_y, start_time); } // Now we need to find the arrival time at the // destination coordinates if (speed != 0.0) { destination_time = sqrt((start_x - destination_x) * (start_x - destination_x) + (start_y - destination_y) * (start_y - destination_y)) / speed + start_time; addMovementDestination(destination_x, destination_y, destination_time); } return TCL_OK; } return TCL_ERROR;}//----------------------------------------------------------------------//----------------------------------------------------------------------NodeMark* Node::find_mark(char *name) { NodeMark *p = nm_; while (p != NULL) { if (strcmp(p->name, name) == 0) break; p = p->next; } return p;}int Node::add_mark(char *name, char *color, char *shape){ if (find_mark(name) != NULL) return 1; NodeMark *cm = new NodeMark(name); cm->color = Paint::instance()->lookup(color, 2); if (strcmp(shape, "circle") == 0) cm->shape = NodeMarkCircle; else if (strcmp(shape, "square") == 0) cm->shape = NodeMarkSquare; else if (strcmp(shape, "hexagon") == 0) cm->shape = NodeMarkHexagon; if (nm_ != NULL) cm->next = nm_; nm_ = cm; nMark_++; update_bb(); return 0;}void Node::delete_mark(char *name){ NodeMark **p; p = &nm_; while (*p != NULL) { if (strcmp((*p)->name, name) == 0) { NodeMark *q = *p; *p = (*p)->next; delete q; nMark_--; update_bb(); return;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -