X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FFeaturesPlugin%2FFeaturesPlugin_ImportResult.cpp;h=9e6a14c4844df1f522e4fcaac1b33b5aa1194a83;hb=c575ad28dd7f9087e727b675f43bbbc9ad3446f6;hp=a49ef0fb480529c1edb95e640f8386493804400f;hpb=0c316ec74fd5f46832756cb6304fd644d017cc2a;p=modules%2Fshaper.git diff --git a/src/FeaturesPlugin/FeaturesPlugin_ImportResult.cpp b/src/FeaturesPlugin/FeaturesPlugin_ImportResult.cpp index a49ef0fb4..9e6a14c48 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_ImportResult.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_ImportResult.cpp @@ -20,33 +20,181 @@ #include "FeaturesPlugin_ImportResult.h" #include +#include #include +#include #include #include +#include #include +#include void FeaturesPlugin_ImportResult::initAttributes() { data()->addAttribute(OBJECTS(), ModelAPI_AttributeSelectionList::typeId()); + + AttributePtr aFeaturesAttribute = + data()->addAttribute(FEATURES_ID(), + ModelAPI_AttributeRefList::typeId()); + aFeaturesAttribute->setIsArgument(false); + + ModelAPI_Session::get()->validators()->registerNotObligatory( + getKind(), FEATURES_ID()); } void FeaturesPlugin_ImportResult::execute() { + // Process groups/fields + std::shared_ptr aRefListOfGroups = + std::dynamic_pointer_cast(data()->attribute(FEATURES_ID())); + + // Remove previous groups/fields stored in RefList + //std::list anGroupList = aRefListOfGroups->list(); + //std::list::iterator anGroupIt = anGroupList.begin(); + const std::list& anGroupList = aRefListOfGroups->list(); + std::list::const_iterator anGroupIt = anGroupList.begin(); + for (; anGroupIt != anGroupList.end(); ++anGroupIt) { + std::shared_ptr aFeature = ModelAPI_Feature::feature(*anGroupIt); + if (aFeature) + document()->removeFeature(aFeature); + } + + aRefListOfGroups->clear(); + + std::set aGlobalResultsCashed; // cash to speed up searching in all results selected + std::list aGroups; + + std::list aResults; + AttributeSelectionListPtr aList = selectionList(OBJECTS()); int aResultIndex = 0; - for (int aSelIndex = 0; aSelIndex < aList->size(); aSelIndex++) { + for (int aSelIndex = 0; aSelIndex < aList->size(); aSelIndex++) + { AttributeSelectionPtr aSel = aList->value(aSelIndex); + ResultPtr aContext = aSel->context(); - if (!aContext.get()) - continue; - GeomShapePtr aShape = aContext->shape(); + if (aContext.get()) + aResults.push_back (aContext); + else + { + FeaturePtr aFeature = aSel->contextFeature(); + if (aFeature.get()) + { + const std::list& aResList = aFeature->results(); + aResults.assign (aResList.begin(), aResList.end()); + } + } + } + + std::list::iterator aResIter = aResults.begin(); + for(; aResIter != aResults.end(); aResIter++) + { + GeomShapePtr aShape = (*aResIter)->shape(); if (!aShape.get() || aShape->isNull()) continue; + std::shared_ptr aResultBody = document()->createBody(data(), aResultIndex); aResultBody->store(aShape); aResultBody->loadFirstLevel(aShape, "ImportResult"); setResult(aResultBody, aResultIndex++); + + std::set allResultsCashed; // cash to speed up searching in all results selected + std::list aLocalResults; + aLocalResults.push_back (*aResIter); + + std::list aDocuments; /// documents of Parts + aDocuments.push_back ((*aResIter)->document()); + std::list::iterator aDoc = aDocuments.begin(); + for(; aDoc != aDocuments.end(); aDoc++) + { + // groups + int aGroupCount = (*aDoc)->size(ModelAPI_ResultGroup::group()); + for (int aGroupIndex = 0; aGroupIndex < aGroupCount; ++aGroupIndex) + { + ResultGroupPtr aResultGroup = + std::dynamic_pointer_cast((*aDoc)->object(ModelAPI_ResultGroup::group(), aGroupIndex)); + + if (!aResultGroup.get() || !aResultGroup->shape().get()) + continue; + + FeaturePtr aGroupFeature = (*aDoc)->feature(aResultGroup); + + AttributeSelectionListPtr aSelectionList = + aGroupFeature->selectionList("group_list"); + + if (!ModelAPI_Tools::isInResults(aSelectionList, + aLocalResults, + allResultsCashed))// skip group not used in result + continue; + + aGlobalResultsCashed.insert (allResultsCashed.begin(), allResultsCashed.end()); + + //Check: may be this group already exists in the list + bool anIsFound = false; + std::list::iterator anIter = aGroups.begin(); + for (; anIter != aGroups.end(); anIter++) + { + if (*anIter == aResultGroup) + { + anIsFound = true; + break; + } + } + if (!anIsFound) + aGroups.push_back (aResultGroup); + } + } + } + + std::list::iterator anIter = aGroups.begin(); + for (; anIter != aGroups.end(); anIter++) + { + DocumentPtr aDoc = (*anIter)->document(); + + FeaturePtr aGroupFeature = aDoc->feature(*anIter); + + AttributeSelectionListPtr aSelectionList = + aGroupFeature->selectionList("group_list"); + + std::shared_ptr aNewGroupFeature = addFeature("Group"); + aNewGroupFeature->data()->setName(aGroupFeature->name()); + + AttributeSelectionListPtr aNewSelectionList = aNewGroupFeature->selectionList("group_list"); + aNewSelectionList->setSelectionType (aSelectionList->selectionType()); + GeomAPI_Shape::ShapeType aTypeOfShape = GeomAPI_Shape::shapeTypeByStr (aSelectionList->selectionType()); + + for (int aLocalSelIndex = 0; aLocalSelIndex < aSelectionList->size(); aLocalSelIndex++) { + + AttributeSelectionPtr aLocalSel = aSelectionList->value(aLocalSelIndex); + ResultPtr aLocalContext = aLocalSel->context(); + ResultGroupPtr aLocalGroup = std::dynamic_pointer_cast (aLocalContext); + if (aLocalGroup.get()) + { + GeomShapePtr aLocalShape = aGroupFeature->firstResult()->shape(); + GeomAPI_ShapeExplorer anExplo (aLocalShape, aTypeOfShape); + for (; anExplo.more(); anExplo.next()) + { + GeomShapePtr anExploredShape = anExplo.current(); + std::set::iterator aResultIter = aGlobalResultsCashed.begin(); + for (; aResultIter != aGlobalResultsCashed.end(); aResultIter++) + { + GeomShapePtr aCashedShape = (*aResultIter)->shape(); + if (aCashedShape->isSubShape(anExploredShape)) + aNewSelectionList->append((*aResultIter), anExploredShape); + } + } + break; + } + else + { + GeomShapePtr aLocalShape = aLocalSel->value(); + + if (aLocalContext.get() && aGlobalResultsCashed.count(aLocalContext)) + aNewSelectionList->append(aLocalContext, aLocalShape); + } + } } + removeResults(aResultIndex); } @@ -115,3 +263,69 @@ bool FeaturesPlugin_ValidatorImportResults::isValid(const AttributePtr& theAttri } return true; } + +//============================================================================ +std::shared_ptr FeaturesPlugin_ImportResult::addFeature( + std::string theID) +{ + std::shared_ptr aNew = document()->addFeature(theID, false); + if (aNew) + data()->reflist(FEATURES_ID())->append(aNew); + // set as current also after it becomes sub to set correctly enabled for other subs + //document()->setCurrentFeature(aNew, false); + return aNew; +} + +//================================================================================================= +int FeaturesPlugin_ImportResult::numberOfSubs(bool /*forTree*/) const +{ + return data()->reflist(FEATURES_ID())->size(true); +} + +//================================================================================================= +std::shared_ptr FeaturesPlugin_ImportResult::subFeature(const int theIndex, + bool /*forTree*/) +{ + ObjectPtr anObj = data()->reflist(FEATURES_ID())->object(theIndex, false); + FeaturePtr aRes = std::dynamic_pointer_cast(anObj); + return aRes; +} + +//================================================================================================= +int FeaturesPlugin_ImportResult::subFeatureId(const int theIndex) const +{ + std::shared_ptr aRefList = std::dynamic_pointer_cast< + ModelAPI_AttributeRefList>(data()->attribute(FEATURES_ID())); + std::list aFeatures = aRefList->list(); + std::list::const_iterator anIt = aFeatures.begin(); + int aResultIndex = 1; // number of the counted (created) features, started from 1 + int aFeatureIndex = -1; // number of the not-empty features in the list + for (; anIt != aFeatures.end(); anIt++) { + if (anIt->get()) + aFeatureIndex++; + if (aFeatureIndex == theIndex) + break; + aResultIndex++; + } + return aResultIndex; +} + +//================================================================================================= +bool FeaturesPlugin_ImportResult::isSub(ObjectPtr theObject) const +{ + // check is this feature of result + FeaturePtr aFeature = ModelAPI_Feature::feature(theObject); + if (aFeature) + return data()->reflist(FEATURES_ID())->isInList(aFeature); + return false; +} + +//================================================================================================= +void FeaturesPlugin_ImportResult::removeFeature( + std::shared_ptr theFeature) +{ + if (!data()->isValid()) + return; + AttributeRefListPtr aList = reflist(FEATURES_ID()); + aList->remove(theFeature); +}