index 0f89464411e395c9a6235bdd24fd5d1b80b54418..114ed9c645a67470811fe9d9502201820303eab0 100644 (file)
#include "svg/svg.h"
#include "inkscape.h"
#include "desktop.h"
-//#include "desktop-style.h"
+#include "desktop-style.h"
#include "selection.h"
#include "tools-switch.h"
#include "desktop-handles.h"
@@ -130,7 +130,7 @@ void sp_selection_copy_impl (GSList const *items, GSList **clip, Inkscape::XML::
// Copy item reprs:
for (GSList *i = (GSList *) sorted_items; i != NULL; i = i->next) {
- sp_selection_copy_one (SP_OBJECT_REPR (i->data), sp_item_i2doc_affine(SP_ITEM (i->data)), clip, xml_doc);
+ sp_selection_copy_one (SP_OBJECT_REPR (i->data), from_2geom(sp_item_i2doc_affine(SP_ITEM (i->data))), clip, xml_doc);
}
*clip = g_slist_reverse(*clip);
@@ -148,7 +148,7 @@ GSList *sp_selection_paste_impl (SPDocument *doc, SPObject *parent, GSList **cli
Inkscape::XML::Node *copy = repr->duplicate(xml_doc);
// premultiply the item transform by the accumulated parent transform in the paste layer
- NR::Matrix local = sp_item_i2doc_affine(SP_ITEM(parent));
+ NR::Matrix local = from_2geom(sp_item_i2doc_affine(SP_ITEM(parent)));
if (!local.test_identity()) {
gchar const *t_str = copy->attribute("transform");
NR::Matrix item_t (NR::identity());
}
/* fixme: sequencing */
-void sp_selection_duplicate()
+void sp_selection_duplicate(bool suppressDone)
{
SPDesktop *desktop = SP_ACTIVE_DESKTOP;
if (desktop == NULL)
Inkscape::GC::release(copy);
}
- sp_document_done(sp_desktop_document(desktop), SP_VERB_EDIT_DUPLICATE,
- _("Duplicate"));
+ if ( !suppressDone ) {
+ sp_document_done(sp_desktop_document(desktop), SP_VERB_EDIT_DUPLICATE,
+ _("Duplicate"));
+ }
selection->setReprList(newsel);
NR::Matrix item_t (NR::identity());
if (t_str)
sp_svg_transform_read(t_str, &item_t);
- item_t *= sp_item_i2doc_affine(SP_ITEM(doc->getObjectByRepr(current->parent())));
+ item_t *= from_2geom(sp_item_i2doc_affine(SP_ITEM(doc->getObjectByRepr(current->parent()))));
//FIXME: when moving both clone and original from a transformed group (either by
//grouping into another parent, or by cut/paste) the transform from the original's
//parent becomes embedded into original itself, and this affects its clones. Fix
}
/** Finds out the minimum common bbox of the selected items. */
-static NR::Maybe<NR::Rect>
+static boost::optional<NR::Rect>
enclose_items(GSList const *items)
{
g_assert(items != NULL);
- NR::Maybe<NR::Rect> r = NR::Nothing();
+ boost::optional<NR::Rect> r;
for (GSList const *i = items; i; i = i->next) {
r = NR::union_bounds(r, sp_item_bbox_desktop((SPItem *) i->data));
}
rev = g_slist_sort(rev, (GCompareFunc) sp_item_repr_compare_position);
// Determine the common bbox of the selected items.
- NR::Maybe<NR::Rect> selected = enclose_items(items);
+ boost::optional<NR::Rect> selected = enclose_items(items);
// Iterate over all objects in the selection (starting from top).
if (selected) {
for (SPObject *newref = child->next; newref; newref = newref->next) {
// if the sibling is an item AND overlaps our selection,
if (SP_IS_ITEM(newref)) {
- NR::Maybe<NR::Rect> newref_bbox = sp_item_bbox_desktop(SP_ITEM(newref));
+ boost::optional<NR::Rect> newref_bbox = sp_item_bbox_desktop(SP_ITEM(newref));
if ( newref_bbox && selected->intersects(*newref_bbox) ) {
// AND if it's not one of our selected objects,
if (!g_slist_find((GSList *) items, newref)) {
Inkscape::XML::Node *grepr = SP_OBJECT_REPR(group);
// Determine the common bbox of the selected items.
- NR::Maybe<NR::Rect> selected = enclose_items(items);
+ boost::optional<NR::Rect> selected = enclose_items(items);
/* Construct direct-ordered list of selected children. */
GSList *rev = g_slist_copy((GSList *) items);
for (SPObject *newref = prev_sibling(child); newref; newref = prev_sibling(newref)) {
// if the sibling is an item AND overlaps our selection,
if (SP_IS_ITEM(newref)) {
- NR::Maybe<NR::Rect> ref_bbox = sp_item_bbox_desktop(SP_ITEM(newref));
+ boost::optional<NR::Rect> ref_bbox = sp_item_bbox_desktop(SP_ITEM(newref));
if ( ref_bbox && selected->intersects(*ref_bbox) ) {
// AND if it's not one of our selected objects,
if (!g_slist_find((GSList *) items, newref)) {
}
// FIXME: also transform gradient/pattern fills, by forking? NO, this must be nondestructive
- double ex = NR::expansion(sp_item_i2doc_affine(item));
+ double ex = NR::expansion(from_2geom(sp_item_i2doc_affine(item)));
if (ex != 1.0) {
css = sp_css_attr_scale (css, ex);
}
void sp_selection_remove_livepatheffect_impl(SPItem *item)
{
if ( item && SP_IS_LPE_ITEM(item) ) {
- sp_lpe_item_remove_path_effect(SP_LPE_ITEM(item), false);
+ sp_lpe_item_remove_all_path_effects(SP_LPE_ITEM(item), false);
}
}
}
- sp_document_done(sp_desktop_document (desktop), SP_VERB_EDIT_PASTE_LIVEPATHEFFECT,
+ sp_document_done(sp_desktop_document (desktop), SP_VERB_EDIT_REMOVE_LIVEPATHEFFECT,
_("Remove live path effect"));
}
+void sp_selection_remove_filter ()
+{
+ SPDesktop *desktop = SP_ACTIVE_DESKTOP;
+ if (desktop == NULL) return;
+
+ Inkscape::Selection *selection = sp_desktop_selection(desktop);
+
+ // check if something is selected
+ if (selection->isEmpty()) {
+ desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>object(s)</b> to remove filters from."));
+ return;
+ }
+
+ SPCSSAttr *css = sp_repr_css_attr_new();
+ sp_repr_css_unset_property(css, "filter");
+ sp_desktop_set_style(desktop, css);
+ sp_repr_css_attr_unref(css);
+
+ sp_document_done(sp_desktop_document (desktop), SP_VERB_EDIT_REMOVE_FILTER,
+ _("Remove filter"));
+}
+
+
void sp_selection_paste_size (bool apply_x, bool apply_y)
{
Inkscape::UI::ClipboardManager *cm = Inkscape::UI::ClipboardManager::get();
_("Paste size separately"));
}
-void sp_selection_to_next_layer ()
+void sp_selection_to_next_layer(bool suppressDone)
{
SPDesktop *dt = SP_ACTIVE_DESKTOP;
g_slist_free (copied);
if (temp_clip) g_slist_free (temp_clip);
if (next) dt->setCurrentLayer(next);
- sp_document_done(sp_desktop_document (dt), SP_VERB_LAYER_MOVE_TO_NEXT,
- _("Raise to next layer"));
+ if ( !suppressDone ) {
+ sp_document_done(sp_desktop_document (dt), SP_VERB_LAYER_MOVE_TO_NEXT,
+ _("Raise to next layer"));
+ }
} else {
no_more = true;
}
g_slist_free ((GSList *) items);
}
-void sp_selection_to_prev_layer ()
+void sp_selection_to_prev_layer(bool suppressDone)
{
SPDesktop *dt = SP_ACTIVE_DESKTOP;
g_slist_free (copied);
if (temp_clip) g_slist_free (temp_clip);
if (next) dt->setCurrentLayer(next);
- sp_document_done(sp_desktop_document (dt), SP_VERB_LAYER_MOVE_TO_PREV,
- _("Lower to previous layer"));
+ if ( !suppressDone ) {
+ sp_document_done(sp_desktop_document (dt), SP_VERB_LAYER_MOVE_TO_PREV,
+ _("Lower to previous layer"));
+ }
} else {
no_more = true;
}
@@ -1149,9 +1178,9 @@ void sp_selection_apply_affine(Inkscape::Selection *selection, NR::Matrix const
sp_object_read_attr (SP_OBJECT (item), "transform");
// calculate the matrix we need to apply to the clone to cancel its induced transform from its original
- NR::Matrix parent_transform = sp_item_i2root_affine(SP_ITEM(SP_OBJECT_PARENT (item)));
- NR::Matrix t = parent_transform * matrix_to_desktop (matrix_from_desktop (affine, item), item) * parent_transform.inverse();
- NR::Matrix t_inv =parent_transform * matrix_to_desktop (matrix_from_desktop (affine.inverse(), item), item) * parent_transform.inverse();
+ NR::Matrix parent_transform = from_2geom(sp_item_i2root_affine(SP_ITEM(SP_OBJECT_PARENT (item))));
+ NR::Matrix t = parent_transform * from_2geom(matrix_to_desktop (matrix_from_desktop (to_2geom(affine), item), item)) * parent_transform.inverse();
+ NR::Matrix t_inv =parent_transform * from_2geom(matrix_to_desktop (matrix_from_desktop (to_2geom(affine.inverse()), item), item)) * parent_transform.inverse();
NR::Matrix result = t_inv * item->transform * t;
if ((prefs_parallel || prefs_unmoved) && affine.is_translation()) {
@@ -1179,7 +1208,7 @@ void sp_selection_apply_affine(Inkscape::Selection *selection, NR::Matrix const
} else {
if (set_i2d) {
- sp_item_set_i2d_affine(item, sp_item_i2d_affine(item) * affine);
+ sp_item_set_i2d_affine(item, sp_item_i2d_affine(item) * to_2geom(affine));
}
sp_item_write_transform(item, SP_OBJECT_REPR(item), item->transform, NULL);
}
if (selection->isEmpty())
return;
- NR::Maybe<NR::Rect> const bbox(selection->bounds());
+ boost::optional<NR::Rect> const bbox(selection->bounds());
if ( !bbox || bbox->isEmpty() ) {
return;
}
@@ -1241,7 +1270,7 @@ void sp_selection_scale_relative(Inkscape::Selection *selection, NR::Point const
if (selection->isEmpty())
return;
- NR::Maybe<NR::Rect> const bbox(selection->bounds());
+ boost::optional<NR::Rect> const bbox(selection->bounds());
if ( !bbox || bbox->isEmpty() ) {
return;
@@ -1350,7 +1379,7 @@ sp_selection_rotate(Inkscape::Selection *selection, gdouble const angle_degrees)
if (selection->isEmpty())
return;
- NR::Maybe<NR::Point> center = selection->center();
+ boost::optional<NR::Point> center = selection->center();
if (!center) {
return;
}
if (selection->isEmpty())
return;
- NR::Maybe<NR::Rect> const bbox(selection->bounds());
- NR::Maybe<NR::Point> center = selection->center();
+ boost::optional<NR::Rect> const bbox(selection->bounds());
+ boost::optional<NR::Point> center = selection->center();
if ( !bbox || !center ) {
return;
if (selection->isEmpty())
return;
- NR::Maybe<NR::Rect> const bbox(selection->bounds());
+ boost::optional<NR::Rect> const bbox(selection->bounds());
if (!bbox) {
return;
}
if (selection->isEmpty())
return;
- NR::Maybe<NR::Rect> sel_bbox = selection->bounds();
+ boost::optional<NR::Rect> sel_bbox = selection->bounds();
if (!sel_bbox) {
return;
}
ShapeEditor * shape_editor = SP_NODE_CONTEXT( dt->event_context )->shape_editor;
- shape_editor->set_item(SP_ITEM(child));
+ // TODO: should we set the item for nodepath or knotholder or both? seems to work with both.
+ shape_editor->set_item(SP_ITEM(child), SH_NODEPATH);
+ shape_editor->set_item(SP_ITEM(child), SH_KNOTHOLDER);
Inkscape::NodePath::Path *np = shape_editor->get_nodepath();
if (np) {
// take colors from prefs (same as used in outline mode)
void scroll_to_show_item(SPDesktop *desktop, SPItem *item)
{
NR::Rect dbox = desktop->get_display_area();
- NR::Maybe<NR::Rect> sbox = sp_item_bbox_desktop(item);
+ boost::optional<NR::Rect> sbox = sp_item_bbox_desktop(item);
if ( sbox && dbox.contains(*sbox) == false ) {
NR::Point const s_dt = sbox->midpoint();
g_slist_free(newsel);
}
+void
+sp_selection_relink()
+{
+ SPDesktop *desktop = SP_ACTIVE_DESKTOP;
+ if (!desktop)
+ return;
+
+ Inkscape::Selection *selection = sp_desktop_selection(desktop);
+
+ if (selection->isEmpty()) {
+ desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>clones</b> to relink."));
+ return;
+ }
+
+ Inkscape::UI::ClipboardManager *cm = Inkscape::UI::ClipboardManager::get();
+ const gchar *newid = cm->getFirstObjectID();
+ if (!newid) {
+ desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Copy an <b>object</b> to clipboard to relink clones to."));
+ return;
+ }
+ gchar *newref = g_strdup_printf ("#%s", newid);
+
+ // Get a copy of current selection.
+ bool relinked = false;
+ for (GSList *items = (GSList *) selection->itemList();
+ items != NULL;
+ items = items->next)
+ {
+ SPItem *item = (SPItem *) items->data;
+
+ if (!SP_IS_USE(item))
+ continue;
+
+ SP_OBJECT_REPR(item)->setAttribute("xlink:href", newref);
+ SP_OBJECT(item)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
+ relinked = true;
+ }
+
+ g_free(newref);
+
+ if (!relinked) {
+ desktop->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("<b>No clones to relink</b> in the selection."));
+ } else {
+ sp_document_done(sp_desktop_document(desktop), SP_VERB_EDIT_UNLINK_CLONE,
+ _("Relink clone"));
+ }
+}
+
+
void
sp_selection_unlink()
{
Inkscape::Selection *selection = sp_desktop_selection(desktop);
if (selection->isEmpty()) {
- desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select a <b>clone</b> to unlink."));
+ desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>clones</b> to unlink."));
return;
}
}
sp_document_ensure_up_to_date(doc);
- NR::Maybe<NR::Rect> r = selection->bounds();
- NR::Maybe<NR::Point> c = selection->center();
+ boost::optional<NR::Rect> r = selection->bounds();
+ boost::optional<NR::Point> c = selection->center();
if ( !r || !c || r->isEmpty() ) {
return;
}
// bottommost object, after sorting
SPObject *parent = SP_OBJECT_PARENT (items->data);
- NR::Matrix parent_transform = sp_item_i2root_affine(SP_ITEM(parent));
+ NR::Matrix parent_transform = from_2geom(sp_item_i2root_affine(SP_ITEM(parent)));
// remember the position of the first item
gint pos = SP_OBJECT_REPR (items->data)->position();
}
sp_document_ensure_up_to_date(doc);
- NR::Maybe<NR::Rect> r = selection->bounds();
+ boost::optional<NR::Rect> r = selection->bounds();
if ( !r || r->isEmpty() ) {
return;
}
// bottommost object, after sorting
SPObject *parent = SP_OBJECT_PARENT (items->data);
- NR::Matrix parent_transform = sp_item_i2root_affine(SP_ITEM(parent));
+ NR::Matrix parent_transform = from_2geom(sp_item_i2root_affine(SP_ITEM(parent)));
// remember the position of the first item
gint pos = SP_OBJECT_REPR (items->data)->position();
return;
}
+ desktop->messageStack()->flash(Inkscape::IMMEDIATE_MESSAGE, _("Rendering bitmap..."));
+ // set "busy" cursor
+ desktop->setWaitingCursor();
+
// Get the bounding box of the selection
NRRect bbox;
sp_document_ensure_up_to_date (document);
selection->bounds(&bbox);
if (NR_RECT_DFLS_TEST_EMPTY(&bbox)) {
+ desktop->clearWaitingCursor();
return; // exceptional situation, so not bother with a translatable error message, just quit quietly
}
unsigned width = (unsigned) floor ((bbox.x1 - bbox.x0) * res / PX_PER_IN);
unsigned height =(unsigned) floor ((bbox.y1 - bbox.y0) * res / PX_PER_IN);
- // Find out if we have to run a filter
+ // Find out if we have to run an external filter
gchar const *run = NULL;
gchar const *filter = prefs_get_string_attribute ("options.createbitmap", "filter");
if (filter) {
}
// Calculate the matrix that will be applied to the image so that it exactly overlaps the source objects
- NR::Matrix eek = sp_item_i2d_affine (SP_ITEM(parent_object));
+ NR::Matrix eek = from_2geom(sp_item_i2d_affine (SP_ITEM(parent_object)));
NR::Matrix t;
double shift_x = bbox.x0;
// Run filter, if any
if (run) {
g_print ("Running external filter: %s\n", run);
- system (run);
+ int retval;
+ retval = system (run);
}
// Import the image back
_("Create bitmap"));
}
+ desktop->clearWaitingCursor();
+
g_free (filename);
g_free (filepath);
}
sp_document_ensure_up_to_date(doc);
gchar const *attributeName = apply_clip_path ? "clip-path" : "mask";
- std::map<SPObject*,SPItem*> referenced_objects;
+ std::map<SPObject*,SPItem*> referenced_objects;
+ // SPObject* refers to a group containing the clipped path or mask itself,
+ // whereas SPItem* refers to the item being clipped or masked
for (GSList const *i = selection->itemList(); NULL != i; i = i->next) {
if (remove_original) {
// remember referenced mask/clippath, so orphaned masks can be moved back to document
// restore mask objects into a document
for ( std::map<SPObject*,SPItem*>::iterator it = referenced_objects.begin() ; it != referenced_objects.end() ; ++it) {
- SPObject *obj = (*it).first;
+ SPObject *obj = (*it).first; // Group containing the clipped paths or masks
GSList *items_to_move = NULL;
for (SPObject *child = sp_object_first_child(obj) ; child != NULL; child = SP_OBJECT_NEXT(child) ) {
+ // Collect all clipped paths and masks within a single group
Inkscape::XML::Node *copy = SP_OBJECT_REPR(child)->duplicate(xml_doc);
items_to_move = g_slist_prepend (items_to_move, copy);
}
Inkscape::XML::Node *parent = SP_OBJECT_REPR((*it).second)->parent();
gint pos = SP_OBJECT_REPR((*it).second)->position();
+ // Iterate through all clipped paths / masks
for (GSList *i = items_to_move; NULL != i; i = i->next) {
Inkscape::XML::Node *repr = (Inkscape::XML::Node *)i->data;
sp_document_done (doc, SP_VERB_OBJECT_UNSET_MASK, _("Release mask"));
}
-void fit_canvas_to_selection(SPDesktop *desktop) {
- g_return_if_fail(desktop != NULL);
+/**
+ * Returns true if an undoable change should be recorded.
+ */
+bool
+fit_canvas_to_selection(SPDesktop *desktop)
+{
+ g_return_val_if_fail(desktop != NULL, false);
SPDocument *doc = sp_desktop_document(desktop);
- g_return_if_fail(doc != NULL);
- g_return_if_fail(desktop->selection != NULL);
+ g_return_val_if_fail(doc != NULL, false);
+ g_return_val_if_fail(desktop->selection != NULL, false);
if (desktop->selection->isEmpty()) {
desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>object(s)</b> to fit canvas to."));
- return;
+ return false;
}
- NR::Maybe<NR::Rect> const bbox(desktop->selection->bounds());
+ boost::optional<NR::Rect> const bbox(desktop->selection->bounds());
if (bbox && !bbox->isEmpty()) {
doc->fitToRect(*bbox);
+ return true;
+ } else {
+ return false;
}
-};
+}
-void fit_canvas_to_drawing(SPDocument *doc) {
- g_return_if_fail(doc != NULL);
+/**
+ * Fit canvas to the bounding box of the selection, as an undoable action.
+ */
+void
+verb_fit_canvas_to_selection(SPDesktop *const desktop)
+{
+ if (fit_canvas_to_selection(desktop)) {
+ sp_document_done(sp_desktop_document(desktop), SP_VERB_FIT_CANVAS_TO_SELECTION,
+ _("Fit Page to Selection"));
+ }
+}
+
+bool
+fit_canvas_to_drawing(SPDocument *doc)
+{
+ g_return_val_if_fail(doc != NULL, false);
sp_document_ensure_up_to_date(doc);
SPItem const *const root = SP_ITEM(doc->root);
- NR::Maybe<NR::Rect> const bbox(root->getBounds(sp_item_i2r_affine(root)));
+ boost::optional<NR::Rect> const bbox(root->getBounds(from_2geom(sp_item_i2r_affine(root))));
if (bbox && !bbox->isEmpty()) {
doc->fitToRect(*bbox);
+ return true;
+ } else {
+ return false;
}
-};
+}
+
+void
+verb_fit_canvas_to_drawing(SPDesktop *desktop)
+{
+ if (fit_canvas_to_drawing(sp_desktop_document(desktop))) {
+ sp_document_done(sp_desktop_document(desktop), SP_VERB_FIT_CANVAS_TO_DRAWING,
+ _("Fit Page to Drawing"));
+ }
+}
void fit_canvas_to_selection_or_drawing(SPDesktop *desktop) {
g_return_if_fail(desktop != NULL);
g_return_if_fail(doc != NULL);
g_return_if_fail(desktop->selection != NULL);
- if (desktop->selection->isEmpty()) {
- fit_canvas_to_drawing(doc);
- } else {
- fit_canvas_to_selection(desktop);
+ bool const changed = ( desktop->selection->isEmpty()
+ ? fit_canvas_to_drawing(doc)
+ : fit_canvas_to_selection(desktop) );
+ if (changed) {
+ sp_document_done(sp_desktop_document(desktop), SP_VERB_FIT_CANVAS_TO_SELECTION_OR_DRAWING,
+ _("Fit Page to Selection or Drawing"));
}
-
- sp_document_done(doc, SP_VERB_FIT_CANVAS_TO_DRAWING,
- _("Fit page to selection"));
};
static void itemtree_map(void (*f)(SPItem *, SPDesktop *), SPObject *root, SPDesktop *desktop) {