Inconsistent $MEASUREMENT/$INSUNITS variables.

This commit is contained in:
Roman Telezhynskyi 2022-09-20 11:50:38 +03:00
parent d3205b853c
commit fb85ec4eec
2 changed files with 54 additions and 4 deletions

View File

@ -1368,7 +1368,11 @@ void DRW_Header::write(dxfWriter *writer, DRW::Version ver){
writer->writeInt16(70, varInt); writer->writeInt16(70, varInt);
else else
writer->writeInt16(70, 1); writer->writeInt16(70, 1);
int insunits {Units::None};
getInt("$INSUNITS", &insunits); // get $INSUNITS now to evaluate $MEASUREMENT
getInt("$MEASUREMENT", &varInt); // just remove the variable from list
writer->writeString(9, "$MEASUREMENT"); writer->writeString(9, "$MEASUREMENT");
writer->writeInt16(70, measurement( insunits));
if (getInt("$MEASUREMENT", &varInt)) if (getInt("$MEASUREMENT", &varInt))
writer->writeInt16(70, varInt); writer->writeInt16(70, varInt);
else else
@ -1395,10 +1399,7 @@ void DRW_Header::write(dxfWriter *writer, DRW::Version ver){
writer->writeInt16(290, 0); writer->writeInt16(290, 0);
if (ver > DRW::AC1014) { if (ver > DRW::AC1014) {
writer->writeString(9, "$INSUNITS"); writer->writeString(9, "$INSUNITS");
if (getInt("$INSUNITS", &varInt)) writer->writeInt16(70, insunits); // already fetched above for $MEASUREMENT
writer->writeInt16(70, varInt);
else
writer->writeInt16(70, 0);
} }
writer->writeString(9, "$HYPERLINKBASE"); writer->writeString(9, "$HYPERLINKBASE");
if (getStr("$HYPERLINKBASE", &varStr)) if (getStr("$HYPERLINKBASE", &varStr))
@ -1752,3 +1753,20 @@ bool DRW_Header::getCoord(const std::string &key, DRW_Coord *varCoord){
} }
return result; return result;
} }
int DRW_Header::measurement(const int unit) {
switch (unit) {
case Units::Inch:
case Units::Foot:
case Units::Mile:
case Units::Microinch:
case Units::Mil:
case Units::Yard:
return Units::English;
default:
break;
}
return Units::Metric;
}

View File

@ -39,6 +39,36 @@ public:
clearVars(); clearVars();
} }
enum Units {
/** $ISUNITS header variable, since ACAD2000/AC1015 */
None = 0, ///< No unit (unit from parent)
Inch = 1, ///< 25.4 mm
Foot = 2, ///< 12 Inches = 0.3048 m
Mile = 3, ///< 1760 Yards = 1609 m
Millimeter = 4, ///< 0.001 m
Centimeter = 5, ///< 0.01 m
Meter = 6,
Kilometer = 7, ///< 1000 m
Microinch = 8, ///< 0.000001 Inch = 0.0000254 mm = 25.4 Nanometer
Mil = 9, ///< 0.001 Inch = 0.0254 mm = 25.4 Micron
Yard = 10, ///< 3 Feet = 0.9144 m
Angstrom = 11, ///< 10^-10 m
Nanometer = 12, ///< 10^-9 m
Micron = 13, ///< 10^-6 m
Decimeter = 14, ///< 0.1 m
Decameter = 15, ///< 10 m
Hectometer = 16, ///< 100 m
Gigameter = 17, ///< 10^9 m
Astro = 18, ///< ~149.6 x 10^9 m
Lightyear = 19, ///< ~9.46 x 10^15 m
Parsec = 20, ///< ~3.0857 x 10^16 m
UnitCount = 21, ///< Used to iterate through units
/** $MEASUREMENT header variable, since R14/AC1014 */
English = 0, ///< English/Imperial drawing */
Metric = 1, ///< Metric drawing */
};
DRW_Header(const DRW_Header& h) DRW_Header(const DRW_Header& h)
: vars(), : vars(),
comments(h.comments), comments(h.comments),
@ -119,6 +149,8 @@ private:
duint32 ucsCtrl; duint32 ucsCtrl;
duint32 vportCtrl; duint32 vportCtrl;
duint32 vpEntHeaderCtrl; duint32 vpEntHeaderCtrl;
int measurement(const int unit);
}; };
#endif #endif