From f9471019385fdbf8b8b74b845c5a1f0532b69892 Mon Sep 17 00:00:00 2001 From: DeepSOIC Date: Wed, 4 May 2016 17:05:57 +0300 Subject: [PATCH] Attacher: use getModeName() instead of eMapModeStrings[] getModeName() does range checking. eMapModeStrings[] will crash if out of range. --- src/Mod/PartDesign/Gui/Command.cpp | 4 ++-- src/Mod/PartDesign/Gui/TaskDatumParameters.cpp | 2 +- src/Mod/PartDesign/Gui/Utils.cpp | 6 +++--- src/Mod/Sketcher/Gui/Command.cpp | 10 +++++----- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Mod/PartDesign/Gui/Command.cpp b/src/Mod/PartDesign/Gui/Command.cpp index 94a262084..d3ceff674 100644 --- a/src/Mod/PartDesign/Gui/Command.cpp +++ b/src/Mod/PartDesign/Gui/Command.cpp @@ -423,7 +423,7 @@ void CmdPartDesignNewSketch::activated(int iMsg) openCommand("Create a Sketch on Face"); 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.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)", pcActiveBody->getNameInDocument(), FeatName.c_str()); 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::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.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::doCommand(Doc,"App.activeDocument().%s.addFeature(App.activeDocument().%s)", pcActiveBody->getNameInDocument(), FeatName.c_str()); diff --git a/src/Mod/PartDesign/Gui/TaskDatumParameters.cpp b/src/Mod/PartDesign/Gui/TaskDatumParameters.cpp index 89dc7131a..d9089f030 100644 --- a/src/Mod/PartDesign/Gui/TaskDatumParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskDatumParameters.cpp @@ -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 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()"); if (!DatumView->getObject()->isValid()) diff --git a/src/Mod/PartDesign/Gui/Utils.cpp b/src/Mod/PartDesign/Gui/Utils.cpp index 4597ec4c6..79dc32377 100644 --- a/src/Mod/PartDesign/Gui/Utils.cpp +++ b/src/Mod/PartDesign/Gui/Utils.cpp @@ -196,7 +196,7 @@ void fixSketchSupport (Sketcher::SketchObject* sketch) Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.MapReversed = %s", sketch->getNameInDocument(), reverseSketch ? "True" : "False"); 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 { // Offset to base plane @@ -213,7 +213,7 @@ void fixSketchSupport (Sketcher::SketchObject* sketch) Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.Support = %s", Datum.c_str(), refStr.toStdString().c_str()); 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", Datum.c_str(), offset); 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", sketch->getNameInDocument(), reverseSketch ? "True" : "False"); 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()); } } diff --git a/src/Mod/Sketcher/Gui/Command.cpp b/src/Mod/Sketcher/Gui/Command.cpp index 5b33edfc1..c88399751 100644 --- a/src/Mod/Sketcher/Gui/Command.cpp +++ b/src/Mod/Sketcher/Gui/Command.cpp @@ -204,7 +204,7 @@ void CmdSketcherNewSketch::activated(int iMsg) openCommand("Create a Sketch on Face"); doCommand(Doc,"App.activeDocument().addObject('Sketcher::SketchObject','%s')",FeatName.c_str()); 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 assert(0 /* mapmode index out of range */); 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"); 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.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().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 iCurr = 0;//index of current 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] == curMapMode) { iCurr = items.size() - 1; items.back().append(bCurIncompatible? @@ -564,12 +564,12 @@ void CmdSketcherMapSketch::activated(int iMsg) std::string supportString = support.getPyReprString(); 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()); commitCommand(); } else { 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()); commitCommand(); }