Beispiel #1
0
    def testExportPlane(self):
        # Create an empty temp folder to use for temporary model files.
        try:
            os.mkdir(Util.path_conversion("tests/temp"))
        except OSError:
            pass

        pass
        # The file path we will use.
        file_path = Util.path_conversion("tests/temp/plane.dat")

        # Import the model.
        mesh = ModelShipper.load_stl_model(Util.path_conversion("tests/test_models/plane.stl"))
        self.assertNotEqual(mesh, False)

        model = LDrawModel(mesh)

        """# Export the model.
        ModelShipper.save_ldraw_file_model(file_path, model)

        # Read the file.
        with open(file_path, 'r') as file:
            file_data = file.read()

        # The final file data should look like this.
        self.assertEqual(
            file_data,
            "0 LScan auto generated part plane\n0 Name: plane.dat\n0 Author: Rando\n0 !LICENSE Redistributable under CCAL version 2.0 : see CAreadme.txt\n3 4 -0.5 0.0 0.5 -0.5 0.0 -0.5 0.5 0.0 -0.5\n3 4 0.5 0.0 -0.5 0.5 0.0 0.5 -0.5 0.0 0.5\n")
        """
        # Cleanup.
        if os.path.exists(file_path):
            os.remove(file_path)
        os.rmdir(Util.path_conversion("tests/temp/"))
Beispiel #2
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()
Beispiel #3
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()
    def test_(self):
        test_message = "test input model message"

        input_model = ModelShipper.load_stl_model(
            Util.path_conversion("tests/test_models/plane.stl"))

        model_message = InputModelMessage(LogType.INFORMATION, test_message,
                                          input_model)

        self.assertEqual(model_message.get_message(), test_message)
        self.assertEqual(model_message.get_message_type(), LogType.INFORMATION)
        self.assertIsNotNone(model_message.get_timestamp())
        self.assertIsNotNone(model_message.get_model())
Beispiel #5
0
    def testImportPlane(self):
        # Load the model from the assets folder.
        mesh = ModelShipper.load_stl_model(Util.path_conversion("tests/test_models/plane.stl"))
        self.assertNotEqual(mesh, False)
        # First triangle facet.
        self.assertEqual(mesh.v0[0], Vector3([0.5, 0., -0.5]))
        self.assertEqual(mesh.v1[0], Vector3([-0.5, 0., -0.5]))
        self.assertEqual(mesh.v2[0], Vector3([-0.5, 0., 0.5]))

        # Second triangle facet.
        self.assertEqual(mesh.v0[1], Vector3([-0.5, 0., 0.5]))
        self.assertEqual(mesh.v1[1], Vector3([0.5, 0., 0.5]))
        self.assertEqual(mesh.v2[1], Vector3([0.5, 0., -0.5]))
    def test_(self):

        # Load the model from the assets folder.
        input_model = ModelShipper.load_stl_model(
            Util.path_conversion("tests/test_models/plane.stl"))
        output_model = LDrawModel(input_model  # Mesh
                                  )

        test_message = "test output model message"
        log_type = LogType.ERROR
        model_message = InputModelMessage(log_type, test_message,
                                          output_model.get_mesh())

        self.assertEqual(model_message.get_message(), test_message)
        self.assertEqual(model_message.get_message_type(), log_type)
        self.assertIsNotNone(model_message.get_timestamp())
Beispiel #7
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 + "'.")))
Beispiel #8
0
 def test_get_input_model(self):
     self.assertEqual(len(ModelShipper.input_model), len(ModelShipper.get_input_model()))
     self.assertTrue(numpy.array_equal(ModelShipper.input_model.data, ModelShipper.get_input_model().data))
Beispiel #9
0
 def setUp(self):
     ModelShipper.input_model = ModelShipper.load_stl_model(path)
     ModelShipper.output_model = None
     ModelShipper.output_data_text = None
     ModelShipper.output_path = None
     ModelShipper.output_metadata_text = None