KiCad PCB EDA Suite
EDIT_POINTS_FACTORY Class Reference

Static Public Member Functions

static std::shared_ptr< EDIT_POINTSMake (EDA_ITEM *aItem, SCH_BASE_FRAME *frame)
 
static std::shared_ptr< EDIT_POINTSMake (EDA_ITEM *aItem)
 

Private Member Functions

 EDIT_POINTS_FACTORY ()
 
 EDIT_POINTS_FACTORY ()
 

Detailed Description

Definition at line 66 of file ee_point_editor.cpp.

Constructor & Destructor Documentation

◆ EDIT_POINTS_FACTORY() [1/2]

EDIT_POINTS_FACTORY::EDIT_POINTS_FACTORY ( )
inlineprivate

Definition at line 206 of file ee_point_editor.cpp.

206 {};

◆ EDIT_POINTS_FACTORY() [2/2]

EDIT_POINTS_FACTORY::EDIT_POINTS_FACTORY ( )
inlineprivate

Definition at line 100 of file pl_point_editor.cpp.

100 {};

Member Function Documentation

◆ Make() [1/2]

static std::shared_ptr<EDIT_POINTS> EDIT_POINTS_FACTORY::Make ( EDA_ITEM aItem)
inlinestatic

Definition at line 56 of file pl_point_editor.cpp.

57  {
58  std::shared_ptr<EDIT_POINTS> points = std::make_shared<EDIT_POINTS>( aItem );
59 
60  if( !aItem )
61  return points;
62 
63  // Generate list of edit points based on the item type
64  switch( aItem->Type() )
65  {
66  case WSG_LINE_T:
67  {
68  DS_DRAW_ITEM_LINE* line = static_cast<DS_DRAW_ITEM_LINE*>( aItem );
69  points->AddPoint( line->GetStart() );
70  points->AddPoint( line->GetEnd() );
71  break;
72  }
73  case WSG_RECT_T:
74  {
75  DS_DRAW_ITEM_RECT* rect = static_cast<DS_DRAW_ITEM_RECT*>( aItem );
76  wxPoint topLeft = rect->GetStart();
77  wxPoint botRight = rect->GetEnd();
78 
79  if( topLeft.y > botRight.y )
80  std::swap( topLeft.y, botRight.y );
81 
82  if( topLeft.x > botRight.x )
83  std::swap( topLeft.x, botRight.x );
84 
85  points->AddPoint( (VECTOR2I) topLeft );
86  points->AddPoint( VECTOR2I( botRight.x, topLeft.y ) );
87  points->AddPoint( VECTOR2I( topLeft.x, botRight.y ) );
88  points->AddPoint( (VECTOR2I) botRight );
89  break;
90  }
91  default:
92  points.reset();
93  break;
94  }
95 
96  return points;
97  }
VECTOR2< int > VECTOR2I
Definition: vector2d.h:623
const wxPoint & GetStart() const
Definition: ds_draw_item.h:133
const wxPoint & GetStart() const
Definition: ds_draw_item.h:219
Non filled rectangle with thick segment.
Definition: ds_draw_item.h:205
const wxPoint & GetEnd() const
Definition: ds_draw_item.h:221
const wxPoint & GetEnd() const
Definition: ds_draw_item.h:135
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:112

References DS_DRAW_ITEM_LINE::GetEnd(), DS_DRAW_ITEM_RECT::GetEnd(), DS_DRAW_ITEM_LINE::GetStart(), DS_DRAW_ITEM_RECT::GetStart(), EDA_ITEM::Type(), WSG_LINE_T, WSG_RECT_T, VECTOR2< T >::x, and VECTOR2< T >::y.

◆ Make() [2/2]

static std::shared_ptr<EDIT_POINTS> EDIT_POINTS_FACTORY::Make ( EDA_ITEM aItem,
SCH_BASE_FRAME frame 
)
inlinestatic

Definition at line 69 of file ee_point_editor.cpp.

70  {
71  std::shared_ptr<EDIT_POINTS> points = std::make_shared<EDIT_POINTS>( aItem );
72 
73  if( !aItem )
74  return points;
75 
76  // Generate list of edit points based on the item type
77  switch( aItem->Type() )
78  {
79  case LIB_SHAPE_T:
80  {
81  LIB_SHAPE* shape = static_cast<LIB_SHAPE*>( aItem );
82 
83  switch( shape->GetShape() )
84  {
85  case SHAPE_T::ARC:
86  points->AddPoint( mapCoords( shape->GetPosition() ) );
87  points->AddPoint( mapCoords( shape->GetStart() ) );
88  points->AddPoint( mapCoords( shape->GetEnd() ) );
89  break;
90 
91  case SHAPE_T::CIRCLE:
92  points->AddPoint( mapCoords( shape->GetPosition() ) );
93  points->AddPoint( mapCoords( shape->GetEnd() ) );
94  break;
95 
96  case SHAPE_T::RECT:
97  {
98  // point editor works only with rectangles having width and height > 0
99  // Some symbols can have rectangles with width or height < 0
100  // So normalize the size:
101  BOX2I dummy;
102  dummy.SetOrigin( mapCoords( shape->GetPosition() ) );
103  dummy.SetEnd( mapCoords( shape->GetEnd() ) );
104  dummy.Normalize();
105  VECTOR2I topLeft = dummy.GetPosition();
106  VECTOR2I botRight = dummy.GetEnd();
107 
108  points->AddPoint( topLeft );
109  points->AddPoint( VECTOR2I( botRight.x, topLeft.y ) );
110  points->AddPoint( VECTOR2I( topLeft.x, botRight.y ) );
111  points->AddPoint( botRight );
112  }
113  break;
114 
115  case SHAPE_T::POLY:
116  for( const VECTOR2I& pt : shape->GetPolyShape().Outline( 0 ).CPoints() )
117  points->AddPoint( mapCoords( pt ) );
118 
119  break;
120 
121  case SHAPE_T::BEZIER:
122  // TODO
123  break;
124 
125  default:
126  wxFAIL_MSG( "EDIT_POINTS_FACTORY::Make not implemented for "
127  + shape->SHAPE_T_asString() );
128  }
129  }
130  break;
131 
132  case SCH_SHEET_T:
133  {
134  SCH_SHEET* sheet = (SCH_SHEET*) aItem;
135  wxPoint topLeft = sheet->GetPosition();
136  wxPoint botRight = sheet->GetPosition() + sheet->GetSize();
137 
138  points->AddPoint( (wxPoint) topLeft );
139  points->AddPoint( wxPoint( botRight.x, topLeft.y ) );
140  points->AddPoint( wxPoint( topLeft.x, botRight.y ) );
141  points->AddPoint( (wxPoint) botRight );
142  }
143  break;
144 
145  case SCH_BITMAP_T:
146  {
147  SCH_BITMAP* bitmap = (SCH_BITMAP*) aItem;
148  wxPoint topLeft = bitmap->GetPosition() - bitmap->GetSize() / 2;
149  wxPoint botRight = bitmap->GetPosition() + bitmap->GetSize() / 2;
150 
151  points->AddPoint( (wxPoint) topLeft );
152  points->AddPoint( wxPoint( botRight.x, topLeft.y ) );
153  points->AddPoint( wxPoint( topLeft.x, botRight.y ) );
154  points->AddPoint( (wxPoint) botRight );
155  }
156  break;
157 
158  case SCH_LINE_T:
159  {
160  SCH_LINE* line = (SCH_LINE*) aItem;
161  std::pair<EDA_ITEM*, int> connectedStart = { nullptr, STARTPOINT };
162  std::pair<EDA_ITEM*, int> connectedEnd = { nullptr, STARTPOINT };
163 
164  for( SCH_ITEM* test : frame->GetScreen()->Items().OfType( SCH_LINE_T ) )
165  {
166  if( test->GetLayer() != LAYER_NOTES )
167  continue;
168 
169  if( test == aItem )
170  continue;
171 
172  SCH_LINE* testLine = static_cast<SCH_LINE*>( test );
173 
174  if( testLine->GetStartPoint() == line->GetStartPoint() )
175  {
176  connectedStart = { testLine, STARTPOINT };
177  }
178  else if( testLine->GetEndPoint() == line->GetStartPoint() )
179  {
180  connectedStart = { testLine, ENDPOINT };
181  }
182  else if( testLine->GetStartPoint() == line->GetEndPoint() )
183  {
184  connectedEnd = { testLine, STARTPOINT };
185  }
186  else if( testLine->GetEndPoint() == line->GetEndPoint() )
187  {
188  connectedEnd = { testLine, ENDPOINT };
189  }
190  }
191 
192  points->AddPoint( line->GetStartPoint(), connectedStart );
193  points->AddPoint( line->GetEndPoint(), connectedEnd );
194  }
195  break;
196 
197  default:
198  points.reset();
199  break;
200  }
201 
202  return points;
203  }
EE_TYPE OfType(KICAD_T aType) const
Definition: sch_rtree.h:230
#define STARTPOINT
When a line is selected, these flags indicate which.
wxPoint GetStartPoint() const
Definition: sch_line.h:90
const wxPoint & GetStart() const
Return the starting point of the graphic.
Definition: eda_shape.h:97
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
#define ENDPOINT
ends. (Used to support dragging.)
virtual wxPoint GetPosition() const
Definition: eda_item.h:251
wxPoint GetPosition() const override
Definition: sch_bitmap.h:136
VECTOR2< int > VECTOR2I
Definition: vector2d.h:623
static LIB_SYMBOL * dummy()
Used to draw a dummy shape when a LIB_SYMBOL is not found in library.
Definition: sch_symbol.cpp:72
const wxPoint & GetEnd() const
Return the ending point of the graphic.
Definition: eda_shape.h:122
wxSize GetSize() const
Definition: sch_bitmap.cpp:125
const std::vector< VECTOR2I > & CPoints() const
SHAPE_LINE_CHAIN & Outline(int aIndex)
wxString SHAPE_T_asString() const
Definition: eda_shape.cpp:71
static VECTOR2D mapCoords(const wxPoint &aCoord)
wxPoint GetPosition() const override
Definition: sch_sheet.h:382
Object to handle a bitmap image that can be inserted in a schematic.
Definition: sch_bitmap.h:40
SHAPE_POLY_SET & GetPolyShape()
Definition: eda_shape.h:207
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:54
Segment description base class to describe items which have 2 end points (track, wire,...
Definition: sch_line.h:37
wxSize GetSize() const
Definition: sch_sheet.h:107
EE_RTREE & Items()
Gets the full RTree, usually for iterating.
Definition: sch_screen.h:110
SHAPE_T GetShape() const
Definition: eda_shape.h:92
wxPoint GetPosition() const override
Definition: lib_shape.h:86
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:182
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:112
wxPoint GetEndPoint() const
Definition: sch_line.h:93

References ARC, BEZIER, CIRCLE, SHAPE_LINE_CHAIN::CPoints(), dummy(), ENDPOINT, EDA_SHAPE::GetEnd(), SCH_LINE::GetEndPoint(), EDA_SHAPE::GetPolyShape(), LIB_SHAPE::GetPosition(), SCH_BITMAP::GetPosition(), EDA_ITEM::GetPosition(), SCH_SHEET::GetPosition(), SCH_BASE_FRAME::GetScreen(), EDA_SHAPE::GetShape(), SCH_BITMAP::GetSize(), SCH_SHEET::GetSize(), EDA_SHAPE::GetStart(), SCH_LINE::GetStartPoint(), SCH_SCREEN::Items(), LAYER_NOTES, LIB_SHAPE_T, KIGFX::mapCoords(), EE_RTREE::OfType(), SHAPE_POLY_SET::Outline(), POLY, RECT, SCH_BITMAP_T, SCH_LINE_T, SCH_SHEET_T, EDA_SHAPE::SHAPE_T_asString(), STARTPOINT, EDA_ITEM::Type(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by EE_POINT_EDITOR::Main(), PL_POINT_EDITOR::Main(), and EE_POINT_EDITOR::updatePoints().


The documentation for this class was generated from the following files: