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

// -*-Mode: Java-*- 
// $Id: PinJoint.java,v 1.3 2003/03/06 00:40:49 moltmans Exp $
// PinJoint.java -- 
// Author: Michael Oltmans <moltmans@ai.mit.edu> 
// Created: <Tue May 16 15:29:44 2000> 
// Time-stamp: <2000-07-19 16:58:37 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 pinjoints
 **/
public class PinJoint extends PartConstraint
{
  protected WSimPinJoint m_pin;
  protected String m_name;

  public PinJoint( WSimPinJoint pin, String name )
  {
    super( pin );
    Assert.notNull( pin, "Cannot make PinJoint with null pin" );
    m_pin = pin;
    m_name = name;
  }

  public WSimPinJoint getPinJoint()
  {
    return m_pin;
  }

  public String getName() 
  {
    return m_name;
  }

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

  public boolean sameFact( Fact fact ) 
  {
    if( fact instanceof PinJoint ) {
      PinJoint pin = (PinJoint)fact;
      return ( m_pin.equals( pin.m_pin ) &&
	       m_name.equals( pin.m_name ) );
    }
    return false;
  }

  public boolean isAttachedTo( Body body ) 
  {
    return ( body.getBody().equals( m_pin.getBody1() ) ||
	     body.getBody().equals( m_pin.getBody2() ) );
  }

  public String toEnglish() 
  {
    return m_name;
  }

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