Logo Search packages:      
Sourcecode: inkscape version File versions

static void sp_spiral_set ( SPObject object,
unsigned int  key,
const gchar *  value 
) [static]

Virtual set: change spiral object attribute.

Todo:
fixme: we should really collect updates

Todo:
FIXME: check that value looks like a (finite) number. Create a routine that uses strtod, and accepts a default value (if strtod finds an error). N.B. atof/sscanf/strtod consider "nan" and "inf" to be valid numbers.

Todo:
FIXME: We still need some bounds on arg, for numerical reasons. E.g., we don't want inf or NaN, nor near-infinite numbers. I'm inclined to take modulo 2*pi. If so, then change the knot editors, which use atan2 - revo*2*pi, which typically results in very negative arg.

Todo:
Have shared constants for the allowable bounds for attributes. There was a bug here where we used -1.0 as the minimum (which leads to NaN via, e.g., pow(-1.0, 0.5); see sp_spiral_get_xy for requirements.

Definition at line 188 of file sp-spiral.cpp.

References SPSpiral::arg, SPSpiral::cx, SPSpiral::cy, SPSpiral::exp, SPSpiral::rad, SPSpiral::revo, and SPSpiral::t0.

Referenced by sp_spiral_class_init().

{
      SPSpiral *spiral;
      SPShape  *shape;

      spiral = SP_SPIRAL (object);
      shape  = SP_SHAPE (object);

      /// \todo fixme: we should really collect updates
      switch (key) {
      case SP_ATTR_SODIPODI_CX:
            if (!sp_svg_length_read_computed_absolute (value, &spiral->cx)) {
                  spiral->cx = 0.0;
            }
            object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
            break;
      case SP_ATTR_SODIPODI_CY:
            if (!sp_svg_length_read_computed_absolute (value, &spiral->cy)) {
                  spiral->cy = 0.0;
            }
            object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
            break;
      case SP_ATTR_SODIPODI_EXPANSION:
            if (value) {
                  /** \todo
                         * FIXME: check that value looks like a (finite)
                         * number. Create a routine that uses strtod, and
                         * accepts a default value (if strtod finds an error).
                         * N.B. atof/sscanf/strtod consider "nan" and "inf"
                         * to be valid numbers.
                         */
                  spiral->exp = g_ascii_strtod (value, NULL);
                  spiral->exp = CLAMP (spiral->exp, 0.0, 1000.0);
            } else {
                  spiral->exp = 1.0;
            }
            object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
            break;
      case SP_ATTR_SODIPODI_REVOLUTION:
            if (value) {
                  spiral->revo = g_ascii_strtod (value, NULL);
                  spiral->revo = CLAMP (spiral->revo, 0.05, 1024.0);
            } else {
                  spiral->revo = 3.0;
            }
            object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
            break;
      case SP_ATTR_SODIPODI_RADIUS:
            if (!sp_svg_length_read_computed_absolute (value, &spiral->rad)) {
                  spiral->rad = MAX (spiral->rad, 0.001);
            }
            object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
            break;
      case SP_ATTR_SODIPODI_ARGUMENT:
            if (value) {
                  spiral->arg = g_ascii_strtod (value, NULL);
                  /** \todo
                         * FIXME: We still need some bounds on arg, for
                         * numerical reasons. E.g., we don't want inf or NaN,
                         * nor near-infinite numbers. I'm inclined to take
                         * modulo 2*pi.  If so, then change the knot editors,
                         * which use atan2 - revo*2*pi, which typically
                         * results in very negative arg.
                         */
            } else {
                  spiral->arg = 0.0;
            }
            object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
            break;
      case SP_ATTR_SODIPODI_T0:
            if (value) {
                  spiral->t0 = g_ascii_strtod (value, NULL);
                  spiral->t0 = CLAMP (spiral->t0, 0.0, 0.999);
                  /** \todo
                         * Have shared constants for the allowable bounds for
                         * attributes. There was a bug here where we used -1.0
                         * as the minimum (which leads to NaN via, e.g.,
                         * pow(-1.0, 0.5); see sp_spiral_get_xy for
                         * requirements.
                         */
            } else {
                  spiral->t0 = 0.0;
            }
            object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
            break;
      default:
            if (((SPObjectClass *) parent_class)->set)
                  ((SPObjectClass *) parent_class)->set (object, key, value);
            break;
      }
}


Generated by  Doxygen 1.6.0   Back to index