Gui: clean-up Selection API
Replace the int of the 'resolve' argument of several functions with a proper enum class. * This avoids the inconsistencies in client code where often true/false is passed when an int is expected * This avoids the use of magic numbers like 0, 1, 2 or the undocumented 3
This commit is contained in:
@@ -193,7 +193,7 @@ void Tessellation::on_estimateMaximumEdgeLength_clicked()
|
||||
}
|
||||
|
||||
double edgeLen = 0;
|
||||
for (auto &sel : Gui::Selection().getSelection("*",0)) {
|
||||
for (auto &sel : Gui::Selection().getSelection("*", Gui::ResolveMode::NoResolve)) {
|
||||
auto shape = Part::Feature::getTopoShape(sel.pObject,sel.SubName);
|
||||
if (shape.hasSubShape(TopAbs_FACE)) {
|
||||
Base::BoundBox3d bbox = shape.getBoundBox();
|
||||
@@ -225,7 +225,7 @@ bool Tessellation::accept()
|
||||
|
||||
bool bodyWithNoTip = false;
|
||||
bool partWithNoFace = false;
|
||||
for (auto &sel : Gui::Selection().getSelection("*",0)) {
|
||||
for (auto &sel : Gui::Selection().getSelection("*", Gui::ResolveMode::NoResolve)) {
|
||||
auto shape = Part::Feature::getTopoShape(sel.pObject,sel.SubName);
|
||||
if (shape.hasSubShape(TopAbs_FACE)) {
|
||||
shapeObjects.emplace_back(sel.pObject, sel.SubName);
|
||||
|
||||
@@ -307,7 +307,7 @@ void CmdPartCut::activated(int iMsg)
|
||||
{
|
||||
Q_UNUSED(iMsg);
|
||||
std::vector<Gui::SelectionObject> Sel =
|
||||
getSelection().getSelectionEx(nullptr, App::DocumentObject::getClassTypeId(),3);
|
||||
getSelection().getSelectionEx(nullptr, App::DocumentObject::getClassTypeId(), Gui::ResolveMode::FollowLink);
|
||||
if (Sel.size() != 2) {
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
|
||||
QObject::tr("Select two shapes please."));
|
||||
@@ -361,7 +361,7 @@ void CmdPartCut::activated(int iMsg)
|
||||
bool CmdPartCut::isActive(void)
|
||||
{
|
||||
return getSelection().countObjectsOfType(
|
||||
App::DocumentObject::getClassTypeId(),nullptr,3)==2;
|
||||
App::DocumentObject::getClassTypeId(), nullptr, Gui::ResolveMode::FollowLink)==2;
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
@@ -385,7 +385,7 @@ void CmdPartCommon::activated(int iMsg)
|
||||
{
|
||||
Q_UNUSED(iMsg);
|
||||
std::vector<Gui::SelectionObject> Sel =
|
||||
getSelection().getSelectionEx(nullptr, App::DocumentObject::getClassTypeId(), 3);
|
||||
getSelection().getSelectionEx(nullptr, App::DocumentObject::getClassTypeId(), Gui::ResolveMode::FollowLink);
|
||||
|
||||
//test if selected object is a compound, and if it is, look how many children it has...
|
||||
std::size_t numShapes = 0;
|
||||
@@ -461,7 +461,7 @@ void CmdPartCommon::activated(int iMsg)
|
||||
bool CmdPartCommon::isActive(void)
|
||||
{
|
||||
return getSelection().countObjectsOfType(
|
||||
App::DocumentObject::getClassTypeId(),nullptr,3)>=1;
|
||||
App::DocumentObject::getClassTypeId(), nullptr, Gui::ResolveMode::FollowLink) >= 1;
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
@@ -485,7 +485,7 @@ void CmdPartFuse::activated(int iMsg)
|
||||
{
|
||||
Q_UNUSED(iMsg);
|
||||
std::vector<Gui::SelectionObject> Sel =
|
||||
getSelection().getSelectionEx(nullptr, App::DocumentObject::getClassTypeId(),3);
|
||||
getSelection().getSelectionEx(nullptr, App::DocumentObject::getClassTypeId(), Gui::ResolveMode::FollowLink);
|
||||
|
||||
//test if selected object is a compound, and if it is, look how many children it has...
|
||||
std::size_t numShapes = 0;
|
||||
@@ -561,7 +561,7 @@ void CmdPartFuse::activated(int iMsg)
|
||||
bool CmdPartFuse::isActive(void)
|
||||
{
|
||||
return getSelection().countObjectsOfType(
|
||||
App::DocumentObject::getClassTypeId(),nullptr,3)>=1;
|
||||
App::DocumentObject::getClassTypeId(), nullptr, Gui::ResolveMode::FollowLink) >= 1;
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
@@ -921,7 +921,7 @@ void CmdPartCompound::activated(int iMsg)
|
||||
{
|
||||
Q_UNUSED(iMsg);
|
||||
unsigned int n = getSelection().countObjectsOfType(
|
||||
App::DocumentObject::getClassTypeId(),nullptr,3);
|
||||
App::DocumentObject::getClassTypeId(), nullptr, Gui::ResolveMode::FollowLink);
|
||||
if (n < 1) {
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
|
||||
QObject::tr("Select one shape or more, please."));
|
||||
@@ -954,7 +954,7 @@ void CmdPartCompound::activated(int iMsg)
|
||||
bool CmdPartCompound::isActive(void)
|
||||
{
|
||||
return getSelection().countObjectsOfType(
|
||||
App::DocumentObject::getClassTypeId(),nullptr,3)>=1;
|
||||
App::DocumentObject::getClassTypeId(), nullptr, Gui::ResolveMode::FollowLink) >= 1;
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
@@ -978,7 +978,7 @@ void CmdPartSection::activated(int iMsg)
|
||||
{
|
||||
Q_UNUSED(iMsg);
|
||||
std::vector<Gui::SelectionObject> Sel =
|
||||
getSelection().getSelectionEx(nullptr, App::DocumentObject::getClassTypeId(),3);
|
||||
getSelection().getSelectionEx(nullptr, App::DocumentObject::getClassTypeId(), Gui::ResolveMode::FollowLink);
|
||||
if (Sel.size() != 2) {
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
|
||||
QObject::tr("Select two shapes please."));
|
||||
@@ -1002,7 +1002,7 @@ void CmdPartSection::activated(int iMsg)
|
||||
|
||||
bool CmdPartSection::isActive(void)
|
||||
{
|
||||
return getSelection().countObjectsOfType(App::DocumentObject::getClassTypeId(),nullptr,3)==2;
|
||||
return getSelection().countObjectsOfType(App::DocumentObject::getClassTypeId(), nullptr, Gui::ResolveMode::FollowLink) == 2;
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
@@ -1113,7 +1113,7 @@ void CmdPartExport::activated(int iMsg)
|
||||
|
||||
bool CmdPartExport::isActive(void)
|
||||
{
|
||||
return Gui::Selection().countObjectsOfType(App::DocumentObject::getClassTypeId(),nullptr,3) > 0;
|
||||
return Gui::Selection().countObjectsOfType(App::DocumentObject::getClassTypeId(), nullptr, Gui::ResolveMode::FollowLink) > 0;
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
@@ -1185,7 +1185,7 @@ void CmdPartMakeSolid::activated(int iMsg)
|
||||
{
|
||||
Q_UNUSED(iMsg);
|
||||
std::vector<App::DocumentObject*> objs = Gui::Selection().getObjectsOfType
|
||||
(App::DocumentObject::getClassTypeId(),nullptr,3);
|
||||
(App::DocumentObject::getClassTypeId(), nullptr, Gui::ResolveMode::FollowLink);
|
||||
runCommand(Doc, "import Part");
|
||||
for (std::vector<App::DocumentObject*>::iterator it = objs.begin(); it != objs.end(); ++it) {
|
||||
const TopoDS_Shape& shape = Part::Feature::getShape(*it);
|
||||
@@ -1240,7 +1240,7 @@ void CmdPartMakeSolid::activated(int iMsg)
|
||||
bool CmdPartMakeSolid::isActive(void)
|
||||
{
|
||||
return Gui::Selection().countObjectsOfType
|
||||
(App::DocumentObject::getClassTypeId(),nullptr,3) > 0;
|
||||
(App::DocumentObject::getClassTypeId(), nullptr, Gui::ResolveMode::FollowLink) > 0;
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
@@ -1303,7 +1303,7 @@ void CmdPartReverseShape::activated(int iMsg)
|
||||
bool CmdPartReverseShape::isActive(void)
|
||||
{
|
||||
return Gui::Selection().countObjectsOfType
|
||||
(Part::Feature::getClassTypeId(), 0, 3) > 0;
|
||||
(Part::Feature::getClassTypeId(), nullptr, Gui::ResolveMode::FollowLink) > 0;
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
@@ -1385,7 +1385,7 @@ CmdPartMakeFace::CmdPartMakeFace()
|
||||
void CmdPartMakeFace::activated(int iMsg)
|
||||
{
|
||||
Q_UNUSED(iMsg);
|
||||
auto sketches = Gui::Selection().getObjectsOfType(App::DocumentObject::getClassTypeId(),nullptr,3);
|
||||
auto sketches = Gui::Selection().getObjectsOfType(App::DocumentObject::getClassTypeId(), nullptr, Gui::ResolveMode::FollowLink);
|
||||
if(sketches.empty())
|
||||
return;
|
||||
openCommand(QT_TRANSLATE_NOOP("Command", "Make face"));
|
||||
@@ -1413,7 +1413,7 @@ void CmdPartMakeFace::activated(int iMsg)
|
||||
|
||||
bool CmdPartMakeFace::isActive(void)
|
||||
{
|
||||
return (Gui::Selection().countObjectsOfType(App::DocumentObject::getClassTypeId(),nullptr,3) > 0 &&
|
||||
return (Gui::Selection().countObjectsOfType(App::DocumentObject::getClassTypeId(), nullptr, Gui::ResolveMode::FollowLink) > 0 &&
|
||||
!Gui::Control().activeDialog());
|
||||
}
|
||||
|
||||
@@ -1960,7 +1960,7 @@ void CmdPartThickness::activated(int iMsg)
|
||||
bool CmdPartThickness::isActive(void)
|
||||
{
|
||||
Base::Type partid = Base::Type::fromName("Part::Feature");
|
||||
bool objectsSelected = Gui::Selection().countObjectsOfType(partid, 0, 3) > 0;
|
||||
bool objectsSelected = Gui::Selection().countObjectsOfType(partid, nullptr, Gui::ResolveMode::FollowLink) > 0;
|
||||
return (objectsSelected && !Gui::Control().activeDialog());
|
||||
}
|
||||
|
||||
|
||||
@@ -189,12 +189,15 @@ CmdPartSimpleCopy::CmdPartSimpleCopy()
|
||||
static void _copyShape(const char *cmdName, bool resolve,bool needElement=false, bool refine=false) {
|
||||
Gui::WaitCursor wc;
|
||||
Gui::Command::openCommand(cmdName);
|
||||
for(auto &sel : Gui::Selection().getSelectionEx("*",App::DocumentObject::getClassTypeId(),resolve)) {
|
||||
for(auto &sel : Gui::Selection().getSelectionEx("*", App::DocumentObject::getClassTypeId(),
|
||||
resolve ? Gui::ResolveMode::OldStyleElement : Gui::ResolveMode::NoResolve)) {
|
||||
std::map<std::string,App::DocumentObject*> subMap;
|
||||
auto obj = sel.getObject();
|
||||
if(!obj) continue;
|
||||
if(resolve || !sel.hasSubNames())
|
||||
if (!obj)
|
||||
continue;
|
||||
if (resolve || !sel.hasSubNames()) {
|
||||
subMap.emplace("",obj);
|
||||
}
|
||||
else {
|
||||
for(const auto &sub : sel.getSubNames()) {
|
||||
const char *element = nullptr;
|
||||
@@ -215,8 +218,9 @@ static void _copyShape(const char *cmdName, bool resolve,bool needElement=false,
|
||||
"App.ActiveDocument.addObject('Part::Feature','%s').Shape=__shape\n"
|
||||
"App.ActiveDocument.ActiveObject.Label=%s.Label\n",
|
||||
parentName.c_str(), v.first.c_str(),
|
||||
needElement?"True":"False", refine?"True":"False",
|
||||
needElement?".copy()":"",
|
||||
needElement ? "True" : "False",
|
||||
refine ? "True" : "False",
|
||||
needElement ? ".copy()" : "",
|
||||
v.second->getNameInDocument(),
|
||||
Gui::Command::getObjectCmd(v.second).c_str());
|
||||
auto newObj = App::GetApplication().getActiveDocument()->getActiveObject();
|
||||
|
||||
@@ -366,7 +366,7 @@ void TaskAttacher::onSelectionChanged(const Gui::SelectionChanges& msg)
|
||||
std::vector<std::string> refnames = pcAttach->Support.getSubValues();
|
||||
App::DocumentObject* selObj = ViewProvider->getObject()->getDocument()->getObject(msg.pObjectName);
|
||||
if (!selObj || selObj == ViewProvider->getObject())//prevent self-referencing
|
||||
return;
|
||||
return;
|
||||
|
||||
std::string subname = msg.pSubName;
|
||||
|
||||
@@ -564,7 +564,7 @@ void TaskAttacher::onRefName(const QString& text, unsigned idx)
|
||||
return;
|
||||
|
||||
QLineEdit* line = getLine(idx);
|
||||
if (line == nullptr)
|
||||
if (line == nullptr)
|
||||
return;
|
||||
|
||||
if (text.length() == 0) {
|
||||
@@ -608,7 +608,7 @@ void TaskAttacher::onRefName(const QString& text, unsigned idx)
|
||||
parts.push_back(QString::fromLatin1(""));
|
||||
// Check whether this is the name of an App::Plane or Part::Datum feature
|
||||
App::DocumentObject* obj = ViewProvider->getObject()->getDocument()->getObject(parts[0].toLatin1());
|
||||
if (obj == nullptr)
|
||||
if (obj == nullptr)
|
||||
return;
|
||||
|
||||
std::string subElement;
|
||||
@@ -999,7 +999,7 @@ void TaskAttacher::visibilityAutomation(bool opening_not_closing)
|
||||
auto editDoc = Gui::Application::Instance->editDocument();
|
||||
App::DocumentObject *editObj = ViewProvider->getObject();
|
||||
std::string editSubName;
|
||||
auto sels = Gui::Selection().getSelection(nullptr,0,true);
|
||||
auto sels = Gui::Selection().getSelection(nullptr, Gui::ResolveMode::NoResolve, true);
|
||||
if(sels.size() && sels[0].pResolvedObject
|
||||
&& sels[0].pResolvedObject->getLinkedObject()==editObj)
|
||||
{
|
||||
|
||||
@@ -121,7 +121,7 @@ bool PartGui::getShapeFromStrings(TopoDS_Shape &shapeOut, const std::string &doc
|
||||
|
||||
bool PartGui::evaluateLinearPreSelection(TopoDS_Shape &shape1, TopoDS_Shape &shape2)
|
||||
{
|
||||
std::vector<Gui::SelectionSingleton::SelObj> selections = Gui::Selection().getSelection(nullptr,false);
|
||||
std::vector<Gui::SelectionSingleton::SelObj> selections = Gui::Selection().getSelection(nullptr, Gui::ResolveMode::NoResolve);
|
||||
if (selections.size() != 2)
|
||||
return false;
|
||||
std::vector<Gui::SelectionSingleton::SelObj>::iterator it;
|
||||
@@ -515,7 +515,7 @@ void PartGui::DimensionLinear::setupDimension()
|
||||
}
|
||||
|
||||
PartGui::TaskMeasureLinear::TaskMeasureLinear()
|
||||
: Gui::SelectionObserver(true,false)
|
||||
: Gui::SelectionObserver(true, Gui::ResolveMode::NoResolve)
|
||||
, selections1(), selections2(), buttonSelectedIndex(0)
|
||||
{
|
||||
setUpGui();
|
||||
@@ -832,7 +832,7 @@ void PartGui::goDimensionAngularRoot()
|
||||
|
||||
bool PartGui::evaluateAngularPreSelection(VectorAdapter &vector1Out, VectorAdapter &vector2Out)
|
||||
{
|
||||
std::vector<Gui::SelectionSingleton::SelObj> selections = Gui::Selection().getSelection(nullptr,false);
|
||||
std::vector<Gui::SelectionSingleton::SelObj> selections = Gui::Selection().getSelection(nullptr, Gui::ResolveMode::NoResolve);
|
||||
if (selections.size() > 4 || selections.size() < 2)
|
||||
return false;
|
||||
std::vector<Gui::SelectionSingleton::SelObj>::iterator it;
|
||||
@@ -1514,7 +1514,7 @@ void PartGui::DimensionControl::clearAllSlot(bool)
|
||||
}
|
||||
|
||||
PartGui::TaskMeasureAngular::TaskMeasureAngular()
|
||||
: Gui::SelectionObserver(true,false)
|
||||
: Gui::SelectionObserver(true, Gui::ResolveMode::NoResolve)
|
||||
, selections1(), selections2(), buttonSelectedIndex(0)
|
||||
{
|
||||
setUpGui();
|
||||
|
||||
@@ -355,7 +355,7 @@ void CmdPartDesignSubShapeBinder::activated(int iMsg)
|
||||
App::DocumentObject *parent = nullptr;
|
||||
std::string parentSub;
|
||||
std::map<App::DocumentObject *, std::vector<std::string> > values;
|
||||
for (auto &sel : Gui::Selection().getCompleteSelection(0)) {
|
||||
for (auto &sel : Gui::Selection().getCompleteSelection(Gui::ResolveMode::NoResolve)) {
|
||||
if (!sel.pObject) continue;
|
||||
auto &subs = values[sel.pObject];
|
||||
if (sel.SubName && sel.SubName[0])
|
||||
|
||||
@@ -144,7 +144,7 @@ void ViewProviderShapeBinder::highlightReferences(const bool on, bool /*auxiliar
|
||||
|
||||
PartGui::ViewProviderPart* svp = dynamic_cast<PartGui::ViewProviderPart*>(
|
||||
Gui::Application::Instance->getViewProvider(obj));
|
||||
if (svp == nullptr)
|
||||
if (svp == nullptr)
|
||||
return;
|
||||
|
||||
if (on) {
|
||||
@@ -271,7 +271,7 @@ std::string ViewProviderSubShapeBinder::dropObjectEx(App::DocumentObject* obj, A
|
||||
const char* subname, const std::vector<std::string>& elements)
|
||||
{
|
||||
auto self = dynamic_cast<PartDesign::SubShapeBinder*>(getObject());
|
||||
if (!self)
|
||||
if (!self)
|
||||
return std::string();
|
||||
std::map<App::DocumentObject*, std::vector<std::string> > values;
|
||||
if (!subname) subname = "";
|
||||
@@ -356,7 +356,7 @@ void ViewProviderSubShapeBinder::updatePlacement(bool transaction) {
|
||||
App::DocumentObject* parent = nullptr;
|
||||
std::string parentSub;
|
||||
if (relative && self->getParents().size()) {
|
||||
const auto& sel = Gui::Selection().getSelection("", 0);
|
||||
const auto& sel = Gui::Selection().getSelection("", Gui::ResolveMode::NoResolve);
|
||||
if (sel.size() != 1 || !sel[0].pObject ||
|
||||
sel[0].pObject->getSubObject(sel[0].SubName) != self)
|
||||
{
|
||||
|
||||
@@ -320,8 +320,8 @@ void CmdTechDrawView::activated(int iMsg)
|
||||
std::vector<App::DocumentObject*> xShapes;
|
||||
App::DocumentObject* partObj = nullptr;
|
||||
std::string faceName;
|
||||
int resolve = 1; //mystery
|
||||
bool single = false; //mystery
|
||||
Gui::ResolveMode resolve = Gui::ResolveMode::OldStyleElement; //mystery
|
||||
bool single = false; //mystery
|
||||
auto selection = getSelection().getSelectionEx(nullptr,
|
||||
App::DocumentObject::getClassTypeId(),
|
||||
resolve,
|
||||
@@ -599,8 +599,8 @@ void CmdTechDrawProjectionGroup::activated(int iMsg)
|
||||
std::vector<App::DocumentObject*> xShapes;
|
||||
App::DocumentObject* partObj = nullptr;
|
||||
std::string faceName;
|
||||
int resolve = 1; //mystery
|
||||
bool single = false; //mystery
|
||||
Gui::ResolveMode resolve = Gui::ResolveMode::OldStyleElement; //mystery
|
||||
bool single = false; //mystery
|
||||
auto selection = getSelection().getSelectionEx(nullptr,
|
||||
App::DocumentObject::getClassTypeId(),
|
||||
resolve,
|
||||
|
||||
@@ -995,14 +995,13 @@ void CmdTechDrawLinkDimension::activated(int iMsg)
|
||||
if (!page) {
|
||||
return;
|
||||
}
|
||||
std::string PageName = page->getNameInDocument();
|
||||
|
||||
bool result = _checkSelection(this,2);
|
||||
if (!result)
|
||||
return;
|
||||
|
||||
std::vector<Gui::SelectionObject> selection = getSelection().getSelectionEx(nullptr,
|
||||
App::DocumentObject::getClassTypeId(),0);
|
||||
App::DocumentObject::getClassTypeId(), Gui::ResolveMode::NoResolve);
|
||||
|
||||
App::DocumentObject* obj3D = nullptr;
|
||||
std::vector<App::DocumentObject*> parts;
|
||||
|
||||
Reference in New Issue
Block a user