Skip to content

Commit

Permalink
Merge pull request #400 from sheetmetalman/master
Browse files Browse the repository at this point in the history
ExtrudedCutout: add "Refine" option property
  • Loading branch information
shaise authored Nov 19, 2024
2 parents 8af539c + 0b2fe65 commit 1857624
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions ExtrudedCutout.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
import os # Make sure 'os' is imported for the icon path
import SheetMetalTools

translate = FreeCAD.Qt.translate

class ExtrudedCutout:
def __init__(self, obj, sketch, selected_face):
'''Initialize the parametric Sheet Metal Cut object and add properties'''
obj.addProperty("App::PropertyLink", "Sketch", "ExtrudedCutout", "The sketch for the cut").Sketch = sketch
obj.addProperty("App::PropertyLinkSub", "SelectedFace", "ExtrudedCutout", "The selecteds object and face").SelectedFace = selected_face
self._addProperties(obj) # Add other properties (is necessary this way to not cause errors on old files)
obj.addProperty("App::PropertyLength", "ExtrusionLength1", "ExtrudedCutout", "Length of the extrusion direction 1").ExtrusionLength1 = 500.0
obj.setEditorMode("ExtrusionLength1",2) # Hide by default
obj.addProperty("App::PropertyLength", "ExtrusionLength2", "ExtrudedCutout", "Length of the extrusion direction 2").ExtrusionLength2 = 500.0
Expand All @@ -25,9 +28,18 @@ def __init__(self, obj, sketch, selected_face):

obj.Proxy = self

def _addProperties(self, obj):
SheetMetalTools.smAddBoolProperty(
obj,
"Refine",
translate("App::Property", "Refine the geometry"),
False,
"ExtrudedCutout"
)

def onChanged(self, fp, prop):
'''Respond to property changes'''
if prop in ["Sketch", "SelectedFace", "ExtrusionLength1", "ExtrusionLength2", "CutSide", "CutType"]:
if prop in ["Sketch", "SelectedFace", "ExtrusionLength1", "ExtrusionLength2", "CutSide", "CutType", "Refine"]:
App.ActiveDocument.recompute() # Trigger a recompute when these properties change

# Show or hide length properties based in the CutType property:
Expand All @@ -50,6 +62,9 @@ def onChanged(self, fp, prop):

def execute(self, fp):
'''Perform the cut when the object is recomputed'''

self._addProperties(fp)

try:
# Debug: Print the values of Sketch, SelectedFace, and CutSide
App.Console.PrintMessage(f"Sketch: {fp.Sketch}\n")
Expand Down Expand Up @@ -166,7 +181,11 @@ def execute(self, fp):

myExtrusion1 = compFaces.extrude(ExtLength1)
myExtrusion2 = compFaces.extrude(ExtLength2)
myUnion = Part.Solid.fuse(myExtrusion1, myExtrusion2).removeSplitter()

if fp.Refine == True:
myUnion = Part.Solid.fuse(myExtrusion1, myExtrusion2).removeSplitter()
else:
myUnion = Part.Solid.fuse(myExtrusion1, myExtrusion2)

myCommon = myUnion.common(shell)

Expand All @@ -189,9 +208,15 @@ def execute(self, fp):
# Step 6: Cut
# Check the "CutSide" property to decide how to perform the cut
if fp.CutSide == "Inside":
cut_result = selected_object.Shape.cut(combined_offset).removeSplitter()
if fp.Refine == True:
cut_result = selected_object.Shape.cut(combined_offset).removeSplitter()
else:
cut_result = selected_object.Shape.cut(combined_offset)
elif fp.CutSide == "Outside":
cut_result = selected_object.Shape.common(combined_offset).removeSplitter()
if fp.Refine == True:
cut_result = selected_object.Shape.common(combined_offset).removeSplitter()
else:
cut_result = selected_object.Shape.common(combined_offset)
else:
raise Exception("Invalid CutSide value.")

Expand Down

0 comments on commit 1857624

Please sign in to comment.