You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

810 lines
20 KiB

* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
15 years ago
15 years ago
15 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2012 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 2004-2017 KiCad Developers, see AUTHORS.txt for contributors.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, you may find one here:
  19. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  20. * or you may search the http://www.gnu.org website for the version 2 license,
  21. * or you may write to the Free Software Foundation, Inc.,
  22. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  23. */
  24. /**
  25. * @file lib_field.cpp
  26. */
  27. #include <fctsys.h>
  28. #include <pgm_base.h>
  29. #include <gr_basic.h>
  30. #include <macros.h>
  31. #include <base_struct.h>
  32. #include <drawtxt.h>
  33. #include <kicad_string.h>
  34. #include <class_drawpanel.h>
  35. #include <plot_common.h>
  36. #include <trigo.h>
  37. #include <base_units.h>
  38. #include <msgpanel.h>
  39. #include <bitmaps.h>
  40. #include <general.h>
  41. #include <class_libentry.h>
  42. #include <transform.h>
  43. #include <lib_field.h>
  44. #include <template_fieldnames.h>
  45. LIB_FIELD::LIB_FIELD(LIB_PART * aParent, int idfield ) :
  46. LIB_ITEM( LIB_FIELD_T, aParent )
  47. {
  48. Init( idfield );
  49. }
  50. LIB_FIELD::LIB_FIELD( int idfield ) :
  51. LIB_ITEM( LIB_FIELD_T, NULL )
  52. {
  53. Init( idfield );
  54. }
  55. LIB_FIELD::~LIB_FIELD()
  56. {
  57. }
  58. void LIB_FIELD::operator=( const LIB_FIELD& field )
  59. {
  60. m_id = field.m_id;
  61. m_Text = field.m_Text;
  62. m_name = field.m_name;
  63. m_Parent = field.m_Parent;
  64. SetEffects( field );
  65. }
  66. void LIB_FIELD::Init( int id )
  67. {
  68. m_id = id;
  69. SetTextWidth( GetDefaultTextSize() );
  70. SetTextHeight( GetDefaultTextSize() );
  71. m_typeName = _( "Field" );
  72. SetTextAngle( TEXT_ANGLE_HORIZ ); // constructor already did this.
  73. m_rotate = false;
  74. m_updateText = false;
  75. // fields in RAM must always have names, because we are trying to get
  76. // less dependent on field ids and more dependent on names.
  77. // Plus assumptions are made in the field editors.
  78. m_name = TEMPLATE_FIELDNAME::GetDefaultFieldName( id );
  79. switch( id )
  80. {
  81. case DATASHEET:
  82. case FOOTPRINT:
  83. // by contrast, VALUE and REFERENCE are are always constructed as
  84. // initially visible, and template fieldsnames' initial visibility
  85. // is controlled by the template fieldname configuration record.
  86. SetVisible( false );
  87. break;
  88. }
  89. }
  90. bool LIB_FIELD::Save( OUTPUTFORMATTER& aFormatter )
  91. {
  92. int hjustify, vjustify;
  93. wxString text = m_Text;
  94. hjustify = 'C';
  95. if( GetHorizJustify() == GR_TEXT_HJUSTIFY_LEFT )
  96. hjustify = 'L';
  97. else if( GetHorizJustify() == GR_TEXT_HJUSTIFY_RIGHT )
  98. hjustify = 'R';
  99. vjustify = 'C';
  100. if( GetVertJustify() == GR_TEXT_VJUSTIFY_BOTTOM )
  101. vjustify = 'B';
  102. else if( GetVertJustify() == GR_TEXT_VJUSTIFY_TOP )
  103. vjustify = 'T';
  104. aFormatter.Print( 0, "F%d %s %d %d %d %c %c %c %c%c%c",
  105. m_id,
  106. EscapedUTF8( text ).c_str(), // wraps in quotes
  107. GetTextPos().x, GetTextPos().y, GetTextWidth(),
  108. GetTextAngle() == 0 ? 'H' : 'V',
  109. IsVisible() ? 'V' : 'I',
  110. hjustify, vjustify,
  111. IsItalic() ? 'I' : 'N',
  112. IsBold() ? 'B' : 'N' );
  113. /* Save field name, if necessary
  114. * Field name is saved only if it is not the default name.
  115. * Just because default name depends on the language and can change from
  116. * a country to an other
  117. */
  118. wxString defName = TEMPLATE_FIELDNAME::GetDefaultFieldName( m_id );
  119. if( m_id >= FIELD1 && !m_name.IsEmpty() && m_name != defName )
  120. aFormatter.Print( 0, " %s", EscapedUTF8( m_name ).c_str() );
  121. aFormatter.Print( 0, "\n" );
  122. return true;
  123. }
  124. bool LIB_FIELD::Load( LINE_READER& aLineReader, wxString& errorMsg )
  125. {
  126. int cnt;
  127. int x, y, size;
  128. char textOrient;
  129. char textVisible;
  130. char textHJustify;
  131. char textVJustify[256];
  132. char* line = (char*) aLineReader;
  133. char* limit = line + aLineReader.Length();
  134. if( sscanf( line + 1, "%d", &m_id ) != 1 || m_id < 0 )
  135. {
  136. errorMsg = wxT( "invalid field header" );
  137. return false;
  138. }
  139. // Caller did a strtok(), which inserts a nul, so next few bytes are ugly:
  140. // digit(s), a nul, some whitespace, then a double quote.
  141. while( line < limit && *line != '"' )
  142. line++;
  143. if( line == limit )
  144. return false;
  145. line += ReadDelimitedText( &m_Text, line );
  146. // Doctor the *.lib file field which has a "~" in blank fields. New saves will
  147. // not save like this, and eventually these two lines can be removed.
  148. if( m_Text.size() == 1 && m_Text[0] == wxChar( '~' ) )
  149. m_Text.clear();
  150. memset( textVJustify, 0, sizeof( textVJustify ) );
  151. cnt = sscanf( line, " %d %d %d %c %c %c %255s", &x, &y, &size,
  152. &textOrient, &textVisible, &textHJustify, textVJustify );
  153. if( cnt < 5 )
  154. {
  155. errorMsg.Printf( wxT( "field %d does not have the correct number of parameters" ),
  156. m_id );
  157. return false;
  158. }
  159. SetTextPos( wxPoint( x, y ) );
  160. SetTextSize( wxSize( size, size ) );
  161. if( textOrient == 'H' )
  162. SetTextAngle( TEXT_ANGLE_HORIZ );
  163. else if( textOrient == 'V' )
  164. SetTextAngle( TEXT_ANGLE_VERT );
  165. else
  166. {
  167. errorMsg.Printf( wxT( "field %d text orientation parameter <%c> is not valid" ),
  168. textOrient );
  169. return false;
  170. }
  171. if( textVisible == 'V' )
  172. SetVisible( true );
  173. else if( textVisible == 'I' )
  174. SetVisible( false );
  175. else
  176. {
  177. errorMsg.Printf( wxT( "field %d text visible parameter <%c> is not valid" ),
  178. textVisible );
  179. return false;
  180. }
  181. SetHorizJustify( GR_TEXT_HJUSTIFY_CENTER );
  182. SetVertJustify( GR_TEXT_VJUSTIFY_CENTER );
  183. if( cnt >= 6 )
  184. {
  185. if( textHJustify == 'C' )
  186. SetHorizJustify( GR_TEXT_HJUSTIFY_CENTER );
  187. else if( textHJustify == 'L' )
  188. SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
  189. else if( textHJustify == 'R' )
  190. SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
  191. else
  192. {
  193. errorMsg.Printf(
  194. wxT( "field %d text horizontal justification parameter <%c> is not valid" ),
  195. textHJustify );
  196. return false;
  197. }
  198. if( textVJustify[0] == 'C' )
  199. SetVertJustify( GR_TEXT_VJUSTIFY_CENTER );
  200. else if( textVJustify[0] == 'B' )
  201. SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM );
  202. else if( textVJustify[0] == 'T' )
  203. SetVertJustify( GR_TEXT_VJUSTIFY_TOP );
  204. else
  205. {
  206. errorMsg.Printf(
  207. wxT( "field %d text vertical justification parameter <%c> is not valid" ),
  208. textVJustify[0] );
  209. return false;
  210. }
  211. if( textVJustify[1] == 'I' ) // Italic
  212. SetItalic( true );
  213. if( textVJustify[2] == 'B' ) // Bold
  214. SetBold( true );
  215. }
  216. // fields in RAM must always have names.
  217. if( m_id < MANDATORY_FIELDS )
  218. {
  219. // Fields in RAM must always have names, because we are trying to get
  220. // less dependent on field ids and more dependent on names.
  221. // Plus assumptions are made in the field editors.
  222. m_name = TEMPLATE_FIELDNAME::GetDefaultFieldName( m_id );
  223. }
  224. else
  225. {
  226. ReadDelimitedText( &m_name, line );
  227. }
  228. return true;
  229. }
  230. int LIB_FIELD::GetPenSize() const
  231. {
  232. return GetThickness() == 0 ? GetDefaultLineThickness() : GetThickness();
  233. }
  234. void LIB_FIELD::drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset,
  235. COLOR4D aColor, GR_DRAWMODE aDrawMode, void* aData,
  236. const TRANSFORM& aTransform )
  237. {
  238. wxPoint text_pos;
  239. COLOR4D color = UNSPECIFIED_COLOR4D;
  240. int linewidth = GetPenSize();
  241. if( IsBold() )
  242. linewidth = GetPenSizeForBold( GetTextWidth() );
  243. else
  244. linewidth = Clamp_Text_PenSize( linewidth, GetTextSize(), IsBold() );
  245. if( !IsVisible() && ( aColor == UNSPECIFIED_COLOR4D ) )
  246. {
  247. color = GetInvisibleItemColor();
  248. }
  249. else if( IsSelected() && ( aColor == UNSPECIFIED_COLOR4D ) )
  250. {
  251. color = GetItemSelectedColor();
  252. }
  253. else
  254. {
  255. color = aColor;
  256. }
  257. if( color == UNSPECIFIED_COLOR4D )
  258. color = GetDefaultColor();
  259. text_pos = aTransform.TransformCoordinate( GetTextPos() ) + aOffset;
  260. wxString text;
  261. if( aData )
  262. text = *(wxString*)aData;
  263. else
  264. text = m_Text;
  265. GRSetDrawMode( aDC, aDrawMode );
  266. EDA_RECT* clipbox = aPanel? aPanel->GetClipBox() : NULL;
  267. DrawGraphicText( clipbox, aDC, text_pos, color, text,
  268. GetTextAngle(), GetTextSize(),
  269. GetHorizJustify(), GetVertJustify(),
  270. linewidth, IsItalic(), IsBold() );
  271. /* Set to one (1) to draw bounding box around field text to validate
  272. * bounding box calculation. */
  273. #if 0
  274. EDA_RECT bBox = GetBoundingBox();
  275. bBox.RevertYAxis();
  276. bBox = aTransform.TransformCoordinate( bBox );
  277. bBox.Move( aOffset );
  278. GRRect( clipbox, aDC, bBox, 0, LIGHTMAGENTA );
  279. #endif
  280. }
  281. bool LIB_FIELD::HitTest( const wxPoint& aPosition ) const
  282. {
  283. // Because HitTest is mainly used to select the field
  284. // return always false if this field is void
  285. if( IsVoid() )
  286. return false;
  287. return HitTest( aPosition, 0, DefaultTransform );
  288. }
  289. bool LIB_FIELD::HitTest( const wxPoint &aPosition, int aThreshold, const TRANSFORM& aTransform ) const
  290. {
  291. if( aThreshold < 0 )
  292. aThreshold = 0;
  293. // Build a temporary copy of the text for hit testing
  294. EDA_TEXT tmp_text( *this );
  295. // Reference designator text has one or 2 additional character (displays
  296. // U? or U?A)
  297. if( m_id == REFERENCE )
  298. {
  299. wxString extended_text = tmp_text.GetText();
  300. extended_text.Append('?');
  301. const LIB_PART* parent = static_cast<const LIB_PART*>( m_Parent );
  302. if ( parent && ( parent->GetUnitCount() > 1 ) )
  303. extended_text.Append('A');
  304. tmp_text.SetText( extended_text );
  305. }
  306. tmp_text.SetTextPos( aTransform.TransformCoordinate( GetTextPos() ) );
  307. /* The text orientation may need to be flipped if the
  308. * transformation matrix causes xy axes to be flipped.
  309. * this simple algo works only for schematic matrix (rot 90 or/and mirror)
  310. */
  311. bool t1 = ( aTransform.x1 != 0 ) ^ ( GetTextAngle() != 0 );
  312. tmp_text.SetTextAngle( t1 ? TEXT_ANGLE_HORIZ : TEXT_ANGLE_VERT );
  313. return tmp_text.TextHitTest( aPosition );
  314. }
  315. EDA_ITEM* LIB_FIELD::Clone() const
  316. {
  317. LIB_FIELD* newfield = new LIB_FIELD( m_id );
  318. Copy( newfield );
  319. return (EDA_ITEM*) newfield;
  320. }
  321. void LIB_FIELD::Copy( LIB_FIELD* aTarget ) const
  322. {
  323. aTarget->m_Text = m_Text;
  324. aTarget->m_name = m_name;
  325. aTarget->SetEffects( *this );
  326. aTarget->SetParent( m_Parent );
  327. }
  328. int LIB_FIELD::compare( const LIB_ITEM& other ) const
  329. {
  330. wxASSERT( other.Type() == LIB_FIELD_T );
  331. const LIB_FIELD* tmp = ( LIB_FIELD* ) &other;
  332. if( m_id != tmp->m_id )
  333. return m_id - tmp->m_id;
  334. int result = m_Text.CmpNoCase( tmp->m_Text );
  335. if( result != 0 )
  336. return result;
  337. if( GetTextPos().x != tmp->GetTextPos().x )
  338. return GetTextPos().x - tmp->GetTextPos().x;
  339. if( GetTextPos().y != tmp->GetTextPos().y )
  340. return GetTextPos().y - tmp->GetTextPos().y;
  341. if( GetTextWidth() != tmp->GetTextWidth() )
  342. return GetTextWidth() - tmp->GetTextWidth();
  343. if( GetTextHeight() != tmp->GetTextHeight() )
  344. return GetTextHeight() - tmp->GetTextHeight();
  345. return 0;
  346. }
  347. void LIB_FIELD::SetOffset( const wxPoint& aOffset )
  348. {
  349. EDA_TEXT::Offset( aOffset );
  350. }
  351. bool LIB_FIELD::Inside( EDA_RECT& rect ) const
  352. {
  353. /*
  354. * FIXME: This fails to take into account the size and/or orientation of
  355. * the text.
  356. */
  357. return rect.Contains( GetTextPos().x, -GetTextPos().y );
  358. }
  359. void LIB_FIELD::Move( const wxPoint& newPosition )
  360. {
  361. EDA_TEXT::SetTextPos( newPosition );
  362. }
  363. void LIB_FIELD::MirrorHorizontal( const wxPoint& center )
  364. {
  365. int x = GetTextPos().x;
  366. x -= center.x;
  367. x *= -1;
  368. x += center.x;
  369. SetTextX( x );
  370. }
  371. void LIB_FIELD::MirrorVertical( const wxPoint& center )
  372. {
  373. int y = GetTextPos().y;
  374. y -= center.y;
  375. y *= -1;
  376. y += center.y;
  377. SetTextY( y );
  378. }
  379. void LIB_FIELD::Rotate( const wxPoint& center, bool aRotateCCW )
  380. {
  381. int rot_angle = aRotateCCW ? -900 : 900;
  382. wxPoint pt = GetTextPos();
  383. RotatePoint( &pt, center, rot_angle );
  384. SetTextPos( pt );
  385. SetTextAngle( GetTextAngle() != 0.0 ? 0 : 900 );
  386. }
  387. void LIB_FIELD::Plot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill,
  388. const TRANSFORM& aTransform )
  389. {
  390. if( IsVoid() )
  391. return;
  392. /* Calculate the text orientation, according to the component
  393. * orientation/mirror */
  394. int orient = GetTextAngle();
  395. if( aTransform.y1 ) // Rotate component 90 deg.
  396. {
  397. if( orient == TEXT_ANGLE_HORIZ )
  398. orient = TEXT_ANGLE_VERT;
  399. else
  400. orient = TEXT_ANGLE_HORIZ;
  401. }
  402. EDA_RECT BoundaryBox = GetBoundingBox();
  403. BoundaryBox.RevertYAxis();
  404. EDA_TEXT_HJUSTIFY_T hjustify = GR_TEXT_HJUSTIFY_CENTER;
  405. EDA_TEXT_VJUSTIFY_T vjustify = GR_TEXT_VJUSTIFY_CENTER;
  406. wxPoint textpos = aTransform.TransformCoordinate( BoundaryBox.Centre() )
  407. + aOffset;
  408. aPlotter->Text( textpos, GetDefaultColor(), GetShownText(),
  409. orient, GetTextSize(),
  410. hjustify, vjustify,
  411. GetPenSize(), IsItalic(), IsBold() );
  412. }
  413. wxString LIB_FIELD::GetFullText( int unit ) const
  414. {
  415. if( m_id != REFERENCE )
  416. return GetText();
  417. wxString text = GetText();
  418. text << wxT( "?" );
  419. if( GetParent()->IsMulti() )
  420. text << LIB_PART::SubReference( unit );
  421. return text;
  422. }
  423. const EDA_RECT LIB_FIELD::GetBoundingBox() const
  424. {
  425. /* Y coordinates for LIB_ITEMS are bottom to top, so we must invert the Y position when
  426. * calling GetTextBox() that works using top to bottom Y axis orientation.
  427. */
  428. EDA_RECT rect = GetTextBox( -1, -1, true );
  429. rect.RevertYAxis();
  430. // We are using now a bottom to top Y axis.
  431. wxPoint orig = rect.GetOrigin();
  432. wxPoint end = rect.GetEnd();
  433. RotatePoint( &orig, GetTextPos(), -GetTextAngle() );
  434. RotatePoint( &end, GetTextPos(), -GetTextAngle() );
  435. rect.SetOrigin( orig );
  436. rect.SetEnd( end );
  437. // We are using now a top to bottom Y axis:
  438. rect.RevertYAxis();
  439. return rect;
  440. }
  441. COLOR4D LIB_FIELD::GetDefaultColor()
  442. {
  443. COLOR4D color;
  444. switch( m_id )
  445. {
  446. case REFERENCE:
  447. color = GetLayerColor( LAYER_REFERENCEPART );
  448. break;
  449. case VALUE:
  450. color = GetLayerColor( LAYER_VALUEPART );
  451. break;
  452. default:
  453. color = GetLayerColor( LAYER_FIELDS );
  454. break;
  455. }
  456. return color;
  457. }
  458. void LIB_FIELD::Rotate()
  459. {
  460. if( InEditMode() )
  461. {
  462. m_rotate = true;
  463. }
  464. else
  465. {
  466. SetTextAngle( GetTextAngle() == TEXT_ANGLE_VERT ? TEXT_ANGLE_HORIZ : TEXT_ANGLE_VERT );
  467. }
  468. }
  469. wxString LIB_FIELD::GetName( bool aTranslate ) const
  470. {
  471. wxString name;
  472. switch( m_id )
  473. {
  474. case REFERENCE:
  475. if( aTranslate )
  476. name = _( "Reference" );
  477. else
  478. name = wxT( "Reference" );
  479. break;
  480. case VALUE:
  481. if( aTranslate )
  482. name = _( "Value" );
  483. else
  484. name = wxT( "Value" );
  485. break;
  486. case FOOTPRINT:
  487. if( aTranslate )
  488. name = _( "Footprint" );
  489. else
  490. name = wxT( "Footprint" );
  491. break;
  492. case DATASHEET:
  493. if( aTranslate )
  494. name = _( "Datasheet" );
  495. else
  496. name = wxT( "Datasheet" );
  497. break;
  498. default:
  499. if( m_name.IsEmpty() )
  500. {
  501. if( aTranslate )
  502. name.Printf( _( "Field%d" ), m_id );
  503. else
  504. name.Printf( wxT( "Field%d" ), m_id );
  505. }
  506. else
  507. name = m_name;
  508. }
  509. return name;
  510. }
  511. void LIB_FIELD::SetName( const wxString& aName )
  512. {
  513. // Mandatory field names are fixed.
  514. // So what? Why should the low level code be in charge of such a policy issue?
  515. // Besides, m_id is a relic that is untrustworthy now.
  516. if( m_id >=0 && m_id < MANDATORY_FIELDS )
  517. {
  518. DBG(printf( "trying to set a MANDATORY_FIELD's name\n" );)
  519. return;
  520. }
  521. if( m_name != aName )
  522. {
  523. m_name = aName;
  524. SetModified();
  525. }
  526. }
  527. void LIB_FIELD::SetText( const wxString& aText )
  528. {
  529. if( aText == GetText() )
  530. return;
  531. wxString oldName = m_Text;
  532. if( m_id == VALUE && m_Parent != NULL )
  533. {
  534. LIB_PART* parent = GetParent();
  535. // Set the parent component and root alias to the new name.
  536. if( parent->GetName().CmpNoCase( aText ) != 0 )
  537. parent->SetName( aText );
  538. }
  539. if( InEditMode() )
  540. {
  541. m_Text = oldName;
  542. m_savedText = aText;
  543. m_updateText = true;
  544. }
  545. else
  546. {
  547. m_Text = aText;
  548. }
  549. }
  550. wxString LIB_FIELD::GetSelectMenuText() const
  551. {
  552. return wxString::Format( _( "Field %s %s" ),
  553. GetChars( GetName() ),
  554. GetChars( ShortenedShownText() ) );
  555. }
  556. void LIB_FIELD::BeginEdit( STATUS_FLAGS aEditMode, const wxPoint aPosition )
  557. {
  558. wxCHECK_RET( ( aEditMode & ( IS_NEW | IS_MOVED ) ) != 0,
  559. wxT( "Invalid edit mode for LIB_FIELD object." ) );
  560. if( aEditMode == IS_MOVED )
  561. {
  562. m_initialPos = GetTextPos();
  563. m_initialCursorPos = aPosition;
  564. SetEraseLastDrawItem();
  565. }
  566. else
  567. {
  568. SetTextPos( aPosition );
  569. }
  570. m_Flags = aEditMode;
  571. }
  572. bool LIB_FIELD::ContinueEdit( const wxPoint aPosition )
  573. {
  574. wxCHECK_MSG( ( m_Flags & ( IS_NEW | IS_MOVED ) ) != 0, false,
  575. wxT( "Bad call to ContinueEdit(). Text is not being edited." ) );
  576. return false;
  577. }
  578. void LIB_FIELD::EndEdit( const wxPoint& aPosition, bool aAbort )
  579. {
  580. wxCHECK_RET( ( m_Flags & ( IS_NEW | IS_MOVED ) ) != 0,
  581. wxT( "Bad call to EndEdit(). Text is not being edited." ) );
  582. m_Flags = 0;
  583. m_rotate = false;
  584. m_updateText = false;
  585. SetEraseLastDrawItem( false );
  586. }
  587. void LIB_FIELD::calcEdit( const wxPoint& aPosition )
  588. {
  589. if( m_rotate )
  590. {
  591. SetTextAngle( GetTextAngle() == TEXT_ANGLE_VERT ? TEXT_ANGLE_HORIZ : TEXT_ANGLE_VERT );
  592. m_rotate = false;
  593. }
  594. if( m_updateText )
  595. {
  596. std::swap( m_Text, m_savedText );
  597. m_updateText = false;
  598. }
  599. if( m_Flags == IS_NEW )
  600. {
  601. SetTextPos( aPosition );
  602. }
  603. else if( m_Flags == IS_MOVED )
  604. {
  605. Move( m_initialPos + aPosition - m_initialCursorPos );
  606. }
  607. }
  608. void LIB_FIELD::GetMsgPanelInfo( MSG_PANEL_ITEMS& aList )
  609. {
  610. wxString msg;
  611. LIB_ITEM::GetMsgPanelInfo( aList );
  612. // Display style:
  613. msg = GetTextStyleName();
  614. aList.push_back( MSG_PANEL_ITEM( _( "Style" ), msg, MAGENTA ) );
  615. msg = StringFromValue( g_UserUnit, GetTextWidth(), true );
  616. aList.push_back( MSG_PANEL_ITEM( _( "Width" ), msg, BLUE ) );
  617. msg = StringFromValue( g_UserUnit, GetTextHeight(), true );
  618. aList.push_back( MSG_PANEL_ITEM( _( "Height" ), msg, BLUE ) );
  619. // Display field name (ref, value ...)
  620. msg = GetName();
  621. aList.push_back( MSG_PANEL_ITEM( _( "Field" ), msg, BROWN ) );
  622. // Display field text:
  623. aList.push_back( MSG_PANEL_ITEM( _( "Value" ), GetShownText(), BROWN ) );
  624. }
  625. BITMAP_DEF LIB_FIELD::GetMenuImage() const
  626. {
  627. return move_field_xpm;
  628. }