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 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
|
# Copyright (c) 2019-2020 Manfred Moitzi
# License: MIT License
# created 2019-02-15
from typing import cast
import pytest
import ezdxf
from ezdxf.entities.image import Wipeout
from ezdxf.lldxf.tagwriter import TagCollector, basic_tags_from_text
from ezdxf.layouts import VirtualLayout
from ezdxf.math import Vec2
@pytest.fixture
def doc():
return ezdxf.new()
def test_wipeout_default_new():
entity = Wipeout.new(
handle="ABBA", owner="0", dxfattribs={"image_size": (640, 200)}
)
assert entity.dxf.layer == "0"
assert entity.dxf.insert is None # set by add_image()
assert entity.dxf.u_pixel is None # set by add_image()
assert entity.dxf.v_pixel is None # set by add_image()
assert entity.dxf.class_version == 0
assert entity.dxf.image_size == (640, 200)
assert entity.dxf.image_def_handle == "0"
assert entity.dxf.flags == 3
assert entity.dxf.clipping == 0
assert entity.dxf.brightness == 50
assert entity.dxf.contrast == 50
assert entity.dxf.fade == 0
assert entity.dxf.image_def_reactor_handle == "0"
assert entity.dxf.clipping_boundary_type == 1
assert entity.dxf.clip_mode == 0
assert entity.boundary_path[0] == (-0.5, -0.5)
assert entity.boundary_path[1] == (639.5, 199.5)
def test_wipeout_write_dxf():
entity = Wipeout.from_text(WIPEOUT)
result = TagCollector.dxftags(entity)
expected = basic_tags_from_text(WIPEOUT)
assert result == expected
def test_wipeout_creator_interface():
layout = VirtualLayout()
wipeout = layout.add_wipeout(
[(150, 100), (250, 100), (250, 200), (150, 200)]
)
assert wipeout.dxftype() == "WIPEOUT"
assert wipeout.dxf.insert == (150, 100, 0)
assert wipeout.dxf.u_pixel == (100, 0, 0)
assert wipeout.dxf.v_pixel == (0, 100, 0)
assert wipeout.dxf.image_size == (1, 1)
assert wipeout.dxf.flags == 7
assert wipeout.dxf.clipping == 1
assert wipeout.dxf.clip_mode == 0
path = wipeout.boundary_path
assert path[0].isclose(Vec2(-0.5, 0.5))
assert path[1].isclose(Vec2(0.5, 0.5))
assert path[2].isclose(Vec2(0.5, -0.5))
assert path[3].isclose(Vec2(-0.5, -0.5))
assert path[4] == path[0]
path = wipeout.boundary_path_wcs()
assert path[0] == (150, 100)
assert path[1] == (250, 100)
assert path[2] == (250, 200)
assert path[3] == (150, 200)
assert path[0] == path[-1]
def test_copy_wipeout():
layout = VirtualLayout()
wipeout = layout.add_wipeout([(150, 100), (250, 200)])
copy = wipeout.copy()
layout.add_entity(copy)
assert len(layout) == 2
def test_wipeout_vars(doc):
doc.set_wipeout_variables(frame=1)
wipeout_variables = doc.rootdict["ACAD_WIPEOUT_VARS"]
assert wipeout_variables.dxf.frame == 1
def test_boundary_path_wcs():
from ezdxf.layouts import VirtualLayout
layout = VirtualLayout()
e = cast(
Wipeout,
layout.new_entity(
"WIPEOUT",
dxfattribs={
"layer": "0",
"class_version": 0,
"insert": (150.0, 100.0, 0.0),
"u_pixel": (100.0, 0.0, 0.0),
"v_pixel": (0.0, 100.0, 0.0),
"image_size": (1.0, 1.0, 0.0),
"image_def_handle": "0",
"flags": 7,
"clipping": 1,
"brightness": 50,
"contrast": 50,
"fade": 0,
"image_def_reactor_handle": "0",
"clipping_boundary_type": 2,
"count_boundary_points": 5,
"clip_mode": 0,
},
),
)
e.set_boundary_path(
[
(-0.5, 0.5),
(0.5, 0.5),
(0.5, -0.5),
(-0.5, -0.5),
(-0.5, 0.5),
]
)
path = e.boundary_path_wcs()
assert path[0] == (150, 100)
assert path[1] == (250, 100)
assert path[2] == (250, 200)
assert path[3] == (150, 200)
assert path[0] == path[-1]
WIPEOUT = """0
WIPEOUT
5
0
330
0
100
AcDbEntity
8
0
100
AcDbWipeout
90
0
10
0.0
20
0.0
30
0.0
11
0.0
21
0.0
31
0.0
12
0.0
22
0.0
32
0.0
13
640
23
320
340
0
70
3
280
1
281
50
282
50
283
0
360
0
71
1
91
2
14
-0.5
24
-0.5
14
639.5
24
319.5
290
0
"""
|