kicad/eeschema/lib_pin.cpp

1222 lines
41 KiB
C++
Raw Normal View History

/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2016 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2015 Wayne Stambaugh <stambaughw@gmail.com>
* Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
*
* 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
*/
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
#include <pgm_base.h>
#include <sch_draw_panel.h>
2018-01-30 10:49:51 +00:00
#include <sch_edit_frame.h>
2020-10-31 01:27:16 +00:00
#include <symbol_edit_frame.h>
#include <lib_pin.h>
#include <settings/settings_manager.h>
2020-10-31 01:27:16 +00:00
#include <symbol_editor/symbol_editor_settings.h>
2020-10-14 03:37:48 +00:00
#include <trigo.h>
#include <string_utils.h>
#include "sch_painter.h"
2008-09-13 18:59:57 +00:00
// small margin in internal units between the pin text and the pin line
#define PIN_TEXT_MARGIN 4
const wxString LIB_PIN::GetCanonicalElectricalTypeName( ELECTRICAL_PINTYPE aType )
{
// These strings are the canonical name of the electrictal type
// Not translated, no space in name, only ASCII chars.
// to use when the string name must be known and well defined
// must have same order than enum ELECTRICAL_PINTYPE (see lib_pin.h)
static const wxChar* msgPinElectricType[] =
{
wxT( "input" ),
wxT( "output" ),
wxT( "bidirectional" ),
wxT( "tri_state" ),
wxT( "passive" ),
wxT( "free" ),
wxT( "unspecified" ),
wxT( "power_in" ),
wxT( "power_out" ),
wxT( "open_collector" ),
wxT( "open_emitter" ),
wxT( "no_connect" )
};
return msgPinElectricType[static_cast<int>( aType )];
}
/// Utility for getting the size of the 'internal' pin decorators (as a radius)
// i.e. the clock symbols (falling clock is actually external but is of
// the same kind)
2020-12-20 18:18:54 +00:00
static int internalPinDecoSize( const RENDER_SETTINGS* aSettings, const LIB_PIN &aPin )
{
2020-12-20 18:18:54 +00:00
const KIGFX::SCH_RENDER_SETTINGS* settings = static_cast<const KIGFX::SCH_RENDER_SETTINGS*>( aSettings );
if( settings && settings->m_PinSymbolSize )
return settings->m_PinSymbolSize;
return aPin.GetNameTextSize() != 0 ? aPin.GetNameTextSize() / 2 : aPin.GetNumberTextSize() / 2;
}
/// Utility for getting the size of the 'external' pin decorators (as a radius)
// i.e. the negation circle, the polarity 'slopes' and the nonlogic
// marker
2020-12-20 18:18:54 +00:00
static int externalPinDecoSize( const RENDER_SETTINGS* aSettings, const LIB_PIN &aPin )
{
2020-12-20 18:18:54 +00:00
const KIGFX::SCH_RENDER_SETTINGS* settings = static_cast<const KIGFX::SCH_RENDER_SETTINGS*>( aSettings );
if( settings && settings->m_PinSymbolSize )
return settings->m_PinSymbolSize;
return aPin.GetNumberTextSize() / 2;
}
2021-06-10 18:51:46 +00:00
LIB_PIN::LIB_PIN( LIB_SYMBOL* aParent ) :
LIB_ITEM( LIB_PIN_T, aParent ),
2020-11-07 21:55:18 +00:00
m_orientation( PIN_RIGHT ),
m_shape( GRAPHIC_PINSHAPE::LINE ),
m_type( ELECTRICAL_PINTYPE::PT_UNSPECIFIED ),
m_attributes( 0 )
{
// Use the application settings for pin sizes if exists.
// pgm can be nullptr when running a shared lib from a script, not from a kicad appl
PGM_BASE* pgm = PgmOrNull();
if( pgm )
{
2020-10-31 01:27:16 +00:00
auto* settings = pgm->GetSettingsManager().GetAppSettings<SYMBOL_EDITOR_SETTINGS>();
m_length = Mils2iu( settings->m_Defaults.pin_length );
m_numTextSize = Mils2iu( settings->m_Defaults.pin_num_size );
m_nameTextSize = Mils2iu( settings->m_Defaults.pin_name_size );
}
2020-10-31 01:27:16 +00:00
else // Use hardcoded eeschema defaults: symbol_editor settings are not existing.
{
m_length = Mils2iu( DEFAULT_PIN_LENGTH );
m_numTextSize = Mils2iu( DEFAULT_PINNUM_SIZE );
m_nameTextSize = Mils2iu( DEFAULT_PINNAME_SIZE );
}
2009-06-13 17:06:07 +00:00
}
2021-06-10 18:51:46 +00:00
LIB_PIN::LIB_PIN( LIB_SYMBOL* aParent, const wxString& aName, const wxString& aNumber,
2020-11-07 21:55:18 +00:00
int aOrientation, ELECTRICAL_PINTYPE aPinType, int aLength, int aNameTextSize,
int aNumTextSize, int aConvert, const wxPoint& aPos, int aUnit ) :
LIB_ITEM( LIB_PIN_T, aParent ),
m_position( aPos ),
m_length( aLength ),
m_orientation( aOrientation ),
m_shape( GRAPHIC_PINSHAPE::LINE ),
m_type( aPinType ),
m_attributes( 0 ),
m_numTextSize( aNumTextSize ),
m_nameTextSize( aNameTextSize )
{
SetName( aName );
SetNumber( aNumber );
SetUnit( aUnit );
SetConvert( aConvert );
}
bool LIB_PIN::HitTest( const wxPoint& aPosition, int aAccuracy ) const
2009-06-13 17:06:07 +00:00
{
EDA_RECT rect = GetBoundingBox();
return rect.Inflate( aAccuracy ).Contains( aPosition );
}
bool LIB_PIN::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
{
2020-11-14 18:11:28 +00:00
if( m_flags & (STRUCT_DELETED | SKIP_STRUCT ) )
return false;
EDA_RECT sel = aRect;
if ( aAccuracy )
sel.Inflate( aAccuracy );
if( aContained )
return sel.Contains( GetBoundingBox( false, true ) );
return sel.Intersects( GetBoundingBox( false, true ) );
}
2020-04-14 12:25:00 +00:00
int LIB_PIN::GetPenWidth() const
{
return 0;
}
wxString LIB_PIN::GetShownName() const
{
if( m_name == "~" )
return wxEmptyString;
else
return m_name;
}
wxPoint LIB_PIN::GetPinRoot() const
{
switch( m_orientation )
{
default:
case PIN_RIGHT: return wxPoint( m_position.x + m_length, -( m_position.y ) );
case PIN_LEFT: return wxPoint( m_position.x - m_length, -( m_position.y ) );
case PIN_UP: return wxPoint( m_position.x, -( m_position.y - m_length ) );
case PIN_DOWN: return wxPoint( m_position.x, -( m_position.y + m_length ) );
}
}
2020-12-20 18:18:54 +00:00
void LIB_PIN::print( const RENDER_SETTINGS* aSettings, const wxPoint& aOffset, void* aData,
2020-04-14 12:25:00 +00:00
const TRANSFORM& aTransform )
2008-09-13 18:59:57 +00:00
{
LIB_SYMBOL_OPTIONS* opts = (LIB_SYMBOL_OPTIONS*) aData;
2020-04-17 20:11:12 +00:00
bool drawHiddenFields = opts ? opts->draw_hidden_fields : false;
bool showPinType = opts ? opts->show_elec_type : false;
bool show_connect_point = opts ? opts->show_connect_point : false;
2020-04-17 20:11:12 +00:00
2021-06-10 18:51:46 +00:00
LIB_SYMBOL* part = GetParent();
/* Calculate pin orient taking in account the symbol orientation. */
int orient = PinDrawOrient( aTransform );
/* Calculate the pin position */
wxPoint pos1 = aTransform.TransformCoordinate( m_position ) + aOffset;
2020-04-17 20:11:12 +00:00
if( IsVisible() || drawHiddenFields )
{
printPinSymbol( aSettings, pos1, orient );
2008-09-13 18:59:57 +00:00
printPinTexts( aSettings, pos1, orient, part->GetPinNameOffset(), part->ShowPinNumbers(),
part->ShowPinNames() );
2020-04-17 20:11:12 +00:00
if( showPinType )
printPinElectricalTypeName( aSettings, pos1, orient );
if( show_connect_point )
{
wxDC* DC = aSettings->GetPrintDC();
COLOR4D color = aSettings->GetLayerColor( IsVisible() ? LAYER_PIN : LAYER_HIDDEN );
GRCircle( nullptr, DC, pos1.x, pos1.y, TARGET_PIN_RADIUS, 0, color );
}
}
2008-09-13 18:59:57 +00:00
}
2020-12-20 18:18:54 +00:00
void LIB_PIN::printPinSymbol( const RENDER_SETTINGS* aSettings, const wxPoint& aPos, int aOrient )
2008-09-13 18:59:57 +00:00
{
2020-04-14 12:25:00 +00:00
wxDC* DC = aSettings->GetPrintDC();
int MapX1, MapY1, x1, y1;
int width = GetEffectivePenWidth( aSettings );
2020-04-14 12:25:00 +00:00
int posX = aPos.x, posY = aPos.y, len = m_length;
COLOR4D color = aSettings->GetLayerColor( IsVisible() ? LAYER_PIN : LAYER_HIDDEN );
2008-09-13 18:59:57 +00:00
MapX1 = MapY1 = 0;
2011-04-18 20:22:17 +00:00
x1 = posX;
y1 = posY;
2008-09-13 18:59:57 +00:00
switch( aOrient )
{
case PIN_UP: y1 = posY - len; MapY1 = 1; break;
case PIN_DOWN: y1 = posY + len; MapY1 = -1; break;
case PIN_LEFT: x1 = posX - len; MapX1 = 1; break;
case PIN_RIGHT: x1 = posX + len; MapX1 = -1; break;
}
if( m_shape == GRAPHIC_PINSHAPE::INVERTED || m_shape == GRAPHIC_PINSHAPE::INVERTED_CLOCK )
2008-09-13 18:59:57 +00:00
{
const int radius = externalPinDecoSize( aSettings, *this );
2020-04-14 12:25:00 +00:00
GRCircle( nullptr, DC, MapX1 * radius + x1, MapY1 * radius + y1, radius, width, color );
2008-09-13 18:59:57 +00:00
GRMoveTo( MapX1 * radius * 2 + x1, MapY1 * radius * 2 + y1 );
2020-04-14 12:25:00 +00:00
GRLineTo( nullptr, DC, posX, posY, width, color );
2008-09-13 18:59:57 +00:00
}
else
{
GRMoveTo( x1, y1 );
2020-04-14 12:25:00 +00:00
GRLineTo( nullptr, DC, posX, posY, width, color );
2008-09-13 18:59:57 +00:00
}
// Draw the clock shape (>)inside the symbol
2020-11-07 21:55:18 +00:00
if( m_shape == GRAPHIC_PINSHAPE::CLOCK
|| m_shape == GRAPHIC_PINSHAPE::INVERTED_CLOCK
|| m_shape == GRAPHIC_PINSHAPE::FALLING_EDGE_CLOCK
|| m_shape == GRAPHIC_PINSHAPE::CLOCK_LOW )
2008-09-13 18:59:57 +00:00
{
const int clock_size = internalPinDecoSize( aSettings, *this );
2008-09-13 18:59:57 +00:00
if( MapY1 == 0 ) /* MapX1 = +- 1 */
{
GRMoveTo( x1, y1 + clock_size );
2020-04-14 12:25:00 +00:00
GRLineTo( nullptr, DC, x1 - MapX1 * clock_size * 2, y1, width, color );
GRLineTo( nullptr, DC, x1, y1 - clock_size, width, color );
2008-09-13 18:59:57 +00:00
}
else /* MapX1 = 0 */
{
GRMoveTo( x1 + clock_size, y1 );
2020-04-14 12:25:00 +00:00
GRLineTo( nullptr, DC, x1, y1 - MapY1 * clock_size * 2, width, color );
GRLineTo( nullptr, DC, x1 - clock_size, y1, width, color );
2008-09-13 18:59:57 +00:00
}
}
// Draw the active low (or H to L active transition)
2020-11-07 21:55:18 +00:00
if( m_shape == GRAPHIC_PINSHAPE::INPUT_LOW
|| m_shape == GRAPHIC_PINSHAPE::FALLING_EDGE_CLOCK
|| m_shape == GRAPHIC_PINSHAPE::CLOCK_LOW )
2008-09-13 18:59:57 +00:00
{
const int deco_size = externalPinDecoSize( aSettings, *this );
2008-09-13 18:59:57 +00:00
if( MapY1 == 0 ) /* MapX1 = +- 1 */
{
GRMoveTo( x1 + MapX1 * deco_size * 2, y1 );
2020-04-14 12:25:00 +00:00
GRLineTo( nullptr, DC, x1 + MapX1 * deco_size * 2, y1 - deco_size * 2, width, color );
GRLineTo( nullptr, DC, x1, y1, width, color );
2008-09-13 18:59:57 +00:00
}
else /* MapX1 = 0 */
{
GRMoveTo( x1, y1 + MapY1 * deco_size * 2 );
2020-04-14 12:25:00 +00:00
GRLineTo( nullptr, DC, x1 - deco_size * 2, y1 + MapY1 * deco_size * 2, width, color );
GRLineTo( nullptr, DC, x1, y1, width, color );
2008-09-13 18:59:57 +00:00
}
}
if( m_shape == GRAPHIC_PINSHAPE::OUTPUT_LOW ) /* IEEE symbol "Active Low Output" */
2008-09-13 18:59:57 +00:00
{
const int deco_size = externalPinDecoSize( aSettings, *this );
2008-09-13 18:59:57 +00:00
if( MapY1 == 0 ) /* MapX1 = +- 1 */
{
GRMoveTo( x1, y1 - deco_size * 2 );
2020-04-14 12:25:00 +00:00
GRLineTo( nullptr, DC, x1 + MapX1 * deco_size * 2, y1, width, color );
2008-09-13 18:59:57 +00:00
}
else /* MapX1 = 0 */
{
GRMoveTo( x1 - deco_size * 2, y1 );
2020-04-14 12:25:00 +00:00
GRLineTo( nullptr, DC, x1, y1 + MapY1 * deco_size * 2, width, color );
2008-09-13 18:59:57 +00:00
}
}
else if( m_shape == GRAPHIC_PINSHAPE::NONLOGIC ) /* NonLogic pin symbol */
{
const int deco_size = externalPinDecoSize( aSettings, *this );
GRMoveTo( x1 - (MapX1 + MapY1) * deco_size, y1 - (MapY1 - MapX1) * deco_size );
2020-04-14 12:25:00 +00:00
GRLineTo( nullptr, DC, x1 + (MapX1 + MapY1) * deco_size,
y1 + ( MapY1 - MapX1 ) * deco_size, width, color );
GRMoveTo( x1 - (MapX1 - MapY1) * deco_size, y1 - (MapY1 + MapX1) * deco_size );
2020-04-14 12:25:00 +00:00
GRLineTo( nullptr, DC, x1 + (MapX1 - MapY1) * deco_size,
y1 + ( MapY1 + MapX1 ) * deco_size, width, color );
}
if( m_type == ELECTRICAL_PINTYPE::PT_NC ) // Draw a N.C. symbol
{
const int deco_size = TARGET_PIN_RADIUS;
2020-04-14 12:25:00 +00:00
GRLine( nullptr, DC, posX - deco_size, posY - deco_size, posX + deco_size,
posY + deco_size, width, color );
GRLine( nullptr, DC, posX + deco_size, posY - deco_size, posX - deco_size,
posY + deco_size, width, color );
}
2008-09-13 18:59:57 +00:00
}
2020-12-20 18:18:54 +00:00
void LIB_PIN::printPinTexts( const RENDER_SETTINGS* aSettings, wxPoint& aPinPos, int aPinOrient,
2020-11-07 21:55:18 +00:00
int aTextInside, bool aDrawPinNum, bool aDrawPinName )
2008-09-13 18:59:57 +00:00
{
2020-11-07 21:55:18 +00:00
if( !aDrawPinName && !aDrawPinNum )
return;
int x, y;
2020-04-14 12:25:00 +00:00
wxDC* DC = aSettings->GetPrintDC();
wxSize PinNameSize( m_nameTextSize, m_nameTextSize );
wxSize PinNumSize( m_numTextSize, m_numTextSize );
2020-04-14 12:25:00 +00:00
int namePenWidth = std::max( Clamp_Text_PenSize( GetPenWidth(), m_nameTextSize, false ),
aSettings->GetDefaultPenWidth() );
int numPenWidth = std::max( Clamp_Text_PenSize( GetPenWidth(), m_numTextSize, false ),
aSettings->GetDefaultPenWidth() );
int name_offset = Mils2iu( PIN_TEXT_MARGIN ) + namePenWidth;
int num_offset = Mils2iu( PIN_TEXT_MARGIN ) + numPenWidth;
2008-09-13 18:59:57 +00:00
/* Get the num and name colors */
2020-04-14 12:25:00 +00:00
COLOR4D NameColor = aSettings->GetLayerColor( IsVisible() ? LAYER_PINNAM : LAYER_HIDDEN );
COLOR4D NumColor = aSettings->GetLayerColor( IsVisible() ? LAYER_PINNUM : LAYER_HIDDEN );
2008-09-13 18:59:57 +00:00
2020-11-07 21:55:18 +00:00
int x1 = aPinPos.x;
int y1 = aPinPos.y;
2008-09-13 18:59:57 +00:00
2020-11-07 21:55:18 +00:00
switch( aPinOrient )
2008-09-13 18:59:57 +00:00
{
case PIN_UP: y1 -= m_length; break;
case PIN_DOWN: y1 += m_length; break;
case PIN_LEFT: x1 -= m_length; break;
case PIN_RIGHT: x1 += m_length; break;
2008-09-13 18:59:57 +00:00
}
wxString name = GetShownName();
wxString number = GetShownNumber();
if( name.IsEmpty() )
2020-11-07 21:55:18 +00:00
aDrawPinName = false;
2008-09-13 18:59:57 +00:00
if( number.IsEmpty() )
aDrawPinNum = false;
2020-11-07 21:55:18 +00:00
if( aTextInside ) // Draw the text inside, but the pin numbers outside.
2008-09-13 18:59:57 +00:00
{
2020-11-07 21:55:18 +00:00
if(( aPinOrient == PIN_LEFT) || ( aPinOrient == PIN_RIGHT) )
2008-09-13 18:59:57 +00:00
{
// It is an horizontal line
2020-11-07 21:55:18 +00:00
if( aDrawPinName )
2008-09-13 18:59:57 +00:00
{
2020-11-07 21:55:18 +00:00
if( aPinOrient == PIN_RIGHT )
2008-09-13 18:59:57 +00:00
{
2020-11-07 21:55:18 +00:00
x = x1 + aTextInside;
GRText( DC, wxPoint( x, y1 ), NameColor, name, TEXT_ANGLE_HORIZ, PinNameSize,
GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_VJUSTIFY_CENTER, namePenWidth, false,
false );
2008-09-13 18:59:57 +00:00
}
else // Orient == PIN_LEFT
{
2020-11-07 21:55:18 +00:00
x = x1 - aTextInside;
GRText( DC, wxPoint( x, y1 ), NameColor, name, TEXT_ANGLE_HORIZ, PinNameSize,
GR_TEXT_HJUSTIFY_RIGHT, GR_TEXT_VJUSTIFY_CENTER, namePenWidth, false,
false );
2008-09-13 18:59:57 +00:00
}
}
2020-11-07 21:55:18 +00:00
if( aDrawPinNum )
2008-09-13 18:59:57 +00:00
{
GRText( DC, wxPoint(( x1 + aPinPos.x) / 2, y1 - num_offset ), NumColor, number,
TEXT_ANGLE_HORIZ, PinNumSize, GR_TEXT_HJUSTIFY_CENTER,
GR_TEXT_VJUSTIFY_BOTTOM, numPenWidth, false, false );
2008-09-13 18:59:57 +00:00
}
}
else /* Its a vertical line. */
{
// Text is drawn from bottom to top (i.e. to negative value for Y axis)
2020-11-07 21:55:18 +00:00
if( aPinOrient == PIN_DOWN )
2008-09-13 18:59:57 +00:00
{
2020-11-07 21:55:18 +00:00
y = y1 + aTextInside;
2008-09-13 18:59:57 +00:00
2020-11-07 21:55:18 +00:00
if( aDrawPinName )
{
GRText( DC, wxPoint( x1, y ), NameColor, name, TEXT_ANGLE_VERT, PinNameSize,
2020-04-14 12:25:00 +00:00
GR_TEXT_HJUSTIFY_RIGHT, GR_TEXT_VJUSTIFY_CENTER, namePenWidth, false,
false );
2020-11-07 21:55:18 +00:00
}
2020-11-07 21:55:18 +00:00
if( aDrawPinNum )
{
GRText( DC, wxPoint( x1 - num_offset, ( y1 + aPinPos.y) / 2 ), NumColor,
number, TEXT_ANGLE_VERT, PinNumSize, GR_TEXT_HJUSTIFY_CENTER,
GR_TEXT_VJUSTIFY_BOTTOM, numPenWidth, false, false );
2020-11-07 21:55:18 +00:00
}
}
else /* PIN_UP */
{
2020-11-07 21:55:18 +00:00
y = y1 - aTextInside;
2008-09-13 18:59:57 +00:00
2020-11-07 21:55:18 +00:00
if( aDrawPinName )
{
GRText( DC, wxPoint( x1, y ), NameColor, name, TEXT_ANGLE_VERT, PinNameSize,
2020-04-14 12:25:00 +00:00
GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_VJUSTIFY_CENTER, namePenWidth, false,
false );
2020-11-07 21:55:18 +00:00
}
2020-11-07 21:55:18 +00:00
if( aDrawPinNum )
{
GRText( DC, wxPoint( x1 - num_offset, ( y1 + aPinPos.y) / 2 ), NumColor,
number, TEXT_ANGLE_VERT, PinNumSize, GR_TEXT_HJUSTIFY_CENTER,
GR_TEXT_VJUSTIFY_BOTTOM, numPenWidth, false, false );
2020-11-07 21:55:18 +00:00
}
2008-09-13 18:59:57 +00:00
}
}
}
else /**** Draw num & text pin outside ****/
{
2020-11-07 21:55:18 +00:00
if(( aPinOrient == PIN_LEFT) || ( aPinOrient == PIN_RIGHT) )
2008-09-13 18:59:57 +00:00
{
/* Its an horizontal line. */
2020-11-07 21:55:18 +00:00
if( aDrawPinName )
2008-09-13 18:59:57 +00:00
{
2020-11-07 21:55:18 +00:00
x = ( x1 + aPinPos.x) / 2;
GRText( DC, wxPoint( x, y1 - name_offset ), NameColor, name, TEXT_ANGLE_HORIZ,
PinNameSize, GR_TEXT_HJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_BOTTOM,
namePenWidth, false, false );
2008-09-13 18:59:57 +00:00
}
2020-11-07 21:55:18 +00:00
if( aDrawPinNum )
2008-09-13 18:59:57 +00:00
{
2020-11-07 21:55:18 +00:00
x = ( x1 + aPinPos.x) / 2;
GRText( DC, wxPoint( x, y1 + num_offset ), NumColor, number, TEXT_ANGLE_HORIZ,
2020-04-14 12:25:00 +00:00
PinNumSize, GR_TEXT_HJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_TOP, numPenWidth,
false, false );
2008-09-13 18:59:57 +00:00
}
}
else /* Its a vertical line. */
{
2020-11-07 21:55:18 +00:00
if( aDrawPinName )
2008-09-13 18:59:57 +00:00
{
2020-11-07 21:55:18 +00:00
y = ( y1 + aPinPos.y) / 2;
GRText( DC, wxPoint( x1 - name_offset, y ), NameColor, name, TEXT_ANGLE_VERT,
PinNameSize, GR_TEXT_HJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_BOTTOM,
namePenWidth, false, false );
2008-09-13 18:59:57 +00:00
}
2020-11-07 21:55:18 +00:00
if( aDrawPinNum )
2008-09-13 18:59:57 +00:00
{
GRText( DC, wxPoint( x1 + num_offset, ( y1 + aPinPos.y) / 2 ), NumColor, number,
TEXT_ANGLE_VERT, PinNumSize, GR_TEXT_HJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_TOP,
numPenWidth, false, false );
2008-09-13 18:59:57 +00:00
}
}
}
}
2008-09-13 19:06:31 +00:00
2009-06-13 17:06:07 +00:00
2020-12-20 18:18:54 +00:00
void LIB_PIN::printPinElectricalTypeName( const RENDER_SETTINGS* aSettings, wxPoint& aPosition,
2020-04-14 12:25:00 +00:00
int aOrientation )
{
2020-04-14 12:25:00 +00:00
wxDC* DC = aSettings->GetPrintDC();
wxString typeName = GetElectricalTypeName();
// Use a reasonable (small) size to draw the text
2020-04-14 12:25:00 +00:00
int textSize = ( m_nameTextSize * 3 ) / 4;
2020-04-14 12:25:00 +00:00
#define ETXT_MAX_SIZE Millimeter2iu( 0.7 )
2020-11-07 21:55:18 +00:00
if( textSize > ETXT_MAX_SIZE )
textSize = ETXT_MAX_SIZE;
// Use a reasonable pen size to draw the text
int pensize = textSize/6;
// Get a suitable color
2020-04-14 12:25:00 +00:00
COLOR4D color = aSettings->GetLayerColor( IsVisible() ? LAYER_NOTES : LAYER_HIDDEN );
wxPoint txtpos = aPosition;
int offset = Millimeter2iu( 0.4 );
EDA_TEXT_HJUSTIFY_T hjustify = GR_TEXT_HJUSTIFY_LEFT;
int orient = TEXT_ANGLE_HORIZ;
switch( aOrientation )
{
case PIN_UP:
txtpos.y += offset;
orient = TEXT_ANGLE_VERT;
hjustify = GR_TEXT_HJUSTIFY_RIGHT;
break;
case PIN_DOWN:
txtpos.y -= offset;
orient = TEXT_ANGLE_VERT;
break;
case PIN_LEFT:
txtpos.x += offset;
break;
case PIN_RIGHT:
txtpos.x -= offset;
hjustify = GR_TEXT_HJUSTIFY_RIGHT;
break;
}
2020-04-14 12:25:00 +00:00
GRText( DC, txtpos, color, typeName, orient, wxSize( textSize, textSize ), hjustify,
GR_TEXT_VJUSTIFY_CENTER, pensize, false, false, nullptr );
}
void LIB_PIN::PlotSymbol( PLOTTER* aPlotter, const wxPoint& aPosition, int aOrientation ) const
{
2020-04-14 12:25:00 +00:00
int MapX1, MapY1, x1, y1;
COLOR4D color = aPlotter->RenderSettings()->GetLayerColor( LAYER_PIN );
int penWidth = GetEffectivePenWidth( aPlotter->RenderSettings() );
aPlotter->SetColor( color );
2020-04-14 12:25:00 +00:00
aPlotter->SetCurrentLineWidth( penWidth );
MapX1 = MapY1 = 0;
x1 = aPosition.x; y1 = aPosition.y;
switch( aOrientation )
{
case PIN_UP: y1 = aPosition.y - m_length; MapY1 = 1; break;
case PIN_DOWN: y1 = aPosition.y + m_length; MapY1 = -1; break;
case PIN_LEFT: x1 = aPosition.x - m_length; MapX1 = 1; break;
case PIN_RIGHT: x1 = aPosition.x + m_length; MapX1 = -1; break;
}
if( m_shape == GRAPHIC_PINSHAPE::INVERTED || m_shape == GRAPHIC_PINSHAPE::INVERTED_CLOCK )
{
const int radius = externalPinDecoSize( aPlotter->RenderSettings(), *this );
2020-04-14 12:25:00 +00:00
aPlotter->Circle( wxPoint( MapX1 * radius + x1, MapY1 * radius + y1 ), radius * 2,
FILL_T::NO_FILL, penWidth );
aPlotter->MoveTo( wxPoint( MapX1 * radius * 2 + x1, MapY1 * radius * 2 + y1 ) );
aPlotter->FinishTo( aPosition );
}
else if( m_shape == GRAPHIC_PINSHAPE::FALLING_EDGE_CLOCK )
{
const int deco_size = internalPinDecoSize( aPlotter->RenderSettings(), *this );
if( MapY1 == 0 ) /* MapX1 = +- 1 */
{
aPlotter->MoveTo( wxPoint( x1, y1 + deco_size ) );
aPlotter->LineTo( wxPoint( x1 + MapX1 * deco_size * 2, y1 ) );
aPlotter->FinishTo( wxPoint( x1, y1 - deco_size ) );
}
else /* MapX1 = 0 */
{
aPlotter->MoveTo( wxPoint( x1 + deco_size, y1 ) );
aPlotter->LineTo( wxPoint( x1, y1 + MapY1 * deco_size * 2 ) );
aPlotter->FinishTo( wxPoint( x1 - deco_size, y1 ) );
}
aPlotter->MoveTo( wxPoint( MapX1 * deco_size * 2 + x1, MapY1 * deco_size * 2 + y1 ) );
aPlotter->FinishTo( aPosition );
}
else
{
aPlotter->MoveTo( wxPoint( x1, y1 ) );
aPlotter->FinishTo( aPosition );
}
2020-11-07 21:55:18 +00:00
if( m_shape == GRAPHIC_PINSHAPE::CLOCK
|| m_shape == GRAPHIC_PINSHAPE::INVERTED_CLOCK
|| m_shape == GRAPHIC_PINSHAPE::CLOCK_LOW )
{
const int deco_size = internalPinDecoSize( aPlotter->RenderSettings(), *this );
if( MapY1 == 0 ) /* MapX1 = +- 1 */
{
aPlotter->MoveTo( wxPoint( x1, y1 + deco_size ) );
aPlotter->LineTo( wxPoint( x1 - MapX1 * deco_size * 2, y1 ) );
aPlotter->FinishTo( wxPoint( x1, y1 - deco_size ) );
}
else /* MapX1 = 0 */
{
aPlotter->MoveTo( wxPoint( x1 + deco_size, y1 ) );
aPlotter->LineTo( wxPoint( x1, y1 - MapY1 * deco_size * 2 ) );
aPlotter->FinishTo( wxPoint( x1 - deco_size, y1 ) );
}
}
if( m_shape == GRAPHIC_PINSHAPE::INPUT_LOW
|| m_shape == GRAPHIC_PINSHAPE::CLOCK_LOW ) /* IEEE symbol "Active Low Input" */
{
const int deco_size = externalPinDecoSize( aPlotter->RenderSettings(), *this );
if( MapY1 == 0 ) /* MapX1 = +- 1 */
{
aPlotter->MoveTo( wxPoint( x1 + MapX1 * deco_size * 2, y1 ) );
aPlotter->LineTo( wxPoint( x1 + MapX1 * deco_size * 2, y1 - deco_size * 2 ) );
aPlotter->FinishTo( wxPoint( x1, y1 ) );
}
else /* MapX1 = 0 */
{
aPlotter->MoveTo( wxPoint( x1, y1 + MapY1 * deco_size * 2 ) );
aPlotter->LineTo( wxPoint( x1 - deco_size * 2, y1 + MapY1 * deco_size * 2 ) );
aPlotter->FinishTo( wxPoint( x1, y1 ) );
}
}
if( m_shape == GRAPHIC_PINSHAPE::OUTPUT_LOW ) /* IEEE symbol "Active Low Output" */
{
const int symbol_size = externalPinDecoSize( aPlotter->RenderSettings(), *this );
if( MapY1 == 0 ) /* MapX1 = +- 1 */
{
aPlotter->MoveTo( wxPoint( x1, y1 - symbol_size * 2 ) );
aPlotter->FinishTo( wxPoint( x1 + MapX1 * symbol_size * 2, y1 ) );
}
else /* MapX1 = 0 */
{
aPlotter->MoveTo( wxPoint( x1 - symbol_size * 2, y1 ) );
aPlotter->FinishTo( wxPoint( x1, y1 + MapY1 * symbol_size * 2 ) );
}
}
else if( m_shape == GRAPHIC_PINSHAPE::NONLOGIC ) /* NonLogic pin symbol */
{
const int deco_size = externalPinDecoSize( aPlotter->RenderSettings(), *this );
aPlotter->MoveTo( wxPoint( x1 - (MapX1 + MapY1) * deco_size, y1 - (MapY1 - MapX1) * deco_size ) );
aPlotter->FinishTo( wxPoint( x1 + (MapX1 + MapY1) * deco_size, y1 + (MapY1 - MapX1) * deco_size ) );
aPlotter->MoveTo( wxPoint( x1 - (MapX1 - MapY1) * deco_size, y1 - (MapY1 + MapX1) * deco_size ) );
aPlotter->FinishTo( wxPoint( x1 + (MapX1 - MapY1) * deco_size, y1 + (MapY1 + MapX1) * deco_size ) );
}
2020-11-07 21:55:18 +00:00
if( m_type == ELECTRICAL_PINTYPE::PT_NC ) // Draw a N.C. symbol
{
const int deco_size = TARGET_PIN_RADIUS;
const int ex1 = aPosition.x;
const int ey1 = aPosition.y;
aPlotter->MoveTo( wxPoint( ex1 - deco_size, ey1 - deco_size ) );
aPlotter->FinishTo( wxPoint( ex1 + deco_size, ey1 + deco_size ) );
aPlotter->MoveTo( wxPoint( ex1 + deco_size, ey1 - deco_size ) );
aPlotter->FinishTo( wxPoint( ex1 - deco_size, ey1 + deco_size ) );
}
}
void LIB_PIN::PlotPinTexts( PLOTTER* aPlotter, const wxPoint& aPinPos, int aPinOrient, int aTextInside,
bool aDrawPinNum, bool aDrawPinName ) const
2008-09-13 19:06:31 +00:00
{
wxString name = GetShownName();
wxString number = GetShownNumber();
if( name.IsEmpty() )
2020-11-07 21:55:18 +00:00
aDrawPinName = false;
if( number.IsEmpty() )
2020-11-07 21:55:18 +00:00
aDrawPinNum = false;
2020-11-07 21:55:18 +00:00
if( !aDrawPinNum && !aDrawPinName )
return;
int x, y;
2020-11-07 21:55:18 +00:00
wxSize pinNameSize = wxSize( m_nameTextSize, m_nameTextSize );
wxSize pinNumSize = wxSize( m_numTextSize, m_numTextSize );
2008-09-13 19:06:31 +00:00
2020-04-14 12:25:00 +00:00
int namePenWidth = std::max( Clamp_Text_PenSize( GetPenWidth(), m_nameTextSize, false ),
2020-11-07 21:55:18 +00:00
aPlotter->RenderSettings()->GetDefaultPenWidth() );
int numPenWidth = std::max( Clamp_Text_PenSize( GetPenWidth(), m_numTextSize, false ),
2020-11-07 21:55:18 +00:00
aPlotter->RenderSettings()->GetDefaultPenWidth() );
2020-04-14 12:25:00 +00:00
int name_offset = Mils2iu( PIN_TEXT_MARGIN ) + namePenWidth;
int num_offset = Mils2iu( PIN_TEXT_MARGIN ) + numPenWidth;
2008-09-13 19:06:31 +00:00
/* Get the num and name colors */
2020-11-07 21:55:18 +00:00
COLOR4D nameColor = aPlotter->RenderSettings()->GetLayerColor( LAYER_PINNAM );
COLOR4D numColor = aPlotter->RenderSettings()->GetLayerColor( LAYER_PINNUM );
2008-09-13 19:06:31 +00:00
2020-11-07 21:55:18 +00:00
int x1 = aPinPos.x;
int y1 = aPinPos.y;
2008-09-13 19:06:31 +00:00
2020-11-07 21:55:18 +00:00
switch( aPinOrient )
2008-09-13 19:06:31 +00:00
{
case PIN_UP: y1 -= m_length; break;
case PIN_DOWN: y1 += m_length; break;
case PIN_LEFT: x1 -= m_length; break;
case PIN_RIGHT: x1 += m_length; break;
2008-09-13 19:06:31 +00:00
}
/* Draw the text inside, but the pin numbers outside. */
2020-11-07 21:55:18 +00:00
if( aTextInside )
2008-09-13 19:06:31 +00:00
{
2020-11-07 21:55:18 +00:00
if( ( aPinOrient == PIN_LEFT) || ( aPinOrient == PIN_RIGHT) ) /* Its an horizontal line. */
{
2020-11-07 21:55:18 +00:00
if( aDrawPinName )
2008-09-13 19:06:31 +00:00
{
2021-01-31 19:54:48 +00:00
EDA_TEXT_HJUSTIFY_T hjustify;
2020-11-07 21:55:18 +00:00
if( aPinOrient == PIN_RIGHT )
2008-09-13 19:06:31 +00:00
{
2020-11-07 21:55:18 +00:00
x = x1 + aTextInside;
2021-01-31 19:54:48 +00:00
hjustify = GR_TEXT_HJUSTIFY_LEFT;
2008-09-13 19:06:31 +00:00
}
else // orient == PIN_LEFT
{
2020-11-07 21:55:18 +00:00
x = x1 - aTextInside;
2021-01-31 19:54:48 +00:00
hjustify = GR_TEXT_HJUSTIFY_RIGHT;
}
2021-01-31 19:54:48 +00:00
aPlotter->Text( wxPoint( x, y1 ), nameColor, name, TEXT_ANGLE_HORIZ, pinNameSize,
2021-01-31 19:54:48 +00:00
hjustify, GR_TEXT_VJUSTIFY_CENTER, namePenWidth,
false, false );
2009-09-25 13:59:42 +00:00
}
2020-11-07 21:55:18 +00:00
if( aDrawPinNum )
2009-09-25 13:59:42 +00:00
{
2020-11-07 21:55:18 +00:00
aPlotter->Text( wxPoint( ( x1 + aPinPos.x) / 2, y1 - num_offset ), numColor,
number, TEXT_ANGLE_HORIZ, pinNumSize, GR_TEXT_HJUSTIFY_CENTER,
2020-11-07 21:55:18 +00:00
GR_TEXT_VJUSTIFY_BOTTOM, numPenWidth, false, false );
2008-09-13 19:06:31 +00:00
}
}
else /* Its a vertical line. */
{
2020-11-07 21:55:18 +00:00
if( aPinOrient == PIN_DOWN )
2008-09-13 19:06:31 +00:00
{
2020-11-07 21:55:18 +00:00
y = y1 + aTextInside;
2008-09-13 19:06:31 +00:00
2020-11-07 21:55:18 +00:00
if( aDrawPinName )
aPlotter->Text( wxPoint( x1, y ), nameColor, name, TEXT_ANGLE_VERT,
2020-11-07 21:55:18 +00:00
pinNameSize, GR_TEXT_HJUSTIFY_RIGHT, GR_TEXT_VJUSTIFY_CENTER,
namePenWidth, false, false );
2020-11-07 21:55:18 +00:00
if( aDrawPinNum )
2008-09-13 19:06:31 +00:00
{
2020-11-07 21:55:18 +00:00
aPlotter->Text( wxPoint( x1 - num_offset, ( y1 + aPinPos.y) / 2 ), numColor,
number, TEXT_ANGLE_VERT, pinNumSize, GR_TEXT_HJUSTIFY_CENTER,
2020-11-07 21:55:18 +00:00
GR_TEXT_VJUSTIFY_BOTTOM, numPenWidth, false, false );
}
}
else /* PIN_UP */
{
2020-11-07 21:55:18 +00:00
y = y1 - aTextInside;
2008-09-13 19:06:31 +00:00
2020-11-07 21:55:18 +00:00
if( aDrawPinName )
{
aPlotter->Text( wxPoint( x1, y ), nameColor, name, TEXT_ANGLE_VERT,
2020-11-07 21:55:18 +00:00
pinNameSize, GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_VJUSTIFY_CENTER,
namePenWidth, false, false );
}
2020-11-07 21:55:18 +00:00
if( aDrawPinNum )
{
2020-11-07 21:55:18 +00:00
aPlotter->Text( wxPoint( x1 - num_offset, ( y1 + aPinPos.y) / 2 ), numColor,
number, TEXT_ANGLE_VERT, pinNumSize, GR_TEXT_HJUSTIFY_CENTER,
2020-11-07 21:55:18 +00:00
GR_TEXT_VJUSTIFY_BOTTOM, numPenWidth, false, false );
2008-09-13 19:06:31 +00:00
}
}
}
}
else /* Draw num & text pin outside */
{
2020-11-07 21:55:18 +00:00
if(( aPinOrient == PIN_LEFT) || ( aPinOrient == PIN_RIGHT) )
2008-09-13 19:06:31 +00:00
{
/* Its an horizontal line. */
2020-11-07 21:55:18 +00:00
if( aDrawPinName )
2008-09-13 19:06:31 +00:00
{
2020-11-07 21:55:18 +00:00
x = ( x1 + aPinPos.x) / 2;
aPlotter->Text( wxPoint( x, y1 - name_offset ), nameColor, name,
2020-11-07 21:55:18 +00:00
TEXT_ANGLE_HORIZ, pinNameSize, GR_TEXT_HJUSTIFY_CENTER,
GR_TEXT_VJUSTIFY_BOTTOM, namePenWidth, false, false );
2008-09-13 19:06:31 +00:00
}
2020-11-07 21:55:18 +00:00
if( aDrawPinNum )
2008-09-13 19:06:31 +00:00
{
2020-11-07 21:55:18 +00:00
x = ( x1 + aPinPos.x ) / 2;
aPlotter->Text( wxPoint( x, y1 + num_offset ), numColor, number,
2020-11-07 21:55:18 +00:00
TEXT_ANGLE_HORIZ, pinNumSize, GR_TEXT_HJUSTIFY_CENTER,
GR_TEXT_VJUSTIFY_TOP, numPenWidth, false, false );
2008-09-13 19:06:31 +00:00
}
}
else /* Its a vertical line. */
{
2020-11-07 21:55:18 +00:00
if( aDrawPinName )
2008-09-13 19:06:31 +00:00
{
2020-11-07 21:55:18 +00:00
y = ( y1 + aPinPos.y ) / 2;
aPlotter->Text( wxPoint( x1 - name_offset, y ), nameColor, name,
2020-11-07 21:55:18 +00:00
TEXT_ANGLE_VERT, pinNameSize, GR_TEXT_HJUSTIFY_CENTER,
GR_TEXT_VJUSTIFY_BOTTOM, namePenWidth, false, false );
2008-09-13 19:06:31 +00:00
}
2020-11-07 21:55:18 +00:00
if( aDrawPinNum )
2008-09-13 19:06:31 +00:00
{
2020-11-07 21:55:18 +00:00
aPlotter->Text( wxPoint( x1 + num_offset, ( y1 + aPinPos.y ) / 2 ), numColor,
number, TEXT_ANGLE_VERT, pinNumSize, GR_TEXT_HJUSTIFY_CENTER,
2020-11-07 21:55:18 +00:00
GR_TEXT_VJUSTIFY_TOP, numPenWidth, false, false );
2008-09-13 19:06:31 +00:00
}
}
}
}
2008-09-14 04:27:22 +00:00
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
int LIB_PIN::PinDrawOrient( const TRANSFORM& aTransform ) const
2008-09-14 04:27:22 +00:00
{
int orient;
wxPoint end; // position of pin end starting at 0,0 according to its orientation, length = 1
2008-09-14 04:27:22 +00:00
switch( m_orientation )
2008-09-14 04:27:22 +00:00
{
case PIN_UP: end.y = 1; break;
case PIN_DOWN: end.y = -1; break;
case PIN_LEFT: end.x = -1; break;
case PIN_RIGHT: end.x = 1; break;
2008-09-14 04:27:22 +00:00
}
// = pos of end point, according to the symbol orientation.
2011-04-18 20:22:17 +00:00
end = aTransform.TransformCoordinate( end );
2008-09-14 04:27:22 +00:00
orient = PIN_UP;
if( end.x == 0 )
2008-09-14 04:27:22 +00:00
{
if( end.y > 0 )
2008-09-14 04:27:22 +00:00
orient = PIN_DOWN;
}
else
{
orient = PIN_RIGHT;
if( end.x < 0 )
2008-09-14 04:27:22 +00:00
orient = PIN_LEFT;
}
return orient;
}
EDA_ITEM* LIB_PIN::Clone() const
2008-09-14 04:27:22 +00:00
{
return new LIB_PIN( *this );
2008-09-14 04:27:22 +00:00
}
int LIB_PIN::compare( const LIB_ITEM& aOther, LIB_ITEM::COMPARE_FLAGS aCompareFlags ) const
{
wxASSERT( aOther.Type() == LIB_PIN_T );
int retv = LIB_ITEM::compare( aOther, aCompareFlags );
if( retv )
return retv;
const LIB_PIN* tmp = (LIB_PIN*) &aOther;
// When comparing units, we do not compare the part numbers. If everything else is
// identical, then we can just renumber the parts for the inherited symbol.
if( !( aCompareFlags & COMPARE_FLAGS::UNIT ) && m_number != tmp->m_number )
return m_number.Cmp( tmp->m_number );
int result = m_name.CmpNoCase( tmp->m_name );
if( result )
return result;
if( m_position.x != tmp->m_position.x )
return m_position.x - tmp->m_position.x;
if( m_position.y != tmp->m_position.y )
return m_position.y - tmp->m_position.y;
if( m_length != tmp->m_length )
return m_length - tmp->m_length;
if( m_orientation != tmp->m_orientation )
return m_orientation - tmp->m_orientation;
if( m_shape != tmp->m_shape )
return static_cast<int>( m_shape ) - static_cast<int>( tmp->m_shape );
if( m_type != tmp->m_type )
return static_cast<int>( m_type ) - static_cast<int>( tmp->m_type );
if( m_attributes != tmp->m_attributes )
return m_attributes - tmp->m_attributes;
if( m_numTextSize != tmp->m_numTextSize )
return m_numTextSize - tmp->m_numTextSize;
if( m_nameTextSize != tmp->m_nameTextSize )
return m_nameTextSize - tmp->m_nameTextSize;
if( m_alternates.size() != tmp->m_alternates.size() )
return m_alternates.size() - tmp->m_alternates.size();
auto lhsItem = m_alternates.begin();
auto rhsItem = tmp->m_alternates.begin();
while( lhsItem != m_alternates.end() )
{
const ALT& lhsAlt = lhsItem->second;
const ALT& rhsAlt = rhsItem->second;
retv = lhsAlt.m_Name.Cmp( rhsAlt.m_Name );
if( retv )
return retv;
if( lhsAlt.m_Type != rhsAlt.m_Type )
return static_cast<int>( lhsAlt.m_Type ) - static_cast<int>( rhsAlt.m_Type );
if( lhsAlt.m_Shape != rhsAlt.m_Shape )
return static_cast<int>( lhsAlt.m_Shape ) - static_cast<int>( rhsAlt.m_Shape );
++lhsItem;
++rhsItem;
}
return 0;
}
void LIB_PIN::Offset( const wxPoint& aOffset )
{
m_position += aOffset;
}
2020-11-07 21:55:18 +00:00
void LIB_PIN::MoveTo( const wxPoint& aNewPosition )
{
2020-11-07 21:55:18 +00:00
if( m_position != aNewPosition )
{
2020-11-07 21:55:18 +00:00
m_position = aNewPosition;
SetModified();
}
}
2020-11-07 21:55:18 +00:00
void LIB_PIN::MirrorHorizontal( const wxPoint& aCenter )
{
2020-11-07 21:55:18 +00:00
m_position.x -= aCenter.x;
m_position.x *= -1;
2020-11-07 21:55:18 +00:00
m_position.x += aCenter.x;
if( m_orientation == PIN_RIGHT )
m_orientation = PIN_LEFT;
else if( m_orientation == PIN_LEFT )
m_orientation = PIN_RIGHT;
}
2020-11-07 21:55:18 +00:00
void LIB_PIN::MirrorVertical( const wxPoint& aCenter )
{
2020-11-07 21:55:18 +00:00
m_position.y -= aCenter.y;
m_position.y *= -1;
2020-11-07 21:55:18 +00:00
m_position.y += aCenter.y;
if( m_orientation == PIN_UP )
m_orientation = PIN_DOWN;
else if( m_orientation == PIN_DOWN )
m_orientation = PIN_UP;
}
2020-11-07 21:55:18 +00:00
void LIB_PIN::Rotate( const wxPoint& aCenter, bool aRotateCCW )
{
int rot_angle = aRotateCCW ? -900 : 900;
2020-11-07 21:55:18 +00:00
RotatePoint( &m_position, aCenter, rot_angle );
if( aRotateCCW )
{
switch( m_orientation )
{
case PIN_RIGHT: m_orientation = PIN_UP; break;
case PIN_UP: m_orientation = PIN_LEFT; break;
case PIN_LEFT: m_orientation = PIN_DOWN; break;
case PIN_DOWN: m_orientation = PIN_RIGHT; break;
}
}
else
{
switch( m_orientation )
{
case PIN_RIGHT: m_orientation = PIN_DOWN; break;
case PIN_UP: m_orientation = PIN_RIGHT; break;
case PIN_LEFT: m_orientation = PIN_UP; break;
case PIN_DOWN: m_orientation = PIN_LEFT; break;
}
}
}
2020-11-07 21:55:18 +00:00
void LIB_PIN::Plot( PLOTTER* aPlotter, const wxPoint& aPffset, bool aFill,
const TRANSFORM& aTransform ) const
{
if( !IsVisible() )
return;
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
int orient = PinDrawOrient( aTransform );
2020-11-07 21:55:18 +00:00
wxPoint pos = aTransform.TransformCoordinate( m_position ) + aPffset;
2020-11-07 21:55:18 +00:00
PlotSymbol( aPlotter, pos, orient );
PlotPinTexts( aPlotter, pos, orient, GetParent()->GetPinNameOffset(),
GetParent()->ShowPinNumbers(), GetParent()->ShowPinNames() );
}
void LIB_PIN::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
{
LIB_ITEM::GetMsgPanelInfo( aFrame, aList );
2021-09-28 13:28:35 +00:00
aList.emplace_back( _( "Name" ), UnescapeString( GetShownName() ) );
aList.emplace_back( _( "Number" ), GetShownNumber() );
aList.emplace_back( _( "Type" ), ElectricalPinTypeGetText( m_type ) );
aList.emplace_back( _( "Style" ), PinShapeGetText( m_shape ) );
2021-09-28 13:28:35 +00:00
aList.emplace_back( _( "Style" ), IsVisible() ? _( "Yes" ) : _( "No" ) );
// Display pin length
2021-09-28 13:28:35 +00:00
aList.emplace_back( _( "Length" ), StringFromValue( aFrame->GetUserUnits(), m_length ) );
2021-09-28 13:28:35 +00:00
int i = PinOrientationIndex( m_orientation );
aList.emplace_back( _( "Orientation" ), PinOrientationName( (unsigned) i ) );
wxPoint pinpos = GetPosition();
2021-09-28 13:28:35 +00:00
pinpos.y = -pinpos.y; // Display coords are top to bottom; lib item coords are bottom to top
2021-09-28 13:28:35 +00:00
aList.emplace_back( _( "Pos X" ), MessageTextFromValue( aFrame->GetUserUnits(), pinpos.x ) );
aList.emplace_back( _( "Pos Y" ), MessageTextFromValue( aFrame->GetUserUnits(), pinpos.y ) );
}
const EDA_RECT LIB_PIN::GetBoundingBox( bool aIncludeInvisibles, bool aPinOnly ) const
{
2011-04-18 20:22:17 +00:00
EDA_RECT bbox;
wxPoint begin;
wxPoint end;
int nameTextOffset = 0;
wxString name = GetShownName();
wxString number = GetShownNumber();
bool showName = !name.IsEmpty();
bool showNum = !number.IsEmpty();
int minsizeV = TARGET_PIN_RADIUS;
if( !aIncludeInvisibles && !IsVisible() )
showName = false;
2011-04-18 20:22:17 +00:00
2020-05-09 13:09:50 +00:00
if( GetParent() )
{
2020-05-09 13:09:50 +00:00
if( GetParent()->ShowPinNames() )
nameTextOffset = GetParent()->GetPinNameOffset();
else
showName = false;
2020-05-09 13:09:50 +00:00
if( !GetParent()->ShowPinNumbers() )
showNum = false;
}
2011-04-18 20:22:17 +00:00
if( aPinOnly )
{
showName = false;
showNum = false;
}
2011-04-18 20:22:17 +00:00
// First, calculate boundary box corners position
int numberTextLength = showNum ? m_numTextSize * number.Len() : 0;
2011-04-18 20:22:17 +00:00
// Actual text height is bigger than text size
// Dick Hollenbeck's KiROUND R&D // This provides better project control over rounding to int from double // than wxRound() did. This scheme provides better logging in Debug builds // and it provides for compile time calculation of constants. #include <stdio.h> #include <assert.h> #include <limits.h> //-----<KiROUND KIT>------------------------------------------------------------ /** * KiROUND * rounds a floating point number to an int using * "round halfway cases away from zero". * In Debug build an assert fires if will not fit into an int. */ #if defined( DEBUG ) // DEBUG: a macro to capture line and file, then calls this inline static inline int KiRound( double v, int line, const char* filename ) { v = v < 0 ? v - 0.5 : v + 0.5; if( v > INT_MAX + 0.5 ) { printf( "%s: in file %s on line %d, val: %.16g too ' > 0 ' for int\n", __FUNCTION__, filename, line, v ); } else if( v < INT_MIN - 0.5 ) { printf( "%s: in file %s on line %d, val: %.16g too ' < 0 ' for int\n", __FUNCTION__, filename, line, v ); } return int( v ); } #define KiROUND( v ) KiRound( v, __LINE__, __FILE__ ) #else // RELEASE: a macro so compile can pre-compute constants. #define KiROUND( v ) int( (v) < 0 ? (v) - 0.5 : (v) + 0.5 ) #endif //-----</KiROUND KIT>----------------------------------------------------------- // Only a macro is compile time calculated, an inline function causes a static constructor // in a situation like this. // Therefore the Release build is best done with a MACRO not an inline function. int Computed = KiROUND( 14.3 * 8 ); int main( int argc, char** argv ) { for( double d = double(INT_MAX)-1; d < double(INT_MAX)+8; d += 2.0 ) { int i = KiROUND( d ); printf( "t: %d %.16g\n", i, d ); } return 0; }
2012-04-19 06:55:45 +00:00
int numberTextHeight = showNum ? KiROUND( m_numTextSize * 1.1 ) : 0;
if( m_shape == GRAPHIC_PINSHAPE::INVERTED || m_shape == GRAPHIC_PINSHAPE::INVERTED_CLOCK )
minsizeV = std::max( TARGET_PIN_RADIUS, externalPinDecoSize( nullptr, *this ) );
2011-04-18 20:22:17 +00:00
// calculate top left corner position
// for the default pin orientation (PIN_RIGHT)
begin.y = std::max( minsizeV, numberTextHeight + Mils2iu( PIN_TEXT_MARGIN ) );
begin.x = std::min( 0, m_length - (numberTextLength / 2) );
2011-04-18 20:22:17 +00:00
// calculate bottom right corner position and adjust top left corner position
int nameTextLength = 0;
int nameTextHeight = 0;
if( showName )
{
int length = name.Len();
// TODO: exclude markup characters!
nameTextLength = ( m_nameTextSize * length ) + nameTextOffset;
// Actual text height are bigger than text size
nameTextHeight = KiROUND( m_nameTextSize * 1.1 ) + Mils2iu( PIN_TEXT_MARGIN );
}
if( nameTextOffset ) // for values > 0, pin name is inside the body
{
end.x = m_length + nameTextLength;
end.y = std::min( -minsizeV, -nameTextHeight / 2 );
}
else // if value == 0:
// pin name is outside the body, and above the pin line
// pin num is below the pin line
{
end.x = std::max( m_length, nameTextLength );
end.y = -begin.y;
begin.y = std::max( minsizeV, nameTextHeight );
}
2011-04-18 20:22:17 +00:00
// Now, calculate boundary box corners position for the actual pin orientation
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
int orient = PinDrawOrient( DefaultTransform );
/* Calculate the pin position */
switch( orient )
2011-04-18 20:22:17 +00:00
{
case PIN_UP:
// Pin is rotated and texts positions are mirrored
RotatePoint( &begin, wxPoint( 0, 0 ), -900 );
RotatePoint( &end, wxPoint( 0, 0 ), -900 );
break;
2011-04-18 20:22:17 +00:00
case PIN_DOWN:
RotatePoint( &begin, wxPoint( 0, 0 ), 900 );
RotatePoint( &end, wxPoint( 0, 0 ), 900 );
begin.x = -begin.x;
end.x = -end.x;
2011-04-18 20:22:17 +00:00
break;
case PIN_LEFT:
begin.x = -begin.x;
end.x = -end.x;
2011-04-18 20:22:17 +00:00
break;
case PIN_RIGHT:
break;
}
begin += m_position;
end += m_position;
2011-04-18 20:22:17 +00:00
bbox.SetOrigin( begin );
bbox.SetEnd( end );
2011-04-18 20:22:17 +00:00
bbox.Normalize();
2020-04-14 12:25:00 +00:00
bbox.Inflate( ( GetPenWidth() / 2 ) + 1 );
// Draw Y axis is reversed in schematic:
bbox.RevertYAxis();
2011-04-18 20:22:17 +00:00
return bbox;
}
BITMAPS LIB_PIN::GetMenuImage() const
{
return ElectricalPinTypeGetBitmap( m_type );
}
2019-12-20 14:11:39 +00:00
wxString LIB_PIN::GetSelectMenuText( EDA_UNITS aUnits ) const
{
if( !m_name.IsEmpty() )
{
return wxString::Format( _( "Pin %s [%s, %s, %s]" ),
GetShownNumber(),
UnescapeString( GetShownName() ),
GetElectricalTypeName(),
PinShapeGetText( m_shape ) );
}
else
{
return wxString::Format( _( "Pin %s [%s, %s]" ),
GetShownNumber(),
GetElectricalTypeName(),
PinShapeGetText( m_shape ) );
}
}
#if defined(DEBUG)
void LIB_PIN::Show( int nestLevel, std::ostream& os ) const
{
NestedSpace( nestLevel, os ) << '<' << GetClass().Lower().mb_str()
<< " num=\"" << m_number.mb_str()
<< '"' << "/>\n";
// NestedSpace( nestLevel, os ) << "</" << GetClass().Lower().mb_str() << ">\n";
}
#endif
void LIB_PIN::CalcEdit( const wxPoint& aPosition )
{
2019-05-08 18:56:03 +00:00
if( IsMoving() )
MoveTo( aPosition );
}