home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 March / Chip_1998-03_cd.bin / tema / MINICAD / MC7DEMO / MINICAD.1 / DOWL_PIN.MPC < prev    next >
Text File  |  1997-04-30  |  4KB  |  264 lines

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