Skip to content

Commit

Permalink
Merge pull request FreeCAD#15508 from bgbsww/bgbsww-toponamingSaveRes…
Browse files Browse the repository at this point in the history
…tore7

Toponaming: bring in getHigherElements code
  • Loading branch information
chennes authored Jul 25, 2024
2 parents 8764cd1 + d92029f commit e4e17cf
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/App/GeoFeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions src/App/GeoFeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ class AppExport GeoFeature : public App::DocumentObject

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;
Expand Down
3 changes: 3 additions & 0 deletions src/Mod/Part/App/TopoShape.h
Original file line number Diff line number Diff line change
Expand Up @@ -1496,6 +1496,9 @@ class PartExport TopoShape: public Data::ComplexGeoData
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
Expand Down
21 changes: 20 additions & 1 deletion src/Mod/Part/App/TopoShapeExpansion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -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,
Expand Down
58 changes: 58 additions & 0 deletions src/Mod/Sketcher/App/SketchObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
5 changes: 5 additions & 0 deletions src/Mod/Sketcher/App/SketchObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,11 @@ class SketcherExport SketchObject: public Part::Part2DObject

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;
Expand Down

0 comments on commit e4e17cf

Please sign in to comment.