コード例 #1
0
  def on_begin( self, scaling=None):
    self.paper.unselect_all()
    if self.paper.get_paper_property( 'crop_svg'):

      if len( self.paper.find_all()) <= 1: # background only
        Store.log( _('There is nothing to export. If you want to export an empty paper disable cropping of the drawing in the File/Properties menu.'), message_type="error")
        return 0

      x1, y1, x2, y2 = self.paper.get_cropping_bbox()
      dx = x2-x1
      dy = y2-y1
      scalex, scaley = scaling or self.get_scaling( dx, dy)
      if not scalex:
        # the setting of scaling was canceled
        return 0

      self.transformer = transform.transform()
      self.transformer.set_move( -x1, -y1)
      self.transformer.set_scaling_xy( scalex, scaley)
    else:
      dx = Screen.mm_to_px( self.paper._paper_properties['size_x'])
      dy = Screen.mm_to_px( self.paper._paper_properties['size_y'])
      scalex, scaley = scaling or self.get_scaling( dx, dy)
      if not scalex:
        # the setting of scaling was canceled
        return 0

      self.transformer = transform.transform()
      self.transformer.set_scaling_xy( scalex, scaley)

    x1, y1, x2, y2 = self.transformer.transform_4( (0, 0, dx, dy))
    self.pagesize = tuple( map( round, (x2-x1, y2-y1)))
    self.attrs['text_to_curves'] = False
    self.converter = self.converter_class( **self.attrs)
    return 1
コード例 #2
0
ファイル: cairo_lowlevel.py プロジェクト: sctincman/bkchem
  def on_begin( self, scaling=None):
    self.paper.unselect_all()
    if self.paper.get_paper_property( 'crop_svg'):

      if len( self.paper.find_all()) <= 1: # background only
        Store.log( _('There is nothing to export. If you want to export an empty paper disable cropping of the drawing in the File/Properties menu.'), message_type="error")
        return 0

      x1, y1, x2, y2 = self.paper.get_cropping_bbox()
      dx = x2-x1
      dy = y2-y1
      scalex, scaley = scaling or self.get_scaling( dx, dy)
      if not scalex:
        # the setting of scaling was canceled
        return 0

      self.transformer = transform.transform()
      self.transformer.set_move( -x1, -y1)
      self.transformer.set_scaling_xy( scalex, scaley)
    else:
      dx = Screen.mm_to_px( self.paper._paper_properties['size_x'])
      dy = Screen.mm_to_px( self.paper._paper_properties['size_y'])
      scalex, scaley = scaling or self.get_scaling( dx, dy)
      if not scalex:
        # the setting of scaling was canceled
        return 0

      self.transformer = transform.transform()
      self.transformer.set_scaling_xy( scalex, scaley)

    x1, y1, x2, y2 = self.transformer.transform_4( (0, 0, dx, dy))
    self.pagesize = tuple( map( round, (x2-x1, y2-y1)))
    self.attrs['text_to_curves'] = False
    self.converter = self.converter_class( **self.attrs)
    return 1
コード例 #3
0
ファイル: piddle_lowlevel.py プロジェクト: insilichem/bkchem
    def on_begin(self):
        self.paper.unselect_all()
        scale = 720.0 / self.paper.winfo_fpixels('254m')
        if self.paper.get_paper_property('crop_svg'):
            margin = self.paper.get_paper_property('crop_margin')
            items = list(self.paper.find_all())
            items.remove(self.paper.background)

            if not items:
                Store.log(_(
                    'There is nothing to export. If you want to export an empty paper disable cropping of the drawing in the File/Properties menu.'
                ),
                          message_type="error")
                return 0

            x1, y1, x2, y2 = self.paper.list_bbox(items)
            self.transformer = transform.transform()
            self.transformer.set_move(-x1 + margin, -y1 + margin)
            self.transformer.set_scaling(scale)
            dx = x2 - x1 + 2 * margin
            dy = y2 - y1 + 2 * margin
        else:
            self.transformer = transform.transform()
            self.transformer.set_scaling(scale)
            dx = Screen.mm_to_px(self.paper._paper_properties['size_x'])
            dy = Screen.mm_to_px(self.paper._paper_properties['size_y'])

        self.canvas = self.init_canvas(pagesize=(scale * dx, scale * dy))
        self.converter = self.converter_class()
        return 1
コード例 #4
0
ファイル: piddle_lowlevel.py プロジェクト: sctincman/bkchem
  def on_begin( self):
    self.paper.unselect_all()
    scale = 720.0/self.paper.winfo_fpixels( '254m')
    if self.paper.get_paper_property( 'crop_svg'):
      margin = self.paper.get_paper_property('crop_margin')
      items = list( self.paper.find_all())
      items.remove( self.paper.background)

      if not items:
        Store.log( _('There is nothing to export. If you want to export an empty paper disable cropping of the drawing in the File/Properties menu.'), message_type="error")
        return 0

      x1, y1, x2, y2 = self.paper.list_bbox( items)
      self.transformer = transform.transform()
      self.transformer.set_move( -x1+margin, -y1+margin)
      self.transformer.set_scaling( scale)
      dx = x2-x1 +2*margin
      dy = y2-y1 +2*margin
    else:
      self.transformer = transform.transform()
      self.transformer.set_scaling( scale)
      dx = Screen.mm_to_px( self.paper._paper_properties['size_x'])
      dy = Screen.mm_to_px( self.paper._paper_properties['size_y'])

    self.canvas = self.init_canvas( pagesize=(scale*dx, scale*dy))
    self.converter = self.converter_class()
    return 1
コード例 #5
0
ファイル: gtml.py プロジェクト: insilichem/bkchem
  def _scale_and_move_molecule( self, m, anchor_x, anchor_y):
    bbox, bl = m.get_geometry()
    maxx, maxy, minx, miny = m.bbox()

    if bl:
      scale = self.paper.any_to_px( self.paper.standard.bond_length) / bl
    else:
      scale = 1

    # at first we scale to the standard bond length
    tr = transform()
    tr.set_move( -minx, -miny)
    tr.set_scaling( scale)
    m.transform( tr)

    # then we recalculate the bbox and position the molecule
    #    we need to decide pos first, it is vital for bbox calculation and normaly done on draw
    [a.decide_pos() for a in m.atoms]
    maxx, maxy, minx, miny = m.bbox()
    m.move( anchor_x-minx, anchor_y - (maxy-miny)/2 - miny)

    #import graphics
    #self.molecules.append( graphics.rect( self.paper, coords = m.bbox()))
    #self.molecules.append( graphics.rect( self.paper, coords = (anchor_x + (maxx), 100, anchor_x + (maxx) + 2, 300)))

    return anchor_x + maxx - minx
コード例 #6
0
 def _get_my_curve( self, num_points=20):
   points = points_of_curve_eight_y( self.atom.x, self.atom.y, 0.35*self.size, 0.5*self.size, 1, num_points=num_points)
   angle = math.atan2( self.atom.x - self.x, self.atom.y - self.y)
   tr = transform.transform()
   tr.set_move( -self.atom.x, -self.atom.y)
   tr.set_rotation( -angle)
   tr.set_move( self.atom.x, self.atom.y)
   points = tr.transform_xy_flat_list( points)
   return points
コード例 #7
0
ファイル: molfile.py プロジェクト: sctincman/bkchem
def invert_coords( molecule, tr=None):
  if not tr:
    ys = [a.y for a in molecule.vertices]
    center_y = (max( ys) + min( ys)) / 2.0
    tr = transform.transform()
    tr.set_move( 0, -center_y)
    tr.set_scaling_xy( 1, -1)
    tr.set_move( 0, center_y)

  molecule.transform( tr)
  return tr
コード例 #8
0
def invert_coords(molecule, tr=None):
    if not tr:
        ys = [a.y for a in molecule.vertices]
        center_y = (max(ys) + min(ys)) / 2.0
        tr = transform.transform()
        tr.set_move(0, -center_y)
        tr.set_scaling_xy(1, -1)
        tr.set_move(0, center_y)

    molecule.transform(tr)
    return tr
コード例 #9
0
ファイル: temp_manager.py プロジェクト: sctincman/bkchem
 def get_transformed_template( self, n, coords, type='empty', paper=None):
   """type is type of connection - 'bond', 'atom1'(for single atom), 'atom2'(for atom with more than 1 bond), 'empty'"""
   pap = paper or Store.app.paper
   pap.onread_id_sandbox_activate() # must be here to mangle the ids
   current = molecule( pap, package=self.templates[n])
   pap.onread_id_sandbox_finish( apply_to= [current]) # id mangling
   current.name = ''
   self._scale_ratio = 1
   trans = transform()
   # type empty - just draws the template - no conection
   if type == 'empty':
     xt1, yt1 = current.t_atom.get_xy()
     xt2, yt2 = current.next_to_t_atom.get_xy()
     x1, y1 = coords
     bond_length = Screen.any_to_px( Store.app.paper.standard.bond_length)
     current.delete_items( [current.t_atom], redraw=0, delete_single_atom=0)
     trans.set_move( -xt2, -yt2)
     trans.set_scaling( bond_length / math.sqrt( (xt1-xt2)**2 + (yt1-yt2)**2))
     trans.set_move( x1, y1)
   #type atom
   elif type == 'atom1' or type == 'atom2':
     xt1, yt1 = current.t_atom.get_xy()
     xt2, yt2 = current.next_to_t_atom.get_xy()
     x1, y1, x2, y2 = coords
     trans.set_move( -xt2, -yt2)
     trans.set_scaling( math.sqrt( (x1-x2)**2 + (y1-y2)**2) / math.sqrt( (xt1-xt2)**2 + (yt1-yt2)**2))
     trans.set_rotation( math.atan2( xt1-xt2, yt1-yt2) - math.atan2( x1-x2, y1-y2))
     trans.set_move( x2, y2)
   #type bond
   elif type == 'bond':
     if not (current.t_bond_first and current.t_bond_second):
       warn( "this template is not capable to be added to bond - sorry.")
       return None
     current.delete_items( [current.t_atom], redraw=0, delete_single_atom=0)
     xt1, yt1 = current.t_bond_first.get_xy()
     xt2, yt2 = current.t_bond_second.get_xy()
     x1, y1, x2, y2 = coords
     self._scale_ratio = math.sqrt( (x1-x2)**2 + (y1-y2)**2) / math.sqrt( (xt1-xt2)**2 + (yt1-yt2)**2) # further needed for bond.bond_width transformation
     trans.set_move( -xt1, -yt1)
     trans.set_rotation( math.atan2( xt1-xt2, yt1-yt2) - math.atan2( x1-x2, y1-y2))
     trans.set_scaling( self._scale_ratio)
     trans.set_move( x1, y1)
   self.transform_template( current, trans)
   #remove obsolete info from template
   if type == 'atom1':
     current.delete_items( [current.t_atom], redraw=0, delete_single_atom=0)
   elif type == 'atom2':
     current.t_atom.x = x1
     current.t_atom.y = y1
   current.t_atom = None
   current.t_bond_first = None
   current.t_bond_second = None
   #return ready template
   return current
コード例 #10
0
ファイル: tk2piddle.py プロジェクト: bartlebee/bkchem
 def _create_arrow( self, shape, start, to, color):
   """creates an arrow with 'shape' pointing from 'start' to 'to' filled with 'color'
   and returns x, y - where the to should be to not to overlay the arrow"""
   a, b, c = map( float, shape.split())
   points = [a,0, a-b,c, 0,0, a-b,-c]
   ang = geometry.clockwise_angle_from_east( to[0]-start[0], to[1]-start[1])
   tr = transform.transform()
   tr.set_move( -a, 0)
   tr.set_rotation( ang)
   tr.set_move( to[0], to[1])
   points = tr.transform_xy_flat_list( points)
   points = self.transformer.transform_xy_flat_list( points)
   points = self._flat_list_to_list_of_tuples( points)
   self.canvas.drawPolygon( points, edgeColor=color, edgeWidth=0, fillColor=color, closed=1)    
   return points[2]
コード例 #11
0
 def _create_arrow(self, shape, start, to, color):
     """creates an arrow with 'shape' pointing from 'start' to 'to' filled with 'color'
 and returns x, y - where the to should be to not to overlay the arrow"""
     a, b, c = map(float, shape.split())
     points = [a, 0, a - b, c, 0, 0, a - b, -c]
     ang = geometry.clockwise_angle_from_east(to[0] - start[0],
                                              to[1] - start[1])
     tr = transform.transform()
     tr.set_move(-a, 0)
     tr.set_rotation(ang)
     tr.set_move(to[0], to[1])
     points = tr.transform_xy_flat_list(points)
     points = self.transformer.transform_xy_flat_list(points)
     points = self._flat_list_to_list_of_tuples(points)
     self.canvas.drawPolygon(points,
                             edgeColor=color,
                             edgeWidth=0,
                             fillColor=color,
                             closed=1)
     return points[2]
コード例 #12
0
ファイル: tk2cairo.py プロジェクト: bartlebee/bkchem
  def _create_arrow( self, shape, start, to, color):
    """creates an arrow with 'shape' pointing from 'start' to 'to' filled with 'color'
    and returns x, y - where the to should be to not to overlay the arrow"""
    a, b, c = map( float, shape.split())
    points = [a,0, a-b,c, 0,0, a-b,-c]
    ang = geometry.clockwise_angle_from_east( to[0]-start[0], to[1]-start[1])
    tr = transform.transform()
    tr.set_move( -a, 0)
    tr.set_rotation( ang)
    tr.set_move( to[0], to[1])
    points = tr.transform_xy_flat_list( points)
    points = self.transformer.transform_xy_flat_list( points)
    points = self._flat_list_to_list_of_tuples( points)

    self.context.set_line_join( cairo.LINE_JOIN_MITER)
    self._create_cairo_path( points, closed=True)
    is_visible = self.set_cairo_color( color)
    if is_visible:
      self.context.fill()

    return points[1]
コード例 #13
0
ファイル: tk2cairo.py プロジェクト: yassineMrabet/bkchem
    def _create_arrow(self, shape, start, to, color):
        """creates an arrow with 'shape' pointing from 'start' to 'to' filled with 'color'
    and returns x, y - where the to should be to not to overlay the arrow"""
        a, b, c = map(float, shape.split())
        points = [a, 0, a - b, c, 0, 0, a - b, -c]
        ang = geometry.clockwise_angle_from_east(to[0] - start[0],
                                                 to[1] - start[1])
        tr = transform.transform()
        tr.set_move(-a, 0)
        tr.set_rotation(ang)
        tr.set_move(to[0], to[1])
        points = tr.transform_xy_flat_list(points)
        points = self.transformer.transform_xy_flat_list(points)
        points = self._flat_list_to_list_of_tuples(points)

        self.context.set_line_join(cairo.LINE_JOIN_MITER)
        self._create_cairo_path(points, closed=True)
        is_visible = self.set_cairo_color(color)
        if is_visible:
            self.context.fill()

        return points[1]
コード例 #14
0
 def prepare_dumb_transformer(self):
     tr = transform.transform()
     tr.set_scaling(self.paper_to_canvas_coord(1))
     return tr
コード例 #15
0
ファイル: tk2cairo.py プロジェクト: bartlebee/bkchem
 def prepare_dumb_transformer( self):
   tr = transform.transform()
   tr.set_scaling( 1)
   return tr
コード例 #16
0
ファイル: tk2cairo.py プロジェクト: yassineMrabet/bkchem
 def prepare_dumb_transformer(self):
     tr = transform.transform()
     tr.set_scaling(1)
     return tr
コード例 #17
0
ファイル: tk2piddle.py プロジェクト: bartlebee/bkchem
 def prepare_dumb_transformer( self):
   tr = transform.transform()
   tr.set_scaling( self.paper_to_canvas_coord( 1))
   return tr