From 48b3193b3aa7ad3413effc73276ab77d6226d73f Mon Sep 17 00:00:00 2001 From: mpv Date: Fri, 10 Aug 2018 10:30:16 +0300 Subject: [PATCH] Implementation of names of features selection. --- .../FeaturesPlugin_Validators.cpp | 11 +++-- .../GeomValidators_IntersectionSelection.cpp | 12 +++-- src/Model/Model_AttributeSelection.cpp | 47 ++++++++++++++++++- src/Model/Model_Data.cpp | 39 ++++++++++----- src/ModelHighAPI/ModelHighAPI_Dumper.cpp | 10 +++- 5 files changed, 98 insertions(+), 21 deletions(-) diff --git a/src/FeaturesPlugin/FeaturesPlugin_Validators.cpp b/src/FeaturesPlugin/FeaturesPlugin_Validators.cpp index c62648649..5400cbd3f 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Validators.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Validators.cpp @@ -583,8 +583,11 @@ bool FeaturesPlugin_ValidatorBooleanSelection::isValid(const AttributePtr& theAt } ResultPtr aContext = anAttrSelection->context(); if(!aContext.get()) { - theError = "Error: Empty selection context."; - return false; + FeaturePtr aContFeat = anAttrSelection->contextFeature(); + if (!aContFeat.get()) { + theError = "Error: Empty selection context."; + return false; + } } ResultConstructionPtr aResultConstruction = std::dynamic_pointer_cast(aContext); @@ -596,15 +599,15 @@ bool FeaturesPlugin_ValidatorBooleanSelection::isValid(const AttributePtr& theAt } } std::shared_ptr aShape = anAttrSelection->value(); - GeomShapePtr aContextShape = aContext->shape(); if(!aShape.get()) { + GeomShapePtr aContextShape = aContext->shape(); aShape = aContextShape; } if(!aShape.get()) { theError = "Error: Empty shape."; return false; } - if(!aShape->isEqual(aContextShape)) { + if (aContext.get() && !aShape->isEqual(aContext->shape())) { theError = "Error: Local selection not allowed."; return false; } diff --git a/src/GeomValidators/GeomValidators_IntersectionSelection.cpp b/src/GeomValidators/GeomValidators_IntersectionSelection.cpp index 010098800..fe437a01a 100644 --- a/src/GeomValidators/GeomValidators_IntersectionSelection.cpp +++ b/src/GeomValidators/GeomValidators_IntersectionSelection.cpp @@ -45,12 +45,18 @@ bool GeomValidators_IntersectionSelection::isValid(const AttributePtr& theAttrib theError = "Error: empty attribute selection."; return false; } + FeaturePtr aFeature; ResultPtr aContext = anAttrSelection->context(); if(!aContext.get()) { - theError = "Error: empty selection context."; - return false; + aFeature = anAttrSelection->contextFeature(); + if (!aFeature.get()) { + theError = "Error: Empty selection context."; + return false; + } + } else { + aFeature = ModelAPI_Feature::feature(aContext); } - FeaturePtr aFeature = ModelAPI_Feature::feature(aContext); + if(!aFeature.get()) { theError = "Error: empty feature."; return false; diff --git a/src/Model/Model_AttributeSelection.cpp b/src/Model/Model_AttributeSelection.cpp index a57ba24b3..b76998d85 100644 --- a/src/Model/Model_AttributeSelection.cpp +++ b/src/Model/Model_AttributeSelection.cpp @@ -39,6 +39,7 @@ #include #include #include +#include #include #include @@ -85,6 +86,9 @@ Standard_GUID kELLIPSE_CENTER1("f70df04c-3168-4dc9-87a4-f1f840c1275d"); // identifier of the selection of the second focus point of ellipse on edge Standard_GUID kELLIPSE_CENTER2("1395ae73-8e02-4cf8-b204-06ff35873a32"); +// prefix for the whole feature context identification +const static std::string kWHOLE_FEATURE = "all-in-"; + // on this label is stored: // TNaming_NamedShape - selected shape // TNaming_Naming - topological selection information (for the body) @@ -349,6 +353,22 @@ std::shared_ptr Model_AttributeSelection::internalValue(CenterTyp if (aConstr->isInfinite()) return aResult; // empty result } + // whole feature + FeaturePtr aFeature = contextFeature(); + if (aFeature.get()) { + std::list allShapes; + std::list::const_iterator aRes = aFeature->results().cbegin(); + for (; aRes != aFeature->results().cend(); aRes++) { + if (aRes->get() && !(*aRes)->isDisabled()) { + GeomShapePtr aShape = (*aRes)->shape(); + if (aShape.get() && !aShape->isNull()) { + allShapes.push_back(aShape); + } + } + } + return GeomAlgoAPI_CompoundBuilder::compound(allShapes); + } + Handle(TNaming_NamedShape) aSelection; if (aSelLab.FindAttribute(TNaming_NamedShape::GetID(), aSelection)) { TopoDS_Shape aSelShape = aSelection->Get(); @@ -394,6 +414,10 @@ bool Model_AttributeSelection::isInitialized() return true; } } + // for the whole feature, a feature object + FeaturePtr aFeat = contextFeature(); + if (aFeat.get()) + return true; } } } @@ -795,8 +819,15 @@ std::string Model_AttributeSelection::namingName(const std::string& theDefaultNa std::shared_ptr aSubSh = internalValue(aCenterType); ResultPtr aCont = context(); - if (!aCont.get()) // in case of selection of removed result + if (!aCont.get()) { + // selection of a full feature + FeaturePtr aFeatureCont = contextFeature(); + if (aFeatureCont.get()) { + return kWHOLE_FEATURE + aFeatureCont->name(); + } + // in case of selection of removed result return ""; + } Model_SelectionNaming aSelNaming(selectionLabel()); std::string aResult = aSelNaming.namingName( @@ -867,9 +898,21 @@ void Model_AttributeSelection::selectSubShape( } } - Model_SelectionNaming aSelNaming(selectionLabel()); std::shared_ptr aDoc = std::dynamic_pointer_cast(owner()->document()); + // check this is a whole feature context + if (aSubShapeName.size() > kWHOLE_FEATURE.size() && + aSubShapeName.substr(0, kWHOLE_FEATURE.size()) == kWHOLE_FEATURE) { + std::string aFeatureName = aSubShapeName.substr(kWHOLE_FEATURE.size()); + ObjectPtr anObj = aDoc->objectByName(ModelAPI_Feature::group(), aFeatureName); + if (anObj.get()) { + static const GeomShapePtr anEmptyShape; + setValue(anObj, anEmptyShape); + return; + } + } + + Model_SelectionNaming aSelNaming(selectionLabel()); std::shared_ptr aShapeToBeSelected; ResultPtr aCont; if (aSelNaming.selectSubShape(aType, aSubShapeName, aDoc, aShapeToBeSelected, aCont)) { diff --git a/src/Model/Model_Data.cpp b/src/Model/Model_Data.cpp index 6a7af0170..697bfedd9 100644 --- a/src/Model/Model_Data.cpp +++ b/src/Model/Model_Data.cpp @@ -484,10 +484,10 @@ int Model_Data::featureId() const void Model_Data::eraseBackReferences() { myRefsToMe.clear(); - std::shared_ptr aRes = - std::dynamic_pointer_cast(myObject); - if (aRes) + std::shared_ptr aRes = std::dynamic_pointer_cast(myObject); + if (aRes) { aRes->setIsConcealed(false); + } } void Model_Data::removeBackReference(ObjectPtr theObject, std::string theAttrID) @@ -518,8 +518,7 @@ void Model_Data::addBackReference(FeaturePtr theFeature, std::string theAttrID, if (theApplyConcealment && theFeature->isStable() && ModelAPI_Session::get()->validators()->isConcealed(theFeature->getKind(), theAttrID)) { - std::shared_ptr aRes = - std::dynamic_pointer_cast(myObject); + std::shared_ptr aRes = std::dynamic_pointer_cast(myObject); // the second condition is for history upper than concealment causer, so the feature result may // be displayed and previewed; also for avoiding of quick show/hide on history // moving deep down @@ -546,8 +545,7 @@ void Model_Data::updateConcealmentFlag() if (aFeature.get() && !aFeature->isDisabled() && aFeature->isStable()) { if (ModelAPI_Session::get()->validators()->isConcealed( aFeature->getKind(), (*aRefsIter)->id())) { - std::shared_ptr aRes = - std::dynamic_pointer_cast(myObject); + std::shared_ptr aRes = std::dynamic_pointer_cast(myObject); if (aRes.get()) { aRes->setIsConcealed(true); // set concealed return; @@ -637,15 +635,34 @@ void Model_Data::referencesToObjects( } } else if (aType == ModelAPI_AttributeRefList::typeId()) { // list of references aReferenced = std::dynamic_pointer_cast(anAttr)->list(); - } else if (aType == ModelAPI_AttributeSelection::typeId()) { // selection attribute + } + else if (aType == ModelAPI_AttributeSelection::typeId()) { // selection attribute std::shared_ptr aRef = std::dynamic_pointer_cast< - ModelAPI_AttributeSelection>(anAttr); - aReferenced.push_back(aRef->context()); + ModelAPI_AttributeSelection>(anAttr); + FeaturePtr aRefFeat = aRef->contextFeature(); + if (aRefFeat.get()) { // reference to all results of the referenced feature + const std::list& allRes = aRefFeat->results(); + std::list::const_iterator aRefRes = allRes.cbegin(); + for(; aRefRes != allRes.cend(); aRefRes++) { + aReferenced.push_back(*aRefRes); + } + } else { + aReferenced.push_back(aRef->context()); + } } else if (aType == ModelAPI_AttributeSelectionList::typeId()) { // list of selection attributes std::shared_ptr aRef = std::dynamic_pointer_cast< ModelAPI_AttributeSelectionList>(anAttr); for(int a = 0, aSize = aRef->size(); a < aSize; ++a) { - aReferenced.push_back(aRef->value(a)->context()); + FeaturePtr aRefFeat = aRef->value(a)->contextFeature(); + if (aRefFeat.get()) { // reference to all results of the referenced feature + const std::list& allRes = aRefFeat->results(); + std::list::const_iterator aRefRes = allRes.cbegin(); + for (; aRefRes != allRes.cend(); aRefRes++) { + aReferenced.push_back(*aRefRes); + } + } else { + aReferenced.push_back(aRef->value(a)->context()); + } } } else if (aType == ModelAPI_AttributeRefAttrList::typeId()) { std::shared_ptr aRefAttr = std::dynamic_pointer_cast< diff --git a/src/ModelHighAPI/ModelHighAPI_Dumper.cpp b/src/ModelHighAPI/ModelHighAPI_Dumper.cpp index 5142efc31..8bc41417b 100644 --- a/src/ModelHighAPI/ModelHighAPI_Dumper.cpp +++ b/src/ModelHighAPI/ModelHighAPI_Dumper.cpp @@ -787,16 +787,24 @@ ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(const ResultPtr& theResult) { // iterate in the structure of sub-results to the parent ResultPtr aCurRes = theResult; + FeaturePtr aFeature = ModelAPI_Feature::feature(theResult); std::list anIndices; // indexes of results in the parent result, starting from topmost while(aCurRes.get()) { ResultBodyPtr aParent = ModelAPI_Tools::bodyOwner(aCurRes); if (aParent) { anIndices.push_front(ModelAPI_Tools::bodyIndex(aCurRes)); + } else { // index of the result in the feature + std::list::const_iterator aRes = aFeature->results().cbegin(); + for(int anIndex = 0; aRes != aFeature->results().cend(); aRes++, anIndex++) { + if (*aRes == aCurRes) { + anIndices.push_front(anIndex); + break; + } + } } aCurRes = aParent; } - FeaturePtr aFeature = ModelAPI_Feature::feature(theResult); myDumpBuffer << name(aFeature); for (std::list::iterator anI = anIndices.begin(); anI != anIndices.end(); anI++) { if (anI == anIndices.begin()) { -- 2.30.2