Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/task 5 implement import functi #17

Merged
merged 21 commits into from
Dec 4, 2019
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
466e60c
Update commands and add file open dialog to import command - (Task #5)
Nov 14, 2019
4e00299
Add import functionality to CommandImport - (Task #5)
Nov 14, 2019
b2ef16c
Refactor importer and add fixture - (Task #5)
Nov 14, 2019
f721858
Call JsonProductAssembly in full_import function- (Task #5)
Nov 19, 2019
7ea25ff
Add inheritance to JsonProductChild - (Task #5)
Nov 25, 2019
51af564
Add functionality for importing a JSON twice - (Task #5)
Nov 25, 2019
205ea9c
Add position and rotation propagation - (Task #5)
Nov 25, 2019
05bc713
Add functionality for full import twice with changes - (Task #5)
Nov 25, 2019
f7a0f27
Resolve TODOs - (Task #5)
Nov 27, 2019
76ebada
Fix missing Mod directory in AppData - (Task #5)
Nov 27, 2019
abbaab2
Disable full import test cases and add TODOs - (Task #5)
Nov 28, 2019
5e03847
Add test_json_product_assembly test cases - (Task #5)
Nov 28, 2019
c3c7cb9
Add JsonProductAssemblyTreeTraverser - (Task #5)
Dec 2, 2019
90b28ba
Add test_json_product_assemby_tree_traverser - (Task #5)
Dec 2, 2019
e7af193
Cleanup traverser - (Task #5)
Dec 2, 2019
694b1dd
Use traverser in importer and add test cases- (Task #5)
Dec 2, 2019
a7ce015
Add identifiers for product assembly and part files - (Task #5)
Dec 3, 2019
043b84c
Reactivate full_import test case and update importer - (Task #5)
Dec 3, 2019
2709748
Refactor command_import and resolve TODOs - (Task #5)
Dec 3, 2019
d0e7fa6
Remove unused import and blank lines at EOF - (Task #5)
Dec 3, 2019
c941d5a
Merge branch 'development' into feature/task_5-Implement_Import_Functi
Dec 3, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions VirtualSatelliteCAD/Init.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@
# SPDX-License-Identifier: LGPL-3.0-or-later
#
import FreeCAD
from os.path import isdir
import os
import sys

MOD_DIR = os.path.join(FreeCAD.ConfigGet("UserAppData"), "Mod")
APPDATA_DIR = os.path.join(MOD_DIR, "VirtualSatelliteCAD")

# FreeCAD seems to load modules differently once they are stored in the User Home directory.
# We try to load the whole folder if it exists
Expand All @@ -37,13 +39,19 @@

Log("See if the directory " + freecad_user_mod + "exists...")

if isdir(freecad_user_mod):
if os.path.isdir(freecad_user_mod):
Log("Directory Exists... Check if it is already on the path...")
if (freecad_user_mod in sys.path):
Log("Directory is already on the path...")
else:
Log("Directory will be appended to system path...")
sys.path.append(freecad_user_mod)

# Create an appdata directory
if not os.path.isdir(MOD_DIR):
os.mkdir(MOD_DIR)
if not os.path.isdir(APPDATA_DIR):
os.mkdir(APPDATA_DIR)

# Finally register the unit test for being executed with all other FreeCAD tests
FreeCAD.__unit_test__ += ["TestVirtualSatelliteApp"]
4 changes: 2 additions & 2 deletions VirtualSatelliteCAD/InitGui.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ def Initialize(self):
import commands.command_export # NOQA @UnusedImport
from commands.command_definitions import COMMAND_ID_EXPORT_2_VIRTUAL_SATELLITE
from commands.command_definitions import COMMAND_ID_IMPORT_2_FREECAD
self.appendToolbar('VirtualSatelliteMod', [COMMAND_ID_EXPORT_2_VIRTUAL_SATELLITE])
self.appendMenu('VirtualSatelliteMod', [COMMAND_ID_EXPORT_2_VIRTUAL_SATELLITE])
self.appendToolbar('VirtualSatelliteMod', [COMMAND_ID_IMPORT_2_FREECAD])
self.appendMenu('VirtualSatelliteMod', [COMMAND_ID_IMPORT_2_FREECAD])
self.appendToolbar('VirtualSatelliteMod', [COMMAND_ID_EXPORT_2_VIRTUAL_SATELLITE])
self.appendMenu('VirtualSatelliteMod', [COMMAND_ID_EXPORT_2_VIRTUAL_SATELLITE])

def GetClassName(self):
# Required method by FreeCAD framework
Expand Down
158 changes: 158 additions & 0 deletions VirtualSatelliteCAD/Resources/Tests/VisCube2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
{
"Products": {
"children": [{
"posX": 0.0,
"posY": 0.0,
"posZ": 1.0,
"rotX": 0.0,
"children": [],
"rotZ": 0.0,
"rotY": 0.0,
"name": "Top",
"uuid": "cc14e2c7-9d7e-4cf2-8d6d-9b8cf5e96d56",
"partUuid": "cc14e2c7-9d7e-4cf2-8d6d-9b8cf5e96d56",
"partName": "Top"
}, {
"posX": 0.0,
"posY": 0.0,
"posZ": 0.0,
"rotX": 0.0,
"children": [],
"rotZ": 0.0,
"rotY": 0.0,
"name": "Bottom",
"uuid": "61db0622-6fef-4f12-932d-a00fdb9d0848",
"partUuid": "00f430a6-6311-4a33-961b-41ded4cf57d5",
"partName": "Plate"
}, {
"posX": 0.5,
"posY": 0.0,
"posZ": 0.5,
"rotX": 0.0,
"children": [],
"rotZ": 0.0,
"rotY": 1.5707963267948966,
"name": "Front",
"uuid": "e6af9d3f-8ad6-4488-b3d0-d35549be9a1e",
"partUuid": "e6af9d3f-8ad6-4488-b3d0-d35549be9a1e",
"partName": "Front"
}, {
"posX": -0.5,
"posY": 0.0,
"posZ": 0.5,
"rotX": 0.0,
"children": [],
"rotZ": 0.0,
"rotY": 1.5707963267948966,
"name": "Back",
"uuid": "a3c9c547-8fd3-40d5-97a1-a3f9a3a9c337",
"partUuid": "a3c9c547-8fd3-40d5-97a1-a3f9a3a9c337",
"partName": "Back"
}, {
"posX": 0.0,
"posY": 0.0,
"posZ": 0.5,
"rotX": 0.0,
"children": [{
"posX": 0.0,
"posY": 0.5,
"posZ": 0.0,
"rotX": 1.5707963267948966,
"children": [],
"rotZ": 0.0,
"rotY": 0.0,
"name": "Left",
"uuid": "615985c0-73fd-48db-8f8b-e11b7cbb2ee8",
"partUuid": "615985c0-73fd-48db-8f8b-e11b7cbb2ee8",
"partName": "Left"
}, {
"posX": 0.0,
"posY": -0.5,
"posZ": 0.0,
"rotX": 1.5707963267948966,
"children": [],
"rotZ": 0.0,
"rotY": 0.0,
"name": "Right",
"uuid": "882a0b35-7da8-4555-903d-fd6b5cbec392",
"partUuid": "882a0b35-7da8-4555-903d-fd6b5cbec392",
"partName": "Right"
}
],
"rotZ": 0.0,
"rotY": 0.0,
"name": "BeamStructure",
"uuid": "2afb23c9-f458-4bdb-a4e7-fc863364644f",
"partUuid": "2afb23c9-f458-4bdb-a4e7-fc863364644f",
"partName": "BeamStructure"
}
],
"name": "SpaceCube",
"uuid": "a3533e02-125c-4066-bffe-d046d8d8342a"
},
"Parts": [{
"color": 16744448,
"shape": "CYLINDER",
"name": "BeamStructure",
"lengthY": 1.0,
"lengthX": 1.0,
"radius": 0.05,
"uuid": "2afb23c9-f458-4bdb-a4e7-fc863364644f",
"lengthZ": 1.0
}, {
"color": 8388608,
"shape": "BOX",
"name": "Right",
"lengthY": 1.0,
"lengthX": 1.0,
"radius": 0.05,
"uuid": "882a0b35-7da8-4555-903d-fd6b5cbec392",
"lengthZ": 0.02
}, {
"color": 32832,
"shape": "BOX",
"name": "Front",
"lengthY": 1.0,
"lengthX": 1.0,
"radius": 0.05,
"uuid": "e6af9d3f-8ad6-4488-b3d0-d35549be9a1e",
"lengthZ": 0.02
}, {
"color": 16711680,
"shape": "BOX",
"name": "Left",
"lengthY": 1.0,
"lengthX": 1.0,
"radius": 0.05,
"uuid": "615985c0-73fd-48db-8f8b-e11b7cbb2ee8",
"lengthZ": 0.02
}, {
"color": 65280,
"shape": "BOX",
"name": "Plate",
"lengthY": 1.0,
"lengthX": 1.0,
"radius": 0.05,
"uuid": "00f430a6-6311-4a33-961b-41ded4cf57d5",
"lengthZ": 0.02
}, {
"color": 16776960,
"shape": "BOX",
"name": "Back",
"lengthY": 1.0,
"lengthX": 1.0,
"radius": 0.05,
"uuid": "a3c9c547-8fd3-40d5-97a1-a3f9a3a9c337",
"lengthZ": 0.02
}, {
"color": 32768,
"shape": "BOX",
"name": "Top",
"lengthY": 1.0,
"lengthX": 1.0,
"radius": 0.05,
"uuid": "cc14e2c7-9d7e-4cf2-8d6d-9b8cf5e96d56",
"lengthZ": 0.02
}
]
}
31 changes: 31 additions & 0 deletions VirtualSatelliteCAD/Resources/Tests/VisCube2_update.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"Products": {
"children": [{
"posX": 0.0,
"posY": 0.0,
"posZ": 1.0,
"rotX": 0.0,
"children": [],
"rotZ": 0.0,
"rotY": 0.0,
"name": "Top",
"uuid": "cc14e2c7-9d7e-4cf2-8d6d-9b8cf5e96d56",
"partUuid": "cc14e2c7-9d7e-4cf2-8d6d-9b8cf5e96d57",
"partName": "Top2"
}
],
"name": "SpaceCube",
"uuid": "a3533e02-125c-4066-bffe-d046d8d8342a"
},
"Parts": [{
"color": 32768,
"shape": "BOX",
"name": "Top2",
"lengthY": 1.0,
"lengthX": 1.0,
"radius": 0.05,
"uuid": "cc14e2c7-9d7e-4cf2-8d6d-9b8cf5e96d57",
"lengthZ": 0.02
}
]
}
10 changes: 5 additions & 5 deletions VirtualSatelliteCAD/commands/command_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,21 @@

import FreeCAD
import FreeCADGui
from module.environment import Environment, ICON_IMPORT
from module.environment import Environment, ICON_EXPORT
from commands.command_definitions import COMMAND_ID_EXPORT_2_VIRTUAL_SATELLITE


class CommandExport:
def Activated(self):
FreeCAD.Console.PrintMessage("Calling the importer\n")
FreeCAD.Console.PrintMessage("Calling the exporter\n")

def IsActive(self):
return True

def GetResources(self):
return {'Pixmap': Environment().get_icon_path(ICON_IMPORT),
'MenuText': 'Import from Virtual Satellite',
'ToolTip': 'Open the dialog for the Virtual Satellite json import.'}
return {'Pixmap': Environment().get_icon_path(ICON_EXPORT),
'MenuText': 'Export from Virtual Satellite',
'ToolTip': 'Open the dialog for the Virtual Satellite json export.'}


FreeCADGui.addCommand(COMMAND_ID_EXPORT_2_VIRTUAL_SATELLITE, CommandExport()) # @UndefinedVariable
26 changes: 21 additions & 5 deletions VirtualSatelliteCAD/commands/command_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,35 @@
import FreeCADGui
from module.environment import Environment, ICON_IMPORT
from commands.command_definitions import COMMAND_ID_IMPORT_2_FREECAD
from PySide2.QtWidgets import QFileDialog
from json_io.json_importer import JsonImporter
import os


class CommandExport:
class CommandImport:
def Activated(self):
FreeCAD.Console.PrintMessage("Calling the json_io\n")
FreeCAD.Console.PrintMessage("Calling the importer\n")

# call pyqt dialog: returns (filename, filter)
filename = QFileDialog.getOpenFileName(
None, # ui parent
"Open JSON file", # dialog caption
Environment.get_appdata_module_path(),
"JSON(*.json)")[0] # filter

if filename != '':
FreeCAD.Console.PrintMessage(f"Selected file '{filename}'\n")

json_importer = JsonImporter(Environment.get_appdata_module_path() + os.sep)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we have to hand over this appdata_module_path?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created an issue for this: #19

json_importer.full_import(filename)

def IsActive(self):
return True

def GetResources(self):
return {'Pixmap': Environment().get_icon_path(ICON_IMPORT),
'MenuText': 'Export to Virtual Satellite',
'ToolTip': 'Open the dialog for the Virtual Satellite json export.'}
'MenuText': 'Import to Virtual Satellite',
'ToolTip': 'Open the dialog for the Virtual Satellite json import.'}


FreeCADGui.addCommand(COMMAND_ID_IMPORT_2_FREECAD, CommandExport()) # @UndefinedVariable
FreeCADGui.addCommand(COMMAND_ID_IMPORT_2_FREECAD, CommandImport()) # @UndefinedVariable
8 changes: 8 additions & 0 deletions VirtualSatelliteCAD/freecad/active_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ def open_set_and_get_document(self, file_name_without_extension):

return self

def clear_if_open_document(self, file_name_without_extension):
documents = list(App.listDocuments().keys())

if documents.count(file_name_without_extension) != 0:
Log('Delete and recreate new FreeCAD file...\n')
App.closeDocument(file_name_without_extension)
App.newDocument(file_name_without_extension)

def set_active_documents(self, file_name_without_extension):
App.setActiveDocument(file_name_without_extension)

Expand Down
Loading