// History:
// 29/03/16 - Sergey POKHODENKO - Creation of the file
-//--------------------------------------------------------------------------------------
#include "ConstructionAPI_Point.h"
-//--------------------------------------------------------------------------------------
+
#include <ModelHighAPI_Tools.h>
-//--------------------------------------------------------------------------------------
-ConstructionAPI_Point::ConstructionAPI_Point(
- const std::shared_ptr<ModelAPI_Feature> & theFeature)
+
+//==================================================================================================
+ConstructionAPI_Point::ConstructionAPI_Point(const std::shared_ptr<ModelAPI_Feature>& theFeature)
: ModelHighAPI_Interface(theFeature)
{
initialize();
}
-ConstructionAPI_Point::ConstructionAPI_Point(
- const std::shared_ptr<ModelAPI_Feature> & theFeature,
- const ModelHighAPI_Double & theX,
- const ModelHighAPI_Double & theY,
- const ModelHighAPI_Double & theZ)
+//==================================================================================================
+ConstructionAPI_Point::ConstructionAPI_Point(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+ const ModelHighAPI_Double& theX,
+ const ModelHighAPI_Double& theY,
+ const ModelHighAPI_Double& theZ)
+: ModelHighAPI_Interface(theFeature)
+{
+ if(initialize()) {
+ setByXYZ(theX, theY, theZ);
+ }
+}
+
+//==================================================================================================
+ConstructionAPI_Point::ConstructionAPI_Point(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+ const ModelHighAPI_Selection& theEdge,
+ const ModelHighAPI_Double& theDistanceValue,
+ const bool theDistancePercent,
+ const bool theReverse)
: ModelHighAPI_Interface(theFeature)
{
- if (initialize())
- setPoint(theX, theY, theZ);
+ if(initialize()) {
+ setByDistanceOnEdge(theEdge, theDistanceValue, theDistancePercent, theReverse);
+ }
}
+//==================================================================================================
ConstructionAPI_Point::~ConstructionAPI_Point()
{
}
-//--------------------------------------------------------------------------------------
-void ConstructionAPI_Point::setPoint(const ModelHighAPI_Double & theX,
- const ModelHighAPI_Double & theY,
- const ModelHighAPI_Double & theZ)
+//==================================================================================================
+void ConstructionAPI_Point::setByXYZ(const ModelHighAPI_Double& theX,
+ const ModelHighAPI_Double& theY,
+ const ModelHighAPI_Double& theZ)
{
+ fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_XYZ(), mycreationMethod);
fillAttribute(theX, myx);
fillAttribute(theY, myy);
fillAttribute(theZ, myz);
execute();
}
-//--------------------------------------------------------------------------------------
-PointPtr addPoint(
- const std::shared_ptr<ModelAPI_Document> & thePart,
- const ModelHighAPI_Double& theX,
- const ModelHighAPI_Double& theY,
- const ModelHighAPI_Double& theZ)
+//==================================================================================================
+void ConstructionAPI_Point::setByDistanceOnEdge(const ModelHighAPI_Selection& theEdge,
+ const ModelHighAPI_Double& theDistanceValue,
+ const bool theDistancePercent,
+ const bool theReverse)
+{
+ fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_DISTANCE_ON_EDGE(), mycreationMethod);
+ fillAttribute(theEdge, myedge);
+ fillAttribute(theDistanceValue, mydistanceValue);
+ fillAttribute(theDistancePercent, mydistancePercent);
+ fillAttribute(theReverse, myreverse);
+
+ execute();
+}
+
+//==================================================================================================
+PointPtr addPoint(const std::shared_ptr<ModelAPI_Document>& thePart,
+ const ModelHighAPI_Double& theX,
+ const ModelHighAPI_Double& theY,
+ const ModelHighAPI_Double& theZ)
{
// TODO(spo): check that thePart is not empty
std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
return PointPtr(new ConstructionAPI_Point(aFeature, theX, theY, theZ));
}
+
+//==================================================================================================
+PointPtr addPoint(const std::shared_ptr<ModelAPI_Document> & thePart,
+ const ModelHighAPI_Selection& theEdge,
+ const ModelHighAPI_Double& theDistanceValue,
+ const bool theDistancePercent,
+ const bool theReverse)
+{
+ // TODO(spo): check that thePart is not empty
+ std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
+ return PointPtr(new ConstructionAPI_Point(aFeature, theEdge, theDistanceValue, theDistancePercent, theReverse));
+}
#ifndef SRC_CONSTRUCTIONAPI_CONSTRUCTIONAPI_POINT_H_
#define SRC_CONSTRUCTIONAPI_CONSTRUCTIONAPI_POINT_H_
-//--------------------------------------------------------------------------------------
#include "ConstructionAPI.h"
#include <ConstructionPlugin_Point.h>
#include <ModelHighAPI_Interface.h>
#include <ModelHighAPI_Macro.h>
-//--------------------------------------------------------------------------------------
+
class ModelAPI_AttributeDouble;
class ModelAPI_Document;
class ModelHighAPI_Double;
-//--------------------------------------------------------------------------------------
-/**\class ConstructionAPI_Point
- * \ingroup CPPHighAPI
- * \brief Interface for Point feature
- */
-class ConstructionAPI_Point : public ModelHighAPI_Interface
+
+/// \class ConstructionAPI_Point
+/// \ingroup CPPHighAPI
+/// \brief Interface for Point feature
+class ConstructionAPI_Point: public ModelHighAPI_Interface
{
public:
/// Constructor without values
CONSTRUCTIONAPI_EXPORT
- explicit ConstructionAPI_Point(const std::shared_ptr<ModelAPI_Feature> & theFeature);
+ explicit ConstructionAPI_Point(const std::shared_ptr<ModelAPI_Feature>& theFeature);
+
+ /// Constructor with values
+ CONSTRUCTIONAPI_EXPORT
+ ConstructionAPI_Point(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+ const ModelHighAPI_Double& theX,
+ const ModelHighAPI_Double& theY,
+ const ModelHighAPI_Double& theZ);
+
/// Constructor with values
CONSTRUCTIONAPI_EXPORT
- ConstructionAPI_Point(const std::shared_ptr<ModelAPI_Feature> & theFeature,
- const ModelHighAPI_Double & theX,
- const ModelHighAPI_Double & theY,
- const ModelHighAPI_Double & theZ);
+ ConstructionAPI_Point(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+ const ModelHighAPI_Selection& theEdge,
+ const ModelHighAPI_Double& theDistanceValue,
+ const bool theDistancePercent = false,
+ const bool theReverse = false);
+
/// Destructor
CONSTRUCTIONAPI_EXPORT
virtual ~ConstructionAPI_Point();
- INTERFACE_3(ConstructionPlugin_Point::ID(),
+ INTERFACE_8(ConstructionPlugin_Point::ID(),
+ creationMethod, ConstructionPlugin_Point::CREATION_METHOD(), ModelAPI_AttributeString, /** Creation method */,
x, ConstructionPlugin_Point::X(), ModelAPI_AttributeDouble, /** X attribute */,
y, ConstructionPlugin_Point::Y(), ModelAPI_AttributeDouble, /** Y attribute */,
- z, ConstructionPlugin_Point::Z(), ModelAPI_AttributeDouble, /** Z attribute */
+ z, ConstructionPlugin_Point::Z(), ModelAPI_AttributeDouble, /** Z attribute */,
+ edge, ConstructionPlugin_Point::EDGE(), ModelAPI_AttributeSelection, /** Edge attribute */,
+ distanceValue, ConstructionPlugin_Point::DISTANCE_VALUE(), ModelAPI_AttributeDouble, /** Distance value attribute */,
+ distancePercent, ConstructionPlugin_Point::DISTANCE_PERCENT(), ModelAPI_AttributeBoolean, /** Distance percent attribute */,
+ reverse, ConstructionPlugin_Point::REVERSE(), ModelAPI_AttributeBoolean, /** Reverse attribute */
)
/// Set point values
CONSTRUCTIONAPI_EXPORT
- void setPoint(const ModelHighAPI_Double & theX,
+ void setByXYZ(const ModelHighAPI_Double & theX,
const ModelHighAPI_Double & theY,
const ModelHighAPI_Double & theZ);
+
+ /// Set edge and distance on it for point
+ CONSTRUCTIONAPI_EXPORT
+ void setByDistanceOnEdge(const ModelHighAPI_Selection& theEdge,
+ const ModelHighAPI_Double& theDistanceValue,
+ const bool theDistancePercent = false,
+ const bool theReverse = false);
};
-//! Pointer on Point object
+/// Pointer on Point object
typedef std::shared_ptr<ConstructionAPI_Point> PointPtr;
-/**\ingroup CPPHighAPI
- * \brief Create Point feature
- */
+/// \ingroup CPPHighAPI
+/// \brief Create Point feature
CONSTRUCTIONAPI_EXPORT
PointPtr addPoint(const std::shared_ptr<ModelAPI_Document> & thePart,
const ModelHighAPI_Double & theX,
const ModelHighAPI_Double & theY,
const ModelHighAPI_Double & theZ);
-//--------------------------------------------------------------------------------------
-//--------------------------------------------------------------------------------------
+/// \ingroup CPPHighAPI
+/// \brief Create Point feature
+CONSTRUCTIONAPI_EXPORT
+PointPtr addPoint(const std::shared_ptr<ModelAPI_Document> & thePart,
+ const ModelHighAPI_Selection& theEdge,
+ const ModelHighAPI_Double& theDistanceValue,
+ const bool theDistancePercent = false,
+ const bool theReverse = false);
+
#endif /* SRC_CONSTRUCTIONAPI_CONSTRUCTIONAPI_POINT_H_ */
self.assertEqual(0, point.y().value())
self.assertEqual(0, point.z().value())
- point.setPoint(10, "20", "x + 30")
+ point.setByXYZ(10, "20", "x + 30")
self.assertEqual(10, point.x().value())
self.assertEqual("20", point.y().text())
self.assertEqual("x + 30", point.z().text())
ConstructionPlugin.h
ConstructionPlugin_Plugin.h
ConstructionPlugin_Point.h
- ConstructionPlugin_Axis.h
- ConstructionPlugin_Plane.h
+ ConstructionPlugin_Axis.h
+ ConstructionPlugin_Plane.h
)
SET(PROJECT_SOURCES
ConstructionPlugin_Plugin.cpp
ConstructionPlugin_Point.cpp
- ConstructionPlugin_Axis.cpp
- ConstructionPlugin_Plane.cpp
+ ConstructionPlugin_Axis.cpp
+ ConstructionPlugin_Plane.cpp
)
SET(XML_RESOURCES
// Author: Mikhail PONIKAROV
#include "ConstructionPlugin_Point.h"
-#include "ModelAPI_Session.h"
-#include "ModelAPI_Document.h"
-#include "ModelAPI_Data.h"
-#include "ModelAPI_AttributeDouble.h"
+
+#include <ModelAPI_AttributeBoolean.h>
+#include <ModelAPI_AttributeDouble.h>
+#include <ModelAPI_AttributeSelection.h>
+#include <ModelAPI_AttributeString.h>
#include <ModelAPI_ResultConstruction.h>
-#include <GeomAlgoAPI_PointBuilder.h>
-#include <GeomAPI_Pnt.h>
-#include <Config_PropManager.h>
+#include <GeomAlgoAPI_PointBuilder.h>
+#include <GeomAlgoAPI_ShapeTools.h>
-using namespace std;
+#include <GeomAPI_Edge.h>
+#include <GeomAPI_Pnt.h>
+//==================================================================================================
ConstructionPlugin_Point::ConstructionPlugin_Point()
{
}
+//==================================================================================================
const std::string& ConstructionPlugin_Point::getKind()
{
static std::string MY_KIND = ConstructionPlugin_Point::ID();
return MY_KIND;
}
+//==================================================================================================
void ConstructionPlugin_Point::initAttributes()
{
- data()->addAttribute(ConstructionPlugin_Point::X(), ModelAPI_AttributeDouble::typeId());
- data()->addAttribute(ConstructionPlugin_Point::Y(), ModelAPI_AttributeDouble::typeId());
- data()->addAttribute(ConstructionPlugin_Point::Z(), ModelAPI_AttributeDouble::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());
+ data()->addAttribute(REVERSE(), ModelAPI_AttributeBoolean::typeId());
}
+//==================================================================================================
void ConstructionPlugin_Point::execute()
{
- std::shared_ptr<GeomAPI_Pnt> aPnt(
- new GeomAPI_Pnt(data()->real(ConstructionPlugin_Point::X())->value(),
- data()->real(ConstructionPlugin_Point::Y())->value(),
- data()->real(ConstructionPlugin_Point::Z())->value()));
-
- std::shared_ptr<ModelAPI_ResultConstruction> aConstr = document()->createConstruction(data());
- aConstr->setShape(GeomAlgoAPI_PointBuilder::point(aPnt));
- setResult(aConstr);
+ GeomShapePtr aShape;
+
+ std::string aCreationMethod = string(CREATION_METHOD())->value();
+ if(aCreationMethod == CREATION_METHOD_BY_XYZ()) {
+ aShape = createByXYZ();
+ } else if(aCreationMethod == CREATION_METHOD_BY_DISTANCE_ON_EDGE()) {
+ aShape = createByDistanceOnEdge();
+ }
+
+ if(aShape.get()) {
+ std::shared_ptr<ModelAPI_ResultConstruction> aConstr = document()->createConstruction(data());
+ aConstr->setShape(aShape);
+ setResult(aConstr);
+ }
}
-bool ConstructionPlugin_Point::customisePresentation(ResultPtr theResult,
+//==================================================================================================
+bool ConstructionPlugin_Point::customisePresentation(ResultPtr theResult,
AISObjectPtr thePrs,
- std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs)
+ std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs)
{
bool isCustomized = theDefaultPrs.get() != NULL &&
theDefaultPrs->customisePresentation(theResult, thePrs, theDefaultPrs);
//thePrs->setPointMarker(1, 1.); // Set point as a '+' symbol
return true;
}
+
+//==================================================================================================
+GeomShapePtr ConstructionPlugin_Point::createByXYZ()
+{
+ return GeomAlgoAPI_PointBuilder::point(real(X())->value(),
+ real(Y())->value(),
+ real(Z())->value());
+}
+
+//==================================================================================================
+GeomShapePtr ConstructionPlugin_Point::createByDistanceOnEdge()
+{
+ // Get edge.
+ AttributeSelectionPtr anEdgeSelection = selection(EDGE());
+ GeomShapePtr aShape = anEdgeSelection->value();
+ if(!aShape.get()) {
+ aShape = anEdgeSelection->context()->shape();
+ }
+ std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge(aShape));
+
+ // Get distance value and percent flag.
+ double aValue = real(DISTANCE_VALUE())->value();
+ bool anIsPercent = boolean(DISTANCE_PERCENT())->value();
+
+ // Get reverse flag.
+ bool anIsReverse = boolean(REVERSE())->value();
+
+ return GeomAlgoAPI_ShapeTools::findVertexOnEdge(anEdge, aValue, anIsPercent, anIsReverse);
+}
#define ConstructionPlugin_Point_H_
#include "ConstructionPlugin.h"
+
+#include <GeomAPI_ICustomPrs.h>
#include <ModelAPI_Feature.h>
#include <ModelAPI_Result.h>
-#include <GeomAPI_ICustomPrs.h>
-/**\class ConstructionPlugin_Point
- * \ingroup Plugins
- * \brief Feature for creation of the new part in PartSet.
- */
-class ConstructionPlugin_Point : public ModelAPI_Feature, public GeomAPI_ICustomPrs
+/// \class ConstructionPlugin_Point
+/// \ingroup Plugins
+/// \brief Feature for creation of the new part in PartSet.
+class ConstructionPlugin_Point: public ModelAPI_Feature, public GeomAPI_ICustomPrs
{
- public:
- /// Returns the kind of a feature
+public:
+ /// Returns the kind of a feature.
CONSTRUCTIONPLUGIN_EXPORT virtual const std::string& getKind();
- /// Point kind
+ /// Point kind.
inline static const std::string& ID()
{
static const std::string CONSTRUCTION_POINT_KIND("Point");
return CONSTRUCTION_POINT_KIND;
}
- /// attribute name for X coordinate
+ /// 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_XYZ()
+ {
+ static const std::string MY_CREATION_METHOD_ID("by_xyz");
+ return MY_CREATION_METHOD_ID;
+ }
+
+ /// Attribute name for creation method.
+ inline static const std::string& CREATION_METHOD_BY_DISTANCE_ON_EDGE()
+ {
+ static const std::string MY_CREATION_METHOD_ID("by_distance_on_edge");
+ return MY_CREATION_METHOD_ID;
+ }
+
+ /// Attribute name for X coordinate.
inline static const std::string& X()
{
static const std::string POINT_ATTR_X("x");
return POINT_ATTR_X;
}
- /// attribute name for Y coordinate
+
+ /// Attribute name for Y coordinate.
inline static const std::string& Y()
{
static const std::string POINT_ATTR_Y("y");
return POINT_ATTR_Y;
}
- /// attribute name for Z coordinate
+
+ /// Attribute name for Z coordinate.
inline static const std::string& Z()
{
static const std::string POINT_ATTR_Z("z");
return POINT_ATTR_Z;
}
- /// Creates a new part document if needed
+ /// Attribute name for seleted edge.
+ inline static const std::string& EDGE()
+ {
+ static const std::string ATTR_ID("edge");
+ return ATTR_ID;
+ }
+
+ /// Attribute name for distance.
+ inline static const std::string& DISTANCE_VALUE()
+ {
+ static const std::string ATTR_ID("value");
+ return ATTR_ID;
+ }
+
+ /// Attribute name for percent flag.
+ inline static const std::string& DISTANCE_PERCENT()
+ {
+ static const std::string ATTR_ID("percent");
+ return ATTR_ID;
+ }
+
+ /// Attribute name for reverse flag.
+ inline static const std::string& REVERSE()
+ {
+ static const std::string ATTR_ID("reverse");
+ return ATTR_ID;
+ }
+
+ /// Creates a new part document if needed.
CONSTRUCTIONPLUGIN_EXPORT virtual void execute();
- /// Request for initialization of data model of the feature: adding all attributes
+ /// Request for initialization of data model of the feature: adding all attributes.
CONSTRUCTIONPLUGIN_EXPORT virtual void initAttributes();
- /// Construction result is allways recomuted on the fly
+ /// Construction result is allways recomuted on the fly.
CONSTRUCTIONPLUGIN_EXPORT virtual bool isPersistentResult() {return false;}
/// Use plugin manager for features creation
/// Customize presentation of the feature
virtual bool customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs);
+
+private:
+ std::shared_ptr<GeomAPI_Shape> createByXYZ();
+ std::shared_ptr<GeomAPI_Shape> createByDistanceOnEdge();
+
};
#endif
aPointFeature = aPart.addFeature("Point")
aPointFeatureData = aPointFeature.data()
assert(aPointFeatureData is not None)
+aPointFeatureData.string("creation_method").setValue("by_xyz")
aPointFeatureData.real("x").setValue(0.)
aPointFeatureData.real("y").setValue(0.)
aPointFeatureData.real("z").setValue(0.)
aPointFeature = aPart.addFeature("Point")
aPointFeatureData = aPointFeature.data()
assert(aPointFeatureData is not None)
+aPointFeatureData.string("creation_method").setValue("by_xyz")
aPointFeatureData.real("x").setValue(0.)
aPointFeatureData.real("y").setValue(0.)
aPointFeatureData.real("z").setValue(100.)
aFeature = aDoc.addFeature("Point")
aFeatureData = aFeature.data()
assert(aFeatureData is not None)
+aFeatureData.string("creation_method").setValue("by_xyz")
aFeatureData.real("x").setValue(0.)
aFeatureData.real("y").setValue(0.)
aFeatureData.real("z").setValue(0.)
<!-- Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
<source>
- <doublevalue id="x" label="X " tooltip="X coordinate" default="0"/>
- <doublevalue id="y" label="Y " tooltip="Y coordinate" default="0"/>
- <doublevalue id="z" label="Z " tooltip="Z coordinate" default="0"/>
+ <toolbox id="creation_method">
+ <box id="by_xyz"
+ title="By X, Y, Z"
+ tooltip="Point at a given distance from the origin."
+ icon="icons/Construction/point_by_xyz_32x32.png">
+ <doublevalue id="x"
+ label="X "
+ tooltip="X coordinate."
+ icon="icons/Construction/x_size.png"
+ default="0"/>
+ <doublevalue id="y"
+ label="Y "
+ tooltip="Y coordinate."
+ icon="icons/Construction/y_size.png"
+ default="0"/>
+ <doublevalue id="z"
+ label="Z "
+ tooltip="Z coordinate."
+ icon="icons/Construction/z_size.png"
+ default="0"/>
+ </box>
+ <box id="by_distance_on_edge"
+ title="By distance on edge"
+ tooltip="Point on an edge, at a given distance of one of its end."
+ icon="icons/Construction/point_by_distance_on_edge_32x32.png">
+ <shape_selector id="edge"
+ label="Edge"
+ tooltip="Edge for creating point on it."
+ icon="icons/Construction/edge.png"
+ shape_types="edge">
+ <validator id="GeomValidators_Finite"/>
+ </shape_selector>
+ <groupbox title="Distance">
+ <doublevalue id="value"
+ label="Value"
+ tooltip="Distance value."
+ icon="icons/Construction/distance_value.png"
+ default="50"/>
+ <boolvalue id="percent"
+ label="Percent(%)"
+ tooltip="Distance in percent from length."
+ default="true"/>
+ </groupbox>
+ <boolvalue id="reverse"
+ label="Reverse"
+ tooltip="Distance from edge end point."
+ default="false"/>
+ </box>
+ </toolbox>
</source>
#include<GeomAPI_Dir.h>
#include<GeomAPI_Lin.h>
+#include <BRepAdaptor_Curve.hxx>
+
#include <TopoDS_Shape.hxx>
#include <TopoDS_Edge.hxx>
#include <TopoDS.hxx>
#include <gp_Ax1.hxx>
#include <gp_Pln.hxx>
+#include <GCPnts_AbscissaPoint.hxx>
+
GeomAPI_Edge::GeomAPI_Edge()
{
TopoDS_Edge* anEdge = new TopoDS_Edge;
}
return inPlane;
}
+
+double GeomAPI_Edge::length() const
+{
+ const TopoDS_Edge& anEdge = TopoDS::Edge(impl<TopoDS_Shape>());
+ return GCPnts_AbscissaPoint::Length(BRepAdaptor_Curve(anEdge));
+}
/// Returns true, if the edge is fully placed in the specified plane
GEOMAPI_EXPORT
bool isInPlane(const std::shared_ptr<GeomAPI_Pln> thePlane) const;
+
+ /// Returns edge length.
+ GEOMAPI_EXPORT
+ double length() const;
};
#endif
#include <BRepBuilderAPI_FindPlane.hxx>
#include <BRepBuilderAPI_MakeEdge.hxx>
#include <BRepBuilderAPI_MakeFace.hxx>
+#include <BRepBuilderAPI_MakeVertex.hxx>
#include <BRepCheck_Analyzer.hxx>
#include <BRepExtrema_DistShapeShape.hxx>
#include <BRepExtrema_ExtCF.hxx>
#include <BRepGProp.hxx>
#include <BRepTools.hxx>
#include <BRepTopAdaptor_FClass2d.hxx>
+#include <GCPnts_AbscissaPoint.hxx>
#include <Geom_Curve.hxx>
#include <Geom2d_Curve.hxx>
#include <BRepLib_CheckCurveOnSurface.hxx>
BRepExtrema_ExtCF anExt(anEdge, aFace);
return anExt.IsParallel() == Standard_True;
}
+
+//==================================================================================================
+std::shared_ptr<GeomAPI_Vertex> GeomAlgoAPI_ShapeTools::findVertexOnEdge(const std::shared_ptr<GeomAPI_Edge> theEdge,
+ const double theValue,
+ const bool theIsPercent,
+ const bool theIsReverse)
+{
+ std::shared_ptr<GeomAPI_Vertex> aVertex;
+
+ if(!theEdge.get()) {
+ return aVertex;
+ }
+
+ double aValue = theValue;
+ if(theIsPercent) {
+ aValue = theEdge->length() / 100.0 * aValue;
+ }
+
+ const TopoDS_Edge& anEdge = TopoDS::Edge(theEdge->impl<TopoDS_Shape>());
+ Standard_Real aUFirst, aULast;
+ Handle(Geom_Curve) anEdgeCurve = BRep_Tool::Curve(anEdge, aUFirst, aULast);
+
+ if(!anEdgeCurve.IsNull() ) {
+ Handle(Geom_Curve) aReOrientedCurve = anEdgeCurve;
+
+ if(theIsReverse) {
+ aReOrientedCurve = anEdgeCurve->Reversed();
+ aUFirst = anEdgeCurve->ReversedParameter(aULast);
+ }
+
+ // Get the point by length
+ GeomAdaptor_Curve anAdapCurve = GeomAdaptor_Curve(aReOrientedCurve);
+ GCPnts_AbscissaPoint anAbsPnt(anAdapCurve, aValue, aUFirst);
+ Standard_Real aParam = anAbsPnt.Parameter();
+ gp_Pnt aPnt = anAdapCurve.Value(aParam);
+ BRepBuilderAPI_MakeVertex aMkVertex(aPnt);
+ const TopoDS_Vertex& aShape = aMkVertex.Vertex();
+ aVertex.reset(new GeomAPI_Vertex());
+ aVertex->setImpl(new TopoDS_Vertex(aShape));
+ }
+
+ return aVertex;
+}
GEOMALGOAPI_EXPORT static bool isParallel(const std::shared_ptr<GeomAPI_Edge> theEdge,
const std::shared_ptr<GeomAPI_Face> theFace);
+ /// \brief Creates vertex by edge and distance on it.
+ /// \param[in] theEdge edge.
+ /// \param[in] theValue distance value.
+ /// \param[in] theIsPercent if true theValue will be treated as a percentage of theEdge total length.
+ /// \param[in] theIsReverse if true the distance will be measured from the edge end point.
+ /// \ return created vertex.
+ GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Vertex> findVertexOnEdge(const std::shared_ptr<GeomAPI_Edge> theEdge,
+ const double theValue,
+ const bool theIsPercent = false,
+ const bool theIsReverse = false);
+
};
#endif
{
bool aValid = true;
- if (theAttribute->attributeType() == ModelAPI_AttributeSelectionList::typeId()) {
+ const std::string anAttributeType = theAttribute->attributeType();
+
+ if(anAttributeType == ModelAPI_AttributeSelection::typeId()) {
+ AttributeSelectionPtr aSelectionAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
+ ResultPtr aResult = aSelectionAttr->context();
+ ResultConstructionPtr aConstruction = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aResult);
+ if (aConstruction.get() && aConstruction->isInfinite()) {
+ aValid = false;
+ theError = "Infinite result is selected.";
+ }
+ } else if(anAttributeType == ModelAPI_AttributeSelectionList::typeId()) {
AttributeSelectionListPtr aSelectionListAttr =
std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
for (int i = 0, aSize = aSelectionListAttr->size(); i < aSize; i++) {
double theX, double theY, double theZ)
{
std::shared_ptr<ModelAPI_Feature> aPoint = theDoc->addFeature("Point");
+ aPoint->string("creation_method")->setValue("by_xyz");
aPoint->real("x")->setValue(theX);
aPoint->real("y")->setValue(theY);
aPoint->real("z")->setValue(theZ);
aFeature = aDoc.addFeature("Point")\r
# Since validators are introduced we have to initialize all\r
# the feature's attributes\r
+aFeature.string("creation_method").setValue("by_xyz")\r
aFeature.real("x").setValue(1.)\r
aFeature.real("y").setValue(-1.)\r
aFeature.real("z").setValue(0.)\r
"""
TestConstraintCoincidence.py
Unit test of SketchPlugin_ConstraintCoincidence class
-
+
SketchPlugin_Constraint
static const std::string MY_CONSTRAINT_VALUE("ConstraintValue");
static const std::string MY_FLYOUT_VALUE_PNT("ConstraintFlyoutValuePnt");
static const std::string MY_ENTITY_B("ConstraintEntityB");
static const std::string MY_ENTITY_C("ConstraintEntityC");
static const std::string MY_ENTITY_D("ConstraintEntityD");
-
+
SketchPlugin_ConstraintCoincidence
static const std::string MY_CONSTRAINT_COINCIDENCE_ID("SketchConstraintCoincidence");
data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttr::typeId());
# add an origin
aSession.startOperation()
aFeature = aDocument.addFeature("Point")
+aFeature.string("creation_method").setValue("by_xyz")
aFeature.real("x").setValue(0.)
aFeature.real("y").setValue(0.)
aFeature.real("z").setValue(0.)
"""
TestConstraintCoincidence.py
Unit test of SketchPlugin_ConstraintCoincidence class
-
+
SketchPlugin_Constraint
static const std::string MY_CONSTRAINT_VALUE("ConstraintValue");
static const std::string MY_FLYOUT_VALUE_PNT("ConstraintFlyoutValuePnt");
static const std::string MY_ENTITY_B("ConstraintEntityB");
static const std::string MY_ENTITY_C("ConstraintEntityC");
static const std::string MY_ENTITY_D("ConstraintEntityD");
-
+
SketchPlugin_ConstraintCoincidence
static const std::string MY_CONSTRAINT_COINCIDENCE_ID("SketchConstraintCoincidence");
data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttr::typeId());
# add an origin
aSession.startOperation()
aFeature = aDocument.addFeature("Point")
+aFeature.string("creation_method").setValue("by_xyz")
aFeature.real("x").setValue(0.)
aFeature.real("y").setValue(0.)
aFeature.real("z").setValue(0.)