Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_layer_utils.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2015 Dmitry Kazakov <dimula73@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
7#include "kis_layer_utils.h"
8
9#include <algorithm>
10
11#include <QUuid>
13#include <KoProperties.h>
14
15#include "kis_painter.h"
16#include "kis_image.h"
17#include "kis_node.h"
18#include "kis_layer.h"
19#include "kis_paint_layer.h"
20#include "kis_clone_layer.h"
21#include "kis_group_layer.h"
22#include "kis_selection.h"
23#include "kis_selection_mask.h"
25#include <kundo2command.h>
37#include "kis_projection_leaf.h"
39#include "kis_time_span.h"
40#include "kis_command_utils.h"
48#include "krita_utils.h"
53#include "kis_command_ids.h"
54#include "kis_image_config.h"
55#include "KisFutureUtils.h"
58#include "kis_transaction.h"
59
60namespace KisLayerUtils {
61
62namespace Private {
63 void refreshHiddenAreaAsync(KisImageSP image, KisNodeSP rootNode, const QRect &preparedArea, const QRect &extraUpdateRect);
64}
65
67 {
68 foreach (KisNodeSP node, mergedNodes) {
69
70 Q_FOREACH(KisNodeSP child, node->childNodes(QStringList("KisSelectionMask"), KoProperties())) {
71
72 KisSelectionMaskSP mask = qobject_cast<KisSelectionMask*>(child.data());
73 if (mask) {
74 selectionMasks.append(mask);
75 }
76 }
77 }
78 }
79
82 : image(_image),
83 storage(new SwitchFrameCommand::SharedStorage())
84 {
85 }
86
87 virtual ~MergeDownInfoBase() {}
88
90
92
94 KisPaintLayerSP rasterizedDstLayer; // is non-null when merging takes a rasterization path
95
97 QSet<int> frames;
98 bool pinnedToTimeline = false;
99 bool enableOnionSkins = false;
100
102
104 return qobject_cast<KisLayer*>(dstNode.data());
105 }
106 };
107
109 SplitAlphaToMaskInfo(KisImageSP _image, KisNodeSP _node, const QString& maskName)
110 : image(_image)
111 , node(_node)
112 , storage(new SwitchFrameCommand::SharedStorage())
113 {
115 mask = new KisTransparencyMask(image, maskName);
116 }
117
121 QSet<int> frames;
122
126
128 return mask;
129 }
130
132 return qobject_cast<KisLayer*>(node.data());
133 }
134
135 private:
137
138 };
139
142 KisLayerSP _prevLayer,
143 KisLayerSP _currLayer,
144 MergeFlags flags)
145 : MergeDownInfoBase(_image),
146 prevLayer(_prevLayer),
147 currLayer(_currLayer)
148 {
149 if (!flags.testFlag(SkipMergingFrames)) {
152 }
153
160 if (!frames.isEmpty() && !currLayer->isAnimated()) {
162 }
163
165
166 const KisPaintLayer *paintLayer = qobject_cast<KisPaintLayer*>(currLayer.data());
167 if (paintLayer) enableOnionSkins |= paintLayer->onionSkinEnabled();
168
169 paintLayer = qobject_cast<KisPaintLayer*>(prevLayer.data());
170 if (paintLayer) enableOnionSkins |= paintLayer->onionSkinEnabled();
171 }
172
175
177 KisNodeList mergedNodes;
178 mergedNodes << prevLayer;
179 mergedNodes << currLayer;
180 return mergedNodes;
181 }
182 };
183
186 : storage(new SwitchFrameCommand::SharedStorage())
187 , m_sourceNode(node)
188 , m_image(image)
189 , m_pinnedToTimeline(false)
190 {
192
194
197
199
200 KisColorizeMask *colorizeMask = dynamic_cast<KisColorizeMask*>(m_sourceNode.data());
201 if (colorizeMask) {
202 m_sourcePaintDevice = colorizeMask->coloringProjection();
203 const bool putBehind = colorizeMask->compositeOpId() == COMPOSITE_BEHIND;
204 if (putBehind) {
206 }
207
210
211 } else if (dynamic_cast<KisMask*>(m_sourceNode.data())) {
214 } else {
217 }
218
219 KisCloneLayer *cloneLayer = dynamic_cast<KisCloneLayer*>(m_sourceNode.data());
220 if (cloneLayer) {
222 } else if (m_sourcePaintDevice) {
223 KisPaintDeviceSP clone;
224
227
229 clone->setDefaultPixel(
232
233 QRect rc(m_sourcePaintDevice->extent());
234 KisPainter::copyAreaOptimized(rc.topLeft(), m_sourcePaintDevice, clone, rc);
235 } else {
237 }
238
242 clone);
243
245
246 if (sourceLayer() && targetLayer()) {
247 targetLayer()->disableAlphaChannel(sourceLayer()->alphaChannelDisabled());
248 }
249
252 }
253 }
254 }
255
256 QSet<int> frames() {
257 return m_frames;
258 }
259
261 return m_sourceNode;
262 }
263
265 return qobject_cast<KisLayer*>(m_sourceNode.data());
266 }
267
269 KisNodeList list;
270 list << m_sourceNode;
271 return list;
272 }
273
275 return qobject_cast<KisPaintLayer*>(m_sourceNode.data());
276 }
277
279 return m_targetNode != nullptr;
280 }
281
283 return m_targetNode;
284 }
285
287 return qobject_cast<KisLayer*>(m_targetNode.data());
288 }
289
291 return qobject_cast<KisPaintLayer*>(m_targetNode.data());
292 }
293
294
296 return m_image;
297 }
298
302
304 KisNodeList lst;
305 lst << m_sourceNode;
306 return lst;
307 }
308
312
314 return m_insertionParent;
315 }
316
318
319 private:
324 QSet<int> m_frames;
327
330 };
331
334 KisNodeList _mergedNodes,
335 MergeFlags flags)
336 : MergeDownInfoBase(_image),
337 mergedNodes(_mergedNodes)
338 {
339 foreach (KisNodeSP node, mergedNodes) {
340 if (!flags.testFlag(SkipMergingFrames)) {
342 }
344
345 const KisPaintLayer *paintLayer = qobject_cast<KisPaintLayer*>(node.data());
346 if (paintLayer) {
347 enableOnionSkins |= paintLayer->onionSkinEnabled();
348 }
349 }
350 }
351
352 QScopedPointer<KisSurrogateUndoStore> ephemeralCommandsStore;
355
357 return mergedNodes;
358 }
359 };
360
366
369
370 void redo() override {
371 fetchSelectionMasks(m_info->allSrcNodes(), m_info->selectionMasks);
372 }
373
374 private:
376 };
377
380
381 void populateChildCommands() override {
382 Q_FOREACH (KisNodeSP node, m_info->allSrcNodes()) {
384 [this] (KisNodeSP node) {
385 if (dynamic_cast<KisColorizeMask*>(node.data()) &&
387
388 KisBaseNode::PropertyList props = node->sectionModelProperties();
389 KisLayerPropertiesIcons::setNodeProperty(&props,
390 KisLayerPropertiesIcons::colorizeEditKeyStrokes,
391 false);
392
393 addCommand(new KisNodePropertyListCommand(node, props));
394 }
395 });
396 }
397 }
398
399 private:
401 };
402
405
406 void populateChildCommands() override {
407 Q_FOREACH (KisNodeSP node, m_info->allSrcNodes()) {
409 [this] (KisNodeSP node) {
411
415 false);
416
417 addCommand(new KisNodePropertyListCommand(node, props));
418 }
419 });
420 }
421 }
422
423 private:
425 };
426
429
430 void populateChildCommands() override {
436 if (m_info->nodesCompositingVaries) return;
437
438 // we should disable dirty requests on **redo only**, otherwise
439 // the state of the layers will not be recovered on undo
440 m_info->image->disableDirtyRequests();
441
442 Q_FOREACH (KisNodeSP node, m_info->allSrcNodes()) {
443 if (node->compositeOpId() != COMPOSITE_OVER) {
445 }
446
448
452 false);
453
454 addCommand(new KisNodePropertyListCommand(node, props));
455 }
456 }
457
458 m_info->image->enableDirtyRequests();
459 }
460
461 private:
463 };
464
466 DisablePassThroughForHeadsOnly(MergeDownInfoBaseSP info, bool skipIfDstIsGroup = false)
467 : m_info(info),
468 m_skipIfDstIsGroup(skipIfDstIsGroup)
469 {
470 }
471
472 void populateChildCommands() override {
473 if (m_skipIfDstIsGroup &&
474 m_info->dstLayer() &&
475 m_info->dstLayer()->inherits("KisGroupLayer")) {
476
477 return;
478 }
479
480
481 Q_FOREACH (KisNodeSP node, m_info->allSrcNodes()) {
483
487 false);
488
489 addCommand(new KisNodePropertyListCommand(node, props));
490 }
491 }
492 }
493
494 private:
497 };
498
502
503 RefreshHiddenAreas(MergeDownInfoBaseSP info) : m_image(info->image), m_nodes(info->allSrcNodes()) {}
504 RefreshHiddenAreas(MergeDownInfoBaseSP info, refresh_entire_image_t) : m_image(info->image), m_nodes(info->allSrcNodes()), m_extraUpdateRect(info->image->bounds()) {}
506 m_nodes << node;
507 }
508
509 void populateChildCommands() override {
510 KisImageAnimationInterface *interface = m_image->animationInterface();
511 const QRect preparedRect = !interface->externalFrameActive() ?
512 m_image->bounds() : QRect();
513
514 foreach (KisNodeSP node, m_nodes) {
516 }
517 }
518
519 private:
523 };
524
527 : m_nodes(info->allSrcNodes()) {}
528
530 m_nodes << nodes;
531 }
532
533 void redo() override {
534 if (m_info) {
535 m_nodes << m_info->allSrcNodes();
536 }
537
538 foreach (KisNodeSP node, m_nodes) {
540 }
541 }
542
543 private:
546 };
547
550 : m_singleInfo(info),
551 m_finalizing(finalizing) {}
552
554 : m_multipleInfo(info),
555 m_finalizing(finalizing),
556 m_putAfter(putAfter) {}
557
558 void populateChildCommands() override {
559 KisNodeSP prevNode;
560 KisNodeSP nextNode;
561 KisNodeList prevSelection;
562 KisNodeList nextSelection;
563 KisImageSP image;
564
565 if (m_singleInfo) {
566 prevNode = m_singleInfo->currLayer;
567 nextNode = m_singleInfo->dstNode;
568 image = m_singleInfo->image;
569 } else if (m_multipleInfo) {
570 prevNode = m_putAfter;
571 nextNode = m_multipleInfo->dstNode;
572 prevSelection = m_multipleInfo->allSrcNodes();
573 image = m_multipleInfo->image;
574 }
575
576 if (!m_finalizing) {
578 prevNode, KisNodeSP(),
579 image, false));
580 } else {
582 KisNodeSP(), nextNode,
583 image, true));
584 }
585 }
586
587 private:
592 };
593
596
597 void populateChildCommands() override {
598 // actual merging done by KisLayer::createMergedLayer (or specialized descendant)
599 m_info->dstNode = m_info->currLayer->createMergedLayerTemplate(m_info->prevLayer);
600
601 if (m_info->frames.size() > 0) {
602 m_info->dstNode->enableAnimation();
603 m_info->dstNode->getKeyframeChannel(KisKeyframeChannel::Raster.id(), true);
604 }
605
606 m_info->dstNode->setPinnedToTimeline(m_info->pinnedToTimeline);
607 m_info->dstNode->setColorLabelIndex(m_info->allSrcNodes().first()->colorLabelIndex());
608
609 KisPaintLayer *dstPaintLayer = qobject_cast<KisPaintLayer*>(m_info->dstNode.data());
610 if (dstPaintLayer) {
611 dstPaintLayer->setOnionSkinEnabled(m_info->enableOnionSkins);
612 }
613 }
614
615 private:
617 };
618
620 CreateMergedLayerMultiple(MergeMultipleInfoSP info, const QString name = QString() )
621 : m_info(info),
622 m_name(name) {}
623
624 void populateChildCommands() override {
625 QString mergedLayerName;
626 if (m_name.isEmpty()){
627 const QString mergedLayerSuffix = i18n("Merged");
628 mergedLayerName = m_info->mergedNodes.first()->name();
629
630 if (KisImageConfig(true).renameMergedLayers() && !mergedLayerName.endsWith(mergedLayerSuffix)) {
631 mergedLayerName = QString("%1 %2")
632 .arg(mergedLayerName).arg(mergedLayerSuffix);
633 }
634 } else {
635 mergedLayerName = m_name;
636 }
637
638 auto channelFlagsLazy = [](KisNodeSP node) {
639 KisLayer *layer = dynamic_cast<KisLayer*>(node.data());
640 return layer ? layer->channelFlags() : QBitArray();
641 };
642
643 QString compositeOpId;
644 QBitArray channelFlags;
645 bool compositionVaries = false;
646 bool isFirstCycle = true;
647
648 foreach (KisNodeSP node, m_info->allSrcNodes()) {
649 if (isFirstCycle) {
650 compositeOpId = node->compositeOpId();
651 channelFlags = channelFlagsLazy(node);
652 isFirstCycle = false;
653 } else if (compositeOpId != node->compositeOpId() ||
654 channelFlags != channelFlagsLazy(node)) {
655 compositionVaries = true;
656 break;
657 }
658
659 KisLayerSP layer = qobject_cast<KisLayer*>(node.data());
660 if (layer && layer->layerStyle()) {
661 compositionVaries = true;
662 break;
663 }
664 }
665
670 if (!compositionVaries && m_info->frames.isEmpty()) {
671 QList<KisLayerSP> layers;
672 Q_FOREACH(KisNodeSP node, m_info->allSrcNodes()) {
673 KisLayer *layer = dynamic_cast<KisLayer*>(node.data());
674 if (!layer) {
675 layers.clear();
676 break;
677 }
678 layers << layer;
679 }
680
681 if (!layers.isEmpty()) {
686 m_info->dstNode = layers.first()->tryCreateInternallyMergedLayerFromMutipleLayers(layers);
687 }
688 }
689
693 if (!m_info->dstNode) {
694 m_info->rasterizedDstLayer = new KisPaintLayer(m_info->image, mergedLayerName, OPACITY_OPAQUE_U8);
695 m_info->dstNode = m_info->rasterizedDstLayer;
696
697 if (m_info->frames.size() > 0) {
698 m_info->dstNode->enableAnimation();
699 m_info->dstNode->getKeyframeChannel(KisKeyframeChannel::Raster.id(), true);
700 }
701
702 if (!compositionVaries) {
703 if (!compositeOpId.isEmpty()) {
704 m_info->dstNode->setCompositeOpId(compositeOpId);
705 }
706 if (m_info->dstLayer() && !channelFlags.isEmpty()) {
707 m_info->dstLayer()->setChannelFlags(channelFlags);
708 }
709 }
710
711 m_info->dstNode->setPinnedToTimeline(m_info->pinnedToTimeline);
712 m_info->dstNode->setColorLabelIndex(m_info->allSrcNodes().first()->colorLabelIndex());
713
714 m_info->rasterizedDstLayer->setOnionSkinEnabled(m_info->enableOnionSkins);
715 }
716
717 m_info->nodesCompositingVaries = compositionVaries;
718 }
719
720 private:
722 QString m_name;
723 };
724
726 MergeLayers(MergeDownInfoSP info, bool skipMergingSourceLayer)
727 : m_info(info), m_skipMergingSourceLayer(skipMergingSourceLayer) {}
728
729 void populateChildCommands() override {
730 // actual merging done by KisLayer::createMergedLayer (or specialized descendant)
731 m_info->currLayer->fillMergedLayerTemplate(m_info->dstLayer(), m_info->prevLayer, m_skipMergingSourceLayer);
732 }
733
734 private:
737 };
738
741
742 void populateChildCommands() override {
743 if (!m_info->rasterizedDstLayer) return;
744
745 KisPainter gc(m_info->rasterizedDstLayer->paintDevice());
746
747 foreach (KisNodeSP node, m_info->allSrcNodes()) {
748 QRect rc = node->exactBounds() | m_info->image->bounds();
749 node->projectionPlane()->apply(&gc, rc);
750 }
751 }
752
753 private:
755 };
756
757 struct MergeMetaData : public KUndo2Command {
759 : m_info(info),
760 m_strategy(strategy) {}
761
762 void redo() override {
763 QRect layerProjectionExtent = m_info->currLayer->projection()->extent();
764 QRect prevLayerProjectionExtent = m_info->prevLayer->projection()->extent();
765 int prevLayerArea = prevLayerProjectionExtent.width() * prevLayerProjectionExtent.height();
766 int layerArea = layerProjectionExtent.width() * layerProjectionExtent.height();
767
768 QList<double> scores;
769 double norm = qMax(prevLayerArea, layerArea);
770 scores.append(prevLayerArea / norm);
771 scores.append(layerArea / norm);
772
774 srcs.append(m_info->prevLayer->metaData());
775 srcs.append(m_info->currLayer->metaData());
776 m_strategy->merge(m_info->dstLayer()->metaData(), srcs, scores);
777 }
778
779 private:
782 };
783
787
788 void populateChildCommands() override {
789 m_info->getMask()->initSelection(m_info->getLayer());
790 }
791
792 private:
794 };
795
800
801 void populateChildCommands() override {
802 KisPaintDeviceSP srcDevice = m_info->node->paintDevice();
803 const KoColorSpace *srcCS = srcDevice->colorSpace();
804 const QRect processRect =
805 srcDevice->exactBounds() |
806 srcDevice->defaultBounds()->bounds();
807
808 KisTransaction transaction(srcDevice);
809
810 KisSequentialIterator srcIt(srcDevice, processRect);
811 KisSequentialIterator dstIt(m_info->getMaskDevice(), processRect);
812
813 while (srcIt.nextPixel() && dstIt.nextPixel()) {
814 quint8 *srcPtr = srcIt.rawData();
815 quint8 *alpha8Ptr = dstIt.rawData();
816
817 *alpha8Ptr = srcCS->opacityU8(srcPtr);
818 srcCS->setOpacity(srcPtr, OPACITY_OPAQUE_U8, 1);
819 }
820
821 addCommand(transaction.endAndTake());
822 }
823
824 private:
826 };
827
830 : m_source(src)
832 , m_frame(frame)
833 {}
834
835 void populateChildCommands() override {
837 if (!channel)
838 return;
839
840
843 m_target->paintDevice()->framesInterface()->uploadFrame(key->frameID(), clone);
844 }
845
846 private:
850 };
851
853 const KisNodeList &selectedAfter,
854 KisNodeSP activeBefore,
855 KisNodeSP activeAfter,
856 KisImageSP image,
857 bool finalize, KUndo2Command *parent)
858 : FlipFlopCommand(finalize, parent),
859 m_selectedBefore(selectedBefore),
860 m_selectedAfter(selectedAfter),
861 m_activeBefore(activeBefore),
862 m_activeAfter(activeAfter),
863 m_image(image)
864 {
865 }
866
876
881
885
893
897
908 safeReplaceMultipleNodes(nodes, image, std::nullopt);
909 }
910
912 std::optional<ReplacementNode> replacementNode) {
913
914 const bool lastLayer = !replacementNode && scanForLastLayer(image, removedNodes);
915
916 auto isNodeWeird = [] (KisNodeSP node) {
917 const bool normalCompositeMode = node->compositeOpId() == COMPOSITE_OVER;
918
919 KisLayer *layer = dynamic_cast<KisLayer*>(node.data());
920 const bool hasInheritAlpha = layer && layer->alphaChannelDisabled();
921 return !normalCompositeMode && !hasInheritAlpha;
922 };
923
924
927 RecipeSP updateRecipe(new Recipe());
928
929 if (replacementNode) {
930 updateRecipe->nodesToAdd.push_back({replacementNode->node,
931 replacementNode->doRedoUpdates,
932 replacementNode->doUndoUpdates});
933 }
934
935 Q_FOREACH (KisNodeSP node, removedNodes) {
936 updateRecipe->nodesToRemove.push_back({node, !isNodeWeird(node), true});
937 }
938
940
941 if (replacementNode) {
943 replacementNode->node,
944 replacementNode->parent,
945 replacementNode->putAfter,
946 false, false));
947
948 Q_FOREACH (KisSelectionMaskSP mask, replacementNode->selectionMasks) {
949 addCommandImpl(new KisImageLayerMoveCommand(image, mask, replacementNode->node, replacementNode->node->lastChild(), false));
951 }
952
953 // relink all the clone layers onto the new replacement node
954 if (replacementNode->relinkClones) {
956
957 Q_FOREACH (KisNodeSP node, removedNodes) {
958 KisLayerSP originalSource = dynamic_cast<KisLayer*>(node.data());
959 if (originalSource) {
960 clones.append(originalSource->registeredClones());
961 }
962 }
963
964 KisLayerSP finalSource = dynamic_cast<KisLayer*>(replacementNode->node.data());
965
966 if (finalSource && !clones.isEmpty()) {
967 addCommandImpl(new KisChangeCloneLayersCommand(implicitCastList<KisCloneLayerSP>(clones), finalSource));
968 }
969 }
970 }
971
972 while (!removedNodes.isEmpty()) {
973 KisNodeList::iterator it = removedNodes.begin();
974
975 while (it != removedNodes.end()) {
976 if (!checkIsSourceForClone(*it, removedNodes)) {
977 KisNodeSP node = *it;
978
979 addCommandImpl(new KisImageLayerRemoveCommand(image, node, false, false));
980 it = removedNodes.erase(it);
981 } else {
982 ++it;
983 }
984 }
985 }
986
988
989 // Hint: we shouldn't include that into the batch update since this layer doesn't trigger any updates
990 if (lastLayer) {
991 KisLayerSP newLayer = new KisPaintLayer(image.data(), image->nextLayerName(), OPACITY_OPAQUE_U8, image->colorSpace());
992 addCommandImpl(new KisImageLayerAddCommand(image, newLayer,
993 image->root(),
994 KisNodeSP(),
995 false, false));
996 }
997 }
998
1000 foreach (KisNodeSP node, nodes) {
1001 if (node == src) continue;
1002
1003 KisCloneLayer *clone = dynamic_cast<KisCloneLayer*>(node.data());
1004
1005 if (clone && KisNodeSP(clone->copyFrom()) == src) {
1006 return true;
1007 }
1008 }
1009
1010 return false;
1011 }
1012
1014 bool removeLayers = false;
1015 Q_FOREACH(KisNodeSP nodeToRemove, nodesToRemove) {
1016 if (qobject_cast<KisLayer*>(nodeToRemove.data())) {
1017 removeLayers = true;
1018 break;
1019 }
1020 }
1021 if (!removeLayers) return false;
1022
1023 bool lastLayer = true;
1024 KisNodeSP node = image->root()->firstChild();
1025 while (node) {
1026 if (!nodesToRemove.contains(node) &&
1027 qobject_cast<KisLayer*>(node.data()) &&
1028 !node->isFakeNode()) {
1029
1030 lastLayer = false;
1031 break;
1032 }
1033 node = node->nextSibling();
1034 }
1035
1036 return lastLayer;
1037 }
1038
1040 KisImageSP image)
1041 : m_nodes(nodes),
1042 m_image(image)
1043 {
1044 }
1045
1050
1054
1057 : m_info(info), m_putAfter(putAfter) {}
1058
1059 void populateChildCommands() override {
1061 m_info->dstNode,
1062 m_putAfter->parent(),
1063 m_putAfter,
1064 true, false));
1065
1066 }
1067
1068 private:
1069 virtual void addCommandImpl(KUndo2Command *cmd) {
1070 addCommand(cmd);
1071 }
1072
1075 };
1076
1078 SimpleAddNode(KisImageSP image, KisNodeSP toAdd, KisNodeSP parent = 0, KisNodeSP putAfter = 0)
1079 : m_image(image)
1080 , m_toAdd(toAdd)
1081 , m_parent(parent)
1082 , m_putAfter(putAfter)
1083 {
1084 while (m_parent && !m_parent->allowAsChild(m_toAdd)) {
1087 }
1088
1089 if (!m_parent) {
1090 m_parent = m_image->root();
1091 }
1092 }
1093
1094
1095 void populateChildCommands() override {
1097 m_toAdd,
1098 m_parent,
1099 m_putAfter,
1100 true, false));
1101 }
1102
1103 private:
1104 virtual void addCommandImpl(KUndo2Command *cmd) {
1105 addCommand(cmd);
1106 }
1107
1112
1113 };
1114
1115
1116 void splitNonRemovableNodes(KisNodeList &nodesToRemove, KisNodeList &_nodesToHide)
1117 {
1118 QSet<KisNodeSP> nodesToHide;
1119 QSet<KisNodeSP> extraNodesToRemove;
1120
1121 for (auto it = nodesToRemove.begin(); it != nodesToRemove.end(); ++it) {
1122 KisNodeSP root = *it;
1124
1125 if (!root->isEditable(false)) {
1126 nodesToHide.insert(root);
1127 } else {
1128 bool rootNeedsCarefulRemoval = false;
1129
1131 [root, &nodesToHide, &rootNeedsCarefulRemoval] (KisNodeSP node) {
1132 if (!node->isEditable(false)) {
1133 while (node != root) {
1134 nodesToHide.insert(node);
1135 node = node->parent();
1136 KIS_SAFE_ASSERT_RECOVER_BREAK(node);
1137 }
1138 nodesToHide.insert(root);
1139 rootNeedsCarefulRemoval = true;
1140 }
1141 });
1142
1143 if (rootNeedsCarefulRemoval) {
1145 [&extraNodesToRemove] (KisNodeSP node) {
1146 extraNodesToRemove.insert(node);
1147 });
1148 }
1149 }
1150 }
1151 nodesToRemove += KisNodeList(extraNodesToRemove.begin(), extraNodesToRemove.end());
1152 KritaUtils::filterContainer<KisNodeList>(nodesToRemove,
1153 [nodesToHide](KisNodeSP node) {
1154 return !nodesToHide.contains(node);
1155 });
1156 _nodesToHide = KisNodeList(nodesToHide.begin(), nodesToHide.end());
1157 }
1158
1160 CleanUpNodes(MergeDownInfoBaseSP info, KisNodeSP putAfter, bool relinkClones = false)
1161 : m_info(info), m_putAfter(putAfter), m_relinkClones(relinkClones) {}
1162
1163 static void findPerfectParent(KisNodeList nodesToDelete, KisNodeSP &putAfter, KisNodeSP &parent) {
1164 if (!putAfter) {
1165 putAfter = nodesToDelete.last();
1166 }
1167
1168 // Add the new merged node on top of the active node
1169 // -- checking all parents if they are included in nodesToDelete
1170 // Not every descendant is included in nodesToDelete even if in fact
1171 // they are going to be deleted, so we need to check it.
1172 // If we consider the path from root to the putAfter node,
1173 // if there are any nodes marked for deletion, any node afterwards
1174 // is going to be deleted, too.
1175 // example: root . . . . . ! ! . . ! ! ! ! . . . . putAfter
1176 // it should be: root . . . . . ! ! ! ! ! ! ! ! ! ! ! ! !putAfter
1177 // and here: root . . . . X ! ! . . ! ! ! ! . . . . putAfter
1178 // you can see which node is "the perfect ancestor"
1179 // (marked X; called "parent" in the function arguments).
1180 // and here: root . . . . . O ! . . ! ! ! ! . . . . putAfter
1181 // you can see which node is "the topmost deleted ancestor" (marked 'O')
1182
1183 KisNodeSP node = putAfter->parent();
1184 bool foundDeletedAncestor = false;
1185 KisNodeSP topmostAncestorToDelete = nullptr;
1186
1187 while (node) {
1188
1189 if (nodesToDelete.contains(node)
1190 && !nodesToDelete.contains(node->parent())) {
1191 foundDeletedAncestor = true;
1192 topmostAncestorToDelete = node;
1193 // Here node is to be deleted and its parent is not,
1194 // so its parent is the one of the first not deleted (="perfect") ancestors.
1195 // We need the one that is closest to the top (root)
1196 }
1197
1198 node = node->parent();
1199 }
1200
1201 if (foundDeletedAncestor) {
1202 parent = topmostAncestorToDelete->parent();
1203 putAfter = topmostAncestorToDelete;
1204 }
1205 else {
1206 parent = putAfter->parent(); // putAfter (and none of its ancestors) is to be deleted, so its parent is the first not deleted ancestor
1207 }
1208
1209 }
1210
1211 void populateChildCommands() override {
1212 KisNodeList nodesToDelete = m_info->allSrcNodes();
1213
1214 KisNodeSP parent;
1215 findPerfectParent(nodesToDelete, m_putAfter, parent);
1216
1217 if (!parent) {
1218 KisNodeSP oldRoot = m_info->image->root();
1219 KisNodeSP newRoot(new KisGroupLayer(m_info->image, "root", OPACITY_OPAQUE_U8));
1220
1221 // copy all fake nodes into the new image
1222 KisLayerUtils::recursiveApplyNodes(oldRoot, [this, oldRoot, newRoot] (KisNodeSP node) {
1223 if (node->isFakeNode() && node->parent() == oldRoot) {
1224 addCommand(new KisImageLayerAddCommand(m_info->image,
1225 node->clone(),
1226 newRoot,
1227 KisNodeSP(),
1228 false, false));
1229
1230 }
1231 });
1232
1233 addCommand(new KisImageLayerAddCommand(m_info->image,
1234 m_info->dstNode,
1235 newRoot,
1236 KisNodeSP(),
1237 true, false));
1238 addCommand(new KisImageChangeLayersCommand(m_info->image, oldRoot, newRoot));
1239
1240 }
1241 else {
1242 KisNodeList safeNodesToDelete = m_info->allSrcNodes();
1243 KisNodeList safeNodesToHide;
1244
1245 splitNonRemovableNodes(safeNodesToDelete, safeNodesToHide);
1246
1247 Q_FOREACH(KisNodeSP node, safeNodesToHide) {
1248 addCommand(new KisImageChangeVisibilityCommand(false, node));
1249 }
1250
1251 safeReplaceMultipleNodes(safeNodesToDelete, m_info->image,
1252 std::make_optional<ReplacementNode>(
1253 {m_info->dstNode,
1254 parent,
1255 m_putAfter,
1256 true, false,
1257 m_info->selectionMasks,
1258 m_relinkClones}));
1259 }
1260
1261
1262 }
1263
1264 private:
1265 void addCommandImpl(KUndo2Command *cmd) override {
1266 addCommand(cmd);
1267 }
1268
1269 private:
1272 bool m_relinkClones {false};
1273 };
1274
1275 SwitchFrameCommand::SharedStorage::~SharedStorage() {
1276 }
1277
1278 SwitchFrameCommand::SwitchFrameCommand(KisImageSP image, int time, bool finalize, SharedStorageSP storage)
1279 : FlipFlopCommand(finalize),
1280 m_image(image),
1281 m_newTime(time),
1282 m_storage(storage) {}
1283
1285
1287 KisImageAnimationInterface *interface = m_image->animationInterface();
1288 const int currentTime = interface->currentTime();
1289 if (currentTime == m_newTime) {
1290 m_storage->value = m_newTime;
1291 return;
1292 }
1293
1294 interface->image()->disableUIUpdates();
1295 interface->saveAndResetCurrentTime(m_newTime, &m_storage->value);
1296 }
1297
1299 KisImageAnimationInterface *interface = m_image->animationInterface();
1300 const int currentTime = interface->currentTime();
1301 if (currentTime == m_storage->value) {
1302 return;
1303 }
1304
1305 interface->restoreCurrentTime(&m_storage->value);
1306 interface->image()->enableUIUpdates();
1307 }
1308
1310 AddNewFrame(KisNodeSP node, int frame) : m_node(node), m_frame(frame) {}
1311 AddNewFrame(KisNodeSP node, int frame, KisNodeList sampleNodes) : m_node(node), m_frame(frame), m_sampledNodes(sampleNodes) {}
1312 AddNewFrame(KisNodeSP node, int frame, KisNodeSP source) : m_node(node), m_frame(frame) { m_sampledNodes << source; }
1313 AddNewFrame(MergeDownInfoBaseSP info, int frame) : m_frame(frame), m_sampledNodes(info->allSrcNodes()), m_mergeInfo(info) {}
1314
1315 void populateChildCommands() override {
1316 KUndo2Command *cmd = new KUndo2Command;
1317
1318 KisNodeSP node = m_node ? m_node : m_mergeInfo->dstNode;
1320
1321 if (!channel->keyframeAt(m_frame)) {
1322 channel->addKeyframe(m_frame, cmd);
1323 }
1324
1325 if (m_sampledNodes.count() > 0) {
1327 }
1328
1329 addCommand(cmd);
1330 }
1331
1333 Q_FOREACH(KisNodeSP srcNode, srcNodes) {
1334 Q_FOREACH(KisKeyframeChannel *channel, srcNode->keyframeChannels().values()) {
1335 KisKeyframeSP keyframe = channel->keyframeAt(m_frame);
1336 if (!keyframe.isNull() && keyframe->colorLabel() != 0) {
1337 dstKeyframe->setColorLabel(keyframe->colorLabel());
1338 return;
1339 }
1340 }
1341 }
1342
1343 dstKeyframe->setColorLabel(0);
1344 }
1345
1346 private:
1351 };
1352
1353 QSet<int> fetchLayerFrames(KisNodeSP node) {
1354 QSet<int> frames;
1355 Q_FOREACH(KisKeyframeChannel *channel, node->keyframeChannels()) {
1356 if (!channel) {
1357 continue;
1358 }
1359
1360 KisRasterKeyframeChannel *rasterChan = dynamic_cast<KisRasterKeyframeChannel*>(channel);
1361 if (rasterChan) {
1362 frames.unite(rasterChan->allKeyframeTimes());
1363 continue;
1364 }
1365
1366 KisScalarKeyframeChannel *scalarChan = dynamic_cast<KisScalarKeyframeChannel*>(channel);
1367 if (scalarChan) {
1368 const int initialKeyframe = scalarChan->firstKeyframeTime();
1369
1370 if (initialKeyframe == -1) {
1371 continue;
1372 }
1373
1374 const int lastKeyframe = scalarChan->lastKeyframeTime();
1375 KisTimeSpan currentSpan = scalarChan->identicalFrames(initialKeyframe);
1376 while (!currentSpan.isInfinite() && currentSpan.isValid() && currentSpan.start() < lastKeyframe) {
1377 frames.insert(currentSpan.start());
1378 currentSpan = scalarChan->identicalFrames(currentSpan.end() + 1);
1379 }
1380
1381 frames.insert(lastKeyframe);
1382 }
1383
1384 }
1385
1386 return frames;
1387 }
1388
1390 if (!rootNode->visible()) return QSet<int>();
1391
1392 QSet<int> frames = fetchLayerFrames(rootNode);
1393
1394 KisNodeSP node = rootNode->firstChild();
1395 while(node) {
1396 frames |= fetchLayerFramesRecursive(node);
1397 node = node->nextSibling();
1398 }
1399
1400 return frames;
1401 }
1402
1404 QSet<int> frames = fetchLayerFrames(node);
1405 frames = fetchUniqueFrameTimes(node, frames, false);
1406
1407 if (frames.isEmpty()) {
1408 (*jobs)[0].insert(node);
1409 } else {
1410 foreach (int frame, frames) {
1411 (*jobs)[frame].insert(node);
1412 }
1413 }
1414 }
1415
1417 updateFrameJobs(jobs, rootNode);
1418
1419 KisNodeSP node = rootNode->firstChild();
1420 while(node) {
1421 updateFrameJobsRecursive(jobs, node);
1422 node = node->nextSibling();
1423 }
1424 }
1425
1426 void updateFrameJobsNonRecursive(FrameJobs *jobs, KisNodeSP rootNode, bool frameTimesRecursive)
1427 {
1428 if (frameTimesRecursive) {
1429 QSet<int> frames = fetchLayerFramesRecursive(rootNode);
1430
1431 if (frames.isEmpty()) {
1432 (*jobs)[0].insert(rootNode);
1433 } else {
1434 foreach (int frame, frames) {
1435 (*jobs)[frame].insert(rootNode);
1436 }
1437 }
1438 } else {
1439 updateFrameJobs(jobs, rootNode);
1440 }
1441 }
1442
1446 void mergeDown(KisImageSP image, KisLayerSP layer, const KisMetaData::MergeStrategy* strategy, MergeFlags flags)
1447 {
1448 if (!layer->prevSibling()) return;
1449
1450 // XXX: this breaks if we allow free mixing of masks and layers
1451 KisLayerSP prevLayer = qobject_cast<KisLayer*>(layer->prevSibling().data());
1452
1453 while (prevLayer && prevLayer->isFakeNode()) {
1454 prevLayer = qobject_cast<KisLayer*>(prevLayer->prevSibling().data());
1455 }
1456
1457 if (!prevLayer) return;
1458
1459 if (!layer->visible() && !prevLayer->visible()) {
1460 return;
1461 }
1462
1463 KisImageSignalVector emitSignals;
1464 KisProcessingApplicator applicator(image, 0,
1466 emitSignals,
1467 kundo2_i18n("Merge Down"));
1468
1469 if (layer->visible() && prevLayer->visible()) {
1470 MergeDownInfoSP info(new MergeDownInfo(image, prevLayer, layer, flags));
1471
1472 // disable key strokes on all colorize masks, all onion skins on
1473 // paint layers and wait until update is finished with a barrier
1474 applicator.applyCommand(new DisableColorizeKeyStrokes(info));
1475 applicator.applyCommand(new DisableOnionSkins(info));
1477
1478 applicator.applyCommand(new KeepMergedNodesSelected(info, false));
1479 applicator.applyCommand(new FillSelectionMasks(info));
1481
1482 // NOTE: shape layer may have emitted spontaneous jobs during layer creation,
1483 // wait for them to complete!
1486
1487 // in two-layer mode we disable pass through only when the destination layer
1488 // is not a group layer
1489 applicator.applyCommand(new DisablePassThroughForHeadsOnly(info, true));
1491
1492 if (info->frames.size() > 0) {
1497 const int currentTimeOnStart = info->image->animationInterface()->currentTime();
1498
1499 foreach (int frame, info->frames) {
1500 applicator.applyCommand(new SwitchFrameCommand(info->image, frame, false, info->storage));
1501
1502 applicator.applyCommand(new AddNewFrame(info, frame));
1511
1520 const bool skipMergingSourceLayer = !layer->isAnimated() &&
1521 frame != currentTimeOnStart;
1522
1523 applicator.applyCommand(new MergeLayers(info, skipMergingSourceLayer), KisStrokeJobData::BARRIER);
1524
1525 applicator.applyCommand(new SwitchFrameCommand(info->image, frame, true, info->storage), KisStrokeJobData::BARRIER);
1526 }
1527 } else {
1528 applicator.applyCommand(new RefreshHiddenAreas(info));
1530 applicator.applyCommand(new MergeLayers(info, false), KisStrokeJobData::BARRIER);
1531 }
1532
1533 applicator.applyCommand(new MergeMetaData(info, strategy), KisStrokeJobData::BARRIER);
1534 applicator.applyCommand(new CleanUpNodes(info, layer),
1537 applicator.applyCommand(new KeepMergedNodesSelected(info, true));
1538 } else if (layer->visible()) {
1540 layer, KisNodeSP(),
1541 image, false));
1542
1543 applicator.applyCommand(
1544 new SimpleRemoveLayers(KisNodeList() << prevLayer,
1545 image),
1548
1550 KisNodeSP(), layer,
1551 image, true));
1552 } else if (prevLayer->visible()) {
1554 layer, KisNodeSP(),
1555 image, false));
1556
1557 applicator.applyCommand(
1558 new SimpleRemoveLayers(KisNodeList() << layer,
1559 image),
1562
1564 KisNodeSP(), prevLayer,
1565 image, true));
1566 }
1567
1568 applicator.end();
1569 }
1570
1571 bool checkIsChildOf(KisNodeSP node, const KisNodeList &parents)
1572 {
1573 KisNodeList nodeParents;
1574
1575 KisNodeSP parent = node->parent();
1576 while (parent) {
1577 nodeParents << parent;
1578 parent = parent->parent();
1579 }
1580
1581 foreach(KisNodeSP perspectiveParent, parents) {
1582 if (nodeParents.contains(perspectiveParent)) {
1583 return true;
1584 }
1585 }
1586
1587 return false;
1588 }
1589
1590 bool checkIsCloneOf(KisNodeSP node, const KisNodeList &nodes)
1591 {
1592 bool result = false;
1593
1594 KisCloneLayer *clone = dynamic_cast<KisCloneLayer*>(node.data());
1595 if (clone) {
1596 KisNodeSP cloneSource = KisNodeSP(clone->copyFrom());
1597
1598 Q_FOREACH(KisNodeSP subtree, nodes) {
1599 result =
1600 recursiveFindNode(subtree,
1601 [cloneSource](KisNodeSP node) -> bool
1602 {
1603 return node == cloneSource;
1604 });
1605
1606 if (!result) {
1607 result = checkIsCloneOf(cloneSource, nodes);
1608 }
1609
1610 if (result) {
1611 break;
1612 }
1613 }
1614 }
1615
1616 return result;
1617 }
1618
1619 void filterMergeableNodes(KisNodeList &nodes, bool allowMasks)
1620 {
1621 KisNodeList::iterator it = nodes.begin();
1622
1623 while (it != nodes.end()) {
1624 if ((!allowMasks && !qobject_cast<KisLayer*>(it->data())) ||
1625 checkIsChildOf(*it, nodes)) {
1626 //qDebug() << "Skipping node" << ppVar((*it)->name());
1627 it = nodes.erase(it);
1628 } else {
1629 ++it;
1630 }
1631 }
1632 }
1633
1634 void sortMergeableNodes(KisNodeSP root, KisNodeList &inputNodes, KisNodeList &outputNodes)
1635 {
1636 KisNodeList::iterator it = std::find(inputNodes.begin(), inputNodes.end(), root);
1637
1638 if (it != inputNodes.end()) {
1639 outputNodes << *it;
1640 inputNodes.erase(it);
1641 }
1642
1643 if (inputNodes.isEmpty()) {
1644 return;
1645 }
1646
1647 KisNodeSP child = root->firstChild();
1648 while (child) {
1649 sortMergeableNodes(child, inputNodes, outputNodes);
1650 child = child->nextSibling();
1651 }
1652
1656 KIS_ASSERT_RECOVER_NOOP(root->parent() || inputNodes.isEmpty());
1657 }
1658
1660 {
1661 KisNodeList result;
1662 sortMergeableNodes(root, nodes, result);
1663 return result;
1664 }
1665
1667 {
1668 KIS_SAFE_ASSERT_RECOVER(!nodes.isEmpty()) { return nodes; }
1669
1670 KisNodeSP root;
1671 Q_FOREACH(KisNodeSP node, nodes) {
1672 KisNodeSP localRoot = node;
1673 while (localRoot->parent()) {
1674 localRoot = localRoot->parent();
1675 }
1676
1677 if (!root) {
1678 root = localRoot;
1679 }
1680 KIS_SAFE_ASSERT_RECOVER(root == localRoot) { return nodes; }
1681 }
1682
1683 KisNodeList result;
1684 sortMergeableNodes(root, nodes, result);
1685 filterMergeableNodes(result, allowMasks);
1686 return result;
1687 }
1688
1690 {
1691 KIS_SAFE_ASSERT_RECOVER(!nodes.isEmpty()) { return nodes; }
1692
1693 KisNodeSP root;
1694 Q_FOREACH(KisNodeSP node, nodes) {
1695 KisNodeSP localRoot = node;
1696 while (localRoot->parent()) {
1697 localRoot = localRoot->parent();
1698 }
1699
1700 if (!root) {
1701 root = localRoot;
1702 }
1703 KIS_SAFE_ASSERT_RECOVER(root == localRoot) { return nodes; }
1704 }
1705
1706 KisNodeList result;
1707 sortMergeableNodes(root, nodes, result);
1708 return result;
1709 }
1710
1712 KisNodeList filteredNodes = nodes;
1713 KisNodeList sortedNodes;
1714
1715 KisLayerUtils::filterMergeableNodes(filteredNodes, true);
1716
1717 bool haveExternalNodes = false;
1718 Q_FOREACH (KisNodeSP node, nodes) {
1719 if (node->graphListener() != image->root()->graphListener()) {
1720 haveExternalNodes = true;
1721 break;
1722 }
1723 }
1724
1725 if (!haveExternalNodes) {
1726 KisLayerUtils::sortMergeableNodes(image->root(), filteredNodes, sortedNodes);
1727 } else {
1728 sortedNodes = filteredNodes;
1729 }
1730
1731 return sortedNodes;
1732 }
1733
1734
1736 {
1737 if (!KisImageConfig(true).renameDuplicatedLayers()) { return; }
1738
1739 const QString prefix = i18n("Copy of");
1740 QString newName = node->name();
1741 if (!newName.startsWith(prefix)) {
1742 newName = QString("%1 %2").arg(prefix).arg(newName);
1743 node->setName(newName);
1744 }
1745 }
1746
1747 KisNodeList findNodesWithProps(KisNodeSP root, const KoProperties &props, bool excludeRoot)
1748 {
1749 KisNodeList nodes;
1750
1751 if ((!excludeRoot || root->parent()) && root->check(props)) {
1752 nodes << root;
1753 }
1754
1755 KisNodeSP node = root->firstChild();
1756 while (node) {
1757 nodes += findNodesWithProps(node, props, excludeRoot);
1758 node = node->nextSibling();
1759 }
1760
1761 return nodes;
1762 }
1763
1764 KisNodeList filterInvisibleNodes(const KisNodeList &nodes, KisNodeList *invisibleNodes, KisNodeSP *putAfter)
1765 {
1766 KIS_ASSERT_RECOVER(invisibleNodes) { return nodes; }
1767 KIS_ASSERT_RECOVER(putAfter) { return nodes; }
1768
1769 KisNodeList visibleNodes;
1770 int putAfterIndex = -1;
1771
1772 Q_FOREACH(KisNodeSP node, nodes) {
1773 if (node->visible()) {
1774 visibleNodes << node;
1775 } else if (node->userLocked()) {
1780 } else {
1781 *invisibleNodes << node;
1782
1783 if (node == *putAfter) {
1784 putAfterIndex = visibleNodes.size() - 1;
1785 }
1786 }
1787 }
1788
1789 if (!visibleNodes.isEmpty() && putAfterIndex >= 0) {
1790 putAfterIndex = qBound(0, putAfterIndex, visibleNodes.size() - 1);
1791 *putAfter = visibleNodes[putAfterIndex];
1792 }
1793
1794 return visibleNodes;
1795 }
1796
1798 {
1799 KisNodeList::iterator it = nodes.begin();
1800
1801 while (it != nodes.end()) {
1802 if ((*it)->userLocked()) {
1803 it = nodes.erase(it);
1804 } else {
1805 ++it;
1806 }
1807 }
1808 }
1809
1811 {
1812 KisImageSignalVector emitSignals;
1813 KisProcessingApplicator applicator(image,
1814 image->root(),
1816 emitSignals,
1817 kundo2_i18n("Change projection color"),
1818 0,
1821 applicator.end();
1822 }
1823
1825 {
1827 : m_info(info)
1828 , m_commands(commands)
1829 , m_cleanupNodes(cleanupNodes)
1830 {
1831 }
1832
1834 if (!m_cleanupNodes && !m_info->ephemeralCommandsStore) {
1835 m_info->ephemeralCommandsStore.reset(new KisSurrogateUndoStore());
1836 }
1837
1838 Q_FOREACH (KUndo2Command *cmd, m_commands) {
1839 if (m_cleanupNodes) {
1840 addCommand(cmd);
1841 } else {
1842 m_info->ephemeralCommandsStore->addCommand(cmd);
1843 }
1844 }
1845 m_commands.clear();
1846 m_info.reset();
1847 }
1848
1849 private:
1852 bool m_cleanupNodes {true};
1853 };
1854
1856 {
1858 : m_info(info)
1859 {
1860 }
1861
1863 KIS_SAFE_ASSERT_RECOVER_RETURN(m_info->ephemeralCommandsStore);
1864 m_info->ephemeralCommandsStore->undoAll();
1865
1866 }
1867
1868 private:
1870 };
1871
1897 void mergeMultipleLayersImpl(KisImageSP image, KisNodeList mergedNodes, KisNodeSP putAfter,
1898 bool flattenSingleLayer, const KUndo2MagicString &actionName,
1899 bool cleanupNodes = true, const QString layerName = QString(),
1900 MergeFlags flags = None)
1901 {
1902 if (!putAfter) {
1903 putAfter = mergedNodes.first();
1904 }
1905
1906 filterMergeableNodes(mergedNodes);
1907 {
1908 KisNodeList tempNodes;
1909 std::swap(mergedNodes, tempNodes);
1910 sortMergeableNodes(image->root(), tempNodes, mergedNodes);
1911 }
1912
1913 if (mergedNodes.size() <= 1 &&
1914 (!flattenSingleLayer && mergedNodes.size() == 1)) return;
1915
1916 KisImageSignalVector emitSignals;
1917 emitSignals << ComplexNodeReselectionSignal(KisNodeSP(), KisNodeList(), KisNodeSP(), mergedNodes);
1918
1919
1920
1921 KisNodeList originalNodes = mergedNodes;
1922 KisNodeList invisibleNodes;
1923 mergedNodes = filterInvisibleNodes(originalNodes, &invisibleNodes, &putAfter);
1924
1925 if (mergedNodes.isEmpty()) return;
1926
1927
1928 // make sure we don't add the new layer into a locked group
1930 while (putAfter->parent() && !putAfter->parent()->isEditable()) {
1931 putAfter = putAfter->parent();
1932 }
1933
1941 if (!putAfter->parent()) {
1942 return;
1943 }
1944
1945 KisProcessingApplicator applicator(image, 0,
1947 emitSignals,
1948 actionName);
1949
1950
1951 if (!invisibleNodes.isEmpty() && cleanupNodes) {
1952
1953 /* If the putAfter node is invisible,
1954 * we should instead pick one of the nodes
1955 * to be merged to avoid a null putAfter
1956 * after we remove all invisible layers from
1957 * the image.
1958 * (The assumption is that putAfter is among
1959 * the layers to merge, so if it's invisible,
1960 * it's going to be removed)
1961 */
1962 if (!putAfter->visible()){
1963 putAfter = mergedNodes.first();
1964 }
1965
1966 applicator.applyCommand(
1967 new SimpleRemoveLayers(invisibleNodes,
1968 image),
1971 }
1972
1973 if (mergedNodes.size() > 1 || invisibleNodes.isEmpty()) {
1974 MergeMultipleInfoSP info(new MergeMultipleInfo(image, mergedNodes, flags));
1975
1976 // disable key strokes on all colorize masks, all onion skins on
1977 // paint layers and wait until update is finished with a barrier
1978 //
1979 // when doing "new layer from visible" we should undo these changes
1980 // before the action stops, because the source layers are **not**
1981 // removed as a result of this action
1982 applicator.applyCommand(
1983 new EphemeralCommandsWrapper(info,
1984 {
1985 new DisableColorizeKeyStrokes(info),
1986 new DisableOnionSkins(info),
1988 },
1989 cleanupNodes));
1991
1992 applicator.applyCommand(new KeepMergedNodesSelected(info, putAfter, false));
1993 applicator.applyCommand(new FillSelectionMasks(info));
1994 applicator.applyCommand(new CreateMergedLayerMultiple(info, layerName), KisStrokeJobData::BARRIER);
1995 applicator.applyCommand(new EphemeralCommandsWrapper(info, { new DisableExtraCompositing(info) } , cleanupNodes));
1997
1998 if (!info->frames.isEmpty()) {
1999 foreach (int frame, info->frames) {
2000 applicator.applyCommand(new SwitchFrameCommand(info->image, frame, false, info->storage));
2001
2002 applicator.applyCommand(new AddNewFrame(info, frame));
2012
2013 applicator.applyCommand(new SwitchFrameCommand(info->image, frame, true, info->storage));
2014 }
2015 } else {
2016 applicator.applyCommand(new RefreshHiddenAreas(info));
2019 }
2020
2021 //applicator.applyCommand(new MergeMetaData(info, strategy), KisStrokeJobData::BARRIER);
2022 if (cleanupNodes){
2023 applicator.applyCommand(new CleanUpNodes(info, putAfter, flattenSingleLayer),
2026 } else {
2027 applicator.applyCommand(new UndoEphemeralCommands(info));
2028 applicator.applyCommand(new InsertNode(info, putAfter),
2031 }
2032
2033 applicator.applyCommand(new KeepMergedNodesSelected(info, putAfter, true));
2034 }
2035
2036 applicator.end();
2037
2038 }
2039
2040 void mergeMultipleLayers(KisImageSP image, KisNodeList mergedNodes, KisNodeSP putAfter, MergeFlags flags)
2041 {
2042 mergeMultipleLayersImpl(image, mergedNodes, putAfter,
2043 false, kundo2_i18n("Merge Selected Nodes"),
2044 true, QString(),
2045 flags);
2046 }
2047
2048 void mergeMultipleNodes(KisImageSP image, KisNodeList mergedNodes, KisNodeSP putAfter, MergeFlags flags)
2049 {
2050 if (!tryMergeSelectionMasks(image, mergedNodes, putAfter)) {
2051 mergeMultipleLayers(image, mergedNodes, putAfter, flags);
2052 }
2053 }
2054
2055 void newLayerFromVisible(KisImageSP image, KisNodeSP putAfter, MergeFlags flags)
2056 {
2057 KisNodeList mergedNodes;
2058 mergedNodes << image->root();
2059
2060 mergeMultipleLayersImpl(image, mergedNodes, putAfter,
2061 true, kundo2_i18n("New From Visible"),
2062 false, i18nc("New layer created from all the visible layers", "Visible"),
2063 flags);
2064 }
2065
2068 : m_info(info),
2069 m_putAfter(putAfter){}
2070
2071 void populateChildCommands() override {
2072 KisNodeSP parent;
2073 CleanUpNodes::findPerfectParent(m_info->allSrcNodes(), m_putAfter, parent);
2074
2075 KisLayerSP parentLayer;
2076 do {
2077 parentLayer = qobject_cast<KisLayer*>(parent.data());
2078
2079 parent = parent->parent();
2080 } while(!parentLayer && parent);
2081
2082 KisSelectionSP selection = new KisSelection();
2083
2084 foreach (KisNodeSP node, m_info->allSrcNodes()) {
2085 KisMaskSP mask = dynamic_cast<KisMask*>(node.data());
2086 if (!mask) continue;
2087
2088 selection->pixelSelection()->applySelection(
2089 mask->selection()->pixelSelection(), SELECTION_ADD);
2090 }
2091
2092 KisSelectionMaskSP mergedMask = new KisSelectionMask(m_info->image, i18n("Selection Mask"));
2093 mergedMask->initSelection(parentLayer);
2094 mergedMask->setSelection(selection);
2095
2096 m_info->dstNode = mergedMask;
2097 }
2098
2099 private:
2102 };
2103
2107
2108 void populateChildCommands() override {
2109 KisSelectionMaskSP mergedMask = dynamic_cast<KisSelectionMask*>(m_info->dstNode.data());
2110 addCommand(new KisActivateSelectionMaskCommand(mergedMask, true));
2111 }
2112
2113 private:
2115 };
2116
2117 bool tryMergeSelectionMasks(KisImageSP image, KisNodeList mergedNodes, KisNodeSP putAfter)
2118 {
2119 QList<KisSelectionMaskSP> selectionMasks;
2120
2121 for (auto it = mergedNodes.begin(); it != mergedNodes.end(); /*noop*/) {
2122 KisSelectionMaskSP mask = dynamic_cast<KisSelectionMask*>(it->data());
2123 if (!mask) {
2124 it = mergedNodes.erase(it);
2125 } else {
2126 selectionMasks.append(mask);
2127 ++it;
2128 }
2129 }
2130
2131 if (mergedNodes.isEmpty()) return false;
2132
2133 KisLayerSP parentLayer = qobject_cast<KisLayer*>(selectionMasks.first()->parent().data());
2134 KIS_ASSERT_RECOVER(parentLayer) { return 0; }
2135
2136 KisImageSignalVector emitSignals;
2137
2138 KisProcessingApplicator applicator(image, 0,
2140 emitSignals,
2141 kundo2_i18n("Merge Selection Masks"));
2142
2143 MergeMultipleInfoSP info(new MergeMultipleInfo(image, mergedNodes, None));
2144
2145
2146 applicator.applyCommand(new MergeSelectionMasks(info, putAfter));
2147 applicator.applyCommand(new CleanUpNodes(info, putAfter),
2150 applicator.applyCommand(new ActivateSelectionMask(info));
2151 applicator.end();
2152
2153 return true;
2154 }
2155
2156 void flattenLayer(KisImageSP image, KisLayerSP layer, MergeFlags flags)
2157 {
2158 if (!layer->childCount() && !layer->layerStyle())
2159 return;
2160
2161 KisNodeList mergedNodes;
2162 mergedNodes << layer;
2163
2164 mergeMultipleLayersImpl(image, mergedNodes, layer,
2165 true, kundo2_i18n("Flatten Layer"),
2166 true, QString(),
2167 flags);
2168 }
2169
2170 void flattenImage(KisImageSP image, KisNodeSP activeNode, MergeFlags flags)
2171 {
2172 if (!activeNode) {
2173 activeNode = image->root()->lastChild();
2174 }
2175
2176
2177 KisNodeList mergedNodes;
2178 mergedNodes << image->root();
2179
2180 mergeMultipleLayersImpl(image, mergedNodes, activeNode,
2181 true, kundo2_i18n("Flatten Image"),
2182 true, QString(),
2183 flags);
2184 }
2185
2187 : FlipFlopCommand(finalize, parent),
2188 m_nodes(nodes)
2189 {
2190 }
2196 {
2197 Q_FOREACH(KisNodeSP node, nodes) {
2198 node->setDirty(node->extent());
2199 }
2200 }
2201
2202 KisNodeSP recursiveFindNode(KisNodeSP node, std::function<bool(KisNodeSP)> func)
2203 {
2204 if (func(node)) {
2205 return node;
2206 }
2207
2208 node = node->firstChild();
2209 while (node) {
2210 KisNodeSP resultNode = recursiveFindNode(node, func);
2211 if (resultNode) {
2212 return resultNode;
2213 }
2214 node = node->nextSibling();
2215 }
2216
2217 return 0;
2218 }
2219
2220 KisNodeSP findNodeByUuid(KisNodeSP root, const QUuid &uuid)
2221 {
2222 return recursiveFindNode(root,
2223 [uuid] (KisNodeSP node) {
2224 return node->uuid() == uuid;
2225 });
2226 }
2227
2228 QList<KisNodeSP> findNodesByName(KisNodeSP root, const QString &name, bool recursive, bool partialMatch)
2229 {
2230 KisNodeList nodeList;
2231 KisNodeSP child = root->firstChild();
2232
2233 while (child) {
2234 if (name.isEmpty() || (!partialMatch && child->name() == name) || (partialMatch && child->name().contains(name, Qt::CaseInsensitive))) {
2235 nodeList << child;
2236 }
2237 if (recursive && child->childCount() > 0) {
2238 nodeList << findNodesByName(child, name, recursive, partialMatch);
2239 }
2240 child = child->nextSibling();
2241 }
2242
2243 return nodeList;
2244 }
2245
2246 KisNodeSP findNodeByName(KisNodeSP root, const QString &name)
2247 {
2248 return recursiveFindNode(root,
2249 [name] (KisNodeSP node) {
2250 return node->name() == name;
2251 });
2252 }
2253
2255 {
2256 KisImageSP image = node->image();
2257 if (image)
2258 return image->isolationRootNode();
2259 return nullptr;
2260 }
2261
2263 {
2265 [] (KisNodeSP node) {
2266 KisDelayedUpdateNodeInterface *delayedUpdate =
2267 dynamic_cast<KisDelayedUpdateNodeInterface*>(node.data());
2268 if (delayedUpdate) {
2269 delayedUpdate->forceUpdateTimedNode();
2270 }
2271 });
2272 }
2273
2275 {
2276 return recursiveFindNode(root,
2277 [] (KisNodeSP node) {
2278 KisDelayedUpdateNodeInterface *delayedUpdate =
2279 dynamic_cast<KisDelayedUpdateNodeInterface*>(node.data());
2280
2281 return delayedUpdate ? delayedUpdate->hasPendingTimedUpdates() : false;
2282 });
2283 }
2284
2286 {
2288 [] (KisNodeSP node) {
2289 KisCroppedOriginalLayerInterface *croppedUpdate =
2290 dynamic_cast<KisCroppedOriginalLayerInterface*>(node.data());
2291 if (croppedUpdate) {
2292 croppedUpdate->forceUpdateHiddenAreaOnOriginal();
2293 }
2294 });
2295 }
2296
2298 {
2299 while (node) {
2300 const KisLayer *layer = dynamic_cast<const KisLayer*>(node.data());
2301 if (layer) {
2302 return layer->image();
2303 }
2304
2305 node = node->parent();
2306 }
2307
2308 return 0;
2309 }
2310
2311 namespace Private {
2312 QRect realNodeChangeRect(KisNodeSP rootNode, QRect currentRect = QRect()) {
2313 KisNodeSP node = rootNode->firstChild();
2314
2315 while(node) {
2316 currentRect |= realNodeChangeRect(node, currentRect);
2317 node = node->nextSibling();
2318 }
2319
2320 if (!rootNode->isFakeNode() && !rootNode->projectionLeaf()->isMask()) {
2321 // TODO: it would be better to count up changeRect inside
2322 // node's extent() method
2323 //
2324 // NOTE: when flattening a group layer, we should take the change rect of the
2325 // all the child layers as the source of the change. We are calculating
2326 // the change rect **before** the update itself, therefore rootNode->exactBounds()
2327 // is not yet prepared, hence its exact bounds still contail old values.
2328 currentRect |= rootNode->projectionPlane()->changeRect(rootNode->exactBounds() | currentRect);
2329 }
2330
2331 return currentRect;
2332 }
2333 }
2334
2335namespace Private {
2336 void refreshHiddenAreaAsync(KisImageSP image, KisNodeSP rootNode, const QRect &preparedArea, const QRect &extraUpdateRect) {
2337 QRect realNodeRect = Private::realNodeChangeRect(rootNode) | extraUpdateRect;
2338 if (!preparedArea.contains(realNodeRect)) {
2339
2340 QRegion dirtyRegion = realNodeRect;
2341 dirtyRegion -= preparedArea;
2342
2343 auto rc = dirtyRegion.begin();
2344 while (rc != dirtyRegion.end()) {
2345 image->refreshGraphAsync(rootNode, *rc, realNodeRect);
2346 rc++;
2347 }
2348 }
2349 }
2350} // namespace Private
2351
2352 void refreshHiddenAreaAsync(KisImageSP image, KisNodeSP rootNode, const QRect &preparedArea) {
2353 Private::refreshHiddenAreaAsync(image, rootNode, preparedArea, QRect());
2354 }
2355
2357 {
2358 QRect exactBounds;
2359 recursiveApplyNodes(rootNode, [&exactBounds] (KisNodeSP node) {
2360 exactBounds |= node->projectionPlane()->tightUserVisibleBounds();
2361 });
2362 return exactBounds;
2363 }
2364
2366 {
2367 if (!node) return node;
2368
2369 while (node->parent()) {
2370 node = node->parent();
2371 }
2372 return node;
2373 }
2374
2376 {
2377 int numLayers = 0;
2378 bool hasNonNormalLayers = false;
2379 bool hasTransparentLayer = false;
2380
2381
2382 recursiveApplyNodes(image->root(),
2383 [&numLayers, &hasNonNormalLayers, &hasTransparentLayer, image] (KisNodeSP node) {
2384 if (!node->inherits("KisLayer")) return;
2385
2386 numLayers++;
2387
2388 if (node->exactBounds().isEmpty()) return;
2389
2390 // this is only an approximation! it is not exact!
2391 if (!hasTransparentLayer &&
2392 node->exactBounds() != image->bounds()) {
2393
2394 hasTransparentLayer = true;
2395 }
2396
2397 if (!hasNonNormalLayers &&
2398 node->compositeOpId() != COMPOSITE_OVER) {
2399
2400 hasNonNormalLayers = true;
2401 }
2402 });
2403
2404 return numLayers == 1 || (!hasNonNormalLayers && !hasTransparentLayer);
2405 }
2406
2407 void splitAlphaToMask(KisImageSP image, KisNodeSP node, const QString& maskName)
2408 {
2409 SplitAlphaToMaskInfoSP info( new SplitAlphaToMaskInfo(node->image(), node, maskName) );
2410
2411 KisImageSignalVector emitSignals;
2412 KisProcessingApplicator applicator(image, node,
2414 emitSignals,
2415 kundo2_i18n("Split Alpha into a Mask"));
2416
2417 applicator.applyCommand(new SimpleAddNode(info->image, info->getMask(), info->node), KisStrokeJobData::BARRIER);
2418 applicator.applyCommand(new InitSplitAlphaSelectionMask(info));
2419 if (info->frames.count() > 0) {
2420 Q_FOREACH(const int& frame, info->frames) {
2421 applicator.applyCommand(new SwitchFrameCommand(info->image, frame, false, info->storage));
2422 applicator.applyCommand(new AddNewFrame(info->getMask(), frame, info->node));
2424 applicator.applyCommand(new SwitchFrameCommand(info->image, frame, true, info->storage));
2425 }
2426 } else {
2428 }
2429 applicator.end();
2430 }
2431
2432 std::future<KisNodeSP> convertToPaintLayer(KisImageSP image, KisNodeSP src)
2433 {
2434 //Initialize all operation dependencies.
2435 ConvertToPaintLayerInfoSP info( new ConvertToPaintLayerInfo(image, src) );
2436
2437 if (!info->hasTargetNode())
2439
2440 KisImageSignalVector emitSignals;
2441 KisProcessingApplicator applicator(image, 0, KisProcessingApplicator::NONE, emitSignals, kundo2_i18n("Convert to a Paint Layer"));
2442
2443 applicator.applyCommand(new SimpleAddNode(info->image(), info->targetNode(), info->insertionParent(), info->insertionPutAfter()), KisStrokeJobData::BARRIER);
2444
2445 if (info->frames().count() > 0) {
2446 Q_FOREACH(const int& frame, info->frames()) {
2447 applicator.applyCommand(new SwitchFrameCommand(info->image(), frame, false, info->storage));
2448 applicator.applyCommand(new RefreshDelayedUpdateLayers(info->sourceNodes()), KisStrokeJobData::BARRIER);
2449 applicator.applyCommand(new RefreshHiddenAreas(info->image(), info->sourceNode()), KisStrokeJobData::BARRIER);
2450 applicator.applyCommand(new AddNewFrame(info->targetNode(), frame, info->sourceNode()), KisStrokeJobData::BARRIER);
2451 applicator.applyCommand(new UploadProjectionToFrameCommand(info->sourceNode(), info->targetNode(), frame));
2452 applicator.applyCommand(new SwitchFrameCommand(info->image(), frame, true, info->storage));
2453 }
2454 }
2455
2456 applicator.applyCommand(new SimpleRemoveLayers(info->toRemove(), info->image()));
2457
2458 applicator.end();
2459
2460 return kismpl::then(applicator.successfullyCompletedFuture(),
2461 [node = info->targetNode()] (std::future<bool> completed) {
2462 return completed.get() ? node : KisNodeSP();
2463 });
2464 }
2465
2466 //===========================================================
2467
2469 {
2471 KisPaintDeviceSP paintDevice = node->paintDevice();
2472 KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(paintDevice, -1);
2473
2474 if (!paintDevice->keyframeChannel()) {
2475 return -1;
2476 }
2477
2478 const int activeTime = paintDevice->keyframeChannel()->activeKeyframeTime();
2479 KisRasterKeyframeSP keyframe = paintDevice->keyframeChannel()->activeKeyframeAt<KisRasterKeyframe>(activeTime);
2481
2482 return keyframe->frameID();
2483 }
2484
2486 {
2488 KisPaintDeviceSP paintDevice = node->paintDevice();
2489 KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(paintDevice, -1);
2490
2491 if (!paintDevice->keyframeChannel()) {
2492 return -1;
2493 }
2494
2495 return paintDevice->keyframeChannel()->activeKeyframeTime();
2496 }
2497
2499 {
2501 KisPaintDeviceSP paintDevice = node->paintDevice();
2503 if (!paintDevice->keyframeChannel()) {
2504 return KisTimeSpan::infinite(0);
2505 }
2506
2507 return paintDevice->keyframeChannel()->affectedFrames(time);
2508 }
2509
2510 QSet<int> fetchLayerIdenticalRasterFrameTimes(KisNodeSP node, const int &frameTime)
2511 {
2512 KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(node, QSet<int>());
2513 KisPaintDeviceSP paintDevice = node->paintDevice();
2514 KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(paintDevice, QSet<int>());
2515 if (!paintDevice->keyframeChannel()) {
2516 return QSet<int>();
2517 }
2518
2519 return paintDevice->keyframeChannel()->clonesOf(node.data(), frameTime);
2520 }
2521
2522 /* Finds all frames matching a specific frame ID. useful to filter out duplicate frames. */
2523 QSet<int> fetchLayerRasterFrameTimesMatchingID(KisNodeSP node, const int frameID) {
2524 KIS_ASSERT(node);
2525 KisRasterKeyframeChannel* rasterChannel = dynamic_cast<KisRasterKeyframeChannel*>(node->getKeyframeChannel(KisKeyframeChannel::Raster.id(), false));
2526
2527 if (!rasterChannel) {
2528 return QSet<int>();
2529 }
2530
2531 return rasterChannel->timesForFrameID(frameID);
2532 }
2533
2534 QSet<int> fetchLayerRasterIDsAtTimes(KisNodeSP node, const QSet<int> &times)
2535 {
2536 KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(node, QSet<int>());
2537 KisPaintDeviceSP paintDevice = node->paintDevice();
2538 KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(paintDevice, QSet<int>());
2539 if (!paintDevice->keyframeChannel()) {
2540 return QSet<int>();
2541 }
2542
2543 QSet<int> frameIDs;
2544
2545 Q_FOREACH( const int& frame, times ) {
2547 frameIDs << raster->frameID();
2548 }
2549
2550 return frameIDs;
2551 }
2552
2553 QSet<int> filterTimesForOnlyRasterKeyedTimes(KisNodeSP node, const QSet<int> &times)
2554 {
2556 KisPaintDeviceSP paintDevice = node->paintDevice();
2557 KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(paintDevice, times);
2558 if (!paintDevice->keyframeChannel()) {
2559 return times;
2560 }
2561
2562 return paintDevice->keyframeChannel()->allKeyframeTimes().intersect(times);
2563 }
2564
2565 QSet<int> fetchLayerUniqueRasterTimesMatchingIDs(KisNodeSP node, QSet<int>& frameIDs)
2566 {
2567 KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(node, QSet<int>());
2568 KisPaintDeviceSP paintDevice = node->paintDevice();
2569 KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(paintDevice, QSet<int>());
2570 KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(paintDevice->framesInterface(), QSet<int>());
2571
2572 QSet<int> uniqueTimes;
2573
2574 Q_FOREACH( const int& id, frameIDs) {
2575 QSet<int> times = fetchLayerRasterFrameTimesMatchingID(node, id);
2576 if (times.count() > 0) {
2577 uniqueTimes.insert(*times.begin());
2578 }
2579 }
2580
2581 return uniqueTimes;
2582 }
2583
2584 QSet<int> fetchUniqueFrameTimes(KisNodeSP node, QSet<int> selectedTimes, bool filterActiveFrameID)
2585 {
2586 if (selectedTimes.isEmpty() || !node->supportsKeyframeChannel(KisKeyframeChannel::Raster.id()))
2587 return selectedTimes;
2588
2589 // Convert a set of selected keyframe times into set of selected "frameIDs"...
2590 QSet<int> selectedFrameIDs = KisLayerUtils::fetchLayerRasterIDsAtTimes(node, selectedTimes);
2591
2592 if (filterActiveFrameID) {
2593 // Current frame was already filtered e.g. during filter preview in `KisFilterManager::apply`...
2594 // So let's remove it...
2595 const int currentActiveFrameID = KisLayerUtils::fetchLayerActiveRasterFrameID(node);
2596 selectedFrameIDs.remove(currentActiveFrameID);
2597 }
2598
2599 // Convert frameIDs to any arbitrary frame time associated with the frameID...
2600 QSet<int> uniqueFrameTimes = node->paintDevice()->framesInterface() ? KisLayerUtils::fetchLayerUniqueRasterTimesMatchingIDs(node, selectedFrameIDs) : QSet<int>();
2601
2602 return uniqueFrameTimes;
2603 }
2604
2605}
KisMagneticGraph::vertex_descriptor target(typename KisMagneticGraph::edge_descriptor e, KisMagneticGraph g)
KisMagneticGraph::vertex_descriptor source(typename KisMagneticGraph::edge_descriptor e, KisMagneticGraph g)
@ SELECTION_ADD
const quint8 OPACITY_OPAQUE_U8
const QString COMPOSITE_OVER
const QString COMPOSITE_BEHIND
KUndo2Command(KUndo2Command *parent=0)
KisPaintDeviceSP coloringProjection() const
virtual void forceUpdateHiddenAreaOnOriginal()=0
virtual QRect bounds() const =0
The KisDelayedUpdateNodeInterface class is an interface for nodes that delay their real updates with ...
virtual void forceUpdateTimedNode()=0
forceUpdateTimedNode forces the node to regenerate its project. The update might be asynchronous,...
virtual bool hasPendingTimedUpdates() const =0
The command for adding a layer.
The command for layer moves inside the layer stack.
void emitNotification(KisImageSignalType type)
void refreshGraphAsync(KisNodeSP root, const QVector< QRect > &rects, const QRect &cropRect, KisProjectionUpdateFlags flags=KisProjectionUpdateFlag::None) override
KisGroupLayerSP rootLayer() const
const KoColorSpace * colorSpace() const
KisImageAnimationInterface * animationInterface() const
QString nextLayerName(const QString &baseName="") const
Definition kis_image.cc:741
QVector< QRect > enableUIUpdates() override
KisNodeSP isolationRootNode() const
KisImageSignalRouter * signalRouter()
QRect bounds() const override
KisKeyframeChannel stores and manages KisKeyframes. Maps units of time to virtual keyframe values....
QSet< int > allKeyframeTimes() const
Get a set of all integer times that map to a keyframe.
static const KoID Raster
KisKeyframeSP keyframeAt(int time) const
Get a keyframe at specified time. Used primarily when the value of a given keyframe is needed.
void addKeyframe(int time, KUndo2Command *parentUndoCmd=nullptr)
Add a new keyframe to the channel at the specified time.
virtual KisTimeSpan affectedFrames(int time) const
Get the set of frames affected by any changes to the value or content of the active keyframe at the g...
KisKeyframeSP activeKeyframeAt(int time) const
int activeKeyframeTime(int time) const
Get the time of the active keyframe. Useful for snapping any time to that of the most recent keyframe...
static QVariant nodeProperty(KisNodeSP node, const KoID &id, const QVariant &defaultValue)
static void setNodeProperty(KisBaseNode::PropertyList *props, const KoID &id, const QVariant &value)
KeepNodesSelectedCommand(const KisNodeList &selectedBefore, const KisNodeList &selectedAfter, KisNodeSP activeBefore, KisNodeSP activeAfter, KisImageSP image, bool finalize, KUndo2Command *parent=0)
static void updateNodes(const KisNodeList &nodes)
KisSimpleUpdateCommand(KisNodeList nodes, bool finalize, KUndo2Command *parent=0)
virtual void addCommandImpl(KUndo2Command *cmd)=0
void safeReplaceMultipleNodes(KisNodeList removedNodes, KisImageSP image, std::optional< ReplacementNode > replacementNode)
void safeRemoveMultipleNodes(KisNodeList nodes, KisImageSP image)
bool checkIsSourceForClone(KisNodeSP src, const KisNodeList &nodes)
static bool scanForLastLayer(KisImageWSP image, KisNodeList nodesToRemove)
virtual void merge(Store *dst, QList< const Store * > srcs, QList< double > scores) const =0
The command for setting the composite op.
The command for changing the property list of a layer.
void uploadFrame(int srcFrameId, int dstFrameId, KisPaintDeviceSP srcDevice)
KisRasterKeyframeChannel * keyframeChannel() const
void setDefaultPixel(const KoColor &defPixel)
virtual const KoColorSpace * compositionSourceColorSpace() const
KisPaintDeviceFramesInterface * framesInterface()
QRect exactBounds() const
QRect extent() const
const KoColorSpace * colorSpace() const
KoColor defaultPixel() const
KisDefaultBoundsBaseSP defaultBounds() const
static void copyAreaOptimized(const QPoint &dstPt, KisPaintDeviceSP src, KisPaintDeviceSP dst, const QRect &originalSrcRect)
void applyCommand(KUndo2Command *command, KisStrokeJobData::Sequentiality sequentiality=KisStrokeJobData::SEQUENTIAL, KisStrokeJobData::Exclusivity exclusivity=KisStrokeJobData::NORMAL)
std::future< bool > && successfullyCompletedFuture()
The KisRasterKeyframeChannel is a concrete KisKeyframeChannel subclass that stores and manages KisRas...
QSet< int > timesForFrameID(int frameID) const
The KisRasterKeyframe class is a concrete subclass of KisKeyframe that wraps a physical raster image ...
The KisScalarKeyframeChannel is a concrete KisKeyframeChannel subclass that stores and manages KisSca...
virtual KisTimeSpan identicalFrames(int time) const override
Get a span of times for which the channel gives identical results compared to frame at a given time....
ALWAYS_INLINE quint8 * rawData()
int start() const
bool isInfinite() const
static KisTimeSpan infinite(int start)
int end() const
bool isValid() const
KUndo2Command * endAndTake()
virtual void setOpacity(quint8 *pixels, quint8 alpha, qint32 nPixels) const =0
virtual quint8 opacityU8(const quint8 *pixel) const =0
KoColor convertedTo(const KoColorSpace *cs, KoColorConversionTransformation::Intent renderingIntent, KoColorConversionTransformation::ConversionFlags conversionFlags) const
Definition KoColor.cpp:163
QString id() const
Definition KoID.cpp:63
#define KIS_ASSERT_RECOVER(cond)
Definition kis_assert.h:55
#define KIS_SAFE_ASSERT_RECOVER(cond)
Definition kis_assert.h:126
#define KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(cond, val)
Definition kis_assert.h:129
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:128
#define KIS_ASSERT_RECOVER_NOOP(cond)
Definition kis_assert.h:97
#define KIS_SAFE_ASSERT_RECOVER_NOOP(cond)
Definition kis_assert.h:130
#define KIS_ASSERT(cond)
Definition kis_assert.h:33
#define bounds(x, a, b)
QList< KisNodeSP > KisNodeList
Definition kis_types.h:264
KisSharedPtr< KisNode > KisNodeSP
Definition kis_types.h:86
KUndo2MagicString kundo2_i18n(const char *text)
QRect realNodeChangeRect(KisNodeSP rootNode, QRect currentRect=QRect())
void refreshHiddenAreaAsync(KisImageSP image, KisNodeSP rootNode, const QRect &preparedArea, const QRect &extraUpdateRect)
void flattenImage(KisImageSP image, KisNodeSP activeNode, MergeFlags flags)
bool checkIsCloneOf(KisNodeSP node, const KisNodeList &nodes)
KisNodeSP findIsolationRoot(KisNodeSP node)
QSet< int > fetchLayerFrames(KisNodeSP node)
QSet< int > fetchUniqueFrameTimes(KisNodeSP node, QSet< int > selectedTimes, bool filterActiveFrameID)
bool hasDelayedNodeWithUpdates(KisNodeSP root)
void updateFrameJobs(FrameJobs *jobs, KisNodeSP node)
QSet< int > filterTimesForOnlyRasterKeyedTimes(KisNodeSP node, const QSet< int > &times)
void updateFrameJobsRecursive(FrameJobs *jobs, KisNodeSP rootNode)
KisNodeSP recursiveFindNode(KisNodeSP node, std::function< bool(KisNodeSP)> func)
void splitAlphaToMask(KisImageSP image, KisNodeSP node, const QString &maskName)
void changeImageDefaultProjectionColor(KisImageSP image, const KoColor &color)
KisTimeSpan fetchLayerActiveRasterFrameSpan(KisNodeSP node, const int time)
KisNodeList sortAndFilterMergeableInternalNodes(KisNodeList nodes, bool allowMasks)
QMap< int, QSet< KisNodeSP > > FrameJobs
int fetchLayerActiveRasterFrameID(KisNodeSP node)
QSharedPointer< SplitAlphaToMaskInfo > SplitAlphaToMaskInfoSP
QSharedPointer< MergeDownInfo > MergeDownInfoSP
void sortMergeableNodes(KisNodeSP root, KisNodeList &inputNodes, KisNodeList &outputNodes)
QRect recursiveTightNodeVisibleBounds(KisNodeSP rootNode)
KisImageSP findImageByHierarchy(KisNodeSP node)
QSet< int > fetchLayerUniqueRasterTimesMatchingIDs(KisNodeSP node, QSet< int > &frameIDs)
KisNodeSP findNodeByName(KisNodeSP root, const QString &name)
KisNodeList filterInvisibleNodes(const KisNodeList &nodes, KisNodeList *invisibleNodes, KisNodeSP *putAfter)
void flattenLayer(KisImageSP image, KisLayerSP layer, MergeFlags flags)
QSet< int > fetchLayerRasterIDsAtTimes(KisNodeSP node, const QSet< int > &times)
KisNodeSP findRoot(KisNodeSP node)
QList< KisNodeSP > findNodesByName(KisNodeSP root, const QString &name, bool recursive, bool partialMatch)
QSharedPointer< ConvertToPaintLayerInfo > ConvertToPaintLayerInfoSP
KisNodeList findNodesWithProps(KisNodeSP root, const KoProperties &props, bool excludeRoot)
void addCopyOfNameTag(KisNodeSP node)
KisNodeSP findNodeByUuid(KisNodeSP root, const QUuid &uuid)
void newLayerFromVisible(KisImageSP image, KisNodeSP putAfter, MergeFlags flags)
void filterUnlockedNodes(KisNodeList &nodes)
void mergeMultipleLayersImpl(KisImageSP image, KisNodeList mergedNodes, KisNodeSP putAfter, bool flattenSingleLayer, const KUndo2MagicString &actionName, bool cleanupNodes=true, const QString layerName=QString(), MergeFlags flags=None)
bool canChangeImageProfileInvisibly(KisImageSP image)
void recursiveApplyNodes(NodePointer node, Functor func)
int fetchLayerActiveRasterFrameTime(KisNodeSP node)
void splitNonRemovableNodes(KisNodeList &nodesToRemove, KisNodeList &_nodesToHide)
KisNodeList sortAndFilterAnyMergeableNodesSafe(const KisNodeList &nodes, KisImageSP image)
void filterMergeableNodes(KisNodeList &nodes, bool allowMasks)
void forceAllHiddenOriginalsUpdate(KisNodeSP root)
QSet< int > fetchLayerIdenticalRasterFrameTimes(KisNodeSP node, const int &frameTime)
bool checkIsChildOf(KisNodeSP node, const KisNodeList &parents)
void updateFrameJobsNonRecursive(FrameJobs *jobs, KisNodeSP rootNode, bool frameTimesRecursive)
updateFrameJobsNonRecursive updates the frame jobs non-recursively, that is, on the rootNode only.
void refreshHiddenAreaAsync(KisImageSP image, KisNodeSP rootNode, const QRect &preparedArea)
void mergeMultipleLayers(KisImageSP image, KisNodeList mergedNodes, KisNodeSP putAfter, MergeFlags flags)
void mergeDown(KisImageSP image, KisLayerSP layer, const KisMetaData::MergeStrategy *strategy, MergeFlags flags)
bool tryMergeSelectionMasks(KisImageSP image, KisNodeList mergedNodes, KisNodeSP putAfter)
std::future< KisNodeSP > convertToPaintLayer(KisImageSP image, KisNodeSP src)
QSet< int > fetchLayerRasterFrameTimesMatchingID(KisNodeSP node, const int frameID)
void forceAllDelayedNodesUpdate(KisNodeSP root)
QSharedPointer< MergeDownInfoBase > MergeDownInfoBaseSP
QSet< int > fetchLayerFramesRecursive(KisNodeSP rootNode)
void fetchSelectionMasks(KisNodeList mergedNodes, QVector< KisSelectionMaskSP > &selectionMasks)
KisNodeList sortMergeableInternalNodes(KisNodeList nodes)
QSharedPointer< MergeMultipleInfo > MergeMultipleInfoSP
void mergeMultipleNodes(KisImageSP image, KisNodeList mergedNodes, KisNodeSP putAfter, MergeFlags flags)
auto then(std::future< T > &&future, Function &&func) -> std::future< decltype(func(std::move(future)))>
std::future< void > make_ready_future()
QMap< QString, KisKeyframeChannel * > keyframeChannels
QUuid uuid() const
virtual KisPaintDeviceSP projection() const =0
const QString & compositeOpId() const
bool isEditable(bool checkVisibility=true) const
bool isPinnedToTimeline() const
KisKeyframeChannel * getKeyframeChannel(const QString &id, bool create)
virtual QRect exactBounds() const
virtual KisPaintDeviceSP original() const =0
void setName(const QString &name)
KisImageWSP image
virtual QRect extent() const
bool userLocked() const
bool isAnimated() const
virtual KisPaintDeviceSP paintDevice() const =0
virtual PropertyList sectionModelProperties() const
QString name() const
void setCompositeOpId(const QString &compositeOpId)
virtual bool isFakeNode() const
quint8 opacity() const
bool check(const KoProperties &properties) const
virtual bool visible(bool recursive=false) const
virtual bool supportsKeyframeChannel(const QString &id)
KisLayerSP copyFrom
KisLayerSP reincarnateAsPaintLayer() const
The AggregateCommand struct is a command with delayed initialization. On first redo() populateChildCo...
void addCommand(KUndo2Command *cmd)
ActivateSelectionMask(MergeDownInfoBaseSP info)
MergeDownInfoBaseSP m_mergeInfo
AddNewFrame(KisNodeSP node, int frame, KisNodeSP source)
AddNewFrame(KisNodeSP node, int frame)
AddNewFrame(KisNodeSP node, int frame, KisNodeList sampleNodes)
void applyKeyframeColorLabel(KisKeyframeSP dstKeyframe, KisNodeList srcNodes)
AddNewFrame(MergeDownInfoBaseSP info, int frame)
static void findPerfectParent(KisNodeList nodesToDelete, KisNodeSP &putAfter, KisNodeSP &parent)
CleanUpNodes(MergeDownInfoBaseSP info, KisNodeSP putAfter, bool relinkClones=false)
void addCommandImpl(KUndo2Command *cmd) override
ConvertToPaintLayerInfo(KisImageSP image, KisNodeSP node)
SwitchFrameCommand::SharedStorageSP storage
CreateMergedLayerMultiple(MergeMultipleInfoSP info, const QString name=QString())
CreateMergedLayer(MergeDownInfoSP info)
DisableColorizeKeyStrokes(MergeDownInfoBaseSP info)
DisableExtraCompositing(MergeMultipleInfoSP info)
DisableOnionSkins(MergeDownInfoBaseSP info)
DisablePassThroughForHeadsOnly(MergeDownInfoBaseSP info, bool skipIfDstIsGroup=false)
EphemeralCommandsWrapper(MergeMultipleInfoSP info, QVector< KUndo2Command * > commands, bool cleanupNodes)
FillSelectionMasks(MergeDownInfoBaseSP info)
InitSplitAlphaSelectionMask(SplitAlphaToMaskInfoSP info)
void populateChildCommands() override
InsertNode(MergeDownInfoBaseSP info, KisNodeSP putAfter)
virtual void addCommandImpl(KUndo2Command *cmd)
KeepMergedNodesSelected(MergeDownInfoSP info, bool finalizing)
KeepMergedNodesSelected(MergeMultipleInfoSP info, KisNodeSP putAfter, bool finalizing)
SwitchFrameCommand::SharedStorageSP storage
QVector< KisSelectionMaskSP > selectionMasks
virtual KisNodeList allSrcNodes()=0
MergeDownInfo(KisImageSP _image, KisLayerSP _prevLayer, KisLayerSP _currLayer, MergeFlags flags)
KisNodeList allSrcNodes() override
MergeLayersMultiple(MergeMultipleInfoSP info)
MergeLayers(MergeDownInfoSP info, bool skipMergingSourceLayer)
void populateChildCommands() override
const KisMetaData::MergeStrategy * m_strategy
MergeMetaData(MergeDownInfoSP info, const KisMetaData::MergeStrategy *strategy)
MergeMultipleInfo(KisImageSP _image, KisNodeList _mergedNodes, MergeFlags flags)
QScopedPointer< KisSurrogateUndoStore > ephemeralCommandsStore
MergeSelectionMasks(MergeDownInfoBaseSP info, KisNodeSP putAfter)
RefreshDelayedUpdateLayers(MergeDownInfoBaseSP info)
RefreshHiddenAreas(KisImageSP image, KisNodeSP node)
RefreshHiddenAreas(MergeDownInfoBaseSP info, refresh_entire_image_t)
RefreshHiddenAreas(MergeDownInfoBaseSP info)
static constexpr refresh_entire_image_t refresh_entire_image
virtual void addCommandImpl(KUndo2Command *cmd)
SimpleAddNode(KisImageSP image, KisNodeSP toAdd, KisNodeSP parent=0, KisNodeSP putAfter=0)
SimpleRemoveLayers(const KisNodeList &nodes, KisImageSP image)
void addCommandImpl(KUndo2Command *cmd) override
SplitAlphaCommand(SplitAlphaToMaskInfoSP info)
SwitchFrameCommand::SharedStorageSP storage
SplitAlphaToMaskInfo(KisImageSP _image, KisNodeSP _node, const QString &maskName)
The SwitchFrameCommand struct Switches to frame with undo/redo support.
UndoEphemeralCommands(MergeMultipleInfoSP info)
UploadProjectionToFrameCommand(KisNodeSP src, KisNodeSP target, int frame)
void disableAlphaChannel(bool disable)
Definition kis_layer.cc:319
QBitArray channelFlags
Definition kis_layer.cc:167
virtual KisSelectionMaskSP selectionMask() const
Definition kis_layer.cc:504
bool alphaChannelDisabled() const
Definition kis_layer.cc:334
KisPSDLayerStyleSP layerStyle
Definition kis_layer.cc:171
const QList< KisCloneLayerWSP > registeredClones() const
Definition kis_layer.cc:484
void initSelection(KisSelectionSP copyFrom, KisLayerSP parentLayer)
initSelection initializes the selection for the mask from the given selection's projection.
Definition kis_mask.cc:157
KisPaintDeviceSP paintDevice() const override
Definition kis_mask.cc:223
KisNodeSP prevSibling() const
Definition kis_node.cpp:402
KisNodeSP firstChild() const
Definition kis_node.cpp:361
QList< KisNodeSP > childNodes(const QStringList &nodeTypes, const KoProperties &properties) const
Definition kis_node.cpp:439
virtual KisAbstractProjectionPlaneSP projectionPlane() const
Definition kis_node.cpp:240
KisProjectionLeafSP projectionLeaf
Definition kis_node.cpp:93
quint32 childCount() const
Definition kis_node.cpp:414
KisNodeWSP parent
Definition kis_node.cpp:86
KisNodeSP lastChild() const
Definition kis_node.cpp:367
KisNodeSP nextSibling() const
Definition kis_node.cpp:408
KisNodeGraphListener * graphListener
Definition kis_node.cpp:87
virtual void setDirty()
Definition kis_node.cpp:577
virtual bool allowAsChild(KisNodeSP) const =0
void setOnionSkinEnabled(bool state)
bool onionSkinEnabled() const
void setAlphaLocked(bool lock)
void applySelection(KisPixelSelectionSP selection, SelectionAction action)
void setSelection(KisSelectionSP selection)
Set the selection of this adjustment layer to a copy of selection.
KisPixelSelectionSP pixelSelection