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

  1. Procedure DowelPin;
  2. {
  3. (Windows version)
  4. ⌐1996, Diehl Graphsoft, Inc.
  5. Developed by Tom Urie
  6.  
  7. This procedure draws a dowel pin.
  8. }
  9.  
  10. LABEL 20,30,99;
  11. CONST
  12.     Bk=0.97; {Used to calculate chamfer}
  13.     Theta=15;  {Angle of chamfer.}
  14.     CF=0.33333;  {Used to determind radius of round end.}
  15. VAR
  16.     A1,A2,B,C,D,L,SF,x0,y0 : REAL;
  17.     View : INTEGER;
  18.     RFlag : ARRAY[1..2] OF INTEGER;
  19.     Abort,OK,Inch : BOOLEAN;
  20.     UPI : REAL;
  21.     Fmt : INTEGER;
  22.     UM,UM2 : STRING;
  23.     UName,DA : LONGINT;
  24.  
  25. Procedure PinDialog;
  26. {
  27. This procedure defines the dialog box.
  28. }
  29. VAR
  30.     Width,x1,y1,x2,y2,px1,px2,px3,px4,py1,py2 : INTEGER;
  31.  
  32. Procedure AlignScr(Width:INTEGER; VAR x1,x2:INTEGER);
  33. VAR
  34.     scrx1,scry1,scrx2,scry2:INTEGER;
  35. BEGIN
  36.     GetScreen(scrx1,scry1,scrx2,scry2);
  37.     x1:=((scrx1+scrx2) div 2)-(Width div 2);
  38.     x2:=x1+Width; 
  39. END;
  40.  
  41. Procedure MakeDialog;
  42. CONST
  43.     y1=100;
  44.     scnh=135; scnw=280;
  45.     h=30;
  46. BEGIN
  47.     AlignScr(scnw,x1,x2);
  48.     y2:=y1+scnh;
  49.     px1:=scnw-160;
  50.     px2:=scnw-100;
  51.     px3:=scnw-80;
  52.     px4:=scnw-20;
  53.     py1:=scnh-40;
  54.     py2:=scnh-20;
  55.  
  56.     BeginDialog(1,1,x1,y1,x2,y2);
  57.         AddButton('OK',1,1,px1,py1,px2,py2);
  58.         AddButton('Cancel',2,1,px3,py1,px4,py2);
  59.         AddField('Diameter:',4,1,20,45-h,90,60-h);
  60.         AddField('',5,2,100,45-h,150,60-h);
  61.         AddField('Length:',6,1,20,80-h,80,95-h);
  62.         AddField('',7,2,100,80-h,150,95-h);
  63.         AddField('View:',8,1,210,40-h,265,55-h);
  64.         AddButton('Top',9,3,210,80-h,250,95-h);
  65.         AddButton('Side',10,3,210,60-h,260,75-h);
  66.         AddField('',12,1,160,45-h,185,60-h);
  67.         AddField('',13,1,160,80-h,185,95-h);
  68.     EndDialog;
  69. END;
  70.  
  71. BEGIN
  72.     MakeDialog;
  73. END;
  74.  
  75. Procedure SetRButton(i,Item : INTEGER);
  76. BEGIN
  77.     IF RFlag[i] <> Item THEN BEGIN
  78.         SetItem(RFlag[i],FALSE);
  79.         SetItem(Item,TRUE);
  80.         RFlag[i]:=Item;
  81.     END;
  82. END;
  83.  
  84. Procedure GetInfo;
  85. {
  86. This procedure displays the dialog box and retrieves the information.
  87. }
  88. LABEL 10,99;
  89. VAR
  90.     Done:Boolean;
  91.     Item:Integer;
  92.  
  93. BEGIN
  94.     View:=2;
  95.     Done:=FALSE;
  96.     Abort:=FALSE;
  97.     RFlag[1]:=10;
  98.     GetDialog(1);
  99.     SetTitle('Dowel Pins');
  100.     SetItem(RFlag[1],TRUE);
  101.     SelField(5);
  102.     IF Inch THEN BEGIN
  103.         SetField(12,'in');
  104.         SetField(13,'in');
  105.     END
  106.     ELSE BEGIN
  107.         SetField(12,'mm');
  108.         SetField(13,'mm');
  109.     END;
  110.     10:REPEAT
  111.         DialogEvent(Item);
  112.         IF Item=1 THEN
  113.             Done:=True;
  114.         IF Item=2 THEN BEGIN
  115.             Done:=TRUE;
  116.             Abort:=TRUE;
  117.         END;
  118.         IF (Item = 9) OR (Item = 10) THEN BEGIN
  119.             SetRButton(1,Item);
  120.             View:=Item-8;
  121.         END;
  122.     UNTIL Done;
  123.     IF Abort THEN GOTO 99;
  124.     OK:=ValidNumStr(GetField(5),D);
  125.     OK:=ValidNumStr(GetField(7),L);
  126.     IF (D <= 0) OR ((VIEW = 2) AND (L <= 0)) THEN BEGIN
  127.         Sysbeep;
  128.         Done:=FALSE;
  129.         GOTO 10;
  130.     END;
  131.     99:ClrDialog;
  132. END;
  133.  
  134. {
  135. Main program.
  136. }
  137. BEGIN
  138.     DselectAll;
  139. {
  140. Get units/inch. Determine if units are inches or metric.
  141. }
  142.     GetUnits(UName,DA,Fmt,UPI,UM,UM2);
  143.     IF (UPI=25.4) OR (UPI=2.54) OR (UPI=0.0254) THEN BEGIN
  144.         SF:=UPI/25.4;
  145.         Inch:=FALSE;
  146.     END
  147.     ELSE BEGIN
  148.         SF:=UPI;
  149.         Inch:=TRUE;
  150.     END;
  151. {
  152. Display the dialog box and get the information.
  153. }
  154.     PinDialog;
  155.     SetCursor(ArrowC);
  156.     GetInfo;
  157.     IF Abort THEN GoTo 99;
  158. {
  159. Calculate the variables needed to draw the dowel pin.
  160. }
  161.     B:=D*Bk;
  162.     A1:=(D-B)/2;
  163.     A2:=A1/Tan(Deg2Rad(Theta));
  164.     C:=CF*D;
  165. {
  166. Adjust variables for units.
  167. }
  168.     D:=D*SF;
  169.     L:=L*SF;
  170.     B:=B*SF;
  171.     A1:=A1*SF;
  172.     A2:=A2*SF;
  173.     C:=C*SF;
  174. {
  175. Get the insertion point.
  176. }
  177.     GetPt(x0,y0);
  178.     Absolute;
  179.     MoveTo(x0,y0);
  180.     Relative;
  181.     IF View = 1 THEN GOTO 20;
  182. {
  183. Draw Side View.
  184. }
  185.     MoveTo(L-A2,D/2);
  186.     OpenPoly;
  187.     BeginPoly;
  188.         LineTo(0,0);
  189.         LineTo(A2,-A1);
  190.         LineTo(0,-B);
  191.         LineTo(-A2,-A1);
  192.         ArcTo(-(L-A2),0,C);
  193.         ArcTo(0,D,C);
  194.         LineTo(L-A2,0);
  195.     EndPoly;
  196.     LineTo(0,-D);
  197.     Move(-(L-A2-C),0);
  198.     LineTo(0,D);
  199.     GOTO 30;
  200. {
  201. Draw Top View.
  202. }
  203.     20:Arc(-D/2,D/2,D/2,-D/2,0,360);
  204.     30:Group;
  205. 99:END;
  206.  
  207. Run(DowelPin);
  208.