bool VIA::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const { EDA_RECT box; EDA_RECT arect = aRect; arect.Inflate( aAccuracy ); box.SetOrigin( GetStart() ); box.Inflate( GetWidth() / 2 ); if( aContained ) return arect.Contains( box ); else return arect.Intersects( box ); }
bool DIMENSION::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const { EDA_RECT arect = aRect; arect.Inflate( aAccuracy ); EDA_RECT rect = GetBoundingBox(); if( aAccuracy ) rect.Inflate( aAccuracy ); if( aContained ) return arect.Contains( rect ); return arect.Intersects( rect ); }
void EDA_TEXT::TransformBoundingBoxWithClearanceToPolygon( SHAPE_POLY_SET* aCornerBuffer, int aClearanceValue ) const { // Oh dear. When in UTF-8 mode, wxString puts string iterators in a linked list, and // that linked list is not thread-safe. std::lock_guard<std::mutex> guard( m_mutex ); if( GetText().Length() == 0 ) return; wxPoint corners[4]; // Buffer of polygon corners EDA_RECT rect = GetTextBox( -1 ); rect.Inflate( aClearanceValue ); corners[0].x = rect.GetOrigin().x; corners[0].y = rect.GetOrigin().y; corners[1].y = corners[0].y; corners[1].x = rect.GetRight(); corners[2].x = corners[1].x; corners[2].y = rect.GetBottom(); corners[3].y = corners[2].y; corners[3].x = corners[0].x; aCornerBuffer->NewOutline(); for( int ii = 0; ii < 4; ii++ ) { // Rotate polygon RotatePoint( &corners[ii].x, &corners[ii].y, GetTextPos().x, GetTextPos().y, GetTextAngle() ); aCornerBuffer->Append( corners[ii].x, corners[ii].y ); } }
const EDA_RECT LIB_BEZIER::GetBoundingBox() const { EDA_RECT rect; int xmin, xmax, ymin, ymax; if( !GetCornerCount() ) return rect; 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 ); rect.SetEnd( xmax, ymax ); rect.Inflate( ( GetPenSize()+1 ) / 2 ); rect.RevertYAxis(); return rect; }
/** * Function TransformBoundingBoxWithClearanceToPolygon * Convert the text bounding box to a rectangular polygon * Used in filling zones calculations * Circles and arcs are approximated by segments * @param aCornerBuffer = a buffer to store the polygon * @param aClearanceValue = the clearance around the text bounding box */ void TEXTE_PCB::TransformBoundingBoxWithClearanceToPolygon( SHAPE_POLY_SET& aCornerBuffer, int aClearanceValue ) const { if( GetText().Length() == 0 ) return; wxPoint corners[4]; // Buffer of polygon corners EDA_RECT rect = GetTextBox( -1 ); rect.Inflate( aClearanceValue ); corners[0].x = rect.GetOrigin().x; corners[0].y = rect.GetOrigin().y; corners[1].y = corners[0].y; corners[1].x = rect.GetRight(); corners[2].x = corners[1].x; corners[2].y = rect.GetBottom(); corners[3].y = corners[2].y; corners[3].x = corners[0].x; aCornerBuffer.NewOutline(); for( int ii = 0; ii < 4; ii++ ) { // Rotate polygon RotatePoint( &corners[ii].x, &corners[ii].y, m_Pos.x, m_Pos.y, m_Orient ); aCornerBuffer.Append( corners[ii].x, corners[ii].y ); } }
/* Test if the module can be placed on the board. * Returns the value TstRectangle(). * Module is known by its bounding box */ int TstModuleOnBoard( BOARD* Pcb, MODULE* aModule, bool TstOtherSide ) { int side = TOP; int otherside = BOTTOM; if( aModule->GetLayer() == B_Cu ) { side = BOTTOM; otherside = TOP; } EDA_RECT fpBBox = aModule->GetFootprintRect(); fpBBox.Move( -g_Offset_Module ); int diag = TstRectangle( Pcb, fpBBox, side ); if( diag != FREE_CELL ) return diag; if( TstOtherSide ) { diag = TstRectangle( Pcb, fpBBox, otherside ); if( diag != FREE_CELL ) return diag; } int marge = ( RoutingMatrix.m_GridRouting * aModule->GetPadCount() ) / GAIN; fpBBox.Inflate( marge ); return CalculateKeepOutArea( fpBBox, side ); }
/* 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 ); }
bool SCH_SHEET_PIN::HitTest( const wxPoint& aPoint, int aAccuracy ) const { EDA_RECT rect = GetBoundingBox(); rect.Inflate( aAccuracy ); return rect.Contains( aPoint ); }
bool SCH_JUNCTION::HitTest( const wxPoint& aPosition, int aAccuracy ) const { EDA_RECT rect = GetBoundingBox(); rect.Inflate( aAccuracy ); return rect.Contains( aPosition ); }
/* This function is used to extract a board outlines (3D view, automatic zones build ...) * Any closed outline inside the main outline is a hole * All contours should be closed, i.e. valid closed polygon vertices */ bool BuildBoardPolygonOutlines( BOARD* aBoard, SHAPE_POLY_SET& aOutlines, wxString* aErrorText, unsigned int aTolerance, wxPoint* aErrorLocation ) { PCB_TYPE_COLLECTOR items; // Get all the DRAWSEGMENTS and module graphics into 'items', // then keep only those on layer == Edge_Cuts. static const KICAD_T scan_graphics[] = { PCB_LINE_T, PCB_MODULE_EDGE_T, EOT }; items.Collect( aBoard, scan_graphics ); // Make a working copy of aSegList, because the list is modified during calculations std::vector< DRAWSEGMENT* > segList; for( int ii = 0; ii < items.GetCount(); ii++ ) { if( items[ii]->GetLayer() == Edge_Cuts ) segList.push_back( static_cast< DRAWSEGMENT* >( items[ii] ) ); } bool success = ConvertOutlineToPolygon( segList, aOutlines, aErrorText, aTolerance, aErrorLocation ); if( !success || !aOutlines.OutlineCount() ) { // Creates a valid polygon outline is not possible. // So uses the board edge cuts bounding box to create a // rectangular outline // When no edge cuts items, build a contour // from global bounding box EDA_RECT bbbox = aBoard->GetBoardEdgesBoundingBox(); // If null area, uses the global bounding box. if( ( bbbox.GetWidth() ) == 0 || ( bbbox.GetHeight() == 0 ) ) bbbox = aBoard->ComputeBoundingBox(); // Ensure non null area. If happen, gives a minimal size. if( ( bbbox.GetWidth() ) == 0 || ( bbbox.GetHeight() == 0 ) ) bbbox.Inflate( Millimeter2iu( 1.0 ) ); aOutlines.RemoveAllContours(); aOutlines.NewOutline(); wxPoint corner; aOutlines.Append( bbbox.GetOrigin() ); corner.x = bbbox.GetOrigin().x; corner.y = bbbox.GetEnd().y; aOutlines.Append( corner ); aOutlines.Append( bbbox.GetEnd() ); corner.x = bbbox.GetEnd().x; corner.y = bbbox.GetOrigin().y; aOutlines.Append( corner ); } return success; }
EDA_RECT LIB_RECTANGLE::GetBoundingBox() const { EDA_RECT rect; rect.SetOrigin( m_Pos.x, m_Pos.y * -1 ); rect.SetEnd( m_End.x, m_End.y * -1 ); rect.Inflate( (GetPenSize() / 2) + 1 ); return rect; }
EDA_RECT SCH_JUNCTION::GetBoundingBox() const { EDA_RECT rect; rect.SetOrigin( m_pos ); rect.Inflate( ( GetPenSize() + m_size.x ) / 2 ); return rect; }
bool ZONE_CONTAINER::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const { EDA_RECT arect = aRect; arect.Inflate( aAccuracy ); CRect rect = m_Poly->GetBoundingBox(); EDA_RECT bbox; bbox.SetOrigin( rect.left, rect.bottom ); bbox.SetEnd( rect.right, rect.top ); if( aContained ) return arect.Contains( bbox ); else // Test for intersection between aRect and the polygon // For a polygon, using its bounding box has no sense here { // Fast test: if aRect is outside the polygon bounding box, // rectangles cannot intersect if( ! bbox.Intersects( arect ) ) return false; // aRect is inside the polygon bounding box, // and can intersect the polygon: use a fine test. // aRect intersects the polygon if at least one aRect corner // is inside the polygon wxPoint corner = arect.GetOrigin(); if( HitTestInsideZone( corner ) ) return true; corner.x = arect.GetEnd().x; if( HitTestInsideZone( corner ) ) return true; corner = arect.GetEnd(); if( HitTestInsideZone( corner ) ) return true; corner.x = arect.GetOrigin().x; if( HitTestInsideZone( corner ) ) return true; // No corner inside arect, but outlines can intersect arect // if one of outline corners is inside arect int count = m_Poly->GetCornersCount(); for( int ii =0; ii < count; ii++ ) { if( arect.Contains( m_Poly->GetPos( ii ) ) ) return true; } return false; } }
bool MODULE::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const { EDA_RECT arect = aRect; arect.Inflate( aAccuracy ); if( aContained ) return arect.Contains( m_BoundaryBox ); else return m_BoundaryBox.Intersects( arect ); }
bool EDA_TEXT::TextHitTest( const wxPoint& aPoint, int aAccuracy ) const { EDA_RECT rect = GetTextBox( -1 ); // Get the full text area. wxPoint location = aPoint; rect.Inflate( aAccuracy ); RotatePoint( &location, m_Pos, -m_Orient ); return rect.Contains( location ); }
bool PCB_TARGET::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const { EDA_RECT arect = aRect; arect.Inflate( aAccuracy ); if( aContained ) return arect.Contains( GetBoundingBox() ); else return GetBoundingBox().Intersects( arect ); }
/** Prefill in black an area a little bigger than the board to prepare for the * negative plot */ static void FillNegativeKnockout( PLOTTER *aPlotter, const EDA_RECT &aBbbox ) { const int margin = 5 * IU_PER_MM; // Add a 5 mm margin around the board aPlotter->SetNegative( true ); aPlotter->SetColor( WHITE ); // Which will be plotted as black EDA_RECT area = aBbbox; area.Inflate( margin ); aPlotter->Rect( area.GetOrigin(), area.GetEnd(), FILLED_SHAPE ); aPlotter->SetColor( BLACK ); }
const EDA_RECT LIB_CIRCLE::GetBoundingBox() const { EDA_RECT rect; rect.SetOrigin( m_Pos.x - m_Radius, ( m_Pos.y - m_Radius ) * -1 ); rect.SetEnd( m_Pos.x + m_Radius, ( m_Pos.y + m_Radius ) * -1 ); rect.Inflate( m_Width / 2, m_Width / 2 ); return rect; }
bool SCH_TEXT::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const { EDA_RECT bBox = GetBoundingBox(); bBox.Inflate( aAccuracy ); if( aContained ) return aRect.Contains( bBox ); return aRect.Intersects( bBox ); }
EDA_RECT BITMAP_BASE::GetBoundingBox() const { EDA_RECT rect; wxSize size = GetSize(); rect.Inflate( size.x / 2, size.y / 2 ); return rect; }
const EDA_RECT SCH_NO_CONNECT::GetBoundingBox() const { int delta = ( GetPenSize() + m_size.x ) / 2; EDA_RECT box; box.SetOrigin( m_pos ); box.Inflate( delta ); return box; }
void LIB_POLYLINE::drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset, EDA_COLOR_T aColor, GR_DRAWMODE aDrawMode, void* aData, const TRANSFORM& aTransform ) { wxPoint pos1; EDA_COLOR_T color = GetLayerColor( LAYER_DEVICE ); wxPoint* buffer = NULL; if( aColor < 0 ) // Used normal color or selected color { if( IsSelected() ) color = GetItemSelectedColor(); } else { color = aColor; } buffer = new wxPoint[ m_PolyPoints.size() ]; for( unsigned ii = 0; ii < m_PolyPoints.size(); ii++ ) { buffer[ii] = aTransform.TransformCoordinate( m_PolyPoints[ii] ) + aOffset; } FILL_T fill = aData ? NO_FILL : m_Fill; if( aColor >= 0 ) fill = NO_FILL; GRSetDrawMode( aDC, aDrawMode ); EDA_RECT* const clipbox = aPanel? aPanel->GetClipBox() : NULL; if( fill == FILLED_WITH_BG_BODYCOLOR ) GRPoly( clipbox, aDC, m_PolyPoints.size(), buffer, 1, GetPenSize(), (m_Flags & IS_MOVED) ? color : GetLayerColor( LAYER_DEVICE_BACKGROUND ), GetLayerColor( LAYER_DEVICE_BACKGROUND ) ); else if( fill == FILLED_SHAPE ) GRPoly( clipbox, aDC, m_PolyPoints.size(), buffer, 1, GetPenSize(), color, color ); else GRPoly( clipbox, aDC, m_PolyPoints.size(), buffer, 0, GetPenSize(), color, color ); delete[] buffer; /* Set to one (1) to draw bounding box around polyline to validate * bounding box calculation. */ #if 0 EDA_RECT bBox = GetBoundingBox(); bBox.Inflate( m_Thickness + 1, m_Thickness + 1 ); GRRect( clipbox, aDC, bBox.GetOrigin().x, bBox.GetOrigin().y, bBox.GetEnd().x, bBox.GetEnd().y, 0, LIGHTMAGENTA ); #endif }
bool SCH_BUS_ENTRY_BASE::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const { EDA_RECT rect = aRect; rect.Inflate( aAccuracy ); if( aContained ) return rect.Contains( GetBoundingBox() ); return rect.Intersects( GetBoundingBox() ); }
bool EDA_TEXT::TextHitTest( const EDA_RECT& aRect, bool aContains, int aAccuracy ) const { EDA_RECT rect = aRect; rect.Inflate( aAccuracy ); if( aContains ) return rect.Contains( GetTextBox( -1 ) ); return rect.Intersects( GetTextBox( -1 ) ); }
bool TEXTE_MODULE::TextHitTest( const wxPoint& aPoint, int aAccuracy ) const { EDA_RECT rect = GetTextBox( -1 ); wxPoint location = aPoint; rect.Inflate( aAccuracy ); RotatePoint( &location, GetTextPos(), -GetDrawRotation() ); return rect.Contains( location ); }
bool TRACK::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const { EDA_RECT arect = aRect; arect.Inflate( aAccuracy ); if( aContained ) /* Tracks are a special case: * they are considered inside the rect if one end is inside the rect */ return arect.Contains( GetStart() ) || arect.Contains( GetEnd() ); else return arect.Intersects( GetStart(), GetEnd() ); }
const EDA_RECT SCH_BUS_ENTRY_BASE::GetBoundingBox() const { EDA_RECT box; box.SetOrigin( m_pos ); box.SetEnd( m_End() ); box.Normalize(); box.Inflate( GetPenSize() / 2 ); return box; }
bool SCH_FIELD::HitTest( const wxPoint& aPosition, int aAccuracy ) const { // Do not hit test hidden or empty fields. if( !IsVisible() || IsVoid() ) return false; EDA_RECT rect = GetBoundingBox(); rect.Inflate( aAccuracy ); return rect.Contains( aPosition ); }
const EDA_RECT LIB_RECTANGLE::GetBoundingBox() const { EDA_RECT rect; rect.SetOrigin( m_Pos ); rect.SetEnd( m_End ); rect.Inflate( ( GetPenSize()+1 ) / 2 ); rect.RevertYAxis(); return rect; }
const EDA_RECT LIB_CIRCLE::GetBoundingBox() const { EDA_RECT rect; rect.SetOrigin( m_Pos.x - m_Radius, m_Pos.y - m_Radius ); rect.SetEnd( m_Pos.x + m_Radius, m_Pos.y + m_Radius ); rect.Inflate( ( GetPenSize()+1 ) / 2 ); rect.RevertYAxis(); return rect; }