def resolve(self) -> None: """Resolve: Using three libraries to solve the system. + Pyslvs + Python-Solvespace + Sketch Solve """ for b, d, a in self.inputs_widget.input_pairs(): if b == d: self.vpoint_list[b].set_offset(a) solve_kernel = self.prefer.planar_solver_option try: if solve_kernel == 0: result = expr_solving( self.get_triangle(), {n: f'P{n}' for n in range(len(self.vpoint_list))}, self.vpoint_list, tuple(a for b, d, a in self.inputs_widget.input_pairs() if b != d)) elif solve_kernel == 1: result, _ = _slvs_solve(self.vpoint_list, { (b, d): a for b, d, a in self.inputs_widget.input_pairs() } if not self.free_move_button.isChecked() else {}) elif solve_kernel == 2: result = SolverSystem( self.vpoint_list, {(b, d): a for b, d, a in self.inputs_widget.input_pairs()}).solve() else: raise ValueError("incorrect kernel") except ValueError as error: # Error: Show warning without update data. if self.prefer.console_error_option: logger.warn(format_exc()) error_text = f"Error: {error}" self.conflict.setToolTip(error_text) self.conflict.setStatusTip(error_text) self.conflict.setVisible(True) self.dof_view.setVisible(False) else: self.entities_point.update_current_position(result) for i, c in enumerate(result): if type(c[0]) is float: self.vpoint_list[i].move(cast(_Coord, c)) else: c1, c2 = cast(Tuple[_Coord, _Coord], c) self.vpoint_list[i].move(c1, c2) self.__dof = vpoint_dof(self.vpoint_list) self.dof_view.setText( f"{self.__dof} ({self.inputs_widget.input_count()})") self.conflict.setVisible(False) self.dof_view.setVisible(True) self.reload_canvas()
def resolve(self) -> None: """Resolve: Using three libraries to solve the system. + Pyslvs + Python-Solvespace + Sketch Solve """ for b, d, a in self.inputs_widget.input_pairs(): if b == d: self.vpoint_list[b].set_offset(a) solve_kernel = self.prefer.planar_solver_option input_pair = {(b, d): a for b, d, a in self.inputs_widget.input_pairs()} try: if solve_kernel == Kernel.PYSLVS: result = expr_solving( self.get_triangle(), self.vpoint_list, input_pair ) elif solve_kernel == Kernel.SOLVESPACE: result, _ = _slvs_solve( self.vpoint_list, input_pair if not self.free_move_button.isChecked() else {} ) elif solve_kernel == Kernel.SKETCH_SOLVE: result = SolverSystem(self.vpoint_list, input_pair).solve() else: raise ValueError("incorrect kernel") except ValueError as error: # Error: Show warning without update data. if self.prefer.console_error_option: logger.warn(format_exc()) error_text = f"Error: {error}" self.conflict.setToolTip(error_text) self.conflict.setStatusTip(error_text) self.conflict.setVisible(True) self.dof_view.setVisible(False) else: self.entities_point.update_current_position(result) for i, c in enumerate(result): if isinstance(c[0], float): self.vpoint_list[i].move(c) else: c1, c2 = c self.vpoint_list[i].move(c1, c2) self.__dof = vpoint_dof(self.vpoint_list) self.dof_view.setText( f"{self.__dof} ({self.inputs_widget.input_count()})") self.conflict.setVisible(False) self.dof_view.setVisible(True) self.reload_canvas()