Model_ResultBody::Model_ResultBody()
{
+ myIsDisabled = true; // by default it is not initialized and false to be after created
setIsConcealed(false);
}
theDefault = DEFAULT_COLOR();
}
+// 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) {
+ std::list<std::pair<TopoDS_Shape, TopoDS_Shape> > aShapePairs; // to store old and new shapes
+ Handle(TNaming_NamedShape) aName;
+ int anEvolution = -1;
+ if (theLab.FindAttribute(TNaming_NamedShape::GetID(), aName)) {
+ TNaming_Evolution aNSEvol = aName->Evolution();
+ if ((aNSEvol == TNaming_SELECTED && theFlag) ||
+ (aNSEvol != TNaming_SELECTED && !theFlag)) { // nothing to do, it is already correct
+ return;
+ }
+ anEvolution = (int)(aNSEvol);
+ if (!theFlag) {
+ Handle(TDataStd_Integer) anAttrEvol;
+ if (theLab.FindAttribute(TDataStd_Integer::GetID(), anAttrEvol)) {
+ anEvolution = anAttrEvol->Get();
+ }
+ } else {
+ TDataStd_Integer::Set(theLab, anEvolution);
+ }
+
+ for(TNaming_Iterator anIter(aName); anIter.More(); anIter.Next()) {
+ aShapePairs.push_back(std::pair<TopoDS_Shape, TopoDS_Shape>
+ (anIter.OldShape(), anIter.NewShape()));
+ }
+ }
+ // create new
+ TNaming_Builder aBuilder(theLab);
+ TNaming_Evolution anEvol = (TNaming_Evolution)(anEvolution);
+ std::list<std::pair<TopoDS_Shape, TopoDS_Shape> >::iterator aPairsIter = aShapePairs.begin();
+ for(; aPairsIter != aShapePairs.end(); aPairsIter++) {
+ if (theFlag) { // disabled => make selection
+ aBuilder.Select(aPairsIter->first, aPairsIter->second);
+ } else if (anEvol == TNaming_GENERATED) {
+ aBuilder.Generated(aPairsIter->first, aPairsIter->second);
+ } else if (anEvol == TNaming_MODIFY) {
+ aBuilder.Modify(aPairsIter->first, aPairsIter->second);
+ } else if (anEvol == TNaming_DELETE) {
+ aBuilder.Delete(aPairsIter->first);
+ } else if (anEvol == TNaming_PRIMITIVE) {
+ aBuilder.Generated(aPairsIter->second);
+ }
+ }
+ // recursive call for all sub-labels
+ TDF_ChildIterator anIter(theLab, Standard_False);
+ for(; anIter.More(); anIter.Next()) {
+ EvolutionToSelection(anIter.Value(), theFlag);
+ }
+}
+
bool Model_ResultBody::setDisabled(std::shared_ptr<ModelAPI_Result> theThis, const bool theFlag)
{
bool aChanged = ModelAPI_ResultBody::setDisabled(theThis, theFlag);
if (!aData) // unknown case
return aChanged;
TDF_Label& aShapeLab = aData->shapeLab();
-
- std::list<std::pair<TopoDS_Shape, TopoDS_Shape> > aShapePairs; // to store old and new shapes
- Handle(TNaming_NamedShape) aName;
- int anEvolution = -1;
- if (aShapeLab.FindAttribute(TNaming_NamedShape::GetID(), aName)) {
- anEvolution = (int)(aName->Evolution());
- for(TNaming_Iterator anIter(aName); anIter.More(); anIter.Next()) {
- aShapePairs.push_back(std::pair<TopoDS_Shape, TopoDS_Shape>
- (anIter.OldShape(), anIter.NewShape()));
- }
- }
- // remove old
- aShapeLab.ForgetAttribute(TNaming_NamedShape::GetID());
- // create new
- TNaming_Builder aBuilder(aShapeLab);
- TNaming_Evolution anEvol = (TNaming_Evolution)(anEvolution);
- std::list<std::pair<TopoDS_Shape, TopoDS_Shape> >::iterator aPairsIter = aShapePairs.begin();
- for(; aPairsIter != aShapePairs.end(); aPairsIter++) {
- if (theFlag) { // disabled => make selection
- aBuilder.Select(aPairsIter->first, aPairsIter->second);
- } else if (anEvol == TNaming_GENERATED) {
- aBuilder.Generated(aPairsIter->first, aPairsIter->second);
- } else if (anEvol == TNaming_MODIFY) {
- aBuilder.Modify(aPairsIter->first, aPairsIter->second);
- }
- }
+ EvolutionToSelection(aShapeLab, theFlag);
}
return aChanged;
}
}
void Model_ResultBody::storeModified(const std::shared_ptr<GeomAPI_Shape>& theOldShape,
- const std::shared_ptr<GeomAPI_Shape>& theNewShape)
+ const std::shared_ptr<GeomAPI_Shape>& theNewShape, const int theDecomposeSolidsTag)
{
std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(data());
if (aData) {
if (aShapeNew.IsNull())
return; // null shape inside
aBuilder.Modify(aShapeOld, aShapeNew);
+ if (theDecomposeSolidsTag && aShapeNew.ShapeType() == TopAbs_COMPOUND) { // make sub elements as subs
+
+ // register name if it is possible
+ TCollection_AsciiString aName;
+ if(!aBuilder.NamedShape()->IsEmpty()) {
+ Handle(TDataStd_Name) anAttr;
+ if(aBuilder.NamedShape()->Label().FindAttribute(TDataStd_Name::GetID(),anAttr)) {
+ aName = TCollection_AsciiString(anAttr->Get()).ToCString();
+ }
+ }
+
+ TopoDS_Iterator aSubIter(aShapeNew);
+ for(int aTag = theDecomposeSolidsTag; aSubIter.More(); aSubIter.Next()) {
+ TNaming_Builder aSubBuilder(aShapeLab.FindChild(aTag++));
+ aSubBuilder.Generated(aSubIter.Value());
+ if(!aName.IsEmpty()) {
+ std::string aSolidName =
+ (aName + "_Solid_" + TCollection_AsciiString(aTag - theDecomposeSolidsTag)).ToCString();
+ std::shared_ptr<Model_Document> aDoc =
+ std::dynamic_pointer_cast<Model_Document>(document());
+ aDoc->addNamingName(aSubBuilder.NamedShape()->Label(), aSolidName);
+ TDataStd_Name::Set(aSubBuilder.NamedShape()->Label(), aSolidName.c_str());
+ }
+ }
+ }
}
}