Skip to content

Commit 94ab25c

Browse files
committed
Implemented help button on model viewer to show help page for selected item in model tree. (#259)
1 parent 92eff87 commit 94ab25c

9 files changed

Lines changed: 79 additions & 22 deletions

File tree

FEBioLink/FEBioClass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ FEBioClassInfo FEBio::GetClassInfo(int classId)
366366
ci.classId = classId;
367367
ci.baseClassId = baseClassIndex(fac->GetBaseClassName());
368368
ci.sztype = fac->GetTypeStr();
369-
ci.szmod = fecore.GetModuleName(modId - 1);
369+
ci.szmod = (modId == 0 ? "core" : fecore.GetModuleName(modId - 1));
370370
ci.superClassName = FECoreKernel::SuperClassString(fac->GetSuperClassID());
371371
ci.spec = fac->GetSpecID();
372372
ci.allocId = fac->GetAllocatorID();

FEBioStudio/DlgAddPhysicsItem.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,11 +232,11 @@ void CDlgAddPhysicsItem::UpdateHelpURL()
232232
{
233233
int classID = ui->type->currentItem()->data(0, Qt::UserRole).toInt();
234234

235-
SetURL(classID);
235+
SetURL(ClassIDToURL(classID));
236236
}
237237
else
238238
{
239-
SetURL(-1);
239+
SetURL(QString());
240240
}
241241
}
242242

FEBioStudio/HelpDialog.cpp

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ SOFTWARE.*/
4040
#include <FEBioLink/FEBioClass.h>
4141

4242
#define MANUAL_PATH "https://febiosoftware.github.io/febio-feature-manual/features/"
43-
#define UNSELECTED_HELP "unselected_help"
4443

4544
class Ui::CHelpDialog
4645
{
@@ -74,7 +73,7 @@ class Ui::CHelpDialog
7473
};
7574

7675

77-
CHelpDialog::CHelpDialog(QWidget* parent) : QDialog(parent), ui(new Ui::CHelpDialog), m_url(UNSELECTED_HELP)
76+
CHelpDialog::CHelpDialog(QWidget* parent) : QDialog(parent), ui(new Ui::CHelpDialog)
7877
{
7978
ui->setupUi(this);
8079

@@ -83,17 +82,22 @@ CHelpDialog::CHelpDialog(QWidget* parent) : QDialog(parent), ui(new Ui::CHelpDia
8382

8483
CHelpDialog::~CHelpDialog() { delete ui; }
8584

85+
void ShowHelp(const QString& url)
86+
{
87+
QDesktopServices::openUrl(QUrl(QString(MANUAL_PATH) + url));
88+
}
89+
8690
void CHelpDialog::on_help_clicked()
8791
{
8892
UpdateHelpURL();
8993

90-
if(m_url == UNSELECTED_HELP)
94+
if(m_url.isEmpty())
9195
{
9296
QMessageBox::information(this, "Help", "Please select an item before clicking Help.");
9397
}
9498
else
9599
{
96-
QDesktopServices::openUrl(QUrl(QString(MANUAL_PATH) + m_url));
100+
ShowHelp(m_url);
97101
}
98102
}
99103

@@ -102,19 +106,23 @@ void CHelpDialog::SetLeftSideLayout(QLayout* layout)
102106
ui->helpLayout->insertLayout(0, layout);
103107
}
104108

105-
void CHelpDialog::SetURL(int classID)
109+
QString ClassIDToURL(int classID)
106110
{
107-
if(classID == -1)
108-
{
109-
m_url = UNSELECTED_HELP;
110-
return;
111-
}
111+
QString url;
112+
if (classID != -1)
113+
{
114+
FEBio::FEBioClassInfo classInfo = FEBio::GetClassInfo(classID);
112115

113-
FEBio::FEBioClassInfo classInfo = FEBio::GetClassInfo(classID);
116+
QString superClass = classInfo.superClassName;
117+
superClass.remove(0, 2).remove("_ID");
114118

115-
QString superClass = classInfo.superClassName;
116-
superClass.remove(0,2).remove("_ID");
119+
QString tmp = QString(classInfo.szmod) + "_" + superClass + "_" + QString(classInfo.sztype);
120+
url = tmp.replace(" ", "_").toLower();
121+
}
122+
return url;
123+
}
117124

118-
QString url = QString(classInfo.szmod) + "_" + superClass + "_" + QString(classInfo.sztype);
119-
m_url = url.replace(" ", "_").toLower();
120-
}
125+
void CHelpDialog::SetURL(const QString& url)
126+
{
127+
m_url = url;
128+
}

FEBioStudio/HelpDialog.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ SOFTWARE.*/
2727
#pragma once
2828
#include <QDialog>
2929

30-
#define UNSELECTED_HELP "unselected_help"
31-
3230
class QLayout;
3331

3432
namespace Ui {
@@ -52,7 +50,7 @@ protected slots:
5250
virtual void UpdateHelpURL() = 0;
5351

5452
protected:
55-
void SetURL(int classID);
53+
void SetURL(const QString& url);
5654

5755
protected:
5856
int m_module;
@@ -61,3 +59,6 @@ protected slots:
6159
private:
6260
Ui::CHelpDialog* ui;
6361
};
62+
63+
QString ClassIDToURL(int classID);
64+
void ShowHelp(const QString& url);

FEBioStudio/ModelViewer.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ SOFTWARE.*/
6060
#include "FEObjectProps.h"
6161
#include "GLHighlighter.h"
6262
#include "Command.h"
63+
#include "HelpDialog.h" // for ShowHelp
6364
using namespace std;
6465

6566
class CDlgWarnings : public QDialog
@@ -403,6 +404,44 @@ void CModelViewer::on_refreshButton_clicked()
403404
Update(false);
404405
}
405406

407+
void CModelViewer::on_helpButton_clicked()
408+
{
409+
// make sure we have something selected
410+
if (m_currentObject == nullptr)
411+
{
412+
QMessageBox::information(this, "Help", "No item selected!");
413+
return;
414+
}
415+
416+
// find the class ID
417+
int classID = -1;
418+
GMaterial* gmat = dynamic_cast<GMaterial*>(m_currentObject);
419+
if (gmat)
420+
{
421+
FEBioMaterial* pm = dynamic_cast<FEBioMaterial*>(gmat->GetMaterialProperties());
422+
if (pm)
423+
{
424+
classID = FEBio::GetClassId(pm->GetSuperClassID(), pm->GetTypeString());
425+
}
426+
}
427+
FSModelComponent* pmc = dynamic_cast<FSModelComponent*>(m_currentObject);
428+
if (pmc)
429+
{
430+
classID = FEBio::GetClassId(pmc->GetSuperClassID(), pmc->GetTypeString());
431+
}
432+
433+
// show the help page
434+
QString url = ClassIDToURL(classID);
435+
if (url.isEmpty())
436+
{
437+
QMessageBox::critical(this, "Help", "No help available for this item.");
438+
}
439+
else
440+
{
441+
ShowHelp(url);
442+
}
443+
}
444+
406445
bool CModelViewer::IsHighlightSelectionEnabled() const
407446
{
408447
return ui->highlightButton->isChecked();

FEBioStudio/ModelViewer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ public slots:
115115
void on_syncButton_clicked();
116116
void on_refreshButton_clicked();
117117
void on_highlightButton_toggled(bool);
118+
void on_helpButton_clicked();
118119
void on_props_nameChanged(const QString& txt);
119120
void on_props_selectionChanged();
120121
void on_props_dataChanged(bool b);

FEBioStudio/ui_modelviewer.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,12 @@ class Ui::CModelViewer
129129
highlightButton->setCheckable(true);
130130
highlightButton->setChecked(false);
131131

132+
QToolButton* helpButton = new QToolButton;
133+
helpButton->setIcon(QIcon(":/icons/help.png"));
134+
helpButton->setObjectName("helpButton");
135+
helpButton->setAutoRaise(true);
136+
helpButton->setToolTip("<font color=\"black\">Help");
137+
132138
// filter box
133139
m_filter = new QComboBox;
134140
m_filter->addItems(QStringList() << "All items" << "Geometry" << "Materials" << "Physics" << "Steps" << "Jobs" << "Studies" << "Images");
@@ -184,6 +190,7 @@ class Ui::CModelViewer
184190
buttonLayout->addWidget(srcButton);
185191
buttonLayout->addWidget(syncButton);
186192
buttonLayout->addWidget(refreshButton);
193+
buttonLayout->addWidget(helpButton);
187194
buttonLayout->addStretch();
188195
buttonLayout->setContentsMargins(0,0,0,0);
189196

febiostudio.qrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,5 +212,6 @@
212212
<file>icons/helix.png</file>
213213
<file>icons/teapot.png</file>
214214
<file>icons/foam.png</file>
215+
<file>icons/help.png</file>
215216
</qresource>
216217
</RCC>

icons/help.png

5.28 KB
Loading

0 commit comments

Comments
 (0)