-
Notifications
You must be signed in to change notification settings - Fork 5
/
blocks.cpp
69 lines (56 loc) · 2.15 KB
/
blocks.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
* Read Blocks from file and convert to vectors of entities
*
* Author:
* Matt Squires <squiresm@colorado.edu>
*
* Copyright (C) 2005 Matt Squires
*
* Released under GNU GPL and LGPL, read the file 'GPL.txt' and 'LGPL.txt' for details
*/
#include "blocks.h"
#include <iostream>
#include <stdlib.h>
#include <string.h>
block::block(const std::vector<std::vector<dxfpair> > §ions) : entities(sections) {
// Inherit most of the functionality of the entitites section
basic_entity(sections[0]);
block_info(sections[0]);
}
const char* block::name() const {
return block_name.c_str();
}
void block::block_info(const std::vector<dxfpair> &info) {
for (const auto &i : info) {
switch(i.group_code) {
case 2: // Block name
block_name = i.value_str();
break;
}
}
}
blocks::blocks(const std::vector<std::vector<dxfpair> > §ions) {
// Read the main information about the entities section and then put it in the enetites class
size_t n_loop = sections.size();
n_loop--;
//for(int i = 0; i < (sections.size()-1); i++) { // It is odd but the last value seems to be bad so don't use it
// I am not really sure if I need the -1. I needed it once upon a time to make things work but I don't have time to test it well right now
// But sections.size() is an unsigned int so when you subtract 1 it becomes 4294967295 and tries to run the loop so work around that by making n_loop that is signed
for (int i = 0; i < n_loop; i++) { // It is odd but the last value seems to be bad so don't use it
std::vector<std::vector<dxfpair> > ents;
// Get everything from the start of the BLOCK designation to an ENDBLK value
if (strcmp(sections[i][0].value_char(), "BLOCK") == 0 && (i < sections.size())) {
do {
ents.push_back(sections[i]);
} while (strcmp(sections[++i][0].value_char(), "ENDBLK") != 0 && (i < sections.size()-1) );
blocks_blocks.push_back(block(ents));
}
}
}
const block &blocks::ret_block(const char *block_name) const {
for (const auto &b : blocks_blocks) {
if (strcmp(b.name(), block_name) == 0 )
return b;
}
return blocks_blocks[0];
}