X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModel%2FModel_BodyBuilder.cpp;h=1d3b8a4d506d48ef85e711e995ad7c75e8568f93;hb=4fc2dc9fdc0c14fab5f2780598eccdc1368d81b9;hp=604c99b2c4181186cda4529d1e05b7c280ff4e75;hpb=b6be33d3af5a10e204e3bd69708d49b8b9f1a127;p=modules%2Fshaper.git diff --git a/src/Model/Model_BodyBuilder.cpp b/src/Model/Model_BodyBuilder.cpp index 604c99b2c..1d3b8a4d5 100755 --- a/src/Model/Model_BodyBuilder.cpp +++ b/src/Model/Model_BodyBuilder.cpp @@ -12,11 +12,13 @@ #include #include #include +#include #include #include #include #include #include +#include #include #include #include @@ -46,7 +48,7 @@ Model_BodyBuilder::Model_BodyBuilder(ModelAPI_Object* theOwner) // Converts evolution of naming shape to selection evelution and back to avoid // naming support on the disabled results. Deeply in the labels tree, recursively. -static void EvolutionToSelection(TDF_Label theLab, const bool theFlag) { +static void evolutionToSelectionRec(TDF_Label theLab, const bool theFlag) { std::list > aShapePairs; // to store old and new shapes Handle(TNaming_NamedShape) aName; int anEvolution = -1; @@ -77,7 +79,7 @@ static void EvolutionToSelection(TDF_Label theLab, const bool theFlag) { std::list >::iterator aPairsIter = aShapePairs.begin(); for(; aPairsIter != aShapePairs.end(); aPairsIter++) { if (theFlag) { // disabled => make selection - aBuilder.Select(aPairsIter->first, aPairsIter->second); + aBuilder.Select(aPairsIter->second, aPairsIter->first); } else if (anEvol == TNaming_GENERATED) { aBuilder.Generated(aPairsIter->first, aPairsIter->second); } else if (anEvol == TNaming_MODIFY) { @@ -86,16 +88,28 @@ static void EvolutionToSelection(TDF_Label theLab, const bool theFlag) { aBuilder.Delete(aPairsIter->first); } else if (anEvol == TNaming_PRIMITIVE) { aBuilder.Generated(aPairsIter->second); + } else if (anEvol == TNaming_SELECTED) { + aBuilder.Select(aPairsIter->second, aPairsIter->first); } } // recursive call for all sub-labels TDF_ChildIterator anIter(theLab, Standard_False); for(; anIter.More(); anIter.Next()) { - EvolutionToSelection(anIter.Value(), theFlag); + evolutionToSelectionRec(anIter.Value(), theFlag); } } -void Model_BodyBuilder::store(const std::shared_ptr& theShape) +void Model_BodyBuilder::evolutionToSelection(const bool theFlag) +{ + std::shared_ptr aData = std::dynamic_pointer_cast(data()); + if (!aData) // unknown case + return; + TDF_Label& aShapeLab = aData->shapeLab(); + evolutionToSelectionRec(aShapeLab, theFlag); +} + +void Model_BodyBuilder::store(const std::shared_ptr& theShape, + const bool theIsStoreSameShapes) { std::shared_ptr aData = std::dynamic_pointer_cast(data()); if (aData) { @@ -110,8 +124,20 @@ void Model_BodyBuilder::store(const std::shared_ptr& theShape) if (aShape.IsNull()) return; // null shape inside + if(!theIsStoreSameShapes) { + Handle(TNaming_NamedShape) aNS = TNaming_Tool::NamedShape(aShape, aShapeLab); + if(!aNS.IsNull() && !aNS->IsEmpty()) { + // This shape is already in document, store reference instead of shape; + const TDF_Label aFoundLabel = aNS->Label(); + TDF_Reference::Set(aShapeLab, aFoundLabel); + aShapeLab.ForgetAttribute(TNaming_NamedShape::GetID()); + return; + } + } + aBuilder.Generated(aShape); // register name + aShapeLab.ForgetAttribute(TDF_Reference::GetID()); if(!aBuilder.NamedShape()->IsEmpty()) { Handle(TDataStd_Name) anAttr; if(aBuilder.NamedShape()->Label().FindAttribute(TDataStd_Name::GetID(),anAttr)) { @@ -190,11 +216,20 @@ void Model_BodyBuilder::storeModified(const std::shared_ptr& theO TopoDS_Iterator aSubIter(aShapeNew); for(int aTag = theDecomposeSolidsTag; aSubIter.More(); aSubIter.Next()) { + const TopoDS_Shape& aShape = aSubIter.Value(); + Handle(TNaming_NamedShape) aNS = TNaming_Tool::NamedShape(aShape, aShapeLab); + if(!aNS.IsNull() && !aNS->IsEmpty()) { + // This shape is already in document, don't add it. + continue; + } TNaming_Builder aSubBuilder(aShapeLab.FindChild(aTag++)); aSubBuilder.Generated(aSubIter.Value()); if(!aName.IsEmpty()) { + TCollection_AsciiString aShapeType = aShape.ShapeType() == TopAbs_EDGE ? "_Edge_" : + aShape.ShapeType() == TopAbs_FACE ? "_Face_" : + aShape.ShapeType() == TopAbs_SOLID ? "_Solid_" : "_Shape_"; std::string aSolidName = - (aName + "_Solid_" + TCollection_AsciiString(aTag - theDecomposeSolidsTag)).ToCString(); + (aName + aShapeType + TCollection_AsciiString(aTag - theDecomposeSolidsTag)).ToCString(); std::shared_ptr aDoc = std::dynamic_pointer_cast(document()); aDoc->addNamingName(aSubBuilder.NamedShape()->Label(), aSolidName); @@ -204,6 +239,22 @@ void Model_BodyBuilder::storeModified(const std::shared_ptr& theO } } } + +void Model_BodyBuilder::storeWithoutNaming(const std::shared_ptr& theShape) +{ + std::shared_ptr aData = std::dynamic_pointer_cast(data()); + if (aData) { + clean(); + if (!theShape.get()) + return; // bad shape + TopoDS_Shape aShape = theShape->impl(); + if (aShape.IsNull()) + return; // null shape inside + TNaming_Builder aBuilder(aData->shapeLab()); + aBuilder.Select(aShape, aShape); + } +} + void Model_BodyBuilder::clean() { std::vector::iterator aBuilder = myBuilders.begin(); @@ -301,8 +352,13 @@ void Model_BodyBuilder::loadAndOrientModifiedShapes ( const int theKindOfShape, const int theTag, const std::string& theName, - GeomAPI_DataMapOfShapeShape& theSubShapes) + GeomAPI_DataMapOfShapeShape& theSubShapes, + const bool theIsStoreSeparate) { + int aTag = theTag; + std::string aName = theName; + std::ostringstream aStream; + int anIndex = 1; TopoDS_Shape aShapeIn = theShapeIn->impl(); TopTools_MapOfShape aView; bool isBuilt = theName.empty(); @@ -322,9 +378,19 @@ void Model_BodyBuilder::loadAndOrientModifiedShapes ( aNewShape.Orientation(aMapShape->impl().Orientation()); } if (!aRoot.IsSame (aNewShape)) { - builder(theTag)->Modify(aRoot,aNewShape); - if(!isBuilt) - buildName(theTag, theName); + builder(aTag)->Modify(aRoot,aNewShape); + if(!isBuilt) { + if(theIsStoreSeparate) { + aStream.str(std::string()); + aStream.clear(); + aStream << theName << "_" << anIndex++; + aName = aStream.str(); + } + buildName(aTag, aName); + } + if(theIsStoreSeparate) { + aTag++; + } } } } @@ -714,3 +780,50 @@ void Model_BodyBuilder::loadDisconnectedVertexes(std::shared_ptr } } } + +std::shared_ptr Model_BodyBuilder::shape() +{ + std::shared_ptr aData = std::dynamic_pointer_cast(data()); + if (aData) { + TDF_Label aShapeLab = aData->shapeLab(); + Handle(TDF_Reference) aRef; + if (aShapeLab.FindAttribute(TDF_Reference::GetID(), aRef)) { + aShapeLab = aRef->Get(); + } + Handle(TNaming_NamedShape) aName; + if (aShapeLab.FindAttribute(TNaming_NamedShape::GetID(), aName)) { + TopoDS_Shape aShape = aName->Get(); + if (!aShape.IsNull()) { + std::shared_ptr aRes(new GeomAPI_Shape); + aRes->setImpl(new TopoDS_Shape(aShape)); + return aRes; + } + } + } + return std::shared_ptr(); +} + +bool Model_BodyBuilder::isLatestEqual(const std::shared_ptr& theShape) +{ + if (theShape.get()) { + TopoDS_Shape aShape = theShape->impl(); + std::shared_ptr aData = std::dynamic_pointer_cast(data()); + if (aData) { + TDF_Label& aShapeLab = aData->shapeLab(); + Handle(TNaming_NamedShape) aName; + if (aShapeLab.FindAttribute(TNaming_NamedShape::GetID(), aName)) { + TopoDS_Shape aLatest = TNaming_Tool::CurrentShape(aName); + if (aLatest.IsNull()) + return false; + if (aLatest.IsEqual(aShape)) + return true; + // check sub-shapes for comp-solids: + for (TopExp_Explorer anExp(aShape, aLatest.ShapeType()); anExp.More(); anExp.Next()) { + if (aLatest.IsEqual(anExp.Current())) + return true; + } + } + } + } + return false; +}