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

  1. Procedure DrawNut;
  2. {
  3. (Windows version)
  4. ⌐1996, Diehl Graphsoft, Inc.
  5. Developed by Tom Urie
  6.  
  7. This procedure draws various types of machine nuts.
  8. }
  9. LABEL 10,15,20,30,40,99;
  10. CONST
  11.     Filename1='External\Data\MachNuti.txt';
  12.     Filename2='External\Data\MachNutm.txt';
  13.     PathL=14;
  14. VAR
  15.     a,b,c,d,e,di,j,h,s,f,y,dia,h1,h2,h3 : REAL;
  16.     x0,y0,UPI,SF : REAL;
  17.     i,Type,View,Fmt : INTEGER;
  18.     RFlag : ARRAY[1..3] OF INTEGER;
  19.     Sz,Size,Size1,Filename,UM,UM2 : STRING;
  20.     Ans,Abort,Inch : BOOLEAN;
  21.     UName,DA : LONGINT;
  22.  
  23. Procedure NutDialog;
  24. {
  25. This procedure defines the various dialog boxes.
  26. }
  27. VAR
  28.     Width,x1,y1,x2,y2,px1,px2,px3,px4,py1,py2 : INTEGER;
  29.  
  30. Procedure AlignScr(Width:INTEGER; VAR x1,x2:INTEGER);
  31. VAR
  32.     scrx1,scry1,scrx2,scry2:INTEGER;
  33. BEGIN
  34.     GetScreen(scrx1,scry1,scrx2,scry2);
  35.     x1:=((scrx1+scrx2) div 2)-(Width div 2);
  36.     x2:=x1+Width; 
  37. END;
  38.  
  39. Procedure MakeDialog1;
  40. {
  41. This procedure defines the main dialog box.
  42. }
  43. CONST
  44.     y1=100;
  45.     scnh=160; scnw=320;
  46.     h=30;
  47. BEGIN
  48.     AlignScr(scnw,x1,x2);
  49.     y2:=y1+scnh;
  50.     px3:=scnw-160;
  51.     px4:=scnw-100;
  52.     px1:=scnw-80;
  53.     px2:=scnw-20;
  54.     py1:=scnh-40;
  55.     py2:=scnh-20;
  56.  
  57.     BeginDialog(1,1,x1,y1,x2,y2);
  58.         AddButton('OK',1,1,px1,py1-30,px2,py2-30);
  59.         AddButton('Cancel',2,1,px1,py1,px2,py2);
  60.         AddField('Type of Nut:',5,1,20,40-h,145,55-h);
  61.         AddButton('Regular Hex',6,3,20,65-h,115,80-h);
  62.         AddButton('Hex Jam',7,3,20,85-h,92,100-h);
  63.         AddButton('Square',8,3,20,105-h,87,120-h);
  64.         AddField('',29,1,92,105-h,127,120-h);
  65.         AddField('View:',9,1,155,40-h,195,55-h);
  66.         AddButton('Top',10,3,155,65-h,200,80-h);
  67.         AddButton('Front',11,3,155,85-h,210,100-h);
  68.         AddButton('Side',12,3,155,105-h,200,120-h);
  69.         AddField('Series:',17,1,245,40-h,295,55-h);
  70.         AddButton('Inch',14,3,245,65-h,295,80-h);
  71.         AddButton('Metric',15,3,245,85-h,305,100-h);
  72.         AddField('Size:',13,1,20,135-h,50,150-h);
  73.         AddField('',16,2,55,135-h,125,150-h);
  74.         AddField('in',18,1,133,135-h,155,150-h);
  75.     EndDialog
  76. END;
  77.  
  78. Procedure MakeDialog2;
  79. {
  80. This procedure defines a warning dialog box if the data files cannot be found.
  81. }
  82. CONST
  83.     y1=100;
  84.     scnh=120; scnw=395;
  85. VAR
  86.     Count1,Count2 : INTEGER;
  87.     File1,File2,WarningMsg : STRING;
  88. BEGIN
  89.     AlignScr(scnw,x1,x2);
  90.     y2:=y1+scnh;
  91.     Count1:=Len(Filename1)-PathL;
  92.     Count2:=Len(Filename2)-PathL;
  93.     File1:=Copy(Filename1,PathL+1,Count1);
  94.     File2:=Copy(Filename2,PathL+1,Count2);
  95. WarningMsg:=Concat('The files: ',File1,', and ',File2,' must be in the Data folder located in the External 
  96. folder for this program to run.');
  97.     BeginDialog(2,1,x1,y1,x2,y2);
  98.         AddButton('OK',1,1,155,75,235,105);
  99.         AddField(WarningMsg,2,1,20,10,380,60);
  100.     EndDialog;
  101. END;
  102.  
  103. BEGIN
  104.     MakeDialog1;
  105.     MakeDialog2;
  106. END;
  107.  
  108. Procedure GetWarning;
  109. {
  110. This procedure displays the warning dialog box.
  111. }
  112. VAR
  113.     Done:Boolean;
  114.     Item:Integer;
  115. BEGIN
  116.     Done:=FALSE;
  117.     GetDialog(2);
  118.     SetTitle('Warning!');
  119.     REPEAT
  120.         DialogEvent(Item);
  121.         IF Item=1 THEN
  122.             Done:=True;
  123.     UNTIL Done;
  124.     ClrDialog;
  125. END;
  126.  
  127. Procedure GetInfo;
  128. {
  129. This procedure displays the main dialog box and retrieves the information.
  130. }
  131. LABEL 10;
  132. VAR
  133.     Done:Boolean;
  134.     Item:Integer;
  135.  
  136. Procedure SetRButton(i,Item : INTEGER);
  137. BEGIN
  138.     IF RFlag[i] <> Item THEN BEGIN
  139.         SetItem(RFlag[i],FALSE);
  140.         SetItem(Item,TRUE);
  141.         RFlag[i]:=Item;
  142.     END;
  143. END;
  144.  
  145. BEGIN
  146.     Done:=FALSE;
  147.     Abort:=FALSE;
  148.     IF Ans THEN BEGIN
  149.         Ans:=FALSE;
  150.         GOTO 10;
  151.     END;
  152.     Type:=1;
  153.     View:=1;
  154.     Inch:=TRUE;
  155.     RFlag[1]:=6;
  156.     RFlag[2]:=10;
  157.     RFlag[3]:=14;
  158.     10:GetDialog(1);
  159.     SetTitle('Machine Nuts');
  160.     SetItem(RFlag[1],TRUE);
  161.     SetItem(RFlag[2],TRUE);
  162.     SetItem(RFlag[3],TRUE);
  163.     SetField(16,Size1);
  164.     SelField(16);
  165.     IF Inch THEN BEGIN
  166.         SetField(18,'in');
  167.         SetField(29,'');
  168.     END
  169.     ELSE BEGIN
  170.         SetField(18,'mm');
  171.         SetField(29,'<n/a>');
  172.     END;
  173.     REPEAT
  174.         DialogEvent(Item);
  175.         IF Item=1 THEN
  176.             Done:=True;
  177.         IF Item=2 then BEGIN
  178.             Done:=TRUE;
  179.             Abort:=TRUE;
  180.         END;
  181.         IF (Item > 5) AND (Item < 8) THEN BEGIN
  182.             SetRButton(1,Item);
  183.             Type:=Item-5;            
  184.         END;
  185.         IF Item = 8 THEN BEGIN
  186.             IF Inch THEN BEGIN
  187.                 SetRButton(1,Item);
  188.                 Type:=Item-5;
  189.             END
  190.             ELSE BEGIN
  191.                 SetRButton(1,6);
  192.                 Type:=1;
  193.                 SysBeep;
  194.             END;
  195.         END;
  196.         IF (Item > 9) AND (Item < 13) THEN BEGIN
  197.             SetRButton(2,Item);
  198.             View:=Item-9;            
  199.         END;
  200.         IF Item=14 THEN BEGIN
  201.             SetRButton(3,Item);
  202.             Inch:=TRUE;
  203.             SetField(18,'in');
  204.             SetField(29,'');
  205.         END;
  206.         IF Item=15 THEN BEGIN
  207.             SetRButton(3,Item);
  208.             Inch:=FALSE;
  209.             SetField(18,'mm');
  210.             SetField(29,'<n/a>');
  211.             SetRButton(1,6);
  212.             Type:=1;
  213.             SelField(16);
  214.         END;
  215.         Size1:=GetField(16);
  216.         Size:=Concat('''',Size1,'''');
  217.         UprString(Size);
  218.     UNTIL Done;
  219.     ClrDialog;
  220. END;
  221.  
  222. Procedure GetData;
  223. {
  224. This procedure opens the data file and reads the data.
  225. }
  226. LABEL 15,20,99;
  227. BEGIN
  228.     IF Inch=True THEN
  229.         Filename:=Filename1
  230.     ELSE
  231.         Filename:=Filename2;
  232.     Open(Filename);
  233.     IF FndError THEN BEGIN
  234.         Sysbeep;
  235.         GetWarning;
  236.         Abort:=TRUE;
  237.         GoTo 99;
  238.     END;
  239.     WHILE NOT Eoln(Filename) DO BEGIN
  240.         ReadLn(Sz,d,a,h1,b,h2,c,h3);
  241.         IF Sz=Size THEN GoTo 20;
  242.     END;
  243.     Close(Filename);
  244.     15:SysBeep;
  245.     AlrtDialog('That size is not available!');
  246.     Ans:=TRUE;
  247.     GoTo 99;
  248.     20:Close(Filename);
  249.     IF ((Type=1) AND (a=0) OR (Type=2) AND (b=0) OR (Type=3) AND (c=0)) THEN GoTo 15;
  250. 99:END;
  251.  
  252. Procedure Curve(x,y:real);
  253. {
  254. This procedure draws a cubic spline curve through three points.
  255. }
  256. BEGIN;
  257.     OpenPoly;
  258.     BeginPoly;
  259.         LineTo(0,0);
  260.         CurveThrough(x/2,y);
  261.         LineTo(x/2,-y);
  262.     Endpoly;
  263. END;            
  264.  
  265. Procedure DrawTop;
  266. {
  267. This procedure draws the top view of the nut.
  268. }
  269. BEGIN
  270.     Absolute;
  271.     MoveTo(x0,y0);
  272.     Relative;
  273.     IF Type<>3 THEN BEGIN
  274.         Move(j/2,0);
  275.         ClosePoly;
  276.         Poly(0,0,f,#-120,f,#-180,f,#120,f,#60,f,#0);
  277.         Absolute;
  278.         MoveTo(x0,y0);
  279.         Relative;
  280.         Arc(-a/2,a/2,a/2,-a/2,0,360);    
  281.     END
  282.     ELSE BEGIN
  283.         Rect(-c/2,c/2,c/2,-c/2);
  284.         Arc(-c/2,c/2,c/2,-c/2,0,360);
  285.     END;
  286.     PushAttrs;
  287.     PenSize(1);
  288.     PenPat(-2);
  289.     Arc(-d/2,d/2,d/2,-d/2,0,360);
  290.     PopAttrs;
  291.     Arc(-di/2,di/2,di/2,-di/2,0,360);
  292. END;
  293.  
  294. Procedure DrawFront(Type:INTEGER);
  295. {
  296. This procedure draws the front view of the nut.
  297. }
  298. VAR
  299.     h:REAL;
  300. BEGIN
  301.     IF Type=1 THEN
  302.         h:=h1
  303.     ELSE IF Type=2 THEN
  304.         h:=h2
  305.     ELSE
  306.         h:=h3;
  307.     Absolute;
  308.     MoveTo(x0,y0);
  309.     Relative;
  310.     IF (Type=1) OR (Type=2) THEN BEGIN
  311.         Move(j/2,(h-e));
  312.         ClosePoly;    Poly(0,0,0,-(h-2*e),-s,-e,-(j-2*s),0,-s,e,0,(h-2*e),s,e,(j-2*s),0);
  313.         Move(-(j-s),-e);
  314.         Curve(y,e);
  315.         Curve(j-2*y,e);
  316.         Curve(y,e);
  317.         MoveTo(0,-(h-2*e));
  318.         Curve(-y,-e);
  319.         Curve(-(j-2*y),-e);
  320.         Curve(-y,-e);
  321.         Move(y,0);
  322.         Line(0,(h-2*e));
  323.         Move(f,-(h-2*e));
  324.         Line(0,(h-2*e));
  325.     END
  326.     ELSE BEGIN
  327.         Move(c/2,0);
  328.         Rect(0,0,-c,h);
  329.         Move(-c,(h-e));
  330.         Curve(c,e);
  331.     END;
  332. END;
  333.  
  334. Procedure DrawSide(Type:INTEGER);
  335. {
  336. This procedure draws the side view of the nut.
  337. }
  338. VAR
  339.     h:REAL;
  340. BEGIN
  341.     IF Type=1 THEN
  342.         h:=h1
  343.     ELSE IF Type=2 THEN
  344.         h:=h2
  345.     ELSE
  346.         h:=h3;
  347.     Absolute;
  348.     MoveTo(x0,y0);
  349.     Relative;
  350.     IF (Type=1) OR (Type=2) THEN BEGIN
  351.         Move(a/2,0);
  352.         Rect(0,0,-a,h);
  353.         Move(-a,(h-e));
  354.         Curve(a/2,e);
  355.         Curve(a/2,e);
  356.         Move(0,-(h-2*e));
  357.         Curve(-a/2,-e);
  358.         Curve(-a/2,-e);
  359.         Move((a/2),0);
  360.         Line(0,(h-2*e));
  361.     END
  362.     ELSE BEGIN
  363.         MoveTo(j/2,0);
  364.         ClosePoly;
  365.         Poly(0,0,-j,0,0,(h-e),s,e,(j-2*s),0,s,-e);
  366.         Curve(-j/2,e);
  367.         Curve(-j/2,e);
  368.         Move(j/2,0);
  369.         Line(0,-(h-e));
  370.     END;
  371. END;
  372.  
  373. {
  374. Main program.
  375. }
  376. BEGIN
  377.     DselectAll;
  378.     PushAttrs;
  379.     NutDialog;
  380. {
  381. Display the main dialog box and get the information.
  382. }
  383.     Ans:=FALSE;
  384.     SetCursor(ArrowC);
  385.     10:GetInfo;
  386.     IF Abort THEN GoTo 99;
  387. {
  388. Open the data file and get the data.
  389. }
  390.     GetData;
  391.     IF Abort THEN GoTo 99;
  392.     IF Ans THEN GOTO 10;
  393. {
  394. Get units per inch and adjust variables accordingly.
  395. }
  396.     GetUnits(UName,DA,Fmt,UPI,UM,UM2);
  397.     IF Inch=TRUE THEN
  398.         SF:=UPI
  399.     ELSE
  400.         SF:=UPI/25.4;
  401.     d:=SF*d;
  402.     a:=SF*a;
  403.     h1:=SF*h1;
  404.     b:=SF*b;
  405.     h2:=SF*h2;
  406.     c:=SF*c;
  407.     h3:=SF*h3;
  408.     GetPt(x0,y0);
  409.     di:=0.85*d;
  410. {
  411. Calculate additional variables needed to draw nut.
  412. }
  413.     IF Type=1 THEN BEGIN
  414.         f:=0.57735*a;
  415.         j:=1.15470*a;
  416.         e:=0.28868*(j-a);
  417.         y:=(j-f)/2;
  418.         s:=(j-a)/2;
  419.     END
  420.     ELSE IF Type=2 THEN BEGIN
  421.         f:=0.57735*b;
  422.         j:=1.15470*b;
  423.         e:=0.28868*(j-b);
  424.         y:=(j-f)/2;
  425.         s:=(j-b)/2;
  426.     END
  427.     ELSE IF Type=3 THEN BEGIN
  428.         j:=1.41421*c;
  429.         e:=0.23315*(j-c);
  430.         y:=j/2;
  431.         s:=(j-c)/2;
  432.     END;
  433. {
  434. Draw nut.
  435. }
  436.     IF View=1 THEN
  437.         DrawTop
  438.     ELSE IF View=2 THEN
  439.         DrawFront(Type)
  440.     ELSE
  441.         DrawSide(Type);
  442.     Group;
  443.     PopAttrs;
  444. 99:END;
  445.  
  446. Run(DrawNut);
  447.