Code

fix bug #1568462 boolean operation remove mask/clip-path
[inkscape.git] / src / extension / dxf2svg / blocks.cpp
1 /*
2  * Read Blocks from file and convert to vectors of entities
3  *
4  * Author:
5  *   Matt Squires <squiresm@colorado.edu>
6  *
7  * Copyright (C) 2005 Matt Squires
8  *
9  * Released under GNU GPL and LGPL, read the file 'GPL.txt' and 'LGPL.txt' for details
10  */
13 #include"blocks.h"
14 #include<iostream>
16 block::block(std::vector< std::vector< dxfpair > > sections) : entities( sections ){
17         // Inherit most of the functionality of the entitites section
18         
19         basic_entity( sections[0] );
20         block_info( sections[0] );
21 }
23 char* block::name(char* string){
24         return( strcpy(string,block_name) );
25 }
28 void block::block_info( std::vector< dxfpair > info){
29         static char string[10000];
30         for (int i = 0; i < info.size(); i++){
31                 switch( info[i].group_code ){
32                         case 2: // Block name
33                                 strcpy( string," "); // Clear the string out
34                                 info[i].value_char(string);
35                                 strcpy(block_name,string);
36                                 break;
37                 }
38         }
39 }
46 blocks::blocks(std::vector< std::vector< dxfpair > > sections){
47         // Read the main information about the entities section and then put it in the enetites class
48         int value;
49         char string[10000];
50         std::vector< dxfpair > single_line;
51         std::vector< std::vector< dxfpair > > ents;
52         ents.clear();
53         single_line.clear();
54         
55         int n_loop = sections.size();
56         n_loop--;
57         //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
58         // 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 
59         // 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
60         for(int i = 0; i < n_loop; i++){ // It is odd but the last value seems to be bad so don't use it
61                 sections[i][0].value_char(string);
62                 ents.clear();  // First clear out the pline information
63                 
64                 
65                 // Get everything from the start of the BLOCK designation to an ENDBLK value
66                 if ( strncmp(string,"BLOCK",5) == 0 && (i < sections.size())){
67                         do{
68                                 ents.push_back( sections[i] );
69                                 sections[++i][0].value_char(string);
70                         }while( strncmp(string,"ENDBLK",6) != 0  && (i < sections.size()-1) );
71                         blocks_blocks.push_back( block( ents ) );
72                 }
73         }
74 }
76 block blocks::ret_block(char block_name[10000]){
77         int string_len = 0;
78         char temp[10000];
79         
80         for (int i = 0; i < blocks_blocks.size();i++){
81                 string_len = strlen(blocks_blocks[i].name(temp));       
82                 if (strncmp(blocks_blocks[i].name(temp),block_name,string_len) == 0 ) return blocks_blocks[i];  
83         }
84         return blocks_blocks[0];
85 }