Merge pull request #21046 from davesrocketshop/issue_13922_2
Update module dependencies to ensure that automated testing code is considered as well as direct dependencies. Update some automated tests to eliminate unwanted dependencies.
This commit is contained in:
@@ -9,7 +9,7 @@ macro(CheckInterModuleDependencies)
|
||||
foreach(prerequisite IN LISTS ARGN)
|
||||
if(NOT ${prerequisite})
|
||||
message(SEND_ERROR "${dependent} requires ${prerequisite} to be ON, but it"
|
||||
" is \"${${prerequisite}}\"")
|
||||
" is \"${${prerequisite}}\"")
|
||||
set(${dependent} OFF PARENT_SCOPE)
|
||||
break()
|
||||
endif(NOT ${prerequisite})
|
||||
@@ -17,11 +17,11 @@ macro(CheckInterModuleDependencies)
|
||||
endif(${dependent})
|
||||
endfunction(REQUIRES_MODS)
|
||||
|
||||
REQUIRES_MODS(BUILD_BIM BUILD_PART BUILD_MESH BUILD_DRAFT)
|
||||
REQUIRES_MODS(BUILD_DRAFT BUILD_SKETCHER)
|
||||
REQUIRES_MODS(BUILD_ASSEMBLY BUILD_PART BUILD_PART_DESIGN BUILD_SPREADSHEET)
|
||||
REQUIRES_MODS(BUILD_BIM BUILD_PART BUILD_MESH BUILD_MESH_PART BUILD_DRAFT)
|
||||
REQUIRES_MODS(BUILD_DRAFT BUILD_SKETCHER BUILD_TECHDRAW BUILD_BIM)
|
||||
REQUIRES_MODS(BUILD_DRAWING BUILD_PART BUILD_SPREADSHEET)
|
||||
REQUIRES_MODS(BUILD_FEM BUILD_PART)
|
||||
REQUIRES_MODS(BUILD_IDF BUILD_PART)
|
||||
REQUIRES_MODS(BUILD_IMPORT BUILD_PART)
|
||||
REQUIRES_MODS(BUILD_INSPECTION BUILD_MESH BUILD_POINTS BUILD_PART)
|
||||
REQUIRES_MODS(BUILD_JTREADER BUILD_MESH)
|
||||
@@ -29,6 +29,7 @@ macro(CheckInterModuleDependencies)
|
||||
REQUIRES_MODS(BUILD_FLAT_MESH BUILD_MESH_PART)
|
||||
REQUIRES_MODS(BUILD_OPENSCAD BUILD_MESH_PART BUILD_DRAFT)
|
||||
REQUIRES_MODS(BUILD_MATERIAL_EXTERNAL BUILD_MATERIAL)
|
||||
REQUIRES_MODS(BUILD_MEASURE BUILD_PART)
|
||||
REQUIRES_MODS(BUILD_PART BUILD_MATERIAL)
|
||||
REQUIRES_MODS(BUILD_PART_DESIGN BUILD_SKETCHER)
|
||||
# REQUIRES_MODS(BUILD_CAM BUILD_PART BUILD_MESH BUILD_ROBOT)
|
||||
@@ -38,5 +39,6 @@ macro(CheckInterModuleDependencies)
|
||||
REQUIRES_MODS(BUILD_SANDBOX BUILD_PART BUILD_MESH)
|
||||
REQUIRES_MODS(BUILD_SKETCHER BUILD_PART)
|
||||
REQUIRES_MODS(BUILD_SPREADSHEET BUILD_DRAFT)
|
||||
REQUIRES_MODS(BUILD_SURFACE BUILD_PART)
|
||||
REQUIRES_MODS(BUILD_TECHDRAW BUILD_PART BUILD_PART_DESIGN BUILD_SPREADSHEET BUILD_MEASURE BUILD_IMPORT)
|
||||
endmacro(CheckInterModuleDependencies)
|
||||
|
||||
@@ -36,34 +36,36 @@ class DocumentTestCases(unittest.TestCase):
|
||||
|
||||
def testApplyDiffuseColorCheckShapeAppearance(self):
|
||||
""" Test that applying a DiffuseColor with transparency results in a correct ShapeAppearance """
|
||||
dif_col_1 = (1.0, 1.0, 0.0, 1.0) # yellow 0% transparent
|
||||
dif_col_2 = (1.0, 0.0, 0.0, 0.5) # red 50% transparent
|
||||
dif_col = [dif_col_1] + [dif_col_2] + 4 * [dif_col_1]
|
||||
if "BUILD_PART" in FreeCAD.__cmake__:
|
||||
dif_col_1 = (1.0, 1.0, 0.0, 1.0) # yellow 0% transparent
|
||||
dif_col_2 = (1.0, 0.0, 0.0, 0.5) # red 50% transparent
|
||||
dif_col = [dif_col_1] + [dif_col_2] + 4 * [dif_col_1]
|
||||
|
||||
obj = self.doc.addObject("Part::Box")
|
||||
vobj = obj.ViewObject
|
||||
vobj.DiffuseColor = dif_col
|
||||
obj = self.doc.addObject("Part::Box")
|
||||
vobj = obj.ViewObject
|
||||
vobj.DiffuseColor = dif_col
|
||||
|
||||
self.assertEqual(
|
||||
[m.DiffuseColor[:3] + (1.0 - m.Transparency, ) for m in vobj.ShapeAppearance],
|
||||
vobj.DiffuseColor
|
||||
)
|
||||
self.assertEqual(
|
||||
[m.DiffuseColor[:3] + (1.0 - m.Transparency, ) for m in vobj.ShapeAppearance],
|
||||
vobj.DiffuseColor
|
||||
)
|
||||
|
||||
def testApplyShapeAppearanceCheckDiffuseColor(self):
|
||||
""" Test that applying a ShapeAppearance with transparency results in a correct DiffuseColor """
|
||||
sapp_1 = FreeCAD.Material()
|
||||
sapp_1.DiffuseColor = (0.0, 1.0, 1.0, 0.0) # cyan
|
||||
sapp_1.Transparency = 0.0 # 0% transparent
|
||||
sapp_2 = FreeCAD.Material()
|
||||
sapp_2.DiffuseColor = (0.0, 1.0, 0.0, 0.0) # green
|
||||
sapp_2.Transparency = 0.3 # 30% transparent
|
||||
sapp = [sapp_1] + [sapp_2] + 4 * [sapp_1]
|
||||
if "BUILD_PART" in FreeCAD.__cmake__:
|
||||
sapp_1 = FreeCAD.Material()
|
||||
sapp_1.DiffuseColor = (0.0, 1.0, 1.0, 0.0) # cyan
|
||||
sapp_1.Transparency = 0.0 # 0% transparent
|
||||
sapp_2 = FreeCAD.Material()
|
||||
sapp_2.DiffuseColor = (0.0, 1.0, 0.0, 0.0) # green
|
||||
sapp_2.Transparency = 0.3 # 30% transparent
|
||||
sapp = [sapp_1] + [sapp_2] + 4 * [sapp_1]
|
||||
|
||||
obj = self.doc.addObject("Part::Box")
|
||||
vobj = obj.ViewObject
|
||||
vobj.ShapeAppearance = sapp
|
||||
obj = self.doc.addObject("Part::Box")
|
||||
vobj = obj.ViewObject
|
||||
vobj.ShapeAppearance = sapp
|
||||
|
||||
self.assertEqual(
|
||||
[m.DiffuseColor[:3] + (1.0 - m.Transparency, ) for m in vobj.ShapeAppearance],
|
||||
vobj.DiffuseColor
|
||||
)
|
||||
self.assertEqual(
|
||||
[m.DiffuseColor[:3] + (1.0 - m.Transparency, ) for m in vobj.ShapeAppearance],
|
||||
vobj.DiffuseColor
|
||||
)
|
||||
|
||||
@@ -124,47 +124,49 @@ class PartTestBSplineCurve(unittest.TestCase):
|
||||
self.spline.setPole(1, App.Vector([1, 0, 0])) # first parameter 0 gives occ error
|
||||
|
||||
def testIssue2671(self):
|
||||
self.Doc = App.newDocument("Issue2671")
|
||||
Box = self.Doc.addObject("Part::Box","Box")
|
||||
Mirroring = self.Doc.addObject("Part::Mirroring", 'Mirroring')
|
||||
Spreadsheet = self.Doc.addObject('Spreadsheet::Sheet', 'Spreadsheet')
|
||||
Mirroring.Source = Box
|
||||
Mirroring.Base = (8, 5, 25)
|
||||
Mirroring.Normal = (0.5, 0.2, 0.9)
|
||||
Spreadsheet.set('A1', '=Mirroring.Base.x')
|
||||
Spreadsheet.set('B1', '=Mirroring.Base.y')
|
||||
Spreadsheet.set('C1', '=Mirroring.Base.z')
|
||||
Spreadsheet.set('A2', '=Mirroring.Normal.x')
|
||||
Spreadsheet.set('B2', '=Mirroring.Normal.y')
|
||||
Spreadsheet.set('C2', '=Mirroring.Normal.z')
|
||||
self.Doc.recompute()
|
||||
self.assertEqual(Spreadsheet.A1, Units.Quantity('8 mm'))
|
||||
self.assertEqual(Spreadsheet.B1, Units.Quantity('5 mm'))
|
||||
self.assertEqual(Spreadsheet.C1, Units.Quantity('25 mm'))
|
||||
self.assertEqual(Spreadsheet.A2, Units.Quantity('0.5 mm'))
|
||||
self.assertEqual(Spreadsheet.B2, Units.Quantity('0.2 mm'))
|
||||
self.assertEqual(Spreadsheet.C2, Units.Quantity('0.9 mm'))
|
||||
App.closeDocument("Issue2671")
|
||||
if "BUILD_SPREADSHEET" in FreeCAD.__cmake__:
|
||||
self.Doc = App.newDocument("Issue2671")
|
||||
Box = self.Doc.addObject("Part::Box","Box")
|
||||
Mirroring = self.Doc.addObject("Part::Mirroring", 'Mirroring')
|
||||
Spreadsheet = self.Doc.addObject('Spreadsheet::Sheet', 'Spreadsheet')
|
||||
Mirroring.Source = Box
|
||||
Mirroring.Base = (8, 5, 25)
|
||||
Mirroring.Normal = (0.5, 0.2, 0.9)
|
||||
Spreadsheet.set('A1', '=Mirroring.Base.x')
|
||||
Spreadsheet.set('B1', '=Mirroring.Base.y')
|
||||
Spreadsheet.set('C1', '=Mirroring.Base.z')
|
||||
Spreadsheet.set('A2', '=Mirroring.Normal.x')
|
||||
Spreadsheet.set('B2', '=Mirroring.Normal.y')
|
||||
Spreadsheet.set('C2', '=Mirroring.Normal.z')
|
||||
self.Doc.recompute()
|
||||
self.assertEqual(Spreadsheet.A1, Units.Quantity('8 mm'))
|
||||
self.assertEqual(Spreadsheet.B1, Units.Quantity('5 mm'))
|
||||
self.assertEqual(Spreadsheet.C1, Units.Quantity('25 mm'))
|
||||
self.assertEqual(Spreadsheet.A2, Units.Quantity('0.5 mm'))
|
||||
self.assertEqual(Spreadsheet.B2, Units.Quantity('0.2 mm'))
|
||||
self.assertEqual(Spreadsheet.C2, Units.Quantity('0.9 mm'))
|
||||
App.closeDocument("Issue2671")
|
||||
|
||||
def testIssue2876(self):
|
||||
self.Doc = App.newDocument("Issue2876")
|
||||
Cylinder = self.Doc.addObject("Part::Cylinder", "Cylinder")
|
||||
Cylinder.Radius = 5
|
||||
Pipe = self.Doc.addObject("Part::Thickness", "Pipe")
|
||||
Pipe.Faces = (Cylinder, ["Face2", "Face3"])
|
||||
Pipe.Mode = 1
|
||||
Pipe.Value = -1 # negative wall thickness
|
||||
Spreadsheet = self.Doc.addObject('Spreadsheet::Sheet', 'Spreadsheet')
|
||||
Spreadsheet.set('A1', 'Pipe OD')
|
||||
Spreadsheet.set('B1', 'Pipe WT')
|
||||
Spreadsheet.set('C1', 'Pipe ID')
|
||||
Spreadsheet.set('A2', '=2*Cylinder.Radius')
|
||||
Spreadsheet.set('B2', '=-Pipe.Value')
|
||||
Spreadsheet.set('C2', '=2*(Cylinder.Radius + Pipe.Value)')
|
||||
self.Doc.recompute()
|
||||
self.assertEqual(Spreadsheet.B2, Units.Quantity('1 mm'))
|
||||
self.assertEqual(Spreadsheet.C2, Units.Quantity('8 mm'))
|
||||
App.closeDocument("Issue2876")
|
||||
if "BUILD_SPREADSHEET" in FreeCAD.__cmake__:
|
||||
self.Doc = App.newDocument("Issue2876")
|
||||
Cylinder = self.Doc.addObject("Part::Cylinder", "Cylinder")
|
||||
Cylinder.Radius = 5
|
||||
Pipe = self.Doc.addObject("Part::Thickness", "Pipe")
|
||||
Pipe.Faces = (Cylinder, ["Face2", "Face3"])
|
||||
Pipe.Mode = 1
|
||||
Pipe.Value = -1 # negative wall thickness
|
||||
Spreadsheet = self.Doc.addObject('Spreadsheet::Sheet', 'Spreadsheet')
|
||||
Spreadsheet.set('A1', 'Pipe OD')
|
||||
Spreadsheet.set('B1', 'Pipe WT')
|
||||
Spreadsheet.set('C1', 'Pipe ID')
|
||||
Spreadsheet.set('A2', '=2*Cylinder.Radius')
|
||||
Spreadsheet.set('B2', '=-Pipe.Value')
|
||||
Spreadsheet.set('C2', '=2*(Cylinder.Radius + Pipe.Value)')
|
||||
self.Doc.recompute()
|
||||
self.assertEqual(Spreadsheet.B2, Units.Quantity('1 mm'))
|
||||
self.assertEqual(Spreadsheet.C2, Units.Quantity('8 mm'))
|
||||
App.closeDocument("Issue2876")
|
||||
|
||||
def testSubElements(self):
|
||||
box = Part.makeBox(1, 1, 1)
|
||||
@@ -527,20 +529,21 @@ class PartTestRuledSurface(unittest.TestCase):
|
||||
self.assertEqual(len(same32), 3)
|
||||
|
||||
def testRuledSurfaceFromOneObject(self):
|
||||
sketch = self.Doc.addObject('Sketcher::SketchObject', 'Sketch')
|
||||
sketch.Placement = FreeCAD.Placement(FreeCAD.Vector(0.000000, 0.000000, 0.000000), App.Rotation(0.707107, 0.000000, 0.000000, 0.707107))
|
||||
sketch.MapMode = "Deactivated"
|
||||
if "BUILD_SKETCHER" in FreeCAD.__cmake__:
|
||||
sketch = self.Doc.addObject('Sketcher::SketchObject', 'Sketch')
|
||||
sketch.Placement = FreeCAD.Placement(FreeCAD.Vector(0.000000, 0.000000, 0.000000), App.Rotation(0.707107, 0.000000, 0.000000, 0.707107))
|
||||
sketch.MapMode = "Deactivated"
|
||||
|
||||
sketch.addGeometry(Part.LineSegment(App.Vector(-43.475811,34.364464,0),App.Vector(-65.860519,-20.078733,0)),False)
|
||||
sketch.addGeometry(Part.LineSegment(App.Vector(14.004498,27.390331,0),App.Vector(33.577049,-27.952749,0)),False)
|
||||
sketch.addGeometry(Part.LineSegment(App.Vector(-43.475811,34.364464,0),App.Vector(-65.860519,-20.078733,0)),False)
|
||||
sketch.addGeometry(Part.LineSegment(App.Vector(14.004498,27.390331,0),App.Vector(33.577049,-27.952749,0)),False)
|
||||
|
||||
ruled = self.Doc.addObject('Part::RuledSurface', 'Ruled Surface')
|
||||
ruled.Curve1 = (sketch,['Edge1'])
|
||||
ruled.Curve2 = (sketch,['Edge2'])
|
||||
self.Doc.recompute()
|
||||
ruled = self.Doc.addObject('Part::RuledSurface', 'Ruled Surface')
|
||||
ruled.Curve1 = (sketch,['Edge1'])
|
||||
ruled.Curve2 = (sketch,['Edge2'])
|
||||
self.Doc.recompute()
|
||||
|
||||
same = getCoincidentVertexes(sketch.Shape.Vertexes, ruled.Shape.Vertexes)
|
||||
self.assertEqual(len(same), 4)
|
||||
same = getCoincidentVertexes(sketch.Shape.Vertexes, ruled.Shape.Vertexes)
|
||||
self.assertEqual(len(same), 4)
|
||||
|
||||
def tearDown(self):
|
||||
FreeCAD.closeDocument(self.Doc.Name)
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import FreeCAD
|
||||
from FreeCAD import Vector, Base, newDocument, closeDocument
|
||||
import Part
|
||||
import Sketcher
|
||||
if "BUILD_SKETCHER" in FreeCAD.__cmake__:
|
||||
import Sketcher
|
||||
|
||||
import unittest
|
||||
|
||||
@@ -34,67 +36,68 @@ class RegressionTests(unittest.TestCase):
|
||||
The following test is a simplified version of the issue, but the outcome is the same
|
||||
"""
|
||||
|
||||
# Arrange
|
||||
ArcSketch = self.Doc.addObject("Sketcher::SketchObject", "ArcSketch")
|
||||
ArcSketch.Placement = Base.Placement(
|
||||
Base.Vector(0.000000, 0.000000, 0.000000),
|
||||
Base.Rotation(0.500000, 0.500000, 0.500000, 0.500000),
|
||||
)
|
||||
ArcSketch.MapMode = "Deactivated"
|
||||
|
||||
geoList = []
|
||||
geoList.append(
|
||||
Part.ArcOfCircle(
|
||||
Part.Circle(
|
||||
Base.Vector(0.000000, 0.000000, 0.000000),
|
||||
Base.Vector(0.000000, 0.000000, 1.000000),
|
||||
10.000000,
|
||||
),
|
||||
3.141593,
|
||||
6.283185,
|
||||
if "BUILD_SKETCHER" in FreeCAD.__cmake__:
|
||||
# Arrange
|
||||
ArcSketch = self.Doc.addObject("Sketcher::SketchObject", "ArcSketch")
|
||||
ArcSketch.Placement = Base.Placement(
|
||||
Base.Vector(0.000000, 0.000000, 0.000000),
|
||||
Base.Rotation(0.500000, 0.500000, 0.500000, 0.500000),
|
||||
)
|
||||
)
|
||||
ArcSketch.addGeometry(geoList, False)
|
||||
del geoList
|
||||
ArcSketch.MapMode = "Deactivated"
|
||||
|
||||
constraintList = []
|
||||
ArcSketch.addConstraint(Sketcher.Constraint("Radius", 0, 10.000000))
|
||||
constraintList.append(Sketcher.Constraint("Coincident", 0, 3, -1, 1))
|
||||
constraintList.append(Sketcher.Constraint("PointOnObject", 0, 2, -1))
|
||||
constraintList.append(Sketcher.Constraint("PointOnObject", 0, 1, -1))
|
||||
ArcSketch.addConstraint(constraintList)
|
||||
del constraintList
|
||||
geoList = []
|
||||
geoList.append(
|
||||
Part.ArcOfCircle(
|
||||
Part.Circle(
|
||||
Base.Vector(0.000000, 0.000000, 0.000000),
|
||||
Base.Vector(0.000000, 0.000000, 1.000000),
|
||||
10.000000,
|
||||
),
|
||||
3.141593,
|
||||
6.283185,
|
||||
)
|
||||
)
|
||||
ArcSketch.addGeometry(geoList, False)
|
||||
del geoList
|
||||
|
||||
self.Doc.recompute()
|
||||
constraintList = []
|
||||
ArcSketch.addConstraint(Sketcher.Constraint("Radius", 0, 10.000000))
|
||||
constraintList.append(Sketcher.Constraint("Coincident", 0, 3, -1, 1))
|
||||
constraintList.append(Sketcher.Constraint("PointOnObject", 0, 2, -1))
|
||||
constraintList.append(Sketcher.Constraint("PointOnObject", 0, 1, -1))
|
||||
ArcSketch.addConstraint(constraintList)
|
||||
del constraintList
|
||||
|
||||
PointSketch = self.Doc.addObject("Sketcher::SketchObject", "PointSketch")
|
||||
PointSketch.Placement = Base.Placement(
|
||||
Base.Vector(-10.000000, 0.000000, 0.000000),
|
||||
Base.Rotation(0.500000, 0.500000, 0.500000, 0.500000),
|
||||
)
|
||||
PointSketch.MapMode = "Deactivated"
|
||||
self.Doc.recompute()
|
||||
|
||||
PointSketch.addGeometry(Part.Point(Base.Vector(0.000000, 0.000000, 0)))
|
||||
PointSketch = self.Doc.addObject("Sketcher::SketchObject", "PointSketch")
|
||||
PointSketch.Placement = Base.Placement(
|
||||
Base.Vector(-10.000000, 0.000000, 0.000000),
|
||||
Base.Rotation(0.500000, 0.500000, 0.500000, 0.500000),
|
||||
)
|
||||
PointSketch.MapMode = "Deactivated"
|
||||
|
||||
PointSketch.addConstraint(Sketcher.Constraint("Coincident", 0, 1, -1, 1))
|
||||
PointSketch.addGeometry(Part.Point(Base.Vector(0.000000, 0.000000, 0)))
|
||||
|
||||
self.Doc.recompute()
|
||||
PointSketch.addConstraint(Sketcher.Constraint("Coincident", 0, 1, -1, 1))
|
||||
|
||||
Loft = self.Doc.addObject("Part::Loft", "Loft")
|
||||
Loft.Sections = [
|
||||
ArcSketch,
|
||||
PointSketch,
|
||||
]
|
||||
Loft.Solid = False
|
||||
Loft.Ruled = False
|
||||
Loft.Closed = False
|
||||
self.Doc.recompute()
|
||||
|
||||
# Act
|
||||
self.Doc.recompute()
|
||||
Loft = self.Doc.addObject("Part::Loft", "Loft")
|
||||
Loft.Sections = [
|
||||
ArcSketch,
|
||||
PointSketch,
|
||||
]
|
||||
Loft.Solid = False
|
||||
Loft.Ruled = False
|
||||
Loft.Closed = False
|
||||
|
||||
# Assert
|
||||
self.assertTrue(Loft.isValid())
|
||||
self.KeepTestDoc = not Loft.isValid()
|
||||
# Act
|
||||
self.Doc.recompute()
|
||||
|
||||
# Assert
|
||||
self.assertTrue(Loft.isValid())
|
||||
self.KeepTestDoc = not Loft.isValid()
|
||||
|
||||
def test_OptimalBox(self):
|
||||
box = Part.makeBox(1, 1, 1)
|
||||
|
||||
@@ -131,81 +131,84 @@ class TestSketchValidateCoincidents(unittest.TestCase):
|
||||
def testExternalGeoDeletion(self):
|
||||
"""Make sure that we don't remove External Geometry references to deleted geometry.
|
||||
See https://github.com/FreeCAD/FreeCAD/issues/16361"""
|
||||
doc = App.ActiveDocument
|
||||
doc.addObject("PartDesign::Body", "Body")
|
||||
doc.Body.Label = "Body"
|
||||
doc.recompute()
|
||||
doc.Body.newObject("Sketcher::SketchObject", "Sketch")
|
||||
doc.Sketch.AttachmentSupport = (doc.XY_Plane, [""])
|
||||
doc.Sketch.MapMode = "FlatFace"
|
||||
doc.recompute()
|
||||
geoList = []
|
||||
geoList.append(
|
||||
Part.LineSegment(
|
||||
App.Vector(7.548310, 5.193216, 0.000000), App.Vector(31.461353, 5.193216, 0.000000)
|
||||
if "BUILD_PARTDESIGN" in FreeCAD.__cmake__:
|
||||
doc = App.ActiveDocument
|
||||
doc.addObject("PartDesign::Body", "Body")
|
||||
doc.Body.Label = "Body"
|
||||
doc.recompute()
|
||||
doc.Body.newObject("Sketcher::SketchObject", "Sketch")
|
||||
doc.Sketch.AttachmentSupport = (doc.XY_Plane, [""])
|
||||
doc.Sketch.MapMode = "FlatFace"
|
||||
doc.recompute()
|
||||
geoList = []
|
||||
geoList.append(
|
||||
Part.LineSegment(
|
||||
App.Vector(7.548310, 5.193216, 0.000000),
|
||||
App.Vector(31.461353, 5.193216, 0.000000),
|
||||
)
|
||||
)
|
||||
)
|
||||
geoList.append(
|
||||
Part.LineSegment(
|
||||
App.Vector(31.461353, 5.193216, 0.000000),
|
||||
App.Vector(31.461353, 20.652151, 0.000000),
|
||||
geoList.append(
|
||||
Part.LineSegment(
|
||||
App.Vector(31.461353, 5.193216, 0.000000),
|
||||
App.Vector(31.461353, 20.652151, 0.000000),
|
||||
)
|
||||
)
|
||||
)
|
||||
geoList.append(
|
||||
Part.LineSegment(
|
||||
App.Vector(31.461353, 20.652151, 0.000000),
|
||||
App.Vector(7.548310, 20.652151, 0.000000),
|
||||
geoList.append(
|
||||
Part.LineSegment(
|
||||
App.Vector(31.461353, 20.652151, 0.000000),
|
||||
App.Vector(7.548310, 20.652151, 0.000000),
|
||||
)
|
||||
)
|
||||
)
|
||||
geoList.append(
|
||||
Part.LineSegment(
|
||||
App.Vector(7.548310, 20.652151, 0.000000), App.Vector(7.548310, 5.193216, 0.000000)
|
||||
geoList.append(
|
||||
Part.LineSegment(
|
||||
App.Vector(7.548310, 20.652151, 0.000000),
|
||||
App.Vector(7.548310, 5.193216, 0.000000),
|
||||
)
|
||||
)
|
||||
)
|
||||
doc.Sketch.addGeometry(geoList, False)
|
||||
del geoList
|
||||
constraintList = []
|
||||
constraintList.append(Sketcher.Constraint("Coincident", 0, 2, 1, 1))
|
||||
constraintList.append(Sketcher.Constraint("Coincident", 1, 2, 2, 1))
|
||||
constraintList.append(Sketcher.Constraint("Coincident", 2, 2, 3, 1))
|
||||
constraintList.append(Sketcher.Constraint("Coincident", 3, 2, 0, 1))
|
||||
constraintList.append(Sketcher.Constraint("Horizontal", 0))
|
||||
constraintList.append(Sketcher.Constraint("Horizontal", 2))
|
||||
constraintList.append(Sketcher.Constraint("Vertical", 1))
|
||||
constraintList.append(Sketcher.Constraint("Vertical", 3))
|
||||
doc.Sketch.addConstraint(constraintList)
|
||||
del constraintList
|
||||
constraintList = []
|
||||
doc.recompute()
|
||||
doc.Body.newObject("Sketcher::SketchObject", "Sketch001")
|
||||
doc.Sketch001.AttachmentSupport = (doc.XY_Plane, [""])
|
||||
doc.Sketch001.MapMode = "FlatFace"
|
||||
doc.recompute()
|
||||
doc.Sketch001.addExternal("Sketch", "Edge3")
|
||||
geoList = []
|
||||
geoList.append(
|
||||
Part.LineSegment(
|
||||
App.Vector(33.192780, 22.530144, 0.000000),
|
||||
App.Vector(38.493977, 32.289181, 0.000000),
|
||||
doc.Sketch.addGeometry(geoList, False)
|
||||
del geoList
|
||||
constraintList = []
|
||||
constraintList.append(Sketcher.Constraint("Coincident", 0, 2, 1, 1))
|
||||
constraintList.append(Sketcher.Constraint("Coincident", 1, 2, 2, 1))
|
||||
constraintList.append(Sketcher.Constraint("Coincident", 2, 2, 3, 1))
|
||||
constraintList.append(Sketcher.Constraint("Coincident", 3, 2, 0, 1))
|
||||
constraintList.append(Sketcher.Constraint("Horizontal", 0))
|
||||
constraintList.append(Sketcher.Constraint("Horizontal", 2))
|
||||
constraintList.append(Sketcher.Constraint("Vertical", 1))
|
||||
constraintList.append(Sketcher.Constraint("Vertical", 3))
|
||||
doc.Sketch.addConstraint(constraintList)
|
||||
del constraintList
|
||||
constraintList = []
|
||||
doc.recompute()
|
||||
doc.Body.newObject("Sketcher::SketchObject", "Sketch001")
|
||||
doc.Sketch001.AttachmentSupport = (doc.XY_Plane, [""])
|
||||
doc.Sketch001.MapMode = "FlatFace"
|
||||
doc.recompute()
|
||||
doc.Sketch001.addExternal("Sketch", "Edge3")
|
||||
geoList = []
|
||||
geoList.append(
|
||||
Part.LineSegment(
|
||||
App.Vector(33.192780, 22.530144, 0.000000),
|
||||
App.Vector(38.493977, 32.289181, 0.000000),
|
||||
)
|
||||
)
|
||||
)
|
||||
doc.Sketch001.addGeometry(geoList, False)
|
||||
del geoList
|
||||
constraintList = []
|
||||
doc.Sketch001.addConstraint(Sketcher.Constraint("Coincident", 0, 1, -3, 1))
|
||||
doc.recompute()
|
||||
doc.Sketch.delGeometries([1])
|
||||
doc.Sketch.delGeometries([1])
|
||||
doc.recompute()
|
||||
doc.Sketch001.addConstraint(Sketcher.Constraint("Coincident", 0, 1, -3, 1))
|
||||
doc.recompute()
|
||||
# Assert
|
||||
self.assertEqual(len(doc.Sketch001.Constraints), 2) # Still have the constraints
|
||||
self.assertEqual(len(doc.Sketch001.ExternalGeometry), 0)
|
||||
self.assertEqual(len(doc.Sketch001.Geometry), 1)
|
||||
self.assertEqual(
|
||||
len(doc.Sketch001.ExternalGeo), 3
|
||||
) # Two axis, plus one the reference to deleted geometry
|
||||
doc.Sketch001.addGeometry(geoList, False)
|
||||
del geoList
|
||||
constraintList = []
|
||||
doc.Sketch001.addConstraint(Sketcher.Constraint("Coincident", 0, 1, -3, 1))
|
||||
doc.recompute()
|
||||
doc.Sketch.delGeometries([1])
|
||||
doc.Sketch.delGeometries([1])
|
||||
doc.recompute()
|
||||
doc.Sketch001.addConstraint(Sketcher.Constraint("Coincident", 0, 1, -3, 1))
|
||||
doc.recompute()
|
||||
# Assert
|
||||
self.assertEqual(len(doc.Sketch001.Constraints), 2) # Still have the constraints
|
||||
self.assertEqual(len(doc.Sketch001.ExternalGeometry), 0)
|
||||
self.assertEqual(len(doc.Sketch001.Geometry), 1)
|
||||
self.assertEqual(
|
||||
len(doc.Sketch001.ExternalGeo), 3
|
||||
) # Two axis, plus one the reference to deleted geometry
|
||||
|
||||
def tearDown(self):
|
||||
# closing doc
|
||||
|
||||
@@ -481,218 +481,222 @@ class TestSketcherSolver(unittest.TestCase):
|
||||
)
|
||||
|
||||
def testRemovedExternalGeometryReference(self):
|
||||
body = self.Doc.addObject("PartDesign::Body", "Body")
|
||||
sketch = body.newObject("Sketcher::SketchObject", "Sketch")
|
||||
CreateRectangleSketch(sketch, (0, 0), (30, 30))
|
||||
pad = body.newObject("PartDesign::Pad", "Pad")
|
||||
pad.Profile = sketch
|
||||
sketch1 = body.newObject("Sketcher::SketchObject", "Sketch1")
|
||||
CreateCircleSketch(sketch1, (15, 15), 0.25)
|
||||
self.Doc.recompute()
|
||||
self.assertEqual(len(pad.Shape.Edges), 12)
|
||||
if "BUILD_PARTDESIGN" in FreeCAD.__cmake__:
|
||||
body = self.Doc.addObject("PartDesign::Body", "Body")
|
||||
sketch = body.newObject("Sketcher::SketchObject", "Sketch")
|
||||
CreateRectangleSketch(sketch, (0, 0), (30, 30))
|
||||
pad = body.newObject("PartDesign::Pad", "Pad")
|
||||
pad.Profile = sketch
|
||||
sketch1 = body.newObject("Sketcher::SketchObject", "Sketch1")
|
||||
CreateCircleSketch(sketch1, (15, 15), 0.25)
|
||||
self.Doc.recompute()
|
||||
self.assertEqual(len(pad.Shape.Edges), 12)
|
||||
|
||||
hole = self.Doc.addObject("PartDesign::Hole", "Hole")
|
||||
hole.Refine = True
|
||||
hole.Reversed = True
|
||||
body.addObject(hole)
|
||||
hole.Profile = sketch1
|
||||
hole.DrillPointAngle = 118.000000
|
||||
hole.Diameter = 6.000000
|
||||
hole.TaperedAngle = 90.000000
|
||||
hole.Tapered = 0
|
||||
hole.Depth = 8.000000
|
||||
hole.Threaded = 1
|
||||
hole.ModelThread = 0
|
||||
hole.ThreadDepthType = 0
|
||||
hole.ThreadType = 1
|
||||
hole.ThreadSize = 16
|
||||
hole.ThreadClass = 0
|
||||
hole.ThreadDirection = 0
|
||||
hole.HoleCutType = 0
|
||||
hole.DepthType = 0
|
||||
hole.DrillPoint = 1
|
||||
hole.DrillForDepth = 0
|
||||
self.Doc.recompute()
|
||||
# 15 edges if it's passthrough-flat 17 if DrillPoint = 1
|
||||
self.assertEqual(len(hole.Shape.Edges), 17)
|
||||
hole = self.Doc.addObject("PartDesign::Hole", "Hole")
|
||||
hole.Refine = True
|
||||
hole.Reversed = True
|
||||
body.addObject(hole)
|
||||
hole.Profile = sketch1
|
||||
hole.DrillPointAngle = 118.000000
|
||||
hole.Diameter = 6.000000
|
||||
hole.TaperedAngle = 90.000000
|
||||
hole.Tapered = 0
|
||||
hole.Depth = 8.000000
|
||||
hole.Threaded = 1
|
||||
hole.ModelThread = 0
|
||||
hole.ThreadDepthType = 0
|
||||
hole.ThreadType = 1
|
||||
hole.ThreadSize = 16
|
||||
hole.ThreadClass = 0
|
||||
hole.ThreadDirection = 0
|
||||
hole.HoleCutType = 0
|
||||
hole.DepthType = 0
|
||||
hole.DrillPoint = 1
|
||||
hole.DrillForDepth = 0
|
||||
self.Doc.recompute()
|
||||
# 15 edges if it's passthrough-flat 17 if DrillPoint = 1
|
||||
self.assertEqual(len(hole.Shape.Edges), 17)
|
||||
|
||||
hole.ModelThread = 1
|
||||
sketch2 = body.newObject("Sketcher::SketchObject", "Sketch2")
|
||||
CreateRectangleSketch(sketch2, (0, 0), (3, 3))
|
||||
self.Doc.recompute()
|
||||
self.assertGreater(len(hole.Shape.Edges), 17)
|
||||
# 77 edges for basic profile
|
||||
self.assertEqual(len(hole.Shape.Edges), 77)
|
||||
hole.ModelThread = 1
|
||||
sketch2 = body.newObject("Sketcher::SketchObject", "Sketch2")
|
||||
CreateRectangleSketch(sketch2, (0, 0), (3, 3))
|
||||
self.Doc.recompute()
|
||||
self.assertGreater(len(hole.Shape.Edges), 17)
|
||||
# 77 edges for basic profile
|
||||
self.assertEqual(len(hole.Shape.Edges), 77)
|
||||
|
||||
# Edges in the thread should disappear when we stop modeling thread
|
||||
sketch2.addExternal("Hole", "Edge29")
|
||||
hole.ModelThread = 0
|
||||
hole.Refine = 1
|
||||
self.Doc.recompute()
|
||||
self.assertEqual(len(hole.Shape.Edges), 17)
|
||||
self.assertEqual(len(sketch2.ExternalGeometry), 0)
|
||||
# Edges in the thread should disappear when we stop modeling thread
|
||||
sketch2.addExternal("Hole", "Edge29")
|
||||
hole.ModelThread = 0
|
||||
hole.Refine = 1
|
||||
self.Doc.recompute()
|
||||
self.assertEqual(len(hole.Shape.Edges), 17)
|
||||
self.assertEqual(len(sketch2.ExternalGeometry), 0)
|
||||
|
||||
def testSaveLoadWithExternalGeometryReference(self):
|
||||
# Arrange
|
||||
body = self.Doc.addObject("PartDesign::Body", "Body")
|
||||
sketch = self.Doc.addObject("Sketcher::SketchObject", "Sketch")
|
||||
CreateRectangleSketch(sketch, (0, 0), (30, 30))
|
||||
pad = self.Doc.addObject("PartDesign::Pad", "Pad")
|
||||
pad.Profile = sketch
|
||||
sketch1 = self.Doc.addObject("Sketcher::SketchObject", "Sketch1")
|
||||
body.addObject(sketch)
|
||||
body.addObject(pad)
|
||||
body.addObject(sketch1)
|
||||
self.Doc.recompute()
|
||||
sketch1.addExternal("Pad", "Edge12")
|
||||
self.Doc.recompute()
|
||||
if "BUILD_PARTDESIGN" in FreeCAD.__cmake__:
|
||||
# Arrange
|
||||
body = self.Doc.addObject("PartDesign::Body", "Body")
|
||||
sketch = self.Doc.addObject("Sketcher::SketchObject", "Sketch")
|
||||
CreateRectangleSketch(sketch, (0, 0), (30, 30))
|
||||
pad = self.Doc.addObject("PartDesign::Pad", "Pad")
|
||||
pad.Profile = sketch
|
||||
sketch1 = self.Doc.addObject("Sketcher::SketchObject", "Sketch1")
|
||||
body.addObject(sketch)
|
||||
body.addObject(pad)
|
||||
body.addObject(sketch1)
|
||||
self.Doc.recompute()
|
||||
sketch1.addExternal("Pad", "Edge12")
|
||||
self.Doc.recompute()
|
||||
|
||||
# Act: Try changing sketch before the save
|
||||
sketch = self.Doc.getObject("Sketch")
|
||||
g1 = sketch.Constraints[11].First
|
||||
d1 = sketch.Constraints[11].Value
|
||||
sketch.delConstraint(11)
|
||||
sketch.addConstraint(Sketcher.Constraint("Distance", g1, d1 - 1.0))
|
||||
self.Doc.recompute()
|
||||
# Act: Try changing sketch before the save
|
||||
sketch = self.Doc.getObject("Sketch")
|
||||
g1 = sketch.Constraints[11].First
|
||||
d1 = sketch.Constraints[11].Value
|
||||
sketch.delConstraint(11)
|
||||
sketch.addConstraint(Sketcher.Constraint("Distance", g1, d1 - 1.0))
|
||||
self.Doc.recompute()
|
||||
|
||||
# Act: Save and reload the file
|
||||
filename = self.Doc.Name + ".FCStd"
|
||||
self.Doc.saveAs(filename)
|
||||
FreeCAD.closeDocument(self.Doc.Name)
|
||||
self.Doc = FreeCAD.openDocument(filename)
|
||||
pad = self.Doc.getObject("Pad")
|
||||
sketch1 = self.Doc.getObject("Sketch1")
|
||||
self.Doc.recompute()
|
||||
# Act: Save and reload the file
|
||||
filename = self.Doc.Name + ".FCStd"
|
||||
self.Doc.saveAs(filename)
|
||||
FreeCAD.closeDocument(self.Doc.Name)
|
||||
self.Doc = FreeCAD.openDocument(filename)
|
||||
pad = self.Doc.getObject("Pad")
|
||||
sketch1 = self.Doc.getObject("Sketch1")
|
||||
self.Doc.recompute()
|
||||
|
||||
# Act: change sketch after restore ( trigger missing references if there is a bug )
|
||||
sketch = self.Doc.getObject("Sketch")
|
||||
g1 = sketch.Constraints[11].First
|
||||
d1 = sketch.Constraints[11].Value
|
||||
sketch.delConstraint(11)
|
||||
sketch.addConstraint(Sketcher.Constraint("Distance", g1, d1 - 1.0))
|
||||
self.Doc.recompute()
|
||||
# Act: change sketch after restore ( trigger missing references if there is a bug )
|
||||
sketch = self.Doc.getObject("Sketch")
|
||||
g1 = sketch.Constraints[11].First
|
||||
d1 = sketch.Constraints[11].Value
|
||||
sketch.delConstraint(11)
|
||||
sketch.addConstraint(Sketcher.Constraint("Distance", g1, d1 - 1.0))
|
||||
self.Doc.recompute()
|
||||
|
||||
# Assert
|
||||
self.assertEqual(pad.Shape.ElementMapSize, 30)
|
||||
self.assertIn("Edge12", pad.Shape.ElementReverseMap)
|
||||
self.assertIn((pad, ("Edge12",)), sketch1.ExternalGeometry) # Not "?Edge12"
|
||||
# Assert
|
||||
self.assertEqual(pad.Shape.ElementMapSize, 30)
|
||||
self.assertIn("Edge12", pad.Shape.ElementReverseMap)
|
||||
self.assertIn((pad, ("Edge12",)), sketch1.ExternalGeometry) # Not "?Edge12"
|
||||
|
||||
def testTNPExternalGeometryStored(self):
|
||||
# Arrange
|
||||
import xml.etree.ElementTree as ET
|
||||
if "BUILD_PARTDESIGN" in FreeCAD.__cmake__:
|
||||
import xml.etree.ElementTree as ET
|
||||
|
||||
sketch = self.Doc.addObject("Sketcher::SketchObject", "Sketch")
|
||||
CreateRectangleSketch(sketch, (0, 0), (30, 30))
|
||||
sketch1 = self.Doc.addObject("Sketcher::SketchObject", "Sketch1")
|
||||
pad = self.Doc.addObject("PartDesign::Pad", "Pad")
|
||||
pad.Profile = sketch
|
||||
self.Doc.recompute()
|
||||
sketch1.addExternal("Pad", "Edge12")
|
||||
self.Doc.recompute()
|
||||
# Act
|
||||
root = ET.fromstring("<all>" + sketch1.Content + "</all>")
|
||||
# Can't use != in an xpath because it wasn't added until python 3.10.
|
||||
# "*/*[@name='ExternalGeo']//*/[@type='Sketcher::ExternalGeometryExtension']/[@Ref!='']"
|
||||
extRefs = root.findall(
|
||||
"*/*[@name='ExternalGeo']//*/[@type='Sketcher::ExternalGeometryExtension']/[@Ref='']"
|
||||
)
|
||||
extRefsAll = root.findall(
|
||||
"*/*[@name='ExternalGeo']//*/[@type='Sketcher::ExternalGeometryExtension']/[@Ref]"
|
||||
)
|
||||
# Assert
|
||||
self.assertEqual(len(extRefs), 2)
|
||||
self.assertEqual(len(extRefsAll), 3)
|
||||
self.assertEqual(root.tag, "all")
|
||||
# Act
|
||||
filename = self.Doc.Name + ".FCStd"
|
||||
self.Doc.saveAs(filename)
|
||||
FreeCAD.closeDocument(self.Doc.Name)
|
||||
self.Doc = FreeCAD.openDocument(filename)
|
||||
# Assert
|
||||
root = ET.fromstring("<all>" + self.Doc.getObject("Sketch1").Content + "</all>")
|
||||
extRefs = root.findall(
|
||||
"*/*[@name='ExternalGeo']//*/[@type='Sketcher::ExternalGeometryExtension']/[@Ref='']"
|
||||
)
|
||||
extRefsAll = root.findall(
|
||||
"*/*[@name='ExternalGeo']//*/[@type='Sketcher::ExternalGeometryExtension']/[@Ref]"
|
||||
)
|
||||
self.assertEqual(len(extRefs), 2)
|
||||
self.assertEqual(len(extRefsAll), 3)
|
||||
self.assertEqual(root.tag, "all")
|
||||
# Act to change the constraint
|
||||
sketch = self.Doc.getObject("Sketch")
|
||||
g1 = sketch.Constraints[11].First
|
||||
d1 = sketch.Constraints[11].Value
|
||||
sketch.delConstraint(11)
|
||||
sketch.addConstraint(Sketcher.Constraint("Distance", g1, d1 - 1.0))
|
||||
self.Doc.recompute()
|
||||
# Assert
|
||||
root = ET.fromstring("<all>" + self.Doc.getObject("Sketch1").Content + "</all>")
|
||||
extRefs = root.findall(
|
||||
"*/*[@name='ExternalGeo']//*/[@type='Sketcher::ExternalGeometryExtension']/[@Ref='']"
|
||||
)
|
||||
extRefsAll = root.findall(
|
||||
"*/*[@name='ExternalGeo']//*/[@type='Sketcher::ExternalGeometryExtension']/[@Ref]"
|
||||
)
|
||||
self.assertEqual(len(extRefs), 2)
|
||||
self.assertEqual(len(extRefsAll), 3)
|
||||
self.assertEqual(root.tag, "all")
|
||||
sketch = self.Doc.addObject("Sketcher::SketchObject", "Sketch")
|
||||
CreateRectangleSketch(sketch, (0, 0), (30, 30))
|
||||
sketch1 = self.Doc.addObject("Sketcher::SketchObject", "Sketch1")
|
||||
pad = self.Doc.addObject("PartDesign::Pad", "Pad")
|
||||
pad.Profile = sketch
|
||||
self.Doc.recompute()
|
||||
sketch1.addExternal("Pad", "Edge12")
|
||||
self.Doc.recompute()
|
||||
# Act
|
||||
root = ET.fromstring("<all>" + sketch1.Content + "</all>")
|
||||
# Can't use != in an xpath because it wasn't added until python 3.10.
|
||||
# "*/*[@name='ExternalGeo']//*/[@type='Sketcher::ExternalGeometryExtension']/[@Ref!='']"
|
||||
extRefs = root.findall(
|
||||
"*/*[@name='ExternalGeo']//*/[@type='Sketcher::ExternalGeometryExtension']/[@Ref='']"
|
||||
)
|
||||
extRefsAll = root.findall(
|
||||
"*/*[@name='ExternalGeo']//*/[@type='Sketcher::ExternalGeometryExtension']/[@Ref]"
|
||||
)
|
||||
# Assert
|
||||
self.assertEqual(len(extRefs), 2)
|
||||
self.assertEqual(len(extRefsAll), 3)
|
||||
self.assertEqual(root.tag, "all")
|
||||
# Act
|
||||
filename = self.Doc.Name + ".FCStd"
|
||||
self.Doc.saveAs(filename)
|
||||
FreeCAD.closeDocument(self.Doc.Name)
|
||||
self.Doc = FreeCAD.openDocument(filename)
|
||||
# Assert
|
||||
root = ET.fromstring("<all>" + self.Doc.getObject("Sketch1").Content + "</all>")
|
||||
extRefs = root.findall(
|
||||
"*/*[@name='ExternalGeo']//*/[@type='Sketcher::ExternalGeometryExtension']/[@Ref='']"
|
||||
)
|
||||
extRefsAll = root.findall(
|
||||
"*/*[@name='ExternalGeo']//*/[@type='Sketcher::ExternalGeometryExtension']/[@Ref]"
|
||||
)
|
||||
self.assertEqual(len(extRefs), 2)
|
||||
self.assertEqual(len(extRefsAll), 3)
|
||||
self.assertEqual(root.tag, "all")
|
||||
# Act to change the constraint
|
||||
sketch = self.Doc.getObject("Sketch")
|
||||
g1 = sketch.Constraints[11].First
|
||||
d1 = sketch.Constraints[11].Value
|
||||
sketch.delConstraint(11)
|
||||
sketch.addConstraint(Sketcher.Constraint("Distance", g1, d1 - 1.0))
|
||||
self.Doc.recompute()
|
||||
# Assert
|
||||
root = ET.fromstring("<all>" + self.Doc.getObject("Sketch1").Content + "</all>")
|
||||
extRefs = root.findall(
|
||||
"*/*[@name='ExternalGeo']//*/[@type='Sketcher::ExternalGeometryExtension']/[@Ref='']"
|
||||
)
|
||||
extRefsAll = root.findall(
|
||||
"*/*[@name='ExternalGeo']//*/[@type='Sketcher::ExternalGeometryExtension']/[@Ref]"
|
||||
)
|
||||
self.assertEqual(len(extRefs), 2)
|
||||
self.assertEqual(len(extRefsAll), 3)
|
||||
self.assertEqual(root.tag, "all")
|
||||
|
||||
def testConstructionToggleTNP(self):
|
||||
"""Bug 15484"""
|
||||
# Arrange
|
||||
import xml.etree.ElementTree as ET
|
||||
if "BUILD_PARTDESIGN" in FreeCAD.__cmake__:
|
||||
# Arrange
|
||||
import xml.etree.ElementTree as ET
|
||||
|
||||
body = self.Doc.addObject("PartDesign::Body", "Body")
|
||||
sketch = self.Doc.addObject("Sketcher::SketchObject", "Sketch")
|
||||
CreateRectangleSketch(sketch, (0, 0), (30, 30))
|
||||
# Add zigsag geo as construction lines
|
||||
i = sketch.GeometryCount
|
||||
sketch.addGeometry(
|
||||
Part.LineSegment(FreeCAD.Vector(0, 0, 0), FreeCAD.Vector(-10, 10, 0)), True
|
||||
)
|
||||
sketch.addGeometry(
|
||||
Part.LineSegment(FreeCAD.Vector(-10, 10, 0), FreeCAD.Vector(-5, 20, 0)), True
|
||||
)
|
||||
sketch.addGeometry(
|
||||
Part.LineSegment(FreeCAD.Vector(-5, 20, 0), FreeCAD.Vector(-10, 25, 0)), True
|
||||
)
|
||||
sketch.addGeometry(
|
||||
Part.LineSegment(FreeCAD.Vector(-10, 25, 0), FreeCAD.Vector(0, 30, 0)), True
|
||||
)
|
||||
sketch.addConstraint(Sketcher.Constraint("Coincident", i + 0, 2, i + 1, 1))
|
||||
sketch.addConstraint(Sketcher.Constraint("Coincident", i + 1, 2, i + 2, 1))
|
||||
sketch.addConstraint(Sketcher.Constraint("Coincident", i + 2, 2, i + 3, 1))
|
||||
sketch.addConstraint(Sketcher.Constraint("Coincident", i + 3, 2, 0, 1))
|
||||
sketch.addConstraint(Sketcher.Constraint("Coincident", i + 0, 1, 2, 2))
|
||||
body = self.Doc.addObject("PartDesign::Body", "Body")
|
||||
sketch = self.Doc.addObject("Sketcher::SketchObject", "Sketch")
|
||||
CreateRectangleSketch(sketch, (0, 0), (30, 30))
|
||||
# Add zigsag geo as construction lines
|
||||
i = sketch.GeometryCount
|
||||
sketch.addGeometry(
|
||||
Part.LineSegment(FreeCAD.Vector(0, 0, 0), FreeCAD.Vector(-10, 10, 0)), True
|
||||
)
|
||||
sketch.addGeometry(
|
||||
Part.LineSegment(FreeCAD.Vector(-10, 10, 0), FreeCAD.Vector(-5, 20, 0)), True
|
||||
)
|
||||
sketch.addGeometry(
|
||||
Part.LineSegment(FreeCAD.Vector(-5, 20, 0), FreeCAD.Vector(-10, 25, 0)), True
|
||||
)
|
||||
sketch.addGeometry(
|
||||
Part.LineSegment(FreeCAD.Vector(-10, 25, 0), FreeCAD.Vector(0, 30, 0)), True
|
||||
)
|
||||
sketch.addConstraint(Sketcher.Constraint("Coincident", i + 0, 2, i + 1, 1))
|
||||
sketch.addConstraint(Sketcher.Constraint("Coincident", i + 1, 2, i + 2, 1))
|
||||
sketch.addConstraint(Sketcher.Constraint("Coincident", i + 2, 2, i + 3, 1))
|
||||
sketch.addConstraint(Sketcher.Constraint("Coincident", i + 3, 2, 0, 1))
|
||||
sketch.addConstraint(Sketcher.Constraint("Coincident", i + 0, 1, 2, 2))
|
||||
|
||||
pad = self.Doc.addObject("PartDesign::Pad", "Pad")
|
||||
pad.Profile = sketch
|
||||
body.addObject(sketch)
|
||||
body.addObject(pad)
|
||||
self.Doc.recompute()
|
||||
sketch1 = self.Doc.addObject("Sketcher::SketchObject", "Sketch1")
|
||||
sketch1.AttachmentSupport = (pad, ("Face6"))
|
||||
sketch1.MapMode = "FlatFace"
|
||||
self.Doc.recompute()
|
||||
pad = self.Doc.addObject("PartDesign::Pad", "Pad")
|
||||
pad.Profile = sketch
|
||||
body.addObject(sketch)
|
||||
body.addObject(pad)
|
||||
self.Doc.recompute()
|
||||
sketch1 = self.Doc.addObject("Sketcher::SketchObject", "Sketch1")
|
||||
sketch1.AttachmentSupport = (pad, ("Face6"))
|
||||
sketch1.MapMode = "FlatFace"
|
||||
self.Doc.recompute()
|
||||
|
||||
CreateCircleSketch(sketch1, (2, 2, 0), 1)
|
||||
CreateCircleSketch(sketch1, (6, 2, 0), 1)
|
||||
body.addObject(sketch1)
|
||||
self.Doc.recompute()
|
||||
# Act toggle construction lines on in sketch; pad now has 9 instead of 6 faces.
|
||||
sketch.setConstruction(4, False)
|
||||
sketch.setConstruction(5, False)
|
||||
sketch.setConstruction(6, False)
|
||||
sketch.setConstruction(7, False)
|
||||
sketch.setConstruction(3, True)
|
||||
self.Doc.recompute()
|
||||
# Assert
|
||||
# AttachmentSupport is a list of (object,(subobject list)) with 1 entry. Get the
|
||||
# first and only subobject name in second part of that first tuple and see that it moved
|
||||
# from the Face6 we set above.
|
||||
self.assertEqual(sketch1.AttachmentSupport[0][1][0], "Face9")
|
||||
self.assertIn("Face6", pad.Shape.ElementReverseMap) # different Face6 exists
|
||||
CreateCircleSketch(sketch1, (2, 2, 0), 1)
|
||||
CreateCircleSketch(sketch1, (6, 2, 0), 1)
|
||||
body.addObject(sketch1)
|
||||
self.Doc.recompute()
|
||||
# Act toggle construction lines on in sketch; pad now has 9 instead of 6 faces.
|
||||
sketch.setConstruction(4, False)
|
||||
sketch.setConstruction(5, False)
|
||||
sketch.setConstruction(6, False)
|
||||
sketch.setConstruction(7, False)
|
||||
sketch.setConstruction(3, True)
|
||||
self.Doc.recompute()
|
||||
# Assert
|
||||
# AttachmentSupport is a list of (object,(subobject list)) with 1 entry. Get the
|
||||
# first and only subobject name in second part of that first tuple and see that it moved
|
||||
# from the Face6 we set above.
|
||||
self.assertEqual(sketch1.AttachmentSupport[0][1][0], "Face9")
|
||||
self.assertIn("Face6", pad.Shape.ElementReverseMap) # different Face6 exists
|
||||
|
||||
# TODO other tests:
|
||||
# getHigherElement
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
# * *
|
||||
# ***************************************************************************/
|
||||
|
||||
from plistlib import UID
|
||||
import FreeCAD, os, unittest, tempfile
|
||||
from FreeCAD import Base
|
||||
import math
|
||||
@@ -674,45 +673,46 @@ class DocumentBasicCases(unittest.TestCase):
|
||||
|
||||
class DocumentImportCases(unittest.TestCase):
|
||||
def testDXFImportCPPIssue20195(self):
|
||||
import importDXF
|
||||
from draftutils import params
|
||||
if "BUILD_DRAFT" in FreeCAD.__cmake__:
|
||||
import importDXF
|
||||
from draftutils import params
|
||||
|
||||
# Set options, doing our best to restore them:
|
||||
wasShowDialog = params.get_param("dxfShowDialog")
|
||||
wasUseLayers = params.get_param("dxfUseDraftVisGroups")
|
||||
wasUseLegacyImporter = params.get_param("dxfUseLegacyImporter")
|
||||
wasCreatePart = params.get_param("dxfCreatePart")
|
||||
wasCreateDraft = params.get_param("dxfCreateDraft")
|
||||
wasCreateSketch = params.get_param("dxfCreateSketch")
|
||||
# Set options, doing our best to restore them:
|
||||
wasShowDialog = params.get_param("dxfShowDialog")
|
||||
wasUseLayers = params.get_param("dxfUseDraftVisGroups")
|
||||
wasUseLegacyImporter = params.get_param("dxfUseLegacyImporter")
|
||||
wasCreatePart = params.get_param("dxfCreatePart")
|
||||
wasCreateDraft = params.get_param("dxfCreateDraft")
|
||||
wasCreateSketch = params.get_param("dxfCreateSketch")
|
||||
|
||||
try:
|
||||
# disable Preferences dialog in gui mode (avoids popup prompt to user)
|
||||
params.set_param("dxfShowDialog", False)
|
||||
# Preserve the DXF layers (makes the checking of document contents easier)
|
||||
params.set_param("dxfUseDraftVisGroups", True)
|
||||
# Use the new C++ importer -- that's where the bug was
|
||||
params.set_param("dxfUseLegacyImporter", False)
|
||||
# create simple part shapes (3 params)
|
||||
# This is required to display the bug because creation of Draft objects clears out the
|
||||
# pending exception this test is looking for, whereas creation of the simple shape object
|
||||
# actually throws on the pending exception so the entity is absent from the document.
|
||||
params.set_param("dxfCreatePart", True)
|
||||
params.set_param("dxfCreateDraft", False)
|
||||
params.set_param("dxfCreateSketch", False)
|
||||
importDXF.insert(
|
||||
FreeCAD.getHomePath() + "Mod/Test/TestData/DXFSample.dxf", "ImportedDocName"
|
||||
)
|
||||
finally:
|
||||
params.set_param("dxfShowDialog", wasShowDialog)
|
||||
params.set_param("dxfUseDraftVisGroups", wasUseLayers)
|
||||
params.set_param("dxfUseLegacyImporter", wasUseLegacyImporter)
|
||||
params.set_param("dxfCreatePart", wasCreatePart)
|
||||
params.set_param("dxfCreateDraft", wasCreateDraft)
|
||||
params.set_param("dxfCreateSketch", wasCreateSketch)
|
||||
doc = FreeCAD.getDocument("ImportedDocName")
|
||||
# This doc should have 3 objects: The Layers container, the DXF layer called 0, and one Line
|
||||
self.assertEqual(len(doc.Objects), 3)
|
||||
FreeCAD.closeDocument("ImportedDocName")
|
||||
try:
|
||||
# disable Preferences dialog in gui mode (avoids popup prompt to user)
|
||||
params.set_param("dxfShowDialog", False)
|
||||
# Preserve the DXF layers (makes the checking of document contents easier)
|
||||
params.set_param("dxfUseDraftVisGroups", True)
|
||||
# Use the new C++ importer -- that's where the bug was
|
||||
params.set_param("dxfUseLegacyImporter", False)
|
||||
# create simple part shapes (3 params)
|
||||
# This is required to display the bug because creation of Draft objects clears out the
|
||||
# pending exception this test is looking for, whereas creation of the simple shape object
|
||||
# actually throws on the pending exception so the entity is absent from the document.
|
||||
params.set_param("dxfCreatePart", True)
|
||||
params.set_param("dxfCreateDraft", False)
|
||||
params.set_param("dxfCreateSketch", False)
|
||||
importDXF.insert(
|
||||
FreeCAD.getHomePath() + "Mod/Test/TestData/DXFSample.dxf", "ImportedDocName"
|
||||
)
|
||||
finally:
|
||||
params.set_param("dxfShowDialog", wasShowDialog)
|
||||
params.set_param("dxfUseDraftVisGroups", wasUseLayers)
|
||||
params.set_param("dxfUseLegacyImporter", wasUseLegacyImporter)
|
||||
params.set_param("dxfCreatePart", wasCreatePart)
|
||||
params.set_param("dxfCreateDraft", wasCreateDraft)
|
||||
params.set_param("dxfCreateSketch", wasCreateSketch)
|
||||
doc = FreeCAD.getDocument("ImportedDocName")
|
||||
# This doc should have 3 objects: The Layers container, the DXF layer called 0, and one Line
|
||||
self.assertEqual(len(doc.Objects), 3)
|
||||
FreeCAD.closeDocument("ImportedDocName")
|
||||
|
||||
|
||||
# class must be defined in global scope to allow it to be reloaded on document open
|
||||
|
||||
Reference in New Issue
Block a user