mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-10-22 08:11:11 -06:00
GCode Preview - New Layout
This commit is contained in:
parent
c550ad2268
commit
787a5f1715
7 changed files with 202 additions and 31 deletions
|
@ -177,6 +177,8 @@ add_library(libslic3r_gui STATIC
|
|||
${LIBDIR}/slic3r/GUI/PresetHints.hpp
|
||||
${LIBDIR}/slic3r/GUI/GUI.cpp
|
||||
${LIBDIR}/slic3r/GUI/GUI.hpp
|
||||
${LIBDIR}/slic3r/GUI/wxExtensions.cpp
|
||||
${LIBDIR}/slic3r/GUI/wxExtensions.hpp
|
||||
)
|
||||
|
||||
add_library(admesh STATIC
|
||||
|
|
|
@ -5,6 +5,9 @@
|
|||
#include <boost/algorithm/string/predicate.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
#include <boost/algorithm/string/split.hpp>
|
||||
#include <boost/algorithm/string/classification.hpp>
|
||||
|
||||
#if __APPLE__
|
||||
#import <IOKit/pwr_mgt/IOPMLib.h>
|
||||
#elif _WIN32
|
||||
|
@ -20,6 +23,9 @@
|
|||
#include <wx/notebook.h>
|
||||
#include <wx/panel.h>
|
||||
#include <wx/sizer.h>
|
||||
#include <wx/combo.h>
|
||||
|
||||
#include "slic3r/gui/wxextensions.hpp"
|
||||
|
||||
namespace Slic3r { namespace GUI {
|
||||
|
||||
|
@ -183,4 +189,46 @@ void create_preset_tab(const char *name)
|
|||
g_wxTabPanel->AddPage(panel, name);
|
||||
}
|
||||
|
||||
void create_combochecklist(wxComboCtrl* comboCtrl, std::string text, std::string items, bool initial_value)
|
||||
{
|
||||
wxCheckListBoxComboPopup* popup = new wxCheckListBoxComboPopup(-1);
|
||||
if (popup != nullptr)
|
||||
{
|
||||
comboCtrl->SetPopupControl(popup);
|
||||
popup->SetStringValue(text);
|
||||
popup->Connect(-1, wxEVT_CHECKLISTBOX, wxCommandEventHandler(wxCheckListBoxComboPopup::OnCheckListBox), nullptr, popup);
|
||||
popup->Connect(-1, wxEVT_LISTBOX, wxCommandEventHandler(wxCheckListBoxComboPopup::OnListBoxSelection), nullptr, popup);
|
||||
|
||||
std::vector<std::string> items_str;
|
||||
boost::split(items_str, items, boost::is_any_of("|"), boost::token_compress_off);
|
||||
|
||||
for (const std::string& item : items_str)
|
||||
{
|
||||
popup->Append(item);
|
||||
}
|
||||
|
||||
for (unsigned int i = 0; i < popup->GetCount(); ++i)
|
||||
{
|
||||
popup->Check(i, initial_value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int combochecklist_get_flags(wxComboCtrl* comboCtrl)
|
||||
{
|
||||
int flags = 0;
|
||||
|
||||
wxCheckListBoxComboPopup* popup = wxDynamicCast(comboCtrl->GetPopupControl(), wxCheckListBoxComboPopup);
|
||||
if (popup != nullptr)
|
||||
{
|
||||
for (unsigned int i = 0; i < popup->GetCount(); ++i)
|
||||
{
|
||||
if (popup->IsChecked(i))
|
||||
flags += (int)std::pow(2.0f, (float)i);
|
||||
}
|
||||
}
|
||||
|
||||
return flags;
|
||||
}
|
||||
|
||||
} }
|
||||
|
|
|
@ -8,6 +8,7 @@ class wxApp;
|
|||
class wxFrame;
|
||||
class wxMenuBar;
|
||||
class wxNotebook;
|
||||
class wxComboCtrl;
|
||||
|
||||
namespace Slic3r { namespace GUI {
|
||||
|
||||
|
@ -27,6 +28,16 @@ void add_debug_menu(wxMenuBar *menu);
|
|||
// add it at the end of the tab panel.
|
||||
void create_preset_tab(const char *name);
|
||||
|
||||
} }
|
||||
// Creates a wxCheckListBoxComboPopup inside the given wxComboCtrl, filled with the given text and items.
|
||||
// Items are all initialized to the given value.
|
||||
// Items must be separated by '|', for example "Item1|Item2|Item3", and so on.
|
||||
void create_combochecklist(wxComboCtrl* comboCtrl, std::string text, std::string items, bool initial_value);
|
||||
|
||||
// Returns the current state of the items listed in the wxCheckListBoxComboPopup contained in the given wxComboCtrl,
|
||||
// encoded inside an int.
|
||||
int combochecklist_get_flags(wxComboCtrl* comboCtrl);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
74
xs/src/slic3r/GUI/wxExtensions.cpp
Normal file
74
xs/src/slic3r/GUI/wxExtensions.cpp
Normal file
|
@ -0,0 +1,74 @@
|
|||
#include "wxExtensions.hpp"
|
||||
|
||||
const unsigned int wxCheckListBoxComboPopup::Height = 200;
|
||||
|
||||
wxCheckListBoxComboPopup::wxCheckListBoxComboPopup(wxWindowID id)
|
||||
: m_id(id)
|
||||
, m_text(wxEmptyString)
|
||||
{
|
||||
}
|
||||
|
||||
bool wxCheckListBoxComboPopup::Create(wxWindow* parent)
|
||||
{
|
||||
return wxCheckListBox::Create(parent, m_id, wxPoint(0, 0));
|
||||
}
|
||||
|
||||
wxWindow* wxCheckListBoxComboPopup::GetControl()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
void wxCheckListBoxComboPopup::SetStringValue(const wxString& value)
|
||||
{
|
||||
m_text = value;
|
||||
}
|
||||
|
||||
wxString wxCheckListBoxComboPopup::GetStringValue() const
|
||||
{
|
||||
return m_text;
|
||||
}
|
||||
|
||||
wxSize wxCheckListBoxComboPopup::GetAdjustedSize(int minWidth, int prefHeight, int maxHeight)
|
||||
{
|
||||
// matches owner wxComboCtrl's width
|
||||
|
||||
wxComboCtrl* cmb = GetComboCtrl();
|
||||
if (cmb != nullptr)
|
||||
{
|
||||
wxSize size = GetComboCtrl()->GetSize();
|
||||
size.SetHeight(Height);
|
||||
return size;
|
||||
}
|
||||
else
|
||||
return wxSize(200, Height);
|
||||
}
|
||||
|
||||
void wxCheckListBoxComboPopup::OnCheckListBox(wxCommandEvent& evt)
|
||||
{
|
||||
// forwards the checklistbox event to the owner wxComboCtrl
|
||||
|
||||
wxComboCtrl* cmb = GetComboCtrl();
|
||||
if (cmb != nullptr)
|
||||
{
|
||||
wxCommandEvent event(wxEVT_CHECKLISTBOX, cmb->GetId());
|
||||
cmb->ProcessWindowEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
void wxCheckListBoxComboPopup::OnListBoxSelection(wxCommandEvent& evt)
|
||||
{
|
||||
// transforms list box item selection event into checklistbox item toggle event
|
||||
|
||||
int selId = GetSelection();
|
||||
if (selId != wxNOT_FOUND)
|
||||
{
|
||||
Toggle((unsigned int)selId);
|
||||
SetSelection(wxNOT_FOUND);
|
||||
|
||||
wxCommandEvent event(wxEVT_CHECKLISTBOX, GetId());
|
||||
event.SetInt(selId);
|
||||
event.SetEventObject(this);
|
||||
event.SetString(GetString(selId));
|
||||
ProcessEvent(event);
|
||||
}
|
||||
}
|
27
xs/src/slic3r/GUI/wxExtensions.hpp
Normal file
27
xs/src/slic3r/GUI/wxExtensions.hpp
Normal file
|
@ -0,0 +1,27 @@
|
|||
#ifndef slic3r_GUI_wxExtensions_hpp_
|
||||
#define slic3r_GUI_wxExtensions_hpp_
|
||||
|
||||
#include <wx/checklst.h>
|
||||
#include <wx/combo.h>
|
||||
|
||||
class wxCheckListBoxComboPopup : public wxCheckListBox, public wxComboPopup
|
||||
{
|
||||
static const unsigned int Height;
|
||||
|
||||
wxWindowID m_id;
|
||||
wxString m_text;
|
||||
|
||||
public:
|
||||
explicit wxCheckListBoxComboPopup(wxWindowID id);
|
||||
|
||||
virtual bool Create(wxWindow* parent);
|
||||
virtual wxWindow* GetControl();
|
||||
virtual void SetStringValue(const wxString& value);
|
||||
virtual wxString GetStringValue() const;
|
||||
virtual wxSize GetAdjustedSize(int minWidth, int prefHeight, int maxHeight);
|
||||
|
||||
void OnCheckListBox(wxCommandEvent& evt);
|
||||
void OnListBoxSelection(wxCommandEvent& evt);
|
||||
};
|
||||
|
||||
#endif // slic3r_GUI_wxExtensions_hpp_
|
|
@ -37,3 +37,10 @@ void add_debug_menu(SV *ui)
|
|||
|
||||
void create_preset_tab(const char *name)
|
||||
%code%{ Slic3r::GUI::create_preset_tab(name); %};
|
||||
|
||||
void create_combochecklist(SV *ui, std::string text, std::string items, bool initial_value)
|
||||
%code%{ Slic3r::GUI::create_combochecklist((wxComboCtrl*)wxPli_sv_2_object(aTHX_ ui, "Wx::ComboCtrl"), text, items, initial_value); %};
|
||||
|
||||
int combochecklist_get_flags(SV *ui)
|
||||
%code%{ RETVAL=Slic3r::GUI::combochecklist_get_flags((wxComboCtrl*)wxPli_sv_2_object(aTHX_ ui, "Wx::ComboCtrl")); %};
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue