Krita Source Code Documentation
Loading...
Searching...
No Matches
KisPipeBrushParasite Class Reference

#include <kis_pipebrush_parasite.h>

Public Types

enum  Placement { DefaultPlacement , ConstantPlacement , RandomPlacement }
 

Public Member Functions

void init ()
 
 KisPipeBrushParasite ()
 Set some default values.
 
 KisPipeBrushParasite (QStringView source)
 Load the parasite from the source string.
 
bool loadFromDevice (QIODevice *dev)
 
void sanitize ()
 
bool saveToDevice (QIODevice *dev) const
 
void setBrushesCount ()
 Initializes the brushesCount helper.
 

Public Attributes

qint32 brushesCount [MaxDim]
 The total count of brushes in each dimension (helper)
 
qint32 dim {0}
 
qint32 index [MaxDim]
 The current index in each dimension, so that the selection modes know where to start.
 
qint32 ncells {0}
 
bool needsMovement {false}
 If true, the brush won't be painted when there is no motion.
 
qint32 rank [MaxDim] {}
 
KisParasite::SelectionMode selection [MaxDim]
 
QString selectionMode
 

Static Public Attributes

static int const MaxDim = 4
 

Detailed Description

The parasite info that gets loaded from the terribly documented gimp pipe brush parasite.

We only store data we actually use.

BC: How it seems the dimension stuff interacts with rank, selectionMode and the actual selection of a brush to be drawn. So apparently you can have at most 4 'dimensions'. Each dimension has a number of brushes, the rank. Each dimension has an associated selection mode and placement mode (which we don't use). The selection mode says us in which way which of the brushes or brush sets will be selected. In the case of a 1-dimensional pipe brush it is easy.

However, when there are more dimensions it is a bit harder. You can according to the gimp source maximally use 4 dimensions. When you want to select a brush, you first go to the first dimension. Say it has a rank of 2. The code chooses one of the 2 according to the selection mode. Say we choose 2. Then the currentBrush will skip over all the brushes from the first element in dimension 1. Then in dimension we pick again from the choices we have in dimension 2. We again add the appropriate amount to currentBrush. And so on, until we have reached dimension dim. Or at least, that is how it looks like, we'll know for sure when we can test it better with >1 dim brushes and Angular selectionMode.

Definition at line 48 of file kis_pipebrush_parasite.h.

Member Enumeration Documentation

◆ Placement

Enumerator
DefaultPlacement 
ConstantPlacement 
RandomPlacement 

Definition at line 74 of file kis_pipebrush_parasite.h.

Constructor & Destructor Documentation

◆ KisPipeBrushParasite() [1/2]

KisPipeBrushParasite::KisPipeBrushParasite ( )
inline

Set some default values.

Definition at line 52 of file kis_pipebrush_parasite.h.

53 : ncells(0)
54 , dim(0)
55 , needsMovement(false) {
56 init();
57 }
bool needsMovement
If true, the brush won't be painted when there is no motion.

◆ KisPipeBrushParasite() [2/2]

KisPipeBrushParasite::KisPipeBrushParasite ( QStringView source)

Load the parasite from the source string.

Definition at line 11 of file kis_pipebrush_parasite.cpp.

12{
13 init();
14 needsMovement = false;
15
16 const QList<QStringView> parasites = source.split(QLatin1Char(' '), Qt::SkipEmptyParts);
17
18 for (int i = 0; i < parasites.count(); i++) {
19 const QList<QStringView> split = parasites.at(i).split(QLatin1Char(':'), Qt::SkipEmptyParts);
20
21 if (split.count() != 2) {
22 warnImage << "Wrong count for this parasite key/value:" << parasites.at(i);
23 continue;
24 }
25 const QStringView &index = split.at(0);
26 if (index == QLatin1String("dim")) {
27 dim = (split.at(1)).toInt();
29 dim = 1;
30 }
31 } else if (index.startsWith(QLatin1String("sel"))) {
32 int selIndex = index.mid(strlen("sel")).toInt();
33
34 if (selIndex >= 0 && selIndex < dim) {
35 selectionMode = split.at(1).toString();
36
37 if (selectionMode == QLatin1String("incremental")) {
39 } else if (selectionMode == QLatin1String("angular")) {
41 needsMovement = true;
42 } else if (selectionMode == QLatin1String("random")) {
44 } else if (selectionMode == QLatin1String("pressure")) {
46 } else if (selectionMode == QLatin1String("xtilt")) {
48 } else if (selectionMode == QLatin1String("ytilt")) {
50 } else if (selectionMode == QLatin1String("velocity")) {
52 } else {
54 }
55 }
56 else {
57 warnImage << "Sel: wrong index: " << selIndex << "(dim = " << dim << ")";
58 }
59 } else if (index.startsWith(QLatin1String("rank"))) {
60 int rankIndex = index.mid(strlen("rank")).toInt();
62 warnImage << "Rankindex out of range: " << rankIndex;
63 continue;
64 }
65 rank[rankIndex] = (split.at(1)).toInt();
66 } else if (index == QLatin1String("ncells")) {
67 ncells = (split.at(1)).toInt();
68 if (ncells < 1) {
69 warnImage << "ncells out of range: " << ncells;
70 ncells = 1;
71 }
72 }
73 }
74
75 for (int i = 0; i < dim; i++) {
76 index[i] = 0;
77 }
78
80}
KisMagneticGraph::vertex_descriptor source(typename KisMagneticGraph::edge_descriptor e, KisMagneticGraph g)
KisParasite::SelectionMode selection[MaxDim]
void setBrushesCount()
Initializes the brushesCount helper.
qint32 index[MaxDim]
The current index in each dimension, so that the selection modes know where to start.
#define warnImage
Definition kis_debug.h:88
QList< KoSubpath * > split(const KoPathShape &path)
int toInt(const QString &str, bool *ok=nullptr)

References KisParasite::Angular, KisParasite::Constant, dim, KisParasite::Incremental, index, init(), MaxDim, ncells, needsMovement, KisParasite::Pressure, KisParasite::Random, rank, selection, selectionMode, setBrushesCount(), source(), KisParasite::TiltX, KisParasite::TiltY, KisParasite::Velocity, and warnImage.

Member Function Documentation

◆ init()

void KisPipeBrushParasite::init ( )

Definition at line 82 of file kis_pipebrush_parasite.cpp.

83{
84 for (int i = 0; i < MaxDim; i++) {
85 rank[i] = index[i] = brushesCount[i] = 0;
87 }
88}
qint32 brushesCount[MaxDim]
The total count of brushes in each dimension (helper)

References brushesCount, KisParasite::Constant, index, MaxDim, rank, and selection.

◆ loadFromDevice()

bool KisPipeBrushParasite::loadFromDevice ( QIODevice * dev)

◆ sanitize()

void KisPipeBrushParasite::sanitize ( )

Definition at line 90 of file kis_pipebrush_parasite.cpp.

91{
92 for (int i = 0; i < dim; i++) {
93 // In the 2 listed cases, we'd divide by 0!
94 if (rank[i] == 0 &&
97
98 warnImage << "PIPE brush has a wrong rank for its selection mode!";
100 }
101 }
102}

References KisParasite::Angular, KisParasite::Constant, dim, KisParasite::Incremental, rank, selection, and warnImage.

◆ saveToDevice()

bool KisPipeBrushParasite::saveToDevice ( QIODevice * dev) const

Saves a GIMP-compatible representation of this parasite to the device. Also writes the number of brushes (== ncells) (no trailing '
')

Definition at line 124 of file kis_pipebrush_parasite.cpp.

125{
126 // write out something like
127 // <count> ncells:<count> dim:<dim> rank0:<rank0> sel0:<sel0> <...>
128
129 QTextStream stream(dev);
131
132 // XXX: FIXME things like step, placement and so are not added (nor loaded, as a matter of fact)"
133 stream << ncells << " ncells:" << ncells << " dim:" << dim;
134
135 for (int i = 0; i < dim; i++) {
136 stream << " rank" << i << ":" << rank[i] << " sel" << i << ":";
137 switch (selection[i]) {
139 stream << "constant"; break;
141 stream << "incremental"; break;
143 stream << "angular"; break;
145 stream << "velocity"; break;
147 stream << "random"; break;
149 stream << "pressure"; break;
151 stream << "xtilt"; break;
153 stream << "ytilt"; break;
154 }
155 }
156
157 return true;
158}
void setUtf8OnStream(QTextStream &stream)

References KisParasite::Angular, KisParasite::Constant, dim, KisParasite::Incremental, ncells, KisParasite::Pressure, KisParasite::Random, rank, selection, KisPortingUtils::setUtf8OnStream(), KisParasite::TiltX, KisParasite::TiltY, and KisParasite::Velocity.

◆ setBrushesCount()

void KisPipeBrushParasite::setBrushesCount ( )

Initializes the brushesCount helper.

Definition at line 104 of file kis_pipebrush_parasite.cpp.

105{
106 // I assume ncells is correct. If it isn't, complain to the parasite header.
107 if (rank[0] != 0) {
108 brushesCount[0] = ncells / rank[0];
109 }
110 else {
111 brushesCount[0] = ncells;
112 }
113
114 for (int i = 1; i < dim; i++) {
115 if (rank[i] == 0) {
116 brushesCount[i] = brushesCount[i - 1];
117 }
118 else {
119 brushesCount[i] = brushesCount[i - 1] / rank[i];
120 }
121 }
122}

References brushesCount, dim, ncells, and rank.

Member Data Documentation

◆ brushesCount

qint32 KisPipeBrushParasite::brushesCount[MaxDim]

The total count of brushes in each dimension (helper)

Definition at line 94 of file kis_pipebrush_parasite.h.

◆ dim

qint32 KisPipeBrushParasite::dim {0}

Definition at line 80 of file kis_pipebrush_parasite.h.

80{0};

◆ index

qint32 KisPipeBrushParasite::index[MaxDim]

The current index in each dimension, so that the selection modes know where to start.

Definition at line 97 of file kis_pipebrush_parasite.h.

◆ MaxDim

int const KisPipeBrushParasite::MaxDim = 4
static

Definition at line 76 of file kis_pipebrush_parasite.h.

◆ ncells

qint32 KisPipeBrushParasite::ncells {0}

Definition at line 79 of file kis_pipebrush_parasite.h.

79{0};

◆ needsMovement

bool KisPipeBrushParasite::needsMovement {false}

If true, the brush won't be painted when there is no motion.

Definition at line 100 of file kis_pipebrush_parasite.h.

100{false};

◆ rank

qint32 KisPipeBrushParasite::rank[MaxDim] {}

Definition at line 88 of file kis_pipebrush_parasite.h.

88{};

◆ selection

KisParasite::SelectionMode KisPipeBrushParasite::selection[MaxDim]

Definition at line 90 of file kis_pipebrush_parasite.h.

◆ selectionMode

QString KisPipeBrushParasite::selectionMode

Definition at line 91 of file kis_pipebrush_parasite.h.


The documentation for this class was generated from the following files: