bool result = true;
for (; it != theArguments.end(); ++it) {
std::string anArg = *it;
- int aSepPos = anArg.find(":");
+ size_t aSepPos = anArg.find(":");
if (aSepPos == std::string::npos) {
result = false;
continue;
#include <TDF_ChildIterator.hxx>
#include <TDF_RelocationTable.hxx>
#include <TopAbs_ShapeEnum.hxx>
-
#include <TopoDS.hxx>
#include <TopoDS_Shape.hxx>
#include <TopoDS_Edge.hxx>
#include <BRep_Tool.hxx>
+#include <TNaming_Builder.hxx>
+#include <TNaming_Iterator.hxx>
using namespace std;
}
}
-#include <TNaming_Builder.hxx>
-#include <TNaming_Iterator.hxx>
-
// copies named shapes: we need the implementation of this
static void CopyNS(const Handle(TNaming_NamedShape)& theFrom,
const Handle(TDF_Attribute)& theTo)
const std::shared_ptr<GeomAPI_Shape>& theSubShape,
const bool theTemporarily)
{
+ if (myCash.size()) { // the cashing is active
+ std::map<ResultPtr, std::list<const std::shared_ptr<GeomAPI_Shape> > >::iterator aContext =
+ myCash.find(theContext);
+ if (aContext != myCash.end()) {
+ // iterate shapes because "isEqual" method must be called for each shape
+ std::list<const std::shared_ptr<GeomAPI_Shape> >::iterator aShapes = aContext->second.begin();
+ for(; aShapes != aContext->second.end(); aShapes++) {
+ if (!theSubShape.get()) {
+ if (!aShapes->get())
+ return true;
+ } else {
+ if (theSubShape->isEqual(*aShapes))
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+ // no-cash method
for(int anIndex = size() - 1; anIndex >= 0; anIndex--) {
AttributeSelectionPtr anAttr = value(anIndex);
if (anAttr.get()) {
theLabel.FindAttribute(TDataStd_Comment::GetID(), mySelectionType);
}
}
+
+void Model_AttributeSelectionList::cashValues(const bool theEnabled) {
+ myCash.clear(); // empty list as indicator that cash is not used
+ if (theEnabled) {
+ for(int anIndex = size() - 1; anIndex >= 0; anIndex--) {
+ AttributeSelectionPtr anAttr = value(anIndex);
+ if (anAttr.get()) {
+ myCash[anAttr->context()].push_back(anAttr->value());
+ }
+ }
+ }
+}
#include <TDataStd_Integer.hxx>
#include <TDataStd_Comment.hxx>
#include <vector>
+#include <map>
/**\class Model_AttributeSelectionList
* \ingroup DataModel
class Model_AttributeSelectionList : public ModelAPI_AttributeSelectionList
{
Handle(TDataStd_Integer) mySize; ///< Contains size of this list
- Handle(TDataStd_Comment) mySelectionType; ///< Contains current type name (same as selection attribute)
+ /// Contains current type name (same as selection attribute)
+ Handle(TDataStd_Comment) mySelectionType;
std::shared_ptr<Model_AttributeSelection> myTmpAttr; ///< temporary attribute (the last one)
+ /// the cashed shapes to optimize isInList method: from context to set of shapes in this context
+ std::map<ResultPtr, std::list<const std::shared_ptr<GeomAPI_Shape> > > myCash;
public:
/// Adds the new reference to the end of the list
/// \param theContext object where the sub-shape was selected
/// Returns true if attribute was initialized by some value
MODEL_EXPORT virtual bool isInitialized();
+ /// Starts or stops cashing of the values in the attribute (the cash may become invalid
+ /// on modification of the attribute or sub-elements, so the cash must be enabled only
+ /// during non-modification operations with this attribute)
+ MODEL_EXPORT virtual void cashValues(const bool theEnabled);
+
protected:
/// Objects are created for features automatically
MODEL_EXPORT Model_AttributeSelectionList(TDF_Label& theLabel);
/// Returns all attributes
virtual void clear() = 0;
+ /// Starts or stops cashing of the values in the attribute (the cash may become invalid
+ /// on modification of the attribute or sub-elements, so the cash must be enabled only
+ /// during non-modification operations with this attribute)
+ virtual void cashValues(const bool theEnabled) = 0;
+
/// Returns the type of this class of attributes
static std::string typeId()
{