mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-09-15 13:07:33 +00:00
Better safety if publish workflow crashes. Cleanup on Button
This commit is contained in:
@@ -16323,9 +16323,11 @@ int Plater::export_published_3mf(const std::vector<std::string>& published_keys,
|
|||||||
if (full_pathnames)
|
if (full_pathnames)
|
||||||
save_strategy = save_strategy | SaveStrategy::FullPathSources;
|
save_strategy = save_strategy | SaveStrategy::FullPathSources;
|
||||||
|
|
||||||
const int ret = export_3mf(into_path(path), save_strategy, -1, nullptr);
|
// Restore the previous metadata state (both on success and on failure): a thrown export
|
||||||
|
// must not leave the published metadata on the in-memory project, or a later Save Project
|
||||||
// Restore the previous metadata state (both on success and on failure).
|
// would write a hybrid file (full config + slicer tags + published metadata) that receivers
|
||||||
|
// silently load in published mode, skipping the project's own presets.
|
||||||
|
auto restore_metadata = [&]() {
|
||||||
if (!had_model_info) {
|
if (!had_model_info) {
|
||||||
model.model_info = nullptr;
|
model.model_info = nullptr;
|
||||||
} else {
|
} else {
|
||||||
@@ -16346,6 +16348,18 @@ int Plater::export_published_3mf(const std::vector<std::string>& published_keys,
|
|||||||
else
|
else
|
||||||
model.model_info->metadata_items.erase("published_config");
|
model.model_info->metadata_items.erase("published_config");
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
int ret;
|
||||||
|
try {
|
||||||
|
ret = export_3mf(into_path(path), save_strategy, -1, nullptr);
|
||||||
|
} catch (...) {
|
||||||
|
restore_metadata();
|
||||||
|
MessageDialog(this, _L("Failed to export the published 3MF file.\nPlease check whether the folder exists online or if other programs have the file open."),
|
||||||
|
_L("Publish"), wxOK | wxICON_WARNING).ShowModal();
|
||||||
|
return wxID_CANCEL;
|
||||||
|
}
|
||||||
|
restore_metadata();
|
||||||
|
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
MessageDialog(this, _L("Failed to export the published 3MF file.\nPlease check whether the folder exists online or if other programs have the file open."),
|
MessageDialog(this, _L("Failed to export the published 3MF file.\nPlease check whether the folder exists online or if other programs have the file open."),
|
||||||
|
|||||||
@@ -80,7 +80,6 @@ bool Button::SetFont(const wxFont& font)
|
|||||||
|
|
||||||
void Button::SetIcon(const wxString& icon)
|
void Button::SetIcon(const wxString& icon)
|
||||||
{
|
{
|
||||||
custom_icon = wxNullBitmap;
|
|
||||||
auto tmpBitmap = ScalableBitmap(this, icon.ToStdString(), this->active_icon.px_cnt());
|
auto tmpBitmap = ScalableBitmap(this, icon.ToStdString(), this->active_icon.px_cnt());
|
||||||
if (!icon.IsEmpty()) {
|
if (!icon.IsEmpty()) {
|
||||||
//BBS set button icon default size to 20
|
//BBS set button icon default size to 20
|
||||||
@@ -104,13 +103,6 @@ void Button::SetIcon(const wxBitmap& icon)
|
|||||||
Refresh();
|
Refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Button::SetBitmap(const wxBitmap& bitmap)
|
|
||||||
{
|
|
||||||
custom_icon = bitmap;
|
|
||||||
messureSize();
|
|
||||||
Refresh();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Button::SetMinSize(const wxSize& size)
|
void Button::SetMinSize(const wxSize& size)
|
||||||
{
|
{
|
||||||
minSize = size;
|
minSize = size;
|
||||||
@@ -310,8 +302,7 @@ void Button::render(wxDC& dc)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
auto szContent = textSize;
|
auto szContent = textSize;
|
||||||
const bool has_custom_icon = custom_icon.IsOk();
|
if (icon.bmp().IsOk()) {
|
||||||
if (has_custom_icon || icon.bmp().IsOk()) {
|
|
||||||
if (szContent.y > 0) {
|
if (szContent.y > 0) {
|
||||||
//BBS norrow size between text and icon
|
//BBS norrow size between text and icon
|
||||||
if (vertical)
|
if (vertical)
|
||||||
@@ -319,7 +310,7 @@ void Button::render(wxDC& dc)
|
|||||||
else
|
else
|
||||||
szContent.x += spacing;
|
szContent.x += spacing;
|
||||||
}
|
}
|
||||||
szIcon = has_custom_icon ? custom_icon.GetSize() : icon.GetBmpSize();
|
szIcon = icon.GetBmpSize();
|
||||||
if (vertical) {
|
if (vertical) {
|
||||||
szContent.y += szIcon.y;
|
szContent.y += szIcon.y;
|
||||||
if (szIcon.x > szContent.x) szContent.x = szIcon.x;
|
if (szIcon.x > szContent.x) szContent.x = szIcon.x;
|
||||||
@@ -342,12 +333,12 @@ void Button::render(wxDC& dc)
|
|||||||
}
|
}
|
||||||
// start draw
|
// start draw
|
||||||
wxPoint pt = rcContent.GetLeftTop();
|
wxPoint pt = rcContent.GetLeftTop();
|
||||||
if (has_custom_icon || icon.bmp().IsOk()) {
|
if (icon.bmp().IsOk()) {
|
||||||
if (vertical)
|
if (vertical)
|
||||||
pt.x += (rcContent.width - szIcon.x) / 2;
|
pt.x += (rcContent.width - szIcon.x) / 2;
|
||||||
else
|
else
|
||||||
pt.y += (rcContent.height - szIcon.y) / 2;
|
pt.y += (rcContent.height - szIcon.y) / 2;
|
||||||
dc.DrawBitmap(has_custom_icon ? custom_icon : icon.bmp(), pt);
|
dc.DrawBitmap(icon.bmp(), pt);
|
||||||
//BBS norrow size between text and icon
|
//BBS norrow size between text and icon
|
||||||
if (vertical) {
|
if (vertical) {
|
||||||
pt.y += szIcon.y + spacing;
|
pt.y += szIcon.y + spacing;
|
||||||
@@ -380,7 +371,7 @@ void Button::messureSize()
|
|||||||
wxClientDC dc(this);
|
wxClientDC dc(this);
|
||||||
dc.GetTextExtent(GetLabel(), &textSize.width, &textSize.height, &textSize.x, &textSize.y);
|
dc.GetTextExtent(GetLabel(), &textSize.width, &textSize.height, &textSize.x, &textSize.y);
|
||||||
wxSize szContent = textSize.GetSize();
|
wxSize szContent = textSize.GetSize();
|
||||||
if (custom_icon.IsOk() || this->active_icon.bmp().IsOk()) {
|
if (this->active_icon.bmp().IsOk()) {
|
||||||
if (szContent.y > 0) {
|
if (szContent.y > 0) {
|
||||||
//BBS norrow size between text and icon
|
//BBS norrow size between text and icon
|
||||||
if (vertical)
|
if (vertical)
|
||||||
@@ -388,7 +379,7 @@ void Button::messureSize()
|
|||||||
else
|
else
|
||||||
szContent.x += 5;
|
szContent.x += 5;
|
||||||
}
|
}
|
||||||
wxSize szIcon = custom_icon.IsOk() ? custom_icon.GetSize() : this->active_icon.GetBmpSize();
|
wxSize szIcon = this->active_icon.GetBmpSize();
|
||||||
if (vertical) {
|
if (vertical) {
|
||||||
szContent.y += szIcon.y;
|
szContent.y += szIcon.y;
|
||||||
if (szIcon.x > szContent.x) szContent.x = szIcon.x;
|
if (szIcon.x > szContent.x) szContent.x = szIcon.x;
|
||||||
|
|||||||
@@ -36,7 +36,6 @@ class Button : public StaticBox
|
|||||||
wxSize minSize; // set by outer
|
wxSize minSize; // set by outer
|
||||||
wxSize paddingSize;
|
wxSize paddingSize;
|
||||||
ScalableBitmap active_icon;
|
ScalableBitmap active_icon;
|
||||||
wxBitmap custom_icon;
|
|
||||||
|
|
||||||
StateColor text_color;
|
StateColor text_color;
|
||||||
|
|
||||||
@@ -63,8 +62,6 @@ public:
|
|||||||
void SetIcon(const wxString& icon);
|
void SetIcon(const wxString& icon);
|
||||||
void SetIcon(const wxBitmap& icon);
|
void SetIcon(const wxBitmap& icon);
|
||||||
|
|
||||||
void SetBitmap(const wxBitmap& bitmap);
|
|
||||||
|
|
||||||
void SetMinSize(const wxSize& size) override;
|
void SetMinSize(const wxSize& size) override;
|
||||||
void SetMaxSize(const wxSize& size) override;
|
void SetMaxSize(const wxSize& size) override;
|
||||||
|
|
||||||
|
|||||||
@@ -182,7 +182,7 @@ void TabCtrl::SetItemBitmap(unsigned int item, const wxBitmap& bitmap)
|
|||||||
{
|
{
|
||||||
if (item >= btns.size())
|
if (item >= btns.size())
|
||||||
return;
|
return;
|
||||||
btns[item]->SetBitmap(bitmap);
|
btns[item]->SetIcon(bitmap);
|
||||||
relayout();
|
relayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -64,6 +64,9 @@ public:
|
|||||||
int GetNextVisible(int item) const;
|
int GetNextVisible(int item) const;
|
||||||
bool IsVisible(unsigned int item) const;
|
bool IsVisible(unsigned int item) const;
|
||||||
|
|
||||||
|
// Width of the tab strip that keeps every button visible (used to size the Publish dialog).
|
||||||
|
int buttons_best_width() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual void DoSetSize(int x, int y, int width, int height, int sizeFlags = wxSIZE_AUTO);
|
virtual void DoSetSize(int x, int y, int width, int height, int sizeFlags = wxSIZE_AUTO);
|
||||||
|
|
||||||
@@ -73,8 +76,6 @@ private:
|
|||||||
|
|
||||||
void relayout();
|
void relayout();
|
||||||
|
|
||||||
int buttons_best_width() const;
|
|
||||||
|
|
||||||
void buttonClicked(wxCommandEvent & event);
|
void buttonClicked(wxCommandEvent & event);
|
||||||
void keyDown(wxKeyEvent &event);
|
void keyDown(wxKeyEvent &event);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user