summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJabier Arraiza Cenoz <jabier.arraiza@marker.es>2014-03-31 22:48:28 +0000
committerJabiertxof <jtx@jtx.marker.es>2014-03-31 22:48:28 +0000
commit2b19c5f6508b7a59766d89f315f9f4fbc364f288 (patch)
tree11c692eb43b44fca5c9a636eb991d13495e0ddae /src
parentuse <cmath> instead <math.h> by point of Vinícius (diff)
downloadinkscape-2b19c5f6508b7a59766d89f315f9f4fbc364f288.tar.gz
inkscape-2b19c5f6508b7a59766d89f315f9f4fbc364f288.zip
Some node.cpp/h work moved to path_manipulator.
Header variable bsplineWeight removed from all. Simplification of code with less functions in path_manipulator. To fix: tips stop working because is handled by two static functions and couldent call to path_manipulator from here. Vinícius, any work arround? lines 480,481,1426,1427,1462 of node.cpp. gez: ¿Puedes probar si notas algun bug o problema? principalmente con la herramienta nodo, gracias. (bzr r11950.1.322)
Diffstat (limited to 'src')
-rw-r--r--src/ui/tool/curve-drag-point.cpp4
-rw-r--r--src/ui/tool/node.cpp166
-rw-r--r--src/ui/tool/node.h2
-rw-r--r--src/ui/tool/path-manipulator.cpp46
-rw-r--r--src/ui/tool/path-manipulator.h10
5 files changed, 118 insertions, 110 deletions
diff --git a/src/ui/tool/curve-drag-point.cpp b/src/ui/tool/curve-drag-point.cpp
index ad03cf75d..013553410 100644
--- a/src/ui/tool/curve-drag-point.cpp
+++ b/src/ui/tool/curve-drag-point.cpp
@@ -94,8 +94,8 @@ void CurveDragPoint::dragged(Geom::Point &new_pos, GdkEventMotion *event)
if(!_pm.isBSpline(false)){
first->front()->move(first->front()->position() + offset0);
second->back()->move(second->back()->position() + offset1);
- }else if(weight>=0.8 && !second->isEndNode() && held_shift(*event))second->back()->move(new_pos);
- else if(weight<=0.2 && !first->isEndNode() && held_shift(*event))first->front()->move(new_pos);
+ }else if(weight>=0.8 && held_shift(*event))second->back()->move(new_pos);
+ else if(weight<=0.2 && held_shift(*event))first->front()->move(new_pos);
_pm.update();
}
diff --git a/src/ui/tool/node.cpp b/src/ui/tool/node.cpp
index 3be3a89a7..1eaf0afa7 100644
--- a/src/ui/tool/node.cpp
+++ b/src/ui/tool/node.cpp
@@ -30,6 +30,7 @@
#include <gdk/gdkkeysyms.h>
#include <cmath>
+
namespace {
Inkscape::ControlType nodeTypeToCtrlType(Inkscape::UI::NodeType type)
@@ -168,9 +169,9 @@ void Handle::move(Geom::Point const &new_pos)
setPosition(new_pos);
//move the handler and its oposite the same proportion
- if(_pm().isBSpline(false)){
+ if(_pm().isBSpline()){
setPosition(_pm().BSplineHandleReposition(this));
- this->other()->setPosition(_pm().BSplineHandleReposition(this->other(),_parent->bsplineWeight));
+ this->other()->setPosition(_pm().BSplineHandleReposition(this->other(),true));
}
return;
}
@@ -185,9 +186,9 @@ void Handle::move(Geom::Point const &new_pos)
setRelativePos(new_delta);
//move the handler and its oposite the same proportion
- if(_pm().isBSpline(false)){
+ if(_pm().isBSpline()){
setPosition(_pm().BSplineHandleReposition(this));
- this->other()->setPosition(_pm().BSplineHandleReposition(this->other(),_parent->bsplineWeight));
+ this->other()->setPosition(_pm().BSplineHandleReposition(this->other(),true));
}
return;
@@ -211,9 +212,9 @@ void Handle::move(Geom::Point const &new_pos)
setPosition(new_pos);
// moves the handler and its oposite the same proportion
- if(_pm().isBSpline(false)){
+ if(_pm().isBSpline()){
setPosition(_pm().BSplineHandleReposition(this));
- this->other()->setPosition(_pm().BSplineHandleReposition(this->other(),_parent->bsplineWeight));
+ this->other()->setPosition(_pm().BSplineHandleReposition(this->other(),true));
}
}
@@ -305,9 +306,9 @@ bool Handle::_eventHandler(Inkscape::UI::Tools::ToolBase *event_context, GdkEven
//this function moves the handler and its oposite to the default proportion of 0.3334
void Handle::handle_2button_press(){
- if(_pm().isBSpline(false)){
+ if(_pm().isBSpline()){
setPosition(_pm().BSplineHandleReposition(this,0.3334));
- this->other()->setPosition(_pm().BSplineHandleReposition(this->other(),_parent->bsplineWeight));
+ this->other()->setPosition(_pm().BSplineHandleReposition(this->other(),0.3334));
_pm().update();
}
}
@@ -361,17 +362,16 @@ void Handle::dragged(Geom::Point &new_pos, GdkEventMotion *event)
new_pos = result;
// moves the handler and its oposite in X fixed positions depending on parameter "steps with control"
// by default in live BSpline
- if(_pm().isBSpline(false)){
+ if(_pm().isBSpline()){
setPosition(new_pos);
int steps = _pm().BSplineGetSteps();
- _parent->bsplineWeight = ceilf(_pm().BSplineHandlePosition(this)*steps)/steps;
- new_pos=_pm().BSplineHandleReposition(this,_parent->bsplineWeight);
+ new_pos=_pm().BSplineHandleReposition(this,ceilf(_pm().BSplineHandlePosition(this)*steps)/steps);
}
}
std::vector<Inkscape::SnapCandidatePoint> unselected;
//if the snap adjustment is activated and it is not bspline
- if (snap && !_pm().isBSpline(false)) {
+ if (snap && !_pm().isBSpline()) {
ControlPointSelection::Set &nodes = _parent->_selection.allPoints();
for (ControlPointSelection::Set::iterator i = nodes.begin(); i != nodes.end(); ++i) {
Node *n = static_cast<Node*>(*i);
@@ -412,7 +412,7 @@ void Handle::dragged(Geom::Point &new_pos, GdkEventMotion *event)
}
}
//if it is bspline but SHIFT or CONTROL are not pressed it fixes it in the original position
- if(_pm().isBSpline(false) && !held_shift(*event) && !held_control(*event)){
+ if(_pm().isBSpline() && !held_shift(*event) && !held_control(*event)){
new_pos=_last_drag_origin();
}
move(new_pos); // needed for correct update, even though it's redundant
@@ -431,10 +431,6 @@ void Handle::ungrabbed(GdkEventButton *event)
Geom::Point dist = _desktop->d2w(_parent->position()) - _desktop->d2w(position());
if (dist.length() <= drag_tolerance) {
move(_parent->position());
- //sets the bspline strength to 0.0000
- if(_pm().isBSpline(false)){
- _parent->bsplineWeight = 0.0000;
- }
}
}
@@ -481,8 +477,8 @@ Glib::ustring Handle::_getTip(unsigned state) const
// to show the appropiate messages. We cannot do it in any different way becasue the function is constant
bool isBSpline = false;
- if( _parent->bsplineWeight != 0.0000)
- isBSpline = true;
+ //if( _parent->bsplineWeight != 0.0000)
+ // isBSpline = true;
bool can_shift_rotate = _parent->type() == NODE_CUSP && !other()->isDegenerate();
if (can_shift_rotate && !isBSpline) {
more = C_("Path handle tip", "more: Shift, Ctrl, Alt");
@@ -622,11 +618,21 @@ void Node::move(Geom::Point const &new_pos)
Geom::Point old_pos = position();
Geom::Point delta = new_pos - position();
- // save the previous node strength to apply it again once the node is moved
- double oldPos = 0.0000;
+ // save the previous nodes strength to apply it again once the node is moved
+ double nodeWeight = 0.0000;
+ double nextNodeWeight = 0.0000;
+ double prevNodeWeight = 0.0000;
Node *n = this;
- if(_pm().isBSpline(false)){
- oldPos = n->bsplineWeight;
+ Node * nextNode = n->nodeToward(n->front());
+ Node * prevNode = n->nodeToward(n->back());
+ if(_pm().isBSpline()){
+ nodeWeight = _pm().BSplineHandlePosition(n->front());
+ if(nextNode){
+ nextNodeWeight = _pm().BSplineHandlePosition(nextNode->front());
+ }
+ if(prevNode){
+ prevNodeWeight = _pm().BSplineHandlePosition(prevNode->front());
+ }
}
setPosition(new_pos);
@@ -639,21 +645,49 @@ void Node::move(Geom::Point const &new_pos)
_fixNeighbors(old_pos, new_pos);
// move the affected handlers. First the node ones, later the adjoining ones.
- if(_pm().isBSpline(false)){
- _front.setPosition(_pm().BSplineHandleReposition(this->front(),oldPos));
- _back.setPosition(_pm().BSplineHandleReposition(this->back(),oldPos));
- _pm().BSplineNodeHandlesReposition(this);
+ if(_pm().isBSpline()){
+ _front.setPosition(_pm().BSplineHandleReposition(this->front(),nodeWeight));
+ _back.setPosition(_pm().BSplineHandleReposition(this->back(),nodeWeight));
+ if(prevNode){
+ if(prevNode->front()->isDegenerate()){
+ prevNode->front()->setPosition(_pm().BSplineHandleReposition(prevNode->front(),prevNodeWeight));
+ }else{
+ prevNode->front()->setPosition(_pm().BSplineHandleReposition(prevNode->front(),true));
+ }
+ }
+ if(nextNode){
+ if(nextNode->back()->isDegenerate()){
+ nextNode->back()->setPosition(_pm().BSplineHandleReposition(nextNode->back(),nextNodeWeight));
+ }else{
+ nextNode->back()->setPosition(_pm().BSplineHandleReposition(nextNode->back(),true));
+ }
+ }
}
}
void Node::transform(Geom::Affine const &m)
{
- // save the previous node strength to apply it again later when the node is moved
- double oldPos = 0.0000;
- if(_pm().isBSpline(false)){
- oldPos = this->bsplineWeight;
- }
+
Geom::Point old_pos = position();
+
+ // save the previous nodes strength to apply it again once the node is moved
+ double nodeWeight = 0.0000;
+ double nextNodeWeight = 0.0000;
+ double prevNodeWeight = 0.0000;
+
+ Node *n = this;
+ Node * nextNode = n->nodeToward(n->front());
+ Node * prevNode = n->nodeToward(n->back());
+ if(_pm().isBSpline()){
+ nodeWeight = _pm().BSplineHandlePosition(n->front());
+ if(nextNode){
+ nextNodeWeight = _pm().BSplineHandlePosition(nextNode->front());
+ }
+ if(prevNode){
+ prevNodeWeight = _pm().BSplineHandlePosition(prevNode->front());
+ }
+ }
+
setPosition(position() * m);
_front.setPosition(_front.position() * m);
_back.setPosition(_back.position() * m);
@@ -663,10 +697,23 @@ void Node::transform(Geom::Affine const &m)
_fixNeighbors(old_pos, position());
// move the involved handlers, first the node ones, later the adjoining ones
- if(_pm().isBSpline(false)){
- _front.setPosition(_pm().BSplineHandleReposition(this->front(),oldPos));
- _back.setPosition(_pm().BSplineHandleReposition(this->back(),oldPos));
- _pm().BSplineNodeHandlesReposition(this);
+ if(_pm().isBSpline()){
+ _front.setPosition(_pm().BSplineHandleReposition(this->front(),nodeWeight));
+ _back.setPosition(_pm().BSplineHandleReposition(this->back(),nodeWeight));
+ if(prevNode){
+ if(prevNode->front()->isDegenerate()){
+ prevNode->front()->setPosition(_pm().BSplineHandleReposition(prevNode->front(),prevNodeWeight));
+ }else{
+ prevNode->front()->setPosition(_pm().BSplineHandleReposition(prevNode->front(),true));
+ }
+ }
+ if(nextNode){
+ if(nextNode->back()->isDegenerate()){
+ nextNode->back()->setPosition(_pm().BSplineHandleReposition(nextNode->back(),nextNodeWeight));
+ }else{
+ nextNode->back()->setPosition(_pm().BSplineHandleReposition(nextNode->back(),true));
+ }
+ }
}
}
@@ -754,19 +801,6 @@ void Node::showHandles(bool v)
_back.setVisible(v);
}
- // define the node strength, depending on being or not bspline traced.
- // every time we operate over these handlers in a trace bspline
- // that strength needs to be updated.
-
- this->bsplineWeight = 0.0000;
- if(_pm().isBSpline(false) && (!_front.isDegenerate() || !_back.isDegenerate())){
- if (!_front.isDegenerate()) {
- _pm().BSplineHandlePosition(&_front);
- }
- if (!_back.isDegenerate()) {
- _pm().BSplineHandlePosition(&_back);
- }
- }
}
void Node::updateHandles()
@@ -870,10 +904,13 @@ void Node::setType(NodeType type, bool update_handles)
}
/* in node type changes, about bspline traces, we can mantain them with 0.0000 power in border mode,
or we give them the default power in curve mode */
- if(_pm().isBSpline(false)){
- if(this->bsplineWeight !=0.0000) this->bsplineWeight = 0.3334;
- _front.setPosition(_pm().BSplineHandleReposition(this->front(),this->bsplineWeight));
- _back.setPosition(_pm().BSplineHandleReposition(this->back(),this->bsplineWeight));
+ if(_pm().isBSpline()){
+ double weight = 0.0000;
+ if(_pm().BSplineHandlePosition(this->front()) != 0.0000){
+ weight = 0.3334;
+ }
+ _front.setPosition(_pm().BSplineHandleReposition(this->front(),weight));
+ _back.setPosition(_pm().BSplineHandleReposition(this->back(),weight));
}
}
_type = type;
@@ -1123,20 +1160,9 @@ void Node::_setState(State state)
mgr.setActive(_canvas_item, true);
mgr.setPrelight(_canvas_item, false);
//this shows the handlers when selecting the nodes
- if(_pm().isBSpline(false)){
- if(!this->back()->isDegenerate()){
- _pm().BSplineHandlePosition(this->back());
- }else if (!this->front()->isDegenerate()){
- _pm().BSplineHandlePosition(this->front());
- }else{
- this->bsplineWeight = 0.0000;
- }
- if(!this->front()->isDegenerate()){
- this->front()->setPosition(_pm().BSplineHandleReposition(this->front(),this->bsplineWeight));
- }
- if(!this->back()->isDegenerate()){
- this->back()->setPosition(_pm().BSplineHandleReposition(this->back(),this->bsplineWeight));
- }
+ if(_pm().isBSpline()){
+ this->front()->setPosition(_pm().BSplineHandleReposition(this->front()));
+ this->back()->setPosition(_pm().BSplineHandleReposition(this->back()));
}
break;
}
@@ -1397,8 +1423,8 @@ Glib::ustring Node::_getTip(unsigned state) const
to show the appropiate messages. We cannot do it in any other way, because the
function is constant */
bool isBSpline = false;
- if( this->bsplineWeight != 0.0000)
- isBSpline = true;
+ //if( this->bsplineWeight != 0.0000)
+ // isBSpline = true;
if (state_held_shift(state)) {
bool can_drag_out = (_next() && _front.isDegenerate()) || (_prev() && _back.isDegenerate());
if (can_drag_out) {
@@ -1433,7 +1459,7 @@ Glib::ustring Node::_getTip(unsigned state) const
"<b>%s</b>: drag to shape the path (more: Shift, Ctrl, Alt)"), nodetype);
}else if(_selection.size() == 1){
return format_tip(C_("Path node tip",
- "<b>BSpline node</b>: %g weight, drag to shape the path (more: Shift, Ctrl, Alt)"),this->bsplineWeight);
+ "<b>BSpline node</b>: %g weight, drag to shape the path (more: Shift, Ctrl, Alt)"),0.0000/*this->bsplineWeight*/);
}
return format_tip(C_("Path node tip",
"<b>%s</b>: drag to shape the path, click to toggle scale/rotation handles (more: Shift, Ctrl, Alt)"), nodetype);
diff --git a/src/ui/tool/node.h b/src/ui/tool/node.h
index fc36502a5..202dbb3cd 100644
--- a/src/ui/tool/node.h
+++ b/src/ui/tool/node.h
@@ -191,8 +191,6 @@ public:
bool isEndNode() const;
Handle *front() { return &_front; }
Handle *back() { return &_back; }
- //strength value for each node
- double bsplineWeight;
/**
* Gets the handle that faces the given adjacent node.
diff --git a/src/ui/tool/path-manipulator.cpp b/src/ui/tool/path-manipulator.cpp
index 841ab659a..905df61f4 100644
--- a/src/ui/tool/path-manipulator.cpp
+++ b/src/ui/tool/path-manipulator.cpp
@@ -666,14 +666,11 @@ unsigned PathManipulator::_deleteStretch(NodeList::iterator start, NodeList::ite
}
// if we are removing, we readjust the handlers
if(isBSpline()){
- double pos = 0.0000;
if(start.prev()){
- pos = BSplineHandlePosition(start.prev()->back());
- start.prev()->front()->setPosition(BSplineHandleReposition(start.prev()->front(),pos));
+ start.prev()->front()->setPosition(BSplineHandleReposition(start.prev()->front(),true));
}
if(end){
- pos = BSplineHandlePosition(end->front());
- end->back()->setPosition(BSplineHandleReposition(end->back(),pos));
+ end->back()->setPosition(BSplineHandleReposition(end->back(),true));
}
}
@@ -1209,31 +1206,36 @@ bool PathManipulator::isBSpline(bool recalculate){
return _is_bspline;
}
-// returns the corresponding strength to the position of a handler
-double PathManipulator::BSplineHandlePosition(Handle *h){
+// returns the corresponding strength to the position of the handlers
+double PathManipulator::BSplineHandlePosition(Handle *h, bool other){
using Geom::X;
using Geom::Y;
double pos = 0.0000;
Node *n = h->parent();
Node * nextNode = NULL;
+ if(other){
+ h = h->other();
+ }
nextNode = n->nodeToward(h);
- if(nextNode && n->position() != h->position()){
+ if(nextNode && !Geom::are_near(n->position(), h->position())){
SPCurve *lineInsideNodes = new SPCurve();
lineInsideNodes->moveto(n->position());
lineInsideNodes->lineto(nextNode->position());
pos = Geom::nearest_point(h->position(),*lineInsideNodes->first_segment());
}
- n->bsplineWeight = pos;
+ if ((pos == 0.0000 || pos == 1.0000) && other == false){
+ return BSplineHandlePosition(h, true);
+ }
return pos;
}
-// moves the handler to the corresponding position
-Geom::Point PathManipulator::BSplineHandleReposition(Handle *h){
- double pos = this->BSplineHandlePosition(h);
+// give the location for the handler in the corresponding position
+Geom::Point PathManipulator::BSplineHandleReposition(Handle *h, bool other){
+ double pos = this->BSplineHandlePosition(h, other);
return BSplineHandleReposition(h,pos);
}
-// moves the handler to the specified position
+// give the location for the handler to the specified position
Geom::Point PathManipulator::BSplineHandleReposition(Handle *h,double pos){
using Geom::X;
using Geom::Y;
@@ -1247,34 +1249,16 @@ Geom::Point PathManipulator::BSplineHandleReposition(Handle *h,double pos){
lineInsideNodes->moveto(n->position());
lineInsideNodes->lineto(nextNode->position());
SBasisInsideNodes = lineInsideNodes->first_segment()->toSBasis();
- n->bsplineWeight = pos;
ret = SBasisInsideNodes.valueAt(pos);
ret = Geom::Point(ret[X] + 0.005,ret[Y] + 0.005);
}else{
if(pos == 0.0000){
- n->bsplineWeight = 0.0000;
ret = n->position();
}
}
return ret;
}
-//moves the node handlers and its oposite handlers to the strength of its nodes
-void PathManipulator::BSplineNodeHandlesReposition(Node *n){
- Node * nextNode = n->nodeToward(n->front());
- Node * prevNode = n->nodeToward(n->back());
- if(prevNode){
- if(!prevNode->isEndNode())
- prevNode->back()->setPosition(BSplineHandleReposition(prevNode->back(),prevNode->bsplineWeight));
- prevNode->front()->setPosition(BSplineHandleReposition(prevNode->front(),prevNode->bsplineWeight));
- }
- if(nextNode){
- if(!nextNode->isEndNode())
- nextNode->front()->setPosition(BSplineHandleReposition(nextNode->front(),nextNode->bsplineWeight));
- nextNode->back()->setPosition(BSplineHandleReposition(nextNode->back(),nextNode->bsplineWeight));
- }
-}
-
/** Construct the geometric representation of nodes and handles, update the outline
* and display
* \param alert_LPE if true, first the LPE is warned what the new path is going to be before updating it
diff --git a/src/ui/tool/path-manipulator.h b/src/ui/tool/path-manipulator.h
index f15533021..cba029b68 100644
--- a/src/ui/tool/path-manipulator.h
+++ b/src/ui/tool/path-manipulator.h
@@ -106,11 +106,11 @@ private:
typedef boost::shared_ptr<NodeList> SubpathPtr;
void _createControlPointsFromGeometry();
- bool isBSpline(bool recalculate = true);
- double BSplineHandlePosition(Handle *h);
- Geom::Point BSplineHandleReposition(Handle *h);
- Geom::Point BSplineHandleReposition(Handle *h,double pos);
- void BSplineNodeHandlesReposition(Node *n);
+
+ bool isBSpline(bool recalculate = false);
+ double BSplineHandlePosition(Handle *h, bool other = false);
+ Geom::Point BSplineHandleReposition(Handle *h, bool other = false);
+ Geom::Point BSplineHandleReposition(Handle *h, double pos);
void _createGeometryFromControlPoints(bool alert_LPE = false);
unsigned _deleteStretch(NodeList::iterator first, NodeList::iterator last, bool keep_shape);
std::string _createTypeString();