// (c) MIT 2003.  All rights reserved.

// -*-Mode: Java-*- 
// WMSimulatorRegistryBase.java -- 
// Author: Christine Alvarado <calvarad@ai.mit.edu> 
// Maintainer: Christine Alvarado <calvarad@ai.mit.edu> 
// Version: 
// Created: <Wed May 19 15:41:31 1999> 
// Time-stamp: <2001-09-10 18:33:02 moltmans> 
// Keywords: 
package rec.simulate;

import java.util.*;
import rec.util.*;
import java.io.*;
import rec.sys.*;
import rec.geo.*;
import rec.core.widgets.*;
import rec.meche.WMSpring;
import rec.meche.WMForce;
import java.lang.*;
import rec.simulate.widgets.*;
import rec.simulate.widgets.wm.*;


// base for the WM simulation classes, so that they can refer to the same
// WM objects and I don't need to duplicate all those objects.
public abstract class WMSimulatorRegistryBase extends SimulatorRegistry
{
  // conversion factor between pixels and WM units
  protected int m_converter = 80;
  
  public WMSimulatorRegistryBase( )
  {
    super( );
        
  }
  
  public abstract void load( Surface s );
  
    // returns a point which has been converted based on the WM conversion 
  // factor
  // also fixes the strange coords to be correct
  public GPoint convert( GPoint c )
  {
    double newX = c.x / m_converter;
    double newY = c.y / m_converter * -1;
    GPoint newP = new GPoint( newX, newY );
    return newP;
  }

  public double convert( double x )
  {
    return( x / m_converter );
  }

  ///////////////////////////////////////////////////////////////////////////
  // functions to create WMSimulatable objects so we can ask the registry
  // to create us an object of the correct type rather than always knowing
  // what type we want (because we don't care).
  public WSimRectangle makeRectangle( WRectangle r )
  {
    return ( new WMRectangle( r ) );
  }

  public WSimQuadrilateral makeQuadrilateral( WQuadrilateral q )
  {
    return ( new WMSimQuadrilateral( q ) );
  }
  
  public WSimCircle makeCircle( WCircle r )
  {
    return ( new WMSimCircle( r ) );
  }

  public WSimSpring makeSpring( WMSpring r )
  {
    return ( new WMSimSpring( r ) );
  }

  public WSimPulley makePulley( List wheels, List ropes )
  {
    return ( new WMSimPulley( wheels, ropes ) );
  }
  
  public WSimTriangle makeTriangle( WTriangle t )
  {
    return ( new WMSimTriangle( t ) );
  }

  public WSimPolygon makePolygon( PolygonInfo pi )
  {
    return ( new WMSimPolygon( pi ) );
  }

  public WSimPolygon makePolygon( WPolygon poly )
  {
    return ( new WMSimPolygon( poly ) );
  }

  public WSimForce makeForce( WMForce f )
  {
    return ( new WMSimForce( f ) );
  }
  
  public WSimAnchor makeAnchor( GPoint center, double size ) 
  {
    return ( new WMSimAnchor( center, size ) );
  }

  public WSimMotor makeMotor( GPoint center ) 
  {
    return ( new WMSimMotor( center ));
  }

  public WSimGear makeGear( WCircle circle ) 
  {
    return ( new WMSimGear( circle ));
  }

  public WSimGearTrain makeGearTrain( WSimGear[] gears, 
				      WSimGearTrain[] trains, 
				      WSimGear newGear, 
				      boolean singleCircles)
  {
      return ( new WMSimGearTrain( gears,trains,newGear,singleCircles ));
  }

  public WSimRotationalDamper makeRotationalDamper( GPoint center )
  {
    return ( new WMSimRotationalDamper( center ));
  }

  public WSimRotationalSpring makeRotationalSpring( GToolkitSpiral spiral )
  {
    return ( new WMSimRotationalSpring( spiral ));
  }

  public WSimTorque makeTorque( WToolkitArc arc, WLine line1, WLine line2, boolean clockwise ) 
  {
    return ( new WMSimTorque(arc, line1, line2, clockwise));
  }

  public WSimSpringDamper makeSpringDamper(GSegment base, boolean damperup)
  {
    return (new WMSimSpringDamper(base, damperup));
  }

  public WSimPinJoint makePinJoint( WSimCircle c )
  {
    return ( new WMSimPinJoint( c ) );
  }

  public WSimDamper makeDamper( GSegment s )
  { 
    return ( new WMSimDamper( s ));
  }

  public WSimRod makeRod( WLine l )
  {
    return ( new WMSimRod( l ) );
  }

    public WSimRope makeRope( WComplex c )
    {
	return ( new WMSimRope( c ) );
    }

    public WSimRope makeRope( WLine l )
    {
	return ( new WMSimRope( l ) );
    }

}

