diff --git a/common/geometry/shape_file_io.cpp b/common/geometry/shape_file_io.cpp index 24d0225da0..a87fd744fb 100644 --- a/common/geometry/shape_file_io.cpp +++ b/common/geometry/shape_file_io.cpp @@ -28,62 +28,119 @@ #include #include -SHAPE_FILE_IO::SHAPE_FILE_IO( const std::string& aFilename, bool aAppend ) +SHAPE_FILE_IO::SHAPE_FILE_IO( const std::string& aFilename, SHAPE_FILE_IO::IO_MODE aMode ) { m_groupActive = false; if( aFilename.length() ) - m_file = fopen ( aFilename.c_str(), aAppend ? "ab" : "wb" ); + { + switch( aMode ) + { + case IOM_READ: m_file = fopen( aFilename.c_str(), "rb" ); break; + case IOM_WRITE: m_file = fopen( aFilename.c_str(), "wb" ); break; + case IOM_APPEND: m_file = fopen( aFilename.c_str(), "ab" ); break; + default: + return; + } + } else + { m_file = NULL; + } + m_mode = aMode; // fixme: exceptions } + SHAPE_FILE_IO::~SHAPE_FILE_IO() { - if(!m_file) + if( !m_file ) return; - if (m_groupActive) - fprintf(m_file,"endgroup\n"); + if( m_groupActive && m_mode != IOM_READ ) + fprintf( m_file, "endgroup\n" ); - fclose(m_file); + fclose( m_file ); } -SHAPE *SHAPE_FILE_IO::Read() + +SHAPE* SHAPE_FILE_IO::Read() { - assert(false); + /* char tmp[1024]; + + do { + + if (fscanf(m_file, "%s", tmp) != 1) + return NULL; + + if( !strcmp( tmp, "shape" ) + break; + } + + int type; + + SHAPE *rv = NULL; + + fscanf(m_file,"%d %s", &type, tmp); + + printf("create shape %d\n", type); + + switch(type) + { + case SHAPE::LINE_CHAIN: + rv = new SHAPE_LINE_CHAIN; + break; + } + + if(!rv) + return NULL; + + rv.Parse ( ) + + fprintf(m_file,"shape %d %s %s\n", aShape->Type(), aName.c_str(), sh.c_str() ); +*/ + assert( false ); return NULL; } + void SHAPE_FILE_IO::BeginGroup( const std::string aName ) { - if(!m_file) + assert( m_mode != IOM_READ ); + + if( !m_file ) return; - fprintf(m_file, "group %s\n", aName.c_str()); + + fprintf( m_file, "group %s\n", aName.c_str() ); m_groupActive = true; } + void SHAPE_FILE_IO::EndGroup() { - if(!m_file || !m_groupActive) + assert( m_mode != IOM_READ ); + + if( !m_file || !m_groupActive ) return; - fprintf(m_file, "endgroup\n"); + fprintf( m_file, "endgroup\n" ); m_groupActive = false; } -void SHAPE_FILE_IO::Write( const SHAPE *aShape, const std::string aName ) + +void SHAPE_FILE_IO::Write( const SHAPE* aShape, const std::string aName ) { - if(!m_file) + assert( m_mode != IOM_READ ); + + if( !m_file ) return; - if(!m_groupActive) - fprintf(m_file,"group default\n"); + if( !m_groupActive ) + fprintf( m_file,"group default\n" ); std::string sh = aShape->Format(); - fprintf(m_file,"shape %d %s %s\n", aShape->Type(), aName.c_str(), sh.c_str() ); - fflush(m_file); -} + fprintf( m_file, "shape %d %s %s\n", aShape->Type(), aName.c_str(), sh.c_str() ); + fflush( m_file ); +} \ No newline at end of file diff --git a/common/geometry/shape_line_chain.cpp b/common/geometry/shape_line_chain.cpp index c9e5431ac9..a097b0b003 100644 --- a/common/geometry/shape_line_chain.cpp +++ b/common/geometry/shape_line_chain.cpp @@ -559,3 +559,22 @@ SHAPE* SHAPE_LINE_CHAIN::Clone() const { return new SHAPE_LINE_CHAIN( *this ); } + +bool SHAPE_LINE_CHAIN::Parse( std::stringstream& aStream ) +{ + int n_pts; + + m_points.clear(); + aStream >> n_pts; + aStream >> m_closed; + + for( int i = 0; i < n_pts; i++ ) + { + int x, y; + aStream >> x; + aStream >> y; + m_points.push_back( VECTOR2I( x, y ) ); + } + + return true; +} \ No newline at end of file diff --git a/include/geometry/shape_file_io.h b/include/geometry/shape_file_io.h index 5df105aa64..78784d74ea 100644 --- a/include/geometry/shape_file_io.h +++ b/include/geometry/shape_file_io.h @@ -38,24 +38,32 @@ class SHAPE; class SHAPE_FILE_IO { public: - SHAPE_FILE_IO ( const std::string& aFilename, bool aAppend = false ); - ~SHAPE_FILE_IO ( ); - - void BeginGroup( const std::string aName = ""); - void EndGroup( ); - - SHAPE *Read(); - - void Write ( const SHAPE *aShape, const std::string aName = ""); - - void Write ( const SHAPE &aShape, const std::string aName = "") + enum IO_MODE { - Write( &aShape, aName ); + IOM_READ = 0, + IOM_APPEND, + IOM_WRITE }; + SHAPE_FILE_IO( const std::string& aFilename, IO_MODE aMode = IOM_READ ); + ~SHAPE_FILE_IO(); + + void BeginGroup( const std::string aName = ""); + void EndGroup(); + + SHAPE* Read(); + + void Write( const SHAPE* aShape, const std::string aName = "" ); + + void Write( const SHAPE& aShape, const std::string aName = "" ) + { + Write( &aShape, aName ); + } + private: - FILE *m_file; + FILE* m_file; bool m_groupActive; + IO_MODE m_mode; }; #endif diff --git a/include/geometry/shape_line_chain.h b/include/geometry/shape_line_chain.h index 6b9632c94e..ae2bf5e0a2 100644 --- a/include/geometry/shape_line_chain.h +++ b/include/geometry/shape_line_chain.h @@ -554,6 +554,9 @@ public: /// @copydoc SHAPE::Format() const std::string Format() const; + /// @copydoc SHAPE::Parse() + bool Parse( std::stringstream& aStream ); + bool operator!=( const SHAPE_LINE_CHAIN& aRhs ) const { if( PointCount() != aRhs.PointCount() ) diff --git a/pcbnew/zones_convert_brd_items_to_polygons_with_Boost.cpp b/pcbnew/zones_convert_brd_items_to_polygons_with_Boost.cpp index 553bdde54c..1773f16aff 100644 --- a/pcbnew/zones_convert_brd_items_to_polygons_with_Boost.cpp +++ b/pcbnew/zones_convert_brd_items_to_polygons_with_Boost.cpp @@ -406,7 +406,7 @@ void ZONE_CONTAINER::AddClearanceAreasPolygonsToPolysList_NG( BOARD* aPcb ) std::auto_ptr dumper( new SHAPE_FILE_IO( - g_DumpZonesWhenFilling ? "zones_dump.txt" : "", true ) ); + g_DumpZonesWhenFilling ? "zones_dump.txt" : "", SHAPE_FILE_IO::IOM_APPEND ) ); // Set the number of segments in arc approximations if( m_ArcToSegmentsCount == ARC_APPROX_SEGMENTS_COUNT_HIGHT_DEF )