Commit 544ca4c9 authored by charras's avatar charras

solved a very subtle bug in polygon_test_point_inside.cpp. Sometimes a point...

solved a very subtle bug in polygon_test_point_inside.cpp. Sometimes a point outside a polygon was seen inside the polygon
parent 686cd2c5
......@@ -30,6 +30,7 @@ ZONE_CONTAINER::ZONE_CONTAINER( BOARD* parent ) :
utility2 = 0; // flags used in polygon calculations
m_Poly = new CPolyLine(); // Outlines
m_ArcToSegmentsCount = 16; // Use 16 segment to convert a circle to a polygon
m_DrawOptions = 0;
}
......@@ -137,8 +138,9 @@ bool ZONE_CONTAINER::Save( FILE* aFile ) const
if( ret < 2 )
return false;
ret = fprintf( aFile, "ZOptions %d %d\n", m_GridFillValue, m_ArcToSegmentsCount );
if( ret < 2 )
ret = fprintf( aFile, "ZOptions %d %d %c\n", m_GridFillValue, m_ArcToSegmentsCount,
m_DrawOptions ? 'S' : 'F' );
if( ret < 3 )
return false;
......@@ -266,20 +268,26 @@ int ZONE_CONTAINER::ReadDescr( FILE* aFile, int* aLineNum )
break;
}
}
/* Set hatch later, afer reading outlines corners data */
/* Set hatch mode later, after reading outlines corners data */
}
if( strnicmp( Line, "ZOptions", 8 ) == 0 ) // Options info found
{
int gridsize = 50;
int arcsegmentcount = 16;
int drawopt = 'F';
text = Line + 8;
ret = sscanf( text, "%d %d", &gridsize, &arcsegmentcount );
if( ret < 1 ) // Must find 1 or 2 args.
ret = sscanf( text, "%d %d %c", &gridsize, &arcsegmentcount, &drawopt );
if( ret < 1 ) // Must find 1 or more args.
return false;
else
m_GridFillValue = gridsize;
if ( arcsegmentcount >= 32 )
m_ArcToSegmentsCount = 32;
if ( drawopt == 'S' ) // Sketch mode for filled areas in this zone selected
m_DrawOptions = 1;
}
if( strnicmp( Line, "ZClearance", 10 ) == 0 ) // Clearence and pad options info found
{
......@@ -436,7 +444,7 @@ void ZONE_CONTAINER::DrawFilledArea( WinEDA_DrawPanel* panel,
{
static int* CornersBuffer = NULL;
static unsigned CornersBufferSize = 0;
bool sketch_mode = false; // true to show areas outlines only (test and debug purposes)
bool sketch_mode = m_DrawOptions; // false to show filled polys, true to show polygons outlines only (test and debug purposes)
if( DC == NULL )
return;
......
......@@ -41,6 +41,9 @@ public:
* In less simple cases (when m_Poly has holes) m_FilledPolysList is a polygon equivalent to m_Poly, without holes
* In complex cases an ouline decribed by m_Poly can have many filled areas
*/
int m_DrawOptions; /* used to pass some draw options (draw filled areas in sketch mode for instance ...)
* currently useful when testing filling zones algos
*/
private:
int m_NetCode; // Net number for fast comparisons
......@@ -155,7 +158,7 @@ public:
* This function does not add holes for pads and tracks but calls
* AddClearanceAreasPolygonsToPolysList() to do that for copper layers
*/
int BuildFilledPolysListData( BOARD * aPcb );
int BuildFilledPolysListData( BOARD* aPcb );
/** function AddClearanceAreasPolygonsToPolysList
* Add non copper areas polygons (pads and tracks with clearence)
......@@ -167,7 +170,7 @@ public:
* filled copper area polygon (without clearence areas
* @param aPcb: the current board
*/
void AddClearanceAreasPolygonsToPolysList( BOARD * aPcb );
void AddClearanceAreasPolygonsToPolysList( BOARD* aPcb );
/**
* Function HitTestForCorner
......
......@@ -121,6 +121,12 @@ void dialog_copper_zone::OnInitDialog( wxInitDialogEvent& event )
g_Zone_Hatching = m_Zone_Container->m_Poly->GetHatchStyle();
g_Zone_Arc_Approximation = m_Zone_Container->m_ArcToSegmentsCount;
g_FilledAreasShowMode = m_Zone_Container->m_DrawOptions;
if ( g_FilledAreasShowMode == 1)
m_ShowFilledAreasInSketchOpt->SetValue(true);
}
else
{
......@@ -242,19 +248,21 @@ void dialog_copper_zone::OnInitDialog( wxInitDialogEvent& event )
}
/*************************************************************/
/********************************************************************/
void dialog_copper_zone::OnButtonCancelClick( wxCommandEvent& event )
/*************************************************************/
/********************************************************************/
{
EndModal( ZONE_ABORT );
}
/**********************************************************/
bool dialog_copper_zone::AcceptOptions(bool aPromptForErrors)
/**********************************************************/
/********************************************************************************************/
bool dialog_copper_zone::AcceptOptions(bool aPromptForErrors, bool aUseExportableSetupOnly)
/********************************************************************************************/
/** Function dialog_copper_zone::AcceptOptions(
* @return false if incorrect options, true if Ok.
* @param aPromptForErrors = true to prompt user on incorrectparams
* @param aUseExportableSetupOnly = true to use exportable parametres only (used to export this setup to other zones)
*/
{
switch( m_FillOpt->GetSelection() )
......@@ -315,7 +323,7 @@ bool dialog_copper_zone::AcceptOptions(bool aPromptForErrors)
case 4:
g_GridRoutingSize = 0;
wxMessageBox( wxT(
DisplayInfo( this, wxT(
"You are using No grid for filling zones\nThis is currently in development and for tests only.\n Do not use for production"));
break;
}
......@@ -328,6 +336,12 @@ bool dialog_copper_zone::AcceptOptions(bool aPromptForErrors)
else
g_Zone_45_Only = TRUE;
g_FilledAreasShowMode = m_ShowFilledAreasInSketchOpt->IsChecked() ? 1 : 0;
// If we use only exportable to others zones parameters, exit here:
if ( aUseExportableSetupOnly )
return true;
/* Get the layer selection for this zone */
int ii = m_LayerSelectionCtrl->GetSelection();
if( ii < 0 && aPromptForErrors )
......@@ -335,8 +349,11 @@ bool dialog_copper_zone::AcceptOptions(bool aPromptForErrors)
DisplayError( this, _( "Error : you must choose a layer" ) );
return false;
}
g_CurrentZone_Layer = m_LayerId[ii];
/* Get the net name selection for this zone */
ii = m_ListNetNameSelection->GetSelection();
if( ii < 0 && aPromptForErrors )
......@@ -432,4 +449,25 @@ void dialog_copper_zone::OnRemoveFillZoneButtonClick( wxCommandEvent& event )
m_Parent->DrawPanel->Refresh();
}
/******************************************************************************/
void dialog_copper_zone::ExportSetupToOtherCopperZones( wxCommandEvent& event )
/******************************************************************************/
{
if ( !AcceptOptions(true, true) )
return;
// Export to others zones:
BOARD * pcb = m_Parent->m_Pcb;
for( int ii = 0; ii < pcb->GetAreaCount(); ii++ )
{
ZONE_CONTAINER* zone = pcb->GetArea(ii);
zone->m_Poly->SetHatch( g_Zone_Hatching );
zone->m_PadOption = g_Zone_Pad_Options;
zone->m_ZoneClearance = g_DesignSettings.m_ZoneClearence;
zone->m_GridFillValue = g_GridRoutingSize;
zone->m_ArcToSegmentsCount = g_Zone_Arc_Approximation;
zone->m_DrawOptions = g_FilledAreasShowMode;
m_Parent->GetScreen()->SetModify();;
}
}
......@@ -20,9 +20,10 @@ public:
void OnInitDialog( wxInitDialogEvent& event );
void OnButtonOkClick( wxCommandEvent& event );
void OnButtonCancelClick( wxCommandEvent& event );
bool AcceptOptions(bool aPromptForErrors);
bool AcceptOptions(bool aPromptForErrors, bool aUseExportableSetupOnly = false);
void OnRemoveFillZoneButtonClick( wxCommandEvent& event );
void OnNetSortingOptionSelected( wxCommandEvent& event );
void ExportSetupToOtherCopperZones( wxCommandEvent& event );
};
#endif // #ifndef DIALOG_COPPER_ZONES
......@@ -11,9 +11,10 @@
BEGIN_EVENT_TABLE( dialog_copper_zone_frame, wxDialog )
EVT_INIT_DIALOG( dialog_copper_zone_frame::_wxFB_OnInitDialog )
EVT_BUTTON( wxID_BUTTON_EXPORT, dialog_copper_zone_frame::_wxFB_ExportSetupToOtherCopperZones )
EVT_BUTTON( wxID_OK, dialog_copper_zone_frame::_wxFB_OnButtonOkClick )
EVT_BUTTON( wxID_CANCEL, dialog_copper_zone_frame::_wxFB_OnButtonCancelClick )
EVT_BUTTON( wxID_ANY, dialog_copper_zone_frame::_wxFB_OnRemoveFillZoneButtonClick )
EVT_BUTTON( wxID_BUTTON_UNFILL, dialog_copper_zone_frame::_wxFB_OnRemoveFillZoneButtonClick )
EVT_RADIOBOX( ID_NET_SORTING_OPTION, dialog_copper_zone_frame::_wxFB_OnNetSortingOptionSelected )
END_EVENT_TABLE()
......@@ -27,6 +28,9 @@ dialog_copper_zone_frame::dialog_copper_zone_frame( wxWindow* parent, wxWindowID
wxBoxSizer* m_OptionsBoxSizer;
m_OptionsBoxSizer = new wxBoxSizer( wxHORIZONTAL );
wxStaticBoxSizer* m_ExportableSetupSizer;
m_ExportableSetupSizer = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, _("Zone Setup:") ), wxHORIZONTAL );
wxBoxSizer* m_LeftBoxSizer;
m_LeftBoxSizer = new wxBoxSizer( wxVERTICAL );
......@@ -36,8 +40,8 @@ dialog_copper_zone_frame::dialog_copper_zone_frame( wxWindow* parent, wxWindowID
wxString m_GridCtrlChoices[] = { _("0.00000"), _("0.00000"), _("0.00000"), _("0.00000"), _("No Grid (For tests only!)") };
int m_GridCtrlNChoices = sizeof( m_GridCtrlChoices ) / sizeof( wxString );
m_GridCtrl = new wxRadioBox( this, ID_RADIOBOX_GRID_SELECTION, _("Grid Size for Filling:"), wxDefaultPosition, wxDefaultSize, m_GridCtrlNChoices, m_GridCtrlChoices, 1, wxRA_SPECIFY_COLS );
m_GridCtrl->SetSelection( 1 );
m_FillOptionsBox->Add( m_GridCtrl, 0, wxALL, 5 );
m_GridCtrl->SetSelection( 0 );
m_FillOptionsBox->Add( m_GridCtrl, 0, wxALL|wxEXPAND, 5 );
m_ClearanceValueTitle = new wxStaticText( this, wxID_ANY, _("Zone clearance value (mm):"), wxDefaultPosition, wxDefaultSize, 0 );
m_ClearanceValueTitle->Wrap( -1 );
......@@ -49,15 +53,24 @@ dialog_copper_zone_frame::dialog_copper_zone_frame( wxWindow* parent, wxWindowID
wxString m_FillOptChoices[] = { _("Include Pads"), _("Thermal Relief"), _("Exclude Pads") };
int m_FillOptNChoices = sizeof( m_FillOptChoices ) / sizeof( wxString );
m_FillOpt = new wxRadioBox( this, wxID_ANY, _("Pad in Zone:"), wxDefaultPosition, wxDefaultSize, m_FillOptNChoices, m_FillOptChoices, 1, wxRA_SPECIFY_COLS );
m_FillOpt->SetSelection( 1 );
m_FillOpt->SetSelection( 2 );
m_FillOptionsBox->Add( m_FillOpt, 0, wxALL|wxEXPAND, 5 );
m_ShowFilledAreasInSketchOpt = new wxCheckBox( this, wxID_ANY, _("Show filled areas in sketch mode"), wxDefaultPosition, wxDefaultSize, 0 );
m_ShowFilledAreasInSketchOpt->SetToolTip( _("If enabled, filled areas in is this zone will be displayed as non filled polygons.\nIf disabled, filled areas in is this zone will be displayed as \"solid\" areas (normal mode).") );
m_FillOptionsBox->Add( m_ShowFilledAreasInSketchOpt, 0, wxALL, 5 );
m_LeftBoxSizer->Add( m_FillOptionsBox, 1, wxEXPAND, 5 );
m_OptionsBoxSizer->Add( m_LeftBoxSizer, 0, wxEXPAND|wxALIGN_CENTER_VERTICAL, 5 );
m_ExportableSetupSizer->Add( m_LeftBoxSizer, 0, wxEXPAND|wxALIGN_CENTER_VERTICAL, 5 );
m_ExportableSetupSizer->Add( 5, 5, 0, wxEXPAND, 5 );
m_OptionsBoxSizer->Add( 5, 5, 0, wxEXPAND, 5 );
wxBoxSizer* m_MiddleBox;
m_MiddleBox = new wxBoxSizer( wxVERTICAL );
wxBoxSizer* m_MiddleBoxSizer;
m_MiddleBoxSizer = new wxBoxSizer( wxVERTICAL );
......@@ -92,7 +105,16 @@ dialog_copper_zone_frame::dialog_copper_zone_frame( wxWindow* parent, wxWindowID
m_MiddleBoxSizer->Add( m_OutilinesBoxOpt, 1, wxEXPAND, 5 );
m_OptionsBoxSizer->Add( m_MiddleBoxSizer, 0, 0, 5 );
m_ExportSetupBuuton = new wxButton( this, wxID_BUTTON_EXPORT, _("Export to others zones"), wxDefaultPosition, wxDefaultSize, 0 );
m_ExportSetupBuuton->SetToolTip( _("Export this zone setup to all others copper zones") );
m_MiddleBoxSizer->Add( m_ExportSetupBuuton, 0, wxALL|wxALIGN_CENTER_HORIZONTAL, 5 );
m_MiddleBox->Add( m_MiddleBoxSizer, 0, 0, 5 );
m_ExportableSetupSizer->Add( m_MiddleBox, 1, wxEXPAND, 5 );
m_OptionsBoxSizer->Add( m_ExportableSetupSizer, 1, wxEXPAND, 5 );
m_OptionsBoxSizer->Add( 0, 0, 0, wxEXPAND, 5 );
......@@ -107,7 +129,7 @@ dialog_copper_zone_frame::dialog_copper_zone_frame( wxWindow* parent, wxWindowID
m_ButtonCancel = new wxButton( this, wxID_CANCEL, _("Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
m_RightBoxSizer->Add( m_ButtonCancel, 0, wxALL|wxALIGN_CENTER_HORIZONTAL, 5 );
m_UnFillZoneButton = new wxButton( this, wxID_ANY, _("UnFill Zone"), wxDefaultPosition, wxDefaultSize, 0 );
m_UnFillZoneButton = new wxButton( this, wxID_BUTTON_UNFILL, _("UnFill Zone"), wxDefaultPosition, wxDefaultSize, 0 );
m_RightBoxSizer->Add( m_UnFillZoneButton, 0, wxALL|wxALIGN_CENTER_HORIZONTAL, 5 );
......
This diff is collapsed.
......@@ -18,6 +18,7 @@
#include <wx/settings.h>
#include <wx/stattext.h>
#include <wx/textctrl.h>
#include <wx/checkbox.h>
#include <wx/sizer.h>
#include <wx/statbox.h>
#include <wx/button.h>
......@@ -36,6 +37,7 @@ class dialog_copper_zone_frame : public wxDialog
// Private event handlers
void _wxFB_OnInitDialog( wxInitDialogEvent& event ){ OnInitDialog( event ); }
void _wxFB_ExportSetupToOtherCopperZones( wxCommandEvent& event ){ ExportSetupToOtherCopperZones( event ); }
void _wxFB_OnButtonOkClick( wxCommandEvent& event ){ OnButtonOkClick( event ); }
void _wxFB_OnButtonCancelClick( wxCommandEvent& event ){ OnButtonCancelClick( event ); }
void _wxFB_OnRemoveFillZoneButtonClick( wxCommandEvent& event ){ OnRemoveFillZoneButtonClick( event ); }
......@@ -48,6 +50,8 @@ class dialog_copper_zone_frame : public wxDialog
ID_RADIOBOX_GRID_SELECTION = 1000,
ID_RADIOBOX_OUTLINES_OPTION,
wxID_ARC_APPROX,
wxID_BUTTON_EXPORT,
wxID_BUTTON_UNFILL,
ID_NET_SORTING_OPTION,
ID_TEXTCTRL_NETNAMES_FILTER,
ID_NETNAME_SELECTION,
......@@ -58,11 +62,13 @@ class dialog_copper_zone_frame : public wxDialog
wxStaticText* m_ClearanceValueTitle;
wxTextCtrl* m_ZoneClearanceCtrl;
wxRadioBox* m_FillOpt;
wxCheckBox* m_ShowFilledAreasInSketchOpt;
wxRadioBox* m_OrientEdgesOpt;
wxRadioBox* m_OutlineAppearanceCtrl;
wxRadioBox* m_ArcApproximationOpt;
wxButton* m_ExportSetupBuuton;
wxButton* m_OkButton;
wxButton* m_ButtonCancel;
......@@ -78,6 +84,7 @@ class dialog_copper_zone_frame : public wxDialog
// Virtual event handlers, overide them in your derived class
virtual void OnInitDialog( wxInitDialogEvent& event ){ event.Skip(); }
virtual void ExportSetupToOtherCopperZones( wxCommandEvent& event ){ event.Skip(); }
virtual void OnButtonOkClick( wxCommandEvent& event ){ event.Skip(); }
virtual void OnButtonCancelClick( wxCommandEvent& event ){ event.Skip(); }
virtual void OnRemoveFillZoneButtonClick( wxCommandEvent& event ){ event.Skip(); }
......
......@@ -36,6 +36,7 @@ eda_global int g_CurrentZone_Layer; // Layer used to create the
eda_global int g_Zone_Hatching; // Option to show the zone area (outlines only, short hatches or full hatches
eda_global int g_Zone_Arc_Approximation; // Option to select number of segments to approximate a circle
// 16 or 32 segments
eda_global int g_FilledAreasShowMode; // Used to select draw options for filled areas in a zone (currently normal =0, sketch = 1)
eda_global ZONE_CONTAINER::m_PadInZone g_Zone_Pad_Options
#ifdef MAIN
......
......@@ -794,6 +794,7 @@ void WinEDA_PcbFrame::Edit_Zone_Params( wxDC* DC, ZONE_CONTAINER* zone_container
zone_container->m_ZoneClearance = g_DesignSettings.m_ZoneClearence;
zone_container->m_GridFillValue = g_GridRoutingSize;
zone_container->m_ArcToSegmentsCount = g_Zone_Arc_Approximation;
zone_container->m_DrawOptions = g_FilledAreasShowMode;
// Combine zones if possible :
......
......@@ -331,6 +331,13 @@ bool TestPointInsidePolygon( std::vector <CPolyPt> aPolysList,
{
xx = (int) intersectx1;
yy = (int) intersecty1;
/* if the intersection point is on the start point of the current segment,
* do not count it,
* because it was already counted, as ending point of the previous segment
*/
if( xx == aPolysList[ics].x && yy == aPolysList[ics].y )
continue;
#if OUTSIDE_IF_ON_SIDE
if( xx == refx && yy == refy )
return false; // (x,y) is on a side, call it outside
......
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