コード例 #1
0
ファイル: ConnectionParts_Method.cpp プロジェクト: SEDS/GAME
//
// 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);


}
コード例 #2
0
//
// handle_object_created
//
int AMI4CCM_Event_Handler::handle_object_created (GAME::Mga::Object_in obj)
{
  if (!this->is_importing_)
    return 0;

  GAME::Mga::Model model = GAME::Mga::Model::_narrow (obj);
  GAME::Mga::Attribute attr = model->attribute ("SupportsAsync");
  bool supports_async = attr->bool_value ();

  return supports_async ? this->instantiate_connector (obj) : 0;
}
コード例 #3
0
//
// handle_object_attribute
//
int AMI4CCM_Event_Handler::handle_object_attribute (GAME::Mga::Object_in obj)
{
  if (this->is_importing_)
    return 0;

  // Get the support async attribute for the interface.
  GAME::Mga::Model model = GAME::Mga::Model::_narrow (obj);
  GAME::Mga::Attribute attr = model->attribute ("SupportsAsync");

  if (attr->has_changed () && attr->bool_value ())
    return this->instantiate_connector (obj);

  return 0;
}
コード例 #4
0
//
// create
//
BOOL PICML_Enum_Data_Value_Control::
Create (DWORD style, const RECT & rect, CWnd * parent, UINT id)
{
  // Calculate the size of the control to compensate the list.
  LOGFONT logfont;
  parent->GetFont ()->GetLogFont (&logfont);
  size_t font_height = abs (logfont.lfHeight);

  CRect combo_rect (rect.left,
                    rect.top,
                    rect.right,
                    rect.bottom + font_height * 5);

  // Update the style.
  style |= CBS_DROPDOWNLIST | CBS_SORT;

  if (PICML_Simple_Data_Value_Control <CComboBox>::Create (style, combo_rect, parent, id) == FALSE)
    return FALSE;

  // Populate the control with the enumeration values.
  GAME::Mga::Reference ref = GAME::Mga::Reference::_narrow (this->value_);
  GAME::Mga::Model e = GAME::Mga::Model::_narrow (ref->refers_to ());
  std::vector <GAME::Mga::Atom> values;

  if (e->children ("EnumValue", values))
    std::for_each (values.begin (),
                   values.end (),
                   boost::bind (&PICML_Enum_Data_Value_Control::visit_enum_value,
                                this,
                                _1));

  // Select the current value.
  const std::string selection =
    this->value_->attribute (attr::Value)->string_value ();

  if (!selection.empty ())
    this->SelectString (-1, selection.c_str ());

  return TRUE;
}
コード例 #5
0
ファイル: Lesser_Expr.cpp プロジェクト: SEDS/GAME
//
// list delete
//
bool Lesser_Expr::list_delete (GAME::Mga::Model & obj, 
                               size_t count, 
                               GAME::Mga::Meta::FCO & metatype, 
                               GAME::Mga::Meta::Role & metarole)
{
    std::vector <GAME::Mga::FCO> elements;
  GAME::Mga::FCO select;
  obj->children (elements);

   std::vector <GAME::Mga::FCO> qual_fcos;

  std::vector <GAME::Mga::FCO>::iterator
    it = elements.begin (), it_end = elements.end ();

  for (; it != it_end; ++it)
  {
    if ((*it)->meta ()->name () == metatype->name ())
      qual_fcos.push_back ((*it));
  }

  for (size_t i = 0; i < count; ++i)
  {
    AFX_MANAGE_STATE (::AfxGetStaticModuleState ());
    // Create the dialog and pass in the data
    using GAME::Dialogs::Selection_List_Dialog_T;
    Selection_List_Dialog_T <GAME::Mga::FCO> dlg (0, ::AfxGetMainWnd (), 0);
    dlg.title ("Please select the Model/Atom for deletion");
    dlg.directions ("Target evaluator");
    dlg.insert (qual_fcos);

    if (IDOK != dlg.DoModal ())
      return false;

    select = dlg.selection ();

    if (!select.is_nil ())
    {
      select->destroy ();
    }
  }
  return true;
}
コード例 #6
0
//
// 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;
}
コード例 #7
0
//
// instantiate_connector
//
int AMI4CCM_Event_Handler::instantiate_connector (GAME::Mga::Object_in obj)
{
  using GAME::Mga_t;

  // Generate the header file that will define the ami4ccm connector
  // for this interface. This file will be in the same folder and
  // location as this interface, but it will have 'A' appended to the
  // file name.
  const std::string name = obj->name ();
  GAME::Mga::Object file = obj->parent ();

  std::stack <GAME::Mga::Object> scope;
  static const std::string meta_File ("File");
  while (file->meta ()->name () != meta_File)
  {
    // Save the current scope for later usage.
    scope.push (file);
    file = file->parent ();
  }

  GAME::Mga::Model connector_file;
  const std::string connector_filename = file->name () + "A";
  GAME::Mga::Folder idl_folder = GAME::Mga::Folder::_narrow (file->parent ());

  if (GAME::create_if_not <Mga_t> (idl_folder, "File", connector_file,
      GAME::contains <Mga_t> (boost::bind (std::equal_to <std::string> (),
                              connector_filename,
                              boost::bind (&GAME::Mga::Model::impl_type::name,
                                           boost::bind (&GAME::Mga::Model::get, _1))))))
  {
    connector_file->name (connector_filename);
  }

  // Make sure the location (or path) are the same.
  GAME::Mga::Model model = GAME::Mga::Model::_narrow (file);
  const std::string location = model->attribute ("Path")->string_value ();
  connector_file->attribute ("Path")->string_value (location);

  // Reconstruct the scope for the connector in the newly
  // created file.
  while (!scope.empty ())
  {
    // Get the next element in the scope.
    const std::string package_name (scope.top ()->name ());

    // Make sure the package exists in the model.
    if (GAME::create_if_not <Mga_t> (connector_file, "Package", connector_file,
        GAME::contains <Mga_t> (boost::bind (std::equal_to <std::string> (),
                                package_name,
                                boost::bind (&GAME::Mga::Model::impl_type::name,
                                             boost::bind (&GAME::Mga::Model::get, _1))))))
    {
      connector_file->name (package_name);
    }

    // Remove the top element on the stack.
    scope.pop ();
  }

  // Create the standard ami4ccm interface.
  const std::string ami4ccm_interface_name = "AMI4CCM_" + name;
  const std::string ami4ccm_replyhandler_name = "AMI4CCM_" + name + "ReplyHandler";

  GAME::Mga::Model ami4ccm_interface;
  if (GAME::create_if_not <Mga_t> (connector_file, "Object", ami4ccm_interface,
      GAME::contains <Mga_t> (boost::bind (std::equal_to <std::string> (),
                              ami4ccm_interface_name,
                              boost::bind (&GAME::Mga::Model::impl_type::name,
                                           boost::bind (&GAME::Mga::Model::get, _1))))))
  {
    ami4ccm_interface->name (ami4ccm_interface_name);
  }

  ami4ccm_interface->attribute ("InterfaceSemantics")->string_value ("local");

  // Create the standard ami4ccm replyhandler interface.
  GAME::Mga::Model ami4ccm_replyhandler;
  if (GAME::create_if_not <Mga_t> (connector_file, "Object", ami4ccm_replyhandler,
      GAME::contains <Mga_t> (boost::bind (std::equal_to <std::string> (),
                              ami4ccm_replyhandler_name,
                              boost::bind (&GAME::Mga::Model::impl_type::name,
                                           boost::bind (&GAME::Mga::Model::get, _1))))))
  {
    ami4ccm_replyhandler->name (ami4ccm_replyhandler_name);
  }

  ami4ccm_replyhandler->attribute ("InterfaceSemantics")->string_value ("local");

  // Locate the ami4ccm connector element. There is a chance that more than
  // one may be returned. In that case, we need to locate the first one that
  // is from the ami4ccm library.
  GAME::Mga::Filter search (obj->project ());
  search.kind ("ConnectorObject");
  search.name ("AMI4CCM_Connector");

  std::vector <GAME::Mga::FCO> results;

  if (0 == search.apply (results))
  {
    AFX_MANAGE_STATE (::AfxGetStaticModuleState ());

    ::AfxMessageBox ("AMI4CCM_Connector connector not found. Please attach the "
                     "ami4ccm library and try again.",
                     MB_ICONWARNING);

    return 0;
  }

  std::vector <GAME::Mga::FCO>::const_iterator iter =
    std::find_if (results.begin (),
                  results.end (),
                  is_ami4ccm_template_connector ());

  if (iter == results.end ())
  {
    AFX_MANAGE_STATE (::AfxGetStaticModuleState ());

    ::AfxMessageBox ("AMI4CCM_Connector connector not found. Please attach the "
                     "ami4ccm library and try again.",
                     MB_ICONWARNING);

    return 0;
  }

  // Create the template package instance for the connector.
  GAME::Mga::Model tpi;

  GAME::Mga::Model connector_object = GAME::Mga::Model::_narrow (*iter);
  const std::string tpi_name = "AMI4CCM_" + name + "_Connector";

  if (GAME::create_if_not <Mga_t> (connector_file, "TemplatePackageInstance", tpi,
      GAME::contains <Mga_t> (boost::bind (std::equal_to <std::string> (),
                              tpi_name,
                              boost::bind (&GAME::Mga::Model::impl_type::name,
                                           boost::bind (&GAME::Mga::Model::get, _1))))))
  {
    tpi->name (tpi_name);
  }

  // Insert the parameters into the template. First, we must define
  // the package type for the template package instance.
  GAME::Mga::Model template_package = GAME::Mga::Model::_narrow (connector_object->parent ());

  GAME::Mga::Reference package_type;
  if (GAME::create_if_not <Mga_t> (tpi, "PackageType", package_type,
      GAME::contains <Mga_t> (boost::bind (std::equal_to <GAME::Mga::FCO> (),
                              template_package,
                              boost::bind (&GAME::Mga::Reference::impl_type::refers_to,
                                           boost::bind (&GAME::Mga::Reference::get, _1))))))
  {
    package_type->refers_to (template_package);
  }

  GAME::Mga::Point pt (50, 50);
  GAME::Mga::set_position ("TemplateParameters", pt, package_type);

  // Create the template parameter value for interface.
  GAME::Mga::Reference tpv_interface;
  model = GAME::Mga::Model::_narrow (obj);

  if (GAME::create_if_not <Mga_t> (tpi, "TemplateParameterValue", tpv_interface,
      GAME::contains <Mga_t> (boost::bind (std::equal_to <GAME::Mga::FCO> (),
                              model,
                              boost::bind (&GAME::Mga::Reference::impl_type::refers_to,
                                           boost::bind (&GAME::Mga::Reference::get, _1 ))))))
  {
    tpv_interface->refers_to (model);
  }

  pt.shift (100, 0);
  GAME::Mga::set_position ("TemplateParameters", pt, tpv_interface);

  // Create the template parameter value for the reply handler.
  GAME::Mga::Reference ami4ccm_param;

  if (GAME::create_if_not <Mga_t> (tpi, "TemplateParameterValue", ami4ccm_param,
      GAME::contains <Mga_t> (boost::bind (std::equal_to <GAME::Mga::FCO> (),
                              ami4ccm_replyhandler,
                              boost::bind (&GAME::Mga::Reference::impl_type::refers_to,
                                           boost::bind (&GAME::Mga::Reference::get, _1))))))
  {
    ami4ccm_param->refers_to (ami4ccm_interface);
  }

  pt.shift (100, 0);
  GAME::Mga::set_position ("TemplateParameters", pt, ami4ccm_param);

  return 0;
}
コード例 #8
0
 bool operator () (const GAME::Mga::FCO & fco) const
 {
   GAME::Mga::Model parent = fco->parent ();
   return parent->name () == "Connector_T";
 }