#include "window.h"

using namespace std;

using namespace morpheo::tools::viewer::graphics;

/*draw the port in rectangular form*/
void Window::drawPort(int x,int y,int pos,string dir){
    if(pos == NORTH){
      if (dir == "in"){

	painter.drawLine(x,y,x-5,y-10);
	painter.drawLine(x,y,x+5,y-10);
	painter.drawLine(x-5,y-10,x+5,y-10);
	}

      if(dir== "out"){ 
	painter.drawLine(x-5,y,x,y-10);
	painter.drawLine(x+5,y,x,y-10);
	painter.drawLine(x-5,y,x+5,y);
	}

      if(dir ==  "inout"){ 
	painter.drawLine(x,y,x-5,y-5);
	painter.drawLine(x,y,x+5,y-5);
	painter.drawLine(x-5,y-5,x+5,y-5);
	painter.drawLine(x-5,y-5,x,y-10);
	painter.drawLine(x+5,y-5,x,y-10);
	painter.drawLine(x-5,y-5,x+5,y-5);
	}
      }
    

    if(pos==SOUTH){
      if (dir=="in"){
        painter.drawLine(x,y,x-5,y+10);
	painter.drawLine(x,y,x+5,y+10);
	painter.drawLine(x-5,y+10,x+5,y+10);
	}
	
      if(dir== "out"){
	painter.drawLine(x-5,y,x,y+10);
	painter.drawLine(x+5,y,x,y+10);
	painter.drawLine(x-5,y,x+5,y);
	}
	
      if(dir == "inout"){
	painter.drawLine(x,y,x-5,y+5);
	painter.drawLine(x,y,x+5,y+5);
	painter.drawLine(x-5,y+5,x+5,y+5);
	painter.drawLine(x-5,y+5,x,y+10);
	painter.drawLine(x+5,y+5,x,y+10);
	painter.drawLine(x-5,y+5,x+5,y+5);

      }
    } 
    
    if(pos==WEST){
      if(dir== "in"){ 
	painter.drawLine(x-10,y-5,x,y);
	painter.drawLine(x-10,y+5,x,y);
	painter.drawLine(x-10,y-5,x-10,y+5);
	}

      if(dir=="out"){
	painter.drawLine(x-10,y,x,y-5);
	painter.drawLine(x-10,y,x,y+5);
	painter.drawLine(x,y-5,x,y+5);
	}
	
      if(dir== "inout"){
	painter.drawLine(x-5,y-5,x,y);
	painter.drawLine(x-5,y+5,x,y);
	painter.drawLine(x-5,y-5,x-5,y+5);
	painter.drawLine(x-10,y,x-5,y-5);
	painter.drawLine(x-10,y,x-5,y+5);
	painter.drawLine(x-5,y-5,x-5,y+5);
	}
      }
    

    if(pos==EAST){
      if(dir== "in"){ 
	painter.drawLine(x+10,y-5,x,y);
	painter.drawLine(x+10,y+5,x,y);
	painter.drawLine(x+10,y-5,x+10,y+5);
	}

      if(dir== "out"){
	painter.drawLine(x+10,y,x,y-5);
	painter.drawLine(x+10,y,x,y+5);
	painter.drawLine(x,y-5,x,y+5);
	}
	
      if(dir== "inout"){
	painter.drawLine(x+5,y-5,x,y);
	painter.drawLine(x+5,y+5,x,y);
	painter.drawLine(x+5,y-5,x+5,y+5);
	painter.drawLine(x+10,y,x+5,y-5);
	painter.drawLine(x+10,y,x+5,y+5);
	painter.drawLine(x+5,y-5,x+5,y+5);
	
      }
    }
}
