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
Please add newer entries at the top, list the date and your name with
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>
================================================================================
+help
......
......@@ -373,21 +373,3 @@ char* strupper( char* 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:
void Process_Special_Functions( wxCommandEvent& event );
wxPoint CursorRealPosition( const wxPoint& ScreenPos );
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 MouseTo( const wxPoint& Mouse );
......
......@@ -78,6 +78,7 @@ SET(PCBNEW_SRCS
gen_modules_placefile.cpp
gendrill.cpp
globaleditpad.cpp
gpcb_exchange.cpp
graphpcb.cpp
hotkeys.cpp
initpcb.cpp
......
......@@ -765,15 +765,15 @@ int MODULE::ReadDescr( FILE* File, int* LineNum )
}
}
/* Recalcul de l'encadrement */
/* Recalculate the bounding box */
Set_Rectangle_Encadrement();
return 0;
}
/****************************************************/
/*************************************************/
void MODULE::SetPosition( const wxPoint& newpos )
/****************************************************/
/*************************************************/
// replace le module en position newpos
{
......
......@@ -142,6 +142,14 @@ public:
int Write_3D_Descr( FILE* File ) const;
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 );
/* drawing functions */
......
......@@ -32,9 +32,9 @@ TRACK* WinEDA_PcbFrame::Delete_Segment( wxDC* DC, TRACK* Track )
if( Track == 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;
}
......@@ -42,7 +42,7 @@ TRACK* WinEDA_PcbFrame::Delete_Segment( wxDC* DC, TRACK* Track )
{
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
ShowNewTrackWhenMovingCursor( DrawPanel, DC, FALSE );
......@@ -83,7 +83,7 @@ TRACK* WinEDA_PcbFrame::Delete_Segment( wxDC* DC, TRACK* Track )
// Rectification couche active qui a pu changer si une via
// a ete effacee
((PCB_SCREEN*)GetScreen())->m_Active_Layer = previous_layer;
( (PCB_SCREEN*) GetScreen() )->m_Active_Layer = previous_layer;
Affiche_Status_Box();
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 )
#else
// redraw the area where the track was
// this rectangle is corrrect
// this rectangle is correct
EDA_Rect dirty = Track->GetBoundingBox();
D(printf( "dirty m_Pos=(%d, %d) m_Size=(%d, %d)\n",
dirty.m_Pos.x, dirty.m_Pos.y, dirty.m_Size.x, dirty.m_Size.y );)
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;
// Convert the rect coordinates and size in pixels (make a draw clip box):
DrawPanel->ConvertPcbUnitsToPixelsUnits( dirty );
dirty.m_Size.x = (dirty.m_Size.x - drwOrig.x) / zoom;
dirty.m_Size.y = (dirty.m_Size.y - drwOrig.y) / zoom;
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 );)
// Ensure the last line and column are in the dirty rectangle after truncatures
dirty.m_Size.x += 1; dirty.m_Size.y += 1;
// pass wxRect() via EDA_Rect::operator wxRect() overload
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->Refresh( TRUE );
#endif
......@@ -249,7 +227,7 @@ void WinEDA_PcbFrame::Supprime_Une_Piste( wxDC* DC, TRACK* pt_segm )
/* Effacement flag BUSY */
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 );
}
......
This diff is collapsed.
......@@ -43,13 +43,15 @@ MODULE* WinEDA_ModuleEditFrame::Import_Module( wxDC* DC )
wxString CmpFullFileName;
FILE* dest;
MODULE* module = NULL;
bool Footprint_Is_GPCB_Format = false;
wxString mask = wxT("*.*;"); mask += EXT_CMP_MASK;
/* Lecture Fichier module */
CmpFullFileName = EDA_FileSelector( _( "Import Module:" ),
wxEmptyString, /* Chemin par defaut */
wxEmptyString, /* nom fichier par defaut */
EXT_CMP, /* extension par defaut */
EXT_CMP_MASK, /* Masque d'affichage */
wxEmptyString, /* extension par defaut */
mask, /* Masque d'affichage */
this,
wxFD_OPEN,
TRUE
......@@ -70,21 +72,38 @@ MODULE* WinEDA_ModuleEditFrame::Import_Module( wxDC* DC )
GetLine( dest, Line, &NbLine );
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" ) );
return NULL;
}
}
/* Lecture du fichier: recherche du debut de la descr module */
if ( ! Footprint_Is_GPCB_Format )
{
while( GetLine( dest, Line, &NbLine ) != NULL )
{
if( strnicmp( Line, "$MODULE", 7 ) == 0 )
break;
}
}
module = new MODULE( m_Pcb );
if ( Footprint_Is_GPCB_Format )
{
fclose( dest );
module->Read_GPCB_Descr(CmpFullFileName);
}
else
{
module->ReadDescr( dest, &NbLine );
fclose( dest );
}
/* Mise a jour du chainage */
if( m_Pcb->m_Modules )
......
......@@ -116,7 +116,8 @@ OBJECTS= $(TARGET).o classpcb.o\
modedit.o\
export_gencad.o\
hotkeys.o \
collectors.o
collectors.o\
gpcb_exchange.o
PolyLine.o: ../polygon/PolyLine.cpp ../polygon/PolyLine.h $(COMMON)
......
......@@ -18,17 +18,17 @@
// Events used by WinEDA_DrawPanel
BEGIN_EVENT_TABLE( WinEDA_DrawPanel, EDA_DRAW_PANEL )
EVT_LEAVE_WINDOW( WinEDA_DrawPanel::OnMouseLeaving )
EVT_MOUSE_EVENTS( WinEDA_DrawPanel::OnMouseEvent )
EVT_CHAR( WinEDA_DrawPanel::OnKeyEvent )
EVT_CHAR_HOOK( WinEDA_DrawPanel::OnKeyEvent )
EVT_PAINT( WinEDA_DrawPanel::OnPaint )
EVT_SIZE( WinEDA_DrawPanel::OnSize )
EVT_ERASE_BACKGROUND( WinEDA_DrawPanel::OnEraseBackground )
EVT_SCROLLWIN( WinEDA_DrawPanel::OnScroll )
EVT_ACTIVATE( WinEDA_DrawPanel::OnActivate )
EVT_MENU_RANGE( ID_POPUP_ZOOM_START_RANGE, ID_POPUP_ZOOM_END_RANGE,
EVT_LEAVE_WINDOW( WinEDA_DrawPanel::OnMouseLeaving )
EVT_MOUSE_EVENTS( WinEDA_DrawPanel::OnMouseEvent )
EVT_CHAR( WinEDA_DrawPanel::OnKeyEvent )
EVT_CHAR_HOOK( WinEDA_DrawPanel::OnKeyEvent )
EVT_PAINT( WinEDA_DrawPanel::OnPaint )
EVT_SIZE( WinEDA_DrawPanel::OnSize )
EVT_ERASE_BACKGROUND( WinEDA_DrawPanel::OnEraseBackground )
EVT_SCROLLWIN( WinEDA_DrawPanel::OnScroll )
EVT_ACTIVATE( WinEDA_DrawPanel::OnActivate )
EVT_MENU_RANGE( ID_POPUP_ZOOM_START_RANGE, ID_POPUP_ZOOM_END_RANGE,
WinEDA_DrawPanel::Process_Popup_Zoom )
END_EVENT_TABLE()
......@@ -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()
/********************************************************/
/** CursorScreenPosition
* @return relative position in pixels of du curseur
* ( relative position = position in the panel draw area on screen )
* @return the curseur position in pixels in the panel draw area on screen )
*/
{
wxPoint curpos = GetScreen()->m_Curseur;
curpos.x -= GetScreen()->m_DrawOrg.x;
curpos.y -= GetScreen()->m_DrawOrg.y;
curpos -= GetScreen()->m_DrawOrg;
curpos.x /= GetZoom();
curpos.y /= GetZoom();
......@@ -288,7 +336,7 @@ wxPoint WinEDA_DrawPanel::CursorScreenPosition()
/*********************************************************/
wxPoint WinEDA_DrawPanel::GetScreenCenterRealPosition()
wxPoint WinEDA_DrawPanel::GetScreenCenterRealPosition( void )
/*********************************************************/
/** Function GetScreenCenterRealPosition()
......@@ -435,7 +483,9 @@ void WinEDA_DrawPanel::SetBoundaryBox()
*/
{
BASE_SCREEN* Screen = GetScreen();;
if(!Screen) return;
if( !Screen )
return;
wxPoint org;
int ii, jj;
......@@ -504,7 +554,7 @@ void WinEDA_DrawPanel::OnPaint( wxPaintEvent& event )
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",
counter,
PaintClipBox.x,
......@@ -533,7 +583,7 @@ void WinEDA_DrawPanel::OnPaint( wxPaintEvent& event )
#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",
counter,
PaintClipBox.x,
......@@ -557,6 +607,7 @@ void WinEDA_DrawPanel::OnPaint( wxPaintEvent& event )
event.Skip();
}
#else // old code
{
......@@ -886,7 +937,8 @@ void WinEDA_DrawPanel::OnMouseEvent( wxMouseEvent& event )
static WinEDA_DrawPanel* LastPanel;
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
* 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