Beispiel #1
0
    def _ValidateInput(self):
        valid_input = True

        if not self.smp_name_var.get():
            valid_input = False
            self.PlotCmdOutput("Please enter a SubModelPart Name", "red")
        else:
            if not isinstance(self.smp_name_var.get(), str):
                valid_input = False
                self.PlotCmdOutput("SubModelPart name is not valid", "red")

            if self.old_smp_name != self.smp_name_var.get():
                if self.master.GetModelPart().SubModelPartNameExists(
                        self.smp_name_var.get()):
                    self.PlotCmdOutput("SubModelPart name exists already!",
                                       "red")
                    valid_input = False

            if not self.edited_mesh:
                if (self.master.GetModelPart().FileNameExists(self.file_name)
                        or self.master.GetModelPart().FilePathExists(
                            self.file_path)):
                    result = messagebox.askquestion(
                        "Warning",
                        "This file might have been read already, continue?",
                        icon='warning')
                    if result == 'no':
                        valid_input = False
                        utils.BringWindowToFront(self.window)

        return valid_input
Beispiel #2
0
    def _ImportConverterScheme(self):
        if self._CheckForUnsavedChanges():
            self._ResetGUI()
            file_path, valid_file = utils.GetFilePathOpen(
                utils.conv_scheme_file_ending)
            utils.BringWindowToFront(self.window)

            if valid_file:
                json_dict = {}
                try:
                    with open(file_path, "r") as json_file:
                        json_dict = json.load(json_file)
                        if json_dict == {}:
                            self.PlotCmdOutput("Nothing imported", "red")
                        else:
                            corrected_json = {}
                            for file_name in json_dict.keys():
                                if file_name != "general":
                                    corrected_json.update({
                                        file_name:
                                        global_utils.CorrectMeshDict(
                                            json_dict[file_name])
                                    })

                            self.OpenChildWindow(
                                self._CreateFileSelectionWindow,
                                corrected_json)
                except:
                    self.PlotCmdOutput(
                        "Opening scheme from file \"{}\" failed".format(
                            file_path), "red")
Beispiel #3
0
 def PlotCmdOutput(self, String, color):
     utils.BringWindowToFront(self.window)
     current_color = self.entry_output.cget("background")
     self.output_str.set(String)
     for i in range(3):
         self.window.after(200, self._ResetColor(color))
         self.window.after(200, self._ResetColor(current_color))
Beispiel #4
0
    def _SetFilePath(self, entry_field, origin_file_name):
        file_path, valid_file = utils.GetFilePathOpen("dat", origin_file_name)

        if valid_file:
            entry_field.delete(0, "end")
            entry_field.insert(0, file_path)

        utils.BringWindowToFront(self.window)
Beispiel #5
0
 def OpenChildWindow(self, child_create_function, args=None):
     if self.child_window_open:
         self.PlotCmdOutput("Only one window can be open at a time", "red")
         try:
             utils.BringWindowToFront(self.child_window_object.GetWindow())
         except:
             self.PlotCmdOutput(
                 "Couldn't bring existing window to the front", "red")
     else:
         if args is None:
             self.child_window_object = child_create_function()
         else:
             self.child_window_object = child_create_function(args)
Beispiel #6
0
    def __init__(self, window, window_title, master=None):
        self.window = window
        self.child_window_open = False
        self.window.protocol(
            'WM_DELETE_WINDOW',
            self.CloseWindow)  # Overwrite the closing behavior
        self.window.wm_title(window_title)
        utils.BringWindowToFront(self.window)

        self.is_root = False
        if master is None:
            self.is_root = True
        self.master = master

        if not self.is_root:
            self.master.SetChildWindowIsOpen()

        self.window.bind("<Escape>", lambda event: self.CloseWindow())
Beispiel #7
0
    def _ReadAndParseMeshFile(self):
        file_path, valid_file = utils.GetFilePathOpen("dat")
        utils.BringWindowToFront(self.window)

        if valid_file:  # check if file exists
            self.tree_input.delete(*self.tree_input.get_children())
            self.tree_output.delete(*self.tree_output.get_children())

            file_name = utils.GetFileName(file_path)

            valid_file, self.nodes_read, self.geom_entities_read = global_utils.ReadAndParseSalomeDatFile(
                file_path)
            if valid_file:
                self._FillInputTree(self.geom_entities_read)
                self.file_parsed = True

                self.file_name = file_name
                self.file_path = file_path

                self.smp_name_var.set(file_name)
                self.smp_path_var.set(file_path)
            else:
                self.PlotCmdOutput("File is not valid", "red")
Beispiel #8
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")
Beispiel #9
0
 def PlotCmdOutput(self, String, color):
     self.master.PlotCmdOutput(String, color)
     utils.BringWindowToFront(self.window)