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

package rec.house;

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

public class FullRegionRecognizer extends Recognizer
{
  public final static double BREAK = 20.0;

  public FullRegionRecognizer()
  {
  }

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

  public boolean recognize( Surface s, Widget w )
  {
    WPolygon l = (WPolygon)w;

    
    Console.writeln( "Region online" );

    Region q = new Region( l.getPolygon().getPoints() );

    // make walls
    GSegment[] gs = l.getPolygon().getSides();

    int size = l.numSides();
    for ( int i = 0; i < size; i++ )
      {
	Console.writeln( "Making a wall" );
	Wall new_w = new Wall( s, gs[i].getHeadPoint(), gs[i].getTailPoint() );

	s.addWidget( new_w );

	new_w.addRegion( q );
	q.addWall( new_w );
      }

    // put down the region
    s.replaceWidget( l, q );

    return( true );
  }


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

    v.addElement( "rec.core.WPolygon" );

    return( v.iterator() );
  }

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

    v.addElement( "rec.house.Region" );

    return( v.iterator() );
  }
}

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