Skip to content

Commit

Permalink
Merge pull request FreeCAD#13773 from bgbsww/bgbsww-toponamingMissing…
Browse files Browse the repository at this point in the history
…AppMethods

Toponaming: Add toponaming missing methods in app
  • Loading branch information
chennes authored May 3, 2024
2 parents ede6c81 + 2bff3f5 commit a75350b
Show file tree
Hide file tree
Showing 7 changed files with 602 additions and 197 deletions.
5 changes: 5 additions & 0 deletions src/App/ComplexGeoData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,11 @@ unsigned int ComplexGeoData::getMemSize() const
return 0;
}

std::vector<IndexedName> ComplexGeoData::getHigherElements(const char *, bool) const
{
return {};
}

void ComplexGeoData::setMappedChildElements(const std::vector<Data::ElementMap::MappedChildElements> & children)
{
// DO NOT reset element map if there is one. Because we allow mixing child
Expand Down
3 changes: 3 additions & 0 deletions src/App/ComplexGeoData.h
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,9 @@ class AppExport ComplexGeoData: public Base::Persistence, public Base::Handled
/// Get the current element map size
size_t getElementMapSize(bool flush=true) const;

/// Return the higher level element names of the given element
virtual std::vector<IndexedName> getHigherElements(const char *name, bool silent=false) const;

/// Return the current element map version
virtual std::string getElementMapVersion() const;

Expand Down
55 changes: 54 additions & 1 deletion src/App/GeoFeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <App/GeoFeaturePy.h>

#include "ComplexGeoData.h"
#include "Document.h"
#include "GeoFeature.h"
#include "GeoFeatureGroupExtension.h"
#include "ElementNamingUtils.h"
Expand Down Expand Up @@ -146,12 +147,22 @@ DocumentObject *GeoFeature::resolveElement(DocumentObject *obj, const char *subn
subname = "";
const char *element = Data::findElementName(subname);
if(_element) *_element = element;
#ifdef FC_USE_TNP_FIX
elementName.first.clear();
elementName.second.clear();
auto sobj = obj->getSubObject(std::string(subname, element).c_str());
if(!sobj)
return nullptr;
auto linked = sobj->getLinkedObject(true);
auto geo = Base::freecad_dynamic_cast<GeoFeature>(linked);
#else
auto sobj = obj->getSubObject(subname);
if(!sobj)
return nullptr;
obj = sobj->getLinkedObject(true);
auto geo = dynamic_cast<GeoFeature*>(obj);
if(geoFeature)
#endif
if(geoFeature)
*geoFeature = geo;
if(!obj || (filter && obj!=filter))
return nullptr;
Expand Down Expand Up @@ -189,3 +200,45 @@ void GeoFeature::setMaterialAppearance(const App::Material& material)
{
Q_UNUSED(material)
}

#ifdef FC_USE_TNP_FIX
bool GeoFeature::hasMissingElement(const char *subname) {
return Data::hasMissingElement(subname);
if(!subname)
return false;
auto dot = strrchr(subname,'.');
if(!dot)
return subname[0]=='?';
return dot[1]=='?';
}

void GeoFeature::updateElementReference() {
auto prop = getPropertyOfGeometry();
if(!prop) return;
auto geo = prop->getComplexData();
if(!geo) return;
bool reset = false;
PropertyLinkBase::updateElementReferences(this,reset);
}

void GeoFeature::onChanged(const Property *prop) {
if(prop==getPropertyOfGeometry()) {
if(getDocument() && !getDocument()->testStatus(Document::Restoring)
&& !getDocument()->isPerformingTransaction())
{
updateElementReference();
}
}
DocumentObject::onChanged(prop);
}


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
14 changes: 14 additions & 0 deletions src/App/GeoFeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,21 @@ class AppExport GeoFeature : public App::DocumentObject
* appearance from an App::Material object.
*/
virtual void setMaterialAppearance(const App::Material& material);
#ifdef FC_USE_TNP_FIX
static bool hasMissingElement(const char *subname);

/// Return the object that owns the shape that contains the give element name
virtual DocumentObject *getElementOwner(const Data::MappedName & /*name*/) const
{return nullptr;}

/// 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;
// void onDocumentRestored() override;
void updateElementReference();
#endif
protected:
std::pair<std::string, std::string> _getElementName(const char* name,
const Data::MappedElement& mapped) const;
Expand Down
Loading

0 comments on commit a75350b

Please sign in to comment.