Пример #1
0
int MolCoord::appendAtomScrHelper(MolAtomPtr pAtom, const LString &ch,
				  ResidIndex resid, const LString &resn)
{
  qlib::uid_t nuid = pAtom->getParentUID();
  if (nuid!=qlib::invalid_uid) {
    // pAtom has been already belonged to other mol
    // --> ERROR!!
    MB_DPRINTLN("MolCoord.appendAtom> ERROR, pAtom already belongs to mol %d ().", nuid);
    return -1;
  }

  pAtom->setParentUID(getUID());
  pAtom->setChainName(ch);
  pAtom->setResIndex(resid);

  if (resn.isEmpty()) {
    // res name is determined by chain name and resindex
    MolResiduePtr pRes = getResidue(ch, resid);
    if (pRes.isnull()) {
      // ERROR!! cannot determine the residue to append to
      return -1;
    }
    pAtom->setResName(pRes->getName());
  }
  else {
    pAtom->setResName(resn);
  }

  return appendAtom(pAtom);
}
Пример #2
0
void SceneXMLReader::procDataChunks(qlib::LDom2InStream &ois, LDom2Node *pNode)
{
  for (;;) {
    try {
      LString chunkid = ois.getNextDataChunkID();
      if (chunkid.isEmpty())
        return;
      MB_DPRINTLN("SceneXMLReader> load datachunk: %s", chunkid.c_str());

      //LDataSrcContainer *pCnt = findChunkObj(chunkid);
      LDataSrcContainer *pCnt = ois.findChunkObj(chunkid);
      if (pCnt==NULL) {
        LOG_DPRINTLN("SceneXMLReader> data container for chunk %s not found.", chunkid.c_str());
        return;
      }

      qlib::InStream *pin = ois.getNextChunkStream();
      pCnt->readFromStream(*pin);
      ois.closeChunkStream(pin);
      
    }
    catch (qlib::LException &e) {
      pNode->appendErrMsg("SceneXML> Load object error (ignored).");
      pNode->appendErrMsg("SceneXML> Reason: %s", e.getMsg().c_str());
    }
    catch (...) {
      pNode->appendErrMsg("SceneXML> Load object error (ignored).");
      pNode->appendErrMsg("SceneXML> Reason: unknown");
    }
  }
}
Пример #3
0
/// Convert from (persistent) string representation to aid
int MolCoord::fromStrAID(const LString &strid) const
{
  if (!m_reAid.match(strid)) {
    LOG_DPRINTLN("MolCoord> Invalid aid strid=%s (re match failed)", strid.c_str());
    return -1;
  }

  // text type aid
  int nsc = m_reAid.getSubstrCount();
  if (nsc<4) {
    LOG_DPRINTLN("MolCoord> Invalid aid strid=%s", strid.c_str());
    return -1;
  }
  //elem.setAtomID(-1);
  LString sChainName = m_reAid.getSubstr(1);
  LString sResInd = m_reAid.getSubstr(2);
  ResidIndex nResInd;
  if (!sResInd.toInt(&nResInd.first)) {
    LOG_DPRINTLN("MolCoord> Invalid aid resid value=%s", sResInd.c_str());
    return -1;
  }
  LString sInsCode = m_reAid.getSubstr(3);
  if (sInsCode.isEmpty())
    nResInd.second = '\0';
  else
    nResInd.second = sInsCode.getAt(0);
  LString sAtomName = m_reAid.getSubstr(4);
  char cAltLoc = '\0';
  if (nsc>6) {
    LString sAltLoc = m_reAid.getSubstr(6);
    if (!sAltLoc.isEmpty())
      cAltLoc = sAltLoc.getAt(0);
  }

  MolAtomPtr pAtom = getAtom(sChainName, nResInd, sAtomName, cAltLoc);
  if (pAtom.isnull()) {
    LOG_DPRINTLN("MolCoord> fromStrAID/ atom <%s %s %s %c> not found in %s",
		 sChainName.c_str(), nResInd.toString().c_str(), sAtomName.c_str(),
		 cAltLoc=='\0'?' ':cAltLoc,
		 getName().c_str());
    return -1;
  }

  return pAtom->getID();
}
Пример #4
0
// static
LString  LDataSrcContainer::selectSrcAltSrc(const LString &src,
                                            const LString &altsrc,
                                            const LString &base_path,
                                            bool &rbReadFromAltSrc)
{
  bool bReadFromAltSrc = false;

  LString abs_path;

  // First, try to convert "src" to abs path
  if (isAbsolutePath(src))
    abs_path = src;
  else if (!base_path.isEmpty())
    abs_path = makeAbsolutePath(src, base_path);
  
  if (abs_path.isEmpty() || !isFileReadable(abs_path)) {
    // Second, try to convert "altsrc" to abs path
    if (altsrc.isEmpty()) {
      // empty alt src --> no src path info available (ERROR)
      LString msg = LString::format("Fatal error, cannot open file: \"%s\"",
                                    abs_path.c_str());
      LOG_DPRINTLN("SceneXML> %s", msg.c_str());
      MB_THROW(qlib::IOException, msg);
      return LString();
    }

    if (isAbsolutePath(altsrc))
      abs_path = altsrc;
    else if (!base_path.isEmpty())
      abs_path = makeAbsolutePath(altsrc, base_path);

    if (!isFileReadable(abs_path)) {
      LString msg = LString::format("Fatal error, cannot open file: \"%s\"",
                                    abs_path.c_str());
      LOG_DPRINTLN("SceneXML> %s", msg.c_str());
      MB_THROW(qlib::IOException, msg);
      return LString();
    }
    // read from alt_src property (abs_path==alt_src)
    bReadFromAltSrc = true;
  }

  rbReadFromAltSrc = bReadFromAltSrc;
  return abs_path;
}
Пример #5
0
/** module initialization */
bool TopparManager::load()
{
  SysConfig *pconf = SysConfig::getInstance();
  SysConfig::Section *psec = pconf->getSection("toppar");
  bool bOK = false;
  if (psec!=NULL) {
    SysConfig::const_iterator iter = psec->begin();
    iter=psec->findName(iter, "toppar_file");
    for (; iter!=psec->end(); iter=psec->findName(++iter, "toppar_file")) {
      SysConfig::Section *pchild = *iter;
      LString val = pchild->getStringData();
      if (val.isEmpty()) continue;;

      int cpos = val.indexOf(':');
      if (cpos<0) continue;
      LString type = val.substr(0, cpos);
      LString fnam = val.substr(cpos+1);
      fnam = pconf->convPathName(fnam);

      /*if (!fnam.startsWith(MB_PATH_SEPARATOR)) {
        LString config_dir = pconf->get("config_dir");
        fnam = config_dir + MB_PATH_SEPARATOR + fnam;
      }*/
      
      if (readPrmTop(fnam, type))
        bOK = true;
    }
  }

  if (!bOK) {
    //
    // read from default directory with default type/filename
    //
    LString type("cns");
    LString fnam;

    for ( ;; ) {
      fnam = "queptl.prm";
      if (!readPrmTop(fnam, type))
        break;

      fnam = "queptl.top";
      if (!readPrmTop(fnam, type))
        break;

      fnam = "queptl.lin";
      if (!readPrmTop(fnam, type))
        break;

      return true;
    }
    LOG_DPRINTLN("Toppar> warning: no mol topology/parameter files is loaded.");
  }

  // m_pTopoDB->dump();
  return true;
}
Пример #6
0
 BOOST_FOREACH (const LString &brush, uniqset) {
   LString def = pSM->getMaterial(brush, "warabi_brush");
   if (!def.isEmpty()) {
     def = def.trim(" \r\n\t");
     ps.formatln("Brush \"%s\" : {", brush.c_str());
     ps.println(def);
     ps.println("}");
     bWritten = true;
   }
 }
Пример #7
0
LString LString::operator +(const LString &o) const {
    if (this->isEmpty()) return o;
    if (o.isEmpty()) return *this;

    LStringData *newStr = LStringData::create(this->length() + o.length() + 1);
    std::copy(this->mData->begin(), this->mData->end(), newStr->begin());
    std::copy(o.mData->begin(), o.mData->end(), newStr->begin() + this->length());

    newStr->mSize = this->length() + o.length();
    return LString(newStr);
}
Пример #8
0
void LDOMObjOutStream::writeListElemObject(const LScriptable *pScr)
{
  LString clsname = getTypeName(pScr);
  if (clsname.isEmpty())
    return;

  m_data.pushListElem();
  m_data.setTypeName(clsname);
  writeObject(pScr);
  m_data.popNode();
}
Пример #9
0
SelCommand::SelCommand(const LString &psz)
  : m_pSelRoot(NULL)
{
  if (psz.isEmpty()) return;
  bool res = compile(psz);
  if (!res) {
    // TO DO: error handling/throw exception
    MB_DPRINTLN("Cannot initialize SelCommand with %s", psz.c_str());
    return;
  }
  m_origcmd = psz;
}
Пример #10
0
  LString readStr(int start, int end) {
    if (m_recbuf.isEmpty()) return LString();

    start --; end --;
    if (end >= m_recbuf.length())
      end = m_recbuf.length()-1;
    if (start<0)
      start = 0;
    if (start>end)
      start = end;

    return m_recbuf.substr(start, end-start+1);
  }
Пример #11
0
bool Selection::equals(Selection *pSel) const
{
  LString tmp = toString();

  if (pSel==NULL) {
    if (tmp.isEmpty())
      return true;
    else
      return false;
  }

  return (tmp.equals(pSel->toString()));
}
Пример #12
0
bool SelCommand::compile(const LString &com, qlib::uid_t nCtxtID /*= qlib::invalid_uid*/)
{
  if (m_pSelRoot!=NULL)
    delete m_pSelRoot;

  if (com.isEmpty())
    return true;

  SelSuperNode *pnode = NULL;

  // Enter new context
  qsys::AutoStyleCtxt ctxt(nCtxtID);
  pnode = SelCompiler::getInstance()->compile(com);
  
  if (pnode==NULL) {
    return false;
  }

  m_pSelRoot = pnode;
  m_origcmd = com;
  //m_pCurClient = NULL;
  return true;
}
Пример #13
0
/// load from icc file
void CmsXform::loadIccFile(const LString &path)
{
#ifdef HAVE_LCMS2_H
  m_pimpl->cleanup();
  cmsHPROFILE hInProf = cmsCreate_sRGBProfile();
  cmsHPROFILE hOutProf = cmsOpenProfileFromFile(path, "r");
  if (hOutProf==NULL) {
    MB_THROW(qlib::IOException, "cannot open icc file: "+path);
    return;
  }

  int nProofIntent = m_nIntent;
  
  m_info = LString();
  LString info;

  info = GetProfileInfo(hOutProf, cmsInfoDescription);
  info = info.chomp();
  if (!info.isEmpty())
    m_info += info+"\n";

  info = GetProfileInfo(hOutProf, cmsInfoManufacturer);
  info = info.chomp();
  if (!info.isEmpty())
    m_info += info+"\n";

  info = GetProfileInfo(hOutProf, cmsInfoModel);
  info = info.chomp();
  if (!info.isEmpty())
    m_info += info+"\n";

  info = GetProfileInfo(hOutProf, cmsInfoCopyright);
  info = info.chomp();
  if (!info.isEmpty())
    m_info += info+"\n";

#ifdef USEPROOFING
  cmsUInt16Number alarm[cmsMAXCHANNELS];
  for (int i=0; i < cmsMAXCHANNELS; i++)
    alarm[i] = 0xFFFF;
  cmsSetAlarmCodes(alarm);

  m_pimpl->m_hTr = cmsCreateProofingTransform(hInProf,
                                              TYPE_RGB_8,
                                              hInProf,
                                              TYPE_RGB_8,
                                              hOutProf,
                                              nProofIntent,
                                              nProofIntent,
                                              //INTENT_ABSOLUTE_COLORIMETRIC,
                                              //INTENT_PERCEPTUAL,
                                              cmsFLAGS_SOFTPROOFING);
  
  cmsHPROFILE hNullProf = cmsCreateNULLProfile();
  m_pimpl->m_hTrChk = cmsCreateProofingTransform(hInProf,
                                                 TYPE_RGB_DBL,
                                                 hNullProf,
                                                 TYPE_GRAY_DBL,
                                                 hOutProf,
                                                 nProofIntent,
                                                 nProofIntent,
                                                 cmsFLAGS_SOFTPROOFING|cmsFLAGS_GAMUTCHECK|cmsFLAGS_NOCACHE);
  cmsCloseProfile(hNullProf);

#else
  m_pimpl->m_hTr1 = cmsCreateTransform(hInProf,
                                       TYPE_RGB_8,
                                       hOutProf,
                                       //TYPE_CMYK_8,
                                       TYPE_CMYK_FLT,
                                       nProofIntent, 0);
  m_pimpl->m_hTr2 = cmsCreateTransform(hOutProf,
                                       //TYPE_CMYK_8,
                                       TYPE_CMYK_FLT,
                                       hInProf,
                                       TYPE_RGB_8,
                                       //INTENT_ABSOLUTE_COLORIMETRIC,
                                       INTENT_PERCEPTUAL,
                                       0);

#endif

  cmsCloseProfile(hInProf);
  cmsCloseProfile(hOutProf);
#endif
  return;
}
Пример #14
0
/// read one MOL entry from stream
bool MOL2MolReader::readMol(qlib::LineStream &lin, bool bskip)
{
  LString sline;
  std::vector<LString> slist;
  
  for (;;) {
    sline = lin.readLine().chomp();
    if (sline.isEmpty() && !lin.ready())
      return false; // EOF
  
    if (sline.equals("@<TRIPOS>MOLECULE")) {
      break;
    }
  }

  // mol_name
  LString cmpd_name = lin.readLine().trim(" \t\r\n");
  if (cmpd_name.isEmpty())
    cmpd_name = "_"; // XXX

  // molecule info
  sline = lin.readLine().chomp();
  split(sline, ' ', std::back_inserter(slist));
  if (slist.size()<1) {
    MB_THROW(MOL2FormatException, "Invalid atom info record");
  }
  int natoms;
  if (!slist[0].toInt(&natoms)) {
    MB_THROW(MOL2FormatException, "Invalid atom info record");
  }
  int nbonds=0;
  if (slist.size()>1) {
    if (!slist[1].toInt(&nbonds)) {
      MB_THROW(MOL2FormatException, "Invalid atom info record");
    }
  }

  // mol_type
  LString mol_type = lin.readLine().chomp();
  bool bApplyTopo = false;
  if (mol_type.equals("PROTEIN") ||
      mol_type.equals("NUCLEIC_ACID"))
    bApplyTopo = true;    

  // Ignore charge_type
  // Ignore mol_comment

  // Search ATOM record
  for (;;) {
    sline = lin.readLine().chomp();
    if (sline.isEmpty() && !lin.ready())
      return false; // EOF
  
    if (sline.equals("@<TRIPOS>ATOM")) {
      break;
    }
  }

  int i, idot, iresid, naid, ind, prev_resid;
  ElemID eleid;
  double xx, yy, zz;
  LString aname, atype, satom, res_name;
  std::map<int,int> atommap;
  std::map<LString, int> aname_counts;
  std::map<LString, int>::iterator an_iter;

  // XXXX
  prev_resid = -999999;
  
  for (i=0; i<natoms; ++i) {
    //LOG_DPRINTLN("i=%d, natoms=%d", i, natoms);

    sline = lin.readLine().chomp();
    slist.clear();
    split(sline, ' ', std::back_inserter(slist));
    if (slist.size()<8) {
      MB_THROW(MOL2FormatException, "Invalid atom record");
    }

    if (!slist[0].toInt(&ind)) {
      MB_THROW(MOL2FormatException, "Invalid atom ID record");
    }

    aname = slist[1];
    an_iter = aname_counts.find(aname);
    if (an_iter==aname_counts.end()) {
      aname_counts.insert(std::pair<LString, int>(aname, 1));
    }
    else {
      an_iter->second = an_iter->second + 1;
      aname = LString::format("%d%s", an_iter->second, aname.c_str());
    }

    if (!slist[2].toRealNum(&xx)) {
      MB_THROW(MOL2FormatException, "Invalid atom coord record");
    }
    if (!slist[3].toRealNum(&yy)) {
      MB_THROW(MOL2FormatException, "Invalid atom coord record");
    }
    if (!slist[4].toRealNum(&zz)) {
      MB_THROW(MOL2FormatException, "Invalid atom coord record");
    }

    atype = slist[5];

    satom = "";
    idot = atype.indexOf('.');
    if (idot<0) {
      satom = atype;
    }
    else if (idot>0) {
      satom = atype.substr(0, idot);
    }
    else {
      MB_THROW(MOL2FormatException, "Invalid SYBYL atom type");
    }

    iresid = 0;
    if (!slist[6].toInt(&iresid)) {
      MB_THROW(MOL2FormatException, "Invalid atom resid record");
    }

    res_name = slist[7];
    if (res_name.equals("<0>"))
      res_name = cmpd_name;

    if (bApplyTopo) {
      // protein or nucleic acid
      // strip residue number from res_name
      int ntmp;
      if (res_name.substr(3).toInt(&ntmp)) {
	res_name = res_name.substr(0, 3);
	iresid = ntmp;
      }

      if (iresid!=prev_resid)
	// residue is changed --> clear atom name count
	aname_counts.clear();
    }

    eleid = ElemSym::str2SymID(satom);

    // LOG_DPRINTLN("Atom: %f, %f, %f, <%s> %d", xx, yy, zz, aname.c_str(), eleid);

    if (!bskip) {
      MolAtomPtr pAtom = MolAtomPtr(MB_NEW MolAtom());
      pAtom->setParentUID(m_pMol->getUID());
      pAtom->setName(aname);
      pAtom->setElement(eleid);

      pAtom->setChainName(m_sCurrChName);
      pAtom->setResIndex(iresid);
      pAtom->setResName(res_name);
    
      pAtom->setPos(Vector4D(xx,yy,zz));
      pAtom->setBfac(0.0);
      pAtom->setOcc(1.0);
    
      naid = m_pMol->appendAtom(pAtom);
      if (naid<0)
	MB_THROW(MOL2FormatException, "appendAtom() failed");

      atommap.insert(std::pair<int,int>(ind, naid));
      m_nReadAtoms++;
    }

    prev_resid = iresid;

  }
  
  // Search BOND record
  for (;;) {
    sline = lin.readLine().chomp();
    if (sline.isEmpty() && !lin.ready())
      return false; // EOF
  
    if (sline.equals("@<TRIPOS>BOND")) {
      break;
    }
  }

  int natm1, natm2;
  int natm_id1, natm_id2;
  std::map<int,int>::const_iterator iter;
  
  for (i=0; i<nbonds; ++i) {

    sline = lin.readLine().chomp();
    slist.clear();
    split(sline, ' ', std::back_inserter(slist));
    if (slist.size()<4) {
      MB_THROW(MOL2FormatException, "Invalid bond record");
    }

    if (!slist[1].toInt(&natm1)) {
      MB_THROW(MOL2FormatException, "Invalid bond line (atom1)");
    }
    if (!slist[2].toInt(&natm2)) {
      MB_THROW(MOL2FormatException, "Invalid bond line (atom2)");
    }
    LString sbont = slist[3];

    if (!bskip) {
      iter = atommap.find(natm1);
      if (iter==atommap.end())
	MB_THROW(MOL2FormatException, "Invalid bond line (bond atom1 not found)");
      natm_id1 = iter->second;

      iter = atommap.find(natm2);
      if (iter==atommap.end())
	MB_THROW(MOL2FormatException, "Invalid bond line (bond atom2 not found)");
      natm_id2 = iter->second;

      MolBond *pB = m_pMol->makeBond(natm_id1, natm_id2, true);
      if (pB==NULL)
	MB_THROW(MOL2FormatException, "makeBond failed");

      if (sbont.equals("1"))
	pB->setType(MolBond::SINGLE);
      else if (sbont.equals("2"))
	pB->setType(MolBond::DOUBLE);
      else if (sbont.equals("3"))
	pB->setType(MolBond::TRIPLE);
      else if (sbont.equals("ar")||sbont.equals("am"))
	pB->setType(MolBond::DELOC);

      m_nReadBonds++;
    }

    //LOG_DPRINTLN("bond %d<-->%d: %d", natm_id1, natm_id2, nbont);
  }
  
  if (bApplyTopo) {
    m_pMol->applyTopology();
    if (mol_type.equals("PROTEIN"))
      m_pMol->calcProt2ndry(-500.0);
    if (mol_type.equals("NUCLEIC_ACID"))
      m_pMol->calcBasePair(3.7, 30);
  }
  else {
    // Set noautogen prop to this residue,
    // to avoid topology autogen, when saved to and loaded from the qdf stream.
    if (!bskip) {
      iter = atommap.begin();
      if (iter!=atommap.end()) {
	int aid0 = iter->second;
	MolAtomPtr pA = m_pMol->getAtom(aid0);
	if (!pA.isnull()) {
	  MolResiduePtr pRes = pA->getParentResidue();
	  if (!pRes.isnull()) {
	    pRes->setPropStr("noautogen", "true");
	  }
	}
      }      
    }
  }
  /*
  */

  return true;
}
Пример #15
0
///
///   main routine for CueTTY (CLI version)
///
int main(int argc, const char *argv[])
{
  if (qlib::init())
    MB_DPRINTLN("qlib::init() OK.");
  else {
    LOG_DPRINTLN("Init: ERROR!!");
    return -1;
  }

  int i;
  LString loadscr;
  LString confpath;
  std::deque<LString> args2;

  for (i=1; i<argc; ++i) {
    MB_DPRINTLN("arg%d=%s", i, argv[i]);
    LString value = argv[i];

    if (value.equals("-conf")) {
      ++i;
      if (i>=argc) break;
      confpath = argv[i];
      ++i;
    }

    break;
  }
  
  for (; i<argc; ++i) {
    MB_DPRINTLN("arg%d=%s", i, argv[i]);
    args2.push_back(argv[i]);
  }

  if (args2.size()>0)
    loadscr = args2.front();

  if (confpath.isEmpty()) {
    confpath = DEFAULT_CONFIG;
  }

  if (!qsys::init(confpath)) {
    LOG_DPRINTLN("Qsys Init (%s): ERROR!!", confpath.c_str());
    return -1;
  }

  MB_DPRINTLN("main> confpath=%s", confpath.c_str());

  // load molstr/lwview module
  molstr::init();
  lwview::init();
  anim::init();

#if !defined(QM_BUILD_LW)
  // load other modules
  render::init();
  molvis::init();
  xtal::init();
  symm::init();
  surface::init();
  molanl::init();
#endif

#ifdef HAVE_JAVASCRIPT
  // load internal JS module
  jsbr::init();
#endif

#ifdef HAVE_PYTHON
  // load python module
  pybr::init();
#endif

  //////////

  if (!loadscr.isEmpty()) {
    process_input(loadscr, args2);
  }

  //////////

#ifdef HAVE_PYTHON
  // unload python module
  pybr::fini();
  MB_DPRINTLN("=== pybr::fini() OK ===");
#endif

#ifdef HAVE_JAVASCRIPT
  jsbr::fini();
  MB_DPRINTLN("=== jsbr::fini() OK ===");
#endif

#if !defined(QM_BUILD_LW)
  // load other modules
  render::fini();
  molvis::fini();
  xtal::fini();
  symm::fini();
  surface::fini();
  molanl::fini();
#endif

  anim::fini();
  lwview::fini();
  molstr::fini();
  MB_DPRINTLN("=== molstr::fini() OK ===");

  qsys::fini();
  MB_DPRINTLN("=== qsys::fini() OK ===");

  qlib::fini();

  std::cerr << "=== Terminated normaly ===" << std::endl;
  return 0;
}
Пример #16
0
void process_input(const LString &loadscr, const std::deque<LString> &args)
{
  qsys::SceneManager *pSM = qsys::SceneManager::getInstance();
  LOG_DPRINTLN("CueMol version %s build %s", pSM->getVersion().c_str(), pSM->getBuildID().c_str());

  fs::path scr_path(loadscr);
  
  fs::path full_path = fs::system_complete( scr_path );

  if ( !fs::exists( full_path ) ) {
#if (BOOST_FILESYSTEM_VERSION==2)
    std::cout << "\nNot found: " << full_path.file_string() << std::endl;
#else
    std::cout << "\nNot found: " << full_path.string() << std::endl;
#endif
    return;
  }

  //std::cerr << "\nFull path: " << full_path.file_string() << std::endl;
  //std::cerr << "Extn: " << full_path.extension() << std::endl;

  if (full_path.extension()==".qsc") {
    //qsys::ScenePtr rscene = pSM->loadSceneFrom(scr_path.file_string(), "xml");
    //qlib::FileOutStream &fos = qlib::FileOutStream::getStdErr();
    //rscene->writeTo(fos, true);
  }
  else if (full_path.extension()==".js") {
    //qsys::ScenePtr rscene = pSM->createScene();
    //qlib::uid_t scene_id = rscene->getUID();
    //rscene->execJSFile(loadscr);
    //pSM->destroyScene(scene_id);

    jsbr::Interp *pInt = jsbr::createInterp(NULL);
    pInt->setCmdArgs(args);

    // setup system default script path
    qsys::SysConfig *pconf = qsys::SysConfig::getInstance();
    LString scrdir = pconf->get("script_dir");
    MB_DPRINTLN("sysconfig: script_dir=%s", scrdir.c_str());
    if (!scrdir.isEmpty())
      pInt->setScriptPath("system", pconf->convPathName(scrdir));

    // run startup script
    pInt->execFile("startup.js");

    // run the main script
    pInt->execFile(loadscr);

    delete pInt;
  }
  else if (full_path.extension()==".py") {
#ifdef HAVE_PYTHON
    pybr::runFile(loadscr);
#else
    LOG_DPRINTLN("Python not supported!!");
#endif
  }
  MB_DPRINTLN("main> cleanup ...");
  pSM->destroyAllScenes();
  MB_DPRINTLN("main> cleanup done.");
}
Пример #17
0
void SceneXMLReader::procDataSrcLoad(qlib::LDom2InStream &ois, LDom2Node *pNode)
{
  //////////
  // Recursively check the data src load requests

  LDom2Node::NodeList::const_iterator iter = pNode->childBegin();
  LDom2Node::NodeList::const_iterator eiter = pNode->childEnd();
  for (; iter!=eiter; ++iter) {
    LDom2Node *pChNode = *iter;
    if (pChNode!=NULL)
      procDataSrcLoad(ois, pChNode);
  }

  //////////
  // Do data source loading

  LDataSrcContainer *pCnt = pNode->getDataSrcContainer();
  if (pCnt==NULL)
    return;
  
  LString src = pNode->getDataSrc();
  LString altsrc = pNode->getDataAltSrc();
  LString srctype = pNode->getDataSrcType();

  if (src.isEmpty())
    return;

  if (srctype.isEmpty()) {
    // ERROR!! (TO DO: handling)
    LOG_DPRINTLN("SceneXML> src %s: srctype is not defined. (ignored)", src.c_str());
    return;
  }

  if (src.startsWith("datachunk:") && src.length()==15) {
    // Data source is in datachunk
    // --> Prepare for reading from data chunk of the stream
    MB_DPRINTLN("Data chunk found %s, %s ",
                src.c_str(), srctype.c_str());
    // addChunkMap(src, pCnt, srctype);
    ois.addChunkMap(src, pCnt);
    return;
  }
  
  //robj->readFromPath(src, altsrc, m_pClient);
  bool bAlt = false;
  LString basedir = m_pClient->getBasePath();
  LString abs_path = pCnt->readFromSrcAltSrc(src, altsrc, basedir, bAlt);

  // ATTN 14/06/29:
  // Update src/altsrc properties based on where the data source has been loaded.
  // (In the qsc file, there are two alternative sources. However, only one src is actually loaded.)
  // This is required to keep consistency between the "src prop" and "actual data src".
  if (bAlt) {
    // loaded from altsrc; altsrc --> src
    if (!qlib::isAbsolutePath(altsrc))
      altsrc = qlib::makeAbsolutePath(altsrc, basedir);
    pCnt->updateSrcPath(altsrc);
  }
  else {
    // loaded from src; keep src
    if (!qlib::isAbsolutePath(src))
      src = qlib::makeAbsolutePath(src, basedir);
    pCnt->updateSrcPath(src);
  }

}