//
//      SceneComponent.java
//
//------------------------------------------------------------------------
//
//      Portions Copyright (c) 2000 SURVICE Engineering Company.
//      All Rights Reserved.
//      This file contains Original Code and/or Modifications of Original
//      Code as defined in and that are subject to the SURVICE Public
//      Source License (Version 1.2, dated December 14, 1999)
//
//      A copy of this license can be found in the doc directory
//------------------------------------------------------------------------
//
//      Developed by QUADRA Enterprises, Inc. (www.quadra-inc.com)
//      January 27, 2000
//
//      Authors:
//              John P. Williams
//              Robb P. Bush
//------------------------------------------------------------------------
package com.quadra.OpenCanvas3D;

import javax.media.j3d.*;
import javax.vecmath.*;
import javax.swing.tree.*;

/**The parent class (single interface) representing OpenCanvas3D components
* or groups of components using the Composite Structural Pattern.
* (include diagram) - mention strength of this abstraction
*/
public class SceneComponent 
{
//DESIGN NOTE: Each Component (leaf or composite) will be responsible for
//      managing its own units - we will use a common unit of meters for
//      displaying all the various elements of the world.  Therefore, the
//      components must convert from original units to meters when building
//      the BranchGroup
public static final int FEET=0;
public static final int INCHES=1;
public static final int METERS=2;
public static final int MILLIMETERS=3;
public static final int CENTIMETERS=4;

int unitsFlag=METERS;  //The default if nothing is specified
Integer IDnumber;
String  Name;
String  Alias;
ComponentData compData=null;
BranchGroup compBG;
Switch compSwitch;

//This is only used if the Component is Scaled or Translated or Rotated
//This will be added to the graph as needed - the methods that would need
//to instantiate this transform have not yet been created
Transform3D compT3D = null;

        //The constructor should setup the basic (common) scene graph nodes
        public SceneComponent()
                {
                compBG = new BranchGroup();
                compBG.setCapability(Group.ALLOW_CHILDREN_WRITE);
                compBG.setCapability(BranchGroup.ALLOW_DETACH);
                compBG.setPickable(true);
                compBG.setCapability(Node.ENABLE_PICK_REPORTING);
                compBG.setUserData(this);
                compSwitch = new Switch(Switch.CHILD_ALL);
                compSwitch.setCapability(Group.ALLOW_CHILDREN_WRITE);
                compSwitch.setCapability(Switch.ALLOW_SWITCH_WRITE);
                compBG.addChild(compSwitch);
                }

        //Public Interface
        public void SetID(Integer val) {IDnumber=val;}
        public Integer GetID() {return IDnumber;}
        public void SetName(String val) {Name = val;}
        public String GetName() {return Name;}
        public void SetAlias(String val) {Alias = val;}
        public String GetAlias() {return Alias;}
        public void SetData(ComponentData thisData) {compData = thisData;}
        public ComponentData GetData() {return compData;}

        //Overriding the toString method for JTree (& other uses)
        public String toString() {return Name;}

        public void ShowComp() {compSwitch.setWhichChild(Switch.CHILD_ALL);}
        public void HideComp() {compSwitch.setWhichChild(Switch.CHILD_NONE);}
        public void SetVisibility(boolean val)
                {
                if (val) compSwitch.setWhichChild(Switch.CHILD_ALL);
                else compSwitch.setWhichChild(Switch.CHILD_NONE);
                }

        public Node GetRootNode() {return compBG;}

        public void SetUnits(int val)
                {
                unitsFlag=val;
                //TODO - set up the compT3D if val != METERS
                }
        public int GetUnits() {return unitsFlag;}
        public float ConvertToMeters()
                {
                if (unitsFlag == METERS) return 1.0f;
                else if (unitsFlag == CENTIMETERS) return 0.01f;
                else if (unitsFlag == MILLIMETERS) return 0.001f;
                else if (unitsFlag == FEET) return 0.3048f;
                else if (unitsFlag == INCHES) return 0.0254f;
                else {System.out.println("Unknown units"); return 0f;}
                }
        public String GetLinearUnits()
                {
                if (unitsFlag == METERS) return "Meters";
                else if (unitsFlag == CENTIMETERS) return "Centimeters";
                else if (unitsFlag == MILLIMETERS) return "Millimeters";
                else if (unitsFlag == FEET) return "Feet";
                else if (unitsFlag == INCHES) return "Inches";
                else return "Unknown Units";
                }

        //DESIGN NOTE: Although I would like to make some of these methods
        //      abstract(virtual) it would mean making the entire class
        //      abstract as well, which I don't think we want (because we can do some useful work here)
        public SceneComponent GetCompByName(String name) {return null;}
        public DefaultMutableTreeNode GetTreeNode() {return null;}
        public void AddComponent(SceneComponent sc) {}
        public void RemoveComponent(SceneComponent sc) {}
        public void SetTransparency(float val) {}
        public void SetColor(float r, float g, float b) {}
        public void SolidShade(){}
        public void LineDrawing() {}

}


