File: test_216_dimlines_R12.py

package info (click to toggle)
ezdxf 1.4.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 104,528 kB
  • sloc: python: 182,341; makefile: 116; lisp: 20; ansic: 4
file content (159 lines) | stat: -rw-r--r-- 4,748 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# Copyright (c) 2018-2019 Manfred Moitzi
# License: MIT License
import pytest
import ezdxf


@pytest.fixture(scope="module")
def dxf12():
    dwg = ezdxf.new("R12", setup="all")
    return dwg


def test_dimstyle_standard_exist(dxf12):
    assert "EZDXF" in dxf12.dimstyles


def test_dimstyle_override(dxf12):
    msp = dxf12.modelspace()
    dimstyle = msp.add_linear_dim(
        base=(3, 2, 0),
        p1=(0, 0, 0),
        p2=(3, 0, 0),
        dxfattribs={
            "dimstyle": "EZDXF",
        },
    )
    dimline = dimstyle.dimension
    assert dimline.dxf.dimstyle == "EZDXF"

    preset = {
        "dimtxsty": "TEST",  # virtual attribute - 'dimtxsty_handle' stores the text style handle
        "dimexe": 0.777,
        "dimblk": ezdxf.ARROWS.dot_blank,
    }
    dimstyle.update(preset)
    assert dimstyle["dimtxsty"] == "TEST"
    assert dimstyle["dimexe"] == 0.777

    assert dimstyle["invalid"] is None

    # ignores invalid attributes
    dimstyle.update({"invalid": 7})
    assert dimstyle["invalid"] == 7
    dstyle_orig = dimstyle.get_dstyle_dict()
    assert len(dstyle_orig) == 0

    dimstyle.commit()
    # check group code 5 handling for 'dimblk'
    data = dimline.get_xdata_list("ACAD", "DSTYLE")
    for tag in data:
        if tag.value == ezdxf.ARROWS.dot_blank:
            assert (
                tag.code == 1000
            ), "Despite group code 5, 'dimblk' should be treated as string, not as handle"

    dstyle = dimstyle.get_dstyle_dict()
    assert dstyle["dimexe"] == 0.777
    # unsupported DXF DimStyle attributes are not stored in dstyle
    assert "dimtxsty" not in dstyle, "dimtxsty is not a DXF12 attribute"


def test_dimstyle_override_arrows(dxf12):
    msp = dxf12.modelspace()
    preset = {
        "dimblk": "XYZ",
        "dimblk1": "ABC",
        "dimblk2": "DEF",
        "dimldrblk": "ZZZLDR",  # not supported by DXF12, but used by ezdxf for rendering
    }

    dimstyle = msp.add_linear_dim(
        base=(3, 2, 0),
        p1=(0, 0, 0),
        p2=(3, 0, 0),
        dimstyle="EZDXF",
        override=preset,
    )

    assert dimstyle["dimblk"] == "XYZ"
    assert dimstyle["dimblk1"] == "ABC"
    assert dimstyle["dimblk2"] == "DEF"
    assert dimstyle["dimldrblk"] == "ZZZLDR"

    dstyle_orig = dimstyle.get_dstyle_dict()
    assert len(dstyle_orig) == 0

    dimstyle.commit()
    dstyle = dimstyle.get_dstyle_dict()
    assert dstyle["dimblk"] == "XYZ"
    assert dstyle["dimblk1"] == "ABC"
    assert dstyle["dimblk2"] == "DEF"
    assert "dimldrblk" not in dstyle, "not supported by DXF12"

    dimstyle.set_arrows(blk="BLK", blk1="B1", blk2="B2", ldrblk="LBLK")
    assert dimstyle["dimblk"] == "BLK"
    assert dimstyle["dimblk1"] == "B1"
    assert dimstyle["dimblk2"] == "B2"
    assert (
        dimstyle["dimldrblk"] == "LBLK"
    )  # not supported by DXF12, but used by ezdxf for rendering

    dimstyle.commit()
    dstyle = dimstyle.get_dstyle_dict()
    assert dstyle["dimblk"] == "BLK"
    assert dstyle["dimblk1"] == "B1"
    assert dstyle["dimblk2"] == "B2"
    assert "dimnldrblk" not in dstyle, "not supported by DXF12"


def test_dimstyle_override_linetypes(dxf12):
    msp = dxf12.modelspace()
    preset = {
        "dimltype": "DOT",
        "dimltex1": "DOT2",
        "dimltex2": "DOTX2",
    }
    dimstyle = msp.add_linear_dim(
        base=(3, 2, 0),
        p1=(0, 0, 0),
        p2=(3, 0, 0),
        dimstyle="EZDXF",
        override=preset,
    )
    assert dimstyle["dimltype"] == "DOT"
    assert dimstyle["dimltex1"] == "DOT2"
    assert dimstyle["dimltex2"] == "DOTX2"

    dimstyle.commit()
    dstyle = dimstyle.get_dstyle_dict()
    assert "dimltype" not in dstyle, "not supported by DXF12"
    assert "dimltype_handle" not in dstyle, "not supported by DXF12"
    assert "dimltex1" not in dstyle, "not supported by DXF12"
    assert "dimltex1_handle" not in dstyle, "not supported by DXF12"
    assert "dimltex2" not in dstyle, "not supported by DXF12"
    assert "dimltex2_handle" not in dstyle, "not supported by DXF12"


def test_horizontal_dimline(dxf12):
    msp = dxf12.modelspace()
    dimstyle = msp.add_linear_dim(
        base=(3, 2, 0),
        p1=(0, 0, 0),
        p2=(3, 0, 0),
    )
    dimline = dimstyle.dimension
    assert dimline.dxf.dimstyle == "EZDXF"

    dimstyle.render()
    block_name = dimline.dxf.geometry
    assert block_name.startswith("*D")

    # shortcut for: block = dxf12.blocks.get(block_name)
    block = dimline.get_geometry_block()
    assert len(list(block.query("TEXT"))) == 1
    assert len(list(block.query("INSERT"))) == 2
    assert (
        len(list(block.query("LINE"))) == 3
    )  # dimension line + 2 extension lines
    assert len(list(block.query("POINT"))) == 3  # def points