package modeler.shape;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.vecmath.Color3f;

/**
 * @author ags
 */
public abstract class Shape implements modeler.Treeable {

  // Auto-incrementing id for picking purposes.
  private static int nextId = 1000;
  private final int pickId = ++nextId;
  protected String name;
  
  //The default material parameters
  protected final Color3f diffuseColor = new Color3f(1,0,0);
  protected final Color3f specularColor = new Color3f(0,0,0);
  protected float expSpecular = 1;

  //Image used in tree
  protected Icon icon = new ImageIcon("../icons/thingy.gif");

  public Shape() {

    String classname = this.getClass().getName();
    setName(classname.substring(classname.lastIndexOf('.') + 1, classname.length()));
  }

  public Shape(Shape copy) {

    diffuseColor.set(copy.diffuseColor);
    specularColor.set(copy.specularColor);
    expSpecular = copy.expSpecular;
    
  }

  public Icon getIcon() {

    return icon;
  }

  /**
   * Just sets the pick id and then calls drawShape
   * @param glSim
   */
  public void render(GLSim glSim) {
    
    glSim.gl.glPushName(pickId);
    drawShape(glSim);
    glSim.gl.glPopName();
    
  }
  
  /**
   * Draws a shape to the screen.
   * @param glSim
   */
  public abstract void drawShape(GLSim glSim);
  
  /**
   * @return Returns the diffuseColor.
   */
  public Color3f getDiffuseColor() {
  
    return this.diffuseColor;
  }

  /**
   * @return Returns the diffuseColor.
   */
  public void setDiffuseColor(Color3f inColor) {
  
    diffuseColor.set(inColor);
    
  }
  
  /**
   * @return Returns the expSpecular.
   */
  public float getExpSpecular() {
  
    return this.expSpecular;
  }
  
  /**
   * @param expSpecular The expSpecular to set.
   */
  public void setExpSpecular(float expSpecular) {
  
    this.expSpecular = expSpecular;
  }
  
  /**
   * @return Returns the specularColor.
   */
  public Color3f getSpecularColor() {
  
    return this.specularColor;
    
  }
  
  /**
   * @return Returns the diffuseColor.
   */
  public void setSpecularColor(Color3f inColor) {
  
    specularColor.set(inColor);
    
  }

  // Treeable interface
  public void setName(String name) {
    this.name = name;
  }
  public String toString() {
    return name;
  }
  public int getPickId() {
    return pickId;
  }
}