[Toponaming] create ElementMap class (#9175)

* Copypaste ElementMap
* Add MappedNameRef
* Fix missing include
* Copypaste `findTagInElementName`
* fix error introduced _somewhere_
* refactor toponaming constants
* Move `findTagInElementName` in `MappedName`
* reintroduce workaround to compile ElementMap
* Added missing functions copied from complexgeodata
* fix last compile errors, reorder and format files
* remove recursive refs to ComplexGeoData
* Add more comments
* fixed comments and added tests
* added FIXME, make functions private, misc fixes
* Move static functions from complexGeoData to PostfixStringReferences. Rename to ElementNamingUtils
* Fix broken includes due to previous change
* Revert constants from string to const char*
* added childmap tests and made hasher public
* Make functions private
* Added remaining tests
* removed bool return from `erase` functions
* fix missing appexport

Co-authored-by: John Dupuy <jdupuy98@gmail.com>
This commit is contained in:
Pesc0
2023-06-15 16:05:24 +02:00
committed by GitHub
parent 32d8029780
commit 4a8d3853ba
26 changed files with 2450 additions and 218 deletions

View File

@@ -74,6 +74,7 @@
#include <App/Application.h>
#include <App/Document.h>
#include <App/DocumentObjectPy.h>
#include <App/ElementNamingUtils.h>
#include <Base/Console.h>
#include <Base/Exception.h>
#include <Base/FileInfo.h>
@@ -102,7 +103,6 @@
#include "TopoShapeSolidPy.h"
#include "TopoShapeWirePy.h"
#ifdef FCUseFreeType
# include "FT2FC.h"
#endif
@@ -2286,14 +2286,14 @@ private:
const char *subname;
if (!PyArg_ParseTuple(args.ptr(), "s",&subname))
throw Py::Exception();
auto element = Data::ComplexGeoData::findElementName(subname);
auto element = Data::findElementName(subname);
std::string sub(subname,element-subname);
Py::List list;
list.append(Py::String(sub));
const char *dot = strchr(element,'.');
if(!dot)
dot = element+strlen(element);
const char *mapped = Data::ComplexGeoData::isMappedElement(element);
const char *mapped = Data::isMappedElement(element);
if(mapped)
list.append(Py::String(std::string(mapped,dot-mapped)));
else
@@ -2317,8 +2317,8 @@ private:
if (!subname.empty() && subname[subname.size()-1]!='.')
subname += '.';
if (mapped && mapped[0]) {
if (!Data::ComplexGeoData::isMappedElement(mapped))
subname += Data::ComplexGeoData::elementMapPrefix();
if (!Data::isMappedElement(mapped))
subname += Data::ELEMENT_MAP_PREFIX;
subname += mapped;
}
if (element && element[0]) {

View File

@@ -55,6 +55,7 @@
#include <App/FeaturePythonPyImp.h>
#include <App/Link.h>
#include <App/GeoFeatureGroupExtension.h>
#include <App/ElementNamingUtils.h>
#include <Base/Exception.h>
#include <Base/Placement.h>
#include <Base/Rotation.h>
@@ -65,7 +66,6 @@
#include "PartPyCXX.h"
#include "TopoShapePy.h"
using namespace Part;
namespace bp = boost::placeholders;
@@ -121,7 +121,7 @@ App::DocumentObject *Feature::getSubObject(const char *subname,
{
// having '.' inside subname means it is referencing some children object,
// instead of any sub-element from ourself
if(subname && !Data::ComplexGeoData::isMappedElement(subname) && strchr(subname,'.'))
if(subname && !Data::isMappedElement(subname) && strchr(subname,'.'))
return App::DocumentObject::getSubObject(subname,pyObj,pmat,transform,depth);
Base::Matrix4D _mat;
@@ -280,7 +280,7 @@ static TopoShape _getTopoShape(const App::DocumentObject *obj, const char *subna
if(powner) *powner = nullptr;
std::string _subname;
auto subelement = Data::ComplexGeoData::findElementName(subname);
auto subelement = Data::findElementName(subname);
if(!needSubElement && subname) {
// strip out element name if not needed
if(subelement && *subelement) {
@@ -413,7 +413,7 @@ static TopoShape _getTopoShape(const App::DocumentObject *obj, const char *subna
continue;
}else{
if(link && !link->getShowElementValue())
shape = baseShape.makeTransform(mat,(TopoShape::indexPostfix()+childName).c_str());
shape = baseShape.makeTransform(mat,(Data::POSTFIX_INDEX + childName).c_str());
else {
shape = baseShape.makeTransform(mat);
}

View File

@@ -160,6 +160,7 @@
#endif // _PreComp_
#include <App/Material.h>
#include <App/ElementNamingUtils.h>
#include <Base/BoundBox.h>
#include <Base/Builder3D.h>
#include <Base/Console.h>
@@ -472,7 +473,7 @@ TopAbs_ShapeEnum TopoShape::shapeType(const char *type, bool silent) {
}
}
if(!silent) {
if(Data::ComplexGeoData::hasMissingElement(type))
if(Data::hasMissingElement(type))
FC_THROWM(Base::CADKernelError,"missing shape element: " << (type?type:"?"));
FC_THROWM(Base::CADKernelError,"invalid shape type: " << (type?type:"?"));
}

View File

@@ -34,6 +34,7 @@
#include "App/DocumentObject.h"
#include <App/FeaturePythonPyImp.h>
#include <App/ElementNamingUtils.h>
#include "App/OriginFeature.h"
#include <Base/Console.h>
@@ -237,7 +238,7 @@ Body* Feature::getFeatureBody() const {
App::DocumentObject *Feature::getSubObject(const char *subname,
PyObject **pyObj, Base::Matrix4D *pmat, bool transform, int depth) const
{
if (subname && subname != Data::ComplexGeoData::findElementName(subname)) {
if (subname && subname != Data::findElementName(subname)) {
const char * dot = strchr(subname,'.');
if (dot) {
auto body = PartDesign::Body::findBodyOf(this);

View File

@@ -39,6 +39,7 @@
#include <App/GroupExtension.h>
#include <App/Link.h>
#include <App/OriginFeature.h>
#include <App/ElementNamingUtils.h>
#include <Mod/Part/App/TopoShape.h>
#include "ShapeBinder.h"
@@ -382,7 +383,7 @@ App::DocumentObject* SubShapeBinder::getSubObject(const char* subname, PyObject*
auto sobj = Part::Feature::getSubObject(subname, pyObj, mat, transform, depth);
if (sobj)
return sobj;
if (Data::ComplexGeoData::findElementName(subname) == subname)
if (Data::findElementName(subname) == subname)
return nullptr;
const char* dot = strchr(subname, '.');
@@ -405,7 +406,7 @@ App::DocumentObject* SubShapeBinder::getSubObject(const char* subname, PyObject*
}
else if (!boost::equals(sobj->getNameInDocument(), name))
continue;
name = Data::ComplexGeoData::noElementName(sub.c_str());
name = Data::noElementName(sub.c_str());
name += dot + 1;
if (mat && transform)
*mat *= Placement.getValue().toMatrix();
@@ -640,7 +641,7 @@ void SubShapeBinder::update(SubShapeBinder::UpdateOption options) {
std::ostringstream ss;
ss << "Failed to obtain shape " <<
obj->getFullName() << '.'
<< Data::ComplexGeoData::oldElementName(sub.c_str());
<< Data::oldElementName(sub.c_str());
errMsg = ss.str();
}
}