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

// -*-Mode: Java-*- 
// $Id: PropelsEvent.java,v 1.4 2003/03/06 00:40:49 moltmans Exp $
// Propels.java -- 
// Author: Michael Oltmans <moltmans@ai.mit.edu> 
// Created: <Thu May 18 18:33:19 2000> 
// Time-stamp: <2000-07-19 16:59:55 moltmans> 
package rec.annotate.facts;

import rec.annotate.rules.*;
import rec.annotate.*;
import rec.sys.*;
import rec.tms.*;

public class PropelsEvent extends Event
{
  protected Body m_body1;
  protected Body m_body2;
  protected Annotation m_base;

  public PropelsEvent( Surface s, Annotation base,
		       Body body1, Body body2 )
  {
    super( s, base.getStartTime(), base.getEndTime() );
    m_base = base;
    m_body1 = body1;
    m_body2 = body2;
  }

  public Body getBody1()
  {
    return m_body1;
  }

  public Body getBody2()
  {
    return m_body2;
  }
  
  public String getFactType() 
  {
    return Type.PROPELS_EVENT;
  }

  public Body getSubject() 
  {
    return getBody1();
  }
  
  public boolean isBasedOn( Annotation a ) 
  {
    return m_base.sameFact( a );
  }

  public boolean sameFact( Fact fact ) 
  {
    if( fact instanceof PropelsEvent ) {
      PropelsEvent f = (PropelsEvent)fact;
      return ( m_body1.sameFact( f.m_body1 ) &&
	       m_body2.sameFact( f.m_body2 ) &&
	       m_base.sameFact( f.m_base ) );
    }
    return false;
  }

  public Event combineWith( Event event )
  {
    if( event instanceof PropelsEvent ) {
      PropelsEvent propel = (PropelsEvent)event;
      if( m_body1.sameFact( propel.m_body1 ) &&
	  m_body2.sameFact( propel.m_body2 ) &&
	  m_base.sameFact( propel.m_base ) )
      {
	return new PropelsEvent( getSurface(), m_base,
				 m_body1, m_body2 );
      }
    }
    return null;    
  }
  
  public String toString() 
  {
    return ( "<PropelsEvent: [" + m_body1.getName() +
	     "] [" + m_body2.getName() + "]>" );
  }

  public String toEnglish()
  {
    return m_body1.toEnglish() + " propels " + m_body2.toEnglish();
  }
  
}
