display_with_tv.cpp
上传用户:yhdzpy8989
上传日期:2007-06-13
资源大小:13604k
文件大小:5k
- /*
- * ===========================================================================
- * PRODUCTION $Log: display_with_tv.cpp,v $
- * PRODUCTION Revision 1000.1 2004/06/01 20:57:03 gouriano
- * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.3
- * PRODUCTION
- * ===========================================================================
- */
- /* $Id: display_with_tv.cpp,v 1000.1 2004/06/01 20:57:03 gouriano Exp $
- * ===========================================================================
- *
- * PUBLIC DOMAIN NOTICE
- * National Center for Biotechnology Information
- *
- * This software/database is a "United States Government Work" under the
- * terms of the United States Copyright Act. It was written as part of
- * the author's official duties as a United States Government employee and
- * thus cannot be copyrighted. This software/database is freely available
- * to the public for use. The National Library of Medicine and the U.S.
- * Government have not placed any restriction on its use or reproduction.
- *
- * Although all reasonable efforts have been taken to ensure the accuracy
- * and reliability of the software and data, the NLM and the U.S.
- * Government do not and cannot warrant the performance or results that
- * may be obtained by using this software or data. The NLM and the U.S.
- * Government disclaim all warranties, express or implied, including
- * warranties of performance, merchantability or fitness for any particular
- * purpose.
- *
- * Please cite the author in any work or product based on this material.
- *
- * ===========================================================================
- *
- * Authors: Josh Cherry
- *
- * File Description: gbench plugin for displaying a phylogenetic tree
- * using the tv application
- *
- */
- #include <ncbi_pch.hpp>
- #include "display_with_tv.hpp"
- #include <gui/core/idocument.hpp>
- #include <gui/core/plugin_utils.hpp>
- #include <gui/plugin/PluginCommandSet.hpp>
- #include <gui/plugin/PluginValue.hpp>
- #include <gui/plugin/PluginInfo.hpp>
- #include <gui/plugin/PluginReply.hpp>
- #include <gui/plugin/PluginRequest.hpp>
- #include <gui/plugin/PluginValueConstraint.hpp>
- #include <gui/core/version.hpp>
- #include <gui/core/doc_manager.hpp>
- #include <gui/objutils/utils.hpp>
- #include <gui/utils/message_box.hpp>
- #include <util/random_gen.hpp>
- #include <gui/utils/file_deletion.hpp>
- #include <corelib/ncbifile.hpp>
- #include <corelib/ncbiexec.hpp>
- #include <algo/phy_tree/phy_tree_serial.hpp>
- BEGIN_NCBI_SCOPE
- USING_SCOPE(objects);
- // standard info boilerplate
- void CAlgoPlugin_DisplayWithTv::GetInfo(CPluginInfo& info)
- {
- info.Reset();
- // version info macro
- info.SetInfo(CPluginVersion::eMajor, CPluginVersion::eMinor, 0,
- string(__DATE__) + " " + string(__TIME__),
- "CAlgoPlugin_DisplayWithTv",
- "Phylogenetic trees/Display using tv",
- "Display phylogenetic tree using the tv program",
- "");
- // command info
- CPluginCommandSet& cmds = info.SetCommands();
- CPluginCommand& args = cmds.AddAlgoCommand(eAlgoCommand_run);
- args.AddArgument("tree", "Tree", CPhyTreeSerial::GetTypeInfo());
- }
- void CAlgoPlugin_DisplayWithTv::RunCommand(CPluginMessage& msg)
- {
- const CPluginCommand& args = msg.GetRequest().GetCommand();
- CPluginReply& reply = msg.SetReply();
- _TRACE("CAlgoPlugin_DisplayWithTv::Run()");
- const CPhyTreeSerial *tree =
- dynamic_cast<const CPhyTreeSerial *>(&args["tree"].AsObject());
- if (!tree) {
- throw runtime_error("CAlgoPlugin_DisplayWithTv::Save: not a tree");
- }
- // make the file name end in appropriate extension
- CRandom r(time(0));
- string fname;
- const int max_tries = 100;
- int i;
- for (i = 0; i < max_tries; i++) {
- fname = CFile::GetTmpName();
- fname += NStr::IntToString(r.GetRand()) + ".tre";
- CFile file(fname);
- if (!file.Exists()) {
- break;
- }
- }
- if (i == max_tries) {
- LOG_POST(Error << "Couldn't create temporary file");
- return;
- }
- CNcbiOfstream tmpfile(fname.c_str());
- WriteNexusTree(tmpfile, tree->GetTree());
- tmpfile.close();
- CDeleteAtExit::Add(fname);
- int exit_status = CExec::SpawnLP(CExec::eDetach, "tv",
- fname.c_str(), 0);
- if (exit_status != -1) {
- reply.SetStatus(eMessageStatus_success);
- } else {
- NcbiMessageBox("Error launching tv; make sure tv is installed"
- " and on your path");
- }
- }
- END_NCBI_SCOPE
- /*
- * ===========================================================================
- * $Log
- * ===========================================================================
- */