Ejemplo n.º 1
0
def _init_crow(build_popup, crow):
    visible = SETTINGS.value('developer_mode', 0)
    crow.setVisible(bool(visible))
    if visible:
        crow.setChecked(
            safe_int(build_popup.gui_comments.get('BUILD_CROW', '0')))
    crow.toggled.connect(lambda: _update_build_cmd(build_popup))
Ejemplo n.º 2
0
    def init_background_mesh(self):
        """init the background mesh"""
        project = self.project

        self.mesh_extents = [
            safe_float(project.get_value(key, default=0.0))
            for key in MESH_EXTENT_KEYS
        ]
        self.mesh_cells = [
            safe_int(project.get_value(key, default=1))
            for key in MESH_CELL_KEYS
        ]
        self.mesh_spacing = [[], [], []]

        # disable delete btns
        for btn in self.mesh_delete_btns:
            btn.setEnabled(False)

        # collect dx, dy, dz
        for (i, (s, c)) in enumerate(zip(['dx', 'dy', 'dz'], MESH_CELL_KEYS)):
            d = [
                project.get_value(s, args=args)
                for args in sorted(project.get_key_indices(s))
            ]
            l = len(d)

            # if there are spacing, update the keywords.
            if l > 0:
                self.mesh_cells[i] = l
                self.update_mesh_keyword(c, l)
                self.mesh_spacing[i] = d
                self.extract_mesh_spacing(i, d)

        # collect variable grid spacing keywords
        for (i, k) in enumerate(['x', 'y', 'z']):
            indices = project.get_key_indices('cp' + k)
            if indices:
                table_dic = OrderedDict()
                for j, ind in enumerate(sorted(indices)):
                    ind = ind[0]
                    table_dic[j] = {
                        'position': project.get_value('cp' + k, 0, args=ind),
                        'cells': project.get_value('nc' + k, 1, args=ind + 1),
                        'stretch': project.get_value('er' + k, 1,
                                                     args=ind + 1),
                        'first': project.get_value('first_d' + k,
                                                   0,
                                                   args=ind + 1),
                        'last': project.get_value('last_d' + k,
                                                  0,
                                                  args=ind + 1)
                    }
                self.mesh_tables[i].set_value(table_dic)
                self.mesh_tables[i].fit_to_contents()

        self.update_background_mesh()
Ejemplo n.º 3
0
 def update_background_mesh_cells(self, key, val, args):
     """collect cells changes, check if value is different"""
     if not self.mesh_cells: return
     if key == 'no_k':
         self.update_background_mesh()
     else:
         val = safe_int(val, 1)
         ind = MESH_CELL_KEYS.index(key)
         old_val = self.mesh_cells[ind]
         if old_val != val:
             self.mesh_cells[ind] = val
             self.update_background_mesh()
Ejemplo n.º 4
0
    def mesh_split(self, table, d):
        """split the selected control point"""
        row, col = table.get_clicked_cell()
        data = table.value
        split_data = data[row]
        prev_data_loc = self.project.get_value(d + '_min', 0)
        if row >= 2:
            prev_data_loc = safe_float(data[row - 1]['position'])

        # find the midpoint, and slit the cells evenly
        midpoint = (safe_float(split_data['position']) -
                    prev_data_loc) / 2.0 + prev_data_loc
        cells = max(int(safe_int(split_data['cells'], 1) / 2), 1)
        split_data['cells'] = cells

        # insert the cell
        # TODO: better way?
        new = OrderedDict()
        for i, ctrl in data.items():
            if i < row:
                new[i] = ctrl
            elif i == row:
                new[i] = {
                    'position': midpoint,
                    'cells': cells,
                    'stretch': 1.0,
                    'first': 0.0,
                    'last': 0.0
                }
                self.mesh_update_mfixkeys(new[i], i, d)
                new[i + 1] = ctrl
                self.mesh_update_mfixkeys(ctrl, i + 1, d)
            else:
                new[i + 1] = ctrl
                self.mesh_update_mfixkeys(ctrl, i + 1, d)

        table.set_value(new)
        table.fit_to_contents()
        self.update_background_mesh()
Ejemplo n.º 5
0
def ctrl_pts_to_loc(ctrl, min_loc):
    """given control points, convert to location"""
    loc = [min_loc]
    last = min_loc
    for pt in ctrl.values():
        er = safe_float(pt['stretch'], 1.0)
        cp = safe_float(pt['position'], 0.0)
        nc = safe_int(pt['cells'], 1)

        # uniform dx
        dx = (cp - last) / nc

        # first dx?
        fdx = safe_float(pt['first'], 0.0)
        if fdx < 0 and len(loc) > 2:
            fdx = loc[-1] - loc[-2]

        # expansion ratio
        ratio = 1
        prev_cell_w = dx
        if nc > 1 and er != 1:
            ratio = er**(1 / (nc - 1))
            prev_cell_w = (cp - loc[-1]) * (1 - ratio) / (
                1 - ratio**nc)  # current cell width
            prev_cell_w /= ratio  # backup one cell for the loop below

        # add cell positions to list
        for i in range(nc):
            cell_w = dx
            if er != 1:
                cell_w = prev_cell_w * ratio
            loc.append(loc[-1] + cell_w)
            prev_cell_w = cell_w
        last = loc[-1]

    return loc
Ejemplo n.º 6
0
def _init_parallel(build_popup):
    parallel = build_popup.checkBox_parallel
    parallel.setChecked(
        safe_int(build_popup.gui_comments.get('BUILD_PARALLEL', '1')))
    parallel.toggled.connect(lambda: _update_build_cmd(build_popup))
Ejemplo n.º 7
0
def _init_smp(build_popup, smp, visible):
    smp.setVisible(visible)
    if visible:
        smp.setChecked(
            safe_int(build_popup.gui_comments.get('BUILD_SMP', '0')))
    smp.toggled.connect(lambda: _update_build_cmd(build_popup))