From ad64e08f853397dc2e45c2fe953b7756f217ae18 Mon Sep 17 00:00:00 2001 From: nds Date: Fri, 26 Feb 2016 17:21:47 +0300 Subject: [PATCH] #1330 Multiply selection when Create fillet using Shift button --- .../ModuleBase_WidgetMultiSelector.cpp | 151 ++++++++++++++---- .../ModuleBase_WidgetMultiSelector.h | 23 ++- src/ModuleBase/ModuleBase_WidgetSelector.cpp | 2 - src/ModuleBase/ModuleBase_WidgetSelector.h | 3 - .../ModuleBase_WidgetShapeSelector.cpp | 7 - .../ModuleBase_WidgetShapeSelector.h | 3 - src/ModuleBase/ModuleBase_WidgetValidated.cpp | 5 +- src/SketchPlugin/SketchPlugin_Validators.cpp | 5 - 8 files changed, 148 insertions(+), 51 deletions(-) diff --git a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp index 9acca5255..2a999aeb2 100755 --- a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp @@ -271,26 +271,6 @@ void ModuleBase_WidgetMultiSelector::restoreAttributeValue(bool theValid) } } -//******************************************************************** -void ModuleBase_WidgetMultiSelector::clearAttribute() -{ - DataPtr aData = myFeature->data(); - AttributePtr anAttribute = aData->attribute(attributeID()); - std::string aType = anAttribute->attributeType(); - if (aType == ModelAPI_AttributeSelectionList::typeId()) { - AttributeSelectionListPtr aSelectionListAttr = aData->selectionList(attributeID()); - aSelectionListAttr->clear(); - } - else if (aType == ModelAPI_AttributeRefList::typeId()) { - AttributeRefListPtr aRefListAttr = aData->reflist(attributeID()); - aRefListAttr->clear(); - } - else if (aType == ModelAPI_AttributeRefAttrList::typeId()) { - AttributeRefAttrListPtr aRefAttrListAttr = aData->refattrlist(attributeID()); - aRefAttrListAttr->clear(); - } -} - //******************************************************************** void ModuleBase_WidgetMultiSelector::setObject(ObjectPtr theSelectedObject, GeomShapePtr theShape) @@ -301,20 +281,26 @@ void ModuleBase_WidgetMultiSelector::setObject(ObjectPtr theSelectedObject, if (aType == ModelAPI_AttributeSelectionList::typeId()) { AttributeSelectionListPtr aSelectionListAttr = aData->selectionList(attributeID()); ResultPtr aResult = std::dynamic_pointer_cast(theSelectedObject); - aSelectionListAttr->append(aResult, theShape, myIsInValidate); + //if (!aSelectionListAttr->isInList(aResult, theShape, myIsInValidate)) + aSelectionListAttr->append(aResult, theShape, myIsInValidate); } else if (aType == ModelAPI_AttributeRefList::typeId()) { AttributeRefListPtr aRefListAttr = aData->reflist(attributeID()); - aRefListAttr->append(theSelectedObject); + //if (!aRefListAttr->isInList(theSelectedObject)) + aRefListAttr->append(theSelectedObject); } else if (aType == ModelAPI_AttributeRefAttrList::typeId()) { AttributeRefAttrListPtr aRefAttrListAttr = aData->refattrlist(attributeID()); - AttributePtr anAttribute = myWorkshop->module()->findAttribute(theSelectedObject, theShape); - if (anAttribute.get()) - aRefAttrListAttr->append(anAttribute); - else - aRefAttrListAttr->append(theSelectedObject); + + if (anAttribute.get()) { + //if (!aRefAttrListAttr->isInList(anAttribute)) + aRefAttrListAttr->append(anAttribute); + } + else { + //if (!aRefAttrListAttr->isInList(theSelectedObject)) + aRefAttrListAttr->append(theSelectedObject); + } } } @@ -344,6 +330,10 @@ bool ModuleBase_WidgetMultiSelector::setSelection(QList& t // this emit is necessary to call store/restore method an restore type of selection //emit valuesChanged(); //} + + /// remove unused objects from the model attribute + removeUnusedAttributeObjects(theValues); + theValues.clear(); if (!aSkippedValues.empty()) theValues.append(aSkippedValues); @@ -681,3 +671,110 @@ void ModuleBase_WidgetMultiSelector::convertIndicesToViewerSelection(std::set& theValues) +{ + std::map > aGeomSelection = convertSelection(theValues); + + DataPtr aData = myFeature->data(); + AttributePtr anAttribute = aData->attribute(attributeID()); + std::string aType = anAttribute->attributeType(); + std::set aShapes; + std::set anIndicesToBeRemoved; + if (aType == ModelAPI_AttributeSelectionList::typeId()) { + // iteration through data model to find not selected elements to remove them + AttributeSelectionListPtr aSelectionListAttr = aData->selectionList(attributeID()); + for (int i = 0; i < aSelectionListAttr->size(); i++) { + AttributeSelectionPtr anAttr = aSelectionListAttr->value(i); + bool aFound = findInSelection(anAttr->context(), anAttr->value(), aGeomSelection); + if (!aFound) + anIndicesToBeRemoved.insert(i); + } + aSelectionListAttr->remove(anIndicesToBeRemoved); + } + else if (aType == ModelAPI_AttributeRefList::typeId()) { + AttributeRefListPtr aRefListAttr = aData->reflist(attributeID()); + for (int i = 0; i < aRefListAttr->size(); i++) { + ObjectPtr anObject = aRefListAttr->object(i); + if (anObject.get()) { + bool aFound = findInSelection(anObject, GeomShapePtr(), aGeomSelection); + if (!aFound) + anIndicesToBeRemoved.insert(i); + } + } + aRefListAttr->remove(anIndicesToBeRemoved); + } + else if (aType == ModelAPI_AttributeRefAttrList::typeId()) { + /*AttributeRefAttrListPtr aRefAttrListAttr = aData->refattrlist(attributeID()); + for (int i = 0; i < aRefAttrListAttr->size(); i++) { + bool aFound = false; + if (aRefAttrListAttr->isAttribute(i)) { + AttributePtr anAttribute = aRefAttrListAttr->attribute(i); + ObjectPtr anAttrObject = anAttribute->owner(); + if (aGeomSelection.find(anAttrObject) != aGeomSelection.end()) { + std::set aShapes = aGeomSelection[anAttrObject]; + std::set::const_iterator anIt = aShapes.begin(), aLast = aShapes.end(); + for (; anIt != aLast && !aFound; anIt++) { + GeomShapePtr aCShape = *anIt; + if (aCShape.get()) { + AttributePtr aCAttr = myWorkshop->module()->findAttribute(anAttrObject, aCShape); + aFound = aCAttr == anAttribute; + } + } + } + } + else { + aFound = findInSelection(aRefAttrListAttr->object(i), GeomShapePtr(), aGeomSelection); + } + if (!aFound) + anIndicesToBeRemoved.insert(i); + } + aRefAttrListAttr->remove(anIndicesToBeRemoved);*/ + } +} + +std::map > ModuleBase_WidgetMultiSelector::convertSelection + (QList& theValues) +{ + // convert prs list to objects map + std::map > aGeomSelection; + std::set aShapes; + QList::const_iterator anIt = theValues.begin(), aLast = theValues.end(); + ObjectPtr anObject; + GeomShapePtr aShape; + GeomShapePtr anEmptyShape(new GeomAPI_Shape()); + for (; anIt != aLast; anIt++) { + ModuleBase_ViewerPrs aPrs = *anIt; + getGeomSelection(aPrs, anObject, aShape); + aShapes.clear(); + if (aGeomSelection.find(anObject) != aGeomSelection.end()) // found + aShapes = aGeomSelection[anObject]; + // we need to know if there was an empty shape in selection for the object + if (!aShape.get()) + aShape = anEmptyShape; + if (aShape.get() && aShapes.find(aShape) == aShapes.end()) // not found + aShapes.insert(aShape); + aGeomSelection[anObject] = aShapes; + } + return aGeomSelection; +} + +bool ModuleBase_WidgetMultiSelector::findInSelection(const ObjectPtr& theObject, + const GeomShapePtr& theShape, + const std::map >& theGeomSelection) +{ + bool aFound = false; + GeomShapePtr anEmptyShape(new GeomAPI_Shape()); + GeomShapePtr aShape = theShape.get() ? theShape : anEmptyShape; + if (theGeomSelection.find(theObject) != theGeomSelection.end()) {// found + const std::set& aShapes = theGeomSelection.at(theObject); + std::set::const_iterator anIt = aShapes.begin(), aLast = aShapes.end(); + for (; anIt != aLast && !aFound; anIt++) { + GeomShapePtr aCShape = *anIt; + if (aCShape.get()) + aFound = aCShape->isEqual(aShape); + } + } + return aFound; +} diff --git a/src/ModuleBase/ModuleBase_WidgetMultiSelector.h b/src/ModuleBase/ModuleBase_WidgetMultiSelector.h index 7156e0517..bebe4123b 100755 --- a/src/ModuleBase/ModuleBase_WidgetMultiSelector.h +++ b/src/ModuleBase/ModuleBase_WidgetMultiSelector.h @@ -116,9 +116,6 @@ protected: /// parameters of the current attribute virtual void storeAttributeValue(); - /// Clear attribute - virtual void clearAttribute(); - /// Set the focus on the last item in the list virtual void updateFocus(); @@ -168,6 +165,26 @@ protected: /// \param theValues the result presentations, filled with object and shape of an attribute item void convertIndicesToViewerSelection(std::set theAttributeIds, QList& theValues) const; + + /// Iterates throgh the model attribute list and remove elements which do not present in the list + /// \param theValues the wrapped selection values + virtual void removeUnusedAttributeObjects(QList& theValues); + + /// Converts viewer presentation selection list to objects and shapes map + /// \param theValues the wrapped selection values + /// \return selection list + std::map > convertSelection + (QList& theValues); + + /// Returns true if the object and shape present in the container + /// \param theObject a model object, a set of shapes is searched by it + /// \param theShape a shape to be in the set of the object shapes + /// \param theGeomSelection a map built on selection + /// \return boolean result + static bool findInSelection(const ObjectPtr& theObject, + const GeomShapePtr& theShape, + const std::map >& theGeomSelection); + protected: /// List control QListWidget* myListControl; diff --git a/src/ModuleBase/ModuleBase_WidgetSelector.cpp b/src/ModuleBase/ModuleBase_WidgetSelector.cpp index 8aed922a3..53a7b5da8 100755 --- a/src/ModuleBase/ModuleBase_WidgetSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetSelector.cpp @@ -44,8 +44,6 @@ void ModuleBase_WidgetSelector::getGeomSelection(const ModuleBase_ViewerPrs& the //******************************************************************** void ModuleBase_WidgetSelector::onSelectionChanged() { - clearAttribute(); - QList aSelected = getFilteredSelected(); bool isDone = setSelection(aSelected, true/*false*/); diff --git a/src/ModuleBase/ModuleBase_WidgetSelector.h b/src/ModuleBase/ModuleBase_WidgetSelector.h index 58cb33062..e44a2dde3 100755 --- a/src/ModuleBase/ModuleBase_WidgetSelector.h +++ b/src/ModuleBase/ModuleBase_WidgetSelector.h @@ -63,9 +63,6 @@ Q_OBJECT void onSelectionChanged(); protected: - /// Set an empty value to attribute - virtual void clearAttribute() = 0; - /// Update focus after the attribute value change virtual void updateFocus() = 0; diff --git a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp index 13f071c21..b68e282b6 100644 --- a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp @@ -160,13 +160,6 @@ QList ModuleBase_WidgetShapeSelector::getAttributeSelectio return aSelected; } -//******************************************************************** -void ModuleBase_WidgetShapeSelector::clearAttribute() -{ - // In order to make reselection possible, set empty object and shape should be done - setObject(ObjectPtr(), std::shared_ptr(new GeomAPI_Shape())); -} - //******************************************************************** bool ModuleBase_WidgetShapeSelector::restoreValueCustom() { diff --git a/src/ModuleBase/ModuleBase_WidgetShapeSelector.h b/src/ModuleBase/ModuleBase_WidgetShapeSelector.h index 2c8a10363..bcc247b0f 100644 --- a/src/ModuleBase/ModuleBase_WidgetShapeSelector.h +++ b/src/ModuleBase/ModuleBase_WidgetShapeSelector.h @@ -94,9 +94,6 @@ Q_OBJECT /// Computes and updates name of selected object in the widget virtual void updateSelectionName(); - /// Clear attribute - virtual void clearAttribute(); - // Update focus after the attribute value change virtual void updateFocus(); diff --git a/src/ModuleBase/ModuleBase_WidgetValidated.cpp b/src/ModuleBase/ModuleBase_WidgetValidated.cpp index 89315cd4b..995c66717 100644 --- a/src/ModuleBase/ModuleBase_WidgetValidated.cpp +++ b/src/ModuleBase/ModuleBase_WidgetValidated.cpp @@ -37,8 +37,11 @@ ModuleBase_WidgetValidated::~ModuleBase_WidgetValidated() bool ModuleBase_WidgetValidated::setSelection(QList& theValues, const bool theToValidate) { - if (theValues.empty()) + if (theValues.empty()) { + // In order to make reselection possible, set empty object and shape should be done + setSelectionCustom(ModuleBase_ViewerPrs()); return false; + } // it removes the processed value from the parameters list ModuleBase_ViewerPrs aValue = theValues.takeFirst(); bool isDone = false; diff --git a/src/SketchPlugin/SketchPlugin_Validators.cpp b/src/SketchPlugin/SketchPlugin_Validators.cpp index e3a42ecf1..0da828c4c 100755 --- a/src/SketchPlugin/SketchPlugin_Validators.cpp +++ b/src/SketchPlugin/SketchPlugin_Validators.cpp @@ -461,11 +461,6 @@ bool SketchPlugin_FilletVertexValidator::isValid(const AttributePtr& theAttribut const std::list& theArguments, std::string& theError) const { - if(!theAttribute.get() || !theAttribute->isInitialized()) { - theError = "Error: List of points is not initialized."; - return false; - } - std::shared_ptr aFilletFeature = std::dynamic_pointer_cast(theAttribute->owner()); AttributeRefAttrListPtr aPointsRefList = std::dynamic_pointer_cast(theAttribute); if(aPointsRefList->size() == 0) { -- 2.39.2