diff --git a/src/Mod/OpenSCAD/InitGui.py b/src/Mod/OpenSCAD/InitGui.py index 9df219ed08..1323ddf4e4 100644 --- a/src/Mod/OpenSCAD/InitGui.py +++ b/src/Mod/OpenSCAD/InitGui.py @@ -49,7 +49,7 @@ class OpenSCADWorkbench ( Workbench ): return text import OpenSCAD_rc,OpenSCADCommands commands = ['OpenSCAD_ReplaceObject','OpenSCAD_RemoveSubtree', - 'OpenSCAD_RefineShapeFeature','OpenSCAD_IncreaseToleranceFeature', + 'OpenSCAD_RefineShapeFeature','OpenSCAD_MirrorMeshFeature','OpenSCAD_IncreaseToleranceFeature', 'OpenSCAD_Edgestofaces', 'OpenSCAD_ExpandPlacements','OpenSCAD_ExplodeGroup'] toolbarcommands = ['OpenSCAD_ReplaceObject','OpenSCAD_RemoveSubtree', 'OpenSCAD_ExplodeGroup','OpenSCAD_RefineShapeFeature', diff --git a/src/Mod/OpenSCAD/OpenSCADCommands.py b/src/Mod/OpenSCAD/OpenSCADCommands.py index f421fea7a8..99f17bffde 100644 --- a/src/Mod/OpenSCAD/OpenSCADCommands.py +++ b/src/Mod/OpenSCAD/OpenSCADCommands.py @@ -157,6 +157,26 @@ class RefineShapeFeature: 'MenuText': QtCore.QT_TRANSLATE_NOOP('OpenSCAD_RefineShapeFeature', 'Refine Shape Feature'), 'ToolTip' : QtCore.QT_TRANSLATE_NOOP('OpenSCAD_RefineShapeFeature', 'Create Refine Shape Feature')} +class MirrorMeshFeature: + def IsActive(self): + return FreeCADGui.Selection.countObjectsOfType('Mesh::Feature') > 0 + + def Activated(self): + import Part,OpenSCADFeatures,OpenSCADUtils + selection=FreeCADGui.Selection.getSelectionEx() + for selobj in selection: + newobj=selobj.Document.addObject("Mesh::Feature",'mirror') + newobj.Label='mirror_%s' % selobj.Object.Label + msh=selobj.Object.Mesh + newobj.Mesh=OpenSCADUtils.mirror(msh) + selobj.Object.ViewObject.hide() + FreeCAD.ActiveDocument.recompute() + def GetResources(self): + return {'Pixmap' : 'OpenSCAD_MirrorMeshFeature', + 'MenuText': QtCore.QT_TRANSLATE_NOOP('OpenSCAD_MirrorMeshFeature', 'Mirror Mesh Feature'), + 'ToolTip' : QtCore.QT_TRANSLATE_NOOP('OpenSCAD_MirrorMeshFeature', 'Create Mirror Mesh Feature')} + + class IncreaseToleranceFeature: def IsActive(self): return FreeCADGui.Selection.countObjectsOfType('Part::Feature') > 0 @@ -422,6 +442,7 @@ FreeCADGui.addCommand('OpenSCAD_ColorCodeShape',ColorCodeShape()) FreeCADGui.addCommand('OpenSCAD_ExplodeGroup',ExplodeGroup()) FreeCADGui.addCommand('OpenSCAD_Edgestofaces',Edgestofaces()) FreeCADGui.addCommand('OpenSCAD_RefineShapeFeature',RefineShapeFeature()) +FreeCADGui.addCommand('OpenSCAD_MirrorMeshFeature',MirrorMeshFeature()) FreeCADGui.addCommand('OpenSCAD_IncreaseToleranceFeature',IncreaseToleranceFeature()) FreeCADGui.addCommand('OpenSCAD_ExpandPlacements',ExpandPlacements()) FreeCADGui.addCommand('OpenSCAD_ReplaceObject',ReplaceObject()) diff --git a/src/Mod/OpenSCAD/OpenSCADFeatures.py b/src/Mod/OpenSCAD/OpenSCADFeatures.py index 3c6b6c499d..cc330a742a 100644 --- a/src/Mod/OpenSCAD/OpenSCADFeatures.py +++ b/src/Mod/OpenSCAD/OpenSCADFeatures.py @@ -273,7 +273,8 @@ class RefineShape: def execute(self, fp): if fp.Base and fp.Base.Shape.isValid(): - import freecad.OpenSCAD.OpenSCADUtils + #import freecad.OpenSCAD.OpenSCADUtils + import OpenSCADUtils sh=fp.Base.Shape.removeSplitter() fp.Shape=freecad.OpenSCAD.OpenSCADUtils.applyPlacement(sh) diff --git a/src/Mod/OpenSCAD/OpenSCADUtils.py b/src/Mod/OpenSCAD/OpenSCADUtils.py index 4596c9f5a0..22dc486426 100644 --- a/src/Mod/OpenSCAD/OpenSCADUtils.py +++ b/src/Mod/OpenSCAD/OpenSCADUtils.py @@ -298,6 +298,19 @@ def vec2householder(nv): nv.z*nv.x*l,nv.z*nv.y*l,nv.z*nv.z*l,0,0,0,0,0) return FreeCAD.Matrix()-hh +def mirror(msh): + from exportCSG import mesh2polyhedron + from PySide import QtGui + items=["[1,0,0]","[0,1,0]","[0,0,1]","[1,1,0]","[0,1,1]","[1,0,1]","[1,1,1]"] + item, ok = QtGui.QInputDialog.getItem(QtGui.QApplication.activeWindow(),u'Mirror about which Axis?',u'Select Axis (or enter custom value)?',items,editable=True) + if ok: + param = 'mirror('+item+')' + poly = mesh2polyhedron(msh) + mi = callopenscadmeshstring('%s{%s}' % (param,''.join(poly))) + mi.flipNormals() + return mi + return msh + def angneg(d): return d if (d <= 180.0) else (d-360) diff --git a/src/Mod/OpenSCAD/Resources/icons/OpenSCAD_MirrorMeshFeature.svg b/src/Mod/OpenSCAD/Resources/icons/OpenSCAD_MirrorMeshFeature.svg new file mode 100644 index 0000000000..7fc6326a5c --- /dev/null +++ b/src/Mod/OpenSCAD/Resources/icons/OpenSCAD_MirrorMeshFeature.svg @@ -0,0 +1,541 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + [Sebastian Hoogen] + + + OpenSCAD_RefineShapeFeature + 2012-05-03 + http://www.freecadweb.org/wiki/index.php?title=Artwork + + + FreeCAD + + + FreeCAD/src/Mod/OpenSCAD/Resources/icons/OpenSCAD_RefineShape + + + FreeCAD LGPL2+ + + + https://www.gnu.org/copyleft/lesser.html + + + [agryson] Alexander Gryson + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Mod/OpenSCAD/exportCSG.py b/src/Mod/OpenSCAD/exportCSG.py index 40aa8d42e1..951ad36748 100644 --- a/src/Mod/OpenSCAD/exportCSG.py +++ b/src/Mod/OpenSCAD/exportCSG.py @@ -80,7 +80,9 @@ def check_multmatrix(csg,ob,x,y,z): def mesh2polyhedron(mesh): pointstr=','.join(['[%f,%f,%f]' % tuple(vec) for vec in mesh.Topology[0]]) trianglestr=','.join(['[%d,%d,%d]' % tuple(tri) for tri in mesh.Topology[1]]) - return 'polyhedron ( points = [%s], triangles = [%s]);' % (pointstr,trianglestr) + #avoid deprecation warning by changing triangles to faces + #return 'polyhedron ( points = [%s], triangles = [%s]);' % (pointstr,trianglestr) + return 'polyhedron ( points = [%s], faces = [%s]);' % (pointstr,trianglestr) def vector2d(v): return [v[0],v[1]]