Skip to content

Commit

Permalink
Add position and rotation propagation - (Task #5)
Browse files Browse the repository at this point in the history
Add a simple solution in json_product_child to propagate values from
parent to children and also test this behavior.

The current method results in children only having an absolute position
(and rotation) instead of a relative one to their parent. This should be
reconsidered with usability and the export functionality in mind.

---
Task #5: Implement Import Functionality
  • Loading branch information
JAmmermann-DLR committed Nov 25, 2019
1 parent 51af564 commit 205ea9c
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
4 changes: 3 additions & 1 deletion VirtualSatelliteCAD/json_io/products/json_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ def _set_freecad_position_and_rotation(self, active_document):

product_part = active_document.app_active_document.getObjectsByLabel(product_part_name)[0]

# TODO: check if the same bug as below applies
# TODO: Add testcases in test_product
# First translate than rotate around X, Y and Z
vector_translation = active_document.app.Vector(self.pos_x, self.pos_y, self.pos_z)
vector_rotation_zero = active_document.app.Rotation(VECTOR_ZERO, 0)
Expand Down Expand Up @@ -195,7 +197,7 @@ def is_part_reference(self):

return has_part_uuid and has_part_name

def hasEqualValues(self, other):
def has_equal_values(self, other):
"""
Compares values with another AJsonProduct
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class without implementation. Additionally this method starts parsing
self.children = []
for json_object_child in json_object_children:
json_product_child = JsonProductChild().parse_from_json(json_object_child)
json_product_child.propagate_pos_and_rot_from_parent(self)
self.children.append(json_product_child)

# Don't hand back an assembly if there are no children
Expand Down
23 changes: 23 additions & 0 deletions VirtualSatelliteCAD/json_io/products/json_product_child.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def parse_from_json(self, json_object):
for json_object_child in json_object_children:

json_product_child = JsonProductChild().parse_from_json(json_object_child)
json_product_child.propagate_pos_and_rot_from_parent(self)
self.children.append(json_product_child)

return self
Expand All @@ -70,3 +71,25 @@ def write_to_freecad(self, active_document):
if self.has_children:
for child in self.children:
child.write_to_freecad(active_document)

def propagate_pos_and_rot_from_parent(self, parent):
"""
TODO:
This function propagates position and rotation parameters from the parent:
Doing this the pos and rot of an object become absolute not relative, which could result
in overhead when parsing back.
The question occurs how we handle this problems:
- Does a product hold its relative and absolute position?
- if yes how do we keep them in sync
- ideal would be to only show relative positions to the FreeCAD user and compute them
to absolute positions internally
- is that possible with freecad? it seems to only accept absolute positions and no inheritance
- constraints???
"""
self.pos_x += parent.pos_x
self.pos_y += parent.pos_y
self.pos_z += parent.pos_z

self.rot_x += parent.rot_x
self.rot_y += parent.rot_y
self.rot_z += parent.rot_z
10 changes: 8 additions & 2 deletions VirtualSatelliteCAD/test/json_io/test_json_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,9 @@ def test_full_import(self):
product_object = active_document.app_active_document.getObjectsByLabel(subchild.get_unique_name())
self.assertIsNotNone(product_object, "Found an object under the given part name")

# TODO: Check: Should it propagate coordinate values from parent to child or is there a bug in virsat export?
# Check propagation
# poz_z of -500 should be propagated from "BeamStructure"
self.assertEqual(subchild.pos_z, 500.0, "Z position got propagated correctly")

def test_full_import_again(self):
"""
Expand Down Expand Up @@ -363,7 +365,11 @@ def test_full_import_again(self):

for i, child1 in enumerate(json_product.children):
child2 = json_product2.children[i]
child1.hasEqualValues(child2)
child1.has_equal_values(child2)

def test_full_import_again_with_changes(self):
"""
If two files with the same name get imported all elements of the second file should overwrite the elements of the first file,
but elements existing in the first file (but not in the second file) won't be changed
"""
pass

0 comments on commit 205ea9c

Please sign in to comment.