[brlcad-commits] SF.net SVN: brlcad:[33077]
Open Source Solid Modeling CAD
Brought to you by:
brlcad
From: <ma...@us...> - 2008-10-27 17:26:36
|
Revision: 33077 http://brlcad.svn.sourceforge.net/brlcad/?rev=33077&view=rev Author: mafm Date: 2008-10-27 17:26:32 +0000 (Mon, 27 Oct 2008) Log Message: ----------- Creating especialized class for commands replicating/calling libged functions Modified Paths: -------------- rt^3/trunk/src/g3d/Command.cxx rt^3/trunk/src/g3d/Command.h rt^3/trunk/src/g3d/CommandInterpreter.cxx rt^3/trunk/src/g3d/Commands.h Added Paths: ----------- rt^3/trunk/src/g3d/GedCommand.cxx rt^3/trunk/src/g3d/GedCommand.h rt^3/trunk/src/g3d/GedCommands.h Modified: rt^3/trunk/src/g3d/Command.cxx =================================================================== --- rt^3/trunk/src/g3d/Command.cxx 2008-10-27 16:29:47 UTC (rev 33076) +++ rt^3/trunk/src/g3d/Command.cxx 2008-10-27 17:26:32 UTC (rev 33077) @@ -28,17 +28,9 @@ #include <vector> -#include <brlcad/ged.h> -/** \note mafm: Undefining too-common names to not clash with names - * elsewhere (in example, Ogre uses some of them) */ -#undef X -#undef Y - #include "Command.h" -#include "Logger.h" - /******************************************************************************* * CommandOutput ******************************************************************************/ @@ -58,22 +50,13 @@ /******************************************************************************* * Command ******************************************************************************/ -Command::Command(const std::string& name, const std::string& shortDescr, const std::string& extraDescr) : +Command::Command(const std::string& name, + const std::string& shortDescr, + const std::string& extraDescr) : _name(name), _shortDescription(shortDescr), _extraDescription(extraDescr) { } -void Command::treatGEDResult(int resultCode, - CommandOutput& output, - const std::string& text) const -{ - if (resultCode == BRLCAD_OK) { - output.appendLine(text); - } else { - Logger::logERROR(text.c_str()); - } -} - const std::string& Command::getName() const { return _name; Modified: rt^3/trunk/src/g3d/Command.h =================================================================== --- rt^3/trunk/src/g3d/Command.h 2008-10-27 16:29:47 UTC (rev 33076) +++ rt^3/trunk/src/g3d/Command.h 2008-10-27 17:26:32 UTC (rev 33077) @@ -76,11 +76,6 @@ /** Execute the command (to be implemented by the real commands) */ virtual void execute(std::vector<std::string>& args, CommandOutput& output) = 0; - /** Treat result from GED library (and eventually append output or - * log messages) */ - void treatGEDResult(int resultCode, - CommandOutput& output, - const std::string& text) const; /** The name of the command */ const std::string& getName() const; Modified: rt^3/trunk/src/g3d/CommandInterpreter.cxx =================================================================== --- rt^3/trunk/src/g3d/CommandInterpreter.cxx 2008-10-27 16:29:47 UTC (rev 33076) +++ rt^3/trunk/src/g3d/CommandInterpreter.cxx 2008-10-27 17:26:32 UTC (rev 33077) @@ -34,6 +34,8 @@ #include "Logger.h" #include "Command.h" #include "Commands.h" +#include "GedCommand.h" +#include "GedCommands.h" /******************************************************************************* Modified: rt^3/trunk/src/g3d/Commands.h =================================================================== --- rt^3/trunk/src/g3d/Commands.h 2008-10-27 16:29:47 UTC (rev 33076) +++ rt^3/trunk/src/g3d/Commands.h 2008-10-27 17:26:32 UTC (rev 33077) @@ -36,7 +36,6 @@ #include "Application.h" #include "CameraManager.h" -#include "GedData.h" #include "GeometryConversion.h" @@ -232,218 +231,6 @@ SampleTetrahedron _sampleTetrahedron; }; - -/** @brief Dump a full copy of the database - * - * @author Manuel A. Fernandez Montecelo <ma...@us...> - */ -class CommandGedDump : public Command -{ -public: - CommandGedDump() : - Command("ged_dump", - "Dump a full copy of the database", - "Argument is filename ('.g' not added automatically)") - { - _argNames.push_back("filename"); - } - - virtual void execute(std::vector<std::string>& args, CommandOutput& out) { - ged* g = GedData::instance().getGED(); - int result = 0; - - if (args.size() != 1) { - out.appendLine("This command needs exactly one argument"); - return; - } else { - const char* argv[] = { _name.c_str(), args[1].c_str() }; - int argc = sizeof(argv)/sizeof(const char*); - result = ged_dump(g, argc, argv); - - treatGEDResult(result, out, bu_vls_addr(&g->ged_result_str)); - } - } -}; - - -/** @brief Solids on ray - * - * @author Manuel A. Fernandez Montecelo <ma...@us...> - */ -class CommandGedSolidsOnRay : public Command -{ -public: - CommandGedSolidsOnRay() : - Command("ged_solids_on_ray", - "Solids on ray", - "") - { - } - - virtual void execute(std::vector<std::string>& args, CommandOutput& out) { - ged* g = GedData::instance().getGED(); - int result = 0; - - if (args.size() > 0) { - out.appendLine("Command doesn't accept arguments"); - return; - } else { - const char* argv[] = { _name.c_str() }; - int argc = sizeof(argv)/sizeof(const char*); - result = ged_solids_on_ray(g, argc, argv); - - treatGEDResult(result, out, bu_vls_addr(&g->ged_result_str)); - } - } -}; - - -/** @brief Get libged database file summary. - * - * @author Manuel A. Fernandez Montecelo <ma...@us...> - */ -class CommandGedSummary : public Command -{ -public: - CommandGedSummary() : - Command("ged_summary", - "Get libged database file summary", - "Argument is either empty, or one of [primitives|regions|groups] (initial chars are enough)") - { - _argNames.push_back("type"); - } - - virtual void execute(std::vector<std::string>& args, CommandOutput& out) { - ged* g = GedData::instance().getGED(); - int result = 0; - - if (args.size() > 1) { - out.appendLine("This command needs exactly zero or one argument"); - return; - } else { - if (args.size() == 1) { - std::string type; - if (args[0][0] == 'p') { - type = "p"; - } else if (args[0][0] == 'r') { - type = "r"; - } else if (args[0][0] == 'g') { - type = "g"; - } else { - out.appendLine("Summary type not recognized"); - return; - } - - const char* argv[] = { _name.c_str(), type.c_str() }; - int argc = sizeof(argv)/sizeof(const char*); - result = ged_summary(g, argc, argv); - } else { - const char* argv[] = { _name.c_str() }; - int argc = sizeof(argv)/sizeof(const char*); - result = ged_summary(g, argc, argv); - } - - treatGEDResult(result, out, bu_vls_addr(&g->ged_result_str)); - } - } -}; - - -/** @brief Get/Set libged DB title. - * - * @author Manuel A. Fernandez Montecelo <ma...@us...> - */ -class CommandGedTitle : public Command -{ -public: - CommandGedTitle() : - Command("ged_title", - "Get/Set libged database title", - "Argument is title (empty to get)") - { - _argNames.push_back("title"); - } - - virtual void execute(std::vector<std::string>& args, CommandOutput& out) { - ged* g = GedData::instance().getGED(); - int result = 0; - - if (args.size() > 1) { - out.appendLine("This command needs exactly zero or one argument"); - return; - } else { - if (args.size() == 1) { - const char* argv[] = { _name.c_str(), args[1].c_str() }; - int argc = sizeof(argv)/sizeof(const char*); - result = ged_title(g, argc, argv); - } else { - const char* argv[] = { _name.c_str() }; - int argc = sizeof(argv)/sizeof(const char*); - result = ged_title(g, argc, argv); - } - - treatGEDResult(result, out, bu_vls_addr(&g->ged_result_str)); - } - } -}; - - -/** @brief Get libged database file version. - * - * @author Manuel A. Fernandez Montecelo <ma...@us...> - */ -class CommandGedVersion : public Command -{ -public: - CommandGedVersion() : - Command("ged_version", - "Get libged database file version", - "") - { } - - virtual void execute(std::vector<std::string>& args, CommandOutput& out) { - if (args.size() != 0) { - out.appendLine("Command doesn't accept arguments"); - return; - } else { - ged* g = GedData::instance().getGED(); - const char* argv[] = { _name.c_str() }; - int argc = sizeof(argv)/sizeof(const char*); - int result = ged_version(g, argc, argv); - - treatGEDResult(result, out, bu_vls_addr(&g->ged_result_str)); - } - } -}; - - -/** @brief Erase all currently displayed geometry - * - * @author Manuel A. Fernandez Montecelo <ma...@us...> - */ -class CommandGedZap : public Command -{ -public: - CommandGedZap() : - Command("ged_zap", - "Erase all currently displayed geometry", - "") - { - } - - virtual void execute(std::vector<std::string>& args, CommandOutput& out) { - ged* g = GedData::instance().getGED(); - int result = 0; - - if (args.size() > 0) { - out.appendLine("Command doesn't accept arguments"); - return; - } else { - treatGEDResult(result, out, bu_vls_addr(&g->ged_result_str)); - } - } -}; - #endif Added: rt^3/trunk/src/g3d/GedCommand.cxx =================================================================== --- rt^3/trunk/src/g3d/GedCommand.cxx (rev 0) +++ rt^3/trunk/src/g3d/GedCommand.cxx 2008-10-27 17:26:32 UTC (rev 33077) @@ -0,0 +1,68 @@ +/* G E D C O M M A N D . C X X + * BRL-CAD + * + * Copyright (c) 2008 United States Government as represented by + * the U.S. Army Research Laboratory. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * version 2.1 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this file; see the file named COPYING for more + * information. + */ + +/** @file GedCommand.cxx + * + * @author Manuel A. Fernandez Montecelo <ma...@us...> + * + * @brief + * Implementation of GedCommand class. + */ + +#include <brlcad/ged.h> +/** \note mafm: Undefining too-common names to not clash with names + * elsewhere (in example, Ogre uses some of them) */ +#undef X +#undef Y + +#include "GedCommand.h" + +#include "Logger.h" + + +/******************************************************************************* + * GedCommand + ******************************************************************************/ +GedCommand::GedCommand(const std::string& name, + const std::string& shortDescr, + const std::string& extraDescr) : + Command(name, shortDescr, extraDescr) +{ +} + +void GedCommand::treatGEDResult(int resultCode, + CommandOutput& output, + const std::string& text) const +{ + if (resultCode == BRLCAD_OK) { + output.appendLine(text); + } else { + Logger::logERROR(text.c_str()); + } +} + + +// Local Variables: *** +// mode: C++ *** +// tab-width: 8 *** +// c-basic-offset: 2 *** +// indent-tabs-mode: t *** +// End: *** +// ex: shiftwidth=2 tabstop=8 Property changes on: rt^3/trunk/src/g3d/GedCommand.cxx ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native Added: rt^3/trunk/src/g3d/GedCommand.h =================================================================== --- rt^3/trunk/src/g3d/GedCommand.h (rev 0) +++ rt^3/trunk/src/g3d/GedCommand.h 2008-10-27 17:26:32 UTC (rev 33077) @@ -0,0 +1,74 @@ +/* G E D C O M M A N D . H + * BRL-CAD + * + * Copyright (c) 2008 United States Government as represented by + * the U.S. Army Research Laboratory. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * version 2.1 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this file; see the file named COPYING for more + * information. + */ + +/** @file GedCommand.h + * + * @author Manuel A. Fernandez Montecelo <ma...@us...> + * + * @brief + * Command for invoking libged functions. + */ + +#ifndef __G3D_GEDCOMMAND_H__ +#define __G3D_GEDCOMMAND_H__ + + +#include "Command.h" + + +/** + * @brief Command for invoking libged functions + * + * @author Manuel A. Fernandez Montecelo <ma...@us...> + * + * Derived class for commands invoking libged functions, to contain + * specific functionality and factor code out needed for all this kind + * of commands. + */ +class GedCommand : public Command +{ +public: + /** Constructor with some basics needed when creating any + * command. */ + GedCommand(const std::string& name, + const std::string& shortDescr, + const std::string& extraDescr); + /** Default destructor */ + virtual ~GedCommand() { } + +private: + /** Helper method to treat result from GED library (and eventually + * append output or log messages) */ + void treatGEDResult(int resultCode, + CommandOutput& output, + const std::string& text) const; + +}; + +#endif + + +// Local Variables: *** +// mode: C++ *** +// tab-width: 8 *** +// c-basic-offset: 2 *** +// indent-tabs-mode: t *** +// End: *** +// ex: shiftwidth=2 tabstop=8 Property changes on: rt^3/trunk/src/g3d/GedCommand.h ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native Added: rt^3/trunk/src/g3d/GedCommands.h =================================================================== --- rt^3/trunk/src/g3d/GedCommands.h (rev 0) +++ rt^3/trunk/src/g3d/GedCommands.h 2008-10-27 17:26:32 UTC (rev 33077) @@ -0,0 +1,262 @@ +/* G E D C O M M A N D S . H + * BRL-CAD + * + * Copyright (c) 2008 United States Government as represented by + * the U.S. Army Research Laboratory. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * version 2.1 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this file; see the file named COPYING for more + * information. + */ + +/** @file GedCommands.h + * + * @author Manuel A. Fernandez Montecelo <ma...@us...> + * + * @brief + * Implementation of commands dealing with libged. + */ + +#ifndef __G3D_GEDCOMMANDS_H__ +#define __G3D_GEDCOMMANDS_H__ + + +#include "GedCommand.h" + +#include <string> + +#include "GedData.h" + + +/** @brief Dump a full copy of the database + * + * @author Manuel A. Fernandez Montecelo <ma...@us...> + */ +class CommandGedDump : public GedCommand +{ +public: + CommandGedDump() : + GedCommand("ged_dump", + "Dump a full copy of the database", + "Argument is filename ('.g' not added automatically)") + { + _argNames.push_back("filename"); + } + + virtual void execute(std::vector<std::string>& args, CommandOutput& out) { + ged* g = GedData::instance().getGED(); + int result = 0; + + if (args.size() != 1) { + out.appendLine("This command needs exactly one argument"); + return; + } else { + const char* argv[] = { _name.c_str(), args[1].c_str() }; + int argc = sizeof(argv)/sizeof(const char*); + result = ged_dump(g, argc, argv); + + treatGEDResult(result, out, bu_vls_addr(&g->ged_result_str)); + } + } +}; + + +/** @brief Solids on ray + * + * @author Manuel A. Fernandez Montecelo <ma...@us...> + */ +class CommandGedSolidsOnRay : public GedCommand +{ +public: + CommandGedSolidsOnRay() : + GedCommand("ged_solids_on_ray", + "Solids on ray", + "") + { + } + + virtual void execute(std::vector<std::string>& args, CommandOutput& out) { + ged* g = GedData::instance().getGED(); + int result = 0; + + if (args.size() > 0) { + out.appendLine("Command doesn't accept arguments"); + return; + } else { + const char* argv[] = { _name.c_str() }; + int argc = sizeof(argv)/sizeof(const char*); + result = ged_solids_on_ray(g, argc, argv); + + treatGEDResult(result, out, bu_vls_addr(&g->ged_result_str)); + } + } +}; + + +/** @brief Get libged database file summary. + * + * @author Manuel A. Fernandez Montecelo <ma...@us...> + */ +class CommandGedSummary : public GedCommand +{ +public: + CommandGedSummary() : + GedCommand("ged_summary", + "Get libged database file summary", + "Argument is either empty, or one of [primitives|regions|groups] (initial chars are enough)") + { + _argNames.push_back("type"); + } + + virtual void execute(std::vector<std::string>& args, CommandOutput& out) { + ged* g = GedData::instance().getGED(); + int result = 0; + + if (args.size() > 1) { + out.appendLine("This command needs exactly zero or one argument"); + return; + } else { + if (args.size() == 1) { + std::string type; + if (args[0][0] == 'p') { + type = "p"; + } else if (args[0][0] == 'r') { + type = "r"; + } else if (args[0][0] == 'g') { + type = "g"; + } else { + out.appendLine("Summary type not recognized"); + return; + } + + const char* argv[] = { _name.c_str(), type.c_str() }; + int argc = sizeof(argv)/sizeof(const char*); + result = ged_summary(g, argc, argv); + } else { + const char* argv[] = { _name.c_str() }; + int argc = sizeof(argv)/sizeof(const char*); + result = ged_summary(g, argc, argv); + } + + treatGEDResult(result, out, bu_vls_addr(&g->ged_result_str)); + } + } +}; + + +/** @brief Get/Set libged DB title. + * + * @author Manuel A. Fernandez Montecelo <ma...@us...> + */ +class CommandGedTitle : public GedCommand +{ +public: + CommandGedTitle() : + GedCommand("ged_title", + "Get/Set libged database title", + "Argument is title (empty to get)") + { + _argNames.push_back("title"); + } + + virtual void execute(std::vector<std::string>& args, CommandOutput& out) { + ged* g = GedData::instance().getGED(); + int result = 0; + + if (args.size() > 1) { + out.appendLine("This command needs exactly zero or one argument"); + return; + } else { + if (args.size() == 1) { + const char* argv[] = { _name.c_str(), args[1].c_str() }; + int argc = sizeof(argv)/sizeof(const char*); + result = ged_title(g, argc, argv); + } else { + const char* argv[] = { _name.c_str() }; + int argc = sizeof(argv)/sizeof(const char*); + result = ged_title(g, argc, argv); + } + + treatGEDResult(result, out, bu_vls_addr(&g->ged_result_str)); + } + } +}; + + +/** @brief Get libged database file version. + * + * @author Manuel A. Fernandez Montecelo <ma...@us...> + */ +class CommandGedVersion : public GedCommand +{ +public: + CommandGedVersion() : + GedCommand("ged_version", + "Get libged database file version", + "") + { + } + + virtual void execute(std::vector<std::string>& args, CommandOutput& out) { + if (args.size() != 0) { + out.appendLine("Command doesn't accept arguments"); + return; + } else { + ged* g = GedData::instance().getGED(); + const char* argv[] = { _name.c_str() }; + int argc = sizeof(argv)/sizeof(const char*); + int result = ged_version(g, argc, argv); + + treatGEDResult(result, out, bu_vls_addr(&g->ged_result_str)); + } + } +}; + + +/** @brief Erase all currently displayed geometry + * + * @author Manuel A. Fernandez Montecelo <ma...@us...> + */ +class CommandGedZap : public GedCommand +{ +public: + CommandGedZap() : + GedCommand("ged_zap", + "Erase all currently displayed geometry", + "") + { + } + + virtual void execute(std::vector<std::string>& args, CommandOutput& out) { + ged* g = GedData::instance().getGED(); + int result = 0; + + if (args.size() > 0) { + out.appendLine("Command doesn't accept arguments"); + return; + } else { + treatGEDResult(result, out, bu_vls_addr(&g->ged_result_str)); + } + } +}; + +#endif + + +// Local Variables: *** +// mode: C++ *** +// tab-width: 8 *** +// c-basic-offset: 2 *** +// indent-tabs-mode: t *** +// End: *** +// ex: shiftwidth=2 tabstop=8 + Property changes on: rt^3/trunk/src/g3d/GedCommands.h ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |