diff --git a/gerbview/class_gerber_draw_item.h b/gerbview/class_gerber_draw_item.h index 31c7066dcd..16a17515d4 100644 --- a/gerbview/class_gerber_draw_item.h +++ b/gerbview/class_gerber_draw_item.h @@ -194,7 +194,7 @@ public: * @return const wxPoint& - The position of this object. * This function exists mainly to satisfy the virtual GetPosition() in parent class */ - const wxPoint& GetPosition() const { return m_Start; } + const wxPoint GetPosition() const { return m_Start; } void SetPosition( const wxPoint& aPos ) { m_Start = aPos; } /** diff --git a/include/class_board_item.h b/include/class_board_item.h index 66054cd3ad..8cc841f3df 100644 --- a/include/class_board_item.h +++ b/include/class_board_item.h @@ -84,7 +84,7 @@ public: // Do not create a copy constructor & operator=. // The ones generated by the compiler are adequate. - virtual const wxPoint& GetPosition() const = 0; + virtual const wxPoint GetPosition() const = 0; /** * Function GetCenter() diff --git a/include/worksheet_shape_builder.h b/include/worksheet_shape_builder.h index 32bc63db80..7b7c1f6363 100644 --- a/include/worksheet_shape_builder.h +++ b/include/worksheet_shape_builder.h @@ -211,7 +211,7 @@ public: // Accessors: int GetPenWidth() const { return m_penWidth; } bool IsFilled() const { return m_fill; } - const wxPoint& GetPosition() const { return m_pos; } + const wxPoint GetPosition() const { return m_pos; } /** The function to draw a WS_DRAW_ITEM_POLYGON */ @@ -361,7 +361,7 @@ public: */ virtual bool HitTestStartPoint( const wxPoint& aPosition) override; - const wxPoint& GetPosition() { return m_pos; } + const wxPoint GetPosition() { return m_pos; } }; /* diff --git a/pcbnew/class_board.cpp b/pcbnew/class_board.cpp index 53eebbd48d..da674a64f6 100644 --- a/pcbnew/class_board.cpp +++ b/pcbnew/class_board.cpp @@ -135,7 +135,7 @@ void BOARD::BuildConnectivity() } -const wxPoint& BOARD::GetPosition() const +const wxPoint BOARD::GetPosition() const { wxLogWarning( wxT( "This should not be called on the BOARD object") ); diff --git a/pcbnew/class_board.h b/pcbnew/class_board.h index 7c2ed4747d..ade950aae0 100644 --- a/pcbnew/class_board.h +++ b/pcbnew/class_board.h @@ -261,7 +261,7 @@ public: BOARD(); ~BOARD(); - virtual const wxPoint& GetPosition() const override; + virtual const wxPoint GetPosition() const override; virtual void SetPosition( const wxPoint& aPos ) override; diff --git a/pcbnew/class_dimension.cpp b/pcbnew/class_dimension.cpp index b8a42620e5..390f8f3f4e 100644 --- a/pcbnew/class_dimension.cpp +++ b/pcbnew/class_dimension.cpp @@ -65,7 +65,7 @@ void DIMENSION::SetPosition( const wxPoint& aPos ) } -const wxPoint& DIMENSION::GetPosition() const +const wxPoint DIMENSION::GetPosition() const { return m_Text.GetTextPos(); } diff --git a/pcbnew/class_dimension.h b/pcbnew/class_dimension.h index 961104ce6d..103d59af30 100644 --- a/pcbnew/class_dimension.h +++ b/pcbnew/class_dimension.h @@ -87,7 +87,7 @@ public: int GetValue() const { return m_Value; } - const wxPoint& GetPosition() const override; + const wxPoint GetPosition() const override; void SetPosition( const wxPoint& aPos ) override; diff --git a/pcbnew/class_drawsegment.cpp b/pcbnew/class_drawsegment.cpp index 8df4105c20..ed3f3a1e7b 100644 --- a/pcbnew/class_drawsegment.cpp +++ b/pcbnew/class_drawsegment.cpp @@ -66,6 +66,37 @@ DRAWSEGMENT::~DRAWSEGMENT() { } +void DRAWSEGMENT::SetPosition( const wxPoint& aPos ) +{ + m_Start = aPos; +} + +const wxPoint DRAWSEGMENT::GetPosition() const +{ + if( m_Shape == S_POLYGON ) + return (wxPoint) m_Poly.CVertex( 0 ); + else + return m_Start; +} + +void DRAWSEGMENT::Move( const wxPoint& aMoveVector ) +{ + m_Start += aMoveVector; + m_End += aMoveVector; + + switch ( m_Shape ) + { + case S_POLYGON: + for( auto iter = m_Poly.Iterate(); iter; iter++ ) + { + (*iter) += VECTOR2I( aMoveVector ); + } + break; + default: + break; + } +} + void DRAWSEGMENT::Rotate( const wxPoint& aRotCentre, double aAngle ) { @@ -110,8 +141,20 @@ void DRAWSEGMENT::Flip( const wxPoint& aCentre ) m_Start.y = aCentre.y - (m_Start.y - aCentre.y); m_End.y = aCentre.y - (m_End.y - aCentre.y); - if( m_Shape == S_ARC ) + switch ( m_Shape ) + { + case S_ARC: m_Angle = -m_Angle; + break; + case S_POLYGON: + for( auto iter = m_Poly.Iterate(); iter; iter++ ) + { + iter->y = aCentre.y - (iter->y - aCentre.y); + } + break; + default: + break; + } // DRAWSEGMENT items are not allowed on copper layers, so // copper layers count is not taken in accoun in Flip transform @@ -164,7 +207,7 @@ const wxPoint DRAWSEGMENT::GetArcEnd() const break; default: - ; + break; } return endPoint; // after rotation, the end of the arc. diff --git a/pcbnew/class_drawsegment.h b/pcbnew/class_drawsegment.h index d892172f6d..610070986e 100644 --- a/pcbnew/class_drawsegment.h +++ b/pcbnew/class_drawsegment.h @@ -99,8 +99,8 @@ public: void SetBezControl2( const wxPoint& aPoint ) { m_BezierC2 = aPoint; } const wxPoint& GetBezControl2() const { return m_BezierC2; } - void SetPosition( const wxPoint& aPos ) override { m_Start = aPos; } - const wxPoint& GetPosition() const override { return m_Start; } + void SetPosition( const wxPoint& aPos ) override; + const wxPoint GetPosition() const override; /** * Function GetStart @@ -205,11 +205,7 @@ public: return GetLineLength( GetStart(), GetEnd() ); } - virtual void Move( const wxPoint& aMoveVector ) override - { - m_Start += aMoveVector; - m_End += aMoveVector; - } + virtual void Move( const wxPoint& aMoveVector ) override; virtual void Rotate( const wxPoint& aRotCentre, double aAngle ) override; diff --git a/pcbnew/class_marker_pcb.h b/pcbnew/class_marker_pcb.h index 904affc2a9..1384effb20 100644 --- a/pcbnew/class_marker_pcb.h +++ b/pcbnew/class_marker_pcb.h @@ -85,7 +85,7 @@ public: DrawMarker( aPanel, aDC, aDrawMode, aOffset ); } - const wxPoint& GetPosition() const override { return m_Pos; } + const wxPoint GetPosition() const override { return m_Pos; } void SetPosition( const wxPoint& aPos ) override { m_Pos = aPos; } void SetItem( const BOARD_ITEM* aItem ) diff --git a/pcbnew/class_module.h b/pcbnew/class_module.h index b6fc008072..3c39dccbd5 100644 --- a/pcbnew/class_module.h +++ b/pcbnew/class_module.h @@ -172,7 +172,7 @@ public: void SetPosition( const wxPoint& aPos ) override; - const wxPoint& GetPosition() const override { return m_Pos; } + const wxPoint GetPosition() const override { return m_Pos; } void SetOrientation( double newangle ); diff --git a/pcbnew/class_netinfo.h b/pcbnew/class_netinfo.h index 3ed89459c5..e878744012 100644 --- a/pcbnew/class_netinfo.h +++ b/pcbnew/class_netinfo.h @@ -103,7 +103,7 @@ public: } #endif - const wxPoint& GetPosition() const override + const wxPoint GetPosition() const override { static wxPoint dummy(0, 0); return dummy; diff --git a/pcbnew/class_pad.h b/pcbnew/class_pad.h index bc1c9f118f..ec89a5317d 100644 --- a/pcbnew/class_pad.h +++ b/pcbnew/class_pad.h @@ -217,7 +217,7 @@ public: void SetShape( PAD_SHAPE_T aShape ) { m_padShape = aShape; m_boundingRadius = -1; } void SetPosition( const wxPoint& aPos ) override { m_Pos = aPos; } - const wxPoint& GetPosition() const override { return m_Pos; } + const wxPoint GetPosition() const override { return m_Pos; } /** * Function GetAnchorPadShape diff --git a/pcbnew/class_pcb_target.h b/pcbnew/class_pcb_target.h index 368c85d6a1..95bcb29645 100644 --- a/pcbnew/class_pcb_target.h +++ b/pcbnew/class_pcb_target.h @@ -59,7 +59,7 @@ public: ~PCB_TARGET(); void SetPosition( const wxPoint& aPos ) override { m_Pos = aPos; } - const wxPoint& GetPosition() const override { return m_Pos; } + const wxPoint GetPosition() const override { return m_Pos; } void SetShape( int aShape ) { m_Shape = aShape; } int GetShape() const { return m_Shape; } diff --git a/pcbnew/class_pcb_text.h b/pcbnew/class_pcb_text.h index 8af0d1e977..24bc52212a 100644 --- a/pcbnew/class_pcb_text.h +++ b/pcbnew/class_pcb_text.h @@ -55,7 +55,7 @@ public: return aItem && PCB_TEXT_T == aItem->Type(); } - virtual const wxPoint& GetPosition() const override + virtual const wxPoint GetPosition() const override { return EDA_TEXT::GetTextPos(); } diff --git a/pcbnew/class_text_mod.h b/pcbnew/class_text_mod.h index 3ed3b017a8..eb4318e080 100644 --- a/pcbnew/class_text_mod.h +++ b/pcbnew/class_text_mod.h @@ -74,7 +74,7 @@ public: return aItem && PCB_MODULE_TEXT_T == aItem->Type(); } - virtual const wxPoint& GetPosition() const override + virtual const wxPoint GetPosition() const override { return EDA_TEXT::GetTextPos(); } diff --git a/pcbnew/class_track.h b/pcbnew/class_track.h index 0509c74e80..67980d61fb 100644 --- a/pcbnew/class_track.h +++ b/pcbnew/class_track.h @@ -111,7 +111,7 @@ public: virtual void Flip( const wxPoint& aCentre ) override; void SetPosition( const wxPoint& aPos ) override { m_Start = aPos; } - const wxPoint& GetPosition() const override { return m_Start; } + const wxPoint GetPosition() const override { return m_Start; } void SetWidth( int aWidth ) { m_Width = aWidth; } int GetWidth() const { return m_Width; } @@ -412,7 +412,7 @@ public: */ void LayerPair( PCB_LAYER_ID* top_layer, PCB_LAYER_ID* bottom_layer ) const; - const wxPoint& GetPosition() const override { return m_Start; } + const wxPoint GetPosition() const override { return m_Start; } void SetPosition( const wxPoint& aPoint ) override { m_Start = aPoint; m_End = aPoint; } virtual bool HitTest( const wxPoint& aPosition ) const override; diff --git a/pcbnew/class_zone.cpp b/pcbnew/class_zone.cpp index 35652ecbbc..436bd6ab26 100644 --- a/pcbnew/class_zone.cpp +++ b/pcbnew/class_zone.cpp @@ -163,15 +163,9 @@ bool ZONE_CONTAINER::UnFill() } -const wxPoint& ZONE_CONTAINER::GetPosition() const +const wxPoint ZONE_CONTAINER::GetPosition() const { - const WX_VECTOR_CONVERTER* pos; - - // The retrieved vertex is a VECTOR2I. Casting it to a union WX_VECTOR_CONVERTER, we can later - // return the object shaped as a wxPoint. See the definition of the union in class_zone.h for - // more information on this hack. - pos = reinterpret_cast( &GetCornerPosition( 0 ) ); - return pos->wx; + return (wxPoint) GetCornerPosition( 0 ); } diff --git a/pcbnew/class_zone.h b/pcbnew/class_zone.h index 9603e5b4e6..5d6b162cc6 100644 --- a/pcbnew/class_zone.h +++ b/pcbnew/class_zone.h @@ -85,7 +85,7 @@ public: * * @return a wxPoint, position of the first point of the outline */ - const wxPoint& GetPosition() const override; + const wxPoint GetPosition() const override; void SetPosition( const wxPoint& aPos ) override {} /** diff --git a/pcbnew/pcb_painter.cpp b/pcbnew/pcb_painter.cpp index 6d0c4130d7..08c22dc1e7 100644 --- a/pcbnew/pcb_painter.cpp +++ b/pcbnew/pcb_painter.cpp @@ -932,12 +932,7 @@ void PCB_PAINTER::draw( const DRAWSEGMENT* aSegment, int aLayer ) m_gal->Translate( module->GetPosition() ); m_gal->Rotate( -module->GetOrientationRadians() ); } - else - { - m_gal->Translate( aSegment->GetPosition() ); - m_gal->Rotate( DECIDEG2RAD( -aSegment->GetAngle() ) ); - } - + std::copy( points.begin(), points.end(), std::back_inserter( pointsList ) ); pointsList.push_back( points[0] ); diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index 4cab7c1e6e..0462a55fcf 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -427,7 +427,9 @@ int EDIT_TOOL::Main( const TOOL_EVENT& aEvent ) // Drag items to the current cursor position for( auto item : selection ) + { static_cast( item )->Move( movement ); + } } else if( !m_dragging ) // Prepare to start dragging { diff --git a/pcbnew/tools/grid_helper.cpp b/pcbnew/tools/grid_helper.cpp index dc04749be2..815e21a7dc 100644 --- a/pcbnew/tools/grid_helper.cpp +++ b/pcbnew/tools/grid_helper.cpp @@ -355,7 +355,10 @@ void GRID_HELPER::computeAnchors( BOARD_ITEM* aItem, const VECTOR2I& aRefPos ) case S_POLYGON: { - // no anchors for the moment + for( const auto& p : dseg->GetPolyPoints() ) + { + addAnchor( p, CORNER | SNAPPABLE, dseg ); + } break; } diff --git a/pcbnew/tools/point_editor.cpp b/pcbnew/tools/point_editor.cpp index 819221dbbd..8408dbf92e 100644 --- a/pcbnew/tools/point_editor.cpp +++ b/pcbnew/tools/point_editor.cpp @@ -615,6 +615,15 @@ void POINT_EDITOR::updatePoints() m_editPoints->Point( CIRC_END ).SetPosition( segment->GetEnd() ); break; + case S_POLYGON: + { + const auto& points = segment->GetPolyPoints(); + for( int i = 0; i < points.size(); i++ ) + { + m_editPoints->Point( i ).SetPosition( points[i] ); + } + break; + } default: // suppress warnings break; }