freecad: fix build with coin3>=4.0.8

This commit is contained in:
classabbyamp
2026-07-05 18:18:02 -04:00
parent 9baf585f12
commit e2d4485fac
+153
View File
@@ -0,0 +1,153 @@
From d3ce038692ad445f5fd1f04a3dddd050bcf46065 Mon Sep 17 00:00:00 2001
From: Captain <87000456+captain0xff@users.noreply.github.com>
Date: Sat, 21 Mar 2026 05:52:51 +0530
Subject: [PATCH] Gui: update CoinPtr to not use boost::intrusive_ptr (#28427)
(cherry picked from commit dd3e6b65b537161abfb62188254d60dba5984f2c)
---
src/Gui/View3DInventor.cpp | 2 +-
src/Gui/ViewProvider.h | 104 ++++++++++++++++++++++++++++++-----
src/Gui/ViewProviderLink.cpp | 2 +-
3 files changed, 92 insertions(+), 16 deletions(-)
diff --git a/src/Gui/View3DInventor.cpp b/src/Gui/View3DInventor.cpp
index 2dab86ec05d3..6262f4c4a193 100644
--- a/src/Gui/View3DInventor.cpp
+++ b/src/Gui/View3DInventor.cpp
@@ -604,7 +604,7 @@ bool View3DInventor::setCamera(const char* pCamera)
}
// this is to make sure to reliably delete the node
- CoinPtr<SoNode> camPtr(Cam, true);
+ CoinPtr<SoNode> camPtr {Cam};
// toggle between perspective and orthographic camera
if (Cam->getTypeId() != CamViewer->getTypeId()) {
diff --git a/src/Gui/ViewProvider.h b/src/Gui/ViewProvider.h
index aa2d74c576fd..5d1f224df440 100644
--- a/src/Gui/ViewProvider.h
+++ b/src/Gui/ViewProvider.h
@@ -87,20 +87,101 @@ enum ViewStatus
};
+/** Convenience smart pointer to manage the lifetime of coin nodes.
+ *
+ * This class is copied from Inventor/misc/SoRefPtr.h and can be removed when the
+ * minimum supported coin version provides this header.
+ */
+template<typename T>
+class SoRefPtr
+{
+public:
+ SoRefPtr(void) noexcept
+ : ptr(NULL)
+ {}
+
+ explicit SoRefPtr(T* p)
+ : ptr(p)
+ {
+ if (this->ptr) {
+ this->ptr->ref();
+ }
+ }
+
+ SoRefPtr(const SoRefPtr& other)
+ : ptr(other.ptr)
+ {
+ if (this->ptr) {
+ this->ptr->ref();
+ }
+ }
+
+ SoRefPtr(SoRefPtr&& other) noexcept
+ : ptr(other.ptr)
+ {
+ other.ptr = NULL;
+ }
+
+ ~SoRefPtr(void)
+ {
+ if (this->ptr) {
+ this->ptr->unref();
+ }
+ }
+
+ SoRefPtr& operator=(SoRefPtr other) noexcept
+ {
+ this->swap(other);
+ return *this;
+ }
+
+ void reset(T* p = NULL)
+ {
+ SoRefPtr tmp(p);
+ this->swap(tmp);
+ }
+
+ T* get(void) const noexcept
+ {
+ return this->ptr;
+ }
+ T& operator*(void) const
+ {
+ return *this->ptr;
+ }
+ T* operator->(void) const noexcept
+ {
+ return this->ptr;
+ }
+ explicit operator bool(void) const noexcept
+ {
+ return this->ptr != NULL;
+ }
+
+ void swap(SoRefPtr& other) noexcept
+ {
+ using std::swap;
+ swap(this->ptr, other.ptr);
+ }
+
+private:
+ T* ptr;
+};
+
/** Convenience smart pointer to wrap coin node.
*
- * It is basically boost::intrusive plus implicit pointer conversion to save the
- * trouble of typing get() all the time.
+ * This class isn't merged with SoRefPtr because it can be removed in the future
*/
template<class T>
-class CoinPtr: public boost::intrusive_ptr<T> {
+class CoinPtr: public SoRefPtr<T> {
public:
- // Too bad, VC2013 does not support constructor inheritance
- //using boost::intrusive_ptr<T>::intrusive_ptr;
- using inherited = boost::intrusive_ptr<T>;
- CoinPtr() = default;
- CoinPtr(T *p, bool add_ref=true):inherited(p,add_ref){}
- template<class Y> CoinPtr(CoinPtr<Y> const &r):inherited(r){}
+ using SoRefPtr<T>::SoRefPtr;
+
+ CoinPtr& operator=(T* ptr)
+ {
+ SoRefPtr<T>::reset(ptr);
+ return *this;
+ }
operator T *() const {
return this->get();
diff --git a/src/Gui/ViewProviderLink.cpp b/src/Gui/ViewProviderLink.cpp
index e4bd027484f4..89b61d523235 100644
--- a/src/Gui/ViewProviderLink.cpp
+++ b/src/Gui/ViewProviderLink.cpp
@@ -1624,7 +1624,7 @@ void LinkView::updateLink()
bool LinkView::linkGetElementPicked(const SoPickedPoint* pp, std::string& subname) const
{
std::ostringstream ss;
- CoinPtr<SoPath> path = pp->getPath();
+ CoinPtr<SoPath> path {pp->getPath()};
if(!nodeArray.empty()) {
auto idx = path->findNode(pcLinkRoot);
if (idx < 0 || idx + 2 >= path->getLength()) {