#include <Events_InfoMessage.h>
#include <ModelAPI_Attribute.h>
-#include <ModelAPI_AttributeDouble.h>>
+#include <ModelAPI_AttributeDouble.h>
#include <ModelAPI_AttributeInteger.h>
#include <ModelAPI_AttributeSelectionList.h>
#include <ModelAPI_AttributeString.h>
#include <ModelAPI_Session.h>
#include <ModelAPI_AttributeBoolean.h>
+#include <ModelAPI_AttributeSelectionList.h>
// identifier of the reverse flag of a filter
static const std::string kReverseAttrID("");
data()->attributesOfGroup(theFilterID, aList);
return aList;
}
+
+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 =
+ std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttr);
+ if (aSelList.get()) {
+ std::string aStrType = aSelList->selectionType();
+ GeomAPI_Shape::ShapeType aType = GeomAPI_Shape::shapeTypeByStr(aStrType);
+ std::list<std::string> aFilters;
+ data()->allGroups(aFilters);
+ ModelAPI_FiltersFactory* aFactory = ModelAPI_Session::get()->filters();
+ std::list<std::string>::iterator aFIter = aFilters.begin();
+ for(; aFIter != aFilters.end(); aFIter++) {
+ FilterPtr aFilter = aFactory->filter(*aFIter);
+ if (aFilter.get() && !aFilter->isSupported(aType)) {
+ data()->removeAttributes(*aFIter);
+ }
+ }
+ }
+ }
+}
+
+const AttributePtr& FiltersPlugin_Selection::baseAttribute() const
+{
+ return myBase;
+}
// methods related to the filters management
/// Adds a filter to the feature. Also initializes arguments of this filter.
- FILTERS_EXPORT virtual void addFilter(const std::string theFilterID);
+ FILTERS_EXPORT virtual void addFilter(const std::string theFilterID) override;
/// Removes an existing filter from the feature.
- FILTERS_EXPORT virtual void removeFilter(const std::string theFilterID);
+ FILTERS_EXPORT virtual void removeFilter(const std::string theFilterID) override;
/// Returns the list of existing filters in the feature.
- FILTERS_EXPORT virtual std::list<std::string> filters() const;
+ FILTERS_EXPORT virtual std::list<std::string> filters() const override;
/// Stores the reversed flag for the filter.
- FILTERS_EXPORT virtual void setReversed(const std::string theFilterID, const bool theReversed);
+ FILTERS_EXPORT virtual void setReversed
+ (const std::string theFilterID, const bool theReversed) override;
/// Returns the reversed flag value for the filter.
- FILTERS_EXPORT virtual bool isReversed(const std::string theFilterID);
+ FILTERS_EXPORT virtual bool isReversed(const std::string theFilterID) override;
/// Returns the ordered list of attributes related to the filter.
- FILTERS_EXPORT virtual std::list<AttributePtr> filterArgs(const std::string theFilterID) const;
+ FILTERS_EXPORT virtual std::list<AttributePtr>
+ filterArgs(const std::string theFilterID) const override;
+
+ /// Sets the attribute (not-persistent field) that contains this filters feature.
+ /// The filter feature may make synchronization by this method call.
+ FILTERS_EXPORT virtual void setAttribute(const AttributePtr& theAttr) override;
+
+ /// Returns the attribute (not-persistent field) that contains this filters feature.
+ FILTERS_EXPORT virtual const AttributePtr& baseAttribute() const override;
+
+protected:
+
+ AttributePtr myBase; ///< the attribute related to this filter
+
};
#endif
GeomAPI_Shape::ShapeType GeomAPI_Shape::shapeTypeByStr(std::string theType)
{
std::transform(theType.begin(), theType.end(), theType.begin(), ::toupper);
- if (theType == "COMPOUND")
+ if (theType == "COMPOUND" || theType == "COMPOUNDS")
return COMPOUND;
- if (theType == "COMPSOLID")
+ if (theType == "COMPSOLID" || theType == "COMPSOLIDS")
return COMPSOLID;
- if (theType == "SOLID")
+ if (theType == "SOLID" || theType == "SOLIDS")
return SOLID;
- if (theType == "SHELL")
+ if (theType == "SHELL" || theType == "SHELLS")
return SHELL;
- if (theType == "FACE")
+ if (theType == "FACE" || theType == "FACES")
return FACE;
- if (theType == "WIRE")
+ if (theType == "WIRE" || theType == "WIRES")
return WIRE;
- if (theType == "EDGE")
+ if (theType == "EDGE" || theType == "EDGES")
return EDGE;
- if (theType == "VERTEX")
+ if (theType == "VERTEX" || theType == "VERTICES")
return VERTEX;
return SHAPE; // default
}
#include "Model_Application.h"
#include "Model_Events.h"
#include "Model_Data.h"
+#include "Model_Objects.h"
#include <GeomAPI_Pnt.h>
#include <GeomAPI_Shape.h>
#include <TDF_RelocationTable.hxx>
#include <TDF_DeltaOnAddition.hxx>
#include <TDataStd_UAttribute.hxx>
+#include <TDataStd_ReferenceList.hxx>
#include <TopAbs_ShapeEnum.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Shape.hxx>
/// topology" flag enabled
static const Standard_GUID kIS_GEOMETRICAL_SELECTION("f16987b6-e6c8-435c-99fa-03a7e0b06e83");
+/// GUID for TDataStd_ReferenceList attribute that refers the selection filters feature
+static const Standard_GUID kSELECTION_FILTERS_REF("ea5b1dbf-a740-4a0b-a1b2-3c3c756e691a");
+
+
void Model_AttributeSelectionList::append(
const ObjectPtr& theContext, const std::shared_ptr<GeomAPI_Shape>& theSubShape,
const bool theTemporarily)
myCash.clear(); // empty list as indicator that cash is not used
owner()->data()->sendAttributeUpdated(this);
}
+
+FiltersFeaturePtr Model_AttributeSelectionList::filters() const
+{
+ Handle(TDataStd_ReferenceList) aRef;
+ if (myLab.FindAttribute(kSELECTION_FILTERS_REF, aRef) && !aRef->IsEmpty()) {
+ if (owner().get()) {
+ std::shared_ptr<Model_Document> aDoc = std::dynamic_pointer_cast<Model_Document>(
+ owner()->document());
+ if (aDoc) {
+ const TDF_Label& aRefLab = aRef->First();
+ if (!aRefLab.IsNull()) { // it may happen with old document, issue #285
+ ObjectPtr anObj = aDoc->objects()->object(aRefLab);
+ FiltersFeaturePtr aFeat = std::dynamic_pointer_cast<ModelAPI_FiltersFeature>(anObj);
+ if (aFeat.get()) {
+ aFeat->setAttribute(owner()->data()->attribute(id()));
+ return aFeat;
+ }
+ }
+ }
+ }
+ }
+ return FiltersFeaturePtr(); // null pointer if nothing is defined
+}
+
+void Model_AttributeSelectionList::setFilters(FiltersFeaturePtr theFeature)
+{
+ Handle(TDataStd_ReferenceList) aRef = TDataStd_ReferenceList::Set(myLab, kSELECTION_FILTERS_REF);
+ if (theFeature.get()) {
+ std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(theFeature->data());
+ if (aData->isValid()) {
+ TDF_Label anObjLab = aData->label().Father(); // object label
+ if (!aRef->IsEmpty())
+ aRef->Clear();
+ aRef->Append(anObjLab);
+ theFeature->setAttribute(owner()->data()->attribute(id()));
+ return;
+ }
+ }
+ // remove attribute if something is wrong
+ myLab.ForgetAttribute(TDataStd_ReferenceList::GetID());
+}
/// Returns true if is geometrical selection.
MODEL_EXPORT virtual bool isGeometricalSelection() const override;
+ /// Returns a selection filters feature if it is defined for this selection list
+ MODEL_EXPORT virtual FiltersFeaturePtr filters() const;
+
+ /// Sets a selection filters feature if it is defined for this selection list
+ MODEL_EXPORT virtual void setFilters(FiltersFeaturePtr theFeature);
+
protected:
/// Objects are created for features automatically
MODEL_EXPORT Model_AttributeSelectionList(TDF_Label& theLabel);
friend class Model_AttributeRefList;
friend class Model_AttributeRefAttrList;
friend class Model_AttributeSelection;
+ friend class Model_AttributeSelectionList;
friend class Model_ResultPart;
friend class Model_ResultBody;
friend class Model_ResultConstruction;
#include "Model_Filter.h"
#include "ModelAPI_AttributeBoolean.h"
+#include "ModelAPI_AttributeSelectionList.h"
#include <Events_InfoMessage.h>
bool Model_FiltersFactory::isValid(FeaturePtr theFiltersFeature, GeomShapePtr theShape)
{
+ // check that the shape type corresponds to the attribute list type
+ AttributePtr aBase =
+ std::dynamic_pointer_cast<ModelAPI_FiltersFeature>(theFiltersFeature)->baseAttribute();
+ if (aBase.get()) {
+ std::shared_ptr<ModelAPI_AttributeSelectionList> aList =
+ std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(aBase);
+ std::string aStrType = aList->selectionType();
+ GeomAPI_Shape::ShapeType aType = GeomAPI_Shape::shapeTypeByStr(aStrType);
+ if (theShape->shapeType() != aType)
+ return false;
+ }
// prepare all filters args
ModelAPI_FiltersArgs anArgs;
std::list<FilterArgs> aFilters; /// all filters and the reverse values
/// To virtually destroy the fields of successors
MODELAPI_EXPORT virtual ~ModelAPI_AttributeSelectionList();
- MODELAPI_EXPORT FiltersFeaturePtr filters() const { return myFilters; }
- MODELAPI_EXPORT void setFilters(FiltersFeaturePtr theFeature) { myFilters = theFeature; }
+ /// Returns a selection filters feature if it is defined for this selection list
+ MODELAPI_EXPORT virtual FiltersFeaturePtr filters() const = 0;
+
+ /// Sets a selection filters feature if it is defined for this selection list
+ MODELAPI_EXPORT virtual void setFilters(FiltersFeaturePtr theFeature) = 0;
protected:
/// Objects are created for features automatically
MODELAPI_EXPORT ModelAPI_AttributeSelectionList();
-protected:
- FiltersFeaturePtr myFilters;
};
//! Pointer on double attribute
/// Returns the ordered list of attributes related to the filter.
virtual std::list<AttributePtr> filterArgs(const std::string theFilterID) const = 0;
+
+ /// Sets the attribute (not-persistent field) that contains this filters feature.
+ /// The filter feature may make synchronization by this method call.
+ virtual void setAttribute(const AttributePtr& theAttr) = 0;
+
+ /// Returns the attribute (not-persistent field) that contains this filters feature.
+ virtual const AttributePtr& baseAttribute() const = 0;
};
typedef std::shared_ptr<ModelAPI_FiltersFeature> FiltersFeaturePtr;
/// adds an attribute of the filter
std::shared_ptr<ModelAPI_Attribute> initAttribute(
const std::string& theID, const std::string theAttrType) {
- return myFeature->data()->addFloatingAttribute(theID, theAttrType, myCurrentFilter);
+ AttributePtr aR = myFeature->data()->addFloatingAttribute(theID, theAttrType, myCurrentFilter);
+ aR->setIsArgument(false); // to avoid parametric update
+ return aR;
}
};
GeomShapePtr aShape = aBody->shape();
std::list<GeomShapePtr> aSubShapes =
aShape->subShapes((GeomAPI_Shape::ShapeType)mySelectionType);
+ TopTools_MapOfShape alreadyThere;
std::list<GeomShapePtr>::const_iterator aShapesIt;
for (aShapesIt = aSubShapes.cbegin(); aShapesIt != aSubShapes.cend(); aShapesIt++) {
GeomShapePtr aShape = (*aShapesIt);
- SessionPtr aSession = ModelAPI_Session::get();
+ TopoDS_Shape aTShape = aShape->impl<TopoDS_Shape>();
+ if (!alreadyThere.Add(aTShape))
+ continue;
+ static SessionPtr aSession = ModelAPI_Session::get();
bool isValid = aSession->filters()->isValid(myFeature, aShape);
if (isValid) {
- TopoDS_Shape aTShape = aShape->impl<TopoDS_Shape>();
aBuilder.Add(aComp, aTShape);
ModuleBase_ViewerPrsPtr aValue(new ModuleBase_ViewerPrs(aObj, aShape));
myValues.append(aValue);