From f9ee2f3b87f8757c29589fcfc14ed04ea499dc28 Mon Sep 17 00:00:00 2001 From: nds Date: Mon, 29 Dec 2014 13:10:01 +0300 Subject: [PATCH] It replaces two lists of features and attributes to a map of feature to a list of attributes. It fixes a multi-selection bug, in the new version it is possible to move a countour of four lines in another place, the countour figure is not changed. --- src/PartSet/PartSet_SketcherMgr.cpp | 115 +++++++++++++++++----------- src/PartSet/PartSet_SketcherMgr.h | 7 +- 2 files changed, 74 insertions(+), 48 deletions(-) diff --git a/src/PartSet/PartSet_SketcherMgr.cpp b/src/PartSet/PartSet_SketcherMgr.cpp index 6937e5181..7c4d9ffeb 100644 --- a/src/PartSet/PartSet_SketcherMgr.cpp +++ b/src/PartSet/PartSet_SketcherMgr.cpp @@ -48,10 +48,8 @@ #include - - /// Returns list of unique objects by sum of objects from List1 and List2 -QList getSumList(const QList& theList1, +/*QList getSumList(const QList& theList1, const QList& theList2) { QList aRes; @@ -64,6 +62,38 @@ QList getSumList(const QList& theLis aRes.append(aPrs); } return aRes; +}*/ + +void fillFeature2Attribute(const QList& theList, + QMap >& theFeature2AttributeMap, + const FeaturePtr theSketch) +{ + QList aRes; + + QList::const_iterator anIt = theList.begin(), + aLast = theList.end(); + for (; anIt != aLast; anIt++) + { + ModuleBase_ViewerPrs aPrs = *anIt; + FeaturePtr aFeature = ModelAPI_Feature::feature(aPrs.object()); + if (aFeature.get() == NULL) + continue; + + QList anAttributes; + if (theFeature2AttributeMap.contains(aFeature)) { + anAttributes = theFeature2AttributeMap[aFeature]; + } + AttributePtr anAttr; + TopoDS_Shape aShape = aPrs.shape(); + if (!aShape.IsNull()) { + if (aShape.ShapeType() == TopAbs_VERTEX) { + anAttr = PartSet_Tools::findAttributeBy2dPoint(aFeature, aShape, theSketch); + if (anAttr.get() != NULL && !anAttributes.contains(anAttr)) + anAttributes.push_back(anAttr); + } + } + theFeature2AttributeMap[aFeature] = anAttributes; + } } @@ -128,19 +158,18 @@ void PartSet_SketcherMgr::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseE ModuleBase_ISelection* aSelect = aWorkshop->selection(); QList aHighlighted = aSelect->getHighlighted(); QList aSelected = aSelect->getSelected(); - myEditingFeatures.clear(); - myEditingAttr.clear(); + myFeature2AttributeMap.clear(); bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier); - QList aSelObjects; - if (aHasShift) - aSelObjects = getSumList(aHighlighted, aSelected); + if (aHasShift) { + fillFeature2Attribute(aHighlighted, myFeature2AttributeMap, myCurrentSketch); + fillFeature2Attribute(aSelected, myFeature2AttributeMap, myCurrentSketch); + } else { - foreach (ModuleBase_ViewerPrs aPrs, aHighlighted) { - aSelObjects.append(aPrs); - } + fillFeature2Attribute(aHighlighted, myFeature2AttributeMap, myCurrentSketch); } - if ((aSelObjects.size() == 0)) { + + if (myFeature2AttributeMap.empty()) { if (isSketchOpe && (!isSketcher)) // commit previous operation if (!aOperation->commit()) @@ -148,25 +177,6 @@ void PartSet_SketcherMgr::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseE return; } - foreach(ModuleBase_ViewerPrs aPrs, aSelObjects) { - FeaturePtr aFeature = ModelAPI_Feature::feature(aPrs.object()); - if (aFeature) { - myEditingFeatures.append(aFeature); - AttributePtr aAttr; - TopoDS_Shape aShape = aPrs.shape(); - if (!aShape.IsNull()) { - if (aShape.ShapeType() == TopAbs_VERTEX) { - aAttr = PartSet_Tools::findAttributeBy2dPoint(aFeature, aShape, myCurrentSketch); - } - } - myEditingAttr.append(aAttr); - } - } - - // If nothing highlighted - return - if (myEditingFeatures.size() == 0) - return; - if (isSketcher) { myIsDragging = true; get2dPoint(theWnd, theEvent, myCurX, myCurY); @@ -206,8 +216,7 @@ void PartSet_SketcherMgr::onMouseReleased(ModuleBase_IViewWindow* theWnd, QMouse if (myDragDone) { aViewer->enableMultiselection(true); //aOp->commit(); - myEditingFeatures.clear(); - myEditingAttr.clear(); + myFeature2AttributeMap.clear(); // Reselect edited object aViewer->AISContext()->MoveTo(theEvent->x(), theEvent->y(), theWnd->v3dView()); @@ -245,9 +254,17 @@ void PartSet_SketcherMgr::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEve static Events_ID aMoveEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED); static Events_ID aUpdateEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED); - for (int i = 0; i < myEditingFeatures.size(); i++) { - AttributePtr aAttr = myEditingAttr.at(i); - FeaturePtr aFeature = myEditingFeatures.at(i); + FeatureToAttributesMap::const_iterator anIt = myFeature2AttributeMap.begin(), + aLast = myFeature2AttributeMap.end(); + for (; anIt != aLast; anIt++) { + FeaturePtr aFeature = anIt.key(); + AttributePtr anAttr; + + AttributeList anAttributes = anIt.value(); + if (!anAttributes.empty()) { + anAttr = anAttributes.first(); + } + // save the previous selection std::set aSelectedAttributes; std::set aSelectedResults; @@ -256,8 +273,8 @@ void PartSet_SketcherMgr::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEve // save the previous selection: end // Process selection by attribute - if (aAttr.get() != NULL) { - std::string aAttrId = aAttr->id(); + if (anAttr.get() != NULL) { + std::string aAttrId = anAttr->id(); DataPtr aData = aFeature->data(); if (aData.get() != NULL) { std::shared_ptr aPoint = @@ -279,17 +296,22 @@ void PartSet_SketcherMgr::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEve // TODO: the selection restore should be after the AIS presentation is rebuilt } } - Events_Loop::loop()->flush(aMoveEvent); - Events_Loop::loop()->flush(aUpdateEvent); + //Events_Loop::loop()->flush(aMoveEvent); + //Events_Loop::loop()->flush(aUpdateEvent); // restore the previous selection - SelectMgr_IndexedMapOfOwner anOwnersToSelect; - getSelectionOwners(aFeature, myCurrentSketch, aWorkshop, aSelectedAttributes, - aSelectedResults, anOwnersToSelect); - aConnector->workshop()->selector()->setSelectedOwners(anOwnersToSelect, false); + //TODO: after the last flush + //SelectMgr_IndexedMapOfOwner anOwnersToSelect; + //getSelectionOwners(aFeature, myCurrentSketch, aWorkshop, aSelectedAttributes, + // aSelectedResults, anOwnersToSelect); + //TODO: after the last flush + //aConnector->workshop()->selector()->setSelectedOwners(anOwnersToSelect, false); // restore the previous selection ModelAPI_EventCreator::get()->sendUpdated(aFeature, aMoveEvent, true); + Events_Loop::loop()->flush(aUpdateEvent); } + Events_Loop::loop()->flush(aMoveEvent); Events_Loop::loop()->flush(aUpdateEvent); + aDisplayer->enableUpdateViewer(isEnableUpdateViewer); aDisplayer->updateViewer(); myDragDone = true; @@ -395,14 +417,15 @@ void PartSet_SketcherMgr::launchEditing() XGUI_ModuleConnector* aConnector = dynamic_cast(myModule->workshop()); aConnector->activateSubShapesSelection(aModes); - if (myEditingFeatures.size() > 0) { - FeaturePtr aFeature = myEditingFeatures.first(); + if (!myFeature2AttributeMap.empty()) { + FeaturePtr aFeature = myFeature2AttributeMap.begin().key(); std::shared_ptr aSPFeature = std::dynamic_pointer_cast(aFeature); if (aSPFeature) { myModule->editFeature(aSPFeature); } } + } diff --git a/src/PartSet/PartSet_SketcherMgr.h b/src/PartSet/PartSet_SketcherMgr.h index 083e918b5..c2f55bf79 100644 --- a/src/PartSet/PartSet_SketcherMgr.h +++ b/src/PartSet/PartSet_SketcherMgr.h @@ -22,6 +22,7 @@ #include #include +#include class PartSet_Module; class ModuleBase_IViewWindow; @@ -114,8 +115,10 @@ private: double myCurX, myCurY; CompositeFeaturePtr myCurrentSketch; - QList myEditingFeatures; - QList myEditingAttr; + + typedef QList AttributeList; + typedef QMap FeatureToAttributesMap; + FeatureToAttributesMap myFeature2AttributeMap; /// a map of a feature to attributes Handle(ModuleBase_ShapeInPlaneFilter) myPlaneFilter; }; -- 2.39.2