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

// -*-Mode: Java-*- 
// $Id: Spring.java,v 1.3 2003/03/06 00:40:49 moltmans Exp $
// Spring.java -- 
// Author: Michael Oltmans <moltmans@ai.mit.edu> 
// Created: <Tue May 16 01:18:52 2000> 
// Time-stamp: <2000-07-19 17:04:19 moltmans> 
package rec.annotate.facts;

import rec.annotate.rules.*;
import java.util.*;
import rec.util.*;
import rec.simulate.widgets.*;
import rec.tms.*;

/**
 * This class is for storing information about springs
 **/
public class Spring extends PartConstraint
{
  protected WSimSpring m_spring;
  protected String m_name;

  public Spring( WSimSpring spring, String name )
  {
    super( spring );
    Assert.notNull( spring, "Cannot make Spring with null spring" );
    m_spring = spring;
    m_name = name;
  }

  public WSimSpring getSpring()
  {
    return m_spring;
  }

  public String getName() 
  {
    return m_name;
  }

  public String getFactType() 
  {
    return Type.SPRING;
  }

  public boolean sameFact( Fact fact ) 
  {
    if( fact instanceof Spring ) {
      Spring spring = (Spring)fact;
      return ( m_spring.equals( spring.m_spring ) &&
	       m_name.equals( spring.m_name ) );
    }
    return false;
  }

  public boolean isAttachedTo( Body body ) 
  {
    return ( body.getBody().equals( m_spring.getHeadBody() ) ||
	     body.getBody().equals( m_spring.getTailBody() ) );
  }

  public boolean isAnchored() 
  {
    return ( ( m_spring.getHeadBody() == null ) ||
	     ( m_spring.getTailBody() == null ) ||
	     m_spring.getHeadBody().isAnchored() ||
	     m_spring.getTailBody().isAnchored() );
  }

  public String toEnglish() 
  {
    return m_name;
  }

  public String toString() 
  {
    return "<Spring: [" + m_name + "]>";
  }
}
