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

  1. Procedure ClevisPin;
  2. {
  3. ⌐1997, Diehl Graphsoft, Inc.
  4. Developed by Tom Urie
  5.  
  6. This procedure draws a clevis pin using data from the file Clevis Pin data.
  7. }
  8.  
  9. LABEL 10,20,30,90,99;
  10. CONST
  11.     Filename1 = 'ClevPinE.txt';
  12.     Filename2 = 'ClevPinM.txt';
  13.     PathNameW = 'External\Data\';
  14.     PathNameM = 'Externals:External Data:';
  15.  
  16.     HF=1.25;
  17.     Lkc=1;
  18.  
  19. VAR
  20.     A,B,C,D,E,F,G,H,HD,HD1,S,L,L2,Lk,CL,x0,y0,SF : REAL;
  21.  
  22.     Type,View : INTEGER;
  23.  
  24.     Sz,Size,Size1,Pathname : STRING;
  25.     Abort,FirstTime,StdLgth,SizeNotFound : BOOLEAN;
  26.     UPI : REAL;
  27.  
  28.     Fmt : INTEGER;
  29.     UM,UM2 : STRING;
  30.     UName,DA : LONGINT;
  31.  
  32. Procedure PinDialog;
  33. {
  34. This procedure defines the dialog box.
  35. }
  36. VAR
  37.     Width,x1,y1,x2,y2,px1,px2,px3,px4,py1,py2,py3,py4 : INTEGER;
  38.  
  39. Procedure AlignScr(Width:INTEGER; VAR x1,x2:INTEGER);
  40. VAR
  41.     scrx1,scry1,scrx2,scry2:INTEGER;
  42. BEGIN
  43.     GetScreen(scrx1,scry1,scrx2,scry2);
  44.     x1:=((scrx1+scrx2) div 2)-(Width div 2);
  45.     x2:=x1+Width; 
  46. END;
  47.  
  48. Procedure LocateButtons1(scnh,scnw : INTEGER);
  49. {
  50. This procedure locates the 'OK' and 'Cancel' buttons centered at the bottom of the dialog box.
  51. }
  52. VAR
  53.     v1,v2,v3,v4 : INTEGER;
  54.  
  55. Procedure Swap(VAR  m1,m2,m3,m4 : INTEGER);
  56. VAR
  57.     Temp : INTEGER;
  58. BEGIN
  59.     Temp:=m1;
  60.     m1:=m3;
  61.     m3:=Temp;
  62.     Temp:=m2;
  63.     m2:=m4;
  64.     m4:=Temp;
  65. END;        {of Swap}
  66.  
  67. BEGIN
  68.     px1:=(scnw DIV 2) - 80;
  69.     px2:=(scnw DIV 2) - 10;
  70.     px3:=(scnw DIV 2) + 10;
  71.     px4:=(scnw DIV 2) + 80;
  72.  
  73.     py1:=scnh-40;
  74.     py2:=scnh-20;
  75.     py3:=py1;
  76.     py4:=py2;
  77.  
  78.     GetVersion(v1,v2,v3,v4);
  79.     IF v4 = 1 THEN
  80.     BEGIN
  81.         Swap(px1,px2,px3,px4);
  82.         PathName:=PathNameM;
  83.     END ELSE
  84.         PathName:=PathNameW;
  85.  
  86. END;        {of Locate Buttons1}
  87.  
  88. Procedure MakeDialog1;
  89. CONST
  90.     y1=100;
  91.     scnh = 235;
  92.     scnw = 280;
  93.  
  94. VAR
  95.     h : INTEGER;
  96.  
  97. BEGIN
  98.     AlignScr(scnw,x1,x2);
  99.     y2:=y1+scnh;
  100.     LocateButtons1(scnh,scnw);
  101.  
  102.     BeginDialog(1,1,x1,y1,x2,y2);
  103.         AddButton('OK',1,1,px1,py1,px2,py2);
  104.         AddButton('Cancel',2,1,px3,py3,px4,py4);
  105.  
  106.         h:=30;
  107.         AddField('Pin Dia:',5,1,20,89-h,70,105-h);
  108.         AddField('',6,2,75,90-h,140,105-h);
  109.         AddField('in',17,1,148,89-h,178,105-h);
  110.  
  111.         AddField('Series:',18,1,20,39-h,75,55-h);
  112.         AddButton('Inch',13,3,20,60-h,70,75-h);
  113.         AddButton('Metric',14,3,80,60-h,140,75-h);
  114.  
  115.         AddField('View:',10,1,190,39-h,245,55-h);
  116.         AddButton('Top',11,3,190,80-h,245,95-h);
  117.         AddButton('Side',12,3,190,60-h,245,75-h);
  118.  
  119.         h:=100;
  120.         AddField('Length:',19,1,20,h-1,100,h+15);
  121.         AddButton('Standard',7,3,20,h+20,100,h+35);
  122.         AddField('',15,1,105, h+19,145,h+35);
  123.  
  124.         AddButton('Custom:',8,3,20,h+40,100,h+55);
  125.         AddField('',9,2,105,h+40,175,h+55);
  126.         AddField('in',16,1,183,h+39,213,h+55);
  127.  
  128.     EndDialog;
  129. END;
  130.  
  131. BEGIN
  132.     MakeDialog1;
  133. END;
  134.  
  135. Procedure GetInfo;
  136. {
  137. This procedure displays the main dialog box and retrieves the information.
  138. }
  139. LABEL 15,20,99;
  140.  
  141. VAR
  142.     Item : INTEGER;
  143.     RFlag : ARRAY[1..3] OF INTEGER;
  144.     Done,Go : BOOLEAN;
  145.  
  146. Procedure SetRButton(i,Item : INTEGER);
  147. BEGIN
  148.     IF RFlag[i] <> Item THEN BEGIN
  149.         SetItem(RFlag[i],FALSE);
  150.         SetItem(Item,TRUE);
  151.         RFlag[i]:=Item;
  152.     END;
  153. END;
  154.  
  155. BEGIN
  156.     Done:=FALSE;
  157.     Abort:=FALSE;
  158.     IF NOT FirstTime THEN GOTO 15;
  159.     FirstTime:= FALSE;
  160.     Type:=1;
  161.     View:=2;
  162.     StdLgth:=TRUE;
  163.     RFlag[1]:=12;
  164.     RFlag[2]:=13;
  165.     RFlag[3]:=7;
  166.  
  167.     GetDialog(1);
  168.     SetTitle('Clevis Pins');
  169.     SetField(16,'in');
  170.     SetField(17,'in');
  171.  
  172.     SetItem(RFlag[1],TRUE);
  173.     SetItem(RFlag[2],TRUE);
  174.     SetItem(RFlag[3],TRUE);
  175.     15:SelField(6);
  176.  
  177.     REPEAT
  178.         DialogEvent(Item);
  179.         IF Item=1 THEN
  180.             Done:=True;
  181.  
  182.         IF Item=2 THEN
  183.         BEGIN
  184.             Done:=TRUE;
  185.             Abort:=TRUE;
  186.         END;
  187.  
  188.         IF Item = 7 THEN
  189.         BEGIN
  190.         IF StdLgth THEN GOTO 20;
  191.             IF Type = 1 THEN
  192.             BEGIN
  193.                 SetRButton(3,Item);
  194.                 StdLgth:=TRUE;
  195.                 SetField(9,'');
  196.             END ELSE
  197.             BEGIN
  198.                 SysBeep;
  199.                 SelField(9);
  200.             END;
  201.         20:END;
  202.  
  203.         IF Item = 8 THEN
  204.         BEGIN
  205.             IF StdLgth THEN
  206.             BEGIN
  207.                 SetRButton(3,Item);
  208.                 StdLgth:=FALSE;
  209.                 SelField(9);
  210.             END;
  211.         END;
  212.  
  213.         IF Item = 9 THEN
  214.         BEGIN
  215.             IF StdLgth THEN
  216.             BEGIN
  217.                 StdLgth:=FALSE;
  218.                 SetRButton(3,8);
  219.                 SelField(9);
  220.             END;
  221.         END;
  222.  
  223.         IF (Item = 11) OR (Item = 12) THEN
  224.         BEGIN
  225.             SetRButton(1,Item);
  226.             View:=Item-10;
  227.         END;
  228.  
  229.         IF Item = 13 THEN
  230.         BEGIN
  231.             SetRButton(2,Item);
  232.             Type:=Item-12;
  233.             SetField(15,'');
  234.             SetField(16,'in');
  235.             SetField(17,'in');
  236.         END;
  237.  
  238.         IF Item = 14 THEN
  239.         BEGIN
  240.             SetRButton(2,Item);
  241.             Type:=Item-12;
  242.             StdLgth:=FALSE;
  243.             SetRButton(3,8);
  244.             SetField(15,'<n/a>');
  245.             SetField(16,'mm');
  246.             SetField(17,'mm');
  247.         END;
  248.     UNTIL Done;
  249.     IF Abort then GOTO 99;
  250.     Size1:=GetField(6);
  251.     Size:=Concat('''',Size1,'''');
  252.     UprString(Size);
  253.     Go:=ValidNumStr(GetField(9),CL);
  254.  
  255. 99:END;
  256.  
  257. Procedure GetData;
  258. {
  259. This procedure retrieves data from the data file.
  260. }
  261. LABEL 15,20,99;
  262.  
  263. VAR
  264.     File,Filename,WarningStr : STRING;
  265.  
  266. BEGIN
  267.     IF Type = 1 THEN File:=Filename1
  268.     ELSE File:=Filename2;
  269.     Filename:=Concat(Pathname,File);
  270.  
  271.     Open(Filename);
  272.     IF FndError THEN BEGIN
  273.         ClrDialog;
  274.         Sysbeep;
  275.         WarningStr:=Concat('The data file <',File,'> cannot be found. Check your Toolkit Manual for further explanation.');
  276.         AlrtDialog(WarningStr);
  277.         Abort:=TRUE;
  278.         GoTo 99;
  279.     END;
  280.  
  281.     SizeNotFound:=FALSE;
  282.     WHILE NOT Eoln(Filename) DO BEGIN
  283.         ReadLn(Sz,D,A,B,C,F,G,H,L,HD);
  284.         IF Sz=Size THEN GoTo 20;
  285.     END;
  286.  
  287.     Close(Filename);
  288.     15:SysBeep;
  289.     AlrtDialog('That size is not available! ');
  290.     SizeNotFound:=TRUE;
  291.     GoTo 99;
  292.  
  293.     20:Close(Filename);
  294. 99:END;
  295.  
  296. BEGIN
  297. {
  298. Main program.
  299. }
  300.  
  301. {
  302. Display the main dialog box and get the info.
  303. }
  304.  
  305.     DselectAll;
  306.     PinDialog;
  307.     SetCursor(ArrowC);
  308.  
  309. {
  310. Read the data file.
  311. }
  312.  
  313.     FirstTime:=TRUE;
  314.     10:GetInfo;
  315.     IF Abort THEN GoTo 99;
  316.     GetData;
  317.     IF Abort THEN GoTo 99;
  318.     IF SizeNotFound THEN Goto 10;
  319.     ClrDialog;
  320.  
  321. {
  322. Get units per inch and adjust the dimensions accordingly.
  323. }
  324.  
  325.     GetUnits(UName,DA,Fmt,UPI,UM,UM2);
  326.     IF Type = 1 THEN
  327.         SF:=UPI
  328.     ELSE
  329.         SF:=UPI/25.4;
  330.     D:=D*SF;
  331.     A:=A*SF;
  332.     B:=B*SF;
  333.     C:=C*SF;
  334.     F:=F*SF;
  335.     G:=G*SF;
  336.     H:=H*SF;
  337.     L:=L*SF;
  338.     Lk:=Lkc*SF;
  339.     HD:=HD*SF;
  340.     CL:=CL*SF;
  341.  
  342. {
  343. Calculate parameters for non-standard length.
  344. }
  345.  
  346.     E:=G-L;
  347.     S:=(D-A)/2;
  348.     HD1:=HD*HF;
  349.     IF StdLgth = FALSE THEN BEGIN
  350.         L:=CL;
  351.         G:=L+E;
  352.     END;
  353.     IF Type = 1 THEN
  354.         L2:=G-F
  355.     ELSE
  356.         L2:=L+HD1/2+Lk;
  357.  
  358. {
  359. Get pin location.
  360. }
  361.  
  362.     GetPt(x0,y0);
  363.  
  364. {
  365. Draw Top View.
  366. }
  367.  
  368.     IF View = 1 THEN BEGIN
  369.         Absolute;
  370.         MoveTo(x0,y0);
  371.         Relative;
  372.         Arc(-B/2,B/2,B/2,-B/2,0,360);
  373.         B:=B-2*H;
  374.         Arc(-B/2,B/2,B/2,-B/2,0,360);
  375.         GOTO 90;
  376.     END;
  377.  
  378. {
  379. Draw Side View.
  380. }
  381.  
  382.     Absolute;
  383.     MoveTo(x0,y0+D/2);
  384.     Relative;
  385.     ClosePoly;
  386.  
  387. {
  388. Draw head.
  389. }
  390.  
  391.     Move(-(C-H),(B-D)/2);
  392.     Rect(0,0,(C-H),-B);
  393.     Poly(0,0, -H,-H, 0,-(B-2*H), H,-H);
  394.     IF L <= 0 THEN GOTO 90;
  395. {
  396. Draw body.
  397. }
  398.     Move((C-H+L2),(B-D)/2);
  399.     OpenPoly;
  400.     Poly(F,S,0,D-2*S,-F,S);
  401.     Rect(0,0,-L2,-D);
  402.     Absolute;
  403.     MoveTo(x0+L,y0);
  404.     Relative;
  405. {
  406. Draw hole.
  407. }
  408.     Arc(-HD1/2,HD1/2,HD1/2,-HD1/2,0,360);
  409.     Arc(-HD/2,HD/2,HD/2,-HD/2,0,360);
  410.  
  411.     90:Group;
  412. 99:END;
  413.  
  414. RUN(ClevisPin);