def __read_slvs(self, file_name: str) -> None: """Read slvs format. + Choose a group. + Read the entities of the group. """ parser = SlvsParser(file_name) if not parser.is_valid(): QMessageBox.warning(self, "Format error", "The format is not support.") return groups = parser.get_groups() if not groups: QMessageBox.warning(self, "Format error", "The model file is empty.") return group, ok = QInputDialog.getItem( self, "Solvespace groups", "Choose a group:\n" "(Please know that the group must contain a sketch only.)", ["@".join(g) for g in groups], 0, False) if not ok: return self.clear() logger.debug(f"Read from group: {group}") self.parse_expression(parser.parse(group.split('@')[0]))
def run(self) -> None: """Start the algorithm loop.""" for name, path in self.mech['target'].items(): logger.debug(f"- [P{name}] ({len(path)})") t0 = process_time() for self.loop in range(self.loop): logger.info(f"Algorithm [{self.loop + 1}]: {self.alg}") if self.is_stop: # Cancel the remaining tasks logger.info("Canceled.") continue self.result.emit(self.__task()) logger.info(f"total cost time: {process_time() - t0:.02f} [s]") self.finished.emit()
def output_to(self, format_name: str, format_choose: Sequence[str]) -> str: """Simple to support multiple format.""" file_name, suffix = QFileDialog.getSaveFileName( self, f"Save to {format_name}...", self.env + '/' + self.project_widget.base_file_name() + str_between(format_choose[0], '(', ')').split('*')[-1], ';;'.join(format_choose)) if file_name: suffix = str_between(suffix, '(', ')').split('*')[-1] logger.debug(f"Format: {suffix}") info = QFileInfo(file_name) if info.suffix().lower() != suffix[1:]: file_name += suffix info = QFileInfo(file_name) if info.isFile() and QMessageBox.question( self, "File exist", f"{file_name} already exists.\nDo you want to replace it?" ) == QMessageBox.No: return "" self.set_locate(info.absolutePath()) return file_name
def set_locate(self, locate: str) -> None: """Set environment variables.""" if locate == self.env or not QDir(locate).exists(): return self.env = locate logger.debug(f"~Set workplace to: \"{self.env}\"")