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

// -*-Mode: Java-*- 
// WMSimAnchor.java -- 
// Author: Christine Alvarado <calvarad@ai.mit.edu> 
// Maintainer: Christine Alvarado <calvarad@ai.mit.edu> 
// Version: 
// Created: <Wed May 26 17:51:23 1999> 
// Time-stamp: <2001-09-10 18:27:59 moltmans> 
// Keywords: 
package rec.simulate.widgets.wm;

import java.util.*;
import java.awt.*;
import rec.util.*;
import rec.sys.*;
import rec.core.widgets.*;
import rec.geo.*;
import rec.simulate.*;
import rec.simulate.widgets.*;

public class WMSimAnchor extends WSimAnchor
{
  public WMSimAnchor( GPoint center, double size ) 
  {
    super( center, size );
  }
  
  // only load the anchor if it is "attached" to a body, otherwise it makes
  // no sense.
  public String load( WMSimulatorRegistryBase reg ) 
  {
    GPoint newEnd1 = reg.convert( getLocation().getCenter() );
    String output;

    if ( m_body1 != null ) {
      Console.writeln( "loading anchor" );
      
      output = "Dim " + m_Name + " as WMPoint\n";
      
      // attach the endpoints to bodies, if they are attached to bodies
      // we assume at this point that the bodies have already been loaded
      // otherwise this does not work.
      
      GPoint newBody1 = reg.convert( m_body1.getLocation().getCenter() );
      newEnd1.x -= newBody1.x;
      newEnd1.y -= newBody1.y;
      
      output += "Set " + m_Name + " = doc.NewPoint(\"anchor\")\n";
      output +=  "Set " + m_Name + ".Body = " + m_body1.getName() 
	+ "\n";
      output += m_Name + ".PX.value = " + newEnd1.x + "\n";
      output += m_Name + ".PY.value = " + newEnd1.y + "\n";
      Console.writeln( "attatching " + m_Name + " to " + m_body1.getName() );
    }
    else {
      output = "";
      Console.writeln( "Anchor is not in a body!" );
    }

    return output;
    
  }


}
