Attacher: use getModeName() instead of eMapModeStrings[]

getModeName() does range checking. eMapModeStrings[] will crash if out
of range.
This commit is contained in:
DeepSOIC 2016-05-04 17:05:57 +03:00 committed by wmayer
parent 505ec6a26d
commit f947101938
4 changed files with 11 additions and 11 deletions

View File

@ -423,7 +423,7 @@ void CmdPartDesignNewSketch::activated(int iMsg)
openCommand("Create a Sketch on Face"); openCommand("Create a Sketch on Face");
doCommand(Doc,"App.activeDocument().addObject('Sketcher::SketchObject','%s')",FeatName.c_str()); doCommand(Doc,"App.activeDocument().addObject('Sketcher::SketchObject','%s')",FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.Support = %s",FeatName.c_str(),supportString.c_str()); doCommand(Doc,"App.activeDocument().%s.Support = %s",FeatName.c_str(),supportString.c_str());
doCommand(Doc,"App.activeDocument().%s.MapMode = '%s'",FeatName.c_str(),Attacher::AttachEngine::eMapModeStrings[Attacher::mmFlatFace]); doCommand(Doc,"App.activeDocument().%s.MapMode = '%s'",FeatName.c_str(),Attacher::AttachEngine::getModeName(Attacher::mmFlatFace).c_str());
doCommand(Doc,"App.activeDocument().%s.addFeature(App.activeDocument().%s)", doCommand(Doc,"App.activeDocument().%s.addFeature(App.activeDocument().%s)",
pcActiveBody->getNameInDocument(), FeatName.c_str()); pcActiveBody->getNameInDocument(), FeatName.c_str());
doCommand(Gui,"App.activeDocument().recompute()"); // recompute the sketch placement based on its support doCommand(Gui,"App.activeDocument().recompute()"); // recompute the sketch placement based on its support
@ -511,7 +511,7 @@ void CmdPartDesignNewSketch::activated(int iMsg)
Gui::Command::openCommand("Create a new Sketch"); Gui::Command::openCommand("Create a new Sketch");
Gui::Command::doCommand(Doc,"App.activeDocument().addObject('Sketcher::SketchObject','%s')",FeatName.c_str()); Gui::Command::doCommand(Doc,"App.activeDocument().addObject('Sketcher::SketchObject','%s')",FeatName.c_str());
Gui::Command::doCommand(Doc,"App.activeDocument().%s.Support = %s",FeatName.c_str(),supportString.c_str()); Gui::Command::doCommand(Doc,"App.activeDocument().%s.Support = %s",FeatName.c_str(),supportString.c_str());
Gui::Command::doCommand(Doc,"App.activeDocument().%s.MapMode = '%s'",FeatName.c_str(),Attacher::AttachEngine::eMapModeStrings[Attacher::mmFlatFace]); Gui::Command::doCommand(Doc,"App.activeDocument().%s.MapMode = '%s'",FeatName.c_str(),Attacher::AttachEngine::getModeName(Attacher::mmFlatFace).c_str());
Gui::Command::updateActive(); // Make sure the Support's Placement property is updated Gui::Command::updateActive(); // Make sure the Support's Placement property is updated
Gui::Command::doCommand(Doc,"App.activeDocument().%s.addFeature(App.activeDocument().%s)", Gui::Command::doCommand(Doc,"App.activeDocument().%s.addFeature(App.activeDocument().%s)",
pcActiveBody->getNameInDocument(), FeatName.c_str()); pcActiveBody->getNameInDocument(), FeatName.c_str());

View File

@ -951,7 +951,7 @@ bool TaskDlgDatumParameters::accept()
//here it is assumed that the support was already assigned, it just outputs a dummy Python command to the console //here it is assumed that the support was already assigned, it just outputs a dummy Python command to the console
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Support = %s", name.c_str(), pcDatum->Support.getPyReprString().c_str()); Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Support = %s", name.c_str(), pcDatum->Support.getPyReprString().c_str());
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.MapMode = '%s'", name.c_str(), AttachEngine::eMapModeStrings[parameter->getActiveMapMode()]); Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.MapMode = '%s'", name.c_str(), AttachEngine::getModeName(parameter->getActiveMapMode()).c_str());
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.recompute()"); Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.recompute()");
if (!DatumView->getObject()->isValid()) if (!DatumView->getObject()->isValid())

View File

@ -196,7 +196,7 @@ void fixSketchSupport (Sketcher::SketchObject* sketch)
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.MapReversed = %s", Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.MapReversed = %s",
sketch->getNameInDocument(), reverseSketch ? "True" : "False"); sketch->getNameInDocument(), reverseSketch ? "True" : "False");
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.MapMode = '%s'", Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.MapMode = '%s'",
sketch->getNameInDocument(), Attacher::AttachEngine::eMapModeStrings[Attacher::mmFlatFace]); sketch->getNameInDocument(), Attacher::AttachEngine::getModeName(Attacher::mmFlatFace).c_str());
} else { } else {
// Offset to base plane // Offset to base plane
@ -213,7 +213,7 @@ void fixSketchSupport (Sketcher::SketchObject* sketch)
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.Support = %s", Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.Support = %s",
Datum.c_str(), refStr.toStdString().c_str()); Datum.c_str(), refStr.toStdString().c_str());
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.MapMode = '%s'", Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.MapMode = '%s'",
Datum.c_str(), AttachEngine::eMapModeStrings[Attacher::mmFlatFace]); Datum.c_str(), AttachEngine::getModeName(Attacher::mmFlatFace).c_str());
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.superPlacement.Base.z = %f", Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.superPlacement.Base.z = %f",
Datum.c_str(), offset); Datum.c_str(), offset);
Gui::Command::doCommand(Gui::Command::Doc, Gui::Command::doCommand(Gui::Command::Doc,
@ -225,7 +225,7 @@ void fixSketchSupport (Sketcher::SketchObject* sketch)
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.MapReversed = %s", Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.MapReversed = %s",
sketch->getNameInDocument(), reverseSketch ? "True" : "False"); sketch->getNameInDocument(), reverseSketch ? "True" : "False");
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.MapMode = '%s'", Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.MapMode = '%s'",
sketch->getNameInDocument(),Attacher::AttachEngine::eMapModeStrings[Attacher::mmFlatFace]); sketch->getNameInDocument(),Attacher::AttachEngine::getModeName(Attacher::mmFlatFace).c_str());
} }
} }

View File

@ -204,7 +204,7 @@ void CmdSketcherNewSketch::activated(int iMsg)
openCommand("Create a Sketch on Face"); openCommand("Create a Sketch on Face");
doCommand(Doc,"App.activeDocument().addObject('Sketcher::SketchObject','%s')",FeatName.c_str()); doCommand(Doc,"App.activeDocument().addObject('Sketcher::SketchObject','%s')",FeatName.c_str());
if (mapmode >= 0 && mapmode < Attacher::mmDummy_NumberOfModes) if (mapmode >= 0 && mapmode < Attacher::mmDummy_NumberOfModes)
doCommand(Gui,"App.activeDocument().%s.MapMode = \"%s\"",FeatName.c_str(),AttachEngine::eMapModeStrings[mapmode]); doCommand(Gui,"App.activeDocument().%s.MapMode = \"%s\"",FeatName.c_str(),AttachEngine::getModeName(mapmode).c_str());
else else
assert(0 /* mapmode index out of range */); assert(0 /* mapmode index out of range */);
doCommand(Gui,"App.activeDocument().%s.Support = %s",FeatName.c_str(),supportString.c_str()); doCommand(Gui,"App.activeDocument().%s.Support = %s",FeatName.c_str(),supportString.c_str());
@ -256,7 +256,7 @@ void CmdSketcherNewSketch::activated(int iMsg)
openCommand("Create a new Sketch"); openCommand("Create a new Sketch");
doCommand(Doc,"App.activeDocument().addObject('Sketcher::SketchObject','%s')",FeatName.c_str()); doCommand(Doc,"App.activeDocument().addObject('Sketcher::SketchObject','%s')",FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.Placement = App.Placement(App.Vector(%f,%f,%f),App.Rotation(%f,%f,%f,%f))",FeatName.c_str(),p.x,p.y,p.z,r[0],r[1],r[2],r[3]); doCommand(Doc,"App.activeDocument().%s.Placement = App.Placement(App.Vector(%f,%f,%f),App.Rotation(%f,%f,%f,%f))",FeatName.c_str(),p.x,p.y,p.z,r[0],r[1],r[2],r[3]);
doCommand(Doc,"App.activeDocument().%s.MapMode = \"%s\"",FeatName.c_str(),AttachEngine::eMapModeStrings[int(Attacher::mmDeactivated)]); doCommand(Doc,"App.activeDocument().%s.MapMode = \"%s\"",FeatName.c_str(),AttachEngine::getModeName(Attacher::mmDeactivated).c_str());
doCommand(Gui,"Gui.activeDocument().activeView().setCamera('%s')",camstring.c_str()); doCommand(Gui,"Gui.activeDocument().activeView().setCamera('%s')",camstring.c_str());
doCommand(Gui,"Gui.activeDocument().setEdit('%s')",FeatName.c_str()); doCommand(Gui,"Gui.activeDocument().setEdit('%s')",FeatName.c_str());
} }
@ -517,7 +517,7 @@ void CmdSketcherMapSketch::activated(int iMsg)
int iSugg = 0;//index of the auto-suggested mode in the list of valid modes int iSugg = 0;//index of the auto-suggested mode in the list of valid modes
int iCurr = 0;//index of current mode in the list of valid modes int iCurr = 0;//index of current mode in the list of valid modes
for (size_t i = 0 ; i < validModes.size() ; ++i){ 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] == curMapMode) { if (validModes[i] == curMapMode) {
iCurr = items.size() - 1; iCurr = items.size() - 1;
items.back().append(bCurIncompatible? items.back().append(bCurIncompatible?
@ -564,12 +564,12 @@ void CmdSketcherMapSketch::activated(int iMsg)
std::string supportString = support.getPyReprString(); std::string supportString = support.getPyReprString();
openCommand("Attach Sketch"); openCommand("Attach Sketch");
doCommand(Gui,"App.activeDocument().%s.MapMode = \"%s\"",featName.c_str(),AttachEngine::eMapModeStrings[suggMapMode]); doCommand(Gui,"App.activeDocument().%s.MapMode = \"%s\"",featName.c_str(),AttachEngine::getModeName(suggMapMode).c_str());
doCommand(Gui,"App.activeDocument().%s.Support = %s",featName.c_str(),supportString.c_str()); doCommand(Gui,"App.activeDocument().%s.Support = %s",featName.c_str(),supportString.c_str());
commitCommand(); commitCommand();
} else { } else {
openCommand("Detach Sketch"); openCommand("Detach Sketch");
doCommand(Gui,"App.activeDocument().%s.MapMode = \"%s\"",featName.c_str(),AttachEngine::eMapModeStrings[suggMapMode]); doCommand(Gui,"App.activeDocument().%s.MapMode = \"%s\"",featName.c_str(),AttachEngine::getModeName(suggMapMode).c_str());
doCommand(Gui,"App.activeDocument().%s.Support = None",featName.c_str()); doCommand(Gui,"App.activeDocument().%s.Support = None",featName.c_str());
commitCommand(); commitCommand();
} }