Commit fc0864be authored by Wayne Stambaugh's avatar Wayne Stambaugh

Schematic component library object code cleaning and refactoring.

* Break classes_body_item.cpp(.h) into more reasonable size bites.
* Rename classes_body_item.cpp(.h) to lib_draw_item.cpp(.h)
* Fix some unsatisfied header file dependencies.
* Add stubs to component library draw item base classe to handle editing
  internally.
* Lots of code cleaning.
parent 443534e7
......@@ -154,7 +154,7 @@ void ArmBoolEng( Bool_Engine* aBooleng, bool aConvertHoles )
* Another scaling with Grid is applied on top of it to create space in the integer number for
* even smaller numbers.
*/
int GRID = (int) 10000 / DGRID; // initial value = 10000 in kbool example
int GRID = (int) ( 10000 / DGRID ); // initial value = 10000 in kbool example
// But we use 10000/DGRID because the scalling is made
// by DGRID on integer pcbnew units and
......
......@@ -30,7 +30,6 @@ set(EESCHEMA_SRCS
class_schematic_items.cpp
class_sch_screen.cpp
class_text-label.cpp
classes_body_items.cpp
cleanup.cpp
cmp_library_keywords.cpp
cmp_library_lexer.cpp
......@@ -97,7 +96,13 @@ set(EESCHEMA_SRCS
libedit_onrightclick.cpp
libedit_plot_component.cpp
libedit_undo_redo.cpp
lib_arc.cpp
lib_bezier.cpp
lib_circle.cpp
lib_draw_item.cpp
lib_export.cpp
lib_polyline.cpp
lib_rectangle.cpp
libfield.cpp
load_one_schematic_file.cpp
locate.cpp
......
......@@ -9,7 +9,7 @@
#include "confirm.h"
#include "program.h"
#include "classes_body_items.h"
#include "lib_draw_item.h"
#include "class_pin.h"
#include "general.h"
#include "protos.h"
......
......@@ -16,7 +16,7 @@
#include "trigo.h"
#include "program.h"
#include "classes_body_items.h"
#include "lib_draw_item.h"
#include "general.h"
#include "protos.h"
......
......@@ -5,7 +5,6 @@
#include "fctsys.h"
#include "common.h"
#include "kicad_string.h"
#include "confirm.h"
#include "class_drawpanel.h"
#include "plot_common.h"
#include "gr_basic.h"
......@@ -16,6 +15,11 @@
#include "class_library.h"
#include "class_libentry.h"
#include "class_pin.h"
#include "lib_arc.h"
#include "lib_bezier.h"
#include "lib_circle.h"
#include "lib_polyline.h"
#include "lib_rectangle.h"
#include <boost/foreach.hpp>
......@@ -986,8 +990,7 @@ EDA_Rect LIB_COMPONENT::GetBoundaryBox( int aUnit, int aConvert )
if( item.m_Convert > 0 && ( ( aConvert > 0 ) && ( aConvert != item.m_Convert ) ) )
continue;
if ( ( item.Type() == COMPONENT_FIELD_DRAW_TYPE )
&& !( ( LIB_FIELD& ) item ).IsVisible() )
if ( ( item.Type() == COMPONENT_FIELD_DRAW_TYPE ) && !( ( LIB_FIELD& ) item ).IsVisible() )
continue;
bBox.Merge( item.GetBoundingBox() );
......@@ -1198,8 +1201,7 @@ void LIB_COMPONENT::ClearStatus()
}
int LIB_COMPONENT::SelectItems( EDA_Rect& aRect, int aUnit, int aConvert,
bool aEditPinByPin )
int LIB_COMPONENT::SelectItems( EDA_Rect& aRect, int aUnit, int aConvert, bool aEditPinByPin )
{
int itemCount = 0;
......
......@@ -5,7 +5,7 @@
#ifndef CLASS_LIBENTRY_H
#define CLASS_LIBENTRY_H
#include "classes_body_items.h"
#include "lib_draw_item.h"
#include "class_libentry_fields.h"
#include <map>
......
......@@ -6,7 +6,7 @@
#define CLASS_LIBENTRY_FIELDS_H
#include "program.h"
#include "classes_body_items.h"
#include "lib_draw_item.h"
/**
......
......@@ -7,7 +7,7 @@
#ifndef CLASS_PIN_H
#define CLASS_PIN_H
#include "classes_body_items.h"
#include "lib_draw_item.h"
#define TARGET_PIN_DIAM 12 /* Circle diameter drawn at the active end of
* pins */
......
......@@ -15,6 +15,7 @@
#include "protos.h"
#include "class_library.h"
#include "dialog_schematic_find.h"
#include "lib_rectangle.h"
#include <wx/tokenzr.h>
......
This diff is collapsed.
......@@ -14,7 +14,7 @@
#include "protos.h"
#include "libeditframe.h"
#include "viewlib_frame.h"
#include "classes_body_items.h"
#include "lib_draw_item.h"
#include "class_pin.h"
#include "class_marker_sch.h"
......
......@@ -11,7 +11,7 @@
#include "general.h"
#include "eeschema_id.h"
#include "protos.h"
#include "classes_body_items.h"
#include "lib_draw_item.h"
#include "class_pin.h"
......
......@@ -5,6 +5,16 @@
#ifndef _GENERAL_H_
#define _GENERAL_H_
#include <wx/string.h>
#include <wx/gdicmn.h>
#include "block_commande.h"
#include "program.h"
class SCH_ITEM;
class SCH_SHEET;
#define EESCHEMA_VERSION 2
......
This diff is collapsed.
/**************************/
/* Graphic Body Item: Arc */
/**************************/
#ifndef _LIB_ARC_H_
#define _LIB_ARC_H_
#include "lib_draw_item.h"
class LIB_ARC : public LIB_DRAW_ITEM
{
public:
int m_Radius;
int m_t1; /* First radius angle of the arc in 0.1 degrees. */
int m_t2; /* Second radius angle of the arc in 0.1 degrees. */
wxPoint m_ArcStart;
wxPoint m_ArcEnd; /* Arc end position. */
wxPoint m_Pos; /* Radius center point. */
int m_Width; /* Line width */
public:
LIB_ARC(LIB_COMPONENT * aParent);
LIB_ARC( const LIB_ARC& aArc );
~LIB_ARC() { }
virtual wxString GetClass() const
{
return wxT( "LIB_ARC" );
}
/**
* Save arc object to a FILE in "*.lib" format.
*
* @param aFile The FILE to write to.
* @return - True if success writing else false.
*/
virtual bool Save( FILE* aFile );
virtual bool Load( char* aLine, wxString& aErrorMsg );
/**
* Tests if the given wxPoint is within the bounds of this object.
*
* @param aRefPos - Coordinates to test
* @return - True if a hit, else false
*/
virtual bool HitTest( const wxPoint& aRefPos );
/**
* @param aPosRef - a wxPoint to test
* @param aThreshold - max distance to this object (usually the half
* thickness of a line)
* @param aTransMat - the transform matrix
* @return - True if the point aPosRef is near this object
*/
virtual bool HitTest( wxPoint aPosRef, int aThreshold, const int aTransMat[2][2] );
void Draw( WinEDA_DrawPanel * aPanel, wxDC * aDC, const wxPoint &aOffset,
int aColor, int aDrawMode, void* aData,
const int aTransformMatrix[2][2] );
virtual EDA_Rect GetBoundingBox();
virtual void DisplayInfo( WinEDA_DrawFrame* frame );
/**
* @return the size of the "pen" that be used to draw or plot this item
*/
virtual int GetPenSize( );
protected:
virtual LIB_DRAW_ITEM* DoGenCopy();
/**
* Provide the arc draw object specific comparison.
*
* The sort order is as follows:
* - Arc horizontal (X) position.
* - Arc vertical (Y) position.
* - Arc start angle.
* - Arc end angle.
*/
virtual int DoCompare( const LIB_DRAW_ITEM& aOther ) const;
virtual void DoOffset( const wxPoint& aOffset );
virtual bool DoTestInside( EDA_Rect& aRect );
virtual void DoMove( const wxPoint& aPosition );
virtual wxPoint DoGetPosition() { return m_Pos; }
virtual void DoMirrorHorizontal( const wxPoint& aCenter );
virtual void DoPlot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill,
const int aTransform[2][2] );
virtual int DoGetWidth() { return m_Width; }
virtual void DoSetWidth( int aWidth ) { m_Width = aWidth; }
};
#endif // _LIB_ARC_H_
This diff is collapsed.
#ifndef _LIB_BEZIER_H_
#define _LIB_BEZIER_H_
#include "lib_draw_item.h"
/**************************************************/
/* Graphic Body Item: Bezier Curve (set of lines) */
/**************************************************/
class LIB_BEZIER : public LIB_DRAW_ITEM
{
public:
int m_Width; /* Line width */
std::vector<wxPoint> m_BezierPoints; // list of parameter (3|4)
std::vector<wxPoint> m_PolyPoints; // list of points (>= 2)
public:
LIB_BEZIER( LIB_COMPONENT * aParent );
LIB_BEZIER( const LIB_BEZIER& aBezier );
~LIB_BEZIER() { }
virtual wxString GetClass() const
{
return wxT( "LIB_BEZIER" );
}
/**
* Write bezier curve object out to a FILE in "*.lib" format.
*
* @param aFile - The FILE to write to.
* @return true if success writing else false.
*/
virtual bool Save( FILE* aFile );
virtual bool Load( char* aLine, wxString& aErrorMsg );
void AddPoint( const wxPoint& aPoint );
/**
* @return the number of corners
*/
unsigned GetCornerCount() const { return m_PolyPoints.size(); }
/**
* Test if the given point is within the bounds of this object.
*
* @param aRefPos - A wxPoint to test
* @return true if a hit, else false
*/
virtual bool HitTest( const wxPoint& aRefPos );
/**
* @param aPosRef = a wxPoint to test
* @param aThreshold = max distance to a segment
* @param aTransMat = the transform matrix
* @return true if the point aPosRef is near a segment
*/
virtual bool HitTest( wxPoint aPosRef, int aThreshold, const int aTransMat[2][2] );
/**
* @return the boundary box for this, in library coordinates
*/
virtual EDA_Rect GetBoundingBox();
/**
* @return the size of the "pen" that be used to draw or plot this item
*/
virtual int GetPenSize( );
void Draw( WinEDA_DrawPanel * aPanel, wxDC * aDC, const wxPoint &aOffset,
int aColor, int aDrawMode, void* aData,
const int aTransformMatrix[2][2] );
virtual void DisplayInfo( WinEDA_DrawFrame* aFrame );
protected:
virtual LIB_DRAW_ITEM* DoGenCopy();
/**
* Provide the bezier curve draw object specific comparison.
*
* The sort order for each bezier curve segment point is as follows:
* - Bezier point horizontal (X) point position.
* - Bezier point vertical (Y) point position.
*/
virtual int DoCompare( const LIB_DRAW_ITEM& aOther ) const;
virtual void DoOffset( const wxPoint& aOffset );
virtual bool DoTestInside( EDA_Rect& aRect );
virtual void DoMove( const wxPoint& aPosition );
virtual wxPoint DoGetPosition() { return m_PolyPoints[0]; }
virtual void DoMirrorHorizontal( const wxPoint& aCenter );
virtual void DoPlot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill,
const int aTransform[2][2] );
virtual int DoGetWidth() { return m_Width; }
virtual void DoSetWidth( int aWidth ) { m_Width = aWidth; }
};
#endif // _LIB_BEZIER_H_
/*************************/
/** class LIB_CIRCLE **/
/*************************/
#include "fctsys.h"
#include "gr_basic.h"
#include "common.h"
#include "class_drawpanel.h"
#include "plot_common.h"
#include "trigo.h"
#include "general.h"
#include "protos.h"
#include "lib_circle.h"
LIB_CIRCLE::LIB_CIRCLE( LIB_COMPONENT* aParent ) :
LIB_DRAW_ITEM( COMPONENT_CIRCLE_DRAW_TYPE, aParent )
{
m_Radius = 0;
m_Fill = NO_FILL;
m_isFillable = true;
m_typeName = _( "Circle" );
}
LIB_CIRCLE::LIB_CIRCLE( const LIB_CIRCLE& aCircle ) :
LIB_DRAW_ITEM( aCircle )
{
m_Pos = aCircle.m_Pos;
m_Radius = aCircle.m_Radius;
m_Fill = aCircle.m_Fill;
}
bool LIB_CIRCLE::Save( FILE* aFile )
{
if( fprintf( aFile, "C %d %d %d %d %d %d %c\n", m_Pos.x, m_Pos.y,
m_Radius, m_Unit, m_Convert, m_Width, fill_tab[m_Fill] ) < 0 )
return false;
return true;
}
bool LIB_CIRCLE::Load( char* aLine, wxString& aErrorMsg )
{
char tmp[256];
int cnt = sscanf( &aLine[2], "%d %d %d %d %d %d %s", &m_Pos.x, &m_Pos.y,
&m_Radius, &m_Unit, &m_Convert, &m_Width, tmp );
if( cnt < 6 )
{
aErrorMsg.Printf( _( "circle only had %d parameters of the required 6" ), cnt );
return false;
}
if( tmp[0] == 'F' )
m_Fill = FILLED_SHAPE;
if( tmp[0] == 'f' )
m_Fill = FILLED_WITH_BG_BODYCOLOR;
return true;
}
/**
* Function HitTest
* tests if the given wxPoint is within the bounds of this object.
* @param aRefPos A wxPoint to test in eeschema space
* @return - true if a hit, else false
*/
bool LIB_CIRCLE::HitTest( const wxPoint& aPosRef )
{
int mindist = m_Width ? m_Width / 2 : g_DrawDefaultLineThickness / 2;
// Have a minimal tolerance for hit test
if( mindist < MINIMUM_SELECTION_DISTANCE )
mindist = MINIMUM_SELECTION_DISTANCE;
return HitTest( aPosRef, mindist, DefaultTransformMatrix );
}
/** Function HitTest
* @return true if the point aPosRef is near this object
* @param aPosRef = a wxPoint to test
* @param aThreshold = max distance to this object (usually the half
* thickness of a line)
* @param aTransMat = the transform matrix
*/
bool LIB_CIRCLE::HitTest( wxPoint aPosRef, int aThreshold, const int aTransMat[2][2] )
{
wxPoint relpos = aPosRef - TransformCoordinate( aTransMat, m_Pos );
int dist = wxRound( sqrt( ( (double) relpos.x * relpos.x ) +
( (double) relpos.y * relpos.y ) ) );
if( abs( dist - m_Radius ) <= aThreshold )
return true;
return false;
}
LIB_DRAW_ITEM* LIB_CIRCLE::DoGenCopy()
{
LIB_CIRCLE* newitem = new LIB_CIRCLE( GetParent() );
newitem->m_Pos = m_Pos;
newitem->m_Radius = m_Radius;
newitem->m_Width = m_Width;
newitem->m_Unit = m_Unit;
newitem->m_Convert = m_Convert;
newitem->m_Flags = m_Flags;
newitem->m_Fill = m_Fill;
return (LIB_DRAW_ITEM*) newitem;
}
int LIB_CIRCLE::DoCompare( const LIB_DRAW_ITEM& aOther ) const
{
wxASSERT( aOther.Type() == COMPONENT_CIRCLE_DRAW_TYPE );
const LIB_CIRCLE* tmp = ( LIB_CIRCLE* ) &aOther;
if( m_Pos.x != tmp->m_Pos.x )
return m_Pos.x - tmp->m_Pos.x;
if( m_Pos.y != tmp->m_Pos.y )
return m_Pos.y - tmp->m_Pos.y;
if( m_Radius != tmp->m_Radius )
return m_Radius - tmp->m_Radius;
return 0;
}
void LIB_CIRCLE::DoOffset( const wxPoint& aOffset )
{
m_Pos += aOffset;
}
bool LIB_CIRCLE::DoTestInside( EDA_Rect& aRect )
{
/*
* FIXME: This fails to take into acount the radius around the center
* point.
*/
return aRect.Inside( m_Pos.x, -m_Pos.y );
}
void LIB_CIRCLE::DoMove( const wxPoint& aPosition )
{
m_Pos = aPosition;
}
void LIB_CIRCLE::DoMirrorHorizontal( const wxPoint& aCenter )
{
m_Pos.x -= aCenter.x;
m_Pos.x *= -1;
m_Pos.x += aCenter.x;
}
void LIB_CIRCLE::DoPlot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill,
const int aTransform[2][2] )
{
wxPoint pos = TransformCoordinate( aTransform, m_Pos ) + aOffset;
if( aFill && m_Fill == FILLED_WITH_BG_BODYCOLOR )
{
aPlotter->set_color( ReturnLayerColor( LAYER_DEVICE_BACKGROUND ) );
aPlotter->circle( pos, m_Radius * 2, FILLED_SHAPE, 0 );
}
aPlotter->set_color( ReturnLayerColor( LAYER_DEVICE ) );
aPlotter->circle( pos, m_Radius * 2, m_Fill, GetPenSize() );
}
/** Function GetPenSize
* @return the size of the "pen" that be used to draw or plot this item
*/
int LIB_CIRCLE::GetPenSize()
{
return ( m_Width == 0 ) ? g_DrawDefaultLineThickness : m_Width;
}
void LIB_CIRCLE::Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC,
const wxPoint& aOffset, int aColor, int aDrawMode,
void* aData, const int aTransformMatrix[2][2] )
{
wxPoint pos1;
int color = ReturnLayerColor( LAYER_DEVICE );
if( aColor < 0 ) // Used normal color or selected color
{
if( ( m_Selected & IS_SELECTED ) )
color = g_ItemSelectetColor;
}
else
color = aColor;
pos1 = TransformCoordinate( aTransformMatrix, m_Pos ) + aOffset;
GRSetDrawMode( aDC, aDrawMode );
FILL_T fill = aData ? NO_FILL : m_Fill;
if( aColor >= 0 )
fill = NO_FILL;
if( fill == FILLED_WITH_BG_BODYCOLOR )
GRFilledCircle( &aPanel->m_ClipBox, aDC, pos1.x, pos1.y,
m_Radius, GetPenSize( ),
(m_Flags & IS_MOVED) ? color : ReturnLayerColor( LAYER_DEVICE_BACKGROUND ),
ReturnLayerColor( LAYER_DEVICE_BACKGROUND ) );
else if( fill == FILLED_SHAPE )
GRFilledCircle( &aPanel->m_ClipBox, aDC, pos1.x, pos1.y, m_Radius, 0, color, color );
else
GRCircle( &aPanel->m_ClipBox, aDC, pos1.x, pos1.y, m_Radius, GetPenSize( ), color );
/* Set to one (1) to draw bounding box around circle to validate bounding
* box calculation. */
#if 0
EDA_Rect bBox = GetBoundingBox();
GRRect( &aPanel->m_ClipBox, aDC, bBox.GetOrigin().x, bBox.GetOrigin().y,
bBox.GetEnd().x, bBox.GetEnd().y, 0, LIGHTMAGENTA );
#endif
}
EDA_Rect LIB_CIRCLE::GetBoundingBox()
{
EDA_Rect rect;
rect.SetOrigin( m_Pos.x - m_Radius, ( m_Pos.y - m_Radius ) * -1 );
rect.SetEnd( m_Pos.x + m_Radius, ( m_Pos.y + m_Radius ) * -1 );
rect.Inflate( m_Width / 2, m_Width / 2 );
return rect;
}
void LIB_CIRCLE::DisplayInfo( WinEDA_DrawFrame* aFrame )
{
wxString msg;
EDA_Rect bBox = GetBoundingBox();
LIB_DRAW_ITEM::DisplayInfo( aFrame );
msg = ReturnStringFromValue( g_UserUnit, m_Width, EESCHEMA_INTERNAL_UNIT, true );
aFrame->AppendMsgPanel( _( "Line width" ), msg, BLUE );
msg = ReturnStringFromValue( g_UserUnit, m_Radius, EESCHEMA_INTERNAL_UNIT, true );
aFrame->AppendMsgPanel( _( "Radius" ), msg, RED );
msg.Printf( wxT( "(%d, %d, %d, %d)" ), bBox.GetOrigin().x,
bBox.GetOrigin().y, bBox.GetEnd().x, bBox.GetEnd().y );
aFrame->AppendMsgPanel( _( "Bounding box" ), msg, BROWN );
}
/*****************************/
/* Graphic Body Item: Circle */
/*****************************/
#ifndef _LIB_CIRCLE_H_
#define _LIB_CIRCLE_H_
#include "lib_draw_item.h"
class LIB_CIRCLE : public LIB_DRAW_ITEM
{
public:
int m_Radius;
wxPoint m_Pos; /* Position or centre (Arc and Circle) or start point (segments) */
int m_Width; /* Line width */
public:
LIB_CIRCLE(LIB_COMPONENT * aParent);
LIB_CIRCLE( const LIB_CIRCLE& aCircle );
~LIB_CIRCLE() { }
virtual wxString GetClass() const
{
return wxT( "LIB_CIRCLE" );
}
/**
* Write circle object to a FILE in "*.lib" format.
*
* @param aFile - The FILE to write to.
* @return - true if success writing else false.
*/
virtual bool Save( FILE* aFile );
virtual bool Load( char* aLine, wxString& aErrorMsg );
/**
* Test if the given point is within the bounds of this object.
*
* @param aRefPos - A wxPoint to test
* @return bool - true if a hit, else false
*/
virtual bool HitTest( const wxPoint& aRefPos );
/**
* @param aPosRef - a wxPoint to test
* @param aThreshold - max distance to this object (usually the half
* thickness of a line)
* @param aTransMat - the transform matrix
* @return true if the point aPosRef is near this object
*/
virtual bool HitTest( wxPoint aPosRef, int aThreshold, const int aTransMat[2][2] );
/**
* @return the size of the "pen" that be used to draw or plot this item
*/
virtual int GetPenSize( );
void Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC, const wxPoint &aOffset,
int aColor, int aDrawMode, void* aData,
const int aTransformMatrix[2][2] );
virtual EDA_Rect GetBoundingBox();
virtual void DisplayInfo( WinEDA_DrawFrame* aFrame );
protected:
virtual LIB_DRAW_ITEM* DoGenCopy();
/**
* Provide the circle draw object specific comparison.
*
* The sort order is as follows:
* - Circle horizontal (X) position.
* - Circle vertical (Y) position.
* - Circle radius.
*/
virtual int DoCompare( const LIB_DRAW_ITEM& aOther ) const;
virtual void DoOffset( const wxPoint& aOffset );
virtual bool DoTestInside( EDA_Rect& aRect );
virtual void DoMove( const wxPoint& aPosition );
virtual wxPoint DoGetPosition() { return m_Pos; }
virtual void DoMirrorHorizontal( const wxPoint& aCenter );
virtual void DoPlot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill,
const int aTransform[2][2] );
virtual int DoGetWidth() { return m_Width; }
virtual void DoSetWidth( int aWidth ) { m_Width = aWidth; }
};
#endif // _LIB_CIRCLE_H_
/*********************/
/* lib_draw_item.cpp */
/*********************/
#include "fctsys.h"
#include "gr_basic.h"
#include "common.h"
#include "class_drawpanel.h"
#include "plot_common.h"
#include "drawtxt.h"
#include "trigo.h"
#include "bezier_curves.h"
#include "confirm.h"
#include "program.h"
#include "general.h"
#include "protos.h"
#include "lib_draw_item.h"
const int fill_tab[3] = { 'N', 'F', 'f' };
//#define DRAW_ARC_WITH_ANGLE // Used to draw arcs
/* Base class (abstract) for components bodies items */
LIB_DRAW_ITEM::LIB_DRAW_ITEM( KICAD_T aType,
LIB_COMPONENT* aComponent,
int aUnit,
int aConvert,
FILL_T aFillType ) :
EDA_BaseStruct( aType )
{
m_Unit = aUnit;
m_Convert = aConvert;
m_Fill = aFillType;
m_Parent = (EDA_BaseStruct*) aComponent;
m_typeName = _( "Undefined" );
m_isFillable = false;
}
LIB_DRAW_ITEM::LIB_DRAW_ITEM( const LIB_DRAW_ITEM& aItem ) :
EDA_BaseStruct( aItem )
{
m_Unit = aItem.m_Unit;
m_Convert = aItem.m_Convert;
m_Fill = aItem.m_Fill;
m_Parent = aItem.m_Parent;
m_typeName = aItem.m_typeName;
m_isFillable = aItem.m_isFillable;
}
/**
* Update the message panel information with the drawing information.
*
* This base function is used to display the information common to the
* all library items. Call the base class from the derived class or the
* common information will not be updated in the message panel.
*/
void LIB_DRAW_ITEM::DisplayInfo( WinEDA_DrawFrame* aFrame )
{
wxString msg;
aFrame->ClearMsgPanel();
aFrame->AppendMsgPanel( _( "Type" ), m_typeName, CYAN );
if( m_Unit == 0 )
msg = _( "All" );
else
msg.Printf( wxT( "%d" ), m_Unit );
aFrame->AppendMsgPanel( _( "Unit" ), msg, BROWN );
if( m_Convert == 0 )
msg = _( "All" );
else if( m_Convert == 1 )
msg = _( "no" );
else if( m_Convert == 2 )
msg = _( "yes" );
else
msg = wxT( "?" );
aFrame->AppendMsgPanel( _( "Convert" ), msg, BROWN );
}
bool LIB_DRAW_ITEM::operator==( const LIB_DRAW_ITEM& aOther ) const
{
return ( ( Type() == aOther.Type() )
&& ( m_Unit == aOther.m_Unit )
&& ( m_Convert == aOther.m_Convert )
&& DoCompare( aOther ) == 0 );
}
bool LIB_DRAW_ITEM::operator<( const LIB_DRAW_ITEM& aOther ) const
{
int result = m_Convert - aOther.m_Convert;
if( result != 0 )
return result < 0;
result = m_Unit - aOther.m_Unit;
if( result != 0 )
return result < 0;
result = Type() - aOther.Type();
if( result != 0 )
return result < 0;
return ( DoCompare( aOther ) < 0 );
}
This diff is collapsed.
/**********************************************************/
/* Graphic Body Item: Polygon and polyline (set of lines) */
/**********************************************************/
#ifndef _LIB_POLYLINE_H_
#define _LIB_POLYLINE_H_
#include "lib_draw_item.h"
class LIB_POLYLINE : public LIB_DRAW_ITEM
{
public:
int m_Width; /* Line width */
std::vector<wxPoint> m_PolyPoints; // list of points (>= 2)
int m_ModifyIndex; // Index of the polyline point to modify
public:
LIB_POLYLINE(LIB_COMPONENT * aParent);
LIB_POLYLINE( const LIB_POLYLINE& aPolyline );
~LIB_POLYLINE() { }
virtual wxString GetClass() const
{
return wxT( "LIB_POLYLINE" );
}
/**
* Write polyline object out to a FILE in "*.lib" format.
*
* @param aFile - The FILE to write to.
* @return - true if success writing else false.
*/
virtual bool Save( FILE* aFile );
virtual bool Load( char* aLine, wxString& aErrorMsg );
void AddPoint( const wxPoint& aPoint );
/**
* @return the number of corners
*/
unsigned GetCornerCount() const { return m_PolyPoints.size(); }
/**
* Test if the given point is within the bounds of this object.
*
* @param aRefPos - A wxPoint to test
* @return - true if a hit, else false
*/
virtual bool HitTest( const wxPoint& aRefPos );
/**
* @param aPosRef = a wxPoint to test
* @param aThreshold = max distance to a segment
* @param aTransMat = the transform matrix
* @return true if the point aPosRef is near a segment
*/
virtual bool HitTest( wxPoint aPosRef, int aThreshold,
const int aTransMat[2][2] );
/**
* @return the boundary box for this, in library coordinates
*/
virtual EDA_Rect GetBoundingBox();
/**
* @return the size of the "pen" that be used to draw or plot this item
*/
virtual int GetPenSize( );
void Draw( WinEDA_DrawPanel * aPanel, wxDC * aDC, const wxPoint &aOffset,
int aColor, int aDrawMode, void* aData,
const int aTransformMatrix[2][2] );
virtual void DisplayInfo( WinEDA_DrawFrame* aFrame );
protected:
virtual LIB_DRAW_ITEM* DoGenCopy();
/**
* Provide the ployline segment draw object specific comparison.
*
* The sort order for each polyline segment point is as follows:
* - Line segment point horizontal (X) position.
* - Line segment point vertical (Y) position.
*/
virtual int DoCompare( const LIB_DRAW_ITEM& aOther ) const;
virtual void DoOffset( const wxPoint& aOffset );
virtual bool DoTestInside( EDA_Rect& aRect );
virtual void DoMove( const wxPoint& aPosition );
virtual wxPoint DoGetPosition() { return m_PolyPoints[0]; }
virtual void DoMirrorHorizontal( const wxPoint& aCenter );
virtual void DoPlot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill,
const int aTransform[2][2] );
virtual int DoGetWidth() { return m_Width; }
virtual void DoSetWidth( int aWidth ) { m_Width = aWidth; }
};
#endif // _LIB_POLYLIN_H_
This diff is collapsed.
/********************************/
/* Graphic Body Item: Rectangle */
/********************************/
#ifndef _LIB_RECTANGLE_H_
#define _LIB_RECTANGLE_H_
#include "lib_draw_item.h"
class LIB_RECTANGLE : public LIB_DRAW_ITEM
{
public:
wxPoint m_End; /* Rectangle end point. */
wxPoint m_Pos; /* Rectangle start point. */
int m_Width; /* Line width */
bool m_isWidthLocked; /* Flag: Keep width locked */
bool m_isHeightLocked; /* Flag: Keep height locked */
bool m_isStartPointSelected; /* Flag: is the upper left edge selected ? */
public:
LIB_RECTANGLE(LIB_COMPONENT * aParent);
LIB_RECTANGLE( const LIB_RECTANGLE& aRect );
~LIB_RECTANGLE() { }
virtual wxString GetClass() const
{
return wxT( "LIB_RECTANGLE" );
}
/**
* Write rectangle object out to a FILE in "*.lib" format.
*
* @param aFile - The FILE to write to.
* @return - true if success writing else false.
*/
virtual bool Save( FILE* aFile );
virtual bool Load( char* aLine, wxString& aErrorMsg );
/**
* Test if the given point is within the bounds of this object.
*
* @param aRefPos - A wxPoint to test
* @return - true if a hit, else false
*/
virtual bool HitTest( const wxPoint& aRefPos );
/**
* @param aPosRef - a wxPoint to test
* @param aThreshold - max distance to this object (usually the half
* thickness of a line)
* @param aTransMat - the transform matrix
* @return true if the point aPosRef is near this object
*/
virtual bool HitTest( wxPoint aPosRef, int aThreshold, const int aTransMat[2][2] );
/**
* @return the size of the "pen" that be used to draw or plot this item
*/
virtual int GetPenSize( );
void Draw( WinEDA_DrawPanel * aPanel, wxDC * aDC, const wxPoint &aOffset,
int aColor, int aDrawMode, void* aData,
const int aTransformMatrix[2][2] );
virtual EDA_Rect GetBoundingBox();
virtual void DisplayInfo( WinEDA_DrawFrame* aFrame );
protected:
virtual LIB_DRAW_ITEM* DoGenCopy();
/**
* Provide the rectangle draw object specific comparison.
*
* The sort order is as follows:
* - Rectangle horizontal (X) start position.
* - Rectangle vertical (Y) start position.
* - Rectangle horizontal (X) end position.
* - Rectangle vertical (Y) end position.
*/
virtual int DoCompare( const LIB_DRAW_ITEM& aOther ) const;
virtual void DoOffset( const wxPoint& aOffset );
virtual bool DoTestInside( EDA_Rect& aRect );
virtual void DoMove( const wxPoint& aPosition );
virtual wxPoint DoGetPosition() { return m_Pos; }
virtual void DoMirrorHorizontal( const wxPoint& aCenter );
virtual void DoPlot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill,
const int aTransform[2][2] );
virtual int DoGetWidth() { return m_Width; }
virtual void DoSetWidth( int aWidth ) { m_Width = aWidth; }
};
#endif // _LIB_REACTANGLE_H_
......@@ -19,19 +19,18 @@
#include "libeditframe.h"
#include "class_libentry.h"
#include "class_pin.h"
#include "lib_polyline.h"
/* functions to add commands and submenus depending on the item */
static void AddMenusForBlock( wxMenu* PopMenu, WinEDA_LibeditFrame* frame );
static void AddMenusForPin( wxMenu* PopMenu, LIB_PIN* Pin,
WinEDA_LibeditFrame* frame );
static void AddMenusForPin( wxMenu* PopMenu, LIB_PIN* Pin, WinEDA_LibeditFrame* frame );
bool WinEDA_LibeditFrame::OnRightClick( const wxPoint& MousePos,
wxMenu* PopMenu )
bool WinEDA_LibeditFrame::OnRightClick( const wxPoint& MousePos, wxMenu* PopMenu )
{
LIB_DRAW_ITEM* DrawEntry = LocateItemUsingCursor();
bool BlockActive = (GetScreen()->m_BlockLocate.m_Command != BLOCK_IDLE);
bool BlockActive = (GetScreen()->m_BlockLocate.m_Command != BLOCK_IDLE );
if( m_component == NULL )
return true;
......
This diff is collapsed.
This diff is collapsed.
......@@ -3,6 +3,9 @@
#include <vector>
#include <wx/gdicmn.h>
/**
* Function Bezier2Poly
* convert a Bezier curve to a polyline
......
......@@ -6,6 +6,7 @@
#ifndef __INCLUDE__COMMON_H__
#define __INCLUDE__COMMON_H__ 1
#include "wx/wx.h"
#include "wx/confbase.h"
#include "wx/fileconf.h"
......
......@@ -11,6 +11,10 @@
#include <vector>
#include "drawtxt.h"
class Ki_PageDescr;
/**
* Enum PlotFormat
* must be kept in order of the radio buttons in the plot panel/window.
......
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