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

////////////////////////////////////////////////////////////////////////////////
//
// FILE:	RotateTargetRecognizer.java
//
// AUTHOR:	Manoj D. Muzumdar
//		archon@ai.mit.edu
//
// DATE:	10-XX-98
//
// COPYRIGHT:	Massachusetts Institute of Technology
//		All rights reserved.
//
// PURPOSE:	Drawing recognition
//
// HISTORY:     10-XX-98 archon
//              adapted from ModifyModeRecognizer
//
//              11-15-98 archon
//              now aware of new rec.geo package
//
//              1-99 archon
//              added CurveParser testing
//
////////////////////////////////////////////////////////////////////////////////

package rec.core.recognizers;

import java.util.*;
import rec.util.*;
import rec.geo.*;
import rec.sys.*;
import rec.core.widgets.*;
import rec.core.*;

public class RotateTargetRecognizer extends TargetRecognizer
{

  public boolean recognize( Surface s, Widget w )
  {
    rec.sys.Squiggle st = (rec.sys.Squiggle)w;

      // check if rec.sys.Squiggle is a curve
      if( !CurveParser.isCurve( st ) )
	{
	  //Console.writeln( "Spinning REJECTED" );
	  return( false );
	}
      //Console.writeln( "Doing the rotate thing!" );
      VisibleWidget sw = (VisibleWidget)getTarget();

      GPoint center = sw.getLocation().getCenter();

      double angle = Geometry.angleBetween(
        st.getFirstPoint(), center, st.getLastPoint() );

      s.removeWidget( st );

      sw.rotate( center, angle );

      Transition ret = new RotateTransition( s, sw, center, angle );

      s.alterWidget( sw, (AlterTransition)ret );

      return( true );
  }

  public Iterator getInputTypes()
  {
    Vector v = new Vector();

    v.addElement( "rec.sys.Squiggle" );

    return( v.iterator() );
  }

  public Iterator getOutputTypes()
  {
    return( null );
  }
}

////////////////////////////////////////////////////////////////////////////////
