diff --git a/src/Mod/Part/App/PartFeature.cpp b/src/Mod/Part/App/PartFeature.cpp index aae5563c10..32df8cc8e0 100644 --- a/src/Mod/Part/App/PartFeature.cpp +++ b/src/Mod/Part/App/PartFeature.cpp @@ -35,6 +35,7 @@ # include # include # include +# include # include # include # include @@ -68,6 +69,7 @@ #include #include +#include "Geometry.h" #include "PartFeature.h" #include "PartFeaturePy.h" #include "PartPyCXX.h" @@ -1410,6 +1412,44 @@ bool Feature::isElementMappingDisabled(App::PropertyContainer* container) // return false; } +bool Feature::getCameraAlignmentDirection(Base::Vector3d& direction, const char* subname) const +{ + const auto topoShape = getTopoShape(this, subname, true); + + if (topoShape.isNull()) { + return false; + } + + // Face normal + if (topoShape.isPlanar()) { + try { + const auto face = TopoDS::Face(topoShape.getShape()); + gp_Pnt point; + gp_Vec vector; + BRepGProp_Face(face).Normal(0, 0, point, vector); + direction = Base::Vector3d(vector.X(), vector.Y(), vector.Z()).Normalize(); + return true; + } + catch (Standard_TypeMismatch&) { + // Shape is not a face, do nothing + } + } + + // Edge direction + const size_t edgeCount = topoShape.countSubShapes(TopAbs_EDGE); + if (edgeCount == 1 && topoShape.isLinearEdge()) { + if (const std::unique_ptr geometry = Geometry::fromShape(topoShape.getSubShape(TopAbs_EDGE, 1), true)) { + const std::unique_ptr geomLine(static_cast(geometry.get())->toLine()); + if (geomLine) { + direction = geomLine->getDir().Normalize(); + return true; + } + } + } + + return GeoFeature::getCameraAlignmentDirection(direction, subname); +} + // --------------------------------------------------------- PROPERTY_SOURCE(Part::FilletBase, Part::Feature) diff --git a/src/Mod/Part/App/PartFeature.h b/src/Mod/Part/App/PartFeature.h index 6a1af4d48a..4387ccdd74 100644 --- a/src/Mod/Part/App/PartFeature.h +++ b/src/Mod/Part/App/PartFeature.h @@ -152,6 +152,8 @@ public: create(const TopoShape& shape, const char* name = nullptr, App::Document* document = nullptr); static bool isElementMappingDisabled(App::PropertyContainer *container); + + bool getCameraAlignmentDirection(Base::Vector3d& direction, const char* subname) const override; #ifdef FC_USE_TNP_FIX const std::vector& searchElementCache(const std::string &element,