def check_entity_lineweight(self, entity: 'DXFGraphic') -> None: weight = entity.dxf.lineweight if weight not in const.VALID_DXF_LINEWEIGHT_VALUES: entity.dxf.lineweight = validator.fix_lineweight(weight) self.fixed_error( code=AuditError.INVALID_LINEWEIGHT, message=f'Fixed invalid lineweight of {str(entity)}.', dxf_entity=entity, )
def export_acdb_entity(self, tagwriter: 'TagWriter'): """ Export subclass 'AcDbEntity' as DXF tags. (internal API)""" # Full control over tag order and YES, sometimes order matters not_r12 = tagwriter.dxfversion > DXF12 if not_r12: tagwriter.write_tag2(SUBCLASS_MARKER, acdb_entity.name) if self.dxf.hasattr('lineweight'): # AutoCAD does not load DXF documents using invalid lineweights self.dxf.lineweight = fix_lineweight(self.dxf.lineweight) self.dxf.export_dxf_attribs(tagwriter, [ 'paperspace', 'layer', 'linetype', 'material_handle', 'color', 'lineweight', 'ltscale', 'true_color', 'color_name', 'transparency', 'plotstyle_enum', 'plotstyle_handle', 'shadow_mode', 'visualstyle_handle', ]) if self.proxy_graphic and not_r12 and options.store_proxy_graphics: # length tag has group code 92 until DXF R2010 export_proxy_graphic(self.proxy_graphic, tagwriter, length_code=(92 if tagwriter.dxfversion < DXF2013 else 160))
def fix_layer_lineweight(lw: int) -> int: if lw in (LINEWEIGHT_BYLAYER, LINEWEIGHT_BYBLOCK): return LINEWEIGHT_DEFAULT else: return validator.fix_lineweight(lw)
def test_lineweight_fixer(): assert fix_lineweight(-4) == -1, 'too small, fix as BYLAYER' assert fix_lineweight(212) == 211, 'too big, fix as biggest lineweight' assert fix_lineweight(10) == 13, 'invalid, fix as next valid lineweight'
def test_lineweight_too_big(): assert fix_lineweight(212) == 211
def test_lineweight_too_small(): assert fix_lineweight(-4) == -1
def test_invalid_lineweight(): assert fix_lineweight(10) == 13