#include <ModelAPI_ResultConstruction.h>
#include <GeomAlgoAPI_FaceBuilder.h>
+#include <GeomAPI_Pnt2d.h>
+
#define PLANE_SIZE 300
std::shared_ptr<GeomAPI_Dir> aDir = aPln->direction();
aOrig->translate(aDir, aDist);
+ std::shared_ptr<GeomAPI_Pln> aNewPln =
+ std::shared_ptr<GeomAPI_Pln>(new GeomAPI_Pln(aOrig, aDir));
+
+ // Create rectangular face close to the selected
+ double aXmin, aYmin, Zmin, aXmax, aYmax, Zmax;
+ aShape->computeSize(aXmin, aYmin, Zmin, aXmax, aYmax, Zmax);
+
+ std::shared_ptr<GeomAPI_Pnt> aPnt1 =
+ std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aXmin, aYmin, Zmin));
+ std::shared_ptr<GeomAPI_Pnt> aPnt2 =
+ std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aXmax, aYmax, Zmax));
+
+ std::shared_ptr<GeomAPI_Pnt2d> aPnt2d1 = aPnt1->to2D(aNewPln);
+ std::shared_ptr<GeomAPI_Pnt2d> aPnt2d2 = aPnt2->to2D(aNewPln);
+
+ double aWidth = aPnt2d2->x() - aPnt2d1->x();
+ double aHeight = aPnt2d2->y() - aPnt2d1->y();
+ double aWgap = aWidth * 0.1;
+ double aHgap = aHeight * 0.1;
+
std::shared_ptr<GeomAPI_Shape> aPlane =
- GeomAlgoAPI_FaceBuilder::square(aOrig, aDir, PLANE_SIZE);
+ GeomAlgoAPI_FaceBuilder::planarFace(aNewPln, aPnt2d1->x() - aWgap, aPnt2d1->y() - aHgap,
+ aWidth + 2 * aWgap, aHeight + 2 * aHgap);
ResultConstructionPtr aConstr = document()->createConstruction(data());
aConstr->setShape(aPlane);
setResult(aConstr);
#include<GeomAPI_XYZ.h>
#include<GeomAPI_Pnt2d.h>
#include<GeomAPI_Dir.h>
+#include<GeomAPI_Pln.h>
#include<gp_Pnt.hxx>
+#include<gp_Pln.hxx>
+#include<ProjLib.hxx>
#define MY_PNT static_cast<gp_Pnt*>(myImpl)
aVec.Multiply(theDist);
MY_PNT->Translate(aVec);
}
+
+std::shared_ptr<GeomAPI_Pnt2d> GeomAPI_Pnt::to2D(const std::shared_ptr<GeomAPI_Pln>& thePln) const
+{
+ double aA, aB, aC, aD;
+ thePln->coefficients(aA, aB, aC, aD);
+ gp_Pln aPln(aA, aB, aC, aD);
+
+ gp_Pnt2d aRes = ProjLib::Project(aPln, *MY_PNT);
+ return std::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(aRes.X(), aRes.Y()));
+}
class GeomAPI_XYZ;
class GeomAPI_Pnt2d;
class GeomAPI_Dir;
+class GeomAPI_Pln;
/**\class GeomAPI_Pnt
* \ingroup DataModel
const std::shared_ptr<GeomAPI_Dir>& theDirX,
const std::shared_ptr<GeomAPI_Dir>& theDirY);
+ /// Projects a point to the plane defined by the origin and 2 axes vectors in this plane
+ std::shared_ptr<GeomAPI_Pnt2d> to2D(const std::shared_ptr<GeomAPI_Pln>& thePln) const;
+
/// Translates the point along direction theDir on distance theDist
void translate(const std::shared_ptr<GeomAPI_Dir>& theDir, double theDist);
};
#include<GeomAPI_Shape.h>
#include <TopoDS_Shape.hxx>
+#include <BRepBndLib.hxx>
+#include <Bnd_Box.hxx>
#define MY_SHAPE static_cast<TopoDS_Shape*>(myImpl)
const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
return aShape.ShapeType() == TopAbs_FACE;
}
+
+bool GeomAPI_Shape::computeSize(double& theXmin, double& theYmin, double& theZmin,
+ double& theXmax, double& theYmax, double& theZmax) const
+{
+ const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
+ if (aShape.IsNull())
+ return false;
+ Bnd_Box aBndBox;
+ BRepBndLib::Add(aShape, aBndBox);
+ aBndBox.Get(theXmin, theYmin, theZmin, theXmax, theYmax, theZmax);
+ return true;
+}
\ No newline at end of file
/// Returns whether the shape is a face
virtual bool isFace() const;
+ /// Computes boundary dimensions of the shape
+ /// Returns False if it is not possible
+ bool computeSize(double& theXmin, double& theYmin, double& theZmin,
+ double& theXmax, double& theYmax, double& theZmax) const;
+
};
//! Pointer on list of shapes
aResult = std::shared_ptr<GeomAPI_Pln>(new GeomAPI_Pln(aA, aB, aC, aD));
return aResult;
}
+
+
+std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_FaceBuilder::
+ planarFace(std::shared_ptr<GeomAPI_Pln> thePlane,
+ double theX, double theY,
+ double theWidth, double theHeight)
+{
+ double aA, aB, aC, aD;
+ thePlane->coefficients(aA, aB, aC, aD);
+ gp_Pln aPlane(aA, aB, aC, aD);
+
+ // half of the size in each direction from the center
+ BRepBuilderAPI_MakeFace aFaceBuilder(aPlane, theX, theX + theWidth,
+ theY, theY + theHeight);
+ std::shared_ptr<GeomAPI_Shape> aRes(new GeomAPI_Shape);
+ aRes->setImpl(new TopoDS_Shape(aFaceBuilder.Face()));
+ return aRes;
+}
\ No newline at end of file
/// Returns the plane of the planar face. If it is not planar, returns empty ptr.
static std::shared_ptr<GeomAPI_Pln> plane(std::shared_ptr<GeomAPI_Shape> theFace);
+
+ /// Creates a planar face by given plane, left lower point and size.
+ static std::shared_ptr<GeomAPI_Shape> planarFace(std::shared_ptr<GeomAPI_Pln> thePlane,
+ double theX, double theY,
+ double theWidth, double theHeight);
};
#endif