1. === modified file 'src/desktop.cpp'
  2. --- src/desktop.cpp 2016-07-25 05:27:21 +0000
  3. +++ src/desktop.cpp 2017-05-30 23:44:28 +0000
  4. @@ -123,6 +123,7 @@
  5. waiting_cursor( false ),
  6. showing_dialogs ( false ),
  7. guides_active( false ),
  8. + on_live_extension(false),
  9. gr_item( NULL ),
  10. gr_point_type( POINT_LG_BEGIN ),
  11. gr_point_i( 0 ),
  12. @@ -557,6 +558,25 @@
  13. }
  14. }
  15. +void SPDesktop::setOverlay(bool set, bool freeze, double opacity){
  16. + if (opacity > 0.0 && opacity <= 1.0) {
  17. + if (set) {
  18. + getCanvas()->setOverlay(true, opacity);
  19. + } else {
  20. + getCanvas()->setOverlay(false, opacity);
  21. + }
  22. + }
  23. + if (freeze) {
  24. + if ( interaction_disabled_counter == 0) {
  25. + disableInteraction();
  26. + }
  27. + } else {
  28. + if ( interaction_disabled_counter > 0) {
  29. + enableInteraction();
  30. + }
  31. + }
  32. +}
  33. +
  34. // Pass-through LayerModel functions
  35. SPObject *SPDesktop::currentRoot() const
  36. {
  37. @@ -1436,12 +1456,14 @@
  38. void
  39. SPDesktop::enableInteraction()
  40. {
  41. - _widget->enableInteraction();
  42. + _widget->enableInteraction();
  43. + interaction_disabled_counter --;
  44. }
  45. void SPDesktop::disableInteraction()
  46. {
  47. - _widget->disableInteraction();
  48. + _widget->disableInteraction();
  49. + interaction_disabled_counter ++;
  50. }
  51. void SPDesktop::setWaitingCursor()
  52. === modified file 'src/desktop.h'
  53. --- src/desktop.h 2016-07-25 05:27:21 +0000
  54. +++ src/desktop.h 2017-05-30 23:55:16 +0000
  55. @@ -194,6 +194,8 @@
  56. /// \todo fixme: This has to be implemented in different way */
  57. guint guides_active : 1;
  58. + bool on_live_extension;
  59. + void setOverlay(bool set, bool freeze = true, double opacity = 0.2);
  60. // storage for selected dragger used by GrDrag as it's
  61. // created and deleted by tools
  62. === modified file 'src/display/sp-canvas.cpp'
  63. --- src/display/sp-canvas.cpp 2016-08-18 18:55:56 +0000
  64. +++ src/display/sp-canvas.cpp 2017-05-30 21:15:29 +0000
  65. @@ -937,7 +937,8 @@
  66. gtk_widget_set_has_window (GTK_WIDGET (canvas), TRUE);
  67. gtk_widget_set_double_buffered (GTK_WIDGET (canvas), FALSE);
  68. gtk_widget_set_can_focus (GTK_WIDGET (canvas), TRUE);
  69. -
  70. + canvas->_opacity = 0.2;
  71. + canvas->_overlay = false;
  72. canvas->_pick_event.type = GDK_LEAVE_NOTIFY;
  73. canvas->_pick_event.crossing.x = 0;
  74. canvas->_pick_event.crossing.y = 0;
  75. @@ -959,7 +960,6 @@
  76. canvas->_tiles=NULL;
  77. canvas->_tLeft=canvas->_tTop=canvas->_tRight=canvas->_tBottom=0;
  78. canvas->_tile_h=canvas->_tile_w=0;
  79. -
  80. canvas->_forced_redraw_count = 0;
  81. canvas->_forced_redraw_limit = -1;
  82. @@ -1034,6 +1034,21 @@
  83. return GTK_WIDGET(canvas);
  84. }
  85. +void SPCanvas::setOverlay(bool set, double opacity)
  86. +{
  87. + if (opacity == 0.0 || opacity > 1.0){
  88. + return;
  89. + }
  90. + if(set) {
  91. + _opacity = opacity;
  92. + _overlay = true;
  93. + updateNow();
  94. + } else {
  95. + _overlay = false;
  96. + updateNow();
  97. + }
  98. +}
  99. +
  100. void SPCanvas::handle_realize(GtkWidget *widget)
  101. {
  102. GdkWindowAttr attributes;
  103. @@ -1607,6 +1622,12 @@
  104. cairo_set_source_surface(xct, imgs, 0, 0);
  105. cairo_set_operator(xct, CAIRO_OPERATOR_SOURCE);
  106. cairo_paint(xct);
  107. + if (_overlay && _opacity > 0.0 && _opacity <= 1.0) {
  108. + cairo_set_operator(buf.ct, CAIRO_OPERATOR_OVER);
  109. + cairo_rectangle(xct, 0, 0, paint_rect.width(), paint_rect.height());
  110. + cairo_set_source_rgba (xct, 0.0, 0.0, 0.0, _opacity);
  111. + cairo_fill(xct);
  112. + }
  113. cairo_destroy(xct);
  114. cairo_surface_destroy(imgs);
  115. }
  116. === modified file 'src/display/sp-canvas.h'
  117. --- src/display/sp-canvas.h 2016-07-25 05:27:21 +0000
  118. +++ src/display/sp-canvas.h 2017-05-30 21:15:29 +0000
  119. @@ -84,7 +84,7 @@
  120. Geom::Rect getViewbox() const;
  121. Geom::IntRect getViewboxIntegers() const;
  122. SPCanvasGroup *getRoot();
  123. -
  124. + void setOverlay(bool set = true, double opacity = 0.0);
  125. /// Returns new canvas as widget.
  126. static GtkWidget *createAA();
  127. @@ -173,6 +173,9 @@
  128. SPCanvasItem *_root;
  129. + bool _overlay;
  130. + double _opacity;
  131. +
  132. bool _is_dragging;
  133. double _dx0;
  134. double _dy0;
  135. === modified file 'src/extension/execution-env.cpp'
  136. --- src/extension/execution-env.cpp 2016-04-12 10:35:15 +0000
  137. +++ src/extension/execution-env.cpp 2017-05-31 00:21:54 +0000
  138. @@ -23,6 +23,8 @@
  139. #include "selection.h"
  140. #include "effect.h"
  141. #include "document.h"
  142. +#include "desktop.h"
  143. +#include "inkscape.h"
  144. #include "document-undo.h"
  145. #include "desktop.h"
  146. #include "ui/view/view.h"
  147. @@ -54,19 +56,6 @@
  148. _show_working(show_working),
  149. _show_errors(show_errors)
  150. {
  151. - SPDesktop *desktop = (SPDesktop *)_doc;
  152. - sp_namedview_document_from_window(desktop);
  153. -
  154. - if (desktop != NULL) {
  155. - std::vector<SPItem*> selected = desktop->getSelection()->itemList();
  156. - for(std::vector<SPItem*>::const_iterator x = selected.begin(); x != selected.end(); ++x){
  157. - Glib::ustring selected_id;
  158. - selected_id = (*x)->getId();
  159. - _selected.insert(_selected.end(), selected_id);
  160. - //std::cout << "Selected: " << selected_id << std::endl;
  161. - }
  162. - }
  163. -
  164. genDocCache();
  165. return;
  166. @@ -183,24 +172,14 @@
  167. void
  168. ExecutionEnv::reselect (void) {
  169. - if (_doc == NULL) { return; }
  170. - SPDocument * doc = _doc->doc();
  171. - if (doc == NULL) { return; }
  172. -
  173. - SPDesktop *desktop = (SPDesktop *)_doc;
  174. - sp_namedview_document_from_window(desktop);
  175. -
  176. - if (desktop == NULL) { return; }
  177. -
  178. - Inkscape::Selection * selection = desktop->getSelection();
  179. -
  180. - for (std::list<Glib::ustring>::iterator i = _selected.begin(); i != _selected.end(); ++i) {
  181. - SPObject * obj = doc->getObjectById(i->c_str());
  182. - if (obj != NULL) {
  183. - selection->add(obj);
  184. + SPDesktop *desktop = SP_ACTIVE_DESKTOP;
  185. + Inkscape::Selection * selection = NULL;
  186. + if(desktop) {
  187. + selection = desktop->getSelection();
  188. + if (!desktop->on_live_extension) {
  189. + selection->restoreBackup();
  190. }
  191. }
  192. -
  193. return;
  194. }
  195. === modified file 'src/extension/execution-env.h'
  196. --- src/extension/execution-env.h 2014-03-27 01:33:44 +0000
  197. +++ src/extension/execution-env.h 2017-05-30 21:15:29 +0000
  198. @@ -54,9 +54,6 @@
  199. Glib::RefPtr<Glib::MainLoop> _mainloop;
  200. /** \brief The document that we're working on. */
  201. Inkscape::UI::View::View * _doc;
  202. - /** \brief A list of the IDs of all the selected objects before
  203. - we started to work on this document. */
  204. - std::list<Glib::ustring> _selected;
  205. /** \brief A document cache if we were passed one. */
  206. Implementation::ImplementationDocumentCache * _docCache;
  207. === modified file 'src/extension/implementation/script.cpp'
  208. --- src/extension/implementation/script.cpp 2016-06-03 07:50:21 +0000
  209. +++ src/extension/implementation/script.cpp 2017-05-31 00:24:00 +0000
  210. @@ -422,11 +422,29 @@
  211. SPDesktop *desktop = (SPDesktop *) view;
  212. sp_namedview_document_from_window(desktop);
  213. -
  214. + Inkscape::Preferences *prefs = Inkscape::Preferences::get();
  215. + bool sort_attributes = prefs->getBool("/options/svgoutput/sort_attributes", false);
  216. + bool incorrect_style_properties_remove = prefs->getBool("/options/svgoutput/incorrect_style_properties_remove", false);
  217. + bool incorrect_attributes_remove = prefs->getBool("/options/svgoutput/incorrect_attributes_remove", false);
  218. + bool usenamedcolors = prefs->getBool("/options/svgoutput/usenamedcolors", false);
  219. + bool forcerepeatcommands = prefs->getBool("/options/svgoutput/forcerepeatcommands", false);
  220. + bool style_defaults_remove = prefs->getBool("/options/svgoutput/style_defaults_remove", false);
  221. + prefs->setBool("/options/svgoutput/sort_attributes", false);
  222. + prefs->setBool("/options/svgoutput/incorrect_style_properties_remove", false);
  223. + prefs->setBool("/options/svgoutput/incorrect_attributes_remove", false);
  224. + prefs->setBool("/options/svgoutput/usenamedcolors", false);
  225. + prefs->setBool("/options/svgoutput/forcerepeatcommands", false);
  226. + prefs->setBool("/options/svgoutput/style_defaults_remove", false);
  227. Inkscape::Extension::save(
  228. Inkscape::Extension::db.get(SP_MODULE_KEY_OUTPUT_SVG_INKSCAPE),
  229. view->doc(), _filename.c_str(), false, false, false, Inkscape::Extension::FILE_SAVE_METHOD_TEMPORARY);
  230. + prefs->setBool("/options/svgoutput/sort_attributes", sort_attributes);
  231. + prefs->setBool("/options/svgoutput/incorrect_style_properties_remove", incorrect_style_properties_remove);
  232. + prefs->setBool("/options/svgoutput/incorrect_attributes_remove", incorrect_attributes_remove);
  233. + prefs->setBool("/options/svgoutput/usenamedcolors", usenamedcolors);
  234. + prefs->setBool("/options/svgoutput/forcerepeatcommands", forcerepeatcommands);
  235. + prefs->setBool("/options/svgoutput/style_defaults_remove", style_defaults_remove);
  236. return;
  237. }
  238. @@ -688,59 +706,14 @@
  239. /// \todo Popup dialog here
  240. return;
  241. }
  242. -
  243. - std::vector<SPItem*> selected =
  244. - desktop->getSelection()->itemList(); //desktop should not be NULL since doc was checked and desktop is a casted pointer
  245. - for(std::vector<SPItem*>::const_iterator x = selected.begin(); x != selected.end(); ++x){
  246. - Glib::ustring selected_id;
  247. - selected_id += "--id=";
  248. - selected_id += (*x)->getId();
  249. - params.push_front(selected_id);
  250. - }
  251. -
  252. - {//add selected nodes
  253. - Inkscape::UI::Tools::NodeTool *tool = 0;
  254. - if (SP_ACTIVE_DESKTOP ) {
  255. - Inkscape::UI::Tools::ToolBase *ec = SP_ACTIVE_DESKTOP->event_context;
  256. - if (INK_IS_NODE_TOOL(ec)) {
  257. - tool = static_cast<Inkscape::UI::Tools::NodeTool*>(ec);
  258. - }
  259. - }
  260. -
  261. - if(tool){
  262. - Inkscape::UI::ControlPointSelection *cps = tool->_selected_nodes;
  263. - for (Inkscape::UI::ControlPointSelection::iterator i = cps->begin(); i != cps->end(); ++i) {
  264. - Inkscape::UI::Node *node = dynamic_cast<Inkscape::UI::Node*>(*i);
  265. - if (node) {
  266. - std::string id = node->nodeList().subpathList().pm().item()->getId();
  267. -
  268. - int sp = 0;
  269. - bool found_sp = false;
  270. - for(Inkscape::UI::SubpathList::iterator i = node->nodeList().subpathList().begin(); i != node->nodeList().subpathList().end(); ++i,++sp){
  271. - if(&**i == &(node->nodeList())){
  272. - found_sp = true;
  273. - break;
  274. - }
  275. - }
  276. - int nl=0;
  277. - bool found_nl = false;
  278. - for (Inkscape::UI::NodeList::iterator j = node->nodeList().begin(); j != node->nodeList().end(); ++j, ++nl){
  279. - if(&*j==node){
  280. - found_nl = true;
  281. - break;
  282. - }
  283. - }
  284. - std::ostringstream ss;
  285. - ss<< "--selected-nodes=" << id << ":" << sp << ":" << nl;
  286. - Glib::ustring selected = ss.str();
  287. -
  288. - if(found_nl && found_sp)params.push_front(selected);
  289. - else g_warning("Something went wrong while trying to pass selected nodes to extension. Please report a bug.");
  290. - }
  291. - }
  292. - }
  293. - }//end add selected nodes
  294. -
  295. + if (desktop) {
  296. + Inkscape::Selection * selection = desktop->getSelection();
  297. + if (!selection->isEmpty()) {
  298. + selection->setBackup();
  299. + }
  300. + params = selection->params;
  301. + module->paramListString(params);
  302. + }
  303. file_listener fileout;
  304. int data_read = execute(command, params, dc->_filename, fileout);
  305. fileout.toFile(tempfilename_out);
  306. @@ -784,6 +757,7 @@
  307. layer = document->getObjectById(g_quark_to_string(nv->default_layer_id));
  308. }
  309. }
  310. + desktop->showGrids(nv->grids_visible);
  311. }
  312. sp_namedview_update_layers_from_document(desktop);
  313. @@ -792,6 +766,14 @@
  314. //set the current layer
  315. desktop->setCurrentLayer(layer);
  316. }
  317. + SPDesktop *desktop = SP_ACTIVE_DESKTOP;
  318. + if (desktop) {
  319. + Inkscape::Selection * selection = desktop->getSelection();
  320. + if (selection && selection->isEmpty() && !desktop->on_live_extension) {
  321. + selection->restoreBackup();
  322. + selection->emptyBackup();
  323. + }
  324. + }
  325. }
  326. mydoc->release();
  327. }
  328. @@ -827,12 +809,10 @@
  329. g_warning("Error on copy_doc: NULL pointer input.");
  330. return;
  331. }
  332. -
  333. // For copying attributes in root and in namedview
  334. using Inkscape::Util::List;
  335. using Inkscape::XML::AttributeRecord;
  336. std::vector<gchar const *> attribs;
  337. -
  338. // Must explicitly copy root attributes. This must be done first since
  339. // copying grid lines calls "SPGuide::set()" which needs to know the
  340. // width, height, and viewBox of the root element.
  341. @@ -853,80 +833,33 @@
  342. oldroot->setAttribute(name, newroot->attribute(name));
  343. }
  344. -
  345. // Question: Why is the "sodipodi:namedview" special? Treating it as a normal
  346. // elmement results in crashes.
  347. // Seems to be a bug:
  348. // http://inkscape.13.x6.nabble.com/Effect-that-modifies-the-document-properties-tt2822126.html
  349. std::vector<Inkscape::XML::Node *> delete_list;
  350. - Inkscape::XML::Node * oldroot_namedview = NULL;
  351. - Inkscape::XML::Node * newroot_namedview = NULL;
  352. // Make list
  353. for (Inkscape::XML::Node * child = oldroot->firstChild();
  354. child != NULL;
  355. child = child->next()) {
  356. if (!strcmp("sodipodi:namedview", child->name())) {
  357. - oldroot_namedview = child;
  358. for (Inkscape::XML::Node * oldroot_namedview_child = child->firstChild();
  359. oldroot_namedview_child != NULL;
  360. oldroot_namedview_child = oldroot_namedview_child->next()) {
  361. delete_list.push_back(oldroot_namedview_child);
  362. }
  363. - } else {
  364. - delete_list.push_back(child);
  365. + break;
  366. }
  367. }
  368. - if(!oldroot_namedview)
  369. - {
  370. - g_warning("Error on copy_doc: No namedview on destination document.");
  371. - return;
  372. - }
  373. -
  374. // Unparent (delete)
  375. for (unsigned int i = 0; i < delete_list.size(); i++) {
  376. sp_repr_unparent(delete_list[i]);
  377. }
  378. -
  379. - // Copy
  380. - for (Inkscape::XML::Node * child = newroot->firstChild();
  381. - child != NULL;
  382. - child = child->next()) {
  383. - if (!strcmp("sodipodi:namedview", child->name())) {
  384. - newroot_namedview = child;
  385. - for (Inkscape::XML::Node * newroot_namedview_child = child->firstChild();
  386. - newroot_namedview_child != NULL;
  387. - newroot_namedview_child = newroot_namedview_child->next()) {
  388. - oldroot_namedview->appendChild(newroot_namedview_child->duplicate(oldroot->document()));
  389. - }
  390. - } else {
  391. - oldroot->appendChild(child->duplicate(oldroot->document()));
  392. - }
  393. - }
  394. -
  395. attribs.clear();
  396. -
  397. - // Must explicitly copy namedview attributes.
  398. - // Make a list of all attributes of the old namedview node.
  399. - for (List<AttributeRecord const> iter = oldroot_namedview->attributeList(); iter; ++iter) {
  400. - attribs.push_back(g_quark_to_string(iter->key));
  401. - }
  402. -
  403. - // Delete the attributes of the old namedview node.
  404. - for (std::vector<gchar const *>::const_iterator it = attribs.begin(); it != attribs.end(); ++it) {
  405. - oldroot_namedview->setAttribute(*it, NULL);
  406. - }
  407. -
  408. - // Set the new attributes.
  409. - for (List<AttributeRecord const> iter = newroot_namedview->attributeList(); iter; ++iter) {
  410. - gchar const *name = g_quark_to_string(iter->key);
  411. - oldroot_namedview->setAttribute(name, newroot_namedview->attribute(name));
  412. - }
  413. -
  414. - /** \todo Restore correct layer */
  415. - /** \todo Restore correct selection */
  416. + oldroot->mergeFrom(newroot, "id", true, true);
  417. }
  418. /** \brief This function checks the stderr file, and if it has data,
  419. === modified file 'src/extension/internal/bitmap/imagemagick.cpp'
  420. --- src/extension/internal/bitmap/imagemagick.cpp 2015-12-09 20:01:20 +0000
  421. +++ src/extension/internal/bitmap/imagemagick.cpp 2017-05-31 00:25:18 +0000
  422. @@ -65,6 +65,16 @@
  423. _imageItems(NULL)
  424. {
  425. SPDesktop *desktop = (SPDesktop*)view;
  426. + Inkscape::Selection * selection = NULL;
  427. + if (desktop) {
  428. + selection = desktop->getSelection();
  429. + if (selection && !selection->params.empty()) {
  430. + selection->restoreBackup();
  431. + if (!desktop->on_live_extension) {
  432. + selection->emptyBackup();
  433. + }
  434. + }
  435. + }
  436. const std::vector<SPItem*> selectedItemList = desktop->selection->itemList();
  437. int selectCount = selectedItemList.size();
  438. === modified file 'src/extension/internal/bluredge.cpp'
  439. --- src/extension/internal/bluredge.cpp 2016-06-11 17:25:23 +0000
  440. +++ src/extension/internal/bluredge.cpp 2017-05-31 00:25:13 +0000
  441. @@ -53,7 +53,7 @@
  442. void
  443. BlurEdge::effect (Inkscape::Extension::Effect *module, Inkscape::UI::View::View *desktop, Inkscape::Extension::Implementation::ImplementationDocumentCache * /*docCache*/)
  444. {
  445. - Inkscape::Selection * selection = static_cast<SPDesktop *>(desktop)->selection;
  446. +
  447. float width = module->get_param_float("blur-width");
  448. int steps = module->get_param_int("num-steps");
  449. @@ -62,6 +62,17 @@
  450. double old_offset = prefs->getDouble("/options/defaultoffsetwidth/value", 1.0, "px");
  451. // TODO need to properly refcount the items, at least
  452. + SPDesktop *deskt = static_cast<SPDesktop *>(desktop);
  453. + Inkscape::Selection * selection = NULL;
  454. + if (deskt) {
  455. + selection = deskt->selection;
  456. + if (selection && !selection->params.empty()) {
  457. + selection->restoreBackup();
  458. + if (!deskt->on_live_extension) {
  459. + selection->emptyBackup();
  460. + }
  461. + }
  462. + }
  463. std::vector<SPItem*> items(selection->itemList());
  464. selection->clear();
  465. === modified file 'src/extension/internal/filter/filter.cpp'
  466. --- src/extension/internal/filter/filter.cpp 2016-11-11 20:30:37 +0000
  467. +++ src/extension/internal/filter/filter.cpp 2017-05-31 00:25:26 +0000
  468. @@ -122,8 +122,17 @@
  469. }
  470. //printf("Calling filter effect\n");
  471. - Inkscape::Selection * selection = ((SPDesktop *)document)->selection;
  472. -
  473. + SPDesktop *desktop = (SPDesktop *)document;
  474. + Inkscape::Selection * selection = NULL;
  475. + if (desktop) {
  476. + selection = desktop->selection;
  477. + if (selection && !selection->params.empty()) {
  478. + selection->restoreBackup();
  479. + if (!desktop->on_live_extension) {
  480. + selection->emptyBackup();
  481. + }
  482. + }
  483. + }
  484. // TODO need to properly refcount the items, at least
  485. std::vector<SPItem*> items(selection->itemList());
  486. === modified file 'src/extension/internal/grid.cpp'
  487. --- src/extension/internal/grid.cpp 2016-06-11 17:25:23 +0000
  488. +++ src/extension/internal/grid.cpp 2017-05-31 00:25:34 +0000
  489. @@ -87,7 +87,17 @@
  490. void
  491. Grid::effect (Inkscape::Extension::Effect *module, Inkscape::UI::View::View *document, Inkscape::Extension::Implementation::ImplementationDocumentCache * /*docCache*/)
  492. {
  493. - Inkscape::Selection * selection = ((SPDesktop *)document)->selection;
  494. + SPDesktop *desktop = ((SPDesktop *)document);
  495. + Inkscape::Selection * selection = NULL;
  496. + if (desktop) {
  497. + selection = desktop->getSelection();
  498. + if (selection && !selection->params.empty()) {
  499. + selection->restoreBackup();
  500. + if (!desktop->on_live_extension) {
  501. + selection->emptyBackup();
  502. + }
  503. + }
  504. + }
  505. Geom::Rect bounding_area = Geom::Rect(Geom::Point(0,0), Geom::Point(100,100));
  506. if (selection->isEmpty()) {
  507. === modified file 'src/extension/prefdialog.cpp'
  508. --- src/extension/prefdialog.cpp 2016-06-11 17:25:23 +0000
  509. +++ src/extension/prefdialog.cpp 2017-05-31 00:22:52 +0000
  510. @@ -64,7 +64,13 @@
  511. controls = _effect->get_imp()->prefs_effect(_effect, SP_ACTIVE_DESKTOP, &_signal_param_change, NULL);
  512. _signal_param_change.connect(sigc::mem_fun(this, &PrefDialog::param_change));
  513. }
  514. -
  515. + SPDesktop *desktop = SP_ACTIVE_DESKTOP;
  516. + if (desktop) {
  517. + Inkscape::Selection * selection = desktop->getSelection();
  518. + if (selection) {
  519. + selection->emptyBackup();
  520. + }
  521. + }
  522. hbox->pack_start(*controls, true, true, 6);
  523. hbox->show();
  524. @@ -196,19 +202,42 @@
  525. void
  526. PrefDialog::preview_toggle (void) {
  527. + SPDesktop *desktop = SP_ACTIVE_DESKTOP;
  528. + Inkscape::Selection * selection = NULL;
  529. + if(desktop) {
  530. + selection = desktop->getSelection();
  531. + }
  532. + desktop->getSelection();
  533. + desktop->setOverlay(false, false, 0.0);
  534. + desktop->on_live_extension = false;
  535. + set_modal(false);
  536. if(_param_preview->get_bool(NULL, NULL)) {
  537. - set_modal(true);
  538. if (_exEnv == NULL) {
  539. + if (desktop && selection) {
  540. + desktop->setOverlay(false, true, 0.0);
  541. + desktop->on_live_extension = true;
  542. + if (!selection->isEmpty()) {
  543. + selection->setBackup();
  544. + }
  545. + }
  546. _exEnv = new ExecutionEnv(_effect, SP_ACTIVE_DESKTOP, NULL, false, false);
  547. _exEnv->run();
  548. + if (desktop && selection) {
  549. + selection->clear();
  550. + }
  551. }
  552. } else {
  553. - set_modal(false);
  554. + if (desktop) {
  555. + desktop->setOverlay(false);
  556. + }
  557. if (_exEnv != NULL) {
  558. _exEnv->cancel();
  559. _exEnv->undo();
  560. delete _exEnv;
  561. _exEnv = NULL;
  562. + if (desktop && selection) {
  563. + selection->restoreBackup();
  564. + }
  565. }
  566. }
  567. }
  568. @@ -243,12 +272,12 @@
  569. PrefDialog::on_response (int signal) {
  570. if (signal == Gtk::RESPONSE_OK) {
  571. if (_exEnv == NULL) {
  572. - if (_effect != NULL) {
  573. - _effect->effect(SP_ACTIVE_DESKTOP);
  574. - } else {
  575. - // Shutdown run()
  576. - return;
  577. - }
  578. + if (_effect != NULL) {
  579. + _effect->effect(SP_ACTIVE_DESKTOP);
  580. + } else {
  581. + // Shutdown run()
  582. + return;
  583. + }
  584. } else {
  585. if (_exEnv->wait()) {
  586. _exEnv->commit();
  587. @@ -257,6 +286,7 @@
  588. }
  589. delete _exEnv;
  590. _exEnv = NULL;
  591. +
  592. }
  593. }
  594. @@ -267,7 +297,15 @@
  595. if ((signal == Gtk::RESPONSE_CANCEL || signal == Gtk::RESPONSE_DELETE_EVENT) && _effect != NULL) {
  596. delete this;
  597. }
  598. -
  599. + SPDesktop *desktop = SP_ACTIVE_DESKTOP;
  600. + Inkscape::Selection * selection = NULL;
  601. + if(desktop) {
  602. + selection = desktop->getSelection();
  603. + desktop->on_live_extension = false;
  604. + desktop->setOverlay(false);
  605. + selection->restoreBackup();
  606. + selection->emptyBackup();
  607. + }
  608. return;
  609. }
  610. === modified file 'src/selection.cpp'
  611. --- src/selection.cpp 2016-02-08 07:32:51 +0000
  612. +++ src/selection.cpp 2017-05-31 00:20:43 +0000
  613. @@ -22,6 +22,7 @@
  614. #include "macros.h"
  615. #include "inkscape.h"
  616. #include "document.h"
  617. +#include "desktop.h"
  618. #include "layer-model.h"
  619. #include "selection.h"
  620. #include <2geom/rect.h>
  621. @@ -34,6 +35,12 @@
  622. #include "box3d.h"
  623. #include "box3d.h"
  624. #include "persp3d.h"
  625. +#include "ui/tools/node-tool.h"
  626. +#include "ui/tool/multi-path-manipulator.h"
  627. +#include "ui/tool/path-manipulator.h"
  628. +#include "ui/tool/control-point-selection.h"
  629. +#include "sp-path.h"
  630. +#include "sp-defs.h"
  631. #include <sigc++/functors/mem_fun.h>
  632. @@ -541,6 +548,140 @@
  633. return parents.size();
  634. }
  635. +void
  636. +Selection::emptyBackup(){
  637. + _selected_ids.clear();
  638. + _seldata.clear();
  639. + params.clear();
  640. +}
  641. +
  642. +void
  643. +Selection::setBackup ()
  644. +{
  645. + SPDesktop *desktop = SP_ACTIVE_DESKTOP;
  646. + if (desktop) {
  647. + std::vector<SPItem*> selected_items = itemList();
  648. + _selected_ids.clear();
  649. + _seldata.clear();
  650. + params.clear();
  651. + for(std::vector<SPItem*>::const_iterator x = selected_items.begin(); x != selected_items.end(); ++x){
  652. + std::string selected_id;
  653. + selected_id += "--id=";
  654. + selected_id += (*x)->getId();
  655. + params.push_front(selected_id);
  656. + _selected_ids.push_back((*x)->getId());
  657. + }
  658. + Inkscape::UI::Tools::NodeTool *tool = 0;
  659. +
  660. + Inkscape::UI::Tools::ToolBase *ec = desktop->event_context;
  661. + if (INK_IS_NODE_TOOL(ec)) {
  662. + tool = static_cast<Inkscape::UI::Tools::NodeTool*>(ec);
  663. + }
  664. + if(tool){
  665. + Inkscape::UI::ControlPointSelection *cps = tool->_selected_nodes;
  666. + std::list<Inkscape::UI::SelectableControlPoint *> points_list = cps->_points_list;
  667. + for (std::list<Inkscape::UI::SelectableControlPoint *>::iterator i = points_list.begin(); i != points_list.end(); ++i) {
  668. + Inkscape::UI::Node *node = dynamic_cast<Inkscape::UI::Node*>(*i);
  669. + if (node) {
  670. + std::string id = node->nodeList().subpathList().pm().item()->getId();
  671. +
  672. + int sp = 0;
  673. + bool found_sp = false;
  674. + for(Inkscape::UI::SubpathList::iterator i = node->nodeList().subpathList().begin(); i != node->nodeList().subpathList().end(); ++i,++sp){
  675. + if(&**i == &(node->nodeList())){
  676. + found_sp = true;
  677. + break;
  678. + }
  679. + }
  680. + int nl=0;
  681. + bool found_nl = false;
  682. + for (Inkscape::UI::NodeList::iterator j = node->nodeList().begin(); j != node->nodeList().end(); ++j, ++nl){
  683. + if(&*j==node){
  684. + found_nl = true;
  685. + break;
  686. + }
  687. + }
  688. + std::ostringstream ss;
  689. + ss<< "--selected-nodes=" << id << ":" << sp << ":" << nl;
  690. + Glib::ustring selected_nodes = ss.str();
  691. +
  692. + if(found_nl && found_sp) {
  693. + _seldata.push_back(std::make_pair(id,std::make_pair(sp,nl)));
  694. + params.push_front(selected_nodes);
  695. + } else {
  696. + g_warning("Something went wrong while trying to pass selected nodes to extension. Please report a bug.");
  697. + }
  698. + }
  699. + }
  700. + }
  701. + }//end add selected nodes
  702. +}
  703. +
  704. +void
  705. +Selection::restoreBackup()
  706. +{
  707. + SPDesktop *desktop = SP_ACTIVE_DESKTOP;
  708. + if (desktop) {
  709. + Inkscape::UI::Tools::NodeTool *tool = 0;
  710. + Inkscape::UI::Tools::ToolBase *ec = desktop->event_context;
  711. + if (INK_IS_NODE_TOOL(ec)) {
  712. + tool = static_cast<Inkscape::UI::Tools::NodeTool*>(ec);
  713. + }
  714. + clear();
  715. + std::vector<std::string>::reverse_iterator rit = _selected_ids.rbegin();
  716. + for (; rit!= _selected_ids.rend(); ++rit){
  717. + SPObject * obj = desktop->doc()->getObjectById(rit->c_str());
  718. + SPDefs * defs = desktop->getDocument()->getDefs();
  719. + if (obj && !defs->isAncestorOf(obj)) {
  720. + add(obj);
  721. + }
  722. + }
  723. + if (tool) {
  724. + Inkscape::UI::ControlPointSelection *cps = tool->_selected_nodes;
  725. + cps->selectAll();
  726. + std::list<Inkscape::UI::SelectableControlPoint *> points_list = cps->_points_list;
  727. + cps->clear();
  728. + std::vector<Inkscape::UI::Node *> nodes (_seldata.size(), NULL);
  729. + for (std::list<Inkscape::UI::SelectableControlPoint *>::iterator i = points_list.begin(); i != points_list.end(); ++i) {
  730. + Inkscape::UI::Node *node = dynamic_cast<Inkscape::UI::Node*>(*i);
  731. + if (node) {
  732. + SPPath * item = node->nodeList().subpathList().pm().item();
  733. + if(!item || !includes(item->getRepr())) {
  734. + continue;
  735. + }
  736. + std::string id = item->getId();
  737. + int sp=0;
  738. + bool found_sp = false;
  739. + for(Inkscape::UI::SubpathList::iterator j = node->nodeList().subpathList().begin(); j != node->nodeList().subpathList().end(); ++j,++sp){
  740. + if(&**j == &(node->nodeList())){
  741. + found_sp = true;
  742. + break;
  743. + }
  744. + }
  745. + int nl=0;
  746. + for (Inkscape::UI::NodeList::iterator k = node->nodeList().begin(); k != node->nodeList().end(); ++k, ++nl){
  747. + if(&*k==node){
  748. + guint count = 0;
  749. + for (std::vector<std::pair<std::string, std::pair<int, int> > >::iterator l = _seldata.begin(); l != _seldata.end(); ++l, ++count) {
  750. + if(l->first == id && l->second.first == sp && l->second.second == nl && found_sp){
  751. + nodes[count] = node;
  752. + break;
  753. + }
  754. + }
  755. + break;
  756. + }
  757. + }
  758. + }
  759. + }
  760. + for (std::vector<Inkscape::UI::Node *>::iterator m = nodes.begin(); m != nodes.end(); ++m){
  761. + if (*m) {
  762. + (*m)->select(true);
  763. + }
  764. + }
  765. + }
  766. + }
  767. +}
  768. +
  769. }
  770. /*
  771. === modified file 'src/selection.h'
  772. --- src/selection.h 2015-04-29 22:29:17 +0000
  773. +++ src/selection.h 2017-05-31 00:21:11 +0000
  774. @@ -328,13 +328,29 @@
  775. {
  776. return _modified_signal.slots().insert(_modified_signal.slots().begin(), slot);
  777. }
  778. + /**
  779. + * Set a backup of current selection and store it also to be command line readable by extension system
  780. + */
  781. + void setBackup();
  782. + /**
  783. + * Clear backup of current selection
  784. + */
  785. + void emptyBackup();
  786. + /**
  787. + * Restore a selection from a existing backup
  788. + */
  789. + void restoreBackup();
  790. + /**
  791. + * Here store a paramlist when set backup
  792. + */
  793. + std::list<std::string> params;
  794. private:
  795. /** no copy. */
  796. Selection(Selection const &);
  797. /** no assign. */
  798. void operator=(Selection const &);
  799. -
  800. +
  801. /** Issues modification notification signals. */
  802. static int _emit_modified(Selection *selection);
  803. /** Schedules an item modification signal to be sent. */
  804. @@ -381,7 +397,8 @@
  805. SPObject* _selection_context;
  806. unsigned int _flags;
  807. unsigned int _idle;
  808. -
  809. + std::vector<std::pair<std::string, std::pair<int, int> > > _seldata;
  810. + std::vector<std::string> _selected_ids;
  811. std::map<SPObject *, sigc::connection> _modified_connections;
  812. std::map<SPObject *, sigc::connection> _release_connections;
  813. sigc::connection _context_release_connection;
  814. === modified file 'src/ui/tool/control-point-selection.h'
  815. --- src/ui/tool/control-point-selection.h 2016-03-13 23:50:24 +0000
  816. +++ src/ui/tool/control-point-selection.h 2017-05-30 21:15:29 +0000
  817. @@ -118,6 +118,8 @@
  818. void getOriginalPoints(std::vector<Inkscape::SnapCandidatePoint> &pts);
  819. void getUnselectedPoints(std::vector<Inkscape::SnapCandidatePoint> &pts);
  820. void setOriginalPoints();
  821. + //the purpose of this list is to keep track of first and last selected
  822. + std::list<SelectableControlPoint *> _points_list;
  823. private:
  824. // The functions below are invoked from SelectableControlPoint.
  825. @@ -141,8 +143,7 @@
  826. double _rotationRadius(Geom::Point const &);
  827. set_type _points;
  828. - //the purpose of this list is to keep track of first and last selected
  829. - std::list<SelectableControlPoint *> _points_list;
  830. +
  831. set_type _all_points;
  832. INK_UNORDERED_MAP<SelectableControlPoint *, Geom::Point> _original_positions;
  833. INK_UNORDERED_MAP<SelectableControlPoint *, Geom::Affine> _last_trans;
  834. === modified file 'src/ui/tool/selectable-control-point.cpp'
  835. --- src/ui/tool/selectable-control-point.cpp 2014-03-27 01:33:44 +0000
  836. +++ src/ui/tool/selectable-control-point.cpp 2017-05-30 21:15:29 +0000
  837. @@ -87,6 +87,15 @@
  838. return true;
  839. }
  840. +void SelectableControlPoint::select(bool toselect)
  841. +{
  842. + if (toselect) {
  843. + _selection.insert(this);
  844. + } else {
  845. + _selection.erase(this);
  846. + }
  847. +}
  848. +
  849. void SelectableControlPoint::_takeSelection()
  850. {
  851. _selection.clear();
  852. === modified file 'src/ui/tool/selectable-control-point.h'
  853. --- src/ui/tool/selectable-control-point.h 2014-08-08 20:20:44 +0000
  854. +++ src/ui/tool/selectable-control-point.h 2017-05-30 21:15:29 +0000
  855. @@ -28,8 +28,10 @@
  856. virtual Geom::Rect bounds() const {
  857. return Geom::Rect(position(), position());
  858. }
  859. + virtual void select(bool toselect);
  860. friend class NodeList;
  861. +
  862. protected:
  863. SelectableControlPoint(SPDesktop *d, Geom::Point const &initial_pos, SPAnchorType anchor,
  864. === modified file 'src/xml/node.h'
  865. --- src/xml/node.h 2014-12-16 14:05:47 +0000
  866. +++ src/xml/node.h 2017-05-30 21:15:29 +0000
  867. @@ -384,6 +384,20 @@
  868. */
  869. virtual void changeOrder(Node *child, Node *after)=0;
  870. + /**
  871. + * @brief Remove all elements that not in src node
  872. + * @param src The node to check for elemments into this node
  873. + * @param key The attribute to use as the identity attribute
  874. + */
  875. + virtual void cleanOriginal(Node *src, gchar const *key)=0;
  876. +
  877. +
  878. + /**
  879. + * @brief Compare 2 nodes equality
  880. + * @param other The other node to compare
  881. + * @param recursive Recursive mode check
  882. + */
  883. + virtual bool equal(Node const *other, bool recursive)=0;
  884. /**
  885. * @brief Merge all children of another node with the current
  886. *
  887. @@ -397,8 +411,11 @@
  888. *
  889. * @param src The node to merge into this node
  890. * @param key The attribute to use as the identity attribute
  891. + * @param noid If true process noid items
  892. + * @param key If clean callback to cleanOriginal
  893. */
  894. - virtual void mergeFrom(Node const *src, char const *key)=0;
  895. +
  896. + virtual void mergeFrom(Node const *src, char const *key, bool extension = false, bool clean = false)=0;
  897. /*@}*/
  898. === modified file 'src/xml/simple-node.cpp'
  899. --- src/xml/simple-node.cpp 2014-12-16 14:05:47 +0000
  900. +++ src/xml/simple-node.cpp 2017-05-30 21:15:29 +0000
  901. @@ -318,7 +318,7 @@
  902. // Check usefulness of attributes on elements in the svg namespace, optionally don't add them to tree.
  903. Glib::ustring element = g_quark_to_string(_name);
  904. - // g_message("setAttribute: %s: %s: %s", element.c_str(), name, value);
  905. + //g_message("setAttribute: %s: %s: %s", element.c_str(), name, value);
  906. gchar* cleaned_value = g_strdup( value );
  907. // Only check elements in SVG name space and don't block setting attribute to NULL.
  908. @@ -648,28 +648,112 @@
  909. }
  910. }
  911. -void SimpleNode::mergeFrom(Node const *src, gchar const *key) {
  912. +void SimpleNode::cleanOriginal(Node *src, gchar const *key){
  913. + std::vector<Node *> to_delete;
  914. + for ( Node *child = this->firstChild() ; child != NULL ; child = child->next() )
  915. + {
  916. + gchar const *id = child->attribute(key);
  917. + if (id) {
  918. + Node *rch = sp_repr_lookup_child(src, key, id);
  919. + if (rch) {
  920. + child->cleanOriginal(rch, key);
  921. + } else {
  922. + to_delete.push_back(child);
  923. + }
  924. + } else {
  925. + to_delete.push_back(child);
  926. + }
  927. + }
  928. + for ( std::vector<Node *>::iterator i = to_delete.begin(); i != to_delete.end(); ++i) {
  929. + removeChild(*i);
  930. + }
  931. +}
  932. +
  933. +bool SimpleNode::equal(Node const *other, bool recursive) {
  934. + if(strcmp(name(),other->name())!= 0){
  935. + return false;
  936. + }
  937. + if (!(strcmp("sodipodi:namedview", name()))) {
  938. + return true;
  939. + }
  940. + guint orig_length = 0;
  941. + guint other_length = 0;
  942. +
  943. + if(content() && other->content() && strcmp(content(), other->content()) != 0){
  944. + return false;
  945. + }
  946. + for (List<AttributeRecord const> orig_attr = attributeList(); orig_attr; ++orig_attr) {
  947. + for (List<AttributeRecord const> other_attr = other->attributeList(); other_attr; ++other_attr) {
  948. + const gchar * key_orig = g_quark_to_string(orig_attr->key);
  949. + const gchar * key_other = g_quark_to_string(other_attr->key);
  950. + if (!strcmp(key_orig, key_other) &&
  951. + !strcmp(orig_attr->value, other_attr->value))
  952. + {
  953. + other_length++;
  954. + break;
  955. + }
  956. + }
  957. + orig_length++;
  958. + }
  959. + if (orig_length != other_length) {
  960. + return false;
  961. + }
  962. + if (recursive) {
  963. + //NOTE: for faster the childs need to be in the same order
  964. + Node const *other_child = other->firstChild();
  965. + for ( Node *child = firstChild();
  966. + child;
  967. + child = child->next())
  968. + {
  969. + if (!child->equal(other_child, recursive)) {
  970. + return false;
  971. + }
  972. + other_child = other_child->next();
  973. + if(!other_child) {
  974. + return false;
  975. + }
  976. + }
  977. + }
  978. + return true;
  979. +}
  980. +
  981. +void SimpleNode::mergeFrom(Node const *src, gchar const *key, bool extension, bool clean) {
  982. g_return_if_fail(src != NULL);
  983. g_return_if_fail(key != NULL);
  984. g_assert(src != this);
  985. setContent(src->content());
  986. + if(_parent) {
  987. + setPosition(src->position());
  988. + }
  989. +
  990. + if (clean) {
  991. + Node * srcp = const_cast<Node *>(src);
  992. + cleanOriginal(srcp, key);
  993. + }
  994. for ( Node const *child = src->firstChild() ; child != NULL ; child = child->next() )
  995. {
  996. gchar const *id = child->attribute(key);
  997. if (id) {
  998. Node *rch=sp_repr_lookup_child(this, key, id);
  999. - if (rch) {
  1000. - rch->mergeFrom(child, key);
  1001. + if (rch && (!extension || rch->equal(child, false))) {
  1002. + rch->mergeFrom(child, key, extension);
  1003. } else {
  1004. + if(rch) {
  1005. + removeChild(rch);
  1006. + }
  1007. + guint pos = child->position();
  1008. rch = child->duplicate(_document);
  1009. appendChild(rch);
  1010. + rch->setPosition(pos);
  1011. rch->release();
  1012. }
  1013. } else {
  1014. + guint pos = child->position();
  1015. Node *rch=child->duplicate(_document);
  1016. appendChild(rch);
  1017. + rch->setPosition(pos);
  1018. rch->release();
  1019. }
  1020. }
  1021. === modified file 'src/xml/simple-node.h'
  1022. --- src/xml/simple-node.h 2014-12-16 14:05:47 +0000
  1023. +++ src/xml/simple-node.h 2017-05-30 21:15:29 +0000
  1024. @@ -91,7 +91,9 @@
  1025. char const *content() const;
  1026. void setContent(char const *value);
  1027. - void mergeFrom(Node const *src, char const *key);
  1028. + void cleanOriginal(Node *src, gchar const *key);
  1029. + bool equal(Node const *other, bool recursive);
  1030. + void mergeFrom(Node const *src, char const *key, bool extension = false, bool clean = false);
  1031. Inkscape::Util::List<AttributeRecord const> attributeList() const {
  1032. return _attributes;
  1. More ...
 
 

809

Pasted Text #2614

-

PasteBin

Lines
1105
Words
3911
Tamaño
39,6 KB
Creado
Tipo
text/plain
General Public License v2 (GPLv2)
Please log in to leave a comment!