def load_case(load_path: str) -> "Case": """ Loads a case from the given folder and returns its Case data. """ refocus_cwd() project_folder_path = path.dirname(load_path) freecad_document_file_path = path.abspath("{}/DSPH_Case.FCStd".format(project_folder_path)) if not path.isfile(freecad_document_file_path): error_dialog(__("DSPH_Case.FCStd file could not be found. Please check if the project was moved or the file was renamed.")) return None if document_count() and not prompt_close_all_documents(): return None FreeCAD.open(project_folder_path + "/DSPH_Case.FCStd") with open(load_path, "rb") as load_picklefile: try: loaded_data = pickle.load(load_picklefile) if not loaded_data.version: warning_dialog(__("The case data you're trying to load is older than version 0.6 and cannot be loaded.")) prompt_close_all_documents(prompt=False) return None if loaded_data.version < VERSION: warning_dialog(__("The case data you are loading is from a previous version ({}) of this software. They may be missing features or errors.").format(loaded_data.version)) elif loaded_data.version > VERSION: warning_dialog(__("You're loading a case data from a future version ({}) of this software. You should upgrade DesignSPHysics as they may be errors using this file.").format(loaded_data.version)) return loaded_data except AttributeError: error_dialog(__("There was an error opening the case. Case Data file seems to be corrupted.")) return None
def on_new_case(self, prompt=True): """ Defines what happens when new case is clicked. Closes all documents if possible and creates a FreeCAD document with Case Limits object. """ if document_count() and not prompt_close_all_documents(prompt): return create_dsph_document() Case.the().reset() Case.the().add_object( SimulationObject(CASE_LIMITS_OBJ_NAME, -1, ObjectType.SPECIAL, ObjectFillMode.SPECIAL)) self.case_created.emit() self.update_dp.emit() self.need_refresh.emit()
def on_new_from_freecad_document(self, prompt=True): """ Creates a new case based on an existing FreeCAD document. This is specially useful for CAD users that want to use existing geometry for DesignSPHysics. """ file_name, _ = QtGui.QFileDialog().getOpenFileName( get_fc_main_window(), "Select document to import", Case.the().info.last_used_directory) Case.the().info.update_last_used_directory(file_name) if file_name and document_count( ) and not prompt_close_all_documents(prompt): return create_dsph_document_from_fcstd(file_name) Case.the().reset() # Case.the().add_object_to_sim(SimulationObject(CASE_LIMITS_OBJ_NAME, -1, ObjectType.SPECIAL, ObjectFillMode.SPECIAL)) self.update_dp.emit() self.case_created.emit() self.need_refresh.emit()
def boot(): """ Boots the application. """ print_license() check_compatibility() try: master_branch_version = str( urlopen(GITHUB_MASTER_CONSTANTS_URL).read()).split( "VERSION = \"")[-1].split("\"")[0] if VERSION < master_branch_version and NOTIFY_ON_OUTDATED_VERSION: info_dialog( __("Your version of DesignSPHyiscs is outdated. Please go to the Addon Manager and update it. New versions include bug fixes, new features and new DualSPHysics executables, among other things." ), __("The version you're using is {} while the version that you can update to is {}" ).format(VERSION, master_branch_version)) except URLError: log("No network connection or Git repo is down. Skipping version check." ) if document_count() > 0: success = prompt_close_all_documents() if not success: debug( "User chose not to close the currently opened documents. Aborting startup" ) quit() # Tries to delete docks created by a previous execution of DesignSPHysics delete_existing_docks() designsphysics_dock = DesignSPHysicsDock(get_fc_main_window()) properties_widget = PropertiesDockWidget(parent=get_fc_main_window()) get_fc_main_window().addDockWidget(QtCore.Qt.RightDockWidgetArea, designsphysics_dock) get_fc_main_window().addDockWidget(QtCore.Qt.LeftDockWidgetArea, properties_widget) # Subscribe the FreeCAD Objects tree to the item selection change function. # This helps FreeCAD notify DesignSPHysics for the deleted and changed objects to get updated correctly. fc_object_tree: QtGui.QTreeWidget = get_fc_main_window().findChildren( QtGui.QSplitter)[0].findChildren(QtGui.QTreeWidget)[0] fc_object_tree.itemSelectionChanged.connect( lambda p=properties_widget, d=designsphysics_dock: on_tree_item_selection_change(p, d)) debug( "Subscribing selection change monitor handler to freecad object tree item changed." ) properties_widget.need_refresh.connect( lambda p=properties_widget, d=designsphysics_dock: on_tree_item_selection_change(p, d)) designsphysics_dock.need_refresh.connect( lambda p=properties_widget, d=designsphysics_dock: on_tree_item_selection_change(p, d)) # Launch a monitor thread that ensures some things are not changed. monitor_thread = threading.Thread( target=lambda p=properties_widget, d=designsphysics_dock: selection_monitor(p, d)) monitor_thread.start() FreeCADGui.activateWorkbench(DEFAULT_WORKBENCH) log(__("Initialization finished for {} v{}").format(APP_NAME, VERSION))