From c47d9c06b54d8119a308e0fca2507d0a5f26ebcd Mon Sep 17 00:00:00 2001 From: Pasukhin Dmitry Date: Sat, 24 Jan 2026 16:52:30 +0000 Subject: [PATCH] Mesh - Replace plugin system with registry-based factory pattern (#1033) Replace the legacy DISCRETPLUGIN/DISCRETALGO symbol-based plugin system with a clean registry-based factory pattern following the design of Graphic3d_GraphicDriverFactory. Problem: TKMesh and TKXMesh both exported the same DISCRETALGO symbol, causing symbol collisions when both libraries were loaded. The old plugin system required dlopen/dlsym which was error-prone and limited. Solution: Each meshing algorithm now registers itself as a factory with a unique name. Multiple algorithms can coexist and be selected at runtime. New classes: - BRepMesh_DiscretAlgoFactory: Abstract factory base with static registry - BRepMesh_IncrementalMeshFactory: Factory for "FastDiscret" algorithm - XBRepMesh_Factory: Factory for "XBRepMesh" algorithm Removed (breaking changes): - BRepMesh_PluginMacro.hxx: DISCRETPLUGIN macro - BRepMesh_PluginEntryType.hxx: Legacy function pointer type - BRepMesh_FactoryError.hxx: Legacy error enum - XBRepMesh class: Replaced by XBRepMesh_Factory - BRepMesh_DiscretFactory::Names(), SetFunctionName(), FunctionName(), ErrorStatus() - Draw commands: mpsetfunctionname, mpgetfunctionname, mperror Simplified BRepMesh_DiscretFactory API to delegate to the new registry. Updated MeshTest_PluginCommands to use BRepMesh_DiscretAlgoFactory. --- .../MeshTest/MeshTest_PluginCommands.cxx | 160 ++++++------------ .../BRepMesh/BRepMesh_DiscretAlgoFactory.cxx | 114 +++++++++++++ .../BRepMesh/BRepMesh_DiscretAlgoFactory.hxx | 81 +++++++++ .../BRepMesh/BRepMesh_DiscretFactory.cxx | 159 +++-------------- .../BRepMesh/BRepMesh_DiscretFactory.hxx | 75 ++------ .../TKMesh/BRepMesh/BRepMesh_FactoryError.hxx | 25 --- .../BRepMesh/BRepMesh_IncrementalMesh.cxx | 4 - .../BRepMesh_IncrementalMeshFactory.cxx | 61 +++++++ .../BRepMesh_IncrementalMeshFactory.hxx | 41 +++++ .../BRepMesh/BRepMesh_PluginEntryType.hxx | 26 --- .../TKMesh/BRepMesh/BRepMesh_PluginMacro.hxx | 36 ---- .../TKMesh/BRepMesh/FILES.cmake | 7 +- .../BRepMesh_DiscretAlgoFactory_Test.cxx | 145 ++++++++++++++++ .../TKMesh/GTests/FILES.cmake | 1 + .../TKXMesh/XBRepMesh/FILES.cmake | 4 +- .../TKXMesh/XBRepMesh/XBRepMesh.cxx | 38 ----- .../TKXMesh/XBRepMesh/XBRepMesh.hxx | 37 ---- .../TKXMesh/XBRepMesh/XBRepMesh_Factory.cxx | 59 +++++++ .../TKXMesh/XBRepMesh/XBRepMesh_Factory.hxx | 41 +++++ 19 files changed, 634 insertions(+), 480 deletions(-) create mode 100644 src/ModelingAlgorithms/TKMesh/BRepMesh/BRepMesh_DiscretAlgoFactory.cxx create mode 100644 src/ModelingAlgorithms/TKMesh/BRepMesh/BRepMesh_DiscretAlgoFactory.hxx delete mode 100644 src/ModelingAlgorithms/TKMesh/BRepMesh/BRepMesh_FactoryError.hxx create mode 100644 src/ModelingAlgorithms/TKMesh/BRepMesh/BRepMesh_IncrementalMeshFactory.cxx create mode 100644 src/ModelingAlgorithms/TKMesh/BRepMesh/BRepMesh_IncrementalMeshFactory.hxx delete mode 100644 src/ModelingAlgorithms/TKMesh/BRepMesh/BRepMesh_PluginEntryType.hxx delete mode 100644 src/ModelingAlgorithms/TKMesh/BRepMesh/BRepMesh_PluginMacro.hxx create mode 100644 src/ModelingAlgorithms/TKMesh/GTests/BRepMesh_DiscretAlgoFactory_Test.cxx delete mode 100644 src/ModelingAlgorithms/TKXMesh/XBRepMesh/XBRepMesh.cxx delete mode 100644 src/ModelingAlgorithms/TKXMesh/XBRepMesh/XBRepMesh.hxx create mode 100644 src/ModelingAlgorithms/TKXMesh/XBRepMesh/XBRepMesh_Factory.cxx create mode 100644 src/ModelingAlgorithms/TKXMesh/XBRepMesh/XBRepMesh_Factory.hxx diff --git a/src/Draw/TKTopTest/MeshTest/MeshTest_PluginCommands.cxx b/src/Draw/TKTopTest/MeshTest/MeshTest_PluginCommands.cxx index 9f2382f998..adb6e7da43 100644 --- a/src/Draw/TKTopTest/MeshTest/MeshTest_PluginCommands.cxx +++ b/src/Draw/TKTopTest/MeshTest/MeshTest_PluginCommands.cxx @@ -15,9 +15,9 @@ #include #include +#include #include #include -#include #include #include #include @@ -48,9 +48,6 @@ static int mpnames(Draw_Interpretor&, int, const char**); static int mpsetdefaultname(Draw_Interpretor&, int, const char**); static int mpgetdefaultname(Draw_Interpretor&, int, const char**); -static int mpsetfunctionname(Draw_Interpretor&, int, const char**); -static int mpgetfunctionname(Draw_Interpretor&, int, const char**); -static int mperror(Draw_Interpretor&, int, const char**); static int mpincmesh(Draw_Interpretor&, int, const char**); static int mpparallel(Draw_Interpretor&, int, const char**); static int triarea(Draw_Interpretor&, int, const char**); @@ -69,13 +66,18 @@ void MeshTest::PluginCommands(Draw_Interpretor& theCommands) // const char* g = "Mesh Commands"; // Commands - theCommands.Add("mpnames", "use mpnames", __FILE__, mpnames, g); - theCommands.Add("mpsetdefaultname", "use mpsetdefaultname", __FILE__, mpsetdefaultname, g); - theCommands.Add("mpgetdefaultname", "use mpgetdefaultname", __FILE__, mpgetdefaultname, g); - theCommands.Add("mpsetfunctionname", "use mpsetfunctionname", __FILE__, mpsetfunctionname, g); - theCommands.Add("mpgetfunctionname", "use mpgetfunctionname", __FILE__, mpgetfunctionname, g); - theCommands.Add("mperror", "use mperror", __FILE__, mperror, g); - theCommands.Add("mpincmesh", "use mpincmesh", __FILE__, mpincmesh, g); + theCommands.Add("mpnames", "mpnames : list available meshing algorithms", __FILE__, mpnames, g); + theCommands.Add("mpsetdefaultname", + "mpsetdefaultname name : set default meshing algorithm", + __FILE__, + mpsetdefaultname, + g); + theCommands.Add("mpgetdefaultname", + "mpgetdefaultname : get default meshing algorithm name", + __FILE__, + mpgetdefaultname, + g); + theCommands.Add("mpincmesh", "mpincmesh shape deflection [angle]", __FILE__, mpincmesh, g); theCommands.Add("mpparallel", "mpparallel [toTurnOn] : show / set multi-threading flag for incremental mesh", __FILE__, @@ -98,31 +100,29 @@ void MeshTest::PluginCommands(Draw_Interpretor& theCommands) static int mpnames(Draw_Interpretor&, int n, const char**) { - int aNb; - NCollection_Map::Iterator aIt; - // if (n != 1) { printf(" use mpnames\n"); return 0; } - // - const NCollection_Map& aMN = BRepMesh_DiscretFactory::Get().Names(); - aNb = aMN.Extent(); - if (!aNb) + + const NCollection_List>& aFactories = + BRepMesh_DiscretAlgoFactory::Factories(); + + if (aFactories.IsEmpty()) { - printf(" *no names found\n"); + printf(" *no algorithms registered\n"); return 0; } - // - printf(" *available names:\n"); - aIt.Initialize(aMN); - for (; aIt.More(); aIt.Next()) + + printf(" *available algorithms:\n"); + for (NCollection_List>::Iterator anIter(aFactories); + anIter.More(); + anIter.Next()) { - const TCollection_AsciiString& aName = aIt.Key(); - printf(" %s\n", aName.ToCString()); + printf(" %s\n", anIter.Value()->Name().ToCString()); } - // + return 0; } @@ -130,21 +130,22 @@ static int mpnames(Draw_Interpretor&, int n, const char**) static int mpsetdefaultname(Draw_Interpretor&, int n, const char** a) { - TCollection_AsciiString aName; - // if (n != 2) { printf(" use mpsetdefaultname name\n"); return 0; } - // - aName = a[1]; - // + + TCollection_AsciiString aName = a[1]; if (BRepMesh_DiscretFactory::Get().SetDefaultName(aName)) + { printf(" *ready\n"); + } else - printf(" *fault\n"); - // + { + printf(" *algorithm '%s' not found\n", aName.ToCString()); + } + return 0; } @@ -157,66 +158,10 @@ static int mpgetdefaultname(Draw_Interpretor&, int n, const char**) printf(" use mpgetdefaultname\n"); return 0; } - // + const TCollection_AsciiString& aName = BRepMesh_DiscretFactory::Get().DefaultName(); printf(" *default name: %s\n", aName.ToCString()); - // - return 0; -} -//================================================================================================= - -static int mpsetfunctionname(Draw_Interpretor&, int n, const char** a) -{ - TCollection_AsciiString aName; - // - if (n != 2) - { - printf(" use mpsetfunctionname name\n"); - return 0; - } - // - aName = a[1]; - // - if (BRepMesh_DiscretFactory::Get().SetFunctionName(aName)) - printf(" *ready\n"); - else - printf(" *fault\n"); - // - return 0; -} - -//================================================================================================= - -static int mpgetfunctionname(Draw_Interpretor&, int n, const char**) -{ - if (n != 1) - { - printf(" use mpgetfunctionname\n"); - return 0; - } - // - const TCollection_AsciiString& aName = BRepMesh_DiscretFactory::Get().FunctionName(); - printf(" *function name: %s\n", aName.ToCString()); - // - return 0; -} - -//================================================================================================= - -static int mperror(Draw_Interpretor&, int n, const char**) -{ - BRepMesh_FactoryError aErr; - // - if (n != 1) - { - printf(" use mperror\n"); - return 0; - } - // - aErr = BRepMesh_DiscretFactory::Get().ErrorStatus(); - printf(" *ErrorStatus: %d\n", (int)aErr); - // return 0; } @@ -224,50 +169,41 @@ static int mperror(Draw_Interpretor&, int n, const char**) static int mpincmesh(Draw_Interpretor&, int n, const char** a) { - double aDeflection, aAngle; - TopoDS_Shape aS; - // if (n < 3) { - printf(" use mpincmesh s deflection [angle]\n"); + printf(" use mpincmesh shape deflection [angle]\n"); return 0; } - // - aS = DBRep::Get(a[1]); + + TopoDS_Shape aS = DBRep::Get(a[1]); if (aS.IsNull()) { - printf(" null shapes is not allowed here\n"); + printf(" null shape is not allowed here\n"); return 0; } - // - aDeflection = Draw::Atof(a[2]); - aAngle = 0.5; + + double aDeflection = Draw::Atof(a[2]); + double aAngle = 0.5; if (n > 3) { aAngle = Draw::Atof(a[3]); } - // + occ::handle aMeshAlgo = BRepMesh_DiscretFactory::Get().Discret(aS, aDeflection, aAngle); - // - BRepMesh_FactoryError aErr = BRepMesh_DiscretFactory::Get().ErrorStatus(); - if (aErr != BRepMesh_FE_NOERROR) - { - printf(" *Factory::Get().ErrorStatus()=%d\n", (int)aErr); - } - // + if (aMeshAlgo.IsNull()) { - printf(" *Can not create the algo\n"); + printf(" *Cannot create the meshing algorithm\n"); return 0; } - // + aMeshAlgo->Perform(); if (!aMeshAlgo->IsDone()) { - printf(" *Not done\n"); + printf(" *Meshing not done\n"); } - // + return 0; } diff --git a/src/ModelingAlgorithms/TKMesh/BRepMesh/BRepMesh_DiscretAlgoFactory.cxx b/src/ModelingAlgorithms/TKMesh/BRepMesh/BRepMesh_DiscretAlgoFactory.cxx new file mode 100644 index 0000000000..3c00371272 --- /dev/null +++ b/src/ModelingAlgorithms/TKMesh/BRepMesh/BRepMesh_DiscretAlgoFactory.cxx @@ -0,0 +1,114 @@ +// Copyright (c) 2025 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#include + +#include + +IMPLEMENT_STANDARD_RTTIEXT(BRepMesh_DiscretAlgoFactory, Standard_Transient) + +namespace +{ +static NCollection_List>& getFactories() +{ + static NCollection_List> TheFactories; + return TheFactories; +} +} // namespace + +//================================================================================================== + +const NCollection_List>& BRepMesh_DiscretAlgoFactory:: + Factories() +{ + return getFactories(); +} + +//================================================================================================== + +void BRepMesh_DiscretAlgoFactory::RegisterFactory( + const occ::handle& theFactory, + bool theIsPreferred) +{ + const TCollection_AsciiString aName = theFactory->Name(); + NCollection_List>& aFactories = getFactories(); + if (theIsPreferred) + { + UnregisterFactory(aName); + aFactories.Prepend(theFactory); + return; + } + + for (NCollection_List>::Iterator anIter(aFactories); + anIter.More(); + anIter.Next()) + { + if (TCollection_AsciiString::IsSameString(anIter.Value()->Name(), aName, false)) + { + return; + } + } + aFactories.Append(theFactory); +} + +//================================================================================================== + +void BRepMesh_DiscretAlgoFactory::UnregisterFactory(const TCollection_AsciiString& theName) +{ + NCollection_List>& aFactories = getFactories(); + for (NCollection_List>::Iterator anIter(aFactories); + anIter.More();) + { + if (TCollection_AsciiString::IsSameString(anIter.Value()->Name(), theName, false)) + { + aFactories.Remove(anIter); + } + else + { + anIter.Next(); + } + } +} + +//================================================================================================== + +occ::handle BRepMesh_DiscretAlgoFactory::DefaultFactory() +{ + const NCollection_List>& aFactories = getFactories(); + return !aFactories.IsEmpty() ? aFactories.First() : occ::handle(); +} + +//================================================================================================== + +occ::handle BRepMesh_DiscretAlgoFactory::FindFactory( + const TCollection_AsciiString& theName) +{ + const NCollection_List>& aFactories = getFactories(); + for (NCollection_List>::Iterator anIter(aFactories); + anIter.More(); + anIter.Next()) + { + if (TCollection_AsciiString::IsSameString(anIter.Value()->Name(), theName, false)) + { + return anIter.Value(); + } + } + return occ::handle(); +} + +//================================================================================================== + +BRepMesh_DiscretAlgoFactory::BRepMesh_DiscretAlgoFactory(const TCollection_AsciiString& theName) + : myName(theName) +{ +} diff --git a/src/ModelingAlgorithms/TKMesh/BRepMesh/BRepMesh_DiscretAlgoFactory.hxx b/src/ModelingAlgorithms/TKMesh/BRepMesh/BRepMesh_DiscretAlgoFactory.hxx new file mode 100644 index 0000000000..0abbf19dee --- /dev/null +++ b/src/ModelingAlgorithms/TKMesh/BRepMesh/BRepMesh_DiscretAlgoFactory.hxx @@ -0,0 +1,81 @@ +// Copyright (c) 2025 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#ifndef _BRepMesh_DiscretAlgoFactory_HeaderFile +#define _BRepMesh_DiscretAlgoFactory_HeaderFile + +#include +#include +#include +#include + +class BRepMesh_DiscretRoot; +class TopoDS_Shape; + +//! Abstract factory for creating meshing algorithms. +//! This class provides a registry-based factory pattern that allows multiple +//! meshing algorithms to coexist without symbol collisions. +//! It follows the pattern established by Graphic3d_GraphicDriverFactory. +class BRepMesh_DiscretAlgoFactory : public Standard_Transient +{ + DEFINE_STANDARD_RTTIEXT(BRepMesh_DiscretAlgoFactory, Standard_Transient) + +public: + //! Registers a factory in the global registry. + //! @param[in] theFactory factory to register + //! @param[in] theIsPreferred if TRUE, add to the beginning of the list (making it default), + //! otherwise add to the end + Standard_EXPORT static void RegisterFactory( + const occ::handle& theFactory, + bool theIsPreferred = false); + + //! Unregisters a factory by name. + //! @param[in] theName name of the factory to unregister + Standard_EXPORT static void UnregisterFactory(const TCollection_AsciiString& theName); + + //! Returns the default (first registered) factory, or NULL if none registered. + Standard_EXPORT static occ::handle DefaultFactory(); + + //! Finds a factory by name. + //! @param[in] theName name of the factory to find + //! @return factory handle, or NULL if not found + Standard_EXPORT static occ::handle FindFactory( + const TCollection_AsciiString& theName); + + //! Returns the global list of registered factories. + Standard_EXPORT static const NCollection_List>& + Factories(); + +public: + //! Creates a new meshing algorithm instance. + //! @param[in] theShape shape to be meshed + //! @param[in] theLinDeflection linear deflection for meshing + //! @param[in] theAngDeflection angular deflection for meshing + //! @return new meshing algorithm instance + virtual occ::handle CreateAlgorithm(const TopoDS_Shape& theShape, + double theLinDeflection, + double theAngDeflection) = 0; + + //! Returns the factory name. + const TCollection_AsciiString& Name() const { return myName; } + +protected: + //! Constructor. + //! @param[in] theName factory name used for identification + Standard_EXPORT BRepMesh_DiscretAlgoFactory(const TCollection_AsciiString& theName); + +protected: + TCollection_AsciiString myName; +}; + +#endif // _BRepMesh_DiscretAlgoFactory_HeaderFile diff --git a/src/ModelingAlgorithms/TKMesh/BRepMesh/BRepMesh_DiscretFactory.cxx b/src/ModelingAlgorithms/TKMesh/BRepMesh/BRepMesh_DiscretFactory.cxx index cbc1a3f9a6..c7e24e3eaa 100644 --- a/src/ModelingAlgorithms/TKMesh/BRepMesh/BRepMesh_DiscretFactory.cxx +++ b/src/ModelingAlgorithms/TKMesh/BRepMesh/BRepMesh_DiscretFactory.cxx @@ -15,173 +15,52 @@ #include -#include -#include -#include -#include +#include -namespace -{ -//! Embedded triangulation tool(s) -static TCollection_AsciiString THE_FAST_DISCRET_MESH("FastDiscret"); - -//! Generate system-dependent name for dynamic library -//! (add standard prefixes and postfixes) -static void MakeLibName(const TCollection_AsciiString& theDefaultName, - TCollection_AsciiString& theLibName) -{ - theLibName = ""; -#ifndef _WIN32 - theLibName += "lib"; -#endif - theLibName += theDefaultName; -#ifdef _WIN32 - theLibName += ".dll"; -#elif __APPLE__ - theLibName += ".dylib"; -#elif defined(HPUX) || defined(_hpux) - theLibName += ".sl"; -#else - theLibName += ".so"; -#endif -} -} // namespace - -//================================================================================================= +//================================================================================================== BRepMesh_DiscretFactory::BRepMesh_DiscretFactory() - : myPluginEntry(nullptr), - myErrorStatus(BRepMesh_FE_NOERROR), - myDefaultName(THE_FAST_DISCRET_MESH), - myFunctionName("DISCRETALGO") + : myDefaultName("FastDiscret") { - // register built-in meshing algorithms - myNames.Add(THE_FAST_DISCRET_MESH); } -//================================================================================================= - -BRepMesh_DiscretFactory::~BRepMesh_DiscretFactory() -{ - clear(); -} - -//================================================================================================= - -void BRepMesh_DiscretFactory::clear() -{ - // what should we do here? Unload dynamic libraries and reset plugins list? -} - -//================================================================================================= +//================================================================================================== BRepMesh_DiscretFactory& BRepMesh_DiscretFactory::Get() { - //! global factory instance static BRepMesh_DiscretFactory THE_GLOBAL_FACTORY; return THE_GLOBAL_FACTORY; } -//================================================================================================= +//================================================================================================== -bool BRepMesh_DiscretFactory::SetDefault(const TCollection_AsciiString& theName, - const TCollection_AsciiString& theFuncName) +bool BRepMesh_DiscretFactory::SetDefaultName(const TCollection_AsciiString& theName) { - myErrorStatus = BRepMesh_FE_NOERROR; - if (theName == THE_FAST_DISCRET_MESH) + occ::handle aFactory = + BRepMesh_DiscretAlgoFactory::FindFactory(theName); + if (aFactory.IsNull()) { - // built-in, nothing to do - myPluginEntry = nullptr; - myDefaultName = theName; - myFunctionName = theFuncName; - return true; - } - else if (theName == myDefaultName && theFuncName == myFunctionName) - { - // already active - return myPluginEntry != nullptr; - } - - TCollection_AsciiString aMeshAlgoId = theName + "_" + theFuncName; - BRepMesh_PluginEntryType aFunc = nullptr; - if (myFactoryMethods.IsBound(aMeshAlgoId)) - { - // retrieve from cache - aFunc = (BRepMesh_PluginEntryType)myFactoryMethods(aMeshAlgoId); - } - else - { - TCollection_AsciiString aLibName; - MakeLibName(theName, aLibName); - OSD_SharedLibrary aSL(aLibName.ToCString()); - if (!aSL.DlOpen(OSD_RTLD_LAZY)) - { - // library is not found - myErrorStatus = BRepMesh_FE_LIBRARYNOTFOUND; - return false; - } - - // retrieve the function from plugin - aFunc = (BRepMesh_PluginEntryType)aSL.DlSymb(theFuncName.ToCString()); - myFactoryMethods.Bind(aMeshAlgoId, (OSD_Function)aFunc); - } - - if (aFunc == nullptr) - { - // function is not found - invalid plugin? - myErrorStatus = BRepMesh_FE_FUNCTIONNOTFOUND; return false; } - // try to create dummy tool - BRepMesh_DiscretRoot* anInstancePtr = nullptr; - int anErr = aFunc(TopoDS_Shape(), 0.001, 0.1, anInstancePtr); - if (anErr != 0 || anInstancePtr == nullptr) - { - // can not create the algo specified - myErrorStatus = BRepMesh_FE_CANNOTCREATEALGO; - delete anInstancePtr; - return false; - } - delete anInstancePtr; - - // if all checks done - switch to this tool - myPluginEntry = aFunc; - myDefaultName = theName; - myFunctionName = theFuncName; - myNames.Add(theName); + myDefaultName = theName; return true; } -//================================================================================================= +//================================================================================================== occ::handle BRepMesh_DiscretFactory::Discret(const TopoDS_Shape& theShape, - const double theDeflection, - const double theAngle) + double theLinDeflection, + double theAngDeflection) { - occ::handle aDiscretRoot; - BRepMesh_DiscretRoot* anInstancePtr = nullptr; - if (myPluginEntry != nullptr) - { - // use plugin - int anErr = myPluginEntry(theShape, theDeflection, theAngle, anInstancePtr); + occ::handle aFactory = + myDefaultName.IsEmpty() ? BRepMesh_DiscretAlgoFactory::DefaultFactory() + : BRepMesh_DiscretAlgoFactory::FindFactory(myDefaultName); - if (anErr != 0 || anInstancePtr == nullptr) - { - // can not create the algo specified - should never happens here - myErrorStatus = BRepMesh_FE_CANNOTCREATEALGO; - return aDiscretRoot; - } - } - else // if (myDefaultName == THE_FAST_DISCRET_MESH) + if (aFactory.IsNull()) { - // use built-in - BRepMesh_IncrementalMesh::Discret(theShape, theDeflection, theAngle, anInstancePtr); + return occ::handle(); } - // cover with handle - aDiscretRoot = anInstancePtr; - - // return the handle - return aDiscretRoot; + return aFactory->CreateAlgorithm(theShape, theLinDeflection, theAngDeflection); } diff --git a/src/ModelingAlgorithms/TKMesh/BRepMesh/BRepMesh_DiscretFactory.hxx b/src/ModelingAlgorithms/TKMesh/BRepMesh/BRepMesh_DiscretFactory.hxx index b9a0171951..45023eb561 100644 --- a/src/ModelingAlgorithms/TKMesh/BRepMesh/BRepMesh_DiscretFactory.hxx +++ b/src/ModelingAlgorithms/TKMesh/BRepMesh/BRepMesh_DiscretFactory.hxx @@ -16,20 +16,17 @@ #include #include -#include -#include -#include -#include -#include -#include -#include #include +#include class TopoDS_Shape; -//! This class intended to setup / retrieve default triangulation algorithm. +//! Factory for retrieving triangulation algorithms. //! Use BRepMesh_DiscretFactory::Get() static method to retrieve global Factory instance. //! Use BRepMesh_DiscretFactory::Discret() method to retrieve meshing tool. +//! +//! This class delegates to BRepMesh_DiscretAlgoFactory registry for algorithm creation. +//! @sa BRepMesh_DiscretAlgoFactory class BRepMesh_DiscretFactory { public: @@ -38,65 +35,29 @@ public: //! Returns the global factory instance. Standard_EXPORT static BRepMesh_DiscretFactory& Get(); - //! Returns the list of registered meshing algorithms. - const NCollection_Map& Names() const { return myNames; } - //! Setup meshing algorithm by name. - //! Returns TRUE if requested tool is available. - //! On fail Factory will continue to use previous algo. - bool SetDefaultName(const TCollection_AsciiString& theName) - { - return SetDefault(theName, myFunctionName); - } + //! Returns TRUE if requested algorithm is available. + //! On fail Factory will continue to use previous algorithm. + //! @param[in] theName name of the algorithm to use + Standard_EXPORT bool SetDefaultName(const TCollection_AsciiString& theName); - //! Returns name for current meshing algorithm. + //! Returns name of current meshing algorithm. const TCollection_AsciiString& DefaultName() const { return myDefaultName; } - //! Advanced function. Changes function name to retrieve from plugin. - //! Returns TRUE if requested tool is available. - //! On fail Factory will continue to use previous algo. - bool SetFunctionName(const TCollection_AsciiString& theFuncName) - { - return SetDefault(myDefaultName, theFuncName); - } - - //! Returns function name that should be exported by plugin. - const TCollection_AsciiString& FunctionName() const { return myFunctionName; } - - //! Returns error status for last meshing algorithm switch. - BRepMesh_FactoryError ErrorStatus() const { return myErrorStatus; } - - //! Setup meshing algorithm that should be created by this Factory. - //! Returns TRUE if requested tool is available. - //! On fail Factory will continue to use previous algo. - //! Call ::ErrorStatus() method to retrieve fault reason. - Standard_EXPORT bool SetDefault(const TCollection_AsciiString& theName, - const TCollection_AsciiString& theFuncName = "DISCRETALGO"); - //! Returns triangulation algorithm instance. - //! @param theShape shape to be meshed. - //! @param theLinDeflection linear deflection to be used for meshing. - //! @param theAngDeflection angular deflection to be used for meshing. + //! @param[in] theShape shape to be meshed + //! @param[in] theLinDeflection linear deflection to be used for meshing + //! @param[in] theAngDeflection angular deflection to be used for meshing + //! @return new meshing algorithm instance, or NULL if no algorithm available Standard_EXPORT occ::handle Discret(const TopoDS_Shape& theShape, - const double theLinDeflection, - const double theAngDeflection); + double theLinDeflection, + double theAngDeflection); protected: //! Constructor - Standard_EXPORT BRepMesh_DiscretFactory(); + BRepMesh_DiscretFactory(); - //! Destructor - Standard_EXPORT virtual ~BRepMesh_DiscretFactory(); - - //! Clears factory data. - Standard_EXPORT void clear(); - - BRepMesh_PluginEntryType myPluginEntry; - BRepMesh_FactoryError myErrorStatus; - NCollection_Map myNames; - TCollection_AsciiString myDefaultName; - TCollection_AsciiString myFunctionName; - NCollection_DataMap myFactoryMethods; + TCollection_AsciiString myDefaultName; }; #endif diff --git a/src/ModelingAlgorithms/TKMesh/BRepMesh/BRepMesh_FactoryError.hxx b/src/ModelingAlgorithms/TKMesh/BRepMesh/BRepMesh_FactoryError.hxx deleted file mode 100644 index d75c3b41b0..0000000000 --- a/src/ModelingAlgorithms/TKMesh/BRepMesh/BRepMesh_FactoryError.hxx +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (c) 2013 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#ifndef _BRepMesh_FactoryError_HeaderFile -#define _BRepMesh_FactoryError_HeaderFile - -enum BRepMesh_FactoryError -{ - BRepMesh_FE_NOERROR, - BRepMesh_FE_LIBRARYNOTFOUND, - BRepMesh_FE_FUNCTIONNOTFOUND, - BRepMesh_FE_CANNOTCREATEALGO -}; - -#endif diff --git a/src/ModelingAlgorithms/TKMesh/BRepMesh/BRepMesh_IncrementalMesh.cxx b/src/ModelingAlgorithms/TKMesh/BRepMesh/BRepMesh_IncrementalMesh.cxx index c225692d46..589638baee 100644 --- a/src/ModelingAlgorithms/TKMesh/BRepMesh/BRepMesh_IncrementalMesh.cxx +++ b/src/ModelingAlgorithms/TKMesh/BRepMesh/BRepMesh_IncrementalMesh.cxx @@ -16,7 +16,6 @@ #include #include -#include #include #include #include @@ -148,6 +147,3 @@ void BRepMesh_IncrementalMesh::SetParallelDefault(const bool theInParallel) { IS_IN_PARALLEL = theInParallel; } - -//! Export Mesh Plugin entry function -DISCRETPLUGIN(BRepMesh_IncrementalMesh) diff --git a/src/ModelingAlgorithms/TKMesh/BRepMesh/BRepMesh_IncrementalMeshFactory.cxx b/src/ModelingAlgorithms/TKMesh/BRepMesh/BRepMesh_IncrementalMeshFactory.cxx new file mode 100644 index 0000000000..a7f39803be --- /dev/null +++ b/src/ModelingAlgorithms/TKMesh/BRepMesh/BRepMesh_IncrementalMeshFactory.cxx @@ -0,0 +1,61 @@ +// Copyright (c) 2025 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#include + +#include + +IMPLEMENT_STANDARD_RTTIEXT(BRepMesh_IncrementalMeshFactory, BRepMesh_DiscretAlgoFactory) + +namespace +{ +//! Self-registering factory instance +static occ::handle THE_FACTORY_INSTANCE; + +//! Initialization helper that registers the factory at startup +struct FactoryInitializer +{ + FactoryInitializer() + { + if (THE_FACTORY_INSTANCE.IsNull()) + { + THE_FACTORY_INSTANCE = new BRepMesh_IncrementalMeshFactory(); + } + } +}; + +static FactoryInitializer THE_FACTORY_INIT; +} // namespace + +//================================================================================================== + +BRepMesh_IncrementalMeshFactory::BRepMesh_IncrementalMeshFactory() + : BRepMesh_DiscretAlgoFactory("FastDiscret") +{ + RegisterFactory(this, true); +} + +//================================================================================================== + +occ::handle BRepMesh_IncrementalMeshFactory::CreateAlgorithm( + const TopoDS_Shape& theShape, + double theLinDeflection, + double theAngDeflection) +{ + occ::handle anAlgo = new BRepMesh_IncrementalMesh(); + anAlgo->ChangeParameters().Deflection = theLinDeflection; + anAlgo->ChangeParameters().Angle = theAngDeflection; + anAlgo->ChangeParameters().InParallel = BRepMesh_IncrementalMesh::IsParallelDefault(); + anAlgo->SetShape(theShape); + return anAlgo; +} diff --git a/src/ModelingAlgorithms/TKMesh/BRepMesh/BRepMesh_IncrementalMeshFactory.hxx b/src/ModelingAlgorithms/TKMesh/BRepMesh/BRepMesh_IncrementalMeshFactory.hxx new file mode 100644 index 0000000000..c11ee1eb0a --- /dev/null +++ b/src/ModelingAlgorithms/TKMesh/BRepMesh/BRepMesh_IncrementalMeshFactory.hxx @@ -0,0 +1,41 @@ +// Copyright (c) 2025 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#ifndef _BRepMesh_IncrementalMeshFactory_HeaderFile +#define _BRepMesh_IncrementalMeshFactory_HeaderFile + +#include + +//! Factory for creating BRepMesh_IncrementalMesh instances. +//! This factory is registered under the name "FastDiscret" and provides +//! the default built-in meshing algorithm. +class BRepMesh_IncrementalMeshFactory : public BRepMesh_DiscretAlgoFactory +{ + DEFINE_STANDARD_RTTIEXT(BRepMesh_IncrementalMeshFactory, BRepMesh_DiscretAlgoFactory) + +public: + //! Constructor. Registers this factory under the name "FastDiscret". + Standard_EXPORT BRepMesh_IncrementalMeshFactory(); + + //! Creates a new BRepMesh_IncrementalMesh instance. + //! @param[in] theShape shape to be meshed + //! @param[in] theLinDeflection linear deflection for meshing + //! @param[in] theAngDeflection angular deflection for meshing + //! @return new meshing algorithm instance + Standard_EXPORT occ::handle CreateAlgorithm( + const TopoDS_Shape& theShape, + double theLinDeflection, + double theAngDeflection) override; +}; + +#endif // _BRepMesh_IncrementalMeshFactory_HeaderFile diff --git a/src/ModelingAlgorithms/TKMesh/BRepMesh/BRepMesh_PluginEntryType.hxx b/src/ModelingAlgorithms/TKMesh/BRepMesh/BRepMesh_PluginEntryType.hxx deleted file mode 100644 index 824f67d06f..0000000000 --- a/src/ModelingAlgorithms/TKMesh/BRepMesh/BRepMesh_PluginEntryType.hxx +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (c) 1999-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#ifndef _BRepMesh_PluginEntryType_HeaderFile -#define _BRepMesh_PluginEntryType_HeaderFile - -class TopoDS_Shape; -class BRepMesh_DiscretRoot; - -//! Type definition for plugin exported function -typedef int (*BRepMesh_PluginEntryType)(const TopoDS_Shape& theShape, - const double theLinDeflection, - const double theAngDeflection, - BRepMesh_DiscretRoot*& theMeshAlgoInstance); - -#endif diff --git a/src/ModelingAlgorithms/TKMesh/BRepMesh/BRepMesh_PluginMacro.hxx b/src/ModelingAlgorithms/TKMesh/BRepMesh/BRepMesh_PluginMacro.hxx deleted file mode 100644 index 1bbaf90916..0000000000 --- a/src/ModelingAlgorithms/TKMesh/BRepMesh/BRepMesh_PluginMacro.hxx +++ /dev/null @@ -1,36 +0,0 @@ -// Created on: 2008-04-11 -// Created by: Peter KURNEV -// Copyright (c) 2008-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#ifndef BRepMesh_PluginMacro_HeaderFile -#define BRepMesh_PluginMacro_HeaderFile - -#define DISCRETPLUGIN(name) \ - extern "C" \ - { \ - Standard_EXPORT int DISCRETALGO(const TopoDS_Shape&, \ - const double, \ - const double, \ - BRepMesh_DiscretRoot*&); \ - } \ - \ - int DISCRETALGO(const TopoDS_Shape& theShape, \ - const double theLinDeflection, \ - const double theAngDeflection, \ - BRepMesh_DiscretRoot*& theAlgo) \ - { \ - return name::Discret(theShape, theLinDeflection, theAngDeflection, theAlgo); \ - } - -#endif diff --git a/src/ModelingAlgorithms/TKMesh/BRepMesh/FILES.cmake b/src/ModelingAlgorithms/TKMesh/BRepMesh/FILES.cmake index b10314c0e0..b3ede0884d 100644 --- a/src/ModelingAlgorithms/TKMesh/BRepMesh/FILES.cmake +++ b/src/ModelingAlgorithms/TKMesh/BRepMesh/FILES.cmake @@ -34,10 +34,14 @@ set(OCCT_BRepMesh_FILES BRepMesh_DelaunayBaseMeshAlgo.hxx BRepMesh_DelaunayDeflectionControlMeshAlgo.hxx BRepMesh_DelaunayNodeInsertionMeshAlgo.hxx + BRepMesh_DiscretAlgoFactory.cxx + BRepMesh_DiscretAlgoFactory.hxx BRepMesh_DiscretFactory.cxx BRepMesh_DiscretFactory.hxx BRepMesh_DiscretRoot.cxx BRepMesh_DiscretRoot.hxx + BRepMesh_IncrementalMeshFactory.cxx + BRepMesh_IncrementalMeshFactory.hxx BRepMesh_Edge.hxx BRepMesh_EdgeDiscret.cxx BRepMesh_EdgeDiscret.hxx @@ -50,7 +54,6 @@ set(OCCT_BRepMesh_FILES BRepMesh_FaceChecker.hxx BRepMesh_FaceDiscret.cxx BRepMesh_FaceDiscret.hxx - BRepMesh_FactoryError.hxx BRepMesh_FastDiscret.hxx BRepMesh_GeomTool.cxx BRepMesh_GeomTool.hxx @@ -73,8 +76,6 @@ set(OCCT_BRepMesh_FILES BRepMesh_NodeInsertionMeshAlgo.hxx BRepMesh_OrientedEdge.hxx BRepMesh_PairOfIndex.hxx - BRepMesh_PluginEntryType.hxx - BRepMesh_PluginMacro.hxx BRepMesh_SelectorOfDataStructureOfDelaun.cxx BRepMesh_SelectorOfDataStructureOfDelaun.hxx BRepMesh_ShapeTool.cxx diff --git a/src/ModelingAlgorithms/TKMesh/GTests/BRepMesh_DiscretAlgoFactory_Test.cxx b/src/ModelingAlgorithms/TKMesh/GTests/BRepMesh_DiscretAlgoFactory_Test.cxx new file mode 100644 index 0000000000..334f01506f --- /dev/null +++ b/src/ModelingAlgorithms/TKMesh/GTests/BRepMesh_DiscretAlgoFactory_Test.cxx @@ -0,0 +1,145 @@ +// Copyright (c) 2025 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#include + +#include +#include +#include +#include +#include +#include + +//! Test fixture for BRepMesh_DiscretAlgoFactory tests +class BRepMesh_DiscretAlgoFactoryTest : public testing::Test +{ +protected: + void SetUp() override + { + // Create a simple box shape for testing + BRepPrimAPI_MakeBox aBoxMaker(10.0, 10.0, 10.0); + myBox = aBoxMaker.Shape(); + } + + TopoDS_Shape myBox; +}; + +//! Test that at least one factory is registered (FastDiscret from BRepMesh_IncrementalMeshFactory) +TEST_F(BRepMesh_DiscretAlgoFactoryTest, Factories_AtLeastOneRegistered) +{ + const NCollection_List>& aFactories = + BRepMesh_DiscretAlgoFactory::Factories(); + + EXPECT_FALSE(aFactories.IsEmpty()) << "No factories registered"; +} + +//! Test that DefaultFactory returns a valid factory +TEST_F(BRepMesh_DiscretAlgoFactoryTest, DefaultFactory_ReturnsValid) +{ + occ::handle aFactory = BRepMesh_DiscretAlgoFactory::DefaultFactory(); + + EXPECT_FALSE(aFactory.IsNull()) << "DefaultFactory returned null"; +} + +//! Test that FastDiscret factory is registered and can be found +TEST_F(BRepMesh_DiscretAlgoFactoryTest, FindFactory_FastDiscret) +{ + occ::handle aFactory = + BRepMesh_DiscretAlgoFactory::FindFactory("FastDiscret"); + + EXPECT_FALSE(aFactory.IsNull()) << "FastDiscret factory not found"; + if (!aFactory.IsNull()) + { + EXPECT_EQ(aFactory->Name(), "FastDiscret"); + } +} + +//! Test that FindFactory returns null for non-existent factory +TEST_F(BRepMesh_DiscretAlgoFactoryTest, FindFactory_NonExistent_ReturnsNull) +{ + occ::handle aFactory = + BRepMesh_DiscretAlgoFactory::FindFactory("NonExistentFactory"); + + EXPECT_TRUE(aFactory.IsNull()) << "FindFactory should return null for non-existent factory"; +} + +//! Test that CreateAlgorithm creates a valid algorithm +TEST_F(BRepMesh_DiscretAlgoFactoryTest, CreateAlgorithm_ReturnsValid) +{ + occ::handle aFactory = BRepMesh_DiscretAlgoFactory::DefaultFactory(); + ASSERT_FALSE(aFactory.IsNull()); + + occ::handle anAlgo = aFactory->CreateAlgorithm(myBox, 0.1, 0.5); + + EXPECT_FALSE(anAlgo.IsNull()) << "CreateAlgorithm returned null"; +} + +//! Test that created algorithm can mesh a shape +TEST_F(BRepMesh_DiscretAlgoFactoryTest, CreateAlgorithm_CanMesh) +{ + occ::handle aFactory = BRepMesh_DiscretAlgoFactory::DefaultFactory(); + ASSERT_FALSE(aFactory.IsNull()); + + occ::handle anAlgo = aFactory->CreateAlgorithm(myBox, 0.1, 0.5); + ASSERT_FALSE(anAlgo.IsNull()); + + anAlgo->Perform(); + + EXPECT_TRUE(anAlgo->IsDone()) << "Meshing failed"; +} + +//! Test that BRepMesh_DiscretFactory::Discret uses the new registry +TEST_F(BRepMesh_DiscretAlgoFactoryTest, DiscretFactory_UsesRegistry) +{ + BRepMesh_DiscretFactory& aFactory = BRepMesh_DiscretFactory::Get(); + + occ::handle anAlgo = aFactory.Discret(myBox, 0.1, 0.5); + + EXPECT_FALSE(anAlgo.IsNull()) << "Discret returned null"; + if (!anAlgo.IsNull()) + { + anAlgo->Perform(); + EXPECT_TRUE(anAlgo->IsDone()) << "Meshing failed"; + } +} + +//! Test that SetDefaultName works with registry-based factories +TEST_F(BRepMesh_DiscretAlgoFactoryTest, DiscretFactory_SetDefaultName) +{ + BRepMesh_DiscretFactory& aFactory = BRepMesh_DiscretFactory::Get(); + + bool isSuccess = aFactory.SetDefaultName("FastDiscret"); + EXPECT_TRUE(isSuccess) << "SetDefaultName(FastDiscret) failed"; + EXPECT_EQ(aFactory.DefaultName(), "FastDiscret"); +} + +//! Test factory name uniqueness - registering same factory twice should not duplicate +TEST_F(BRepMesh_DiscretAlgoFactoryTest, RegisterFactory_Uniqueness) +{ + const NCollection_List>& aFactories = + BRepMesh_DiscretAlgoFactory::Factories(); + + // Count factories with name "FastDiscret" + int aCount = 0; + for (NCollection_List>::Iterator anIter(aFactories); + anIter.More(); + anIter.Next()) + { + if (anIter.Value()->Name() == "FastDiscret") + { + ++aCount; + } + } + + EXPECT_EQ(aCount, 1) << "FastDiscret factory should be registered exactly once"; +} diff --git a/src/ModelingAlgorithms/TKMesh/GTests/FILES.cmake b/src/ModelingAlgorithms/TKMesh/GTests/FILES.cmake index c6dd438425..4108dc3ea0 100644 --- a/src/ModelingAlgorithms/TKMesh/GTests/FILES.cmake +++ b/src/ModelingAlgorithms/TKMesh/GTests/FILES.cmake @@ -3,5 +3,6 @@ set(OCCT_TKMesh_GTests_FILES_LOCATION "${CMAKE_CURRENT_LIST_DIR}") set(OCCT_TKMesh_GTests_FILES BRepMesh_Delaun_Test.cxx + BRepMesh_DiscretAlgoFactory_Test.cxx BRepMesh_GeomTool_Test.cxx ) diff --git a/src/ModelingAlgorithms/TKXMesh/XBRepMesh/FILES.cmake b/src/ModelingAlgorithms/TKXMesh/XBRepMesh/FILES.cmake index 7fa1e8a105..0c6a8e6454 100644 --- a/src/ModelingAlgorithms/TKXMesh/XBRepMesh/FILES.cmake +++ b/src/ModelingAlgorithms/TKXMesh/XBRepMesh/FILES.cmake @@ -2,6 +2,6 @@ set(OCCT_XBRepMesh_FILES_LOCATION "${CMAKE_CURRENT_LIST_DIR}") set(OCCT_XBRepMesh_FILES - XBRepMesh.cxx - XBRepMesh.hxx + XBRepMesh_Factory.cxx + XBRepMesh_Factory.hxx ) diff --git a/src/ModelingAlgorithms/TKXMesh/XBRepMesh/XBRepMesh.cxx b/src/ModelingAlgorithms/TKXMesh/XBRepMesh/XBRepMesh.cxx deleted file mode 100644 index b0cb9d857d..0000000000 --- a/src/ModelingAlgorithms/TKXMesh/XBRepMesh/XBRepMesh.cxx +++ /dev/null @@ -1,38 +0,0 @@ -// Created on: 2008-04-11 -// Created by: Peter KURNEV -// Copyright (c) 2008-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#include -#include -#include - -//================================================================================================= - -int XBRepMesh::Discret(const TopoDS_Shape& theShape, - const double theDeflection, - const double theAngle, - BRepMesh_DiscretRoot*& theAlgo) -{ - int iErr; - // - iErr = 0; - BRepMesh_IncrementalMesh* anAlgo = new BRepMesh_IncrementalMesh; - anAlgo->ChangeParameters().Deflection = theDeflection; - anAlgo->ChangeParameters().Angle = theAngle; - anAlgo->SetShape(theShape); - theAlgo = anAlgo; - - return iErr; -} -DISCRETPLUGIN(XBRepMesh) diff --git a/src/ModelingAlgorithms/TKXMesh/XBRepMesh/XBRepMesh.hxx b/src/ModelingAlgorithms/TKXMesh/XBRepMesh/XBRepMesh.hxx deleted file mode 100644 index 9049133d00..0000000000 --- a/src/ModelingAlgorithms/TKXMesh/XBRepMesh/XBRepMesh.hxx +++ /dev/null @@ -1,37 +0,0 @@ -// Created on: 2008-04-11 -// Created by: Peter KURNEV -// Copyright (c) 2008-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#ifndef _XBRepMesh_HeaderFile -#define _XBRepMesh_HeaderFile - -#include -#include -#include -#include - -class TopoDS_Shape; - -class XBRepMesh -{ -public: - DEFINE_STANDARD_ALLOC - - Standard_EXPORT static int Discret(const TopoDS_Shape& theShape, - const double theDeflection, - const double theAngle, - BRepMesh_DiscretRoot*& theAlgo); -}; - -#endif diff --git a/src/ModelingAlgorithms/TKXMesh/XBRepMesh/XBRepMesh_Factory.cxx b/src/ModelingAlgorithms/TKXMesh/XBRepMesh/XBRepMesh_Factory.cxx new file mode 100644 index 0000000000..a652688719 --- /dev/null +++ b/src/ModelingAlgorithms/TKXMesh/XBRepMesh/XBRepMesh_Factory.cxx @@ -0,0 +1,59 @@ +// Copyright (c) 2025 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#include + +#include + +IMPLEMENT_STANDARD_RTTIEXT(XBRepMesh_Factory, BRepMesh_DiscretAlgoFactory) + +namespace +{ +//! Self-registering factory instance +static occ::handle THE_FACTORY_INSTANCE; + +//! Initialization helper that registers the factory at startup +struct FactoryInitializer +{ + FactoryInitializer() + { + if (THE_FACTORY_INSTANCE.IsNull()) + { + THE_FACTORY_INSTANCE = new XBRepMesh_Factory(); + } + } +}; + +static FactoryInitializer THE_FACTORY_INIT; +} // namespace + +//================================================================================================== + +XBRepMesh_Factory::XBRepMesh_Factory() + : BRepMesh_DiscretAlgoFactory("XBRepMesh") +{ + RegisterFactory(this); +} + +//================================================================================================== + +occ::handle XBRepMesh_Factory::CreateAlgorithm(const TopoDS_Shape& theShape, + double theLinDeflection, + double theAngDeflection) +{ + occ::handle anAlgo = new BRepMesh_IncrementalMesh(); + anAlgo->ChangeParameters().Deflection = theLinDeflection; + anAlgo->ChangeParameters().Angle = theAngDeflection; + anAlgo->SetShape(theShape); + return anAlgo; +} diff --git a/src/ModelingAlgorithms/TKXMesh/XBRepMesh/XBRepMesh_Factory.hxx b/src/ModelingAlgorithms/TKXMesh/XBRepMesh/XBRepMesh_Factory.hxx new file mode 100644 index 0000000000..fd02a59435 --- /dev/null +++ b/src/ModelingAlgorithms/TKXMesh/XBRepMesh/XBRepMesh_Factory.hxx @@ -0,0 +1,41 @@ +// Copyright (c) 2025 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#ifndef _XBRepMesh_Factory_HeaderFile +#define _XBRepMesh_Factory_HeaderFile + +#include + +//! Factory for creating XBRepMesh meshing algorithm instances. +//! This factory is registered under the name "XBRepMesh" and provides +//! an alternative meshing algorithm based on BRepMesh_IncrementalMesh. +class XBRepMesh_Factory : public BRepMesh_DiscretAlgoFactory +{ + DEFINE_STANDARD_RTTIEXT(XBRepMesh_Factory, BRepMesh_DiscretAlgoFactory) + +public: + //! Constructor. Registers this factory under the name "XBRepMesh". + Standard_EXPORT XBRepMesh_Factory(); + + //! Creates a new meshing algorithm instance. + //! @param[in] theShape shape to be meshed + //! @param[in] theLinDeflection linear deflection for meshing + //! @param[in] theAngDeflection angular deflection for meshing + //! @return new meshing algorithm instance + Standard_EXPORT occ::handle CreateAlgorithm( + const TopoDS_Shape& theShape, + double theLinDeflection, + double theAngDeflection) override; +}; + +#endif // _XBRepMesh_Factory_HeaderFile