Skip to content

Commit

Permalink
Attacher: for reachable modes, display what's to add
Browse files Browse the repository at this point in the history
For grayed out modes in list, show what's needed to get to the mode.
Like so:
"Normal to edge (add Vertex)"
  • Loading branch information
DeepSOIC authored and wwmayer committed May 7, 2016
1 parent e6911ad commit 2b057ef
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 11 deletions.
23 changes: 19 additions & 4 deletions src/Mod/Part/App/Attacher.cpp
Expand Up @@ -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;
Expand All @@ -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();


Expand Down Expand Up @@ -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
Expand Down
14 changes: 10 additions & 4 deletions src/Mod/Part/App/Attacher.h
Expand Up @@ -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,
Expand Down Expand Up @@ -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<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
Expand Down Expand Up @@ -317,8 +325,6 @@ class PartExport AttachEngine : public Base::BaseClass
*/
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:
Expand Down
20 changes: 17 additions & 3 deletions src/Mod/PartDesign/Gui/TaskDatumParameters.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 2b057ef

Please sign in to comment.