#include "PartSet_WidgetShapeSelector.h"
#include <ModelAPI_AttributeRefAttr.h>
+#include <ModelAPI_Session.h>
+#include <ModelAPI_Validator.h>
+#include <ModelAPI_RefAttrValidator.h>
+#include <ModelAPI_ResultValidator.h>
+
#include <PartSet_Tools.h>
#include <SketchPlugin_Feature.h>
if (aRefAttr) {
TopoDS_Shape aShape = myShape->impl<TopoDS_Shape>();
AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(mySelectedObject, aShape, mySketch);
+
// this is an alternative, whether the attribute should be set or object in the attribute
// the first check is the attribute because the object already exist
// the object is set only if there is no selected attribute
return ModuleBase_WidgetShapeSelector::storeValue();
}
+//********************************************************************
+bool PartSet_WidgetShapeSelector::isValid(ObjectPtr theObj, std::shared_ptr<GeomAPI_Shape> theShape)
+{
+ // the method is redefined to analize the selected shape in validators
+ 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 and shape as validator attribute
+ AttributePtr aPntAttr;
+ DataPtr aData = myFeature->data();
+ if (theShape.get() != NULL) {
+ AttributePtr aAttr = aData->attribute(attributeID());
+ AttributeRefAttrPtr aRefAttr =
+ std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aAttr);
+ if (aRefAttr) {
+ TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
+ aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theObj, aShape, mySketch);
+ }
+ }
+ // 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 (aPntAttr.get() != NULL)
+ {
+ if (!aAttrValidator->isValid(myFeature, *aArgs, aPntAttr)) {
+ return false;
+ }
+ }
+ else
+ {
+ if (!aAttrValidator->isValid(myFeature, *aArgs, theObj)) {
+ return false;
+ }
+ }
+ }
+ }
+ return true;
+}
+
//*********************************************
bool PartSet_WidgetConstraintShapeSelector::storeValue() const
{
}
return ModuleBase_WidgetShapeSelector::storeValue();
}
-
void setSketcher(CompositeFeaturePtr theSketch) { mySketch = theSketch; }
CompositeFeaturePtr sketch() const { return mySketch; }
+protected:
+ /// Check the selected with validators if installed
+ virtual bool isValid(ObjectPtr theObj, std::shared_ptr<GeomAPI_Shape> theShape);
+
private:
CompositeFeaturePtr mySketch;
};
bool SketchPlugin_DistanceAttrValidator::isValid(
const AttributePtr& theAttribute, const std::list<std::string>& theArguments ) const
{
- std::shared_ptr<ModelAPI_AttributeRefAttr> anAttr =
- std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
- if (anAttr) {
- const ObjectPtr& anObj = theAttribute->owner();
- const FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(anObj);
- return isValid(aFeature, theArguments, anAttr->object());
- }
- return true; // it may be not reference attribute, in this case, it is OK
+ // any point attribute is acceptable for the distance operation
+ return true;
+}
+
+bool SketchPlugin_DistanceAttrValidator::isValid(const FeaturePtr& theFeature,
+ const std::list<std::string>& theArguments,
+ const AttributePtr& theAttribute) const
+{
+ return isValid(theAttribute, theArguments);
}
bool SketchPlugin_DifferentObjectsValidator::isValid(const FeaturePtr& theFeature,
//! 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 { return true; };
+ const AttributePtr& theAttribute) const;
};
/**
tooltip="Select point, line end point, line, center of circle or arc."
shape_types="edge vertex">
<validator id="SketchPlugin_DifferentObjects"/>
+ <validator id="SketchPlugin_DistanceAttr" parameters="ConstraintEntityA"/>
<selection_filter id="MultiFilter" parameters="line,vertex"/>
</sketch_shape_selector>
#include <ModelAPI_Result.h>
#include <ModelAPI_Object.h>
+#include <SelectMgr_ListIteratorOfListOfFilter.hxx>
+
XGUI_SelectionMgr::XGUI_SelectionMgr(XGUI_Workshop* theParent)
: QObject(theParent),
myWorkshop(theParent)
}
}
+//**************************************************************
+#include <SelectMgr_ListIteratorOfListOfFilter.hxx>
+void XGUI_SelectionMgr::updateSelectedOwners(bool isUpdateViewer)
+{
+ Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
+ const SelectMgr_ListOfFilter& aFilters = aContext->Filters();
+
+ SelectMgr_IndexedMapOfOwner anOwnersToDeselect;
+
+ SelectMgr_ListIteratorOfListOfFilter anIt(aFilters);
+ for (; anIt.More(); anIt.Next()) {
+ Handle(SelectMgr_Filter) aFilter = anIt.Value();
+ for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) {
+ Handle(SelectMgr_EntityOwner) anOwner = aContext->SelectedOwner();
+ if (!aFilter->IsOk(anOwner))
+ anOwnersToDeselect.Add(aContext->SelectedOwner());
+ }
+ }
+
+ setSelectedOwners(anOwnersToDeselect, false);
+
+ if (isUpdateViewer)
+ aContext->UpdateCurrentViewer();
+}
+
//**************************************************************
void XGUI_SelectionMgr::onObjectBrowserSelection()
{
void setSelectedOwners(const SelectMgr_IndexedMapOfOwner& theSelectedOwners,
bool isUpdateViewer);
+ //! Check that the selected owners are valid for the current filters
+ /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
+ void updateSelectedOwners(bool isUpdateViewer);
+
signals:
//! Emited when selection in a one of viewers was changed
void selectionChanged();