App/Toponaming: Basic tests and linter issues
This commit is contained in:
committed by
Chris Hennes
parent
9ea7b6424b
commit
e7f8f26bd5
@@ -24,7 +24,7 @@
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#include "PreCompiled.h"
|
||||
#include "PreCompiled.h"// NOLINT
|
||||
|
||||
#ifndef _PreComp_
|
||||
# include <cstdlib>
|
||||
@@ -41,21 +41,19 @@
|
||||
#include <Base/Rotation.h>
|
||||
|
||||
#include <boost/iostreams/device/array.hpp>
|
||||
#include <boost/iostreams/stream.hpp>
|
||||
|
||||
|
||||
using namespace Data;
|
||||
|
||||
TYPESYSTEM_SOURCE_ABSTRACT(Data::Segment , Base::BaseClass)
|
||||
TYPESYSTEM_SOURCE_ABSTRACT(Data::Segment , Base::BaseClass)// NOLINT
|
||||
TYPESYSTEM_SOURCE_ABSTRACT(Data::ComplexGeoData , Base::Persistence)// NOLINT
|
||||
|
||||
|
||||
TYPESYSTEM_SOURCE_ABSTRACT(Data::ComplexGeoData , Base::Persistence)
|
||||
|
||||
FC_LOG_LEVEL_INIT("ComplexGeoData", true,true)
|
||||
FC_LOG_LEVEL_INIT("ComplexGeoData", true,true)// NOLINT
|
||||
|
||||
namespace bio = boost::iostreams;
|
||||
using namespace Data;
|
||||
|
||||
// NOLINTBEGIN(cppcoreguidelines-pro-bounds-pointer-arithmetic)
|
||||
|
||||
ComplexGeoData::ComplexGeoData()
|
||||
:Tag(0)
|
||||
@@ -107,10 +105,10 @@ Base::Placement ComplexGeoData::getPlacement() const
|
||||
{
|
||||
Base::Matrix4D mat = getTransform();
|
||||
|
||||
return Base::Placement(Base::Vector3d(mat[0][3],
|
||||
mat[1][3],
|
||||
mat[2][3]),
|
||||
Base::Rotation(mat));
|
||||
return {Base::Vector3d(mat[0][3],
|
||||
mat[1][3],
|
||||
mat[2][3]),
|
||||
Base::Rotation(mat)};
|
||||
}
|
||||
|
||||
double ComplexGeoData::getAccuracy() const
|
||||
@@ -118,19 +116,21 @@ double ComplexGeoData::getAccuracy() const
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
void ComplexGeoData::getLinesFromSubElement(const Segment*,
|
||||
void ComplexGeoData::getLinesFromSubElement(const Segment* segment,
|
||||
std::vector<Base::Vector3d> &Points,
|
||||
std::vector<Line> &lines) const
|
||||
{
|
||||
(void)segment;
|
||||
(void)Points;
|
||||
(void)lines;
|
||||
}
|
||||
|
||||
void ComplexGeoData::getFacesFromSubElement(const Segment*,
|
||||
void ComplexGeoData::getFacesFromSubElement(const Segment* segment,
|
||||
std::vector<Base::Vector3d> &Points,
|
||||
std::vector<Base::Vector3d> &PointNormals,
|
||||
std::vector<Facet> &faces) const
|
||||
{
|
||||
(void)segment;
|
||||
(void)Points;
|
||||
(void)PointNormals;
|
||||
(void)faces;
|
||||
@@ -174,8 +174,9 @@ void ComplexGeoData::getFaces(std::vector<Base::Vector3d> &Points,
|
||||
(void)flags;
|
||||
}
|
||||
|
||||
bool ComplexGeoData::getCenterOfGravity(Base::Vector3d&) const
|
||||
bool ComplexGeoData::getCenterOfGravity(Base::Vector3d& unused) const
|
||||
{
|
||||
(void)unused;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -195,18 +196,21 @@ MappedName ComplexGeoData::getMappedName(const IndexedName & element,
|
||||
bool allowUnmapped,
|
||||
ElementIDRefs *sid) const
|
||||
{
|
||||
if (!element)
|
||||
return MappedName();
|
||||
if (!element) {
|
||||
return {};
|
||||
}
|
||||
flushElementMap();
|
||||
if(!_elementMap) {
|
||||
if (allowUnmapped)
|
||||
if (allowUnmapped) {
|
||||
return MappedName(element);
|
||||
return MappedName();
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
MappedName name = _elementMap->find(element, sid);
|
||||
if (allowUnmapped && !name)
|
||||
if (allowUnmapped && !name) {
|
||||
return MappedName(element);
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
@@ -214,11 +218,12 @@ IndexedName ComplexGeoData::getIndexedName(const MappedName & name,
|
||||
ElementIDRefs *sid) const
|
||||
{
|
||||
flushElementMap();
|
||||
if (!name)
|
||||
if (!name) {
|
||||
return IndexedName();
|
||||
}
|
||||
if (!_elementMap) {
|
||||
std::string s;
|
||||
return IndexedName(name.appendToBuffer(s), getElementTypes());
|
||||
std::string str;
|
||||
return {name.appendToBuffer(str), getElementTypes()};
|
||||
}
|
||||
return _elementMap->find(name, sid);
|
||||
}
|
||||
@@ -229,24 +234,29 @@ ComplexGeoData::getElementName(const char *name,
|
||||
bool copy) const
|
||||
{
|
||||
IndexedName element(name, getElementTypes());
|
||||
if (element)
|
||||
return MappedElement(getMappedName(element, false, sid), element);
|
||||
if (element) {
|
||||
return {getMappedName(element, false, sid), element};
|
||||
}
|
||||
|
||||
const char * mapped = isMappedElement(name);
|
||||
if (mapped)
|
||||
if (mapped) {
|
||||
name = mapped;
|
||||
}
|
||||
|
||||
MappedElement res;
|
||||
MappedElement result;
|
||||
// Strip out the trailing '.XXXX' if any
|
||||
const char *dot = strchr(name,'.');
|
||||
if(dot)
|
||||
res.name = MappedName(name, dot-name);
|
||||
else if (copy)
|
||||
res.name = name;
|
||||
else
|
||||
res.name = MappedName(name);
|
||||
res.index = getIndexedName(res.name, sid);
|
||||
return res;
|
||||
if(dot) {
|
||||
result.name = MappedName(name, dot - name);
|
||||
}
|
||||
else if (copy) {
|
||||
result.name = name;
|
||||
}
|
||||
else {
|
||||
result.name = MappedName(name);
|
||||
}
|
||||
result.index = getIndexedName(result.name, sid);
|
||||
return result;
|
||||
}
|
||||
|
||||
std::vector<std::pair<MappedName, ElementIDRefs> >
|
||||
@@ -254,44 +264,30 @@ ComplexGeoData::getElementMappedNames(const IndexedName & element, bool needUnma
|
||||
flushElementMap();
|
||||
if(_elementMap) {
|
||||
auto res = _elementMap->findAll(element);
|
||||
if (!res.empty())
|
||||
if (!res.empty()) {
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
if (!needUnmapped)
|
||||
if (!needUnmapped) {
|
||||
return {};
|
||||
}
|
||||
return {std::make_pair(MappedName(element), ElementIDRefs())};
|
||||
}
|
||||
|
||||
std::vector<Data::MappedElement>
|
||||
ComplexGeoData::getElementNamesWithPrefix(const char *prefix) const {
|
||||
#if 0
|
||||
std::vector<Data::MappedElement> names;
|
||||
flushElementMap();
|
||||
if(!prefix || !prefix[0] || !_elementMap)
|
||||
return names;
|
||||
const auto &p = elementMapPrefix();
|
||||
if(boost::starts_with(prefix,p))
|
||||
prefix += p.size();
|
||||
names = _elementMap->findAllStartsWith(prefix);
|
||||
return names;
|
||||
#else
|
||||
(void)prefix;
|
||||
return {};
|
||||
#endif
|
||||
}
|
||||
|
||||
std::vector<MappedElement> ComplexGeoData::getElementMap() const {
|
||||
flushElementMap();
|
||||
if(!_elementMap)
|
||||
if(!_elementMap) {
|
||||
return {};
|
||||
}
|
||||
return _elementMap->getAll();
|
||||
}
|
||||
|
||||
ElementMapPtr ComplexGeoData::elementMap(bool flush) const
|
||||
{
|
||||
if (flush)
|
||||
if (flush) {
|
||||
flushElementMap();
|
||||
}
|
||||
return _elementMap;
|
||||
}
|
||||
|
||||
@@ -300,82 +296,93 @@ void ComplexGeoData::flushElementMap() const
|
||||
}
|
||||
|
||||
void ComplexGeoData::setElementMap(const std::vector<MappedElement> &map) {
|
||||
resetElementMap();
|
||||
for(auto &v : map)
|
||||
_elementMap->setElementName(v.index, v.name, Tag);
|
||||
_elementMap = std::make_shared<Data::ElementMap>(); // Get rid of the old one, if any, but make
|
||||
// sure the memory exists for the new data.
|
||||
for(auto &element : map) {
|
||||
_elementMap->setElementName(element.index, element.name, Tag);
|
||||
}
|
||||
}
|
||||
|
||||
char ComplexGeoData::elementType(const Data::MappedName &name) const
|
||||
{
|
||||
if(!name)
|
||||
if(!name) {
|
||||
return 0;
|
||||
}
|
||||
auto indexedName = getIndexedName(name);
|
||||
if (indexedName)
|
||||
if (indexedName) {
|
||||
return elementType(indexedName);
|
||||
}
|
||||
char element_type=0;
|
||||
if (name.findTagInElementName(0,0,0,&element_type) < 0)
|
||||
if (name.findTagInElementName(nullptr,nullptr,nullptr,&element_type) < 0) {
|
||||
return elementType(name.toIndexedName());
|
||||
}
|
||||
return element_type;
|
||||
}
|
||||
|
||||
char ComplexGeoData::elementType(const Data::IndexedName &element) const
|
||||
{
|
||||
if(!element)
|
||||
if(!element) {
|
||||
return 0;
|
||||
}
|
||||
for(auto &type : getElementTypes()) {
|
||||
if(boost::equals(element.getType(), type))
|
||||
if(boost::equals(element.getType(), type)) {
|
||||
return type[0];
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// The elementType function can take a char *, in which case it tries a sequence of checks to
|
||||
// see what it got.
|
||||
// 1) Check to see if it is an indexedName, and if so directly look up the type
|
||||
// 2) If not:
|
||||
// a) Remove any element map prefix that is present
|
||||
// b) See if the name contains a dot:
|
||||
// i) If yes, create a MappedName from the part before the dot, and set the type to the
|
||||
// part after the dot
|
||||
// ii) If no, create a MappedName from the whole name
|
||||
// c) Try to get the elementType based on the MappedName. Return it if found
|
||||
// 3) Check to make sure the discovered type is in the list of types, and return its first
|
||||
// character if so.
|
||||
char ComplexGeoData::elementType(const char *name) const {
|
||||
if(!name)
|
||||
if(!name) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char *type = nullptr;
|
||||
IndexedName element(name, getElementTypes());
|
||||
if (element)
|
||||
if (element) {
|
||||
type = element.getType();
|
||||
}
|
||||
else {
|
||||
const char * mapped = isMappedElement(name);
|
||||
if (mapped)
|
||||
if (mapped) {
|
||||
name = mapped;
|
||||
}
|
||||
|
||||
MappedName n;
|
||||
MappedName mappedName;
|
||||
const char *dot = strchr(name,'.');
|
||||
if(dot) {
|
||||
n = MappedName(name, dot-name);
|
||||
mappedName = MappedName(name, dot-name);
|
||||
type = dot+1;
|
||||
}
|
||||
else
|
||||
n = MappedName::fromRawData(name);
|
||||
char res = elementType(n);
|
||||
if (res)
|
||||
else {
|
||||
mappedName = MappedName::fromRawData(name);
|
||||
}
|
||||
char res = elementType(mappedName);
|
||||
if (res != 0) {
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
if(type && type[0]) {
|
||||
for(auto &t : getElementTypes()) {
|
||||
if(boost::starts_with(type, t))
|
||||
for(auto &elementTypes : getElementTypes()) {
|
||||
if(boost::starts_with(type, elementTypes)) {
|
||||
return type[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
MappedName ComplexGeoData::renameDuplicateElement(int index,
|
||||
const IndexedName & element,
|
||||
const IndexedName & element2,
|
||||
const MappedName & name,
|
||||
ElementIDRefs &sids)
|
||||
{
|
||||
std::ostringstream ss;
|
||||
ss << ELEMENT_MAP_PREFIX << 'D' << std::hex << index;
|
||||
MappedName renamed(name);
|
||||
this->elementMap()->encodeElementName(element.getType()[0],renamed,ss,&sids,Tag);
|
||||
if (FC_LOG_INSTANCE.isEnabled(FC_LOGLEVEL_LOG))
|
||||
FC_WARN("duplicate element mapping '" << name << " -> " << renamed << ' '
|
||||
<< element << '/' << element2);
|
||||
return renamed;
|
||||
}
|
||||
// NOLINTEND(cppcoreguidelines-pro-bounds-pointer-arithmetic)
|
||||
|
||||
Reference in New Issue
Block a user