/////////////
//	Author : Colm
///////////////
// 18-8  this is basically a stripped down version
// of arcshape which makes it much easier to use with doors
// than the initial arcshape which goes with the arc tool. 
////////////////
/***************************************
   SIMPLE ARC SHAPE
***************************************/

simpleArc.prototype = new Shape;
simpleArc.constructor = simpleArc;
simpleArc.superclass = Shape.prototype;


function simpleArc( x1, y1, x2, y2, rad, sw, la, axr, draw ){
  if (arguments.length > 0) 
    this.init(x1, y1, x2, y2, rad, sw, la, axr, draw );
}

simpleArc.prototype.init = function(x1, y1, x2, y2, rad, sw, la, axr, draw){
  Arc.superclass.init.call(this, null);

  this.handles[0] = new Handle(x1, y1, this);
  this.handles[1] = new Handle(x2, y2, this);

  this.radius = rad;
  this.sweep = sw;
  this.large_arc = la;
  this.axis_rot = axr;
	
	/*
	debug ("handles 0 : " + this.handles[0].point.x + " " + this.handles[0].point.y); 
	debug ("handles 1 : " + this.handles[1].point.x + " " + this.handles[1].point.y); 
	debug ("radius : " + this.radius);
	debug ("sweep : " + this.sweep);
	debug ("large arc : " + this.large_arc);
	debug ("axis rot : " + this.axis_rot);
	*/
	
	if(draw)
		this.make();
}

simpleArc.prototype.constructPathString = function(){
	var ret = "M" + this.handles[0].point.x + ", " + 
							 this.handles[0].point.y + "A"+this.radius + ", " + 
							 this.radius + " " + this.axis_rot + " " + 
							 this.large_arc + ", " + this.sweep + " " + 
							 this.handles[1].point.x + " " +this.handles[1].point.y;
	return ret;
}

simpleArc.prototype.make = function() {
  this.svgNode = svgDoc.createElement("path");
  this.svgNode.addEventListener( "click", this, false );
 	style = this.svgNode.getStyle();
	style.setProperty("fill", "none");
  style.setProperty("stroke", strokeColor);
  style.setProperty("stroke-width", strokeWidth);
 	drawingGroup.appendChild( this.svgNode );
	this.svgNode.setAttribute("id", "simpleArc");
	var pathstring = this.constructPathString();
	this.svgNode.setAttribute("d", pathstring);
}

simpleArc.prototype.update = function( x1, y1, x2, y2, rad, sw ){
	if (arguments.length > 0){
		this.handles[0].moveto(x1, y1);
		this.handles[1].moveto(x2, y2);
		this.sweep = sw;			
		this.radius = rad;  
  	var pathstring = this.constructPathString();
		this.svgNode.setAttribute("d", pathstring);
	}
	else {
  	var pathstring = this.constructPathString();
  	this.svgNode.setAttribute("d", pathstring);
	} 
}

simpleArc.prototype.destructor = function(){
  this.svgNode.parentNode.removeChild( this.svgNode );
	for (var k = 0; k < this.handles.length ; k ++)
		delete (this.handles[k]);
  delete this.svgNode;
	delete this.radius;
	delete this.axis_rot;
  delete this.large_arc;
  delete this.sweep;
}
