You've already forked IPyConsole
mirror of
https://github.com/izzy2lost/IPyConsole.git
synced 2026-03-10 11:52:51 -07:00
448 lines
17 KiB
Python
448 lines
17 KiB
Python
|
|
# -*- coding: utf-8 -*-
|
|||
|
|
# Python Script, API Version = V241
|
|||
|
|
|
|||
|
|
import clr
|
|||
|
|
|
|||
|
|
clr.AddReference("System")
|
|||
|
|
clr.AddReference("System.IO")
|
|||
|
|
clr.AddReference("System.Threading")
|
|||
|
|
clr.AddReference("System.Drawing")
|
|||
|
|
clr.AddReference("System.Windows.Forms")
|
|||
|
|
|
|||
|
|
from System import Type, Activator
|
|||
|
|
from System.Drawing import Point as sysPoint, Size as sysSize
|
|||
|
|
from System.Threading import Thread, ThreadStart, ApartmentState, CancellationTokenSource
|
|||
|
|
from System.Windows.Forms import Application, Form, Label, TextBox, Button, OpenFileDialog, DialogResult, MessageBox, FolderBrowserDialog, MessageBoxButtons, GroupBox, RadioButton, CheckBox
|
|||
|
|
from System.IO import File, Directory, FileInfo, Path
|
|||
|
|
|
|||
|
|
import sys
|
|||
|
|
import re
|
|||
|
|
import os
|
|||
|
|
import traceback
|
|||
|
|
import tempfile
|
|||
|
|
|
|||
|
|
class MainForm(Form):
|
|||
|
|
def __init__(self):
|
|||
|
|
# <20><><EFBFBD><EFBFBD>self.XmpViewer
|
|||
|
|
try:
|
|||
|
|
# Virtual Huamn Vision Lab --- VisionLabViewer.Application
|
|||
|
|
# Virtual Photometric Lab --- XmpViewer.Application
|
|||
|
|
self.theApp = Type.GetTypeFromProgID("VisionLabViewer.Application")
|
|||
|
|
if self.theApp is None:
|
|||
|
|
raise Exception("<EFBFBD><EFBFBD><EFBFBD>Թ<EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD>Virtual Huamn Vision Lab<61><62>!")
|
|||
|
|
self.XmpViewer = Activator.CreateInstance(self.theApp)
|
|||
|
|
except Exception as e:
|
|||
|
|
self.handleError("<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", e)
|
|||
|
|
|
|||
|
|
# <20><>־λ-<2D><>ֹ<EFBFBD><D6B9><EFBFBD><EFBFBD>
|
|||
|
|
self.stop_sim = False
|
|||
|
|
|
|||
|
|
# <20><><EFBFBD>崰<EFBFBD><E5B4B0>
|
|||
|
|
self.Name = "<EFBFBD>Զ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʲ<EFBFBD>ִ<EFBFBD>е<EFBFBD><EFBFBD><EFBFBD>ͼƬ"
|
|||
|
|
self.Text = "<EFBFBD>Զ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʲ<EFBFBD>ִ<EFBFBD>е<EFBFBD><EFBFBD><EFBFBD>ͼƬ"
|
|||
|
|
self.Width = 1000
|
|||
|
|
self.Height = 300
|
|||
|
|
self.TopMost = True
|
|||
|
|
|
|||
|
|
# ѡ<><D1A1> surface library path
|
|||
|
|
self.labelSurfaceLibrary = Label()
|
|||
|
|
self.labelSurfaceLibrary.Text = "surface library path:"
|
|||
|
|
self.labelSurfaceLibrary.Location = sysPoint(30, 10)
|
|||
|
|
self.labelSurfaceLibrary.Size = sysSize(180, 20)
|
|||
|
|
self.textBoxSurfaceLibrary = TextBox()
|
|||
|
|
self.textBoxSurfaceLibrary.Location = sysPoint(230, 10)
|
|||
|
|
self.textBoxSurfaceLibrary.Size = sysSize(430, 30)
|
|||
|
|
self.btnChooseSurfacePath = Button()
|
|||
|
|
self.btnChooseSurfacePath.Text = "<EFBFBD><EFBFBD>"
|
|||
|
|
self.btnChooseSurfacePath.Location = sysPoint(670, 10)
|
|||
|
|
self.btnChooseSurfacePath.Size = sysSize(28, 20)
|
|||
|
|
self.btnChooseSurfacePath.Click += self.setSurfacePath
|
|||
|
|
|
|||
|
|
# ѡ<><D1A1> volume library path:
|
|||
|
|
self.labelVolumeLibrary = Label()
|
|||
|
|
self.labelVolumeLibrary.Text = "volume library path:"
|
|||
|
|
self.labelVolumeLibrary.Location = sysPoint(30, 50)
|
|||
|
|
self.labelVolumeLibrary.Size = sysSize(180, 20)
|
|||
|
|
self.textBoxVolumeLibrary = TextBox()
|
|||
|
|
self.textBoxVolumeLibrary.Location = sysPoint(230, 50)
|
|||
|
|
self.textBoxVolumeLibrary.Size = sysSize(430, 30)
|
|||
|
|
self.btnChooseVolumePath = Button()
|
|||
|
|
self.btnChooseVolumePath.Text = "<EFBFBD><EFBFBD>"
|
|||
|
|
self.btnChooseVolumePath.Location = sysPoint(670, 50)
|
|||
|
|
self.btnChooseVolumePath.Size = sysSize(28, 20)
|
|||
|
|
self.btnChooseVolumePath.Click += self.setVolumePath
|
|||
|
|
|
|||
|
|
# ѡ<><D1A1> <20><>ǰʹ<C7B0>õ<EFBFBD>scdocx <20>ļ<EFBFBD>
|
|||
|
|
self.labelScDocxPath = Label()
|
|||
|
|
self.labelScDocxPath.Text = "scdocx file:"
|
|||
|
|
self.labelScDocxPath.Location = sysPoint(30, 90)
|
|||
|
|
self.labelScDocxPath.Size = sysSize(180, 20)
|
|||
|
|
self.textBoxScDocxPath = TextBox()
|
|||
|
|
self.textBoxScDocxPath.Location = sysPoint(230, 90)
|
|||
|
|
self.textBoxScDocxPath.Size = sysSize(430, 30)
|
|||
|
|
self.btnChooseScDocxPath = Button()
|
|||
|
|
self.btnChooseScDocxPath.Text = "<EFBFBD><EFBFBD>"
|
|||
|
|
self.btnChooseScDocxPath.Location = sysPoint(670, 90)
|
|||
|
|
self.btnChooseScDocxPath.Size = sysSize(28, 20)
|
|||
|
|
self.btnChooseScDocxPath.Click += self.setScDocxPath
|
|||
|
|
|
|||
|
|
# Radio<69><6F> <20><>ѡCPU/GPU<50><55><EFBFBD><EFBFBD>
|
|||
|
|
self.groupBox = GroupBox()
|
|||
|
|
self.groupBox.Location = sysPoint(750, 10)
|
|||
|
|
self.groupBox.Size = sysSize(200, 80)
|
|||
|
|
self.groupBox.Text = "CPU/GPU"
|
|||
|
|
|
|||
|
|
# Radio Button CPU
|
|||
|
|
self.radio_btn_cpu = RadioButton()
|
|||
|
|
self.radio_btn_cpu.Text = "CPU"
|
|||
|
|
self.radio_btn_cpu.Location = sysPoint(10, 20)
|
|||
|
|
self.radio_btn_cpu.Checked = True # Ĭ<>ϣ<EFBFBD>CPU<50><55><EFBFBD><EFBFBD>
|
|||
|
|
|
|||
|
|
# Radio Button GPU
|
|||
|
|
self.radio_btn_gpu = RadioButton()
|
|||
|
|
self.radio_btn_gpu.Text = "GPU"
|
|||
|
|
self.radio_btn_gpu.Location = sysPoint(10, 40)
|
|||
|
|
|
|||
|
|
# <20><>ֹѡ<D6B9><D1A1>
|
|||
|
|
self.label_pause = Label()
|
|||
|
|
self.label_pause.Text = "<EFBFBD><EFBFBD><EFBFBD>ִ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><EFBFBD><EFBFBD>ֹ"
|
|||
|
|
self.label_pause.Location = sysPoint(790, 110)
|
|||
|
|
self.label_pause.Size = sysSize(180, 20)
|
|||
|
|
self.checkbox_pause = CheckBox()
|
|||
|
|
self.checkbox_pause.Location = sysPoint(760, 100)
|
|||
|
|
self.checkbox_pause.Size = sysSize(30, 30)
|
|||
|
|
self.checkbox_pause.Checked = False # Ĭ<>ϣ<EFBFBD><CFA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֹ<EFBFBD><D6B9><EFBFBD><EFBFBD>
|
|||
|
|
|
|||
|
|
# <20><>ť ִ<>з<EFBFBD><D0B7><EFBFBD>
|
|||
|
|
self.btnCompute = Button()
|
|||
|
|
self.btnCompute.Text = "<EFBFBD><EFBFBD>ʼִ<EFBFBD><EFBFBD>"
|
|||
|
|
self.btnCompute.Location = sysPoint(350, 160)
|
|||
|
|
self.btnCompute.Size = sysSize(180, 30)
|
|||
|
|
self.btnCompute.Click += self.compute
|
|||
|
|
|
|||
|
|
# <20><>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD>·<EFBFBD><C2B7>
|
|||
|
|
self.labelInfo = Label()
|
|||
|
|
self.labelInfo.Location = sysPoint(30, 270)
|
|||
|
|
self.labelInfo.Size = sysSize(340, 30)
|
|||
|
|
|
|||
|
|
# ·<><C2B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
|
|||
|
|
self.outpath = ""
|
|||
|
|
self.configFile = os.path.join(tempfile.gettempdir(), "zhanshengconfig.txt")
|
|||
|
|
self.errorlogFile = os.path.join(tempfile.gettempdir(), "zhanshengerrorlog.txt")
|
|||
|
|
|
|||
|
|
# <20><>·<EFBFBD><C2B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC>ж<EFBFBD>ȡ<EFBFBD><C8A1>һ<EFBFBD>μ<EFBFBD>¼<EFBFBD><C2BC><EFBFBD>ļ<EFBFBD>
|
|||
|
|
if os.path.isfile(self.configFile):
|
|||
|
|
with open(self.configFile, "r") as f:
|
|||
|
|
count = 0
|
|||
|
|
for line in f.readlines():
|
|||
|
|
count += 1
|
|||
|
|
line = line.strip()
|
|||
|
|
if count == 1:
|
|||
|
|
self.textBoxSurfaceLibrary.Text = line
|
|||
|
|
elif count == 2:
|
|||
|
|
self.textBoxVolumeLibrary.Text = line
|
|||
|
|
elif count == 3:
|
|||
|
|
self.textBoxScDocxPath.Text = line
|
|||
|
|
elif count == 4:
|
|||
|
|
sim_type = line.split()[0]
|
|||
|
|
self.radio_btn_cpu.Checked = (sim_type == "CPU")
|
|||
|
|
self.radio_btn_gpu.Checked = (sim_type == "GPU")
|
|||
|
|
|
|||
|
|
# <20><><EFBFBD>ӿؼ<D3BF>
|
|||
|
|
self.Controls.Add(self.labelSurfaceLibrary)
|
|||
|
|
self.Controls.Add(self.textBoxSurfaceLibrary)
|
|||
|
|
self.Controls.Add(self.btnChooseSurfacePath)
|
|||
|
|
self.Controls.Add(self.labelVolumeLibrary)
|
|||
|
|
self.Controls.Add(self.textBoxVolumeLibrary)
|
|||
|
|
self.Controls.Add(self.btnChooseVolumePath)
|
|||
|
|
self.Controls.Add(self.labelScDocxPath)
|
|||
|
|
self.Controls.Add(self.textBoxScDocxPath)
|
|||
|
|
self.Controls.Add(self.btnChooseScDocxPath)
|
|||
|
|
self.Controls.Add(self.btnCompute)
|
|||
|
|
self.Controls.Add(self.labelInfo)
|
|||
|
|
self.Controls.Add(self.groupBox)
|
|||
|
|
self.Controls.Add(self.label_pause)
|
|||
|
|
self.Controls.Add(self.checkbox_pause)
|
|||
|
|
self.groupBox.Controls.Add(self.radio_btn_cpu)
|
|||
|
|
self.groupBox.Controls.Add(self.radio_btn_gpu)
|
|||
|
|
|
|||
|
|
def setSurfacePath(self, sender, event):
|
|||
|
|
dialog = FolderBrowserDialog()
|
|||
|
|
if dialog.ShowDialog() == DialogResult.OK:
|
|||
|
|
self.textBoxSurfaceLibrary.Text = dialog.SelectedPath
|
|||
|
|
|
|||
|
|
def setVolumePath(self, sender, event):
|
|||
|
|
dialog = FolderBrowserDialog()
|
|||
|
|
if dialog.ShowDialog() == DialogResult.OK:
|
|||
|
|
self.textBoxVolumeLibrary.Text = dialog.SelectedPath
|
|||
|
|
|
|||
|
|
def setScDocxPath(self, sender, event):
|
|||
|
|
dialog = OpenFileDialog()
|
|||
|
|
dialog.Filter = "scdocx files (*.scdocx)|*.scdocx"
|
|||
|
|
if dialog.ShowDialog() == DialogResult.OK:
|
|||
|
|
self.textBoxScDocxPath.Text = dialog.FileName
|
|||
|
|
|
|||
|
|
def compute(self, sender, event):
|
|||
|
|
try:
|
|||
|
|
self.labelInfo.Text = "<EFBFBD><EFBFBD>ʼִ<EFBFBD>з<EFBFBD><EFBFBD><EFBFBD>"
|
|||
|
|
self.computeAll()
|
|||
|
|
except Exception as e:
|
|||
|
|
self.handleError("ִ<EFBFBD>з<EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", e)
|
|||
|
|
|
|||
|
|
def computeAll(self):
|
|||
|
|
selectedSim = Selection.GetActive()
|
|||
|
|
if selectedSim == None or len(selectedSim.Items) != 1:
|
|||
|
|
MessageBox.Show("<EFBFBD><EFBFBD>ѡ<EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD>simulation", "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>", MessageBoxButtons.OK)
|
|||
|
|
return
|
|||
|
|
|
|||
|
|
# д<><D0B4>·<EFBFBD><C2B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
|
|||
|
|
with open(self.configFile, "w") as f:
|
|||
|
|
f.write(self.textBoxSurfaceLibrary.Text + "\n")
|
|||
|
|
f.write(self.textBoxVolumeLibrary.Text + "\n")
|
|||
|
|
f.write(self.textBoxScDocxPath.Text + "\n")
|
|||
|
|
# д<><D0B4>CPU/GPU<50><55><EFBFBD><EFBFBD>
|
|||
|
|
if self.radio_btn_cpu.Checked:
|
|||
|
|
f.write(self.radio_btn_cpu.Text + " Compute" + "\n")
|
|||
|
|
else:
|
|||
|
|
f.write(self.radio_btn_gpu.Text + " Compute" + "\n")
|
|||
|
|
|
|||
|
|
# <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD>
|
|||
|
|
surfaceList = []
|
|||
|
|
if os.path.isdir(self.textBoxSurfaceLibrary.Text):
|
|||
|
|
surfaceList = getFiles(self.textBoxSurfaceLibrary.Text, [
|
|||
|
|
".simplescattering",
|
|||
|
|
".scattering",
|
|||
|
|
".brdf",
|
|||
|
|
".bsdf",
|
|||
|
|
".bsdf180",
|
|||
|
|
".coated",
|
|||
|
|
".mirror",
|
|||
|
|
".doe",
|
|||
|
|
".fluorescent",
|
|||
|
|
".grating",
|
|||
|
|
".retroreflecting",
|
|||
|
|
".anisotropic",
|
|||
|
|
".polarizer",
|
|||
|
|
".anisotropicbsdf",
|
|||
|
|
".unpolished"
|
|||
|
|
])
|
|||
|
|
else:
|
|||
|
|
print("δ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> Surface ·<><C2B7>!")
|
|||
|
|
|
|||
|
|
# <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD>
|
|||
|
|
volumeList = []
|
|||
|
|
if os.path.isdir(self.textBoxVolumeLibrary.Text):
|
|||
|
|
volumeList = getFiles(self.textBoxVolumeLibrary.Text, [
|
|||
|
|
".material"])
|
|||
|
|
else:
|
|||
|
|
print("δ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> Volume ·<><C2B7>!")
|
|||
|
|
|
|||
|
|
if len(surfaceList) == 0 and len(volumeList) == 0:
|
|||
|
|
MessageBox.Show("û<EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD><EFBFBD>κβ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD>ȷ<EFBFBD><EFBFBD>", "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>", MessageBoxButtons.OK)
|
|||
|
|
return
|
|||
|
|
|
|||
|
|
if os.path.isfile(self.textBoxScDocxPath.Text) == False:
|
|||
|
|
MessageBox.Show("û<EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD> scdocx <20>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><C2B7><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD>ȷ<EFBFBD><C8B7>", "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>", MessageBoxButtons.OK)
|
|||
|
|
return
|
|||
|
|
|
|||
|
|
line = self.textBoxScDocxPath.Text
|
|||
|
|
baseName = os.path.basename(line)
|
|||
|
|
theDir = os.path.dirname(line)
|
|||
|
|
projectName = os.path.splitext(baseName)[0]
|
|||
|
|
self.outPath = os.path.join(theDir,"SPEOS output files", projectName)
|
|||
|
|
|
|||
|
|
try:
|
|||
|
|
material = SpeosSim.Material.Find("MAINMATERIAL")
|
|||
|
|
except Exception as e:
|
|||
|
|
self.handleError("δ<EFBFBD>ҵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>쳣", e)
|
|||
|
|
MessageBox.Show("<EFBFBD>뽫<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD>MAINMATERIAL", "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>", MessageBoxButtons.OK)
|
|||
|
|
return
|
|||
|
|
|
|||
|
|
self.computeSurface(selectedSim, material, surfaceList)
|
|||
|
|
self.computeVolume(selectedSim, material, volumeList)
|
|||
|
|
|
|||
|
|
MessageBox.Show("ִ<EFBFBD>н<EFBFBD><EFBFBD><EFBFBD>!", "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>", MessageBoxButtons.OK)
|
|||
|
|
self.labelInfo.Text = ""
|
|||
|
|
|
|||
|
|
#
|
|||
|
|
def computeSurface(self, selectedSim, material, surfaceList = []):
|
|||
|
|
if len(surfaceList) == 0:
|
|||
|
|
return False
|
|||
|
|
|
|||
|
|
if self.checkbox_pause.Checked and self.stop_sim == True:
|
|||
|
|
return False
|
|||
|
|
|
|||
|
|
# <20><><EFBFBD><EFBFBD> material <20><><EFBFBD><EFBFBD>
|
|||
|
|
material.VOPType = SpeosSim.Material.EnumVOPType.Opaque
|
|||
|
|
material.SOPType = SpeosSim.Material.EnumSOPType.Library
|
|||
|
|
|
|||
|
|
for surfacePath in surfaceList:
|
|||
|
|
self.labelInfo.Text = "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD>ã<EFBFBD>" + surfacePath
|
|||
|
|
material.SOPLibrary = surfacePath
|
|||
|
|
|
|||
|
|
if not self.compute_and_check(selectedSim):
|
|||
|
|
# <20><>ֹ<EFBFBD><D6B9><EFBFBD><EFBFBD>
|
|||
|
|
self.stop_sim = True
|
|||
|
|
break
|
|||
|
|
|
|||
|
|
#SpeosSim.Command.ComputeOnActiveSelection()
|
|||
|
|
|
|||
|
|
baseName = os.path.basename(surfacePath)
|
|||
|
|
imageName = os.path.splitext(baseName)[0] + ".png"
|
|||
|
|
surfaceDir = os.path.dirname(surfacePath)
|
|||
|
|
fullImageName = os.path.join(surfaceDir, imageName)
|
|||
|
|
|
|||
|
|
# <20><><EFBFBD><EFBFBD>ͼƬ
|
|||
|
|
if self.exportImage(fullImageName) == False:
|
|||
|
|
self.labelInfo.Text = "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼƬʧ<EFBFBD><EFBFBD>:" + fullImageName
|
|||
|
|
return False
|
|||
|
|
|
|||
|
|
return True
|
|||
|
|
|
|||
|
|
#
|
|||
|
|
def computeVolume(self, selectedSim, material, volumeList = []):
|
|||
|
|
if len(volumeList) == 0:
|
|||
|
|
return False
|
|||
|
|
|
|||
|
|
if self.checkbox_pause.Checked and self.stop_sim == True:
|
|||
|
|
return False
|
|||
|
|
|
|||
|
|
# <20><><EFBFBD><EFBFBD> material <20><><EFBFBD><EFBFBD>
|
|||
|
|
material.VOPType = SpeosSim.Material.EnumVOPType.Library
|
|||
|
|
material.SOPType = SpeosSim.Material.EnumSOPType.OpticalPolished
|
|||
|
|
|
|||
|
|
for volumePath in volumeList:
|
|||
|
|
self.labelInfo.Text = "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD>ã<EFBFBD>" + volumePath
|
|||
|
|
material.VOPLibrary = volumePath
|
|||
|
|
|
|||
|
|
if not self.compute_and_check(selectedSim):
|
|||
|
|
# <20><>ֹ<EFBFBD><D6B9><EFBFBD><EFBFBD>
|
|||
|
|
self.stop_sim = True
|
|||
|
|
break
|
|||
|
|
|
|||
|
|
#SpeosSim.Command.ComputeOnActiveSelection()
|
|||
|
|
|
|||
|
|
baseName = os.path.basename(volumePath)
|
|||
|
|
imageName = os.path.splitext(baseName)[0] + ".png"
|
|||
|
|
volumeDir = os.path.dirname(volumePath)
|
|||
|
|
fullImageName = os.path.join(volumeDir, imageName)
|
|||
|
|
|
|||
|
|
# <20><><EFBFBD><EFBFBD>ͼƬ
|
|||
|
|
if self.exportImage(fullImageName) == False:
|
|||
|
|
self.labelInfo.Text = "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼƬʧ<EFBFBD><EFBFBD>:" + fullImageName
|
|||
|
|
return False
|
|||
|
|
return True
|
|||
|
|
|
|||
|
|
def compute_and_check(self, selectedSim):
|
|||
|
|
# ִ<>з<EFBFBD><D0B7><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>ɾ<EFBFBD><C9BE>Ŀ¼<C4BF>е<EFBFBD>xmp<6D>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڣ<EFBFBD>
|
|||
|
|
if self.checkbox_pause.Checked:
|
|||
|
|
try:
|
|||
|
|
if Directory.Exists(self.outPath):
|
|||
|
|
files = Directory.GetFiles(self.outPath)
|
|||
|
|
for file_path in files:
|
|||
|
|
try:
|
|||
|
|
File.Delete(file_path)
|
|||
|
|
except Exception as e:
|
|||
|
|
print("<EFBFBD><EFBFBD>ɾ<EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD> {0}: {1}".format(str(file_path), str(e)))
|
|||
|
|
else:
|
|||
|
|
print("Ŀ¼ {0} <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>".format(str(self.outPath)))
|
|||
|
|
except Exception as e:
|
|||
|
|
self.handleError("ɾ<EFBFBD><EFBFBD>xmp<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", e)
|
|||
|
|
|
|||
|
|
# ִ<><D6B4> <20><><EFBFBD><EFBFBD>
|
|||
|
|
if self.radio_btn_cpu.Checked:
|
|||
|
|
SpeosSim.Command.Compute(selectedSim.Items)
|
|||
|
|
else:
|
|||
|
|
SpeosSim.Command.GpuCompute(selectedSim.Items)
|
|||
|
|
print("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>")
|
|||
|
|
|
|||
|
|
# ִ<>з<EFBFBD><D0B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF>Ŀ¼<C4BF>в<EFBFBD><D0B2><EFBFBD><EFBFBD><EFBFBD>xmp<6D>ļ<EFBFBD>
|
|||
|
|
# <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ <20><><EFBFBD>ִ<EFBFBD><D6B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD>ֹ
|
|||
|
|
if self.checkbox_pause.Checked:
|
|||
|
|
if Directory.Exists(self.outPath):
|
|||
|
|
files = Directory.GetFiles(self.outPath, "*.xmp")
|
|||
|
|
if not files:
|
|||
|
|
print("<EFBFBD><EFBFBD>Ŀ¼ {0} <20><>û<EFBFBD><C3BB><EFBFBD>ҵ<EFBFBD><D2B5><EFBFBD> .xmp Ϊ<><CEAA><EFBFBD><D7BA><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>".format(str(self.outPath)))
|
|||
|
|
return False
|
|||
|
|
else:
|
|||
|
|
print("Ŀ¼ {0} <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>".format(str(self.outPath)))
|
|||
|
|
return False
|
|||
|
|
|
|||
|
|
return True
|
|||
|
|
|
|||
|
|
def exportImage(self, imageName):
|
|||
|
|
theFile =""
|
|||
|
|
for file in os.listdir(self.outPath):
|
|||
|
|
if file.endswith(".xmp"):
|
|||
|
|
theFile = os.path.join(self.outPath, file)
|
|||
|
|
break
|
|||
|
|
if theFile == "":
|
|||
|
|
print("û<EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD> xmp <20>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><C2B7><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD>ȷ<EFBFBD><C8B7> '" + theFile + "'")
|
|||
|
|
#MessageBox.Show("û<><C3BB><EFBFBD>ҵ<EFBFBD> xmp <20>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><C2B7><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD>ȷ<EFBFBD><C8B7>", "<22><><EFBFBD><EFBFBD>", MessageBoxButtons.OK)
|
|||
|
|
return False
|
|||
|
|
|
|||
|
|
self.labelInfo.Text = "<EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>" + imageName
|
|||
|
|
print("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼƬ: '" + imageName + "'")
|
|||
|
|
|
|||
|
|
# ʹ<><CAB9>Virtual Huamn Vision Lab<61><62><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɵ<EFBFBD>xmp
|
|||
|
|
try:
|
|||
|
|
if self.XmpViewer.OpenFile(theFile) != 1:
|
|||
|
|
print("XmpViewer <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD>" )
|
|||
|
|
return False
|
|||
|
|
except Exception as e:
|
|||
|
|
self.handleError("<EFBFBD><EFBFBD>ʹ<EFBFBD><EFBFBD>Virtual Huamn Vision Lab<61><62><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD>쳣", e)
|
|||
|
|
|
|||
|
|
# <20><>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼƬ<CDBC><C6AC><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>
|
|||
|
|
# <20>ڶ<EFBFBD><DAB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ ͼ<>θ<EFBFBD>ʽ(0: BMP, 1: PNG, 2 :TIFF, 3: JPG)
|
|||
|
|
if self.XmpViewer.ExportXMPImage(imageName, 1) == 0:
|
|||
|
|
print("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼƬʧ<EFBFBD><EFBFBD>! '" + imageName + "'")
|
|||
|
|
#MessageBox.Show("<22><><EFBFBD><EFBFBD>ͼƬʧ<C6AC><CAA7>", "<22><><EFBFBD><EFBFBD>", MessageBoxButtons.OK)
|
|||
|
|
return False
|
|||
|
|
print("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼƬ<EFBFBD>ɹ<EFBFBD>!")
|
|||
|
|
return True
|
|||
|
|
|
|||
|
|
# <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
def handleError(self, message, exception):
|
|||
|
|
error_message = "{0}\n\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>飺{1}".format(message, str(exception))
|
|||
|
|
MessageBox.Show(error_message, "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>", MessageBoxButtons.OK)
|
|||
|
|
self.labelInfo.Text = error_message
|
|||
|
|
# <20><>¼<EFBFBD><C2BC>־
|
|||
|
|
log_file_path = self.errorlogFile
|
|||
|
|
# д<><D0B4><EFBFBD><EFBFBD>־<EFBFBD>ļ<EFBFBD>
|
|||
|
|
with open(log_file_path, "w") as f:
|
|||
|
|
f.write("{0}\n{1}\n\n".format(message, traceback.format_exc()))
|
|||
|
|
|
|||
|
|
|
|||
|
|
def getFiles(path, suffixs = []):
|
|||
|
|
fileList = []
|
|||
|
|
|
|||
|
|
if len(suffixs) == 0:
|
|||
|
|
for root, dirs, files in os.walk(path):
|
|||
|
|
for file in files:
|
|||
|
|
fileList.append(os.path.join(root, file))
|
|||
|
|
else:
|
|||
|
|
for root, dirs, files in os.walk(path):
|
|||
|
|
for file in files:
|
|||
|
|
suffix = os.path.splitext(file)[1].lower()
|
|||
|
|
|
|||
|
|
if suffix not in suffixs:
|
|||
|
|
continue
|
|||
|
|
|
|||
|
|
fileList.append(os.path.join(root, file))
|
|||
|
|
|
|||
|
|
return fileList
|
|||
|
|
|
|||
|
|
|
|||
|
|
def main():
|
|||
|
|
try:
|
|||
|
|
app = MainForm()
|
|||
|
|
|
|||
|
|
# <20><>ģ̬
|
|||
|
|
app.Show()
|
|||
|
|
# ģ̬
|
|||
|
|
#app.ShowDialog()
|
|||
|
|
except Exception as e:
|
|||
|
|
print(e.ToString())
|
|||
|
|
|
|||
|
|
main()
|