Add FreeCAD WebAssembly runtime probes
Some checks failed
FreeCAD master CI / Prepare (push) Has been cancelled
CodeQL Advanced / Analyze (actions) (push) Has been cancelled
CodeQL Advanced / Analyze (python) (push) Has been cancelled
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
FreeCAD master CI / Pixi (push) Has been cancelled
FreeCAD master CI / Ubuntu (push) Has been cancelled
FreeCAD master CI / Windows (push) Has been cancelled
FreeCAD master CI / Lint (push) Has been cancelled
FreeCAD master CI / WrapUp (push) Has been cancelled
Stale Issues / stale (push) Has been cancelled
Push Crowdin Translations / update-crowdin (push) Has been cancelled
Fetch Crowdin Translations / update-crowdin (push) Has been cancelled

This commit is contained in:
2026-08-23 17:48:10 +08:00
parent 0644133717
commit 0a2e7ce7f5
32 changed files with 2160 additions and 74 deletions

View File

@@ -176,7 +176,10 @@ bool TopoShapeCache::isTouched(const TopoDS_Shape& tds) const
TopoShapeCache::Ancestry& TopoShapeCache::getAncestry(TopAbs_ShapeEnum type)
{
auto& ancestry = shapeAncestryCache.at(type);
if (type < TopAbs_COMPOUND || type > TopAbs_SHAPE) {
throw Base::ValueError("invalid TopoShape ancestry type: " + std::to_string(static_cast<int>(type)));
}
auto& ancestry = shapeAncestryCache[static_cast<std::size_t>(type)];
if (!ancestry.owner) {
ancestry.owner = this;
if (!shape.IsNull()) {
@@ -231,7 +234,10 @@ TopoDS_Shape TopoShapeCache::findAncestor(
auto& info = getAncestry(type);
auto& ancestorInfo = info.ancestors.at(subShape.ShapeType());
if (subShape.ShapeType() < TopAbs_COMPOUND || subShape.ShapeType() > TopAbs_SHAPE) {
return nullShape;
}
auto& ancestorInfo = info.ancestors[static_cast<std::size_t>(subShape.ShapeType())];
if (!ancestorInfo.initialized) {
ancestorInfo.initialized = true;
// ancestorInfo.shapes is the output variable here, storing (and caching) the actual map

View File

@@ -1488,7 +1488,7 @@ TopoShape& TopoShape::makeShapeWithElementMap(
int newShapeCounter = 0;
for (auto& newShape : mapper.modified(otherElement)) {
++newShapeCounter;
if (newShape.ShapeType() >= TopAbs_SHAPE) {
if (newShape.ShapeType() < TopAbs_COMPOUND || newShape.ShapeType() >= TopAbs_SHAPE) {
// NOLINTNEXTLINE
FC_ERR(
"unknown modified shape type " << newShape.ShapeType() << " from "
@@ -1496,7 +1496,11 @@ TopoShape& TopoShape::makeShapeWithElementMap(
);
continue;
}
auto& newInfo = *infoMap.at(newShape.ShapeType());
if (newShape.ShapeType() < TopAbs_COMPOUND || newShape.ShapeType() >= TopAbs_SHAPE
|| !infoMap[newShape.ShapeType()]) {
continue;
}
auto& newInfo = *infoMap[newShape.ShapeType()];
if (newInfo.type != newShape.ShapeType()) {
if (FC_LOG_INSTANCE.isEnabled(FC_LOGLEVEL_LOG)) {
// TODO: it seems modified shape may report higher
@@ -1545,7 +1549,7 @@ TopoShape& TopoShape::makeShapeWithElementMap(
// (e.g. a face generated from an edge)
newShapeCounter = 0;
for (auto& newShape : mapper.generated(otherElement)) {
if (newShape.ShapeType() >= TopAbs_SHAPE) {
if (newShape.ShapeType() < TopAbs_COMPOUND || newShape.ShapeType() >= TopAbs_SHAPE) {
// NOLINTNEXTLINE
FC_ERR(
"unknown generated shape type " << newShape.ShapeType() << " from "
@@ -1556,7 +1560,11 @@ TopoShape& TopoShape::makeShapeWithElementMap(
int parallelFace = -1;
int coplanarFace = -1;
auto& newInfo = *infoMap.at(newShape.ShapeType());
if (newShape.ShapeType() < TopAbs_COMPOUND || newShape.ShapeType() >= TopAbs_SHAPE
|| !infoMap[newShape.ShapeType()]) {
continue;
}
auto& newInfo = *infoMap[newShape.ShapeType()];
std::vector<TopoDS_Shape> newShapes;
int shapeOffset = 0;
if (newInfo.type == newShape.ShapeType()) {

View File

@@ -34,6 +34,7 @@ SET(Sandbox_SRCS
DocumentProtectorPy.h
DocumentThread.cpp
DocumentThread.h
SandboxGlobal.h
PreCompiled.h
)

View File

@@ -23,14 +23,14 @@
***************************************************************************/
# include <QCoreApplication>
# include <QObject>
# include <QEvent>
# include <QMutex>
# include <QMutexLocker>
# include <QSemaphore>
# include <QThread>
# include <QWaitCondition>
# include <QCoreApplication>
# include <QObject>
# include <QEvent>
#ifndef FREECAD_WEB_CORE
# include <QSemaphore>
# include <QThread>
# include <QWaitCondition>
#endif
#include "DocumentProtector.h"
@@ -49,18 +49,25 @@ static const int QT_CUSTOM_EVENT_PROTECTOR = 10000;
class AbstractCustomProtectorEvent : public QEvent
{
public:
AbstractCustomProtectorEvent()
: QEvent(QEvent::Type(QT_CUSTOM_EVENT_PROTECTOR)), semaphore(0)
AbstractCustomProtectorEvent()
: QEvent(QEvent::Type(QT_CUSTOM_EVENT_PROTECTOR))
#ifndef FREECAD_WEB_CORE
, semaphore(0)
#endif
{
}
~AbstractCustomProtectorEvent()
{
if (semaphore)
semaphore->release();
~AbstractCustomProtectorEvent()
{
#ifndef FREECAD_WEB_CORE
if (semaphore)
semaphore->release();
#endif
}
virtual void execute() = 0;
QSemaphore* semaphore;
#ifndef FREECAD_WEB_CORE
QSemaphore* semaphore;
#endif
};
class CustomAddObjectEvent : public AbstractCustomProtectorEvent
@@ -208,9 +215,13 @@ DocumentReceiver *DocumentReceiver::globalInstance()
}
// Posts an event and waits for it to finish processing
void DocumentReceiver::postEventAndWait(QEvent* e)
{
QThread *currentThread = QThread::currentThread();
void DocumentReceiver::postEventAndWait(QEvent* e)
{
#ifdef FREECAD_WEB_CORE
QCoreApplication::sendEvent(this, e);
delete e;
#else
QThread *currentThread = QThread::currentThread();
QThread *thr = this->thread(); // this is the main thread
if (currentThread == thr) {
@@ -225,8 +236,9 @@ void DocumentReceiver::postEventAndWait(QEvent* e)
static_cast<AbstractCustomProtectorEvent*>(e)->semaphore = &semaphore;
QCoreApplication::postEvent(this, e);
// wait until the event has been processed
semaphore.acquire();
}
semaphore.acquire();
}
#endif
}
void DocumentReceiver::customEvent(QEvent* e)
@@ -247,12 +259,14 @@ DocumentProtector::~DocumentProtector()
{
}
void DocumentProtector::init()
{
// this method must be called somewhere from the main thread
DocumentReceiver::globalInstance()->
moveToThread(QCoreApplication::instance()->thread());
}
void DocumentProtector::init()
{
#ifndef FREECAD_WEB_CORE
// this method must be called somewhere from the main thread
DocumentReceiver::globalInstance()->
moveToThread(QCoreApplication::instance()->thread());
#endif
}
void DocumentProtector::slotDeletedDocument(const App::Document& Doc)
{

View File

@@ -23,10 +23,11 @@
***************************************************************************/
#pragma once
#include <string>
#include <App/DocumentObserver.h>
#pragma once
#include <string>
#include <App/DocumentObserver.h>
#include "SandboxGlobal.h"
namespace App {
class Document;
@@ -127,4 +128,4 @@ private:
App::DocumentObject* obj;
};
}
}

View File

@@ -23,25 +23,31 @@
***************************************************************************/
# include <QMutexLocker>
#ifndef FREECAD_WEB_CORE
# include <QMutexLocker>
#endif
#include "DocumentThread.h"
#include "DocumentProtector.h"
#include <Base/Console.h>
#include <Base/Sequencer.h>
#include <Base/Stream.h>
#include <Base/Writer.h>
#include <Base/Interpreter.h>
#include <App/Application.h>
#include <App/Document.h>
#include <Mod/Mesh/App/Mesh.h>
#include <Base/Console.h>
#ifndef FREECAD_WEB_CORE
#include <Base/Sequencer.h>
#include <Base/Stream.h>
#include <Base/Writer.h>
#include <Base/Interpreter.h>
#endif
#include <App/Application.h>
#include <App/Document.h>
#ifndef FREECAD_WEB_CORE
#include <Mod/Mesh/App/Mesh.h>
#endif
using namespace Sandbox;
DocumentThread::DocumentThread(QObject* parent)
#ifndef FREECAD_WEB_CORE
DocumentThread::DocumentThread(QObject* parent)
: QThread(parent)
{
}
@@ -153,11 +159,12 @@ Base::Reference<Mesh::MeshObject> MeshLoaderThread::getMesh() const
return this->mesh;
}
void MeshLoaderThread::run()
{
void MeshLoaderThread::run()
{
this->mesh = new Mesh::MeshObject();
this->mesh->load((const char*)filename.toUtf8());
}
}
#endif
// --------------------------------------
@@ -203,8 +210,8 @@ void SandboxObject::resetValue()
Base::Console().message("SandboxObject::resetValue()\n");
Integer.setValue(4711);
}
DocumentTestThread::DocumentTestThread(QObject* parent)
#ifndef FREECAD_WEB_CORE
DocumentTestThread::DocumentTestThread(QObject* parent)
: QThread(parent)
{
}
@@ -242,7 +249,7 @@ DocumentSaverThread::~DocumentSaverThread()
{
}
void DocumentSaverThread::run()
void DocumentSaverThread::run()
{
std::string uuid = Base::Uuid::createUuid();
std::string fn = doc->TransientDir.getValue();
@@ -268,4 +275,5 @@ void DocumentSaverThread::run()
// write additional files
writer.writeFiles();
}
}
}
#endif

View File

@@ -23,20 +23,24 @@
***************************************************************************/
#pragma once
#include <QThread>
#include <Base/Mutex.h>
#include <Base/Handle.h>
#include <App/DocumentObject.h>
#pragma once
#include <App/DocumentObject.h>
#include "SandboxGlobal.h"
#ifndef FREECAD_WEB_CORE
#include <QThread>
#include <Base/Handle.h>
#endif
namespace Mesh {
class MeshObject;
}
namespace Sandbox {
class SandboxAppExport DocumentThread : public QThread
namespace Sandbox {
#ifndef FREECAD_WEB_CORE
class SandboxAppExport DocumentThread : public QThread
{
public:
DocumentThread(QObject* parent=0);
@@ -67,7 +71,7 @@ protected:
static QRecursiveMutex mutex;
};
class SandboxAppExport MeshLoaderThread : public QThread
class SandboxAppExport MeshLoaderThread : public QThread
{
public:
MeshLoaderThread(const QString&, QObject* parent=0);
@@ -81,9 +85,10 @@ protected:
private:
QString filename;
Base::Reference<Mesh::MeshObject> mesh;
};
};
#endif
class SandboxObject : public App::DocumentObject
class SandboxObject : public App::DocumentObject
{
PROPERTY_HEADER(SandboxObject);
@@ -101,10 +106,11 @@ public:
}
void setIntValue(int);
void resetValue();
};
class SandboxAppExport DocumentTestThread : public QThread
void resetValue();
};
#ifndef FREECAD_WEB_CORE
class SandboxAppExport DocumentTestThread : public QThread
{
public:
DocumentTestThread(QObject* parent=0);
@@ -114,7 +120,7 @@ protected:
void run();
};
class SandboxAppExport DocumentSaverThread : public QThread
class SandboxAppExport DocumentSaverThread : public QThread
{
public:
DocumentSaverThread(App::Document* doc, QObject* parent=0);
@@ -125,6 +131,7 @@ protected:
private:
App::Document* doc;
};
};
#endif
}
}

View File

@@ -0,0 +1,13 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
#pragma once
#include <FCGlobal.h>
#ifndef SandboxAppExport
# ifdef Sandbox_EXPORTS
# define SandboxAppExport FREECAD_DECL_EXPORT
# else
# define SandboxAppExport FREECAD_DECL_IMPORT
# endif
#endif