Fix resources, imports and indentations.
parent
132e6381ea
commit
377ea03c15
30
Cura/cura.py
30
Cura/cura.py
|
@ -9,10 +9,7 @@ The slicing code is the same as Skeinforge. But the UI has been revamped to be..
|
||||||
|
|
||||||
"""
|
"""
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
import __init__
|
|
||||||
|
|
||||||
import sys
|
|
||||||
import platform
|
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
|
|
||||||
from util import profile
|
from util import profile
|
||||||
|
@ -36,6 +33,7 @@ Reece.Arnott <http://forums.reprap.org/profile.php?12,152>
|
||||||
Wade <http://forums.reprap.org/profile.php?12,489>
|
Wade <http://forums.reprap.org/profile.php?12,489>
|
||||||
Xsainnz <http://forums.reprap.org/profile.php?12,563>
|
Xsainnz <http://forums.reprap.org/profile.php?12,563>
|
||||||
Zach Hoeken <http://blog.zachhoeken.com/>
|
Zach Hoeken <http://blog.zachhoeken.com/>
|
||||||
|
Ilya Kulakov (kulakov.ilya@gmail.com)
|
||||||
|
|
||||||
Organizations:
|
Organizations:
|
||||||
Ultimaker <http://www.ultimaker.com>
|
Ultimaker <http://www.ultimaker.com>
|
||||||
|
@ -45,12 +43,18 @@ __license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agp
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
parser = OptionParser(usage="usage: %prog [options] <filename>.stl")
|
parser = OptionParser(usage="usage: %prog [options] <filename>.stl")
|
||||||
parser.add_option("-i", "--ini", action="store", type="string", dest="profileini", help="Load settings from a profile ini file")
|
parser.add_option("-i", "--ini", action="store", type="string", dest="profileini",
|
||||||
parser.add_option("-P", "--project", action="store_true", dest="openprojectplanner", help="Open the project planner")
|
help="Load settings from a profile ini file")
|
||||||
parser.add_option("-F", "--flat", action="store_true", dest="openflatslicer", help="Open the 2D SVG slicer (unfinished)")
|
parser.add_option("-P", "--project", action="store_true", dest="openprojectplanner",
|
||||||
parser.add_option("-r", "--print", action="store", type="string", dest="printfile", help="Open the printing interface, instead of the normal cura interface.")
|
help="Open the project planner")
|
||||||
parser.add_option("-p", "--profile", action="store", type="string", dest="profile", help="Internal option, do not use!")
|
parser.add_option("-F", "--flat", action="store_true", dest="openflatslicer",
|
||||||
parser.add_option("-s", "--slice", action="store_true", dest="slice", help="Slice the given files instead of opening them in Cura")
|
help="Open the 2D SVG slicer (unfinished)")
|
||||||
|
parser.add_option("-r", "--print", action="store", type="string", dest="printfile",
|
||||||
|
help="Open the printing interface, instead of the normal cura interface.")
|
||||||
|
parser.add_option("-p", "--profile", action="store", type="string", dest="profile",
|
||||||
|
help="Internal option, do not use!")
|
||||||
|
parser.add_option("-s", "--slice", action="store_true", dest="slice",
|
||||||
|
help="Slice the given files instead of opening them in Cura")
|
||||||
(options, args) = parser.parse_args()
|
(options, args) = parser.parse_args()
|
||||||
if options.profile != None:
|
if options.profile != None:
|
||||||
profile.loadGlobalProfileFromString(options.profile)
|
profile.loadGlobalProfileFromString(options.profile)
|
||||||
|
@ -58,30 +62,36 @@ def main():
|
||||||
profile.loadGlobalProfile(options.profileini)
|
profile.loadGlobalProfile(options.profileini)
|
||||||
if options.openprojectplanner != None:
|
if options.openprojectplanner != None:
|
||||||
from gui import projectPlanner
|
from gui import projectPlanner
|
||||||
|
|
||||||
projectPlanner.main()
|
projectPlanner.main()
|
||||||
return
|
return
|
||||||
if options.openflatslicer != None:
|
if options.openflatslicer != None:
|
||||||
from gui import flatSlicerWindow
|
from gui import flatSlicerWindow
|
||||||
|
|
||||||
flatSlicerWindow.main()
|
flatSlicerWindow.main()
|
||||||
return
|
return
|
||||||
if options.printfile != None:
|
if options.printfile != None:
|
||||||
from gui import printWindow
|
from gui import printWindow
|
||||||
|
|
||||||
printWindow.startPrintInterface(options.printfile)
|
printWindow.startPrintInterface(options.printfile)
|
||||||
return
|
return
|
||||||
|
|
||||||
if options.slice != None:
|
if options.slice != None:
|
||||||
from util import sliceRun
|
from util import sliceRun
|
||||||
|
|
||||||
sliceRun.runSlice(args)
|
sliceRun.runSlice(args)
|
||||||
else:
|
else:
|
||||||
if len(args) > 0:
|
if len(args) > 0:
|
||||||
profile.putPreference('lastFile', ';'.join(args))
|
profile.putPreference('lastFile', ';'.join(args))
|
||||||
from gui import splashScreen
|
from gui import splashScreen
|
||||||
|
|
||||||
splashScreen.showSplash(mainWindowRunCallback)
|
splashScreen.showSplash(mainWindowRunCallback)
|
||||||
|
|
||||||
|
|
||||||
def mainWindowRunCallback(splash):
|
def mainWindowRunCallback(splash):
|
||||||
from gui import mainWindow
|
from gui import mainWindow
|
||||||
|
|
||||||
mainWindow.main(splash)
|
mainWindow.main(splash)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,447 +1,458 @@
|
||||||
import math, time, os
|
# coding=utf-8
|
||||||
|
from __future__ import absolute_import
|
||||||
from util import meshLoader
|
|
||||||
from util import util3d
|
import math
|
||||||
from util import profile
|
|
||||||
|
from util import meshLoader
|
||||||
try:
|
from util import util3d
|
||||||
import OpenGL
|
from util import profile
|
||||||
OpenGL.ERROR_CHECKING = False
|
from util.resources import getPathForMesh
|
||||||
from OpenGL.GLU import *
|
|
||||||
from OpenGL.GL import *
|
try:
|
||||||
hasOpenGLlibs = True
|
import OpenGL
|
||||||
except:
|
|
||||||
print "Failed to find PyOpenGL: http://pyopengl.sourceforge.net/"
|
OpenGL.ERROR_CHECKING = False
|
||||||
hasOpenGLlibs = False
|
from OpenGL.GLU import *
|
||||||
|
from OpenGL.GL import *
|
||||||
def InitGL(window, view3D, zoom):
|
|
||||||
# set viewing projection
|
hasOpenGLlibs = True
|
||||||
glMatrixMode(GL_MODELVIEW)
|
except:
|
||||||
glLoadIdentity()
|
print "Failed to find PyOpenGL: http://pyopengl.sourceforge.net/"
|
||||||
size = window.GetSize()
|
hasOpenGLlibs = False
|
||||||
glViewport(0,0, size.GetWidth(), size.GetHeight())
|
|
||||||
|
def InitGL(window, view3D, zoom):
|
||||||
glLightfv(GL_LIGHT0, GL_POSITION, [0.2, 0.2, 1.0, 0.0])
|
# set viewing projection
|
||||||
glLightfv(GL_LIGHT1, GL_POSITION, [1.0, 1.0, 1.0, 0.0])
|
glMatrixMode(GL_MODELVIEW)
|
||||||
|
glLoadIdentity()
|
||||||
glEnable(GL_RESCALE_NORMAL)
|
size = window.GetSize()
|
||||||
glEnable(GL_LIGHTING)
|
glViewport(0, 0, size.GetWidth(), size.GetHeight())
|
||||||
glEnable(GL_LIGHT0)
|
|
||||||
glEnable(GL_DEPTH_TEST)
|
glLightfv(GL_LIGHT0, GL_POSITION, [0.2, 0.2, 1.0, 0.0])
|
||||||
glEnable(GL_CULL_FACE)
|
glLightfv(GL_LIGHT1, GL_POSITION, [1.0, 1.0, 1.0, 0.0])
|
||||||
glDisable(GL_BLEND)
|
|
||||||
|
glEnable(GL_RESCALE_NORMAL)
|
||||||
glClearColor(1.0, 1.0, 1.0, 1.0)
|
glEnable(GL_LIGHTING)
|
||||||
glClearStencil(0)
|
glEnable(GL_LIGHT0)
|
||||||
glClearDepth(1.0)
|
glEnable(GL_DEPTH_TEST)
|
||||||
|
glEnable(GL_CULL_FACE)
|
||||||
glMatrixMode(GL_PROJECTION)
|
glDisable(GL_BLEND)
|
||||||
glLoadIdentity()
|
|
||||||
aspect = float(size.GetWidth()) / float(size.GetHeight())
|
glClearColor(1.0, 1.0, 1.0, 1.0)
|
||||||
if view3D:
|
glClearStencil(0)
|
||||||
gluPerspective(45.0, aspect, 1.0, 1000.0)
|
glClearDepth(1.0)
|
||||||
else:
|
|
||||||
glOrtho(-aspect * (zoom), aspect * (zoom), -1.0 * (zoom), 1.0 * (zoom), -1000.0, 1000.0)
|
glMatrixMode(GL_PROJECTION)
|
||||||
|
glLoadIdentity()
|
||||||
glMatrixMode(GL_MODELVIEW)
|
aspect = float(size.GetWidth()) / float(size.GetHeight())
|
||||||
glLoadIdentity()
|
if view3D:
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT)
|
gluPerspective(45.0, aspect, 1.0, 1000.0)
|
||||||
|
else:
|
||||||
platformMesh = None
|
glOrtho(-aspect * (zoom), aspect * (zoom), -1.0 * (zoom), 1.0 * (zoom), -1000.0, 1000.0)
|
||||||
|
|
||||||
def DrawMachine(machineSize):
|
glMatrixMode(GL_MODELVIEW)
|
||||||
if profile.getPreference('machine_type') == 'ultimaker':
|
glLoadIdentity()
|
||||||
glPushMatrix()
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT)
|
||||||
glEnable(GL_LIGHTING)
|
|
||||||
glTranslate(100,200,-5)
|
platformMesh = None
|
||||||
glLightfv(GL_LIGHT0, GL_DIFFUSE, [0.8,0.8,0.8])
|
|
||||||
glLightfv(GL_LIGHT0, GL_AMBIENT, [0.5,0.5,0.5])
|
def DrawMachine(machineSize):
|
||||||
glEnable(GL_BLEND)
|
if profile.getPreference('machine_type') == 'ultimaker':
|
||||||
glBlendFunc(GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR)
|
glPushMatrix()
|
||||||
|
glEnable(GL_LIGHTING)
|
||||||
global platformMesh
|
glTranslate(100, 200, -5)
|
||||||
if platformMesh == None:
|
glLightfv(GL_LIGHT0, GL_DIFFUSE, [0.8, 0.8, 0.8])
|
||||||
platformMesh = meshLoader.loadMesh(os.path.normpath(os.path.join(os.path.split(__file__)[0], "../images", 'ultimaker_platform.stl')))
|
glLightfv(GL_LIGHT0, GL_AMBIENT, [0.5, 0.5, 0.5])
|
||||||
platformMesh.setRotateMirror(0, False, False, False, False, False)
|
glEnable(GL_BLEND)
|
||||||
|
glBlendFunc(GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR)
|
||||||
DrawMesh(platformMesh)
|
|
||||||
glPopMatrix()
|
global platformMesh
|
||||||
|
if platformMesh == None:
|
||||||
glDisable(GL_LIGHTING)
|
platformMesh = meshLoader.loadMesh(getPathForMesh('ultimaker_platform.stl'))
|
||||||
if False:
|
platformMesh.setRotateMirror(0, False, False, False, False, False)
|
||||||
glColor3f(0.7,0.7,0.7)
|
|
||||||
glLineWidth(2)
|
DrawMesh(platformMesh)
|
||||||
glBegin(GL_LINES)
|
glPopMatrix()
|
||||||
for i in xrange(0, int(machineSize.x), 10):
|
|
||||||
glVertex3f(i, 0, 0)
|
glDisable(GL_LIGHTING)
|
||||||
glVertex3f(i, machineSize.y, 0)
|
if False:
|
||||||
for i in xrange(0, int(machineSize.y), 10):
|
glColor3f(0.7, 0.7, 0.7)
|
||||||
glVertex3f(0, i, 0)
|
glLineWidth(2)
|
||||||
glVertex3f(machineSize.x, i, 0)
|
glBegin(GL_LINES)
|
||||||
glEnd()
|
for i in xrange(0, int(machineSize.x), 10):
|
||||||
|
glVertex3f(i, 0, 0)
|
||||||
glEnable(GL_LINE_SMOOTH)
|
glVertex3f(i, machineSize.y, 0)
|
||||||
glEnable(GL_BLEND)
|
for i in xrange(0, int(machineSize.y), 10):
|
||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
|
glVertex3f(0, i, 0)
|
||||||
glHint(GL_LINE_SMOOTH_HINT, GL_DONT_CARE);
|
glVertex3f(machineSize.x, i, 0)
|
||||||
|
glEnd()
|
||||||
glColor3f(0.0,0.0,0.0)
|
|
||||||
glLineWidth(4)
|
glEnable(GL_LINE_SMOOTH)
|
||||||
glBegin(GL_LINE_LOOP)
|
glEnable(GL_BLEND)
|
||||||
glVertex3f(0, 0, 0)
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
|
||||||
glVertex3f(machineSize.x, 0, 0)
|
glHint(GL_LINE_SMOOTH_HINT, GL_DONT_CARE);
|
||||||
glVertex3f(machineSize.x, machineSize.y, 0)
|
|
||||||
glVertex3f(0, machineSize.y, 0)
|
glColor3f(0.0, 0.0, 0.0)
|
||||||
glEnd()
|
glLineWidth(4)
|
||||||
|
glBegin(GL_LINE_LOOP)
|
||||||
glLineWidth(2)
|
glVertex3f(0, 0, 0)
|
||||||
glBegin(GL_LINE_LOOP)
|
glVertex3f(machineSize.x, 0, 0)
|
||||||
glVertex3f(0, 0, machineSize.z)
|
glVertex3f(machineSize.x, machineSize.y, 0)
|
||||||
glVertex3f(machineSize.x, 0, machineSize.z)
|
glVertex3f(0, machineSize.y, 0)
|
||||||
glVertex3f(machineSize.x, machineSize.y, machineSize.z)
|
glEnd()
|
||||||
glVertex3f(0, machineSize.y, machineSize.z)
|
|
||||||
glEnd()
|
glLineWidth(2)
|
||||||
glBegin(GL_LINES)
|
glBegin(GL_LINE_LOOP)
|
||||||
glVertex3f(0, 0, 0)
|
glVertex3f(0, 0, machineSize.z)
|
||||||
glVertex3f(0, 0, machineSize.z)
|
glVertex3f(machineSize.x, 0, machineSize.z)
|
||||||
glVertex3f(machineSize.x, 0, 0)
|
glVertex3f(machineSize.x, machineSize.y, machineSize.z)
|
||||||
glVertex3f(machineSize.x, 0, machineSize.z)
|
glVertex3f(0, machineSize.y, machineSize.z)
|
||||||
glVertex3f(machineSize.x, machineSize.y, 0)
|
glEnd()
|
||||||
glVertex3f(machineSize.x, machineSize.y, machineSize.z)
|
glBegin(GL_LINES)
|
||||||
glVertex3f(0, machineSize.y, 0)
|
glVertex3f(0, 0, 0)
|
||||||
glVertex3f(0, machineSize.y, machineSize.z)
|
glVertex3f(0, 0, machineSize.z)
|
||||||
glEnd()
|
glVertex3f(machineSize.x, 0, 0)
|
||||||
else:
|
glVertex3f(machineSize.x, 0, machineSize.z)
|
||||||
glDisable(GL_CULL_FACE)
|
glVertex3f(machineSize.x, machineSize.y, 0)
|
||||||
glEnable(GL_BLEND)
|
glVertex3f(machineSize.x, machineSize.y, machineSize.z)
|
||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
|
glVertex3f(0, machineSize.y, 0)
|
||||||
glColor4ub(5,171,231,127)
|
glVertex3f(0, machineSize.y, machineSize.z)
|
||||||
glBegin(GL_QUADS)
|
glEnd()
|
||||||
for x in xrange(0, int(machineSize.x), 20):
|
else:
|
||||||
for y in xrange(0, int(machineSize.y), 20):
|
glDisable(GL_CULL_FACE)
|
||||||
glVertex3f(x, y, -0.01)
|
glEnable(GL_BLEND)
|
||||||
glVertex3f(min(x+10, machineSize.x), y, -0.01)
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
|
||||||
glVertex3f(min(x+10, machineSize.x), min(y+10, machineSize.y), -0.01)
|
glColor4ub(5, 171, 231, 127)
|
||||||
glVertex3f(x, min(y+10, machineSize.y), -0.01)
|
glBegin(GL_QUADS)
|
||||||
for x in xrange(10, int(machineSize.x), 20):
|
for x in xrange(0, int(machineSize.x), 20):
|
||||||
for y in xrange(10, int(machineSize.y), 20):
|
for y in xrange(0, int(machineSize.y), 20):
|
||||||
glVertex3f(x, y, -0.01)
|
glVertex3f(x, y, -0.01)
|
||||||
glVertex3f(min(x+10, machineSize.x), y, -0.01)
|
glVertex3f(min(x + 10, machineSize.x), y, -0.01)
|
||||||
glVertex3f(min(x+10, machineSize.x), min(y+10, machineSize.y), -0.01)
|
glVertex3f(min(x + 10, machineSize.x), min(y + 10, machineSize.y), -0.01)
|
||||||
glVertex3f(x, min(y+10, machineSize.y), -0.01)
|
glVertex3f(x, min(y + 10, machineSize.y), -0.01)
|
||||||
glEnd()
|
for x in xrange(10, int(machineSize.x), 20):
|
||||||
glColor4ub(5*8/10,171*8/10,231*8/10,128)
|
for y in xrange(10, int(machineSize.y), 20):
|
||||||
glBegin(GL_QUADS)
|
glVertex3f(x, y, -0.01)
|
||||||
for x in xrange(10, int(machineSize.x), 20):
|
glVertex3f(min(x + 10, machineSize.x), y, -0.01)
|
||||||
for y in xrange(0, int(machineSize.y), 20):
|
glVertex3f(min(x + 10, machineSize.x), min(y + 10, machineSize.y), -0.01)
|
||||||
glVertex3f(x, y, -0.01)
|
glVertex3f(x, min(y + 10, machineSize.y), -0.01)
|
||||||
glVertex3f(min(x+10, machineSize.x), y, -0.01)
|
glEnd()
|
||||||
glVertex3f(min(x+10, machineSize.x), min(y+10, machineSize.y), -0.01)
|
glColor4ub(5 * 8 / 10, 171 * 8 / 10, 231 * 8 / 10, 128)
|
||||||
glVertex3f(x, min(y+10, machineSize.y), -0.01)
|
glBegin(GL_QUADS)
|
||||||
for x in xrange(0, int(machineSize.x), 20):
|
for x in xrange(10, int(machineSize.x), 20):
|
||||||
for y in xrange(10, int(machineSize.y), 20):
|
for y in xrange(0, int(machineSize.y), 20):
|
||||||
glVertex3f(x, y, -0.01)
|
glVertex3f(x, y, -0.01)
|
||||||
glVertex3f(min(x+10, machineSize.x), y, -0.01)
|
glVertex3f(min(x + 10, machineSize.x), y, -0.01)
|
||||||
glVertex3f(min(x+10, machineSize.x), min(y+10, machineSize.y), -0.01)
|
glVertex3f(min(x + 10, machineSize.x), min(y + 10, machineSize.y), -0.01)
|
||||||
glVertex3f(x, min(y+10, machineSize.y), -0.01)
|
glVertex3f(x, min(y + 10, machineSize.y), -0.01)
|
||||||
glEnd()
|
for x in xrange(0, int(machineSize.x), 20):
|
||||||
glEnable(GL_CULL_FACE)
|
for y in xrange(10, int(machineSize.y), 20):
|
||||||
|
glVertex3f(x, y, -0.01)
|
||||||
glColor4ub(5,171,231,64)
|
glVertex3f(min(x + 10, machineSize.x), y, -0.01)
|
||||||
glBegin(GL_QUADS)
|
glVertex3f(min(x + 10, machineSize.x), min(y + 10, machineSize.y), -0.01)
|
||||||
glVertex3f(0, 0, machineSize.z)
|
glVertex3f(x, min(y + 10, machineSize.y), -0.01)
|
||||||
glVertex3f(0, machineSize.y, machineSize.z)
|
glEnd()
|
||||||
glVertex3f(machineSize.x, machineSize.y, machineSize.z)
|
glEnable(GL_CULL_FACE)
|
||||||
glVertex3f(machineSize.x, 0, machineSize.z)
|
|
||||||
glEnd()
|
glColor4ub(5, 171, 231, 64)
|
||||||
|
glBegin(GL_QUADS)
|
||||||
glColor4ub(5,171,231,96)
|
glVertex3f(0, 0, machineSize.z)
|
||||||
glBegin(GL_QUADS)
|
glVertex3f(0, machineSize.y, machineSize.z)
|
||||||
glVertex3f(0, 0, 0)
|
glVertex3f(machineSize.x, machineSize.y, machineSize.z)
|
||||||
glVertex3f(0, 0, machineSize.z)
|
glVertex3f(machineSize.x, 0, machineSize.z)
|
||||||
glVertex3f(machineSize.x, 0, machineSize.z)
|
glEnd()
|
||||||
glVertex3f(machineSize.x, 0, 0)
|
|
||||||
|
glColor4ub(5, 171, 231, 96)
|
||||||
glVertex3f(0, machineSize.y, machineSize.z)
|
glBegin(GL_QUADS)
|
||||||
glVertex3f(0, machineSize.y, 0)
|
glVertex3f(0, 0, 0)
|
||||||
glVertex3f(machineSize.x, machineSize.y, 0)
|
glVertex3f(0, 0, machineSize.z)
|
||||||
glVertex3f(machineSize.x, machineSize.y, machineSize.z)
|
glVertex3f(machineSize.x, 0, machineSize.z)
|
||||||
glEnd()
|
glVertex3f(machineSize.x, 0, 0)
|
||||||
|
|
||||||
glColor4ub(5,171,231,128)
|
glVertex3f(0, machineSize.y, machineSize.z)
|
||||||
glBegin(GL_QUADS)
|
glVertex3f(0, machineSize.y, 0)
|
||||||
glVertex3f(0, 0, machineSize.z)
|
glVertex3f(machineSize.x, machineSize.y, 0)
|
||||||
glVertex3f(0, 0, 0)
|
glVertex3f(machineSize.x, machineSize.y, machineSize.z)
|
||||||
glVertex3f(0, machineSize.y, 0)
|
glEnd()
|
||||||
glVertex3f(0, machineSize.y, machineSize.z)
|
|
||||||
|
glColor4ub(5, 171, 231, 128)
|
||||||
glVertex3f(machineSize.x, 0, 0)
|
glBegin(GL_QUADS)
|
||||||
glVertex3f(machineSize.x, 0, machineSize.z)
|
glVertex3f(0, 0, machineSize.z)
|
||||||
glVertex3f(machineSize.x, machineSize.y, machineSize.z)
|
glVertex3f(0, 0, 0)
|
||||||
glVertex3f(machineSize.x, machineSize.y, 0)
|
glVertex3f(0, machineSize.y, 0)
|
||||||
glEnd()
|
glVertex3f(0, machineSize.y, machineSize.z)
|
||||||
|
|
||||||
glDisable(GL_BLEND)
|
glVertex3f(machineSize.x, 0, 0)
|
||||||
|
glVertex3f(machineSize.x, 0, machineSize.z)
|
||||||
glPushMatrix()
|
glVertex3f(machineSize.x, machineSize.y, machineSize.z)
|
||||||
glTranslate(5,5,2)
|
glVertex3f(machineSize.x, machineSize.y, 0)
|
||||||
glLineWidth(2)
|
glEnd()
|
||||||
glColor3f(0.5,0,0)
|
|
||||||
glBegin(GL_LINES)
|
glDisable(GL_BLEND)
|
||||||
glVertex3f(0,0,0)
|
|
||||||
glVertex3f(20,0,0)
|
glPushMatrix()
|
||||||
glEnd()
|
glTranslate(5, 5, 2)
|
||||||
glColor3f(0,0.5,0)
|
glLineWidth(2)
|
||||||
glBegin(GL_LINES)
|
glColor3f(0.5, 0, 0)
|
||||||
glVertex3f(0,0,0)
|
glBegin(GL_LINES)
|
||||||
glVertex3f(0,20,0)
|
glVertex3f(0, 0, 0)
|
||||||
glEnd()
|
glVertex3f(20, 0, 0)
|
||||||
glColor3f(0,0,0.5)
|
glEnd()
|
||||||
glBegin(GL_LINES)
|
glColor3f(0, 0.5, 0)
|
||||||
glVertex3f(0,0,0)
|
glBegin(GL_LINES)
|
||||||
glVertex3f(0,0,20)
|
glVertex3f(0, 0, 0)
|
||||||
glEnd()
|
glVertex3f(0, 20, 0)
|
||||||
|
glEnd()
|
||||||
glDisable(GL_DEPTH_TEST)
|
glColor3f(0, 0, 0.5)
|
||||||
#X
|
glBegin(GL_LINES)
|
||||||
glColor3f(1,0,0)
|
glVertex3f(0, 0, 0)
|
||||||
glPushMatrix()
|
glVertex3f(0, 0, 20)
|
||||||
glTranslate(23,0,0)
|
glEnd()
|
||||||
noZ = ResetMatrixRotationAndScale()
|
|
||||||
glBegin(GL_LINES)
|
glDisable(GL_DEPTH_TEST)
|
||||||
glVertex3f(-0.8,1,0)
|
#X
|
||||||
glVertex3f(0.8,-1,0)
|
glColor3f(1, 0, 0)
|
||||||
glVertex3f(0.8,1,0)
|
glPushMatrix()
|
||||||
glVertex3f(-0.8,-1,0)
|
glTranslate(23, 0, 0)
|
||||||
glEnd()
|
noZ = ResetMatrixRotationAndScale()
|
||||||
glPopMatrix()
|
glBegin(GL_LINES)
|
||||||
|
glVertex3f(-0.8, 1, 0)
|
||||||
#Y
|
glVertex3f(0.8, -1, 0)
|
||||||
glColor3f(0,1,0)
|
glVertex3f(0.8, 1, 0)
|
||||||
glPushMatrix()
|
glVertex3f(-0.8, -1, 0)
|
||||||
glTranslate(0,23,0)
|
glEnd()
|
||||||
ResetMatrixRotationAndScale()
|
glPopMatrix()
|
||||||
glBegin(GL_LINES)
|
|
||||||
glVertex3f(-0.8, 1,0)
|
#Y
|
||||||
glVertex3f( 0.0, 0,0)
|
glColor3f(0, 1, 0)
|
||||||
glVertex3f( 0.8, 1,0)
|
glPushMatrix()
|
||||||
glVertex3f(-0.8,-1,0)
|
glTranslate(0, 23, 0)
|
||||||
glEnd()
|
ResetMatrixRotationAndScale()
|
||||||
glPopMatrix()
|
glBegin(GL_LINES)
|
||||||
|
glVertex3f(-0.8, 1, 0)
|
||||||
#Z
|
glVertex3f(0.0, 0, 0)
|
||||||
if not noZ:
|
glVertex3f(0.8, 1, 0)
|
||||||
glColor3f(0,0,1)
|
glVertex3f(-0.8, -1, 0)
|
||||||
glPushMatrix()
|
glEnd()
|
||||||
glTranslate(0,0,23)
|
glPopMatrix()
|
||||||
ResetMatrixRotationAndScale()
|
|
||||||
glBegin(GL_LINES)
|
#Z
|
||||||
glVertex3f(-0.8, 1,0)
|
if not noZ:
|
||||||
glVertex3f( 0.8, 1,0)
|
glColor3f(0, 0, 1)
|
||||||
glVertex3f( 0.8, 1,0)
|
glPushMatrix()
|
||||||
glVertex3f(-0.8,-1,0)
|
glTranslate(0, 0, 23)
|
||||||
glVertex3f(-0.8,-1,0)
|
ResetMatrixRotationAndScale()
|
||||||
glVertex3f( 0.8,-1,0)
|
glBegin(GL_LINES)
|
||||||
glEnd()
|
glVertex3f(-0.8, 1, 0)
|
||||||
glPopMatrix()
|
glVertex3f(0.8, 1, 0)
|
||||||
|
glVertex3f(0.8, 1, 0)
|
||||||
glPopMatrix()
|
glVertex3f(-0.8, -1, 0)
|
||||||
glEnable(GL_DEPTH_TEST)
|
glVertex3f(-0.8, -1, 0)
|
||||||
|
glVertex3f(0.8, -1, 0)
|
||||||
def ResetMatrixRotationAndScale():
|
glEnd()
|
||||||
matrix = glGetFloatv(GL_MODELVIEW_MATRIX)
|
glPopMatrix()
|
||||||
noZ = False
|
|
||||||
if matrix[3][2] > 0:
|
glPopMatrix()
|
||||||
return False
|
glEnable(GL_DEPTH_TEST)
|
||||||
scale2D = matrix[0][0]
|
|
||||||
matrix[0][0] = 1.0
|
|
||||||
matrix[1][0] = 0.0
|
def ResetMatrixRotationAndScale():
|
||||||
matrix[2][0] = 0.0
|
matrix = glGetFloatv(GL_MODELVIEW_MATRIX)
|
||||||
matrix[0][1] = 0.0
|
noZ = False
|
||||||
matrix[1][1] = 1.0
|
if matrix[3][2] > 0:
|
||||||
matrix[2][1] = 0.0
|
return False
|
||||||
matrix[0][2] = 0.0
|
scale2D = matrix[0][0]
|
||||||
matrix[1][2] = 0.0
|
matrix[0][0] = 1.0
|
||||||
matrix[2][2] = 1.0
|
matrix[1][0] = 0.0
|
||||||
|
matrix[2][0] = 0.0
|
||||||
if matrix[3][2] != 0.0:
|
matrix[0][1] = 0.0
|
||||||
matrix[3][0] = matrix[3][0] / (-matrix[3][2] / 100)
|
matrix[1][1] = 1.0
|
||||||
matrix[3][1] = matrix[3][1] / (-matrix[3][2] / 100)
|
matrix[2][1] = 0.0
|
||||||
matrix[3][2] = -100
|
matrix[0][2] = 0.0
|
||||||
else:
|
matrix[1][2] = 0.0
|
||||||
matrix[0][0] = scale2D
|
matrix[2][2] = 1.0
|
||||||
matrix[1][1] = scale2D
|
|
||||||
matrix[2][2] = scale2D
|
if matrix[3][2] != 0.0:
|
||||||
matrix[3][2] = -100
|
matrix[3][0] = matrix[3][0] / (-matrix[3][2] / 100)
|
||||||
noZ = True
|
matrix[3][1] = matrix[3][1] / (-matrix[3][2] / 100)
|
||||||
|
matrix[3][2] = -100
|
||||||
glLoadMatrixf(matrix)
|
else:
|
||||||
return noZ
|
matrix[0][0] = scale2D
|
||||||
|
matrix[1][1] = scale2D
|
||||||
def DrawBox(vMin, vMax):
|
matrix[2][2] = scale2D
|
||||||
glBegin(GL_LINE_LOOP)
|
matrix[3][2] = -100
|
||||||
glVertex3f(vMin[0], vMin[1], vMin[2])
|
noZ = True
|
||||||
glVertex3f(vMax[0], vMin[1], vMin[2])
|
|
||||||
glVertex3f(vMax[0], vMax[1], vMin[2])
|
glLoadMatrixf(matrix)
|
||||||
glVertex3f(vMin[0], vMax[1], vMin[2])
|
return noZ
|
||||||
glEnd()
|
|
||||||
|
|
||||||
glBegin(GL_LINE_LOOP)
|
def DrawBox(vMin, vMax):
|
||||||
glVertex3f(vMin[0], vMin[1], vMax[2])
|
glBegin(GL_LINE_LOOP)
|
||||||
glVertex3f(vMax[0], vMin[1], vMax[2])
|
glVertex3f(vMin[0], vMin[1], vMin[2])
|
||||||
glVertex3f(vMax[0], vMax[1], vMax[2])
|
glVertex3f(vMax[0], vMin[1], vMin[2])
|
||||||
glVertex3f(vMin[0], vMax[1], vMax[2])
|
glVertex3f(vMax[0], vMax[1], vMin[2])
|
||||||
glEnd()
|
glVertex3f(vMin[0], vMax[1], vMin[2])
|
||||||
glBegin(GL_LINES)
|
glEnd()
|
||||||
glVertex3f(vMin[0], vMin[1], vMin[2])
|
|
||||||
glVertex3f(vMin[0], vMin[1], vMax[2])
|
glBegin(GL_LINE_LOOP)
|
||||||
glVertex3f(vMax[0], vMin[1], vMin[2])
|
glVertex3f(vMin[0], vMin[1], vMax[2])
|
||||||
glVertex3f(vMax[0], vMin[1], vMax[2])
|
glVertex3f(vMax[0], vMin[1], vMax[2])
|
||||||
glVertex3f(vMax[0], vMax[1], vMin[2])
|
glVertex3f(vMax[0], vMax[1], vMax[2])
|
||||||
glVertex3f(vMax[0], vMax[1], vMax[2])
|
glVertex3f(vMin[0], vMax[1], vMax[2])
|
||||||
glVertex3f(vMin[0], vMax[1], vMin[2])
|
glEnd()
|
||||||
glVertex3f(vMin[0], vMax[1], vMax[2])
|
glBegin(GL_LINES)
|
||||||
glEnd()
|
glVertex3f(vMin[0], vMin[1], vMin[2])
|
||||||
|
glVertex3f(vMin[0], vMin[1], vMax[2])
|
||||||
def DrawMeshOutline(mesh):
|
glVertex3f(vMax[0], vMin[1], vMin[2])
|
||||||
glEnable(GL_CULL_FACE)
|
glVertex3f(vMax[0], vMin[1], vMax[2])
|
||||||
glEnableClientState(GL_VERTEX_ARRAY);
|
glVertex3f(vMax[0], vMax[1], vMin[2])
|
||||||
glVertexPointer(3, GL_FLOAT, 0, mesh.vertexes)
|
glVertex3f(vMax[0], vMax[1], vMax[2])
|
||||||
|
glVertex3f(vMin[0], vMax[1], vMin[2])
|
||||||
glCullFace(GL_FRONT)
|
glVertex3f(vMin[0], vMax[1], vMax[2])
|
||||||
glLineWidth(3)
|
glEnd()
|
||||||
glPolygonMode(GL_BACK, GL_LINE)
|
|
||||||
glDrawArrays(GL_TRIANGLES, 0, mesh.vertexCount)
|
|
||||||
glPolygonMode(GL_BACK, GL_FILL)
|
def DrawMeshOutline(mesh):
|
||||||
glCullFace(GL_BACK)
|
glEnable(GL_CULL_FACE)
|
||||||
|
glEnableClientState(GL_VERTEX_ARRAY);
|
||||||
glDisableClientState(GL_VERTEX_ARRAY)
|
glVertexPointer(3, GL_FLOAT, 0, mesh.vertexes)
|
||||||
|
|
||||||
def DrawMesh(mesh):
|
glCullFace(GL_FRONT)
|
||||||
glEnable(GL_CULL_FACE)
|
glLineWidth(3)
|
||||||
glEnableClientState(GL_VERTEX_ARRAY);
|
glPolygonMode(GL_BACK, GL_LINE)
|
||||||
glEnableClientState(GL_NORMAL_ARRAY);
|
glDrawArrays(GL_TRIANGLES, 0, mesh.vertexCount)
|
||||||
glVertexPointer(3, GL_FLOAT, 0, mesh.vertexes)
|
glPolygonMode(GL_BACK, GL_FILL)
|
||||||
glNormalPointer(GL_FLOAT, 0, mesh.normal)
|
glCullFace(GL_BACK)
|
||||||
|
|
||||||
#Odd, drawing in batchs is a LOT faster then drawing it all at once.
|
glDisableClientState(GL_VERTEX_ARRAY)
|
||||||
batchSize = 999 #Warning, batchSize needs to be dividable by 3
|
|
||||||
extraStartPos = int(mesh.vertexCount / batchSize) * batchSize
|
|
||||||
extraCount = mesh.vertexCount - extraStartPos
|
def DrawMesh(mesh):
|
||||||
|
glEnable(GL_CULL_FACE)
|
||||||
glCullFace(GL_BACK)
|
glEnableClientState(GL_VERTEX_ARRAY);
|
||||||
for i in xrange(0, int(mesh.vertexCount / batchSize)):
|
glEnableClientState(GL_NORMAL_ARRAY);
|
||||||
glDrawArrays(GL_TRIANGLES, i*batchSize, batchSize)
|
glVertexPointer(3, GL_FLOAT, 0, mesh.vertexes)
|
||||||
glDrawArrays(GL_TRIANGLES, extraStartPos, extraCount)
|
glNormalPointer(GL_FLOAT, 0, mesh.normal)
|
||||||
|
|
||||||
glCullFace(GL_FRONT)
|
#Odd, drawing in batchs is a LOT faster then drawing it all at once.
|
||||||
glNormalPointer(GL_FLOAT, 0, mesh.invNormal)
|
batchSize = 999 #Warning, batchSize needs to be dividable by 3
|
||||||
for i in xrange(0, int(mesh.vertexCount / batchSize)):
|
extraStartPos = int(mesh.vertexCount / batchSize) * batchSize
|
||||||
glDrawArrays(GL_TRIANGLES, i*batchSize, batchSize)
|
extraCount = mesh.vertexCount - extraStartPos
|
||||||
extraStartPos = int(mesh.vertexCount / batchSize) * batchSize
|
|
||||||
extraCount = mesh.vertexCount - extraStartPos
|
glCullFace(GL_BACK)
|
||||||
glDrawArrays(GL_TRIANGLES, extraStartPos, extraCount)
|
for i in xrange(0, int(mesh.vertexCount / batchSize)):
|
||||||
glCullFace(GL_BACK)
|
glDrawArrays(GL_TRIANGLES, i * batchSize, batchSize)
|
||||||
|
glDrawArrays(GL_TRIANGLES, extraStartPos, extraCount)
|
||||||
glDisableClientState(GL_VERTEX_ARRAY)
|
|
||||||
glDisableClientState(GL_NORMAL_ARRAY);
|
glCullFace(GL_FRONT)
|
||||||
|
glNormalPointer(GL_FLOAT, 0, mesh.invNormal)
|
||||||
def DrawGCodeLayer(layer):
|
for i in xrange(0, int(mesh.vertexCount / batchSize)):
|
||||||
filamentRadius = profile.getProfileSettingFloat('filament_diameter') / 2
|
glDrawArrays(GL_TRIANGLES, i * batchSize, batchSize)
|
||||||
filamentArea = math.pi * filamentRadius * filamentRadius
|
extraStartPos = int(mesh.vertexCount / batchSize) * batchSize
|
||||||
lineWidth = profile.getProfileSettingFloat('nozzle_size') / 2 / 10
|
extraCount = mesh.vertexCount - extraStartPos
|
||||||
|
glDrawArrays(GL_TRIANGLES, extraStartPos, extraCount)
|
||||||
fillCycle = 0
|
glCullFace(GL_BACK)
|
||||||
fillColorCycle = [[0.5,0.5,0.0],[0.0,0.5,0.5],[0.5,0.0,0.5]]
|
|
||||||
moveColor = [0,0,1]
|
glDisableClientState(GL_VERTEX_ARRAY)
|
||||||
retractColor = [1,0,0.5]
|
glDisableClientState(GL_NORMAL_ARRAY);
|
||||||
supportColor = [0,1,1]
|
|
||||||
extrudeColor = [1,0,0]
|
|
||||||
innerWallColor = [0,1,0]
|
def DrawGCodeLayer(layer):
|
||||||
skirtColor = [0,0.5,0.5]
|
filamentRadius = profile.getProfileSettingFloat('filament_diameter') / 2
|
||||||
prevPathWasRetract = False
|
filamentArea = math.pi * filamentRadius * filamentRadius
|
||||||
|
lineWidth = profile.getProfileSettingFloat('nozzle_size') / 2 / 10
|
||||||
glDisable(GL_CULL_FACE)
|
|
||||||
for path in layer:
|
fillCycle = 0
|
||||||
if path.type == 'move':
|
fillColorCycle = [[0.5, 0.5, 0.0], [0.0, 0.5, 0.5], [0.5, 0.0, 0.5]]
|
||||||
if prevPathWasRetract:
|
moveColor = [0, 0, 1]
|
||||||
c = retractColor
|
retractColor = [1, 0, 0.5]
|
||||||
else:
|
supportColor = [0, 1, 1]
|
||||||
c = moveColor
|
extrudeColor = [1, 0, 0]
|
||||||
zOffset = 0.01
|
innerWallColor = [0, 1, 0]
|
||||||
if path.type == 'extrude':
|
skirtColor = [0, 0.5, 0.5]
|
||||||
if path.pathType == 'FILL':
|
prevPathWasRetract = False
|
||||||
c = fillColorCycle[fillCycle]
|
|
||||||
fillCycle = (fillCycle + 1) % len(fillColorCycle)
|
glDisable(GL_CULL_FACE)
|
||||||
elif path.pathType == 'WALL-INNER':
|
for path in layer:
|
||||||
c = innerWallColor
|
if path.type == 'move':
|
||||||
zOffset = 0.02
|
if prevPathWasRetract:
|
||||||
elif path.pathType == 'SUPPORT':
|
c = retractColor
|
||||||
c = supportColor
|
else:
|
||||||
elif path.pathType == 'SKIRT':
|
c = moveColor
|
||||||
c = skirtColor
|
zOffset = 0.01
|
||||||
else:
|
if path.type == 'extrude':
|
||||||
c = extrudeColor
|
if path.pathType == 'FILL':
|
||||||
if path.type == 'retract':
|
c = fillColorCycle[fillCycle]
|
||||||
c = [0,1,1]
|
fillCycle = (fillCycle + 1) % len(fillColorCycle)
|
||||||
if path.type == 'extrude':
|
elif path.pathType == 'WALL-INNER':
|
||||||
drawLength = 0.0
|
c = innerWallColor
|
||||||
prevNormal = None
|
zOffset = 0.02
|
||||||
for i in xrange(0, len(path.list)-1):
|
elif path.pathType == 'SUPPORT':
|
||||||
v0 = path.list[i]
|
c = supportColor
|
||||||
v1 = path.list[i+1]
|
elif path.pathType == 'SKIRT':
|
||||||
|
c = skirtColor
|
||||||
# Calculate line width from ePerDistance (needs layer thickness and filament diameter)
|
else:
|
||||||
dist = (v0 - v1).vsize()
|
c = extrudeColor
|
||||||
if dist > 0 and path.layerThickness > 0:
|
if path.type == 'retract':
|
||||||
extrusionMMperDist = (v1.e - v0.e) / dist
|
c = [0, 1, 1]
|
||||||
lineWidth = extrusionMMperDist * filamentArea / path.layerThickness / 2 * v1.extrudeAmountMultiply
|
if path.type == 'extrude':
|
||||||
|
drawLength = 0.0
|
||||||
drawLength += (v0 - v1).vsize()
|
prevNormal = None
|
||||||
normal = (v0 - v1).cross(util3d.Vector3(0,0,1))
|
for i in xrange(0, len(path.list) - 1):
|
||||||
normal.normalize()
|
v0 = path.list[i]
|
||||||
|
v1 = path.list[i + 1]
|
||||||
vv2 = v0 + normal * lineWidth
|
|
||||||
vv3 = v1 + normal * lineWidth
|
# Calculate line width from ePerDistance (needs layer thickness and filament diameter)
|
||||||
vv0 = v0 - normal * lineWidth
|
dist = (v0 - v1).vsize()
|
||||||
vv1 = v1 - normal * lineWidth
|
if dist > 0 and path.layerThickness > 0:
|
||||||
|
extrusionMMperDist = (v1.e - v0.e) / dist
|
||||||
glBegin(GL_QUADS)
|
lineWidth = extrusionMMperDist * filamentArea / path.layerThickness / 2 * v1.extrudeAmountMultiply
|
||||||
glColor3fv(c)
|
|
||||||
glVertex3f(vv0.x, vv0.y, vv0.z - zOffset)
|
drawLength += (v0 - v1).vsize()
|
||||||
glVertex3f(vv1.x, vv1.y, vv1.z - zOffset)
|
normal = (v0 - v1).cross(util3d.Vector3(0, 0, 1))
|
||||||
glVertex3f(vv3.x, vv3.y, vv3.z - zOffset)
|
normal.normalize()
|
||||||
glVertex3f(vv2.x, vv2.y, vv2.z - zOffset)
|
|
||||||
glEnd()
|
vv2 = v0 + normal * lineWidth
|
||||||
if prevNormal != None:
|
vv3 = v1 + normal * lineWidth
|
||||||
n = (normal + prevNormal)
|
vv0 = v0 - normal * lineWidth
|
||||||
n.normalize()
|
vv1 = v1 - normal * lineWidth
|
||||||
vv4 = v0 + n * lineWidth
|
|
||||||
vv5 = v0 - n * lineWidth
|
glBegin(GL_QUADS)
|
||||||
glBegin(GL_QUADS)
|
glColor3fv(c)
|
||||||
glColor3fv(c)
|
glVertex3f(vv0.x, vv0.y, vv0.z - zOffset)
|
||||||
glVertex3f(vv2.x, vv2.y, vv2.z - zOffset)
|
glVertex3f(vv1.x, vv1.y, vv1.z - zOffset)
|
||||||
glVertex3f(vv4.x, vv4.y, vv4.z - zOffset)
|
glVertex3f(vv3.x, vv3.y, vv3.z - zOffset)
|
||||||
glVertex3f(prevVv3.x, prevVv3.y, prevVv3.z - zOffset)
|
glVertex3f(vv2.x, vv2.y, vv2.z - zOffset)
|
||||||
glVertex3f(v0.x, v0.y, v0.z - zOffset)
|
glEnd()
|
||||||
|
if prevNormal != None:
|
||||||
glVertex3f(vv0.x, vv0.y, vv0.z - zOffset)
|
n = (normal + prevNormal)
|
||||||
glVertex3f(vv5.x, vv5.y, vv5.z - zOffset)
|
n.normalize()
|
||||||
glVertex3f(prevVv1.x, prevVv1.y, prevVv1.z - zOffset)
|
vv4 = v0 + n * lineWidth
|
||||||
glVertex3f(v0.x, v0.y, v0.z - zOffset)
|
vv5 = v0 - n * lineWidth
|
||||||
glEnd()
|
glBegin(GL_QUADS)
|
||||||
|
glColor3fv(c)
|
||||||
prevNormal = normal
|
glVertex3f(vv2.x, vv2.y, vv2.z - zOffset)
|
||||||
prevVv1 = vv1
|
glVertex3f(vv4.x, vv4.y, vv4.z - zOffset)
|
||||||
prevVv3 = vv3
|
glVertex3f(prevVv3.x, prevVv3.y, prevVv3.z - zOffset)
|
||||||
else:
|
glVertex3f(v0.x, v0.y, v0.z - zOffset)
|
||||||
glBegin(GL_LINE_STRIP)
|
|
||||||
glColor3fv(c)
|
glVertex3f(vv0.x, vv0.y, vv0.z - zOffset)
|
||||||
for v in path.list:
|
glVertex3f(vv5.x, vv5.y, vv5.z - zOffset)
|
||||||
glVertex3f(v.x, v.y, v.z)
|
glVertex3f(prevVv1.x, prevVv1.y, prevVv1.z - zOffset)
|
||||||
glEnd()
|
glVertex3f(v0.x, v0.y, v0.z - zOffset)
|
||||||
if not path.type == 'move':
|
glEnd()
|
||||||
prevPathWasRetract = False
|
|
||||||
if path.type == 'retract' and path.list[0].almostEqual(path.list[-1]):
|
prevNormal = normal
|
||||||
prevPathWasRetract = True
|
prevVv1 = vv1
|
||||||
glEnable(GL_CULL_FACE)
|
prevVv3 = vv3
|
||||||
|
else:
|
||||||
|
glBegin(GL_LINE_STRIP)
|
||||||
|
glColor3fv(c)
|
||||||
|
for v in path.list:
|
||||||
|
glVertex3f(v.x, v.y, v.z)
|
||||||
|
glEnd()
|
||||||
|
if not path.type == 'move':
|
||||||
|
prevPathWasRetract = False
|
||||||
|
if path.type == 'retract' and path.list[0].almostEqual(path.list[-1]):
|
||||||
|
prevPathWasRetract = True
|
||||||
|
glEnable(GL_CULL_FACE)
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,39 +1,39 @@
|
||||||
import sys, os
|
# coding=utf-8
|
||||||
#We only need the core here, which speeds up the import. As we want to show the splashscreen ASAP.
|
from __future__ import absolute_import
|
||||||
import wx._core
|
|
||||||
|
import wx._core #We only need the core here, which speeds up the import. As we want to show the splashscreen ASAP.
|
||||||
|
|
||||||
|
from util.resources import getPathForImage
|
||||||
|
|
||||||
def getBitmapImage(filename):
|
|
||||||
#The frozen executable has the script files in a zip, so we need to exit another level to get to our images.
|
|
||||||
if hasattr(sys, 'frozen'):
|
|
||||||
return wx.Bitmap(os.path.normpath(os.path.join(os.path.split(__file__)[0], "../../images", filename)))
|
|
||||||
else:
|
|
||||||
return wx.Bitmap(os.path.normpath(os.path.join(os.path.split(__file__)[0], "../images", filename)))
|
|
||||||
|
|
||||||
class splashScreen(wx.SplashScreen):
|
class splashScreen(wx.SplashScreen):
|
||||||
def __init__(self, callback):
|
def __init__(self, callback):
|
||||||
self.callback = callback
|
self.callback = callback
|
||||||
bitmap = getBitmapImage("splash.png")
|
bitmap = wx.Bitmap(getPathForImage('splash.png'))
|
||||||
super(splashScreen, self).__init__(bitmap, wx.SPLASH_CENTRE_ON_SCREEN, 0, None)
|
super(splashScreen, self).__init__(bitmap, wx.SPLASH_CENTRE_ON_SCREEN, 0, None)
|
||||||
wx.CallAfter(self.DoCallback)
|
wx.CallAfter(self.DoCallback)
|
||||||
|
|
||||||
def DoCallback(self):
|
def DoCallback(self):
|
||||||
self.callback(self)
|
self.callback(self)
|
||||||
self.Destroy()
|
self.Destroy()
|
||||||
|
|
||||||
|
|
||||||
def showSplash(callback):
|
def showSplash(callback):
|
||||||
app = wx.App(False)
|
app = wx.App(False)
|
||||||
splashScreen(callback)
|
splashScreen(callback)
|
||||||
app.MainLoop()
|
app.MainLoop()
|
||||||
|
|
||||||
|
|
||||||
def testCallback(splashscreen):
|
def testCallback(splashscreen):
|
||||||
print "Callback!"
|
print "Callback!"
|
||||||
import time
|
import time
|
||||||
|
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
print "!Callback"
|
print "!Callback"
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
showSplash(testCallback)
|
showSplash(testCallback)
|
||||||
|
|
||||||
if __name__ == u'__main__':
|
if __name__ == u'__main__':
|
||||||
main()
|
main()
|
||||||
|
|
||||||
|
|
|
@ -1,28 +1,23 @@
|
||||||
|
# coding=utf-8
|
||||||
|
from __future__ import absolute_import
|
||||||
from __future__ import division
|
from __future__ import division
|
||||||
|
|
||||||
import os, sys
|
|
||||||
|
|
||||||
import wx
|
import wx
|
||||||
from wx.lib import buttons
|
from wx.lib import buttons
|
||||||
|
|
||||||
from util import profile
|
from util import profile
|
||||||
|
from util.resources import getPathForImage
|
||||||
|
|
||||||
|
|
||||||
#######################################################
|
#######################################################
|
||||||
# toolbarUtil contains help classes and functions for
|
# toolbarUtil contains help classes and functions for
|
||||||
# toolbar buttons.
|
# toolbar buttons.
|
||||||
#######################################################
|
#######################################################
|
||||||
|
|
||||||
def getBitmapImage(filename):
|
|
||||||
#The frozen executable has the script files in a zip, so we need to exit another level to get to our images.
|
|
||||||
if hasattr(sys, 'frozen'):
|
|
||||||
return wx.Bitmap(os.path.normpath(os.path.join(os.path.split(__file__)[0], "../../images", filename)))
|
|
||||||
else:
|
|
||||||
return wx.Bitmap(os.path.normpath(os.path.join(os.path.split(__file__)[0], "../images", filename)))
|
|
||||||
|
|
||||||
class Toolbar(wx.ToolBar):
|
class Toolbar(wx.ToolBar):
|
||||||
def __init__(self, parent):
|
def __init__(self, parent):
|
||||||
super(Toolbar, self).__init__(parent, -1, style=wx.TB_HORIZONTAL | wx.NO_BORDER)
|
super(Toolbar, self).__init__(parent, -1, style=wx.TB_HORIZONTAL | wx.NO_BORDER)
|
||||||
self.SetToolBitmapSize( ( 21, 21 ) )
|
self.SetToolBitmapSize(( 21, 21 ))
|
||||||
|
|
||||||
if not hasattr(parent, 'popup'):
|
if not hasattr(parent, 'popup'):
|
||||||
# Create popup window
|
# Create popup window
|
||||||
|
@ -30,14 +25,14 @@ class Toolbar(wx.ToolBar):
|
||||||
parent.popup.SetBackgroundColour(wx.SystemSettings.GetColour(wx.SYS_COLOUR_INFOBK))
|
parent.popup.SetBackgroundColour(wx.SystemSettings.GetColour(wx.SYS_COLOUR_INFOBK))
|
||||||
parent.popup.text = wx.StaticText(parent.popup, -1, '')
|
parent.popup.text = wx.StaticText(parent.popup, -1, '')
|
||||||
parent.popup.sizer = wx.BoxSizer()
|
parent.popup.sizer = wx.BoxSizer()
|
||||||
parent.popup.sizer.Add(parent.popup.text, flag=wx.EXPAND|wx.ALL, border=1)
|
parent.popup.sizer.Add(parent.popup.text, flag=wx.EXPAND | wx.ALL, border=1)
|
||||||
parent.popup.SetSizer(parent.popup.sizer)
|
parent.popup.SetSizer(parent.popup.sizer)
|
||||||
parent.popup.owner = None
|
parent.popup.owner = None
|
||||||
|
|
||||||
def OnPopupDisplay(self, e):
|
def OnPopupDisplay(self, e):
|
||||||
self.UpdatePopup(e.GetEventObject())
|
self.UpdatePopup(e.GetEventObject())
|
||||||
self.GetParent().popup.Show(True)
|
self.GetParent().popup.Show(True)
|
||||||
|
|
||||||
def OnPopupHide(self, e):
|
def OnPopupHide(self, e):
|
||||||
if self.GetParent().popup.owner == e.GetEventObject():
|
if self.GetParent().popup.owner == e.GetEventObject():
|
||||||
self.GetParent().popup.Show(False)
|
self.GetParent().popup.Show(False)
|
||||||
|
@ -50,13 +45,14 @@ class Toolbar(wx.ToolBar):
|
||||||
popup.Fit();
|
popup.Fit();
|
||||||
x, y = control.ClientToScreenXY(0, 0)
|
x, y = control.ClientToScreenXY(0, 0)
|
||||||
sx, sy = control.GetSizeTuple()
|
sx, sy = control.GetSizeTuple()
|
||||||
popup.SetPosition((x, y+sy))
|
popup.SetPosition((x, y + sy))
|
||||||
|
|
||||||
|
|
||||||
class ToggleButton(buttons.GenBitmapToggleButton):
|
class ToggleButton(buttons.GenBitmapToggleButton):
|
||||||
def __init__(self, parent, profileSetting, bitmapFilenameOn, bitmapFilenameOff,
|
def __init__(self, parent, profileSetting, bitmapFilenameOn, bitmapFilenameOff,
|
||||||
helpText='', id=-1, callback=None, size=(20,20)):
|
helpText='', id=-1, callback=None, size=(20, 20)):
|
||||||
self.bitmapOn = getBitmapImage(bitmapFilenameOn)
|
self.bitmapOn = wx.Bitmap(getPathForImage(bitmapFilenameOn))
|
||||||
self.bitmapOff = getBitmapImage(bitmapFilenameOff)
|
self.bitmapOff = wx.Bitmap(getPathForImage(bitmapFilenameOff))
|
||||||
|
|
||||||
super(ToggleButton, self).__init__(parent, id, self.bitmapOff, size=size)
|
super(ToggleButton, self).__init__(parent, id, self.bitmapOff, size=size)
|
||||||
|
|
||||||
|
@ -75,7 +71,7 @@ class ToggleButton(buttons.GenBitmapToggleButton):
|
||||||
|
|
||||||
self.Bind(wx.EVT_ENTER_WINDOW, self.OnMouseEnter)
|
self.Bind(wx.EVT_ENTER_WINDOW, self.OnMouseEnter)
|
||||||
self.Bind(wx.EVT_LEAVE_WINDOW, self.OnMouseLeave)
|
self.Bind(wx.EVT_LEAVE_WINDOW, self.OnMouseLeave)
|
||||||
|
|
||||||
parent.AddControl(self)
|
parent.AddControl(self)
|
||||||
|
|
||||||
def SetBitmap(self, boolValue):
|
def SetBitmap(self, boolValue):
|
||||||
|
@ -117,11 +113,12 @@ class ToggleButton(buttons.GenBitmapToggleButton):
|
||||||
self.Refresh()
|
self.Refresh()
|
||||||
event.Skip()
|
event.Skip()
|
||||||
|
|
||||||
|
|
||||||
class RadioButton(buttons.GenBitmapButton):
|
class RadioButton(buttons.GenBitmapButton):
|
||||||
def __init__(self, parent, group, bitmapFilenameOn, bitmapFilenameOff,
|
def __init__(self, parent, group, bitmapFilenameOn, bitmapFilenameOff,
|
||||||
helpText='', id=-1, callback=None, size=(20,20)):
|
helpText='', id=-1, callback=None, size=(20, 20)):
|
||||||
self.bitmapOn = getBitmapImage(bitmapFilenameOn)
|
self.bitmapOn = wx.Bitmap(getPathForImage(bitmapFilenameOn))
|
||||||
self.bitmapOff = getBitmapImage(bitmapFilenameOff)
|
self.bitmapOff = wx.Bitmap(getPathForImage(bitmapFilenameOff))
|
||||||
|
|
||||||
super(RadioButton, self).__init__(parent, id, self.bitmapOff, size=size)
|
super(RadioButton, self).__init__(parent, id, self.bitmapOff, size=size)
|
||||||
|
|
||||||
|
@ -138,10 +135,10 @@ class RadioButton(buttons.GenBitmapButton):
|
||||||
|
|
||||||
self.Bind(wx.EVT_ENTER_WINDOW, self.OnMouseEnter)
|
self.Bind(wx.EVT_ENTER_WINDOW, self.OnMouseEnter)
|
||||||
self.Bind(wx.EVT_LEAVE_WINDOW, self.OnMouseLeave)
|
self.Bind(wx.EVT_LEAVE_WINDOW, self.OnMouseLeave)
|
||||||
|
|
||||||
if len(group) == 1:
|
if len(group) == 1:
|
||||||
self.SetValue(True)
|
self.SetValue(True)
|
||||||
|
|
||||||
parent.AddControl(self)
|
parent.AddControl(self)
|
||||||
|
|
||||||
def SetBitmap(self, boolValue):
|
def SetBitmap(self, boolValue):
|
||||||
|
@ -158,7 +155,7 @@ class RadioButton(buttons.GenBitmapButton):
|
||||||
for other in self.group:
|
for other in self.group:
|
||||||
if other != self:
|
if other != self:
|
||||||
other.SetValue(False)
|
other.SetValue(False)
|
||||||
|
|
||||||
def GetValue(self):
|
def GetValue(self):
|
||||||
return self._value
|
return self._value
|
||||||
|
|
||||||
|
@ -179,10 +176,11 @@ class RadioButton(buttons.GenBitmapButton):
|
||||||
self.Refresh()
|
self.Refresh()
|
||||||
event.Skip()
|
event.Skip()
|
||||||
|
|
||||||
|
|
||||||
class NormalButton(buttons.GenBitmapButton):
|
class NormalButton(buttons.GenBitmapButton):
|
||||||
def __init__(self, parent, callback, bitmapFilename,
|
def __init__(self, parent, callback, bitmapFilename,
|
||||||
helpText='', id=-1, size=(20,20)):
|
helpText='', id=-1, size=(20, 20)):
|
||||||
self.bitmap = getBitmapImage(bitmapFilename)
|
self.bitmap = wx.Bitmap(getPathForImage(bitmapFilename))
|
||||||
super(NormalButton, self).__init__(parent, id, self.bitmap, size=size)
|
super(NormalButton, self).__init__(parent, id, self.bitmap, size=size)
|
||||||
|
|
||||||
self.helpText = helpText
|
self.helpText = helpText
|
||||||
|
@ -193,9 +191,9 @@ class NormalButton(buttons.GenBitmapButton):
|
||||||
|
|
||||||
self.Bind(wx.EVT_ENTER_WINDOW, self.OnMouseEnter)
|
self.Bind(wx.EVT_ENTER_WINDOW, self.OnMouseEnter)
|
||||||
self.Bind(wx.EVT_LEAVE_WINDOW, self.OnMouseLeave)
|
self.Bind(wx.EVT_LEAVE_WINDOW, self.OnMouseLeave)
|
||||||
|
|
||||||
self.Bind(wx.EVT_BUTTON, self.OnButton)
|
self.Bind(wx.EVT_BUTTON, self.OnButton)
|
||||||
|
|
||||||
parent.AddControl(self)
|
parent.AddControl(self)
|
||||||
|
|
||||||
def OnButton(self, event):
|
def OnButton(self, event):
|
||||||
|
|
|
@ -1,141 +1,156 @@
|
||||||
import os, glob, subprocess, platform
|
# coding=utf-8
|
||||||
import wx
|
from __future__ import absolute_import
|
||||||
|
|
||||||
from util import profile
|
import os
|
||||||
from gui import toolbarUtil
|
import glob
|
||||||
|
import subprocess
|
||||||
try:
|
import platform
|
||||||
#Try to find the OpenCV library for video capture.
|
|
||||||
from opencv import cv
|
import wx
|
||||||
from opencv import highgui
|
|
||||||
except:
|
from util import profile
|
||||||
cv = None
|
from util.resources import getPathForImage
|
||||||
|
from gui import toolbarUtil
|
||||||
try:
|
|
||||||
#Use the vidcap library directly from the VideoCapture package. (Windows only)
|
try:
|
||||||
# http://videocapture.sourceforge.net/
|
#Try to find the OpenCV library for video capture.
|
||||||
# We're using the binary interface, not the python interface, so we don't depend on PIL
|
from opencv import cv
|
||||||
import vidcap as win32vidcap
|
from opencv import highgui
|
||||||
except:
|
except:
|
||||||
win32vidcap = None
|
cv = None
|
||||||
|
|
||||||
def hasWebcamSupport():
|
try:
|
||||||
if cv == None and win32vidcap == None:
|
#Use the vidcap library directly from the VideoCapture package. (Windows only)
|
||||||
return False
|
# http://videocapture.sourceforge.net/
|
||||||
if not os.path.exists(getFFMPEGpath()):
|
# We're using the binary interface, not the python interface, so we don't depend on PIL
|
||||||
return False
|
import vidcap as win32vidcap
|
||||||
return True
|
except:
|
||||||
|
win32vidcap = None
|
||||||
def getFFMPEGpath():
|
|
||||||
if platform.system() == "Windows":
|
def hasWebcamSupport():
|
||||||
return os.path.normpath(os.path.join(os.path.split(__file__)[0], "../ffmpeg.exe"))
|
if cv == None and win32vidcap == None:
|
||||||
elif os.path.exists('/usr/bin/ffmpeg'):
|
return False
|
||||||
return '/usr/bin/ffmpeg'
|
if not os.path.exists(getFFMPEGpath()):
|
||||||
return os.path.normpath(os.path.join(os.path.split(__file__)[0], "../ffmpeg"))
|
return False
|
||||||
|
return True
|
||||||
class webcam(object):
|
|
||||||
def __init__(self):
|
|
||||||
self._cam = None
|
def getFFMPEGpath():
|
||||||
self._overlayImage = toolbarUtil.getBitmapImage("cura-overlay.png")
|
if platform.system() == "Windows":
|
||||||
self._overlayUltimaker = toolbarUtil.getBitmapImage("ultimaker-overlay.png")
|
return os.path.normpath(os.path.join(os.path.split(__file__)[0], "../ffmpeg.exe"))
|
||||||
if cv != None:
|
elif os.path.exists('/usr/bin/ffmpeg'):
|
||||||
self._cam = highgui.cvCreateCameraCapture(-1)
|
return '/usr/bin/ffmpeg'
|
||||||
elif win32vidcap != None:
|
return os.path.normpath(os.path.join(os.path.split(__file__)[0], "../ffmpeg"))
|
||||||
try:
|
|
||||||
self._cam = win32vidcap.new_Dev(0, False)
|
|
||||||
except:
|
class webcam(object):
|
||||||
pass
|
def __init__(self):
|
||||||
|
self._cam = None
|
||||||
self._doTimelaps = False
|
self._overlayImage = wx.Bitmap(getPathForImage('cura-overlay.png'))
|
||||||
self._bitmap = None
|
self._overlayUltimaker = wx.Bitmap(getPathForImage('ultimaker-overlay.png'))
|
||||||
|
if cv != None:
|
||||||
def hasCamera(self):
|
self._cam = highgui.cvCreateCameraCapture(-1)
|
||||||
return self._cam != None
|
elif win32vidcap != None:
|
||||||
|
try:
|
||||||
def propertyPages(self):
|
self._cam = win32vidcap.new_Dev(0, False)
|
||||||
if self._cam == None:
|
except:
|
||||||
return []
|
pass
|
||||||
if cv != None:
|
|
||||||
#TODO Make an OpenCV property page
|
self._doTimelaps = False
|
||||||
return []
|
self._bitmap = None
|
||||||
elif win32vidcap != None:
|
|
||||||
return ['Image properties', 'Format properties']
|
def hasCamera(self):
|
||||||
|
return self._cam != None
|
||||||
def openPropertyPage(self, pageType = 0):
|
|
||||||
if self._cam == None:
|
def propertyPages(self):
|
||||||
return
|
if self._cam == None:
|
||||||
if cv != None:
|
return []
|
||||||
pass
|
if cv != None:
|
||||||
elif win32vidcap != None:
|
#TODO Make an OpenCV property page
|
||||||
if pageType == 0:
|
return []
|
||||||
self._cam.displaycapturefilterproperties()
|
elif win32vidcap != None:
|
||||||
else:
|
return ['Image properties', 'Format properties']
|
||||||
del self._cam
|
|
||||||
self._cam = None
|
def openPropertyPage(self, pageType=0):
|
||||||
tmp = win32vidcap.new_Dev(0, False)
|
if self._cam == None:
|
||||||
tmp.displaycapturepinproperties()
|
return
|
||||||
self._cam = tmp
|
if cv != None:
|
||||||
|
pass
|
||||||
def takeNewImage(self):
|
elif win32vidcap != None:
|
||||||
if self._cam == None:
|
if pageType == 0:
|
||||||
return
|
self._cam.displaycapturefilterproperties()
|
||||||
if cv != None:
|
else:
|
||||||
frame = cv.QueryFrame(self._cam)
|
del self._cam
|
||||||
cv.CvtColor(frame, frame, cv.CV_BGR2RGB)
|
self._cam = None
|
||||||
bitmap = wx.BitmapFromBuffer(frame.width, frame.height, frame.imageData)
|
tmp = win32vidcap.new_Dev(0, False)
|
||||||
elif win32vidcap != None:
|
tmp.displaycapturepinproperties()
|
||||||
buffer, width, height = self._cam.getbuffer()
|
self._cam = tmp
|
||||||
try:
|
|
||||||
wxImage = wx.EmptyImage(width, height)
|
def takeNewImage(self):
|
||||||
wxImage.SetData(buffer[::-1])
|
if self._cam == None:
|
||||||
if self._bitmap != None:
|
return
|
||||||
del self._bitmap
|
if cv != None:
|
||||||
bitmap = wxImage.ConvertToBitmap()
|
frame = cv.QueryFrame(self._cam)
|
||||||
del wxImage
|
cv.CvtColor(frame, frame, cv.CV_BGR2RGB)
|
||||||
del buffer
|
bitmap = wx.BitmapFromBuffer(frame.width, frame.height, frame.imageData)
|
||||||
except:
|
elif win32vidcap != None:
|
||||||
pass
|
buffer, width, height = self._cam.getbuffer()
|
||||||
|
try:
|
||||||
dc = wx.MemoryDC()
|
wxImage = wx.EmptyImage(width, height)
|
||||||
dc.SelectObject(bitmap)
|
wxImage.SetData(buffer[::-1])
|
||||||
dc.DrawBitmap(self._overlayImage, bitmap.GetWidth() - self._overlayImage.GetWidth() - 5, 5, True)
|
if self._bitmap != None:
|
||||||
if profile.getPreference('machine_type') == 'ultimaker':
|
del self._bitmap
|
||||||
dc.DrawBitmap(self._overlayUltimaker, (bitmap.GetWidth() - self._overlayUltimaker.GetWidth()) / 2, bitmap.GetHeight() - self._overlayUltimaker.GetHeight() - 5, True)
|
bitmap = wxImage.ConvertToBitmap()
|
||||||
dc.SelectObject(wx.NullBitmap)
|
del wxImage
|
||||||
|
del buffer
|
||||||
self._bitmap = bitmap
|
except:
|
||||||
|
pass
|
||||||
if self._doTimelaps:
|
|
||||||
filename = os.path.normpath(os.path.join(os.path.split(__file__)[0], "../__tmp_snap", "__tmp_snap_%04d.jpg" % (self._snapshotCount)))
|
dc = wx.MemoryDC()
|
||||||
self._snapshotCount += 1
|
dc.SelectObject(bitmap)
|
||||||
bitmap.SaveFile(filename, wx.BITMAP_TYPE_JPEG)
|
dc.DrawBitmap(self._overlayImage, bitmap.GetWidth() - self._overlayImage.GetWidth() - 5, 5, True)
|
||||||
|
if profile.getPreference('machine_type') == 'ultimaker':
|
||||||
return self._bitmap
|
dc.DrawBitmap(self._overlayUltimaker, (bitmap.GetWidth() - self._overlayUltimaker.GetWidth()) / 2,
|
||||||
|
bitmap.GetHeight() - self._overlayUltimaker.GetHeight() - 5, True)
|
||||||
def getLastImage(self):
|
dc.SelectObject(wx.NullBitmap)
|
||||||
return self._bitmap
|
|
||||||
|
self._bitmap = bitmap
|
||||||
def startTimelaps(self, filename):
|
|
||||||
if self._cam == None:
|
if self._doTimelaps:
|
||||||
return
|
filename = os.path.normpath(os.path.join(os.path.split(__file__)[0], "../__tmp_snap",
|
||||||
self._cleanTempDir()
|
"__tmp_snap_%04d.jpg" % (self._snapshotCount)))
|
||||||
self._timelapsFilename = filename
|
self._snapshotCount += 1
|
||||||
self._snapshotCount = 0
|
bitmap.SaveFile(filename, wx.BITMAP_TYPE_JPEG)
|
||||||
self._doTimelaps = True
|
|
||||||
print "startTimelaps"
|
return self._bitmap
|
||||||
|
|
||||||
def endTimelaps(self):
|
def getLastImage(self):
|
||||||
if self._doTimelaps:
|
return self._bitmap
|
||||||
ffmpeg = getFFMPEGpath()
|
|
||||||
basePath = os.path.normpath(os.path.join(os.path.split(__file__)[0], "../__tmp_snap", "__tmp_snap_%04d.jpg"))
|
def startTimelaps(self, filename):
|
||||||
subprocess.call([ffmpeg, '-r', '12.5', '-i', basePath, '-vcodec', 'mpeg2video', '-pix_fmt', 'yuv420p', '-r', '25', '-y', '-b:v', '1500k', '-f', 'vob', self._timelapsFilename])
|
if self._cam == None:
|
||||||
self._doTimelaps = False
|
return
|
||||||
|
self._cleanTempDir()
|
||||||
def _cleanTempDir(self):
|
self._timelapsFilename = filename
|
||||||
basePath = os.path.normpath(os.path.join(os.path.split(__file__)[0], "../__tmp_snap"))
|
self._snapshotCount = 0
|
||||||
try:
|
self._doTimelaps = True
|
||||||
os.makedirs(basePath)
|
print "startTimelaps"
|
||||||
except:
|
|
||||||
pass
|
def endTimelaps(self):
|
||||||
for filename in glob.iglob(basePath + "/*.jpg"):
|
if self._doTimelaps:
|
||||||
os.remove(filename)
|
ffmpeg = getFFMPEGpath()
|
||||||
|
basePath = os.path.normpath(
|
||||||
|
os.path.join(os.path.split(__file__)[0], "../__tmp_snap", "__tmp_snap_%04d.jpg"))
|
||||||
|
subprocess.call(
|
||||||
|
[ffmpeg, '-r', '12.5', '-i', basePath, '-vcodec', 'mpeg2video', '-pix_fmt', 'yuv420p', '-r', '25', '-y',
|
||||||
|
'-b:v', '1500k', '-f', 'vob', self._timelapsFilename])
|
||||||
|
self._doTimelaps = False
|
||||||
|
|
||||||
|
def _cleanTempDir(self):
|
||||||
|
basePath = os.path.normpath(os.path.join(os.path.split(__file__)[0], "../__tmp_snap"))
|
||||||
|
try:
|
||||||
|
os.makedirs(basePath)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
for filename in glob.iglob(basePath + "/*.jpg"):
|
||||||
|
os.remove(filename)
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
# coding=utf-8
|
||||||
|
from __future__ import absolute_import
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
__all__ = ['getPathForResource', 'getPathForImage', 'getPathForMesh']
|
||||||
|
|
||||||
|
|
||||||
|
if sys.platform.startswith('darwin'):
|
||||||
|
if hasattr(sys, 'frozen'):
|
||||||
|
from Foundation import *
|
||||||
|
imagesPath = os.path.join(NSBundle.mainBundle().resourcePath(), 'images')
|
||||||
|
meshesPath = os.path.join(NSBundle.mainBundle().resourcePath(), 'images')
|
||||||
|
else:
|
||||||
|
imagesPath = os.path.join(os.path.dirname(__file__), "../images")
|
||||||
|
meshesPath = os.path.join(os.path.dirname(__file__), "../images")
|
||||||
|
else:
|
||||||
|
if hasattr(sys, 'frozen'):
|
||||||
|
imagesPath = os.path.join(os.path.dirname(__file__), "../../images")
|
||||||
|
meshesPath = os.path.join(os.path.dirname(__file__), "../../images")
|
||||||
|
else:
|
||||||
|
imagesPath = os.path.join(os.path.dirname(__file__), "../images")
|
||||||
|
meshesPath = os.path.join(os.path.dirname(__file__), "../images")
|
||||||
|
|
||||||
|
|
||||||
|
def getPathForResource(dir, resource_name):
|
||||||
|
assert os.path.isdir(dir), "{p} is not a directory".format(p=dir)
|
||||||
|
path = os.path.normpath(os.path.join(dir, resource_name))
|
||||||
|
assert os.path.isfile(path), "{p} is not a file.".format(p=path)
|
||||||
|
return path
|
||||||
|
|
||||||
|
def getPathForImage(name):
|
||||||
|
return getPathForResource(imagesPath, name)
|
||||||
|
|
||||||
|
def getPathForMesh(name):
|
||||||
|
return getPathForResource(meshesPath, name)
|
Loading…
Reference in New Issue