Browse Source
Add copy constructors and cloning to schematic objects and other minor fixes.
pull/1/head
Add copy constructors and cloning to schematic objects and other minor fixes.
pull/1/head
66 changed files with 2249 additions and 2505 deletions
-
14CHANGELOG.txt
-
166common/base_struct.cpp
-
4common/basicframe.cpp
-
34common/class_marker_base.cpp
-
2common/dcsvg.cpp
-
9common/sch_item_struct.cpp
-
4eeschema/CMakeLists.txt
-
3eeschema/block.cpp
-
141eeschema/bus-wire-junction.cpp
-
4eeschema/busentry.cpp
-
8eeschema/cleanup.cpp
-
1eeschema/delete.cpp
-
6eeschema/dialogs/dialog_color_config.cpp
-
14eeschema/dialogs/dialog_edit_component_in_lib.cpp
-
2eeschema/edit_component_in_schematic.cpp
-
2eeschema/edit_label.cpp
-
17eeschema/eeredraw.cpp
-
4eeschema/events_called_functions_for_edit.cpp
-
3eeschema/getpart.cpp
-
3eeschema/hotkeys.cpp
-
4eeschema/load_one_schematic_file.cpp
-
4eeschema/locate.cpp
-
2eeschema/netlist.cpp
-
3eeschema/onleftclick.cpp
-
3eeschema/onrightclick.cpp
-
85eeschema/operations_on_items_lists.cpp
-
3eeschema/plot.cpp
-
246eeschema/sch_bus_entry.cpp
-
115eeschema/sch_bus_entry.h
-
46eeschema/sch_component.cpp
-
35eeschema/sch_component.h
-
83eeschema/sch_field.cpp
-
37eeschema/sch_field.h
-
1129eeschema/sch_items.cpp
-
436eeschema/sch_items.h
-
429eeschema/sch_line.cpp
-
136eeschema/sch_line.h
-
17eeschema/sch_marker.cpp
-
11eeschema/sch_marker.h
-
182eeschema/sch_no_connect.cpp
-
102eeschema/sch_no_connect.h
-
233eeschema/sch_polyline.cpp
-
104eeschema/sch_polyline.h
-
7eeschema/sch_screen.cpp
-
170eeschema/sch_sheet.cpp
-
25eeschema/sch_sheet.h
-
56eeschema/sch_sheet_pin.cpp
-
298eeschema/sch_text.cpp
-
55eeschema/sch_text.h
-
2eeschema/schedit.cpp
-
4eeschema/schematic_undo_redo.cpp
-
4gerbview/dialogs/dialog_gerber_config.cpp
-
94include/base_struct.h
-
11include/class_base_screen.h
-
41include/class_marker_base.h
-
81include/sch_item_struct.h
-
2include/wxPcbStruct.h
-
2pcbnew/dialogs/dialog_display_options.h
-
2pcbnew/dialogs/dialog_edit_module_for_BoardEditor.cpp
-
2pcbnew/dialogs/dialog_edit_module_for_Modedit.cpp
-
2pcbnew/dimension.cpp
-
2pcbnew/mirepcb.cpp
-
2pcbnew/muonde.cpp
-
2pcbnew/pcbframe.cpp
-
2pcbnew/pcbplot.cpp
-
2pcbnew/xchgmod.cpp
@ -0,0 +1,246 @@ |
|||
/***********************/ |
|||
/* class SCH_BUS_ENTRY */ |
|||
/***********************/ |
|||
|
|||
#include "fctsys.h"
|
|||
#include "gr_basic.h"
|
|||
#include "macros.h"
|
|||
#include "class_drawpanel.h"
|
|||
#include "trigo.h"
|
|||
#include "common.h"
|
|||
#include "richio.h"
|
|||
|
|||
#include "general.h"
|
|||
#include "protos.h"
|
|||
#include "sch_bus_entry.h"
|
|||
|
|||
|
|||
SCH_BUS_ENTRY::SCH_BUS_ENTRY( const wxPoint& pos, int shape, int id ) : |
|||
SCH_ITEM( NULL, SCH_BUS_ENTRY_T ) |
|||
{ |
|||
m_Pos = pos; |
|||
m_Size.x = 100; |
|||
m_Size.y = 100; |
|||
m_Layer = LAYER_WIRE; |
|||
m_Width = 0; |
|||
|
|||
if( id == BUS_TO_BUS ) |
|||
{ |
|||
m_Layer = LAYER_BUS; |
|||
} |
|||
|
|||
if( shape == '/' ) |
|||
m_Size.y = -100; |
|||
} |
|||
|
|||
|
|||
SCH_BUS_ENTRY::SCH_BUS_ENTRY( const SCH_BUS_ENTRY& aBusEntry ) : |
|||
SCH_ITEM( aBusEntry ) |
|||
{ |
|||
m_Pos = aBusEntry.m_Pos; |
|||
m_Size = aBusEntry.m_Size; |
|||
m_Width = aBusEntry.m_Width; |
|||
} |
|||
|
|||
|
|||
EDA_ITEM* SCH_BUS_ENTRY::doClone() const |
|||
{ |
|||
return new SCH_BUS_ENTRY( *this ); |
|||
} |
|||
|
|||
|
|||
wxPoint SCH_BUS_ENTRY::m_End() const |
|||
{ |
|||
return wxPoint( m_Pos.x + m_Size.x, m_Pos.y + m_Size.y ); |
|||
} |
|||
|
|||
|
|||
bool SCH_BUS_ENTRY::Save( FILE* aFile ) const |
|||
{ |
|||
bool success = true; |
|||
|
|||
const char* layer = "Wire"; |
|||
const char* width = "Line"; |
|||
|
|||
if( GetLayer() == LAYER_BUS ) |
|||
{ |
|||
layer = "Bus"; width = "Bus"; |
|||
} |
|||
|
|||
if( fprintf( aFile, "Entry %s %s\n", layer, width ) == EOF ) |
|||
{ |
|||
success = false; |
|||
} |
|||
if( fprintf( aFile, "\t%-4d %-4d %-4d %-4d\n", |
|||
m_Pos.x, m_Pos.y, m_End().x, m_End().y ) == EOF ) |
|||
{ |
|||
success = false; |
|||
} |
|||
|
|||
return success; |
|||
} |
|||
|
|||
|
|||
bool SCH_BUS_ENTRY::Load( LINE_READER& aLine, wxString& aErrorMsg ) |
|||
{ |
|||
char Name1[256]; |
|||
char Name2[256]; |
|||
char* line = (char*) aLine; |
|||
|
|||
while( (*line != ' ' ) && *line ) |
|||
line++; |
|||
|
|||
if( sscanf( line, "%s %s", Name1, Name2 ) != 2 ) |
|||
{ |
|||
aErrorMsg.Printf( wxT( "EESchema file bus entry load error at line %d" ), |
|||
aLine.LineNumber() ); |
|||
aErrorMsg << wxT( "\n" ) << CONV_FROM_UTF8( (char*) aLine ); |
|||
return false; |
|||
} |
|||
|
|||
m_Layer = LAYER_WIRE; |
|||
|
|||
if( Name1[0] == 'B' ) |
|||
m_Layer = LAYER_BUS; |
|||
|
|||
if( !aLine.ReadLine() || sscanf( (char*) aLine, "%d %d %d %d ", &m_Pos.x, &m_Pos.y, |
|||
&m_Size.x, &m_Size.y ) != 4 ) |
|||
{ |
|||
aErrorMsg.Printf( wxT( "EESchema file bus entry load error at line %d" ), |
|||
aLine.LineNumber() ); |
|||
aErrorMsg << wxT( "\n" ) << CONV_FROM_UTF8( (char*) aLine ); |
|||
return false; |
|||
} |
|||
|
|||
m_Size.x -= m_Pos.x; |
|||
m_Size.y -= m_Pos.y; |
|||
|
|||
return true; |
|||
} |
|||
|
|||
|
|||
EDA_Rect SCH_BUS_ENTRY::GetBoundingBox() const |
|||
{ |
|||
EDA_Rect box; |
|||
|
|||
box.SetOrigin( m_Pos ); |
|||
box.SetEnd( m_End() ); |
|||
|
|||
box.Normalize(); |
|||
int width = ( m_Width == 0 ) ? g_DrawDefaultLineThickness : m_Width; |
|||
box.Inflate( width / 2 ); |
|||
|
|||
return box; |
|||
} |
|||
|
|||
|
|||
int SCH_BUS_ENTRY::GetPenSize() const |
|||
{ |
|||
int pensize = ( m_Width == 0 ) ? g_DrawDefaultLineThickness : m_Width; |
|||
|
|||
if( m_Layer == LAYER_BUS && m_Width == 0 ) |
|||
{ |
|||
pensize = wxRound( g_DrawDefaultLineThickness * BUS_WIDTH_EXPAND ); |
|||
pensize = MAX( pensize, 3 ); |
|||
} |
|||
|
|||
return pensize; |
|||
} |
|||
|
|||
|
|||
void SCH_BUS_ENTRY::Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC, const wxPoint& aOffset, |
|||
int aDrawMode, int aColor ) |
|||
{ |
|||
int color; |
|||
|
|||
if( aColor >= 0 ) |
|||
color = aColor; |
|||
else |
|||
color = ReturnLayerColor( m_Layer ); |
|||
|
|||
GRSetDrawMode( aDC, aDrawMode ); |
|||
|
|||
GRLine( &aPanel->m_ClipBox, aDC, m_Pos.x + aOffset.x, m_Pos.y + aOffset.y, |
|||
m_End().x + aOffset.x, m_End().y + aOffset.y, GetPenSize(), color ); |
|||
} |
|||
|
|||
|
|||
void SCH_BUS_ENTRY::Mirror_X( int aXaxis_position ) |
|||
{ |
|||
m_Pos.y -= aXaxis_position; |
|||
NEGATE( m_Pos.y ); |
|||
m_Pos.y += aXaxis_position; |
|||
NEGATE( m_Size.y ); |
|||
} |
|||
|
|||
|
|||
void SCH_BUS_ENTRY::Mirror_Y( int aYaxis_position ) |
|||
{ |
|||
m_Pos.x -= aYaxis_position; |
|||
NEGATE( m_Pos.x ); |
|||
m_Pos.x += aYaxis_position; |
|||
NEGATE( m_Size.x ); |
|||
} |
|||
|
|||
|
|||
void SCH_BUS_ENTRY::Rotate( wxPoint rotationPoint ) |
|||
{ |
|||
RotatePoint( &m_Pos, rotationPoint, 900 ); |
|||
RotatePoint( &m_Size.x, &m_Size.y, 900 ); |
|||
} |
|||
|
|||
|
|||
void SCH_BUS_ENTRY::GetEndPoints( std::vector< DANGLING_END_ITEM >& aItemList ) |
|||
{ |
|||
DANGLING_END_ITEM item( ENTRY_END, this ); |
|||
item.m_Pos = m_Pos; |
|||
|
|||
DANGLING_END_ITEM item1( ENTRY_END, this ); |
|||
item1.m_Pos = m_End(); |
|||
aItemList.push_back( item ); |
|||
aItemList.push_back( item1 ); |
|||
} |
|||
|
|||
|
|||
bool SCH_BUS_ENTRY::IsSelectStateChanged( const wxRect& aRect ) |
|||
{ |
|||
bool previousState = IsSelected(); |
|||
|
|||
// If either end of the bus entry is inside the selection rectangle, the entire
|
|||
// bus entry is selected. Bus entries have a fixed length and angle.
|
|||
if( aRect.Contains( m_Pos ) || aRect.Contains( m_End() ) ) |
|||
m_Flags |= SELECTED; |
|||
else |
|||
m_Flags &= ~SELECTED; |
|||
|
|||
return previousState != IsSelected(); |
|||
} |
|||
|
|||
|
|||
void SCH_BUS_ENTRY::GetConnectionPoints( vector< wxPoint >& aPoints ) const |
|||
{ |
|||
aPoints.push_back( m_Pos ); |
|||
aPoints.push_back( m_End() ); |
|||
} |
|||
|
|||
|
|||
bool SCH_BUS_ENTRY::doHitTest( const wxPoint& aPoint, int aAccuracy, SCH_FILTER_T aFilter ) const |
|||
{ |
|||
if( !( aFilter & BUS_ENTRY_T ) ) |
|||
return false; |
|||
|
|||
return TestSegmentHit( aPoint, m_Pos, m_End(), aAccuracy ); |
|||
} |
|||
|
|||
|
|||
bool SCH_BUS_ENTRY::doHitTest( const EDA_Rect& aRect, bool aContained, int aAccuracy ) const |
|||
{ |
|||
EDA_Rect rect = aRect; |
|||
|
|||
rect.Inflate( aAccuracy ); |
|||
|
|||
if( aContained ) |
|||
return rect.Contains( GetBoundingBox() ); |
|||
|
|||
return rect.Intersects( GetBoundingBox() ); |
|||
} |
@ -0,0 +1,115 @@ |
|||
/** |
|||
* @file sch_bus_entry.h |
|||
* |
|||
*/ |
|||
|
|||
#ifndef _SCH_BUS_ENTRY_H_ |
|||
#define _SCH_BUS_ENTRY_H_ |
|||
|
|||
#include "sch_item_struct.h" |
|||
|
|||
|
|||
/* Flags for BUS ENTRY (bus to bus or wire to bus */ |
|||
#define WIRE_TO_BUS 0 |
|||
#define BUS_TO_BUS 1 |
|||
|
|||
|
|||
/** |
|||
* Class SCH_BUS_ENTRY |
|||
* |
|||
* Defines a bus or wire entry. |
|||
*/ |
|||
class SCH_BUS_ENTRY : public SCH_ITEM |
|||
{ |
|||
public: |
|||
int m_Width; |
|||
wxPoint m_Pos; |
|||
wxSize m_Size; |
|||
|
|||
public: |
|||
SCH_BUS_ENTRY( const wxPoint& pos = wxPoint( 0, 0 ), int shape = '\\', int id = WIRE_TO_BUS ); |
|||
|
|||
SCH_BUS_ENTRY( const SCH_BUS_ENTRY& aBusEntry ); |
|||
|
|||
~SCH_BUS_ENTRY() { } |
|||
|
|||
virtual wxString GetClass() const |
|||
{ |
|||
return wxT( "SCH_BUS_ENTRY" ); |
|||
} |
|||
|
|||
wxPoint m_End() const; |
|||
|
|||
virtual void Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC, const wxPoint& aOffset, |
|||
int aDrawMode, int aColor = -1 ); |
|||
|
|||
/** |
|||
* Function Save |
|||
* writes the data structures for this object out to a FILE in "*.sch" |
|||
* format. |
|||
* @param aFile The FILE to write to. |
|||
* @return bool - true if success writing else false. |
|||
*/ |
|||
bool Save( FILE* aFile ) const; |
|||
|
|||
/** |
|||
* Load schematic bus entry from \a aLine in a .sch file. |
|||
* |
|||
* @param aLine - Essentially this is file to read schematic bus entry from. |
|||
* @param aErrorMsg - Description of the error if an error occurs while loading the |
|||
* schematic bus entry. |
|||
* @return True if the schematic bus entry loaded successfully. |
|||
*/ |
|||
virtual bool Load( LINE_READER& aLine, wxString& aErrorMsg ); |
|||
|
|||
/** |
|||
* Function GetBoundingBox |
|||
* returns the orthogonal, bounding box of this object for display |
|||
* purposes. This box should be an enclosing perimeter for visible |
|||
* components of this object, and the units should be in the pcb or |
|||
* schematic coordinate system. It is OK to overestimate the size |
|||
* by a few counts. |
|||
*/ |
|||
EDA_Rect GetBoundingBox() const; |
|||
|
|||
/** |
|||
* Function GetPenSize |
|||
* @return the size of the "pen" that be used to draw or plot this item |
|||
*/ |
|||
virtual int GetPenSize() const; |
|||
|
|||
/** |
|||
* Function Move |
|||
* moves and item to a new position by \a aMoveVector. |
|||
* @param aMoveVector The displacement vector. |
|||
*/ |
|||
virtual void Move( const wxPoint& aMoveVector ) |
|||
{ |
|||
m_Pos += aMoveVector; |
|||
} |
|||
|
|||
/** |
|||
* Function Mirror_Y |
|||
* mirrors the item relative to \a aYaxis_position. |
|||
* @param aYaxis_position The Y axis coordinate to mirror around. |
|||
*/ |
|||
virtual void Mirror_Y( int aYaxis_position ); |
|||
|
|||
virtual void Mirror_X( int aXaxis_position ); |
|||
|
|||
virtual void Rotate( wxPoint rotationPoint ); |
|||
|
|||
virtual void GetEndPoints( std::vector <DANGLING_END_ITEM>& aItemList ); |
|||
|
|||
virtual bool IsSelectStateChanged( const wxRect& aRect ); |
|||
|
|||
virtual void GetConnectionPoints( vector< wxPoint >& aPoints ) const; |
|||
|
|||
private: |
|||
virtual bool doHitTest( const wxPoint& aPoint, int aAccuracy, SCH_FILTER_T aFilter ) const; |
|||
virtual bool doHitTest( const EDA_Rect& aRect, bool aContained, int aAccuracy ) const; |
|||
virtual EDA_ITEM* doClone() const; |
|||
}; |
|||
|
|||
|
|||
#endif // _SCH_BUS_ENTRY_H_ |
1129
eeschema/sch_items.cpp
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
@ -0,0 +1,429 @@ |
|||
/******************/ |
|||
/* Class SCH_LINE */ |
|||
/******************/ |
|||
|
|||
#include "fctsys.h"
|
|||
#include "gr_basic.h"
|
|||
#include "macros.h"
|
|||
#include "class_drawpanel.h"
|
|||
#include "trigo.h"
|
|||
#include "richio.h"
|
|||
|
|||
#include "general.h"
|
|||
#include "protos.h"
|
|||
#include "sch_line.h"
|
|||
|
|||
#include <boost/foreach.hpp>
|
|||
|
|||
|
|||
SCH_LINE::SCH_LINE( const wxPoint& pos, int layer ) : |
|||
SCH_ITEM( NULL, SCH_LINE_T ) |
|||
{ |
|||
m_Start = pos; |
|||
m_End = pos; |
|||
m_Width = 0; // Default thickness used
|
|||
m_StartIsDangling = m_EndIsDangling = FALSE; |
|||
|
|||
switch( layer ) |
|||
{ |
|||
default: |
|||
m_Layer = LAYER_NOTES; |
|||
break; |
|||
|
|||
case LAYER_WIRE: |
|||
m_Layer = LAYER_WIRE; |
|||
break; |
|||
|
|||
case LAYER_BUS: |
|||
m_Layer = LAYER_BUS; |
|||
break; |
|||
} |
|||
} |
|||
|
|||
|
|||
SCH_LINE::SCH_LINE( const SCH_LINE& aLine ) : |
|||
SCH_ITEM( aLine ) |
|||
{ |
|||
m_Start = aLine.m_Start; |
|||
m_End = aLine.m_End; |
|||
m_Width = aLine.m_Width; |
|||
m_StartIsDangling = m_EndIsDangling = false; |
|||
} |
|||
|
|||
|
|||
EDA_ITEM* SCH_LINE::doClone() const |
|||
{ |
|||
return new SCH_LINE( *this ); |
|||
} |
|||
|
|||
|
|||
void SCH_LINE::Move( const wxPoint& aOffset ) |
|||
{ |
|||
if( (m_Flags & STARTPOINT) == 0 && aOffset != wxPoint( 0, 0 ) ) |
|||
{ |
|||
m_Start += aOffset; |
|||
SetModified(); |
|||
} |
|||
|
|||
if( (m_Flags & ENDPOINT) == 0 && aOffset != wxPoint( 0, 0 ) ) |
|||
{ |
|||
m_End += aOffset; |
|||
SetModified(); |
|||
} |
|||
} |
|||
|
|||
|
|||
#if defined(DEBUG)
|
|||
|
|||
void SCH_LINE::Show( int nestLevel, std::ostream& os ) const |
|||
{ |
|||
NestedSpace( nestLevel, os ) << '<' << GetClass().Lower().mb_str() |
|||
<< " layer=\"" << m_Layer << '"' |
|||
<< " width=\"" << m_Width << '"' |
|||
<< " startIsDangling=\"" << m_StartIsDangling |
|||
<< '"' << " endIsDangling=\"" |
|||
<< m_EndIsDangling << '"' << ">" |
|||
<< " <start" << m_Start << "/>" |
|||
<< " <end" << m_End << "/>" << "</" |
|||
<< GetClass().Lower().mb_str() << ">\n"; |
|||
} |
|||
|
|||
#endif
|
|||
|
|||
|
|||
EDA_Rect SCH_LINE::GetBoundingBox() const |
|||
{ |
|||
int width = 25; |
|||
|
|||
int xmin = MIN( m_Start.x, m_End.x ) - width; |
|||
int ymin = MIN( m_Start.y, m_End.y ) - width; |
|||
|
|||
int xmax = MAX( m_Start.x, m_End.x ) + width; |
|||
int ymax = MAX( m_Start.y, m_End.y ) + width; |
|||
|
|||
// return a rectangle which is [pos,dim) in nature. therefore the +1
|
|||
EDA_Rect ret( wxPoint( xmin, ymin ), wxSize( xmax - xmin + 1, ymax - ymin + 1 ) ); |
|||
|
|||
return ret; |
|||
} |
|||
|
|||
|
|||
bool SCH_LINE::Save( FILE* aFile ) const |
|||
{ |
|||
bool success = true; |
|||
|
|||
const char* layer = "Notes"; |
|||
const char* width = "Line"; |
|||
|
|||
if( GetLayer() == LAYER_WIRE ) |
|||
layer = "Wire"; |
|||
|
|||
if( GetLayer() == LAYER_BUS ) |
|||
layer = "Bus"; |
|||
|
|||
if( fprintf( aFile, "Wire %s %s\n", layer, width ) == EOF ) |
|||
{ |
|||
success = false; |
|||
} |
|||
|
|||
if( fprintf( aFile, "\t%-4d %-4d %-4d %-4d\n", m_Start.x, m_Start.y, |
|||
m_End.x, m_End.y ) == EOF ) |
|||
{ |
|||
success = false; |
|||
} |
|||
|
|||
return success; |
|||
} |
|||
|
|||
|
|||
bool SCH_LINE::Load( LINE_READER& aLine, wxString& aErrorMsg ) |
|||
{ |
|||
char Name1[256]; |
|||
char Name2[256]; |
|||
char* line = (char*) aLine; |
|||
|
|||
while( (*line != ' ' ) && *line ) |
|||
line++; |
|||
|
|||
if( sscanf( line, "%s %s", Name1, Name2 ) != 2 ) |
|||
{ |
|||
aErrorMsg.Printf( wxT( "EESchema file segment error at line %d, aborted" ), |
|||
aLine.LineNumber() ); |
|||
aErrorMsg << wxT( "\n" ) << CONV_FROM_UTF8( (char*) aLine ); |
|||
return false; |
|||
} |
|||
|
|||
m_Layer = LAYER_NOTES; |
|||
|
|||
if( Name1[0] == 'W' ) |
|||
m_Layer = LAYER_WIRE; |
|||
|
|||
if( Name1[0] == 'B' ) |
|||
m_Layer = LAYER_BUS; |
|||
|
|||
if( !aLine.ReadLine() || sscanf( (char*) aLine, "%d %d %d %d ", |
|||
&m_Start.x, &m_Start.y, &m_End.x, &m_End.y ) != 4 ) |
|||
{ |
|||
aErrorMsg.Printf( wxT( "EESchema file Segment struct error at line %d, aborted" ), |
|||
aLine.LineNumber() ); |
|||
aErrorMsg << wxT( "\n" ) << CONV_FROM_UTF8( (char*) aLine ); |
|||
return false; |
|||
} |
|||
|
|||
return true; |
|||
} |
|||
|
|||
|
|||
int SCH_LINE::GetPenSize() const |
|||
{ |
|||
int pensize = ( m_Width == 0 ) ? g_DrawDefaultLineThickness : m_Width; |
|||
|
|||
if( m_Layer == LAYER_BUS && m_Width == 0 ) |
|||
{ |
|||
pensize = wxRound( g_DrawDefaultLineThickness * BUS_WIDTH_EXPAND ); |
|||
pensize = MAX( pensize, 3 ); |
|||
} |
|||
|
|||
return pensize; |
|||
} |
|||
|
|||
|
|||
void SCH_LINE::Draw( WinEDA_DrawPanel* panel, wxDC* DC, const wxPoint& offset, |
|||
int DrawMode, int Color ) |
|||
{ |
|||
int color; |
|||
int width = GetPenSize(); |
|||
|
|||
if( Color >= 0 ) |
|||
color = Color; |
|||
else |
|||
color = ReturnLayerColor( m_Layer ); |
|||
|
|||
GRSetDrawMode( DC, DrawMode ); |
|||
|
|||
if( m_Layer == LAYER_NOTES ) |
|||
GRDashedLine( &panel->m_ClipBox, DC, m_Start.x + offset.x, |
|||
m_Start.y + offset.y, m_End.x + offset.x, |
|||
m_End.y + offset.y, width, color ); |
|||
else |
|||
GRLine( &panel->m_ClipBox, DC, m_Start.x + offset.x, |
|||
m_Start.y + offset.y, m_End.x + offset.x, m_End.y + offset.y, |
|||
width, color ); |
|||
|
|||
if( m_StartIsDangling ) |
|||
DrawDanglingSymbol( panel, DC, m_Start + offset, color ); |
|||
|
|||
if( m_EndIsDangling ) |
|||
DrawDanglingSymbol( panel, DC, m_End + offset, color ); |
|||
} |
|||
|
|||
|
|||
void SCH_LINE::Mirror_X( int aXaxis_position ) |
|||
{ |
|||
m_Start.y -= aXaxis_position; |
|||
NEGATE( m_Start.y ); |
|||
m_Start.y += aXaxis_position; |
|||
m_End.y -= aXaxis_position; |
|||
NEGATE( m_End.y ); |
|||
m_End.y += aXaxis_position; |
|||
} |
|||
|
|||
|
|||
void SCH_LINE::Mirror_Y( int aYaxis_position ) |
|||
{ |
|||
m_Start.x -= aYaxis_position; |
|||
NEGATE( m_Start.x ); |
|||
m_Start.x += aYaxis_position; |
|||
m_End.x -= aYaxis_position; |
|||
NEGATE( m_End.x ); |
|||
m_End.x += aYaxis_position; |
|||
} |
|||
|
|||
|
|||
void SCH_LINE::Rotate( wxPoint rotationPoint ) |
|||
{ |
|||
RotatePoint( &m_Start, rotationPoint, 900 ); |
|||
RotatePoint( &m_End, rotationPoint, 900 ); |
|||
} |
|||
|
|||
|
|||
bool SCH_LINE::MergeOverlap( SCH_LINE* aLine ) |
|||
{ |
|||
wxCHECK_MSG( aLine != NULL && aLine->Type() == SCH_LINE_T, false, |
|||
wxT( "Cannot test line segment for overlap." ) ); |
|||
|
|||
if( this == aLine || GetLayer() != aLine->GetLayer() ) |
|||
return false; |
|||
|
|||
// Search for a common end, and modify coordinates to ensure RefSegm->m_End
|
|||
// == TstSegm->m_Start
|
|||
if( m_Start == aLine->m_Start ) |
|||
{ |
|||
if( m_End == aLine->m_End ) |
|||
return true; |
|||
|
|||
EXCHG( m_Start, m_End ); |
|||
} |
|||
else if( m_Start == aLine->m_End ) |
|||
{ |
|||
EXCHG( m_Start, m_End ); |
|||
EXCHG( aLine->m_Start, aLine->m_End ); |
|||
} |
|||
else if( m_End == aLine->m_End ) |
|||
{ |
|||
EXCHG( aLine->m_Start, aLine->m_End ); |
|||
} |
|||
else if( m_End != aLine->m_Start ) |
|||
{ |
|||
// No common end point, segments cannot be merged.
|
|||
return false; |
|||
} |
|||
|
|||
/* Test alignment: */ |
|||
if( m_Start.y == m_End.y ) // Horizontal segment
|
|||
{ |
|||
if( aLine->m_Start.y == aLine->m_End.y ) |
|||
{ |
|||
m_End = aLine->m_End; |
|||
return true; |
|||
} |
|||
} |
|||
else if( m_Start.x == m_End.x ) // Vertical segment
|
|||
{ |
|||
if( aLine->m_Start.x == aLine->m_End.x ) |
|||
{ |
|||
m_End = aLine->m_End; |
|||
return true; |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
if( atan2( (double) ( m_Start.x - m_End.x ), (double) ( m_Start.y - m_End.y ) ) |
|||
== atan2( (double) ( aLine->m_Start.x - aLine->m_End.x ), |
|||
(double) ( aLine->m_Start.y - aLine->m_End.y ) ) ) |
|||
{ |
|||
m_End = aLine->m_End; |
|||
return true; |
|||
} |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
|
|||
|
|||
void SCH_LINE::GetEndPoints( std::vector <DANGLING_END_ITEM>& aItemList ) |
|||
{ |
|||
if( GetLayer() == LAYER_NOTES ) |
|||
return; |
|||
|
|||
if( ( GetLayer() == LAYER_BUS ) || ( GetLayer() == LAYER_WIRE ) ) |
|||
{ |
|||
DANGLING_END_ITEM item( (GetLayer() == LAYER_BUS) ? BUS_START_END : WIRE_START_END, this ); |
|||
item.m_Pos = m_Start; |
|||
DANGLING_END_ITEM item1( (GetLayer() == LAYER_BUS) ? BUS_END_END : WIRE_END_END, this ); |
|||
item1.m_Pos = m_End; |
|||
|
|||
aItemList.push_back( item ); |
|||
aItemList.push_back( item1 ); |
|||
} |
|||
} |
|||
|
|||
|
|||
bool SCH_LINE::IsDanglingStateChanged( std::vector< DANGLING_END_ITEM >& aItemList ) |
|||
{ |
|||
bool previousStartState = m_StartIsDangling; |
|||
bool previousEndState = m_EndIsDangling; |
|||
|
|||
m_StartIsDangling = m_EndIsDangling = true; |
|||
|
|||
if( GetLayer() == LAYER_WIRE ) |
|||
{ |
|||
BOOST_FOREACH( DANGLING_END_ITEM item, aItemList ) |
|||
{ |
|||
if( item.m_Item == this ) |
|||
continue; |
|||
|
|||
if( m_Start == item.m_Pos ) |
|||
m_StartIsDangling = false; |
|||
|
|||
if( m_End == item.m_Pos ) |
|||
m_EndIsDangling = false; |
|||
|
|||
if( (m_StartIsDangling == false) && (m_EndIsDangling == false) ) |
|||
break; |
|||
} |
|||
} |
|||
else if( GetLayer() == LAYER_BUS || GetLayer() == LAYER_NOTES ) |
|||
{ |
|||
// Lines on the notes layer and the bus layer cannot be tested for dangling ends.
|
|||
previousStartState = previousEndState = m_StartIsDangling = m_EndIsDangling = false; |
|||
} |
|||
|
|||
return ( previousStartState != m_StartIsDangling ) || ( previousEndState != m_EndIsDangling ); |
|||
} |
|||
|
|||
|
|||
bool SCH_LINE::IsSelectStateChanged( const wxRect& aRect ) |
|||
{ |
|||
bool previousState = IsSelected(); |
|||
|
|||
if( aRect.Contains( m_Start ) ) |
|||
m_Flags |= STARTPOINT | SELECTED; |
|||
else |
|||
m_Flags &= ~( STARTPOINT | SELECTED ); |
|||
|
|||
if( aRect.Contains( m_End ) ) |
|||
m_Flags |= ENDPOINT | SELECTED; |
|||
else |
|||
m_Flags &= ~( ENDPOINT | SELECTED ); |
|||
|
|||
return previousState != IsSelected(); |
|||
} |
|||
|
|||
|
|||
void SCH_LINE::GetConnectionPoints( vector< wxPoint >& aPoints ) const |
|||
{ |
|||
aPoints.push_back( m_Start ); |
|||
aPoints.push_back( m_End ); |
|||
} |
|||
|
|||
|
|||
bool SCH_LINE::doHitTest( const wxPoint& aPoint, int aAccuracy, SCH_FILTER_T aFilter ) const |
|||
{ |
|||
if( !( aFilter & ( DRAW_ITEM_T | WIRE_T | BUS_T ) ) ) |
|||
return false; |
|||
|
|||
if( ( ( aFilter & DRAW_ITEM_T ) && ( m_Layer == LAYER_NOTES ) ) |
|||
|| ( ( aFilter & WIRE_T ) && ( m_Layer == LAYER_WIRE ) ) |
|||
|| ( ( aFilter & BUS_T ) && ( m_Layer == LAYER_BUS ) ) ) |
|||
{ |
|||
if( ( aFilter & EXCLUDE_WIRE_BUS_ENDPOINTS && IsEndPoint( aPoint ) ) |
|||
|| ( aFilter & WIRE_BUS_ENDPOINTS_ONLY && !IsEndPoint( aPoint ) ) |
|||
|| ( TestSegmentHit( aPoint, m_Start, m_End, aAccuracy ) ) ) |
|||
return true; |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
|
|||
|
|||
bool SCH_LINE::doHitTest( const EDA_Rect& aRect, bool aContained, int aAccuracy ) const |
|||
{ |
|||
EDA_Rect rect = aRect; |
|||
|
|||
rect.Inflate( aAccuracy ); |
|||
|
|||
if( aContained ) |
|||
return rect.Contains( GetBoundingBox() ); |
|||
|
|||
return rect.Intersects( GetBoundingBox() ); |
|||
} |
|||
|
|||
|
|||
bool SCH_LINE::doIsConnected( const wxPoint& aPosition ) const |
|||
{ |
|||
if( m_Layer != LAYER_WIRE && m_Layer != LAYER_BUS ) |
|||
return false; |
|||
|
|||
return IsEndPoint( aPosition ); |
|||
} |
@ -0,0 +1,136 @@ |
|||
/** |
|||
* @file sch_line.h |
|||
* |
|||
*/ |
|||
|
|||
#ifndef _SCH_LINE_H_ |
|||
#define _SCH_LINE_H_ |
|||
|
|||
|
|||
#include "sch_item_struct.h" |
|||
|
|||
|
|||
/** |
|||
* Class SCH_LINE |
|||
* is a segment description base class to describe items which have 2 end |
|||
* points (track, wire, draw line ...) |
|||
*/ |
|||
class SCH_LINE : public SCH_ITEM |
|||
{ |
|||
bool m_StartIsDangling; |
|||
bool m_EndIsDangling; // TRUE if not connected (wires, tracks...) |
|||
|
|||
public: |
|||
int m_Width; // 0 = line, > 0 = tracks, bus ... |
|||
wxPoint m_Start; // Line start point |
|||
wxPoint m_End; // Line end point |
|||
|
|||
public: |
|||
SCH_LINE( const wxPoint& pos = wxPoint( 0, 0 ), int layer = LAYER_NOTES ); |
|||
SCH_LINE( const SCH_LINE& aLine ); |
|||
~SCH_LINE() { } |
|||
|
|||
SCH_LINE* Next() const { return (SCH_LINE*) Pnext; } |
|||
SCH_LINE* Back() const { return (SCH_LINE*) Pback; } |
|||
|
|||
virtual wxString GetClass() const |
|||
{ |
|||
return wxT( "SCH_LINE" ); |
|||
} |
|||
|
|||
bool IsEndPoint( const wxPoint& aPoint ) const |
|||
{ |
|||
return aPoint == m_Start || aPoint == m_End; |
|||
} |
|||
|
|||
bool IsNull() const { return m_Start == m_End; } |
|||
|
|||
/** |
|||
* Function GetBoundingBox |
|||
* returns the orthogonal, bounding box of this object for display purposes. |
|||
* This box should be an enclosing perimeter for visible components of this |
|||
* object, and the units should be in the pcb or schematic coordinate system. |
|||
* It is OK to overestimate the size by a few counts. |
|||
*/ |
|||
EDA_Rect GetBoundingBox() const; |
|||
|
|||
virtual void Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC, const wxPoint& aOffset, |
|||
int aDrawMode, int aColor = -1 ); |
|||
|
|||
/** |
|||
* Function Save |
|||
* writes the data structures for this object out to a FILE in "*.sch" format. |
|||
* @param aFile The FILE to write to. |
|||
* @return bool - true if success writing else false. |
|||
*/ |
|||
bool Save( FILE* aFile ) const; |
|||
|
|||
/** |
|||
* Load schematic line from \a aLine in a .sch file. |
|||
* |
|||
* @param aLine - Essentially this is file to read schematic line from. |
|||
* @param aErrorMsg - Description of the error if an error occurs while loading the |
|||
* schematic line. |
|||
* @return True if the schematic line loaded successfully. |
|||
*/ |
|||
virtual bool Load( LINE_READER& aLine, wxString& aErrorMsg ); |
|||
|
|||
/** |
|||
* Function GetPenSize |
|||
* @return the size of the "pen" that be used to draw or plot this item |
|||
*/ |
|||
virtual int GetPenSize() const; |
|||
|
|||
/** |
|||
* Function Move |
|||
* moves the item by \a aMoveVector. |
|||
* @param aMoveVector The displacement vector |
|||
*/ |
|||
virtual void Move( const wxPoint& aMoveVector ); |
|||
|
|||
virtual void Mirror_X( int aXaxis_position ); |
|||
|
|||
/** |
|||
* Function Mirror_Y |
|||
* mirrors the item relative to \a aYaxis_position. |
|||
* @param aYaxis_position = the y axis position |
|||
*/ |
|||
virtual void Mirror_Y( int aYaxis_position ); |
|||
|
|||
virtual void Rotate( wxPoint rotationPoint ); |
|||
|
|||
/** |
|||
* Check line against \a aLine to see if it overlaps and merge if it does. |
|||
* |
|||
* This method will change the line to be equivalent of the line and \a aLine if the |
|||
* two lines overlap. This method is used to merge multple line segments into a single |
|||
* line. |
|||
* |
|||
* @param aLine - Line to compare. |
|||
* @return True if lines overlap and the line was merged with \a aLine. |
|||
*/ |
|||
bool MergeOverlap( SCH_LINE* aLine ); |
|||
|
|||
virtual void GetEndPoints( std::vector <DANGLING_END_ITEM>& aItemList ); |
|||
|
|||
virtual bool IsDanglingStateChanged( std::vector< DANGLING_END_ITEM >& aItemList ); |
|||
|
|||
virtual bool IsDangling() const { return m_StartIsDangling || m_EndIsDangling; } |
|||
|
|||
virtual bool IsSelectStateChanged( const wxRect& aRect ); |
|||
|
|||
virtual void GetConnectionPoints( vector< wxPoint >& aPoints ) const; |
|||
|
|||
#if defined(DEBUG) |
|||
void Show( int nestLevel, std::ostream& os ) const; |
|||
#endif |
|||
|
|||
private: |
|||
virtual bool doHitTest( const wxPoint& aPoint, int aAccuracy, SCH_FILTER_T aFilter ) const; |
|||
virtual bool doHitTest( const EDA_Rect& aRect, bool aContained, int aAccuracy ) const; |
|||
virtual bool doIsConnected( const wxPoint& aPosition ) const; |
|||
virtual EDA_ITEM* doClone() const; |
|||
}; |
|||
|
|||
|
|||
#endif // _SCH_LINE_H_ |
@ -0,0 +1,182 @@ |
|||
/************************/ |
|||
/* Class SCH_NO_CONNECT */ |
|||
/************************/ |
|||
|
|||
#include "fctsys.h"
|
|||
#include "gr_basic.h"
|
|||
#include "macros.h"
|
|||
#include "class_drawpanel.h"
|
|||
#include "common.h"
|
|||
#include "trigo.h"
|
|||
#include "richio.h"
|
|||
|
|||
#include "general.h"
|
|||
#include "protos.h"
|
|||
#include "sch_no_connect.h"
|
|||
|
|||
|
|||
SCH_NO_CONNECT::SCH_NO_CONNECT( const wxPoint& pos ) : |
|||
SCH_ITEM( NULL, SCH_NO_CONNECT_T ) |
|||
{ |
|||
#define DRAWNOCONNECT_SIZE 48 /* No symbol connection range. */
|
|||
m_Pos = pos; |
|||
m_Size.x = m_Size.y = DRAWNOCONNECT_SIZE; |
|||
#undef DRAWNOCONNECT_SIZE
|
|||
} |
|||
|
|||
|
|||
SCH_NO_CONNECT::SCH_NO_CONNECT( const SCH_NO_CONNECT& aNoConnect ) : |
|||
SCH_ITEM( aNoConnect ) |
|||
{ |
|||
m_Pos = aNoConnect.m_Pos; |
|||
m_Size = aNoConnect.m_Size; |
|||
} |
|||
|
|||
|
|||
EDA_ITEM* SCH_NO_CONNECT::doClone() const |
|||
{ |
|||
return new SCH_NO_CONNECT( *this ); |
|||
} |
|||
|
|||
|
|||
EDA_Rect SCH_NO_CONNECT::GetBoundingBox() const |
|||
{ |
|||
int delta = ( GetPenSize() + m_Size.x ) / 2; |
|||
EDA_Rect box; |
|||
|
|||
box.SetOrigin( m_Pos ); |
|||
box.Inflate( delta ); |
|||
|
|||
return box; |
|||
} |
|||
|
|||
|
|||
bool SCH_NO_CONNECT::Save( FILE* aFile ) const |
|||
{ |
|||
bool success = true; |
|||
|
|||
if( fprintf( aFile, "NoConn ~ %-4d %-4d\n", m_Pos.x, m_Pos.y ) == EOF ) |
|||
{ |
|||
success = false; |
|||
} |
|||
|
|||
return success; |
|||
} |
|||
|
|||
|
|||
bool SCH_NO_CONNECT::Load( LINE_READER& aLine, wxString& aErrorMsg ) |
|||
{ |
|||
char name[256]; |
|||
char* line = (char*) aLine; |
|||
|
|||
while( (*line != ' ' ) && *line ) |
|||
line++; |
|||
|
|||
if( sscanf( line, "%s %d %d", name, &m_Pos.x, &m_Pos.y ) != 3 ) |
|||
{ |
|||
aErrorMsg.Printf( wxT( "EESchema file No Connect load error at line %d" ), |
|||
aLine.LineNumber() ); |
|||
aErrorMsg << wxT( "\n" ) << CONV_FROM_UTF8( ((char*)aLine) ); |
|||
return false; |
|||
} |
|||
|
|||
return true; |
|||
} |
|||
|
|||
|
|||
int SCH_NO_CONNECT::GetPenSize() const |
|||
{ |
|||
return g_DrawDefaultLineThickness; |
|||
} |
|||
|
|||
|
|||
void SCH_NO_CONNECT::Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC, const wxPoint& aOffset, |
|||
int aDrawMode, int aColor ) |
|||
{ |
|||
int pX, pY, color; |
|||
int delta = m_Size.x / 2; |
|||
int width = g_DrawDefaultLineThickness; |
|||
|
|||
pX = m_Pos.x + aOffset.x; |
|||
pY = m_Pos.y + aOffset.y; |
|||
|
|||
if( aColor >= 0 ) |
|||
color = aColor; |
|||
else |
|||
color = ReturnLayerColor( LAYER_NOCONNECT ); |
|||
|
|||
GRSetDrawMode( aDC, aDrawMode ); |
|||
|
|||
GRLine( &aPanel->m_ClipBox, aDC, pX - delta, pY - delta, pX + delta, pY + delta, width, color ); |
|||
GRLine( &aPanel->m_ClipBox, aDC, pX + delta, pY - delta, pX - delta, pY + delta, width, color ); |
|||
} |
|||
|
|||
|
|||
void SCH_NO_CONNECT::Mirror_X( int aXaxis_position ) |
|||
{ |
|||
m_Pos.y -= aXaxis_position; |
|||
NEGATE( m_Pos.y ); |
|||
m_Pos.y += aXaxis_position; |
|||
} |
|||
|
|||
|
|||
void SCH_NO_CONNECT::Mirror_Y( int aYaxis_position ) |
|||
{ |
|||
m_Pos.x -= aYaxis_position; |
|||
NEGATE( m_Pos.x ); |
|||
m_Pos.x += aYaxis_position; |
|||
} |
|||
|
|||
|
|||
void SCH_NO_CONNECT::Rotate( wxPoint rotationPoint ) |
|||
{ |
|||
RotatePoint( &m_Pos, rotationPoint, 900 ); |
|||
} |
|||
|
|||
|
|||
bool SCH_NO_CONNECT::IsSelectStateChanged( const wxRect& aRect ) |
|||
{ |
|||
bool previousState = IsSelected(); |
|||
|
|||
if( aRect.Contains( m_Pos ) ) |
|||
m_Flags |= SELECTED; |
|||
else |
|||
m_Flags &= ~SELECTED; |
|||
|
|||
return previousState != IsSelected(); |
|||
} |
|||
|
|||
|
|||
void SCH_NO_CONNECT::GetConnectionPoints( vector< wxPoint >& aPoints ) const |
|||
{ |
|||
aPoints.push_back( m_Pos ); |
|||
} |
|||
|
|||
|
|||
bool SCH_NO_CONNECT::doHitTest( const wxPoint& aPoint, int aAccuracy, SCH_FILTER_T aFilter ) const |
|||
{ |
|||
if( !( aFilter & NO_CONNECT_T ) ) |
|||
return false; |
|||
|
|||
int delta = ( ( m_Size.x + g_DrawDefaultLineThickness ) / 2 ) + aAccuracy; |
|||
|
|||
wxPoint dist = aPoint - m_Pos; |
|||
|
|||
if( ( ABS( dist.x ) <= delta ) && ( ABS( dist.y ) <= delta ) ) |
|||
return true; |
|||
|
|||
return false; |
|||
} |
|||
|
|||
|
|||
bool SCH_NO_CONNECT::doHitTest( const EDA_Rect& aRect, bool aContained, int aAccuracy ) const |
|||
{ |
|||
EDA_Rect rect = aRect; |
|||
|
|||
rect.Inflate( aAccuracy ); |
|||
|
|||
if( aContained ) |
|||
return rect.Contains( GetBoundingBox() ); |
|||
|
|||
return rect.Intersects( GetBoundingBox() ); |
|||
} |
@ -0,0 +1,102 @@ |
|||
/** |
|||
* @file sch_no_connect.h |
|||
* |
|||
*/ |
|||
|
|||
#ifndef _SCH_NO_CONNECT_H_ |
|||
#define _SCH_NO_CONNECT_H_ |
|||
|
|||
|
|||
#include "sch_item_struct.h" |
|||
|
|||
|
|||
class SCH_NO_CONNECT : public SCH_ITEM |
|||
{ |
|||
public: |
|||
wxPoint m_Pos; /* XY coordinates of NoConnect. */ |
|||
wxSize m_Size; // size of this symbol |
|||
|
|||
public: |
|||
SCH_NO_CONNECT( const wxPoint& pos = wxPoint( 0, 0 ) ); |
|||
|
|||
SCH_NO_CONNECT( const SCH_NO_CONNECT& aNoConnect ); |
|||
|
|||
~SCH_NO_CONNECT() { } |
|||
|
|||
virtual wxString GetClass() const |
|||
{ |
|||
return wxT( "SCH_NO_CONNECT" ); |
|||
} |
|||
|
|||
/** |
|||
* Function GetPenSize |
|||
* @return the size of the "pen" that be used to draw or plot this item |
|||
*/ |
|||
virtual int GetPenSize() const; |
|||
|
|||
virtual void Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC, const wxPoint& aOffset, |
|||
int aDrawMode, int aColor = -1 ); |
|||
|
|||
/** |
|||
* Function Save |
|||
* writes the data structures for this object out to a FILE in "*.sch" |
|||
* format. |
|||
* @param aFile The FILE to write to. |
|||
* @return bool - true if success writing else false. |
|||
*/ |
|||
bool Save( FILE* aFile ) const; |
|||
|
|||
/** |
|||
* Load schematic no connect entry from \a aLine in a .sch file. |
|||
* |
|||
* @param aLine - Essentially this is file to read schematic no connect from. |
|||
* @param aErrorMsg - Description of the error if an error occurs while loading the |
|||
* schematic no connect. |
|||
* @return True if the schematic no connect loaded successfully. |
|||
*/ |
|||
virtual bool Load( LINE_READER& aLine, wxString& aErrorMsg ); |
|||
|
|||
/** |
|||
* Function GetBoundingBox |
|||
* returns the orthogonal, bounding box of this object for display |
|||
* purposes. This box should be an enclosing perimeter for visible |
|||
* components of this object, and the units should be in the pcb or |
|||
* schematic coordinate system. It is OK to overestimate the size |
|||
* by a few counts. |
|||
*/ |
|||
EDA_Rect GetBoundingBox() const; |
|||
|
|||
// Geometric transforms (used in block operations): |
|||
|
|||
/** virtual function Move |
|||
* move item to a new position. |
|||
* @param aMoveVector = the displacement vector |
|||
*/ |
|||
virtual void Move( const wxPoint& aMoveVector ) |
|||
{ |
|||
m_Pos += aMoveVector; |
|||
} |
|||
|
|||
/** |
|||
* Function Mirror_Y |
|||
* mirrors item relative to \a aYaxis_position. |
|||
* @param aYaxis_position = the y axis position |
|||
*/ |
|||
virtual void Mirror_Y( int aYaxis_position ); |
|||
|
|||
virtual void Mirror_X( int aXaxis_position ); |
|||
|
|||
virtual void Rotate( wxPoint rotationPoint ); |
|||
|
|||
virtual bool IsSelectStateChanged( const wxRect& aRect ); |
|||
|
|||
virtual void GetConnectionPoints( vector< wxPoint >& aPoints ) const; |
|||
|
|||
private: |
|||
virtual bool doHitTest( const wxPoint& aPoint, int aAccuracy, SCH_FILTER_T aFilter ) const; |
|||
virtual bool doHitTest( const EDA_Rect& aRect, bool aContained, int aAccuracy ) const; |
|||
virtual EDA_ITEM* doClone() const; |
|||
}; |
|||
|
|||
|
|||
#endif // _SCH_NO_CONNECT_H_ |
@ -0,0 +1,233 @@ |
|||
/**********************/ |
|||
/* Class SCH_POLYLINE */ |
|||
/**********************/ |
|||
|
|||
#include "fctsys.h"
|
|||
#include "gr_basic.h"
|
|||
#include "macros.h"
|
|||
#include "class_drawpanel.h"
|
|||
#include "trigo.h"
|
|||
#include "common.h"
|
|||
#include "richio.h"
|
|||
|
|||
#include "general.h"
|
|||
#include "protos.h"
|
|||
#include "sch_polyline.h"
|
|||
|
|||
|
|||
SCH_POLYLINE::SCH_POLYLINE( int layer ) : |
|||
SCH_ITEM( NULL, SCH_POLYLINE_T ) |
|||
{ |
|||
m_Width = 0; |
|||
|
|||
switch( layer ) |
|||
{ |
|||
default: |
|||
m_Layer = LAYER_NOTES; |
|||
break; |
|||
|
|||
case LAYER_WIRE: |
|||
case LAYER_NOTES: |
|||
case LAYER_BUS: |
|||
m_Layer = layer; |
|||
break; |
|||
} |
|||
} |
|||
|
|||
|
|||
SCH_POLYLINE::SCH_POLYLINE( const SCH_POLYLINE& aPolyLine ) : |
|||
SCH_ITEM( aPolyLine ) |
|||
{ |
|||
m_Width = aPolyLine.m_Width; |
|||
m_PolyPoints = aPolyLine.m_PolyPoints; |
|||
} |
|||
|
|||
|
|||
SCH_POLYLINE::~SCH_POLYLINE() |
|||
{ |
|||
} |
|||
|
|||
|
|||
EDA_ITEM* SCH_POLYLINE::doClone() const |
|||
{ |
|||
return new SCH_POLYLINE( *this ); |
|||
} |
|||
|
|||
|
|||
bool SCH_POLYLINE::Save( FILE* aFile ) const |
|||
{ |
|||
bool success = true; |
|||
|
|||
const char* layer = "Notes"; |
|||
const char* width = "Line"; |
|||
|
|||
if( GetLayer() == LAYER_WIRE ) |
|||
layer = "Wire"; |
|||
|
|||
if( GetLayer() == LAYER_BUS ) |
|||
layer = "Bus"; |
|||
|
|||
if( fprintf( aFile, "Poly %s %s %d\n", width, layer, GetCornerCount() ) == EOF ) |
|||
{ |
|||
return false; |
|||
} |
|||
|
|||
for( unsigned ii = 0; ii < GetCornerCount(); ii++ ) |
|||
{ |
|||
if( fprintf( aFile, "\t%-4d %-4d\n", m_PolyPoints[ii ].x, m_PolyPoints[ii].y ) == EOF ) |
|||
{ |
|||
success = false; |
|||
break; |
|||
} |
|||
} |
|||
|
|||
return success; |
|||
} |
|||
|
|||
|
|||
bool SCH_POLYLINE::Load( LINE_READER& aLine, wxString& aErrorMsg ) |
|||
{ |
|||
char Name1[256]; |
|||
char Name2[256]; |
|||
wxPoint pt; |
|||
int ii; |
|||
char* line = (char*) aLine; |
|||
|
|||
while( (*line != ' ' ) && *line ) |
|||
line++; |
|||
|
|||
if( sscanf( line, "%s %s %d", Name1, Name2, &ii ) != 3 ) |
|||
{ |
|||
aErrorMsg.Printf( wxT( "EESchema file polyline struct error at line %d, aborted" ), |
|||
aLine.LineNumber() ); |
|||
aErrorMsg << wxT( "\n" ) << CONV_FROM_UTF8( (char*) aLine ); |
|||
return false; |
|||
} |
|||
|
|||
m_Layer = LAYER_NOTES; |
|||
|
|||
if( Name2[0] == 'W' ) |
|||
m_Layer = LAYER_WIRE; |
|||
|
|||
if( Name2[0] == 'B' ) |
|||
m_Layer = LAYER_BUS; |
|||
|
|||
for( unsigned jj = 0; jj < (unsigned)ii; jj++ ) |
|||
{ |
|||
wxPoint point; |
|||
|
|||
if( !aLine.ReadLine() || sscanf( ((char*) aLine), "%d %d", &pt.x, &pt.y ) != 2 ) |
|||
{ |
|||
aErrorMsg.Printf( wxT( "EESchema file polyline struct error at line %d, aborted" ), |
|||
aLine.LineNumber() ); |
|||
aErrorMsg << wxT( "\n" ) << CONV_FROM_UTF8( (char*) aLine ); |
|||
return false; |
|||
} |
|||
|
|||
AddPoint( pt ); |
|||
} |
|||
|
|||
return true; |
|||
} |
|||
|
|||
|
|||
int SCH_POLYLINE::GetPenSize() const |
|||
{ |
|||
int pensize = ( m_Width == 0 ) ? g_DrawDefaultLineThickness : m_Width; |
|||
|
|||
return pensize; |
|||
} |
|||
|
|||
|
|||
void SCH_POLYLINE::Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC, const wxPoint& aOffset, |
|||
int aDrawMode, int aColor ) |
|||
{ |
|||
int color; |
|||
int width = GetPenSize(); |
|||
|
|||
if( aColor >= 0 ) |
|||
color = aColor; |
|||
else |
|||
color = ReturnLayerColor( m_Layer ); |
|||
|
|||
GRSetDrawMode( aDC, aDrawMode ); |
|||
|
|||
if( m_Layer == LAYER_BUS ) |
|||
{ |
|||
width *= 3; |
|||
} |
|||
|
|||
GRMoveTo( m_PolyPoints[0].x, m_PolyPoints[0].y ); |
|||
|
|||
if( m_Layer == LAYER_NOTES ) |
|||
{ |
|||
for( unsigned i = 1; i < GetCornerCount(); i++ ) |
|||
GRDashedLineTo( &aPanel->m_ClipBox, aDC, m_PolyPoints[i].x + aOffset.x, |
|||
m_PolyPoints[i].y + aOffset.y, width, color ); |
|||
} |
|||
else |
|||
{ |
|||
for( unsigned i = 1; i < GetCornerCount(); i++ ) |
|||
GRLineTo( &aPanel->m_ClipBox, aDC, m_PolyPoints[i].x + aOffset.x, |
|||
m_PolyPoints[i].y + aOffset.y, width, color ); |
|||
} |
|||
} |
|||
|
|||
|
|||
void SCH_POLYLINE::Mirror_X( int aXaxis_position ) |
|||
{ |
|||
for( unsigned ii = 0; ii < GetCornerCount(); ii++ ) |
|||
{ |
|||
m_PolyPoints[ii].y -= aXaxis_position; |
|||
NEGATE( m_PolyPoints[ii].y ); |
|||
m_PolyPoints[ii].y = aXaxis_position; |
|||
} |
|||
} |
|||
|
|||
|
|||
void SCH_POLYLINE::Mirror_Y( int aYaxis_position ) |
|||
{ |
|||
for( unsigned ii = 0; ii < GetCornerCount(); ii++ ) |
|||
{ |
|||
m_PolyPoints[ii].x -= aYaxis_position; |
|||
NEGATE( m_PolyPoints[ii].x ); |
|||
m_PolyPoints[ii].x = aYaxis_position; |
|||
} |
|||
} |
|||
|
|||
|
|||
void SCH_POLYLINE::Rotate( wxPoint rotationPoint ) |
|||
{ |
|||
for( unsigned ii = 0; ii < GetCornerCount(); ii++ ) |
|||
{ |
|||
RotatePoint( &m_PolyPoints[ii], rotationPoint, 900 ); |
|||
} |
|||
} |
|||
|
|||
|
|||
bool SCH_POLYLINE::doHitTest( const wxPoint& aPoint, int aAccuracy, SCH_FILTER_T aFilter ) const |
|||
{ |
|||
if( !( aFilter & ( DRAW_ITEM_T | WIRE_T | BUS_T ) ) ) |
|||
return false; |
|||
|
|||
for( size_t i = 0; i < m_PolyPoints.size() - 1; i++ ) |
|||
{ |
|||
if( TestSegmentHit( aPoint, m_PolyPoints[i], m_PolyPoints[i + 1], aAccuracy ) ) |
|||
return true; |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
|
|||
|
|||
bool SCH_POLYLINE::doHitTest( const EDA_Rect& aRect, bool aContained, int aAccuracy ) const |
|||
{ |
|||
EDA_Rect rect = aRect; |
|||
|
|||
rect.Inflate( aAccuracy ); |
|||
|
|||
if( aContained ) |
|||
return rect.Contains( GetBoundingBox() ); |
|||
|
|||
return rect.Intersects( GetBoundingBox() ); |
|||
} |
@ -0,0 +1,104 @@ |
|||
/** |
|||
* @file sch_polyline.h |
|||
* |
|||
*/ |
|||
|
|||
#ifndef _SCH_POLYLINE_H_ |
|||
#define _SCH_POLYLINE_H_ |
|||
|
|||
|
|||
#include "sch_item_struct.h" |
|||
|
|||
|
|||
class SCH_POLYLINE : public SCH_ITEM |
|||
{ |
|||
public: |
|||
int m_Width; /* Thickness */ |
|||
std::vector<wxPoint> m_PolyPoints; // list of points (>= 2) |
|||
|
|||
public: |
|||
SCH_POLYLINE( int layer = LAYER_NOTES ); |
|||
|
|||
SCH_POLYLINE( const SCH_POLYLINE& aPolyLine ); |
|||
|
|||
~SCH_POLYLINE(); |
|||
|
|||
virtual wxString GetClass() const |
|||
{ |
|||
return wxT( "SCH_POLYLINE" ); |
|||
} |
|||
|
|||
virtual void Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC, const wxPoint& aOffset, |
|||
int aDrawMode, int aColor = -1 ); |
|||
|
|||
/** |
|||
* Function Save |
|||
* writes the data structures for this object out to a FILE in "*.sch" |
|||
* format. |
|||
* @param aFile The FILE to write to. |
|||
* @return bool - true if success writing else false. |
|||
*/ |
|||
bool Save( FILE* aFile ) const; |
|||
|
|||
/** |
|||
* Load schematic poly line entry from \a aLine in a .sch file. |
|||
* |
|||
* @param aLine - Essentially this is file to read schematic poly line from. |
|||
* @param aErrorMsg - Description of the error if an error occurs while loading the |
|||
* schematic poly line. |
|||
* @return True if the schematic poly line loaded successfully. |
|||
*/ |
|||
virtual bool Load( LINE_READER& aLine, wxString& aErrorMsg ); |
|||
|
|||
/** |
|||
* Function AddPoint |
|||
* add a corner to m_PolyPoints |
|||
*/ |
|||
void AddPoint( const wxPoint& point ) |
|||
{ |
|||
m_PolyPoints.push_back( point ); |
|||
} |
|||
|
|||
/** |
|||
* Function GetCornerCount |
|||
* @return the number of corners |
|||
*/ |
|||
|
|||
unsigned GetCornerCount() const { return m_PolyPoints.size(); } |
|||
|
|||
/** |
|||
* Function GetPenSize |
|||
* @return the size of the "pen" that be used to draw or plot this item |
|||
*/ |
|||
virtual int GetPenSize() const; |
|||
|
|||
/** |
|||
* Function Move |
|||
* moves an item to a new position by \a aMoveVector. |
|||
* @param aMoveVector = the displacement vector |
|||
*/ |
|||
virtual void Move( const wxPoint& aMoveVector ) |
|||
{ |
|||
for( unsigned ii = 0; ii < GetCornerCount(); ii++ ) |
|||
m_PolyPoints[ii] += aMoveVector; |
|||
} |
|||
|
|||
/** |
|||
* Function Mirror_Y |
|||
* mirrors an item relative to \a aYaxis_position. |
|||
* @param aYaxis_position The y axis position to mirror around. |
|||
*/ |
|||
virtual void Mirror_Y( int aYaxis_position ); |
|||
|
|||
virtual void Mirror_X( int aXaxis_position ); |
|||
|
|||
virtual void Rotate( wxPoint rotationPoint ); |
|||
|
|||
private: |
|||
virtual bool doHitTest( const wxPoint& aPoint, int aAccuracy, SCH_FILTER_T aFilter ) const; |
|||
virtual bool doHitTest( const EDA_Rect& aRect, bool aContained, int aAccuracy ) const; |
|||
virtual EDA_ITEM* doClone() const; |
|||
}; |
|||
|
|||
|
|||
#endif // _SCH_POLYLINE_H_ |
Write
Preview
Loading…
Cancel
Save
Reference in new issue