const EDA_RECT SCH_HIERLABEL::GetBoundingBox() const { int x, y, dx, dy, length, height; x = m_Pos.x; y = m_Pos.y; dx = dy = 0; int width = (m_Thickness == 0) ? GetDefaultLineThickness() : m_Thickness; height = m_Size.y + width + 2 * TXTMARGE; length = LenSize( GetShownText() ) + height // add height for triangular shapes + 2 * DANGLING_SYMBOL_SIZE; switch( m_schematicOrientation ) // respect orientation { case 0: /* Horiz Normal Orientation (left justified) */ dx = -length; dy = height; x += DANGLING_SYMBOL_SIZE; y -= height / 2; break; case 1: /* Vert Orientation UP */ dx = height; dy = -length; x -= height / 2; y += DANGLING_SYMBOL_SIZE; break; case 2: /* Horiz Orientation - Right justified */ dx = length; dy = height; x -= DANGLING_SYMBOL_SIZE; y -= height / 2; break; case 3: /* Vert Orientation BOTTOM */ dx = height; dy = length; x -= height / 2; y -= DANGLING_SYMBOL_SIZE; break; } EDA_RECT box( wxPoint( x, y ), wxSize( dx, dy ) ); box.Normalize(); return box; }
EDA_RECT SCH_LABEL::GetBoundingBox() const { int x, y, dx, dy, length, height; x = m_Pos.x; y = m_Pos.y; int width = (m_Thickness == 0) ? GetDefaultLineThickness() : m_Thickness; length = LenSize( m_Text ); height = m_Size.y + width; dx = dy = 0; switch( m_schematicOrientation ) { case 0: /* Horiz Normal Orientation (left justified) */ dx = 2 * DANGLING_SYMBOL_SIZE + length; dy = -2 * DANGLING_SYMBOL_SIZE - height - TXTMARGE; x -= DANGLING_SYMBOL_SIZE; y += DANGLING_SYMBOL_SIZE; break; case 1: /* Vert Orientation UP */ dx = -2 * DANGLING_SYMBOL_SIZE - height - TXTMARGE; dy = -2 * DANGLING_SYMBOL_SIZE - length; x += DANGLING_SYMBOL_SIZE; y += DANGLING_SYMBOL_SIZE; break; case 2: /* Horiz Orientation - Right justified */ dx = -2 * DANGLING_SYMBOL_SIZE - length; dy = -2 * DANGLING_SYMBOL_SIZE - height - TXTMARGE; x += DANGLING_SYMBOL_SIZE; y += DANGLING_SYMBOL_SIZE; break; case 3: /* Vert Orientation BOTTOM */ dx = -2 * DANGLING_SYMBOL_SIZE - height - TXTMARGE; dy = 2 * DANGLING_SYMBOL_SIZE + length; x += DANGLING_SYMBOL_SIZE; y -= DANGLING_SYMBOL_SIZE; break; } EDA_RECT box( wxPoint( x, y ), wxSize( dx, dy ) ); box.Normalize(); return box; }
EDA_RECT EDA_TEXT::GetTextBox( int aLine, int aThickness, bool aInvertY ) const { EDA_RECT rect; wxPoint pos; wxArrayString strings; wxString text = GetShownText(); int thickness = ( aThickness < 0 ) ? m_Thickness : aThickness; int linecount = 1; if( m_MultilineAllowed ) { wxStringSplit( text, strings, '\n' ); if ( strings.GetCount() ) // GetCount() == 0 for void strings { if( aLine >= 0 && (aLine < (int)strings.GetCount()) ) text = strings.Item( aLine ); else text = strings.Item( 0 ); linecount = strings.GetCount(); } } // calculate the H and V size int dx = LenSize( text ); int dy = GetInterline( aThickness ); // Creates bounding box (rectangle) for an horizontal text wxSize textsize = wxSize( dx, dy ); if( aInvertY ) rect.SetOrigin( m_Pos.x, -m_Pos.y ); else rect.SetOrigin( m_Pos ); // extra dy interval for letters like j and y and ] int extra_dy = dy - m_Size.y; rect.Move( wxPoint( 0, -extra_dy / 2 ) ); // move origin by the half extra interval // for multiline texts and aLine < 0, merge all rectangles if( m_MultilineAllowed && aLine < 0 ) { for( unsigned ii = 1; ii < strings.GetCount(); ii++ ) { text = strings.Item( ii ); dx = LenSize( text ); textsize.x = std::max( textsize.x, dx ); textsize.y += dy; } } rect.SetSize( textsize ); /* Now, calculate the rect origin, according to text justification * At this point the rectangle origin is the text origin (m_Pos). * This is true only for left and top text justified texts (using top to bottom Y axis * orientation). and must be recalculated for others justifications * also, note the V justification is relative to the first line */ switch( m_HJustify ) { case GR_TEXT_HJUSTIFY_LEFT: if( m_Mirror ) rect.SetX( rect.GetX() - rect.GetWidth() ); break; case GR_TEXT_HJUSTIFY_CENTER: rect.SetX( rect.GetX() - (rect.GetWidth() / 2) ); break; case GR_TEXT_HJUSTIFY_RIGHT: if( !m_Mirror ) rect.SetX( rect.GetX() - rect.GetWidth() ); break; } dy = m_Size.y + thickness; switch( m_VJustify ) { case GR_TEXT_VJUSTIFY_TOP: break; case GR_TEXT_VJUSTIFY_CENTER: rect.SetY( rect.GetY() - ( dy / 2) ); break; case GR_TEXT_VJUSTIFY_BOTTOM: rect.SetY( rect.GetY() - dy ); break; } if( linecount > 1 ) { int yoffset; linecount -= 1; switch( m_VJustify ) { case GR_TEXT_VJUSTIFY_TOP: break; case GR_TEXT_VJUSTIFY_CENTER: yoffset = linecount * GetInterline() / 2; rect.SetY( rect.GetY() - yoffset ); break; case GR_TEXT_VJUSTIFY_BOTTOM: yoffset = linecount * GetInterline( aThickness ); rect.SetY( rect.GetY() - yoffset ); break; } } rect.Inflate( thickness / 2 ); rect.Normalize(); // Make h and v sizes always >= 0 return rect; }
void SCH_GLOBALLABEL::CreateGraphicShape( std::vector <wxPoint>& aPoints, const wxPoint& Pos ) { int halfSize = GetTextHeight() / 2; int linewidth = GetThickness() == 0 ? GetDefaultLineThickness() : GetThickness(); linewidth = Clamp_Text_PenSize( linewidth, GetTextSize(), IsBold() ); aPoints.clear(); int symb_len = LenSize( GetShownText(), linewidth ) + ( TXT_MARGIN * 2 ); // Create outline shape : 6 points int x = symb_len + linewidth + 3; // Use negation bar Y position to calculate full vertical size // Search for overbar symbol bool hasOverBar = false; for( unsigned ii = 1; ii < m_Text.size(); ii++ ) { if( m_Text[ii-1] == '~' && m_Text[ii] != '~' ) { hasOverBar = true; break; } } #define Y_CORRECTION 1.40 // Note: this factor is due to the fact the Y size of a few letters like [ // are bigger than the y size value, and we need a margin for the graphic symbol. int y = KiROUND( halfSize * Y_CORRECTION ); // Note: this factor is due to the fact we need a margin for the graphic symbol. #define Y_OVERBAR_CORRECTION 1.2 if( hasOverBar ) y = KiROUND( KIGFX::STROKE_FONT::GetInterline( halfSize, linewidth ) * Y_OVERBAR_CORRECTION ); // Gives room for line thickess and margin y += linewidth // for line thickess + linewidth/2; // for margin // Starting point(anchor) aPoints.push_back( wxPoint( 0, 0 ) ); aPoints.push_back( wxPoint( 0, -y ) ); // Up aPoints.push_back( wxPoint( -x, -y ) ); // left aPoints.push_back( wxPoint( -x, 0 ) ); // Up left aPoints.push_back( wxPoint( -x, y ) ); // left down aPoints.push_back( wxPoint( 0, y ) ); // down int x_offset = 0; switch( m_shape ) { case NET_INPUT: x_offset = -halfSize; aPoints[0].x += halfSize; break; case NET_OUTPUT: aPoints[3].x -= halfSize; break; case NET_BIDI: case NET_TRISTATE: x_offset = -halfSize; aPoints[0].x += halfSize; aPoints[3].x -= halfSize; break; case NET_UNSPECIFIED: default: break; } int angle = 0; switch( GetLabelSpinStyle() ) { default: case 0: break; // Orientation horiz normal case 1: angle = -900; break; // Orientation vert UP case 2: angle = 1800; break; // Orientation horiz inverse case 3: angle = 900; break; // Orientation vert BOTTOM } // Rotate outlines and move corners in real position for( wxPoint& aPoint : aPoints ) { aPoint.x += x_offset; if( angle ) RotatePoint( &aPoint, angle ); aPoint += Pos; } aPoints.push_back( aPoints[0] ); // closing }
void SCH_GLOBALLABEL::CreateGraphicShape( std::vector <wxPoint>& aPoints, const wxPoint& Pos ) { int HalfSize = m_Size.y / 2; int linewidth = (m_Thickness == 0) ? GetDefaultLineThickness() : m_Thickness; linewidth = Clamp_Text_PenSize( linewidth, m_Size, m_Bold ); aPoints.clear(); int symb_len = LenSize( m_Text ) + ( TXTMARGE * 2 ); // Create outline shape : 6 points int x = symb_len + linewidth + 3; // Use negation bar Y position to calculate full vertical size #define Y_CORRECTION 1.22 // Note: this factor is due to the fact the negation bar Y position // does not give exactly the full Y size of text // and is experimentally set to this value int y = KiROUND( OverbarPositionY( HalfSize, linewidth ) * Y_CORRECTION ); // add room for line thickness and space between top of text and graphic shape y += linewidth; // Starting point(anchor) aPoints.push_back( wxPoint( 0, 0 ) ); aPoints.push_back( wxPoint( 0, -y ) ); // Up aPoints.push_back( wxPoint( -x, -y ) ); // left aPoints.push_back( wxPoint( -x, 0 ) ); // Up left aPoints.push_back( wxPoint( -x, y ) ); // left down aPoints.push_back( wxPoint( 0, y ) ); // down int x_offset = 0; switch( m_shape ) { case NET_INPUT: x_offset = -HalfSize; aPoints[0].x += HalfSize; break; case NET_OUTPUT: aPoints[3].x -= HalfSize; break; case NET_BIDI: case NET_TRISTATE: x_offset = -HalfSize; aPoints[0].x += HalfSize; aPoints[3].x -= HalfSize; break; case NET_UNSPECIFIED: default: break; } int angle = 0; switch( m_schematicOrientation ) { case 0: /* Orientation horiz normal */ break; case 1: /* Orientation vert UP */ angle = -900; break; case 2: /* Orientation horiz inverse */ angle = 1800; break; case 3: /* Orientation vert BOTTOM */ angle = 900; break; } // Rotate outlines and move corners in real position for( unsigned ii = 0; ii < aPoints.size(); ii++ ) { aPoints[ii].x += x_offset; if( angle ) RotatePoint( &aPoints[ii], angle ); aPoints[ii] += Pos; } aPoints.push_back( aPoints[0] ); // closing }