#include <ModelAPI_AttributeSelection.h>
#include "ModelAPI_Object.h"
-bool ModelAPI_ShapeValidator::isValid(const FeaturePtr& theFeature,
- const std::list<std::string>& theArguments,
- const ObjectPtr& theObject,
- const AttributePtr& theAttribute,
- const GeomShapePtr& theShape) const
+bool ModelAPI_ShapeValidator::isValid(const AttributePtr& theAttribute,
+ const std::list<std::string>& theArguments) const
{
+ FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
+ AttributeSelectionPtr aSelectionAttribute =
+ std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
+ GeomShapePtr aShape = aSelectionAttribute->value();
+
std::string aCurrentAttributeId = theAttribute->id();
// get all feature attributes
std::list<AttributePtr> anAttrs =
- theFeature->data()->attributes(ModelAPI_AttributeSelection::type());
- if (anAttrs.size() > 0 && theShape.get() != NULL) {
+ aFeature->data()->attributes(ModelAPI_AttributeSelection::type());
+ if (anAttrs.size() > 0 && aShape.get() != NULL) {
std::list<AttributePtr>::iterator anAttr = anAttrs.begin();
for(; anAttr != anAttrs.end(); anAttr++) {
AttributePtr anAttribute = *anAttr;
AttributeSelectionPtr aSelectionAttribute =
std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(anAttribute);
// the shape of the attribute should be not the same
- if (aSelectionAttribute.get() != NULL && theShape->isEqual(aSelectionAttribute->value())) {
+ if (aSelectionAttribute.get() != NULL && aShape->isEqual(aSelectionAttribute->value())) {
return false;
}
}
#include <ModelAPI.h>
-#include <ModelAPI_Validator.h>
-#include <ModelAPI_Feature.h>
+#include <ModelAPI_AttributeValidator.h>
#include <ModelAPI_Attribute.h>
-#include <GeomAPI_Shape.h>
-
/**
* Generic validator for any attribute of a feature.
*/
-class ModelAPI_ShapeValidator : public ModelAPI_Validator
+class ModelAPI_ShapeValidator : public ModelAPI_AttributeValidator
{
public:
/// returns True if the attribute is valid. It checks whether the feature of the attribute
/// does not contain a selection attribute filled with the same shape
- /// \param theFeature a feature to check
- /// \param theArguments a filter parameters
- /// \param theObject an object
/// \param theAttribute an attribute to check
- /// \param theShape a shape
- MODELAPI_EXPORT virtual bool isValid(const FeaturePtr& theFeature,
- const std::list<std::string>& theArguments,
- const ObjectPtr& theObject, const AttributePtr& theAttribute,
- const GeomShapePtr& theShape) const;
+ /// \param theArguments a filter parameters
+ MODELAPI_EXPORT virtual bool isValid(const AttributePtr& theAttribute,
+ const std::list<std::string>& theArguments) const;
};
#endif
ModuleBase_FilterNoConsructionSubShapes.h
ModuleBase_FilterNoDegeneratedEdge.h
ModuleBase_FilterShapeType.h
+ ModuleBase_FilterValidated.h
ModuleBase_Tools.h
ModuleBase_IModule.h
ModuleBase_Operation.h
ModuleBase_FilterNoConsructionSubShapes.cpp
ModuleBase_FilterNoDegeneratedEdge.cpp
ModuleBase_FilterShapeType.cpp
+ ModuleBase_FilterValidated.cpp
ModuleBase_Tools.cpp
ModuleBase_IModule.cpp
ModuleBase_IWorkshop.cpp
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: ModuleBase_FilterValidated.h
+// Created: 17 Mar 2015
+// Author: Natalia ERMOLAEVA
+
+
+#include "ModuleBase_FilterValidated.h"
+#include "ModuleBase_IWorkshop.h"
+
+#include <ModelAPI_Session.h>
+#include <ModelAPI_Document.h>
+#include <ModelAPI_ResultConstruction.h>
+
+#include <AIS_InteractiveObject.hxx>
+#include <AIS_Shape.hxx>
+
+#include <StdSelect_BRepOwner.hxx>
+
+#include <BRep_Tool.hxx>
+#include <TopoDS.hxx>
+#include <TopoDS_Edge.hxx>
+#include <Geom_Curve.hxx>
+
+#include <ModelAPI_CompositeFeature.h>
+#include <GeomAPI_ICustomPrs.h>
+
+
+IMPLEMENT_STANDARD_HANDLE(ModuleBase_FilterValidated, SelectMgr_Filter);
+IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_FilterValidated, SelectMgr_Filter);
+
+Standard_Boolean ModuleBase_FilterValidated::IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const
+{
+/* // global selection should be ignored, the filter processes only selected sub-shapes
+ Handle(StdSelect_BRepOwner) aShapeOwner = Handle(StdSelect_BRepOwner)::DownCast(theOwner);
+ if (!aShapeOwner.IsNull()) {
+ if (!aShapeOwner->ComesFromDecomposition())
+ return Standard_True;
+ }
+
+ if (theOwner->HasSelectable()) {
+ Handle(AIS_InteractiveObject) aAisObj =
+ Handle(AIS_InteractiveObject)::DownCast(theOwner->Selectable());
+ if (!aAisObj.IsNull()) {
+ std::shared_ptr<GeomAPI_AISObject> aAISObj = AISObjectPtr(new GeomAPI_AISObject());
+ aAISObj->setImpl(new Handle(AIS_InteractiveObject)(aAisObj));
+ ObjectPtr aObj = myWorkshop->findPresentedObject(aAISObj);
+
+ ResultConstructionPtr aConstr =
+ std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aObj);
+ if (aConstr != NULL) {
+ // it provides selection only on compositie features, construction without composite
+ // feature is not selectable
+ FeaturePtr aFeature = ModelAPI_Feature::feature(aConstr);
+ CompositeFeaturePtr aComposite =
+ std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aFeature);
+ return aComposite && aComposite->numberOfSubs() > 0;
+ }
+ }
+ }
+ */
+ return Standard_False;
+}
+
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: ModuleBase_FilterValidated.h
+// Created: 17 Mar 2015
+// Author: Natalia ERMOLAEVA
+
+
+#ifndef ModuleBase_FilterValidated_H
+#define ModuleBase_FilterValidated_H
+
+#include <SelectMgr_Filter.hxx>
+#include <SelectMgr_EntityOwner.hxx>
+
+class ModuleBase_IWorkshop;
+
+/**
+* \ingroup GUI
+* \class ModuleBase_FilterValidated
+* A filter which provides filtering of selection in 3d viewer.
+* Installing of this filter lets to select objects which belong to
+* currently active document or to global document
+*/
+DEFINE_STANDARD_HANDLE(ModuleBase_FilterValidated, SelectMgr_Filter);
+class ModuleBase_FilterValidated: public SelectMgr_Filter
+{
+public:
+ /// Constructor
+ /// \param theWorkshop instance of workshop interface
+ Standard_EXPORT ModuleBase_FilterValidated(ModuleBase_IWorkshop* theWorkshop):
+ SelectMgr_Filter(), myWorkshop(theWorkshop) {}
+
+ /**
+ * Returns true if the owner is computed from decomposition(it is global selection, not the sub-shapes)
+ * of if the selected result is a construction and the result feature is composite and has sub-elements.
+ * \param theOwner the result of selection
+ * \return whether the owner is selectable in the viewer
+ */
+ Standard_EXPORT virtual Standard_Boolean IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const;
+
+ DEFINE_STANDARD_RTTI(ModuleBase_FilterValidated)
+
+protected:
+ /// Instance of workshop interface
+ ModuleBase_IWorkshop* myWorkshop;
+};
+
+#endif
\ No newline at end of file
#include <ModelAPI_AttributeRefAttr.h>
#include <ModelAPI_Validator.h>
#include <ModelAPI_ResultValidator.h>
-#include <ModelAPI_RefAttrValidator.h>
+#include <ModelAPI_AttributeValidator.h>
#include <ModelAPI_ShapeValidator.h>
#include <Config_WidgetAPI.h>
aData->blockSendAttributeUpdated(true);
storeAttributeValues(theObj, theShape);
-// 3. check the acceptability of the current values
+ // 3. check the acceptability of the current values
std::list<ModelAPI_Validator*>::iterator aValidator = aValidators.begin();
std::list<std::list<std::string> >::iterator aArgs = anArguments.begin();
bool aValid = true;
for (; aValidator != aValidators.end() && aValid; aValidator++, aArgs++) {
- const ModelAPI_RefAttrValidator* aAttrValidator =
- dynamic_cast<const ModelAPI_RefAttrValidator*>(*aValidator);
+ const ModelAPI_AttributeValidator* aAttrValidator =
+ dynamic_cast<const ModelAPI_AttributeValidator*>(*aValidator);
if (aAttrValidator) {
aValid = aAttrValidator->isValid(anAttribute, *aArgs);
}
bool PartSet_WidgetConstraintShapeSelector::storeAttributeValues(ObjectPtr theSelectedObject, GeomShapePtr theShape) const
{
ObjectPtr aSelectedObject = theSelectedObject;
- GeomShapePtr aShape = theShape;
FeaturePtr aFeature = ModelAPI_Feature::feature(aSelectedObject);
if (aFeature) {
ObjectPtr aObj = PartSet_Tools::createFixedObjectByExternal(theShape->impl<TopoDS_Shape>(),
aSelectedObject, mySketch);
if (aObj) {
- PartSet_WidgetConstraintShapeSelector* that = (PartSet_WidgetConstraintShapeSelector*) this;
aSelectedObject = aObj;
} else
return false;
}
}
- return ModuleBase_WidgetShapeSelector::storeAttributeValues(theSelectedObject, theShape);
+ return ModuleBase_WidgetShapeSelector::storeAttributeValues(aSelectedObject, theShape);
}
#include <ModelAPI_AttributeRefAttr.h>
#include <ModelAPI_ResultValidator.h>
-bool SketchPlugin_ShapeValidator::isValid(const FeaturePtr& theFeature,
- const std::list<std::string>& theArguments,
- const ObjectPtr& theObject,
- const AttributePtr& theAttribute,
- const GeomShapePtr& theShape) const
+bool SketchPlugin_ShapeValidator::isValid(const AttributePtr& theAttribute,
+ const std::list<std::string>& theArguments) const
{
- ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
- std::shared_ptr<GeomAPI_Shape> aShape = ModelAPI_Tools::shape(aResult);
-
- // if the shapes are equal, that means that the given shape is a result.
- // if the result is selected, the
- if (aShape->isEqual(theShape))
+ if (theArguments.size() != 1)
return true;
- // found a non-external argument on the feature
- std::list<std::string>::const_iterator anIt = theArguments.begin(), aLast = theArguments.end();
- bool aHasNullParam = false;
- bool aHasNonExternalParams = false;
- for (; anIt != aLast; anIt++) {
- std::string aParamA = *anIt;
- std::shared_ptr<ModelAPI_AttributeRefAttr> anAttr = std::dynamic_pointer_cast<
- ModelAPI_AttributeRefAttr>(theFeature->data()->attribute(aParamA));
- if (anAttr) {
- FeaturePtr anOtherFeature = ModelAPI_Feature::feature(anAttr->object());
- if (anOtherFeature.get() != NULL) {
- std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
- std::dynamic_pointer_cast<SketchPlugin_Feature>(anOtherFeature);
- if (aSketchFeature) {
- aHasNonExternalParams = !aSketchFeature->isExternal();
- }
+ // ask whether the feature of the attribute is external
+ //std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
+ //AttributeRefAttrPtr anAttribute = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
+ // std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
+ bool isAttributeExternal = isExternalAttribute(theAttribute);
+
+ // ask whether the feature of the attribute by parameter identifier is external
+ std::string aFrontArgument = theArguments.front();
+ FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
+ bool isParameterExternal = isExternalAttribute(aFeature->attribute(aFrontArgument));
+
+ // it is not possible that both features, attribute and attribute in parameter, are external
+ if (isAttributeExternal && isParameterExternal)
+ return false;
+ return true;
+}
+
+bool SketchPlugin_ShapeValidator::isExternalAttribute(const AttributePtr& theAttribute) const
+{
+ bool isExternal = false;
+ AttributeRefAttrPtr anAttribute = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
+
+ if (anAttribute.get() != NULL) {
+ FeaturePtr anArgumentFeature = ModelAPI_Feature::feature(anAttribute->object());
+ if (anArgumentFeature.get() != NULL) {
+ std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
+ std::dynamic_pointer_cast<SketchPlugin_Feature>(anArgumentFeature);
+ if (aSketchFeature.get() != NULL) {
+ isExternal = aSketchFeature->isExternal();
}
- else
- aHasNullParam = true;
}
}
- if (aHasNullParam || aHasNonExternalParams)
- return true;
- return false;
+ return isExternal;
}
#define SketchPlugin_ShapeValidator_H
#include <SketchPlugin.h>
-#include <ModelAPI_ShapeValidator.h>
-#include <ModelAPI_Object.h>
+#include <ModelAPI_AttributeValidator.h>
/**\class SketchPlugin_ResultPointValidator
* \ingroup Validators
*
* Allows to select points only.
*/
-class SketchPlugin_ShapeValidator : public ModelAPI_ShapeValidator
+class SketchPlugin_ShapeValidator : public ModelAPI_AttributeValidator
{
public:
- // returns true if there is an empty or non-external shape on the feature.
- // in the given shape or in the list of attribute shapes
- /// \param theFeature a feature to check
+ /// returns true if the feature of attribute do not contain external features in the given attribute and
+ /// among attributes listed in the arguments
+ /// \param theAttribute an attribute to check
/// \param theArguments a filter parameters
- /// \param theObject an object
+ SKETCHPLUGIN_EXPORT virtual bool isValid(const AttributePtr& theAttribute,
+ const std::list<std::string>& theArguments) const;
+
+protected:
+ /// returns true if the feature of the attribute is external
/// \param theAttribute an attribute to check
- /// \param theShape a shape
- SKETCHPLUGIN_EXPORT virtual bool isValid(const FeaturePtr& theFeature,
- const std::list<std::string>& theArguments,
- const ObjectPtr& theObject, const AttributePtr& theAttribute,
- const GeomShapePtr& theShape) const;
+ bool isExternalAttribute(const AttributePtr& theAttribute) const;
};
#endif
#include <ModuleBase_Definitions.h>
#include <ModuleBase_ViewerPrs.h>
+#include <ModuleBase_FilterValidated.h>
#include <GeomAPI_ICustomPrs.h>
/// A container for selection filters
Handle(SelectMgr_AndFilter) myAndFilter;
+ Handle(ModuleBase_FilterValidated) myFilterValidated;
+
/// A default custom presentation, which is used if the displayed feature is not a custom presentation
GeomCustomPrsPtr myCustomPrs;