Added option to create plane by line and point.
const ModelHighAPI_Double & theDistance)
{
fillAttribute("PlaneByFaceAndDistance", mycreationMethod);
- fillAttribute(theFace, myface);
+ fillAttribute(theFace, myplane);
fillAttribute(theDistance, mydistance);
execute();
virtual ~ConstructionAPI_Plane();
INTERFACE_7(ConstructionPlugin_Plane::ID(),
- creationMethod, ConstructionPlugin_Plane::METHOD(), ModelAPI_AttributeString, /** Creation method */,
- face, ConstructionPlugin_Plane::FACE(), ModelAPI_AttributeSelection, /** Plane face */,
- distance, ConstructionPlugin_Plane::DISTANCE(), ModelAPI_AttributeDouble, /** Distance */,
+ creationMethod, ConstructionPlugin_Plane::CREATION_METHOD(), ModelAPI_AttributeString, /** Creation method */,
A, ConstructionPlugin_Plane::A(), ModelAPI_AttributeDouble, /** Parameter A for general equation */,
B, ConstructionPlugin_Plane::B(), ModelAPI_AttributeDouble, /** Parameter B for general equation */,
C, ConstructionPlugin_Plane::C(), ModelAPI_AttributeDouble, /** Parameter C for general equation */,
- D, ConstructionPlugin_Plane::D(), ModelAPI_AttributeDouble, /** Parameter D for general equation */
- )
+ D, ConstructionPlugin_Plane::D(), ModelAPI_AttributeDouble, /** Parameter D for general equation */,
+ plane, ConstructionPlugin_Plane::PLANE(), ModelAPI_AttributeSelection, /** Plane face */,
+ distance, ConstructionPlugin_Plane::DISTANCE(), ModelAPI_AttributeDouble, /** Distance */
+ )
/// Set face and distance
CONSTRUCTIONAPI_EXPORT
- void setFaceAndDistance(const ModelHighAPI_Selection & theFace,
- const ModelHighAPI_Double & theDistance);
+ void setFaceAndDistance(const ModelHighAPI_Selection& theFace,
+ const ModelHighAPI_Double& theDistance);
/// Set GeneralEquation parameters of the feature
CONSTRUCTIONAPI_EXPORT
#include <Config_PropManager.h>
-#include <ModelAPI_AttributeSelection.h>
+#include <GeomAlgoAPI_FaceBuilder.h>
+#include <GeomAlgoAPI_ShapeTools.h>
+
+#include <GeomAPI_Edge.h>
+#include <GeomAPI_Pln.h>
+#include <GeomAPI_Pnt.h>
+#include <GeomAPI_Pnt2d.h>
+#include <GeomAPI_Vertex.h>
+
#include <ModelAPI_AttributeDouble.h>
-#include <ModelAPI_ResultConstruction.h>
#include <ModelAPI_AttributeIntArray.h>
+#include <ModelAPI_AttributeSelection.h>
#include <ModelAPI_AttributeString.h>
+#include <ModelAPI_ResultConstruction.h>
#include <ModelAPI_Session.h>
#include <ModelAPI_Validator.h>
-#include <GeomAlgoAPI_FaceBuilder.h>
-#include <GeomAPI_Pnt2d.h>
+static GeomShapePtr faceByThreeVertices(const std::shared_ptr<GeomAPI_Vertex> theV1,
+ const std::shared_ptr<GeomAPI_Vertex> theV2,
+ const std::shared_ptr<GeomAPI_Vertex> theV3);
+//==================================================================================================
ConstructionPlugin_Plane::ConstructionPlugin_Plane()
{
}
+//==================================================================================================
void ConstructionPlugin_Plane::initAttributes()
{
- data()->addAttribute(ConstructionPlugin_Plane::METHOD(), ModelAPI_AttributeString::typeId());
- // Face & Distance
- data()->addAttribute(ConstructionPlugin_Plane::FACE(), ModelAPI_AttributeSelection::typeId());
- data()->addAttribute(ConstructionPlugin_Plane::DISTANCE(), ModelAPI_AttributeDouble::typeId());
- // General equation
- data()->addAttribute(ConstructionPlugin_Plane::A(), ModelAPI_AttributeDouble::typeId());
- data()->addAttribute(ConstructionPlugin_Plane::B(), ModelAPI_AttributeDouble::typeId());
- data()->addAttribute(ConstructionPlugin_Plane::C(), ModelAPI_AttributeDouble::typeId());
- data()->addAttribute(ConstructionPlugin_Plane::D(), ModelAPI_AttributeDouble::typeId());
-
- ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), ConstructionPlugin_Plane::A());
- ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), ConstructionPlugin_Plane::B());
- ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), ConstructionPlugin_Plane::C());
- ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), ConstructionPlugin_Plane::D());
+ data()->addAttribute(ConstructionPlugin_Plane::CREATION_METHOD(), ModelAPI_AttributeString::typeId());
+
+ // By general equation.
+ data()->addAttribute(A(), ModelAPI_AttributeDouble::typeId());
+ data()->addAttribute(B(), ModelAPI_AttributeDouble::typeId());
+ data()->addAttribute(C(), ModelAPI_AttributeDouble::typeId());
+ data()->addAttribute(D(), ModelAPI_AttributeDouble::typeId());
+ ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), A());
+ ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), B());
+ ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), C());
+ ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), D());
+
+ // By three points.
+ data()->addAttribute(POINT1(), ModelAPI_AttributeSelection::typeId());
+ data()->addAttribute(POINT2(), ModelAPI_AttributeSelection::typeId());
+ data()->addAttribute(POINT3(), ModelAPI_AttributeSelection::typeId());
+
+ // By line and point.
+ data()->addAttribute(LINE(), ModelAPI_AttributeSelection::typeId());
+ data()->addAttribute(POINT(), ModelAPI_AttributeSelection::typeId());
+
+ // By other plane.
+ data()->addAttribute(CREATION_METHOD_BY_OTHER_PLANE_OPTION(), ModelAPI_AttributeString::typeId());
+ data()->addAttribute(PLANE(), ModelAPI_AttributeSelection::typeId());
+ data()->addAttribute(DISTANCE(), ModelAPI_AttributeDouble::typeId());
}
+//==================================================================================================
void ConstructionPlugin_Plane::execute()
{
- AttributeStringPtr aMethodTypeAttr = string(ConstructionPlugin_Plane::METHOD());
- std::string aMethodType = aMethodTypeAttr->value();
- std::shared_ptr<GeomAPI_Shape> aPlaneFace;
- if (aMethodType == "PlaneByFaceAndDistance") {
- aPlaneFace = createPlaneByFaceAndDistance();
- } else if (aMethodType == "PlaneByGeneralEquation") {
- aPlaneFace = createPlaneByGeneralEquation();
+ GeomShapePtr aShape;
+
+ std::string aCreationMethod = string(CREATION_METHOD())->value();
+ if(aCreationMethod == CREATION_METHOD_BY_GENERAL_EQUATION()) {
+ aShape = createByGeneralEquation();
+ } else if(aCreationMethod == CREATION_METHOD_BY_THREE_POINTS()) {
+ aShape = createByThreePoints();
+ } else if(aCreationMethod == CREATION_METHOD_BY_LINE_AND_POINT()) {
+ aShape = createByLineAndPoint();
+ } else if(aCreationMethod == CREATION_METHOD_BY_OTHER_PLANE()) {
+ std::string aCreationMethodOption = string(CREATION_METHOD_BY_OTHER_PLANE_OPTION())->value();
+ if(aCreationMethodOption == CREATION_METHOD_BY_DISTANCE_FROM_OTHER()) {
+ aShape = createByDistanceFromOther();
+ }
}
- if (!aPlaneFace.get())
+
+
+ if(!aShape.get()) {
return;
+ }
+
ResultConstructionPtr aConstr = document()->createConstruction(data());
aConstr->setInfinite(true);
- aConstr->setShape(aPlaneFace);
+ aConstr->setShape(aShape);
setResult(aConstr);
}
+//==================================================================================================
bool ConstructionPlugin_Plane::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs)
{
return isCustomized;
}
-std::shared_ptr<GeomAPI_Shape> ConstructionPlugin_Plane::createPlaneByFaceAndDistance()
+//==================================================================================================
+std::shared_ptr<GeomAPI_Shape> ConstructionPlugin_Plane::createByGeneralEquation()
{
- AttributeSelectionPtr aFaceAttr = data()->selection(ConstructionPlugin_Plane::FACE());
+ AttributeDoublePtr anAttrA = real(ConstructionPlugin_Plane::A());
+ AttributeDoublePtr anAttrB = real(ConstructionPlugin_Plane::B());
+ AttributeDoublePtr anAttrC = real(ConstructionPlugin_Plane::C());
+ AttributeDoublePtr anAttrD = real(ConstructionPlugin_Plane::D());
+ std::shared_ptr<GeomAPI_Shape> aPlaneFace;
+ if ((anAttrA.get() != NULL) && (anAttrB.get() != NULL) &&
+ (anAttrC.get() != NULL) && (anAttrD.get() != NULL) &&
+ anAttrA->isInitialized() && anAttrB->isInitialized() &&
+ anAttrC->isInitialized() && anAttrD->isInitialized() ) {
+ double aA = anAttrA->value(), aB = anAttrB->value(),
+ aC = anAttrC->value(), aD = anAttrD->value();
+ std::shared_ptr<GeomAPI_Pln> aPlane =
+ std::shared_ptr<GeomAPI_Pln>(new GeomAPI_Pln(aA, aB, aC, aD));
+ std::string kDefaultPlaneSize = "200";
+ double aSize = Config_PropManager::integer("Sketch planes", "planes_size", kDefaultPlaneSize);
+ aSize *= 4.;
+ aPlaneFace = GeomAlgoAPI_FaceBuilder::squareFace(aPlane, aSize);
+ }
+ return aPlaneFace;
+}
+
+//==================================================================================================
+std::shared_ptr<GeomAPI_Shape> ConstructionPlugin_Plane::createByThreePoints()
+{
+ // Get first point.
+ AttributeSelectionPtr aPointSelection1 = selection(POINT1());
+ GeomShapePtr aPointShape1 = aPointSelection1->value();
+ if(!aPointShape1.get()) {
+ aPointShape1 = aPointSelection1->context()->shape();
+ }
+ std::shared_ptr<GeomAPI_Vertex> aVertex1(new GeomAPI_Vertex(aPointShape1));
+
+ // Get second point.
+ AttributeSelectionPtr aPointSelection2 = selection(POINT2());
+ GeomShapePtr aPointShape2 = aPointSelection2->value();
+ if(!aPointShape2.get()) {
+ aPointShape2 = aPointSelection2->context()->shape();
+ }
+ std::shared_ptr<GeomAPI_Vertex> aVertex2(new GeomAPI_Vertex(aPointShape2));
+
+ // Get third point.
+ AttributeSelectionPtr aPointSelection3 = selection(POINT3());
+ GeomShapePtr aPointShape3 = aPointSelection3->value();
+ if(!aPointShape3.get()) {
+ aPointShape3 = aPointSelection3->context()->shape();
+ }
+ std::shared_ptr<GeomAPI_Vertex> aVertex3(new GeomAPI_Vertex(aPointShape3));
+
+ GeomShapePtr aRes = faceByThreeVertices(aVertex1, aVertex2, aVertex3);
+
+ return aRes;
+}
+
+//==================================================================================================
+std::shared_ptr<GeomAPI_Shape> ConstructionPlugin_Plane::createByLineAndPoint()
+{
+ // Get edge.
+ AttributeSelectionPtr anEdgeSelection = selection(LINE());
+ GeomShapePtr aLineShape = anEdgeSelection->value();
+ if(!aLineShape.get()) {
+ aLineShape = anEdgeSelection->context()->shape();
+ }
+ std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge(aLineShape));
+ std::shared_ptr<GeomAPI_Vertex> aV1, aV2;
+ GeomAlgoAPI_ShapeTools::findBounds(anEdge, aV1, aV2);
+
+
+ // Get point.
+ AttributeSelectionPtr aPointSelection = selection(POINT());
+ GeomShapePtr aPointShape = aPointSelection->value();
+ if(!aPointShape.get()) {
+ aPointShape = aPointSelection->context()->shape();
+ }
+ std::shared_ptr<GeomAPI_Vertex> aVertex(new GeomAPI_Vertex(aPointShape));
+
+ GeomShapePtr aRes = faceByThreeVertices(aV1, aV2, aVertex);
+
+ return aRes;
+}
+
+//==================================================================================================
+std::shared_ptr<GeomAPI_Shape> ConstructionPlugin_Plane::createByDistanceFromOther()
+{
+ AttributeSelectionPtr aFaceAttr = data()->selection(ConstructionPlugin_Plane::PLANE());
AttributeDoublePtr aDistAttr = data()->real(ConstructionPlugin_Plane::DISTANCE());
std::shared_ptr<GeomAPI_Shape> aPlane;
if ((aFaceAttr.get() != NULL) &&
aShape = aFaceAttr->context()->shape();
}
- if (aShape.get() != NULL) {
- std::shared_ptr<GeomAPI_Pln> aPln = GeomAlgoAPI_FaceBuilder::plane(aShape);
- std::shared_ptr<GeomAPI_Pnt> aOrig = aPln->location();
- 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);
-
- // use all 8 points of the bounding box to find the 2D bounds
- bool isFirst = true;
- double aMinX2d, aMaxX2d, aMinY2d, aMaxY2d;
- for(int aXIsMin = 0; aXIsMin < 2; aXIsMin++) {
- for(int aYIsMin = 0; aYIsMin < 2; aYIsMin++) {
- for(int aZIsMin = 0; aZIsMin < 2; aZIsMin++) {
- std::shared_ptr<GeomAPI_Pnt> aPnt = std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(
- aXIsMin ? aXmin : aXmax, aYIsMin ? aYmin : aYmax, aZIsMin ? Zmin : Zmax));
- std::shared_ptr<GeomAPI_Pnt2d> aPnt2d = aPnt->to2D(aNewPln);
- if (isFirst || aPnt2d->x() < aMinX2d)
- aMinX2d = aPnt2d->x();
- if (isFirst || aPnt2d->y() < aMinY2d)
- aMinY2d = aPnt2d->y();
- if (isFirst || aPnt2d->x() > aMaxX2d)
- aMaxX2d = aPnt2d->x();
- if (isFirst || aPnt2d->y() > aMaxY2d)
- aMaxY2d = aPnt2d->y();
- if (isFirst)
- isFirst = !isFirst;
- }
+ if(!aShape.get()) {
+ return aPlane;
+ }
+
+ std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(aShape));
+
+ std::shared_ptr<GeomAPI_Pln> aPln = GeomAlgoAPI_FaceBuilder::plane(aFace);
+ std::shared_ptr<GeomAPI_Pnt> aOrig = aPln->location();
+ std::shared_ptr<GeomAPI_Dir> aDir = aPln->direction();
+
+ aOrig->translate(aDir, aDist);
+ std::shared_ptr<GeomAPI_Pln> aNewPln(new GeomAPI_Pln(aOrig, aDir));
+
+ // Create rectangular face close to the selected
+ double aXmin, aYmin, Zmin, aXmax, aYmax, Zmax;
+ aFace->computeSize(aXmin, aYmin, Zmin, aXmax, aYmax, Zmax);
+
+ // use all 8 points of the bounding box to find the 2D bounds
+ bool isFirst = true;
+ double aMinX2d, aMaxX2d, aMinY2d, aMaxY2d;
+ for(int aXIsMin = 0; aXIsMin < 2; aXIsMin++) {
+ for(int aYIsMin = 0; aYIsMin < 2; aYIsMin++) {
+ for(int aZIsMin = 0; aZIsMin < 2; aZIsMin++) {
+ std::shared_ptr<GeomAPI_Pnt> aPnt(new GeomAPI_Pnt(
+ aXIsMin ? aXmin : aXmax, aYIsMin ? aYmin : aYmax, aZIsMin ? Zmin : Zmax));
+ std::shared_ptr<GeomAPI_Pnt2d> aPnt2d = aPnt->to2D(aNewPln);
+ if (isFirst || aPnt2d->x() < aMinX2d)
+ aMinX2d = aPnt2d->x();
+ if (isFirst || aPnt2d->y() < aMinY2d)
+ aMinY2d = aPnt2d->y();
+ if (isFirst || aPnt2d->x() > aMaxX2d)
+ aMaxX2d = aPnt2d->x();
+ if (isFirst || aPnt2d->y() > aMaxY2d)
+ aMaxY2d = aPnt2d->y();
+ if (isFirst)
+ isFirst = !isFirst;
}
}
- double aWgap = (aMaxX2d - aMinX2d) * 0.1;
- double aHgap = (aMaxY2d - aMinY2d) * 0.1;
- aPlane = GeomAlgoAPI_FaceBuilder::planarFace(aNewPln,
- aMinX2d - aWgap, aMinY2d - aHgap, aMaxX2d - aMinX2d + 2. * aWgap, aMaxY2d - aMinY2d + 2. * aHgap);
}
+ double aWgap = (aMaxX2d - aMinX2d) * 0.1;
+ double aHgap = (aMaxY2d - aMinY2d) * 0.1;
+ aPlane = GeomAlgoAPI_FaceBuilder::planarFace(aNewPln,
+ aMinX2d - aWgap, aMinY2d - aHgap, aMaxX2d - aMinX2d + 2. * aWgap, aMaxY2d - aMinY2d + 2. * aHgap);
+
}
return aPlane;
}
-std::shared_ptr<GeomAPI_Shape> ConstructionPlugin_Plane::createPlaneByGeneralEquation()
+//==================================================================================================
+GeomShapePtr faceByThreeVertices(const std::shared_ptr<GeomAPI_Vertex> theV1,
+ const std::shared_ptr<GeomAPI_Vertex> theV2,
+ const std::shared_ptr<GeomAPI_Vertex> theV3)
{
- AttributeDoublePtr anAttrA = real(ConstructionPlugin_Plane::A());
- AttributeDoublePtr anAttrB = real(ConstructionPlugin_Plane::B());
- AttributeDoublePtr anAttrC = real(ConstructionPlugin_Plane::C());
- AttributeDoublePtr anAttrD = real(ConstructionPlugin_Plane::D());
- std::shared_ptr<GeomAPI_Shape> aPlaneFace;
- if ((anAttrA.get() != NULL) && (anAttrB.get() != NULL) &&
- (anAttrC.get() != NULL) && (anAttrD.get() != NULL) &&
- anAttrA->isInitialized() && anAttrB->isInitialized() &&
- anAttrC->isInitialized() && anAttrD->isInitialized() ) {
- double aA = anAttrA->value(), aB = anAttrB->value(),
- aC = anAttrC->value(), aD = anAttrD->value();
- std::shared_ptr<GeomAPI_Pln> aPlane =
- std::shared_ptr<GeomAPI_Pln>(new GeomAPI_Pln(aA, aB, aC, aD));
- std::string kDefaultPlaneSize = "200";
- double aSize = Config_PropManager::integer("Sketch planes", "planes_size", kDefaultPlaneSize);
- aSize *= 4.;
- aPlaneFace = GeomAlgoAPI_FaceBuilder::square(aPlane, aSize);
- }
- return aPlaneFace;
-}
+ std::shared_ptr<GeomAPI_Face> aFace = GeomAlgoAPI_FaceBuilder::planarFaceByThreeVertices(theV1, theV2, theV3);
+ ListOfShape anObjects;
+ anObjects.push_back(theV1);
+ anObjects.push_back(theV2);
+ anObjects.push_back(theV3);
+ std::list<std::shared_ptr<GeomAPI_Pnt> > aBoundingPoints = GeomAlgoAPI_ShapeTools::getBoundingBox(anObjects, 1.0);
+ GeomShapePtr aRes = GeomAlgoAPI_ShapeTools::fitPlaneToBox(aFace, aBoundingPoints);
+
+ return aRes;
+}
#define ConstructionPlugin_Plane_H
#include "ConstructionPlugin.h"
+
#include <ModelAPI_Feature.h>
#include <ModelAPI_Result.h>
#include <GeomAPI_ICustomPrs.h>
-
-
-/**\class ConstructionPlugin_Plane
- * \ingroup Plugins
- * \brief Feature for creation of the new planar surface in PartSet.
- */
-class ConstructionPlugin_Plane : public ModelAPI_Feature, public GeomAPI_ICustomPrs
+/// \class ConstructionPlugin_Plane
+/// \ingroup Plugins
+/// \brief Feature for creation of the new planar surface in PartSet.
+class ConstructionPlugin_Plane: public ModelAPI_Feature, public GeomAPI_ICustomPrs
{
- public:
- /// Returns the kind of a feature
+public:
+ /// \return the kind of a feature.
CONSTRUCTIONPLUGIN_EXPORT virtual const std::string& getKind()
{
static std::string MY_KIND = ConstructionPlugin_Plane::ID();
return MY_KIND;
}
- /// default color for a plane
+ /// Default color for a plane.
inline static const std::string& DEFAULT_COLOR()
{
static const std::string CONSTRUCTION_PLANE_COLOR("150,150,180");
return CONSTRUCTION_PLANE_COLOR;
}
- /// Plane kind
+ /// Plane kind.
inline static const std::string& ID()
{
static const std::string CONSTRUCTION_PLANE_KIND("Plane");
return CONSTRUCTION_PLANE_KIND;
}
- /// attribute name for first point
- inline static const std::string& METHOD()
+ /// Attribute name for creation method.
+ inline static const std::string& CREATION_METHOD()
+ {
+ static const std::string MY_CREATION_METHOD_ID("creation_method");
+ return MY_CREATION_METHOD_ID;
+ }
+
+ /// Attribute name for creation method.
+ inline static const std::string& CREATION_METHOD_BY_GENERAL_EQUATION()
+ {
+ static const std::string MY_CREATION_METHOD_ID("by_general_equation");
+ return MY_CREATION_METHOD_ID;
+ }
+
+ /// Attribute name for creation method.
+ inline static const std::string& CREATION_METHOD_BY_THREE_POINTS()
+ {
+ static const std::string MY_CREATION_METHOD_ID("by_three_points");
+ return MY_CREATION_METHOD_ID;
+ }
+
+ /// Attribute name for creation method.
+ inline static const std::string& CREATION_METHOD_BY_LINE_AND_POINT()
+ {
+ static const std::string MY_CREATION_METHOD_ID("by_line_and_point");
+ return MY_CREATION_METHOD_ID;
+ }
+
+ /// Attribute name for creation method.
+ inline static const std::string& CREATION_METHOD_BY_OTHER_PLANE()
+ {
+ static const std::string MY_CREATION_METHOD_ID("by_other_plane");
+ return MY_CREATION_METHOD_ID;
+ }
+
+ /// Attribute name for creation method.
+ inline static const std::string& CREATION_METHOD_BY_OTHER_PLANE_OPTION()
+ {
+ static const std::string MY_CREATION_METHOD_ID("by_other_plane_option");
+ return MY_CREATION_METHOD_ID;
+ }
+
+ /// Attribute name for creation method.
+ inline static const std::string& CREATION_METHOD_BY_DISTANCE_FROM_OTHER()
+ {
+ static const std::string MY_CREATION_METHOD_ID("by_distance_from_other");
+ return MY_CREATION_METHOD_ID;
+ }
+
+ /// Attribute name for creation method.
+ inline static const std::string& CREATION_METHOD_BY_COINCIDENT_TO_POINT()
{
- static const std::string METHOD_ATTR("CreationMethod");
- return METHOD_ATTR;
+ static const std::string MY_CREATION_METHOD_ID("by_coincident_to_point");
+ return MY_CREATION_METHOD_ID;
}
- /// attribute name for base face
- inline static const std::string& FACE()
+ /// Attribute name for creation method.
+ inline static const std::string& CREATION_METHOD_BY_ROTATION()
{
- static const std::string FACE_ATTR("planeFace");
- return FACE_ATTR;
+ static const std::string MY_CREATION_METHOD_ID("by_rotation");
+ return MY_CREATION_METHOD_ID;
}
- /// attribute name for distance
+
+ /// Attribute name for creation method.
+ inline static const std::string& CREATION_METHOD_BY_TWO_PARALLEL_PLANES()
+ {
+ static const std::string MY_CREATION_METHOD_ID("by_two_parallel_planes");
+ return MY_CREATION_METHOD_ID;
+ }
+
+ /// Attribute name for first point.
+ inline static const std::string& POINT1()
+ {
+ static const std::string ATTR_ID("point1");
+ return ATTR_ID;
+ }
+
+ /// Attribute name for second point.
+ inline static const std::string& POINT2()
+ {
+ static const std::string ATTR_ID("point2");
+ return ATTR_ID;
+ }
+
+ /// Attribute name for third point.
+ inline static const std::string& POINT3()
+ {
+ static const std::string ATTR_ID("point3");
+ return ATTR_ID;
+ }
+
+ /// Attribute name for line.
+ inline static const std::string& LINE()
+ {
+ static const std::string ATTR_ID("line");
+ return ATTR_ID;
+ }
+
+ /// Attribute name for point.
+ inline static const std::string& POINT()
+ {
+ static const std::string ATTR_ID("point");
+ return ATTR_ID;
+ }
+
+ /// Attribute name for selected plane.
+ inline static const std::string& PLANE()
+ {
+ static const std::string ATTR_ID("plane");
+ return ATTR_ID;
+ }
+
+ /// Attribute name for distance.
inline static const std::string& DISTANCE()
{
- static const std::string DISTANCE_ATTR("distance");
- return DISTANCE_ATTR;
+ static const std::string ATTR_ID("distance");
+ return ATTR_ID;
}
- /// the a parameter for the general equation of a plane (ax+by+cz+d=0)
+ /// Attribute name for a parameter for the general equation of a plane (ax+by+cz+d=0)
inline static const std::string& A()
{
- static const std::string PARAM_A_ATTR("A");
- return PARAM_A_ATTR;
+ static const std::string ATTR_ID("A");
+ return ATTR_ID;
}
- /// the b parameter for the general equation of a plane (ax+by+cz+d=0)
+ /// Attribute name for b parameter for the general equation of a plane (ax+by+cz+d=0)
inline static const std::string& B()
{
- static const std::string PARAM_B_ATTR("B");
- return PARAM_B_ATTR;
+ static const std::string ATTR_ID("B");
+ return ATTR_ID;
}
- /// the c parameter for the general equation of a plane (ax+by+cz+d=0)
+ /// Attribute name for c parameter for the general equation of a plane (ax+by+cz+d=0)
inline static const std::string& C()
{
- static const std::string PARAM_C_ATTR("C");
- return PARAM_C_ATTR;
+ static const std::string ATTR_ID("C");
+ return ATTR_ID;
}
- /// the d parameter for the general equation of a plane (ax+by+cz+d=0)
+ /// Attribute name for d parameter for the general equation of a plane (ax+by+cz+d=0)
inline static const std::string& D()
{
- static const std::string PARAM_D_ATTR("D");
- return PARAM_D_ATTR;
+ static const std::string ATTR_ID("D");
+ return ATTR_ID;
}
/// Creates a new part document if needed
virtual bool customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs);
- protected:
+protected:
+ /// Creates a new plane by general equation.
+ std::shared_ptr<GeomAPI_Shape> createByGeneralEquation();
+ std::shared_ptr<GeomAPI_Shape> createByThreePoints();
+ std::shared_ptr<GeomAPI_Shape> createByLineAndPoint();
/// Creates a new plane by copy of face plane with translation along the normal
/// to the specified distance.
- std::shared_ptr<GeomAPI_Shape> createPlaneByFaceAndDistance();
- /// Creates a new plane by general equation.
- std::shared_ptr<GeomAPI_Shape> createPlaneByGeneralEquation();
+ std::shared_ptr<GeomAPI_Shape> createByDistanceFromOther();
};
#endif
new ConstructionPlugin_ValidatorPointLines());
aFactory->registerValidator("ConstructionPlugin_ValidatorPointLineAndPlaneNotParallel",
new ConstructionPlugin_ValidatorPointLineAndPlaneNotParallel());
+ aFactory->registerValidator("ConstructionPlugin_ValidatorPlaneThreePoints",
+ new ConstructionPlugin_ValidatorPlaneThreePoints());
+ aFactory->registerValidator("ConstructionPlugin_ValidatorPlaneLinePoint",
+ new ConstructionPlugin_ValidatorPlaneLinePoint());
// register this plugin
ModelAPI_Session::get()->registerPlugin(this);
//==================================================================================================
void ConstructionPlugin_Point::initAttributes()
{
+ data()->addAttribute(CREATION_METHOD(), ModelAPI_AttributeString::typeId());
+
data()->addAttribute(X(), ModelAPI_AttributeDouble::typeId());
data()->addAttribute(Y(), ModelAPI_AttributeDouble::typeId());
data()->addAttribute(Z(), ModelAPI_AttributeDouble::typeId());
- data()->addAttribute(CREATION_METHOD(), ModelAPI_AttributeString::typeId());
-
data()->addAttribute(EDGE(), ModelAPI_AttributeSelection::typeId());
data()->addAttribute(DISTANCE_VALUE(), ModelAPI_AttributeDouble::typeId());
data()->addAttribute(DISTANCE_PERCENT(), ModelAPI_AttributeBoolean::typeId());
aShape = createByLineAndPlaneIntersection();
}
- if(aShape.get()) {
- std::shared_ptr<ModelAPI_ResultConstruction> aConstr = document()->createConstruction(data());
- aConstr->setShape(aShape);
- setResult(aConstr);
+ if(!aShape.get()) {
+ return;
}
+
+ std::shared_ptr<ModelAPI_ResultConstruction> aConstr = document()->createConstruction(data());
+ aConstr->setShape(aShape);
+ setResult(aConstr);
}
//==================================================================================================
}
std::shared_ptr<GeomAPI_Edge> aFirstEdge(new GeomAPI_Edge(aFirstLineShape));
- // Get first line.
+ // Get second line.
AttributeSelectionPtr aSecondLineSelection= selection(SECOND_LINE());
GeomShapePtr aSecondLineShape = aSecondLineSelection->value();
if(!aSecondLineShape.get()) {
#include <GeomAPI_Face.h>
#include <GeomAPI_Lin.h>
#include <GeomAPI_Pln.h>
+#include <GeomAPI_Vertex.h>
#include <ModelAPI_AttributeSelection.h>
static std::shared_ptr<GeomAPI_Lin> getLin(const GeomShapePtr theShape);
static std::shared_ptr<GeomAPI_Pln> getPln(const GeomShapePtr theShape);
+static std::shared_ptr<GeomAPI_Pnt> getPnt(const GeomShapePtr theShape);
//==================================================================================================
bool ConstructionPlugin_ValidatorPointLines::isValid(const AttributePtr& theAttribute,
return true;
}
-static std::shared_ptr<GeomAPI_Lin> getLin(const GeomShapePtr theShape)
+//==================================================================================================
+bool ConstructionPlugin_ValidatorPlaneThreePoints::isValid(const AttributePtr& theAttribute,
+ const std::list<std::string>& theArguments,
+ Events_InfoMessage& theError) const
+{
+ FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
+
+ AttributeSelectionPtr aPointAttribute1 = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
+ AttributeSelectionPtr aPointAttribute2 = aFeature->selection(theArguments.front());
+ AttributeSelectionPtr aPointAttribute3 = aFeature->selection(theArguments.back());
+
+ GeomShapePtr aPointShape1 = aPointAttribute1->value();
+ ResultPtr aContext1 = aPointAttribute1->context();
+ if(!aContext1.get()) {
+ theError = "One of the attribute not initialized.";
+ return false;
+ }
+ if(!aPointShape1.get()) {
+ aPointShape1 = aContext1->shape();
+ }
+ if(!aPointShape1->isVertex()) {
+ theError = "One of the selected shapes not a vertex.";
+ return false;
+ }
+
+ GeomShapePtr aPointShape2 = aPointAttribute2->value();
+ ResultPtr aContext2 = aPointAttribute2->context();
+ if(!aContext2.get()) {
+ return true;
+ }
+ if(!aPointShape2.get()) {
+ aPointShape2 = aContext2->shape();
+ }
+ if(!aPointShape2->isVertex()) {
+ theError = "One of the selected shapes not a vertex.";
+ return false;
+ }
+
+ GeomShapePtr aPointShape3 = aPointAttribute3->value();
+ ResultPtr aContext3 = aPointAttribute3->context();
+ if(!aContext3.get()) {
+ return true;
+ }
+ if(!aPointShape3.get()) {
+ aPointShape3 = aContext3->shape();
+ }
+ if(!aPointShape3->isVertex()) {
+ theError = "One of the selected shapes not a vertex.";
+ return false;
+ }
+
+ std::shared_ptr<GeomAPI_Vertex> aVertex1(new GeomAPI_Vertex(aPointShape1));
+ std::shared_ptr<GeomAPI_Vertex> aVertex2(new GeomAPI_Vertex(aPointShape2));
+ std::shared_ptr<GeomAPI_Vertex> aVertex3(new GeomAPI_Vertex(aPointShape3));
+
+ std::shared_ptr<GeomAPI_Pnt> aPnt1 = aVertex1->point();
+ std::shared_ptr<GeomAPI_Pnt> aPnt2 = aVertex2->point();
+ std::shared_ptr<GeomAPI_Pnt> aPnt3 = aVertex3->point();
+
+ std::shared_ptr<GeomAPI_Lin> aLin(new GeomAPI_Lin(aPnt1, aPnt2));
+
+ if(aLin->contains(aPnt3)) {
+ theError = "Selected points lie on a line.";
+ return false;
+ }
+
+ return true;
+}
+
+//==================================================================================================
+bool ConstructionPlugin_ValidatorPlaneLinePoint::isValid(
+ const AttributePtr& theAttribute,
+ const std::list<std::string>& theArguments,
+ Events_InfoMessage& theError) const
+{
+ FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
+
+ AttributeSelectionPtr anAttribute1 = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
+ AttributeSelectionPtr anAttribute2 = aFeature->selection(theArguments.front());
+
+ std::shared_ptr<GeomAPI_Lin> aLin;
+ std::shared_ptr<GeomAPI_Pnt> aPnt;
+
+ GeomShapePtr aShape1 = anAttribute1->value();
+ ResultPtr aContext1 = anAttribute1->context();
+ if(!aContext1.get()) {
+ theError = "One of the attribute not initialized.";
+ return false;
+ }
+ if(!aShape1.get()) {
+ aShape1 = aContext1->shape();
+ }
+
+ GeomShapePtr aShape2 = anAttribute2->value();
+ ResultPtr aContext2 = anAttribute2->context();
+ if(!aContext2.get()) {
+ return true;
+ }
+ if(!aShape2.get()) {
+ aShape2 = aContext2->shape();
+ }
+
+ aLin = getLin(aShape1);
+ aPnt = getPnt(aShape2);
+ if(!aLin.get() || !aPnt.get()) {
+ aLin = getLin(aShape2);
+ aPnt = getPnt(aShape1);
+ }
+
+ if(!aLin.get() || !aPnt.get()) {
+ theError = "Wrong shape types selected.";
+ return false;
+ }
+
+ if(aLin->contains(aPnt)) {
+ theError = "Point lies on the line.";
+ return false;
+ }
+
+ return true;
+}
+
+std::shared_ptr<GeomAPI_Lin> getLin(const GeomShapePtr theShape)
{
std::shared_ptr<GeomAPI_Lin> aLin;
return aLin;
}
-static std::shared_ptr<GeomAPI_Pln> getPln(const GeomShapePtr theShape)
+std::shared_ptr<GeomAPI_Pln> getPln(const GeomShapePtr theShape)
{
std::shared_ptr<GeomAPI_Pln> aPln;
return aPln;
}
+
+std::shared_ptr<GeomAPI_Pnt> getPnt(const GeomShapePtr theShape)
+{
+ std::shared_ptr<GeomAPI_Pnt> aPnt;
+
+ if(!theShape->isVertex()) {
+ return aPnt;
+ }
+
+ std::shared_ptr<GeomAPI_Vertex> aVertex(new GeomAPI_Vertex(theShape));
+
+ aPnt = aVertex->point();
+
+ return aPnt;
+}
/// \class ConstructionPlugin_ValidatorPointLineAndPlaneNotParallel
/// \ingroup Validators
-/// \brief A validator for selection line and plane for point by intersection..
+/// \brief A validator for selection line and plane for point by intersection.
class ConstructionPlugin_ValidatorPointLineAndPlaneNotParallel: public ModelAPI_AttributeValidator
{
public:
Events_InfoMessage& theError) const;
};
+/// \class ConstructionPlugin_ValidatorPlaneThreePoints
+/// \ingroup Validators
+/// \brief A validator for selection three points for plane.
+class ConstructionPlugin_ValidatorPlaneThreePoints: public ModelAPI_AttributeValidator
+{
+public:
+ //! \return True if the attribute is valid.
+ //! \param[in] theAttribute the checked attribute.
+ //! \param[in] theArguments arguments of the attribute.
+ //! \param[out] theError error message.
+ virtual bool isValid(const AttributePtr& theAttribute,
+ const std::list<std::string>& theArguments,
+ Events_InfoMessage& theError) const;
+};
+
+/// \class ConstructionPlugin_ValidatorPlaneLinePoint
+/// \ingroup Validators
+/// \brief A validator for selection line and point for plane.
+class ConstructionPlugin_ValidatorPlaneLinePoint: public ModelAPI_AttributeValidator
+{
+public:
+ //! \return True if the attribute is valid.
+ //! \param[in] theAttribute the checked attribute.
+ //! \param[in] theArguments arguments of the attribute.
+ //! \param[out] theError error message.
+ virtual bool isValid(const AttributePtr& theAttribute,
+ const std::list<std::string>& theArguments,
+ Events_InfoMessage& theError) const;
+};
+
#endif
\ No newline at end of file
<!-- Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
<source>
- <switch id="CreationMethod">
- <case id="PlaneByFaceAndDistance" title="On some distance from a face">
+ <toolbox id="creation_method">
+ <box id="by_three_points"
+ title="By three points"
+ tooltip="Plane by three points."
+ icon="icons/Construction/plane_by_three_points_32x32.png">
+ <shape_selector id="point1"
+ label="1st point"
+ tooltip="First point."
+ icon="icons/Construction/point.png"
+ shape_types="vertex">
+ <validator id="ConstructionPlugin_ValidatorPlaneThreePoints" parameters="point2,point3"/>
+ </shape_selector>
+ <shape_selector id="point2"
+ label="2nd point"
+ tooltip="Second point."
+ icon="icons/Construction/point.png"
+ shape_types="vertex">
+ <validator id="ConstructionPlugin_ValidatorPlaneThreePoints" parameters="point1,point3"/>
+ </shape_selector>
+ <shape_selector id="point3"
+ label="3rd point"
+ tooltip="Third point."
+ icon="icons/Construction/point.png"
+ shape_types="vertex">
+ <validator id="ConstructionPlugin_ValidatorPlaneThreePoints" parameters="point1,point2"/>
+ </shape_selector>
+ </box>
+ <box id="by_line_and_point"
+ title="By line and point"
+ tooltip="Plane by line and point."
+ icon="icons/Construction/plane_by_line_and_point_32x32.png">
+ <shape_selector id="line"
+ label="Line"
+ tooltip="Select line."
+ icon="icons/Construction/edge.png"
+ shape_types="edge">
+ <validator id="GeomValidators_ShapeType" parameters="line"/>
+ <validator id="ConstructionPlugin_ValidatorPlaneLinePoint" parameters="point"/>
+ </shape_selector>
+ <shape_selector id="point"
+ label="Point"
+ tooltip="Select point."
+ icon="icons/Construction/point.png"
+ shape_types="vertex">
+ <validator id="ConstructionPlugin_ValidatorPlaneLinePoint" parameters="line"/>
+ </shape_selector>
+ </box>
+ <box id="by_other_plane"
+ title="By other plane"
+ tooltip="Plane by other plane with different options."
+ icon="icons/Construction/plane_by_other_plane_32x32.png">
+ <shape_selector id="plane"
+ label="Plane"
+ tooltip="Select a planar face."
+ icon="icons/Construction/face.png"
+ shape_types="face">
+ <validator id="GeomValidators_Face" parameters="plane"/>
+ </shape_selector>
+ <toolbox id="by_other_plane_option">
+ <box id="by_distance_from_other"
+ title="By distance from other"
+ tooltip="Plane by distance from other plane."
+ icon="icons/Construction/plane_by_distance_from_other_32x32.png">
+ <doublevalue id="distance"
+ label="Distance"
+ tooltip="Distance from selected face to plane."
+ icon="icons/Construction/distance_value.png"
+ default="0"/>
+ </box>
+ <box id="by_coincident_to_point"
+ title="By coincident to point"
+ tooltip="Plane by coincident to point."
+ icon="icons/Construction/plane_by_coincident_to_point_32x32.png">
+ </box>
+ <box id="by_rotation"
+ title="By rotation"
+ tooltip="Plane by rotation around axis."
+ icon="icons/Construction/plane_by_rotation_32x32.png">
+ </box>
+ </toolbox>
+ </box>
+ <box id="by_two_parallel_planes"
+ title="By two parallel planes"
+ tooltip="Plane equidistant from 2 parallel planes."
+ icon="icons/Construction/plane_by_two_parallel_planes_32x32.png">
+ </box>
+
+
+ <!--<box id="PlaneByFaceAndDistance" title="On some distance from a face">
<shape_selector id="planeFace"
label="Plane face"
tooltip="Select a planar face"
label="Distance"
tooltip="Distance from selected face to plane"
default="0" />
- </case>
- </switch>
+ </box>-->
+
+ </toolbox>
</source>
bool GeomAPI_Face::isEqual(std::shared_ptr<GeomAPI_Shape> theFace) const
{
+ if (!theFace.get())
+ return false;
+
if (!theFace->isFace())
return false;
return std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aResult.X(), aResult.Y(), aResult.Z()));
}
+bool GeomAPI_Lin::contains(const std::shared_ptr<GeomAPI_Pnt> thePoint, const double theLinearTolerance) const
+{
+ if(!thePoint.get()) {
+ return false;
+ }
+
+ return MY_LIN->Contains(thePoint->impl<gp_Pnt>(), theLinearTolerance) == Standard_True;
+}
+
bool GeomAPI_Lin::isParallel(const std::shared_ptr<GeomAPI_Lin> theLin) const
{
return MY_LIN->Direction().IsParallel(theLin->impl<gp_Lin>().Direction(), Precision::Confusion()) == Standard_True;
const std::shared_ptr<GeomAPI_Pnt> project(
const std::shared_ptr<GeomAPI_Pnt>& thePoint) const;
+ /// \return true if this line contains thePoint, that is, if the distance between thePoint and this line
+ /// is less than or equal to theLinearTolerance.
+ GEOMAPI_EXPORT
+ bool contains(const std::shared_ptr<GeomAPI_Pnt> thePoint, const double theLinearTolerance = 1.e-7) const;
+
/// \return true if lines are parallel.
GEOMAPI_EXPORT
bool isParallel(const std::shared_ptr<GeomAPI_Lin> theLin) const;
// Created: 23 Apr 2014
// Author: Mikhail PONIKAROV
-#include <GeomAlgoAPI_FaceBuilder.h>
-#include <gp_Pln.hxx>
-#include <BRepBuilderAPI_MakeFace.hxx>
-#include <TopoDS_Face.hxx>
-#include <TopoDS.hxx>
+#include "GeomAlgoAPI_FaceBuilder.h"
+
+#include <GeomAPI_Face.h>
+#include <GeomAPI_Dir.h>
+#include <GeomAPI_Pln.h>
+#include <GeomAPI_Pnt.h>
+#include <GeomAPI_Shape.h>
+#include <GeomAPI_Vertex.h>
+
#include <BRep_Tool.hxx>
+#include <BRepBuilderAPI_MakeFace.hxx>
+#include <GC_MakePlane.hxx>
#include <Geom_Plane.hxx>
#include <GeomLib_IsPlanarSurface.hxx>
+#include <gp_Pln.hxx>
+#include <TopoDS.hxx>
+#include <TopoDS_Face.hxx>
-
-std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_FaceBuilder::square(
- std::shared_ptr<GeomAPI_Pnt> theCenter, std::shared_ptr<GeomAPI_Dir> theNormal,
- const double theSize)
+//==================================================================================================
+std::shared_ptr<GeomAPI_Face> GeomAlgoAPI_FaceBuilder::squareFace(const std::shared_ptr<GeomAPI_Pnt> theCenter,
+ const std::shared_ptr<GeomAPI_Dir> theNormal,
+ const double theSize)
{
const gp_Pnt& aCenter = theCenter->impl<gp_Pnt>();
const gp_Dir& aDir = theNormal->impl<gp_Dir>();
// half of the size in each direction from the center
BRepBuilderAPI_MakeFace aFaceBuilder(aPlane, -theSize / 2., theSize / 2., -theSize / 2.,
theSize / 2.);
- std::shared_ptr<GeomAPI_Shape> aRes(new GeomAPI_Shape);
- aRes->setImpl(new TopoDS_Shape(aFaceBuilder.Face()));
+ std::shared_ptr<GeomAPI_Face> aRes(new GeomAPI_Face());
+ aRes->setImpl(new TopoDS_Face(aFaceBuilder.Face()));
return aRes;
}
-std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_FaceBuilder::square(
- std::shared_ptr<GeomAPI_Pln> thePlane,
- const double theSize)
+//==================================================================================================
+std::shared_ptr<GeomAPI_Face> GeomAlgoAPI_FaceBuilder::squareFace(const std::shared_ptr<GeomAPI_Pln> thePlane,
+ const double theSize)
{
// half of the size in each direction from the center
BRepBuilderAPI_MakeFace aFaceBuilder(thePlane->impl<gp_Pln>(),
-theSize / 2., theSize / 2.,
-theSize / 2., theSize / 2.);
- std::shared_ptr<GeomAPI_Shape> aRes(new GeomAPI_Shape);
- TopoDS_Shape aFace = aFaceBuilder.Face();
- aRes->setImpl(new TopoDS_Shape(aFace/*aFaceBuilder.Face()*/));
+ std::shared_ptr<GeomAPI_Face> aRes(new GeomAPI_Face());
+ const TopoDS_Face& aFace = aFaceBuilder.Face();
+ aRes->setImpl(new TopoDS_Face(aFace));
+ return aRes;
+}
+
+//==================================================================================================
+std::shared_ptr<GeomAPI_Face> GeomAlgoAPI_FaceBuilder::planarFace(const std::shared_ptr<GeomAPI_Pnt> theCenter,
+ const std::shared_ptr<GeomAPI_Dir> theNormal)
+{
+ const gp_Pnt& aCenter = theCenter->impl<gp_Pnt>();
+ const gp_Dir& aDir = theNormal->impl<gp_Dir>();
+ gp_Pln aPlane(aCenter, aDir);
+ BRepBuilderAPI_MakeFace aFaceBuilder(aPlane);
+ std::shared_ptr<GeomAPI_Face> aRes(new GeomAPI_Face());
+ aRes->setImpl(new TopoDS_Face(aFaceBuilder.Face()));
+ return aRes;
+}
+
+//==================================================================================================
+std::shared_ptr<GeomAPI_Face> GeomAlgoAPI_FaceBuilder::planarFace(const std::shared_ptr<GeomAPI_Pln> thePlane,
+ const double theX, const double theY,
+ const double theWidth, const 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_Face> aRes(new GeomAPI_Face());
+ aRes->setImpl(new TopoDS_Face(aFaceBuilder.Face()));
return aRes;
}
-std::shared_ptr<GeomAPI_Pln> GeomAlgoAPI_FaceBuilder::plane(
- std::shared_ptr<GeomAPI_Shape> theFace)
+//==================================================================================================
+std::shared_ptr<GeomAPI_Face> GeomAlgoAPI_FaceBuilder::planarFaceByThreeVertices(
+ const std::shared_ptr<GeomAPI_Vertex> theVertex1,
+ const std::shared_ptr<GeomAPI_Vertex> theVertex2,
+ const std::shared_ptr<GeomAPI_Vertex> theVertex3)
+{
+ gp_Pnt aPnt1 = theVertex1->point()->impl<gp_Pnt>();
+ gp_Pnt aPnt2 = theVertex2->point()->impl<gp_Pnt>();
+ gp_Pnt aPnt3 = theVertex3->point()->impl<gp_Pnt>();
+
+ std::shared_ptr<GeomAPI_Face> aFace;
+ GC_MakePlane aMakePlane(aPnt1, aPnt2, aPnt3);
+ if(!aMakePlane.IsDone()) {
+ return aFace;
+ }
+
+ BRepBuilderAPI_MakeFace aMakeFace(aMakePlane.Value()->Pln());
+ aFace.reset(new GeomAPI_Face());
+ aFace->setImpl(new TopoDS_Face(aMakeFace.Face()));
+ return aFace;
+}
+
+//==================================================================================================
+std::shared_ptr<GeomAPI_Pln> GeomAlgoAPI_FaceBuilder::plane(const std::shared_ptr<GeomAPI_Face> theFace)
{
std::shared_ptr<GeomAPI_Pln> aResult;
if (!theFace)
}
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_Pnt> theCenter,
- std::shared_ptr<GeomAPI_Dir> theNormal)
-{
- const gp_Pnt& aCenter = theCenter->impl<gp_Pnt>();
- const gp_Dir& aDir = theNormal->impl<gp_Dir>();
- gp_Pln aPlane(aCenter, aDir);
- BRepBuilderAPI_MakeFace aFaceBuilder(aPlane);
- std::shared_ptr<GeomAPI_Shape> aRes(new GeomAPI_Shape);
- aRes->setImpl(new TopoDS_Shape(aFaceBuilder.Face()));
- return aRes;
-}
-
-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
#ifndef GeomAlgoAPI_FaceBuilder_H_
#define GeomAlgoAPI_FaceBuilder_H_
-#include <GeomAlgoAPI.h>
-#include <GeomAPI_Shape.h>
-#include <GeomAPI_Pnt.h>
-#include <GeomAPI_Pln.h>
-#include <GeomAPI_Dir.h>
+#include "GeomAlgoAPI.h"
+
#include <memory>
-/**\class GeomAlgoAPI_FaceBuilder
- * \ingroup DataAlgo
- * \brief Allows to create face-shapes by different parameters
- */
+class GeomAPI_Dir;
+class GeomAPI_Face;
+class GeomAPI_Pln;
+class GeomAPI_Pnt;
+class GeomAPI_Vertex;
+/// \class GeomAlgoAPI_FaceBuilder
+/// \ingroup DataAlgo
+/// \brief Allows to create face-shapes by different parameters
class GEOMALGOAPI_EXPORT GeomAlgoAPI_FaceBuilder
{
public:
/// Creates square planar face by given point of the center,
/// normal to the plane and size of square
- static std::shared_ptr<GeomAPI_Shape> square(std::shared_ptr<GeomAPI_Pnt> theCenter,
- std::shared_ptr<GeomAPI_Dir> theNormal,
- const double theSize);
+ static std::shared_ptr<GeomAPI_Face> squareFace(const std::shared_ptr<GeomAPI_Pnt> theCenter,
+ const std::shared_ptr<GeomAPI_Dir> theNormal,
+ const double theSize);
/// Creates square planar face by given point of the center,
/// normal to the plane and size of square
- static std::shared_ptr<GeomAPI_Shape> square(std::shared_ptr<GeomAPI_Pln> thePlane,
- const double theSize);
-
- /// 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);
+ static std::shared_ptr<GeomAPI_Face> squareFace(const std::shared_ptr<GeomAPI_Pln> thePlane,
+ const double theSize);
/// Creates the planar face by given point of the center and normal to the plane.
- static std::shared_ptr<GeomAPI_Shape> planarFace(std::shared_ptr<GeomAPI_Pnt> theCenter,
- std::shared_ptr<GeomAPI_Dir> theNormal);
+ static std::shared_ptr<GeomAPI_Face> planarFace(const std::shared_ptr<GeomAPI_Pnt> theCenter,
+ const std::shared_ptr<GeomAPI_Dir> theNormal);
/// 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);
+ static std::shared_ptr<GeomAPI_Face> planarFace(const std::shared_ptr<GeomAPI_Pln> thePlane,
+ const double theX, const double theY,
+ const double theWidth, const double theHeight);
+
+ /// Creates a planar face by three vertices.
+ static std::shared_ptr<GeomAPI_Face> planarFaceByThreeVertices(const std::shared_ptr<GeomAPI_Vertex> theVertex1,
+ const std::shared_ptr<GeomAPI_Vertex> theVertex2,
+ const std::shared_ptr<GeomAPI_Vertex> theVertex3);
+
+ /// Returns the plane of the planar face. If it is not planar, returns empty ptr.
+ static std::shared_ptr<GeomAPI_Pln> plane(const std::shared_ptr<GeomAPI_Face> theFace);
};
#endif
#include <memory>
+#define NESTED_TOOLBOX_FIX
+
// the only created instance of this plugin
static InitializationPlugin_Plugin* MY_INITIALIZATIONPLUGIN_INSTANCE =
new InitializationPlugin_Plugin();
double theZ)
{
FeaturePtr aPlane = theDoc->addFeature("Plane");
- aPlane->string("CreationMethod")->setValue("PlaneByGeneralEquation");
+ aPlane->string("creation_method")->setValue("by_general_equation");
+#ifdef NESTED_TOOLBOX_FIX
+ aPlane->string("by_other_plane_option")->setValue("by_distance_from_other");
+ aPlane->real("distance")->setValue(0);
+#endif
aPlane->real("A")->setValue(theX);
aPlane->real("B")->setValue(theY);
aPlane->real("C")->setValue(theZ);
const int theRGB[3])
{
double aSize = Config_PropManager::integer("Sketch planes", "planes_size", PLANE_SIZE);
- std::shared_ptr<GeomAPI_Shape> aFace = GeomAlgoAPI_FaceBuilder::square(theOrigin, theNorm, aSize);
+ std::shared_ptr<GeomAPI_Shape> aFace = GeomAlgoAPI_FaceBuilder::squareFace(theOrigin, theNorm, aSize);
AISObjectPtr aAIS = AISObjectPtr(new GeomAPI_AISObject());
aAIS->createShape(aFace);
aAIS->setWidth(Config_PropManager::integer("Sketch planes", "planes_thickness", SKETCH_WIDTH));
}
if (aGShape.get() != NULL) {
// get plane parameters
- std::shared_ptr<GeomAPI_Pln> aPlane = GeomAlgoAPI_FaceBuilder::plane(aGShape);
+ std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(aGShape));
+ std::shared_ptr<GeomAPI_Pln> aPlane = GeomAlgoAPI_FaceBuilder::plane(aFace);
std::shared_ptr<GeomAPI_Dir> aDir = aPlane->direction();
gp_XYZ aXYZ = aDir->impl<gp_Dir>().XYZ();
double aTwist = 0.0;
// get plane parameters
- std::shared_ptr<GeomAPI_Pln> aPlane = GeomAlgoAPI_FaceBuilder::plane(aGShape);
+ std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(aGShape));
+ std::shared_ptr<GeomAPI_Pln> aPlane = GeomAlgoAPI_FaceBuilder::plane(aFace);
if (!aPlane.get())
return std::shared_ptr<GeomAPI_Dir>();
data()->selection(SketchPlugin_SketchEntity::EXTERNAL_ID())->value();
if (aSelection) { // update arguments due to the selection value
// update the sketch plane
- std::shared_ptr<GeomAPI_Pln> aPlane = GeomAlgoAPI_FaceBuilder::plane(aSelection);
+ std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(aSelection));
+ std::shared_ptr<GeomAPI_Pln> aPlane = GeomAlgoAPI_FaceBuilder::plane(aFace);
if (aPlane) {
double anA, aB, aC, aD;
aPlane->coefficients(anA, aB, aC, aD);