home *** CD-ROM | disk | FTP | other *** search
- Procedure DrawNut;
- {
- (Windows version)
- ⌐1996, Diehl Graphsoft, Inc.
- Developed by Tom Urie
-
- This procedure draws various types of machine nuts.
- }
- LABEL 10,15,20,30,40,99;
- CONST
- Filename1='External\Data\MachNuti.txt';
- Filename2='External\Data\MachNutm.txt';
- PathL=14;
- VAR
- a,b,c,d,e,di,j,h,s,f,y,dia,h1,h2,h3 : REAL;
- x0,y0,UPI,SF : REAL;
- i,Type,View,Fmt : INTEGER;
- RFlag : ARRAY[1..3] OF INTEGER;
- Sz,Size,Size1,Filename,UM,UM2 : STRING;
- Ans,Abort,Inch : BOOLEAN;
- UName,DA : LONGINT;
-
- Procedure NutDialog;
- {
- This procedure defines the various dialog boxes.
- }
- VAR
- Width,x1,y1,x2,y2,px1,px2,px3,px4,py1,py2 : INTEGER;
-
- Procedure AlignScr(Width:INTEGER; VAR x1,x2:INTEGER);
- VAR
- scrx1,scry1,scrx2,scry2:INTEGER;
- BEGIN
- GetScreen(scrx1,scry1,scrx2,scry2);
- x1:=((scrx1+scrx2) div 2)-(Width div 2);
- x2:=x1+Width;
- END;
-
- Procedure MakeDialog1;
- {
- This procedure defines the main dialog box.
- }
- CONST
- y1=100;
- scnh=160; scnw=320;
- h=30;
- BEGIN
- AlignScr(scnw,x1,x2);
- y2:=y1+scnh;
- px3:=scnw-160;
- px4:=scnw-100;
- px1:=scnw-80;
- px2:=scnw-20;
- py1:=scnh-40;
- py2:=scnh-20;
-
- BeginDialog(1,1,x1,y1,x2,y2);
- AddButton('OK',1,1,px1,py1-30,px2,py2-30);
- AddButton('Cancel',2,1,px1,py1,px2,py2);
- AddField('Type of Nut:',5,1,20,40-h,145,55-h);
- AddButton('Regular Hex',6,3,20,65-h,115,80-h);
- AddButton('Hex Jam',7,3,20,85-h,92,100-h);
- AddButton('Square',8,3,20,105-h,87,120-h);
- AddField('',29,1,92,105-h,127,120-h);
- AddField('View:',9,1,155,40-h,195,55-h);
- AddButton('Top',10,3,155,65-h,200,80-h);
- AddButton('Front',11,3,155,85-h,210,100-h);
- AddButton('Side',12,3,155,105-h,200,120-h);
- AddField('Series:',17,1,245,40-h,295,55-h);
- AddButton('Inch',14,3,245,65-h,295,80-h);
- AddButton('Metric',15,3,245,85-h,305,100-h);
- AddField('Size:',13,1,20,135-h,50,150-h);
- AddField('',16,2,55,135-h,125,150-h);
- AddField('in',18,1,133,135-h,155,150-h);
- EndDialog
- END;
-
- Procedure MakeDialog2;
- {
- This procedure defines a warning dialog box if the data files cannot be found.
- }
- CONST
- y1=100;
- scnh=120; scnw=395;
- VAR
- Count1,Count2 : INTEGER;
- File1,File2,WarningMsg : STRING;
- BEGIN
- AlignScr(scnw,x1,x2);
- y2:=y1+scnh;
- Count1:=Len(Filename1)-PathL;
- Count2:=Len(Filename2)-PathL;
- File1:=Copy(Filename1,PathL+1,Count1);
- File2:=Copy(Filename2,PathL+1,Count2);
- WarningMsg:=Concat('The files: ',File1,', and ',File2,' must be in the Data folder located in the External
- folder for this program to run.');
- BeginDialog(2,1,x1,y1,x2,y2);
- AddButton('OK',1,1,155,75,235,105);
- AddField(WarningMsg,2,1,20,10,380,60);
- EndDialog;
- END;
-
- BEGIN
- MakeDialog1;
- MakeDialog2;
- END;
-
- Procedure GetWarning;
- {
- This procedure displays the warning dialog box.
- }
- VAR
- Done:Boolean;
- Item:Integer;
- BEGIN
- Done:=FALSE;
- GetDialog(2);
- SetTitle('Warning!');
- REPEAT
- DialogEvent(Item);
- IF Item=1 THEN
- Done:=True;
- UNTIL Done;
- ClrDialog;
- END;
-
- Procedure GetInfo;
- {
- This procedure displays the main dialog box and retrieves the information.
- }
- LABEL 10;
- VAR
- Done:Boolean;
- Item:Integer;
-
- Procedure SetRButton(i,Item : INTEGER);
- BEGIN
- IF RFlag[i] <> Item THEN BEGIN
- SetItem(RFlag[i],FALSE);
- SetItem(Item,TRUE);
- RFlag[i]:=Item;
- END;
- END;
-
- BEGIN
- Done:=FALSE;
- Abort:=FALSE;
- IF Ans THEN BEGIN
- Ans:=FALSE;
- GOTO 10;
- END;
- Type:=1;
- View:=1;
- Inch:=TRUE;
- RFlag[1]:=6;
- RFlag[2]:=10;
- RFlag[3]:=14;
- 10:GetDialog(1);
- SetTitle('Machine Nuts');
- SetItem(RFlag[1],TRUE);
- SetItem(RFlag[2],TRUE);
- SetItem(RFlag[3],TRUE);
- SetField(16,Size1);
- SelField(16);
- IF Inch THEN BEGIN
- SetField(18,'in');
- SetField(29,'');
- END
- ELSE BEGIN
- SetField(18,'mm');
- SetField(29,'<n/a>');
- END;
- REPEAT
- DialogEvent(Item);
- IF Item=1 THEN
- Done:=True;
- IF Item=2 then BEGIN
- Done:=TRUE;
- Abort:=TRUE;
- END;
- IF (Item > 5) AND (Item < 8) THEN BEGIN
- SetRButton(1,Item);
- Type:=Item-5;
- END;
- IF Item = 8 THEN BEGIN
- IF Inch THEN BEGIN
- SetRButton(1,Item);
- Type:=Item-5;
- END
- ELSE BEGIN
- SetRButton(1,6);
- Type:=1;
- SysBeep;
- END;
- END;
- IF (Item > 9) AND (Item < 13) THEN BEGIN
- SetRButton(2,Item);
- View:=Item-9;
- END;
- IF Item=14 THEN BEGIN
- SetRButton(3,Item);
- Inch:=TRUE;
- SetField(18,'in');
- SetField(29,'');
- END;
- IF Item=15 THEN BEGIN
- SetRButton(3,Item);
- Inch:=FALSE;
- SetField(18,'mm');
- SetField(29,'<n/a>');
- SetRButton(1,6);
- Type:=1;
- SelField(16);
- END;
- Size1:=GetField(16);
- Size:=Concat('''',Size1,'''');
- UprString(Size);
- UNTIL Done;
- ClrDialog;
- END;
-
- Procedure GetData;
- {
- This procedure opens the data file and reads the data.
- }
- LABEL 15,20,99;
- BEGIN
- IF Inch=True THEN
- Filename:=Filename1
- ELSE
- Filename:=Filename2;
- Open(Filename);
- IF FndError THEN BEGIN
- Sysbeep;
- GetWarning;
- Abort:=TRUE;
- GoTo 99;
- END;
- WHILE NOT Eoln(Filename) DO BEGIN
- ReadLn(Sz,d,a,h1,b,h2,c,h3);
- IF Sz=Size THEN GoTo 20;
- END;
- Close(Filename);
- 15:SysBeep;
- AlrtDialog('That size is not available!');
- Ans:=TRUE;
- GoTo 99;
- 20:Close(Filename);
- IF ((Type=1) AND (a=0) OR (Type=2) AND (b=0) OR (Type=3) AND (c=0)) THEN GoTo 15;
- 99:END;
-
- Procedure Curve(x,y:real);
- {
- This procedure draws a cubic spline curve through three points.
- }
- BEGIN;
- OpenPoly;
- BeginPoly;
- LineTo(0,0);
- CurveThrough(x/2,y);
- LineTo(x/2,-y);
- Endpoly;
- END;
-
- Procedure DrawTop;
- {
- This procedure draws the top view of the nut.
- }
- BEGIN
- Absolute;
- MoveTo(x0,y0);
- Relative;
- IF Type<>3 THEN BEGIN
- Move(j/2,0);
- ClosePoly;
- Poly(0,0,f,#-120,f,#-180,f,#120,f,#60,f,#0);
- Absolute;
- MoveTo(x0,y0);
- Relative;
- Arc(-a/2,a/2,a/2,-a/2,0,360);
- END
- ELSE BEGIN
- Rect(-c/2,c/2,c/2,-c/2);
- Arc(-c/2,c/2,c/2,-c/2,0,360);
- END;
- PushAttrs;
- PenSize(1);
- PenPat(-2);
- Arc(-d/2,d/2,d/2,-d/2,0,360);
- PopAttrs;
- Arc(-di/2,di/2,di/2,-di/2,0,360);
- END;
-
- Procedure DrawFront(Type:INTEGER);
- {
- This procedure draws the front view of the nut.
- }
- VAR
- h:REAL;
- BEGIN
- IF Type=1 THEN
- h:=h1
- ELSE IF Type=2 THEN
- h:=h2
- ELSE
- h:=h3;
- Absolute;
- MoveTo(x0,y0);
- Relative;
- IF (Type=1) OR (Type=2) THEN BEGIN
- Move(j/2,(h-e));
- 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);
- Move(-(j-s),-e);
- Curve(y,e);
- Curve(j-2*y,e);
- Curve(y,e);
- MoveTo(0,-(h-2*e));
- Curve(-y,-e);
- Curve(-(j-2*y),-e);
- Curve(-y,-e);
- Move(y,0);
- Line(0,(h-2*e));
- Move(f,-(h-2*e));
- Line(0,(h-2*e));
- END
- ELSE BEGIN
- Move(c/2,0);
- Rect(0,0,-c,h);
- Move(-c,(h-e));
- Curve(c,e);
- END;
- END;
-
- Procedure DrawSide(Type:INTEGER);
- {
- This procedure draws the side view of the nut.
- }
- VAR
- h:REAL;
- BEGIN
- IF Type=1 THEN
- h:=h1
- ELSE IF Type=2 THEN
- h:=h2
- ELSE
- h:=h3;
- Absolute;
- MoveTo(x0,y0);
- Relative;
- IF (Type=1) OR (Type=2) THEN BEGIN
- Move(a/2,0);
- Rect(0,0,-a,h);
- Move(-a,(h-e));
- Curve(a/2,e);
- Curve(a/2,e);
- Move(0,-(h-2*e));
- Curve(-a/2,-e);
- Curve(-a/2,-e);
- Move((a/2),0);
- Line(0,(h-2*e));
- END
- ELSE BEGIN
- MoveTo(j/2,0);
- ClosePoly;
- Poly(0,0,-j,0,0,(h-e),s,e,(j-2*s),0,s,-e);
- Curve(-j/2,e);
- Curve(-j/2,e);
- Move(j/2,0);
- Line(0,-(h-e));
- END;
- END;
-
- {
- Main program.
- }
- BEGIN
- DselectAll;
- PushAttrs;
- NutDialog;
- {
- Display the main dialog box and get the information.
- }
- Ans:=FALSE;
- SetCursor(ArrowC);
- 10:GetInfo;
- IF Abort THEN GoTo 99;
- {
- Open the data file and get the data.
- }
- GetData;
- IF Abort THEN GoTo 99;
- IF Ans THEN GOTO 10;
- {
- Get units per inch and adjust variables accordingly.
- }
- GetUnits(UName,DA,Fmt,UPI,UM,UM2);
- IF Inch=TRUE THEN
- SF:=UPI
- ELSE
- SF:=UPI/25.4;
- d:=SF*d;
- a:=SF*a;
- h1:=SF*h1;
- b:=SF*b;
- h2:=SF*h2;
- c:=SF*c;
- h3:=SF*h3;
- GetPt(x0,y0);
- di:=0.85*d;
- {
- Calculate additional variables needed to draw nut.
- }
- IF Type=1 THEN BEGIN
- f:=0.57735*a;
- j:=1.15470*a;
- e:=0.28868*(j-a);
- y:=(j-f)/2;
- s:=(j-a)/2;
- END
- ELSE IF Type=2 THEN BEGIN
- f:=0.57735*b;
- j:=1.15470*b;
- e:=0.28868*(j-b);
- y:=(j-f)/2;
- s:=(j-b)/2;
- END
- ELSE IF Type=3 THEN BEGIN
- j:=1.41421*c;
- e:=0.23315*(j-c);
- y:=j/2;
- s:=(j-c)/2;
- END;
- {
- Draw nut.
- }
- IF View=1 THEN
- DrawTop
- ELSE IF View=2 THEN
- DrawFront(Type)
- ELSE
- DrawSide(Type);
- Group;
- PopAttrs;
- 99:END;
-
- Run(DrawNut);
-