int iupClassObjectSetAttributeId(Ihandle* ih, const char* name, int id, const char * value)
{
  IattribFunc* afunc;

  if (ih->iclass->has_attrib_id==0)
    return 1;  /* function not found, default to string */

  if (name[0]==0)
    name = "IDVALUE";  /* pure numbers are used as attributes in IupList and IupMatrix, 
                          translate them into IDVALUE. */
  afunc = (IattribFunc*)iupTableGet(ih->iclass->attrib_func, name);
  if (afunc && afunc->flags & IUPAF_HAS_ID)
  {         
    if (afunc->flags & IUPAF_READONLY)
    {
      if (afunc->flags & IUPAF_NO_STRING)
        return -1;  /* value is NOT a string, can NOT call iupAttribSetStr */
      return 0;
    }

    if (afunc->set && 
        !(afunc->flags & IUPAF_HAS_ID2) &&
        (ih->handle || afunc->flags & IUPAF_NOT_MAPPED))
    {
      /* id numbered attributes have default value NULL always */
      IattribSetIdFunc id_set = (IattribSetIdFunc)afunc->set;
      return id_set(ih, id, value);
    }

    if (afunc->flags & IUPAF_NO_STRING)
      return -1; /* value is NOT a string, can NOT call iupAttribSetStr */
  }

  return 1;  /* function not found, default to string */
}
示例#2
0
void notes_display(ustring& note_buffer, vector <unsigned int> ids, unsigned int cursor_id, unsigned int &cursor_offset, bool & stop, unsigned int edited_note_id)
/*
 This collect html data for displaying the notes.
 It collects data for all the notes that have an id given in ids.
 It inserts a html anchor at the start of the note whose id is "cursor_id".
 If an "edited_note_id" is given that is not in the list of "ids", then it will display that one too, together with a message.
 */
{
    extern Settings *settings;
    ProjectConfiguration *projectconfig = settings->projectconfig(settings->genconfig.project_get());
    ustring language = projectconfig->language_get();

    // Whether to show the text of the reference(s).
    bool show_reference_text = settings->genconfig.notes_display_reference_text_get();

    // Whether to show the summary only.
    bool show_summary = settings->genconfig.notes_display_summary_get();

    // See whether to display an extra note, one just edited.
    if (edited_note_id) {
        set <unsigned int> id_set (ids.begin(), ids.end());
        if (id_set.find (edited_note_id) == id_set.end()) {
            notes_display_internal(language, show_reference_text, show_summary, note_buffer, edited_note_id,
                                   _("The following note is displayed because it was created or edited. Normally it would not have been displayed."),
                                   cursor_id, cursor_offset);
        }
    }

    // Go through all the notes.
    for (unsigned int c = 0; c < ids.size(); c++) {

        // Handle possible stop command.
        if (stop)
            continue;

        // Display this note.
        notes_display_internal(language, show_reference_text, show_summary, note_buffer, ids[c], NULL, cursor_id, cursor_offset);

    }

}
示例#3
0
BlkResTestDiffusion::BlkResTestDiffusion(const InputParameters & parameters)
  : Kernel(modifyParams(parameters))
{

  // Get an test enum from the kernel parameters
  MooseEnum test = parameters.get<MooseEnum>("test");

  // test that hasBlocks is working
  if (test == "hasBlocks")
  {
    // Define a SubdomainName vector for testing against
    std::vector<SubdomainName> id_names(2);
    id_names[0] = "1";
    id_names[1] = "2";

    // Define a SubdomainID vector for testing against
    std::vector<SubdomainID> ids(2);
    ids[0] = 1;
    ids[1] = 2;

    // Define a SubdomainID set for testing against
    std::set<SubdomainID> id_set(ids.begin(), ids.end());

    // Test true single SudomainName input
    if (!hasBlocks("1"))
      mooseError("Test 1: hasBlocks(SubdomainName) = true failed");

    // Test false of single Subdomain input
    if (hasBlocks("3"))
      mooseError("Test 2: hasBlocks(SubdomainName) = false failed");

    // Test true vector SubdomainName input
    if (!hasBlocks(id_names))
      mooseError("Test 3: hasBlocks(std::vector<SubdomainName>) = true failed");

    // Test false vector SudomainName input
    id_names.push_back("3");
    if (hasBlocks(id_names))
      mooseError("Test 4: hasBlocks(std::vector<SubdomainName>) = false failed");

    // Test true single SubdomainID input
    if (!hasBlocks(1))
      mooseError("Test 5: hasBlocks(SubdomainID) = true failed");

    // Test false single SubdomainID input
    if (hasBlocks(5))
      mooseError("Test 6: hasBlocks(SubdomainID) = false failed");

    // Test true for std::vector<SubdomainID>
    if (!hasBlocks(ids))
      mooseError("Test 7: hasBlocks(std::vector<SubdomainID>) = true failed");

    // Test false for std::vector<SubdomainID>
    ids.push_back(4);
    if (hasBlocks(ids))
      mooseError("Test 8: hasBlocks(std::vector<SubdomainID>) = false failed");

    // Test true for std::set<SubdomainID>
    if (!hasBlocks(id_set))
      mooseError("Test 9: hasBlocks(std::set<SubdomainID) = true failed");

    // Test false for std::set<SubdomainID>
    id_set.insert(12);
    if (hasBlocks(id_set))
      mooseError("Test 10: hasBlocks(std::set<SubdomainID>) = false failed");

    // This is the expected error, all the above tests passed
    mooseError("hasBlocks testing passed");
  }

  // Test of stored ANY_BLOCK_ID on object
  else if (test == "hasBlocks_ANY_BLOCK_ID")
  {
    // Test that ANY_BLOCK_ID is working
    if (hasBlocks(1))
      mooseError("hasBlocks_ANY_BLOCK_ID test passed");
    else
      mooseError("hasBlocks_ANY_BLOCK_ID test failed");
  }

  // Test that the blocks() method is working
  else if (test == "blocks")
  {
    const std::vector<SubdomainName> & blks = blocks();
    if (blks[0] == "1" && blks[1] == "2" && blks.size() == 2)
      mooseError("Blocks testing passed"); // expected error
    else
      mooseError("Blocks testing failed");
  }

  // Test that the getSubdomains() is working
  else if (test == "blockIDs")
  {
    const std::set<SubdomainID> & ids = blockIDs();
    if (ids.count(1) == 1 && ids.count(2) == 1)
      mooseError("blockIDs testing passed"); // expected error
    else
      mooseError("blockIDs testing failed");
  }

  // Test that the isSubset() is working
  else if (test == "isBlockSubset")
  {
    std::set<SubdomainID> sub_id;
    sub_id.insert(10);
    sub_id.insert(1);
    sub_id.insert(4);
    sub_id.insert(2);
    if (isBlockSubset(sub_id))
      mooseError("isBlockSubset testing passed"); // expected error
    else
      mooseError("isBlockSubset testing failed");
  }

  // Test that hasMaterialPropertyBlock is working properly
  else if (test == "hasBlockMaterialProperty_true")
  {
    if (hasBlockMaterialProperty<Real>("a"))
      mooseError("hasBlockMaterialProperty is true, test passed"); // expected error
    else
      mooseError("hasBlockMaterialProperty is false, test failed");
  }

  else if (test == "hasBlockMaterialProperty_false")
  {
    if (hasBlockMaterialProperty<Real>("b"))
      mooseError("hasBlockMaterialProperty is true, test failed");
    else
      mooseError("hasBlockMaterialProperty is false, test passed"); // expected error
  }
}
int iupClassObjectSetAttribute(Ihandle* ih, const char* name, const char * value, int *inherit)
{
  IattribFunc* afunc;

  if (ih->iclass->has_attrib_id!=0)
  {
    const char* name_id = iClassFindId(name);
    if (name_id)
    {
      const char* partial_name = iClassCutNameId(name, name_id);
      if (!partial_name)
        partial_name = "IDVALUE";  /* pure numbers are used as attributes in IupList and IupMatrix, 
                                      translate them into IDVALUE. */
      afunc = (IattribFunc*)iupTableGet(ih->iclass->attrib_func, partial_name);
      if (afunc && afunc->flags & IUPAF_HAS_ID)
      {         
        *inherit = 0;       /* id numbered attributes are NON inheritable always */

        if (afunc->flags & IUPAF_READONLY)
        {
          if (afunc->flags & IUPAF_NO_STRING)
            return -1;  /* value is NOT a string, can NOT call iupAttribSetStr */
          return 0;
        }

        if (afunc->set && (ih->handle || afunc->flags & IUPAF_NOT_MAPPED))
        {
          if (afunc->flags & IUPAF_HAS_ID2)
          {
            IattribSetId2Func id2_set = (IattribSetId2Func)afunc->set;
            int id1=IUP_INVALID_ID, id2=IUP_INVALID_ID;
            iupStrToIntInt(name_id, &id1, &id2, ':');  /* ignore errors because of '*' ids */
            return id2_set(ih, id1, id2, value);
          }
          else
          {
            IattribSetIdFunc id_set = (IattribSetIdFunc)afunc->set;
            int id=IUP_INVALID_ID;
            if (iupStrToInt(name_id, &id))
              return id_set(ih, id, value);
          }
        }

        if (afunc->flags & IUPAF_NO_STRING)
          return -1; /* value is NOT a string, can NOT call iupAttribSetStr */

        return 1; /* if the function exists, then must return here */
      }
    }
  }

  /* if not has_attrib_id, or not found an ID, or not found the partial name, check using the full name */

  afunc = (IattribFunc*)iupTableGet(ih->iclass->attrib_func, name);
  *inherit = 1; /* default is inheritable */
  if (afunc)
  {
    *inherit = !(afunc->flags & IUPAF_NO_INHERIT) &&   /* is inheritable */
               !(afunc->flags & IUPAF_NO_STRING);      /* is a string */

    if (afunc->flags & IUPAF_READONLY)
    {
      if (afunc->flags & IUPAF_NO_STRING)
        return -1;  /* value is NOT a string, can NOT call iupAttribSetStr */
      return 0;
    }

    if (afunc->set && (ih->handle || afunc->flags & IUPAF_NOT_MAPPED))
    {
      int ret;
      if (!value)
      {
        /* inheritable attributes when reset must check the parent value */
        if (*inherit && ih->parent)   
          value = iupAttribGetInherit(ih->parent, name); 

        if (!value)
          value = iClassGetDefaultValue(afunc);
      }

      if (afunc->flags & IUPAF_HAS_ID2)
      {
        IattribSetId2Func id2_set = (IattribSetId2Func)afunc->set;
        return id2_set(ih, IUP_INVALID_ID, IUP_INVALID_ID, value);  /* empty Id */
      }
      else if (afunc->flags & IUPAF_HAS_ID)
      {
        IattribSetIdFunc id_set = (IattribSetIdFunc)afunc->set;
        return id_set(ih, IUP_INVALID_ID, value);  /* empty Id */
      }
      else
        ret = afunc->set(ih, value);

      if (ret == 1 && afunc->flags & IUPAF_NO_STRING)
        return -1;  /* value is NOT a string, can NOT call iupAttribSetStr */

      if (*inherit)
        return 1;   /* inheritable attributes are always stored in the hash table, */
      else          /* to indicate that they are set at the control.               */
        return ret;
    }
  }

  return 1;  /* function not found, default to string */
}
示例#5
0
BndTestDirichletBC::BndTestDirichletBC(const InputParameters & parameters) :
  NodalBC(parameters),
  _value(getParam<Real>("value"))
{

  // Get an test enum from the kernel parameters
  MooseEnum test = parameters.get<MooseEnum>("test");

  // test that hasBlocks is working
  if (test == "hasBoundary")
  {
    // Define a SubdomainName vector for testing against
    std::vector<BoundaryName> id_names(1);
    id_names[0] = "1";

    // Define a SubdomainID vector for testing against
    std::vector<BoundaryID> ids(1);
    ids[0] = 1;

    // Define a SubdomainID set for testing against
    std::set<BoundaryID> id_set(ids.begin(), ids.end());

    // Test true single SudomainName input
    if (!hasBoundary("1"))
      mooseError("Test 1: hasBoundary(SubdomainName) = true failed");

    // Test false of single Subdomain input
    if (hasBoundary("3"))
      mooseError("Test 2: hasBoundary(BoundaryName) = false failed");

    // Test true vector BoundaryName input
    if (!hasBoundary(id_names))
      mooseError("Test 3: hasBoundary(std::vector<BoundaryName>) = true failed");

    // Test false vector SudomainName input
    id_names.push_back("3");
    if (hasBoundary(id_names))
      mooseError("Test 4: hasBoundary(std::vector<BoundaryName>) = false failed");

    // Test true single BoundaryID input
    if (!hasBoundary(1))
      mooseError("Test 5: hasBoundary(BoundaryID) = true failed");

    // Test false single BoundaryID input
    if (hasBoundary(5))
      mooseError("Test 6: hasBoundary(BoundaryID) = false failed");

    // Test true for std::vector<BoundaryID>
    if (!hasBoundary(ids))
      mooseError("Test 7: hasBoundary(std::vector<BoundaryID>) = true failed");

    // Test false for std::vector<BoundaryID>
    ids.push_back(4);
    if (hasBoundary(ids))
      mooseError("Test 8: hasBoundary(std::vector<BoundaryID>) = false failed");

    // Test true for std::set<BoundaryID>
    if (!hasBoundary(id_set))
      mooseError("Test 9: hasBoundary(std::set<BoundaryID) = true failed");

    // Test false for std::set<BoundaryID>
    id_set.insert(12);
    if (hasBoundary(id_set))
      mooseError("Test 10: hasBoundary(std::set<BoundaryID>) = false failed");

    // This is the expected error, all the above tests passed
    mooseError("hasBoundary testing passed");
  }

  // Test that the boundarhNames() method is working
  else if (test == "boundaryNames")
  {
    const std::vector<BoundaryName> & bnds = boundaryNames();
    if (bnds.size() == 1 && bnds[0] == "1")
      mooseError("boundaryNames test passed"); // expected error
    else
      mooseError("boundaryNames test failed");
  }

  // Test that the boundaryIDS() is working
  else if (test == "boundaryIDs")
  {
    const std::set<BoundaryID> & ids = boundaryIDs();
    if (ids.count(1) == 1)
      mooseError("boundaryIDs test passed"); // expected error
    else
      mooseError("boundaryIDs test faild");
  }

  // Test that the isBoundarySubset() is working
  else if (test == "isBoundarySubset")
  {
    std::set<BoundaryID> sub_id;
    sub_id.insert(10);
    sub_id.insert(1);
    sub_id.insert(4);
    sub_id.insert(2);
    if (isBoundarySubset(sub_id))
      mooseError("isBoundarySubset test passed"); // expetect error
    else
      mooseError("isBoundarySubset test failed");
  }

  // Test that hasMaterialPropertyBoundary is working properly
  else if (test == "hasBoundaryMaterialProperty_true")
  {
    if (hasBoundaryMaterialProperty<Real>("a"))
      mooseError("hasBoundaryMaterialProperty is true, test passed"); // expected error
    else
      mooseError("hasBoundaryMaterialProperty is false, test failed");
  }

  else if (test == "hasBoundaryMaterialProperty_false")
  {
    if (hasBoundaryMaterialProperty<Real>("b"))
      mooseError("hasBoundaryMaterialProperty is true, test failed");
    else
      mooseError("hasBoundaryMaterialProperty is false, test passed"); // expected error
  }
}