chiark / gitweb /
Add more documentation, fix commandline slicing.
authordaid <daid303@gmail.com>
Tue, 4 Feb 2014 11:38:19 +0000 (12:38 +0100)
committerdaid <daid303@gmail.com>
Tue, 4 Feb 2014 11:38:19 +0000 (12:38 +0100)
17 files changed:
Cura/cura.py
Cura/doctest.py
Cura/serialCommunication.py
Cura/util/explorer.py
Cura/util/meshLoaders/amf.py
Cura/util/meshLoaders/dae.py
Cura/util/meshLoaders/obj.py
Cura/util/meshLoaders/stl.py
Cura/util/polygon.py
Cura/util/profile.py
Cura/util/removableStorage.py
Cura/util/resources.py
Cura/util/sliceEngine.py
Cura/util/util3d.py
Cura/util/validators.py
Cura/util/version.py
Cura/util/youmagine.py

index 2208d983f7b02aaf9901b1383ca4ba2089d5b4a5..a8b22ef53a33d86cf2eebf5e3479f8ae6fb71dd9 100644 (file)
@@ -46,26 +46,25 @@ def main():
                from Cura.util import meshLoader
                import shutil
 
-               def commandlineProgressCallback(progress, ready):
-                       if progress >= 0 and not ready:
-                               print 'Preparing: %d%%' % (progress * 100)
+               def commandlineProgressCallback(progress):
+                       if progress >= 0:
+                               #print 'Preparing: %d%%' % (progress * 100)
+                               pass
                scene = objectScene.Scene()
                scene.updateMachineDimensions()
-               slicer = sliceEngine.Slicer(commandlineProgressCallback)
+               engine = sliceEngine.Engine(commandlineProgressCallback)
                for m in meshLoader.loadMeshes(args[0]):
                        scene.add(m)
-               slicer.runSlicer(scene)
-               slicer.wait()
-               profile.replaceGCodeTagsFromSlicer(slicer.getGCodeFilename(), slicer)
+               engine.runEngine(scene)
+               engine.wait()
 
-               if options.output:
-                       shutil.copyfile(slicer.getGCodeFilename(), options.output)
-                       print 'GCode file saved : %s' % options.output
-               else:
-                       shutil.copyfile(slicer.getGCodeFilename(), args[0] + '.gcode')
-                       print 'GCode file saved as: %s' % (args[0] + '.gcode')
+               if not options.output:
+                       options.output = args[0] + '.gcode'
+               with open(options.output, "wb") as f:
+                       f.write(engine.getResult().getGCode())
+               print 'GCode file saved : %s' % options.output
 
-               slicer.cleanup()
+               engine.cleanup()
        else:
                from Cura.gui import app
                app.CuraApp(args).MainLoop()
index 18139c0855b2a0c0038637de264869d050d4a0a9..3640367e675612158da504f1feecba44d53448d1 100644 (file)
@@ -11,6 +11,7 @@ import types
 import random
 
 def treeWalk(moduleList, dirname, fnames):
+       """ Callback from the os.path.walk function, see if the given path is a module and import it to put it in the moduleList """
        dirname = dirname.replace("\\", ".").replace("/", ".")
        if dirname == 'Cura.util.pymclevel':
                return
@@ -33,6 +34,11 @@ def treeWalk(moduleList, dirname, fnames):
                        print "Failed to load: %s" % (fullName)
 
 def main():
+       """
+       Main doctest function.
+       Calculate how many things are documented and not documented yet.
+       And report a random selection of undocumented functions/ modules.
+       """
        moduleList = []
        os.path.walk("Cura", treeWalk, moduleList)
        moduleDocCount = 0
@@ -48,6 +54,11 @@ def main():
                        undocList.append(module.__name__)
                for name in dir(module):
                        a = getattr(module, name)
+                       try:
+                               if not inspect.getfile(a).startswith('Cura'):
+                                       continue
+                       except:
+                               continue
                        if type(a) is types.FunctionType:
                                functionCount += 1
                                if inspect.getdoc(a):
@@ -74,6 +85,7 @@ def main():
        print '%d/%d modules have documentation.' % (moduleDocCount, len(moduleList))
        print '%d/%d functions have documentation.' % (functionDocCount, functionCount)
        print '%d/%d types have documentation.' % (typeDocCount, typeCount)
+       print '%.1f%% documented.' % (float(moduleDocCount + functionDocCount + typeDocCount) / float(len(moduleList) + functionCount + typeCount) * 100.0)
        print ''
        print 'You might want to document:'
        for n in xrange(0, 10):
index 6a8b1a0501370f50f25e1976dd21383bf3c5715f..0534a84bfd34ae6caa6e308791177c90b892a03d 100644 (file)
@@ -1,8 +1,12 @@
-__copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AGPLv3 License"
+"""
+Serial communication with the printer for printing is done from a separate process,
+this to ensure that the PIL does not block the serial printing.
 
-# Serial communication with the printer for printing is done from a separate process,
-# this to ensure that the PIL does not block the serial printing.
+This file is the 2nd process that is started to handle communication with the printer.
+And handles all communication with the initial process.
+"""
 
+__copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AGPLv3 License"
 import sys
 import time
 import os
index 35991823070c9abb98a341c05b789b7681072adf..1e2a5a0b21220a34c5fac85ed398e400c602b221 100644 (file)
@@ -1,3 +1,7 @@
+"""
+Simple utility module to open "explorer" file dialogs.
+The name "explorer" comes from the windows file explorer, which is called explorer.
+"""
 __copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AGPLv3 License"
 
 import sys
@@ -5,6 +9,7 @@ import os
 import subprocess
 
 def hasExplorer():
+       """Check if we have support for opening file dialog windows."""
        if sys.platform == 'win32' or sys.platform == 'cygwin' or sys.platform == 'darwin':
                return True
        if sys.platform == 'linux2':
@@ -15,17 +20,20 @@ def hasExplorer():
        return False
 
 def openExplorer(filename):
+       """Open an file dialog window in the directory of a file, and select the file."""
        if sys.platform == 'win32' or sys.platform == 'cygwin':
                subprocess.Popen(r'explorer /select,"%s"' % (filename))
        if sys.platform == 'darwin':
                subprocess.Popen(['open', '-R', filename])
        if sys.platform.startswith('linux'):
+               #TODO: On linux we cannot seem to select a certain file, only open the specified path.
                if os.path.isfile('/usr/bin/nautilus'):
                        subprocess.Popen(['/usr/bin/nautilus', os.path.split(filename)[0]])
                elif os.path.isfile('/usr/bin/dolphin'):
                        subprocess.Popen(['/usr/bin/dolphin', os.path.split(filename)[0]])
 
 def openExplorerPath(filename):
+       """Open a file dialog inside a directory, without selecting any file."""
        if sys.platform == 'win32' or sys.platform == 'cygwin':
                subprocess.Popen(r'explorer "%s"' % (filename))
        if sys.platform == 'darwin':
index 0c63151b88bd032332f57bb4f6e4ac6550875272..848f8bd03a8bd23fe0a4433bbe49e8d709535839 100644 (file)
@@ -1,3 +1,10 @@
+"""
+AMF file reader.
+AMF files are the proposed replacement for STL. AMF is an open standard to share 3D manufacturing files.
+Many of the features found in AMF are currently not yet support in Cura. Most important the curved surfaces.
+
+http://en.wikipedia.org/wiki/Additive_Manufacturing_File_Format
+"""
 __copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AGPLv3 License"
 
 import cStringIO as StringIO
index 8798859a623314405b63c6effd202db13b492213..f173ddf10f768ca113737e49670c25c57eb60421 100644 (file)
@@ -1,3 +1,10 @@
+"""
+DAE are COLLADA files.
+The DAE reader is a limited COLLADA reader. And has only been tested with DAE exports from SketchUp, http://www.sketchup.com/
+The reason for this reader in Cura is that the free version of SketchUp by default does not support any other format that we can read.
+
+http://en.wikipedia.org/wiki/COLLADA
+"""
 __copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AGPLv3 License"
 
 from  xml.parsers.expat import ParserCreate
index c5a2be9ff54a0ec0cf079ec74ae531659c85f954..8c1fc083335b9e3b270e476624e9613c17ab0a9b 100644 (file)
@@ -1,3 +1,10 @@
+"""
+OBJ file reader.
+OBJ are wavefront object files. These are quite common and can be exported from a lot of 3D tools.
+Only vertex information is read from the OBJ file, information about textures and normals is ignored.
+
+http://en.wikipedia.org/wiki/Wavefront_.obj_file
+"""
 __copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AGPLv3 License"
 
 import os
index 029a0b860603bfe54397cddea9718ff1e23a5b2b..dc7c56ed1bf354e012253e904e1202f62a4974dd 100644 (file)
@@ -1,3 +1,15 @@
+"""
+STL file mesh loader.
+STL is the most common file format used for 3D printing right now.
+STLs come in 2 flavors.
+       Binary, which is easy and quick to read.
+       Ascii, which is harder to read, as can come with windows, mac and unix style newlines.
+       The ascii reader has been designed so it has great compatibility with all kinds of formats or slightly broken exports from tools.
+
+This module also contains a function to save objects as an STL file.
+
+http://en.wikipedia.org/wiki/STL_(file_format)
+"""
 __copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AGPLv3 License"
 
 import sys
index 8772139f54eb28a52f515a65151c263a7e7a56ae..2ec81952d19962ab7de94c492811dc5b423d3c48 100644 (file)
@@ -1,8 +1,12 @@
+"""
+The polygon module has functions that assist in working with 2D convex polygons.
+"""
 __copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AGPLv3 License"
 
 import numpy
 
 def convexHull(pointList):
+       """ Create a convex hull from a list of points. """
        def _isRightTurn((p, q, r)):
                sum1 = q[0]*r[1] + p[0]*q[1] + r[0]*p[1]
                sum2 = q[0]*p[1] + r[0]*q[1] + p[0]*r[1]
@@ -45,6 +49,7 @@ def convexHull(pointList):
        return numpy.array(upper + lower, numpy.float32)
 
 def minkowskiHull(a, b):
+       """Calculate the minkowski hull of 2 convex polygons"""
        points = numpy.zeros((len(a) * len(b), 2))
        for n in xrange(0, len(a)):
                for m in xrange(0, len(b)):
@@ -52,6 +57,11 @@ def minkowskiHull(a, b):
        return convexHull(points.copy())
 
 def projectPoly(poly, normal):
+       """
+       Project a convex polygon on a given normal.
+       A projection of a convex polygon on a infinite line is a finite line.
+       Give the min and max value on the normal line.
+       """
        pMin = numpy.dot(normal, poly[0])
        pMax = pMin
        for n in xrange(1 , len(poly)):
@@ -61,6 +71,7 @@ def projectPoly(poly, normal):
        return pMin, pMax
 
 def polygonCollision(polyA, polyB):
+       """ Check if convexy polygon A and B collide, return True if this is the case. """
        for n in xrange(0, len(polyA)):
                p0 = polyA[n-1]
                p1 = polyA[n]
@@ -88,6 +99,7 @@ def polygonCollision(polyA, polyB):
        return True
 
 def polygonCollisionPushVector(polyA, polyB):
+       """ Check if convex polygon A and B collide, return the vector of penetration if this is the case, else return False. """
        retSize = 10000000.0
        ret = False
        for n in xrange(0, len(polyA)):
@@ -124,8 +136,10 @@ def polygonCollisionPushVector(polyA, polyB):
                        retSize = size
        return ret
 
-#Check if polyA is fully inside of polyB.
 def fullInside(polyA, polyB):
+       """
+       Check if convex polygon A is completely inside of convex polygon B.
+       """
        for n in xrange(0, len(polyA)):
                p0 = polyA[n-1]
                p1 = polyA[n]
@@ -153,9 +167,11 @@ def fullInside(polyA, polyB):
        return True
 
 def isLeft(a, b, c):
+       """ Check if C is left of the infinite line from A to B """
        return ((b[0] - a[0])*(c[1] - a[1]) - (b[1] - a[1])*(c[0] - a[0])) > 0
 
 def lineLineIntersection(p0, p1, p2, p3):
+       """ Return the intersection of the infinite line trough points p0 and p1 and infinite line trough points p2 and p3. """
        A1 = p1[1] - p0[1]
        B1 = p0[0] - p1[0]
        C1 = A1*p0[0] + B1*p0[1]
@@ -170,6 +186,7 @@ def lineLineIntersection(p0, p1, p2, p3):
        return [(B2*C1 - B1*C2)/det, (A1 * C2 - A2 * C1) / det]
 
 def clipConvex(poly0, poly1):
+       """ Cut the convex polygon 0 so that it completely fits in convex polygon 1, any part sticking out of polygon 1 is cut off """
        res = poly0
        for p1idx in xrange(0, len(poly1)):
                src = res
index 8a764ac659647d06a65c83ccbd52f89dcbd5fc3d..1e3e4416cf5420c088324e554766cfe10804cc94 100644 (file)
@@ -1,3 +1,7 @@
+"""
+The profile module contains all the settings for Cura.
+These settings can be globally accessed and modified.
+"""
 from __future__ import division
 __copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AGPLv3 License"
 
index 9bf7e4fd00e80d6eba455073e10635511785520d..812e9e9866dd8e5555f3d6f220275b7bd86673f1 100644 (file)
@@ -1,3 +1,10 @@
+"""
+This module handles detection and clean ejection of removable storage. (Mainly SD cards)
+This is OS depended.
+       On windows it looks for removable storage drives.
+       On MacOS it specificly looks for SD cards.
+       On Linux it looks for anything mounted in /media/
+"""
 __copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AGPLv3 License"
 import platform
 import string
index 70ac64e5f78f45d4a7b33cc4d1fc460dcd669208..1d7bcc472fcf8b82e140f4790dbb26a8d9167f95 100644 (file)
@@ -1,3 +1,7 @@
+"""
+Helper module to get easy access to the path where resources are stored.
+This is because the resource location is depended on the packaging method and OS
+"""
 __copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AGPLv3 License"
 
 import os
index 12388e76ca2d5f30bbcdf2d0a2087c872b40d782..51e8a59ec83ea4d63b48e624e860a6f74365c0b4 100644 (file)
@@ -1,3 +1,7 @@
+"""
+Slice engine communication.
+This module handles all communication with the slicing engine.
+"""
 __copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AGPLv3 License"
 import subprocess
 import time
index db52e7919458cbe04e75f6c806d0303e48f66b87..f923f37bc969355fb9ae1000809439e9d19cea67 100644 (file)
@@ -1,9 +1,17 @@
+"""
+The util3d module a vector class to work with 3D points. All the basic math operators have been overloaded to work on this object.
+This module is deprecated and only used by the SplitModels function.
+
+Use numpy arrays instead to work with vectors.
+"""
 __copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AGPLv3 License"
 
 import math
 
 class Vector3(object):
+       """ 3D vector object. """
        def __init__(self, x=0.0, y=0.0, z=0.0):
+               """Create a new 3D vector"""
                self.x = x
                self.y = y
                self.z = z
index f920aa9764206bc526579f9564dfaa97071b52bc..15673791c6354aaac08407596bdd1410d304a680 100644 (file)
@@ -1,3 +1,12 @@
+"""
+Setting validators.
+These are the validators for various profile settings, each validator can be attached to a setting.
+The validators can be queried to see if the setting is valid.
+There are 3 possible outcomes:
+       Valid   - No problems found
+       Warning - The value is valid, but not recommended
+       Error   - The value is not a proper number, out of range, or some other way wrong.
+"""
 from __future__ import division
 __copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AGPLv3 License"
 
index 2a34ac384d40e468204a6c05e4a7e4f70b318698..475e0c46dec336abf4eb9d7ead02eff68b020ec6 100644 (file)
@@ -1,3 +1,7 @@
+"""
+The version utility module is used to get the current Cura version, and check for updates.
+It can also see if we are running a development build of Cura.
+"""
 __copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AGPLv3 License"
 
 import os
index 6e77da7b5bfa8aad1a10524fab4c0821ed693882..6e0615c65210e6b27658e18785f9ded07cb317fa 100644 (file)
@@ -1,3 +1,7 @@
+"""
+YouMagine communication module.
+This module handles all communication with the YouMagine API.
+"""
 __copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AGPLv3 License"
 
 import json