diff --git a/src/Gui/DAGView/DAGModel.cpp b/src/Gui/DAGView/DAGModel.cpp index 6bfec76745..e4bb87c1a5 100644 --- a/src/Gui/DAGView/DAGModel.cpp +++ b/src/Gui/DAGView/DAGModel.cpp @@ -150,6 +150,12 @@ Model::Model(QObject *parentIn, const Gui::Document &documentIn) : QGraphicsScen connectChgObject = documentIn.signalChangedObject.connect(boost::bind(&Model::slotChangeObject, this, _1, _2)); connectEdtObject = documentIn.signalInEdit.connect(boost::bind(&Model::slotInEdit, this, _1)); connectResObject = documentIn.signalResetEdit.connect(boost::bind(&Model::slotResetEdit, this, _1)); + + for (auto obj : documentIn.getDocument()->getObjects()) { + auto vpd = Base::freecad_dynamic_cast(documentIn.getViewProvider(obj)); + if (vpd) + slotNewObject(*vpd); + } } Model::~Model() diff --git a/src/Gui/DAGView/DAGView.cpp b/src/Gui/DAGView/DAGView.cpp index 5742f1e7ff..c4820b3560 100644 --- a/src/Gui/DAGView/DAGView.cpp +++ b/src/Gui/DAGView/DAGView.cpp @@ -69,6 +69,8 @@ View::~View() void View::slotActiveDocument(const Document &documentIn) { + if (Gui::Selection().hasSelection()) + return; ModelMap::const_iterator it = modelMap.find(&documentIn); if (it == modelMap.end()) { @@ -98,24 +100,31 @@ void View::awakeSlot() void View::onSelectionChanged(const SelectionChanges& msg) { - //dispatch to appropriate document. - ModelMap::iterator it; - for (auto it = modelMap.begin(); it != modelMap.end(); ++it) - { - if (std::string(it->first->getDocument()->getName()) == std::string(msg.pDocName)) - { - it->second->selectionChanged(msg); + switch(msg.Type) { + case SelectionChanges::AddSelection: + case SelectionChanges::RmvSelection: + case SelectionChanges::SetSelection: + if (!msg.pDocName || !msg.pDocName[0]) + return; + break; + case SelectionChanges::ClrSelection: + if (!msg.pDocName || !msg.pDocName[0]) { + for (auto &v : modelMap) { + v.second->selectionChanged(msg); + } return; } + break; + default: + return; } - - //FIXME: why am I getting a spontaneous event with an empty name? - //also getting events after the document has been removed from modelMap. - //just ignore for now. -// std::ostringstream stream; -// stream << std::endl << "couldn't find document of name: " << std::string(msg.pDocName) << std::endl << std::endl; -// Base::Console().Warning(stream.str().c_str()); -// assert(0); //no document of name. + auto doc = Gui::Application::Instance->getDocument(msg.pDocName); + if (!doc) return; + auto &model = modelMap[doc]; + if(!model) + model = std::make_shared(this, *doc); + this->setScene(model.get()); + model->selectionChanged(msg); }