ToolTransform.py 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832
  1. from PyQt5 import QtGui, QtCore, QtWidgets
  2. from PyQt5.QtCore import Qt
  3. from GUIElements import FCEntry, FCButton, OptionalInputSection
  4. from FlatCAMTool import FlatCAMTool
  5. from FlatCAMObj import *
  6. class ToolTransform(FlatCAMTool):
  7. toolName = "Object Transform"
  8. rotateName = "Rotate"
  9. skewName = "Skew/Shear"
  10. scaleName = "Scale"
  11. flipName = "Mirror (Flip)"
  12. offsetName = "Offset"
  13. def __init__(self, app):
  14. FlatCAMTool.__init__(self, app)
  15. self.transform_lay = QtWidgets.QVBoxLayout()
  16. self.layout.addLayout(self.transform_lay)
  17. ## Title
  18. title_label = QtWidgets.QLabel("%s" % self.toolName)
  19. title_label.setStyleSheet("""
  20. QLabel
  21. {
  22. font-size: 16px;
  23. font-weight: bold;
  24. }
  25. """)
  26. self.transform_lay.addWidget(title_label)
  27. self.empty_label = QtWidgets.QLabel("")
  28. self.empty_label.setFixedWidth(50)
  29. self.empty_label1 = QtWidgets.QLabel("")
  30. self.empty_label1.setFixedWidth(70)
  31. self.empty_label2 = QtWidgets.QLabel("")
  32. self.empty_label2.setFixedWidth(70)
  33. self.empty_label3 = QtWidgets.QLabel("")
  34. self.empty_label3.setFixedWidth(70)
  35. self.empty_label4 = QtWidgets.QLabel("")
  36. self.empty_label4.setFixedWidth(70)
  37. self.transform_lay.addWidget(self.empty_label)
  38. ## Rotate Title
  39. rotate_title_label = QtWidgets.QLabel("<font size=3><b>%s</b></font>" % self.rotateName)
  40. self.transform_lay.addWidget(rotate_title_label)
  41. ## Layout
  42. form_layout = QtWidgets.QFormLayout()
  43. self.transform_lay.addLayout(form_layout)
  44. form_child = QtWidgets.QHBoxLayout()
  45. self.rotate_label = QtWidgets.QLabel("Angle:")
  46. self.rotate_label.setToolTip(
  47. "Angle for Rotation action, in degrees.\n"
  48. "Float number between -360 and 359.\n"
  49. "Positive numbers for CW motion.\n"
  50. "Negative numbers for CCW motion."
  51. )
  52. self.rotate_label.setFixedWidth(50)
  53. self.rotate_entry = FCEntry()
  54. # self.rotate_entry.setFixedWidth(60)
  55. self.rotate_entry.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
  56. self.rotate_button = FCButton()
  57. self.rotate_button.set_value("Rotate")
  58. self.rotate_button.setToolTip(
  59. "Rotate the selected object(s).\n"
  60. "The point of reference is the middle of\n"
  61. "the bounding box for all selected objects."
  62. )
  63. self.rotate_button.setFixedWidth(60)
  64. form_child.addWidget(self.rotate_entry)
  65. form_child.addWidget(self.rotate_button)
  66. form_layout.addRow(self.rotate_label, form_child)
  67. self.transform_lay.addWidget(self.empty_label1)
  68. ## Skew Title
  69. skew_title_label = QtWidgets.QLabel("<font size=3><b>%s</b></font>" % self.skewName)
  70. self.transform_lay.addWidget(skew_title_label)
  71. ## Form Layout
  72. form1_layout = QtWidgets.QFormLayout()
  73. self.transform_lay.addLayout(form1_layout)
  74. form1_child_1 = QtWidgets.QHBoxLayout()
  75. form1_child_2 = QtWidgets.QHBoxLayout()
  76. self.skewx_label = QtWidgets.QLabel("Angle X:")
  77. self.skewx_label.setToolTip(
  78. "Angle for Skew action, in degrees.\n"
  79. "Float number between -360 and 359."
  80. )
  81. self.skewx_label.setFixedWidth(50)
  82. self.skewx_entry = FCEntry()
  83. self.skewx_entry.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
  84. # self.skewx_entry.setFixedWidth(60)
  85. self.skewx_button = FCButton()
  86. self.skewx_button.set_value("Skew X")
  87. self.skewx_button.setToolTip(
  88. "Skew/shear the selected object(s).\n"
  89. "The point of reference is the middle of\n"
  90. "the bounding box for all selected objects.")
  91. self.skewx_button.setFixedWidth(60)
  92. self.skewy_label = QtWidgets.QLabel("Angle Y:")
  93. self.skewy_label.setToolTip(
  94. "Angle for Skew action, in degrees.\n"
  95. "Float number between -360 and 359."
  96. )
  97. self.skewy_label.setFixedWidth(50)
  98. self.skewy_entry = FCEntry()
  99. self.skewy_entry.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
  100. # self.skewy_entry.setFixedWidth(60)
  101. self.skewy_button = FCButton()
  102. self.skewy_button.set_value("Skew Y")
  103. self.skewy_button.setToolTip(
  104. "Skew/shear the selected object(s).\n"
  105. "The point of reference is the middle of\n"
  106. "the bounding box for all selected objects.")
  107. self.skewy_button.setFixedWidth(60)
  108. form1_child_1.addWidget(self.skewx_entry)
  109. form1_child_1.addWidget(self.skewx_button)
  110. form1_child_2.addWidget(self.skewy_entry)
  111. form1_child_2.addWidget(self.skewy_button)
  112. form1_layout.addRow(self.skewx_label, form1_child_1)
  113. form1_layout.addRow(self.skewy_label, form1_child_2)
  114. self.transform_lay.addWidget(self.empty_label2)
  115. ## Scale Title
  116. scale_title_label = QtWidgets.QLabel("<font size=3><b>%s</b></font>" % self.scaleName)
  117. self.transform_lay.addWidget(scale_title_label)
  118. ## Form Layout
  119. form2_layout = QtWidgets.QFormLayout()
  120. self.transform_lay.addLayout(form2_layout)
  121. form2_child_1 = QtWidgets.QHBoxLayout()
  122. form2_child_2 = QtWidgets.QHBoxLayout()
  123. self.scalex_label = QtWidgets.QLabel("Factor X:")
  124. self.scalex_label.setToolTip(
  125. "Factor for Scale action over X axis."
  126. )
  127. self.scalex_label.setFixedWidth(50)
  128. self.scalex_entry = FCEntry()
  129. self.scalex_entry.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
  130. # self.scalex_entry.setFixedWidth(60)
  131. self.scalex_button = FCButton()
  132. self.scalex_button.set_value("Scale X")
  133. self.scalex_button.setToolTip(
  134. "Scale the selected object(s).\n"
  135. "The point of reference depends on \n"
  136. "the Scale reference checkbox state.")
  137. self.scalex_button.setFixedWidth(60)
  138. self.scaley_label = QtWidgets.QLabel("Factor Y:")
  139. self.scaley_label.setToolTip(
  140. "Factor for Scale action over Y axis."
  141. )
  142. self.scaley_label.setFixedWidth(50)
  143. self.scaley_entry = FCEntry()
  144. self.scaley_entry.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
  145. # self.scaley_entry.setFixedWidth(60)
  146. self.scaley_button = FCButton()
  147. self.scaley_button.set_value("Scale Y")
  148. self.scaley_button.setToolTip(
  149. "Scale the selected object(s).\n"
  150. "The point of reference depends on \n"
  151. "the Scale reference checkbox state.")
  152. self.scaley_button.setFixedWidth(60)
  153. self.scale_link_cb = FCCheckBox()
  154. self.scale_link_cb.set_value(True)
  155. self.scale_link_cb.setText("Link")
  156. self.scale_link_cb.setToolTip(
  157. "Scale the selected object(s)\n"
  158. "using the Scale Factor X for both axis.")
  159. self.scale_link_cb.setFixedWidth(50)
  160. self.scale_zero_ref_cb = FCCheckBox()
  161. self.scale_zero_ref_cb.set_value(True)
  162. self.scale_zero_ref_cb.setText("Scale Reference")
  163. self.scale_zero_ref_cb.setToolTip(
  164. "Scale the selected object(s)\n"
  165. "using the origin reference when checked,\n"
  166. "and the center of the biggest bounding box\n"
  167. "of the selected objects when unchecked.")
  168. form2_child_1.addWidget(self.scalex_entry)
  169. form2_child_1.addWidget(self.scalex_button)
  170. form2_child_2.addWidget(self.scaley_entry)
  171. form2_child_2.addWidget(self.scaley_button)
  172. form2_layout.addRow(self.scalex_label, form2_child_1)
  173. form2_layout.addRow(self.scaley_label, form2_child_2)
  174. form2_layout.addRow(self.scale_link_cb, self.scale_zero_ref_cb)
  175. self.ois_scale = OptionalInputSection(self.scale_link_cb, [self.scaley_entry, self.scaley_button], logic=False)
  176. self.transform_lay.addWidget(self.empty_label3)
  177. ## Offset Title
  178. offset_title_label = QtWidgets.QLabel("<font size=3><b>%s</b></font>" % self.offsetName)
  179. self.transform_lay.addWidget(offset_title_label)
  180. ## Form Layout
  181. form3_layout = QtWidgets.QFormLayout()
  182. self.transform_lay.addLayout(form3_layout)
  183. form3_child_1 = QtWidgets.QHBoxLayout()
  184. form3_child_2 = QtWidgets.QHBoxLayout()
  185. self.offx_label = QtWidgets.QLabel("Value X:")
  186. self.offx_label.setToolTip(
  187. "Value for Offset action on X axis."
  188. )
  189. self.offx_label.setFixedWidth(50)
  190. self.offx_entry = FCEntry()
  191. self.offx_entry.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
  192. # self.offx_entry.setFixedWidth(60)
  193. self.offx_button = FCButton()
  194. self.offx_button.set_value("Offset X")
  195. self.offx_button.setToolTip(
  196. "Offset the selected object(s).\n"
  197. "The point of reference is the middle of\n"
  198. "the bounding box for all selected objects.\n")
  199. self.offx_button.setFixedWidth(60)
  200. self.offy_label = QtWidgets.QLabel("Value Y:")
  201. self.offy_label.setToolTip(
  202. "Value for Offset action on Y axis."
  203. )
  204. self.offy_label.setFixedWidth(50)
  205. self.offy_entry = FCEntry()
  206. self.offy_entry.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
  207. # self.offy_entry.setFixedWidth(60)
  208. self.offy_button = FCButton()
  209. self.offy_button.set_value("Offset Y")
  210. self.offy_button.setToolTip(
  211. "Offset the selected object(s).\n"
  212. "The point of reference is the middle of\n"
  213. "the bounding box for all selected objects.\n")
  214. self.offy_button.setFixedWidth(60)
  215. form3_child_1.addWidget(self.offx_entry)
  216. form3_child_1.addWidget(self.offx_button)
  217. form3_child_2.addWidget(self.offy_entry)
  218. form3_child_2.addWidget(self.offy_button)
  219. form3_layout.addRow(self.offx_label, form3_child_1)
  220. form3_layout.addRow(self.offy_label, form3_child_2)
  221. self.transform_lay.addWidget(self.empty_label4)
  222. ## Flip Title
  223. flip_title_label = QtWidgets.QLabel("<font size=3><b>%s</b></font>" % self.flipName)
  224. self.transform_lay.addWidget(flip_title_label)
  225. ## Form Layout
  226. form4_layout = QtWidgets.QFormLayout()
  227. form4_child_hlay = QtWidgets.QHBoxLayout()
  228. self.transform_lay.addLayout(form4_child_hlay)
  229. self.transform_lay.addLayout(form4_layout)
  230. form4_child_1 = QtWidgets.QHBoxLayout()
  231. self.flipx_button = FCButton()
  232. self.flipx_button.set_value("Flip on X")
  233. self.flipx_button.setToolTip(
  234. "Flip the selected object(s) over the X axis.\n"
  235. "Does not create a new object.\n "
  236. )
  237. self.flipx_button.setFixedWidth(60)
  238. self.flipy_button = FCButton()
  239. self.flipy_button.set_value("Flip on Y")
  240. self.flipy_button.setToolTip(
  241. "Flip the selected object(s) over the X axis.\n"
  242. "Does not create a new object.\n "
  243. )
  244. self.flipy_button.setFixedWidth(60)
  245. self.flip_ref_cb = FCCheckBox()
  246. self.flip_ref_cb.set_value(True)
  247. self.flip_ref_cb.setText("Ref Pt")
  248. self.flip_ref_cb.setToolTip(
  249. "Flip the selected object(s)\n"
  250. "around the point in Point Entry Field.\n"
  251. "\n"
  252. "The point coordinates can be captured by\n"
  253. "left click on canvas together with pressing\n"
  254. "SHIFT key. \n"
  255. "Then click Add button to insert coordinates.\n"
  256. "Or enter the coords in format (x, y) in the\n"
  257. "Point Entry field and click Flip on X(Y)")
  258. self.flip_ref_cb.setFixedWidth(50)
  259. self.flip_ref_label = QtWidgets.QLabel("Point:")
  260. self.flip_ref_label.setToolTip(
  261. "Coordinates in format (x, y) used as reference for mirroring.\n"
  262. "The 'x' in (x, y) will be used when using Flip on X and\n"
  263. "the 'y' in (x, y) will be used when using Flip on Y and"
  264. )
  265. self.flip_ref_label.setFixedWidth(50)
  266. self.flip_ref_entry = EvalEntry2("(0, 0)")
  267. self.flip_ref_entry.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
  268. # self.flip_ref_entry.setFixedWidth(60)
  269. self.flip_ref_button = FCButton()
  270. self.flip_ref_button.set_value("Add")
  271. self.flip_ref_button.setToolTip(
  272. "The point coordinates can be captured by\n"
  273. "left click on canvas together with pressing\n"
  274. "SHIFT key. Then click Add button to insert.")
  275. self.flip_ref_button.setFixedWidth(60)
  276. form4_child_hlay.addStretch()
  277. form4_child_hlay.addWidget(self.flipx_button)
  278. form4_child_hlay.addWidget(self.flipy_button)
  279. form4_child_1.addWidget(self.flip_ref_entry)
  280. form4_child_1.addWidget(self.flip_ref_button)
  281. form4_layout.addRow(self.flip_ref_cb)
  282. form4_layout.addRow(self.flip_ref_label, form4_child_1)
  283. self.ois_flip = OptionalInputSection(self.flip_ref_cb,
  284. [self.flip_ref_entry, self.flip_ref_button], logic=True)
  285. self.transform_lay.addStretch()
  286. ## Signals
  287. self.rotate_button.clicked.connect(self.on_rotate)
  288. self.skewx_button.clicked.connect(self.on_skewx)
  289. self.skewy_button.clicked.connect(self.on_skewy)
  290. self.scalex_button.clicked.connect(self.on_scalex)
  291. self.scaley_button.clicked.connect(self.on_scaley)
  292. self.offx_button.clicked.connect(self.on_offx)
  293. self.offy_button.clicked.connect(self.on_offy)
  294. self.flipx_button.clicked.connect(self.on_flipx)
  295. self.flipy_button.clicked.connect(self.on_flipy)
  296. self.flip_ref_button.clicked.connect(self.on_flip_add_coords)
  297. self.rotate_entry.returnPressed.connect(self.on_rotate)
  298. self.skewx_entry.returnPressed.connect(self.on_skewx)
  299. self.skewy_entry.returnPressed.connect(self.on_skewy)
  300. self.scalex_entry.returnPressed.connect(self.on_scalex)
  301. self.scaley_entry.returnPressed.connect(self.on_scaley)
  302. self.offx_entry.returnPressed.connect(self.on_offx)
  303. self.offy_entry.returnPressed.connect(self.on_offy)
  304. def run(self):
  305. self.app.report_usage("ToolTransform()")
  306. FlatCAMTool.run(self)
  307. self.set_tool_ui()
  308. # if the splitter us hidden, display it
  309. if self.app.ui.splitter.sizes()[0] == 0:
  310. self.app.ui.splitter.setSizes([1, 1])
  311. self.app.ui.notebook.setTabText(2, "Transform Tool")
  312. def install(self, icon=None, separator=None, **kwargs):
  313. FlatCAMTool.install(self, icon, separator, shortcut='ALT+T', **kwargs)
  314. def set_tool_ui(self):
  315. ## Initialize form
  316. self.rotate_entry.set_value('0')
  317. self.skewx_entry.set_value('0')
  318. self.skewy_entry.set_value('0')
  319. self.scalex_entry.set_value('1')
  320. self.scaley_entry.set_value('1')
  321. self.offx_entry.set_value('0')
  322. self.offy_entry.set_value('0')
  323. self.flip_ref_cb.setChecked(False)
  324. def on_rotate(self):
  325. try:
  326. value = float(self.rotate_entry.get_value())
  327. except ValueError:
  328. # try to convert comma to decimal point. if it's still not working error message and return
  329. try:
  330. value = float(self.rotate_entry.get_value().replace(',', '.'))
  331. except ValueError:
  332. self.app.inform.emit("[ERROR_NOTCL]Wrong value format entered for Rotate, "
  333. "use a number.")
  334. return
  335. self.app.worker_task.emit({'fcn': self.on_rotate_action,
  336. 'params': [value]})
  337. # self.on_rotate_action(value)
  338. return
  339. def on_flipx(self):
  340. # self.on_flip("Y")
  341. axis = 'Y'
  342. self.app.worker_task.emit({'fcn': self.on_flip,
  343. 'params': [axis]})
  344. return
  345. def on_flipy(self):
  346. # self.on_flip("X")
  347. axis = 'X'
  348. self.app.worker_task.emit({'fcn': self.on_flip,
  349. 'params': [axis]})
  350. return
  351. def on_flip_add_coords(self):
  352. val = self.app.clipboard.text()
  353. self.flip_ref_entry.set_value(val)
  354. def on_skewx(self):
  355. try:
  356. value = float(self.skewx_entry.get_value())
  357. except ValueError:
  358. # try to convert comma to decimal point. if it's still not working error message and return
  359. try:
  360. value = float(self.skewx_entry.get_value().replace(',', '.'))
  361. except ValueError:
  362. self.app.inform.emit("[ERROR_NOTCL]Wrong value format entered for Skew X, "
  363. "use a number.")
  364. return
  365. # self.on_skew("X", value)
  366. axis = 'X'
  367. self.app.worker_task.emit({'fcn': self.on_skew,
  368. 'params': [axis, value]})
  369. return
  370. def on_skewy(self):
  371. try:
  372. value = float(self.skewy_entry.get_value())
  373. except ValueError:
  374. # try to convert comma to decimal point. if it's still not working error message and return
  375. try:
  376. value = float(self.skewy_entry.get_value().replace(',', '.'))
  377. except ValueError:
  378. self.app.inform.emit("[ERROR_NOTCL]Wrong value format entered for Skew Y, "
  379. "use a number.")
  380. return
  381. # self.on_skew("Y", value)
  382. axis = 'Y'
  383. self.app.worker_task.emit({'fcn': self.on_skew,
  384. 'params': [axis, value]})
  385. return
  386. def on_scalex(self):
  387. try:
  388. xvalue = float(self.scalex_entry.get_value())
  389. except ValueError:
  390. # try to convert comma to decimal point. if it's still not working error message and return
  391. try:
  392. xvalue = float(self.scalex_entry.get_value().replace(',', '.'))
  393. except ValueError:
  394. self.app.inform.emit("[ERROR_NOTCL]Wrong value format entered for Scale X, "
  395. "use a number.")
  396. return
  397. # scaling to zero has no sense so we remove it, because scaling with 1 does nothing
  398. if xvalue == 0:
  399. xvalue = 1
  400. if self.scale_link_cb.get_value():
  401. yvalue = xvalue
  402. else:
  403. yvalue = 1
  404. axis = 'X'
  405. point = (0, 0)
  406. if self.scale_zero_ref_cb.get_value():
  407. self.app.worker_task.emit({'fcn': self.on_scale,
  408. 'params': [axis, xvalue, yvalue, point]})
  409. # self.on_scale("X", xvalue, yvalue, point=(0,0))
  410. else:
  411. # self.on_scale("X", xvalue, yvalue)
  412. self.app.worker_task.emit({'fcn': self.on_scale,
  413. 'params': [axis, xvalue, yvalue]})
  414. return
  415. def on_scaley(self):
  416. xvalue = 1
  417. try:
  418. yvalue = float(self.scaley_entry.get_value())
  419. except ValueError:
  420. # try to convert comma to decimal point. if it's still not working error message and return
  421. try:
  422. yvalue = float(self.scaley_entry.get_value().replace(',', '.'))
  423. except ValueError:
  424. self.app.inform.emit("[ERROR_NOTCL]Wrong value format entered for Scale Y, "
  425. "use a number.")
  426. return
  427. # scaling to zero has no sense so we remove it, because scaling with 1 does nothing
  428. if yvalue == 0:
  429. yvalue = 1
  430. axis = 'Y'
  431. point = (0, 0)
  432. if self.scale_zero_ref_cb.get_value():
  433. self.app.worker_task.emit({'fcn': self.on_scale,
  434. 'params': [axis, xvalue, yvalue, point]})
  435. # self.on_scale("Y", xvalue, yvalue, point=(0,0))
  436. else:
  437. # self.on_scale("Y", xvalue, yvalue)
  438. self.app.worker_task.emit({'fcn': self.on_scale,
  439. 'params': [axis, xvalue, yvalue]})
  440. return
  441. def on_offx(self):
  442. try:
  443. value = float(self.offx_entry.get_value())
  444. except ValueError:
  445. # try to convert comma to decimal point. if it's still not working error message and return
  446. try:
  447. value = float(self.offx_entry.get_value().replace(',', '.'))
  448. except ValueError:
  449. self.app.inform.emit("[ERROR_NOTCL]Wrong value format entered for Offset X, "
  450. "use a number.")
  451. return
  452. # self.on_offset("X", value)
  453. axis = 'X'
  454. self.app.worker_task.emit({'fcn': self.on_offset,
  455. 'params': [axis, value]})
  456. return
  457. def on_offy(self):
  458. try:
  459. value = float(self.offy_entry.get_value())
  460. except ValueError:
  461. # try to convert comma to decimal point. if it's still not working error message and return
  462. try:
  463. value = float(self.offy_entry.get_value().replace(',', '.'))
  464. except ValueError:
  465. self.app.inform.emit("[ERROR_NOTCL]Wrong value format entered for Offset Y, "
  466. "use a number.")
  467. return
  468. # self.on_offset("Y", value)
  469. axis = 'Y'
  470. self.app.worker_task.emit({'fcn': self.on_offset,
  471. 'params': [axis, value]})
  472. return
  473. def on_rotate_action(self, num):
  474. obj_list = self.app.collection.get_selected()
  475. xminlist = []
  476. yminlist = []
  477. xmaxlist = []
  478. ymaxlist = []
  479. if not obj_list:
  480. self.app.inform.emit("[WARNING_NOTCL] No object selected. Please Select an object to rotate!")
  481. return
  482. else:
  483. with self.app.proc_container.new("Appying Rotate"):
  484. try:
  485. # first get a bounding box to fit all
  486. for obj in obj_list:
  487. if isinstance(obj, FlatCAMCNCjob):
  488. pass
  489. else:
  490. xmin, ymin, xmax, ymax = obj.bounds()
  491. xminlist.append(xmin)
  492. yminlist.append(ymin)
  493. xmaxlist.append(xmax)
  494. ymaxlist.append(ymax)
  495. # get the minimum x,y and maximum x,y for all objects selected
  496. xminimal = min(xminlist)
  497. yminimal = min(yminlist)
  498. xmaximal = max(xmaxlist)
  499. ymaximal = max(ymaxlist)
  500. self.app.progress.emit(20)
  501. for sel_obj in obj_list:
  502. px = 0.5 * (xminimal + xmaximal)
  503. py = 0.5 * (yminimal + ymaximal)
  504. if isinstance(sel_obj, FlatCAMCNCjob):
  505. self.app.inform.emit("CNCJob objects can't be rotated.")
  506. else:
  507. sel_obj.rotate(-num, point=(px, py))
  508. sel_obj.plot()
  509. self.app.object_changed.emit(sel_obj)
  510. # add information to the object that it was changed and how much
  511. sel_obj.options['rotate'] = num
  512. self.app.inform.emit('[success]Rotate done ...')
  513. self.app.progress.emit(100)
  514. except Exception as e:
  515. self.app.inform.emit("[ERROR_NOTCL] Due of %s, rotation movement was not executed." % str(e))
  516. return
  517. def on_flip(self, axis):
  518. obj_list = self.app.collection.get_selected()
  519. xminlist = []
  520. yminlist = []
  521. xmaxlist = []
  522. ymaxlist = []
  523. if not obj_list:
  524. self.app.inform.emit("[WARNING_NOTCL] No object selected. Please Select an object to flip!")
  525. return
  526. else:
  527. with self.app.proc_container.new("Applying Flip"):
  528. try:
  529. # get mirroring coords from the point entry
  530. if self.flip_ref_cb.isChecked():
  531. px, py = eval('{}'.format(self.flip_ref_entry.text()))
  532. # get mirroing coords from the center of an all-enclosing bounding box
  533. else:
  534. # first get a bounding box to fit all
  535. for obj in obj_list:
  536. if isinstance(obj, FlatCAMCNCjob):
  537. pass
  538. else:
  539. xmin, ymin, xmax, ymax = obj.bounds()
  540. xminlist.append(xmin)
  541. yminlist.append(ymin)
  542. xmaxlist.append(xmax)
  543. ymaxlist.append(ymax)
  544. # get the minimum x,y and maximum x,y for all objects selected
  545. xminimal = min(xminlist)
  546. yminimal = min(yminlist)
  547. xmaximal = max(xmaxlist)
  548. ymaximal = max(ymaxlist)
  549. px = 0.5 * (xminimal + xmaximal)
  550. py = 0.5 * (yminimal + ymaximal)
  551. self.app.progress.emit(20)
  552. # execute mirroring
  553. for obj in obj_list:
  554. if isinstance(obj, FlatCAMCNCjob):
  555. self.app.inform.emit("CNCJob objects can't be mirrored/flipped.")
  556. else:
  557. if axis is 'X':
  558. obj.mirror('X', (px, py))
  559. # add information to the object that it was changed and how much
  560. # the axis is reversed because of the reference
  561. if 'mirror_y' in obj.options:
  562. obj.options['mirror_y'] = not obj.options['mirror_y']
  563. else:
  564. obj.options['mirror_y'] = True
  565. obj.plot()
  566. self.app.inform.emit('[success]Flip on the Y axis done ...')
  567. elif axis is 'Y':
  568. obj.mirror('Y', (px, py))
  569. # add information to the object that it was changed and how much
  570. # the axis is reversed because of the reference
  571. if 'mirror_x' in obj.options:
  572. obj.options['mirror_x'] = not obj.options['mirror_x']
  573. else:
  574. obj.options['mirror_x'] = True
  575. obj.plot()
  576. self.app.inform.emit('[success]Flip on the X axis done ...')
  577. self.app.object_changed.emit(obj)
  578. self.app.progress.emit(100)
  579. except Exception as e:
  580. self.app.inform.emit("[ERROR_NOTCL] Due of %s, Flip action was not executed." % str(e))
  581. return
  582. def on_skew(self, axis, num):
  583. obj_list = self.app.collection.get_selected()
  584. xminlist = []
  585. yminlist = []
  586. if not obj_list:
  587. self.app.inform.emit("[WARNING_NOTCL] No object selected. Please Select an object to shear/skew!")
  588. return
  589. else:
  590. with self.app.proc_container.new("Applying Skew"):
  591. try:
  592. # first get a bounding box to fit all
  593. for obj in obj_list:
  594. if isinstance(obj, FlatCAMCNCjob):
  595. pass
  596. else:
  597. xmin, ymin, xmax, ymax = obj.bounds()
  598. xminlist.append(xmin)
  599. yminlist.append(ymin)
  600. # get the minimum x,y and maximum x,y for all objects selected
  601. xminimal = min(xminlist)
  602. yminimal = min(yminlist)
  603. self.app.progress.emit(20)
  604. for obj in obj_list:
  605. if isinstance(obj, FlatCAMCNCjob):
  606. self.app.inform.emit("CNCJob objects can't be skewed.")
  607. else:
  608. if axis is 'X':
  609. obj.skew(num, 0, point=(xminimal, yminimal))
  610. # add information to the object that it was changed and how much
  611. obj.options['skew_x'] = num
  612. elif axis is 'Y':
  613. obj.skew(0, num, point=(xminimal, yminimal))
  614. # add information to the object that it was changed and how much
  615. obj.options['skew_y'] = num
  616. obj.plot()
  617. self.app.object_changed.emit(obj)
  618. self.app.inform.emit('[success]Skew on the %s axis done ...' % str(axis))
  619. self.app.progress.emit(100)
  620. except Exception as e:
  621. self.app.inform.emit("[ERROR_NOTCL] Due of %s, Skew action was not executed." % str(e))
  622. return
  623. def on_scale(self, axis, xfactor, yfactor, point=None):
  624. obj_list = self.app.collection.get_selected()
  625. xminlist = []
  626. yminlist = []
  627. xmaxlist = []
  628. ymaxlist = []
  629. if not obj_list:
  630. self.app.inform.emit("[WARNING_NOTCL] No object selected. Please Select an object to scale!")
  631. return
  632. else:
  633. with self.app.proc_container.new("Applying Scale"):
  634. try:
  635. # first get a bounding box to fit all
  636. for obj in obj_list:
  637. if isinstance(obj, FlatCAMCNCjob):
  638. pass
  639. else:
  640. xmin, ymin, xmax, ymax = obj.bounds()
  641. xminlist.append(xmin)
  642. yminlist.append(ymin)
  643. xmaxlist.append(xmax)
  644. ymaxlist.append(ymax)
  645. # get the minimum x,y and maximum x,y for all objects selected
  646. xminimal = min(xminlist)
  647. yminimal = min(yminlist)
  648. xmaximal = max(xmaxlist)
  649. ymaximal = max(ymaxlist)
  650. self.app.progress.emit(20)
  651. if point is None:
  652. px = 0.5 * (xminimal + xmaximal)
  653. py = 0.5 * (yminimal + ymaximal)
  654. else:
  655. px = 0
  656. py = 0
  657. for obj in obj_list:
  658. if isinstance(obj, FlatCAMCNCjob):
  659. self.app.inform.emit("CNCJob objects can't be scaled.")
  660. else:
  661. obj.scale(xfactor, yfactor, point=(px, py))
  662. # add information to the object that it was changed and how much
  663. obj.options['scale_x'] = xfactor
  664. obj.options['scale_y'] = yfactor
  665. obj.plot()
  666. self.app.object_changed.emit(obj)
  667. self.app.inform.emit('[success]Scale on the %s axis done ...' % str(axis))
  668. self.app.progress.emit(100)
  669. except Exception as e:
  670. self.app.inform.emit("[ERROR_NOTCL] Due of %s, Scale action was not executed." % str(e))
  671. return
  672. def on_offset(self, axis, num):
  673. obj_list = self.app.collection.get_selected()
  674. xminlist = []
  675. yminlist = []
  676. if not obj_list:
  677. self.app.inform.emit("[WARNING_NOTCL] No object selected. Please Select an object to offset!")
  678. return
  679. else:
  680. with self.app.proc_container.new("Applying Offset"):
  681. try:
  682. # first get a bounding box to fit all
  683. for obj in obj_list:
  684. if isinstance(obj, FlatCAMCNCjob):
  685. pass
  686. else:
  687. xmin, ymin, xmax, ymax = obj.bounds()
  688. xminlist.append(xmin)
  689. yminlist.append(ymin)
  690. # get the minimum x,y and maximum x,y for all objects selected
  691. xminimal = min(xminlist)
  692. yminimal = min(yminlist)
  693. self.app.progress.emit(20)
  694. for obj in obj_list:
  695. if isinstance(obj, FlatCAMCNCjob):
  696. self.app.inform.emit("CNCJob objects can't be offseted.")
  697. else:
  698. if axis is 'X':
  699. obj.offset((num, 0))
  700. # add information to the object that it was changed and how much
  701. obj.options['offset_x'] = num
  702. elif axis is 'Y':
  703. obj.offset((0, num))
  704. # add information to the object that it was changed and how much
  705. obj.options['offset_y'] = num
  706. obj.plot()
  707. self.app.object_changed.emit(obj)
  708. self.app.inform.emit('[success]Offset on the %s axis done ...' % str(axis))
  709. self.app.progress.emit(100)
  710. except Exception as e:
  711. self.app.inform.emit("[ERROR_NOTCL] Due of %s, Offset action was not executed." % str(e))
  712. return
  713. # end of file