Beispiel #1
0
def test_write_endblk_dxf(txt, ver):
    expected = basic_tags_from_text(txt)
    endblk = EndBlk.from_text(txt)
    collector = TagCollector(dxfversion=ver, optional=True)
    endblk.export_dxf(collector)
    assert collector.tags == expected

    collector2 = TagCollector(dxfversion=ver, optional=False)
    endblk.export_dxf(collector2)
    assert collector.has_all_tags(collector2)
Beispiel #2
0
def test_write_dxf(txt, ver):
    expected = basic_tags_from_text(txt)
    vertex = TEST_CLASS.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)
Beispiel #3
0
def test_write_dxf_r2000():
    expected = basic_tags_from_text(ENTITY_R2000)
    viewport = TEST_CLASS.from_text(ENTITY_R2000)
    collector = TagCollector(dxfversion=DXF2000, optional=True)
    viewport.export_dxf(collector)
    # todo: tag checking
    assert len(collector.tags) == len(expected)

    collector2 = TagCollector(dxfversion=DXF2000, optional=False)
    viewport.export_dxf(collector2)
    assert collector.has_all_tags(collector2)
Beispiel #4
0
def test_internals_polymesh(layout):
    mesh = layout.add_polymesh((4, 4))
    collector = TagCollector()
    mesh.export_dxf(collector)
    tags = collector.tags
    assert (100, 'AcDbPolygonMesh') in tags
    collector.reset()
    mesh[0].export_dxf(collector)
    tags = collector.tags
    assert (100, 'AcDbVertex') in tags
    assert (100, 'AcDbPolygonMeshVertex') in tags
Beispiel #5
0
def test_export_polyline3d(layout):
    polyline = layout.add_polyline3d([(0, 0), (1, 1)])
    collector = TagCollector()
    polyline.export_dxf(collector)
    tags = collector.tags
    assert (100, 'AcDb3dPolyline') in tags
    collector.reset()
    polyline[0].export_dxf(collector)
    tags = collector.tags
    assert (100, 'AcDbVertex') in tags
    assert (100, 'AcDb3dPolylineVertex') in tags
def test_export_dynamic_columns_manual_height_as_embedded_object():
    mtext = make_mtext(DYNAMIC_MANUAL_HEIGHT)
    collector = TagCollector(dxfversion=const.DXF2018)
    mtext.export_embedded_object(collector)
    tags = collector.tags
    assert len(tags) == 21
    assert tags[0] == (EMBEDDED_OBJ_MARKER, EMBEDDED_OBJ_STR)
    assert tags[1] == (70, 1)
    assert tags[2] == (10, 1)
    assert tags[3] == (20, 0)
    assert tags[4] == (30, 0)
    assert tags[5] == (11, 69.8)
    assert tags[6] == (21, 276.1)
    assert tags[7] == (31, 0)
    assert tags[8] == (40, 62.6)
    assert tags[9] == (41, 0.0)
    assert tags[10] == (42, 175.0)
    assert tags[11] == (43, 164.8)
    assert tags[12] == (71, 2)
    assert tags[13] == (72, 3)
    assert tags[14] == (44, 50.0)
    assert tags[15] == (45, 12.5)
    assert tags[16] == (73, 0)
    assert tags[17] == (74, 0)
    assert tags[18] == (46, 164.8)
    assert tags[19] == (46, 154.3)
    assert tags[20] == (46, 0)
Beispiel #7
0
 def test_export_dxf(self, tags):
     expected = basic_tags_from_text(LEADER_1)
     ctx = compile_context_tags(tags, 303)
     leader = Leader.load(ctx)
     collector = TagCollector()
     leader.export_dxf(collector)
     assert collector.tags == expected
def test_create_vertex_array(mesh_tags):
    start_index = mesh_tags.tag_index(92) + 1
    vertices = create_vertex_array(mesh_tags, start_index)
    assert len(vertices) == 56

    tags = TagCollector.dxftags(vertices)
    assert len(tags) == 3 * len(vertices)
Beispiel #9
0
def test_no_fit_points_export(spline_edge_hatch):
    path = spline_edge_hatch.paths[0]
    spline = path.add_spline(control_points=[(1, 1), (2, 2), (3, 3), (4, 4)],
                             degree=3, periodic=1)
    spline.knot_values = [1, 2, 3, 4, 5, 6]
    assert [(1, 1), (2, 2), (3, 3), (4, 4)] == spline.control_points
    assert len(spline.fit_points) == 0
    writer = TagCollector(dxfversion=DXF2007)
    spline.export_dxf(writer)
    # do not write length tag 97 if no fit points exists for DXF2007 and prior
    assert any(tag.code == 97 for tag in writer.tags) is False

    writer = TagCollector(dxfversion=DXF2010)
    spline.export_dxf(writer)
    # do write length tag 97 if no fit points exists for DXF2010+
    assert (97, 0) in writer.tags
Beispiel #10
0
def test_3dface():
    face = Face3d()
    face.dxf.invisible = 2 + 8
    assert face.is_invisible_edge(0) is False
    assert face.is_invisible_edge(1) is True
    assert face.is_invisible_edge(2) is False
    assert face.is_invisible_edge(3) is True

    assert face.get_edges_visibility() == [True, False, True, False]

    face.dxf.vtx3 = (1, 2, 3)
    assert face.get_edges_visibility() == [True, False, True, False]

    face.dxf.invisible = 0
    face.set_edge_visibility(3, False)
    assert face.dxf.invisible == 8
    face.set_edge_visibility(1, False)
    assert face.dxf.invisible == 10
    face.set_edge_visibility(3, True)
    assert face.dxf.invisible == 2

    collector = TagCollector(dxfversion=DXF2000)
    face.export_dxf(collector)
    assert collector.tags[0] == (0, "3DFACE")
    assert collector.tags[5] == (100, "AcDbFace")
Beispiel #11
0
def test_create_spline_edge(spline_edge_hatch):
    # create the spline
    path = spline_edge_hatch.paths[0]
    spline = path.add_spline([(1, 1), (2, 2), (3, 3), (4, 4)], degree=3,
                             periodic=1)
    # the following values do not represent a mathematically valid spline
    spline.control_points = [(1, 1), (2, 2), (3, 3), (4, 4)]
    spline.knot_values = [1, 2, 3, 4, 5, 6]
    spline.weights = [4, 3, 2, 1]
    spline.start_tangent = (10, 1)
    spline.end_tangent = (2, 20)

    # test the spline
    path = spline_edge_hatch.paths[0]
    spline = path.edges[-1]
    assert 3 == spline.degree
    assert 1 == spline.periodic
    assert (10, 1) == spline.start_tangent
    assert (2, 20) == spline.end_tangent
    assert [(1, 1), (2, 2), (3, 3), (4, 4)] == spline.control_points
    assert [(1, 1), (2, 2), (3, 3), (4, 4)] == spline.fit_points
    assert [1, 2, 3, 4, 5, 6] == spline.knot_values
    assert [4, 3, 2, 1] == spline.weights

    writer = TagCollector()
    spline.export_dxf(writer)
    assert (97, 4) in writer.tags
Beispiel #12
0
def test_write_r12_dxf(entity):
    tagwriter = TagCollector(dxfversion=DXF12)
    entity.export_dxf(tagwriter)
    tag = tagwriter.tags
    assert len(tag) == 2
    assert tag[0] == (0, 'DXFENTITY')
    assert tag[1] == (5, 'FFFF')
def test_dxf_export_two_attribute(entity, processor):
    attribs = DXFNamespace(processor, entity)
    tagwriter = TagCollector()
    attribs.export_dxf_attribs(tagwriter, ["handle", "owner"])
    assert len(tagwriter.tags) == 2
    assert tagwriter.tags[0] == (5, "FFFF")
    assert tagwriter.tags[1] == (330, "ABBA")
Beispiel #14
0
def test_create_gradient_low_level_dxf_tags(hatch):
    hatch.set_gradient((10, 10, 10), (250, 250, 250), rotation=180.)
    tags = TagCollector.dxftags(hatch.gradient)
    for code in [450, 451, 452, 453, 460, 461, 462, 470]:
        assert tags.has_tag(code) is True, "missing required tag: %d" % code
    assert 2 == len(tags.find_all(463))
    assert 2 == len(tags.find_all(421))
Beispiel #15
0
def test_dxf_export_two_attribute(entity, processor):
    attribs = DXFNamespace(processor, entity)
    tagwriter = TagCollector()
    attribs.export_dxf_attribs(tagwriter, ['handle', 'owner'])
    assert len(tagwriter.tags) == 2
    assert tagwriter.tags[0] == (5, 'FFFF')
    assert tagwriter.tags[1] == (330, 'ABBA')
def test_dxf_tags(doc):
    buffer = cast(FieldList, doc.objects.new_entity("FIELDLIST", {}))
    buffer.handles = ["FF", "EE", "DD", "CC"]
    tags = TagCollector.dxftags(buffer)[-4:]

    assert len(tags) == 4
    assert tags[0] == (330, "FF")
    assert tags[-1] == (330, "CC")
Beispiel #17
0
def test_ac1024_write(table):
    collector = TagCollector(dxfversion="R2004")
    table.export_dxf(collector)
    tags = collector.tags
    assert tags[0] == (0, "TABLE")
    assert tags[1] == (2, "APPID")
    # exporting table entries is tested by associated class tests
    assert tags[-1] == (0, "ENDTAB")
Beispiel #18
0
def test_do_not_write_line_endings():
    txt = MText()
    txt.text = 'test\ntext\r'
    collector = TagCollector(optional=True)
    txt.export_dxf(collector)
    for tag in collector.tags:
        if tag[0] == 1:
            assert tag[1] == 'test\\Ptext\\P'
def test_export_dimension(dim):
    tagwriter = TagCollector(dxfversion=DXF2010)
    dim.export_dxf(tagwriter)
    assert (10, 46) in tagwriter.tags
    assert (13, 46) in tagwriter.tags
    assert (14, 47) in tagwriter.tags
    assert (15, 49) in tagwriter.tags
    assert (40, 0.0) in tagwriter.tags
Beispiel #20
0
def test_dxf_export_one_attribute(entity, processor):
    attribs = DXFNamespace(processor, entity)
    tagwriter = TagCollector()
    attribs.export_dxf_attribs(tagwriter, 'handle')
    assert len(tagwriter.tags) == 1
    assert tagwriter.tags[0] == (5, 'FFFF')
    with pytest.raises(DXFAttributeError):
        attribs.export_dxf_attribute(tagwriter, 'mozman')
def test_dxf_tags(doc):
    buffer = cast(LayerFilter, doc.objects.new_entity("LAYER_FILTER", {}))
    buffer.handles = ["FF", "EE", "DD", "CC"]
    tags = TagCollector.dxftags(buffer)[-4:]

    assert len(tags) == 4
    assert tags[0] == (330, "FF")
    assert tags[-1] == (330, "CC")
def test_dxf_tags(doc):
    buffer = cast(LayerFilter, doc.objects.new_entity('LAYER_FILTER', {}))
    buffer.handles = ['FF', 'EE', 'DD', 'CC']
    tags = TagCollector.dxftags(buffer)[-4:]

    assert len(tags) == 4
    assert tags[0] == (330, 'FF')
    assert tags[-1] == (330, 'CC')
Beispiel #23
0
def test_vertex_array_to_dxf_tags():
    tags = ExtendedTags.from_text(SPLINE)
    vertices = VertexArray.from_tags(tags.get_subclass('AcDbSpline'))
    tags = TagCollector.dxftags(vertices)
    assert len(tags) == 7 * 3
    assert tags[0] == (10, 0.)
    assert tags[3] == (10, 10.)
    assert tags[-1] == (30, 60.)
Beispiel #24
0
def test_dxf_tags(doc):
    id_buffer = cast(IDBuffer, doc.objects.new_entity('IDBUFFER', {}))
    id_buffer.handles = ['FF', 'EE', 'DD', 'CC']
    tags = TagCollector.dxftags(id_buffer)[-4:]

    assert len(tags) == 4
    assert tags[0] == (330, 'FF')
    assert tags[-1] == (330, 'CC')
Beispiel #25
0
def test_dxf_tags(doc):
    id_buffer = cast(IDBuffer, doc.objects.new_entity("IDBUFFER", {}))
    id_buffer.handles = ["FF", "EE", "DD", "CC"]
    tags = TagCollector.dxftags(id_buffer)[-4:]

    assert len(tags) == 4
    assert tags[0] == (330, "FF")
    assert tags[-1] == (330, "CC")
Beispiel #26
0
def test_export_dimtxsty(doc):
    dimstyle = doc.dimstyles.get(DIMSTYLE_NAME)
    style = doc.styles.get(TEXTSTYLE_NAME)
    t = TagCollector()
    dimstyle.export_dxf(t)
    tags = Tags(t.tags)
    dimtxsty_handle = tags.get_first_value(340)
    assert style.dxf.handle == dimtxsty_handle
Beispiel #27
0
def test_ac1024_write(table):
    collector = TagCollector(dxfversion='R2004')
    table.export_dxf(collector)
    tags = collector.tags
    assert tags[0] == (0, 'TABLE')
    assert tags[1] == (2, 'APPID')
    # exporting table entries is tested by associated class tests
    assert tags[-1] == (0, 'ENDTAB')
Beispiel #28
0
def test_write_latest_dxf(entity):
    tagwriter = TagCollector()
    entity.export_dxf(tagwriter)
    tag = tagwriter.tags
    assert len(tag) == 3
    assert tag[0] == (0, 'DXFENTITY')
    assert tag[1] == (5, 'FFFF')
    assert tag[2] == (330, 'ABBA')
Beispiel #29
0
def test_dxf_tags(doc):
    buffer = cast(FieldList, doc.objects.new_entity('FIELDLIST', {}))
    buffer.handles = ['FF', 'EE', 'DD', 'CC']
    tags = TagCollector.dxftags(buffer)[-4:]

    assert len(tags) == 4
    assert tags[0] == (330, 'FF')
    assert tags[-1] == (330, 'CC')
Beispiel #30
0
def test_required_escaping_of_line_endings_at_dxf_export(layout, text):
    txt = layout.add_mtext(text)
    collector = TagCollector(optional=True)
    txt.export_dxf(collector)
    for tag in collector.tags:
        if tag[0] == 1:
            assert tag[1].count(r'\P') == 1
            assert '\n' not in tag[1]
            assert '\r' not in tag[1]