Skip to content

Commit

Permalink
Reactivate full_import test case and update importer - (Task #5)
Browse files Browse the repository at this point in the history
---
Task #5: Implement Import Functionality
  • Loading branch information
JAmmermann-DLR committed Dec 3, 2019
1 parent a7ce015 commit 043b84c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 20 deletions.
4 changes: 2 additions & 2 deletions VirtualSatelliteCAD/json_io/json_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from freecad.active_document import ActiveDocument
from json_io.parts.json_part_factory import JsonPartFactory
from json_io.products.json_product_assembly_tree_traverser import JsonProductAssemblyTreeTraverser
from json_io.json_definitions import get_part_name_uuid, JSON_PRODUCTS, JSON_PARTS
from json_io.json_definitions import get_part_name_uuid, JSON_PRODUCTS, JSON_PARTS, PART_IDENTIFIER

import json
from freecad import active_document
Expand Down Expand Up @@ -61,7 +61,7 @@ def create_or_update_part(self, json_object):
# should be careful in case the name already exists.
# thus it is combined with the uuid. not really nice
# but definitely efficient
part_file_name = get_part_name_uuid(json_object)
part_file_name = PART_IDENTIFIER + get_part_name_uuid(json_object)

active_document = ActiveDocument(self.working_output_directory).open_set_and_get_document(part_file_name)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
# SPDX-License-Identifier: LGPL-3.0-or-later

from json_io.products.json_product_assembly import JsonProductAssembly
from json_io.json_definitions import JSON_ELEMNT_CHILDREN, JSON_ELEMENT_NAME, PRODUCT_IDENTIFIER
from json_io.json_definitions import JSON_ELEMNT_CHILDREN, JSON_ELEMENT_NAME
from freecad.active_document import ActiveDocument
import FreeCAD
Log = FreeCAD.Console.PrintLog
Expand Down Expand Up @@ -79,7 +79,7 @@ def parse_from_json(self):

# the last json_product is the root of the assembly, open it again for the UI
if(json_product is not None):
active_document = ActiveDocument(self.working_output_directory).open_set_and_get_document(json_product.get_unique_name())
active_document = ActiveDocument(self.working_output_directory).open_set_and_get_document(json_product.get_product_unique_name())

return json_product, active_document

Expand Down
31 changes: 15 additions & 16 deletions VirtualSatelliteCAD/test/json_io/test_json_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,10 @@
import FreeCAD
import FreeCADGui
from test.test_setup import AWorkingDirectoryTest
from freecad.active_document import FREECAD_FILE_EXTENSION
from freecad.active_document import FREECAD_FILE_EXTENSION, ActiveDocument
from module.environment import Environment
from json_io.json_definitions import JSON_ELEMENT_STL_PATH
from json_io.json_definitions import JSON_ELEMENT_STL_PATH, PART_IDENTIFIER, PRODUCT_IDENTIFIER
import unittest
from freecad.active_document import ActiveDocument

App = FreeCAD
Gui = FreeCADGui
Expand Down Expand Up @@ -73,7 +72,7 @@ def test_create_part(self):
json_importer.create_or_update_part(json_object)

# Check the file got created
test_file_name = self._WORKING_DIRECTORY + "Beam_6201a731_d703_43f8_ab37_6a0581dfe022" + FREECAD_FILE_EXTENSION
test_file_name = self._WORKING_DIRECTORY + PART_IDENTIFIER + "Beam_6201a731_d703_43f8_ab37_6a0581dfe022" + FREECAD_FILE_EXTENSION
self.assertTrue(os.path.isfile(test_file_name), "File exists on drive")
App.open(test_file_name)

Expand Down Expand Up @@ -128,7 +127,7 @@ def test_create_part_update_uuid(self):
json_importer.create_or_update_part(json_object)

# Check the file got created
test_file_name = self._WORKING_DIRECTORY + "Beam_6201a731_d703_43f8_ab37_6a0581dfe022" + FREECAD_FILE_EXTENSION
test_file_name = self._WORKING_DIRECTORY + PART_IDENTIFIER + "Beam_6201a731_d703_43f8_ab37_6a0581dfe022" + FREECAD_FILE_EXTENSION
self.assertTrue(os.path.isfile(test_file_name), "File exists on drive")
App.open(test_file_name)

Expand All @@ -151,7 +150,7 @@ def test_create_part_update_uuid(self):
json_importer.create_or_update_part(json_object)

# Check the file got created
test_file_name = self._WORKING_DIRECTORY + "Beam_6201a731_d703_43f8_ab37_6a0666dfe022" + FREECAD_FILE_EXTENSION
test_file_name = self._WORKING_DIRECTORY + PART_IDENTIFIER + "Beam_6201a731_d703_43f8_ab37_6a0666dfe022" + FREECAD_FILE_EXTENSION
App.open(test_file_name)

self.assertEquals(len(App.ActiveDocument.RootObjects), TEST_ALLOWED_AMOUNT_OF_PART_OBJECTS, "Correct amount of objects in file")
Expand All @@ -178,7 +177,7 @@ def test_create_part_update_value(self):
json_importer.create_or_update_part(json_object)

# Check the file got created
test_file_name = self._WORKING_DIRECTORY + "Beam_6201a731_d703_43f8_ab37_6a0581dfe022" + FREECAD_FILE_EXTENSION
test_file_name = self._WORKING_DIRECTORY + PART_IDENTIFIER + "Beam_6201a731_d703_43f8_ab37_6a0581dfe022" + FREECAD_FILE_EXTENSION
self.assertTrue(os.path.isfile(test_file_name), "File exists on drive")
App.open(test_file_name)

Expand All @@ -202,7 +201,7 @@ def test_create_part_update_value(self):
json_importer.create_or_update_part(json_object)

# Check the file got created
test_file_name = self._WORKING_DIRECTORY + "Beam_6201a731_d703_43f8_ab37_6a0581dfe022" + FREECAD_FILE_EXTENSION
test_file_name = self._WORKING_DIRECTORY + PART_IDENTIFIER + "Beam_6201a731_d703_43f8_ab37_6a0581dfe022" + FREECAD_FILE_EXTENSION
self.assertTrue(os.path.isfile(test_file_name), "File exists on drive")
App.open(test_file_name)

Expand Down Expand Up @@ -234,12 +233,12 @@ def test_create_part_change_shape(self):
json_importer.create_or_update_part(json_object)

# Check the file got created
test_file_name = self._WORKING_DIRECTORY + "Beam_6201a731_d703_43f8_ab37_6a7171dfe022" + FREECAD_FILE_EXTENSION
test_file_name = self._WORKING_DIRECTORY + PART_IDENTIFIER + "Beam_6201a731_d703_43f8_ab37_6a7171dfe022" + FREECAD_FILE_EXTENSION
App.open(test_file_name)

# Check that there is the correct object inside
self.assertIsNotNone(App.ActiveDocument.getObject("Box"), "Got correct object")
App.closeDocument("Beam_6201a731_d703_43f8_ab37_6a7171dfe022")
App.closeDocument(PART_IDENTIFIER + "Beam_6201a731_d703_43f8_ab37_6a7171dfe022")

# Now start cyling the objects
json_object["shape"] = "CYLINDER"
Expand All @@ -249,7 +248,7 @@ def test_create_part_change_shape(self):
App.open(test_file_name)
self.assertIsNone(App.ActiveDocument.getObject("Box"), "Removed previous object")
self.assertIsNotNone(App.ActiveDocument.getObject("Cylinder"), "Got correct object")
App.closeDocument("Beam_6201a731_d703_43f8_ab37_6a7171dfe022")
App.closeDocument(PART_IDENTIFIER + "Beam_6201a731_d703_43f8_ab37_6a7171dfe022")

# Next object
json_object["shape"] = "SPHERE"
Expand All @@ -259,7 +258,7 @@ def test_create_part_change_shape(self):
App.open(test_file_name)
self.assertIsNone(App.ActiveDocument.getObject("Cylinder"), "Removed previous object")
self.assertIsNotNone(App.ActiveDocument.getObject("Sphere"), "Got correct object")
App.closeDocument("Beam_6201a731_d703_43f8_ab37_6a7171dfe022")
App.closeDocument(PART_IDENTIFIER + "Beam_6201a731_d703_43f8_ab37_6a7171dfe022")

# Next object
json_object["shape"] = "GEOMETRY"
Expand All @@ -269,7 +268,7 @@ def test_create_part_change_shape(self):
App.open(test_file_name)
self.assertIsNone(App.ActiveDocument.getObject("Sphere"), "Removed previous object")
self.assertIsNotNone(App.ActiveDocument.getObject("Geometry"), "Got correct object")
App.closeDocument("Beam_6201a731_d703_43f8_ab37_6a7171dfe022")
App.closeDocument(PART_IDENTIFIER + "Beam_6201a731_d703_43f8_ab37_6a7171dfe022")

# Next object
json_object["shape"] = "CONE"
Expand All @@ -279,9 +278,8 @@ def test_create_part_change_shape(self):
App.open(test_file_name)
self.assertIsNone(App.ActiveDocument.getObject("Geometry"), "Removed previous object")
self.assertIsNotNone(App.ActiveDocument.getObject("Cone"), "Got correct object")
App.closeDocument("Beam_6201a731_d703_43f8_ab37_6a7171dfe022")
App.closeDocument(PART_IDENTIFIER + "Beam_6201a731_d703_43f8_ab37_6a7171dfe022")

@unittest.SkipTest
def test_full_import(self):
"""
Full JSON import test
Expand Down Expand Up @@ -311,7 +309,8 @@ def test_full_import(self):
self.assertEquals(len(json_product.children), 5, "Correct amount of children")
self.assertEquals(len(active_document.app_active_document.RootObjects), 10, "Found correct amount of root objects 5 plus 5 sheets")

active_document = ActiveDocument(self._WORKING_DIRECTORY).open_set_and_get_document("BeamStructure_2afb23c9_f458_4bdb_a4e7_fc863364644f")
active_document = ActiveDocument(self._WORKING_DIRECTORY).open_set_and_get_document(
PRODUCT_IDENTIFIER + "BeamStructure_2afb23c9_f458_4bdb_a4e7_fc863364644f")
self.assertEquals(len(active_document.app_active_document.RootObjects), 6, "Found correct amount of root objects 3 objects plus 3 sheets")

@unittest.SkipTest
Expand Down

0 comments on commit 043b84c

Please sign in to comment.