Commit aac10106 authored by Dick Hollenbeck's avatar Dick Hollenbeck

more eagle_plugin work

parent cb210042
...@@ -1340,7 +1340,7 @@ public: ...@@ -1340,7 +1340,7 @@ public:
void ShowTargetOptionsDialog( PCB_TARGET* aTarget, wxDC* DC ); void ShowTargetOptionsDialog( PCB_TARGET* aTarget, wxDC* DC );
// Graphic segments type DRAWSEGMENT handling: // Graphic segments type DRAWSEGMENT handling:
DRAWSEGMENT* Begin_DrawSegment( DRAWSEGMENT* Segment, int shape, wxDC* DC ); DRAWSEGMENT* Begin_DrawSegment( DRAWSEGMENT* Segment, STROKE_T shape, wxDC* DC );
void End_Edge( DRAWSEGMENT* Segment, wxDC* DC ); void End_Edge( DRAWSEGMENT* Segment, wxDC* DC );
void Delete_Segment_Edge( DRAWSEGMENT* Segment, wxDC* DC ); void Delete_Segment_Edge( DRAWSEGMENT* Segment, wxDC* DC );
void Delete_Drawings_All_Layer( int aLayer ); void Delete_Drawings_All_Layer( int aLayer );
......
...@@ -124,6 +124,10 @@ const wxPoint DRAWSEGMENT::GetArcEnd() const ...@@ -124,6 +124,10 @@ const wxPoint DRAWSEGMENT::GetArcEnd() const
// m_Start is the arc centre // m_Start is the arc centre
endPoint = m_End; // m_End = start point of arc endPoint = m_End; // m_End = start point of arc
RotatePoint( &endPoint, m_Start, -m_Angle ); RotatePoint( &endPoint, m_Start, -m_Angle );
break;
default:
;
} }
return endPoint; // after rotation, the end of the arc. return endPoint; // after rotation, the end of the arc.
...@@ -387,15 +391,15 @@ EDA_RECT DRAWSEGMENT::GetBoundingBox() const ...@@ -387,15 +391,15 @@ EDA_RECT DRAWSEGMENT::GetBoundingBox() const
switch( m_Shape ) switch( m_Shape )
{ {
case S_SEGMENT: case S_SEGMENT:
bbox.SetEnd( m_End ); bbox.SetEnd( m_End );
break; break;
case S_CIRCLE: case S_CIRCLE:
bbox.Inflate( GetRadius() ); bbox.Inflate( GetRadius() );
break; break;
case S_ARC: case S_ARC:
{ {
bbox.Merge( m_End ); bbox.Merge( m_End );
wxPoint end = m_End; wxPoint end = m_End;
...@@ -404,7 +408,7 @@ EDA_RECT DRAWSEGMENT::GetBoundingBox() const ...@@ -404,7 +408,7 @@ EDA_RECT DRAWSEGMENT::GetBoundingBox() const
} }
break; break;
case S_POLYGON: case S_POLYGON:
{ {
wxPoint p_end; wxPoint p_end;
MODULE* module = GetParentModule(); MODULE* module = GetParentModule();
...@@ -429,8 +433,11 @@ EDA_RECT DRAWSEGMENT::GetBoundingBox() const ...@@ -429,8 +433,11 @@ EDA_RECT DRAWSEGMENT::GetBoundingBox() const
} }
bbox.SetEnd( p_end ); bbox.SetEnd( p_end );
break;
} }
break;
default:
;
} }
bbox.Inflate( ((m_Width+1) / 2) + 1 ); bbox.Inflate( ((m_Width+1) / 2) + 1 );
...@@ -449,30 +456,30 @@ bool DRAWSEGMENT::HitTest( const wxPoint& aPosition ) ...@@ -449,30 +456,30 @@ bool DRAWSEGMENT::HitTest( const wxPoint& aPosition )
{ {
case S_CIRCLE: case S_CIRCLE:
case S_ARC: case S_ARC:
{
int radius = GetRadius();
int dist = (int) hypot( (double) relPos.x, (double) relPos.y );
if( abs( radius - dist ) <= ( m_Width / 2 ) )
{ {
if( m_Shape == S_CIRCLE ) int radius = GetRadius();
return true; int dist = (int) hypot( (double) relPos.x, (double) relPos.y );
wxPoint startVec = wxPoint( m_End.x - m_Start.x, m_End.y - m_Start.y ); if( abs( radius - dist ) <= ( m_Width / 2 ) )
wxPoint endVec = m_End - m_Start; {
RotatePoint( &endVec, -m_Angle ); if( m_Shape == S_CIRCLE )
return true;
// Check dot products wxPoint startVec = wxPoint( m_End.x - m_Start.x, m_End.y - m_Start.y );
if( (long long)relPos.x*startVec.x + (long long)relPos.y*startVec.y < 0 ) wxPoint endVec = m_End - m_Start;
return false; RotatePoint( &endVec, -m_Angle );
if( (long long)relPos.x*endVec.x + (long long)relPos.y*endVec.y < 0 ) // Check dot products
return false; if( (long long)relPos.x*startVec.x + (long long)relPos.y*startVec.y < 0 )
return false;
return true; if( (long long)relPos.x*endVec.x + (long long)relPos.y*endVec.y < 0 )
return false;
return true;
}
} }
} break;
break;
case S_CURVE: case S_CURVE:
for( unsigned int i= 1; i < m_BezierPoints.size(); i++) for( unsigned int i= 1; i < m_BezierPoints.size(); i++)
...@@ -499,7 +506,7 @@ bool DRAWSEGMENT::HitTest( const EDA_RECT& aRect ) const ...@@ -499,7 +506,7 @@ bool DRAWSEGMENT::HitTest( const EDA_RECT& aRect ) const
{ {
switch( m_Shape ) switch( m_Shape )
{ {
case S_CIRCLE: case S_CIRCLE:
{ {
int radius = GetRadius(); int radius = GetRadius();
...@@ -512,14 +519,17 @@ bool DRAWSEGMENT::HitTest( const EDA_RECT& aRect ) const ...@@ -512,14 +519,17 @@ bool DRAWSEGMENT::HitTest( const EDA_RECT& aRect ) const
} }
break; break;
case S_ARC: case S_ARC:
case S_SEGMENT: case S_SEGMENT:
if( aRect.Contains( GetStart() ) ) if( aRect.Contains( GetStart() ) )
return true; return true;
if( aRect.Contains( GetEnd() ) ) if( aRect.Contains( GetEnd() ) )
return true; return true;
break; break;
default:
;
} }
return false; return false;
} }
......
...@@ -43,15 +43,15 @@ class MODULE; ...@@ -43,15 +43,15 @@ class MODULE;
class DRAWSEGMENT : public BOARD_ITEM class DRAWSEGMENT : public BOARD_ITEM
{ {
protected: protected:
int m_Width; ///< thickness of lines ... int m_Width; ///< thickness of lines ...
wxPoint m_Start; ///< Line start point or Circle and Arc center wxPoint m_Start; ///< Line start point or Circle and Arc center
wxPoint m_End; ///< Line end point or circle and arc start point wxPoint m_End; ///< Line end point or circle and arc start point
int m_Shape; ///< Shape: line, Circle, Arc STROKE_T m_Shape; ///< Shape: line, Circle, Arc
int m_Type; ///< Used in complex associations ( Dimensions.. ) int m_Type; ///< Used in complex associations ( Dimensions.. )
double m_Angle; ///< Used only for Arcs: Arc angle in 1/10 deg double m_Angle; ///< Used only for Arcs: Arc angle in 1/10 deg
wxPoint m_BezierC1; ///< Bezier Control Point 1 wxPoint m_BezierC1; ///< Bezier Control Point 1
wxPoint m_BezierC2; ///< Bezier Control Point 2 wxPoint m_BezierC2; ///< Bezier Control Point 2
std::vector<wxPoint> m_BezierPoints; std::vector<wxPoint> m_BezierPoints;
std::vector<wxPoint> m_PolyPoints; std::vector<wxPoint> m_PolyPoints;
...@@ -80,11 +80,11 @@ public: ...@@ -80,11 +80,11 @@ public:
void SetAngle( double aAngle ); // encapsulates the transition to degrees void SetAngle( double aAngle ); // encapsulates the transition to degrees
double GetAngle() const { return m_Angle; } double GetAngle() const { return m_Angle; }
void SetType( int aType ) { m_Type = aType; } void SetType( int aType ) { m_Type = aType; }
int GetType() const { return m_Type; } int GetType() const { return m_Type; }
void SetShape( int aShape ) { m_Shape = aShape; } void SetShape( STROKE_T aShape ) { m_Shape = aShape; }
int GetShape() const { return m_Shape; } STROKE_T GetShape() const { return m_Shape; }
void SetBezControl1( const wxPoint& aPoint ) { m_BezierC1 = aPoint; } void SetBezControl1( const wxPoint& aPoint ) { m_BezierC1 = aPoint; }
const wxPoint& GetBezControl1() const { return m_BezierC1; } const wxPoint& GetBezControl1() const { return m_BezierC1; }
...@@ -92,8 +92,8 @@ public: ...@@ -92,8 +92,8 @@ public:
void SetBezControl2( const wxPoint& aPoint ) { m_BezierC2 = aPoint; } void SetBezControl2( const wxPoint& aPoint ) { m_BezierC2 = aPoint; }
const wxPoint& GetBezControl2() const { return m_BezierC2; } const wxPoint& GetBezControl2() const { return m_BezierC2; }
void SetPosition( const wxPoint& aPos ) { m_Start = aPos; } // override void SetPosition( const wxPoint& aPos ) { m_Start = aPos; } // override
const wxPoint& GetPosition() const { return m_Start; } // override const wxPoint& GetPosition() const { return m_Start; } // override
/** /**
* Function GetStart * Function GetStart
......
...@@ -294,6 +294,11 @@ public: ...@@ -294,6 +294,11 @@ public:
m_Value->m_Text = aValue; m_Value->m_Text = aValue;
} }
/// read/write accessors:
TEXTE_MODULE& Value() { return *m_Value; }
TEXTE_MODULE& Reference() { return *m_Reference; }
/** /**
* Function FindPadByName * Function FindPadByName
* returns a D_PAD* with a matching name. Note that names may not be * returns a D_PAD* with a matching name. Note that names may not be
......
...@@ -88,14 +88,14 @@ public: ...@@ -88,14 +88,14 @@ public:
} }
/// @deprecated it seems /// @deprecated it seems
void SetType( int aType ) { m_Type = aType; } void SetType( int aType ) { m_Type = aType; }
int GetType() const { return m_Type; } int GetType() const { return m_Type; }
void SetVisible( bool isVisible ) { m_NoShow = !isVisible; } void SetVisible( bool isVisible ) { m_NoShow = !isVisible; }
bool IsVisible() const { return !m_NoShow; } bool IsVisible() const { return !m_NoShow; }
void SetPos0( const wxPoint& aPos ) { m_Pos0 = aPos; } void SetPos0( const wxPoint& aPos ) { m_Pos0 = aPos; }
const wxPoint& GetPos0() const { return m_Pos0; } const wxPoint& GetPos0() const { return m_Pos0; }
void Copy( TEXTE_MODULE* source ); // copy structure void Copy( TEXTE_MODULE* source ); // copy structure
......
This diff is collapsed.
...@@ -55,15 +55,10 @@ namespace boost { ...@@ -55,15 +55,10 @@ namespace boost {
typedef boost::property_tree::ptree PTREE; typedef boost::property_tree::ptree PTREE;
typedef const PTREE CPTREE; typedef const PTREE CPTREE;
struct EWIRE ///< Eagle wire struct EWIRE;
{ struct EROT;
double x1; struct EATTR;
double y1; struct ECIRCLE;
double x2;
double y2;
double width;
int layer;
};
/** /**
...@@ -104,26 +99,26 @@ public: ...@@ -104,26 +99,26 @@ public:
EAGLE_PLUGIN(); EAGLE_PLUGIN();
~EAGLE_PLUGIN(); ~EAGLE_PLUGIN();
private: private:
MODULE_MAP m_modules; ///< is a factory by use of MODULE copy constructor, MODULE_MAP m_templates; ///< is part of a MODULE factory that operates
///< lookup is based on libname.packagename ///< using copy construction.
///< lookup key is libname.packagename
PROPERTIES* m_props; ///< passed via Save() or Load(), no ownership, may be NULL. PROPERTIES* m_props; ///< passed via Save() or Load(), no ownership, may be NULL.
BOARD* m_board; ///< which BOARD, no ownership here BOARD* m_board; ///< which BOARD, no ownership here
double mm_per_biu; ///< how many mm in each BIU double mm_per_biu; ///< how many mm in each BIU
double biu_per_mm; ///< how many bius in a mm double biu_per_mm; ///< how many bius in a mm
/// initialize PLUGIN like a constructor would, and futz with fresh BOARD if needed. /// initialize PLUGIN like a constructor would, and futz with fresh BOARD if needed.
void init( PROPERTIES* aProperties ); void init( PROPERTIES* aProperties );
int kicad( double d ) const; int kicad( double d ) const;
int kicad_y( double y ) const { return kicad( y ); } int kicad_y( double y ) const { return -kicad( y ); }
int kicad_x( double x ) const { return kicad( x ); } int kicad_x( double x ) const { return kicad( x ); }
int kicad_layer( int aLayer ) const; static int kicad_layer( int aLayer );
double eagle( BIU d ) const { return mm_per_biu * d; } double eagle( BIU d ) const { return mm_per_biu * d; }
double eagle_x( BIU x ) const { return eagle( x ); } double eagle_x( BIU x ) const { return eagle( x ); }
...@@ -202,16 +197,32 @@ private: ...@@ -202,16 +197,32 @@ private:
void loadAllSections( CPTREE& aEagleBoard, const std::string& aXpath, bool aAppendToMe ); void loadAllSections( CPTREE& aEagleBoard, const std::string& aXpath, bool aAppendToMe );
void loadPlain( CPTREE& aPlain, const std::string& aXpath );
void loadNetsAndTracks( CPTREE& aSignals, const std::string& aXpath ); void loadNetsAndTracks( CPTREE& aSignals, const std::string& aXpath );
void loadModules( CPTREE& aLibs, const std::string& aXpath ); void loadLibraries( CPTREE& aLibs, const std::string& aXpath );
void loadElements( CPTREE& aElements, const std::string& aXpath );
/** /**
* Function wire * Function ewire
* converts a <wire>'s xml attributes to binary without additional conversion. * converts a <wire>'s xml attributes to binary without additional conversion.
* @return EWIRE - an Eagle <wire> object in binary. * @param aResult is an EWIRE to fill in with the <wire> data converted to binary.
*/
EWIRE ewire( CPTREE& aWire ) const;
ECIRCLE ecircle( CPTREE& aCircle ) const;
EROT erot( const std::string& aRot ) const;
/**
* Function eattr
* parses an Eagle "attribute" element. Note that an attribute element
* is different than an XML element attribute. The attribute element is a
* full XML node in and of itself, and has attributes of its own. Blame Eagle.
*/ */
EWIRE wire( CPTREE aWire ) const; EATTR eattr( CPTREE& aAttribute ) const;
/** /**
* Function fmtDEG * Function fmtDEG
......
...@@ -310,7 +310,7 @@ static void Abort_Move_ModuleOutline( EDA_DRAW_PANEL* Panel, wxDC* DC ) ...@@ -310,7 +310,7 @@ static void Abort_Move_ModuleOutline( EDA_DRAW_PANEL* Panel, wxDC* DC )
EDGE_MODULE* FOOTPRINT_EDIT_FRAME::Begin_Edge_Module( EDGE_MODULE* aEdge, EDGE_MODULE* FOOTPRINT_EDIT_FRAME::Begin_Edge_Module( EDGE_MODULE* aEdge,
wxDC* DC, wxDC* DC,
int type_edge ) STROKE_T type_edge )
{ {
MODULE* module = GetBoard()->m_Modules; MODULE* module = GetBoard()->m_Modules;
int angle = 0; int angle = 0;
......
...@@ -231,7 +231,7 @@ static void Abort_EditEdge( EDA_DRAW_PANEL* Panel, wxDC* DC ) ...@@ -231,7 +231,7 @@ static void Abort_EditEdge( EDA_DRAW_PANEL* Panel, wxDC* DC )
/* Initialize the drawing of a segment of type other than trace. /* Initialize the drawing of a segment of type other than trace.
*/ */
DRAWSEGMENT* PCB_EDIT_FRAME::Begin_DrawSegment( DRAWSEGMENT* Segment, int shape, wxDC* DC ) DRAWSEGMENT* PCB_EDIT_FRAME::Begin_DrawSegment( DRAWSEGMENT* Segment, STROKE_T shape, wxDC* DC )
{ {
int s_large; int s_large;
DRAWSEGMENT* DrawItem; DRAWSEGMENT* DrawItem;
......
...@@ -1238,7 +1238,7 @@ void LEGACY_PLUGIN::loadPAD( MODULE* aModule ) ...@@ -1238,7 +1238,7 @@ void LEGACY_PLUGIN::loadPAD( MODULE* aModule )
pos.y = biuParse( data ); pos.y = biuParse( data );
pad->SetPos0( pos ); pad->SetPos0( pos );
pad->SetPosition( pos ); // pad->SetPosition( pos ); set at function return
} }
else if( TESTLINE( "Le" ) ) else if( TESTLINE( "Le" ) )
...@@ -1291,7 +1291,10 @@ void LEGACY_PLUGIN::loadPAD( MODULE* aModule ) ...@@ -1291,7 +1291,10 @@ void LEGACY_PLUGIN::loadPAD( MODULE* aModule )
else if( TESTLINE( "$EndPAD" ) ) else if( TESTLINE( "$EndPAD" ) )
{ {
wxPoint padpos = pad->GetPosition(); // pad's "Position" is not relative to the module's,
// whereas Pos0 is relative to the module's but is the unrotated coordinate.
wxPoint padpos = pad->GetPos0();
RotatePoint( &padpos, aModule->GetOrientation() ); RotatePoint( &padpos, aModule->GetOrientation() );
...@@ -1634,7 +1637,7 @@ void LEGACY_PLUGIN::loadPCB_LINE() ...@@ -1634,7 +1637,7 @@ void LEGACY_PLUGIN::loadPCB_LINE()
if( width < 0 ) if( width < 0 )
width = 0; width = 0;
dseg->SetShape( shape ); dseg->SetShape( STROKE_T( shape ) );
dseg->SetWidth( width ); dseg->SetWidth( width );
dseg->SetStart( wxPoint( start_x, start_y ) ); dseg->SetStart( wxPoint( start_x, start_y ) );
dseg->SetEnd( wxPoint( end_x, end_y ) ); dseg->SetEnd( wxPoint( end_x, end_y ) );
......
...@@ -81,7 +81,7 @@ void FOOTPRINT_EDIT_FRAME::OnLeftClick( wxDC* DC, const wxPoint& MousePos ) ...@@ -81,7 +81,7 @@ void FOOTPRINT_EDIT_FRAME::OnLeftClick( wxDC* DC, const wxPoint& MousePos )
case ID_MODEDIT_LINE_TOOL: case ID_MODEDIT_LINE_TOOL:
if( !item || item->GetFlags() == 0 ) if( !item || item->GetFlags() == 0 )
{ {
int shape = S_SEGMENT; STROKE_T shape = S_SEGMENT;
if( GetToolId() == ID_MODEDIT_CIRCLE_TOOL ) if( GetToolId() == ID_MODEDIT_CIRCLE_TOOL )
shape = S_CIRCLE; shape = S_CIRCLE;
...@@ -107,7 +107,7 @@ void FOOTPRINT_EDIT_FRAME::OnLeftClick( wxDC* DC, const wxPoint& MousePos ) ...@@ -107,7 +107,7 @@ void FOOTPRINT_EDIT_FRAME::OnLeftClick( wxDC* DC, const wxPoint& MousePos )
} }
else if( ( (EDGE_MODULE*) item )->GetShape() == S_SEGMENT ) else if( ( (EDGE_MODULE*) item )->GetShape() == S_SEGMENT )
{ {
SetCurItem( Begin_Edge_Module( (EDGE_MODULE*) item, DC, 0 ) ); SetCurItem( Begin_Edge_Module( (EDGE_MODULE*) item, DC, S_SEGMENT ) );
} }
else else
{ {
......
...@@ -319,7 +319,7 @@ public: ...@@ -319,7 +319,7 @@ public:
* @param type_edge = S_SEGMENT,S_ARC .. * @param type_edge = S_SEGMENT,S_ARC ..
* @return the new created edge. * @return the new created edge.
*/ */
EDGE_MODULE* Begin_Edge_Module( EDGE_MODULE* Edge, wxDC* DC, int type_edge ); EDGE_MODULE* Begin_Edge_Module( EDGE_MODULE* Edge, wxDC* DC, STROKE_T type_edge );
/** /**
* Function End_Edge_Module * Function End_Edge_Module
......
...@@ -229,37 +229,37 @@ void PCB_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition ) ...@@ -229,37 +229,37 @@ void PCB_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition )
case ID_PCB_CIRCLE_BUTT: case ID_PCB_CIRCLE_BUTT:
case ID_PCB_ARC_BUTT: case ID_PCB_ARC_BUTT:
case ID_PCB_ADD_LINE_BUTT: case ID_PCB_ADD_LINE_BUTT:
{ {
int shape = S_SEGMENT; STROKE_T shape = S_SEGMENT;
if( GetToolId() == ID_PCB_CIRCLE_BUTT ) if( GetToolId() == ID_PCB_CIRCLE_BUTT )
shape = S_CIRCLE; shape = S_CIRCLE;
if( GetToolId() == ID_PCB_ARC_BUTT ) if( GetToolId() == ID_PCB_ARC_BUTT )
shape = S_ARC; shape = S_ARC;
if( getActiveLayer() <= LAST_COPPER_LAYER ) if( getActiveLayer() <= LAST_COPPER_LAYER )
{ {
DisplayError( this, _( "Graphic not authorized on Copper layers" ) ); DisplayError( this, _( "Graphic not authorized on Copper layers" ) );
break; break;
} }
if( (DrawStruct == NULL) || (DrawStruct->GetFlags() == 0) ) if( (DrawStruct == NULL) || (DrawStruct->GetFlags() == 0) )
{ {
DrawStruct = (BOARD_ITEM*) Begin_DrawSegment( NULL, shape, aDC ); DrawStruct = (BOARD_ITEM*) Begin_DrawSegment( NULL, shape, aDC );
SetCurItem( DrawStruct ); SetCurItem( DrawStruct );
m_canvas->SetAutoPanRequest( true ); m_canvas->SetAutoPanRequest( true );
} }
else if( DrawStruct else if( DrawStruct
&& (DrawStruct->Type() == PCB_LINE_T) && (DrawStruct->Type() == PCB_LINE_T)
&& DrawStruct->IsNew() ) && DrawStruct->IsNew() )
{ {
DrawStruct = (BOARD_ITEM*) Begin_DrawSegment( (DRAWSEGMENT*) DrawStruct, shape, aDC ); DrawStruct = (BOARD_ITEM*) Begin_DrawSegment( (DRAWSEGMENT*) DrawStruct, shape, aDC );
SetCurItem( DrawStruct ); SetCurItem( DrawStruct );
m_canvas->SetAutoPanRequest( true ); m_canvas->SetAutoPanRequest( true );
}
} }
break; break;
}
case ID_TRACK_BUTT: case ID_TRACK_BUTT:
if( getActiveLayer() > LAST_COPPER_LAYER ) if( getActiveLayer() > LAST_COPPER_LAYER )
......
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