81 const auto inDrawingArc =
87 const auto inManagedShape = [
this](
const SELECTION& aSel )
146 aItem->ClearEditFlags();
155 aCommit.
Push( aDescription );
160 aCommit.
Add( aItem.release(),
frame()->GetScreen() );
161 aCommit.
Push( aDescription );
188 std::unique_ptr<SCH_SHAPE> item;
231 grid.SetUseGrid(
getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
237 bool isSyntheticClick = item && evt->IsActivate() && evt->HasPosition() && evt->Matches( aEvent );
239 if( evt->IsCancelInteractive() || ( item && evt->IsAction( &
ACTIONS::undo ) ) )
246 else if( evt->IsActivate() && !isSyntheticClick )
248 if( item && evt->IsMoveTool() )
251 evt->SetPassEvent(
false );
258 if( evt->IsPointEditor() )
264 if( evt->IsMoveTool() )
267 frame()->PushTool( originalEvent );
272 else if( !item && ( evt->IsClick(
BUT_LEFT )
281 textbox->SetTextSize(
VECTOR2I( defaultTextSize, defaultTextSize ) );
292 textbox->SetParent( parent );
294 item = std::move( textbox );
298 item = std::make_unique<SCH_SHAPE>( type, shapeLayer, 0,
m_lastFillStyle );
302 item->SetParent( parent );
309 item->BeginEdit( cursorPos );
312 m_view->AddToPreview( item->Clone() );
319 bool finished =
false;
320 bool closedShape =
false;
327 closedShape = !isLineTool;
331 finished = !item->ContinueEdit( cursorPos );
336 item->EndEdit( closedShape );
373 wxString msg = wxString::Format(
_(
"Draw %s" ), item->GetClass() );
397 || evt->IsMotion() ) )
399 item->CalcEdit( cursorPos );
401 m_view->AddToPreview( item->Clone() );
403 frame()->SetMsgPanel( item.get() );
405 else if( !item && ( evt->IsDblClick(
BUT_LEFT )
453 std::vector<VECTOR2D> initialPts;
455 const auto makeNewArc =
458 std::unique_ptr<SCH_SHAPE> arc = std::make_unique<SCH_SHAPE>(
SHAPE_T::ARC, shapeLayer, 0,
462 arc->SetParent( parent );
470 std::unique_ptr<SCH_SHAPE> arc = makeNewArc();
487 std::optional<ARC_TANGENT_SEED> tangentSeed;
511 commitItem( commit, std::move( arc ),
_(
"Draw Arc" ) );
538 std::vector<VECTOR2D> initialPts;
540 const auto makeNewEllipseArc =
547 arc->SetParent( parent );
555 std::unique_ptr<SCH_SHAPE> arc = makeNewEllipseArc();
581 commitItem( commit, std::move( arc ),
_(
"Draw Elliptical Arc" ) );
586 arc = makeNewEllipseArc();
608 std::vector<VECTOR2D> initialPts;
610 const auto makeNewBezier =
613 std::unique_ptr<SCH_SHAPE> bezier = std::make_unique<SCH_SHAPE>(
SHAPE_T::BEZIER, shapeLayer, 0,
617 bezier->SetParent( parent );
618 bezier->SetFlags(
IS_NEW );
625 std::unique_ptr<SCH_SHAPE> bezier = makeNewBezier();
650 initialPts.push_back( bezier->GetEnd() );
653 if( bezier->GetEnd() != bezier->GetBezierC2() )
655 VECTOR2D mirroredC1 = bezier->GetEnd() - ( bezier->GetBezierC2() - bezier->GetEnd() );
656 initialPts.push_back( mirroredC1 );
662 commitItem( commit, std::move( bezier ),
_(
"Draw Bezier" ) );
671 bezier = makeNewBezier();
681 grid.SetUseGrid(
getView()->GetGAL()->GetGridSnapping() );
689 const std::vector<VECTOR2D>& aInitialPts,
690 const std::optional<ARC_TANGENT_SEED>& aTangentSeed,
722 auto findTangentSeed =
723 [&](
const VECTOR2I& aMouse,
const VECTOR2I& aPos ) -> std::optional<ARC_TANGENT_SEED>
729 [&](
SCH_ITEM* aItem,
const VECTOR2I& aSeedPos ) -> std::optional<ARC_TANGENT_SEED>
731 if( !aItem || aItem->
GetLayer() != layer )
753 if( std::optional<ARC_TANGENT_SEED> seed = seedFrom(
grid.GetSnapped(), snap.
position ) )
762 for(
SCH_ITEM& item : symbol->GetDrawItems() )
764 bool inUnit = item.GetUnit() ==
ALL_UNITS
765 || item.GetUnit() == symFrame->
GetUnit();
769 if( !inUnit || !inBodyStyle )
772 if( std::optional<ARC_TANGENT_SEED> seed = seedFrom( &item, aPos ) )
782 for(
SCH_ITEM* item :
frame()->GetScreen()->Items().Overlapping( type, aPos, tolerance ) )
784 if( std::optional<ARC_TANGENT_SEED> seed = seedFrom( item, aPos ) )
802 bool started =
false;
803 bool cancelled =
false;
804 bool finished =
false;
811 for(
const VECTOR2D& pt : aInitialPts )
812 arcSession.PlacePoint( pt, pt );
814 if( !aInitialPts.empty() || aTangentSeed )
821 preview.
Add( aShape.get() );
822 frame()->SetMsgPanel( aShape.get() );
829 while( ( evt =
Wait() ) )
855 else if( arcSession.HandleModeEvent( *evt ) )
886 preview.
Add( aShape.get() );
887 frame()->SetMsgPanel( aShape.get() );
894 *aLastClick = cursorPos;
916 arcSession.RemoveLastPoint();
951 m_view->Update( &preview );
956 frame()->SetMsgPanel( aShape.get() );
958 frame()->SetMsgPanel( parent );
966 preview.
Remove( aShape.get() );
968 m_view->Remove( &preview );
971 frame()->SetMsgPanel( parent );
1008 std::unique_ptr<GRAPHICS_IMPORTER> importer;
1013 importer = std::make_unique<GRAPHICS_IMPORTER_LIB_SYMBOL>( symFrame->
GetCurSymbol(), symFrame->
GetUnit() );
1017 importer = std::make_unique<GRAPHICS_IMPORTER_SCH>();
1031 if( dlgResult != wxID_OK )
1037 wxMessageBox(
_(
"No graphic items found in file." ) );
1044 std::vector<SCH_ITEM*> newItems;
1045 std::vector<SCH_ITEM*> selectedItems;
1054 newItems.push_back(
group );
1055 selectedItems.push_back(
group );
1060 [&](
const std::vector<SCH_ITEM*>& aItems )
1070 item->ClearEditFlags();
1076 commit.
Add( item,
frame()->GetScreen() );
1079 commit.
Push(
_(
"Import Graphic" ) );
1085 for( std::unique_ptr<EDA_ITEM>& ptr : list )
1087 EDA_ITEM* eda_item = ptr.release();
1090 wxCHECK2_MSG( item,
continue, wxString::Format(
"Bad item type: ", eda_item->
Type() ) );
1092 newItems.push_back( item );
1093 preview.
Add( item );
1096 group->AddItem( item );
1098 selectedItems.push_back( item );
1103 commitImport( newItems );
1111 EDA_ITEMS selItems( selectedItems.begin(), selectedItems.end() );
1133 for(
SCH_ITEM* item : selectedItems )
1134 item->Move(
delta );
1136 currentOffset +=
delta;
1137 m_view->Update( &preview );
1145 grid.SetUseGrid(
getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
1150 if( evt->IsCancelInteractive() || evt->IsActivate() )
1161 delta = cursorPos - currentOffset;
1163 for(
SCH_ITEM* item : selectedItems )
1164 item->Move(
delta );
1166 currentOffset +=
delta;
1167 m_view->Update( &preview );
1176 commitImport( newItems );
1181 evt->SetPassEvent();
1186 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.
Import a graphics file into whichever editor opened the dialog.
std::list< std::unique_ptr< EDA_ITEM > > & GetImportedItems()
bool IsPlacementInteractive()
void SetFilenameOverride(const wxString &aFilenameOverride)
Set the filename override to be applied in TransferDataToWindow.
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.
A set of SCH_ITEMs (i.e., without duplicates).
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.
Class to handle a set of SCH_ITEMs.
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