Commit d7feb9ab authored by Wayne Stambaugh's avatar Wayne Stambaugh
Browse files

Initial Pcbnew s-expression file format commit.

* Add s-expression Format() function to all objects derived from
  BOARD_ITEM.
* Add s-expression Format() function to base objects as required.
* Add functions to convert coordinates from base internal units
  (nanometers) to millimeter string for writing to s-expression
  file.
* Add temporary dummy conversion functions to prevent link errors
  until schematic and board object and action code can be separated
  into DSO/DLL.
* Add CMake build option to build Pcbnew with nanometer internal
  units.
parent 57ede4af
Loading
Loading
Loading
Loading
+2 −0
Original line number Original line Diff line number Diff line
@@ -24,6 +24,8 @@ option(USE_PNG_BITMAPS "use PNG bitmaps instead of XPM (default ON)" ON)


option(USE_NEW_PCBNEW_LOAD "use new plugin support for legacy file format" OFF)
option(USE_NEW_PCBNEW_LOAD "use new plugin support for legacy file format" OFF)
option(USE_NEW_PCBNEW_SAVE "use new plugin support for legacy file format" OFF)
option(USE_NEW_PCBNEW_SAVE "use new plugin support for legacy file format" OFF)
option(USE_PCBNEW_NANOMETRES
       "Use nanometers for Pcbnew internal units instead of deci-mils (default OFF).")


# Russian GOST patch
# Russian GOST patch
option(wxUSE_UNICODE "enable/disable building unicode (default OFF)")
option(wxUSE_UNICODE "enable/disable building unicode (default OFF)")
+1 −1
Original line number Original line Diff line number Diff line
@@ -59,7 +59,7 @@


#cmakedefine USE_NEW_PCBNEW_LOAD
#cmakedefine USE_NEW_PCBNEW_LOAD
#cmakedefine USE_NEW_PCBNEW_SAVE
#cmakedefine USE_NEW_PCBNEW_SAVE

#cmakedefine USE_PCBNEW_NANAMETERS


/// The file format revision of the *.brd file created by this build
/// The file format revision of the *.brd file created by this build
#if defined(KICAD_NANOMETRE)
#if defined(KICAD_NANOMETRE)
+14 −0
Original line number Original line Diff line number Diff line
@@ -426,3 +426,17 @@ bool EDA_APP::OnInit()
void EDA_APP::MacOpenFile(const wxString &fileName)
void EDA_APP::MacOpenFile(const wxString &fileName)
{
{
}
}




/**
 * @copydoc
 *
 * This is a dummy since KiCad doesn't perform any interal unit formatting.
 */
/** @todo Remove FormatBIU() when the common DSO/DSL code is implemented. */
std::string FormatBIU( int aValue )
{
    return "";
}
+88 −0
Original line number Original line Diff line number Diff line
@@ -32,6 +32,7 @@
#include <trigo.h>
#include <trigo.h>
#include <common.h>
#include <common.h>
#include <macros.h>
#include <macros.h>
#include <kicad_string.h>
#include <wxstruct.h>
#include <wxstruct.h>
#include <class_drawpanel.h>
#include <class_drawpanel.h>
#include <class_base_screen.h>
#include <class_base_screen.h>
@@ -223,6 +224,14 @@ EDA_ITEM& EDA_ITEM::operator=( const EDA_ITEM& aItem )
}
}




void EDA_ITEM::Format( OUTPUTFORMATTER* aFormatter, int aNestLevel, int aControlBits ) const
    throw( IO_ERROR )
{
    wxFAIL_MSG( wxString::Format( wxT( "Format method not defined for item type %s." ),
                                  GetChars( GetClass() ) ) );
}


#if defined(DEBUG)
#if defined(DEBUG)


// A function that should have been in wxWidgets
// A function that should have been in wxWidgets
@@ -546,6 +555,85 @@ wxString EDA_TEXT::GetTextStyleName()
}
}




bool EDA_TEXT::IsDefaultFormatting() const
{
    return (  ( m_Size.x == DEFAULT_SIZE_TEXT )
           && ( m_Size.y == DEFAULT_SIZE_TEXT )
           && ( m_Attributs == 0 )
           && ( m_Mirror == false )
           && ( m_HJustify == GR_TEXT_HJUSTIFY_CENTER )
           && ( m_VJustify == GR_TEXT_VJUSTIFY_CENTER )
           && ( m_Thickness == 0 )
           && ( m_Italic == false )
           && ( m_Bold == false )
           && ( m_MultilineAllowed == false ) );
}


void EDA_TEXT::Format( OUTPUTFORMATTER* aFormatter, int aNestLevel, int aControlBits ) const
    throw( IO_ERROR )
{
    aFormatter->Print( aNestLevel, "(text %s (at %s",
                       EscapedUTF8( m_Text ).c_str(), FormatBIU( m_Pos ).c_str() );

    if( m_Orient != 0.0 )
        aFormatter->Print( aNestLevel, "%0.1f", m_Orient );

    aFormatter->Print( aNestLevel, ")\n" );

    if( !IsDefaultFormatting() )
    {
        aFormatter->Print( aNestLevel+1, "(effects\n" );

        if( ( m_Size.x != DEFAULT_SIZE_TEXT ) || ( m_Size.y != DEFAULT_SIZE_TEXT ) || m_Bold
          || m_Italic )
        {
            aFormatter->Print( aNestLevel+2, "(font" );

            // Add font support here at some point in the future.

            if( ( m_Size.x != DEFAULT_SIZE_TEXT ) || ( m_Size.y != DEFAULT_SIZE_TEXT ) )
                aFormatter->Print( aNestLevel+2, " (size %s)", FormatBIU( m_Size ).c_str() );

            if( m_Bold )
                aFormatter->Print( aNestLevel+2, " bold" );

            if( m_Bold )
                aFormatter->Print( aNestLevel+2, " italic" );

            aFormatter->Print( aNestLevel+1, ")\n");
        }

        if( m_Mirror || ( m_HJustify != GR_TEXT_HJUSTIFY_CENTER )
          || ( m_VJustify != GR_TEXT_VJUSTIFY_CENTER ) )
        {
            aFormatter->Print( aNestLevel+2, "(justify");

            if( m_HJustify != GR_TEXT_HJUSTIFY_CENTER )
                aFormatter->Print( aNestLevel+2,
                                   (m_HJustify == GR_TEXT_HJUSTIFY_LEFT) ? " left" : " right" );

            if( m_VJustify != GR_TEXT_VJUSTIFY_CENTER )
                aFormatter->Print( aNestLevel+2,
                                   (m_VJustify == GR_TEXT_VJUSTIFY_TOP) ? " top" : " bottom" );

            if( m_Mirror )
                aFormatter->Print( aNestLevel+2, " mirror" );

            aFormatter->Print( aNestLevel+2, ")\n" );
        }

        // As of now the only place this is used is in Eeschema to hide or show the text.
        if( m_Attributs )
            aFormatter->Print( aNestLevel+2, "hide" );

        aFormatter->Print( aNestLevel+1, "\n)\n" );
    }

    aFormatter->Print( aNestLevel, ")\n" );
}


/******************/
/******************/
/* Class EDA_RECT */
/* Class EDA_RECT */
/******************/
/******************/
+21 −0
Original line number Original line Diff line number Diff line
@@ -24,6 +24,8 @@




#include <common.h>
#include <common.h>
#include <macros.h>



// late arriving wxPAPER_A0, wxPAPER_A1
// late arriving wxPAPER_A0, wxPAPER_A1
#if wxABI_VERSION >= 20999
#if wxABI_VERSION >= 20999
@@ -309,3 +311,22 @@ void PAGE_INFO::SetHeightMils( int aHeightInMils )
    }
    }
}
}



void PAGE_INFO::Format( OUTPUTFORMATTER* aFormatter, int aNestLevel, int aControlBits ) const
    throw( IO_ERROR )
{
    // If page is A3 landscape, then it is assumed to be the default and is not written.
    if( !IsDefault() )
    {
        aFormatter->Print( aNestLevel, "(page %s", TO_UTF8( GetType() ) );

        // The page dimensions are only required for user defined page sizes.
        if( GetType() == PAGE_INFO::Custom )
            aFormatter->Print( aNestLevel, " %d %d", GetWidthMils(), GetHeightMils() );

        if( IsCustom() && IsPortrait() )
            aFormatter->Print( aNestLevel, " portrait" );

        aFormatter->Print( aNestLevel, ")\n" );
    }
}
Loading