Esempio n. 1
0
//
// evaluate
//
Value * ConnectionParts_Method::evaluate (Ocl_Context &res, GAME::Mga::Object caller)
{
  GAME::Mga::Model mod = GAME::Mga::Model::_narrow (caller);

  std::vector <GAME::Mga::Connection> parts;
  std::vector <std::string> rolenames;
  bool flag = false;

  // Verifying if role_ is a valid containment role
  std::vector <GAME::Mga::Meta::Role> all;
  mod->meta ()->roles (all);
  std::vector <GAME::Mga::Meta::Role>::iterator
    it = all.begin (), ite = all.end ();

  for (; it != ite; ++it)
    rolenames.push_back ((*it)->name ());

  std::vector <std::string>::iterator
    st = rolenames.begin (), ste = rolenames.end ();

  for (; st != ste; ++st)
  {
    if ((*st) == this->role_)
      flag = true;
  }

  // Continue if the role is valid
  if (flag)
  {
    GAME::Mga::Meta::Role target_metarole = mod->meta ()->role (this->role_);

    // Setting the target metarole in the model intelligence context
    // only if it doesn't already exist in the list
    std::vector <GAME::Mga::Meta::Role>::iterator
      roleit = res.target_metaroles.begin (), roleit_end = res.target_metaroles.end ();

    bool exists = false;

    for (; roleit != roleit_end; ++ roleit)
    {
      if ((*roleit)->name () == target_metarole->name ())
        exists = true;
    }

    if (!exists)
      res.target_metaroles.push_back (target_metarole);
  
    GAME::Mga::Meta::FCO temp = target_metarole->kind ();

    // Collecting children only if the type of element is Connection
    if (temp->type () == OBJTYPE_CONNECTION)
      mod->children (temp->name (), parts);
  }

  return new Collection_Value_T <GAME::Mga::Connection> (parts);


}
//
// initialize_ports
//
int Component_Decorator_Impl::
initialize_ports (const std::string & aspect_name,
                  const GAME::Mga::FCO_in fco,
                  GAME::Mga::graphics::Image_Resolver * resolver)
{
  GAME::Mga::Model model = GAME::Mga::Model::_narrow (fco);
  GAME::Mga::Meta::Model metamodel = model->meta ();

  // Get the target aspect.
  GAME::Mga::Meta::Aspect aspect = metamodel->aspect (aspect_name);

  if (aspect.is_nil ())
    return 0;

  // Select all the FCO elements in the specified aspect.
  std::vector <GAME::Mga::FCO> ports;

  if (model->children (aspect, ports) == 0)
    return 0;

  std::vector <GAME::Mga::FCO>::iterator
    iter = ports.begin (), iter_end = ports.end ();

  GAME::Mga::Part part;
  std::string icon_filename, filename;
  Gdiplus::Image * image = 0;

  for (; iter != iter_end; ++ iter)
  {
    // First, let's determine if the element is indeed a port. If
    // it is not a port, let's just continue to the next iteration.
    part = (*iter)->part (aspect);

    if (!part.meta ()->is_linked ())
      continue;

    // Load the icon for the specified element.
    icon_filename = (*iter)->meta ()->registry_value ("icon");

    if (resolver->lookup_icon (icon_filename, filename))
      this->port_bitmaps_.associate_image (*iter, filename, image);

    // Determine what side of the model this port should
    // be displayed.
    long x, y;
    part.get_location (x, y);


    // Allocate a new port for the FCO.
    GAME::Mga::Point location (x, y);

    using GAME::Mga::Port_Decorator;
    Port_Decorator * port = new Port_Decorator (*iter,
                                                image,
                                                (*iter)->name (),
                                                location);

    if (x < 200)
    {
      this->l_ports_.push_back (port);
      port->alignment (Port_Decorator::ALIGNMENT_LEFT);
    }
    else
    {
      this->r_ports_.push_back (port);
      port->alignment (Port_Decorator::ALINGMENT_RIGHT);
    }
  }

  // We need to get all the ports that we inherit.
  std::vector <GAME::Mga::Reference> inherits;

  if (model->children ("ComponentInherits", inherits))
  {
    GAME::Mga::FCO refers_to = inherits.front ()->refers_to ();

    if (!refers_to.is_nil ())
      this->initialize_ports ("InterfaceDefinition", refers_to, resolver);
  }

  return 0;
}