def test_resolve_block_entities(doc):
    ctx = RenderContext(doc)
    msp = doc.modelspace()
    blockref = msp.query("INSERT").first
    ctx.push_state(ctx.resolve_all(blockref))
    assert ctx.inside_block_reference is True
    lines = list(blockref.virtual_entities())

    # properties by block
    line1 = ctx.resolve_all(lines[0])
    assert lines[0].dxf.linetype == "BYBLOCK"
    assert line1.color == "#00ff00"
    assert line1.linetype_name == "CENTER"
    assert line1.lineweight == 0.13

    # explicit properties
    line2 = ctx.resolve_all(lines[1])
    assert lines[1].dxf.linetype == "DASHED"
    assert line2.color == "#ff0000"
    assert line2.linetype_name == "DASHED"
    assert line2.lineweight == 0.50

    # properties by layer 'Test'
    line3 = ctx.resolve_all(lines[2])
    assert lines[2].dxf.linetype == "BYLAYER"
    assert line3.color == "#0000ff"
    assert line3.linetype_name == "DOT"
    assert line3.lineweight == 0.70

    ctx.pop_state()
    assert ctx.inside_block_reference is False
Exemplo n.º 2
0
def test_resolve_block_entities(doc):
    ctx = RenderContext(doc)
    msp = doc.modelspace()
    blockref = msp.query('INSERT').first
    ctx.push_state(ctx.resolve_all(blockref))
    assert ctx.is_block_context is True
    lines = list(blockref.virtual_entities())

    # properties by block
    line1 = ctx.resolve_all(lines[0])
    assert lines[0].dxf.linetype == 'BYBLOCK'
    assert line1.color == '#00ff00'
    assert line1.linetype_name == 'CENTER'
    assert line1.lineweight == 0.13

    # explicit properties
    line2 = ctx.resolve_all(lines[1])
    assert lines[1].dxf.linetype == 'DASHED'
    assert line2.color == '#ff0000'
    assert line2.linetype_name == 'DASHED'
    assert line2.lineweight == 0.50

    # properties by layer 'Test'
    line3 = ctx.resolve_all(lines[2])
    assert lines[2].dxf.linetype == 'BYLAYER'
    assert line3.color == '#0000ff'
    assert line3.linetype_name == 'DOT'
    assert line3.lineweight == 0.70

    ctx.pop_state()
    assert ctx.is_block_context is False
def test_resolve_entity_color(doc):
    ctx = RenderContext(doc)
    msp = doc.modelspace()
    lines = msp.query("LINE")
    line1 = ctx.resolve_all(lines[0])
    assert line1.color == "#0000ff"  # by layer

    line2 = ctx.resolve_all(lines[1])
    assert line2.color == "#ff0000"
def test_resolve_entity_lineweight(doc):
    ctx = RenderContext(doc)
    msp = doc.modelspace()
    lines = msp.query("LINE")

    line1 = ctx.resolve_all(lines[0])
    assert line1.lineweight == 0.70  # by layer

    line2 = ctx.resolve_all(lines[1])
    assert line2.lineweight == 0.50
def test_resolve_entity_linetype(doc):
    ctx = RenderContext(doc)
    msp = doc.modelspace()
    lines = msp.query("LINE")

    line1 = ctx.resolve_all(lines[0])
    assert line1.linetype_name == "DOT"  # by layer

    line2 = ctx.resolve_all(lines[1])
    assert line2.linetype_name == "DASHED"
def test_existing_true_color_overrides_any_aci_color(doc):
    ctx = RenderContext(doc)
    line = factory.new("LINE")
    line.rgb = (255, 1, 1)
    for color in range(const.BYLAYER + 1):
        line.dxf.color = color
        props = ctx.resolve_all(line)
        assert (props.color == "#ff0101"
                ), "true_color should override any ACI color"
def test_resolve_transparency_from_layer():
    doc = ezdxf.new()
    doc.layers.add("Layer_T50", color=1, transparency=0.50)
    msp = doc.modelspace()
    line = msp.add_line(
        (0, 0),
        (1, 0),
        dxfattribs={
            "color": 5,
            "layer": "Layer_T50",
        },
    )
    context = RenderContext(doc)
    context.set_current_layout(msp)
    prop = context.resolve_all(line)
    assert prop.color == "#0000ff7f"