Attacher: change suggestion routine interface

When another bit of information was needed to be extracted from mode
suggestion routine, it felt like listMapModes had too many arguments.
So, the arguments have been collapsed into a struct. This triggered a
few namespace-related changes, which lead to massive search-and-replace
changes all over FreeCAD.

So the only functional change carried out is the addition of reference
types readout to info returned by suggestor.
This commit is contained in:
DeepSOIC
2016-05-04 17:03:18 +03:00
committed by wmayer
parent 22480effeb
commit 39249581eb
6 changed files with 123 additions and 117 deletions

View File

@@ -79,14 +79,14 @@ namespace SketcherGui {
};
Attacher::eMapMode SuggestAutoMapMode(Attacher::eSuggestResult* pMsgId = 0,
Attacher::eMapMode SuggestAutoMapMode(Attacher::SuggestResult::eSuggestResult* pMsgId = 0,
QString* message = 0,
std::vector<Attacher::eMapMode>* allmodes = 0){
//convert pointers into valid references, to avoid checking for null pointers everywhere
Attacher::eSuggestResult buf;
Attacher::SuggestResult::eSuggestResult buf;
if (pMsgId == 0)
pMsgId = &buf;
Attacher::eSuggestResult &msg = *pMsgId;
Attacher::SuggestResult::eSuggestResult &msg = *pMsgId;
QString buf2;
if (message == 0)
message = &buf2;
@@ -95,23 +95,26 @@ namespace SketcherGui {
App::PropertyLinkSubList tmpSupport;
Gui::Selection().getAsPropertyLinkSubList(tmpSupport);
Attacher::SuggestResult sugr;
AttachEngine3D eng;
eng.setUp(tmpSupport);
Attacher::eMapMode ret;
ret = eng.listMapModes(msg, allmodes);
eng.suggestMapModes(sugr);
if (allmodes)
*allmodes = sugr.allApplicableModes;
msg = sugr.message;
switch(msg){
case Attacher::srOK:
case Attacher::SuggestResult::srOK:
break;
case Attacher::srNoModesFit:
case Attacher::SuggestResult::srNoModesFit:
msg_str = QObject::tr("There are no modes that accept the selected set of subelements");
break;
case Attacher::srLinkBroken:
case Attacher::SuggestResult::srLinkBroken:
msg_str = QObject::tr("Broken link to support subelements");
break;
case Attacher::srUnexpectedError:
case Attacher::SuggestResult::srUnexpectedError:
msg_str = QObject::tr("Unexpected error");
break;
case Attacher::srIncompatibleGeometry:
case Attacher::SuggestResult::srIncompatibleGeometry:
if(tmpSupport.getSubValues()[0].substr(0,4) == std::string("Face"))
msg_str = QObject::tr("Face is non-planar");
else
@@ -122,7 +125,7 @@ namespace SketcherGui {
assert(0/*no message for eSuggestResult enum item*/);
}
return ret;
return sugr.bestFitMode;
}
} //namespace SketcherGui
@@ -147,13 +150,13 @@ void CmdSketcherNewSketch::activated(int iMsg)
Attacher::eMapMode mapmode = Attacher::mmDeactivated;
bool bAttach = false;
if (Gui::Selection().hasSelection()){
Attacher::eSuggestResult msgid = Attacher::srOK;
Attacher::SuggestResult::eSuggestResult msgid = Attacher::SuggestResult::srOK;
QString msg_str;
std::vector<Attacher::eMapMode> validModes;
mapmode = SuggestAutoMapMode(&msgid, &msg_str, &validModes);
if (msgid == Attacher::srOK)
if (msgid == Attacher::SuggestResult::srOK)
bAttach = true;
if (msgid != Attacher::srOK && msgid != Attacher::srNoModesFit){
if (msgid != Attacher::SuggestResult::srOK && msgid != Attacher::SuggestResult::srNoModesFit){
QMessageBox::warning(Gui::getMainWindow(),
QObject::tr("Sketch mapping"),
QObject::tr("Can't map the skecth to selected object. %1.").arg(msg_str));
@@ -166,7 +169,7 @@ void CmdSketcherNewSketch::activated(int iMsg)
items.push_back(QObject::tr("Don't attach"));
int iSugg = 0;//index of the auto-suggested mode in the list of valid modes
for (size_t i = 0 ; i < validModes.size() ; ++i){
items.push_back(QString::fromLatin1(AttachEngine::eMapModeStrings[validModes[i]]));
items.push_back(QString::fromLatin1(AttachEngine::getModeName(validModes[i]).c_str()));
if (validModes[i] == mapmode)
iSugg = items.size()-1;
}
@@ -447,7 +450,7 @@ void CmdSketcherMapSketch::activated(int iMsg)
std::vector<Attacher::eMapMode> validModes;
//check that selection is valid for at least some mapping mode.
Attacher::eSuggestResult msgid = Attacher::srOK;
Attacher::SuggestResult::eSuggestResult msgid = Attacher::SuggestResult::srOK;
suggMapMode = SuggestAutoMapMode(&msgid, &msg_str, &validModes);
App::Document* doc = App::GetApplication().getActiveDocument();