You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

161 lines
4.4 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2024 Mark Roszko <mark.roszko@gmail.com>
  5. * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
  6. *
  7. * This program is free software: you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by the
  9. * Free Software Foundation, either version 3 of the License, or (at your
  10. * option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License along
  18. * with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #ifndef JOBS_FILE_H
  21. #define JOBS_FILE_H
  22. #include <bitmaps/bitmaps_list.h>
  23. #include <jobs/job.h>
  24. #include <jobs/jobs_output.h>
  25. #include <settings/json_settings.h>
  26. #include <settings/parameters.h>
  27. #include <ctime>
  28. #include <memory>
  29. class REPORTER;
  30. struct KICOMMON_API JOBSET_JOB
  31. {
  32. JOBSET_JOB() :
  33. m_job( nullptr )
  34. {}
  35. JOBSET_JOB( const wxString& id, const wxString& type, JOB* job ) :
  36. m_id( id ),
  37. m_type( type ),
  38. m_job( job )
  39. {}
  40. wxString m_id;
  41. wxString m_type;
  42. wxString m_description;
  43. std::shared_ptr<JOB> m_job;
  44. wxString GetDescription() const;
  45. void SetDescription( const wxString& aDescription );
  46. bool operator==( const JOBSET_JOB& rhs ) const;
  47. };
  48. enum class KICOMMON_API JOBSET_OUTPUT_TYPE
  49. {
  50. FOLDER,
  51. ARCHIVE
  52. };
  53. struct KICOMMON_API JOBSET_OUTPUT_TYPE_INFO
  54. {
  55. wxString name;
  56. BITMAPS bitmap;
  57. bool outputPathIsFolder;
  58. wxString fileWildcard;
  59. };
  60. extern KICOMMON_API std::map<JOBSET_OUTPUT_TYPE, JOBSET_OUTPUT_TYPE_INFO> JobsetOutputTypeInfos;
  61. struct KICOMMON_API JOBSET_OUTPUT
  62. {
  63. JOBSET_OUTPUT();
  64. JOBSET_OUTPUT( const wxString& id, JOBSET_OUTPUT_TYPE type );
  65. ~JOBSET_OUTPUT();
  66. void InitOutputHandler();
  67. wxString m_id;
  68. JOBSET_OUTPUT_TYPE m_type;
  69. wxString m_description;
  70. JOBS_OUTPUT_HANDLER* m_outputHandler;
  71. std::vector<wxString> m_only;
  72. wxString GetDescription() const;
  73. void SetDescription( const wxString& aDescription );
  74. ///< Transient property, not stored for now
  75. std::optional<bool> m_lastRunSuccess;
  76. std::unordered_map<wxString, std::optional<bool>> m_lastRunSuccessMap;
  77. std::unordered_map<wxString, REPORTER*> m_lastRunReporters;
  78. bool operator==( const JOBSET_OUTPUT& rhs ) const;
  79. };
  80. class KICOMMON_API JOBSET : public JSON_SETTINGS
  81. {
  82. public:
  83. JOBSET( const wxString& aFilename );
  84. virtual ~JOBSET() {}
  85. std::vector<JOBSET_JOB>& GetJobs()
  86. {
  87. return m_jobs;
  88. }
  89. std::vector<JOBSET_JOB> GetJobsForOutput( JOBSET_OUTPUT* aOutput );
  90. std::vector<JOBSET_OUTPUT>& GetOutputs() { return m_outputs; }
  91. JOBSET_OUTPUT* GetOutput( wxString& aOutput );
  92. bool SaveToFile( const wxString& aDirectory = "", bool aForce = false ) override;
  93. void SetDirty( bool aFlag = true ) { m_dirty = aFlag; }
  94. bool GetDirty() const { return m_dirty; }
  95. wxString GetFullName() const { return m_fileNameWithoutPath; }
  96. void AddNewJob( wxString aType, JOB* aJob );
  97. JOBSET_OUTPUT* AddNewJobOutput( JOBSET_OUTPUT_TYPE aType );
  98. void RemoveOutput( JOBSET_OUTPUT* aOutput );
  99. void MoveJobUp( size_t aJobIdx );
  100. void MoveJobDown( size_t aJobIdx );
  101. void RemoveJob( size_t aJobIdx );
  102. protected:
  103. wxString getFileExt() const override;
  104. private:
  105. std::vector<JOBSET_JOB> m_jobs;
  106. std::vector<JOBSET_OUTPUT> m_outputs;
  107. bool m_dirty;
  108. wxString m_fileNameWithoutPath;
  109. };
  110. KICOMMON_API void to_json( nlohmann::json& j, const JOBSET_JOB& f );
  111. KICOMMON_API void from_json( const nlohmann::json& j, JOBSET_JOB& f );
  112. KICOMMON_API void to_json( nlohmann::json& j, const JOBSET_OUTPUT& f );
  113. KICOMMON_API void from_json( const nlohmann::json& j, JOBSET_OUTPUT& f );
  114. #if defined( __MINGW32__ )
  115. template class KICOMMON_API PARAM_LIST<struct JOBSET_JOB>;
  116. template class KICOMMON_API PARAM_LIST<struct JOBSET_OUTPUT>;
  117. #else
  118. extern template class APIVISIBLE PARAM_LIST<JOBSET_JOB>;
  119. extern template class APIVISIBLE PARAM_LIST<JOBSET_OUTPUT>;
  120. #endif
  121. #endif