Exemplo n.º 1
0
def test_copy_entity_transparency():
    line = Line()
    line2 = line.copy()
    assert line2.dxf.hasattr("transparency") is False

    line.transparency = 0.5
    line2 = line.copy()
    assert line2.dxf.transparency == 0x0200007F
Exemplo n.º 2
0
def test_load_entity_with_invalid_transparency():
    line = Line.from_text(ENTITY_INVALID_TRANSPARENCY)
    # No auto fix in normal loading mode - Auditor fixes this issue at DXF
    # attribute level!
    assert line.dxf.transparency == 268435456
    assert (line.transparency == 0.0
            ), "should replace invalid transparency by opaque"
Exemplo n.º 3
0
def test_malformed_line():
    line = Line.from_text(MALFORMED_LINE)
    assert line.dxf.layer == "LY_EZDXF"
    assert line.dxf.linetype == "LT_EZDXF"
    assert line.dxf.color == 7
    assert line.dxf.start.isclose((1, 1, 1))
    assert line.dxf.end.isclose((2, 2, 2))
Exemplo n.º 4
0
def test_get_pass_through_ocs():
    line = Line.new(dxfattribs={
        "start": (0, 0, 0),
        "end": (1, 0, 0),
        "extrusion": (0, 0, -1),
    })
    ocs = line.ocs()
    assert ocs.to_wcs((0, 0, 0)) == (0, 0, 0)
    assert ocs.to_wcs((1, 0, 0)) == (1, 0, 0)
Exemplo n.º 5
0
def test_translation():
    line = Line.new(dxfattribs={
        'start': (0, 0, 0),
        'end': (1, 0, 0),
        'extrusion': (0, 1, 0)
    })
    line.translate(1, 2, 3)
    assert line.dxf.start == (1, 2, 3)
    assert line.dxf.end == (2, 2, 3)
Exemplo n.º 6
0
def test_translation():
    line = Line.new(dxfattribs={
        "start": (0, 0, 0),
        "end": (1, 0, 0),
        "extrusion": (0, 1, 0),
    })
    line.translate(1, 2, 3)
    assert line.dxf.start == (1, 2, 3)
    assert line.dxf.end == (2, 2, 3)
Exemplo n.º 7
0
def test_line_to_code():
    from ezdxf.entities.line import Line
    entity = Line.new(handle='ABBA', owner='0', dxfattribs={
        'color': '7',
        'start': (1, 2, 3),
        'end': (4, 5, 6),
    })

    new_entity = translate_to_code_and_execute(entity)
    for name in ('color', 'start', 'end'):
        assert new_entity.get_dxf_attrib(name) == entity.get_dxf_attrib(name)
Exemplo n.º 8
0
def test_scaling():
    line = Line.new(
        dxfattribs={
            "start": (0, 0, 0),
            "end": (1, 0, 0),
            "extrusion": (0, 1, 0),
            "thickness": 2,
        })
    m = Matrix44.scale(2, 2, 0)
    line.transform(m)
    assert line.dxf.start == (0, 0, 0)
    assert line.dxf.end == (2, 0, 0)
    assert line.dxf.extrusion == (0, 1, 0)
    assert line.dxf.thickness == 4
Exemplo n.º 9
0
def test_scaling():
    line = Line.new(
        dxfattribs={
            'start': (0, 0, 0),
            'end': (1, 0, 0),
            'extrusion': (0, 1, 0),
            'thickness': 2
        })
    m = Matrix44.scale(2, 2, 0)
    line.transform(m)
    assert line.dxf.start == (0, 0, 0)
    assert line.dxf.end == (2, 0, 0)
    assert line.dxf.extrusion == (0, 1, 0)
    assert line.dxf.thickness == 4
Exemplo n.º 10
0
def test_rotation():
    line = Line.new(dxfattribs={
        "start": (0, 0, 0),
        "end": (1, 0, 0),
        "extrusion": (0, 1, 0),
    })
    angle = math.pi / 4
    m = Matrix44.z_rotate(angle)
    line.transform(m)
    assert line.dxf.start == (0, 0, 0)
    assert line.dxf.end.isclose((math.cos(angle), math.sin(angle), 0),
                                abs_tol=1e-9)
    assert line.dxf.extrusion.isclose((-math.cos(angle), math.sin(angle), 0),
                                      abs_tol=1e-9)
    assert line.dxf.thickness == 0
Exemplo n.º 11
0
def test_line_to_code():
    from ezdxf.entities.line import Line

    entity = Line.new(
        handle="ABBA",
        owner="0",
        dxfattribs={
            "color": "7",
            "start": (1, 2, 3),
            "end": (4, 5, 6),
        },
    )

    new_entity = translate_to_code_and_execute(entity)
    for name in ("color", "start", "end"):
        assert new_entity.get_dxf_attrib(name) == entity.get_dxf_attrib(name)
Exemplo n.º 12
0
def test_default_new():
    entity = Line.new(handle='ABBA',
                      owner='0',
                      dxfattribs={
                          'color': '7',
                          'start': (1, 2, 3),
                          'end': (4, 5, 6),
                      })
    assert entity.dxf.layer == '0'
    assert entity.dxf.color == 7
    assert entity.dxf.start == (1, 2, 3)
    assert entity.dxf.start.x == 1, 'is not Vector compatible'
    assert entity.dxf.start.y == 2, 'is not Vector compatible'
    assert entity.dxf.start.z == 3, 'is not Vector compatible'
    assert entity.dxf.end == (4, 5, 6)
    assert entity.dxf.extrusion == (0.0, 0.0, 1.0)
    assert entity.dxf.hasattr('extrusion') is False, 'just the default value'

    # can set DXF R2007 value
    entity.dxf.shadow_mode = 1
    assert entity.dxf.shadow_mode == 1
Exemplo n.º 13
0
def test_transform():
    line = Line.new(dxfattribs={
        "start": (0, 0, 0),
        "end": (1, 0, 0),
        "extrusion": (0, 1, 0),
    })
    m = Matrix44.translate(1, 2, 3)
    line.transform(m)

    # simple 3D entity - no OCS transformation,
    assert line.dxf.start == (1, 2, 3)
    assert line.dxf.end == (2, 2, 3)
    # extrusion direction without translation - not an OCS extrusion vector!
    assert line.dxf.extrusion == (0, 1, 0)

    # Create new entity by transformation:
    new_line = line.copy()
    new_line.transform(m)

    assert new_line.dxf.start == (2, 4, 6)
    assert new_line.dxf.end == (3, 4, 6)
    assert new_line.dxf.extrusion == (0, 1, 0)
Exemplo n.º 14
0
def test_default_new():
    entity = Line.new(
        handle="ABBA",
        owner="0",
        dxfattribs={
            "color": "7",
            "start": (1, 2, 3),
            "end": (4, 5, 6),
        },
    )
    assert entity.dxf.layer == "0"
    assert entity.dxf.color == 7
    assert entity.dxf.start == (1, 2, 3)
    assert entity.dxf.start.x == 1, "is not Vec3 compatible"
    assert entity.dxf.start.y == 2, "is not Vec3 compatible"
    assert entity.dxf.start.z == 3, "is not Vec3 compatible"
    assert entity.dxf.end == (4, 5, 6)
    assert entity.dxf.extrusion == (0.0, 0.0, 1.0)
    assert entity.dxf.hasattr("extrusion") is False, "just the default value"

    # can set DXF R2007 value
    entity.dxf.shadow_mode = 1
    assert entity.dxf.shadow_mode == 1
Exemplo n.º 15
0
def test_default_init():
    entity = Line()
    assert entity.dxftype() == TEST_TYPE
Exemplo n.º 16
0
def line(request):
    return Line.from_text(request.param)
Exemplo n.º 17
0
def test_recover_acdb_entity_tags():
    line = Line.from_text(ERR_LINE)
    assert line.dxf.layer == "0"
    assert line.dxf.color == 1
    assert line.dxf.linetype == "Linetype"
Exemplo n.º 18
0
def line():
    return Line.from_text(LINE_DATA)
Exemplo n.º 19
0
 def entity(self):
     return Line.from_text(LINE_DATA)
Exemplo n.º 20
0
def test_setting_invalid_transparency_value_raises_exception():
    line = Line()
    with pytest.raises(DXFValueError):
        line.dxf.transparency = 0