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:
wmayer
2022-04-09 17:03:43 +02:00
parent 0571a7f2b2
commit 9eac35cf5d
24 changed files with 365 additions and 274 deletions
+1 -4
View File
@@ -892,10 +892,7 @@ App.Units.KinematicViscosity = App.Units.Unit(2,0,-1)
App.Units.VacuumPermittivity = App.Units.Unit(-3,-1,4,2)
# Add an enum for the different unit schemes
if sys.version_info.major < 3:
IntEnum = object
else:
from enum import IntEnum
from enum import IntEnum
# The values must match with that of the
# C++ enum class UnitSystem
+1 -1
View File
@@ -90,7 +90,7 @@ Gui::ActiveObjectList::ObjectInfo Gui::ActiveObjectList::getObjectInfo(App::Docu
// If the input object is not from this document, it must be brought in
// by some link type object of this document. We only accept the object
// if we can find such object in the current selection.
auto sels = Gui::Selection().getSelection(_Doc->getDocument()->getName(),false);
auto sels = Gui::Selection().getSelection(_Doc->getDocument()->getName(), ResolveMode::NoResolve);
for (auto &sel : sels) {
if (sel.pObject == obj || sel.pObject->getLinkedObject(true)==obj) {
info.obj = sel.pObject;
+2 -1
View File
@@ -144,7 +144,8 @@ bool StdCmdSendToPythonConsole::isActive(void)
void StdCmdSendToPythonConsole::activated(int iMsg)
{
Q_UNUSED(iMsg);
const std::vector<Gui::SelectionObject> &sels = Gui::Selection().getSelectionEx("*",App::DocumentObject::getClassTypeId(),true,false);
const std::vector<Gui::SelectionObject> &sels = Gui::Selection().getSelectionEx("*", App::DocumentObject::getClassTypeId(),
ResolveMode::OldStyleElement, false);
if (sels.empty())
return;
const App::DocumentObject *obj = sels[0].getObject();
+5 -5
View File
@@ -290,7 +290,7 @@ void StdCmdLinkMakeRelative::activated(int) {
try {
std::map<std::pair<App::DocumentObject*,std::string>,
std::pair<App::DocumentObject*, std::vector<std::string> > > linkInfo;
for(auto &sel : Selection().getCompleteSelection(0)) {
for(auto &sel : Selection().getCompleteSelection(ResolveMode::NoResolve)) {
if(!sel.pObject || !sel.pObject->getNameInDocument())
continue;
auto key = std::make_pair(sel.pObject,
@@ -548,7 +548,7 @@ StdCmdLinkImport::StdCmdLinkImport()
static std::map<App::Document*, std::vector<App::DocumentObject*> > getLinkImportSelections()
{
std::map<App::Document*, std::vector<App::DocumentObject*> > objMap;
for(auto &sel : Selection().getCompleteSelection(false)) {
for(auto &sel : Selection().getCompleteSelection(ResolveMode::NoResolve)) {
auto obj = sel.pObject->resolve(sel.SubName);
if(!obj || !obj->getNameInDocument())
continue;
@@ -652,7 +652,7 @@ StdCmdLinkSelectLinked::StdCmdLinkSelectLinked()
}
static App::DocumentObject *getSelectedLink(bool finalLink, std::string *subname=nullptr) {
const auto &sels = Selection().getSelection("*",0,true);
const auto &sels = Selection().getSelection("*", ResolveMode::NoResolve, true);
if(sels.empty())
return nullptr;
auto sobj = sels[0].pObject->getSubObject(sels[0].SubName);
@@ -812,7 +812,7 @@ StdCmdLinkSelectAllLinks::StdCmdLinkSelectAllLinks()
}
bool StdCmdLinkSelectAllLinks::isActive() {
const auto &sels = Selection().getSelection("*",true,true);
const auto &sels = Selection().getSelection("*", ResolveMode::OldStyleElement, true);
if(sels.empty())
return false;
return App::GetApplication().hasLinksTo(sels[0].pObject);
@@ -820,7 +820,7 @@ bool StdCmdLinkSelectAllLinks::isActive() {
void StdCmdLinkSelectAllLinks::activated(int)
{
auto sels = Selection().getSelection("*",true,true);
auto sels = Selection().getSelection("*", ResolveMode::OldStyleElement, true);
if(sels.empty())
return;
Selection().selStackPush();
+5 -5
View File
@@ -458,7 +458,7 @@ void StdCmdFreezeViews::onRestoreViews()
bool ok;
int scheme = root.attribute(QString::fromLatin1("SchemaVersion")).toInt(&ok);
if (!ok)
if (!ok)
return;
// SchemeVersion "1"
if (scheme == 1) {
@@ -1695,7 +1695,7 @@ void StdViewDockUndockFullscreen::activated(int iMsg)
MDIView* view = getMainWindow()->activeWindow();
if (!view) // no active view
return;
return;
// nothing to do when the view is docked and 'Docked' is pressed
if (iMsg == 0 && view->currentViewMode() == MDIView::Child)
@@ -2169,7 +2169,7 @@ bool StdCmdAxisCross::isActive(void)
if (_pcAction->isChecked())
_pcAction->setChecked(false);
}
if (view )
if (view)
return true;
return false;
@@ -3125,7 +3125,7 @@ StdCmdTreeSelectAllInstances::StdCmdTreeSelectAllInstances()
bool StdCmdTreeSelectAllInstances::isActive(void)
{
const auto &sels = Selection().getSelectionEx("*",App::DocumentObject::getClassTypeId(),true,true);
const auto &sels = Selection().getSelectionEx("*",App::DocumentObject::getClassTypeId(), ResolveMode::OldStyleElement, true);
if(sels.empty())
return false;
auto obj = sels[0].getObject();
@@ -3138,7 +3138,7 @@ bool StdCmdTreeSelectAllInstances::isActive(void)
void StdCmdTreeSelectAllInstances::activated(int iMsg)
{
Q_UNUSED(iMsg);
const auto &sels = Selection().getSelectionEx("*",App::DocumentObject::getClassTypeId(),true,true);
const auto &sels = Selection().getSelectionEx("*",App::DocumentObject::getClassTypeId(), ResolveMode::OldStyleElement, true);
if(sels.empty())
return;
auto obj = sels[0].getObject();
+2 -2
View File
@@ -66,7 +66,7 @@ public:
/* TRANSLATOR Gui::Dialog::DlgPropertyLink */
DlgPropertyLink::DlgPropertyLink(QWidget* parent)
: QDialog(parent), SelectionObserver(false,0)
: QDialog(parent), SelectionObserver(false, ResolveMode::NoResolve)
, ui(new Ui_DlgPropertyLink)
{
ui->setupUi(this);
@@ -428,7 +428,7 @@ void DlgPropertyLink::attachObserver() {
auto view = qobject_cast<Gui::PropertyView*>(p);
if(view) {
parentView = view;
for(auto &sel : Gui::Selection().getCompleteSelection(0))
for(auto &sel : Gui::Selection().getCompleteSelection(ResolveMode::NoResolve))
savedSelections.emplace_back(sel.DocName, sel.FeatName, sel.SubName);
break;
}
+2 -2
View File
@@ -297,7 +297,7 @@ bool Document::setEdit(Gui::ViewProvider* p, int ModNum, const char *subname)
if(!subname || !subname[0]) {
// No subname reference is given, we try to extract one from the current
// selection in order to obtain the correct transformation matrix below
auto sels = Gui::Selection().getCompleteSelection(false);
auto sels = Gui::Selection().getCompleteSelection(ResolveMode::NoResolve);
App::DocumentObject *parentObj = nullptr;
for(auto &sel : sels) {
if(!sel.pObject || !sel.pObject->getNameInDocument())
@@ -737,7 +737,7 @@ void Document::slotDeletedObject(const App::DocumentObject& Obj)
// cycling to all views of the document
ViewProvider* viewProvider = getViewProvider(&Obj);
if(!viewProvider)
if(!viewProvider)
return;
if (d->_editViewProvider==viewProvider || d->_editViewProviderParent==viewProvider)
+2 -2
View File
@@ -66,7 +66,7 @@ static ParameterGrp::handle _GetParam() {
* in two tabs.
*/
PropertyView::PropertyView(QWidget *parent)
: QWidget(parent), SelectionObserver(false, 0)
: QWidget(parent), SelectionObserver(false, ResolveMode::NoResolve)
{
QGridLayout* pLayout = new QGridLayout( this );
pLayout->setSpacing(0);
@@ -298,7 +298,7 @@ void PropertyView::checkEnable(const char *doc) {
}
// check if at least one selected object is part of the active document
setEnabled(!Selection().hasSelection()
|| Selection().hasSelection(doc,false));
|| Selection().hasSelection(doc, ResolveMode::NoResolve));
}
struct PropertyView::PropInfo
+202 -141
View File
@@ -79,7 +79,7 @@ bool SelectionGateFilterExternal::allow(App::Document *doc ,App::DocumentObject
//////////////////////////////////////////////////////////////////////////////////////////
SelectionObserver::SelectionObserver(bool attach, int resolve)
SelectionObserver::SelectionObserver(bool attach, ResolveMode resolve)
: resolve(resolve)
, blockedSelection(false)
{
@@ -87,7 +87,7 @@ SelectionObserver::SelectionObserver(bool attach, int resolve)
attachSelection();
}
SelectionObserver::SelectionObserver(const ViewProviderDocumentObject *vp,bool attach, int resolve)
SelectionObserver::SelectionObserver(const ViewProviderDocumentObject *vp, bool attach, ResolveMode resolve)
: resolve(resolve)
, blockedSelection(false)
{
@@ -125,9 +125,11 @@ bool SelectionObserver::isSelectionAttached() const
void SelectionObserver::attachSelection()
{
if (!connectSelection.connected()) {
auto &signal = resolve > 1 ? Selection().signalSelectionChanged3 :
resolve ? Selection().signalSelectionChanged2 :
Selection().signalSelectionChanged ;
bool newStyle = (resolve >= ResolveMode::NewStyleElement);
bool oldStyle = (resolve == ResolveMode::OldStyleElement);
auto &signal = newStyle ? Selection().signalSelectionChanged3 :
oldStyle ? Selection().signalSelectionChanged2 :
Selection().signalSelectionChanged ;
connectSelection = signal.connect(boost::bind
(&SelectionObserver::_onSelectionChanged, this, bp::_1));
@@ -166,8 +168,8 @@ void SelectionObserver::detachSelection()
std::vector<SelectionObserverPython*> SelectionObserverPython::_instances;
SelectionObserverPython::SelectionObserverPython(const Py::Object& obj, int resolve)
: SelectionObserver(true,resolve),inst(obj)
SelectionObserverPython::SelectionObserverPython(const Py::Object& obj, ResolveMode resolve)
: SelectionObserver(true, resolve), inst(obj)
{
#undef FC_PY_ELEMENT
#define FC_PY_ELEMENT(_name) FC_PY_GetCallable(obj.ptr(),#_name,py_##_name);
@@ -178,9 +180,9 @@ SelectionObserverPython::~SelectionObserverPython()
{
}
void SelectionObserverPython::addObserver(const Py::Object& obj, int resolve)
void SelectionObserverPython::addObserver(const Py::Object& obj, ResolveMode resolve)
{
_instances.push_back(new SelectionObserverPython(obj,resolve));
_instances.push_back(new SelectionObserverPython(obj, resolve));
}
void SelectionObserverPython::removeObserver(const Py::Object& obj)
@@ -362,20 +364,20 @@ bool SelectionSingleton::hasPreselection() const {
return !CurrentPreselection.Object.getObjectName().empty();
}
std::vector<SelectionSingleton::SelObj> SelectionSingleton::getCompleteSelection(int resolve) const
std::vector<SelectionSingleton::SelObj> SelectionSingleton::getCompleteSelection(ResolveMode resolve) const
{
return getSelection("*",resolve);
return getSelection("*", resolve);
}
std::vector<SelectionSingleton::SelObj> SelectionSingleton::getSelection(const char* pDocName,
int resolve, bool single) const
std::vector<SelectionSingleton::SelObj> SelectionSingleton::getSelection(const char* pDocName, ResolveMode resolve, bool single) const
{
std::vector<SelObj> temp;
if(single) temp.reserve(1);
if (single)
temp.reserve(1);
SelObj tempSelObj;
App::Document *pcDoc = nullptr;
if(!pDocName || strcmp(pDocName,"*")!=0) {
if(!pDocName || strcmp(pDocName,"*") != 0) {
pcDoc = getDocument(pDocName);
if (!pcDoc)
return temp;
@@ -384,17 +386,18 @@ std::vector<SelectionSingleton::SelObj> SelectionSingleton::getSelection(const c
std::map<App::DocumentObject*,std::set<std::string> > objMap;
for(auto &sel : _SelList) {
if(!sel.pDoc) continue;
if (!sel.pDoc)
continue;
const char *subelement = nullptr;
auto obj = getObjectOfType(sel,App::DocumentObject::getClassTypeId(),resolve,&subelement);
if(!obj || (pcDoc && sel.pObject->getDocument()!=pcDoc))
auto obj = getObjectOfType(sel, App::DocumentObject::getClassTypeId(), resolve, &subelement);
if (!obj || (pcDoc && sel.pObject->getDocument() != pcDoc))
continue;
// In case we are resolving objects, make sure no duplicates
if(resolve && !objMap[obj].insert(std::string(subelement?subelement:"")).second)
if (resolve != ResolveMode::NoResolve && !objMap[obj].insert(std::string(subelement ? subelement : "")).second)
continue;
if(single && temp.size()) {
if (single && temp.size()) {
temp.clear();
break;
}
@@ -416,18 +419,19 @@ std::vector<SelectionSingleton::SelObj> SelectionSingleton::getSelection(const c
return temp;
}
bool SelectionSingleton::hasSelection(const char* doc, bool resolve) const
bool SelectionSingleton::hasSelection(const char* doc, ResolveMode resolve) const
{
App::Document *pcDoc = nullptr;
if(!doc || strcmp(doc,"*")!=0) {
if (!doc || strcmp(doc,"*") != 0) {
pcDoc = getDocument(doc);
if (!pcDoc)
return false;
}
for(auto &sel : _SelList) {
if(!sel.pDoc) continue;
auto obj = getObjectOfType(sel,App::DocumentObject::getClassTypeId(),resolve);
if(obj && (!pcDoc || sel.pObject->getDocument()==pcDoc)) {
if (!sel.pDoc)
continue;
auto obj = getObjectOfType(sel, App::DocumentObject::getClassTypeId(), resolve);
if (obj && (!pcDoc || sel.pObject->getDocument()==pcDoc)) {
return true;
}
}
@@ -463,7 +467,7 @@ std::vector<SelectionSingleton::SelObj> SelectionSingleton::getPickedList(const
SelObj tempSelObj;
App::Document *pcDoc = nullptr;
if(!pDocName || strcmp(pDocName,"*")!=0) {
if(!pDocName || strcmp(pDocName,"*") != 0) {
pcDoc = getDocument(pDocName);
if (!pcDoc)
return temp;
@@ -488,20 +492,24 @@ std::vector<SelectionSingleton::SelObj> SelectionSingleton::getPickedList(const
return temp;
}
std::vector<SelectionObject> SelectionSingleton::getSelectionEx(
const char* pDocName, Base::Type typeId, int resolve, bool single) const {
return getObjectList(pDocName,typeId,_SelList,resolve,single);
std::vector<SelectionObject> SelectionSingleton::getSelectionEx(const char* pDocName, Base::Type typeId,
ResolveMode resolve, bool single) const
{
return getObjectList(pDocName, typeId, _SelList, resolve, single);
}
std::vector<SelectionObject> SelectionSingleton::getPickedListEx(const char* pDocName, Base::Type typeId) const {
return getObjectList(pDocName,typeId,_PickedList,false);
std::vector<SelectionObject> SelectionSingleton::getPickedListEx(const char* pDocName, Base::Type typeId) const
{
return getObjectList(pDocName, typeId, _PickedList, ResolveMode::NoResolve);
}
std::vector<SelectionObject> SelectionSingleton::getObjectList(const char* pDocName, Base::Type typeId,
std::list<_SelObj> &objList, int resolve, bool single) const
std::list<_SelObj> &objList,
ResolveMode resolve, bool single) const
{
std::vector<SelectionObject> temp;
if(single) temp.reserve(1);
if (single)
temp.reserve(1);
std::map<App::DocumentObject*,size_t> SortMap;
// check the type
@@ -509,30 +517,31 @@ std::vector<SelectionObject> SelectionSingleton::getObjectList(const char* pDocN
return temp;
App::Document *pcDoc = nullptr;
if(!pDocName || strcmp(pDocName,"*")!=0) {
if (!pDocName || strcmp(pDocName,"*") != 0) {
pcDoc = getDocument(pDocName);
if (!pcDoc)
return temp;
}
for (auto &sel : objList) {
if(!sel.pDoc) continue;
if(!sel.pDoc)
continue;
const char *subelement = nullptr;
auto obj = getObjectOfType(sel,typeId,resolve,&subelement);
if(!obj || (pcDoc && sel.pObject->getDocument()!=pcDoc))
if (!obj || (pcDoc && sel.pObject->getDocument() != pcDoc))
continue;
auto it = SortMap.find(obj);
if(it!=SortMap.end()) {
// only add sub-element
if (subelement && *subelement) {
if(resolve && !temp[it->second]._SubNameSet.insert(subelement).second)
if (resolve != ResolveMode::NoResolve && !temp[it->second]._SubNameSet.insert(subelement).second)
continue;
temp[it->second].SubNames.push_back(subelement);
temp[it->second].SelPoses.emplace_back(sel.x,sel.y,sel.z);
}
}
else {
if(single && temp.size()) {
if (single && temp.size()) {
temp.clear();
break;
}
@@ -541,7 +550,7 @@ std::vector<SelectionObject> SelectionSingleton::getObjectList(const char* pDocN
if (subelement && *subelement) {
temp.back().SubNames.push_back(subelement);
temp.back().SelPoses.emplace_back(sel.x,sel.y,sel.z);
if(resolve)
if (resolve != ResolveMode::NoResolve)
temp.back()._SubNameSet.insert(subelement);
}
SortMap.insert(std::make_pair(obj,temp.size()-1));
@@ -551,11 +560,13 @@ std::vector<SelectionObject> SelectionSingleton::getObjectList(const char* pDocN
return temp;
}
bool SelectionSingleton::needPickedList() const {
bool SelectionSingleton::needPickedList() const
{
return _needPickedList;
}
void SelectionSingleton::enablePickedList(bool enable) {
void SelectionSingleton::enablePickedList(bool enable)
{
if(enable != _needPickedList) {
_needPickedList = enable;
_PickedList.clear();
@@ -563,7 +574,8 @@ void SelectionSingleton::enablePickedList(bool enable) {
}
}
void SelectionSingleton::notify(SelectionChanges &&Chng) {
void SelectionSingleton::notify(SelectionChanges &&Chng)
{
if(Notifying) {
NotificationQueue.push_back(std::move(Chng));
return;
@@ -575,10 +587,10 @@ void SelectionSingleton::notify(SelectionChanges &&Chng) {
bool notify;
switch(msg.Type) {
case SelectionChanges::AddSelection:
notify = isSelected(msg.pDocName,msg.pObjectName,msg.pSubName,0);
notify = isSelected(msg.pDocName, msg.pObjectName, msg.pSubName, ResolveMode::NoResolve);
break;
case SelectionChanges::RmvSelection:
notify = !isSelected(msg.pDocName,msg.pObjectName,msg.pSubName,0);
notify = !isSelected(msg.pDocName, msg.pObjectName, msg.pSubName, ResolveMode::NoResolve);
break;
case SelectionChanges::SetPreselect:
notify = CurrentPreselection.Type==SelectionChanges::SetPreselect
@@ -604,23 +616,27 @@ void SelectionSingleton::notify(SelectionChanges &&Chng) {
}
}
bool SelectionSingleton::hasPickedList() const {
bool SelectionSingleton::hasPickedList() const
{
return _PickedList.size();
}
int SelectionSingleton::getAsPropertyLinkSubList(App::PropertyLinkSubList &prop) const
{
std::vector<Gui::SelectionObject> sel = this->getSelectionEx();
std::vector<App::DocumentObject*> objs; objs.reserve(sel.size()*2);
std::vector<App::DocumentObject*> objs; objs.reserve(sel.size() * 2);
std::vector<std::string> subs; subs.reserve(sel.size()*2);
for (std::size_t iobj = 0; iobj < sel.size(); iobj++) {
Gui::SelectionObject &selitem = sel[iobj];
App::DocumentObject* obj = selitem.getObject();
const std::vector<std::string> &subnames = selitem.getSubNames();
if (subnames.size() == 0){//whole object is selected
//whole object is selected
if (subnames.size() == 0){
objs.push_back(obj);
subs.emplace_back();
} else {
}
else {
for (std::size_t isub = 0; isub < subnames.size(); isub++) {
objs.push_back(obj);
subs.push_back(subnames[isub]);
@@ -632,35 +648,39 @@ int SelectionSingleton::getAsPropertyLinkSubList(App::PropertyLinkSubList &prop)
return objs.size();
}
App::DocumentObject *SelectionSingleton::getObjectOfType(_SelObj &sel,
Base::Type typeId, int resolve, const char **subelement)
App::DocumentObject *SelectionSingleton::getObjectOfType(_SelObj &sel, Base::Type typeId,
ResolveMode resolve, const char **subelement)
{
auto obj = sel.pObject;
if(!obj || !obj->getNameInDocument())
return nullptr;
const char *subname = sel.SubName.c_str();
if(resolve) {
if (resolve != ResolveMode::NoResolve) {
obj = sel.pResolvedObject;
if(resolve==2 && sel.elementName.first.size())
if (resolve == ResolveMode::NewStyleElement && sel.elementName.first.size())
subname = sel.elementName.first.c_str();
else
subname = sel.elementName.second.c_str();
}
if(!obj)
if (!obj)
return nullptr;
if(!obj->isDerivedFrom(typeId) &&
(resolve!=3 || !obj->getLinkedObject(true)->isDerivedFrom(typeId)))
if (!obj->isDerivedFrom(typeId) && (resolve != ResolveMode::FollowLink || !obj->getLinkedObject(true)->isDerivedFrom(typeId)))
return nullptr;
if(subelement) *subelement = subname;
if (subelement)
*subelement = subname;
return obj;
}
vector<App::DocumentObject*> SelectionSingleton::getObjectsOfType(const Base::Type& typeId, const char* pDocName, int resolve) const
vector<App::DocumentObject*> SelectionSingleton::getObjectsOfType(const Base::Type& typeId, const char* pDocName, ResolveMode resolve) const
{
std::vector<App::DocumentObject*> temp;
App::Document *pcDoc = nullptr;
if(!pDocName || strcmp(pDocName,"*")!=0) {
if (!pDocName || strcmp(pDocName,"*") != 0) {
pcDoc = getDocument(pDocName);
if (!pcDoc)
return temp;
@@ -669,7 +689,7 @@ vector<App::DocumentObject*> SelectionSingleton::getObjectsOfType(const Base::Ty
std::set<App::DocumentObject*> objs;
for(auto &sel : _SelList) {
if(pcDoc && pcDoc!=sel.pDoc) continue;
App::DocumentObject *pObject = getObjectOfType(sel,typeId,resolve);
App::DocumentObject *pObject = getObjectOfType(sel, typeId, resolve);
if (pObject) {
auto ret = objs.insert(pObject);
if(ret.second)
@@ -680,7 +700,7 @@ vector<App::DocumentObject*> SelectionSingleton::getObjectsOfType(const Base::Ty
return temp;
}
std::vector<App::DocumentObject*> SelectionSingleton::getObjectsOfType(const char* typeName, const char* pDocName, int resolve) const
std::vector<App::DocumentObject*> SelectionSingleton::getObjectsOfType(const char* typeName, const char* pDocName, ResolveMode resolve) const
{
Base::Type typeId = Base::Type::fromName(typeName);
if (typeId == Base::Type::badType())
@@ -688,25 +708,25 @@ std::vector<App::DocumentObject*> SelectionSingleton::getObjectsOfType(const cha
return getObjectsOfType(typeId, pDocName, resolve);
}
unsigned int SelectionSingleton::countObjectsOfType(const Base::Type& typeId, const char* pDocName, int resolve) const
unsigned int SelectionSingleton::countObjectsOfType(const Base::Type& typeId, const char* pDocName, ResolveMode resolve) const
{
unsigned int iNbr=0;
App::Document *pcDoc = nullptr;
if(!pDocName || strcmp(pDocName,"*")!=0) {
if(!pDocName || strcmp(pDocName,"*") != 0) {
pcDoc = getDocument(pDocName);
if (!pcDoc)
return 0;
}
for (auto &sel : _SelList) {
if((!pcDoc||pcDoc==sel.pDoc) && getObjectOfType(sel,typeId,resolve))
if((!pcDoc||pcDoc==sel.pDoc) && getObjectOfType(sel, typeId, resolve))
iNbr++;
}
return iNbr;
}
unsigned int SelectionSingleton::countObjectsOfType(const char* typeName, const char* pDocName, int resolve) const
unsigned int SelectionSingleton::countObjectsOfType(const char* typeName, const char* pDocName, ResolveMode resolve) const
{
Base::Type typeId = Base::Type::fromName(typeName);
if (typeId == Base::Type::badType())
@@ -715,7 +735,8 @@ unsigned int SelectionSingleton::countObjectsOfType(const char* typeName, const
}
void SelectionSingleton::slotSelectionChanged(const SelectionChanges& msg) {
void SelectionSingleton::slotSelectionChanged(const SelectionChanges& msg)
{
if(msg.Type == SelectionChanges::SetPreselectSignal ||
msg.Type == SelectionChanges::ShowSelection ||
msg.Type == SelectionChanges::HideSelection)
@@ -723,13 +744,13 @@ void SelectionSingleton::slotSelectionChanged(const SelectionChanges& msg) {
if(msg.Object.getSubName().size()) {
auto pParent = msg.Object.getObject();
if(!pParent)
if(!pParent)
return;
std::pair<std::string,std::string> elementName;
auto &newElementName = elementName.first;
auto &oldElementName = elementName.second;
auto pObject = App::GeoFeature::resolveElement(pParent,msg.pSubName,elementName);
if (!pObject)
if (!pObject)
return;
SelectionChanges msg2(msg.Type,pObject->getDocument()->getName(),
pObject->getNameInDocument(),
@@ -797,18 +818,18 @@ int SelectionSingleton::setPreselect(const char* pDocName, const char* pObjectNa
return 0;
const char *subelement = pSubName;
if(gateResolve) {
if (gateResolve != ResolveMode::NoResolve) {
auto &newElementName = elementName.first;
auto &oldElementName = elementName.second;
pObject = App::GeoFeature::resolveElement(pObject,pSubName,elementName);
if (!pObject)
return 0;
if(gateResolve > 1)
subelement = newElementName.size()?newElementName.c_str():oldElementName.c_str();
if (gateResolve > ResolveMode::OldStyleElement)
subelement = newElementName.size() ? newElementName.c_str() : oldElementName.c_str();
else
subelement = oldElementName.c_str();
}
if (!ActiveGate->allow(pObject->getDocument(),pObject,subelement)) {
if (!ActiveGate->allow(pObject->getDocument(), pObject, subelement)) {
QString msg;
if (ActiveGate->notAllowedReason.length() > 0){
msg = QObject::tr(ActiveGate->notAllowedReason.c_str());
@@ -894,7 +915,7 @@ void SelectionSingleton::setPreselectCoord( float x, float y, float z)
static char buf[513];
// if nothing is in preselect ignore
if(CurrentPreselection.Object.getObjectName().empty())
if(CurrentPreselection.Object.getObjectName().empty())
return;
CurrentPreselection.x = x;
@@ -955,7 +976,7 @@ const SelectionChanges &SelectionSingleton::getPreselection(void) const
}
// add a SelectionGate to control what is selectable
void SelectionSingleton::addSelectionGate(Gui::SelectionGate *gate, int resolve)
void SelectionSingleton::addSelectionGate(Gui::SelectionGate *gate, ResolveMode resolve)
{
if (ActiveGate)
rmvSelectionGate();
@@ -1059,8 +1080,8 @@ bool SelectionSingleton::addSelection(const char* pDocName, const char* pObjectN
}
_SelObj temp;
int ret = checkSelection(pDocName,pObjectName,pSubName,0,temp);
if(ret!=0)
int ret = checkSelection(pDocName, pObjectName, pSubName, ResolveMode::NoResolve, temp);
if (ret!=0)
return false;
temp.x = x;
@@ -1206,15 +1227,15 @@ void SelectionSingleton::selStackGoForward(int count) {
getMainWindow()->updateActions();
}
std::vector<SelectionObject> SelectionSingleton::selStackGet(
const char* pDocName, int resolve, int index) const
std::vector<SelectionObject> SelectionSingleton::selStackGet(const char* pDocName, ResolveMode resolve, int index) const
{
const SelStackItem *item = nullptr;
if(index>=0) {
if(index>=(int)_SelStackBack.size())
if (index >= 0) {
if(index >= (int)_SelStackBack.size())
return {};
item = &_SelStackBack[_SelStackBack.size()-1-index];
}else{
}
else {
index = -index-1;
if(index>=(int)_SelStackForward.size())
return {};
@@ -1227,7 +1248,7 @@ std::vector<SelectionObject> SelectionSingleton::selStackGet(
if(checkSelection(sobjT.getDocumentName().c_str(),
sobjT.getObjectName().c_str(),
sobjT.getSubName().c_str(),
0,
ResolveMode::NoResolve,
sel,
&selList)==0)
{
@@ -1235,7 +1256,7 @@ std::vector<SelectionObject> SelectionSingleton::selStackGet(
}
}
return getObjectList(pDocName,App::DocumentObject::getClassTypeId(),selList,resolve);
return getObjectList(pDocName,App::DocumentObject::getClassTypeId(), selList, resolve);
}
bool SelectionSingleton::addSelections(const char* pDocName, const char* pObjectName, const std::vector<std::string>& pSubNames)
@@ -1248,8 +1269,8 @@ bool SelectionSingleton::addSelections(const char* pDocName, const char* pObject
bool update = false;
for(std::vector<std::string>::const_iterator it = pSubNames.begin(); it != pSubNames.end(); ++it) {
_SelObj temp;
int ret = checkSelection(pDocName,pObjectName,it->c_str(),0,temp);
if(ret!=0)
int ret = checkSelection(pDocName, pObjectName, it->c_str(), ResolveMode::NoResolve, temp);
if (ret!=0)
continue;
temp.x = 0;
@@ -1288,12 +1309,12 @@ bool SelectionSingleton::updateSelection(bool show, const char* pDocName,
rmvPreselect();
}
auto pDoc = getDocument(pDocName);
if(!pDoc)
if(!pDoc)
return false;
auto pObject = pDoc->getObject(pObjectName);
if(!pObject)
if(!pObject)
return false;
if (!isSelected(pObject, pSubName,0))
if (!isSelected(pObject, pSubName, ResolveMode::NoResolve))
return false;
SelectionChanges Chng(show?SelectionChanges::ShowSelection:SelectionChanges::HideSelection,
@@ -1306,7 +1327,7 @@ bool SelectionSingleton::updateSelection(bool show, const char* pDocName,
return true;
}
bool SelectionSingleton::addSelection(const SelectionObject& obj,bool clearPreselect)
bool SelectionSingleton::addSelection(const SelectionObject& obj, bool clearPreselect)
{
const std::vector<std::string>& subNames = obj.getSubNames();
const std::vector<Base::Vector3d> points = obj.getPickedPoints();
@@ -1357,12 +1378,12 @@ void SelectionSingleton::rmvSelection(const char* pDocName, const char* pObjectN
notify(SelectionChanges(SelectionChanges::PickedListChanged));
}
if(!pDocName)
if(!pDocName)
return;
_SelObj temp;
int ret = checkSelection(pDocName,pObjectName,pSubName,0,temp);
if(ret<0)
int ret = checkSelection(pDocName, pObjectName, pSubName, ResolveMode::NoResolve, temp);
if (ret<0)
return;
std::vector<SelectionChanges> changes;
@@ -1518,8 +1539,8 @@ void SelectionSingleton::setSelection(const char* pDocName, const std::vector<Ap
if(!obj || !obj->getNameInDocument())
continue;
_SelObj temp;
int ret = checkSelection(pDocName,obj->getNameInDocument(),nullptr,0,temp);
if(ret!=0)
int ret = checkSelection(pDocName,obj->getNameInDocument(), nullptr, ResolveMode::NoResolve, temp);
if (ret!=0)
continue;
touched = true;
_SelList.push_back(temp);
@@ -1527,7 +1548,7 @@ void SelectionSingleton::setSelection(const char* pDocName, const std::vector<Ap
if(touched) {
_SelStackForward.clear();
notify(SelectionChanges(SelectionChanges::SetSelection,pDocName));
notify(SelectionChanges(SelectionChanges::SetSelection, pDocName));
getMainWindow()->updateActions();
}
}
@@ -1611,24 +1632,24 @@ void SelectionSingleton::clearCompleteSelection(bool clearPreSelect)
getMainWindow()->updateActions();
}
bool SelectionSingleton::isSelected(const char* pDocName,
const char* pObjectName, const char* pSubName, int resolve) const
bool SelectionSingleton::isSelected(const char* pDocName, const char* pObjectName,
const char* pSubName, ResolveMode resolve) const
{
_SelObj sel;
return checkSelection(pDocName,pObjectName,pSubName,resolve,sel,&_SelList)>0;
return checkSelection(pDocName, pObjectName, pSubName, resolve, sel, &_SelList) > 0;
}
bool SelectionSingleton::isSelected(App::DocumentObject* pObject, const char* pSubName, int resolve) const
bool SelectionSingleton::isSelected(App::DocumentObject* pObject, const char* pSubName, ResolveMode resolve) const
{
if(!pObject || !pObject->getNameInDocument() || !pObject->getDocument())
if (!pObject || !pObject->getNameInDocument() || !pObject->getDocument())
return false;
_SelObj sel;
return checkSelection(pObject->getDocument()->getName(),
pObject->getNameInDocument(),pSubName,resolve,sel,&_SelList)>0;
pObject->getNameInDocument(), pSubName, resolve, sel, &_SelList) > 0;
}
int SelectionSingleton::checkSelection(const char *pDocName, const char *pObjectName,
const char *pSubName, int resolve, _SelObj &sel, const std::list<_SelObj> *selList) const
int SelectionSingleton::checkSelection(const char *pDocName, const char *pObjectName, const char *pSubName,
ResolveMode resolve, _SelObj &sel, const std::list<_SelObj> *selList) const
{
sel.pDoc = getDocument(pDocName);
if(!sel.pDoc) {
@@ -1648,11 +1669,11 @@ int SelectionSingleton::checkSelection(const char *pDocName, const char *pObject
FC_ERR("Object not found");
return -1;
}
if(sel.pObject->testStatus(App::ObjectStatus::Remove))
if (sel.pObject->testStatus(App::ObjectStatus::Remove))
return -1;
if(pSubName)
if (pSubName)
sel.SubName = pSubName;
if(!resolve)
if (resolve == ResolveMode::NoResolve)
TreeWidget::checkTopParent(sel.pObject,sel.SubName);
pSubName = sel.SubName.size()?sel.SubName.c_str():nullptr;
sel.FeatName = sel.pObject->getNameInDocument();
@@ -1688,20 +1709,21 @@ int SelectionSingleton::checkSelection(const char *pDocName, const char *pObject
if (s.DocName==pDocName && s.FeatName==sel.FeatName) {
if(s.SubName==pSubName)
return 1;
if(resolve>1 && boost::starts_with(s.SubName,prefix))
if (resolve > ResolveMode::OldStyleElement && boost::starts_with(s.SubName,prefix))
return 1;
}
}
if(resolve==1) {
if (resolve == ResolveMode::OldStyleElement) {
for(auto &s : *selList) {
if(s.pResolvedObject != sel.pResolvedObject)
continue;
if(!pSubName[0])
return 1;
if(s.elementName.first.size()) {
if(s.elementName.first == sel.elementName.first)
if (s.elementName.first.size()) {
if (s.elementName.first == sel.elementName.first)
return 1;
}else if(s.SubName == sel.elementName.second)
}
else if(s.SubName == sel.elementName.second)
return 1;
}
}
@@ -1710,7 +1732,7 @@ int SelectionSingleton::checkSelection(const char *pDocName, const char *pObject
const char *SelectionSingleton::getSelectedElement(App::DocumentObject *obj, const char* pSubName) const
{
if (!obj)
if (!obj)
return nullptr;
for(list<_SelObj>::const_iterator It = _SelList.begin();It != _SelList.end();++It) {
@@ -1729,7 +1751,7 @@ const char *SelectionSingleton::getSelectedElement(App::DocumentObject *obj, con
void SelectionSingleton::slotDeletedObject(const App::DocumentObject& Obj)
{
if(!Obj.getNameInDocument())
if(!Obj.getNameInDocument())
return;
// For safety reason, don't bother checking
@@ -1787,7 +1809,7 @@ SelectionSingleton::SelectionSingleton()
hy = 0;
hz = 0;
ActiveGate = nullptr;
gateResolve = 1;
gateResolve = ResolveMode::OldStyleElement;
App::GetApplication().signalDeletedObject.connect(boost::bind(&Gui::SelectionSingleton::slotDeletedObject, this, bp::_1));
signalSelectionChanged.connect(boost::bind(&Gui::SelectionSingleton::slotSelectionChanged, this, bp::_1));
}
@@ -2171,19 +2193,41 @@ PyObject *SelectionSingleton::sClearSelection(PyObject * /*self*/, PyObject *arg
Py_Return;
}
namespace {
ResolveMode toEnum(int value) {
switch (value) {
case 0:
return ResolveMode::NoResolve;
case 1:
return ResolveMode::OldStyleElement;
case 2:
return ResolveMode::NewStyleElement;
case 3:
return ResolveMode::FollowLink;
default:
throw Base::ValueError("Wrong enum value");
}
}
}
PyObject *SelectionSingleton::sIsSelected(PyObject * /*self*/, PyObject *args)
{
PyObject *object;
char* subname = nullptr;
PyObject *resolve = Py_True;
if (!PyArg_ParseTuple(args, "O!|sO!", &(App::DocumentObjectPy::Type), &object,
&subname, &PyBool_Type, &resolve))
int resolve = 1;
if (!PyArg_ParseTuple(args, "O!|si", &(App::DocumentObjectPy::Type), &object, &subname, &resolve))
return nullptr;
App::DocumentObjectPy* docObj = static_cast<App::DocumentObjectPy*>(object);
bool ok = Selection().isSelected(docObj->getDocumentObjectPtr(), subname,PyObject_IsTrue(resolve));
try {
App::DocumentObjectPy* docObj = static_cast<App::DocumentObjectPy*>(object);
bool ok = Selection().isSelected(docObj->getDocumentObjectPtr(), subname, toEnum(resolve));
return Py_BuildValue("O", (ok ? Py_True : Py_False));
return Py_BuildValue("O", (ok ? Py_True : Py_False));
}
catch (const Base::Exception& e) {
e.setPyException();
return nullptr;
}
}
PyObject *SelectionSingleton::sCountObjectsOfType(PyObject * /*self*/, PyObject *args)
@@ -2194,9 +2238,14 @@ PyObject *SelectionSingleton::sCountObjectsOfType(PyObject * /*self*/, PyObject
if (!PyArg_ParseTuple(args, "s|si", &objecttype, &document,&resolve))
return nullptr;
unsigned int count = Selection().countObjectsOfType(objecttype, document, resolve);
return PyLong_FromLong(count);
try {
unsigned int count = Selection().countObjectsOfType(objecttype, document, toEnum(resolve));
return PyLong_FromLong(count);
}
catch (const Base::Exception& e) {
e.setPyException();
return nullptr;
}
}
PyObject *SelectionSingleton::sGetSelection(PyObject * /*self*/, PyObject *args)
@@ -2207,10 +2256,10 @@ PyObject *SelectionSingleton::sGetSelection(PyObject * /*self*/, PyObject *args)
if (!PyArg_ParseTuple(args, "|siO!", &documentName, &resolve, &PyBool_Type, &single))
return nullptr;
std::vector<SelectionSingleton::SelObj> sel;
sel = Selection().getSelection(documentName,resolve,PyObject_IsTrue(single));
try {
std::vector<SelectionSingleton::SelObj> sel;
sel = Selection().getSelection(documentName, toEnum(resolve), PyObject_IsTrue(single));
std::set<App::DocumentObject*> noduplicates;
std::vector<App::DocumentObject*> selectedObjects; // keep the order of selection
Py::List list;
@@ -2224,6 +2273,10 @@ PyObject *SelectionSingleton::sGetSelection(PyObject * /*self*/, PyObject *args)
}
return Py::new_reference_to(list);
}
catch (const Base::Exception& e) {
e.setPyException();
return nullptr;
}
catch (Py::Exception&) {
return nullptr;
}
@@ -2294,16 +2347,20 @@ PyObject *SelectionSingleton::sGetCompleteSelection(PyObject * /*self*/, PyObjec
if (!PyArg_ParseTuple(args, "|i",&resolve))
return nullptr;
std::vector<SelectionSingleton::SelObj> sel;
sel = Selection().getCompleteSelection(resolve);
try {
std::vector<SelectionSingleton::SelObj> sel;
sel = Selection().getCompleteSelection(toEnum(resolve));
Py::List list;
for (std::vector<SelectionSingleton::SelObj>::iterator it = sel.begin(); it != sel.end(); ++it) {
list.append(Py::asObject(it->pObject->getPyObject()));
}
return Py::new_reference_to(list);
}
catch (const Base::Exception& e) {
e.setPyException();
return nullptr;
}
catch (Py::Exception&) {
return nullptr;
}
@@ -2317,17 +2374,21 @@ PyObject *SelectionSingleton::sGetSelectionEx(PyObject * /*self*/, PyObject *arg
if (!PyArg_ParseTuple(args, "|siO!", &documentName, &resolve, &PyBool_Type, &single))
return nullptr;
std::vector<SelectionObject> sel;
sel = Selection().getSelectionEx(documentName,
App::DocumentObject::getClassTypeId(),resolve,PyObject_IsTrue(single));
try {
std::vector<SelectionObject> sel;
sel = Selection().getSelectionEx(documentName,
App::DocumentObject::getClassTypeId(), toEnum(resolve), PyObject_IsTrue(single));
Py::List list;
for (std::vector<SelectionObject>::iterator it = sel.begin(); it != sel.end(); ++it) {
list.append(Py::asObject(it->getPyObject()));
}
return Py::new_reference_to(list);
}
catch (const Base::Exception& e) {
e.setPyException();
return nullptr;
}
catch (Py::Exception&) {
return nullptr;
}
@@ -2396,7 +2457,7 @@ PyObject *SelectionSingleton::sAddSelObserver(PyObject * /*self*/, PyObject *arg
return nullptr;
PY_TRY {
SelectionObserverPython::addObserver(Py::Object(o),resolve);
SelectionObserverPython::addObserver(Py::Object(o), toEnum(resolve));
Py_Return;
}
PY_CATCH;
@@ -2421,7 +2482,7 @@ PyObject *SelectionSingleton::sAddSelectionGate(PyObject * /*self*/, PyObject *a
int resolve = 1;
if (PyArg_ParseTuple(args, "s|i", &filter, &resolve)) {
PY_TRY {
Selection().addSelectionGate(new SelectionFilterGate(filter),resolve);
Selection().addSelectionGate(new SelectionFilterGate(filter), toEnum(resolve));
Py_Return;
}
PY_CATCH;
@@ -2432,7 +2493,7 @@ PyObject *SelectionSingleton::sAddSelectionGate(PyObject * /*self*/, PyObject *a
if (PyArg_ParseTuple(args, "O!|i",SelectionFilterPy::type_object(),&filterPy,resolve)) {
PY_TRY {
Selection().addSelectionGate(new SelectionFilterGatePython(
static_cast<SelectionFilterPy*>(filterPy)),resolve);
static_cast<SelectionFilterPy*>(filterPy)), toEnum(resolve));
Py_Return;
}
PY_CATCH;
@@ -2442,7 +2503,7 @@ PyObject *SelectionSingleton::sAddSelectionGate(PyObject * /*self*/, PyObject *a
PyObject* gate;
if (PyArg_ParseTuple(args, "O|i",&gate,&resolve)) {
PY_TRY {
Selection().addSelectionGate(new SelectionGatePython(Py::Object(gate, false)),resolve);
Selection().addSelectionGate(new SelectionGatePython(Py::Object(gate, false)), toEnum(resolve));
Py_Return;
}
PY_CATCH;
@@ -2505,14 +2566,14 @@ PyObject *SelectionSingleton::sPushSelStack(PyObject * /*self*/, PyObject *args)
PyObject *SelectionSingleton::sHasSelection(PyObject * /*self*/, PyObject *args)
{
const char *doc = nullptr;
PyObject *resolve = Py_False;
if (!PyArg_ParseTuple(args, "|sO!", &doc, &PyBool_Type, &resolve))
int resolve = 0;
if (!PyArg_ParseTuple(args, "|sO!", &doc, &resolve))
return nullptr;
PY_TRY {
bool ret;
if(doc || PyObject_IsTrue(resolve))
ret = Selection().hasSelection(doc,PyObject_IsTrue(resolve));
if (doc || resolve > 0)
ret = Selection().hasSelection(doc, toEnum(resolve));
else
ret = Selection().hasSelection();
@@ -2545,7 +2606,7 @@ PyObject *SelectionSingleton::sGetSelectionFromStack(PyObject * /*self*/, PyObje
PY_TRY {
Py::List list;
for(auto &sel : Selection().selStackGet(documentName, resolve, index))
for(auto &sel : Selection().selStackGet(documentName, toEnum(resolve), index))
list.append(Py::asObject(sel.getPyObject()));
return Py::new_reference_to(list);
}
+32 -25
View File
@@ -47,8 +47,15 @@ namespace App
namespace Gui
{
class SelectionObject;
class SelectionFilter;
enum class ResolveMode {
NoResolve,
OldStyleElement,
NewStyleElement,
FollowLink
};
class SelectionObject;
class SelectionFilter;
/** Transport the changes of the Selection
* This class transports closer information what was changed in the
@@ -213,7 +220,7 @@ public:
* 1 resolve sub-object with old style element name
* 2 resolve sub-object with new style element name
*/
SelectionObserver(bool attach = true, int resolve = 1);
SelectionObserver(bool attach = true, ResolveMode resolve = ResolveMode::OldStyleElement);
/** Constructor
*
* @param vp: filtering view object.
@@ -226,7 +233,7 @@ public:
* Constructs an selection observer that receives only selection event of
* objects within the same document as the input view object.
*/
SelectionObserver(const Gui::ViewProviderDocumentObject *vp, bool attach=true, int resolve=1);
SelectionObserver(const Gui::ViewProviderDocumentObject *vp, bool attach=true, ResolveMode resolve = ResolveMode::OldStyleElement);
virtual ~SelectionObserver();
bool blockSelection(bool block);
@@ -247,7 +254,7 @@ private:
Connection connectSelection;
std::string filterDocName;
std::string filterObjName;
int resolve;
ResolveMode resolve;
bool blockedSelection;
};
@@ -263,10 +270,10 @@ class GuiExport SelectionObserverPython : public SelectionObserver
public:
/// Constructor
SelectionObserverPython(const Py::Object& obj, int resolve=1);
SelectionObserverPython(const Py::Object& obj, ResolveMode resolve = ResolveMode::OldStyleElement);
virtual ~SelectionObserverPython();
static void addObserver(const Py::Object& obj, int resolve=1);
static void addObserver(const Py::Object& obj, ResolveMode resolve = ResolveMode::OldStyleElement);
static void removeObserver(const Py::Object& obj);
private:
@@ -387,9 +394,9 @@ public:
void clearCompleteSelection(bool clearPreSelect=true);
/// Check if selected
bool isSelected(const char* pDocName, const char* pObjectName=nullptr,
const char* pSubName=nullptr, int resolve=1) const;
const char* pSubName=nullptr, ResolveMode resolve = ResolveMode::OldStyleElement) const;
/// Check if selected
bool isSelected(App::DocumentObject*, const char* pSubName=nullptr, int resolve=1) const;
bool isSelected(App::DocumentObject*, const char* pSubName=nullptr, ResolveMode resolve = ResolveMode::OldStyleElement) const;
const char *getSelectedElement(App::DocumentObject*, const char* pSubName) const;
@@ -403,7 +410,7 @@ public:
/// returns the present preselection
const SelectionChanges& getPreselection(void) const;
/// add a SelectionGate to control what is selectable
void addSelectionGate(Gui::SelectionGate *gate, int resolve = 1);
void addSelectionGate(Gui::SelectionGate *gate, ResolveMode resolve = ResolveMode::OldStyleElement);
/// remove the active SelectionGate
void rmvSelectionGate(void);
@@ -420,14 +427,14 @@ public:
* field
*/
unsigned int countObjectsOfType(const Base::Type& typeId=App::DocumentObject::getClassTypeId(),
const char* pDocName=nullptr, int resolve=1) const;
const char* pDocName=nullptr, ResolveMode resolve = ResolveMode::OldStyleElement) const;
/**
* Does basically the same as the method above unless that it accepts a string literal as first argument.
* \a typeName must be a registered type, otherwise 0 is returned.
*/
unsigned int countObjectsOfType(const char* typeName,
const char* pDocName=nullptr, int resolve=1) const;
const char* pDocName=nullptr, ResolveMode resolve = ResolveMode::OldStyleElement) const;
/** Returns a vector of objects of type \a TypeName selected for the given document name \a pDocName.
* If no document name is specified the objects from the active document are regarded.
@@ -435,19 +442,19 @@ public:
* @note The vector reflects the sequence of selection.
*/
std::vector<App::DocumentObject*> getObjectsOfType(const Base::Type& typeId,
const char* pDocName=nullptr, int resolve=1) const;
const char* pDocName=nullptr, ResolveMode resolve = ResolveMode::OldStyleElement) const;
/**
* Does basically the same as the method above unless that it accepts a string literal as first argument.
* \a typeName must be a registered type otherwise an empty array is returned.
*/
std::vector<App::DocumentObject*> getObjectsOfType(const char* typeName,
const char* pDocName=nullptr, int resolve=1) const;
const char* pDocName=nullptr, ResolveMode resolve = ResolveMode::OldStyleElement) const;
/**
* A convenience template-based method that returns an array with the correct types already.
*/
template<typename T> inline std::vector<T*> getObjectsOfType(
const char* pDocName=nullptr, int resolve=1) const;
const char* pDocName=nullptr, ResolveMode resolve = ResolveMode::OldStyleElement) const;
/// Visible state used by setVisible()
enum VisibleState {
@@ -488,7 +495,7 @@ public:
*
* @return The returned vector reflects the sequence of selection.
*/
std::vector<SelObj> getSelection(const char* pDocName=nullptr, int resolve=1, bool single=false) const;
std::vector<SelObj> getSelection(const char* pDocName=nullptr, ResolveMode resolve = ResolveMode::OldStyleElement, bool single=false) const;
/** Returns a vector of selection objects
*
* @param pDocName: document name. If no document name is given the objects
@@ -506,7 +513,7 @@ public:
* @return The returned vector reflects the sequence of selection.
*/
std::vector<Gui::SelectionObject> getSelectionEx(const char* pDocName=nullptr,
Base::Type typeId=App::DocumentObject::getClassTypeId(),int resolve=1, bool single=false) const;
Base::Type typeId=App::DocumentObject::getClassTypeId(), ResolveMode resolve = ResolveMode::OldStyleElement, bool single=false) const;
/**
* @brief getAsPropertyLinkSubList fills PropertyLinkSubList with current selection.
@@ -516,7 +523,7 @@ public:
int getAsPropertyLinkSubList(App::PropertyLinkSubList &prop) const;
/** Returns a vector of all selection objects of all documents. */
std::vector<SelObj> getCompleteSelection(int resolve=1) const;
std::vector<SelObj> getCompleteSelection(ResolveMode resolve = ResolveMode::OldStyleElement) const;
/// Check if there is any selection
bool hasSelection() const;
@@ -533,7 +540,7 @@ public:
* If \c resolve is false, then the match is only done with the top
* level parent object.
*/
bool hasSelection(const char* doc, bool resolve=true) const;
bool hasSelection(const char* doc, ResolveMode resolve = ResolveMode::OldStyleElement) const;
/** Check if there is any sub-element selection
*
@@ -576,7 +583,7 @@ public:
* 2 resolve sub-object with new style element name
* @param index: optional position in the stack
*/
std::vector<Gui::SelectionObject> selStackGet(const char* pDocName=nullptr,int resolve=1,int index=0) const;
std::vector<Gui::SelectionObject> selStackGet(const char* pDocName=nullptr, ResolveMode resolve = ResolveMode::OldStyleElement, int index=0) const;
/** Go back selection history
*
@@ -708,12 +715,12 @@ protected:
std::deque<SelStackItem> _SelStackForward;
int checkSelection(const char *pDocName, const char *pObjectName,
const char *pSubName,int resolve, _SelObj &sel, const std::list<_SelObj> *selList=nullptr) const;
const char *pSubName, ResolveMode resolve, _SelObj &sel, const std::list<_SelObj> *selList=nullptr) const;
std::vector<Gui::SelectionObject> getObjectList(const char* pDocName,Base::Type typeId, std::list<_SelObj> &objs, int resolve, bool single=false) const;
std::vector<Gui::SelectionObject> getObjectList(const char* pDocName,Base::Type typeId, std::list<_SelObj> &objs, ResolveMode resolve, bool single=false) const;
static App::DocumentObject *getObjectOfType(_SelObj &sel, Base::Type type,
int resolve, const char **subelement=nullptr);
ResolveMode resolve, const char **subelement=nullptr);
static SelectionSingleton* _pcSingleton;
@@ -723,7 +730,7 @@ protected:
float hx,hy,hz;
Gui::SelectionGate *ActiveGate;
int gateResolve;
ResolveMode gateResolve;
int logDisabled = 0;
bool logHasSelection = false;
@@ -733,7 +740,7 @@ protected:
* A convenience template-based method that returns an array with the correct types already.
*/
template<typename T>
inline std::vector<T*> SelectionSingleton::getObjectsOfType(const char* pDocName, int resolve) const
inline std::vector<T*> SelectionSingleton::getObjectsOfType(const char* pDocName, ResolveMode resolve) const
{
std::vector<T*> type;
std::vector<App::DocumentObject*> obj = this->getObjectsOfType(T::getClassTypeId(), pDocName, resolve);
+6 -6
View File
@@ -54,7 +54,7 @@ using namespace Gui::DockWnd;
SelectionView::SelectionView(Gui::Document* pcDocument, QWidget *parent)
: DockWindow(pcDocument,parent)
, SelectionObserver(true,0)
, SelectionObserver(true, ResolveMode::NoResolve)
, x(0.0f), y(0.0f), z(0.0f)
, openedAutomatically(false)
{
@@ -201,7 +201,7 @@ void SelectionView::onSelectionChanged(const SelectionChanges &Reason)
else if (Reason.Type == SelectionChanges::SetSelection) {
// remove all items
selectionView->clear();
std::vector<SelectionSingleton::SelObj> objs = Gui::Selection().getSelection(Reason.pDocName,0);
std::vector<SelectionSingleton::SelObj> objs = Gui::Selection().getSelection(Reason.pDocName, ResolveMode::NoResolve);
for (std::vector<SelectionSingleton::SelObj>::iterator it = objs.begin(); it != objs.end(); ++it) {
// save as user data
QStringList list;
@@ -360,12 +360,12 @@ void SelectionView::deselect(void)
void SelectionView::toggleSelect(QListWidgetItem* item)
{
if (!item)
if (!item)
return;
std::string name = item->text().toLatin1().constData();
char *docname = &name.at(0);
char *objname = std::strchr(docname,'#');
if(!objname)
if(!objname)
return;
*objname++ = 0;
char *subname = std::strchr(objname,'.');
@@ -400,12 +400,12 @@ void SelectionView::toggleSelect(QListWidgetItem* item)
void SelectionView::preselect(QListWidgetItem* item)
{
if (!item)
if (!item)
return;
std::string name = item->text().toLatin1().constData();
char *docname = &name.at(0);
char *objname = std::strchr(docname,'#');
if(!objname)
if(!objname)
return;
*objname++ = 0;
char *subname = std::strchr(objname,'.');
+11 -11
View File
@@ -204,7 +204,7 @@ void SoFCUnifiedSelection::write(SoWriteAction * action)
SoOutput * out = action->getOutput();
if (out->getStage() == SoOutput::WRITE) {
// Do not write out the fields of this class
if (this->writeHeader(out, true, false))
if (this->writeHeader(out, true, false))
return;
SoGroup::doAction((SoAction *)action);
this->writeFooter(out);
@@ -217,13 +217,13 @@ void SoFCUnifiedSelection::write(SoWriteAction * action)
int SoFCUnifiedSelection::getPriority(const SoPickedPoint* p)
{
const SoDetail* detail = p->getDetail();
if (!detail)
if (!detail)
return 0;
if (detail->isOfType(SoFaceDetail::getClassTypeId()))
if (detail->isOfType(SoFaceDetail::getClassTypeId()))
return 1;
if (detail->isOfType(SoLineDetail::getClassTypeId()))
if (detail->isOfType(SoLineDetail::getClassTypeId()))
return 2;
if (detail->isOfType(SoPointDetail::getClassTypeId()))
if (detail->isOfType(SoPointDetail::getClassTypeId()))
return 3;
return 0;
}
@@ -268,7 +268,7 @@ SoFCUnifiedSelection::getPickedList(SoHandleEventAction* action, bool singlePick
ret.push_back(info);
}
if(ret.size()<=1)
if(ret.size()<=1)
return ret;
// To identify the picking of lines in a concave area we have to
@@ -540,7 +540,7 @@ bool SoFCUnifiedSelection::setHighlight(SoFullPath *path, const SoDetail *det,
}
bool SoFCUnifiedSelection::setSelection(const std::vector<PickedInfo> &infos, bool ctrlDown) {
if(infos.empty() || !infos[0].vpd)
if(infos.empty() || !infos[0].vpd)
return false;
std::vector<SelectionSingleton::SelObj> sels;
@@ -566,10 +566,10 @@ bool SoFCUnifiedSelection::setSelection(const std::vector<PickedInfo> &infos, bo
const auto &info = infos[0];
auto vpd = info.vpd;
if(!vpd)
if(!vpd)
return false;
const char *objname = vpd->getObject()->getNameInDocument();
if(!objname)
if(!objname)
return false;
const char *docname = vpd->getObject()->getDocument()->getName();
@@ -584,8 +584,8 @@ bool SoFCUnifiedSelection::setSelection(const std::vector<PickedInfo> &infos, bo
static char buf[513];
if (ctrlDown) {
if(Gui::Selection().isSelected(docname,objname,info.element.c_str(),0))
Gui::Selection().rmvSelection(docname,objname,info.element.c_str(),&sels);
if(Gui::Selection().isSelected(docname, objname, info.element.c_str(), ResolveMode::NoResolve))
Gui::Selection().rmvSelection(docname, objname,info.element.c_str(), &sels);
else {
bool ok = Gui::Selection().addSelection(docname,objname,
info.element.c_str(), pt[0] ,pt[1] ,pt[2], &sels);
+5 -5
View File
@@ -271,12 +271,12 @@ public:
}
void onSelectionChanged() {
if(busy)
if(busy)
return;
busy = true;
std::map<std::string,int> sels;
for(auto &sel : Selection().getSelectionEx(
editDoc.c_str(),App::DocumentObject::getClassTypeId(),0))
editDoc.c_str(),App::DocumentObject::getClassTypeId(), ResolveMode::NoResolve))
{
if(sel.getFeatName()!=editObj) continue;
for(auto &sub : sel.getSubNames()) {
@@ -324,7 +324,7 @@ ElementColors::ElementColors(ViewProviderDocumentObject* vp, bool noHide)
if(d->ui->onTop->isChecked())
d->vpParent->OnTopWhenSelected.setValue(3);
Selection().addSelectionGate(d,0);
Selection().addSelectionGate(d, ResolveMode::NoResolve);
d->connectDelDoc = Application::Instance->signalDeleteDocument.connect(boost::bind
(&ElementColors::slotDeleteDocument, this, bp::_1));
@@ -379,7 +379,7 @@ void ElementColors::on_boxSelect_clicked()
}
void ElementColors::on_hideSelection_clicked() {
auto sels = Selection().getSelectionEx(d->editDoc.c_str(),App::DocumentObject::getClassTypeId(),0);
auto sels = Selection().getSelectionEx(d->editDoc.c_str(), App::DocumentObject::getClassTypeId(), ResolveMode::NoResolve);
for(auto &sel : sels) {
if(d->editObj!=sel.getFeatName())
continue;
@@ -400,7 +400,7 @@ void ElementColors::on_hideSelection_clicked() {
void ElementColors::on_addSelection_clicked()
{
auto sels = Selection().getSelectionEx(d->editDoc.c_str(),App::DocumentObject::getClassTypeId(),0);
auto sels = Selection().getSelectionEx(d->editDoc.c_str(), App::DocumentObject::getClassTypeId(), ResolveMode::NoResolve);
d->items.clear();
if(sels.empty())
d->addItem(-1,"Face",true);
+16 -12
View File
@@ -429,9 +429,13 @@ QWidget* TreeWidgetEditDelegate::createEditor(
// ---------------------------------------------------------------------------
TreeWidget::TreeWidget(const char* name, QWidget* parent)
: QTreeWidget(parent), SelectionObserver(true, 0), contextItem(nullptr)
, searchObject(nullptr), searchDoc(nullptr), searchContextDoc(nullptr)
, editingItem(nullptr), currentDocItem(nullptr)
: QTreeWidget(parent), SelectionObserver(true, ResolveMode::NoResolve)
, contextItem(nullptr)
, searchObject(nullptr)
, searchDoc(nullptr)
, searchContextDoc(nullptr)
, editingItem(nullptr)
, currentDocItem(nullptr)
, myName(name)
{
Instances.insert(this);
@@ -1060,7 +1064,7 @@ void TreeWidget::onFinishEditing()
DocumentObjectItem* objitem = static_cast<DocumentObjectItem*>
(this->contextItem);
App::DocumentObject* obj = objitem->object()->getObject();
if (!obj)
if (!obj)
return;
Gui::Document* doc = Gui::Application::Instance->getDocument(obj->getDocument());
doc->commitCommand();
@@ -1239,7 +1243,7 @@ std::vector<TreeWidget::SelInfo> TreeWidget::getSelection(App::Document* doc)
break;
}
}
if (!tree)
if (!tree)
return ret;
if (tree->selectTimer->isActive())
@@ -1440,14 +1444,14 @@ void TreeWidget::keyPressEvent(QKeyEvent* event)
void TreeWidget::mouseDoubleClickEvent(QMouseEvent* event)
{
QTreeWidgetItem* item = itemAt(event->pos());
if (!item)
if (!item)
return;
try {
if (item->type() == TreeWidget::DocumentType) {
//QTreeWidget::mouseDoubleClickEvent(event);
Gui::Document* doc = static_cast<DocumentItem*>(item)->document();
if (!doc)
if (!doc)
return;
if (doc->getDocument()->testStatus(App::Document::PartialDoc)) {
contextItem = item;
@@ -2752,7 +2756,7 @@ void TreeWidget::scrollItemToTop()
tree->_updateStatus(false);
if (doc && Gui::Selection().hasSelection(doc->getDocument()->getName(), false)) {
if (doc && Gui::Selection().hasSelection(doc->getDocument()->getName(), ResolveMode::NoResolve)) {
auto it = tree->DocumentMap.find(doc);
if (it != tree->DocumentMap.end()) {
bool lock = tree->blockSelection(true);
@@ -2871,7 +2875,7 @@ void TreeWidget::syncView(ViewProviderDocumentObject* vp)
void TreeWidget::onShowHidden()
{
if (!this->contextItem)
if (!this->contextItem)
return;
DocumentItem* docItem = nullptr;
if (this->contextItem->type() == DocumentType)
@@ -4149,7 +4153,7 @@ void DocumentItem::updateSelection(QTreeWidgetItem* ti, bool unselect) {
}
}
if (unselect)
if (unselect)
return;
for (int i = 0, count = ti->childCount(); i < count; ++i)
updateSelection(ti->child(i));
@@ -4419,7 +4423,7 @@ DocumentObjectItem* DocumentItem::findItem(
}
void DocumentItem::selectItems(SelectionReason reason) {
const auto& sels = Selection().getSelection(pDocument->getDocument()->getName(), false);
const auto& sels = Selection().getSelection(pDocument->getDocument()->getName(), ResolveMode::NoResolve);
bool sync = (sels.size() > 50 || reason == SR_SELECT) ? false : true;
@@ -4475,7 +4479,7 @@ void DocumentItem::selectItems(SelectionReason reason) {
void DocumentItem::populateParents(const ViewProvider* vp, ViewParentMap& parentMap) {
auto it = parentMap.find(vp);
if (it == parentMap.end())
if (it == parentMap.end())
return;
for (auto parent : it->second) {
auto it = ObjectMap.find(parent->getObject());
+28 -10
View File
@@ -293,19 +293,37 @@ public:
// *************************************************************************
View3DInventorViewer::View3DInventorViewer(QWidget* parent, const QtGLWidget* sharewidget)
: Quarter::SoQTQuarterAdaptor(parent, sharewidget), SelectionObserver(false,0),
editViewProvider(nullptr), navigation(nullptr),
renderType(Native), framebuffer(nullptr), axisCross(nullptr), axisGroup(nullptr), editing(false), redirected(false),
allowredir(false), overrideMode("As Is"), _viewerPy(nullptr)
: Quarter::SoQTQuarterAdaptor(parent, sharewidget)
, SelectionObserver(false, ResolveMode::NoResolve)
, editViewProvider(nullptr)
, navigation(nullptr)
, renderType(Native)
, framebuffer(nullptr)
, axisCross(nullptr)
, axisGroup(nullptr)
, editing(false)
, redirected(false)
, allowredir(false)
, overrideMode("As Is")
, _viewerPy(nullptr)
{
init();
}
View3DInventorViewer::View3DInventorViewer(const QtGLFormat& format, QWidget* parent, const QtGLWidget* sharewidget)
: Quarter::SoQTQuarterAdaptor(format, parent, sharewidget), SelectionObserver(false,0),
editViewProvider(nullptr), navigation(nullptr),
renderType(Native), framebuffer(nullptr), axisCross(nullptr), axisGroup(nullptr), editing(false), redirected(false),
allowredir(false), overrideMode("As Is"), _viewerPy(nullptr)
: Quarter::SoQTQuarterAdaptor(format, parent, sharewidget)
, SelectionObserver(false, ResolveMode::NoResolve)
, editViewProvider(nullptr)
, navigation(nullptr)
, renderType(Native)
, framebuffer(nullptr)
, axisCross(nullptr)
, axisGroup(nullptr)
, editing(false)
, redirected(false)
, allowredir(false)
, overrideMode("As Is")
, _viewerPy(nullptr)
{
init();
}
@@ -646,7 +664,7 @@ void View3DInventorViewer::setDocument(Gui::Document* pcDocument)
selectionRoot->pcDocument = pcDocument;
if(pcDocument) {
const auto &sels = Selection().getSelection(pcDocument->getDocument()->getName(),0);
const auto &sels = Selection().getSelection(pcDocument->getDocument()->getName(), ResolveMode::NoResolve);
for(auto &sel : sels) {
SelectionChanges Chng(SelectionChanges::ShowSelection,
sel.DocName,sel.FeatName,sel.SubName);
@@ -3058,7 +3076,7 @@ void View3DInventorViewer::viewAll(float factor)
void View3DInventorViewer::viewSelection()
{
Base::BoundBox3d bbox;
for(auto &sel : Selection().getSelection(nullptr,0)) {
for(auto &sel : Selection().getSelection(nullptr, ResolveMode::NoResolve)) {
auto vp = Application::Instance->getViewProvider(sel.pObject);
if(!vp)
continue;
+2 -2
View File
@@ -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);
+17 -17
View File
@@ -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());
}
+9 -5
View File
@@ -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();
+4 -4
View File
@@ -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)
{
+4 -4
View File
@@ -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();
+1 -1
View File
@@ -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)
{
+4 -4
View File
@@ -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,
+1 -2
View File
@@ -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;