-
- myIsDisabled = true; // by default it is not initialized and false to be after created
- setIsConcealed(false);
-}
-
-void Model_ResultBody::initAttributes()
-{
- // append the color attribute. It is empty, the attribute will be filled by a request
- DataPtr aData = data();
- aData->addAttribute(COLOR_ID(), ModelAPI_AttributeIntArray::typeId());
-}
-
-void Model_ResultBody::colorConfigInfo(std::string& theSection, std::string& theName,
- std::string& theDefault)
-{
- theSection = "Visualization";
- theName = "result_body_color";
- 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 (aChanged) { // state is changed, so modifications are needed
- std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(data());
- if (!aData) // unknown case
- return aChanged;
- TDF_Label& aShapeLab = aData->shapeLab();
- EvolutionToSelection(aShapeLab, theFlag);
- }
- return aChanged;