- TDF_Label aLab = aShapeLab.FindChild(aCurrentTag);
- TNaming_Builder aFaceBuilder(aLab);
- aFaceBuilder.Generated(aFaceToPut);
- // store also indices of the new face edges
- Handle(TDataStd_IntPackedMap) aNewMap = TDataStd_IntPackedMap::Set(aLab);
- const TColStd_ListOfInteger& aNewInd = aNewIndices.FindFromKey(aFaceToPut);
- std::stringstream aName;
- aName<<"Face";
- TopExp_Explorer aPutEdges(aFaceToPut, TopAbs_EDGE);
- TNaming_Builder *anEdgesBuilder = 0, *aVerticesBuilder = 0;
- for(TColStd_ListOfInteger::Iterator anIter(aNewInd); anIter.More(); anIter.Next()) {
- int anIndex = anIter.Value();
- int aModIndex = anIndex > 0 ? anIndex : -anIndex;
- aNewMap->Add(anIndex);
- aName<<"-"<<aComponentsNames[aModIndex];
- if (anIter.Value() > 0)
- aName<<"f";
- else
- aName<<"r";
- // collect all edges of the face which are modified in sub-label of the face
- if (anEdgeIndices.IsBound(aModIndex) &&
- !aFaceEdges.Contains(anEdgeIndices.Find(aModIndex))) {
- if (!anEdgesBuilder) {
- TDF_Label anEdgesLabel = aLab.FindChild(1);
- anEdgesBuilder = new TNaming_Builder(anEdgesLabel);
- std::ostringstream aSubName;
- // tag is needed for Test1922 to distinguish sub-edges of different faces
- aSubName<<"SubEdge_"<<aCurrentTag;
- TDataStd_Name::Set(anEdgesLabel, aSubName.str().c_str());
- }
- anEdgesBuilder->Modify(anEdgeIndices.Find(aModIndex), aPutEdges.Current());
- }
- // put also modified vertices, otherwise vertex of original edge has no history
- if (anEdgeIndices.IsBound(aModIndex)) {
- TopExp_Explorer aVExpOld(anEdgeIndices.Find(aModIndex), TopAbs_VERTEX);
- TopExp_Explorer aVExpNew(aPutEdges.Current(), TopAbs_VERTEX);
- for(; aVExpNew.More() && aVExpOld.More(); aVExpNew.Next(), aVExpOld.Next()) {
- if (!aVExpOld.Current().IsSame(aVExpNew.Current())) {
- if (!aVerticesBuilder) {
- TDF_Label aVertLabel = aLab.FindChild(2);
- aVerticesBuilder = new TNaming_Builder(aVertLabel);
- std::ostringstream aSubName;
- // tag is needed for Test1922 to distinguish sub-edges of different faces
- aSubName<<"SubVertex_"<<aCurrentTag;
- TDataStd_Name::Set(aVertLabel, aSubName.str().c_str());
- }
- aVerticesBuilder->Modify(aVExpOld.Current(), aVExpNew.Current());
-
- }
- }
+ ListOfShape aFaces;
+ NCollection_DataMap<int, TopoDS_Face> aFacesOrder; // faces -> tag where they must be set
+ NCollection_List<TopoDS_Face> anUnorderedFaces; // unordered faces are empty in this case
+ int aTagId = 0;
+ for (std::list<GeomFacePtr>::const_iterator aFIt = theFaces.begin();
+ aFIt != theFaces.end(); ++aFIt) {
+ aFaces.push_back(*aFIt);
+ aFacesOrder.Bind(++aTagId, (*aFIt)->impl<TopoDS_Face>());
+ }
+
+ MapFaceToEdgeIndices aNewIndices; // edges indices
+ faceToEdgeIndices(aFaces, aCurvesIndices, aNewIndices);
+
+ storeFacesOnLabel(aMyDoc, aShapeLab, aMyName, aShape, aFacesOrder, anUnorderedFaces,
+ aNewIndices, anEdgeIndices, aComponentsNames);
+ }
+ }
+}
+
+// ========================== Auxiliary functions =========================================
+
+void storeFacesOnLabel(std::shared_ptr<Model_Document>& theDocument,
+ TDF_Label& theShapeLabel,
+ const std::string& theName,
+ const TopoDS_Shape& theShape,
+ NCollection_DataMap<int, TopoDS_Face>& theFacesOrder,
+ NCollection_List<TopoDS_Face>& theUnorderedFaces,
+ const MapFaceToEdgeIndices& theFaceEdges,
+ const NCollection_DataMap<int, TopoDS_Edge>& theEdgesIndices,
+ const std::map<int, std::string>& theEdgesNames)
+{
+ theShapeLabel.ForgetAllAttributes(); // clear all previously stored
+ TDataStd_Name::Set(theShapeLabel, theName.c_str()); // restore name forgotten
+ TNaming_Builder aBuilder(theShapeLabel); // store the compound to get it ready on open of document
+ aBuilder.Generated(theShape);
+ theDocument->addNamingName(theShapeLabel, theName);
+ // set new faces to the labels
+ int aCurrentTag = 1;
+ NCollection_List<TopoDS_Face>::Iterator anUnordered(theUnorderedFaces);
+ for (int aCurrentTag = 1; !theFacesOrder.IsEmpty() || anUnordered.More(); aCurrentTag++) {
+ TopoDS_Face aFaceToPut;
+ if (theFacesOrder.IsBound(aCurrentTag)) {
+ aFaceToPut = theFacesOrder.Find(aCurrentTag);
+ theFacesOrder.UnBind(aCurrentTag);
+ }
+ else if (anUnordered.More()) {
+ aFaceToPut = anUnordered.Value();
+ anUnordered.Next();
+ }
+
+ if (aFaceToPut.IsNull())
+ continue;
+
+ TopTools_MapOfShape aFaceEdges;
+ for (TopExp_Explorer anEdges(aFaceToPut, TopAbs_EDGE); anEdges.More(); anEdges.Next())
+ aFaceEdges.Add(anEdges.Current());
+
+ TDF_Label aLab = theShapeLabel.FindChild(aCurrentTag);
+ TNaming_Builder aFaceBuilder(aLab);
+ aFaceBuilder.Generated(aFaceToPut);
+ // store also indices of the new face edges
+ Handle(TDataStd_IntPackedMap) aNewMap = TDataStd_IntPackedMap::Set(aLab);
+ const TColStd_ListOfInteger& aNewInd = theFaceEdges.FindFromKey(aFaceToPut);
+ std::stringstream aName;
+ aName<<"Face";
+ TopExp_Explorer aPutEdges(aFaceToPut, TopAbs_EDGE);
+ TNaming_Builder *anEdgesBuilder = 0, *aVerticesBuilder = 0;
+ for(TColStd_ListOfInteger::Iterator anIter(aNewInd); anIter.More(); anIter.Next()) {
+ int anIndex = anIter.Value();
+ int aModIndex = anIndex > 0 ? anIndex : -anIndex;
+ aNewMap->Add(anIndex);
+ aName<<"-"<<theEdgesNames.find(aModIndex)->second;
+ if (anIter.Value() > 0)
+ aName<<"f";
+ else
+ aName<<"r";
+ // collect all edges of the face which are modified in sub-label of the face
+ if (theEdgesIndices.IsBound(aModIndex) &&
+ !aFaceEdges.Contains(theEdgesIndices.Find(aModIndex))) {
+ if (!anEdgesBuilder) {
+ TDF_Label anEdgesLabel = aLab.FindChild(1);
+ anEdgesBuilder = new TNaming_Builder(anEdgesLabel);
+ std::ostringstream aSubName;
+ // tag is needed for Test1922 to distinguish sub-edges of different faces
+ aSubName<<"SubEdge_"<<aCurrentTag;
+ TDataStd_Name::Set(anEdgesLabel, aSubName.str().c_str());
+ }
+ anEdgesBuilder->Modify(theEdgesIndices.Find(aModIndex), aPutEdges.Current());
+ }
+ // put also modified vertices, otherwise vertex of original edge has no history
+ if (theEdgesIndices.IsBound(aModIndex)) {
+ TopExp_Explorer aVExpOld(theEdgesIndices.Find(aModIndex), TopAbs_VERTEX);
+ TopExp_Explorer aVExpNew(aPutEdges.Current(), TopAbs_VERTEX);
+ for(; aVExpNew.More() && aVExpOld.More(); aVExpNew.Next(), aVExpOld.Next()) {
+ if (!aVExpOld.Current().IsSame(aVExpNew.Current())) {
+ if (!aVerticesBuilder) {
+ TDF_Label aVertLabel = aLab.FindChild(2);
+ aVerticesBuilder = new TNaming_Builder(aVertLabel);
+ std::ostringstream aSubName;
+ // tag is needed for Test1922 to distinguish sub-edges of different faces
+ aSubName<<"SubVertex_"<<aCurrentTag;
+ TDataStd_Name::Set(aVertLabel, aSubName.str().c_str());