Пример #1
0
    def __init__(self, root_window, model_part):  # Constructor
        super(GUIObject, self).__init__(root_window, "SALOME Kratos Converter")

        global_utils.LogInfo("Initializing Main Window")

        self.model_part = model_part

        utils.MaximizeWindow(self.window)

        self._InitializeWidgets()

        self.child_window_open = False

        self.window.bind("<Control-n>", lambda event: self._NewProject())
        self.window.bind("<Control-o>",
                         lambda event: self._OpenConverterProject())
        self.window.bind("<Control-s>",
                         lambda event: self._SaveConverterProject(False))
        self.window.bind("<Control-Shift-S>",
                         lambda event: self._SaveConverterProject(True))
        self.window.unbind("<Escape>")  # Overwritting the base class behaviour

        self.window.bind("<Control-r>",
                         lambda event: self._CreateReadMainMeshWindow())
        self.window.bind("<Control-i>",
                         lambda event: self._ImportConverterScheme())
        self.window.bind("<Control-e>",
                         lambda event: self._ExportConverterScheme())

        self._Initialize()
Пример #2
0
    def _DeleteTreeItems(self, event):
        smp_to_remove = []
        for item in self.tree.selection():
            smp_name = self.tree.item(item, "text")
            smp_to_remove.append(smp_name)  # Identify SubModelParts by name
            self.tree.delete(item)
            global_utils.LogInfo("Deleted SubModelPart: " + smp_name)

        if len(self.tree.get_children(self.main_tree_item)
               ) == 0:  # Everything is deleted, reset ModelPart
            self.tree.delete(self.main_tree_item)
            self.model_part.Reset()
            self.unsaved_changes_exist = False
            self.PlotCmdOutput("ModelPart resetted", "orange")
            global_utils.LogInfo("ModelPart resetted")
        else:
            for smp_name in smp_to_remove:
                self.model_part.RemoveSubmodelPart(smp_name)
    def __Assemble(self, readable_mdpa):
        # TODO Check if this was done before! (same for the submodelparts)
        start_time = time.time()
        global_utils.LogInfo("Assembling Mesh")
        self.__InitializeMesh()
        for smp_name in sorted(self.sub_model_parts.keys()):
            smp = self.sub_model_parts[smp_name]
            smp.Assemble()
            smp_nodes, smp_elements, smp_conditions = smp.GetMesh()
            self.__AddNodes(smp_nodes, readable_mdpa)
            self.__AddElements(smp_elements)
            self.__AddConditions(smp_conditions)

        global_utils.LogTiming("Mesh assembling time", start_time)
    def WriteMesh(self,
                  mdpa_file_path,
                  info_text="",
                  readable_mdpa=False):  # TODO use this
        self.__Assemble(readable_mdpa)  # TODO only do this if sth has changed

        start_time = time.time()
        global_utils.LogInfo("Writing Mesh")

        # Write Header
        if not mdpa_file_path.endswith('.mdpa'):
            mdpa_file_path += ".mdpa"
        with open(mdpa_file_path, "w") as mdpa_file:
            self.__WriteMeshInfo(mdpa_file, info_text)
            mdpa_file.write(
                "\nBegin ModelPartData\n//  VARIABLE_NAME value\nEnd ModelPartData\n\n"
            )
            mdpa_file.write("Begin Properties 0\nEnd Properties\n\n")

            # Write Nodes
            self.__WriteNodes(mdpa_file, readable_mdpa)

            # Write Elements
            self.__WriteElements(mdpa_file, readable_mdpa)

            # Write Conditions
            self.__WriteConditions(mdpa_file, readable_mdpa)

            # Write Nodal Data
            self.__WriteNodalData(mdpa_file, readable_mdpa)

            # Write Elemental Data
            self.__WriteGeometricalEntityData(mdpa_file, readable_mdpa,
                                              self.elements, "Element")

            # Write Conditional Data
            self.__WriteGeometricalEntityData(mdpa_file, readable_mdpa,
                                              self.conditions, "Condition")

            # Write SubModelParts
            for smp_name in sorted(self.sub_model_parts.keys()):
                smp = self.sub_model_parts[smp_name]
                smp.WriteMesh(mdpa_file, readable_mdpa)

            global_utils.LogTiming("Mesh writing time", start_time)

        self.__ClearAfterWriting()

        return True
Пример #5
0
    def _SaveConverterProject(self, save_as):
        if len(self.tree.get_children()) == 0:
            self.PlotCmdOutput("Nothing to be saved", "red")
        else:
            if (self.save_file_path == "" or save_as):
                input_save_file_path = tk.filedialog.asksaveasfilename(
                    title="Select file",
                    filetypes=[("converter files",
                                "*" + utils.conv_project_file_ending)])

                if input_save_file_path:  # A file path was returned
                    if not input_save_file_path.endswith(
                            utils.conv_project_file_ending):
                        input_save_file_path += utils.conv_project_file_ending

                    self.save_file_path = input_save_file_path

            if self.save_file_path == "":
                self.PlotCmdOutput("File was not saved", "red")
            else:
                start_time = time.time()
                serialized_model_part_dict = self.model_part.Serialize()

                # Add general information to file
                serialized_model_part_dict.update({
                    "general":
                    global_utils.GetGeneralInfoDict(utils.VERSION)
                })

                with open(self.save_file_path, "w") as save_file:
                    if global_utils.GetDebug():
                        # Do this only for debugging, file size is much larger!
                        json.dump(serialized_model_part_dict,
                                  save_file,
                                  sort_keys=True,
                                  indent=4)
                    else:
                        fast_json.dump(serialized_model_part_dict, save_file)

                global_utils.LogTiming("Save Project", start_time)
                self.PlotCmdOutput("Saved the project", "green")
                self.unsaved_changes_exist = False
                global_utils.LogInfo("Saved Project")
Пример #6
0
    def _OpenConverterProject(self):
        if self._CheckForUnsavedChanges():
            self._ResetGUI()
            file_path, valid_file = utils.GetFilePathOpen(
                utils.conv_project_file_ending)
            utils.BringWindowToFront(self.window)

            if valid_file:
                serialized_model_part_dict = {}
                try:
                    start_time = time.time()
                    with open(file_path, "r") as json_file:
                        serialized_model_part_dict = fast_json.load(json_file)

                    self.model_part.Deserialize(serialized_model_part_dict)
                    self.UpdateMeshTree()
                    global_utils.LogTiming("Open Project", start_time)
                    self.PlotCmdOutput("Opened the project", "green")
                    global_utils.LogInfo("Opened Project")
                except:
                    self.PlotCmdOutput(
                        "Opening project from file \"{}\" failed".format(
                            file_path), "red")
Пример #7
0
 def _CloseMainWindow(self):
     global_utils.LogInfo("Closing the Main Window")
     self.window.quit()  # needed to end the GUI with the plot
     self.window.destroy()
Пример #8
0
 def _ResetGUI(self):
     global_utils.LogInfo("Resetted the GUI")
     self._Initialize()
Пример #9
0
Author: Philipp Bucher
Chair of Structural Analysis
June 2017
Intended for non-commercial use in research
'''

# Python imports
import tkinter as tk
from tkinter import messagebox
import time
from tkinter import ttk
import global_utilities as global_utils
try:  # ujson is much faster in file saving and a bit faster in file opening. Install in Ubuntu with: "sudo apt-get install python3-ujson"
    import ujson as fast_json
    import json
    global_utils.LogInfo("Using ujson-module")
except ImportError:
    import json as fast_json
    import json
    global_utils.LogInfo("Using json-module")

# Project imports
import converter_gui_utilities as utils


class BaseWindow():  # This is the base class for all window classes
    def __init__(self, window, window_title, master=None):
        self.window = window
        self.child_window_open = False
        self.window.protocol(
            'WM_DELETE_WINDOW',