Example #1
0
def test_resolve_block_entities(doc):
    ctx = RenderContext(doc)
    msp = doc.modelspace()
    blockref = msp.query('INSERT').first
    ctx.push_state(ctx.resolve_all(blockref))
    assert ctx.is_block_context is True
    lines = list(blockref.virtual_entities())

    # properties by block
    line1 = ctx.resolve_all(lines[0])
    assert lines[0].dxf.linetype == 'BYBLOCK'
    assert line1.color == '#00ff00'
    assert line1.linetype_name == 'CENTER'
    assert line1.lineweight == 0.13

    # explicit properties
    line2 = ctx.resolve_all(lines[1])
    assert lines[1].dxf.linetype == 'DASHED'
    assert line2.color == '#ff0000'
    assert line2.linetype_name == 'DASHED'
    assert line2.lineweight == 0.50

    # properties by layer 'Test'
    line3 = ctx.resolve_all(lines[2])
    assert lines[2].dxf.linetype == 'BYLAYER'
    assert line3.color == '#0000ff'
    assert line3.linetype_name == 'DOT'
    assert line3.lineweight == 0.70

    ctx.pop_state()
    assert ctx.is_block_context is False
def test_resolve_block_entities(doc):
    ctx = RenderContext(doc)
    msp = doc.modelspace()
    blockref = msp.query("INSERT").first
    ctx.push_state(ctx.resolve_all(blockref))
    assert ctx.inside_block_reference is True
    lines = list(blockref.virtual_entities())

    # properties by block
    line1 = ctx.resolve_all(lines[0])
    assert lines[0].dxf.linetype == "BYBLOCK"
    assert line1.color == "#00ff00"
    assert line1.linetype_name == "CENTER"
    assert line1.lineweight == 0.13

    # explicit properties
    line2 = ctx.resolve_all(lines[1])
    assert lines[1].dxf.linetype == "DASHED"
    assert line2.color == "#ff0000"
    assert line2.linetype_name == "DASHED"
    assert line2.lineweight == 0.50

    # properties by layer 'Test'
    line3 = ctx.resolve_all(lines[2])
    assert lines[2].dxf.linetype == "BYLAYER"
    assert line3.color == "#0000ff"
    assert line3.linetype_name == "DOT"
    assert line3.lineweight == 0.70

    ctx.pop_state()
    assert ctx.inside_block_reference is False
Example #3
0
    def __init__(self, ctx: RenderContext, out: Backend):
        # RenderContext contains all information to resolve resources for a
        # specific DXF document.
        self.ctx = ctx

        # DrawingBackend is the interface to the render engine
        self.out = out

        # Transfer render context info to backend:
        ctx.update_backend_configuration(out)

        # Parents entities of current entity/sub-entity
        self.parent_stack: List[DXFGraphic] = []

        # Approximate a full circle by `n` segments, arcs have proportional
        # less segments
        self.circle_approximation_count = 128

        # The sagitta (also known as the versine) is a line segment drawn
        # perpendicular to a chord, between the midpoint of that chord and the
        # arc of the circle. https://en.wikipedia.org/wiki/Circle not used yet!
        # Could be used for all curves CIRCLE, ARC, ELLIPSE and SPLINE
        # self.approximation_max_sagitta = 0.01  # for drawing unit = 1m, max
        # sagitta = 1cm

        # set to None to disable nested polygon detection:
        self.nested_polygon_detection = nesting.fast_bbox_detection
 def ctx(self):
     doc = ezdxf.new()
     doc.layers.new(
         'TrueColor',
         dxfattribs={'true_color': ezdxf.rgb2int((0xB0, 0xB0, 0xB0))})
     context = RenderContext(doc)
     context.set_current_layout(doc.modelspace())
     return context
def test_existing_true_color_overrides_any_aci_color(doc):
    ctx = RenderContext(doc)
    line = factory.new("LINE")
    line.rgb = (255, 1, 1)
    for color in range(const.BYLAYER + 1):
        line.dxf.color = color
        props = ctx.resolve_all(line)
        assert (props.color == "#ff0101"
                ), "true_color should override any ACI color"
def test_resolve_entity_color(doc):
    ctx = RenderContext(doc)
    msp = doc.modelspace()
    lines = msp.query("LINE")
    line1 = ctx.resolve_all(lines[0])
    assert line1.color == "#0000ff"  # by layer

    line2 = ctx.resolve_all(lines[1])
    assert line2.color == "#ff0000"
def test_resolve_entity_linetype(doc):
    ctx = RenderContext(doc)
    msp = doc.modelspace()
    lines = msp.query("LINE")

    line1 = ctx.resolve_all(lines[0])
    assert line1.linetype_name == "DOT"  # by layer

    line2 = ctx.resolve_all(lines[1])
    assert line2.linetype_name == "DASHED"
def test_resolve_entity_lineweight(doc):
    ctx = RenderContext(doc)
    msp = doc.modelspace()
    lines = msp.query("LINE")

    line1 = ctx.resolve_all(lines[0])
    assert line1.lineweight == 0.70  # by layer

    line2 = ctx.resolve_all(lines[1])
    assert line2.lineweight == 0.50
Example #9
0
    def __init__(
            self,
            ctx: RenderContext,
            out: BackendInterface,
            config: Configuration = Configuration.defaults(),
    ):
        # RenderContext contains all information to resolve resources for a
        # specific DXF document.
        self.ctx = ctx
        self.out = out
        self.config = ctx.update_configuration(config)

        if self.config.pdsize is None or self.config.pdsize <= 0:
            self.log_message("relative point size is not supported")
            self.config = self.config.with_changes(pdsize=1)

        self.out.configure(self.config)

        # Parents entities of current entity/sub-entity
        self.parent_stack: List[DXFGraphic] = []

        self._dispatch = self._build_dispatch_table()

        # Supported DXF entities which use only proxy graphic for rendering:
        self._proxy_graphic_only_entities: Set[str] = {
            "MLEADER",  # todo: remove if MLeader.virtual_entities() is implemented
            "MULTILEADER",
            "ACAD_PROXY_ENTITY",
        }
def test_resolve_transparency_from_layer():
    doc = ezdxf.new()
    doc.layers.add("Layer_T50", color=1, transparency=0.50)
    msp = doc.modelspace()
    line = msp.add_line(
        (0, 0),
        (1, 0),
        dxfattribs={
            "color": 5,
            "layer": "Layer_T50",
        },
    )
    context = RenderContext(doc)
    context.set_current_layout(msp)
    prop = context.resolve_all(line)
    assert prop.color == "#0000ff7f"
Example #11
0
    def __init__(self,
                 ctx: RenderContext,
                 out: Backend,
                 proxy_graphics: int = USE_PROXY_GRAPHICS):
        # RenderContext contains all information to resolve resources for a
        # specific DXF document.
        self.ctx = ctx

        # DrawingBackend is the interface to the render engine
        self.out = out

        # To get proxy graphics support proxy graphics have to be loaded:
        # Set the global option ezdxf.options.load_proxy_graphics to True.
        # How to handle proxy graphics:
        # 0 = ignore proxy graphics
        # 1 = use proxy graphics if no rendering support by ezdxf exist
        # 2 = prefer proxy graphics over ezdxf rendering
        self.proxy_graphics = proxy_graphics

        # Transfer render context info to backend:
        ctx.update_backend_configuration(out)

        # Parents entities of current entity/sub-entity
        self.parent_stack: List[DXFGraphic] = []

        # Approximate a full circle by `n` segments, arcs have proportional
        # less segments
        self.circle_approximation_count = 128

        # The sagitta (also known as the versine) is a line segment drawn
        # perpendicular to a chord, between the midpoint of that chord and the
        # arc of the circle. https://en.wikipedia.org/wiki/Circle not used yet!
        # Could be used for all curves CIRCLE, ARC, ELLIPSE and SPLINE
        # self.approximation_max_sagitta = 0.01  # for drawing unit = 1m, max
        # sagitta = 1cm

        # set to None to disable nested polygon detection:
        self.nested_polygon_detection = fast_bbox_detection

        self._dispatch = self._build_dispatch_table()
def test_resolve_attrib_visibility():
    doc = ezdxf.new()
    layout = doc.modelspace()
    block = doc.blocks.new(name='block')
    doc.layers.new(name='invisible', dxfattribs={'color':
                                                 -1})  # color < 0 => invisible

    block.add_attdef('att1', (0, 0), '', {})
    block.add_attdef('att2', (0, 0), '', {'flags': const.ATTRIB_INVISIBLE})
    block.add_attdef('att3', (0, 0), '', {'layer': 'invisible'})

    i = layout.add_blockref('block', (0, 0))
    i.add_auto_attribs({'att1': 'abc', 'att2': 'def', 'att3': 'hij'})

    assert not i.attribs[0].is_invisible
    assert i.attribs[1].is_invisible
    assert not i.attribs[2].is_invisible

    ctx = RenderContext(layout.doc)
    assert ctx.resolve_visible(i.attribs[0]) is True
    assert ctx.resolve_visible(i.attribs[1]) is False
    assert ctx.resolve_visible(i.attribs[2]) is False
def test_resolve_attrib_visibility():
    doc = ezdxf.new()
    layout = doc.modelspace()
    block = doc.blocks.new(name="block")
    doc.layers.new(name="invisible", dxfattribs={"color":
                                                 -1})  # color < 0 => invisible

    block.add_attdef("att1", (0, 0), "", dxfattribs={})
    block.add_attdef("att2", (0, 0),
                     "",
                     dxfattribs={"flags": const.ATTRIB_INVISIBLE})
    block.add_attdef("att3", (0, 0), "", dxfattribs={"layer": "invisible"})

    i = layout.add_blockref("block", (0, 0))
    i.add_auto_attribs({"att1": "abc", "att2": "def", "att3": "hij"})

    assert not i.attribs[0].is_invisible
    assert i.attribs[1].is_invisible
    assert not i.attribs[2].is_invisible

    ctx = RenderContext(layout.doc)
    assert ctx.resolve_visible(i.attribs[0]) is True
    assert ctx.resolve_visible(i.attribs[1]) is False
    assert ctx.resolve_visible(i.attribs[2]) is False
def test_resolve_entity_visibility():
    doc = ezdxf.new()
    layout = doc.modelspace()
    doc.layers.new(name="visible", dxfattribs={"color": 0})
    doc.layers.new(name="invisible", dxfattribs={"color":
                                                 -1})  # color < 0 => invisible
    doc.layers.new(name="frozen", dxfattribs={"flags":
                                              Layer.FROZEN})  # also invisible
    doc.layers.new(name="noplot", dxfattribs={
        "plot": 0
    })  # visible in the CAD application but not when exported

    for export_mode in (False, True):
        ctx = RenderContext(layout.doc, export_mode=export_mode)

        text = layout.add_text("a",
                               dxfattribs={
                                   "invisible": 0,
                                   "layer": "non_existent"
                               })
        assert ctx.resolve_visible(text) is True

        text = layout.add_text("a",
                               dxfattribs={
                                   "invisible": 0,
                                   "layer": "visible"
                               })
        assert ctx.resolve_visible(text) is True

        for layer in ["invisible", "frozen"]:
            text = layout.add_text("a",
                                   dxfattribs={
                                       "invisible": 0,
                                       "layer": layer
                                   })
            assert ctx.resolve_visible(text) is False

        for layer in [
                "non_existent",
                "visible",
                "invisible",
                "frozen",
                "noplot",
        ]:
            text = layout.add_text("a",
                                   dxfattribs={
                                       "invisible": 1,
                                       "layer": layer
                                   })
            assert ctx.resolve_visible(text) is False

    ctx = RenderContext(layout.doc, export_mode=False)
    text = layout.add_text("a", dxfattribs={"invisible": 0, "layer": "noplot"})
    assert ctx.resolve_visible(text) is True

    ctx = RenderContext(layout.doc, export_mode=True)
    text = layout.add_text("a", dxfattribs={"invisible": 0, "layer": "noplot"})
    assert ctx.resolve_visible(text) is False
def test_new_ctb(doc):
    ctx = RenderContext(doc)
    assert bool(ctx.plot_styles) is True
    assert ctx.plot_styles[1].color == (255, 0, 0)
def test_load_default_ctb(doc):
    ctx = RenderContext(doc, ctb="color.ctb")
    assert bool(ctx.plot_styles) is True
    assert ctx.plot_styles[1].color == (255, 0, 0)
def test_resolve_entity_visibility():
    doc = ezdxf.new()
    layout = doc.modelspace()
    doc.layers.new(name='visible', dxfattribs={'color': 0})
    doc.layers.new(name='invisible', dxfattribs={'color':
                                                 -1})  # color < 0 => invisible
    doc.layers.new(name='frozen', dxfattribs={'flags':
                                              Layer.FROZEN})  # also invisible
    doc.layers.new(name='noplot', dxfattribs={
        'plot': 0
    })  # visible in the CAD application but not when exported

    for export_mode in (False, True):
        ctx = RenderContext(layout.doc, export_mode=export_mode)

        text = layout.add_text('a', {'invisible': 0, 'layer': 'non_existent'})
        assert ctx.resolve_visible(text) is True

        text = layout.add_text('a', {'invisible': 0, 'layer': 'visible'})
        assert ctx.resolve_visible(text) is True

        for layer in ['invisible', 'frozen']:
            text = layout.add_text('a', {'invisible': 0, 'layer': layer})
            assert ctx.resolve_visible(text) is False

        for layer in [
                'non_existent', 'visible', 'invisible', 'frozen', 'noplot'
        ]:
            text = layout.add_text('a', {'invisible': 1, 'layer': layer})
            assert ctx.resolve_visible(text) is False

    ctx = RenderContext(layout.doc, export_mode=False)
    text = layout.add_text('a', {'invisible': 0, 'layer': 'noplot'})
    assert ctx.resolve_visible(text) is True

    ctx = RenderContext(layout.doc, export_mode=True)
    text = layout.add_text('a', {'invisible': 0, 'layer': 'noplot'})
    assert ctx.resolve_visible(text) is False