Sketch: Fix TestSketchValidateCoincidents
This commit is contained in:
@@ -1,55 +1,69 @@
|
||||
# **************************************************************************
|
||||
# Copyright (c) 2024 Syres *
|
||||
# Copyright (c) 2024 Syres *
|
||||
# *
|
||||
# This file is part of the FreeCAD CAx development system. *
|
||||
# *
|
||||
# This program is free software; you can redistribute it and/or modify *
|
||||
# it under the terms of the GNU Lesser General Public License (LGPL) *
|
||||
# as published by the Free Software Foundation; either version 2 of *
|
||||
# the License, or (at your option) any later version. *
|
||||
# for detail see the LICENCE text file. *
|
||||
# FreeCAD is free software: you can redistribute it and/or modify it *
|
||||
# under the terms of the GNU Lesser General Public License as *
|
||||
# published by the Free Software Foundation, either version 2.1 of the *
|
||||
# License, or (at your option) any later version. *
|
||||
# *
|
||||
# FreeCAD is distributed in the hope that it will be useful, *
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
# GNU Library General Public License for more details. *
|
||||
# FreeCAD is distributed in the hope that it will be useful, but *
|
||||
# WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
|
||||
# Lesser General Public License for more details. *
|
||||
# *
|
||||
# You should have received a copy of the GNU Library General Public *
|
||||
# License along with FreeCAD; if not, write to the Free Software *
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
|
||||
# USA *
|
||||
# You should have received a copy of the GNU Lesser General Public *
|
||||
# License along with FreeCAD. If not, see *
|
||||
# <https://www.gnu.org/licenses/>. *
|
||||
# **************************************************************************
|
||||
|
||||
import FreeCAD, os, sys, unittest, Part, Sketcher
|
||||
import unittest
|
||||
import FreeCAD
|
||||
import Part
|
||||
import Sketcher
|
||||
from FreeCAD import Vector
|
||||
|
||||
App = FreeCAD
|
||||
|
||||
|
||||
class TestSketchValidateCoincidents(unittest.TestCase):
|
||||
"""Sketch validation test"""
|
||||
|
||||
def setUp(self):
|
||||
self.Doc = FreeCAD.newDocument("SketchValidateCoincidentsTest")
|
||||
|
||||
def testSingleMissingCoincidentCase(self):
|
||||
self.Sketch = self.Doc.addObject('Sketcher::SketchObject', 'Sketch')
|
||||
geo0 = self.Sketch.addGeometry(Part.LineSegment(Vector (-47.680691, 18.824165000000004, 0.0), Vector (-47.680691, -27.346279, 0.0)))
|
||||
geo1 = self.Sketch.addGeometry(Part.LineSegment(Vector (-47.680691, -27.346279, 0.0), Vector (51.132679, -27.346279, 0.0)))
|
||||
geo2 = self.Sketch.addGeometry(Part.LineSegment(Vector (51.132679, -27.346279, 0.0), Vector (51.132679, 18.824165000000004, 0.0)))
|
||||
geo3 = self.Sketch.addGeometry(Part.LineSegment(Vector (51.132679, 18.824165, 0.0), Vector (-47.680691, 18.824165, 0.0)))
|
||||
self.Sketch.addConstraint(Sketcher.Constraint('Coincident', geo0, 2, geo1, 1))
|
||||
self.Sketch.addConstraint(Sketcher.Constraint('Coincident', geo1, 2, geo2, 1))
|
||||
self.Sketch.addConstraint(Sketcher.Constraint('Vertical', geo0))
|
||||
self.Sketch.addConstraint(Sketcher.Constraint('Vertical', geo2))
|
||||
self.Sketch.addConstraint(Sketcher.Constraint('Horizontal', geo1))
|
||||
self.Sketch.addConstraint(Sketcher.Constraint('Coincident', geo3, 1, geo2, 2))
|
||||
self.Sketch.addConstraint(Sketcher.Constraint('Horizontal', geo3))
|
||||
self.Sketch.ViewObject.DiffuseColor = [(0.44, 0.91, 1.00, 0.00)]
|
||||
sketch = self.Doc.addObject("Sketcher::SketchObject", "Sketch")
|
||||
v0 = Vector(-47.680691, 18.824165000000004, 0.0)
|
||||
v1 = Vector(-47.680691, -27.346279, 0.0)
|
||||
v2 = Vector(51.132679, -27.346279, 0.0)
|
||||
v3 = Vector(51.132679, 18.824165000000004, 0.0)
|
||||
v4 = Vector(51.132679, 18.824165, 0.0)
|
||||
v5 = Vector(-47.680691, 18.824165, 0.0)
|
||||
|
||||
geo0 = sketch.addGeometry(Part.LineSegment(v0, v1))
|
||||
geo1 = sketch.addGeometry(Part.LineSegment(v1, v2))
|
||||
geo2 = sketch.addGeometry(Part.LineSegment(v2, v3))
|
||||
geo3 = sketch.addGeometry(Part.LineSegment(v4, v5))
|
||||
|
||||
sketch.addConstraint(Sketcher.Constraint("Coincident", geo0, 2, geo1, 1))
|
||||
sketch.addConstraint(Sketcher.Constraint("Coincident", geo1, 2, geo2, 1))
|
||||
sketch.addConstraint(Sketcher.Constraint("Vertical", geo0))
|
||||
sketch.addConstraint(Sketcher.Constraint("Vertical", geo2))
|
||||
sketch.addConstraint(Sketcher.Constraint("Horizontal", geo1))
|
||||
sketch.addConstraint(Sketcher.Constraint("Coincident", geo3, 1, geo2, 2))
|
||||
sketch.addConstraint(Sketcher.Constraint("Horizontal", geo3))
|
||||
self.Doc.recompute()
|
||||
self.assertTrue(self.Sketch.ConstraintCount == 7)
|
||||
self.Sketch.makeMissingPointOnPointCoincident()
|
||||
self.assertEqual(sketch.ConstraintCount, 7)
|
||||
sketch.detectMissingPointOnPointConstraints()
|
||||
sketch.makeMissingPointOnPointCoincident()
|
||||
self.Doc.recompute()
|
||||
self.assertTrue(self.Sketch.ConstraintCount == 8)
|
||||
self.assertEqual(sketch.ConstraintCount, 8)
|
||||
del v0, v1, v2, v3, v4, v5
|
||||
del geo0, geo1, geo2, geo3
|
||||
del sketch
|
||||
|
||||
def tearDown(self):
|
||||
# closing doc
|
||||
FreeCAD.closeDocument(self.Doc.Name)
|
||||
# print ("omit closing document for debugging")
|
||||
|
||||
Reference in New Issue
Block a user