+ std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(data());
+ if (aData.get() && aData->isValid()) {
+ if (theInfinite)
+ TDataStd_UAttribute::Set(aData->label(), kIS_INFINITE);
+ else
+ aData->label().ForgetAttribute(kIS_INFINITE);
+ }
+}
+
+int Model_ResultConstruction::facesNum(const bool theUpdateNaming)
+{
+ int aResult = 0;
+ std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(data());
+ if (aData.get() && aData->isValid()) {
+ TDF_Label aShapeLab = aData->shapeLab();
+ TDF_ChildIDIterator anOldIter(aShapeLab, TDataStd_IntPackedMap::GetID());
+ for (; anOldIter.More(); anOldIter.Next()) {
+ aResult++;
+ }
+ }
+ return aResult;
+}
+
+std::shared_ptr<GeomAPI_Face> Model_ResultConstruction::face(const int theIndex)
+{
+ std::shared_ptr<GeomAPI_Face> aResult;
+ int anIndex = 0;
+ std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(data());
+ if (aData.get() && aData->isValid()) {
+ TDF_Label aShapeLab = aData->shapeLab();
+ TDF_ChildIDIterator anOldIter(aShapeLab, TDataStd_IntPackedMap::GetID());
+ for (; anOldIter.More(); anOldIter.Next()) {
+ if (anIndex == theIndex) {
+ Handle(TNaming_NamedShape) aNS;
+ anOldIter.Value()->Label().FindAttribute(TNaming_NamedShape::GetID(), aNS);
+ aResult.reset(new GeomAPI_Face);
+ aResult->setImpl(new TopoDS_Shape(aNS->Get()));
+ break;
+ }
+ anIndex++;
+ }
+ }
+ return aResult;
+}
+
+void Model_ResultConstruction::setIsConcealed(const bool theValue)
+{
+ // do nothing: the construction element is never concealed
+}
+
+void Model_ResultConstruction::storeShape(std::shared_ptr<GeomAPI_Shape> theShape)
+{
+ std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(data());
+ if (aData && aData->isValid()) {
+ std::string aMyName = data()->name();
+ TDF_Label aShapeLab = aData->shapeLab();
+ if (!theShape.get() || theShape->isNull()) {
+ aShapeLab.ForgetAllAttributes();
+ TDataStd_Name::Set(aShapeLab, aMyName.c_str()); // restore name forgotten
+ return;
+ }
+ std::shared_ptr<Model_Document> aMyDoc =
+ std::dynamic_pointer_cast<Model_Document>(document());
+ const TopoDS_Shape& aShape = theShape->impl<TopoDS_Shape>();
+ if (aShape.ShapeType() == TopAbs_VERTEX) {
+ aShapeLab.ForgetAllAttributes(); // clear all previously stored
+ TNaming_Builder aBuilder(aShapeLab);
+ aBuilder.Generated(aShape);
+ TDataStd_Name::Set(aShapeLab, aMyName.c_str());
+ aMyDoc->addNamingName(aShapeLab, aMyName);
+ } else if (aShape.ShapeType() == TopAbs_EDGE) { // store sub-vertices on sub-labels
+ aShapeLab.ForgetAllAttributes(); // clear all previously stored
+ TNaming_Builder aBuilder(aShapeLab);
+ aBuilder.Generated(aShape);
+
+ TopExp_Explorer anExp(aShape, TopAbs_VERTEX);
+ for(int anIndex = 1; anExp.More(); anExp.Next(), anIndex++) {
+ TDF_Label aSubLab = aShapeLab.FindChild(anIndex);
+ TNaming_Builder aBuilder(aSubLab);
+ aBuilder.Generated(anExp.Current());
+ std::string aVertexName = aMyName + "_" + (anIndex == 1 ? "StartVertex" : "EndVertex");
+ TDataStd_Name::Set(aSubLab, aVertexName.c_str());
+ aMyDoc->addNamingName(aSubLab, aVertexName);
+ }
+ TDataStd_Name::Set(aShapeLab, aMyName.c_str());
+ aMyDoc->addNamingName(aShapeLab, aMyName);
+ } else { // this is probably sketch, so, work with it as with composite
+ std::shared_ptr<GeomAPI_PlanarEdges> aWirePtr =
+ std::dynamic_pointer_cast<GeomAPI_PlanarEdges>(theShape);
+ if (!aWirePtr.get())
+ return; // unknown case
+ ResultPtr aThisPtr = std::dynamic_pointer_cast<ModelAPI_Result>(data()->owner());
+ FeaturePtr aThisFeature = aMyDoc->feature(aThisPtr);
+ CompositeFeaturePtr aComposite =
+ std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aThisFeature);
+ if (!aComposite || aComposite->numberOfSubs() == 0)
+ return; // unknown case
+ // collect indices of curves of current composite
+ NCollection_DataMap<Handle(Geom_Curve), int> aCurvesIndices;
+ NCollection_DataMap<int, TopoDS_Edge> anEdgeIndices;
+ std::map<int, std::string> aComponentsNames; // names of components that lay on index
+ const int aSubNum = aComposite->numberOfSubs();
+ for (int a = 0; a < aSubNum; a++) {
+ FeaturePtr aSub = aComposite->subFeature(a);
+ const std::list<std::shared_ptr<ModelAPI_Result> >& aResults = aSub->results();
+ std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aRes = aResults.cbegin();
+ for (; aRes != aResults.cend(); aRes++) {
+ ResultConstructionPtr aConstr =
+ std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(*aRes);
+ if (aConstr->shape() && aConstr->shape()->isEdge()) {
+ TopoDS_Edge anEdge = TopoDS::Edge(aConstr->shape()->impl<TopoDS_Shape>());
+ Standard_Real aFirst, aLast;
+ Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, aFirst, aLast);
+ aCurvesIndices.Bind(aCurve, a);
+ anEdgeIndices.Bind(a, anEdge);
+ aComponentsNames[a] = shortName(aConstr);
+ }
+ }
+ }
+