home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 1998 March
/
Chip_1998-03_cd.bin
/
tema
/
MINICAD
/
MC7DEMO
/
MINICAD.1
/
SHLD_SCR.MPC
< prev
next >
Wrap
Text File
|
1997-04-30
|
9KB
|
548 lines
Procedure ShoulderScrew;
{
(c)1997, Diehl Graphsoft, Inc.
Developed by Tom Urie
This procedure draws a shoulder screw.
}
LABEL 10,20,30,89,90,99;
CONST
Mac = FALSE;
Filename1='ShldScrE.txt';
Filename2='ShldScrM.txt';
sdC=0.010; {Depth of undercut (inches)}
kps1 = 0.75;
kps2 = 1.25;
VAR
a,b,c,d,di,dia,f,fl,g,h,L,L1,j,s,t,td,tl : REAL;
p,p1,q1,x0,y0,y,sd,tpi,SF : REAL;
i,n,ThdType,View,ScrType,nThreads : INTEGER;
Sz,Size,Size1,Pathname : STRING;
Ans,Abort,Inch,SizeNotFound : 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,py3,py4 : 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 LocateButtons(DialogType,scnh,scnw : INTEGER);
{
This procedure locates the 'OK' and 'Cancel' buttons.
}
VAR
v1,v2,v3,v4 : INTEGER;
Mac : BOOLEAN;
Procedure Swap(VAR m1,m2,m3,m4 : INTEGER);
VAR
Temp : INTEGER;
BEGIN
Temp:=m1;
m1:=m3;
m3:=Temp;
Temp:=m2;
m2:=m4;
m4:=Temp;
END; {of Swap}
BEGIN
Mac:=FALSE;
PathName:='External\Data\';
GetVersion(v1,v2,v3,v4);
IF v4 = 1 THEN
BEGIN
Mac:=TRUE;
PathName:=':Externals:External Data:';
END;
IF DialogType = 1 THEN
BEGIN
px1:=(scnw DIV 2) - 80;
px2:=(scnw DIV 2) - 10;
px3:=(scnw DIV 2) + 10;
px4:=(scnw DIV 2) + 80;
IF Mac THEN SWAP(px1,px2,px3,px4);
py1:=scnh-40;
py2:=scnh-20;
py3:=py1;
py4:=py2;
END ELSE IF DialogType = 2 THEN
BEGIN
px1:=scnw - 180;
px2:=scnw - 110;
px3:=scnw - 90;
px4:=scnw - 20;
IF Mac THEN SWAP(px1,px2,px3,px4);
py1:=scnh-40;
py2:=scnh-20;
py3:=py1;
py4:=py2;
END ELSE
BEGIN
px1:=scnw - 90;
px2:=scnw - 20;
px3:=px1;
px4:=px2;
py1:=scnh -70;
py2:=scnh - 50;
py3:=scnh - 40;
py4:=scnh - 20;
IF Mac THEN SWAP(py1,py2,py3,py4);
END;
END; {of Locate Buttons}
Procedure MakeDialog1;
CONST
y1=100;
scnh=250;
scnw=290;
DialogType = 1;
VAR
h : INTEGER;
BEGIN
AlignScr(scnw,x1,x2);
y2:=y1+scnh;
LocateButtons(DialogType,scnh,scnw);
BeginDialog(1,1,x1,y1,x2,y2);
AddButton('OK',1,1,px1,py1,px2,py2);
AddButton('Cancel',2,1,px3,py3,px4,py4);
h:=45;
AddField('Size:',4,1,20,4+h,60,20+h);
AddField('',5,2,80,5+h,140,20+h);
AddField('in',17,1,148,5+h,170,20+h);
AddField('Length:',6,1,19,29+h,70,45+h);
AddField('',7,2,80,30+h,140,45+h);
AddField('in',18,1,148,30+h,170,45+h);
h:=0;
AddField('View:',8,1,190,5+h,245,20+h);
AddButton('Top',9,3,190,45+h,235,60+h);
AddButton('Side',10,3,190,25+h,235,40+h);
AddField('Series:',16,1,20,4,75,20);
AddButton('Inch',14,3,20,25,70,40);
AddButton('Metric',15,3,75,25,135,40);
h:=110;
AddField('Threads:',20,1,20,h+4,75,h+20);
AddButton('Type 1 (dashed lines)',21,3,20,h+25,200,h+40);
AddButton('Type 2 (solid lines)',22,3,20,h+45,200,h+60);
AddButton('Type 3 (detailed threads)',23,3,20,h+65,190,h+80);
EndDialog;
END;
BEGIN
MakeDialog1;
END;
Procedure GetData;
{
This procedure opens the data file and reads the data.
}
LABEL 15,20,99;
VAR
File,Filename,WarningStr : STRING;
BEGIN
{
Open the data file.
}
IF Inch=True THEN
File:=Filename1
ELSE
File:=Filename2;
Filename:=Concat(Pathname,File);
SizeNotFound:=FALSE;
Open(Filename);
{
Display the warning dialog box if the data file cannot be found.
}
IF FndError THEN BEGIN
ClrDialog;
Sysbeep;
WarningStr:=Concat('The data file <',File,'> cannot be found. Check your Toolkit Manual for further explanation.');
AlrtDialog(WarningStr);
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!');
SizeNotFound:=TRUE;
GoTo 99;
20:Close(Filename);
99:END;
Procedure GetInfo;
{
This procedure displays the main dialog box and retrieves the information.
}
LABEL 10,15,99;
VAR
Done,OK:Boolean;
Item:Integer;
RFlag : ARRAY[1..3] OF 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;
Inch:=TRUE;
View:=2;
ThdType:=1;
RFlag[1]:=10;
RFlag[2]:=14;
RFlag[3]:=ThdType+20;
Size1:='1/2';
L:=1.000;
GetDialog(1);
SetTitle('Shoulder Screws');
SetField(5,Size1);
SetField(7,Num2Str(3,L));
SetItem(RFlag[1],TRUE);
SetItem(RFlag[2],TRUE);
SetItem(RFlag[3],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=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;
IF (Item > 20) AND (Item < 24) THEN
BEGIN
SetRButton(3,Item);
ThdType:=Item-20;
END;
UNTIL Done;
IF Abort THEN GOTO 99;
Size1:=GetField(5);
Size:=Concat('''',Size1,'''');
UprString(Size);
OK:=ValidNumStr(GetField(7),L);
GetData;
IF Abort THEN GOTO 99;
IF SizeNotFound THEN
BEGIN
Done:=FALSE;
SelField(5);
GOTO 15;
END;
99:ClrDialog;
END;
{
Main program.
}
BEGIN
DselectAll;
PushAttrs;
{
Display the main dialog box and get the information.
}
SSDialog;
SetCursor(ArrowC);
GetInfo;
IF Abort THEN GoTo 99;
{
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;
di:=t-2*td;
p:=1/tpi;
p1:=t - 5*td/2;
nThreads:=(tl-g-p)*tpi;
q1:=tl-(nThreads + 1.5)*p;
{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));
IF L = 0 THEN GOTO 90;
{
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 = 3 THEN GOTO 30;
{
Draw Type 1 or Type 2 threads.
}
L1:=nThreads*p + 2*td;
g:=tl - L1;
Absolute;
MoveTo(x0 - di/2, y0 - L);
Relative;
Rect(0,0,di,-g);
Move(0, -g);
ClosePoly;
Poly(0,0, -td,-td, 0,-(L1-2*td), td,-td, di,0 ,td,td, 0,(L1-2*td), -td,td);
IF ThdType = 1 THEN
BEGIN
Move(td,-td);
LineTo(-t, 0);
Move(0, -(L1-2*td));
LineTo(t, 0);
Move(-td, -td);
PenPat(-2);
PenSize(kps1*FPenSize);
LineTo(0, L1);
Move(-di, -L1);
LineTo(0, L1);
END ELSE
BEGIN
Move(td,-td);
FOR i:=1 TO nThreads+1 DO
BEGIN
LineTo(-t, 0);
Move(t, -p);
END;
PenSize(kps2*FPenSize);
MoveTo(-td, 3*p/2);
FOR i:=1 TO nThreads DO
BEGIN
LineTo(-di,0);
Move(di,p);
END;
END;
GOTO 90;
{
Draw Type 3 (detailed) threads.
}
{
Draw bottom thread.
}
30:Absolute;
MoveTo(x0 - t/2 + 3*td/2, y0 - L - tl);
Relative;
ClosePoly;
BeginPoly;
LineTo(0, 0);
LineTo(p1, 0);
LineTo(td/2, p/4);
LineTo(-td/2, p/4);
LineTo(td, p/2);
LineTo(-(t-td/2), -p/2);
EndPoly;
Absolute;
MoveTo((x0 + t/2 - td/2), (y0 - L - tl + p/4));
Relative;
LineTo(-(t/2 - td/2), 0);
LineTo(di/2, p/4);
{
Draw first whole thread.
}
Absolute;
MoveTo((x0 - t/2 + td/2), (y0 - L - tl + p/2));
Relative;
Poly(0,0, (t - td/2),p/2, -td, p/2, -di,-p/2);
Poly (0,0, di,p/2, td,p/2, -t,-p/2);
{
Draw remaining whole threads.
}
Relative;
ClosePoly;
FOR i:=1 TO nThreads-1 DO BEGIN
Poly(0,0, t,p/2, -td,p/2, -di,-p/2);
Poly(0,0, di,p/2, td,p/2, -t,-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,q1);
Line(di,0);
Line(0,-q1);
Line(td,-p/2);
EndPoly;
Move(-(t-td),0);
Line(di/2,p/4);
Line(-(di+td)/2,0);
90:Group;
PopAttrs;
99:END;
RUN(ShoulderScrew);