Merge branch 'main' into master

This commit is contained in:
qewer
2024-03-16 10:47:58 +03:00
committed by GitHub
7 changed files with 1491 additions and 930 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -30,8 +30,10 @@
#include <GProp_GProps.hxx>
#include <App/DocumentObserver.h>
#include <App/GeoFeature.h>
#include <App/PropertyLinks.h>
#include <App/PropertyStandard.h>
#include <Base/Exception.h>
#include <Base/Placement.h>
@@ -222,7 +224,17 @@ public: //methods
const Base::Placement &attachmentOffset = Base::Placement());
virtual void setUp(const AttachEngine &another);
virtual AttachEngine* copy() const = 0;
virtual Base::Placement calculateAttachedPlacement(const Base::Placement& origPlacement) const = 0;
Base::Placement calculateAttachedPlacement(
const Base::Placement &origPlacement, bool *subChanged=0);
virtual Base::Placement _calculateAttachedPlacement(
const std::vector<App::DocumentObject*> &objs,
const std::vector<std::string> &subs,
const Base::Placement &origPlacement) const = 0;
void setReferences(const App::PropertyLinkSubList &references);
void setReferences(const std::vector<App::SubObjectT> &references);
/**
* @brief placementFactory calculates placement from Z axis direction,
@@ -348,6 +360,9 @@ public://helper functions that may be useful outside of the class
static GProp_GProps getInertialPropsOfShape(const std::vector<const TopoDS_Shape*> &shapes);
std::vector<App::DocumentObject*> getRefObjects() const;
const std::vector<std::string> &getSubValues() const {return subnames;}
/**
* @brief verifyReferencesAreSafe: checks if pointers in references still
* point to objects contained in open documents. This guarantees the links
@@ -362,6 +377,10 @@ public: //enums
public: //members
App::PropertyLinkSubList references;
std::string docName;
std::vector<std::string> objNames;
std::vector<std::string> subnames;
std::vector<std::string> shadowSubs;
eMapMode mapMode = mmDeactivated;
bool mapReverse = false;
@@ -405,7 +424,8 @@ protected:
ret.push_back(rt4);
return ret;
}
static void readLinks(const App::PropertyLinkSubList &references, std::vector<App::GeoFeature *> &geofs,
static void readLinks(const std::vector<App::DocumentObject*> &objs,
const std::vector<std::string> &subs, std::vector<App::GeoFeature *> &geofs,
std::vector<const TopoDS_Shape*>& shapes, std::vector<TopoDS_Shape> &storage,
std::vector<eRefType> &types);
@@ -420,7 +440,10 @@ class PartExport AttachEngine3D : public AttachEngine
public:
AttachEngine3D();
AttachEngine3D* copy() const override;
Base::Placement calculateAttachedPlacement(const Base::Placement& origPlacement) const override;
Base::Placement _calculateAttachedPlacement(
const std::vector<App::DocumentObject*> &objs,
const std::vector<std::string> &subs,
const Base::Placement &origPlacement) const override;
private:
double calculateFoldAngle(gp_Vec axA, gp_Vec axB, gp_Vec edA, gp_Vec edB) const;
};
@@ -432,7 +455,10 @@ class PartExport AttachEnginePlane : public AttachEngine
public:
AttachEnginePlane();
AttachEnginePlane* copy() const override;
Base::Placement calculateAttachedPlacement(const Base::Placement& origPlacement) const override;
Base::Placement _calculateAttachedPlacement(
const std::vector<App::DocumentObject*> &objs,
const std::vector<std::string> &subs,
const Base::Placement &origPlacement) const override;
};
//attacher specialized for datum lines
@@ -442,7 +468,10 @@ class PartExport AttachEngineLine : public AttachEngine
public:
AttachEngineLine();
AttachEngineLine* copy() const override;
Base::Placement calculateAttachedPlacement(const Base::Placement& origPlacement) const override;
Base::Placement _calculateAttachedPlacement(
const std::vector<App::DocumentObject*> &objs,
const std::vector<std::string> &subs,
const Base::Placement &origPlacement) const override;
};
//attacher specialized for datum points
@@ -452,7 +481,10 @@ class PartExport AttachEnginePoint : public AttachEngine
public:
AttachEnginePoint();
AttachEnginePoint* copy() const override;
Base::Placement calculateAttachedPlacement(const Base::Placement& origPlacement) const override;
Base::Placement _calculateAttachedPlacement(
const std::vector<App::DocumentObject*> &objs,
const std::vector<std::string> &subs,
const Base::Placement &origPlacement) const override;
private:
gp_Pnt getProximityPoint(eMapMode mode, const TopoDS_Shape& s1, const TopoDS_Shape& s2) const;

View File

@@ -336,50 +336,19 @@ Data::Segment* TopoShape::getSubElement(const char* Type, unsigned long n) const
return new ShapeSegment(getSubShape(temp.c_str()));
}
TopoDS_Shape TopoShape::getSubShape(const char* Type, bool silent) const
{
auto res = shapeTypeAndIndex(Type);
return getSubShape(res.first,res.second,silent);
TopoDS_Shape TopoShape::getSubShape(const char* Type, bool silent) const {
TopoShape s(*this);
s.Tag = 0;
return s.getSubTopoShape(Type,silent).getShape();
}
TopoDS_Shape TopoShape::getSubShape(TopAbs_ShapeEnum type, int index, bool silent) const
{
if(index <= 0) {
if(silent)
return {};
// TODO: Is this message clear? Should we complain about the negative index instead
Standard_Failure::Raise("Unsupported sub-shape type");
}
if (this->_Shape.IsNull()) {
if(silent)
return {};
Standard_Failure::Raise("Cannot get sub-shape from empty shape");
}
try {
if(type == TopAbs_SHAPE) {
int i=1;
for(TopoDS_Iterator it(_Shape);it.More();it.Next(),++i) {
if(i == index)
return it.Value();
}
} else {
TopTools_IndexedMapOfShape anIndices;
TopExp::MapShapes(this->_Shape, type, anIndices);
if(index <= anIndices.Extent())
return anIndices.FindKey(index);
}
} catch(Standard_Failure &) {
if(silent)
return {};
throw;
}
if(!silent)
Standard_Failure::Raise("Index out of bound");
return {};
TopoDS_Shape TopoShape::getSubShape(TopAbs_ShapeEnum type, int idx, bool silent) const {
TopoShape s(*this);
s.Tag = 0;
return s.getSubTopoShape(type,idx,silent).getShape();
}
unsigned long TopoShape::countSubShapes(const char* Type) const
{
if(!Type)

View File

@@ -170,7 +170,9 @@ class PartTestBSplineCurve(unittest.TestCase):
box.getElement("InvalidName")
with self.assertRaises(ValueError):
box.getElement("Face6_abc")
with self.assertRaises(Part.OCCError):
# getSubTopoShape now catches this before it gets to OCC, so the error changes:
# with self.assertRaises(Part.OCCError):
with self.assertRaises(IndexError):
box.getElement("Face7")
def tearDown(self):