| 1 | // CAVirtualVG class |
|---|
| 2 | |
|---|
| 3 | #include "CAVirtualVG.hpp" |
|---|
| 4 | #include "CubitSimpleAttrib.hpp" |
|---|
| 5 | #include "TopologyEntity.hpp" |
|---|
| 6 | #include "RefEntity.hpp" |
|---|
| 7 | #include "BasicTopologyEntity.hpp" |
|---|
| 8 | #include "RefEdge.hpp" |
|---|
| 9 | #include "RefVertex.hpp" |
|---|
| 10 | #include "TDUniqueId.hpp" |
|---|
| 11 | #include "CADeferredAttrib.hpp" |
|---|
| 12 | |
|---|
| 13 | CubitAttrib* CAVirtualVG_creator(RefEntity* entity, CubitSimpleAttrib *p_csa) |
|---|
| 14 | { |
|---|
| 15 | CAVirtualVG *new_attrib = NULL; |
|---|
| 16 | if (NULL == p_csa) |
|---|
| 17 | { |
|---|
| 18 | new_attrib = new CAVirtualVG(entity); |
|---|
| 19 | } |
|---|
| 20 | else |
|---|
| 21 | { |
|---|
| 22 | new_attrib = new CAVirtualVG(entity, p_csa); |
|---|
| 23 | } |
|---|
| 24 | |
|---|
| 25 | return new_attrib; |
|---|
| 26 | } |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | CAVirtualVG::CAVirtualVG(RefEntity *owner) |
|---|
| 30 | : CubitAttrib(owner) |
|---|
| 31 | { |
|---|
| 32 | numVC = 0; |
|---|
| 33 | numVV = 0; |
|---|
| 34 | } |
|---|
| 35 | |
|---|
| 36 | CAVirtualVG::CAVirtualVG(RefEntity *owner, CubitSimpleAttrib *simple_attrib) |
|---|
| 37 | : CubitAttrib(owner) |
|---|
| 38 | { |
|---|
| 39 | // generate a simple attribute containing the data in this CA |
|---|
| 40 | DLIList<CubitString*> *cs_list = simple_attrib->string_data_list(); |
|---|
| 41 | DLIList<double*> *d_list = simple_attrib->double_data_list(); |
|---|
| 42 | DLIList<int*> *i_list = simple_attrib->int_data_list(); |
|---|
| 43 | |
|---|
| 44 | cs_list->reset(); |
|---|
| 45 | d_list->reset(); |
|---|
| 46 | i_list->reset(); |
|---|
| 47 | |
|---|
| 48 | // (no string) |
|---|
| 49 | |
|---|
| 50 | // now the integers |
|---|
| 51 | // numVV, numVC |
|---|
| 52 | numVV = *i_list->get_and_step(); |
|---|
| 53 | numVC = *i_list->get_and_step(); |
|---|
| 54 | |
|---|
| 55 | // vgUIDs |
|---|
| 56 | int i; |
|---|
| 57 | for (i = numVV+(3*numVC); i > 0; i--) |
|---|
| 58 | vgUIDs.append(*i_list->get_and_step()); |
|---|
| 59 | |
|---|
| 60 | // numVCPoints |
|---|
| 61 | int sum = 0; |
|---|
| 62 | for (i = numVC; i > 0; i--) { |
|---|
| 63 | int temp_int = *i_list->get_and_step(); |
|---|
| 64 | numVCPoints.append(temp_int); |
|---|
| 65 | sum += temp_int; |
|---|
| 66 | } |
|---|
| 67 | |
|---|
| 68 | // pointUIDList |
|---|
| 69 | for (i = numVV+sum; i > 0; i--) { |
|---|
| 70 | double x = *d_list->get_and_step(); |
|---|
| 71 | double y = *d_list->get_and_step(); |
|---|
| 72 | double z = *d_list->get_and_step(); |
|---|
| 73 | posVector.append( new CubitVector( x, y, z ) ); |
|---|
| 74 | } |
|---|
| 75 | |
|---|
| 76 | // If we are constructing from a CubitSimpleAttrib, |
|---|
| 77 | // then this attrib is already written |
|---|
| 78 | has_written(CUBIT_TRUE); |
|---|
| 79 | } |
|---|
| 80 | |
|---|
| 81 | CubitStatus CAVirtualVG::update() |
|---|
| 82 | { |
|---|
| 83 | |
|---|
| 84 | // the owner entity is virtual; put a CAVirtualVG on the underlying entity to represent |
|---|
| 85 | // this entity |
|---|
| 86 | |
|---|
| 87 | if (hasUpdated) return CUBIT_SUCCESS; |
|---|
| 88 | /* |
|---|
| 89 | assert(attrib_owner() != 0); |
|---|
| 90 | |
|---|
| 91 | TopologyEntity *topo_entity = CAST_TO(attrib_owner(), TopologyEntity); |
|---|
| 92 | assert(topo_entity != 0); |
|---|
| 93 | |
|---|
| 94 | DLIList<VirtualEntity*> ve_list; |
|---|
| 95 | VirtualGeometryEngine::instance()->get_VEs(topo_entity, ve_list, CUBIT_FALSE, CUBIT_FALSE); |
|---|
| 96 | |
|---|
| 97 | for( int i = ve_list.size(); i--; ) |
|---|
| 98 | { |
|---|
| 99 | ParasiteEntity *vge = dynamic_cast<ParasiteEntity*>(ve_list.get_and_step()); |
|---|
| 100 | |
|---|
| 101 | if (vge == NULL) { |
|---|
| 102 | // this entity isn't a virtual entity - if this entity doesn't have any virtual |
|---|
| 103 | // entities registered, set delete flag, then exit |
|---|
| 104 | if (numVV == 0 && numVC == 0) |
|---|
| 105 | delete_attrib(CUBIT_TRUE); |
|---|
| 106 | else { |
|---|
| 107 | PRINT_DEBUG_90("Keeping CA_VIRTUAL_VG for %s %d\n", |
|---|
| 108 | attrib_owner()->class_name(), attrib_owner()->id()); |
|---|
| 109 | hasUpdated = CUBIT_TRUE; |
|---|
| 110 | } |
|---|
| 111 | |
|---|
| 112 | continue; |
|---|
| 113 | } |
|---|
| 114 | |
|---|
| 115 | // ok, we have a virtual entity; first get the underlying entity, and a CAVVG for that |
|---|
| 116 | // entity |
|---|
| 117 | BasicTopologyEntity* bte_ptr = vge->bte_bound_to(); |
|---|
| 118 | |
|---|
| 119 | if (!bte_ptr) { |
|---|
| 120 | PRINT_ERROR("Couldn't find underlying BTE for virtual entity %s %d.\n", |
|---|
| 121 | attrib_owner()->class_name(), attrib_owner()->id()); |
|---|
| 122 | return CUBIT_FAILURE; |
|---|
| 123 | } |
|---|
| 124 | |
|---|
| 125 | CAVirtualVG *other_CAVVG = (CAVirtualVG *) bte_ptr->get_cubit_attrib(CA_VIRTUAL_VG); |
|---|
| 126 | |
|---|
| 127 | // if that other CAPVG's written flag is set, it's an old one from a |
|---|
| 128 | // previous write and needs to be reset |
|---|
| 129 | if (other_CAVVG->has_written() == CUBIT_TRUE) { |
|---|
| 130 | other_CAVVG->reset(); |
|---|
| 131 | other_CAVVG->has_written(CUBIT_FALSE); |
|---|
| 132 | } |
|---|
| 133 | |
|---|
| 134 | // now put virtual geometry-specific data on the attribute |
|---|
| 135 | ParasitePoint *vvertex = CAST_TO(vge, ParasitePoint); |
|---|
| 136 | ParasiteCurve *vcurve = CAST_TO(vge, ParasiteCurve); |
|---|
| 137 | if (vvertex != NULL) { |
|---|
| 138 | // put uids and position on ca |
|---|
| 139 | other_CAVVG->add_vvertex(vvertex); |
|---|
| 140 | other_CAVVG->delete_attrib(CUBIT_FALSE); |
|---|
| 141 | } |
|---|
| 142 | |
|---|
| 143 | else if (vcurve != NULL) { |
|---|
| 144 | other_CAVVG->add_vcurve(vcurve); |
|---|
| 145 | other_CAVVG->delete_attrib(CUBIT_FALSE); |
|---|
| 146 | } |
|---|
| 147 | |
|---|
| 148 | else { |
|---|
| 149 | PRINT_ERROR("Shouldn't get here in CAVirtualVG::update.\n"); |
|---|
| 150 | return CUBIT_FAILURE; |
|---|
| 151 | } |
|---|
| 152 | } |
|---|
| 153 | |
|---|
| 154 | hasUpdated = CUBIT_TRUE; |
|---|
| 155 | if (numVV == 0 && numVV == 0) delete_attrib(CUBIT_TRUE); |
|---|
| 156 | |
|---|
| 157 | return CUBIT_SUCCESS; |
|---|
| 158 | */ |
|---|
| 159 | |
|---|
| 160 | delete_attrib(CUBIT_TRUE); |
|---|
| 161 | return CUBIT_SUCCESS; |
|---|
| 162 | } |
|---|
| 163 | |
|---|
| 164 | |
|---|
| 165 | CubitStatus CAVirtualVG::reset() |
|---|
| 166 | { |
|---|
| 167 | //- reset info; called from CAU and also from update! |
|---|
| 168 | numVV = 0; |
|---|
| 169 | numVC = 0; |
|---|
| 170 | //- the number of virtual points and curves contained in this attr |
|---|
| 171 | |
|---|
| 172 | vgUIDs.clean_out(); |
|---|
| 173 | //- unique ids of virtual points and curves contained in this attr |
|---|
| 174 | |
|---|
| 175 | posVector.clean_out(); |
|---|
| 176 | //- position vectors for virtual curves |
|---|
| 177 | |
|---|
| 178 | numVCPoints.clean_out(); |
|---|
| 179 | //- for each virtual curve, the number of virtual points in that curve |
|---|
| 180 | |
|---|
| 181 | return CUBIT_SUCCESS; |
|---|
| 182 | } |
|---|
| 183 | |
|---|
| 184 | CubitSimpleAttrib *CAVirtualVG::cubit_simple_attrib() |
|---|
| 185 | { |
|---|
| 186 | // generate a simple attribute containing the data in this CA |
|---|
| 187 | DLIList<CubitString*> cs_list; |
|---|
| 188 | DLIList<double> d_list; |
|---|
| 189 | DLIList<int> i_list; |
|---|
| 190 | |
|---|
| 191 | // first the string |
|---|
| 192 | cs_list.append(new CubitString(att_internal_name())); |
|---|
| 193 | |
|---|
| 194 | // now the integers |
|---|
| 195 | // numVV, numVC |
|---|
| 196 | i_list.append(numVV); |
|---|
| 197 | i_list.append(numVC); |
|---|
| 198 | |
|---|
| 199 | // vgUIDs |
|---|
| 200 | int i; |
|---|
| 201 | vgUIDs.reset(); |
|---|
| 202 | for (i = vgUIDs.size(); i > 0; i--) |
|---|
| 203 | i_list.append(vgUIDs.get_and_step()); |
|---|
| 204 | |
|---|
| 205 | // numVCPoints |
|---|
| 206 | numVCPoints.reset(); |
|---|
| 207 | for (i = numVCPoints.size(); i > 0; i--) |
|---|
| 208 | i_list.append(numVCPoints.get_and_step()); |
|---|
| 209 | |
|---|
| 210 | // now the doubles |
|---|
| 211 | posVector.reset(); |
|---|
| 212 | for (i = posVector.size(); i > 0; i--) { |
|---|
| 213 | d_list.append(posVector.get()->x()); |
|---|
| 214 | d_list.append(posVector.get()->y()); |
|---|
| 215 | d_list.append(posVector.get_and_step()->z()); |
|---|
| 216 | } |
|---|
| 217 | |
|---|
| 218 | CubitSimpleAttrib* csattrib_ptr = new CubitSimpleAttrib(&cs_list, |
|---|
| 219 | &d_list, |
|---|
| 220 | &i_list); |
|---|
| 221 | |
|---|
| 222 | for( i=cs_list.size(); i--;) delete cs_list.get_and_step(); |
|---|
| 223 | |
|---|
| 224 | return csattrib_ptr; |
|---|
| 225 | } |
|---|
| 226 | |
|---|
| 227 | CubitStatus CAVirtualVG::actuate() |
|---|
| 228 | { |
|---|
| 229 | // actuate this CA |
|---|
| 230 | /* |
|---|
| 231 | // first, actuate the points, with this CA's owner as their owners |
|---|
| 232 | int i, j; |
|---|
| 233 | vgUIDs.reset(); |
|---|
| 234 | posVector.reset(); |
|---|
| 235 | |
|---|
| 236 | DLIList<int> leftover_uids, leftover_vcpoints; |
|---|
| 237 | DLIList<CubitVector*> leftover_posvector; |
|---|
| 238 | int leftover_vvs = 0, leftover_vcs = 0; |
|---|
| 239 | |
|---|
| 240 | DLIList<ParasitePoint*> vpoint_list; |
|---|
| 241 | for (i = 0; i < numVV; i++) { |
|---|
| 242 | CubitVector pos_vec(*posVector.get_and_step()); |
|---|
| 243 | // make the virtual vertex |
|---|
| 244 | BasicTopologyEntity *bte_ptr = CAST_TO(attrib_owner(), BasicTopologyEntity); |
|---|
| 245 | RefVertex *new_vertex = |
|---|
| 246 | VirtualGeometryEngine::instance()->create_VirtualVertex(pos_vec, bte_ptr); |
|---|
| 247 | // add a unique id to it, for referencing later |
|---|
| 248 | TDUniqueId *uid_ptr = new TDUniqueId(new_vertex, vgUIDs.get()); |
|---|
| 249 | CADeferredAttrib::owner_created( new_vertex, vgUIDs.get_and_step() ); |
|---|
| 250 | |
|---|
| 251 | if (new_vertex == NULL) { |
|---|
| 252 | PRINT_WARNING("Problems making new vertex with uid = %d.\n", vgUIDs.prev()); |
|---|
| 253 | leftover_uids.append(vgUIDs.prev()); |
|---|
| 254 | leftover_posvector.append(posVector.prev()); |
|---|
| 255 | leftover_vvs++; |
|---|
| 256 | } |
|---|
| 257 | } |
|---|
| 258 | |
|---|
| 259 | // now actuate CAVVG's on lower order entities |
|---|
| 260 | DLIList<RefEntity*> children; |
|---|
| 261 | attrib_owner()->get_child_ref_entities(children); |
|---|
| 262 | for (i = children.size(); i > 0; i--) { |
|---|
| 263 | children.get_and_step()->actuate_cubit_attrib(CA_VIRTUAL_VG); |
|---|
| 264 | } |
|---|
| 265 | |
|---|
| 266 | // now handle creating virtual curves |
|---|
| 267 | numVCPoints.reset(); |
|---|
| 268 | DLIList<RefEdge*> vcurve_list; |
|---|
| 269 | for (i = 0; i < numVC; i++) { |
|---|
| 270 | // start by grabbing all the stuff off the attribute's lists |
|---|
| 271 | |
|---|
| 272 | int start_uid = vgUIDs.get_and_step(), |
|---|
| 273 | end_uid = vgUIDs.get_and_step(); |
|---|
| 274 | |
|---|
| 275 | // now get the intermediate points; these should all be virtual, and should |
|---|
| 276 | // be in this entity's virtual point list |
|---|
| 277 | DLIList<CubitVector*> vec_list; |
|---|
| 278 | // get the number of virtual points in the list |
|---|
| 279 | int num_points = numVCPoints.get_and_step(); |
|---|
| 280 | for (j = 0; j < num_points; j++) |
|---|
| 281 | vec_list.append(posVector.get_and_step()); |
|---|
| 282 | |
|---|
| 283 | int virtual_curve_uid = vgUIDs.get_and_step(); |
|---|
| 284 | |
|---|
| 285 | // the first two are start and end points, and may not be virtual |
|---|
| 286 | ToolDataUser *tdu = TDUniqueId::find_td_unique_id(start_uid); |
|---|
| 287 | RefVertex *start_vertex = CAST_TO(tdu, RefVertex); |
|---|
| 288 | tdu = TDUniqueId::find_td_unique_id(end_uid); |
|---|
| 289 | RefVertex *end_vertex = CAST_TO(tdu, RefVertex); |
|---|
| 290 | |
|---|
| 291 | if (!start_vertex || !end_vertex) { |
|---|
| 292 | PRINT_DEBUG_90("Couldn't restore virtual curve with uid = %d.\n", |
|---|
| 293 | virtual_curve_uid); |
|---|
| 294 | // cache leftover data for restoring later |
|---|
| 295 | leftover_uids.append(start_uid); |
|---|
| 296 | leftover_uids.append(end_uid); |
|---|
| 297 | leftover_uids.append(virtual_curve_uid); |
|---|
| 298 | leftover_vcpoints.append(num_points); |
|---|
| 299 | leftover_posvector += vec_list; |
|---|
| 300 | leftover_vcs++; |
|---|
| 301 | continue; |
|---|
| 302 | } |
|---|
| 303 | |
|---|
| 304 | // make the virtual curve |
|---|
| 305 | RefEdge *virtual_edge = |
|---|
| 306 | VirtualGeometryEngine::instance()->create_VirtualEdge(start_vertex, |
|---|
| 307 | end_vertex, |
|---|
| 308 | vec_list); |
|---|
| 309 | if (!virtual_edge) { |
|---|
| 310 | PRINT_DEBUG_90("Couldn't restore virtual curve with uid = %d.\n", |
|---|
| 311 | virtual_curve_uid); |
|---|
| 312 | // cache leftover data for restoring later |
|---|
| 313 | leftover_uids.append(start_uid); |
|---|
| 314 | leftover_uids.append(end_uid); |
|---|
| 315 | leftover_uids.append(virtual_curve_uid); |
|---|
| 316 | leftover_vcpoints.append(num_points); |
|---|
| 317 | leftover_posvector += vec_list; |
|---|
| 318 | leftover_vcs++; |
|---|
| 319 | continue; |
|---|
| 320 | } |
|---|
| 321 | |
|---|
| 322 | ParasiteEntity* curve = |
|---|
| 323 | dynamic_cast<ParasiteEntity*>(virtual_edge->get_geometry_entity_ptr()); |
|---|
| 324 | assert(curve != NULL); |
|---|
| 325 | curve->bind_to( dynamic_cast<BasicTopologyEntity*>(attrib_owner()) |
|---|
| 326 | ->get_geometry_entity_ptr()); |
|---|
| 327 | |
|---|
| 328 | // save the curve's unique id |
|---|
| 329 | TDUniqueId *uid_ptr = new TDUniqueId(virtual_edge, virtual_curve_uid); |
|---|
| 330 | |
|---|
| 331 | CADeferredAttrib::owner_created( virtual_edge, virtual_curve_uid ); |
|---|
| 332 | //virtual_edge->actuate_cubit_attrib(CA_VIRTUAL_VG); |
|---|
| 333 | //virtual_edge->actuate_cubit_attrib(CA_PARTITION_VG); |
|---|
| 334 | } |
|---|
| 335 | |
|---|
| 336 | if (0 == leftover_vvs && 0 == leftover_vcs) |
|---|
| 337 | hasActuated = CUBIT_TRUE; |
|---|
| 338 | else { |
|---|
| 339 | // have some leftover data - reset data in this attribute |
|---|
| 340 | numVV = leftover_vvs; |
|---|
| 341 | numVC = leftover_vcs; |
|---|
| 342 | vgUIDs = leftover_uids; |
|---|
| 343 | numVCPoints = leftover_vcpoints; |
|---|
| 344 | posVector = leftover_posvector; |
|---|
| 345 | hasActuated = CUBIT_FALSE; |
|---|
| 346 | |
|---|
| 347 | // now add this attribute to the unactuated list in CADA |
|---|
| 348 | CADeferredAttrib::add_unactuated_ca(this); |
|---|
| 349 | } |
|---|
| 350 | |
|---|
| 351 | // we're done |
|---|
| 352 | return (CUBIT_FALSE == hasActuated ? |
|---|
| 353 | CUBIT_FAILURE : CUBIT_SUCCESS); |
|---|
| 354 | */ return CUBIT_FAILURE; |
|---|
| 355 | } |
|---|
| 356 | |
|---|
| 357 | /* |
|---|
| 358 | void CAVirtualVG::add_vvertex(ParasitePoint *vpoint) |
|---|
| 359 | { |
|---|
| 360 | |
|---|
| 361 | TopologyEntity *vpoint_topo_entity = vpoint->topology_entity(); |
|---|
| 362 | RefVertex *owning_vertex = CAST_TO(vpoint_topo_entity, RefVertex); |
|---|
| 363 | assert(owning_vertex != 0); |
|---|
| 364 | int vvertex_uid = TDUniqueId::get_unique_id(owning_vertex); |
|---|
| 365 | |
|---|
| 366 | //- adds data for this vpoint to this CA |
|---|
| 367 | numVV++; |
|---|
| 368 | vgUIDs.insert_first(vvertex_uid); |
|---|
| 369 | posVector.insert_first(new CubitVector(vpoint->coordinates())); |
|---|
| 370 | } |
|---|
| 371 | */ |
|---|
| 372 | /* |
|---|
| 373 | void CAVirtualVG::add_vcurve(ParasiteCurve *vcurve) |
|---|
| 374 | { |
|---|
| 375 | // need to get list of vpoint uids defining the virtual curve |
|---|
| 376 | // the owner should be a RefEdge |
|---|
| 377 | TopologyEntity *vcurve_topo_entity = vcurve->topology_entity(); |
|---|
| 378 | RefEdge *virtual_edge = CAST_TO(vcurve_topo_entity, RefEdge); |
|---|
| 379 | assert(virtual_edge != 0); |
|---|
| 380 | |
|---|
| 381 | // first get start and end points, and their uids |
|---|
| 382 | DLIList<int> uid_list; |
|---|
| 383 | RefVertex *temp_vertex = virtual_edge->start_vertex(); |
|---|
| 384 | int start_uid = TDUniqueId::get_unique_id(temp_vertex); |
|---|
| 385 | vgUIDs.append(start_uid); |
|---|
| 386 | temp_vertex = virtual_edge->end_vertex(); |
|---|
| 387 | int end_uid = TDUniqueId::get_unique_id(temp_vertex); |
|---|
| 388 | vgUIDs.append(end_uid); |
|---|
| 389 | |
|---|
| 390 | // now get the other points and their uids |
|---|
| 391 | DLIList<ParasitePoint*> vpoint_list; |
|---|
| 392 | vcurve->getSegments(vpoint_list); |
|---|
| 393 | vpoint_list.reset(); |
|---|
| 394 | |
|---|
| 395 | for (int i = vpoint_list.size(); i > 0; i--) { |
|---|
| 396 | ParasitePoint *temp_point = vpoint_list.get_and_step(); |
|---|
| 397 | posVector.append(new CubitVector(temp_point->coordinates())); |
|---|
| 398 | } |
|---|
| 399 | |
|---|
| 400 | int owner_uid = TDUniqueId::get_unique_id(virtual_edge); |
|---|
| 401 | |
|---|
| 402 | //- adds data for this vcurve to this CA |
|---|
| 403 | vgUIDs.append(owner_uid); |
|---|
| 404 | numVCPoints.append(vpoint_list.size()); |
|---|
| 405 | numVC++; |
|---|
| 406 | } |
|---|
| 407 | |
|---|
| 408 | */ |
|---|