Exemplo n.º 1
0
    def on_export(self, event: wx.Event):
        org_choice_values = []
        rep_rx_choice_values = []
        rep_ry_choice_values = []
        rep_rz_choice_values = []
        rep_mx_choice_values = []
        rep_my_choice_values = []
        rep_mz_choice_values = []

        for m in self.get_bone_list():
            org_choice_values.append(m[0])
            rep_rx_choice_values.append(m[1])
            rep_ry_choice_values.append(m[2])
            rep_rz_choice_values.append(m[3])
            rep_mx_choice_values.append(m[4])
            rep_my_choice_values.append(m[5])
            rep_mz_choice_values.append(m[6])

        output_bone_path = MFileUtils.get_output_split_bone_path(
            self.panel.vmd_file_ctrl.file_ctrl.GetPath(),
            self.panel.model_file_ctrl.file_ctrl.GetPath())

        try:
            with open(output_bone_path, encoding='cp932', mode='w',
                      newline='') as f:
                cw = csv.writer(f,
                                delimiter=",",
                                quotechar='"',
                                quoting=csv.QUOTE_ALL)

                cw.writerow(org_choice_values)
                cw.writerow(rep_rx_choice_values)
                cw.writerow(rep_ry_choice_values)
                cw.writerow(rep_rz_choice_values)
                cw.writerow(rep_mx_choice_values)
                cw.writerow(rep_my_choice_values)
                cw.writerow(rep_mz_choice_values)

            logger.info("出力成功: %s" % output_bone_path)

            dialog = wx.MessageDialog(self.frame,
                                      "多段ボーンデータのエクスポートに成功しました \n'%s'" %
                                      (output_bone_path),
                                      style=wx.OK)
            dialog.ShowModal()
            dialog.Destroy()

        except Exception:
            dialog = wx.MessageDialog(
                self.frame,
                "多段ボーンデータのエクスポートに失敗しました \n'%s'\n\n%s." %
                (output_bone_path, traceback.format_exc()),
                style=wx.OK)
            dialog.ShowModal()
            dialog.Destroy()
Exemplo n.º 2
0
    def on_import(self, event: wx.Event):
        input_bone_path = MFileUtils.get_output_split_bone_path(
            self.panel.vmd_file_ctrl.file_ctrl.GetPath(),
            self.panel.model_file_ctrl.file_ctrl.GetPath())

        with wx.FileDialog(
                self.frame,
                "ボーン組み合わせCSVを読み込む",
                wildcard=u"CSVファイル (*.csv)|*.csv|すべてのファイル (*.*)|*.*",
                defaultDir=os.path.dirname(input_bone_path),
                style=wx.FD_OPEN | wx.FD_FILE_MUST_EXIST) as fileDialog:

            if fileDialog.ShowModal() == wx.ID_CANCEL:
                return  # the user changed their mind

            # Proceed loading the file chosen by the user
            target_bone_path = fileDialog.GetPath()
            try:
                with open(target_bone_path, 'r') as f:
                    cr = csv.reader(f, delimiter=",", quotechar='"')
                    bone_lines = [row for row in cr]

                    if len(bone_lines) == 0:
                        return

                    if not bone_lines[0]:
                        raise Exception("処理対象ボーン名指定なし")

                    org_choice_values = bone_lines[0]
                    if len(bone_lines) >= 4:
                        rep_rx_choice_values = bone_lines[1]
                        rep_ry_choice_values = bone_lines[2]
                        rep_rz_choice_values = bone_lines[3]
                    else:
                        rep_rx_choice_values = [""]
                        rep_ry_choice_values = [""]
                        rep_rz_choice_values = [""]

                    if len(bone_lines) >= 7:
                        rep_mx_choice_values = bone_lines[4]
                        rep_my_choice_values = bone_lines[5]
                        rep_mz_choice_values = bone_lines[6]
                    else:
                        rep_mx_choice_values = [""]
                        rep_my_choice_values = [""]
                        rep_mz_choice_values = [""]

                    for (ov, rmxv, rmyv, rmzv, rrxv, rryv, rrzv) in zip(org_choice_values, rep_mx_choice_values, rep_my_choice_values, rep_mz_choice_values, \
                                                                        rep_rx_choice_values, rep_ry_choice_values, rep_rz_choice_values):
                        oc = self.org_choices[-1]
                        rrxc = self.rep_rx_choices[-1]
                        rryc = self.rep_ry_choices[-1]
                        rrzc = self.rep_rz_choices[-1]
                        rmxc = self.rep_mx_choices[-1]
                        rmyc = self.rep_my_choices[-1]
                        rmzc = self.rep_mz_choices[-1]

                        is_seted = False
                        for v, c in [(ov, oc), (rmxv, rmxc), (rmyv, rmyc),
                                     (rmzv, rmzc), (rrxv, rrxc), (rryv, rryc),
                                     (rrzv, rrzc)]:
                            logger.debug("v: %s, c: %s", v, c)
                            for n in range(c.GetCount()):
                                if c.GetString(n).strip() == v:
                                    c.SetSelection(n)
                                    is_seted = True

                        if is_seted:
                            # 行追加
                            self.add_line()
                        else:
                            # ひとつも追加がなかった場合、終了
                            break

                # パス変更
                self.panel.set_output_vmd_path(event)

            except Exception:
                dialog = wx.MessageDialog(
                    self.frame,
                    "CSVファイルが読み込めませんでした '%s'\n\n%s." %
                    (target_bone_path, traceback.format_exc()),
                    style=wx.OK)
                dialog.ShowModal()
                dialog.Destroy()