1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275
|
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2004-2018 KiCad Developers, see AUTHORS.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
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <wx/tooltip.h>
#include <wx/hyperlink.h>
#include <wx/url.h>
#include <fctsys.h>
#include <pgm_base.h>
#include <kiway.h>
#include <class_drawpanel.h>
#include <confirm.h>
#include <sch_edit_frame.h>
#include <base_units.h>
#include <sch_reference_list.h>
#include <class_library.h>
#include <sch_component.h>
#include <dialog_helpers.h>
#include <sch_validators.h>
#include <kicad_device_context.h>
#include <symbol_lib_table.h>
#include <bitmaps.h>
#include <dialog_edit_component_in_schematic_base.h>
#include <invoke_sch_dialog.h>
#ifdef KICAD_SPICE
#include <dialog_spice_model.h>
#include <netlist_exporter_pspice.h>
#endif /* KICAD_SPICE */
#include "common.h"
#include "eda_doc.h"
#include <list>
/**
* Dialog used to edit #SCH_COMPONENT objects in a schematic.
*
* This is derived from DIALOG_EDIT_COMPONENT_IN_SCHEMATIC_BASE which is maintained by
* wxFormBuilder. Do not auto-generate this class or file, it is hand coded.
*/
class DIALOG_EDIT_COMPONENT_IN_SCHEMATIC : public DIALOG_EDIT_COMPONENT_IN_SCHEMATIC_BASE
{
public:
DIALOG_EDIT_COMPONENT_IN_SCHEMATIC( SCH_EDIT_FRAME* aParent );
/**
* Initialize controls with \a aComponent.
*.
* @param aComponent The component to edit.
*/
void InitBuffers( SCH_COMPONENT* aComponent );
SCH_EDIT_FRAME* GetParent() { return dynamic_cast< SCH_EDIT_FRAME* >( wxDialog::GetParent() ); }
private:
friend class SCH_EDIT_FRAME;
SCH_COMPONENT* m_cmp;
LIB_PART* m_part;
bool m_skipCopyFromPanel;
static int s_SelectedRow;
/// a copy of the edited symbol's SCH_FIELDs
SCH_FIELDS m_FieldsBuf;
void setSelectedFieldNdx( int aFieldNdx );
int getSelectedFieldNdx();
/**
* Sets the values displayed on the panel according to the currently selected field row.
*/
void copySelectedFieldToPanel();
/**
* Copy the values displayed on the panel fields to the currently selected field.
*
* @return bool - true if all fields are OK, else false if the user has put
* bad data into a field, and this value can be used to deny a row change.
*/
bool copyPanelToSelectedField();
void copyOptionsToPanel();
void copyPanelToOptions();
void setRowItem( int aFieldNdx, const wxString& aName, const wxString& aValue );
void setRowItem( int aFieldNdx, const SCH_FIELD& aField )
{
// Use default field name for mandatory fields, because they are transalted
// according to the current locale
wxString f_name;
if( aFieldNdx < MANDATORY_FIELDS )
f_name = TEMPLATE_FIELDNAME::GetDefaultFieldName( aFieldNdx );
else
f_name = aField.GetName( false );
setRowItem( aFieldNdx, f_name, aField.GetText() );
}
// event handlers
void OnCloseDialog( wxCloseEvent& event ) override;
void OnListItemDeselected( wxListEvent& event ) override;
void OnListItemSelected( wxListEvent& event ) override;
void OnCancelButtonClick( wxCommandEvent& event ) override;
void OnOKButtonClick( wxCommandEvent& event ) override;
void SetInitCmp( wxCommandEvent& event ) override;
void UpdateFields( wxCommandEvent& event ) override;
void addFieldButtonHandler( wxCommandEvent& event ) override;
void deleteFieldButtonHandler( wxCommandEvent& event ) override;
void moveUpButtonHandler( wxCommandEvent& event ) override;
void moveDownButtonHandler( wxCommandEvent& event ) override;
void showButtonHandler( wxCommandEvent& event ) override;
void OnTestChipName( wxCommandEvent& event ) override;
void OnSelectChipName( wxCommandEvent& event ) override;
void OnSizeFieldsList( wxSizeEvent& event ) override;
void OnInitDlg( wxInitDialogEvent& event ) override
{
TransferDataToWindow();
// Now all widgets have the size fixed, call FinishDialogSettings
FinishDialogSettings();
}
void EditSpiceModel( wxCommandEvent& event ) override;
SCH_FIELD* findField( const wxString& aFieldName );
/**
* Update the listbox showing fields according to the field's text.
*
* This must be called after a text change in fields if this change is not an edition.
*/
void updateDisplay()
{
fieldListCtrl->DeleteAllItems();
for( unsigned ii = 0; ii < m_FieldsBuf.size(); ii++ )
setRowItem( ii, m_FieldsBuf[ii] );
}
};
int DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::s_SelectedRow;
void SCH_EDIT_FRAME::EditComponent( SCH_COMPONENT* aComponent )
{
wxCHECK_RET( aComponent != NULL && aComponent->Type() == SCH_COMPONENT_T,
wxT( "Invalid component object pointer. Bad Programmer!" ) );
m_canvas->SetIgnoreMouseEvents( true );
DIALOG_EDIT_COMPONENT_IN_SCHEMATIC* dlg = new DIALOG_EDIT_COMPONENT_IN_SCHEMATIC( this );
dlg->InitBuffers( aComponent );
// make sure the chipnameTextCtrl is wide enough to hold any unusually long chip names:
EnsureTextCtrlWidth( dlg->chipnameTextCtrl );
// This dialog itself subsequently can invoke a KIWAY_PLAYER as a quasimodal
// frame. Therefore this dialog as a modal frame parent, MUST be run under
// quasimodal mode for the quasimodal frame support to work. So don't use
// the QUASIMODAL macros here.
int ret = dlg->ShowQuasiModal();
if( m_autoplaceFields )
aComponent->AutoAutoplaceFields( GetScreen() );
m_canvas->SetIgnoreMouseEvents( false );
m_canvas->MoveCursorToCrossHair();
dlg->Destroy();
if( ret == wxID_OK )
GetCanvas()->Refresh();
}
DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::DIALOG_EDIT_COMPONENT_IN_SCHEMATIC( SCH_EDIT_FRAME* aParent ) :
DIALOG_EDIT_COMPONENT_IN_SCHEMATIC_BASE( aParent )
{
#ifndef KICAD_SPICE
spiceFieldsButton->Hide();
#endif /* not KICAD_SPICE */
m_cmp = NULL;
m_part = NULL;
m_skipCopyFromPanel = false;
wxListItem columnLabel;
columnLabel.SetImage( -1 );
columnLabel.SetText( _( "Name" ) );
fieldListCtrl->InsertColumn( 0, columnLabel );
columnLabel.SetText( _( "Value" ) );
fieldListCtrl->InsertColumn( 1, columnLabel );
m_staticTextUnitSize->SetLabel( GetAbbreviatedUnitsLabel( g_UserUnit ) );
m_staticTextUnitPosX->SetLabel( GetAbbreviatedUnitsLabel( g_UserUnit ) );
m_staticTextUnitPosY->SetLabel( GetAbbreviatedUnitsLabel( g_UserUnit ) );
wxToolTip::Enable( true );
stdDialogButtonSizerOK->SetDefault();
// Configure button logos
addFieldButton->SetBitmap( KiBitmap( plus_xpm ) );
deleteFieldButton->SetBitmap( KiBitmap( minus_xpm ) );
moveUpButton->SetBitmap( KiBitmap( go_up_xpm ) );
moveDownButton->SetBitmap( KiBitmap( go_down_xpm ) );
Fit();
}
void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::OnListItemDeselected( wxListEvent& event )
{
if( !m_skipCopyFromPanel )
{
if( !copyPanelToSelectedField() )
event.Skip(); // do not go to the next row
}
}
void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::OnTestChipName( wxCommandEvent& event )
{
LIB_ID id;
wxString msg;
wxString partname = chipnameTextCtrl->GetValue();
id.Parse( partname, LIB_ID::ID_SCH );
if( !id.IsValid() )
{
msg.Printf( _( "\"%s\" is not a valid library symbol identifier." ), partname );
DisplayError( this, msg );
return;
}
LIB_ALIAS* alias = NULL;
try
{
alias = Prj().SchSymbolLibTable()->LoadSymbol( id );
}
catch( ... )
{
}
if( !alias )
{
msg.Printf( _( "Symbol \"%s\" not found in library \"%s\"" ),
id.GetLibItemName().wx_str(), id.GetLibNickname().wx_str() );
DisplayError( this, msg );
return;
}
msg.Printf( _( "Symbol \"%s\" found in library \"%s\"" ),
id.GetLibItemName().wx_str(), id.GetLibNickname().wx_str() );
DisplayInfoMessage( this, msg );
}
void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::OnSelectChipName( wxCommandEvent& event )
{
SCH_BASE_FRAME::HISTORY_LIST dummy;
auto sel = GetParent()->SelectComponentFromLibrary( NULL, dummy, true, 0, 0, false );
if( !sel.LibId.IsValid() )
return;
chipnameTextCtrl->SetValue( sel.LibId.Format() );
// Update the value field for Power symbols
LIB_PART* entry = GetParent()->GetLibPart( sel.LibId );
if( entry && entry->IsPower() )
{
m_FieldsBuf[VALUE].SetText( sel.LibId.GetLibItemName() );
setRowItem( VALUE, m_FieldsBuf[VALUE] );
if( s_SelectedRow == VALUE )
copySelectedFieldToPanel();
}
}
void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::EditSpiceModel( wxCommandEvent& event )
{
#ifdef KICAD_SPICE
setSelectedFieldNdx( 0 );
DIALOG_SPICE_MODEL dialog( this, *m_cmp, m_FieldsBuf );
if( dialog.ShowModal() == wxID_OK )
updateDisplay();
#endif /* KICAD_SPICE */
}
void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::OnListItemSelected( wxListEvent& event )
{
// remember the selected row, statically
s_SelectedRow = event.GetIndex();
copySelectedFieldToPanel();
}
void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::OnCloseDialog( wxCloseEvent& event )
{
// On wxWidgets 2.8, and on Linux, calling EndQuasiModal here is mandatory
// Otherwise, the main event loop is never restored, and Eeschema does not
// respond to any event, because the DIALOG_SHIM destructor is never called.
// On wxWidgets 3.0, or on Windows, the DIALOG_SHIM destructor is called,
// and calls EndQuasiModal.
// therefore calling EndQuasiModal here is not always mandatory but it creates no issues
EndQuasiModal( wxID_CANCEL );
}
void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::OnCancelButtonClick( wxCommandEvent& event )
{
EndQuasiModal( wxID_CANCEL );
}
void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::copyPanelToOptions()
{
LIB_ID id;
wxString msg;
wxString tmp = chipnameTextCtrl->GetValue();
tmp.Replace( wxT( " " ), wxT( "_" ) );
id.Parse( tmp, LIB_ID::ID_SCH );
// Save current flags which could be modified by next change settings
STATUS_FLAGS flags = m_cmp->GetFlags();
if( !id.IsValid() )
{
msg.Printf( _( "Symbol library identifier \"%s\" is not valid!" ), tmp );
DisplayError( this, msg );
}
else if( id != m_cmp->GetLibId() )
{
LIB_ALIAS* alias = NULL;
try
{
alias = Prj().SchSymbolLibTable()->LoadSymbol( id );
}
catch( ... )
{
}
if( !alias )
{
msg.Printf( _( "Symbol \"%s\" not found in library \"%s\"!" ),
id.GetLibItemName().wx_str(), id.GetLibNickname().wx_str() );
DisplayError( this, msg );
}
else // Change symbol from lib!
{
m_cmp->SetLibId( id, Prj().SchSymbolLibTable(), Prj().SchLibs()->GetCacheLibrary() );
}
}
// For symbols with multiple shapes (De Morgan representation) Set the selected shape:
if( convertCheckBox->IsEnabled() )
{
m_cmp->SetConvert( convertCheckBox->GetValue() ? 2 : 1 );
}
//Set the part selection in multiple part per package
if( m_cmp->GetUnitCount() > 1 )
{
int unit_selection = unitChoice->GetCurrentSelection() + 1;
m_cmp->SetUnitSelection( &GetParent()->GetCurrentSheet(), unit_selection );
m_cmp->SetUnit( unit_selection );
}
switch( orientationRadioBox->GetSelection() )
{
case 0:
m_cmp->SetOrientation( CMP_ORIENT_0 );
break;
case 1:
m_cmp->SetOrientation( CMP_ORIENT_90 );
break;
case 2:
m_cmp->SetOrientation( CMP_ORIENT_180 );
break;
case 3:
m_cmp->SetOrientation( CMP_ORIENT_270 );
break;
}
int mirror = mirrorRadioBox->GetSelection();
switch( mirror )
{
case 0:
break;
case 1:
m_cmp->SetOrientation( CMP_MIRROR_X );
break;
case 2:
m_cmp->SetOrientation( CMP_MIRROR_Y );
break;
}
// Restore m_Flag modified by SetUnit() and other change settings
m_cmp->ClearFlags();
m_cmp->SetFlags( flags );
}
void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::OnOKButtonClick( wxCommandEvent& event )
{
bool removeRemainingFields = false;
if( !copyPanelToSelectedField() )
return;
if( ! SCH_COMPONENT::IsReferenceStringValid( m_FieldsBuf[REFERENCE].GetText() ) )
{
DisplayError( NULL, _( "Illegal reference. References must start with a letter" ) );
return;
}
// save old cmp in undo list if not already in edit, or moving ...
// or the component to be edited is part of a block
if( m_cmp->GetFlags() == 0
|| GetParent()->GetScreen()->m_BlockLocate.GetState() != STATE_NO_BLOCK )
GetParent()->SaveCopyInUndoList( m_cmp, UR_CHANGED );
copyPanelToOptions();
// Delete any fields with no name before we copy all of m_FieldsBuf back into the component.
for( unsigned i = MANDATORY_FIELDS; i<m_FieldsBuf.size(); )
{
if( m_FieldsBuf[i].GetName( false ).IsEmpty() || m_FieldsBuf[i].GetText().IsEmpty() )
{
// If a field has no value and is not it the field template list, warn the user
// that it will be remove from the component. This gives the user a chance to
// correct the problem before removing the undefined fields. It should also
// resolve most of the bug reports and questions regarding missing fields.
if( !m_FieldsBuf[i].GetName( false ).IsEmpty() && m_FieldsBuf[i].GetText().IsEmpty()
&& !GetParent()->GetTemplates().HasFieldName( m_FieldsBuf[i].GetName( false ) )
&& !removeRemainingFields )
{
wxString msg = wxString::Format(
_( "The field name \"%s\" does not have a value and is not defined in "
"the field template list. Empty field values are invalid an will "
"be removed from the component. Do you wish to remove this and "
"all remaining undefined fields?" ),
GetChars( m_FieldsBuf[i].GetName( false ) )
);
wxMessageDialog dlg( this, msg, _( "Remove Fields" ), wxYES_NO | wxNO_DEFAULT );
if( dlg.ShowModal() == wxID_NO )
return;
removeRemainingFields = true;
}
m_FieldsBuf.erase( m_FieldsBuf.begin() + i );
continue;
}
++i;
}
// change all field positions from relative to absolute
for( unsigned i = 0; i<m_FieldsBuf.size(); ++i )
{
m_FieldsBuf[i].Offset( m_cmp->m_Pos );
}
LIB_PART* entry = GetParent()->GetLibPart( m_cmp->GetLibId() );
if( entry && entry->IsPower() )
m_FieldsBuf[VALUE].SetText( m_cmp->GetLibId().GetLibItemName() );
// copy all the fields back, and change the length of m_Fields.
m_cmp->SetFields( m_FieldsBuf );
// Reference has a specific initialization, depending on the current active sheet
// because for a given component, in a complex hierarchy, there are more than one
// reference.
m_cmp->SetRef( &GetParent()->GetCurrentSheet(), m_FieldsBuf[REFERENCE].GetText() );
// The value, footprint and datasheet fields should be kept in sync in multi-unit
// parts.
if( m_cmp->GetUnitCount() > 1 )
{
const LIB_ID thisLibId = m_cmp->GetLibId();
const wxString thisRef = m_cmp->GetRef( &( GetParent()->GetCurrentSheet() ) );
int thisUnit = m_cmp->GetUnit();
SCH_REFERENCE_LIST components;
GetParent()->GetCurrentSheet().GetComponents( components );
for( unsigned i = 0; i < components.GetCount(); i++ )
{
SCH_REFERENCE component = components[i];
if( component.GetLibPart()->GetLibId() == thisLibId
&& component.GetRef() == thisRef
&& component.GetUnit() != thisUnit )
{
SCH_COMPONENT* otherUnit = component.GetComp();
GetParent()->SaveCopyInUndoList( otherUnit, UR_CHANGED, true /* append */);
otherUnit->GetField( VALUE )->SetText( m_FieldsBuf[VALUE].GetText() );
otherUnit->GetField( FOOTPRINT )->SetText( m_FieldsBuf[FOOTPRINT].GetText() );
otherUnit->GetField( DATASHEET )->SetText( m_FieldsBuf[DATASHEET].GetText() );
}
}
}
m_cmp->UpdatePinCache();
GetParent()->OnModify();
GetParent()->GetScreen()->TestDanglingEnds();
EndQuasiModal( wxID_OK );
}
void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::addFieldButtonHandler( wxCommandEvent& event )
{
// in case m_FieldsBuf[REFERENCE].m_Orient has changed on screen only, grab
// screen contents.
if( !copyPanelToSelectedField() )
return;
unsigned fieldNdx = m_FieldsBuf.size();
SCH_FIELD blank( wxPoint(), fieldNdx, m_cmp );
blank.SetTextAngle( m_FieldsBuf[REFERENCE].GetTextAngle() );
m_FieldsBuf.push_back( blank );
m_FieldsBuf[fieldNdx].SetName( TEMPLATE_FIELDNAME::GetDefaultFieldName( fieldNdx ) );
m_skipCopyFromPanel = true;
setRowItem( fieldNdx, m_FieldsBuf[fieldNdx] );
setSelectedFieldNdx( fieldNdx );
m_skipCopyFromPanel = false;
}
void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::deleteFieldButtonHandler( wxCommandEvent& event )
{
unsigned fieldNdx = getSelectedFieldNdx();
if( fieldNdx >= m_FieldsBuf.size() ) // traps the -1 case too
return;
if( fieldNdx < MANDATORY_FIELDS )
{
wxBell();
return;
}
m_skipCopyFromPanel = true;
m_FieldsBuf.erase( m_FieldsBuf.begin() + fieldNdx );
fieldListCtrl->DeleteItem( fieldNdx );
if( fieldNdx >= m_FieldsBuf.size() )
--fieldNdx;
updateDisplay();
setSelectedFieldNdx( fieldNdx );
m_skipCopyFromPanel = false;
}
void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::showButtonHandler( wxCommandEvent& event )
{
unsigned fieldNdx = getSelectedFieldNdx();
if( fieldNdx == DATASHEET )
{
wxString datasheet_uri = fieldValueTextCtrl->GetValue();
datasheet_uri = ResolveUriByEnvVars( datasheet_uri );
GetAssociatedDocument( this, datasheet_uri );
}
else if( fieldNdx == FOOTPRINT )
{
// pick a footprint using the footprint picker.
wxString fpid = fieldValueTextCtrl->GetValue();
KIWAY_PLAYER* frame = Kiway().Player( FRAME_PCB_MODULE_VIEWER_MODAL, true, this );
if( frame->ShowModal( &fpid, this ) )
{
// DBG( printf( "%s: %s\n", __func__, TO_UTF8( fpid ) ); )
fieldValueTextCtrl->SetValue( fpid );
setRowItem( fieldNdx, m_FieldsBuf[fieldNdx].GetName( false ), fpid );
}
frame->Destroy();
}
}
void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::moveUpButtonHandler( wxCommandEvent& event )
{
unsigned fieldNdx = getSelectedFieldNdx();
if( fieldNdx >= m_FieldsBuf.size() ) // traps the -1 case too
return;
if( fieldNdx <= MANDATORY_FIELDS )
{
wxBell();
return;
}
if( !copyPanelToSelectedField() )
return;
// swap the fieldNdx field with the one before it, in both the vector
// and in the fieldListCtrl
SCH_FIELD tmp = m_FieldsBuf[fieldNdx - 1];
DBG( printf( "tmp.m_Text=\"%s\" tmp.m_Name=\"%s\"\n",
TO_UTF8( tmp.GetText() ), TO_UTF8( tmp.GetName( false ) ) ); )
m_FieldsBuf[fieldNdx - 1] = m_FieldsBuf[fieldNdx];
setRowItem( fieldNdx - 1, m_FieldsBuf[fieldNdx] );
m_FieldsBuf[fieldNdx] = tmp;
setRowItem( fieldNdx, tmp );
updateDisplay();
m_skipCopyFromPanel = true;
setSelectedFieldNdx( fieldNdx - 1 );
m_skipCopyFromPanel = false;
}
void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::moveDownButtonHandler( wxCommandEvent& event )
{
unsigned fieldNdx = getSelectedFieldNdx();
// Ensure there is at least one field after this one
if( fieldNdx >= ( m_FieldsBuf.size() - 1 ) )
{
return;
}
// The first field which can be moved up is the second user field
// so any field which id < MANDATORY_FIELDS cannot be moved down
if( fieldNdx < MANDATORY_FIELDS )
return;
if( !copyPanelToSelectedField() )
return;
// swap the fieldNdx field with the one before it, in both the vector
// and in the fieldListCtrl
SCH_FIELD tmp = m_FieldsBuf[fieldNdx + 1];
m_FieldsBuf[fieldNdx + 1] = m_FieldsBuf[fieldNdx];
setRowItem( fieldNdx + 1, m_FieldsBuf[fieldNdx] );
m_FieldsBuf[fieldNdx + 1].SetId( fieldNdx + 1 );
m_FieldsBuf[fieldNdx] = tmp;
setRowItem( fieldNdx, tmp );
m_FieldsBuf[fieldNdx].SetId( fieldNdx );
updateDisplay( );
m_skipCopyFromPanel = true;
setSelectedFieldNdx( fieldNdx + 1 );
m_skipCopyFromPanel = false;
}
void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::setSelectedFieldNdx( int aFieldNdx )
{
/* deselect old selection, but I think this is done by single selection
* flag within fieldListCtrl.
* fieldListCtrl->SetItemState( s_SelectedRow, 0,
* wxLIST_STATE_SELECTED|wxLIST_STATE_FOCUSED);
*/
if( aFieldNdx >= (int) m_FieldsBuf.size() )
aFieldNdx = m_FieldsBuf.size() - 1;
if( aFieldNdx < 0 )
aFieldNdx = 0;
fieldListCtrl->SetItemState( aFieldNdx, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
fieldListCtrl->EnsureVisible( aFieldNdx );
s_SelectedRow = aFieldNdx;
}
int DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::getSelectedFieldNdx()
{
return s_SelectedRow;
}
SCH_FIELD* DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::findField( const wxString& aFieldName )
{
for( unsigned i=0; i<m_FieldsBuf.size(); ++i )
{
if( aFieldName == m_FieldsBuf[i].GetName( false ) )
return &m_FieldsBuf[i];
}
return NULL;
}
void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::InitBuffers( SCH_COMPONENT* aComponent )
{
m_cmp = aComponent;
/* We have 3 component related field lists to be aware of: 1) UI
presentation, 2) fields in component ram copy, and 3) fields recorded
with component on disk. m_FieldsBuf is the list of UI fields, and this
list is not the same as the list which is in the component, which is
also not the same as the list on disk. All 3 lists are potentially
different. In the UI we choose to preserve the order of the first
MANDATORY_FIELDS which are sometimes called fixed fields. Then we append
the template fieldnames in the exact same order as the template
fieldname editor shows them. Then we append any user defined fieldnames
which came from the component.
*/
m_part = GetParent()->GetLibPart( m_cmp->GetLibId(), true );
#if 0 && defined(DEBUG)
for( int i = 0; i<aComponent->GetFieldCount(); ++i )
{
printf( "Orig[%d] (x=%d, y=%d)\n", i,
aComponent->m_Fields[i].GetTextPos().x,
aComponent->m_Fields[i].GetTextPos().y );
}
#endif
// When this code was written, all field constructors ensure that the fixed fields
// are all present within a component. So we can knowingly copy them over
// in the normal order. Copy only the fixed fields at first.
// Please do not break the field constructors.
m_FieldsBuf.clear();
for( int i=0; i<MANDATORY_FIELDS; ++i )
{
m_FieldsBuf.push_back( aComponent->m_Fields[i] );
// make the editable field position relative to the component
m_FieldsBuf[i].Offset( -m_cmp->m_Pos );
// Ensure the Field name reflects the default name, even if the
// local has changed since schematic was read
m_FieldsBuf[i].SetName( TEMPLATE_FIELDNAME::GetDefaultFieldName( i ) );
}
// Add template fieldnames:
// Now copy in the template fields, in the order that they are present in the
// template field editor UI.
const TEMPLATE_FIELDNAMES& tfnames = GetParent()->GetTemplateFieldNames();
for( TEMPLATE_FIELDNAMES::const_iterator it = tfnames.begin(); it!=tfnames.end(); ++it )
{
// add a new field unconditionally to the UI only
SCH_FIELD fld( wxPoint(0,0), -1 /* id is a relic */, m_cmp, it->m_Name );
// See if field by same name already exists in component.
SCH_FIELD* schField = aComponent->FindField( it->m_Name );
// If the field does not already exist in the component, then we
// use defaults from the template fieldname, otherwise the original
// values from the component will be set.
if( !schField )
{
fld.SetVisible( it->m_Visible );
}
else
{
fld = *schField;
// make the editable field position relative to the component
fld.Offset( -m_cmp->m_Pos );
}
m_FieldsBuf.push_back( fld );
}
// Lastly, append any original fields from the component which were not added
// from the set of fixed fields nor from the set of template fields.
for( unsigned i=MANDATORY_FIELDS; i<aComponent->m_Fields.size(); ++i )
{
SCH_FIELD* cmp = &aComponent->m_Fields[i];
SCH_FIELD* buf = findField( cmp->GetName( false ) );
if( !buf )
{
int newNdx = m_FieldsBuf.size();
m_FieldsBuf.push_back( *cmp );
// make the editable field position relative to the component
m_FieldsBuf[newNdx].Offset( -m_cmp->m_Pos );
}
}
#if 0 && defined(DEBUG)
for( unsigned i = 0; i<m_FieldsBuf.size(); ++i )
{
printf( "m_FieldsBuf[%d] (x=%-3d, y=%-3d) name:%s\n", i, m_FieldsBuf[i].m_Pos.x,
m_FieldsBuf[i].m_Pos.y, TO_UTF8(m_FieldsBuf[i].GetName( false ) ) );
}
#endif
m_FieldsBuf[REFERENCE].SetText( m_cmp->GetRef( &GetParent()->GetCurrentSheet() ) );
for( unsigned i = 0; i<m_FieldsBuf.size(); ++i )
{
setRowItem( i, m_FieldsBuf[i] );
}
#if 0 && defined(DEBUG)
for( unsigned i = 0; i<m_FieldsBuf.size(); ++i )
{
printf( "after[%d] (x=%d, y=%d)\n", i, m_FieldsBuf[i].m_Pos.x,
m_FieldsBuf[i].m_Pos.y );
}
#endif
copyOptionsToPanel();
// disable some options inside the edit dialog
// which can cause problems while dragging
if( m_cmp->IsDragging() )
{
orientationRadioBox->Disable();
mirrorRadioBox->Disable();
chipnameTextCtrl->Disable();
}
// put focus on the list ctrl
fieldListCtrl->SetFocus();
// resume editing at the last row edited, last time dialog was up.
setSelectedFieldNdx( s_SelectedRow );
copySelectedFieldToPanel();
}
void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::setRowItem( int aFieldNdx, const wxString& aName, const wxString& aValue )
{
wxASSERT( aFieldNdx >= 0 );
// insert blanks if aFieldNdx is referencing a "yet to be defined" row
while( aFieldNdx >= fieldListCtrl->GetItemCount() )
{
long ndx = fieldListCtrl->InsertItem( fieldListCtrl->GetItemCount(), wxEmptyString );
wxASSERT( ndx >= 0 );
fieldListCtrl->SetItem( ndx, 1, wxEmptyString );
}
fieldListCtrl->SetItem( aFieldNdx, 0, aName );
fieldListCtrl->SetItem( aFieldNdx, 1, aValue );
// recompute the column widths here, after setting texts
int totalWidth = fieldListCtrl->GetSize().GetWidth();
fieldListCtrl->SetColumnWidth( 0, wxLIST_AUTOSIZE );
fieldListCtrl->SetColumnWidth( 1, totalWidth - fieldListCtrl->GetColumnWidth( 0 ) );
}
void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::copySelectedFieldToPanel()
{
wxCHECK_RET( m_cmp != NULL, wxT( "Component pointer not initialized." ) );
unsigned fieldNdx = getSelectedFieldNdx();
if( fieldNdx >= m_FieldsBuf.size() ) // traps the -1 case too
return;
SCH_FIELD& field = m_FieldsBuf[fieldNdx];
showCheckBox->SetValue( field.IsVisible() );
rotateCheckBox->SetValue( field.GetTextAngle() == TEXT_ANGLE_VERT );
int style = 0;
if( field.IsItalic() )
style = 1;
if( field.IsBold() )
style |= 2;
m_StyleRadioBox->SetSelection( style );
// Select the right text justification
if( field.GetHorizJustify() == GR_TEXT_HJUSTIFY_LEFT )
m_FieldHJustifyCtrl->SetSelection( 0 );
else if( field.GetHorizJustify() == GR_TEXT_HJUSTIFY_RIGHT )
m_FieldHJustifyCtrl->SetSelection( 2 );
else
m_FieldHJustifyCtrl->SetSelection( 1 );
if( field.GetVertJustify() == GR_TEXT_VJUSTIFY_TOP )
m_FieldVJustifyCtrl->SetSelection( 0 );
else if( field.GetVertJustify() == GR_TEXT_VJUSTIFY_BOTTOM )
m_FieldVJustifyCtrl->SetSelection( 2 );
else
m_FieldVJustifyCtrl->SetSelection( 1 );
fieldNameTextCtrl->SetValue( field.GetName( false ) );
// the names of the fixed fields are not editable, others are.
fieldNameTextCtrl->Enable( fieldNdx >= MANDATORY_FIELDS );
fieldNameTextCtrl->SetEditable( fieldNdx >= MANDATORY_FIELDS );
// only user defined fields may be moved, and not the top most user defined
// field since it would be moving up into the fixed fields, > not >=
moveUpButton->Enable( fieldNdx > MANDATORY_FIELDS );
moveDownButton->Enable( ( fieldNdx >= MANDATORY_FIELDS ) && ( fieldNdx < ( m_FieldsBuf.size() - 1 ) ) );
// may only delete user defined fields
deleteFieldButton->Enable( fieldNdx >= MANDATORY_FIELDS );
fieldValueTextCtrl->SetValidator( SCH_FIELD_VALIDATOR( false, field.GetId() ) );
fieldValueTextCtrl->SetValue( field.GetText() );
m_show_datasheet_button->Enable( fieldNdx == DATASHEET || fieldNdx == FOOTPRINT );
if( fieldNdx == DATASHEET )
{
m_show_datasheet_button->SetLabel( _( "Show Datasheet" ) );
m_show_datasheet_button->SetToolTip(
_("If your datasheet is given as an http:// link,"
" then pressing this button should bring it up in your webbrowser.") );
}
else if( fieldNdx == FOOTPRINT )
{
m_show_datasheet_button->SetLabel( _( "Browse Footprints" ) );
m_show_datasheet_button->SetToolTip(
_("Open the footprint browser to choose a footprint and assign it.") );
}
else
{
m_show_datasheet_button->SetLabel( wxEmptyString );
m_show_datasheet_button->SetToolTip(
_("Used only for fields Footprint and Datasheet.") );
}
// For power symbols, the value is NOR editable, because value and pin
// name must be same and can be edited only in library editor
if( fieldNdx == VALUE && m_part && m_part->IsPower() )
fieldValueTextCtrl->Enable( false );
else
fieldValueTextCtrl->Enable( true );
textSizeTextCtrl->SetValue( EDA_GRAPHIC_TEXT_CTRL::FormatSize( g_UserUnit, field.GetTextWidth() ) );
wxPoint coord = field.GetTextPos();
wxPoint zero = -m_cmp->m_Pos; // relative zero
// If the field value is empty and the position is at relative zero, we
// set the initial position as a small offset from the ref field, and
// orient it the same as the ref field. That is likely to put it at least
// close to the desired position.
if( coord == zero && field.GetText().IsEmpty() )
{
rotateCheckBox->SetValue( m_FieldsBuf[REFERENCE].GetTextAngle() == TEXT_ANGLE_VERT );
coord.x = m_FieldsBuf[REFERENCE].GetTextPos().x
+ ( fieldNdx - MANDATORY_FIELDS + 1 ) * 100;
coord.y = m_FieldsBuf[REFERENCE].GetTextPos().y
+ ( fieldNdx - MANDATORY_FIELDS + 1 ) * 100;
// coord can compute negative if field is < MANDATORY_FIELDS, e.g. FOOTPRINT.
// That is ok, we basically don't want all the new empty fields on
// top of each other.
}
wxString coordText = StringFromValue( g_UserUnit, coord.x );
posXTextCtrl->SetValue( coordText );
coordText = StringFromValue( g_UserUnit, coord.y );
posYTextCtrl->SetValue( coordText );
}
bool DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::copyPanelToSelectedField()
{
unsigned fieldNdx = getSelectedFieldNdx();
if( fieldNdx >= m_FieldsBuf.size() ) // traps the -1 case too
return true;
// Check for illegal field text.
if( fieldValueTextCtrl->GetValidator()
&& !fieldValueTextCtrl->GetValidator()->Validate( this ) )
return false;
SCH_FIELD& field = m_FieldsBuf[fieldNdx];
field.SetVisible( showCheckBox->GetValue() );
if( rotateCheckBox->GetValue() )
field.SetTextAngle( TEXT_ANGLE_VERT );
else
field.SetTextAngle( TEXT_ANGLE_HORIZ );
rotateCheckBox->SetValue( field.GetTextAngle() == TEXT_ANGLE_VERT );
// Copy the text justification
static const EDA_TEXT_HJUSTIFY_T hjustify[] = {
GR_TEXT_HJUSTIFY_LEFT,
GR_TEXT_HJUSTIFY_CENTER,
GR_TEXT_HJUSTIFY_RIGHT
};
static const EDA_TEXT_VJUSTIFY_T vjustify[] = {
GR_TEXT_VJUSTIFY_TOP,
GR_TEXT_VJUSTIFY_CENTER,
GR_TEXT_VJUSTIFY_BOTTOM
};
field.SetHorizJustify( hjustify[m_FieldHJustifyCtrl->GetSelection()] );
field.SetVertJustify( vjustify[m_FieldVJustifyCtrl->GetSelection()] );
field.SetName( fieldNameTextCtrl->GetValue() );
/* Void fields texts for REFERENCE and VALUE (value is the name of the
* component in lib ! ) are not allowed
* change them only for a new non void value
* When void, usually netlists are broken
*/
if( !fieldValueTextCtrl->GetValue().IsEmpty() || fieldNdx > VALUE )
field.SetText( fieldValueTextCtrl->GetValue() );
setRowItem( fieldNdx, field ); // update fieldListCtrl
int tmp = EDA_GRAPHIC_TEXT_CTRL::ParseSize( textSizeTextCtrl->GetValue(), g_UserUnit );
field.SetTextSize( wxSize( tmp, tmp ) );
int style = m_StyleRadioBox->GetSelection();
field.SetItalic( (style & 1 ) != 0 );
field.SetBold( (style & 2 ) != 0 );
wxPoint pos;
pos.x = ValueFromString( g_UserUnit, posXTextCtrl->GetValue() );
pos.y = ValueFromString( g_UserUnit, posYTextCtrl->GetValue() );
field.SetTextPos( pos );
return true;
}
void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::copyOptionsToPanel()
{
// Remove non existing choices (choiceCount must be <= number for parts)
int unitcount = m_part ? m_part->GetUnitCount() : 1;
if( unitcount < 1 )
unitcount = 1;
unitChoice->Clear();
for( int ii = 1; ii <= unitcount; ii++ )
{
unitChoice->Append( LIB_PART::SubReference( ii, false ) );
}
// For symbols with multiple parts per package, set the unit selection
if( m_cmp->GetUnit() <= (int)unitChoice->GetCount() )
unitChoice->SetSelection( m_cmp->GetUnit() - 1 );
// Disable unit selection if only one unit exists:
if( m_cmp->GetUnitCount() <= 1 )
{
unitChoice->Enable( false );
unitsInterchageableLabel->Show( false );
unitsInterchageableText->Show( false );
}
else
{
// Show the "Units are not interchangeable" message option?
if( !m_part || !m_part->UnitsLocked() )
unitsInterchageableLabel->SetLabel( _( "Yes" ) );
else
unitsInterchageableLabel->SetLabel( _( "No" ) );
}
int orientation = m_cmp->GetOrientation() & ~( CMP_MIRROR_X | CMP_MIRROR_Y );
if( orientation == CMP_ORIENT_90 )
orientationRadioBox->SetSelection( 1 );
else if( orientation == CMP_ORIENT_180 )
orientationRadioBox->SetSelection( 2 );
else if( orientation == CMP_ORIENT_270 )
orientationRadioBox->SetSelection( 3 );
else
orientationRadioBox->SetSelection( 0 );
int mirror = m_cmp->GetOrientation() & ( CMP_MIRROR_X | CMP_MIRROR_Y );
if( mirror == CMP_MIRROR_X )
{
mirrorRadioBox->SetSelection( 1 );
DBG( printf( "mirror=X,1\n" ); )
}
else if( mirror == CMP_MIRROR_Y )
{
mirrorRadioBox->SetSelection( 2 );
DBG( printf( "mirror=Y,2\n" ); )
}
else
mirrorRadioBox->SetSelection( 0 );
// Activate/Desactivate the normal/convert option ? (activated only if
// the component has more than one shape)
if( m_cmp->GetConvert() > 1 )
convertCheckBox->SetValue( true );
if( m_part == NULL || !m_part->HasConversion() )
convertCheckBox->Enable( false );
// Set the component's library name.
chipnameTextCtrl->SetValue( m_cmp->GetLibId().Format() );
// Set the component's unique ID time stamp.
m_textCtrlTimeStamp->SetValue( wxString::Format( wxT( "%8.8lX" ),
(unsigned long) m_cmp->GetTimeStamp() ) );
}
void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::SetInitCmp( wxCommandEvent& event )
{
if( !m_cmp )
return;
if( LIB_PART* part = GetParent()->GetLibPart( m_cmp->GetLibId() ) )
{
// save old cmp in undo list if not already in edit, or moving ...
if( m_cmp->GetFlags() == 0 )
GetParent()->SaveCopyInUndoList( m_cmp, UR_CHANGED );
INSTALL_UNBUFFERED_DC( dc, GetParent()->GetCanvas() );
m_cmp->Draw( GetParent()->GetCanvas(), &dc, wxPoint( 0, 0 ), g_XorMode );
// Initialize fixed field values to default values found in library
// Note: the field texts are not modified because they are set in schematic,
// the text from libraries is most of time a dummy text
// Only VALUE, REFERENCE , FOOTPRINT and DATASHEET are re-initialized
LIB_FIELD& refField = part->GetReferenceField();
m_cmp->GetField( REFERENCE )->ImportValues( refField );
m_cmp->GetField( REFERENCE )->SetTextPos( refField.GetTextPos() + m_cmp->m_Pos );
LIB_FIELD& valField = part->GetValueField();
m_cmp->GetField( VALUE )->ImportValues( valField );
m_cmp->GetField( VALUE )->SetTextPos( valField.GetTextPos() + m_cmp->m_Pos );
LIB_FIELD* field = part->GetField(FOOTPRINT);
if( field && m_cmp->GetField( FOOTPRINT ) )
{
m_cmp->GetField( FOOTPRINT )->ImportValues( *field );
m_cmp->GetField( FOOTPRINT )->SetTextPos( field->GetTextPos() + m_cmp->m_Pos );
}
field = part->GetField(DATASHEET);
if( field && m_cmp->GetField( DATASHEET ) )
{
m_cmp->GetField( DATASHEET )->ImportValues( *field );
m_cmp->GetField( DATASHEET )->SetTextPos( field->GetTextPos() + m_cmp->m_Pos );
}
m_cmp->SetOrientation( CMP_NORMAL );
GetParent()->OnModify();
m_cmp->Draw( GetParent()->GetCanvas(), &dc, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE );
EndQuasiModal( wxID_OK );
}
}
void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::UpdateFields( wxCommandEvent& event )
{
SCH_COMPONENT copy( *m_cmp );
std::list<SCH_COMPONENT*> components;
components.push_back( © );
InvokeDialogUpdateFields( GetParent(), components, false );
// Copy fields from the modified component copy to the dialog buffer
m_FieldsBuf.clear();
for( int i = 0; i < copy.GetFieldCount(); ++i )
{
copy.m_Fields[i].SetParent( m_cmp );
m_FieldsBuf.push_back( copy.m_Fields[i] );
m_FieldsBuf[i].Offset( -m_cmp->m_Pos );
}
// Update the selected field as well
copySelectedFieldToPanel();
updateDisplay();
}
void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::OnSizeFieldsList( wxSizeEvent& event )
{
int newWidth = event.GetSize().GetX();
fieldListCtrl->SetColumnWidth( 1, newWidth - fieldListCtrl->GetColumnWidth( 0 ) );
event.Skip();
}
|