void FiltersPlugin_Selection::setAttribute(const AttributePtr& theAttr)
{
- if (myBase != theAttr) { // clear all filters if the attribute is changed or defined a new
- std::list<std::string> aFilters;
- data()->allGroups(aFilters);
- std::list<std::string>::iterator aFIter = aFilters.begin();
- for(; aFIter != aFilters.end(); aFIter++) {
- data()->removeAttributes(*aFIter);
- }
- }
myBase = theAttr;
if (myBase.get()) { // check that the type of sub-elements is supported by all existing filters
std::shared_ptr<ModelAPI_AttributeSelectionList> aSelList =
{
return myBase;
}
+
+void FiltersPlugin_Selection::initAttributes()
+{
+ ModelAPI_FiltersFactory* aFactory = ModelAPI_Session::get()->filters();
+ std::list<std::string> aFilters;
+ data()->allGroups(aFilters);
+ for(std::list<std::string>::iterator aFIt = aFilters.begin(); aFIt != aFilters.end(); aFIt++) {
+ FilterPtr aFilter = aFactory->filter(*aFIt);
+ if (aFilter.get()) {
+ std::shared_ptr<ModelAPI_AttributeBoolean> aBool =
+ std::dynamic_pointer_cast<ModelAPI_AttributeBoolean>(data()->addFloatingAttribute(
+ kReverseAttrID, ModelAPI_AttributeBoolean::typeId(), *aFIt));
+ aBool->setValue(false); // not reversed by default
+ ModelAPI_FiltersArgs anArgs;
+ anArgs.setFeature(std::dynamic_pointer_cast<ModelAPI_FiltersFeature>(data()->owner()));
+ anArgs.setFilter(*aFIt);
+ aFilter->initAttributes(anArgs);
+ }
+ }
+}
/// Computes a selection?
FILTERS_EXPORT virtual void execute() {}
- /// Initially there are no filters selected, so, no attributes
- virtual void initAttributes() {}
-
/// Feature is created in the plugin manager
FiltersPlugin_Selection() {}
+ /// This method initializes all filters on open of document
+ FILTERS_EXPORT virtual void initAttributes() override;
+
// methods related to the filters management
/// Adds a filter to the feature. Also initializes arguments of this filter.
protected:
AttributePtr myBase; ///< the attribute related to this filter
-
};
#endif
int anIndex;
TDF_Label aLab;
if (myLab.IsAttribute(TDF_TagSource::GetID())) {
+ // check this is re-init of attributes, so, check attribute with this name already there
+ TDF_ChildIDIterator anIter(myLab, kGroupAttributeID, false);
+ for(; anIter.More(); anIter.Next()) {
+ TCollection_AsciiString aThisName(Handle(TDataStd_Name)::DownCast(anIter.Value())->Get());
+ if (theID == aThisName.ToCString()) {
+ TDF_Label aLab = anIter.Value()->Label();
+ Handle(TDataStd_Name) aGName;
+ if (aLab.FindAttribute(kGroupAttributeGroupID, aGName)) {
+ TCollection_AsciiString aGroupName(aGName->Get());
+ if (theGroup == aGroupName.ToCString()) {
+ return addAttribute(theGroup + "__" + theID, theAttrType, aLab.Tag());
+ }
+ }
+ }
+ }
aLab = myLab.NewChild(); // already exists a floating attribute, create the next
anIndex = aLab.Tag();
} else { // put the first floating attribute, quite far from other standard attributes
Handle(TDataStd_Name) aGroupID = Handle(TDataStd_Name)::DownCast(aGroup.Value());
if (aGroupID->Get().IsEqual(theGroup.c_str())) {
Handle(TDataStd_Name) anID;
- if (aGroup.Value()->Label().FindAttribute(kGroupAttributeID, anID)) {
- TCollection_AsciiString anAsciiID(aGroupID->Get() + "__" + anID->Get());
- myAttrs.erase(anAsciiID.ToCString());
+ if (!aGroup.Value()->Label().IsNull() &&
+ aGroup.Value()->Label().FindAttribute(kGroupAttributeID, anID)) {
aLabsToRemove.Append(aGroup.Value()->Label());
}
+ TCollection_AsciiString anAsciiID(aGroupID->Get() + "__" + anID->Get());
+ myAttrs.erase(anAsciiID.ToCString());
}
}
for(TDF_LabelList::Iterator aLab(aLabsToRemove); aLab.More(); aLab.Next()) {
}
}
+void Model_Data::clearAttributes()
+{
+ myAttrs.clear();
+}
+
+
// macro for the generic returning of the attribute by the ID
#define GET_ATTRIBUTE_BY_ID(ATTR_TYPE, METHOD_NAME) \
/// Sets true if the object is deleted, but some data is still kept in memory
MODEL_EXPORT virtual void setIsDeleted(const bool theFlag);
+ /// Erases all attributes from myAttrs, but keeping them in the data structure
+ void clearAttributes();
+
private:
/// Removes a back reference (with identifier which attribute references to this object)
/// \param theFeature feature referenced to this
/// Returns \c true if theAttribute1 is going earlier than theAttribute2 in the data
MODEL_EXPORT virtual bool isPrecedingAttribute(const std::string& theAttribute1,
const std::string& theAttribute2) const;
+
+ friend class Model_Objects;
};
/// Generic method to register back reference, used in referencing attributes.
#include <ModelAPI_Validator.h>
#include <ModelAPI_CompositeFeature.h>
#include <ModelAPI_Tools.h>
+#include <ModelAPI_Filter.h>
+
#include <Events_Loop.h>
#include <Events_InfoMessage.h>
if (anUpdatedMap.Contains(aFeatureLabel)) {
if (!theOpen) { // on abort/undo/redo reinitialize attributes if something is changed
- std::list<std::shared_ptr<ModelAPI_Attribute> > anAttrs =
- anObject->data()->attributes("");
- std::list<std::shared_ptr<ModelAPI_Attribute> >::iterator anAttr = anAttrs.begin();
- for(; anAttr != anAttrs.end(); anAttr++)
- (*anAttr)->reinit();
+ FiltersFeaturePtr aFilter = std::dynamic_pointer_cast<ModelAPI_FiltersFeature>(anObject);
+ if (aFilter.get()) { // for filters attributes may be added/removed on undo/redo
+ std::dynamic_pointer_cast<Model_Data>(aFilter->data())->clearAttributes();
+ aFilter->initAttributes();
+ } else {
+ std::list<std::shared_ptr<ModelAPI_Attribute> > anAttrs =
+ anObject->data()->attributes("");
+ std::list<std::shared_ptr<ModelAPI_Attribute> >::iterator anAttr = anAttrs.begin();
+ for(; anAttr != anAttrs.end(); anAttr++)
+ (*anAttr)->reinit();
+ }
}
ModelAPI_EventCreator::get()->sendUpdated(anObject, anUpdateEvent);
if (aFeature && aFeature->getKind() == "Parameter") {