Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(GraphView): use tools::Variant and tools::VariantVector to handle selection #141

Merged
merged 5 commits into from
Dec 2, 2024
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
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ add_library(
src/tools/core/assertions.h
src/tools/core/format.cpp
src/tools/core/format.h
src/tools/core/hash.h
src/tools/core/Hash.h
src/tools/core/log.cpp
src/tools/core/log.h
src/tools/core/math.h
Expand Down
24 changes: 23 additions & 1 deletion src/ndbl/core/Graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -611,4 +611,26 @@ std::vector<Scope *> Graph::scopes()
if ( node->scope() )
result.push_back( node->scope() );
return result;
}
}

void Graph::destroy_next_frame(Scope *scope)
{
const bool with_inputs = true;
destroy_next_frame_ex( scope->owner(), with_inputs );

for ( Node* node : scope->child() )
destroy_next_frame_ex( node, with_inputs );

for ( Scope* scope : scope->partition() )
destroy_next_frame( scope );
}

void Graph::destroy_next_frame_ex(Node *node, bool with_inputs)
{
m_node_to_delete.insert(node);

if ( with_inputs )
for ( auto input : node->inputs() )
if ( node->scope() == input->scope() )
destroy_next_frame_ex( input, with_inputs );
}
4 changes: 3 additions & 1 deletion src/ndbl/core/Graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ namespace ndbl
std::set<Scope *> root_scopes();
NodeRegistry& nodes() {return m_node_registry;}
const NodeRegistry& nodes()const {return m_node_registry;}
void destroy_next_frame(Node* node) { m_node_to_delete.insert(node ); }
void destroy_next_frame_ex(Node* node, bool with_inputs );
void destroy_next_frame(Node* node) { destroy_next_frame_ex( node, false ); }
void destroy_next_frame(Scope* scope);

template<typename T> inline VariableNode* create_variable_decl(const char* _name = "var"){ return create_variable_decl(tools::type::get<T>(), _name); }
template<typename T> inline LiteralNode* create_literal() { return create_literal( tools::type::get<T>()); }
Expand Down
14 changes: 7 additions & 7 deletions src/ndbl/core/language/Nodlang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include "tools/core/reflection/reflection"
#include "tools/core/format.h"
#include "tools/core/log.h"
#include "tools/core/hash.h"
#include "tools/core/Hash.h"

#include "ndbl/core/Utils.h"
#include "ndbl/core/DirectedEdge.h"
Expand Down Expand Up @@ -120,15 +120,15 @@ Nodlang::Nodlang(bool _strict)

for( auto [keyword, token_t] : m_definition.keywords)
{
m_token_t_by_keyword.insert({hash::hash_cstr(keyword), token_t});
m_token_t_by_keyword.insert({Hash::hash32(keyword), token_t});
m_keyword_by_token_t.insert({token_t, keyword});
}

for( auto [keyword, token_t, type] : m_definition.types)
{
m_keyword_by_token_t.insert({token_t, keyword});
m_keyword_by_type_id.insert({type->id(), keyword});
m_token_t_by_keyword.insert({hash::hash_cstr(keyword), token_t});
m_token_t_by_keyword.insert({Hash::hash32(keyword), token_t});
m_token_t_by_type_id.insert({type->id(), token_t});
m_type_by_token_t.insert({token_t, type});
}
Expand Down Expand Up @@ -1029,8 +1029,8 @@ Token Nodlang::parse_token(const char* buffer, size_t buffer_size, size_t& globa

Token_t type = Token_t::identifier;

auto hash = hash::hash( buffer + start_pos, cursor - start_pos );
auto keyword_found = m_token_t_by_keyword.find( hash );
const u32_t key = Hash::hash32( buffer + start_pos, cursor - start_pos );
auto keyword_found = m_token_t_by_keyword.find( key );
if (keyword_found != m_token_t_by_keyword.end())
{
// a keyword has priority over identifier
Expand Down Expand Up @@ -1813,8 +1813,8 @@ const IInvokable* Nodlang::find_function(const char* _signature_hint) const
return nullptr;
}

auto hash = hash::hash_cstr(_signature_hint);
return find_function( hash );
const u32_t key = Hash::hash32(_signature_hint);
return find_function( key );
}

const tools::IInvokable* Nodlang::find_function(u32_t _hash) const
Expand Down
2 changes: 1 addition & 1 deletion src/ndbl/core/language/Nodlang.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include "tools/core/reflection/reflection"
#include "tools/core/System.h"
#include "tools/core/hash.h"
#include "tools/core/Hash.h"
#include "tools/core/Optional.h"

#include "ndbl/core/VariableNode.h"
Expand Down
5 changes: 2 additions & 3 deletions src/ndbl/gui/Action.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ namespace ndbl

// 1) Basic actions (simple events)

using Action_DeleteNode = Action<Event_DeleteNode>;
using Action_ArrangeNode = Action<Event_ArrangeNode>;
using Action_DeleteNode = Action<Event_DeleteSelection>;
using Action_ArrangeNode = Action<Event_ArrangeSelection>;
using Action_ToggleFolding = Action<Event_ToggleFolding>;
using Action_SelectNext = Action<Event_SelectNext>;
using Action_ToggleIsolate = Action<Event_ToggleIsolationFlags>;
using Action_SelectionChange = Action<Event_GraphViewSelectionChanged>;
using Action_MoveGraph = Action<Event_MoveSelection>;

// 2) Advanced actions (custom events)
Expand Down
12 changes: 2 additions & 10 deletions src/ndbl/gui/Event.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "Event.h"
#include "FrameMode.h"
#include "SlotView.h"
#include "Selection.h"

namespace ndbl
{
Expand Down Expand Up @@ -65,8 +64,8 @@ namespace ndbl
Node* node;
};
using Event_DeleteEdge = tools::Event<EventID_DELETE_EDGE, EventPayload_SlotPair>;
using Event_DeleteNode = tools::Event<EventID_DELETE_NODE, EventPayload_Node>;
using Event_ArrangeNode = tools::Event<EventID_ARRANGE_NODE, EventPayload_Node>;
using Event_DeleteSelection = tools::Event<EventID_DELETE_NODE, EventPayload_Node>;
using Event_ArrangeSelection = tools::Event<EventID_ARRANGE_NODE>;
using Event_SelectNext = tools::Event<EventID_SELECT_NEXT, EventPayload_Node>;

enum ToggleFoldingMode
Expand All @@ -80,13 +79,6 @@ namespace ndbl
};
using Event_ToggleFolding = tools::Event<EventID_TOGGLE_FOLDING, EventPayload_ToggleFoldingEvent>;

struct EventPayload_SelectionChange
{
GraphView* graph_view;
// Selection old_selection; was unused
};
using Event_GraphViewSelectionChanged = tools::Event<EventID_SELECTION_CHANGE, EventPayload_SelectionChange>;

struct EventPayload_CreateNode
{
CreateNodeType node_type; // The note type to create
Expand Down
Loading
Loading