/* 
 *
 *                        plottick.c
 *
 *
 *     XT & YT instructions implementation
 *    
 *     Marek Krawus, PCC
 */
#include "defn.h"

plottick(kind)
char   kind;
{
 float   urtval, dltval;
 float   down1, down2, down3;
 float   up1, up2, up3;
 float   diagonal, line_len;
 int     parts;

  switch (kind) 
  {
   case 'x':
    urtval = ((P2y - P1y) * YSCALE_ABS) * urTICK * 0.01;
    dltval = ((P2y - P1y) * YSCALE_ABS) * dlTICK * 0.01;
    break;

   case 'y':
    urtval = ((P2x - P1x) * XSCALE_ABS) * urTICK * 0.01;
    dltval = ((P2x - P1x) * XSCALE_ABS) * dlTICK * 0.01;
    break;
  }


  if ((LINE_STYLE == SOLID_LINE) || (LINE_STYLE == 0))
  {
     if (!DRAW_FLAG)
     {
        fprintf(outfile, "newpath\n");
        fprintf(outfile, "  %g %g %s\n", absX, absY, MOVE);
        DRAW_FLAG = 1;
     }
     switch (kind) 
     {
        case 'x':
          fprintf(outfile, "  %g %g XT\n", urtval, dltval);
          break;

        case 'y':
          fprintf(outfile, "  %g %g YT\n", urtval, dltval);
          break;
     }
     return;
  }

  else                     /* LINE_STYLE != SOLID_LINE && LINE_STYLE != 0    */
  {
    
    end_draw();
    fprintf(outfile, "newpath\n");
    fprintf(outfile, "  [] 0 setdash\n");
    fprintf(outfile, "  %g %g %s\n", absX, absY, MOVE);

    switch (kind) 
    {
       case 'x':
         fprintf(outfile, "  %g %g XT\n", urtval, dltval);
         break;

       case 'y':
         fprintf(outfile, "  %g %g YT\n", urtval, dltval);
         break;
    }

    fprintf(outfile, "stroke\n");
    
    switch (LINE_STYLE)
    {
    case 6:                /*    [----- - - ]     */ 
       { 
	down1 = 0.5;
	up1 = up2 = up3 = 0.1;
	down2 = down3 = 0.1;
	parts = 6;
       }
	break;

    case 5:               /*    [------- - ]     */
       {
	down1 = 0.7;
	up1 = up2 = 0.1;
	down2 = 0.1;
	parts = 4;
       }
	break;

    case 4:               /*   [-------- . ]     */
       { 
	down1 = 0.78;
	up1 = up2 = 0.1;
	down2 = 0.02;
	parts = 4;
       }
	break;

    case 3:               /*   [-------   ]     */
       { 
	down1 = 0.7; 
	up1 = 0.3;
	parts = 2;
       } 
	break;

    case 2:               /*   [-----     ]     */
       { 
	down1 = 0.5;
	up1 = 0.5;
	parts = 2;
       }
	break;

    case 1:               /*   [.         ]     */
       { 
	down1 = 0.02;
	up1 = 0.98;
	parts = 2;
       }
	break;
    }

    diagonal = pow(((P2x - P1x) * XSCALE_ABS),2.0) + pow(((P2y - P1y) * YSCALE_ABS),2.0);
    diagonal = pow(diagonal,0.5);
    line_len = diagonal * LINE_LENGTH * 0.01;

    down1 *= line_len;
    down2 *= line_len;
    down3 *= line_len;
    up1 *= line_len;
    up2 *= line_len;
    up3 *= line_len;

    switch (parts)
	{
	  case 2:
	    fprintf(outfile, "[%g mm %g mm] 0 setdash\n",
	            down1, up1);
            break;


	  case 4:
	    fprintf(outfile, "[%g mm %g mm %g mm %g mm] 0 setdash\n",
	            down1, up1, down2, up2);
            break;

	  case 6:
	    fprintf(outfile,"[%g mm %g mm %g mm %g mm %g mm %g mm] 0 setdash\n",
	            down1, up1, down2, up2, down3, up3);
            break;
        }


  }

}
