예제 #1
0
파일: Utils.cpp 프로젝트: CueMol/cuemol2
LString makeRelativePath(const LString &aAbs, const LString &aBase)
{
  fs::path abspath(aAbs.c_str());
  fs::path basepath(aBase.c_str());
  if (!abspath.is_complete() || !basepath.is_complete())
    return aAbs; // aAbs or aBase is not absolute path

  if (abspath.root_path()!=basepath.root_path())
    return aAbs; // root names are different; cannot make relative path

  fs::path::const_iterator iter1 = abspath.begin();
  fs::path::const_iterator iter1_end = abspath.end();
  fs::path::const_iterator iter2 = basepath.begin();
  fs::path::const_iterator iter2_end = basepath.end();

  for (; iter1!=iter1_end && iter2!=iter2_end ; ++iter1, ++iter2) {
    if (*iter1!=*iter2) break;
  }

  fs::path relpath;
  //if (iter1!=iter1_end && iter2!=iter2_end) {
    for (; iter2!=iter2_end; ++iter2)
      relpath /= "..";
    for (; iter1!=iter1_end; ++iter1)
      relpath /= *iter1;
  //}

  // string() will canonicalize the path separator to "/"
  //return relpath.file_string();
  return relpath.string();
}
예제 #2
0
void SceneXMLReader::read()
{
  // If getPath() points to a relative path,
  // convert it to the absolute path name using the fs::current_path() (i.e. pwd)
  fs::path curpath = fs::current_path();
#if (BOOST_FILESYSTEM_VERSION==2)
  LString localfile = qlib::makeAbsolutePath(getPath(), curpath.file_string());
#else
  LString localfile = qlib::makeAbsolutePath(getPath(), curpath.string());
#endif


  // Enter the loading scene's context
  AutoStyleCtxt style_ctxt(m_pClient->getUID());
  
  // show start msg
  LOG_DPRINTLN("SceneXML> Start loading: %s ...", localfile.c_str());

  //
  // Setup streams
  //
  qlib::FileInStream fis;
  fis.open(localfile);
  qlib::LDom2InStream ois(fis);

  //
  // Construct data structure
  //   from the XML part in the target scene file.
  //
  qlib::LDom2Tree tree;
  ois.read(tree);
  LDom2Node *pNode = tree.top();

  m_pClient->setSource(localfile);
  m_pClient->setSourceType(getName());

  // perform deserialization to the client scene (m_pClient)
  tree.deserialize(&m_pClient);

  // load data source / collect chunk-load requests
  procDataSrcLoad(ois, pNode);

  // perform chunk loading
  procDataChunks(ois, pNode);

  ois.close();
  m_pClient->setUpdateFlag();
  m_errmsg = pNode->getErrorMsgs();

  LOG_DPRINTLN("SceneXML> File loaded: %s.", localfile.c_str());

  //////////
  // fire the scene-loaded event
  {
    SceneEvent ev;
    ev.setTarget(m_pClient->getUID());
    ev.setType(SceneEvent::SCE_SCENE_ONLOADED);
    m_pClient->fireSceneEvent(ev);
  }
}
예제 #3
0
LSerializable *LDOMObjInStream::readObjImpl()
{
  LString clsname = m_data.current()->type_name;
//  const int ncs = m_pCurNode->children.size();
//  const int nelems = LDomTree::getElemCount(*m_pCurNode);
//  const int nattrs = ncs-nelems;

  ClassRegistry *pMgr = ClassRegistry::getInstance();
  LClass *pClass = pMgr->getClassObj(clsname);
  if (pClass==NULL) {
    LOG_DPRINTLN("ERROR class \"%s\" is not defined", clsname.c_str());
    return NULL;
  }
  
  // createScrObj() creates SmartPtr object, if the class supports it.
  LDynamic *pNewObj = pClass->createScrObj();
  if (pNewObj==NULL) {
    LOG_DPRINTLN("ERROR cannot instantiate class \"%s\"", clsname.c_str());
    return NULL;
  }
  LSerializable *pS = dynamic_cast<LSerializable *>(pNewObj);
  if (pS==NULL) {
    LOG_DPRINTLN("ERROR cannot instantiate class \"%s\"", clsname.c_str());
    return NULL;
  }

  pS->readFrom(*this);

  return pS;
}
예제 #4
0
bool clLibrary::Load( const LString& LibName )
{
#if defined( OS_WINDOWS )
	FLibHandle = ::LoadLibrary( LibName.c_str() );

	if ( !FLibHandle )
	{
		LString DLL = FindLibrary( LibName );

		FLibHandle = ::LoadLibrary( DLL.c_str() );
	}

#else
	const char* ErrStr;

	FLibHandle = dlopen( LibName.c_str(), RTLD_LAZY );

	if ( ( ErrStr = dlerror() ) != NULL )
	{
		FLibHandle = NULL;
	}

#endif

	CHECK_RET( !FLibHandle, false, "Unable to load library " + LibName );

	return true;
}
예제 #5
0
/** register new linkage between two residues */
bool TopoDB::addLinkByName(const LString &prev_res, char prev_ch,
			     const LString &next_res, char next_ch,
			     const LString &link_name)
{
  //MB_DPRINT("addLinkByName search %s\n",plusname.c_str());
  ResiPatch *pPatch = patchPrefixGet('+', link_name);
  if (pPatch==NULL)
    return false;

  // process the case in that prev and next is inverted
  if (pPatch->getPrevPrefix()!=prev_ch ||
      pPatch->getNextPrefix()!=next_ch) {

    pPatch = patchPrefixGet('-', link_name);

    if (pPatch->getPrevPrefix()!=prev_ch ||
        pPatch->getNextPrefix()!=next_ch)
      return false;
  }

  Linkage link;
  link.prev = prev_ch;
  link.next = next_ch;
  link.patch_name = pPatch->getName();

  LString key(prev_res.c_str());
  key.append(':');
  key.append(next_res.c_str());

  //MB_DPRINT("linkage LINK register %s\n",key.c_str());
  return m_linkDict.set(key, link);
  //return true;
}
예제 #6
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");
    }
  }
}
예제 #7
0
bool XmlRpcMgr::setProp(qlib::uid_t uid, const LString &propnm, const xmlrpc_c::value *pVal)
{
  qlib::LScriptable *pObj = getObj(uid);
  if (pObj==NULL) {
    // TO DO: report error
    MB_DPRINTLN("SetProp error, object %d not found", uid);
    return false;
  }
  
  ReoSetProp evt;
  evt.m_pObj = pObj;
  evt.m_propname = propnm;

  //////////
  // convert to LVariant

  // variant (lvar) doesn't have ownership of its content
  qlib::LVariant &lvar = evt.m_value;
  bool ok = false;
  LString errmsg;
  try {
    convXrval2Lvar(pVal, lvar);
    ok = true;
  }
  catch (const qlib::LException &e) {
    errmsg = 
      LString::format("SetProp(%s) cannot converting PyObj to LVariant: %s",
		      propnm.c_str(), e.getMsg().c_str());
    MB_DPRINTLN("Err: %s", errmsg.c_str());
  }
  catch (...) {
    errmsg = 
      LString::format("SetProp(%s): Cannot converting PyObj to LVariant.", propnm.c_str());
    MB_DPRINTLN("Err: %s", errmsg.c_str());
  }

  if (!ok) {
    // TO DO: report error
    return false;
  }

  MB_DPRINTLN("XMLRPC> svrthr SetProp conv OK ");

  //////////
  // perform setProperty

  m_pQue->putWait(&evt);
  if (!evt.m_bOK) {
    throw ( xmlrpc_c::fault(evt.m_errmsg.c_str(), xmlrpc_c::fault::CODE_UNSPECIFIED) );
    return qlib::invalid_uid;
  }
  
  MB_DPRINTLN("XMLRPC> svrthr setProp() putWait OK");

  // OK
  return true;
}
예제 #8
0
void clViewport::SetViewportTitle( const LString& Title )
{
#ifdef OS_WINDOWS
    SetWindowText( FWindowHandle, Title.c_str() );
#endif

#if defined(OS_LINUX) && !defined(OS_ANDROID)
    XSetStandardProperties( FDeviceHandle, *FWindowHandle, Title.c_str(), Title.c_str(), None, NULL, 0, NULL );
#endif
}
예제 #9
0
파일: Utils.cpp 프로젝트: CueMol/cuemol2
LString makeAbsolutePath(const LString &aRel, const LString &aBase)
{
  MB_DPRINTLN("makeAbsPath rel=%s, base=%s", aRel.c_str(), aBase.c_str());

  fs::path relpath(aRel.c_str());
  fs::path basepath(aBase.c_str());
  if (relpath.is_complete())
    return aRel; // aRel is already in abs form

  // convert to the absolute representation

  fs::path::const_iterator iter1 = relpath.begin();
  fs::path::const_iterator iter1_end = relpath.end();

  int nup = 0;
  for (; iter1!=iter1_end; ++iter1) {
    if (*iter1=="..")
      ++nup;
    else
      break;
  }

  if (nup==0) {
    // There's no up-dir ('..') string --> just concat to make abs path.
#if (BOOST_FILESYSTEM_VERSION==2)
    relpath = fs::complete(relpath, basepath);
    return relpath.file_string();
#else
    relpath = fs::absolute(relpath, basepath);
    return relpath.string();
#endif
  }

  for (; nup>0; --nup) {
    MB_ASSERT(basepath.has_parent_path());
    basepath = basepath.parent_path();
  }
  
  for (; iter1!=iter1_end; ++iter1) {
    basepath /= *iter1;
  }

#if (BOOST_FILESYSTEM_VERSION==2)
  return basepath.file_string();
#else
  return basepath.string();
#endif
}
예제 #10
0
void PrintStream::print(const LString &n)
{
  int len = n.length();
  int res = write(n.c_str(), 0, len);
  if (res!=len)
    MB_THROW(IOException, LString::format("OutStream.write() failed. (%d:%d)", res, len));
}
예제 #11
0
void clASELoader::ASE_ReadTVertexList( iIStream* FStream, clVAMender* Mender )
{
	guard();

#ifdef ASE_HEAVY_DEBUG
	Env->Logger->Log( L_DEBUG, "Reading Tvertex list..." );
#endif

	char Keyword[32];

	while ( !FStream->Eof() )
	{
		LString Line = FStream->ReadLineTrimLeadSpaces();

		if ( LStr::ContainsSubStr( Line, "}" ) )
		{
			break;
		}
		else if ( LStr::StartsWith( Line, ASE_MeshTVertex ) )
		{
			int Index;
			float U, V, W;

			sscanf( Line.c_str(), "%s %d %f %f %f", Keyword, &Index, &U, &V, &W );

			Mender->EmitTextureVertex( Index, LVector3( U, 1.0f - V, W ) );
		}
		else
		{
			FATAL_MSG( "Unexpected token in " + ASE_MeshTVertexList + " : " + Line );
		}
	}

	unguard();
}
예제 #12
0
void clAudioThread::InitOpenAL()
{
#if L_AUDIO_USE_OPENAL
	guard();

//	Env->Logger->Log( L_LOG, "Initializing OpenAL..." );

	LString DeviceName = Env->Console->GetVarValueStr( "Audio.AudioDeviceName", "" );

	FDevice = alcOpenDevice( DeviceName.empty() ? NULL : DeviceName.c_str() );

	FATAL( !FDevice, "Unable to open OpenAL device" );

	FContext = alcCreateContext( FDevice, NULL );

	FATAL( !FContext, "Unable to create OpenAL context" );

	FATAL( !alcMakeContextCurrent( FContext ), "Unable to select OpenAL context" );

	Env->Logger->LogP( L_LOG, "OpenAL (%s, %s, %s), extensions : %s", alGetString( AL_VERSION ), alGetString( AL_VENDOR ), alGetString( AL_RENDERER ), alGetString( AL_EXTENSIONS ) );
//	Env->Logger->Log( L_LOG, "OpenAL vendor    : " + LString(  ) );
//	Env->Logger->Log( L_LOG, "OpenAL renderer  : " + LString( alGetString( AL_RENDERER ) ) );
//	Env->Logger->Log( L_LOG, "OpenAL extensions: " );
	/*
	   {
	      LString Extensions;
	      Extensions.assign( alGetString( AL_EXTENSIONS ) );
	      LStr::ReplaceAll( &Extensions, ' ', '\n' );
	      Env->Logger->Log( L_LOG, '\n' + Extensions );
	   }
	*/
	unguard();
#endif
}
예제 #13
0
void clResourcesManager::ReCacheC( const LString& Param )
{
	guard( "%s", Param.c_str() );

	if ( Param.empty() )
	{
		Env->Console->DisplayInfoTip( "Usage: RECACHE <file name>" );
		return;
	}

	iResource* Resource = Env->Resources->FindResourceInGraph( FResourcesGraph, Param );

	if ( !Resource )
	{
		Env->Console->DisplayError( "Unable to find resource: " + Param );
		return;
	}

	Env->Console->DisplayInfoTip( Resource->GetFileName() );
	Env->Console->Display( "Recaching " + Resource->ClassName() );

	Resource->ReloadResource( true );

	unguard();
}
예제 #14
0
static bool is_keyword(const LString &name) {
    const char *str = name.c_str();
    int i = 0;
    while ((i <= 8) && str[i])
	i++;
    if (i > 8)
	return false;
    int start = len_start[i];
    int end = len_start[i+1];
    while ((start < end) && (str[0] > keywords[start][0]))
	start ++;
    if ((start >= end) || (str[0] != keywords[start][0]))
	return false;
    while ((start < end) && (str[0] == keywords[start][0])){
	const char *str1 = str + 1;
	const char *key1 = keywords[start] + 1;
	while ((*key1 == *str1) && *str1) {
	    key1++;
	    str1++;
	    }
	if (*str1 == *key1)
	    return true;
	start ++;
	}
    return false;
    }
예제 #15
0
void clMesh::LoadAnimStates( const LString& FileName )
{
	guard( "%s", FileName.c_str() );

	FAnimations = Env->Resources->LoadAnimation( FileName );

	unguard();
}
예제 #16
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;
}
예제 #17
0
파일: MolCoord.cpp 프로젝트: CueMol/cuemol2
/// 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();
}
예제 #18
0
파일: Utils.cpp 프로젝트: CueMol/cuemol2
  LString getLeafName(const LString &aPath)
  {
    fs::path path(aPath.c_str());
#if (BOOST_FILESYSTEM_VERSION==2)
    return LString(path.filename());
#else
    return LString(path.filename().string());
#endif
  }
예제 #19
0
void clConsole::ExecC( const LString& Param )
{
	guard();

	LString Parameter = Param;
	LStr::TrimSpaces( &Parameter );

	if ( Parameter.empty() )
	{
		DisplayInfoTip( "Usage: EXEC <File Name>" );
		return;
	}

	LString FName = LStr::GetToken( Parameter, 1 );

	Env->Logger->LogP( L_DEBUG, "Exec: %s", FName.c_str() );

	if ( Env->FileSystem->FileExists( FName ) )
	{
		iIStream* FCFGStream = Env->FileSystem->CreateFileReader( FName );

		while ( !FCFGStream->Eof() )
		{
			LString Cmd = FCFGStream->ReadLine();
			LStr::TrimSpaces( &Cmd );

			if ( !Cmd.empty() && Cmd.at( 0 ) != ';' )
			{
				SendCommand( Cmd );
			}
		}

		delete( FCFGStream );
	}
	else
	{
		Env->Logger->LogP( L_WARNING, "Config file %s not found", FName.c_str() );

		DisplayError( "Config file \"" + FName + "\" not found" );
	}

	unguard();
}
예제 #20
0
void ExpatInStream::parse()
{
  // check base URI

  LString s = getURI();
  MB_DPRINTLN("ExpatInStream getURI: <%s>", s.c_str());

  fs::path srcpath(s.c_str());
#if (BOOST_FILESYSTEM_VERSION==2)
  LString base_dir = srcpath.parent_path().directory_string();
#else
  LString base_dir = srcpath.parent_path().string();
#endif

  if (!base_dir.isEmpty())
    setBaseURI(base_dir);

  //detail::AbstFIOImpl *pimpl =
  //dynamic_cast<detail::AbstFIOImpl *>(getImpl().get());
  //if (pimpl!=NULL) {
  //MB_DPRINTLN("File: base URI %s", pimpl->getDirName().c_str());
  //setBaseURI((pimpl->getDirName())+LString(MB_PATH_SEPARATOR));
  //}

  char buf[bufsize];
  bool done=false;
  do {
    int len = super_t::read(buf, 0, sizeof(buf));
    done = len < sizeof(buf);
    if (XML_Parse(getParser(), buf, len, done) == XML_STATUS_ERROR) {
      LString msg =
        LString::format("%s at line %d\n",
                        XML_ErrorString(XML_GetErrorCode(getParser())),
                        getLineNo());
      MB_DPRINTLN("ExpatInStream> error: %s", msg.c_str());
      MB_THROW(qlib::IOException, msg);
    }
    else if (getError()) {
      MB_DPRINTLN("ExpatInStream> error: %s", getErrorMsg().c_str());
      MB_THROW(qlib::IOException, getErrorMsg());
    }
  } while (!done);
}
예제 #21
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;
   }
 }
예제 #22
0
//static 
LString LDOMObjOutStream::getTypeName(const LScriptable *pScr)
{
  LString rval;
  if (!pScr) return rval;
  if (pScr->isSmartPtr() && pScr->getSPInner()==NULL)
    return rval;
  LClass *pCls = pScr->getClassObj();
  rval = pCls->getClassName();
  MB_DPRINTLN("writeObject name=%s", rval.c_str());
  return rval;
}
예제 #23
0
qlib::LScriptable *XmlRpcMgr::getObj(qlib::uid_t uid)
{
  ObjTable::const_iterator i = m_objtab.find(uid);
  if (i==m_objtab.end()) {
    LString msg = LString::format("getObj unknown object ID: %d", uid);
    throw( xmlrpc_c::fault(msg.c_str(), xmlrpc_c::fault::CODE_UNSPECIFIED) );
    return NULL;
  }

  return i->second.p;
}
예제 #24
0
void LDOMObjInStream::reportError()
{
  LDomNode *pNode = m_data.current();
  LString msg = LString::format("Error occurred at node type=<%s> value=<%s> blist=%d nchild=%d",
                                pNode->type_name.c_str(),
                                pNode->value.c_str(),
                                (int) pNode->blist,
                                pNode->children.size());
                                
  LOG_DPRINTLN("LDOMObjInStream> %s", msg.c_str());
}
예제 #25
0
void clLocalizer::SetLocale( const LString& LocaleName )
{
	guard( "%s", LocaleName.c_str() );

	ClearLocalization();

	FLocaleName = LocaleName;

	const LString FileName( FLocalePath + "/Localizer-" + LocaleName + ".txt" );

	if ( Env->FileSystem->FileExists( FileName ) )
	{
		Env->Logger->LogP( L_NOTICE, "Reading locale from %s", FileName.c_str() );

		iIStream* Stream = Env->FileSystem->CreateFileReader( FileName );

		while ( !Stream->Eof() )
		{
			LString Line = Stream->ReadLine();

			size_t SepPos = Line.find( "~" );

			FATAL( SepPos == Line.npos, "Invalid locale translation file format: missing ~" );

			LString Text( Line.substr( 0, SepPos ) );
			LString Translation( Line.substr( SepPos + 1, Line.length() - SepPos - 1 ) );

			FTranslations[ Text ] = Translation;
		}

		delete( Stream );
	}
	else
	{
		Env->Logger->LogP( L_NOTICE, "Locale %s not found", FileName.c_str() );
	}

	this->SendAsync( L_EVENT_LOCALE_CHANGED, LEventArgs(), false );

	unguard();
}
예제 #26
0
void LScrVector4D::setStrValue(const LString &val)
{
  Vector4D vec;
  if (!Vector4D::fromStringS(val, vec)) {
    LString msg = LString::format("cannot convert \"%s\" to vector", val.c_str());
    MB_THROW(qlib::RuntimeException, msg);
    return;
  }

  for (int i=1; i<=4; ++i)
    ai(i) = vec.ai(i);
}
예제 #27
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;
}
예제 #28
0
LString PDBFileWriter::formatAtomName(MolAtomPtr pAtom)
{
  LString atomnam = pAtom->getName();
  char cConfID = pAtom->getConfID();
  int elem = pAtom->getElement();
  
  if (cConfID=='\0')
    cConfID = ' ';

  // invalid name case
  if (atomnam.length()>=4||
      elem==ElemSym::XX) {
    return LString::format("%4s%c", atomnam.c_str(), cConfID);
  }

  LString elenam = ElemSym::symID2Str(elem);
  elenam = elenam.toUpperCase();
  int elepos = atomnam.indexOf(elenam);
  if (elepos<0) {
    return LString::format("%4s%c", atomnam.c_str(), cConfID);
  }
  
  LString atommod;
  // if (atomnam.equals(elenam)) {
  // // atom name==elem name
  // shead += LString::format(" %2s  ", elenam.c_str());
  // break;
  // }
  
  elepos += elenam.length();
  atommod = atomnam.substr(elepos);
  elenam = atomnam.substr(0, elepos);
  
  if (atommod.length()<=2) {
    return LString::format("%2s%-2s%c",
                           elenam.c_str(), atommod.c_str(), cConfID);
  }
  
  return LString::format("%4s%c", atomnam.c_str(), cConfID);
}
예제 #29
0
ResiPatch *TopoDB::findLinkImpl(const LString &aPrevRes, const LString &aNextRes)
{
  // Resolve alias name
  ResiToppar *pTopPrev = get(aPrevRes);
  ResiToppar *pTopNext = get(aNextRes);
  if (pTopPrev==NULL || pTopNext==NULL) return NULL;
  const LString prev_res = pTopPrev->getName();
  const LString next_res = pTopNext->getName();

  // At first, find the complete matching entry
  LString key(prev_res.c_str());
  key.append(':');
  key.append(next_res.c_str());

  //MB_DPRINT("linkage find %s\n",key.c_str());

  if (m_linkDict.containsKey(key)) {
    Linkage link = m_linkDict.get(key);
    return patchGet(link.patch_name);
  }

  // find the (prev==wildcard) case
  key = LString("*:") + next_res.c_str();
  if (m_linkDict.containsKey(key)) {
    //MB_DPRINT("linkage find %s\n",key.c_str());
    Linkage link = m_linkDict.get(key);
    return patchGet(link.patch_name);
  }

  // find the (next==wildcard) case
  key = LString(prev_res.c_str()) + ":*";
  if (m_linkDict.containsKey(key)) {
    //MB_DPRINT("linkage find %s\n",key.c_str());
    Linkage link = m_linkDict.get(key);
    return patchGet(link.patch_name);
  }

  return NULL;
}
예제 #30
0
void UndoManager::startTxn(const LString &desc)
{
  if (isDisabled()) return; // ignore nested txn !!

  if (m_pPendInfo!=NULL) {
    m_nTxnNestLevel ++;
    return;
  }
  m_pPendInfo = MB_NEW UndoInfo();
  m_pPendInfo->setDesc(desc);

  MB_DPRINTLN("===== START UNDO TXN (%s) =====", desc.c_str());
}