def test_has_outside_text_and_arrows(doc: Drawing, angle):
    """The space between extension lines is too narrow to place text and arrows."""
    for dim in measure_fixed_angle(doc.modelspace(), angle=angle):
        render_obj = dim.render()
        assert isinstance(render_obj, _CurvedDimensionLine)
        assert render_obj.arrows_outside is True
        assert render_obj.measurement.text_is_outside is True
        assert render_obj.measurement.is_wide_text is True
示例#2
0
def add_graphic_entity_to_root_dict(doc: Drawing):
    msp = doc.modelspace()
    line = msp.add_line((0, 0), (1, 0))
    # Question: is it possible to store graphical entities which reside in a
    # layout in the root dictionary (Autodesk term: the named dictionary)
    # doc.rootdict["LINE"] = line  # this does not work for v0.17 as consequence!
    # HACK HACK HACK!!! - DO NOT USE HANDLES IN PRODUCTION CODE!
    doc.rootdict["LINE"] = line.dxf.handle
def _get_text_visible_when(doc: Drawing, active_layers: Set[str]) -> List[str]:
    ctx = RenderContext(doc)
    # set given layer to ON, others to OFF
    ctx.set_layers_state(active_layers, state=True)

    backend = BasicBackend()
    Frontend(ctx, backend).draw_layout(doc.modelspace())
    visible_text = [x[1] for x in backend.collector if x[0] == 'text']
    return visible_text
def test_has_outside_text_and_arrows_but_not_a_wide_text(doc: Drawing):
    """The space between extension lines is too narrow to place text and arrows,
    but the text alone has enough space.
    """
    for dim in measure_fixed_angle(doc.modelspace(), angle=9):
        render_obj = dim.render()
        assert isinstance(render_obj, _CurvedDimensionLine)
        assert render_obj.arrows_outside is True
        assert render_obj.measurement.text_is_outside is True
        assert render_obj.measurement.is_wide_text is False
def test_text_and_arrows_fit_between_extension_lines(doc: Drawing):
    """There is enough space between extension lines is to place text and
    arrows.
    """
    for dim in measure_fixed_angle(doc.modelspace(), angle=20):
        render_obj = dim.render()
        assert isinstance(render_obj, _CurvedDimensionLine)
        assert render_obj.arrows_outside is False
        assert render_obj.measurement.is_wide_text is False
        assert render_obj.measurement.text_is_outside is False
def test_fixed_length_extension_lines(doc: Drawing):
    msp = doc.modelspace()
    dim = msp.add_angular_dim_cra(
        center=(0, 0),
        radius=5,
        distance=2,
        start_angle=0,
        end_angle=90,
        override={
            "dimfxlon": 1,  # use fixed length extension lines
            "dimexe": 0.7,  # length "above" the dimension line
            "dimfxl": 0.5,  # length "below" the dimension line
        },
    ).render()
    # only the extension lines are LINE entities:
    for line in dim.dimension.get_geometry_block().query("LINE"):
        length = line.dxf.start.distance(line.dxf.end)
        assert length == pytest.approx(0.5 + 0.7)
def test_dimension_line_divided_by_measurement_text(doc: Drawing, s, e):
    """Vertical centered measurement text should hide the part of the
    dimension line beneath the text. This creates two arcs instead of one.
    """
    msp = doc.modelspace()
    dim = msp.add_angular_dim_cra(
        center=Vec2(),
        radius=5,
        start_angle=s,
        end_angle=e,
        distance=2,
        override={"dimtad": 0},  # vertical centered text
    )
    dim.render()
    arcs = dim.dimension.get_geometry_block().query("ARC")
    assert len(arcs) == 2
    assert sum(
        arc_angle_span_deg(arc.dxf.start_angle, arc.dxf.end_angle)
        for arc in arcs) < arc_angle_span_deg(
            s, e), "sum of visual arcs should be smaller than the full arc"