Toponaming/Part: trasnfer in getElementName

This commit is contained in:
Zheng, Lei
2024-02-27 10:09:32 -05:00
committed by bgbsww
parent e17f1b5cbe
commit 1d9fcfea9a
9 changed files with 440 additions and 6 deletions

View File

@@ -25,6 +25,7 @@
#include <App/GeoFeaturePy.h>
#include "ComplexGeoData.h"
#include "GeoFeature.h"
#include "GeoFeatureGroupExtension.h"
#include "ElementNamingUtils.h"
@@ -78,17 +79,46 @@ PyObject* GeoFeature::getPyObject()
return Py::new_reference_to(PythonObject);
}
std::pair<std::string,std::string> GeoFeature::getElementName(
const char *name, ElementNameType type) const
std::pair<std::string,std::string>
GeoFeature::getElementName(const char *name, ElementNameType type) const
{
(void)type;
std::pair<std::string,std::string> ret;
if(!name)
return ret;
auto prop = getPropertyOfGeometry();
if(!prop) return std::make_pair("", name);
ret.second = name;
auto geo = prop->getComplexData();
if(!geo) return std::make_pair("", name);
return _getElementName(name, geo->getElementName(name));
}
std::pair<std::string,std::string>
GeoFeature::_getElementName(const char *name, const Data::MappedElement &mapped) const
{
std::pair<std::string,std::string> ret;
if (mapped.index && mapped.name) {
std::ostringstream ss;
ss << Data::ComplexGeoData::elementMapPrefix()
<< mapped.name << '.' << mapped.index;
ret.first = ss.str();
mapped.index.toString(ret.second);
} else if (mapped.name) {
// FC_TRACE("element mapped name " << name << " not found in " << getFullName());
ret.first = name;
const char *dot = strrchr(name,'.');
if(dot) {
// deliberately mangle the old style element name to signal a
// missing reference
ret.second = Data::MISSING_PREFIX;
ret.second += dot+1;
}
} else {
mapped.index.toString(ret.second);
}
return ret;
}

View File

@@ -26,7 +26,7 @@
#include "DocumentObject.h"
#include "PropertyGeo.h"
#include "MappedElement.h"
namespace App
{
@@ -120,6 +120,10 @@ public:
* @return Base::Placement The transformation from the global reference coordinate system
*/
Base::Placement globalPlacement() const;
protected:
std::pair<std::string, std::string> _getElementName(const char* name,
const Data::MappedElement& mapped) const;
};
} //namespace App

View File

@@ -147,6 +147,18 @@ public:
return result;
}
const char * toString(std::string & s) const
{
// Note! s is not cleared on purpose.
std::size_t offset = s.size();
s += this->type;
if (this->index > 0)
s += std::to_string(this->index);
return s.c_str() + offset;
}
/// An indexedName is represented as the simple concatenation of the name and its index, e.g.
/// "EDGE1" or "FACE42".
friend std::ostream & operator<<(std::ostream & stream, const IndexedName & indexedName)

View File

@@ -474,6 +474,28 @@ public:
return appendToBuffer(res, startPosition, len);
}
const char * toString(std::string &s, int from=0, int len=-1) const
{
std::size_t offset = s.size();
int count = this->size();
if (from < 0)
from = 0;
else if (from >= count)
return s.c_str()+s.size();
if (len < 0 || len > count - from)
len = count - from;
s.reserve(s.size() + len);
if (from < this->data.size()) {
count = this->data.size() - from;
if (len < count)
count = len;
s.append(this->data.constData()+from, count);
len -= count;
}
s.append(this->postfix.constData(), len);
return s.c_str() + offset;
}
/// Given a (possibly non-empty) std::string buffer, append this instance to it, starting at a
/// specified position, and continuing for a specified number of bytes.
///