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

  1. Procedure TaperPin;
  2. {
  3.  
  4. ⌐1997, Diehl Graphsoft, Inc.
  5. Developed by Tom Urie
  6.  
  7. This procedure draws a taper pin.
  8. }
  9.  
  10. LABEL 10,20,30,90,99;
  11.  
  12. CONST
  13.     Filename1= 'TaprPinE.txt';
  14.     PathnameW = 'External\Data\';
  15.  
  16.     Theta=0.59681;  {Angle of taper in degrees (1/4" per foot).}
  17.  
  18. VAR
  19.     D1,D2,L,Lmin,Lmax,x0,y0 : REAL;
  20.     Phi1,Phi2,RH1,RH2,Y1,Y2 : REAL;
  21.  
  22.     View : INTEGER;
  23.  
  24.     FileName,Sz,Size,Size1 : STRING;
  25.     Abort ,FirstTime,SizeNotFound : BOOLEAN;
  26.  
  27.     UPI : REAL;
  28.     Fmt : INTEGER;
  29.     UM,UM2 : STRING;
  30.     UName,DA : LONGINT;
  31.  
  32. Procedure PinDialog;
  33. VAR
  34.     Width,x1,y1,x2,y2,px1,px2,px3,px4,py1,py2,py3,py4 : INTEGER;
  35.  
  36. Procedure AlignScr(Width:INTEGER; VAR x1,x2:INTEGER);
  37. VAR
  38.     scrx1,scry1,scrx2,scry2:INTEGER;
  39. BEGIN
  40.     GetScreen(scrx1,scry1,scrx2,scry2);
  41.     x1:=((scrx1+scrx2) div 2)-(Width div 2);
  42.     x2:=x1+Width; 
  43. END;
  44.  
  45. Procedure LocateButtons1(scnh,scnw : INTEGER);
  46. {
  47. This procedure locates the 'OK' and 'Cancel' buttons centered at the bottom of the dialog box.
  48. }
  49. VAR
  50.     v1,v2,v3,v4 : INTEGER;
  51.  
  52. Procedure Swap(VAR  m1,m2,m3,m4 : INTEGER);
  53. VAR
  54.     Temp : INTEGER;
  55. BEGIN
  56.     Temp:=m1;
  57.     m1:=m3;
  58.     m3:=Temp;
  59.     Temp:=m2;
  60.     m2:=m4;
  61.     m4:=Temp;
  62. END;        {of Swap}
  63.  
  64. BEGIN
  65.     px1:=(scnw DIV 2) - 80;
  66.     px2:=(scnw DIV 2) - 10;
  67.     px3:=(scnw DIV 2) + 10;
  68.     px4:=(scnw DIV 2) + 80;
  69.  
  70.     py1:=scnh-40;
  71.     py2:=scnh-20;
  72.     py3:=py1;
  73.     py4:=py2;
  74.  
  75.     GetVersion(v1,v2,v3,v4);
  76.     IF v4 = 1 THEN
  77.         Swap(px1,px2,px3,px4); 
  78.  
  79. END;        {of Locate Buttons1}
  80.  
  81. Procedure MakeDialog1;
  82. {
  83. This procedure defines the main dialog box.
  84. }
  85. CONST
  86.     y1=100;
  87.     scnh=135;
  88.     scnw=280;
  89.     h=30;
  90. BEGIN
  91.     AlignScr(scnw,x1,x2);
  92.     y2:=y1+scnh;
  93.     LocateButtons1(scnh,scnw );
  94.  
  95.     BeginDialog(1,1,x1,y1,x2,y2);
  96.         AddButton('OK',1,1,px1,py1,px2,py2);
  97.         AddButton('Cancel',2,1,px3,py3,px4,py4);
  98.  
  99.         AddField('Pin Size#:',4,1,20,44-h,95,60-h);
  100.         AddField('2/0',5,2,100,45-h,160,60-h);
  101.  
  102.         AddField('Length:',6,1,20,79-h,85,95-h);
  103.         AddField('',7,2,100,80-h,160,95-h);
  104.  
  105.         AddField('View:',8,1,190,39-h,245,55-h);
  106.         AddButton('Top',9,3,190,80-h,245,95-h);
  107.         AddButton('Side',10,3,190,60-h,245,75-h);
  108.     EndDialog;
  109. END;
  110.  
  111. BEGIN
  112.     MakeDialog1;
  113. END;
  114.  
  115. Procedure GetInfo;
  116. {
  117. This procedure displays the main dialog box and retrieves the information.
  118. }
  119. LABEL 10,99;
  120.  
  121. VAR
  122.     Item : INTEGER;
  123.     RFlag : ARRAY[1..2] OF INTEGER;
  124.     Done : BOOLEAN;
  125.  
  126. Procedure SetRButton(i,Item : INTEGER);
  127. BEGIN
  128.     IF RFlag[i] <> Item THEN BEGIN
  129.         SetItem(RFlag[i],FALSE);
  130.         SetItem(Item,TRUE);
  131.         RFlag[i]:=Item;
  132.     END;
  133. END;
  134.  
  135. BEGIN
  136.     Done:=FALSE;
  137.     Abort:=FALSE;
  138.     IF NOT FirstTime THEN GOTO 10;
  139.  
  140.     FirstTime:=FALSE;
  141.     View:=2;
  142.     Size1:='2/0';
  143.     L:=1.000;
  144.     RFlag[1]:=10;
  145.  
  146.     GetDialog(1);
  147.     SetTitle('Taper Pins');
  148.     SetItem(RFlag[1],TRUE);
  149.     SetField(5,Size1);
  150.     SetField(7,Num2Str(3,L));
  151.     10:SelField(5);
  152.     REPEAT
  153.         DialogEvent(Item);
  154.         IF Item=1 THEN
  155.             Done:=True;
  156.  
  157.         IF Item=2 THEN
  158.         BEGIN
  159.             Done:=TRUE;
  160.             Abort:=TRUE;
  161.         END;
  162.  
  163.         IF (Item = 9) OR (Item = 10) THEN
  164.         BEGIN
  165.             SetRButton(1,Item);
  166.             View:=Item-8;
  167.         END;
  168.     UNTIL Done;
  169.     IF Abort THEN GOTO 99;
  170.     Size1:=GetField(5);
  171.     Size:=Concat('''',Size1,'''');
  172.     L:=Str2Num(GetField(7)); 
  173.  
  174. 99:END;
  175.  
  176. Procedure GetData;
  177. {
  178. This procedure reads the data file.
  179. }
  180. LABEL 15,20,99;
  181.  
  182. VAR
  183.     File,Filename,WarningStr : STRING;
  184.  
  185. BEGIN
  186.     File:=FileName1;
  187.     Filename:=Concat(PathnameW,File);
  188.     Open(Filename);
  189.  
  190.     IF FndError THEN BEGIN
  191.         ClrDialog;
  192.         Sysbeep;
  193.         WarningStr:=Concat('The data file <',File,'> cannot be found. Check your Toolkit Manual for further explanation.');
  194.         AlrtDialog(WarningStr);
  195.         Abort:=TRUE;
  196.         GoTo 99;
  197.     END;
  198.  
  199.     SizeNotFound:=FALSE;
  200.     WHILE NOT Eoln(Filename) DO BEGIN
  201.         ReadLn(Sz,D1,Lmin,Lmax);
  202.         IF Sz=Size THEN GoTo 20;
  203.     END;
  204.  
  205.     Close(Filename);
  206.     15:SysBeep;
  207.     AlrtDialog('That size is not available! ');
  208.     SizeNotFound:=TRUE;
  209.     GoTo 99;
  210.  
  211.     20:Close(Filename);
  212. 99:END;
  213.  
  214. {
  215. Main program.
  216. }
  217. BEGIN
  218.     DselectAll;
  219.     PinDialog;
  220.     SetCursor(ArrowC);
  221.  
  222. {
  223. Display the main dialog box and get the info.
  224. }
  225.  
  226.     FirstTime:=TRUE;
  227.     10:GetInfo;
  228.     IF Abort THEN GoTo 99;
  229.     GetData;
  230.     IF Abort THEN GoTo 99;
  231.     IF SizeNotFound THEN Goto 10;
  232.     ClrDialog;
  233.  
  234. {
  235. Get units per inch and adjust size accordingly.
  236. }
  237.  
  238.     GetUnits(UName,DA,Fmt,UPI,UM,UM2);
  239.     D1:=D1*UPI;
  240.     L:=L*UPI;
  241.  
  242. {
  243. Calculate variables needed to draw the taper pin.
  244. }
  245.  
  246.     D2:=D1-2*L*Tan(Deg2Rad(Theta));
  247.     Y1:=0.13397*D1;
  248.     RH1:=D1;
  249.     Phi1:=Rad2Deg(ArcSin((D1/2)/RH1));
  250.     Y2:=0.13397*D2;
  251.     RH2:=D2;
  252.     Phi2:=Rad2Deg(ArcSin((D2/2)/RH2));
  253.     GetPt(x0,y0);
  254.  
  255. {
  256. Draw Top View.
  257. }
  258.  
  259.     IF View=1 THEN BEGIN
  260.         Absolute;
  261.         MoveTo(x0,y0);
  262.         Relative;
  263.         Oval(-D1/2,D1/2,D1/2,-D1/2);
  264.         GOTO 99;
  265.     END;
  266.  
  267. {
  268. Draw Side View.
  269. }
  270.  
  271.     Absolute;
  272.     MoveTo(x0-Y1+RH1,y0);
  273.     Relative;
  274.     Arc(-RH1,RH1,RH1,-RH1,(180-Phi1),2*Phi1);
  275.     Absolute;
  276.     MoveTo(x0+L+Y2-RH2,y0);
  277.     Relative;
  278.     Arc(-RH2,RH2,RH2,-RH2,-Phi2,2*Phi2);
  279.     Absolute;
  280.     MoveTo(x0,y0-D1/2);
  281.     Relative;
  282.     ClosePoly;
  283.     BeginPoly;
  284.         LineTo(L,(D1-D2)/2);
  285.         LineTo(0,D2);
  286.         LineTo(-L,(D1-D2)/2);
  287.         LineTo(0,-D1);
  288.     EndPoly;
  289.     90:Group;
  290.  
  291. 99:END;
  292.  
  293. RUN(TaperPin);