Archive for Smart linking of tangents

Looking for a way to modify “Link” action

K, lets proceed to the next stage – find a way to insert additional converts in special cases at the moment of invoking “Link” command.

Read the rest of this entry »

Advertisements

Leave a Comment

Reverse manipulations for Scale Convert – Part 3

Right after the CanvasView::on_duck_changed() function I have found CanvasView::on_duck_angle_changed() function. Looks like Angle ducks defining rotation are handled exclusively. Why? Let’s examine it…

Read the rest of this entry »

Leave a Comment

Reverse manipulations for Scale Convert – Part 2

The solution came when I looked at the end of CanvasView::on_duck_changed() function:

bool
CanvasView::on_duck_changed(const synfig::Point &value,const synfigapp::ValueDesc& value_desc)
{
	//Handling other convert types (LinkToBline)
	if (ValueNode_BLineCalcWidth::Handle bline_width = ValueNode_BLineCalcWidth::Handle::cast_dynamic(value_desc.get_value_node()))
	{
		...
	}

	...

	//Handling Scale Convert
	if (ValueNode_Scale::Handle scale_value_node = ValueNode_Scale::Handle::cast_dynamic(value_desc.get_value_node()))
	{
		//Our code
		int scalar_index(scale_value_node->get_link_index_from_name("scalar"));
		Real scalar((*(scale_value_node->get_link(scalar_index)))(get_time()).get(Real()));
		if (scalar == 0.0)
		{
			return false;
		}
		else
		{
			int link_index(scale_value_node->get_link_index_from_name("link"));
			return canvas_interface()->change_value(synfigapp::ValueDesc(scale_value_node,link_index), value / scalar);
		}
	}

	//Interesting part:
	switch(value_desc.get_value_type())
	{
	case ValueBase::TYPE_REAL:
		return canvas_interface()->change_value(value_desc,value.mag());
	case ValueBase::TYPE_ANGLE:
		return canvas_interface()->change_value(value_desc,Angle::tan(value[1],value[0]));
	default:
		return canvas_interface()->change_value(value_desc,value);
	}
}

Last lines of CanvasView::on_duck_changed() processing the case when the duck is not affected by any convert type – just passing value to the value_desc. Value variable is a Vector type, because it resides on the 2D plane – screen. But changed value node is not always a vector. It could be an Angle or Radius. For those cases value is converted to angle via Angle::tan() and value.mag() functions. “Mag” stays for “magnitude” for sure.

Read the rest of this entry »

Leave a Comment

Reverse manipulations for Scale Convert – Part 1

I’ve got first result. The patch below allows reverse manipulations for Scale convert type.

diff --git a/synfig-studio/trunk/src/gtkmm/canvasview.cpp b/synfig-studio/trunk/src/gtkmm/canvasview.cpp
index 3154ae4..6a8e4cb 100644
--- a/synfig-studio/trunk/src/gtkmm/canvasview.cpp
+++ b/synfig-studio/trunk/src/gtkmm/canvasview.cpp
@@ -2684,6 +2684,21 @@ CanvasView::on_duck_changed(const synfig::Point &value,const synfigapp::ValueDes
}
}

+    if (ValueNode_Scale::Handle scale_value_node = ValueNode_Scale::Handle::cast_dynamic(value_desc.get_value_node()))
+    {
+        int scalar_index(scale_value_node->get_link_index_from_name("scalar"));
+        Real scalar((*(scale_value_node->get_link(scalar_index)))(get_time()).get(Real()));
+        if (scalar == 0.0)
+        {
+            return false;
+        }
+        else
+        {
+            int link_index(scale_value_node->get_link_index_from_name("link"));
+            return canvas_interface()->change_value(synfigapp::ValueDesc(scale_value_node,link_index), value / scalar);
+        }
+    }
+
switch(value_desc.get_value_type())
{
case ValueBase::TYPE_REAL:
diff --git a/synfig-studio/trunk/src/synfigapp/instance.cpp b/synfig-studio/trunk/src/synfigapp/instance.cpp
index 020d337..c3c542b 100644
--- a/synfig-studio/trunk/src/synfigapp/instance.cpp
+++ b/synfig-studio/trunk/src/synfigapp/instance.cpp
@@ -42,6 +42,7 @@
#include <synfig /valuenode_blinecalctangent.h>
#include </synfig><synfig /valuenode_blinecalcvertex.h>
#include </synfig><synfig /valuenode_blinecalcwidth.h>
+#include </synfig><synfig /valuenode_scale.h>
#include <map>

#include "general.h"
@@ -74,6 +75,7 @@ synfigapp::is_editable(synfig::ValueNode::Handle value_node)
         || ValueNode_BLineCalcVertex::Handle::cast_dynamic(value_node)
         || ValueNode_BLineCalcTangent::Handle::cast_dynamic(value_node)
         || ValueNode_BLineCalcWidth::Handle::cast_dynamic(value_node)
+        || ValueNode_Scale::Handle::cast_dynamic(value_node)
)
return true;
return false;

I’ll try to explain some parts of code above. But first want to remind you again what I have no knowledge of C/C++. Be prepared to see some nonsense mumbling here and there. 🙂

Ready? K, here we go.

Read the rest of this entry »

Comments (2)

First task

Ok, the first target: smart tangents linking. Generally it is pita to link red tangent to yellow. You should use scale(-1) convert to achieve that. The goal is to make this handled with grace.

I found what even if I implement that, converting tangent to Scale makes it unmoveable. There is no reverse manipulations supported for scale converts. So here’s my plan:

  1. Find a way to make scale convert support reverse manipulations.
  2. Find a way to insert additional converts in special cases at the moment of invoking “Link” command.
  3. Find a way to insert “Link inverse” menu item to context menu.

K, let’s start from the first item. I found no references to reverse manipulations inside of core/src/valuenode_scale.cpp. I’ve started to inspect commit 80031a8a28bb53f89ad750ec94a1b447b419d616.

It seems I will need to add

ValueNode_Scale::Handle::cast_dynamic(value_node)

to synfig-studio/trunk/src/synfigapp/instance.cpp.

Scale convert have two parameters. I need to set which one to change during reverse manipulation. Looks like a hint how to do that is here.

Comments (1)