42 lines
1.1 KiB
C++
42 lines
1.1 KiB
C++
#pragma once
|
|
#include "vde/brep/feature_tree.h"
|
|
#include <functional>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
namespace vde::brep {
|
|
|
|
/// Callback type for model changes.
|
|
/// Receives the feature name and the new model after rebuild.
|
|
using UpdateCallback = std::function<void(const std::string& feature_name, const BrepModel& new_model)>;
|
|
|
|
/**
|
|
* @brief Notifies listeners when features change.
|
|
*
|
|
* Integrates with FeatureHistory: after each apply/undo/redo,
|
|
* call notify() to push the updated model to all registered callbacks.
|
|
*
|
|
* @ingroup brep
|
|
*/
|
|
class UpdateNotifier {
|
|
public:
|
|
/// Register a callback. Called on every notify().
|
|
void on_update(UpdateCallback cb) { callbacks_.push_back(std::move(cb)); }
|
|
|
|
/// Notify all registered listeners.
|
|
void notify(const std::string& feature, const BrepModel& model) {
|
|
for (auto& cb : callbacks_) cb(feature, model);
|
|
}
|
|
|
|
/// Remove all callbacks.
|
|
void clear() { callbacks_.clear(); }
|
|
|
|
/// Number of registered callbacks.
|
|
[[nodiscard]] size_t listener_count() const { return callbacks_.size(); }
|
|
|
|
private:
|
|
std::vector<UpdateCallback> callbacks_;
|
|
};
|
|
|
|
} // namespace vde::brep
|