78 const auto inDrawingArc =
84 const auto inManagedShape = [
this](
const SELECTION& aSel )
143 aItem->ClearEditFlags();
152 aCommit.
Push( aDescription );
157 aCommit.
Add( aItem.release(),
frame()->GetScreen() );
158 aCommit.
Push( aDescription );
185 std::unique_ptr<SCH_SHAPE> item;
228 grid.SetUseGrid(
getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
234 bool isSyntheticClick = item && evt->IsActivate() && evt->HasPosition() && evt->Matches( aEvent );
236 if( evt->IsCancelInteractive() || ( item && evt->IsAction( &
ACTIONS::undo ) ) )
243 else if( evt->IsActivate() && !isSyntheticClick )
245 if( item && evt->IsMoveTool() )
248 evt->SetPassEvent(
false );
255 if( evt->IsPointEditor() )
261 if( evt->IsMoveTool() )
264 frame()->PushTool( originalEvent );
269 else if( !item && ( evt->IsClick(
BUT_LEFT )
278 textbox->SetTextSize(
VECTOR2I( defaultTextSize, defaultTextSize ) );
289 textbox->SetParent( parent );
291 item = std::move( textbox );
295 item = std::make_unique<SCH_SHAPE>( type, shapeLayer, 0,
m_lastFillStyle );
299 item->SetParent( parent );
306 item->BeginEdit( cursorPos );
309 m_view->AddToPreview( item->Clone() );
316 bool finished =
false;
317 bool closedShape =
false;
324 closedShape = !isLineTool;
328 finished = !item->ContinueEdit( cursorPos );
333 item->EndEdit( closedShape );
370 wxString msg = wxString::Format(
_(
"Draw %s" ), item->GetClass() );
394 || evt->IsMotion() ) )
396 item->CalcEdit( cursorPos );
398 m_view->AddToPreview( item->Clone() );
400 frame()->SetMsgPanel( item.get() );
402 else if( !item && ( evt->IsDblClick(
BUT_LEFT )
450 std::vector<VECTOR2D> initialPts;
452 const auto makeNewArc =
455 std::unique_ptr<SCH_SHAPE> arc = std::make_unique<SCH_SHAPE>(
SHAPE_T::ARC, shapeLayer, 0,
459 arc->SetParent( parent );
467 std::unique_ptr<SCH_SHAPE> arc = makeNewArc();
484 std::optional<ARC_TANGENT_SEED> tangentSeed;
508 commitItem( commit, std::move( arc ),
_(
"Draw Arc" ) );
535 std::vector<VECTOR2D> initialPts;
537 const auto makeNewEllipseArc =
544 arc->SetParent( parent );
552 std::unique_ptr<SCH_SHAPE> arc = makeNewEllipseArc();
578 commitItem( commit, std::move( arc ),
_(
"Draw Elliptical Arc" ) );
583 arc = makeNewEllipseArc();
605 std::vector<VECTOR2D> initialPts;
607 const auto makeNewBezier =
610 std::unique_ptr<SCH_SHAPE> bezier = std::make_unique<SCH_SHAPE>(
SHAPE_T::BEZIER, shapeLayer, 0,
614 bezier->SetParent( parent );
615 bezier->SetFlags(
IS_NEW );
622 std::unique_ptr<SCH_SHAPE> bezier = makeNewBezier();
647 initialPts.push_back( bezier->GetEnd() );
650 if( bezier->GetEnd() != bezier->GetBezierC2() )
652 VECTOR2D mirroredC1 = bezier->GetEnd() - ( bezier->GetBezierC2() - bezier->GetEnd() );
653 initialPts.push_back( mirroredC1 );
659 commitItem( commit, std::move( bezier ),
_(
"Draw Bezier" ) );
668 bezier = makeNewBezier();
678 grid.SetUseGrid(
getView()->GetGAL()->GetGridSnapping() );
686 const std::vector<VECTOR2D>& aInitialPts,
687 const std::optional<ARC_TANGENT_SEED>& aTangentSeed,
719 auto findTangentSeed =
720 [&](
const VECTOR2I& aMouse,
const VECTOR2I& aPos ) -> std::optional<ARC_TANGENT_SEED>
726 [&](
SCH_ITEM* aItem,
const VECTOR2I& aPos ) -> std::optional<ARC_TANGENT_SEED>
728 if( !aItem || aItem->
GetLayer() != layer )
750 if( std::optional<ARC_TANGENT_SEED> seed = seedFrom(
grid.GetSnapped(), snap.
position ) )
759 for(
SCH_ITEM& item : symbol->GetDrawItems() )
761 bool inUnit = item.GetUnit() ==
ALL_UNITS
762 || item.GetUnit() == symFrame->
GetUnit();
766 if( !inUnit || !inBodyStyle )
769 if( std::optional<ARC_TANGENT_SEED> seed = seedFrom( &item, aPos ) )
779 for(
SCH_ITEM* item :
frame()->GetScreen()->Items().Overlapping( type, aPos, tolerance ) )
781 if( std::optional<ARC_TANGENT_SEED> seed = seedFrom( item, aPos ) )
799 bool started =
false;
800 bool cancelled =
false;
801 bool finished =
false;
808 for(
const VECTOR2D& pt : aInitialPts )
809 arcSession.PlacePoint( pt, pt );
811 if( !aInitialPts.empty() || aTangentSeed )
818 preview.
Add( aShape.get() );
819 frame()->SetMsgPanel( aShape.get() );
828 grid.SetUseGrid(
getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
833 if( evt->IsCancelInteractive() )
839 evt->SetPassEvent(
false );
850 else if( arcSession.HandleModeEvent( *evt ) )
854 else if( evt->IsActivate() )
856 if( evt->IsPointEditor() )
862 if( evt->IsMoveTool() )
881 preview.
Add( aShape.get() );
882 frame()->SetMsgPanel( aShape.get() );
889 *aLastClick = cursorPos;
891 else if( evt->IsDblClick(
BUT_LEFT )
911 arcSession.RemoveLastPoint();
946 m_view->Update( &preview );
951 frame()->SetMsgPanel( aShape.get() );
953 frame()->SetMsgPanel( parent );
957 preview.
Remove( aShape.get() );
959 m_view->Remove( &preview );
962 frame()->SetMsgPanel( parent );
1009 if( dlgResult != wxID_OK )
1015 wxMessageBox(
_(
"No graphic items found in file." ) );
1022 std::vector<SCH_ITEM*> newItems;
1023 std::vector<SCH_ITEM*> selectedItems;
1028 [&](
const std::vector<SCH_ITEM*>& aItems )
1038 item->ClearEditFlags();
1044 commit.
Add( item,
frame()->GetScreen() );
1047 commit.
Push(
_(
"Import Graphic" ) );
1053 for( std::unique_ptr<EDA_ITEM>& ptr : list )
1055 EDA_ITEM* eda_item = ptr.release();
1058 wxCHECK2_MSG( item,
continue, wxString::Format(
"Bad item type: ", eda_item->
Type() ) );
1060 newItems.push_back( item );
1061 selectedItems.push_back( item );
1062 preview.
Add( item );
1067 commitImport( newItems );
1075 EDA_ITEMS selItems( selectedItems.begin(), selectedItems.end() );
1097 for(
SCH_ITEM* item : selectedItems )
1098 item->Move(
delta );
1100 currentOffset +=
delta;
1101 m_view->Update( &preview );
1109 grid.SetUseGrid(
getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
1114 if( evt->IsCancelInteractive() || evt->IsActivate() )
1125 delta = cursorPos - currentOffset;
1127 for(
SCH_ITEM* item : selectedItems )
1128 item->Move(
delta );
1130 currentOffset +=
delta;
1131 m_view->Update( &preview );
1140 commitImport( newItems );
1145 evt->SetPassEvent();
1150 m_view->Remove( &preview );
ARC_DRAW_MODE
Construction sequence used when interactively drawing a circular arc.
@ TANGENT
End only; start and departure direction come from a tangent seed.
ARC_DRAW_MODE StartArcDrawMode(const TOOL_EVENT &aEvent, APP_SETTINGS_BASE *aSettings, SHAPE_DRAW_BEHAVIOR &aBehavior)
Pick the mode a Draw Arc action starts in and apply it to aBehavior.
std::optional< ARC_TANGENT_SEED > ArcTangentSeedNear(const EDA_SHAPE &aShape, const VECTOR2I &aNear)
Seed the next tangent arc from whichever endpoint of aShape lies nearest aNear.
std::optional< ARC_TANGENT_SEED > ArcTangentSeedAt(const SEG &aSegment, const VECTOR2I &aPoint, int aTolerance)
Tangent seed for a point on or near a segment, arc or Bezier shape.
constexpr int ARC_SEED_PICK_PIXELS
Screen distance in pixels within which a click picks a graphic to start a tangent arc from.
constexpr EDA_IU_SCALE schIUScale
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
static TOOL_ACTION cancelInteractive
static TOOL_ACTION arcPosture
static TOOL_ACTION updateUnits
static TOOL_ACTION deleteLastPoint
static TOOL_ACTION cursorDblClick
static TOOL_ACTION duplicate
static TOOL_ACTION cycleArcDrawMode
static TOOL_ACTION activatePointEditor
static TOOL_ACTION doDelete
static TOOL_ACTION cursorClick
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)
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
ARC_DRAW_MODE m_ArcDrawMode
Construction sequence last used by the arc drawing tool in this application.
Interactive arc drawing behaviour.
Arc drawing mode and tangent seed bookkeeping for one pass of an editor's managed-shape draw loop.
Interactive bezier drawing behaviour: start -> control1 -> end -> control2.
constexpr BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
constexpr bool Contains(const Vec &aPoint) const
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.
void SetFilenameOverride(const wxString &aFilenameOverride)
Set the filename override to be applied in TransferDataToWindow.
std::list< std::unique_ptr< EDA_ITEM > > & GetImportedItems()
bool IsPlacementInteractive()
A base class for most all the KiCad significant classes used in schematics and boards.
virtual const BOX2I GetBoundingBox() const
Return the orthogonal bounding box of this object for display purposes.
KICAD_T Type() const
Returns the type of object.
FILL_T GetFillMode() const
COLOR4D GetFillColor() const
GR_TEXT_H_ALIGN_T GetHorizJustify() const
virtual EDA_ANGLE GetTextAngle() const
GR_TEXT_V_ALIGN_T GetVertJustify() const
Interactive elliptical-arc drawing behaviour: bbox corner 1 -> bbox corner 2 -> start angle -> end an...
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.
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 SetAutoPan(bool aEnabled)
Turn on/off auto panning (this feature is used when there is a tool active (eg.
Define a library symbol object.
void AddDrawItem(SCH_ITEM *aItem, bool aSort=true)
Add a new draw aItem to the draw object list and sort according to aSort.
static TOOL_ACTION drawArcCenter
static TOOL_ACTION drawArcStartEndCenter
static TOOL_ACTION drawEllipseArc
static TOOL_ACTION drawTextBox
static TOOL_ACTION drawArc
static TOOL_ACTION drawSymbolLines
static TOOL_ACTION drawSymbolTextBox
static TOOL_ACTION properties
static TOOL_ACTION ddImportGraphics
static TOOL_ACTION drawRectangle
static TOOL_ACTION drawEllipse
static TOOL_ACTION drawCircle
static TOOL_ACTION importGraphics
static TOOL_ACTION drawArcTangent
static TOOL_ACTION drawBezier
static TOOL_ACTION drawSymbolPolygon
static TOOL_ACTION drawPolygon
static TOOL_ACTION drawArcStartDirEnd
static TOOL_ACTION drawArcStartEndMid
static TOOL_ACTION repeatDrawItem
static const TOOL_ACTION & DrawArcForMode(ARC_DRAW_MODE aMode)
Tool action that starts the arc tool in the given mode.
A shim class between EDA_DRAW_FRAME and several derived classes: SYMBOL_EDIT_FRAME,...
Commit for the schematic and symbol editors.
void Push(const wxString &aMessage=wxEmptyString, int aCommitFlags=0) override
Execute the changes.
Base class for any item which can be embedded within the SCHEMATIC container class,...
virtual void SetBodyStyle(int aBodyStyle)
SCH_LAYER_ID GetLayer() const
Return the layer this item is on.
virtual void SetUnit(int aUnit)
Segment description base class to describe items which have 2 end points (track, wire,...
bool IsGraphicLine() const
Return if the line is a graphic (non electrical line)
STROKE_PARAMS GetStroke() const override
RAII class that sets an value at construction and resets it to the original value at destruction.
virtual void Add(EDA_ITEM *aItem)
A null aItem is ignored; the selection never holds null members.
virtual void Remove(EDA_ITEM *aItem)
virtual void Clear() override
Remove all the stored items from the group.
Abstract interface for interactive shape-drawing behaviours.
virtual void Reset()=0
Reset the behaviour to its initial state for chained object creation loops.
virtual bool IsComplete() const =0
True when all points have been locked in.
virtual void SetCursorPosition(const VECTOR2I &aPosition)=0
Preview the cursor position without advancing state.
virtual void SetUnits(EDA_UNITS aUnits)=0
Forward a units change to the assistant overlay.
virtual bool HasGeometryChanged() const =0
True if the geometry changed since the last call to ClearGeometryChanged().
virtual EDA_ITEM & GetAssistant()=0
Return the visual assistant overlay item.
virtual void ClearGeometryChanged()=0
Reset the geometry-changed flag (call after updating the preview).
virtual void ApplyToShape(EDA_SHAPE &aShape) const =0
Transfer the current geometry to an EDA_SHAPE.
virtual void ToggleClockwise()
Flip arc direction (applies only when the shape has such a concept of directionality,...
The symbol library editor main window.
bool GetDrawSpecificUnit() const
bool GetDrawSpecificBodyStyle() const
LIB_SYMBOL * GetCurSymbol() const
Return the current symbol being edited or NULL if none selected.
bool IsSymbolGraphicallyEditable() const
Test if a symbol is loaded and can be edited graphically.
#define DEFAULT_TEXT_SIZE
The default text size in mils. (can be changed in preference menu)
static constexpr EDA_ANGLE ANGLE_0
#define IS_NEW
New item, just created.
@ RECTANGLE
Use RECTANGLE instead of RECT to avoid collision in a Windows header.
SCH_LAYER_ID
Eeschema drawing layers.
std::vector< EDA_ITEM * > EDA_ITEMS
SHAPE_DRAW_RESULT
Outcome of an interactive shape drawing loop, telling the caller how to continue.
@ NEXT_SHAPE
Commit the shape, if any, and start drawing another.
@ FINISHED
The user finished; commit the shape, if any, and stop drawing.
@ CANCELLED
The user cancelled; nothing to commit, stop drawing.
LINE_STYLE
Dashed line types.
wxString result
Test unit parsing edge cases and error handling.
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
VECTOR2< int32_t > VECTOR2I
VECTOR2< double > VECTOR2D