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

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

import rec.annotate.rules.*;
import java.util.*;
import rec.util.*;
import rec.sys.*;
import rec.tms.*;
import rec.geo.*;

/**
 **/
public class Attachment extends Annotation
{
  protected PartConstraint m_part;
  protected Body m_body1;
  protected Body m_body2;

  public Attachment( PartConstraint part, Body body1, Body body2 )
  {
    super( part.getStartTime(), part.getEndTime() );
    m_part = part;
    m_body1 = body1;
    m_body2 = body2;
  }

  public Collection getBodies() 
  {
    List list = new ArrayList( 2 );
    list.add( m_body1 );
    list.add( m_body2 );
    return list;
  }
  
  public Body getBody1() 
  {
    return m_body1;
  }

  public Body getBody2() 
  {
    return m_body2;
  }

  public PartConstraint getPart() 
  {
    return m_part;
  }

  public GPoint getAttachmentPoint( Body b ) 
  {
    return m_part.getConstraint().getAttachmentPoint( b.getBody() );
  }

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

  public boolean sameFact( Fact fact ) 
  {
    if( fact instanceof Attachment ) {
      Attachment a = (Attachment)fact;
      return ( m_part.sameFact( a.m_part ) &&
	       m_body1.sameFact( a.m_body1 ) &&
	       m_body2.sameFact( a.m_body2 ) );
    }
    return false;
  }

  public String toEnglish() 
  {
    return ( m_part.toEnglish() + " attaches " + m_body1.toEnglish() +
	     " to " +m_body2.toEnglish() );
  }


  public String toString() 
  {
    return "<Attachment: [" + m_part + "] attaches[" + m_body1 +
      m_body2 + "]>";
  }
}

