Skip to content

Commit

Permalink
[Part] Four Ruled Surfaces on 3 main planes and one special
Browse files Browse the repository at this point in the history
  • Loading branch information
Syres916 authored Oct 15, 2024
1 parent d2adeb6 commit 4965738
Showing 1 changed file with 208 additions and 5 deletions.
213 changes: 208 additions & 5 deletions src/Mod/Part/TestPartGui.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import Part
import PartGui
from PySide import QtWidgets
import Sketcher

def findDockWidget(name):
""" Get a dock widget by name """
Expand All @@ -53,10 +54,10 @@ def findDockWidget(name):
#
# def testBoxCase(self):
# self.Box = self.Doc.addObject('Part::SketchObject','SketchBox')
# self.Box.addGeometry(Part.LineSegment(App.Vector(-99.230339,36.960674,0),App.Vector(69.432587,36.960674,0)))
# self.Box.addGeometry(Part.LineSegment(App.Vector(69.432587,36.960674,0),App.Vector(69.432587,-53.196629,0)))
# self.Box.addGeometry(Part.LineSegment(App.Vector(69.432587,-53.196629,0),App.Vector(-99.230339,-53.196629,0)))
# self.Box.addGeometry(Part.LineSegment(App.Vector(-99.230339,-53.196629,0),App.Vector(-99.230339,36.960674,0)))
# self.Box.addGeometry(Part.LineSegment(FreeCAD.Vector(-99.230339,36.960674,0),FreeCAD.Vector(69.432587,36.960674,0)))
# self.Box.addGeometry(Part.LineSegment(FreeCAD.Vector(69.432587,36.960674,0),FreeCAD.Vector(69.432587,-53.196629,0)))
# self.Box.addGeometry(Part.LineSegment(FreeCAD.Vector(69.432587,-53.196629,0),FreeCAD.Vector(-99.230339,-53.196629,0)))
# self.Box.addGeometry(Part.LineSegment(FreeCAD.Vector(-99.230339,-53.196629,0),FreeCAD.Vector(-99.230339,36.960674,0)))
#
# def tearDown(self):
# #closing doc
Expand Down Expand Up @@ -101,5 +102,207 @@ def testOpenDialog(self):
else:
print ("No Section Cutting panel found")



class RuledSurfaceTestCases(unittest.TestCase):
def setUp(self):
self.Doc = FreeCAD.newDocument("RuledSurfaceTest")

def testXYPlaneRSCreate(self):
self.RuledSurfaceSketch = self.Doc.addObject('Sketcher::SketchObject', 'SketchXY')
self.RuledSurfaceSketch.Placement = FreeCAD.Placement(FreeCAD.Vector(0.000000, 0.000000, 0.000000), FreeCAD.Rotation(0.000000, 0.000000, 0.000000, 1.000000))
self.RuledSurfaceSketch.MapMode = "Deactivated"
geoList = []
geoList.append(Part.ArcOfCircle(Part.Circle(FreeCAD.Vector(-46.406574, 4.004109, 0), FreeCAD.Vector(0, 0, 1), 28.798770), 1.570796, 4.712389))
geoList.append(Part.ArcOfCircle(Part.Circle(FreeCAD.Vector(68.788506, 4.004109 ,0), FreeCAD.Vector(0, 0, 1), 28.798770), 4.712389, 7.853982))
geoList.append(Part.LineSegment(FreeCAD.Vector(-46.406574, -24.794661, 0), FreeCAD.Vector(68.788506, -24.794661, 0)))
geoList.append(Part.LineSegment(FreeCAD.Vector(68.788506, 32.802879, 0), FreeCAD.Vector(-46.406574, 32.802879, 0)))
self.RuledSurfaceSketch.addGeometry(geoList, False)
conList = []
conList.append(Sketcher.Constraint('Tangent', 0, 2, 2, 1))
conList.append(Sketcher.Constraint('Tangent', 2, 2, 1, 1))
conList.append(Sketcher.Constraint('Tangent', 1, 2, 3, 1))
conList.append(Sketcher.Constraint('Tangent', 3, 2, 0, 1))
conList.append(Sketcher.Constraint('Equal', 0, 1))
self.RuledSurfaceSketch.addConstraint(conList)
del geoList, conList

self.RuledSurfaceSketch.addConstraint(Sketcher.Constraint('Horizontal',3))

self.RuledSurfaceSketch.addConstraint(Sketcher.Constraint('Radius',1,28.798770))
self.RuledSurfaceSketch.setDatum(6,FreeCAD.Units.Quantity('30.000000 mm'))
self.RuledSurfaceSketch.addConstraint(Sketcher.Constraint('DistanceX',2,1,2,2,115.195072))
self.RuledSurfaceSketch.setDatum(7,FreeCAD.Units.Quantity('100.000000 mm'))
self.RuledSurfaceSketch.addConstraint(Sketcher.Constraint('PointOnObject',0,3,-1))
self.Doc.recompute()

self.RuledSurfaceSketch.delConstraint(5)
self.RuledSurfaceSketch.addConstraint(Sketcher.Constraint('Symmetric',0,3,1,3,-2))
self.Doc.recompute()

self.RuledSurface = self.Doc.addObject('Part::RuledSurface', 'Ruled SurfaceXY')
self.RuledSurface.Curve1=(self.RuledSurfaceSketch,u'Edge1')
self.RuledSurface.Curve2=(self.RuledSurfaceSketch,u'Edge3')
self.Doc.recompute()

self.assertAlmostEqual(self.RuledSurface.Shape.BoundBox.XMin, -80)
self.assertAlmostEqual(self.RuledSurface.Shape.BoundBox.YMin, -30)
self.assertAlmostEqual(self.RuledSurface.Shape.BoundBox.ZMin, 0)
self.assertAlmostEqual(self.RuledSurface.Shape.BoundBox.XMax, 80)
self.assertAlmostEqual(self.RuledSurface.Shape.BoundBox.YMax, 30)
self.assertAlmostEqual(self.RuledSurface.Shape.BoundBox.ZMax, 0)

self.assertAlmostEqual(self.RuledSurface.Shape.Area, 8827.433388208741)

FreeCADGui.SendMsgToActiveView("ViewFit")


def testXZPlaneRSCreate(self):
self.RuledSurfaceSketch = self.Doc.addObject('Sketcher::SketchObject', 'SketchXZ')
self.RuledSurfaceSketch.Placement = FreeCAD.Placement(FreeCAD.Vector(0.000000, 0.000000, 0.000000), FreeCAD.Rotation(FreeCAD.Vector(0.58,0.58,0.58),120))
self.RuledSurfaceSketch.MapMode = "Deactivated"
geoList = []
geoList.append(Part.ArcOfCircle(Part.Circle(FreeCAD.Vector(-46.406574, 4.004109, 0), FreeCAD.Vector(0, 0, 1), 28.798770), 1.570796, 4.712389))
geoList.append(Part.ArcOfCircle(Part.Circle(FreeCAD.Vector(68.788506, 4.004109 ,0), FreeCAD.Vector(0, 0, 1), 28.798770), 4.712389, 7.853982))
geoList.append(Part.LineSegment(FreeCAD.Vector(-46.406574, -24.794661, 0), FreeCAD.Vector(68.788506, -24.794661, 0)))
geoList.append(Part.LineSegment(FreeCAD.Vector(68.788506, 32.802879, 0), FreeCAD.Vector(-46.406574, 32.802879, 0)))
self.RuledSurfaceSketch.addGeometry(geoList, False)
conList = []
conList.append(Sketcher.Constraint('Tangent', 0, 2, 2, 1))
conList.append(Sketcher.Constraint('Tangent', 2, 2, 1, 1))
conList.append(Sketcher.Constraint('Tangent', 1, 2, 3, 1))
conList.append(Sketcher.Constraint('Tangent', 3, 2, 0, 1))
conList.append(Sketcher.Constraint('Equal', 0, 1))
self.RuledSurfaceSketch.addConstraint(conList)
del geoList, conList

self.RuledSurfaceSketch.addConstraint(Sketcher.Constraint('Horizontal',3))

self.RuledSurfaceSketch.addConstraint(Sketcher.Constraint('Radius',1,28.798770))
self.RuledSurfaceSketch.setDatum(6,FreeCAD.Units.Quantity('30.000000 mm'))
self.RuledSurfaceSketch.addConstraint(Sketcher.Constraint('DistanceX',2,1,2,2,115.195072))
self.RuledSurfaceSketch.setDatum(7,FreeCAD.Units.Quantity('100.000000 mm'))
self.RuledSurfaceSketch.addConstraint(Sketcher.Constraint('PointOnObject',0,3,-1))
self.Doc.recompute()

self.RuledSurfaceSketch.delConstraint(5)
self.RuledSurfaceSketch.addConstraint(Sketcher.Constraint('Symmetric',0,3,1,3,-2))
self.Doc.recompute()

self.RuledSurface = self.Doc.addObject('Part::RuledSurface', 'Ruled SurfaceXZ')
self.RuledSurface.Curve1=(self.RuledSurfaceSketch,u'Edge1')
self.RuledSurface.Curve2=(self.RuledSurfaceSketch,u'Edge3')
self.Doc.recompute()

self.assertAlmostEqual(self.RuledSurface.Shape.BoundBox.XMin, 0)
self.assertAlmostEqual(self.RuledSurface.Shape.BoundBox.YMin, -83.6097)
self.assertAlmostEqual(self.RuledSurface.Shape.BoundBox.ZMin, -30)
self.assertAlmostEqual(self.RuledSurface.Shape.BoundBox.XMax, 0)
self.assertAlmostEqual(self.RuledSurface.Shape.BoundBox.YMax, 83.6097)
self.assertAlmostEqual(self.RuledSurface.Shape.BoundBox.ZMax, 30)

self.assertAlmostEqual(self.RuledSurface.Shape.Area, 8827.433388208741)

FreeCADGui.SendMsgToActiveView("ViewFit")

def testYZPlaneRSCreate(self):
self.RuledSurfaceSketch = self.Doc.addObject('Sketcher::SketchObject', 'SketchYZ')
self.RuledSurfaceSketch.Placement = FreeCAD.Placement(FreeCAD.Vector(0.000000, 0.000000, 0.000000), FreeCAD.Rotation(FreeCAD.Vector(1.0,0,0),90))
self.RuledSurfaceSketch.MapMode = "Deactivated"
geoList = []
geoList.append(Part.ArcOfCircle(Part.Circle(FreeCAD.Vector(-46.406574, 4.004109, 0), FreeCAD.Vector(0, 0, 1), 28.798770), 1.570796, 4.712389))
geoList.append(Part.ArcOfCircle(Part.Circle(FreeCAD.Vector(68.788506, 4.004109 ,0), FreeCAD.Vector(0, 0, 1), 28.798770), 4.712389, 7.853982))
geoList.append(Part.LineSegment(FreeCAD.Vector(-46.406574, -24.794661, 0), FreeCAD.Vector(68.788506, -24.794661, 0)))
geoList.append(Part.LineSegment(FreeCAD.Vector(68.788506, 32.802879, 0), FreeCAD.Vector(-46.406574, 32.802879, 0)))
self.RuledSurfaceSketch.addGeometry(geoList, False)
conList = []
conList.append(Sketcher.Constraint('Tangent', 0, 2, 2, 1))
conList.append(Sketcher.Constraint('Tangent', 2, 2, 1, 1))
conList.append(Sketcher.Constraint('Tangent', 1, 2, 3, 1))
conList.append(Sketcher.Constraint('Tangent', 3, 2, 0, 1))
conList.append(Sketcher.Constraint('Equal', 0, 1))
self.RuledSurfaceSketch.addConstraint(conList)
del geoList, conList

self.RuledSurfaceSketch.addConstraint(Sketcher.Constraint('Horizontal',3))

self.RuledSurfaceSketch.addConstraint(Sketcher.Constraint('Radius',1,28.798770))
self.RuledSurfaceSketch.setDatum(6,FreeCAD.Units.Quantity('30.000000 mm'))
self.RuledSurfaceSketch.addConstraint(Sketcher.Constraint('DistanceX',2,1,2,2,115.195072))
self.RuledSurfaceSketch.setDatum(7,FreeCAD.Units.Quantity('100.000000 mm'))
self.RuledSurfaceSketch.addConstraint(Sketcher.Constraint('PointOnObject',0,3,-1))
self.Doc.recompute()

self.RuledSurfaceSketch.delConstraint(5)
self.RuledSurfaceSketch.addConstraint(Sketcher.Constraint('Symmetric',0,3,1,3,-2))
self.Doc.recompute()

self.RuledSurface = self.Doc.addObject('Part::RuledSurface', 'Ruled SurfaceYZ')
self.RuledSurface.Curve1=(self.RuledSurfaceSketch,u'Edge1')
self.RuledSurface.Curve2=(self.RuledSurfaceSketch,u'Edge3')
self.Doc.recompute()

self.assertAlmostEqual(self.RuledSurface.Shape.BoundBox.XMin, 0)
self.assertAlmostEqual(self.RuledSurface.Shape.BoundBox.YMin, -83.6097)
self.assertAlmostEqual(self.RuledSurface.Shape.BoundBox.ZMin, -30)
self.assertAlmostEqual(self.RuledSurface.Shape.BoundBox.XMax, 0)
self.assertAlmostEqual(self.RuledSurface.Shape.BoundBox.YMax, 83.6097)
self.assertAlmostEqual(self.RuledSurface.Shape.BoundBox.ZMax, 30)

self.assertAlmostEqual(self.RuledSurface.Shape.Area, 8827.433388208741)

FreeCADGui.SendMsgToActiveView("ViewFit")


def testSpecialPlaneRSCreate(self):
self.RuledSurfaceSketch = self.Doc.addObject('Sketcher::SketchObject', 'SketchSpecial')
self.RuledSurfaceSketch.Placement = FreeCAD.Placement(FreeCAD.Vector(3.595176185196667,0,1.753484587156312),FreeCAD.Rotation(FreeCAD.Vector(0.3361383527176155,0.6488071227438279,0.6826861103824818),310))
self.RuledSurfaceSketch.MapMode = "Deactivated"
geoList = []
geoList.append(Part.ArcOfCircle(Part.Circle(FreeCAD.Vector(-46.406574, 4.004109, 0), FreeCAD.Vector(0, 0, 1), 28.798770), 1.570796, 4.712389))
geoList.append(Part.ArcOfCircle(Part.Circle(FreeCAD.Vector(68.788506, 4.004109 ,0), FreeCAD.Vector(0, 0, 1), 28.798770), 4.712389, 7.853982))
geoList.append(Part.LineSegment(FreeCAD.Vector(-46.406574, -24.794661, 0), FreeCAD.Vector(68.788506, -24.794661, 0)))
geoList.append(Part.LineSegment(FreeCAD.Vector(68.788506, 32.802879, 0), FreeCAD.Vector(-46.406574, 32.802879, 0)))
self.RuledSurfaceSketch.addGeometry(geoList, False)
conList = []
conList.append(Sketcher.Constraint('Tangent', 0, 2, 2, 1))
conList.append(Sketcher.Constraint('Tangent', 2, 2, 1, 1))
conList.append(Sketcher.Constraint('Tangent', 1, 2, 3, 1))
conList.append(Sketcher.Constraint('Tangent', 3, 2, 0, 1))
conList.append(Sketcher.Constraint('Equal', 0, 1))
self.RuledSurfaceSketch.addConstraint(conList)
del geoList, conList

self.RuledSurfaceSketch.addConstraint(Sketcher.Constraint('Horizontal',3))

self.RuledSurfaceSketch.addConstraint(Sketcher.Constraint('Radius',1,28.798770))
self.RuledSurfaceSketch.setDatum(6,FreeCAD.Units.Quantity('30.000000 mm'))
self.RuledSurfaceSketch.addConstraint(Sketcher.Constraint('DistanceX',2,1,2,2,115.195072))
self.RuledSurfaceSketch.setDatum(7,FreeCAD.Units.Quantity('100.000000 mm'))
self.RuledSurfaceSketch.addConstraint(Sketcher.Constraint('PointOnObject',0,3,-1))
self.Doc.recompute()

self.RuledSurfaceSketch.delConstraint(5)
self.RuledSurfaceSketch.addConstraint(Sketcher.Constraint('Symmetric',0,3,1,3,-2))
self.Doc.recompute()

self.RuledSurface = self.Doc.addObject('Part::RuledSurface', 'Ruled SurfaceSpecial')
self.RuledSurface.Curve1=(self.RuledSurfaceSketch,u'Edge1')
self.RuledSurface.Curve2=(self.RuledSurfaceSketch,u'Edge3')
self.Doc.recompute()

self.assertAlmostEqual(self.RuledSurface.Shape.BoundBox.XMin, -83.6097)
self.assertAlmostEqual(self.RuledSurface.Shape.BoundBox.YMin, -6.66134e-15)
self.assertAlmostEqual(self.RuledSurface.Shape.BoundBox.ZMin, -30)
self.assertAlmostEqual(self.RuledSurface.Shape.BoundBox.XMax, 83.6097)
self.assertAlmostEqual(self.RuledSurface.Shape.BoundBox.YMax, 6.66134e-15)
self.assertAlmostEqual(self.RuledSurface.Shape.BoundBox.ZMax, 30)

self.assertAlmostEqual(self.RuledSurface.Shape.Area, 8827.433388208741)

FreeCADGui.SendMsgToActiveView("ViewFit")


def tearDown(self):
FreeCAD.closeDocument("SectionCut")
print("No teardown yet")
# FreeCAD.closeDocument("RuledSurfaceTest")

0 comments on commit 4965738

Please sign in to comment.