Improved layer sizer

+ fixed build under OSX and Linux
This commit is contained in:
YuSanka 2019-05-30 14:41:16 +02:00
parent 080274c638
commit a516f76f94
5 changed files with 70 additions and 35 deletions

View file

@ -24,7 +24,7 @@ ObjectLayers::ObjectLayers(wxWindow* parent) :
OG_Settings(parent, true)
{
m_og->label_width = 1;
// m_og->set_grid_vgap(5);
m_og->set_grid_vgap(5);
// Legend for object layers
Line line = Line{ "", "" };
@ -118,13 +118,16 @@ void ObjectLayers::create_layers_list()
}
}
void ObjectLayers::create_layer()
void ObjectLayers::create_layer(int id)
{
for (const auto layer : m_object->layer_height_ranges)
{
m_og->append_line(create_new_layer(layer));
break;
t_layer_height_ranges::iterator layer_range = m_object->layer_height_ranges.begin();
while (id > 0 && layer_range != m_object->layer_height_ranges.end()) {
layer_range++;
id--;
}
m_og->append_line(create_new_layer(*layer_range));
}
void ObjectLayers::update_layers_list()
@ -164,7 +167,7 @@ void ObjectLayers::update_layers_list()
if (type & itLayerRoot)
create_layers_list();
else
create_layer();
create_layer(objects_ctrl->GetModel()->GetLayerIdByItem(item));
m_parent->Layout();
}

View file

@ -25,7 +25,7 @@ public:
~ObjectLayers() {}
void create_layers_list();
void create_layer();
void create_layer(int id);
void update_layers_list();
void add_layer() {};
void del_layer() {};

View file

@ -1801,15 +1801,21 @@ void ObjectList::layers_editing()
wxDataViewItem layers_item = m_objects_model->GetItemByType(obj_item, itLayerRoot);
if (!layers_item.IsOk())
{
const t_layer_height_range first_range = { 0.0f, 0.2f };
object(obj_idx)->layer_height_ranges[first_range] = 0.1f;
const t_layer_height_range second_range = { 0.2f, 0.4f };
object(obj_idx)->layer_height_ranges[second_range] = 0.05f;
// --->>>--- Just for testing
object(obj_idx)->layer_height_ranges[{ 0.0f, 0.2f }] = 0.1f;
object(obj_idx)->layer_height_ranges[{ 0.2f, 0.4f }] = 0.05f;
object(obj_idx)->layer_height_ranges[{ 0.4f, 0.6f }] = 0.2f;
// ---<<<--- Just for testing
layers_item = m_objects_model->AddLayersRoot(obj_item);
}
for (const auto range : object(obj_idx)->layer_height_ranges)
{
const std::string label = (boost::format("(%.2f-%.2f)") % range.first.first % range.first.second).str();
m_objects_model->AddLayersChild(layers_item, label);
}
select_item(layers_item);
}

View file

@ -453,24 +453,39 @@ ObjectDataViewModelNode::ObjectDataViewModelNode(ObjectDataViewModelNode* parent
m_bmp = create_scaled_bitmap(nullptr, "table.png"); // FIXME: pass window ptr
m_name = _(L("Layers"));
}
else if (type == itLayer)
{
m_idx = parent->GetChildCount();
m_name = wxString::Format(_(L("Layer %d")), m_idx + 1);
m_bmp = create_scaled_bitmap(nullptr, "row.png"); // FIXME: pass window ptr
set_action_icon();
}
#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"
if (type & (itInstanceRoot | itLayerRoot | itLayer))
if (type & (itInstanceRoot | itLayerRoot))
m_container = true;
#endif //__WXGTK__
}
ObjectDataViewModelNode::ObjectDataViewModelNode(ObjectDataViewModelNode* parent,
const wxString& label_range,
const wxString& extruder,
const int idx /*= -1 */) :
m_parent(parent),
m_type(itLayer),
m_idx(idx),
m_extruder(extruder)
{
m_idx = parent->GetChildCount();
m_name = wxString::Format(_(L("Layer %s")), label_range);
m_bmp = create_scaled_bitmap(nullptr, "row.png"); // FIXME: pass window ptr
#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__
set_action_icon();
}
void ObjectDataViewModelNode::set_action_icon()
{
m_action_icon_name = m_type & itObject ? "advanced_plus" :
@ -671,7 +686,7 @@ static bool append_root_node(ObjectDataViewModelNode *parent_node,
(root_type&itLayerRoot) && get_root_idx(parent_node, itInstanceRoot)<0)
parent_node->Append(*root_node);
else if (root_type&itLayerRoot)
parent_node->Insert(*root_node, unsigned int(get_root_idx(parent_node, itInstanceRoot)));
parent_node->Insert(*root_node, static_cast<unsigned int>(get_root_idx(parent_node, itInstanceRoot)));
return true;
}
@ -723,38 +738,38 @@ wxDataViewItem ObjectDataViewModel::AddLayersRoot(const wxDataViewItem &parent_i
if (appended)
ItemAdded(parent_item, layer_root_item);// notify control
AddLayersChild(layer_root_item);
return wxDataViewItem((void*)layer_root_item);
return layer_root_item;
}
wxDataViewItem ObjectDataViewModel::AddLayersChild(const wxDataViewItem &parent_item)
wxDataViewItem ObjectDataViewModel::AddLayersChild(const wxDataViewItem &parent_item, const std::string& label_range)
{
ObjectDataViewModelNode *parent_node = (ObjectDataViewModelNode*)parent_item.GetID();
if (!parent_node) return wxDataViewItem(0);
// get LayerRoot node
ObjectDataViewModelNode *layer_root_node;
wxDataViewItem layer_root_item;
if (parent_node->GetType() & itLayerRoot)
if (parent_node->GetType() & itLayerRoot) {
layer_root_node = parent_node;
layer_root_item = parent_item;
}
else {
const int root_idx = get_root_idx(parent_node, itLayerRoot);
if (root_idx < 0) return wxDataViewItem(0);
layer_root_node = parent_node->GetNthChild(root_idx);
layer_root_item = wxDataViewItem((void*)layer_root_node);
}
const wxDataViewItem layer_root_item((void*)layer_root_node);
// Add layer node
ObjectDataViewModelNode *layer_node = new ObjectDataViewModelNode(layer_root_node, itLayer);
ObjectDataViewModelNode *layer_node = new ObjectDataViewModelNode(layer_root_node, label_range);
layer_root_node->Append(layer_node);
// notify control
const wxDataViewItem instance_item((void*)layer_node);
ItemAdded(layer_root_item, instance_item);
const wxDataViewItem layer_item((void*)layer_node);
ItemAdded(layer_root_item, layer_item);
return wxDataViewItem((void*)layer_node);
return layer_item;
}
wxDataViewItem ObjectDataViewModel::Delete(const wxDataViewItem &item)
@ -1138,6 +1153,11 @@ int ObjectDataViewModel::GetInstanceIdByItem(const wxDataViewItem& item) const
return GetIdByItemAndType(item, itInstance);
}
int ObjectDataViewModel::GetLayerIdByItem(const wxDataViewItem& item) const
{
return GetIdByItemAndType(item, itLayer);
}
void ObjectDataViewModel::GetItemInfo(const wxDataViewItem& item, ItemType& type, int& obj_idx, int& idx)
{
wxASSERT(item.IsOk());

View file

@ -231,6 +231,11 @@ public:
set_action_icon();
}
ObjectDataViewModelNode(ObjectDataViewModelNode* parent,
const wxString& label_range,
const wxString& extruder = wxEmptyString,
const int idx = -1 );
ObjectDataViewModelNode(ObjectDataViewModelNode* parent, const ItemType type);
~ObjectDataViewModelNode()
@ -391,7 +396,7 @@ public:
wxDataViewItem AddSettingsChild(const wxDataViewItem &parent_item);
wxDataViewItem AddInstanceChild(const wxDataViewItem &parent_item, size_t num);
wxDataViewItem AddLayersRoot(const wxDataViewItem &parent_item);
wxDataViewItem AddLayersChild(const wxDataViewItem &parent_item);
wxDataViewItem AddLayersChild(const wxDataViewItem &parent_item, const std::string& label_range);
wxDataViewItem Delete(const wxDataViewItem &item);
wxDataViewItem DeleteLastInstance(const wxDataViewItem &parent_item, size_t num);
void DeleteAll();
@ -406,6 +411,7 @@ public:
int GetObjectIdByItem(const wxDataViewItem& item) const;
int GetVolumeIdByItem(const wxDataViewItem& item) const;
int GetInstanceIdByItem(const wxDataViewItem& item) const;
int GetLayerIdByItem(const wxDataViewItem& item) const;
void GetItemInfo(const wxDataViewItem& item, ItemType& type, int& obj_idx, int& idx);
int GetRowByItem(const wxDataViewItem& item) const;
bool IsEmpty() { return m_objects.empty(); }