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.

834 lines
20 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 1992-2019 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 sch_line.cpp
  26. * @brief Class SCH_LINE implementation
  27. */
  28. #include <fctsys.h>
  29. #include <gr_basic.h>
  30. #include <macros.h>
  31. #include <sch_draw_panel.h>
  32. #include <plotter.h>
  33. #include <base_units.h>
  34. #include <eeschema_config.h>
  35. #include <general.h>
  36. #include <sch_line.h>
  37. #include <sch_edit_frame.h>
  38. #include <netlist_object.h>
  39. #include <sch_view.h>
  40. #include <dialogs/dialog_edit_line_style.h>
  41. static wxPenStyle getwxPenStyle( PlotDashType aType )
  42. {
  43. switch( aType )
  44. {
  45. case PLOTDASHTYPE_SOLID: return wxPENSTYLE_SOLID;
  46. case PLOTDASHTYPE_DASH: return wxPENSTYLE_SHORT_DASH;
  47. case PLOTDASHTYPE_DOT: return wxPENSTYLE_DOT;
  48. case PLOTDASHTYPE_DASHDOT: return wxPENSTYLE_DOT_DASH;
  49. }
  50. wxFAIL_MSG( "Unhandled PlotDashType" );
  51. return wxPENSTYLE_SOLID;
  52. }
  53. SCH_LINE::SCH_LINE( const wxPoint& pos, int layer ) :
  54. SCH_ITEM( NULL, SCH_LINE_T )
  55. {
  56. m_start = pos;
  57. m_end = pos;
  58. m_startIsDangling = m_endIsDangling = false;
  59. m_size = 0;
  60. m_style = -1;
  61. m_color = COLOR4D::UNSPECIFIED;
  62. switch( layer )
  63. {
  64. default:
  65. m_Layer = LAYER_NOTES;
  66. break;
  67. case LAYER_WIRE:
  68. m_Layer = LAYER_WIRE;
  69. break;
  70. case LAYER_BUS:
  71. m_Layer = LAYER_BUS;
  72. break;
  73. }
  74. }
  75. SCH_LINE::SCH_LINE( const SCH_LINE& aLine ) :
  76. SCH_ITEM( aLine )
  77. {
  78. m_start = aLine.m_start;
  79. m_end = aLine.m_end;
  80. m_size = aLine.m_size;
  81. m_style = aLine.m_style;
  82. m_color = aLine.m_color;
  83. m_startIsDangling = aLine.m_startIsDangling;
  84. m_endIsDangling = aLine.m_endIsDangling;
  85. }
  86. EDA_ITEM* SCH_LINE::Clone() const
  87. {
  88. return new SCH_LINE( *this );
  89. }
  90. static const char* style_names[] =
  91. {
  92. "solid", "dashed", "dotted", "dash_dot", nullptr
  93. };
  94. const char* SCH_LINE::GetLineStyleName( int aStyle )
  95. {
  96. const char * styleName = style_names[1];
  97. switch( aStyle )
  98. {
  99. case PLOTDASHTYPE_SOLID:
  100. styleName = style_names[0];
  101. break;
  102. default:
  103. case PLOTDASHTYPE_DASH:
  104. styleName = style_names[1];
  105. break;
  106. case PLOTDASHTYPE_DOT:
  107. styleName = style_names[2];
  108. break;
  109. case PLOTDASHTYPE_DASHDOT:
  110. styleName = style_names[3];
  111. break;
  112. }
  113. return styleName;
  114. }
  115. int SCH_LINE::GetLineStyleInternalId( const wxString& aStyleName )
  116. {
  117. int id = -1; // Default style id
  118. for( int ii = 0; style_names[ii] != nullptr; ii++ )
  119. {
  120. if( aStyleName == style_names[ii] )
  121. {
  122. id = ii;
  123. break;
  124. }
  125. }
  126. return id;
  127. }
  128. void SCH_LINE::Move( const wxPoint& aOffset )
  129. {
  130. if( aOffset != wxPoint( 0, 0 ) )
  131. {
  132. m_start += aOffset;
  133. m_end += aOffset;
  134. SetModified();
  135. }
  136. }
  137. void SCH_LINE::MoveStart( const wxPoint& aOffset )
  138. {
  139. if( aOffset != wxPoint( 0, 0 ) )
  140. {
  141. m_start += aOffset;
  142. SetModified();
  143. }
  144. }
  145. void SCH_LINE::MoveEnd( const wxPoint& aOffset )
  146. {
  147. if( aOffset != wxPoint( 0, 0 ) )
  148. {
  149. m_end += aOffset;
  150. SetModified();
  151. }
  152. }
  153. #if defined(DEBUG)
  154. void SCH_LINE::Show( int nestLevel, std::ostream& os ) const
  155. {
  156. NestedSpace( nestLevel, os ) << '<' << GetClass().Lower().mb_str()
  157. << " layer=\"" << m_Layer << '"'
  158. << " startIsDangling=\"" << m_startIsDangling
  159. << '"' << " endIsDangling=\""
  160. << m_endIsDangling << '"' << ">"
  161. << " <start" << m_start << "/>"
  162. << " <end" << m_end << "/>" << "</"
  163. << GetClass().Lower().mb_str() << ">\n";
  164. }
  165. #endif
  166. const EDA_RECT SCH_LINE::GetBoundingBox() const
  167. {
  168. int width = 25;
  169. int xmin = std::min( m_start.x, m_end.x ) - width;
  170. int ymin = std::min( m_start.y, m_end.y ) - width;
  171. int xmax = std::max( m_start.x, m_end.x ) + width;
  172. int ymax = std::max( m_start.y, m_end.y ) + width;
  173. // return a rectangle which is [pos,dim) in nature. therefore the +1
  174. EDA_RECT ret( wxPoint( xmin, ymin ), wxSize( xmax - xmin + 1, ymax - ymin + 1 ) );
  175. return ret;
  176. }
  177. double SCH_LINE::GetLength() const
  178. {
  179. return GetLineLength( m_start, m_end );
  180. }
  181. COLOR4D SCH_LINE::GetDefaultColor() const
  182. {
  183. return GetLayerColor( m_Layer );
  184. }
  185. void SCH_LINE::SetLineColor( const COLOR4D aColor )
  186. {
  187. if( aColor == GetDefaultColor() )
  188. m_color = COLOR4D::UNSPECIFIED;
  189. else
  190. m_color = aColor;
  191. }
  192. void SCH_LINE::SetLineColor( const double r, const double g, const double b, const double a )
  193. {
  194. COLOR4D newColor(r, g, b, a);
  195. if( newColor == GetDefaultColor() || newColor == COLOR4D::UNSPECIFIED )
  196. m_color = COLOR4D::UNSPECIFIED;
  197. else
  198. {
  199. // Eeschema does not allow alpha channel in colors
  200. newColor.a = 1.0;
  201. m_color = newColor;
  202. }
  203. }
  204. COLOR4D SCH_LINE::GetLineColor() const
  205. {
  206. if( m_color == COLOR4D::UNSPECIFIED )
  207. return GetLayerColor( m_Layer );
  208. return m_color;
  209. }
  210. int SCH_LINE::GetDefaultStyle() const
  211. {
  212. if( m_Layer == LAYER_NOTES )
  213. return PLOTDASHTYPE_DASH;
  214. return PLOTDASHTYPE_SOLID;
  215. }
  216. void SCH_LINE::SetLineStyle( const int aStyle )
  217. {
  218. if( aStyle == GetDefaultStyle() )
  219. m_style = -1;
  220. else
  221. m_style = aStyle;
  222. }
  223. int SCH_LINE::GetLineStyle() const
  224. {
  225. if( m_style >= 0 )
  226. return m_style;
  227. return GetDefaultStyle();
  228. }
  229. int SCH_LINE::GetDefaultWidth() const
  230. {
  231. if( m_Layer == LAYER_BUS )
  232. return GetDefaultBusThickness();
  233. return GetDefaultLineThickness();
  234. }
  235. void SCH_LINE::SetLineWidth( const int aSize )
  236. {
  237. if( aSize == GetDefaultWidth() )
  238. m_size = 0;
  239. else
  240. m_size = aSize;
  241. }
  242. int SCH_LINE::GetPenSize() const
  243. {
  244. if( m_size > 0 )
  245. return m_size;
  246. if( m_Layer == LAYER_BUS )
  247. return GetDefaultBusThickness();
  248. return GetDefaultLineThickness();
  249. }
  250. void SCH_LINE::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, const wxPoint& offset )
  251. {
  252. COLOR4D color = ( m_color != COLOR4D::UNSPECIFIED ) ? m_color : GetLayerColor( m_Layer );
  253. int width = GetPenSize();
  254. wxPoint start = m_start;
  255. wxPoint end = m_end;
  256. GRLine( panel->GetClipBox(), DC, start.x, start.y, end.x, end.y, width, color,
  257. getwxPenStyle( (PlotDashType) GetLineStyle() ) );
  258. }
  259. void SCH_LINE::MirrorX( int aXaxis_position )
  260. {
  261. MIRROR( m_start.y, aXaxis_position );
  262. MIRROR( m_end.y, aXaxis_position );
  263. }
  264. void SCH_LINE::MirrorY( int aYaxis_position )
  265. {
  266. MIRROR( m_start.x, aYaxis_position );
  267. MIRROR( m_end.x, aYaxis_position );
  268. }
  269. void SCH_LINE::Rotate( wxPoint aPosition )
  270. {
  271. RotatePoint( &m_start, aPosition, 900 );
  272. RotatePoint( &m_end, aPosition, 900 );
  273. }
  274. void SCH_LINE::RotateStart( wxPoint aPosition )
  275. {
  276. RotatePoint( &m_start, aPosition, 900 );
  277. }
  278. void SCH_LINE::RotateEnd( wxPoint aPosition )
  279. {
  280. RotatePoint( &m_end, aPosition, 900 );
  281. }
  282. bool SCH_LINE::IsSameQuadrant( SCH_LINE* aLine, const wxPoint& aPosition )
  283. {
  284. wxPoint first;
  285. wxPoint second;
  286. if( m_start == aPosition )
  287. first = m_end - aPosition;
  288. else if( m_end == aPosition )
  289. first = m_start - aPosition;
  290. else
  291. return false;
  292. if( aLine->m_start == aPosition )
  293. second = aLine->m_end - aPosition;
  294. else if( aLine->m_end == aPosition )
  295. second = aLine->m_start - aPosition;
  296. else
  297. return false;
  298. return ( sign( first.x ) == sign( second.x ) &&
  299. sign( first.y ) == sign( second.y ) );
  300. }
  301. bool SCH_LINE::IsParallel( SCH_LINE* aLine )
  302. {
  303. wxCHECK_MSG( aLine != NULL && aLine->Type() == SCH_LINE_T, false,
  304. wxT( "Cannot test line segment for overlap." ) );
  305. wxPoint firstSeg = m_end - m_start;
  306. wxPoint secondSeg = aLine->m_end - aLine->m_start;
  307. // Use long long here to avoid overflow in calculations
  308. return !( (long long) firstSeg.x * secondSeg.y - (long long) firstSeg.y * secondSeg.x );
  309. }
  310. EDA_ITEM* SCH_LINE::MergeOverlap( SCH_LINE* aLine )
  311. {
  312. auto less = []( const wxPoint& lhs, const wxPoint& rhs ) -> bool
  313. {
  314. if( lhs.x == rhs.x )
  315. return lhs.y < rhs.y;
  316. return lhs.x < rhs.x;
  317. };
  318. wxCHECK_MSG( aLine != NULL && aLine->Type() == SCH_LINE_T, NULL,
  319. wxT( "Cannot test line segment for overlap." ) );
  320. if( this == aLine || GetLayer() != aLine->GetLayer() )
  321. return NULL;
  322. auto leftmost_start = aLine->m_start;
  323. auto leftmost_end = aLine->m_end;
  324. auto rightmost_start = m_start;
  325. auto rightmost_end = m_end;
  326. // We place the start to the left and below the end of both lines
  327. if( leftmost_start != std::min( { leftmost_start, leftmost_end }, less ) )
  328. std::swap( leftmost_start, leftmost_end );
  329. if( rightmost_start != std::min( { rightmost_start, rightmost_end }, less ) )
  330. std::swap( rightmost_start, rightmost_end );
  331. // -leftmost is the line that starts farthest to the left
  332. // -other is the line that is _not_ leftmost
  333. // -rightmost is the line that ends farthest to the right. This may or
  334. // may not be 'other' as the second line may be completely covered by
  335. // the first.
  336. if( less( rightmost_start, leftmost_start ) )
  337. {
  338. std::swap( leftmost_start, rightmost_start );
  339. std::swap( leftmost_end, rightmost_end );
  340. }
  341. auto other_start = rightmost_start;
  342. auto other_end = rightmost_end;
  343. if( less( rightmost_end, leftmost_end ) )
  344. {
  345. rightmost_start = leftmost_start;
  346. rightmost_end = leftmost_end;
  347. }
  348. // If we end one before the beginning of the other, no overlap is possible
  349. if( less( leftmost_end, other_start ) )
  350. {
  351. return NULL;
  352. }
  353. // Search for a common end:
  354. if( ( leftmost_start == other_start ) &&
  355. ( leftmost_end == other_end ) ) // Trivial case
  356. {
  357. auto ret = new SCH_LINE( *aLine );
  358. ret->SetStartPoint( leftmost_start );
  359. ret->SetEndPoint( leftmost_end );
  360. return ret;
  361. }
  362. bool colinear = false;
  363. /* Test alignment: */
  364. if( ( leftmost_start.y == leftmost_end.y ) &&
  365. ( other_start.y == other_end.y ) ) // Horizontal segment
  366. {
  367. colinear = ( leftmost_start.y == other_start.y );
  368. }
  369. else if( ( leftmost_start.x == leftmost_end.x ) &&
  370. ( other_start.x == other_end.x ) ) // Vertical segment
  371. {
  372. colinear = ( leftmost_start.x == other_start.x );
  373. }
  374. else
  375. {
  376. // We use long long here to avoid overflow -- it enforces promotion
  377. // Don't use double as we need to make a direct comparison
  378. // The slope of the left-most line is dy/dx. Then we check that the slope
  379. // from the left most start to the right most start is the same as well as
  380. // the slope from the left most start to right most end.
  381. long long dx = leftmost_end.x - leftmost_start.x;
  382. long long dy = leftmost_end.y - leftmost_start.y;
  383. colinear = ( ( ( other_start.y - leftmost_start.y ) * dx ==
  384. ( other_start.x - leftmost_start.x ) * dy ) &&
  385. ( ( other_end.y - leftmost_start.y ) * dx ==
  386. ( other_end.x - leftmost_start.x ) * dy ) );
  387. }
  388. // Make a new segment that merges the 2 segments
  389. if( colinear )
  390. {
  391. leftmost_end = rightmost_end;
  392. auto ret = new SCH_LINE( *aLine );
  393. ret->SetStartPoint( leftmost_start );
  394. ret->SetEndPoint( leftmost_end );
  395. return ret;
  396. }
  397. return NULL;
  398. }
  399. void SCH_LINE::GetEndPoints( std::vector <DANGLING_END_ITEM>& aItemList )
  400. {
  401. if( GetLayer() == LAYER_NOTES )
  402. return;
  403. if( ( GetLayer() == LAYER_BUS ) || ( GetLayer() == LAYER_WIRE ) )
  404. {
  405. DANGLING_END_ITEM item( (GetLayer() == LAYER_BUS) ? BUS_START_END : WIRE_START_END, this,
  406. m_start );
  407. aItemList.push_back( item );
  408. DANGLING_END_ITEM item1( (GetLayer() == LAYER_BUS) ? BUS_END_END : WIRE_END_END, this,
  409. m_end );
  410. aItemList.push_back( item1 );
  411. }
  412. }
  413. bool SCH_LINE::UpdateDanglingState( std::vector<DANGLING_END_ITEM>& aItemList )
  414. {
  415. bool previousStartState = m_startIsDangling;
  416. bool previousEndState = m_endIsDangling;
  417. m_startIsDangling = m_endIsDangling = true;
  418. if( GetLayer() == LAYER_WIRE )
  419. {
  420. for( DANGLING_END_ITEM item : aItemList )
  421. {
  422. if( item.GetItem() == this )
  423. continue;
  424. if( item.GetType() == BUS_START_END ||
  425. item.GetType() == BUS_END_END ||
  426. item.GetType() == BUS_ENTRY_END )
  427. continue;
  428. if( m_start == item.GetPosition() )
  429. m_startIsDangling = false;
  430. if( m_end == item.GetPosition() )
  431. m_endIsDangling = false;
  432. if( (m_startIsDangling == false) && (m_endIsDangling == false) )
  433. break;
  434. }
  435. }
  436. else if( GetLayer() == LAYER_BUS || GetLayer() == LAYER_NOTES )
  437. {
  438. // Lines on the notes layer and the bus layer cannot be tested for dangling ends.
  439. previousStartState = previousEndState = m_startIsDangling = m_endIsDangling = false;
  440. }
  441. return ( previousStartState != m_startIsDangling ) || ( previousEndState != m_endIsDangling );
  442. }
  443. bool SCH_LINE::IsConnectable() const
  444. {
  445. if( m_Layer == LAYER_WIRE || m_Layer == LAYER_BUS )
  446. return true;
  447. return false;
  448. }
  449. bool SCH_LINE::CanConnect( const SCH_ITEM* aItem ) const
  450. {
  451. switch( aItem->Type() )
  452. {
  453. case SCH_JUNCTION_T:
  454. case SCH_NO_CONNECT_T:
  455. case SCH_LABEL_T:
  456. case SCH_GLOBAL_LABEL_T:
  457. case SCH_HIER_LABEL_T:
  458. case SCH_BUS_WIRE_ENTRY_T:
  459. case SCH_COMPONENT_T:
  460. case SCH_SHEET_T:
  461. case SCH_SHEET_PIN_T:
  462. return true;
  463. default:
  464. return aItem->GetLayer() == m_Layer;
  465. }
  466. }
  467. void SCH_LINE::GetConnectionPoints( std::vector< wxPoint >& aPoints ) const
  468. {
  469. aPoints.push_back( m_start );
  470. aPoints.push_back( m_end );
  471. }
  472. wxString SCH_LINE::GetSelectMenuText( EDA_UNITS_T aUnits ) const
  473. {
  474. wxString txtfmt, orient;
  475. if( m_start.x == m_end.x )
  476. orient = _( "Vertical" );
  477. else if( m_start.y == m_end.y )
  478. orient = _( "Horizontal" );
  479. switch( m_Layer )
  480. {
  481. case LAYER_NOTES:
  482. txtfmt = _( "%s Graphic Line from (%s, %s) to (%s, %s)" );
  483. break;
  484. case LAYER_WIRE:
  485. txtfmt = _( "%s Wire from (%s, %s) to (%s, %s)" );
  486. break;
  487. case LAYER_BUS:
  488. txtfmt = _( "%s Bus from (%s, %s) to (%s, %s)" );
  489. break;
  490. default:
  491. txtfmt = _( "%s Line on Unknown Layer from (%s, %s) to (%s, %s)" );
  492. }
  493. return wxString::Format( txtfmt,
  494. orient,
  495. MessageTextFromValue( aUnits, m_start.x ),
  496. MessageTextFromValue( aUnits, m_start.y ),
  497. MessageTextFromValue( aUnits, m_end.x ),
  498. MessageTextFromValue( aUnits, m_end.y ) );
  499. }
  500. BITMAP_DEF SCH_LINE::GetMenuImage() const
  501. {
  502. if( m_Layer == LAYER_NOTES )
  503. return add_dashed_line_xpm;
  504. else if( m_Layer == LAYER_WIRE )
  505. return add_line_xpm;
  506. return add_bus_xpm;
  507. }
  508. void SCH_LINE::GetNetListItem( NETLIST_OBJECT_LIST& aNetListItems,
  509. SCH_SHEET_PATH* aSheetPath )
  510. {
  511. // Net list item not required for graphic lines.
  512. if( (GetLayer() != LAYER_BUS) && (GetLayer() != LAYER_WIRE) )
  513. return;
  514. NETLIST_OBJECT* item = new NETLIST_OBJECT();
  515. item->m_SheetPath = *aSheetPath;
  516. item->m_SheetPathInclude = *aSheetPath;
  517. item->m_Comp = (SCH_ITEM*) this;
  518. item->m_Start = m_start;
  519. item->m_End = m_end;
  520. if( GetLayer() == LAYER_BUS )
  521. {
  522. item->m_Type = NET_BUS;
  523. }
  524. else /* WIRE */
  525. {
  526. item->m_Type = NET_SEGMENT;
  527. }
  528. aNetListItems.push_back( item );
  529. }
  530. bool SCH_LINE::operator <( const SCH_ITEM& aItem ) const
  531. {
  532. if( Type() != aItem.Type() )
  533. return Type() < aItem.Type();
  534. SCH_LINE* line = (SCH_LINE*) &aItem;
  535. if( GetLength() != line->GetLength() )
  536. return GetLength() < line->GetLength();
  537. if( m_start.x != line->m_start.x )
  538. return m_start.x < line->m_start.x;
  539. if( m_start.y != line->m_start.y )
  540. return m_start.y < line->m_start.y;
  541. return false;
  542. }
  543. bool SCH_LINE::HitTest( const wxPoint& aPosition, int aAccuracy ) const
  544. {
  545. // Insure minimum accuracy
  546. if( aAccuracy == 0 )
  547. aAccuracy = ( GetPenSize() / 2 ) + 4;
  548. return TestSegmentHit( aPosition, m_start, m_end, aAccuracy );
  549. }
  550. bool SCH_LINE::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
  551. {
  552. if( m_Flags & ( STRUCT_DELETED | SKIP_STRUCT ) )
  553. return false;
  554. EDA_RECT rect = aRect;
  555. if ( aAccuracy )
  556. rect.Inflate( aAccuracy );
  557. if( aContained )
  558. return rect.Contains( m_start ) && rect.Contains( m_end );
  559. return rect.Intersects( m_start, m_end );
  560. }
  561. void SCH_LINE::SwapData( SCH_ITEM* aItem )
  562. {
  563. SCH_LINE* item = (SCH_LINE*) aItem;
  564. std::swap( m_Layer, item->m_Layer );
  565. std::swap( m_start, item->m_start );
  566. std::swap( m_end, item->m_end );
  567. std::swap( m_startIsDangling, item->m_startIsDangling );
  568. std::swap( m_endIsDangling, item->m_endIsDangling );
  569. std::swap( m_style, item->m_style );
  570. std::swap( m_size, item->m_size );
  571. std::swap( m_color, item->m_color );
  572. }
  573. bool SCH_LINE::doIsConnected( const wxPoint& aPosition ) const
  574. {
  575. if( m_Layer != LAYER_WIRE && m_Layer != LAYER_BUS )
  576. return false;
  577. return IsEndPoint( aPosition );
  578. }
  579. void SCH_LINE::Plot( PLOTTER* aPlotter )
  580. {
  581. if( m_color != COLOR4D::UNSPECIFIED )
  582. aPlotter->SetColor( m_color );
  583. else
  584. aPlotter->SetColor( GetLayerColor( GetLayer() ) );
  585. aPlotter->SetCurrentLineWidth( GetPenSize() );
  586. aPlotter->SetDash( GetLineStyle() );
  587. aPlotter->MoveTo( m_start );
  588. aPlotter->FinishTo( m_end );
  589. aPlotter->SetDash( 0 );
  590. }
  591. void SCH_LINE::SetPosition( const wxPoint& aPosition )
  592. {
  593. m_end = m_end - ( m_start - aPosition );
  594. m_start = aPosition;
  595. }
  596. wxPoint SCH_LINE::MidPoint()
  597. {
  598. return wxPoint( ( m_start.x + m_end.x ) / 2, ( m_start.y + m_end.y ) / 2 );
  599. }
  600. void SCH_LINE::GetMsgPanelInfo( EDA_UNITS_T aUnits, MSG_PANEL_ITEMS& aList )
  601. {
  602. wxString msg;
  603. switch( GetLayer() )
  604. {
  605. case LAYER_WIRE:
  606. msg = _( "Net Wire" );
  607. break;
  608. case LAYER_BUS:
  609. msg = _( "Bus Wire" );
  610. break;
  611. default:
  612. msg = _( "Graphical" );
  613. return;
  614. }
  615. aList.push_back( MSG_PANEL_ITEM( _( "Line Type" ), msg, DARKCYAN ) );
  616. if( auto conn = Connection( *g_CurrentSheet ) )
  617. {
  618. #if defined(DEBUG)
  619. conn->AppendDebugInfoToMsgPanel( aList );
  620. msg.Printf( "%zu", m_connected_items.size() );
  621. aList.push_back( MSG_PANEL_ITEM( _( "Connections" ), msg, BROWN ) );
  622. #else
  623. conn->AppendInfoToMsgPanel( aList );
  624. #endif
  625. }
  626. }
  627. int SCH_EDIT_FRAME::EditLine( SCH_LINE* aLine, bool aRedraw )
  628. {
  629. if( aLine == NULL )
  630. return wxID_CANCEL;
  631. // We purposely disallow editing everything except graphic lines
  632. if( aLine->GetLayer() != LAYER_NOTES )
  633. return wxID_CANCEL;
  634. DIALOG_EDIT_LINE_STYLE dlg( this, aLine );
  635. if( dlg.ShowModal() == wxID_CANCEL )
  636. return wxID_CANCEL;
  637. if( aRedraw )
  638. RefreshItem( aLine );
  639. return wxID_OK;
  640. }