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 test_simple_block(self): block = Block(name='empty') block.add(Line()) expected = " 0\nBLOCK\n 8\n0\n 2\nempty\n 3\nempty\n 70\n0\n 10\n0.0\n 20\n0.0\n 30\n0.0\n" \ " 0\nLINE\n 8\n0\n 10\n0.0\n 20\n0.0\n 30\n0.0\n 11\n0.0\n 21\n0.0\n 31\n0.0\n" \ " 0\nENDBLK\n" self.assertEqual(dxfstr(block), expected)
def _draw_extension_lines(self): """ build the extension lines entities """ for vector in [self.start_vector, self.end_vector]: self.data.append( Line(start=self._get_extline_start(vector), end=self._get_extline_end(vector), layer=self.prop('layer'), color=self.prop('dimextlinecolor')))
def line(start=(0., 0.), end=(0., 0.), **kwargs): """ Create a new line-entity of two (3D) points, z-axis is 0 by default. :param start: start point (xy- or xyz-tuple) :param end: end point (xy- or xyz-tuple) """ return Line(start=start, end=end, **kwargs)
def _draw_dimension_line(self): start_point = vadd( self.center, vmul_scalar(self.target_vector, self.radius - self.length)) self.data.append( Line(start=start_point, end=self.target, layer=self.prop('layer'), color=self.prop('dimlinecolor')))
def test_block_attribs(self): block = Block(name='empty') block.add(Line()) block['xref'] = 'test\\test.dxf' expected = " 0\nBLOCK\n 8\n0\n 2\nempty\n 3\nempty\n 70\n0\n" \ " 10\n0.0\n 20\n0.0\n 30\n0.0\n 1\ntest\\test.dxf\n" \ " 0\nLINE\n 8\n0\n 10\n0.0\n 20\n0.0\n 30\n0.0\n 11\n0.0\n 21\n0.0\n 31\n0.0\n" \ " 0\nENDBLK\n" self.assertEqual(dxfstr(block), expected)
def append_line(start, end, style): """ Appends the DXF-LINE entity to the table dxf data. """ if style['status']: table.data.append( Line(start=start, end=end, layer=layer, color=style['color'], linetype=style['linetype']))
def test_common_attribs(self): line = Line(start=(0, 0, 0), end=(1, 1, 1)) line['linetype'] = 'DASHED' line['elevation'] = 1.0 line['thickness'] = 0.70 line['color'] = 7 line['layer'] = 'dxfwrite' line['paper_space'] = 1 line['extrusion_direction'] = (0, 0, 1) expected = " 0\nLINE\n 6\nDASHED\n 38\n1.0\n 39\n0.7\n 62\n7\n 8\n" \ "dxfwrite\n 67\n1\n210\n0.0\n220\n0.0\n230\n1.0\n" \ " 10\n0.0\n 20\n0.0\n 30\n0.0\n 11\n1.0\n 21\n1.0\n 31\n1.0\n" self.assertEqual(dxfstr(line), expected)
def _draw_extension_lines(self): """ build the extension lines entities """ dimextlinegap = self.prop('dimextlinegap') for dimline_point, target_point in \ zip(self.dimline_points, self.measure_points): if distance(dimline_point, target_point) > \ max(dimextlinegap, DIMENSIONS_MIN_DISTANCE): direction_vector = unit_vector( vsub(target_point, dimline_point)) target_point = vsub( target_point, vmul_scalar(direction_vector, dimextlinegap)) self.data.append( Line(start=dimline_point, end=target_point, color=self.prop('dimextlinecolor'), layer=self.prop('layer')))
def _draw_dimline(self): """ build dimension line entity """ start_point, end_point = self._get_dimline_bounds() dimlineext = self.prop('dimlineext') if dimlineext > 0: start_point = vsub(start_point, vmul_scalar(self.parallel_vector, dimlineext)) end_point = vadd(end_point, vmul_scalar(self.parallel_vector, dimlineext)) self.data.append( Line(start=start_point, end=end_point, color=self.prop('dimlinecolor'), layer=self.prop('layer')))
def test_line_no_attribs(self): line = Line(start=(0, 0), end=(1, 1)) # 2d points will be converted to 3d expected = " 0\nLINE\n 8\n0\n 10\n0.0\n 20\n0.0\n 30\n0.0\n 11\n1.0\n 21\n1.0\n 31\n0.0\n" self.assertEqual(dxfstr(line), expected)
def test_line_2d_points(self): line = Line(start=(0, 0), end=(1, 1)) expected = " 0\nLINE\n 8\n0\n 10\n0.0\n 20\n0.0\n 30\n0.0\n 11\n1.0\n 21\n1.0\n 31\n0.0\n" self.assertEqual(dxfstr(line), expected)