#include <Model_Data.h>
#include <ModelAPI_CompositeFeature.h>
#include <GeomAlgoAPI_SketchBuilder.h>
+#include <GeomAPI_Tools.h>
#include <ModelAPI_Events.h>
#include <Model_Document.h>
#include <GeomAPI_PlanarEdges.h>
#include <GeomAPI_Shape.h>
#include <Events_Loop.h>
+#include <GeomDataAPI_Point.h>
+#include <GeomDataAPI_Dir.h>
#include <TDF_ChildIDIterator.hxx>
#include <TNaming_NamedShape.hxx>
#include <TopoDS_ListOfShape.hxx>
#include <TopExp_Explorer.hxx>
#include <TopTools_MapOfShape.hxx>
+#include <NCollection_IndexedDataMap.hxx>
#include <algorithm>
aName.erase(std::remove(aName.begin(), aName.end(), '/'), aName.end());
aName.erase(std::remove(aName.begin(), aName.end(), '&'), aName.end());
// remove the last 's', 'e', 'f' and 'r' symbols:
- // they are used as markers of start/end/forward/rewersed indicators
+ // they are used as markers of start/end/forward/reversed indicators
static const std::string aSyms("sefr");
std::string::iterator aSuffix = aName.end() - 1;
while(aSyms.find(*aSuffix) != std::string::npos) {
return aName;
}
-
bool Model_ResultConstruction::updateShape()
{
std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(data());
if (aData && aData->isValid()) {
- TDF_Label& aShapeLab = aData->shapeLab();
+ TDF_Label aShapeLab = aData->shapeLab();
Handle(TNaming_NamedShape) aNS;
if (aShapeLab.FindAttribute(TNaming_NamedShape::GetID(), aNS)) {
TopoDS_Shape aShape = aNS->Get();
if (!aShape.IsNull()) {
+ if (aShape.ShapeType() == TopAbs_COMPOUND) {
+ // restore the sketch planar edges object
+ std::shared_ptr<GeomAPI_PlanarEdges> aBigWire(new GeomAPI_PlanarEdges);
+ aBigWire->setImpl<TopoDS_Shape>(new TopoDS_Shape(aShape));
+ FeaturePtr aSketch =
+ document()->feature(std::dynamic_pointer_cast<ModelAPI_Result>(data()->owner()));
+ std::shared_ptr<GeomDataAPI_Point> anOrigin =
+ std::dynamic_pointer_cast<GeomDataAPI_Point>(aSketch->data()->attribute("Origin"));
+ std::shared_ptr<GeomDataAPI_Dir> aDirX =
+ std::dynamic_pointer_cast<GeomDataAPI_Dir>(aSketch->data()->attribute("DirX"));
+ std::shared_ptr<GeomDataAPI_Dir> aNorm =
+ std::dynamic_pointer_cast<GeomDataAPI_Dir>(aSketch->data()->attribute("Norm"));
+ if (anOrigin.get() && aDirX.get() && aNorm.get()) {
+ aBigWire->setPlane(anOrigin->pnt(), aDirX->dir(), aNorm->dir());
+ myShape = aBigWire;
+ return true;
+ }
+ }
+ // just restore shape
GeomShapePtr aGShape(new GeomAPI_Shape);
aGShape->setImpl<TopoDS_Shape>(new TopoDS_Shape(aShape));
- myShape = aGShape; // restore the sketch sub-components
+ myShape = GeomAPI_Tools::getTypedShape(aGShape); // restore the sketch sub-components
return true;
}
}
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_Label aShapeLab = aData->shapeLab();
TDF_ChildIDIterator anOldIter(aShapeLab, TDataStd_IntPackedMap::GetID());
for (; anOldIter.More(); anOldIter.Next()) {
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_Label aShapeLab = aData->shapeLab();
TDF_ChildIDIterator anOldIter(aShapeLab, TDataStd_IntPackedMap::GetID());
for (; anOldIter.More(); anOldIter.Next()) {
if (anIndex == theIndex) {
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();
+ TDF_Label aShapeLab = aData->shapeLab();
if (!theShape.get() || theShape->isNull()) {
aShapeLab.ForgetAllAttributes();
TDataStd_Name::Set(aShapeLab, aMyName.c_str()); // restore name forgotten
std::list<std::shared_ptr<GeomAPI_Shape> > aFaces;
GeomAlgoAPI_SketchBuilder::createFaces(aWirePtr->origin(), aWirePtr->dirX(),
aWirePtr->norm(), aWirePtr, aFaces);
- NCollection_DataMap<TopoDS_Face, TColStd_ListOfInteger> aNewIndices; // edges indices
+ // order is important to store faces in the same order if sketch is created from scratch
+ NCollection_IndexedDataMap<TopoDS_Face, TColStd_ListOfInteger> aNewIndices; // edges indices
std::list<std::shared_ptr<GeomAPI_Shape> >::iterator aFIter = aFaces.begin();
for (; aFIter != aFaces.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>());
- aNewIndices.Bind(aTopoFace, TColStd_ListOfInteger());
+ aNewIndices.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());
int anIndex = aCurvesIndices.Find(aCurve);
if ((aFirst > aLast) != (anEdge.Orientation() == TopAbs_REVERSED))
anIndex = -anIndex;
- aNewIndices.ChangeFind(aTopoFace).Append(anIndex);
+ aNewIndices.ChangeFromKey(aTopoFace).Append(anIndex);
}
}
}
NCollection_DataMap<int, TopoDS_Face> aFacesOrder; // faces -> tag where they must be set
NCollection_List<TopoDS_Face> anUnorderedFaces; // faces that may be located at any index
// searching for the best new candidate to old location
- NCollection_DataMap<TopoDS_Face, TColStd_ListOfInteger>::Iterator aNewIter(aNewIndices);
+ NCollection_IndexedDataMap<TopoDS_Face, TColStd_ListOfInteger>::Iterator
+ aNewIter(aNewIndices);
for (; aNewIter.More(); aNewIter.Next()) {
double aBestFound = 0, aBestNotFound = 1.e+100;
int aBestTag = 0;
aFaceBuilder.Generated(aFaceToPut);
// store also indices of the new face edges
Handle(TDataStd_IntPackedMap) aNewMap = TDataStd_IntPackedMap::Set(aLab);
- const TColStd_ListOfInteger& aNewInd = aNewIndices.Find(aFaceToPut);
+ const TColStd_ListOfInteger& aNewInd = aNewIndices.FindFromKey(aFaceToPut);
std::stringstream aName;
aName<<"Face";
TopExp_Explorer aPutEdges(aFaceToPut, TopAbs_EDGE);
- TNaming_Builder* anEdgesBuilder = 0;
+ 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;
if (!anEdgesBuilder) {
TDF_Label anEdgesLabel = aLab.FindChild(1);
anEdgesBuilder = new TNaming_Builder(anEdgesLabel);
- TDataStd_Name::Set(anEdgesLabel, "SubEdge");
+ 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());
+
+ }
+ }
+ }
aPutEdges.Next();
}
+ if (anEdgesBuilder)
+ delete anEdgesBuilder;
+ if (aVerticesBuilder)
+ delete aVerticesBuilder;
TDataStd_Name::Set(aLab, TCollection_ExtendedString(aName.str().c_str()));
aMyDoc->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::ostringstream aWireName;
+ aWireName<<aName.str()<<"_wire";
+ if (aWireTag > 3)
+ aWireName<<"_"<<aWireTag - 2;
+ TDataStd_Name::Set(aWireLab, aWireName.str().c_str());
+ aMyDoc->addNamingName(aWireLab, aWireName.str());
+ aWireTag++;
+ }
}
}
}