2018-02-02 11:38:35 +00:00
|
|
|
#ifndef slic3r_GUI_wxExtensions_hpp_
|
|
|
|
#define slic3r_GUI_wxExtensions_hpp_
|
|
|
|
|
|
|
|
#include <wx/checklst.h>
|
|
|
|
#include <wx/combo.h>
|
2018-04-06 11:37:00 +00:00
|
|
|
#include <wx/dataview.h>
|
2018-05-04 16:32:20 +00:00
|
|
|
#include <wx/dc.h>
|
2018-05-10 14:36:12 +00:00
|
|
|
#include <wx/collpane.h>
|
|
|
|
#include <wx/wupdlock.h>
|
|
|
|
#include <wx/button.h>
|
2018-08-21 00:03:10 +00:00
|
|
|
#include <wx/slider.h>
|
2018-05-10 14:36:12 +00:00
|
|
|
|
2018-05-04 16:32:20 +00:00
|
|
|
#include <vector>
|
|
|
|
#include <set>
|
2018-02-02 11:38:35 +00:00
|
|
|
|
|
|
|
class wxCheckListBoxComboPopup : public wxCheckListBox, public wxComboPopup
|
|
|
|
{
|
2018-02-20 13:25:40 +00:00
|
|
|
static const unsigned int DefaultWidth;
|
|
|
|
static const unsigned int DefaultHeight;
|
2018-02-20 13:44:00 +00:00
|
|
|
static const unsigned int DefaultItemHeight;
|
2018-02-02 11:38:35 +00:00
|
|
|
|
|
|
|
wxString m_text;
|
|
|
|
|
2018-05-17 08:23:02 +00:00
|
|
|
// Events sent on mouseclick are quite complex. Function OnListBoxSelection is supposed to pass the event to the checkbox, which works fine on
|
|
|
|
// Win. On OSX and Linux the events are generated differently - clicking on the checkbox square generates the event twice (and the square
|
|
|
|
// therefore seems not to respond).
|
|
|
|
// This enum is meant to save current state of affairs, i.e., if the event forwarding is ok to do or not. It is only used on Linux
|
|
|
|
// and OSX by some #ifdefs. It also stores information whether OnListBoxSelection is supposed to change the checkbox status,
|
|
|
|
// or if it changed status on its own already (which happens when the square is clicked). More comments in OnCheckListBox(...)
|
|
|
|
// There indeed is a better solution, maybe making a custom event used for the event passing to distinguish the original and passed message
|
|
|
|
// and blocking one of them on OSX and Linux. Feel free to refactor, but carefully test on all platforms.
|
|
|
|
enum class OnCheckListBoxFunction{
|
|
|
|
FreeToProceed,
|
|
|
|
RefuseToProceed,
|
|
|
|
WasRefusedLastTime
|
|
|
|
} m_check_box_events_status = OnCheckListBoxFunction::FreeToProceed;
|
|
|
|
|
|
|
|
|
2018-02-02 11:38:35 +00:00
|
|
|
public:
|
|
|
|
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);
|
|
|
|
|
2018-02-20 13:25:40 +00:00
|
|
|
virtual void OnKeyEvent(wxKeyEvent& evt);
|
|
|
|
|
2018-02-02 11:38:35 +00:00
|
|
|
void OnCheckListBox(wxCommandEvent& evt);
|
|
|
|
void OnListBoxSelection(wxCommandEvent& evt);
|
|
|
|
};
|
|
|
|
|
2018-04-06 11:37:00 +00:00
|
|
|
|
|
|
|
// *** wxDataViewTreeCtrlComboBox ***
|
|
|
|
|
|
|
|
class wxDataViewTreeCtrlComboPopup: public wxDataViewTreeCtrl, public wxComboPopup
|
|
|
|
{
|
|
|
|
static const unsigned int DefaultWidth;
|
|
|
|
static const unsigned int DefaultHeight;
|
|
|
|
static const unsigned int DefaultItemHeight;
|
|
|
|
|
|
|
|
wxString m_text;
|
2018-04-06 13:42:52 +00:00
|
|
|
int m_cnt_open_items{0};
|
2018-04-06 11:37:00 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
virtual bool Create(wxWindow* parent);
|
|
|
|
virtual wxWindow* GetControl() { return this; }
|
|
|
|
virtual void SetStringValue(const wxString& value) { m_text = value; }
|
|
|
|
virtual wxString GetStringValue() const { return m_text; }
|
2018-04-09 10:41:25 +00:00
|
|
|
// virtual wxSize GetAdjustedSize(int minWidth, int prefHeight, int maxHeight);
|
2018-04-06 11:37:00 +00:00
|
|
|
|
|
|
|
virtual void OnKeyEvent(wxKeyEvent& evt);
|
|
|
|
void OnDataViewTreeCtrlSelection(wxCommandEvent& evt);
|
2018-04-06 13:42:52 +00:00
|
|
|
void SetItemsCnt(int cnt) { m_cnt_open_items = cnt; }
|
2018-04-06 11:37:00 +00:00
|
|
|
};
|
|
|
|
|
2018-05-10 14:36:12 +00:00
|
|
|
|
|
|
|
|
2018-06-08 10:43:39 +00:00
|
|
|
// *** PrusaCollapsiblePane ***
|
2018-05-10 14:36:12 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
class PrusaCollapsiblePane : public wxCollapsiblePane
|
2018-06-08 10:43:39 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
PrusaCollapsiblePane() {}
|
|
|
|
PrusaCollapsiblePane(wxWindow *parent,
|
|
|
|
wxWindowID winid,
|
|
|
|
const wxString& label,
|
|
|
|
const wxPoint& pos = wxDefaultPosition,
|
|
|
|
const wxSize& size = wxDefaultSize,
|
|
|
|
long style = wxCP_DEFAULT_STYLE,
|
|
|
|
const wxValidator& val = wxDefaultValidator,
|
|
|
|
const wxString& name = wxCollapsiblePaneNameStr)
|
|
|
|
{
|
|
|
|
Create(parent, winid, label, pos, size, style, val, name);
|
|
|
|
}
|
|
|
|
~PrusaCollapsiblePane() {}
|
|
|
|
|
|
|
|
void OnStateChange(const wxSize& sz); //override/hide of OnStateChange from wxCollapsiblePane
|
|
|
|
virtual bool Show(bool show = true) override {
|
|
|
|
wxCollapsiblePane::Show(show);
|
|
|
|
OnStateChange(GetBestSize());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// *** PrusaCollapsiblePaneMSW *** used only #ifdef __WXMSW__
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
#ifdef __WXMSW__
|
|
|
|
class PrusaCollapsiblePaneMSW : public PrusaCollapsiblePane//wxCollapsiblePane
|
2018-05-10 14:36:12 +00:00
|
|
|
{
|
|
|
|
wxButton* m_pDisclosureTriangleButton = nullptr;
|
|
|
|
wxBitmap m_bmp_close;
|
|
|
|
wxBitmap m_bmp_open;
|
|
|
|
public:
|
2018-06-08 10:43:39 +00:00
|
|
|
PrusaCollapsiblePaneMSW() {}
|
|
|
|
PrusaCollapsiblePaneMSW( wxWindow *parent,
|
2018-05-10 14:36:12 +00:00
|
|
|
wxWindowID winid,
|
|
|
|
const wxString& label,
|
|
|
|
const wxPoint& pos = wxDefaultPosition,
|
|
|
|
const wxSize& size = wxDefaultSize,
|
|
|
|
long style = wxCP_DEFAULT_STYLE,
|
|
|
|
const wxValidator& val = wxDefaultValidator,
|
|
|
|
const wxString& name = wxCollapsiblePaneNameStr)
|
|
|
|
{
|
|
|
|
Create(parent, winid, label, pos, size, style, val, name);
|
|
|
|
}
|
|
|
|
|
2018-06-08 10:43:39 +00:00
|
|
|
~PrusaCollapsiblePaneMSW() {}
|
2018-05-11 09:25:28 +00:00
|
|
|
|
2018-05-10 14:36:12 +00:00
|
|
|
bool Create(wxWindow *parent,
|
|
|
|
wxWindowID id,
|
|
|
|
const wxString& label,
|
|
|
|
const wxPoint& pos,
|
|
|
|
const wxSize& size,
|
|
|
|
long style,
|
|
|
|
const wxValidator& val,
|
|
|
|
const wxString& name);
|
|
|
|
|
|
|
|
void UpdateBtnBmp();
|
|
|
|
void SetLabel(const wxString &label) override;
|
|
|
|
bool Layout() override;
|
2018-05-28 15:08:48 +00:00
|
|
|
void Collapse(bool collapse) override;
|
2018-05-10 14:36:12 +00:00
|
|
|
};
|
2018-06-05 09:17:37 +00:00
|
|
|
#endif //__WXMSW__
|
2018-05-10 14:36:12 +00:00
|
|
|
|
2018-05-04 16:32:20 +00:00
|
|
|
// *****************************************************************************
|
|
|
|
// ----------------------------------------------------------------------------
|
2018-06-15 20:42:51 +00:00
|
|
|
// PrusaObjectDataViewModelNode: a node inside PrusaObjectDataViewModel
|
2018-05-04 16:32:20 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2018-06-15 20:42:51 +00:00
|
|
|
class PrusaObjectDataViewModelNode;
|
|
|
|
WX_DEFINE_ARRAY_PTR(PrusaObjectDataViewModelNode*, MyObjectTreeModelNodePtrArray);
|
2018-05-04 16:32:20 +00:00
|
|
|
|
2018-06-15 20:42:51 +00:00
|
|
|
class PrusaObjectDataViewModelNode
|
2018-05-04 16:32:20 +00:00
|
|
|
{
|
2018-06-18 12:20:29 +00:00
|
|
|
PrusaObjectDataViewModelNode* m_parent;
|
2018-05-04 16:32:20 +00:00
|
|
|
MyObjectTreeModelNodePtrArray m_children;
|
2018-08-09 10:02:09 +00:00
|
|
|
wxIcon m_empty_icon;
|
2018-05-04 16:32:20 +00:00
|
|
|
public:
|
2018-06-15 20:42:51 +00:00
|
|
|
PrusaObjectDataViewModelNode(const wxString &name, int instances_count=1, int scale=100) {
|
2018-05-04 16:32:20 +00:00
|
|
|
m_parent = NULL;
|
|
|
|
m_name = name;
|
2018-06-04 13:59:55 +00:00
|
|
|
m_copy = wxString::Format("%d", instances_count);
|
|
|
|
m_scale = wxString::Format("%d%%", scale);
|
2018-06-18 12:20:29 +00:00
|
|
|
m_type = "object";
|
|
|
|
m_volume_id = -1;
|
2018-07-30 12:25:09 +00:00
|
|
|
#ifdef __WXGTK__
|
|
|
|
// it's necessary on GTK because of control have to know if this item will be container
|
|
|
|
// in another case you couldn't to add subitem for this item
|
|
|
|
// it will be produce "segmentation fault"
|
|
|
|
m_container = true;
|
|
|
|
#endif //__WXGTK__
|
2018-07-04 06:54:30 +00:00
|
|
|
set_object_action_icon();
|
2018-05-04 16:32:20 +00:00
|
|
|
}
|
|
|
|
|
2018-06-15 20:42:51 +00:00
|
|
|
PrusaObjectDataViewModelNode( PrusaObjectDataViewModelNode* parent,
|
2018-07-04 06:54:30 +00:00
|
|
|
const wxString& sub_obj_name,
|
2018-06-18 12:20:29 +00:00
|
|
|
const wxIcon& icon,
|
2018-08-15 11:59:33 +00:00
|
|
|
const wxString& extruder,
|
|
|
|
const int volume_id=-1) {
|
2018-05-04 16:32:20 +00:00
|
|
|
m_parent = parent;
|
2018-07-04 06:54:30 +00:00
|
|
|
m_name = sub_obj_name;
|
2018-05-04 16:32:20 +00:00
|
|
|
m_copy = wxEmptyString;
|
|
|
|
m_scale = wxEmptyString;
|
2018-06-18 12:20:29 +00:00
|
|
|
m_icon = icon;
|
|
|
|
m_type = "volume";
|
2018-07-04 06:54:30 +00:00
|
|
|
m_volume_id = volume_id;
|
2018-08-15 11:59:33 +00:00
|
|
|
m_extruder = extruder;
|
2018-07-04 06:54:30 +00:00
|
|
|
set_part_action_icon();
|
2018-06-15 20:42:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
~PrusaObjectDataViewModelNode()
|
2018-05-04 16:32:20 +00:00
|
|
|
{
|
|
|
|
// free all our children nodes
|
|
|
|
size_t count = m_children.GetCount();
|
|
|
|
for (size_t i = 0; i < count; i++)
|
|
|
|
{
|
2018-06-15 20:42:51 +00:00
|
|
|
PrusaObjectDataViewModelNode *child = m_children[i];
|
2018-05-04 16:32:20 +00:00
|
|
|
delete child;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
wxString m_name;
|
2018-08-09 10:02:09 +00:00
|
|
|
wxIcon& m_icon = m_empty_icon;
|
2018-05-04 16:32:20 +00:00
|
|
|
wxString m_copy;
|
|
|
|
wxString m_scale;
|
2018-06-18 12:20:29 +00:00
|
|
|
std::string m_type;
|
|
|
|
int m_volume_id;
|
2018-05-04 16:32:20 +00:00
|
|
|
bool m_container = false;
|
2018-07-04 06:54:30 +00:00
|
|
|
wxString m_extruder = "default";
|
|
|
|
wxBitmap m_action_icon;
|
2018-05-04 16:32:20 +00:00
|
|
|
|
|
|
|
bool IsContainer() const
|
|
|
|
{
|
|
|
|
return m_container;
|
|
|
|
}
|
|
|
|
|
2018-06-15 20:42:51 +00:00
|
|
|
PrusaObjectDataViewModelNode* GetParent()
|
2018-05-04 16:32:20 +00:00
|
|
|
{
|
|
|
|
return m_parent;
|
|
|
|
}
|
|
|
|
MyObjectTreeModelNodePtrArray& GetChildren()
|
|
|
|
{
|
|
|
|
return m_children;
|
|
|
|
}
|
2018-06-15 20:42:51 +00:00
|
|
|
PrusaObjectDataViewModelNode* GetNthChild(unsigned int n)
|
2018-05-04 16:32:20 +00:00
|
|
|
{
|
|
|
|
return m_children.Item(n);
|
|
|
|
}
|
2018-06-15 20:42:51 +00:00
|
|
|
void Insert(PrusaObjectDataViewModelNode* child, unsigned int n)
|
2018-05-04 16:32:20 +00:00
|
|
|
{
|
|
|
|
m_children.Insert(child, n);
|
|
|
|
}
|
2018-06-15 20:42:51 +00:00
|
|
|
void Append(PrusaObjectDataViewModelNode* child)
|
2018-05-04 16:32:20 +00:00
|
|
|
{
|
|
|
|
if (!m_container)
|
|
|
|
m_container = true;
|
|
|
|
m_children.Add(child);
|
|
|
|
}
|
2018-06-04 13:59:55 +00:00
|
|
|
void RemoveAllChildren()
|
|
|
|
{
|
|
|
|
if (GetChildCount() == 0)
|
|
|
|
return;
|
|
|
|
for (size_t id = GetChildCount() - 1; id >= 0; --id)
|
|
|
|
{
|
|
|
|
if (m_children.Item(id)->GetChildCount() > 0)
|
|
|
|
m_children[id]->RemoveAllChildren();
|
|
|
|
auto node = m_children[id];
|
|
|
|
m_children.RemoveAt(id);
|
|
|
|
delete node;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-29 22:36:44 +00:00
|
|
|
size_t GetChildCount() const
|
2018-05-04 16:32:20 +00:00
|
|
|
{
|
|
|
|
return m_children.GetCount();
|
|
|
|
}
|
2018-06-05 08:41:20 +00:00
|
|
|
|
|
|
|
bool SetValue(const wxVariant &variant, unsigned int col)
|
|
|
|
{
|
|
|
|
switch (col)
|
|
|
|
{
|
2018-06-15 20:42:51 +00:00
|
|
|
case 0:{
|
|
|
|
wxDataViewIconText data;
|
|
|
|
data << variant;
|
|
|
|
m_icon = data.GetIcon();
|
|
|
|
m_name = data.GetText();
|
|
|
|
return true;}
|
2018-06-05 08:41:20 +00:00
|
|
|
case 1:
|
|
|
|
m_copy = variant.GetString();
|
|
|
|
return true;
|
|
|
|
case 2:
|
|
|
|
m_scale = variant.GetString();
|
|
|
|
return true;
|
2018-07-04 06:54:30 +00:00
|
|
|
case 3:
|
|
|
|
m_extruder = variant.GetString();
|
|
|
|
return true;
|
|
|
|
case 4:
|
|
|
|
m_action_icon << variant;
|
|
|
|
return true;
|
2018-06-05 08:41:20 +00:00
|
|
|
default:
|
|
|
|
printf("MyObjectTreeModel::SetValue: wrong column");
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2018-06-15 20:42:51 +00:00
|
|
|
void SetIcon(const wxIcon &icon)
|
|
|
|
{
|
|
|
|
m_icon = icon;
|
|
|
|
}
|
2018-06-18 12:20:29 +00:00
|
|
|
|
|
|
|
void SetType(const std::string& type){
|
|
|
|
m_type = type;
|
|
|
|
}
|
|
|
|
const std::string& GetType(){
|
|
|
|
return m_type;
|
|
|
|
}
|
|
|
|
|
2018-06-18 13:26:09 +00:00
|
|
|
void SetVolumeId(const int& volume_id){
|
|
|
|
m_volume_id = volume_id;
|
|
|
|
}
|
|
|
|
const int& GetVolumeId(){
|
2018-06-18 12:20:29 +00:00
|
|
|
return m_volume_id;
|
|
|
|
}
|
2018-06-19 10:24:16 +00:00
|
|
|
|
|
|
|
// use this function only for childrens
|
|
|
|
void AssignAllVal(PrusaObjectDataViewModelNode& from_node)
|
|
|
|
{
|
|
|
|
// ! Don't overwrite other values because of equality of this values for all children --
|
|
|
|
m_name = from_node.m_name;
|
|
|
|
m_icon = from_node.m_icon;
|
|
|
|
m_volume_id = from_node.m_volume_id;
|
2018-07-04 06:54:30 +00:00
|
|
|
m_extruder = from_node.m_extruder;
|
2018-06-19 10:24:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool SwapChildrens(int frst_id, int scnd_id) {
|
|
|
|
if (GetChildCount() < 2 ||
|
|
|
|
frst_id < 0 || frst_id >= GetChildCount() ||
|
|
|
|
scnd_id < 0 || scnd_id >= GetChildCount())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
PrusaObjectDataViewModelNode new_scnd = *GetNthChild(frst_id);
|
|
|
|
PrusaObjectDataViewModelNode new_frst = *GetNthChild(scnd_id);
|
|
|
|
|
|
|
|
new_scnd.m_volume_id = m_children.Item(scnd_id)->m_volume_id;
|
|
|
|
new_frst.m_volume_id = m_children.Item(frst_id)->m_volume_id;
|
|
|
|
|
|
|
|
m_children.Item(frst_id)->AssignAllVal(new_frst);
|
|
|
|
m_children.Item(scnd_id)->AssignAllVal(new_scnd);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-07-04 06:54:30 +00:00
|
|
|
// Set action icons for node
|
|
|
|
void set_object_action_icon();
|
|
|
|
void set_part_action_icon();
|
2018-05-04 16:32:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2018-06-15 20:42:51 +00:00
|
|
|
// PrusaObjectDataViewModel
|
2018-05-04 16:32:20 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2018-06-15 20:42:51 +00:00
|
|
|
class PrusaObjectDataViewModel :public wxDataViewModel
|
2018-05-04 16:32:20 +00:00
|
|
|
{
|
2018-06-15 20:42:51 +00:00
|
|
|
std::vector<PrusaObjectDataViewModelNode*> m_objects;
|
2018-05-04 16:32:20 +00:00
|
|
|
public:
|
2018-06-15 20:42:51 +00:00
|
|
|
PrusaObjectDataViewModel(){}
|
|
|
|
~PrusaObjectDataViewModel()
|
2018-05-04 16:32:20 +00:00
|
|
|
{
|
|
|
|
for (auto object : m_objects)
|
|
|
|
delete object;
|
|
|
|
}
|
|
|
|
|
2018-05-30 15:52:28 +00:00
|
|
|
wxDataViewItem Add(wxString &name);
|
2018-06-04 13:59:55 +00:00
|
|
|
wxDataViewItem Add(wxString &name, int instances_count, int scale);
|
2018-06-15 20:42:51 +00:00
|
|
|
wxDataViewItem AddChild(const wxDataViewItem &parent_item,
|
|
|
|
const wxString &name,
|
2018-07-30 15:03:14 +00:00
|
|
|
const wxIcon& icon,
|
2018-08-15 11:59:33 +00:00
|
|
|
const int = 0,
|
|
|
|
const bool create_frst_child = true);
|
2018-05-30 15:52:28 +00:00
|
|
|
wxDataViewItem Delete(const wxDataViewItem &item);
|
2018-06-04 13:59:55 +00:00
|
|
|
void DeleteAll();
|
2018-07-31 13:31:12 +00:00
|
|
|
void DeleteChildren(wxDataViewItem& parent);
|
2018-06-04 13:59:55 +00:00
|
|
|
wxDataViewItem GetItemById(int obj_idx);
|
2018-06-06 22:55:09 +00:00
|
|
|
int GetIdByItem(wxDataViewItem& item);
|
2018-06-18 12:20:29 +00:00
|
|
|
int GetVolumeIdByItem(wxDataViewItem& item);
|
2018-05-29 22:36:44 +00:00
|
|
|
bool IsEmpty() { return m_objects.empty(); }
|
2018-05-29 20:45:35 +00:00
|
|
|
|
2018-05-04 16:32:20 +00:00
|
|
|
// helper method for wxLog
|
|
|
|
|
|
|
|
wxString GetName(const wxDataViewItem &item) const;
|
2018-05-09 12:36:20 +00:00
|
|
|
wxString GetCopy(const wxDataViewItem &item) const;
|
2018-05-04 16:32:20 +00:00
|
|
|
wxString GetScale(const wxDataViewItem &item) const;
|
2018-08-09 10:02:09 +00:00
|
|
|
wxIcon& GetIcon(const wxDataViewItem &item) const;
|
2018-05-04 16:32:20 +00:00
|
|
|
|
|
|
|
// helper methods to change the model
|
|
|
|
|
|
|
|
virtual unsigned int GetColumnCount() const override { return 3;}
|
|
|
|
virtual wxString GetColumnType(unsigned int col) const override{ return wxT("string"); }
|
|
|
|
|
|
|
|
virtual void GetValue(wxVariant &variant,
|
|
|
|
const wxDataViewItem &item, unsigned int col) const override;
|
|
|
|
virtual bool SetValue(const wxVariant &variant,
|
|
|
|
const wxDataViewItem &item, unsigned int col) override;
|
2018-06-05 08:41:20 +00:00
|
|
|
bool SetValue(const wxVariant &variant, const int item_idx, unsigned int col);
|
2018-05-04 16:32:20 +00:00
|
|
|
|
2018-06-19 10:24:16 +00:00
|
|
|
wxDataViewItem MoveChildUp(const wxDataViewItem &item);
|
|
|
|
wxDataViewItem MoveChildDown(const wxDataViewItem &item);
|
2018-08-13 12:15:43 +00:00
|
|
|
// For parent move child from cur_volume_id place to new_volume_id
|
|
|
|
// Remaining items will moved up/down accordingly
|
|
|
|
wxDataViewItem ReorganizeChildren(int cur_volume_id,
|
|
|
|
int new_volume_id,
|
|
|
|
const wxDataViewItem &parent);
|
2018-06-19 10:24:16 +00:00
|
|
|
|
2018-05-04 16:32:20 +00:00
|
|
|
// virtual bool IsEnabled(const wxDataViewItem &item,
|
|
|
|
// unsigned int col) const override;
|
|
|
|
|
|
|
|
virtual wxDataViewItem GetParent(const wxDataViewItem &item) const override;
|
|
|
|
virtual bool IsContainer(const wxDataViewItem &item) const override;
|
|
|
|
virtual unsigned int GetChildren(const wxDataViewItem &parent,
|
|
|
|
wxDataViewItemArray &array) const override;
|
2018-05-09 12:36:20 +00:00
|
|
|
|
|
|
|
// Is the container just a header or an item with all columns
|
|
|
|
// In our case it is an item with all columns
|
|
|
|
virtual bool HasContainerColumns(const wxDataViewItem& WXUNUSED(item)) const override { return true; }
|
2018-05-04 16:32:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// MyCustomRenderer
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class MyCustomRenderer : public wxDataViewCustomRenderer
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// This renderer can be either activatable or editable, for demonstration
|
|
|
|
// purposes. In real programs, you should select whether the user should be
|
|
|
|
// able to activate or edit the cell and it doesn't make sense to switch
|
|
|
|
// between the two -- but this is just an example, so it doesn't stop us.
|
|
|
|
explicit MyCustomRenderer(wxDataViewCellMode mode)
|
|
|
|
: wxDataViewCustomRenderer("string", mode, wxALIGN_CENTER)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
virtual bool Render(wxRect rect, wxDC *dc, int state) override/*wxOVERRIDE*/
|
|
|
|
{
|
|
|
|
dc->SetBrush(*wxLIGHT_GREY_BRUSH);
|
|
|
|
dc->SetPen(*wxTRANSPARENT_PEN);
|
|
|
|
|
|
|
|
rect.Deflate(2);
|
|
|
|
dc->DrawRoundedRectangle(rect, 5);
|
|
|
|
|
|
|
|
RenderText(m_value,
|
|
|
|
0, // no offset
|
|
|
|
wxRect(dc->GetTextExtent(m_value)).CentreIn(rect),
|
|
|
|
dc,
|
|
|
|
state);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool ActivateCell(const wxRect& WXUNUSED(cell),
|
|
|
|
wxDataViewModel *WXUNUSED(model),
|
|
|
|
const wxDataViewItem &WXUNUSED(item),
|
|
|
|
unsigned int WXUNUSED(col),
|
|
|
|
const wxMouseEvent *mouseEvent) override/*wxOVERRIDE*/
|
|
|
|
{
|
|
|
|
wxString position;
|
|
|
|
if (mouseEvent)
|
|
|
|
position = wxString::Format("via mouse at %d, %d", mouseEvent->m_x, mouseEvent->m_y);
|
|
|
|
else
|
|
|
|
position = "from keyboard";
|
|
|
|
// wxLogMessage("MyCustomRenderer ActivateCell() %s", position);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual wxSize GetSize() const override/*wxOVERRIDE*/
|
|
|
|
{
|
|
|
|
return wxSize(60, 20);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool SetValue(const wxVariant &value) override/*wxOVERRIDE*/
|
|
|
|
{
|
|
|
|
m_value = value.GetString();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool GetValue(wxVariant &WXUNUSED(value)) const override/*wxOVERRIDE*/{ return true; }
|
|
|
|
|
|
|
|
virtual bool HasEditorCtrl() const override/*wxOVERRIDE*/{ return true; }
|
|
|
|
|
|
|
|
virtual wxWindow*
|
|
|
|
CreateEditorCtrl(wxWindow* parent,
|
|
|
|
wxRect labelRect,
|
|
|
|
const wxVariant& value) override/*wxOVERRIDE*/
|
|
|
|
{
|
|
|
|
wxTextCtrl* text = new wxTextCtrl(parent, wxID_ANY, value,
|
|
|
|
labelRect.GetPosition(),
|
|
|
|
labelRect.GetSize(),
|
|
|
|
wxTE_PROCESS_ENTER);
|
|
|
|
text->SetInsertionPointEnd();
|
|
|
|
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool
|
|
|
|
GetValueFromEditorCtrl(wxWindow* ctrl, wxVariant& value) override/*wxOVERRIDE*/
|
|
|
|
{
|
|
|
|
wxTextCtrl* text = wxDynamicCast(ctrl, wxTextCtrl);
|
|
|
|
if (!text)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
value = text->GetValue();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
wxString m_value;
|
|
|
|
};
|
2018-07-30 10:17:32 +00:00
|
|
|
// ******************************* EXPERIMENTS **********************************************
|
2018-08-21 00:03:10 +00:00
|
|
|
enum SelectedSlider {
|
|
|
|
ssUndef,
|
|
|
|
ssLower,
|
|
|
|
ssHigher
|
|
|
|
};
|
2018-08-23 11:01:18 +00:00
|
|
|
enum TicksAction{
|
2018-08-24 11:34:38 +00:00
|
|
|
taOnIcon,
|
2018-08-23 11:01:18 +00:00
|
|
|
taAdd,
|
|
|
|
taDel
|
|
|
|
};
|
2018-08-21 00:03:10 +00:00
|
|
|
class PrusaDoubleSlider : public wxControl
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
PrusaDoubleSlider(
|
|
|
|
wxWindow *parent,
|
|
|
|
wxWindowID id,
|
|
|
|
int lowerValue,
|
|
|
|
int higherValue,
|
|
|
|
int minValue,
|
|
|
|
int maxValue,
|
|
|
|
const wxPoint& pos = wxDefaultPosition,
|
|
|
|
const wxSize& size = wxDefaultSize,
|
|
|
|
long style = wxSL_HORIZONTAL,
|
|
|
|
const wxValidator& val = wxDefaultValidator,
|
|
|
|
const wxString& name = wxEmptyString);
|
|
|
|
|
2018-08-23 12:37:17 +00:00
|
|
|
int GetLowerValue() const {
|
2018-08-21 00:03:10 +00:00
|
|
|
return m_lower_value;
|
|
|
|
}
|
2018-08-23 12:37:17 +00:00
|
|
|
int GetHigherValue() const {
|
2018-08-21 00:03:10 +00:00
|
|
|
return m_higher_value;
|
|
|
|
}
|
2018-08-23 12:37:17 +00:00
|
|
|
int GetActiveValue() const;
|
2018-08-22 12:24:30 +00:00
|
|
|
wxSize DoGetBestSize() const override;
|
2018-08-24 11:34:38 +00:00
|
|
|
void SetLowerValue(const int lower_val);
|
|
|
|
void SetHigherValue(const int higher_val);
|
|
|
|
void SetMaxValue(const int max_value);
|
2018-08-23 12:37:17 +00:00
|
|
|
void SetKoefForLabels(const double koef) {
|
|
|
|
m_label_koef = koef;
|
|
|
|
}
|
|
|
|
void SetSliderValues(const std::vector<double>& values) {
|
|
|
|
m_values = values;
|
|
|
|
}
|
2018-08-21 00:03:10 +00:00
|
|
|
|
2018-08-21 15:47:05 +00:00
|
|
|
void OnPaint(wxPaintEvent& ){ render();}
|
2018-08-21 00:03:10 +00:00
|
|
|
void OnLeftDown(wxMouseEvent& event);
|
|
|
|
void OnMotion(wxMouseEvent& event);
|
|
|
|
void OnLeftUp(wxMouseEvent& event);
|
2018-08-24 11:34:38 +00:00
|
|
|
void OnEnterWin(wxMouseEvent& event){ enter_window(event, true); }
|
|
|
|
void OnLeaveWin(wxMouseEvent& event){ enter_window(event, false); }
|
2018-08-21 00:03:10 +00:00
|
|
|
void OnWheel(wxMouseEvent& event);
|
2018-08-21 15:47:05 +00:00
|
|
|
void OnKeyDown(wxKeyEvent &event);
|
2018-08-24 11:34:38 +00:00
|
|
|
void OnKeyUp(wxKeyEvent &event);
|
2018-08-22 16:00:48 +00:00
|
|
|
void OnRightDown(wxMouseEvent& event);
|
2018-08-24 11:34:38 +00:00
|
|
|
void OnRightUp(wxMouseEvent& event);
|
2018-08-21 00:03:10 +00:00
|
|
|
|
|
|
|
protected:
|
2018-08-21 15:47:05 +00:00
|
|
|
|
|
|
|
void render();
|
|
|
|
void draw_focus_rect();
|
2018-08-23 12:37:17 +00:00
|
|
|
void draw_action_icon(wxDC& dc, const wxPoint pt_beg, const wxPoint pt_end);
|
2018-08-22 12:24:30 +00:00
|
|
|
void draw_scroll_line(wxDC& dc, const int lower_pos, const int higher_pos);
|
|
|
|
void draw_thumb(wxDC& dc, const wxCoord& pos_coord, const SelectedSlider& selection);
|
2018-08-24 11:34:38 +00:00
|
|
|
void draw_thumbs(wxDC& dc, const wxCoord& lower_pos, const wxCoord& higher_pos);
|
2018-08-22 16:00:48 +00:00
|
|
|
void draw_ticks(wxDC& dc);
|
2018-08-24 11:34:38 +00:00
|
|
|
void draw_one_layer_icon(wxDC& dc);
|
2018-08-22 12:24:30 +00:00
|
|
|
void draw_thumb_item(wxDC& dc, const wxPoint& pos, const SelectedSlider& selection);
|
2018-08-23 11:01:18 +00:00
|
|
|
void draw_info_line_with_icon(wxDC& dc, const wxPoint& pos, SelectedSlider selection);
|
2018-08-22 12:24:30 +00:00
|
|
|
void draw_thumb_text(wxDC& dc, const wxPoint& pos, const SelectedSlider& selection) const;
|
|
|
|
|
|
|
|
void update_thumb_rect(const wxCoord& begin_x, const wxCoord& begin_y, const SelectedSlider& selection);
|
2018-08-21 00:03:10 +00:00
|
|
|
void detect_selected_slider(const wxPoint& pt, const bool is_mouse_wheel = false);
|
2018-08-22 12:24:30 +00:00
|
|
|
void correct_lower_value();
|
|
|
|
void correct_higher_value();
|
|
|
|
void move_current_thumb(const bool condition);
|
2018-08-23 11:01:18 +00:00
|
|
|
void action_tick(const TicksAction action);
|
2018-08-24 11:34:38 +00:00
|
|
|
void enter_window(wxMouseEvent& event, const bool enter);
|
2018-08-22 12:24:30 +00:00
|
|
|
|
2018-08-21 00:03:10 +00:00
|
|
|
bool is_point_in_rect(const wxPoint& pt, const wxRect& rect);
|
|
|
|
bool is_horizontal() const { return m_style == wxSL_HORIZONTAL; }
|
2018-08-22 12:24:30 +00:00
|
|
|
|
|
|
|
double get_scroll_step();
|
|
|
|
wxString get_label(const SelectedSlider& selection) const;
|
|
|
|
void get_lower_and_higher_position(int& lower_pos, int& higher_pos);
|
2018-08-24 11:34:38 +00:00
|
|
|
int get_value_from_position(const wxCoord x, const wxCoord y);
|
2018-08-22 16:00:48 +00:00
|
|
|
wxCoord get_position_from_value(const int value);
|
2018-08-24 11:34:38 +00:00
|
|
|
wxSize get_size();
|
|
|
|
void get_size(int *w, int *h);
|
2018-05-04 16:32:20 +00:00
|
|
|
|
2018-08-21 00:03:10 +00:00
|
|
|
private:
|
|
|
|
int m_min_value;
|
|
|
|
int m_max_value;
|
|
|
|
int m_lower_value;
|
|
|
|
int m_higher_value;
|
2018-08-24 11:34:38 +00:00
|
|
|
wxBitmap m_bmp_thumb_higher;
|
|
|
|
wxBitmap m_bmp_thumb_lower;
|
|
|
|
wxBitmap m_bmp_add_tick_on;
|
|
|
|
wxBitmap m_bmp_add_tick_off;
|
|
|
|
wxBitmap m_bmp_del_tick_on;
|
|
|
|
wxBitmap m_bmp_del_tick_off;
|
|
|
|
wxBitmap m_bmp_one_layer_lock_on;
|
|
|
|
wxBitmap m_bmp_one_layer_lock_off;
|
|
|
|
wxBitmap m_bmp_one_layer_unlock_on;
|
|
|
|
wxBitmap m_bmp_one_layer_unlock_off;
|
2018-08-21 00:03:10 +00:00
|
|
|
SelectedSlider m_selection;
|
|
|
|
bool m_is_left_down = false;
|
2018-08-24 11:34:38 +00:00
|
|
|
bool m_is_right_down = false;
|
|
|
|
bool m_is_one_layer = false;
|
2018-08-21 15:47:05 +00:00
|
|
|
bool m_is_focused = false;
|
2018-08-23 11:01:18 +00:00
|
|
|
bool m_is_action_icon_focesed = false;
|
2018-08-24 11:34:38 +00:00
|
|
|
bool m_is_one_layer_icon_focesed = false;
|
2018-08-21 00:03:10 +00:00
|
|
|
|
|
|
|
wxRect m_rect_lower_thumb;
|
|
|
|
wxRect m_rect_higher_thumb;
|
2018-08-23 11:01:18 +00:00
|
|
|
wxRect m_rect_tick_action;
|
2018-08-24 11:34:38 +00:00
|
|
|
wxRect m_rect_one_layer_icon;
|
2018-08-22 12:24:30 +00:00
|
|
|
wxSize m_thumb_size;
|
2018-08-23 11:01:18 +00:00
|
|
|
int m_tick_icon_dim;
|
2018-08-24 11:34:38 +00:00
|
|
|
int m_lock_icon_dim = 16;
|
2018-08-21 00:03:10 +00:00
|
|
|
long m_style;
|
2018-08-21 15:47:05 +00:00
|
|
|
float m_label_koef = 1.0;
|
2018-08-21 00:03:10 +00:00
|
|
|
|
|
|
|
// control's view variables
|
|
|
|
wxCoord SLIDER_MARGIN; // margin around slider
|
|
|
|
|
|
|
|
wxPen DARK_ORANGE_PEN;
|
|
|
|
wxPen ORANGE_PEN;
|
|
|
|
wxPen LIGHT_ORANGE_PEN;
|
|
|
|
|
|
|
|
wxPen DARK_GREY_PEN;
|
|
|
|
wxPen GREY_PEN;
|
|
|
|
wxPen LIGHT_GREY_PEN;
|
|
|
|
|
|
|
|
std::vector<wxPen*> line_pens;
|
|
|
|
std::vector<wxPen*> segm_pens;
|
2018-08-22 16:00:48 +00:00
|
|
|
std::set<int> m_ticks;
|
2018-08-23 12:37:17 +00:00
|
|
|
std::vector<double> m_values;
|
2018-08-21 00:03:10 +00:00
|
|
|
};
|
2018-07-30 10:17:32 +00:00
|
|
|
// ******************************************************************************************
|
2018-05-04 16:32:20 +00:00
|
|
|
|
|
|
|
|
2018-02-02 11:38:35 +00:00
|
|
|
#endif // slic3r_GUI_wxExtensions_hpp_
|