Example #1
0
bool SCH_LABEL::Load( LINE_READER& aLine, wxString& aErrorMsg )
{
    char      Name1[256];
    char      Name2[256];
    char      Name3[256];
    int       thickness = 0, size = 0, orient = 0;

    Name1[0] = 0; Name2[0] = 0; Name3[0] = 0;

    char*     sline = (char*) aLine;

    while( ( *sline != ' ' ) && *sline )
        sline++;

    // sline points the start of parameters
    int ii = sscanf( sline, "%s %d %d %d %d %s %s %d", Name1, &m_Pos.x, &m_Pos.y,
                     &orient, &size, Name2, Name3, &thickness );

    if( ii < 4 )
    {
        aErrorMsg.Printf( wxT( "Eeschema file label load error at line %d" ),
                          aLine.LineNumber() );
        return false;
    }

    if( !aLine.ReadLine() )
    {
        aErrorMsg.Printf( wxT( "Eeschema file label load error atline %d" ),
                          aLine.LineNumber() );
        return false;
    }

    if( size == 0 )
        size = DEFAULT_SIZE_TEXT;

    char* text = strtok( (char*) aLine, "\n\r" );

    if( text == NULL )
    {
        aErrorMsg.Printf( wxT( "Eeschema file label load error at line %d" ),
                          aLine.LineNumber() );
        return false;
    }

    m_Text = FROM_UTF8( text );
    m_Size.x = m_Size.y = size;
    SetOrientation( orient );

    if( isdigit( Name3[0] ) )
    {
        thickness = atol( Name3 );
        m_Bold = ( thickness != 0 );
        m_Thickness = m_Bold ? GetPenSizeForBold( size ) : 0;
    }

    if( stricmp( Name2, "Italic" ) == 0 )
        m_Italic = 1;

    return true;
}
/**
 * Function PLOTTER::Text
 *  same as DrawGraphicText, but plot graphic text insteed of draw it
 *  @param aPos = text position (according to aH_justify, aV_justify)
 *  @param aColor (COLOR4D) = text color
 *  @param aText = text to draw
 *  @param aOrient = angle in 0.1 degree
 *  @param aSize = text size (size.x or size.y can be < 0 for mirrored texts)
 *  @param aH_justify = horizontal justification (Left, center, right)
 *  @param aV_justify = vertical justification (bottom, center, top)
 *  @param aWidth = line width (pen width) (default = 0)
 *      if width < 0 : draw segments in sketch mode, width = abs(width)
 *      Use a value min(aSize.x, aSize.y) / 5 for a bold text
 *  @param aItalic = true to simulate an italic font
 *  @param aBold = true to use a bold font Useful only with default width value (aWidth = 0)
 *  @param aMultilineAllowed = true to plot text as multiline, otherwise single line
 */
void PLOTTER::Text( const wxPoint&              aPos,
                    const COLOR4D               aColor,
                    const wxString&             aText,
                    double                      aOrient,
                    const wxSize&               aSize,
                    enum EDA_TEXT_HJUSTIFY_T    aH_justify,
                    enum EDA_TEXT_VJUSTIFY_T    aV_justify,
                    int                         aWidth,
                    bool                        aItalic,
                    bool                        aBold,
                    bool                        aMultilineAllowed,
                    void*                       aData )
{
    int textPensize = aWidth;

    if( textPensize == 0 && aBold ) // Use default values if aWidth == 0
        textPensize = GetPenSizeForBold( std::min( aSize.x, aSize.y ) );

    if( textPensize >= 0 )
        textPensize = Clamp_Text_PenSize( aWidth, aSize, aBold );
    else
        textPensize = -Clamp_Text_PenSize( -aWidth, aSize, aBold );

    SetCurrentLineWidth( textPensize, aData );

    SetColor( aColor );

    DrawGraphicText( NULL, NULL, aPos, aColor, aText,
                     aOrient, aSize,
                     aH_justify, aV_justify,
                     textPensize, aItalic, aBold, NULL, this );

    if( aWidth != textPensize )
        SetCurrentLineWidth( aWidth, aData );
}
void DIALOG_LABEL_EDITOR::TextPropertiesAccept( wxCommandEvent& aEvent )
{
    wxString text;
    int      value;

    /* save old text in undo list if not already in edit */
    /* or the label to be edited is part of a block */
    if( m_CurrentText->GetFlags() == 0 ||
        m_Parent->GetScreen()->m_BlockLocate.GetState() != STATE_NO_BLOCK )
        m_Parent->SaveCopyInUndoList( m_CurrentText, UR_CHANGED );

    m_Parent->GetCanvas()->RefreshDrawingRect( m_CurrentText->GetBoundingBox() );

    text = m_textLabel->GetValue();

    if( !text.IsEmpty() )
        m_CurrentText->m_Text = text;
    else if( !m_CurrentText->IsNew() )
    {
        DisplayError( this, _( "Empty Text!" ) );
        return;
    }

    m_CurrentText->SetOrientation( m_TextOrient->GetSelection() );
    text  = m_TextSize->GetValue();
    value = ReturnValueFromString( g_UserUnit, text );
    m_CurrentText->m_Size.x = m_CurrentText->m_Size.y = value;

    if( m_TextShape )
        m_CurrentText->SetShape( m_TextShape->GetSelection() );

    int style = m_TextStyle->GetSelection();

    if( ( style & 1 ) )
        m_CurrentText->m_Italic = 1;
    else
        m_CurrentText->m_Italic = 0;

    if( ( style & 2 ) )
    {
        m_CurrentText->m_Bold  = true;
        m_CurrentText->m_Thickness = GetPenSizeForBold( m_CurrentText->m_Size.x );
    }
    else
    {
        m_CurrentText->m_Bold  = false;
        m_CurrentText->m_Thickness = 0;
    }

    m_Parent->OnModify();

    /* Make the text size as new default size if it is a new text */
    if( m_CurrentText->IsNew() )
        m_Parent->SetDefaultLabelSize( m_CurrentText->m_Size.x );

    m_Parent->GetCanvas()->RefreshDrawingRect( m_CurrentText->GetBoundingBox() );
    m_Parent->GetCanvas()->MoveCursorToCrossHair();
    EndModal( wxID_OK );
}
void DIALOG_LABEL_EDITOR::TextPropertiesAccept( wxCommandEvent& aEvent )
{
    wxString text;
    int      value;

    /* save old text in undo list if not already in edit */
    /* or the label to be edited is part of a block */
    if( m_CurrentText->GetFlags() == 0 ||
        m_Parent->GetScreen()->m_BlockLocate.GetState() != STATE_NO_BLOCK )
        m_Parent->SaveCopyInUndoList( m_CurrentText, UR_CHANGED );

    m_Parent->GetCanvas()->RefreshDrawingRect( m_CurrentText->GetBoundingBox() );

    text = m_textLabel->GetValue();

    if( !text.IsEmpty() )
        m_CurrentText->SetText( text );
    else if( !m_CurrentText->IsNew() )
    {
        DisplayError( this, _( "Empty Text!" ) );
        return;
    }

    m_CurrentText->SetOrientation( m_TextOrient->GetSelection() );
    text  = m_TextSize->GetValue();
    value = ValueFromString( g_UserUnit, text );
    m_CurrentText->SetSize( wxSize( value, value ) );

    if( m_TextShape )
        /// @todo move cast to widget
        m_CurrentText->SetShape( static_cast<PINSHEETLABEL_SHAPE>( m_TextShape->GetSelection() ) );

    int style = m_TextStyle->GetSelection();

    m_CurrentText->SetItalic( ( style & 1 ) );

    if( ( style & 2 ) )
    {
        m_CurrentText->SetBold( true );
        m_CurrentText->SetThickness( GetPenSizeForBold( m_CurrentText->GetSize().x ) );
    }
    else
    {
        m_CurrentText->SetBold( false );
        m_CurrentText->SetThickness( 0 );
    }

    m_Parent->OnModify();

    // Make the text size the new default size ( if it is a new text ):
    if( m_CurrentText->IsNew() )
        SetDefaultTextSize( m_CurrentText->GetSize().x );

    m_Parent->GetCanvas()->RefreshDrawingRect( m_CurrentText->GetBoundingBox() );
    m_Parent->GetCanvas()->MoveCursorToCrossHair();
    EndModal( wxID_OK );
}
void LIB_FIELD::drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset,
                             EDA_COLOR_T aColor, GR_DRAWMODE aDrawMode, void* aData,
                             const TRANSFORM& aTransform )
{
    wxPoint  text_pos;
    int      color;
    int      linewidth = GetPenSize();

    if( m_Bold )
        linewidth = GetPenSizeForBold( m_Size.x );
    else
        linewidth = Clamp_Text_PenSize( linewidth, m_Size, m_Bold );

    if( ( m_Attributs & TEXT_NO_VISIBLE ) && ( aColor < 0 ) )
    {
        color = GetInvisibleItemColor();
    }
    else if( IsSelected() && ( aColor < 0 ) )
    {
        color = GetItemSelectedColor();
    }
    else
    {
        color = aColor;
    }

    if( color < 0 )
        color = GetDefaultColor();

    text_pos = aTransform.TransformCoordinate( m_Pos ) + aOffset;

    wxString text;

    if( aData )
        text = *(wxString*)aData;
    else
        text = m_Text;

    GRSetDrawMode( aDC, aDrawMode );
    EDA_RECT* clipbox = aPanel? aPanel->GetClipBox() : NULL;
    DrawGraphicText( clipbox, aDC, text_pos, (EDA_COLOR_T) color, text, m_Orient, m_Size,
                     m_HJustify, m_VJustify, linewidth, m_Italic, m_Bold );

    /* Set to one (1) to draw bounding box around field text to validate
     * bounding box calculation. */
#if 0
    EDA_RECT bBox = GetBoundingBox();
    EDA_RECT grBox;
    grBox.SetOrigin( aTransform.TransformCoordinate( bBox.GetOrigin() ) );
    grBox.SetEnd( aTransform.TransformCoordinate( bBox.GetEnd() ) );
    grBox.Move( aOffset );
    GRRect( clipbox, aDC, grBox, 0, LIGHTMAGENTA );
#endif
}
/**
 * Function DrawGraphicText
 * Draw a graphic text (like module texts)
 *  @param aClipBox = the clipping rect, or NULL if no clipping
 *  @param aDC = the current Device Context. NULL if draw within a 3D GL Canvas
 *  @param aPos = text position (according to h_justify, v_justify)
 *  @param aColor (COLOR4D) = text color
 *  @param aText = text to draw
 *  @param aOrient = angle in 0.1 degree
 *  @param aSize = text size (size.x or size.y can be < 0 for mirrored texts)
 *  @param aH_justify = horizontal justification (Left, center, right)
 *  @param aV_justify = vertical justification (bottom, center, top)
 *  @param aWidth = line width (pen width) (use default width if aWidth = 0)
 *      if width < 0 : draw segments in sketch mode, width = abs(width)
 *      Use a value min(aSize.x, aSize.y) / 5 for a bold text
 *  @param aItalic = true to simulate an italic font
 *  @param aBold = true to use a bold font. Useful only with default width value (aWidth = 0)
 *  @param aCallback() = function called (if non null) to draw each segment.
 *                  used to draw 3D texts or for plotting, NULL for normal drawings
 *  @param aPlotter = a pointer to a PLOTTER instance, when this function is used to plot
 *                  the text. NULL to draw this text.
 */
void DrawGraphicText( EDA_RECT* aClipBox,
                      wxDC* aDC,
                      const wxPoint& aPos,
                      COLOR4D aColor,
                      const wxString& aText,
                      double aOrient,
                      const wxSize& aSize,
                      enum EDA_TEXT_HJUSTIFY_T aH_justify,
                      enum EDA_TEXT_VJUSTIFY_T aV_justify,
                      int aWidth,
                      bool aItalic,
                      bool aBold,
                      void (* aCallback)( int x0, int y0, int xf, int yf ),
                      PLOTTER* aPlotter )
{
    bool    fill_mode = true;

    if( aWidth == 0 && aBold ) // Use default values if aWidth == 0
        aWidth = GetPenSizeForBold( std::min( aSize.x, aSize.y ) );

    if( aWidth < 0 )
    {
        aWidth = -aWidth;
        fill_mode = false;
    }

    basic_gal.SetIsFill( fill_mode );
    basic_gal.SetLineWidth( aWidth );

    EDA_TEXT dummy;
    dummy.SetItalic( aItalic );
    dummy.SetBold( aBold );
    dummy.SetHorizJustify( aH_justify );
    dummy.SetVertJustify( aV_justify );

    wxSize size = aSize;
    dummy.SetMirrored( size.x < 0 );

    if( size.x < 0 )
        size.x = - size.x;

    dummy.SetTextSize( size );

    basic_gal.SetTextAttributes( &dummy );
    basic_gal.SetPlotter( aPlotter );
    basic_gal.SetCallback( aCallback );
    basic_gal.m_DC = aDC;
    basic_gal.m_Color = aColor;
    basic_gal.SetClipBox( aClipBox );

    basic_gal.StrokeText( aText, VECTOR2D( aPos ), aOrient * M_PI/1800 );
}
Example #7
0
int SCH_FIELD::GetPenSize() const
{
    int pensize = m_Thickness;

    if( pensize == 0 )   // Use default values for pen size
    {
        if( m_Bold  )
            pensize = GetPenSizeForBold( m_Size.x );
        else
            pensize = GetDefaultLineThickness();
    }

    // Clip pen size for small texts:
    pensize = Clamp_Text_PenSize( pensize, m_Size, m_Bold );
    return pensize;
}
Example #8
0
int LIB_TEXT::GetPenSize() const
{
    int pensize = GetThickness();

    if( pensize == 0 )   // Use default values for pen size
    {
        if( IsBold() )
            pensize = GetPenSizeForBold( GetTextWidth() );
        else
            pensize = GetDefaultLineThickness();
    }

    // Clip pen size for small texts:
    pensize = Clamp_Text_PenSize( pensize, GetTextSize(), IsBold() );
    return pensize;
}
Example #9
0
void SCH_FIELD::Draw( EDA_DRAW_PANEL* panel, wxDC* DC,
                      const wxPoint& offset, GR_DRAWMODE DrawMode, EDA_COLOR_T Color )
{
    int            orient;
    EDA_COLOR_T    color;
    wxPoint        textpos;
    SCH_COMPONENT* parentComponent = (SCH_COMPONENT*) m_Parent;
    int            LineWidth = m_Thickness;

    if( LineWidth == 0 )   // Use default values for pen size
    {
        if( m_Bold  )
            LineWidth = GetPenSizeForBold( m_Size.x );
        else
            LineWidth = GetDefaultLineThickness();
    }


    // Clip pen size for small texts:
    LineWidth = Clamp_Text_PenSize( LineWidth, m_Size, m_Bold );

    if( ((m_Attributs & TEXT_NO_VISIBLE) && !m_forceVisible) || IsVoid() )
        return;

    GRSetDrawMode( DC, DrawMode );

    // Calculate the text orientation according to the component orientation.
    orient = m_Orient;

    if( parentComponent->GetTransform().y1 )  // Rotate component 90 degrees.
    {
        if( orient == TEXT_ORIENT_HORIZ )
            orient = TEXT_ORIENT_VERT;
        else
            orient = TEXT_ORIENT_HORIZ;
    }

    /* Calculate the text justification, according to the component
     * orientation/mirror this is a bit complicated due to cumulative
     * calculations:
     * - numerous cases (mirrored or not, rotation)
     * - the DrawGraphicText function recalculate also H and H justifications
     *      according to the text orientation.
     * - When a component is mirrored, the text is not mirrored and
     *   justifications are complicated to calculate
     * so the more easily way is to use no justifications ( Centered text )
     * and use GetBoundaryBox to know the text coordinate considered as centered
     */
    EDA_RECT boundaryBox = GetBoundingBox();
    textpos = boundaryBox.Centre();

    if( m_forceVisible )
    {
        color = DARKGRAY;
    }
    else
    {
        if( m_id == REFERENCE )
            color = ReturnLayerColor( LAYER_REFERENCEPART );
        else if( m_id == VALUE )
            color = ReturnLayerColor( LAYER_VALUEPART );
        else
            color = ReturnLayerColor( LAYER_FIELDS );
    }

    DrawGraphicText( panel, DC, textpos, color, GetText(), orient, m_Size,
                     GR_TEXT_HJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_CENTER,
                     LineWidth, m_Italic, m_Bold );

    /* Enable this to draw the bounding box around the text field to validate
     * the bounding box calculations.
     */
#if 0

    // Draw boundary box:
    GRRect( panel->GetClipBox(), DC, boundaryBox, 0, BROWN );

    // Draw the text anchor point

    /* Calculate the text position, according to the component
     * orientation/mirror */
    textpos  = m_Pos - parentComponent->GetPosition();
    textpos  = parentComponent->GetScreenCoord( textpos );
    textpos += parentComponent->GetPosition();
    const int len = 10;
    GRLine( panel->GetClipBox(), DC,
            textpos.x - len, textpos.y, textpos.x + len, textpos.y, 0, BLUE );
    GRLine( panel->GetClipBox(), DC,
            textpos.x, textpos.y - len, textpos.x, textpos.y + len, 0, BLUE );
#endif
}
void SCH_FIELD::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset,
                      GR_DRAWMODE aDrawMode, COLOR4D aColor )
{
    int            orient;
    COLOR4D        color;
    wxPoint        textpos;
    SCH_COMPONENT* parentComponent = (SCH_COMPONENT*) m_Parent;
    int            lineWidth = GetThickness();

    if( lineWidth == 0 )   // Use default values for pen size
    {
        if( IsBold() )
            lineWidth = GetPenSizeForBold( GetTextWidth() );
        else
            lineWidth = GetDefaultLineThickness();
    }

    // Clip pen size for small texts:
    lineWidth = Clamp_Text_PenSize( lineWidth, GetTextSize(), IsBold() );

    if( ( !IsVisible() && !m_forceVisible) || IsVoid() )
        return;

    GRSetDrawMode( aDC, aDrawMode );

    // Calculate the text orientation according to the component orientation.
    orient = GetTextAngle();

    if( parentComponent->GetTransform().y1 )  // Rotate component 90 degrees.
    {
        if( orient == TEXT_ANGLE_HORIZ )
            orient = TEXT_ANGLE_VERT;
        else
            orient = TEXT_ANGLE_HORIZ;
    }

    /* Calculate the text justification, according to the component
     * orientation/mirror this is a bit complicated due to cumulative
     * calculations:
     * - numerous cases (mirrored or not, rotation)
     * - the DrawGraphicText function recalculate also H and H justifications
     *      according to the text orientation.
     * - When a component is mirrored, the text is not mirrored and
     *   justifications are complicated to calculate
     * so the more easily way is to use no justifications ( Centered text )
     * and use GetBoundaryBox to know the text coordinate considered as centered
     */
    EDA_RECT boundaryBox = GetBoundingBox();
    textpos = boundaryBox.Centre() + aOffset;

    if( m_forceVisible )
    {
        color = COLOR4D( DARKGRAY );
    }
    else
    {
        if( m_id == REFERENCE )
            color = GetLayerColor( LAYER_REFERENCEPART );
        else if( m_id == VALUE )
            color = GetLayerColor( LAYER_VALUEPART );
        else
            color = GetLayerColor( LAYER_FIELDS );
    }

    EDA_RECT* clipbox = aPanel ? aPanel->GetClipBox() : NULL;
    DrawGraphicText( clipbox, aDC, textpos, color, GetFullyQualifiedText(), orient, GetTextSize(),
                     GR_TEXT_HJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_CENTER,
                     lineWidth, IsItalic(), IsBold() );

    // While moving: don't loose visual contact to which component this label belongs.
    if ( IsWireImage() )
    {
        const wxPoint origin = parentComponent->GetPosition();
        textpos  = GetTextPos() - origin;
        textpos  = parentComponent->GetScreenCoord( textpos );
        textpos += parentComponent->GetPosition();
        GRLine( clipbox, aDC, origin, textpos, 2, DARKGRAY );
    }

    /* Enable this to draw the bounding box around the text field to validate
     * the bounding box calculations.
     */
#if 0

    // Draw boundary box:
    GRRect( aPanel->GetClipBox(), aDC, boundaryBox, 0, BROWN );

    // Draw the text anchor point

    /* Calculate the text position, according to the component
     * orientation/mirror */
    textpos  = m_Pos - parentComponent->GetPosition();
    textpos  = parentComponent->GetScreenCoord( textpos );
    textpos += parentComponent->GetPosition();
    const int len = 10;
    GRLine( clipbox, aDC,
            textpos.x - len, textpos.y, textpos.x + len, textpos.y, 0, BLUE );
    GRLine( clipbox, aDC,
            textpos.x, textpos.y - len, textpos.x, textpos.y + len, 0, BLUE );
#endif
}
Example #11
0
/**
 * Function PlotGraphicText
 *  same as DrawGraphicText, but plot graphic text insteed of draw it
 *  @param aPos = text position (according to aH_justify, aV_justify)
 *  @param aColor (enum EDA_COLOR_T) = text color
 *  @param aText = text to draw
 *  @param aOrient = angle in 0.1 degree
 *  @param aSize = text size (size.x or size.y can be < 0 for mirrored texts)
 *  @param aH_justify = horizontal justification (Left, center, right)
 *  @param aV_justify = vertical justification (bottom, center, top)
 *  @param aWidth = line width (pen width) (default = 0)
 *      if width < 0 : draw segments in sketch mode, width = abs(width)
 *      Use a value min(aSize.x, aSize.y) / 5 for a bold text
 *  @param aItalic = true to simulate an italic font
 *  @param aBold = true to use a bold font Useful only with default width value (aWidth = 0)
 *  @param aMultilineAllowed = true to plot text as multiline, otherwise single line
 */
void PLOTTER::Text( const wxPoint&              aPos,
                    enum EDA_COLOR_T            aColor,
                    const wxString&             aText,
                    double                      aOrient,
                    const wxSize&               aSize,
                    enum EDA_TEXT_HJUSTIFY_T    aH_justify,
                    enum EDA_TEXT_VJUSTIFY_T    aV_justify,
                    int                         aWidth,
                    bool                        aItalic,
                    bool                        aBold,
                    bool                        aMultilineAllowed )
{
    int textPensize = aWidth;

    if( textPensize == 0 && aBold ) // Use default values if aWidth == 0
        textPensize = GetPenSizeForBold( std::min( aSize.x, aSize.y ) );

    if( textPensize >= 0 )
        textPensize = Clamp_Text_PenSize( aWidth, aSize, aBold );
    else
        textPensize = -Clamp_Text_PenSize( -aWidth, aSize, aBold );

    SetCurrentLineWidth( textPensize );

    if( aColor >= 0 )
        SetColor( aColor );

    if( aMultilineAllowed )
    {
        // EDA_TEXT needs for calculations of the position of every
        // line according to orientation and justifications
        wxArrayString strings;
        EDA_TEXT* multilineText = new EDA_TEXT( aText );
        multilineText->SetSize( aSize );
        multilineText->SetTextPosition( aPos );
        multilineText->SetOrientation( aOrient );
        multilineText->SetHorizJustify( aH_justify );
        multilineText->SetVertJustify( aV_justify );
        multilineText->SetThickness( aWidth );
        multilineText->SetMultilineAllowed( aMultilineAllowed );

        std::vector<wxPoint> positions;
        wxStringSplit( aText, strings, '\n' );
        positions.reserve( strings.Count() );

        multilineText->GetPositionsOfLinesOfMultilineText(
                positions, strings.Count() );

        for( unsigned ii = 0; ii < strings.Count(); ii++ )
        {
            wxString& txt = strings.Item( ii );
            DrawGraphicText( NULL, NULL, positions[ii], aColor, txt,
                             aOrient, aSize,
                             aH_justify, aV_justify,
                             textPensize, aItalic, aBold, NULL, this );
        }

        delete multilineText;
    }
    else
    {
        DrawGraphicText( NULL, NULL, aPos, aColor, aText,
                         aOrient, aSize,
                         aH_justify, aV_justify,
                         textPensize, aItalic, aBold, NULL, this );
    }

    if( aWidth != textPensize )
        SetCurrentLineWidth( aWidth );
}
Example #12
0
/**
 * Function DrawGraphicText
 * Draw a graphic text (like module texts)
 *  @param aClipBox = the clipping rect, or NULL if no clipping
 *  @param aDC = the current Device Context. NULL if draw within a 3D GL Canvas
 *  @param aPos = text position (according to h_justify, v_justify)
 *  @param aColor (enum EDA_COLOR_T) = text color
 *  @param aText = text to draw
 *  @param aOrient = angle in 0.1 degree
 *  @param aSize = text size (size.x or size.y can be < 0 for mirrored texts)
 *  @param aH_justify = horizontal justification (Left, center, right)
 *  @param aV_justify = vertical justification (bottom, center, top)
 *  @param aWidth = line width (pen width) (use default width if aWidth = 0)
 *      if width < 0 : draw segments in sketch mode, width = abs(width)
 *      Use a value min(aSize.x, aSize.y) / 5 for a bold text
 *  @param aItalic = true to simulate an italic font
 *  @param aBold = true to use a bold font. Useful only with default width value (aWidth = 0)
 *  @param aCallback() = function called (if non null) to draw each segment.
 *                  used to draw 3D texts or for plotting, NULL for normal drawings
 *  @param aPlotter = a pointer to a PLOTTER instance, when this function is used to plot
 *                  the text. NULL to draw this text.
 */
void DrawGraphicText( EDA_RECT* aClipBox,
                      wxDC* aDC,
                      const wxPoint& aPos,
                      EDA_COLOR_T aColor,
                      const wxString& aText,
                      double aOrient,
                      const wxSize& aSize,
                      enum EDA_TEXT_HJUSTIFY_T aH_justify,
                      enum EDA_TEXT_VJUSTIFY_T aV_justify,
                      int aWidth,
                      bool aItalic,
                      bool aBold,
                      void (* aCallback)( int x0, int y0, int xf, int yf ),
                      PLOTTER* aPlotter )
{
    int         AsciiCode;
    int         x0, y0;
    int         size_h, size_v;
    unsigned    ptr;
    int         dx, dy;                     // Draw coordinate for segments to draw. also used in some other calculation
    wxPoint     current_char_pos;           // Draw coordinates for the current char
    wxPoint     overbar_pos;                // Start point for the current overbar
    int         overbar_italic_comp;        // Italic compensation for overbar
    #define        BUF_SIZE 100
    wxPoint coord[BUF_SIZE + 1];                // Buffer coordinate used to draw polylines (one char shape)
    bool    sketch_mode     = false;
    bool    italic_reverse  = false;            // true for mirrored texts with m_Size.x < 0

    size_h  = aSize.x;                          /* PLEASE NOTE: H is for HORIZONTAL not for HEIGHT */
    size_v  = aSize.y;

    if( aWidth == 0 && aBold ) // Use default values if aWidth == 0
        aWidth = GetPenSizeForBold( std::min( aSize.x, aSize.y ) );

    if( aWidth < 0 )
    {
        aWidth = -aWidth;
        sketch_mode = true;
    }

#ifdef CLIP_PEN      // made by draw and plot functions
    aWidth = Clamp_Text_PenSize( aWidth, aSize, aBold );
#endif

    if( size_h < 0 ) // text is mirrored using size.x < 0 (mirror / Y axis)
        italic_reverse = true;

    unsigned char_count = NegableTextLength( aText );

    if( char_count == 0 )
        return;

    current_char_pos = aPos;

    dx  = GraphicTextWidth( aText, size_h, aItalic, aWidth );
    dy  = size_v;

    /* Do not draw the text if out of draw area! */
    if( aClipBox )
    {
        int xm, ym, ll, xc, yc;
        ll = std::abs( dx );

        xc  = current_char_pos.x;
        yc  = current_char_pos.y;

        x0  = aClipBox->GetX() - ll;
        y0  = aClipBox->GetY() - ll;
        xm  = aClipBox->GetRight() + ll;
        ym  = aClipBox->GetBottom() + ll;

        if( xc < x0 )
            return;

        if( yc < y0 )
            return;

        if( xc > xm )
            return;

        if( yc > ym )
            return;
    }


    /* Compute the position of the first letter of the text
     * this position is the position of the left bottom point of the letter
     * this is the same as the text position only for a left and bottom justified text
     * In others cases, this position must be calculated from the text position ans size
     */

    switch( aH_justify )
    {
    case GR_TEXT_HJUSTIFY_CENTER:
        current_char_pos.x -= dx / 2;
        break;

    case GR_TEXT_HJUSTIFY_RIGHT:
        current_char_pos.x -= dx;
        break;

    case GR_TEXT_HJUSTIFY_LEFT:
        break;
    }

    switch( aV_justify )
    {
    case GR_TEXT_VJUSTIFY_CENTER:
        current_char_pos.y += dy / 2;
        break;

    case GR_TEXT_VJUSTIFY_TOP:
        current_char_pos.y += dy;
        break;

    case GR_TEXT_VJUSTIFY_BOTTOM:
        break;
    }

    // Note: if aPanel == NULL, we are using a GL Canvas that handle scaling
    if( aSize.x == 0 )
        return;

    /* if a text size is too small, the text cannot be drawn, and it is drawn as a single
     * graphic line */
    if( aDC && ( aDC->LogicalToDeviceYRel( std::abs( aSize.y ) ) < MIN_DRAWABLE_TEXT_SIZE ))
    {
        // draw the text as a line always vertically centered
        wxPoint end( current_char_pos.x + dx, current_char_pos.y );

        RotatePoint( &current_char_pos, aPos, aOrient );
        RotatePoint( &end, aPos, aOrient );

        if( aPlotter )
        {
            aPlotter->MoveTo( current_char_pos );
            aPlotter->FinishTo( end );
        }
        else if( aCallback )
        {
            aCallback( current_char_pos.x, current_char_pos.y, end.x, end.y );
        }
        else
            GRLine( aClipBox, aDC,
                    current_char_pos.x, current_char_pos.y, end.x, end.y, aWidth, aColor );

        return;
    }

    if( aItalic )
    {
        overbar_italic_comp = OverbarPositionY( size_v ) / 8;

        if( italic_reverse )
        {
            overbar_italic_comp = -overbar_italic_comp;
        }
    }
    else
    {
        overbar_italic_comp = 0;
    }

    int overbars = 0;   // Number of '~' seen (except '~~')
    ptr = 0;            // ptr = text index

    while( ptr < char_count )
    {
        if( aText[ptr + overbars] == '~' )
        {
            if( ptr + overbars + 1 < aText.length()
                && aText[ptr + overbars + 1] == '~' )   /* '~~' draw as '~' */
                ptr++;                                  // skip first '~' char and draw second

            else
            {
                // Found an overbar, adjust the pointers
                overbars++;

                if( overbars & 1 )      // odd overbars count
                {
                    // Starting the overbar
                    overbar_pos     = current_char_pos;
                    overbar_pos.x   += overbar_italic_comp;
                    overbar_pos.y   -= OverbarPositionY( size_v );
                    RotatePoint( &overbar_pos, aPos, aOrient );
                }
                else
                {
                    // Ending the overbar
                    coord[0]        = overbar_pos;
                    overbar_pos     = current_char_pos;
                    overbar_pos.x   += overbar_italic_comp;
                    overbar_pos.y   -= OverbarPositionY( size_v );
                    RotatePoint( &overbar_pos, aPos, aOrient );
                    coord[1] = overbar_pos;
                    // Plot the overbar segment
                    DrawGraphicTextPline( aClipBox, aDC, aColor, aWidth,
                                          sketch_mode, 2, coord, aCallback, aPlotter );
                }

                continue;    // Skip ~ processing
            }
        }

        AsciiCode = aText.GetChar( ptr + overbars );

        const char* ptcar = GetHersheyShapeDescription( AsciiCode );
        // Get metrics
        int         xsta    = *ptcar++ - 'R';
        int         xsto    = *ptcar++ - 'R';
        int         point_count = 0;
        bool        endcar = false;

        while( !endcar )
        {
            int hc1, hc2;
            hc1 = *ptcar++;

            if( hc1 )
            {
                hc2 = *ptcar++;
            }
            else
            {
                // End of character, insert a synthetic pen up:
                hc1    = ' ';
                hc2    = 'R';
                endcar = true;
            }

            // Do the Hershey decode thing:
            // coordinates values are coded as <value> + 'R'
            hc1 -= 'R';
            hc2 -= 'R';

            // Pen up request
            if( hc1 == -50 && hc2 == 0 )
            {
                if( point_count )
                {
                    if( aWidth <= 1 )
                        aWidth = 0;

                    DrawGraphicTextPline( aClipBox, aDC, aColor, aWidth,
                                          sketch_mode, point_count, coord,
                                          aCallback, aPlotter );
                }

                point_count = 0;
            }
            else
            {
                wxPoint currpoint;
                hc1 -= xsta; hc2 -= 10;    // Align the midpoint
                hc1  = KiROUND( hc1 * size_h * s_HersheyScaleFactor );
                hc2  = KiROUND( hc2 * size_v * s_HersheyScaleFactor );

                // To simulate an italic font,
                // add a x offset depending on the y offset
                if( aItalic )
                    hc1 -= KiROUND( italic_reverse ? -hc2 / 8.0 : hc2 / 8.0 );

                currpoint.x = hc1 + current_char_pos.x;
                currpoint.y = hc2 + current_char_pos.y;

                RotatePoint( &currpoint, aPos, aOrient );
                coord[point_count] = currpoint;

                if( point_count < BUF_SIZE - 1 )
                    point_count++;
            }
        }    // end draw 1 char

        ptr++;

        // Apply the advance width
        current_char_pos.x += KiROUND( size_h * (xsto - xsta) * s_HersheyScaleFactor );
    }

    if( overbars % 2 )
    {
        // Close the last overbar
        coord[0]       = overbar_pos;
        overbar_pos    = current_char_pos;
        overbar_pos.y -= OverbarPositionY( size_v );
        RotatePoint( &overbar_pos, aPos, aOrient );
        coord[1] = overbar_pos;

        // Plot the overbar segment
        DrawGraphicTextPline( aClipBox, aDC, aColor, aWidth,
                              sketch_mode, 2, coord, aCallback, aPlotter );
    }
}
Example #13
0
void EDA_DRAW_FRAME::TraceWorkSheet( wxDC* DC, BASE_SCREEN* screen, int line_width )
{
    if( !m_showBorderAndTitleBlock )
        return;

    const PAGE_INFO&  pageInfo = GetPageSettings();
    wxSize  pageSize = pageInfo.GetSizeMils();

    int ii, jj, xg, yg, ipas, gxpas, gypas;
    wxPoint pos;
    int refx, refy;
    EDA_Colors Color;
    wxString Line;
    Ki_WorkSheetData* WsItem;
    int scale = m_internalUnits / 1000;
    wxSize size( SIZETEXT * scale, SIZETEXT * scale );
#if defined(KICAD_GOST)
    wxSize size2( SIZETEXT * scale * 2, SIZETEXT * scale * 2);
    wxSize size3( SIZETEXT * scale * 3, SIZETEXT * scale * 3);
    wxSize size1_5( SIZETEXT * scale * 1.5, SIZETEXT * scale * 1.5);
#endif
    wxSize size_ref( SIZETEXT_REF * scale, SIZETEXT_REF * scale );

    wxString msg;
    int UpperLimit = VARIABLE_BLOCK_START_POSITION;
    int width = line_width;

    Color = RED;

    // if not printing, draw the page limits:
    if( !screen->m_IsPrinting && g_ShowPageLimits )
    {
        GRSetDrawMode( DC, GR_COPY );
        GRRect( m_canvas->GetClipBox(), DC, 0, 0,
                pageSize.x * scale, pageSize.y * scale, width,
                g_DrawBgColor == WHITE ? LIGHTGRAY : DARKDARKGRAY );
    }

    GRSetDrawMode( DC, GR_COPY );

    // Draw the border.

    // Upper left corner
    refx = pageInfo.GetLeftMarginMils();
    refy = pageInfo.GetTopMarginMils();

    // lower right corner
    xg   = pageSize.x - pageInfo.GetRightMarginMils();
    yg   = pageSize.y - pageInfo.GetBottomMarginMils();

#if defined(KICAD_GOST)
    GRRect( m_canvas->GetClipBox(), DC, refx * scale, refy * scale,
            xg * scale, yg * scale, width, Color );

#else
    for( ii = 0; ii < 2; ii++ )
    {
        GRRect( m_canvas->GetClipBox(), DC, refx * scale, refy * scale,
                xg * scale, yg * scale, width, Color );

        refx += GRID_REF_W; refy += GRID_REF_W;
        xg   -= GRID_REF_W; yg -= GRID_REF_W;
    }

#endif

    // Draw the reference legends.
    refx = pageInfo.GetLeftMarginMils();

#if defined(KICAD_GOST)
    refy = pageSize.y - pageInfo.GetBottomMarginMils(); // Lower left corner
    for( WsItem = &WS_Segm1_LU; WsItem != NULL; WsItem = WsItem->Pnext )
    {
        pos.x = ( refx - WsItem->m_Posx ) * scale;
        pos.y = ( refy - WsItem->m_Posy ) * scale;
        msg.Empty();
        switch( WsItem->m_Type )
        {
        case WS_CADRE:
            break;

        case WS_PODPIS_LU:
            if( WsItem->m_Legende )
                msg = WsItem->m_Legende;
            DrawGraphicText( m_canvas, DC, pos, Color,
                             msg, TEXT_ORIENT_VERT, size,
                             GR_TEXT_HJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_BOTTOM,
                             width, false, false );
            break;

        case WS_SEGMENT_LU:
            xg = pageInfo.GetLeftMarginMils() - WsItem->m_Endx;
            yg = pageSize.y - pageInfo.GetBottomMarginMils() - WsItem->m_Endy;
            GRLine( m_canvas->GetClipBox(), DC, pos.x, pos.y,
                    xg * scale, yg * scale, width, Color );
            break;
        }
    }

    refy = pageInfo.GetBottomMarginMils(); // Left Top corner
    for( WsItem = &WS_Segm1_LT; WsItem != NULL; WsItem = WsItem->Pnext )
    {
        pos.x = ( refx + WsItem->m_Posx ) * scale;
        pos.y = ( refy + WsItem->m_Posy ) * scale;
        msg.Empty();
        switch( WsItem->m_Type )
        {
        case WS_SEGMENT_LT:
            xg = pageInfo.GetLeftMarginMils() + WsItem->m_Endx;
            yg = pageInfo.GetBottomMarginMils() + WsItem->m_Endy;
            GRLine( m_canvas->GetClipBox(), DC, pos.x, pos.y,
                    xg * scale, yg * scale, width, Color );
            break;
        }
    }

#else

    // Upper left corner
    refy = pageInfo.GetTopMarginMils();

    // lower right corner
    xg   = pageSize.x - pageInfo.GetRightMarginMils();
    yg   = pageSize.y - pageInfo.GetBottomMarginMils();

    ipas  = ( xg - refx ) / PAS_REF;
    gxpas = ( xg - refx ) / ipas;
    for( ii = refx + gxpas, jj = 1; ipas > 0; ii += gxpas, jj++, ipas-- )
    {
        Line.Printf( wxT( "%d" ), jj );

        if( ii < xg - PAS_REF / 2 )
        {
            GRLine( m_canvas->GetClipBox(), DC, ii * scale, refy * scale,
                    ii * scale, ( refy + GRID_REF_W ) * scale, width, Color );
        }
        DrawGraphicText( m_canvas, DC,
                         wxPoint( ( ii - gxpas / 2 ) * scale,
                                  ( refy + GRID_REF_W / 2 ) * scale ),
                         Color, Line, TEXT_ORIENT_HORIZ, size_ref,
                         GR_TEXT_HJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_CENTER,
                         width, false, false );

        if( ii < xg - PAS_REF / 2 )
        {
            GRLine( m_canvas->GetClipBox(), DC, ii * scale, yg * scale,
                    ii * scale, ( yg - GRID_REF_W ) * scale, width, Color );
        }
        DrawGraphicText( m_canvas, DC,
                         wxPoint( ( ii - gxpas / 2 ) * scale,
                                  ( yg - GRID_REF_W / 2) * scale ),
                         Color, Line, TEXT_ORIENT_HORIZ, size_ref,
                         GR_TEXT_HJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_CENTER,
                         width, false, false );
    }

    ipas  = ( yg - refy ) / PAS_REF;
    gypas = ( yg - refy ) / ipas;

    for( ii = refy + gypas, jj = 0; ipas > 0; ii += gypas, jj++, ipas-- )
    {
        if( jj < 26 )
            Line.Printf( wxT( "%c" ), jj + 'A' );
        else    // I hope 52 identifiers are enought...
            Line.Printf( wxT( "%c" ), 'a' + jj - 26 );

        if( ii < yg - PAS_REF / 2 )
        {
            GRLine( m_canvas->GetClipBox(), DC, refx * scale, ii * scale,
                    ( refx + GRID_REF_W ) * scale, ii * scale, width, Color );
        }

        DrawGraphicText( m_canvas, DC,
                         wxPoint( ( refx + GRID_REF_W / 2 ) * scale,
                                  ( ii - gypas / 2 ) * scale ),
                         Color, Line, TEXT_ORIENT_HORIZ, size_ref,
                         GR_TEXT_HJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_CENTER,
                         width, false, false );

        if( ii < yg - PAS_REF / 2 )
        {
            GRLine( m_canvas->GetClipBox(), DC, xg * scale, ii * scale,
                    ( xg - GRID_REF_W ) * scale, ii * scale, width, Color );
        }
        DrawGraphicText( m_canvas, DC,
                         wxPoint( ( xg - GRID_REF_W / 2 ) * scale,
                                  ( ii - gxpas / 2 ) * scale ),
                         Color, Line, TEXT_ORIENT_HORIZ, size_ref,
                         GR_TEXT_HJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_CENTER,
                         width, false, false );
    }

#endif

#if defined(KICAD_GOST)
    // lower right corner
    refx = pageSize.x - pageInfo.GetRightMarginMils();
    refy = pageSize.y - pageInfo.GetBottomMarginMils();

    if( screen->m_ScreenNumber == 1 )
    {
        for( WsItem = &WS_Date; WsItem != NULL; WsItem = WsItem->Pnext )
        {
            pos.x = (refx - WsItem->m_Posx) * scale;
            pos.y = (refy - WsItem->m_Posy) * scale;
            msg.Empty();
            switch( WsItem->m_Type )
            {
            case WS_DATE:
                break;

            case WS_REV:
                break;

            case WS_KICAD_VERSION:
                break;

            case WS_PODPIS:
                if( WsItem->m_Legende )
                    msg = WsItem->m_Legende;
                DrawGraphicText( m_canvas, DC, pos, Color,
                                 msg, TEXT_ORIENT_HORIZ, size,
                                 GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_VJUSTIFY_CENTER,
                                 width, false, false );
                break;

            case WS_SIZESHEET:
                break;

            case WS_IDENTSHEET:
                if( WsItem->m_Legende )
                    msg = WsItem->m_Legende;
                if( screen->m_NumberOfScreen > 1 )
                    msg << screen->m_ScreenNumber;
                DrawGraphicText( m_canvas, DC, pos, Color, msg,
                                 TEXT_ORIENT_HORIZ, size, GR_TEXT_HJUSTIFY_LEFT,
                                 GR_TEXT_VJUSTIFY_CENTER, width, false, false );
                break;

            case WS_SHEETS:
                if( WsItem->m_Legende )
                    msg = WsItem->m_Legende;
                msg << screen->m_NumberOfScreen;
                DrawGraphicText( m_canvas, DC, pos, Color, msg,
                                 TEXT_ORIENT_HORIZ, size, GR_TEXT_HJUSTIFY_LEFT,
                                 GR_TEXT_VJUSTIFY_CENTER, width, false, false );
                break;

            case WS_COMPANY_NAME:
            msg = GetTitleBlock().GetCompany();
                if( !msg.IsEmpty() )
                {
                    DrawGraphicText( m_canvas, DC, pos, Color,
                                     msg, TEXT_ORIENT_HORIZ, size1_5,
                                     GR_TEXT_HJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_CENTER,
                                     width,
                                     false, false );
                }
                break;

            case WS_TITLE:
            msg = GetTitleBlock().GetTitle();
                if( !msg.IsEmpty() )
                {
                    DrawGraphicText( m_canvas, DC, pos, Color,
                                     msg, TEXT_ORIENT_HORIZ, size1_5,
                                     GR_TEXT_HJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_CENTER,
                                     width,
                                     false, false );
                }
                break;

            case WS_COMMENT1:
            msg = GetTitleBlock().GetComment1();
                if( !msg.IsEmpty() )
                {
                    DrawGraphicText( m_canvas, DC, pos, Color,
                                     msg, TEXT_ORIENT_HORIZ, size3,
                                     GR_TEXT_HJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_CENTER,
                                     width,
                                     false, false );
                    pos.x = (pageInfo.GetLeftMarginMils() + 1260) * scale;
                    pos.y = (pageInfo.GetTopMarginMils() + 270) * scale;
                    DrawGraphicText( m_canvas, DC, pos, Color,
                                     msg, 1800, size2,
                                     GR_TEXT_HJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_CENTER,
                                     width,
                                     false, false );
                }
                break;

            case WS_COMMENT2:
            msg = GetTitleBlock().GetComment2();
                if( !msg.IsEmpty() )
                {
                    DrawGraphicText( m_canvas, DC, pos, Color,
                                     msg, TEXT_ORIENT_HORIZ, size,
                                     GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_VJUSTIFY_CENTER,
                                     width, false, false );
                }
                break;

            case WS_COMMENT3:
            msg = GetTitleBlock().GetComment3();
                if( !msg.IsEmpty() )
                {
                    DrawGraphicText( m_canvas, DC, pos, Color,
                                     msg, TEXT_ORIENT_HORIZ, size,
                                     GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_VJUSTIFY_CENTER,
                                     width, false, false );
                }
                break;

            case WS_COMMENT4:
            msg = GetTitleBlock().GetComment4();
                if( !msg.IsEmpty() )
                {
                    DrawGraphicText( m_canvas, DC, pos, Color,
                                     msg, TEXT_ORIENT_HORIZ, size,
                                     GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_VJUSTIFY_CENTER,
                                     width, false, false );
                }
                break;

            case WS_UPPER_SEGMENT:
            case WS_LEFT_SEGMENT:
                WS_MostUpperLine.m_Posy = WS_MostUpperLine.m_Endy =
                    WS_MostLeftLine.m_Posy = STAMP_OY;
                pos.y = ( refy - WsItem->m_Posy ) * scale;

            case WS_SEGMENT:
                xg = pageSize.x -
                     pageInfo.GetRightMarginMils() - WsItem->m_Endx;
                yg = pageSize.y -
                     pageInfo.GetBottomMarginMils() - WsItem->m_Endy;
                GRLine( m_canvas->GetClipBox(), DC, pos.x, pos.y,
                        xg * scale, yg * scale, width, Color );
                break;
            }
        }
    }
    else
    {
        for( WsItem = &WS_CADRE_D; WsItem != NULL; WsItem = WsItem->Pnext )
        {
            pos.x = ( refx - WsItem->m_Posx ) * scale;
            pos.y = ( refy - WsItem->m_Posy ) * scale;
            msg.Empty();

            switch( WsItem->m_Type )
            {
            case WS_CADRE:
            // Begin list number > 1
            msg = GetTitleBlock().GetComment1();
                if( !msg.IsEmpty() )
                {
                    DrawGraphicText( m_canvas, DC, pos, Color,
                                     msg, TEXT_ORIENT_HORIZ, size3,
                                     GR_TEXT_HJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_CENTER,
                                     width,
                                     false, false );
                    pos.x = (pageInfo.GetLeftMarginMils() + 1260) * scale;
                    pos.y = (pageInfo.GetTopMarginMils() + 270) * scale;
                    DrawGraphicText( m_canvas, DC, pos, Color,
                                     msg, 1800, size2,
                                     GR_TEXT_HJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_CENTER,
                                     width,
                                     false, false );
                }
                break;

            case WS_PODPIS_D:
                if( WsItem->m_Legende )
                    msg = WsItem->m_Legende;
                DrawGraphicText( m_canvas, DC, pos, Color,
                                 msg, TEXT_ORIENT_HORIZ, size,
                                 GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_VJUSTIFY_CENTER,
                                 width,
                                 false, false );
                break;

            case WS_IDENTSHEET_D:
                if( WsItem->m_Legende )
                    msg = WsItem->m_Legende;
                msg << screen->m_ScreenNumber;
                DrawGraphicText( m_canvas, DC, pos, Color,
                                 msg, TEXT_ORIENT_HORIZ, size,
                                 GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_VJUSTIFY_CENTER,
                                 width, false, false );
                break;

            case WS_LEFT_SEGMENT_D:
                pos.y = ( refy - WsItem->m_Posy ) * scale;

            case WS_SEGMENT_D:
                xg = pageSize.x -
                     pageInfo.GetRightMarginMils() - WsItem->m_Endx;
                yg = pageSize.y -
                     pageInfo.GetBottomMarginMils() - WsItem->m_Endy;
                GRLine( m_canvas->GetClipBox(), DC, pos.x, pos.y,
                        xg * scale, yg * scale, width, Color );
                break;
            }
        }
    }

#else

    refx = pageSize.x - pageInfo.GetRightMarginMils()  - GRID_REF_W;
    refy = pageSize.y - pageInfo.GetBottomMarginMils() - GRID_REF_W;

    for( WsItem = &WS_Date; WsItem != NULL; WsItem = WsItem->Pnext )
    {
        pos.x = (refx - WsItem->m_Posx) * scale;
        pos.y = (refy - WsItem->m_Posy) * scale;
        msg.Empty();

        switch( WsItem->m_Type )
        {
        case WS_DATE:
            if( WsItem->m_Legende )
                msg = WsItem->m_Legende;
            msg += GetTitleBlock().GetDate();
            DrawGraphicText( m_canvas, DC, pos, Color,
                             msg, TEXT_ORIENT_HORIZ, size,
                             GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_VJUSTIFY_CENTER,
                             width, false, true );
            break;

        case WS_REV:
            if( WsItem->m_Legende )
                msg = WsItem->m_Legende;
            msg += GetTitleBlock().GetRevision();
            DrawGraphicText( m_canvas, DC, pos, Color,
                             msg, TEXT_ORIENT_HORIZ, size,
                             GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_VJUSTIFY_CENTER,
                             GetPenSizeForBold( MIN( size.x, size.y ) ),
                             false, true );
            break;

        case WS_KICAD_VERSION:
            if( WsItem->m_Legende )
                msg = WsItem->m_Legende;
            msg += g_ProductName + wxGetApp().GetAppName();
            msg += wxT( " " ) + GetBuildVersion();
            DrawGraphicText( m_canvas, DC, pos, Color,
                             msg, TEXT_ORIENT_HORIZ, size,
                             GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_VJUSTIFY_CENTER,
                             width, false, false );
            break;

        case WS_SIZESHEET:
            if( WsItem->m_Legende )
                msg = WsItem->m_Legende;
            msg += pageInfo.GetType();
            DrawGraphicText( m_canvas, DC, pos, Color,
                             msg, TEXT_ORIENT_HORIZ, size,
                             GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_VJUSTIFY_CENTER,
                             width, false, false );
            break;


        case WS_IDENTSHEET:
            if( WsItem->m_Legende )
                msg = WsItem->m_Legende;
            msg << screen->m_ScreenNumber << wxT( "/" ) << screen->m_NumberOfScreen;
            DrawGraphicText( m_canvas, DC, pos, Color,
                             msg, TEXT_ORIENT_HORIZ, size,
                             GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_VJUSTIFY_CENTER,
                             width, false, false );
            break;

        case WS_FILENAME:
        {
            wxString fname, fext;
            wxFileName::SplitPath( screen->GetFileName(), (wxString*) NULL, &fname, &fext );

            if( WsItem->m_Legende )
                msg = WsItem->m_Legende;

            msg << fname << wxT( "." ) << fext;
            DrawGraphicText( m_canvas, DC, pos, Color,
                             msg, TEXT_ORIENT_HORIZ, size,
                             GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_VJUSTIFY_CENTER,
                             width, false, false );
        }
        break;

        case WS_FULLSHEETNAME:
            if( WsItem->m_Legende )
                msg = WsItem->m_Legende;
            msg += GetScreenDesc();
            DrawGraphicText( m_canvas, DC, pos, Color,
                             msg, TEXT_ORIENT_HORIZ, size,
                             GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_VJUSTIFY_CENTER,
                             width, false, false );
            break;


        case WS_COMPANY_NAME:
            if( WsItem->m_Legende )
                msg = WsItem->m_Legende;
            msg += GetTitleBlock().GetCompany();
            if( !msg.IsEmpty() )
            {
                DrawGraphicText( m_canvas, DC, pos, Color,
                                 msg, TEXT_ORIENT_HORIZ, size,
                                 GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_VJUSTIFY_CENTER,
                                 GetPenSizeForBold( MIN( size.x, size.y ) ),
                                 false, true );
                UpperLimit = MAX( UpperLimit, WsItem->m_Posy + SIZETEXT );
            }
            break;

        case WS_TITLE:
            if( WsItem->m_Legende )
                msg = WsItem->m_Legende;
            msg += GetTitleBlock().GetTitle();
            DrawGraphicText( m_canvas, DC, pos, Color,
                             msg, TEXT_ORIENT_HORIZ, size,
                             GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_VJUSTIFY_CENTER,
                             GetPenSizeForBold( MIN( size.x, size.y ) ),
                             false, true );
            break;

        case WS_COMMENT1:
            if( WsItem->m_Legende )
                msg = WsItem->m_Legende;
            msg += GetTitleBlock().GetComment1();
            if( !msg.IsEmpty() )
            {
                DrawGraphicText( m_canvas, DC, pos, Color,
                                 msg, TEXT_ORIENT_HORIZ, size,
                                 GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_VJUSTIFY_CENTER,
                                 width, false, false );
                UpperLimit = MAX( UpperLimit, WsItem->m_Posy + SIZETEXT );
            }
            break;

        case WS_COMMENT2:
            if( WsItem->m_Legende )
                msg = WsItem->m_Legende;
            msg += GetTitleBlock().GetComment2();
            if( !msg.IsEmpty() )
            {
                DrawGraphicText( m_canvas, DC, pos, Color,
                                 msg, TEXT_ORIENT_HORIZ, size,
                                 GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_VJUSTIFY_CENTER,
                                 width, false, false );
                UpperLimit = MAX( UpperLimit, WsItem->m_Posy + SIZETEXT );
            }
            break;

        case WS_COMMENT3:
            if( WsItem->m_Legende )
                msg = WsItem->m_Legende;
            msg += GetTitleBlock().GetComment3();
            if( !msg.IsEmpty() )
            {
                DrawGraphicText( m_canvas, DC, pos, Color,
                                 msg, TEXT_ORIENT_HORIZ, size,
                                 GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_VJUSTIFY_CENTER,
                                 width, false, false );
                UpperLimit = MAX( UpperLimit, WsItem->m_Posy + SIZETEXT );
            }
            break;

        case WS_COMMENT4:
            if( WsItem->m_Legende )
                msg = WsItem->m_Legende;
            msg += GetTitleBlock().GetComment4();
            if( !msg.IsEmpty() )
            {
                DrawGraphicText( m_canvas, DC, pos, Color,
                                 msg, TEXT_ORIENT_HORIZ, size,
                                 GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_VJUSTIFY_CENTER,
                                 width, false, false );
                UpperLimit = MAX( UpperLimit, WsItem->m_Posy + SIZETEXT );
            }
            break;

        case WS_UPPER_SEGMENT:
            if( UpperLimit == 0 )
                break;

        case WS_LEFT_SEGMENT:
            WS_MostUpperLine.m_Posy =
                WS_MostUpperLine.m_Endy    =
                    WS_MostLeftLine.m_Posy = UpperLimit;
            pos.y = (refy - WsItem->m_Posy) * scale;

        case WS_SEGMENT:
            xg = pageSize.x -
                 GRID_REF_W - pageInfo.GetRightMarginMils() - WsItem->m_Endx;
            yg = pageSize.y -
                 GRID_REF_W - pageInfo.GetBottomMarginMils() - WsItem->m_Endy;
            GRLine( m_canvas->GetClipBox(), DC, pos.x, pos.y,
                    xg * scale, yg * scale, width, Color );
            break;
        }
    }

#endif
}
void WS_DRAW_ITEM_LIST::BuildWorkSheetGraphicList(
                       const PAGE_INFO& aPageInfo,
                       const TITLE_BLOCK& aTitleBlock,
                       COLOR4D aColor, COLOR4D aAltColor )
{
    WORKSHEET_LAYOUT& pglayout = WORKSHEET_LAYOUT::GetTheInstance();

    #define milsTomm (25.4/1000)

    m_titleBlock = &aTitleBlock;
    m_paperFormat = &aPageInfo.GetType();

    wxPoint LTmargin( Mm2mils( pglayout.GetLeftMargin() ),
                      Mm2mils( pglayout.GetTopMargin() ) );
    wxPoint RBmargin( Mm2mils( pglayout.GetRightMargin() ),
                      Mm2mils( pglayout.GetBottomMargin() ) );

    SetMargins( LTmargin, RBmargin );
    SetPageSize( aPageInfo.GetSizeMils() );

    // Build the basic layout shape, if the layout list is empty
    if( pglayout.GetCount() == 0 && !pglayout.VoidListAllowed() )
        pglayout.SetPageLayout();

    WORKSHEET_DATAITEM::m_WSunits2Iu = m_milsToIu / milsTomm;
    WORKSHEET_DATAITEM::m_Color = aColor;       // the default color to draw items
    WORKSHEET_DATAITEM::m_AltColor = aAltColor; // an alternate color to draw items

    // Left top corner position
    DPOINT lt_corner;
    lt_corner.x = pglayout.GetLeftMargin();
    lt_corner.y = pglayout.GetTopMargin();
    WORKSHEET_DATAITEM::m_LT_Corner = lt_corner;

    // Right bottom corner position
    DPOINT rb_corner;
    rb_corner.x = (m_pageSize.x*milsTomm) - pglayout.GetRightMargin();
    rb_corner.y = (m_pageSize.y*milsTomm) - pglayout.GetBottomMargin();
    WORKSHEET_DATAITEM::m_RB_Corner = rb_corner;

    WS_DRAW_ITEM_TEXT* gtext;
    int pensize;

    for( unsigned ii = 0; ; ii++ )
    {
        WORKSHEET_DATAITEM*  wsItem = pglayout.GetItem( ii );

        if( wsItem == NULL )
            break;

        // Generate it only if the page option allows this
        if( wsItem->GetPage1Option() < 0    // Not on page 1
            && m_sheetNumber <= 1 )
            continue;

        if( wsItem->GetPage1Option() > 0    // Only on page 1
            && m_sheetNumber > 1 )
            continue;

        COLOR4D color = wsItem->GetItemColor();

        pensize = wsItem->GetPenSizeUi();

        switch( wsItem->GetType() )
        {
        case WORKSHEET_DATAITEM::WS_TEXT:
        {
            WORKSHEET_DATAITEM_TEXT * wsText = (WORKSHEET_DATAITEM_TEXT*)wsItem;
            bool multilines = false;

            if( wsText->m_SpecialMode )
                wsText->m_FullText = wsText->m_TextBase;
            else
            {
                wsText->m_FullText = BuildFullText( wsText->m_TextBase );
                multilines = wsText->ReplaceAntiSlashSequence();
            }

            if( wsText->m_FullText.IsEmpty() )
                break;

            if( pensize == 0 )
                pensize = m_penSize;

            wsText->SetConstrainedTextSize();
            wxSize textsize;

            textsize.x = KiROUND( wsText->m_ConstrainedTextSize.x
                                  * WORKSHEET_DATAITEM::m_WSunits2Iu );
            textsize.y = KiROUND( wsText->m_ConstrainedTextSize.y
                                  * WORKSHEET_DATAITEM::m_WSunits2Iu );

            if( wsText->IsBold())
                pensize = GetPenSizeForBold( std::min( textsize.x, textsize.y ) );

            for( int jj = 0; jj < wsText->m_RepeatCount; jj++)
            {
                if( jj && ! wsText->IsInsidePage( jj ) )
                    continue;

                gtext = new WS_DRAW_ITEM_TEXT( wsText, wsText->m_FullText,
                                               wsText->GetStartPosUi( jj ),
                                               textsize, pensize, color,
                                               wsText->IsItalic(),
                                               wsText->IsBold() );
                Append( gtext );
                gtext->SetMultilineAllowed( multilines );
                wsText->TransfertSetupToGraphicText( gtext );

                // Increment label for the next text
                // (has no meaning for multiline texts)
                if( wsText->m_RepeatCount > 1 && !multilines )
                    wsText->IncrementLabel( (jj+1)*wsText->m_IncrementLabel);
            }
        }
            break;

        case WORKSHEET_DATAITEM::WS_SEGMENT:
            if( pensize == 0 )
                pensize = m_penSize;

            for( int jj = 0; jj < wsItem->m_RepeatCount; jj++ )
            {
                if( jj && ! wsItem->IsInsidePage( jj ) )
                    continue;
                Append( new WS_DRAW_ITEM_LINE( wsItem, wsItem->GetStartPosUi( jj ),
                                               wsItem->GetEndPosUi( jj ),
                                               pensize, color ) );
            }
            break;

        case WORKSHEET_DATAITEM::WS_RECT:
            if( pensize == 0 )
                pensize = m_penSize;

            for( int jj = 0; jj < wsItem->m_RepeatCount; jj++ )
            {
                if( jj && ! wsItem->IsInsidePage( jj ) )
                    break;

                Append( new WS_DRAW_ITEM_RECT( wsItem, wsItem->GetStartPosUi( jj ),
                                               wsItem->GetEndPosUi( jj ),
                                               pensize, color ) );
            }
            break;

        case WORKSHEET_DATAITEM::WS_POLYPOLYGON:
        {
            WORKSHEET_DATAITEM_POLYPOLYGON * wspoly =
                (WORKSHEET_DATAITEM_POLYPOLYGON*) wsItem;
            for( int jj = 0; jj < wsItem->m_RepeatCount; jj++ )
            {
                if( jj && ! wsItem->IsInsidePage( jj ) )
                    continue;

                for( int kk = 0; kk < wspoly->GetPolyCount(); kk++ )
                {
                    const bool fill = true;
                    WS_DRAW_ITEM_POLYGON* poly = new WS_DRAW_ITEM_POLYGON( wspoly,
                                                wspoly->GetStartPosUi( jj ),
                                                fill, pensize, color );
                    Append( poly );

                    // Create polygon outline
                    unsigned ist = wspoly->GetPolyIndexStart( kk );
                    unsigned iend = wspoly->GetPolyIndexEnd( kk );
                    while( ist <= iend )
                        poly->m_Corners.push_back(
                            wspoly->GetCornerPositionUi( ist++, jj ) );

                }
            }
        }
            break;

        case WORKSHEET_DATAITEM::WS_BITMAP:

            ((WORKSHEET_DATAITEM_BITMAP*)wsItem)->SetPixelScaleFactor();

            for( int jj = 0; jj < wsItem->m_RepeatCount; jj++ )
            {
                if( jj && ! wsItem->IsInsidePage( jj ) )
                    continue;

                Append( new WS_DRAW_ITEM_BITMAP( wsItem,
                    wsItem->GetStartPosUi( jj ) ) );
            }
            break;

        }
    }
}
Example #15
0
bool SCH_TEXT::Load( LINE_READER& aLine, wxString& aErrorMsg )
{
    char      Name1[256];
    char      Name2[256];
    char      Name3[256];
    int       thickness = 0, size = 0, orient = 0;

    Name1[0] = 0; Name2[0] = 0; Name3[0] = 0;

    char*     sline = (char*) aLine;

    while( ( *sline != ' ' ) && *sline )
        sline++;

    // sline points the start of parameters
    int ii = sscanf( sline, "%255s %d %d %d %d %255s %255s %d", Name1, &m_Pos.x, &m_Pos.y,
                     &orient, &size, Name2, Name3, &thickness );

    if( ii < 4 )
    {
        aErrorMsg.Printf( wxT( "Eeschema file text load error at line %d" ),
                          aLine.LineNumber() );
        return false;
    }

    if( !aLine.ReadLine() )
    {
        aErrorMsg.Printf( wxT( "Eeschema file text load error at line %d" ),
                          aLine.LineNumber() );
        return false;
    }

    if( size == 0 )
        size = GetDefaultTextSize();

    char* text = strtok( (char*) aLine, "\n\r" );

    if( text == NULL )
    {
        aErrorMsg.Printf( wxT( "Eeschema file text load error at line %d" ),
                          aLine.LineNumber() );
        return false;
    }

    wxString val = FROM_UTF8( text );

    for( ; ; )
    {
        int i = val.find( wxT( "\\n" ) );

        if( i == wxNOT_FOUND )
            break;

        val.erase( i, 2 );
        val.insert( i, wxT( "\n" ) );
    }

    m_Text = val;
    m_Size.x = m_Size.y = size;
    SetOrientation( orient );

    if( isdigit( Name3[0] ) )
    {
        thickness = atol( Name3 );
        m_Bold = ( thickness != 0 );
        m_Thickness = m_Bold ? GetPenSizeForBold( size ) : 0;
    }

    if( strnicmp( Name2, "Italic", 6 ) == 0 )
        m_Italic = 1;

    return true;
}
Example #16
0
bool SCH_HIERLABEL::Load( LINE_READER& aLine, wxString& aErrorMsg )
{
    char      Name1[256];
    char      Name2[256];
    char      Name3[256];
    int       thickness = 0, size = 0, orient = 0;

    Name1[0] = 0; Name2[0] = 0; Name3[0] = 0;

    char*     sline = (char*) aLine;

    while( (*sline != ' ' ) && *sline )
        sline++;

    // sline points the start of parameters
    int ii = sscanf( sline, "%255s %d %d %d %d %255s %255s %d", Name1, &m_Pos.x, &m_Pos.y,
                     &orient, &size, Name2, Name3, &thickness );

    if( ii < 4 )
    {
        aErrorMsg.Printf( wxT( "Eeschema file hierarchical label load error at line %d" ),
                          aLine.LineNumber() );
        return false;
    }

    if( !aLine.ReadLine() )
    {
        aErrorMsg.Printf( wxT( "Eeschema file hierarchical label load  error at line %d" ),
                          aLine.LineNumber() );
        return false;
    }

    if( size == 0 )
        size = GetDefaultTextSize();

    char* text = strtok( (char*) aLine, "\n\r" );

    if( text == NULL )
    {
        aErrorMsg.Printf( wxT( "Eeschema file hierarchical label load error at line %d" ),
                          aLine.LineNumber() );
        return false;
    }

    m_Text = FROM_UTF8( text );
    m_Size.x = m_Size.y = size;
    SetOrientation( orient );
    m_shape  = NET_INPUT;
    m_Bold = ( thickness != 0 );
    m_Thickness = m_Bold ? GetPenSizeForBold( size ) : 0;

    if( stricmp( Name2, SheetLabelType[NET_OUTPUT] ) == 0 )
        m_shape = NET_OUTPUT;

    if( stricmp( Name2, SheetLabelType[NET_BIDI] ) == 0 )
        m_shape = NET_BIDI;

    if( stricmp( Name2, SheetLabelType[NET_TRISTATE] ) == 0 )
        m_shape = NET_TRISTATE;

    if( stricmp( Name2, SheetLabelType[NET_UNSPECIFIED] ) == 0 )
        m_shape = NET_UNSPECIFIED;

    if( stricmp( Name3, "Italic" ) == 0 )
        m_Italic = 1;

    return true;
}