MCPcopy Create free account
hub / github.com/codereader/DarkRadiant / importState

Method importState

libs/scene/SelectableNode.cpp:156–209  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

154}
155
156void SelectableNode::importState(const IUndoMementoPtr& state)
157{
158 undoSave();
159
160 // Process the incoming set difference
161 GroupIds newGroups = std::static_pointer_cast< undo::BasicUndoMemento<GroupIds> >(state)->data();
162
163 // The set_difference algorithm requires the sets to be sorted
164 std::sort(_groups.begin(), _groups.end());
165 std::sort(newGroups.begin(), newGroups.end());
166
167 GroupIds removedGroups;
168 std::set_difference(_groups.begin(), _groups.end(), newGroups.begin(), newGroups.end(),
169 std::inserter(removedGroups, removedGroups.begin()));
170
171 GroupIds addedGroups;
172 std::set_difference(newGroups.begin(), newGroups.end(), _groups.begin(), _groups.end(),
173 std::inserter(addedGroups, addedGroups.begin()));
174
175 auto rootNode = getRootNode();
176 if (!rootNode)
177 {
178 throw std::runtime_error("No root available, cannot import undo state for orphaned node.");
179 }
180
181 // Remove ourselves from each removed group ID
182 for (GroupIds::value_type id : removedGroups)
183 {
184 auto group = rootNode->getSelectionGroupManager().getSelectionGroup(id);
185
186 if (group)
187 {
188 group->removeNode(getSelf());
189 }
190 }
191
192 // Add ourselves to each missing group ID
193 for (GroupIds::value_type id : addedGroups)
194 {
195 auto group = rootNode->getSelectionGroupManager().findOrCreateSelectionGroup(id);
196
197 assert(group);
198 group->addNode(getSelf());
199 }
200
201 // The _groups array should now contain the same elements as the imported ones
202#if _DEBUG
203 std::sort(_groups.begin(), _groups.end());
204 assert(std::equal(_groups.begin(), _groups.end(), newGroups.begin()));
205#endif
206
207 // After undoing group assignments, highlight this node for better user feedback
208 setSelected(true, false);
209}
210
211void SelectableNode::onSelectionStatusChange(bool changeGroupStatus)
212{

Callers

nothing calls this directly

Calls 10

sortFunction · 0.85
equalFunction · 0.85
setSelectedFunction · 0.85
dataMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
getSelectionGroupMethod · 0.45
removeNodeMethod · 0.45
addNodeMethod · 0.45

Tested by

no test coverage detected