/* Generated By:JJTree: Do not edit this line. ASTSquare.java */

public class ASTSquare extends SimpleNode 
{
	/*************************************************
	
						Constructors
	
	*************************************************/
	
	public ASTSquare(int id) 
	{
    	super(id);
  	}

  	public ASTSquare(drawphase2 p, int id) 
  	{
    	super(p, id);
  	}
  
  	/*************************************************
	
	Creates and returns a string containing the SVG code
	for square object
	
	*************************************************/
  
  	public String generateSVG()
  	{
  		String temp, right, left, bottom, top, colour ="black", parent;
  		int brushSize = 1, offsetX = 0, offsetY = 0;
  		
  		//Variables containing the co-ordinates of the square
  		
  		int x1 = ((ASTInt) jjtGetChild(0)).val;
  		int y1 = ((ASTInt) jjtGetChild(1)).val;
  		int x2 = ((ASTInt) jjtGetChild(2)).val;
  		int y2 = ((ASTInt) jjtGetChild(2)).val;
  		
        /*************************************************
	
		Checks to see if the parent's type is null
	
		*************************************************/
        
        if(!(jjtGetParent().getParentType() == null))
        {
        
  			if(jjtGetParent().getParentType().equals("brush"))
  			{
  				brushSize = jjtGetParent().getBrush();
  			}
  		
  			if(jjtGetParent().getParentType().equals("colour"))
  			{
  				colour = jjtGetParent().getColour();
  			}
  		
  			if(jjtGetParent().getParentType().equals("offset"))
  			{
  				offsetX = jjtGetParent().getOffsetX();
  				offsetY = jjtGetParent().getOffsetY();
  				
  				x1 = x1 + offsetX; 
  				y1 = y1 + offsetY;
				x2 = x2 + offsetX;
			}
			
			/*************************************************
	
			Checks to see if the parent of the parent's type is null
	
			*************************************************/
  			
  			if(!(jjtGetParent().jjtGetParent().getParentType() == null))
        	{
  		
  				if(jjtGetParent().jjtGetParent().getParentType().equals("brush"))
  				{
  					brushSize = jjtGetParent().jjtGetParent().getBrush();
  				}
  		
  				if(jjtGetParent().jjtGetParent().getParentType().equals("colour"))
  				{
  					colour = jjtGetParent().jjtGetParent().getColour();
  				}
  		
  				if(jjtGetParent().jjtGetParent().getParentType().equals("offset"))
  				{
  					offsetX = jjtGetParent().jjtGetParent().getOffsetX();
  					offsetY = jjtGetParent().jjtGetParent().getOffsetY();
  					
  					x1 = x1 + offsetX; 
  					y1 = y1 + offsetY;
  					x2 = x2 + offsetX;
  				}
  				
  				/*************************************************
	
				Checks to see if the parent of the parent of the 
				parent's type is null
	
				*************************************************/
  				
  				if(!(jjtGetParent().jjtGetParent().jjtGetParent().getParentType() == null))
  				{
  					if(jjtGetParent().jjtGetParent().jjtGetParent().getParentType().equals("brush"))
  					{
  						brushSize = jjtGetParent().jjtGetParent().jjtGetParent().getBrush();
  					}
  		
  					if(jjtGetParent().jjtGetParent().jjtGetParent().getParentType().equals("colour"))
  					{
  						colour = jjtGetParent().jjtGetParent().jjtGetParent().getColour();
  					}
  		
  					if(jjtGetParent().jjtGetParent().jjtGetParent().getParentType().equals("offset"))
  					{	
  						offsetX = jjtGetParent().jjtGetParent().jjtGetParent().getOffsetX();
  						offsetY = jjtGetParent().jjtGetParent().jjtGetParent().getOffsetY();
  						
  						x1 = x1 + offsetX; 
  						y1 = y1 + offsetY;
 	 					x2 = x2 + offsetX;
  					}
  				}
  			}
  		}
  		
  		/*************************************************
	
		Takes the four lines that make up the square and
		concatinated them into one string and return them
	
		*************************************************/
    	    	    	
    	top = ("<line x1=\"" + x1 +
        	"\" y1=\"" + y1 +
        	"\" x2=\"" + x2 +
        	"\" y2=\"" + y1 +
        	"\" stroke=\""+ colour + "\" stroke-width=\""+brushSize+"\"/>\n");
		
		left = ("<line x1=\"" + x1 +
        	"\" y1=\"" + y1 +
        	"\" x2=\"" + x1 +
        	"\" y2=\"" + y2 +
        	"\" stroke=\""+ colour + "\" stroke-width=\""+brushSize+"\"/>\n");
			
		right = ("<line x1=\"" + x2 +
        	"\" y1=\"" + y1 +
        	"\" x2=\"" + x2 +
        	"\" y2=\"" + y2 +
        	"\" stroke=\""+ colour + "\" stroke-width=\""+brushSize+"\"/>\n");
			
		bottom =("<line x1=\"" + x1 +
        	"\" y1=\"" + y2 +
        	"\" x2=\"" + x2 +
        	"\" y2=\"" + y2 +
        	"\" stroke=\""+ colour + "\" stroke-width=\""+brushSize+"\"/>");

  		temp = top + left + right + bottom;
  		
  		return temp;
  	}
  	
  	/*************************************************
	
	Methods needed by Node interface
	
	*************************************************/
  		
  	public void generate()
  	{
  	}
  	
  	public int getBrush()
  	{
  		return 0;
  	}
  	 
  	 public String getColour()
  	{
  		return null;
  	}
  	
  	public String getParentType()
  	{
  		return null;
  	}
  	
  	public int getOffsetX()
  	{
  		return 0;
  	}
  
  	public int getOffsetY()
	{
  		return 0;
  	}

}
