home *** CD-ROM | disk | FTP | other *** search
- Procedure ShoulderScrew;
- {
- (Windows version)
- ⌐1996, Diehl Graphsoft, Inc.
- Developed by Tom Urie
-
- This procedure draws a shoulder screw.
- }
-
- LABEL 10,20,30,89,90,99;
- CONST
- Filename1='External\Data\ShldScri.txt';
- Filename2='External\Data\ShldScrm.txt';
- sdC=0.010; {Depth of undercut (inches)}
- PathL=14;
- VAR
- d,a,h,j,s,t,tl,g,y,f,fl,td,b,dia,l,c : REAL;
- di,l1,p,x0,y0,sd,tpi,SF : REAL;
- i,n,ThdType,View,ScrType : INTEGER;
- RFlag : ARRAY[1..2] OF INTEGER;
- Sz,Size,Size1,Filename : STRING;
- Ans,Abort,CFlag1,Inch : BOOLEAN;
- UPI : REAL;
- Fmt : INTEGER;
- UM,UM2 : STRING;
- UName,DA : LONGINT;
-
- Procedure SSDialog;
- {
- This procedure defines the main dialog box.
- }
- 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;
- CONST
- y1=100;
- scnh=190; scnw=290;
- h=25;
- BEGIN
- AlignScr(scnw,x1,x2);
- y2:=y1+scnh;
- px3:=scnw/2-70;
- px4:=scnw/2-10;
- px1:=scnw/2+10;
- px2:=scnw/2+70;
- py1:=scnh-40;
- py2:=scnh-20;
-
- BeginDialog(1,1,x1,y1,x2,y2);
- AddButton('OK',1,1,px3,py1,px4,py2);
- AddButton('Cancel',2,1,px1,py1,px2,py2);
- AddField('Size:',4,1,20,75,60,90);
- AddField('',5,2,80,75,140,90);
- AddField('in',17,1,148,75,170,90);
- AddField('Length:',6,1,20,105,70,121);
- AddField('',7,2,80,105,140,120);
- AddField('in',18,1,148,105,170,120);
- AddField('View:',8,1,190,40-h,245,55-h);
- AddButton('Top',9,3,190,85-h,235,100-h);
- AddButton('Side',10,3,190,65-h,235,80-h);
- AddButton('Detailed',11,2,190,120-h,320,135-h);
- AddField('Threads',12,1,210,137-h,280,152-h);
- AddField('Series:',16,1,20,15,75,30);
- AddButton('Inch',14,3,20,40,70,55);
- AddButton('Metric',15,3,75,40,135,55);
- EndDialog;
- END;
-
- Procedure MakeDialog2;
- {
- This procedure creates a warning dialog box telling the user that the data file is missing.
- }
- 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,15,99;
- VAR
- Done,OK: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;
- Inch:=TRUE;
- View:=2;
- ThdType:=1;
- RFlag[1]:=10;
- RFlag[2]:=14;
- CFlag1:=FALSE;
- Inch:=TRUE;
- 10:GetDialog(1);
- SetTitle('Shoulder Screws');
- SetField(5,Size1);
- IF View=1 THEN
- SetField(7,'n/a')
- ELSE
- SetField(7,Num2StrF(L));
- IF Inch THEN BEGIN
- SetField(17,'in');
- SetField(18,'in');
- END
- ELSE BEGIN
- SetField(17,'mm');
- SetField(18,'mm');
- END;
- SetItem(11,CFlag1);
- SetItem(RFlag[1],TRUE);
- SetItem(RFlag[2],TRUE);
- SelField(5);
- 15:REPEAT
- DialogEvent(Item);
- IF Item=1 THEN
- Done:=True;
- IF Item=2 THEN BEGIN
- Done:=TRUE;
- Abort:=TRUE;
- END;
- IF Item = 9 THEN BEGIN
- SetRButton(1,9);
- View:=1;
- SetField(7,'n/a');
- END;
- IF Item = 10 THEN BEGIN
- SetRButton(1,10);
- View:=2;
- SetField(7,Num2StrF(L));
- END;
- IF Item=11 THEN BEGIN
- SetItem(Item,NOT CFlag1);
- CFlag1:=NOT CFlag1;
- END;
- IF Item=14 THEN BEGIN
- SetRButton(2,Item);
- Inch:=TRUE;
- SetField(17,'in');
- SetField(18,'in');
- SelField(5);
- END;
- IF Item=15 THEN BEGIN
- SetRButton(2,Item);
- Inch:=FALSE;
- SetField(17,'mm');
- SetField(18,'mm');
- SelField(5);
- END;
- UNTIL Done;
- IF Abort THEN GOTO 99;
- Size1:=GetField(5);
- Size:=Concat('''',Size1,'''');
- UprString(Size);
- OK:=ValidNumStr(GetField(7),L);
- IF (View = 2) AND (L <= 0) THEN BEGIN
- Sysbeep;
- Done:=FALSE;
- SelField(7);
- GOTO 15;
- END;
- IF CFlag1 THEN
- ThdType:=2
- ELSE
- ThdType:=1;
- 99:ClrDialog;
- END;
-
- Procedure GetData;
- {
- This procedure opens the data file and reads the data.
- }
- LABEL 15,20,99;
- BEGIN
- If Inch THEN
- Filename:=Filename1
- ELSE
- Filename:=Filename2;
- Open(Filename);
- {
- Display the warning dialog box if the data file cannot be found.
- }
- IF FndError THEN BEGIN
- Sysbeep;
- GetWarning;
- Abort:=TRUE;
- GoTo 99;
- END;
- {
- Read the data.
- }
- WHILE NOT Eoln(Filename) DO BEGIN
- ReadLn(Sz,d,a,h,j,s,t,tpi,tl,f,g);
- IF Sz=Size THEN GoTo 20;
- END;
- Close(Filename);
- {
- Diaplay a warning if the specified size is not available.
- }
- 15:SysBeep;
- AlrtDialog('That size is not available!');
- Ans:=TRUE;
- GoTo 99;
- 20:Close(Filename);
- 99:END;
-
- {
- Main program.
- }
- BEGIN
- DselectAll;
- {
- Display the main dialog box and get the information.
- }
- SSDialog;
- SetCursor(ArrowC);
- Ans:=FALSE;
- 10:GetInfo;
- IF Abort THEN GoTo 99;
- GetData;
- IF Abort THEN GoTo 99;
- IF Ans THEN Goto 10;
- {
- Get drawing units and adjust parameters accordingly.
- }
- GetUnits(UName,DA,Fmt,UPI,UM,UM2);
- IF Inch = TRUE THEN BEGIN
- SF:=UPI;
- sd:=sdc;
- END
- ELSE BEGIN
- SF:=UPI/25.4;
- sd:=sdc*25.4;
- END;
- sd:=sd*SF;
- L:=L*SF;
- d:=d*SF;
- a:=a*SF;
- h:=h*SF;
- j:=j*SF;
- s:=s*SF;
- t:=t*SF;
- tl:=tl*SF;
- f:=f*SF;
- g:=g*SF;
- tpi:=tpi/SF;
- {
- Get insertion point and calculate variables.
- }
- GetPt(x0,y0);
- c:=a-3.4641*(h-s);
- y:=0.2887*j;
- fl:=0.5774*j;
- td:=0.86603/tpi;
- b:=0.60640/tpi;
- n:=(tl-g)*tpi;
- di:=t-2*td;
- p:=1/tpi;
- l1:=tl-g-n*p;
- IF View=2 THEN Goto 20;
- {
- Draw top view.
- }
- Absolute;
- MoveTo(x0,y0);
- Relative;
- Arc(-a/2,a/2,a/2,-a/2,0,360);
- Arc(-c/2,c/2,c/2,-c/2,0,360);
- MoveTo(0,y+fl/2);
- Relative;
- ClosePoly;
- Poly(fl,#-30,fl,#-90,fl,#-150,fl,#150,fl,#90);
- GOTO 90;
- {
- Draw side view.
-
- Draw head.
- }
- 20:Absolute;
- MoveTo(x0-a/2,y0);
- Relative;
- Rect(0,0,a,s);
- Move(0,s);
- Poly((a-c)/2,(h-s),c,0,(a-c)/2,-(h-s));
- {
- Draw shoulder.
- }
- Move(-(a+d)/2,-(s+f));
- Rect(0,0,d,-(l-f));
- Move(sd,0);
- Rect(0,0,(d-2*sd),f);
- IF ThdType=2 THEN GoTo 30;
- {
- Draw non-detail threads.
- }
- Absolute;
- MoveTo(x0-t/2,y0-(L+g));
- Relative;
- Rect(0,0,t,-(tl-g-b));
- Move(t,-(tl-g-b));
- ClosePoly;
- Poly(-td,-b,-(t-2*td),0,-td,b);
- Move(td,-b);
- PenPat(-2);
- Line(0,(tl-g));
- Move((t-2*td),0);
- Line(0,-(tl-g));
- PenPat(2);
- Move(0,(tl-g));
- Rect(0,0,-di,g);
- GoTo 90;
- {
- Draw detailed threads.
- }
- 30:Absolute;
- {
- Draw bottom thread.
- }
- MoveTo(x0-t/2,y0-L-tl+td);
- Relative;
- OpenPoly;
- BeginPoly;
- LineTo(0,0);
- LineTo(td,-td);
- LineTo(t-5*td/2+p/4,0);
- LineTo(td-p/4,td-p/4);
- LineTo(-(t/2-td/2),0);
- EndPoly;
- ClosePoly;
- BeginPoly;
- Lineto(0,0);
- LineTo((t/2-td/2),0);
- Line(-td/2,p/4);
- LineTo(-(t/2-td/2),-p/4);
- EndPoly;
- OpenPoly;
- BeginPoly;
- LineTo(0,0);
- LineTo((t/2-td/2),p/4);
- LineTo(td,p/2);
- Lineto(-t,-p/2);
- EndPoly;
- {
- Draw whole threads.
- }
- FOR i:=1 TO n-1 DO BEGIN
- BeginPoly;
- Line(0,0);
- Line(td,p/2);
- Line(di,p/2);
- Line(td,-p/2);
- Line(-t,-p/2);
- EndPoly;
- Move(td,p/2);
- BeginPoly;
- Line(0,0);
- Line(-td,p/2);
- Line(t,p/2);
- Line(-td,-p/2);
- Line(-di,-p/2);
- EndPoly;
- Move(-td,p/2);
- END;
- {
- Draw last thread & shoulder.
- }
- BeginPoly;
- LineTo(0,0);
- LineTo(td,p/2);
- LineTo(-td/2,p/4);
- LineTo(td/2,p/4);
- Line(0,tl-n*p-td);
- Line(di,0);
- Line(0,-(tl-n*p-td));
- Line(td,-p/2);
- EndPoly;
- Move(-(t-td),0);
- Line(di/2,p/4);
- Line(-(di+td)/2,0);
- 90:Group;
- 99:END;
-
- RUN(ShoulderScrew);
-