1 #include "common/common.hpp"
2 #include "common/lut.hpp"
3 #include "pool-update/pool-update.hpp"
4 #include "pool/package.hpp"
5 #include "pool/part.hpp"
6 #include "pool/pool.hpp"
7 #include "pool/symbol.hpp"
8 #include "pool/unit.hpp"
9 #include "util/util.hpp"
10 #include "util/uuid.hpp"
11 #include "frame/frame.hpp"
12 #include <fstream>
13 #include <giomm/file.h>
14 #include <giomm/init.h>
15 #include <glib/gstdio.h>
16 #include <glibmm.h>
17 #include <glibmm/datetime.h>
18 #include <iostream>
19 #include <memory>
20 #include <stdlib.h>
21 #include "nlohmann/json.hpp"
22 #include "pool/pool_manager.hpp"
23
status_cb(horizon::PoolUpdateStatus st,const std::string filename,const std::string msg)24 static void status_cb(horizon::PoolUpdateStatus st, const std::string filename, const std::string msg)
25 {
26 switch (st) {
27 case horizon::PoolUpdateStatus::DONE:
28 std::cout << "done: ";
29 break;
30 case horizon::PoolUpdateStatus::ERROR:
31 std::cout << "error: ";
32 break;
33 case horizon::PoolUpdateStatus::FILE:
34 std::cout << "file: ";
35 break;
36 case horizon::PoolUpdateStatus::FILE_ERROR:
37 std::cout << "file error: ";
38 break;
39 case horizon::PoolUpdateStatus::INFO:
40 std::cout << "info: ";
41 break;
42 }
43 std::cout << msg << " file: " << filename << std::endl;
44 }
45
main(int c_argc,char * c_argv[])46 int main(int c_argc, char *c_argv[])
47 {
48 Gio::init();
49 horizon::PoolManager::init();
50
51 std::vector<std::string> argv;
52 for (int i = 0; i < c_argc; i++) {
53 argv.emplace_back(c_argv[i]);
54 }
55 auto pool_base_path = Gio::File::create_for_path(Glib::getenv("HORIZON_POOL"))->get_path();
56
57 if (argv.size() <= 1) {
58 std::cout << "Usage: " << argv.at(0) << " <command> args" << std::endl << std::endl;
59 std::cout << "Available commands :" << std::endl;
60 std::cout << "\tcreate-symbol <symbol file> <unit file>" << std::endl;
61 std::cout << "\tcreate-package <package folder>" << std::endl;
62 std::cout << "\tcreate-padstack <padstack file>" << std::endl;
63 std::cout << "\tcreate-frame <frame file>" << std::endl;
64 std::cout << "\tupdate" << std::endl;
65 return 0;
66 }
67
68 else if (argv.at(1) == "create-symbol") {
69 if (argv.size() >= 4) {
70 const auto &filename_sym = argv.at(2);
71 const auto &filename_unit = argv.at(3);
72
73 horizon::Symbol sym(horizon::UUID::random());
74 auto unit = horizon::Unit::new_from_file(filename_unit);
75 sym.unit = &unit;
76 horizon::save_json_to_file(filename_sym, sym.serialize());
77 }
78 else {
79 std::cout << "Usage: " << argv.at(0) << " create-symbol <symbol file> <unit file>" << std::endl;
80 }
81 }
82
83 else if (argv.at(1) == "create-package") {
84 if (argv.size() >= 3) {
85 auto &base_path = argv.at(2);
86 {
87 auto fi = Gio::File::create_for_path(Glib::build_filename(base_path, "padstacks"));
88 fi->make_directory_with_parents();
89 }
90 auto pkg_filename = Glib::build_filename(base_path, "package.json");
91 horizon::Package pkg(horizon::UUID::random());
92 auto j = pkg.serialize();
93 horizon::save_json_to_file(pkg_filename, j);
94 }
95 else {
96 std::cout << "Usage: " << argv.at(0) << " create-package <package folder>" << std::endl;
97 }
98 }
99
100 else if (argv.at(1) == "create-padstack") {
101 if (argv.size() >= 3) {
102 horizon::Padstack ps(horizon::UUID::random());
103 auto j = ps.serialize();
104 horizon::save_json_to_file(argv.at(2), j);
105 }
106 else {
107 std::cout << "Usage: " << argv.at(0) << " create-padstack <padstack file>" << std::endl;
108 }
109 }
110
111 else if (argv.at(1) == "create-frame") {
112 if (argv.size() >= 3) {
113 horizon::Frame fr(horizon::UUID::random());
114 auto j = fr.serialize();
115 horizon::save_json_to_file(argv.at(2), j);
116 }
117 else {
118 std::cout << "Usage: " << argv.at(0) << " create-frame <frame file>" << std::endl;
119 }
120 }
121
122 else if (argv.at(1) == "update") {
123 horizon::pool_update(pool_base_path, status_cb);
124 }
125
126 return 0;
127 }
128