diff --git a/src/Mod/TechDraw/CMakeLists.txt b/src/Mod/TechDraw/CMakeLists.txt index 5551569069..47238635fb 100644 --- a/src/Mod/TechDraw/CMakeLists.txt +++ b/src/Mod/TechDraw/CMakeLists.txt @@ -142,7 +142,7 @@ endif(BUILD_GUI) SET(TDTest_SRCS TDTest/__init__.py TDTest/DrawHatchTest.py - TDTest/DProjGroupTest.py + TDTest/DrawProjectionGroupTest.py TDTest/DrawViewAnnotationTest.py TDTest/DrawViewImageTest.py TDTest/DrawViewSymbolTest.py diff --git a/src/Mod/TechDraw/TDTest/DProjGroupTest.py b/src/Mod/TechDraw/TDTest/DProjGroupTest.py deleted file mode 100644 index 24ac0ea9c2..0000000000 --- a/src/Mod/TechDraw/TDTest/DProjGroupTest.py +++ /dev/null @@ -1,109 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -# test script for TechDraw module -# creates a Box and a Sphere and makes a Fusions from them -# creates a page -# creates a Projection Group -# adds Front,Left,Top projections to the group -# a template in the source folder -from __future__ import print_function - -import FreeCAD -import os - - -def DProjGroupTest(): - path = os.path.dirname(os.path.abspath(__file__)) - print("TDGroup path: " + path) - templateFileSpec = path + "/TestTemplate.svg" - - FreeCAD.newDocument("TDGroup") - FreeCAD.setActiveDocument("TDGroup") - FreeCAD.ActiveDocument = FreeCAD.getDocument("TDGroup") - doc = FreeCAD.ActiveDocument - print("document created") - - # make Fusion feature - box = FreeCAD.ActiveDocument.addObject("Part::Box", "Box") - box.recompute() - print("box created") - sphere = FreeCAD.ActiveDocument.addObject("Part::Sphere", "Sphere") - sphere.recompute() - print("sphere created") - fusion = FreeCAD.ActiveDocument.addObject("Part::MultiFuse", "Fusion") - FreeCAD.ActiveDocument.Fusion.Shapes = [box, sphere] - fusion.recompute() - print("Fusion created") - - # make a page - print("making a page") - page = FreeCAD.ActiveDocument.addObject("TechDraw::DrawPage", "Page") - FreeCAD.ActiveDocument.addObject("TechDraw::DrawSVGTemplate", "Template") - FreeCAD.ActiveDocument.Template.Template = templateFileSpec - FreeCAD.ActiveDocument.Page.Template = FreeCAD.ActiveDocument.Template - # page.ViewObject.show() # for debugging. unit tests run in console mode - print("Page created") - - # make projection group - print("making a projection group") - doc.openTransaction("Create Proj Group") - groupName = "ProjGroup" - group = FreeCAD.ActiveDocument.addObject("TechDraw::DrawProjGroup", groupName) - page.addView(group) - print("Group created") - group.Source = [fusion] - - print("adding views") - group.addProjection("Front") # need an Anchor - print("added Front") - - # update group - anchorDir = FreeCAD.Vector(0.0, 0.0, 1.0) - anchorRot = FreeCAD.Vector(1.0, 0.0, 0.0) - group.Anchor.Direction = anchorDir - group.Anchor.RotationVector = anchorRot - print("Anchor values set") - group.Anchor.recompute() - doc.commitTransaction() - print("Front/Anchor recomputed") - - print("adding left") - group.addProjection("Left") - print("added Left") - group.addProjection("Top") - print("added Top") - group.addProjection("Right") - print("added Right") - group.addProjection("Rear") - print("added Rear") - group.addProjection("Bottom") - print("added Bottom") - - # remove a view from projection group - group.removeProjection("Left") - print("removed Left") - - # test getItemByLabel method - print("testing getItemByLabel") - label = "Top" - item = group.getItemByLabel(label) - print("Item Label: " + label + " Item Name: " + item.Name) - - print("recomputing document") - FreeCAD.ActiveDocument.recompute() - - for v in group.Views: - print("View: " + v.Label + " " + v.TypeId) - v.autoPosition() - - rc = False - if "Up-to-date" in group.State: - rc = True - - FreeCAD.closeDocument("TDGroup") - return rc - - -if __name__ == "__main__": - DProjGroupTest() diff --git a/src/Mod/TechDraw/TDTest/DrawProjectionGroupTest.py b/src/Mod/TechDraw/TDTest/DrawProjectionGroupTest.py new file mode 100644 index 0000000000..4779484a68 --- /dev/null +++ b/src/Mod/TechDraw/TDTest/DrawProjectionGroupTest.py @@ -0,0 +1,94 @@ +import FreeCAD +import unittest +from .TechDrawTestUtilities import createPageWithSVGTemplate + + +class DrawProjectionGroupTest(unittest.TestCase): + def setUp(self): + """Creates a box and sphere to make a fusions from them. + Then creates a page and projection group""" + FreeCAD.newDocument("TDGroup") + FreeCAD.setActiveDocument("TDGroup") + FreeCAD.ActiveDocument = FreeCAD.getDocument("TDGroup") + self.document = FreeCAD.ActiveDocument + print("document created") + + # make Fusion feature + box = FreeCAD.ActiveDocument.addObject("Part::Box", "Box") + box.recompute() + print("box created") + sphere = FreeCAD.ActiveDocument.addObject("Part::Sphere", "Sphere") + sphere.recompute() + print("sphere created") + self.fusion = FreeCAD.ActiveDocument.addObject("Part::MultiFuse", "Fusion") + FreeCAD.ActiveDocument.Fusion.Shapes = [box, sphere] + self.fusion.recompute() + print("Fusion created") + + # make a page + print("making a page") + self.page = createPageWithSVGTemplate() + print("Page created") + + def tearDown(self): + FreeCAD.closeDocument("TDGroup") + + def testMakeProjectionGroup(self): + """Tests if a projection group can be added to view1""" + # make projection group + print("making a projection group") + self.document.openTransaction("Create Proj Group") + groupName = "ProjGroup" + group = FreeCAD.ActiveDocument.addObject("TechDraw::DrawProjGroup", groupName) + self.page.addView(group) + print("Group created") + group.Source = [self.fusion] + + print("adding views") + group.addProjection("Front") # need an Anchor + print("added Front") + + # update group + anchorDir = FreeCAD.Vector(0.0, 0.0, 1.0) + anchorRot = FreeCAD.Vector(1.0, 0.0, 0.0) + group.Anchor.Direction = anchorDir + group.Anchor.RotationVector = anchorRot + print("Anchor values set") + group.Anchor.recompute() + self.document.commitTransaction() + print("Front/Anchor recomputed") + group.addProjection("Left") + print("added Left") + group.addProjection("Top") + print("added Top") + group.addProjection("Right") + print("added Right") + group.addProjection("Rear") + print("added Rear") + group.addProjection("Bottom") + print("added Bottom") + + # remove a view from projection group + group.removeProjection("Left") + print("removed Left") + + # test getItemByLabel method + print("testing getItemByLabel") + label = "Top" + item = group.getItemByLabel(label) + print("Item Label: " + label + " Item Name: " + item.Name) + + print("recomputing document") + FreeCAD.ActiveDocument.recompute() + + for v in group.Views: + print("View: " + v.Label + " " + v.TypeId) + v.autoPosition() + + group.recompute() + + self.assertTrue("Up-to-date" in group.State) + + +if __name__ == "__main__": + unittest.main() diff --git a/src/Mod/TechDraw/TestTechDrawApp.py b/src/Mod/TechDraw/TestTechDrawApp.py index f8b3b526ab..b4b277655c 100644 --- a/src/Mod/TechDraw/TestTechDrawApp.py +++ b/src/Mod/TechDraw/TestTechDrawApp.py @@ -20,8 +20,6 @@ # USA * # ************************************************************************** -import unittest - from TDTest.DrawHatchTest import DrawHatchTest # noqa: F401 from TDTest.DrawViewAnnotationTest import DrawViewAnnotationTest # noqa: F401 from TDTest.DrawViewBalloonTest import DrawViewBalloonTest # noqa: F401 @@ -30,18 +28,4 @@ from TDTest.DrawViewImageTest import DrawViewImageTest # noqa: F401 from TDTest.DrawViewSectionTest import DrawViewSectionTest # noqa: F401 from TDTest.DrawViewSymbolTest import DrawViewSymbolTest # noqa: F401 from TDTest.DrawViewPartTest import DrawViewPartTest # noqa: F401 -from TDTest.DProjGroupTest import DProjGroupTest - -# --------------------------------------------------------------------------- -# define the test cases to test the FreeCAD TechDraw module -# --------------------------------------------------------------------------- - - -class TechDrawTestCases(unittest.TestCase): - def testProjGroupCase(self): - print("starting TD DrawProjGroup test") - rc = DProjGroupTest() - if rc: - print("TD DrawProjGroup test passed") - else: - print("TD DrawProjGroup test failed") +from TDTest.DrawProjectionGroupTest import DrawProjectionGroupTest # noqa: F401