187{
188 if (wxTheApp == nullptr || wxGetApp().is_closing() ||
190 return;
191
194
196 m_reload_task = std::make_unique<boost::thread>([
this, cancel_token] {
197 if (cancel_token->load(std::memory_order_acquire) || wxTheApp == nullptr || wxGetApp().is_closing())
198 return;
199 std::string update_type;
200 std::string license;
201 std::string model_name;
202 std::string model_author;
203 std::string cover_file;
204 std::string description;
205 std::string p_name;
206 std::string p_author;
207 std::string p_description;
208 std::string p_cover_file;
209
210 std::map<std::string, std::vector<json>> files;
211
212 if (wxGetApp().
plater() ==
nullptr)
213 return;
214
215 Model model = wxGetApp().plater()->model();
216
217 auto model_info = model.model_info;
218 if (model_info != nullptr) {
219 license = model_info->license;
220 model_name = model_info->model_name;
221 cover_file = model_info->cover_file;
222 description = model_info->description;
223 update_type = model_info->origin;
224
225 try {
226 if (!model_info->copyright.empty()) {
227 json copy_right = json::parse(model_info->copyright);
228
229 if (copy_right.is_array()) {
230 for (auto it = copy_right.begin(); it != copy_right.end(); it++) {
231 if ((*it).contains("author")) {
232 model_author = (*it)["author"].get<std::string>();
233 }
234 }
235 }
236 }
237 } catch (...) {
238 ;
239 }
240 }
241
242 if (model_author.empty() && model.design_info != nullptr)
243 model_author = model.design_info->Designer;
244
245 if (model.profile_info != nullptr) {
246 p_name = model.profile_info->ProfileTile;
247 p_description = model.profile_info->ProfileDescription;
248 p_cover_file = model.profile_info->ProfileCover;
249 p_author = model.profile_info->ProfileUserName;
250 }
251
252
253 std::string file_path =
encode_path(wxGetApp().
plater()->model().get_auxiliary_file_temp_path().c_str());
254 if (!file_path.empty()) {
255 files =
Reload(file_path);
256 if (cancel_token->load(std::memory_order_acquire) || wxTheApp == nullptr || wxGetApp().is_closing())
257 return;
258
259 wxGetApp().CallAfter([this, cancel_token, file_path, files] {
260 if (cancel_token->load(std::memory_order_acquire) || wxTheApp == nullptr || wxGetApp().is_closing())
261 return;
263 });
264 } else {
266 return;
267 }
268
269 bool has_content = false;
270 for (const std::string& v : {
271 update_type,
272 license,
273 model_name,
274 model_author,
275 cover_file,
276 description,
277 p_name,
278 p_author,
279 p_description,
280 p_cover_file,
281 }) {
282 if (!v.empty()) {
283 has_content = true;
284 break;
285 }
286 }
287 if (!has_content) {
288 for (const auto & file : files) {
289 if (!file.second.empty()) {
290 has_content = true;
291 break;
292 }
293 }
294 }
295 if (!has_content) {
296
298 return;
299 }
300
302 j["model"]["license"] = license;
303 j["model"]["name"] = wxGetApp().url_encode(model_name);
304 j["model"]["author"] = wxGetApp().url_encode(model_author);;
305 j["model"]["cover_img"] = wxGetApp().url_encode(cover_file);
307 j["model"]["preview_img"] = files["Model Pictures"];
308 j["model"]["upload_type"] = update_type;
309
310 j["file"]["BOM"] = files["Bill of Materials"];
311 j["file"]["Assembly"] = files["Assembly Guide"];
312 j["file"]["Other"] = files["Others"];
313
314 j["profile"]["name"] = wxGetApp().url_encode(p_name);
315 j["profile"]["author"] = wxGetApp().url_encode(p_author);
316 j["profile"]["description"] = wxGetApp().url_encode(p_description);
317 j["profile"]["cover_img"] = wxGetApp().url_encode(p_cover_file);
318 j["profile"]["preview_img"] = files["Profile Pictures"];
319
320 json m_Res = json::object();
321 m_Res["command"] = "show_3mf_info";
323 m_Res["model"] = j;
324
325 wxString strJS = wxString::Format("HandleStudio(%s)", m_Res.dump(-1, ' ', false, json::error_handler_t::ignore));
326
327 if (!cancel_token->load(std::memory_order_acquire) && wxTheApp != nullptr && !wxGetApp().is_closing()) {
328 wxGetApp().CallAfter([this, cancel_token, strJS] {
329 if (cancel_token->load(std::memory_order_acquire) || wxTheApp == nullptr || wxGetApp().is_closing())
330 return;
334 });
335 }
336 });
337}
std::atomic< bool > m_web_init_completed
Definition Project.hpp:73
std::map< std::string, std::vector< nlohmann::json > > Reload(wxString aux_path)
Definition Project.cpp:441
void clear_model_info()
Definition Project.cpp:419
std::unique_ptr< boost::thread > m_reload_task
Definition Project.hpp:76
static Plater * plater()
Definition GUI_Factories.cpp:400
static std::string convert_newlines_to_br(const std::string &text)
Definition Project.cpp:164
std::string encode_path(const char *src)
Definition utils.cpp:1382