Commit 544ca4c9 authored by charras's avatar charras
Browse files

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
Loading
Loading
Loading
Loading
+14 −6
Original line number Original line Diff line number Diff line
@@ -30,6 +30,7 @@ ZONE_CONTAINER::ZONE_CONTAINER( BOARD* parent ) :
    utility2 = 0;               // flags used in polygon calculations
    utility2 = 0;               // flags used in polygon calculations
    m_Poly   = new CPolyLine(); // Outlines
    m_Poly   = new CPolyLine(); // Outlines
    m_ArcToSegmentsCount = 16;   // Use 16 segment to convert a circle to a polygon
    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 )
    if( ret < 2 )
        return false;
        return false;


    ret = fprintf( aFile, "ZOptions %d %d\n", m_GridFillValue, m_ArcToSegmentsCount );
    ret = fprintf( aFile, "ZOptions %d %d %c\n", m_GridFillValue, m_ArcToSegmentsCount,
    if( ret < 2 )
                m_DrawOptions ? 'S' : 'F' );
    if( ret < 3 )
        return false;
        return false;




@@ -266,20 +268,26 @@ int ZONE_CONTAINER::ReadDescr( FILE* aFile, int* aLineNum )
                    break;
                    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
        if( strnicmp( Line, "ZOptions", 8 ) == 0 )    // Options info found
        {
        {
            int gridsize = 50;
            int gridsize = 50;
            int arcsegmentcount = 16;
            int arcsegmentcount = 16;
            int drawopt = 'F';
            text = Line + 8;
            text = Line + 8;
            ret  = sscanf( text, "%d %d", &gridsize, &arcsegmentcount );
            ret  = sscanf( text, "%d %d %c", &gridsize, &arcsegmentcount, &drawopt );
            if( ret < 1 )   // Must find 1 or 2 args.
            if( ret < 1 )   // Must find 1 or more args.
                return false;
                return false;
            else
            else
                m_GridFillValue = gridsize;
                m_GridFillValue = gridsize;

            if ( arcsegmentcount >= 32 )
            if ( arcsegmentcount >= 32 )
                m_ArcToSegmentsCount = 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
        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 int*     CornersBuffer     = NULL;
    static unsigned CornersBufferSize = 0;
    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 )
    if( DC == NULL )
        return;
        return;
+31 −28
Original line number Original line Diff line number Diff line
@@ -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 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
                                               * 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:
private:
    int                   m_NetCode; // Net number for fast comparisons
    int                   m_NetCode; // Net number for fast comparisons
+45 −7
Original line number Original line Diff line number Diff line
@@ -121,6 +121,12 @@ void dialog_copper_zone::OnInitDialog( wxInitDialogEvent& event )
        g_Zone_Hatching = m_Zone_Container->m_Poly->GetHatchStyle();
        g_Zone_Hatching = m_Zone_Container->m_Poly->GetHatchStyle();
        g_Zone_Arc_Approximation = m_Zone_Container->m_ArcToSegmentsCount;
        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
    else
    {
    {
@@ -242,19 +248,21 @@ void dialog_copper_zone::OnInitDialog( wxInitDialogEvent& event )
}
}




/*************************************************************/
/********************************************************************/
void dialog_copper_zone::OnButtonCancelClick( wxCommandEvent& event )
void dialog_copper_zone::OnButtonCancelClick( wxCommandEvent& event )
/*************************************************************/
/********************************************************************/
{
{
    EndModal( ZONE_ABORT );
    EndModal( ZONE_ABORT );
}
}




/**********************************************************/
/********************************************************************************************/
bool dialog_copper_zone::AcceptOptions(bool aPromptForErrors)
bool dialog_copper_zone::AcceptOptions(bool aPromptForErrors, bool aUseExportableSetupOnly)
/**********************************************************/
/********************************************************************************************/
/** Function dialog_copper_zone::AcceptOptions(
/** Function dialog_copper_zone::AcceptOptions(
 * @return false if incorrect options, true if Ok.
 * @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() )
    switch( m_FillOpt->GetSelection() )
@@ -315,7 +323,7 @@ bool dialog_copper_zone::AcceptOptions(bool aPromptForErrors)


    case 4:
    case 4:
        g_GridRoutingSize = 0;
        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"));
"You are using No grid for filling zones\nThis is currently in development and for tests only.\n Do not use for production"));
        break;
        break;
    }
    }
@@ -328,6 +336,12 @@ bool dialog_copper_zone::AcceptOptions(bool aPromptForErrors)
    else
    else
        g_Zone_45_Only = TRUE;
        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 */
    /* Get the layer selection for this zone */
    int ii = m_LayerSelectionCtrl->GetSelection();
    int ii = m_LayerSelectionCtrl->GetSelection();
    if( ii < 0 && aPromptForErrors )
    if( ii < 0 && aPromptForErrors )
@@ -335,8 +349,11 @@ bool dialog_copper_zone::AcceptOptions(bool aPromptForErrors)
        DisplayError( this, _( "Error : you must choose a layer" ) );
        DisplayError( this, _( "Error : you must choose a layer" ) );
        return false;
        return false;
    }
    }
    

    g_CurrentZone_Layer = m_LayerId[ii];
    g_CurrentZone_Layer = m_LayerId[ii];
    
    

    /* Get the net name selection for this zone */
    /* Get the net name selection for this zone */
    ii = m_ListNetNameSelection->GetSelection();
    ii = m_ListNetNameSelection->GetSelection();
    if( ii < 0 && aPromptForErrors )
    if( ii < 0 && aPromptForErrors )
@@ -432,4 +449,25 @@ void dialog_copper_zone::OnRemoveFillZoneButtonClick( wxCommandEvent& event )
    m_Parent->DrawPanel->Refresh();
    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();;
    }
}
+2 −1
Original line number Original line Diff line number Diff line
@@ -20,9 +20,10 @@ public:
    void OnInitDialog( wxInitDialogEvent& event );
    void OnInitDialog( wxInitDialogEvent& event );
	void OnButtonOkClick( wxCommandEvent& event );
	void OnButtonOkClick( wxCommandEvent& event );
	void OnButtonCancelClick( wxCommandEvent& event );
	void OnButtonCancelClick( wxCommandEvent& event );
    bool AcceptOptions(bool aPromptForErrors);
    bool AcceptOptions(bool aPromptForErrors, bool aUseExportableSetupOnly = false);
	void OnRemoveFillZoneButtonClick( wxCommandEvent& event );
	void OnRemoveFillZoneButtonClick( wxCommandEvent& event );
    void OnNetSortingOptionSelected( wxCommandEvent& event );
    void OnNetSortingOptionSelected( wxCommandEvent& event );
	void ExportSetupToOtherCopperZones( wxCommandEvent& event );
};
};


#endif      // #ifndef DIALOG_COPPER_ZONES
#endif      // #ifndef DIALOG_COPPER_ZONES
+30 −8
Original line number Original line Diff line number Diff line
@@ -11,9 +11,10 @@


BEGIN_EVENT_TABLE( dialog_copper_zone_frame, wxDialog )
BEGIN_EVENT_TABLE( dialog_copper_zone_frame, wxDialog )
	EVT_INIT_DIALOG( dialog_copper_zone_frame::_wxFB_OnInitDialog )
	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_OK, dialog_copper_zone_frame::_wxFB_OnButtonOkClick )
	EVT_BUTTON( wxID_CANCEL, dialog_copper_zone_frame::_wxFB_OnButtonCancelClick )
	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 )
	EVT_RADIOBOX( ID_NET_SORTING_OPTION, dialog_copper_zone_frame::_wxFB_OnNetSortingOptionSelected )
END_EVENT_TABLE()
END_EVENT_TABLE()


@@ -27,6 +28,9 @@ dialog_copper_zone_frame::dialog_copper_zone_frame( wxWindow* parent, wxWindowID
	wxBoxSizer* m_OptionsBoxSizer;
	wxBoxSizer* m_OptionsBoxSizer;
	m_OptionsBoxSizer = new wxBoxSizer( wxHORIZONTAL );
	m_OptionsBoxSizer = new wxBoxSizer( wxHORIZONTAL );
	
	
	wxStaticBoxSizer* m_ExportableSetupSizer;
	m_ExportableSetupSizer = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, _("Zone Setup:") ), wxHORIZONTAL );
	
	wxBoxSizer* m_LeftBoxSizer;
	wxBoxSizer* m_LeftBoxSizer;
	m_LeftBoxSizer = new wxBoxSizer( wxVERTICAL );
	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!)") };
	wxString m_GridCtrlChoices[] = { _("0.00000"), _("0.00000"), _("0.00000"), _("0.00000"), _("No Grid (For tests only!)") };
	int m_GridCtrlNChoices = sizeof( m_GridCtrlChoices ) / sizeof( wxString );
	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 = 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_GridCtrl->SetSelection( 0 );
	m_FillOptionsBox->Add( m_GridCtrl, 0, wxALL, 5 );
	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 = new wxStaticText( this, wxID_ANY, _("Zone clearance value (mm):"), wxDefaultPosition, wxDefaultSize, 0 );
	m_ClearanceValueTitle->Wrap( -1 );
	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") };
	wxString m_FillOptChoices[] = { _("Include Pads"), _("Thermal Relief"), _("Exclude Pads") };
	int m_FillOptNChoices = sizeof( m_FillOptChoices ) / sizeof( wxString );
	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 = 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_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_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;
	wxBoxSizer* m_MiddleBoxSizer;
	m_MiddleBoxSizer = new wxBoxSizer( wxVERTICAL );
	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_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 );
	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_ButtonCancel = new wxButton( this, wxID_CANCEL, _("Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
	m_RightBoxSizer->Add( m_ButtonCancel, 0, wxALL|wxALIGN_CENTER_HORIZONTAL, 5 );
	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 );
	m_RightBoxSizer->Add( m_UnFillZoneButton, 0, wxALL|wxALIGN_CENTER_HORIZONTAL, 5 );
	
	
	
	
Loading