Example #1
0
    def __init__(self, vis_model, il, model):
        BaseViewWidget.__init__(self)

        self.il = il
        self.iv = ImageView(il)
        self.model = model
        self.vis_model = vis_model

        self.overlays = set()
        self.active_overlays = set()

        self.setFocusPolicy(QtCore.Qt.StrongFocus)

        self.viewState.transform = scale(0.80)

        self.originView = OriginView()

        self.text_batch = TextBatcher(self.gls.text)
Example #2
0
    def __init__(self, project):
        BaseViewWidget.__init__(self)
        self.project = project

        self.image_view_cache = { }

        self.pad_renderer = PadRender(self)
        self.dip_renderer = DIPRender(self)
        self.smd_renderer = SMDRender(self)
        self.trace_renderer = TraceRender(self)
        self.via_renderer = THRenderer(self)
        self.text_batch = TextBatcher(self.gls.text)
        self.poly_renderer = CachedPolygonRenderer(self)
        self.hairline_renderer = HairlineRenderer(self)
        self.passive_renderer = PassiveRender(self)

        # Initial view is a normalized 1-1-1 area.
        # Shift to be 10cm max
        self.viewState.transform = translate(-0.9, -0.9).dot(scale(1./100000))
Example #3
0
    def __init__(self, vis_model: VisibilityModelRoot, il: ImageLayer,
                 model) -> None:
        BaseViewWidget.__init__(self)

        self.il = il
        self.iv = ImageView(il)
        self.model = model
        self.vis_model = vis_model

        self.overlays: Set[OverlayProtocol] = set()
        self.active_overlays: Set[OverlayProtocol] = set()

        self.setFocusPolicy(QtCore.Qt.StrongFocus)

        self.viewState.set_scale(0.80)

        self.originView = OriginView()

        self.text_batch = TextBatcher(self.gls.text)
Example #4
0
    def __init__(self, project):
        BaseViewWidget.__init__(self)
        self.project = project

        self.image_view_cache = { }

        self.pad_renderer = PadRender(self)
        self.dip_renderer = DIPRender(self)
        self.smd_renderer = SMDRender(self)
        self.trace_renderer = TraceRender(self)
        self.via_renderer = THRenderer(self)
        self.text_batch = TextBatcher(self.gls.text)
        self.poly_renderer = CachedPolygonRenderer(self)
        self.hairline_renderer = HairlineRenderer(self)
        self.passive_renderer = PassiveRender(self)

        # Initial view is a normalized 1-1-1 area.
        # Shift to be 10cm max
        self.viewState.transform = translate(-0.9, -0.9).dot(scale(1./100000))
Example #5
0
class AlignmentViewWidget(BaseViewWidget):
    def __init__(self, vis_model, il, model):
        BaseViewWidget.__init__(self)

        self.il = il
        self.iv = ImageView(il)
        self.model = model
        self.vis_model = vis_model

        self.overlays = set()
        self.active_overlays = set()

        self.setFocusPolicy(QtCore.Qt.StrongFocus)

        self.viewState.transform = scale(0.80)

        self.originView = OriginView()

        self.text_batch = TextBatcher(self.gls.text)

    def reinit(self):
        self.iv.initGL(self.gls)
        self.iv_cache = {}

        for ov in self.overlays:
            ov.initializeGL(self.gls)

        self.originView.initializeGL(self.gls)

        self.text_batch.initializeGL()

    def get_iv(self, il):
        if il is self.iv.il:
            return self.iv

        if il not in self.iv_cache:
            iv = ImageView(il)

            iv.initGL(self.gls)

            self.iv_cache[il]  = iv


        return self.iv_cache[il]

    def get_flattened(self, n=None, l=None):
        if l is None:
            l = []

        if n is None:
            n = self.vis_model

        for i in n.children:
            if hasattr(i, "_il_obj") and i.visible:
                l.append(i._il_obj)
            else:
                self.get_flattened(i, l)

        return l

    def render(self):
        self.text_batch.restart()
        GL.glEnable(GL.GL_BLEND)
        if self.model.align_by == ALIGN_BY_DIMENSIONS:
            if self.model.view_mode == VIEW_MODE_UNALIGNED:
                self.iv.mat = numpy.identity(3)
            else:
                self.iv.mat = self.model.ra.image_matrix
        else:
            if self.model.view_mode == VIEW_MODE_UNALIGNED:
                self.iv.mat = numpy.identity(3)
            else:
                self.iv.mat = self.model.kp.image_matrix

        # Render the base image
        if self.model.view_mode == VIEW_MODE_UNALIGNED:
            self.iv.render(self.viewState.glMatrix)
        else:
            # Draw all visible layers bottom to top
            all_ils = list(reversed(self.get_flattened()))

            for il in all_ils:
                iv = self.get_iv(il)
                iv.render(self.viewState.glMatrix)

        for ovl in self.active_overlays:
            ovl.render(self.viewState)


        self.text_batch.render()


    def keyPressEvent(self, evt):
        if self.interactionDelegate:
            self.interactionDelegate.keyPressEvent(evt)

    def focusNextPrevChild(self, next):
        found = False

        if self.interactionDelegate:
            found = self.interactionDelegate.next_prev_child(next)

        if not found:
            return super(AlignmentViewWidget, self).focusNextPrevChild(next)
        return True

    def focusOutEvent(self, evt):
        if self.interactionDelegate:
            self.interactionDelegate.focusOutEvent(evt)
Example #6
0
class BoardViewWidget(BaseViewWidget):
    def __init__(self, project):
        BaseViewWidget.__init__(self)
        self.project = project

        self.image_view_cache = { }

        self.pad_renderer = PadRender(self)
        self.dip_renderer = DIPRender(self)
        self.smd_renderer = SMDRender(self)
        self.trace_renderer = TraceRender(self)
        self.via_renderer = THRenderer(self)
        self.text_batch = TextBatcher(self.gls.text)
        self.poly_renderer = CachedPolygonRenderer(self)
        self.hairline_renderer = HairlineRenderer(self)
        self.passive_renderer = PassiveRender(self)

        # Initial view is a normalized 1-1-1 area.
        # Shift to be 10cm max
        self.viewState.transform = translate(-0.9, -0.9).dot(scale(1./100000))



    def text_color(self):
        return [1,1,1]

    def current_layer_hack(self):
        return self.viewState.current_layer

    def color_for_pad(self, pad):
        if pad.th_diam != 0:
            return [0.5, 0.5, 0.5]

        return self.color_for_layer(pad.layer)

    def color_for_trace(self, trace):
        return self.color_for_layer(trace.layer)

    def color_for_layer(self, layer):
        return list(layer.color)

    def sel_colormod(self, t, oldcolor):
        if t:
            return [1,1,1,1]
        return oldcolor



    def image_view_cache_load(self, il):
        key = id(il)
        if key not in self.image_view_cache:
            iv = ImageView(il)
            iv.initGL(self.gls)
            self.image_view_cache[key] = iv

        return self.image_view_cache[key]

    def reinit(self):
        self.pad_renderer.initializeGL(self, self.gls)
        self.dip_renderer.initializeGL(self.gls)
        self.smd_renderer.initializeGL(self.gls)
        self.trace_renderer.initializeGL(self.gls)
        self.via_renderer.initializeGL(self.gls)
        self.text_batch.initializeGL()
        self.poly_renderer.initializeGL()
        self.hairline_renderer.initializeGL()

        for i in list(self.image_view_cache.values()):
            i.initGL()

    def getVisibleArtwork(self):
        objects = []
        objects += self.project.artwork.vias
        objects += self.project.artwork.traces
        objects += self.project.artwork.polygons
        objects += self.project.artwork.airwires
        return objects


    def render_component(self, mat, cmp, render_mode=RENDER_STANDARD, render_hint=RENDER_HINT_NORMAL):
        if not self.layer_visible_m(cmp.on_layers()):
            return

        if isinstance(cmp, DIPComponent):
            self.dip_renderer.render(mat, cmp, render_mode, render_hint)
        elif isinstance(cmp, SMD4Component):
            self.smd_renderer.render(mat, cmp, render_mode, render_hint)
        elif isinstance(cmp, PassiveComponent):
            self.passive_renderer.render(mat, cmp, render_mode, render_hint)
        else:
            pass
            #raise TypeError("Can't render %s" % cmp)

        cm = mat.dot(cmp.matrix)

        for pad in cmp.get_pads():
            pad_render_mode = render_mode
            if not pad.is_through() and not self.layer_visible(pad.layer):
                continue

            if pad in self.selectionList:
                pad_render_mode |= RENDER_SELECTED
            self.pad_renderer.render(cm, pad, pad_render_mode, render_hint)


    def layer_visible(self, l):
        return l is self.viewState.current_layer or self.viewState.draw_other_layers

    def layer_visible_m(self, l):
        return self.viewState.current_layer in l or self.viewState.draw_other_layers

    def render(self):
        t_render_start = time.time()

        # zero accuum buffers for restarts
        self.trace_renderer.restart()
        self.via_renderer.restart()
        self.text_batch.restart()
        self.poly_renderer.restart()
        self.hairline_renderer.restart()

        stackup_layer = self.viewState.current_layer
        if stackup_layer is None:
            return

        # Render all images down onto the layer
        with Timer() as il_timer:
            if self.viewState.show_images:
                for l in stackup_layer.imagelayers:
                    self.image_view_cache_load(l).render(self.viewState.glMatrix)

        # Now render features
        self.lt = time.time()


        GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA)

        artwork = self.getVisibleArtwork()

        # Build rendering batches
        with Timer() as t_aw:
            for i in artwork:
                rs = RENDER_SELECTED if i in self.selectionList else 0

                if isinstance(i, Trace):
                    if self.layer_visible(i.layer):
                        self.trace_renderer.deferred(i, rs, RENDER_HINT_NORMAL)
                elif isinstance(i, Via):
                    if self.layer_visible_m(i.viapair.all_layers):
                        self.via_renderer.deferred(i.pt, i.r, 0, rs, RENDER_HINT_NORMAL)
                elif isinstance(i, Polygon):
                    if self.layer_visible(i.layer):
                        self.poly_renderer.deferred(i, rs, RENDER_HINT_NORMAL)
                elif isinstance(i, Airwire):
                    self.hairline_renderer.deferred(i.p0, i.p1, AIRWIRE_COLOR, None, RENDER_HINT_NORMAL)
                else:
                    raise NotImplementedError()


        with Timer() as cmp_timer:
            for cmp in self.project.artwork.components:
                render_state = 0
                if cmp in self.selectionList:
                    render_state |= RENDER_SELECTED
                self.render_component(self.viewState.glMatrix, cmp, render_state)

        with Timer() as other_timer:
            super(BoardViewWidget, self).render()

        def ly_order_func(layer):
            # We always draw the current layer last
            if layer is self.viewState.current_layer:
                return 1

            return -layer.order

        with Timer() as t:
            # Draw all the layers
            layers = sorted(self.project.stackup.layers, key=ly_order_func)
            for layer in layers:
                self.trace_renderer.render_deferred_layer(self.viewState.glMatrix, layer)
                self.poly_renderer.render(self.viewState.glMatrix, layer)
                self.text_batch.render(key=layer)
                self.hairline_renderer.render_group(self.viewState.glMatrix, layer)

            self.via_renderer.render(self.viewState.glMatrix)

            # Render the non-layer text
            self.text_batch.render()
            self.hairline_renderer.render_group(self.viewState.glMatrix, None)

            self.hairline_renderer.render_group(self.viewState.glWMatrix, "OVERLAY_VS")
            #self.hairline_renderer.render_group(self.viewState.glMatrix, "OVERLAY_VS")

            GL.glFinish()

        all_time = time.time() - t_render_start
        print("Render time all: %f ot: %f cmp: %f aw: %f gl: %f" % (all_time, other_timer.interval, cmp_timer.interval, t_aw.interval, t.interval))
Example #7
0
class BoardViewWidget(BaseViewWidget):
    def __init__(self, project):
        BaseViewWidget.__init__(self)
        self.project = project

        self.image_view_cache = { }

        self.pad_renderer = PadRender(self)
        self.dip_renderer = DIPRender(self)
        self.smd_renderer = SMDRender(self)
        self.trace_renderer = TraceRender(self)
        self.via_renderer = THRenderer(self)
        self.text_batch = TextBatcher(self.gls.text)
        self.poly_renderer = CachedPolygonRenderer(self)
        self.hairline_renderer = HairlineRenderer(self)
        self.passive_renderer = PassiveRender(self)

        # Initial view is a normalized 1-1-1 area.
        # Shift to be 10cm max
        self.viewState.transform = translate(-0.9, -0.9).dot(scale(1./100000))



    def text_color(self):
        return [1,1,1]

    def current_layer_hack(self):
        return self.viewState.current_layer

    def color_for_pad(self, pad):
        if pad.th_diam != 0:
            return [0.5, 0.5, 0.5]

        return self.color_for_layer(pad.layer)

    def color_for_trace(self, trace):
        return self.color_for_layer(trace.layer)

    def color_for_layer(self, layer):
        return list(layer.color)

    def sel_colormod(self, t, oldcolor):
        if t:
            return [1,1,1,1]
        return oldcolor



    def image_view_cache_load(self, il):
        key = id(il)
        if key not in self.image_view_cache:
            iv = ImageView(il)
            iv.initGL(self.gls)
            self.image_view_cache[key] = iv

        return self.image_view_cache[key]

    def reinit(self):
        self.pad_renderer.initializeGL(self, self.gls)
        self.dip_renderer.initializeGL(self.gls)
        self.smd_renderer.initializeGL(self.gls)
        self.trace_renderer.initializeGL(self.gls)
        self.via_renderer.initializeGL(self.gls)
        self.text_batch.initializeGL()
        self.poly_renderer.initializeGL()
        self.hairline_renderer.initializeGL()

        for i in list(self.image_view_cache.values()):
            i.initGL()

    def getVisibleArtwork(self):
        objects = []
        objects += self.project.artwork.vias
        objects += self.project.artwork.traces
        objects += self.project.artwork.polygons
        objects += self.project.artwork.airwires
        return objects


    def render_component(self, mat, cmp, render_mode=RENDER_STANDARD, render_hint=RENDER_HINT_NORMAL):
        if not self.layer_visible_m(cmp.on_layers()):
            return

        if isinstance(cmp, DIPComponent):
            self.dip_renderer.render(mat, cmp, render_mode, render_hint)
        elif isinstance(cmp, SMD4Component):
            self.smd_renderer.render(mat, cmp, render_mode, render_hint)
        elif isinstance(cmp, PassiveComponent):
            self.passive_renderer.render(mat, cmp, render_mode, render_hint)
        else:
            pass
            #raise TypeError("Can't render %s" % cmp)

        cm = mat.dot(cmp.matrix)

        for pad in cmp.get_pads():
            pad_render_mode = render_mode
            if not pad.is_through() and not self.layer_visible(pad.layer):
                continue

            if pad in self.selectionList:
                pad_render_mode |= RENDER_SELECTED
            self.pad_renderer.render(cm, pad, pad_render_mode, render_hint)


    def layer_visible(self, l):
        return l is self.viewState.current_layer or self.viewState.draw_other_layers

    def layer_visible_m(self, l):
        return self.viewState.current_layer in l or self.viewState.draw_other_layers

    def render(self):
        t_render_start = time.time()

        # zero accuum buffers for restarts
        self.trace_renderer.restart()
        self.via_renderer.restart()
        self.text_batch.restart()
        self.poly_renderer.restart()
        self.hairline_renderer.restart()

        stackup_layer = self.viewState.current_layer
        if stackup_layer is None:
            return

        # Render all images down onto the layer
        with Timer() as il_timer:
            if self.viewState.show_images:
                images = list(stackup_layer.imagelayers)
                i = self.viewState.layer_permute % len(images)
                images_cycled = images[i:] + images[:i]
                for l in images_cycled:
                    self.image_view_cache_load(l).render(self.viewState.glMatrix)

        # Now render features
        self.lt = time.time()


        GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA)

        artwork = self.getVisibleArtwork()

        # Build rendering batches
        with Timer() as t_aw:
            for i in artwork:
                rs = RENDER_SELECTED if i in self.selectionList else 0

                if isinstance(i, Trace):
                    if self.layer_visible(i.layer):
                        self.trace_renderer.deferred(i, rs, RENDER_HINT_NORMAL)
                elif isinstance(i, Via):
                    if self.layer_visible_m(i.viapair.all_layers):
                        self.via_renderer.deferred(i.pt, i.r, 0, rs, RENDER_HINT_NORMAL)
                elif isinstance(i, Polygon):
                    if self.layer_visible(i.layer):
                        self.poly_renderer.deferred(i, rs, RENDER_HINT_NORMAL)
                elif isinstance(i, Airwire):
                    self.hairline_renderer.deferred(i.p0, i.p1, AIRWIRE_COLOR, None, RENDER_HINT_NORMAL)
                else:
                    raise NotImplementedError()


        with Timer() as cmp_timer:
            for cmp in self.project.artwork.components:
                render_state = 0
                if cmp in self.selectionList:
                    render_state |= RENDER_SELECTED
                self.render_component(self.viewState.glMatrix, cmp, render_state)

        with Timer() as other_timer:
            super(BoardViewWidget, self).render()

        def ly_order_func(layer):
            # We always draw the current layer last
            if layer is self.viewState.current_layer:
                return 1

            return -layer.order

        with Timer() as t:
            # Draw all the layers
            layers = sorted(self.project.stackup.layers, key=ly_order_func)
            for layer in layers:
                self.trace_renderer.render_deferred_layer(self.viewState.glMatrix, layer)
                self.poly_renderer.render(self.viewState.glMatrix, layer)
                self.text_batch.render(key=layer)
                self.hairline_renderer.render_group(self.viewState.glMatrix, layer)

            self.via_renderer.render(self.viewState.glMatrix)

            # Render the non-layer text
            self.text_batch.render()
            self.hairline_renderer.render_group(self.viewState.glMatrix, None)

            self.hairline_renderer.render_group(self.viewState.glWMatrix, "OVERLAY_VS")
            #self.hairline_renderer.render_group(self.viewState.glMatrix, "OVERLAY_VS")

            GL.glFinish()

        all_time = time.time() - t_render_start
        print("Render time all: %f ot: %f cmp: %f aw: %f gl: %f" % (all_time, other_timer.interval, cmp_timer.interval, t_aw.interval, t.interval))
Example #8
0
class AlignmentViewWidget(BaseViewWidget):
    def __init__(self, vis_model: VisibilityModelRoot, il: ImageLayer,
                 model) -> None:
        BaseViewWidget.__init__(self)

        self.il = il
        self.iv = ImageView(il)
        self.model = model
        self.vis_model = vis_model

        self.overlays: Set[OverlayProtocol] = set()
        self.active_overlays: Set[OverlayProtocol] = set()

        self.setFocusPolicy(QtCore.Qt.StrongFocus)

        self.viewState.set_scale(0.80)

        self.originView = OriginView()

        self.text_batch = TextBatcher(self.gls.text)

    def reinit(self) -> None:
        """Reinitialize self render state and subview render state"""
        self.iv.initGL(self.gls)
        self.iv_cache = {}

        for ov in self.overlays:
            ov.initializeGL(self.gls)

        self.originView.initializeGL(self.gls)
        self.text_batch.initializeGL()

    def get_imageview(self, il: ImageLayer) -> None:
        """For an imagelayer, return an ImageView that can draw it"""
        if il is self.iv.il:
            return self.iv

        if il not in self.iv_cache:
            iv = ImageView(il)

            iv.initGL(self.gls)

            self.iv_cache[il] = iv

        return self.iv_cache[il]

    def get_flattened(self,
                      n: 'VisibilityNode' = None,
                      l: List = None) -> List[Any]:
        if l is None:
            l = []

        if n is None:
            n = self.vis_model

        for i in n.children:
            if i.visible == Visible.YES and i.obj is not None:
                l.append(i.obj)
            else:
                self.get_flattened(i, l)

        return l

    def render(self):
        self.text_batch.restart()
        GL.glEnable(GL.GL_BLEND)
        if self.model.align_by == AlignBy.Dimensions:
            if self.model.view_mode == ViewMode.UnAligned:
                self.iv.mat = numpy.identity(3)
            else:
                self.iv.mat = self.model.ra.image_matrix
        else:
            if self.model.view_mode == ViewMode.UnAligned:
                self.iv.mat = numpy.identity(3)
            else:
                self.iv.mat = self.model.kp.image_matrix

        # Render the base image
        if self.model.view_mode == ViewMode.UnAligned:
            self.iv.render(self.viewState.glMatrix)
        else:
            # Draw all visible layers bottom to top
            all_ils = list(reversed(self.get_flattened()))

            for il in all_ils:
                iv = self.get_imageview(il)
                iv.render(self.viewState.glMatrix)

        for ovl in self.active_overlays:
            ovl.render(self.viewState)

        self.text_batch.render()

    def focusNextPrevChild(self, next) -> bool:
        found = False

        if self.interactionDelegate:
            found = self.interactionDelegate.next_prev_child(next)

        if not found:
            return super(AlignmentViewWidget, self).focusNextPrevChild(next)
        return True

    def focusOutEvent(self, evt) -> None:
        if self.interactionDelegate:
            self.interactionDelegate.focusOutEvent(evt)