Пример #1
0
    def on_event(self, event: UserEvent):
        """A user event was passed to the ConversionPanel.

        :param event: The recorded UserEvent.
        :return: None
        """
        if not glInitGl42VERSION():
            return

        if event is not None:
            if event.get_event_type() == UserEventType.CONVERSION_COMPLETE:
                self.opengl_canvas.update_meshes()
                self.cycle_preview_button.Enable()
                self.set_preview_from_context()

            if event.get_event_type(
            ) == UserEventType.RENDERING_MOUSE_WHEEL_EVENT:
                if self.can_use_opengl():
                    # Log Message here is of derived class FloatMessage.
                    if isinstance(event.get_log_message(), FloatMessage):
                        self.zoom_static_text_ctrl.SetLabelText(
                            "Camera Distance to Origin: {0:0.3f}".format(
                                event.get_log_message().get_float()))
            elif event.get_event_type() == UserEventType.INPUT_MODEL_READY:
                if self.can_use_opengl():
                    self.preview_render_context.SetLabelText(
                        "Current Preview: STL Model")
                    self.set_widget_rendering_contexts(True)
                    self.cycle_preview_button.Disable()
                    self.zoom_static_text_ctrl.SetLabelText(
                        "Camera Distance to Origin: " +
                        str(self.opengl_canvas.scene.
                            get_camera_distance_to_origin()))
Пример #2
0
    def handle_log_message_event(self, event: UserEvent):
        """Take apart the log message and display it to the log. Different types of messages
        will have different colors.
            -INFO: White
            -WARNING: Yellow
            -ERROR: Red
            -DEBUG: Blue

        :param event: The event that contains the LogMessage that will be displayed on the log.
        :return: None
        """
        if event is not None:
            if event.get_log_message() is not None:
                log_message = event.get_log_message()
                log_type = log_message.get_message_type()
                if log_type is not LogType.IGNORE:
                    message = log_message.get_message()
                    timestamp = log_message.get_timestamp()
                    color = log_message.get_log_message_color()

                    if log_type == LogType.DEBUG and __debug__ or log_type != LogType.DEBUG:
                        self.log_text_ctrl.SetInsertionPointEnd()
                        self.log_text_ctrl.BeginFontSize(UIStyle.log_font_size)
                        self.log_text_ctrl.BeginTextColour(
                            UIStyle.log_default_text_color)
                        self.log_text_ctrl.WriteText(timestamp + ": ")
                        self.log_text_ctrl.BeginTextColour(wx.Colour(color))
                        if __debug__ and event.get_event_type() is not None:
                            self.log_text_ctrl.WriteText(
                                str(event.get_event_type()) + "| ")
                        self.log_text_ctrl.WriteText(message + "\n")
                        self.log_text_ctrl.EndFontSize()
                        # Scrolls down to show last line added
                        self.log_text_ctrl.ShowPosition(
                            self.log_text_ctrl.GetLastPosition())
Пример #3
0
    def check_input(self):
        """Checks if all input fields have valid flag, and changes program
        state if needed. Should be called after an input field updates.

        :return: None
        """
        if self.ldraw_name_isvalid and self.stl_path_isvalid:
            if UIDriver.application_state != ApplicationState.WAITING_GO:
                UIDriver.fire_event(UserEvent(
                    UserEventType.INPUT_VALID,
                    LogMessage(LogType.IGNORE, "")))
        else:
            if UIDriver.application_state != ApplicationState.WAITING_INPUT:
                UIDriver.fire_event(UserEvent(
                    UserEventType.INPUT_INVALID,
                    LogMessage(LogType.IGNORE, "")))

        # Set colors
        if self.ldraw_name_isvalid:
            self.ldraw_name_input.SetBackgroundColour(UIStyle.metadata_input_valid_background)
        else:
            self.ldraw_name_input.SetBackgroundColour(UIStyle.metadata_input_invalid_background)
        if self.stl_path_isvalid:
            self.stl_path_input.SetBackgroundColour(UIStyle.metadata_input_valid_background)
        else:
            self.stl_path_input.SetBackgroundColour(wx.Colour(UIStyle.metadata_input_invalid_background))
Пример #4
0
    def on_event(self, event: UserEvent):
        """A user event was passed to the OpenGLCanvas.

        :param event: The recorded UserEvent.
        :return: None
        """
        if glInitGl42VERSION():
            if event is not None:
                if event.get_event_type() == UserEventType.INPUT_MODEL_READY:
                    self.scene.replace_input_model_mesh(
                        ModelShipper.input_model.mesh)
                    self.scene.replace_output_model_mesh(None)
                    self.scene.set_input_model_active(True)

                if event.get_event_type(
                ) == UserEventType.RENDERING_WIRE_FRAME_PRESSED:
                    # A log message of this type is a BoolMessage.
                    self.wire_frame = event.get_log_message().get_bool()

                if event.get_event_type(
                ) == UserEventType.RENDERING_CANVAS_DISABLE:
                    self.Unbind(wx.EVT_PAINT)
                    self.Unbind(wx.EVT_PAINT)
                    self.Refresh()

                if event.get_event_type(
                ) == UserEventType.RENDERING_CANVAS_ENABLE:
                    self.Bind(wx.EVT_PAINT, self.on_paint)
                    self.Refresh()
Пример #5
0
    def text_ctrl_input_on_kill_focus(self, event):
        """Get the path for STL input file from user typing into TextCtrl element.
        :param event:
        :return:
        """
        prev_text = self.stl_path_text
        self.stl_path_text = self.stl_path_input.GetValue()
        self.stl_path_input.SetValue(MetadataPanel.reduce_text_path(self.stl_path_input.GetValue()))

        if prev_text != self.stl_path_text:

            # Check file path validity
            if Util.is_file(self.stl_path_text):
                if self.stl_path_text.endswith('.stl'):

                    # Check if this .stl is valid

                    mesh = ModelShipper.load_stl_model(self.stl_path_text)

                    if mesh:
                        # Load in LDraw object to input model
                        ModelShipper.input_model = LDrawModel(mesh)
                        self.stl_dir = Util.get_parent(self.stl_path_text)  # Only the dir
                        SettingsManager.save_settings("stl_dir", self.stl_dir)
                        self.stl_path_isvalid = True
                        UIDriver.fire_event(
                            UserEvent(UserEventType.INPUT_MODEL_READY,
                                      LogMessage(LogType.INFORMATION,
                                                 "Input file loaded from: '" +
                                                 self.stl_path_text + "'.")))
                    else:
                        self.stl_path_isvalid = False
                        UIDriver.fire_event(
                            UserEvent(UserEventType.LOG_INFO,
                                      LogMessage(LogType.ERROR,
                                                 "The input file '" +
                                                 self.stl_path_text +
                                                 "' is not a valid STL file.")))
                else:
                    self.stl_path_isvalid = False
                    UIDriver.fire_event(
                        UserEvent(UserEventType.LOG_INFO,
                                  LogMessage(LogType.ERROR,
                                             "Input file must have .stl extension.")))
            else:
                self.stl_path_isvalid = False
                if len(self.stl_path_text) <=0:
                    log_msg = "Input filepath cannot be blank."
                else:
                    log_msg = "The path '" + self.stl_path_text + "' could not be found."
                UIDriver.fire_event(
                    UserEvent(UserEventType.LOG_INFO,
                              LogMessage(LogType.ERROR, log_msg)))
            self.check_input()
        event.Skip()
Пример #6
0
    def on_event(self, event: UserEvent):
        """A user event was passed to the ConversionPanel.

        :param event: The recorded UserEvent.
        :return: None
        """
        if event.get_event_type() == UserEventType.CONVERSION_COMPLETE:
            self.save_button.Enable()

        if event.get_event_type() == UserEventType.INPUT_MODEL_READY:
            self.save_button.Disable()
Пример #7
0
    def browse_input(self, event):
        """Browse for a valid STL input file.
        :param event:
        :return:
        """
        UIDriver.fire_event(UserEvent(
            UserEventType.RENDERING_CANVAS_DISABLE,
            LogMessage(LogType.IGNORE, "")))
        stl_wildcard = "*.stl"
        dialog = wx.FileDialog(self, "Choose a STL file",
                               defaultDir=self.stl_dir, wildcard=stl_wildcard,
                               style=wx.FD_OPEN
                               | wx.FD_FILE_MUST_EXIST)

        if dialog.ShowModal() == wx.ID_OK:
            filename = dialog.GetPath()
            # Check for file existing
            # If valid, pass to worker thread who will check data
            if self.stl_path_text != filename:
                self.stl_path_input.SetValue(filename)
                self.stl_path_input.SetValue(MetadataPanel.reduce_text_path(self.stl_path_input.GetValue()))

                # Only update stuff if selection changed
                # Check if this .stl is valid
                mesh = ModelShipper.load_stl_model(filename)
                if mesh:
                    # Load in LDraw object to input model
                    ModelShipper.input_model = LDrawModel(mesh)
                    self.stl_dir = Util.get_parent(filename)  # Only the dir
                    self.stl_path_text = filename  # The whole path to file
                    self.stl_path_isvalid = True
                    SettingsManager.save_settings("stl_dir", self.stl_dir)

                    UIDriver.fire_event(
                        UserEvent(UserEventType.INPUT_MODEL_READY,
                                  LogMessage(LogType.INFORMATION,
                                             "Input file loaded from: '" +
                                             self.stl_path_text + "'.")))
                else:
                    self.stl_path_isvalid = False
                    UIDriver.fire_event(
                        UserEvent(UserEventType.LOG_INFO,
                                  LogMessage(LogType.ERROR,
                                             "The input file '" +
                                             filename +
                                             "' is not a valid STL file.")))
                self.check_input()

            UIDriver.fire_event(UserEvent(
                UserEventType.RENDERING_CANVAS_ENABLE,
                LogMessage(LogType.IGNORE, "")))

        dialog.Destroy()
Пример #8
0
    def save_log(self, event):
        """
        Save the feedback log to a file
        :param event:
        :return:
        """
        try:
            UIDriver.fire_event(
                UserEvent(UserEventType.RENDERING_CANVAS_DISABLE,
                          LogMessage(LogType.IGNORE, "")))

            with open(SettingsManager.file_path, "r") as file:
                file_settings = json.load(file)
                part_name = file_settings["part_name"]
                log_dir = file_settings["log_dir"]

            log_name = part_name.split(".")[0] + ".txt"
            dialog = wx.FileDialog(self,
                                   "Choose a log save location",
                                   defaultFile=log_name,
                                   defaultDir=log_dir,
                                   style=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT,
                                   wildcard="*.txt")

            if dialog.ShowModal() == wx.ID_OK:
                pathname = dialog.GetPath()
                directory = dialog.GetDirectory()

                # Check if the new directory is different the old one. If so update the settings file.
                if log_dir != directory:
                    SettingsManager.save_settings("log_dir", directory)

                try:
                    log_file = open(pathname, mode="w")
                    log_file.write(self.log_text_ctrl.GetValue())
                    log_file.close()
                except IOError:
                    pass
                finally:
                    pass
            UIDriver.fire_event(
                UserEvent(UserEventType.RENDERING_CANVAS_ENABLE,
                          LogMessage(LogType.IGNORE, "")))
            dialog.Destroy()
        except IOError:
            pass
Пример #9
0
    def test_constructor_user_event(self):
        """Test the constructor builds the correct user event.

        :return: None
        """
        event_type = UserEventType.INPUT_MODEL_READY
        log_type = LogType.ERROR
        log_message = "test user event"

        user_event = UserEvent(event_type, LogMessage(log_type, log_message))

        self.assertTrue(user_event.get_event_type(), event_type)
        self.assertTrue(user_event.log_message.get_message_type(), log_type)
        self.assertTrue(user_event.log_message.get_message(), log_message)

        # The log message color for ERROR should return full Red intensity. [255, 0, 0]
        self.assertTrue(user_event.get_log_message().get_log_message_color(), [255, 0, 0])
Пример #10
0
    def on_event(self, event: UserEvent):
        """A user event was passed to the thread manager.

        :param event: The recorded UserEvent.
        :return: None
        """
        if event.get_event_type() == UserEventType.CONVERSION_STARTED:
            self.start_work()

        elif event.get_event_type() == UserEventType.CONVERSION_PAUSED:
            self.pause_work()

        elif event.get_event_type() == UserEventType.CONVERSION_RESUMED:
            self.continue_work()

        elif event.get_event_type() == UserEventType.CONVERSION_CANCELED:
            self.kill_work()
Пример #11
0
    def browse_output(self, event):
        """Browse for a valid output file path
        :param event:
        :return:
        """
        UIDriver.fire_event(UserEvent(
            UserEventType.RENDERING_CANVAS_DISABLE,
            LogMessage(LogType.IGNORE, "")))

        dat_wildcard = "*.dat"
        dialog = wx.FileDialog(self, "Choose a location for the LDraw file",
                               defaultDir=self.part_dir,
                               style=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT,
                               wildcard=dat_wildcard)

        dialog.SetFilename(self.part_name)

        if dialog.ShowModal() == wx.ID_OK:
            pathname = dialog.GetPath()

            if self.out_file != pathname:
                # Check if part name ends with .dat, if not append that
                if not pathname.endswith('.dat'):
                    pathname = pathname + '.dat'

                self.out_file = pathname  # Full path
                self.part_dir = Util.get_parent(pathname)  # Only the dir
                self.part_name = Util.get_filename(pathname)  # Only filename
                self.ldraw_name_isvalid = True
                SettingsManager.save_settings("part_dir", self.part_dir)
                SettingsManager.save_settings("part_name", self.part_name)
                self.ldraw_name_input.SetValue(self.out_file)
                self.ldraw_name_input.SetValue(MetadataPanel.reduce_text_path(self.ldraw_name_input.GetValue()))
                self.check_input()
                UIDriver.fire_event(
                    UserEvent(UserEventType.LOG_INFO,
                              LogMessage(LogType.INFORMATION,
                                         "Output file will be saved as: '" +
                                         self.out_file + "'.")))

        UIDriver.fire_event(UserEvent(
            UserEventType.RENDERING_CANVAS_ENABLE,
            LogMessage(LogType.IGNORE, "")))
        dialog.Destroy()
Пример #12
0
    def cancel(self, event):
        """Cancel the conversion operation.

        :param event: The wx event that was recorded.
        :return: None
        """
        UIDriver.fire_event(
            UserEvent(
                UserEventType.CONVERSION_CANCELED,
                LogMessage(LogType.INFORMATION,
                           "Conversion process canceled.")))
Пример #13
0
    def convert(self, event):
        """Convert the selected STL file into an LDraw file.

        :param event: The wx event that was recorded.
        :return: None
        """
        UIDriver.fire_event(
            UserEvent(
                UserEventType.CONVERSION_STARTED,
                LogMessage(LogType.INFORMATION,
                           "Conversion process started..")))
Пример #14
0
    def pause_resume(self, event):
        """Pause/resume the conversion process.

        :param event: The wx event that was recorded.
        :return: None
        """
        self.is_paused = not self.is_paused
        if self.is_paused:
            self.pause_button.SetLabelText('Resume')
            UIDriver.fire_event(
                UserEvent(
                    UserEventType.CONVERSION_PAUSED,
                    LogMessage(LogType.INFORMATION,
                               "Conversion process paused.")))
        else:
            self.pause_button.SetLabelText('Pause')
            UIDriver.fire_event(
                UserEvent(
                    UserEventType.CONVERSION_RESUMED,
                    LogMessage(LogType.INFORMATION,
                               "Conversion process resumed.")))
Пример #15
0
    def on_wire_frame_pressed(self, event):
        """Send an event that the wire frame button was pressed. The OpenGLCanvas will
        detect and react accordingly.

        :param event: The wxpython event that occured.
        :return: None
        """
        UIDriver.fire_event(
            UserEvent(
                UserEventType.RENDERING_WIRE_FRAME_PRESSED,
                BoolMessage(LogType.DEBUG, "Wire frame checkbox pressed.",
                            self.cb_wire_frame.GetValue())))
        event.Skip()
Пример #16
0
    def on_state_changed(self, new_state: ApplicationState):
        """A state change was passed to the LogPanel.

        :param new_state: The recorded ApplicationState.
        :return: None
        """
        if new_state == ApplicationState.STARTUP:
            self.save_log_button.Enable()

        self.handle_log_message_event(
            UserEvent(
                UserEventType.APPLICATION_STATE_CHANGE,
                LogMessage(LogType.DEBUG,
                           "State changed to: " + str(new_state))))
Пример #17
0
    def on_mouse_wheel(self, event):
        """Called when the user scrolls with the mouse wheel. We will notify all panels of the
        mouse wheel instance.

        :param event: The wxpython Event.
        :return: None
        """
        if ModelShipper.input_model is not None:
            self.scene.on_mouse_wheel(event)
            UIDriver.fire_event(
                UserEvent(
                    UserEventType.RENDERING_MOUSE_WHEEL_EVENT,
                    FloatMessage(LogType.IGNORE, "Mouse Moved",
                                 self.scene.get_camera_distance_to_origin())))
Пример #18
0
    def text_ctrl_output_on_kill_focus(self, event):
        """Called when the output text control loses focus.

        :param event: The event that occurred.
        :return: None.
        """
        output_text = self.ldraw_name_input.GetValue()
        if len(output_text) <= 0:
            self.ldraw_name_input.SetValue("Browse output -->")
            if len(self.ldraw_name_input.GetValue()) > 0:
                self.ldraw_name_input.SetBackgroundColour(UIStyle.metadata_input_valid_background)
            UIDriver.fire_event(
                UserEvent(UserEventType.LOG_INFO,
                          LogMessage(LogType.ERROR,
                                     "Output file path cannot be blank.")))
        event.Skip()
Пример #19
0
    def text_ctrl_license_on_kill_focus(self, event):
        """Get the license value from the user and update the settings file
        as needed."""
        license_input_text = self.license_input.GetValue()

        # Update settings file license info
        if license_input_text != self.license_text and license_input_text != "":
            self.license_text = license_input_text
            UIDriver.fire_event(
                UserEvent(UserEventType.LOG_INFO,
                          LogMessage(LogType.INFORMATION,
                                     "License changed to: " +
                                     self.license_text)))
            SettingsManager.save_settings("license", self.license_text)

        elif len(license_input_text) == 0:
            self.reset_license()
        event.Skip()
Пример #20
0
    def text_ctrl_author_on_kill_focus(self, event):
        """Get the author value from the user and update the settings file
        as needed.

        :param event: The event that occurred.
        :return: None
        """
        author = self.author_input.GetValue()

        # Update settings file author info
        if author != self.author_text and author != "":
            self.author_text = author
            UIDriver.fire_event(
                UserEvent(UserEventType.LOG_INFO,
                          LogMessage(LogType.INFORMATION,
                                     "Author changed to: " +
                                     self.author_text)))
            SettingsManager.save_settings("author", self.author_text)

        elif len(author) == 0:
            self.reset_author()
        event.Skip()
Пример #21
0
    def save(self, event):
        """Save the finalized conversion of the input file. Hide main window options and replace them with metadata
        options. Once the user finalizes their metadata options (back or save), they return to the original options.

        :param event: The wx event that was recorded.
        :return: None
        """
        self.save_button.Disable()

        with open(SettingsManager.file_path, "r") as file:
            file_settings = json.load(file)
            part_dir = file_settings["part_dir"]
            part_name = file_settings["part_name"]

        file_path = Util.path_conversion(part_dir + "/" + part_name)
        with open(file_path, "w") as text_file:
            text_file.write(ModelShipper.get_metadata() +
                            ModelShipper.output_data_text)
        self.save_button.Enable()
        UIDriver.fire_event(
            UserEvent(
                UserEventType.LOG_INFO,
                LogMessage(LogType.INFORMATION,
                           "File was saved to '" + file_path + "'.")))