// Created: 23 Apr 2014
// Author: Mikhail PONIKAROV
-#include<GeomAPI_Pln.h>
+#include <GeomAPI_Pln.h>
#include <GeomAPI_Ax3.h>
#include <GeomAPI_Pnt.h>
#include <GeomAPI_Dir.h>
+#include <GeomAPI_Lin.h>
+#include <GeomAPI_XYZ.h>
-#include<gp_Pln.hxx>
+#include <gp_Pln.hxx>
using namespace std;
{
}
-std::shared_ptr<GeomAPI_Pnt> GeomAPI_Pln::location()
+std::shared_ptr<GeomAPI_Pnt> GeomAPI_Pln::location() const
{
gp_Pnt aLoc = impl<gp_Pln>().Location();
return std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aLoc.X(), aLoc.Y(), aLoc.Z()));
}
-std::shared_ptr<GeomAPI_Dir> GeomAPI_Pln::direction()
+std::shared_ptr<GeomAPI_Dir> GeomAPI_Pln::direction() const
{
const gp_Dir& aDir = impl<gp_Pln>().Axis().Direction();
return std::shared_ptr<GeomAPI_Dir>(new GeomAPI_Dir(aDir.X(), aDir.Y(), aDir.Z()));
const gp_Pln& anOtherPln = thePlane->impl<gp_Pln>();
return (aMyPln.Contains(anOtherPln.Location(), theTolerance) && aMyPln.Axis().IsParallel(anOtherPln.Axis(), theTolerance));
}
+
+std::shared_ptr<GeomAPI_Pnt> GeomAPI_Pln::intersect(const std::shared_ptr<GeomAPI_Lin>& theLine) const
+{
+ std::shared_ptr<GeomAPI_XYZ> aLineDir = theLine->direction()->xyz();
+ std::shared_ptr<GeomAPI_XYZ> aLineLoc = theLine->location()->xyz();
+
+ std::shared_ptr<GeomAPI_XYZ> aNormal = direction()->xyz();
+ std::shared_ptr<GeomAPI_XYZ> aLocation = location()->xyz();
+
+ double aDot = aNormal->dot(aLineDir);
+ if (Abs(aDot) < Precision::SquareConfusion())
+ return std::shared_ptr<GeomAPI_Pnt>();
+
+ double aParam = aNormal->dot(aLocation->decreased(aLineLoc)) / aDot;
+ return std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aLineLoc->added(aLineDir->multiplied(aParam))));
+}
class GeomAPI_Ax3;
class GeomAPI_Pnt;
class GeomAPI_Dir;
+class GeomAPI_Lin;
/**\class GeomAPI_Pln
* \ingroup DataModel
/// Returns a point of this plane
GEOMAPI_EXPORT
- std::shared_ptr<GeomAPI_Pnt> location();
+ std::shared_ptr<GeomAPI_Pnt> location() const;
/// Returns a plane normal
GEOMAPI_EXPORT
- std::shared_ptr<GeomAPI_Dir> direction();
+ std::shared_ptr<GeomAPI_Dir> direction() const;
/// Returns the plane coefficients (Ax+By+Cz+D=0)
GEOMAPI_EXPORT
/// Returns true if planes are coincident.
GEOMAPI_EXPORT
bool isCoincident(const std::shared_ptr<GeomAPI_Pln> thePlane, const double theTolerance = 1.e-7);
+
+ /// Returns intersection point or empty if no intersections
+ GEOMAPI_EXPORT
+ std::shared_ptr<GeomAPI_Pnt> intersect(const std::shared_ptr<GeomAPI_Lin>& theLine) const;
};
#endif
SketchPlugin_SketchEntity.h
SketchPlugin_Line.h
SketchPlugin_Point.h
+ SketchPlugin_IntersectionPoint.h
SketchPlugin_Circle.h
SketchPlugin_Arc.h
SketchPlugin_Constraint.h
SketchPlugin_SketchEntity.cpp
SketchPlugin_Line.cpp
SketchPlugin_Point.cpp
+ SketchPlugin_IntersectionPoint.cpp
SketchPlugin_Circle.cpp
SketchPlugin_Arc.cpp
SketchPlugin_Constraint.cpp
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
+// File: SketchPlugin_IntersectionPoint.cpp
+// Created: 07 May 2014
+// Author: Artem ZHIDKOV
+
+#include "SketchPlugin_IntersectionPoint.h"
+
+#include <ModelAPI_AttributeRefAttr.h>
+
+#include <GeomAPI_Edge.h>
+#include <GeomAPI_Lin.h>
+#include <GeomDataAPI_Point2D.h>
+
+SketchPlugin_IntersectionPoint::SketchPlugin_IntersectionPoint()
+ : SketchPlugin_Point()
+{
+}
+
+void SketchPlugin_IntersectionPoint::initDerivedClassAttributes()
+{
+ data()->addAttribute(EXTERNAL_LINE_ID(), ModelAPI_AttributeRefAttr::typeId());
+
+ SketchPlugin_Point::initDerivedClassAttributes();
+}
+
+void SketchPlugin_IntersectionPoint::execute()
+{
+ SketchPlugin_Sketch* aSketch = sketch();
+ if (aSketch) {
+ computePoint();
+ SketchPlugin_Point::execute();
+
+ // set this feature as external
+ data()->selection(EXTERNAL_ID())->setValue(lastResult(), lastResult()->shape());
+ }
+}
+
+void SketchPlugin_IntersectionPoint::move(double theDeltaX, double theDeltaY)
+{
+}
+
+void SketchPlugin_IntersectionPoint::attributeChanged(const std::string& theID)
+{
+ if (theID == EXTERNAL_LINE_ID()) {
+ // compute intersection between line and sketch plane
+ computePoint();
+ }
+}
+
+void SketchPlugin_IntersectionPoint::computePoint()
+{
+ AttributeRefAttrPtr aLineRefAttr =
+ std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(attribute(EXTERNAL_LINE_ID()));
+ ResultPtr aLineResult = std::dynamic_pointer_cast<ModelAPI_Result>(aLineRefAttr->object());
+ if (!aLineResult)
+ return;
+
+ std::shared_ptr<GeomAPI_Edge> aLinearEdge =
+ std::dynamic_pointer_cast<GeomAPI_Edge>(aLineResult->shape());
+ std::shared_ptr<GeomAPI_Lin> aLine = aLinearEdge->line();
+ std::shared_ptr<GeomAPI_Pln> aSketchPlane = sketch()->plane();
+
+ std::shared_ptr<GeomAPI_Pnt> anIntersection = aSketchPlane->intersect(aLine);
+ if (!anIntersection)
+ return;
+
+ std::shared_ptr<GeomDataAPI_Point2D> aCoordAttr =
+ std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(COORD_ID()));
+ aCoordAttr->setValue(sketch()->to2D(anIntersection));
+}
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
+// File: SketchPlugin_IntersectionPoint.h
+// Created: 07 May 2014
+// Author: Artem ZHIDKOV
+
+#ifndef SketchPlugin_IntersectionPoint_H_
+#define SketchPlugin_IntersectionPoint_H_
+
+#include "SketchPlugin_Point.h"
+
+/**\class SketchPlugin_IntersectionPoint
+ * \ingroup Plugins
+ * \brief Feature for creation of external point as an intersection
+ * between external edge and a plane of the sketch.
+ */
+class SketchPlugin_IntersectionPoint : public SketchPlugin_Point
+{
+public:
+ /// Point feature kind
+ inline static const std::string& ID()
+ {
+ static const std::string MY_POINT_ID("SketchIntersectionPoint");
+ return MY_POINT_ID;
+ }
+ /// Returns the kind of a feature
+ virtual const std::string& getKind()
+ {
+ static std::string MY_KIND = SketchPlugin_IntersectionPoint::ID();
+ return MY_KIND;
+ }
+
+ static const std::string& EXTERNAL_LINE_ID()
+ {
+ static std::string MY_LINE_ID("ExternalLine");
+ return MY_LINE_ID;
+ }
+
+ /// Returns true because intersection point is always external
+ virtual bool isFixed()
+ { return true; }
+
+ /// Creates a new part document if needed
+ SKETCHPLUGIN_EXPORT virtual void execute();
+
+ /// Moves the feature
+ /// \param theDeltaX the delta for X coordinate is moved
+ /// \param theDeltaY the delta for Y coordinate is moved
+ SKETCHPLUGIN_EXPORT virtual void move(const double theDeltaX, const double theDeltaY);
+
+ /// Called on change of any argument-attribute of this object: for external point
+ SKETCHPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID);
+
+ /// Use plugin manager for features creation
+ SketchPlugin_IntersectionPoint();
+
+protected:
+ /// \brief Initializes attributes of derived class.
+ virtual void initDerivedClassAttributes();
+
+private:
+ /// \brief Find intersection between a line and a sketch plane
+ void computePoint();
+};
+
+#endif
#include <SketchPlugin_Sketch.h>
#include <SketchPlugin_Line.h>
#include <SketchPlugin_Point.h>
+#include <SketchPlugin_IntersectionPoint.h>
#include <SketchPlugin_Circle.h>
#include <SketchPlugin_Arc.h>
#include <SketchPlugin_ConstraintAngle.h>
new SketchPlugin_MiddlePointAttrValidator);
aFactory->registerValidator("SketchPlugin_ArcTangentPoint",
new SketchPlugin_ArcTangentPointValidator);
+ aFactory->registerValidator("SketchPlugin_IntersectionValidator",
+ new SketchPlugin_IntersectionValidator);
// register this plugin
ModelAPI_Session::get()->registerPlugin(this);
return FeaturePtr(new SketchPlugin_Sketch);
} else if (theFeatureID == SketchPlugin_Point::ID()) {
return FeaturePtr(new SketchPlugin_Point);
+ } else if (theFeatureID == SketchPlugin_IntersectionPoint::ID()) {
+ return FeaturePtr(new SketchPlugin_IntersectionPoint);
} else if (theFeatureID == SketchPlugin_Line::ID()) {
return FeaturePtr(new SketchPlugin_Line);
} else if (theFeatureID == SketchPlugin_Circle::ID()) {
!(aNormal->x() == 0 && aNormal->y() == 0 && aNormal->z() == 0);
aMsg->setState(SketchPlugin_Point::ID(), aHasSketchPlane);
+ aMsg->setState(SketchPlugin_IntersectionPoint::ID(), aHasSketchPlane);
aMsg->setState(SketchPlugin_Line::ID(), aHasSketchPlane);
aMsg->setState(SketchPlugin_Circle::ID(), aHasSketchPlane);
aMsg->setState(SketchPlugin_Arc::ID(), aHasSketchPlane);
#include <ModelAPI_Session.h>
#include <ModelAPI_ResultConstruction.h>
+#include <GeomAPI_Lin.h>
+#include <GeomAPI_Edge.h>
#include <GeomAPI_Vertex.h>
#include <GeomDataAPI_Point2D.h>
+#include <cmath>
+
const double tolerance = 1.e-7;
bool SketchPlugin_DistanceAttrValidator::isValid(const AttributePtr& theAttribute,
return true;
}
+
+bool SketchPlugin_IntersectionValidator::isValid(const AttributePtr& theAttribute,
+ const std::list<std::string>& theArguments,
+ std::string& theError) const
+{
+ if (theAttribute->attributeType() != ModelAPI_AttributeRefAttr::typeId()) {
+ theError = "The attribute with the " + theAttribute->attributeType() + " type is not processed";
+ return false;
+ }
+ AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
+ ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(aRefAttr->object());
+ if (!aResult) {
+ theError = "The attribute " + theAttribute->id() + " should be an object";
+ return false;
+ }
+
+ std::shared_ptr<GeomAPI_Edge> anEdge = std::dynamic_pointer_cast<GeomAPI_Edge>(aResult->shape());
+ if (!anEdge || !anEdge->isLine()) {
+ theError = "The attribute " + theAttribute->id() + " should be a line";
+ return false;
+ }
+
+ std::shared_ptr<GeomAPI_Dir> aLineDir = anEdge->line()->direction();
+
+ // find a sketch
+ std::shared_ptr<SketchPlugin_Sketch> aSketch;
+ std::set<AttributePtr> aRefs = aRefAttr->owner()->data()->refsToMe();
+ std::set<AttributePtr>::const_iterator anIt = aRefs.begin();
+ for (; anIt != aRefs.end(); ++anIt) {
+ CompositeFeaturePtr aComp =
+ std::dynamic_pointer_cast<ModelAPI_CompositeFeature>((*anIt)->owner());
+ if (aComp && aComp->getKind() == SketchPlugin_Sketch::ID()) {
+ aSketch = std::dynamic_pointer_cast<SketchPlugin_Sketch>(aComp);
+ break;
+ }
+ }
+ if (!aSketch) {
+ theError = "There is no sketch referring to the current feature";
+ return false;
+ }
+
+ std::shared_ptr<GeomAPI_Pln> aPlane = aSketch->plane();
+ std::shared_ptr<GeomAPI_Dir> aNormal = aPlane->direction();
+ return fabs(aNormal->dot(aLineDir)) > tolerance * tolerance;
+}
std::string& theError) const;
};
+/**\class SketchPlugin_IntersectionValidator
+ * \ingroup Validators
+ * \brief Validator for the attribute to be intersected with the sketch plane.
+ */
+class SketchPlugin_IntersectionValidator : public ModelAPI_AttributeValidator
+{
+ public:
+ //! returns true if attribute is valid
+ //! \param theAttribute the checked attribute
+ //! \param theArguments arguments of the attribute
+ //! \param theError error message
+ virtual bool isValid(const AttributePtr& theAttribute,
+ const std::list<std::string>& theArguments,
+ std::string& theError) const;
+};
+
#endif
<group id="Basic">
<feature
id="Sketch"
- nested="SketchPoint SketchLine SketchCircle SketchArc SketchRectangle SketchConstraintLength SketchConstraintRadius SketchConstraintDistance SketchConstraintParallel SketchConstraintPerpendicular SketchConstraintRigid SketchConstraintHorizontal SketchConstraintVertical SketchConstraintEqual SketchConstraintTangent SketchConstraintFillet SketchConstraintCoincidence SketchConstraintMirror SketchConstraintAngle SketchMultiRotation SketchMultiTranslation SketchConstraintCollinear SketchConstraintMiddle"
+ nested="SketchPoint SketchIntersectionPoint SketchLine SketchCircle SketchArc SketchRectangle SketchConstraintLength SketchConstraintRadius SketchConstraintDistance SketchConstraintParallel SketchConstraintPerpendicular SketchConstraintRigid SketchConstraintHorizontal SketchConstraintVertical SketchConstraintEqual SketchConstraintTangent SketchConstraintFillet SketchConstraintCoincidence SketchConstraintMirror SketchConstraintAngle SketchMultiRotation SketchMultiTranslation SketchConstraintCollinear SketchConstraintMiddle"
when_nested="accept abort"
title="Sketch"
tooltip="Create sketch"
<validator id="SketchPlugin_SolverErrorValidator"/>
<!--icon=":pictures/x_point.png"-->
</feature>
+
+ <!-- SketchPoint -->
<feature id="SketchPoint" title="Point" tooltip="Create point" icon=":icons/point.png">
<sketch-2dpoint_selector id="PointCoordindates" accept_expressions="0" title="Point" tooltip="Point coordinates"/>
<boolvalue id="Auxiliary" label="Auxiliary" default="false" tooltip="Construction element" obligatory="0"/>
</feature>
+
+ <!-- Intersection Point -->
+ <feature
+ id="SketchIntersectionPoint"
+ title="Intersection Point"
+ tooltip="Create intersection point"
+ icon=":icons/point.png">
+ <sketch_shape_selector
+ id="ExternalLine"
+ label="Edge"
+ tooltip="Select external line."
+ shape_types="edge">
+ <validator id="GeomValidators_ShapeType" parameters="line"/>
+ <validator id="SketchPlugin_IntersectionValidator"/>
+ </sketch_shape_selector>
+ </feature>
+
+ <!-- SketchLine -->
<feature id="SketchLine" title="Line" tooltip="Create line" icon=":icons/line.png">
<sketch-2dpoint_selector id="StartPoint" accept_expressions="0" title="Start point" tooltip="Start point coordinates" previous_feature_param="EndPoint"/>
<sketch-2dpoint_selector id="EndPoint" accept_expressions="0" title="End point" tooltip="End point coordinates"/>
#include <SketchPlugin_Circle.h>
#include <SketchPlugin_Line.h>
#include <SketchPlugin_Point.h>
+#include <SketchPlugin_IntersectionPoint.h>
#include <SketchPlugin_ConstraintAngle.h>
#include <math.h>
else if (aFeatureKind == SketchPlugin_Arc::ID())
return createArc(theFeature, theAttributes, theGroupID);
// Point (it has low probability to be an attribute of constraint, so it is checked at the end)
- else if (aFeatureKind == SketchPlugin_Point::ID()) {
+ else if (aFeatureKind == SketchPlugin_Point::ID() ||
+ aFeatureKind == SketchPlugin_IntersectionPoint::ID()) {
EntityWrapperPtr aSub;
if (theAttributes.size() == 1)
aSub = theAttributes.front();
#include <PlaneGCSSolver_EntityWrapper.h>
#include <SketchPlugin_Point.h>
+#include <SketchPlugin_IntersectionPoint.h>
#include <SketchPlugin_Sketch.h>
PlaneGCSSolver_EntityWrapper::PlaneGCSSolver_EntityWrapper(
}
// empty entity, probably this is a SketchPlugin_Point or SketchPlugin_Sketch
- if (theFeature->getKind() == SketchPlugin_Point::ID())
+ if (theFeature->getKind() == SketchPlugin_Point::ID() ||
+ theFeature->getKind() == SketchPlugin_IntersectionPoint::ID())
myType = ENTITY_POINT;
else if (theFeature->getKind() == SketchPlugin_Sketch::ID())
myType = ENTITY_SKETCH;
#include <SketchPlugin_Circle.h>
#include <SketchPlugin_Line.h>
#include <SketchPlugin_Point.h>
+#include <SketchPlugin_IntersectionPoint.h>
void SketchSolver_ConstraintMulti::getEntities(std::list<EntityWrapperPtr>& theEntities)
{
aPoints.push_back(aFeature->attribute(SketchPlugin_Line::END_ID()));
} else if (aFeature->getKind() == SketchPlugin_Circle::ID())
aPoints.push_back(aFeature->attribute(SketchPlugin_Circle::CENTER_ID()));
- else if (aFeature->getKind() == SketchPlugin_Point::ID())
+ else if (aFeature->getKind() == SketchPlugin_Point::ID() ||
+ aFeature->getKind() == SketchPlugin_IntersectionPoint::ID())
aPoints.push_back(aFeature->attribute(SketchPlugin_Point::COORD_ID()));
std::list<AttributePtr>::iterator aPtIt = aPoints.begin();
#include <SketchPlugin_Circle.h>
#include <SketchPlugin_Line.h>
#include <SketchPlugin_Point.h>
+#include <SketchPlugin_IntersectionPoint.h>
#include <SketchPlugin_ConstraintRigid.h>
aPoints.push_back(theFeature->attribute(SketchPlugin_Line::START_ID()));
aPoints.push_back(theFeature->attribute(SketchPlugin_Line::END_ID()));
}
- else if (theFeature->getKind() == SketchPlugin_Point::ID())
+ else if (theFeature->getKind() == SketchPlugin_Point::ID() ||
+ theFeature->getKind() == SketchPlugin_IntersectionPoint::ID())
aPoints.push_back(theFeature->attribute(SketchPlugin_Point::COORD_ID()));
return aPoints;
}
#include <SketchPlugin_Circle.h>
#include <SketchPlugin_Line.h>
#include <SketchPlugin_Point.h>
+#include <SketchPlugin_IntersectionPoint.h>
#include <math.h>
else if (aFeatureKind == SketchPlugin_Arc::ID())
return createArc(theFeature, theAttributes, theGroupID, theSketchID);
// Point (it has low probability to be an attribute of constraint, so it is checked at the end)
- else if (aFeatureKind == SketchPlugin_Point::ID()) {
+ else if (aFeatureKind == SketchPlugin_Point::ID() ||
+ aFeatureKind == SketchPlugin_IntersectionPoint::ID()) {
AttributePtr aPoint = theFeature->attribute(SketchPlugin_Point::COORD_ID());
if (!aPoint->isInitialized())
return aDummy;