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

package rec.simulate.widgets.wm;
// -*-Mode: Java-*- 
// WMSquare.java -- 
// Author: Christine Alvarado <calvarad@ai.mit.edu> 
// Maintainer: Christine Alvarado <calvarad@ai.mit.edu> 
// Version: 
// Created: <Wed Mar 10 19:09:22 1999> 
// Time-stamp: <2000-01-12 17:29:57 calvarad> 
// Keywords: 


import java.util.*;
import java.io.*;  //????
import rec.util.*;
import rec.geo.*;
import rec.sys.*;
import rec.core.widgets.*;
import java.math.*;
import rec.simulate.*;
import rec.simulate.widgets.*;

// class used when an interface to Working Model is desired.
public class WMSimPolygon extends WSimPolygon
{

  public WMSimPolygon( PolygonInfo pi )
  {
    super( pi );
  }

  public WMSimPolygon( WPolygon pi )
  {
    super( pi.getPolygon() );
  }

  // the key to this class is the load funciton, which "loads"
  // the object into the simulator.  that is, prints it to the file.
  // it takes a WMSimulator so that it knows the conversion factors
  // that it should use to convert dimensions.
  // it needs another parameter to resolve name conflicts.  The system
  // is seriously limited at the moment.
  public String load( WMSimulatorRegistryBase reg ) 
  {
    GPoint newCenter = reg.convert( getLocation().getCenter() );
    String output;

    Console.writeln( "loading polygon" );
    
    output = "Dim " + m_Name + " as WMBody\n";
    // assume the point center is a temp point here for our use
    // also there is a dynamic array which is here for our use as well
    output += "center.X = " + newCenter.x + " : center.Y = " + 
		    newCenter.y + "\n";
    // build the points array
    // remember to multiply the y coord by -1
    GPoint[] points = m_Polygon.getPoints();
    output += "redim p(" + m_NumSides + ")\n";
    for ( int i = 1; i <= m_NumSides; i++ ) {
      GPoint vertex = reg.convert( points[i-1] );
      output += "p(" + i + ").X = " + vertex.x + "\n";
      output += "p(" + i + ").Y = " + vertex.y + "\n";
    }
    output += "Set " + m_Name + " = Draw_Poly( " + m_NumSides + 
      ", p, center )\n";

    return output;

  }
  
///////////////////////////////////////////////////////////////////////////  
//
}
