class_edge_mod.cpp 8.07 KB
Newer Older
1 2 3
/*
 * This program source code file is part of KiCad, a free EDA CAD application.
 *
4 5 6 7
 * Copyright (C) 2012 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr
 * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
 * Copyright (C) 2012 Wayne Stambaugh <stambaughw@verizon.net>
 * Copyright (C) 1992-2012 KiCad Developers, see AUTHORS.txt for contributors.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, you may find one here:
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * or you may search the http://www.gnu.org website for the version 2 license,
 * or you may write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 */

27 28 29 30
/**
 * @file class_edge_mod.cpp
 * @brief EDGE_MODULE class definition.
 */
31

32 33 34 35 36
#include <fctsys.h>
#include <gr_basic.h>
#include <wxstruct.h>
#include <trigo.h>
#include <class_drawpanel.h>
37
#include <class_pcb_screen.h>
38 39 40 41 42
#include <confirm.h>
#include <kicad_string.h>
#include <colors_selection.h>
#include <richio.h>
#include <macros.h>
43
#include <math_for_graphics.h>
44 45
#include <wxBasePcbFrame.h>
#include <pcbcommon.h>
46 47
#include <msgpanel.h>
#include <base_units.h>
48 49 50 51

#include <class_board.h>
#include <class_module.h>
#include <class_edge_mod.h>
52

53
#include <stdio.h>
54

Dick Hollenbeck's avatar
Dick Hollenbeck committed
55
EDGE_MODULE::EDGE_MODULE( MODULE* parent, STROKE_T aShape ) :
56
    DRAWSEGMENT( parent, PCB_MODULE_EDGE_T )
57
{
Dick Hollenbeck's avatar
Dick Hollenbeck committed
58
    m_Shape = aShape;
charras's avatar
charras committed
59
    m_Angle = 0;
60
    m_Layer = SILKSCREEN_N_FRONT;
61 62
}

63

64 65 66 67
EDGE_MODULE::~EDGE_MODULE()
{
}

68

69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
const EDGE_MODULE& EDGE_MODULE::operator = ( const EDGE_MODULE& rhs )
{
    if( &rhs == this )
        return *this;

    DRAWSEGMENT::operator=( rhs );

    m_Start0 = rhs.m_Start0;
    m_End0   = rhs.m_End0;

    m_PolyPoints = rhs.m_PolyPoints;    // std::vector copy
    return *this;
}


84
void EDGE_MODULE::Copy( EDGE_MODULE* source )
85
{
86 87 88
    if( source == NULL )
        return;

89
    *this = *source;
90 91
}

stambaughw's avatar
stambaughw committed
92

93
void EDGE_MODULE::SetDrawCoord()
94
{
95
    MODULE* module = (MODULE*) m_Parent;
96 97 98 99

    m_Start = m_Start0;
    m_End   = m_End0;

100
    if( module )
101
    {
102 103 104
        RotatePoint( &m_Start.x, &m_Start.y, module->GetOrientation() );
        RotatePoint( &m_End.x,   &m_End.y,   module->GetOrientation() );

105 106
        m_Start += module->GetPosition();
        m_End   += module->GetPosition();
107
    }
108 109 110
}


111 112
void EDGE_MODULE::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, GR_DRAWMODE draw_mode,
                        const wxPoint& offset )
113
{
114
    int             ux0, uy0, dx, dy, radius, StAngle, EndAngle;
115
    int             type_trace;
116
    int             typeaff;
117
    LAYER_NUM curr_layer = ( (PCB_SCREEN*) panel->GetScreen() )->m_Active_Layer;
118
    PCB_BASE_FRAME* frame;
119
    MODULE* module = (MODULE*) m_Parent;
120

121 122
    if( module == NULL )
        return;
123

124

125
    BOARD * brd = GetBoard( );
126

127
    if( brd->IsLayerVisible( m_Layer ) == false )
128 129
        return;

130
    EDA_COLOR_T color = brd->GetLayerColor( m_Layer );
131

132 133 134
    if(( draw_mode & GR_ALLOW_HIGHCONTRAST ) && DisplayOpt.ContrastModeDisplay )
    {
        if( !IsOnLayer( curr_layer ) )
135
            ColorTurnToDarkDarkGray( &color );
136 137 138
    }


139
    frame = (PCB_BASE_FRAME*) panel->GetParent();
140 141

    type_trace = m_Shape;
dickelbeck's avatar
dickelbeck committed
142 143

    ux0 = m_Start.x - offset.x;
144
    uy0 = m_Start.y - offset.y;
dickelbeck's avatar
dickelbeck committed
145

charras's avatar
charras committed
146 147
    dx = m_End.x - offset.x;
    dy = m_End.y - offset.y;
148 149 150

    GRSetDrawMode( DC, draw_mode );
    typeaff = frame->m_DisplayModEdge;
151

152
    if( m_Layer <= LAST_COPPER_LAYER )
153 154
    {
        typeaff = frame->m_DisplayPcbTrackFill;
155

156 157 158
        if( !typeaff )
            typeaff = SKETCH;
    }
159

160
    if( DC->LogicalToDeviceXRel( m_Width ) <= MIN_DRAW_WIDTH )
161
        typeaff = LINE;
162 163 164 165

    switch( type_trace )
    {
    case S_SEGMENT:
166
        if( typeaff == LINE )
167
            GRLine( panel->GetClipBox(), DC, ux0, uy0, dx, dy, 0, color );
168
        else if( typeaff == FILLED )
169
            GRLine( panel->GetClipBox(), DC, ux0, uy0, dx, dy, m_Width, color );
170 171
        else
            // SKETCH Mode
172
            GRCSegm( panel->GetClipBox(), DC, ux0, uy0, dx, dy, m_Width, color );
173

174 175 176
        break;

    case S_CIRCLE:
177
        radius = KiROUND( Distance( ux0, uy0, dx, dy ) );
178

179
        if( typeaff == LINE )
180
        {
181
            GRCircle( panel->GetClipBox(), DC, ux0, uy0, radius, color );
182 183 184 185 186
        }
        else
        {
            if( typeaff == FILLED )
            {
187
                GRCircle( panel->GetClipBox(), DC, ux0, uy0, radius, m_Width, color );
188 189 190
            }
            else        // SKETCH Mode
            {
191 192
                GRCircle( panel->GetClipBox(), DC, ux0, uy0, radius + (m_Width / 2), color );
                GRCircle( panel->GetClipBox(), DC, ux0, uy0, radius - (m_Width / 2), color );
193 194
            }
        }
195

196 197 198
        break;

    case S_ARC:
199 200
        radius   = KiROUND( Distance( ux0, uy0, dx, dy ) );
        StAngle  = ArcTangente( dy - uy0, dx - ux0 );
201
        EndAngle = StAngle + m_Angle;
202

203 204 205 206 207 208 209 210 211 212
        if( !panel->GetPrintMirrored() )
        {
            if( StAngle > EndAngle )
                EXCHG( StAngle, EndAngle );
        }
        else    // Mirrored mode: arc orientation is reversed
        {
            if( StAngle < EndAngle )
                EXCHG( StAngle, EndAngle );
        }
213

214
        if( typeaff == LINE )
215
        {
216
            GRArc( panel->GetClipBox(), DC, ux0, uy0, StAngle, EndAngle, radius, color );
217 218 219
        }
        else if( typeaff == FILLED )
        {
220
            GRArc( panel->GetClipBox(), DC, ux0, uy0, StAngle, EndAngle, radius, m_Width, color );
221 222 223
        }
        else        // SKETCH Mode
        {
224
            GRArc( panel->GetClipBox(), DC, ux0, uy0, StAngle, EndAngle,
225
                   radius + (m_Width / 2), color );
226
            GRArc( panel->GetClipBox(), DC, ux0, uy0, StAngle, EndAngle,
227
                   radius - (m_Width / 2), color );
228 229 230 231
        }
        break;

    case S_POLYGON:
charras's avatar
charras committed
232

233 234
        // We must compute true coordinates from m_PolyPoints
        // which are relative to module position, orientation 0
235

236
        std::vector<wxPoint> points = m_PolyPoints;
237

238 239 240
        for( unsigned ii = 0; ii < points.size(); ii++ )
        {
            wxPoint& pt = points[ii];
241

242
            RotatePoint( &pt.x, &pt.y, module->GetOrientation() );
243
            pt += module->GetPosition() - offset;
244
        }
245

246
        GRPoly( panel->GetClipBox(), DC, points.size(), &points[0], true, m_Width, color, color );
247 248
        break;
    }
249
}
250 251


dickelbeck's avatar
dickelbeck committed
252
// see class_edge_mod.h
253
void EDGE_MODULE::GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList )
254
{
255
    wxString msg;
256

charras's avatar
charras committed
257 258
    MODULE*  module = (MODULE*) m_Parent;

259 260
    if( !module )
        return;
dickelbeck's avatar
dickelbeck committed
261

262
    BOARD* board = (BOARD*) module->GetParent();
263

dickelbeck's avatar
dickelbeck committed
264 265 266
    if( !board )
        return;

267
    aList.push_back( MSG_PANEL_ITEM( _( "Graphic Item" ), wxEmptyString, DARKCYAN ) );
268 269
    aList.push_back( MSG_PANEL_ITEM( _( "Module" ), module->GetReference(), DARKCYAN ) );
    aList.push_back( MSG_PANEL_ITEM( _( "Value" ), module->GetValue(), BLUE ) );
Dick Hollenbeck's avatar
Dick Hollenbeck committed
270
    msg.Printf( wxT( "%8.8lX" ), module->GetTimeStamp() );
271
    aList.push_back( MSG_PANEL_ITEM( _( "TimeStamp" ), msg, BROWN ) );
272
    aList.push_back( MSG_PANEL_ITEM( _( "Mod Layer" ),
273
                     module->GetLayerName(), RED ) );
274
    aList.push_back( MSG_PANEL_ITEM( _( "Seg Layer" ),
275
                     GetLayerName(), RED ) );
276 277
    msg = ::CoordinateToString( m_Width );
    aList.push_back( MSG_PANEL_ITEM( _( "Width" ), msg, BLUE ) );
278
}
279 280 281



282 283 284
wxString EDGE_MODULE::GetSelectMenuText() const
{
    wxString text;
285 286 287 288
    text.Printf( _( "Graphic (%s) on %s of %s" ),
            GetChars( ShowShape( (STROKE_T) m_Shape ) ),
            GetChars( GetLayerName() ),
            GetChars( ((MODULE*) GetParent())->GetReference() ) );
289 290 291 292 293

    return text;
}


294
EDA_ITEM* EDGE_MODULE::Clone() const
295 296 297 298
{
    return new EDGE_MODULE( *this );
}