Skip to content

Commit

Permalink
Toponaming: Remove remaining FC_USE_TNP_FIX defines
Browse files Browse the repository at this point in the history
  • Loading branch information
bgbsww authored and chennes committed Aug 31, 2024
1 parent 4068341 commit 2a541c9
Show file tree
Hide file tree
Showing 19 changed files with 2 additions and 491 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,4 @@ macro(SetGlobalCompilerAndLinkerSettings)
endif()
endif(MINGW)

# Enable the Topological Naming Problem mitigation code
add_compile_options(-DFC_USE_TNP_FIX)

endmacro(SetGlobalCompilerAndLinkerSettings)
2 changes: 0 additions & 2 deletions src/App/ElementNamingUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,9 @@ std::string Data::noElementName(const char *name) {
}

const char *Data::findElementName(const char *subname) {
#ifdef FC_USE_TNP_FIX
// skip leading dots
while(subname && subname[0] == '.')
++subname;
#endif
if(!subname || !subname[0] || isMappedElement(subname))
return subname;
const char *dot = strrchr(subname,'.');
Expand Down
4 changes: 0 additions & 4 deletions src/Gui/SoFCUnifiedSelection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,14 +398,12 @@ void SoFCUnifiedSelection::doAction(SoAction *action)
SoDetail *detail = nullptr;
detailPath->truncate(0);
auto subName = selaction->SelChange.pSubName;
#ifdef FC_USE_TNP_FIX
App::ElementNamePair elementName;;
App::GeoFeature::resolveElement(obj, subName, elementName);
if (Data::isMappedElement(subName)
&& !elementName.oldName.empty()) { // If we have a shortened element name
subName = elementName.oldName.c_str(); // use it.
}
#endif
if(!selaction->SelChange.pSubName || !selaction->SelChange.pSubName[0] ||
vp->getDetailPath(subName,detailPath,true,detail))
{
Expand Down Expand Up @@ -625,7 +623,6 @@ bool SoFCUnifiedSelection::setSelection(const std::vector<PickedInfo> &infos, bo
std::string subName = info.element;
std::string objectName = objname;

#ifdef FC_USE_TNP_FIX
// We need to convert the short name in the selection to a full element path to look it up
// Ex: Body.Pad.Face9 to Body.Pad.;g3;SKT;:H12dc,E;FAC;:H12dc:4,F;:G0;XTR;:H12dc:8,F.Face9
App::ElementNamePair elementName;
Expand All @@ -635,7 +632,6 @@ bool SoFCUnifiedSelection::setSelection(const std::vector<PickedInfo> &infos, bo
subName.erase(subName.find(elementNameSuffix)); // Everything except original suffix suffix
subName = subName.append(elementName.newName); // Add the mapped name suffix,
}
#endif
const char *subSelected = Gui::Selection().getSelectedElement(
vpd->getObject(),subName.c_str());

Expand Down
2 changes: 0 additions & 2 deletions src/Gui/View3DInventorSelection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,12 @@ void View3DInventorSelection::checkGroupOnTop(const SelectionChanges &Reason)
std::string key(obj->getNameInDocument());
key += '.';
auto subname = Reason.pSubName;
#ifdef FC_USE_TNP_FIX
App::ElementNamePair element;
App::GeoFeature::resolveElement(obj, Reason.pSubName, element);
if (Data::isMappedElement(subname)
&& !element.oldName.empty()) { // If we have a shortened element name
subname = element.oldName.c_str(); // use if
}
#endif
if(subname)
key += subname;
if(Reason.Type == SelectionChanges::RmvSelection) {
Expand Down
73 changes: 0 additions & 73 deletions src/Mod/Part/App/Attacher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,6 @@ void AttachEngine::readLinks(const std::vector<App::DocumentObject*> &objs,
storage.reserve(objs.size());
shapes.resize(objs.size());
types.resize(objs.size());
#ifdef FC_USE_TNP_FIX
for (std::size_t i = 0; i < objs.size(); i++) {
if (!objs[i]->getTypeId().isDerivedFrom(App::GeoFeature::getClassTypeId())) {
FC_THROWM(AttachEngineException,
Expand Down Expand Up @@ -914,78 +913,6 @@ void AttachEngine::readLinks(const std::vector<App::DocumentObject*> &objs,
}
}

#else
for (std::size_t i = 0; i < objs.size(); i++) {
if (!objs[i]->isDerivedFrom<App::GeoFeature>()) {
throw AttachEngineException("AttachEngine3D: link points to something that is not App::GeoFeature");
}
App::GeoFeature* geof = static_cast<App::GeoFeature*>(objs[i]);
geofs[i] = geof;
Part::TopoShape shape;
if (geof->isDerivedFrom(Part::Feature::getClassTypeId())){
shape = (static_cast<Part::Feature*>(geof)->Shape.getShape());
if (shape.isNull()){
throw AttachEngineException("AttachEngine3D: Part has null shape");
}
if (sub[i].length()>0){
try{
shape = Part::Feature::getTopoShape(geof, sub[i].c_str(), true);
if (shape.isNull())
throw AttachEngineException("AttachEngine3D: null subshape");
storage.push_back(shape.getShape());
} catch (Standard_Failure &e){
FC_THROWM(AttachEngineException, "AttachEngine3D: subshape not found "
<< objs[i]->getNameInDocument() << '.' << sub[i]
<< std::endl << e.GetMessageString());
} catch (Base::CADKernelError &e){
FC_THROWM(AttachEngineException, "AttachEngine3D: subshape not found "
<< objs[i]->getNameInDocument() << '.' << sub[i]
<< std::endl << e.what());
}
if(storage[storage.size()-1].IsNull())
FC_THROWM(AttachEngineException, "AttachEngine3D: null subshape "
<< objs[i]->getNameInDocument() << '.' << sub[i]);
} else {
storage.push_back(shape.getShape());
}
shapes[i] = &(storage[storage.size()-1]);
} else if ( geof->isDerivedFrom(App::Plane::getClassTypeId()) ){
//obtain Z axis and origin of placement
Base::Vector3d norm;
geof->Placement.getValue().getRotation().multVec(Base::Vector3d(0.0,0.0,1.0),norm);
Base::Vector3d org;
geof->Placement.getValue().multVec(Base::Vector3d(),org);
//make shape - an local-XY plane infinite face
gp_Pln pl = gp_Pln(gp_Pnt(org.x, org.y, org.z), gp_Dir(norm.x, norm.y, norm.z));
TopoDS_Shape myShape = BRepBuilderAPI_MakeFace(pl).Shape();
myShape.Infinite(true);
storage.push_back(myShape);
shapes[i] = &(storage[storage.size()-1]);
} else if ( geof->isDerivedFrom(App::Line::getClassTypeId()) ){
//obtain X axis and origin of placement
//note an inconsistency: App::Line is along local X, PartDesign::DatumLine is along local Z.
Base::Vector3d dir;
geof->Placement.getValue().getRotation().multVec(Base::Vector3d(1.0,0.0,0.0),dir);
Base::Vector3d org;
geof->Placement.getValue().multVec(Base::Vector3d(),org);
//make shape - an infinite line along local X axis
gp_Lin l = gp_Lin(gp_Pnt(org.x, org.y, org.z), gp_Dir(dir.x, dir.y, dir.z));
TopoDS_Shape myShape = BRepBuilderAPI_MakeEdge(l).Shape();
myShape.Infinite(true);
storage.push_back(myShape);
shapes[i] = &(storage[storage.size()-1]);
} else {
Base::Console().Warning("Attacher: linked object %s is unexpected, assuming it has no shape.\n",geof->getNameInDocument());
storage.emplace_back();
shapes[i] = &(storage[storage.size()-1]);
}

//FIXME: unpack single-child compounds here? Compounds are not used so far, so it should be considered later, when the need arises.
types[i] = getShapeType(*(shapes[i]));
if (sub[i].length() == 0)
types[i] = eRefType(types[i] | rtFlagHasPlacement);
}
#endif
}

void AttachEngine::throwWrongMode(eMapMode mmode)
Expand Down
34 changes: 0 additions & 34 deletions src/Mod/Part/App/PropertyTopoShape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,25 +257,6 @@ void PropertyPartShape::beforeSave() const
_Shape.beforeSave();
}
}
#ifndef FC_USE_TNP_FIX
void PropertyPartShape::Save (Base::Writer &writer) const
{
if(!writer.isForceXML()) {
//See SaveDocFile(), RestoreDocFile()
if (writer.getMode("BinaryBrep")) {
writer.Stream() << writer.ind() << "<Part file=\""
<< writer.addFile("PartShape.bin", this)
<< "\"/>" << std::endl;
}
else {
writer.Stream() << writer.ind() << "<Part file=\""
<< writer.addFile("PartShape.brp", this)
<< "\"/>" << std::endl;
}
}
}

#else
void PropertyPartShape::Save (Base::Writer &writer) const
{
//See SaveDocFile(), RestoreDocFile()
Expand Down Expand Up @@ -328,27 +309,13 @@ void PropertyPartShape::Save (Base::Writer &writer) const
_Shape.Save(writer);
}
}
#endif

std::string PropertyPartShape::getElementMapVersion(bool restored) const {
if(restored)
return _Ver;
return PropertyComplexGeoData::getElementMapVersion(false);
}

#ifndef FC_USE_TNP_FIX
void PropertyPartShape::Restore(Base::XMLReader &reader)
{
reader.readElement("Part");
std::string file (reader.getAttribute("file") );

if (!file.empty()) {
// initiate a file read
reader.addFile(file.c_str(),this);
}
}

#else
void PropertyPartShape::Restore(Base::XMLReader &reader)
{
reader.readElement("Part");
Expand Down Expand Up @@ -450,7 +417,6 @@ void PropertyPartShape::afterRestore()
}
PropertyComplexGeoData::afterRestore();
}
#endif

// The following function is copied from OCCT BRepTools.cxx and modified
// to disable saving of triangulation
Expand Down
28 changes: 0 additions & 28 deletions src/Mod/Part/App/PropertyTopoShapeList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,6 @@ void PropertyTopoShapeList::setPyObject(PyObject *value)
}
}

#ifdef FC_USE_TNP_FIX

void PropertyTopoShapeList::Save(Writer& writer) const
{
writer.Stream() << writer.ind() << "<ShapeList count=\"" << getSize() << "\">" << endl;
Expand Down Expand Up @@ -251,32 +249,6 @@ void PropertyTopoShapeList::RestoreDocFile(Base::Reader& reader)
}
}

#else
void PropertyTopoShapeList::Save(Writer &writer) const
{
writer.Stream() << writer.ind() << "<ShapeList count=\"" << getSize() <<"\">" << endl;
writer.incInd();
for (int i = 0; i < getSize(); i++) {
_lValueList[i].Save(writer);
}
writer.decInd();
writer.Stream() << writer.ind() << "</ShapeList>" << endl ;
}

void PropertyTopoShapeList::Restore(Base::XMLReader &reader)
{
reader.readElement("ShapeList");
int count = reader.getAttributeAsInteger("count");
m_restorePointers.clear(); // just in case
m_restorePointers.reserve(count);
for (int i = 0; i < count; i++) {
auto newShape = std::make_shared<TopoShape>();
newShape->Restore(reader);
m_restorePointers.push_back(newShape);
}
reader.readEndElement("ShapeList");
}
#endif
App::Property *PropertyTopoShapeList::Copy() const
{
PropertyTopoShapeList *p = new PropertyTopoShapeList();
Expand Down
56 changes: 1 addition & 55 deletions src/Mod/Part/App/TopoShape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1199,7 +1199,7 @@ bool TopoShape::getCenterOfGravity(Base::Vector3d& center) const

return false;
}
#ifdef FC_USE_TNP_FIX

void TopoShape::Save (Base::Writer &writer ) const
{
Data::ComplexGeoData::Save(writer);
Expand All @@ -1221,60 +1221,6 @@ void TopoShape::RestoreDocFile(Base::Reader &reader)
}


#else
void TopoShape::Save (Base::Writer& writer) const
{
if(!writer.isForceXML()) {
//See SaveDocFile(), RestoreDocFile()
// add a filename to the writer's list. Each file on the list is eventually
// processed by SaveDocFile().
if (writer.getMode("BinaryBrep")) {
writer.Stream() << writer.ind() << "<TopoShape file=\""
<< writer.addFile("TopoShape.bin", this)
<< "\"/>" << std::endl;
}
else {
writer.Stream() << writer.ind() << "<TopoShape file=\""
<< writer.addFile("TopoShape.brp", this)
<< "\"/>" << std::endl;
}
}}

void TopoShape::Restore(Base::XMLReader& reader)
{
reader.readElement("TopoShape");
std::string file (reader.getAttribute("file") );

if (!file.empty()) {
// add a filename to the writer's list. Each file on the list is eventually
// processed by RestoreDocFile().
reader.addFile(file.c_str(),this);
}
}

void TopoShape::SaveDocFile (Base::Writer& writer) const
{
if (getShape().IsNull()) {
return;
}
//the writer has already opened a stream with the appropriate filename
if (writer.getMode("BinaryBrep")) {
exportBinary(writer.Stream());
} else {
exportBrep(writer.Stream());
}
}

void TopoShape::RestoreDocFile(Base::Reader& reader)
{
Base::FileInfo brep(reader.getFileName());
if (brep.hasExtension("bin")) {
importBinary(reader);
} else {
importBrep(reader);
}
}
#endif
unsigned int TopoShape_RefCountShapes(const TopoDS_Shape& aShape)
{
unsigned int size = 1; // this shape
Expand Down
39 changes: 0 additions & 39 deletions src/Mod/Part/App/TopoShapeExpansion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -792,41 +792,6 @@ void TopoShape::copyElementMap(const TopoShape& topoShape, const char* op)
setMappedChildElements(children);
}

#ifndef FC_USE_TNP_FIX
namespace
{
void warnIfLogging()
{
if (FC_LOG_INSTANCE.isEnabled(FC_LOGLEVEL_LOG)) {
FC_WARN("hasher mismatch"); // NOLINT
}
}

void hasherMismatchError()
{
FC_ERR("hasher mismatch"); // NOLINT
}


void checkAndMatchHasher(TopoShape& topoShape1, const TopoShape& topoShape2)
{
if (topoShape1.Hasher) {
if (topoShape2.Hasher != topoShape1.Hasher) {
if (topoShape1.getElementMapSize(false) == 0U) {
warnIfLogging();
}
else {
hasherMismatchError();
}
topoShape1.Hasher = topoShape2.Hasher;
}
}
else {
topoShape1.Hasher = topoShape2.Hasher;
}
}
} // namespace
#endif

// TODO: Refactor mapSubElementTypeForShape to reduce complexity
void TopoShape::mapSubElementTypeForShape(const TopoShape& other,
Expand Down Expand Up @@ -2045,11 +2010,7 @@ TopoShape TopoShape::getSubTopoShape(const char* Type, bool silent) const
}
return TopoShape();
}
#ifdef FC_USE_TNP_FIX
auto res = shapeTypeAndIndex(mapped.index);
#else
auto res = shapeTypeAndIndex(Type);
#endif
if (res.second <= 0) {
if (!silent) {
FC_THROWM(Base::ValueError, "Invalid shape name " << (Type ? Type : ""));
Expand Down
Loading

0 comments on commit 2a541c9

Please sign in to comment.