#include <TNaming_NamedShape.hxx>
#include <TNaming_Iterator.hxx>
#include <TNaming_Tool.hxx>
+#include <TNaming_SameShapeIterator.hxx>
#include <TDataStd_Name.hxx>
#include <TDataStd_Integer.hxx>
+#include <TDataStd_ExtStringList.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Face.hxx>
#include <TDF_ChildIterator.hxx>
#include <TDF_ChildIDIterator.hxx>
#include <TDF_Reference.hxx>
+#include <TDF_Tool.hxx>
#include <TopTools_MapOfShape.hxx>
#include <TopExp_Explorer.hxx>
#include <TopTools_ListOfShape.hxx>
#include <Config_PropManager.h>
// DEB
//#include <TCollection_AsciiString.hxx>
-//#include <TDF_Tool.hxx>
//#define DEB_IMPORT 1
+/// reference to the shape in external document: sting list attribute identifier
+static const Standard_GUID kEXTERNAL_SHAPE_REF("9aa5dd14-6d34-4a8d-8786-05842fd7bbbd");
+
static const int INVALID_TAG = -1;
static const int GENERATED_VERTICES_TAG = 1;
static const int GENERATED_EDGES_TAG = 2;
if(!theIsStoreSameShapes) {
Handle(TNaming_NamedShape) aNS = TNaming_Tool::NamedShape(aShape, aShapeLab);
- if(!aNS.IsNull() && !aNS->IsEmpty()) {
+ // the last condition is for the issue 2751 : existing shape may be found in compound-NS
+ if(!aNS.IsNull() && !aNS->IsEmpty() && aNS->Get().IsSame(aShape)) {
// This shape is already in document, store reference instead of shape;
const TDF_Label aFoundLabel = aNS->Label();
TDF_Reference::Set(aShapeLab, aFoundLabel);
return;
std::map<int, TNaming_Builder*>::iterator aBuilder = myBuilders.begin();
for(; aBuilder != myBuilders.end(); aBuilder++) {
+ Handle(TNaming_NamedShape) aNS = aBuilder->second->NamedShape();
delete aBuilder->second;
- // clear also shapes on cleaned sub-labels (#2241)
- Handle(TNaming_NamedShape) aNS;
- if (aLab.FindChild(aBuilder->first).FindAttribute(TNaming_NamedShape::GetID(), aNS)) {
- aNS->Clear();
- }
+ if (!aNS.IsNull() && !aNS->Label().IsNull())
+ aNS->Label().ForgetAttribute(TNaming_NamedShape::GetID());
}
myBuilders.clear();
myPrimitivesNamesIndexMap.clear();
// remove the old reference (if any)
aLab.ForgetAttribute(TDF_Reference::GetID());
myFreePrimitiveTag = PRIMITIVES_START_TAG;
+ TDF_ChildIDIterator anEntriesIter(aLab, kEXTERNAL_SHAPE_REF, true);
+ for(; anEntriesIter.More(); anEntriesIter.Next()) {
+ anEntriesIter.Value()->Label().ForgetAttribute(kEXTERNAL_SHAPE_REF);
+ }
}
Model_BodyBuilder::~Model_BodyBuilder()
TDataStd_Name::Set(builder(theTag)->NamedShape()->Label(), aName.c_str());
}
-void Model_BodyBuilder::generated(const GeomShapePtr& theNewShape,
- const std::string& theName)
+bool Model_BodyBuilder::generated(const GeomShapePtr& theNewShape,
+ const std::string& theName,
+ const bool theCheckIsInResult)
{
GeomShapePtr aResultShape = shape();
-
- bool aNewShapeIsNotInResultShape = !aResultShape->isSubShape(theNewShape, false);
- if (aNewShapeIsNotInResultShape) {
- return;
+ if (theCheckIsInResult) {
+ bool aNewShapeIsNotInResultShape = !aResultShape->isSubShape(theNewShape, false);
+ if (aNewShapeIsNotInResultShape) {
+ return false;
+ }
}
TopoDS_Shape aShape = theNewShape->impl<TopoDS_Shape>();
buildName(myFreePrimitiveTag, aName);
}
++myFreePrimitiveTag;
+ return true;
}
void Model_BodyBuilder::generated(const GeomShapePtr& theOldShape,
return TopAbs_VERTEX; // bad case
}
+/// Checks that shape is presented in the tree with not-selection evolution
+/// In theOriginalLabel it returns label where NS of old sub-shape is stored
+static bool isShapeInTree(const TDF_Label& theAccess1, const TDF_Label& theAccess2,
+ TopoDS_Shape theShape, TDF_Label& theOriginalLabel)
+{
+ bool aResult = TNaming_Tool::HasLabel(theAccess1, theShape);
+ if (aResult) { //check evolution and a label of this shape
+ for(TNaming_SameShapeIterator aShapes(theShape, theAccess1); aShapes.More(); aShapes.Next())
+ {
+ static Handle(TNaming_NamedShape) aNS;
+ if (aShapes.Label().FindAttribute(TNaming_NamedShape::GetID(), aNS)) {
+ if (aNS->Evolution() != TNaming_SELECTED) {
+ theOriginalLabel = aNS->Label();
+ return true;
+ }
+ }
+ }
+ }
+ if (!theAccess2.IsNull()) {
+ static const TDF_Label anEmpty;
+ return isShapeInTree(theAccess2, anEmpty, theShape, theOriginalLabel);
+ }
+ return false;
+}
+
+/// Stores entry to the external label in the entries list at this label
+static void storeExternalReference(const TDF_Label& theExternal, const TDF_Label theThis)
+{
+ // store information about the external document reference to restore old shape on open
+ if (!theExternal.IsNull() && !theExternal.Root().IsEqual(theThis.Root())) {
+ Handle(TDataStd_ExtStringList) anEntries;
+ if (!theThis.FindAttribute(kEXTERNAL_SHAPE_REF, anEntries)) {
+ anEntries = TDataStd_ExtStringList::Set(theThis, kEXTERNAL_SHAPE_REF);
+ }
+ TCollection_AsciiString anEntry;
+ TDF_Tool::Entry(theExternal, anEntry);
+ // check it already contains this entry
+ TDataStd_ListOfExtendedString::Iterator anIter(anEntries->List());
+ for(; anIter.More(); anIter.Next())
+ if (anIter.Value() == anEntry)
+ break;
+ if (!anIter.More()) {
+ anEntries->Append(anEntry);
+ }
+ }
+}
+
void Model_BodyBuilder::loadModifiedShapes(const GeomMakeShapePtr& theAlgo,
const GeomShapePtr& theOldShape,
const GeomAPI_Shape::ShapeType theShapeTypeToExplore,
// There is no sense to write history if shape already processed
// or old shape does not exist in the document.
bool anOldSubShapeAlreadyProcessed = !anAlreadyProcessedShapes.Add(anOldSubShape_);
- bool anOldSubShapeNotInTree = !TNaming_Tool::HasLabel(aData->shapeLab(), anOldSubShape_);
- if (anOldSubShapeNotInTree) {// check this is in the module document
- TDF_Label anAccess = std::dynamic_pointer_cast<Model_Document>(
- ModelAPI_Session::get()->moduleDocument())->generalLabel();
- anOldSubShapeNotInTree = !TNaming_Tool::HasLabel(anAccess, anOldSubShape_);
- }
- if (anOldSubShapeAlreadyProcessed
- || anOldSubShapeNotInTree)
- {
+ TDF_Label anAccess2 = std::dynamic_pointer_cast<Model_Document>(
+ ModelAPI_Session::get()->moduleDocument())->generalLabel();
+ TDF_Label anOriginalLabel;
+ bool anOldSubShapeNotInTree =
+ !isShapeInTree(aData->shapeLab(), anAccess2, anOldSubShape_, anOriginalLabel);
+ if (anOldSubShapeAlreadyProcessed || anOldSubShapeNotInTree) {
continue;
}
isGenerated ? aBuilder->Generated(anOldSubShape_, aNewShape_)
: aBuilder->Modify(anOldSubShape_, aNewShape_);
+ // store information about the external document reference to restore old shape on open
+ storeExternalReference(anOriginalLabel, aBuilder->NamedShape()->Label());
}
}
}
// There is no sense to write history if shape already processed
// or old shape does not exist in the document.
bool anOldSubShapeAlreadyProcessed = !anAlreadyProcessedShapes.Add(anOldSubShape_);
- bool anOldSubShapeNotInTree = !TNaming_Tool::HasLabel(aData->shapeLab(), anOldSubShape_);
- if (anOldSubShapeNotInTree) {// check this is in the module document
- TDF_Label anAccess = std::dynamic_pointer_cast<Model_Document>(
- ModelAPI_Session::get()->moduleDocument())->generalLabel();
- anOldSubShapeNotInTree = !TNaming_Tool::HasLabel(anAccess, anOldSubShape_);
- }
- if (anOldSubShapeAlreadyProcessed
- || anOldSubShapeNotInTree)
- {
+ TDF_Label anAccess2 = std::dynamic_pointer_cast<Model_Document>(
+ ModelAPI_Session::get()->moduleDocument())->generalLabel();
+ TDF_Label anOriginalLabel;
+ bool anOldSubShapeNotInTree =
+ !isShapeInTree(aData->shapeLab(), anAccess2, anOldSubShape_, anOriginalLabel);
+ if (anOldSubShapeAlreadyProcessed || anOldSubShapeNotInTree) {
continue;
}
int aTag = TopAbs_WIRE ? GENERATED_EDGES_TAG : GENERATED_FACES_TAG;
for (TopExp_Explorer anExp(aNewShape_, aShapeTypeToExplore); anExp.More(); anExp.Next()) {
builder(aTag)->Generated(anOldSubShape_, anExp.Current());
+ // store information about the external document reference to restore old shape on open
+ storeExternalReference(anOriginalLabel, builder(aTag)->NamedShape()->Label());
}
buildName(aTag, theName);
}
if (aTag == INVALID_TAG) return;
builder(aTag)->Generated(anOldSubShape_, aNewShape_);
buildName(aTag, theName);
+ // store information about the external document reference to restore old shape on open
+ storeExternalReference(anOriginalLabel, builder(aTag)->NamedShape()->Label());
}
}
}