/** * 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(); }
void LIB_EDIT_FRAME::OnEditPin( wxCommandEvent& event ) { if( m_drawItem == NULL || m_drawItem->Type() != LIB_PIN_T ) return; STATUS_FLAGS item_flags = m_drawItem->GetFlags(); // save flags to restore them after editing LIB_PIN* pin = (LIB_PIN*) m_drawItem; DIALOG_LIB_EDIT_PIN dlg( this, pin ); wxString units = GetUnitsLabel( g_UserUnit ); dlg.SetDlgUnitsLabel( units ); dlg.SetOrientationList( LIB_PIN::GetOrientationNames(), LIB_PIN::GetOrientationSymbols() ); dlg.SetOrientation( LIB_PIN::GetOrientationCodeIndex( pin->GetOrientation() ) ); dlg.SetStyle( pin->GetShape() ); dlg.SetElectricalType( pin->GetType() ); dlg.SetPinName( pin->GetName() ); dlg.SetPinNameTextSize( StringFromValue( g_UserUnit, pin->GetNameTextSize() ) ); dlg.SetPinPositionX( StringFromValue( g_UserUnit, pin->GetPosition().x ) ); dlg.SetPinPositionY( StringFromValue( g_UserUnit, -pin->GetPosition().y ) ); dlg.SetPadName( pin->GetNumberString() ); dlg.SetPadNameTextSize( StringFromValue( g_UserUnit, pin->GetNumberTextSize() ) ); dlg.SetLength( StringFromValue( g_UserUnit, pin->GetLength() ) ); dlg.SetAddToAllParts( pin->GetUnit() == 0 ); dlg.SetAddToAllBodyStyles( pin->GetConvert() == 0 ); dlg.SetVisible( pin->IsVisible() ); /* This ugly hack fixes a bug in wxWidgets 2.8.7 and likely earlier * versions for the flex grid sizer in wxGTK that prevents the last * column from being sized correctly. It doesn't cause any problems * on win32 so it doesn't need to wrapped in ugly #ifdef __WXGTK__ * #endif. */ dlg.Layout(); dlg.Fit(); dlg.SetMinSize( dlg.GetSize() ); if( dlg.ShowModal() == wxID_CANCEL ) { if( pin->IsNew() ) { pin->SetFlags( IS_CANCELLED ); m_canvas->EndMouseCapture(); } return; } // Test the pin position validity: to avoid issues in schematic, // it must be on a 50 mils grid wxPoint pinpos; pinpos.x = ValueFromString( g_UserUnit, dlg.GetPinPositionX() ); pinpos.y = -ValueFromString( g_UserUnit, dlg.GetPinPositionY() ); const int acceptable_mingrid = 50; if( (pinpos.x % acceptable_mingrid) || (pinpos.y % acceptable_mingrid) ) { wxString msg; msg.Printf( _( "This pin is not on a %d mils grid\n" "It will be not easy to connect in schematic\n" "Do you want to continue?"), acceptable_mingrid ); if( !IsOK( this, msg ) ) return; } // Save the pin properties to use for the next new pin. LastPinNameSize = ValueFromString( g_UserUnit, dlg.GetPinNameTextSize() ); LastPinNumSize = ValueFromString( g_UserUnit, dlg.GetPadNameTextSize() ); LastPinOrient = LIB_PIN::GetOrientationCode( dlg.GetOrientation() ); LastPinLength = ValueFromString( g_UserUnit, dlg.GetLength() ); LastPinShape = dlg.GetStyle(); LastPinType = dlg.GetElectricalType(); LastPinCommonConvert = dlg.GetAddToAllBodyStyles(); LastPinCommonUnit = dlg.GetAddToAllParts(); LastPinVisible = dlg.GetVisible(); pin->EnableEditMode( true, m_editPinsPerPartOrConvert ); pin->SetName( dlg.GetPinName() ); pin->SetNameTextSize( GetLastPinNameSize() ); pin->SetNumber( dlg.GetPadName() ); pin->SetNumberTextSize( GetLastPinNumSize() ); pin->SetOrientation( LastPinOrient ); pin->SetLength( GetLastPinLength() ); pin->SetPinPosition( pinpos ); pin->SetType( LastPinType ); pin->SetShape( LastPinShape ); pin->SetConversion( ( LastPinCommonConvert ) ? 0 : m_convert ); pin->SetPartNumber( ( LastPinCommonUnit ) ? 0 : m_unit ); pin->SetVisible( LastPinVisible ); if( pin->IsModified() || pin->IsNew() ) { if( !pin->InEditMode() ) SaveCopyInUndoList( pin->GetParent() ); OnModify( ); MSG_PANEL_ITEMS items; pin->GetMsgPanelInfo( items ); SetMsgPanel( items ); m_canvas->Refresh(); } pin->EnableEditMode( false, m_editPinsPerPartOrConvert ); // Restore pin flags, that can be changed by the dialog editor pin->ClearFlags(); pin->SetFlags( item_flags ); }
// 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( ); }
void LIB_EDIT_FRAME::OnEditPin( wxCommandEvent& event ) { if( m_drawItem == NULL || m_drawItem->Type() != LIB_PIN_T ) return; STATUS_FLAGS item_flags = m_drawItem->GetFlags(); // save flags to restore them after editing LIB_PIN* pin = (LIB_PIN*) m_drawItem; DIALOG_LIB_EDIT_PIN dlg( this, pin ); wxString units = GetUnitsLabel( g_UserUnit ); dlg.SetOrientationList( LIB_PIN::GetOrientationNames(), LIB_PIN::GetOrientationSymbols() ); dlg.SetOrientation( LIB_PIN::GetOrientationCodeIndex( pin->GetOrientation() ) ); dlg.SetStyleList( LIB_PIN::GetStyleNames(), LIB_PIN::GetStyleSymbols() ); dlg.SetStyle( LIB_PIN::GetStyleCodeIndex( pin->GetShape() ) ); dlg.SetElectricalTypeList( LIB_PIN::GetElectricalTypeNames(), LIB_PIN::GetElectricalTypeSymbols() ); dlg.SetElectricalType( pin->GetType() ); dlg.SetName( pin->GetName() ); dlg.SetNameTextSize( ReturnStringFromValue( g_UserUnit, pin->GetNameTextSize() ) ); dlg.SetNameTextSizeUnits( units ); dlg.SetPadName( pin->GetNumberString() ); dlg.SetPadNameTextSize( ReturnStringFromValue( g_UserUnit, pin->GetNumberTextSize() ) ); dlg.SetPadNameTextSizeUnits( units ); dlg.SetLength( ReturnStringFromValue( g_UserUnit, pin->GetLength() ) ); dlg.SetLengthUnits( units ); dlg.SetAddToAllParts( pin->GetUnit() == 0 ); dlg.SetAddToAllBodyStyles( pin->GetConvert() == 0 ); dlg.SetVisible( pin->IsVisible() ); /* This ugly hack fixes a bug in wxWidgets 2.8.7 and likely earlier * versions for the flex grid sizer in wxGTK that prevents the last * column from being sized correctly. It doesn't cause any problems * on win32 so it doesn't need to wrapped in ugly #ifdef __WXGTK__ * #endif. */ dlg.Layout(); dlg.Fit(); dlg.SetMinSize( dlg.GetSize() ); // dlg.SetLastSizeAndPosition(); // done in DIALOG_SHIM::Show() if( dlg.ShowModal() == wxID_CANCEL ) { if( pin->IsNew() ) { pin->SetFlags( IS_CANCELLED ); m_canvas->EndMouseCapture(); } return; } // Save the pin properties to use for the next new pin. LastPinNameSize = ReturnValueFromString( g_UserUnit, dlg.GetNameTextSize() ); LastPinNumSize = ReturnValueFromString( g_UserUnit, dlg.GetPadNameTextSize() ); LastPinOrient = LIB_PIN::GetOrientationCode( dlg.GetOrientation() ); LastPinLength = ReturnValueFromString( g_UserUnit, dlg.GetLength() ); LastPinShape = LIB_PIN::GetStyleCode( dlg.GetStyle() ); LastPinType = dlg.GetElectricalType(); LastPinCommonConvert = dlg.GetAddToAllBodyStyles(); LastPinCommonUnit = dlg.GetAddToAllParts(); LastPinVisible = dlg.GetVisible(); pin->EnableEditMode( true, m_editPinsPerPartOrConvert ); pin->SetName( dlg.GetName() ); pin->SetNameTextSize( LastPinNameSize ); pin->SetNumber( dlg.GetPadName() ); pin->SetNumberTextSize( LastPinNumSize ); pin->SetOrientation( LastPinOrient ); pin->SetLength( LastPinLength ); pin->SetType( LastPinType ); pin->SetShape( LastPinShape ); pin->SetConversion( ( LastPinCommonConvert ) ? 0 : m_convert ); pin->SetPartNumber( ( LastPinCommonUnit ) ? 0 : m_unit ); pin->SetVisible( LastPinVisible ); if( pin->IsModified() || pin->IsNew() ) { if( !pin->InEditMode() ) SaveCopyInUndoList( pin->GetParent() ); OnModify( ); MSG_PANEL_ITEMS items; pin->GetMsgPanelInfo( items ); SetMsgPanel( items ); m_canvas->Refresh(); } pin->EnableEditMode( false, m_editPinsPerPartOrConvert ); // Restore pin flags, that can be changed by the dialog editor pin->ClearFlags(); pin->SetFlags( item_flags ); }