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,11 +785,7 @@ void WinEDA_LibeditFrame::OnHotKey( wxDC* DC, int hotkey, EDA_BaseStruct* DrawSt
case HK_REPEAT_LAST:
if( m_lastDrawItem && (m_lastDrawItem->m_Flags == 0)
&& ( m_lastDrawItem->Type() == COMPONENT_PIN_DRAW_TYPE ) )
{
RepeatPinItem( DC, (LIB_PIN*) m_lastDrawItem );
}
else
wxBell();
break;
case HK_EDIT:
......@@ -827,7 +823,7 @@ void WinEDA_LibeditFrame::OnHotKey( wxDC* DC, int hotkey, EDA_BaseStruct* DrawSt
case HK_ROTATE:
m_drawItem = LocateItemUsingCursor();
if( m_drawItem && !m_drawItem->InEditMode() )
if( m_drawItem )
{
switch( m_drawItem->Type() )
{
......
......@@ -75,7 +75,6 @@ void WinEDA_LibeditFrame::OnLeftClick( wxDC* DC, const wxPoint& MousePos )
}
else
{
SaveCopyInUndoList( m_component );
PlacePin( DC );
}
break;
......
......@@ -816,53 +816,31 @@ void WinEDA_LibeditFrame::Process_Special_Functions( wxCommandEvent& event )
case ID_POPUP_LIBEDIT_ROTATE_GRAPHIC_TEXT:
if( m_drawItem == NULL && m_drawItem->Type() != COMPONENT_GRAPHIC_TEXT_DRAW_TYPE )
break;
DrawPanel->CursorOff( &dc );
DrawPanel->MouseToCursorSchema();
if( !m_drawItem->InEditMode() )
{
SaveCopyInUndoList( m_component );
m_drawItem->SetUnit( m_unit );
m_drawItem->Draw( DrawPanel, &dc, wxPoint( 0, 0 ), -1, g_XorMode, NULL,
DefaultTransform );
}
m_drawItem->Rotate();
if( !m_drawItem->InEditMode() )
{
m_drawItem->Draw( DrawPanel, &dc, wxPoint( 0, 0 ), -1, g_XorMode, NULL,
DefaultTransform );
DrawPanel->Refresh();
}
DrawPanel->CursorOn( &dc );
break;
case ID_POPUP_LIBEDIT_FIELD_ROTATE_ITEM:
{
if( m_drawItem == NULL || ( m_drawItem->Type() != COMPONENT_FIELD_DRAW_TYPE ) )
break;
DrawPanel->CursorOff( &dc );
DrawPanel->MouseToCursorSchema();
if( !m_drawItem->InEditMode() )
{
SaveCopyInUndoList( m_component );
m_drawItem->SetUnit( m_unit );
m_drawItem->Draw( DrawPanel, &dc, wxPoint( 0, 0 ), -1, g_XorMode, NULL,
DefaultTransform );
}
m_drawItem->Rotate();
if( !m_drawItem->InEditMode() )
{
m_drawItem->Draw( DrawPanel, &dc, wxPoint( 0, 0 ), -1, g_XorMode, NULL,
DefaultTransform );
DrawPanel->Refresh();
}
DrawPanel->CursorOn( &dc );
break;
}
......@@ -980,6 +958,7 @@ void WinEDA_LibeditFrame::TempCopyComponent()
{
if( m_tempCopyComponent )
delete m_tempCopyComponent;
m_tempCopyComponent = NULL;
if( m_component )
m_tempCopyComponent = new LIB_COMPONENT( *m_component );
}
......@@ -990,8 +969,19 @@ void WinEDA_LibeditFrame::TempCopyComponent()
*/
void WinEDA_LibeditFrame::RestoreComponent()
{
if( m_tempCopyComponent == NULL )
return;
if( m_component )
delete m_component;
m_component = m_tempCopyComponent;
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:
*/
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(); }
private:
......
......@@ -50,6 +50,7 @@ void WinEDA_LibeditFrame::OnRotatePin( wxCommandEvent& event ){
// Save old pin orientation
LastPinOrient = pin -> m_Orient;
if( !pin->InEditMode() )
SaveCopyInUndoList( pin->GetParent() );
// Get the actual pin orientation index
......@@ -159,7 +160,7 @@ void WinEDA_LibeditFrame::OnEditPin( wxCommandEvent& event )
if( pin->IsModified() || pin->IsNew() )
{
if( !pin->IsNew() )
if( !pin->InEditMode() )
SaveCopyInUndoList( pin->GetParent() );
OnModify( );
......@@ -192,7 +193,7 @@ static void AbortPinMove( WinEDA_DrawPanel* Panel, wxDC* DC )
if( CurrentPin->m_Flags & IS_NEW )
delete CurrentPin;
else
CurrentPin->m_Flags = 0;
parent->RestoreComponent();
/* clear edit flags */
Panel->ManageCurseur = NULL;
......@@ -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->ForceCloseManageCurseur = NULL;
OnModify( );
......@@ -294,6 +302,8 @@ void WinEDA_LibeditFrame::StartMovePin( wxDC* DC )
LIB_PIN* CurrentPin = (LIB_PIN*) m_drawItem;
wxPoint startPos;
TempCopyComponent();
/* Mark pins for moving. */
Pin = m_component->GetNextPin();
for( ; Pin != NULL; Pin = m_component->GetNextPin( Pin ) )
......@@ -466,6 +476,7 @@ void WinEDA_LibeditFrame::CreatePin( wxDC* DC )
}
else
{
ClearTempCopyComponent();
DrawPanel->ManageCurseur = DrawMovePin;
DrawPanel->ForceCloseManageCurseur = AbortPinMove;
if( DC )
......@@ -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
m_drawItem = Pin;
ClearTempCopyComponent();
PlacePin( DC );
m_lastDrawItem = Pin;
......
......@@ -69,7 +69,7 @@ void WinEDA_LibeditFrame::EditGraphicSymbol( wxDC* DC, LIB_DRAW_ITEM* DrawItem )
#endif
// 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() );
if( m_drawSpecificUnit )
......@@ -113,11 +113,11 @@ static void AbortSymbolTraceOn( WinEDA_DrawPanel* Panel, wxDC* DC )
if( newItem )
{
delete item;
parent->SetDrawItem( NULL );
}
else
parent->RestoreComponent();
parent->SetDrawItem( NULL );
Panel->Refresh();
}
......@@ -128,6 +128,10 @@ LIB_DRAW_ITEM* WinEDA_LibeditFrame::CreateGraphicItem( LIB_COMPONENT* LibEntry,
DrawPanel->ForceCloseManageCurseur = AbortSymbolTraceOn;
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 )
{
case ID_LIBEDIT_BODY_ARC_BUTT:
......@@ -156,12 +160,12 @@ LIB_DRAW_ITEM* WinEDA_LibeditFrame::CreateGraphicItem( LIB_COMPONENT* LibEntry,
// Enter the graphic text info
DrawPanel->m_IgnoreMouseEvents = true;
EditSymbolText( NULL, Text );
DrawPanel->MouseToCursorSchema();
DrawPanel->m_IgnoreMouseEvents = false;
DrawPanel->MouseToCursorSchema();
if( Text->m_Text.IsEmpty() )
{
SAFE_DELETE( Text );
delete Text;
m_drawItem = NULL;
}
else
......@@ -186,7 +190,8 @@ LIB_DRAW_ITEM* WinEDA_LibeditFrame::CreateGraphicItem( LIB_COMPONENT* LibEntry,
if( m_drawSpecificConvert )
m_drawItem->m_Convert = m_convert;
TempCopyComponent();
// Draw initial symbol:
DrawPanel->ManageCurseur( DrawPanel, DC, false );
}
else
{
......@@ -282,13 +287,15 @@ static void SymbolDisplayDraw( WinEDA_DrawPanel* panel, wxDC* DC, bool erase )
if( item == NULL )
return;
item->SetEraseLastDrawItem( erase );
item->Draw( panel, DC, Screen->GetCursorDrawPosition(), -1, g_XorMode, NULL,
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 )
{
......@@ -300,7 +307,11 @@ void WinEDA_LibeditFrame::EndDrawGraphicItem( wxDC* DC )
else
SetCursor( wxCURSOR_ARROW );
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() )
m_component->AddDrawItem( m_drawItem );
......
......@@ -236,5 +236,5 @@ void WinEDA_LibeditFrame::PlaceAncre()
/* Redraw the symbol */
GetScreen()->m_Curseur.x = GetScreen()->m_Curseur.y = 0;
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