#include <TopoDS.hxx>
#include <TopoDS_Face.hxx>
#include <TDF_ChildIterator.hxx>
+#include <TDF_Reference.hxx>
#include <TopTools_MapOfShape.hxx>
#include <TopExp_Explorer.hxx>
#include <TopTools_ListOfShape.hxx>
evolutionToSelectionRec(aShapeLab, theFlag);
}
-void Model_BodyBuilder::store(const std::shared_ptr<GeomAPI_Shape>& theShape)
+void Model_BodyBuilder::store(const std::shared_ptr<GeomAPI_Shape>& theShape,
+ const bool theIsStoreSameShapes)
{
std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(data());
if (aData) {
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);
+ return;
+ }
+ }
+
aBuilder.Generated(aShape);
// register name
if(!aBuilder.NamedShape()->IsEmpty()) {
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()) {
std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(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();
std::vector<TNaming_Builder*> myBuilders;
public:
/// Stores the shape (called by the execution method).
- MODEL_EXPORT virtual void store(const std::shared_ptr<GeomAPI_Shape>& theShape);
+ MODEL_EXPORT virtual void store(const std::shared_ptr<GeomAPI_Shape>& theShape,
+ const bool theIsStoreSameShapes = true);
/// Stores the generated shape (called by the execution method).
MODEL_EXPORT virtual void storeGenerated(const std::shared_ptr<GeomAPI_Shape>& theFromShape,
MODELAPI_EXPORT virtual ~ModelAPI_BodyBuilder() {};
/// Stores the shape (called by the execution method).
- virtual void store(const std::shared_ptr<GeomAPI_Shape>& theShape) = 0;
+ virtual void store(const std::shared_ptr<GeomAPI_Shape>& theShape,
+ const bool theIsStoreSameShapes = true) = 0;
/// Stores the generated shape (called by the execution method).
virtual void storeGenerated(const std::shared_ptr<GeomAPI_Shape>& theFromShape,
return group();
}
-void ModelAPI_ResultBody::store(const std::shared_ptr<GeomAPI_Shape>& theShape)
+void ModelAPI_ResultBody::store(const std::shared_ptr<GeomAPI_Shape>& theShape,
+ const bool theIsStoreSameShapes)
{
- myBuilder->store(theShape);
+ myBuilder->store(theShape, theIsStoreSameShapes);
static Events_Loop* aLoop = Events_Loop::loop();
static Events_ID aRedispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
return RESULT_BODY_COLOR;
}
- /// Stores the shape (called by the execution method).
- MODELAPI_EXPORT virtual void store(const std::shared_ptr<GeomAPI_Shape>& theShape);
+ /// \brief Stores the shape (called by the execution method).
+ /// param[in] theShape shape to store.
+ /// param[in] theIsStoreSameShapes if false stores reference to the same shape if it is already in document.
+ MODELAPI_EXPORT virtual void store(const std::shared_ptr<GeomAPI_Shape>& theShape,
+ const bool theIsStoreSameShapes = true);
/// Stores the generated shape (called by the execution method).
MODELAPI_EXPORT virtual void storeGenerated(const std::shared_ptr<GeomAPI_Shape>& theFromShape,