home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 1998 March
/
Chip_1998-03_cd.bin
/
tema
/
MINICAD
/
MC7DEMO
/
MINICAD.1
/
WASHER.MPC
< prev
next >
Wrap
Text File
|
1997-04-30
|
14KB
|
780 lines
Procedure Washer;
{
(c)1997, Diehl Graphsoft, Inc.
Developed by Tom Urie
This procedure draws plain, lock, and user specified washers.
}
LABEL 10,20,30,99;
CONST
Filename1='WashPlnE.txt';
Filename2='WashPlnM.txt';
Filename3='WashLokE.txt';
Filename4='WashLokM.txt';
PathNameW = 'External\Data\';
PathNameM = ':Externals:External Data:';
SWF=0.05; {Used to determine the width of the slot on lock washers.}
Theta=30.0; {Angle of the slot on lock washers.}
VAR
ID,OD,T : REAL;
OD1,T1 : ARRAY [1..3] OF REAL;
x0,y0,x1,y1,x2,y2,SW : REAL;
Style,Type,View,Series,n : INTEGER;
RFlag : ARRAY[1..5] OF INTEGER;
Ans,Abort,OK,Inch,SizeNotFound : BOOLEAN;
Sz,Size,Size1,Pathname : STRING;
SA,DA:LONGINT;
Fmt:INTEGER;
SF,UPI:REAL;
UM,UM2:STRING;
Procedure WasherDialog;
{
This procedure defines the various dialog boxes.
}
VAR
h,DialogType,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:=PathNameW;
GetVersion(v1,v2,v3,v4);
IF v4 = 1 THEN
BEGIN
Mac:=TRUE;
PathName:=PathNameM;
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;
{
This procedure defines the dialog box for Plain Washers.
}
CONST
y1=100;
scnh=245;
scnw=280;
BEGIN
DialogType:=1;
AlignScr(scnw,x1,x2);
y2:=y1+scnh;
LocateButtons(DialogType,scnh,scnw);
BeginDialog(1,1,x1,y1,x2,y2);
h:=40;
AddButton('OK',1,1,px1,py1,px2,py2);
AddButton('Cancel',2,1,px3,py3,px4,py4);
AddField('Type:',13,1,20,44-h,60,60-h);
AddButton('Inch (Type B Plain Washer)',14,3,20,65-h,250,80-h);
AddButton('Metric (Metric Plain Washer)',15,3,20,85-h,260,100-h);
AddField('Bolt or Screw Size:',4,1,20,117-h,160,133-h);
AddField('',5,2,165,118-h,225,133-h);
AddField('in',16,1,233,118-h,255,133-h);
h:=45;
AddField('Series:',6,1,20,154-h,100,170-h);
AddButton('Narrow',7,3,20,175-h,100,190-h);
AddButton('Regular',8,3,20,195-h,100,210-h);
AddButton('Wide',9,3,20,215-h,100,230-h);
AddField('View:',10,1,165,154-h,205,170-h);
AddButton('Top',11,3,165,175-h,210,190-h);
AddButton('Side',12,3,165,195-h,210,210-h);
EndDialog;
END;
Procedure MakeDialog2;
{
This procedure defines the dialog box for User Defined Plain Washers.
}
CONST
y1=100;
scnh=170;
scnw=270;
BEGIN
DialogType:=3;
AlignScr(scnw,x1,x2);
y2:=y1+scnh;
LocateButtons(DialogType,scnh,scnw);
BeginDialog(2,1,x1,y1,x2,y2);
h:=30;
AddButton('OK',1,1,px1,py1,px2,py2);
AddButton('Cancel',2,1,px3,py3,px4,py4);
AddField('Inside Diameter:',4,1,20,44-h,143,60-h);
AddField('',5,2,156,45-h,240,60-h);
AddField('Outside Diameter:',6,1,20,69-h,143,85-h);
AddField('',7,2,156,70-h,240,85-h);
AddField('Thickness:',8,1,20,94-h,143,110-h);
AddField('',9,2,156,95-h,240,110-h);
AddField('View:',10,1,20,124-h,90,140-h);
AddButton('Top',11,3,20,145-h,65,160-h);
AddButton('Side',12,3,20,165-h,65,180-h);
EndDialog;
END;
Procedure MakeDialog3;
{
This procedure defines the dialog box for Lock Washers.
}
CONST
y1=100;
scnh=225;
scnw=280;
BEGIN
DialogType:=1;
AlignScr(scnw,x1,x2);
y2:=y1+scnh;
LocateButtons(DialogType,scnh,scnw);
BeginDialog(3,1,x1,y1,x2,y2);
AddButton('OK',1,1,px1,py1,px2,py2);
AddButton('Cancel',2,1,px3,py3,px4,py4);
h:=40;
AddField('Type:',13,1,20,44-h,60,60-h);
AddButton('Inch',14,3,20,65-h,70,80-h);
AddButton('Metric',15,3,80,65-h,140,80-h);
AddField('Bolt or Screw Size:',4,1,20,97-h,160,113-h);
AddField('',5,2,165,98-h,225,113-h);
AddField('in',17,1,233,98-h,255,113-h);
h:=45;
AddField('Series:',6,1,20,134-h,100,150-h);
AddButton('Regular',7,3,20,155-h,100,170-h);
AddButton('Heavy',8,3,20,175-h,100,190-h);
AddButton('Extra Duty',9,3,20,195-h,100,210-h);
AddField('',16,1,105,195-h,155,210-h);
AddField('View:',10,1,165,134-h,205,150-h);
AddButton('Top',11,3,165,155-h,210,170-h);
AddButton('Side',12,3,165,175-h,210,190-h);
EndDialog;
END;
Procedure MakeDialog4;
{
This procedure defines the main dialog box.
}
CONST
y1=100;
scnh=150;
scnw=270;
BEGIN
DialogType:=1;
AlignScr(scnw,x1,x2);
y2:=y1+scnh;
LocateButtons(DialogType,scnh,scnw);
BeginDialog(4,1,x1,y1,x2,y2);
AddButton('OK',1,1,px1,py1,px2,py2);
AddButton('Cancel',2,1,px3,py3,px4,py4);
h:=40;
AddField('Type of Washer:',4,1,20,44-h,195,60-h);
AddButton('Plain Washer - Commercial',5,3,20,65-h,220,80-h);
AddButton('Plain Washer - User Defined',6,3,20,85-h,220,100-h);
AddButton('Helical Spring Lock Washer',7,3,20,105-h,220,120-h);
EndDialog;
END;
BEGIN
MakeDialog1;
MakeDialog2;
MakeDialog3;
MakeDialog4;
END;
Procedure GetData;
{
This procedure opens the data file and reads the data.
}
LABEL 10,20,99;
VAR
File,Filename,WarningStr : STRING;
File1 : ARRAY[1..4] OF STRING;
BEGIN
File1[1]:=Filename1;
File1[2]:=Filename2;
File1[3]:=Filename3;
File1[4]:=Filename4;
File:=File1[Type];
Filename:=Concat(Pathname,File);
Open(Filename);
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;
SizeNotFound:=FALSE;
WHILE NOT Eoln(Filename) DO BEGIN
IF Type <> 4 THEN
ReadLn(Sz,ID,OD1[1],OD1[2],OD1[3],T1[1],T1[2],T1[3])
ELSE
ReadLn(Sz,ID,OD1[1],OD1[2],T1[1],T1[2]);
IF Sz=Size THEN GoTo 20;
END;
Close(Filename);
10:SysBeep;
AlrtDialog('That size is not available!');
SizeNotFound:=TRUE;
GoTo 99;
20:Close(Filename);
OD:=OD1[Series];
T:=T1[Series];
IF OD = 0.0 THEN GOTO 10;
99:END;
Procedure SetRButton(i,Item : INTEGER);
BEGIN
IF RFlag[i] <> Item THEN BEGIN
SetItem(RFlag[i],FALSE);
SetItem(Item,TRUE);
RFlag[i]:=Item;
END;
END;
Procedure GetInfo1;
{
This procedure displays the Plain Washer dialog box and retrieves the information.
}
LABEL 10,99;
VAR
Done:boolean;
Item:integer;
BEGIN
Done:=FALSE;
Abort:=FALSE;
Type:=1;
View:=1;
Series:=2;
Inch:=TRUE;
RFlag[1]:=8;
RFlag[2]:=11;
RFlag[3]:=14;
GetDialog(1);
SetTitle('Plain Washers');
SetItem(RFlag[1],TRUE);
SetItem(RFlag[2],TRUE);
SetItem(RFlag[3],TRUE);
SetField(5,Size1);
10:SelField(5);
REPEAT
DialogEvent(Item);
IF Item=1 THEN
Done:=TRUE;
IF Item=2 THEN
BEGIN
Done:=TRUE;
Abort:=TRUE;
END;
IF (Item > 6) AND (Item < 10) THEN
BEGIN
SetRButton(1,Item);
Series:=Item-6;
END;
IF (Item=11) OR (Item=12) THEN
BEGIN
SetRButton(2,Item);
View:=Item-10;
END;
IF Item=14 THEN
BEGIN
SetRButton(3,Item);
Type:=1;
Inch:=TRUE;
SetField(16,'in');
SelField(5);
END;
IF Item=15 THEN
BEGIN
SetRButton(3,Item);
Type:=2;
Inch:=FALSE;
SetField(16,'mm');
SelField(5);
END;
UNTIL DONE;
IF Abort THEN GOTO 99;
Size1:=GetField(5);
UprString(Size);
Size:=ConCat('''',Size1,'''');
UprString(Size);
GetData;
IF Abort THEN GOTO 99;
IF SizeNotFound THEN
BEGIN
Done:=FALSE;
GOTO 10;
END;
99:ClrDialog;
END;
Procedure GetInfo2;
{
This procedure displays the User Defined Washer dialog box and retrieves the information.
}
LABEL 10,99;
VAR
Done:boolean;
Item:integer;
BEGIN
Done:=FALSE;
Abort:=FALSE;
View:=1;
RFlag[1]:=11;
GetDialog(2);
SetTitle('User Defined Plain Washers');
SetItem(RFlag[1],TRUE);
SetField(5,Num2Str(4,ID));
SetField(7,Num2Str(4,OD));
SetField(9,Num2Str(4,T));
10:SelField(5);
REPEAT
DialogEvent(Item);
IF Item=1 THEN
Done:=TRUE;
IF Item=2 THEN
BEGIN
Done:=TRUE;
Abort:=TRUE;
END;
IF (Item = 11) OR (Item = 12) THEN
BEGIN
SetRButton(1,Item);
View:=Item-10;
END;
UNTIL DONE;
IF Abort THEN GOTO 99;
OK:=ValidNumStr(GetField(5),ID);
OK:=ValidNumStr(GetField(7),OD);
OK:=ValidNumStr(GetField(9),T);
IF ID < OD THEN GOTO 99;
SysBeep;
AlrtDialog('ID must be less than OD!');
Done:=FALSE;
GOTO 10;
99:ClrDialog;
END;
Procedure GetInfo3;
{
This procedure displays the Helical Spring Lock Washer dialog box and retrieves the informaion.
}
LABEL 10,99;
VAR
Done:boolean;
Item:integer;
BEGIN
Done:=FALSE;
Abort:=FALSE;
Type:=3;
View:=1;
Series:=1;
Inch:=TRUE;
RFlag[1]:=7;
RFlag[2]:=11;
RFlag[3]:=14;
GetDialog(3);
SetTitle('Helical Spring Lock Washers');
SetItem(RFlag[1],TRUE);
SetItem(RFlag[2],TRUE);
SetItem(RFlag[3],TRUE);
SetField(5,Size1);
10:SelField(5);
REPEAT
DialogEvent(Item);
IF Item=1 THEN
Done:=TRUE;
IF Item=2 THEN
BEGIN
Done:=TRUE;
Abort:=TRUE;
END;
IF (Item > 6) AND (Item < 9) THEN
BEGIN
SetRButton(1,Item);
Series:=Item-6;
END;
IF Item = 9 THEN
BEGIN
If Type <> 4 THEN
BEGIN
SetRButton(1,Item);
Series:=Item-6;
END
ELSE Sysbeep;
END;
IF (Item=11) OR (Item=12) THEN
BEGIN
SetRButton(2,Item);
View:=Item-10;
END;
IF Item=14 THEN
BEGIN
SetRButton(3,Item);
Type:=3;
Inch:=TRUE;
SetField(16,'');
SetField(17,'in');
SelField(5);
END;
IF Item=15 THEN
BEGIN
SetRButton(3,Item);
Type:=4;
Inch:=FALSE;
SetField(16,'<n/a>');
SetField(17,'mm');
SelField(5);
IF Series = 3 THEN
BEGIN
SetRButton(1,7);
Series:=1;
END;
END;
UNTIL DONE;
IF Abort THEN GOTO 99;
Size1:=GetField(5);
UprString(Size);
Size:=ConCat('''',Size1,'''');
UprString(Size);
GetData;
IF Abort THEN GOTO 99;
IF SizeNotFound THEN
BEGIN
Done:=FALSE;
GOTO 10;
END;
99:ClrDialog;
END;
Procedure GetInfo4;
{
This procedure displays the main dialog box and retrieves the information.
}
VAR
Done:BOOLEAN;
Item:INTEGER;
BEGIN
Done:=FALSE;
Abort:=FALSE;
RFlag[1]:=5;
GetDialog(4);
SetTitle('Washers');
SetItem(RFlag[1],TRUE);
REPEAT
DialogEvent(Item);
IF Item = 1 THEN
Done:=TRUE;
IF Item = 2 THEN
BEGIN
Done:=TRUE;
Abort:=TRUE;
END;
IF Item > 4 THEN
BEGIN
SetRButton(1,Item);
Style:=Item-4;
END;
UNTIL DONE;
ClrDialog;
END;
{
Main program.
}
BEGIN
DSelectAll;
PushAttrs;
Inch:=TRUE;
Style:=1;
{
Create the dialog boxes.
}
WasherDialog;
SetCursor(ArrowC);
{
Display the main dialog box and get the type of washer to draw.
}
GetInfo4;
IF Abort THEN GOTO 99;
{
Display the proper dialog box and get the information.
}
IF Style = 1 THEN GetInfo1
ELSE IF Style = 2 THEN GetInfo2
ELSE GetInfo3;
IF Abort THEN GOTO 99;
{
IF (Style = 1) OR (Style = 3) THEN BEGIN
Ans:=FALSE;
10:IF Style = 1 THEN
GetInfo1
ELSE
GetInfo3;
IF Abort THEN GOTO 99;
GetData;
IF Abort THEN GOTO 99;
IF Ans THEN GOTO 10;
OD:=OD1[Series];
T:=T1[Series];
END
ELSE BEGIN
Type:=5;
ANS:=FALSE;
20:GetInfo2;
IF Abort THEN GOTO 99;
IF ID < OD THEN GOTO 30;
Ans:=TRUE;
SysBeep;
AlrtDialog('ID must be less than OD!');
GOTO 20;
END;
}
{
Get the units per inch and adjust the parameters accordingly.
}
GetUnits(SA,DA,Fmt,UPI,UM,UM2);
IF Inch = TRUE THEN
SF:=UPI
ELSE
SF:=UPI/25.4;
ID:=SF*ID;
OD:=SF*OD;
T:=SF*T;
30:GetPt(x0,y0);
{
Draw Top View.
}
IF View=1 THEN
BEGIN
{
Absolute;
MoveTo(x0,y0);
Relative;
Arc(-OD/2,OD/2,OD/2,-OD/2,0,360);
Arc(-ID/2,ID/2,ID/2,-ID/2,0,360);
IF (Type=3) OR (TYPE=4) THEN
BEGIN
SW:=SWF*ID;
x1:=SW/2;
y1:=Sqrt((OD/2)^2-x1^2);
x2:=SW/2;
y2:=Sqrt((ID/2)^2-x1^2);
Move(-x1,-y1);
Line(0,(y1-y2));
Move(2*x1,0);
Line(0,(y2-y1));
END;
}
IF (Type = 3) OR (TYPE = 4) THEN
SW:=SWF*ID
ELSE
SW:=0;
Absolute;
MoveTo(x0+SW/2, y0-OD/2);
Relative;
ClosePoly;
BeginPoly;
LineTo(0, 0);
ArcTo(OD/2-SW/2, 0, OD/2);
ArcTo(0, OD, OD/2);
ArcTo(-OD, 0, OD/2);
ArcTo(0, -OD, OD/2);
LineTo(OD/2-SW/2, 0);
IF (Type = 3) OR (Type = 4) THEN
LineTo(0, (OD - ID)/2)
ELSE
MoveTo(0, (OD - ID)/2);
ArcTo(-(ID/2-SW/2), 0, ID/2);
ArcTo(0, ID, ID/2);
ArcTo(ID, 0, ID/2);
ArcTo(0, -ID, ID/2);
LineTo(-(ID/2-SW/2), 0);
IF (Type = 3) OR (Type = 4) THEN
LineTo(0, -(OD - ID)/2)
ELSE
MoveTo(0, -(OD - ID)/2);
EndPoly;
END
{
Draw Side View.
}
ELSE BEGIN
Absolute;
MoveTo(x0,y0);
Relative;
Rect(-OD/2,t,OD/2,0);
PushAttrs;
PenPat(-2);
Move(-ID/2,0);
Line(0,t);
Move(ID,0);
Line(0,-t);
PopAttrs;
IF (Type=3) OR (TYPE=4) THEN
BEGIN
SW:=SWF*ID;
x1:=T*Tan(Deg2Rad(Theta));
Move(-ID/2,T);
Line(-x1,-T);
Move(-SW,0);
Line(x1,T);
END;
END;
PopAttrs;
99:END;
Run(Washer);