Skip to content

Commit

Permalink
Renamed part properties to fit to FreeCad convention - (Task #5)
Browse files Browse the repository at this point in the history
- Realized, that coordinate systems across FreeCAD and Virtual Satellite
are matching. No further conversions needed.

---
Task #5: Implement Import Functionality
  • Loading branch information
PhilMFischer committed Aug 15, 2019
1 parent 3247269 commit 9e8494f
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 29 deletions.
1 change: 1 addition & 0 deletions .settings/org.eclipse.core.resources.prefs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion InitGui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
18 changes: 8 additions & 10 deletions json_io/parts/json_part.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand All @@ -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

Expand Down
8 changes: 4 additions & 4 deletions json_io/parts/json_part_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions json_io/parts/json_part_cone.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ 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
# 2. the origin is in the center of it
# 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(
Expand Down
4 changes: 2 additions & 2 deletions json_io/parts/json_part_cylinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ 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
# 2. the origin is in the center of it
# 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(
Expand Down
6 changes: 3 additions & 3 deletions test/test_json_part.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
10 changes: 5 additions & 5 deletions test/test_json_part_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}"""
Expand All @@ -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),
Expand Down
4 changes: 2 additions & 2 deletions test/test_json_part_sheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

0 comments on commit 9e8494f

Please sign in to comment.