コード例 #1
0
    def generate_cut_summary(self):
        self.generate_cut_list()
        self.cut_summary = {}
        self.cut_summary['boardfeet'] = 0.0
        self.cut_summary['pieces'] = {}
        self.width_list = {}
        for cut_item in self.cut_list :

            if str(cut_item.material) == "solid":
                if not "solid" in self.cut_summary['pieces'] :
                    self.cut_summary['pieces']["solid"] = {}
                width_rounded = "{0:.3f}".format(cut_item.width)
                if not str(width_rounded) in self.cut_summary['pieces'][cut_item.material] :
                    self.cut_summary['pieces']["solid"][str(width_rounded)] = {}
                    self.cut_summary['pieces']["solid"][str(width_rounded)]['totallength'] = 0.0
                    self.cut_summary['pieces']["solid"][str(width_rounded)]['boardfeet'] = 0.0
                    self.cut_summary['pieces']["solid"][str(width_rounded)]['pieces'] = {}
                length_rounded = "{0:.3f}".format(cut_item.length)
                if not str(length_rounded) in self.cut_summary['pieces']["solid"][str(width_rounded)]['pieces']:
                    self.cut_summary['pieces']["solid"][str(width_rounded)]['pieces'][str(length_rounded)] = []
                self.cut_summary['pieces']["solid"][str(width_rounded)]['pieces'][str(length_rounded)].append(cut_item)
                self.add_label(cut_item)

                # Update Totals
                self.cut_summary['pieces']["solid"][str(width_rounded)]['totallength'] += cut_item.length
                cur_board_feet = (cut_item.length / 12) * (cut_item.width / 12) * cut_item.thickness
                self.cut_summary['pieces']["solid"][str(width_rounded)]['boardfeet'] = self.cut_summary['pieces']["solid"][str(width_rounded)]['boardfeet'] + cur_board_feet
                self.cut_summary['boardfeet'] = self.cut_summary['pieces']['solid'][str(width_rounded)]['boardfeet'] + cur_board_feet

            else :
                if not 'sheet' in self.cut_summary['pieces']:
                    self.cut_summary['pieces']['sheet'] = {}
                if not cut_item.material in self.cut_summary['pieces']['sheet']:
                    self.cut_summary['pieces']['sheet'][cut_item.material] = []
                self.cut_summary['pieces']['sheet'][cut_item.material].append(cut_item)
                self.add_label(cut_item)

        if 'sheet' in self.cut_summary['pieces']:
            sheet_set_id = 0
            for sheet_material, cut_items in self.cut_summary['pieces']['sheet'].items():
                width_sorted_items = sorted(cut_items, key=lambda k: k.width, reverse=True)
                sheet_set = SheetSet(sheet_set_id, sheet_material, 48, 96)
                if 'wood' in sheet_material:
                    grain_orientation = True
                else:
                    grain_orientation = False
                sheet_set.add_piece_list(width_sorted_items, grain_orientation)
                if not sheet_material in self.sheet_layout:
                    self.sheet_layout[sheet_material] = []
                self.sheet_layout[sheet_material].append(sheet_set)
                for cut_item in cut_items:
                    self.add_label(cut_item)
                sheet_set_id += 1

            # Sheet pieces are now all assigned to shelves. Time to sort.
            for cur_material, sheet_sets in self.sheet_layout.iteritems():

                if 'wood' in sheet_material:
                    grain_orientation = True
                else:
                    grain_orientation = False

                # Sorts here
                # self.use_existing_sheet_space_sort(cur_material, sheet_sets, grain_orientation=grain_orientation)
                self.cut_simplification_sort(cur_material, sheet_sets, grain_orientation=grain_orientation)
                self.cut_simplification_sort(cur_material, sheet_sets, grain_orientation=grain_orientation)
                self.shelf_height_sort(cur_material, sheet_sets)
                self.shelf_piece_thickness_sort(cur_material, sheet_sets)

                for cur_set in sheet_sets:
                    cur_set.build_raphael()
コード例 #2
0
ファイル: views.py プロジェクト: JacobSanford/cabinet-master
def generatePlans(request, project_data_json):

    post_base64 = base64.b64encode(project_data_json)
    project_data = json.loads(project_data_json)

    project = CabinetProject()
    project.rail_bit_cut_depth = float(project_data['rail-bit-cut-depth'])
    project.stock_thickness = float(project_data['stock-thickness'])

    # Loop over all section items:
    for section_number in range(1, int(project_data['num-section-counter-input'])+1):
        # Door Project
        if 'door-opening-overflow_' + str(section_number) in project_data:
            # Sections Add
            box_sections = []
            for section_ratio in str(project_data['box-dividers_' + str(section_number)]).split('|'):
                box_sections.append({
                    'type': CabinetDoor,
                    'ratio': section_ratio
                })
            box_section_counter = 0
            for cur_box_section in box_sections:
                box_section_counter += 1
                for _ in xrange(int(project_data['door-number-doors_' + str(section_number)])):
                    door = CabinetDoor()
                    door.id = str(project.get_new_door_id())
                    project.summary['DOOR' + str(door.id)] = str(project_data['door-opening-width_' + str(section_number)]) + '" x ' + str(project_data['door-opening-height_' + str(section_number)]) + '"'
                    door.panel_material = str(project_data['door-panel-type_' + str(section_number)])
                    door.panel_undersize = float(project_data['panel-undersize'])
                    door.rail_bit_cut_depth = float(project.rail_bit_cut_depth)
                    door.stock_thickness = float(project.stock_thickness)
                    door.frame_width = float(project_data['door-frame-width_' + str(section_number)])
                    if str(project_data['door-number-doors_' + str(section_number)]) == "2" :
                        door.width = (float(project_data['door-opening-width_' + str(section_number)]) + 2 * float(project_data['door-opening-overflow_' + str(section_number)]) - float(project_data['door-split-gap_' + str(section_number)]))/2
                    else :
                        door.width = float(project_data['door-opening-width_' + str(section_number)]) + 2 * float(project_data['door-opening-overflow_' + str(section_number)])
                    door.height = float(project_data['door-opening-height_' + str(section_number)]) + 2 * float(project_data['door-opening-overflow_' + str(section_number)])
                    project.doors.append(door)

                    # Compute heights for sections
                    door_split_gap = float(project_data['door-split-gap_' + str(section_number)])
                    divisible_height = door.height - ((len(box_sections) - 1) * door_split_gap)
                    door.height = divisible_height * float(cur_box_section['ratio'])

        # Box Project
        elif 'box-depth_' + str(section_number) in project_data:
            # Determine Ratios
            # Special Case : Drawer on Top
            box_sections = []
            if str(project_data['box-dividers_' + str(section_number)]) == '6" Drawer on Top':
                # Find Ratio of 6" to height
                drawer_ratio = (6.0 + float(project_data['box-door-reveal-top_' + str(section_number)])) / float(project_data['box-height_' + str(section_number)])
                box_sections.append({
                    'type': CabinetDrawer,
                    'ratio': drawer_ratio
                })
                box_sections.append({
                    'type': CabinetDoor,
                    'ratio': 1 - drawer_ratio
                })
            elif str(project_data['box-dividers_' + str(section_number)]) == '6" Drawer on Top With Hamper':
                # Find Ratio of 6" to height
                drawer_ratio = (6.0 + float(project_data['box-door-reveal-top_' + str(section_number)]))  / float(project_data['box-height_' + str(section_number)])
                box_sections.append({
                    'type': CabinetDrawer,
                    'ratio': drawer_ratio
                })
                box_sections.append({
                    'type': CabinetHamper,
                    'ratio': 1 - drawer_ratio
                })
            else:
                for section_ratio in str(project_data['box-dividers_' + str(section_number)]).split('|'):
                    box_sections.append({
                        'type': CabinetDoor,
                        'ratio': section_ratio
                    })

            num_doors_per_gap = int(project_data['box-number-doors_' + str(section_number)])
            door_split_gap = float(project_data['box-door-split-gap_' + str(section_number)])

            # Doors / Drawers
            box_section_counter = 0
            for cur_box_section in box_sections:
                box_section_counter += 1
                doors_across_gap_counter = 0
                for _ in xrange(num_doors_per_gap):
                    doors_across_gap_counter += 1
                    door = cur_box_section['type']()
                    door.id = str(project.get_new_door_id())
                    door.box_depth = float(project_data['box-depth_' + str(section_number)])
                    door.box_width = float(project_data['box-width_' + str(section_number)])
                    door.box_sheet_thickness = float(project_data['box-sheet-thickness_' + str(section_number)])
                    door.reveal_left = float(project_data['box-door-reveal-left_' + str(section_number)])
                    door.reveal_right = float(project_data['box-door-reveal-right_' + str(section_number)])
                    door.reveal_top = float(project_data['box-door-reveal-top_' + str(section_number)])
                    door.reveal_bottom = float(project_data['box-door-reveal-bottom_' + str(section_number)])
                    door.panel_material = str(project_data['box-door-panel-type_' + str(section_number)])
                    door.panel_undersize = float(project_data['panel-undersize'])
                    door.rail_bit_cut_depth = float(project.rail_bit_cut_depth)
                    door.stock_thickness = float(project.stock_thickness)
                    door.frame_width = float(project_data['box-door-frame-width_' + str(section_number)])

                    # Compute widths for multiple doors across box
                    if num_doors_per_gap == 2:
                        door.width = (float(project_data['box-width_' + str(section_number)]) - door_split_gap)/2
                    else:
                        door.width = float(project_data['box-width_' + str(section_number)])

                    # Deal with multiple doors across gap and reveals properly
                    # Door splits are already considered in door_split_gap
                    if num_doors_per_gap == 2:
                        if doors_across_gap_counter == 1:
                            door.reveal_right = 0.0
                        if doors_across_gap_counter == 2:
                            door.hinge_side = "right"
                            door.reveal_left = 0.0

                    # Compute heights for sections
                    divisible_height = float(project_data['box-height_' + str(section_number)]) - ((len(box_sections) - 1) * door_split_gap)

                    # Since we may have modified the ratios earlier for a drawer on top, force a width here. It usually doesn't matter.
                    if cur_box_section['type'] == CabinetDrawer and box_section_counter == 1 and str(project_data['box-dividers_' + str(section_number)]) in ['6" Drawer on Top', '6" Drawer on Top With Hamper']:
                        door.height = 6.0
                        door.reveal_top = 0.0
                    else:
                        door.height = divisible_height * float(cur_box_section['ratio'])

                    # Deal with sections and reveals properly
                    # Gaps in sections are already considered in door_split_gap
                    if len(box_sections) > 1:
                        if box_section_counter == 1:
                            door.reveal_bottom = 0.0
                        elif box_section_counter == len(box_sections):
                            door.reveal_top = 0.0
                        else:
                            door.reveal_bottom = 0.0
                            door.reveal_top = 0.0

                    if cur_box_section['type'] == CabinetDoor:
                        project.doors.append(door)
                    if cur_box_section['type'] == CabinetDrawer or cur_box_section['type'] == CabinetHamper:
                        project.drawers.append(door)

            # Box Carcass
            box = CabinetBox()
            box.id = str(project.get_new_box_id())
            project.summary['BOX' + str(box.id)] = str(project_data['box-width_' + str(section_number)]) + '" wide x ' + str(project_data['box-height_' + str(section_number)]) + '" high x ' + str(project_data['box-depth_' + str(section_number)]) + '" deep (' + str(project_data['box-dividers_' + str(section_number)]) + ')'
            box.material = str(project_data['box-sheet-material_' + str(section_number)])
            box.sheet_thickness = float(project_data['box-sheet-thickness_' + str(section_number)])
            box.width = float(project_data['box-width_' + str(section_number)])
            box.height = float(project_data['box-height_' + str(section_number)])
            box.depth = float(project_data['box-depth_' + str(section_number)]) - float(project_data['bumper-thickness']) - float(project_data['stock-thickness'])
            box.num_dividers = len(box_sections) - 1
            if str(project_data['box-dividers_' + str(section_number)]) == '6" Drawer on Top':
                box.divider_is_spreader = True
            box.num_shelves = int(project_data['box-number-shelves_' + str(section_number)])
            if 'box-counter-on-top_' + str(section_number) in project_data:
                box.counter_on_top = True
            project.boxes.append(box)

        # Freeform Piece
        elif 'piece-width_' + str(section_number) in project_data:
            if str(project_data['piece-sheet-material_' + str(section_number)]) == 'solid':
                material_string = 'solid'
            else:
                material_string = str(float(project_data['piece-sheet-thickness_' + str(section_number)])) + '-' + str(project_data['piece-sheet-material_' + str(section_number)])
            piece = WoodPiece(
                str(str(project_data['piece-label-input_' + str(section_number)]) + str(project.get_new_door_id())).upper().replace(' ', '_'),
                str(project_data['piece-label-input_' + str(section_number)]),
                float(project_data['piece-sheet-thickness_' + str(section_number)]),
                float(project_data['piece-height_' + str(section_number)]),
                float(project_data['piece-width_' + str(section_number)]),
                material_string,
                str(project_data['piece-comments-input_' + str(section_number)])
            )
            project.pieces.append(piece)

    project.generate_cut_summary()

    stock_length = 96
    stock_length = stock_length - 1.5

    message_to_print = 'Based on ' + str(stock_length) + '"' + "\n"

    # Get Number of Solid Lengths Needed For Each Based on Passed Length
    for width, material_pieces in project.cut_summary['pieces']['solid'].items():
        solid_set = SheetSet(1, 'solid', float(width), float(stock_length))
        for cur_length in material_pieces['pieces']:
            for x in range(0, len(material_pieces['pieces'][cur_length])):
                solid_set.add_piece( WoodPiece('1', '1', 1, float(width), float(cur_length), '', ''), True)
        message_to_print = message_to_print + str(len(solid_set.sheets)) + ' lengths needed for ' + width + "\n"

    context = {
        'project_summary' : project.summary,
        'cut_summary' : project.cut_summary,
        'sheet_layouts' : project.sheet_layout,
        'banding' : project.banding,
        'hardware' : project.hardware,
        'project_hash' : post_base64,
        'label_hash' : base64.b64encode(json.dumps(project.labels)),
        'project_data_json' : project_data_json,
        'stock_message' : message_to_print,
    }

    return render(request, 'cutlist.html', context)