Gerbview: more code refactoring.

This commit is contained in:
jean-pierre charras 2016-05-26 13:57:43 +02:00
parent 3b379787bc
commit 130c6e3639
20 changed files with 216 additions and 208 deletions

View File

@ -33,6 +33,8 @@
#include <class_drawpanel.h> #include <class_drawpanel.h>
#include <gerbview_frame.h> #include <gerbview_frame.h>
#include <class_gerber_draw_item.h> #include <class_gerber_draw_item.h>
#include <class_gerber_file_image.h>
#include <class_gerber_file_image_list.h>
static void DrawMovingBlockOutlines( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition, static void DrawMovingBlockOutlines( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition,
@ -200,14 +202,22 @@ void GERBVIEW_FRAME::Block_Move( wxDC* DC )
/* Calculate displacement vectors. */ /* Calculate displacement vectors. */
delta = GetScreen()->m_BlockLocate.GetMoveVector(); delta = GetScreen()->m_BlockLocate.GetMoveVector();
for( int layer = 0; layer < GERBER_DRAWLAYERS_COUNT; ++layer )
{
GERBER_FILE_IMAGE* gerber = g_GERBER_List.GetGbrImage( layer );
if( gerber == NULL ) // Graphic layer not yet used
continue;
/* Move items in block */ /* Move items in block */
for( GERBER_DRAW_ITEM* item = GetItemsList(); item; item = item->Next() ) for( GERBER_DRAW_ITEM* item = gerber->GetItemsList(); item; item = item->Next() )
{ {
GERBER_DRAW_ITEM* gerb_item = item; GERBER_DRAW_ITEM* gerb_item = item;
if( gerb_item->HitTest( GetScreen()->m_BlockLocate ) ) if( gerb_item->HitTest( GetScreen()->m_BlockLocate ) )
gerb_item->MoveAB( delta ); gerb_item->MoveAB( delta );
} }
}
m_canvas->Refresh( true ); m_canvas->Refresh( true );
} }

View File

@ -93,6 +93,7 @@ private:
READ_HEADER_STATE, // When we are in this state, we are reading header READ_HEADER_STATE, // When we are in this state, we are reading header
READ_PROGRAM_STATE // When we are in this state, we are reading drill data READ_PROGRAM_STATE // When we are in this state, we are reading drill data
}; };
excellon_state m_State; // state of excellon file analysis excellon_state m_State; // state of excellon file analysis
bool m_SlotOn; // true during an oblong drill definition bool m_SlotOn; // true during an oblong drill definition

View File

@ -51,8 +51,16 @@ EDA_RECT GBR_LAYOUT::ComputeBoundingBox()
{ {
EDA_RECT bbox; EDA_RECT bbox;
for( GERBER_DRAW_ITEM* gerb_item = m_Drawings; gerb_item; gerb_item = gerb_item->Next() ) for( int layer = 0; layer < GERBER_DRAWLAYERS_COUNT; ++layer )
bbox.Merge( gerb_item->GetBoundingBox() ); {
GERBER_FILE_IMAGE* gerber = g_GERBER_List.GetGbrImage( layer );
if( gerber == NULL ) // Graphic layer not yet used
continue;
for( GERBER_DRAW_ITEM* item = gerber->GetItemsList(); item; item = item->Next() )
bbox.Merge( item->GetBoundingBox() );
}
SetBoundingBox( bbox ); SetBoundingBox( bbox );
return bbox; return bbox;
@ -232,7 +240,7 @@ void GBR_LAYOUT::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, GR_DRAWMODE aDrawMode,
// Now we can draw the current layer to the bitmap buffer // Now we can draw the current layer to the bitmap buffer
// When needed, the previous bitmap is already copied to the screen buffer. // When needed, the previous bitmap is already copied to the screen buffer.
for( GERBER_DRAW_ITEM* item = gerbFrame->GetItemsList(); item; item = item->Next() ) for( GERBER_DRAW_ITEM* item = gerber->GetItemsList(); item; item = item->Next() )
{ {
if( item->GetLayer() != layer ) if( item->GetLayer() != layer )
continue; continue;

View File

@ -55,8 +55,6 @@ private:
std::bitset <GERBER_DRAWLAYERS_COUNT> m_printLayersMask; // When printing: the list of layers to print std::bitset <GERBER_DRAWLAYERS_COUNT> m_printLayersMask; // When printing: the list of layers to print
public: public:
DLIST<GERBER_DRAW_ITEM> m_Drawings; // linked list of Gerber Items to draw
GBR_LAYOUT(); GBR_LAYOUT();
~GBR_LAYOUT(); ~GBR_LAYOUT();

View File

@ -1,8 +1,8 @@
/* /*
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 1992-2010 <Jean-Pierre Charras> * Copyright (C) 1992-2016 <Jean-Pierre Charras>
* Copyright (C) 1992-2010 KiCad Developers, see change_log.txt for contributors. * Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -38,11 +38,10 @@
#include <class_gerber_file_image.h> #include <class_gerber_file_image.h>
GERBER_DRAW_ITEM::GERBER_DRAW_ITEM( GBR_LAYOUT* aParent, GERBER_FILE_IMAGE* aGerberImageFile ) : GERBER_DRAW_ITEM::GERBER_DRAW_ITEM( GERBER_FILE_IMAGE* aGerberImageFile ) :
EDA_ITEM( (EDA_ITEM*)aParent, TYPE_GERBER_DRAW_ITEM ) EDA_ITEM( (EDA_ITEM*)NULL, TYPE_GERBER_DRAW_ITEM )
{ {
m_GerberImageFile = aGerberImageFile; m_GerberImageFile = aGerberImageFile;
m_Layer = 0;
m_Shape = GBR_SEGMENT; m_Shape = GBR_SEGMENT;
m_Flashed = false; m_Flashed = false;
m_DCode = 0; m_DCode = 0;
@ -72,7 +71,6 @@ GERBER_DRAW_ITEM::GERBER_DRAW_ITEM( const GERBER_DRAW_ITEM& aSource ) :
m_Start = aSource.m_Start; m_Start = aSource.m_Start;
m_End = aSource.m_End; m_End = aSource.m_End;
m_Size = aSource.m_Size; m_Size = aSource.m_Size;
m_Layer = aSource.m_Layer;
m_Shape = aSource.m_Shape; m_Shape = aSource.m_Shape;
m_Flashed = aSource.m_Flashed; m_Flashed = aSource.m_Flashed;
m_DCode = aSource.m_DCode; m_DCode = aSource.m_DCode;
@ -99,6 +97,13 @@ GERBER_DRAW_ITEM* GERBER_DRAW_ITEM::Copy() const
} }
int GERBER_DRAW_ITEM::GetLayer() const
{
// returns the layer this item is on, or 0 if the m_GerberImageFile is NULL.
return m_GerberImageFile ? m_GerberImageFile->m_GraphicLayer : 0;
}
wxPoint GERBER_DRAW_ITEM::GetABPosition( const wxPoint& aXYPosition ) const wxPoint GERBER_DRAW_ITEM::GetABPosition( const wxPoint& aXYPosition ) const
{ {
/* Note: RS274Xrevd_e is obscure about the order of transforms: /* Note: RS274Xrevd_e is obscure about the order of transforms:
@ -612,7 +617,7 @@ void GERBER_DRAW_ITEM::Show( int nestLevel, std::ostream& os ) const
" shape=\"" << m_Shape << '"' << " shape=\"" << m_Shape << '"' <<
" addr=\"" << std::hex << this << std::dec << '"' << " addr=\"" << std::hex << this << std::dec << '"' <<
" layer=\"" << m_Layer << '"' << " layer=\"" << GetLayer() << '"' <<
" size=\"" << m_Size << '"' << " size=\"" << m_Size << '"' <<
" flags=\"" << m_Flags << '"' << " flags=\"" << m_Flags << '"' <<
" status=\"" << GetStatus() << '"' << " status=\"" << GetStatus() << '"' <<

View File

@ -1,8 +1,8 @@
/* /*
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 1992-2010 <Jean-Pierre Charras> * Copyright (C) 1992-2016 <Jean-Pierre Charras>
* Copyright (C) 1992-2010 KiCad Developers, see change_log.txt for contributors. * Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -90,8 +90,6 @@ public:
* redundancy for these parameters * redundancy for these parameters
*/ */
private: private:
int m_Layer;
// These values are used to draw this item, according to gerber layers parameters // These values are used to draw this item, according to gerber layers parameters
// Because they can change inside a gerber image, they are stored here // Because they can change inside a gerber image, they are stored here
// for each item // for each item
@ -104,7 +102,7 @@ private:
double m_lyrRotation; // Fine rotation, from OR parameter, in degrees double m_lyrRotation; // Fine rotation, from OR parameter, in degrees
public: public:
GERBER_DRAW_ITEM( GBR_LAYOUT* aParent, GERBER_FILE_IMAGE* aGerberparams ); GERBER_DRAW_ITEM( GERBER_FILE_IMAGE* aGerberparams );
GERBER_DRAW_ITEM( const GERBER_DRAW_ITEM& aSource ); GERBER_DRAW_ITEM( const GERBER_DRAW_ITEM& aSource );
~GERBER_DRAW_ITEM(); ~GERBER_DRAW_ITEM();
@ -123,16 +121,7 @@ public:
* Function GetLayer * Function GetLayer
* returns the layer this item is on. * returns the layer this item is on.
*/ */
int GetLayer() const { return m_Layer; } int GetLayer() const;
/**
* Function SetLayer
* sets the layer this item is on.
* @param aLayer The layer number.
* is virtual because some items (in fact: class DIMENSION)
* have a slightly different initialization
*/
void SetLayer( int aLayer ) { m_Layer = aLayer; }
bool GetLayerPolarity() bool GetLayerPolarity()
{ {
@ -216,10 +205,8 @@ public:
const EDA_RECT GetBoundingBox() const; // Virtual const EDA_RECT GetBoundingBox() const; // Virtual
/* Display on screen: */ /* Display on screen: */
void Draw( EDA_DRAW_PANEL* aPanel, void Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC,
wxDC* aDC, GR_DRAWMODE aDrawMode, const wxPoint&aOffset );
GR_DRAWMODE aDrawMode,
const wxPoint&aOffset );
/** /**
* Function ConvertSegmentToPolygon * Function ConvertSegmentToPolygon
@ -233,8 +220,7 @@ public:
* Function DrawGbrPoly * Function DrawGbrPoly
* a helper function used to draw the polygon stored in m_PolyCorners * a helper function used to draw the polygon stored in m_PolyCorners
*/ */
void DrawGbrPoly( EDA_RECT* aClipBox, void DrawGbrPoly( EDA_RECT* aClipBox, wxDC* aDC, EDA_COLOR_T aColor,
wxDC* aDC, EDA_COLOR_T aColor,
const wxPoint& aOffset, bool aFilledShape ); const wxPoint& aOffset, bool aFilledShape );
/* divers */ /* divers */

View File

@ -89,7 +89,7 @@ void GERBER_LAYER::ResetDefaultValues()
GERBER_FILE_IMAGE::GERBER_FILE_IMAGE( GERBVIEW_FRAME* aParent, int aLayer ) GERBER_FILE_IMAGE::GERBER_FILE_IMAGE( GERBVIEW_FRAME* aParent, int aLayer )
{ {
//m_parent = aParent; m_parent = aParent;
m_GraphicLayer = aLayer; // Graphic layer Number m_GraphicLayer = aLayer; // Graphic layer Number
m_Selected_Tool = FIRST_DCODE; m_Selected_Tool = FIRST_DCODE;
@ -118,7 +118,7 @@ GERBER_FILE_IMAGE::~GERBER_FILE_IMAGE()
*/ */
GERBER_DRAW_ITEM * GERBER_FILE_IMAGE::GetItemsList() GERBER_DRAW_ITEM * GERBER_FILE_IMAGE::GetItemsList()
{ {
return m_parent->GetItemsList(); return m_Drawings;
} }
D_CODE* GERBER_FILE_IMAGE::GetDCODE( int aDCODE, bool aCreateIfNoExist ) D_CODE* GERBER_FILE_IMAGE::GetDCODE( int aDCODE, bool aCreateIfNoExist )
@ -323,7 +323,7 @@ void GERBER_FILE_IMAGE::StepAndRepeatItem( const GERBER_DRAW_ITEM& aItem )
move_vector.y = scaletoIU( jj * GetLayerParams().m_StepForRepeat.y, move_vector.y = scaletoIU( jj * GetLayerParams().m_StepForRepeat.y,
GetLayerParams().m_StepForRepeatMetric ); GetLayerParams().m_StepForRepeatMetric );
dupItem->MoveXY( move_vector ); dupItem->MoveXY( move_vector );
m_parent->GetGerberLayout()->m_Drawings.Append( dupItem ); m_Drawings.Append( dupItem );
} }
} }
} }

View File

@ -101,6 +101,8 @@ class GERBER_FILE_IMAGE
GERBER_LAYER m_GBRLayerParams; // hold params for the current gerber layer GERBER_LAYER m_GBRLayerParams; // hold params for the current gerber layer
public: public:
DLIST<GERBER_DRAW_ITEM> m_Drawings; // linked list of Gerber Items to draw
bool m_InUse; // true if this image is currently in use bool m_InUse; // true if this image is currently in use
// (a file is loaded in it) // (a file is loaded in it)
wxString m_FileName; // Full File Name for this layer wxString m_FileName; // Full File Name for this layer

View File

@ -204,7 +204,7 @@ static bool sortZorder( const GERBER_FILE_IMAGE* const& ref, const GERBER_FILE_I
return ref->m_FileFunction->GetZSubOrder() > test->m_FileFunction->GetZSubOrder(); return ref->m_FileFunction->GetZSubOrder() > test->m_FileFunction->GetZSubOrder();
} }
void GERBER_FILE_IMAGE_LIST::SortImagesByZOrder( GERBER_DRAW_ITEM* aDrawList ) void GERBER_FILE_IMAGE_LIST::SortImagesByZOrder()
{ {
std::sort( m_GERBER_List.begin(), m_GERBER_List.end(), sortZorder ); std::sort( m_GERBER_List.begin(), m_GERBER_List.end(), sortZorder );
@ -216,18 +216,13 @@ void GERBER_FILE_IMAGE_LIST::SortImagesByZOrder( GERBER_DRAW_ITEM* aDrawList )
for( unsigned layer = 0; layer < m_GERBER_List.size(); ++layer ) for( unsigned layer = 0; layer < m_GERBER_List.size(); ++layer )
{ {
if( m_GERBER_List[layer] ) GERBER_FILE_IMAGE* gerber = m_GERBER_List[layer];
{
tab_lyr[m_GERBER_List[layer]->m_GraphicLayer] = layer;
m_GERBER_List[layer]->m_GraphicLayer = layer ;
}
}
// update the graphic layer in items to draw if( !gerber )
for( GERBER_DRAW_ITEM* item = aDrawList; item; item = item->Next() ) continue;
{
int layer = item->GetLayer(); tab_lyr[gerber->m_GraphicLayer] = layer;
item->SetLayer( tab_lyr[layer] ); gerber->m_GraphicLayer = layer ;
} }
} }

View File

@ -114,10 +114,9 @@ public:
/** /**
* Sort loaded images by Z order priority, if they have the X2 FileFormat info * Sort loaded images by Z order priority, if they have the X2 FileFormat info
* @param aDrawList: the draw list associated to the gerber images
* (SortImagesByZOrder updates the graphic layer of these items) * (SortImagesByZOrder updates the graphic layer of these items)
*/ */
void SortImagesByZOrder( GERBER_DRAW_ITEM* aDrawList ); void SortImagesByZOrder();
}; };

View File

@ -208,7 +208,7 @@ void GERBER_LAYER_WIDGET::onPopupSelection( wxCommandEvent& event )
break; break;
case ID_SORT_GBR_LAYERS: case ID_SORT_GBR_LAYERS:
g_GERBER_List.SortImagesByZOrder( myframe->GetItemsList() ); g_GERBER_List.SortImagesByZOrder();
myframe->ReFillLayerWidget(); myframe->ReFillLayerWidget();
myframe->syncLayerBox( true ); myframe->syncLayerBox( true );
myframe->GetCanvas()->Refresh(); myframe->GetCanvas()->Refresh();

View File

@ -38,6 +38,7 @@
#include <gerbview.h> #include <gerbview.h>
#include <gerbview_frame.h> #include <gerbview_frame.h>
#include <class_gerber_file_image.h> #include <class_gerber_file_image.h>
#include <class_gerber_file_image_list.h>
#include <printout_controler.h> #include <printout_controler.h>
@ -157,11 +158,19 @@ void GERBVIEW_FRAME::DrawItemsDCodeID( wxDC* aDC, GR_DRAWMODE aDrawMode )
GRSetDrawMode( aDC, aDrawMode ); GRSetDrawMode( aDC, aDrawMode );
for( GERBER_DRAW_ITEM* item = GetItemsList(); item != NULL; item = item->Next() ) for( int layer = 0; layer < GERBER_DRAWLAYERS_COUNT; ++layer )
{ {
if( IsLayerVisible( item->GetLayer() ) == false ) GERBER_FILE_IMAGE* gerber = g_GERBER_List.GetGbrImage( layer );
if( gerber == NULL ) // Graphic layer not yet used
continue; continue;
if( IsLayerVisible( layer ) == false )
continue;
for( GERBER_DRAW_ITEM* item = gerber->GetItemsList(); item != NULL; item = item->Next() )
{
if( item->m_DCode <= 0 ) if( item->m_DCode <= 0 )
continue; continue;
@ -211,3 +220,4 @@ void GERBVIEW_FRAME::DrawItemsDCodeID( wxDC* aDC, GR_DRAWMODE aDrawMode )
0, false, false ); 0, false, false );
} }
} }
}

View File

@ -88,16 +88,16 @@ static const int fmtIntegerInch = 2;
extern int ReadInt( char*& text, bool aSkipSeparator = true ); extern int ReadInt( char*& text, bool aSkipSeparator = true );
extern double ReadDouble( char*& text, bool aSkipSeparator = true ); extern double ReadDouble( char*& text, bool aSkipSeparator = true );
// See ds274d.cpp:
extern void fillFlashedGBRITEM( GERBER_DRAW_ITEM* aGbrItem, extern void fillFlashedGBRITEM( GERBER_DRAW_ITEM* aGbrItem,
APERTURE_T aAperture, APERTURE_T aAperture,
int Dcode_index, int Dcode_index,
int aLayer,
const wxPoint& aPos, const wxPoint& aPos,
wxSize aSize, wxSize aSize,
bool aLayerNegative ); bool aLayerNegative );
void fillLineGBRITEM( GERBER_DRAW_ITEM* aGbrItem, void fillLineGBRITEM( GERBER_DRAW_ITEM* aGbrItem,
int Dcode_index, int Dcode_index,
int aLayer,
const wxPoint& aStart, const wxPoint& aStart,
const wxPoint& aEnd, const wxPoint& aEnd,
wxSize aPenSize, wxSize aPenSize,
@ -548,22 +548,19 @@ bool EXCELLON_IMAGE::Execute_Drill_Command( char*& text )
return false; return false;
} }
gbritem = new GERBER_DRAW_ITEM( GetParent()->GetGerberLayout(), this ); gbritem = new GERBER_DRAW_ITEM( this );
GetParent()->GetGerberLayout()->m_Drawings.Append( gbritem ); m_Drawings.Append( gbritem );
if( m_SlotOn ) // Oval hole if( m_SlotOn ) // Oval hole
{ {
fillLineGBRITEM( gbritem, fillLineGBRITEM( gbritem, tool->m_Num_Dcode,
tool->m_Num_Dcode, GetParent()->getActiveLayer(),
m_PreviousPos, m_CurrentPos, m_PreviousPos, m_CurrentPos,
tool->m_Size, false ); tool->m_Size, false );
} }
else else
{ {
fillFlashedGBRITEM( gbritem, tool->m_Shape, fillFlashedGBRITEM( gbritem, tool->m_Shape, tool->m_Num_Dcode,
tool->m_Num_Dcode, GetParent()->getActiveLayer(), m_CurrentPos, tool->m_Size, false );
m_CurrentPos,
tool->m_Size, false );
} }
StepAndRepeatItem( *gbritem ); StepAndRepeatItem( *gbritem );

View File

@ -220,33 +220,45 @@ bool GBR_TO_PCB_EXPORTER::ExportPcb( LAYER_NUM* aLayerLookUpTable, int aCopperLa
// create an image of gerber data // create an image of gerber data
// First: non copper layers: // First: non copper layers:
GERBER_DRAW_ITEM* gerb_item = m_gerbview_frame->GetItemsList(); const int pcbCopperLayerMax = 31;
int pcbCopperLayerMax = 31;
for( ; gerb_item; gerb_item = gerb_item->Next() ) for( int layer = 0; layer < GERBER_DRAWLAYERS_COUNT; ++layer )
{ {
int layer = gerb_item->GetLayer(); GERBER_FILE_IMAGE* gerber = g_GERBER_List.GetGbrImage( layer );
if( gerber == NULL ) // Graphic layer not yet used
continue;
LAYER_NUM pcb_layer_number = aLayerLookUpTable[layer]; LAYER_NUM pcb_layer_number = aLayerLookUpTable[layer];
if( !IsPcbLayer( pcb_layer_number ) ) if( !IsPcbLayer( pcb_layer_number ) )
continue; continue;
if( pcb_layer_number > pcbCopperLayerMax ) if( pcb_layer_number <= pcbCopperLayerMax ) // copper layer
continue;
GERBER_DRAW_ITEM* gerb_item = gerber->GetItemsList();
for( ; gerb_item; gerb_item = gerb_item->Next() )
export_non_copper_item( gerb_item, pcb_layer_number ); export_non_copper_item( gerb_item, pcb_layer_number );
} }
// Copper layers // Copper layers
gerb_item = m_gerbview_frame->GetItemsList(); for( int layer = 0; layer < GERBER_DRAWLAYERS_COUNT; ++layer )
for( ; gerb_item; gerb_item = gerb_item->Next() )
{ {
int layer = gerb_item->GetLayer(); GERBER_FILE_IMAGE* gerber = g_GERBER_List.GetGbrImage( layer );
if( gerber == NULL ) // Graphic layer not yet used
continue;
LAYER_NUM pcb_layer_number = aLayerLookUpTable[layer]; LAYER_NUM pcb_layer_number = aLayerLookUpTable[layer];
if( pcb_layer_number < 0 || pcb_layer_number > pcbCopperLayerMax ) if( pcb_layer_number < 0 || pcb_layer_number > pcbCopperLayerMax )
continue; continue;
else GERBER_DRAW_ITEM* gerb_item = gerber->GetItemsList();
for( ; gerb_item; gerb_item = gerb_item->Next() )
export_copper_item( gerb_item, pcb_layer_number ); export_copper_item( gerb_item, pcb_layer_number );
} }

View File

@ -228,14 +228,13 @@ bool GERBVIEW_FRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, in
double GERBVIEW_FRAME::BestZoom() 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(); EDA_RECT bbox = GetGerberLayout()->ComputeBoundingBox();
// gives a minimal value to zoom, if no item in list
if( bbox.GetWidth() == 0 || bbox.GetHeight() == 0 )
return ZOOM_FACTOR( 200.0 );
wxSize size = m_canvas->GetClientSize(); wxSize size = m_canvas->GetClientSize();
double x = (double) bbox.GetWidth() / (double) size.x; double x = (double) bbox.GetWidth() / (double) size.x;

View File

@ -110,16 +110,6 @@ public:
return m_gerberLayout; return m_gerberLayout;
} }
/**
* Function GetItemsList
* @return the first GERBER_DRAW_ITEM * item of the items list
*/
GERBER_DRAW_ITEM* GetItemsList()
{
GERBER_DRAW_ITEM* item = GetGerberLayout()->m_Drawings;
return item;
}
/** /**
* Function GetGerberLayoutBoundingBox * Function GetGerberLayoutBoundingBox

View File

@ -31,6 +31,7 @@
#include <confirm.h> #include <confirm.h>
#include <gerbview_frame.h> #include <gerbview_frame.h>
#include <class_gerber_file_image.h>
#include <class_gerber_file_image_list.h> #include <class_gerber_file_image_list.h>
#include <class_gerbview_layer_widget.h> #include <class_gerbview_layer_widget.h>
@ -45,7 +46,15 @@ bool GERBVIEW_FRAME::Clear_DrawLayers( bool query )
return false; return false;
} }
GetGerberLayout()->m_Drawings.DeleteAll(); for( int layer = 0; layer < GERBER_DRAWLAYERS_COUNT; ++layer )
{
GERBER_FILE_IMAGE* gerber = g_GERBER_List.GetGbrImage( layer );
if( gerber == NULL ) // Graphic layer not yet used
continue;
gerber->m_Drawings.DeleteAll();
}
g_GERBER_List.ClearList(); g_GERBER_List.ClearList();
@ -72,18 +81,10 @@ void GERBVIEW_FRAME::Erase_Current_DrawLayer( bool query )
SetCurItem( NULL ); SetCurItem( NULL );
GERBER_DRAW_ITEM* item = GetGerberLayout()->m_Drawings; GERBER_FILE_IMAGE* gerber = g_GERBER_List.GetGbrImage( layer );
GERBER_DRAW_ITEM * next;
for( ; item; item = next ) if( gerber ) // gerber == NULL should not occur
{ gerber->m_Drawings.DeleteAll();
next = item->Next();
if( item->GetLayer() != layer )
continue;
item->DeleteStructure();
}
g_GERBER_List.ClearImage( layer ); g_GERBER_List.ClearImage( layer );

View File

@ -32,9 +32,11 @@
#include <gerbview.h> #include <gerbview.h>
#include <gerbview_frame.h> #include <gerbview_frame.h>
#include <class_gerber_file_image.h>
#include <class_gerber_file_image_list.h>
/* localize a gerber item and return a pointer to it. /* locate a gerber item and return a pointer to it.
* Display info about this item * Display info about this item
*/ */
GERBER_DRAW_ITEM* GERBVIEW_FRAME::Locate( const wxPoint& aPosition, int aTypeloc ) GERBER_DRAW_ITEM* GERBVIEW_FRAME::Locate( const wxPoint& aPosition, int aTypeloc )
@ -47,25 +49,33 @@ GERBER_DRAW_ITEM* GERBVIEW_FRAME::Locate( const wxPoint& aPosition, int aTypeloc
ref = GetNearestGridPosition( ref ); ref = GetNearestGridPosition( ref );
int layer = getActiveLayer(); int layer = getActiveLayer();
GERBER_FILE_IMAGE* gerber = g_GERBER_List.GetGbrImage( layer );
// Search first on active layer // Search first on active layer
GERBER_DRAW_ITEM* gerb_item = GetItemsList(); GERBER_DRAW_ITEM* gerb_item;
for( ; gerb_item; gerb_item = gerb_item->Next() ) if( gerber ) // A not used graphic layer can be selected. So gerber can be NULL
{
for( gerb_item = gerber->GetItemsList(); gerb_item; gerb_item = gerb_item->Next() )
{ {
if( gerb_item->GetLayer()!= layer )
continue;
if( gerb_item->HitTest( ref ) ) if( gerb_item->HitTest( ref ) )
{ {
found = true; found = true;
break; break;
} }
} }
}
if( !found ) // Search on all layers if( !found ) // Search on all layers
{ {
for( gerb_item = GetItemsList(); gerb_item; gerb_item = gerb_item->Next() ) for( layer = 0; layer < GERBER_DRAWLAYERS_COUNT; ++layer )
{
gerber = g_GERBER_List.GetGbrImage( layer );
if( gerber == NULL ) // Graphic layer not yet used
continue;
for( gerb_item = gerber->GetItemsList(); gerb_item; gerb_item = gerb_item->Next() )
{ {
if( gerb_item->HitTest( ref ) ) if( gerb_item->HitTest( ref ) )
{ {
@ -74,6 +84,7 @@ GERBER_DRAW_ITEM* GERBVIEW_FRAME::Locate( const wxPoint& aPosition, int aTypeloc
} }
} }
} }
}
if( found ) if( found )
{ {

View File

@ -108,12 +108,10 @@
void fillFlashedGBRITEM( GERBER_DRAW_ITEM* aGbrItem, void fillFlashedGBRITEM( GERBER_DRAW_ITEM* aGbrItem,
APERTURE_T aAperture, APERTURE_T aAperture,
int Dcode_index, int Dcode_index,
int aLayer,
const wxPoint& aPos, const wxPoint& aPos,
wxSize aSize, wxSize aSize,
bool aLayerNegative ) bool aLayerNegative )
{ {
aGbrItem->SetLayer( aLayer );
aGbrItem->m_Size = aSize; aGbrItem->m_Size = aSize;
aGbrItem->m_Start = aPos; aGbrItem->m_Start = aPos;
aGbrItem->m_End = aGbrItem->m_Start; aGbrItem->m_End = aGbrItem->m_Start;
@ -160,13 +158,11 @@ void fillFlashedGBRITEM( GERBER_DRAW_ITEM* aGbrItem,
*/ */
void fillLineGBRITEM( GERBER_DRAW_ITEM* aGbrItem, void fillLineGBRITEM( GERBER_DRAW_ITEM* aGbrItem,
int Dcode_index, int Dcode_index,
int aLayer,
const wxPoint& aStart, const wxPoint& aStart,
const wxPoint& aEnd, const wxPoint& aEnd,
wxSize aPenSize, wxSize aPenSize,
bool aLayerNegative ) bool aLayerNegative )
{ {
aGbrItem->SetLayer( aLayer );
aGbrItem->m_Flashed = false; aGbrItem->m_Flashed = false;
aGbrItem->m_Size = aPenSize; aGbrItem->m_Size = aPenSize;
@ -209,7 +205,7 @@ void fillLineGBRITEM( GERBER_DRAW_ITEM* aGbrItem,
* false when arc is inside one quadrant * false when arc is inside one quadrant
* @param aLayerNegative = true if the current layer is negative * @param aLayerNegative = true if the current layer is negative
*/ */
static void fillArcGBRITEM( GERBER_DRAW_ITEM* aGbrItem, int Dcode_index, int aLayer, static void fillArcGBRITEM( GERBER_DRAW_ITEM* aGbrItem, int Dcode_index,
const wxPoint& aStart, const wxPoint& aEnd, const wxPoint& aStart, const wxPoint& aEnd,
const wxPoint& aRelCenter, wxSize aPenSize, const wxPoint& aRelCenter, wxSize aPenSize,
bool aClockwise, bool aMultiquadrant, bool aClockwise, bool aMultiquadrant,
@ -218,7 +214,6 @@ static void fillArcGBRITEM( GERBER_DRAW_ITEM* aGbrItem, int Dcode_index, int aL
wxPoint center, delta; wxPoint center, delta;
aGbrItem->m_Shape = GBR_ARC; aGbrItem->m_Shape = GBR_ARC;
aGbrItem->SetLayer( aLayer );
aGbrItem->m_Size = aPenSize; aGbrItem->m_Size = aPenSize;
aGbrItem->m_Flashed = false; aGbrItem->m_Flashed = false;
@ -343,12 +338,11 @@ static void fillArcPOLY( GERBER_DRAW_ITEM* aGbrItem,
/* in order to calculate arc parameters, we use fillArcGBRITEM /* in order to calculate arc parameters, we use fillArcGBRITEM
* so we muse create a dummy track and use its geometric parameters * so we muse create a dummy track and use its geometric parameters
*/ */
static GERBER_DRAW_ITEM dummyGbrItem( NULL, NULL ); static GERBER_DRAW_ITEM dummyGbrItem( NULL );
static const int drawlayer = 0;
aGbrItem->SetLayerPolarity( aLayerNegative ); aGbrItem->SetLayerPolarity( aLayerNegative );
fillArcGBRITEM( &dummyGbrItem, 0, drawlayer, fillArcGBRITEM( &dummyGbrItem, 0,
aStart, aEnd, rel_center, wxSize(0, 0), aStart, aEnd, rel_center, wxSize(0, 0),
aClockwise, aMultiquadrant, aLayerNegative ); aClockwise, aMultiquadrant, aLayerNegative );
@ -550,9 +544,9 @@ bool GERBER_FILE_IMAGE::Execute_G_Command( char*& text, int G_command )
break; break;
case GC_TURN_OFF_POLY_FILL: case GC_TURN_OFF_POLY_FILL:
if( m_Exposure && m_parent->GetGerberLayout()->m_Drawings ) // End of polygon if( m_Exposure && GetItemsList() ) // End of polygon
{ {
GERBER_DRAW_ITEM * gbritem = m_parent->GetGerberLayout()->m_Drawings.GetLast(); GERBER_DRAW_ITEM * gbritem = m_Drawings.GetLast();
StepAndRepeatItem( *gbritem ); StepAndRepeatItem( *gbritem );
} }
m_Exposure = false; m_Exposure = false;
@ -581,16 +575,11 @@ bool GERBER_FILE_IMAGE::Execute_DCODE_Command( char*& text, int D_commande )
APERTURE_T aperture = APT_CIRCLE; APERTURE_T aperture = APT_CIRCLE;
GERBER_DRAW_ITEM* gbritem; GERBER_DRAW_ITEM* gbritem;
GBR_LAYOUT* layout = m_parent->GetGerberLayout();
int activeLayer = m_parent->getActiveLayer();
int dcode = 0; int dcode = 0;
D_CODE* tool = NULL; D_CODE* tool = NULL;
wxString msg; wxString msg;
// D( printf( "%22s: D_CODE<%d>\n", __func__, D_commande ); )
if( D_commande >= FIRST_DCODE ) // This is a "Set tool" command if( D_commande >= FIRST_DCODE ) // This is a "Set tool" command
{ {
if( D_commande > (TOOLS_MAX_COUNT - 1) ) if( D_commande > (TOOLS_MAX_COUNT - 1) )
@ -619,10 +608,9 @@ bool GERBER_FILE_IMAGE::Execute_DCODE_Command( char*& text, int D_commande )
if( !m_Exposure ) // Start a new polygon outline: if( !m_Exposure ) // Start a new polygon outline:
{ {
m_Exposure = true; m_Exposure = true;
gbritem = new GERBER_DRAW_ITEM( layout, this ); gbritem = new GERBER_DRAW_ITEM( this );
layout->m_Drawings.Append( gbritem ); m_Drawings.Append( gbritem );
gbritem->m_Shape = GBR_POLYGON; gbritem->m_Shape = GBR_POLYGON;
gbritem->SetLayer( activeLayer );
gbritem->m_Flashed = false; gbritem->m_Flashed = false;
} }
@ -630,7 +618,7 @@ bool GERBER_FILE_IMAGE::Execute_DCODE_Command( char*& text, int D_commande )
{ {
case GERB_INTERPOL_ARC_NEG: case GERB_INTERPOL_ARC_NEG:
case GERB_INTERPOL_ARC_POS: case GERB_INTERPOL_ARC_POS:
gbritem = layout->m_Drawings.GetLast(); gbritem = m_Drawings.GetLast();
// D( printf( "Add arc poly %d,%d to %d,%d fill %d interpol %d 360_enb %d\n", // D( printf( "Add arc poly %d,%d to %d,%d fill %d interpol %d 360_enb %d\n",
// m_PreviousPos.x, m_PreviousPos.y, m_CurrentPos.x, // m_PreviousPos.x, m_PreviousPos.y, m_CurrentPos.x,
@ -643,7 +631,7 @@ bool GERBER_FILE_IMAGE::Execute_DCODE_Command( char*& text, int D_commande )
break; break;
default: default:
gbritem = layout->m_Drawings.GetLast(); gbritem = m_Drawings.GetLast();
// D( printf( "Add poly edge %d,%d to %d,%d fill %d\n", // D( printf( "Add poly edge %d,%d to %d,%d fill %d\n",
// m_PreviousPos.x, m_PreviousPos.y, // m_PreviousPos.x, m_PreviousPos.y,
@ -663,9 +651,9 @@ bool GERBER_FILE_IMAGE::Execute_DCODE_Command( char*& text, int D_commande )
break; break;
case 2: // code D2: exposure OFF (i.e. "move to") case 2: // code D2: exposure OFF (i.e. "move to")
if( m_Exposure && layout->m_Drawings ) // End of polygon if( m_Exposure && GetItemsList() ) // End of polygon
{ {
gbritem = layout->m_Drawings.GetLast(); gbritem = m_Drawings.GetLast();
StepAndRepeatItem( *gbritem ); StepAndRepeatItem( *gbritem );
} }
m_Exposure = false; m_Exposure = false;
@ -695,13 +683,13 @@ bool GERBER_FILE_IMAGE::Execute_DCODE_Command( char*& text, int D_commande )
switch( m_Iterpolation ) switch( m_Iterpolation )
{ {
case GERB_INTERPOL_LINEAR_1X: case GERB_INTERPOL_LINEAR_1X:
gbritem = new GERBER_DRAW_ITEM( layout, this ); gbritem = new GERBER_DRAW_ITEM( this );
layout->m_Drawings.Append( gbritem ); m_Drawings.Append( gbritem );
// D( printf( "Add line %d,%d to %d,%d\n", // D( printf( "Add line %d,%d to %d,%d\n",
// m_PreviousPos.x, m_PreviousPos.y, // m_PreviousPos.x, m_PreviousPos.y,
// m_CurrentPos.x, m_CurrentPos.y ); ) // m_CurrentPos.x, m_CurrentPos.y ); )
fillLineGBRITEM( gbritem, dcode, activeLayer, m_PreviousPos, fillLineGBRITEM( gbritem, dcode, m_PreviousPos,
m_CurrentPos, size, GetLayerParams().m_LayerNegative ); m_CurrentPos, size, GetLayerParams().m_LayerNegative );
StepAndRepeatItem( *gbritem ); StepAndRepeatItem( *gbritem );
break; break;
@ -714,14 +702,10 @@ bool GERBER_FILE_IMAGE::Execute_DCODE_Command( char*& text, int D_commande )
case GERB_INTERPOL_ARC_NEG: case GERB_INTERPOL_ARC_NEG:
case GERB_INTERPOL_ARC_POS: case GERB_INTERPOL_ARC_POS:
gbritem = new GERBER_DRAW_ITEM( layout, this ); gbritem = new GERBER_DRAW_ITEM( this );
layout->m_Drawings.Append( gbritem ); m_Drawings.Append( gbritem );
// D( printf( "Add arc %d,%d to %d,%d center %d, %d interpol %d 360_enb %d\n", fillArcGBRITEM( gbritem, dcode, m_PreviousPos,
// m_PreviousPos.x, m_PreviousPos.y, m_CurrentPos.x,
// m_CurrentPos.y, m_IJPos.x,
// m_IJPos.y, m_Iterpolation, m_360Arc_enbl ); )
fillArcGBRITEM( gbritem, dcode, activeLayer, m_PreviousPos,
m_CurrentPos, m_IJPos, size, m_CurrentPos, m_IJPos, size,
( m_Iterpolation == GERB_INTERPOL_ARC_NEG ) ? ( m_Iterpolation == GERB_INTERPOL_ARC_NEG ) ?
false : true, m_360Arc_enbl, GetLayerParams().m_LayerNegative ); false : true, m_360Arc_enbl, GetLayerParams().m_LayerNegative );
@ -752,10 +736,9 @@ bool GERBER_FILE_IMAGE::Execute_DCODE_Command( char*& text, int D_commande )
aperture = tool->m_Shape; aperture = tool->m_Shape;
} }
gbritem = new GERBER_DRAW_ITEM( layout, this ); gbritem = new GERBER_DRAW_ITEM( this );
layout->m_Drawings.Append( gbritem ); m_Drawings.Append( gbritem );
fillFlashedGBRITEM( gbritem, aperture, fillFlashedGBRITEM( gbritem, aperture, dcode, m_CurrentPos,
dcode, activeLayer, m_CurrentPos,
size, GetLayerParams().m_LayerNegative ); size, GetLayerParams().m_LayerNegative );
StepAndRepeatItem( *gbritem ); StepAndRepeatItem( *gbritem );
m_PreviousPos = m_CurrentPos; m_PreviousPos = m_CurrentPos;

View File

@ -584,8 +584,9 @@ bool GERBER_FILE_IMAGE::ExecuteRS274XCommand( int command, char* buff, char*& te
else else
GetLayerParams().m_LayerNegative = false; GetLayerParams().m_LayerNegative = false;
DBG( printf( "%22s: LAYER_POLARITY m_LayerNegative=%s\n", __func__,
GetLayerParams().m_LayerNegative ? "true" : "false" ); ) // DBG( printf( "%22s: LAYER_POLARITY m_LayerNegative=%s\n", __func__,
// GetLayerParams().m_LayerNegative ? "true" : "false" ); )
break; break;
case INCLUDE_FILE: case INCLUDE_FILE: