summaryrefslogtreecommitdiffstats
path: root/src/ui
diff options
context:
space:
mode:
authorJabier Arraiza Cenoz <jabier.arraiza@marker.es>2015-10-16 17:17:47 +0000
committerjabiertxof <jabier.arraiza@marker.es>2015-10-16 17:17:47 +0000
commit69aa4c6436321b22525fb11c552ca7d60ac1b096 (patch)
tree403718e9d2f93ab95ef6b1a21e9c0c1299009cb6 /src/ui
parentremoved unnecesary line (diff)
downloadinkscape-69aa4c6436321b22525fb11c552ca7d60ac1b096.tar.gz
inkscape-69aa4c6436321b22525fb11c552ca7d60ac1b096.zip
Add convert to guides option
(bzr r14393.2.4)
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/tools/measure-tool.cpp91
-rw-r--r--src/ui/tools/measure-tool.h1
2 files changed, 92 insertions, 0 deletions
diff --git a/src/ui/tools/measure-tool.cpp b/src/ui/tools/measure-tool.cpp
index 7fedf6631..bf82fb745 100644
--- a/src/ui/tools/measure-tool.cpp
+++ b/src/ui/tools/measure-tool.cpp
@@ -650,6 +650,97 @@ void MeasureTool::setMarker(bool isStart)
path->updateRepr();
}
+void MeasureTool::toGuides()
+{
+ SPDesktop *desktop = SP_ACTIVE_DESKTOP;
+ SPDocument *doc = desktop->getDocument();
+ Inkscape::XML::Document *xml_doc = doc->getReprDoc();
+ Geom::Point start = start_p * SP_ITEM(desktop->currentLayer())->i2doc_affine().inverse();
+ Geom::Point end = end_p * SP_ITEM(desktop->currentLayer())->i2doc_affine().inverse();
+ Geom::Ray ray(start,end);
+ SPNamedView *namedview = desktop->namedview;
+ if(!namedview){
+ return;
+ }
+ //meassure angle
+ Inkscape::XML::Node *measure_line;
+ measure_line = xml_doc->createElement("sodipodi:guide");
+ std::stringstream position;
+ position.imbue(std::locale::classic());
+ position << start[Geom::X] << "," << start[Geom::Y];
+ measure_line->setAttribute("position", position.str().c_str() );
+ Geom::Point unit_vector = Geom::rot90(start.polar(ray.angle()));
+ std::stringstream angle;
+ angle.imbue(std::locale::classic());
+ angle << unit_vector[Geom::X] << "," << unit_vector[Geom::Y];
+ measure_line->setAttribute("orientation", angle.str().c_str());
+ namedview->appendChild(measure_line);
+ Inkscape::GC::release(measure_line);
+ //base angle
+ if(explicitBase){
+ explicitBase = *explicitBase * SP_ITEM(desktop->currentLayer())->i2doc_affine().inverse();
+ ray.setPoints(start, *explicitBase);
+ if(ray.angle() != 0){
+ Inkscape::XML::Node *base_line;
+ base_line = xml_doc->createElement("sodipodi:guide");
+ position.str("");
+ position.imbue(std::locale::classic());
+ position << start[Geom::X] << "," << start[Geom::Y];
+ base_line->setAttribute("position", position.str().c_str() );
+ Geom::Point unit_vector = Geom::rot90(start.polar(ray.angle()));
+ std::stringstream angle;
+ angle.imbue(std::locale::classic());
+ angle << unit_vector[Geom::X] << "," << unit_vector[Geom::Y];
+ base_line->setAttribute("orientation", angle.str().c_str());
+ namedview->appendChild(base_line);
+ Inkscape::GC::release(base_line);
+ }
+ }
+ //start horizontal
+ Inkscape::XML::Node *start_horizontal;
+ start_horizontal = xml_doc->createElement("sodipodi:guide");
+ position.str("");
+ position.imbue(std::locale::classic());
+ position << start[Geom::X] << "," << start[Geom::Y];
+ start_horizontal->setAttribute("position", position.str().c_str() );
+ start_horizontal->setAttribute("orientation", "0,1");
+ namedview->appendChild(start_horizontal);
+ Inkscape::GC::release(start_horizontal);
+ //start vertical
+ Inkscape::XML::Node *start_vertical;
+ start_vertical = xml_doc->createElement("sodipodi:guide");
+ position.str("");
+ position.imbue(std::locale::classic());
+ position << start[Geom::X] << "," << start[Geom::Y];
+ start_vertical->setAttribute("position", position.str().c_str() );
+ start_vertical->setAttribute("orientation", "1,0");
+ namedview->appendChild(start_vertical);
+ Inkscape::GC::release(start_vertical);
+ //end horizontal
+ Inkscape::XML::Node *end_horizontal;
+ end_horizontal = xml_doc->createElement("sodipodi:guide");
+ position.str("");
+ position.imbue(std::locale::classic());
+ position << end[Geom::X] << "," << end[Geom::Y];
+ end_horizontal->setAttribute("position", position.str().c_str() );
+ end_horizontal->setAttribute("orientation", "0,1");
+ namedview->appendChild(end_horizontal);
+ Inkscape::GC::release(end_horizontal);
+ //start vertical
+ Inkscape::XML::Node *end_vertical;
+ end_vertical = xml_doc->createElement("sodipodi:guide");
+ position.str("");
+ position.imbue(std::locale::classic());
+ position << end[Geom::X] << "," << end[Geom::Y];
+ end_vertical->setAttribute("position", position.str().c_str() );
+ end_vertical->setAttribute("orientation", "1,0");
+ namedview->appendChild(end_vertical);
+ Inkscape::GC::release(end_vertical);
+
+ doc->ensureUpToDate();
+ DocumentUndo::done(desktop->getDocument(), SP_VERB_CONTEXT_MEASURE,_("Add guides from measure tool"));
+}
+
void MeasureTool::toItem()
{
SPDesktop *desktop = SP_ACTIVE_DESKTOP;
diff --git a/src/ui/tools/measure-tool.h b/src/ui/tools/measure-tool.h
index 919152aad..b53131ef9 100644
--- a/src/ui/tools/measure-tool.h
+++ b/src/ui/tools/measure-tool.h
@@ -38,6 +38,7 @@ public:
virtual bool root_handler(GdkEvent* event);
virtual void showCanvasItems(bool to_item = false, Inkscape::XML::Node *measure_repr = NULL);
virtual void reverseKnots();
+ virtual void toGuides();
virtual void toMarkDimension();
virtual void toItem();
virtual void reset();