home *** CD-ROM | disk | FTP | other *** search
/ PC & Mediji 1997 January / PCM_9701.iso / programi / minicad / minicad.1 / BRK_LINE.MPC < prev    next >
Encoding:
Text File  |  1996-04-30  |  3.5 KB  |  158 lines

  1. Procedure BreakLine;
  2. {
  3. (Windows version)
  4. ⌐1996, Diehl Graphsoft, Inc.
  5. Developed by Tom Urie
  6.  
  7. This procedure creates a break line.
  8. }
  9. LABEL 99;
  10. CONST
  11.     A1C=0.25;  {Length of zig-zag for type #1}
  12.     f=0.25;  {Ratio of zig-zag to length of line for type #2} 
  13.     Alpha=15;  {Angle of zig-zag relative to line}
  14.     LDivC=1.5;  {Used to determine the number of zig-zags for type #3}
  15. VAR
  16.     A,A1,x1,y1,x2,y2,xt,yt,Theta,Theta2,L,L1,LDiv,LScale : REAL;
  17.     i,NDiv,Type : INTEGER;
  18.     Abort : BOOLEAN;
  19.     LayerH : HANDLE;
  20.     UPI,SF : REAL;
  21.     Fmt : INTEGER;
  22.     UM,UM2 : STRING;
  23.     UName,DA : LONGINT;
  24.  
  25. Procedure Dialog;
  26. VAR
  27.     Width,x1,y1,x2,y2,px1,px2,px3,px4,py1,py2 : INTEGER;
  28.  
  29. Procedure AlignScr(Width:INTEGER; VAR x1,x2:INTEGER);
  30. VAR
  31.     scrx1,scry1,scrx2,scry2:INTEGER;
  32. BEGIN
  33.     GetScreen(scrx1,scry1,scrx2,scry2);
  34.     x1:=((scrx1+scrx2) div 2)-(Width div 2);
  35.     x2:=x1+Width; 
  36. END;
  37.  
  38. Procedure MakeDialog;
  39. CONST
  40.     y1=100;
  41.     scnh=160; scnw=230;
  42.     h=30;
  43. BEGIN
  44.     AlignScr(scnw,x1,x2);
  45.     y2:=y1+scnh;
  46.     px3:=(scnw div 2) - 70;
  47.     px4:=(scnw div 2) - 10;
  48.     px1:=(scnw div 2) + 10;
  49.     px2:=(scnw div 2) + 70;
  50.     py1:=scnh-40;
  51.     py2:=scnh-20;
  52.     BeginDialog(1,1,x1,y1,x2,y2);
  53.         AddButton('OK',1,1,px3,py1,px4,py2);
  54.         AddButton('Cancel',2,1,px1,py1,px2,py2);
  55.         AddField('Type:',5,1,20,40-h,185,55-h);
  56.         AddButton('Single - fixed size',6,3,20,65-h,160,80-h);
  57.         AddButton('Single - proportional',7,3,20,90-h,175,105-h);
  58.         AddButton('Multiple - fixed size',8,3,20,115-h,173,130-h);        
  59.     EndDialog;
  60. END;
  61.  
  62. BEGIN
  63.     MakeDialog;
  64. END;
  65.  
  66. Procedure GetInfo;
  67. VAR
  68.     Item,RFlag1 : INTEGER;
  69.     Done : BOOLEAN;
  70.  
  71. BEGIN
  72.     Done:=FALSE;
  73.     Abort:=FALSE;
  74.     Type:=1;
  75.     RFlag1:=6;
  76.     GetDialog(1);
  77.     SetTitle('Break Line');
  78.     SetItem(RFlag1,TRUE);
  79.     REPEAT
  80.         DialogEvent(Item);
  81.         IF Item=1 THEN
  82.             Done:=TRUE;
  83.         IF Item=2 THEN BEGIN
  84.             Done:=TRUE;
  85.             Abort:=TRUE;
  86.         END;         
  87.         IF (Item > 5) AND (Item < 9) THEN BEGIN
  88.             SetItem(RFlag1,FALSE);
  89.             SetItem(Item,TRUE);
  90.             RFlag1:=Item;
  91.             Type:=Item-5;
  92.         END; 
  93.     UNTIL Done;
  94.     ClrDialog;
  95. END;
  96. {
  97. Main Program
  98. }
  99. BEGIN
  100.     DselectAll;
  101.     AngleVar;
  102.     Dialog;
  103.     SetCursor(ArrowC);
  104.     GetInfo;
  105.     IF Abort THEN GOTO 99;
  106. {
  107. Get units per inch and layer scale
  108. }
  109.     GetUnits(UName,DA,Fmt,UPI,UM,UM2);
  110.     LayerH:=ActLayer;
  111.     LScale:=GetLScale(LayerH);
  112. {
  113. Adjust constants for units and scale
  114. }
  115.     A1:=A1C*LScale*UPI;
  116.     LDiv:=LDivC*LScale*UPI;
  117. {
  118. Get the end points of the line and determine length and angle
  119. }
  120.     GetLine(x1,y1,x2,y2);
  121.     IF (x1=x2) AND (y1=y2) THEN BEGIN
  122.         Sysbeep;
  123.         GOTO 99;
  124.     END;
  125.     L:=Sqrt((y2-y1)^2 + (x2-x1)^2);
  126.     IF x2 <> x1 THEN
  127.         Theta:=Rad2Deg(ArcTan((y2-y1)/(x2-x1)))
  128.     ELSE IF y2 > y1 THEN
  129.         Theta:=90
  130.     ELSE Theta:=-90;
  131.     IF x2 < x1 THEN BEGIN
  132.         xt:=x1; yt:=y1;
  133.         x1:=x2; y1:=y2;
  134.         x2:=xt; y2:=yt;
  135.     END;
  136.     IF Type=2 THEN
  137.         A:=f*L
  138.     ELSE
  139.         A:=A1;
  140.     IF Type=3 THEN
  141.         NDiv:=L/LDiv
  142.     ELSE
  143.         NDiv:=2;
  144.     L1:=(L-2*(NDiv-1)*A*Tan(Deg2Rad(Alpha)))/NDiv;
  145.     MoveTo(x1,y1);
  146.     Relative;
  147.     FOR i:=1 TO NDiv-1 DO BEGIN
  148.         Line(L1,#Theta);
  149.         Line(A,#(Theta-90));
  150.         Line(2*A/Cos(Deg2Rad(Alpha)), #(90+Theta-Alpha));
  151.         Line(A,#(Theta-90));
  152.     END;
  153.     Line(L1,#Theta);
  154.     Group;
  155. 99:END;
  156.  
  157. Run(BreakLine);
  158.