24
#include "PreCompiled.h"
26
#include <App/Document.h>
27
#include <Gui/Application.h>
28
#include <Gui/Document.h>
29
#include <Gui/Selection.h>
30
#include <Gui/ViewProviderDocumentObject.h>
32
#include "ActiveObjectList.h"
33
#include "TreeParams.h"
36
FC_LOG_LEVEL_INIT("MDIView", true, true)
40
App::DocumentObject *ActiveObjectList::getObject(const ObjectInfo &info, bool resolve,
41
App::DocumentObject **parent,
42
std::string *subname) const
47
*subname = info.subname;
49
if (!obj || !obj->isAttachedToDocument())
51
if (!info.subname.empty()) {
52
obj = obj->getSubObject(info.subname.c_str());
57
return resolve ? obj->getLinkedObject(true) : obj;
60
void ActiveObjectList::setHighlight(const ObjectInfo &info, HighlightMode mode, bool enable)
62
auto obj = getObject(info, false);
65
auto vp = dynamic_cast<ViewProviderDocumentObject*>(Application::Instance->getViewProvider(obj));
69
if (TreeParams::getTreeActiveAutoExpand()) {
70
vp->getDocument()->signalExpandObject(*vp, enable ? TreeItemMode::ExpandPath : TreeItemMode::CollapseItem,
71
info.obj, info.subname.c_str());
74
vp->getDocument()->signalHighlightObject(*vp, mode, enable, info.obj, info.subname.c_str());
77
Gui::ActiveObjectList::ObjectInfo Gui::ActiveObjectList::getObjectInfo(App::DocumentObject *obj, const char *subname) const
81
if (!obj || !obj->isAttachedToDocument())
86
info.subname = subname;
92
auto sels = Gui::Selection().getSelection(_Doc->getDocument()->getName(), ResolveMode::NoResolve);
93
for (auto &sel : sels) {
94
if (sel.pObject == obj || sel.pObject->getLinkedObject(true)==obj) {
95
info.obj = sel.pObject;
99
for (auto dot=strchr(sel.SubName,'.');dot;dot=strchr(dot+1,'.')) {
100
std::string subname(sel.SubName,dot-sel.SubName+1);
101
auto sobj = sel.pObject->getSubObject(subname.c_str());
104
if (sobj == obj || sobj->getLinkedObject(true) == obj) {
105
info.obj = sel.pObject;
106
info.subname = subname;
117
unsigned long count = 0xffffffff;
118
for(auto &v : obj->getParents()) {
119
if(v.first->getDocument() != _Doc->getDocument())
124
unsigned long cnt = v.first->getSubObjectList(v.second.c_str()).size();
125
if(v.first->getLinkedObject(false) != v.first)
130
info.subname = v.second;
135
if (obj->getDocument()!=_Doc->getDocument())
145
bool Gui::ActiveObjectList::hasObject(App::DocumentObject *obj,
146
const char *name, const char *subname) const
148
auto it = _ObjectMap.find(name);
149
if (it == _ObjectMap.end())
151
auto info = getObjectInfo(obj, subname);
152
return info.obj == it->second.obj && info.subname == it->second.subname;
155
void Gui::ActiveObjectList::setObject(App::DocumentObject* obj, const char* name,
156
const char *subname, const Gui::HighlightMode& mode)
158
auto it = _ObjectMap.find(name);
159
if (it!=_ObjectMap.end()) {
160
setHighlight(it->second, mode, false);
161
_ObjectMap.erase(it);
167
auto info = getObjectInfo(obj,subname);
169
FC_ERR("Cannot set active object "
170
<< obj->getFullName() << '.' << (subname?subname:"")
171
<< " in document '" << _Doc->getDocument()->getName()
172
<< "'. Not found in current selection");
176
_ObjectMap[name] = info;
177
setHighlight(info, mode, true);
180
bool Gui::ActiveObjectList::hasObject(const char*name)const
182
return _ObjectMap.find(name) != _ObjectMap.end();
185
void ActiveObjectList::objectDeleted(const ViewProviderDocumentObject &vp)
188
for (auto it = _ObjectMap.begin(); it != _ObjectMap.end(); ++it) {
189
if (it->second.obj == vp.getObject()) {
190
_ObjectMap.erase(it);