void LIB_EDIT_FRAME::CreateImagePins( LIB_PIN* aPin, int aUnit, int aConvert, bool aDeMorgan ) { int ii; LIB_PIN* NewPin; if( !SynchronizePins() ) return; // Create "convert" pin at the current position. if( aDeMorgan && ( aPin->GetConvert() != 0 ) ) { NewPin = (LIB_PIN*) aPin->Clone(); if( aPin->GetConvert() > 1 ) NewPin->SetConvert( 1 ); else NewPin->SetConvert( 2 ); aPin->GetParent()->AddDrawItem( NewPin ); } for( ii = 1; ii <= aPin->GetParent()->GetUnitCount(); ii++ ) { if( ii == aUnit || aPin->GetUnit() == 0 ) continue; // Pin common to all units. NewPin = (LIB_PIN*) aPin->Clone(); // To avoid mistakes, gives this pin a new pin number because // it does no have the save pin number as the master pin // Because we do not know the actual number, give it '??' wxString unknownNum( wxT( "??" ) ); NewPin->SetPinNumFromString( unknownNum ); if( aConvert != 0 ) NewPin->SetConvert( 1 ); NewPin->SetUnit( ii ); aPin->GetParent()->AddDrawItem( NewPin ); if( !( aDeMorgan && ( aPin->GetConvert() != 0 ) ) ) continue; NewPin = (LIB_PIN*) aPin->Clone(); NewPin->SetConvert( 2 ); // Gives this pin a new pin number // Because we do not know the actual number, give it '??' NewPin->SetPinNumFromString( unknownNum ); if( aPin->GetUnit() != 0 ) NewPin->SetUnit( ii ); aPin->GetParent()->AddDrawItem( NewPin ); } }
void LIB_EDIT_FRAME::deleteItem( wxDC* aDC ) { wxCHECK_RET( m_drawItem != NULL, wxT( "No drawing item selected to delete." ) ); m_canvas->CrossHairOff( aDC ); LIB_PART* part = GetCurPart(); SaveCopyInUndoList( part ); if( m_drawItem->Type() == LIB_PIN_T ) { LIB_PIN* pin = (LIB_PIN*) m_drawItem; wxPoint pos = pin->GetPosition(); part->RemoveDrawItem( (LIB_ITEM*) pin, m_canvas, aDC ); if( SynchronizePins() ) { LIB_PIN* tmp = part->GetNextPin(); while( tmp != NULL ) { pin = tmp; tmp = part->GetNextPin( pin ); if( pin->GetPosition() != pos ) continue; part->RemoveDrawItem( (LIB_ITEM*) pin ); } } m_canvas->Refresh(); } else { if( m_canvas->IsMouseCaptured() ) { m_canvas->CallEndMouseCapture( aDC ); } else { part->RemoveDrawItem( m_drawItem, m_canvas, aDC ); m_canvas->Refresh(); } } m_drawItem = NULL; m_lastDrawItem = NULL; OnModify(); m_canvas->CrossHairOn( aDC ); }
/** * Prepare the displacement of a pin * * Locate the pin pointed to by the cursor, and set the cursor management * function move the pin. */ void LIB_EDIT_FRAME::StartMovePin( wxDC* DC ) { LIB_PIN* cur_pin = (LIB_PIN*) m_drawItem; wxPoint startPos; TempCopyComponent(); LIB_PART* part = GetCurPart(); // Mark pins for moving. for( LIB_PIN* pin = part->GetNextPin(); pin; pin = part->GetNextPin( pin ) ) { pin->ClearFlags(); if( pin == cur_pin ) continue; if( pin->GetPosition() == cur_pin->GetPosition() && pin->GetOrientation() == cur_pin->GetOrientation() && SynchronizePins() ) { pin->SetFlags( IS_LINKED | IS_MOVED ); } } cur_pin->SetFlags( IS_LINKED | IS_MOVED ); PinPreviousPos = OldPos = cur_pin->GetPosition(); startPos.x = OldPos.x; startPos.y = -OldPos.y; // m_canvas->CrossHairOff( DC ); SetCrossHairPosition( startPos ); m_canvas->MoveCursorToCrossHair(); MSG_PANEL_ITEMS items; cur_pin->GetMsgPanelInfo( items ); SetMsgPanel( items ); m_canvas->SetMouseCapture( DrawMovePin, AbortPinMove ); // m_canvas->CrossHairOn( DC ); // Refresh the screen to avoid color artifacts when drawing // the pin in Edit mode and moving it from its start position m_canvas->Refresh(); }
/** * Managed cursor callback for placing component pins. */ void LIB_EDIT_FRAME::PlacePin() { LIB_PIN* Pin; LIB_PIN* CurrentPin = (LIB_PIN*) m_drawItem; bool ask_for_pin = true; wxPoint newpos; bool status; // Some tests if( (CurrentPin == NULL) || (CurrentPin->Type() != LIB_PIN_T) ) { wxMessageBox( wxT( "LIB_EDIT_FRAME::PlacePin() error" ) ); return; } newpos = GetCrossHairPosition( true ); // Test for an other pin in same new position: for( Pin = m_component->GetNextPin(); Pin != NULL; Pin = m_component->GetNextPin( Pin ) ) { if( Pin == CurrentPin || newpos != Pin->GetPosition() || Pin->GetFlags() ) continue; if( ask_for_pin && SynchronizePins() ) { m_canvas->SetIgnoreMouseEvents( true ); status = IsOK( this, _( "This position is already occupied by \ another pin. Continue?" ) ); m_canvas->MoveCursorToCrossHair(); m_canvas->SetIgnoreMouseEvents( false ); if( !status ) return; else ask_for_pin = false; } }
// Create a new pin based on the previous pin with an incremented pin number. void LIB_EDIT_FRAME::RepeatPinItem( wxDC* DC, LIB_PIN* SourcePin ) { wxString msg; LIB_PART* part = GetCurPart(); if( !part || !SourcePin || SourcePin->Type() != LIB_PIN_T ) return; LIB_PIN* pin = (LIB_PIN*) SourcePin->Clone(); pin->ClearFlags(); pin->SetFlags( IS_NEW ); wxPoint step; switch( pin->GetOrientation() ) { case PIN_UP: step.x = GetRepeatPinStep(); break; case PIN_DOWN: step.x = GetRepeatPinStep(); break; case PIN_LEFT: step.y = - GetRepeatPinStep(); break; case PIN_RIGHT: step.y = - GetRepeatPinStep(); break; } pin->Move( pin->GetPosition() + step ); wxString nextName = pin->GetName(); IncrementLabelMember( nextName, GetRepeatDeltaLabel() ); pin->SetName( nextName ); pin->PinStringNum( msg ); IncrementLabelMember( msg, GetRepeatDeltaLabel() ); pin->SetPinNumFromString( msg ); m_drawItem = pin; if( SynchronizePins() ) pin->SetFlags( IS_LINKED ); wxPoint savepos = GetCrossHairPosition(); m_canvas->CrossHairOff( DC ); SetCrossHairPosition( wxPoint( pin->GetPosition().x, -pin->GetPosition().y ) ); // Add this new pin in list, and creates pins for others parts if needed m_drawItem = pin; ClearTempCopyComponent(); PlacePin(); m_lastDrawItem = pin; SetCrossHairPosition( savepos ); m_canvas->CrossHairOn( DC ); MSG_PANEL_ITEMS items; pin->GetMsgPanelInfo( items ); SetMsgPanel( items ); OnModify( ); }
/* * Create a new pin. */ void LIB_EDIT_FRAME::CreatePin( wxDC* DC ) { LIB_PART* part = GetCurPart(); if( !part ) return; part->ClearStatus(); LIB_PIN* pin = new LIB_PIN( part ); m_drawItem = pin; pin->SetFlags( IS_NEW ); pin->SetUnit( m_unit ); pin->SetConvert( m_convert ); // Flag pins to consider if( SynchronizePins() ) pin->SetFlags( IS_LINKED ); pin->Move( GetCrossHairPosition( true ) ); pin->SetLength( GetLastPinLength() ); pin->SetOrientation( LastPinOrient ); pin->SetType( LastPinType ); pin->SetShape( LastPinShape ); pin->SetNameTextSize( GetLastPinNameSize() ); pin->SetNumberTextSize( GetLastPinNumSize() ); pin->SetConvert( LastPinCommonConvert ? 0 : m_convert ); pin->SetUnit( LastPinCommonUnit ? 0 : m_unit ); pin->SetVisible( LastPinVisible ); PinPreviousPos = pin->GetPosition(); m_canvas->SetIgnoreMouseEvents( true ); wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED ); cmd.SetId( ID_LIBEDIT_EDIT_PIN ); GetEventHandler()->ProcessEvent( cmd ); m_canvas->MoveCursorToCrossHair(); m_canvas->SetIgnoreMouseEvents( false ); if( pin->GetFlags() & IS_CANCELLED ) { deleteItem( DC ); } else { ClearTempCopyComponent(); m_canvas->SetMouseCapture( DrawMovePin, AbortPinMove ); if( DC ) { int show_opts = PIN_DRAW_TEXTS | PIN_DRAW_DANGLING | PIN_DANGLING_HIDDEN; if( GetShowElectricalType() ) show_opts |= PIN_DRAW_ELECTRICAL_TYPE_NAME; // In LIB_PIN::Draw() a void* parameter used as flag to pass show_opts. // Build it: void* showOptions = reinterpret_cast<void*>( show_opts ); pin->Draw( m_canvas, DC, wxPoint( 0, 0 ), UNSPECIFIED_COLOR, GR_COPY, showOptions, DefaultTransform ); } } }
/** * Managed cursor callback for placing component pins. */ void LIB_EDIT_FRAME::PlacePin() { LIB_PIN* cur_pin = (LIB_PIN*) m_drawItem; bool ask_for_pin = true; wxPoint newpos; bool status; // Some tests if( !cur_pin || cur_pin->Type() != LIB_PIN_T ) { wxMessageBox( wxT( "LIB_EDIT_FRAME::PlacePin() error" ) ); return; } newpos = GetCrossHairPosition( true ); LIB_PART* part = GetCurPart(); // Test for an other pin in same new position: for( LIB_PIN* pin = part->GetNextPin(); pin; pin = part->GetNextPin( pin ) ) { if( pin == cur_pin || newpos != pin->GetPosition() || pin->GetFlags() ) continue; if( ask_for_pin && SynchronizePins() ) { m_canvas->SetIgnoreMouseEvents( true ); status = IsOK( this, _( "This position is already occupied by another pin. Continue?" ) ); m_canvas->MoveCursorToCrossHair(); m_canvas->SetIgnoreMouseEvents( false ); if( !status ) return; else ask_for_pin = false; } } // Create Undo from GetTempCopyComponent() if exists ( i.e. after a pin move) // or from m_component (pin add ...) if( GetTempCopyComponent() ) SaveCopyInUndoList( GetTempCopyComponent() ); else SaveCopyInUndoList( part ); m_canvas->SetMouseCapture( NULL, NULL ); OnModify(); cur_pin->Move( newpos ); if( cur_pin->IsNew() ) { LastPinOrient = cur_pin->GetOrientation(); LastPinType = cur_pin->GetType(); LastPinShape = cur_pin->GetShape(); if( SynchronizePins() ) CreateImagePins( cur_pin, m_unit, m_convert, m_showDeMorgan ); m_lastDrawItem = cur_pin; part->AddDrawItem( m_drawItem ); } // Put linked pins in new position, and clear flags for( LIB_PIN* pin = part->GetNextPin(); pin; pin = part->GetNextPin( pin ) ) { if( pin->GetFlags() == 0 ) continue; pin->Move( cur_pin->GetPosition() ); pin->ClearFlags(); } m_drawItem = NULL; m_canvas->Refresh(); }