Added CQGI debug objects.
This commit is contained in:
parent
2cdd504888
commit
21200cc10d
|
@ -9,6 +9,7 @@ import ExportCQ, ImportCQ
|
||||||
import module_locator
|
import module_locator
|
||||||
import Settings
|
import Settings
|
||||||
import Shared
|
import Shared
|
||||||
|
from random import random
|
||||||
from cadquery import cqgi
|
from cadquery import cqgi
|
||||||
from Helpers import show
|
from Helpers import show
|
||||||
|
|
||||||
|
@ -130,7 +131,7 @@ class CadQueryExecuteScript:
|
||||||
scriptText = cqCodePane.toPlainText().encode('utf-8')
|
scriptText = cqCodePane.toPlainText().encode('utf-8')
|
||||||
|
|
||||||
# Check to see if we are executig a CQGI compliant script
|
# Check to see if we are executig a CQGI compliant script
|
||||||
if "build_object(" in scriptText and "# build_object(" not in scriptText and "#build_boject(" not in scriptText:
|
if ("build_object(" in scriptText and "# build_object(" not in scriptText and "#build_boject(" not in scriptText) or ("debug(" in scriptText and "# debug(" not in scriptText and "#debug(" not in scriptText):
|
||||||
FreeCAD.Console.PrintMessage("Executing CQGI-compliant script.\r\n")
|
FreeCAD.Console.PrintMessage("Executing CQGI-compliant script.\r\n")
|
||||||
|
|
||||||
# A repreentation of the CQ script with all the metadata attached
|
# A repreentation of the CQ script with all the metadata attached
|
||||||
|
@ -173,6 +174,16 @@ class CadQueryExecuteScript:
|
||||||
show(result.shape, result.options["rgba"])
|
show(result.shape, result.options["rgba"])
|
||||||
else:
|
else:
|
||||||
show(result.shape)
|
show(result.shape)
|
||||||
|
|
||||||
|
for debugObj in build_result.debugObjects:
|
||||||
|
# Mark this as a debug object
|
||||||
|
debugObj.shape.val().label = "Debug" + str(random())
|
||||||
|
|
||||||
|
# Apply options to the show function if any were provided
|
||||||
|
if debugObj.options and debugObj.options["rgba"]:
|
||||||
|
show(debugObj.shape, debugObj.options["rgba"])
|
||||||
|
else:
|
||||||
|
show(debugObj.shape, (255, 0, 0, 0.80))
|
||||||
else:
|
else:
|
||||||
FreeCAD.Console.PrintError("Error executing CQGI-compliant script. " + str(build_result.exception) + "\r\n")
|
FreeCAD.Console.PrintError("Error executing CQGI-compliant script. " + str(build_result.exception) + "\r\n")
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -2184,6 +2184,44 @@ class Workplane(CQ):
|
||||||
|
|
||||||
return self.newObject([newS])
|
return self.newObject([newS])
|
||||||
|
|
||||||
|
def intersect(self, toIntersect, combine=True, clean=True):
|
||||||
|
"""
|
||||||
|
Intersects the provided solid from the current solid.
|
||||||
|
|
||||||
|
if combine=True, the result and the original are updated to point to the new object
|
||||||
|
if combine=False, the result will be on the stack, but the original is unmodified
|
||||||
|
|
||||||
|
:param toIntersect: object to intersect
|
||||||
|
:type toIntersect: a solid object, or a CQ object having a solid,
|
||||||
|
:param boolean clean: call :py:meth:`clean` afterwards to have a clean shape
|
||||||
|
:raises: ValueError if there is no solid to intersect with in the chain
|
||||||
|
:return: a CQ object with the resulting object selected
|
||||||
|
"""
|
||||||
|
|
||||||
|
# look for parents to intersect with
|
||||||
|
solidRef = self.findSolid(searchStack=True, searchParents=True)
|
||||||
|
|
||||||
|
if solidRef is None:
|
||||||
|
raise ValueError("Cannot find solid to intersect with")
|
||||||
|
solidToIntersect = None
|
||||||
|
|
||||||
|
if isinstance(toIntersect, CQ):
|
||||||
|
solidToIntersect = toIntersect.val()
|
||||||
|
elif isinstance(toIntersect, Solid):
|
||||||
|
solidToIntersect = toIntersect
|
||||||
|
else:
|
||||||
|
raise ValueError("Cannot intersect type '{}'".format(type(toIntersect)))
|
||||||
|
|
||||||
|
newS = solidRef.intersect(solidToIntersect)
|
||||||
|
|
||||||
|
if clean: newS = newS.clean()
|
||||||
|
|
||||||
|
if combine:
|
||||||
|
solidRef.wrapped = newS.wrapped
|
||||||
|
|
||||||
|
return self.newObject([newS])
|
||||||
|
|
||||||
|
|
||||||
def cutBlind(self, distanceToCut, clean=True):
|
def cutBlind(self, distanceToCut, clean=True):
|
||||||
"""
|
"""
|
||||||
Use all un-extruded wires in the parent chain to create a prismatic cut from existing solid.
|
Use all un-extruded wires in the parent chain to create a prismatic cut from existing solid.
|
||||||
|
|
|
@ -109,10 +109,8 @@ class CQModel(object):
|
||||||
c = compile(self.ast_tree, CQSCRIPT, 'exec')
|
c = compile(self.ast_tree, CQSCRIPT, 'exec')
|
||||||
exec (c, env)
|
exec (c, env)
|
||||||
result.set_debug(collector.debugObjects )
|
result.set_debug(collector.debugObjects )
|
||||||
if collector.has_results():
|
result.set_success_result(collector.outputObjects)
|
||||||
result.set_success_result(collector.outputObjects)
|
|
||||||
else:
|
|
||||||
raise NoOutputError("Script did not call build_object-- no output available.")
|
|
||||||
except Exception, ex:
|
except Exception, ex:
|
||||||
#print "Error Executing Script:"
|
#print "Error Executing Script:"
|
||||||
result.set_failure_result(ex)
|
result.set_failure_result(ex)
|
||||||
|
@ -171,7 +169,8 @@ class BuildResult(object):
|
||||||
|
|
||||||
def set_success_result(self, results):
|
def set_success_result(self, results):
|
||||||
self.results = results
|
self.results = results
|
||||||
self.first_result = self.results[0]
|
if len(self.results) > 0:
|
||||||
|
self.first_result = self.results[0]
|
||||||
self.success = True
|
self.success = True
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -604,6 +604,20 @@ class TestCadQuery(BaseTest):
|
||||||
|
|
||||||
self.assertEqual(10,currentS.faces().size())
|
self.assertEqual(10,currentS.faces().size())
|
||||||
|
|
||||||
|
def testIntersect(self):
|
||||||
|
"""
|
||||||
|
Tests the intersect function.
|
||||||
|
"""
|
||||||
|
s = Workplane(Plane.XY())
|
||||||
|
currentS = s.rect(2.0, 2.0).extrude(0.5)
|
||||||
|
toIntersect = s.rect(1.0, 1.0).extrude(1)
|
||||||
|
|
||||||
|
currentS.intersect(toIntersect.val())
|
||||||
|
|
||||||
|
self.assertEqual(6, currentS.faces().size())
|
||||||
|
bb = currentS.val().BoundingBox()
|
||||||
|
self.assertListEqual([bb.xlen, bb.ylen, bb.zlen], [1, 1, 0.5])
|
||||||
|
|
||||||
def testBoundingBox(self):
|
def testBoundingBox(self):
|
||||||
"""
|
"""
|
||||||
Tests the boudingbox center of a model
|
Tests the boudingbox center of a model
|
||||||
|
@ -1408,6 +1422,3 @@ class TestCadQuery(BaseTest):
|
||||||
self.assertTupleAlmostEquals(delta.toTuple(),
|
self.assertTupleAlmostEquals(delta.toTuple(),
|
||||||
(0.,0.,2.*h),
|
(0.,0.,2.*h),
|
||||||
decimal_places)
|
decimal_places)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user