From: dbv Date: Wed, 13 Jul 2016 12:21:33 +0000 (+0300) Subject: Issue #1649: Added options to create plane by three points; X-Git-Tag: V_2.5.0~194 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=24e5375957ba83cea9bf9fbe9bff030df996914a;p=modules%2Fshaper.git Issue #1649: Added options to create plane by three points; Added option to create plane by line and point. --- diff --git a/src/ConstructionAPI/ConstructionAPI_Plane.cpp b/src/ConstructionAPI/ConstructionAPI_Plane.cpp index a248e71d1..b33d4d746 100644 --- a/src/ConstructionAPI/ConstructionAPI_Plane.cpp +++ b/src/ConstructionAPI/ConstructionAPI_Plane.cpp @@ -49,7 +49,7 @@ void ConstructionAPI_Plane::setFaceAndDistance( const ModelHighAPI_Double & theDistance) { fillAttribute("PlaneByFaceAndDistance", mycreationMethod); - fillAttribute(theFace, myface); + fillAttribute(theFace, myplane); fillAttribute(theDistance, mydistance); execute(); diff --git a/src/ConstructionAPI/ConstructionAPI_Plane.h b/src/ConstructionAPI/ConstructionAPI_Plane.h index 75936094e..7713d19cd 100644 --- a/src/ConstructionAPI/ConstructionAPI_Plane.h +++ b/src/ConstructionAPI/ConstructionAPI_Plane.h @@ -45,19 +45,19 @@ public: 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 diff --git a/src/ConstructionPlugin/ConstructionPlugin_Plane.cpp b/src/ConstructionPlugin/ConstructionPlugin_Plane.cpp index 07a223b44..40529c0c9 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Plane.cpp +++ b/src/ConstructionPlugin/ConstructionPlugin_Plane.cpp @@ -8,57 +8,93 @@ #include -#include +#include +#include + +#include +#include +#include +#include +#include + #include -#include #include +#include #include +#include #include #include -#include -#include +static GeomShapePtr faceByThreeVertices(const std::shared_ptr theV1, + const std::shared_ptr theV2, + const std::shared_ptr 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 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 theDefaultPrs) { @@ -85,9 +121,93 @@ bool ConstructionPlugin_Plane::customisePresentation(ResultPtr theResult, AISObj return isCustomized; } -std::shared_ptr ConstructionPlugin_Plane::createPlaneByFaceAndDistance() +//================================================================================================== +std::shared_ptr 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 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 aPlane = + std::shared_ptr(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 ConstructionPlugin_Plane::createByThreePoints() +{ + // Get first point. + AttributeSelectionPtr aPointSelection1 = selection(POINT1()); + GeomShapePtr aPointShape1 = aPointSelection1->value(); + if(!aPointShape1.get()) { + aPointShape1 = aPointSelection1->context()->shape(); + } + std::shared_ptr 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 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 aVertex3(new GeomAPI_Vertex(aPointShape3)); + + GeomShapePtr aRes = faceByThreeVertices(aVertex1, aVertex2, aVertex3); + + return aRes; +} + +//================================================================================================== +std::shared_ptr ConstructionPlugin_Plane::createByLineAndPoint() +{ + // Get edge. + AttributeSelectionPtr anEdgeSelection = selection(LINE()); + GeomShapePtr aLineShape = anEdgeSelection->value(); + if(!aLineShape.get()) { + aLineShape = anEdgeSelection->context()->shape(); + } + std::shared_ptr anEdge(new GeomAPI_Edge(aLineShape)); + std::shared_ptr 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 aVertex(new GeomAPI_Vertex(aPointShape)); + + GeomShapePtr aRes = faceByThreeVertices(aV1, aV2, aVertex); + + return aRes; +} + +//================================================================================================== +std::shared_ptr ConstructionPlugin_Plane::createByDistanceFromOther() +{ + AttributeSelectionPtr aFaceAttr = data()->selection(ConstructionPlugin_Plane::PLANE()); AttributeDoublePtr aDistAttr = data()->real(ConstructionPlugin_Plane::DISTANCE()); std::shared_ptr aPlane; if ((aFaceAttr.get() != NULL) && @@ -100,70 +220,67 @@ std::shared_ptr ConstructionPlugin_Plane::createPlaneByFaceAndDi aShape = aFaceAttr->context()->shape(); } - if (aShape.get() != NULL) { - std::shared_ptr aPln = GeomAlgoAPI_FaceBuilder::plane(aShape); - std::shared_ptr aOrig = aPln->location(); - std::shared_ptr aDir = aPln->direction(); - - aOrig->translate(aDir, aDist); - std::shared_ptr aNewPln = std::shared_ptr( - 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 aPnt = std::shared_ptr(new GeomAPI_Pnt( - aXIsMin ? aXmin : aXmax, aYIsMin ? aYmin : aYmax, aZIsMin ? Zmin : Zmax)); - std::shared_ptr 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 aFace(new GeomAPI_Face(aShape)); + + std::shared_ptr aPln = GeomAlgoAPI_FaceBuilder::plane(aFace); + std::shared_ptr aOrig = aPln->location(); + std::shared_ptr aDir = aPln->direction(); + + aOrig->translate(aDir, aDist); + std::shared_ptr 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 aPnt(new GeomAPI_Pnt( + aXIsMin ? aXmin : aXmax, aYIsMin ? aYmin : aYmax, aZIsMin ? Zmin : Zmax)); + std::shared_ptr 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 ConstructionPlugin_Plane::createPlaneByGeneralEquation() +//================================================================================================== +GeomShapePtr faceByThreeVertices(const std::shared_ptr theV1, + const std::shared_ptr theV2, + const std::shared_ptr 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 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 aPlane = - std::shared_ptr(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 aFace = GeomAlgoAPI_FaceBuilder::planarFaceByThreeVertices(theV1, theV2, theV3); + ListOfShape anObjects; + anObjects.push_back(theV1); + anObjects.push_back(theV2); + anObjects.push_back(theV3); + std::list > aBoundingPoints = GeomAlgoAPI_ShapeTools::getBoundingBox(anObjects, 1.0); + GeomShapePtr aRes = GeomAlgoAPI_ShapeTools::fitPlaneToBox(aFace, aBoundingPoints); + + return aRes; +} diff --git a/src/ConstructionPlugin/ConstructionPlugin_Plane.h b/src/ConstructionPlugin/ConstructionPlugin_Plane.h index b82f1e8c3..3bfecc7a7 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Plane.h +++ b/src/ConstructionPlugin/ConstructionPlugin_Plane.h @@ -8,83 +8,180 @@ #define ConstructionPlugin_Plane_H #include "ConstructionPlugin.h" + #include #include #include - - -/**\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 @@ -103,12 +200,14 @@ class ConstructionPlugin_Plane : public ModelAPI_Feature, public GeomAPI_ICustom virtual bool customisePresentation(ResultPtr theResult, AISObjectPtr thePrs, std::shared_ptr theDefaultPrs); - protected: +protected: + /// Creates a new plane by general equation. + std::shared_ptr createByGeneralEquation(); + std::shared_ptr createByThreePoints(); + std::shared_ptr createByLineAndPoint(); /// Creates a new plane by copy of face plane with translation along the normal /// to the specified distance. - std::shared_ptr createPlaneByFaceAndDistance(); - /// Creates a new plane by general equation. - std::shared_ptr createPlaneByGeneralEquation(); + std::shared_ptr createByDistanceFromOther(); }; #endif diff --git a/src/ConstructionPlugin/ConstructionPlugin_Plugin.cpp b/src/ConstructionPlugin/ConstructionPlugin_Plugin.cpp index e9f202998..521873f11 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Plugin.cpp +++ b/src/ConstructionPlugin/ConstructionPlugin_Plugin.cpp @@ -24,6 +24,10 @@ ConstructionPlugin_Plugin::ConstructionPlugin_Plugin() 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); diff --git a/src/ConstructionPlugin/ConstructionPlugin_Point.cpp b/src/ConstructionPlugin/ConstructionPlugin_Point.cpp index c3866c52d..00ae6f738 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Point.cpp +++ b/src/ConstructionPlugin/ConstructionPlugin_Point.cpp @@ -33,12 +33,12 @@ const std::string& ConstructionPlugin_Point::getKind() //================================================================================================== 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()); @@ -72,11 +72,13 @@ void ConstructionPlugin_Point::execute() aShape = createByLineAndPlaneIntersection(); } - if(aShape.get()) { - std::shared_ptr aConstr = document()->createConstruction(data()); - aConstr->setShape(aShape); - setResult(aConstr); + if(!aShape.get()) { + return; } + + std::shared_ptr aConstr = document()->createConstruction(data()); + aConstr->setShape(aShape); + setResult(aConstr); } //================================================================================================== @@ -152,7 +154,7 @@ std::shared_ptr ConstructionPlugin_Point::createByLinesIntersect } std::shared_ptr aFirstEdge(new GeomAPI_Edge(aFirstLineShape)); - // Get first line. + // Get second line. AttributeSelectionPtr aSecondLineSelection= selection(SECOND_LINE()); GeomShapePtr aSecondLineShape = aSecondLineSelection->value(); if(!aSecondLineShape.get()) { diff --git a/src/ConstructionPlugin/ConstructionPlugin_Validators.cpp b/src/ConstructionPlugin/ConstructionPlugin_Validators.cpp index 7c8fd6751..9cf88ccd9 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Validators.cpp +++ b/src/ConstructionPlugin/ConstructionPlugin_Validators.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include @@ -17,6 +18,7 @@ static std::shared_ptr getLin(const GeomShapePtr theShape); static std::shared_ptr getPln(const GeomShapePtr theShape); +static std::shared_ptr getPnt(const GeomShapePtr theShape); //================================================================================================== bool ConstructionPlugin_ValidatorPointLines::isValid(const AttributePtr& theAttribute, @@ -127,7 +129,129 @@ bool ConstructionPlugin_ValidatorPointLineAndPlaneNotParallel::isValid( return true; } -static std::shared_ptr getLin(const GeomShapePtr theShape) +//================================================================================================== +bool ConstructionPlugin_ValidatorPlaneThreePoints::isValid(const AttributePtr& theAttribute, + const std::list& theArguments, + Events_InfoMessage& theError) const +{ + FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner()); + + AttributeSelectionPtr aPointAttribute1 = std::dynamic_pointer_cast(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 aVertex1(new GeomAPI_Vertex(aPointShape1)); + std::shared_ptr aVertex2(new GeomAPI_Vertex(aPointShape2)); + std::shared_ptr aVertex3(new GeomAPI_Vertex(aPointShape3)); + + std::shared_ptr aPnt1 = aVertex1->point(); + std::shared_ptr aPnt2 = aVertex2->point(); + std::shared_ptr aPnt3 = aVertex3->point(); + + std::shared_ptr 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& theArguments, + Events_InfoMessage& theError) const +{ + FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner()); + + AttributeSelectionPtr anAttribute1 = std::dynamic_pointer_cast(theAttribute); + AttributeSelectionPtr anAttribute2 = aFeature->selection(theArguments.front()); + + std::shared_ptr aLin; + std::shared_ptr 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 getLin(const GeomShapePtr theShape) { std::shared_ptr aLin; @@ -146,7 +270,7 @@ static std::shared_ptr getLin(const GeomShapePtr theShape) return aLin; } -static std::shared_ptr getPln(const GeomShapePtr theShape) +std::shared_ptr getPln(const GeomShapePtr theShape) { std::shared_ptr aPln; @@ -164,3 +288,18 @@ static std::shared_ptr getPln(const GeomShapePtr theShape) return aPln; } + +std::shared_ptr getPnt(const GeomShapePtr theShape) +{ + std::shared_ptr aPnt; + + if(!theShape->isVertex()) { + return aPnt; + } + + std::shared_ptr aVertex(new GeomAPI_Vertex(theShape)); + + aPnt = aVertex->point(); + + return aPnt; +} diff --git a/src/ConstructionPlugin/ConstructionPlugin_Validators.h b/src/ConstructionPlugin/ConstructionPlugin_Validators.h index 65fb54be5..9bbb6f950 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Validators.h +++ b/src/ConstructionPlugin/ConstructionPlugin_Validators.h @@ -26,7 +26,7 @@ public: /// \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: @@ -39,4 +39,34 @@ 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& 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& theArguments, + Events_InfoMessage& theError) const; +}; + #endif \ No newline at end of file diff --git a/src/ConstructionPlugin/plane_widget.xml b/src/ConstructionPlugin/plane_widget.xml index 938850f41..299e6ae35 100644 --- a/src/ConstructionPlugin/plane_widget.xml +++ b/src/ConstructionPlugin/plane_widget.xml @@ -1,8 +1,95 @@ - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/GeomAPI/GeomAPI_Face.cpp b/src/GeomAPI/GeomAPI_Face.cpp index e47070176..6c3894ba7 100644 --- a/src/GeomAPI/GeomAPI_Face.cpp +++ b/src/GeomAPI/GeomAPI_Face.cpp @@ -32,6 +32,9 @@ GeomAPI_Face::GeomAPI_Face(const std::shared_ptr& theShape) bool GeomAPI_Face::isEqual(std::shared_ptr theFace) const { + if (!theFace.get()) + return false; + if (!theFace->isFace()) return false; diff --git a/src/GeomAPI/GeomAPI_Lin.cpp b/src/GeomAPI/GeomAPI_Lin.cpp index b76131aa3..9ccc30f2b 100644 --- a/src/GeomAPI/GeomAPI_Lin.cpp +++ b/src/GeomAPI/GeomAPI_Lin.cpp @@ -105,6 +105,15 @@ const std::shared_ptr GeomAPI_Lin::project( return std::shared_ptr(new GeomAPI_Pnt(aResult.X(), aResult.Y(), aResult.Z())); } +bool GeomAPI_Lin::contains(const std::shared_ptr thePoint, const double theLinearTolerance) const +{ + if(!thePoint.get()) { + return false; + } + + return MY_LIN->Contains(thePoint->impl(), theLinearTolerance) == Standard_True; +} + bool GeomAPI_Lin::isParallel(const std::shared_ptr theLin) const { return MY_LIN->Direction().IsParallel(theLin->impl().Direction(), Precision::Confusion()) == Standard_True; diff --git a/src/GeomAPI/GeomAPI_Lin.h b/src/GeomAPI/GeomAPI_Lin.h index c62215bbc..e9e35296a 100644 --- a/src/GeomAPI/GeomAPI_Lin.h +++ b/src/GeomAPI/GeomAPI_Lin.h @@ -54,6 +54,11 @@ class GeomAPI_Lin : public GeomAPI_Interface const std::shared_ptr project( const std::shared_ptr& 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 thePoint, const double theLinearTolerance = 1.e-7) const; + /// \return true if lines are parallel. GEOMAPI_EXPORT bool isParallel(const std::shared_ptr theLin) const; diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.cpp index 8e108ebfa..7a6251310 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.cpp @@ -4,19 +4,28 @@ // Created: 23 Apr 2014 // Author: Mikhail PONIKAROV -#include -#include -#include -#include -#include +#include "GeomAlgoAPI_FaceBuilder.h" + +#include +#include +#include +#include +#include +#include + #include +#include +#include #include #include +#include +#include +#include - -std::shared_ptr GeomAlgoAPI_FaceBuilder::square( - std::shared_ptr theCenter, std::shared_ptr theNormal, - const double theSize) +//================================================================================================== +std::shared_ptr GeomAlgoAPI_FaceBuilder::squareFace(const std::shared_ptr theCenter, + const std::shared_ptr theNormal, + const double theSize) { const gp_Pnt& aCenter = theCenter->impl(); const gp_Dir& aDir = theNormal->impl(); @@ -24,27 +33,79 @@ std::shared_ptr GeomAlgoAPI_FaceBuilder::square( // 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 aRes(new GeomAPI_Shape); - aRes->setImpl(new TopoDS_Shape(aFaceBuilder.Face())); + std::shared_ptr aRes(new GeomAPI_Face()); + aRes->setImpl(new TopoDS_Face(aFaceBuilder.Face())); return aRes; } -std::shared_ptr GeomAlgoAPI_FaceBuilder::square( - std::shared_ptr thePlane, - const double theSize) +//================================================================================================== +std::shared_ptr GeomAlgoAPI_FaceBuilder::squareFace(const std::shared_ptr thePlane, + const double theSize) { // half of the size in each direction from the center BRepBuilderAPI_MakeFace aFaceBuilder(thePlane->impl(), -theSize / 2., theSize / 2., -theSize / 2., theSize / 2.); - std::shared_ptr aRes(new GeomAPI_Shape); - TopoDS_Shape aFace = aFaceBuilder.Face(); - aRes->setImpl(new TopoDS_Shape(aFace/*aFaceBuilder.Face()*/)); + std::shared_ptr aRes(new GeomAPI_Face()); + const TopoDS_Face& aFace = aFaceBuilder.Face(); + aRes->setImpl(new TopoDS_Face(aFace)); + return aRes; +} + +//================================================================================================== +std::shared_ptr GeomAlgoAPI_FaceBuilder::planarFace(const std::shared_ptr theCenter, + const std::shared_ptr theNormal) +{ + const gp_Pnt& aCenter = theCenter->impl(); + const gp_Dir& aDir = theNormal->impl(); + gp_Pln aPlane(aCenter, aDir); + BRepBuilderAPI_MakeFace aFaceBuilder(aPlane); + std::shared_ptr aRes(new GeomAPI_Face()); + aRes->setImpl(new TopoDS_Face(aFaceBuilder.Face())); + return aRes; +} + +//================================================================================================== +std::shared_ptr GeomAlgoAPI_FaceBuilder::planarFace(const std::shared_ptr 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 aRes(new GeomAPI_Face()); + aRes->setImpl(new TopoDS_Face(aFaceBuilder.Face())); return aRes; } -std::shared_ptr GeomAlgoAPI_FaceBuilder::plane( - std::shared_ptr theFace) +//================================================================================================== +std::shared_ptr GeomAlgoAPI_FaceBuilder::planarFaceByThreeVertices( + const std::shared_ptr theVertex1, + const std::shared_ptr theVertex2, + const std::shared_ptr theVertex3) +{ + gp_Pnt aPnt1 = theVertex1->point()->impl(); + gp_Pnt aPnt2 = theVertex2->point()->impl(); + gp_Pnt aPnt3 = theVertex3->point()->impl(); + + std::shared_ptr 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 GeomAlgoAPI_FaceBuilder::plane(const std::shared_ptr theFace) { std::shared_ptr aResult; if (!theFace) @@ -75,32 +136,4 @@ std::shared_ptr GeomAlgoAPI_FaceBuilder::plane( } aResult = std::shared_ptr(new GeomAPI_Pln(aA, aB, aC, aD)); return aResult; -} - -std::shared_ptr GeomAlgoAPI_FaceBuilder::planarFace(std::shared_ptr theCenter, - std::shared_ptr theNormal) -{ - const gp_Pnt& aCenter = theCenter->impl(); - const gp_Dir& aDir = theNormal->impl(); - gp_Pln aPlane(aCenter, aDir); - BRepBuilderAPI_MakeFace aFaceBuilder(aPlane); - std::shared_ptr aRes(new GeomAPI_Shape); - aRes->setImpl(new TopoDS_Shape(aFaceBuilder.Face())); - return aRes; -} - -std::shared_ptr GeomAlgoAPI_FaceBuilder::planarFace(std::shared_ptr 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 aRes(new GeomAPI_Shape); - aRes->setImpl(new TopoDS_Shape(aFaceBuilder.Face())); - return aRes; -} +} \ No newline at end of file diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.h b/src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.h index 49ec19c30..603ed4620 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.h @@ -7,42 +7,48 @@ #ifndef GeomAlgoAPI_FaceBuilder_H_ #define GeomAlgoAPI_FaceBuilder_H_ -#include -#include -#include -#include -#include +#include "GeomAlgoAPI.h" + #include -/**\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 square(std::shared_ptr theCenter, - std::shared_ptr theNormal, - const double theSize); + static std::shared_ptr squareFace(const std::shared_ptr theCenter, + const std::shared_ptr 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 square(std::shared_ptr thePlane, - const double theSize); - - /// Returns the plane of the planar face. If it is not planar, returns empty ptr. - static std::shared_ptr plane(std::shared_ptr theFace); + static std::shared_ptr squareFace(const std::shared_ptr thePlane, + const double theSize); /// Creates the planar face by given point of the center and normal to the plane. - static std::shared_ptr planarFace(std::shared_ptr theCenter, - std::shared_ptr theNormal); + static std::shared_ptr planarFace(const std::shared_ptr theCenter, + const std::shared_ptr theNormal); /// Creates a planar face by given plane, left lower point and size. - static std::shared_ptr planarFace(std::shared_ptr thePlane, - double theX, double theY, - double theWidth, double theHeight); + static std::shared_ptr planarFace(const std::shared_ptr thePlane, + const double theX, const double theY, + const double theWidth, const double theHeight); + + /// Creates a planar face by three vertices. + static std::shared_ptr planarFaceByThreeVertices(const std::shared_ptr theVertex1, + const std::shared_ptr theVertex2, + const std::shared_ptr theVertex3); + + /// Returns the plane of the planar face. If it is not planar, returns empty ptr. + static std::shared_ptr plane(const std::shared_ptr theFace); }; #endif diff --git a/src/InitializationPlugin/InitializationPlugin_Plugin.cpp b/src/InitializationPlugin/InitializationPlugin_Plugin.cpp index cdfe868ac..3b3ba3c3b 100644 --- a/src/InitializationPlugin/InitializationPlugin_Plugin.cpp +++ b/src/InitializationPlugin/InitializationPlugin_Plugin.cpp @@ -15,6 +15,8 @@ #include +#define NESTED_TOOLBOX_FIX + // the only created instance of this plugin static InitializationPlugin_Plugin* MY_INITIALIZATIONPLUGIN_INSTANCE = new InitializationPlugin_Plugin(); @@ -89,7 +91,11 @@ FeaturePtr InitializationPlugin_Plugin::createPlane(DocumentPtr theDoc, double t 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); diff --git a/src/PartSet/PartSet_PreviewPlanes.cpp b/src/PartSet/PartSet_PreviewPlanes.cpp index e7210b0ce..53e4cebfd 100755 --- a/src/PartSet/PartSet_PreviewPlanes.cpp +++ b/src/PartSet/PartSet_PreviewPlanes.cpp @@ -124,7 +124,7 @@ AISObjectPtr PartSet_PreviewPlanes::createPreviewPlane(std::shared_ptr aFace = GeomAlgoAPI_FaceBuilder::square(theOrigin, theNorm, aSize); + std::shared_ptr 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)); diff --git a/src/PartSet/PartSet_WidgetSketchLabel.cpp b/src/PartSet/PartSet_WidgetSketchLabel.cpp index 74a7ee5e3..c09625924 100644 --- a/src/PartSet/PartSet_WidgetSketchLabel.cpp +++ b/src/PartSet/PartSet_WidgetSketchLabel.cpp @@ -257,7 +257,8 @@ void PartSet_WidgetSketchLabel::updateByPlaneSelected(const ModuleBase_ViewerPrs } if (aGShape.get() != NULL) { // get plane parameters - std::shared_ptr aPlane = GeomAlgoAPI_FaceBuilder::plane(aGShape); + std::shared_ptr aFace(new GeomAPI_Face(aGShape)); + std::shared_ptr aPlane = GeomAlgoAPI_FaceBuilder::plane(aFace); std::shared_ptr aDir = aPlane->direction(); gp_XYZ aXYZ = aDir->impl().XYZ(); double aTwist = 0.0; @@ -487,7 +488,8 @@ std::shared_ptr PartSet_WidgetSketchLabel::setSketchPlane(const Fea // get plane parameters - std::shared_ptr aPlane = GeomAlgoAPI_FaceBuilder::plane(aGShape); + std::shared_ptr aFace(new GeomAPI_Face(aGShape)); + std::shared_ptr aPlane = GeomAlgoAPI_FaceBuilder::plane(aFace); if (!aPlane.get()) return std::shared_ptr(); diff --git a/src/SketchPlugin/SketchPlugin_Sketch.cpp b/src/SketchPlugin/SketchPlugin_Sketch.cpp index 22b3257ef..ef2ef9c69 100755 --- a/src/SketchPlugin/SketchPlugin_Sketch.cpp +++ b/src/SketchPlugin/SketchPlugin_Sketch.cpp @@ -216,7 +216,8 @@ void SketchPlugin_Sketch::attributeChanged(const std::string& theID) { data()->selection(SketchPlugin_SketchEntity::EXTERNAL_ID())->value(); if (aSelection) { // update arguments due to the selection value // update the sketch plane - std::shared_ptr aPlane = GeomAlgoAPI_FaceBuilder::plane(aSelection); + std::shared_ptr aFace(new GeomAPI_Face(aSelection)); + std::shared_ptr aPlane = GeomAlgoAPI_FaceBuilder::plane(aFace); if (aPlane) { double anA, aB, aC, aD; aPlane->coefficients(anA, aB, aC, aD);