#include "ModelGeomAlgo_Point2D.h"
#include <ModelAPI_Feature.h>
+#include <ModelAPI_Result.h>
#include <ModelAPI_AttributeRefAttr.h>
#include <GeomAlgoAPI_ShapeTools.h>
#include <GeomAPI_Pnt2d.h>
#include <GeomAPI_Vertex.h>
#include <GeomAPI_Dir.h>
+#include <GeomAPI_Edge.h>
+#include <GeomAPI_Lin.h>
namespace ModelGeomAlgo_Point2D {
std::shared_ptr<GeomDataAPI_Point2D> getPointOfRefAttr(ModelAPI_Feature* theFeature,
FeaturePtr aFeature;
std::shared_ptr<ModelAPI_AttributeRefAttr> anAttr = std::dynamic_pointer_cast<
ModelAPI_AttributeRefAttr>(theFeature->data()->attribute(theAttribute));
- if(!anAttr.get()) {
- return std::shared_ptr<GeomDataAPI_Point2D>();
+ if(anAttr.get() && anAttr->isInitialized()) {
+ aFeature = ModelAPI_Feature::feature(anAttr->object());
+ if (aFeature.get()) {
+ bool aFeatureOfObjectKind = !theObjectFeatureKind.empty() &&
+ !theObjectFeatureAttribute.empty() &&
+ aFeature->getKind() == theObjectFeatureKind;
+ if(aFeatureOfObjectKind)
+ aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+ aFeature->data()->attribute(theObjectFeatureAttribute));
+ else if (anAttr->attr())
+ aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttr->attr());
+ }
}
- aFeature = ModelAPI_Feature::feature(anAttr->object());
-
- bool aFeatureOfObjectKind = !theObjectFeatureKind.empty() &&
- !theObjectFeatureAttribute.empty() &&
- aFeature->getKind() == theObjectFeatureKind;
- if (aFeature.get() && aFeatureOfObjectKind)
- aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
- aFeature->data()->attribute(theObjectFeatureAttribute));
- else if (anAttr->attr())
- aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttr->attr());
-
return aPointAttr;
}
- void getPointsOfReference(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+ void getPointsOfReference(const std::shared_ptr<ModelAPI_Object>& theObject,
const std::string& theReferenceFeatureKind,
std::set<std::shared_ptr<GeomDataAPI_Point2D> >& theAttributes,
const std::string& theObjectFeatureKind,
const std::string& theObjectFeatureAttribute)
{
- const std::set<AttributePtr>& aRefsList = theFeature->data()->refsToMe();
+ // find by feature
+ const std::set<AttributePtr>& aRefsList = theObject->data()->refsToMe();
std::set<AttributePtr>::const_iterator aIt;
for (aIt = aRefsList.cbegin(); aIt != aRefsList.cend(); ++aIt) {
std::shared_ptr<ModelAPI_Attribute> aAttr = (*aIt);
FeaturePtr aRefFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aAttr->owner());
if (aRefFeature->getKind() == theReferenceFeatureKind) {
std::list<AttributePtr> anAttributes =
- theFeature->data()->attributes(ModelAPI_AttributeRefAttr::typeId());
+ aRefFeature->data()->attributes(ModelAPI_AttributeRefAttr::typeId());
std::list<AttributePtr>::iterator anIter = anAttributes.begin();
// it searches the first point of AttributeRefAtt
std::shared_ptr<GeomDataAPI_Point2D> aPointAttr;
}
}
}
+ // find by results
+ FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theObject);
+ if (aFeature.get()) {
+ const std::list<std::shared_ptr<ModelAPI_Result> > aResults = aFeature->results();
+ std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aRIter = aResults.begin();
+ for (; aRIter != aResults.cend(); aRIter++) {
+ ResultPtr aResult = *aRIter;
+ getPointsOfReference(aResult, theReferenceFeatureKind, theAttributes, theObjectFeatureKind,
+ theObjectFeatureAttribute);
+ }
+ }
}
void getPointsInsideShape(const std::shared_ptr<GeomAPI_Shape> theBaseShape,
for (; anIt != aLast; anIt++) {
std::shared_ptr<GeomDataAPI_Point2D> anAttribute = *anIt;
std::shared_ptr<GeomAPI_Pnt2d> aPnt2d = anAttribute->pnt();
- std::shared_ptr<GeomAPI_Pnt> aPnt = aPnt2d->to3D(theOrigin, theDirX, theDirY);
- std::shared_ptr<GeomAPI_Vertex> aVertexShape(new GeomAPI_Vertex(aPnt->x(), aPnt->y(), aPnt->z()));
- if (GeomAlgoAPI_ShapeTools::isSubShapeInsideShape(aVertexShape, theBaseShape))
- thePoints.insert(aPnt);
+ std::shared_ptr<GeomAPI_Pnt> aPoint = aPnt2d->to3D(theOrigin, theDirX, theDirY);
+ std::shared_ptr<GeomAPI_Pnt> aProjectedPoint;
+ if (isPointOnEdge(theBaseShape, aPoint, aProjectedPoint))
+ thePoints.insert(aProjectedPoint);
}
}
+ bool isPointOnEdge(const std::shared_ptr<GeomAPI_Shape> theBaseShape,
+ const std::shared_ptr<GeomAPI_Pnt>& thePoint,
+ std::shared_ptr<GeomAPI_Pnt>& theProjectedPoint)
+ {
+ bool isInside = false;
+ if (theBaseShape->shapeType() == GeomAPI_Shape::EDGE) {
+ std::shared_ptr<GeomAPI_Edge> aLineEdge(new GeomAPI_Edge(theBaseShape));
+ std::shared_ptr<GeomAPI_Lin> aLine = aLineEdge->line();
+ theProjectedPoint = aLine->project(thePoint);
+
+ std::shared_ptr<GeomAPI_Vertex> aVertexShape(new GeomAPI_Vertex(theProjectedPoint->x(),
+ theProjectedPoint->y(), theProjectedPoint->z()));
+ isInside = GeomAlgoAPI_ShapeTools::isSubShapeInsideShape(aVertexShape, theBaseShape);
+ }
+ return isInside;
+ }
} // namespace ModelGeomAlgo_Point2D