def test_create_part_geometry(self): json_data = TEST_JSON_PART_GEOMETRY active_document = ActiveDocument( self._WORKING_DIRECTORY).open_set_and_get_document("PartGeometry") json_object = json.loads(json_data) # get the current module path and get the directory for the test resource # place that path into the json object before executing the transformations stl_test_resource_path = Environment.get_test_resource_path( "Switch.stl") json_object[JSON_ELEMENT_STL_PATH] = stl_test_resource_path json_part = JsonPartGeometry() json_part.parse_from_json(json_object) json_part.write_to_freecad(active_document) active_document.save_as("PartGeometry") self.assertIsNotNone(App.ActiveDocument.getObject("Geometry"), "The Box object got created") # Check that the extra attribute for the STL files got written to the sheet sheet_stl_path = json_part.sheet.read_sheet_attribute( active_document, "stl_path") self.assertEqual(sheet_stl_path, stl_test_resource_path, "The path is perfectly written to the spreadsheet") # Check that there is a box with the correct properties self.assertEquals( Gui.ActiveDocument.getObject("Geometry").ShapeColor, (0.003921568859368563, 0.007843137718737125, 0.9098039269447327, 0.0), "Shape has correct color")
def test_create_part_sphere(self): json_data = TEST_JSON_PART_SPHERE active_document = ActiveDocument( self._WORKING_DIRECTORY).open_set_and_get_document("PartSphere") json_object = json.loads(json_data) json_part = JsonPartSphere() json_part.parse_from_json(json_object) json_part.write_to_freecad(active_document) active_document.save_as("PartSphere") self.assertIsNotNone(App.ActiveDocument.getObject("Sphere"), "The Sphere object got created") # Check that there is a box with the correct properties self.assertEquals( App.ActiveDocument.getObject("Sphere").Radius, 3, "Shape has correct size") self.assertEquals( Gui.ActiveDocument.getObject("Sphere").ShapeColor, (0.7529411911964417, 0.7529411911964417, 0.7529411911964417, 0.0), "Shape has correct color")
def test_create_part_product_subassembly_with_root_part(self): json_data = TEST_JSON_PRODUCT_WITH_CHILDREN_WITH_CHILD self.create_Test_Part() active_document = ActiveDocument( self._WORKING_DIRECTORY).open_set_and_get_document( "ProductSubassemblyRootPart") json_object = json.loads(json_data) subassembly = json_object[JSON_ELEMNT_CHILDREN][0] json_product = JsonProductAssembly().parse_from_json(subassembly) json_product.write_to_freecad(active_document) active_document.save_as("ProductSubassemblyRootPart") self.assertEquals(len(json_product.children), 1, "correct amount of children") self.assertEquals( len(active_document.app_active_document.RootObjects), 4, "Found correct amount of root objects 2 objects plus 2 sheets") product_part_name = json_product.get_unique_name() product_object = active_document.app_active_document.getObjectsByLabel( product_part_name)[0] self.assertIsNotNone(product_object, "Found an object under the given part name") product_child1_part_name = json_product.children[0].get_unique_name() product_object = active_document.app_active_document.getObjectsByLabel( product_child1_part_name)[0] self.assertIsNotNone(product_object, "Found an object under the given part name")
def test_create_part_product_assembly_and_subassembly_with_root_part_manual( self): json_data = TEST_JSON_PRODUCT_WITH_CHILDREN_WITH_CHILD self.create_Test_Part() json_object = json.loads(json_data) subassembly = json_object[JSON_ELEMNT_CHILDREN][0] active_document = ActiveDocument( self._WORKING_DIRECTORY).open_set_and_get_document( PRODUCT_IDENTIFIER + "BasePlateBottom2_e8794f3d_86ec_44c5_9618_8b7170c45484") json_product = JsonProductAssembly().parse_from_json(subassembly) json_product.write_to_freecad(active_document) active_document.save_as( PRODUCT_IDENTIFIER + "BasePlateBottom2_e8794f3d_86ec_44c5_9618_8b7170c45484") self.assertEquals( len(active_document.app_active_document.RootObjects), 4, "Found correct amount of root objects 2 objects plus 2 sheets") active_document = ActiveDocument( self._WORKING_DIRECTORY).open_set_and_get_document( "ProductAssemblyAndSubassemblyRootPart") json_product = JsonProductAssembly().parse_from_json(json_object) json_product.write_to_freecad(active_document) active_document.save_as("ProductAssemblyAndSubassemblyRootPart") self.assertEquals( len(active_document.app_active_document.RootObjects), 6, "Found correct amount of root objects 3 objects plus 3 sheets")
def test_create_part_product_assembly_with_root_part(self): self.create_Test_Part() active_document = ActiveDocument( self._WORKING_DIRECTORY).open_set_and_get_document( "ProductAssemblyRootPart") json_object = json.loads(self.json_data) json_product = JsonProductAssembly().parse_from_json(json_object) json_product.write_to_freecad(active_document) active_document.save_as("ProductAssemblyRootPart") # find the object by its label there should be three objects identifiable in the current export # the part in the product and two times the referenced parts in the children. self.assertEquals(len(json_product.children), 2, "correct amount of children") self.assertEquals( len(active_document.app_active_document.RootObjects), 6, "Found correct amount of root objects 3 objects plus 3 sheets") product_part_name = json_product.get_unique_name() product_object = active_document.app_active_document.getObjectsByLabel( product_part_name)[0] self.assertIsNotNone(product_object, "Found an object under the given part name") product_child1_part_name = json_product.children[0].get_unique_name() product_object = active_document.app_active_document.getObjectsByLabel( product_child1_part_name)[0] self.assertIsNotNone(product_object, "Found an object under the given part name") product_child2_part_name = json_product.children[1].get_unique_name() product_object = active_document.app_active_document.getObjectsByLabel( product_child2_part_name)[0] self.assertIsNotNone(product_object, "Found an object under the given part name")