From: daid Date: Tue, 27 Aug 2013 09:08:37 +0000 (+0200) Subject: Upload design files with mesh files when uploading to YouMagine. X-Git-Tag: 13.10~86 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=16e9098790cfbf598da2327f7a22d07e3778969f;p=cura.git Upload design files with mesh files when uploading to YouMagine. --- diff --git a/Cura/gui/sceneView.py b/Cura/gui/sceneView.py index d9296000..cc3bbe4b 100644 --- a/Cura/gui/sceneView.py +++ b/Cura/gui/sceneView.py @@ -105,7 +105,6 @@ class SceneView(openglGui.glGuiPanel): self.youMagineButton = openglGui.glButton(self, 26, 'YouMagine upload', (2,0), lambda button: youmagineGui.youmagineManager(self.GetTopLevelParent(), self._scene)) self.youMagineButton.setDisabled(True) - self.youMagineButton.setHidden(True) self.notification = openglGui.glNotification(self, (0, 0)) diff --git a/Cura/gui/tools/minecraftImport.py b/Cura/gui/tools/minecraftImport.py index 95d0c5e5..8de17012 100644 --- a/Cura/gui/tools/minecraftImport.py +++ b/Cura/gui/tools/minecraftImport.py @@ -213,7 +213,7 @@ class minecraftImportWindow(wx.Frame): if y == sy - 1 or not self.isSolid[blocks[x, y + 1, z]]: faceCount += 1 - obj = mesh.printableObject("minecraft") + obj = mesh.printableObject(None) m = obj._addMesh() m._prepareFaceCount(faceCount * 2) for x in xrange(0, sx): diff --git a/Cura/gui/tools/youmagineGui.py b/Cura/gui/tools/youmagineGui.py index f7d60ce8..b027540e 100644 --- a/Cura/gui/tools/youmagineGui.py +++ b/Cura/gui/tools/youmagineGui.py @@ -18,6 +18,8 @@ from Cura.util.resources import getPathForImage from Cura.gui.util import webcam +DESIGN_FILE_EXT = ['.scad', '.blend', '.max', '.stp', '.step', '.igs', '.iges', '.sldasm', '.sldprt', '.skp', '.ipt', '.dwg', '.123d', '.wings'] + def getClipboardText(): ret = '' try: @@ -31,6 +33,30 @@ def getClipboardText(): except: return ret +def getAdditionalFiles(objects, onlyExtChanged): + names = set() + for obj in objects: + name = obj.getOriginFilename() + if name is None: + continue + names.add(name[:name.rfind('.')]) + ret = [] + for name in names: + for ext in DESIGN_FILE_EXT: + if os.path.isfile(name + ext): + ret.append(name + ext) + if onlyExtChanged: + return ret + onlyExtList = ret + ret = [] + for name in names: + for ext in DESIGN_FILE_EXT: + for filename in os.listdir(os.path.dirname(name)): + filename = os.path.join(os.path.dirname(name), filename) + if filename.endswith(ext) and filename not in ret and filename not in onlyExtList: + ret.append(filename) + return ret + class youmagineManager(object): def __init__(self, parent, objectScene): self._mainWindow = parent @@ -77,12 +103,12 @@ class youmagineManager(object): #TODO: Would you like to create a new design or add the model to an existing design? wx.CallAfter(self._newDesignWindow.Show) - def createNewDesign(self, name, description, category, license, imageList, publish): - thread = threading.Thread(target=self.createNewDesignThread, args=(name, description, category, license, imageList, publish)) + def createNewDesign(self, name, description, category, license, imageList, extraFileList, publish): + thread = threading.Thread(target=self.createNewDesignThread, args=(name, description, category, license, imageList, extraFileList, publish)) thread.daemon = True thread.start() - def createNewDesignThread(self, name, description, category, license, imageList, publish): + def createNewDesignThread(self, name, description, category, license, imageList, extraFileList, publish): wx.CallAfter(self._indicatorWindow.showBusy, 'Creating new design on YouMagine...') id = self._ym.createDesign(name, description, category, license) wx.CallAfter(self._indicatorWindow.Hide) @@ -107,6 +133,12 @@ class youmagineManager(object): wx.MessageBox('Failed to upload %s!' % (filename), 'YouMagine error.', wx.OK | wx.ICON_ERROR) s.close() + for extra in extraFileList: + wx.CallAfter(self._indicatorWindow.showBusy, 'Uploading file %s...' % (os.path.basename(extra))) + with open(extra, "rb") as f: + if self._ym.createDocument(id, os.path.basename(extra), f.read()) is None: + wx.MessageBox('Failed to upload %s!' % (os.path.basename(extra)), 'YouMagine error.', wx.OK | wx.ICON_ERROR) + for image in imageList: if type(image) in types.StringTypes: filename = os.path.basename(image) @@ -126,6 +158,7 @@ class youmagineManager(object): wx.CallAfter(self._indicatorWindow.showBusy, 'Publishing design...') self._ym.publishDesign(id) wx.CallAfter(self._indicatorWindow.Hide) + webbrowser.open(self._ym.viewUrlForDesign(id)) @@ -232,25 +265,26 @@ class newDesignWindow(wx.Frame): self.GetSizer().Add(p, 1, wx.EXPAND) self._manager = manager self._ym = ym - self._cam = webcam.webcam() categoryOptions = ym.getCategories() licenseOptions = ym.getLicenses() self._designName = wx.TextCtrl(p, -1, 'Design name') - self._designDescription = wx.TextCtrl(p, -1, '', size=(1, 150), style = wx.TE_MULTILINE|wx.TE_PROCESS_TAB) + self._designDescription = wx.TextCtrl(p, -1, '', size=(1, 150), style = wx.TE_MULTILINE) self._designLicense = wx.ComboBox(p, -1, licenseOptions[0], choices=licenseOptions, style=wx.CB_DROPDOWN|wx.CB_READONLY) self._category = wx.ComboBox(p, -1, categoryOptions[-1], choices=categoryOptions, style=wx.CB_DROPDOWN|wx.CB_READONLY) self._publish = wx.CheckBox(p, -1, 'Publish after upload') self._shareButton = wx.Button(p, -1, 'Upload') self._imageScroll = wx.lib.scrolledpanel.ScrolledPanel(p) + self._additionalFiles = wx.CheckListBox(p, -1) + self._additionalFiles.InsertItems(getAdditionalFiles(self._manager._scene.objects(), True), 0) + self._additionalFiles.SetChecked(range(0, self._additionalFiles.GetCount())) + self._additionalFiles.InsertItems(getAdditionalFiles(self._manager._scene.objects(), False), self._additionalFiles.GetCount()) self._imageScroll.SetSizer(wx.BoxSizer(wx.HORIZONTAL)) self._addImageButton = wx.Button(self._imageScroll, -1, 'Add...', size=(70,52)) self._imageScroll.GetSizer().Add(self._addImageButton) - self._snapshotButton = wx.Button(self._imageScroll, -1, 'Take...', size=(70,52)) + self._snapshotButton = wx.Button(self._imageScroll, -1, 'Webcam...', size=(70,52)) self._imageScroll.GetSizer().Add(self._snapshotButton) - if not self._cam.hasCamera(): - self._snapshotButton.Hide() self._imageScroll.Fit() self._imageScroll.SetupScrolling(scroll_x=True, scroll_y=False) self._imageScroll.SetMinSize((20, self._imageScroll.GetSize()[1] + wx.SystemSettings_GetMetric(wx.SYS_HSCROLL_Y))) @@ -274,8 +308,11 @@ class newDesignWindow(wx.Frame): s.Add(wx.StaticText(p, -1, 'Images:'), (6, 0), flag=wx.LEFT|wx.TOP, border=5) s.Add(self._imageScroll, (6, 1), span=(1, 2), flag=wx.EXPAND|wx.LEFT|wx.TOP|wx.RIGHT, border=5) s.Add(wx.StaticLine(p, -1), (7,0), span=(1,3), flag=wx.EXPAND|wx.ALL) - s.Add(self._shareButton, (8, 1), flag=wx.BOTTOM, border=15) - s.Add(self._publish, (8, 2), flag=wx.BOTTOM|wx.ALIGN_CENTER_VERTICAL, border=15) + s.Add(wx.StaticText(p, -1, 'Design files:'), (8, 0), flag=wx.LEFT|wx.TOP, border=5) + s.Add(self._additionalFiles, (8, 1), span=(1, 2), flag=wx.EXPAND|wx.LEFT|wx.TOP|wx.RIGHT, border=5) + s.Add(wx.StaticLine(p, -1), (9,0), span=(1,3), flag=wx.EXPAND|wx.ALL) + s.Add(self._shareButton, (10, 1), flag=wx.BOTTOM, border=15) + s.Add(self._publish, (10, 2), flag=wx.BOTTOM|wx.ALIGN_CENTER_VERTICAL, border=15) s.AddGrowableRow(2) s.AddGrowableCol(2) @@ -306,7 +343,7 @@ class newDesignWindow(wx.Frame): imageList.append(child.imageFilename) if hasattr(child, 'imageData'): imageList.append(child.imageData) - self._manager.createNewDesign(self._designName.GetValue(), self._designDescription.GetValue(), self._category.GetValue(), self._designLicense.GetValue(), imageList, self._publish.GetValue()) + self._manager.createNewDesign(self._designName.GetValue(), self._designDescription.GetValue(), self._category.GetValue(), self._designLicense.GetValue(), imageList, self._additionalFiles.GetCheckedStrings(), self._publish.GetValue()) self.Destroy() def OnAddImage(self, e): @@ -318,7 +355,7 @@ class newDesignWindow(wx.Frame): dlg.Destroy() def OnTakeImage(self, e): - webcamPhotoWindow(self, self._cam).Show() + webcamPhotoWindow(self).Show() def _addImage(self, image): wxImage = None @@ -365,14 +402,14 @@ class newDesignWindow(wx.Frame): self._imageScroll.SetupScrolling(scroll_x=True, scroll_y=False) class webcamPhotoWindow(wx.Frame): - def __init__(self, parent, cam): + def __init__(self, parent): super(webcamPhotoWindow, self).__init__(parent, title='YouMagine') p = wx.Panel(self) self.panel = p self.SetSizer(wx.BoxSizer()) self.GetSizer().Add(p, 1, wx.EXPAND) - self._cam = cam + self._cam = webcam.webcam() self._cam.takeNewImage(False) s = wx.GridBagSizer(3, 3) @@ -383,9 +420,9 @@ class webcamPhotoWindow(wx.Frame): self._takeImageButton = wx.Button(p, -1, 'Snap image') self._takeImageTimer = wx.Timer(self) - s.Add(self._takeImageButton, pos=(1, 0)) - s.Add(self._cameraSelect, pos=(1, 1)) - s.Add(self._preview, pos=(0, 0), span=(1, 2), flag=wx.EXPAND) + s.Add(self._takeImageButton, pos=(1, 0), flag=wx.ALL, border=5) + s.Add(self._cameraSelect, pos=(1, 1), flag=wx.ALL, border=5) + s.Add(self._preview, pos=(0, 0), span=(1, 2), flag=wx.EXPAND|wx.ALL, border=5) if self._cam.getLastImage() is not None: self._preview.SetMinSize((self._cam.getLastImage().GetWidth(), self._cam.getLastImage().GetHeight())) diff --git a/Cura/util/mesh.py b/Cura/util/mesh.py index c0910988..7067ed77 100644 --- a/Cura/util/mesh.py +++ b/Cura/util/mesh.py @@ -3,13 +3,18 @@ __copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AG import time import math +import os import numpy numpy.seterr(all='ignore') class printableObject(object): - def __init__(self, name): - self._name = name + def __init__(self, originFilename): + self._originFilename = originFilename + if originFilename is None: + self._name = 'None' + else: + self._name = os.path.basename(originFilename) if '.' in self._name: self._name = self._name[0:self._name.rfind('.')] self._meshList = [] @@ -23,7 +28,7 @@ class printableObject(object): self._loadAnim = None def copy(self): - ret = printableObject(self._name) + ret = printableObject(self._originFilename) ret._matrix = self._matrix.copy() ret._transformedMin = self._transformedMin.copy() ret._transformedMax = self._transformedMin.copy() @@ -78,6 +83,8 @@ class printableObject(object): def getName(self): return self._name + def getOriginFilename(self): + return self._originFilename def getPosition(self): return self._position def setPosition(self, newPos): @@ -340,7 +347,7 @@ class mesh(object): doneSet.add(i) todoList.append(i) - obj = printableObject(self._obj._name) + obj = printableObject(self._obj.getOriginFilename()) obj._matrix = self._obj._matrix.copy() m = obj._addMesh() m._prepareFaceCount(len(meshFaceList)) diff --git a/Cura/util/meshLoaders/amf.py b/Cura/util/meshLoaders/amf.py index 9030536d..f577c90a 100644 --- a/Cura/util/meshLoaders/amf.py +++ b/Cura/util/meshLoaders/amf.py @@ -42,7 +42,7 @@ def loadScene(filename): ret = [] for amfObj in amf.iter('object'): - obj = mesh.printableObject(os.path.basename(filename)) + obj = mesh.printableObject(filename) for amfMesh in amfObj.iter('mesh'): vertexList = [] for vertices in amfMesh.iter('vertices'): diff --git a/Cura/util/meshLoaders/dae.py b/Cura/util/meshLoaders/dae.py index 6a01efa4..9e33c4da 100644 --- a/Cura/util/meshLoaders/dae.py +++ b/Cura/util/meshLoaders/dae.py @@ -12,7 +12,7 @@ def loadScene(filename): class daeLoader(object): def __init__(self, filename): - self.obj = mesh.printableObject(os.path.basename(filename)) + self.obj = mesh.printableObject(filename) self.mesh = self.obj._addMesh() r = ParserCreate() diff --git a/Cura/util/meshLoaders/obj.py b/Cura/util/meshLoaders/obj.py index d872583a..bb5ef292 100644 --- a/Cura/util/meshLoaders/obj.py +++ b/Cura/util/meshLoaders/obj.py @@ -5,7 +5,7 @@ import os from Cura.util import mesh def loadScene(filename): - obj = mesh.printableObject(os.path.basename(filename)) + obj = mesh.printableObject(filename) m = obj._addMesh() vertexList = [] diff --git a/Cura/util/meshLoaders/stl.py b/Cura/util/meshLoaders/stl.py index 1150c1d1..76c53b72 100644 --- a/Cura/util/meshLoaders/stl.py +++ b/Cura/util/meshLoaders/stl.py @@ -37,7 +37,7 @@ def _loadBinary(m, f): m._addFace(data[3], data[4], data[5], data[6], data[7], data[8], data[9], data[10], data[11]) def loadScene(filename): - obj = mesh.printableObject(os.path.basename(filename)) + obj = mesh.printableObject(filename) m = obj._addMesh() f = open(filename, "rb") diff --git a/Cura/util/youmagine.py b/Cura/util/youmagine.py index ba1c2ca4..935aae1a 100644 --- a/Cura/util/youmagine.py +++ b/Cura/util/youmagine.py @@ -112,7 +112,6 @@ class Youmagine(object): def publishDesign(self, id): res = self._request('PUT', '/designs/%d/mark_as/publish.json' % (id), {'ignore': 'me'}) if res is not None: - print res return False return True