home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 1998 March
/
Chip_1998-03_cd.bin
/
tema
/
MINICAD
/
MC7DEMO
/
MINICAD.1
/
DWG_FMS.MPC
< prev
next >
Wrap
Text File
|
1997-04-30
|
15KB
|
620 lines
Procedure DrawingForm;
{
⌐1997, Diehl Graphsoft, Inc.
Developed by Tom Urie
This procedure creates an ASME, Archetectural, or ISO drawing border.
}
LABEL 10,20,99;
CONST
POffsetD=0; {Default print offset.}
BWidthD=1/4; {Default width of drawing border.}
LDivD=3.0; {Approximate width of grid. Exact size depends on size of drawing border.}
TSize=12; {Size of grid text.}
RecordName='TitleBlkInfo'; {Name of record attached to title block containing title block information.}
SymbolName='TitleBlk'; {Name of title block symbol definition.}
VAR
W,H : ARRAY [1..3,1..6] OF REAL;
x1,y1,x2,y2: REAL;
dx1,dy1,dy,POffset,Bwidth,LDiv,TBWdth, TBHgt : REAL;
n,Size,Type,OldType : INTEGER;
i,j,k,NFields : INTEGER;
nZones : ARRAY[1..6,1..2] OF INTEGER;
RFlag : ARRAY[1..2] OF INTEGER;
AChar,Field,s : STRING;
FieldName,FieldNameD,FieldVal,NewVal : ARRAY[1..15] OF STRING;
Abort,ShowGrids,TitleBlock,OK : BOOLEAN;
TitleBlkH,RecordH,LayerH,SymbolH : HANDLE;
Width,sx1,sy1,sx2,sy2,px1,px2,px3,px4,py1,py2,py3,py4 : INTEGER;
UPI : REAL;
Fmt : INTEGER;
UM,UM2 : STRING;
UName,DA : LONGINT;
Procedure AlignScr(Width:INTEGER; VAR sx1,sx2:INTEGER);
VAR
scrx1,scry1,scrx2,scry2:INTEGER;
BEGIN
GetScreen(scrx1,scry1,scrx2,scry2);
sx1:=((scrx1+scrx2) div 2)-(Width div 2);
sx2:=sx1+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 BorderDialog;
{
This procedure defines the main dialog boxe.
}
Procedure MakeBorderDialog;
CONST
sy1=100;
scnh =175; scnw =390;
h=30;
DialogType = 3;
BEGIN
AlignScr(scnw,sx1,sx2);
sy2:=sy1+scnh;
LocateButtons(DialogType,scnh,scnw );
BeginDialog(1,1,sx1,sy1,sx2,sy2);
AddButton('OK',1,1,px1,py1,px2,py2);
AddButton('Cancel',2,1,px3,py3,px4,py4);
AddField('Type:',5,1,20,40-h,75,55-h);
AddButton('ASME',6,3,20,65-h,75,80-h);
AddButton('Arch',7,3,20,85-h,75,100-h);
AddButton('ISO',8,3,20,105-h,75,120-h);
AddButton('Show Title Block',9,2,175,100-h,310,115-h);
AddButton('Show Grids',10,2,175,125-h,265,140-h);
AddField('Size:',17,1,100,40-h,150,55-h);
AddButton('',11,3,100,65-h,115,80-h);
AddButton('',12,3,100,85-h,115,100-h);
AddButton('',13,3,100,105-h,115,120-h);
AddButton('',14,3,100,125-h,115,140-h);
AddButton('',15,3,100,145-h,115,160-h);
AddButton('',16,3,100,165-h,115,180-h);
AddField('Print Offset:',18,1,175,45-h,275,60-h);
AddField('',19,2,285,45-h,345,60-h);
AddField('Border Width:',20,1,175,70-h,275,85-h);
AddField('',21,2,285,70-h,345,85-h);
AddField('A',22,1,118,65-h,135,80-h);
AddField('B',23,1,118,85-h,135,100-h);
AddField('C',24,1,118,105-h,135,120-h);
AddField('D',25,1,118,125-h,135,140-h);
AddField('E',26,1,118,145-h,135,160-h);
AddField('F',27,1,118,165-h,155,180-h);
AddField('in.',28,1,353,45-h,375,60-h);
AddField('in.',29,1,353,70-h,375,85-h);
EndDialog;
END;
BEGIN
MakeBorderDialog;
END;
Procedure TitleDialog;
{
This procedure defines the title block information dialog box.
}
Procedure MakeTitleDialog(NFields : INTEGER);
CONST
sy1=100;
scnw=325;
h1=30;
DialogType = 1;
VAR
scnh,i,j,h : INTEGER;
BEGIN
scnh:=85+25*NFields;
AlignScr(scnw,sx1,sx2);
sy2:=sy1+scnh;
LocateButtons(DialogType,scnh,scnw );
BeginDialog(2,1,sx1,sy1,sx2,sy2);
AddButton('OK',1,1,px1,py1,px2,py2);
AddButton('Cancel',2,1,px3,py3,px4,py4);
h:=25-h1;
j:=3;
FOR i:= 1 TO NFields DO BEGIN
h:=h+25;
j:=j+2;
AddField(FieldNameD[i],j,1,20,h,125,h+15);
AddField(FieldVal[i],j+1,2,135,h,300,h+15);
END;
EndDialog;
END;
BEGIN
MakeTitleDialog(NFields);
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 GetBorderInfo;
{
This procedure displays the main dialog box and retrieves the information.
}
VAR
Done : Boolean;
Item,i : Integer;
A : STRING;
BEGIN
Done:=FALSE;
Abort:=FALSE;
Size:=1;
Type:=1;
POffset:=POffsetD;
BWidth:=BWidthD;
TitleBlock:=FALSE;
ShowGrids:=FALSE;
RFlag[1]:=6;
RFlag[2]:=11;
GetDialog(1);
SetTitle('Drawing Forms');
SetItem(6,TRUE);
SetItem(11,TRUE);
SetField(19,Num2StrF(POffset));
SetField(21,Num2StrF(BWidth));
SelField(19);
REPEAT
DialogEvent(Item);
IF Item=1 THEN
Done:=TRUE;
IF Item=2 THEN BEGIN
Done:=TRUE;
Abort:=TRUE;
END;
IF (Item > 5) AND (Item < 9) THEN BEGIN
SetRButton(1,Item);
OldType:=Type;
Type:=Item-5;
IF (Item = 8) AND (OldType <> 3) THEN BEGIN
SetField(22,'A0');
SetField(23,'A1');
SetField(24,'A2');
SetField(25,'A3');
SetField(26,'A4');
SetField(27,'<n/a>');
SetField(19,Num2StrF(POffset*25.4));
SetField(21,Num2StrF(BWidth*25.4));
SetField(28,'mm');
SetField(29,'mm');
SetRButton(2,11);
Size:=1;
END
ELSE IF ((Type = 1) OR (Type = 2)) AND (OldType = 3) THEN BEGIN
SetField(22,'A');
SetField(23,'B');
SetField(24,'C');
SetField(25,'D');
SetField(26,'E');
SetField(27,'F');
SetField(19,Num2StrF(POffset));
SetField(21,Num2StrF(BWidth));
SetField(28,'in.');
SetField(29,'in.');
END;
END;
IF Item=9 THEN BEGIN
TitleBlock:=NOT TitleBlock;
SetItem(9,TitleBlock);
END;
IF Item = 10 THEN BEGIN
ShowGrids:=NOT ShowGrids;
SetItem(10,ShowGrids);
END;
IF (Item > 10) AND (Item < 17) THEN BEGIN
IF (Type = 3) AND (Item = 16) THEN BEGIN
SysBeep;
SetRButton(2,11);
Size:=1;
END
ELSE BEGIN
SetRButton(2,Item);
Size:=Item-10;
END;
END;
UNTIL Done;
OK:=ValidNumStr(GetField(19), POffset);
OK:=ValidNumStr(GetField(21), BWidth);
IF Type = 3 THEN BEGIN
POffset:=POffset/25.4;
BWidth:=BWidth/25.4;
END;
ClrDialog;
END;
Procedure GetTitleInfo;
{
This procedure displays the title block information dialog box and retrieves the information.
}
VAR
Done : BOOLEAN;
i,n,Item : INTEGER;
BEGIN
Done:=FALSE;
Abort:=FALSE;
GetDialog(2);
SetTitle('Title Block Information');
REPEAT
DialogEvent(Item);
IF Item=1 THEN
Done:=TRUE;
IF Item=2 THEN BEGIN
Done:=TRUE;
Abort:=TRUE;
END;
UNTIL Done;
n:=4;
FOR i:=1 TO NFields DO BEGIN
n:=n+2;
NewVal[i]:=GetField(n);
END;
ClrDialog;
END;
BEGIN
{
Main Program.
Display the main dialog box and get the information.
}
BorderDialog;
SetCursor(ArrowC);
GetBorderInfo;
IF Abort THEN GOTO 99;
DselectAll;
PushAttrs;
{
Get units/inch adjust constants.
}
GetUnits(UName,DA,Fmt,UPI,UM,UM2);
POffset:=POffset*UPI;
BWidth:=BWidth*UPI;
LDiv:=LDivD*UPI;
{
Set attributes.
}
FillPat(0);
PenFore(255);
PenSize(20);
PenPat(2);
NameClass('None');
{
Assign standard sheet sizes to the variables W & H.
}
IF Type = 1 THEN BEGIN
W[1,1]:=11;W[1,2]:=17;W[1,3]:=22;W[1,4]:=34;
W[1,5]:=44;W[1,6]:=40;
H[1,1]:=8.5;H[1,2]:=11;H[1,3]:=17;H[1,4]:=22;
H[1,5]:=34;H[1,6]:=28;
END
ELSE IF Type = 2 THEN BEGIN
W[1,1]:=12;W[1,2]:=18;W[1,3]:=24;W[1,4]:=36;
W[1,5]:=48;W[1,6]:=42;
H[1,1]:=9;H[1,2]:=12;H[1,3]:=18;H[1,4]:=24;
H[1,5]:=36;H[1,6]:=30;
END
ELSE BEGIN
W[1,1]:=46.811;W[1,2]:=33.110;W[1,3]:=23.386;
W[1,4]:=16.535;W[1,5]:=11.693;
H[1,1]:=33.110;H[1,2]:=23.386;H[1,3]:=16.535;
H[1,4]:=11.693;H[1,5]:=8.268;
END;
{
Calculate outer and inner border sizes and adjust for units per inch.
}
FOR n:=1 TO 6 DO BEGIN
W[2,n]:=W[1,n]*UPI-2*POffset;
W[3,n]:=W[2,n]-2*BWidth;
H[2,n]:=H[1,n]*UPI-2*POffset;
H[3,n]:=H[2,n]-2*BWidth;
END;
x1:=W[3,Size]/2;
y1:=H[3,Size]/2;
x2:=W[2,Size]/2;
y2:=H[2,Size]/2;
{
Insert title block symbol & text.
}
Layer('Drawing Form');
SetScale(1);
Absolute;
IF NOT TitleBlock THEN GOTO 10;
{
Get the title block symbol handle, record handle and number of fields.
}
SymbolH:=GetObject(SymbolName);
IF SymbolH = NIL THEN BEGIN
SysBeep;
s:=Concat('There is no title block symbol named ',SymbolName,' in the symbol library!');
AlrtDialog(s);
GOTO 99;
END;
RecordH:=GetObject(RecordName);
IF RecordH = NIL THEN BEGIN
SysBeep;
s:=Concat('There is no record named ',RecordName,' in this drawing!');
AlrtDialog(s);
GOTO 99;
END;
NFields:=NumFields(RecordH);
{
Assign the field names to the variable FieldName[i]. Append a colon to the field names to display in the dialog box.
}
FOR i:=1 TO NFields DO BEGIN
FieldName[i]:=GetFldName(RecordH,i);
FieldNameD[i]:=Concat(FieldName[i],':');
END;
{
Get the current default values of all fields of the record.
}
FOR i:=1 TO NFields DO BEGIN
Field:=Concat('''',RecordName,'''','.','''',FieldName[i],'''');
FieldVal[i]:=EvalStr(SymbolH,Field);
END;
{
Assign any delault values for the title block here; Field[4] is the date, Field[5] is the drawing size.
}
FieldVal[4]:=Date(2,0);
IF (Type = 1) OR (Type = 2) THEN
FieldVal[5]:=Chr(64+Size)
ELSE BEGIN
IF Size = 1 THEN FieldVal[5]:='A0'
ELSE IF Size = 2 THEN FieldVal[5]:='A1'
ELSE IF Size = 3 THEN FieldVal[5]:='A2'
ELSE IF Size = 4 THEN FieldVal[5]:='A3'
ELSE FieldVal[5]:='A4';
END;
{
Display the title block information dialog box.
}
TitleDialog;
GetTitleInfo;
IF Abort THEN GOTO 99;
Symbol(SymbolName,x1,-y1,0);
SymbolH:=LSActLayer;
{
Get the title block information and enter the values into the record.
}
FOR i:=1 TO NFields DO BEGIN
SetRField(SymbolH,RecordName,FieldName[i],NewVal[i]);
END;
{
Draw Borders.
}
10:PenSize(20);
Rect(-x1,y1,x1,-y1);
PenSize(7);
Rect(-x2,y2,x2,-y2);
{
Draw grids.
}
IF NOT ShowGrids THEN GOTO 20;
{
Draw grid lines.
}
IF Type = 3 THEN BEGIN
NZones[1,1]:=12; NZones[1,2]:=16;
NZones[2,1]:=8; NZones[2,2]:=12;
NZones[3,1]:=6; NZones[3,2]:=8;
NZones[4,1]:=4; NZones[4,2]:=6;
NZones[5,1]:=2; NZones[5,2]:=2;
END
ELSE BEGIN
NZones[1,1]:=2; NZones[1,2]:=2;
NZones[2,1]:=2; NZones[2,2]:=4;
NZones[3,1]:=4; NZones[3,2]:=4;
NZones[4,1]:=4; NZones[4,2]:=8;
NZones[5,1]:=8; NZones[5,2]:=8;
NZones[6,1]:=6; NZones[6,2]:=8;
END;
dx1:=2*x1/NZones[Size,2];
dy1:=2*y1/NZones[Size,1];
TextFont(3);
TextSize(TSize);
TextFace([bold]);
TextFlip(0);
TextRotate(#0);
TextSpace(2);
TextJust(2);
Absolute;
MoveTo(-x1,y1+BWidth);
Relative;
FOR n:=1 TO NZones[Size,2]-1 DO BEGIN
MoveTo(dx1,-BWidth);
LineTo(0,BWidth);
END;
Absolute;
MoveTo(-x1,-(y1+BWidth));
Relative;
FOR n:=1 TO NZones[Size,2]-1 DO BEGIN
MoveTo(dx1,BWidth);
LineTo(0,-BWidth);
END;
Absolute;
MoveTo(-(x1+BWidth),y1);
Relative;
FOR n:=1 TO NZones[Size,1]-1 DO BEGIN
MoveTo(BWidth,-dy1);
LineTo(-BWidth,0);
END;
Absolute;
MoveTo(x1,y1);
Relative;
FOR n:=1 TO NZones[Size,1]-1 DO BEGIN
MoveTo(BWidth,-dy1);
LineTo(-BWidth,0);
END;
{
Enter grid numbers at top and bottom.
}
dy:=BWidth/2+0.6*TSize*UPI/72;
Absolute;
MoveTo(x1+dx1/2,y1+dy);
Relative;
FOR n:=1 TO NZones[Size,2] DO BEGIN
TextOrigin(-dx1,0);
BeginText;
Num2Str(0,n)
EndText;
END;
dy:=BWidth/2-0.6*TSize*UPI/72;
Absolute;
MoveTo(x1+dx1/2,-(y1+dy));
Relative;
FOR n:=1 TO NZones[Size,2] DO BEGIN
Achar:=Chr(64+n);
TextOrigin(-dx1,0);
BeginText;
Num2Str(0,n)
EndText;
END;
{
Enter grid letters along sides.
}
Absolute;
MoveTo(-(x1+BWidth/2),-(y1+dy1/2));
Relative;
FOR n:=1 TO NZones[Size,1] DO BEGIN
Achar:=Chr(64+n);
TextOrigin(0,dy1);
BeginText;
Achar
EndText;
END;
Absolute;
MoveTo(x1+BWidth/2,-(y1+dy1/2));
Relative;
FOR n:=1 TO NZones[Size,1] DO BEGIN
Achar:=Chr(64+n);
TextOrigin(0,dy1);
BeginText;
AChar
EndText;
END;
20:Group;
PopAttrs;
99:END;
RUN(DrawingForm);