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.

513 lines
20 KiB

5 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2013 CERN
  5. * Copyright (C) 2019 KiCad Developers, see AUTHORS.txt for contributors.
  6. * @author Jean-Pierre Charras, jp.charras at wanadoo.fr
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, you may find one here:
  20. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  21. * or you may search the http://www.gnu.org website for the version 2 license,
  22. * or you may write to the Free Software Foundation, Inc.,
  23. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  24. */
  25. #include <project.h>
  26. #include <scintilla_tricks.h>
  27. #include <tool/tool_manager.h>
  28. #include <page_layout/ws_draw_item.h>
  29. #include <page_layout/ws_data_item.h>
  30. #include <page_layout/ws_data_model.h>
  31. #include <view/view.h>
  32. #include "properties_frame.h"
  33. #include "pl_draw_panel_gal.h"
  34. #include "pl_editor_frame.h"
  35. #include "tools/pl_selection_tool.h"
  36. PROPERTIES_FRAME::PROPERTIES_FRAME( PL_EDITOR_FRAME* aParent ) :
  37. PANEL_PROPERTIES_BASE( aParent ),
  38. m_scintillaTricks( nullptr ),
  39. m_textCtrlTextSizeXBinder( aParent, m_staticTextTsizeX, m_textCtrlTextSizeX, m_TextTextSizeXUnits ),
  40. m_textCtrlTextSizeYBinder( aParent, m_staticTextTsizeY, m_textCtrlTextSizeY, m_TextTextSizeYUnits ),
  41. m_textCtrlConstraintXBinder( aParent, m_staticTextConstraintX, m_textCtrlConstraintX, m_TextConstraintXUnits ),
  42. m_textCtrlConstraintYBinder( aParent, m_staticTextConstraintY, m_textCtrlConstraintY, m_TextConstraintYUnits ),
  43. m_textCtrlPosXBinder( aParent, m_staticTextPosX, m_textCtrlPosX, m_TextPosXUnits ),
  44. m_textCtrlPosYBinder( aParent, m_staticTextPosY, m_textCtrlPosY, m_TextPosYUnits ),
  45. m_textCtrlEndXBinder( aParent, m_staticTextEndX, m_textCtrlEndX, m_TextEndXUnits ),
  46. m_textCtrlEndYBinder( aParent, m_staticTextEndY, m_textCtrlEndY, m_TextEndYUnits ),
  47. m_textCtrlStepXBinder( aParent, m_staticTextStepX, m_textCtrlStepX, m_TextStepXUnits ),
  48. m_textCtrlStepYBinder( aParent, m_staticTextStepY, m_textCtrlStepY, m_TextStepYUnits ),
  49. m_textCtrlDefaultTextSizeXBinder( aParent, m_staticTextDefTsX, m_textCtrlDefaultTextSizeX, m_TextDefaultTextSizeXUnits ),
  50. m_textCtrlDefaultTextSizeYBinder( aParent, m_staticTextDefTsY, m_textCtrlDefaultTextSizeY, m_TextDefaultTextSizeYUnits ),
  51. m_textCtrlDefaultLineWidthBinder( aParent, m_staticTextDefLineW, m_textCtrlDefaultLineWidth, m_TextDefaultLineWidthUnits ),
  52. m_textCtrlDefaultTextThicknessBinder( aParent, m_staticTextDefTextThickness, m_textCtrlDefaultTextThickness, m_TextDefaultTextThicknessUnits ),
  53. m_textCtrlLeftMarginBinder( aParent, m_staticTextLeftMargin, m_textCtrlLeftMargin, m_TextLeftMarginUnits ),
  54. m_textCtrlRightMarginBinder( aParent, m_staticTextDefRightMargin, m_textCtrlRightMargin, m_TextRightMarginUnits ),
  55. m_textCtrlTopMarginBinder( aParent, m_staticTextTopMargin, m_textCtrlTopMargin, m_TextTopMarginUnits ),
  56. m_textCtrlBottomMarginBinder( aParent, m_staticTextBottomMargin, m_textCtrlBottomMargin, m_TextBottomMarginUnits ),
  57. m_textCtrlThicknessBinder( aParent, m_staticTextThickness, m_textCtrlThickness, m_TextLineThicknessUnits )
  58. {
  59. m_parent = aParent;
  60. m_stcText->SetUseVerticalScrollBar( false );
  61. m_stcText->SetUseHorizontalScrollBar( false );
  62. m_scintillaTricks = new SCINTILLA_TRICKS( m_stcText, wxT( "{}" ) );
  63. wxFont infoFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
  64. infoFont.SetSymbolicSize( wxFONTSIZE_SMALL );
  65. m_staticTextSizeInfo->SetFont( infoFont );
  66. infoFont.SetSymbolicSize( wxFONTSIZE_X_SMALL );
  67. m_staticTextInfoThickness->SetFont( infoFont );
  68. m_buttonOK->SetDefault();
  69. m_stcText->Bind( wxEVT_STC_CHARADDED, &PROPERTIES_FRAME::onScintillaCharAdded, this );
  70. }
  71. PROPERTIES_FRAME::~PROPERTIES_FRAME()
  72. {
  73. delete m_scintillaTricks;
  74. }
  75. void PROPERTIES_FRAME::OnPageChanged( wxNotebookEvent& event )
  76. {
  77. if( event.GetSelection() == 0 )
  78. m_buttonOK->SetDefault();
  79. else
  80. m_buttonGeneralOptsOK->SetDefault();
  81. event.Skip();
  82. }
  83. wxSize PROPERTIES_FRAME::GetMinSize() const
  84. {
  85. return wxSize( 150, -1 );
  86. }
  87. // Data transfert from general properties to widgets
  88. void PROPERTIES_FRAME::CopyPrmsFromGeneralToPanel()
  89. {
  90. WS_DATA_MODEL& model = WS_DATA_MODEL::GetTheInstance();
  91. // Set default parameters
  92. m_textCtrlDefaultLineWidthBinder.SetDoubleValue(
  93. From_User_Unit( EDA_UNITS::MILLIMETRES, model.m_DefaultLineWidth ) );
  94. m_textCtrlDefaultTextSizeXBinder.SetDoubleValue(
  95. From_User_Unit( EDA_UNITS::MILLIMETRES, model.m_DefaultTextSize.x ) );
  96. m_textCtrlDefaultTextSizeYBinder.SetDoubleValue(
  97. From_User_Unit( EDA_UNITS::MILLIMETRES, model.m_DefaultTextSize.y ) );
  98. m_textCtrlDefaultTextThicknessBinder.SetDoubleValue(
  99. From_User_Unit( EDA_UNITS::MILLIMETRES, model.m_DefaultTextThickness ) );
  100. m_textCtrlLeftMarginBinder.SetDoubleValue( From_User_Unit( EDA_UNITS::MILLIMETRES, model.GetLeftMargin() ) );
  101. m_textCtrlRightMarginBinder.SetDoubleValue(From_User_Unit( EDA_UNITS::MILLIMETRES, model.GetRightMargin() ) );
  102. m_textCtrlTopMarginBinder.SetDoubleValue( From_User_Unit( EDA_UNITS::MILLIMETRES, model.GetTopMargin() ) );
  103. m_textCtrlBottomMarginBinder.SetDoubleValue( From_User_Unit( EDA_UNITS::MILLIMETRES, model.GetBottomMargin() ) );
  104. }
  105. // Data transfert from widgets to general properties
  106. bool PROPERTIES_FRAME::CopyPrmsFromPanelToGeneral()
  107. {
  108. WS_DATA_MODEL& model = WS_DATA_MODEL::GetTheInstance();
  109. // Import default parameters from widgets
  110. model.m_DefaultLineWidth =
  111. To_User_Unit( EDA_UNITS::MILLIMETRES, m_textCtrlDefaultLineWidthBinder.GetValue() );
  112. model.m_DefaultTextSize.x =
  113. To_User_Unit( EDA_UNITS::MILLIMETRES, m_textCtrlDefaultTextSizeXBinder.GetValue() );
  114. model.m_DefaultTextSize.y =
  115. To_User_Unit( EDA_UNITS::MILLIMETRES, m_textCtrlDefaultTextSizeYBinder.GetValue() );
  116. model.m_DefaultTextThickness =
  117. To_User_Unit( EDA_UNITS::MILLIMETRES, m_textCtrlDefaultTextThicknessBinder.GetValue() );
  118. // Get page margins values
  119. model.SetRightMargin(
  120. To_User_Unit( EDA_UNITS::MILLIMETRES, m_textCtrlRightMarginBinder.GetValue() ) );
  121. model.SetBottomMargin(
  122. To_User_Unit( EDA_UNITS::MILLIMETRES, m_textCtrlBottomMarginBinder.GetValue() ) );
  123. // cordinates of the left top corner are the left and top margins
  124. model.SetLeftMargin(
  125. To_User_Unit( EDA_UNITS::MILLIMETRES, m_textCtrlLeftMarginBinder.GetValue() ) );
  126. model.SetTopMargin(
  127. To_User_Unit( EDA_UNITS::MILLIMETRES, m_textCtrlTopMarginBinder.GetValue() ) );
  128. return true;
  129. }
  130. // Data transfert from item to widgets in properties frame
  131. void PROPERTIES_FRAME::CopyPrmsFromItemToPanel( WS_DATA_ITEM* aItem )
  132. {
  133. if( !aItem )
  134. {
  135. m_SizerItemProperties->Show( false );
  136. return;
  137. }
  138. wxString msg;
  139. // Set parameters common to all WS_DATA_ITEM types
  140. m_staticTextType->SetLabel( aItem->GetClassName() );
  141. m_textCtrlComment->SetValue( aItem->m_Info );
  142. switch( aItem->GetPage1Option() )
  143. {
  144. default:
  145. case ALL_PAGES: m_choicePageOpt->SetSelection( 0 ); break;
  146. case FIRST_PAGE_ONLY: m_choicePageOpt->SetSelection( 1 ); break;
  147. case SUBSEQUENT_PAGES: m_choicePageOpt->SetSelection( 2 ); break;
  148. }
  149. // Position/ start point
  150. m_textCtrlPosXBinder.SetDoubleValue(
  151. From_User_Unit( EDA_UNITS::MILLIMETRES, aItem->m_Pos.m_Pos.x ) );
  152. m_textCtrlPosYBinder.SetDoubleValue(
  153. From_User_Unit( EDA_UNITS::MILLIMETRES, aItem->m_Pos.m_Pos.y ) );
  154. switch( aItem->m_Pos.m_Anchor )
  155. {
  156. case RB_CORNER: m_comboBoxCornerPos->SetSelection( 2 ); break;
  157. case RT_CORNER: m_comboBoxCornerPos->SetSelection( 0 ); break;
  158. case LB_CORNER: m_comboBoxCornerPos->SetSelection( 3 ); break;
  159. case LT_CORNER: m_comboBoxCornerPos->SetSelection( 1 ); break;
  160. }
  161. // End point
  162. m_textCtrlEndXBinder.SetDoubleValue(
  163. From_User_Unit( EDA_UNITS::MILLIMETRES, aItem->m_End.m_Pos.y ) );
  164. m_textCtrlEndYBinder.SetDoubleValue(
  165. From_User_Unit( EDA_UNITS::MILLIMETRES, aItem->m_End.m_Pos.y ) );
  166. switch( aItem->m_End.m_Anchor )
  167. {
  168. case RB_CORNER: m_comboBoxCornerEnd->SetSelection( 2 ); break;
  169. case RT_CORNER: m_comboBoxCornerEnd->SetSelection( 0 ); break;
  170. case LB_CORNER: m_comboBoxCornerEnd->SetSelection( 3 ); break;
  171. case LT_CORNER: m_comboBoxCornerEnd->SetSelection( 1 ); break;
  172. }
  173. m_textCtrlThicknessBinder.SetDoubleValue(
  174. From_User_Unit( EDA_UNITS::MILLIMETRES, aItem->m_LineWidth ) );
  175. // Now, set prms more specific to WS_DATA_ITEM types
  176. // For a given type, disable widgets which are not relevant,
  177. // and be sure widgets which are relevant are enabled
  178. if( aItem->GetType() == WS_DATA_ITEM::WS_TEXT )
  179. {
  180. WS_DATA_ITEM_TEXT* item = (WS_DATA_ITEM_TEXT*) aItem;
  181. item->m_FullText = item->m_TextBase;
  182. // Replace our '\' 'n' sequence by the EOL char
  183. item->ReplaceAntiSlashSequence();
  184. m_stcText->SetValue( item->m_FullText );
  185. msg.Printf( wxT("%d"), item->m_IncrementLabel );
  186. m_textCtrlTextIncrement->SetValue( msg );
  187. // Rotation (poly and text)
  188. msg.Printf( wxT("%.3f"), item->m_Orient );
  189. m_textCtrlRotation->SetValue( msg );
  190. // Constraints:
  191. m_textCtrlConstraintXBinder.SetDoubleValue(
  192. From_User_Unit( EDA_UNITS::MILLIMETRES, item->m_BoundingBoxSize.x ) );
  193. m_textCtrlConstraintYBinder.SetDoubleValue(
  194. From_User_Unit( EDA_UNITS::MILLIMETRES, item->m_BoundingBoxSize.y ) );
  195. // Font Options
  196. m_checkBoxBold->SetValue( item->m_Bold );
  197. m_checkBoxItalic->SetValue( item->m_Italic );
  198. switch( item->m_Hjustify )
  199. {
  200. case GR_TEXT_HJUSTIFY_LEFT: m_choiceHjustify->SetSelection( 0 ); break;
  201. case GR_TEXT_HJUSTIFY_CENTER: m_choiceHjustify->SetSelection( 1 ); break;
  202. case GR_TEXT_HJUSTIFY_RIGHT: m_choiceHjustify->SetSelection( 2 ); break;
  203. }
  204. switch( item->m_Vjustify )
  205. {
  206. case GR_TEXT_VJUSTIFY_TOP: m_choiceVjustify->SetSelection( 0 ); break;
  207. case GR_TEXT_VJUSTIFY_CENTER: m_choiceVjustify->SetSelection( 1 ); break;
  208. case GR_TEXT_VJUSTIFY_BOTTOM: m_choiceVjustify->SetSelection( 2 ); break;
  209. }
  210. // Text size
  211. m_textCtrlTextSizeXBinder.SetDoubleValue(
  212. From_User_Unit( EDA_UNITS::MILLIMETRES, item->m_TextSize.x ) );
  213. m_textCtrlTextSizeYBinder.SetDoubleValue(
  214. From_User_Unit( EDA_UNITS::MILLIMETRES, item->m_TextSize.y ) );
  215. }
  216. if( aItem->GetType() == WS_DATA_ITEM::WS_POLYPOLYGON )
  217. {
  218. WS_DATA_ITEM_POLYGONS* item = (WS_DATA_ITEM_POLYGONS*) aItem;
  219. // Rotation (poly and text)
  220. msg.Printf( wxT("%.3f"), item->m_Orient );
  221. m_textCtrlRotation->SetValue( msg );
  222. }
  223. if( aItem->GetType() == WS_DATA_ITEM::WS_BITMAP )
  224. {
  225. WS_DATA_ITEM_BITMAP* item = (WS_DATA_ITEM_BITMAP*) aItem;
  226. // select definition in PPI
  227. msg.Printf( wxT("%d"), item->GetPPI() );
  228. m_textCtrlBitmapPPI->SetValue( msg );
  229. }
  230. m_SizerItemProperties->Show( true );
  231. m_SizerTextOptions->Show( aItem->GetType() == WS_DATA_ITEM::WS_TEXT );
  232. m_sbSizerEndPosition->Show( aItem->GetType() == WS_DATA_ITEM::WS_SEGMENT
  233. || aItem->GetType() == WS_DATA_ITEM::WS_RECT );
  234. m_SizerLineThickness->Show( aItem->GetType() != WS_DATA_ITEM::WS_BITMAP );
  235. // Polygons have no defaut value for line width
  236. m_staticTextInfoThickness->Show( aItem->GetType() != WS_DATA_ITEM::WS_POLYPOLYGON );
  237. m_SizerRotation->Show( aItem->GetType() == WS_DATA_ITEM::WS_TEXT
  238. || aItem->GetType() == WS_DATA_ITEM::WS_POLYPOLYGON );
  239. m_SizerPPI->Show( aItem->GetType() == WS_DATA_ITEM::WS_BITMAP );
  240. m_staticTextInclabel->Show( aItem->GetType() == WS_DATA_ITEM::WS_TEXT );
  241. m_textCtrlTextIncrement->Show( aItem->GetType() == WS_DATA_ITEM::WS_TEXT );
  242. // Repeat parameters
  243. msg.Printf( wxT("%d"), aItem->m_RepeatCount );
  244. m_textCtrlRepeatCount->SetValue( msg );
  245. m_textCtrlStepXBinder.SetDoubleValue(
  246. From_User_Unit( EDA_UNITS::MILLIMETRES, aItem->m_IncrementVector.x ) );
  247. m_textCtrlStepYBinder.SetDoubleValue(
  248. From_User_Unit( EDA_UNITS::MILLIMETRES, aItem->m_IncrementVector.y ) );
  249. // The number of widgets was modified, so recalculate sizers
  250. m_swItemProperties->Layout();
  251. #ifdef __WXGTK__
  252. // This call is mandatory on wxGTK to initialize the right virtual size and therefore
  253. // scrollbars, but for some reason, create issues on Windows (incorrect disply
  254. // until the frame is resized). Joys of multiplatform dev.
  255. m_swItemProperties->Fit();
  256. #endif
  257. // send a size event to be sure scrollbars will be added/removed as needed
  258. m_swItemProperties->PostSizeEvent();
  259. m_swItemProperties->Refresh();
  260. }
  261. // Event function called by clicking on the OK button
  262. void PROPERTIES_FRAME::OnAcceptPrms( wxCommandEvent& event )
  263. {
  264. PL_SELECTION_TOOL* selTool = m_parent->GetToolManager()->GetTool<PL_SELECTION_TOOL>();
  265. PL_SELECTION& selection = selTool->GetSelection();
  266. m_parent->SaveCopyInUndoList();
  267. WS_DRAW_ITEM_BASE* drawItem = (WS_DRAW_ITEM_BASE*) selection.Front();
  268. if( drawItem )
  269. {
  270. WS_DATA_ITEM* dataItem = drawItem->GetPeer();
  271. CopyPrmsFromPanelToItem( dataItem );
  272. // Be sure what is displayed is what is set for item
  273. // (mainly, texts can be modified if they contain "\n")
  274. CopyPrmsFromItemToPanel( dataItem );
  275. m_parent->GetCanvas()->GetView()->Update( drawItem );
  276. }
  277. CopyPrmsFromPanelToGeneral();
  278. // Refresh values, exactly as they are converted, to avoid any mistake
  279. CopyPrmsFromGeneralToPanel();
  280. m_parent->OnModify();
  281. // Rebuild the draw list with the new parameters
  282. m_parent->GetCanvas()->DisplayWorksheet();
  283. m_parent->GetCanvas()->Refresh();
  284. }
  285. void PROPERTIES_FRAME::OnSetDefaultValues( wxCommandEvent& event )
  286. {
  287. WS_DATA_MODEL& model = WS_DATA_MODEL::GetTheInstance();
  288. model.m_DefaultTextSize = DSIZE( TB_DEFAULT_TEXTSIZE, TB_DEFAULT_TEXTSIZE );
  289. model.m_DefaultLineWidth = 0.15;
  290. model.m_DefaultTextThickness = 0.15;
  291. CopyPrmsFromGeneralToPanel();
  292. // Rebuild the draw list with the new parameters
  293. m_parent->GetCanvas()->DisplayWorksheet();
  294. m_parent->GetCanvas()->Refresh();
  295. }
  296. // Data transfert from properties frame to item parameters
  297. bool PROPERTIES_FRAME::CopyPrmsFromPanelToItem( WS_DATA_ITEM* aItem )
  298. {
  299. if( aItem == NULL )
  300. return false;
  301. wxString msg;
  302. // Import common parameters:
  303. aItem->m_Info = m_textCtrlComment->GetValue();
  304. switch( m_choicePageOpt->GetSelection() )
  305. {
  306. default:
  307. case 0: aItem->SetPage1Option( ALL_PAGES ); break;
  308. case 1: aItem->SetPage1Option( FIRST_PAGE_ONLY ); break;
  309. case 2: aItem->SetPage1Option( SUBSEQUENT_PAGES ); break;
  310. }
  311. // Import thickness
  312. aItem->m_LineWidth = To_User_Unit( EDA_UNITS::MILLIMETRES, m_textCtrlThicknessBinder.GetValue() );
  313. // Import Start point
  314. aItem->m_Pos.m_Pos.x = To_User_Unit( EDA_UNITS::MILLIMETRES, m_textCtrlPosXBinder.GetValue() );
  315. aItem->m_Pos.m_Pos.y = To_User_Unit( EDA_UNITS::MILLIMETRES, m_textCtrlPosYBinder.GetValue() );
  316. switch( m_comboBoxCornerPos->GetSelection() )
  317. {
  318. case 2: aItem->m_Pos.m_Anchor = RB_CORNER; break;
  319. case 0: aItem->m_Pos.m_Anchor = RT_CORNER; break;
  320. case 3: aItem->m_Pos.m_Anchor = LB_CORNER; break;
  321. case 1: aItem->m_Pos.m_Anchor = LT_CORNER; break;
  322. }
  323. // Import End point
  324. aItem->m_End.m_Pos.x = To_User_Unit( EDA_UNITS::MILLIMETRES, m_textCtrlEndXBinder.GetValue() );
  325. aItem->m_End.m_Pos.y = To_User_Unit( EDA_UNITS::MILLIMETRES, m_textCtrlEndYBinder.GetValue() );
  326. switch( m_comboBoxCornerEnd->GetSelection() )
  327. {
  328. case 2: aItem->m_End.m_Anchor = RB_CORNER; break;
  329. case 0: aItem->m_End.m_Anchor = RT_CORNER; break;
  330. case 3: aItem->m_End.m_Anchor = LB_CORNER; break;
  331. case 1: aItem->m_End.m_Anchor = LT_CORNER; break;
  332. }
  333. // Import Repeat prms
  334. long itmp;
  335. msg = m_textCtrlRepeatCount->GetValue();
  336. msg.ToLong( &itmp );
  337. aItem->m_RepeatCount = itmp;
  338. aItem->m_IncrementVector.x = To_User_Unit( EDA_UNITS::MILLIMETRES, m_textCtrlStepXBinder.GetValue() );
  339. aItem->m_IncrementVector.y = To_User_Unit( EDA_UNITS::MILLIMETRES, m_textCtrlStepYBinder.GetValue() );
  340. if( aItem->GetType() == WS_DATA_ITEM::WS_TEXT )
  341. {
  342. WS_DATA_ITEM_TEXT* item = (WS_DATA_ITEM_TEXT*) aItem;
  343. item->m_TextBase = m_stcText->GetValue();
  344. msg = m_textCtrlTextIncrement->GetValue();
  345. msg.ToLong( &itmp );
  346. item->m_IncrementLabel = itmp;
  347. item->m_Bold = m_checkBoxBold->IsChecked();
  348. item->m_Italic = m_checkBoxItalic->IsChecked();
  349. switch( m_choiceHjustify->GetSelection() )
  350. {
  351. case 0: item->m_Hjustify = GR_TEXT_HJUSTIFY_LEFT; break;
  352. case 1: item->m_Hjustify = GR_TEXT_HJUSTIFY_CENTER; break;
  353. case 2: item->m_Hjustify = GR_TEXT_HJUSTIFY_RIGHT; break;
  354. }
  355. switch( m_choiceVjustify->GetSelection() )
  356. {
  357. case 0: item->m_Vjustify = GR_TEXT_VJUSTIFY_TOP; break;
  358. case 1: item->m_Vjustify = GR_TEXT_VJUSTIFY_CENTER; break;
  359. case 2: item->m_Vjustify = GR_TEXT_VJUSTIFY_BOTTOM; break;
  360. }
  361. msg = m_textCtrlRotation->GetValue();
  362. item->m_Orient = DoubleValueFromString( EDA_UNITS::UNSCALED, msg );
  363. // Import text size
  364. item->m_TextSize.x =
  365. To_User_Unit( EDA_UNITS::MILLIMETRES, m_textCtrlTextSizeXBinder.GetValue() );
  366. item->m_TextSize.y =
  367. To_User_Unit( EDA_UNITS::MILLIMETRES, m_textCtrlTextSizeYBinder.GetValue() );
  368. // Import constraints:
  369. item->m_BoundingBoxSize.x =
  370. To_User_Unit( EDA_UNITS::MILLIMETRES, m_textCtrlConstraintXBinder.GetValue() );
  371. item->m_BoundingBoxSize.y =
  372. To_User_Unit( EDA_UNITS::MILLIMETRES, m_textCtrlConstraintYBinder.GetValue() );
  373. }
  374. if( aItem->GetType() == WS_DATA_ITEM::WS_POLYPOLYGON )
  375. {
  376. WS_DATA_ITEM_POLYGONS* item = (WS_DATA_ITEM_POLYGONS*) aItem;
  377. msg = m_textCtrlRotation->GetValue();
  378. item->m_Orient = DoubleValueFromString( EDA_UNITS::UNSCALED, msg );
  379. }
  380. if( aItem->GetType() == WS_DATA_ITEM::WS_BITMAP )
  381. {
  382. WS_DATA_ITEM_BITMAP* item = (WS_DATA_ITEM_BITMAP*) aItem;
  383. // Set definition in PPI
  384. long value;
  385. msg = m_textCtrlBitmapPPI->GetValue();
  386. if( msg.ToLong( &value ) )
  387. item->SetPPI( (int)value );
  388. }
  389. return true;
  390. }
  391. void PROPERTIES_FRAME::onScintillaCharAdded( wxStyledTextEvent &aEvent )
  392. {
  393. wxArrayString autocompleteTokens;
  394. int pos = m_stcText->GetCurrentPos();
  395. int start = m_stcText->WordStartPosition( pos, true );
  396. wxString partial;
  397. if( start >= 2
  398. && m_stcText->GetCharAt( start-2 ) == '$'
  399. && m_stcText->GetCharAt( start-1 ) == '{' )
  400. {
  401. WS_DRAW_ITEM_LIST::GetTextVars( &autocompleteTokens );
  402. partial = m_stcText->GetTextRange( start, pos );
  403. for( std::pair<wxString, wxString> entry : m_parent->Prj().GetTextVars() )
  404. autocompleteTokens.push_back( entry.first );
  405. }
  406. m_scintillaTricks->DoAutocomplete( partial, autocompleteTokens );
  407. m_stcText->SetFocus();
  408. }