| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | # include <TopoDS_Shape.hxx> |
| |
|
| |
|
| | #include <BRep_Tool.hxx> |
| | #include <BRepAdaptor_Curve.hxx> |
| | #include <BRepBuilderAPI_MakeVertex.hxx> |
| | #include <TopExp.hxx> |
| |
|
| | #include <App/GeoFeature.h> |
| | #include <App/DocumentObject.h> |
| | #include <App/Document.h> |
| | #include <App/Link.h> |
| | #include <Base/Console.h> |
| |
|
| | #include <Mod/Measure/App/ShapeFinder.h> |
| | #include <Mod/Part/App/TopoShape.h> |
| | #include <Mod/PartDesign/App/Body.h> |
| | #include <Mod/PartDesign/App/Feature.h> |
| |
|
| | #include "DimensionReferences.h" |
| | #include "DrawUtil.h" |
| | #include "DrawViewPart.h" |
| | #include "ShapeUtils.h" |
| | #include "CosmeticVertex.h" |
| |
|
| | using namespace TechDraw; |
| | using namespace Measure; |
| | using DU = DrawUtil; |
| | using SU = ShapeUtils; |
| |
|
| |
|
| | ReferenceEntry::ReferenceEntry( App::DocumentObject* docObject, const std::string& subName, App::Document* document) |
| | { |
| | setObject(docObject); |
| | setSubName(subName); |
| | setDocument(document); |
| | if (docObject) { |
| | setObjectName(docObject->getNameInDocument()); |
| | if (document == nullptr) { |
| | setDocument(docObject->getDocument()); |
| | } |
| | } |
| | } |
| |
|
| |
|
| | ReferenceEntry::ReferenceEntry(const ReferenceEntry& other) |
| | { |
| | setObject(other.getObject()); |
| | setSubName(other.getSubName(true)); |
| | setObjectName(other.getObjectName()); |
| | setDocument(other.getDocument()); |
| | } |
| |
|
| |
|
| |
|
| | ReferenceEntry& ReferenceEntry::operator=(const ReferenceEntry& otherRef) |
| | { |
| | if (this == &otherRef) { |
| | return *this; |
| | } |
| | setObject(otherRef.getObject()); |
| | setSubName(otherRef.getSubName(true)); |
| | setObjectName(otherRef.getObjectName()); |
| | setDocument(otherRef.getDocument()); |
| | return *this; |
| | } |
| |
|
| |
|
| | bool ReferenceEntry::operator==(const ReferenceEntry& otherRef) const |
| | { |
| | return getObjectName() == otherRef.getObjectName() && getSubName() == otherRef.getSubName(); |
| | } |
| |
|
| |
|
| | TopoDS_Shape ReferenceEntry::getGeometry() const |
| | { |
| | |
| | App::DocumentObject* obj = getDocument()->getObject(getObjectName().c_str()); |
| | if (!obj) { |
| | return {}; |
| | } |
| |
|
| | if (getSubName().empty()) { |
| | return {}; |
| | } |
| |
|
| | if ( getObject()->isDerivedFrom<TechDraw::DrawViewPart>() ) { |
| | |
| | return getGeometry2d(); |
| | } |
| |
|
| | |
| | return ShapeFinder::getLocatedShape(*getObject(), getSubName(true)); |
| | } |
| |
|
| |
|
| | |
| | TopoDS_Shape ReferenceEntry::getGeometry2d() const |
| | { |
| | std::string gType; |
| | try { |
| | auto dvp = getObject<TechDraw::DrawViewPart>(); |
| | gType = geomType(); |
| | if (gType == "Vertex") { |
| | |
| | |
| | auto vgeom = dvp->getVertex(getSubName()); |
| | if (!vgeom) { |
| | return {}; |
| | } |
| | return vgeom->getOCCVertex(); |
| | } |
| | if (gType == "Edge") { |
| | auto egeom = dvp->getEdge(getSubName()); |
| | if (!egeom) { |
| | return {}; |
| | } |
| | return egeom->getOCCEdge(); |
| | } |
| | if (gType == "Face") { |
| | auto fgeom = dvp->getFace(getSubName()); |
| | if (!fgeom) { |
| | return {}; |
| | } |
| | return fgeom->toOccFace(); |
| | } |
| | } |
| | catch (...) { |
| | Base::Console().message("RE::getGeometry2d - no shape for dimension 2d reference - gType: **%s**\n", gType.c_str()); |
| | } |
| |
|
| | return {}; |
| | } |
| |
|
| |
|
| | std::string ReferenceEntry::getSubName(bool longForm) const |
| | { |
| | if (longForm) { |
| | return m_subName; |
| | } |
| |
|
| | return ShapeFinder::getLastTerm(m_subName); |
| | } |
| |
|
| |
|
| | App::DocumentObject* ReferenceEntry::getObject() const |
| | { |
| | if (!getDocument()) { |
| | return nullptr; |
| | } |
| | App::DocumentObject* obj = getDocument()->getObject(getObjectName().c_str()); |
| | if (!obj) { |
| | return nullptr; |
| | } |
| |
|
| | return obj; |
| | } |
| |
|
| |
|
| | |
| | Part::TopoShape ReferenceEntry::asTopoShape() const |
| | { |
| | TopoDS_Shape geom = getGeometry(); |
| | if (geom.IsNull()) { |
| | return {}; |
| | } |
| | if (geom.ShapeType() == TopAbs_VERTEX) { |
| | TopoDS_Vertex vert = TopoDS::Vertex(geom); |
| | return asTopoShapeVertex(vert); |
| | } |
| | if (geom.ShapeType() == TopAbs_EDGE) { |
| | TopoDS_Edge edge = TopoDS::Edge(geom); |
| | return asTopoShapeEdge(edge); |
| | } |
| | if (geom.ShapeType() == TopAbs_FACE) { |
| | TopoDS_Face face = TopoDS::Face(geom); |
| | return asTopoShapeFace(face); |
| | } |
| | throw Base::RuntimeError("Dimension Reference has unsupported geometry"); |
| | } |
| |
|
| | |
| | Part::TopoShape ReferenceEntry::asCanonicalTopoShape() const |
| | { |
| | if (is3d()) { |
| | return asTopoShape(); |
| | } |
| |
|
| | |
| | auto dvp = getObject<DrawViewPart>(); |
| | auto rawTopoShape = asTopoShape(); |
| | return ReferenceEntry::asCanonicalTopoShape(rawTopoShape, *dvp); |
| | } |
| |
|
| |
|
| | |
| | |
| | |
| | |
| | Part::TopoShape ReferenceEntry::asCanonicalTopoShape(const Part::TopoShape& inShape, const DrawViewPart& dvp) |
| | { |
| | gp_Ax2 OXYZ; |
| | auto unscaledShape = SU::scaleShape(inShape.getShape(), 1.0 / dvp.getScale()); |
| | if (dvp.Rotation.getValue() != 0.0) { |
| | auto rotationDeg = dvp.Rotation.getValue(); |
| | unscaledShape = SU::invertGeometry(unscaledShape); |
| | unscaledShape = SU::rotateShape(unscaledShape, OXYZ, -rotationDeg); |
| | unscaledShape = SU::invertGeometry(unscaledShape); |
| | } |
| | return {unscaledShape}; |
| | } |
| |
|
| |
|
| | Part::TopoShape ReferenceEntry::asTopoShapeVertex(const TopoDS_Vertex& vert) |
| | { |
| | return { vert }; |
| | } |
| |
|
| | Part::TopoShape ReferenceEntry::asTopoShapeEdge(const TopoDS_Edge &edge) |
| | { |
| | return { edge }; |
| | } |
| |
|
| | Part::TopoShape ReferenceEntry::asTopoShapeFace(const TopoDS_Face &face) |
| | { |
| | return { face }; |
| | } |
| |
|
| | std::string ReferenceEntry::geomType() const |
| | { |
| | return DrawUtil::getGeomTypeFromName(getSubName()); |
| | } |
| |
|
| | GeomType ReferenceEntry::geomEdgeType() const |
| | { |
| | int geoId = TechDraw::DrawUtil::getIndexFromName(getSubName()); |
| | auto dvp = getObject<TechDraw::DrawViewPart>(); |
| | BaseGeomPtr geom = dvp->getGeomByIndex(geoId); |
| |
|
| | if (geomType() == "Edge" && geom) { |
| | return geom->getGeomType(); |
| | } |
| |
|
| | return GeomType::NOTDEF; |
| | } |
| |
|
| | bool ReferenceEntry::isWholeObject() const |
| | { |
| | return getSubName().empty(); |
| | } |
| |
|
| | |
| | bool ReferenceEntry::is3d() const |
| | { |
| | if (getObject() && |
| | getObject()->isDerivedFrom<TechDraw::DrawViewPart>() && |
| | !getSubName().empty()) { |
| | |
| | return false; |
| | } |
| |
|
| | if (getObject() && |
| | getObject()->isDerivedFrom<TechDraw::DrawViewPart>() && |
| | getSubName().empty()) { |
| | |
| | return true; |
| | } |
| |
|
| | |
| | return true; |
| | } |
| |
|
| |
|
| | |
| | bool ReferenceEntry::hasGeometry() const |
| | { |
| | if (!getObject()) { |
| | return false; |
| | } |
| |
|
| | if ( getObject()->isDerivedFrom<TechDraw::DrawViewPart>() ) { |
| | |
| | return hasGeometry2d(); |
| | } |
| |
|
| | |
| | |
| | auto shape = Part::Feature::getTopoShape(getObject(), Part::ShapeOption::ResolveLink | Part::ShapeOption::Transform); |
| | auto subShape = shape.getSubShape(getSubName().c_str()); |
| |
|
| | return !subShape.IsNull(); |
| | } |
| |
|
| |
|
| | |
| | bool ReferenceEntry::hasGeometry2d() const |
| | { |
| | auto dvp = getObject<TechDraw::DrawViewPart>(); |
| | if (getSubName().empty()) { |
| | return false; |
| | } |
| | int geomNumber = DU::getIndexFromName(getSubName()); |
| | std::string gType = geomType(); |
| | if (gType == "Vertex") { |
| | auto vert = dvp->getProjVertexByIndex(geomNumber); |
| | if (vert) { |
| | return true; |
| | } |
| | } |
| | else if (gType == "Edge") { |
| | auto edge = dvp->getGeomByIndex(geomNumber); |
| | if (edge) { |
| | return true; |
| | } |
| | } |
| | else if (gType == "Face") { |
| | auto face = dvp->getFace(getSubName()); |
| | if (face) { |
| | return true; |
| | } |
| | } |
| | return false; |
| | } |
| |
|
| |
|
| |
|