SkyObject.java 8.55 KB
package osp;

import java.awt.Color;
import java.awt.geom.Point2D;
import java.util.ArrayList;

import jsky.coords.WorldCoords;

/**
 * This class represents a sky object.
 * Object coords are stored in image coord.
 */
public class SkyObject
{
  // Attributes
  //-----------
  // Attributes needed to be saved
  /** Position in pixels */
  private Point2D.Double posPix; // In Image coord
  /** Center position in Ra-Dec world Coordinates */
  private WorldCoords objWorldCenter;
  /** Recalculated position in pixels */
  private Point2D.Double posPixRecalc; // In Image coord
  /** Position of recalculated center in Ra-Dec world Coordinates */
  private WorldCoords objWorldRecalc;
  
  // Attributes not needed to be saved for masks
  /** Number of the object on project image */
  private int numIm;
  /**  object id When loaded */

//  private int id=0;
  private String targetId="";

  /** Specifying if the object is a reference or not */
  private boolean isRef;
  /** Origin of the object (C: for catalogue, L : local catalog, M: loaded from a mask, S : Selected from image) */
  private String src;
  /**Properties  **/
  private ArrayList<String> properties;
  private String prop;
  /** catalog group number where the object is from when loaded */
  private int group=0;
  /** Object priority */
  private int priority;
  /* display object color */  
  private Color col;
  
  
  // Constructors
  //-----------
  
  /**
   * Constructs a temporary new sky object only to display. 
   * @param n Object number in image objects list
   * @param iR true if the object is a reference object, false otherwise
   * @param p Center of the object (in image coordinates)
   * @param pRecalc Center of the object once recalculated (in image coordinates)
 * @param c Color following priority.
   */ 
  public SkyObject(int n, boolean iR, Point2D.Double p, Point2D.Double pRecalc, Color c)
  {
//	  System.out.print("SkyObj 1 "+n+" ");
    numIm = n;
    isRef = iR;    
	
    posPix = new Point2D.Double();
    setPosPix(p);

//    if (pRecalc!= null)
//    {
//    	 System.out.println("SkyObj - pRecal "+pRecalc.getX()+" "+pRecalc.getY());
//    	 setPosPixRecalc(pRecalc); 
//    	 c=Color.green;
//    }
 	
    if (isRef )c=Color.red;
 //   System.out.println("SkyObj -"+n+" const temp color "+c.toString());
	 this.setColor(c);
//    WorldCoords coords = new WorldCoords(wc.getRA(),wc.getDec());
//    setObjWorldCenter(coords);
//    setObjWorldRecalc(coords);
 // System.out.println("Sk Obj Nw "+n+" "+ p.x +" "+p.y);
  }
  
  
  /**
   * Constructs a new sky object when loading a project, loading a catalog, 
   *  or selecting manually on image.
   * @param id Object id from a project or a catalog 
   * @param n Object number in project
   * @param iR true if the object is a reference object, false otherwise
   * @param fi nbCat : number of catalogs loaded
   * @param props Object Properties/catalog name/ ...
   * @param p Center of the object (in canvas coordinates)
   * @param wc Object world coordinates in J2000
   * @param prior Object priority
   */

//  public SkyObject(int idO, int n, boolean iR, int fi, String fr, Point2D.Double p, WorldCoords wc, int prior)
  public SkyObject(String idO, int n, boolean iR, int fi, String props, Point2D.Double p, WorldCoords wc, int prior)

  {
//System.out.println(" SkyObj 2 num "+n+" id "+idO);
    targetId = idO;
    numIm=n;
    isRef = iR;
    group=fi;
    prop=props;
    posPix = new Point2D.Double();
    setPosPix(p);
    posPixRecalc = null;
    objWorldCenter=new WorldCoords(wc.getRA(),wc.getDec());
    objWorldRecalc=new WorldCoords(0,0);
    priority = prior;  
    Color c=Color.blue;
    switch (prior)
    {
    	case 1: 
    		c=Color.RED;
    		break;
    	case 2:
    		c=Color.WHITE;
    		break;
    	default:
    		c=Color.BLUE;
    		break;
    }
   
    if (isRef )c=Color.RED;
    
    setColor(c);
    
  //  System.out.println("SkyObj - "+n+ " const Norm color "+c.toString());
  }
  
   
  // Methods
  //-----------
  /**
   * Sets the position of the object.
   * @param mouse Center of the object
   */
  public void setPosPix( Point2D.Double point )
  { posPix.x = point.x; posPix.y = point.y; }
  
  /**
   * Sets the recalculated position of the object.
   * @param point Recalculated center of the object
   */
  public void setPosPixRecalc( Point2D.Double point )
  { 
    if (point == null)
      posPixRecalc = null;
    else
      posPixRecalc = new Point2D.Double(point.x, point.y);
  }
 
  /**
   * Returns the object priority
   * @return Object priority
   */
  public int getPriority() { return priority; }
  
  /**
   * Set  object's priority
   * 
   */
  public void setPriority(int n)
  {
	  priority=n;
  }
  
  /**
   * Returns the actual position of the center of the object. If the center has been
   * recalculated, returns the recalculated position.
   * @return Center of the object.
   */
  public Point2D.Double getPosition()
  {
    if (posPixRecalc != null)
    {
      return posPixRecalc;
    }
    else
      return posPix;
  }

  /**
   * Returns the original position of the object
   * (position before any recalculation).
   * @return Initial center of the object
   */
  public Point2D.Double getPosPix() { return posPix; }
  /**
   * Returns the recalculated position of the object.
   * @return Recalculated center of the object
   */
  public Point2D.Double getPosPixRecalc() { return posPixRecalc; }
 
  /**
   * Returns the number of the object for project image
   * @return Object number
   */
  public int getNum() { return numIm; }
  
  /**
   * Repositions the object's id in the image objects list
   * 
   */
  public void reSetNum(int n)
  {
    numIm=n;
  }
  
  /**
   * Returns the object id (when loaded by a local cat and has yet an identifier)
   * @return Object id
   */

  public String getTargetId() { return targetId; }

    
  /**
   * Sets if the object is a reference on the image.
   * @param b true if the object is a reference
   */
  public void setRef(boolean b) { 
	  this.isRef = b; 
	  Color c=Color.red;
	  setColor(c);
  }
  /**
   * Returns whether the object is a reference on the image or not.
   * @return true if the object is a reference, false otherwise.
   */
  public boolean isRef() { return this.isRef; }

  /**
   * Sets the object origin : catalog ('C') or user picked ('S') 
   * or local catalog ('L') or charged with a mask ('M')
   * @param f Origin of the object
   */
    public void setSrc(String ff) { src = ff; }
  /**
   * Returns the object origin: catalog ('C') or user picked ('S') 
   * or local catalog ('L') or charged with a mask ('M')
   * or loaded from a mask ('load').
   * @return Origin of the object
   */
  public String getSrc() { return src; }
  
  /**
   * Sets the object properties 
   */
  // Used
  public void setObjectProp(String pr)
  {
	 // System.out.println("skObj prop "+pr);
	  prop=pr;
  }
 
 
  /**
   * Returns some object properties stored in String (Last array column) 
   */
  public String getProperty() { return prop; }
  
  /**
   * Returns <i>true</i> if the center of the object has been recalculated.
   * @return true if the center has been recalculated
   */
  public boolean isCenterRecalc ()
  { 
	  boolean err=false;
	  if (posPixRecalc != null)
	  {
	    Color c = new Color(0, 255, 0);
	    this.setColor(c);
	    err=true;
	  }
	  return err;  
  
  }


  public WorldCoords getObjWorldCenter() {	
	return objWorldCenter;
  }

  public void setObjWorldCenter(WorldCoords objWorldCenter) {
	this.objWorldCenter = objWorldCenter;
  }

  public WorldCoords getObjWorldRecalc() {
	return objWorldRecalc;
  }

  public void setObjWorldRecalc(WorldCoords objWorldRecalc) {
	this.objWorldRecalc = objWorldRecalc;
  }

/**
 * Get the color to draw the object with
 * @return Color col : object color
 */
public Color getColor() {
	return col;
}

/**
 * Set the color the object will be drawn with
 * @param col : color
 */
public void setColorWithPriority(int p) {
Color c;
	switch (p)
   {
	case 1: 
		c=Color.RED;
		break;
	case 2:
		c=Color.WHITE;
		break;
	default:
		c=Color.BLUE;
		break;
   }
	this.col=c;
}
/**
 * Set the color the object will be drawn with
 * @param col : color
 */
public void setColor(Color col) {
	this.col = col;
}

/**
 * Get the catalog group where the object is from 
 * @return int group
 */
public int getGroup() {
	return group;
}

}