1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
//- Class:          CAUniqueId
//- Owner:          Tim Tautges
//- Description:    Cubit Attribute for unique ids
//- Checked By:
//- Version:

#include "CAUniqueId.hpp"
#include "CubitSimpleAttrib.hpp"
#include "RefEntity.hpp"
#include "TDUniqueId.hpp"
#include "GSaveOpen.hpp"
#include "GeometryQueryTool.hpp"

DLIList<CAUniqueId *> CAUniqueId::allCAUniqueIds;
bool CAUniqueId::autoUniqueId = false;
UIDMap CAUniqueId::oldUIDToNewUID;

CubitAttrib* CAUniqueId_creator(RefEntity* entity, const CubitSimpleAttrib &p_csa)
{
  return new CAUniqueId(entity, p_csa);
}

CAUniqueId::~CAUniqueId()
{
  if (allCAUniqueIds.move_to(this))
    allCAUniqueIds.extract();
}

CAUniqueId::CAUniqueId(RefEntity* new_attrib_owner,
                               const CubitSimpleAttrib &csa_ptr)
        : CubitAttrib(new_attrib_owner)
{
  uniqueId = -1;

  if(!csa_ptr.isEmpty())
  {
    uniqueId = csa_ptr.int_data_list()[0];
  }
  allCAUniqueIds.append(this);
}

CubitStatus CAUniqueId::actuate()
{

  if (hasActuated == CUBIT_TRUE) return CUBIT_SUCCESS;

    // create a TDUniqueId for the entity, if it doesn't already
    // exist
  TDUniqueId *uid = (TDUniqueId *) attrib_owner()->get_TD(&TDUniqueId::is_unique_id);

  if (uid != NULL) {
      // check to make sure it's the same unique id
    if (uid->unique_id() != uniqueId) {
      PRINT_ERROR("Different unique id found for %s %d.\n",
                  attrib_owner()->class_name(), attrib_owner()->id());
      return CUBIT_FAILURE;
    }
  }
  else 
  {
    if( !GSaveOpen::performingUndo && 
         GeometryQueryTool::importingSolidModel &&
        !GeometryQueryTool::mergeGloballyOnImport)
    {
      //Is there an entity that already has this id?
      ToolDataUser *tdu = TDUniqueId::find_td_unique_id(uniqueId);
      if( tdu )
      {
        //is it already in the map
        UIDMap::iterator iter;
        iter = oldUIDToNewUID.find( uniqueId );
        
        if( iter != oldUIDToNewUID.end() )
          uniqueId = (*iter).second;
        else
        {
          int new_unique_id = TDUniqueId::generate_unique_id();
          UIDMap::value_type this_pair(uniqueId, new_unique_id);
          oldUIDToNewUID.insert(this_pair);
          uniqueId = new_unique_id;
        }
      }
    }

      // else make a new one
    uid = new TDUniqueId(attrib_owner(), uniqueId);<--- Variable 'uid' is assigned a value that is never used.
  }
  
  delete_attrib(CUBIT_TRUE);
  hasActuated = CUBIT_TRUE;
  
  return CUBIT_SUCCESS;
}

CubitStatus CAUniqueId::update()
{
  if (hasUpdated) return CUBIT_SUCCESS;
  
    // set the updated flag
  hasUpdated = CUBIT_TRUE;

    // if the owner has a unique id, save it, otherwise delete this one
  TDUniqueId *td_uid = (TDUniqueId *) attrib_owner()->get_TD(&TDUniqueId::is_unique_id);

  if (NULL == td_uid && autoUniqueId) 
    td_uid = new TDUniqueId(attrib_owner());

  if (td_uid == NULL) {
    delete_attrib(CUBIT_TRUE);
  }

  else {
    uniqueId = td_uid->unique_id();
    if (delete_attrib() == CUBIT_TRUE) delete_attrib(CUBIT_FALSE);
  }
  
  return CUBIT_SUCCESS;
}

CubitSimpleAttrib CAUniqueId::cubit_simple_attrib()
{
  return CubitSimpleAttrib(att_internal_name(), "", "",
                               &uniqueId);
}

CubitStatus CAUniqueId::actuate_all()
{
    //- actuate all the CAUI's on the list, then empty the list
  for (int i = allCAUniqueIds.size(); i > 0; i--) {
    CAUniqueId *cauid = allCAUniqueIds.get();
    if (cauid->actuate() == CUBIT_SUCCESS) allCAUniqueIds.extract();
    else allCAUniqueIds.step();
  }
  
  return CUBIT_SUCCESS;
}

void CAUniqueId::print()
{
    // print info on this attribute
  
  PRINT_INFO("CAUniqueId: owner = %s %d: uid=%d\n",
             attribOwnerEntity->class_name(), attribOwnerEntity->id(),
             uniqueId);
}

void CAUniqueId::clear_out_old_to_new_map()
{
  oldUIDToNewUID.clear(); 
}