Assembly: Replace Tangent+Parallel+Planar by 'Distance'.
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -25,6 +25,10 @@
|
||||
#ifndef ASSEMBLY_AssemblyObject_H
|
||||
#define ASSEMBLY_AssemblyObject_H
|
||||
|
||||
|
||||
#include <GeomAbs_CurveType.hxx>
|
||||
#include <GeomAbs_SurfaceType.hxx>
|
||||
|
||||
#include <Mod/Assembly/AssemblyGlobal.h>
|
||||
|
||||
#include <App/FeaturePython.h>
|
||||
@@ -49,6 +53,8 @@ class Rotation;
|
||||
namespace Assembly
|
||||
{
|
||||
|
||||
class JointGroup;
|
||||
|
||||
// This enum has to be the same as the one in JointObject.py
|
||||
enum class JointType
|
||||
{
|
||||
@@ -57,9 +63,7 @@ enum class JointType
|
||||
Cylindrical,
|
||||
Slider,
|
||||
Ball,
|
||||
Planar,
|
||||
Parallel,
|
||||
Tangent
|
||||
Distance
|
||||
};
|
||||
|
||||
class AssemblyExport AssemblyObject: public App::Part
|
||||
@@ -78,35 +82,78 @@ public:
|
||||
return "AssemblyGui::ViewProviderAssembly";
|
||||
}
|
||||
|
||||
int solve();
|
||||
int solve(bool enableRedo = false);
|
||||
void savePlacementsForUndo();
|
||||
void undoSolve();
|
||||
void clearUndo();
|
||||
void exportAsASMT(std::string fileName);
|
||||
std::shared_ptr<MbD::ASMTAssembly> makeMbdAssembly();
|
||||
std::shared_ptr<MbD::ASMTPart>
|
||||
makeMbdPart(std::string& name, Base::Placement plc = Base::Placement(), double mass = 1.0);
|
||||
std::shared_ptr<MbD::ASMTPart> getMbDPart(App::DocumentObject* obj);
|
||||
std::shared_ptr<MbD::ASMTMarker> makeMbdMarker(std::string& name, Base::Placement& plc);
|
||||
std::shared_ptr<MbD::ASMTJoint> makeMbdJoint(App::DocumentObject* joint);
|
||||
std::shared_ptr<MbD::ASMTJoint> makeMbdJointOfType(JointType jointType);
|
||||
std::vector<std::shared_ptr<MbD::ASMTJoint>> makeMbdJoint(App::DocumentObject* joint);
|
||||
std::shared_ptr<MbD::ASMTJoint> makeMbdJointOfType(App::DocumentObject* joint,
|
||||
JointType jointType);
|
||||
std::shared_ptr<MbD::ASMTJoint> makeMbdJointDistance(App::DocumentObject* joint);
|
||||
std::shared_ptr<MbD::ASMTJoint> makeMbdJointDistanceFaceVertex(App::DocumentObject* joint);
|
||||
std::shared_ptr<MbD::ASMTJoint> makeMbdJointDistanceEdgeVertex(App::DocumentObject* joint);
|
||||
std::shared_ptr<MbD::ASMTJoint> makeMbdJointDistanceFaceEdge(App::DocumentObject* joint);
|
||||
std::shared_ptr<MbD::ASMTJoint> makeMbdJointDistanceEdgeEdge(App::DocumentObject* joint);
|
||||
std::shared_ptr<MbD::ASMTJoint> makeMbdJointDistanceFaceFace(App::DocumentObject* joint);
|
||||
|
||||
std::string handleOneSideOfJoint(App::DocumentObject* joint,
|
||||
JointType jointType,
|
||||
const char* propObjLinkName,
|
||||
const char* propPlcName);
|
||||
void fixGroundedPart(App::DocumentObject* obj, Base::Placement& plc, std::string& jointName);
|
||||
bool fixGroundedParts();
|
||||
void jointParts(std::vector<App::DocumentObject*> joints);
|
||||
std::vector<App::DocumentObject*> getJoints();
|
||||
Base::Placement getPlacementFromProp(App::DocumentObject* obj, const char* propName);
|
||||
std::vector<App::DocumentObject*> getGroundedJoints();
|
||||
void fixGroundedPart(App::DocumentObject* obj, Base::Placement& plc, std::string& jointName);
|
||||
std::vector<App::DocumentObject*> fixGroundedParts();
|
||||
|
||||
void removeUnconnectedJoints(std::vector<App::DocumentObject*>& joints,
|
||||
std::vector<App::DocumentObject*> groundedObjs);
|
||||
void traverseAndMarkConnectedParts(App::DocumentObject* currentPart,
|
||||
std::set<App::DocumentObject*>& connectedParts,
|
||||
const std::vector<App::DocumentObject*>& joints);
|
||||
std::vector<App::DocumentObject*>
|
||||
getConnectedParts(App::DocumentObject* part, const std::vector<App::DocumentObject*>& joints);
|
||||
|
||||
JointGroup* getJointGroup();
|
||||
|
||||
void swapJCS(App::DocumentObject* joint);
|
||||
|
||||
void setNewPlacements();
|
||||
void recomputeJointPlacements(std::vector<App::DocumentObject*> joints);
|
||||
|
||||
bool isPartConnected(App::DocumentObject* obj);
|
||||
|
||||
double getObjMass(App::DocumentObject* obj);
|
||||
void setObjMasses(std::vector<std::pair<App::DocumentObject*, double>> objectMasses);
|
||||
|
||||
bool isEdgeType(App::DocumentObject* obj, const char* elName, GeomAbs_CurveType type);
|
||||
bool isFaceType(App::DocumentObject* obj, const char* elName, GeomAbs_SurfaceType type);
|
||||
double getFaceRadius(App::DocumentObject* obj, const char* elName);
|
||||
double getEdgeRadius(App::DocumentObject* obj, const char* elName);
|
||||
|
||||
// getters to get from properties
|
||||
double getJointDistance(App::DocumentObject* joint);
|
||||
JointType getJointType(App::DocumentObject* joint);
|
||||
const char* getElementFromProp(App::DocumentObject* obj, const char* propName);
|
||||
std::string getElementTypeFromProp(App::DocumentObject* obj, const char* propName);
|
||||
Base::Placement getPlacementFromProp(App::DocumentObject* obj, const char* propName);
|
||||
App::DocumentObject* getLinkObjFromProp(App::DocumentObject* joint, const char* propName);
|
||||
App::DocumentObject* getLinkedObjFromProp(App::DocumentObject* joint, const char* propName);
|
||||
|
||||
private:
|
||||
std::shared_ptr<MbD::ASMTAssembly> mbdAssembly;
|
||||
|
||||
std::unordered_map<App::DocumentObject*, std::shared_ptr<MbD::ASMTPart>> objectPartMap;
|
||||
std::vector<std::pair<App::DocumentObject*, double>> objMasses;
|
||||
|
||||
std::vector<std::pair<App::DocumentObject*, Base::Placement>> previousPositions;
|
||||
|
||||
// void handleChangedPropertyType(Base::XMLReader &reader, const char *TypeName, App::Property
|
||||
// *prop) override;
|
||||
};
|
||||
|
||||
@@ -18,7 +18,13 @@
|
||||
<UserDocu>
|
||||
Solve the assembly and update part placements.
|
||||
|
||||
solve()
|
||||
solve(enableRedo=False) -> int
|
||||
|
||||
Args:
|
||||
enableRedo: Whether the solve save the initial position of parts
|
||||
to enable undoing it even without a transaction.
|
||||
Defaults to `False` ie the solve cannot be undone if called
|
||||
outside of a transaction.
|
||||
|
||||
Returns:
|
||||
0 in case of success, otherwise the following codes in this order of
|
||||
@@ -32,6 +38,41 @@
|
||||
</UserDocu>
|
||||
</Documentation>
|
||||
</Methode>
|
||||
<Methode Name="undoSolve">
|
||||
<Documentation>
|
||||
<UserDocu>
|
||||
Undo the last solve of the assembly and return part placements to their initial position.
|
||||
|
||||
undoSolve()
|
||||
|
||||
Returns: None
|
||||
</UserDocu>
|
||||
</Documentation>
|
||||
</Methode>
|
||||
<Methode Name="clearUndo">
|
||||
<Documentation>
|
||||
<UserDocu>
|
||||
Clear the registered undo positions.
|
||||
|
||||
clearUndo()
|
||||
|
||||
Returns: None
|
||||
</UserDocu>
|
||||
</Documentation>
|
||||
</Methode>
|
||||
<Methode Name="isPartConnected">
|
||||
<Documentation>
|
||||
<UserDocu>
|
||||
Check if a part is connected to the ground through joints.
|
||||
|
||||
isPartConnected(obj) -> bool
|
||||
|
||||
Args: document object to check.
|
||||
|
||||
Returns: True if part is connected to ground
|
||||
</UserDocu>
|
||||
</Documentation>
|
||||
</Methode>
|
||||
<Methode Name="exportAsASMT">
|
||||
<Documentation>
|
||||
<UserDocu>
|
||||
|
||||
@@ -46,12 +46,55 @@ int AssemblyObjectPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*
|
||||
}
|
||||
|
||||
PyObject* AssemblyObjectPy::solve(PyObject* args)
|
||||
{
|
||||
PyObject* enableUndoPy;
|
||||
bool enableUndo;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "O!", &PyBool_Type, &enableUndoPy)) {
|
||||
PyErr_Clear();
|
||||
if (!PyArg_ParseTuple(args, "")) {
|
||||
return nullptr;
|
||||
}
|
||||
else {
|
||||
enableUndo = false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
enableUndo = Base::asBoolean(enableUndoPy);
|
||||
}
|
||||
|
||||
int ret = this->getAssemblyObjectPtr()->solve(enableUndo);
|
||||
return Py_BuildValue("i", ret);
|
||||
}
|
||||
|
||||
PyObject* AssemblyObjectPy::undoSolve(PyObject* args)
|
||||
{
|
||||
if (!PyArg_ParseTuple(args, "")) {
|
||||
return nullptr;
|
||||
}
|
||||
int ret = this->getAssemblyObjectPtr()->solve();
|
||||
return Py_BuildValue("i", ret);
|
||||
this->getAssemblyObjectPtr()->undoSolve();
|
||||
Py_Return;
|
||||
}
|
||||
|
||||
PyObject* AssemblyObjectPy::clearUndo(PyObject* args)
|
||||
{
|
||||
if (!PyArg_ParseTuple(args, "")) {
|
||||
return nullptr;
|
||||
}
|
||||
this->getAssemblyObjectPtr()->clearUndo();
|
||||
Py_Return;
|
||||
}
|
||||
|
||||
PyObject* AssemblyObjectPy::isPartConnected(PyObject* args)
|
||||
{
|
||||
PyObject* pyobj;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "O", &pyobj)) {
|
||||
return nullptr;
|
||||
}
|
||||
auto* obj = static_cast<App::DocumentObjectPy*>(pyobj)->getDocumentObjectPtr();
|
||||
bool ok = this->getAssemblyObjectPtr()->isPartConnected(obj);
|
||||
return Py_BuildValue("O", (ok ? Py_True : Py_False));
|
||||
}
|
||||
|
||||
PyObject* AssemblyObjectPy::exportAsASMT(PyObject* args)
|
||||
|
||||
@@ -42,5 +42,10 @@
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
|
||||
#include <BRepAdaptor_Curve.hxx>
|
||||
#include <BRepAdaptor_Surface.hxx>
|
||||
#include <TopoDS.hxx>
|
||||
#include <TopoDS_Face.hxx>
|
||||
|
||||
#endif // _PreComp_
|
||||
#endif // ASSEMBLY_PRECOMPILED_H
|
||||
|
||||
Reference in New Issue
Block a user