//********************************************************************
bool ModuleBase_WidgetMultiSelector::storeValueCustom() const
{
- // A rare case when plugin was not loaded.
- if(!myFeature)
- return false;
- DataPtr aData = myFeature->data();
- AttributeSelectionListPtr aSelectionListAttr =
- std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(aData->attribute(attributeID()));
-
- if (aSelectionListAttr) {
- aSelectionListAttr->clear();
- // Store shapes type
- TopAbs_ShapeEnum aCurrentType =
- ModuleBase_WidgetShapeSelector::shapeType(myTypeCombo->currentText());
- aSelectionListAttr->setSelectionType(myTypeCombo->currentText().toStdString());
- // Store selection in the attribute
- foreach (GeomSelection aSelec, mySelection) {
- aSelectionListAttr->append(aSelec.first, aSelec.second);
- }
- //updateSelectionList(aSelectionListAttr);
- updateObject(myFeature);
- return true;
- }
- return false;
+ // the value is stored on the selection changed signal processing
+ return true;
}
//********************************************************************
std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(aData->attribute(attributeID()));
if (aSelectionListAttr) {
- mySelection.clear();
// Restore shape type
setCurrentShapeType(
ModuleBase_WidgetShapeSelector::shapeType(aSelectionListAttr->selectionType().c_str()));
- // Restore selection in the list
- for (int i = 0; i < aSelectionListAttr->size(); i++) {
- AttributeSelectionPtr aSelectAttr = aSelectionListAttr->value(i);
- mySelection.append(GeomSelection(aSelectAttr->context(), aSelectAttr->value()));
- }
updateSelectionList(aSelectionListAttr);
return true;
}
//********************************************************************
void ModuleBase_WidgetMultiSelector::backupAttributeValue(const bool isBackup)
{
+ DataPtr aData = myFeature->data();
+ AttributeSelectionListPtr aSelectionListAttr =
+ std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(aData->attribute(attributeID()));
+ if (aSelectionListAttr.get() == NULL)
+ return;
+
+ if (isBackup) {
+ mySelectionType = aSelectionListAttr->selectionType();
+ mySelection.clear();
+ for (int i = 0; i < aSelectionListAttr->size(); i++) {
+ AttributeSelectionPtr aSelectAttr = aSelectionListAttr->value(i);
+ mySelection.append(GeomSelection(aSelectAttr->context(), aSelectAttr->value()));
+ }
+ }
+ else {
+ aSelectionListAttr->clear();
+ // Store shapes type
+ aSelectionListAttr->setSelectionType(mySelectionType);
+ // Store selection in the attribute
+ foreach (GeomSelection aSelec, mySelection) {
+ aSelectionListAttr->append(aSelec.first, aSelec.second);
+ }
+ }
}
//********************************************************************
bool ModuleBase_WidgetMultiSelector::setSelection(const Handle_SelectMgr_EntityOwner& theOwner)
{
- return false;
+ ModuleBase_ViewerPrs aPrs;
+ ModuleBase_ISelection* aSelection = myWorkshop->selection();
+ aSelection->fillPresentation(aPrs, theOwner);
+
+ const TopoDS_Shape& aTDSShape = aPrs.shape();
+ if (aTDSShape.IsNull())
+ return false;
+ GeomShapePtr aShape = std::shared_ptr<GeomAPI_Shape>(new GeomAPI_Shape());
+ aShape->setImpl(new TopoDS_Shape(aTDSShape));
+
+ ObjectPtr anObject = aSelection->getSelectableObject(theOwner);
+ ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
+ if (myFeature) {
+ // We can not select a result of our feature
+ const std::list<ResultPtr>& aResList = myFeature->results();
+ std::list<ResultPtr>::const_iterator aIt;
+ bool isSkipSelf = false;
+ for (aIt = aResList.cbegin(); aIt != aResList.cend(); ++aIt) {
+ if ((*aIt) == aResult) {
+ isSkipSelf = true;
+ break;
+ }
+ }
+ if(isSkipSelf)
+ return false;
+ }
+
+ // if the result has the similar shap as the parameter shape, just the context is set to the
+ // selection list attribute.
+ DataPtr aData = myFeature->data();
+ AttributeSelectionListPtr aSelectionListAttr =
+ std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(aData->attribute(attributeID()));
+ if (aShape->isEqual(aResult->shape()))
+ aSelectionListAttr->append(aResult, NULL);
+ else
+ aSelectionListAttr->append(aResult, aShape);
+
+ return true;
}
//********************************************************************
//********************************************************************
void ModuleBase_WidgetMultiSelector::onSelectionChanged()
{
- ModuleBase_ISelection* aSelection = myWorkshop->selection();
- NCollection_List<TopoDS_Shape> aSelectedShapes;
- std::list<ObjectPtr> aOwnersList;
- aSelection->selectedShapes(aSelectedShapes, aOwnersList);
-
- mySelection.clear();
- std::list<ObjectPtr>::const_iterator aIt;
- NCollection_List<TopoDS_Shape>::Iterator aShpIt(aSelectedShapes);
- GeomShapePtr aShape;
- for (aIt = aOwnersList.cbegin(); aIt != aOwnersList.cend(); aShpIt.Next(), aIt++) {
- ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(*aIt);
- if (myFeature) {
- // We can not select a result of our feature
- const std::list<ResultPtr>& aResList = myFeature->results();
- std::list<ResultPtr>::const_iterator aIt;
- bool isSkipSelf = false;
- for (aIt = aResList.cbegin(); aIt != aResList.cend(); ++aIt) {
- if ((*aIt) == aResult) {
- isSkipSelf = true;
- break;
- }
+ QList<ModuleBase_ViewerPrs> aSelected = myWorkshop->selection()->getSelected();
+
+ DataPtr aData = myFeature->data();
+ AttributeSelectionListPtr aSelectionListAttr =
+ std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(aData->attribute(attributeID()));
+
+ aSelectionListAttr->clear();
+ if (aSelected.size() > 0) {
+ foreach (ModuleBase_ViewerPrs aPrs, aSelected) {
+ Handle(SelectMgr_EntityOwner) anOwner = aPrs.owner();
+ if (isValid(anOwner)) {
+ setSelection(anOwner);
}
- if(isSkipSelf)
- continue;
}
- aShape = std::shared_ptr<GeomAPI_Shape>(new GeomAPI_Shape());
- aShape->setImpl(new TopoDS_Shape(aShpIt.Value()));
-
- // if the result has the similar shap as the parameter shape, just the context is set to the
- // selection list attribute.
- if (aShape->isEqual(aResult->shape()))
- mySelection.append(GeomSelection(aResult, NULL));
- else
- mySelection.append(GeomSelection(aResult, aShape));
}
- //updateSelectionList();
+ // the updateObject method should be called to flush the updated sigal. The workshop listens it,
+ // calls validators for the feature and, as a result, updates the Apply button state.
+ updateObject(myFeature);
+
emit valuesChanged();
}
aFactory->registerValidator("ModuleBase_ValidatorNoConstructionSubShapes",
new ModuleBase_ValidatorNoConstructionSubShapes);
+
+ aFactory->registerValidator("PartSet_SketchEntityValidator",
+ new PartSet_SketchEntityValidator);
}
void PartSet_Module::registerFilters()
XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
ModuleBase_FilterFactory* aFactory = aConnector->selectionFilters();
- aFactory->registerFilter("EdgeFilter", new ModuleBase_FilterLinearEdge);
- aFactory->registerFilter("FaceFilter", new ModuleBase_FilterFace);
- aFactory->registerFilter("MultiFilter", new ModuleBase_FilterMulti);
- Handle(SelectMgr_Filter) aSelectFilter = new ModuleBase_FilterNoConsructionSubShapes(workshop());
- aFactory->registerFilter("NoConstructionSubShapesFilter",
- new ModuleBase_FilterCustom(aSelectFilter));
- aSelectFilter = new PartSet_FilterSketchEntity(workshop());
- aFactory->registerFilter("SketchEntityFilter", new ModuleBase_FilterCustom(aSelectFilter));
+ //aFactory->registerFilter("EdgeFilter", new ModuleBase_FilterLinearEdge);
+ //aFactory->registerFilter("FaceFilter", new ModuleBase_FilterFace);
+ //aFactory->registerFilter("MultiFilter", new ModuleBase_FilterMulti);
+ //Handle(SelectMgr_Filter) aSelectFilter = new ModuleBase_FilterNoConsructionSubShapes(workshop());
+ //aFactory->registerFilter("NoConstructionSubShapesFilter",
+ // new ModuleBase_FilterCustom(aSelectFilter));
+ //Handle(SelectMgr_Filter) aSelectFilter = new PartSet_FilterSketchEntity(workshop());
+ //aFactory->registerFilter("SketchEntityFilter", new ModuleBase_FilterCustom(aSelectFilter));
}
void PartSet_Module::registerProperties()
#include <ModelAPI_AttributeRefAttr.h>
#include <ModelAPI_AttributeSelection.h>
#include <ModelAPI_AttributeReference.h>
+#include <ModelAPI_AttributeSelectionList.h>
#include <ModelAPI_Object.h>
#include <SketchPlugin_Sketch.h>
return true;
}
+bool PartSet_SketchEntityValidator::isValid(const AttributePtr& theAttribute,
+ const std::list<std::string>& theArguments) const
+{
+ AttributeSelectionListPtr aSelectionListAttr =
+ std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
+
+ // it filters only selection list attributes
+ if (aSelectionListAttr.get() == NULL)
+ return true;
+
+ std::string aType = aSelectionListAttr->selectionType().c_str();
+
+ // all context objects should be sketch entities
+ bool isSketchEntities = true;
+ int aSize = aSelectionListAttr->size();
+ for (int i = 0; i < aSelectionListAttr->size(); i++) {
+ AttributeSelectionPtr aSelectAttr = aSelectionListAttr->value(i);
+ ObjectPtr anObject = aSelectAttr->context();
+ FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
+ isSketchEntities = aFeature->getKind() == SketchPlugin_Sketch::ID();
+ }
+ return isSketchEntities;
+}
+
bool PartSet_SketchValidator::isValid(const ObjectPtr theObject) const
{
FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);