From b2d25c66e794a3b653ecb138690ac6a37d21d521 Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Fri, 26 Sep 2025 10:14:59 -0700 Subject: [PATCH] ADDED: Wire/Bus/Line start/end/length properties --- common/properties/pg_properties.cpp | 8 +++++ eeschema/sch_line.cpp | 47 +++++++++++++++++++++++++++++ eeschema/sch_line.h | 9 ++++++ 3 files changed, 64 insertions(+) diff --git a/common/properties/pg_properties.cpp b/common/properties/pg_properties.cpp index e3e649c296..95a601c0e4 100644 --- a/common/properties/pg_properties.cpp +++ b/common/properties/pg_properties.cpp @@ -348,6 +348,14 @@ wxString PGPROPERTY_DISTANCE::DistanceToString( wxVariant& aVariant, wxString PGPROPERTY_DISTANCE::DistanceToString( wxVariant& aVariant, int aFlags ) const #endif { + if( aVariant.GetType() == wxPG_VARIANT_TYPE_DOUBLE ) + { + double distanceIU = aVariant.GetDouble(); + ORIGIN_TRANSFORMS& transforms = m_parentFrame->GetOriginTransforms(); + distanceIU = transforms.ToDisplay( distanceIU, m_coordType ); + return m_parentFrame->StringFromValue( distanceIU, true, EDA_DATA_TYPE::DISTANCE ); + } + long distanceIU; if( aVariant.GetType() == wxT( "std::optional" ) ) diff --git a/eeschema/sch_line.cpp b/eeschema/sch_line.cpp index 9cb605f9fc..9429e31ce5 100644 --- a/eeschema/sch_line.cpp +++ b/eeschema/sch_line.cpp @@ -42,6 +42,8 @@ #include #include #include +#include +#include SCH_LINE::SCH_LINE( const VECTOR2I& pos, int layer ) : @@ -250,6 +252,32 @@ double SCH_LINE::GetLength() const } +void SCH_LINE::SetLength( double aLength ) +{ + if( aLength < 0.0 ) + aLength = 0.0; + + double currentLength = GetLength(); + VECTOR2I start = GetStartPoint(); + VECTOR2I end; + + if( currentLength <= 0.0 ) + { + end = VECTOR2I( start.x + KiROUND( aLength ), start.y ); + } + else + { + VECTOR2I delta = GetEndPoint() - start; + double scale = aLength / currentLength; + + end = VECTOR2I( start.x + KiROUND( delta.x * scale ), + start.y + KiROUND( delta.y * scale ) ); + } + + SetEndPoint( end ); +} + + void SCH_LINE::SetLineColor( const COLOR4D& aColor ) { m_stroke.SetColor( aColor ); @@ -1245,6 +1273,25 @@ static struct SCH_LINE_DESC return false; }; + propMgr.AddProperty( new PROPERTY( _HKI( "Start X" ), + &SCH_LINE::SetStartX, &SCH_LINE::GetStartX, PROPERTY_DISPLAY::PT_COORD, + ORIGIN_TRANSFORMS::ABS_X_COORD ) ); + + propMgr.AddProperty( new PROPERTY( _HKI( "Start Y" ), + &SCH_LINE::SetStartY, &SCH_LINE::GetStartY, PROPERTY_DISPLAY::PT_COORD, + ORIGIN_TRANSFORMS::ABS_Y_COORD ) ); + + propMgr.AddProperty( new PROPERTY( _HKI( "End X" ), + &SCH_LINE::SetEndX, &SCH_LINE::GetEndX, PROPERTY_DISPLAY::PT_COORD, + ORIGIN_TRANSFORMS::ABS_X_COORD ) ); + + propMgr.AddProperty( new PROPERTY( _HKI( "End Y" ), + &SCH_LINE::SetEndY, &SCH_LINE::GetEndY, PROPERTY_DISPLAY::PT_COORD, + ORIGIN_TRANSFORMS::ABS_Y_COORD ) ); + + propMgr.AddProperty( new PROPERTY( _HKI( "Length" ), + &SCH_LINE::SetLength, &SCH_LINE::GetLength, PROPERTY_DISPLAY::PT_SIZE ) ); + propMgr.AddProperty( new PROPERTY_ENUM( _HKI( "Line Style" ), &SCH_LINE::SetLineStyle, &SCH_LINE::GetLineStyle ) ) .SetAvailableFunc( isGraphicLine ); diff --git a/eeschema/sch_line.h b/eeschema/sch_line.h index 1095d61329..4b6e398215 100644 --- a/eeschema/sch_line.h +++ b/eeschema/sch_line.h @@ -138,11 +138,19 @@ public: VECTOR2I GetStartPoint() const { return m_start; } void SetStartPoint( const VECTOR2I& aPosition ) { m_start = aPosition; } + int GetStartX() const { return m_start.x; } + void SetStartX( int aX ) { SetStartPoint( VECTOR2I( aX, m_start.y ) ); } + int GetStartY() const { return m_start.y; } + void SetStartY( int aY ) { SetStartPoint( VECTOR2I( m_start.x, aY ) ); } VECTOR2I GetMidPoint() const { return ( m_start + m_end ) / 2; } VECTOR2I GetEndPoint() const { return m_end; } void SetEndPoint( const VECTOR2I& aPosition ) { m_end = aPosition; } + int GetEndX() const { return m_end.x; } + void SetEndX( int aX ) { SetEndPoint( VECTOR2I( aX, m_end.y ) ); } + int GetEndY() const { return m_end.y; } + void SetEndY( int aY ) { SetEndPoint( VECTOR2I( m_end.x, aY ) ); } /** * Get the geometric aspect of the wire as a SEG @@ -219,6 +227,7 @@ public: * @return The length of the line segment. */ double GetLength() const; + void SetLength( double aLength ); int GetPenWidth() const override;