Skip to content

Commit

Permalink
Update function handling and argument controllers
Browse files Browse the repository at this point in the history
The graph_api.rs functions for creating and deleting nodes have been renamed and updated to better reflect their functionality (new_node to add_node, and add a remove_node function). In q
  • Loading branch information
xorza committed Jun 9, 2024
1 parent b1501c9 commit 963e81f
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 19 deletions.
6 changes: 5 additions & 1 deletion ScenariumEditor.QML/qml/Node.qml
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ Rectangle {
id: triggerPin
width: 10
height: 10
radius: 5
color: triggerMouseArea.containsMouse
? triggerMouseArea.containsPress
? Qt.darker("yellow")
: Qt.lighter("yellow")
: "yellow"
radius: 5
x: -5
y: -5

Expand All @@ -67,6 +67,10 @@ Rectangle {
id: triggerMouseArea
anchors.fill: parent
hoverEnabled: true

onClicked: {
nodeController.trigger.selected()
}
}
}

Expand Down
11 changes: 8 additions & 3 deletions ScenariumEditor.QML/qml/NodeController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@


NodeController::NodeController(QObject *parent) : QObject(parent) {
this->m_trigger = new ArgumentController(this);
trigger()->setName("Trigger");
m_trigger = new ArgumentController(this);
m_trigger->setType(ArgumentController::ArgumentType::Trigger);
m_trigger->setIndex(0);
m_trigger->setName("Trigger");
}

void ArgumentController::setName(const QString &name) {
Expand Down Expand Up @@ -33,7 +35,10 @@ void ArgumentController::setItem(QQuickItem *item) {
}

m_item = item;
emit itemChanged();
}

void ArgumentController::selected() {

}

void NodeController::setSelected(bool selected) {
Expand Down
55 changes: 49 additions & 6 deletions ScenariumEditor.QML/qml/NodeController.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,21 @@ Q_OBJECT

Q_PROPERTY(QString name READ name NOTIFY nameChanged)
Q_PROPERTY(QPointF viewPos READ viewPos WRITE setViewPos NOTIFY viewPosChanged)
Q_PROPERTY(QQuickItem *item READ item WRITE setItem NOTIFY itemChanged)
Q_PROPERTY(QQuickItem *item READ item WRITE setItem)

Q_PROPERTY(ArgumentType type READ type)


public:
enum class ArgumentType {
Input,
Output,
Event,
Trigger
};

Q_ENUM(ArgumentType)

explicit ArgumentController(QObject *parent = nullptr) : QObject(parent) {}

~ArgumentController() override = default;
Expand All @@ -35,19 +47,42 @@ Q_OBJECT

void setItem(QQuickItem *item);

[[nodiscard]] ArgumentType type() const {
return m_type;
}

void setType(ArgumentType type) {
m_type = type;
}

[[nodiscard]] uint32_t index() const {
return idx;
}

void setIndex(uint32_t index) {
idx = index;
}


signals:

void nameChanged();

void viewPosChanged();

void itemChanged();
void selectedChenged();

public slots:

void selected();


private:
QString m_name;
QString m_name{};
QPointF m_viewPos{};
QQuickItem *m_item{};
ArgumentType m_type{};
uint32_t idx{};
};


Expand All @@ -67,7 +102,7 @@ Q_OBJECT


public:
explicit NodeController(QObject *parent = nullptr) ;
explicit NodeController(QObject *parent = nullptr);

~NodeController() override = default;

Expand All @@ -82,6 +117,9 @@ Q_OBJECT
}

void addInput(ArgumentController *const input) {
input->setType(ArgumentController::ArgumentType::Input);
input->setIndex(m_inputs.size());

m_inputs.push_back(input);
emit inputsChanged();
}
Expand All @@ -91,6 +129,9 @@ Q_OBJECT
}

void addOutput(ArgumentController *const output) {
output->setType(ArgumentController::ArgumentType::Output);
output->setIndex(m_outputs.size());

m_outputs.push_back(output);
emit outputsChanged();
}
Expand All @@ -113,6 +154,8 @@ Q_OBJECT
}

void addEvent(ArgumentController *const event) {
event->setType(ArgumentController::ArgumentType::Event);
event->setIndex(m_events.size());
m_events.push_back(event);
emit eventsChanged();
}
Expand All @@ -129,8 +172,6 @@ Q_OBJECT
}




void updateViewPos();

signals:
Expand All @@ -151,6 +192,8 @@ Q_OBJECT

void triggerChanged();

void argumentSelected(ArgumentController *arg);


private:
QString m_name{};
Expand Down
12 changes: 9 additions & 3 deletions ScenariumEditor.QML/src/CoreContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ DLL_IMPORT void destroy_context(void *ctx);

DLL_IMPORT FfiBuf get_funcs(void *ctx);
DLL_IMPORT FfiBuf get_nodes(void *ctx);
DLL_IMPORT FfiNode new_node(void *ctx, FfiUuid func_id);
DLL_IMPORT FfiNode add_node(void *ctx, FfiUuid func_id);
DLL_IMPORT FfiNode remove_node(void *ctx, FfiUuid node_id);

}

Expand Down Expand Up @@ -82,12 +83,17 @@ std::vector<Node> Ctx::get_nodes() const {
return result;
}

Node Ctx::new_node(const uuid &func_id) const {
Node Ctx::add_node(const uuid &func_id) const {
auto ffi_uuid = to_ffi(func_id);
auto ffi_node = ::new_node(this->ctx, ffi_uuid);
auto ffi_node = ::add_node(this->ctx, ffi_uuid);
return Node{ffi_node};
}

void Ctx::remove_node(const uuid &node_id) const {
auto ffi_uuid = to_ffi(node_id);
::remove_node(this->ctx, ffi_uuid);
}

Func::Func(const FfiFunc &ffi_func) {
this->id = uuid{Buf(ffi_func.id).to_string()};
this->name = Buf(ffi_func.name).to_string();
Expand Down
4 changes: 3 additions & 1 deletion ScenariumEditor.QML/src/CoreContext.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ struct Ctx {

[[nodiscard]] std::vector<Node> get_nodes() const;

[[nodiscard]] Node new_node(const uuid &func_id) const;
[[nodiscard]] Node add_node(const uuid &func_id) const;

void remove_node(const uuid &node_id) const;
};

24 changes: 20 additions & 4 deletions ScenariumEditor.QML/tests/interop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,31 @@ TEST_CASE("Uuid tests", "[uuid]") {
}


TEST_CASE("New node 1", "[context]") {
TEST_CASE("add node", "[context]") {
auto ctx = Ctx{};

auto nodes1 = ctx.get_nodes();
REQUIRE(nodes1.empty());

auto funcs = ctx.get_funcs();
auto new_node = ctx.new_node(funcs[0].id);
REQUIRE(!funcs.empty());

auto nodes2 = ctx.get_nodes();
auto new_node = ctx.add_node(funcs[0].id);

REQUIRE(nodes1.size() + 1 == nodes2.size());
auto nodes = ctx.get_nodes();

REQUIRE(1 == nodes.size());
}


TEST_CASE("remove node", "[context]") {
auto ctx = Ctx{};

auto funcs = ctx.get_funcs();
auto new_node = ctx.add_node(funcs[0].id);
ctx.remove_node(new_node.id);

auto nodes = ctx.get_nodes();

REQUIRE(nodes.empty());
}
10 changes: 9 additions & 1 deletion cs_interop/src/graph_api.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::ffi::c_void;

use graph::function::FuncId;
use graph::graph::NodeId;

use crate::{get_context, FfiBuf};
use crate::utils::FfiUuid;
Expand Down Expand Up @@ -49,7 +50,7 @@ extern "C" fn get_nodes(ctx: *mut c_void) -> FfiBuf {
}

#[no_mangle]
unsafe extern "C" fn new_node(ctx: *mut c_void, func_id: FfiUuid) -> FfiNode {
unsafe extern "C" fn add_node(ctx: *mut c_void, func_id: FfiUuid) -> FfiNode {
let context = get_context(ctx);

let id: FuncId = uuid::Uuid::from(func_id).into();
Expand All @@ -60,3 +61,10 @@ unsafe extern "C" fn new_node(ctx: *mut c_void, func_id: FfiUuid) -> FfiNode {
context.graph.nodes().last().unwrap().into()
}

#[no_mangle]
unsafe extern "C" fn remove_node(ctx: *mut c_void, node_id: FfiUuid) {
let context = get_context(ctx);

let node_id: NodeId = uuid::Uuid::from(node_id).into();
context.graph.remove_node_by_id(node_id);
}

0 comments on commit 963e81f

Please sign in to comment.