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

// -*-Mode: Java-*- 
// $Id: Rod.java,v 1.3 2003/03/06 00:40:49 moltmans Exp $
// Rod.java -- 
// Author: Michael Oltmans <moltmans@ai.mit.edu> 
// Created: <Tue May 23 19:08:22 2000> 
// Time-stamp: <2000-07-19 17:00:30 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 rods
 **/
public class Rod extends PartConstraint
{
  protected WSimRod m_rod;
  protected String m_name;

  public Rod( WSimRod rod, String name )
  {
    super( rod );
    Assert.notNull( rod, "Cannot make Rod with null rod" );
    m_rod = rod;
    m_name = name;
  }

  public WSimRod getRod()
  {
    return m_rod;
  }

  public String getName() 
  {
    return m_name;
  }

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

  public boolean sameFact( Fact fact ) 
  {
    if( fact instanceof Rod ) {
      Rod rod = (Rod)fact;
      return ( m_rod.equals( rod.m_rod ) &&
	       m_name.equals( rod.m_name ) );
    }
    return false;
  }

  public boolean isAttachedTo( Body body ) 
  {
    return ( body.getBody().equals( m_rod.getHeadPoint() ) ||
	     body.getBody().equals( m_rod.getTailPoint() ) );
  }

  public boolean isAnchored() 
  {
    return ( ( m_rod.getHeadPoint() == null ) ||
	     ( m_rod.getTailPoint() == null ) ||
	     m_rod.getHeadBody().isAnchored() ||
	     m_rod.getTailBody().isAnchored() );
  }
  
  public String toEnglish() 
  {
    return m_name;
  }

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