Commit 6c3235c1 authored by CHARRAS's avatar CHARRAS

first DRC control about zone outlines. Needs improvements, but works

parent 8d90da0a
......@@ -259,6 +259,21 @@ public:
return NULL;
}
/**
* Function GetAreaIndex
* returns the Area Index for the given Zone Container.
* @param aArea :The ZONE_CONTAINER to find.
* @return an Area Index in m_ZoneDescriptorList or -1 if non found.
*/
int GetAreaIndex( const ZONE_CONTAINER* aArea) const
{
for( int ii = 0; ii < GetAreaCount(); ii++ ) // Search for aArea in list
{
if ( aArea == GetArea( ii ) ) // Found !
return ii;
}
return -1;
}
/**
* Function GetAreaCount
......@@ -385,6 +400,16 @@ public:
*/
int CombineAreas( ZONE_CONTAINER* area_ref, ZONE_CONTAINER* area_to_combine );
/**
* Function Test_Drc_Areas_Outlines_To_Areas_Outlines
* Test Areas outlines for DRC:
* Test areas inside other areas
* Test areas too close
* @param aArea_To_Examine: area to compare with other areas. if NULL: all areas are compared tp all others
* @param aCreate_Markers: if true create DRC markers. False: do not creates anything
* @return errors count
*/
int Test_Drc_Areas_Outlines_To_Areas_Outlines( ZONE_CONTAINER* aArea_To_Examine,bool aCreate_Markers );
};
#endif // #ifndef CLASS_BOARD_H
......@@ -65,6 +65,10 @@ wxString DRC_ITEM::GetErrorText() const
return wxString( _("Pad near pad") );
case DRCE_VIA_HOLE_BIGGER:
return wxString( _("Via hole > diameter"));
case COPPERAREA_INSIDE_COPPERAREA:
return wxString( _("Copper area inside copper area"));
case COPPERAREA_CLOSE_TO_COPPERAREA:
return wxString( _("Copper areas intersect or too close"));
default:
return wxString( wxT("PROGRAM BUG, PLEASE LEAVE THE ROOM.") );
......
......@@ -124,8 +124,8 @@ void MARKER::Display_Infos( WinEDA_DrawFrame* frame )
wxString txtB;
txtB << DRC_ITEM::ShowCoord( rpt.GetPointB() ) << wxT(": ") << rpt.GetTextB();
text_pos = 20; // @todo pick a better color here
Affiche_1_Parametre( frame, text_pos, txtA, txtB, BLACK );
text_pos = 25;
Affiche_1_Parametre( frame, text_pos, txtA, txtB, DARKBROWN );
}
......
......@@ -35,7 +35,7 @@
const KICAD_T GENERAL_COLLECTOR::AllBoardItems[] = {
// there are some restrictions on the order of items in the general case.
// all items in m_Drawings for instance should be contiguous.
// *** all items in a same list (shown here) must be contigous ****
// *** all items in a same list (shown here) must be contiguous ****
TYPEMARKER, // in m_markers
TYPETEXTE, // in m_Drawings
TYPEDRAWSEGMENT, // in m_Drawings
......
......@@ -290,6 +290,10 @@ void WinEDA_ZoneFrame::CreateControls()
if ( m_Zone_Container )
s_Zone_Hatching = m_Zone_Container->m_Poly->GetHatchStyle();
else
s_Zone_Hatching = m_Parent->m_Parent->m_EDA_Config->Read( ZONE_NET_OUTLINES_HATCH_OPTION_KEY,
(long) CPolyLine::DIAGONAL_EDGE );
switch( s_Zone_Hatching )
{
case CPolyLine::NO_HATCH:
......@@ -461,6 +465,11 @@ bool WinEDA_ZoneFrame::AcceptOptions(bool aPromptForErrors)
break;
}
if( m_Parent->m_Parent->m_EDA_Config )
{
m_Parent->m_Parent->m_EDA_Config->Write( ZONE_NET_OUTLINES_HATCH_OPTION_KEY, (long)s_Zone_Hatching);
}
switch( m_GridCtrl->GetSelection() )
{
case 0:
......
......@@ -285,6 +285,10 @@ void DRC::testUnconnected()
void DRC::testZones()
{
// Test copper areas outlines, and create markers when needed
m_pcb->Test_Drc_Areas_Outlines_To_Areas_Outlines( NULL, true );
TRACK* zoneSeg;
/* this was for display purposes, don't know that we need it anymore
......
......@@ -54,7 +54,8 @@
#define DRCE_ENDS_PROBLEM5 18 ///< track ends are too close
#define DRCE_PAD_NEAR_PAD1 19 ///< pad too close to pad
#define DRCE_VIA_HOLE_BIGGER 20 ///< via's hole is bigger than its diameter
#define COPPERAREA_INSIDE_COPPERAREA 21 ///< copper area outlines intersect
#define COPPERAREA_CLOSE_TO_COPPERAREA 22 ///< copper area outlines are too close
/**
* Class DRC_ITEM
......
/////////////////////////////////////////////////////////////////////////////
// Name: zones_by_polygon.cpp
// Licence: GNU License
// Licence: GPL License
/////////////////////////////////////////////////////////////////////////////
#if defined (__GNUG__) && !defined (NO_GCC_PRAGMA)
......@@ -35,7 +34,7 @@ using namespace std;
/* Local functions */
// Outile creation:
// Outline creation:
static void Abort_Zone_Create_Outline( WinEDA_DrawPanel* Panel, wxDC* DC );
static void Show_New_Zone_Edge_While_Move_Mouse( WinEDA_DrawPanel* panel, wxDC* DC, bool erase );
......@@ -54,7 +53,8 @@ static bool s_CornerIsNew; // Used to abort
static bool s_AddCutoutToCurrentZone; // if true, the next outline will be addes to s_CurrentZone
static ZONE_CONTAINER* s_CurrentZone; // if != NULL, these ZONE_CONTAINER params will be used for the next zone
// key used to store net sort option in config file :
// keys used to store net sort option in config file :
#define ZONE_NET_OUTLINES_HATCH_OPTION_KEY wxT( "Zone_Ouline_Hatch_Opt" )
#define ZONE_NET_SORT_OPTION_KEY wxT( "Zone_NetSort_Opt" )
#define ZONE_NET_FILTER_STRING_KEY wxT( "Zone_Filter_Opt" )
......@@ -297,6 +297,8 @@ void WinEDA_PcbFrame::End_Move_Zone_Corner( wxDC* DC, ZONE_CONTAINER* zone_conta
SetCurItem( NULL ); // This outine can be deleted when merging outlines
/* Combine zones if possible */
wxBusyCursor dummy;
int layer = zone_container->GetLayer();
for( int ii = 0; ii < m_Pcb->GetAreaCount(); ii++ )
......@@ -313,6 +315,14 @@ void WinEDA_PcbFrame::End_Move_Zone_Corner( wxDC* DC, ZONE_CONTAINER* zone_conta
if( layer == edge_zone->GetLayer() )
edge_zone->Draw( DrawPanel, DC, wxPoint( 0, 0 ), GR_OR );
}
int ii = m_Pcb->GetAreaIndex(zone_container); // test if zone_container exists
if ( ii < 0 ) zone_container = NULL; // was removed by combining zones
int error_count = m_Pcb->Test_Drc_Areas_Outlines_To_Areas_Outlines(zone_container, true);
if ( error_count )
{
DisplayError(this, _("Area: DRC outline error"));
}
}
......@@ -325,6 +335,8 @@ void WinEDA_PcbFrame::Remove_Zone_Corner( wxDC* DC, ZONE_CONTAINER * zone_contai
* the .m_CornerSelection is used as corner selection
*/
{
GetScreen()->SetModify();
if ( zone_container->m_Poly->GetNumCorners() <= 3 )
{
Delete_Zone_Fill( DC, NULL, zone_container->m_TimeStamp );
......@@ -357,6 +369,14 @@ void WinEDA_PcbFrame::Remove_Zone_Corner( wxDC* DC, ZONE_CONTAINER * zone_contai
edge_zone->Draw( DrawPanel, DC, wxPoint( 0, 0 ), GR_OR );
}
}
int ii = m_Pcb->GetAreaIndex(zone_container); // test if zone_container exists
if ( ii < 0 ) zone_container = NULL; // was removed by combining zones
int error_count = m_Pcb->Test_Drc_Areas_Outlines_To_Areas_Outlines(zone_container, true);
if ( error_count )
{
DisplayError(this, _("Area: DRC outline error"));
}
}
......@@ -639,6 +659,14 @@ void WinEDA_PcbFrame::End_Zone( wxDC* DC )
edge_zone->Draw( DrawPanel, DC, wxPoint( 0, 0 ), GR_OR );
}
int ii = m_Pcb->GetAreaIndex(new_zone_container); // test if zone_container exists
if ( ii < 0 ) new_zone_container = NULL; // was removed by combining zones
int error_count = m_Pcb->Test_Drc_Areas_Outlines_To_Areas_Outlines(new_zone_container, true);
if ( error_count )
{
DisplayError(this, _("Area: DRC outline error"));
}
GetScreen()->SetModify();
}
......
/****************************************************************************/
/* Name: zones_by_polygon.cpp */
/* Licence: GPL License */
/* functions to test, merges and cut polygons used as copper areas outlines */
/****************************************************************************/
......@@ -374,7 +376,7 @@ int BOARD::CombineAllAreasInNet( int aNetCode, bool bMessageBox, bool bUseUtilit
if( !( b1.left > b2.right || b1.right < b2.left
|| b1.bottom > b2.top || b1.top < b2.bottom ) )
{
// check ia2 against 1a1
// check area2 against curr_area
if( curr_area->utility || area2->utility || bUseUtility ==
false )
{
......@@ -442,10 +444,11 @@ bool BOARD::TestAreaIntersections( ZONE_CONTAINER* area_to_test )
for( unsigned ia2 = 0; ia2 < m_ZoneDescriptorList.size(); ia2++ )
{
ZONE_CONTAINER* area2 = m_ZoneDescriptorList[ia2];
if( area_to_test->GetNet() != area_to_test->GetNet() )
if( area_to_test->GetNet() != area2->GetNet() )
continue;
if( area_to_test != area2 )
{
if( area_to_test == area2 )
continue;
// see if areas are on same layer
if( area_to_test->GetLayer() != area2->GetLayer() )
continue;
......@@ -511,7 +514,6 @@ bool BOARD::TestAreaIntersections( ZONE_CONTAINER* area_to_test )
}
}
}
}
return false;
}
......@@ -690,7 +692,8 @@ int BOARD::CombineAreas( ZONE_CONTAINER* area_ref, ZONE_CONTAINER* area_to_combi
int y = ( (union_gpc->contour)[ic].vertex )[i].y;
if( i==0 )
{
area_ref->m_Poly->Start( area_ref->GetLayer(), 0, 0, x, y, area_ref->m_Poly->GetHatchStyle() );
area_ref->m_Poly->Start( area_ref->GetLayer(
), 0, 0, x, y, area_ref->m_Poly->GetHatchStyle() );
}
else
area_ref->m_Poly->AppendCorner( x, y );
......@@ -727,164 +730,178 @@ int BOARD::CombineAreas( ZONE_CONTAINER* area_ref, ZONE_CONTAINER* area_to_combi
}
#if 0
void dra_areas( CDlgLog* log, int copper_layers,
int units, BOOL check_unrouted,
CArray<CPolyLine> * board_outline,
DesignRules* dr, DRErrorList* drelist )
#if 0 // Currently not used: work in progress
/**
* Function Is_Area_Inside_Area
* Test a given area to see if it is inside an other area, or an other area is inside the given area
* an area is inside an other are if ALL its corners are inside
* @param Area_Ref: the given area to compare with other areas
* used to remove redundant areas
*/
ZONE_CONTAINER* BOARD::Is_Area_Inside_Area( ZONE_CONTAINER* Area_Ref)
{
CString d_str, x_str, y_str;
CString str;
CString str2;
long nerrors = 0;
// now iterate through all areas
for( int ia = 0; ia<net->nareas; ia++ )
int corners_inside_count;
for( int ia = 0; ia < GetAreaCount(); ia++ )
{
ZONE_CONTAINER* Area_To_Test = GetArea( ia );
if( Area_Ref == Area_To_Test )
continue;
// test for same layer
if( Area_Ref->GetLayer() != Area_To_Test->GetLayer() )
continue;
// test if Area_Ref inside Area_To_Test
corners_inside_count = Area_Ref->m_Poly->GetNumCorners();
for( int ic = 0; ic < Area_Ref->m_Poly->GetNumCorners(); ic++ )
{
ZONE_CONTAINER* a = &net->area[ia];
int x = Area_Ref->m_Poly->GetX( ic );
int y = Area_Ref->m_Poly->GetY( ic );
if( Area_To_Test->m_Poly->TestPointInside( x, y ) )
corners_inside_count--;
}
if ( corners_inside_count == 0 )
return Area_Ref;
// test if Area_To_Test inside Area_Ref
corners_inside_count = Area_To_Test->m_Poly->GetNumCorners();
for( int ic2 = 0; ic2 < Area_To_Test->m_Poly->GetNumCorners(); ic2++ )
{
int x = Area_To_Test->m_Poly->GetX( ic2 );
int y = Area_To_Test->m_Poly->GetY( ic2 );
if( Area_Ref->m_Poly->TestPointInside( x, y ) )
corners_inside_count--;
}
if ( corners_inside_count == 0 )
return Area_Ref;
}
return NULL;
}
#endif
/**
* Function Test_Drc_Areas_Outlines_To_Areas_Outlines
* Test Areas outlines for DRC:
* Test areas inside other areas
* Test areas too close
* @param aArea_To_Examine: area to compare with other areas. if NULL: all areas are compared tp all others
* @param aCreate_Markers: if true create DRC markers. False: do not creates anything
* @return errors count
*/
int BOARD::Test_Drc_Areas_Outlines_To_Areas_Outlines( ZONE_CONTAINER* aArea_To_Examine,
bool aCreate_Markers)
{
wxString str;
long nerrors = 0;
// iterate through all nets again
POSITION pos2 = pos;
void* ptr2;
CString name2;
while( pos2 != NULL )
// iterate through all areas
for( int ia = 0; ia < GetAreaCount(); ia++ )
{
m_nlist->m_map.GetNextAssoc( pos2, name2, ptr2 );
cnet* net2 = (cnet*) ptr2;
for( int ia2 = 0; ia2<net2->nareas; ia2++ )
ZONE_CONTAINER* Area_Ref = GetArea( ia );
if ( aArea_To_Examine && (aArea_To_Examine != Area_Ref) )
continue;
for( int ia2 = 0; ia2 < GetAreaCount(); ia2++ )
{
ZONE_CONTAINER* a2 = &net2->area[ia2];
ZONE_CONTAINER* Area_To_Test = GetArea( ia2 );
if( Area_Ref == Area_To_Test )
continue;
// test for same layer
if( a->m_Poly->GetLayer() == a2->m_Poly->GetLayer() )
{
// test for points inside one another
for( int ic = 0; ic<a->m_Poly->GetNumCorners(); ic++ )
{
int x = a->m_Poly->GetX( ic );
int y = a->m_Poly->GetY( ic );
if( a2->m_Poly->TestPointInside( x, y ) )
{
// COPPERAREA_COPPERAREA error
id id_a = net->id;
id_a.st = ID_AREA;
id_a.i = ia;
id_a.sst = ID_SEL_CORNER;
id_a.ii = ic;
str.Format(
"%ld: \"%s\" copper area inside \"%s\" inside copper area\r\n",
nerrors + 1,
net->name,
net2->name );
DRError* dre = drelist->Add( nerrors,
DRError::COPPERAREA_INSIDE_COPPERAREA,
&str,
&net->name,
&net2->name,
id_a,
id_a,
x,
y,
x,
y,
0,
0 );
if( dre )
if( Area_Ref->GetLayer() != Area_To_Test->GetLayer() )
continue;
// Test for same net
if( Area_Ref->GetNet() == Area_To_Test->GetNet() )
continue;
// test for some corners of Area_Ref inside Area_To_Test
for( int ic = 0; ic < Area_Ref->m_Poly->GetNumCorners(); ic++ )
{
nerrors++;
if( log )
log->AddLine( str );
}
}
}
for( int ic2 = 0; ic2<a2->m_Poly->GetNumCorners(); ic2++ )
{
int x = a2->m_Poly->GetX( ic2 );
int y = a2->m_Poly->GetY( ic2 );
if( a->m_Poly->TestPointInside( x, y ) )
{
// COPPERAREA_COPPERAREA error
id id_a = net2->id;
id_a.st = ID_AREA;
id_a.i = ia2;
id_a.sst = ID_SEL_CORNER;
id_a.ii = ic2;
str.Format( "%ld: \"%s\" copper area inside \"%s\" copper area\r\n",
nerrors + 1, net2->name, net->name );
DRError* dre = drelist->Add( nerrors,
DRError::COPPERAREA_INSIDE_COPPERAREA,
&str,
&net2->name,
&net->name,
id_a,
id_a,
x,
y,
x,
y,
0,
0 );
if( dre )
int x = Area_Ref->m_Poly->GetX( ic );
int y = Area_Ref->m_Poly->GetY( ic );
if( Area_To_Test->m_Poly->TestPointInside( x, y ) )
{
// COPPERAREA_COPPERAREA error: copper area ref corner inside copper area
if ( aCreate_Markers )
{
wxString msg1 = Area_Ref->MenuText(this);
wxString msg2 = Area_To_Test->MenuText(this);
MARKER* marker = new MARKER( COPPERAREA_INSIDE_COPPERAREA, wxPoint( x, y ),
msg1, wxPoint( x, y ),
msg2, wxPoint( x, y ) );
Add( marker );
}
nerrors++;
if( log )
log->AddLine( str );
}
}
// test for some corners of Area_To_Test inside Area_Ref
for( int ic2 = 0; ic2 < Area_To_Test->m_Poly->GetNumCorners(); ic2++ )
{
int x = Area_To_Test->m_Poly->GetX( ic2 );
int y = Area_To_Test->m_Poly->GetY( ic2 );
if( Area_Ref->m_Poly->TestPointInside( x, y ) )
{
// COPPERAREA_COPPERAREA error: copper area corner inside copper area ref
if ( aCreate_Markers )
{
wxString msg1 = Area_To_Test->MenuText(this);
wxString msg2 = Area_Ref->MenuText(this);
MARKER* marker = new MARKER( COPPERAREA_INSIDE_COPPERAREA, wxPoint( x, y ),
msg1, wxPoint( x, y ),
msg2, wxPoint( x, y ) );
Add( marker );
}
nerrors++;
}
}
// now test spacing between areas
for( int icont = 0; icont<a->m_Poly->GetNumContours(); icont++ )
for( int icont = 0; icont < Area_Ref->m_Poly->GetNumContours(); icont++ )
{
int ic_start = a->m_Poly->GetContourStart( icont );
int ic_end = a->m_Poly->GetContourEnd( icont );
int ic_start = Area_Ref->m_Poly->GetContourStart( icont );
int ic_end = Area_Ref->m_Poly->GetContourEnd( icont );
for( int ic = ic_start; ic<=ic_end; ic++ )
{
id id_a = net->id;
id_a.st = ID_AREA;
id_a.i = ia;
id_a.sst = ID_SIDE;
id_a.ii = ic;
int ax1 = a->m_Poly->GetX( ic );
int ay1 = a->m_Poly->GetY( ic );
int ax1 = Area_Ref->m_Poly->GetX( ic );
int ay1 = Area_Ref->m_Poly->GetY( ic );
int ax2, ay2;
if( ic == ic_end )
{
ax2 = a->m_Poly->GetX( ic_start );
ay2 = a->m_Poly->GetY( ic_start );
ax2 = Area_Ref->m_Poly->GetX( ic_start );
ay2 = Area_Ref->m_Poly->GetY( ic_start );
}
else
{
ax2 = a->m_Poly->GetX( ic + 1 );
ay2 = a->m_Poly->GetY( ic + 1 );
ax2 = Area_Ref->m_Poly->GetX( ic + 1 );
ay2 = Area_Ref->m_Poly->GetY( ic + 1 );
}
int astyle = a->m_Poly->GetSideStyle( ic );
for( int icont2 = 0; icont2<a2->m_Poly->GetNumContours(); icont2++ )
int astyle = Area_Ref->m_Poly->GetSideStyle( ic );
for( int icont2 = 0; icont2 < Area_To_Test->m_Poly->GetNumContours(); icont2++ )
{
int ic_start2 = a2->m_Poly->GetContourStart( icont2 );
int ic_end2 = a2->m_Poly->GetContourEnd( icont2 );
int ic_start2 = Area_To_Test->m_Poly->GetContourStart( icont2 );
int ic_end2 = Area_To_Test->m_Poly->GetContourEnd( icont2 );
for( int ic2 = ic_start2; ic2<=ic_end2; ic2++ )
{
id id_b = net2->id;
id_b.st = ID_AREA;
id_b.i = ia2;
id_b.sst = ID_SIDE;
id_b.ii = ic2;
int bx1 = a2->m_Poly->GetX( ic2 );
int by1 = a2->m_Poly->GetY( ic2 );
int bx1 = Area_To_Test->m_Poly->GetX( ic2 );
int by1 = Area_To_Test->m_Poly->GetY( ic2 );
int bx2, by2;
if( ic2 == ic_end2 )
{
bx2 = a2->m_Poly->GetX( ic_start2 );
by2 = a2->m_Poly->GetY( ic_start2 );
bx2 = Area_To_Test->m_Poly->GetX( ic_start2 );
by2 = Area_To_Test->m_Poly->GetY( ic_start2 );
}
else
{
bx2 = a2->m_Poly->GetX( ic2 + 1 );
by2 = a2->m_Poly->GetY( ic2 + 1 );
bx2 = Area_To_Test->m_Poly->GetX( ic2 + 1 );
by2 = Area_To_Test->m_Poly->GetY( ic2 + 1 );
}
int bstyle = a2->m_Poly->GetSideStyle( ic2 );
int bstyle = Area_To_Test->m_Poly->GetSideStyle( ic2 );
int x, y;
int d = ::GetClearanceBetweenSegments( bx1,
by1,
......@@ -898,64 +915,22 @@ void dra_areas( CDlgLog* log, int copper_layers,
ay2,
astyle,
0,
dr->copper_copper,
g_DesignSettings.m_TrackClearence,
&x,
&y );
if( d < dr->copper_copper )
{
// COPPERAREA_COPPERAREA error
::MakeCStringFromDimension( &d_str,
d,
units,
TRUE,
TRUE,
TRUE,
1 );
::MakeCStringFromDimension( &x_str,
x,
units,
FALSE,
TRUE,
TRUE,
1 );
::MakeCStringFromDimension( &y_str,
y,
units,
FALSE,
TRUE,
TRUE,
1 );
str.Format(
"%ld: \"%s\" copper area to \"%s\" copper area = %s, x=%s, y=%s\r\n",
nerrors + 1,
net->name,
net2->name,
d_str,
x_str,
y_str );
DRError* dre = drelist->Add(
nerrors,
DRError::
COPPERAREA_COPPERAREA,
&str,
&net->name,
&net2->name,
id_a,
id_b,
x,
y,
x,
y,
0,
0 );
if( dre )
if( d < g_DesignSettings.m_TrackClearence )
{
nerrors++;
if( log )
log->AddLine( str );
}
}
// COPPERAREA_COPPERAREA error : intersect or too close
if ( aCreate_Markers )
{
wxString msg1 = Area_Ref->MenuText(this);
wxString msg2 = Area_To_Test->MenuText(this);
MARKER* marker = new MARKER( COPPERAREA_CLOSE_TO_COPPERAREA, wxPoint( x, y ),
msg1, wxPoint( x, y ),
msg2, wxPoint( x, y ) );
Add( marker );
}
nerrors++;
}
}
}
......@@ -963,7 +938,7 @@ void dra_areas( CDlgLog* log, int copper_layers,
}
}
}
}
return nerrors;
}
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment