| 223 | } |
| 224 | |
| 225 | void EraserTool::commit_erase() { |
| 226 | bool placedNewObject = false; |
| 227 | std::unordered_map<DrawingProgramLayerListItem*, std::vector<std::pair<CanvasComponentContainer::ObjInfoIterator, CanvasComponentContainer*>>> newObjectsToPlace; |
| 228 | |
| 229 | std::for_each(updatedComponents.begin(), updatedComponents.end(), [&](auto& compPair) { |
| 230 | compPair.second.splitComps = compPair.first->obj->get_comp().attempt_split(drawP); |
| 231 | }); |
| 232 | |
| 233 | std::erase_if(updatedComponents, [&] (auto& p) { |
| 234 | auto& [comp, oldData] = p; |
| 235 | comp->obj->set_object_update_lock(drawP, false); |
| 236 | if(!oldData.splitComps.empty()) { |
| 237 | for(CanvasComponentContainer* c : oldData.splitComps) |
| 238 | newObjectsToPlace[comp->obj->parentLayer].emplace_back(std::next(comp->obj->objInfo), c); |
| 239 | placedNewObject = true; |
| 240 | erasedComponents.emplace(comp); |
| 241 | comp->obj->get_comp().set_data_from(*oldData.copyData->obj); |
| 242 | return true; |
| 243 | } |
| 244 | return false; |
| 245 | }); |
| 246 | |
| 247 | drawP.world.send_reliable_multi_command_to_all([&]() { |
| 248 | bool firstPlacement = true; |
| 249 | for(auto& [layer, compMap] : newObjectsToPlace) { |
| 250 | layer->get_layer().components->sort_netobj_ordered_list_iterator_insert_list(layer->get_layer().components, compMap); |
| 251 | drawP.layerMan.add_many_components_to_layer(layer, compMap, firstPlacement); |
| 252 | firstPlacement = false; |
| 253 | } |
| 254 | bool objectsToErase = !erasedComponents.empty(); |
| 255 | if(objectsToErase) |
| 256 | drawP.layerMan.erase_component_container(erasedComponents, !placedNewObject); |
| 257 | bool first = !objectsToErase && !placedNewObject; |
| 258 | std::for_each(updatedComponents.begin(), updatedComponents.end(), [&](auto& compPair) { |
| 259 | auto& [comp, oldData] = compPair; |
| 260 | comp->obj->get_comp().simplify_paths(); |
| 261 | comp->obj->normalize_object_coordinates(); |
| 262 | }); |
| 263 | for(auto& [comp, oldData] : updatedComponents) { |
| 264 | comp->obj->commit_update(drawP); // commit_update_dont_invalidate_cache also works (it's faster), but might cause cache issues if the object changes significantly due to simplify_paths or normalize_object_coordinates |
| 265 | drawP.send_transforms_for({comp}); |
| 266 | comp->obj->send_comp_update(drawP, true); |
| 267 | if(first) { |
| 268 | first = false; |
| 269 | drawP.world.undo.push(std::make_unique<EditTransformCanvasComponentWorldUndoAction>(std::move(oldData.copyData->obj), oldData.copyData->coords, drawP.world.undo.get_undoid_from_netid(comp->obj.get_net_id()))); |
| 270 | } |
| 271 | else |
| 272 | drawP.world.undo.push_on_last(std::make_unique<EditTransformCanvasComponentWorldUndoAction>(std::move(oldData.copyData->obj), oldData.copyData->coords, drawP.world.undo.get_undoid_from_netid(comp->obj.get_net_id()))); |
| 273 | } |
| 274 | }); |
| 275 | erasedComponents.clear(); |
| 276 | updatedComponents.clear(); |
| 277 | } |
| 278 | |
| 279 | void EraserTool::switch_tool(DrawingProgramToolType newTool) { |
| 280 | commit_erase(); |
nothing calls this directly
no test coverage detected