* Transform an area fill pattern sequence for OCD structure export. * * In Mapper, fill patterns are point symbols which are placed at certain offsets * and which are repeated in X and Y direction. OCD format does not support such * offsets, so we must move the point symbols elements instead. * * In addition, Mappper allows multiple explicit fill patterns. OCD format does * not support su
| 232 | * even if no adjustments are necessary. |
| 233 | */ |
| 234 | std::unique_ptr<PointSymbol> postProcessFillPattern(const FillPatternSequence& patterns, int structure_mode) |
| 235 | { |
| 236 | auto* first_point_pattern = patterns.front(); |
| 237 | auto point_symbol = duplicate(*first_point_pattern->point); |
| 238 | |
| 239 | // If the (cloned) first point pattern has non-zero offsets, |
| 240 | // we must apply them to the elements. |
| 241 | if (first_point_pattern->line_offset != 0 |
| 242 | || first_point_pattern->offset_along_line != 0) |
| 243 | { |
| 244 | for (int i = 0, last = point_symbol->getNumElements(); i < last; ++i) |
| 245 | { |
| 246 | if (auto* element = point_symbol->getElementObject(i)) |
| 247 | element->move(first_point_pattern->line_offset, first_point_pattern->offset_along_line); |
| 248 | } |
| 249 | if ((point_symbol->getInnerRadius() > 0 && point_symbol->getInnerColor()) |
| 250 | || (point_symbol->getOuterWidth() > 0 && point_symbol->getOuterColor())) |
| 251 | { |
| 252 | // The central dot/circle must be converted to an explicit element to apply the offset. |
| 253 | auto* primary_element = new PointSymbol(); |
| 254 | primary_element->setInnerRadius(point_symbol->getInnerRadius()); |
| 255 | primary_element->setInnerColor(point_symbol->getInnerColor()); |
| 256 | primary_element->setOuterWidth(point_symbol->getOuterWidth()); |
| 257 | primary_element->setOuterColor(point_symbol->getOuterColor()); |
| 258 | auto* object = new PointObject(primary_element); |
| 259 | object->setPosition(first_point_pattern->line_offset, first_point_pattern->offset_along_line); |
| 260 | point_symbol->addElement(0, object, primary_element); |
| 261 | // Now, the central dot/circle have been replaced by primary_element. |
| 262 | point_symbol->setInnerColor(nullptr); |
| 263 | point_symbol->setOuterColor(nullptr); |
| 264 | } |
| 265 | } |
| 266 | |
| 267 | // Any remaining point patterns must be appended to the elements of |
| 268 | // point_symbol, applying offsets if needed, ... |
| 269 | using std::begin; using std::end; |
| 270 | auto first = begin(patterns) + 1; |
| 271 | auto last = end(patterns); |
| 272 | |
| 273 | // ... except for the second pattern when the OCD structure is "shifted rows". |
| 274 | if (structure_mode == Ocd::StructureShiftedRows) |
| 275 | { |
| 276 | FILEFORMAT_ASSERT(patterns.size() == 2); |
| 277 | if (first != last) |
| 278 | ++first; |
| 279 | } |
| 280 | |
| 281 | auto i = point_symbol->getNumElements(); |
| 282 | for (auto it = first; it != last; ++it) |
| 283 | { |
| 284 | auto const* pattern = *it; |
| 285 | auto const* pattern_symbol = pattern->point; |
| 286 | if ((pattern_symbol->getInnerRadius() > 0 && pattern_symbol->getInnerColor()) |
| 287 | || (pattern_symbol->getOuterWidth() > 0 && pattern_symbol->getOuterColor())) |
| 288 | { |
| 289 | auto* primary_element = new PointSymbol(); |
| 290 | primary_element->setInnerRadius(pattern_symbol->getInnerRadius()); |
| 291 | primary_element->setInnerColor(pattern_symbol->getInnerColor()); |
no test coverage detected