bool LIB_CIRCLE::Inside( EDA_RECT& aRect ) const { /* * FIXME: This fails to take into account the radius around the center * point. */ return aRect.Contains( m_Pos.x, -m_Pos.y ); }
bool LIB_TEXT::Inside( EDA_RECT& rect ) const { /* * FIXME: This should calculate the text size and justification and * use rectangle intersect. */ return rect.Contains( m_Pos.x, -m_Pos.y ); }
bool LIB_FIELD::Inside( EDA_RECT& rect ) const { /* * FIXME: This fails to take into account the size and/or orientation of * the text. */ return rect.Contains( m_Pos.x, -m_Pos.y ); }
bool TEXTE_MODULE::HitTest( const wxPoint& aPosition ) { wxPoint rel_pos; EDA_RECT area = GetTextBox( -1, -1 ); /* Rotate refPos to - angle * to test if refPos is within area (which is relative to an horizontal * text) */ rel_pos = aPosition; RotatePoint( &rel_pos, m_Pos, -GetDrawRotation() ); if( area.Contains( rel_pos ) ) return true; return false; }
void EDA_DRAW_PANEL::EraseScreen( wxDC* DC ) { GRSetDrawMode( DC, GR_COPY ); EDA_COLOR_T bgColor = GetParent()->GetDrawBgColor(); GRSFilledRect( NULL, DC, m_ClipBox.GetX(), m_ClipBox.GetY(), m_ClipBox.GetRight(), m_ClipBox.GetBottom(), 0, bgColor, bgColor ); // Set to one (1) to draw bounding box validate bounding box calculation. #if DEBUG_SHOW_CLIP_RECT EDA_RECT bBox = m_ClipBox; GRRect( NULL, DC, bBox.GetOrigin().x, bBox.GetOrigin().y, bBox.GetEnd().x, bBox.GetEnd().y, 0, LIGHTMAGENTA ); #endif }
double LIB_EDIT_FRAME::BestZoom() { /* Please, note: wxMSW before version 2.9 seems have * problems with zoom values < 1 ( i.e. userscale > 1) and needs to be patched: * edit file <wxWidgets>/src/msw/dc.cpp * search for line static const int VIEWPORT_EXTENT = 1000; * and replace by static const int VIEWPORT_EXTENT = 10000; */ int dx, dy; LIB_PART* part = GetCurPart(); if( part ) { EDA_RECT boundingBox = part->GetBoundingBox( m_unit, m_convert ); dx = boundingBox.GetWidth(); dy = boundingBox.GetHeight(); SetScrollCenterPosition( wxPoint( 0, 0 ) ); } else { const PAGE_INFO& pageInfo = GetScreen()->GetPageSettings(); dx = pageInfo.GetSizeIU().x; dy = pageInfo.GetSizeIU().y; SetScrollCenterPosition( wxPoint( 0, 0 ) ); } wxSize size = m_canvas->GetClientSize(); // Reserve a 10% margin around component bounding box. double margin_scale_factor = 0.8; double zx =(double) dx / ( margin_scale_factor * (double)size.x ); double zy = (double) dy / ( margin_scale_factor * (double)size.y ); double bestzoom = std::max( zx, zy ); // keep it >= minimal existing zoom (can happen for very small components // for instance when starting a new component if( bestzoom < GetScreen()->m_ZoomList[0] ) bestzoom = GetScreen()->m_ZoomList[0]; return bestzoom; }
void SELECTION_TOOL::findCallback( BOARD_ITEM* aItem ) { clearSelection(); if( aItem ) { select( aItem ); EDA_RECT bbox = aItem->GetBoundingBox(); BOX2D viewport( VECTOR2D( bbox.GetOrigin() ), VECTOR2D( bbox.GetSize() ) ); getView()->SetViewport( viewport ); // Inform other potentially interested tools m_toolMgr->ProcessEvent( SelectedEvent ); } m_frame->GetGalCanvas()->ForceRefresh(); }
void LIB_CIRCLE::drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset, COLOR4D aColor, GR_DRAWMODE aDrawMode, void* aData, const TRANSFORM& aTransform ) { wxPoint pos1; COLOR4D color = GetLayerColor( LAYER_DEVICE ); if( aColor == COLOR4D::UNSPECIFIED ) // Used normal color or selected color { if( IsSelected() ) color = GetItemSelectedColor(); } else { color = aColor; } pos1 = aTransform.TransformCoordinate( m_Pos ) + aOffset; GRSetDrawMode( aDC, aDrawMode ); FILL_T fill = aData ? NO_FILL : m_Fill; if( aColor != COLOR4D::UNSPECIFIED ) fill = NO_FILL; EDA_RECT* const clipbox = aPanel? aPanel->GetClipBox() : NULL; if( fill == FILLED_WITH_BG_BODYCOLOR ) GRFilledCircle( clipbox, aDC, pos1.x, pos1.y, m_Radius, GetPenSize(), (m_Flags & IS_MOVED) ? color : GetLayerColor( LAYER_DEVICE_BACKGROUND ), GetLayerColor( LAYER_DEVICE_BACKGROUND ) ); else if( fill == FILLED_SHAPE ) GRFilledCircle( clipbox, aDC, pos1.x, pos1.y, m_Radius, 0, color, color ); else GRCircle( clipbox, aDC, pos1.x, pos1.y, m_Radius, GetPenSize(), color ); /* Set to one (1) to draw bounding box around circle to validate bounding * box calculation. */ #if 0 EDA_RECT bBox = GetBoundingBox(); bBox.RevertYAxis(); bBox = aTransform.TransformCoordinate( bBox ); bBox.Move( aOffset ); GRRect( clipbox, aDC, bBox, 0, LIGHTMAGENTA ); #endif }
EDA_RECT SCH_FIELD::GetBoundingBox() const { SCH_COMPONENT* parentComponent = (SCH_COMPONENT*) m_Parent; int linewidth = ( m_Thickness == 0 ) ? GetDefaultLineThickness() : m_Thickness; // We must pass the effective text thickness to GetTextBox // when calculating the bounding box linewidth = Clamp_Text_PenSize( linewidth, m_Size, m_Bold ); // Calculate the text bounding box: EDA_RECT rect; // set USE_TEXT_JUSTIFY_INITIAL_BEHAVIOR to 0 to use // a justification relative to the text itself // i.e. justification relative to an horizontal text // or to 1 to keep the initial behavior #if (USE_TEXT_JUSTIFY_INITIAL_BEHAVIOR == 1 ) if( m_Orient == TEXT_ORIENT_VERT ) { // For vertical texts, exchange the horizontal and the vertical justification // The idea is to keep the justification always left or top for instance, // no matter the text orientation SCH_FIELD text( *this ); // Make a local copy to swap justifications // because GetBoundingBox() is const int tmp = (int)text.m_VJustify; NEGATE( tmp ); text.m_VJustify = (EDA_TEXT_VJUSTIFY_T)text.m_HJustify; text.m_HJustify = (EDA_TEXT_HJUSTIFY_T)tmp; rect = text.GetTextBox( -1, linewidth ); } else #endif rect = GetTextBox( -1, linewidth ); // Calculate the bounding box position relative to the component: wxPoint origin = parentComponent->GetPosition(); wxPoint pos = m_Pos - origin; wxPoint begin = rect.GetOrigin() - origin; wxPoint end = rect.GetEnd() - origin; RotatePoint( &begin, pos, m_Orient ); RotatePoint( &end, pos, m_Orient ); // Due to the Y axis direction, we must mirror the bounding box, // relative to the text position: begin.y -= pos.y; end.y -= pos.y; NEGATE( begin.y ); NEGATE( end.y ); begin.y += pos.y; end.y += pos.y; // Now, apply the component transform (mirror/rot) begin = parentComponent->GetTransform().TransformCoordinate( begin ); end = parentComponent->GetTransform().TransformCoordinate( end ); rect.SetOrigin( begin); rect.SetEnd( end); rect.Move( origin ); rect.Normalize(); return rect; }
double LIB_VIEW_FRAME::BestZoom() { /* Please, note: wxMSW before version 2.9 seems have * problems with zoom values < 1 ( i.e. userscale > 1) and needs to be patched: * edit file <wxWidgets>/src/msw/dc.cpp * search for line static const int VIEWPORT_EXTENT = 1000; * and replace by static const int VIEWPORT_EXTENT = 10000; */ LIB_COMPONENT* component = NULL; double bestzoom = 16.0; // default value for bestzoom CMP_LIBRARY* lib = CMP_LIBRARY::FindLibrary( m_libraryName ); if( lib ) component = lib->FindComponent( m_entryName ); if( component == NULL ) { SetScrollCenterPosition( wxPoint( 0, 0 ) ); return bestzoom; } wxSize size = m_canvas->GetClientSize(); EDA_RECT BoundaryBox = component->GetBoundingBox( m_unit, m_convert ); // Reserve a 10% margin around component bounding box. double margin_scale_factor = 0.8; double zx =(double) BoundaryBox.GetWidth() / ( margin_scale_factor * (double)size.x ); double zy = (double) BoundaryBox.GetHeight() / ( margin_scale_factor * (double)size.y); // Calculates the best zoom bestzoom = std::max( zx, zy ); // keep it >= minimal existing zoom (can happen for very small components // like small power symbols if( bestzoom < GetScreen()->m_ZoomList[0] ) bestzoom = GetScreen()->m_ZoomList[0]; SetScrollCenterPosition( BoundaryBox.Centre() ); return bestzoom; }
void EDA_DRAW_PANEL::RefreshDrawingRect( const EDA_RECT& aRect, bool aEraseBackground ) { INSTALL_UNBUFFERED_DC( dc, this ); wxRect rect = aRect; rect.x = dc.LogicalToDeviceX( rect.x ); rect.y = dc.LogicalToDeviceY( rect.y ); rect.width = dc.LogicalToDeviceXRel( rect.width ); rect.height = dc.LogicalToDeviceYRel( rect.height ); wxLogTrace( kicadTraceCoords, wxT( "Refresh area: drawing (%d, %d, %d, %d), device (%d, %d, %d, %d)" ), aRect.GetX(), aRect.GetY(), aRect.GetWidth(), aRect.GetHeight(), rect.x, rect.y, rect.width, rect.height ); RefreshRect( rect, aEraseBackground ); }
double PCB_BASE_FRAME::BestZoom() { if( m_Pcb == NULL ) return 1.0; EDA_RECT ibbbox = GetBoardBoundingBox(); DSIZE clientz = m_canvas->GetClientSize(); DSIZE boardz( ibbbox.GetWidth(), ibbbox.GetHeight() ); double iu_per_du_X = clientz.x ? boardz.x / clientz.x : 1.0; double iu_per_du_Y = clientz.y ? boardz.y / clientz.y : 1.0; double bestzoom = std::max( iu_per_du_X, iu_per_du_Y ); GetScreen()->SetScrollCenterPosition( ibbbox.Centre() ); return bestzoom; }
void LIB_CIRCLE::GetMsgPanelInfo( EDA_UNITS_T aUnits, MSG_PANEL_ITEMS& aList ) { wxString msg; EDA_RECT bBox = GetBoundingBox(); LIB_ITEM::GetMsgPanelInfo( aUnits, aList ); msg = MessageTextFromValue( aUnits, m_Width, true ); aList.push_back( MSG_PANEL_ITEM( _( "Line Width" ), msg, BLUE ) ); msg = MessageTextFromValue( aUnits, m_Radius, true ); aList.push_back( MSG_PANEL_ITEM( _( "Radius" ), msg, RED ) ); msg.Printf( wxT( "(%d, %d, %d, %d)" ), bBox.GetOrigin().x, bBox.GetOrigin().y, bBox.GetEnd().x, bBox.GetEnd().y ); aList.push_back( MSG_PANEL_ITEM( _( "Bounding Box" ), msg, BROWN ) ); }
bool LIB_POLYLINE::Inside( EDA_RECT& aRect ) const { for( size_t i = 0; i < m_PolyPoints.size(); i++ ) { if( aRect.Contains( m_PolyPoints[i].x, -m_PolyPoints[i].y ) ) return true; } return false; }
double GERBVIEW_FRAME::BestZoom() { GERBER_DRAW_ITEM* item = GetGerberLayout()->m_Drawings; // gives a minimal value to zoom, if no item in list if( item == NULL ) return ZOOM_FACTOR( 350.0 ); EDA_RECT bbox = GetGerberLayout()->ComputeBoundingBox(); wxSize size = m_canvas->GetClientSize(); double x = (double) bbox.GetWidth() / (double) size.x; double y = (double) bbox.GetHeight() / (double) size.y; SetScrollCenterPosition( bbox.Centre() ); double best_zoom = std::max( x, y ); return best_zoom; }
void LIB_CIRCLE::DisplayInfo( EDA_DRAW_FRAME* aFrame ) { wxString msg; EDA_RECT bBox = GetBoundingBox(); LIB_ITEM::DisplayInfo( aFrame ); msg = ReturnStringFromValue( g_UserUnit, m_Width, EESCHEMA_INTERNAL_UNIT, true ); aFrame->AppendMsgPanel( _( "Line width" ), msg, BLUE ); msg = ReturnStringFromValue( g_UserUnit, m_Radius, EESCHEMA_INTERNAL_UNIT, true ); aFrame->AppendMsgPanel( _( "Radius" ), msg, RED ); msg.Printf( wxT( "(%d, %d, %d, %d)" ), bBox.GetOrigin().x, bBox.GetOrigin().y, bBox.GetEnd().x, bBox.GetEnd().y ); aFrame->AppendMsgPanel( _( "Bounding box" ), msg, BROWN ); }
const EDA_RECT MODULE::GetBoundingBox() const { EDA_RECT area = GetFootprintRect(); // Calculate extended area including text fields area.Merge( m_Reference->GetBoundingBox() ); area.Merge( m_Value->GetBoundingBox() ); // Add the Clearance shape size: (shape around the pads when the // clearance is shown. Not optimized, but the draw cost is small // (perhaps smaller than optimization). BOARD* board = GetBoard(); if( board ) { int biggest_clearance = board->GetDesignSettings().GetBiggestClearanceValue(); area.Inflate( biggest_clearance ); } return area; }
void LIB_CIRCLE::drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset, int aColor, int aDrawMode, void* aData, const TRANSFORM& aTransform ) { wxPoint pos1; int color = ReturnLayerColor( LAYER_DEVICE ); if( aColor < 0 ) // Used normal color or selected color { if( IsSelected() ) color = g_ItemSelectetColor; } else { color = aColor; } pos1 = aTransform.TransformCoordinate( m_Pos ) + aOffset; GRSetDrawMode( aDC, aDrawMode ); FILL_T fill = aData ? NO_FILL : m_Fill; if( aColor >= 0 ) fill = NO_FILL; if( fill == FILLED_WITH_BG_BODYCOLOR ) GRFilledCircle( aPanel->GetClipBox(), aDC, pos1.x, pos1.y, m_Radius, GetPenSize(), (m_Flags & IS_MOVED) ? color : ReturnLayerColor( LAYER_DEVICE_BACKGROUND ), ReturnLayerColor( LAYER_DEVICE_BACKGROUND ) ); else if( fill == FILLED_SHAPE ) GRFilledCircle( aPanel->GetClipBox(), aDC, pos1.x, pos1.y, m_Radius, 0, color, color ); else GRCircle( aPanel->GetClipBox(), aDC, pos1.x, pos1.y, m_Radius, GetPenSize(), color ); /* Set to one (1) to draw bounding box around circle to validate bounding * box calculation. */ #if 0 EDA_RECT bBox = GetBoundingBox(); GRRect( aPanel->GetClipBox(), aDC, bBox.GetOrigin().x, bBox.GetOrigin().y, bBox.GetEnd().x, bBox.GetEnd().y, 0, LIGHTMAGENTA ); #endif }
double LIB_VIEW_FRAME::BestZoom() { LIB_PART* part = NULL; double defaultLibraryZoom = 7.33; if( m_libraryName.IsEmpty() || m_entryName.IsEmpty() ) { SetScrollCenterPosition( wxPoint( 0, 0 ) ); return defaultLibraryZoom; } LIB_ALIAS* alias = nullptr; try { alias = Prj().SchSymbolLibTable()->LoadSymbol( m_libraryName, m_entryName ); } catch( ... ) { } if( alias ) part = alias->GetPart(); if( !part ) { SetScrollCenterPosition( wxPoint( 0, 0 ) ); return defaultLibraryZoom; } EDA_RECT boundingBox = part->GetUnitBoundingBox( m_unit, m_convert ); double sizeX = (double) boundingBox.GetWidth(); double sizeY = (double) boundingBox.GetHeight(); wxPoint centre = boundingBox.Centre(); // Reserve a 20% margin around component bounding box. double margin_scale_factor = 1.2; return bestZoom( sizeX, sizeY, margin_scale_factor, centre ); }
const EDA_RECT CPolyLine::GetBoundingBox() { int xmin = INT_MAX; int ymin = INT_MAX; int xmax = INT_MIN; int ymax = INT_MIN; for( unsigned i = 0; i< m_CornersList.GetCornersCount(); i++ ) { xmin = std::min( xmin, m_CornersList[i].x ); xmax = std::max( xmax, m_CornersList[i].x ); ymin = std::min( ymin, m_CornersList[i].y ); ymax = std::max( ymax, m_CornersList[i].y ); } EDA_RECT r; r.SetOrigin( wxPoint( xmin, ymin ) ); r.SetEnd( wxPoint( xmax, ymax ) ); return r; }
/* Place module on Routing matrix. */ void genModuleOnRoutingMatrix( MODULE* Module ) { int ox, oy, fx, fy; int layerMask; D_PAD* Pad; EDA_RECT fpBBox = Module->GetBoundingBox(); fpBBox.Inflate( RoutingMatrix.m_GridRouting / 2 ); ox = fpBBox.GetX(); fx = fpBBox.GetRight(); oy = fpBBox.GetY(); fy = fpBBox.GetBottom(); if( ox < RoutingMatrix.m_BrdBox.GetX() ) ox = RoutingMatrix.m_BrdBox.GetX(); if( ox > RoutingMatrix.m_BrdBox.GetRight() ) ox = RoutingMatrix.m_BrdBox.GetRight(); if( fx < RoutingMatrix.m_BrdBox.GetX() ) fx = RoutingMatrix.m_BrdBox.GetX(); if( fx > RoutingMatrix.m_BrdBox.GetRight() ) fx = RoutingMatrix.m_BrdBox.GetRight(); if( oy < RoutingMatrix.m_BrdBox.GetY() ) oy = RoutingMatrix.m_BrdBox.GetY(); if( oy > RoutingMatrix.m_BrdBox.GetBottom() ) oy = RoutingMatrix.m_BrdBox.GetBottom(); if( fy < RoutingMatrix.m_BrdBox.GetY() ) fy = RoutingMatrix.m_BrdBox.GetY(); if( fy > RoutingMatrix.m_BrdBox.GetBottom() ) fy = RoutingMatrix.m_BrdBox.GetBottom(); layerMask = 0; if( Module->GetLayer() == LAYER_N_FRONT ) layerMask = LAYER_FRONT; if( Module->GetLayer() == LAYER_N_BACK ) layerMask = LAYER_BACK; TraceFilledRectangle( ox, oy, fx, fy, layerMask, CELL_is_MODULE, WRITE_OR_CELL ); // Trace pads + clearance areas. for( Pad = Module->Pads(); Pad != NULL; Pad = Pad->Next() ) { int margin = (RoutingMatrix.m_GridRouting / 2) + Pad->GetClearance(); ::PlacePad( Pad, CELL_is_MODULE, margin, WRITE_OR_CELL ); } // Trace clearance. int margin = ( RoutingMatrix.m_GridRouting * Module->GetPadCount() ) / GAIN; CreateKeepOutRectangle( ox, oy, fx, fy, margin, KEEP_OUT_MARGIN, layerMask ); }
const EDA_RECT SCH_TEXT::GetBoundingBox() const { // We must pass the effective text thickness to GetTextBox // when calculating the bounding box int linewidth = GetThickness() == 0 ? GetDefaultLineThickness() : GetThickness(); linewidth = Clamp_Text_PenSize( linewidth, GetTextSize(), IsBold() ); EDA_RECT rect = GetTextBox( -1, linewidth ); if( GetTextAngle() != 0 ) // Rotate rect { wxPoint pos = rect.GetOrigin(); wxPoint end = rect.GetEnd(); RotatePoint( &pos, GetTextPos(), GetTextAngle() ); RotatePoint( &end, GetTextPos(), GetTextAngle() ); rect.SetOrigin( pos ); rect.SetEnd( end ); } rect.Normalize(); return rect; }
double LIB_EDIT_FRAME::BestZoom() { LIB_PART* part = GetCurPart(); double defaultLibraryZoom = 7.33; if( !part ) { SetScrollCenterPosition( wxPoint( 0, 0 ) ); return defaultLibraryZoom; } EDA_RECT boundingBox = part->GetUnitBoundingBox( m_unit, m_convert ); double sizeX = (double) boundingBox.GetWidth(); double sizeY = (double) boundingBox.GetHeight(); wxPoint centre = boundingBox.Centre(); // Reserve a 20% margin around component bounding box. double margin_scale_factor = 1.2; return bestZoom( sizeX, sizeY, margin_scale_factor, centre); }
void LIB_FIELD::drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset, EDA_COLOR_T aColor, GR_DRAWMODE aDrawMode, void* aData, const TRANSFORM& aTransform ) { wxPoint text_pos; int color; int linewidth = GetPenSize(); if( m_Bold ) linewidth = GetPenSizeForBold( m_Size.x ); else linewidth = Clamp_Text_PenSize( linewidth, m_Size, m_Bold ); if( ( m_Attributs & TEXT_NO_VISIBLE ) && ( aColor < 0 ) ) { color = GetInvisibleItemColor(); } else if( IsSelected() && ( aColor < 0 ) ) { color = GetItemSelectedColor(); } else { color = aColor; } if( color < 0 ) color = GetDefaultColor(); text_pos = aTransform.TransformCoordinate( m_Pos ) + aOffset; wxString text; if( aData ) text = *(wxString*)aData; else text = m_Text; GRSetDrawMode( aDC, aDrawMode ); EDA_RECT* clipbox = aPanel? aPanel->GetClipBox() : NULL; DrawGraphicText( clipbox, aDC, text_pos, (EDA_COLOR_T) color, text, m_Orient, m_Size, m_HJustify, m_VJustify, linewidth, m_Italic, m_Bold ); /* Set to one (1) to draw bounding box around field text to validate * bounding box calculation. */ #if 0 EDA_RECT bBox = GetBoundingBox(); EDA_RECT grBox; grBox.SetOrigin( aTransform.TransformCoordinate( bBox.GetOrigin() ) ); grBox.SetEnd( aTransform.TransformCoordinate( bBox.GetEnd() ) ); grBox.Move( aOffset ); GRRect( clipbox, aDC, grBox, 0, LIGHTMAGENTA ); #endif }
void WORKSHEET_DATAITEM_TEXT::SetConstrainedTextSize() { m_ConstrainedTextSize = m_TextSize; if( m_ConstrainedTextSize.x == 0 ) m_ConstrainedTextSize.x = m_DefaultTextSize.x; if( m_ConstrainedTextSize.y == 0 ) m_ConstrainedTextSize.y = m_DefaultTextSize.y; if( m_BoundingBoxSize.x || m_BoundingBoxSize.y ) { int linewidth = 0; // to know the X and Y size of the line, we should use // EDA_TEXT::GetTextBox() // but this function uses integers // So, to avoid truncations with our unit in mm, use microns. wxSize size_micron; size_micron.x = KiROUND( m_ConstrainedTextSize.x * 1000.0 ); size_micron.y = KiROUND( m_ConstrainedTextSize.y * 1000.0 ); WS_DRAW_ITEM_TEXT dummy( WS_DRAW_ITEM_TEXT( this, this->m_FullText, wxPoint(0,0), size_micron, linewidth, BLACK, IsItalic(), IsBold() ) ); dummy.SetMultilineAllowed( true ); TransfertSetupToGraphicText( &dummy ); EDA_RECT rect = dummy.GetTextBox(); DSIZE size; size.x = rect.GetWidth() / 1000.0; size.y = rect.GetHeight() / 1000.0; if( m_BoundingBoxSize.x && size.x > m_BoundingBoxSize.x ) m_ConstrainedTextSize.x *= m_BoundingBoxSize.x / size.x; if( m_BoundingBoxSize.y && size.y > m_BoundingBoxSize.y ) m_ConstrainedTextSize.y *= m_BoundingBoxSize.y / size.y; } }
const EDA_RECT LIB_POLYLINE::GetBoundingBox() const { EDA_RECT rect; int xmin, xmax, ymin, ymax; xmin = xmax = m_PolyPoints[0].x; ymin = ymax = m_PolyPoints[0].y; for( unsigned ii = 1; ii < GetCornerCount(); ii++ ) { xmin = std::min( xmin, m_PolyPoints[ii].x ); xmax = std::max( xmax, m_PolyPoints[ii].x ); ymin = std::min( ymin, m_PolyPoints[ii].y ); ymax = std::max( ymax, m_PolyPoints[ii].y ); } rect.SetOrigin( xmin, ymin * -1 ); rect.SetEnd( xmax, ymax * -1 ); rect.Inflate( m_Width / 2, m_Width / 2 ); return rect; }
int SCH_SHEET::GetMinWidth() const { int width = MIN_SHEET_WIDTH; for( size_t i = 0; i < m_pins.size(); i++ ) { int edge = m_pins[i].GetEdge(); EDA_RECT pinRect = m_pins[i].GetBoundingBox(); wxASSERT( edge != SCH_SHEET_PIN::SHEET_UNDEFINED_SIDE ); if( edge == SCH_SHEET_PIN::SHEET_TOP_SIDE || edge == SCH_SHEET_PIN::SHEET_BOTTOM_SIDE ) { if( width < pinRect.GetRight() - m_pos.x ) width = pinRect.GetRight() - m_pos.x; } else { if( width < pinRect.GetWidth() ) width = pinRect.GetWidth(); for( size_t j = 0; j < m_pins.size(); j++ ) { // Check for pin directly across from the current pin. if( (i == j) || (m_pins[i].GetPosition().y != m_pins[j].GetPosition().y) ) continue; if( width < pinRect.GetWidth() + m_pins[j].GetBoundingBox().GetWidth() ) { width = pinRect.GetWidth() + m_pins[j].GetBoundingBox().GetWidth(); break; } } } } return width; }
const EDA_RECT CPolyLine::GetBoundingBox( int icont ) { int xmin = INT_MAX; int ymin = INT_MAX; int xmax = INT_MIN; int ymax = INT_MIN; int istart = GetContourStart( icont ); int iend = GetContourEnd( icont ); for( int i = istart; i<=iend; i++ ) { xmin = std::min( xmin, m_CornersList[i].x ); xmax = std::max( xmax, m_CornersList[i].x ); ymin = std::min( ymin, m_CornersList[i].y ); ymax = std::max( ymax, m_CornersList[i].y ); } EDA_RECT r; r.SetOrigin( wxPoint( xmin, ymin ) ); r.SetEnd( wxPoint( xmax, ymax ) ); return r; }
int SCH_SHEET::GetMinHeight() const { int height = MIN_SHEET_HEIGHT; for( size_t i = 0; i < m_pins.size(); i++ ) { int edge = m_pins[i].GetEdge(); EDA_RECT pinRect = m_pins[i].GetBoundingBox(); // Make sure pin is on top or bottom side of sheet. if( edge == SCH_SHEET_PIN::SHEET_RIGHT_SIDE || edge == SCH_SHEET_PIN::SHEET_LEFT_SIDE ) { if( height < pinRect.GetBottom() - m_pos.y ) height = pinRect.GetBottom() - m_pos.y; } else { if( height < pinRect.GetHeight() ) height = pinRect.GetHeight(); for( size_t j = 0; j < m_pins.size(); j++ ) { // Check for pin directly above or below the current pin. if( (i == j) || (m_pins[i].GetPosition().x != m_pins[j].GetPosition().x) ) continue; if( height < pinRect.GetHeight() + m_pins[j].GetBoundingBox().GetHeight() ) { height = pinRect.GetHeight() + m_pins[j].GetBoundingBox().GetHeight(); break; } } } } return height; }
/* * Draw (on m_panelShowPin) the pin currently edited * accroding to current settings in dialog */ void DIALOG_LIB_EDIT_PIN::OnPaintShowPanel( wxPaintEvent& event ) { wxPaintDC dc( m_panelShowPin ); wxSize dc_size = dc.GetSize(); dc.SetDeviceOrigin( dc_size.x / 2, dc_size.y / 2 ); // Give a parent to m_dummyPin only from draw purpose. // In fact m_dummyPin should not have a parent, but draw functions need a parent // to know some options, about pin texts LIB_EDIT_FRAME* libframe = (LIB_EDIT_FRAME*) GetParent(); m_dummyPin->SetParent( libframe->GetCurPart() ); // Calculate a suitable scale to fit the available draw area EDA_RECT bBox = m_dummyPin->GetBoundingBox(); double xscale = (double) dc_size.x / bBox.GetWidth(); double yscale = (double) dc_size.y / bBox.GetHeight(); double scale = std::min( xscale, yscale ); // Give a 10% margin scale *= 0.9; dc.SetUserScale( scale, scale ); wxPoint offset = -bBox.Centre(); GRResetPenAndBrush( &dc ); // This is a flag for m_dummyPin->Draw uintptr_t flags = uintptr_t( PIN_DRAW_TEXTS | PIN_DRAW_DANGLING ); m_dummyPin->Draw( NULL, &dc, offset, COLOR4D::UNSPECIFIED, GR_COPY, (void*)flags, DefaultTransform ); m_dummyPin->SetParent(NULL); event.Skip(); }