25#include <unordered_set>
74#include <wx/filedlg.h>
104 auto belowRootSheetCondition =
107 return m_frame->GetCurrentSheet().Last() != &
m_frame->Schematic().Root();
117 auto inDrawingRuleArea =
144 bool placeOneOnly = symbol !=
nullptr;
147 std::vector<PICKED_SYMBOL>* historyList =
nullptr;
148 bool ignorePrimePosition =
false;
152 bool keepSymbol =
false;
181 filter.FilterPowerSymbols(
true );
185 wxFAIL_MSG(
"PlaceSymbol(): unexpected request" );
200 m_view->AddToPreview( aSymbol,
false );
221 existingRefs.
Clear();
249 for(
size_t i = 0; i < refs.
GetCount(); i++ )
250 existingRefs.
AddItem( refs[i] );
254 m_frame->GetCurrentSheet().UpdateAllScreenReferences();
277 existingRefs.
AddItem( placedSymbolReference );
289 ignorePrimePosition =
true;
297 grid.SetUseGrid(
getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
303 bool isSyntheticClick = symbol && evt->IsActivate() && evt->HasPosition() && evt->Matches( aEvent );
305 if( evt->IsCancelInteractive() || ( symbol && evt->IsAction( &
ACTIONS::undo ) ) )
307 m_frame->GetInfoBar()->Dismiss();
324 else if( evt->IsActivate() && !isSyntheticClick )
326 if( symbol && evt->IsMoveTool() )
329 evt->SetPassEvent(
false );
335 m_frame->ShowInfoBarMsg(
_(
"Press <ESC> to cancel symbol creation." ) );
336 evt->SetPassEvent(
false );
340 if( evt->IsMoveTool() )
343 frame()->PushTool( originalEvent );
359 std::set<UTF8> unique_libid;
360 std::vector<PICKED_SYMBOL> alreadyPlaced;
380 alreadyPlaced.push_back( pickedSymbol );
386 bool footprintPreviews =
m_frame->eeconfig()->m_Appearance.footprint_preview;
401 if( evt->IsPrime() && !ignorePrimePosition )
428 if( keywords.Contains( wxT(
"global power" ) ) )
430 keywords.Replace( wxT(
"global power" ), wxT(
"local power" ) );
436 if( desc.Contains( wxT(
"global label" ) ) )
438 desc.Replace( wxT(
"global label" ), wxT(
"local label" ) );
451 symbol =
new SCH_SYMBOL( *libSymbol, &
m_frame->GetCurrentSheet(), sel, cursorPos,
458 existingRefs.
AddItem( placedSymbolReference );
461 if(
m_frame->eeconfig()->m_AutoplaceFields.enable )
473 m_frame->AddToScreen( symbol, screen );
475 if(
m_frame->eeconfig()->m_AutoplaceFields.enable )
478 m_frame->SaveCopyForRepeatItem( symbol );
481 commit.
Added( symbol, screen );
487 commit.
Push(
_(
"Place Symbol" ) );
492 if( placeOneOnly && !placeAllUnits )
497 if( keepSymbol || placeAllUnits )
509 const wxString currentRefStr = currentReference.
GetRef();
510 const bool isUnannotated = !currentRefStr.IsEmpty() && currentRefStr.Last() ==
'?';
511 const LIB_ID symLibId = symbol->GetLibId();
514 [&](
int aUnit ) ->
bool
520 return schematic.
Contains( candidate );
526 while( currentReference.
GetUnit() <= symbol->GetUnitCount()
527 && unitOccupied( currentReference.
GetUnit() ) )
532 if( currentReference.
GetUnit() > symbol->GetUnitCount() )
539 if( keepSymbol || currentReference.
GetUnit() > 1 )
545 addSymbol( nextSymbol );
548 if( currentReference.
GetUnit() == 1 )
553 existingRefs.
AddItem( placedSymbolReference );
561 if( placeOneOnly && !symbol )
582 m_frame->SelectUnit( symbol, unit );
591 if( symbol && symbol->GetBodyStyle() != bodyStyle )
593 m_frame->SelectBodyStyle( symbol, bodyStyle );
614 symbol->SetPosition( cursorPos );
616 m_view->AddToPreview( symbol,
false );
617 m_frame->SetMsgPanel( symbol );
665 int requestedUnit = params.
m_Unit;
670 static const std::vector<KICAD_T> symbolTypes = {
SCH_SYMBOL_T };
673 if( selection.
Size() != 1 )
675 m_frame->ShowInfoBarMsg(
_(
"Select a single symbol to place the next unit." ) );
686 if( !symbol->IsMultiUnit() )
688 m_frame->ShowInfoBarMsg(
_(
"This symbol has only one unit." ) );
694 if( missingUnits.empty() )
696 m_frame->ShowInfoBarMsg(
_(
"All units of this symbol are already placed." ) );
702 if( requestedUnit > 0 )
704 if( missingUnits.count( requestedUnit ) == 0 )
706 m_frame->ShowInfoBarMsg(
_(
"Requested unit already placed." ) );
710 nextMissing = requestedUnit;
715 nextMissing = *std::min_element( missingUnits.begin(), missingUnits.end() );
718 std::unique_ptr<SCH_SYMBOL> newSymbol = std::make_unique<SCH_SYMBOL>( *symbol );
724 newSymbol->SetUnitSelection( nextMissing );
725 newSymbol->SetUnit( nextMissing );
726 newSymbol->SetRefProp( symbol->GetRef( &sheetPath,
false ) );
743 std::optional<VECTOR2I> connectionAnchor;
744 std::optional<VECTOR2I> positionAnchor;
747 []( std::optional<VECTOR2I>& aBest,
const VECTOR2I& aCandidate )
749 if( !aBest || aCandidate.y < aBest->y || ( aCandidate.y == aBest->y && aCandidate.x < aBest->x ) )
758 for(
const VECTOR2I& pt : item->GetConnectionPoints() )
759 keepTopLeft( connectionAnchor, pt );
761 keepTopLeft( positionAnchor, item->GetPosition() );
764 return connectionAnchor ? connectionAnchor : positionAnchor;
781 struct RESET_FORCED_CURSOR_GUARD
785 ~RESET_FORCED_CURSOR_GUARD()
791 RESET_FORCED_CURSOR_GUARD forcedCursorGuard{ controls };
793 if( !cfg || !common_settings )
801 std::unique_ptr<DESIGN_BLOCK> designBlock;
802 wxString sheetFileName = wxEmptyString;
804 if( placingDesignBlock )
815 sheetFileName = designBlock->GetSchematicFile();
817 if( sheetFileName.IsEmpty() || !wxFileExists( sheetFileName ) )
819 m_frame->ShowInfoBarError(
_(
"Design block has no schematic to place." ),
true );
826 wxString* importSourceFile = aEvent.
Parameter<wxString*>();
828 if( importSourceFile !=
nullptr )
829 sheetFileName = *importSourceFile;
839 auto placeSheetContents =
855 if( !
m_frame->LoadSheetFromFile( sheetPath.
Last(), &sheetPath, sheetFileName,
true,
856 placingDesignBlock ) )
861 m_frame->SetSheetNumberAndCount();
877 baseName = designBlock->GetLibId().GetLibItemName().wx_str();
878 group->SetDesignBlockLibId( designBlock->GetLibId() );
882 baseName = wxFileName( sheetFileName ).GetName();
900 if( item->Type() ==
SCH_SYMBOL_T && !keepAnnotations && !autoAnnotate )
901 static_cast<SCH_SYMBOL*
>( item )->ClearAnnotation( &sheetPath,
false );
906 if( !item->GetParentGroup() )
909 group->AddItem( item );
911 newItems.emplace_back( item );
914 commit.
Added( item, screen );
936 std::vector<SCH_ITEM*> blockItems =
FlattenGroups( newItems );
944 if( !keepAnnotations || placingDesignBlock )
958 if( placingDesignBlock )
1005 commit.
Push( placingDesignBlock ?
_(
"Add Design Block" )
1006 :
_(
"Import Schematic Sheet Content" ) );
1014 m_frame->UpdateHierarchyNavigator();
1021 if( sheetFileName.IsEmpty() )
1026 if (!placingDesignBlock)
1028 if( sheetFileName.IsEmpty() )
1030 path = wxPathOnly(
m_frame->Prj().GetProjectFullName() );
1031 file = wxEmptyString;
1035 path = wxPathOnly( sheetFileName );
1036 file = wxFileName( sheetFileName ).GetFullName();
1041 wxFileDialog dlg(
m_frame,
_(
"Choose Schematic" ),
path, file,
1045 dlg.SetCustomizeHook( dlgHook );
1049 if( dlg.ShowModal() == wxID_CANCEL )
1052 sheetFileName = dlg.GetPath();
1054 m_frame->GetDesignBlockPane()->UpdateCheckboxes();
1057 if( sheetFileName.IsEmpty() )
1093 grid.SetUseGrid(
getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
1099 bool isSyntheticClick = designBlock && evt->IsActivate() && evt->HasPosition() && evt->Matches( aEvent );
1101 if( evt->IsCancelInteractive() || ( designBlock && evt->IsAction( &
ACTIONS::undo ) ) )
1103 m_frame->GetInfoBar()->Dismiss();
1106 else if( evt->IsActivate() && !isSyntheticClick )
1108 m_frame->GetInfoBar()->Dismiss();
1115 if( placingDesignBlock )
1143 evt->SetPassEvent();
1155 bool immediateMode =
image !=
nullptr;
1156 bool ignorePrimePosition =
false;
1195 m_view->RecacheAllItems();
1220 ignorePrimePosition =
true;
1228 grid.SetUseGrid(
getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
1234 bool isSyntheticClick =
image && evt->IsActivate() && evt->HasPosition() && evt->Matches( aEvent );
1238 m_frame->GetInfoBar()->Dismiss();
1248 else if( evt->IsActivate() && !isSyntheticClick )
1250 if(
image && evt->IsMoveTool() )
1253 evt->SetPassEvent(
false );
1259 m_frame->ShowInfoBarMsg(
_(
"Press <ESC> to cancel image creation." ) );
1260 evt->SetPassEvent(
false );
1264 if( evt->IsMoveTool() )
1267 m_frame->PushTool( originalEvent );
1285 bool cancelled =
false;
1290 cancelled = dlg.ShowModal() != wxID_OK;
1299 if( evt->IsPrime() && !ignorePrimePosition )
1301 cursorPos =
grid.Align( evt->Position() );
1310 wxString fullFilename = dlg.GetPath();
1313 if( wxFileExists( fullFilename ) )
1316 if( !
image || !
image->GetReferenceImage().ReadImageFile( fullFilename ) )
1318 wxMessageBox( wxString::Format(
_(
"Could not load image from '%s'." ), fullFilename ) );
1330 m_view->RecacheAllItems();
1341 commit.
Push(
_(
"Place Image" ) );
1373 evt->SetPassEvent();
1378 image->SetPosition( cursorPos );
1381 m_view->RecacheAllItems();
1394 evt->SetPassEvent();
1417 bool loggedInfoBarError =
false;
1418 wxString description;
1420 bool allowRepeat =
false;
1446 description =
_(
"Add No Connect Flag" );
1453 description =
_(
"Add Junction" );
1459 description =
_(
"Add Wire to Bus Entry" );
1464 wxASSERT_MSG(
false,
"Unknown item type in SCH_DRAWING_TOOLS::SingleClickPlace" );
1503 grid.SetUseGrid(
getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
1505 cursorPos = evt->IsPrime() ? evt->Position() : controls->
GetMousePosition();
1506 cursorPos =
grid.ResolveSnap( cursorPos,
grid.GetItemGrid( previewItem ),
nullptr ).position;
1509 if( evt->IsCancelInteractive() )
1513 else if( evt->IsActivate() )
1515 if( evt->IsMoveTool() )
1518 frame()->PushTool( originalEvent );
1533 commit.
Removed( existingItem, screen );
1534 m_frame->RemoveFromScreen( existingItem, screen );
1535 commit.
Push(
_(
"Remove No Connect Flag" ) );
1544 m_frame->ShowInfoBarError(
_(
"Junction location contains no joinable wires and/or pins." ) );
1545 loggedInfoBarError =
true;
1548 else if( loggedInfoBarError )
1550 m_frame->GetInfoBar()->Dismiss();
1558 lwbTool->
AddJunction( &commit, screen, cursorPos );
1560 m_frame->Schematic().CleanUp( &commit );
1562 commit.
Push( description );
1570 m_frame->AddToScreen( newItem, screen );
1573 m_frame->SaveCopyForRepeatItem( newItem );
1576 commit.
Added( newItem, screen );
1578 m_frame->Schematic().CleanUp( &commit );
1580 commit.
Push( description );
1596 m_frame->SetMsgPanel( previewItem );
1633 std::deque<SCH_ITEM*> strokeItems;
1634 strokeItems.push_back( previewItem );
1649 std::deque<SCH_JUNCTION*> junctions;
1650 junctions.push_back(
static_cast<SCH_JUNCTION*
>( previewItem ) );
1673 evt->SetPassEvent();
1678 evt->SetPassEvent();
1711 wxASSERT( aWire->
IsWire() );
1717 SCH_ITEM* wireDriver = wireConnection->Driver();
1719 if( wireDriver && wireDriver->
IsType( { SCH_LABEL_T, SCH_GLOBAL_LABEL_T } ) )
1720 return wireConnection->LocalName();
1723 return wxEmptyString;
1728 std::list<std::unique_ptr<SCH_LABEL_BASE>>& aLabelList )
1751 labelItem->
GetFields().back().SetItalic(
true );
1752 labelItem->
GetFields().back().SetVisible(
true );
1766 labelItem = globalLabel;
1774 wxFAIL_MSG(
"SCH_DRAWING_TOOLS::createNewLabel() unknown label type" );
1794 if( !netName.IsEmpty() )
1797 labelItem->
SetText( netName );
1832 if( aLabelList.empty() )
1833 aLabelList.push_back( std::unique_ptr<SCH_LABEL_BASE>( labelItem ) );
1847 textItem =
new SCH_TEXT( aPosition );
1882 pin->SetText( std::to_string( aSheet->
GetPins().size() + 1 ) );
1884 pin->SetPosition( aPosition );
1885 pin->ClearSelected();
1909 bool ignorePrimePosition =
false;
1912 wxString description;
1914 std::list<std::unique_ptr<SCH_LABEL_BASE>> itemsToPlace;
1946 else if( isGlobalLabel )
1948 else if( isNetLabel || isClassLabel )
1950 else if( isHierLabel )
1956 auto updatePreview =
1960 m_view->AddToPreview( item,
false );
1963 m_view->AddToPreview( aChild,
false );
1977 while( !itemsToPlace.empty() )
1978 itemsToPlace.erase( itemsToPlace.begin() );
1981 auto prepItemForPlacement =
2013 && ( isText || isGlobalLabel || isHierLabel || isClassLabel || isNetLabel ) )
2016 ignorePrimePosition =
true;
2026 grid.SetUseGrid(
getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
2029 cursorPos =
grid.ResolveSnap( cursorPos, snapGrid, item ).position;
2033 bool isSyntheticClick = item && evt->IsActivate() && evt->HasPosition() && evt->
Matches( aEvent );
2035 if( evt->IsCancelInteractive() || evt->IsAction( &
ACTIONS::undo ) )
2037 m_frame->GetInfoBar()->Dismiss();
2044 else if( evt->IsActivate() && !isSyntheticClick )
2046 if( item && evt->IsMoveTool() )
2049 evt->SetPassEvent(
false );
2055 m_frame->ShowInfoBarMsg(
_(
"Press <ESC> to cancel item creation." ) );
2056 evt->SetPassEvent(
false );
2060 if( evt->IsPointEditor() )
2066 if( evt->IsMoveTool() )
2069 frame()->PushTool( originalEvent );
2087 description =
_(
"Add Text" );
2089 else if( isHierLabel )
2106 itemsToPlace.push_back( std::unique_ptr<SCH_LABEL_BASE>( label ) );
2113 description =
_(
"Add Hierarchical Label" );
2115 else if( isNetLabel )
2118 description =
_(
"Add Label" );
2120 else if( isGlobalLabel )
2123 description =
_(
"Add Label" );
2125 else if( isClassLabel )
2128 description =
_(
"Add Label" );
2130 else if( isSheetPin )
2135 if( !sheet &&
m_selectionTool->SelectPoint( cursorPos, { SCH_SHEET_T }, &i ) )
2162 m_statusPopup->SetText(
_(
"No new hierarchical labels found." ) );
2173 description =
_(
"Add Sheet Pin" );
2179 if( evt->IsPrime() && !ignorePrimePosition )
2181 cursorPos =
grid.Align( evt->Position() );
2188 cursorPos =
grid.ResolveSnap( cursorPos, snapGrid, item ).position;
2191 if( !itemsToPlace.empty() )
2193 item = itemsToPlace.front().release();
2194 itemsToPlace.pop_front();
2198 prepItemForPlacement( item, cursorPos );
2200 if(
m_frame->GetMoveWarpsCursor() )
2212 if( isSheetPin && sheet )
2220 m_frame->SaveCopyForRepeatItem( item );
2227 commit.
Push( description );
2248 if( isSheetPin && sheet )
2255 m_statusPopup->SetText(
_(
"No new hierarchical labels found." ) );
2263 else if( !itemsToPlace.empty() )
2265 item = itemsToPlace.front().release();
2266 itemsToPlace.pop_front();
2267 prepItemForPlacement( item, cursorPos );
2279 else if( item && evt->IsSelectionEvent() )
2284 if( selection.
GetSize() == 1 )
2296 if( evt->HasParameter() )
2312 evt->SetPassEvent();
2347 evt->SetPassEvent();
2351 evt->SetPassEvent();
2388 bool started =
false;
2408 polyGeomMgr.
Reset();
2433 grid.SetUseGrid(
getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
2441 if( evt->IsCancelInteractive() )
2450 evt->SetPassEvent(
false );
2454 else if( evt->IsActivate() )
2459 if( evt->IsPointEditor() )
2465 if( evt->IsMoveTool() )
2468 frame()->PushTool( originalEvent );
2486 const bool endPolygon = evt->IsDblClick(
BUT_LEFT )
2494 polyGeomMgr.
Reset();
2501 else if( polyGeomMgr.
AddPoint( cursorPos ) )
2518 cursorPos = last.value();
2528 else if( started && ( evt->IsMotion() || evt->IsDrag(
BUT_LEFT ) ) )
2543 evt->SetPassEvent();
2548 evt->SetPassEvent();
2614 grid.SetUseGrid(
getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
2620 bool isSyntheticClick =
table && evt->IsActivate() && evt->HasPosition() && evt->Matches( aEvent );
2629 else if( evt->IsActivate() && !isSyntheticClick )
2631 if(
table && evt->IsMoveTool() )
2634 evt->SetPassEvent(
false );
2641 if( evt->IsPointEditor() )
2647 if( evt->IsMoveTool() )
2650 frame()->PushTool( originalEvent );
2661 table->SetColCount( 1 );
2667 table->AddCell( tableCell );
2669 table->SetParent( schematic );
2671 table->SetPosition( cursorPos );
2681 table->ClearEditFlags();
2692 commit.
Push(
_(
"Draw Table" ) );
2710 VECTOR2I requestedSize( cursorPos - origin );
2712 int colCount = std::max( 1, requestedSize.
x / ( fontSize * 15 ) );
2713 int rowCount = std::max( 1, requestedSize.
y / ( fontSize * 2 ) );
2715 VECTOR2I cellSize( std::max( gridSize.
x * 5, requestedSize.
x / colCount ),
2716 std::max( gridSize.
y * 2, requestedSize.
y / rowCount ) );
2718 cellSize.
x =
KiROUND( (
double) cellSize.
x / gridSize.
x ) * gridSize.
x;
2719 cellSize.
y =
KiROUND( (
double) cellSize.
y / gridSize.
y ) * gridSize.
y;
2721 table->ClearCells();
2722 table->SetColCount( colCount );
2724 for(
int col = 0; col < colCount; ++col )
2725 table->SetColWidth( col, cellSize.
x );
2727 for(
int row = 0; row < rowCount; ++row )
2729 table->SetRowHeight( row, cellSize.
y );
2731 for(
int col = 0; col < colCount; ++col )
2739 table->AddCell( cell );
2770 evt->SetPassEvent();
2779 evt->SetPassEvent();
2799 std::unique_ptr<DESIGN_BLOCK> designBlock;
2805 if( isDrawSheetCopy )
2807 wxString* ptr = aEvent.
Parameter<wxString*>();
2814 else if( isDrawSheetFromDesignBlock )
2817 wxCHECK( designBlock, 0 );
2818 filename = designBlock->GetSchematicFile();
2821 if( ( isDrawSheetCopy || isDrawSheetFromDesignBlock ) && !wxFileExists( filename ) )
2823 wxMessageBox( wxString::Format(
_(
"File '%s' does not exist." ), filename ) );
2837 bool startedWithDrag =
false;
2867 if( aEvent.
HasPosition() && !( isDrawSheetCopy || isDrawSheetFromDesignBlock ) )
2875 grid.SetUseGrid(
getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
2881 bool isSyntheticClick = sheet && evt->IsActivate() && evt->HasPosition()
2884 if( evt->IsCancelInteractive() || ( sheet && evt->IsAction( &
ACTIONS::undo ) ) )
2886 m_frame->GetInfoBar()->Dismiss();
2893 else if( evt->IsActivate() && !isSyntheticClick )
2895 if( sheet && evt->IsMoveTool() )
2898 evt->SetPassEvent(
false );
2904 m_frame->ShowInfoBarMsg(
_(
"Press <ESC> to cancel sheet creation." ) );
2905 evt->SetPassEvent(
false );
2909 if( evt->IsPointEditor() )
2915 if( evt->IsMoveTool() )
2918 frame()->PushTool( originalEvent );
2923 else if( !sheet && ( evt->IsClick(
BUT_LEFT ) || evt->IsDblClick(
BUT_LEFT )
2929 if( selection.
Size() == 1
2953 startedWithDrag = evt->IsDrag(
BUT_LEFT );
2960 if( isDrawSheetCopy )
2962 wxFileName fn( filename );
2967 else if( isDrawSheetFromDesignBlock )
2970 wxFileName fn( filename );
2975 std::vector<SCH_FIELD>& sheetFields = sheet->
GetFields();
2978 for(
const auto& [fieldName, fieldValue] : designBlock->GetFields() )
2980 sheetFields.emplace_back( sheet,
FIELD_T::USER, fieldName );
2981 sheetFields.back().SetText( fieldValue );
2982 sheetFields.back().SetVisible(
false );
3006 else if( sheet && ( evt->IsClick(
BUT_LEFT ) || evt->IsDblClick(
BUT_LEFT )
3010 || ( startedWithDrag && evt->IsMouseUp(
BUT_LEFT ) ) ) )
3015 if(
m_frame->EditSheetProperties( sheet, &
m_frame->GetCurrentSheet(),
nullptr,
nullptr,
nullptr,
3028 m_frame->AddToScreen( sheet );
3033 m_frame->Schematic().RefreshHierarchy();
3036 && !( ( isDrawSheetCopy || isDrawSheetFromDesignBlock )
3038 bool annotatePowerSymbols = isDrawSheetFromDesignBlock;
3040 if( annotateNonPowerSymbols || annotatePowerSymbols )
3047 if( annotateNonPowerSymbols )
3058 if( annotatePowerSymbols )
3079 c.
Add( sheetGroup, screen );
3084 c.
Push( isDrawSheetCopy ?
"Import Sheet Copy" :
"Draw Sheet" );
3091 if( ( isDrawSheetCopy || isDrawSheetFromDesignBlock )
3116 evt->SetPassEvent();
3125 m_frame->SetMsgPanel( sheet );
3141 evt->SetPassEvent();
3172 if( !sheetPaths.size() )
3176 m_frame, std::move( sheetPaths ),
3177 std::make_shared<SHEET_SYNCHRONIZATION_AGENT>(
3187 commit.
Push(
_(
"Modify sheet pin" ) );
3193 commit.
Push(
_(
"Modify schematic item" ) );
3204 selectionTool->AddItemToSel( aItem,
true );
3209 std::set<EDA_ITEM*> aTemplates )
3282 if( labels.empty() )
3287 m_statusPopup->SetText(
_(
"No new hierarchical labels found." ) );
3306 const int margin = pitch;
3312 int leftY = topY + margin - pitch;
3313 int rightY = topY + margin - pitch;
3318 rightY = std::max( rightY,
pin->GetPosition().y );
3320 leftY = std::max( leftY,
pin->GetPosition().y );
3324 std::vector<SCH_HIERLABEL*> leftLabels;
3325 std::vector<SCH_HIERLABEL*> rightLabels;
3330 rightLabels.push_back( label );
3332 leftLabels.push_back( label );
3338 return a->
GetText() < b->GetText();
3341 std::sort( leftLabels.begin(), leftLabels.end(), byText );
3342 std::sort( rightLabels.begin(), rightLabels.end(), byText );
3345 int botLeft = leftY + (int) leftLabels.size() * pitch;
3346 int botRight = rightY + (int) rightLabels.size() * pitch;
3347 int needBot = std::max( botLeft, botRight ) + margin;
3349 if( needBot > topY + sheet->
GetSize().
y )
3353 [&]( std::vector<SCH_HIERLABEL*>& aLabels,
int aX,
int aStartY )
3368 placeColumn( leftLabels, leftX, leftY );
3369 placeColumn( rightLabels, rightX, rightY );
3371 commit.
Push(
_(
"Auto-place Sheet Pins" ) );
3378 static const std::function<void( std::list<SCH_SHEET_PATH>&,
SCH_SCREEN*, std::set<SCH_SCREEN*>&,
3380 []( std::list<SCH_SHEET_PATH>& aPaths,
SCH_SCREEN* aScene, std::set<SCH_SCREEN*>& aVisited,
3383 if( ! aScene || aVisited.find(aScene) != aVisited.end() )
3386 std::vector<SCH_ITEM*> sheetChildren;
3387 aScene->GetSheets( &sheetChildren );
3388 aVisited.insert( aScene );
3390 for(
SCH_ITEM* child : sheetChildren )
3395 aPaths.push_back( cp );
3396 getSheetChildren( aPaths, sheet->
GetScreen(), aVisited, cp );
3400 std::list<SCH_SHEET_PATH> sheetPaths;
3401 std::set<SCH_SCREEN*> visited;
3404 std::vector<SCH_SHEET*> topLevelSheets =
m_frame->Schematic().GetTopLevelSheets();
3406 for(
SCH_SHEET* topSheet : topLevelSheets )
3408 if( topSheet && topSheet->GetScreen() )
3412 getSheetChildren( sheetPaths, topSheet->GetScreen(), visited, current );
3416 if( sheetPaths.size() == 0 )
3418 m_frame->ShowInfoBarMsg(
_(
"No sub schematic found in the current project" ) );
3433 std::vector<SCH_HIERLABEL*> labels;
3438 labels.push_back( label );
3441 std::sort( labels.begin(), labels.end(),
3444 return StrNumCmp( label1->GetText(), label2->GetText(), true ) < 0;
3449 if( !aSheet->
HasPin( label->GetText() ) )
3462 std::vector<SCH_HIERLABEL*> labels;
3469 labels.push_back( label );
constexpr EDA_IU_SCALE schIUScale
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
static TOOL_ACTION deleteLastPoint
static TOOL_ACTION cursorDblClick
static TOOL_ACTION duplicate
static TOOL_ACTION activatePointEditor
static TOOL_ACTION doDelete
static TOOL_ACTION cursorClick
static TOOL_ACTION increment
static TOOL_ACTION selectionClear
Clear the current selection.
static TOOL_ACTION refreshPreview
static TOOL_ACTION finishInteractive
PANEL_DESIGN_BLOCK_CHOOSER m_DesignBlockChooserPanel
constexpr bool Contains(const Vec &aPoint) const
COMMIT & Added(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Notify observers that aItem has been added.
COMMIT & Modify(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr, RECURSE_MODE aRecurse=RECURSE_MODE::NO_RECURSE)
Modify a given item in the model.
COMMIT & Add(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Add a new item to the model.
COMMIT & Removed(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
LIB_ID GetSelectedLibId(int *aUnit=nullptr) const
DESIGN_BLOCK * GetDesignBlock(const LIB_ID &aLibId, bool aUseCacheLib, bool aShowErrorMsg, wxString *aErrorMsg=nullptr)
Load design block from design block library table.
void SetLabelList(std::list< std::unique_ptr< SCH_LABEL_BASE > > *aLabelList)
FIELDS_GRID_TABLE * GetFieldsGridTable()
void SetDesignBlockLibId(const LIB_ID &aLibId)
void AddItem(EDA_ITEM *aItem)
Add item to group.
void SetName(const wxString &aName)
A base class for most all the KiCad significant classes used in schematics and boards.
virtual void SetPosition(const VECTOR2I &aPos)
virtual const BOX2I GetBoundingBox() const
Return the orthogonal bounding box of this object for display purposes.
EDA_ITEM_FLAGS GetEditFlags() const
void SetFlags(EDA_ITEM_FLAGS aMask)
KICAD_T Type() const
Returns the type of object.
void ClearFlags(EDA_ITEM_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
virtual bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const
Compare the item against the search criteria in aSearchData.
virtual EDA_ITEM * Clone() const
Create a duplicate of this item with linked list members set to NULL.
virtual void SetParent(EDA_ITEM *aParent)
virtual void SetEnd(const VECTOR2I &aEnd)
virtual void SetTextSize(VECTOR2I aNewSize, bool aEnforceMinTextSize=true)
virtual const wxString & GetText() const
Return the string associated with the text object.
void SetVertJustify(GR_TEXT_V_ALIGN_T aType)
GR_TEXT_H_ALIGN_T GetHorizJustify() const
virtual void SetVisible(bool aVisible)
virtual EDA_ANGLE GetTextAngle() const
void SetBold(bool aBold)
Set the text to be bold - this will also update the font if needed.
GR_TEXT_V_ALIGN_T GetVertJustify() const
virtual void SetText(const wxString &aText)
virtual void SetTextAngle(const EDA_ANGLE &aAngle)
void SetItalic(bool aItalic)
Set the text to be italic - this will also update the font if needed.
void SetHorizJustify(GR_TEXT_H_ALIGN_T aType)
PANEL_ANNOTATE m_AnnotatePanel
EE_TYPE OfType(KICAD_T aType) 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 SetCursorPosition(const VECTOR2D &aPosition, bool aWarpView=true, bool aTriggeredByArrows=false, long aArrowCommand=0)=0
Move cursor to the requested position expressed in world coordinates.
virtual void SetAutoPan(bool aEnabled)
Turn on/off auto panning (this feature is used when there is a tool active (eg.
virtual void PinCursorInsideNonAutoscrollArea(bool aWarpMouseCursor)=0
LEGACY_SYMBOL_LIB * GetCacheLibrary()
Object used to load, save, search, and otherwise manipulate symbol library files.
A logical library item identifier and consists of various portions much like a URI.
bool IsValid() const
Check if this LID_ID is valid.
Define a library symbol object.
wxString GetDescription() const override
const LIB_ID & GetLibId() const override
wxString GetKeyWords() const override
bool IsPower() const override
void SetDescription(const wxString &aDescription)
Gets the Description field text value */.
void SetKeyWords(const wxString &aKeyWords)
bool IsLocalPower() const override
bool IsGlobalPower() const override
A singleton reporter that reports to nowhere.
virtual COMMON_SETTINGS * GetCommonSettings() const
Class that handles the drawing of a polygon, including management of last corner deletion and drawing...
bool AddPoint(const VECTOR2I &aPt)
Lock in a polygon point.
void SetCursorPosition(const VECTOR2I &aPos)
Set the current cursor position.
bool NewPointClosesOutline(const VECTOR2I &aPt) const
std::optional< VECTOR2I > DeleteLastCorner()
Remove the last-added point from the polygon.
void SetFinished()
Mark the polygon finished and update the client.
void SetLeaderMode(LEADER_MODE aMode)
Set the leader mode to use when calculating the leader/returner lines.
void Reset()
Clear the manager state and start again.
static SYMBOL_LIBRARY_ADAPTER * SymbolLibAdapter(PROJECT *aProject)
Accessor for project symbol library manager adapter.
static LEGACY_SYMBOL_LIBS * LegacySchLibs(PROJECT *aProject)
Returns the list of symbol libraries from a legacy (pre-5.x) design This is only used from the remapp...
An adjunct helper to the DRAWING_TOOL interactive tool, which handles incoming geometry changes from ...
These are loaded from Eeschema settings but then overwritten by the project settings.
std::shared_ptr< REFDES_TRACKER > m_refDesTracker
A list of previously used schematic reference designators.
bool m_IntersheetRefsShow
Holds all the data relating to one schematic.
SCHEMATIC_SETTINGS & Settings() const
bool Contains(const SCH_REFERENCE &aRef) const
Check if the schematic contains the specified reference.
static TOOL_ACTION rotateCCW
static TOOL_ACTION placeClassLabel
static TOOL_ACTION placeSheetPin
static TOOL_ACTION placeNextSymbolUnit
static TOOL_ACTION editValue
static TOOL_ACTION setExcludeFromBOM
static TOOL_ACTION mirrorV
static TOOL_ACTION drawSheetFromFile
static TOOL_ACTION placeGlobalLabel
static TOOL_ACTION autoplaceFields
static TOOL_ACTION changeSymbol
static TOOL_ACTION syncAllSheetsPins
static TOOL_ACTION closeOutline
static TOOL_ACTION drawSheet
static TOOL_ACTION properties
static TOOL_ACTION editReference
static TOOL_ACTION leaveSheet
static TOOL_ACTION autoplaceAllSheetPins
static TOOL_ACTION placeHierLabel
static TOOL_ACTION placeLabel
static TOOL_ACTION toText
static TOOL_ACTION placeBusWireEntry
static TOOL_ACTION toHLabel
static TOOL_ACTION rotateCW
static TOOL_ACTION importSheet
static TOOL_ACTION setExcludeFromSim
static TOOL_ACTION toLabel
static TOOL_ACTION placeJunction
static TOOL_ACTION setDNP
static TOOL_ACTION drawRuleArea
static TOOL_ACTION placeSymbol
static TOOL_ACTION placeImage
static TOOL_ACTION editWithLibEdit
static TOOL_ACTION toDLabel
static TOOL_ACTION setExcludeFromPosFiles
static TOOL_ACTION cycleBodyStyle
static TOOL_ACTION drawSheetFromDesignBlock
static TOOL_ACTION mirrorH
static TOOL_ACTION placeDesignBlock
static TOOL_ACTION drawTable
static TOOL_ACTION placeSchematicText
static TOOL_ACTION toTextBox
static TOOL_ACTION changeSheet
static TOOL_ACTION enterSheet
static TOOL_ACTION editFootprint
static TOOL_ACTION repeatDrawItem
static TOOL_ACTION placeNoConnect
static TOOL_ACTION toGLabel
static TOOL_ACTION setExcludeFromBoard
static TOOL_ACTION syncSheetPins
static TOOL_ACTION placePower
Object to handle a bitmap image that can be inserted in a schematic.
Base class for a bus or wire entry.
VECTOR2I GetPosition() const override
void MirrorHorizontally(int aCenter) override
Mirror item horizontally about aCenter.
void MirrorVertically(int aCenter) override
Mirror item vertically about aCenter.
void Rotate(const VECTOR2I &aCenter, bool aRotateCCW) override
Rotate the item around aCenter 90 degrees in the clockwise direction.
Class for a wire to bus entry.
virtual void Push(const wxString &aMessage=wxT("A commit"), int aCommitFlags=0) override
Execute the changes.
virtual void Revert() override
Revert the commit by restoring the modified items state.
Each graphical item can have a SCH_CONNECTION describing its logical connection (to a bus or net).
Schematic editor (Eeschema) main window.
void SetText(const wxString &aText) override
SCH_FIELD * GetField(FIELD_T aFieldType)
Return a mandatory field in this label.
A set of SCH_ITEMs (i.e., without duplicates).
void SetSpinStyle(SPIN_STYLE aSpinStyle) override
Base class for any item which can be embedded within the SCHEMATIC container class,...
virtual bool IsConnectable() const
virtual void AutoplaceFields(SCH_SCREEN *aScreen, AUTOPLACE_ALGO aAlgo)
virtual void RunOnChildren(const std::function< void(SCH_ITEM *)> &aFunction, RECURSE_MODE aMode)
SCHEMATIC * Schematic() const
Search the item hierarchy to find a SCHEMATIC.
virtual void CalcEdit(const VECTOR2I &aPosition)
Calculate the attributes of an item at aPosition when it is being edited.
virtual void SetUnit(int aUnit)
SCH_CONNECTION * Connection(const SCH_SHEET_PATH *aSheet=nullptr) const
Retrieve the connection associated with this object in the given sheet.
bool IsType(const std::vector< KICAD_T > &aScanTypes) const override
Check whether the item is one of the listed types.
bool AutoRotateOnPlacement() const
autoRotateOnPlacement
SPIN_STYLE GetSpinStyle() const
void SetShape(LABEL_FLAG_SHAPE aShape)
LABEL_FLAG_SHAPE GetShape() const
void SetAutoRotateOnPlacement(bool autoRotate=true)
std::vector< SCH_FIELD > & GetFields()
virtual void SetSpinStyle(SPIN_STYLE aSpinStyle)
Segment description base class to describe items which have 2 end points (track, wire,...
bool IsWire() const
Return true if the line is a wire.
VECTOR2I GetEndPoint() const
VECTOR2I GetStartPoint() const
Container to create a flattened list of symbols because in a complex hierarchy, a symbol can be used ...
void SortByReferenceOnly()
Sort the list of references by reference.
void ReannotateByOptions(ANNOTATE_ORDER_T aSortOption, ANNOTATE_ALGO_T aAlgoOption, int aStartNumber, const SCH_REFERENCE_LIST &aAdditionalRefs, bool aStartAtCurrent, SCH_SHEET_LIST *aHierarchy)
Forces reannotation of the provided references.
void SetRefDesTracker(std::shared_ptr< REFDES_TRACKER > aTracker)
void AddItem(const SCH_REFERENCE &aItem)
void UpdateAnnotation()
Update the symbol references for the schematic project (or the current sheet).
A helper to define a symbol's reference designator in a schematic.
bool AlwaysAnnotate() const
Verify the reference should always be automatically annotated.
EE_RTREE & Items()
Get the full RTree, usually for iterating.
SCH_ITEM * GetItem(const VECTOR2I &aPosition, int aAccuracy=0, KICAD_T aType=SCH_LOCATE_ANY_T) const
Check aPosition within a distance of aAccuracy for items of type aFilter.
bool IsExplicitJunctionAllowed(const VECTOR2I &aPosition) const
Indicate that a junction dot may be placed at the given location.
void SetPosition(const VECTOR2I &aPos) override
VECTOR2I GetPosition() const override
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
void SortByPageNumbers(bool aUpdateVirtualPageNums=true)
Sort the list of sheets by page number.
SCH_SHEET_LIST FindAllSheetsForScreen(const SCH_SCREEN *aScreen) const
Return a SCH_SHEET_LIST with a copy of all the SCH_SHEET_PATH using a particular screen.
wxString GetNextPageNumber() const
void GetSymbols(SCH_REFERENCE_LIST &aReferences, SYMBOL_FILTER aSymbolFilter, bool aForceIncludeOrphanSymbols=false) const
Add a SCH_REFERENCE object to aReferences for each symbol in the list of sheets.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
SCH_SCREEN * LastScreen()
void SetPageNumber(const wxString &aPageNumber)
Set the sheet instance user definable page number.
SCH_SHEET * Last() const
Return a pointer to the last SCH_SHEET of the list.
void push_back(SCH_SHEET *aSheet)
Forwarded method from std::vector.
Define a sheet pin (label) used in sheets to create hierarchical schematics.
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
void SetBorderColor(KIGFX::COLOR4D aColor)
void SetSize(const VECTOR2I &aSize)
void AddPin(SCH_SHEET_PIN *aSheetPin)
Add aSheetPin to the sheet.
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const override
Compare the item against the search criteria in aSearchData.
std::vector< SCH_FIELD > & GetFields()
Return a reference to the vector holding the sheet's fields.
SCH_FIELD * GetField(FIELD_T aFieldType)
Return a mandatory field in this sheet.
void SetBackgroundColor(KIGFX::COLOR4D aColor)
SCH_SCREEN * GetScreen() const
VECTOR2I GetPosition() const override
bool HasPin(const wxString &aName) const
Check if the sheet already has a sheet pin named aName.
void SetScreen(SCH_SCREEN *aScreen)
Set the SCH_SCREEN associated with this sheet to aScreen.
void SetBorderWidth(int aWidth)
void AutoplaceFields(SCH_SCREEN *aScreen, AUTOPLACE_ALGO aAlgo) override
void Resize(const VECTOR2I &aSize)
Resize this sheet to aSize and adjust all of the labels accordingly.
std::vector< SCH_SHEET_PIN * > & GetPins()
const LIB_ID & GetLibId() const override
void SetUnitSelection(const SCH_SHEET_PATH *aSheet, int aUnitSelection)
Set the selected unit of this symbol on one sheet.
RAII class that sets an value at construction and resets it to the original value at destruction.
const VECTOR2I NearestPoint(const VECTOR2I &aP) const
Compute a point on the segment (this) that is closest to point aP.
virtual unsigned int GetSize() const override
Return the number of stored items.
int Size() const
Returns the number of selected parts.
void SetReferencePoint(const VECTOR2I &aP)
SHEET_SYNCHRONIZATION_PLACEMENT
std::function< void()> MODIFICATION
An interface to the global shared library manager that is schematic-specific and linked to one projec...
Helper object to filter a list of libraries.
This file is part of the common library.
static constexpr EDA_ANGLE ANGLE_0
#define IGNORE_PARENT_GROUP
#define IS_NEW
New item, just created.
#define STRUCT_DELETED
flag indication structures to be erased
#define ENDPOINT
ends. (Used to support dragging.)
#define SKIP_STRUCT
flag indicating that the structure should be ignored
#define IS_MOVING
Item being moved.
#define STARTPOINT
When a line is selected, these flags indicate which.
@ ID_POPUP_SCH_SELECT_UNIT
@ ID_POPUP_SCH_SELECT_BODY_STYLE
@ ID_POPUP_SCH_SELECT_BODY_STYLE_END
@ ID_POPUP_SCH_SELECT_UNIT_END
@ DIRECT
Unconstrained point-to-point.
static const std::string KiCadSchematicFileExtension
static wxString ImageFileWildcard()
static wxString KiCadSchematicFileWildcard()
PGM_BASE & Pgm()
The global program "get" accessor.
LIB_SYMBOL * SchGetLibSymbol(const LIB_ID &aLibId, SYMBOL_LIBRARY_ADAPTER *aLibMgr, LEGACY_SYMBOL_LIB *aCacheLib, wxWindow *aParent, bool aShowErrorMsg)
Load symbol from symbol library table.
Class to handle a set of SCH_ITEMs.
std::vector< EDA_ITEM * > EDA_ITEMS
ANNOTATE_ORDER_T
Schematic annotation order options.
@ ANNOTATE_SELECTION
Annotate the selection.
ANNOTATE_ALGO_T
Schematic annotation type options.
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
@ SYMBOL_FILTER_NON_POWER
COLOR4D default_sheet_border_color
COLOR4D default_sheet_background_color
int default_line_thickness
POWER_SYMBOLS new_power_symbols
bool m_Reannotate
For a preselected multi-unit symbol, keep placing remaining units instead of exiting.
SCH_SYMBOL * m_Symbol
< Provide a symbol to place
SCH_SYMBOL * m_Symbol
< Symbol used as reference for unit placement
@ USER
The field ID hasn't been set yet; field is invalid.
@ INTERSHEET_REFS
Global label cross-reference page numbers.
IbisParser parser & reporter
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
VECTOR2< int32_t > VECTOR2I
Definition of file extensions used in Kicad.