summaryrefslogtreecommitdiffstats
path: root/src/extension/dxf2svg/blocks.cpp
blob: 75f348bde7904543ee7df746b2bfc2daf4929b61 (plain)
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
 * 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>

block::block(std::vector< std::vector< dxfpair > > sections) : entities( sections ){
	// Inherit most of the functionality of the entitites section
	
	basic_entity( sections[0] );
	block_info( sections[0] );
}

char* block::name(char* string){
	return( strcpy(string,block_name) );
}


void block::block_info( std::vector< dxfpair > info){
	static char string[10000];
	for (int i = 0; i < info.size(); i++){
		switch( info[i].group_code ){
			case 2: // Block name
				strcpy( string," "); // Clear the string out
				info[i].value_char(string);
				strcpy(block_name,string);
				break;
		}
	}
}






blocks::blocks(std::vector< std::vector< dxfpair > > sections){
	// Read the main information about the entities section and then put it in the enetites class
	int value;
	char string[10000];
	std::vector< dxfpair > single_line;
	std::vector< std::vector< dxfpair > > ents;
	ents.clear();
	single_line.clear();
	
	int 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
		sections[i][0].value_char(string);
		ents.clear();  // First clear out the pline information
		
		
		// Get everything from the start of the BLOCK designation to an ENDBLK value
		if ( strncmp(string,"BLOCK",5) == 0 && (i < sections.size())){
			do{
				ents.push_back( sections[i] );
				sections[++i][0].value_char(string);
			}while( strncmp(string,"ENDBLK",6) != 0  && (i < sections.size()-1) );
			blocks_blocks.push_back( block( ents ) );
		}
	}
}

block blocks::ret_block(char block_name[10000]){
	int string_len = 0;
	char temp[10000];
	
	for (int i = 0; i < blocks_blocks.size();i++){
		string_len = strlen(blocks_blocks[i].name(temp));	
		if (strncmp(blocks_blocks[i].name(temp),block_name,string_len) == 0 ) return blocks_blocks[i];	
	}
	return blocks_blocks[0];
}