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

  1. Procedure DrawNut;
  2. {
  3. (c)1997, Diehl Graphsoft, Inc.
  4. Developed by Tom Urie
  5.  
  6. This procedure draws all kinds of hex and square nuts.
  7. }
  8. LABEL 10,15,20,30,40,99;
  9.  
  10. CONST
  11.     nTypes = 5;
  12.     Alpha = 30;
  13.     Beta = 25;
  14.     dik = 0.85;
  15.     k1 = 0.75;
  16.     k2 = 0.88;
  17.     k3 = 0.60;
  18.     k4 = 0.866;
  19.  
  20.     Filename1 = 'NutHexE.txt';
  21.     Filename2 = 'NutHJamE.txt';
  22.     Filename3 = 'NutSqarE.txt';
  23.     Filename4 = 'NutSlotE.txt';
  24.     Filename5 = 'NutM.txt';
  25.     PathNameW = 'External\Data\';
  26.     PathNameM = ':Externals:External Data:';
  27.  
  28. VAR
  29.     a,b,c,d,e1,e2,f,g,di,j,h,m,s,t : REAL;
  30.     x0,y0,UPI,SF : REAL;
  31.     f1,h1,t1,s1 : ARRAY[1..6] OF REAL;
  32.  
  33.     i,Class,Index,Type,View,Fmt,PathLength : INTEGER;
  34.     nClasses : ARRAY[1..nTypes] OF INTEGER;
  35.     RFlag : ARRAY[1..3] OF INTEGER;
  36.  
  37.     Sz,Size,Size1,PathName : STRING;
  38.  
  39.     UM,UM2 : STRING;
  40.     Abort,Inch,Mac,SizeNotFound : BOOLEAN;
  41.     UName,DA : LONGINT;
  42.  
  43. Procedure NutDialog;
  44. {
  45. This procedure defines the dialog box.
  46. }
  47. VAR
  48.     Width,x1,y1,x2,y2,px1,px2,px3,px4,py1,py2,py3,py4 : INTEGER;
  49.  
  50. Procedure AlignScr(Width:INTEGER; VAR x1,x2:INTEGER);
  51. VAR
  52.     scrx1,scry1,scrx2,scry2:INTEGER;
  53. BEGIN
  54.     GetScreen(scrx1,scry1,scrx2,scry2);
  55.     x1:=((scrx1+scrx2) div 2)-(Width div 2);
  56.     x2:=x1+Width; 
  57. END;
  58.  
  59. Procedure LocateButtons(DialogType,scnh,scnw : INTEGER);
  60. {
  61. This procedure locates the 'OK' and 'Cancel' buttons.
  62. }
  63. VAR
  64.     v1,v2,v3,v4 : INTEGER;
  65.  
  66. Procedure Swap(VAR  m1,m2,m3,m4 : INTEGER);
  67. VAR
  68.     Temp : INTEGER;
  69.  
  70. BEGIN
  71.     Temp:=m1;
  72.     m1:=m3;
  73.     m3:=Temp;
  74.     Temp:=m2;
  75.     m2:=m4;
  76.     m4:=Temp;
  77. END;        {of Swap}
  78.  
  79. BEGIN
  80.     Mac:=FALSE;
  81.     PathName:=PathNameW;
  82.     GetVersion(v1,v2,v3,v4);
  83.     IF v4 = 1 THEN
  84.     BEGIN
  85.         Mac:=TRUE;
  86.         PathName:=PathNameM;
  87.     END;
  88.  
  89.     IF DialogType = 1 THEN
  90.     BEGIN
  91.         px1:=(scnw DIV 2) - 80;
  92.         px2:=(scnw DIV 2) - 10;
  93.         px3:=(scnw DIV 2) + 10;
  94.         px4:=(scnw DIV 2) + 80;
  95.         IF Mac THEN SWAP(px1,px2,px3,px4);
  96.  
  97.         py1:=scnh-40;
  98.         py2:=scnh-20;
  99.         py3:=py1;
  100.         py4:=py2;
  101.     END ELSE IF DialogType = 2 THEN
  102.     BEGIN
  103.         px1:=scnw - 180;
  104.         px2:=scnw - 110;
  105.         px3:=scnw - 90;
  106.         px4:=scnw - 20;
  107.         IF Mac THEN SWAP(px1,px2,px3,px4);
  108.  
  109.         py1:=scnh-40;
  110.         py2:=scnh-20;
  111.         py3:=py1;
  112.         py4:=py2;
  113.     END ELSE
  114.     BEGIN
  115.         px1:=scnw - 90;
  116.         px2:=scnw - 20;
  117.         px3:=px1;
  118.         px4:=px2;
  119.  
  120.         py1:=scnh -70;
  121.         py2:=scnh - 50;
  122.         py3:=scnh - 40;
  123.         py4:=scnh - 20;
  124.         IF Mac THEN SWAP(py1,py2,py3,py4);
  125.     END;
  126. END;        {of Locate Buttons}
  127.  
  128. Procedure MakeDialog1;
  129. {
  130. This procedure defines the main dialog box.
  131. }
  132. CONST
  133.     y1=100;
  134.     scnh = 260;
  135.     scnw =480;
  136.     DialogType = 3;
  137.  
  138.     VAR
  139.         g,h : INTEGER;
  140. BEGIN
  141.     AlignScr(scnw,x1,x2);
  142.     y2:=y1+scnh;
  143.     LocateButtons(DialogType,scnh,scnw);
  144.  
  145.     BeginDialog(1,1,x1,y1,x2,y2);
  146.         AddButton('OK',1,1,px1,py1,px2,py2);
  147.         AddButton('Cancel',2,1,px3,py3,px4,py4);
  148.  
  149.         g:=0; h:=5;
  150.         AddField('Type of Nut (Inch Series):',5,1,20,h-1,265,15+h);
  151.  
  152.         AddField('Hex:',20,1,20,19+h,145,35+h);
  153.         AddButton('Regular',30,3,20,40+h,110,55+h);
  154.         AddButton('Heavy',31,3,20,60+h,110,75+h);
  155.         AddButton('Thick',32,3,20,80+h,110,95+h);
  156.         AddButton('Flat',33,3,20,100+h,110,115+h);
  157.         AddButton('Heavy Flat',34,3,20,120+h,120,135+h);
  158.         AddButton('Machine Screw',35,3,20,140+h,140,155+h);
  159.  
  160.         g:=125;h:=5;
  161.         AddField('Hex Jam:',21,1,20+g,19+h,145+g,35+h);
  162.         AddButton('Regular',36,3,20+g,40+h,110+g,55+h);
  163.         AddButton('Heavy',37,3,20+g,60+h,110+g,75+h);
  164.         AddButton('Flat',38,3,20+g,80+h,110+g,95+h);
  165.         AddButton('Heavy Flat',39,3,20+g,100+h,120+g,115+h);
  166.  
  167.         g:=0;h:=150;
  168.         AddField('Square:',22,1,20+g,19+h,145+g,35+h);
  169.         AddButton('Regular',40,3,20+g,40+h,110+g,55+h);
  170.         AddButton('Heavy',41,3,20+g,60+h,110+g,75+h);
  171.         AddButton('Machine Screw',42,3,20+g,80+h,140+g,95+h);
  172.  
  173.         g:=125;h:=150;
  174.         AddField('Slotted:',23,1,20+g,19+h,145+g,35+h);
  175.         AddButton('Regular',43,3,20+g,40+h,110+g,55+h);
  176.         AddButton('Heavy',44,3,20+g,60+h,110+g,75+h);
  177.         AddButton('Thick',45,3,20+g,80+h,110+g,95+h);
  178.  
  179.         g:=250; h:=5;
  180.         AddField('Type of Nut (Metric Series)',6,1,20+g,h-1,265+g,15+h);
  181.  
  182.         AddButton('Hex, Style 1',46,3,20+g,20+h,120+g,35+h);
  183.         AddButton('Hex, Style 2',47,3,20+g,40+h,120+g,55+h);
  184.         AddButton('Hex Jam',48,3,20+g,60+h,110+g,75+h);
  185.         AddButton('Heavy Hex',49,3,20+g,80+h,110+g,95+h);
  186.         AddButton('Slotted',50,3,20+g,100+h,100+g,115+h);
  187.  
  188.         g:=250;h:=170;
  189.         AddField('View:',9,1,20+g,h-1,70+g,15+h);
  190.         AddButton('Top',10,3,20+g,20+h,70+g,35+h);
  191.         AddButton('Front',11,3,20+g,40+h,75+g,55+h);
  192.         AddButton('Side',12,3,20+g,60+h,70+g,75+h);
  193.  
  194.         g:=250;h:=140;
  195.         AddField('Size:',13,1,20+g,h-1,50+g,15+h);
  196.         AddField('',16,2,55+g,h,125+g,15+h);
  197.         AddField('in',18,1,133+g,h-1,160+g,15+h);
  198.     EndDialog;
  199. END;
  200.  
  201. BEGIN
  202.     MakeDialog1;
  203. END;
  204.  
  205. Procedure GetData;
  206. {
  207. This procedure opens the data file and reads the data.
  208. }
  209. LABEL 15,20,99;
  210.  
  211. VAR
  212.     k : INTEGER;
  213.     Filename,FileS,WarningStr : STRING;
  214.     File : ARRAY[1..nTypes] OF STRING;
  215.  
  216. BEGIN
  217.     File[1]:=Filename1;
  218.     File[2]:=Filename2;
  219.     File[3]:=Filename3;
  220.     File[4]:=Filename4;
  221.     File[5]:=Filename5;
  222.     FileS:=File[Type];
  223.  
  224.     Filename:=Concat(Pathname,FileS);
  225.     Open(Filename);
  226.  
  227.     IF FndError THEN
  228.     BEGIN
  229.         ClrDialog;
  230.         Sysbeep;
  231.         WarningStr:=Concat('The data file <',FileS,'> cannot be found. Check your Toolkit Manual for further explanation.');
  232.         AlrtDialog(WarningStr);
  233.         Abort:=TRUE;
  234.         GoTo 99;
  235.     END;
  236.  
  237.     SizeNotFound:=FALSE;
  238.     WHILE NOT EOF(Filename) DO
  239.     BEGIN
  240.         k:=0;
  241.         Read(Sz,d);
  242.         REPEAT
  243.             k:=k+1;
  244.             IF Type <> 4 THEN
  245.                 Read(f1[k], h1[k])
  246.             ELSE
  247.                 Read(f1[k], h1[k], t1[k], s1[k]);
  248.         UNTIL  k = nClasses[Type];
  249.  
  250.         IF Type = 5 THEN
  251.             Read(t1[k], s1[k]);
  252.  
  253.         IF Sz = Size THEN GOTO 20;
  254.     END;
  255.  
  256.     Close(Filename);
  257.     15:SysBeep;
  258.     AlrtDialog('That size is not available!');
  259.     SizeNotFound:=TRUE;
  260.     GoTo 99;
  261.  
  262.     20:Close(Filename);
  263.     f:=f1[Class];
  264.     h:=h1[Class];
  265.     t:=t1[Class];
  266.     s:=s1[Class];
  267.     IF f = 0 THEN GoTo 15;
  268.  
  269. 99:END;
  270.  
  271. Procedure GetInfo;
  272. {
  273. This procedure displays the main dialog box and retrieves the information.
  274. }
  275. LABEL 5,10,20,99;
  276. VAR
  277.     Done : BOOLEAN;
  278.     j,k,n,Item : INTEGER;
  279.  
  280. Procedure SetRButton(i,Item : INTEGER);
  281. BEGIN
  282.     IF RFlag[i] <> Item THEN BEGIN
  283.         SetItem(RFlag[i],FALSE);
  284.         SetItem(Item,TRUE);
  285.         RFlag[i]:=Item;
  286.     END;
  287. END;
  288.  
  289. BEGIN
  290.     5:Done:=FALSE;
  291.     Abort:=FALSE;
  292.     
  293.     Index:=1;
  294.     View:=1;
  295.     Inch:=TRUE;
  296.     RFlag[1]:=Index+29;
  297.     RFlag[2]:=View+9;
  298.  
  299.     GetDialog(1);
  300.     SetTitle('Hex & Square Nuts');
  301.     SetItem(RFlag[1],TRUE);
  302.     SetItem(RFlag[2],TRUE);
  303.     SetField(16,'3/4');
  304.  
  305.     10:SelField(16);
  306.     REPEAT
  307.         DialogEvent(Item);
  308.         IF Item=1 THEN
  309.             Done:=True;
  310.  
  311.         IF Item=2 THEN
  312.         BEGIN
  313.             Done:=TRUE;
  314.             Abort:=TRUE;
  315.         END;
  316.  
  317.         IF (Item > 9) AND (Item < 13) THEN
  318.         BEGIN
  319.             SetRButton(2,Item);
  320.             View:=Item-9;            
  321.         END;
  322.  
  323.         IF (Item >= 30) AND (Item <= 50) THEN
  324.         BEGIN
  325.             SetRButton(1,Item);
  326.             Index:=Item-29;
  327.             IF Index > 16 THEN
  328.             BEGIN
  329.                 Inch:=FALSE;
  330.                 SetField(18, 'mm');
  331.             END ELSE
  332.             BEGIN
  333.                 Inch:=TRUE;
  334.                 SetField(18, 'in');
  335.             END;
  336.         END;
  337.  
  338.     UNTIL Done;
  339.  
  340.     IF Abort THEN GOTO 99;
  341.     Size1:=GetField(16);
  342.     Size:=Concat('''',Size1,'''');
  343.     UprString(Size);
  344.  
  345. {
  346. Determine the Type and Class of the nut.
  347. }
  348.  
  349.     j:=0;
  350.     FOR n:=1 TO 5 DO
  351.     BEGIN
  352.         k:=n;
  353.         j:=j + nClasses[n];
  354.         IF Index <= j THEN
  355.         BEGIN
  356.             Type:=n;
  357.             Class:=Index - j + nClasses[k];
  358.             GOTO 20;
  359.         END;
  360.     END;
  361.     GOTO 99;
  362.  
  363. {
  364. Open the data file and get the dimensions of the nut.
  365. }
  366.  
  367.     20:GetData;
  368.     IF Abort THEN GOTO 99;
  369.     IF SizeNotFound THEN
  370.     BEGIN
  371.         Done:=FALSE;
  372.         GOTO 10;
  373.     END;
  374.  
  375.     99:ClrDialog;
  376. END;
  377.  
  378. Procedure DrawTopView(Type : INTEGER);
  379. {
  380. This procedure draws the top view of the nut.
  381. }
  382. VAR
  383.     r1, x1, y1, x2, y2, Theta, Theta1, Theta2, Theta3 : REAL;
  384.  
  385. BEGIN
  386.     Absolute;
  387.     MoveTo(x0,y0);
  388.     Relative;
  389.     IF Type <> 3 THEN
  390.     BEGIN
  391.         Move(g/2,0);
  392.         ClosePoly;
  393.         Poly(0,0,a,#-120,a,#-180,a,#120,a,#60,a,#0);
  394.         Absolute;
  395.         MoveTo(x0,y0);
  396.         Relative;
  397.         IF (Type = 4) OR ((Type = 5)AND(Class = 5)) THEN
  398.         BEGIN
  399.             Theta1:=Rad2Deg(ArcSin(s/f));
  400.             Theta:=30;
  401.             REPEAT
  402.                 Arc(-f/2,f/2,f/2,-f/2,Theta+Theta1,60-2*Theta1);
  403.                 Theta:=Theta+60;
  404.             UNTIL Theta > 360;
  405.         END ELSE
  406.             Arc(-f/2,f/2,f/2,-f/2,0,360);    
  407.     END
  408.     ELSE BEGIN
  409.         Rect(-f/2,f/2,f/2,-f/2);
  410.         IF Class <> 3 THEN
  411.             Arc(-f/2,f/2,f/2,-f/2,0,360)
  412.     END;
  413.  
  414.     PushAttrs;
  415.     PenSize(1);
  416.     PenPat(-2);
  417.     Arc(-d/2,d/2,d/2,-d/2,0,360);
  418.     PopAttrs;
  419.     Arc(-di/2,di/2,di/2,-di/2,0,360);
  420.  
  421.     IF (Type = 4) OR ((Type = 5)AND(Class = 5)) THEN
  422.     BEGIN
  423.         r1:=Sqrt((s/2)^2 + (f/2)^2);
  424.         Theta2:=ArcSin(s/di);
  425.         Theta3:=ArcTan(s/f);
  426.         Theta:=0;
  427.         Absolute;
  428.         REPEAT
  429.             x1:=di*Sin(Theta+Theta2)/2;
  430.             y1:=di*Cos(Theta+Theta2)/2;
  431.             x2:=r1*Sin(Theta+Theta3);
  432.             y2:=r1*Cos(Theta+Theta3);
  433.             MoveTo(x0-x1, y0-y1);
  434.             LineTo(x0-x2, y0-y2);
  435.             MoveTo(x0+x1, y0-y1);
  436.             LineTo(x0+x2, y0-y2);
  437.             Theta:=Theta + Pi/3;
  438.         UNTIL Theta > 2*Pi;
  439.     END;
  440. END;
  441.  
  442. Procedure DrawFrontView(Type : INTEGER);
  443. {
  444. This procedure draws the front view of the nut.
  445. }
  446. LABEL 10, 20, 30;
  447.  
  448. BEGIN
  449.     Absolute;
  450.     MoveTo(x0-g/2, y0+h);
  451.     Relative;
  452.  
  453. {
  454. Regular hex nuts.
  455. }
  456.  
  457.     IF (Type = 1) OR (Type = 2) OR ((Type = 5)AND(Class <> 5))THEN
  458.     BEGIN
  459.         Move(0, -e1);
  460.         ClosePoly;
  461.         BeginPoly;
  462.             LineTo(0, 0);
  463.             LineTo(m, e1);
  464.             LineTo(f, 0);
  465.             LineTo(m, -e1);
  466.             LineTo(0, -c);
  467.             IF e2 <> 0 THEN
  468.             BEGIN
  469.                 LineTo(-m, -e2);
  470.                 LineTo(-f, 0);
  471.                 LineTo(-m, e2);
  472.             END ELSE
  473.                 LineTo(-g, 0);
  474.         EndPoly;
  475.         Move(0, c);
  476.         OpenPoly;
  477.         BeginPoly;
  478.             LineTo(0,0);
  479.             CurveThrough(b/2, e1);
  480.             LineTo(b/2, -e1);
  481.             CurveThrough(a/2, e1);
  482.             LineTo(a/2, -e1);
  483.             CurveThrough(b/2, e1);
  484.             LineTo(b/2, -e1);
  485.         EndPoly;
  486.         IF e2 = 0 THEN GOTO 10;
  487.         Move(-g, -c);
  488.         OpenPoly;
  489.         BeginPoly;
  490.             LineTo(0,0);
  491.             CurveThrough(b/2, -e2);
  492.             LineTo(b/2, e2);
  493.             CurveThrough(a/2, -e2);
  494.             LineTo(a/2, e2);
  495.             CurveThrough(b/2,- e2);
  496.             LineTo(b/2, e2);
  497.         EndPoly;
  498.         10:Absolute;
  499.         MoveTo(x0-a/2, y0+(h-e1));
  500.         Relative;
  501.         LineTo(0,- c);
  502.         Move(a, 0);
  503.         LineTo(0, c);
  504.     END
  505.  
  506. {
  507. Slotted nuts.
  508. }
  509.  
  510.     ELSE IF (Type = 4) OR ((Type = 5)AND(Class = 5)) THEN
  511.     BEGIN
  512.         Move(0, -e1);
  513.         ClosePoly;
  514.         BeginPoly;
  515.             LineTo(0, 0);
  516.             LineTo(m, e1);
  517.             LineTo((f-s)/2, 0);
  518.             ArcTo(0, -(h-t), s/2);
  519.             ArcTo(s, 0, s/2);
  520.             LineTo(0, (h-t));
  521.             LineTo((f-s)/2, 0);
  522.             LineTo(m, -e1);
  523.             LineTo(0, -c);
  524.             IF e2 <> 0 THEN
  525.             BEGIN
  526.                 LineTo(-m, -e2);
  527.                 LineTo(-f, 0);
  528.                 LineTo(-m, e2);
  529.             END ELSE
  530.                 LineTo(-g, 0);
  531.         EndPoly;
  532.  
  533.         Move(0, c);
  534.         OpenPoly;
  535.         BeginPoly;
  536.             LineTo(0,0);
  537.             CurveThrough((b-s/2)/4, k3*k2*e1);
  538.             LineTo((b-s/2)/4, (1-k3)*k2*e1);
  539.         EndPoly;
  540.  
  541.         MoveTo(s/2, 0);
  542.         BeginPoly;
  543.             LineTo(0,0);
  544.             CurveThrough((b-s/2)/4, -(1-k3)*k2*e1);
  545.             LineTo((b-s/2)/4, -k3*k2*e1);
  546.             CurveThrough((a-s)/4, k1*e1);
  547.             LineTo((a-s)/4, (1-k1)*e1);
  548.         EndPoly;
  549.  
  550.         MoveTo(s, 0);
  551.         BeginPoly;
  552.             LineTo(0, 0);
  553.             CurveThrough((a-s)/4, -(1-k1)*e1);
  554.             LineTo((a-s)/4, -k1*e1);
  555.             CurveThrough((b-s/2)/4, k3*k2*e1);
  556.             LineTo((b-s/2)/4, (1-k3)*k2*e1);
  557.         EndPoly;
  558.  
  559.         MoveTo(s/2, 0);
  560.         BeginPoly;
  561.             LineTo(0,0);
  562.             CurveThrough((b-s/2)/4, -(1-k3)*k2*e1);
  563.             LineTo((b-s/2)/4, -k3*k2*e1);
  564.         EndPoly;
  565.  
  566.         IF e2 = 0 THEN GOTO 10;
  567.         Move(-g, -c);
  568.         OpenPoly;
  569.         BeginPoly;
  570.             LineTo(0,0);
  571.             CurveThrough(b/2, -e2);
  572.             LineTo(b/2, e2);
  573.             CurveThrough(a/2, -e2);
  574.             LineTo(a/2, e2);
  575.             CurveThrough(b/2,- e2);
  576.             LineTo(b/2, e2);
  577.         EndPoly;
  578.         10:Absolute;
  579.         MoveTo(x0-a/2, y0+(h-e1));
  580.         Relative;
  581.         LineTo(0,- c);
  582.         Move(a, 0);
  583.         LineTo(0, c);
  584.  
  585.         Absolute;
  586.         MoveTo(x0 - (a+b+s/2)/2, y0+h);
  587.         Relative;
  588.         LineTo(0, -(h-t-s/2));
  589.         MoveTo(s/4, 0);
  590.         Arc(-s/4, s/2, s/4, -s/2, 180, 180);
  591.         MoveTo(s/4, 0);
  592.         LineTo(0, (h-t-s/2));
  593.  
  594.         Absolute;
  595.         MoveTo(x0 + (a+b-s/2)/2, y0+h);
  596.         Relative;
  597.         LineTo(0, -(h-t-s/2));
  598.         MoveTo(s/4, 0);
  599.         Arc(-s/4, s/2, s/4, -s/2, 180, 180);
  600.         MoveTo(s/4, 0);
  601.         LineTo(0, (h-t-s/2));
  602.     END
  603.  
  604. {
  605. Square nuts.
  606. }
  607.  
  608.     ELSE BEGIN
  609.         Move(0, -e1);
  610.         IF Class = 3 THEN GOTO 20;
  611.         ClosePoly;
  612.         BeginPoly;
  613.             LineTo(0, 0);
  614.             LineTo(m, e1);
  615.             LineTo(f, 0);
  616.             LineTo(m, -e1);
  617.             LineTo(0, -c);
  618.             IF e2 <> 0 THEN
  619.             BEGIN
  620.                 LineTo(-m, -e2);
  621.                 LineTo(-f, 0);
  622.                 LineTo(-m, e2);
  623.             END ELSE
  624.                 LineTo(-g, 0);
  625.         EndPoly;
  626.         Move(0, c);
  627.         OpenPoly;
  628.         BeginPoly;
  629.             LineTo(0,0);
  630.             CurveThrough(b/2, e1);
  631.             LineTo(b/2, -e1);
  632.             CurveThrough(b/2, e1);
  633.             LineTo(b/2, -e1);
  634.         EndPoly;
  635.         IF e2 = 0 THEN GOTO 30;
  636.         Move(-g, -c);
  637.         OpenPoly;
  638.         BeginPoly;
  639.             LineTo(0,0);
  640.             CurveThrough(b/2, -e2);
  641.             LineTo(b/2, e2);
  642.             CurveThrough(b/2,- e2);
  643.             LineTo(b/2, e2);
  644.         EndPoly;
  645.         GOTO 30;
  646.         20:Rect(0, 0, g, -h);
  647.         30:Absolute;
  648.         MoveTo(x0-a/2, y0+(h-e1));
  649.         Relative;
  650.         LineTo(0,- c);
  651.     END;
  652. END;
  653.  
  654. Procedure DrawSideView(Type:INTEGER);
  655. {
  656. This procedure draws the side view of the nut.
  657. }
  658. LABEL 10, 20;
  659.  
  660. BEGIN
  661.     Absolute;
  662.     MoveTo(x0-f/2, y0+h);
  663.     Relative;
  664.     Rect(0, 0, f, -h);
  665.  
  666. {
  667. Regular hex nuts.
  668. }
  669.  
  670.     IF (Type = 1) OR (Type = 2) OR ((Type = 5)AND(Class <> 5)) THEN
  671.     BEGIN
  672.         Move(0, -e1);
  673.         OpenPoly;
  674.         BeginPoly;
  675.             LineTo(0,0);
  676.             CurveThrough(f/4, e1);
  677.             LineTo(f/4, -e1);
  678.             CurveThrough(f/4, e1);
  679.             LineTo(f/4, -e1);
  680.         EndPoly;
  681.         IF e2 = 0 THEN GOTO 10;
  682.         Move(-f, -c);
  683.         OpenPoly;
  684.         BeginPoly;
  685.             LineTo(0,0);
  686.             CurveThrough(f/4, -e2);
  687.             LineTo(f/4, e2);
  688.             CurveThrough(f/4, -e2);
  689.             LineTo(f/4, e2);
  690.         EndPoly;
  691.         10:Absolute;
  692.         MoveTo(x0, y0+(h-e1));
  693.         Relative;
  694.         LineTo(0,- c);
  695.     END
  696.  
  697. {
  698. Slotted hex nuts.
  699. }
  700.  
  701.     ELSE IF (Type = 4) OR ((Type = 5)AND(Class = 5)) THEN
  702.     BEGIN
  703.         MoveTo((f/2 - k4*s)/2, 0);
  704.         ClosePoly;
  705.         BeginPoly;
  706.             LineTo(0, 0);
  707.             LineTo(0, -(h-t-s/2));
  708.             MoveTo(k4*s/2, 0);
  709.             Arc(-k4*s/2, s/2, k4*s/2, -s/2, 180, 180);
  710.             MoveTo(k4*s/2, 0);
  711.             LineTo(0, (h-t-s/2));
  712.         EndPoly;
  713.  
  714.         MoveTo((f/2 - k4*s), 0);
  715.         BeginPoly;
  716.             LineTo(0, 0);
  717.             LineTo(0, -(h-t-s/2));
  718.             MoveTo(k4*s/2, 0);
  719.             Arc(-k4*s/2, s/2, k4*s/2, -s/2, 180, 180);
  720.             MoveTo(k4*s/2, 0);
  721.             LineTo(0, (h-t-s/2));
  722.         EndPoly;
  723.  
  724.         Absolute;
  725.         MoveTo((x0 - f/2), (y0 + h - e1));
  726.         Relative;
  727.         OpenPoly;
  728.         BeginPoly;
  729.             LineTo(0,0);
  730.             CurveThrough((f/2 - k4*s)/4, k3*k2*e1);
  731.             LineTo((f/2 - k4*s)/4, (1-k3)*k2*e1);
  732.         EndPoly;
  733.  
  734.         Move(k4*S, 0);
  735.         BeginPoly;
  736.             LineTo(0,0);
  737.             CurveThrough((f/2 - k4*s)/4, -(1-k3)*k2*e1);
  738.             LineTo((f/2 - k4*s)/4, -k3*k2*e1);
  739.             CurveThrough((f/2 - k4*s)/4, k3*k2*e1);
  740.             LineTo((f/2 - k4*s)/4, (1-k3)*k2*e1);
  741.         EndPoly;
  742.  
  743.         Move(k4*S, 0);
  744.         BeginPoly;
  745.             LineTo(0,0);
  746.             CurveThrough((f/2 - k4*s)/4, -(1-k3)*k2*e1);
  747.             LineTo((f/2 - k4*s)/4, -k3*k2*e1);
  748.         EndPoly;
  749.  
  750.         IF e2 = 0 THEN GOTO 10;
  751.         Move(-f, -c);
  752.         OpenPoly;
  753.         BeginPoly;
  754.             LineTo(0,0);
  755.             CurveThrough(f/4, -e2);
  756.             LineTo(f/4, e2);
  757.             CurveThrough(f/4, -e2);
  758.             LineTo(f/4, e2);
  759.         EndPoly;
  760.         10:Absolute;
  761.         MoveTo(x0, y0+(h-e1));
  762.         Relative;
  763.         LineTo(0,- c);
  764.     END
  765.  
  766. {
  767. Square nuts.
  768. }
  769.  
  770.     ELSE BEGIN;
  771.         IF Class = 3 THEN GOTO 20;
  772.         Move(0, -e1);
  773.         OpenPoly;
  774.         BeginPoly;
  775.             LineTo(0,0);
  776.             CurveThrough(f/2, e1);
  777.             LineTo(f/2, -e1);
  778.         EndPoly;
  779.         IF e2 = 0 THEN GOTO 20;
  780.         Move(-f, -c);
  781.         OpenPoly;
  782.         BeginPoly;
  783.             LineTo(0,0);
  784.             CurveThrough(f/2, -e2);
  785.             LineTo(f/2, e2);
  786.         EndPoly;
  787.     20:END;
  788. END;
  789.  
  790. {
  791. Main program.
  792. }
  793. BEGIN
  794.     DselectAll;
  795.     PushAttrs;
  796.     NutDialog;
  797.  
  798. {
  799. Set the number of classes for each type of nut.
  800. }
  801.  
  802.     nClasses[1]:=6;
  803.     nClasses[2]:=4;
  804.     nClasses[3]:=3;
  805.     nClasses[4]:=3;
  806.     nClasses[5]:=5;
  807.  
  808. {
  809. Display the main dialog box and get the information.
  810. }
  811.  
  812.     SetCursor(ArrowC);
  813.     GetInfo;
  814.     IF Abort THEN GOTO 99;
  815.  
  816. {
  817. Get the location of the nut.
  818. }
  819.  
  820.     GetPt(x0,y0);
  821.  
  822. {
  823. Get units per inch and adjust variables accordingly.
  824. }
  825.  
  826.     GetUnits(UName,DA,Fmt,UPI,UM,UM2);
  827.     IF Inch=TRUE THEN
  828.         SF:=UPI
  829.     ELSE
  830.         SF:=UPI/25.4;
  831.  
  832.     d:=d*SF;
  833.     f:=f*SF;
  834.     h:=h*SF;
  835.     t:=t*SF;
  836.     s:=s*SF;
  837.  
  838. {
  839. Calculate additional variables needed to draw nut.
  840. }
  841.  
  842.     IF Type <>3 THEN
  843.     BEGIN
  844.         a:=f*Tan(Pi/6);
  845.         g:=f/Cos(Pi/6);
  846.         b:=(g-a)/2;
  847.         e1:=(g-f)*Tan(Deg2Rad(Alpha))/2;
  848.         IF ((Type=1)AND((Class=4)OR(Class=5))) OR ((Type = 2)AND(Class>2)) THEN
  849.             e2:=0
  850.         ELSE
  851.             e2:=e1;
  852.     END ELSE
  853.  
  854.     BEGIN
  855.         a:=0;
  856.         g:=f/Cos(Pi/4);
  857.         b:=(g-a)/2;
  858.         IF Class <> 3 THEN
  859.             e1:=(g-f)*Tan(Deg2Rad(Beta))/2
  860.         ELSE
  861.             e1:=0;
  862.         e2:=e1;
  863.     END;
  864.  
  865.     di:=dik*d;
  866.     c:=h - (e1+e2);
  867.     m:=(g-f)/2;
  868.  
  869. {
  870. Draw nut.
  871. }
  872.  
  873.     IF View = 1 THEN
  874.         DrawTopView(Type)
  875.     ELSE IF View = 2 THEN
  876.         DrawFrontView(Type)
  877.     ELSE
  878.         DrawSideView(Type);
  879.     Group;
  880.     PopAttrs;
  881.  
  882. 99:END;
  883.  
  884. Run(DrawNut);
  885.