Commit bd022c23 authored by jean-pierre charras's avatar jean-pierre charras

Libedit: fixed draw artefacts when editing a graphic symbol. fixed minor...

Libedit: fixed draw artefacts when editing a graphic symbol. fixed minor issues in undo and abort commands when editing graphic items.
parent 0c24113d
...@@ -785,12 +785,8 @@ void WinEDA_LibeditFrame::OnHotKey( wxDC* DC, int hotkey, EDA_BaseStruct* DrawSt ...@@ -785,12 +785,8 @@ void WinEDA_LibeditFrame::OnHotKey( wxDC* DC, int hotkey, EDA_BaseStruct* DrawSt
case HK_REPEAT_LAST: case HK_REPEAT_LAST:
if( m_lastDrawItem && (m_lastDrawItem->m_Flags == 0) if( m_lastDrawItem && (m_lastDrawItem->m_Flags == 0)
&& ( m_lastDrawItem->Type() == COMPONENT_PIN_DRAW_TYPE ) ) && ( m_lastDrawItem->Type() == COMPONENT_PIN_DRAW_TYPE ) )
{
RepeatPinItem( DC, (LIB_PIN*) m_lastDrawItem ); RepeatPinItem( DC, (LIB_PIN*) m_lastDrawItem );
} break;
else
wxBell();
break;
case HK_EDIT: case HK_EDIT:
m_drawItem = LocateItemUsingCursor(); m_drawItem = LocateItemUsingCursor();
...@@ -827,7 +823,7 @@ void WinEDA_LibeditFrame::OnHotKey( wxDC* DC, int hotkey, EDA_BaseStruct* DrawSt ...@@ -827,7 +823,7 @@ void WinEDA_LibeditFrame::OnHotKey( wxDC* DC, int hotkey, EDA_BaseStruct* DrawSt
case HK_ROTATE: case HK_ROTATE:
m_drawItem = LocateItemUsingCursor(); m_drawItem = LocateItemUsingCursor();
if( m_drawItem && !m_drawItem->InEditMode() ) if( m_drawItem )
{ {
switch( m_drawItem->Type() ) switch( m_drawItem->Type() )
{ {
......
...@@ -75,7 +75,6 @@ void WinEDA_LibeditFrame::OnLeftClick( wxDC* DC, const wxPoint& MousePos ) ...@@ -75,7 +75,6 @@ void WinEDA_LibeditFrame::OnLeftClick( wxDC* DC, const wxPoint& MousePos )
} }
else else
{ {
SaveCopyInUndoList( m_component );
PlacePin( DC ); PlacePin( DC );
} }
break; break;
......
...@@ -816,53 +816,31 @@ void WinEDA_LibeditFrame::Process_Special_Functions( wxCommandEvent& event ) ...@@ -816,53 +816,31 @@ void WinEDA_LibeditFrame::Process_Special_Functions( wxCommandEvent& event )
case ID_POPUP_LIBEDIT_ROTATE_GRAPHIC_TEXT: case ID_POPUP_LIBEDIT_ROTATE_GRAPHIC_TEXT:
if( m_drawItem == NULL && m_drawItem->Type() != COMPONENT_GRAPHIC_TEXT_DRAW_TYPE ) if( m_drawItem == NULL && m_drawItem->Type() != COMPONENT_GRAPHIC_TEXT_DRAW_TYPE )
break; break;
DrawPanel->CursorOff( &dc );
DrawPanel->MouseToCursorSchema(); DrawPanel->MouseToCursorSchema();
if( !m_drawItem->InEditMode() ) if( !m_drawItem->InEditMode() )
{ {
SaveCopyInUndoList( m_component ); SaveCopyInUndoList( m_component );
m_drawItem->SetUnit( m_unit ); m_drawItem->SetUnit( m_unit );
m_drawItem->Draw( DrawPanel, &dc, wxPoint( 0, 0 ), -1, g_XorMode, NULL,
DefaultTransform );
} }
m_drawItem->Rotate(); m_drawItem->Rotate();
DrawPanel->Refresh();
if( !m_drawItem->InEditMode() )
{
m_drawItem->Draw( DrawPanel, &dc, wxPoint( 0, 0 ), -1, g_XorMode, NULL,
DefaultTransform );
DrawPanel->Refresh();
}
DrawPanel->CursorOn( &dc );
break; break;
case ID_POPUP_LIBEDIT_FIELD_ROTATE_ITEM: case ID_POPUP_LIBEDIT_FIELD_ROTATE_ITEM:
{ {
if( m_drawItem == NULL || ( m_drawItem->Type() != COMPONENT_FIELD_DRAW_TYPE ) ) if( m_drawItem == NULL || ( m_drawItem->Type() != COMPONENT_FIELD_DRAW_TYPE ) )
break; break;
DrawPanel->CursorOff( &dc );
DrawPanel->MouseToCursorSchema(); DrawPanel->MouseToCursorSchema();
if( !m_drawItem->InEditMode() ) if( !m_drawItem->InEditMode() )
{ {
SaveCopyInUndoList( m_component ); SaveCopyInUndoList( m_component );
m_drawItem->SetUnit( m_unit ); m_drawItem->SetUnit( m_unit );
m_drawItem->Draw( DrawPanel, &dc, wxPoint( 0, 0 ), -1, g_XorMode, NULL,
DefaultTransform );
} }
m_drawItem->Rotate(); m_drawItem->Rotate();
DrawPanel->Refresh();
if( !m_drawItem->InEditMode() )
{
m_drawItem->Draw( DrawPanel, &dc, wxPoint( 0, 0 ), -1, g_XorMode, NULL,
DefaultTransform );
DrawPanel->Refresh();
}
DrawPanel->CursorOn( &dc );
break; break;
} }
...@@ -980,6 +958,7 @@ void WinEDA_LibeditFrame::TempCopyComponent() ...@@ -980,6 +958,7 @@ void WinEDA_LibeditFrame::TempCopyComponent()
{ {
if( m_tempCopyComponent ) if( m_tempCopyComponent )
delete m_tempCopyComponent; delete m_tempCopyComponent;
m_tempCopyComponent = NULL;
if( m_component ) if( m_component )
m_tempCopyComponent = new LIB_COMPONENT( *m_component ); m_tempCopyComponent = new LIB_COMPONENT( *m_component );
} }
...@@ -990,8 +969,19 @@ void WinEDA_LibeditFrame::TempCopyComponent() ...@@ -990,8 +969,19 @@ void WinEDA_LibeditFrame::TempCopyComponent()
*/ */
void WinEDA_LibeditFrame::RestoreComponent() void WinEDA_LibeditFrame::RestoreComponent()
{ {
if( m_tempCopyComponent == NULL )
return;
if( m_component ) if( m_component )
delete m_component; delete m_component;
m_component = m_tempCopyComponent; m_component = m_tempCopyComponent;
m_tempCopyComponent = NULL; m_tempCopyComponent = NULL;
} }
/** Function ClearTempCopyComponent
* delete temporary copy of the current component and clear pointer
*/
void WinEDA_LibeditFrame::ClearTempCopyComponent()
{
delete m_tempCopyComponent;
m_tempCopyComponent = NULL;
}
...@@ -188,6 +188,11 @@ public: ...@@ -188,6 +188,11 @@ public:
*/ */
LIB_COMPONENT* GetTempCopyComponent() { return m_tempCopyComponent; } LIB_COMPONENT* GetTempCopyComponent() { return m_tempCopyComponent; }
/** Function ClearTempCopyComponent
* delete temporary copy of the current component and clear pointer
*/
void ClearTempCopyComponent();
bool IsEditingDrawItem() { return m_drawItem && m_drawItem->InEditMode(); } bool IsEditingDrawItem() { return m_drawItem && m_drawItem->InEditMode(); }
private: private:
......
...@@ -50,7 +50,8 @@ void WinEDA_LibeditFrame::OnRotatePin( wxCommandEvent& event ){ ...@@ -50,7 +50,8 @@ void WinEDA_LibeditFrame::OnRotatePin( wxCommandEvent& event ){
// Save old pin orientation // Save old pin orientation
LastPinOrient = pin -> m_Orient; LastPinOrient = pin -> m_Orient;
SaveCopyInUndoList( pin->GetParent() ); if( !pin->InEditMode() )
SaveCopyInUndoList( pin->GetParent() );
// Get the actual pin orientation index // Get the actual pin orientation index
int orientationIndex = pin -> GetOrientationCodeIndex(pin -> m_Orient); int orientationIndex = pin -> GetOrientationCodeIndex(pin -> m_Orient);
...@@ -159,7 +160,7 @@ void WinEDA_LibeditFrame::OnEditPin( wxCommandEvent& event ) ...@@ -159,7 +160,7 @@ void WinEDA_LibeditFrame::OnEditPin( wxCommandEvent& event )
if( pin->IsModified() || pin->IsNew() ) if( pin->IsModified() || pin->IsNew() )
{ {
if( !pin->IsNew() ) if( !pin->InEditMode() )
SaveCopyInUndoList( pin->GetParent() ); SaveCopyInUndoList( pin->GetParent() );
OnModify( ); OnModify( );
...@@ -192,7 +193,7 @@ static void AbortPinMove( WinEDA_DrawPanel* Panel, wxDC* DC ) ...@@ -192,7 +193,7 @@ static void AbortPinMove( WinEDA_DrawPanel* Panel, wxDC* DC )
if( CurrentPin->m_Flags & IS_NEW ) if( CurrentPin->m_Flags & IS_NEW )
delete CurrentPin; delete CurrentPin;
else else
CurrentPin->m_Flags = 0; parent->RestoreComponent();
/* clear edit flags */ /* clear edit flags */
Panel->ManageCurseur = NULL; Panel->ManageCurseur = NULL;
...@@ -246,6 +247,13 @@ another pin. Continue?" ) ); ...@@ -246,6 +247,13 @@ another pin. Continue?" ) );
} }
} }
// Create Undo from GetTempCopyComponent() if exists ( i.e. after a pin move)
// or from m_component (pin add ...)
if( GetTempCopyComponent() )
SaveCopyInUndoList( GetTempCopyComponent() );
else
SaveCopyInUndoList( m_component );
DrawPanel->ManageCurseur = NULL; DrawPanel->ManageCurseur = NULL;
DrawPanel->ForceCloseManageCurseur = NULL; DrawPanel->ForceCloseManageCurseur = NULL;
OnModify( ); OnModify( );
...@@ -294,6 +302,8 @@ void WinEDA_LibeditFrame::StartMovePin( wxDC* DC ) ...@@ -294,6 +302,8 @@ void WinEDA_LibeditFrame::StartMovePin( wxDC* DC )
LIB_PIN* CurrentPin = (LIB_PIN*) m_drawItem; LIB_PIN* CurrentPin = (LIB_PIN*) m_drawItem;
wxPoint startPos; wxPoint startPos;
TempCopyComponent();
/* Mark pins for moving. */ /* Mark pins for moving. */
Pin = m_component->GetNextPin(); Pin = m_component->GetNextPin();
for( ; Pin != NULL; Pin = m_component->GetNextPin( Pin ) ) for( ; Pin != NULL; Pin = m_component->GetNextPin( Pin ) )
...@@ -466,6 +476,7 @@ void WinEDA_LibeditFrame::CreatePin( wxDC* DC ) ...@@ -466,6 +476,7 @@ void WinEDA_LibeditFrame::CreatePin( wxDC* DC )
} }
else else
{ {
ClearTempCopyComponent();
DrawPanel->ManageCurseur = DrawMovePin; DrawPanel->ManageCurseur = DrawMovePin;
DrawPanel->ForceCloseManageCurseur = AbortPinMove; DrawPanel->ForceCloseManageCurseur = AbortPinMove;
if( DC ) if( DC )
...@@ -609,6 +620,7 @@ void WinEDA_LibeditFrame::RepeatPinItem( wxDC* DC, LIB_PIN* SourcePin ) ...@@ -609,6 +620,7 @@ void WinEDA_LibeditFrame::RepeatPinItem( wxDC* DC, LIB_PIN* SourcePin )
// Add this new pin in list, and creates pins for others parts if needed // Add this new pin in list, and creates pins for others parts if needed
m_drawItem = Pin; m_drawItem = Pin;
ClearTempCopyComponent();
PlacePin( DC ); PlacePin( DC );
m_lastDrawItem = Pin; m_lastDrawItem = Pin;
......
...@@ -69,7 +69,7 @@ void WinEDA_LibeditFrame::EditGraphicSymbol( wxDC* DC, LIB_DRAW_ITEM* DrawItem ) ...@@ -69,7 +69,7 @@ void WinEDA_LibeditFrame::EditGraphicSymbol( wxDC* DC, LIB_DRAW_ITEM* DrawItem )
#endif #endif
// Save copy for undo if not in edit (edit command already handle the save copy) // Save copy for undo if not in edit (edit command already handle the save copy)
if( DrawItem->m_Flags == 0 ) if( !DrawItem->InEditMode() )
SaveCopyInUndoList( DrawItem->GetParent() ); SaveCopyInUndoList( DrawItem->GetParent() );
if( m_drawSpecificUnit ) if( m_drawSpecificUnit )
...@@ -113,11 +113,11 @@ static void AbortSymbolTraceOn( WinEDA_DrawPanel* Panel, wxDC* DC ) ...@@ -113,11 +113,11 @@ static void AbortSymbolTraceOn( WinEDA_DrawPanel* Panel, wxDC* DC )
if( newItem ) if( newItem )
{ {
delete item; delete item;
parent->SetDrawItem( NULL );
} }
else else
parent->RestoreComponent(); parent->RestoreComponent();
parent->SetDrawItem( NULL );
Panel->Refresh(); Panel->Refresh();
} }
...@@ -128,6 +128,10 @@ LIB_DRAW_ITEM* WinEDA_LibeditFrame::CreateGraphicItem( LIB_COMPONENT* LibEntry, ...@@ -128,6 +128,10 @@ LIB_DRAW_ITEM* WinEDA_LibeditFrame::CreateGraphicItem( LIB_COMPONENT* LibEntry,
DrawPanel->ForceCloseManageCurseur = AbortSymbolTraceOn; DrawPanel->ForceCloseManageCurseur = AbortSymbolTraceOn;
wxPoint drawPos = GetScreen()->GetCursorDrawPosition(); wxPoint drawPos = GetScreen()->GetCursorDrawPosition();
// no temp copy -> the current version of component will be used for Undo
// This is normal when adding new items to the current component
ClearTempCopyComponent();
switch( m_ID_current_state ) switch( m_ID_current_state )
{ {
case ID_LIBEDIT_BODY_ARC_BUTT: case ID_LIBEDIT_BODY_ARC_BUTT:
...@@ -156,12 +160,12 @@ LIB_DRAW_ITEM* WinEDA_LibeditFrame::CreateGraphicItem( LIB_COMPONENT* LibEntry, ...@@ -156,12 +160,12 @@ LIB_DRAW_ITEM* WinEDA_LibeditFrame::CreateGraphicItem( LIB_COMPONENT* LibEntry,
// Enter the graphic text info // Enter the graphic text info
DrawPanel->m_IgnoreMouseEvents = true; DrawPanel->m_IgnoreMouseEvents = true;
EditSymbolText( NULL, Text ); EditSymbolText( NULL, Text );
DrawPanel->MouseToCursorSchema();
DrawPanel->m_IgnoreMouseEvents = false; DrawPanel->m_IgnoreMouseEvents = false;
DrawPanel->MouseToCursorSchema();
if( Text->m_Text.IsEmpty() ) if( Text->m_Text.IsEmpty() )
{ {
SAFE_DELETE( Text ); delete Text;
m_drawItem = NULL; m_drawItem = NULL;
} }
else else
...@@ -186,7 +190,8 @@ LIB_DRAW_ITEM* WinEDA_LibeditFrame::CreateGraphicItem( LIB_COMPONENT* LibEntry, ...@@ -186,7 +190,8 @@ LIB_DRAW_ITEM* WinEDA_LibeditFrame::CreateGraphicItem( LIB_COMPONENT* LibEntry,
if( m_drawSpecificConvert ) if( m_drawSpecificConvert )
m_drawItem->m_Convert = m_convert; m_drawItem->m_Convert = m_convert;
TempCopyComponent(); // Draw initial symbol:
DrawPanel->ManageCurseur( DrawPanel, DC, false );
} }
else else
{ {
...@@ -282,13 +287,15 @@ static void SymbolDisplayDraw( WinEDA_DrawPanel* panel, wxDC* DC, bool erase ) ...@@ -282,13 +287,15 @@ static void SymbolDisplayDraw( WinEDA_DrawPanel* panel, wxDC* DC, bool erase )
if( item == NULL ) if( item == NULL )
return; return;
item->SetEraseLastDrawItem( erase );
item->Draw( panel, DC, Screen->GetCursorDrawPosition(), -1, g_XorMode, NULL, item->Draw( panel, DC, Screen->GetCursorDrawPosition(), -1, g_XorMode, NULL,
DefaultTransform ); DefaultTransform );
} }
/* /*
* Place the new graphic object in the list of component drawing objects. * Place the new graphic object in the list of component drawing objects,
* or terminate a draw item edition
*/ */
void WinEDA_LibeditFrame::EndDrawGraphicItem( wxDC* DC ) void WinEDA_LibeditFrame::EndDrawGraphicItem( wxDC* DC )
{ {
...@@ -300,7 +307,11 @@ void WinEDA_LibeditFrame::EndDrawGraphicItem( wxDC* DC ) ...@@ -300,7 +307,11 @@ void WinEDA_LibeditFrame::EndDrawGraphicItem( wxDC* DC )
else else
SetCursor( wxCURSOR_ARROW ); SetCursor( wxCURSOR_ARROW );
SaveCopyInUndoList( GetTempCopyComponent() ); if( GetTempCopyComponent() ) // used when editing an existing item
SaveCopyInUndoList( GetTempCopyComponent() );
else // When creating a new item, there is still no change for the current component
// So save it.
SaveCopyInUndoList( m_component );
if( m_drawItem->IsNew() ) if( m_drawItem->IsNew() )
m_component->AddDrawItem( m_drawItem ); m_component->AddDrawItem( m_drawItem );
......
...@@ -236,5 +236,5 @@ void WinEDA_LibeditFrame::PlaceAncre() ...@@ -236,5 +236,5 @@ void WinEDA_LibeditFrame::PlaceAncre()
/* Redraw the symbol */ /* Redraw the symbol */
GetScreen()->m_Curseur.x = GetScreen()->m_Curseur.y = 0; GetScreen()->m_Curseur.x = GetScreen()->m_Curseur.y = 0;
Recadre_Trace( TRUE ); Recadre_Trace( TRUE );
GetScreen()->SetRefreshReq(); DrawPanel->Refresh();
} }
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