def test_solid_no_attributes(self): solid = Solid() # need at least 3 points self.assertRaises(DXFValidationError, dxfstr, solid) solid = Solid([(0, 0)]) # need at least 3 points self.assertRaises(DXFValidationError, dxfstr, solid) solid = Solid([(0, 0), (1, 0)]) # need at least 3 points self.assertRaises(DXFValidationError, dxfstr, solid)
def setup(drawing): """ Insert necessary definitions into drawing: - ticks: DIMTICK_ARCH, DIMTICK_DOT, DIMTICK_ARROW - layers: DIMENSIONS """ # default pen assignment: # 1 : 1.40mm - red # 2 : 0.35mm - yellow # 3 : 0.70mm - green # 4 : 0.50mm - cyan # 5 : 0.13mm - blue # 6 : 1.00mm - magenta # 7 : 0.25mm - white/black # 8, 9 : 2.00mm # >=10 : 1.40mm def block(name, elements): """ Create the block entity """ tick = Block(name=name, basepoint=(0., 0.)) for element in elements: tick.add(element) return tick dimcolor = dimstyles.default.dimextlinecolor byblock = const.BYBLOCK elements = [ Line(start=(0., +.5), end=(0., -.5), color=dimcolor, layer=byblock), Line(start=(-.2, -.2), end=(.2, +.2), color=4, layer=byblock) ] drawing.blocks.add(block('DIMTICK_ARCH', elements)) elements = [ Line(start=(0., .5), end=(0., -.5), color=dimcolor, layer=byblock), Circle(radius=.1, color=4, layer=byblock) ] drawing.blocks.add(block('DIMTICK_DOT', elements)) elements = [ Line(start=(0., .5), end=(0., -.50), color=dimcolor, layer=byblock), Solid([(0, 0), (.3, .05), (.3, -.05)], color=7, layer=byblock) ] drawing.blocks.add(block('DIMTICK_ARROW', elements)) elements = [ # special tick for RadialDimension Solid([(0, 0), (.3, .05), (0.25, 0.), (.3, -.05)], color=7, layer=byblock) ] drawing.blocks.add(block('DIMTICK_RADIUS', elements))
def draw_cell_background(self, row, col, cell): """ Draw the cell background for <row>, <col> as DXF-SOLID entity. """ style = cell.style if style['bgcolor'] is None: return # get cell coords in absolute drawing units left, right, top, bottom = self.cell_coords(row, col, cell.span) ltop = (left, top) lbot = (left, bottom) rtop = (right, top) rbot = (right, bottom) self.table.data.append( Solid(points=[ltop, lbot, rbot, rtop], color=style['bgcolor'], layer=self.table.bglayer))
def _build_solid(self): """ build a single unified background solid (only works for 4 points)""" return Solid(self.transformed_points, color=self.bgcolor, layer=self.layer)
def _build_solid_triangle(self, i): ''' build a single background solid quadrangle segment ''' solidpts = [self.points[j] for j in [0, i + 1, i + 2]] return Solid(solidpts, color=self.bgcolor, layer=self.layer)
def _build_solid_quad(self, i, center=None): ''' build a single background solid quadrangle segment ''' solidpts = [self.points[j] for j in [i, i + 1, -i - 2, -i - 1]] return Solid(solidpts, color=self.bgcolor, layer=self.layer)
def test_solid_change_point(self): solid = Solid([(0, 0), (1, 0), (1, 1), (0, 1)]) solid[3] = (0, 2) # tuple! not DXFPoint expected = " 0\nSOLID\n 8\n0\n 10\n0.0\n 20\n0.0\n 30\n0.0\n 11\n1.0\n 21\n0.0\n 31\n0.0\n" \ " 13\n1.0\n 23\n1.0\n 33\n0.0\n 12\n0.0\n 22\n2.0\n 32\n0.0\n" self.assertEqual(dxfstr(solid), expected)
def test_solid_4points(self): solid = Solid([(0, 0), (1, 0), (1, 1), (0, 1)]) expected = " 0\nSOLID\n 8\n0\n 10\n0.0\n 20\n0.0\n 30\n0.0\n 11\n1.0\n 21\n0.0\n 31\n0.0\n" \ " 13\n1.0\n 23\n1.0\n 33\n0.0\n 12\n0.0\n 22\n1.0\n 32\n0.0\n" self.assertEqual(dxfstr(solid), expected)
def solid(points=[], **kwargs): """ Create a solid-entity by 3 or 4 vertices, the z-axis for 2D-points is 0. :param list points: three or four 2D- or 3D-points (tuples) """ return Solid(points, **kwargs)
def _build_solid(self): """ build the background solid """ return Solid(self.points, color=self.bgcolor, layer=self.layer)