コード例 #1
0
def test_insert_scaling():
    # Insert.transform() changes the extrusion vector
    # sign of scaling factors depend from new extrusion vector
    # just compare absolute values
    insert = Insert()
    insert.dxf.insert = (0, 0, 0)

    insert.scale(2, 3, 4)
    assert abs(insert.dxf.xscale) == 2
    assert abs(insert.dxf.yscale) == 3
    assert abs(insert.dxf.zscale) == 4

    insert.scale(-1, 1, 1)
    assert abs(insert.dxf.xscale) == 2
    assert abs(insert.dxf.yscale) == 3
    assert abs(insert.dxf.zscale) == 4

    insert.scale(-1, -1, 1)
    assert abs(insert.dxf.xscale) == 2
    assert abs(insert.dxf.yscale) == 3
    assert abs(insert.dxf.zscale) == 4

    insert.scale(-2, -2, -2)
    assert abs(insert.dxf.xscale) == 4
    assert abs(insert.dxf.yscale) == 6
    assert abs(insert.dxf.zscale) == 8
コード例 #2
0
def test_get_block(doc):
    blk = doc.blocks.new('TEST-2020-02-29')
    msp = doc.modelspace()
    insert = msp.add_blockref('TEST-2020-02-29', (0, 0))
    assert insert.block() is blk
    insert = msp.add_blockref('NOT-EXIST-2020-02-29', (0, 0))
    assert insert.block() is None
    insert = Insert()
    assert insert.block() is None
コード例 #3
0
def test_matrix44_insert():
    insert = Insert.new(handle='ABBA', owner='0', dxfattribs={
        'insert': (1, 2, 3),
    })
    m = insert.matrix44()
    assert m.transform((0, 0, 0)) == (1, 2, 3)
    assert m.transform_direction((1, 0, 0)) == (1, 0, 0)
コード例 #4
0
def test_load_malformed_insert():
    insert = Insert.from_text(MALFORMED_INSERT)
    assert insert.dxf.layer == "LY_EZDXF"
    assert insert.dxf.linetype == "LT_EZDXF"
    assert insert.dxf.color == 7
    assert insert.dxf.insert.isclose((1, 2, 3))
    assert insert.dxf.name == "BLOCKNAME"
コード例 #5
0
def test_matrix44_direction():
    insert = Insert.new(handle='ABBA', owner='0', dxfattribs={
        'insert': (1, 2, 3),
        'xscale': 2,
    })
    m = insert.matrix44()
    assert m.transform((1, 0, 0)) == (3, 2, 3)
    assert m.transform_direction((1, 0, 0)) == (2, 0, 0), \
        'only scaling has to be applied for directions'
コード例 #6
0
def test_insert_transformation_error():
    insert = Insert.new(dxfattribs={
        'name': 'AXIS',
        'insert': (0, 0, 0),
        'rotation': 45,
    })
    m = Matrix44.scale(0.5, 1, 1)
    with pytest.raises(InsertTransformationError):
        insert.transform(m)
コード例 #7
0
def test_has_scaling():
    entity = Insert.new(handle='ABBA', owner='0', dxfattribs={'xscale': 2})
    assert entity.has_scaling is True
    assert entity.has_uniform_scaling is False
    entity = Insert.new(handle='ABBA', owner='0', dxfattribs={'yscale': 2})
    assert entity.has_scaling is True
    assert entity.has_uniform_scaling is False
    entity = Insert.new(handle='ABBA', owner='0', dxfattribs={'zscale': 2})
    assert entity.has_scaling is True
    assert entity.has_uniform_scaling is False

    # reflections are under control, so (-2, 2, 2) is a uniform scaling
    entity = Insert.new(handle='ABBA', owner='0', dxfattribs={
        'xscale': -2,
        'yscale': 2,
        'zscale': 2,
    })
    assert entity.has_uniform_scaling is True
コード例 #8
0
def test_insert_to_code():
    from ezdxf.entities.insert import Insert
    entity = Insert.new(handle='ABBA', owner='0', dxfattribs={
        'name': 'block1',
        'insert': (2, 3, 4),
    })
    new_entity = translate_to_code_and_execute(entity)
    for name in ('name', 'insert'):
        assert new_entity.get_dxf_attrib(name) == entity.get_dxf_attrib(name)
コード例 #9
0
def test_write_dxf(txt, ver):
    expected = basic_tags_from_text(txt)
    vertex = Insert.from_text(txt)
    collector = TagCollector(dxfversion=ver, optional=True)
    vertex.export_dxf(collector)
    assert collector.tags == expected

    collector2 = TagCollector(dxfversion=ver, optional=False)
    vertex.export_dxf(collector2)
    assert collector.has_all_tags(collector2)
コード例 #10
0
def test_matrix44_scaled():
    insert = Insert.new(handle='ABBA', owner='0', dxfattribs={
        'xscale': 2,
        'yscale': 3,
        'zscale': 4,
    })
    m = insert.matrix44()
    assert m.transform((1, 1, 1)) == (2, 3, 4)
    assert m.transform_direction((1, 0, 0)) == (
    2, 0, 0), 'scaling has to be applied for directions'
コード例 #11
0
def test_matrix44_rotation():
    insert = Insert.new(handle='ABBA',
                        owner='0',
                        dxfattribs={
                            'insert': (0, 0, 0),
                            'rotation': 90,
                        })
    m = insert.matrix44()
    assert list(m.transform_vertices([(1, 0, 0), (0, 0, 1)])) == [(0, 1, 0),
                                                                  (0, 0, 1)]
    assert m.transform_direction((1, 0, 0)) == (0, 1, 0)
コード例 #12
0
def test_matrix44_rotation():
    insert = Insert.new(handle='ABBA', owner='0', dxfattribs={
        'insert': (0, 0, 0),
        'rotation': 90,
    })
    m = insert.matrix44()
    for v1, v2 in zip(
            m.transform_vertices([(1, 0, 0), (0, 0, 1)]),
            [(0, 1, 0), (0, 0, 1)]):
        assert v1.isclose(v2)
    assert m.transform_direction((1, 0, 0)).isclose((0, 1, 0))
コード例 #13
0
def test_matrix44_insert():
    insert = Insert.new(
        handle="ABBA",
        owner="0",
        dxfattribs={
            "insert": (1, 2, 3),
        },
    )
    m = insert.matrix44()
    assert m.transform((0, 0, 0)) == (1, 2, 3)
    assert m.transform_direction((1, 0, 0)) == (1, 0, 0)
コード例 #14
0
def test_has_scaling():
    entity = Insert.new(handle="ABBA", owner="0", dxfattribs={"xscale": 2})
    assert entity.has_scaling is True
    assert entity.has_uniform_scaling is False
    entity = Insert.new(handle="ABBA", owner="0", dxfattribs={"yscale": 2})
    assert entity.has_scaling is True
    assert entity.has_uniform_scaling is False
    entity = Insert.new(handle="ABBA", owner="0", dxfattribs={"zscale": 2})
    assert entity.has_scaling is True
    assert entity.has_uniform_scaling is False

    # reflections are under control, so (-2, 2, 2) is a uniform scaling
    entity = Insert.new(
        handle="ABBA",
        owner="0",
        dxfattribs={
            "xscale": -2,
            "yscale": 2,
            "zscale": 2,
        },
    )
    assert entity.has_uniform_scaling is True
コード例 #15
0
def test_clone_with_insert():
    # difference of clone() to copy_entity() is:
    # - clone returns and unassigned entity without handle, owner or reactors
    # - copy_entity clones the entity and assigns the new entity to the same owner as the source and adds the entity
    #   and it linked entities (ATTRIB & VERTEX) to the entity database, but does not adding entity to a layout, setting
    #   owner tag is not enough to assign an entity to a layout, use Layout.add_entity()
    insert = Insert()
    insert.add_attrib('T1', 'value1', (0, 0))
    clone = insert.copy()
    assert clone.dxf.handle is None
    assert clone.dxf.owner is None
    assert len(clone.attribs) == 1
    attrib = clone.attribs[0]
    assert attrib.dxf.handle is None
    assert attrib.dxf.tag == 'T1'
    assert attrib.dxf.text == 'value1'
    # change cloned attrib
    attrib.dxf.tag = 'T2'
    attrib.dxf.text = 'value2'
    # source attrib is unchanged
    assert insert.attribs[0].dxf.tag == 'T1'
    assert insert.attribs[0].dxf.text == 'value1'
コード例 #16
0
def test_add_virtual_insert_with_attribs_to_layout(doc):
    doc.blocks.new("TestAddVirtualInsert")
    msp = doc.modelspace()
    insert = Insert.new(dxfattribs={"name": "TestAddVirtualInsert"})
    insert.add_attrib("TAG", "TEXT", (0, 0))
    msp.add_entity(insert)

    assert factory.is_bound(insert, doc) is True
    assert (factory.is_bound(insert.seqend, doc) is
            True), "SEQEND must be bound to document"

    assert insert.attribs_follow is True
    assert (factory.is_bound(insert.attribs[0], doc) is
            True), "ATTRIB must be bound to document"
コード例 #17
0
def test_add_virtual_insert_with_attribs_to_layout(doc):
    doc.blocks.new('TestAddVirtualInsert')
    msp = doc.modelspace()
    insert = Insert.new(dxfattribs={'name': 'TestAddVirtualInsert'})
    insert.add_attrib('TAG', 'TEXT', (0, 0))
    msp.add_entity(insert)

    assert factory.is_bound(insert, doc) is True
    assert factory.is_bound(insert.seqend, doc) is True, \
        'SEQEND must be bound to document'

    assert insert.attribs_follow is True
    assert factory.is_bound(insert.attribs[0], doc) is True, \
        'ATTRIB must be bound to document'
コード例 #18
0
def test_matrix44_rotation():
    insert = Insert.new(
        handle="ABBA",
        owner="0",
        dxfattribs={
            "insert": (0, 0, 0),
            "rotation": 90,
        },
    )
    m = insert.matrix44()
    for v1, v2 in zip(m.transform_vertices([(1, 0, 0), (0, 0, 1)]),
                      [(0, 1, 0), (0, 0, 1)]):
        assert v1.isclose(v2)
    assert m.transform_direction((1, 0, 0)).isclose((0, 1, 0))
コード例 #19
0
def test_insert_to_code():
    from ezdxf.entities.insert import Insert

    entity = Insert.new(
        handle="ABBA",
        owner="0",
        dxfattribs={
            "name": "block1",
            "insert": (2, 3, 4),
        },
    )
    new_entity = translate_to_code_and_execute(entity)
    for name in ("name", "insert"):
        assert new_entity.get_dxf_attrib(name) == entity.get_dxf_attrib(name)
コード例 #20
0
def test_insert_transform_interface():
    insert = Insert()
    insert.dxf.insert = (1, 0, 0)

    insert.transform(Matrix44.translate(1, 2, 3))
    assert insert.dxf.insert == (2, 2, 3)

    # optimized translate implementation
    insert.translate(-1, -2, -3)
    assert insert.dxf.insert == (1, 0, 0)
コード例 #21
0
def test_matrix44_direction():
    insert = Insert.new(
        handle="ABBA",
        owner="0",
        dxfattribs={
            "insert": (1, 2, 3),
            "xscale": 2,
        },
    )
    m = insert.matrix44()
    assert m.transform((1, 0, 0)) == (3, 2, 3)
    assert m.transform_direction((1, 0, 0)) == (
        2,
        0,
        0,
    ), "only scaling has to be applied for directions"
コード例 #22
0
def test_matrix44_scaled():
    insert = Insert.new(
        handle="ABBA",
        owner="0",
        dxfattribs={
            "xscale": 2,
            "yscale": 3,
            "zscale": 4,
        },
    )
    m = insert.matrix44()
    assert m.transform((1, 1, 1)) == (2, 3, 4)
    assert m.transform_direction((1, 0, 0)) == (
        2,
        0,
        0,
    ), "scaling has to be applied for directions"
コード例 #23
0
def test_new_constructor():
    insert = Insert.new(handle='ABBA', owner='0', dxfattribs={
        'color': '7',
        'insert': (1, 2, 3),
    })
    assert insert.is_virtual is True, 'Has no assigned document'
    assert insert.dxf.layer == '0'
    assert insert.dxf.color == 7
    assert insert.dxf.linetype == 'BYLAYER'
    assert insert.dxf.insert == (1, 2, 3)
    assert insert.dxf.insert.x == 1, 'is not Vec3 compatible'
    assert insert.dxf.insert.y == 2, 'is not Vec3 compatible'
    assert insert.dxf.insert.z == 3, 'is not Vec3 compatible'
    assert insert.has_scaling is False
    assert insert.has_uniform_scaling is True
    # can set DXF R2007 value
    insert.dxf.shadow_mode = 1
    assert insert.dxf.shadow_mode == 1
コード例 #24
0
def test_new_constructor():
    insert = Insert.new(
        handle="ABBA",
        owner="0",
        dxfattribs={
            "color": "7",
            "insert": (1, 2, 3),
        },
    )
    assert insert.is_virtual is True, "Has no assigned document"
    assert insert.dxf.layer == "0"
    assert insert.dxf.color == 7
    assert insert.dxf.linetype == "BYLAYER"
    assert insert.dxf.insert == (1, 2, 3)
    assert insert.dxf.insert.x == 1, "is not Vec3 compatible"
    assert insert.dxf.insert.y == 2, "is not Vec3 compatible"
    assert insert.dxf.insert.z == 3, "is not Vec3 compatible"
    assert insert.has_scaling is False
    assert insert.has_uniform_scaling is True
    # can set DXF R2007 value
    insert.dxf.shadow_mode = 1
    assert insert.dxf.shadow_mode == 1
コード例 #25
0
def test_add_attribs():
    insert = Insert()
    assert insert.attribs_follow is False
    insert.add_attrib('T1', 'value1', (0, 0))
    assert len(insert.attribs) == 1
    assert insert.attribs_follow is True
コード例 #26
0
def test_default_constructor():
    insert = Insert()
    assert insert.dxftype() == 'INSERT'
    assert insert.is_virtual
    assert insert.seqend is None, 'SEQEND must not exist'
コード例 #27
0
def entity(request):
    return Insert.from_text(request.param)
コード例 #28
0
def test_matrix44_no_transform():
    insert = Insert.new(handle='ABBA', owner='0')
    m = insert.matrix44()
    assert m.transform((0, 0, 0)) == (0, 0, 0)
    assert m.transform_direction((1, 0, 0)) == (1, 0, 0)