home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 1998 March
/
Chip_1998-03_cd.bin
/
tema
/
MINICAD
/
MC7DEMO
/
MINICAD.1
/
CUT_LINE.MPC
< prev
next >
Wrap
Text File
|
1997-04-30
|
5KB
|
272 lines
Procedure CutLine;
{
⌐1996, Diehl Graphsoft, Inc.
Developed by Tom Urie
This procedure creates a cut, or section, line and applies the section name. Up to 10 segments of the line are allowed.
}
LABEL 5,20,30,99;
CONST
LeaderLgth=0.375; {Length of leader}
ArrowLgth=0.1875; {Size of arrowhead}
Alpha=15; {Angle of arrowhead}
TxtCenter=0.1875; {Used to place text above arrowhead}
TxtOffset=0.125; {Used to center text on arrowhead}
TxtSizeR=14; {Reference text point size}
VAR
r,xs,ys,xt,yt,LScale,L1,L2,L3,L4,L5,TxtC : REAL;
x,y : ARRAY[1..10] OF REAL;
Theta : ARRAY[1..2] OF REAL;
i,j,k,TxtSize : INTEGER;
Section : STRING;
Abort : BOOLEAN;
LayerH,TxtH : HANDLE;
UPI,SF : REAL;
Fmt : INTEGER;
UM,UM2 : STRING;
UName,DA : LONGINT;
Procedure CutLineDialog;
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;
GetVersion(v1,v2,v3,v4);
IF v4 = 1 THEN Mac:=TRUE;
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 MakeDialog;
CONST
y1=100;
scnw = 240;
scnh = 90;
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);
AddField('Type in section name:',5,1,20,14+h,165,30+h);
AddField('A',6,2,170,15+h,210,30+h);
EndDialog;
END;
BEGIN
MakeDialog;
END;
Procedure GetInfo;
VAR
Done:Boolean;
Item:Integer;
BEGIN
Done:=FALSE;
Abort:=FALSE;
GetDialog(1);
SetTitle('Cut Line');
SelField(6);
REPEAT
DialogEvent(Item);
IF Item=1 THEN
Done:=TRUE;
IF Item=2 THEN
BEGIN
Done:=TRUE;
Abort:=TRUE;
END;
UNTIL Done;
Section:=GetField(6);
ClrDialog;
END;
{
Main Program
}
BEGIN
CutLineDialog;
SetCursor(ArrowC);
GetInfo;
IF Abort THEN GOTO 99;
{
Set attributes.
}
PushAttrs;
TextJust(2);
{
Get units per inch and layer scale.
}
GetUnits(UName,DA,Fmt,UPI,UM,UM2);
LayerH:=ActLayer;
LScale:=GetLScale(LayerH);
{
Get text size.
}
DSelectAll;
TextOrigin(0,0);
BeginText;
' '
EndText;
TxtH:=FSActLayer;
TxtSize:=GetSize(TxtH);
DelObject(TxtH);
TxtC:=TxtSize/TxtSizeR;
{
Adjust leader and arrowhead size for units, scale, and text size.
}
L1:=LeaderLgth*LScale*UPI;
L2:=ArrowLgth*LScale*UPI/Cos(Deg2Rad(Alpha));
L3:=2*L2*Sin(Deg2Rad(Alpha));
L4:=TxtCenter*LScale*UPI*TxtC;
L5:=TxtOffset*LScale*UPI*TxtC;
AngleVar;
Absolute;
{
Get path for cut line and draw lines
}
DSelectAll;
GetLine(x[1],y[1],x[2],y[2]);
IF (x[1]=x[2]) AND (y[1]=y[2]) THEN GOTO 99;
MoveTo(x[1],y[1]);
LineTo(x[2],y[2]);
Redraw;
j:=2;
FOR i:=3 TO 10 DO
BEGIN
GetPtL(x[i-1],y[i-1],x[i],y[i]);
IF (x[i-1]=x[i]) AND (y[i-1]=y[i]) THEN GOTO 5;
LineTo(x[i],y[i]);
Redraw;
j:=j+1;
END;
{
Determine on which side of line to put arrows
}
5:GetPt(xs,ys);
r:=Distance(x[1],y[1],x[2],y[2]);
Theta[1]:=Rad2Deg(ArcCos((x[2]-x[1])/r));
IF y[2] < y[1] THEN
Theta[1]:=360 - Theta[1];
r:=Distance(x[j],y[j],x[j-1],y[j-1]);
Theta[2]:=Rad2Deg(ArcCos((x[j]-x[j-1])/r));
IF y[j] < y[j-1] THEN
Theta[2]:=360 - Theta[2];
yt:=(ys-y[1])*Cos(Deg2Rad(Theta[1])) + (x[1]-xs)*Sin(Deg2Rad(Theta[1]));
IF yt < 0 THEN
BEGIN
Theta[1]:=180+Theta[1];
Theta[2]:=180+Theta[2];
END;
PenPat(2);
{
Draw extension lines and arrowheads
}
k:=1;
FOR i:=1 TO 2 DO
BEGIN
Absolute;
MoveTo(x[k],y[k]);
Relative;
Line(L1,#(Theta[i]+90));
Move(L3/2,#(Theta[i]+180));
FillPat(2);
ClosePoly;
Poly(0,0,L2,#(90-Alpha+Theta[i]),L2,#-(90-Alpha-Theta[i]));
{
Place text
}
xt:=x[k]-(L1+L2*Cos(Deg2Rad(Alpha))+L4)*Sin(Deg2Rad(Theta[i]));
yt:=y[k]+(L1+L2*Cos(Deg2Rad(Alpha))+L4)*Cos(Deg2Rad(Theta[i]))+L5;
Absolute;
TextOrigin(xt,yt);
FillPat(1);
BeginText;
Section
EndText;
k:=j;
END;
Group;
PopAttrs;
99:END;
Run(CutLine);