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

// $Id: WMSimQuadrilateral.java,v 1.4 2003/03/06 00:40:40 moltmans Exp $
// Time-stamp: <2000-03-11 18:59:37 moltmans>
package rec.simulate.widgets.wm;


import java.awt.*;
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 WMSimQuadrilateral extends WSimQuadrilateral
{

  public WMSimQuadrilateral( WQuadrilateral q )
  {
    super( q );
  }

  // 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 quadrilateral" );
    
    
    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(4)\n" ;
    for ( int i = 1; i <= 4; 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( 4, p, center )\n";
      
    return output;

  }


}
