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)"
This commit is contained in:
DeepSOIC 2016-05-03 16:05:40 +03:00 committed by wmayer
parent e6911adc50
commit 2b057ef192
3 changed files with 46 additions and 11 deletions

View File

@ -248,7 +248,7 @@ Base::Placement AttachEngine::placementFactory(const gp_Dir &ZAxis,
eMapMode AttachEngine::listMapModes(eSuggestResult& msg,
std::vector<eMapMode>* allApplicableModes,
std::set<eRefType>* nextRefTypeHint,
std::set<eMapMode>* reachableModes) const
std::map<eMapMode,refTypeStringList>* reachableModes) const
{
//replace a pointer with a valid reference, to avoid checks for zero pointer everywhere
std::vector<eMapMode> buf;
@ -264,10 +264,10 @@ eMapMode AttachEngine::listMapModes(eSuggestResult& msg,
std::set<eRefType> &hints = *nextRefTypeHint;
hints.clear();
std::set<eMapMode> buf3;
std::map<eMapMode,refTypeStringList> buf3;
if (reachableModes == 0)
reachableModes = &buf3;
std::set<eMapMode> &mlist_reachable = *reachableModes;
std::map<eMapMode,refTypeStringList> &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,refTypeStringList>(eMapMode(iMode),refTypeStringList())).first;
}
refTypeStringList &list = it_r->second;
list.push_back(extraRefs);
}
//size check is last, because we needed to collect hints

View File

@ -144,6 +144,10 @@ enum eRefType {
class PartExport AttachEngine : public Base::BaseClass
{
TYPESYSTEM_HEADER();
public: //typedefs
typedef std::vector<eRefType> refTypeString; //a sequence of ref types, according to Support contents for example
typedef std::vector<refTypeString> 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 @@ public: //methods
*
* @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<eMapMode>* allApplicableModes = 0,
std::set<eRefType>* nextRefTypeHint = 0,
std::set<eMapMode> *reachableModes = 0) const;
std::map<eMapMode, refTypeStringList> *reachableModes = 0) const;
/**
* @brief getHint function returns a set of types that user can add to
@ -317,8 +325,6 @@ public: //members
*/
std::vector<bool> modeEnabled;
typedef std::vector<eRefType> refTypeString; //a sequence of ref types, according to Support contents for example
typedef std::vector<refTypeString> refTypeStringList; //a set of type strings, defines which selection sets are supported by a certain mode
std::vector<refTypeStringList> modeRefTypes; //a complete data structure, containing info on which modes support what selection
protected:

View File

@ -675,15 +675,15 @@ void TaskDatumParameters::updateListOfModes(eMapMode curMode)
//obtain list of available modes:
Part::Datum* pcDatum = static_cast<Part::Datum*>(DatumView->getObject());
eMapMode suggMode = mmDeactivated;
std::set<eMapMode> reachableModes;
std::map<eMapMode, AttachEngine::refTypeStringList> 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<const eMapMode, AttachEngine::refTypeStringList> &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);