Skip to content

Commit

Permalink
Added option to delete a watch variable from the FEBio monitor's mode…
Browse files Browse the repository at this point in the history
…l panel.
  • Loading branch information
SteveMaas1978 committed Mar 8, 2025
1 parent 4489897 commit e4314e2
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 5 deletions.
34 changes: 31 additions & 3 deletions FEBioMonitor/FEBioModelPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,13 @@ class CFEBioDataModel : public QAbstractItemModel
}
else if (row == N)
{
beginInsertRows(QModelIndex(), row, row + 1);
m_doc->AddWatchVariable(value.toString());
endInsertRows();
QString v = value.toString();
if (!v.isEmpty())
{
beginInsertRows(QModelIndex(), row, row + 1);
m_doc->AddWatchVariable(value.toString());
endInsertRows();
}
}
}
return false;
Expand All @@ -165,6 +169,8 @@ class CFEBioDataModel : public QAbstractItemModel
endResetModel();
}

FEBioMonitorDoc* GetDocument() { return m_doc; }

private:
FEBioMonitorDoc* m_doc;
};
Expand Down Expand Up @@ -223,6 +229,20 @@ class Ui::CFEBioModelPanel
m_tree->setModel(nullptr);
}
}

void deleteSelection()
{
if (m_data == nullptr) return;
FEBioMonitorDoc* doc = m_data->GetDocument(); assert(doc);
if (doc == nullptr) return;
QModelIndexList indices = m_tree->selectionModel()->selectedIndexes();
if (indices.size() == 2) // size==2 because we have two columns.
{
QModelIndex i = indices[0];
doc->DeleteWatchVariable(i.row());
m_data->update();
}
}
};

CFEBioModelPanel::CFEBioModelPanel(CMainWindow* wnd, QWidget* parent) : CWindowPanel(wnd, parent), ui(new Ui::CFEBioModelPanel)
Expand All @@ -235,6 +255,14 @@ FEBioMonitorDoc* CFEBioModelPanel::GetCurrentDocument()
return dynamic_cast<FEBioMonitorDoc*>(GetMainWindow()->GetDocument());
}

void CFEBioModelPanel::keyPressEvent(QKeyEvent* e)
{
if (e->key() == Qt::Key_Delete)
{
ui->deleteSelection();
}
}

void CFEBioModelPanel::Clear()
{
ui->reset();
Expand Down
2 changes: 2 additions & 0 deletions FEBioMonitor/FEBioModelPanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ class CFEBioModelPanel : public CWindowPanel

FEBioMonitorDoc* GetCurrentDocument();

void keyPressEvent(QKeyEvent* e) override;

public slots:
void launchMatrixInspector();

Expand Down
9 changes: 7 additions & 2 deletions FEBioMonitor/FEBioMonitorDoc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ bool FEBioMonitorDoc::processFEBioEvent(FEModel* fem, int nevent)

if (nevent == CB_INIT) InitDefaultWatchVariables();
UpdateAllWatchVariables();
emit updateViews(false, updateGL);
emit updateViews(nevent == CB_INIT, updateGL);
m->mutex.lock();

constexpr double eps = std::numeric_limits<double>::epsilon();
Expand All @@ -631,7 +631,7 @@ bool FEBioMonitorDoc::processFEBioEvent(FEModel* fem, int nevent)
{
m->outputBuffer += "\n[paused on " + eventToString(nevent) + "]\n";
emit outputReady();
emit updateViews(true, true);
emit updateViews(false, true);
m->isPaused = true;
jobIsPaused.wait(&m->mutex);
m->isPaused = false;
Expand Down Expand Up @@ -695,6 +695,11 @@ void FEBioMonitorDoc::SetWatchVariable(int n, const QString& name)
UpdateWatchVariable(*var);
}

void FEBioMonitorDoc::DeleteWatchVariable(int n)
{
m->watches.removeAt(n);
}

void FEBioMonitorDoc::InitDefaultWatchVariables()
{
m->watches.clear();
Expand Down
2 changes: 2 additions & 0 deletions FEBioMonitor/FEBioMonitorDoc.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ class FEBioMonitorDoc : public CGLModelDocument
int GetWatchVariables() const;
void SetWatchVariable(int n, const QString& name);

void DeleteWatchVariable(int n);

public:
FEGlobalMatrix* GetStiffnessMatrix();

Expand Down

0 comments on commit e4314e2

Please # to comment.