IMenuProvider: declarative menu placement with optional context awareness. C++ interface with pybind11 bindings + GIL-safe holder. SDKMenuManipulator (shared WorkbenchManipulator) injects menu items on workbench switch, filtered by editing context when context_ids() is non-empty. register_command(): thin Python wrapper around FreeCADGui.addCommand() that standardizes the calling convention within the SDK contract. Python wrappers (kindred_sdk.register_menu, kindred_sdk.register_command) use kcsdk-first routing with FreeCADGui fallback.
70 lines
2.9 KiB
C++
70 lines
2.9 KiB
C++
// SPDX-License-Identifier: LGPL-2.1-or-later
|
|
/****************************************************************************
|
|
* *
|
|
* Copyright (c) 2025 Kindred Systems <development@kindred-systems.com> *
|
|
* *
|
|
* This file is part of FreeCAD. *
|
|
* *
|
|
* FreeCAD is free software: you can redistribute it and/or modify it *
|
|
* under the terms of the GNU Lesser General Public License as *
|
|
* published by the Free Software Foundation, either version 2.1 of the *
|
|
* License, or (at your option) any later version. *
|
|
* *
|
|
* FreeCAD is distributed in the hope that it will be useful, but *
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
|
|
* Lesser General Public License for more details. *
|
|
* *
|
|
* You should have received a copy of the GNU Lesser General Public *
|
|
* License along with FreeCAD. If not, see *
|
|
* <https://www.gnu.org/licenses/>. *
|
|
* *
|
|
***************************************************************************/
|
|
|
|
#ifndef KCSDK_PYIMENUPROVIDER_H
|
|
#define KCSDK_PYIMENUPROVIDER_H
|
|
|
|
#include <pybind11/pybind11.h>
|
|
#include <pybind11/stl.h>
|
|
|
|
#include <Gui/SDK/IMenuProvider.h>
|
|
|
|
namespace KCSDK
|
|
{
|
|
|
|
/// pybind11 trampoline class for IMenuProvider.
|
|
/// Enables Python subclasses that override virtual methods.
|
|
class PyIMenuProvider : public IMenuProvider
|
|
{
|
|
public:
|
|
using IMenuProvider::IMenuProvider;
|
|
|
|
// ── Pure virtuals ──────────────────────────────────────────────
|
|
|
|
std::string id() const override
|
|
{
|
|
PYBIND11_OVERRIDE_PURE(std::string, IMenuProvider, id);
|
|
}
|
|
|
|
std::string menu_path() const override
|
|
{
|
|
PYBIND11_OVERRIDE_PURE(std::string, IMenuProvider, menu_path);
|
|
}
|
|
|
|
std::vector<std::string> items() const override
|
|
{
|
|
PYBIND11_OVERRIDE_PURE(std::vector<std::string>, IMenuProvider, items);
|
|
}
|
|
|
|
// ── Virtuals with defaults ─────────────────────────────────────
|
|
|
|
std::vector<std::string> context_ids() const override
|
|
{
|
|
PYBIND11_OVERRIDE(std::vector<std::string>, IMenuProvider, context_ids);
|
|
}
|
|
};
|
|
|
|
} // namespace KCSDK
|
|
|
|
#endif // KCSDK_PYIMENUPROVIDER_H
|