Пример #1
0
    def _write_to_file(self, _file_abs_path=None):
        """

        :return:
        """
        if _file_abs_path is not None:
            self._file_abs_path = _file_abs_path

        #   number of coordinates and velocities of MBD system
        if self.MBD_item.typeInfo() == "MBDsystem":
            if self.solution_data.ndim == 2:
                [steps, self.cols] = np.shape(self.solution_data)
            else:
                steps = 0
                self.cols = len(self.solution_data)
                self.solution_data = np.array([self.solution_data])

        #   check filename
        if self._file_abs_path is None:
            self._filename = self._name + self._filetype
        else:
            self._filename = self._file_abs_path

        if self._filetype not in self._filename:
            self._filename = self._filename + self._filetype

        if type(self._filename) == QtCore.QString:
            self._filename = str(self._filename)
        else:
            if self._solution_save_options == "save to new":
                self._filename = check_filename(self._filename)

        #   save to file of selected type
        if self._filetype == ".dat" or self._filetype == ".sol":
            self._write_to_txt_file()

        elif self._filetype == ".xlsx":
            self._write_to_excel_file()

        elif self._filetype == ".csv":
            self._read_csv_file()

        else:
            raise ValueError, "Filetype not supported."

        self.simulation_status = "saved to file"

        #   write info to log file
        logging.getLogger("DyS_logger").info(
            "Solution data saved to file: %s. Size is %s", self._filename,
            convert_bytes_to_.convert_size(os.path.getsize(self._filename)))
Пример #2
0
    def saveFile(self):
        """
        Save MBD system object to file
        """
        if not self.MBD_system.saved:
            #   file dialog
            file_dialog = QtGui.QFileDialog()
            file_dialog.setFileMode(QtGui.QFileDialog.ExistingFiles)

            self.MBD_file_abs_path = file_dialog.getSaveFileName(self,
                                                    caption=QtCore.QString("Save file"),
                                                    directory=QtCore.QString(self.MBD_folder_abs_path),
                                                    filter=QtCore.QString(self._file_types))

            self.MBD_file_abs_path = str(self.MBD_file_abs_path)

        if self.MBD_file_abs_path:
            with open(self.MBD_file_abs_path, "wb") as _file:
                save_data = self.MBD_system
                # pickle.dump(MBD_system, save, -1)
                dill.dump(save_data, _file)

                _file.close()
                self.MBD_system.saved = True

                logging.getLogger("DyS_logger").info("Project saved to file: %s. Size is %s", self.MBD_file_abs_path, convert_bytes_to_.convert_size(os.path.getsize(self.MBD_file_abs_path)))
Пример #3
0
    def write_to_file(self, _file_abs_path=None):
        """
        Function saves data to file

        :param _file_abs_path:
        """
        print "write_to_file()"
        if _file_abs_path != None:
            self._file_abs_path = _file_abs_path

        #   number of coordinates and velocities of MBD system
        [steps, n] = np.shape(self.solution_data)
        self.n = n - self.__header0_size

        #   nuimber of bodies
        self.n_b = self.n / 6.

        #   create header ids
        self._header_ids = np.arange(0, self.n_b)

        #   check filename
        #   check filename
        if self._file_abs_path is None:
            self._filename = self._name+self._filetype
        else:
            self._filename = self._file_abs_path

        if self._filetype not in self._filename:
            self._filename = self._filename + self._filetype
        

        if type(self._filename) == QtCore.QString: 
            self._filename = str(self._filename)
        else:
            self._filename = check_filename(self._filename)

        #   save to file of selected type
        if self._filetype == ".dat" or self._filetype == ".sol":
            data = self._write_to_txt_file()
        elif self._filetype == ".xlsx":
            data = self._write_to_excel_file()
        elif self._filetype == ".csv":
            data = self._read_csv_file()
        else:
            raise ValueError, "Filetype not supported."

        self.simulation_status = "saved to file"

        #   write info to log file
        logging.getLogger("DyS_logger").info("Solution data saved to file: %s. Size is %s", self._filename, convert_bytes_to_.convert_size(os.path.getsize(self._filename)))
Пример #4
0
    def saveFile(self):
        """
        Save MBD system object to file
        """
        if not self.MBD_system.saved:
            #   file dialog
            file_dialog = QtGui.QFileDialog()
            file_dialog.setFileMode(QtGui.QFileDialog.ExistingFiles)

            self.MBD_file_abs_path = file_dialog.getSaveFileName(self,
                                                    caption=QtCore.QString("Save file"),
                                                    directory=QtCore.QString(self.MBD_folder_abs_path),
                                                    filter=QtCore.QString(self._file_types))

            self.MBD_file_abs_path = str(self.MBD_file_abs_path)

        if self.MBD_file_abs_path:
            with open(self.MBD_file_abs_path, "wb") as _file:
                save_data = self.MBD_system
                # pickle.dump(MBD_system, save, -1)
                dill.dump(save_data, _file)

                _file.close()
                self.MBD_system.saved = True

                logging.getLogger("DyS_logger").info("Project saved to file: %s. Size is %s", self.MBD_file_abs_path, convert_bytes_to_.convert_size(os.path.getsize(self.MBD_file_abs_path)))