30#include <wx/translation.h>
80 SetIcon( BITMAPS::add_line2bus );
114 if( !connection || !connection->
IsBus() || connection->
Members().empty() )
129 for(
const std::shared_ptr<SCH_CONNECTION>& member : connection->
Members() )
132 wxString
name = member->FullLocalName();
134 if( member->Type() == CONNECTION_TYPE::BUS )
139 for(
const std::shared_ptr<SCH_CONNECTION>& sub_member : member->Members() )
142 name = sub_member->FullLocalName();
148 Append(
id,
name, wxEmptyString );
174 m_inDrawingTool( false )
190 const auto busGetter = [
this]()
195 std::shared_ptr<BUS_UNFOLD_MENU>
196 busUnfoldMenu = std::make_shared<BUS_UNFOLD_MENU>( busGetter );
197 busUnfoldMenu->SetTool(
this );
198 m_menu->RegisterSubMenu( busUnfoldMenu );
200 std::shared_ptr<BUS_UNFOLD_MENU> selBusUnfoldMenu = std::make_shared<BUS_UNFOLD_MENU>( busGetter );
217 auto belowRootSheetCondition =
234 auto& ctxMenu =
m_menu->GetMenu();
241 ctxMenu.AddSeparator( 10 );
252 ctxMenu.AddSeparator( 100 );
263 ctxMenu.AddSeparator( 200 );
323 wxString* netPtr = aEvent.
Parameter<wxString*>();
337 const auto busGetter = [
this]()
351 std::optional<int>
id = evt->GetCommandId();
353 if(
id && ( *
id > 0 ) )
354 net = *evt->Parameter<wxString*>();
394 const std::optional<VECTOR2I>& aPos )
401 if ( bus ==
nullptr )
403 wxASSERT_MSG(
false, wxString::Format(
"Couldn't find the originating bus line (but had a net: %s )",
434 std::vector<DANGLING_END_ITEM> endPointsByType;
437 item->GetEndPoints( endPointsByType );
439 std::vector<DANGLING_END_ITEM> endPointsByPos = endPointsByType;
459 if(
pin->GetPosition() == aPosition )
473 wxCHECK_RET( aSegments.first && aSegments.second,
474 wxT(
"Cannot compute break point of NULL line segment." ) );
477 SCH_LINE* segment = aSegments.first;
478 SCH_LINE* nextSegment = aSegments.second;
481 int xDir =
delta.x > 0 ? 1 : -1;
482 int yDir =
delta.y > 0 ? 1 : -1;
485 bool preferHorizontal;
501 SHEET_SIDE force = connectedPin ? connectedPin->
GetSide() : SHEET_SIDE::UNDEFINED;
503 if( force == SHEET_SIDE::LEFT || force == SHEET_SIDE::RIGHT )
507 int direction = ( force == SHEET_SIDE::LEFT ) ? -1 : 1;
508 aPosition.
x +=
KiROUND(
getView()->GetGAL()->GetGridSize().x * direction );
511 preferHorizontal =
true;
512 preferVertical =
false;
516 auto breakVertical = [&]()
mutable
524 midPoint.
y = aPosition.
y - yDir * abs(
delta.x );
528 midPoint.
x = aPosition.
x;
534 midPoint.
y = aPosition.
y;
539 auto breakHorizontal = [&]()
mutable
546 midPoint.
x = aPosition.
x - xDir * abs(
delta.y );
552 midPoint.
y = aPosition.
y;
556 midPoint.
x = aPosition.
x;
566 else if( preferHorizontal )
576 if( mode == LINE_MODE::LINE_MODE_45 && !posture
580 preferVertical =
false;
581 preferHorizontal =
false;
583 else if( mode == LINE_MODE::LINE_MODE_45 && posture
584 && ( ( abs( deltaMidpoint.
x ) > abs(
delta.x ) )
585 || ( abs( deltaMidpoint.
y ) > abs(
delta.y ) ) ) )
587 preferVertical =
false;
588 preferHorizontal =
false;
591 if( !preferHorizontal && !preferVertical )
606 int aType,
bool aQuitOnDraw )
614 static bool posture =
false;
677 bool twoSegments = currentMode != LINE_MODE::LINE_MODE_FREE;
681 && evt->HasPosition() && evt->Matches( aTool );
686 grid.SetUseGrid(
getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
697 VECTOR2D eventPosition = evt->HasPosition() ? evt->Position()
700 VECTOR2I cursorPos =
grid.BestSnapAnchor( eventPosition, gridType, segment );
704 if( currentMode != lastMode )
707 if( segment && currentMode == LINE_MODE::LINE_MODE_FREE &&
m_wires.size() >= 2 )
717 else if( segment && lastMode == LINE_MODE::LINE_MODE_FREE )
730 lastMode = currentMode;
736 if( evt->IsCancelInteractive() )
756 else if( evt->IsActivate() && !isSyntheticClick )
761 evt->SetPassEvent(
false );
765 if( evt->IsMoveTool() )
786 aCommit.
Push(
_(
"Draw Wires" ) );
799 || ( segment && evt->IsDblClick(
BUT_LEFT ) )
800 || isSyntheticClick )
817 else if( !segment->
IsNull()
827 aCommit.
Push(
_(
"Draw Wires" ) );
837 int placedSegments = 1;
842 if( currentMode == LINE_MODE::LINE_MODE_45 )
847 for(
int i = 0; i < placedSegments; i++ )
860 if( evt->IsDblClick(
BUT_LEFT ) && segment )
862 if( twoSegments &&
m_wires.size() >= 2 )
865 currentMode, posture );
871 aCommit.
Push(
_(
"Draw Wires" ) );
893 bool flipX = ( cursor_delta.
x < 0 );
894 bool flipY = ( cursor_delta.
y < 0 );
900 int ySign = flipY ? -1 : 1;
901 int xSign = flipX ? -1 : 1;
926 if( twoSegments &&
m_wires.size() >= 2 )
929 currentMode, posture );
939 if( !wire->IsNull() )
947 if( ( currentMode == LINE_MODE::LINE_MODE_FREE &&
m_wires.size() > 1 )
948 || ( LINE_MODE::LINE_MODE_90 &&
m_wires.size() > 2 ) )
961 if( twoSegments &&
m_wires.size() >= 2 )
964 currentMode, posture );
973 if( !wire->IsNull() )
994 if( currentMode == LINE_MODE::LINE_MODE_90 )
1009 if( !wire->IsNull() )
1030 contextMenuPos = cursorPos;
1038 wxASSERT_MSG( !segment,
"Bus unfold event received when already drawing!" );
1041 wxString net = *evt->Parameter<wxString*>();
1042 segment =
doUnfoldBus( aCommit, net, contextMenuPos );
1068 evt->SetPassEvent();
1110 m_wires.push_back( aSegment );
1120 m_wires.push_back( aSegment );
1158 if( next_it ==
m_wires.end() )
1190 std::vector<VECTOR2I> new_ends;
1198 std::vector<VECTOR2I> tmpends = wire->GetConnectionPoints();
1200 new_ends.insert( new_ends.end(), tmpends.begin(), tmpends.end() );
1202 for(
const VECTOR2I& pt : connections )
1205 new_ends.push_back( pt );
1208 aCommit.
Added( wire, screen );
1227 for(
size_t ii = 1; ii <
m_wires.size(); ++ii )
1251 std::vector<SCH_ITEM*> symbols;
1254 symbols.push_back( symbol );
1258 std::vector<VECTOR2I> pts = symbol->GetConnectionPoints();
1260 if( pts.size() > 2 )
1263 for(
auto pt = pts.begin(); pt != pts.end(); pt++ )
1265 for(
auto secondPt = pt + 1; secondPt != pts.end(); secondPt++ )
1270 for(
const VECTOR2I& pt : new_ends )
1280 item->ClearEditFlags();
1289 std::set<SCH_LINE*> lines;
1293 lines.insert(
static_cast<SCH_LINE*
>( item ) );
1295 for(
unsigned ii = 0; ii < aSelection->
GetSize(); ii++ )
1308 std::vector<VECTOR2I> conn_pts;
1313 conn_pts.push_back( pt );
1315 if( conn_pts.size() > 2 )
1319 if( conn_pts.size() == 2 )
1331 std::deque<EDA_ITEM*> allItems;
1335 allItems.push_back( item );
1339 static_cast<SCH_GROUP*
>( item )->RunOnChildren(
1342 allItems.push_back( child );
1343 }, RECURSE_MODE::RECURSE );
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
static TOOL_ACTION doDelete
static TOOL_ACTION selectionClear
Clear the current selection.
static TOOL_ACTION refreshPreview
static TOOL_ACTION finishInteractive
COMMIT & Added(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Notify observers that aItem has been added.
static void sort_dangling_end_items(std::vector< DANGLING_END_ITEM > &aItemListByType, std::vector< DANGLING_END_ITEM > &aItemListByPos)
Both contain the same information.
void ShowInfoBarMsg(const wxString &aMsg, bool aShowCloseButton=false)
Show the WX_INFOBAR displayed on the top of the canvas with a message and an info icon on the left of...
WX_INFOBAR * GetInfoBar()
void SetCurrentCursor(KICURSOR aCursor)
Set the current cursor shape for this panel.
A base class for most all the KiCad significant classes used in schematics and boards.
virtual void ClearEditFlags()
void SetFlags(EDA_ITEM_FLAGS aMask)
KICAD_T Type() const
Returns the type of object.
virtual void SetParent(EDA_ITEM *aParent)
void SetTextSize(VECTOR2I aNewSize, bool aEnforceMinTextSize=true)
EE_TYPE Overlapping(const BOX2I &aRect) const
EE_TYPE OfType(KICAD_T aType) const
bool GetGridSnapping() const
An interface for classes handling user events controlling the view behavior such as zooming,...
virtual void CaptureCursor(bool aEnabled)
Force the cursor to stay within the drawing panel area.
virtual void ForceCursorPosition(bool aEnabled, const VECTOR2D &aPosition=VECTOR2D(0, 0))
Place the cursor immediately at a given point.
virtual void ShowCursor(bool aEnabled)
Enable or disables display of cursor.
virtual void WarpMouseCursor(const VECTOR2D &aPosition, bool aWorldCoordinates=false, bool aWarpView=false)=0
If enabled (.
virtual void SetCrossHairCursorPosition(const VECTOR2D &aPosition, bool aWarpView=true)=0
Move the graphic crosshair cursor to the requested position expressed in world coordinates.
virtual VECTOR2D GetMousePosition(bool aWorldCoordinates=true) const =0
Return the current mouse pointer position.
virtual void SetAutoPan(bool aEnabled)
Turn on/off auto panning (this feature is used when there is a tool active (eg.
void ShowPreview(bool aShow=true)
GAL * GetGAL() const
Return the #GAL this view is using to draw graphical primitives.
void AddToPreview(VIEW_ITEM *aItem, bool aTakeOwnership=true)
These are loaded from Eeschema settings but then overwritten by the project settings.
Holds all the data relating to one schematic.
void CleanUp(SCH_COMMIT *aCommit, SCH_SCREEN *aScreen=nullptr)
Perform routine schematic cleaning including breaking wire and buses and deleting identical objects s...
SCH_SHEET_PATH & CurrentSheet() const
static TOOL_ACTION rotateCCW
static TOOL_ACTION placeClassLabel
static TOOL_ACTION clearHighlight
static TOOL_ACTION placeGlobalLabel
static TOOL_ACTION leaveSheet
static TOOL_ACTION breakWire
static TOOL_ACTION drawLines
static TOOL_ACTION placeHierLabel
static TOOL_ACTION selectConnection
If current selection is a wire or bus, expand to entire connection.
static TOOL_ACTION placeLabel
static TOOL_ACTION drawWire
static TOOL_ACTION rotateCW
static TOOL_ACTION placeJunction
static TOOL_ACTION selectNode
Select the junction, wire or bus segment under the cursor.
static TOOL_ACTION unfoldBus
static TOOL_ACTION drawBus
static TOOL_ACTION undoLastSegment
static TOOL_ACTION switchSegmentPosture
void RemoveFromScreen(EDA_ITEM *aItem, SCH_SCREEN *aScreen) override
Remove an item from the screen (and view) aScreen is the screen the item is located on,...
SCH_DRAW_PANEL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
EESCHEMA_SETTINGS * eeconfig() const
void AddToScreen(EDA_ITEM *aItem, SCH_SCREEN *aScreen=nullptr) override
Add an item to the screen (and view) aScreen is the screen the item is located on,...
void SetSize(const VECTOR2I &aSize)
void SetEndDangling(bool aDanglingState)
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Class for a wire to bus entry.
bool UpdateDanglingState(std::vector< DANGLING_END_ITEM > &aItemListByType, std::vector< DANGLING_END_ITEM > &aItemListByPos, const SCH_SHEET_PATH *aPath=nullptr) override
Test the schematic item to aItemList to check if it's dangling state has changed.
virtual void Push(const wxString &aMessage=wxT("A commit"), int aCommitFlags=0) override
Execute the changes.
Each graphical item can have a SCH_CONNECTION describing its logical connection (to a bus or net).
const std::vector< std::shared_ptr< SCH_CONNECTION > > & Members() const
static wxString PrintBusForUI(const wxString &aString)
Schematic editor (Eeschema) main window.
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
SCH_SHEET_PATH & GetCurrentSheet() const
SCHEMATIC & Schematic() const
const wxString & GetHighlightedConnection() const
void UpdateItem(EDA_ITEM *aItem, bool isAddOrDelete=false, bool aUpdateRtree=false) override
Mark an item for refresh.
bool TrimWire(SCH_COMMIT *aCommit, const VECTOR2I &aStart, const VECTOR2I &aEnd)
If any single wire passes through both points, remove the portion between the two points,...
void AddCopyForRepeatItem(const SCH_ITEM *aItem)
SCH_JUNCTION * AddJunction(SCH_COMMIT *aCommit, SCH_SCREEN *aScreen, const VECTOR2I &aPos)
void SaveCopyForRepeatItem(const SCH_ITEM *aItem)
Clone aItem and owns that clone in this container.
A set of SCH_ITEMs (i.e., without duplicates).
Base class for any item which can be embedded within the SCHEMATIC container class,...
SCH_ITEM * Duplicate(bool addToParentGroup, SCH_COMMIT *aCommit=nullptr, bool doClone=false) const
Routine to create a new copy of given item.
virtual bool IsConnectable() const
SCH_LAYER_ID GetLayer() const
Return the layer this item is on.
SCH_CONNECTION * Connection(const SCH_SHEET_PATH *aSheet=nullptr) const
Retrieve the connection associated with this object in the given sheet.
virtual std::vector< VECTOR2I > GetConnectionPoints() const
Add all the connection points for this item to aPoints.
void SetIsDangling(bool aIsDangling)
SPIN_STYLE GetSpinStyle() const
void SetPosition(const VECTOR2I &aPosition) override
void Rotate90(bool aClockwise) override
virtual void SetSpinStyle(SPIN_STYLE aSpinStyle)
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Segment description base class to describe items which have 2 end points (track, wire,...
void SetStartPoint(const VECTOR2I &aPosition)
VECTOR2I GetEndPoint() const
VECTOR2I GetStartPoint() const
SEG GetSeg() const
Get the geometric aspect of the wire as a SEG.
SCH_LINE * MergeOverlap(SCH_SCREEN *aScreen, SCH_LINE *aLine, bool aCheckJunctions)
Check line against aLine to see if it overlaps and merge if it does.
void SetEndPoint(const VECTOR2I &aPosition)
SCH_LINE * GetLine(const VECTOR2I &aPosition, int aAccuracy=0, int aLayer=LAYER_NOTES, SCH_LINE_TEST_T aSearchType=ENTIRE_LENGTH_T) const
Return a line item located at aPosition.
EE_RTREE & Items()
Get the full RTree, usually for iterating.
bool IsTerminalPoint(const VECTOR2I &aPosition, int aLayer) const
Test if aPosition is a connection point on aLayer.
bool IsExplicitJunctionNeeded(const VECTOR2I &aPosition) const
Indicate that a junction dot is necessary at the given location, and does not yet exist.
std::vector< VECTOR2I > GetNeededJunctions(const std::deque< EDA_ITEM * > &aItems) const
Return the unique set of points belonging to aItems where a junction is needed.
std::vector< VECTOR2I > GetConnections() const
Collect a unique list of all possible connection points in the schematic.
BOX2I GetBoundingBox() const override
SCH_SCREEN * LastScreen()
SCH_SHEET * Last() const
Return a pointer to the last SCH_SHEET of the list.
Define a sheet pin (label) used in sheets to create hierarchical schematics.
SHEET_SIDE GetSide() const
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
std::vector< SCH_SHEET_PIN * > & GetPins()
VECTOR2I GetPosition() const override
const VECTOR2I NearestPoint(const VECTOR2I &aP) const
Compute a point on the segment (this) that is closest to point aP.
static SELECTION_CONDITION MoreThan(int aNumber)
Create a functor that tests if the number of selected items is greater than the value given as parame...
static bool Idle(const SELECTION &aSelection)
Test if there no items selected or being edited.
static bool ShowAlways(const SELECTION &aSelection)
The default condition function (always returns true).
static SELECTION_CONDITION OnlyTypes(std::vector< KICAD_T > aTypes)
Create a functor that tests if the selected items are only of given types.
virtual KIGFX::VIEW_ITEM * GetItem(unsigned int aIdx) const override
virtual unsigned int GetSize() const override
Return the number of stored items.
std::deque< EDA_ITEM * > & Items()
void Dismiss() override
Dismisses the infobar and updates the containing layout and AUI manager (if one is provided).
#define IS_NEW
New item, just created.
#define SKIP_STRUCT
flag indicating that the structure should be ignored
#define IS_MOVING
Item being moved.
@ ID_POPUP_SCH_UNFOLD_BUS_END
@ ID_POPUP_SCH_UNFOLD_BUS
bool signbit(T v)
Integral version of std::signbit that works all compilers.
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Class to handle a set of SCH_ITEMs.
SHEET_SIDE
Define the edge of the sheet that the sheet pin is positioned.
bool label_placed
True if user has placed the net label.
wxString net_name
Net label for the unfolding operation.
bool flipY
True if the bus entry should be flipped in the y-axis.
SCH_BUS_WIRE_ENTRY * entry
bool flipX
True if the bus entry should be flipped in the x-axis.
VECTOR2I origin
Origin (on the bus) of the unfold.
bool in_progress
True if bus unfold operation is running.
Settings for bus unfolding that are persistent across invocations of the tool.
SPIN_STYLE label_spin_style
bool IsPointOnSegment(const VECTOR2I &aSegStart, const VECTOR2I &aSegEnd, const VECTOR2I &aTestPoint)
Test if aTestPoint is on line defined by aSegStart and aSegEnd.
VECTOR2< int32_t > VECTOR2I
VECTOR2< double > VECTOR2D