geometry: Parse() method for SHAPE_LINE_CHAIN, working on Read() in SHAPE_FILE_IO
This commit is contained in:
parent
9c2bcb2f3c
commit
07f5516e59
|
@ -28,62 +28,119 @@
|
||||||
#include <geometry/shape.h>
|
#include <geometry/shape.h>
|
||||||
#include <geometry/shape_file_io.h>
|
#include <geometry/shape_file_io.h>
|
||||||
|
|
||||||
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;
|
m_groupActive = false;
|
||||||
|
|
||||||
if( aFilename.length() )
|
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
|
else
|
||||||
|
{
|
||||||
m_file = NULL;
|
m_file = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_mode = aMode;
|
||||||
// fixme: exceptions
|
// fixme: exceptions
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
SHAPE_FILE_IO::~SHAPE_FILE_IO()
|
SHAPE_FILE_IO::~SHAPE_FILE_IO()
|
||||||
{
|
{
|
||||||
if(!m_file)
|
if( !m_file )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (m_groupActive)
|
if( m_groupActive && m_mode != IOM_READ )
|
||||||
fprintf(m_file,"endgroup\n");
|
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;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SHAPE_FILE_IO::BeginGroup( const std::string aName )
|
void SHAPE_FILE_IO::BeginGroup( const std::string aName )
|
||||||
{
|
{
|
||||||
if(!m_file)
|
assert( m_mode != IOM_READ );
|
||||||
|
|
||||||
|
if( !m_file )
|
||||||
return;
|
return;
|
||||||
fprintf(m_file, "group %s\n", aName.c_str());
|
|
||||||
|
fprintf( m_file, "group %s\n", aName.c_str() );
|
||||||
m_groupActive = true;
|
m_groupActive = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SHAPE_FILE_IO::EndGroup()
|
void SHAPE_FILE_IO::EndGroup()
|
||||||
{
|
{
|
||||||
if(!m_file || !m_groupActive)
|
assert( m_mode != IOM_READ );
|
||||||
|
|
||||||
|
if( !m_file || !m_groupActive )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
fprintf(m_file, "endgroup\n");
|
fprintf( m_file, "endgroup\n" );
|
||||||
m_groupActive = false;
|
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;
|
return;
|
||||||
|
|
||||||
if(!m_groupActive)
|
if( !m_groupActive )
|
||||||
fprintf(m_file,"group default\n");
|
fprintf( m_file,"group default\n" );
|
||||||
|
|
||||||
std::string sh = aShape->Format();
|
std::string sh = aShape->Format();
|
||||||
|
|
||||||
fprintf(m_file,"shape %d %s %s\n", aShape->Type(), aName.c_str(), sh.c_str() );
|
fprintf( m_file, "shape %d %s %s\n", aShape->Type(), aName.c_str(), sh.c_str() );
|
||||||
fflush(m_file);
|
fflush( m_file );
|
||||||
}
|
}
|
|
@ -559,3 +559,22 @@ SHAPE* SHAPE_LINE_CHAIN::Clone() const
|
||||||
{
|
{
|
||||||
return new SHAPE_LINE_CHAIN( *this );
|
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;
|
||||||
|
}
|
|
@ -38,24 +38,32 @@ class SHAPE;
|
||||||
class SHAPE_FILE_IO
|
class SHAPE_FILE_IO
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SHAPE_FILE_IO ( const std::string& aFilename, bool aAppend = false );
|
enum IO_MODE
|
||||||
~SHAPE_FILE_IO ( );
|
|
||||||
|
|
||||||
void BeginGroup( const std::string aName = "<noname>");
|
|
||||||
void EndGroup( );
|
|
||||||
|
|
||||||
SHAPE *Read();
|
|
||||||
|
|
||||||
void Write ( const SHAPE *aShape, const std::string aName = "<noname>");
|
|
||||||
|
|
||||||
void Write ( const SHAPE &aShape, const std::string aName = "<noname>")
|
|
||||||
{
|
{
|
||||||
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 = "<noname>");
|
||||||
|
void EndGroup();
|
||||||
|
|
||||||
|
SHAPE* Read();
|
||||||
|
|
||||||
|
void Write( const SHAPE* aShape, const std::string aName = "<noname>" );
|
||||||
|
|
||||||
|
void Write( const SHAPE& aShape, const std::string aName = "<noname>" )
|
||||||
|
{
|
||||||
|
Write( &aShape, aName );
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
FILE *m_file;
|
FILE* m_file;
|
||||||
bool m_groupActive;
|
bool m_groupActive;
|
||||||
|
IO_MODE m_mode;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -554,6 +554,9 @@ public:
|
||||||
/// @copydoc SHAPE::Format()
|
/// @copydoc SHAPE::Format()
|
||||||
const std::string Format() const;
|
const std::string Format() const;
|
||||||
|
|
||||||
|
/// @copydoc SHAPE::Parse()
|
||||||
|
bool Parse( std::stringstream& aStream );
|
||||||
|
|
||||||
bool operator!=( const SHAPE_LINE_CHAIN& aRhs ) const
|
bool operator!=( const SHAPE_LINE_CHAIN& aRhs ) const
|
||||||
{
|
{
|
||||||
if( PointCount() != aRhs.PointCount() )
|
if( PointCount() != aRhs.PointCount() )
|
||||||
|
|
|
@ -406,7 +406,7 @@ void ZONE_CONTAINER::AddClearanceAreasPolygonsToPolysList_NG( BOARD* aPcb )
|
||||||
|
|
||||||
|
|
||||||
std::auto_ptr<SHAPE_FILE_IO> dumper( new SHAPE_FILE_IO(
|
std::auto_ptr<SHAPE_FILE_IO> 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
|
// Set the number of segments in arc approximations
|
||||||
if( m_ArcToSegmentsCount == ARC_APPROX_SEGMENTS_COUNT_HIGHT_DEF )
|
if( m_ArcToSegmentsCount == ARC_APPROX_SEGMENTS_COUNT_HIGHT_DEF )
|
||||||
|
|
Loading…
Reference in New Issue