Merge pull request #15508 from bgbsww/bgbsww-toponamingSaveRestore7
Toponaming: bring in getHigherElements code
This commit is contained in:
@@ -279,4 +279,13 @@ std::vector<const char*> GeoFeature::getElementTypes(bool /*all*/) const
|
||||
return prop->getComplexData()->getElementTypes();
|
||||
}
|
||||
|
||||
std::vector<Data::IndexedName>
|
||||
GeoFeature::getHigherElements(const char *element, bool silent) const
|
||||
{
|
||||
auto prop = getPropertyOfGeometry();
|
||||
if (!prop)
|
||||
return {};
|
||||
return prop->getComplexData()->getHigherElements(element, silent);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -177,6 +177,8 @@ public:
|
||||
|
||||
virtual std::vector<const char *> getElementTypes(bool all=true) const;
|
||||
|
||||
/// Return the higher level element names of the given element
|
||||
virtual std::vector<Data::IndexedName> getHigherElements(const char *name, bool silent=false) const;
|
||||
|
||||
protected:
|
||||
void onChanged(const Property* prop) override;
|
||||
|
||||
@@ -1496,6 +1496,9 @@ public:
|
||||
Data::ElementMapPtr resetElementMap(
|
||||
Data::ElementMapPtr elementMap=Data::ElementMapPtr()) override;
|
||||
|
||||
std::vector<Data::IndexedName> getHigherElements(const char *element,
|
||||
bool silent = false) const override;
|
||||
|
||||
/** Helper class to return the generated and modified shape given an input shape
|
||||
*
|
||||
* Shape history information is extracted using OCCT APIs
|
||||
|
||||
@@ -3714,7 +3714,7 @@ struct MapperPrism: MapperMaker
|
||||
}
|
||||
}
|
||||
}
|
||||
virtual const std::vector<TopoDS_Shape>& generated(const TopoDS_Shape& s) const override
|
||||
const std::vector<TopoDS_Shape>& generated(const TopoDS_Shape& s) const override
|
||||
{
|
||||
_res.clear();
|
||||
switch (s.ShapeType()) {
|
||||
@@ -4775,6 +4775,25 @@ TopoShape& TopoShape::makeElementRefine(const TopoShape& shape, const char* op,
|
||||
return *this;
|
||||
}
|
||||
|
||||
std::vector<Data::IndexedName>
|
||||
TopoShape::getHigherElements(const char *element, bool silent) const
|
||||
{
|
||||
TopoShape shape = getSubTopoShape(element, silent);
|
||||
if(shape.isNull())
|
||||
return {};
|
||||
|
||||
std::vector<Data::IndexedName> res;
|
||||
int type = shape.shapeType();
|
||||
for(;;) {
|
||||
if(--type < 0)
|
||||
break;
|
||||
const char *shapetype = shapeName((TopAbs_ShapeEnum)type).c_str();
|
||||
for(int idx : findAncestors(shape.getShape(), (TopAbs_ShapeEnum)type))
|
||||
res.emplace_back(shapetype, idx);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
TopoShape& TopoShape::makeElementBSplineFace(const TopoShape& shape,
|
||||
FillingStyle style,
|
||||
bool keepBezier,
|
||||
|
||||
@@ -9695,6 +9695,64 @@ App::DocumentObject *SketchObject::getSubObject(
|
||||
return const_cast<SketchObject*>(this);
|
||||
}
|
||||
|
||||
std::vector<Data::IndexedName>
|
||||
SketchObject::getHigherElements(const char *element, bool silent) const
|
||||
{
|
||||
std::vector<Data::IndexedName> res;
|
||||
if (boost::istarts_with(element, "vertex")) {
|
||||
int n = 0;
|
||||
int index = atoi(element+6);
|
||||
for (auto cstr : Constraints.getValues()) {
|
||||
++n;
|
||||
if (cstr->Type != Sketcher::Coincident)
|
||||
continue;
|
||||
if(cstr->First >= 0 && index == getSolvedSketch().getPointId(cstr->First, cstr->FirstPos) + 1)
|
||||
res.push_back(Data::IndexedName::fromConst("Constraint", n));
|
||||
if(cstr->Second >= 0 && index == getSolvedSketch().getPointId(cstr->Second, cstr->SecondPos) + 1)
|
||||
res.push_back(Data::IndexedName::fromConst("Constraint", n));
|
||||
}
|
||||
}
|
||||
return res;
|
||||
|
||||
auto getNames = [this, &silent, &res](const char *element) {
|
||||
bool internal = boost::starts_with(element, internalPrefix());
|
||||
const auto &shape = internal ? InternalShape.getShape() : Shape.getShape();
|
||||
for (const auto &indexedName : shape.getHigherElements(element+(internal?internalPrefix().size() : 0), silent)) {
|
||||
if (!internal) {
|
||||
res.push_back(indexedName);
|
||||
}
|
||||
else if (boost::equals(indexedName.getType(), "Face")
|
||||
|| boost::equals(indexedName.getType(), "Edge")
|
||||
|| boost::equals(indexedName.getType(), "Wire")) {
|
||||
res.emplace_back((internalPrefix() + indexedName.getType()).c_str(), indexedName.getIndex());
|
||||
}
|
||||
}
|
||||
};
|
||||
getNames(element);
|
||||
const auto &elementMap = getInternalElementMap();
|
||||
auto it = elementMap.find(element);
|
||||
if (it != elementMap.end()) {
|
||||
res.emplace_back(it->second.c_str());
|
||||
getNames(it->second.c_str());
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
std::vector<const char *> SketchObject::getElementTypes(bool all) const
|
||||
{
|
||||
if (!all)
|
||||
return Part::Part2DObject::getElementTypes();
|
||||
static std::vector<const char *> res { Part::TopoShape::shapeName(TopAbs_VERTEX).c_str(),
|
||||
Part::TopoShape::shapeName(TopAbs_EDGE).c_str(),
|
||||
"ExternalEdge",
|
||||
"Constraint",
|
||||
"InternalEdge",
|
||||
"InternalFace",
|
||||
"InternalVertex",
|
||||
};
|
||||
return res;
|
||||
}
|
||||
|
||||
void SketchObject::setExpression(const App::ObjectIdentifier& path,
|
||||
std::shared_ptr<App::Expression> expr)
|
||||
{
|
||||
|
||||
@@ -684,6 +684,11 @@ public:
|
||||
|
||||
Part::TopoShape getEdge(const Part::Geometry* geo, const char* name) const;
|
||||
|
||||
std::vector<const char*> getElementTypes(bool all = true) const override;
|
||||
|
||||
std::vector<Data::IndexedName> getHigherElements(const char* element,
|
||||
bool silent = false) const override;
|
||||
|
||||
Data::IndexedName checkSubName(const char* subname) const;
|
||||
|
||||
bool geoIdFromShapeType(const Data::IndexedName&, int& geoId, PointPos& posId) const;
|
||||
|
||||
Reference in New Issue
Block a user