mirror of
https://github.com/RTimothyEdwards/magic.git
synced 2026-10-06 09:53:00 +02:00
Added checks for GDS scalefactor (DBU) both when reading GDS in
"gds readonly true" mode and when writing a GDS file in full-dump mode. Reading or writing a file with an incompatible DBU is now prohibited. This is not a great solution, as it forces the original file to be rewritten with a different DBU. Preferably there should be code to scale the units during a dump, but that needs to be coded.
This commit is contained in:
+34
-2
@@ -114,8 +114,6 @@ extern bool CalmaDoLibrary; /* Also used by GDS write */
|
||||
extern void calmaUnexpected();
|
||||
extern int calmaWriteInitFunc();
|
||||
|
||||
bool calmaParseUnits();
|
||||
|
||||
/*
|
||||
* Scaling.
|
||||
* Multiply all coordinates by calmaReadScale1, then divide them
|
||||
@@ -351,6 +349,7 @@ calmaParseUnits()
|
||||
double metersPerDBUnit;
|
||||
double userUnitsPerDBUnit;
|
||||
double cuPerDBUnit;
|
||||
bool compatible;
|
||||
|
||||
READRH(nbytes, rtype);
|
||||
#ifdef lint
|
||||
@@ -369,6 +368,39 @@ calmaParseUnits()
|
||||
/* Read meters per database unit */
|
||||
if (!calmaReadR8(&metersPerDBUnit)) return (FALSE);
|
||||
|
||||
/* Important! When CalmaReadOnly is TRUE, then this file will have its
|
||||
* contents output verbatim. But if the database units don't match,
|
||||
* then it will get output at the wrong scale. Setting a magnification
|
||||
* factor on the instance when generating output might (?) work. For
|
||||
* now, prohibiting a GDS read in read-only mode when the database units
|
||||
* don't match. This forces the user either to reconsider the read-only
|
||||
* status or to rewrite the GDS at a compatible scalefactor.
|
||||
*/
|
||||
compatible = TRUE;
|
||||
if (CalmaReadOnly == TRUE)
|
||||
{
|
||||
if (CIFCurStyle->cs_flags & CWF_ANGSTROMS)
|
||||
{
|
||||
if ((int)(0.5 + metersPerDBUnit * 1e12) != 100)
|
||||
{
|
||||
CalmaReadError("Incompatible scale factor of %g, must be 1e-10.\n",
|
||||
metersPerDBUnit);
|
||||
TxError("Cannot read this file in read-only mode.\n");
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((int)(0.5 + metersPerDBUnit * 1e11) != 100)
|
||||
{
|
||||
CalmaReadError("Incompatible scale factor of %g, must be 1e-9.\n",
|
||||
metersPerDBUnit);
|
||||
TxError("Cannot read this file in read-only mode.\n");
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef notdef
|
||||
TxPrintf("1 database unit equals %e user units\n", userUnitsPerDBUnit);
|
||||
TxPrintf("1 database unit equals %e meters\n", metersPerDBUnit);
|
||||
|
||||
+10
-4
@@ -706,7 +706,7 @@ calmaFullDump(def, fi, outf, filename)
|
||||
|
||||
static int hdrSkip[] = { CALMA_FORMAT, CALMA_MASK, CALMA_ENDMASKS,
|
||||
CALMA_REFLIBS, CALMA_FONTS, CALMA_ATTRTABLE,
|
||||
CALMA_STYPTABLE, CALMA_GENERATIONS, CALMA_UNITS, -1 };
|
||||
CALMA_STYPTABLE, CALMA_GENERATIONS, -1 };
|
||||
static int skipBeforeLib[] = { CALMA_LIBDIRSIZE, CALMA_SRFNAME,
|
||||
CALMA_LIBSECUR, -1 };
|
||||
|
||||
@@ -722,11 +722,17 @@ calmaFullDump(def, fi, outf, filename)
|
||||
calmaSkipSet(skipBeforeLib);
|
||||
if (!calmaReadStringRecord(CALMA_LIBNAME, &libname)) goto done;
|
||||
|
||||
// NOTE: CALMA_UNITS needs to be parsed to determine if units in
|
||||
// the input file are compatible with units being used in the output
|
||||
// file.
|
||||
calmaSkipSet(hdrSkip);
|
||||
|
||||
// CALMA_UNITS needs to be parsed to determine if units in the
|
||||
// input file are compatible with units being used in the output
|
||||
// file.
|
||||
if (calmaParseUnits() == FALSE)
|
||||
{
|
||||
TxError("Error: Library %s has incompatible database units!\n", libname);
|
||||
return;
|
||||
}
|
||||
|
||||
// Record the GDS library so it will not be processed again.
|
||||
he = HashFind(&calmaLibHash, filename);
|
||||
if ((char *)HashGetValue(he) != NULL)
|
||||
|
||||
+8
-4
@@ -682,7 +682,7 @@ calmaFullDumpZ(def, fi, outf, filename)
|
||||
|
||||
static int hdrSkip[] = { CALMA_FORMAT, CALMA_MASK, CALMA_ENDMASKS,
|
||||
CALMA_REFLIBS, CALMA_FONTS, CALMA_ATTRTABLE,
|
||||
CALMA_STYPTABLE, CALMA_GENERATIONS, CALMA_UNITS, -1 };
|
||||
CALMA_STYPTABLE, CALMA_GENERATIONS, -1 };
|
||||
static int skipBeforeLib[] = { CALMA_LIBDIRSIZE, CALMA_SRFNAME,
|
||||
CALMA_LIBSECUR, -1 };
|
||||
|
||||
@@ -698,10 +698,14 @@ calmaFullDumpZ(def, fi, outf, filename)
|
||||
calmaSkipSet(skipBeforeLib);
|
||||
if (!calmaReadStringRecord(CALMA_LIBNAME, &libname)) goto done;
|
||||
|
||||
// NOTE: CALMA_UNITS needs to be parsed to determine if units in
|
||||
// the input file are compatible with units being used in the output
|
||||
// CALMA_UNITS needs to be parsed to determine if units in the
|
||||
// input file are compatible with units being used in the output
|
||||
// file.
|
||||
calmaSkipSet(hdrSkip);
|
||||
if (calmaParseUnits() == FALSE)
|
||||
{
|
||||
TxError("Error: Library %s has incompatible database units!\n", libname);
|
||||
return;
|
||||
}
|
||||
|
||||
// Record the GDS library so it will not be processed again.
|
||||
he = HashFind(&calmaLibHash, filename);
|
||||
|
||||
@@ -237,6 +237,7 @@ extern bool calmaIsContactCell;
|
||||
|
||||
extern char *calmaRecordName();
|
||||
extern void calmaSkipSet();
|
||||
extern bool calmaParseUnits();
|
||||
|
||||
extern int compport();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user