67#include <dialogs/dialog_text_properties.h>
70#include <dialogs/dialog_table_properties.h>
75#include <wx/filedlg.h>
110 auto belowRootSheetCondition =
113 return m_frame->GetCurrentSheet().Last() != &
m_frame->Schematic().Root();
116 auto inDrawingRuleArea =
139 bool placeOneOnly = symbol !=
nullptr;
142 std::vector<PICKED_SYMBOL>* historyList =
nullptr;
143 bool ignorePrimePosition =
false;
147 bool keepSymbol =
false;
148 bool placeAllUnits =
false;
176 filter.FilterPowerSymbols(
true );
180 wxFAIL_MSG(
"PlaceSymbol(): unexpected request" );
194 m_view->AddToPreview( aSymbol,
false );
215 existingRefs.
Clear();
243 for(
size_t i = 0; i < refs.
GetCount(); i++ )
244 existingRefs.
AddItem( refs[i] );
248 m_frame->GetCurrentSheet().UpdateAllScreenReferences();
276 ignorePrimePosition =
true;
284 grid.SetUseGrid(
getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
290 bool isSyntheticClick = symbol && evt->IsActivate() && evt->HasPosition() && evt->Matches( aEvent );
292 if( evt->IsCancelInteractive() || ( symbol && evt->IsAction( &
ACTIONS::undo ) ) )
294 m_frame->GetInfoBar()->Dismiss();
312 else if( evt->IsActivate() && !isSyntheticClick )
314 if( symbol && evt->IsMoveTool() )
317 evt->SetPassEvent(
false );
323 m_frame->ShowInfoBarMsg(
_(
"Press <ESC> to cancel symbol creation." ) );
324 evt->SetPassEvent(
false );
328 if( evt->IsMoveTool() )
350 std::set<UTF8> unique_libid;
351 std::vector<PICKED_SYMBOL> alreadyPlaced;
368 alreadyPlaced.push_back( pickedSymbol );
374 bool footprintPreviews =
m_frame->eeconfig()->m_Appearance.footprint_preview;
389 if( evt->IsPrime() && !ignorePrimePosition )
409 if( keywords.Contains( wxT(
"global power" ) ) )
411 keywords.Replace( wxT(
"global power" ), wxT(
"local power" ) );
417 if( desc.Contains( wxT(
"global label" ) ) )
419 desc.Replace( wxT(
"global label" ), wxT(
"local label" ) );
431 symbol =
new SCH_SYMBOL( *libSymbol, &
m_frame->GetCurrentSheet(), sel, cursorPos,
438 existingRefs.
AddItem( placedSymbolReference );
441 if(
m_frame->eeconfig()->m_AutoplaceFields.enable )
453 m_frame->AddToScreen( symbol, screen );
455 if(
m_frame->eeconfig()->m_AutoplaceFields.enable )
458 m_frame->SaveCopyForRepeatItem( symbol );
461 commit.
Added( symbol, screen );
467 commit.
Push(
_(
"Place Symbol" ) );
477 if( keepSymbol || placeAllUnits )
484 while( currentReference.
GetUnit() <= symbol->GetUnitCount()
485 && schematic.
Contains( currentReference ) )
490 if( currentReference.
GetUnit() > symbol->GetUnitCount() )
497 if( keepSymbol || currentReference.
GetUnit() > 1 )
503 addSymbol( nextSymbol );
506 if( currentReference.
GetUnit() == 1 )
511 existingRefs.
AddItem( placedSymbolReference );
536 m_frame->SelectUnit( symbol, unit );
545 if( symbol && symbol->GetBodyStyle() != bodyStyle )
547 m_frame->SelectBodyStyle( symbol, bodyStyle );
569 symbol->SetPosition( cursorPos );
571 m_view->AddToPreview( symbol,
false );
572 m_frame->SetMsgPanel( symbol );
625 int requestedUnit = params.
m_Unit;
630 static const std::vector<KICAD_T> symbolTypes = {
SCH_SYMBOL_T };
633 if( selection.
Size() != 1 )
635 m_frame->ShowInfoBarMsg(
_(
"Select a single symbol to place the next unit." ) );
646 if( !symbol->IsMultiUnit() )
648 m_frame->ShowInfoBarMsg(
_(
"This symbol has only one unit." ) );
654 if( missingUnits.empty() )
656 m_frame->ShowInfoBarMsg(
_(
"All units of this symbol are already placed." ) );
662 if( requestedUnit > 0 )
664 if( missingUnits.count( requestedUnit ) == 0 )
666 m_frame->ShowInfoBarMsg(
_(
"Requested unit already placed." ) );
670 nextMissing = requestedUnit;
675 nextMissing = *std::min_element( missingUnits.begin(), missingUnits.end() );
678 std::unique_ptr<SCH_SYMBOL> newSymbol = std::make_unique<SCH_SYMBOL>( *symbol );
684 newSymbol->SetUnitSelection( nextMissing );
685 newSymbol->SetUnit( nextMissing );
686 newSymbol->SetRefProp( symbol->GetRef( &sheetPath,
false ) );
708 struct RESET_FORCED_CURSOR_GUARD
715 RESET_FORCED_CURSOR_GUARD forcedCursorGuard{ controls };
717 if( !cfg || !common_settings )
725 std::unique_ptr<DESIGN_BLOCK> designBlock;
726 wxString sheetFileName = wxEmptyString;
729 if( placingDesignBlock )
741 msg.Printf(
_(
"Could not find design block %s." ),
743 m_frame->ShowInfoBarError( msg,
true );
747 sheetFileName = designBlock->GetSchematicFile();
749 if( sheetFileName.IsEmpty() || !wxFileExists( sheetFileName ) )
751 m_frame->ShowInfoBarError(
_(
"Design block has no schematic to place." ),
true );
758 wxString* importSourceFile = aEvent.
Parameter<wxString*>();
760 if( importSourceFile !=
nullptr )
761 sheetFileName = *importSourceFile;
771 auto placeSheetContents =
788 if( !
m_frame->LoadSheetFromFile( sheetPath.
Last(), &sheetPath, sheetFileName,
true,
789 placingDesignBlock ) )
794 m_frame->SetSheetNumberAndCount();
808 group->SetName( designBlock->GetLibId().GetLibItemName() );
809 group->SetDesignBlockLibId( designBlock->GetLibId() );
813 group->SetName( wxFileName( sheetFileName ).
GetName() );
816 if( repeatPlacement )
817 group->SetName(
group->GetName() + wxString::Format(
"%d", suffix++ ) );
826 static_cast<SCH_SYMBOL*
>( item )->ClearAnnotation( &sheetPath,
false );
831 if( !item->GetParentGroup() )
834 group->AddItem( item );
836 newItems.emplace_back( item );
839 commit.
Added( item, screen );
870 if( !keepAnnotations )
902 commit.
Push( placingDesignBlock ?
_(
"Add Design Block" )
903 :
_(
"Import Schematic Sheet Content" ) );
911 m_frame->UpdateHierarchyNavigator();
918 if( sheetFileName.IsEmpty() )
923 if (!placingDesignBlock)
925 if( sheetFileName.IsEmpty() )
927 path = wxPathOnly(
m_frame->Prj().GetProjectFullName() );
928 file = wxEmptyString;
932 path = wxPathOnly( sheetFileName );
933 file = wxFileName( sheetFileName ).GetFullName();
938 wxFileDialog dlg(
m_frame,
_(
"Choose Schematic" ),
path, file,
942 dlg.SetCustomizeHook( dlgHook );
946 if( dlg.ShowModal() == wxID_CANCEL )
949 sheetFileName = dlg.GetPath();
951 m_frame->GetDesignBlockPane()->UpdateCheckboxes();
954 if( sheetFileName.IsEmpty() )
990 grid.SetUseGrid(
getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
996 bool isSyntheticClick = designBlock && evt->IsActivate() && evt->HasPosition() && evt->Matches( aEvent );
998 if( evt->IsCancelInteractive() || ( designBlock && evt->IsAction( &
ACTIONS::undo ) ) )
1000 m_frame->GetInfoBar()->Dismiss();
1003 else if( evt->IsActivate() && !isSyntheticClick )
1005 m_frame->GetInfoBar()->Dismiss();
1012 if( placingDesignBlock )
1040 evt->SetPassEvent();
1054 bool immediateMode =
image !=
nullptr;
1055 bool ignorePrimePosition =
false;
1093 m_view->RecacheAllItems();
1118 ignorePrimePosition =
true;
1126 grid.SetUseGrid(
getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
1132 bool isSyntheticClick =
image && evt->IsActivate() && evt->HasPosition() && evt->Matches( aEvent );
1136 m_frame->GetInfoBar()->Dismiss();
1154 else if( evt->IsActivate() && !isSyntheticClick )
1156 if(
image && evt->IsMoveTool() )
1159 evt->SetPassEvent(
false );
1165 m_frame->ShowInfoBarMsg(
_(
"Press <ESC> to cancel image creation." ) );
1166 evt->SetPassEvent(
false );
1170 if( evt->IsMoveTool() )
1194 bool cancelled =
false;
1199 cancelled = dlg.ShowModal() != wxID_OK;
1208 if( evt->IsPrime() && !ignorePrimePosition )
1210 cursorPos =
grid.Align( evt->Position() );
1219 wxString fullFilename = dlg.GetPath();
1222 if( wxFileExists( fullFilename ) )
1225 if( !
image || !
image->GetReferenceImage().ReadImageFile( fullFilename ) )
1227 wxMessageBox( wxString::Format(
_(
"Could not load image from '%s'." ), fullFilename ) );
1239 m_view->RecacheAllItems();
1250 commit.
Push(
_(
"Place Image" ) );
1286 evt->SetPassEvent();
1291 image->SetPosition( cursorPos );
1294 m_view->RecacheAllItems();
1307 evt->SetPassEvent();
1342 if( dlgResult != wxID_OK )
1348 wxMessageBox(
_(
"No graphic items found in file." ) );
1355 std::vector<SCH_ITEM*> newItems;
1356 std::vector<SCH_ITEM*> selectedItems;
1360 for( std::unique_ptr<EDA_ITEM>& ptr : list )
1363 wxCHECK2_MSG( item,
continue, wxString::Format(
"Bad item type: ", ptr->Type() ) );
1365 newItems.push_back( item );
1366 selectedItems.push_back( item );
1367 preview.
Add( item );
1378 commit.
Push(
_(
"Import Graphic" ) );
1387 EDA_ITEMS selItems( selectedItems.begin(), selectedItems.end() );
1413 for(
SCH_ITEM* item : selectedItems )
1414 item->Move(
delta );
1416 currentOffset +=
delta;
1418 m_view->Update( &preview );
1426 grid.SetUseGrid(
getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
1431 if( evt->IsCancelInteractive() || evt->IsActivate() )
1440 else if( evt->IsMotion() )
1442 delta = cursorPos - currentOffset;
1444 for(
SCH_ITEM* item : selectedItems )
1445 item->Move(
delta );
1447 currentOffset +=
delta;
1449 m_view->Update( &preview );
1462 commit.
Push(
_(
"Import Graphic" ) );
1467 evt->SetPassEvent();
1472 m_view->Remove( &preview );
1490 bool loggedInfoBarError =
false;
1491 wxString description;
1493 bool allowRepeat =
false;
1519 description =
_(
"Add No Connect Flag" );
1526 description =
_(
"Add Junction" );
1532 description =
_(
"Add Wire to Bus Entry" );
1537 wxASSERT_MSG(
false,
"Unknown item type in SCH_DRAWING_TOOLS::SingleClickPlace" );
1575 grid.SetUseGrid(
getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
1577 cursorPos = evt->IsPrime() ? evt->Position() : controls->
GetMousePosition();
1578 cursorPos =
grid.BestSnapAnchor( cursorPos,
grid.GetItemGrid( previewItem ),
nullptr );
1581 if( evt->IsCancelInteractive() )
1586 else if( evt->IsActivate() )
1588 if( evt->IsMoveTool() )
1602 if( !screen->
GetItem( cursorPos, 0, type ) )
1608 m_frame->ShowInfoBarError(
_(
"Junction location contains no joinable wires and/or pins." ) );
1609 loggedInfoBarError =
true;
1612 else if( loggedInfoBarError )
1614 m_frame->GetInfoBar()->Dismiss();
1623 lwbTool->
AddJunction( &commit, screen, cursorPos );
1625 m_frame->Schematic().CleanUp( &commit );
1627 commit.
Push( description );
1635 m_frame->AddToScreen( newItem, screen );
1638 m_frame->SaveCopyForRepeatItem( newItem );
1641 commit.
Added( newItem, screen );
1643 m_frame->Schematic().CleanUp( &commit );
1645 commit.
Push( description );
1664 m_frame->SetMsgPanel( previewItem );
1701 std::deque<SCH_ITEM*> strokeItems;
1702 strokeItems.push_back( previewItem );
1717 std::deque<SCH_JUNCTION*> junctions;
1718 junctions.push_back(
static_cast<SCH_JUNCTION*
>( previewItem ) );
1741 evt->SetPassEvent();
1746 evt->SetPassEvent();
1779 wxASSERT( aWire->
IsWire() );
1785 SCH_ITEM* wireDriver = wireConnection->Driver();
1787 if( wireDriver && wireDriver->
IsType( { SCH_LABEL_T, SCH_GLOBAL_LABEL_T } ) )
1788 return wireConnection->LocalName();
1791 return wxEmptyString;
1796 std::list<std::unique_ptr<SCH_LABEL_BASE>>& aLabelList )
1819 labelItem->
GetFields().back().SetItalic(
true );
1820 labelItem->
GetFields().back().SetVisible(
true );
1834 labelItem = globalLabel;
1842 wxFAIL_MSG(
"SCH_DRAWING_TOOLS::createNewLabel() unknown label type" );
1862 if( !netName.IsEmpty() )
1865 labelItem->
SetText( netName );
1900 if( aLabelList.empty() )
1901 aLabelList.push_back( std::unique_ptr<SCH_LABEL_BASE>( labelItem ) );
1915 textItem =
new SCH_TEXT( aPosition );
1950 pin->SetText( std::to_string( aSheet->
GetPins().size() + 1 ) );
1952 pin->SetPosition( aPosition );
1953 pin->ClearSelected();
1977 bool ignorePrimePosition =
false;
1980 wxString description;
1982 std::list<std::unique_ptr<SCH_LABEL_BASE>> itemsToPlace;
2013 else if( isGlobalLabel )
2015 else if( isNetLabel || isClassLabel )
2017 else if( isHierLabel )
2023 auto updatePreview =
2027 m_view->AddToPreview( item,
false );
2030 m_view->AddToPreview( aChild,
false );
2044 while( !itemsToPlace.empty() )
2046 itemsToPlace.front().release();
2047 itemsToPlace.pop_front();
2051 auto prepItemForPlacement =
2083 && ( isText || isGlobalLabel || isHierLabel || isClassLabel || isNetLabel ) )
2086 ignorePrimePosition =
true;
2096 grid.SetUseGrid(
getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
2099 cursorPos =
grid.BestSnapAnchor( cursorPos, snapGrid, item );
2103 bool isSyntheticClick = item && evt->IsActivate() && evt->HasPosition() && evt->
Matches( aEvent );
2105 if( evt->IsCancelInteractive() || evt->IsAction( &
ACTIONS::undo ) )
2107 m_frame->GetInfoBar()->Dismiss();
2119 else if( evt->IsActivate() && !isSyntheticClick )
2121 if( item && evt->IsMoveTool() )
2124 evt->SetPassEvent(
false );
2130 m_frame->ShowInfoBarMsg(
_(
"Press <ESC> to cancel item creation." ) );
2131 evt->SetPassEvent(
false );
2135 if( evt->IsPointEditor() )
2139 else if( evt->IsMoveTool() )
2163 description =
_(
"Add Text" );
2165 else if( isHierLabel )
2182 itemsToPlace.push_back( std::unique_ptr<SCH_LABEL_BASE>( label ) );
2189 description =
_(
"Add Hierarchical Label" );
2191 else if( isNetLabel )
2194 description =
_(
"Add Label" );
2196 else if( isGlobalLabel )
2199 description =
_(
"Add Label" );
2201 else if( isClassLabel )
2204 description =
_(
"Add Label" );
2206 else if( isSheetPin )
2211 if( !sheet &&
m_selectionTool->SelectPoint( cursorPos, { SCH_SHEET_T }, &i ) )
2219 + wxPoint( 20, 20 ) );
2240 m_statusPopup->SetText(
_(
"No new hierarchical labels found." ) );
2253 description =
_(
"Add Sheet Pin" );
2259 if( evt->IsPrime() && !ignorePrimePosition )
2261 cursorPos =
grid.Align( evt->Position() );
2268 cursorPos =
grid.BestSnapAnchor( cursorPos, snapGrid, item );
2271 if( !itemsToPlace.empty() )
2273 item = itemsToPlace.front().release();
2274 itemsToPlace.pop_front();
2278 prepItemForPlacement( item, cursorPos );
2280 if(
m_frame->GetMoveWarpsCursor() )
2292 if( isSheetPin && sheet )
2300 m_frame->SaveCopyForRepeatItem( item );
2307 commit.
Push( description );
2329 if( isSheetPin && sheet )
2336 m_statusPopup->SetText(
_(
"No new hierarchical labels found." ) );
2346 else if( !itemsToPlace.empty() )
2348 item = itemsToPlace.front().release();
2349 itemsToPlace.pop_front();
2350 prepItemForPlacement( item, cursorPos );
2362 else if( item && evt->IsSelectionEvent() )
2367 if( selection.
GetSize() == 1 )
2379 if( evt->HasParameter() )
2396 evt->SetPassEvent();
2433 evt->SetPassEvent();
2437 evt->SetPassEvent();
2467 wxString description;
2517 grid.SetUseGrid(
getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
2523 bool isSyntheticClick = item && evt->IsActivate() && evt->HasPosition() && evt->
Matches( aEvent );
2525 if( evt->IsCancelInteractive() || ( item && evt->IsAction( &
ACTIONS::undo ) ) )
2537 else if( evt->IsActivate() && !isSyntheticClick )
2539 if( item && evt->IsMoveTool() )
2542 evt->SetPassEvent(
false );
2549 if( evt->IsPointEditor() )
2553 else if( evt->IsMoveTool() )
2564 else if( !item && ( evt->IsClick(
BUT_LEFT )
2588 description =
_(
"Add Text Box" );
2611 bool finished =
false;
2663 commit.
Push( wxString::Format(
_(
"Draw %s" ), item->
GetClass() ) );
2684 evt->SetPassEvent();
2694 else if( evt->IsDblClick(
BUT_LEFT ) && !item )
2712 evt->SetPassEvent();
2741 bool started =
false;
2760 polyGeomMgr.
Reset();
2785 grid.SetUseGrid(
getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
2793 if( evt->IsCancelInteractive() )
2804 evt->SetPassEvent(
false );
2808 else if( evt->IsActivate() )
2813 if( evt->IsPointEditor() )
2817 else if( evt->IsMoveTool() )
2841 const bool endPolygon = evt->IsDblClick(
BUT_LEFT )
2849 polyGeomMgr.
Reset();
2856 else if( polyGeomMgr.
AddPoint( cursorPos ) )
2873 cursorPos = last.value();
2883 else if( started && ( evt->IsMotion() || evt->IsDrag(
BUT_LEFT ) ) )
2899 evt->SetPassEvent();
2904 evt->SetPassEvent();
2969 grid.SetUseGrid(
getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
2975 bool isSyntheticClick =
table && evt->IsActivate() && evt->HasPosition() && evt->Matches( aEvent );
2989 else if( evt->IsActivate() && !isSyntheticClick )
2991 if(
table && evt->IsMoveTool() )
2994 evt->SetPassEvent(
false );
3001 if( evt->IsPointEditor() )
3005 else if( evt->IsMoveTool() )
3022 table->SetColCount( 1 );
3028 table->AddCell( tableCell );
3030 table->SetParent( schematic );
3032 table->SetPosition( cursorPos );
3042 table->ClearEditFlags();
3053 commit.
Push(
_(
"Draw Table" ) );
3071 VECTOR2I requestedSize( cursorPos - origin );
3073 int colCount = std::max( 1, requestedSize.
x / ( fontSize * 15 ) );
3074 int rowCount = std::max( 1, requestedSize.
y / ( fontSize * 2 ) );
3076 VECTOR2I cellSize( std::max( gridSize.
x * 5, requestedSize.
x / colCount ),
3077 std::max( gridSize.
y * 2, requestedSize.
y / rowCount ) );
3079 cellSize.
x =
KiROUND( (
double) cellSize.
x / gridSize.
x ) * gridSize.
x;
3080 cellSize.
y =
KiROUND( (
double) cellSize.
y / gridSize.
y ) * gridSize.
y;
3082 table->ClearCells();
3083 table->SetColCount( colCount );
3085 for(
int col = 0; col < colCount; ++col )
3086 table->SetColWidth( col, cellSize.
x );
3088 for(
int row = 0; row < rowCount; ++row )
3090 table->SetRowHeight( row, cellSize.
y );
3092 for(
int col = 0; col < colCount; ++col )
3100 table->AddCell( cell );
3132 evt->SetPassEvent();
3141 evt->SetPassEvent();
3161 std::unique_ptr<DESIGN_BLOCK> designBlock;
3167 if( isDrawSheetCopy )
3169 wxString* ptr = aEvent.
Parameter<wxString*>();
3176 else if( isDrawSheetFromDesignBlock )
3179 wxCHECK( designBlock, 0 );
3180 filename = designBlock->GetSchematicFile();
3183 if( ( isDrawSheetCopy || isDrawSheetFromDesignBlock ) && !wxFileExists( filename ) )
3185 wxMessageBox( wxString::Format(
_(
"File '%s' does not exist." ), filename ) );
3199 bool startedWithDrag =
false;
3228 if( aEvent.
HasPosition() && !( isDrawSheetCopy || isDrawSheetFromDesignBlock ) )
3236 grid.SetUseGrid(
getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
3242 bool isSyntheticClick = sheet && evt->IsActivate() && evt->HasPosition()
3245 if( evt->IsCancelInteractive() || ( sheet && evt->IsAction( &
ACTIONS::undo ) ) )
3247 m_frame->GetInfoBar()->Dismiss();
3259 else if( evt->IsActivate() && !isSyntheticClick )
3261 if( sheet && evt->IsMoveTool() )
3264 evt->SetPassEvent(
false );
3270 m_frame->ShowInfoBarMsg(
_(
"Press <ESC> to cancel sheet creation." ) );
3271 evt->SetPassEvent(
false );
3275 if( evt->IsPointEditor() )
3279 else if( evt->IsMoveTool() )
3290 else if( !sheet && ( evt->IsClick(
BUT_LEFT ) || evt->IsDblClick(
BUT_LEFT )
3296 if( selection.
Size() == 1
3321 startedWithDrag = evt->IsDrag(
BUT_LEFT );
3328 if( isDrawSheetCopy )
3330 wxFileName fn( filename );
3335 else if( isDrawSheetFromDesignBlock )
3337 wxFileName fn( filename );
3342 std::vector<SCH_FIELD>& sheetFields = sheet->
GetFields();
3345 for(
const auto& [fieldName, fieldValue] : designBlock->GetFields() )
3347 sheetFields.emplace_back( sheet,
FIELD_T::USER, fieldName );
3348 sheetFields.back().SetText( fieldValue );
3349 sheetFields.back().SetVisible(
false );
3367 wxString pageNumber;
3370 std::set<int> usedPageNumbers;
3374 wxString existingPageNum =
path.GetPageNumber();
3377 if( existingPageNum.ToLong( &pageNum ) && pageNum > 0 )
3378 usedPageNumbers.insert(
static_cast<int>( pageNum ) );
3382 int nextAvailable = 1;
3384 while( usedPageNumbers.count( nextAvailable ) > 0 )
3387 pageNumber.Printf( wxT(
"%d" ), nextAvailable );
3393 else if( sheet && ( evt->IsClick(
BUT_LEFT ) || evt->IsDblClick(
BUT_LEFT )
3397 || ( startedWithDrag && evt->IsMouseUp(
BUT_LEFT ) ) ) )
3403 nullptr,
nullptr,
nullptr, &filename ) )
3415 m_frame->AddToScreen( sheet );
3420 m_frame->Schematic().RefreshHierarchy();
3426 && !( ( isDrawSheetCopy || isDrawSheetFromDesignBlock )
3448 sheetGroup->
SetName( designBlock->GetLibId().GetLibItemName() );
3455 c.
Push( isDrawSheetCopy ?
"Import Sheet Copy" :
"Draw Sheet" );
3462 if( ( isDrawSheetCopy || isDrawSheetFromDesignBlock )
3489 evt->SetPassEvent();
3498 m_frame->SetMsgPanel( sheet );
3514 evt->SetPassEvent();
3546 if( !sheetPaths.size() )
3550 m_frame, std::move( sheetPaths ),
3551 std::make_shared<SHEET_SYNCHRONIZATION_AGENT>(
3561 commit.
Push(
_(
"Modify sheet pin" ) );
3567 commit.
Push(
_(
"Modify schematic item" ) );
3578 selectionTool->AddItemToSel( aItem,
true );
3583 std::set<EDA_ITEM*> aTemplates )
3656 if( labels.empty() )
3660 m_statusPopup->SetText(
_(
"No new hierarchical labels found." ) );
3674 SCH_ITEM* lastPlacedLabel =
nullptr;
3676 auto calculatePositionForLabel =
3687 int currentWidth = currentLabel->GetBoundingBox().GetWidth();
3688 int currentHeight = currentLabel->GetBoundingBox().GetHeight();
3692 return { lastX + lastWidth, lastY };
3703 if( !lastPlacedLabel )
3705 std::vector<SCH_SHEET_PIN*> existingPins = sheet->
GetPins();
3707 if( !existingPins.empty() )
3709 std::sort( existingPins.begin(), existingPins.end(),
3712 return ( a->GetPosition().x < b->GetPosition().x )
3713 || ( a->GetPosition().x == b->GetPosition().x
3714 && a->GetPosition().y < b->GetPosition().y );
3717 lastPlacedLabel = existingPins.back();
3721 cursorPos = calculatePositionForLabel( lastPlacedLabel, label );
3738 commit.
Push(
_(
"Add Sheet Pin" ) );
3740 lastPlacedLabel = item;
3750 static const std::function<void( std::list<SCH_SHEET_PATH>&,
SCH_SCREEN*, std::set<SCH_SCREEN*>&,
3752 []( std::list<SCH_SHEET_PATH>& aPaths,
SCH_SCREEN* aScene, std::set<SCH_SCREEN*>& aVisited,
3755 if( ! aScene || aVisited.find(aScene) != aVisited.end() )
3758 std::vector<SCH_ITEM*> sheetChildren;
3759 aScene->GetSheets( &sheetChildren );
3760 aVisited.insert( aScene );
3762 for(
SCH_ITEM* child : sheetChildren )
3767 aPaths.push_back( cp );
3768 getSheetChildren( aPaths, sheet->
GetScreen(), aVisited, cp );
3772 std::list<SCH_SHEET_PATH> sheetPaths;
3773 std::set<SCH_SCREEN*> visited;
3776 std::vector<SCH_SHEET*> topLevelSheets =
m_frame->Schematic().GetTopLevelSheets();
3778 for(
SCH_SHEET* topSheet : topLevelSheets )
3780 if( topSheet && topSheet->GetScreen() )
3784 getSheetChildren( sheetPaths, topSheet->GetScreen(), visited, current );
3788 if( sheetPaths.size() == 0 )
3790 m_frame->ShowInfoBarMsg(
_(
"No sub schematic found in the current project" ) );
3805 std::vector<SCH_HIERLABEL*> labels;
3810 labels.push_back( label );
3813 std::sort( labels.begin(), labels.end(),
3816 return StrNumCmp( label1->GetText(), label2->GetText(), true ) < 0;
3821 if( !aSheet->
HasPin( label->GetText() ) )
3834 std::vector<SCH_HIERLABEL*> labels;
3841 labels.push_back( label );
constexpr EDA_IU_SCALE schIUScale
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
static TOOL_ACTION cancelInteractive
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
static TOOL_ACTION selectItems
Select a list of items (specified as the event parameter)
PANEL_DESIGN_BLOCK_CHOOSER m_DesignBlockChooserPanel
constexpr const Vec & GetPosition() const
constexpr size_type GetWidth() const
constexpr size_type GetHeight() const
constexpr bool Contains(const Vec &aPoint) const
constexpr const SizeVec & GetSize() 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.
LIB_ID GetSelectedLibId(int *aUnit=nullptr) const
DESIGN_BLOCK * GetDesignBlock(const LIB_ID &aLibId, bool aUseCacheLib, bool aShowErrorMsg)
Load design block from design block library table.
void SetFilenameOverride(const wxString &aFilenameOverride)
Set the filename override to be applied in TransferDataToWindow.
std::list< std::unique_ptr< EDA_ITEM > > & GetImportedItems()
bool IsPlacementInteractive()
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 VECTOR2I GetPosition() const
virtual void ClearEditFlags()
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 wxString GetFriendlyName() const
virtual EDA_ITEM * Clone() const
Create a duplicate of this item with linked list members set to NULL.
virtual void SetParent(EDA_ITEM *aParent)
FILL_T GetFillMode() const
void SetFillColor(const COLOR4D &aColor)
COLOR4D GetFillColor() const
void SetEnd(const VECTOR2I &aEnd)
const EDA_ANGLE & GetTextAngle() const
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)
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
A color representation with 4 components: red, green, blue, alpha.
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.
VECTOR2D GetCursorPosition() const
Return the current cursor position 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.
bool IsValid() const
Check if this LID_ID is valid.
wxString GetUniStringLibId() const
Define a library symbol object.
wxString GetDescription() const override
const LIB_ID & GetLibId() const override
wxString GetKeyWords() 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 drawTextBox
static TOOL_ACTION autoplaceFields
static TOOL_ACTION changeSymbol
static TOOL_ACTION syncAllSheetsPins
static TOOL_ACTION closeOutline
static TOOL_ACTION drawArc
static TOOL_ACTION drawSheet
static TOOL_ACTION properties
static TOOL_ACTION editReference
static TOOL_ACTION leaveSheet
static TOOL_ACTION ddImportGraphics
static TOOL_ACTION autoplaceAllSheetPins
static TOOL_ACTION drawRectangle
static TOOL_ACTION placeHierLabel
static TOOL_ACTION placeLabel
static TOOL_ACTION drawCircle
static TOOL_ACTION importGraphics
static TOOL_ACTION toText
static TOOL_ACTION placeBusWireEntry
static TOOL_ACTION toHLabel
static TOOL_ACTION drawBezier
static TOOL_ACTION rotateCW
static TOOL_ACTION importSheet
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 deleteLastPoint
static TOOL_ACTION editWithLibEdit
static TOOL_ACTION toDLabel
static TOOL_ACTION cycleBodyStyle
static TOOL_ACTION drawSheetFromDesignBlock
static TOOL_ACTION mirrorH
static TOOL_ACTION placeDesignBlock
static TOOL_ACTION setExcludeFromSimulation
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 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
void BeginEdit(const VECTOR2I &aStartPoint) override
Begin drawing a symbol library draw item at aPosition.
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
void EndEdit(bool aClosed=false) override
End an object editing action.
void SetStroke(const STROKE_PARAMS &aStroke) override
bool ContinueEdit(const VECTOR2I &aPosition) override
Continue an edit in progress at aPosition.
void CalcEdit(const VECTOR2I &aPosition) override
Calculate the attributes of an item at aPosition when it is being edited.
wxString GetClass() const override
Return the class name.
STROKE_PARAMS GetStroke() const 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.
void GetSymbols(SCH_REFERENCE_LIST &aReferences, bool aIncludePowerSymbols=true, 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 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.
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
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 void Add(EDA_ITEM *aItem)
VECTOR2I GetReferencePoint() const
virtual unsigned int GetSize() const override
Return the number of stored items.
virtual void Clear() override
Remove all the stored items from the group.
int Size() const
Returns the number of selected parts.
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.
LINE_STYLE
Dashed line types.
COLOR4D default_sheet_border_color
COLOR4D default_sheet_background_color
int default_line_thickness
POWER_SYMBOLS new_power_symbols
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.
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.