mirror of
https://gitlab.com/kicad/code/kicad.git
synced 2025-04-21 08:21:39 +00:00
Break out pin spin function
This is a long routine that's easier to reason about as a function and also can be useful elsewhere when dealing with pin text orientation.
This commit is contained in:
parent
4c5ce1a603
commit
7a986b5e55
@ -53,6 +53,7 @@
|
||||
#include <sch_sheet_pin.h>
|
||||
#include <sch_text.h>
|
||||
#include <schematic.h>
|
||||
#include <symb_transforms_utils.h>
|
||||
#include <symbol_lib_table.h>
|
||||
#include <tool/common_tools.h>
|
||||
#include <sim/sim_model.h> // For V6 to V7 simulation model migration.
|
||||
@ -584,119 +585,7 @@ SPIN_STYLE SCH_SCREEN::GetLabelOrientationForPoint( const VECTOR2I& aPosit
|
||||
{
|
||||
if( pin->GetPosition() == aPosition )
|
||||
{
|
||||
if( pin->GetOrientation() == PIN_ORIENTATION::PIN_RIGHT )
|
||||
ret = SPIN_STYLE::LEFT;
|
||||
else if( pin->GetOrientation() == PIN_ORIENTATION::PIN_LEFT )
|
||||
ret = SPIN_STYLE::RIGHT;
|
||||
else if( pin->GetOrientation() == PIN_ORIENTATION::PIN_UP )
|
||||
ret = SPIN_STYLE::BOTTOM;
|
||||
else if( pin->GetOrientation() == PIN_ORIENTATION::PIN_DOWN )
|
||||
ret = SPIN_STYLE::UP;
|
||||
|
||||
switch( static_cast<SYMBOL_ORIENTATION_T>(
|
||||
symbol->GetOrientation() & ( ~( SYM_MIRROR_X | SYM_MIRROR_Y ) ) ) )
|
||||
{
|
||||
case SYM_ROTATE_CLOCKWISE:
|
||||
case SYM_ORIENT_90:
|
||||
if( ret == SPIN_STYLE::UP )
|
||||
ret = SPIN_STYLE::LEFT;
|
||||
else if( ret == SPIN_STYLE::BOTTOM )
|
||||
ret = SPIN_STYLE::RIGHT;
|
||||
else if( ret == SPIN_STYLE::LEFT )
|
||||
ret = SPIN_STYLE::BOTTOM;
|
||||
else if( ret == SPIN_STYLE::RIGHT )
|
||||
ret = SPIN_STYLE::UP;
|
||||
|
||||
if( symbol->GetOrientation() & SYM_MIRROR_X )
|
||||
{
|
||||
if( ret == SPIN_STYLE::UP )
|
||||
ret = SPIN_STYLE::BOTTOM;
|
||||
else if( ret == SPIN_STYLE::BOTTOM )
|
||||
ret = SPIN_STYLE::UP;
|
||||
}
|
||||
|
||||
if( symbol->GetOrientation() & SYM_MIRROR_Y )
|
||||
{
|
||||
if( ret == SPIN_STYLE::LEFT )
|
||||
ret = SPIN_STYLE::RIGHT;
|
||||
else if( ret == SPIN_STYLE::RIGHT )
|
||||
ret = SPIN_STYLE::LEFT;
|
||||
}
|
||||
break;
|
||||
case SYM_ROTATE_COUNTERCLOCKWISE:
|
||||
case SYM_ORIENT_270:
|
||||
if( ret == SPIN_STYLE::UP )
|
||||
ret = SPIN_STYLE::RIGHT;
|
||||
else if( ret == SPIN_STYLE::BOTTOM )
|
||||
ret = SPIN_STYLE::LEFT;
|
||||
else if( ret == SPIN_STYLE::LEFT )
|
||||
ret = SPIN_STYLE::UP;
|
||||
else if( ret == SPIN_STYLE::RIGHT )
|
||||
ret = SPIN_STYLE::BOTTOM;
|
||||
|
||||
if( symbol->GetOrientation() & SYM_MIRROR_X )
|
||||
{
|
||||
if( ret == SPIN_STYLE::UP )
|
||||
ret = SPIN_STYLE::BOTTOM;
|
||||
else if( ret == SPIN_STYLE::BOTTOM )
|
||||
ret = SPIN_STYLE::UP;
|
||||
}
|
||||
|
||||
if( symbol->GetOrientation() & SYM_MIRROR_Y )
|
||||
{
|
||||
if( ret == SPIN_STYLE::LEFT )
|
||||
ret = SPIN_STYLE::RIGHT;
|
||||
else if( ret == SPIN_STYLE::RIGHT )
|
||||
ret = SPIN_STYLE::LEFT;
|
||||
}
|
||||
break;
|
||||
case SYM_ORIENT_180:
|
||||
if( ret == SPIN_STYLE::UP )
|
||||
ret = SPIN_STYLE::BOTTOM;
|
||||
else if( ret == SPIN_STYLE::BOTTOM )
|
||||
ret = SPIN_STYLE::UP;
|
||||
else if( ret == SPIN_STYLE::LEFT )
|
||||
ret = SPIN_STYLE::RIGHT;
|
||||
else if( ret == SPIN_STYLE::RIGHT )
|
||||
ret = SPIN_STYLE::LEFT;
|
||||
|
||||
if( symbol->GetOrientation() & SYM_MIRROR_X )
|
||||
{
|
||||
if( ret == SPIN_STYLE::UP )
|
||||
ret = SPIN_STYLE::BOTTOM;
|
||||
else if( ret == SPIN_STYLE::BOTTOM )
|
||||
ret = SPIN_STYLE::UP;
|
||||
}
|
||||
|
||||
if( symbol->GetOrientation() & SYM_MIRROR_Y )
|
||||
{
|
||||
if( ret == SPIN_STYLE::LEFT )
|
||||
ret = SPIN_STYLE::RIGHT;
|
||||
else if( ret == SPIN_STYLE::RIGHT )
|
||||
ret = SPIN_STYLE::LEFT;
|
||||
}
|
||||
break;
|
||||
case SYM_ORIENT_0:
|
||||
case SYM_NORMAL:
|
||||
default:
|
||||
if( symbol->GetOrientation() & SYM_MIRROR_X )
|
||||
{
|
||||
if( ret == SPIN_STYLE::UP )
|
||||
ret = SPIN_STYLE::BOTTOM;
|
||||
else if( ret == SPIN_STYLE::BOTTOM )
|
||||
ret = SPIN_STYLE::UP;
|
||||
}
|
||||
|
||||
if( symbol->GetOrientation() & SYM_MIRROR_Y )
|
||||
{
|
||||
if( ret == SPIN_STYLE::LEFT )
|
||||
ret = SPIN_STYLE::RIGHT;
|
||||
else if( ret == SPIN_STYLE::RIGHT )
|
||||
ret = SPIN_STYLE::LEFT;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
ret = GetPinSpinStyle( *pin, *symbol );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -17,9 +17,11 @@
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "lib_symbol.h"
|
||||
#include "sch_symbol.h"
|
||||
#include "sch_pin.h"
|
||||
|
||||
#include "symb_transforms_utils.h"
|
||||
|
||||
#include <lib_symbol.h>
|
||||
#include <sch_symbol.h>
|
||||
|
||||
struct ORIENT_MIRROR
|
||||
{
|
||||
@ -105,3 +107,123 @@ void RotateAndMirrorPin( SCH_PIN& aPin, int aOrientMirror )
|
||||
if( o.mirror_y )
|
||||
aPin.MirrorHorizontallyPin( 0 );
|
||||
}
|
||||
|
||||
SPIN_STYLE GetPinSpinStyle( const SCH_PIN& aPin, const SCH_SYMBOL& aSymbol )
|
||||
{
|
||||
SPIN_STYLE ret = SPIN_STYLE::UP;
|
||||
|
||||
if( aPin.GetOrientation() == PIN_ORIENTATION::PIN_RIGHT )
|
||||
ret = SPIN_STYLE::LEFT;
|
||||
else if( aPin.GetOrientation() == PIN_ORIENTATION::PIN_LEFT )
|
||||
ret = SPIN_STYLE::RIGHT;
|
||||
else if( aPin.GetOrientation() == PIN_ORIENTATION::PIN_UP )
|
||||
ret = SPIN_STYLE::BOTTOM;
|
||||
else if( aPin.GetOrientation() == PIN_ORIENTATION::PIN_DOWN )
|
||||
ret = SPIN_STYLE::UP;
|
||||
|
||||
switch( static_cast<SYMBOL_ORIENTATION_T>( aSymbol.GetOrientation()
|
||||
& ( ~( SYM_MIRROR_X | SYM_MIRROR_Y ) ) ) )
|
||||
{
|
||||
case SYM_ROTATE_CLOCKWISE:
|
||||
case SYM_ORIENT_90:
|
||||
if( ret == SPIN_STYLE::UP )
|
||||
ret = SPIN_STYLE::LEFT;
|
||||
else if( ret == SPIN_STYLE::BOTTOM )
|
||||
ret = SPIN_STYLE::RIGHT;
|
||||
else if( ret == SPIN_STYLE::LEFT )
|
||||
ret = SPIN_STYLE::BOTTOM;
|
||||
else if( ret == SPIN_STYLE::RIGHT )
|
||||
ret = SPIN_STYLE::UP;
|
||||
|
||||
if( aSymbol.GetOrientation() & SYM_MIRROR_X )
|
||||
{
|
||||
if( ret == SPIN_STYLE::UP )
|
||||
ret = SPIN_STYLE::BOTTOM;
|
||||
else if( ret == SPIN_STYLE::BOTTOM )
|
||||
ret = SPIN_STYLE::UP;
|
||||
}
|
||||
|
||||
if( aSymbol.GetOrientation() & SYM_MIRROR_Y )
|
||||
{
|
||||
if( ret == SPIN_STYLE::LEFT )
|
||||
ret = SPIN_STYLE::RIGHT;
|
||||
else if( ret == SPIN_STYLE::RIGHT )
|
||||
ret = SPIN_STYLE::LEFT;
|
||||
}
|
||||
break;
|
||||
case SYM_ROTATE_COUNTERCLOCKWISE:
|
||||
case SYM_ORIENT_270:
|
||||
if( ret == SPIN_STYLE::UP )
|
||||
ret = SPIN_STYLE::RIGHT;
|
||||
else if( ret == SPIN_STYLE::BOTTOM )
|
||||
ret = SPIN_STYLE::LEFT;
|
||||
else if( ret == SPIN_STYLE::LEFT )
|
||||
ret = SPIN_STYLE::UP;
|
||||
else if( ret == SPIN_STYLE::RIGHT )
|
||||
ret = SPIN_STYLE::BOTTOM;
|
||||
|
||||
if( aSymbol.GetOrientation() & SYM_MIRROR_X )
|
||||
{
|
||||
if( ret == SPIN_STYLE::UP )
|
||||
ret = SPIN_STYLE::BOTTOM;
|
||||
else if( ret == SPIN_STYLE::BOTTOM )
|
||||
ret = SPIN_STYLE::UP;
|
||||
}
|
||||
|
||||
if( aSymbol.GetOrientation() & SYM_MIRROR_Y )
|
||||
{
|
||||
if( ret == SPIN_STYLE::LEFT )
|
||||
ret = SPIN_STYLE::RIGHT;
|
||||
else if( ret == SPIN_STYLE::RIGHT )
|
||||
ret = SPIN_STYLE::LEFT;
|
||||
}
|
||||
break;
|
||||
case SYM_ORIENT_180:
|
||||
if( ret == SPIN_STYLE::UP )
|
||||
ret = SPIN_STYLE::BOTTOM;
|
||||
else if( ret == SPIN_STYLE::BOTTOM )
|
||||
ret = SPIN_STYLE::UP;
|
||||
else if( ret == SPIN_STYLE::LEFT )
|
||||
ret = SPIN_STYLE::RIGHT;
|
||||
else if( ret == SPIN_STYLE::RIGHT )
|
||||
ret = SPIN_STYLE::LEFT;
|
||||
|
||||
if( aSymbol.GetOrientation() & SYM_MIRROR_X )
|
||||
{
|
||||
if( ret == SPIN_STYLE::UP )
|
||||
ret = SPIN_STYLE::BOTTOM;
|
||||
else if( ret == SPIN_STYLE::BOTTOM )
|
||||
ret = SPIN_STYLE::UP;
|
||||
}
|
||||
|
||||
if( aSymbol.GetOrientation() & SYM_MIRROR_Y )
|
||||
{
|
||||
if( ret == SPIN_STYLE::LEFT )
|
||||
ret = SPIN_STYLE::RIGHT;
|
||||
else if( ret == SPIN_STYLE::RIGHT )
|
||||
ret = SPIN_STYLE::LEFT;
|
||||
}
|
||||
break;
|
||||
case SYM_ORIENT_0:
|
||||
case SYM_NORMAL:
|
||||
default:
|
||||
if( aSymbol.GetOrientation() & SYM_MIRROR_X )
|
||||
{
|
||||
if( ret == SPIN_STYLE::UP )
|
||||
ret = SPIN_STYLE::BOTTOM;
|
||||
else if( ret == SPIN_STYLE::BOTTOM )
|
||||
ret = SPIN_STYLE::UP;
|
||||
}
|
||||
|
||||
if( aSymbol.GetOrientation() & SYM_MIRROR_Y )
|
||||
{
|
||||
if( ret == SPIN_STYLE::LEFT )
|
||||
ret = SPIN_STYLE::RIGHT;
|
||||
else if( ret == SPIN_STYLE::RIGHT )
|
||||
ret = SPIN_STYLE::LEFT;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -20,7 +20,11 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <sch_label.h>
|
||||
#include <sch_pin.h>
|
||||
|
||||
class LIB_SYMBOL;
|
||||
class SCH_SYMBOL;
|
||||
|
||||
/**
|
||||
* Rotate and/or mirror graphic objects of LIB_SYMBOL aSymbol according to aOrientMirror.
|
||||
@ -39,3 +43,12 @@ void OrientAndMirrorSymbolItems( LIB_SYMBOL* aLibSymbol, int aOrientation );
|
||||
* @param aOrientation is the orientation+mirror value like returned by SCH_SYMBOL::GetOrientation()
|
||||
*/
|
||||
void RotateAndMirrorPin( SCH_PIN& aPin, int aOrientMirror );
|
||||
|
||||
/**
|
||||
* Get the spin style for a pin's label, taking into account the pin's orientation,
|
||||
* as well as the given symbol's orientation.
|
||||
*
|
||||
* For example, pin with PIN_RIGHT (i.e. a pin on the left side of a symbol, probably)
|
||||
* and no symbol rotation/mirror will return SPIN_STYLE::LEFT.
|
||||
*/
|
||||
SPIN_STYLE GetPinSpinStyle( const SCH_PIN& aPin, const SCH_SYMBOL& aSymbol );
|
Loading…
Reference in New Issue
Block a user