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

📄 motesimobject.java

📁 这是无线传感器网络用的操作系统tinyos-1.1.0,未来的世界将是它呵
💻 JAVA
字号:
// $Id: MoteSimObject.java,v 1.4.4.3 2003/08/26 09:08:11 cssharp Exp $/*									tab:2 * * * "Copyright (c) 2000 and The Regents of the University  * of California.  All rights reserved. * * Permission to use, copy, modify, and distribute this software and * its documentation for any purpose, without fee, and without written * agreement is hereby granted, provided that the above copyright * notice and the following two paragraphs appear in all copies of * this software. *  * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL * DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS * DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *  * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE * PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF * CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, * UPDATES, ENHANCEMENTS, OR MODIFICATIONS." * * Authors:	Phil Levis, Nelson Lee * Date:        December 11, 2002 * Desc:        mote object for AdvSim * *//** * @author Phil Levis * @author Nelson Lee */package net.tinyos.sim;import net.tinyos.sim.event.*;import java.util.*;public class MoteSimObject extends SimObject {  private int id;  public MoteSimObject(TinyViz tv, double x, double y, int id, SimObjectPopupMenu popup) {    super(tv, MOTE_OBJECT_SIZE, popup);    Attribute a;    a = new MoteCoordinateAttribute(x, y);    addAttribute(a);    a = new MoteIDAttribute(id);    addAttribute(a);    this.id = id;    a = new MoteLedsAttribute();    addAttribute(a);  }  public int getID() {    return id;  }  public MoteCoordinateAttribute getCoordinate() {    return (MoteCoordinateAttribute)getAttribute("net.tinyos.sim.MoteCoordinateAttribute");  }  public boolean getPower() {    MotePowerAttribute attr = (MotePowerAttribute)getAttribute("net.tinyos.sim.MotePowerAttribute");    if (attr == null) return false;    return attr.getPower();  }  public void setPower(boolean power) {    MotePowerAttribute attr = (MotePowerAttribute)getAttribute("net.tinyos.sim.MotePowerAttribute");    if (attr == null) {      addAttribute(new MotePowerAttribute(power));    } else {      attr.setPower(power);    }  }  public boolean pointInSimObjectSpace(int windowX, int windowY, CoordinateTransformer cT) {    synchronized (simState) {      MoteCoordinateAttribute coordAttrib = getCoordinate();      double moteWinX = cT.simXToGUIX(coordAttrib.getX());      double moteWinY = cT.simYToGUIY(coordAttrib.getY());      double dx = (double)windowX - moteWinX;      double dy = (double)windowY - moteWinY;      int distance = (int)Math.sqrt((dx * dx) + (dy * dy));      if (distance <= super.getObjectSize()) {	return true;      }      return false;    }  }  public boolean simObjectInQuad(double x1, double y1, double x2, double y2, CoordinateTransformer cT) {    synchronized (simState) {      MoteCoordinateAttribute coordAttrib = getCoordinate();      double sGUIMinX = cT.simXToGUIX(coordAttrib.getX());      double sGUIMaxX = sGUIMinX + getObjectSize();      double sGUIMaxY = cT.simYToGUIY(coordAttrib.getY());      double sGUIMinY = sGUIMaxY - getObjectSize();      if ((((x1 <= sGUIMinX) && (sGUIMinX <= x2)) || ((x1 <= sGUIMaxX) && (sGUIMaxX <= x2))) &&	  (((y1 <= sGUIMinY) && (sGUIMinY <= y2)) || ((y1 <= sGUIMaxY) && (sGUIMaxY <= y2)))) {	return true;      }      return false;    }  }  public void moveSimObject(int dx, int dy, CoordinateTransformer cT) {    synchronized (simState) {	      MoteCoordinateAttribute coordinateAttribute = getCoordinate();      coordinateAttribute.setX(cT.guiXToSimX(dx) + coordinateAttribute.getX());      coordinateAttribute.setY(cT.guiYToSimY(dy) + coordinateAttribute.getY());    }  }  public void addCoordinateChangedEvent() {    synchronized (simState) {      MoteCoordinateAttribute coordinateAttribute = getCoordinate();      eventBus.addEvent(new AttributeEvent(ATTRIBUTE_CHANGED, this, coordinateAttribute));    }  }//  public boolean equals(Object o) { //   if (o instanceof MoteSimObject) {  //    MoteSimObject mso = (MoteSimObject)o;   //   if (mso.id == this.id) return true; //   } //   return false;//  }//  public int hashCode() {//    return this.id;//  }  public String toString() {    return "[Mote "+id+"]";  }}

⌨️ 快捷键说明

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