// Read one field for a body int InputFront::readBody(emf_ObjectData_X* od) { static UserInterface* gui = theControlCenter->getGui(); strstream strm1, strm2; static ecif_Body_X tx; static ecif_BodyLayer_X tx_layer; static int current_layer_tag = NO_INDEX; static char* current_layer_name = NULL; static IdArray edge_tags; static IdArray edge_group_tags; static IdArray vertex_groups; static IdArray vertex_tags; static int vertex_group_id = 0; static int layer = 0; static bool new_layer = false; static Body* body = NULL; static BodyLayer* bl = NULL; const char* fn = od->field_name; // This is the field id (when it make sense!) int id; LibFront::setNumericData(id, 0); bool isEgf = isEgfInput; bool isEmf = isEmfInput; // New body object started // ======================= if (od->is_object_start) { // Init tx data init_trx_data(tx); init_trx_data(tx_layer); current_layer_tag = NO_INDEX; delete[] current_layer_name; current_layer_name = NULL; bl = NULL; tx.tag = od->object_id; tx.is_checked = geometryIsChecked(); } // --------------- // Body level data // --------------- //-Body name if ( LibFront::in(EMF_NAME, fn) ) { //update_dyna_string(tx.name, (char*) od->data); readName(od, tx.name); } //-Body type else if ( LibFront::in(EMF_TYPE, fn) ) { if ( LibFront::in("Open", (char*) od->data) ) { tx.is_open = true; } else if ( LibFront::in("Bem", (char*) od->data) ) { tx.is_checked = true; tx.is_bem = true; } else if ( LibFront::in("Virtual", (char*) od->data) ) { tx.is_checked = true; tx.is_virtual = true; } } //-Body color else if ( LibFront::in(EMF_COLOR, fn) ) { if ( readColor(od, tx.color) ) { tx.has_color = true; } } //-Body Force id else if ( LibFront::in(EMF_BODY_FORCE, fn) ) { LibFront::setNumericData(tx.body_force_id, 0); } //-Body Parameter id else if ( LibFront::in(EMF_BODY_PARAMETER, fn) ) { LibFront::setNumericData(tx.body_param_id, 0); } //-Equation id else if ( LibFront::in(EMF_EQUATION, fn) ) { LibFront::setNumericData(tx.equation_id, 0); } //-Initial condition else if ( LibFront::in(EMF_INITIAL_CONDITION, fn) ) { LibFront::setNumericData(tx.init_cond_id, 0); } //-Material else if ( LibFront::in(EMF_MATERIAL, fn) ) { LibFront::setNumericData(tx.material_id, 0); } //-Edge groups (for virtual body) // else if ( LibFront::in("Edge Groups", fn) || LibFront::in("Element Groups", fn) ) { int tag; for (int i = 0; i < od->data_length; i++) { LibFront::setNumericData(tag, i); edge_group_tags.push_back(tag); } } // ---------------- // Layer level data // ---------------- //-Layer tag else if ( LibFront::in(EMF_LAYER, fn) || LibFront::in(EMF_LAYER_TAG, fn) ) { LibFront::setNumericData(current_layer_tag, 0); } //-Layer type else if ( LibFront::in(EMF_LAYER_TYPE, fn) ) { if ( LibFront::in("Open", (char*) od->data) ) { tx_layer.is_open = true; } } //-Layer name else if ( LibFront::in(EMF_LAYER_NAME, fn) ) { tx_layer.has_name = true; update_dyna_string(current_layer_name, (char*) od->data); } //-Layer color else if ( LibFront::in(EMF_LAYER_COLOR, fn) ) { if ( readColor(od, tx_layer.color) ) { tx_layer.has_color = true; } } //-Element loop tags // EMF_EDGE_LOOPS (egf-style) // EMF_ELEMENT_LOOPS (emf-style) // else if ( LibFront::in(EMF_EDGE_LOOPS, fn) || LibFront::in(EMF_ELEMENT_LOOPS, fn) ) { new_layer = true; tx_layer.nof_elem_loops = od->data_length; delete[] tx_layer.elem_loop_tags; tx_layer.elem_loop_tags = NULL; if ( tx_layer.nof_elem_loops > 0 ) { tx_layer.elem_loop_tags = new int[tx_layer.nof_elem_loops]; } for (int i = 0; i < od->data_length; i++) { LibFront::setNumericData(tx_layer.elem_loop_tags[i], i); } } //-Body vertices as tags (short egf-style) // else if ( LibFront::in(EMF_VERTICES, fn) || LibFront::in(EMF_POLYGON, fn) ) { new_layer = true; vertex_group_id++; int tag, first_tag; for (int i = 0; i < od->data_length; i++) { LibFront::setNumericData(tag, i); vertex_groups.push_back(vertex_group_id); vertex_tags.push_back(tag); if ( i == 0) { first_tag = tag; } } // Close the loop if given as open! if ( tag != first_tag ) { vertex_tags.push_back(first_tag); vertex_groups.push_back(vertex_group_id); } } //-Edge tags // else if ( LibFront::in(EMF_EDGES, fn) ) { new_layer = true; int tag; for (int i = 0; i < od->data_length; i++) { LibFront::setNumericData(tag, i); edge_tags.push_back(tag); } } //-Grid parameter ids // else if ( LibFront::in(EMF_GRID_PARAMETER_IDS, fn) ) { tx_layer.nof_grid_param_ids = od->data_length; tx_layer.grid_param_ids = new int[od->data_length]; for (int i = 0; i < od->data_length; i++) { LibFront::setNumericData(tx_layer.grid_param_ids[i], i); } if ( bl != NULL ) { bl->setGridParameterIds(od->data_length, tx_layer.grid_param_ids); } } //-Excluded mesh indices // else if ( LibFront::in(EMF_EXCLUDED_MESH_INDICES, fn) ) { tx_layer.nof_excluded_meshes = od->data_length; tx_layer.excluded_mesh_indices = new int[od->data_length]; for (int i = 0; i < od->data_length; i++) { LibFront::setNumericData(tx_layer.excluded_mesh_indices[i], i); } if ( bl != NULL ) { bl->setExcludedMeshData(od->data_length, tx_layer.excluded_mesh_indices); } } //-Grid parameter mesh indices // else if ( LibFront::in(EMF_GRID_PARAMETER_MESH_INDICES, fn) ) { tx_layer.grid_param_mesh_indices = new int[od->data_length]; for (int i = 0; i < od->data_length; i++) { LibFront::setNumericData(tx_layer.grid_param_mesh_indices[i], i); } if ( bl != NULL ) { bl->setGridParameterMeshIndices(od->data_length, tx_layer.grid_param_mesh_indices); } } //-Unknown field // else { unknownFieldMsg(od, IS_FATAL); } //----Body and the first layer or some additional layer is ready // if ( new_layer ) { // First layer --> a new body if ( layer == 0 ) { model->addBody(tx); body = model->getBodyByTag(tx.tag); } // Add new layer to the body // ========================= if ( body != NULL ) { tx_layer.tag = current_layer_tag; update_dyna_string(tx_layer.name, current_layer_name); tx_layer.body_id = body->Id(); tx_layer.body_tag = body->Tag(); body->addLayer(tx_layer); body->addElementLoopTags(layer, tx_layer.nof_elem_loops, tx_layer.elem_loop_tags); int nof_edges = edge_tags.size(); int nof_vertices = vertex_tags.size(); // Store edges as pending elements (will be resolved later when // the whole file is read if ( nof_edges > 0 ) { for (int i = 0; i < nof_edges; i++) { body->addPendingElement(layer, edge_tags[i]); } edge_tags.clear(); } // Store vertices as pending start-end points (will be resolved later when // the whole file is read if ( nof_vertices > 0 ) { for (int i = 0; i < nof_vertices; i++) { body->addPendingVertex(layer, vertex_groups[i], vertex_tags[i]); } vertex_groups.clear(); vertex_tags.clear(); vertex_group_id = 0; } bl = body->getLayer(layer); new_layer = false; layer++; init_trx_data(tx_layer); } } // Reset for the next body // if ( od->is_object_end ) { int nof_edge_groups = edge_group_tags.size(); if ( !tx.is_virtual && nof_edge_groups > 0 ) { strm1 << "***ERROR in definition for Body " << tx.tag << ends; strm2 << "Edge Groups are valid only for virtual bodies (Type=virtual)" << ends; gui->showMsg(strm1.str()); gui->showMsg(strm2.str()); goto error; } if ( !tx.is_virtual && body == NULL ) { strm1 << "***ERROR in definition for Body " << tx.tag << ends; strm2 << "No geometry defined for the body!" << ends; gui->showMsg(strm1.str()); gui->showMsg(strm2.str()); goto error; } if ( tx.is_virtual && body == NULL && nof_edge_groups == 0) { strm1 << "***ERROR in definition for Body " << tx.tag << ends; strm2 << "No edge groups defined for a virtual body!" << ends; gui->showMsg(strm1.str()); gui->showMsg(strm2.str()); goto error; } // If body not yet created (a virtual body) // if ( body == NULL ) { model->addBody(tx); body = model->getBodyByTag(tx.tag); } // Add possible pending group tags // if ( body != NULL && nof_edge_groups > 0 ) { for (int i = 0; i < nof_edge_groups; i++) { body->addElementGroupTag(edge_group_tags[i]); } edge_group_tags.clear(); } body = NULL; bl = NULL; layer = 0; new_layer = false; reset_trx_data(tx); } return isOk; // Error error: reset_trx_data(tx); return notOk; }
// Read one field for a face int InputFront::readFace(emf_ObjectData_X* od) { static UserInterface* gui = theControlCenter->getGui(); strstream strm1; strstream strm2; int i; int rc = isOk; static IdArray edge_tags; static IdArray vertex_tags; const char* fn = od->field_name; static ecif_Element_X tx; //---New element is started if (od->is_object_start) { // Init tx data init_trx_data(tx); tx.tag = od->object_id; tx.bndr_tag = NO_INDEX; tx.tplg_type = ECIF_FACE; } // Parse fields // ============ //-No data for the element (but id) if ( od->field_name_length == 0) { ; // Do nothing! } //-Boundary tag else if ( LibFront::in(EMF_BOUNDARY_TAG, fn) ) { LibFront::setNumericData(tx.bndr_tag, 0); } //-Boundary Condition id else if ( LibFront::in(EMF_BOUNDARY_CONDITION, fn) ) { LibFront::setNumericData(tx.bndr_cond_id, 0); } //-Boundary Parameter id else if ( LibFront::in(EMF_BOUNDARY_PARAMETER, fn) ) { LibFront::setNumericData(tx.bndr_param_id, 0); } //-Boundary name else if ( LibFront::in(EMF_NAME, fn) ) { //update_dyna_string(tx.name, (char*) od->data); readName(od, tx.name); } //-Edge tags else if ( LibFront::in(EMF_EDGES, fn) ) { int tag; for (int i = 0; i < od->data_length; i++) { LibFront::setNumericData(tag, i); edge_tags.push_back(tag); } } //-Vertex tags // NOTE: This is for mesh bodies which may not have any edges // but we still want to store some vertices in the model // else if ( LibFront::in(EMF_VERTICES, fn) ) { int tag; for (int i = 0; i < od->data_length; i++) { LibFront::setNumericData(tag, i); vertex_tags.push_back(tag); } } //-Grid parameter ids else if ( LibFront::in("Gridh Ids", fn) ) { tx.nof_gridh_ids = od->data_length; tx.gridh_ids = new int[od->data_length]; for (int i = 0; i < od->data_length; i++) { LibFront::setNumericData(tx.gridh_ids[i], i); } } //-GridH mesh indices else if ( LibFront::in("Gridh Mesh Indices", fn) ) { tx.gridh_mesh_indices = new int[od->data_length]; for (int i = 0; i < od->data_length; i++) { LibFront::setNumericData(tx.gridh_mesh_indices[i], i); } } if (rc != isOk) return !isOk; //----Element is ready if ( od->is_object_end ) { model->addBodyElement(tx); // Add possible pending edge definitions // into the created face bodyelement BodyElement* be = model->getBodyElementByTag(OT_FACE, tx.tag); if ( be != NULL ) { // Store edges as pending elements (will be resolved later when // the whole file is read int nof_edges = edge_tags.size(); if ( nof_edges > 0 ) { for (i = 0; i < nof_edges; i++) be->addPendingEdge(edge_tags[i]); } edge_tags.clear(); // Store vertices as pending elements (will be resolved later when // the whole file is read int nof_vertices = vertex_tags.size(); if ( nof_vertices > 0 ) { for (i = 0; i < nof_vertices; i++) be->addPendingVertex(vertex_tags[i]); } vertex_tags.clear(); } reset_trx_data(tx); } return isOk; }