PartDesign: Add transparent previews
This commit is contained in:
@@ -71,7 +71,11 @@
|
||||
|
||||
#include "Tools.h"
|
||||
|
||||
#include <TopExp_Explorer.hxx>
|
||||
#include <TopoShape.h>
|
||||
|
||||
|
||||
class TopExp_Explorer;
|
||||
void Part::closestPointsOnLines(const gp_Lin& lin1, const gp_Lin& lin2, gp_Pnt& p1, gp_Pnt& p2)
|
||||
{
|
||||
// they might be the same point
|
||||
@@ -746,36 +750,71 @@ TopLoc_Location Part::Tools::fromPlacement(const Base::Placement& plm)
|
||||
return {trf};
|
||||
}
|
||||
|
||||
bool Part::Tools::isConcave(const TopoDS_Face &face, const gp_Pnt &pointOfVue, const gp_Dir &direction){
|
||||
bool Part::Tools::isConcave(const TopoDS_Face& face,
|
||||
const gp_Pnt& pointOfVue,
|
||||
const gp_Dir& direction)
|
||||
{
|
||||
bool result = false;
|
||||
|
||||
Handle(Geom_Surface) surf = BRep_Tool::Surface(face);
|
||||
GeomAdaptor_Surface adapt(surf);
|
||||
if(adapt.GetType() == GeomAbs_Plane){
|
||||
if (adapt.GetType() == GeomAbs_Plane) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// create a line through the point of vue
|
||||
// create a line through the point of vue
|
||||
gp_Lin line;
|
||||
line.SetLocation(pointOfVue);
|
||||
line.SetDirection(direction);
|
||||
|
||||
// Find intersection of line with the face
|
||||
// Find intersection of line with the face
|
||||
BRepIntCurveSurface_Inter mkSection;
|
||||
mkSection.Init(face, line, Precision::Confusion());
|
||||
|
||||
result = mkSection.Transition() == IntCurveSurface_In;
|
||||
|
||||
// compute normals at the intersection
|
||||
// compute normals at the intersection
|
||||
gp_Pnt iPnt;
|
||||
gp_Vec dU, dV;
|
||||
surf->D1(mkSection.U(), mkSection.V(), iPnt, dU, dV);
|
||||
|
||||
// check normals orientation
|
||||
// check normals orientation
|
||||
gp_Dir dirdU(dU);
|
||||
result = (dirdU.Angle(direction) - std::numbers::pi/2) <= Precision::Confusion();
|
||||
result = (dirdU.Angle(direction) - std::numbers::pi / 2) <= Precision::Confusion();
|
||||
gp_Dir dirdV(dV);
|
||||
result = result || ((dirdV.Angle(direction) - std::numbers::pi/2) <= Precision::Confusion());
|
||||
result = result || ((dirdV.Angle(direction) - std::numbers::pi / 2) <= Precision::Confusion());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool Part::Tools::isShapeEmpty(const TopoShape& shape)
|
||||
{
|
||||
return shape.isEmpty();
|
||||
}
|
||||
|
||||
bool Part::Tools::isShapeEmpty(const TopoDS_Shape& shape)
|
||||
{
|
||||
static const auto isEveryShapeInCompoundEmpty = [](const TopoDS_Shape& shape) {
|
||||
for (TopoDS_Iterator it(shape); it.More(); it.Next()) {
|
||||
if (const TopoDS_Shape& sub = it.Value(); !isShapeEmpty(sub)) {
|
||||
// Found a non-empty sub-shape
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
// If shape is null we consider it as empty
|
||||
if (shape.IsNull()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (shape.ShapeType() == TopAbs_COMPOUND) {
|
||||
return isEveryShapeInCompoundEmpty(shape);
|
||||
}
|
||||
|
||||
// To see if shape is non-empty we check if it has at least one vertex
|
||||
TopExp_Explorer explorer(shape, TopAbs_VERTEX);
|
||||
return !explorer.More();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user