From 2b057ef19291549412fb2723a6581b1ca7de4e0d Mon Sep 17 00:00:00 2001 From: DeepSOIC Date: Tue, 3 May 2016 16:05:40 +0300 Subject: [PATCH] Attacher: for reachable modes, display what's to add For grayed out modes in list, show what's needed to get to the mode. Like so: "Normal to edge (add Vertex)" --- src/Mod/Part/App/Attacher.cpp | 23 +++++++++++++++---- src/Mod/Part/App/Attacher.h | 14 +++++++---- .../PartDesign/Gui/TaskDatumParameters.cpp | 20 +++++++++++++--- 3 files changed, 46 insertions(+), 11 deletions(-) diff --git a/src/Mod/Part/App/Attacher.cpp b/src/Mod/Part/App/Attacher.cpp index f4e8b314767b..a8a25983d263 100644 --- a/src/Mod/Part/App/Attacher.cpp +++ b/src/Mod/Part/App/Attacher.cpp @@ -248,7 +248,7 @@ Base::Placement AttachEngine::placementFactory(const gp_Dir &ZAxis, eMapMode AttachEngine::listMapModes(eSuggestResult& msg, std::vector* allApplicableModes, std::set* nextRefTypeHint, - std::set* reachableModes) const + std::map* reachableModes) const { //replace a pointer with a valid reference, to avoid checks for zero pointer everywhere std::vector buf; @@ -264,10 +264,10 @@ eMapMode AttachEngine::listMapModes(eSuggestResult& msg, std::set &hints = *nextRefTypeHint; hints.clear(); - std::set buf3; + std::map buf3; if (reachableModes == 0) reachableModes = &buf3; - std::set &mlist_reachable = *reachableModes; + std::map &mlist_reachable = *reachableModes; mlist_reachable.clear(); @@ -313,8 +313,23 @@ eMapMode AttachEngine::listMapModes(eSuggestResult& msg, } if (score > 0 && str.size() > typeStr.size()){ + //mode does not fit, but adding more references will make this mode fit. hints.insert(str[typeStr.size()]); - reachableModes->insert(eMapMode(iMode)); + + //build string of references to be added to fit this mode + refTypeString extraRefs; + extraRefs.resize(str.size() - typeStr.size()); + for (int iChr = typeStr.size() ; iChr < str.size() ; iChr++){ + extraRefs[iChr - typeStr.size()] = str[iChr]; + } + + //add reachable mode + auto it_r = mlist_reachable.find(eMapMode(iMode)); + if (it_r == mlist_reachable.end()){ + it_r = mlist_reachable.insert(std::pair(eMapMode(iMode),refTypeStringList())).first; + } + refTypeStringList &list = it_r->second; + list.push_back(extraRefs); } //size check is last, because we needed to collect hints diff --git a/src/Mod/Part/App/Attacher.h b/src/Mod/Part/App/Attacher.h index d69abfd964cc..356c0daabe1e 100644 --- a/src/Mod/Part/App/Attacher.h +++ b/src/Mod/Part/App/Attacher.h @@ -144,6 +144,10 @@ enum eRefType { class PartExport AttachEngine : public Base::BaseClass { TYPESYSTEM_HEADER(); +public: //typedefs + typedef std::vector refTypeString; //a sequence of ref types, according to Support contents for example + typedef std::vector refTypeStringList; //a set of type strings, defines which selection sets are supported by a certain mode + public: //methods AttachEngine(); virtual void setUp(const App::PropertyLinkSubList &references, @@ -217,12 +221,16 @@ class PartExport AttachEngine : public Base::BaseClass * * @param nextRefTypeHint (output). A hint of what can be added to references. * - * @param reachableModes (output). List of modes that can be reached by selecing more references. + * @param reachableModes (output). List of modes that can be reached by + * selecing more references. Is a map, where key is the mode that can be + * reached and value is a list of reference sequences that can be added to + * reach the mode (stuff already linked is omitted from these lists; only + * extra links needed are listed) */ virtual eMapMode listMapModes(eSuggestResult &msg, std::vector* allApplicableModes = 0, std::set* nextRefTypeHint = 0, - std::set *reachableModes = 0) const; + std::map *reachableModes = 0) const; /** * @brief getHint function returns a set of types that user can add to @@ -317,8 +325,6 @@ class PartExport AttachEngine : public Base::BaseClass */ std::vector modeEnabled; - typedef std::vector refTypeString; //a sequence of ref types, according to Support contents for example - typedef std::vector refTypeStringList; //a set of type strings, defines which selection sets are supported by a certain mode std::vector modeRefTypes; //a complete data structure, containing info on which modes support what selection protected: diff --git a/src/Mod/PartDesign/Gui/TaskDatumParameters.cpp b/src/Mod/PartDesign/Gui/TaskDatumParameters.cpp index 8fb79507dd05..e6b540ba67f8 100644 --- a/src/Mod/PartDesign/Gui/TaskDatumParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskDatumParameters.cpp @@ -675,15 +675,15 @@ void TaskDatumParameters::updateListOfModes(eMapMode curMode) //obtain list of available modes: Part::Datum* pcDatum = static_cast(DatumView->getObject()); eMapMode suggMode = mmDeactivated; - std::set reachableModes; + std::map reachableModes; int lastValidModeItemIndex = mmDummy_NumberOfModes; if (pcDatum->Support.getSize() > 0){ eSuggestResult msg; suggMode = pcDatum->attacher().listMapModes(msg, &modesInList, 0, &reachableModes); //add reachable modes to the list, too, but gray them out (using lastValidModeItemIndex, later) lastValidModeItemIndex = modesInList.size()-1; - for(eMapMode m: reachableModes){ - modesInList.push_back(m); + for(std::pair &rm: reachableModes){ + modesInList.push_back(rm.first); } } else { //no references - display all modes @@ -712,6 +712,20 @@ void TaskDatumParameters::updateListOfModes(eMapMode curMode) if (i > lastValidModeItemIndex){ //potential mode - can be reached by selecting more stuff item->setFlags(item->flags() & ~(Qt::ItemFlag::ItemIsEnabled | Qt::ItemFlag::ItemIsSelectable)); + + AttachEngine::refTypeStringList &extraRefs = reachableModes[mmode]; + if (extraRefs.size() == 1){ + QStringList buf; + for(eRefType rt : extraRefs[0]){ + buf.append(AttacherGui::getShapeTypeText(rt)); + } + item->setText(tr("%1 (add %2)").arg( + item->text(), + buf.join(QString::fromLatin1("+")) + )); + } else { + item->setText(tr("%1 (add more references)").arg(item->text())); + } } else if (mmode == suggMode){ //suggested mode - make bold assert (item);