diff --git a/eeschema/hotkeys.cpp b/eeschema/hotkeys.cpp index c833cba56e..12518867d3 100644 --- a/eeschema/hotkeys.cpp +++ b/eeschema/hotkeys.cpp @@ -162,9 +162,9 @@ static EDA_HOTKEY HkAddGraphicPolyLine( _HKI( "Add Graphic PolyLine" ), HK_ADD_G 'I', ID_LINE_COMMENT_BUTT ); static EDA_HOTKEY HkAddGraphicText( _HKI( "Add Graphic Text" ), HK_ADD_GRAPHIC_TEXT, 'T', ID_TEXT_COMMENT_BUTT ); -static EDA_HOTKEY HkMirrorY( _HKI( "Mirror Y Component" ), HK_MIRROR_Y_COMPONENT, 'Y', +static EDA_HOTKEY HkMirrorY( _HKI( "Mirror Y" ), HK_MIRROR_Y, 'Y', ID_SCH_MIRROR_Y ); -static EDA_HOTKEY HkMirrorX( _HKI( "Mirror X Component" ), HK_MIRROR_X_COMPONENT, 'X', +static EDA_HOTKEY HkMirrorX( _HKI( "Mirror X" ), HK_MIRROR_X, 'X', ID_SCH_MIRROR_X ); static EDA_HOTKEY HkOrientNormalComponent( _HKI( "Orient Normal Component" ), HK_ORIENT_NORMAL_COMPONENT, 'N', ID_SCH_ORIENT_NORMAL ); @@ -556,8 +556,8 @@ bool SCH_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition, case HK_EDIT_COMPONENT_VALUE: // Edit component value field. case HK_EDIT_COMPONENT_REFERENCE: // Edit component value reference. case HK_EDIT_COMPONENT_FOOTPRINT: // Edit component footprint field. - case HK_MIRROR_Y_COMPONENT: // Mirror Y - case HK_MIRROR_X_COMPONENT: // Mirror X + case HK_MIRROR_Y: // Mirror Y + case HK_MIRROR_X: // Mirror X case HK_ORIENT_NORMAL_COMPONENT: // Orient 0, no mirror (Component) case HK_ROTATE: // Rotate schematic item. case HK_EDIT_COMPONENT_WITH_LIBEDIT: // Call Libedit and load the current component diff --git a/eeschema/hotkeys.h b/eeschema/hotkeys.h index 5bbe561f4a..38f3f60b62 100644 --- a/eeschema/hotkeys.h +++ b/eeschema/hotkeys.h @@ -51,8 +51,8 @@ enum hotkey_id_commnand { HK_EDIT_COMPONENT_REFERENCE, HK_EDIT_COMPONENT_FOOTPRINT, HK_EDIT_COMPONENT_WITH_LIBEDIT, - HK_MIRROR_X_COMPONENT, - HK_MIRROR_Y_COMPONENT, + HK_MIRROR_X, + HK_MIRROR_Y, HK_ORIENT_NORMAL_COMPONENT, HK_MOVE_COMPONENT_OR_ITEM, HK_COPY_COMPONENT_OR_LABEL, diff --git a/eeschema/lib_field.cpp b/eeschema/lib_field.cpp index 814799bdd1..3cbc198ba5 100644 --- a/eeschema/lib_field.cpp +++ b/eeschema/lib_field.cpp @@ -100,15 +100,6 @@ bool LIB_FIELD::Save( OUTPUTFORMATTER& aFormatter ) else if( m_VJustify == GR_TEXT_VJUSTIFY_TOP ) vjustify = 'T'; - /* Dick 24-May-2013: - What the hell is this?. There was no comment here. - Hell no. You don't want this in the *.lib files, it is crap. Fields get read - back in and they have a tilda in them. - - if( text.IsEmpty() ) - text = wxT( "~" ); - */ - aFormatter.Print( 0, "F%d %s %d %d %d %c %c %c %c%c%c", m_id, EscapedUTF8( text ).c_str(), // wraps in quotes diff --git a/eeschema/onrightclick.cpp b/eeschema/onrightclick.cpp index cf3358c859..310910b4b6 100644 --- a/eeschema/onrightclick.cpp +++ b/eeschema/onrightclick.cpp @@ -373,9 +373,9 @@ void AddMenusForComponent( wxMenu* PopMenu, SCH_COMPONENT* Component, PART_LIBS* AddMenuItem( orientmenu, ID_SCH_ROTATE_CLOCKWISE, msg, KiBitmap( rotate_cw_xpm ) ); AddMenuItem( orientmenu, ID_SCH_ROTATE_COUNTERCLOCKWISE, _( "Rotate Counterclockwise" ), KiBitmap( rotate_ccw_xpm ) ); - msg = AddHotkeyName( _( "Mirror --" ), g_Schematic_Hokeys_Descr, HK_MIRROR_X_COMPONENT ); + msg = AddHotkeyName( _( "Mirror --" ), g_Schematic_Hokeys_Descr, HK_MIRROR_X ); AddMenuItem( orientmenu, ID_SCH_MIRROR_X, msg, KiBitmap( mirror_v_xpm ) ); - msg = AddHotkeyName( _( "Mirror ||" ), g_Schematic_Hokeys_Descr, HK_MIRROR_Y_COMPONENT ); + msg = AddHotkeyName( _( "Mirror ||" ), g_Schematic_Hokeys_Descr, HK_MIRROR_Y ); AddMenuItem( orientmenu, ID_SCH_MIRROR_Y, msg, KiBitmap( mirror_h_xpm ) ); msg = AddHotkeyName( _( "Normal" ), g_Schematic_Hokeys_Descr, HK_ORIENT_NORMAL_COMPONENT ); AddMenuItem( orientmenu, ID_SCH_ORIENT_NORMAL, msg, KiBitmap( normal_xpm ) ); @@ -757,6 +757,21 @@ void AddMenusForHierchicalSheet( wxMenu* PopMenu, SCH_SHEET* Sheet ) msg = AddHotkeyName( _( "Drag Sheet" ), g_Schematic_Hokeys_Descr, HK_DRAG ); AddMenuItem( PopMenu, ID_SCH_DRAG_ITEM, msg, KiBitmap( move_sheet_xpm ) ); + + wxMenu* orientmenu = new wxMenu; + msg = AddHotkeyName( _( "Rotate Sheet CW" ), g_Schematic_Hokeys_Descr, HK_ROTATE ); + AddMenuItem( orientmenu, ID_SCH_ROTATE_CLOCKWISE, msg, KiBitmap( rotate_cw_xpm ) ); + + AddMenuItem( orientmenu, ID_SCH_ROTATE_COUNTERCLOCKWISE, _( "Rotate Sheet CCW" ), + KiBitmap( rotate_ccw_xpm ) ); + + msg = AddHotkeyName( _( "Mirror --" ), g_Schematic_Hokeys_Descr, HK_MIRROR_X ); + AddMenuItem( orientmenu, ID_SCH_MIRROR_X, msg, KiBitmap( mirror_v_xpm ) ); + msg = AddHotkeyName( _( "Mirror ||" ), g_Schematic_Hokeys_Descr, HK_MIRROR_Y ); + AddMenuItem( orientmenu, ID_SCH_MIRROR_Y, msg, KiBitmap( mirror_h_xpm ) ); + + AddMenuItem( PopMenu, orientmenu, ID_POPUP_SCH_GENERIC_ORIENT_CMP, + _( "Orient Sheet" ), KiBitmap( orient_xpm ) ); } if( Sheet->GetFlags() ) @@ -831,10 +846,10 @@ void AddMenusForBlock( wxMenu* PopMenu, SCH_EDIT_FRAME* frame ) AddMenuItem( PopMenu, ID_POPUP_DRAG_BLOCK, msg, KiBitmap( move_xpm ) ); AddMenuItem( PopMenu, ID_POPUP_DELETE_BLOCK, _( "Delete Block" ), KiBitmap( delete_xpm ) ); msg = AddHotkeyName( _( "Mirror Block ||" ), g_Schematic_Hokeys_Descr, - HK_MIRROR_Y_COMPONENT ); + HK_MIRROR_Y ); AddMenuItem( PopMenu, ID_SCH_MIRROR_Y, msg, KiBitmap( mirror_h_xpm ) ); msg = AddHotkeyName( _( "Mirror Block --" ), g_Schematic_Hokeys_Descr, - HK_MIRROR_X_COMPONENT ); + HK_MIRROR_X ); AddMenuItem( PopMenu, ID_SCH_MIRROR_X, msg, KiBitmap( mirror_v_xpm ) ); msg = AddHotkeyName( _( "Rotate Block CCW" ), g_Schematic_Hokeys_Descr, HK_ROTATE ); AddMenuItem( PopMenu, ID_SCH_ROTATE_CLOCKWISE, msg, KiBitmap( rotate_ccw_xpm ) ); @@ -871,10 +886,10 @@ void AddMenusForBitmap( wxMenu* aPopMenu, SCH_BITMAP * aBitmap ) msg = AddHotkeyName( _( "Rotate Image" ), g_Schematic_Hokeys_Descr, HK_ROTATE ); AddMenuItem( aPopMenu, ID_SCH_ROTATE_CLOCKWISE, msg, KiBitmap( rotate_ccw_xpm ) ); msg = AddHotkeyName( _( "Mirror --" ), g_Schematic_Hokeys_Descr, - HK_MIRROR_X_COMPONENT ); + HK_MIRROR_X ); AddMenuItem( aPopMenu, ID_SCH_MIRROR_X, msg, KiBitmap( mirror_v_xpm ) ); msg = AddHotkeyName( _( "Mirror ||" ), g_Schematic_Hokeys_Descr, - HK_MIRROR_Y_COMPONENT ); + HK_MIRROR_Y ); AddMenuItem( aPopMenu, ID_SCH_MIRROR_Y, msg, KiBitmap( mirror_h_xpm ) ); msg = AddHotkeyName( _( "Edit Image" ), g_Schematic_Hokeys_Descr, HK_EDIT ); AddMenuItem( aPopMenu, ID_SCH_EDIT_ITEM, msg, KiBitmap( image_xpm ) ); diff --git a/eeschema/sch_collectors.cpp b/eeschema/sch_collectors.cpp index f2da340247..45905018d3 100644 --- a/eeschema/sch_collectors.cpp +++ b/eeschema/sch_collectors.cpp @@ -194,6 +194,7 @@ const KICAD_T SCH_COLLECTOR::SheetsAndSheetLabels[] = { const KICAD_T SCH_COLLECTOR::OrientableItems[] = { SCH_COMPONENT_T, SCH_BITMAP_T, + SCH_SHEET_T, EOT }; diff --git a/eeschema/sch_component.cpp b/eeschema/sch_component.cpp index ff7734e4bc..75496d4605 100644 --- a/eeschema/sch_component.cpp +++ b/eeschema/sch_component.cpp @@ -148,8 +148,18 @@ SCH_COMPONENT::SCH_COMPONENT( LIB_PART& aPart, SCH_SHEET_PATH* sheet, int unit, if( it->GetName().IsEmpty() ) continue; - // See if field by same name already exists. - SCH_FIELD* schField = FindField( it->GetName() ); + // See if field already exists (mandatory fields always exist). + // for mandatory fields, the name and field id are fixed, so we use the + // known and fixed id to get them (more reliable than names, which can be translated) + // for other fields (custom fields), locate the field by same name + // (field id has no known meaning for custom fields) + int idx = it->GetId(); + SCH_FIELD* schField; + + if( idx < MANDATORY_FIELDS ) + schField = GetField( idx ); + else + schField = FindField( it->GetName() ); if( !schField ) { @@ -158,9 +168,7 @@ SCH_COMPONENT::SCH_COMPONENT( LIB_PART& aPart, SCH_SHEET_PATH* sheet, int unit, } schField->SetTextPosition( m_Pos + it->GetTextPosition() ); - schField->ImportValues( *it ); - schField->SetText( it->GetText() ); } @@ -232,7 +240,7 @@ void SCH_COMPONENT::Init( const wxPoint& pos ) AddField( field ); } - m_prefix = wxString( _( "U" ) ); + m_prefix = wxString( wxT( "U" ) ); } diff --git a/eeschema/schedit.cpp b/eeschema/schedit.cpp index 8e0df2b4d3..29227ce6ed 100644 --- a/eeschema/schedit.cpp +++ b/eeschema/schedit.cpp @@ -1,9 +1,9 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2013 Jean-Pierre Charras, jp.charras at wanadoo.fr + * Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2008-2013 Wayne Stambaugh - * Copyright (C) 2004-2013 KiCad Developers, see change_log.txt for contributors. + * Copyright (C) 2004-2015 KiCad Developers, see change_log.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -457,14 +457,12 @@ void SCH_EDIT_FRAME::OnMoveItem( wxCommandEvent& aEvent ) case SCH_MARKER_T: // Moving a marker has no sense - wxFAIL_MSG( wxString::Format( wxT( "Cannot move item type %s" ), - GetChars( item->GetClass() ) ) ); break; default: // Unknown items cannot be moved wxFAIL_MSG( wxString::Format( - wxT( "Cannot move unknown item type %d" ), item->Type() ) ); + wxT( "Cannot move item type %d" ), item->Type() ) ); break; } @@ -841,8 +839,25 @@ void SCH_EDIT_FRAME::OnRotate( wxCommandEvent& aEvent ) RotateImage( (SCH_BITMAP*) item ); break; - case SCH_SHEET_T: /// @todo allow sheet rotate on hotkey + case SCH_SHEET_T: + if( !item->IsNew() ) // rotate a sheet during its creation has no sense + { + bool retCCW = ( aEvent.GetId() == ID_SCH_ROTATE_COUNTERCLOCKWISE ); + RotateHierarchicalSheet( static_cast( item ), retCCW ); + } + + break; + + case SCH_JUNCTION_T: + case SCH_NO_CONNECT_T: + // these items are not rotated, because rotation does not change them. + break; + default: + // Other items (wires...) cannot be rotated, at least during creation + if( item->IsNew() ) + break; + wxFAIL_MSG( wxString::Format( wxT( "Cannot rotate schematic item type %s." ), GetChars( item->GetClass() ) ) ); } @@ -1112,6 +1127,14 @@ void SCH_EDIT_FRAME::OnOrient( wxCommandEvent& aEvent ) break; + case SCH_SHEET_T: + if( aEvent.GetId() == ID_SCH_MIRROR_X ) + MirrorSheet( (SCH_SHEET*) item, true ); + else if( aEvent.GetId() == ID_SCH_MIRROR_Y ) + MirrorSheet( (SCH_SHEET*) item, false ); + + break; + default: wxFAIL_MSG( wxString::Format( wxT( "Schematic object type %s cannot be oriented." ), GetChars( item->GetClass() ) ) ); diff --git a/eeschema/schframe.h b/eeschema/schframe.h index 587d69e367..93b09cc23d 100644 --- a/eeschema/schframe.h +++ b/eeschema/schframe.h @@ -930,6 +930,25 @@ private: SCH_SHEET* CreateSheet( wxDC* DC ); void ReSizeSheet( SCH_SHEET* Sheet, wxDC* DC ); + /** + * Rotate a sheet on itself. Sheets do not have a anchor point. + * Because rotating it from its origin or its end is not friendly, + * Rotation is made around its centre + * @param aSheet the hierarchical sheet to rotate + * @param aRotCCW = true to rotate CCW, false to rotate CW + */ + void RotateHierarchicalSheet( SCH_SHEET* aSheet, bool aRotCCW ); + + /** + * Function MirrorSheet + * Mirror a hierarchical sheet + * Mirroring is made around its centre + * @param aSheet = the SCH_SHEET to mirror + * @param aFromXaxis = true to mirror relative to Horizontal axis + * false to mirror relative to vertical axis + */ + void MirrorSheet( SCH_SHEET* aSheet, bool aFromXaxis ); + /// Loads the cache library associated to the aFileName bool LoadCacheLibrary( const wxString& aFileName ); diff --git a/eeschema/sheet.cpp b/eeschema/sheet.cpp index 8254ef4eea..b13266f2b6 100644 --- a/eeschema/sheet.cpp +++ b/eeschema/sheet.cpp @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2006 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com + * Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2004-2011 KiCad Developers, see change_log.txt for contributors. * * This program is free software; you can redistribute it and/or @@ -392,3 +392,52 @@ void SCH_EDIT_FRAME::ReSizeSheet( SCH_SHEET* aSheet, wxDC* aDC ) SetUndoItem( aSheet ); } +#define GRID_SIZE_REF 50 +void SCH_EDIT_FRAME::RotateHierarchicalSheet( SCH_SHEET* aSheet, bool aRotCCW ) +{ + if( aSheet == NULL ) + return; + + // Save old sheet in undo list if not already in edit, or moving. + if( aSheet->GetFlags() == 0 ) + SaveCopyInUndoList( aSheet, UR_CHANGED ); + + // Rotate the sheet on itself. Sheets do not have a anchor point. + // Rotation is made around it center + wxPoint rotPoint = aSheet->GetBoundingBox().Centre(); + + // rotate CCW, or CW. to rotate CW, rotate 3 times + aSheet->Rotate( rotPoint ); + + if( !aRotCCW ) + { + aSheet->Rotate( rotPoint ); + aSheet->Rotate( rotPoint ); + } + + GetCanvas()->Refresh(); + OnModify(); +} + + +void SCH_EDIT_FRAME::MirrorSheet( SCH_SHEET* aSheet, bool aFromXaxis ) +{ + if( aSheet == NULL ) + return; + + // Save old sheet in undo list if not already in edit, or moving. + if( aSheet->GetFlags() == 0 ) + SaveCopyInUndoList( aSheet, UR_CHANGED ); + + // Mirror the sheet on itself. Sheets do not have a anchor point. + // Mirroring is made around it center + wxPoint mirrorPoint = aSheet->GetBoundingBox().Centre(); + + if( aFromXaxis ) // mirror relative to Horizontal axis + aSheet->MirrorX( mirrorPoint.y ); + else // Mirror relative to vertical axis + aSheet->MirrorY( mirrorPoint.x ); + + GetCanvas()->Refresh(); + OnModify(); +} diff --git a/eeschema/template_fieldnames.cpp b/eeschema/template_fieldnames.cpp index a2077e3e89..95acf69d94 100644 --- a/eeschema/template_fieldnames.cpp +++ b/eeschema/template_fieldnames.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2010 SoftPLC Corporation, Dick Hollenbeck - * Copyright (C) 2014 KiCad Developers, see CHANGELOG.TXT for contributors. + * Copyright (C) 2015 KiCad Developers, see CHANGELOG.TXT for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -29,27 +29,32 @@ using namespace TFIELD_T; -wxString TEMPLATE_FIELDNAME::GetDefaultFieldName( int aFieldNdx ) +const wxString TEMPLATE_FIELDNAME::GetDefaultFieldName( int aFieldNdx ) { // Fixed values for the first few default fields used by EESCHEMA - static const wxString fixedNames[] = { - _( "Reference" ), // The component reference, R1, C1, etc. - _( "Value" ), // The component value + name - _( "Footprint" ), // The footprint for use with Pcbnew - _( "Datasheet" ), // Link to a datasheet for component - }; - - if( (unsigned) aFieldNdx < DIM(fixedNames) ) - return fixedNames[aFieldNdx]; - - else + // (mandatory fields) + switch( aFieldNdx ) { - wxString fieldName = _( "Field" ); + case REFERENCE: + return _( "Reference" ); // The component reference, R1, C1, etc. - fieldName << aFieldNdx; + case VALUE: + return _( "Value" ); // The component value + name - return fieldName; + case FOOTPRINT: + return _( "Footprint" ); // The footprint for use with Pcbnew + + case DATASHEET: + return _( "Datasheet" ); // Link to a datasheet for component + + default: + break; } + + // Other fields are use fields, give a default name: + wxString fieldName = _( "Field" ); + fieldName << aFieldNdx; + return fieldName; } void TEMPLATE_FIELDNAME::Format( OUTPUTFORMATTER* out, int nestLevel ) const throw( IO_ERROR ) diff --git a/eeschema/template_fieldnames.h b/eeschema/template_fieldnames.h index 248df58856..130ab14712 100644 --- a/eeschema/template_fieldnames.h +++ b/eeschema/template_fieldnames.h @@ -120,7 +120,7 @@ struct TEMPLATE_FIELDNAME * These fieldnames are not modifiable, but template fieldnames are. * @param aFieldNdx The field number index, > 0 */ - static wxString GetDefaultFieldName( int aFieldNdx ); + static const wxString GetDefaultFieldName( int aFieldNdx ); }; typedef std::vector< TEMPLATE_FIELDNAME > TEMPLATE_FIELDNAMES; diff --git a/pcbnew/class_footprint_wizard.cpp b/pcbnew/class_footprint_wizard.cpp index 10461e4c79..bbc2318f82 100644 --- a/pcbnew/class_footprint_wizard.cpp +++ b/pcbnew/class_footprint_wizard.cpp @@ -53,7 +53,7 @@ FOOTPRINT_WIZARD* FOOTPRINT_WIZARDS::GetWizard( int aIndex ) FOOTPRINT_WIZARD* FOOTPRINT_WIZARDS::GetWizard( wxString aName ) { - int max = GetSize(); + int max = GetWizardsCount(); for( int i = 0; i m_FootprintWizards; + public: /** @@ -151,7 +151,6 @@ public: * into the system wizards * * @param aWizard is the footprint wizard to be registered - * */ static void register_wizard( FOOTPRINT_WIZARD* aWizard ); @@ -162,7 +161,6 @@ public: * and deleted * * @param aObject is the footprint wizard object to be deregistered - * */ static bool deregister_object( void* aObject ); @@ -170,7 +168,6 @@ public: * Function GetWizard * @param aName is the footprint wizard name * @return a wizard object by it's name or NULL if it isn't available. - * */ static FOOTPRINT_WIZARD* GetWizard( wxString aName ); @@ -178,15 +175,14 @@ public: * Function GetWizard * @return a wizard object by it's number or NULL if it isn't available. * @param aIndex is the wizard index in list - * */ static FOOTPRINT_WIZARD* GetWizard( int aIndex ); /** - * Function GetSize + * Function GetWizardsCount * @return the number of wizards available into the system */ - static int GetSize(); + static int GetWizardsCount(); }; #endif /* PCBNEW_FOOTPRINT_WIZARDS_H */ diff --git a/pcbnew/dialogs/dialog_footprint_wizard_list.cpp b/pcbnew/dialogs/dialog_footprint_wizard_list.cpp index 858b372a07..d012c2abdb 100644 --- a/pcbnew/dialogs/dialog_footprint_wizard_list.cpp +++ b/pcbnew/dialogs/dialog_footprint_wizard_list.cpp @@ -41,7 +41,7 @@ DIALOG_FOOTPRINT_WIZARD_LIST::DIALOG_FOOTPRINT_WIZARD_LIST( wxWindow* aParent ) : DIALOG_FOOTPRINT_WIZARD_LIST_BASE( aParent ) { - int n_wizards = FOOTPRINT_WIZARDS::GetSize(); + int n_wizards = FOOTPRINT_WIZARDS::GetWizardsCount(); // Current wizard selection, empty or first m_FootprintWizard = NULL;