def import_dxf_layer_geometry(dxf, layername): entities = dxf.entities generics = [] for entity in entities: if entity.dxf.layer in layername: if isinstance(entity, ezdxf.modern.graphics.Line): import numpy points = numpy.array( [entity.dxf.start[:2], entity.dxf.end[:2]]) generics.append( GenericLine.gen_from_point_lists(points.tolist(), [])) elif isinstance(entity, ezdxf.modern.graphics.LWPolyline): import numpy points = numpy.array([item for item in entity.get_points()]) points = points[:, :2] if entity.closed: generics.append( GenericPoly.gen_from_point_lists(points.tolist(), [])) else: generics.append( GenericPolyline.gen_from_point_lists( points.tolist(), [])) elif isinstance(entity, ezdxf.modern.graphics.Point): from popupcad.geometry.vertex import DrawnPoint point = DrawnPoint( numpy.array(entity.get_dxf_attrib('location')[:2])) generics.append(point) elif isinstance(entity, ezdxf.modern.graphics.Spline): knots = entity.get_knot_values() control_points = entity.get_control_points() weights = entity.get_weights() n = len(control_points) - 1 domain = popupcad.algorithms.spline_functions.make_domain( knots, n * 5) points = popupcad.algorithms.spline_functions.interpolated_points( control_points, knots, weights, domain) points = points[:, :2] if entity.closed: generics.append( GenericPoly.gen_from_point_lists(points.tolist(), [])) else: generics.append( GenericPolyline.gen_from_point_lists( points.tolist(), [])) # print(points) else: print(entity) new = popupcad.filetypes.sketch.Sketch.new() new.addoperationgeometries(generics) newsketchname = layername + '.sketch' new.updatefilename(newsketchname) return new
def import_dxf_layer_geometry(dxf, layername): entities = dxf.entities generics = [] for entity in entities: if entity.dxf.layer in layername: if isinstance(entity, ezdxf.modern.graphics.Line): import numpy points = numpy.array( [entity.dxf.start[:2], entity.dxf.end[:2]]) generics.append( GenericLine.gen_from_point_lists( points.tolist(), [])) elif isinstance(entity, ezdxf.modern.graphics.LWPolyline): import numpy points = numpy.array([item for item in entity.get_points()]) points = points[:, :2] if entity.closed: generics.append(GenericPoly.gen_from_point_lists(points.tolist(), [])) else: generics.append(GenericPolyline.gen_from_point_lists(points.tolist(), [])) elif isinstance(entity, ezdxf.modern.graphics.Point): from popupcad.geometry.vertex import DrawnPoint point = DrawnPoint(numpy.array(entity.get_dxf_attrib('location')[:2])) generics.append(point) elif isinstance(entity, ezdxf.modern.graphics.Spline): knots = entity.get_knot_values() control_points = entity.get_control_points() weights = entity.get_weights() n = len(control_points) - 1 domain = popupcad.algorithms.spline_functions.make_domain(knots, n * 5) points = popupcad.algorithms.spline_functions.interpolated_points(control_points, knots, weights, domain) points = points[:, :2] if entity.closed: generics.append(GenericPoly.gen_from_point_lists(points.tolist(), [])) else: generics.append(GenericPolyline.gen_from_point_lists(points.tolist(), [])) # print(points) else: print(entity) new = popupcad.filetypes.sketch.Sketch.new() new.addoperationgeometries(generics) newsketchname = layername + '.sketch' new.updatefilename(newsketchname) return new
def load_dxf(cls, filename, parent=None): import ezdxf ezdxf.options.template_dir = popupcad.supportfiledir import ezdxf.modern dxf = ezdxf.readfile(filename) layer_names = [layer.dxf.name for layer in dxf.layers] dialog = qg.QDialog() lw = qg.QListWidget() for item in layer_names: lw.addItem(qg.QListWidgetItem(item)) lw.setSelectionMode(lw.ExtendedSelection) button_ok = qg.QPushButton('Ok') button_cancel = qg.QPushButton('Cancel') button_ok.clicked.connect(dialog.accept) button_cancel.clicked.connect(dialog.reject) layout = qg.QVBoxLayout() layout_buttons = qg.QHBoxLayout() layout_buttons.addWidget(button_ok) layout_buttons.addWidget(button_cancel) layout.addWidget(lw) layout.addLayout(layout_buttons) dialog.setLayout(layout) result = dialog.exec_() if result: selected_layers = [ item.data(qc.Qt.DisplayRole) for item in lw.selectedItems() ] entities = [item for item in dxf.modelspace()] generics = [] for entity in entities: if entity.dxf.layer in selected_layers: if isinstance(entity, ezdxf.modern.graphics.Line): import numpy points = numpy.array( [entity.dxf.start[:2], entity.dxf.end[:2]]) generics.append( GenericLine.gen_from_point_lists( points.tolist(), [])) elif isinstance(entity, ezdxf.modern.graphics.LWPolyline): import numpy points = numpy.array( [item for item in entity.get_points()]) points = points[:, :2] if entity.closed: generics.append( GenericPoly.gen_from_point_lists( points.tolist(), [])) else: generics.append( GenericPolyline.gen_from_point_lists( points.tolist(), [])) elif isinstance(entity, ezdxf.modern.graphics.Point): from popupcad.geometry.vertex import DrawnPoint point = DrawnPoint( numpy.array(entity.get_dxf_attrib('location')[:2])) generics.append(point) elif isinstance(entity, ezdxf.modern.spline.Spline): knots = entity.get_knot_values() control_points = entity.get_control_points() weights = entity.get_weights() n = len(control_points) - 1 domain = popupcad.algorithms.spline_functions.make_domain( knots, n * 5) points = popupcad.algorithms.spline_functions.interpolated_points( control_points, knots, weights, domain) points = points[:, :2] if entity.closed: generics.append( GenericPoly.gen_from_point_lists( points.tolist(), [])) else: generics.append( GenericPolyline.gen_from_point_lists( points.tolist(), [])) # print(points) else: print(entity) new = cls.new() new.addoperationgeometries(generics) newfile = os.path.splitext(filename)[0] + '.sketch' new.updatefilename(newfile) return filename, new else: return None, None
def operate(self, design): design_copy = design # design_copy.reprocessoperations() part_to_insert = design_copy.operations[design_copy.operation_index(self.part_opref)] sheet_to_insert_into = design_copy.operations[design_copy.operation_index(self.sheet_opref)] release_to_insert_into = design_copy.operations[design_copy.operation_index(self.release_opref)] # build the op_links, then auto make the operation op = part_to_insert op_ref = op.id op_links = {'parent': [(op_ref, op.getoutputref())]} new_web = AutoWeb4(op_links,[self.support_offset,0],MultiValueOperation3.keepout_types.laser_keepout) new_web.setcustomname(op.name) # support = OperationOutput(new_web.output[1], "support", self) design_copy.addoperation(new_web) new_web.generate(design_copy) ######################## generate the same size construction line somewhere in the sheet file # get geom for line parts_bounding_box = new_web.output[1].generic_laminate().getBoundingBox() # parts_bounding_box = support.generic_laminate().getBoundingBox() # make the sketch construction_geom_hinge = Sketch.new() tmp_geom = [(parts_bounding_box[0],parts_bounding_box[1]), (parts_bounding_box[0],parts_bounding_box[3])] construction_line = GenericLine.gen_from_point_lists(tmp_geom,[],construction=False) construction_geom_hinge.addoperationgeometries([construction_line]) # add sketch to sketch list design_copy.sketches[construction_geom_hinge.id] = construction_geom_hinge ######################## generate the external transform geometry in the sheet # center the locate line top left as origin position_hinge = (-tmp_geom[0][0],-tmp_geom[0][1]) locate_lines = [(x + position_hinge[0], y + position_hinge[1]) for (x,y) in tmp_geom] # lets make 4x4 width = (parts_bounding_box[2] - parts_bounding_box[0])*self.sc + self.x_gap height = (parts_bounding_box[3] - parts_bounding_box[1])*self.sc + self.y_gap # check if will all fit in one window, if not fill first and check if remainder will fit in second window max_num_cols = divmod(self.sketch_bounding_box[2] - self.sketch_bounding_box[0], width)[0] max_num_rows = divmod(self.sketch_bounding_box[3] - self.sketch_bounding_box[1], height)[0] if max_num_cols == 0 or max_num_rows == 0: print('Cannot tile into this area') design.remove_operation(new_web) return Laminate() # check if can fit in one # if N <= max_num_rows*max_num_cols: rows = math.ceil(self.N / max_num_cols) cols = math.ceil(self.N / rows) # spread across the two windows upper_right_origin_bounding_box = (self.sketch_bounding_box[0], self.sketch_bounding_box[3]) n_count = 0 arrayed_reference_lines = [] for row in range(rows): for col in range(cols): if n_count >= self.N or n_count >= max_num_rows*max_num_cols*2: break newx = upper_right_origin_bounding_box[0] + locate_lines[0][0] + col*width newy = upper_right_origin_bounding_box[1] - locate_lines[1][1] - row*height arrayed_reference_lines.append([(newx, newy), (newx, newy + height)]) n_count = n_count + 1 construction_geom_sheet = Sketch.new() construction_line = [GenericLine.gen_from_point_lists(line,[],construction=False) for line in arrayed_reference_lines] construction_geom_sheet.addoperationgeometries(construction_line) # add sketch to sketch list design_copy.sketches[construction_geom_sheet.id] = construction_geom_sheet ######################## External transform the hinge onto the sheet construction line # # insert hinge into sheet as subdesign # sheet.subdesigns[hinge.id] = hinge # # make design links operation_links = {} operation_links['from'] = [(part_to_insert.id,0)] sketch_links = {} sketch_links['sketch_to'] = [construction_geom_sheet.id] sketch_links['sketch_from'] = [construction_geom_hinge.id] insert_part = TransformInternal(sketch_links, operation_links, 'scale', 'scale', 0, False, 1., 1.) insert_part.customname = 'Inserted part' design_copy.addoperation(insert_part) insert_part.generate(design_copy) insert_part_id = design_copy.operations[-1].id # save for later ######################## External transform the web.sheet to the construction line # # make design links operation_links = {} operation_links['from'] = [(new_web.id,1)] sketch_links = {} sketch_links['sketch_to'] = [construction_geom_sheet.id] sketch_links['sketch_from'] = [construction_geom_hinge.id] insert_webs = TransformInternal(sketch_links, operation_links, 'scale', 'scale', 0, False, 1., 1.) insert_webs.customname = 'Inserted part webs' design_copy.addoperation(insert_webs) insert_webs.generate(design_copy) ######################## Remove web.sheet from sheet, union external transform + generateed sheet with hole + web # first the difference # link 1 is the sheet sheet_with_hole = LaminateOperation2({'unary': [(sheet_to_insert_into.id,0)], 'binary': [(insert_webs.id,0)]},'difference') sheet_with_hole.customname = 'Sheet with hole' design_copy.addoperation(sheet_with_hole) sheet_with_hole.generate(design_copy) sheet_with_part = LaminateOperation2({'unary': [(sheet_with_hole.id,0), (insert_part_id,0)], 'binary':[]},'union') sheet_with_part.customname = 'First pass cuts' design_copy.addoperation(sheet_with_part) sheet_with_part.generate(design_copy) # ######################## Make release cut laminate operation operation_links = {} operation_links['from'] = [(release_to_insert_into.id,0)] sketch_links = {} sketch_links['sketch_to'] = [construction_geom_sheet.id] sketch_links['sketch_from'] = [construction_geom_hinge.id] insert_release = TransformInternal(sketch_links, operation_links, 'scale', 'scale', 0, False, 1., 1.) design.addoperation(insert_release) insert_release.generate(design) ######################################### prepare outputs # delete the intermediate layers design.remove_operation(sheet_with_hole) design.remove_operation(insert_webs) design.remove_operation(insert_part) design.remove_operation(new_web) design.remove_operation(sheet_with_part) design.remove_operation(insert_release) self.output = [OperationOutput(sheet_with_part.output[0].csg, 'FirstCuts', self), OperationOutput(sheet_with_part.output[0].csg, 'FirstCuts', self), OperationOutput(insert_release.output[0].csg, 'Release', self)] return sheet_with_part.output[0].csg
def load_dxf(cls, filename, parent=None): import ezdxf ezdxf.options.template_dir = popupcad.supportfiledir import ezdxf.modern dxf = ezdxf.readfile(filename) layer_names = [layer.dxf.name for layer in dxf.layers] dialog = qg.QDialog() lw = qg.QListWidget() for item in layer_names: lw.addItem(qg.QListWidgetItem(item)) lw.setSelectionMode(lw.SelectionMode.ExtendedSelection) button_ok = qg.QPushButton('Ok') button_cancel = qg.QPushButton('Cancel') button_ok.clicked.connect(dialog.accept) button_cancel.clicked.connect(dialog.reject) layout = qg.QVBoxLayout() layout_buttons = qg.QHBoxLayout() layout_buttons.addWidget(button_ok) layout_buttons.addWidget(button_cancel) layout.addWidget(lw) layout.addLayout(layout_buttons) dialog.setLayout(layout) result = dialog.exec_() if result: selected_layers = [ item.data( qc.Qt.ItemDataRole.DisplayRole) for item in lw.selectedItems()] entities = dxf.entities generics = [] for entity in entities: if entity.dxf.layer in selected_layers: if isinstance(entity, ezdxf.modern.graphics.Line): from popupcad.filetypes.genericshapes import GenericLine import numpy points = numpy.array( [entity.dxf.start[:2], entity.dxf.end[:2]]) generics.append( GenericLine.gen_from_point_lists( points.tolist(), [])) elif isinstance(entity, ezdxf.modern.graphics.LWPolyline): from popupcad.filetypes.genericshapes import GenericPolyline from popupcad.filetypes.genericshapes import GenericPoly import numpy points = numpy.array([item for item in entity.get_points()]) points = points[:,:2] if entity.closed: generics.append( GenericPoly.gen_from_point_lists( points.tolist(), [])) else: generics.append( GenericPolyline.gen_from_point_lists( points.tolist(), [])) elif isinstance(entity, ezdxf.modern.graphics.Point): from popupcad.geometry.vertex import DrawnPoint point = DrawnPoint(numpy.array(entity.get_dxf_attrib('location')[:2])) generics.append(point) else: print(entity) new = cls() new.addoperationgeometries(generics) return filename, new else: return None, None
def load_dxf(cls, filename, parent=None): import ezdxf ezdxf.options.template_dir = popupcad.supportfiledir import ezdxf.modern dxf = ezdxf.readfile(filename) layer_names = [layer.dxf.name for layer in dxf.layers] dialog = qg.QDialog() lw = qg.QListWidget() for item in layer_names: lw.addItem(qg.QListWidgetItem(item)) lw.setSelectionMode(lw.ExtendedSelection) button_ok = qg.QPushButton('Ok') button_cancel = qg.QPushButton('Cancel') button_ok.clicked.connect(dialog.accept) button_cancel.clicked.connect(dialog.reject) layout = qg.QVBoxLayout() layout_buttons = qg.QHBoxLayout() layout_buttons.addWidget(button_ok) layout_buttons.addWidget(button_cancel) layout.addWidget(lw) layout.addLayout(layout_buttons) dialog.setLayout(layout) result = dialog.exec_() if result: selected_layers = [ item.data( qc.Qt.DisplayRole) for item in lw.selectedItems()] entities = [item for item in dxf.modelspace()] generics = [] for entity in entities: if entity.dxf.layer in selected_layers: if isinstance(entity, ezdxf.modern.graphics.Line): import numpy points = numpy.array( [entity.dxf.start[:2], entity.dxf.end[:2]]) generics.append( GenericLine.gen_from_point_lists( points.tolist(), [])) elif isinstance(entity, ezdxf.modern.graphics.LWPolyline): import numpy points = numpy.array([item for item in entity.get_points()]) points = points[:,:2] if entity.closed: generics.append(GenericPoly.gen_from_point_lists(points.tolist(),[])) else: generics.append(GenericPolyline.gen_from_point_lists(points.tolist(),[])) elif isinstance(entity, ezdxf.modern.graphics.Point): from popupcad.geometry.vertex import DrawnPoint point = DrawnPoint(numpy.array(entity.get_dxf_attrib('location')[:2])) generics.append(point) elif isinstance(entity, ezdxf.modern.graphics.Spline): knots = entity.get_knot_values() control_points = entity.get_control_points() weights = entity.get_weights() n = len(control_points)-1 domain = popupcad.algorithms.spline_functions.make_domain(knots,n*5) points = popupcad.algorithms.spline_functions.interpolated_points(control_points,knots,weights,domain) points = points[:,:2] if entity.closed: generics.append(GenericPoly.gen_from_point_lists(points.tolist(),[])) else: generics.append(GenericPolyline.gen_from_point_lists(points.tolist(),[])) # print(points) else: print(entity) new = cls.new() new.addoperationgeometries(generics) newfile = os.path.splitext(filename)[0]+'.sketch' new.updatefilename(newfile) return filename, new else: return None, None