-// Copyright (C) 2014-2019 CEA/DEN, EDF R&D
+// Copyright (C) 2014-2023 CEA, EDF
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
#include <Model_BodyBuilder.h>
+#include <Locale_Convert.h>
+
#include <Model_Data.h>
#include <Model_Document.h>
#include <ModelAPI_Session.h>
case TopAbs_VERTEX: return GENERATED_VERTICES_TAG;
case TopAbs_EDGE: return GENERATED_EDGES_TAG;
case TopAbs_FACE: return GENERATED_FACES_TAG;
+ default: break; // [to avoid compilation warning]
}
return INVALID_TAG;
case TopAbs_VERTEX: return MODIFIED_VERTICES_TAG;
case TopAbs_EDGE: return MODIFIED_EDGES_TAG;
case TopAbs_FACE: return MODIFIED_FACES_TAG;
+ default: break; // [to avoid compilation warning]
}
return INVALID_TAG;
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;
+ Handle(TNaming_NamedShape) aNS;
if (aShapes.Label().FindAttribute(TNaming_NamedShape::GetID(), aNS)) {
if (aNS->Evolution() != TNaming_SELECTED) {
theOriginalLabel = aNS->Label();
if(!aBuilder.NamedShape()->IsEmpty()) {
Handle(TDataStd_Name) anAttr;
if(aBuilder.NamedShape()->Label().FindAttribute(TDataStd_Name::GetID(),anAttr)) {
- std::string aName (TCollection_AsciiString(anAttr->Get()).ToCString());
+ std::wstring aName = Locale::Convert::toWString(anAttr->Get().ToExtString());
if(!aName.empty()) {
std::shared_ptr<Model_Document> aDoc =
std::dynamic_pointer_cast<Model_Document>(document());
{
std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(data());
if (aData) {
- TDF_Label aShapeLab = aData->shapeLab();
// clean builders
if (theIsCleanStored)
clean();
if(!aBuilder->NamedShape()->IsEmpty()) {
Handle(TDataStd_Name) anAttr;
if(aBuilder->NamedShape()->Label().FindAttribute(TDataStd_Name::GetID(),anAttr)) {
- std::string aName (TCollection_AsciiString(anAttr->Get()).ToCString());
+ std::wstring aName = Locale::Convert::toWString(anAttr->Get().ToExtString());
if(!aName.empty()) {
std::shared_ptr<Model_Document> aDoc =
std::dynamic_pointer_cast<Model_Document>(document());
}
}
+static TDF_Label builderLabel(DataPtr theData, const int theTag )
+{
+ std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(theData);
+ return theTag == 0 ? aData->shapeLab() : aData->shapeLab().FindChild(theTag);
+}
+
TNaming_Builder* Model_BodyBuilder::builder(const int theTag)
{
std::map<int, TNaming_Builder*>::iterator aFind = myBuilders.find(theTag);
if (aFind == myBuilders.end()) {
- std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(data());
- myBuilders[theTag] = new TNaming_Builder(
- theTag == 0 ? aData->shapeLab() : aData->shapeLab().FindChild(theTag));
+ myBuilders[theTag] = new TNaming_Builder(builderLabel(data(), theTag));
aFind = myBuilders.find(theTag);
}
return aFind->second;
TDF_Label anAccess2 = std::dynamic_pointer_cast<Model_Document>(
ModelAPI_Session::get()->moduleDocument())->generalLabel();
TDF_Label anOriginalLabel;
+ TopTools_ListOfShape anOldList;
if (!isShapeInTree(aData->shapeLab(), anAccess2, aShapeOld, anOriginalLabel)) {
+ // check this could be a compund by the whole feature selection
+ if (aShapeOld.ShapeType() == TopAbs_COMPOUND) {
+ for(TopoDS_Iterator aCompIter(aShapeOld); aCompIter.More(); aCompIter.Next()) {
+ if (isShapeInTree(aData->shapeLab(), anAccess2, aCompIter.Value(), anOriginalLabel)) {
+ anOldList.Append(aCompIter.Value());
+ } else {
+ anOldList.Clear();
+ break;
+ }
+ }
+ }
+ } else {
+ anOldList.Append(aShapeOld);
+ }
+ if (anOldList.IsEmpty()) {
if (aBuilder->NamedShape()->Get().IsNull()) { // store as primitive if alone anyway
aBuilder->Generated(aShapeNew);
}
myBuilders.erase(0);
aBuilder = builder(0);
}
-
- aBuilder->Modify(aShapeOld, aShapeNew);
+ TopTools_ListIteratorOfListOfShape anOldIter(anOldList);
+ for(; anOldIter.More(); anOldIter.Next()) {
+ aBuilder->Modify(anOldIter.Value(), aShapeNew);
+ }
// store information about the external document reference to restore old shape on open
storeExternalReference(anOriginalLabel, aBuilder->NamedShape()->Label());
}
if(!aBuilder->NamedShape()->IsEmpty()) {
Handle(TDataStd_Name) anAttr;
if(aBuilder->NamedShape()->Label().FindAttribute(TDataStd_Name::GetID(), anAttr)) {
- std::string aName (TCollection_AsciiString(anAttr->Get()).ToCString());
+ std::wstring aName = Locale::Convert::toWString(anAttr->Get().ToExtString());
if(!aName.empty()) {
std::shared_ptr<Model_Document> aDoc =
std::dynamic_pointer_cast<Model_Document>(document());
}
aName.insert(0, aPrefix);
- TDataStd_Name::Set(builder(theTag)->NamedShape()->Label(), aName.c_str());
+ TDataStd_Name::Set(builderLabel(data(), theTag), aName.c_str());
}
bool Model_BodyBuilder::generated(const GeomShapePtr& theNewShape,
const std::string& theName,
if (aNewShapeType == TopAbs_WIRE || aNewShapeType == TopAbs_SHELL) {
// TODO: This is a workaround. New shape should be only vertex, edge or face.
TopAbs_ShapeEnum aShapeTypeToExplore = aNewShapeType == TopAbs_WIRE ? TopAbs_EDGE : TopAbs_FACE;
- aTag = TopAbs_WIRE ? GENERATED_EDGES_TAG : GENERATED_FACES_TAG;
+ aTag = aNewShapeType == TopAbs_WIRE ? GENERATED_EDGES_TAG : GENERATED_FACES_TAG;
for (TopExp_Explorer anExp(aNewShape, aShapeTypeToExplore); anExp.More(); anExp.Next()) {
builder(aTag)->Generated(anOldShape, anExp.Current());
}
bool anOldSubShapeNotInTree =
!isShapeInTree(aData->shapeLab(), anAccess2, anOldSubShape_, anOriginalLabel);
if (anOldSubShapeAlreadyProcessed || anOldSubShapeNotInTree) {
- if (theSaveOldIfNotInTree) {
+ // The second condition is added due to #20170 because sub-shape must be added to real parent
+ // shape, not the reference. The naming name of pure reference is not registered in document.
+ if (theSaveOldIfNotInTree && !aData->shapeLab().IsAttribute(TDF_Reference::GetID())) {
std::string aSelectionName = theName + "Selected";
generated(anOldSubShape, aSelectionName, false);
} else
// TODO: This is a workaround. New shape should be only edge or face.
TopAbs_ShapeEnum aShapeTypeToExplore = aNewShapeType == TopAbs_WIRE ? TopAbs_EDGE
: TopAbs_FACE;
- int aTag = TopAbs_WIRE ? GENERATED_EDGES_TAG : GENERATED_FACES_TAG;
+ int aTag = aNewShapeType == 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());
+ storeExternalReference(anOriginalLabel, builderLabel(data(), aTag));
}
buildName(aTag, theName);
} else {
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());
+ storeExternalReference(anOriginalLabel, builderLabel(data(), aTag));
}
}
}
//=======================================================================
void Model_BodyBuilder::loadFirstLevel(GeomShapePtr theShape, const std::string& theName)
{
- if(theShape->isNull()) return;
- TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
+ GeomShapePtr aShapePtr = shape();
+ if (theShape->isNull() || !aShapePtr.get())
+ return;
+ TopoDS_Shape aShape = shape()->impl<TopoDS_Shape>();
+ if (aShape.IsNull())
+ return;
std::string aName;
if (aShape.ShapeType() == TopAbs_COMPOUND || aShape.ShapeType() == TopAbs_COMPSOLID) {
TopoDS_Iterator itr(aShape);