use_subshapes="true"
/>
<shape_selector id="placement_attractable_face"
- label="Select a face"
- icon=":icons/cut_shape.png"
- tooltip="Select a face of another object"
- shape_types="face"
- use_subshapes="true"
- concealment="true"
- />
+ label="Select a face"
+ icon=":icons/cut_shape.png"
+ tooltip="Select a face of another object"
+ shape_types="face"
+ use_subshapes="true"
+ concealment="true" >
+ <validator id="PartSet_DifferentObjects"/>
+ </shape_selector>
</source>
#include <ModelAPI_Tools.h>
#include <ModelAPI_ResultBody.h>
#include <ModelAPI_AttributeRefAttr.h>
+#include <ModelAPI_Validator.h>
+#include <ModelAPI_ResultValidator.h>
+#include <ModelAPI_RefAttrValidator.h>
#include <Config_WidgetAPI.h>
#include <Events_Error.h>
return false;
}
+//********************************************************************
+void ModuleBase_WidgetShapeSelector::clearAttribute()
+{
+ DataPtr aData = myFeature->data();
+ AttributeSelectionPtr aSelect = aData->selection(attributeID());
+ if (aSelect) {
+ aSelect->setValue(ResultPtr(), std::shared_ptr<GeomAPI_Shape>(new GeomAPI_Shape()));
+ return;
+ }
+ AttributeRefAttrPtr aRefAttr = aData->refattr(attributeID());
+ if (aRefAttr) {
+ aRefAttr->setObject(ObjectPtr());
+ return;
+ }
+ AttributeReferencePtr aRef = aData->reference(attributeID());
+ if (aRef) {
+ aRef->setObject(ObjectPtr());
+ }
+}
+
//********************************************************************
bool ModuleBase_WidgetShapeSelector::restoreValue()
{
//********************************************************************
void ModuleBase_WidgetShapeSelector::onSelectionChanged()
{
+ // In order to make reselection possible
+ // TODO: check with MPV clearAttribute();
+
QObjectPtrList aObjects = myWorkshop->selection()->selectedPresentations();
if (aObjects.size() > 0) {
ObjectPtr aObject = aObjects.first();
if (!acceptObjectShape(aObject))
return;
}
- setObject(aObject, aShape);
- emit focusOutWidget(this);
+ if (isValid(aObject, aShape)) {
+ setObject(aObject, aShape);
+ emit focusOutWidget(this);
+ }
}
}
{
activateSelection(false);
}
+
+//********************************************************************
+bool ModuleBase_WidgetShapeSelector::isValid(ObjectPtr theObj, std::shared_ptr<GeomAPI_Shape> theShape)
+{
+ SessionPtr aMgr = ModelAPI_Session::get();
+ ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
+ std::list<ModelAPI_Validator*> aValidators;
+ std::list<std::list<std::string> > anArguments;
+ aFactory->validators(parentID(), attributeID(), aValidators, anArguments);
+
+ // Check the type of selected object
+ std::list<ModelAPI_Validator*>::iterator aValidator = aValidators.begin();
+ bool isValid = true;
+ for (; aValidator != aValidators.end(); aValidator++) {
+ const ModelAPI_ResultValidator* aResValidator =
+ dynamic_cast<const ModelAPI_ResultValidator*>(*aValidator);
+ if (aResValidator) {
+ isValid = false;
+ if (aResValidator->isValid(theObj)) {
+ isValid = true;
+ break;
+ }
+ }
+ }
+ if (!isValid)
+ return false;
+
+ // Check the acceptability of the object as attribute
+ aValidator = aValidators.begin();
+ std::list<std::list<std::string> >::iterator aArgs = anArguments.begin();
+ for (; aValidator != aValidators.end(); aValidator++, aArgs++) {
+ const ModelAPI_RefAttrValidator* aAttrValidator =
+ dynamic_cast<const ModelAPI_RefAttrValidator*>(*aValidator);
+ if (aAttrValidator) {
+ if (!aAttrValidator->isValid(myFeature, *aArgs, theObj)) {
+ return false;
+ }
+ }
+ }
+ return true;
+}
\ No newline at end of file
// Set the given object as a value of the widget
void setObject(ObjectPtr theObj, std::shared_ptr<GeomAPI_Shape> theShape = std::shared_ptr<GeomAPI_Shape>());
+ /// Check the selected with validators if installed
+ virtual bool isValid(ObjectPtr theObj, std::shared_ptr<GeomAPI_Shape> theShape);
+
+ /// Clear attribute
+ void clearAttribute();
+
//----------- Class members -------------
protected:
QWidget* myContainer;
aFactory->registerValidator("PartSet_PerpendicularValidator", new PartSet_PerpendicularValidator);
aFactory->registerValidator("PartSet_ParallelValidator", new PartSet_ParallelValidator);
aFactory->registerValidator("PartSet_RadiusValidator", new PartSet_RadiusValidator);
+ aFactory->registerValidator("PartSet_DifferentObjects", new PartSet_DifferentObjectsValidator);
}
#include <GeomAbs_CurveType.hxx>
#include <ModuleBase_ISelection.h>
+#include <ModelAPI_AttributeRefAttr.h>
+#include <ModelAPI_AttributeSelection.h>
+
#include <list>
int shapesNbPoints(const ModuleBase_ISelection* theSelection)
return (aCount > 0) && (aCount < 2);
}
+
+
+bool PartSet_DifferentObjectsValidator::isValid(const FeaturePtr& theFeature,
+ const std::list<std::string>& theArguments,
+ const ObjectPtr& theObject) const
+{
+ // Check RefAttr attributes
+ std::list<std::shared_ptr<ModelAPI_Attribute> > anAttrs =
+ theFeature->data()->attributes(ModelAPI_AttributeRefAttr::type());
+ if (anAttrs.size() > 0) {
+ std::list<std::shared_ptr<ModelAPI_Attribute> >::iterator anAttr = anAttrs.begin();
+ for(; anAttr != anAttrs.end(); anAttr++) {
+ if (*anAttr) {
+ std::shared_ptr<ModelAPI_AttributeRefAttr> aRef =
+ std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anAttr);
+ // check the object is already presented
+ if (aRef->isObject() && aRef->object() == theObject)
+ return false;
+ }
+ }
+ }
+ // Check selection attributes
+ anAttrs = theFeature->data()->attributes(ModelAPI_AttributeSelection::type());
+ if (anAttrs.size() > 0) {
+ std::list<std::shared_ptr<ModelAPI_Attribute> >::iterator anAttr = anAttrs.begin();
+ for(; anAttr != anAttrs.end(); anAttr++) {
+ if (*anAttr) {
+ std::shared_ptr<ModelAPI_AttributeSelection> aRef =
+ std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(*anAttr);
+ // check the object is already presented
+ if (aRef->isInitialized() && aRef->context() == theObject)
+ return false;
+ }
+ }
+ }
+ return true;
+}
+
+bool PartSet_DifferentObjectsValidator::isValid(const FeaturePtr& theFeature,
+ const std::list<std::string>& theArguments,
+ const AttributePtr& theAttribute) const
+{
+ // not implemented
+ return true;
+}
+
+bool PartSet_DifferentObjectsValidator::isValid(const AttributePtr& theAttribute,
+ const std::list<std::string>& theArguments) const
+{
+ // not implemented
+ return true;
+}
\ No newline at end of file
#include <ModuleBase_SelectionValidator.h>
#include <ModuleBase_ISelection.h>
+#include <ModelAPI_RefAttrValidator.h>
/*
* Selector validators
PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection) const;
};
+class PartSet_DifferentObjectsValidator : public ModelAPI_RefAttrValidator
+{
+ public:
+ virtual bool isValid(const FeaturePtr& theFeature, const std::list<std::string>& theArguments,
+ const ObjectPtr& theObject) const;
+ //! Returns true if the attribute is good for the feature attribute
+ virtual bool isValid(const FeaturePtr& theFeature, const std::list<std::string>& theArguments,
+ const AttributePtr& theAttribute) const;
+
+ virtual bool isValid(const AttributePtr& theAttribute,
+ const std::list<std::string>& theArguments) const;
+};
+
+
#endif