#include "blueprints_engine.h" #include "containers/root_container.h" #include "nodes.h" #include #include #include BlueprintsEngine::BlueprintsEngine() : m_GraphFilename("BlueprintsGraph.json") { } // ============================================================================ // File I/O // ============================================================================ bool BlueprintsEngine::LoadGraph(const std::string& filename) { ClearError(); // Note: This is a virtual method that will be overridden by subclasses // BlueprintsCLI will provide its own implementation // App will use its existing SaveGraph/LoadGraph methods SetError("LoadGraph must be implemented by subclass"); return false; } bool BlueprintsEngine::SaveGraph(const std::string& filename) { ClearError(); // Note: Virtual method - will be overridden by subclasses SetError("SaveGraph must be implemented by subclass"); return false; } // ============================================================================ // Validation // ============================================================================ bool BlueprintsEngine::ValidateGraph() { ClearError(); auto* container = GetActiveRootContainer(); if (!container) { SetError("No active container"); return false; } // Basic checks if (!ValidateNodeConnections()) { return false; } if (!ValidatePinTypes()) { return false; } if (!ValidateNoCycles()) { return false; } return true; } bool BlueprintsEngine::ValidateNodeConnections() { // Virtual method - subclasses will implement return true; } bool BlueprintsEngine::ValidatePinTypes() { // Virtual method - subclasses will implement return true; } bool BlueprintsEngine::ValidateNoCycles() { auto* container = GetActiveRootContainer(); if (!container) return false; // TODO: Implement cycle detection // For now, just return true return true; } // ============================================================================ // Execution // ============================================================================ std::vector BlueprintsEngine::GetExecutionOrder() { // Virtual method - subclasses will implement return std::vector(); } bool BlueprintsEngine::ExecuteNode(Node* node) { if (!node) return false; // TODO: Implement actual node execution // This would evaluate the node's operation based on input values // and produce output values printf("Executing node: %s (ID: %d)\n", node->Name.c_str(), node->ID.Get()); return true; } bool BlueprintsEngine::ExecuteGraph() { ClearError(); if (!ValidateGraph()) { return false; } auto executionOrder = GetExecutionOrder(); printf("Executing %zu nodes...\n", executionOrder.size()); for (Node* node : executionOrder) { if (!ExecuteNode(node)) { SetError("Failed to execute node: " + node->Name); return false; } } printf("Graph execution completed successfully\n"); return true; } // ============================================================================ // Graph Info // ============================================================================ std::map BlueprintsEngine::GetGraphInfo() const { // Virtual method - subclasses will implement std::map info; info["error"] = "GetGraphInfo must be implemented by subclass"; return info; } // ============================================================================ // Export // ============================================================================ std::string BlueprintsEngine::ExportGraph(const std::string& format) const { ClearError(); if (format == "json") { // TODO: Implement JSON export (different from internal format) return "{}"; } else if (format == "xml") { // TODO: Implement XML export return ""; } else if (format == "yaml") { // TODO: Implement YAML export return ""; } else if (format == "dot") { // TODO: Implement Graphviz DOT export return ""; } return ""; } // ============================================================================ // ID Management (delegates to GraphState) // ============================================================================ int BlueprintsEngine::GetNextId() { return m_GraphState.GetNextId(); } ed::LinkId BlueprintsEngine::GetNextLinkId() { return m_GraphState.GetNextLinkId(); } // ============================================================================ // UUID Management (delegates to UuidGenerator) // ============================================================================ uint32_t BlueprintsEngine::GenerateRandomUuid() { return m_UuidGenerator.GenerateRandom(); } uint32_t BlueprintsEngine::GenerateSequentialUuid() { return m_UuidGenerator.GenerateSequential(); } std::string BlueprintsEngine::UuidToHexString(uint32_t uuid) { return m_UuidGenerator.ToHexString(uuid); } uint32_t BlueprintsEngine::HexStringToUuid(const std::string& hexString) { return m_UuidGenerator.FromHexString(hexString); } Uuid64 BlueprintsEngine::GenerateRandomUuid64() { return m_UuidGenerator.GenerateRandom64(); } Uuid64 BlueprintsEngine::GenerateSequentialUuid64() { return m_UuidGenerator.GenerateSequential64(); } std::string BlueprintsEngine::UuidToHexString64(const Uuid64& uuid) { return m_UuidGenerator.ToHexString64(uuid); } Uuid64 BlueprintsEngine::HexStringToUuid64(const std::string& hexString) { return m_UuidGenerator.FromHexString64(hexString); } std::string BlueprintsEngine::UuidToStandardString(const Uuid64& uuid) { // Format as standard UUID string char buf[64]; snprintf(buf, sizeof(buf), "%08x-%04x-%04x-%04x-%08x%04x", 0, 0, 0, 0, uuid.high, uuid.low); return std::string(buf); } Uuid64 BlueprintsEngine::StandardStringToUuid(const std::string& uuidStr, bool takeLast64) { // Parse standard UUID string - for now just return empty Uuid64 result; result.high = 0; result.low = 0; return result; } // ============================================================================ // Node/Link/Pin Lookups (delegates to GraphState) // ============================================================================ Node* BlueprintsEngine::FindNode(ed::NodeId id) { return m_GraphState.FindNode(id); } Link* BlueprintsEngine::FindLink(ed::LinkId id) { return m_GraphState.FindLink(id); } Pin* BlueprintsEngine::FindPin(ed::PinId id) { // FindPin requires iterating nodes which requires App* for container lookup // Subclasses will implement this return nullptr; } // ============================================================================ // Validation Helpers // ============================================================================ bool BlueprintsEngine::IsPinLinked(ed::PinId id) { // Virtual method - subclasses will implement return false; } bool BlueprintsEngine::CanCreateLink(Pin* a, Pin* b) { if (!a || !b || a == b) return false; // Can only connect Input to Output if (a->Kind == b->Kind) return false; // TODO: Add type compatibility checking return true; } bool BlueprintsEngine::IsLinkDuplicate(ed::PinId startPinId, ed::PinId endPinId) { // Virtual method - subclasses will implement return false; } Link* BlueprintsEngine::FindLinkConnectedToPin(ed::PinId pinId) { // Virtual method - subclasses will implement return nullptr; } // ============================================================================ // Container Management (delegates to GraphState) // ============================================================================ RootContainer* BlueprintsEngine::GetActiveRootContainer() const { return m_GraphState.GetActiveRootContainer(); } RootContainer* BlueprintsEngine::AddRootContainer(const std::string& filename) { return m_GraphState.AddRootContainer(filename); } void BlueprintsEngine::RemoveRootContainer(RootContainer* container) { m_GraphState.RemoveRootContainer(container); } void BlueprintsEngine::SetActiveRootContainer(RootContainer* container) { m_GraphState.SetActiveRootContainer(container); } Container* BlueprintsEngine::FindContainerForNode(ed::NodeId nodeId) { return m_GraphState.FindContainerForNode(nodeId); }