cgma
|
00001 //- Class: RefEntityName 00002 //- 00003 //- Description: This file maintains a map between a name and a 00004 //- refentity. Names must be unique, but a refentity may have 00005 //- multiple names. This is a singleton class. 00006 //- 00007 //- Owner: Greg Sjaardema 00008 //- Checked by: 00009 //- Version: $Id: 00010 00011 #ifndef REFENTITYNAME_HPP 00012 #define REFENTITYNAME_HPP 00013 00014 #include "CGMGeomConfigure.h" 00015 #include "CubitDefines.h" 00016 #include <map> 00017 00018 template <class X> class DLIList; 00019 class CubitString; 00020 class RefEntity; 00021 00022 typedef std::multimap<RefEntity*, CubitString> RefEntityNameMap; 00023 typedef std::map<CubitString, RefEntity*> NameRefEntityMap; 00024 00025 struct RefEntityNameMaps 00026 { 00027 RefEntityNameMap refMap; 00028 NameRefEntityMap nameMap; 00029 }; 00030 00031 class CUBIT_GEOM_EXPORT RefEntityName 00032 { 00033 00034 public: 00035 00036 //Initialize all settings in this class 00037 static void initialize_settings(); 00038 static RefEntityName *instance(); 00039 ~RefEntityName(); 00040 00041 static void delete_instance() 00042 { 00043 if(instance_) 00044 delete instance_; 00045 instance_ = NULL; 00046 } 00047 00048 void remove_refentity_name(RefEntity* entity, 00049 const CubitString &name, 00050 CubitBoolean update_attribs = CUBIT_TRUE); 00051 //- Remove the this name from the map. All other names for this 00052 //- RefEntity remain in the map 00053 00054 void remove_refentity_name(RefEntity *entity, 00055 CubitBoolean update_attribs = CUBIT_TRUE); 00056 //- Remove this RefEntity and all its names from the map. 00057 00058 CubitStatus add_refentity_name(RefEntity *entity, 00059 CubitString &name, 00060 bool update_attribs = true, 00061 bool check_name_validity = true); 00062 //- Add the map between this RefEntity and the name. 00063 //- If 'name' is invalid or duplicate, it is changed and 00064 //- new name is returned. 00065 //- Returns CUBIT_FAILURE if unsuccessful. 00066 00067 CubitStatus add_refentity_name(RefEntity *entity, 00068 DLIList<CubitString> &names, 00069 bool update_attribs = true, 00070 bool check_name_validity = true); 00071 //- add multiple names to the name map for this entity 00072 00073 int get_refentity_name(const RefEntity *entity, DLIList<CubitString> &names); 00074 //- Get the list of names corresponding to this RefEntity. 00075 //- Returns the number of names found for this RefEntity. 00076 00077 void merge_refentity_names(RefEntity *retained, 00078 RefEntity *dead); 00079 //- Associates the names of the dead RefEntity with the retained 00080 //- RefEntity. 00081 00082 void switch_refentity_names(RefEntity *entity1, 00083 RefEntity *entity2); 00084 //- Switch names of entity1 and entity2 00085 00086 RefEntity* get_refentity(const CubitString &name); 00087 //- Returns a pointer to the RefEntity with this name. 00088 00089 void list_refentity_names(const char *type = "all"); 00090 //- Prints an alphabetical list of all entity names in the map. 00091 //- The argument is a filter on the list which restricts it to 00092 //- certain entity types (body, volume, surface, curve, vertex). 00093 00094 const char* get_refentity_type(const CubitString &name); 00095 //- Returns a pointer to the string identifying the type of the 00096 //- RefEntity with this name. (Body, Volume, ...) 00097 00098 int get_refentity_id(const CubitString &name); 00099 //- Returns the id of the RefEntity with this name. 00100 00101 static int get_generate_default_names(); 00102 static void set_generate_default_names(int on_off); 00103 //- Specifies whether default RefEntity names should be generated (Surface1). 00104 00105 static int get_fix_duplicate_names(); 00106 static void set_fix_duplicate_names(int on_off); 00107 //- Specifies whether duplicate names should be fixed (made unique) 00108 00109 void set_character(char rep, const CubitString &type); 00110 char get_character(const CubitString &type) const; 00111 00112 00113 static void set_suffix_setting(CubitString rep); 00114 static CubitString get_suffix_setting(); 00115 static void set_replacement_setting(CubitString rep); 00116 static CubitString get_replacement_setting(); 00117 00118 static CubitString base_name(const CubitString &name); 00119 00120 CubitBoolean same_base_name(const CubitString &name1, 00121 const CubitString &name2); 00122 //- return CUBIT_TRUE if the base name (i.e. the name before the suffixChar) 00123 //- is the same 00124 00125 static CubitBoolean get_merge_base_names() {return mergeBaseNames;}; 00126 static void set_merge_base_names(CubitBoolean flag) {mergeBaseNames = flag;}; 00127 //- get/set mergeBaseNames 00128 00129 void copy_refentity_names( const RefEntity* source, 00130 RefEntity* target, 00131 CubitBoolean update_attribs = CUBIT_TRUE ); 00132 void copy_refentity_names( DLIList<RefEntity*>& source_list, 00133 RefEntity* target, 00134 CubitBoolean unique_base_names = CUBIT_TRUE, 00135 CubitBoolean update_attribs = CUBIT_TRUE ); 00136 //- Copy names from one entity to another. 00137 00138 bool print_name_change_warnings() {return printNameChangeWarnings;} 00139 void print_name_change_warnings(bool new_val) {printNameChangeWarnings = new_val;} 00140 int num_name_change_warnings() {return numNameChangeWarnings;} 00141 void num_name_change_warnings(int new_val) {numNameChangeWarnings = new_val;} 00142 00143 protected: 00144 RefEntityName(); 00145 //- Class Constructor. (Not callable by user code. Class is constructed 00146 //- by the {instance()} member function. 00147 00148 private: 00149 CubitStatus clean(CubitString &raw_name); 00150 //- replace invalid characters in {raw_name} with {replacementCharacter} 00151 00152 CubitStatus generate_unique_name(CubitString &name); 00153 00154 static RefEntityName *instance_; 00155 //- static pointer to unique instance of this class 00156 00157 RefEntityNameMaps nameEntityList; 00158 00159 static int fixDuplicateNames; 00160 static int generateDefaultNames; 00161 static char replacementCharacter; 00162 static char suffixCharacter; 00163 static bool printNameChangeWarnings; 00164 static int numNameChangeWarnings; 00165 00166 static CubitBoolean mergeBaseNames; 00167 //- if CUBIT_TRUE, when entity names are merged, names with duplicate 00168 //- base names are removed 00169 }; 00170 #endif 00171 00172