From 8d0af8fcbf8b0939ac44c95f1a9ae6710add4041 Mon Sep 17 00:00:00 2001 From: sliptonic Date: Mon, 19 Sep 2016 15:27:54 -0500 Subject: [PATCH] PathSurface now uses base object from job. This means Surface won't work on Meshes directly. They should be converted so FreeCAD solids first. Surface still needs lots of work. --- src/Mod/Path/CMakeLists.txt | 2 + src/Mod/Path/Gui/Resources/Path.qrc | 4 +- .../Path/Gui/Resources/panels/ContourEdit.ui | 365 ++++++++++++++++++ src/Mod/Path/PathScripts/PathContour.py | 15 +- src/Mod/Path/PathScripts/PathJob.py | 24 +- src/Mod/Path/PathScripts/PathProfileEdges.py | 4 +- src/Mod/Path/PathScripts/PathSurface.py | 66 ++-- .../PathScripts/PathToolLibraryManager.py | 17 +- 8 files changed, 445 insertions(+), 52 deletions(-) create mode 100644 src/Mod/Path/Gui/Resources/panels/ContourEdit.ui diff --git a/src/Mod/Path/CMakeLists.txt b/src/Mod/Path/CMakeLists.txt index a3be495c4..63b46d50e 100644 --- a/src/Mod/Path/CMakeLists.txt +++ b/src/Mod/Path/CMakeLists.txt @@ -14,6 +14,7 @@ INSTALL( ) SET(PathScripts_SRCS + PathCommands.py PathScripts/__init__.py PathScripts/PostUtils.py PathScripts/example_pre.py @@ -27,6 +28,7 @@ SET(PathScripts_SRCS PathScripts/rml_post.py PathScripts/TooltableEditor.py PathScripts/PathProfile.py + PathScripts/PathProfileEdges.py PathScripts/PathContour.py PathScripts/PathPocket.py PathScripts/PathDrilling.py diff --git a/src/Mod/Path/Gui/Resources/Path.qrc b/src/Mod/Path/Gui/Resources/Path.qrc index 3ee1fe973..0d50dca31 100644 --- a/src/Mod/Path/Gui/Resources/Path.qrc +++ b/src/Mod/Path/Gui/Resources/Path.qrc @@ -5,7 +5,7 @@ icons/Path-Compound.svg icons/Path-Shape.svg icons/Path-Profile.svg - icons/Path-Contour.svg + icons/Path-Contour.svg icons/Path-Pocket.svg icons/Path-Drilling.svg icons/Path-Job.svg @@ -80,5 +80,7 @@ panels/DlgToolCopy.ui panels/ToolEdit.ui panels/DlgJobChooser.ui + panels/ContourEdit.ui + panels/ProfileEdgesEdit.ui diff --git a/src/Mod/Path/Gui/Resources/panels/ContourEdit.ui b/src/Mod/Path/Gui/Resources/panels/ContourEdit.ui new file mode 100644 index 000000000..d68a4c97d --- /dev/null +++ b/src/Mod/Path/Gui/Resources/panels/ContourEdit.ui @@ -0,0 +1,365 @@ + + + TaskPanel + + + + 0 + 0 + 352 + 455 + + + + + 0 + 400 + + + + Contour + + + + + + 4 + + + + true + + + + 0 + 0 + 334 + 288 + + + + Contour works on shape outer loop but maybe could work on something else + + + + :/icons/Path-BaseGeometry.svg:/icons/Path-BaseGeometry.svg + + + Base Geometry + + + + + + + 0 + 0 + 334 + 288 + + + + + :/icons/Path-Depths.svg:/icons/Path-Depths.svg + + + Depths + + + + + + mm + + + + + + + Start Depth + + + + + + + mm + + + + + + + Final Depth + + + + + + + 3 + + + 0.100000000000000 + + + 1.000000000000000 + + + + + + + Step Down + + + + + + + + + 0 + 0 + 334 + 288 + + + + + :/icons/Path-Heights.svg:/icons/Path-Heights.svg + + + Heights + + + + QFormLayout::AllNonFixedFieldsGrow + + + + + mm + + + + + + + Safe Height + + + + + + + mm + + + + + + + Clearance Height + + + + + + + + + 0 + 0 + 334 + 288 + + + + Holding + + + + + + Add New + + + + + + + Delete + + + + + + + + Tag + + + + + Location + + + + + Height + + + + + Length + + + + + Angle + + + + + + + + + + 0 + 0 + 334 + 288 + + + + + :/icons/Path-OperationB.svg:/icons/Path-OperationB.svg + + + Operation + + + + QFormLayout::AllNonFixedFieldsGrow + + + + + + + + Direction + + + + + + + + CW + + + + + CCW + + + + + + + + + + + + + + Use Start Point + + + + + + + Use Compensation + + + + + + + Use End Point + + + + + + + + + + + + + Extra Offset + + + + + + + + + + Segment Length + + + + + + + + + + Roll Radius + + + + + + + + + + Plunge Angle + + + + + + + + + + + + + + + + + + Gui::InputField + QLineEdit +
Gui/InputField.h
+
+
+ + + + + +
diff --git a/src/Mod/Path/PathScripts/PathContour.py b/src/Mod/Path/PathScripts/PathContour.py index 6acb76abd..4d598e02a 100644 --- a/src/Mod/Path/PathScripts/PathContour.py +++ b/src/Mod/Path/PathScripts/PathContour.py @@ -248,7 +248,10 @@ class ObjectContour: edgelist = contourwire.Edges edgelist = Part.__sortEdges__(edgelist) - output += self._buildPathLibarea(obj, edgelist) + try: + output += self._buildPathLibarea(obj, edgelist) + except: + FreeCAD.Console.PrintError("Something unexpected happened. Unable to generate a contour path. Check project and tool config.") if obj.Active: path = Path.Path(output) obj.Path = path @@ -408,22 +411,24 @@ class CommandPathContour: class TaskPanel: def __init__(self): - #self.form = FreeCADGui.PySideUic.loadUi(":/panels/ContourEdit.ui") - self.form = FreeCADGui.PySideUic.loadUi(FreeCAD.getHomePath() + "Mod/Path/ContourEdit.ui") + self.form = FreeCADGui.PySideUic.loadUi(":/panels/ContourEdit.ui") + #self.form = FreeCADGui.PySideUic.loadUi(FreeCAD.getHomePath() + "Mod/Path/ContourEdit.ui") self.updating = False def accept(self): + print "removed" self.getFields() FreeCADGui.ActiveDocument.resetEdit() FreeCADGui.Control.closeDialog() - FreeCAD.ActiveDocument.recompute() FreeCADGui.Selection.removeObserver(self.s) + FreeCAD.ActiveDocument.recompute() def reject(self): + print "removed1" FreeCADGui.Control.closeDialog() - FreeCAD.ActiveDocument.recompute() FreeCADGui.Selection.removeObserver(self.s) + FreeCAD.ActiveDocument.recompute() def getFields(self): if self.obj: diff --git a/src/Mod/Path/PathScripts/PathJob.py b/src/Mod/Path/PathScripts/PathJob.py index d66245405..9c98be775 100644 --- a/src/Mod/Path/PathScripts/PathJob.py +++ b/src/Mod/Path/PathScripts/PathJob.py @@ -226,8 +226,8 @@ tl.ToolNumber = 1 class TaskPanel: def __init__(self): - #self.form = FreeCADGui.PySideUic.loadUi(":/panels/JobEdit.ui") - self.form = FreeCADGui.PySideUic.loadUi(FreeCAD.getHomePath() + "Mod/Path/JobEdit.ui") + self.form = FreeCADGui.PySideUic.loadUi(":/panels/JobEdit.ui") + #self.form = FreeCADGui.PySideUic.loadUi(FreeCAD.getHomePath() + "Mod/Path/JobEdit.ui") path = FreeCAD.getHomePath() + ("Mod/Path/PathScripts/") posts = glob.glob(path + '/*_post.py') allposts = [ str(os.path.split(os.path.splitext(p)[0])[1][:-5]) for p in posts] @@ -259,6 +259,7 @@ class TaskPanel: FreeCAD.ActiveDocument.recompute() def getFields(self): + '''sets properties in the object to match the form''' if self.obj: if hasattr(self.obj, "PostProcessor"): self.obj.PostProcessor = str(self.form.cboPostProcessor.currentText()) @@ -283,26 +284,31 @@ class TaskPanel: selObj = Draft.clone(selObj) self.obj.Base = selObj - self.obj.Proxy.execute(self.obj) def setFields(self): + '''sets fields in the form to match the object''' self.form.leLabel.setText(self.obj.Label) self.form.leOutputFile.setText(self.obj.OutputFile) - index = self.form.cboPostProcessor.findText( + postindex = self.form.cboPostProcessor.findText( self.obj.PostProcessor, QtCore.Qt.MatchFixedString) - if index >= 0: - self.form.cboPostProcessor.setCurrentIndex(index) + if postindex >= 0: + self.form.cboPostProcessor.blockSignals(True) + self.form.cboPostProcessor.setCurrentIndex(postindex) + self.form.cboPostProcessor.blockSignals(False) for child in self.obj.Group: self.form.PathsList.addItem(child.Name) if self.obj.Base is not None: - index = self.form.cboBaseObject.findText(self.obj.Base.Name, QtCore.Qt.MatchFixedString) - if index >= 0: - self.form.cboBaseObject.setCurrentIndex(index) + baseindex = self.form.cboBaseObject.findText(self.obj.Base.Name, QtCore.Qt.MatchFixedString) + print baseindex + if baseindex >= 0: + self.form.cboBaseObject.blockSignals(True) + self.form.cboBaseObject.setCurrentIndex(baseindex) + self.form.cboBaseObject.blockSignals(False) def open(self): diff --git a/src/Mod/Path/PathScripts/PathProfileEdges.py b/src/Mod/Path/PathScripts/PathProfileEdges.py index f200c12d2..add7ee748 100644 --- a/src/Mod/Path/PathScripts/PathProfileEdges.py +++ b/src/Mod/Path/PathScripts/PathProfileEdges.py @@ -453,8 +453,8 @@ class CommandPathProfileEdges: class TaskPanel: def __init__(self): - #self.form = FreeCADGui.PySideUic.loadUi(":/panels/ProfileEdgesEdit.ui") - self.form = FreeCADGui.PySideUic.loadUi(FreeCAD.getHomePath() + "Mod/Path/ProfileEdgesEdit.ui") + self.form = FreeCADGui.PySideUic.loadUi(":/panels/ProfileEdgesEdit.ui") + #self.form = FreeCADGui.PySideUic.loadUi(FreeCAD.getHomePath() + "Mod/Path/ProfileEdgesEdit.ui") self.updating = False diff --git a/src/Mod/Path/PathScripts/PathSurface.py b/src/Mod/Path/PathScripts/PathSurface.py index a89ed056e..613fdd46d 100644 --- a/src/Mod/Path/PathScripts/PathSurface.py +++ b/src/Mod/Path/PathScripts/PathSurface.py @@ -287,38 +287,48 @@ class ObjectSurface: output += "(" + obj.Label + ")" output += "(Compensated Tool Path. Diameter: " + str(self.radius * 2) + ")" - if obj.Base: - for b in obj.Base: + # if obj.Base: + # for b in obj.Base: - if obj.Algorithm in ['OCL Dropcutter', 'OCL Waterline']: - try: - import ocl - except: - FreeCAD.Console.PrintError(translate( - "PathSurface", "This operation requires OpenCamLib to be installed.\n")) - return + parentJob = PathUtils.findParentJob(obj) + if parentJob is None: + return + mesh = parentJob.Base + if mesh is None: + return + print "base object: " + mesh.Name - mesh = b[0] - if mesh.TypeId.startswith('Mesh'): - mesh = mesh.Mesh - bb = mesh.BoundBox - else: - bb = mesh.Shape.BoundBox - mesh = MeshPart.meshFromShape(mesh.Shape, MaxLength=2) - s = ocl.STLSurf() - for f in mesh.Facets: - p = f.Points[0] - q = f.Points[1] - r = f.Points[2] - t = ocl.Triangle(ocl.Point(p[0], p[1], p[2]), ocl.Point( - q[0], q[1], q[2]), ocl.Point(r[0], r[1], r[2])) - s.addTriangle(t) - if obj.Algorithm == 'OCL Dropcutter': - output = self._dropcutter(obj, s, bb) - elif obj.Algorithm == 'OCL Waterline': - output = self._waterline(obj, s, bb) + if obj.Algorithm in ['OCL Dropcutter', 'OCL Waterline']: + try: + import ocl + except: + FreeCAD.Console.PrintError(translate( + "PathSurface", "This operation requires OpenCamLib to be installed.\n")) + return + + #mesh = b[0] + if mesh.TypeId.startswith('Mesh'): + mesh = mesh.Mesh + bb = mesh.BoundBox + else: + bb = mesh.Shape.BoundBox + mesh = MeshPart.meshFromShape(mesh.Shape, MaxLength=2) + + s = ocl.STLSurf() + for f in mesh.Facets: + p = f.Points[0] + q = f.Points[1] + r = f.Points[2] + t = ocl.Triangle(ocl.Point(p[0], p[1], p[2]), ocl.Point( + q[0], q[1], q[2]), ocl.Point(r[0], r[1], r[2])) + s.addTriangle(t) + + if obj.Algorithm == 'OCL Dropcutter': + output = self._dropcutter(obj, s, bb) + elif obj.Algorithm == 'OCL Waterline': + output = self._waterline(obj, s, bb) if obj.Active: path = Path.Path(output) diff --git a/src/Mod/Path/PathScripts/PathToolLibraryManager.py b/src/Mod/Path/PathScripts/PathToolLibraryManager.py index 67ebcce8d..78658385e 100644 --- a/src/Mod/Path/PathScripts/PathToolLibraryManager.py +++ b/src/Mod/Path/PathScripts/PathToolLibraryManager.py @@ -248,6 +248,7 @@ class ToolLibraryManager(): def addnew(self, listname, tool, position = None): "adds a new tool at the end of the table" + print listname, tool, position tt = self._findList(listname) if position is None: tt.addTools(tool) @@ -326,7 +327,6 @@ class ToolLibraryManager(): pass class EditorPanel(): - def __init__(self): #self.form = FreeCADGui.PySideUic.loadUi(FreeCAD.getHomePath() + "Mod/Path/ToolLibraryEditor.ui") self.form = FreeCADGui.PySideUic.loadUi(":/panels/ToolLibraryEditor.ui") @@ -441,14 +441,17 @@ class EditorPanel(): def delete(self): '''deletes a tool''' - item = self.form.ToolsList.selectedIndexes()[1].data() - if item: - number = int(item) - listname = self.form.listView.selectedIndexes()[0].data() - if self.TLM.delete(number, listname) is True: - self.loadTable(self.form.listView.selectedIndexes()[0]) + listname = self.form.listView.selectedIndexes()[0].data() + model = self.form.ToolsList.model() + for i in range(model.rowCount()): + item = model.item(i, 0) + if item.checkState(): + t = model.index(i, 1) + self.TLM.delete(int(t.data()) ,listname) + self.loadTable(self.form.listView.selectedIndexes()[0]) def editTool(self, currItem): + row = currItem.row() value = currItem.sibling(row, 1).data() listname = self.form.listView.selectedIndexes()[0].data()