Toposhape/Part:: Fix, relocate and test element methods in ComplexGeoData and TopoShape
This commit is contained in:
@@ -28,6 +28,7 @@
|
||||
# include <unordered_set>
|
||||
#endif
|
||||
|
||||
#include "DocumentObject.h"
|
||||
#include "MappedElement.h"
|
||||
|
||||
using namespace Data;
|
||||
@@ -161,4 +162,11 @@ bool ElementNameComparator::operator()(const MappedName& leftName,
|
||||
}
|
||||
}
|
||||
return leftName.size() < rightName.size();
|
||||
}
|
||||
}
|
||||
|
||||
HistoryItem::HistoryItem(App::DocumentObject *obj, const Data::MappedName &name)
|
||||
:obj(obj),tag(0),element(name)
|
||||
{
|
||||
if(obj)
|
||||
tag = obj->getID();
|
||||
}
|
||||
|
||||
@@ -99,6 +99,15 @@ struct AppExport MappedElement
|
||||
}
|
||||
};
|
||||
|
||||
struct AppExport HistoryItem {
|
||||
App::DocumentObject *obj;
|
||||
long tag;
|
||||
Data::MappedName element;
|
||||
Data::IndexedName index;
|
||||
std::vector<Data::MappedName> intermediates;
|
||||
HistoryItem(App::DocumentObject *obj, const Data::MappedName &name);
|
||||
};
|
||||
|
||||
struct AppExport ElementNameComparator {
|
||||
/** Comparison function to make topo name more stable
|
||||
*
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -76,7 +76,10 @@ public:
|
||||
const char *name, bool recursive=true, bool sameType=false);
|
||||
|
||||
static QVector<Data::MappedElement>
|
||||
getRelatedElements(App::DocumentObject *obj, const char *name, bool sameType=true, bool withCache=true);
|
||||
getRelatedElements(App::DocumentObject* obj,
|
||||
const char* name,
|
||||
HistoryTraceType sameType = HistoryTraceType::followTypeChange,
|
||||
bool withCache = true);
|
||||
|
||||
/** Obtain the element name from a feature based of the element name of its source feature
|
||||
*
|
||||
@@ -143,6 +146,8 @@ public:
|
||||
static Feature*
|
||||
create(const TopoShape& shape, const char* name = nullptr, App::Document* document = nullptr);
|
||||
|
||||
static bool isElementMappingDisabled(App::PropertyContainer *container);
|
||||
|
||||
protected:
|
||||
/// recompute only this object
|
||||
App::DocumentObjectExecReturn *recompute() override;
|
||||
|
||||
@@ -50,6 +50,7 @@
|
||||
#include "PartPyCXX.h"
|
||||
#include "PropertyTopoShape.h"
|
||||
#include "TopoShapePy.h"
|
||||
#include "PartFeature.h"
|
||||
|
||||
FC_LOG_LEVEL_INIT("App", true, true)
|
||||
|
||||
@@ -103,14 +104,15 @@ TopoShape PropertyPartShape::getShape() const
|
||||
{
|
||||
_Shape.initCache(-1);
|
||||
auto res = _Shape;
|
||||
// March, 2024 Toponaming project: There was originally an unused feature to disable elementMapping
|
||||
// that has not been kept:
|
||||
// March, 2024 Toponaming project: There was originally an unused feature to disable
|
||||
// elementMapping that has not been kept:
|
||||
// if (Feature::isElementMappingDisabled(getContainer()))
|
||||
if ( false )
|
||||
res.Tag = -1;
|
||||
else if (!res.Tag) {
|
||||
if (auto parent = Base::freecad_dynamic_cast<App::DocumentObject>(getContainer()))
|
||||
// res.Tag = -1;
|
||||
// else if (!res.Tag) {
|
||||
if (!res.Tag) {
|
||||
if (auto parent = Base::freecad_dynamic_cast<App::DocumentObject>(getContainer())) {
|
||||
res.Tag = parent->getID();
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -107,6 +107,7 @@ using namespace Part;
|
||||
#define M_PI_2 1.57079632679489661923 /* pi/2 */
|
||||
#endif
|
||||
|
||||
#ifdef FC_USE_TNP_FIX
|
||||
static Py_hash_t _TopoShapeHash(PyObject *self) {
|
||||
if (!self) {
|
||||
PyErr_SetString(PyExc_TypeError, "descriptor 'hash' of 'Part.TopoShape' object needs an argument");
|
||||
@@ -124,6 +125,7 @@ struct TopoShapePyInit {
|
||||
TopoShapePy::Type.tp_hash = _TopoShapeHash;
|
||||
}
|
||||
} _TopoShapePyInit;
|
||||
#endif
|
||||
|
||||
// returns a string which represents the object e.g. when printed in python
|
||||
std::string TopoShapePy::representation() const
|
||||
|
||||
@@ -218,6 +218,6 @@ TEST_F(FeaturePartCommonTest, testMapping)
|
||||
#ifndef FC_USE_TNP_FIX
|
||||
EXPECT_EQ(ts1.getElementMap().size(), 0);
|
||||
#else
|
||||
EXPECT_EQ(ts1.getElementMap().size(), 26); // TODO: This should be 26.
|
||||
EXPECT_EQ(ts1.getElementMap().size(), 26);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <src/App/InitApplication.h>
|
||||
#include <BRepBuilderAPI_MakeVertex.hxx>
|
||||
#include "PartTestHelpers.h"
|
||||
#include "App/MappedElement.h"
|
||||
|
||||
using namespace Part;
|
||||
using namespace PartTestHelpers;
|
||||
@@ -54,7 +55,7 @@ TEST_F(FeaturePartTest, testGetElementName)
|
||||
#ifndef FC_USE_TNP_FIX
|
||||
EXPECT_EQ(ts.getElementMap().size(), 0);
|
||||
#else
|
||||
EXPECT_EQ(ts.getElementMap().size(), 0); // TODO: Value and code TBD
|
||||
EXPECT_EQ(ts.getElementMap().size(), 26);
|
||||
#endif
|
||||
// TBD
|
||||
}
|
||||
@@ -127,3 +128,88 @@ TEST_F(FeaturePartTest, create)
|
||||
// will have only 1 feature
|
||||
EXPECT_EQ(otherDoc->getObjects().size(), 1);
|
||||
}
|
||||
|
||||
TEST_F(FeaturePartTest, getElementHistory)
|
||||
{
|
||||
// Arrange
|
||||
const char* name = "Part__Box";
|
||||
const char* name2 = "Edge2"; // Edge, Vertex, or Face. will work here.
|
||||
// Act
|
||||
auto result = Feature::getElementHistory(_boxes[0], name2, true, false);
|
||||
Data::HistoryItem histItem = result.front();
|
||||
// Assert
|
||||
EXPECT_EQ(result.size(), 1);
|
||||
EXPECT_NE(histItem.tag, 0); // Make sure we have one. It will vary.
|
||||
EXPECT_EQ(histItem.index.getIndex(), 2);
|
||||
EXPECT_STREQ(histItem.index.getType(), "Edge");
|
||||
EXPECT_STREQ(histItem.element.toString().c_str(), name2);
|
||||
EXPECT_EQ(histItem.obj, _boxes[0]);
|
||||
}
|
||||
|
||||
TEST_F(FeaturePartTest, getRelatedElements)
|
||||
{
|
||||
// Arrange
|
||||
_common->Base.setValue(_boxes[0]);
|
||||
_common->Tool.setValue(_boxes[1]);
|
||||
// Act
|
||||
_common->execute();
|
||||
auto label1 = _common->Label.getValue();
|
||||
auto label2 = _boxes[1]->Label.getValue();
|
||||
const TopoShape& ts = _common->Shape.getShape();
|
||||
auto result = Feature::getRelatedElements(_doc->getObject(label1),
|
||||
"Edge2",
|
||||
HistoryTraceType::followTypeChange,
|
||||
true);
|
||||
auto result2 = Feature::getRelatedElements(_doc->getObject(label2),
|
||||
"Edge1",
|
||||
HistoryTraceType::followTypeChange,
|
||||
true);
|
||||
// Assert
|
||||
#ifdef FC_USE_TNP_FIX
|
||||
EXPECT_EQ(result.size(), 1); // Found the one.
|
||||
EXPECT_EQ(result2.size(), 0); // No element map, so no related elements
|
||||
// The results are always going to vary, so we can't test for specific values:
|
||||
// EXPECT_STREQ(result.front().name.toString().c_str(),"Edge3;:M;CMN;:H38d:7,E");
|
||||
#else
|
||||
EXPECT_EQ(result.size(), 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
// Note that this test is pretty trivial and useless .. but the method in question is never
|
||||
// called in the codebase.
|
||||
TEST_F(FeaturePartTest, getElementFromSource)
|
||||
{
|
||||
// Arrange
|
||||
_common->Base.setValue(_boxes[0]);
|
||||
_common->Tool.setValue(_boxes[1]);
|
||||
App::DocumentObject sourceObject;
|
||||
// const char *sourceSubElement;
|
||||
// Act
|
||||
_common->execute();
|
||||
auto label1 = _common->Label.getValue();
|
||||
auto label2 = _boxes[1]->Label.getValue();
|
||||
const TopoShape& ts = _common->Shape.getShape();
|
||||
auto element = Feature::getElementFromSource(_common,
|
||||
"Part__Box001", // "Edge1",
|
||||
_boxes[0],
|
||||
"Face1", // "Edge1",
|
||||
false);
|
||||
// Assert
|
||||
EXPECT_EQ(element.size(), 0);
|
||||
}
|
||||
|
||||
TEST_F(FeaturePartTest, getSubObject)
|
||||
{
|
||||
// Arrange
|
||||
_common->Base.setValue(_boxes[0]);
|
||||
_common->Tool.setValue(_boxes[1]);
|
||||
App::DocumentObject sourceObject;
|
||||
const char* sourceSubElement;
|
||||
PyObject* pyObj;
|
||||
// Act
|
||||
_common->execute();
|
||||
auto result = _boxes[1]->getSubObject("Face5", &pyObj, nullptr, false, 10);
|
||||
// Assert
|
||||
ASSERT_NE(result, nullptr);
|
||||
EXPECT_STREQ(result->getNameInDocument(), "Part__Box001");
|
||||
}
|
||||
|
||||
@@ -2028,17 +2028,16 @@ TEST_F(TopoShapeExpansionTest, makeElementSlice)
|
||||
{
|
||||
"Face1;SLC;:H1:4,F;:G2;SLC;:H1:8,V;SLC;:H1:4,V;MAK;:H1:4,V",
|
||||
"Face1;SLC;:H1:4,F;:G3;SLC;:H1:8,V;SLC;:H1:4,V;MAK;:H1:4,V",
|
||||
// TODO: Prove that this difference is not a problem.
|
||||
// The next element varies according to platform / OCCT version and thus can't be
|
||||
// absolutely tested.
|
||||
// "Face1;SLC;:H1:4,F;:G4;SLC;:H1:8,V;D1;:H1:3,V;SLC;:H1:4,V;MAK;:H1:4,V",
|
||||
// MacOSX difference:
|
||||
// "Face1;SLC;:H1:4,F;:G4;SLC;:H1:8,V;D25fd;:H1:6,V;SLC;:H1:4,V;MAK;:H1:4,V",
|
||||
// "Face1;SLC;:H1:4,F;:G4;SLC;:H1:8,V;D1;:H1:3,V;SLC;:H1:4,V;MAK;:H1:4,V",
|
||||
"Face1;SLC;:H1:4,F;:G4;SLC;:H1:8,V;SLC;:H1:4,V;MAK;:H1:4,V",
|
||||
"Face1;SLC;:H1:4,F;:G5;SLC;:H1:8,E;SLC;:H1:4,E;MAK;:H1:4,E",
|
||||
"Face1;SLC;:H1:4,F;:G6;SLC;:H1:8,E;SLC;:H1:4,E;MAK;:H1:4,E",
|
||||
"Face1;SLC;:H1:4,F;:G7;SLC;:H1:8,E;SLC;:H1:4,E;MAK;:H1:4,E",
|
||||
"Face1;SLC;:H1:4,F;:G8;SLC;:H1:8,E;SLC;:H1:4,E;MAK;:H1:4,E",
|
||||
})); // Changed with PR#12471. Probably will change again after importing
|
||||
// other TopoNaming logics
|
||||
})); // Changed with PR#12471. Probably will change again after
|
||||
// importing other TopoNaming logics
|
||||
}
|
||||
|
||||
TEST_F(TopoShapeExpansionTest, makeElementSlices)
|
||||
|
||||
Reference in New Issue
Block a user