void IfcAlignmentModel::insertEntity( shared_ptr<IfcAlignmentP6Entity> e, bool overwrite_existing ) { int entity_id = e->getId(); if( entity_id < 0 ) { int next_unused_id = getMaxUsedEntityId() + 1; e->setId( next_unused_id ); entity_id = next_unused_id; } std::map<int,shared_ptr<IfcAlignmentP6Entity> >::iterator lb = m_map_entities.lower_bound( entity_id ); if( lb != m_map_entities.end() && !(m_map_entities.key_comp()(entity_id, lb->first)) ) { // key already exists if( overwrite_existing ) { (*lb).second = e; } else { std::stringstream strs; strs << "IfcAlignmentModel::insertEntity: entity with id " << entity_id << " already exists in model" << std::endl; throw IfcAlignmentP6Exception( strs.str().c_str() ); } } else { // the key does not exist in the map m_map_entities.insert( lb, std::map<int,shared_ptr<IfcAlignmentP6Entity> >::value_type( entity_id, e ) ); } // TODO: if type is IfcRoot (or subtype), and GlobalID not set, create one }
void IfcPPModel::insertEntity( shared_ptr<IfcPPEntity> e, bool overwrite_existing, bool warn_on_existing_entities ) { if( !e ) { return; } int entity_id = e->m_id; if( entity_id < 0 ) { int next_unused_id = getMaxUsedEntityId() + 1; e->m_id = next_unused_id; entity_id = next_unused_id; } auto it_find = m_map_entities.find( entity_id ); if( it_find != m_map_entities.end() ) { // key already exists if( overwrite_existing ) { it_find->second = e; } else { if( warn_on_existing_entities ) { messageCallback( "Entity already in model", StatusCallback::MESSAGE_TYPE_WARNING, __FUNC__, e.get() ); } } } else { // the key does not exist in the map m_map_entities.insert( it_find, map_t<int,shared_ptr<IfcPPEntity> >::value_type( entity_id, e ) ); } #ifdef _DEBUG auto product = dynamic_pointer_cast<IfcProduct>( e ); if( product ) { if( !product->m_GlobalId ) { messageCallback( "IfcProduct->m_GlobalId not set", StatusCallback::MESSAGE_TYPE_WARNING, __FUNC__, product.get() ); return; } if( product->m_GlobalId->m_value.length() < 22 ) { messageCallback( "IfcProduct->m_GlobalId.length() < 22", StatusCallback::MESSAGE_TYPE_WARNING, __FUNC__, product.get() ); } } #endif // TODO: if type is IfcRoot (or subtype), and GlobalID not set, create one }