Commit 00f8994e authored by jean-pierre charras's avatar jean-pierre charras

Eeschema: Fix a (minor but annoying) bug detected by coverity which prevent...

Eeschema: Fix a (minor but annoying) bug detected by coverity which prevent Eeschema to draw components in "fast mode" (i;e. without pin texts) when they are moved, due to a draw parameter which was incorrectly used.
Move items rework: enhancements: for some items (sheets, components, bus entries) the mouse cursor is no more wrapped to the anchor. For large symbols, this is better: they are more easy to place.
There is also a change when starting a move item command: the full screen is redraw, and therefore there is no artifact due to the XOR draw mode.
Some other minor coverity fixes (uninitialized members).
parent 21013246
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2009-2011 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2004-2011 KiCad Developers, see change_log.txt for contributors.
* Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2009-2015 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2004-2015 KiCad Developers, see change_log.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
......@@ -397,7 +397,12 @@ static void DrawMovingBlockOutlines( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wx
for( unsigned ii = 0; ii < block->GetCount(); ii++ )
{
schitem = (SCH_ITEM*) block->GetItem( ii );
schitem->Draw( aPanel, aDC, block->GetMoveVector(), g_XorMode, g_GhostColor );
if( schitem->Type() == SCH_COMPONENT_T )
((SCH_COMPONENT*)schitem)->Draw( aPanel, aDC, block->GetMoveVector(),
g_XorMode, g_GhostColor, false );
else
schitem->Draw( aPanel, aDC, block->GetMoveVector(), g_XorMode, g_GhostColor );
}
}
......@@ -408,7 +413,12 @@ static void DrawMovingBlockOutlines( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wx
for( unsigned ii = 0; ii < block->GetCount(); ii++ )
{
schitem = (SCH_ITEM*) block->GetItem( ii );
schitem->Draw( aPanel, aDC, block->GetMoveVector(), g_XorMode, g_GhostColor );
if( schitem->Type() == SCH_COMPONENT_T )
((SCH_COMPONENT*)schitem)->Draw( aPanel, aDC, block->GetMoveVector(),
g_XorMode, g_GhostColor, false );
else
schitem->Draw( aPanel, aDC, block->GetMoveVector(), g_XorMode, g_GhostColor );
}
}
......
......@@ -442,7 +442,7 @@ void SCH_EDIT_FRAME::RepeatDrawItem( wxDC* DC )
( (SCH_COMPONENT*) my_clone )->SetTimeStamp( GetNewTimeStamp() );
my_clone->Move( pos );
my_clone->Draw( m_canvas, DC, wxPoint( 0, 0 ), g_XorMode );
MoveItem( my_clone, DC );
PrepareMoveItem( my_clone, DC );
}
else
{
......
......@@ -4,11 +4,11 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 1992-2012 Jean-Pierre Charras <jp.charras at wanadoo.fr
* Copyright (C) 1992-2015 Jean-Pierre Charras jp.charras at wanadoo.fr
* Copyright (C) 1992-2010 Lorenzo Marcantonio
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
*
* Copyright (C) 1992-2012 KiCad Developers, see change_log.txt for contributors.
* Copyright (C) 1992-2015 KiCad Developers, see change_log.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
......@@ -343,7 +343,15 @@ wxFileName DIALOG_PLOT_SCHEMATIC::createPlotFileName( wxTextCtrl* aOutputDirecto
wxString plotFileName = Prj().AbsolutePath( aPlotFileName + wxT(".") + aExtension);
EnsureFileDirectoryExists( &outputDir, plotFileName, aReporter );
if( !EnsureFileDirectoryExists( &outputDir, plotFileName, aReporter ) )
{
wxString msg;
msg.Printf( _( "Could not write plot files to folder \"%s\"." ),
GetChars( outputDir.GetPath() ) );
msg << wxT( "\n" );
aReporter->Report( msg );
}
wxFileName fn( plotFileName );
fn.SetPath( outputDir.GetFullPath() );
return fn;
......
......@@ -123,7 +123,7 @@ SCH_TEXT* SCH_EDIT_FRAME::CreateNewText( wxDC* aDC, int aType )
// Prepare display to move the new item
textItem->Draw( m_canvas, aDC, wxPoint( 0, 0 ), g_XorMode );
MoveItem( (SCH_ITEM*) textItem, aDC );
PrepareMoveItem( (SCH_ITEM*) textItem, aDC );
return textItem;
}
......
......@@ -56,7 +56,7 @@ void SCH_EDIT_FRAME::OnCopySchematicItemRequest( wxCommandEvent& event )
newitem->SetFlags( IS_NEW );
// Draw the new part, MoveItem() expects it to be already on screen.
newitem->Draw( m_canvas, &dc, wxPoint( 0, 0 ), g_XorMode );
MoveItem( newitem, &dc );
PrepareMoveItem( newitem, &dc );
}
break;
......@@ -69,7 +69,7 @@ void SCH_EDIT_FRAME::OnCopySchematicItemRequest( wxCommandEvent& event )
newitem->SetFlags( IS_NEW );
// Draw the new item, MoveItem() expects it to be already on screen.
newitem->Draw( m_canvas, &dc, wxPoint( 0, 0 ), g_XorMode );
MoveItem( newitem, &dc );
PrepareMoveItem( newitem, &dc );
}
break;
......
......@@ -222,7 +222,7 @@ SCH_COMPONENT* SCH_EDIT_FRAME::Load_Component( wxDC* aDC,
SetMsgPanel( items );
component->Draw( m_canvas, aDC, wxPoint( 0, 0 ), g_XorMode );
component->SetFlags( IS_NEW );
MoveItem( (SCH_ITEM*) component, aDC );
PrepareMoveItem( (SCH_ITEM*) component, aDC );
return component;
}
......
......@@ -56,7 +56,8 @@ class TreeItemData : public wxTreeItemData
{
public:
SCH_SHEET_PATH m_SheetPath;
TreeItemData( SCH_SHEET_PATH sheet ) : wxTreeItemData()
TreeItemData( SCH_SHEET_PATH& sheet ) : wxTreeItemData()
{
m_SheetPath = sheet;
}
......
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2004-2011 KiCad Developers, see change_log.txt for contributors.
* Copyright (C) 2015 Jean-Pierre Charras, jaen-pierre.charras at wanadoo.fr
* Copyright (C) 2015 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2004-2015 KiCad Developers, see change_log.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
......
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2004-2011 KiCad Developers, see change_log.txt for contributors.
* Copyright (C) 2015 Jean-Pierre Charras, jaen-pierre.charras at wanadoo.fr
* Copyright (C) 2015 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2004-2015 KiCad Developers, see change_log.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
......
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2012 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 1992-2012 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2015 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 1992-2015 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
......@@ -834,11 +835,12 @@ void LIB_PIN::drawGraphic( EDA_DRAW_PANEL* aPanel,
aColor = GetInvisibleItemColor();
}
LIB_PART* Entry = GetParent();
bool DrawPinText = true;
// aData is used here as bool: if not null, draw pin texts
//(i.e = true to draw pin texts, false to draw only the pin shape, which
// is useful to draw moving component in fast mode)
if( ( aData != NULL ) && ( (bool*) aData == false ) )
DrawPinText = false;
LIB_PART* Entry = GetParent();
bool drawPinText = aData ? true : false;
/* Calculate pin orient taking in account the component orientation. */
int orient = PinDrawOrient( aTransform );
......@@ -849,7 +851,7 @@ void LIB_PIN::drawGraphic( EDA_DRAW_PANEL* aPanel,
/* Drawing from the pin and the special symbol combination */
DrawPinSymbol( aPanel, aDC, pos1, orient, aDrawMode, aColor );
if( DrawPinText )
if( drawPinText )
{
DrawPinTexts( aPanel, aDC, pos1, orient, Entry->GetPinNameOffset(),
Entry->ShowPinNumbers(), Entry->ShowPinNames(),
......
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2004-2011 KiCad Developers, see change_log.txt for contributors.
* Copyright (C) 2015 Jean-Pierre Charras, jaen-pierre.charras at wanadoo.fr
* Copyright (C) 2015 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2004-2015 KiCad Developers, see change_log.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
......@@ -98,8 +99,21 @@ class LIB_PIN : public LIB_ITEM
///< "G6", or "12". It is stored as "12\0\0" and does not
///< depend on endian type.
int m_numTextSize;
int m_nameTextSize; /* Pin num and Pin name sizes */
int m_nameTextSize; ///< Pin num and Pin name sizes
/**
* Draw a pin, with or without the pin texts
*
* @param aPanel DrawPanel to use (can be null) mainly used for clipping purposes.
* @param aDC Device Context (can be null)
* @param aOffset Offset to draw
* @param aColor -1 to use the normal body item color, or use this color if >= 0
* @param aDrawMode GR_OR, GR_XOR, ...
* @param aData = used here as bool: if not null, draw pin texts
* (i.e = true to draw pin texts, false to draw only the pin shape, which
* is useful to draw moving component in fast mode)
* @param aTransform Transform Matrix (rotation, mirror ..)
*/
void drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset,
EDA_COLOR_T aColor, GR_DRAWMODE aDrawMode, void* aData,
const TRANSFORM& aTransform );
......
......@@ -51,6 +51,14 @@ public:
~SCH_BUS_ENTRY_BASE() { }
/**
* Virtual function IsMovableFromAnchorPoint
* Return true for items which are moved with the anchor point at mouse cursor
* and false for items moved with no reference to anchor
* @return false for a bus entry
*/
bool IsMovableFromAnchorPoint() { return false; }
wxPoint m_End() const;
/**
......
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2009 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 1992-2011 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 1992-2015 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
......@@ -327,23 +327,26 @@ int SCH_COMPONENT::GetUnitCount() const
}
void SCH_COMPONENT::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, const wxPoint& offset,
GR_DRAWMODE DrawMode, EDA_COLOR_T Color, bool DrawPinText )
void SCH_COMPONENT::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset,
GR_DRAWMODE aDrawMode, EDA_COLOR_T aColor,
bool aDrawPinText )
{
if( PART_SPTR part = m_part.lock() )
{
part->Draw( panel, DC, m_Pos + offset, m_unit, m_convert, DrawMode, Color, m_transform, DrawPinText, false );
part->Draw( aPanel, aDC, m_Pos + aOffset, m_unit, m_convert, aDrawMode, aColor,
m_transform, aDrawPinText, false );
}
else // Use dummy() part if the actual cannot be found.
{
dummy()->Draw( panel, DC, m_Pos + offset, 0, 0, DrawMode, Color, m_transform, DrawPinText, false );
dummy()->Draw( aPanel, aDC, m_Pos + aOffset, 0, 0, aDrawMode, aColor,
m_transform, aDrawPinText, false );
}
SCH_FIELD* field = GetField( REFERENCE );
if( field->IsVisible() && !field->IsMoving() )
{
field->Draw( panel, DC, offset, DrawMode );
field->Draw( aPanel, aDC, aOffset, aDrawMode );
}
for( int ii = VALUE; ii < GetFieldCount(); ii++ )
......@@ -353,26 +356,26 @@ void SCH_COMPONENT::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, const wxPoint& offset
if( field->IsMoving() )
continue;
field->Draw( panel, DC, offset, DrawMode );
field->Draw( aPanel, aDC, aOffset, aDrawMode );
}
#if 0
// Draw the component bounding box
// Only for testing purposes, draw the component bounding box
{
EDA_RECT boundingBox = GetBoundingBox();
GRRect( panel->GetClipBox(), DC, boundingBox, 0, BROWN );
GRRect( aPanel->GetClipBox(), aDC, boundingBox, 0, BROWN );
#if 1
if( GetField( REFERENCE )->IsVisible() )
{
boundingBox = GetField( REFERENCE )->GetBoundingBox();
GRRect( panel->GetClipBox(), DC, boundingBox, 0, BROWN );
GRRect( aPanel->GetClipBox(), aDC, boundingBox, 0, BROWN );
}
if( GetField( VALUE )->IsVisible() )
{
boundingBox = GetField( VALUE )->GetBoundingBox();
GRRect( panel->GetClipBox(), DC, boundingBox, 0, BROWN );
GRRect( aPanel->GetClipBox(), aDC, boundingBox, 0, BROWN );
}
#endif
}
......
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2009 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 1992-2011 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2014 Dick Hollenbeck, dick@softplc.com
* Copyright (C) 2015 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 1992-2015 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
......@@ -133,6 +135,16 @@ public:
return wxT( "SCH_COMPONENT" );
}
/**
* Virtual function IsMovableFromAnchorPoint
* Return true for items which are moved with the anchor point at mouse cursor
* and false for items moved with no reference to anchor
* Usually return true for small items (labels, junctions) and false for
* items which can be large (hierarchical sheets, compoments)
* @return false for a componant
*/
bool IsMovableFromAnchorPoint() { return false; }
void SetPartName( const wxString& aName, PART_LIBS* aLibs=NULL );
const wxString& GetPartName() const { return m_part_name; }
......@@ -287,21 +299,30 @@ public:
*/
LIB_PIN* GetPin( const wxString& number );
void Draw( EDA_DRAW_PANEL* panel,
wxDC* DC,
const wxPoint& offset,
GR_DRAWMODE draw_mode,
EDA_COLOR_T Color = UNSPECIFIED_COLOR )
/**
* Virtual function, from the base class SCH_ITEM::Draw
*/
void Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset,
GR_DRAWMODE aDrawMode, EDA_COLOR_T aColor = UNSPECIFIED_COLOR )
{
Draw( panel, DC, offset, draw_mode, Color, true );
Draw( aPanel, aDC, aOffset, aDrawMode, aColor, true );
}
void Draw( EDA_DRAW_PANEL* panel,
wxDC* DC,
const wxPoint& offset,
GR_DRAWMODE draw_mode,
EDA_COLOR_T Color,
bool DrawPinText );
/**
* Function Draw, specific to components.
* Draw a component, with or without pin texts.
* @param aPanel DrawPanel to use (can be null) mainly used for clipping purposes.
* @param aDC Device Context (can be null)
* @param aOffset drawing Offset (usually wxPoint(0,0),
* but can be different when moving an object)
* @param aDrawMode GR_OR, GR_XOR, ...
* @param aColor UNSPECIFIED_COLOR to use the normal body item color, or use this color if >= 0
* @param aDrawPinText = true to draw pin texts, false to draw only the pin shape
* usually false to draw a component when moving it, and true otherwise.
*/
void Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset,
GR_DRAWMODE aDrawMode, EDA_COLOR_T aColor,
bool aDrawPinText );
void SwapData( SCH_ITEM* aItem );
......
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2004-2011 KiCad Developers, see change_log.txt for contributors.
* Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2004-2014 KiCad Developers, see change_log.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
......@@ -114,8 +114,8 @@ int SCH_FIELD::GetPenSize() const
}
void SCH_FIELD::Draw( EDA_DRAW_PANEL* panel, wxDC* DC,
const wxPoint& offset, GR_DRAWMODE DrawMode, EDA_COLOR_T Color )
void SCH_FIELD::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset,
GR_DRAWMODE aDrawMode, EDA_COLOR_T aColor )
{
int orient;
EDA_COLOR_T color;
......@@ -131,14 +131,13 @@ void SCH_FIELD::Draw( EDA_DRAW_PANEL* panel, wxDC* DC,
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 );
GRSetDrawMode( aDC, aDrawMode );
// Calculate the text orientation according to the component orientation.
orient = m_Orient;
......@@ -163,7 +162,7 @@ void SCH_FIELD::Draw( EDA_DRAW_PANEL* panel, wxDC* DC,
* and use GetBoundaryBox to know the text coordinate considered as centered
*/
EDA_RECT boundaryBox = GetBoundingBox();
textpos = boundaryBox.Centre();
textpos = boundaryBox.Centre() + aOffset;
if( m_forceVisible )
{
......@@ -179,8 +178,8 @@ void SCH_FIELD::Draw( EDA_DRAW_PANEL* panel, wxDC* DC,
color = GetLayerColor( LAYER_FIELDS );
}
EDA_RECT* clipbox = panel? panel->GetClipBox() : NULL;
DrawGraphicText( clipbox, DC, textpos, color, GetFullyQualifiedText(), orient, m_Size,
EDA_RECT* clipbox = aPanel ? aPanel->GetClipBox() : NULL;
DrawGraphicText( clipbox, aDC, textpos, color, GetFullyQualifiedText(), orient, m_Size,
GR_TEXT_HJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_CENTER,
LineWidth, m_Italic, m_Bold );
......@@ -191,7 +190,7 @@ void SCH_FIELD::Draw( EDA_DRAW_PANEL* panel, wxDC* DC,
textpos = m_Pos - origin;
textpos = parentComponent->GetScreenCoord( textpos );
textpos += parentComponent->GetPosition();
GRLine( clipbox, DC, origin, textpos, 2, DARKGRAY );
GRLine( clipbox, aDC, origin, textpos, 2, DARKGRAY );
}
/* Enable this to draw the bounding box around the text field to validate
......@@ -200,7 +199,7 @@ void SCH_FIELD::Draw( EDA_DRAW_PANEL* panel, wxDC* DC,
#if 0
// Draw boundary box:
GRRect( panel->GetClipBox(), DC, boundaryBox, 0, BROWN );
GRRect( aPanel->GetClipBox(), aDC, boundaryBox, 0, BROWN );
// Draw the text anchor point
......@@ -210,9 +209,9 @@ void SCH_FIELD::Draw( EDA_DRAW_PANEL* panel, wxDC* DC,
textpos = parentComponent->GetScreenCoord( textpos );
textpos += parentComponent->GetPosition();
const int len = 10;
GRLine( clipbox, DC,
GRLine( clipbox, aDC,
textpos.x - len, textpos.y, textpos.x + len, textpos.y, 0, BLUE );
GRLine( clipbox, DC,
GRLine( clipbox, aDC,
textpos.x, textpos.y - len, textpos.x, textpos.y + len, 0, BLUE );
#endif
}
......
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2012 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2004-2012 KiCad Developers, see change_log.txt for contributors.
* Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2004-2015 KiCad Developers, see change_log.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
......@@ -134,11 +134,8 @@ public:
return (m_Attributs & TEXT_NO_VISIBLE) == 0 ? true : false;
}
void Draw( EDA_DRAW_PANEL* aPanel,
wxDC* aDC,
const wxPoint& aOffset,
GR_DRAWMODE aDrawMode,
EDA_COLOR_T aColor = UNSPECIFIED_COLOR );
void Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset,
GR_DRAWMODE aDrawMode, EDA_COLOR_T aColor = UNSPECIFIED_COLOR );
bool Save( FILE* aFile ) const;
......
......@@ -117,6 +117,8 @@ class SCH_ITEM : public EDA_ITEM
protected:
LAYERSCH_ID m_Layer;
EDA_ITEMS m_connections; ///< List of items connected to this item.
wxPoint m_storedPos; ///< a temporary variable used in some move commands
///> to store a initial pos (of the item or mouse cursor)
public:
SCH_ITEM( EDA_ITEM* aParent, KICAD_T aType );
......@@ -141,6 +143,19 @@ public:
SCH_ITEM* Next() const { return static_cast<SCH_ITEM*>( Pnext ); }
SCH_ITEM* Back() const { return static_cast<SCH_ITEM*>( Pback ); }
/**
* Virtual function IsMovableFromAnchorPoint
* @return true for items which are moved with the anchor point at mouse cursor
* and false for items moved with no reference to anchor
* Usually return true for small items (labels, junctions) and false for
* items which can be large (hierarchical sheets, compoments)
*/
virtual bool IsMovableFromAnchorPoint() { return true; }
wxPoint& GetStoredPos() { return m_storedPos; }
void SetStoredPos( wxPoint aPos ) { m_storedPos = aPos; }
/**
* Function GetLayer
* returns the layer this item is on.
......@@ -162,12 +177,17 @@ public:
/**
* Function Draw
* Draw a schematic item. Each schematic item should have its own method
* @param aPanel DrawPanel to use (can be null) mainly used for clipping purposes.
* @param aDC Device Context (can be null)
* @param aOffset drawing Offset (usually wxPoint(0,0),
* but can be different when moving an object)
* @param aDrawMode GR_OR, GR_XOR, ...
* @param aColor UNSPECIFIED_COLOR to use the normal body item color,
* or force this color if it is a valid color
*/
virtual void Draw( EDA_DRAW_PANEL* aPanel,
wxDC* aDC,
const wxPoint& aOffset,
GR_DRAWMODE aDrawMode,
EDA_COLOR_T aColor = UNSPECIFIED_COLOR ) = 0;
virtual void Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset,
GR_DRAWMODE aDrawMode, EDA_COLOR_T aColor = UNSPECIFIED_COLOR ) = 0;
/**
* Function Move
......
......@@ -887,6 +887,14 @@ void SCH_SHEET::MirrorY( int aYaxis_position )
}
}
void SCH_SHEET::SetPosition( const wxPoint& aPosition )
{
// Remember the sheet and all pin sheet positions must be
// modified. So use Move function to do that.
Move( aPosition - m_pos );
}
void SCH_SHEET::Resize( const wxSize& aSize )
{
......
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2009 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 1992-2011 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 1992-2015 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
......@@ -95,11 +95,16 @@ public:
bool operator ==( const SCH_SHEET_PIN* aPin ) const;
void Draw( EDA_DRAW_PANEL* aPanel,
wxDC* aDC,
const wxPoint& aOffset,
GR_DRAWMODE aDraw_mode,
EDA_COLOR_T aColor = UNSPECIFIED_COLOR );
/**
* Virtual function IsMovableFromAnchorPoint
* Return true for items which are moved with the anchor point at mouse cursor
* and false for items moved with no reference to anchor
* @return false for a hierarchical sheet pin
*/
bool IsMovableFromAnchorPoint() { return false; }
void Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset,
GR_DRAWMODE aDrawMode, EDA_COLOR_T aColor = UNSPECIFIED_COLOR );
/**
* Function CreateGraphicShape (virtual)
......@@ -247,6 +252,15 @@ public:
return wxT( "SCH_SHEET" );
}
/**
* Virtual function IsMovableFromAnchorPoint
* Return true for items which are moved with the anchor point at mouse cursor
* and false for items moved with no reference to anchor
* Usually return true for small items (labels, junctions) and false for
* items which can be large (hierarchical sheets, compoments)
* @return false for a hierarchical sheet
*/
bool IsMovableFromAnchorPoint() { return false; }
wxString GetName() const { return m_name; }
......@@ -392,11 +406,8 @@ public:
int GetPenSize() const;
void Draw( EDA_DRAW_PANEL* aPanel,
wxDC* aDC,
const wxPoint& aOffset,
GR_DRAWMODE aDrawMode,
EDA_COLOR_T aColor = UNSPECIFIED_COLOR );
void Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset,
GR_DRAWMODE aDrawMode, EDA_COLOR_T aColor = UNSPECIFIED_COLOR );
EDA_RECT const GetBoundingBox() const;
......@@ -549,7 +560,7 @@ public:
wxPoint GetPosition() const { return m_pos; }
void SetPosition( const wxPoint& aPosition ) { m_pos = aPosition; }
void SetPosition( const wxPoint& aPosition );
bool HitTest( const wxPoint& aPosition, int aAccuracy ) const;
......
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2009 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 1992-2011 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 1992-2015 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
......@@ -131,11 +131,8 @@ public:
*/
virtual wxPoint GetSchematicTextOffset() const;
virtual void Draw( EDA_DRAW_PANEL* panel,
wxDC* DC,
const wxPoint& offset,
GR_DRAWMODE draw_mode,
EDA_COLOR_T Color = UNSPECIFIED_COLOR );
virtual void Draw( EDA_DRAW_PANEL* panel, wxDC* DC, const wxPoint& offset,
GR_DRAWMODE draw_mode, EDA_COLOR_T Color = UNSPECIFIED_COLOR );
/**
* Function CreateGraphicShape
......@@ -230,11 +227,8 @@ public:
~SCH_LABEL() { }
void Draw( EDA_DRAW_PANEL* panel,
wxDC* DC,
const wxPoint& offset,
GR_DRAWMODE draw_mode,
EDA_COLOR_T Color = UNSPECIFIED_COLOR );
void Draw( EDA_DRAW_PANEL* panel, wxDC* DC, const wxPoint& offset,
GR_DRAWMODE draw_mode, EDA_COLOR_T Color = UNSPECIFIED_COLOR );
wxString GetClass() const
{
......@@ -279,11 +273,8 @@ public:
~SCH_GLOBALLABEL() { }
void Draw( EDA_DRAW_PANEL* panel,
wxDC* DC,
const wxPoint& offset,
GR_DRAWMODE draw_mode,
EDA_COLOR_T Color = UNSPECIFIED_COLOR );
void Draw( EDA_DRAW_PANEL* panel, wxDC* DC, const wxPoint& offset,
GR_DRAWMODE draw_mode, EDA_COLOR_T Color = UNSPECIFIED_COLOR );
wxString GetClass() const
{
......@@ -332,11 +323,8 @@ public:
~SCH_HIERLABEL() { }
void Draw( EDA_DRAW_PANEL* panel,
wxDC* DC,
const wxPoint& offset,
GR_DRAWMODE draw_mode,
EDA_COLOR_T Color = UNSPECIFIED_COLOR );
void Draw( EDA_DRAW_PANEL* panel, wxDC* DC, const wxPoint& offset,
GR_DRAWMODE draw_mode, EDA_COLOR_T Color = UNSPECIFIED_COLOR );
wxString GetClass() const
{
......
......@@ -443,21 +443,26 @@ void SCH_EDIT_FRAME::OnMoveItem( wxCommandEvent& aEvent )
case SCH_COMPONENT_T:
case SCH_SHEET_PIN_T:
case SCH_FIELD_T:
MoveItem( item, &dc );
case SCH_SHEET_T:
PrepareMoveItem( item, &dc );
break;
case SCH_BITMAP_T:
// move an image is a special case:
// we cannot undraw/redraw a bitmap just using our xor mode
// the MoveImage function handle this undraw/redraw difficulty
// By redrawing the full bounding box
MoveImage( (SCH_BITMAP*) item, &dc );
break;
case SCH_SHEET_T:
StartMoveSheet( (SCH_SHEET*) item, &dc );
break;
case SCH_MARKER_T:
default:
// Moving a marker has no sense
wxFAIL_MSG( wxString::Format( wxT( "Cannot move item type %s" ),
GetChars( item->GetClass() ) ) );
default:
// Unknown items cannot be moved
wxFAIL_MSG( wxString::Format(
wxT( "Cannot move unknown item type %d" ), item->Type() ) );
break;
}
......@@ -640,25 +645,44 @@ bool SCH_EDIT_FRAME::DeleteItemAtCrossHair( wxDC* DC )
return false;
}
static void moveItem( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition, bool aErase )
// This function is a callback function, called by the mouse cursor movin event
// when an item is currently moved
static void moveItemWithMouseCursor( EDA_DRAW_PANEL* aPanel, wxDC* aDC,
const wxPoint& aPosition, bool aErase )
{
SCH_SCREEN* screen = (SCH_SCREEN*) aPanel->GetScreen();
SCH_ITEM* item = screen->GetCurItem();
wxCHECK_RET( (item != NULL), wxT( "Cannot move invalid schematic item." ) );
SCH_COMPONENT* cmp = NULL;
if( item->Type() == SCH_COMPONENT_T )
cmp = static_cast< SCH_COMPONENT* >( item );
#ifndef USE_WX_OVERLAY
// Erase the current item at its current position.
if( aErase )
item->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode );
{
if( cmp ) // Use fast mode (do not draw pin texts)
cmp->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode, UNSPECIFIED_COLOR, false );
else
item->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode );
}
#endif
item->SetPosition( aPanel->GetParent()->GetCrossHairPosition() );
wxPoint cpos = aPanel->GetParent()->GetCrossHairPosition();
cpos -= item->GetStoredPos();
item->SetPosition( cpos );
// Draw the item item at it's new position.
item->SetWireImage(); // While moving, the item may choose to render differently
item->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode );
if( cmp ) // Use fast mode (do not draw pin texts)
cmp->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode, UNSPECIFIED_COLOR, false );
else
item->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode );
}
......@@ -714,7 +738,7 @@ static void abortMoveItem( EDA_DRAW_PANEL* aPanel, wxDC* aDC )
}
void SCH_EDIT_FRAME::MoveItem( SCH_ITEM* aItem, wxDC* aDC )
void SCH_EDIT_FRAME::PrepareMoveItem( SCH_ITEM* aItem, wxDC* aDC )
{
wxCHECK_RET( aItem != NULL, wxT( "Cannot move invalid schematic item" ) );
......@@ -729,22 +753,27 @@ void SCH_EDIT_FRAME::MoveItem( SCH_ITEM* aItem, wxDC* aDC )
}
aItem->SetFlags( IS_MOVED );
#ifdef USE_WX_OVERLAY
this->Refresh();
this->Update();
#endif
m_canvas->CrossHairOff( aDC );
if( aItem->Type() != SCH_SHEET_PIN_T )
// For some items, moving the cursor to anchor is not good
// (for instance large hierarchical sheets od componants can have
// the anchor position outside the canvas)
// these items return IsMovableFromAnchorPoint() == false
// For these items, do not wrap the cursor
if( aItem->IsMovableFromAnchorPoint() )
{
SetCrossHairPosition( aItem->GetPosition() );
m_canvas->MoveCursorToCrossHair();
aItem->SetStoredPos( wxPoint( 0,0 ) );
}
else
aItem->SetStoredPos( GetCrossHairPosition() - aItem->GetPosition() );
m_canvas->MoveCursorToCrossHair();
OnModify();
m_canvas->SetMouseCapture( moveItem, abortMoveItem );
m_canvas->SetMouseCapture( moveItemWithMouseCursor, abortMoveItem );
GetScreen()->SetCurItem( aItem );
moveItem( m_canvas, aDC, wxDefaultPosition, true );
m_canvas->CrossHairOn( aDC );
m_canvas->Refresh();
}
......
......@@ -846,13 +846,13 @@ private:
SCH_JUNCTION* AddJunction( wxDC* aDC, const wxPoint& aPosition, bool aPutInUndoList = false );
/**
* Function MoveItem
* Function PrepareMoveItem
* start moving \a aItem using the mouse.
*
* @param aItem A pointer to an SCH_ITEM to move.
* @param aDC The device context to draw \a aItem.
*/
void MoveItem( SCH_ITEM* aItem, wxDC* aDC );
void PrepareMoveItem( SCH_ITEM* aItem, wxDC* aDC );
// Text, label, glabel
SCH_TEXT* CreateNewText( wxDC* aDC, int aType );
......@@ -947,8 +947,6 @@ public:
wxPoint GetLastSheetPinPosition() const { return m_lastSheetPinPosition; }
private:
void StartMoveSheet( SCH_SHEET* sheet, wxDC* DC );
/**
* Function CreateSheetPin
* creates a new SCH_SHEET_PIN object and add it to \a aSheet at the current cursor position.
......
......@@ -251,9 +251,11 @@ bool SCH_EDIT_FRAME::EditSheet( SCH_SHEET* aSheet, wxDC* aDC )
/* Move selected sheet with the cursor.
* Callback function use by m_mouseCaptureCallback.
* Callback function used by m_mouseCaptureCallback.
* Note also now this function is aclled only when resizing the sheet
* But the (very small code) relative to sheet move is still present here
*/
static void MoveOrResizeSheet( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition,
static void resizeSheetWithMouseCursor( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition,
bool aErase )
{
wxPoint moveVector;
......@@ -265,37 +267,29 @@ static void MoveOrResizeSheet( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint&
wxPoint pos = sheet->GetPosition();
if( sheet->IsResized() )
{
int width = aPanel->GetParent()->GetCrossHairPosition().x - sheet->GetPosition().x;
int height = aPanel->GetParent()->GetCrossHairPosition().y - sheet->GetPosition().y;
int width = aPanel->GetParent()->GetCrossHairPosition().x - sheet->GetPosition().x;
int height = aPanel->GetParent()->GetCrossHairPosition().y - sheet->GetPosition().y;
// If the sheet doesn't have any pins, clamp the minimum size to the default values.
width = ( width < MIN_SHEET_WIDTH ) ? MIN_SHEET_WIDTH : width;
height = ( height < MIN_SHEET_HEIGHT ) ? MIN_SHEET_HEIGHT : height;
// If the sheet doesn't have any pins, clamp the minimum size to the default values.
width = ( width < MIN_SHEET_WIDTH ) ? MIN_SHEET_WIDTH : width;
height = ( height < MIN_SHEET_HEIGHT ) ? MIN_SHEET_HEIGHT : height;
if( sheet->HasPins() )
{
int gridSizeX = KiROUND( screen->GetGridSize().x );
int gridSizeY = KiROUND( screen->GetGridSize().y );
// If the sheet has pins, use the pin positions to clamp the minimum height.
height = ( height < sheet->GetMinHeight() + gridSizeY ) ?
sheet->GetMinHeight() + gridSizeY : height;
width = ( width < sheet->GetMinWidth() + gridSizeX ) ?
sheet->GetMinWidth() + gridSizeX : width;
}
wxPoint grid = aPanel->GetParent()->GetNearestGridPosition(
wxPoint( pos.x + width, pos.y + height ) );
sheet->Resize( wxSize( grid.x - pos.x, grid.y - pos.y ) );
}
else if( sheet->IsMoving() )
if( sheet->HasPins() )
{
moveVector = aPanel->GetParent()->GetCrossHairPosition() - pos;
sheet->Move( moveVector );
int gridSizeX = KiROUND( screen->GetGridSize().x );
int gridSizeY = KiROUND( screen->GetGridSize().y );
// If the sheet has pins, use the pin positions to clamp the minimum height.
height = ( height < sheet->GetMinHeight() + gridSizeY ) ?
sheet->GetMinHeight() + gridSizeY : height;
width = ( width < sheet->GetMinWidth() + gridSizeX ) ?
sheet->GetMinWidth() + gridSizeX : width;
}
wxPoint grid = aPanel->GetParent()->GetNearestGridPosition(
wxPoint( pos.x + width, pos.y + height ) );
sheet->Resize( wxSize( grid.x - pos.x, grid.y - pos.y ) );
sheet->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode );
}
......@@ -360,7 +354,7 @@ SCH_SHEET* SCH_EDIT_FRAME::CreateSheet( wxDC* aDC )
// also need to update the hierarchy, if we are adding
// a sheet to a screen that already has multiple instances (!)
GetScreen()->SetCurItem( sheet );
m_canvas->SetMouseCapture( MoveOrResizeSheet, ExitSheet );
m_canvas->SetMouseCapture( resizeSheetWithMouseCursor, ExitSheet );
m_canvas->CallMouseCapture( aDC, wxDefaultPosition, false );
m_canvas->CrossHairOff( aDC );
......@@ -390,28 +384,10 @@ void SCH_EDIT_FRAME::ReSizeSheet( SCH_SHEET* aSheet, wxDC* aDC )
SetUndoItem( aSheet );
aSheet->SetFlags( IS_RESIZED );
m_canvas->SetMouseCapture( MoveOrResizeSheet, ExitSheet );
m_canvas->SetMouseCapture( resizeSheetWithMouseCursor, ExitSheet );
m_canvas->CallMouseCapture( aDC, wxDefaultPosition, true );
if( aSheet->IsNew() ) // not already in edit, save a copy for undo/redo
SetUndoItem( aSheet );
}
void SCH_EDIT_FRAME::StartMoveSheet( SCH_SHEET* aSheet, wxDC* aDC )
{
if( ( aSheet == NULL ) || ( aSheet->Type() != SCH_SHEET_T ) )
return;
m_canvas->CrossHairOff( aDC );
SetCrossHairPosition( aSheet->GetPosition() );
m_canvas->MoveCursorToCrossHair();
if( !aSheet->IsNew() )
SetUndoItem( aSheet );
aSheet->SetFlags( IS_MOVED );
m_canvas->SetMouseCapture( MoveOrResizeSheet, ExitSheet );
m_canvas->CallMouseCapture( aDC, wxDefaultPosition, true );
m_canvas->CrossHairOn( aDC );
}
......@@ -128,7 +128,7 @@ SCH_SHEET_PIN* SCH_EDIT_FRAME::CreateSheetPin( SCH_SHEET* aSheet, wxDC* aDC )
sheetPin->SetPosition( GetCrossHairPosition() );
sheetPin->Draw( m_canvas, aDC, wxPoint( 0, 0 ), g_XorMode );
MoveItem( (SCH_ITEM*) sheetPin, aDC );
PrepareMoveItem( (SCH_ITEM*) sheetPin, aDC );
OnModify();
return sheetPin;
......@@ -174,7 +174,7 @@ SCH_SHEET_PIN* SCH_EDIT_FRAME::ImportSheetPin( SCH_SHEET* aSheet, wxDC* aDC )
sheetPin->SetPosition( GetCrossHairPosition() );
sheetPin->Draw( m_canvas, aDC, wxPoint( 0, 0 ), g_XorMode );
MoveItem( (SCH_ITEM*) sheetPin, aDC );
PrepareMoveItem( (SCH_ITEM*) sheetPin, aDC );
return sheetPin;
}
bom_?.py are some python scripts which read a generic xml netlist from eeschema,
and create a bom.
All examples use ky_netlist_reader.py, which is a python utility to read
All examples use kicad_netlist_reader.py, which is a python utility to read
and parse this generic xml netlist and create the corresponding data
used to build the bom.
......
......@@ -3,11 +3,12 @@
#
"""
@package
Generate a csv list file.
Components are sorted by ref and grouped by value
Generate a BOM list file.
Components are sorted by ref
One component per line
Fields are (if exist)
Ref, Quantity, value, Part, footprint, 'Description', 'Vendor'
Fields are separated by tabs
"""
from __future__ import print_function
......@@ -38,7 +39,8 @@ out = csv.writer(f, lineterminator='\n', delimiter='\t', quoting=csv.QUOTE_NONE)
def writerow( acsvwriter, columns ):
utf8row = []
for col in columns:
utf8row.append( str(col).encode('utf8') )
txt=str(col);
utf8row.append( txt.encode('utf-8') )
acsvwriter.writerow( utf8row )
components = net.getInterestingComponents()
......
......@@ -7,7 +7,7 @@
"""
@package
Generate a csv list file.
Components are sorted by ref and grouped by value
Components are sorted by ref
One component per line
Fields are (if exist)
Ref, value, Part, footprint, Datasheet, Manufacturer, Vendor
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment