Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/gui2/models/enumOptionsModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ void EnumOptionsModel::setData(std::shared_ptr<const EnumOptionsBase> options)
/*
* QAbstractItemModel overrides
*/

int EnumOptionsModel::rowCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
Expand Down
2 changes: 2 additions & 0 deletions src/gui2/models/enumRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "math/windowFunction.h"
#include "nodes/gr.h"
#include "nodes/md.h"
#include "nodes/registry.h"

std::map<std::type_index, std::shared_ptr<EnumOptionsModel>> EnumRegistry::options_;

Expand Down Expand Up @@ -35,6 +36,7 @@ void EnumRegistry::instantiateOptions()
};

options_ = {{typeid(StructureFactors::NormalisationType), wrap(StructureFactors::normalisationTypes())},
{typeid(NodeRegistry::Category), wrap(NodeRegistry::category())},
{typeid(GRNode::PartialsMethod), wrap(GRNode::partialsMethods())},
{typeid(MDNode::TimestepType), wrap(MDNode::timestepType())},
{typeid(WindowFunction::Form), wrap(WindowFunction::forms())}};
Expand Down
36 changes: 33 additions & 3 deletions src/gui2/models/nodeRegistryModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Copyright (c) 2026 Team Dissolve and contributors

#include "gui2/models/nodeRegistryModel.h"
#include "enumRegistry.h"
#include "nodes/dissolve.h"

NodeRegistryModel::NodeRegistryModel(QObject *parent)
Expand Down Expand Up @@ -42,14 +43,43 @@ int &NodeRegistryModel::tally(QString nodeType)
return entries_[idx].tally;
}

// Instantiate node from registry
void NodeRegistryModel::instantiateNode(int x, int y, QVariant type)
// Return node names by category
QList<QVariantMap> NodeRegistryModel::nodeNames(QString category)
{
QList<QVariantMap> names;
auto categoryEnum = NodeRegistry::category().enumeration(category.toStdString());
auto nodes = NodeRegistry::categoricalProducers_;
for (const auto &[name, _] : nodes[categoryEnum])
{
auto nodeName = QString::fromStdString(std::string(name));
auto descriptionIt =
std::find_if(entries_.begin(), entries_.end(), [&nodeName](const auto &entry) { return entry.name == nodeName; });
auto descriptionIdx = std::distance(entries_.begin(), descriptionIt);
QVariantMap nodeInfo;
nodeInfo[QString::fromStdString("name")] = nodeName;
nodeInfo[QString::fromStdString("description")] = entries_[descriptionIdx].description;
names.push_back(nodeInfo);
}
return names;
}

// Return the enum options for the node categories
EnumOptionsModel *NodeRegistryModel::categories() { return EnumRegistry::options(typeid(NodeRegistry::Category)).get(); }

// Return a unique default node name for a given node type
QString NodeRegistryModel::uniqueNodeName(QVariant type)
{
increment(type.toString());
const auto count = tally(type.toString());
std::string prefix = type.toString().toStdString() + "_";
auto name = prefix + std::format("{}", count);
graphModel_->emplace_back(x, y, type, name);
return QString::fromStdString(name);
}

// Instantiate node from registry
void NodeRegistryModel::instantiateNode(int x, int y, QVariant type)
{
graphModel_->emplace_back(x, y, type, uniqueNodeName(type).toStdString());
}

// Set the graph model
Expand Down
7 changes: 7 additions & 0 deletions src/gui2/models/nodeRegistryModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#pragma once

#include "enumOptionsModel.h"
#include "gui2/models/graphModel.h"
#include "nodes/registry.h"
#include <QAbstractListModel>
Expand Down Expand Up @@ -55,6 +56,12 @@ class NodeRegistryModel : public QAbstractListModel
GraphModel *graphModel_{nullptr};

public:
// Return a unique default node name for a given node type
Q_INVOKABLE QString uniqueNodeName(QVariant type);
// Return node names by category
Q_INVOKABLE QList<QVariantMap> nodeNames(QString category);
// Return the enum options for the node categories
Q_INVOKABLE EnumOptionsModel *categories();
// Instantiate node from registry
Q_INVOKABLE void instantiateNode(int x, int y, QVariant type);
// Set the graph model
Expand Down
143 changes: 30 additions & 113 deletions src/gui2/qml/nodeGraph/GraphView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ Pane {

Component.onCompleted: nodeRegistry.setGraphModel(rootGraphModel);

/*
MouseArea {
id: ctxMenuCatcher

Expand All @@ -24,133 +23,51 @@ Pane {

onClicked: contextMenu.popup()

property point mousePos: Qt.point(ctxMenuCatcher.mouseX, ctxMenuCatcher.mouseY)

Menu {
id: contextMenu

Menu {
title: "Math"

MenuItem {
text: "Add"

onClicked: graphRoot.rootGraphModel.emplace_back(Math.round(ctxMenuCatcher.mouseX), Math.round(ctxMenuCatcher.mouseY), "Add", "New Node")
}
MenuItem {
text: "Derivative"

onClicked: graphRoot.rootGraphModel.emplace_back(Math.round(ctxMenuCatcher.mouseX), Math.round(ctxMenuCatcher.mouseY), "Derivative", "New Node")
}
MenuItem {
text: "Dot Product"

onClicked: graphRoot.rootGraphModel.emplace_back(Math.round(ctxMenuCatcher.mouseX), Math.round(ctxMenuCatcher.mouseY), "DotProduct", "New Node")
}
MenuItem {
text: "Integrator"

onClicked: graphRoot.rootGraphModel.emplace_back(Math.round(ctxMenuCatcher.mouseX), Math.round(ctxMenuCatcher.mouseY), "Integrator", "New Node")
}
MenuItem {
text: "Multiply"

onClicked: graphRoot.rootGraphModel.emplace_back(Math.round(ctxMenuCatcher.mouseX), Math.round(ctxMenuCatcher.mouseY), "Multiply", "New Node")
}
MenuItem {
text: "Number"
Repeater {
model: nodeRegistry.categories()
Comment thread
RobBuchananCompPhys marked this conversation as resolved.

onClicked: graphRoot.rootGraphModel.emplace_back(Math.round(ctxMenuCatcher.mouseX), Math.round(ctxMenuCatcher.mouseY), "Number", "New Number")
}
MenuItem {
text: "Subtract"

onClicked: graphRoot.rootGraphModel.emplace_back(Math.round(ctxMenuCatcher.mouseX), Math.round(ctxMenuCatcher.mouseY), "Subtract", "New Node")
}
MenuItem {
text: "Vec3Assembly"
delegate: Item {
id: menuDelegateItem
required property var display
property Menu innerMenu: innerMenuComponent.createObject(parent)

onClicked: graphRoot.rootGraphModel.emplace_back(Math.round(ctxMenuCatcher.mouseX), Math.round(ctxMenuCatcher.mouseY), "Vec3Assembly", "New Node")
}
MenuItem {
text: "Vec3Decompostion"
Component {
id: innerMenuComponent

onClicked: graphRoot.rootGraphModel.emplace_back(Math.round(ctxMenuCatcher.mouseX), Math.round(ctxMenuCatcher.mouseY), "Vec3Decomposition", "New Node")
}
}
Menu {
title: "Action"
Menu {
id: nodeCategoryMenu

MenuItem {
text: "Atomic MC"
title: menuDelegateItem.display

onClicked: graphRoot.rootGraphModel.emplace_back(Math.round(ctxMenuCatcher.mouseX), Math.round(ctxMenuCatcher.mouseY), "AtomicMC", "New Node")
}
MenuItem {
text: "G(r)"
Repeater {
model: nodeRegistry.nodeNames(menuDelegateItem.display)

onClicked: rootGraphModel.emplace_back(Math.round(ctxMenuCatcher.mouseX), Math.round(ctxMenuCatcher.mouseY), "GR", "New Node")
delegate: MenuItem {
required property var modelData
text: modelData.name
onClicked: graphRoot.rootGraphModel.emplace_back(ctxMenuCatcher.mousePos.x, ctxMenuCatcher.mousePos.y, modelData.name, nodeRegistry.uniqueNodeName(modelData.name), false)
ToolTip.text: modelData.description
ToolTip.visible: hovered
ToolTip.delay: 500
}
}
}
}
}
MenuItem {
text: "Insert"

onClicked: graphRoot.rootGraphModel.emplace_back(Math.round(ctxMenuCatcher.mouseX), Math.round(ctxMenuCatcher.mouseY), "Insert", "New Node")
onItemAdded: (index, item) => {
contextMenu.addMenu(item.innerMenu)
}
MenuItem {
text: "Molecular Dynamics"

onClicked: graphRoot.rootGraphModel.emplace_back(Math.round(ctxMenuCatcher.mouseX), Math.round(ctxMenuCatcher.mouseY), "MD", "New Node")
}
MenuItem {
text: "S(q)"

onClicked: rootGraphModel.emplace_back(Math.round(ctxMenuCatcher.mouseX), Math.round(ctxMenuCatcher.mouseY), "SQ", "New Node")
}
}
Menu {
title: "Data"

MenuItem {
text: "Atomic Species"

onClicked: graphRoot.rootGraphModel.emplace_back(Math.round(ctxMenuCatcher.mouseX), Math.round(ctxMenuCatcher.mouseY), "AtomicSpecies", "New Node")
}
MenuItem {
text: "Configuration"

onClicked: graphRoot.rootGraphModel.emplace_back(Math.round(ctxMenuCatcher.mouseX), Math.round(ctxMenuCatcher.mouseY), "Configuration", "New Node")
}
MenuItem {
text: "Forcefield"

onClicked: forcefieldDialog.open()

ForcefieldDialog {
id: forcefieldDialog

graphModel: graphRoot.rootGraphModel
posx: Math.round(ctxMenuCatcher.mouseX)
posy: Math.round(ctxMenuCatcher.mouseY)
}
}
MenuItem {
text: "Graph"

onClicked: graphRoot.rootGraphModel.emplace_back(Math.round(ctxMenuCatcher.mouseX), Math.round(ctxMenuCatcher.mouseY), "Graph", "New Graph")
}
MenuItem {
text: "Species"

onClicked: speciesDialog.open()

SpeciesDialog {
id: speciesDialog

graphModel: graphRoot.rootGraphModel
}
onItemRemoved: (index, item) => {
contextMenu.removeMenu(item.innerMenu)
}
}
}
}
*/
// Edge connections
Repeater {
model: graphRoot.parameterEndPointsModel
Expand Down
2 changes: 1 addition & 1 deletion src/nodes/dotProduct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ DotProductNode::DotProductNode(Graph *parentGraph) : Node(parentGraph)
*/

// Return type of the node
std::string_view DotProductNode::type() const { return "Dot Product"; }
std::string_view DotProductNode::type() const { return "DotProduct"; }

// Return short summary of the node's purpose
std::string_view DotProductNode::summary() const { return "Compute the dot product of vectors u and v"; }
Expand Down
2 changes: 1 addition & 1 deletion src/nodes/exportDLPUtilsPDensData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ ExportDLPUtilsPDensDataNode::ExportDLPUtilsPDensDataNode(Graph *parentGraph) : N
*/

// Return type of the node
std::string_view ExportDLPUtilsPDensDataNode::type() const { return "ExportPDensData"; }
std::string_view ExportDLPUtilsPDensDataNode::type() const { return "ExportDLPUtilsPDensData"; }

// Return short summary of the node's purpose
std::string_view ExportDLPUtilsPDensDataNode::summary() const { return "Export 3D data in DLPUtils PDens format"; }
Expand Down
2 changes: 1 addition & 1 deletion src/nodes/exportXYZTrajectory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ ExportXYZTrajectoryNode::ExportXYZTrajectoryNode(Graph *parentGraph) : Node(pare
*/

// Return type of the node
std::string_view ExportXYZTrajectoryNode::type() const { return "ExportTrajectory"; }
std::string_view ExportXYZTrajectoryNode::type() const { return "ExportXYZTrajectory"; }

// Return short summary of the node's purpose
std::string_view ExportXYZTrajectoryNode::summary() const
Expand Down
4 changes: 2 additions & 2 deletions src/nodes/importXYData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ ImportXYDataNode::ImportXYDataNode(Graph *parentGraph) : Node(parentGraph)
*/

// Return type of the node
std::string_view ImportXYDataNode::type() const { return "Data1DImport"; }
std::string_view ImportXYDataNode::type() const { return "ImportXYData"; }

// Return short summary of the node's purpose
std::string_view ImportXYDataNode::summary() const { return "Import 1D data"; }
std::string_view ImportXYDataNode::summary() const { return "Import 1D (XY) data"; }

/*
* Processing
Expand Down
Loading
Loading