X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModel%2FModel_AttributeSelectionList.cpp;h=0ed47aca4a6952184f3d71473ea39c9e1e4c7a6f;hb=21b49d1cb352330d2221dbe397a1621ef9b04a01;hp=50b04d3c35d967dd388f9b8637f60d340a5aa19f;hpb=696ce87ccb8fed24ff4451f3a1d1235cd0d89a53;p=modules%2Fshaper.git diff --git a/src/Model/Model_AttributeSelectionList.cpp b/src/Model/Model_AttributeSelectionList.cpp index 50b04d3c3..0ed47aca4 100644 --- a/src/Model/Model_AttributeSelectionList.cpp +++ b/src/Model/Model_AttributeSelectionList.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2019 CEA/DEN, EDF R&D +// Copyright (C) 2014-2021 CEA/DEN, EDF R&D // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -65,9 +65,7 @@ void Model_AttributeSelectionList::append( } if (myIsCashed && !theTemporarily) { - ResultPtr aResContext = std::dynamic_pointer_cast(theContext); - if (aResContext.get()) - myCash[aResContext].push_back(theSubShape); + myCash[theContext].push_back(theSubShape); } int aNewTag = mySize->Get() + 1; @@ -90,7 +88,7 @@ void Model_AttributeSelectionList::append( } void Model_AttributeSelectionList::append( - const std::string& theNamingName, const std::string& theType) + const std::wstring& theNamingName, const std::string& theType) { int aNewTag = mySize->Get() + 1; TDF_Label aNewLab = mySize->Label().FindChild(aNewTag); @@ -125,7 +123,7 @@ void Model_AttributeSelectionList::append(const GeomPointPtr& thePoint, const st } void Model_AttributeSelectionList::append(const std::string& theType, - const std::string& theContextName, const int theIndex) + const std::wstring& theContextName, const int theIndex) { int aNewTag = mySize->Get() + 1; TDF_Label aNewLab = mySize->Label().FindChild(aNewTag); @@ -219,6 +217,8 @@ static void copyAttrs(TDF_Label theSource, TDF_Label theDestination) { if (!theDestination.FindAttribute(anAttrIter.Value()->ID(), aTargetAttr)) { // create a new attribute if not yet exists in the destination aTargetAttr = anAttrIter.Value()->NewEmpty(); + if (aTargetAttr->ID() != anAttrIter.Value()->ID()) + aTargetAttr->SetID(anAttrIter.Value()->ID()); theDestination.AddAttribute(aTargetAttr); } // for named shape copy exact shapes (in NamedShape Paste method the CopyTool is used) @@ -269,6 +269,16 @@ void Model_AttributeSelectionList::remove(const std::set& theIndices) } } +void Model_AttributeSelectionList::copyTo(AttributeSelectionListPtr theTarget) const +{ + std::shared_ptr aTarget = + std::dynamic_pointer_cast(theTarget); + if (aTarget) { + copyAttrs(myLab, aTarget->myLab); + aTarget->reinit(); + } +} + int Model_AttributeSelectionList::size() { return mySize->Get(); @@ -291,19 +301,22 @@ static bool isIn(GeomShapePtr theInList, GeomShapePtr theShape) { bool Model_AttributeSelectionList::isInList(const ObjectPtr& theContext, const std::shared_ptr& theSubShape, - const bool theTemporarily) + const bool /*theTemporarily*/) { - ResultPtr aResCont = std::dynamic_pointer_cast(theContext); if (myIsCashed) { // the cashing is active - if (aResCont.get()) { - std::map > >::iterator aContext = - myCash.find(aResCont); + if (theContext.get()) { + std::map > >::iterator aContext = + myCash.find(theContext); if (aContext != myCash.end()) { // iterate shapes because "isSame" method must be called for each shape std::list >::iterator aShapes = aContext->second.begin(); for(; aShapes != aContext->second.end(); aShapes++) { if (!theSubShape.get()) { - if (!aShapes->get() || (*aShapes)->isSame(aContext->first->shape())) + if (!aShapes->get()) + return true; + ResultPtr aRes = std::dynamic_pointer_cast(aContext->first); + FeaturePtr aFeat = std::dynamic_pointer_cast(aContext->first); + if ((aRes.get() && (*aShapes)->isSame(aRes->shape())) || aFeat.get()) return true; } else { // we need to call here isSame instead of isEqual to do not check shapes orientation @@ -316,15 +329,21 @@ bool Model_AttributeSelectionList::isInList(const ObjectPtr& theContext, } } // no-cash method + bool isFeature = std::dynamic_pointer_cast(theContext).get() != NULL; + ResultPtr aRes; + if (!isFeature) + aRes = std::dynamic_pointer_cast(theContext); for(int anIndex = size() - 1; anIndex >= 0; anIndex--) { AttributeSelectionPtr anAttr = value(anIndex); if (anAttr.get()) { - if (anAttr->context() == theContext) { // contexts are equal, so, check that values are also + if (isFeature && anAttr->contextFeature() == theContext) + return true; // for the feature value should not be compared + if (!isFeature && anAttr->context() == theContext) { + // contexts are equal, so, check that values are also std::shared_ptr aValue = anAttr->value(); if (!theSubShape.get()) { - if (!aValue.get() || (aResCont.get() && aValue->isSame(aResCont->shape()))) {// both null + if (!aValue.get() || (aRes.get() && aValue->isSame(aRes->shape()))) return true; - } } else { // we need to call here isSame instead of isEqual to do not check shapes orientation if (isIn(aValue, theSubShape)) // shapes are equal @@ -398,7 +417,7 @@ bool Model_AttributeSelectionList::isInitialized() } Model_AttributeSelectionList::Model_AttributeSelectionList(TDF_Label& theLabel) -: myLab(theLabel) +: ModelAPI_AttributeSelectionList(), myLab(theLabel) { reinit(); } @@ -424,7 +443,7 @@ void Model_AttributeSelectionList::cashValues(const bool theEnabled) for(int anIndex = size() - 1; anIndex >= 0; anIndex--) { AttributeSelectionPtr anAttr = value(anIndex); if (anAttr.get()) { - myCash[anAttr->context()].push_back(anAttr->value()); + myCash[anAttr->contextObject()].push_back(anAttr->value()); } } }