/*
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOUSE. See the GNU
 * General Public License for more details.
 *
 * You should have recieved a copy of the GNU General Public License
 * along with this program; if not write to the Free Software
 * Foundation, inc., 59 Temple Place, Suite 330, Boston MA 02111-1307
 * USA
 */
package j3d;
import java.awt.*;
import java.util.*;
import javax.swing.tree.*;
import java.io.*;
import javax.swing.*;
import gui.*;
/**
 * Insert the type's description here.
 *
 * @author: Yuriy Mikhaylovskiy
 */

public class _Point implements _Object, Serializable{
  public float x,y,z;
  public Color color;
  protected String Id;
  public boolean selected = false;

  private void writeObject(ObjectOutputStream out)  throws IOException{
    out.writeFloat(x);
    out.writeFloat(y);
    out.writeFloat(z);
    out.writeObject(color);
  }
  private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException{
    x = in.readFloat();
    y = in.readFloat();
    z = in.readFloat();
    color = (Color)in.readObject();
    selected = false;
  }

  public void mesh(int type, float size){}
  public boolean delete(){return selected;}

  public _Point() {
    this(0,0,0,Color.black);
  }
  public _Point(float xx, float yy, float zz) {
    this(xx,yy,zz,Color.black);
  }
  public _Point(float xx, float yy, float zz, Color cl) {
    x=xx;
    y=yy;
    z=zz;
    color=cl;
  }

  public Object[] get_Array(Canvas3D j3d){
    Object[] arr = {new shpPoint(x,y,z,selected ? j3d.SELECTCOLOR : color)};
    return arr;
  }
  public String get_Id(){
    return Id;
  }
  public void set_Id(String id){
    Id=id;
  }
  public boolean isSelected(){return selected;}
  public void Select(String st){ selected=st!=null; }
  public String toString(){ return "Point ID="+Id;}
  public MutableTreeNode get_TreeNode(){
    DefaultMutableTreeNode node = new DefaultMutableTreeNode(this);
    node.add(new DefaultMutableTreeNode("Color - ("+color.getRed()+","+color.getGreen()+","+color.getBlue()+")"));
    node.add(new DefaultMutableTreeNode("X,Y,Z - ("+x+","+y+","+z+")"));
    return node;
  }
  public void transform3D(Matrix3D t){
    if(!selected)return;
    float xx=x*t.xx+y*t.xy+z*t.xz+t.xo;
    float yy=x*t.yx+y*t.yy+z*t.yz+t.yo;
    float zz=x*t.zx+y*t.zy+z*t.zz+t.zo;
    x=xx; y=yy; z=zz;
  }
  public JPanel getEditPanel(Canvas3D j3d, PreProcessor pp){ return new JPanel(); }
  public _Node[] get_Nodes(){return null;}
  public _Object[] get_Elements(){return null;}
  public float distance(_Point p){ return (float)Math.sqrt((x-p.x)*(x-p.x)+(y-p.y)*(y-p.y)+(z-p.z)*(z-p.z)); }
}