gm_list2obj.cpp

来自「算断裂的」· C++ 代码 · 共 575 行 · 第 1/2 页

CPP
575
字号
// ------------------------------------------------------------------// gm_list2obj.cpp//// This file contains the routine for converting a brep or simpcomplex// to a Tcl/Tk list.// ------------------------------------------------------------------// Copyright (c) 1999 by Cornell University.  All rights reserved.// // See the accompanying file 'Copyright' for authorship information,// the terms of the license governing this software, and disclaimers// concerning this software.// ------------------------------------------------------------------// This file is part of the QMG software.  // Version 2.0 of QMG, release date September 3, 1999.// ------------------------------------------------------------------extern "C" {#include "tcl.h"}#include "qbrep_constr.h"#include "qsimpcomp.h"#include "qerr.h"namespace QMG {  // ------------------------------------------------------------------  // see objectstream.cpp  extern void init_faceselect_order(vector<unsigned int>& order, int gdim);  extern string get_element_typename(int gdim, int ord);  namespace FrontEnd {    // See qmg_init.cpp    extern Tcl_Obj* new_simpcomp_obj(Cptc_MshDesc* mesh);    extern Tcl_Obj* new_brep_obj(Cptc_GeomDesc* geo);  }}namespace {  using namespace QMG;  void throw_tcl_error(Tcl_Interp* interp) {    throw_error(string(interp -> result));  }  // ------------------------------------------------------------------  // get_tcl_string, get_tcl_int, get_tcl_double, get_tcl_list_length  // The following local routines are for extracting various data  // types from a Tcl list.  string get_tcl_string(Tcl_Interp* interp,    Tcl_Obj* list,    int listindex) {    Tcl_Obj* subobj;    int returncode = Tcl_ListObjIndex(interp, list, listindex, &subobj);    if (returncode != TCL_OK)      throw_tcl_error(interp);    int length1;    char* data = Tcl_GetStringFromObj(subobj, &length1);    return string(data, length1);  }  int get_tcl_int(Tcl_Interp* interp,    Tcl_Obj* list,    int listindex) {    Tcl_Obj* subobj;    int returncode = Tcl_ListObjIndex(interp, list, listindex, &subobj);    if (returncode != TCL_OK)      throw_tcl_error(interp);    int val;    returncode = Tcl_GetIntFromObj(interp, subobj,  &val);    if (returncode != TCL_OK)      throw_tcl_error(interp);    return val;  }  double get_tcl_double(Tcl_Interp* interp,    Tcl_Obj* list,    int listindex) {    Tcl_Obj* subobj;    int returncode = Tcl_ListObjIndex(interp, list, listindex, &subobj);    if (returncode != TCL_OK)      throw_tcl_error(interp);    double val;    returncode = Tcl_GetDoubleFromObj(interp, subobj,  &val);    if (returncode != TCL_OK)      throw_tcl_error(interp);    return val;  }  Tcl_Obj* get_tcl_obj(Tcl_Interp* interp,    Tcl_Obj* list,    int listindex) {    Tcl_Obj* subobj;    int returncode = Tcl_ListObjIndex(interp, list, listindex, &subobj);    if (returncode != TCL_OK)      throw_tcl_error(interp);    return subobj;  }  int get_tcl_list_length(Tcl_Interp* interp,    Tcl_Obj* list) {    int length1;    int returncode = Tcl_ListObjLength(interp, list, &length1);    if (returncode != TCL_OK)      throw_tcl_error(interp);    return length1;  }  // This is a function object used for a map whose key is a string.  // We want to compare strings disregarding case.  class Nocase {  public:    bool operator() (const string& x, const string& y) const {      return compare_nocase(x,y) < 0;    }  };  // ------------------------------------------------------------------  // Class Face_lookup_map_type  // This is a map from strings to fspecs.  // It generates errors upon duplication, and so on.  It is used  // for keeping track of face names when a brep is read in.  class Face_lookup_map_type {  private:    typedef map <string, Brep::Face_Spec, Nocase> Actual_Map_type;    Actual_Map_type actual_map_;  public:    Face_lookup_map_type() { }    ~Face_lookup_map_type() { }    void insert(const string& facename, const Brep::Face_Spec& fspec) {      const char* tmp = facename.c_str();      string tmp2 = string(tmp);      pair<Actual_Map_type::iterator, bool> rval =         actual_map_.insert(pair<string,Brep::Face_Spec>(tmp2, fspec));      if (!rval.second) {        string errmsg = string("Duplicate face name ") + facename          + " occurs in brep";        throw_error(errmsg);      }      return;    }    Brep::Face_Spec find(const string& facename) const {      Actual_Map_type::const_iterator it =        actual_map_.find(facename);      if (it == actual_map_.end()) {        string errmsg = string("Face ") + facename  +           " listed as a subface but is not found";        throw_error(errmsg);      }      return it -> second;    }  };  // ------------------------------------------------------------------  // This routine converts a list to a brep.  Brep_Under_Construction get_brep_from_list(Tcl_Interp* interp,    Tcl_Obj* olist) {    Error_Message errorinfo;    errorinfo.set_string("Error detected while processing header information");        int di = get_tcl_int(interp, olist, 2);    if (di < 2 || di > 3)      throw_error("Embedded dimension out of range");    int gdim = get_tcl_int(interp, olist, 1);    if (gdim > di || gdim < 0)      throw_error("Intrinsic dimension out of range");    int listlen = get_tcl_list_length(interp, olist);    if (listlen != 6 + gdim)       throw_error("Wrong number of entries in list (should be 6+intrinsic dim)");    Brep_Under_Construction g(gdim, di);    // convert brep property values    {          errorinfo.set_string("Error detected while processing brep's property-value pairs");      Tcl_Obj* pvlist = get_tcl_obj(interp, olist, 3);      int pvlen = get_tcl_list_length(interp, pvlist);      if (pvlen % 2)        throw_error("Property-value list must have an even number of entries");      Brep_Under_Construction::Propval_inserter pvi(g);      for (int i = 0; i < pvlen; i += 2) {        string prop = get_tcl_string(interp, pvlist, i);        string val = get_tcl_string(interp, pvlist, i+1);        pvi.insert_propval(prop,val);      }    }    // convert control points    {      errorinfo.set_string("Error detected while processing brep's control points");      Tcl_Obj* cplist = get_tcl_obj(interp, olist, 4);      int cplen = get_tcl_list_length(interp, cplist);      if (cplen % di)        throw_error("Control point list length must be divisible by embedded dim");      Brep_Under_Construction::Control_point_inserter cpi(g);      vector<Real> coord(di);      for (int i = 0; i < cplen; i += di) {        for (int j = 0; j < di; ++j)          coord[j] = get_tcl_double(interp, cplist, i + j);        cpi.insert_control_point(coord);      }    }    // convert faces    Face_lookup_map_type facemap;    for (int dim = 0; dim <= gdim; ++dim) {      {        ostringstream os;        os << "Error detected while processing topological faces of dimension " << dim;        errorinfo.set_string(os.str());      }      Tcl_Obj* dimlist = get_tcl_obj(interp, olist, 5 + dim);      int dimlen = get_tcl_list_length(interp, dimlist);      if (dimlen % 5)        throw_error("List for topological faces must be divisible by 5");      Brep_Under_Construction::Top_face_inserter tfi(g, dim);      for (int faceind = 0; faceind < dimlen / 5; ++faceind) {        // convert face name        string facename = get_tcl_string(interp, dimlist, faceind * 5);        Brep::Face_Spec fspec = tfi.insert_top_face(facename);        facemap.insert(facename, fspec);        Error_Message error_info2;        {          ostringstream os;          os << "Error detected while processing property-value pairs of face " << facename;          error_info2.set_string(os.str());          Tcl_Obj* pvlist = get_tcl_obj(interp, dimlist, faceind * 5 + 1);          int pvlen = get_tcl_list_length(interp, pvlist);          if (pvlen % 2)            throw_error("Property-value list length must be even");          Brep_Under_Construction::Top_face_propval_inserter tfpi(g, fspec);          for (int i = 0; i < pvlen; i += 2) {            string prop = get_tcl_string(interp, pvlist, i);            string val = get_tcl_string(interp, pvlist, i + 1);            tfpi.insert_propval(prop,val);          }        }        // convert child faces        {          ostringstream os;          os << "Error detected while processing bounding subfaces of face " << facename;          error_info2.set_string(os.str());          Tcl_Obj* chlist = get_tcl_obj(interp, dimlist, faceind * 5 + 2);          int chlen = get_tcl_list_length(interp, chlist);          Brep_Under_Construction::Top_face_bound_inserter tfbi(g, fspec);          for (int i = 0; i < chlen; ++i) {            string subfacename = get_tcl_string(interp, chlist, i);            int ori = 2;            if (subfacename[0] == '+') {              ori = 0;              subfacename = subfacename.substr(1, subfacename.length() - 1);            }            else if (subfacename[0] == '-') {              ori = 1;              subfacename = subfacename.substr(1, subfacename.length() - 1);            }                    Brep::Face_Spec subfspec = facemap.find(subfacename);

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?