From 08b7d9d0f3abc89c853e90d0e76fdb0e27bc0948 Mon Sep 17 00:00:00 2001 From: Chris Hennes Date: Tue, 30 Mar 2021 14:05:49 -0500 Subject: [PATCH] [OpenSCAD] Fix projection for OCCT7.3 OCCT 7.3 did not work well when using a very large projection plane, so this commit reduces the plane size to the minimum required for the cut operation. It also performs some minor refactoring in anticipation of the implementation of the true projection feature, and it removes the last attempted fix, which proved unnecessary. --- src/Mod/OpenSCAD/OpenSCADFeatures.py | 9 -------- src/Mod/OpenSCAD/importCSG.py | 34 +++++++++++++++------------- 2 files changed, 18 insertions(+), 25 deletions(-) diff --git a/src/Mod/OpenSCAD/OpenSCADFeatures.py b/src/Mod/OpenSCAD/OpenSCADFeatures.py index a3b0b306a1..433cf0d83f 100644 --- a/src/Mod/OpenSCAD/OpenSCADFeatures.py +++ b/src/Mod/OpenSCAD/OpenSCADFeatures.py @@ -434,15 +434,6 @@ class Twist: auxiliary_spine = Part.makeHelix(pitch, height, radius, 0.0, left_handed) - # OCC versions before 7.5 had a problem with using a helix as the auxilliary spine, so approximate - # it piecewise - occ_version = Part.OCC_VERSION.split(".") - if int(occ_version[0]) <= 7 and int(occ_version[1]) < 5: - num_points = int(max(3,num_revolutions * 36)) # Every ten degrees is adequate - wire = auxiliary_spine.Wires[0] - points = wire.discretize(Number=num_points) - auxiliary_spine = Part.makePolygon(points) - faces = [lower_face,upper_face] for wire1,wire2 in zip(lower_face.Wires,upper_face.Wires): pipe_shell = Part.BRepOffsetAPI.MakePipeShell(spine) diff --git a/src/Mod/OpenSCAD/importCSG.py b/src/Mod/OpenSCAD/importCSG.py index 315eb94d44..432a4d70a5 100644 --- a/src/Mod/OpenSCAD/importCSG.py +++ b/src/Mod/OpenSCAD/importCSG.py @@ -1322,25 +1322,27 @@ def p_polyhedron_action(p) : def p_projection_action(p) : 'projection_action : projection LPAREN keywordargument_list RPAREN OBRACE block_list EBRACE' if printverbose: print('Projection') - if p[3]['cut']=='true' : - planedim=1e9 # large but finite - #infinite planes look bad in the GUI - planename='xy_plane_used_for_project_cut' - obj=doc.addObject('Part::MultiCommon','projection_cut') - plane = doc.getObject(planename) - if not plane: - plane=doc.addObject("Part::Plane",planename) - plane.Length=planedim*2 - plane.Width=planedim*2 - plane.Placement = FreeCAD.Placement(FreeCAD.Vector(\ - -planedim,-planedim,0),FreeCAD.Rotation()) - if gui: - plane.ViewObject.hide() + + doc.recompute() + bbox = p[6][0].Shape.BoundBox + for shape in p[6]: + bbox.add(shape.Shape.BoundBox) + print (bbox) + plane = doc.addObject("Part::Plane","xy_plane_used_for_projection") + plane.Length = bbox.XLength + plane.Width = bbox.YLength + plane.Placement = FreeCAD.Placement(FreeCAD.Vector(\ + bbox.XMin,bbox.YMin,0),FreeCAD.Rotation()) + if gui: + plane.ViewObject.hide() + + if p[3]['cut'] == 'true' : + obj = doc.addObject('Part::MultiCommon','projection_cut') if (len(p[6]) > 1): subobj = [fuse(p[6],"projection_cut_implicit_group")] else: subobj = p[6] - obj.Shapes = [plane]+subobj + obj.Shapes = [plane] + subobj if gui: subobj[0].ViewObject.hide() p[0] = [obj] @@ -1348,6 +1350,6 @@ def p_projection_action(p) : if gui and not FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/OpenSCAD").\ GetBool('usePlaceholderForUnsupported'): from PySide import QtGui - QtGui.QMessageBox.critical(None, translate('OpenSCAD',"Unsupported Function")+" : "+p[1],translate('OpenSCAD',"Press OK")) + QtGui.QMessageBox.critical(None, translate('OpenSCAD',"Unsupported Function") + " : " + p[1],translate('OpenSCAD',"Press OK")) else: p[0] = [placeholder(p[1],p[6],p[3])]