if(aType1 == GeomAPI_Shape::VERTEX && aType2 == GeomAPI_Shape::FACE) {
// If first object is vertex and second object is face then set by projection.
setByProjectionOnFace(theObject1, theObject2);
- } /*else if(aType1 == GeomAPI_Shape::EDGE && aType2 == GeomAPI_Shape::EDGE) {
+ } else if (aType1 == GeomAPI_Shape::VERTEX && aType2 == GeomAPI_Shape::EDGE) {
+ // If first object is vertex and second object is edge then set by projection.
+ setByProjectionOnEdge(theObject1, theObject2);
+ } /* else if(aType1 == GeomAPI_Shape::EDGE && aType2 == GeomAPI_Shape::EDGE) {
// If both objects are edges then set by lines intersection.
setByLinesIntersection(theObject1, theObject2);
} */ else if(aType1 == GeomAPI_Shape::EDGE && aType2 == GeomAPI_Shape::FACE) {
execute();
}
+//==================================================================================================
+void ConstructionAPI_Point::setByProjectionOnEdge(const ModelHighAPI_Selection& theVertex,
+ const ModelHighAPI_Selection& theEdge)
+{
+ fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_PROJECTION_ON_EDGE(),
+ mycreationMethod);
+ fillAttribute(theVertex, mypoinToProjectOnEdge);
+ fillAttribute(theEdge, myedgeForPointProjection);
+
+ execute();
+}
+
//==================================================================================================
void ConstructionAPI_Point::setByProjectionOnFace(const ModelHighAPI_Selection& theVertex,
const ModelHighAPI_Selection& theFace)
theDumper << ratio() << ", " << true;
}
theDumper << ", " << reverse()->value();
+ } else if (aMeth == ConstructionPlugin_Point::CREATION_METHOD_BY_PROJECTION_ON_EDGE()) {
+ theDumper << mypoinToProjectOnEdge << ", " << myedgeForPointProjection;
} else if (aMeth == ConstructionPlugin_Point::CREATION_METHOD_BY_PROJECTION_ON_FACE()) {
theDumper << mypoinToProjectOnFace << ", " << myfaceForPointProjection;
}
CONSTRUCTIONAPI_EXPORT
virtual ~ConstructionAPI_Point();
- INTERFACE_16(ConstructionPlugin_Point::ID(),
+ INTERFACE_18(ConstructionPlugin_Point::ID(),
x, ConstructionPlugin_Point::X(), ModelAPI_AttributeDouble, /** X attribute */,
y, ConstructionPlugin_Point::Y(), ModelAPI_AttributeDouble, /** Y attribute */,
z, ConstructionPlugin_Point::Z(), ModelAPI_AttributeDouble, /** Z attribute */,
poinToProjectOnFace, ConstructionPlugin_Point::POINT_TO_PROJECT_ON_FACE(),
ModelAPI_AttributeSelection, /** Point to project on face */,
faceForPointProjection, ConstructionPlugin_Point::FACE_FOR_POINT_PROJECTION(),
- ModelAPI_AttributeSelection, /** Face for point projection */)
+ ModelAPI_AttributeSelection, /** Face for point projection */,
+ poinToProjectOnEdge, ConstructionPlugin_Point::POINT_TO_PROJECT_ON_EDGE(),
+ ModelAPI_AttributeSelection, /** Point to project on edge */,
+ edgeForPointProjection, ConstructionPlugin_Point::EDGE_FOR_POINT_PROJECTION(),
+ ModelAPI_AttributeSelection, /** Edge for point projection */)
/// Set point values.
const bool theUseRatio = false,
const bool theReverse = false);
- /// Set point and plane for projection.
+ /// Set point and edge for projection.
+ CONSTRUCTIONAPI_EXPORT
+ void setByProjectionOnEdge(const ModelHighAPI_Selection& theVertex,
+ const ModelHighAPI_Selection& theEdge);
+
+ /// Set point and face for projection.
CONSTRUCTIONAPI_EXPORT
void setByProjectionOnFace(const ModelHighAPI_Selection& theVertex,
const ModelHighAPI_Selection& theFace);
TestPoint_XYZ.py
TestPoint_LineAndPlane.py
TestPoint_Edge.py
+ TestPoint_ProjectOnEdge.py
TestPoint_ProjectOnFace.py
TestPointName.py
TestPlane.py)
data()->addAttribute(RATIO(), ModelAPI_AttributeDouble::typeId());
data()->addAttribute(REVERSE(), ModelAPI_AttributeBoolean::typeId());
+ data()->addAttribute(POINT_TO_PROJECT_ON_EDGE(), ModelAPI_AttributeSelection::typeId());
+ data()->addAttribute(EDGE_FOR_POINT_PROJECTION(), ModelAPI_AttributeSelection::typeId());
+
data()->addAttribute(POINT_TO_PROJECT_ON_FACE(), ModelAPI_AttributeSelection::typeId());
data()->addAttribute(FACE_FOR_POINT_PROJECTION(), ModelAPI_AttributeSelection::typeId());
}
aShape = createByXYZ();
} else if(aCreationMethod == CREATION_METHOD_BY_DISTANCE_ON_EDGE()) {
aShape = createByDistanceOnEdge();
+ } else if(aCreationMethod == CREATION_METHOD_BY_PROJECTION_ON_EDGE()) {
+ aShape = createByProjectionOnEdge();
} else if(aCreationMethod == CREATION_METHOD_BY_PROJECTION_ON_FACE()) {
aShape = createByProjectionOnFace();
} /* else if(aCreationMethod == CREATION_METHOD_BY_LINES_INTERSECTION()) {
return GeomAlgoAPI_PointBuilder::vertexOnEdge(anEdge, aValue, anIsPercent, anIsReverse);
}
+//==================================================================================================
+std::shared_ptr<GeomAPI_Vertex> ConstructionPlugin_Point::createByProjectionOnEdge()
+{
+ // Get point.
+ AttributeSelectionPtr aPointSelection = selection(POINT_TO_PROJECT_ON_EDGE());
+ GeomShapePtr aPointShape = aPointSelection->value();
+ if (!aPointShape.get()) {
+ aPointShape = aPointSelection->context()->shape();
+ }
+ std::shared_ptr<GeomAPI_Vertex> aVertex(new GeomAPI_Vertex(aPointShape));
+
+ // Get edge.
+ AttributeSelectionPtr anEdgeSelection = selection(EDGE_FOR_POINT_PROJECTION());
+ GeomShapePtr anEdgeShape = anEdgeSelection->value();
+ if (!anEdgeShape.get()) {
+ anEdgeShape = anEdgeSelection->context()->shape();
+ }
+ std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge(anEdgeShape));
+
+ return GeomAlgoAPI_PointBuilder::vertexByProjection(aVertex, anEdge);
+}
+
//==================================================================================================
std::shared_ptr<GeomAPI_Vertex> ConstructionPlugin_Point::createByProjectionOnFace()
{
return MY_CREATION_METHOD_ID;
}
+ /// Attribute name for creation method.
+ inline static const std::string& CREATION_METHOD_BY_PROJECTION_ON_EDGE()
+ {
+ static const std::string MY_CREATION_METHOD_ID("by_projection_on_edge");
+ return MY_CREATION_METHOD_ID;
+ }
+
/// Attribute name for creation method.
inline static const std::string& CREATION_METHOD_BY_PROJECTION_ON_FACE()
{
return ATTR_ID;
}
+ /// Attribute name for point to project on edge.
+ inline static const std::string& POINT_TO_PROJECT_ON_EDGE()
+ {
+ static const std::string ATTR_ID("point_to_project_on_edge");
+ return ATTR_ID;
+ }
+
+ /// Attribute name for edge for point projection.
+ inline static const std::string& EDGE_FOR_POINT_PROJECTION()
+ {
+ static const std::string ATTR_ID("edge_for_point_projection");
+ return ATTR_ID;
+ }
+
/// Attribute name for point to project on surface.
inline static const std::string& POINT_TO_PROJECT_ON_FACE()
{
private:
std::shared_ptr<GeomAPI_Vertex> createByXYZ();
std::shared_ptr<GeomAPI_Vertex> createByDistanceOnEdge();
+ std::shared_ptr<GeomAPI_Vertex> createByProjectionOnEdge();
std::shared_ptr<GeomAPI_Vertex> createByProjectionOnFace();
/*std::shared_ptr<GeomAPI_Vertex> createByLinesIntersection();*/
std::list<std::shared_ptr<GeomAPI_Vertex> > createByLineAndPlaneIntersection();
--- /dev/null
+## Copyright (C) 2014-2017 CEA/DEN, EDF R&D
+##
+## This library is free software; you can redistribute it and/or
+## modify it under the terms of the GNU Lesser General Public
+## License as published by the Free Software Foundation; either
+## version 2.1 of the License, or (at your option) any later version.
+##
+## This library is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+## Lesser General Public License for more details.
+##
+## You should have received a copy of the GNU Lesser General Public
+## License along with this library; if not, write to the Free Software
+## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+##
+## See http:##www.salome-platform.org/ or
+## email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+##
+
+"""
+Test case for Construction Point feature by coordinates.
+"""
+
+from salome.shaper import model
+from GeomAPI import *
+
+model.begin()
+partSet = model.moduleDocument()
+Part_1 = model.addPart(partSet)
+Part_1_doc = Part_1.document()
+Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
+SketchCircle_1 = Sketch_1.addCircle(0, 0, 100)
+SketchPoint_1 = Sketch_1.addPoint(100, 100)
+model.do()
+Box_1 = model.addBox(Part_1_doc, 50, 50, 50)
+Point_2 = model.addPoint(Part_1_doc, model.selection("VERTEX", "Sketch_1/Vertex-SketchPoint_1"), model.selection("EDGE", "Sketch_1/Edge-SketchCircle_1_2"))
+Point_3 = model.addPoint(Part_1_doc, model.selection("VERTEX", "Sketch_1/Vertex-SketchPoint_1"), model.selection("EDGE", "Box_1_1/Front&Box_1_1/Right"))
+model.do()
+model.end()
+
+assert (len(Point_2.results()) > 0)
+rightPosition = GeomAPI_Vertex(70.7106781187, 70.7106781187, 0)
+assert(rightPosition.isEqual(Point_2.results()[0].resultSubShapePair()[0].shape()))
+
+assert (len(Point_3.results()) > 0)
+rightPosition = GeomAPI_Vertex(50, 50, 0)
+assert(rightPosition.isEqual(Point_4.results()[0].resultSubShapePair()[0].shape()))
+
+assert(model.checkPythonDump())
tooltip="Distance from edge end point."
default="false"/>
</box>
+ <box id="by_projection_on_edge"
+ title="By projection on edge"
+ tooltip="Point on edge by projection selected point."
+ icon="icons/Construction/point_by_projection_on_edge_32x32.png">
+ <shape_selector id="point_to_project_on_edge"
+ label="Point"
+ tooltip="Point for projection."
+ icon="icons/Construction/point.png"
+ shape_types="vertex">
+ </shape_selector>
+ <shape_selector id="edge_for_point_projection"
+ label="edge"
+ tooltip="Edge for projection."
+ icon="icons/Construction/edge.png"
+ shape_types="edge">
+ </shape_selector>
+ </box>
<box id="by_projection_on_face"
title="By projection on face"
tooltip="Point on face surface by projection selected point."
#include <Geom_Line.hxx>
#include <GeomAdaptor_Curve.hxx>
#include <GeomAPI_ExtremaCurveCurve.hxx>
+#include <GeomAPI_ProjectPointOnCurve.hxx>
#include <gp_Pln.hxx>
#include <gp_Pnt.hxx>
#include <TopoDS.hxx>
+#include <TopoDS_Edge.hxx>
#include <TopoDS_Vertex.hxx>
//==================================================================================================
return aVertex;
}
+//==================================================================================================
+std::shared_ptr<GeomAPI_Vertex> GeomAlgoAPI_PointBuilder::vertexByProjection(
+ const std::shared_ptr<GeomAPI_Vertex> theVertex,
+ const std::shared_ptr<GeomAPI_Edge> theEdge)
+{
+ std::shared_ptr<GeomAPI_Vertex> aVertex;
+
+ if (!theVertex.get() || !theEdge.get()) {
+ return aVertex;
+ }
+
+ std::shared_ptr<GeomAPI_Pnt> aProjPnt = theVertex->point();
+ gp_Pnt aPnt(aProjPnt->x(), aProjPnt->y(), aProjPnt->z());
+
+ TopoDS_Edge anEdge = TopoDS::Edge(theEdge->impl<TopoDS_Shape>());
+ double aFirstOnCurve, aLastOnCurve;
+ Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, aFirstOnCurve, aLastOnCurve);
+
+ if (aCurve.IsNull()) {
+ return aVertex;
+ }
+
+ GeomAPI_ProjectPointOnCurve aProjection(aPnt, aCurve);
+
+ if (aProjection.NbPoints() == 0) {
+ return aVertex;
+ }
+
+ gp_Pnt aNearestPoint = aProjection.NearestPoint();
+
+ aVertex.reset(new GeomAPI_Vertex(aNearestPoint.X(), aNearestPoint.Y(), aNearestPoint.Z()));
+
+ return aVertex;
+}
+
//==================================================================================================
std::shared_ptr<GeomAPI_Vertex> GeomAlgoAPI_PointBuilder::vertexByProjection(
const std::shared_ptr<GeomAPI_Vertex> theVertex,
const bool theIsPercent = false,
const bool theIsReverse = false);
+ /// \brief Creates vertex by projection another vertex on edge.
+ /// \param[in] theVertex vertex to project.
+ /// \param[in] theEdge edge for projection.
+ /// \return created vertex.
+ static std::shared_ptr<GeomAPI_Vertex>
+ vertexByProjection(const std::shared_ptr<GeomAPI_Vertex> theVertex,
+ const std::shared_ptr<GeomAPI_Edge> theEdge);
+
/// \brief Creates vertex by projection another vertex on plane.
/// \param[in] theVertex vertex to project.
/// \param[in] theFace face for projection. Should be planar.
END_INIT() \
public:
+//--------------------------------------------------------------------------------------
+#define INTERFACE_18(KIND, \
+ N_0, AN_0, T_0, C_0, \
+ N_1, AN_1, T_1, C_1, \
+ N_2, AN_2, T_2, C_2, \
+ N_3, AN_3, T_3, C_3, \
+ N_4, AN_4, T_4, C_4, \
+ N_5, AN_5, T_5, C_5, \
+ N_6, AN_6, T_6, C_6, \
+ N_7, AN_7, T_7, C_7, \
+ N_8, AN_8, T_8, C_8, \
+ N_9, AN_9, T_9, C_9, \
+ N_10, AN_10, T_10, C_10, \
+ N_11, AN_11, T_11, C_11, \
+ N_12, AN_12, T_12, C_12, \
+ N_13, AN_13, T_13, C_13, \
+ N_14, AN_14, T_14, C_14, \
+ N_15, AN_15, T_15, C_15, \
+ N_16, AN_16, T_16, C_16, \
+ N_17, AN_17, T_17, C_17) \
+ public: \
+ INTERFACE_COMMON(KIND) \
+ DEFINE_ATTRIBUTE(N_0, T_0, C_0) \
+ DEFINE_ATTRIBUTE(N_1, T_1, C_1) \
+ DEFINE_ATTRIBUTE(N_2, T_2, C_2) \
+ DEFINE_ATTRIBUTE(N_3, T_3, C_3) \
+ DEFINE_ATTRIBUTE(N_4, T_4, C_4) \
+ DEFINE_ATTRIBUTE(N_5, T_5, C_5) \
+ DEFINE_ATTRIBUTE(N_6, T_6, C_6) \
+ DEFINE_ATTRIBUTE(N_7, T_7, C_7) \
+ DEFINE_ATTRIBUTE(N_8, T_8, C_8) \
+ DEFINE_ATTRIBUTE(N_9, T_9, C_9) \
+ DEFINE_ATTRIBUTE(N_10, T_10, C_10) \
+ DEFINE_ATTRIBUTE(N_11, T_11, C_11) \
+ DEFINE_ATTRIBUTE(N_12, T_12, C_12) \
+ DEFINE_ATTRIBUTE(N_13, T_13, C_13) \
+ DEFINE_ATTRIBUTE(N_14, T_14, C_14) \
+ DEFINE_ATTRIBUTE(N_15, T_15, C_15) \
+ DEFINE_ATTRIBUTE(N_16, T_16, C_16) \
+ DEFINE_ATTRIBUTE(N_17, T_17, C_17) \
+ protected: \
+ START_INIT() \
+ SET_ATTRIBUTE(N_0, T_0, AN_0) \
+ SET_ATTRIBUTE(N_1, T_1, AN_1) \
+ SET_ATTRIBUTE(N_2, T_2, AN_2) \
+ SET_ATTRIBUTE(N_3, T_3, AN_3) \
+ SET_ATTRIBUTE(N_4, T_4, AN_4) \
+ SET_ATTRIBUTE(N_5, T_5, AN_5) \
+ SET_ATTRIBUTE(N_6, T_6, AN_6) \
+ SET_ATTRIBUTE(N_7, T_7, AN_7) \
+ SET_ATTRIBUTE(N_8, T_8, AN_8) \
+ SET_ATTRIBUTE(N_9, T_9, AN_9) \
+ SET_ATTRIBUTE(N_10, T_10, AN_10) \
+ SET_ATTRIBUTE(N_11, T_11, AN_11) \
+ SET_ATTRIBUTE(N_12, T_12, AN_12) \
+ SET_ATTRIBUTE(N_13, T_13, AN_13) \
+ SET_ATTRIBUTE(N_14, T_14, AN_14) \
+ SET_ATTRIBUTE(N_15, T_15, AN_15) \
+ SET_ATTRIBUTE(N_16, T_16, AN_16) \
+ SET_ATTRIBUTE(N_17, T_17, AN_17) \
+ END_INIT() \
+ public:
+
//--------------------------------------------------------------------------------------
#define INTERFACE_20(KIND, \
N_0, AN_0, T_0, C_0, \