Exemple #1
0
    def save_to_database(self, glyph):
        """ Save list of point dictionary to database """

        for point in self.points:
            glyphpoint = GlyphPoint.get(glyphname=glyph.name, glyph_id=glyph.id,
                                        master_id=glyph.master_id,
                                        pointnr=point['number'])
            if not glyphpoint:
                glyphpoint = GlyphPoint.create(glyphname=glyph.name,
                                               glyph_id=glyph.id,
                                               master_id=glyph.master_id,
                                               pointnr=point['number'])
            glyphpoint.x = self.x(point)
            glyphpoint.y = self.y(point)

            glyphpointparam = GlyphPointParam.get(glyphpoint_id=glyphpoint.id,
                                                  glyph_id=glyph.id)
            if not glyphpointparam:
                glyphpointparam = GlyphPointParam.create(glyphpoint_id=glyphpoint.id,
                                                         master_id=glyph.master_id,
                                                         glyph_id=glyph.id,
                                                         pointname=self.name(point))
            for attr in point['preset']:
                if attr == 'name':
                    continue
                setattr(glyphpointparam, attr, point['preset'][attr])

        web.ctx.orm.commit()
Exemple #2
0
def get_glyph_points_from_db(master, glyphid):
    """ Returns json with information about glyphs' points including coords
        and point parameters.

        Example result:
        ```yaml
        ---
          width: 1680
          points:
           -
             x: 12
             y: 123
             pointnr: 1
             iszpoint: true
             data:
               width: 1680
               width_new: 1490
               # then list of another point parameters
        ```
    """
    # todo: move mflist to another common module
    glyph = Glyph.get(master_id=master.id, name=glyphid)

    points = GlyphPoint.filter(glyph_id=glyph.id)
    localparam = LocalParam.get(id=master.idlocala)

    _points = []
    for point in points.order_by(GlyphPoint.pointnr.asc()):
        param = GlyphPointParam.get(glyphpoint_id=point.id)
        iszpoint = False
        if re.match('z(\d+)[lr]', param.pointname):
            iszpoint = True

        x = point.x
        if localparam:
            x += localparam.px

        params = param.as_dict()
        params.update({'width': glyph.width})
        params.update({'width_new': glyph.width_new})
        _points.append({
            'x': x,
            'y': point.y,
            'pointnr': point.pointnr,
            'iszpoint': iszpoint,
            'data': params
        })

    return {'width': glyph.width, 'points': _points}
Exemple #3
0
def get_glyph_points_from_db(master, glyphid):
    """ Returns json with information about glyphs' points including coords
        and point parameters.

        Example result:
        ```yaml
        ---
          width: 1680
          points:
           -
             x: 12
             y: 123
             pointnr: 1
             iszpoint: true
             data:
               width: 1680
               width_new: 1490
               # then list of another point parameters
        ```
    """
    # todo: move mflist to another common module
    glyph = Glyph.get(master_id=master.id, name=glyphid)

    points = GlyphPoint.filter(glyph_id=glyph.id)
    localparam = LocalParam.get(id=master.idlocala)

    _points = []
    for point in points.order_by(GlyphPoint.pointnr.asc()):
        param = GlyphPointParam.get(glyphpoint_id=point.id)
        iszpoint = False
        if re.match('z(\d+)[lr]', param.pointname):
            iszpoint = True

        x = point.x
        if localparam:
            x += localparam.px

        params = param.as_dict()
        params.update({'width': glyph.width})
        params.update({'width_new': glyph.width_new})
        _points.append({'x': x, 'y': point.y, 'pointnr': point.pointnr,
                        'iszpoint': iszpoint, 'data': params})

    return {'width': glyph.width, 'points': _points}