-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improve the ezdxf.render.dim_base.Measurement class
Improves the text override feature of the Measurement class. Replaces the first occurrence of "<>" in then replacement text, so string interpolation from "$<> xyz" to "$300 xyz" for a measurement of 300 units is now possible. Replaces only the first "<>" like BricsCAD. The override text "<><>" evaluates to "300<>" for the previous measurement.
- Loading branch information
Showing
3 changed files
with
118 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# Copyright (c) 2024 Manfred Moitzi | ||
# License: MIT License | ||
import pytest | ||
import ezdxf | ||
from ezdxf.layouts import Modelspace | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def msp() -> Modelspace: | ||
doc = ezdxf.new("R2007", setup=True) | ||
return doc.modelspace() | ||
|
||
|
||
@pytest.mark.parametrize("text", ["", "<>"]) | ||
def test_regular_measurement_text(msp, text): | ||
dim = msp.add_linear_dim( | ||
base=(0, 2), | ||
p1=(0, 0), | ||
p2=(3, 0), | ||
) | ||
dim.set_text(text) | ||
|
||
block = dim.render().geometry.layout | ||
mtext = block.query("MTEXT").first | ||
assert mtext.text == "300" | ||
|
||
|
||
def test_suppress_measurement_text(msp): | ||
dim = msp.add_linear_dim( | ||
base=(0, 2), | ||
p1=(0, 0), | ||
p2=(3, 0), | ||
) | ||
dim.set_text(" ") | ||
|
||
block = dim.render().geometry.layout | ||
assert len(block.query("MTEXT")) == 0 # no MTEXT entity expected | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"text,expected", | ||
[ | ||
("<>", "300"), | ||
("Ø <>", "Ø 300"), | ||
("<> cm", "300 cm"), | ||
("[ <> ]", "[ 300 ]"), | ||
("<> <>", "300 <>"), # only the first "<>" will be replaced | ||
], | ||
) | ||
def test_override_measurement_text(msp, text, expected): | ||
dim = msp.add_linear_dim( | ||
base=(0, 2), | ||
p1=(0, 0), | ||
p2=(3, 0), | ||
) | ||
dim.set_text(text) | ||
|
||
block = dim.render().geometry.layout | ||
mtext = block.query("MTEXT").first | ||
assert mtext.text == expected | ||
|
||
|
||
if __name__ == "__main__": | ||
pytest.main([__file__]) |