- } else if (aShapeType == TopAbs_VERTEX) {
- // just reselect the vertex by the id of edge
- const int aSubNum = aComposite->numberOfSubs();
- for(int a = 0; a < aSubNum; a++) {
- // if aSubIds take any, the first appropriate
- int aFeatureID = aComposite->subFeatureId(a);
- if (aSubIds->IsEmpty() || aSubIds->Contains(aFeatureID) ||
- aSubIds->Contains(aFeatureID + kSTART_VERTEX_DELTA) ||
- aSubIds->Contains(aFeatureID + kSTART_VERTEX_DELTA * 2)) {
- // searching for deltas
- int aVertexNum = 0;
- if (aSubIds->Contains(aFeatureID + kSTART_VERTEX_DELTA)) aVertexNum = 1;
- else if (aSubIds->Contains(aFeatureID + kSTART_VERTEX_DELTA * 2)) aVertexNum = 2;
- // found the feature with appropriate edge
- FeaturePtr aFeature = aComposite->subFeature(a);
- std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aResIter =
- aFeature->results().cbegin();
- for(;aResIter != aFeature->results().cend(); aResIter++) {
- ResultConstructionPtr aRes =
- std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(*aResIter);
- if (aRes && aRes->shape()) {
- if (aRes->shape()->isVertex() && aVertexNum == 0) { // found!
- select(aRes->shape(), theExtDoc, theIndex);
- theModified = true;
- return true;
- } else if (aRes->shape()->isEdge() && aVertexNum > 0) {
- const TopoDS_Shape& anEdge = aRes->shape()->impl<TopoDS_Shape>();
- int aVIndex = 1;
- for(TopExp_Explorer aVExp(anEdge, TopAbs_VERTEX); aVExp.More(); aVExp.Next()) {
- if (aVIndex == aVertexNum) { // found!
- std::shared_ptr<GeomAPI_Shape> aVertex(new GeomAPI_Shape);
- aVertex->setImpl(new TopoDS_Shape(aVExp.Current()));
- select(aVertex, theExtDoc, theIndex);
- theModified = true;
- return true;
- }
- aVIndex++;
- }
- }
- }
- }
+ aPutEdges.Next();
+ }
+ if (anEdgesBuilder)
+ delete anEdgesBuilder;
+ if (aVerticesBuilder)
+ delete aVerticesBuilder;
+ TDataStd_Name::Set(aLab, TCollection_ExtendedString(aName.str().c_str()));
+ theDocument->addNamingName(aLab, aName.str());
+ // put also wires to sub-labels to correctly select them instead of collection by edges
+ int aWireTag = 3; // first tag is for SubEdge-s, second - for vertices
+ for(TopExp_Explorer aWires(aFaceToPut, TopAbs_WIRE); aWires.More(); aWires.Next()) {
+ TDF_Label aWireLab = aLab.FindChild(aWireTag);
+ TNaming_Builder aWireBuilder(aWireLab);
+ aWireBuilder.Generated(aWires.Current());
+ std::wostringstream aWireName;
+ aWireName<<aName.str()<<L"_wire";
+ if (aWireTag > 3)
+ aWireName<<"_"<<aWireTag - 2;
+ TDataStd_Name::Set(aWireLab, aWireName.str().c_str());
+ theDocument->addNamingName(aWireLab, aWireName.str());
+ aWireTag++;
+ }
+ }
+}
+
+void indexingSketchEdges(const CompositeFeaturePtr& theComposite,
+ NCollection_DataMap<Handle(Geom_Curve), int>& theCurvesIndices,
+ NCollection_DataMap<int, TopoDS_Edge>& theEdgesIndices,
+ std::map<int, std::wstring>& theEdgesNames)
+{
+ const int aSubNum = theComposite->numberOfSubs();
+ for (int a = 0; a < aSubNum; a++) {
+ FeaturePtr aSub = theComposite->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);
+ theCurvesIndices.Bind(aCurve, a);
+ theEdgesIndices.Bind(a, anEdge);
+ theEdgesNames[a] = shortName(aConstr);
+ }
+ }
+ }
+}
+
+void faceToEdgeIndices(const ListOfShape& theFaces,
+ const NCollection_DataMap<Handle(Geom_Curve), int>& theCurvesIndices,
+ MapFaceToEdgeIndices& theFaceEdges)
+{
+ std::list<std::shared_ptr<GeomAPI_Shape> >::const_iterator aFIter = theFaces.begin();
+ for (; aFIter != theFaces.end(); aFIter++) {
+ std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(*aFIter));
+ // put them to a label, trying to keep the same faces on the same labels
+ if (aFace.get() && !aFace->isNull()) {
+ TopoDS_Face aTopoFace = TopoDS::Face(aFace->impl<TopoDS_Shape>());
+ theFaceEdges.Add(aTopoFace, TColStd_ListOfInteger());
+ // keep new indices of sub-elements used in this face
+ for (TopExp_Explorer anEdges(aTopoFace, TopAbs_EDGE); anEdges.More(); anEdges.Next()) {
+ TopoDS_Edge anEdge = TopoDS::Edge(anEdges.Current());
+ Standard_Real aFirst, aLast;
+ Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, aFirst, aLast);
+ if (theCurvesIndices.IsBound(aCurve)) {
+ int anIndex = theCurvesIndices.Find(aCurve);
+ if ((aFirst > aLast) != (anEdge.Orientation() == TopAbs_REVERSED))
+ anIndex = -anIndex;
+ theFaceEdges.ChangeFromKey(aTopoFace).Append(anIndex);