Commit 8111fe49 authored by charras's avatar charras

Dirty rect Ok. Code must be cleaned. Import footprints from gpcb ok. See changelog for details

parent 92390f6c
...@@ -5,6 +5,17 @@ Started 2007-June-11 ...@@ -5,6 +5,17 @@ Started 2007-June-11
Please add newer entries at the top, list the date and your name with Please add newer entries at the top, list the date and your name with
email address. email address.
2008-Mar-10 UPDATE Jean-Pierre Charras <jean-pierre.charras@inpg.fr>
================================================================================
+pcbnew
Pcbnew can import footprints in gpcb format in Nelib format only
Pcbnew automatically recognizes pcbnew or gpcb format when importing a footprint.
Due to differences between pcbnew and gpcb,
only gpcb newlib files containing only one footprint (one element) are useables.
Dirty rectangle calculation debugged.
WinEDA_DrawPanel::ConvertPcbUnitsToPixelsUnits( EDA_Rect& aRect ) can be used to convert a bouding box to a clip box
(see example in deltrack.cpp)
2008-Mar-06 UPDATE Igor Plyatov <plyatov@mail.ru> 2008-Mar-06 UPDATE Igor Plyatov <plyatov@mail.ru>
================================================================================ ================================================================================
+help +help
......
...@@ -373,21 +373,3 @@ char* strupper( char* Text ) ...@@ -373,21 +373,3 @@ char* strupper( char* Text )
return Text; return Text;
} }
#if 0
/********************************/
char* strlower( char* text )
/********************************/
{
char* start = text;
while( *text )
{
if( *text >= 'A' && *text <= 'Z' )
*text -= 'A' - 'a';
text++;
}
return start;
}
#endif
...@@ -95,7 +95,23 @@ public: ...@@ -95,7 +95,23 @@ public:
void Process_Special_Functions( wxCommandEvent& event ); void Process_Special_Functions( wxCommandEvent& event );
wxPoint CursorRealPosition( const wxPoint& ScreenPos ); wxPoint CursorRealPosition( const wxPoint& ScreenPos );
wxPoint CursorScreenPosition(); wxPoint CursorScreenPosition();
wxPoint GetScreenCenterRealPosition();
/** Function ConvertPcbUnitsToPixelsUnits
* Convert pos and size of the given EDA_Rect to pos and size in pixels,
* relative to the current draw area (origin 0,0 is the left top visible corner draw area)
* according to the current scrool and zoom
* @param aRect = the given rect
*/
void ConvertPcbUnitsToPixelsUnits( EDA_Rect & aRect);
/** Function ConvertPcbUnitsToPixelsUnits
* Convert a given wxPoint position (in internal units) to the pos in pixels,
* relative to the current draw area (origin 0,0 is the left top visible corner draw area)
* according to the current scrool and zoom
* @param aPosition = the given position
*/
void ConvertPcbUnitsToPixelsUnits( wxPoint & aPosition);
wxPoint GetScreenCenterRealPosition( void );
void MouseToCursorSchema(); void MouseToCursorSchema();
void MouseTo( const wxPoint& Mouse ); void MouseTo( const wxPoint& Mouse );
......
...@@ -78,6 +78,7 @@ SET(PCBNEW_SRCS ...@@ -78,6 +78,7 @@ SET(PCBNEW_SRCS
gen_modules_placefile.cpp gen_modules_placefile.cpp
gendrill.cpp gendrill.cpp
globaleditpad.cpp globaleditpad.cpp
gpcb_exchange.cpp
graphpcb.cpp graphpcb.cpp
hotkeys.cpp hotkeys.cpp
initpcb.cpp initpcb.cpp
......
...@@ -765,15 +765,15 @@ int MODULE::ReadDescr( FILE* File, int* LineNum ) ...@@ -765,15 +765,15 @@ int MODULE::ReadDescr( FILE* File, int* LineNum )
} }
} }
/* Recalcul de l'encadrement */ /* Recalculate the bounding box */
Set_Rectangle_Encadrement(); Set_Rectangle_Encadrement();
return 0; return 0;
} }
/****************************************************/ /*************************************************/
void MODULE::SetPosition( const wxPoint& newpos ) void MODULE::SetPosition( const wxPoint& newpos )
/****************************************************/ /*************************************************/
// replace le module en position newpos // replace le module en position newpos
{ {
......
...@@ -142,6 +142,14 @@ public: ...@@ -142,6 +142,14 @@ public:
int Write_3D_Descr( FILE* File ) const; int Write_3D_Descr( FILE* File ) const;
int ReadDescr( FILE* File, int* LineNum = NULL ); int ReadDescr( FILE* File, int* LineNum = NULL );
/**
* Function Read_GPCB_Descr
* Read a footprint description in GPCB format
* @param CmpFullFileName = Full file name (there is one footprint per file.
* this is also the footprint name
* @return bool - true if success reading else false.
*/
bool Read_GPCB_Descr(const wxString & CmpFullFileName);
int Read_3D_Descr( FILE* File, int* LineNum = NULL ); int Read_3D_Descr( FILE* File, int* LineNum = NULL );
/* drawing functions */ /* drawing functions */
......
...@@ -32,9 +32,9 @@ TRACK* WinEDA_PcbFrame::Delete_Segment( wxDC* DC, TRACK* Track ) ...@@ -32,9 +32,9 @@ TRACK* WinEDA_PcbFrame::Delete_Segment( wxDC* DC, TRACK* Track )
if( Track == NULL ) if( Track == NULL )
return NULL; return NULL;
if( Track->GetState(DELETED) ) if( Track->GetState( DELETED ) )
{ {
D(printf("WinEDA_PcbFrame::Delete_Segment(): bug deleted already deleted TRACK\n");) D( printf( "WinEDA_PcbFrame::Delete_Segment(): bug deleted already deleted TRACK\n" ); )
return NULL; return NULL;
} }
...@@ -42,7 +42,7 @@ TRACK* WinEDA_PcbFrame::Delete_Segment( wxDC* DC, TRACK* Track ) ...@@ -42,7 +42,7 @@ TRACK* WinEDA_PcbFrame::Delete_Segment( wxDC* DC, TRACK* Track )
{ {
if( g_TrackSegmentCount > 0 ) if( g_TrackSegmentCount > 0 )
{ {
int previous_layer = ((PCB_SCREEN*)GetScreen())->m_Active_Layer; int previous_layer = ( (PCB_SCREEN*) GetScreen() )->m_Active_Layer;
// effacement de la piste en cours // effacement de la piste en cours
ShowNewTrackWhenMovingCursor( DrawPanel, DC, FALSE ); ShowNewTrackWhenMovingCursor( DrawPanel, DC, FALSE );
...@@ -83,7 +83,7 @@ TRACK* WinEDA_PcbFrame::Delete_Segment( wxDC* DC, TRACK* Track ) ...@@ -83,7 +83,7 @@ TRACK* WinEDA_PcbFrame::Delete_Segment( wxDC* DC, TRACK* Track )
// Rectification couche active qui a pu changer si une via // Rectification couche active qui a pu changer si une via
// a ete effacee // a ete effacee
((PCB_SCREEN*)GetScreen())->m_Active_Layer = previous_layer; ( (PCB_SCREEN*) GetScreen() )->m_Active_Layer = previous_layer;
Affiche_Status_Box(); Affiche_Status_Box();
if( g_TwoSegmentTrackBuild ) // We must have 2 segments or more, or 0 if( g_TwoSegmentTrackBuild ) // We must have 2 segments or more, or 0
...@@ -126,41 +126,19 @@ TRACK* WinEDA_PcbFrame::Delete_Segment( wxDC* DC, TRACK* Track ) ...@@ -126,41 +126,19 @@ TRACK* WinEDA_PcbFrame::Delete_Segment( wxDC* DC, TRACK* Track )
#else #else
// redraw the area where the track was // redraw the area where the track was
// this rectangle is correct
// this rectangle is corrrect
EDA_Rect dirty = Track->GetBoundingBox(); EDA_Rect dirty = Track->GetBoundingBox();
D(printf( "dirty m_Pos=(%d, %d) m_Size=(%d, %d)\n", // Convert the rect coordinates and size in pixels (make a draw clip box):
dirty.m_Pos.x, dirty.m_Pos.y, dirty.m_Size.x, dirty.m_Size.y );) DrawPanel->ConvertPcbUnitsToPixelsUnits( dirty );
int zoom = GetZoom();
wxPoint drwOrig = GetScreen()->m_DrawOrg;
dirty.m_Pos.x = (dirty.m_Pos.x - drwOrig.x) / zoom;
dirty.m_Pos.y = (dirty.m_Pos.y - drwOrig.y) / zoom;
dirty.m_Size.x = (dirty.m_Size.x - drwOrig.x) / zoom; // Ensure the last line and column are in the dirty rectangle after truncatures
dirty.m_Size.y = (dirty.m_Size.y - drwOrig.y) / zoom; dirty.m_Size.x += 1; dirty.m_Size.y += 1;
D(printf( "dirty scaled zoom=%d m_Pos=(%d, %d) m_Size=(%d, %d) drwOrig=(%d, %d)\n",
zoom,
dirty.m_Pos.x, dirty.m_Pos.y, dirty.m_Size.x, dirty.m_Size.y,
drwOrig.x, drwOrig.y );)
// pass wxRect() via EDA_Rect::operator wxRect() overload // pass wxRect() via EDA_Rect::operator wxRect() overload
wxRect dirtyR = dirty; wxRect dirtyR = dirty;
D(printf( "dirtyR m_Pos=(%d, %d) m_Size=(%d, %d)\n",
dirtyR.x, dirtyR.y, dirtyR.width, dirtyR.height );)
/* The calculation for dirtyR is either wrong or the handling of the clipping
rect in OnPaint() is wrong. Enable this line instead of the Refresh() below,
then try deleting a track segment.
DrawPanel->RefreshRect( dirtyR, TRUE ); DrawPanel->RefreshRect( dirtyR, TRUE );
*/
DrawPanel->Refresh( TRUE );
#endif #endif
...@@ -249,7 +227,7 @@ void WinEDA_PcbFrame::Supprime_Une_Piste( wxDC* DC, TRACK* pt_segm ) ...@@ -249,7 +227,7 @@ void WinEDA_PcbFrame::Supprime_Une_Piste( wxDC* DC, TRACK* pt_segm )
/* Effacement flag BUSY */ /* Effacement flag BUSY */
Struct = pt_track;; Struct = pt_track;;
for( ii=0; ii<nb_segm; ii++, Struct = (TRACK*) Struct->Pnext ) for( ii = 0; ii<nb_segm; ii++, Struct = (TRACK*) Struct->Pnext )
{ {
Struct->SetState( BUSY, OFF ); Struct->SetState( BUSY, OFF );
} }
......
This diff is collapsed.
...@@ -43,13 +43,15 @@ MODULE* WinEDA_ModuleEditFrame::Import_Module( wxDC* DC ) ...@@ -43,13 +43,15 @@ MODULE* WinEDA_ModuleEditFrame::Import_Module( wxDC* DC )
wxString CmpFullFileName; wxString CmpFullFileName;
FILE* dest; FILE* dest;
MODULE* module = NULL; MODULE* module = NULL;
bool Footprint_Is_GPCB_Format = false;
wxString mask = wxT("*.*;"); mask += EXT_CMP_MASK;
/* Lecture Fichier module */ /* Lecture Fichier module */
CmpFullFileName = EDA_FileSelector( _( "Import Module:" ), CmpFullFileName = EDA_FileSelector( _( "Import Module:" ),
wxEmptyString, /* Chemin par defaut */ wxEmptyString, /* Chemin par defaut */
wxEmptyString, /* nom fichier par defaut */ wxEmptyString, /* nom fichier par defaut */
EXT_CMP, /* extension par defaut */ wxEmptyString, /* extension par defaut */
EXT_CMP_MASK, /* Masque d'affichage */ mask, /* Masque d'affichage */
this, this,
wxFD_OPEN, wxFD_OPEN,
TRUE TRUE
...@@ -70,21 +72,38 @@ MODULE* WinEDA_ModuleEditFrame::Import_Module( wxDC* DC ) ...@@ -70,21 +72,38 @@ MODULE* WinEDA_ModuleEditFrame::Import_Module( wxDC* DC )
GetLine( dest, Line, &NbLine ); GetLine( dest, Line, &NbLine );
if( strnicmp( Line, ENTETE_LIBRAIRIE, L_ENTETE_LIB ) != 0 ) if( strnicmp( Line, ENTETE_LIBRAIRIE, L_ENTETE_LIB ) != 0 )
{ {
if( strnicmp( Line, "Element", 7 ) == 0 )
Footprint_Is_GPCB_Format = true;
else
{
fclose( dest );
DisplayError( this, _( "Not a module file" ) ); DisplayError( this, _( "Not a module file" ) );
return NULL; return NULL;
} }
}
/* Lecture du fichier: recherche du debut de la descr module */ /* Lecture du fichier: recherche du debut de la descr module */
if ( ! Footprint_Is_GPCB_Format )
{
while( GetLine( dest, Line, &NbLine ) != NULL ) while( GetLine( dest, Line, &NbLine ) != NULL )
{ {
if( strnicmp( Line, "$MODULE", 7 ) == 0 ) if( strnicmp( Line, "$MODULE", 7 ) == 0 )
break; break;
} }
}
module = new MODULE( m_Pcb ); module = new MODULE( m_Pcb );
if ( Footprint_Is_GPCB_Format )
{
fclose( dest );
module->Read_GPCB_Descr(CmpFullFileName);
}
else
{
module->ReadDescr( dest, &NbLine ); module->ReadDescr( dest, &NbLine );
fclose( dest ); fclose( dest );
}
/* Mise a jour du chainage */ /* Mise a jour du chainage */
if( m_Pcb->m_Modules ) if( m_Pcb->m_Modules )
......
...@@ -116,7 +116,8 @@ OBJECTS= $(TARGET).o classpcb.o\ ...@@ -116,7 +116,8 @@ OBJECTS= $(TARGET).o classpcb.o\
modedit.o\ modedit.o\
export_gencad.o\ export_gencad.o\
hotkeys.o \ hotkeys.o \
collectors.o collectors.o\
gpcb_exchange.o
PolyLine.o: ../polygon/PolyLine.cpp ../polygon/PolyLine.h $(COMMON) PolyLine.o: ../polygon/PolyLine.cpp ../polygon/PolyLine.h $(COMMON)
......
...@@ -18,17 +18,17 @@ ...@@ -18,17 +18,17 @@
// Events used by WinEDA_DrawPanel // Events used by WinEDA_DrawPanel
BEGIN_EVENT_TABLE( WinEDA_DrawPanel, EDA_DRAW_PANEL ) BEGIN_EVENT_TABLE( WinEDA_DrawPanel, EDA_DRAW_PANEL )
EVT_LEAVE_WINDOW( WinEDA_DrawPanel::OnMouseLeaving ) EVT_LEAVE_WINDOW( WinEDA_DrawPanel::OnMouseLeaving )
EVT_MOUSE_EVENTS( WinEDA_DrawPanel::OnMouseEvent ) EVT_MOUSE_EVENTS( WinEDA_DrawPanel::OnMouseEvent )
EVT_CHAR( WinEDA_DrawPanel::OnKeyEvent ) EVT_CHAR( WinEDA_DrawPanel::OnKeyEvent )
EVT_CHAR_HOOK( WinEDA_DrawPanel::OnKeyEvent ) EVT_CHAR_HOOK( WinEDA_DrawPanel::OnKeyEvent )
EVT_PAINT( WinEDA_DrawPanel::OnPaint ) EVT_PAINT( WinEDA_DrawPanel::OnPaint )
EVT_SIZE( WinEDA_DrawPanel::OnSize ) EVT_SIZE( WinEDA_DrawPanel::OnSize )
EVT_ERASE_BACKGROUND( WinEDA_DrawPanel::OnEraseBackground ) EVT_ERASE_BACKGROUND( WinEDA_DrawPanel::OnEraseBackground )
EVT_SCROLLWIN( WinEDA_DrawPanel::OnScroll ) EVT_SCROLLWIN( WinEDA_DrawPanel::OnScroll )
EVT_ACTIVATE( WinEDA_DrawPanel::OnActivate ) EVT_ACTIVATE( WinEDA_DrawPanel::OnActivate )
EVT_MENU_RANGE( ID_POPUP_ZOOM_START_RANGE, ID_POPUP_ZOOM_END_RANGE, EVT_MENU_RANGE( ID_POPUP_ZOOM_START_RANGE, ID_POPUP_ZOOM_END_RANGE,
WinEDA_DrawPanel::Process_Popup_Zoom ) WinEDA_DrawPanel::Process_Popup_Zoom )
END_EVENT_TABLE() END_EVENT_TABLE()
...@@ -266,19 +266,67 @@ bool WinEDA_DrawPanel::IsPointOnDisplay( wxPoint ref_pos ) ...@@ -266,19 +266,67 @@ bool WinEDA_DrawPanel::IsPointOnDisplay( wxPoint ref_pos )
} }
/************************************************************************/
void WinEDA_DrawPanel::ConvertPcbUnitsToPixelsUnits( EDA_Rect& aRect )
/************************************************************************/
/** Function ConvertPcbUnitsToPixelsUnits
* Convert pos and size off the given EDA_Rect to pos and size in pixels,
* relative to the current draw area (origin 0,0 is the left top visible corner draw area)
* according to the current scrool and zoom
* @param aRect = the given rect
*/
{
// Calculate the draw area origin in internal units:
wxPoint pos = aRect.GetPosition();
ConvertPcbUnitsToPixelsUnits( pos );
aRect.SetOrigin( pos ); // rect origin in pixel units
aRect.m_Size.x /= GetZoom();
aRect.m_Size.y /= GetZoom(); // size in pixel units
}
/***************************************************************************/
void WinEDA_DrawPanel::ConvertPcbUnitsToPixelsUnits( wxPoint& aPosition )
/***************************************************************************/
/** Function ConvertPcbUnitsToPixelsUnits
* Convert a given wxPoint position (in internal units) to the pos in pixels,
* relative to the current draw area (origin 0,0 is the left top visible corner draw area)
* according to the current scrool and zoom
* @param aPosition = the given position
*/
{
// Calculate the draw area origin in internal units:
wxPoint drwOrig;
int x_axis_scale, y_axis_scale;
GetViewStart( &drwOrig.x, &drwOrig.y ); // Origin in scrool units;
GetScrollPixelsPerUnit( &x_axis_scale, &y_axis_scale );
drwOrig.x *= x_axis_scale; drwOrig.y *= y_axis_scale; // Origin in pixels units;
drwOrig.x *= GetZoom(); drwOrig.y *= GetZoom(); // Origin in internal units;
drwOrig += GetScreen()->m_DrawOrg; // Real origin, according to the "plot" origin
aPosition -= drwOrig; // position in internal units, relative to the visible draw area origin
aPosition.x /= GetZoom();
aPosition.y /= GetZoom(); // position in pixels, relative to the visible draw area origin
}
/********************************************************/ /********************************************************/
wxPoint WinEDA_DrawPanel::CursorScreenPosition() wxPoint WinEDA_DrawPanel::CursorScreenPosition()
/********************************************************/ /********************************************************/
/** CursorScreenPosition /** CursorScreenPosition
* @return relative position in pixels of du curseur * @return the curseur position in pixels in the panel draw area on screen )
* ( relative position = position in the panel draw area on screen )
*/ */
{ {
wxPoint curpos = GetScreen()->m_Curseur; wxPoint curpos = GetScreen()->m_Curseur;
curpos.x -= GetScreen()->m_DrawOrg.x; curpos -= GetScreen()->m_DrawOrg;
curpos.y -= GetScreen()->m_DrawOrg.y;
curpos.x /= GetZoom(); curpos.x /= GetZoom();
curpos.y /= GetZoom(); curpos.y /= GetZoom();
...@@ -288,7 +336,7 @@ wxPoint WinEDA_DrawPanel::CursorScreenPosition() ...@@ -288,7 +336,7 @@ wxPoint WinEDA_DrawPanel::CursorScreenPosition()
/*********************************************************/ /*********************************************************/
wxPoint WinEDA_DrawPanel::GetScreenCenterRealPosition() wxPoint WinEDA_DrawPanel::GetScreenCenterRealPosition( void )
/*********************************************************/ /*********************************************************/
/** Function GetScreenCenterRealPosition() /** Function GetScreenCenterRealPosition()
...@@ -435,7 +483,9 @@ void WinEDA_DrawPanel::SetBoundaryBox() ...@@ -435,7 +483,9 @@ void WinEDA_DrawPanel::SetBoundaryBox()
*/ */
{ {
BASE_SCREEN* Screen = GetScreen();; BASE_SCREEN* Screen = GetScreen();;
if(!Screen) return;
if( !Screen )
return;
wxPoint org; wxPoint org;
int ii, jj; int ii, jj;
...@@ -504,7 +554,7 @@ void WinEDA_DrawPanel::OnPaint( wxPaintEvent& event ) ...@@ -504,7 +554,7 @@ void WinEDA_DrawPanel::OnPaint( wxPaintEvent& event )
PaintClipBox = upd.GetBox(); PaintClipBox = upd.GetBox();
#if 1 && defined(DEBUG) #if 1 && defined (DEBUG)
printf( "PaintClipBox[%d]=(%d, %d, %d, %d) org=(%d, %d) m_ClipBox=(%d, %d, %d, %d)\n", printf( "PaintClipBox[%d]=(%d, %d, %d, %d) org=(%d, %d) m_ClipBox=(%d, %d, %d, %d)\n",
counter, counter,
PaintClipBox.x, PaintClipBox.x,
...@@ -533,7 +583,7 @@ void WinEDA_DrawPanel::OnPaint( wxPaintEvent& event ) ...@@ -533,7 +583,7 @@ void WinEDA_DrawPanel::OnPaint( wxPaintEvent& event )
#endif #endif
#if 1 && defined(DEBUG) #if 1 // && defined(DEBUG)
printf( "PaintClipBox[%d]=(%d, %d, %d, %d) org=(%d, %d) m_ClipBox=(%d, %d, %d, %d)\n", printf( "PaintClipBox[%d]=(%d, %d, %d, %d) org=(%d, %d) m_ClipBox=(%d, %d, %d, %d)\n",
counter, counter,
PaintClipBox.x, PaintClipBox.x,
...@@ -557,6 +607,7 @@ void WinEDA_DrawPanel::OnPaint( wxPaintEvent& event ) ...@@ -557,6 +607,7 @@ void WinEDA_DrawPanel::OnPaint( wxPaintEvent& event )
event.Skip(); event.Skip();
} }
#else // old code #else // old code
{ {
...@@ -886,7 +937,8 @@ void WinEDA_DrawPanel::OnMouseEvent( wxMouseEvent& event ) ...@@ -886,7 +937,8 @@ void WinEDA_DrawPanel::OnMouseEvent( wxMouseEvent& event )
static WinEDA_DrawPanel* LastPanel; static WinEDA_DrawPanel* LastPanel;
static bool IgnoreNextLeftButtonRelease = false; static bool IgnoreNextLeftButtonRelease = false;
if(!screen) return; if( !screen )
return;
#define MIN_DRAG_COUNT_FOR_START_BLOCK_COMMAND 5 /* Adjust value to filter mouse deplacement before #define MIN_DRAG_COUNT_FOR_START_BLOCK_COMMAND 5 /* Adjust value to filter mouse deplacement before
* consider the drag mouse is really a drag command, not just a movement while click * consider the drag mouse is really a drag command, not just a movement while click
*/ */
......
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