Commit 6d930ede authored by charras's avatar charras
Browse files

work in progress about ERC and markers in eeschema

parent 0d2ee0c0
Loading
Loading
Loading
Loading
+67 −88
Original line number Original line Diff line number Diff line
@@ -10,45 +10,48 @@
#include "gr_basic.h"
#include "gr_basic.h"
#include "class_base_screen.h"
#include "class_base_screen.h"
#include "common.h"
#include "common.h"
#include "macros.h"
#include "class_drawpanel.h"
#include "class_drawpanel.h"
#include "class_marker_base.h"
#include "class_marker_base.h"




/* Default bitmap shape for markers */
// Default marquer shape:
static char Default_MarkerBitmap[] =
#define M_SHAPE_SCALE 6     // default scaling factor for MarkerShapeCorners coordinates
#define CORNERS_COUNT 8
// corners of the default shape
static wxPoint MarkerShapeCorners[CORNERS_COUNT] =
{
{
    12, 12,                                 /* x and y size of the bitmap */
    wxPoint( 0,  0 ),
    1,  1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0,    /* bitmap: 1 = color, 0 = notrace */
    wxPoint( 8,  1 ),
    1,  1, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0,
    wxPoint( 4,  3 ),
    1,  1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0,
    wxPoint( 13, 8 ),
    1,  0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0,
    wxPoint( 9, 9 ),
    1,  1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0,
    wxPoint( 8,  13 ),
    1,  1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0,
    wxPoint( 3,  4 ),
    1,  1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0,
    wxPoint( 1,  8 )
    0,  0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0,
    0,  0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0,
    0,  0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0,
    0,  0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1,
    0,  0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0
};
};



/*******************/
/*******************/
/* Classe MARKER_BASE */
/* Classe MARKER_BASE */
/*******************/
/*******************/


void MARKER_BASE::init()
void MARKER_BASE::init()
{
{
    m_Bitmap = NULL;
    m_MarkerType = 0;
    m_MarkerType = 0;
    m_Color = RED;
    m_Color = RED;
    m_Bitmap = Default_MarkerBitmap;
    for( unsigned ii = 0; ii < CORNERS_COUNT; ii++ )
    m_Size.x = Default_MarkerBitmap[0];
    {
    m_Size.y = Default_MarkerBitmap[1];
        wxPoint corner = MarkerShapeCorners[ii];
        m_Corners.push_back( corner );
        m_Size.x = MAX( m_Size.x, corner.x);
        m_Size.y = MAX( m_Size.y, corner.y);
    }
}
}



MARKER_BASE::MARKER_BASE()
MARKER_BASE::MARKER_BASE()
{
{
    m_ScalingFactor = M_SHAPE_SCALE;
    init();
    init();
}
}


@@ -57,6 +60,7 @@ MARKER_BASE::MARKER_BASE( int aErrorCode, const wxPoint& aMarkerPos,
                          const wxString& aText, const wxPoint& aPos,
                          const wxString& aText, const wxPoint& aPos,
                          const wxString& bText, const wxPoint& bPos )
                          const wxString& bText, const wxPoint& bPos )
{
{
    m_ScalingFactor = M_SHAPE_SCALE;
    init();
    init();


    SetData( aErrorCode, aMarkerPos,
    SetData( aErrorCode, aMarkerPos,
@@ -64,11 +68,12 @@ MARKER_BASE::MARKER_BASE( int aErrorCode, const wxPoint& aMarkerPos,
             bText, bPos );
             bText, bPos );
}
}



MARKER_BASE::MARKER_BASE( int aErrorCode, const wxPoint& aMarkerPos,
MARKER_BASE::MARKER_BASE( int aErrorCode, const wxPoint& aMarkerPos,
                          const wxString& aText, const wxPoint& aPos )
                          const wxString& aText, const wxPoint& aPos )
{
{
    m_ScalingFactor = M_SHAPE_SCALE;
    init();
    init();

    SetData( aErrorCode, aMarkerPos, aText, aPos );
    SetData( aErrorCode, aMarkerPos, aText, aPos );
}
}


@@ -86,9 +91,6 @@ void MARKER_BASE::SetData( int aErrorCode, const wxPoint& aMarkerPos,
    m_Pos = aMarkerPos;
    m_Pos = aMarkerPos;
    m_drc.SetData( aErrorCode,
    m_drc.SetData( aErrorCode,
                   aText, bText, aPos, bPos );
                   aText, bText, aPos, bPos );

    // @todo: switch on error code to set error code specific color, and possibly bitmap.
    m_Color = WHITE;
}
}




@@ -98,78 +100,55 @@ void MARKER_BASE::SetData( int aErrorCode, const wxPoint& aMarkerPos,
    m_Pos = aMarkerPos;
    m_Pos = aMarkerPos;
    m_drc.SetData( aErrorCode,
    m_drc.SetData( aErrorCode,
                   aText, aPos );
                   aText, aPos );

    // @todo: switch on error code to set error code specific color, and possibly bitmap.
    m_Color = WHITE;
}
}





/**********************************************/
/**********************************************/
bool MARKER_BASE::HitTestMarker( const wxPoint& refPos )
bool MARKER_BASE::HitTestMarker( const wxPoint& refPos )
/**********************************************/
/**********************************************/
{
{
    // the MARKER_BASE is 12 pixels by 12 pixels, but is not resized with zoom, so
    int     dx = refPos.x - m_Pos.x;
    // as zoom changes, the effective real size (in user units) of the MARKER_BASE changes.
    int     dy = refPos.y - m_Pos.y;

    wxSize TrueSize = m_Size;
    if ( ActiveScreen )
    {
        ActiveScreen->Unscale( TrueSize );
    }

    wxPoint pos = m_Pos;


    int dx = refPos.x - pos.x;
    wxSize Realsize = m_Size;
    int dy = refPos.y - pos.y;
    Realsize.x *= m_ScalingFactor;
    Realsize.y *= m_ScalingFactor;


    /* is refPos in the box: Marker size to right an bottom,
    /* is refPos in the box: Marker size to right an bottom,
    or size/2 to left or top */
     *  or size/2 to left or top */
    if( dx <= TrueSize.x  && dy <= TrueSize.y &&
    if( dx <= Realsize.x  && dy <= Realsize.y
        dx >= -TrueSize.x/2  && dy >= -TrueSize.y/2 )
        && dx >= -Realsize.x / 2  && dy >= -Realsize.y / 2 )
        return true;
        return true;
    else
    else
        return false;
        return false;
}
}





/**********************************************************************/
/**********************************************************************/
void MARKER_BASE::DrawMarker( WinEDA_DrawPanel* panel, wxDC* DC, int DrawMode,
void MARKER_BASE::DrawMarker( WinEDA_DrawPanel* aPanel, wxDC* aDC, int aDrawMode,
                                                const wxPoint& offset )
                              const wxPoint& aOffset )
/**********************************************************************/
/**********************************************************************/


/*
/**  Function DrawMarker
 *  Trace un repere sur l'ecran au point de coordonnees PCB pos
 *  The shape is the polygon defined in m_Corners (array of wxPoints)
 *  Le marqueur est defini par un tableau de 2 + (lig*col) elements:
 *   1er element: dim nbre ligne
 *   2er element: dim nbre col
 *   suite: lig * col elements a 0 ou 1 : si 1 mise a color du pixel
 */
 */
{
{
    int   ii, jj;
    wxPoint corners[CORNERS_COUNT];
    char* pt_bitmap = m_Bitmap;

    if( pt_bitmap == NULL ) return;


    GRSetDrawMode( DC, DrawMode );
    GRSetDrawMode( aDC, aDrawMode );


    wxPoint pos = m_Pos;
    for( unsigned ii = 0; ii < m_Corners.size(); ii++ )
    pos.x = GRMapX( pos.x );
    pos.y = GRMapY( pos.y );

    /* Get the bitmap size */
    m_Size.x = *(pt_bitmap++);
    m_Size.y = *(pt_bitmap++);

    /* Draw the bitmap */
    for( ii = 0; ii < m_Size.x; ii++ )
    {
        for( jj = 0; jj < m_Size.y; jj++, pt_bitmap++ )
    {
    {
            if( *pt_bitmap )
        corners[ii] = m_Corners[ii];
                GRSPutPixel( &panel->m_ClipBox, DC,
        corners[ii].x *= m_ScalingFactor;
                             pos.x + ii, pos.y + jj, m_Color );
        corners[ii].y *= m_ScalingFactor;
        }
        corners[ii] += m_Pos + aOffset;
    }
    }

    GRClosedPoly( &aPanel->m_ClipBox, aDC, CORNERS_COUNT, corners,
                  true,         // = Filled
                  0,            // outline width
                  m_Color,      // outline color
                  m_Color       // fill collor
                  );
}
}
+1 −2
Original line number Original line Diff line number Diff line
@@ -5,7 +5,6 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}
                   )
                   )


set(EESCHEMA_SRCS
set(EESCHEMA_SRCS
#    affiche.cpp
    annotate.cpp
    annotate.cpp
    annotate_dialog.cpp
    annotate_dialog.cpp
    backanno.cpp
    backanno.cpp
@@ -21,6 +20,7 @@ set(EESCHEMA_SRCS
    class_libentry.cpp
    class_libentry.cpp
    class_libentry_fields.cpp
    class_libentry_fields.cpp
    class_library.cpp
    class_library.cpp
    class_marker_sch.cpp
    class_pin.cpp
    class_pin.cpp
    class_sch_cmp_field.cpp
    class_sch_cmp_field.cpp
    class_schematic_items.cpp
    class_schematic_items.cpp
@@ -62,7 +62,6 @@ set(EESCHEMA_SRCS
    edit_component_in_schematic.cpp
    edit_component_in_schematic.cpp
    edit_label.cpp
    edit_label.cpp
    eeconfig.cpp
    eeconfig.cpp
#   eecreate.cpp
    eelayer.cpp
    eelayer.cpp
    eelibs_draw_components.cpp
    eelibs_draw_components.cpp
    eelibs_read_libraryfiles.cpp
    eelibs_read_libraryfiles.cpp
+1 −0
Original line number Original line Diff line number Diff line
@@ -16,6 +16,7 @@
#include "libcmp.h"
#include "libcmp.h"
#include "general.h"
#include "general.h"
#include "protos.h"
#include "protos.h"
#include "class_marker_sch.h"




/* Variables Locales */
/* Variables Locales */
+127 −0
Original line number Original line Diff line number Diff line
/***********************************************************************/
/* Methodes de base de gestion des classes des elements de schematique */
/***********************************************************************/

#include "fctsys.h"
#include "class_drawpanel.h"

#include "common.h"
#include "program.h"
#include "general.h"

#include "class_marker_sch.h"
#include "erc.h"


/* Marker are mainly used to show an ERC error
 * but they could be used to give a specifi info
*/


const wxChar* NameMarqueurType[] =
{
    wxT( "" ),
    wxT( "ERC" ),
    wxT( "PCB" ),
    wxT( "SIMUL" ),
    wxT( "?????" )
};


/**************************/
/* class MARKER_SCH */
/**************************/

MARKER_SCH::MARKER_SCH( ) :
    SCH_ITEM( NULL, DRAW_MARKER_STRUCT_TYPE ),
    MARKER_BASE( )
{
}

MARKER_SCH::MARKER_SCH( const wxPoint& pos, const wxString& text ) :
    SCH_ITEM( NULL, DRAW_MARKER_STRUCT_TYPE ),
    MARKER_BASE(0, pos, text, pos)
{
}


MARKER_SCH::~MARKER_SCH()
{
}


MARKER_SCH* MARKER_SCH::GenCopy()
{
    MARKER_SCH* newitem = new MARKER_SCH( GetPos(), GetErrorText() );

    newitem->SetMarkerType( GetMarkerType());
    newitem->SetErrorLevel( GetErrorLevel());

    return newitem;
}



#if defined(DEBUG)

/**
 * Function Show
 * is used to output the object tree, currently for debugging only.
 * @param nestLevel An aid to prettier tree indenting, and is the level
 *          of nesting of this object within the overall tree.
 * @param os The ostream& to output to.
 */
void MARKER_SCH::Show( int nestLevel, std::ostream& os )
{
    // for now, make it look like XML:
    NestedSpace( nestLevel, os ) << '<' << GetClass().Lower().mb_str() << GetPos()
                                 << "/>\n";
}


#endif

/**
 * Function Save
 * writes the data structures for this object out to a FILE in "*.brd" format.
 * @param aFile The FILE to write to.
 * @return bool - true if success writing else false.
 */
bool MARKER_SCH::Save( FILE* aFile ) const
{
    bool success = true;
    wxString msg = GetErrorText();
    if( fprintf( aFile, "Kmarq %c %-4d %-4d \"%s\" F=%X\n",
                 GetMarkerType() + 'A', GetPos().x, GetPos().y,
                 CONV_TO_UTF8( msg ), GetErrorLevel() ) == EOF )
    {
        success = false;
    }

    return success;
}


/****************************************************************************/
void MARKER_SCH::Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC,
                             const wxPoint& aOffset, int aDrawMode, int aColor )
/****************************************************************************/
{
    EDA_Colors color = (EDA_Colors) m_Color;
    EDA_Colors tmp = color;
    if( GetMarkerType() == MARK_ERC )
    {
        color = (GetErrorLevel() == WAR ) ?
                (EDA_Colors)g_LayerDescr.LayerColor[LAYER_ERC_WARN] :
                (EDA_Colors)g_LayerDescr.LayerColor[LAYER_ERC_ERR];
    }

    if ( aColor < 0 )
        m_Color = color;
    else
        m_Color = (EDA_Colors) aColor;

    DrawMarker( aPanel, aDC, aDrawMode, aOffset );
    m_Color = tmp;
}
+84 −0
Original line number Original line Diff line number Diff line
/***************************************************/
/* classes to handle markers used in schematic ... */
/***************************************************/

#ifndef _CLASS_MARKER_SCH_H_
#define _CLASS_MARKER_SCH_H_

#include "class_marker_base.h"

/* Marker are mainly used to show an ERC error
*/

enum TypeMarker {      /* Markers type */
    MARK_UNSPEC,
    MARK_ERC,
    MARK_PCB,
    MARK_SIMUL,
    MARK_NMAX        /* Lats value: end of list */
};


/* Names for corresponding types of markers: */
extern const wxChar* NameMarqueurType[];


class MARKER_SCH : public SCH_ITEM , public MARKER_BASE
{
public:
    MARKER_SCH( );
    MARKER_SCH( const wxPoint& aPos, const wxString& aText );
    ~MARKER_SCH();
    virtual wxString GetClass() const
    {
        return wxT( "MARKER_SCH" );
    }


    MARKER_SCH* GenCopy();

    virtual void      Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC,
                            const wxPoint& aOffset, int aDraw_mode,
                            int aColor = -1 );


    wxString GetErrorText( ) const
    {
        wxString text = m_drc.GetMainText();
        return text;
    }

    void SetErrorText( wxString aText)
    {
        SetData( m_drc.GetErrorCode(), GetPos(), aText, GetPos() );
    }

    /**
     * Function Save
     * writes the data structures for this object out to a FILE in "*.sch"
     * format.
     * @param aFile The FILE to write to.
     * @return bool - true if success writing else false.
     */
    bool              Save( FILE* aFile ) const;

    /** Function GetPenSize
     * @return the size of the "pen" that be used to draw or plot this item
     * for a marker, has no meaning, but it is necessary to satisfy the SCH_ITEM class requirements
     */
    virtual int GetPenSize( ) { return 0; };

    /** Function HitTest
     * @return true if the point aPosRef is within item area
     * @param aPosRef = a wxPoint to test
     */
    bool HitTest( const wxPoint& aPosRef )
    {
        return HitTestMarker( aPosRef );
    }
#if defined(DEBUG)
    void              Show( int nestLevel, std::ostream& os );
#endif
};

#endif /* _CLASS_MARKER_SCH_H_ */
Loading