#*************************************************************************** #* Copyright (c) 2013 Yorik van Havre * #* * #* 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 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. * #* * #* 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 * #* * #***************************************************************************/ # Unit test for the Arch module import os import unittest import FreeCAD as App from FreeCAD import Units import Arch import Draft import Part import Sketcher import TechDraw import WorkingPlane from draftutils.messages import _msg if App.GuiUp: import FreeCADGui class ArchTest(unittest.TestCase): def setUp(self): # setting a new document to hold the tests if App.ActiveDocument: if App.ActiveDocument.Name != "ArchTest": App.newDocument("ArchTest") else: App.newDocument("ArchTest") App.setActiveDocument("ArchTest") def testRebar(self): App.Console.PrintLog ('Checking Arch Rebar...\n') s = Arch.makeStructure(length=2,width=3,height=5) sk = App.ActiveDocument.addObject('Sketcher::SketchObject','Sketch') sk.AttachmentSupport = (s,["Face6"]) sk.addGeometry(Part.LineSegment(App.Vector(-0.85,1.25,0),App.Vector(0.75,1.25,0))) sk.addGeometry(Part.LineSegment(App.Vector(0.75,1.25,0),App.Vector(0.75,-1.20,0))) sk.addGeometry(Part.LineSegment(App.Vector(0.75,-1.20,0),App.Vector(-0.85,-1.20,0))) sk.addGeometry(Part.LineSegment(App.Vector(-0.85,-1.20,0),App.Vector(-0.85,1.25,0))) sk.addConstraint(Sketcher.Constraint('Coincident',0,2,1,1)) sk.addConstraint(Sketcher.Constraint('Coincident',1,2,2,1)) sk.addConstraint(Sketcher.Constraint('Coincident',2,2,3,1)) sk.addConstraint(Sketcher.Constraint('Coincident',3,2,0,1)) r = Arch.makeRebar(s,sk,diameter=.1,amount=2) self.assertTrue(r,"Arch Rebar failed") def testBuildingPart(self): """Create a BuildingPart from a wall with a window and check its shape. """ # Also regression test for: # https://github.com/FreeCAD/FreeCAD/issues/6178 operation = "Arch BuildingPart" _msg(" Test '{}'".format(operation)) # Most of the code below taken from testWindow function. line = Draft.makeLine(App.Vector(0, 0, 0), App.Vector(3000, 0, 0)) wall = Arch.makeWall(line) sk = App.ActiveDocument.addObject("Sketcher::SketchObject", "Sketch001") sk.Placement.Rotation = App.Rotation(App.Vector(1, 0, 0), 90) sk.addGeometry(Part.LineSegment(App.Vector( 500, 800, 0), App.Vector(1500, 800, 0))) sk.addGeometry(Part.LineSegment(App.Vector(1500, 800, 0), App.Vector(1500, 2000, 0))) sk.addGeometry(Part.LineSegment(App.Vector(1500, 2000, 0), App.Vector( 500, 2000, 0))) sk.addGeometry(Part.LineSegment(App.Vector( 500, 2000, 0), App.Vector( 500, 800, 0))) sk.addConstraint(Sketcher.Constraint('Coincident', 0, 2, 1, 1)) sk.addConstraint(Sketcher.Constraint('Coincident', 1, 2, 2, 1)) sk.addConstraint(Sketcher.Constraint('Coincident', 2, 2, 3, 1)) sk.addConstraint(Sketcher.Constraint('Coincident', 3, 2, 0, 1)) App.ActiveDocument.recompute() win = Arch.makeWindow(sk) Arch.removeComponents(win, host=wall) App.ActiveDocument.recompute() bp = Arch.makeBuildingPart() # Wall visibility works when standalone FreeCADGui.Selection.clearSelection() FreeCADGui.Selection.addSelection('ArchTest',wall.Name) assert wall.Visibility FreeCADGui.runCommand('Std_ToggleVisibility',0) App.ActiveDocument.recompute() assert not wall.Visibility FreeCADGui.runCommand('Std_ToggleVisibility',0) assert wall.Visibility bp.Group = [wall] App.ActiveDocument.recompute() # Fails with OCC 7.5 # self.assertTrue(len(bp.Shape.Faces) == 16, "'{}' failed".format(operation)) # Wall visibility works when inside a BuildingPart FreeCADGui.runCommand('Std_ToggleVisibility',0) App.ActiveDocument.recompute() assert not wall.Visibility FreeCADGui.runCommand('Std_ToggleVisibility',0) assert wall.Visibility # Wall visibility works when BuildingPart Toggled FreeCADGui.Selection.clearSelection() FreeCADGui.Selection.addSelection('ArchTest',bp.Name) FreeCADGui.runCommand('Std_ToggleVisibility',0) assert not wall.Visibility FreeCADGui.runCommand('Std_ToggleVisibility',0) assert wall.Visibility # Wall visibiity works inside group inside BuildingPart Toggled grp = App.ActiveDocument.addObject("App::DocumentObjectGroup","Group") grp.Label="Group" grp.Group = [wall] bp.Group = [grp] App.ActiveDocument.recompute() assert wall.Visibility FreeCADGui.runCommand('Std_ToggleVisibility',0) App.ActiveDocument.recompute() assert not wall.Visibility FreeCADGui.runCommand('Std_ToggleVisibility',0) App.ActiveDocument.recompute() assert wall.Visibility def testImportSH3D(self): """Import a SweetHome 3D file """ operation = "importers.importSH3D" _msg(" Test '{}'".format(operation)) import BIM.importers.importSH3DHelper importer = BIM.importers.importSH3DHelper.SH3DImporter(None) importer.import_sh3d_from_string(SH3D_HOME) assert App.ActiveDocument.Site assert App.ActiveDocument.BuildingPart.Label == "Building" assert App.ActiveDocument.BuildingPart001.Label == "Level" assert App.ActiveDocument.Wall def tearDown(self): App.closeDocument("ArchTest") pass SH3D_HOME = """ """