1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: ModelAPI_Tools.cpp
4 // Created: 20 Jul 2016
5 // Author: Natalia ERMOLAEVA
7 #include "ModelGeomAlgo_Point2D.h"
9 #include <ModelAPI_Feature.h>
10 #include <ModelAPI_AttributeRefAttr.h>
12 #include <GeomAlgoAPI_ShapeTools.h>
13 #include <GeomDataAPI_Point2D.h>
15 #include <GeomAPI_Pnt.h>
16 #include <GeomAPI_Pnt2d.h>
17 #include <GeomAPI_Vertex.h>
18 #include <GeomAPI_Dir.h>
20 namespace ModelGeomAlgo_Point2D {
21 std::shared_ptr<GeomDataAPI_Point2D> getPointOfRefAttr(ModelAPI_Feature* theFeature,
22 const std::string& theAttribute,
23 const std::string& theObjectFeatureKind,
24 const std::string& theObjectFeatureAttribute)
26 std::shared_ptr<GeomDataAPI_Point2D> aPointAttr;
28 /// essential check as it is called in openGl thread
29 if (!theFeature || !theFeature->data().get() || !theFeature->data()->isValid())
30 return std::shared_ptr<GeomDataAPI_Point2D>();
33 std::shared_ptr<ModelAPI_AttributeRefAttr> anAttr = std::dynamic_pointer_cast<
34 ModelAPI_AttributeRefAttr>(theFeature->data()->attribute(theAttribute));
36 return std::shared_ptr<GeomDataAPI_Point2D>();
38 aFeature = ModelAPI_Feature::feature(anAttr->object());
40 bool aFeatureOfObjectKind = !theObjectFeatureKind.empty() &&
41 !theObjectFeatureAttribute.empty() &&
42 aFeature->getKind() == theObjectFeatureKind;
43 if (aFeature.get() && aFeatureOfObjectKind)
44 aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
45 aFeature->data()->attribute(theObjectFeatureAttribute));
46 else if (anAttr->attr())
47 aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttr->attr());
52 void getPointsOfReference(const std::shared_ptr<ModelAPI_Feature>& theFeature,
53 const std::string& theReferenceFeatureKind,
54 std::set<std::shared_ptr<GeomDataAPI_Point2D> >& theAttributes,
55 const std::string& theObjectFeatureKind,
56 const std::string& theObjectFeatureAttribute)
58 const std::set<AttributePtr>& aRefsList = theFeature->data()->refsToMe();
59 std::set<AttributePtr>::const_iterator aIt;
60 for (aIt = aRefsList.cbegin(); aIt != aRefsList.cend(); ++aIt) {
61 std::shared_ptr<ModelAPI_Attribute> aAttr = (*aIt);
62 FeaturePtr aRefFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aAttr->owner());
63 if (aRefFeature->getKind() == theReferenceFeatureKind) {
64 std::list<AttributePtr> anAttributes =
65 theFeature->data()->attributes(ModelAPI_AttributeRefAttr::typeId());
66 std::list<AttributePtr>::iterator anIter = anAttributes.begin();
67 // it searches the first point of AttributeRefAtt
68 std::shared_ptr<GeomDataAPI_Point2D> aPointAttr;
69 for(; anIter != anAttributes.end() && !aPointAttr.get(); anIter++) {
70 AttributeRefAttrPtr aRefAttribute =
71 std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anIter);
72 if (aRefAttribute.get())
73 aPointAttr = getPointOfRefAttr(aRefFeature.get(), aRefAttribute->id(),
74 theObjectFeatureKind, theObjectFeatureAttribute);
76 if (aPointAttr.get()) {
77 theAttributes.insert(aPointAttr);
83 void getPointsInsideShape(const std::shared_ptr<GeomAPI_Shape> theBaseShape,
84 const std::set<std::shared_ptr<GeomDataAPI_Point2D> >& theAttributes,
85 const std::shared_ptr<GeomAPI_Pnt>& theOrigin,
86 const std::shared_ptr<GeomAPI_Dir>& theDirX,
87 const std::shared_ptr<GeomAPI_Dir>& theDirY,
88 std::set<std::shared_ptr<GeomAPI_Pnt> >& thePoints)
90 std::set<std::shared_ptr<GeomDataAPI_Point2D> >::const_iterator anIt = theAttributes.begin(),
91 aLast = theAttributes.end();
92 for (; anIt != aLast; anIt++) {
93 std::shared_ptr<GeomDataAPI_Point2D> anAttribute = *anIt;
94 std::shared_ptr<GeomAPI_Pnt2d> aPnt2d = anAttribute->pnt();
95 std::shared_ptr<GeomAPI_Pnt> aPnt = aPnt2d->to3D(theOrigin, theDirX, theDirY);
96 std::shared_ptr<GeomAPI_Vertex> aVertexShape(new GeomAPI_Vertex(aPnt->x(), aPnt->y(), aPnt->z()));
97 if (GeomAlgoAPI_ShapeTools::isSubShapeInsideShape(aVertexShape, theBaseShape))
98 thePoints.insert(aPnt);
103 } // namespace ModelGeomAlgo_Point2D