diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs index 70005ef..bfc6156 100755 --- a/.settings/org.eclipse.core.resources.prefs +++ b/.settings/org.eclipse.core.resources.prefs @@ -28,6 +28,7 @@ encoding//test/test_json_part_box.py=utf-8 encoding//test/test_json_part_cone.py=utf-8 encoding//test/test_json_part_cylinder.py=utf-8 encoding//test/test_json_part_factory.py=utf-8 +encoding//test/test_json_part_geometry.py=utf-8 encoding//test/test_json_part_sheet.py=utf-8 encoding//test/test_json_part_sphere.py=utf-8 encoding//test/test_setup.py=utf-8 diff --git a/InitGui.py b/InitGui.py index 4947e45..ff4ccea 100755 --- a/InitGui.py +++ b/InitGui.py @@ -24,7 +24,6 @@ # SPDX-License-Identifier: LGPL-3.0-or-later # - class VirtualSatelliteWorkbench(Workbench): # NOQA @UndefinedVariable ''' This class initializes the Virtual Satellite Workbench in FreeCAD. diff --git a/json_io/parts/json_part.py b/json_io/parts/json_part.py index 841428a..9cce860 100644 --- a/json_io/parts/json_part.py +++ b/json_io/parts/json_part.py @@ -44,9 +44,9 @@ class AJsonPart(): "name": "-", "shape": "-", "uuid": "-", - "length_x": "mm", - "length_y": "mm", - "length_z": "mm", + "length": "mm", + "width": "mm", + "height": "mm", "radius": "mm", "color": "rgba" } @@ -56,13 +56,11 @@ def parse_from_json(self, json_object): self.shape = str(json_object[JSON_ELEMENT_SHAPE]) self.uuid = str(json_object[JSON_ELEMENT_UUID]).replace("-", "_") - # The axis between Virtual Satellite and FreeCAD are not identical - # Therefore Y and Z gets swpapped here. We also convert m to mm - # by definition the values in this part object represent the values - # as used in FreeCAD - self.length_x = float(json_object[JSON_ELEMENT_LENGTH_X]) * M_TO_MM - self.length_y = float(json_object[JSON_ELEMENT_LENGTH_Z]) * M_TO_MM - self.length_z = float(json_object[JSON_ELEMENT_LENGTH_Y]) * M_TO_MM + # the coordinate system between virtual satellite and FreeCAD seem + # to be identical. no Further adjustments or transformations needed. + self.length = float(json_object[JSON_ELEMENT_LENGTH_X]) * M_TO_MM + self.width = float(json_object[JSON_ELEMENT_LENGTH_Y]) * M_TO_MM + self.height = float(json_object[JSON_ELEMENT_LENGTH_Z]) * M_TO_MM self.radius = float(json_object[JSON_ELEMENT_RADIUS]) * M_TO_MM diff --git a/json_io/parts/json_part_box.py b/json_io/parts/json_part_box.py index b88ac5d..3741ae3 100644 --- a/json_io/parts/json_part_box.py +++ b/json_io/parts/json_part_box.py @@ -35,9 +35,9 @@ def _set_freecad_properties(self, active_document): object_name_and_type = self.get_shape_type() box = active_document.app_active_document.getObject(object_name_and_type) - box.Length = self.length_x - box.Height = self.length_y - box.Width = self.length_z + box.Length = self.length + box.Height = self.height + box.Width = self.width # now center the box as in virtual satellite @@ -47,7 +47,7 @@ def _set_freecad_properties(self, active_document): # hence: # 1. turn it by 90° on the x axis # 2. move it forward by half its size on the y axis - vector_translation = active_document.app.Vector(-self.length_x/2, -self.length_z/2, -self.length_y/2) + vector_translation = active_document.app.Vector(-self.length/2, -self.width/2, -self.height/2) vector_rotation = active_document.app.Rotation(VECTOR_X, 0) placement = active_document.app.Placement( diff --git a/json_io/parts/json_part_cone.py b/json_io/parts/json_part_cone.py index 4d61721..2b39d28 100644 --- a/json_io/parts/json_part_cone.py +++ b/json_io/parts/json_part_cone.py @@ -37,7 +37,7 @@ def _set_freecad_properties(self, active_document): cone.Radius1 = 0 cone.Radius2 = self.radius - cone.Height = self.length_z + cone.Height = self.width # Now virtual satellite axis correction # 1. the cone is aligned on the y axis @@ -45,7 +45,7 @@ def _set_freecad_properties(self, active_document): # hence: # 1. turn it by 90° on the x axis # 2. move it forward by half its size on the y axis - vector_translation = active_document.app.Vector(0, self.length_z/2, 0) + vector_translation = active_document.app.Vector(0, self.width/2, 0) vector_rotation = active_document.app.Rotation(VECTOR_X, 90) placement = active_document.app.Placement( diff --git a/json_io/parts/json_part_cylinder.py b/json_io/parts/json_part_cylinder.py index eacbcdc..f632d46 100644 --- a/json_io/parts/json_part_cylinder.py +++ b/json_io/parts/json_part_cylinder.py @@ -36,7 +36,7 @@ def _set_freecad_properties(self, active_document): cone = active_document.app_active_document.getObject(object_name_and_type) cone.Radius = self.radius - cone.Height = self.length_z + cone.Height = self.width # Now virtual satellite axis correction # 1. the cone is aligned on the y axis @@ -44,7 +44,7 @@ def _set_freecad_properties(self, active_document): # hence: # 1. turn it by 90° on the x axis # 2. move it forward by half its size on the y axis - vector_translation = active_document.app.Vector(0, self.length_z/2, 0) + vector_translation = active_document.app.Vector(0, self.width/2, 0) vector_rotation = active_document.app.Rotation(VECTOR_X, 90) placement = active_document.app.Placement( diff --git a/test/test_json_part.py b/test/test_json_part.py index 892c23e..8f425c8 100644 --- a/test/test_json_part.py +++ b/test/test_json_part.py @@ -65,9 +65,9 @@ def test_parse(self): self.assertEqual(json_part.uuid, "6201a731_d703_43f8_ab37_6a0581dfe022", "Property is correctly set") self.assertEqual(json_part.shape, "BOX", "Property is correctly set") - self.assertEqual(json_part.length_x, 40, "Property is correctly set") - self.assertEqual(json_part.length_y, 300, "Property is correctly set and axes are swapped") - self.assertEqual(json_part.length_z, 10, "Property is correctly set and axes are swapped") + self.assertEqual(json_part.length, 40, "Property is correctly set") + self.assertEqual(json_part.width, 10, "Property is correctly set") + self.assertEqual(json_part.height, 300, "Property is correctly set") self.assertEqual(json_part.radius, 0, "Property is correctly set and") self.assertEqual(json_part.color, 12632256 << 8, "Property is correctly set") diff --git a/test/test_json_part_box.py b/test/test_json_part_box.py index 9ba81a5..aa2418f 100644 --- a/test/test_json_part_box.py +++ b/test/test_json_part_box.py @@ -52,8 +52,8 @@ def test_create_part_box(self): "shape": "BOX", "name": "Beam", "lengthX": 0.04, - "lengthY": 0.01, - "lengthZ": 0.3, + "lengthY": 0.02, + "lengthZ": 0.01, "radius": 0.0, "uuid": "6201a731-d703-43f8-ab37-6a0581dfe022" }""" @@ -68,9 +68,9 @@ def test_create_part_box(self): self.assertIsNotNone(App.ActiveDocument.getObject("Box"), "The Box object got created") # Check that there is a box with the correct properties - self.assertEquals(str(App.ActiveDocument.getObject("Box").Length), "40 mm", "Shape has correct size") - self.assertEquals(str(App.ActiveDocument.getObject("Box").Height), "300 mm", "Shape has correct size") - self.assertEquals(str(App.ActiveDocument.getObject("Box").Width), "10 mm", "Shape has correct size") + self.assertEquals(App.ActiveDocument.getObject("Box").Length, 40, "Shape has correct size") + self.assertEquals(App.ActiveDocument.getObject("Box").Width, 20, "Shape has correct size") + self.assertEquals(App.ActiveDocument.getObject("Box").Height, 10, "Shape has correct size") self.assertEquals(Gui.ActiveDocument.getObject("Box").ShapeColor, (0.7529411911964417, 0.7529411911964417, 0.7529411911964417, 0.0), diff --git a/test/test_json_part_sheet.py b/test/test_json_part_sheet.py index badd398..fb0470f 100644 --- a/test/test_json_part_sheet.py +++ b/test/test_json_part_sheet.py @@ -80,6 +80,6 @@ def test_read_sheet_attribute(self): json_part_sheet.write_to_freecad(active_document) - attribute = json_part_sheet.read_sheet_attribute(active_document, "length_z") + attribute = json_part_sheet.read_sheet_attribute(active_document, "height") - self.assertEquals(attribute, 10, "Got correct value") + self.assertEquals(attribute, 300, "Got correct value")