home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 1998 March
/
Chip_1998-03_cd.bin
/
tema
/
MINICAD
/
MC7DEMO
/
MINICAD.1
/
DRAWSPAC.MPC
< prev
next >
Wrap
Text File
|
1997-04-30
|
7KB
|
219 lines
PROCEDURE DrawSpaces;
{** This procedure reads the first two columns from each row of the selected worksheet and,
if there is a string in the first column amd a number in the second column, lays out a group
with a named square polygon and a text object in a non-overlapping pattern about the origin
In a layer called 'Space Planning'. The name of the poly and the string of the text object
is the string in column 1. The length of each side of the poly is the square root of the
value in column 2. }
LABEL 1, 2;
CONST
kLayerName = 'Space Planning';
kWorksheetName = 'Area Worksheet';
kGapFactor = 50;
kTextSize = 9;
kFont = 3; {Geneva}
kPointsPerInch = 72;
VAR
x, y : ARRAY [1..4, 1..4] of REAL; {storage of coord points}
f : ARRAY [1..4] of BOOLEAN; {first time through flags}
xf, yf : ARRAY [1..4] of REAL; {x and y quadrant factors}
wsHan, layerhan : HANDLE;
spaceArea, spaceLen, spaceSep, myScale, textOffset, upi : REAL;
startRow, numRows, numCols, numNames, row, i, format : INTEGER;
worksheetName, spaceName, skipped, uMark, squMark : STRING;
frac, disAcc : LONGINT;
PROCEDURE CenterDialog(dX1,dX2 : INTEGER; VAR x1,x2 : INTEGER);
VAR
scrX1,scrY1,scrX2,scrY2,w : INTEGER;
BEGIN
GetScreen(scrX1,scrY1,scrX2,scrY2);
w := dX2 - dX1;
x1 := ((scrX1 + scrX2) DIV 2) - (w DIV 2);
x2 := x1 + w;
END;
FUNCTION PermissionDeniedToDelete : BOOLEAN;
VAR
result, finished, cancel : BOOLEAN;
item, x1, x2 : INTEGER;
layerHan : HANDLE;
BEGIN
finished := FALSE;
cancel:= FALSE;
layerHan := GetObject(kLayerName);
IF FActLayer <> Nil THEN BEGIN
{IF ( NumObj ( layerHan ) ) <> 0 THEN BEGIN}
CenterDialog(0,320,x1,x2);
BeginDialog(1,1,x1,189,x2,323);
AddButton('Delete',1,1,211,82,275,105);
AddButton('Cancel',2,1,128,82,192,105);
AddField('Existing items in layer',3,1,49,24,208,42);
AddField( Concat( ' ╘',kLayerName,'╒ will be deleted.' ), 4,1,49,47,277,65);
EndDialog;
GetDialog(1);
REPEAT DialogEvent(item);
IF item = 2 THEN BEGIN
finished := TRUE;
cancel := TRUE;
END;
IF item = 1 THEN finished := TRUE;
UNTIL finished;
CLRDIALOG;
IF cancel THEN result := TRUE
ELSE BEGIN
DoMenuText('Active Only');
SelectObj(L=kLayerName);
DeleteObjs;
END;
END;
PermissionDeniedToDelete := result;
END;
BEGIN
PushAttrs;
SetCursor(watchC);
IF PermissionDeniedToDelete THEN GoTo 1;
DSelectall;
{** Set up required attributes. }
AngleVar;
ClosePoly;
TextJust(2);
TextSize(kTextSize);
TextFont(kFont);
GetUnits(frac, disAcc, format, upi, uMark, squMark);
{** Calculate vertical offset for centering text placement. }
textOffset := upi/((kTextSize/kPointsPerInch)/2);
{** Try named worksheet constant. }
wsHan := GetObject(kWorksheetName);
{** Try active worksheet. }
IF (wsHan = nil) THEN wsHan := ActSSheet;
{** Try getting worksheet name from user. }
IF (wsHan = nil) THEN BEGIN
worksheetName := StrDialog('Enter the name of the worksheet to be used.', 'Worksheet 1');
wsHan := GetObject(worksheetName);
END;
{** If no worksheet then punch out with dialog╔ }
IF ((wsHan = nil) | (GetType(wsHan) <> 18)) THEN BEGIN
SysBeep;
AlrtDialog('I can╒t find a worksheet by that name.');
GOTO 1;
END;
SelectSS(wsHan);
SprdSize(wsHan, numRows, numCols);
{** Determine number of names and average area factor. }
numNames := 0;
IF GetCellStr(wsHan, 1, 1) = 'Name' THEN startRow := 2
ELSE startrow := 1;
IF GetCellStr(wsHan, 1, 1) = '' THEN startRow := 2;
{** Calculate separation between spaces in layout. }
spaceSep := 0;
FOR row := startRow to numRows DO BEGIN
IF CellHasStr(wsHan, row, 1) THEN BEGIN
numNames := numNames + 1;
spaceSep := spaceSep + Str2Num(GetCellStr(wsHan, row, 2));
END;
END;
spaceSep := (spaceSep / numNames) / kGapFactor;
{** Initialize first time through flags. }
FOR i := 1 to 4 DO f[i] := true;
{** Initialize x and y quadrant factors. }
xf[1] := 1;
yf[1] := 1;
xf[2] := 1;
yf[2] := -1;
xf[3] := -1;
yf[3] := 1;
xf[4] := -1;
yf[4] := -1;
{** Initialize error string. }
skipped:='Areas missing. Skipped row ';
{** Process each row of worksheet. }
FOR row := startRow to numRows DO BEGIN
IF CellHasStr(wsHan, row, 1) THEN BEGIN
spaceName := getcellstr(wsHan, row, 1);
IF CellHasNum(wsHan, row, 2) THEN
spaceArea := Str2Num(GetCellStr(wsHan, row, 2))
ELSE BEGIN
{** Add skipped row to error string and goto next row. }
skipped := Concat(skipped, row, ', ');
GoTo 2;
END;
spaceLen := Sqrt(spaceArea);
{** Create quadrant index for this row; q1 = 1, q2 = 2, etc. }
i := ((row + 4) MOD 4) +1;
IF f[i] THEN BEGIN
{** First time through; load initial values. }
f[i] := false;
x[i, 1] := (spaceSep/2) * xf[i];
y[i, 1] := (spaceSep/2) * yf[i];
x[i, 2] := x[i, 1];
y[i, 2] := y[i, 1];
x[i, 3] := x[i, 1] + (spaceLen * xf[i]);
y[i, 3] := y[i, 1] + (spaceLen * yf[i]);
x[i, 4] := x[i, 3];
y[i, 4] := y[i, 3];
BeginGroup;
{** draw first box and text group }
NameObject(spaceName);
Poly(x[i, 2], y[i, 2], x[i, 2], y[i, 3], x[i, 3], y[i, 3], x[i, 3], y[i, 2]);
TextOrigin(x[i, 2] + ((spaceLen/2) * xf[i]), y[i, 2] + ((spaceLen/2) * yf[i]) + textOffset);
BeginText;
spaceName
EndText;
EndGroup;
END
ELSE BEGIN
{** Compare new values; load to build layout vertically or horizontally. }
IF Abs(y[i, 4]) >= Abs(x[i, 4]) THEN BEGIN
x[i, 2] := x[i, 4] + (spaceSep * xf[i]);
y[i, 2] := y[i, 1];
END
ELSE BEGIN
x[i, 2] := x[i, 1];
y[i, 2] := y[i, 4] + (spaceSep * yf[i]);
END;
x[i, 3] := x[i, 2] + (spaceLen * xf[i]);
y[i, 3] := y[i, 2] + (spaceLen * yf[i]);
BeginGroup;
{** Draw next box and text group. }
NameObject(spaceName);
Poly(x[i, 2], y[i, 2], x[i, 2], y[i, 3], x[i, 3], y[i, 3], x[i, 3], y[i, 2]);
TextOrigin(x[i, 2] + ((spaceLen/2) * xf[i]), y[i, 2] + ((spaceLen/2) * yf[i]) + textOffset);
BeginText;
spaceName
EndText;
EndGroup;
{** Update largest x and y values so far, if nessicary. }
IF Abs(x[i, 3]) >= Abs(x[i, 4]) THEN x[i, 4] := x[i, 3];
IF Abs(y[i, 3]) >= Abs(y[i, 4]) THEN y[i, 4] := y[i, 3];
END;
END;
2: END;
{** Cleanup and report errors. }
DSelectAll;
{** Report if any lines were skipped. }
IF skipped <> 'Areas missing. Skipped row ' THEN BEGIN
Delete(skipped, len(skipped) - 1, 2);
AlrtDialog(Concat(skipped, '.'));
END;
1: PopAttrs;
END;
RUN(DrawSpaces);