Fix: drag only by text not by object

Divide set and reset of text volume
This commit is contained in:
Filip Sykala - NTB T15p 2023-02-20 12:52:08 +01:00
parent 8269452927
commit d6b8163975
2 changed files with 32 additions and 22 deletions

View File

@ -586,13 +586,17 @@ bool GLGizmoEmboss::on_mouse_for_translate(const wxMouseEvent &mouse_event)
if (m_volume == nullptr) if (m_volume == nullptr)
return false; return false;
if (m_parent.get_first_hover_volume_idx() < 0)
return false;
GLVolume *gl_volume = priv::get_gl_volume(m_parent); GLVolume *gl_volume = priv::get_gl_volume(m_parent);
if (gl_volume == nullptr) if (gl_volume == nullptr)
return false; return false;
// is text hovered?
const GLVolumePtrs& gl_volumes = m_parent.get_volumes().volumes;
int hovered_idx = m_parent.get_first_hover_volume_idx();
if (hovered_idx < 0 || hovered_idx >= gl_volumes.size() ||
gl_volumes[hovered_idx] != gl_volume)
return false;
// hovered object must be actual text volume // hovered object must be actual text volume
const ModelObjectPtrs &objects = m_parent.get_model()->objects; const ModelObjectPtrs &objects = m_parent.get_model()->objects;
if (m_volume != priv::get_model_volume(gl_volume, objects)) if (m_volume != priv::get_model_volume(gl_volume, objects))
@ -1005,7 +1009,7 @@ void GLGizmoEmboss::on_set_state()
_u8L("ERROR: Wait until ends or Cancel process.")); _u8L("ERROR: Wait until ends or Cancel process."));
return; return;
} }
set_volume(nullptr); reset_volume();
// Store order and last activ index into app.ini // Store order and last activ index into app.ini
// TODO: what to do when can't store into file? // TODO: what to do when can't store into file?
m_style_manager.store_styles_to_app_config(false); m_style_manager.store_styles_to_app_config(false);
@ -1015,7 +1019,7 @@ void GLGizmoEmboss::on_set_state()
wxFontEnumerator::InvalidateCache(); wxFontEnumerator::InvalidateCache();
// Try(when exist) set text configuration by volume // Try(when exist) set text configuration by volume
set_volume(priv::get_selected_volume(m_parent.get_selection())); set_volume_by_selection();
// when open window by "T" and no valid volume is selected, so Create new one // when open window by "T" and no valid volume is selected, so Create new one
if (m_volume == nullptr || if (m_volume == nullptr ||
@ -1248,25 +1252,22 @@ void GLGizmoEmboss::set_volume_by_selection()
m_volume != vol) // when update volume it changed id BUT not pointer m_volume != vol) // when update volume it changed id BUT not pointer
ImGuiWrapper::left_inputs(); ImGuiWrapper::left_inputs();
if (vol == nullptr) {
reset_volume();
return;
}
// is select embossed volume? // is select embossed volume?
set_volume(vol); set_volume(vol);
} }
bool GLGizmoEmboss::set_volume(ModelVolume *volume) bool GLGizmoEmboss::set_volume(ModelVolume *volume)
{ {
if (volume == nullptr) { assert(volume != nullptr);
if (m_volume == nullptr)
return false;
m_volume = nullptr;
// TODO: check if it is neccessary to set default text
// Idea is to set default text when create object
set_default_text();
return false;
}
const std::optional<TextConfiguration> tc_opt = volume->text_configuration; const std::optional<TextConfiguration> tc_opt = volume->text_configuration;
if (!tc_opt.has_value()) return false; if (!tc_opt.has_value()) return false;
const TextConfiguration &tc = *tc_opt; const TextConfiguration &tc = *tc_opt;
const EmbossStyle &style = tc.style; const EmbossStyle &style = tc.style;
// Could exist OS without getter on face_name, // Could exist OS without getter on face_name,
// but it is able to restore font from descriptor // but it is able to restore font from descriptor
@ -1377,6 +1378,18 @@ bool GLGizmoEmboss::set_volume(ModelVolume *volume)
return true; return true;
} }
void GLGizmoEmboss::reset_volume()
{
if (m_volume == nullptr)
return; // already reseted
m_volume = nullptr;
m_volume_id.id = 0;
// TODO: check if it is neccessary to set default text
// Idea is to set default text when create object
set_default_text();
}
void GLGizmoEmboss::calculate_scale() { void GLGizmoEmboss::calculate_scale() {
Transform3d to_world = m_parent.get_selection().get_first_volume()->world_matrix(); Transform3d to_world = m_parent.get_selection().get_first_volume()->world_matrix();
auto to_world_linear = to_world.linear(); auto to_world_linear = to_world.linear();
@ -4069,12 +4082,8 @@ bool priv::start_create_volume_on_surface_job(
Transform3d surface_trmat = create_transformation_onto_surface(hit->position, hit->normal); Transform3d surface_trmat = create_transformation_onto_surface(hit->position, hit->normal);
const FontProp &font_prop = emboss_data.text_configuration.style.prop; const FontProp &font_prop = emboss_data.text_configuration.style.prop;
apply_transformation(font_prop, surface_trmat); apply_transformation(font_prop, surface_trmat);
Transform3d world_new = surface_trmat; // new transformation in world coor is surface_trmat
Transform3d volume_trmat = instance.inverse() * surface_trmat;
// Reset skew
//priv::reset_skew_respect_z(world_new);
Transform3d volume_trmat = instance.inverse() * world_new;
start_create_volume_job(obj, volume_trmat, emboss_data, volume_type); start_create_volume_job(obj, volume_trmat, emboss_data, volume_type);
return true; return true;
} }

View File

@ -89,6 +89,7 @@ private:
void set_volume_by_selection(); void set_volume_by_selection();
// load text configuration from volume into gizmo // load text configuration from volume into gizmo
bool set_volume(ModelVolume *volume); bool set_volume(ModelVolume *volume);
void reset_volume();
// create volume from text - main functionality // create volume from text - main functionality
bool process(); bool process();