cgma
CAMergePartner Class Reference

#include <CAMergePartner.hpp>

Inheritance diagram for CAMergePartner:
CubitAttrib

List of all members.

Public Member Functions

 CAMergePartner (RefEntity *, const CubitSimpleAttrib &)
void initialize ()
virtual ~CAMergePartner ()
CubitStatus actuate ()
CubitStatus actuate_list (DLIList< RefEntity * >)
CubitStatus update ()
CubitStatus reset ()
CubitSimpleAttrib cubit_simple_attrib ()
CubitSimpleAttrib cubit_simple_attrib (CubitString)
int merge_id ()
int int_attrib_type ()
CubitSense bridge_sense ()
void merge_prepare (DLIList< RefEntity * > &merge_list)
virtual void print ()

Static Public Member Functions

static void set_survivor (CubitSimpleAttrib &csa, int is_survivor)
static CubitBoolean is_survivor (const CubitSimpleAttrib &csa)
static void set_bridge_sense (CubitSimpleAttrib &csa, CubitSense sense)
static CubitSense get_bridge_sense (const CubitSimpleAttrib &csa_ptr)
static void set_saved_id (CubitSimpleAttrib &csa, int id)
static int get_saved_id (const CubitSimpleAttrib &csa)

Private Attributes

int mergeID
int isSurvivor
CubitSense bridge_sense_

Detailed Description

Definition at line 19 of file CAMergePartner.hpp.


Constructor & Destructor Documentation

CAMergePartner::CAMergePartner ( RefEntity new_attrib_owner,
const CubitSimpleAttrib csa_ptr 
)

Definition at line 32 of file CAMergePartner.cpp.

        : CubitAttrib(new_attrib_owner)
{
  initialize();

  if(!csa_ptr.isEmpty())
  {
    int i_temp = csa_ptr.int_data_list()[0];
    mergeID = i_temp;
    if( csa_ptr.int_data_list().size() > 1 )
    {
      i_temp = csa_ptr.int_data_list()[1];
      switch( i_temp ) {
        case -1: bridge_sense_ = CUBIT_REVERSED; break;
        case  1: bridge_sense_ = CUBIT_FORWARD;  break;
        case  0: bridge_sense_ = CUBIT_UNKNOWN; break;
        default: bridge_sense_ = CUBIT_UNKNOWN; assert(0);
      }
    }
  }
}

Definition at line 55 of file CAMergePartner.cpp.

{
    //
  mergeID = 0;
}

Member Function Documentation

Implements CubitAttrib.

Definition at line 70 of file CAMergePartner.cpp.

{
  hasActuated = CUBIT_TRUE;
  return CUBIT_SUCCESS;
  //We don't need to actuate this attribute here since the merging
  //happens in GeometryQueryTool::check_mergeable_refentity.
  
  /*
  if (hasActuated == CUBIT_TRUE) return CUBIT_SUCCESS;
  
  BasicTopologyEntity * bte_ptr = CAST_TO(attribOwnerEntity,BasicTopologyEntity); 
  if (bte_ptr == NULL || bte_ptr->deactivated() == CUBIT_TRUE)
    return CUBIT_FAILURE;
  
  DLIList<RefEntity*> merge_list;
  //merge_prepare(merge_list);
  merge_list.append_unique(attribOwnerEntity);

  CubitStatus result = CUBIT_SUCCESS;

  if (merge_list.size() > 1)
    result = (NULL == MergeTool::instance()->force_merge(merge_list))
            ? CUBIT_FAILURE : CUBIT_SUCCESS;

  if( result )
  {
    hasActuated = CUBIT_TRUE;
  }        

  return result; */
}
CubitStatus CAMergePartner::actuate_list ( DLIList< RefEntity * >  entity_list) [virtual]

Reimplemented from CubitAttrib.

Definition at line 161 of file CAMergePartner.cpp.

{

    // given a list of ref entities (usually all entities of a given type),
    // actuate the camp's on those entities
  RefEntity *ref_ent, *keeper;
  DLIList<CubitAttrib*> ca_list;
  DLIList<TopologyBridge*> bridge_list(entity_list.size());
  SDLCAMergePartnerList sorted_camp_list;
  int i;
  for(i = entity_list.size(); i > 0; i--)
  {
    ref_ent = entity_list.get_and_step();
    ca_list.clean_out();
    ref_ent->find_cubit_attrib_type(CA_MERGE_PARTNER, ca_list);
    assert(ca_list.size() < 2); // There should only be one
                                //  merge partner per entity
    if(ca_list.size() > 0)
    {
      CAMergePartner* attrib = dynamic_cast<CAMergePartner*>(ca_list.get());
      sorted_camp_list.append( attrib );
      TopologyEntity* te = dynamic_cast<TopologyEntity*>(ref_ent);
      TopologyBridge* bridge = te->bridge_manager()->topology_bridge();
      bridge_list.append(bridge);
    }
  }
  sorted_camp_list.sort();
  sorted_camp_list.reset();

  if (DEBUG_FLAG(90)) {
    for (i = sorted_camp_list.size(); i > 0; i--) {
      CAMergePartner *camp_ptr = sorted_camp_list.get_and_step();
      ref_ent = camp_ptr->attrib_owner();
      PRINT_DEBUG_90("%s %d, unique id = %d\n", ref_ent->class_name(),
                     ref_ent->id(), camp_ptr->merge_id());
    }
  }
  
    // now go through all the camp's for the entity list; peel off
    // camp's with the same id, and merge the associated entities together
  while (sorted_camp_list.size() > 0) 
  {
    DLIList<RefEntity*> refent_list;
    DLIList<CubitAttrib*> camp_list;
    keeper = NULL;

      // get the next list of entities with the same camp id
    sorted_camp_list.last();
    CAMergePartner *camp_ptr = sorted_camp_list.remove();
    sorted_camp_list.back();
    camp_list.append(camp_ptr);
    int current_id = camp_ptr->merge_id();
    while (sorted_camp_list.size() > 0 &&
           sorted_camp_list.get()->merge_id() == current_id) {
      camp_list.append(sorted_camp_list.remove());
      sorted_camp_list.back();
    }
    
    if (camp_list.size() == 1) continue;
    
    CubitBoolean has_actuated = camp_list.get()->has_actuated();

      // check the has actuated flag; if one is set, they all should be;
      // also, compile list of ref entities while we're at it
    for (current_id = camp_list.size(); current_id > 0; current_id--) {
      ref_ent = camp_list.get()->attrib_owner();
      refent_list.append(ref_ent);
      if (!keeper || ref_ent->id() < keeper->id()) keeper = ref_ent;
      assert(camp_list.get()->has_actuated() == has_actuated);
      camp_list.step();
    }

      // if they have already actuated, go on to next ones
    if (has_actuated == CUBIT_TRUE) continue;

      // otherwise merge
    if(refent_list.size() > 1)
      MergeTool::instance()->force_merge(refent_list);

        // remove the cubit attribute from the surviving parent
    keeper->remove_cubit_attrib(CA_MERGE_PARTNER);

  } // loop over existing camp's
  
  return CUBIT_SUCCESS;
}

Definition at line 56 of file CAMergePartner.hpp.

    { return bridge_sense_; }

Implements CubitAttrib.

Definition at line 276 of file CAMergePartner.cpp.

{
  std::vector<CubitString> cs_list;
  std::vector<double> d_list;
  std::vector<int> i_list;

  i_list.push_back(mergeID);
  cs_list.push_back(att_internal_name());

  return CubitSimpleAttrib(&cs_list, &d_list, &i_list);
}

Definition at line 346 of file CAMergePartner.cpp.

{
  const std::vector<int>& data = csa.int_data_list();
  if( data.size() >= 2)
  {
    int i = data[1];
    switch(i) {
      case  1: return CUBIT_FORWARD;
      case -1: return CUBIT_REVERSED;
      default: assert(0);  // if -DNDEBUG, fall through to unknown
      case  0: return CUBIT_UNKNOWN;
    }
  }

  return CUBIT_UNKNOWN;
}
int CAMergePartner::get_saved_id ( const CubitSimpleAttrib csa) [static]

Definition at line 385 of file CAMergePartner.cpp.

{
   //get the list we want to modify from the CSA
  const std::vector<int>& data = csa.int_data_list();

  if (data.size() < 3)
    return 0;
  
  return data[2];
}

Definition at line 62 of file CAMergePartner.cpp.

int CAMergePartner::int_attrib_type ( ) [inline, virtual]

Implements CubitAttrib.

Definition at line 53 of file CAMergePartner.hpp.

{return CA_MERGE_PARTNER;}

Definition at line 333 of file CAMergePartner.cpp.

{
  const std::vector<int>& data = csa.int_data_list();
  if( data.size() >= 4)
  {
    int i = data[3];
    if( i == 1 )
      return true;
  }
  return false;
}
int CAMergePartner::merge_id ( ) [inline]

Definition at line 51 of file CAMergePartner.hpp.

{return mergeID;}
void CAMergePartner::merge_prepare ( DLIList< RefEntity * > &  merge_list)

Definition at line 102 of file CAMergePartner.cpp.

{
  DLIList<CubitAttrib*> my_ca_list;
  CAMergePartner *my_camp_ptr;
  RefEntity* re_ptr;

    // get all the merge partner attributes that are on my owner
  attribOwnerEntity->find_cubit_attrib_type(CA_MERGE_PARTNER, my_ca_list);
  merge_list.clean_out();
  DLIList<ToolDataUser*> td_list, temp_td_list;
  int i;
  for (i = my_ca_list.size(); i > 0; i--)
  {
    my_camp_ptr = CAST_TO(my_ca_list.get(),CAMergePartner);
    my_ca_list.step();
    td_list.clean_out();
      // get all the objects with this unique id (which is also the merge id)
    TDUniqueId::find_td_unique_id(my_camp_ptr->merge_id(), temp_td_list);
    td_list += temp_td_list;
  }
  
    // now put those entities into the merge_list
  for (i = td_list.size(); i > 0; i--) 
  {
    re_ptr = CAST_TO(td_list.get(), RefEntity);
    if (re_ptr) 
    {
      CubitAttrib *tmp_attrib = re_ptr->get_cubit_attrib( CA_MERGE_PARTNER, CUBIT_FALSE );
      if( tmp_attrib )
        merge_list.append(re_ptr);
    }
    td_list.step();
  }
  
    // Now get bridge sense for each entity in list.
    // Add this entity to list, too.
  merge_list.append( attribOwnerEntity );
  for( i = merge_list.size(); i--; )
  {
    RefEntity* ent = merge_list.get_and_step();
    TopologyEntity* te = dynamic_cast<TopologyEntity*>(ent);
    if( te->bridge_manager()->number_of_bridges() != 1 )
      continue;
    
    my_ca_list.clean_out();
    ent->find_cubit_attrib_type(CA_MERGE_PARTNER, my_ca_list);
    assert( my_ca_list.size() < 2);
    if( !my_ca_list.size() )
      continue;
    
    my_camp_ptr = dynamic_cast<CAMergePartner*>(my_ca_list.get());
    if( my_camp_ptr->bridge_sense() == CUBIT_UNKNOWN )
      continue;
  }  
  merge_list.pop(); // take attribOwnerEntity back off list
    
  return;
}
void CAMergePartner::print ( ) [virtual]

Reimplemented from CubitAttrib.

Definition at line 398 of file CAMergePartner.cpp.

{
  PRINT_INFO("Attribute MERGE_PARTNER, %s %d: mergeId = %d, sense = %d.\n",
             attribOwnerEntity->class_name(), attribOwnerEntity->id(),
             mergeID, bridge_sense_);
}
void CAMergePartner::set_bridge_sense ( CubitSimpleAttrib csa,
CubitSense  sense 
) [static]

Definition at line 305 of file CAMergePartner.cpp.

{
  //encode/decode sense as:
  // CUBIT_FORWARD :  1
  // CUBIT_REVERSE : -1
  // CUBIT_UNKNOWN :  0
  int i = 0;
  switch( sense ) { 
    case CUBIT_FORWARD  : i =  1; break;
    case CUBIT_REVERSED : i = -1; break;
    case CUBIT_UNKNOWN  : i =  0; break;
    default: assert(0);
  }
  
  //get the list we want to modify from the CSA
  std::vector<int>& data = csa.int_data_list();
  
  //change or append?
  if( data.size() >= 2 )
  {
    data[1] = i;
  }
  else 
  {
    assert( data.size() == 1 );
    data.push_back(i);
  }
}
void CAMergePartner::set_saved_id ( CubitSimpleAttrib csa,
int  id 
) [static]

Definition at line 363 of file CAMergePartner.cpp.

{
   //get the list we want to modify from the CSA
  std::vector<int>& data = csa.int_data_list();

    // ID goes after bridge sense, so save bridge sense first
  if (data.size() == 1)
    set_bridge_sense( csa, CUBIT_UNKNOWN );
  
    // change?
  if (data.size() > 2 )
  {
    data[2] = id;
  }
    // set?
  else
  {
    assert(data.size() == 2);
    data.push_back(id);
  }
}
void CAMergePartner::set_survivor ( CubitSimpleAttrib csa,
int  is_survivor 
) [static]

Definition at line 288 of file CAMergePartner.cpp.

{
  //get the list we want to modify from the CSA
  std::vector<int>& data = csa.int_data_list();
  
  //change or append?
  if( data.size() >= 4 )
  {
    data[3] = is_survivor;
  }
  else 
  {
    assert( data.size() == 3 );
    data.push_back(is_survivor);
  }
}

Implements CubitAttrib.

Definition at line 248 of file CAMergePartner.cpp.

{
  if (hasUpdated) return CUBIT_SUCCESS;
  
    // set the updated flag
  hasUpdated = CUBIT_TRUE;
  BasicTopologyEntity* bte_ptr = CAST_TO(attribOwnerEntity, BasicTopologyEntity);

  if( (bte_ptr == NULL) || (dynamic_cast<RefVolume*>(bte_ptr) != NULL))
  {
    delete_attrib(CUBIT_TRUE);
  }
  else if( (bte_ptr->bridge_manager()->number_of_bridges() == 1) &&
           (bte_ptr->bridge_manager()->topology_bridge()->bridge_sense() != CUBIT_REVERSED) )
  {
    delete_attrib(CUBIT_TRUE);
  }
  else
  {
      // get the merge id from the TDUniqueId for the owner entity
    mergeID = TDUniqueId::get_unique_id(attribOwnerEntity);
    bridge_sense_ = CUBIT_UNKNOWN;
    isSurvivor = 0;
  }

  return CUBIT_SUCCESS;
}

Member Data Documentation

Definition at line 27 of file CAMergePartner.hpp.

Definition at line 26 of file CAMergePartner.hpp.

int CAMergePartner::mergeID [private]

Definition at line 23 of file CAMergePartner.hpp.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines