Exemplo n.º 1
0
symbol
Block::expand_reference (const symbol key) const
{
  const Frame& key_frame = find_frame (key);
  daisy_assert (key_frame.is_reference (key));

  const symbol var = key_frame.get_reference (key);
  if (var == key)
    {
      error ("Value of '" + key + "' refers to itself");
      throw "Reference loop";
    }
  const Attribute::type var_type = lookup (var);
  const Attribute::type key_type = key_frame.lookup (key);
  if (var_type != key_type)
    {
      std::ostringstream tmp;
      tmp << "Value of '" << key << "' is $" << var
          << ", which is a " << Attribute::type_name (var_type)
          << ", should be " << Attribute::type_name (key_type);
      error (tmp.str ());
      throw "Reference type mismatch";
    }
  const int var_size = find_frame (var).type_size (var);
  const int key_size = key_frame.type_size (key);
  if (var_size != key_size
      && (key_size != Attribute::Variable
          || var_size == Attribute::Singleton))
      // Matching dimension.
    {
      std::ostringstream tmp;
      tmp << "Value of '" << key << "' is $" << var
          << ", a " << Attribute::size_name (var_size)
          << ", should be " << Attribute::size_name (key_size);
      error (tmp.str ());
      throw "Reference size mismatch";
    }

  if (var_type == Attribute::Number)
    {
      daisy_assert (key_type == Attribute::Number);
      
      const symbol var_dim = find_frame (var).dimension (var);
      const symbol key_dim = key_frame.dimension (key);

      if (var_dim != key_dim)
        {
          std::ostringstream tmp;
          tmp << "Value of '" << key << "' is $" << var
              << ", which is a " << var_dim << ", should be " << key_dim;
          error (tmp.str ());
          throw "Reference unit mismatch";
        }
    }
  return var;
}
Exemplo n.º 2
0
point
edit_graphics_rep::adjust (point p) {
  frame f= find_frame ();
  grid g= find_grid ();
  if (!is_nil (g) && !is_nil (gr0) &&
      (g != gr0 || p[0] != p_x || p[1] != p_y)) {
    graphical_select (p[0], p[1]);
    g= gr0;
    p[0]= p_x;
    p[1]= p_y;
  }
  if (is_nil (g)) return p;
  point res;
  gr_selections sels= copy (gs);
  frame f2= find_frame (true);
  if (is_nil (f2)) return p;
  point fp= f2 (p);
  if ((tree) g != "empty_grid") {
    point q= g->find_point_around (p, snap_distance, f);
    point fq= f2 (q);
    if (norm (fq - fp) < snap_distance) {
      gr_selection sel;
      sel->type= "grid-point";
      sel->p   = fq;
      sel->dist= (SI) norm (fq - fp);
      sels << sel;
    }
    array<grid_curve> gc=
      g->get_curves_around (p, snap_distance, f);
    for (int i=0; i<N(gc); i++) {
      point fc= closest (f2 (gc[i]->c), fp);
      if (norm (fc - fp) < snap_distance) {
        gr_selection sel;
        sel->type= "grid-curve-point";
        sel->p   = fc;
        sel->dist= (SI) norm (fc - fp);
        sel->c   = f2 (gc[i]->c);
        sels << sel;
      }
    }
  }
  double eps= get_pixel_size () / 10.0;
  gr_selection snap= snap_to_guide (fp, sels, eps);
  //cout << "Snap " << fp << " to " << snap << ", " << snap->p << "\n";
  point snapped= f2[snap->p];
  if (N(snapped) == 2) return snapped;
  return p;
  // FIXME: why can snapped be an invalid point?
}
Exemplo n.º 3
0
bool 
Block::flag (const symbol key) const
{ 
  const Frame& frame = find_frame (key);
  if (frame.is_reference (key))
    return flag (expand_reference (key));

  //Handle primitive flags.
  Attribute::type type = lookup (key);
  if (type != Attribute::Model)
    return frame.flag (key); 

  // Handle boolean objects.
  daisy_assert (type == Attribute::Model);
  daisy_assert (frame.component (key) == Boolean::component);
  daisy_assert (frame.check (*this));
  std::unique_ptr<Boolean> boolean (Librarian::build_frame<Boolean> 
                                (*this, frame.model (key), key));
  daisy_assert (boolean.get ());
  daisy_assert (boolean->initialize (units (), *this, msg ()));
  daisy_assert (boolean->check (units (), *this, msg ()));
  boolean->tick (units (), *this, msg ());
  daisy_assert (!boolean->missing (*this));
  return boolean->value (*this);
}
Exemplo n.º 4
0
symbol
Block::name (const symbol key) const
{ 
  const Frame& frame = find_frame (key);
  if (frame.is_reference (key))
    return name (expand_reference (key));

  //Handle primitive names.
  Attribute::type type = lookup (key);
  if (type != Attribute::Model)
    return expand_string (frame.name (key)); 

  // Handle stringer objects.
  daisy_assert (type == Attribute::Model);
  daisy_assert (frame.component (key) == Stringer::component);
  daisy_assert (frame.check (*this));
  std::unique_ptr<Stringer> stringer (Librarian::build_frame<Stringer> 
                                (*this, frame.model (key), key));
  daisy_assert (stringer.get ());
  daisy_assert (stringer->initialize (units (), *this, msg ()));
  daisy_assert (stringer->check (units (), *this, msg ()));
  stringer->tick (units (), *this, msg ());
  daisy_assert (!stringer->missing (*this));
  return symbol (stringer->value (*this));
}
Exemplo n.º 5
0
void
edit_graphics_rep::set_graphical_object (tree t) {
  go_box= box ();
  graphical_object= t;
  if (N (graphical_object) == 0) return;
  edit_env env= get_typesetter ()->env;
  //tree old_fr= env->local_begin (GR_FRAME, (tree) find_frame ());  
  frame f_env= env->fr;
  env->fr= find_frame ();
  if (!is_nil (env->fr)) {
    int i,n=0;
    go_box= typeset_as_concat (env, t, path (0));
    for (i=0; i<N(go_box); i++)
      if (go_box[i]!="") n++;
    if (n) {
      array<box> bx(n);
      n=0;
      for (i=0; i<N(go_box); i++) if (go_box[i]!="") {
	array<box> bx2(1);
	array<SI> spc2(1);
	bx2[0]= go_box[i];
	spc2[0]=0;
	bx[n]= concat_box (path (0), bx2, spc2);
	n++;
      }
      go_box= composite_box (path (0), bx);
    }
  }
  env->fr= f_env;
  //env->local_end (GR_FRAME, old_fr);
}
Exemplo n.º 6
0
void add_signal(struct frame_struct *db, int frameId, char *signalName, int startBit, int signalLength, int is_big_endian, int signedState, float factor, float offset, float min, float max, char *unit, char *receiverList, unsigned char isMultiplexer, unsigned char muxId)
{
	struct frame_struct *frame;
	struct signal_struct *newSignal;

	frame = find_frame(db, frameId);
	
	newSignal = malloc(sizeof(struct signal_struct));
	strcpy(newSignal->name, signalName);
	newSignal->startBit = startBit;
	newSignal->signalLength = signalLength;
	newSignal->is_big_endian = is_big_endian;
	newSignal->is_signed = signedState;
	newSignal->factor = factor;
	newSignal->offset = offset;
	newSignal->min = min;
	newSignal->max = max;
        
        
        if(isMultiplexer > 0)
        {
            frame->isMultiplexed = 1;
        }
        newSignal->isMultiplexer = isMultiplexer;
        newSignal->muxId = muxId;
	
	strcpy(newSignal->unit, unit);
	strcpy(newSignal->receiverList, receiverList);

	HASH_ADD_STR( frame->signals, name, newSignal );
}
Exemplo n.º 7
0
tree
edit_graphics_rep::graphical_select (double x, double y) { 
  frame f= find_frame ();
  if (is_nil (f)) return tuple ();
  gr_selections sels;
  point p0 = point (x, y);
  point p = f (p0);
  sels= eb->graphical_select ((SI)p[0], (SI)p[1], 10*get_pixel_size ());
  gs= sels;
  pts= array<point> (0);
  ci= array<point> (0);
  cgi= array<point> (0);
  gr0= empty_grid ();
  grid g= find_grid ();
  frame f2= find_frame (true);
  if (!is_nil (g) && !is_nil (f2)) {
    gr0= g;
    p = f2 (point (x, y));
    int i, j, n= N(sels);
    for (i=0; i<n; i++) {
      array<point> pts2= sels[i]->pts;
      if (N(pts2)>0 && norm (pts2[0] - p) <= 10*get_pixel_size ())
	pts= pts << pts2[0];
      if (N(pts2)>1 && norm (pts2[1] - p) <= 10*get_pixel_size ())
	pts= pts << pts2[1];
    }
    double eps= get_pixel_size () / 10.0;
    for (i=0; i<n; i++) {
      for (j=0; j<n; j++)
        if (i<j) {
	  curve c1= sels[i]->c;
	  curve c2= sels[j]->c;
	  if (!is_nil (c1) && !is_nil (c2))
	    ci= ci << intersection (c1, c2, p, eps);
        }
    }
    array<grid_curve> gc= g->get_curves_around (p0, 10*get_pixel_size (), f);
    //FIXME: Too slow
    for (i=0; i<N(gc); i++) {
      curve c= f2 (gc[i]->c);
      for (j=0; j<n; j++)
	if (!is_nil (sels[j]->c))
	  cgi= cgi << intersection (c, sels[j]->c, p, eps);
    }
  }
  return as_tree (sels);
}
Exemplo n.º 8
0
int 
Block::integer (const symbol key) const
{ 
  const Frame& frame = find_frame (key);
  if (frame.is_reference (key))
    return integer (expand_reference (key));

  return frame.integer (key); 
}
Exemplo n.º 9
0
boost::shared_ptr<const FrameSubmodel>
Block::submodel_ptr (const symbol key) const
{ 
  const Frame& frame = find_frame (key);
  if (frame.is_reference (key))
    return submodel_ptr (expand_reference (key));

  return frame.submodel_ptr (key); 
}
Exemplo n.º 10
0
boost::shared_ptr<const PLF>
Block::plf_ptr (const symbol key) const
{ 
  const Frame& frame = find_frame (key);
  if (frame.is_reference (key))
    return plf_ptr (expand_reference (key));

  return frame.plf_ptr (key); 
}
Exemplo n.º 11
0
bool 
Block::flag (const symbol key, bool default_value) const
{ 
  const Frame& frame = find_frame (key);
  if (frame.is_reference (key))
    return flag (expand_reference (key), default_value);

  return frame.flag (key, default_value); 
}
Exemplo n.º 12
0
symbol
Block::name (const symbol key, const symbol default_value) const
{ 
  const Frame& frame = find_frame (key);
  if (frame.is_reference (key))
    return name (expand_reference (key), default_value);

  return expand_string (frame.name (key, default_value)); 
}
Exemplo n.º 13
0
double 
Block::number (const symbol key, double default_value) const
{ 
  const Frame& frame = find_frame (key);
  if (frame.is_reference (key))
    return number (expand_reference (key), default_value);

  return frame.number (key, default_value); 
}
Exemplo n.º 14
0
int 
Block::integer (const symbol key, int default_value) const
{ 
  const Frame& frame = find_frame (key);
  if (frame.is_reference (key))
    return integer (expand_reference (key), default_value);

  return frame.integer (key, default_value); 
}
Exemplo n.º 15
0
const std::vector<double>& 
Block::number_sequence (const symbol key) const
{ 
  const Frame& frame = find_frame (key);
  if (frame.is_reference (key))
    return number_sequence (expand_reference (key));

  return frame.number_sequence (key); 
}
Exemplo n.º 16
0
const std::vector<boost::shared_ptr<const PLF>/**/>& 
Block::plf_sequence (const symbol key) const
{ 
  const Frame& frame = find_frame (key);
  if (frame.is_reference (key))
    return plf_sequence (expand_reference (key));

  return frame.plf_sequence (key); 
}
Exemplo n.º 17
0
const std::vector<int>& 
Block::integer_sequence (const symbol key) const
{ 
  const Frame& frame = find_frame (key);
  if (frame.is_reference (key))
    return integer_sequence (expand_reference (key));

  return frame.integer_sequence (key); 
}
Exemplo n.º 18
0
const std::vector<bool>& 
Block::flag_sequence (const symbol key) const
{ 
  const Frame& frame = find_frame (key);
  if (frame.is_reference (key))
    return flag_sequence (expand_reference (key));

  return frame.flag_sequence (key); 
}
Exemplo n.º 19
0
value_t* get_binding( const frame_t* f, const int frameindex, const int varindex )
{
  frame_t* correctframe = find_frame( f, frameindex );

  if ( varindex < 0 && varindex >= sizeof( correctframe->values ) ) {
    fatal_error( "binding not found in frame" );
  }

  return correctframe->values[varindex];
}
Exemplo n.º 20
0
void set_binding( frame_t* f, const int frameindex, const int varindex, value_t* value )
{
  frame_t* correctframe = find_frame( f, frameindex );

  if ( varindex < 0 && varindex >= sizeof( correctframe->values ) ) {
    fatal_error( "binding not found in frame" );
  }

  correctframe->values[varindex] = value;
}
Exemplo n.º 21
0
tree
edit_graphics_rep::graphical_select (
  double x1, double y1, double x2, double y2)
{ 
  frame f= find_frame ();
  if (is_nil (f)) return tuple ();
  gr_selections sels;
  point p1 = f (point (x1, y1)), p2= f (point (x2, y2));
  sels= eb->graphical_select ((SI)p1[0], (SI)p1[1], (SI)p2[0], (SI)p2[1]);
  return as_tree (sels);
}
Exemplo n.º 22
0
bool
edit_graphics_rep::find_graphical_region (SI& x1, SI& y1, SI& x2, SI& y2) {
  point lim1, lim2;
  find_limits (lim1, lim2);
  if (lim1 == point ()) return false;
  frame f= find_frame ();
  if (is_nil (f)) return false;
  point p1= f (point (lim1[0], lim1[1]));
  point p2= f (point (lim2[0], lim2[1]));
  x1= (SI) p1[0]; y1= (SI) p1[1];
  x2= (SI) p2[0]; y2= (SI) p2[1];
  return true;
}
Exemplo n.º 23
0
const std::vector<symbol>
Block::name_sequence (const symbol key) const
{ 
  const Frame& frame = find_frame (key);
  if (frame.is_reference (key))
    return name_sequence (expand_reference (key));

  const std::vector<symbol>& value = frame.name_sequence (key);
  std::vector<symbol> result;
  for (size_t i = 0; i < value.size (); i++)
    result.push_back (expand_string (value[i]));
  return result;
}
Exemplo n.º 24
0
bool
edit_graphics_rep::mouse_graphics (string type, SI x, SI y, int m, time_t t) {
  //cout << type << ", " << x << ", " << y << ", " << m << ", " << t << "\n";
  //cout << "et= " << et << "\n";
  //cout << "tp= " << tp << "\n";
  //cout << "gp= " << graphics_path () << "\n";
  (void) t;
  // apply_changes (); // FIXME: remove after review of synchronization
  frame f= find_frame ();
  if (!is_nil (f)) {
    if (!over_graphics (x, y))
      return false;
    if (type == "move" || type == "dragging-left")
      if (check_event (MOTION_EVENT))
	return true;
    point p = f [point (x, y)];
    graphical_select (p[0], p[1]); // init the caching for adjust().
    p= adjust (p);
    gr_x= p[0];
    gr_y= p[1];
    string sx= as_string (p[0]);
    string sy= as_string (p[1]);
    invalidate_graphical_object ();
    call ("set-keyboard-modifiers", object (m));
    if (type == "move")
      call ("graphics-move", sx, sy);
    else if (type == "release-left" || type == "double-left")
      call ("graphics-release-left", sx, sy);
    else if (type == "release-middle")
      call ("graphics-release-middle", sx, sy);
    else if (type == "release-right" || type == "double-right")
      call ("graphics-release-right", sx, sy);
    else if (type == "start-drag-left")
      call ("graphics-start-drag-left", sx, sy);
    else if (type == "dragging-left")
      call ("graphics-dragging-left", sx, sy);
    else if (type == "end-drag-left")
      call ("graphics-end-drag-left", sx, sy);
    else if (type == "start-drag-right")
      call ("graphics-start-drag-right", sx, sy);
    else if (type == "dragging-right")
      call ("graphics-dragging-right", sx, sy);
    else if (type == "end-drag-right")
      call ("graphics-end-drag-right", sx, sy);
    invalidate_graphical_object ();
    notify_change (THE_CURSOR);
    return true;
  }
  //cout << "No frame " << tp << ", " << subtree (et, path_up (tp)) << "\n";
  return false;
}
Exemplo n.º 25
0
bool
edit_graphics_rep::over_graphics (SI x, SI y) {
  frame f= find_frame ();
  if (!is_nil (f)) {
    point lim1, lim2;
    find_limits (lim1, lim2);
    point p = adjust (f [point (x, y)]);
    // cout << type << " at " << p << " [" << lim1 << ", " << lim2 << "]\n";
    if (N(lim1) == 2)
      if ((p[0]<lim1[0]) || (p[0]>lim2[0]) || (p[1]<lim1[1]) || (p[1]>lim2[1]))
	return false;
    return true;
  }
  return false;
}
Exemplo n.º 26
0
tree
edit_graphics_rep::graphical_select (double x, double y) { 
  frame f= find_frame ();
  if (is_nil (f)) return tuple ();
  gr_selections pre_sels, sels;
  point p0 = point (x, y);
  point p = f (p0);
  pre_sels= eb->graphical_select ((SI)p[0], (SI)p[1], snap_distance);
  for (int i=0; i<N(pre_sels); i++)
    if (admissible_selection (pre_sels[i]))
      sels << pre_sels[i];
  //for (int i=0; i<N(sels); i++)
  //  cout << i << ":\t" << sels[i] << "\n";
  gs= sels;
  gr0= empty_grid ();
  grid g= find_grid ();
  frame f2= find_frame (true);
  if (!is_nil (g) && !is_nil (f2)) {
    gr0= g;
    p_x= x;
    p_y= y;
  }
  return as_tree (sels);
}
Exemplo n.º 27
0
bool
edit_graphics_rep::mouse_graphics (string type, SI x, SI y, int m, time_t t) {
  (void) t;
  // apply_changes (); // FIXME: remove after review of synchronization
  frame f= find_frame ();
  if (!is_nil (f)) {
    if (!over_graphics (x, y)) return false;
    if (type == "move" || type == "dragging")
      if (check_event (MOTION_EVENT))
	return true;
    point p = f [point (x, y)];
    graphical_select (p[0], p[1]); // init the caching for adjust().
    p = adjust (p);
    gr_x= p[0];
    gr_y= p[1];
    string sx= as_string (p[0]);
    string sy= as_string (p[1]);
    invalidate_graphical_object ();
    call ("set-keyboard-modifiers", object (m));
    if (type == "move")
      call ("graphics-move-point", sx, sy);
    else if (type == "release-left")
      call ("graphics-insert-point", sx, sy);
    else if (type == "release-middle")
      call ("graphics-remove-point", sx, sy);
    else if (type == "release-right")
      call ("graphics-last-point", sx, sy);
    else if (type == "start-drag")
      call ("graphics-start-drag", sx, sy);
    else if (type == "dragging")
      call ("graphics-dragging", sx, sy);
    else if (type == "end-drag")
      call ("graphics-end-drag", sx, sy);
    else if (type == "start-right-drag")
      call ("graphics-start-right-drag", sx, sy);
    else if (type == "right-dragging")
      call ("graphics-right-dragging", sx, sy);
    else if (type == "end-right-drag")
      call ("graphics-end-right-drag", sx, sy);
    invalidate_graphical_object ();
    notify_change (THE_CURSOR);
    return true;
  }
  return false;
}
Exemplo n.º 28
0
	std::string operator[] (const char* name ) const
	{
		std::string ret;

		field f = m_remap[ name ];
		if( !f.mapped )
			throw bad_ident();
		if (m_header->version_major>3 && !strcmp(name, "YEAR"))
			f=field("TDRC", text);

		if( const id3v2_frame* frame = find_frame( f.mapped ) )
		{
			if( f.pfn )
				ret = f.pfn( frame, m_header, !!g_utf8 );

			if( !ret.empty() )
				return ret;
		}

		return "";
	}
Exemplo n.º 29
0
bool 
Block::check (const symbol key) const
{
  const Frame& frame = find_frame (key);

  if (frame.lookup (key) == Attribute::Error)
    // Why are we asking?  No such attribute is defined.
    return false;

  if (!frame.is_reference (key))
    // Just a normal attribute.
    return frame.check (key);

  // A reference.
  const symbol var = frame.get_reference (key);
  if (key == var)
    {
      error ("Self reference: '" + key + "'");
      return false;
    }
  
  // Try expanded version.
  return this->check (var);
}
Exemplo n.º 30
0
double 
Block::number (const symbol key) const
{ 
  const Frame& frame = find_frame (key);
  if (frame.is_reference (key))
    return number (expand_reference (key));

  Attribute::type type = lookup (key);
  if (type != Attribute::Model)
    return frame.number (key);

  // Handle number objects.
  daisy_assert (type == Attribute::Model);
  daisy_assert (frame.component (key) == Number::component);
  daisy_assert (frame.check (*this));
  std::unique_ptr<Number> number (Librarian::build_frame<Number> 
                                (*this, frame.model (key), key));
  daisy_assert (number.get ());
  daisy_assert (number->initialize (units (), *this, msg ()));
  daisy_assert (number->check (units (), *this, msg ()));
  number->tick (units (), *this, msg ());
  daisy_assert (!number->missing (*this));
  return number->value (*this);
}