⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 node.cc

📁 NS2网络仿真软件是目前最为流行的网络仿真模拟软件
💻 CC
📖 第 1 页 / 共 3 页
字号:
		}		p = &((*p)->next);	}}void Node::update(double now) {	if (now >= endtime_ || now <= starttime_ ) {		return;	}	double xpos = xorig_ + (now - starttime_)* x_vel_;	double ypos = yorig_ + (now - starttime_)* y_vel_;	place(xpos,ypos);}void Node::draw_mark(View* nv) const{	NodeMark *cm;	double s = size_ * 0.7;	for (cm = nm_; cm != NULL; cm = cm->next, s += size_ * NodeMarkScale) {		switch (cm->shape) {		case NodeMarkCircle:			nv->circle(x_, y_, s, cm->color);			break;		case NodeMarkSquare: {			double x[2], y[2];			x[0] = x_ - s, x[1] = x_ + s;			y[0] = y_ - s, y[1] = y_ + s;			nv->rect(x[0], y[0], x[1], y[1], cm->color);			break;		}		case NodeMarkHexagon: {			float x[6], y[6];			double qd = 0.5 * s;			x[0] = x_ - s;			y[0] = y_;						x[1] = x_ - qd;			y[1] = y_ + s;						x[2] = x_ + qd;			y[2] = y_ + s;						x[3] = x_ + s;			y[3] = y_;						x[4] = x_ + qd;			y[4] = y_ - s;						x[5] = x_ - qd;			y[5] = y_ - s;						nv->polygon((float *)x, (float *)y, 6, cm->color);			break;		}		}	}}void Node::drawlabel(View* nv) const{	/*XXX node number */	if (label_ != 0)               nv->string(x_, y_, size_, label_, anchor_, lcolor_);	if (monitor_!=NULL)		monitor_->draw(nv, x_, y_-size_/2);	if (dlabel_ != 0) {                switch (direction_) {                case 0:		    nv->string(x_, y_+size_, size_*0.7, dlabel_, 0, dcolor_);                    break;                case 1:		    nv->string(x_-size_*1.5, y_, size_*0.7, dlabel_, 0, 			       dcolor_);                    break;                case 2:		    nv->string(x_, y_-size_, size_*0.7, dlabel_, 0, dcolor_);                    break;                case 3:		    nv->string(x_+size_*1.5, y_, size_*0.7, dlabel_, 0, 			       dcolor_);                    break;                case 4:		    nv->string(x_,           y_+size_,   size_*0.7, dlabel_, 0,			       dcolor_);                    break;                default:		    nv->string(x_,           y_+size_,   size_*0.7, dlabel_, 0,			       dcolor_);                    break;                }        }}void Node::reset(double){	//XXX why should reset to black??? 	//	paint_ = Paint::instance()->thick();}//----------------------------------------------------------------------// MovementElement * // Node::addMovementDestination(double x, double y, double time)//   - add a movement destination to node if it doesn't have any links//   - only node without links can be moved//----------------------------------------------------------------------MovementElement * Node::addMovementDestination(double world_x, double world_y, double time) {	if (!links()) {		if (!movement_list.head() && time != 0.0) {			addMovementDestination(x(), y(), 0.0);		}		return movement_list.add(world_x,world_y,time);	} else {		place(world_x,world_y);		return NULL;	}}//----------------------------------------------------------------------//----------------------------------------------------------------------void Node::removeMovementDestination(double time) {	movement_list.remove(time);}//----------------------------------------------------------------------//----------------------------------------------------------------------int Node::getMovementTimeList(char * buffer, int buffer_size) {	return movement_list.getListString(buffer, buffer_size);}//----------------------------------------------------------------------// double // Node::getMaximumX()//   - Get the maximum x value that a node can be at during it's//     movement sequence//----------------------------------------------------------------------double Node::getMaximumX() {	MovementElement * movement;	double X;	movement = movement_list.head();	if (movement) {		X = movement->x_;		while(movement) {			if (movement->x_ > X) {				X = movement->x_;			}			movement = movement->next_;		}	} else {		X = x();	}	return X;}//----------------------------------------------------------------------// double// Node::getMaximumY()//   - Get the maximum y value that a node can be at during it's//     movement sequence//----------------------------------------------------------------------doubleNode::getMaximumY() {	MovementElement * movement;	double Y;	movement = movement_list.head();	if (movement) {		Y = movement->y_;		while(movement) {			if (movement->y_ > Y) {				Y = movement->y_;			}			movement = movement->next_;		}	} else {		Y = y();	}	return Y;}void Node::place(double _x, double _y) { 	x_ = _x;	y_ = _y;	mark_ = 1;	update_bb();	if (!links() && !movement_list.head()) {		addMovementDestination(x(), y(), 0.0);	}	// Should we place queues here too? 	if (queue_ != NULL) { 		queue_->place(0.5 * size_, x_+0.5*size_, y_+0.5*size_);	}}//----------------------------------------------------------------------// void// Node::move(EditView *v, float wdx, float wdy)//   - Move by a displacement in *window* coordinates//----------------------------------------------------------------------void Node::move(EditView * edit_view, float wdx, float wdy) {	float cx, cy;	// First get our position in window coordinates	cx = x_, cy = y_;	edit_view->map(cx, cy);	cx += wdx;	cy += wdy;	// Now switch back to world coordinates	edit_view->imap(cx, cy);	// Place the new location	place(cx, cy);	// Because all placements are centrally organized by AutoNetModel, 	// we'll have to call back. :(	edit_view->moveNode(this);}//----------------------------------------------------------------------//////----------------------------------------------------------------------voidNode::updatePositionAt(double current_time) {	double world_x, world_y;	world_x = x();	world_y = y();	movement_list.getPositionAt(current_time, world_x, world_y);	place(world_x, world_y);}Edge *Node::find_edge(int dst) const {	for (Edge *e = links_; e != 0; e = e->next_) 		if (e->dst() == dst)			return e;	return NULL;}int Node::save(FILE *file){	char buffer[TRACE_LINE_MAXLEN], *p;	rgb *color;	color=Paint::instance()->paint_to_rgb(paint_);	buffer[0] = 0;	if (state_ == UP)		strcpy(buffer, "-S UP");	else if (state_==DOWN)		strcpy(buffer, "-S DOWN");	p = buffer + strlen(buffer);	if (dlabel_)		sprintf(p, " -b \"%s\"", dlabel_);	fprintf(file, "n -t * -s %d -v %s -c %s -z %f %s\n", 		nn_, style(), color->colorname, size_, buffer);	return(0);}//----------------------------------------------------------------------// int// Node::writeNsScript(FILE *file)//----------------------------------------------------------------------intNode::writeNsScript(FILE *file) {	int chars_written = 0;	rgb * color;	color = Paint::instance()->paint_to_rgb(paint_);	double start_x, start_y;	// If there are no values on movement_list then start_ and start_y	// will be unchanged. So we need to intialize start_x and start_y	// to the current values	start_x = x();	start_y = y();	movement_list.getPositionAt(0.0, start_x, start_y);	chars_written += fprintf(file, "set node(%d) [$ns node]\n", number());	chars_written += fprintf(file, "## node(%d) at %f,%f\n", number(), start_x, start_y);	chars_written += fprintf(file, "$node(%d) set X_ %f\n", number(), start_x);	chars_written += fprintf(file, "$node(%d) set Y_ %f\n", number(), start_y);	chars_written += fprintf(file, "$node(%d) set Z_ 0.0\n", number());//	chars_written += fprintf(file, "$node(%d) size \"%f\"\n", number(), size_);	chars_written += fprintf(file, "$node(%d) color \"%s\"\n", number(), color->colorname);	if (dlabel_) {		chars_written += fprintf(file, "$ns at 0.0 \"$node(%d) label %s\"\n", number(), dlabel_);	}	return chars_written;}//----------------------------------------------------------------------// int// Node::writeNsMovement(FILE *file)//----------------------------------------------------------------------intNode::writeNsMovement(FILE *file) {	int chars_written = 0;	MovementElement * start, * destination;	double speed;	start = movement_list.head();	if (start) {		fprintf(file, "$ns initial_node_pos $node(%d) %f\n", number(), size());		// Skip first command since it is our starting place		destination = start->next_;		while (destination) {			if (start->x_ != destination->x_ ||			    start->y_ != destination->y_) {				// find speed from start to destination				speed = sqrt((start->x_ - destination->x_) *				             (start->x_ - destination->x_) +				             (start->y_ - destination->y_) *				             (start->y_ - destination->y_))/				        (destination->time_ - start->time_);				chars_written += fprintf(file, "$ns at %f \"$node(%d) setdest %f %f %f\"\n",				                                start->time_, number(),				                                destination->x_, destination->y_, speed);			}			start = destination;			destination = destination->next_;		}	}	return chars_written;}BoxNode::BoxNode(const char* name, double size) : Node(name, size){	BoxNode::size(size);}void BoxNode::size(double s){	Node::size(s);	double delta = 0.5 * s;	x0_ = x_ - delta;	y0_ = y_ - delta;	x1_ = x_ + delta;	y1_ = y_ + delta;}void BoxNode::draw(View* nv, double now) {	nv->rect(x0_, y0_, x1_, y1_, paint_);	drawlabel(nv);	draw_mark(nv);}void BoxNode::place(double x, double y){	Node::place(x, y);	double delta = 0.5 * size_;	x0_ = x_ - delta;	y0_ = y_ - delta;	x1_ = x_ + delta;	y1_ = y_ + delta;}CircleNode::CircleNode(const char* name, double size) : Node(name, size){	CircleNode::size(size);}void CircleNode::size(double s){	Node::size(s);	radius_ = 0.5 * s;}void CircleNode::draw(View* nv, double now) {	nv->circle(x_, y_, radius_, paint_);	drawlabel(nv);	draw_mark(nv);}HexagonNode::HexagonNode(const char* name, double size) : Node(name, size){	HexagonNode::size(size);}void HexagonNode::size(double s){	Node::size(s);	double hd = 0.5 * s;	double qd = 0.5 * hd;	xpoly_[0] = x_ - hd; ypoly_[0] = y_;	xpoly_[1] = x_ - qd; ypoly_[1] = y_ + hd;	xpoly_[2] = x_ + qd; ypoly_[2] = y_ + hd;	xpoly_[3] = x_ + hd; ypoly_[3] = y_;	xpoly_[4] = x_ + qd; ypoly_[4] = y_ - hd;	xpoly_[5] = x_ - qd; ypoly_[5] = y_ - hd;}void HexagonNode::draw(View* nv, double now) {	nv->polygon(xpoly_, ypoly_, 6, paint_);	drawlabel(nv);	draw_mark(nv);}void HexagonNode::place(double x, double y){	Node::place(x, y);	double hd = 0.5 * size_;	double qd = 0.5 * hd;	xpoly_[0] = x_ - hd; ypoly_[0] = y_;	xpoly_[1] = x_ - qd; ypoly_[1] = y_ + hd;	xpoly_[2] = x_ + qd; ypoly_[2] = y_ + hd;	xpoly_[3] = x_ + hd; ypoly_[3] = y_;	xpoly_[4] = x_ + qd; ypoly_[4] = y_ - hd;	xpoly_[5] = x_ - qd; ypoly_[5] = y_ - hd;}VirtualNode::VirtualNode(const char* name, Lan *lan) :   Node(name, 0), lan_(lan){}void VirtualNode::size(double s){	Node::size(0);	lan_->size(s);}void VirtualNode::draw(View* nv, double now) {  printf("drawing vn at %f %f\n", x_, y_);}void VirtualNode::place(double x, double y){	Node::place(x, y);	lan_->place(x, y);}void VirtualNode::arrive_packet(Packet *p, Edge *e, double atime){        lan_->arrive_packet(p,e,atime);}void VirtualNode::delete_packet(Packet *p){        lan_->delete_packet(p);}double VirtualNode::x(Edge *e) const{  return lan_->x(e);}double VirtualNode::y(Edge *e) const{  return lan_->y(e);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -