Merge pull request 'feat(sdk): scaffold KCSDK library + kcsdk pybind11 module (#350)' (#358) from feat/kcsdk-scaffold into main
Reviewed-on: #358
This commit was merged in pull request #358.
This commit is contained in:
@@ -14,6 +14,7 @@ endif()
|
|||||||
add_subdirectory(Stylesheets)
|
add_subdirectory(Stylesheets)
|
||||||
add_subdirectory(PreferencePacks)
|
add_subdirectory(PreferencePacks)
|
||||||
add_subdirectory(PreferencePackTemplates)
|
add_subdirectory(PreferencePackTemplates)
|
||||||
|
add_subdirectory(SDK)
|
||||||
|
|
||||||
if(BUILD_WITH_CONDA)
|
if(BUILD_WITH_CONDA)
|
||||||
add_definitions(-DFC_CONDA)
|
add_definitions(-DFC_CONDA)
|
||||||
|
|||||||
31
src/Gui/SDK/CMakeLists.txt
Normal file
31
src/Gui/SDK/CMakeLists.txt
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
# SPDX-License-Identifier: LGPL-2.1-or-later
|
||||||
|
|
||||||
|
set(KCSDK_SRCS
|
||||||
|
KCSDKGlobal.h
|
||||||
|
SDKRegistry.h
|
||||||
|
SDKRegistry.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
add_library(KCSDK SHARED ${KCSDK_SRCS})
|
||||||
|
|
||||||
|
target_include_directories(KCSDK
|
||||||
|
PUBLIC
|
||||||
|
${CMAKE_SOURCE_DIR}/src
|
||||||
|
${CMAKE_BINARY_DIR}/src
|
||||||
|
)
|
||||||
|
|
||||||
|
target_link_libraries(KCSDK
|
||||||
|
PRIVATE
|
||||||
|
FreeCADBase
|
||||||
|
)
|
||||||
|
|
||||||
|
if(FREECAD_WARN_ERROR)
|
||||||
|
target_compile_warn_error(KCSDK)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
SET_BIN_DIR(KCSDK KCSDK /Mod/Create)
|
||||||
|
INSTALL(TARGETS KCSDK DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||||
|
|
||||||
|
if(FREECAD_USE_PYBIND11)
|
||||||
|
add_subdirectory(bindings)
|
||||||
|
endif()
|
||||||
37
src/Gui/SDK/KCSDKGlobal.h
Normal file
37
src/Gui/SDK/KCSDKGlobal.h
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
// 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/>. *
|
||||||
|
* *
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
#include <FCGlobal.h>
|
||||||
|
|
||||||
|
#ifndef KCSDK_GLOBAL_H
|
||||||
|
#define KCSDK_GLOBAL_H
|
||||||
|
|
||||||
|
#ifndef KCSDKExport
|
||||||
|
# ifdef KCSDK_EXPORTS
|
||||||
|
# define KCSDKExport FREECAD_DECL_EXPORT
|
||||||
|
# else
|
||||||
|
# define KCSDKExport FREECAD_DECL_IMPORT
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // KCSDK_GLOBAL_H
|
||||||
51
src/Gui/SDK/SDKRegistry.cpp
Normal file
51
src/Gui/SDK/SDKRegistry.cpp
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
// 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/>. *
|
||||||
|
* *
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
#include "SDKRegistry.h"
|
||||||
|
|
||||||
|
#include <Base/Console.h>
|
||||||
|
|
||||||
|
namespace KCSDK
|
||||||
|
{
|
||||||
|
|
||||||
|
SDKRegistry& SDKRegistry::instance()
|
||||||
|
{
|
||||||
|
static SDKRegistry reg;
|
||||||
|
return reg;
|
||||||
|
}
|
||||||
|
|
||||||
|
SDKRegistry::SDKRegistry()
|
||||||
|
{
|
||||||
|
Base::Console().log("KCSDK: registry initialized (API v%d)\n", API_VERSION_MAJOR);
|
||||||
|
}
|
||||||
|
|
||||||
|
SDKRegistry::~SDKRegistry() = default;
|
||||||
|
|
||||||
|
std::vector<std::string> SDKRegistry::available() const
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(mutex_);
|
||||||
|
// No providers registered yet — will be populated in subsequent phases.
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace KCSDK
|
||||||
71
src/Gui/SDK/SDKRegistry.h
Normal file
71
src/Gui/SDK/SDKRegistry.h
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
// 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_SDKREGISTRY_H
|
||||||
|
#define KCSDK_SDKREGISTRY_H
|
||||||
|
|
||||||
|
#include <mutex>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "KCSDKGlobal.h"
|
||||||
|
|
||||||
|
namespace KCSDK
|
||||||
|
{
|
||||||
|
|
||||||
|
/// Current KCSDK API major version. Addons should check this at load time.
|
||||||
|
constexpr int API_VERSION_MAJOR = 1;
|
||||||
|
|
||||||
|
/// Singleton registry for SDK-managed UI providers.
|
||||||
|
///
|
||||||
|
/// This is the central coordination point for the Kindred addon SDK.
|
||||||
|
/// Provider interfaces (IPanelProvider, IToolbarProvider, etc.) will be
|
||||||
|
/// added in subsequent phases. For now this establishes the singleton
|
||||||
|
/// pattern, thread safety, and API versioning.
|
||||||
|
///
|
||||||
|
/// Thread safety: all public methods are internally synchronized.
|
||||||
|
class KCSDKExport SDKRegistry
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
/// Access the singleton instance.
|
||||||
|
static SDKRegistry& instance();
|
||||||
|
|
||||||
|
~SDKRegistry();
|
||||||
|
|
||||||
|
/// Return names of all registered providers (across all provider types).
|
||||||
|
std::vector<std::string> available() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
SDKRegistry();
|
||||||
|
|
||||||
|
SDKRegistry(const SDKRegistry&) = delete;
|
||||||
|
SDKRegistry& operator=(const SDKRegistry&) = delete;
|
||||||
|
SDKRegistry(SDKRegistry&&) = delete;
|
||||||
|
SDKRegistry& operator=(SDKRegistry&&) = delete;
|
||||||
|
|
||||||
|
mutable std::mutex mutex_;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace KCSDK
|
||||||
|
|
||||||
|
#endif // KCSDK_SDKREGISTRY_H
|
||||||
30
src/Gui/SDK/bindings/CMakeLists.txt
Normal file
30
src/Gui/SDK/bindings/CMakeLists.txt
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
# SPDX-License-Identifier: LGPL-2.1-or-later
|
||||||
|
|
||||||
|
set(KCSDKPy_SRCS
|
||||||
|
kcsdk_py.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
add_library(kcsdk_py SHARED ${KCSDKPy_SRCS})
|
||||||
|
|
||||||
|
target_include_directories(kcsdk_py
|
||||||
|
PRIVATE
|
||||||
|
${CMAKE_SOURCE_DIR}/src
|
||||||
|
${CMAKE_BINARY_DIR}/src
|
||||||
|
${pybind11_INCLUDE_DIR}
|
||||||
|
)
|
||||||
|
|
||||||
|
target_link_libraries(kcsdk_py
|
||||||
|
PRIVATE
|
||||||
|
pybind11::module
|
||||||
|
Python3::Python
|
||||||
|
KCSDK
|
||||||
|
)
|
||||||
|
|
||||||
|
if(FREECAD_WARN_ERROR)
|
||||||
|
target_compile_warn_error(kcsdk_py)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
SET_BIN_DIR(kcsdk_py kcsdk /Mod/Create)
|
||||||
|
SET_PYTHON_PREFIX_SUFFIX(kcsdk_py)
|
||||||
|
|
||||||
|
INSTALL(TARGETS kcsdk_py DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||||
40
src/Gui/SDK/bindings/kcsdk_py.cpp
Normal file
40
src/Gui/SDK/bindings/kcsdk_py.cpp
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
// 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/>. *
|
||||||
|
* *
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
#include <pybind11/pybind11.h>
|
||||||
|
#include <pybind11/stl.h>
|
||||||
|
|
||||||
|
#include <Gui/SDK/SDKRegistry.h>
|
||||||
|
|
||||||
|
namespace py = pybind11;
|
||||||
|
using namespace KCSDK;
|
||||||
|
|
||||||
|
PYBIND11_MODULE(kcsdk, m)
|
||||||
|
{
|
||||||
|
m.doc() = "KCSDK — Kindred Create addon SDK C++ API";
|
||||||
|
m.attr("API_VERSION_MAJOR") = API_VERSION_MAJOR;
|
||||||
|
|
||||||
|
m.def("available", []() {
|
||||||
|
return SDKRegistry::instance().available();
|
||||||
|
}, "Return names of all registered providers.");
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user