[PD] Fix Pad uptoface with custom direction (#16539)
* [PD] Fix Pad uptoface with custom direction * Add unit test
This commit is contained in:
committed by
GitHub
parent
0ff7c3a38f
commit
490d6c5abc
@@ -625,7 +625,7 @@ App::DocumentObjectExecReturn* FeatureExtrude::buildExtrusion(ExtrudeOptions opt
|
||||
}
|
||||
|
||||
if (faceCount == 1) {
|
||||
getUpToFace(upToShape, base, supportface, sketchshape, method, dir);
|
||||
getUpToFace(upToShape, base, sketchshape, method, dir);
|
||||
addOffsetToFace(upToShape, dir, Offset.getValue());
|
||||
}
|
||||
else{
|
||||
|
||||
@@ -848,7 +848,6 @@ void ProfileBased::getUpToFace(TopoDS_Face& upToFace,
|
||||
|
||||
void ProfileBased::getUpToFace(TopoShape& upToFace,
|
||||
const TopoShape& support,
|
||||
const TopoShape& supportface,
|
||||
const TopoShape& sketchshape,
|
||||
const std::string& method,
|
||||
gp_Dir& dir)
|
||||
@@ -887,13 +886,11 @@ void ProfileBased::getUpToFace(TopoShape& upToFace,
|
||||
TopoDS_Face face = TopoDS::Face(upToFace.getShape());
|
||||
|
||||
// Check that the upToFace does not intersect the sketch face and
|
||||
// is not parallel to the extrusion direction (for simplicity, supportface is used instead of
|
||||
// sketchshape)
|
||||
BRepAdaptor_Surface adapt1(TopoDS::Face(supportface.getShape()));
|
||||
BRepAdaptor_Surface adapt2(face);
|
||||
// is not parallel to the extrusion direction
|
||||
BRepAdaptor_Surface adapt(face);
|
||||
|
||||
if (adapt2.GetType() == GeomAbs_Plane) {
|
||||
if (adapt1.Plane().Axis().IsNormal(adapt2.Plane().Axis(), Precision::Confusion())) {
|
||||
if (adapt.GetType() == GeomAbs_Plane) {
|
||||
if (dir.IsNormal(adapt.Plane().Axis().Direction(), Precision::Confusion())) {
|
||||
throw Base::ValueError(
|
||||
"SketchBased: Up to face: Must not be parallel to extrusion direction!");
|
||||
}
|
||||
|
||||
@@ -173,7 +173,6 @@ protected:
|
||||
/// Find a valid face to extrude up to
|
||||
static void getUpToFace(TopoShape& upToFace,
|
||||
const TopoShape& support,
|
||||
const TopoShape& supportface,
|
||||
const TopoShape& sketchshape,
|
||||
const std::string& method,
|
||||
gp_Dir& dir);
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
import unittest
|
||||
|
||||
import FreeCAD
|
||||
from FreeCAD import Base
|
||||
import TestSketcherApp
|
||||
|
||||
class TestPad(unittest.TestCase):
|
||||
@@ -211,35 +212,52 @@ class TestPad(unittest.TestCase):
|
||||
self.Doc.recompute()
|
||||
self.assertAlmostEqual(self.Pad.Shape.Volume, 2208.0963, places=4)
|
||||
|
||||
def testPadToShapeCase(self):
|
||||
self.Body = self.Doc.addObject('PartDesign::Body','Body')
|
||||
# Make first offset cube Pad
|
||||
self.PadSketch = self.Doc.addObject('Sketcher::SketchObject', 'SketchPad')
|
||||
self.Body.addObject(self.PadSketch)
|
||||
TestSketcherApp.CreateRectangleSketch(self.PadSketch, (0, 1), (1, 1))
|
||||
self.Doc.recompute()
|
||||
self.Pad = self.Doc.addObject("PartDesign::Pad", "Pad")
|
||||
self.Body.addObject(self.Pad)
|
||||
self.Pad.Profile = self.PadSketch
|
||||
self.Pad.Length = 1
|
||||
self.Doc.recompute()
|
||||
# Make second pad on different plane and pad to first
|
||||
self.PadSketch1 = self.Doc.addObject('Sketcher::SketchObject', 'SketchPad1')
|
||||
self.Body.addObject(self.PadSketch1)
|
||||
self.PadSketch1.MapMode = 'FlatFace'
|
||||
self.PadSketch1.AttachmentSupport = (self.Doc.XZ_Plane, [''])
|
||||
self.PadSketch1.AttachmentOffset.Rotation.Axis = App.Vector(0,1,0)
|
||||
self.PadSketch1.AttachmentOffset.Rotation.Angle = 0.436332 # 25°
|
||||
self.PadSketch1.AttachmentOffset.Base.z = 1
|
||||
self.Doc.recompute()
|
||||
TestSketcherApp.CreateRectangleSketch(self.PadSketch1, (1, 0), (1, 1))
|
||||
self.Doc.recompute()
|
||||
self.Pad1 = self.Doc.addObject("PartDesign::Pad", "Pad1")
|
||||
self.Body.addObject(self.Pad1)
|
||||
self.Pad1.Profile = self.PadSketch1
|
||||
self.Pad1.Type = 5
|
||||
self.Doc.recompute()
|
||||
self.assertAlmostEqual(self.Pad1.Shape.Volume, 2.58787, places=4)
|
||||
def testPadToShapeCase(self):
|
||||
self.Body = self.Doc.addObject('PartDesign::Body','Body')
|
||||
# Make first offset cube Pad
|
||||
self.PadSketch = self.Doc.addObject('Sketcher::SketchObject', 'SketchPad')
|
||||
self.Body.addObject(self.PadSketch)
|
||||
TestSketcherApp.CreateRectangleSketch(self.PadSketch, (0, 1), (1, 1))
|
||||
self.Doc.recompute()
|
||||
self.Pad = self.Doc.addObject("PartDesign::Pad", "Pad")
|
||||
self.Body.addObject(self.Pad)
|
||||
self.Pad.Profile = self.PadSketch
|
||||
self.Pad.Length = 1
|
||||
self.Doc.recompute()
|
||||
# Make second pad on different plane and pad to first
|
||||
self.PadSketch1 = self.Doc.addObject('Sketcher::SketchObject', 'SketchPad1')
|
||||
self.Body.addObject(self.PadSketch1)
|
||||
self.PadSketch1.MapMode = 'FlatFace'
|
||||
self.PadSketch1.AttachmentSupport = (self.Doc.XZ_Plane, [''])
|
||||
self.PadSketch1.AttachmentOffset.Rotation.Axis = Base.Vector(0,1,0)
|
||||
self.PadSketch1.AttachmentOffset.Rotation.Angle = 0.436332 # 25°
|
||||
self.PadSketch1.AttachmentOffset.Base.z = 1
|
||||
self.Doc.recompute()
|
||||
TestSketcherApp.CreateRectangleSketch(self.PadSketch1, (1, 0), (1, 1))
|
||||
self.Doc.recompute()
|
||||
self.Pad1 = self.Doc.addObject("PartDesign::Pad", "Pad1")
|
||||
self.Body.addObject(self.Pad1)
|
||||
self.Pad1.Profile = self.PadSketch1
|
||||
self.Pad1.Type = 5
|
||||
self.Doc.recompute()
|
||||
self.assertAlmostEqual(self.Pad1.Shape.Volume, 2.58787, places=4)
|
||||
|
||||
def testPadToPlaneCustomDir(self):
|
||||
self.Body = self.Doc.addObject('PartDesign::Body','Body')
|
||||
# Make first offset cube Pad
|
||||
self.PadSketch = self.Doc.addObject('Sketcher::SketchObject', 'SketchPad')
|
||||
self.Body.addObject(self.PadSketch)
|
||||
TestSketcherApp.CreateRectangleSketch(self.PadSketch, (0, 1), (1, 1))
|
||||
self.Doc.recompute()
|
||||
self.Pad = self.Doc.addObject("PartDesign::Pad", "Pad")
|
||||
self.Body.addObject(self.Pad)
|
||||
self.Pad.Profile = self.PadSketch
|
||||
self.Pad.Type = 3
|
||||
self.Doc.Pad.UseCustomVector = True
|
||||
self.Doc.Pad.Direction = Base.Vector(0,1,1)
|
||||
self.Pad.UpToFace = (self.Doc.XZ_Plane, [''])
|
||||
self.Doc.recompute()
|
||||
self.assertAlmostEqual(self.Pad.Shape.Volume, 1.5)
|
||||
|
||||
def tearDown(self):
|
||||
#closing doc
|
||||
|
||||
Reference in New Issue
Block a user