|
|
|
|
@@ -135,6 +135,12 @@ TEST_F(DocumentObserverTest, normalize)
|
|
|
|
|
auto box {_doc->addObject("Part::Box")};
|
|
|
|
|
// The name of the Part::Box added to the document
|
|
|
|
|
auto boxName {box->getNameInDocument()};
|
|
|
|
|
// Changing the label of the Part::Box to test the differences between calling
|
|
|
|
|
// SubObjectT::normalized() with the options argument set to
|
|
|
|
|
// SubObjectT::NormalizeOption::KeepSubName or set to other values
|
|
|
|
|
box->Label.setValue("Cube");
|
|
|
|
|
// The label of the Part::Box added to the document
|
|
|
|
|
auto boxLabel {box->Label.getValue()};
|
|
|
|
|
// The name of a Part::Cylinder added to the document
|
|
|
|
|
auto cylName {_doc->addObject("Part::Cylinder")->getNameInDocument()};
|
|
|
|
|
// An App::Part added to the document
|
|
|
|
|
@@ -148,7 +154,7 @@ TEST_F(DocumentObserverTest, normalize)
|
|
|
|
|
// The name of the object used as argument for various calls of the constructors of
|
|
|
|
|
// App::SubObjectT objects
|
|
|
|
|
auto subName {std::string()};
|
|
|
|
|
// An helper string used to compose the argument of some calls of
|
|
|
|
|
// A helper string used to compose the argument of some calls of
|
|
|
|
|
// Base::Interpreter().runString()
|
|
|
|
|
auto cmd {std::string()};
|
|
|
|
|
|
|
|
|
|
@@ -210,10 +216,21 @@ TEST_F(DocumentObserverTest, normalize)
|
|
|
|
|
auto subObjTNoFlatten {SubObjectT(lGrp, subName.c_str())};
|
|
|
|
|
// An App::SubObjectT object used to test SubObjectT::normalize() with the option argument set
|
|
|
|
|
// to SubObjectT::NormalizeOption::KeepSubName
|
|
|
|
|
auto subObjTKeepSubName {SubObjectT(lGrp, subName.replace(0, strlen(partName), "0").c_str())};
|
|
|
|
|
// The subName is modified replacing "Part__Box" with "$Cube" to test the effect of using
|
|
|
|
|
// SubObjectT::NormalizeOption::KeepSubName, that is leaving the "$Cube" instead of replacing it
|
|
|
|
|
// with the name of the DocumentObject with that label ("Part__Box")
|
|
|
|
|
auto subObjTKeepSubName {SubObjectT(lGrp,
|
|
|
|
|
subName
|
|
|
|
|
.replace(strlen(partName) + strlen(fuseName) + 2,
|
|
|
|
|
strlen(boxName),
|
|
|
|
|
std::string("$").append(boxLabel).c_str())
|
|
|
|
|
.c_str())};
|
|
|
|
|
// An App::SubObjectT object used to test SubObjectT::normalize() with the option argument set
|
|
|
|
|
// to SubObjectT::NormalizeOption::ConvertIndex
|
|
|
|
|
auto subObjTConvertIndex {SubObjectT(lGrp, subName.c_str())};
|
|
|
|
|
// The subName is modified replacing "App_Part" with "0" to test the effect of using
|
|
|
|
|
// SubObjectT::NormalizeOption::ConvertIndex, that is replacing the "0" with the name of the
|
|
|
|
|
// DocumentObject at position 0 of lGrp
|
|
|
|
|
auto subObjTConvertIndex {SubObjectT(lGrp, subName.replace(0, strlen(partName), "0").c_str())};
|
|
|
|
|
|
|
|
|
|
// A bool variable used to store the result of subObjTEmpty.normalize()
|
|
|
|
|
auto normalizeEmpty {false};
|
|
|
|
|
@@ -251,25 +268,42 @@ TEST_F(DocumentObserverTest, normalize)
|
|
|
|
|
// hasn't any sub objects
|
|
|
|
|
EXPECT_FALSE(normalizeWithoutSubObj);
|
|
|
|
|
|
|
|
|
|
// In this case calling SubObjectT::normalize() changes subObjTWithSubObj subname removing the
|
|
|
|
|
// "Fusion." part of the of the original subname
|
|
|
|
|
// In this case calling SubObjectT::normalize() changes subObjTWithSubObj subname in this way:
|
|
|
|
|
// The "Fusion." part of the of the original subname is removed because the
|
|
|
|
|
// SubObjectT::NormalizeOption::NoFlatten flag isn't set;
|
|
|
|
|
// The "Edge1" part of the of the original subname is kept because the
|
|
|
|
|
// SubObjectT::NormalizeOption::NoElement flag isn't set;
|
|
|
|
|
EXPECT_TRUE(normalizeWithSubObj);
|
|
|
|
|
|
|
|
|
|
// In this case calling SubObjectT::normalize() changes subObjTWithoutEl subname removing the
|
|
|
|
|
// "Fusion." and "Edge1" parts of the of the original subname
|
|
|
|
|
// In this case calling SubObjectT::normalize() changes subObjTWithoutEl subname in this way:
|
|
|
|
|
// The "Fusion." part of the of the original subname is removed because the
|
|
|
|
|
// SubObjectT::NormalizeOption::NoFlatten flag isn't set;
|
|
|
|
|
// The "Edge1" part of the of the original subname is removed because the
|
|
|
|
|
// SubObjectT::NormalizeOption::NoElement flag is set;
|
|
|
|
|
EXPECT_TRUE(normalizeWithoutEl);
|
|
|
|
|
|
|
|
|
|
// In this case calling SubObjectT::normalize() doesn't have effect as neither the
|
|
|
|
|
// DocumentObject referenced nor the subname of subObjTNoFlatten are changed
|
|
|
|
|
EXPECT_FALSE(normalizeNoFlatten);
|
|
|
|
|
|
|
|
|
|
// In this case calling SubObjectT::normalize() changes subObjTKeepSubName subname removing the
|
|
|
|
|
// "Fusion." part of the of the original subname
|
|
|
|
|
// In this case calling SubObjectT::normalize() changes subObjTKeepSubName subname in this way:
|
|
|
|
|
// The "Fusion." part of the of the original subname is removed because the
|
|
|
|
|
// SubObjectT::NormalizeOption::NoFlatten flag isn't set;
|
|
|
|
|
// The "$Cube." part of the of the original subname is kept because the
|
|
|
|
|
// SubObjectT::NormalizeOption::KeepSubName flag is set;
|
|
|
|
|
// The "Edge1" part of the of the original subname is kept because the
|
|
|
|
|
// SubObjectT::NormalizeOption::NoElement flag isn't set;
|
|
|
|
|
EXPECT_TRUE(normalizeKeepSubName);
|
|
|
|
|
|
|
|
|
|
// In this case calling SubObjectT::normalize() changes subObjTConvertIndex subname replacing
|
|
|
|
|
// the "0" part of the of the original subname with "App__Part" as lGrp object at position 0 is
|
|
|
|
|
// the DocumentObject with name "App__Part" and removing the "Fusion" part
|
|
|
|
|
// In this case calling SubObjectT::normalize() changes subObjTConvertIndex subname in this way:
|
|
|
|
|
// The "0." part of the of the original subname is replaced with "App__Part" because the
|
|
|
|
|
// SubObjectT::NormalizeOption::ConvertIndex flag is set;
|
|
|
|
|
// The "Fusion." part of the of the original subname is removed because the
|
|
|
|
|
// SubObjectT::NormalizeOption::NoFlatten flag isn't set;
|
|
|
|
|
// The "$Cube." part of the of the original subname is replaced with "Part__Box." because the
|
|
|
|
|
// SubObjectT::NormalizeOption::KeepSubName flag isn't set;
|
|
|
|
|
// The "Edge1" part of the of the original subname is kept because the
|
|
|
|
|
// SubObjectT::NormalizeOption::NoElement flag isn't set;
|
|
|
|
|
EXPECT_TRUE(normalizeConvertIndex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -281,6 +315,12 @@ TEST_F(DocumentObserverTest, normalized)
|
|
|
|
|
auto box {_doc->addObject("Part::Box")};
|
|
|
|
|
// The name of the Part::Box added to the document
|
|
|
|
|
auto boxName {box->getNameInDocument()};
|
|
|
|
|
// Changing the label of the Part::Box to test the differences between calling
|
|
|
|
|
// SubObjectT::normalized() with the options argument set to
|
|
|
|
|
// SubObjectT::NormalizeOption::KeepSubName or set to other values
|
|
|
|
|
box->Label.setValue("Cube");
|
|
|
|
|
// The label of the Part::Box added to the document
|
|
|
|
|
auto boxLabel {box->Label.getValue()};
|
|
|
|
|
// The name of a Part::Cylinder added to the document
|
|
|
|
|
auto cylName {_doc->addObject("Part::Cylinder")->getNameInDocument()};
|
|
|
|
|
// An App::Part added to the document
|
|
|
|
|
@@ -291,10 +331,11 @@ TEST_F(DocumentObserverTest, normalized)
|
|
|
|
|
auto lGrp {_doc->addObject("App::LinkGroup")};
|
|
|
|
|
// The name of the App::LinkGroup added to the document
|
|
|
|
|
auto lGrpName {lGrp->getNameInDocument()};
|
|
|
|
|
|
|
|
|
|
// The name of the object used as argument for various calls of the constructors of
|
|
|
|
|
// App::SubObjectT objects
|
|
|
|
|
auto subName {std::string()};
|
|
|
|
|
// An helper string used to compose the argument of some calls of
|
|
|
|
|
// A helper string used to compose the argument of some calls of
|
|
|
|
|
// Base::Interpreter().runString()
|
|
|
|
|
auto cmd {std::string()};
|
|
|
|
|
|
|
|
|
|
@@ -323,24 +364,43 @@ TEST_F(DocumentObserverTest, normalized)
|
|
|
|
|
Base::Interpreter().runString(cmd.c_str());
|
|
|
|
|
Base::Interpreter().runString("App.ActiveDocument.recompute()");
|
|
|
|
|
|
|
|
|
|
// Adding the fusion to the App::LinkGroup object to test SubObjectT::normalized() with the
|
|
|
|
|
// options argument set to SubObjectT::NormalizeOption::ConvertIndex
|
|
|
|
|
// Creating a Link Array with the App::Part object added to the document to test
|
|
|
|
|
// SubObjectT::normalized() with the options argument set to
|
|
|
|
|
// SubObjectT::NormalizeOption::ConvertIndex or set to other values
|
|
|
|
|
Base::Interpreter().runString("import Draft");
|
|
|
|
|
cmd = "_obj = Draft.make_ortho_array(App.ActiveDocument.";
|
|
|
|
|
cmd += partName;
|
|
|
|
|
cmd += ", v_x=FreeCAD.Vector(100.0, 0.0, 0.0), v_y=FreeCAD.Vector(0.0, 100.0, 0.0), "
|
|
|
|
|
"v_z=FreeCAD.Vector(0.0, 0.0, 100.0), n_x=2, n_y=2, n_z=1, use_link=True)";
|
|
|
|
|
Base::Interpreter().runString(cmd.c_str());
|
|
|
|
|
cmd = "_obj.Fuse = False";
|
|
|
|
|
Base::Interpreter().runString(cmd.c_str());
|
|
|
|
|
cmd = "Draft.autogroup(_obj)";
|
|
|
|
|
Base::Interpreter().runString(cmd.c_str());
|
|
|
|
|
Base::Interpreter().runString("App.ActiveDocument.recompute()");
|
|
|
|
|
auto lArr {_doc->getObject("Array")};
|
|
|
|
|
auto lArrName {lArr->getNameInDocument()};
|
|
|
|
|
|
|
|
|
|
// Adding the Link Array to the App::LinkGroup object to test SubObjectT::normalized() with the
|
|
|
|
|
// options argument set to SubObjectT::NormalizeOption::ConvertIndex or set to other values
|
|
|
|
|
cmd = "App.ActiveDocument.getObject(\"";
|
|
|
|
|
cmd += lGrpName;
|
|
|
|
|
cmd += "\").setLink(App.ActiveDocument.getObject(\"";
|
|
|
|
|
cmd += partName;
|
|
|
|
|
cmd += lArrName;
|
|
|
|
|
cmd += "\"))";
|
|
|
|
|
Base::Interpreter().runString(cmd.c_str());
|
|
|
|
|
Base::Interpreter().runString("App.ActiveDocument.recompute()");
|
|
|
|
|
|
|
|
|
|
// Defining the name of the object that will be used as argument for various calls of the
|
|
|
|
|
// constructors of App::SubObjectT objects
|
|
|
|
|
subName = partName;
|
|
|
|
|
subName += ".";
|
|
|
|
|
subName = "0.";
|
|
|
|
|
subName += "3.";
|
|
|
|
|
subName += fuseName;
|
|
|
|
|
subName += ".";
|
|
|
|
|
subName += boxName;
|
|
|
|
|
subName += ".Edge1";
|
|
|
|
|
subName += "$";
|
|
|
|
|
subName += boxLabel;
|
|
|
|
|
subName += ".";
|
|
|
|
|
subName += "Edge1";
|
|
|
|
|
|
|
|
|
|
// An empty App::SubObjectT object
|
|
|
|
|
auto subObjTEmpty {SubObjectT()};
|
|
|
|
|
@@ -356,7 +416,7 @@ TEST_F(DocumentObserverTest, normalized)
|
|
|
|
|
auto subObjTNoFlatten {SubObjectT(lGrp, subName.c_str())};
|
|
|
|
|
// An App::SubObjectT object used to test SubObjectT::normalized() with the option argument set
|
|
|
|
|
// to SubObjectT::NormalizeOption::KeepSubName
|
|
|
|
|
auto subObjTKeepSubName {SubObjectT(lGrp, subName.replace(0, strlen(partName), "0").c_str())};
|
|
|
|
|
auto subObjTKeepSubName {SubObjectT(lGrp, subName.c_str())};
|
|
|
|
|
// An App::SubObjectT object used to test SubObjectT::normalized() with the option argument set
|
|
|
|
|
// to SubObjectT::NormalizeOption::ConvertIndex
|
|
|
|
|
auto subObjTConvertIndex {SubObjectT(lGrp, subName.c_str())};
|
|
|
|
|
@@ -398,29 +458,91 @@ TEST_F(DocumentObserverTest, normalized)
|
|
|
|
|
|
|
|
|
|
// In this case calling SubObjectT::normalized() doesn't have effect as subObjTWithoutSubObj
|
|
|
|
|
// hasn't any sub objects
|
|
|
|
|
EXPECT_EQ(subObjTWithoutSubObj.getSubName(), subObjTWithoutSubObj.getSubName());
|
|
|
|
|
EXPECT_EQ(subObjTWithoutSubObj.getSubName(), subObjTWithoutSubObjNormalized.getSubName());
|
|
|
|
|
|
|
|
|
|
// In this case calling SubObjectT::normalized() changes subObjTWithSubObj subname removing the
|
|
|
|
|
// "Fusion." part of the of the original subname
|
|
|
|
|
// In this case calling SubObjectT::normalized() changes subObjTWithSubObj subname in this way:
|
|
|
|
|
// The "0." part of the of the original subname is kept because the
|
|
|
|
|
// SubObjectT::NormalizeOption::ConvertIndex flag isn't set;
|
|
|
|
|
// The "3." part of the of the original subname is kept because the
|
|
|
|
|
// SubObjectT::NormalizeOption::ConvertIndex flag isn't set;
|
|
|
|
|
// The "Fusion." part of the of the original subname is removed because the
|
|
|
|
|
// SubObjectT::NormalizeOption::NoFlatten flag isn't set;
|
|
|
|
|
// The "$Cube." part of the of the original subname is replaced with "Part__Box." because the
|
|
|
|
|
// SubObjectT::NormalizeOption::KeepSubName flag isn't set;
|
|
|
|
|
// The "Edge1" part of the of the original subname is kept because the
|
|
|
|
|
// SubObjectT::NormalizeOption::NoElement flag isn't set;
|
|
|
|
|
EXPECT_NE(subObjTWithSubObjNormalized.getSubName().find("0."), std::string::npos);
|
|
|
|
|
EXPECT_EQ(subObjTWithSubObjNormalized.getSubName().find(fuseName), std::string::npos);
|
|
|
|
|
EXPECT_EQ(subObjTWithSubObjNormalized.getSubName().find(boxLabel), std::string::npos);
|
|
|
|
|
EXPECT_NE(subObjTWithSubObjNormalized.getSubName().find(boxName), std::string::npos);
|
|
|
|
|
EXPECT_NE(subObjTWithSubObjNormalized.getSubName().find("Edge1"), std::string::npos);
|
|
|
|
|
|
|
|
|
|
// In this case calling SubObjectT::normalized() changes subObjTWithoutEl subname removing the
|
|
|
|
|
// "Fusion." and "Edge1" parts of the of the original subname
|
|
|
|
|
// In this case calling SubObjectT::normalized() changes subObjTWithoutEl subname in this way:
|
|
|
|
|
// The "0." part of the of the original subname is kept because the
|
|
|
|
|
// SubObjectT::NormalizeOption::ConvertIndex flag isn't set;
|
|
|
|
|
// The "3." part of the of the original subname is kept because the
|
|
|
|
|
// SubObjectT::NormalizeOption::ConvertIndex flag isn't set;
|
|
|
|
|
// The "Fusion." part of the of the original subname is removed because the
|
|
|
|
|
// SubObjectT::NormalizeOption::NoFlatten flag isn't set;
|
|
|
|
|
// The "$Cube." part of the of the original subname is replaced with "Part__Box." because the
|
|
|
|
|
// SubObjectT::NormalizeOption::KeepSubName flag isn't set;
|
|
|
|
|
// The "Edge1" part of the of the original subname is removed because the
|
|
|
|
|
// SubObjectT::NormalizeOption::NoElement flag is set;
|
|
|
|
|
EXPECT_NE(subObjTWithoutElNormalized.getSubName().find("0."), std::string::npos);
|
|
|
|
|
EXPECT_EQ(subObjTWithoutElNormalized.getSubName().find(fuseName), std::string::npos);
|
|
|
|
|
EXPECT_EQ(subObjTWithoutElNormalized.getSubName().find(boxLabel), std::string::npos);
|
|
|
|
|
EXPECT_NE(subObjTWithoutElNormalized.getSubName().find(boxName), std::string::npos);
|
|
|
|
|
EXPECT_EQ(subObjTWithoutElNormalized.getSubName().find("Edge1"), std::string::npos);
|
|
|
|
|
|
|
|
|
|
// In this case calling SubObjectT::normalized() doesn't have effect as neither the
|
|
|
|
|
// DocumentObject referenced nor the subname of subObjTNoFlatten are changed
|
|
|
|
|
EXPECT_EQ(subObjTNoFlatten.getSubName(), subObjTNoFlattenNormalized.getSubName());
|
|
|
|
|
// In this case calling SubObjectT::normalized() changes subObjTNoFlatten subname in this way:
|
|
|
|
|
// The "0." part of the of the original subname is kept because the
|
|
|
|
|
// SubObjectT::NormalizeOption::ConvertIndex flag isn't set;
|
|
|
|
|
// The "3." part of the of the original subname is kept because the
|
|
|
|
|
// SubObjectT::NormalizeOption::ConvertIndex flag isn't set;
|
|
|
|
|
// The "Fusion." part of the of the original subname is kept because the
|
|
|
|
|
// SubObjectT::NormalizeOption::NoFlatten flag is set;
|
|
|
|
|
// The "$Cube." part of the of the original subname is replaced with "Part__Box." because the
|
|
|
|
|
// SubObjectT::NormalizeOption::KeepSubName flag isn't set;
|
|
|
|
|
// The "Edge1" part of the of the original subname is kept because the
|
|
|
|
|
// SubObjectT::NormalizeOption::NoElement flag isn't set;
|
|
|
|
|
EXPECT_NE(subObjTNoFlattenNormalized.getSubName().find("0."), std::string::npos);
|
|
|
|
|
EXPECT_NE(subObjTNoFlattenNormalized.getSubName().find(fuseName), std::string::npos);
|
|
|
|
|
EXPECT_EQ(subObjTNoFlattenNormalized.getSubName().find(boxLabel), std::string::npos);
|
|
|
|
|
EXPECT_NE(subObjTNoFlattenNormalized.getSubName().find(boxName), std::string::npos);
|
|
|
|
|
EXPECT_NE(subObjTNoFlattenNormalized.getSubName().find("Edge1"), std::string::npos);
|
|
|
|
|
|
|
|
|
|
// In this case calling SubObjectT::normalized() changes subObjTKeepSubName subname removing the
|
|
|
|
|
// "Fusion." part of the of the original subname
|
|
|
|
|
// In this case calling SubObjectT::normalized() changes subObjTKeepSubName subname in this way:
|
|
|
|
|
// The "0." part of the of the original subname is kept because the
|
|
|
|
|
// SubObjectT::NormalizeOption::ConvertIndex flag isn't set;
|
|
|
|
|
// The "3." part of the of the original subname is kept because the
|
|
|
|
|
// SubObjectT::NormalizeOption::ConvertIndex flag isn't set;
|
|
|
|
|
// The "Fusion." part of the of the original subname is removed because the
|
|
|
|
|
// SubObjectT::NormalizeOption::NoFlatten flag isn't set;
|
|
|
|
|
// The "$Cube." part of the of the original subname is kept because the
|
|
|
|
|
// SubObjectT::NormalizeOption::KeepSubName flag is set;
|
|
|
|
|
// The "Edge1" part of the of the original subname is kept because the
|
|
|
|
|
// SubObjectT::NormalizeOption::NoElement flag isn't set;
|
|
|
|
|
EXPECT_NE(subObjTKeepSubNameNormalized.getSubName().find("0."), std::string::npos);
|
|
|
|
|
EXPECT_EQ(subObjTKeepSubNameNormalized.getSubName().find(fuseName), std::string::npos);
|
|
|
|
|
EXPECT_NE(subObjTKeepSubNameNormalized.getSubName().find(boxLabel), std::string::npos);
|
|
|
|
|
EXPECT_NE(subObjTKeepSubNameNormalized.getSubName().find("Edge1"), std::string::npos);
|
|
|
|
|
|
|
|
|
|
// In this case calling SubObjectT::normalized() changes subObjTConvertIndex subname replacing
|
|
|
|
|
// the "0" part of the of the original subname with "App__Part" as lGrp object at position 0 is
|
|
|
|
|
// the DocumentObject with name "App__Part" and removing the "Fusion" part
|
|
|
|
|
EXPECT_EQ(subObjTConvertIndexNormalized.getSubName().find("0"), std::string::npos);
|
|
|
|
|
// In this case calling SubObjectT::normalized() changes subObjTConvertIndex in this way:
|
|
|
|
|
// The "0." part of the of the original subname is replaced with "Array." because the
|
|
|
|
|
// SubObjectT::NormalizeOption::ConvertIndex flag is set;
|
|
|
|
|
// The "3." part of the of the original subname is kept even if the
|
|
|
|
|
// SubObjectT::NormalizeOption::ConvertIndex flag is set because it refers to a specific
|
|
|
|
|
// DocumentObject of the "Array." DocumentObject;
|
|
|
|
|
// The "Fusion." part of the of the original subname is removed because the
|
|
|
|
|
// SubObjectT::NormalizeOption::NoFlatten flag isn't set;
|
|
|
|
|
// The "$Cube." part of the of the original subname is replaced with "Part__Box." because the
|
|
|
|
|
// SubObjectT::NormalizeOption::KeepSubName flag isn't set;
|
|
|
|
|
// The "Edge1" part of the of the original subname is kept because the
|
|
|
|
|
// SubObjectT::NormalizeOption::NoElement flag isn't set;
|
|
|
|
|
EXPECT_EQ(subObjTConvertIndexNormalized.getSubName().find("0."), std::string::npos);
|
|
|
|
|
EXPECT_NE(subObjTConvertIndexNormalized.getSubName().find(lArrName), std::string::npos);
|
|
|
|
|
EXPECT_EQ(subObjTConvertIndexNormalized.getSubName().find(fuseName), std::string::npos);
|
|
|
|
|
EXPECT_NE(subObjTConvertIndexNormalized.getSubName().find(partName), std::string::npos);
|
|
|
|
|
EXPECT_EQ(subObjTConvertIndexNormalized.getSubName().find(boxLabel), std::string::npos);
|
|
|
|
|
EXPECT_NE(subObjTConvertIndexNormalized.getSubName().find(boxName), std::string::npos);
|
|
|
|
|
EXPECT_NE(subObjTConvertIndexNormalized.getSubName().find("Edge1"), std::string::npos);
|
|
|
|
|
}
|
|
|
|
|
|