示例#1
0
    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]))
示例#2
0
 def run(self) -> None:
     """Start the algorithm loop."""
     for name, path in self.mech_params['Target'].items():
         logger.debug(f"- [P{name}] ({len(path)})")
     t0 = perf_counter()
     for self.current_loop in range(self.loop):
         logger.info(
             f"Algorithm [{self.current_loop + 1}]: {self.type_num}")
         if self.is_stop:
             # Cancel the remaining tasks
             logger.info("Canceled.")
             continue
         self.result.emit(self.__algorithm())
     logger.info(f"total cost time: {perf_counter() - t0:.02f} [s]")
     self.finished.emit()
示例#3
0
 def input_from(self,
                format_name: str,
                format_choose: Sequence[str],
                multiple: bool = False) -> Union[str, List[str]]:
     """Get file name(s)."""
     if multiple:
         func = QFileDialog.getOpenFileNames
     else:
         func = QFileDialog.getOpenFileName
     file_names: Union[str, List[str]]
     file_names, suffix = func(
         self, f"Open {format_name} file{'s' if multiple else ''}...",
         self.env, ';;'.join(format_choose))
     if file_names:
         if type(file_names) is str:
             self.set_locate(QFileInfo(file_names).absolutePath())
         else:
             self.set_locate(QFileInfo(file_names[0]).absolutePath())
         suffix = str_between(suffix, '(', ')').split('*')[-1]
         logger.debug(f"Format: {suffix}")
     return file_names
示例#4
0
 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() != 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
示例#5
0
 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}\"]")