def get_dxf_entity(self, coords, layer): """Create the cell content as INSERT-entity with trailing ATTRIB-entities. coords -- tuple of border-coordinates : left, right, top, bottom layer -- layer, which should be used for dxf entities """ left, right, top, bottom = self.substract_margin(coords) style = self.style halign = style['halign'] valign = style['valign'] xpos = (left, float(left+right)/2., right)[halign] ypos = (bottom, float(bottom+top)/2., top)[valign-1] insert = Insert(blockname=self.blockdef['name'], insert=(xpos, ypos), xscale=style['xscale'], yscale=style['yscale'], rotation=style['rotation'], layer=layer) # process attribs for key, value in self.attribs.items(): try: attdef = self.blockdef.find_attdef(key) attrib = attdef.new_attrib(text=str(value)) insert.add(attrib, relative=True) except KeyError: pass # ignore none existing attdefs return insert
def get_dxf_entity(self, border_coords, layer): """ Create the cell content as INSERT-entity with trailing ATTRIB-Entities. :param border_coords: tuple of border-coordinates : left, right, top, bottom :param str layer: layer, which should be used for dxf entities """ left, right, top, bottom = self.get_workspace_coords(border_coords) style = self.style halign = style['halign'] valign = style['valign'] xpos = (left, float(left + right) / 2., right)[halign] ypos = (bottom, float(bottom + top) / 2., top)[valign - 1] insert = Insert(blockname=self.blockdef['name'], insert=(xpos, ypos), xscale=style['xscale'], yscale=style['yscale'], rotation=style['rotation'], layer=layer) # process attribs for key, value in self.attribs.items(): try: attdef = self.blockdef.find_attdef(key) attrib = attdef.new_attrib(text=str(value)) insert.add(attrib, relative=True) except KeyError: pass # ignore none existing ATTDEFs return insert
def test_add_attrib_absolute(self): block_ref = Insert(blockname='TestAttrib', insert=(5, 5), rotation=30) attrib = Attrib( insert=(1, 1), rotation=15, tag='TEST', text='attrib', ) block_ref.add(attrib, relative=False) inserted_attrib = block_ref.data[0] self.assertEqual(inserted_attrib['rotation'], 15.) self.assertEqual(inserted_attrib['insert']['xy'], [1., 1.])
def test_add_attrib_absolute(self): block_ref = Insert(blockname='TestAttrib', insert=(5, 5), rotation=30) attrib = Attrib( insert=(1, 1), rotation=15, tag='TEST', text='attrib', ) block_ref.add(attrib, relative=False) inserted_attrib = block_ref.data[0] self.assertEqual(inserted_attrib['rotation'], 15.) self.assertEqual(inserted_attrib['insert']['xy'], [1., 1.])
def test_add_attrib_relative(self): # insert blockref with 45 degree rotation block_ref = Insert(blockname='TestAttrib', insert=(0, 0), rotation=45) attrib = Attrib( insert=(1, 1), rotation=45, # 45 degree relative to original block definition tag='TEST', text='attrib', ) block_ref.add(attrib, relative=True) # result rotation = 45 + 45 = 90 inserted_attrib = block_ref.data[0] self.assertEqual(inserted_attrib['rotation'], 90.) self.assertAlmostEqual(inserted_attrib['insert']['x'], 0, places=3) self.assertAlmostEqual(inserted_attrib['insert']['y'], 1.4142, places=3) # y = sqrt(2)
def test_add_attrib_relative(self): # insert blockref with 45 degree rotation block_ref = Insert(blockname='TestAttrib', insert=(0, 0), rotation=45) attrib = Attrib( insert=(1, 1), rotation=45, # 45 degree relative to original block definition tag='TEST', text='attrib', ) block_ref.add(attrib, relative=True) # result rotation = 45 + 45 = 90 inserted_attrib = block_ref.data[0] self.assertEqual(inserted_attrib['rotation'], 90.) self.assertAlmostEqual(inserted_attrib['insert']['x'], 0, places=3) self.assertAlmostEqual(inserted_attrib['insert']['y'], 1.4142, places=3) # y = sqrt(2)