home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 1998 March
/
Chip_1998-03_cd.bin
/
tema
/
MINICAD
/
MC7DEMO
/
MINICAD.1
/
DOWL_PIN.MPC
< prev
next >
Wrap
Text File
|
1997-04-30
|
4KB
|
264 lines
Procedure DowelPin;
{
⌐1997, Diehl Graphsoft, Inc.
Developed by Tom Urie
This procedure draws a dowel pin.
}
LABEL 20,30,99;
CONST
Bk=0.97; {Used to calculate chamfer}
Theta=15; {Angle of chamfer}
CF=0.33333; {Used to determind radius of round end}
VAR
A1,A2,B,C,D,L,SF,x0,y0 : REAL;
View : INTEGER;
Abort,OK,Inch : BOOLEAN;
UPI : REAL;
Fmt : INTEGER;
UM,UM2 : STRING;
UName,DA : LONGINT;
Procedure PinDialog;
{
This procedure defines the 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 LocateButtons2(scnh,scnw : INTEGER);
{
This procedure locates the 'OK' and 'Cancel' buttons centered at the bottom of the dialog box.
}
VAR
v1,v2,v3,v4 : INTEGER;
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
px1:=scnw - 180;
px2:=scnw - 110;
px3:=scnw - 90;
px4:=scnw - 20;
py1:=scnh-40;
py2:=scnh-20;
py3:=py1;
py4:=py2;
GetVersion(v1,v2,v3,v4);
IF v4 = 1 THEN Swap(px1,px2,px3,px4);
END; {of Locate Buttons1}
Procedure MakeDialog;
CONST
y1=100;
scnh=135; scnw=280;
h=30;
BEGIN
AlignScr(scnw,x1,x2);
y2:=y1+scnh;
LocateButtons2(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);
AddField('Diameter:',4,1,20,44-h,90,60-h);
AddField('',5,2,100,45-h,150,60-h);
AddField('Length:',6,1,20,79-h,80,95-h);
AddField('',7,2,100,80-h,150,95-h);
AddField('View:',8,1,210,39-h,265,55-h);
AddButton('Top',9,3,210,80-h,265,95-h);
AddButton('Side',10,3,210,60-h,265,75-h);
AddField('',12,1,160,45-h,185,60-h);
AddField('',13,1,160,80-h,185,95-h);
EndDialog;
END;
BEGIN
MakeDialog;
END;
Procedure GetInfo;
{
This procedure displays the dialog box and retrieves the information.
}
LABEL 10,99;
VAR
Item:Integer;
RFlag : ARRAY[1..2] OF INTEGER;
Done:Boolean;
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
View:=2;
Done:=FALSE;
Abort:=FALSE;
RFlag[1]:=10;
GetDialog(1);
SetTitle('Dowel Pins');
SetItem(RFlag[1],TRUE);
SelField(5);
IF Inch THEN BEGIN
SetField(12,'in');
SetField(13,'in');
END
ELSE BEGIN
SetField(12,'mm');
SetField(13,'mm');
END;
10:REPEAT
DialogEvent(Item);
IF Item=1 THEN
Done:=True;
IF Item=2 THEN
BEGIN
Done:=TRUE;
Abort:=TRUE;
END;
IF (Item = 9) OR (Item = 10) THEN
BEGIN
SetRButton(1,Item);
View:=Item-8;
END;
UNTIL Done;
IF Abort THEN GOTO 99;
OK:=ValidNumStr(GetField(5),D);
OK:=ValidNumStr(GetField(7),L);
IF (D <= 0) OR ((VIEW = 2) AND (L <= 0)) THEN BEGIN
Sysbeep;
Done:=FALSE;
GOTO 10;
END;
99:ClrDialog;
END;
{
Main program.
}
BEGIN
DselectAll;
{
Get units/inch. Determine if units are inches or metric.
}
GetUnits(UName,DA,Fmt,UPI,UM,UM2);
IF (UPI=25.4) OR (UPI=2.54) OR (UPI=0.0254) THEN BEGIN
SF:=UPI/25.4;
Inch:=FALSE;
END
ELSE BEGIN
SF:=UPI;
Inch:=TRUE;
END;
{
Display the dialog box and get the information.
}
PinDialog;
SetCursor(ArrowC);
GetInfo;
IF Abort THEN GoTo 99;
{
Calculate the variables needed to draw the dowel pin.
}
B:=D*Bk;
A1:=(D-B)/2;
A2:=A1/Tan(Deg2Rad(Theta));
C:=CF*D;
{
Adjust variables for units.
}
D:=D*SF;
L:=L*SF;
B:=B*SF;
A1:=A1*SF;
A2:=A2*SF;
C:=C*SF;
{
Get the insertion point.
}
GetPt(x0,y0);
Absolute;
MoveTo(x0,y0);
Relative;
IF View = 1 THEN GOTO 20;
{
Draw Side View.
}
MoveTo(L-A2,D/2);
OpenPoly;
BeginPoly;
LineTo(0,0);
LineTo(A2,-A1);
LineTo(0,-B);
LineTo(-A2,-A1);
ArcTo(-(L-A2),0,C);
ArcTo(0,D,C);
LineTo(L-A2,0);
EndPoly;
LineTo(0,-D);
Move(-(L-A2-C),0);
LineTo(0,D);
GOTO 30;
{
Draw Top View.
}
20:Arc(-D/2,D/2,D/2,-D/2,0,360);
30:Group;
99:END;
Run(DowelPin);