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

  const std::string no_op_message = "A MultiInputAction has already been created for all facet operations.";

  GAME::Mga::Connection connection = GAME::Mga::Connection::_narrow (obj);
  GAME::Mga::Reference facet = GAME::Mga::Reference::_narrow (connection->src ());
  GAME::Mga::FCO input_action = connection->dst ();
  GAME::Mga::Model object = GAME::Mga::Model::_narrow (facet->refers_to ());

  // Collect the operations on the Object
  std::vector <GAME::Mga::Object> operations;
  this->get_operations (object, operations);

  // Get all the other MultiInputActions connected to the facet
  std::vector <GAME::Mga::Object> existing_actions;
  this->get_actions (facet, existing_actions);

  // Remove existing actions from the operations
  std::vector <GAME::Mga::Object> targets;
  this->narrow_targets (operations, existing_actions, targets);

  // The name to use for the MultiInputAction
  std::string name;

  if (targets.size () == 0)
  {
    ::AfxMessageBox (no_op_message.c_str (), MB_ICONINFORMATION | MB_OK);
    return 0;
  }
  else if (targets.size () == 1)
    name = targets.front ()->name ();
  else
  {
    AFX_MANAGE_STATE (::AfxGetStaticModuleState ());

    using GAME::Dialogs::Selection_List_Dialog_T;
    Selection_List_Dialog_T <GAME::Mga::Object> dlg (0, ::AfxGetMainWnd ());

    dlg.title ("Target Operation");
    dlg.directions ("Select the target Operation for the MultiInputAction");
    dlg.insert (targets);

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

    name = dlg.selection ()->name ();
  }

  if (!name.empty())
    input_action->name (name);

  return 0;
}
コード例 #2
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;
}
コード例 #3
0
ファイル: Lesser_Expr.cpp プロジェクト: SEDS/GAME
//
// evaluate
//
bool Lesser_Expr::evaluate (Ocl_Context & res)
{
  // flag to decide the case
  size_t flag = 0;
  bool ret = false;

	if (res.model_constraint)
	{

		// Checking if the local variables are mutable/non-mutable
		if (this->lhs_->is_mutable () && !this->rhs_->is_mutable ())
			flag = 1;
		else if (!this->lhs_->is_mutable () && this->rhs_->is_mutable ())
			flag = 2;
		else if (this->lhs_->is_mutable () && this->rhs_->is_mutable ())
			flag = 3;

		switch (flag) {

			case 1:
				{
					if (this->lhs_->evaluate (res)->is_greater (this->rhs_->evaluate (res)))
					 {
						 // Counting the number of objects to be deleted
						 double count;
						 this->rhs_->evaluate (res)->get_diff (this->lhs_->evaluate (res), count);

						 // Calling the delete command
						 ret = true;
					 }
					break;
				}
			case 2:
				{
					if (this->lhs_->evaluate (res)->is_lesser (this->rhs_->evaluate (res)))
					{
						// Counting the number of objects to be deleted
						double count;
						this->lhs_->evaluate (res)->get_diff (this->rhs_->evaluate (res), count);

						// Calling the delete command
						ret = true;
					}
					break;
				}
			default:
				{
					//throw an exception
					ret = false;
				}
		}
	}
  else if (res.model_attributes)
  {
    // Assumption for now is that the attribute_expression is lhs and constant_value_expr
    // is rhs

    // Caller
    std::string obj = "";
    // Attribute name
    std::string name = "";


    // Performing the automated attribute value setting only if
    // the constraint contains attribute i.e. either lhs or rhs has attribute
    Attribute_Expr * left = dynamic_cast <Attribute_Expr *> (this->lhs_);
    Attribute_Expr * right = dynamic_cast <Attribute_Expr *> (this->rhs_);

    if (left != 0 || right != 0 )
    {
      if (left != 0)
      {
        name = left->attribute_name ();
        obj = left->caller ();
      }
      else
      {
        name = right->attribute_name ();
        obj = right->caller ();
      }

      GAME::Mga::FCO fco;

      // Checking the invoking object for the attribute
      if (obj == "self")
        fco = GAME::Mga::FCO::_narrow (res.self);
      else
      {
        // The object value associated with the local variable is taken from map
        // and is used for attribute value calculation
        Object_Value * iv = dynamic_cast <Object_Value *> (res.locals [obj]);
        fco = GAME::Mga::FCO::_narrow (iv->value ());
      }

      if (!this->lhs_->evaluate (res)->is_lesser (this->rhs_->evaluate (res)))
      {
        Expr_Command *cmd = new Attribute_Add_Command (fco, name, new Int_Value (0));

        //Pushing adding operation to the action list
        res.actions.push_back (cmd);
      }
      ret = true;
    }
    else
      ret = this->lhs_->evaluate (res)->is_lesser (this->rhs_->evaluate (res));
    
  }
  else if (res.checker)      // This section is used by Containment Check Handler only
  {
    // Checking if the local variables are mutable/non-mutable
		if (this->lhs_->is_mutable () && !this->rhs_->is_mutable ())
			flag = 1;
		else if (!this->lhs_->is_mutable () && this->rhs_->is_mutable ())
			flag = 2;
		else if (this->lhs_->is_mutable () && this->rhs_->is_mutable ())
			flag = 3;

    // Collecting the value and data of left hand side
    Value * v1 = this->lhs_->evaluate (res);
    Int_Value * iv = dynamic_cast <Int_Value * > (v1);
    int left_value = iv->value ();
    GAME::Mga::Meta::FCO left_metatype;
    GAME::Mga::Meta::Role left_metarole;
    if (flag == 1 || flag == 3)
    {
      left_metatype = res.target_metaroles[0]->kind ();
      left_metarole = res.target_metaroles[0];
    }

    if (flag == 3)
    {
      // Clearing the metaroles
      res.target_metaroles.clear ();
    }

    // Collecting the value and data of right hand side
    Value * v2 = this->rhs_->evaluate (res);
    Int_Value * iv2 = dynamic_cast <Int_Value * > (v2);
    int right_value = iv2->value ();
    GAME::Mga::Meta::FCO right_metatype;
    GAME::Mga::Meta::Role right_metarole;
    if (flag == 3 || flag == 2)
    {
      right_metatype = res.target_metaroles[0]->kind ();
      right_metarole = res.target_metaroles[0];
    }
    std::vector <std::string> options;
    double count;

    if (iv != 0 && iv2 != 0)
    {
      switch (flag) {
        case 1:
          {
            if (left_value >= right_value)
            {
             // This option is when the left side is greater than the constant right side 
             // Counting the number of objects to be deleted
						  double count = left_value - right_value;						
              ret = list_delete (res.model_object, count, left_metatype, left_metarole);
            }
            break;
          }
        case 2:
          {
            if (right_value <= left_value)
            {
              // This option is when the right side is greater than the constant left side 
              // Counting the number of objects to be deleted
						  double count = left_value - right_value;
              ret = list_add (res.model_object, count, right_metatype, right_metarole);
            }
            break;
          }
        case 3:
          {
            // This option is used when both sides are variable
            if (this->lhs_->evaluate (res)->is_equal (this->rhs_->evaluate (res)))
              ret = true;
            else if (left_value > right_value)
            {
              // Options for the modeler if the right side is greater than left side
              count = left_value - right_value;
              options.push_back ("Add " + right_metatype->name ());
              options.push_back ("Delete " + left_metatype->name ());
            }
            if (options.size () > 0)
            {
              std::string select;
              AFX_MANAGE_STATE (::AfxGetStaticModuleState ());

              // Create the dialog and pass in the data
              using GAME::Dialogs::Selection_List_Dialog_T;
              Selection_List_Dialog_T <std::string> dlg (0, ::AfxGetMainWnd (), 2);
              dlg.title ("Object Addition/Deletion Resolver");
              dlg.directions ("Select the desired action");
              dlg.string_insert (options);
              if (IDOK != dlg.DoModal ())
                return false;

              select = dlg.string_selection ();

              if (!select.empty ())
              {
                if (select == ("Add " + right_metatype->name ()))
                  ret = list_add (res.model_object, count, right_metatype, right_metarole);
                else if (select == ("Delete " + left_metatype->name ()))
                  ret = list_delete (res.model_object, count, left_metatype, left_metarole);
              }
            }
            break;
          }
        default:
          {
            ret = false;
          }
        }
      }
    
  }
	else
		ret = this->lhs_->evaluate (res)->is_lesser (this->rhs_->evaluate (res));

	return ret;
}