コード例 #1
0
ファイル: classes.py プロジェクト: yassineMrabet/bkchem
 def get_package(self, doc):
     """returns a DOM element describing the object in CDML,
 doc is the parent document which is used for element creation
 (the returned element is not inserted into the document)"""
     a = doc.createElement('text')
     a.setAttribute('id', self.id)
     if self.area_color != '':
         a.setAttribute('background-color', self.area_color)
     if self.font_size != self.paper.standard.font_size \
        or self.font_family != self.paper.standard.font_family \
        or self.line_color != self.paper.standard.line_color:
         font = dom_extensions.elementUnder(
             a,
             'font',
             attributes=(('size', str(self.font_size)), ('family',
                                                         self.font_family)))
         if self.line_color != self.paper.standard.line_color:
             font.setAttribute('color', self.line_color)
     x, y = Screen.px_to_text_with_unit((self.x, self.y))
     dom_extensions.elementUnder(a,
                                 'point',
                                 attributes=(('x', x), ('y', y)))
     ftext = dom_extensions.elementUnder(a, 'ftext')
     ftext.appendChild(doc.createTextNode(self.xml_ftext))
     return a
コード例 #2
0
ファイル: graphics.py プロジェクト: insilichem/bkchem
 def get_package(self, doc):
     """returns a DOM element describing the object in CDML,
 doc is the parent document which is used for element creation
 (the returned element is not inserted into the document)"""
     pack = doc.createElement('circle')
     x1, y1, x2, y2 = Screen.px_to_text_with_unit(
         self.paper.screen_to_real_coords(self.coords))
     dom_extensions.setAttributes(
         pack,
         (('x1', x1), ('y1', y1), ('x2', x2), ('y2', y2),
          ('area_color', self.area_color), ('line_color', self.line_color),
          ('width', str(self.line_width))))
     return pack
コード例 #3
0
ファイル: classes.py プロジェクト: yassineMrabet/bkchem
 def get_package(self, doc):
     """returns a DOM element describing the object in CDML,
 doc is the parent document which is used for element creation
 (the returned element is not inserted into the document)"""
     pls = doc.createElement('plus')
     pls.setAttribute('id', self.id)
     x, y = Screen.px_to_text_with_unit((self.x, self.y))
     dom_extensions.elementUnder(pls, 'point', (('x', x), ('y', y)))
     pls.setAttribute('font_size', str(self.font_size))
     if self.line_color != '#000':
         pls.setAttribute('color', self.line_color)
     if self.area_color != '#ffffff':
         pls.setAttribute('background-color', self.area_color)
     return pls
コード例 #4
0
ファイル: graphics.py プロジェクト: bartlebee/bkchem
 def get_package( self, doc):
   """returns a DOM element describing the object in CDML,
   doc is the parent document which is used for element creation
   (the returned element is not inserted into the document)"""
   pack = doc.createElement( 'circle')
   x1, y1, x2, y2 = Screen.px_to_text_with_unit( self.paper.screen_to_real_coords( self.coords))
   dom_extensions.setAttributes( pack, (('x1', x1),
                                        ('y1', y1),
                                        ('x2', x2),
                                        ('y2', y2),
                                        ('area_color', self.area_color),
                                        ('line_color', self.line_color),
                                        ('width', str( self.line_width))))
   return pack
コード例 #5
0
ファイル: classes.py プロジェクト: sctincman/bkchem
 def get_package( self, doc):
   """returns a DOM element describing the object in CDML,
   doc is the parent document which is used for element creation
   (the returned element is not inserted into the document)"""
   pls = doc.createElement('plus')
   pls.setAttribute( 'id', self.id)
   x, y = Screen.px_to_text_with_unit( (self.x, self.y))
   dom_extensions.elementUnder( pls, 'point', (('x', x),
                                               ('y', y)))
   pls.setAttribute('font_size', str( self.font_size))
   if self.line_color != '#000':
     pls.setAttribute( 'color', self.line_color)
   if self.area_color != '#ffffff':
     pls.setAttribute( 'background-color', self.area_color)
   return pls
コード例 #6
0
ファイル: classes.py プロジェクト: sctincman/bkchem
 def get_package( self, doc):
   """returns a DOM element describing the object in CDML,
   doc is the parent document which is used for element creation
   (the returned element is not inserted into the document)"""
   a = doc.createElement('text')
   a.setAttribute( 'id', self.id)
   if self.area_color != '':
     a.setAttribute( 'background-color', self.area_color)
   if self.font_size != self.paper.standard.font_size \
      or self.font_family != self.paper.standard.font_family \
      or self.line_color != self.paper.standard.line_color:
     font = dom_extensions.elementUnder( a, 'font', attributes=(('size', str( self.font_size)), ('family', self.font_family)))
     if self.line_color != self.paper.standard.line_color:
       font.setAttribute( 'color', self.line_color)
   x, y = Screen.px_to_text_with_unit( (self.x, self.y))
   dom_extensions.elementUnder( a, 'point', attributes=(('x', x),('y', y)))
   ftext = dom_extensions.elementUnder( a, 'ftext')
   ftext.appendChild( doc.createTextNode( self.xml_ftext))
   return a
コード例 #7
0
ファイル: xml_writer.py プロジェクト: insilichem/bkchem
    def construct_dom_tree(self, top_levels):
        """Construct the SVG dom from all top_levels.

    """
        # the constants
        border_size = self.paper.get_paper_property('crop_margin')

        # converter
        px_to_cm_txt = lambda x: Screen.px_to_text_with_unit(
            x, unit="cm", round_to=5)
        px_to_mm_txt = lambda x: Screen.px_to_text_with_unit(
            x, unit="mm", round_to=5)

        # the code
        self._id = 0
        doc = self.document
        self.top = dom_extensions.elementUnder(
            doc,
            "svg",
            attributes=(("xmlns", "http://www.w3.org/2000/svg"), ("version",
                                                                  "1.0")))
        if self.full_size:
            sx = self.paper.get_paper_property('size_x')
            sy = self.paper.get_paper_property('size_y')
            dom_extensions.setAttributes(
                self.top, (("width", '%fmm' % sx), ("height", '%fmm' % sy),
                           ('viewBox', '0 0 %d %d' %
                            (Screen.mm_to_px(sx), Screen.mm_to_px(sy)))))
        else:
            items = list(self.paper.find_all())
            items.remove(self.paper.background)
            x1, y1, x2, y2 = self.paper.list_bbox(items)
            w = px_to_mm_txt(x2 - x1 + 2 * border_size)
            h = px_to_mm_txt(y2 - y1 + 2 * border_size)
            bx2, by2 = x2 - x1 + 2 * border_size, y2 - y1 + 2 * border_size
            dom_extensions.setAttributes(
                self.top, (("width", w), ("height", h),
                           ("viewBox", '0 0 %d %d' % (bx2, by2))))
        self.group = dom_extensions.elementUnder(self.top, 'g',
                                                 (('font-size', '12pt'),
                                                  ('font-family', 'Helvetica'),
                                                  ('stroke-linecap', 'round')))
        if not self.full_size:
            self.group.setAttribute(
                'transform',
                'translate(%d,%d)' % (-x1 + border_size, -y1 + border_size))

        # sort the top_levels according to paper.stack
        cs = []
        for c in self.paper.stack:
            if c in top_levels:
                cs.append(c)
        for o in cs:
            if o.object_type == 'molecule':
                for b in o.bonds:
                    self.add_bond(b)
                for a in o.atoms:
                    self.add_atom(a)
            elif o.object_type == 'arrow':
                self.add_arrow(o)
            elif o.object_type == 'text':
                self.add_text(o)
            elif o.object_type == 'plus':
                self.add_plus(o)
            elif o.object_type in data.vector_graphics_types:
                if o.object_type == 'rect':
                    self.add_rect(o)
                elif o.object_type == 'oval':
                    self.add_oval(o)
                elif o.object_type == 'polygon':
                    self.add_polygon(o)
                elif o.object_type == 'polyline':
                    self.add_polyline(o)
コード例 #8
0
ファイル: xml_writer.py プロジェクト: bartlebee/bkchem
  def construct_dom_tree( self, top_levels):
    """constructs the SVG dom from all top_levels"""
    # the constants
    border_size = self.paper.get_paper_property( 'crop_margin')

    # converter
    px_to_cm_txt = lambda x: Screen.px_to_text_with_unit( x, unit="cm", round_to=5)
    px_to_mm_txt = lambda x: Screen.px_to_text_with_unit( x, unit="mm", round_to=5)

    # the code
    self._id = 0
    doc = self.document
    self.top = dom_extensions.elementUnder( doc, "svg", attributes=(("xmlns", "http://www.w3.org/2000/svg"),
                                                                    ("version", "1.0")))
    if self.full_size:
      sx = self.paper.get_paper_property( 'size_x')
      sy = self.paper.get_paper_property( 'size_y')
      dom_extensions.setAttributes( self.top, (("width", '%fmm' % sx),
                                               ("height", '%fmm' % sy),
                                               ('viewBox', '0 0 %d %d' % (Screen.mm_to_px(sx), Screen.mm_to_px(sy)))))
    else:
      items = list( self.paper.find_all())
      items.remove( self.paper.background)
      x1, y1, x2, y2 = self.paper.list_bbox( items)
      w = px_to_mm_txt( x2 -x1 +2*border_size)
      h = px_to_mm_txt( y2 -y1 +2*border_size)
      bx2, by2 = x2-x1+2*border_size, y2-y1+2*border_size
      dom_extensions.setAttributes( self.top, (("width", w),
                                               ("height", h),
                                               ("viewBox",'0 0 %d %d' % ( bx2, by2))))
    self.group = dom_extensions.elementUnder( self.top, 'g',
                                              (('font-size', '12pt'),
                                               ('font-family', 'Helvetica'),
                                               ('stroke-linecap', 'round')))
    if not self.full_size:
      self.group.setAttribute( 'transform', 'translate(%d,%d)' % (-x1+border_size, -y1+border_size))
      
    # sort the top_levels according to paper.stack
    cs = []
    for c in self.paper.stack:
      if c in top_levels:
        cs.append( c)
    for o in cs:
      if o.object_type == 'molecule':
        for b in o.bonds:
          self.add_bond( b)
        for a in o.atoms:
          self.add_atom( a)
      elif o.object_type == 'arrow':
        self.add_arrow( o)
      elif o.object_type == 'text':
        self.add_text( o)
      elif o.object_type == 'plus':
        self.add_plus( o)
      elif o.object_type in data.vector_graphics_types:
        if o.object_type == 'rect':
          self.add_rect( o)
        elif o.object_type == 'oval':
          self.add_oval( o)
        elif o.object_type == 'polygon':
          self.add_polygon( o)
        elif o.object_type == 'polyline':
          self.add_polyline( o)