Commit 6f8e22f7 authored by Tobias WEBER's avatar Tobias WEBER
Browse files

continued with 3d plot

parent 65793b58
......@@ -298,6 +298,14 @@ void GlPlot_impl::SetObjectVisible(std::size_t idx, bool visible)
}
void GlPlot_impl::RemoveObject(std::size_t idx)
{
m_objs[idx].m_valid = false;
// TODO: remove if object has no follow-up indices
}
std::size_t GlPlot_impl::AddLinkedObject(std::size_t linkTo,
t_real_gl x, t_real_gl y, t_real_gl z)
{
......@@ -640,7 +648,7 @@ void GlPlot_impl::UpdatePicker()
if(obj.linkedObj)
linkedObj = &m_objs[*obj.linkedObj];
if(linkedObj->m_type != GlPlotObjType::TRIANGLES || !obj.m_visible)
if(linkedObj->m_type != GlPlotObjType::TRIANGLES || !obj.m_visible || !obj.m_valid)
continue;
linkedObj->m_pcolorbuf->bind();
......@@ -797,7 +805,7 @@ void GlPlot_impl::paintGL()
if(obj.linkedObj)
linkedObj = &m_objs[*obj.linkedObj];
if(!obj.m_visible) continue;
if(!obj.m_visible || !obj.m_valid) continue;
// main vertex array object
pGl->glBindVertexArray(linkedObj->m_vertexarr);
......@@ -855,7 +863,7 @@ void GlPlot_impl::paintGL()
// render object labels
for(const auto& obj : m_objs)
{
if(!obj.m_visible) continue;
if(!obj.m_visible || !obj.m_valid) continue;
if(obj.m_label != "")
{
......@@ -955,7 +963,7 @@ void GlPlot_impl::paintGL()
if(obj.linkedObj)
linkedObj = &m_objs[*obj.linkedObj];
if(!obj.m_visible) continue;
if(!obj.m_visible || !obj.m_valid) continue;
// main vertex array object
pGl->glBindVertexArray(linkedObj->m_vertexarr);
......
......@@ -103,6 +103,7 @@ struct GlPlotObj
t_mat_gl m_mat = m::unit<t_mat_gl>();
bool m_visible = true; // object shown?
bool m_valid = true; // object deleted?
t_vec3_gl m_labelPos = m::create<t_vec3_gl>({0., 0., 0.});
std::string m_label;
......@@ -192,6 +193,9 @@ public:
const t_vec_gl& color, bool bUseVertsAsNorm=false);
GlPlotObj CreateLineObject(const std::vector<t_vec3_gl>& verts, const t_vec_gl& color);
void RemoveObject(std::size_t obj);
std::size_t AddLinkedObject(std::size_t linkTo,
t_real_gl x=0, t_real_gl y=0, t_real_gl z=0);
std::size_t AddSphere(t_real_gl rad=1,
t_real_gl x=0, t_real_gl y=0, t_real_gl z=0,
t_real_gl r=0, t_real_gl g=0, t_real_gl b=0, t_real_gl a=1);
......@@ -205,8 +209,6 @@ public:
t_real_gl x=0, t_real_gl y=0, t_real_gl z=0,
t_real_gl r=0, t_real_gl g=0, t_real_gl b=0, t_real_gl a=1);
std::size_t AddCoordinateCross(t_real_gl min, t_real_gl max);
std::size_t AddLinkedObject(std::size_t linkTo,
t_real_gl x=0, t_real_gl y=0, t_real_gl z=0);
void SetObjectMatrix(std::size_t idx, const t_mat_gl& mat);
void SetObjectLabel(std::size_t idx, const std::string& label);
......
......@@ -36,11 +36,11 @@ using t_mat_cplx = m::mat<t_cplx, std::vector>;
enum : int
{
COL_NAME = 0,
COL_SCATLEN_RE = 1,
COL_SCATLEN_IM = 2,
COL_X = 3,
COL_Y = 4,
COL_Z = 5,
COL_SCATLEN_RE,
COL_SCATLEN_IM,
COL_X, COL_Y, COL_Z,
NUM_COLS
};
......@@ -78,7 +78,7 @@ StructFactDlg::StructFactDlg(QWidget* pParent) : QDialog{pParent},
m_nuclei->verticalHeader()->setDefaultSectionSize(fontMetrics().lineSpacing() + 4);
m_nuclei->verticalHeader()->setVisible(false);
m_nuclei->setColumnCount(6);
m_nuclei->setColumnCount(NUM_COLS);
m_nuclei->setHorizontalHeaderItem(COL_NAME, new QTableWidgetItem{"Name"});
m_nuclei->setHorizontalHeaderItem(COL_SCATLEN_RE, new QTableWidgetItem{"Re{b} (fm)"});
m_nuclei->setHorizontalHeaderItem(COL_SCATLEN_IM, new QTableWidgetItem{"Im{b} (fm)"});
......@@ -321,7 +321,7 @@ void StructFactDlg::AddTabItem(int row)
if(bclone)
{
for(int thecol=0; thecol<6; ++thecol)
for(int thecol=0; thecol<NUM_COLS; ++thecol)
m_nuclei->setItem(row, thecol, m_nuclei->item(m_iCursorRow, thecol)->clone());
}
else
......@@ -347,6 +347,9 @@ void StructFactDlg::AddTabItem(int row)
auto obj = m_plot->GetImpl()->AddLinkedObject(m_sphere);
m_plot->GetImpl()->SetObjectMatrix(obj, m::hom_translation<t_mat_gl>(posx, posy, posz));
m_plot->update();
m_nuclei->item(row, COL_NAME)->setData(Qt::UserRole, unsigned(obj));
}
......@@ -367,12 +370,25 @@ void StructFactDlg::DelTabItem()
// if nothing is selected, clear all items
if(m_nuclei->selectedItems().count() == 0)
{
for(int row=0; row<m_nuclei->rowCount(); ++row)
if(std::size_t obj = m_nuclei->item(row, COL_NAME)->data(Qt::UserRole).toUInt(); obj)
m_plot->GetImpl()->RemoveObject(obj);
m_plot->update();
m_nuclei->clearContents();
m_nuclei->setRowCount(0);
}
for(int row : GetSelectedRows(true))
{
// remove 3d object
if(std::size_t obj = m_nuclei->item(row, COL_NAME)->data(Qt::UserRole).toUInt(); obj)
m_plot->GetImpl()->RemoveObject(obj);
m_plot->update();
m_nuclei->removeRow(row);
}
m_ignoreChanges = 0;
Calc();
......@@ -491,6 +507,25 @@ void StructFactDlg::TableCellEntered(const QModelIndex& idx)
*/
void StructFactDlg::TableItemChanged(QTableWidgetItem *item)
{
// update associated 3d object
if(item)
{
int row = item->row();
if(std::size_t obj = m_nuclei->item(row, COL_NAME)->data(Qt::UserRole).toUInt(); obj)
{
auto *itemx = m_nuclei->item(row, COL_X);
auto *itemy = m_nuclei->item(row, COL_Y);
auto *itemz = m_nuclei->item(row, COL_Z);
t_real_gl posx, posy, posz;
std::istringstream{itemx->text().toStdString()} >> posx;
std::istringstream{itemy->text().toStdString()} >> posy;
std::istringstream{itemz->text().toStdString()} >> posz;
m_plot->GetImpl()->SetObjectMatrix(obj, m::hom_translation<t_mat_gl>(posx, posy, posz));
m_plot->update();
}
}
if(!m_ignoreChanges)
Calc();
}
......
......@@ -51,7 +51,9 @@ public:
virtual QTableWidgetItem* clone() const override
{
return new NumericTableWidgetItem<T>(this->text());
auto item = new NumericTableWidgetItem<T>(this->text());
item->setData(Qt::UserRole, this->data(Qt::UserRole));
return item;
};
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment