From 5f12bc6008bc367e60f5aa1d92deb88400b09f3c Mon Sep 17 00:00:00 2001 From: Kliment Yanev Date: Mon, 2 May 2016 23:44:35 +0200 Subject: [PATCH 01/58] Add standalone slic3r binary that takes an stl file and emits a multilayer SVG --- xs/src/CMakeLists.txt | 98 ++++++++++++++++++++++++++++++++++ xs/src/libslic3r/SVGExport.cpp | 60 +++++++++++++++++++++ xs/src/libslic3r/SVGExport.hpp | 25 +++++++++ xs/src/slic3r.cpp | 64 ++++++++++++++++++++++ xs/src/standalone/config.h | 0 5 files changed, 247 insertions(+) create mode 100644 xs/src/CMakeLists.txt create mode 100644 xs/src/libslic3r/SVGExport.cpp create mode 100644 xs/src/libslic3r/SVGExport.hpp create mode 100644 xs/src/slic3r.cpp create mode 100644 xs/src/standalone/config.h diff --git a/xs/src/CMakeLists.txt b/xs/src/CMakeLists.txt new file mode 100644 index 0000000000..9a862b9a8b --- /dev/null +++ b/xs/src/CMakeLists.txt @@ -0,0 +1,98 @@ +cmake_minimum_required (VERSION 2.8) +project (slic3r) +set(workaround "") +if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.7.0) +if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.7.3) +set(workaround "-fno-inline-small-functions") +endif(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.7.3) +endif(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.7.0) + +set(CMAKE_CXX_FLAGS "-D_GLIBCXX_USE_C99 -DHAS_BOOL -DNOGDI -DBOOST_ASIO_DISABLE_KQUEUE -std=c++14 ${workaround}") +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +IF(CMAKE_HOST_APPLE) + set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++ -framework IOKit -framework CoreFoundation") +ELSE(CMAKE_HOST_APPLE) + set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++") +ENDIF(CMAKE_HOST_APPLE) +set(Boost_USE_STATIC_LIBS ON) +set(Boost_USE_STATIC_RUNTIME ON) +set(CMAKE_FIND_LIBRARY_SUFFIXES ".a") +find_package(Boost COMPONENTS system thread) + +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/libslic3r) +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/Slic3r/GUI/) +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/standalone/) +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/admesh/) +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/poly2tri/) +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/poly2tri/sweep) +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/poly2tri/common) +add_library(slic3r_gui STATIC slic3r/GUI/3DScene.cpp slic3r/GUI/GUI.cpp) +add_library(libslic3r STATIC libslic3r/BoundingBox.cpp + libslic3r/ExPolygon.cpp + libslic3r/GCode.cpp + libslic3r/LayerRegion.cpp + libslic3r/PerimeterGenerator.cpp + libslic3r/Polyline.cpp + libslic3r/SurfaceCollection.cpp + libslic3r/BridgeDetector.cpp + libslic3r/Extruder.cpp + libslic3r/GCodeSender.cpp + libslic3r/Line.cpp + libslic3r/PlaceholderParser.cpp + libslic3r/PrintConfig.cpp + libslic3r/Surface.cpp + libslic3r/ClipperUtils.cpp + libslic3r/ExtrusionEntityCollection.cpp + libslic3r/GCodeWriter.cpp + libslic3r/Model.cpp + libslic3r/Point.cpp + libslic3r/Print.cpp + libslic3r/SVG.cpp + libslic3r/SVGExport.cpp + libslic3r/Config.cpp + libslic3r/ExtrusionEntity.cpp + libslic3r/Geometry.cpp + libslic3r/MotionPlanner.cpp + libslic3r/Polygon.cpp + libslic3r/PrintObject.cpp + libslic3r/TriangleMesh.cpp + libslic3r/ExPolygonCollection.cpp + libslic3r/Flow.cpp + libslic3r/Layer.cpp + libslic3r/MultiPoint.cpp + libslic3r/PolylineCollection.cpp + libslic3r/PrintRegion.cpp) +add_library(admesh STATIC admesh/util.c admesh/stl_io.c admesh/stlinit.c admesh/shared.c admesh/normals.c admesh/connect.c) +add_library(clipper STATIC clipper.cpp) +add_library(polypartition STATIC polypartition.cpp) +add_library(poly2tri STATIC poly2tri/sweep/sweep.cc poly2tri/sweep/sweep_context.cc poly2tri/sweep/cdt.cc poly2tri/sweep/advancing_front.cc poly2tri/common/shapes.cc) +add_executable(slic3r slic3r.cpp) +set_target_properties(slic3r PROPERTIES LINK_SEARCH_START_STATIC 1) +set_target_properties(slic3r PROPERTIES LINK_SEARCH_END_STATIC 1) +set(wxWidgets_USE_STATIC) +SET(wxWidgets_USE_LIBS) + +set(Boost_USE_STATIC_LIBS ON) +set(Boost_USE_STATIC_RUNTIME ON) +set(CMAKE_FIND_LIBRARY_SUFFIXES ".a") +find_library(bsystem_l boost_system) +add_library(bsystem STATIC IMPORTED) +set_target_properties(bsystem PROPERTIES IMPORTED_LOCATION ${bsystem_l}) +find_library(bthread_l boost_thread) +add_library(bthread STATIC IMPORTED) +set_target_properties(bthread PROPERTIES IMPORTED_LOCATION ${bthread_l}) +include_directories(${Boost_INCLUDE_DIRS}) + +#find_package(wxWidgets) + +IF(wxWidgets_FOUND) + MESSAGE("wx found!") + INCLUDE("${wxWidgets_USE_FILE}") + target_link_libraries (slic3r slic3r_gui libslic3r admesh clipper polypartition poly2tri bsystem bthread ${wxWidgets_LIBRARIES}) +ELSE(wxWidgets_FOUND) + # For convenience. When we cannot continue, inform the user + MESSAGE("wx not found!") + target_link_libraries (slic3r slic3r_gui libslic3r admesh clipper polypartition poly2tri bsystem bthread) +ENDIF(wxWidgets_FOUND) + diff --git a/xs/src/libslic3r/SVGExport.cpp b/xs/src/libslic3r/SVGExport.cpp new file mode 100644 index 0000000000..f700ca34b3 --- /dev/null +++ b/xs/src/libslic3r/SVGExport.cpp @@ -0,0 +1,60 @@ +#include "SVGExport.hpp" +#include "SVG.hpp" +#include +#include +#define COORD(x) ((float)unscale(x)*10) + +namespace Slic3r { + +SVGExport::SVGExport(TriangleMesh &t, float layerheight, float firstlayerheight) + :t(&t), sliced(false) +{ + heights={}; + if(layerheight>0){ + for(float f=firstlayerheight;f<=t.stl.stats.max.z;f+=layerheight){ + heights.push_back(f); + } + + TriangleMeshSlicer(&t).slice(heights,&layers); + sliced=true; + } + +} + +// + +void SVGExport::writeSVG(const char* outputfile){ + if(sliced){ + FILE* f = fopen(outputfile, "w"); + fprintf(f, + "\n" + "\n" + "\n" + "\n" + ,t->stl.stats.max.x*10,t->stl.stats.max.y*10,SLIC3R_VERSION); + for (int i=0;i",i,heights[i]); + for (ExPolygons::const_iterator it = layers[i].begin(); it != layers[i].end(); ++it){ + std::string pd; + Polygons pp = *it; + for (Polygons::const_iterator mp = pp.begin(); mp != pp.end(); ++mp) { + std::ostringstream d; + d << "M "; + for (Points::const_iterator p = mp->points.begin(); p != mp->points.end(); ++p) { + d << COORD(p->x) << " "; + d << COORD(p->y) << " "; + } + d << "z"; + pd += d.str() + " "; + } + fprintf(f,"\t\t\n", + pd.c_str(),"white","black","0" + ); + } + fprintf(f,"\t\n"); + } + fprintf(f,"\n"); + } +} + +} diff --git a/xs/src/libslic3r/SVGExport.hpp b/xs/src/libslic3r/SVGExport.hpp new file mode 100644 index 0000000000..554e627b6b --- /dev/null +++ b/xs/src/libslic3r/SVGExport.hpp @@ -0,0 +1,25 @@ +#ifndef slic3r_SVGExport_hpp_ +#define slic3r_SVGExport_hpp_ + +#include "libslic3r.h" +#include "ExPolygon.hpp" +#include "SVG.hpp" +#include "TriangleMesh.hpp" + +namespace Slic3r { + +class SVGExport +{ + public: + SVGExport(TriangleMesh &t, float layerheight, float firstlayerheight=0.0); + void writeSVG(const char* outputfile); + private: + TriangleMesh *t; + std::vector layers; + std::vector heights; + bool sliced; +}; + +} + +#endif diff --git a/xs/src/slic3r.cpp b/xs/src/slic3r.cpp new file mode 100644 index 0000000000..219435ec0b --- /dev/null +++ b/xs/src/slic3r.cpp @@ -0,0 +1,64 @@ + + +#include "TriangleMesh.hpp" +#include "SVGExport.hpp" +#include "libslic3r.h" +#include +#include +#include +#include +#include "tclap/CmdLine.h" + +using namespace Slic3r; + +void confess_at(const char *file, int line, const char *func, const char *pat, ...){} + +void exportSVG(const char* stlname, const char* svgname, float layerheight=0.2, float initialheight=0., float scale=1.0, float rotate=0.){ + TriangleMesh t; + std::string outname; + if(strlen(svgname)==0){ + outname=outname+stlname+".svg"; + }else{ + outname=outname+svgname; + } + t.ReadSTLFile(const_cast(stlname)); + t.repair(); + t.scale(scale); + t.rotate_z(rotate); + t.align_to_origin(); + SVGExport e(t,layerheight,initialheight); + const char* svgfilename=outname.data(); + e.writeSVG(svgfilename); + printf("writing: %s\n",svgfilename); +} + +int main (int argc, char **argv){ + + try{ + TCLAP::CmdLine cmd("Rudimentary commandline slic3r, currently only supports STL to SVG slice export.", ' ', SLIC3R_VERSION); + TCLAP::ValueArg outputArg("o","output","File to output results to",false,"","output file name"); + cmd.add( outputArg ); + TCLAP::ValueArg scaleArg("","scale","Factor for scaling input object (default: 1)",false,1.0,"float"); + cmd.add( scaleArg ); + TCLAP::ValueArg rotArg("","rotate","Rotation angle in degrees (0-360, default: 0)",false,0.0,"float"); + cmd.add( rotArg ); + TCLAP::ValueArg flhArg("","first-layer-height","Layer height for first layer in mm (default: 0)",false,0.0,"float"); + cmd.add( flhArg ); + TCLAP::ValueArg lhArg("","layer-height","Layer height in mm (default: 0.2)",false,0.2,"float"); + cmd.add( lhArg ); + TCLAP::SwitchArg expsvg("","export-svg","Export a SVG file containing slices", cmd, false); + + TCLAP::UnlabeledValueArg input("inputfile","Input STL file name", true, "", "input file name"); + cmd.add(input); + cmd.parse(argc,argv); + if(expsvg.getValue()){ + exportSVG(input.getValue().data(),outputArg.getValue().data(),lhArg.getValue(),flhArg.getValue(),scaleArg.getValue(),rotArg.getValue()); + }else{ + std::cerr << "error: only svg export currently supported"<< std::endl; + return 1; + } + + }catch (TCLAP::ArgException &e) + { std::cerr << "error: " << e.error() << " for arg " << e.argId() << std::endl; } + +} diff --git a/xs/src/standalone/config.h b/xs/src/standalone/config.h new file mode 100644 index 0000000000..e69de29bb2 From 9872e9db33442748cfce90df0fcc7afe25fb7215 Mon Sep 17 00:00:00 2001 From: Kliment Yanev Date: Tue, 3 May 2016 15:35:13 +0200 Subject: [PATCH 02/58] Adding tclap headers --- xs/src/tclap/Arg.h | 692 ++++++++++++++++++++++++ xs/src/tclap/ArgException.h | 200 +++++++ xs/src/tclap/ArgTraits.h | 87 +++ xs/src/tclap/CmdLine.h | 633 ++++++++++++++++++++++ xs/src/tclap/CmdLineInterface.h | 150 +++++ xs/src/tclap/CmdLineOutput.h | 74 +++ xs/src/tclap/Constraint.h | 68 +++ xs/src/tclap/DocBookOutput.h | 299 ++++++++++ xs/src/tclap/HelpVisitor.h | 76 +++ xs/src/tclap/IgnoreRestVisitor.h | 52 ++ xs/src/tclap/Makefile.am | 28 + xs/src/tclap/Makefile.in | 403 ++++++++++++++ xs/src/tclap/MultiArg.h | 433 +++++++++++++++ xs/src/tclap/MultiSwitchArg.h | 216 ++++++++ xs/src/tclap/OptionalUnlabeledTracker.h | 62 +++ xs/src/tclap/StandardTraits.h | 208 +++++++ xs/src/tclap/StdOutput.h | 298 ++++++++++ xs/src/tclap/SwitchArg.h | 266 +++++++++ xs/src/tclap/UnlabeledMultiArg.h | 301 +++++++++++ xs/src/tclap/UnlabeledValueArg.h | 340 ++++++++++++ xs/src/tclap/ValueArg.h | 425 +++++++++++++++ xs/src/tclap/ValuesConstraint.h | 148 +++++ xs/src/tclap/VersionVisitor.h | 81 +++ xs/src/tclap/Visitor.h | 53 ++ xs/src/tclap/XorHandler.h | 166 ++++++ xs/src/tclap/ZshCompletionOutput.h | 323 +++++++++++ 26 files changed, 6082 insertions(+) create mode 100644 xs/src/tclap/Arg.h create mode 100644 xs/src/tclap/ArgException.h create mode 100644 xs/src/tclap/ArgTraits.h create mode 100644 xs/src/tclap/CmdLine.h create mode 100644 xs/src/tclap/CmdLineInterface.h create mode 100644 xs/src/tclap/CmdLineOutput.h create mode 100644 xs/src/tclap/Constraint.h create mode 100644 xs/src/tclap/DocBookOutput.h create mode 100644 xs/src/tclap/HelpVisitor.h create mode 100644 xs/src/tclap/IgnoreRestVisitor.h create mode 100644 xs/src/tclap/Makefile.am create mode 100644 xs/src/tclap/Makefile.in create mode 100644 xs/src/tclap/MultiArg.h create mode 100644 xs/src/tclap/MultiSwitchArg.h create mode 100644 xs/src/tclap/OptionalUnlabeledTracker.h create mode 100644 xs/src/tclap/StandardTraits.h create mode 100644 xs/src/tclap/StdOutput.h create mode 100644 xs/src/tclap/SwitchArg.h create mode 100644 xs/src/tclap/UnlabeledMultiArg.h create mode 100644 xs/src/tclap/UnlabeledValueArg.h create mode 100644 xs/src/tclap/ValueArg.h create mode 100644 xs/src/tclap/ValuesConstraint.h create mode 100644 xs/src/tclap/VersionVisitor.h create mode 100644 xs/src/tclap/Visitor.h create mode 100644 xs/src/tclap/XorHandler.h create mode 100644 xs/src/tclap/ZshCompletionOutput.h diff --git a/xs/src/tclap/Arg.h b/xs/src/tclap/Arg.h new file mode 100644 index 0000000000..b28eef117c --- /dev/null +++ b/xs/src/tclap/Arg.h @@ -0,0 +1,692 @@ +// -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*- + +/****************************************************************************** + * + * file: Arg.h + * + * Copyright (c) 2003, Michael E. Smoot . + * Copyright (c) 2004, Michael E. Smoot, Daniel Aarno . + * All rights reverved. + * + * See the file COPYING in the top directory of this distribution for + * more information. + * + * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + *****************************************************************************/ + + +#ifndef TCLAP_ARGUMENT_H +#define TCLAP_ARGUMENT_H + +#ifdef HAVE_CONFIG_H +#include +#else +#define HAVE_SSTREAM +#endif + +#include +#include +#include +#include +#include +#include + +#if defined(HAVE_SSTREAM) +#include +typedef std::istringstream istringstream; +#elif defined(HAVE_STRSTREAM) +#include +typedef std::istrstream istringstream; +#else +#error "Need a stringstream (sstream or strstream) to compile!" +#endif + +#include +#include +#include +#include +#include + +namespace TCLAP { + +/** + * A virtual base class that defines the essential data for all arguments. + * This class, or one of its existing children, must be subclassed to do + * anything. + */ +class Arg +{ + private: + /** + * Prevent accidental copying. + */ + Arg(const Arg& rhs); + + /** + * Prevent accidental copying. + */ + Arg& operator=(const Arg& rhs); + + /** + * Indicates whether the rest of the arguments should be ignored. + */ + static bool& ignoreRestRef() { static bool ign = false; return ign; } + + /** + * The delimiter that separates an argument flag/name from the + * value. + */ + static char& delimiterRef() { static char delim = ' '; return delim; } + + protected: + + /** + * The single char flag used to identify the argument. + * This value (preceded by a dash {-}), can be used to identify + * an argument on the command line. The _flag can be blank, + * in fact this is how unlabeled args work. Unlabeled args must + * override appropriate functions to get correct handling. Note + * that the _flag does NOT include the dash as part of the flag. + */ + std::string _flag; + + /** + * A single work namd indentifying the argument. + * This value (preceded by two dashed {--}) can also be used + * to identify an argument on the command line. Note that the + * _name does NOT include the two dashes as part of the _name. The + * _name cannot be blank. + */ + std::string _name; + + /** + * Description of the argument. + */ + std::string _description; + + /** + * Indicating whether the argument is required. + */ + bool _required; + + /** + * Label to be used in usage description. Normally set to + * "required", but can be changed when necessary. + */ + std::string _requireLabel; + + /** + * Indicates whether a value is required for the argument. + * Note that the value may be required but the argument/value + * combination may not be, as specified by _required. + */ + bool _valueRequired; + + /** + * Indicates whether the argument has been set. + * Indicates that a value on the command line has matched the + * name/flag of this argument and the values have been set accordingly. + */ + bool _alreadySet; + + /** + * A pointer to a vistitor object. + * The visitor allows special handling to occur as soon as the + * argument is matched. This defaults to NULL and should not + * be used unless absolutely necessary. + */ + Visitor* _visitor; + + /** + * Whether this argument can be ignored, if desired. + */ + bool _ignoreable; + + /** + * Indicates that the arg was set as part of an XOR and not on the + * command line. + */ + bool _xorSet; + + bool _acceptsMultipleValues; + + /** + * Performs the special handling described by the Vistitor. + */ + void _checkWithVisitor() const; + + /** + * Primary constructor. YOU (yes you) should NEVER construct an Arg + * directly, this is a base class that is extended by various children + * that are meant to be used. Use SwitchArg, ValueArg, MultiArg, + * UnlabeledValueArg, or UnlabeledMultiArg instead. + * + * \param flag - The flag identifying the argument. + * \param name - The name identifying the argument. + * \param desc - The description of the argument, used in the usage. + * \param req - Whether the argument is required. + * \param valreq - Whether the a value is required for the argument. + * \param v - The visitor checked by the argument. Defaults to NULL. + */ + Arg( const std::string& flag, + const std::string& name, + const std::string& desc, + bool req, + bool valreq, + Visitor* v = NULL ); + + public: + /** + * Destructor. + */ + virtual ~Arg(); + + /** + * Adds this to the specified list of Args. + * \param argList - The list to add this to. + */ + virtual void addToList( std::list& argList ) const; + + /** + * Begin ignoring arguments since the "--" argument was specified. + */ + static void beginIgnoring() { ignoreRestRef() = true; } + + /** + * Whether to ignore the rest. + */ + static bool ignoreRest() { return ignoreRestRef(); } + + /** + * The delimiter that separates an argument flag/name from the + * value. + */ + static char delimiter() { return delimiterRef(); } + + /** + * The char used as a place holder when SwitchArgs are combined. + * Currently set to the bell char (ASCII 7). + */ + static char blankChar() { return (char)7; } + + /** + * The char that indicates the beginning of a flag. Defaults to '-', but + * clients can define TCLAP_FLAGSTARTCHAR to override. + */ +#ifndef TCLAP_FLAGSTARTCHAR +#define TCLAP_FLAGSTARTCHAR '-' +#endif + static char flagStartChar() { return TCLAP_FLAGSTARTCHAR; } + + /** + * The sting that indicates the beginning of a flag. Defaults to "-", but + * clients can define TCLAP_FLAGSTARTSTRING to override. Should be the same + * as TCLAP_FLAGSTARTCHAR. + */ +#ifndef TCLAP_FLAGSTARTSTRING +#define TCLAP_FLAGSTARTSTRING "-" +#endif + static const std::string flagStartString() { return TCLAP_FLAGSTARTSTRING; } + + /** + * The sting that indicates the beginning of a name. Defaults to "--", but + * clients can define TCLAP_NAMESTARTSTRING to override. + */ +#ifndef TCLAP_NAMESTARTSTRING +#define TCLAP_NAMESTARTSTRING "--" +#endif + static const std::string nameStartString() { return TCLAP_NAMESTARTSTRING; } + + /** + * The name used to identify the ignore rest argument. + */ + static const std::string ignoreNameString() { return "ignore_rest"; } + + /** + * Sets the delimiter for all arguments. + * \param c - The character that delimits flags/names from values. + */ + static void setDelimiter( char c ) { delimiterRef() = c; } + + /** + * Pure virtual method meant to handle the parsing and value assignment + * of the string on the command line. + * \param i - Pointer the the current argument in the list. + * \param args - Mutable list of strings. What is + * passed in from main. + */ + virtual bool processArg(int *i, std::vector& args) = 0; + + /** + * Operator ==. + * Equality operator. Must be virtual to handle unlabeled args. + * \param a - The Arg to be compared to this. + */ + virtual bool operator==(const Arg& a) const; + + /** + * Returns the argument flag. + */ + const std::string& getFlag() const; + + /** + * Returns the argument name. + */ + const std::string& getName() const; + + /** + * Returns the argument description. + */ + std::string getDescription() const; + + /** + * Indicates whether the argument is required. + */ + virtual bool isRequired() const; + + /** + * Sets _required to true. This is used by the XorHandler. + * You really have no reason to ever use it. + */ + void forceRequired(); + + /** + * Sets the _alreadySet value to true. This is used by the XorHandler. + * You really have no reason to ever use it. + */ + void xorSet(); + + /** + * Indicates whether a value must be specified for argument. + */ + bool isValueRequired() const; + + /** + * Indicates whether the argument has already been set. Only true + * if the arg has been matched on the command line. + */ + bool isSet() const; + + /** + * Indicates whether the argument can be ignored, if desired. + */ + bool isIgnoreable() const; + + /** + * A method that tests whether a string matches this argument. + * This is generally called by the processArg() method. This + * method could be re-implemented by a child to change how + * arguments are specified on the command line. + * \param s - The string to be compared to the flag/name to determine + * whether the arg matches. + */ + virtual bool argMatches( const std::string& s ) const; + + /** + * Returns a simple string representation of the argument. + * Primarily for debugging. + */ + virtual std::string toString() const; + + /** + * Returns a short ID for the usage. + * \param valueId - The value used in the id. + */ + virtual std::string shortID( const std::string& valueId = "val" ) const; + + /** + * Returns a long ID for the usage. + * \param valueId - The value used in the id. + */ + virtual std::string longID( const std::string& valueId = "val" ) const; + + /** + * Trims a value off of the flag. + * \param flag - The string from which the flag and value will be + * trimmed. Contains the flag once the value has been trimmed. + * \param value - Where the value trimmed from the string will + * be stored. + */ + virtual void trimFlag( std::string& flag, std::string& value ) const; + + /** + * Checks whether a given string has blank chars, indicating that + * it is a combined SwitchArg. If so, return true, otherwise return + * false. + * \param s - string to be checked. + */ + bool _hasBlanks( const std::string& s ) const; + + /** + * Sets the requireLabel. Used by XorHandler. You shouldn't ever + * use this. + * \param s - Set the requireLabel to this value. + */ + void setRequireLabel( const std::string& s ); + + /** + * Used for MultiArgs and XorHandler to determine whether args + * can still be set. + */ + virtual bool allowMore(); + + /** + * Use by output classes to determine whether an Arg accepts + * multiple values. + */ + virtual bool acceptsMultipleValues(); + + /** + * Clears the Arg object and allows it to be reused by new + * command lines. + */ + virtual void reset(); +}; + +/** + * Typedef of an Arg list iterator. + */ +typedef std::list::iterator ArgListIterator; + +/** + * Typedef of an Arg vector iterator. + */ +typedef std::vector::iterator ArgVectorIterator; + +/** + * Typedef of a Visitor list iterator. + */ +typedef std::list::iterator VisitorListIterator; + +/* + * Extract a value of type T from it's string representation contained + * in strVal. The ValueLike parameter used to select the correct + * specialization of ExtractValue depending on the value traits of T. + * ValueLike traits use operator>> to assign the value from strVal. + */ +template void +ExtractValue(T &destVal, const std::string& strVal, ValueLike vl) +{ + static_cast(vl); // Avoid warning about unused vl + std::istringstream is(strVal); + + int valuesRead = 0; + while ( is.good() ) { + if ( is.peek() != EOF ) +#ifdef TCLAP_SETBASE_ZERO + is >> std::setbase(0) >> destVal; +#else + is >> destVal; +#endif + else + break; + + valuesRead++; + } + + if ( is.fail() ) + throw( ArgParseException("Couldn't read argument value " + "from string '" + strVal + "'")); + + + if ( valuesRead > 1 ) + throw( ArgParseException("More than one valid value parsed from " + "string '" + strVal + "'")); + +} + +/* + * Extract a value of type T from it's string representation contained + * in strVal. The ValueLike parameter used to select the correct + * specialization of ExtractValue depending on the value traits of T. + * StringLike uses assignment (operator=) to assign from strVal. + */ +template void +ExtractValue(T &destVal, const std::string& strVal, StringLike sl) +{ + static_cast(sl); // Avoid warning about unused sl + SetString(destVal, strVal); +} + +////////////////////////////////////////////////////////////////////// +//BEGIN Arg.cpp +////////////////////////////////////////////////////////////////////// + +inline Arg::Arg(const std::string& flag, + const std::string& name, + const std::string& desc, + bool req, + bool valreq, + Visitor* v) : + _flag(flag), + _name(name), + _description(desc), + _required(req), + _requireLabel("required"), + _valueRequired(valreq), + _alreadySet(false), + _visitor( v ), + _ignoreable(true), + _xorSet(false), + _acceptsMultipleValues(false) +{ + if ( _flag.length() > 1 ) + throw(SpecificationException( + "Argument flag can only be one character long", toString() ) ); + + if ( _name != ignoreNameString() && + ( _flag == Arg::flagStartString() || + _flag == Arg::nameStartString() || + _flag == " " ) ) + throw(SpecificationException("Argument flag cannot be either '" + + Arg::flagStartString() + "' or '" + + Arg::nameStartString() + "' or a space.", + toString() ) ); + + if ( ( _name.substr( 0, Arg::flagStartString().length() ) == Arg::flagStartString() ) || + ( _name.substr( 0, Arg::nameStartString().length() ) == Arg::nameStartString() ) || + ( _name.find( " ", 0 ) != std::string::npos ) ) + throw(SpecificationException("Argument name begin with either '" + + Arg::flagStartString() + "' or '" + + Arg::nameStartString() + "' or space.", + toString() ) ); + +} + +inline Arg::~Arg() { } + +inline std::string Arg::shortID( const std::string& valueId ) const +{ + std::string id = ""; + + if ( _flag != "" ) + id = Arg::flagStartString() + _flag; + else + id = Arg::nameStartString() + _name; + + if ( _valueRequired ) + id += std::string( 1, Arg::delimiter() ) + "<" + valueId + ">"; + + if ( !_required ) + id = "[" + id + "]"; + + return id; +} + +inline std::string Arg::longID( const std::string& valueId ) const +{ + std::string id = ""; + + if ( _flag != "" ) + { + id += Arg::flagStartString() + _flag; + + if ( _valueRequired ) + id += std::string( 1, Arg::delimiter() ) + "<" + valueId + ">"; + + id += ", "; + } + + id += Arg::nameStartString() + _name; + + if ( _valueRequired ) + id += std::string( 1, Arg::delimiter() ) + "<" + valueId + ">"; + + return id; + +} + +inline bool Arg::operator==(const Arg& a) const +{ + if ( ( _flag != "" && _flag == a._flag ) || _name == a._name) + return true; + else + return false; +} + +inline std::string Arg::getDescription() const +{ + std::string desc = ""; + if ( _required ) + desc = "(" + _requireLabel + ") "; + +// if ( _valueRequired ) +// desc += "(value required) "; + + desc += _description; + return desc; +} + +inline const std::string& Arg::getFlag() const { return _flag; } + +inline const std::string& Arg::getName() const { return _name; } + +inline bool Arg::isRequired() const { return _required; } + +inline bool Arg::isValueRequired() const { return _valueRequired; } + +inline bool Arg::isSet() const +{ + if ( _alreadySet && !_xorSet ) + return true; + else + return false; +} + +inline bool Arg::isIgnoreable() const { return _ignoreable; } + +inline void Arg::setRequireLabel( const std::string& s) +{ + _requireLabel = s; +} + +inline bool Arg::argMatches( const std::string& argFlag ) const +{ + if ( ( argFlag == Arg::flagStartString() + _flag && _flag != "" ) || + argFlag == Arg::nameStartString() + _name ) + return true; + else + return false; +} + +inline std::string Arg::toString() const +{ + std::string s = ""; + + if ( _flag != "" ) + s += Arg::flagStartString() + _flag + " "; + + s += "(" + Arg::nameStartString() + _name + ")"; + + return s; +} + +inline void Arg::_checkWithVisitor() const +{ + if ( _visitor != NULL ) + _visitor->visit(); +} + +/** + * Implementation of trimFlag. + */ +inline void Arg::trimFlag(std::string& flag, std::string& value) const +{ + int stop = 0; + for ( int i = 0; static_cast(i) < flag.length(); i++ ) + if ( flag[i] == Arg::delimiter() ) + { + stop = i; + break; + } + + if ( stop > 1 ) + { + value = flag.substr(stop+1); + flag = flag.substr(0,stop); + } + +} + +/** + * Implementation of _hasBlanks. + */ +inline bool Arg::_hasBlanks( const std::string& s ) const +{ + for ( int i = 1; static_cast(i) < s.length(); i++ ) + if ( s[i] == Arg::blankChar() ) + return true; + + return false; +} + +inline void Arg::forceRequired() +{ + _required = true; +} + +inline void Arg::xorSet() +{ + _alreadySet = true; + _xorSet = true; +} + +/** + * Overridden by Args that need to added to the end of the list. + */ +inline void Arg::addToList( std::list& argList ) const +{ + argList.push_front( const_cast(this) ); +} + +inline bool Arg::allowMore() +{ + return false; +} + +inline bool Arg::acceptsMultipleValues() +{ + return _acceptsMultipleValues; +} + +inline void Arg::reset() +{ + _xorSet = false; + _alreadySet = false; +} + +////////////////////////////////////////////////////////////////////// +//END Arg.cpp +////////////////////////////////////////////////////////////////////// + +} //namespace TCLAP + +#endif + diff --git a/xs/src/tclap/ArgException.h b/xs/src/tclap/ArgException.h new file mode 100644 index 0000000000..3411aa9543 --- /dev/null +++ b/xs/src/tclap/ArgException.h @@ -0,0 +1,200 @@ +// -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*- + +/****************************************************************************** + * + * file: ArgException.h + * + * Copyright (c) 2003, Michael E. Smoot . + * All rights reverved. + * + * See the file COPYING in the top directory of this distribution for + * more information. + * + * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + *****************************************************************************/ + + +#ifndef TCLAP_ARG_EXCEPTION_H +#define TCLAP_ARG_EXCEPTION_H + +#include +#include + +namespace TCLAP { + +/** + * A simple class that defines and argument exception. Should be caught + * whenever a CmdLine is created and parsed. + */ +class ArgException : public std::exception +{ + public: + + /** + * Constructor. + * \param text - The text of the exception. + * \param id - The text identifying the argument source. + * \param td - Text describing the type of ArgException it is. + * of the exception. + */ + ArgException( const std::string& text = "undefined exception", + const std::string& id = "undefined", + const std::string& td = "Generic ArgException") + : std::exception(), + _errorText(text), + _argId( id ), + _typeDescription(td) + { } + + /** + * Destructor. + */ + virtual ~ArgException() throw() { } + + /** + * Returns the error text. + */ + std::string error() const { return ( _errorText ); } + + /** + * Returns the argument id. + */ + std::string argId() const + { + if ( _argId == "undefined" ) + return " "; + else + return ( "Argument: " + _argId ); + } + + /** + * Returns the arg id and error text. + */ + const char* what() const throw() + { + static std::string ex; + ex = _argId + " -- " + _errorText; + return ex.c_str(); + } + + /** + * Returns the type of the exception. Used to explain and distinguish + * between different child exceptions. + */ + std::string typeDescription() const + { + return _typeDescription; + } + + + private: + + /** + * The text of the exception message. + */ + std::string _errorText; + + /** + * The argument related to this exception. + */ + std::string _argId; + + /** + * Describes the type of the exception. Used to distinguish + * between different child exceptions. + */ + std::string _typeDescription; + +}; + +/** + * Thrown from within the child Arg classes when it fails to properly + * parse the argument it has been passed. + */ +class ArgParseException : public ArgException +{ + public: + /** + * Constructor. + * \param text - The text of the exception. + * \param id - The text identifying the argument source + * of the exception. + */ + ArgParseException( const std::string& text = "undefined exception", + const std::string& id = "undefined" ) + : ArgException( text, + id, + std::string( "Exception found while parsing " ) + + std::string( "the value the Arg has been passed." )) + { } +}; + +/** + * Thrown from CmdLine when the arguments on the command line are not + * properly specified, e.g. too many arguments, required argument missing, etc. + */ +class CmdLineParseException : public ArgException +{ + public: + /** + * Constructor. + * \param text - The text of the exception. + * \param id - The text identifying the argument source + * of the exception. + */ + CmdLineParseException( const std::string& text = "undefined exception", + const std::string& id = "undefined" ) + : ArgException( text, + id, + std::string( "Exception found when the values ") + + std::string( "on the command line do not meet ") + + std::string( "the requirements of the defined ") + + std::string( "Args." )) + { } +}; + +/** + * Thrown from Arg and CmdLine when an Arg is improperly specified, e.g. + * same flag as another Arg, same name, etc. + */ +class SpecificationException : public ArgException +{ + public: + /** + * Constructor. + * \param text - The text of the exception. + * \param id - The text identifying the argument source + * of the exception. + */ + SpecificationException( const std::string& text = "undefined exception", + const std::string& id = "undefined" ) + : ArgException( text, + id, + std::string("Exception found when an Arg object ")+ + std::string("is improperly defined by the ") + + std::string("developer." )) + { } + +}; + +class ExitException { +public: + ExitException(int estat) : _estat(estat) {} + + int getExitStatus() const { return _estat; } + +private: + int _estat; +}; + +} // namespace TCLAP + +#endif + diff --git a/xs/src/tclap/ArgTraits.h b/xs/src/tclap/ArgTraits.h new file mode 100644 index 0000000000..0b2c18f70c --- /dev/null +++ b/xs/src/tclap/ArgTraits.h @@ -0,0 +1,87 @@ +// -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*- + +/****************************************************************************** + * + * file: ArgTraits.h + * + * Copyright (c) 2007, Daniel Aarno, Michael E. Smoot . + * All rights reverved. + * + * See the file COPYING in the top directory of this distribution for + * more information. + * + * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + *****************************************************************************/ + +// This is an internal tclap file, you should probably not have to +// include this directly + +#ifndef TCLAP_ARGTRAITS_H +#define TCLAP_ARGTRAITS_H + +namespace TCLAP { + +// We use two empty structs to get compile type specialization +// function to work + +/** + * A value like argument value type is a value that can be set using + * operator>>. This is the default value type. + */ +struct ValueLike { + typedef ValueLike ValueCategory; + virtual ~ValueLike() {} +}; + +/** + * A string like argument value type is a value that can be set using + * operator=(string). Usefull if the value type contains spaces which + * will be broken up into individual tokens by operator>>. + */ +struct StringLike { + virtual ~StringLike() {} +}; + +/** + * A class can inherit from this object to make it have string like + * traits. This is a compile time thing and does not add any overhead + * to the inherenting class. + */ +struct StringLikeTrait { + typedef StringLike ValueCategory; + virtual ~StringLikeTrait() {} +}; + +/** + * A class can inherit from this object to make it have value like + * traits. This is a compile time thing and does not add any overhead + * to the inherenting class. + */ +struct ValueLikeTrait { + typedef ValueLike ValueCategory; + virtual ~ValueLikeTrait() {} +}; + +/** + * Arg traits are used to get compile type specialization when parsing + * argument values. Using an ArgTraits you can specify the way that + * values gets assigned to any particular type during parsing. The two + * supported types are StringLike and ValueLike. + */ +template +struct ArgTraits { + typedef typename T::ValueCategory ValueCategory; + virtual ~ArgTraits() {} + //typedef ValueLike ValueCategory; +}; + +#endif + +} // namespace diff --git a/xs/src/tclap/CmdLine.h b/xs/src/tclap/CmdLine.h new file mode 100644 index 0000000000..0fec8d8a11 --- /dev/null +++ b/xs/src/tclap/CmdLine.h @@ -0,0 +1,633 @@ +// -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*- + +/****************************************************************************** + * + * file: CmdLine.h + * + * Copyright (c) 2003, Michael E. Smoot . + * Copyright (c) 2004, Michael E. Smoot, Daniel Aarno. + * All rights reverved. + * + * See the file COPYING in the top directory of this distribution for + * more information. + * + * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + *****************************************************************************/ + +#ifndef TCLAP_CMDLINE_H +#define TCLAP_CMDLINE_H + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include + +#include +#include + +#include +#include +#include +#include +#include +#include +#include // Needed for exit(), which isn't defined in some envs. + +namespace TCLAP { + +template void DelPtr(T ptr) +{ + delete ptr; +} + +template void ClearContainer(C &c) +{ + typedef typename C::value_type value_type; + std::for_each(c.begin(), c.end(), DelPtr); + c.clear(); +} + + +/** + * The base class that manages the command line definition and passes + * along the parsing to the appropriate Arg classes. + */ +class CmdLine : public CmdLineInterface +{ + protected: + + /** + * The list of arguments that will be tested against the + * command line. + */ + std::list _argList; + + /** + * The name of the program. Set to argv[0]. + */ + std::string _progName; + + /** + * A message used to describe the program. Used in the usage output. + */ + std::string _message; + + /** + * The version to be displayed with the --version switch. + */ + std::string _version; + + /** + * The number of arguments that are required to be present on + * the command line. This is set dynamically, based on the + * Args added to the CmdLine object. + */ + int _numRequired; + + /** + * The character that is used to separate the argument flag/name + * from the value. Defaults to ' ' (space). + */ + char _delimiter; + + /** + * The handler that manages xoring lists of args. + */ + XorHandler _xorHandler; + + /** + * A list of Args to be explicitly deleted when the destructor + * is called. At the moment, this only includes the three default + * Args. + */ + std::list _argDeleteOnExitList; + + /** + * A list of Visitors to be explicitly deleted when the destructor + * is called. At the moment, these are the Vistors created for the + * default Args. + */ + std::list _visitorDeleteOnExitList; + + /** + * Object that handles all output for the CmdLine. + */ + CmdLineOutput* _output; + + /** + * Should CmdLine handle parsing exceptions internally? + */ + bool _handleExceptions; + + /** + * Throws an exception listing the missing args. + */ + void missingArgsException(); + + /** + * Checks whether a name/flag string matches entirely matches + * the Arg::blankChar. Used when multiple switches are combined + * into a single argument. + * \param s - The message to be used in the usage. + */ + bool _emptyCombined(const std::string& s); + + /** + * Perform a delete ptr; operation on ptr when this object is deleted. + */ + void deleteOnExit(Arg* ptr); + + /** + * Perform a delete ptr; operation on ptr when this object is deleted. + */ + void deleteOnExit(Visitor* ptr); + +private: + + /** + * Prevent accidental copying. + */ + CmdLine(const CmdLine& rhs); + CmdLine& operator=(const CmdLine& rhs); + + /** + * Encapsulates the code common to the constructors + * (which is all of it). + */ + void _constructor(); + + + /** + * Is set to true when a user sets the output object. We use this so + * that we don't delete objects that are created outside of this lib. + */ + bool _userSetOutput; + + /** + * Whether or not to automatically create help and version switches. + */ + bool _helpAndVersion; + + public: + + /** + * Command line constructor. Defines how the arguments will be + * parsed. + * \param message - The message to be used in the usage + * output. + * \param delimiter - The character that is used to separate + * the argument flag/name from the value. Defaults to ' ' (space). + * \param version - The version number to be used in the + * --version switch. + * \param helpAndVersion - Whether or not to create the Help and + * Version switches. Defaults to true. + */ + CmdLine(const std::string& message, + const char delimiter = ' ', + const std::string& version = "none", + bool helpAndVersion = true); + + /** + * Deletes any resources allocated by a CmdLine object. + */ + virtual ~CmdLine(); + + /** + * Adds an argument to the list of arguments to be parsed. + * \param a - Argument to be added. + */ + void add( Arg& a ); + + /** + * An alternative add. Functionally identical. + * \param a - Argument to be added. + */ + void add( Arg* a ); + + /** + * Add two Args that will be xor'd. If this method is used, add does + * not need to be called. + * \param a - Argument to be added and xor'd. + * \param b - Argument to be added and xor'd. + */ + void xorAdd( Arg& a, Arg& b ); + + /** + * Add a list of Args that will be xor'd. If this method is used, + * add does not need to be called. + * \param xors - List of Args to be added and xor'd. + */ + void xorAdd( std::vector& xors ); + + /** + * Parses the command line. + * \param argc - Number of arguments. + * \param argv - Array of arguments. + */ + void parse(int argc, const char * const * argv); + + /** + * Parses the command line. + * \param args - A vector of strings representing the args. + * args[0] is still the program name. + */ + void parse(std::vector& args); + + /** + * + */ + CmdLineOutput* getOutput(); + + /** + * + */ + void setOutput(CmdLineOutput* co); + + /** + * + */ + std::string& getVersion(); + + /** + * + */ + std::string& getProgramName(); + + /** + * + */ + std::list& getArgList(); + + /** + * + */ + XorHandler& getXorHandler(); + + /** + * + */ + char getDelimiter(); + + /** + * + */ + std::string& getMessage(); + + /** + * + */ + bool hasHelpAndVersion(); + + /** + * Disables or enables CmdLine's internal parsing exception handling. + * + * @param state Should CmdLine handle parsing exceptions internally? + */ + void setExceptionHandling(const bool state); + + /** + * Returns the current state of the internal exception handling. + * + * @retval true Parsing exceptions are handled internally. + * @retval false Parsing exceptions are propagated to the caller. + */ + bool getExceptionHandling() const; + + /** + * Allows the CmdLine object to be reused. + */ + void reset(); + +}; + + +/////////////////////////////////////////////////////////////////////////////// +//Begin CmdLine.cpp +/////////////////////////////////////////////////////////////////////////////// + +inline CmdLine::CmdLine(const std::string& m, + char delim, + const std::string& v, + bool help ) + : + _argList(std::list()), + _progName("not_set_yet"), + _message(m), + _version(v), + _numRequired(0), + _delimiter(delim), + _xorHandler(XorHandler()), + _argDeleteOnExitList(std::list()), + _visitorDeleteOnExitList(std::list()), + _output(0), + _handleExceptions(true), + _userSetOutput(false), + _helpAndVersion(help) +{ + _constructor(); +} + +inline CmdLine::~CmdLine() +{ + ClearContainer(_argDeleteOnExitList); + ClearContainer(_visitorDeleteOnExitList); + + if ( !_userSetOutput ) { + delete _output; + _output = 0; + } +} + +inline void CmdLine::_constructor() +{ + _output = new StdOutput; + + Arg::setDelimiter( _delimiter ); + + Visitor* v; + + if ( _helpAndVersion ) + { + v = new HelpVisitor( this, &_output ); + SwitchArg* help = new SwitchArg("h","help", + "Displays usage information and exits.", + false, v); + add( help ); + deleteOnExit(help); + deleteOnExit(v); + + v = new VersionVisitor( this, &_output ); + SwitchArg* vers = new SwitchArg("","version", + "Displays version information and exits.", + false, v); + add( vers ); + deleteOnExit(vers); + deleteOnExit(v); + } + + v = new IgnoreRestVisitor(); + SwitchArg* ignore = new SwitchArg(Arg::flagStartString(), + Arg::ignoreNameString(), + "Ignores the rest of the labeled arguments following this flag.", + false, v); + add( ignore ); + deleteOnExit(ignore); + deleteOnExit(v); +} + +inline void CmdLine::xorAdd( std::vector& ors ) +{ + _xorHandler.add( ors ); + + for (ArgVectorIterator it = ors.begin(); it != ors.end(); it++) + { + (*it)->forceRequired(); + (*it)->setRequireLabel( "OR required" ); + add( *it ); + } +} + +inline void CmdLine::xorAdd( Arg& a, Arg& b ) +{ + std::vector ors; + ors.push_back( &a ); + ors.push_back( &b ); + xorAdd( ors ); +} + +inline void CmdLine::add( Arg& a ) +{ + add( &a ); +} + +inline void CmdLine::add( Arg* a ) +{ + for( ArgListIterator it = _argList.begin(); it != _argList.end(); it++ ) + if ( *a == *(*it) ) + throw( SpecificationException( + "Argument with same flag/name already exists!", + a->longID() ) ); + + a->addToList( _argList ); + + if ( a->isRequired() ) + _numRequired++; +} + + +inline void CmdLine::parse(int argc, const char * const * argv) +{ + // this step is necessary so that we have easy access to + // mutable strings. + std::vector args; + for (int i = 0; i < argc; i++) + args.push_back(argv[i]); + + parse(args); +} + +inline void CmdLine::parse(std::vector& args) +{ + bool shouldExit = false; + int estat = 0; + + try { + _progName = args.front(); + args.erase(args.begin()); + + int requiredCount = 0; + + for (int i = 0; static_cast(i) < args.size(); i++) + { + bool matched = false; + for (ArgListIterator it = _argList.begin(); + it != _argList.end(); it++) { + if ( (*it)->processArg( &i, args ) ) + { + requiredCount += _xorHandler.check( *it ); + matched = true; + break; + } + } + + // checks to see if the argument is an empty combined + // switch and if so, then we've actually matched it + if ( !matched && _emptyCombined( args[i] ) ) + matched = true; + + if ( !matched && !Arg::ignoreRest() ) + throw(CmdLineParseException("Couldn't find match " + "for argument", + args[i])); + } + + if ( requiredCount < _numRequired ) + missingArgsException(); + + if ( requiredCount > _numRequired ) + throw(CmdLineParseException("Too many arguments!")); + + } catch ( ArgException& e ) { + // If we're not handling the exceptions, rethrow. + if ( !_handleExceptions) { + throw; + } + + try { + _output->failure(*this,e); + } catch ( ExitException &ee ) { + estat = ee.getExitStatus(); + shouldExit = true; + } + } catch (ExitException &ee) { + // If we're not handling the exceptions, rethrow. + if ( !_handleExceptions) { + throw; + } + + estat = ee.getExitStatus(); + shouldExit = true; + } + + if (shouldExit) + exit(estat); +} + +inline bool CmdLine::_emptyCombined(const std::string& s) +{ + if ( s.length() > 0 && s[0] != Arg::flagStartChar() ) + return false; + + for ( int i = 1; static_cast(i) < s.length(); i++ ) + if ( s[i] != Arg::blankChar() ) + return false; + + return true; +} + +inline void CmdLine::missingArgsException() +{ + int count = 0; + + std::string missingArgList; + for (ArgListIterator it = _argList.begin(); it != _argList.end(); it++) + { + if ( (*it)->isRequired() && !(*it)->isSet() ) + { + missingArgList += (*it)->getName(); + missingArgList += ", "; + count++; + } + } + missingArgList = missingArgList.substr(0,missingArgList.length()-2); + + std::string msg; + if ( count > 1 ) + msg = "Required arguments missing: "; + else + msg = "Required argument missing: "; + + msg += missingArgList; + + throw(CmdLineParseException(msg)); +} + +inline void CmdLine::deleteOnExit(Arg* ptr) +{ + _argDeleteOnExitList.push_back(ptr); +} + +inline void CmdLine::deleteOnExit(Visitor* ptr) +{ + _visitorDeleteOnExitList.push_back(ptr); +} + +inline CmdLineOutput* CmdLine::getOutput() +{ + return _output; +} + +inline void CmdLine::setOutput(CmdLineOutput* co) +{ + if ( !_userSetOutput ) + delete _output; + _userSetOutput = true; + _output = co; +} + +inline std::string& CmdLine::getVersion() +{ + return _version; +} + +inline std::string& CmdLine::getProgramName() +{ + return _progName; +} + +inline std::list& CmdLine::getArgList() +{ + return _argList; +} + +inline XorHandler& CmdLine::getXorHandler() +{ + return _xorHandler; +} + +inline char CmdLine::getDelimiter() +{ + return _delimiter; +} + +inline std::string& CmdLine::getMessage() +{ + return _message; +} + +inline bool CmdLine::hasHelpAndVersion() +{ + return _helpAndVersion; +} + +inline void CmdLine::setExceptionHandling(const bool state) +{ + _handleExceptions = state; +} + +inline bool CmdLine::getExceptionHandling() const +{ + return _handleExceptions; +} + +inline void CmdLine::reset() +{ + for( ArgListIterator it = _argList.begin(); it != _argList.end(); it++ ) + (*it)->reset(); + + _progName.clear(); +} + +/////////////////////////////////////////////////////////////////////////////// +//End CmdLine.cpp +/////////////////////////////////////////////////////////////////////////////// + + + +} //namespace TCLAP +#endif diff --git a/xs/src/tclap/CmdLineInterface.h b/xs/src/tclap/CmdLineInterface.h new file mode 100644 index 0000000000..1b25e9b8c9 --- /dev/null +++ b/xs/src/tclap/CmdLineInterface.h @@ -0,0 +1,150 @@ + +/****************************************************************************** + * + * file: CmdLineInterface.h + * + * Copyright (c) 2003, Michael E. Smoot . + * Copyright (c) 2004, Michael E. Smoot, Daniel Aarno. + * All rights reverved. + * + * See the file COPYING in the top directory of this distribution for + * more information. + * + * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + *****************************************************************************/ + +#ifndef TCLAP_COMMANDLINE_INTERFACE_H +#define TCLAP_COMMANDLINE_INTERFACE_H + +#include +#include +#include +#include +#include + + +namespace TCLAP { + +class Arg; +class CmdLineOutput; +class XorHandler; + +/** + * The base class that manages the command line definition and passes + * along the parsing to the appropriate Arg classes. + */ +class CmdLineInterface +{ + public: + + /** + * Destructor + */ + virtual ~CmdLineInterface() {} + + /** + * Adds an argument to the list of arguments to be parsed. + * \param a - Argument to be added. + */ + virtual void add( Arg& a )=0; + + /** + * An alternative add. Functionally identical. + * \param a - Argument to be added. + */ + virtual void add( Arg* a )=0; + + /** + * Add two Args that will be xor'd. + * If this method is used, add does + * not need to be called. + * \param a - Argument to be added and xor'd. + * \param b - Argument to be added and xor'd. + */ + virtual void xorAdd( Arg& a, Arg& b )=0; + + /** + * Add a list of Args that will be xor'd. If this method is used, + * add does not need to be called. + * \param xors - List of Args to be added and xor'd. + */ + virtual void xorAdd( std::vector& xors )=0; + + /** + * Parses the command line. + * \param argc - Number of arguments. + * \param argv - Array of arguments. + */ + virtual void parse(int argc, const char * const * argv)=0; + + /** + * Parses the command line. + * \param args - A vector of strings representing the args. + * args[0] is still the program name. + */ + void parse(std::vector& args); + + /** + * Returns the CmdLineOutput object. + */ + virtual CmdLineOutput* getOutput()=0; + + /** + * \param co - CmdLineOutput object that we want to use instead. + */ + virtual void setOutput(CmdLineOutput* co)=0; + + /** + * Returns the version string. + */ + virtual std::string& getVersion()=0; + + /** + * Returns the program name string. + */ + virtual std::string& getProgramName()=0; + + /** + * Returns the argList. + */ + virtual std::list& getArgList()=0; + + /** + * Returns the XorHandler. + */ + virtual XorHandler& getXorHandler()=0; + + /** + * Returns the delimiter string. + */ + virtual char getDelimiter()=0; + + /** + * Returns the message string. + */ + virtual std::string& getMessage()=0; + + /** + * Indicates whether or not the help and version switches were created + * automatically. + */ + virtual bool hasHelpAndVersion()=0; + + /** + * Resets the instance as if it had just been constructed so that the + * instance can be reused. + */ + virtual void reset()=0; +}; + +} //namespace + + +#endif diff --git a/xs/src/tclap/CmdLineOutput.h b/xs/src/tclap/CmdLineOutput.h new file mode 100644 index 0000000000..71ee5a3b41 --- /dev/null +++ b/xs/src/tclap/CmdLineOutput.h @@ -0,0 +1,74 @@ + + +/****************************************************************************** + * + * file: CmdLineOutput.h + * + * Copyright (c) 2004, Michael E. Smoot + * All rights reverved. + * + * See the file COPYING in the top directory of this distribution for + * more information. + * + * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + *****************************************************************************/ + +#ifndef TCLAP_CMDLINEOUTPUT_H +#define TCLAP_CMDLINEOUTPUT_H + +#include +#include +#include +#include +#include +#include + +namespace TCLAP { + +class CmdLineInterface; +class ArgException; + +/** + * The interface that any output object must implement. + */ +class CmdLineOutput +{ + + public: + + /** + * Virtual destructor. + */ + virtual ~CmdLineOutput() {} + + /** + * Generates some sort of output for the USAGE. + * \param c - The CmdLine object the output is generated for. + */ + virtual void usage(CmdLineInterface& c)=0; + + /** + * Generates some sort of output for the version. + * \param c - The CmdLine object the output is generated for. + */ + virtual void version(CmdLineInterface& c)=0; + + /** + * Generates some sort of output for a failure. + * \param c - The CmdLine object the output is generated for. + * \param e - The ArgException that caused the failure. + */ + virtual void failure( CmdLineInterface& c, + ArgException& e )=0; + +}; + +} //namespace TCLAP +#endif diff --git a/xs/src/tclap/Constraint.h b/xs/src/tclap/Constraint.h new file mode 100644 index 0000000000..a92acf9a9a --- /dev/null +++ b/xs/src/tclap/Constraint.h @@ -0,0 +1,68 @@ + +/****************************************************************************** + * + * file: Constraint.h + * + * Copyright (c) 2005, Michael E. Smoot + * All rights reverved. + * + * See the file COPYING in the top directory of this distribution for + * more information. + * + * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + *****************************************************************************/ + +#ifndef TCLAP_CONSTRAINT_H +#define TCLAP_CONSTRAINT_H + +#include +#include +#include +#include +#include +#include + +namespace TCLAP { + +/** + * The interface that defines the interaction between the Arg and Constraint. + */ +template +class Constraint +{ + + public: + /** + * Returns a description of the Constraint. + */ + virtual std::string description() const =0; + + /** + * Returns the short ID for the Constraint. + */ + virtual std::string shortID() const =0; + + /** + * The method used to verify that the value parsed from the command + * line meets the constraint. + * \param value - The value that will be checked. + */ + virtual bool check(const T& value) const =0; + + /** + * Destructor. + * Silences warnings about Constraint being a base class with virtual + * functions but without a virtual destructor. + */ + virtual ~Constraint() { ; } +}; + +} //namespace TCLAP +#endif diff --git a/xs/src/tclap/DocBookOutput.h b/xs/src/tclap/DocBookOutput.h new file mode 100644 index 0000000000..a42ca274df --- /dev/null +++ b/xs/src/tclap/DocBookOutput.h @@ -0,0 +1,299 @@ +// -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*- + +/****************************************************************************** + * + * file: DocBookOutput.h + * + * Copyright (c) 2004, Michael E. Smoot + * All rights reverved. + * + * See the file COPYING in the top directory of this distribution for + * more information. + * + * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + *****************************************************************************/ + +#ifndef TCLAP_DOCBOOKOUTPUT_H +#define TCLAP_DOCBOOKOUTPUT_H + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +namespace TCLAP { + +/** + * A class that generates DocBook output for usage() method for the + * given CmdLine and its Args. + */ +class DocBookOutput : public CmdLineOutput +{ + + public: + + /** + * Prints the usage to stdout. Can be overridden to + * produce alternative behavior. + * \param c - The CmdLine object the output is generated for. + */ + virtual void usage(CmdLineInterface& c); + + /** + * Prints the version to stdout. Can be overridden + * to produce alternative behavior. + * \param c - The CmdLine object the output is generated for. + */ + virtual void version(CmdLineInterface& c); + + /** + * Prints (to stderr) an error message, short usage + * Can be overridden to produce alternative behavior. + * \param c - The CmdLine object the output is generated for. + * \param e - The ArgException that caused the failure. + */ + virtual void failure(CmdLineInterface& c, + ArgException& e ); + + protected: + + /** + * Substitutes the char r for string x in string s. + * \param s - The string to operate on. + * \param r - The char to replace. + * \param x - What to replace r with. + */ + void substituteSpecialChars( std::string& s, char r, std::string& x ); + void removeChar( std::string& s, char r); + void basename( std::string& s ); + + void printShortArg(Arg* it); + void printLongArg(Arg* it); + + char theDelimiter; +}; + + +inline void DocBookOutput::version(CmdLineInterface& _cmd) +{ + std::cout << _cmd.getVersion() << std::endl; +} + +inline void DocBookOutput::usage(CmdLineInterface& _cmd ) +{ + std::list argList = _cmd.getArgList(); + std::string progName = _cmd.getProgramName(); + std::string xversion = _cmd.getVersion(); + theDelimiter = _cmd.getDelimiter(); + XorHandler xorHandler = _cmd.getXorHandler(); + std::vector< std::vector > xorList = xorHandler.getXorList(); + basename(progName); + + std::cout << "" << std::endl; + std::cout << "" << std::endl << std::endl; + + std::cout << "" << std::endl; + + std::cout << "" << std::endl; + std::cout << "" << progName << "" << std::endl; + std::cout << "1" << std::endl; + std::cout << "" << std::endl; + + std::cout << "" << std::endl; + std::cout << "" << progName << "" << std::endl; + std::cout << "" << _cmd.getMessage() << "" << std::endl; + std::cout << "" << std::endl; + + std::cout << "" << std::endl; + std::cout << "" << std::endl; + + std::cout << "" << progName << "" << std::endl; + + // xor + for ( int i = 0; (unsigned int)i < xorList.size(); i++ ) + { + std::cout << "" << std::endl; + for ( ArgVectorIterator it = xorList[i].begin(); + it != xorList[i].end(); it++ ) + printShortArg((*it)); + + std::cout << "" << std::endl; + } + + // rest of args + for (ArgListIterator it = argList.begin(); it != argList.end(); it++) + if ( !xorHandler.contains( (*it) ) ) + printShortArg((*it)); + + std::cout << "" << std::endl; + std::cout << "" << std::endl; + + std::cout << "" << std::endl; + std::cout << "Description" << std::endl; + std::cout << "" << std::endl; + std::cout << _cmd.getMessage() << std::endl; + std::cout << "" << std::endl; + std::cout << "" << std::endl; + + std::cout << "" << std::endl; + std::cout << "Options" << std::endl; + + std::cout << "" << std::endl; + + for (ArgListIterator it = argList.begin(); it != argList.end(); it++) + printLongArg((*it)); + + std::cout << "" << std::endl; + std::cout << "" << std::endl; + + std::cout << "" << std::endl; + std::cout << "Version" << std::endl; + std::cout << "" << std::endl; + std::cout << xversion << std::endl; + std::cout << "" << std::endl; + std::cout << "" << std::endl; + + std::cout << "" << std::endl; + +} + +inline void DocBookOutput::failure( CmdLineInterface& _cmd, + ArgException& e ) +{ + static_cast(_cmd); // unused + std::cout << e.what() << std::endl; + throw ExitException(1); +} + +inline void DocBookOutput::substituteSpecialChars( std::string& s, + char r, + std::string& x ) +{ + size_t p; + while ( (p = s.find_first_of(r)) != std::string::npos ) + { + s.erase(p,1); + s.insert(p,x); + } +} + +inline void DocBookOutput::removeChar( std::string& s, char r) +{ + size_t p; + while ( (p = s.find_first_of(r)) != std::string::npos ) + { + s.erase(p,1); + } +} + +inline void DocBookOutput::basename( std::string& s ) +{ + size_t p = s.find_last_of('/'); + if ( p != std::string::npos ) + { + s.erase(0, p + 1); + } +} + +inline void DocBookOutput::printShortArg(Arg* a) +{ + std::string lt = "<"; + std::string gt = ">"; + + std::string id = a->shortID(); + substituteSpecialChars(id,'<',lt); + substituteSpecialChars(id,'>',gt); + removeChar(id,'['); + removeChar(id,']'); + + std::string choice = "opt"; + if ( a->isRequired() ) + choice = "plain"; + + std::cout << "acceptsMultipleValues() ) + std::cout << " rep='repeat'"; + + + std::cout << '>'; + if ( !a->getFlag().empty() ) + std::cout << a->flagStartChar() << a->getFlag(); + else + std::cout << a->nameStartString() << a->getName(); + if ( a->isValueRequired() ) + { + std::string arg = a->shortID(); + removeChar(arg,'['); + removeChar(arg,']'); + removeChar(arg,'<'); + removeChar(arg,'>'); + arg.erase(0, arg.find_last_of(theDelimiter) + 1); + std::cout << theDelimiter; + std::cout << "" << arg << ""; + } + std::cout << "" << std::endl; + +} + +inline void DocBookOutput::printLongArg(Arg* a) +{ + std::string lt = "<"; + std::string gt = ">"; + + std::string desc = a->getDescription(); + substituteSpecialChars(desc,'<',lt); + substituteSpecialChars(desc,'>',gt); + + std::cout << "" << std::endl; + + if ( !a->getFlag().empty() ) + { + std::cout << "" << std::endl; + std::cout << "" << std::endl; + std::cout << "" << std::endl; + } + + std::cout << "" << std::endl; + std::cout << "" << std::endl; + std::cout << "" << std::endl; + + std::cout << "" << std::endl; + std::cout << "" << std::endl; + std::cout << desc << std::endl; + std::cout << "" << std::endl; + std::cout << "" << std::endl; + + std::cout << "" << std::endl; +} + +} //namespace TCLAP +#endif diff --git a/xs/src/tclap/HelpVisitor.h b/xs/src/tclap/HelpVisitor.h new file mode 100644 index 0000000000..cc3bd070ca --- /dev/null +++ b/xs/src/tclap/HelpVisitor.h @@ -0,0 +1,76 @@ + +/****************************************************************************** + * + * file: HelpVisitor.h + * + * Copyright (c) 2003, Michael E. Smoot . + * All rights reverved. + * + * See the file COPYING in the top directory of this distribution for + * more information. + * + * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + *****************************************************************************/ + +#ifndef TCLAP_HELP_VISITOR_H +#define TCLAP_HELP_VISITOR_H + +#include +#include +#include + +namespace TCLAP { + +/** + * A Visitor object that calls the usage method of the given CmdLineOutput + * object for the specified CmdLine object. + */ +class HelpVisitor: public Visitor +{ + private: + /** + * Prevent accidental copying. + */ + HelpVisitor(const HelpVisitor& rhs); + HelpVisitor& operator=(const HelpVisitor& rhs); + + protected: + + /** + * The CmdLine the output will be generated for. + */ + CmdLineInterface* _cmd; + + /** + * The output object. + */ + CmdLineOutput** _out; + + public: + + /** + * Constructor. + * \param cmd - The CmdLine the output will be generated for. + * \param out - The type of output. + */ + HelpVisitor(CmdLineInterface* cmd, CmdLineOutput** out) + : Visitor(), _cmd( cmd ), _out( out ) { } + + /** + * Calls the usage method of the CmdLineOutput for the + * specified CmdLine. + */ + void visit() { (*_out)->usage(*_cmd); throw ExitException(0); } + +}; + +} + +#endif diff --git a/xs/src/tclap/IgnoreRestVisitor.h b/xs/src/tclap/IgnoreRestVisitor.h new file mode 100644 index 0000000000..e328649e51 --- /dev/null +++ b/xs/src/tclap/IgnoreRestVisitor.h @@ -0,0 +1,52 @@ + +/****************************************************************************** + * + * file: IgnoreRestVisitor.h + * + * Copyright (c) 2003, Michael E. Smoot . + * All rights reverved. + * + * See the file COPYING in the top directory of this distribution for + * more information. + * + * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + *****************************************************************************/ + + +#ifndef TCLAP_IGNORE_REST_VISITOR_H +#define TCLAP_IGNORE_REST_VISITOR_H + +#include +#include + +namespace TCLAP { + +/** + * A Vistor that tells the CmdLine to begin ignoring arguments after + * this one is parsed. + */ +class IgnoreRestVisitor: public Visitor +{ + public: + + /** + * Constructor. + */ + IgnoreRestVisitor() : Visitor() {} + + /** + * Sets Arg::_ignoreRest. + */ + void visit() { Arg::beginIgnoring(); } +}; + +} + +#endif diff --git a/xs/src/tclap/Makefile.am b/xs/src/tclap/Makefile.am new file mode 100644 index 0000000000..0e247bf5bf --- /dev/null +++ b/xs/src/tclap/Makefile.am @@ -0,0 +1,28 @@ + +libtclapincludedir = $(includedir)/tclap + +libtclapinclude_HEADERS = \ + CmdLineInterface.h \ + ArgException.h \ + CmdLine.h \ + XorHandler.h \ + MultiArg.h \ + UnlabeledMultiArg.h \ + ValueArg.h \ + UnlabeledValueArg.h \ + Visitor.h Arg.h \ + HelpVisitor.h \ + SwitchArg.h \ + MultiSwitchArg.h \ + VersionVisitor.h \ + IgnoreRestVisitor.h \ + CmdLineOutput.h \ + StdOutput.h \ + DocBookOutput.h \ + ZshCompletionOutput.h \ + OptionalUnlabeledTracker.h \ + Constraint.h \ + ValuesConstraint.h \ + ArgTraits.h \ + StandardTraits.h + diff --git a/xs/src/tclap/Makefile.in b/xs/src/tclap/Makefile.in new file mode 100644 index 0000000000..65ef2515c2 --- /dev/null +++ b/xs/src/tclap/Makefile.in @@ -0,0 +1,403 @@ +# Makefile.in generated by automake 1.10 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004, 2005, 2006 Free Software Foundation, Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + +VPATH = @srcdir@ +pkgdatadir = $(datadir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +subdir = include/tclap +DIST_COMMON = $(libtclapinclude_HEADERS) $(srcdir)/Makefile.am \ + $(srcdir)/Makefile.in +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/config/ac_cxx_have_long_long.m4 \ + $(top_srcdir)/config/ac_cxx_have_sstream.m4 \ + $(top_srcdir)/config/ac_cxx_have_strstream.m4 \ + $(top_srcdir)/config/ac_cxx_namespaces.m4 \ + $(top_srcdir)/config/ac_cxx_warn_effective_cxx.m4 \ + $(top_srcdir)/config/bb_enable_doxygen.m4 \ + $(top_srcdir)/configure.in +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(SHELL) $(top_srcdir)/config/mkinstalldirs +CONFIG_HEADER = $(top_builddir)/config/config.h +CONFIG_CLEAN_FILES = +SOURCES = +DIST_SOURCES = +am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; +am__vpath_adj = case $$p in \ + $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ + *) f=$$p;; \ + esac; +am__strip_dir = `echo $$p | sed -e 's|^.*/||'`; +am__installdirs = "$(DESTDIR)$(libtclapincludedir)" +libtclapincludeHEADERS_INSTALL = $(INSTALL_HEADER) +HEADERS = $(libtclapinclude_HEADERS) +ETAGS = etags +CTAGS = ctags +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = @ACLOCAL@ +AMTAR = @AMTAR@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CPPFLAGS = @CPPFLAGS@ +CXX = @CXX@ +CXXCPP = @CXXCPP@ +CXXDEPMODE = @CXXDEPMODE@ +CXXFLAGS = @CXXFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DOT = @DOT@ +DOXYGEN = @DOXYGEN@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +GREP = @GREP@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +LDFLAGS = @LDFLAGS@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LTLIBOBJS = @LTLIBOBJS@ +MAKEINFO = @MAKEINFO@ +MKDIR_P = @MKDIR_P@ +OBJEXT = @OBJEXT@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +RANLIB = @RANLIB@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRIP = @STRIP@ +VERSION = @VERSION@ +WARN_EFFECTIVE_CXX = @WARN_EFFECTIVE_CXX@ +WARN_NO_EFFECTIVE_CXX = @WARN_NO_EFFECTIVE_CXX@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_CXX = @ac_ct_CXX@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build_alias = @build_alias@ +builddir = @builddir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +docdir = @docdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +host_alias = @host_alias@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +srcdir = @srcdir@ +sysconfdir = @sysconfdir@ +target_alias = @target_alias@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +libtclapincludedir = $(includedir)/tclap +libtclapinclude_HEADERS = \ + CmdLineInterface.h \ + ArgException.h \ + CmdLine.h \ + XorHandler.h \ + MultiArg.h \ + UnlabeledMultiArg.h \ + ValueArg.h \ + UnlabeledValueArg.h \ + Visitor.h Arg.h \ + HelpVisitor.h \ + SwitchArg.h \ + MultiSwitchArg.h \ + VersionVisitor.h \ + IgnoreRestVisitor.h \ + CmdLineOutput.h \ + StdOutput.h \ + DocBookOutput.h \ + ZshCompletionOutput.h \ + OptionalUnlabeledTracker.h \ + Constraint.h \ + ValuesConstraint.h \ + ArgTraits.h \ + StandardTraits.h + +all: all-am + +.SUFFIXES: +$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \ + && exit 0; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu include/tclap/Makefile'; \ + cd $(top_srcdir) && \ + $(AUTOMAKE) --gnu include/tclap/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +install-libtclapincludeHEADERS: $(libtclapinclude_HEADERS) + @$(NORMAL_INSTALL) + test -z "$(libtclapincludedir)" || $(MKDIR_P) "$(DESTDIR)$(libtclapincludedir)" + @list='$(libtclapinclude_HEADERS)'; for p in $$list; do \ + if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ + f=$(am__strip_dir) \ + echo " $(libtclapincludeHEADERS_INSTALL) '$$d$$p' '$(DESTDIR)$(libtclapincludedir)/$$f'"; \ + $(libtclapincludeHEADERS_INSTALL) "$$d$$p" "$(DESTDIR)$(libtclapincludedir)/$$f"; \ + done + +uninstall-libtclapincludeHEADERS: + @$(NORMAL_UNINSTALL) + @list='$(libtclapinclude_HEADERS)'; for p in $$list; do \ + f=$(am__strip_dir) \ + echo " rm -f '$(DESTDIR)$(libtclapincludedir)/$$f'"; \ + rm -f "$(DESTDIR)$(libtclapincludedir)/$$f"; \ + done + +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + mkid -fID $$unique +tags: TAGS + +TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + tags=; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$tags $$unique; \ + fi +ctags: CTAGS +CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + tags=; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + test -z "$(CTAGS_ARGS)$$tags$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$tags $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && cd $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) $$here + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + +distdir: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + list='$(DISTFILES)'; \ + dist_files=`for file in $$list; do echo $$file; done | \ + sed -e "s|^$$srcdirstrip/||;t" \ + -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ + case $$dist_files in \ + */*) $(MKDIR_P) `echo "$$dist_files" | \ + sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ + sort -u` ;; \ + esac; \ + for file in $$dist_files; do \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + if test -d $$d/$$file; then \ + dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \ + fi; \ + cp -pR $$d/$$file $(distdir)$$dir || exit 1; \ + else \ + test -f $(distdir)/$$file \ + || cp -p $$d/$$file $(distdir)/$$file \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-am +all-am: Makefile $(HEADERS) +installdirs: + for dir in "$(DESTDIR)$(libtclapincludedir)"; do \ + test -z "$$dir" || $(MKDIR_P) "$$dir"; \ + done +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-generic mostlyclean-am + +distclean: distclean-am + -rm -f Makefile +distclean-am: clean-am distclean-generic distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +info: info-am + +info-am: + +install-data-am: install-libtclapincludeHEADERS + +install-dvi: install-dvi-am + +install-exec-am: + +install-html: install-html-am + +install-info: install-info-am + +install-man: + +install-pdf: install-pdf-am + +install-ps: install-ps-am + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-generic + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: uninstall-libtclapincludeHEADERS + +.MAKE: install-am install-strip + +.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \ + ctags distclean distclean-generic distclean-tags distdir dvi \ + dvi-am html html-am info info-am install install-am \ + install-data install-data-am install-dvi install-dvi-am \ + install-exec install-exec-am install-html install-html-am \ + install-info install-info-am install-libtclapincludeHEADERS \ + install-man install-pdf install-pdf-am install-ps \ + install-ps-am install-strip installcheck installcheck-am \ + installdirs maintainer-clean maintainer-clean-generic \ + mostlyclean mostlyclean-generic pdf pdf-am ps ps-am tags \ + uninstall uninstall-am uninstall-libtclapincludeHEADERS + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/xs/src/tclap/MultiArg.h b/xs/src/tclap/MultiArg.h new file mode 100644 index 0000000000..34bb2d7895 --- /dev/null +++ b/xs/src/tclap/MultiArg.h @@ -0,0 +1,433 @@ +/****************************************************************************** + * + * file: MultiArg.h + * + * Copyright (c) 2003, Michael E. Smoot . + * Copyright (c) 2004, Michael E. Smoot, Daniel Aarno. + * All rights reverved. + * + * See the file COPYING in the top directory of this distribution for + * more information. + * + * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + *****************************************************************************/ + + +#ifndef TCLAP_MULTIPLE_ARGUMENT_H +#define TCLAP_MULTIPLE_ARGUMENT_H + +#include +#include + +#include +#include + +namespace TCLAP { +/** + * An argument that allows multiple values of type T to be specified. Very + * similar to a ValueArg, except a vector of values will be returned + * instead of just one. + */ +template +class MultiArg : public Arg +{ +public: + typedef std::vector container_type; + typedef typename container_type::iterator iterator; + typedef typename container_type::const_iterator const_iterator; + +protected: + + /** + * The list of values parsed from the CmdLine. + */ + std::vector _values; + + /** + * The description of type T to be used in the usage. + */ + std::string _typeDesc; + + /** + * A list of constraint on this Arg. + */ + Constraint* _constraint; + + /** + * Extracts the value from the string. + * Attempts to parse string as type T, if this fails an exception + * is thrown. + * \param val - The string to be read. + */ + void _extractValue( const std::string& val ); + + /** + * Used by XorHandler to decide whether to keep parsing for this arg. + */ + bool _allowMore; + +public: + + /** + * Constructor. + * \param flag - The one character flag that identifies this + * argument on the command line. + * \param name - A one word name for the argument. Can be + * used as a long flag on the command line. + * \param desc - A description of what the argument is for or + * does. + * \param req - Whether the argument is required on the command + * line. + * \param typeDesc - A short, human readable description of the + * type that this object expects. This is used in the generation + * of the USAGE statement. The goal is to be helpful to the end user + * of the program. + * \param v - An optional visitor. You probably should not + * use this unless you have a very good reason. + */ + MultiArg( const std::string& flag, + const std::string& name, + const std::string& desc, + bool req, + const std::string& typeDesc, + Visitor* v = NULL); + + /** + * Constructor. + * \param flag - The one character flag that identifies this + * argument on the command line. + * \param name - A one word name for the argument. Can be + * used as a long flag on the command line. + * \param desc - A description of what the argument is for or + * does. + * \param req - Whether the argument is required on the command + * line. + * \param typeDesc - A short, human readable description of the + * type that this object expects. This is used in the generation + * of the USAGE statement. The goal is to be helpful to the end user + * of the program. + * \param parser - A CmdLine parser object to add this Arg to + * \param v - An optional visitor. You probably should not + * use this unless you have a very good reason. + */ + MultiArg( const std::string& flag, + const std::string& name, + const std::string& desc, + bool req, + const std::string& typeDesc, + CmdLineInterface& parser, + Visitor* v = NULL ); + + /** + * Constructor. + * \param flag - The one character flag that identifies this + * argument on the command line. + * \param name - A one word name for the argument. Can be + * used as a long flag on the command line. + * \param desc - A description of what the argument is for or + * does. + * \param req - Whether the argument is required on the command + * line. + * \param constraint - A pointer to a Constraint object used + * to constrain this Arg. + * \param v - An optional visitor. You probably should not + * use this unless you have a very good reason. + */ + MultiArg( const std::string& flag, + const std::string& name, + const std::string& desc, + bool req, + Constraint* constraint, + Visitor* v = NULL ); + + /** + * Constructor. + * \param flag - The one character flag that identifies this + * argument on the command line. + * \param name - A one word name for the argument. Can be + * used as a long flag on the command line. + * \param desc - A description of what the argument is for or + * does. + * \param req - Whether the argument is required on the command + * line. + * \param constraint - A pointer to a Constraint object used + * to constrain this Arg. + * \param parser - A CmdLine parser object to add this Arg to + * \param v - An optional visitor. You probably should not + * use this unless you have a very good reason. + */ + MultiArg( const std::string& flag, + const std::string& name, + const std::string& desc, + bool req, + Constraint* constraint, + CmdLineInterface& parser, + Visitor* v = NULL ); + + /** + * Handles the processing of the argument. + * This re-implements the Arg version of this method to set the + * _value of the argument appropriately. It knows the difference + * between labeled and unlabeled. + * \param i - Pointer the the current argument in the list. + * \param args - Mutable list of strings. Passed from main(). + */ + virtual bool processArg(int* i, std::vector& args); + + /** + * Returns a vector of type T containing the values parsed from + * the command line. + */ + const std::vector& getValue(); + + /** + * Returns an iterator over the values parsed from the command + * line. + */ + const_iterator begin() const { return _values.begin(); } + + /** + * Returns the end of the values parsed from the command + * line. + */ + const_iterator end() const { return _values.end(); } + + /** + * Returns the a short id string. Used in the usage. + * \param val - value to be used. + */ + virtual std::string shortID(const std::string& val="val") const; + + /** + * Returns the a long id string. Used in the usage. + * \param val - value to be used. + */ + virtual std::string longID(const std::string& val="val") const; + + /** + * Once we've matched the first value, then the arg is no longer + * required. + */ + virtual bool isRequired() const; + + virtual bool allowMore(); + + virtual void reset(); + +private: + /** + * Prevent accidental copying + */ + MultiArg(const MultiArg& rhs); + MultiArg& operator=(const MultiArg& rhs); + +}; + +template +MultiArg::MultiArg(const std::string& flag, + const std::string& name, + const std::string& desc, + bool req, + const std::string& typeDesc, + Visitor* v) : + Arg( flag, name, desc, req, true, v ), + _values(std::vector()), + _typeDesc( typeDesc ), + _constraint( NULL ), + _allowMore(false) +{ + _acceptsMultipleValues = true; +} + +template +MultiArg::MultiArg(const std::string& flag, + const std::string& name, + const std::string& desc, + bool req, + const std::string& typeDesc, + CmdLineInterface& parser, + Visitor* v) +: Arg( flag, name, desc, req, true, v ), + _values(std::vector()), + _typeDesc( typeDesc ), + _constraint( NULL ), + _allowMore(false) +{ + parser.add( this ); + _acceptsMultipleValues = true; +} + +/** + * + */ +template +MultiArg::MultiArg(const std::string& flag, + const std::string& name, + const std::string& desc, + bool req, + Constraint* constraint, + Visitor* v) +: Arg( flag, name, desc, req, true, v ), + _values(std::vector()), + _typeDesc( constraint->shortID() ), + _constraint( constraint ), + _allowMore(false) +{ + _acceptsMultipleValues = true; +} + +template +MultiArg::MultiArg(const std::string& flag, + const std::string& name, + const std::string& desc, + bool req, + Constraint* constraint, + CmdLineInterface& parser, + Visitor* v) +: Arg( flag, name, desc, req, true, v ), + _values(std::vector()), + _typeDesc( constraint->shortID() ), + _constraint( constraint ), + _allowMore(false) +{ + parser.add( this ); + _acceptsMultipleValues = true; +} + +template +const std::vector& MultiArg::getValue() { return _values; } + +template +bool MultiArg::processArg(int *i, std::vector& args) +{ + if ( _ignoreable && Arg::ignoreRest() ) + return false; + + if ( _hasBlanks( args[*i] ) ) + return false; + + std::string flag = args[*i]; + std::string value = ""; + + trimFlag( flag, value ); + + if ( argMatches( flag ) ) + { + if ( Arg::delimiter() != ' ' && value == "" ) + throw( ArgParseException( + "Couldn't find delimiter for this argument!", + toString() ) ); + + // always take the first one, regardless of start string + if ( value == "" ) + { + (*i)++; + if ( static_cast(*i) < args.size() ) + _extractValue( args[*i] ); + else + throw( ArgParseException("Missing a value for this argument!", + toString() ) ); + } + else + _extractValue( value ); + + /* + // continuing taking the args until we hit one with a start string + while ( (unsigned int)(*i)+1 < args.size() && + args[(*i)+1].find_first_of( Arg::flagStartString() ) != 0 && + args[(*i)+1].find_first_of( Arg::nameStartString() ) != 0 ) + _extractValue( args[++(*i)] ); + */ + + _alreadySet = true; + _checkWithVisitor(); + + return true; + } + else + return false; +} + +/** + * + */ +template +std::string MultiArg::shortID(const std::string& val) const +{ + static_cast(val); // Ignore input, don't warn + return Arg::shortID(_typeDesc) + " ... "; +} + +/** + * + */ +template +std::string MultiArg::longID(const std::string& val) const +{ + static_cast(val); // Ignore input, don't warn + return Arg::longID(_typeDesc) + " (accepted multiple times)"; +} + +/** + * Once we've matched the first value, then the arg is no longer + * required. + */ +template +bool MultiArg::isRequired() const +{ + if ( _required ) + { + if ( _values.size() > 1 ) + return false; + else + return true; + } + else + return false; + +} + +template +void MultiArg::_extractValue( const std::string& val ) +{ + try { + T tmp; + ExtractValue(tmp, val, typename ArgTraits::ValueCategory()); + _values.push_back(tmp); + } catch( ArgParseException &e) { + throw ArgParseException(e.error(), toString()); + } + + if ( _constraint != NULL ) + if ( ! _constraint->check( _values.back() ) ) + throw( CmdLineParseException( "Value '" + val + + "' does not meet constraint: " + + _constraint->description(), + toString() ) ); +} + +template +bool MultiArg::allowMore() +{ + bool am = _allowMore; + _allowMore = true; + return am; +} + +template +void MultiArg::reset() +{ + Arg::reset(); + _values.clear(); +} + +} // namespace TCLAP + +#endif diff --git a/xs/src/tclap/MultiSwitchArg.h b/xs/src/tclap/MultiSwitchArg.h new file mode 100644 index 0000000000..8820b64162 --- /dev/null +++ b/xs/src/tclap/MultiSwitchArg.h @@ -0,0 +1,216 @@ + +/****************************************************************************** +* +* file: MultiSwitchArg.h +* +* Copyright (c) 2003, Michael E. Smoot . +* Copyright (c) 2004, Michael E. Smoot, Daniel Aarno. +* Copyright (c) 2005, Michael E. Smoot, Daniel Aarno, Erik Zeek. +* All rights reverved. +* +* See the file COPYING in the top directory of this distribution for +* more information. +* +* THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS +* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +* DEALINGS IN THE SOFTWARE. +* +*****************************************************************************/ + + +#ifndef TCLAP_MULTI_SWITCH_ARG_H +#define TCLAP_MULTI_SWITCH_ARG_H + +#include +#include + +#include + +namespace TCLAP { + +/** +* A multiple switch argument. If the switch is set on the command line, then +* the getValue method will return the number of times the switch appears. +*/ +class MultiSwitchArg : public SwitchArg +{ + protected: + + /** + * The value of the switch. + */ + int _value; + + /** + * Used to support the reset() method so that ValueArg can be + * reset to their constructed value. + */ + int _default; + + public: + + /** + * MultiSwitchArg constructor. + * \param flag - The one character flag that identifies this + * argument on the command line. + * \param name - A one word name for the argument. Can be + * used as a long flag on the command line. + * \param desc - A description of what the argument is for or + * does. + * \param init - Optional. The initial/default value of this Arg. + * Defaults to 0. + * \param v - An optional visitor. You probably should not + * use this unless you have a very good reason. + */ + MultiSwitchArg(const std::string& flag, + const std::string& name, + const std::string& desc, + int init = 0, + Visitor* v = NULL); + + + /** + * MultiSwitchArg constructor. + * \param flag - The one character flag that identifies this + * argument on the command line. + * \param name - A one word name for the argument. Can be + * used as a long flag on the command line. + * \param desc - A description of what the argument is for or + * does. + * \param parser - A CmdLine parser object to add this Arg to + * \param init - Optional. The initial/default value of this Arg. + * Defaults to 0. + * \param v - An optional visitor. You probably should not + * use this unless you have a very good reason. + */ + MultiSwitchArg(const std::string& flag, + const std::string& name, + const std::string& desc, + CmdLineInterface& parser, + int init = 0, + Visitor* v = NULL); + + + /** + * Handles the processing of the argument. + * This re-implements the SwitchArg version of this method to set the + * _value of the argument appropriately. + * \param i - Pointer the the current argument in the list. + * \param args - Mutable list of strings. Passed + * in from main(). + */ + virtual bool processArg(int* i, std::vector& args); + + /** + * Returns int, the number of times the switch has been set. + */ + int getValue(); + + /** + * Returns the shortID for this Arg. + */ + std::string shortID(const std::string& val) const; + + /** + * Returns the longID for this Arg. + */ + std::string longID(const std::string& val) const; + + void reset(); + +}; + +////////////////////////////////////////////////////////////////////// +//BEGIN MultiSwitchArg.cpp +////////////////////////////////////////////////////////////////////// +inline MultiSwitchArg::MultiSwitchArg(const std::string& flag, + const std::string& name, + const std::string& desc, + int init, + Visitor* v ) +: SwitchArg(flag, name, desc, false, v), +_value( init ), +_default( init ) +{ } + +inline MultiSwitchArg::MultiSwitchArg(const std::string& flag, + const std::string& name, + const std::string& desc, + CmdLineInterface& parser, + int init, + Visitor* v ) +: SwitchArg(flag, name, desc, false, v), +_value( init ), +_default( init ) +{ + parser.add( this ); +} + +inline int MultiSwitchArg::getValue() { return _value; } + +inline bool MultiSwitchArg::processArg(int *i, std::vector& args) +{ + if ( _ignoreable && Arg::ignoreRest() ) + return false; + + if ( argMatches( args[*i] )) + { + // so the isSet() method will work + _alreadySet = true; + + // Matched argument: increment value. + ++_value; + + _checkWithVisitor(); + + return true; + } + else if ( combinedSwitchesMatch( args[*i] ) ) + { + // so the isSet() method will work + _alreadySet = true; + + // Matched argument: increment value. + ++_value; + + // Check for more in argument and increment value. + while ( combinedSwitchesMatch( args[*i] ) ) + ++_value; + + _checkWithVisitor(); + + return false; + } + else + return false; +} + +inline std::string +MultiSwitchArg::shortID(const std::string& val) const +{ + return Arg::shortID(val) + " ... "; +} + +inline std::string +MultiSwitchArg::longID(const std::string& val) const +{ + return Arg::longID(val) + " (accepted multiple times)"; +} + +inline void +MultiSwitchArg::reset() +{ + MultiSwitchArg::_value = MultiSwitchArg::_default; +} + +////////////////////////////////////////////////////////////////////// +//END MultiSwitchArg.cpp +////////////////////////////////////////////////////////////////////// + +} //namespace TCLAP + +#endif diff --git a/xs/src/tclap/OptionalUnlabeledTracker.h b/xs/src/tclap/OptionalUnlabeledTracker.h new file mode 100644 index 0000000000..8174c5f624 --- /dev/null +++ b/xs/src/tclap/OptionalUnlabeledTracker.h @@ -0,0 +1,62 @@ + + +/****************************************************************************** + * + * file: OptionalUnlabeledTracker.h + * + * Copyright (c) 2005, Michael E. Smoot . + * All rights reverved. + * + * See the file COPYING in the top directory of this distribution for + * more information. + * + * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + *****************************************************************************/ + + +#ifndef TCLAP_OPTIONAL_UNLABELED_TRACKER_H +#define TCLAP_OPTIONAL_UNLABELED_TRACKER_H + +#include + +namespace TCLAP { + +class OptionalUnlabeledTracker +{ + + public: + + static void check( bool req, const std::string& argName ); + + static void gotOptional() { alreadyOptionalRef() = true; } + + static bool& alreadyOptional() { return alreadyOptionalRef(); } + + private: + + static bool& alreadyOptionalRef() { static bool ct = false; return ct; } +}; + + +inline void OptionalUnlabeledTracker::check( bool req, const std::string& argName ) +{ + if ( OptionalUnlabeledTracker::alreadyOptional() ) + throw( SpecificationException( + "You can't specify ANY Unlabeled Arg following an optional Unlabeled Arg", + argName ) ); + + if ( !req ) + OptionalUnlabeledTracker::gotOptional(); +} + + +} // namespace TCLAP + +#endif diff --git a/xs/src/tclap/StandardTraits.h b/xs/src/tclap/StandardTraits.h new file mode 100644 index 0000000000..46d7f6fafd --- /dev/null +++ b/xs/src/tclap/StandardTraits.h @@ -0,0 +1,208 @@ +// -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*- + +/****************************************************************************** + * + * file: StandardTraits.h + * + * Copyright (c) 2007, Daniel Aarno, Michael E. Smoot . + * All rights reverved. + * + * See the file COPYING in the top directory of this distribution for + * more information. + * + * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + *****************************************************************************/ + +// This is an internal tclap file, you should probably not have to +// include this directly + +#ifndef TCLAP_STANDARD_TRAITS_H +#define TCLAP_STANDARD_TRAITS_H + +#ifdef HAVE_CONFIG_H +#include // To check for long long +#endif + +// If Microsoft has already typedef'd wchar_t as an unsigned +// short, then compiles will break because it's as if we're +// creating ArgTraits twice for unsigned short. Thus... +#ifdef _MSC_VER +#ifndef _NATIVE_WCHAR_T_DEFINED +#define TCLAP_DONT_DECLARE_WCHAR_T_ARGTRAITS +#endif +#endif + +namespace TCLAP { + +// ====================================================================== +// Integer types +// ====================================================================== + +/** + * longs have value-like semantics. + */ +template<> +struct ArgTraits { + typedef ValueLike ValueCategory; +}; + +/** + * ints have value-like semantics. + */ +template<> +struct ArgTraits { + typedef ValueLike ValueCategory; +}; + +/** + * shorts have value-like semantics. + */ +template<> +struct ArgTraits { + typedef ValueLike ValueCategory; +}; + +/** + * chars have value-like semantics. + */ +template<> +struct ArgTraits { + typedef ValueLike ValueCategory; +}; + +#ifdef HAVE_LONG_LONG +/** + * long longs have value-like semantics. + */ +template<> +struct ArgTraits { + typedef ValueLike ValueCategory; +}; +#endif + +// ====================================================================== +// Unsigned integer types +// ====================================================================== + +/** + * unsigned longs have value-like semantics. + */ +template<> +struct ArgTraits { + typedef ValueLike ValueCategory; +}; + +/** + * unsigned ints have value-like semantics. + */ +template<> +struct ArgTraits { + typedef ValueLike ValueCategory; +}; + +/** + * unsigned shorts have value-like semantics. + */ +template<> +struct ArgTraits { + typedef ValueLike ValueCategory; +}; + +/** + * unsigned chars have value-like semantics. + */ +template<> +struct ArgTraits { + typedef ValueLike ValueCategory; +}; + +// Microsoft implements size_t awkwardly. +#if defined(_MSC_VER) && defined(_M_X64) +/** + * size_ts have value-like semantics. + */ +template<> +struct ArgTraits { + typedef ValueLike ValueCategory; +}; +#endif + + +#ifdef HAVE_LONG_LONG +/** + * unsigned long longs have value-like semantics. + */ +template<> +struct ArgTraits { + typedef ValueLike ValueCategory; +}; +#endif + +// ====================================================================== +// Float types +// ====================================================================== + +/** + * floats have value-like semantics. + */ +template<> +struct ArgTraits { + typedef ValueLike ValueCategory; +}; + +/** + * doubles have value-like semantics. + */ +template<> +struct ArgTraits { + typedef ValueLike ValueCategory; +}; + +// ====================================================================== +// Other types +// ====================================================================== + +/** + * bools have value-like semantics. + */ +template<> +struct ArgTraits { + typedef ValueLike ValueCategory; +}; + + +/** + * wchar_ts have value-like semantics. + */ +#ifndef TCLAP_DONT_DECLARE_WCHAR_T_ARGTRAITS +template<> +struct ArgTraits { + typedef ValueLike ValueCategory; +}; +#endif + +/** + * Strings have string like argument traits. + */ +template<> +struct ArgTraits { + typedef StringLike ValueCategory; +}; + +template +void SetString(T &dst, const std::string &src) +{ + dst = src; +} + +} // namespace + +#endif + diff --git a/xs/src/tclap/StdOutput.h b/xs/src/tclap/StdOutput.h new file mode 100644 index 0000000000..35f7b99b2c --- /dev/null +++ b/xs/src/tclap/StdOutput.h @@ -0,0 +1,298 @@ +// -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*- + +/****************************************************************************** + * + * file: StdOutput.h + * + * Copyright (c) 2004, Michael E. Smoot + * All rights reverved. + * + * See the file COPYING in the top directory of this distribution for + * more information. + * + * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + *****************************************************************************/ + +#ifndef TCLAP_STDCMDLINEOUTPUT_H +#define TCLAP_STDCMDLINEOUTPUT_H + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +namespace TCLAP { + +/** + * A class that isolates any output from the CmdLine object so that it + * may be easily modified. + */ +class StdOutput : public CmdLineOutput +{ + + public: + + /** + * Prints the usage to stdout. Can be overridden to + * produce alternative behavior. + * \param c - The CmdLine object the output is generated for. + */ + virtual void usage(CmdLineInterface& c); + + /** + * Prints the version to stdout. Can be overridden + * to produce alternative behavior. + * \param c - The CmdLine object the output is generated for. + */ + virtual void version(CmdLineInterface& c); + + /** + * Prints (to stderr) an error message, short usage + * Can be overridden to produce alternative behavior. + * \param c - The CmdLine object the output is generated for. + * \param e - The ArgException that caused the failure. + */ + virtual void failure(CmdLineInterface& c, + ArgException& e ); + + protected: + + /** + * Writes a brief usage message with short args. + * \param c - The CmdLine object the output is generated for. + * \param os - The stream to write the message to. + */ + void _shortUsage( CmdLineInterface& c, std::ostream& os ) const; + + /** + * Writes a longer usage message with long and short args, + * provides descriptions and prints message. + * \param c - The CmdLine object the output is generated for. + * \param os - The stream to write the message to. + */ + void _longUsage( CmdLineInterface& c, std::ostream& os ) const; + + /** + * This function inserts line breaks and indents long strings + * according the params input. It will only break lines at spaces, + * commas and pipes. + * \param os - The stream to be printed to. + * \param s - The string to be printed. + * \param maxWidth - The maxWidth allowed for the output line. + * \param indentSpaces - The number of spaces to indent the first line. + * \param secondLineOffset - The number of spaces to indent the second + * and all subsequent lines in addition to indentSpaces. + */ + void spacePrint( std::ostream& os, + const std::string& s, + int maxWidth, + int indentSpaces, + int secondLineOffset ) const; + +}; + + +inline void StdOutput::version(CmdLineInterface& _cmd) +{ + std::string progName = _cmd.getProgramName(); + std::string xversion = _cmd.getVersion(); + + std::cout << std::endl << progName << " version: " + << xversion << std::endl << std::endl; +} + +inline void StdOutput::usage(CmdLineInterface& _cmd ) +{ + std::cout << std::endl << "USAGE: " << std::endl << std::endl; + + _shortUsage( _cmd, std::cout ); + + std::cout << std::endl << std::endl << "Where: " << std::endl << std::endl; + + _longUsage( _cmd, std::cout ); + + std::cout << std::endl; + +} + +inline void StdOutput::failure( CmdLineInterface& _cmd, + ArgException& e ) +{ + std::string progName = _cmd.getProgramName(); + + std::cerr << "PARSE ERROR: " << e.argId() << std::endl + << " " << e.error() << std::endl << std::endl; + + if ( _cmd.hasHelpAndVersion() ) + { + std::cerr << "Brief USAGE: " << std::endl; + + _shortUsage( _cmd, std::cerr ); + + std::cerr << std::endl << "For complete USAGE and HELP type: " + << std::endl << " " << progName << " --help" + << std::endl << std::endl; + } + else + usage(_cmd); + + throw ExitException(1); +} + +inline void +StdOutput::_shortUsage( CmdLineInterface& _cmd, + std::ostream& os ) const +{ + std::list argList = _cmd.getArgList(); + std::string progName = _cmd.getProgramName(); + XorHandler xorHandler = _cmd.getXorHandler(); + std::vector< std::vector > xorList = xorHandler.getXorList(); + + std::string s = progName + " "; + + // first the xor + for ( int i = 0; static_cast(i) < xorList.size(); i++ ) + { + s += " {"; + for ( ArgVectorIterator it = xorList[i].begin(); + it != xorList[i].end(); it++ ) + s += (*it)->shortID() + "|"; + + s[s.length()-1] = '}'; + } + + // then the rest + for (ArgListIterator it = argList.begin(); it != argList.end(); it++) + if ( !xorHandler.contains( (*it) ) ) + s += " " + (*it)->shortID(); + + // if the program name is too long, then adjust the second line offset + int secondLineOffset = static_cast(progName.length()) + 2; + if ( secondLineOffset > 75/2 ) + secondLineOffset = static_cast(75/2); + + spacePrint( os, s, 75, 3, secondLineOffset ); +} + +inline void +StdOutput::_longUsage( CmdLineInterface& _cmd, + std::ostream& os ) const +{ + std::list argList = _cmd.getArgList(); + std::string message = _cmd.getMessage(); + XorHandler xorHandler = _cmd.getXorHandler(); + std::vector< std::vector > xorList = xorHandler.getXorList(); + + // first the xor + for ( int i = 0; static_cast(i) < xorList.size(); i++ ) + { + for ( ArgVectorIterator it = xorList[i].begin(); + it != xorList[i].end(); + it++ ) + { + spacePrint( os, (*it)->longID(), 75, 3, 3 ); + spacePrint( os, (*it)->getDescription(), 75, 5, 0 ); + + if ( it+1 != xorList[i].end() ) + spacePrint(os, "-- OR --", 75, 9, 0); + } + os << std::endl << std::endl; + } + + // then the rest + for (ArgListIterator it = argList.begin(); it != argList.end(); it++) + if ( !xorHandler.contains( (*it) ) ) + { + spacePrint( os, (*it)->longID(), 75, 3, 3 ); + spacePrint( os, (*it)->getDescription(), 75, 5, 0 ); + os << std::endl; + } + + os << std::endl; + + spacePrint( os, message, 75, 3, 0 ); +} + +inline void StdOutput::spacePrint( std::ostream& os, + const std::string& s, + int maxWidth, + int indentSpaces, + int secondLineOffset ) const +{ + int len = static_cast(s.length()); + + if ( (len + indentSpaces > maxWidth) && maxWidth > 0 ) + { + int allowedLen = maxWidth - indentSpaces; + int start = 0; + while ( start < len ) + { + // find the substring length + // int stringLen = std::min( len - start, allowedLen ); + // doing it this way to support a VisualC++ 2005 bug + using namespace std; + int stringLen = min( len - start, allowedLen ); + + // trim the length so it doesn't end in middle of a word + if ( stringLen == allowedLen ) + while ( stringLen >= 0 && + s[stringLen+start] != ' ' && + s[stringLen+start] != ',' && + s[stringLen+start] != '|' ) + stringLen--; + + // ok, the word is longer than the line, so just split + // wherever the line ends + if ( stringLen <= 0 ) + stringLen = allowedLen; + + // check for newlines + for ( int i = 0; i < stringLen; i++ ) + if ( s[start+i] == '\n' ) + stringLen = i+1; + + // print the indent + for ( int i = 0; i < indentSpaces; i++ ) + os << " "; + + if ( start == 0 ) + { + // handle second line offsets + indentSpaces += secondLineOffset; + + // adjust allowed len + allowedLen -= secondLineOffset; + } + + os << s.substr(start,stringLen) << std::endl; + + // so we don't start a line with a space + while ( s[stringLen+start] == ' ' && start < len ) + start++; + + start += stringLen; + } + } + else + { + for ( int i = 0; i < indentSpaces; i++ ) + os << " "; + os << s << std::endl; + } +} + +} //namespace TCLAP +#endif diff --git a/xs/src/tclap/SwitchArg.h b/xs/src/tclap/SwitchArg.h new file mode 100644 index 0000000000..3916109069 --- /dev/null +++ b/xs/src/tclap/SwitchArg.h @@ -0,0 +1,266 @@ + +/****************************************************************************** + * + * file: SwitchArg.h + * + * Copyright (c) 2003, Michael E. Smoot . + * Copyright (c) 2004, Michael E. Smoot, Daniel Aarno. + * All rights reverved. + * + * See the file COPYING in the top directory of this distribution for + * more information. + * + * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + *****************************************************************************/ + + +#ifndef TCLAP_SWITCH_ARG_H +#define TCLAP_SWITCH_ARG_H + +#include +#include + +#include + +namespace TCLAP { + +/** + * A simple switch argument. If the switch is set on the command line, then + * the getValue method will return the opposite of the default value for the + * switch. + */ +class SwitchArg : public Arg +{ + protected: + + /** + * The value of the switch. + */ + bool _value; + + /** + * Used to support the reset() method so that ValueArg can be + * reset to their constructed value. + */ + bool _default; + + public: + + /** + * SwitchArg constructor. + * \param flag - The one character flag that identifies this + * argument on the command line. + * \param name - A one word name for the argument. Can be + * used as a long flag on the command line. + * \param desc - A description of what the argument is for or + * does. + * \param def - The default value for this Switch. + * \param v - An optional visitor. You probably should not + * use this unless you have a very good reason. + */ + SwitchArg(const std::string& flag, + const std::string& name, + const std::string& desc, + bool def = false, + Visitor* v = NULL); + + + /** + * SwitchArg constructor. + * \param flag - The one character flag that identifies this + * argument on the command line. + * \param name - A one word name for the argument. Can be + * used as a long flag on the command line. + * \param desc - A description of what the argument is for or + * does. + * \param parser - A CmdLine parser object to add this Arg to + * \param def - The default value for this Switch. + * \param v - An optional visitor. You probably should not + * use this unless you have a very good reason. + */ + SwitchArg(const std::string& flag, + const std::string& name, + const std::string& desc, + CmdLineInterface& parser, + bool def = false, + Visitor* v = NULL); + + + /** + * Handles the processing of the argument. + * This re-implements the Arg version of this method to set the + * _value of the argument appropriately. + * \param i - Pointer the the current argument in the list. + * \param args - Mutable list of strings. Passed + * in from main(). + */ + virtual bool processArg(int* i, std::vector& args); + + /** + * Checks a string to see if any of the chars in the string + * match the flag for this Switch. + */ + bool combinedSwitchesMatch(std::string& combined); + + /** + * Returns bool, whether or not the switch has been set. + */ + bool getValue(); + + virtual void reset(); + + private: + /** + * Checks to see if we've found the last match in + * a combined string. + */ + bool lastCombined(std::string& combined); + + /** + * Does the common processing of processArg. + */ + void commonProcessing(); +}; + +////////////////////////////////////////////////////////////////////// +//BEGIN SwitchArg.cpp +////////////////////////////////////////////////////////////////////// +inline SwitchArg::SwitchArg(const std::string& flag, + const std::string& name, + const std::string& desc, + bool default_val, + Visitor* v ) +: Arg(flag, name, desc, false, false, v), + _value( default_val ), + _default( default_val ) +{ } + +inline SwitchArg::SwitchArg(const std::string& flag, + const std::string& name, + const std::string& desc, + CmdLineInterface& parser, + bool default_val, + Visitor* v ) +: Arg(flag, name, desc, false, false, v), + _value( default_val ), + _default(default_val) +{ + parser.add( this ); +} + +inline bool SwitchArg::getValue() { return _value; } + +inline bool SwitchArg::lastCombined(std::string& combinedSwitches ) +{ + for ( unsigned int i = 1; i < combinedSwitches.length(); i++ ) + if ( combinedSwitches[i] != Arg::blankChar() ) + return false; + + return true; +} + +inline bool SwitchArg::combinedSwitchesMatch(std::string& combinedSwitches ) +{ + // make sure this is actually a combined switch + if ( combinedSwitches.length() > 0 && + combinedSwitches[0] != Arg::flagStartString()[0] ) + return false; + + // make sure it isn't a long name + if ( combinedSwitches.substr( 0, Arg::nameStartString().length() ) == + Arg::nameStartString() ) + return false; + + // make sure the delimiter isn't in the string + if ( combinedSwitches.find_first_of( Arg::delimiter() ) != std::string::npos ) + return false; + + // ok, we're not specifying a ValueArg, so we know that we have + // a combined switch list. + for ( unsigned int i = 1; i < combinedSwitches.length(); i++ ) + if ( _flag.length() > 0 && + combinedSwitches[i] == _flag[0] && + _flag[0] != Arg::flagStartString()[0] ) + { + // update the combined switches so this one is no longer present + // this is necessary so that no unlabeled args are matched + // later in the processing. + //combinedSwitches.erase(i,1); + combinedSwitches[i] = Arg::blankChar(); + return true; + } + + // none of the switches passed in the list match. + return false; +} + +inline void SwitchArg::commonProcessing() +{ + if ( _xorSet ) + throw(CmdLineParseException( + "Mutually exclusive argument already set!", toString())); + + if ( _alreadySet ) + throw(CmdLineParseException("Argument already set!", toString())); + + _alreadySet = true; + + if ( _value == true ) + _value = false; + else + _value = true; + + _checkWithVisitor(); +} + +inline bool SwitchArg::processArg(int *i, std::vector& args) +{ + if ( _ignoreable && Arg::ignoreRest() ) + return false; + + // if the whole string matches the flag or name string + if ( argMatches( args[*i] ) ) + { + commonProcessing(); + + return true; + } + // if a substring matches the flag as part of a combination + else if ( combinedSwitchesMatch( args[*i] ) ) + { + // check again to ensure we don't misinterpret + // this as a MultiSwitchArg + if ( combinedSwitchesMatch( args[*i] ) ) + throw(CmdLineParseException("Argument already set!", + toString())); + + commonProcessing(); + + // We only want to return true if we've found the last combined + // match in the string, otherwise we return true so that other + // switches in the combination will have a chance to match. + return lastCombined( args[*i] ); + } + else + return false; +} + +inline void SwitchArg::reset() +{ + Arg::reset(); + _value = _default; +} +////////////////////////////////////////////////////////////////////// +//End SwitchArg.cpp +////////////////////////////////////////////////////////////////////// + +} //namespace TCLAP + +#endif diff --git a/xs/src/tclap/UnlabeledMultiArg.h b/xs/src/tclap/UnlabeledMultiArg.h new file mode 100644 index 0000000000..d5e1781060 --- /dev/null +++ b/xs/src/tclap/UnlabeledMultiArg.h @@ -0,0 +1,301 @@ + +/****************************************************************************** + * + * file: UnlabeledMultiArg.h + * + * Copyright (c) 2003, Michael E. Smoot. + * All rights reverved. + * + * See the file COPYING in the top directory of this distribution for + * more information. + * + * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + *****************************************************************************/ + + +#ifndef TCLAP_MULTIPLE_UNLABELED_ARGUMENT_H +#define TCLAP_MULTIPLE_UNLABELED_ARGUMENT_H + +#include +#include + +#include +#include + +namespace TCLAP { + +/** + * Just like a MultiArg, except that the arguments are unlabeled. Basically, + * this Arg will slurp up everything that hasn't been matched to another + * Arg. + */ +template +class UnlabeledMultiArg : public MultiArg +{ + + // If compiler has two stage name lookup (as gcc >= 3.4 does) + // this is requried to prevent undef. symbols + using MultiArg::_ignoreable; + using MultiArg::_hasBlanks; + using MultiArg::_extractValue; + using MultiArg::_typeDesc; + using MultiArg::_name; + using MultiArg::_description; + using MultiArg::_alreadySet; + using MultiArg::toString; + + public: + + /** + * Constructor. + * \param name - The name of the Arg. Note that this is used for + * identification, not as a long flag. + * \param desc - A description of what the argument is for or + * does. + * \param req - Whether the argument is required on the command + * line. + * \param typeDesc - A short, human readable description of the + * type that this object expects. This is used in the generation + * of the USAGE statement. The goal is to be helpful to the end user + * of the program. + * \param ignoreable - Whether or not this argument can be ignored + * using the "--" flag. + * \param v - An optional visitor. You probably should not + * use this unless you have a very good reason. + */ + UnlabeledMultiArg( const std::string& name, + const std::string& desc, + bool req, + const std::string& typeDesc, + bool ignoreable = false, + Visitor* v = NULL ); + /** + * Constructor. + * \param name - The name of the Arg. Note that this is used for + * identification, not as a long flag. + * \param desc - A description of what the argument is for or + * does. + * \param req - Whether the argument is required on the command + * line. + * \param typeDesc - A short, human readable description of the + * type that this object expects. This is used in the generation + * of the USAGE statement. The goal is to be helpful to the end user + * of the program. + * \param parser - A CmdLine parser object to add this Arg to + * \param ignoreable - Whether or not this argument can be ignored + * using the "--" flag. + * \param v - An optional visitor. You probably should not + * use this unless you have a very good reason. + */ + UnlabeledMultiArg( const std::string& name, + const std::string& desc, + bool req, + const std::string& typeDesc, + CmdLineInterface& parser, + bool ignoreable = false, + Visitor* v = NULL ); + + /** + * Constructor. + * \param name - The name of the Arg. Note that this is used for + * identification, not as a long flag. + * \param desc - A description of what the argument is for or + * does. + * \param req - Whether the argument is required on the command + * line. + * \param constraint - A pointer to a Constraint object used + * to constrain this Arg. + * \param ignoreable - Whether or not this argument can be ignored + * using the "--" flag. + * \param v - An optional visitor. You probably should not + * use this unless you have a very good reason. + */ + UnlabeledMultiArg( const std::string& name, + const std::string& desc, + bool req, + Constraint* constraint, + bool ignoreable = false, + Visitor* v = NULL ); + + /** + * Constructor. + * \param name - The name of the Arg. Note that this is used for + * identification, not as a long flag. + * \param desc - A description of what the argument is for or + * does. + * \param req - Whether the argument is required on the command + * line. + * \param constraint - A pointer to a Constraint object used + * to constrain this Arg. + * \param parser - A CmdLine parser object to add this Arg to + * \param ignoreable - Whether or not this argument can be ignored + * using the "--" flag. + * \param v - An optional visitor. You probably should not + * use this unless you have a very good reason. + */ + UnlabeledMultiArg( const std::string& name, + const std::string& desc, + bool req, + Constraint* constraint, + CmdLineInterface& parser, + bool ignoreable = false, + Visitor* v = NULL ); + + /** + * Handles the processing of the argument. + * This re-implements the Arg version of this method to set the + * _value of the argument appropriately. It knows the difference + * between labeled and unlabeled. + * \param i - Pointer the the current argument in the list. + * \param args - Mutable list of strings. Passed from main(). + */ + virtual bool processArg(int* i, std::vector& args); + + /** + * Returns the a short id string. Used in the usage. + * \param val - value to be used. + */ + virtual std::string shortID(const std::string& val="val") const; + + /** + * Returns the a long id string. Used in the usage. + * \param val - value to be used. + */ + virtual std::string longID(const std::string& val="val") const; + + /** + * Opertor ==. + * \param a - The Arg to be compared to this. + */ + virtual bool operator==(const Arg& a) const; + + /** + * Pushes this to back of list rather than front. + * \param argList - The list this should be added to. + */ + virtual void addToList( std::list& argList ) const; +}; + +template +UnlabeledMultiArg::UnlabeledMultiArg(const std::string& name, + const std::string& desc, + bool req, + const std::string& typeDesc, + bool ignoreable, + Visitor* v) +: MultiArg("", name, desc, req, typeDesc, v) +{ + _ignoreable = ignoreable; + OptionalUnlabeledTracker::check(true, toString()); +} + +template +UnlabeledMultiArg::UnlabeledMultiArg(const std::string& name, + const std::string& desc, + bool req, + const std::string& typeDesc, + CmdLineInterface& parser, + bool ignoreable, + Visitor* v) +: MultiArg("", name, desc, req, typeDesc, v) +{ + _ignoreable = ignoreable; + OptionalUnlabeledTracker::check(true, toString()); + parser.add( this ); +} + + +template +UnlabeledMultiArg::UnlabeledMultiArg(const std::string& name, + const std::string& desc, + bool req, + Constraint* constraint, + bool ignoreable, + Visitor* v) +: MultiArg("", name, desc, req, constraint, v) +{ + _ignoreable = ignoreable; + OptionalUnlabeledTracker::check(true, toString()); +} + +template +UnlabeledMultiArg::UnlabeledMultiArg(const std::string& name, + const std::string& desc, + bool req, + Constraint* constraint, + CmdLineInterface& parser, + bool ignoreable, + Visitor* v) +: MultiArg("", name, desc, req, constraint, v) +{ + _ignoreable = ignoreable; + OptionalUnlabeledTracker::check(true, toString()); + parser.add( this ); +} + + +template +bool UnlabeledMultiArg::processArg(int *i, std::vector& args) +{ + + if ( _hasBlanks( args[*i] ) ) + return false; + + // never ignore an unlabeled multi arg + + + // always take the first value, regardless of the start string + _extractValue( args[(*i)] ); + + /* + // continue taking args until we hit the end or a start string + while ( (unsigned int)(*i)+1 < args.size() && + args[(*i)+1].find_first_of( Arg::flagStartString() ) != 0 && + args[(*i)+1].find_first_of( Arg::nameStartString() ) != 0 ) + _extractValue( args[++(*i)] ); + */ + + _alreadySet = true; + + return true; +} + +template +std::string UnlabeledMultiArg::shortID(const std::string& val) const +{ + static_cast(val); // Ignore input, don't warn + return std::string("<") + _typeDesc + "> ..."; +} + +template +std::string UnlabeledMultiArg::longID(const std::string& val) const +{ + static_cast(val); // Ignore input, don't warn + return std::string("<") + _typeDesc + "> (accepted multiple times)"; +} + +template +bool UnlabeledMultiArg::operator==(const Arg& a) const +{ + if ( _name == a.getName() || _description == a.getDescription() ) + return true; + else + return false; +} + +template +void UnlabeledMultiArg::addToList( std::list& argList ) const +{ + argList.push_back( const_cast(static_cast(this)) ); +} + +} + +#endif diff --git a/xs/src/tclap/UnlabeledValueArg.h b/xs/src/tclap/UnlabeledValueArg.h new file mode 100644 index 0000000000..5721d61252 --- /dev/null +++ b/xs/src/tclap/UnlabeledValueArg.h @@ -0,0 +1,340 @@ + +/****************************************************************************** + * + * file: UnlabeledValueArg.h + * + * Copyright (c) 2003, Michael E. Smoot . + * Copyright (c) 2004, Michael E. Smoot, Daniel Aarno. + * All rights reverved. + * + * See the file COPYING in the top directory of this distribution for + * more information. + * + * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + *****************************************************************************/ + + +#ifndef TCLAP_UNLABELED_VALUE_ARGUMENT_H +#define TCLAP_UNLABELED_VALUE_ARGUMENT_H + +#include +#include + +#include +#include + + +namespace TCLAP { + +/** + * The basic unlabeled argument that parses a value. + * This is a template class, which means the type T defines the type + * that a given object will attempt to parse when an UnlabeledValueArg + * is reached in the list of args that the CmdLine iterates over. + */ +template +class UnlabeledValueArg : public ValueArg +{ + + // If compiler has two stage name lookup (as gcc >= 3.4 does) + // this is requried to prevent undef. symbols + using ValueArg::_ignoreable; + using ValueArg::_hasBlanks; + using ValueArg::_extractValue; + using ValueArg::_typeDesc; + using ValueArg::_name; + using ValueArg::_description; + using ValueArg::_alreadySet; + using ValueArg::toString; + + public: + + /** + * UnlabeledValueArg constructor. + * \param name - A one word name for the argument. Note that this is used for + * identification, not as a long flag. + * \param desc - A description of what the argument is for or + * does. + * \param req - Whether the argument is required on the command + * line. + * \param value - The default value assigned to this argument if it + * is not present on the command line. + * \param typeDesc - A short, human readable description of the + * type that this object expects. This is used in the generation + * of the USAGE statement. The goal is to be helpful to the end user + * of the program. + * \param ignoreable - Allows you to specify that this argument can be + * ignored if the '--' flag is set. This defaults to false (cannot + * be ignored) and should generally stay that way unless you have + * some special need for certain arguments to be ignored. + * \param v - Optional Vistor. You should leave this blank unless + * you have a very good reason. + */ + UnlabeledValueArg( const std::string& name, + const std::string& desc, + bool req, + T value, + const std::string& typeDesc, + bool ignoreable = false, + Visitor* v = NULL); + + /** + * UnlabeledValueArg constructor. + * \param name - A one word name for the argument. Note that this is used for + * identification, not as a long flag. + * \param desc - A description of what the argument is for or + * does. + * \param req - Whether the argument is required on the command + * line. + * \param value - The default value assigned to this argument if it + * is not present on the command line. + * \param typeDesc - A short, human readable description of the + * type that this object expects. This is used in the generation + * of the USAGE statement. The goal is to be helpful to the end user + * of the program. + * \param parser - A CmdLine parser object to add this Arg to + * \param ignoreable - Allows you to specify that this argument can be + * ignored if the '--' flag is set. This defaults to false (cannot + * be ignored) and should generally stay that way unless you have + * some special need for certain arguments to be ignored. + * \param v - Optional Vistor. You should leave this blank unless + * you have a very good reason. + */ + UnlabeledValueArg( const std::string& name, + const std::string& desc, + bool req, + T value, + const std::string& typeDesc, + CmdLineInterface& parser, + bool ignoreable = false, + Visitor* v = NULL ); + + /** + * UnlabeledValueArg constructor. + * \param name - A one word name for the argument. Note that this is used for + * identification, not as a long flag. + * \param desc - A description of what the argument is for or + * does. + * \param req - Whether the argument is required on the command + * line. + * \param value - The default value assigned to this argument if it + * is not present on the command line. + * \param constraint - A pointer to a Constraint object used + * to constrain this Arg. + * \param ignoreable - Allows you to specify that this argument can be + * ignored if the '--' flag is set. This defaults to false (cannot + * be ignored) and should generally stay that way unless you have + * some special need for certain arguments to be ignored. + * \param v - Optional Vistor. You should leave this blank unless + * you have a very good reason. + */ + UnlabeledValueArg( const std::string& name, + const std::string& desc, + bool req, + T value, + Constraint* constraint, + bool ignoreable = false, + Visitor* v = NULL ); + + + /** + * UnlabeledValueArg constructor. + * \param name - A one word name for the argument. Note that this is used for + * identification, not as a long flag. + * \param desc - A description of what the argument is for or + * does. + * \param req - Whether the argument is required on the command + * line. + * \param value - The default value assigned to this argument if it + * is not present on the command line. + * \param constraint - A pointer to a Constraint object used + * to constrain this Arg. + * \param parser - A CmdLine parser object to add this Arg to + * \param ignoreable - Allows you to specify that this argument can be + * ignored if the '--' flag is set. This defaults to false (cannot + * be ignored) and should generally stay that way unless you have + * some special need for certain arguments to be ignored. + * \param v - Optional Vistor. You should leave this blank unless + * you have a very good reason. + */ + UnlabeledValueArg( const std::string& name, + const std::string& desc, + bool req, + T value, + Constraint* constraint, + CmdLineInterface& parser, + bool ignoreable = false, + Visitor* v = NULL); + + /** + * Handles the processing of the argument. + * This re-implements the Arg version of this method to set the + * _value of the argument appropriately. Handling specific to + * unlabled arguments. + * \param i - Pointer the the current argument in the list. + * \param args - Mutable list of strings. + */ + virtual bool processArg(int* i, std::vector& args); + + /** + * Overrides shortID for specific behavior. + */ + virtual std::string shortID(const std::string& val="val") const; + + /** + * Overrides longID for specific behavior. + */ + virtual std::string longID(const std::string& val="val") const; + + /** + * Overrides operator== for specific behavior. + */ + virtual bool operator==(const Arg& a ) const; + + /** + * Instead of pushing to the front of list, push to the back. + * \param argList - The list to add this to. + */ + virtual void addToList( std::list& argList ) const; + +}; + +/** + * Constructor implemenation. + */ +template +UnlabeledValueArg::UnlabeledValueArg(const std::string& name, + const std::string& desc, + bool req, + T val, + const std::string& typeDesc, + bool ignoreable, + Visitor* v) +: ValueArg("", name, desc, req, val, typeDesc, v) +{ + _ignoreable = ignoreable; + + OptionalUnlabeledTracker::check(req, toString()); + +} + +template +UnlabeledValueArg::UnlabeledValueArg(const std::string& name, + const std::string& desc, + bool req, + T val, + const std::string& typeDesc, + CmdLineInterface& parser, + bool ignoreable, + Visitor* v) +: ValueArg("", name, desc, req, val, typeDesc, v) +{ + _ignoreable = ignoreable; + OptionalUnlabeledTracker::check(req, toString()); + parser.add( this ); +} + +/** + * Constructor implemenation. + */ +template +UnlabeledValueArg::UnlabeledValueArg(const std::string& name, + const std::string& desc, + bool req, + T val, + Constraint* constraint, + bool ignoreable, + Visitor* v) +: ValueArg("", name, desc, req, val, constraint, v) +{ + _ignoreable = ignoreable; + OptionalUnlabeledTracker::check(req, toString()); +} + +template +UnlabeledValueArg::UnlabeledValueArg(const std::string& name, + const std::string& desc, + bool req, + T val, + Constraint* constraint, + CmdLineInterface& parser, + bool ignoreable, + Visitor* v) +: ValueArg("", name, desc, req, val, constraint, v) +{ + _ignoreable = ignoreable; + OptionalUnlabeledTracker::check(req, toString()); + parser.add( this ); +} + +/** + * Implementation of processArg(). + */ +template +bool UnlabeledValueArg::processArg(int *i, std::vector& args) +{ + + if ( _alreadySet ) + return false; + + if ( _hasBlanks( args[*i] ) ) + return false; + + // never ignore an unlabeled arg + + _extractValue( args[*i] ); + _alreadySet = true; + return true; +} + +/** + * Overriding shortID for specific output. + */ +template +std::string UnlabeledValueArg::shortID(const std::string& val) const +{ + static_cast(val); // Ignore input, don't warn + return std::string("<") + _typeDesc + ">"; +} + +/** + * Overriding longID for specific output. + */ +template +std::string UnlabeledValueArg::longID(const std::string& val) const +{ + static_cast(val); // Ignore input, don't warn + + // Ideally we would like to be able to use RTTI to return the name + // of the type required for this argument. However, g++ at least, + // doesn't appear to return terribly useful "names" of the types. + return std::string("<") + _typeDesc + ">"; +} + +/** + * Overriding operator== for specific behavior. + */ +template +bool UnlabeledValueArg::operator==(const Arg& a ) const +{ + if ( _name == a.getName() || _description == a.getDescription() ) + return true; + else + return false; +} + +template +void UnlabeledValueArg::addToList( std::list& argList ) const +{ + argList.push_back( const_cast(static_cast(this)) ); +} + +} +#endif diff --git a/xs/src/tclap/ValueArg.h b/xs/src/tclap/ValueArg.h new file mode 100644 index 0000000000..7ac29526b9 --- /dev/null +++ b/xs/src/tclap/ValueArg.h @@ -0,0 +1,425 @@ +/****************************************************************************** + * + * file: ValueArg.h + * + * Copyright (c) 2003, Michael E. Smoot . + * Copyright (c) 2004, Michael E. Smoot, Daniel Aarno. + * All rights reverved. + * + * See the file COPYING in the top directory of this distribution for + * more information. + * + * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + *****************************************************************************/ + + +#ifndef TCLAP_VALUE_ARGUMENT_H +#define TCLAP_VALUE_ARGUMENT_H + +#include +#include + +#include +#include + +namespace TCLAP { + +/** + * The basic labeled argument that parses a value. + * This is a template class, which means the type T defines the type + * that a given object will attempt to parse when the flag/name is matched + * on the command line. While there is nothing stopping you from creating + * an unflagged ValueArg, it is unwise and would cause significant problems. + * Instead use an UnlabeledValueArg. + */ +template +class ValueArg : public Arg +{ + protected: + + /** + * The value parsed from the command line. + * Can be of any type, as long as the >> operator for the type + * is defined. + */ + T _value; + + /** + * Used to support the reset() method so that ValueArg can be + * reset to their constructed value. + */ + T _default; + + /** + * A human readable description of the type to be parsed. + * This is a hack, plain and simple. Ideally we would use RTTI to + * return the name of type T, but until there is some sort of + * consistent support for human readable names, we are left to our + * own devices. + */ + std::string _typeDesc; + + /** + * A Constraint this Arg must conform to. + */ + Constraint* _constraint; + + /** + * Extracts the value from the string. + * Attempts to parse string as type T, if this fails an exception + * is thrown. + * \param val - value to be parsed. + */ + void _extractValue( const std::string& val ); + + public: + + /** + * Labeled ValueArg constructor. + * You could conceivably call this constructor with a blank flag, + * but that would make you a bad person. It would also cause + * an exception to be thrown. If you want an unlabeled argument, + * use the other constructor. + * \param flag - The one character flag that identifies this + * argument on the command line. + * \param name - A one word name for the argument. Can be + * used as a long flag on the command line. + * \param desc - A description of what the argument is for or + * does. + * \param req - Whether the argument is required on the command + * line. + * \param value - The default value assigned to this argument if it + * is not present on the command line. + * \param typeDesc - A short, human readable description of the + * type that this object expects. This is used in the generation + * of the USAGE statement. The goal is to be helpful to the end user + * of the program. + * \param v - An optional visitor. You probably should not + * use this unless you have a very good reason. + */ + ValueArg( const std::string& flag, + const std::string& name, + const std::string& desc, + bool req, + T value, + const std::string& typeDesc, + Visitor* v = NULL); + + + /** + * Labeled ValueArg constructor. + * You could conceivably call this constructor with a blank flag, + * but that would make you a bad person. It would also cause + * an exception to be thrown. If you want an unlabeled argument, + * use the other constructor. + * \param flag - The one character flag that identifies this + * argument on the command line. + * \param name - A one word name for the argument. Can be + * used as a long flag on the command line. + * \param desc - A description of what the argument is for or + * does. + * \param req - Whether the argument is required on the command + * line. + * \param value - The default value assigned to this argument if it + * is not present on the command line. + * \param typeDesc - A short, human readable description of the + * type that this object expects. This is used in the generation + * of the USAGE statement. The goal is to be helpful to the end user + * of the program. + * \param parser - A CmdLine parser object to add this Arg to + * \param v - An optional visitor. You probably should not + * use this unless you have a very good reason. + */ + ValueArg( const std::string& flag, + const std::string& name, + const std::string& desc, + bool req, + T value, + const std::string& typeDesc, + CmdLineInterface& parser, + Visitor* v = NULL ); + + /** + * Labeled ValueArg constructor. + * You could conceivably call this constructor with a blank flag, + * but that would make you a bad person. It would also cause + * an exception to be thrown. If you want an unlabeled argument, + * use the other constructor. + * \param flag - The one character flag that identifies this + * argument on the command line. + * \param name - A one word name for the argument. Can be + * used as a long flag on the command line. + * \param desc - A description of what the argument is for or + * does. + * \param req - Whether the argument is required on the command + * line. + * \param value - The default value assigned to this argument if it + * is not present on the command line. + * \param constraint - A pointer to a Constraint object used + * to constrain this Arg. + * \param parser - A CmdLine parser object to add this Arg to. + * \param v - An optional visitor. You probably should not + * use this unless you have a very good reason. + */ + ValueArg( const std::string& flag, + const std::string& name, + const std::string& desc, + bool req, + T value, + Constraint* constraint, + CmdLineInterface& parser, + Visitor* v = NULL ); + + /** + * Labeled ValueArg constructor. + * You could conceivably call this constructor with a blank flag, + * but that would make you a bad person. It would also cause + * an exception to be thrown. If you want an unlabeled argument, + * use the other constructor. + * \param flag - The one character flag that identifies this + * argument on the command line. + * \param name - A one word name for the argument. Can be + * used as a long flag on the command line. + * \param desc - A description of what the argument is for or + * does. + * \param req - Whether the argument is required on the command + * line. + * \param value - The default value assigned to this argument if it + * is not present on the command line. + * \param constraint - A pointer to a Constraint object used + * to constrain this Arg. + * \param v - An optional visitor. You probably should not + * use this unless you have a very good reason. + */ + ValueArg( const std::string& flag, + const std::string& name, + const std::string& desc, + bool req, + T value, + Constraint* constraint, + Visitor* v = NULL ); + + /** + * Handles the processing of the argument. + * This re-implements the Arg version of this method to set the + * _value of the argument appropriately. It knows the difference + * between labeled and unlabeled. + * \param i - Pointer the the current argument in the list. + * \param args - Mutable list of strings. Passed + * in from main(). + */ + virtual bool processArg(int* i, std::vector& args); + + /** + * Returns the value of the argument. + */ + T& getValue() ; + + /** + * Specialization of shortID. + * \param val - value to be used. + */ + virtual std::string shortID(const std::string& val = "val") const; + + /** + * Specialization of longID. + * \param val - value to be used. + */ + virtual std::string longID(const std::string& val = "val") const; + + virtual void reset() ; + +private: + /** + * Prevent accidental copying + */ + ValueArg(const ValueArg& rhs); + ValueArg& operator=(const ValueArg& rhs); +}; + + +/** + * Constructor implementation. + */ +template +ValueArg::ValueArg(const std::string& flag, + const std::string& name, + const std::string& desc, + bool req, + T val, + const std::string& typeDesc, + Visitor* v) +: Arg(flag, name, desc, req, true, v), + _value( val ), + _default( val ), + _typeDesc( typeDesc ), + _constraint( NULL ) +{ } + +template +ValueArg::ValueArg(const std::string& flag, + const std::string& name, + const std::string& desc, + bool req, + T val, + const std::string& typeDesc, + CmdLineInterface& parser, + Visitor* v) +: Arg(flag, name, desc, req, true, v), + _value( val ), + _default( val ), + _typeDesc( typeDesc ), + _constraint( NULL ) +{ + parser.add( this ); +} + +template +ValueArg::ValueArg(const std::string& flag, + const std::string& name, + const std::string& desc, + bool req, + T val, + Constraint* constraint, + Visitor* v) +: Arg(flag, name, desc, req, true, v), + _value( val ), + _default( val ), + _typeDesc( constraint->shortID() ), + _constraint( constraint ) +{ } + +template +ValueArg::ValueArg(const std::string& flag, + const std::string& name, + const std::string& desc, + bool req, + T val, + Constraint* constraint, + CmdLineInterface& parser, + Visitor* v) +: Arg(flag, name, desc, req, true, v), + _value( val ), + _default( val ), + _typeDesc( constraint->shortID() ), + _constraint( constraint ) +{ + parser.add( this ); +} + + +/** + * Implementation of getValue(). + */ +template +T& ValueArg::getValue() { return _value; } + +/** + * Implementation of processArg(). + */ +template +bool ValueArg::processArg(int *i, std::vector& args) +{ + if ( _ignoreable && Arg::ignoreRest() ) + return false; + + if ( _hasBlanks( args[*i] ) ) + return false; + + std::string flag = args[*i]; + + std::string value = ""; + trimFlag( flag, value ); + + if ( argMatches( flag ) ) + { + if ( _alreadySet ) + { + if ( _xorSet ) + throw( CmdLineParseException( + "Mutually exclusive argument already set!", + toString()) ); + else + throw( CmdLineParseException("Argument already set!", + toString()) ); + } + + if ( Arg::delimiter() != ' ' && value == "" ) + throw( ArgParseException( + "Couldn't find delimiter for this argument!", + toString() ) ); + + if ( value == "" ) + { + (*i)++; + if ( static_cast(*i) < args.size() ) + _extractValue( args[*i] ); + else + throw( ArgParseException("Missing a value for this argument!", + toString() ) ); + } + else + _extractValue( value ); + + _alreadySet = true; + _checkWithVisitor(); + return true; + } + else + return false; +} + +/** + * Implementation of shortID. + */ +template +std::string ValueArg::shortID(const std::string& val) const +{ + static_cast(val); // Ignore input, don't warn + return Arg::shortID( _typeDesc ); +} + +/** + * Implementation of longID. + */ +template +std::string ValueArg::longID(const std::string& val) const +{ + static_cast(val); // Ignore input, don't warn + return Arg::longID( _typeDesc ); +} + +template +void ValueArg::_extractValue( const std::string& val ) +{ + try { + ExtractValue(_value, val, typename ArgTraits::ValueCategory()); + } catch( ArgParseException &e) { + throw ArgParseException(e.error(), toString()); + } + + if ( _constraint != NULL ) + if ( ! _constraint->check( _value ) ) + throw( CmdLineParseException( "Value '" + val + + + "' does not meet constraint: " + + _constraint->description(), + toString() ) ); +} + +template +void ValueArg::reset() +{ + Arg::reset(); + _value = _default; +} + +} // namespace TCLAP + +#endif diff --git a/xs/src/tclap/ValuesConstraint.h b/xs/src/tclap/ValuesConstraint.h new file mode 100644 index 0000000000..cb41f645e5 --- /dev/null +++ b/xs/src/tclap/ValuesConstraint.h @@ -0,0 +1,148 @@ + + +/****************************************************************************** + * + * file: ValuesConstraint.h + * + * Copyright (c) 2005, Michael E. Smoot + * All rights reverved. + * + * See the file COPYING in the top directory of this distribution for + * more information. + * + * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + *****************************************************************************/ + +#ifndef TCLAP_VALUESCONSTRAINT_H +#define TCLAP_VALUESCONSTRAINT_H + +#include +#include +#include + +#ifdef HAVE_CONFIG_H +#include +#else +#define HAVE_SSTREAM +#endif + +#if defined(HAVE_SSTREAM) +#include +#elif defined(HAVE_STRSTREAM) +#include +#else +#error "Need a stringstream (sstream or strstream) to compile!" +#endif + +namespace TCLAP { + +/** + * A Constraint that constrains the Arg to only those values specified + * in the constraint. + */ +template +class ValuesConstraint : public Constraint +{ + + public: + + /** + * Constructor. + * \param allowed - vector of allowed values. + */ + ValuesConstraint(std::vector& allowed); + + /** + * Virtual destructor. + */ + virtual ~ValuesConstraint() {} + + /** + * Returns a description of the Constraint. + */ + virtual std::string description() const; + + /** + * Returns the short ID for the Constraint. + */ + virtual std::string shortID() const; + + /** + * The method used to verify that the value parsed from the command + * line meets the constraint. + * \param value - The value that will be checked. + */ + virtual bool check(const T& value) const; + + protected: + + /** + * The list of valid values. + */ + std::vector _allowed; + + /** + * The string used to describe the allowed values of this constraint. + */ + std::string _typeDesc; + +}; + +template +ValuesConstraint::ValuesConstraint(std::vector& allowed) +: _allowed(allowed), + _typeDesc("") +{ + for ( unsigned int i = 0; i < _allowed.size(); i++ ) + { + +#if defined(HAVE_SSTREAM) + std::ostringstream os; +#elif defined(HAVE_STRSTREAM) + std::ostrstream os; +#else +#error "Need a stringstream (sstream or strstream) to compile!" +#endif + + os << _allowed[i]; + + std::string temp( os.str() ); + + if ( i > 0 ) + _typeDesc += "|"; + _typeDesc += temp; + } +} + +template +bool ValuesConstraint::check( const T& val ) const +{ + if ( std::find(_allowed.begin(),_allowed.end(),val) == _allowed.end() ) + return false; + else + return true; +} + +template +std::string ValuesConstraint::shortID() const +{ + return _typeDesc; +} + +template +std::string ValuesConstraint::description() const +{ + return _typeDesc; +} + + +} //namespace TCLAP +#endif + diff --git a/xs/src/tclap/VersionVisitor.h b/xs/src/tclap/VersionVisitor.h new file mode 100644 index 0000000000..c110d4fa00 --- /dev/null +++ b/xs/src/tclap/VersionVisitor.h @@ -0,0 +1,81 @@ +// -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*- + +/****************************************************************************** + * + * file: VersionVisitor.h + * + * Copyright (c) 2003, Michael E. Smoot . + * All rights reverved. + * + * See the file COPYING in the top directory of this distribution for + * more information. + * + * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + *****************************************************************************/ + + +#ifndef TCLAP_VERSION_VISITOR_H +#define TCLAP_VERSION_VISITOR_H + +#include +#include +#include + +namespace TCLAP { + +/** + * A Vistor that will call the version method of the given CmdLineOutput + * for the specified CmdLine object and then exit. + */ +class VersionVisitor: public Visitor +{ + private: + /** + * Prevent accidental copying + */ + VersionVisitor(const VersionVisitor& rhs); + VersionVisitor& operator=(const VersionVisitor& rhs); + + protected: + + /** + * The CmdLine of interest. + */ + CmdLineInterface* _cmd; + + /** + * The output object. + */ + CmdLineOutput** _out; + + public: + + /** + * Constructor. + * \param cmd - The CmdLine the output is generated for. + * \param out - The type of output. + */ + VersionVisitor( CmdLineInterface* cmd, CmdLineOutput** out ) + : Visitor(), _cmd( cmd ), _out( out ) { } + + /** + * Calls the version method of the output object using the + * specified CmdLine. + */ + void visit() { + (*_out)->version(*_cmd); + throw ExitException(0); + } + +}; + +} + +#endif diff --git a/xs/src/tclap/Visitor.h b/xs/src/tclap/Visitor.h new file mode 100644 index 0000000000..38ddcbdb86 --- /dev/null +++ b/xs/src/tclap/Visitor.h @@ -0,0 +1,53 @@ + +/****************************************************************************** + * + * file: Visitor.h + * + * Copyright (c) 2003, Michael E. Smoot . + * All rights reverved. + * + * See the file COPYING in the top directory of this distribution for + * more information. + * + * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + *****************************************************************************/ + + +#ifndef TCLAP_VISITOR_H +#define TCLAP_VISITOR_H + +namespace TCLAP { + +/** + * A base class that defines the interface for visitors. + */ +class Visitor +{ + public: + + /** + * Constructor. Does nothing. + */ + Visitor() { } + + /** + * Destructor. Does nothing. + */ + virtual ~Visitor() { } + + /** + * Does nothing. Should be overridden by child. + */ + virtual void visit() { } +}; + +} + +#endif diff --git a/xs/src/tclap/XorHandler.h b/xs/src/tclap/XorHandler.h new file mode 100644 index 0000000000..d9dfad31f6 --- /dev/null +++ b/xs/src/tclap/XorHandler.h @@ -0,0 +1,166 @@ + +/****************************************************************************** + * + * file: XorHandler.h + * + * Copyright (c) 2003, Michael E. Smoot . + * Copyright (c) 2004, Michael E. Smoot, Daniel Aarno. + * All rights reverved. + * + * See the file COPYING in the top directory of this distribution for + * more information. + * + * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + *****************************************************************************/ + +#ifndef TCLAP_XORHANDLER_H +#define TCLAP_XORHANDLER_H + +#include +#include +#include +#include +#include + +namespace TCLAP { + +/** + * This class handles lists of Arg's that are to be XOR'd on the command + * line. This is used by CmdLine and you shouldn't ever use it. + */ +class XorHandler +{ + protected: + + /** + * The list of of lists of Arg's to be or'd together. + */ + std::vector< std::vector > _orList; + + public: + + /** + * Constructor. Does nothing. + */ + XorHandler( ) : _orList(std::vector< std::vector >()) {} + + /** + * Add a list of Arg*'s that will be orred together. + * \param ors - list of Arg* that will be xor'd. + */ + void add( std::vector& ors ); + + /** + * Checks whether the specified Arg is in one of the xor lists and + * if it does match one, returns the size of the xor list that the + * Arg matched. If the Arg matches, then it also sets the rest of + * the Arg's in the list. You shouldn't use this. + * \param a - The Arg to be checked. + */ + int check( const Arg* a ); + + /** + * Returns the XOR specific short usage. + */ + std::string shortUsage(); + + /** + * Prints the XOR specific long usage. + * \param os - Stream to print to. + */ + void printLongUsage(std::ostream& os); + + /** + * Simply checks whether the Arg is contained in one of the arg + * lists. + * \param a - The Arg to be checked. + */ + bool contains( const Arg* a ); + + std::vector< std::vector >& getXorList(); + +}; + + +////////////////////////////////////////////////////////////////////// +//BEGIN XOR.cpp +////////////////////////////////////////////////////////////////////// +inline void XorHandler::add( std::vector& ors ) +{ + _orList.push_back( ors ); +} + +inline int XorHandler::check( const Arg* a ) +{ + // iterate over each XOR list + for ( int i = 0; static_cast(i) < _orList.size(); i++ ) + { + // if the XOR list contains the arg.. + ArgVectorIterator ait = std::find( _orList[i].begin(), + _orList[i].end(), a ); + if ( ait != _orList[i].end() ) + { + // first check to see if a mutually exclusive switch + // has not already been set + for ( ArgVectorIterator it = _orList[i].begin(); + it != _orList[i].end(); + it++ ) + if ( a != (*it) && (*it)->isSet() ) + throw(CmdLineParseException( + "Mutually exclusive argument already set!", + (*it)->toString())); + + // go through and set each arg that is not a + for ( ArgVectorIterator it = _orList[i].begin(); + it != _orList[i].end(); + it++ ) + if ( a != (*it) ) + (*it)->xorSet(); + + // return the number of required args that have now been set + if ( (*ait)->allowMore() ) + return 0; + else + return static_cast(_orList[i].size()); + } + } + + if ( a->isRequired() ) + return 1; + else + return 0; +} + +inline bool XorHandler::contains( const Arg* a ) +{ + for ( int i = 0; static_cast(i) < _orList.size(); i++ ) + for ( ArgVectorIterator it = _orList[i].begin(); + it != _orList[i].end(); + it++ ) + if ( a == (*it) ) + return true; + + return false; +} + +inline std::vector< std::vector >& XorHandler::getXorList() +{ + return _orList; +} + + + +////////////////////////////////////////////////////////////////////// +//END XOR.cpp +////////////////////////////////////////////////////////////////////// + +} //namespace TCLAP + +#endif diff --git a/xs/src/tclap/ZshCompletionOutput.h b/xs/src/tclap/ZshCompletionOutput.h new file mode 100644 index 0000000000..0b37fc7296 --- /dev/null +++ b/xs/src/tclap/ZshCompletionOutput.h @@ -0,0 +1,323 @@ +// -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*- + +/****************************************************************************** + * + * file: ZshCompletionOutput.h + * + * Copyright (c) 2006, Oliver Kiddle + * All rights reverved. + * + * See the file COPYING in the top directory of this distribution for + * more information. + * + * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + *****************************************************************************/ + +#ifndef TCLAP_ZSHCOMPLETIONOUTPUT_H +#define TCLAP_ZSHCOMPLETIONOUTPUT_H + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +namespace TCLAP { + +/** + * A class that generates a Zsh completion function as output from the usage() + * method for the given CmdLine and its Args. + */ +class ZshCompletionOutput : public CmdLineOutput +{ + + public: + + ZshCompletionOutput(); + + /** + * Prints the usage to stdout. Can be overridden to + * produce alternative behavior. + * \param c - The CmdLine object the output is generated for. + */ + virtual void usage(CmdLineInterface& c); + + /** + * Prints the version to stdout. Can be overridden + * to produce alternative behavior. + * \param c - The CmdLine object the output is generated for. + */ + virtual void version(CmdLineInterface& c); + + /** + * Prints (to stderr) an error message, short usage + * Can be overridden to produce alternative behavior. + * \param c - The CmdLine object the output is generated for. + * \param e - The ArgException that caused the failure. + */ + virtual void failure(CmdLineInterface& c, + ArgException& e ); + + protected: + + void basename( std::string& s ); + void quoteSpecialChars( std::string& s ); + + std::string getMutexList( CmdLineInterface& _cmd, Arg* a ); + void printOption( Arg* it, std::string mutex ); + void printArg( Arg* it ); + + std::map common; + char theDelimiter; +}; + +ZshCompletionOutput::ZshCompletionOutput() +: common(std::map()), + theDelimiter('=') +{ + common["host"] = "_hosts"; + common["hostname"] = "_hosts"; + common["file"] = "_files"; + common["filename"] = "_files"; + common["user"] = "_users"; + common["username"] = "_users"; + common["directory"] = "_directories"; + common["path"] = "_directories"; + common["url"] = "_urls"; +} + +inline void ZshCompletionOutput::version(CmdLineInterface& _cmd) +{ + std::cout << _cmd.getVersion() << std::endl; +} + +inline void ZshCompletionOutput::usage(CmdLineInterface& _cmd ) +{ + std::list argList = _cmd.getArgList(); + std::string progName = _cmd.getProgramName(); + std::string xversion = _cmd.getVersion(); + theDelimiter = _cmd.getDelimiter(); + basename(progName); + + std::cout << "#compdef " << progName << std::endl << std::endl << + "# " << progName << " version " << _cmd.getVersion() << std::endl << std::endl << + "_arguments -s -S"; + + for (ArgListIterator it = argList.begin(); it != argList.end(); it++) + { + if ( (*it)->shortID().at(0) == '<' ) + printArg((*it)); + else if ( (*it)->getFlag() != "-" ) + printOption((*it), getMutexList(_cmd, *it)); + } + + std::cout << std::endl; +} + +inline void ZshCompletionOutput::failure( CmdLineInterface& _cmd, + ArgException& e ) +{ + static_cast(_cmd); // unused + std::cout << e.what() << std::endl; +} + +inline void ZshCompletionOutput::quoteSpecialChars( std::string& s ) +{ + size_t idx = s.find_last_of(':'); + while ( idx != std::string::npos ) + { + s.insert(idx, 1, '\\'); + idx = s.find_last_of(':', idx); + } + idx = s.find_last_of('\''); + while ( idx != std::string::npos ) + { + s.insert(idx, "'\\'"); + if (idx == 0) + idx = std::string::npos; + else + idx = s.find_last_of('\'', --idx); + } +} + +inline void ZshCompletionOutput::basename( std::string& s ) +{ + size_t p = s.find_last_of('/'); + if ( p != std::string::npos ) + { + s.erase(0, p + 1); + } +} + +inline void ZshCompletionOutput::printArg(Arg* a) +{ + static int count = 1; + + std::cout << " \\" << std::endl << " '"; + if ( a->acceptsMultipleValues() ) + std::cout << '*'; + else + std::cout << count++; + std::cout << ':'; + if ( !a->isRequired() ) + std::cout << ':'; + + std::cout << a->getName() << ':'; + std::map::iterator compArg = common.find(a->getName()); + if ( compArg != common.end() ) + { + std::cout << compArg->second; + } + else + { + std::cout << "_guard \"^-*\" " << a->getName(); + } + std::cout << '\''; +} + +inline void ZshCompletionOutput::printOption(Arg* a, std::string mutex) +{ + std::string flag = a->flagStartChar() + a->getFlag(); + std::string name = a->nameStartString() + a->getName(); + std::string desc = a->getDescription(); + + // remove full stop and capitalisation from description as + // this is the convention for zsh function + if (!desc.compare(0, 12, "(required) ")) + { + desc.erase(0, 12); + } + if (!desc.compare(0, 15, "(OR required) ")) + { + desc.erase(0, 15); + } + size_t len = desc.length(); + if (len && desc.at(--len) == '.') + { + desc.erase(len); + } + if (len) + { + desc.replace(0, 1, 1, tolower(desc.at(0))); + } + + std::cout << " \\" << std::endl << " '" << mutex; + + if ( a->getFlag().empty() ) + { + std::cout << name; + } + else + { + std::cout << "'{" << flag << ',' << name << "}'"; + } + if ( theDelimiter == '=' && a->isValueRequired() ) + std::cout << "=-"; + quoteSpecialChars(desc); + std::cout << '[' << desc << ']'; + + if ( a->isValueRequired() ) + { + std::string arg = a->shortID(); + arg.erase(0, arg.find_last_of(theDelimiter) + 1); + if ( arg.at(arg.length()-1) == ']' ) + arg.erase(arg.length()-1); + if ( arg.at(arg.length()-1) == ']' ) + { + arg.erase(arg.length()-1); + } + if ( arg.at(0) == '<' ) + { + arg.erase(arg.length()-1); + arg.erase(0, 1); + } + size_t p = arg.find('|'); + if ( p != std::string::npos ) + { + do + { + arg.replace(p, 1, 1, ' '); + } + while ( (p = arg.find_first_of('|', p)) != std::string::npos ); + quoteSpecialChars(arg); + std::cout << ": :(" << arg << ')'; + } + else + { + std::cout << ':' << arg; + std::map::iterator compArg = common.find(arg); + if ( compArg != common.end() ) + { + std::cout << ':' << compArg->second; + } + } + } + + std::cout << '\''; +} + +inline std::string ZshCompletionOutput::getMutexList( CmdLineInterface& _cmd, Arg* a) +{ + XorHandler xorHandler = _cmd.getXorHandler(); + std::vector< std::vector > xorList = xorHandler.getXorList(); + + if (a->getName() == "help" || a->getName() == "version") + { + return "(-)"; + } + + std::ostringstream list; + if ( a->acceptsMultipleValues() ) + { + list << '*'; + } + + for ( int i = 0; static_cast(i) < xorList.size(); i++ ) + { + for ( ArgVectorIterator it = xorList[i].begin(); + it != xorList[i].end(); + it++) + if ( a == (*it) ) + { + list << '('; + for ( ArgVectorIterator iu = xorList[i].begin(); + iu != xorList[i].end(); + iu++ ) + { + bool notCur = (*iu) != a; + bool hasFlag = !(*iu)->getFlag().empty(); + if ( iu != xorList[i].begin() && (notCur || hasFlag) ) + list << ' '; + if (hasFlag) + list << (*iu)->flagStartChar() << (*iu)->getFlag() << ' '; + if ( notCur || hasFlag ) + list << (*iu)->nameStartString() << (*iu)->getName(); + } + list << ')'; + return list.str(); + } + } + + // wasn't found in xor list + if (!a->getFlag().empty()) { + list << "(" << a->flagStartChar() << a->getFlag() << ' ' << + a->nameStartString() << a->getName() << ')'; + } + + return list.str(); +} + +} //namespace TCLAP +#endif From d8ef6e9cc1a09449a849aa04e26c2b4b1bbc285d Mon Sep 17 00:00:00 2001 From: Kliment Yanev Date: Wed, 1 Jun 2016 16:16:01 +0200 Subject: [PATCH 03/58] Mirror output SVG in X to conform to SVG and STL coordinate systems having opposite handedness Moved standalone-specific files to /src from /xs/src so xs will not try to build them Modified CMakeLists to match. --- src/CMakeLists.txt | 101 ++++++++++++++++++ {xs/src => src}/slic3r.cpp | 1 + {xs/src => src}/standalone/config.h | 0 {xs/src => src}/tclap/Arg.h | 0 {xs/src => src}/tclap/ArgException.h | 0 {xs/src => src}/tclap/ArgTraits.h | 0 {xs/src => src}/tclap/CmdLine.h | 0 {xs/src => src}/tclap/CmdLineInterface.h | 0 {xs/src => src}/tclap/CmdLineOutput.h | 0 {xs/src => src}/tclap/Constraint.h | 0 {xs/src => src}/tclap/DocBookOutput.h | 0 {xs/src => src}/tclap/HelpVisitor.h | 0 {xs/src => src}/tclap/IgnoreRestVisitor.h | 0 {xs/src => src}/tclap/Makefile.am | 0 {xs/src => src}/tclap/Makefile.in | 0 {xs/src => src}/tclap/MultiArg.h | 0 {xs/src => src}/tclap/MultiSwitchArg.h | 0 .../tclap/OptionalUnlabeledTracker.h | 0 {xs/src => src}/tclap/StandardTraits.h | 0 {xs/src => src}/tclap/StdOutput.h | 0 {xs/src => src}/tclap/SwitchArg.h | 0 {xs/src => src}/tclap/UnlabeledMultiArg.h | 0 {xs/src => src}/tclap/UnlabeledValueArg.h | 0 {xs/src => src}/tclap/ValueArg.h | 0 {xs/src => src}/tclap/ValuesConstraint.h | 0 {xs/src => src}/tclap/VersionVisitor.h | 0 {xs/src => src}/tclap/Visitor.h | 0 {xs/src => src}/tclap/XorHandler.h | 0 {xs/src => src}/tclap/ZshCompletionOutput.h | 0 xs/src/CMakeLists.txt | 98 ----------------- 30 files changed, 102 insertions(+), 98 deletions(-) create mode 100644 src/CMakeLists.txt rename {xs/src => src}/slic3r.cpp (99%) rename {xs/src => src}/standalone/config.h (100%) rename {xs/src => src}/tclap/Arg.h (100%) rename {xs/src => src}/tclap/ArgException.h (100%) rename {xs/src => src}/tclap/ArgTraits.h (100%) rename {xs/src => src}/tclap/CmdLine.h (100%) rename {xs/src => src}/tclap/CmdLineInterface.h (100%) rename {xs/src => src}/tclap/CmdLineOutput.h (100%) rename {xs/src => src}/tclap/Constraint.h (100%) rename {xs/src => src}/tclap/DocBookOutput.h (100%) rename {xs/src => src}/tclap/HelpVisitor.h (100%) rename {xs/src => src}/tclap/IgnoreRestVisitor.h (100%) rename {xs/src => src}/tclap/Makefile.am (100%) rename {xs/src => src}/tclap/Makefile.in (100%) rename {xs/src => src}/tclap/MultiArg.h (100%) rename {xs/src => src}/tclap/MultiSwitchArg.h (100%) rename {xs/src => src}/tclap/OptionalUnlabeledTracker.h (100%) rename {xs/src => src}/tclap/StandardTraits.h (100%) rename {xs/src => src}/tclap/StdOutput.h (100%) rename {xs/src => src}/tclap/SwitchArg.h (100%) rename {xs/src => src}/tclap/UnlabeledMultiArg.h (100%) rename {xs/src => src}/tclap/UnlabeledValueArg.h (100%) rename {xs/src => src}/tclap/ValueArg.h (100%) rename {xs/src => src}/tclap/ValuesConstraint.h (100%) rename {xs/src => src}/tclap/VersionVisitor.h (100%) rename {xs/src => src}/tclap/Visitor.h (100%) rename {xs/src => src}/tclap/XorHandler.h (100%) rename {xs/src => src}/tclap/ZshCompletionOutput.h (100%) delete mode 100644 xs/src/CMakeLists.txt diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000000..dfa9fda795 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,101 @@ +cmake_minimum_required (VERSION 2.8) +project (slic3r) +set(workaround "") +if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.7.0) +if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.7.3) +set(workaround "-fno-inline-small-functions") +endif(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.7.3) +endif(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.7.0) + +set(CMAKE_CXX_FLAGS "-D_GLIBCXX_USE_C99 -DHAS_BOOL -DNOGDI -DBOOST_ASIO_DISABLE_KQUEUE -std=c++14 ${workaround}") +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +IF(CMAKE_HOST_APPLE) + set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++ -framework IOKit -framework CoreFoundation") +ELSE(CMAKE_HOST_APPLE) + set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++") +ENDIF(CMAKE_HOST_APPLE) +set(Boost_USE_STATIC_LIBS ON) +set(Boost_USE_STATIC_RUNTIME ON) +set(CMAKE_FIND_LIBRARY_SUFFIXES ".a") +find_package(Boost COMPONENTS system thread) + +set(LIBDIR ${CMAKE_CURRENT_SOURCE_DIR}/../xs/src/) + +include_directories(${LIBDIR}) +include_directories(${LIBDIR}/libslic3r) +include_directories(${LIBDIR}/Slic3r/GUI/) +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/standalone/) +include_directories(${LIBDIR}/admesh/) +include_directories(${LIBDIR}/poly2tri/) +include_directories(${LIBDIR}/poly2tri/sweep) +include_directories(${LIBDIR}/poly2tri/common) +add_library(slic3r_gui STATIC ${LIBDIR}/slic3r/GUI/3DScene.cpp ${LIBDIR}/slic3r/GUI/GUI.cpp) +add_library(libslic3r STATIC ${LIBDIR}/libslic3r/BoundingBox.cpp + ${LIBDIR}/libslic3r/ExPolygon.cpp + ${LIBDIR}/libslic3r/GCode.cpp + ${LIBDIR}/libslic3r/LayerRegion.cpp + ${LIBDIR}/libslic3r/PerimeterGenerator.cpp + ${LIBDIR}/libslic3r/Polyline.cpp + ${LIBDIR}/libslic3r/SurfaceCollection.cpp + ${LIBDIR}/libslic3r/BridgeDetector.cpp + ${LIBDIR}/libslic3r/Extruder.cpp + ${LIBDIR}/libslic3r/GCodeSender.cpp + ${LIBDIR}/libslic3r/Line.cpp + ${LIBDIR}/libslic3r/PlaceholderParser.cpp + ${LIBDIR}/libslic3r/PrintConfig.cpp + ${LIBDIR}/libslic3r/Surface.cpp + ${LIBDIR}/libslic3r/ClipperUtils.cpp + ${LIBDIR}/libslic3r/ExtrusionEntityCollection.cpp + ${LIBDIR}/libslic3r/GCodeWriter.cpp + ${LIBDIR}/libslic3r/Model.cpp + ${LIBDIR}/libslic3r/Point.cpp + ${LIBDIR}/libslic3r/Print.cpp + ${LIBDIR}/libslic3r/SVG.cpp + ${LIBDIR}/libslic3r/SVGExport.cpp + ${LIBDIR}/libslic3r/Config.cpp + ${LIBDIR}/libslic3r/ExtrusionEntity.cpp + ${LIBDIR}/libslic3r/Geometry.cpp + ${LIBDIR}/libslic3r/MotionPlanner.cpp + ${LIBDIR}/libslic3r/Polygon.cpp + ${LIBDIR}/libslic3r/PrintObject.cpp + ${LIBDIR}/libslic3r/TriangleMesh.cpp + ${LIBDIR}/libslic3r/ExPolygonCollection.cpp + ${LIBDIR}/libslic3r/Flow.cpp + ${LIBDIR}/libslic3r/Layer.cpp + ${LIBDIR}/libslic3r/MultiPoint.cpp + ${LIBDIR}/libslic3r/PolylineCollection.cpp + ${LIBDIR}/libslic3r/PrintRegion.cpp) +add_library(admesh STATIC ${LIBDIR}/admesh/util.c ${LIBDIR}/admesh/stl_io.c ${LIBDIR}/admesh/stlinit.c ${LIBDIR}/admesh/shared.c ${LIBDIR}/admesh/normals.c ${LIBDIR}/admesh/connect.c) +add_library(clipper STATIC ${LIBDIR}/clipper.cpp) +add_library(polypartition STATIC ${LIBDIR}/polypartition.cpp) +add_library(poly2tri STATIC ${LIBDIR}/poly2tri/sweep/sweep.cc ${LIBDIR}/poly2tri/sweep/sweep_context.cc ${LIBDIR}/poly2tri/sweep/cdt.cc ${LIBDIR}/poly2tri/sweep/advancing_front.cc ${LIBDIR}/poly2tri/common/shapes.cc) +add_executable(slic3r slic3r.cpp) +set_target_properties(slic3r PROPERTIES LINK_SEARCH_START_STATIC 1) +set_target_properties(slic3r PROPERTIES LINK_SEARCH_END_STATIC 1) +set(wxWidgets_USE_STATIC) +SET(wxWidgets_USE_LIBS) + +set(Boost_USE_STATIC_LIBS ON) +set(Boost_USE_STATIC_RUNTIME ON) +set(CMAKE_FIND_LIBRARY_SUFFIXES ".a") +find_library(bsystem_l boost_system) +add_library(bsystem STATIC IMPORTED) +set_target_properties(bsystem PROPERTIES IMPORTED_LOCATION ${bsystem_l}) +find_library(bthread_l boost_thread) +add_library(bthread STATIC IMPORTED) +set_target_properties(bthread PROPERTIES IMPORTED_LOCATION ${bthread_l}) +include_directories(${Boost_INCLUDE_DIRS}) + +#find_package(wxWidgets) + +IF(wxWidgets_FOUND) + MESSAGE("wx found!") + INCLUDE("${wxWidgets_USE_FILE}") + target_link_libraries (slic3r slic3r_gui libslic3r admesh clipper polypartition poly2tri bsystem bthread ${wxWidgets_LIBRARIES}) +ELSE(wxWidgets_FOUND) + # For convenience. When we cannot continue, inform the user + MESSAGE("wx not found!") + target_link_libraries (slic3r slic3r_gui libslic3r admesh clipper polypartition poly2tri bsystem bthread) +ENDIF(wxWidgets_FOUND) + diff --git a/xs/src/slic3r.cpp b/src/slic3r.cpp similarity index 99% rename from xs/src/slic3r.cpp rename to src/slic3r.cpp index 219435ec0b..7e39ae0e3a 100644 --- a/xs/src/slic3r.cpp +++ b/src/slic3r.cpp @@ -25,6 +25,7 @@ void exportSVG(const char* stlname, const char* svgname, float layerheight=0.2, t.repair(); t.scale(scale); t.rotate_z(rotate); + t.mirror_x(); t.align_to_origin(); SVGExport e(t,layerheight,initialheight); const char* svgfilename=outname.data(); diff --git a/xs/src/standalone/config.h b/src/standalone/config.h similarity index 100% rename from xs/src/standalone/config.h rename to src/standalone/config.h diff --git a/xs/src/tclap/Arg.h b/src/tclap/Arg.h similarity index 100% rename from xs/src/tclap/Arg.h rename to src/tclap/Arg.h diff --git a/xs/src/tclap/ArgException.h b/src/tclap/ArgException.h similarity index 100% rename from xs/src/tclap/ArgException.h rename to src/tclap/ArgException.h diff --git a/xs/src/tclap/ArgTraits.h b/src/tclap/ArgTraits.h similarity index 100% rename from xs/src/tclap/ArgTraits.h rename to src/tclap/ArgTraits.h diff --git a/xs/src/tclap/CmdLine.h b/src/tclap/CmdLine.h similarity index 100% rename from xs/src/tclap/CmdLine.h rename to src/tclap/CmdLine.h diff --git a/xs/src/tclap/CmdLineInterface.h b/src/tclap/CmdLineInterface.h similarity index 100% rename from xs/src/tclap/CmdLineInterface.h rename to src/tclap/CmdLineInterface.h diff --git a/xs/src/tclap/CmdLineOutput.h b/src/tclap/CmdLineOutput.h similarity index 100% rename from xs/src/tclap/CmdLineOutput.h rename to src/tclap/CmdLineOutput.h diff --git a/xs/src/tclap/Constraint.h b/src/tclap/Constraint.h similarity index 100% rename from xs/src/tclap/Constraint.h rename to src/tclap/Constraint.h diff --git a/xs/src/tclap/DocBookOutput.h b/src/tclap/DocBookOutput.h similarity index 100% rename from xs/src/tclap/DocBookOutput.h rename to src/tclap/DocBookOutput.h diff --git a/xs/src/tclap/HelpVisitor.h b/src/tclap/HelpVisitor.h similarity index 100% rename from xs/src/tclap/HelpVisitor.h rename to src/tclap/HelpVisitor.h diff --git a/xs/src/tclap/IgnoreRestVisitor.h b/src/tclap/IgnoreRestVisitor.h similarity index 100% rename from xs/src/tclap/IgnoreRestVisitor.h rename to src/tclap/IgnoreRestVisitor.h diff --git a/xs/src/tclap/Makefile.am b/src/tclap/Makefile.am similarity index 100% rename from xs/src/tclap/Makefile.am rename to src/tclap/Makefile.am diff --git a/xs/src/tclap/Makefile.in b/src/tclap/Makefile.in similarity index 100% rename from xs/src/tclap/Makefile.in rename to src/tclap/Makefile.in diff --git a/xs/src/tclap/MultiArg.h b/src/tclap/MultiArg.h similarity index 100% rename from xs/src/tclap/MultiArg.h rename to src/tclap/MultiArg.h diff --git a/xs/src/tclap/MultiSwitchArg.h b/src/tclap/MultiSwitchArg.h similarity index 100% rename from xs/src/tclap/MultiSwitchArg.h rename to src/tclap/MultiSwitchArg.h diff --git a/xs/src/tclap/OptionalUnlabeledTracker.h b/src/tclap/OptionalUnlabeledTracker.h similarity index 100% rename from xs/src/tclap/OptionalUnlabeledTracker.h rename to src/tclap/OptionalUnlabeledTracker.h diff --git a/xs/src/tclap/StandardTraits.h b/src/tclap/StandardTraits.h similarity index 100% rename from xs/src/tclap/StandardTraits.h rename to src/tclap/StandardTraits.h diff --git a/xs/src/tclap/StdOutput.h b/src/tclap/StdOutput.h similarity index 100% rename from xs/src/tclap/StdOutput.h rename to src/tclap/StdOutput.h diff --git a/xs/src/tclap/SwitchArg.h b/src/tclap/SwitchArg.h similarity index 100% rename from xs/src/tclap/SwitchArg.h rename to src/tclap/SwitchArg.h diff --git a/xs/src/tclap/UnlabeledMultiArg.h b/src/tclap/UnlabeledMultiArg.h similarity index 100% rename from xs/src/tclap/UnlabeledMultiArg.h rename to src/tclap/UnlabeledMultiArg.h diff --git a/xs/src/tclap/UnlabeledValueArg.h b/src/tclap/UnlabeledValueArg.h similarity index 100% rename from xs/src/tclap/UnlabeledValueArg.h rename to src/tclap/UnlabeledValueArg.h diff --git a/xs/src/tclap/ValueArg.h b/src/tclap/ValueArg.h similarity index 100% rename from xs/src/tclap/ValueArg.h rename to src/tclap/ValueArg.h diff --git a/xs/src/tclap/ValuesConstraint.h b/src/tclap/ValuesConstraint.h similarity index 100% rename from xs/src/tclap/ValuesConstraint.h rename to src/tclap/ValuesConstraint.h diff --git a/xs/src/tclap/VersionVisitor.h b/src/tclap/VersionVisitor.h similarity index 100% rename from xs/src/tclap/VersionVisitor.h rename to src/tclap/VersionVisitor.h diff --git a/xs/src/tclap/Visitor.h b/src/tclap/Visitor.h similarity index 100% rename from xs/src/tclap/Visitor.h rename to src/tclap/Visitor.h diff --git a/xs/src/tclap/XorHandler.h b/src/tclap/XorHandler.h similarity index 100% rename from xs/src/tclap/XorHandler.h rename to src/tclap/XorHandler.h diff --git a/xs/src/tclap/ZshCompletionOutput.h b/src/tclap/ZshCompletionOutput.h similarity index 100% rename from xs/src/tclap/ZshCompletionOutput.h rename to src/tclap/ZshCompletionOutput.h diff --git a/xs/src/CMakeLists.txt b/xs/src/CMakeLists.txt deleted file mode 100644 index 9a862b9a8b..0000000000 --- a/xs/src/CMakeLists.txt +++ /dev/null @@ -1,98 +0,0 @@ -cmake_minimum_required (VERSION 2.8) -project (slic3r) -set(workaround "") -if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.7.0) -if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.7.3) -set(workaround "-fno-inline-small-functions") -endif(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.7.3) -endif(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.7.0) - -set(CMAKE_CXX_FLAGS "-D_GLIBCXX_USE_C99 -DHAS_BOOL -DNOGDI -DBOOST_ASIO_DISABLE_KQUEUE -std=c++14 ${workaround}") -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -IF(CMAKE_HOST_APPLE) - set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++ -framework IOKit -framework CoreFoundation") -ELSE(CMAKE_HOST_APPLE) - set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++") -ENDIF(CMAKE_HOST_APPLE) -set(Boost_USE_STATIC_LIBS ON) -set(Boost_USE_STATIC_RUNTIME ON) -set(CMAKE_FIND_LIBRARY_SUFFIXES ".a") -find_package(Boost COMPONENTS system thread) - -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/libslic3r) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/Slic3r/GUI/) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/standalone/) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/admesh/) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/poly2tri/) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/poly2tri/sweep) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/poly2tri/common) -add_library(slic3r_gui STATIC slic3r/GUI/3DScene.cpp slic3r/GUI/GUI.cpp) -add_library(libslic3r STATIC libslic3r/BoundingBox.cpp - libslic3r/ExPolygon.cpp - libslic3r/GCode.cpp - libslic3r/LayerRegion.cpp - libslic3r/PerimeterGenerator.cpp - libslic3r/Polyline.cpp - libslic3r/SurfaceCollection.cpp - libslic3r/BridgeDetector.cpp - libslic3r/Extruder.cpp - libslic3r/GCodeSender.cpp - libslic3r/Line.cpp - libslic3r/PlaceholderParser.cpp - libslic3r/PrintConfig.cpp - libslic3r/Surface.cpp - libslic3r/ClipperUtils.cpp - libslic3r/ExtrusionEntityCollection.cpp - libslic3r/GCodeWriter.cpp - libslic3r/Model.cpp - libslic3r/Point.cpp - libslic3r/Print.cpp - libslic3r/SVG.cpp - libslic3r/SVGExport.cpp - libslic3r/Config.cpp - libslic3r/ExtrusionEntity.cpp - libslic3r/Geometry.cpp - libslic3r/MotionPlanner.cpp - libslic3r/Polygon.cpp - libslic3r/PrintObject.cpp - libslic3r/TriangleMesh.cpp - libslic3r/ExPolygonCollection.cpp - libslic3r/Flow.cpp - libslic3r/Layer.cpp - libslic3r/MultiPoint.cpp - libslic3r/PolylineCollection.cpp - libslic3r/PrintRegion.cpp) -add_library(admesh STATIC admesh/util.c admesh/stl_io.c admesh/stlinit.c admesh/shared.c admesh/normals.c admesh/connect.c) -add_library(clipper STATIC clipper.cpp) -add_library(polypartition STATIC polypartition.cpp) -add_library(poly2tri STATIC poly2tri/sweep/sweep.cc poly2tri/sweep/sweep_context.cc poly2tri/sweep/cdt.cc poly2tri/sweep/advancing_front.cc poly2tri/common/shapes.cc) -add_executable(slic3r slic3r.cpp) -set_target_properties(slic3r PROPERTIES LINK_SEARCH_START_STATIC 1) -set_target_properties(slic3r PROPERTIES LINK_SEARCH_END_STATIC 1) -set(wxWidgets_USE_STATIC) -SET(wxWidgets_USE_LIBS) - -set(Boost_USE_STATIC_LIBS ON) -set(Boost_USE_STATIC_RUNTIME ON) -set(CMAKE_FIND_LIBRARY_SUFFIXES ".a") -find_library(bsystem_l boost_system) -add_library(bsystem STATIC IMPORTED) -set_target_properties(bsystem PROPERTIES IMPORTED_LOCATION ${bsystem_l}) -find_library(bthread_l boost_thread) -add_library(bthread STATIC IMPORTED) -set_target_properties(bthread PROPERTIES IMPORTED_LOCATION ${bthread_l}) -include_directories(${Boost_INCLUDE_DIRS}) - -#find_package(wxWidgets) - -IF(wxWidgets_FOUND) - MESSAGE("wx found!") - INCLUDE("${wxWidgets_USE_FILE}") - target_link_libraries (slic3r slic3r_gui libslic3r admesh clipper polypartition poly2tri bsystem bthread ${wxWidgets_LIBRARIES}) -ELSE(wxWidgets_FOUND) - # For convenience. When we cannot continue, inform the user - MESSAGE("wx not found!") - target_link_libraries (slic3r slic3r_gui libslic3r admesh clipper polypartition poly2tri bsystem bthread) -ENDIF(wxWidgets_FOUND) - From 257e34573ee7974f3d08e9710412182f2b1f2243 Mon Sep 17 00:00:00 2001 From: Kliment Yanev Date: Wed, 1 Jun 2016 20:19:28 +0200 Subject: [PATCH 04/58] Modified build system for static linking of boost on windows/mingw Added Windows/MinGW build instructions --- src/CMakeLists.txt | 12 ++++++++---- src/windows-build.txt | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 4 deletions(-) create mode 100644 src/windows-build.txt diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index dfa9fda795..5fd7d09e65 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -7,7 +7,7 @@ set(workaround "-fno-inline-small-functions") endif(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.7.3) endif(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.7.0) -set(CMAKE_CXX_FLAGS "-D_GLIBCXX_USE_C99 -DHAS_BOOL -DNOGDI -DBOOST_ASIO_DISABLE_KQUEUE -std=c++14 ${workaround}") +set(CMAKE_CXX_FLAGS "-DM_PI=3.14159265358979323846 -D_GLIBCXX_USE_C99 -DHAS_BOOL -DNOGDI -DBOOST_ASIO_DISABLE_KQUEUE -std=c++14 ${workaround}") set(CMAKE_INCLUDE_CURRENT_DIR ON) IF(CMAKE_HOST_APPLE) @@ -88,14 +88,18 @@ set_target_properties(bthread PROPERTIES IMPORTED_LOCATION ${bthread_l}) include_directories(${Boost_INCLUDE_DIRS}) #find_package(wxWidgets) - +#disable wx for the time being - we're not building any of the gui yet +IF(CMAKE_HOST_UNIX) + set(Boost_LIBRARIES bsystem bthread) +ENDIF(CMAKE_HOST_UNIX) IF(wxWidgets_FOUND) MESSAGE("wx found!") INCLUDE("${wxWidgets_USE_FILE}") - target_link_libraries (slic3r slic3r_gui libslic3r admesh clipper polypartition poly2tri bsystem bthread ${wxWidgets_LIBRARIES}) + target_link_libraries (slic3r slic3r_gui libslic3r admesh clipper polypartition poly2tri ${Boost_LIBRARIES} ${wxWidgets_LIBRARIES}) ELSE(wxWidgets_FOUND) # For convenience. When we cannot continue, inform the user MESSAGE("wx not found!") - target_link_libraries (slic3r slic3r_gui libslic3r admesh clipper polypartition poly2tri bsystem bthread) + target_link_libraries (slic3r libslic3r admesh clipper polypartition poly2tri ${Boost_LIBRARIES}) + #skip gui when no wx included ENDIF(wxWidgets_FOUND) diff --git a/src/windows-build.txt b/src/windows-build.txt new file mode 100644 index 0000000000..7e98c69436 --- /dev/null +++ b/src/windows-build.txt @@ -0,0 +1,36 @@ +Install: +mingw +boost +cmake +git + +Assuming boost is in c:\program files\boost\boost_1_61_0 and mingw is in c:\mingw + +start cmd.exe +> cd c:\program files\boost\boost_1_61_0 +> set PATH=c:\mingw\bin +> bootstrap gcc +> .\b2 --build-dir=c:\boost-mingw toolset=gcc link=static runtime-link=static variant=release --with-system --with-thread +leave cmd window open + +start git bash +> cd /c +> git clone http://github.com/alexrj/slic3r +> cd slic3r +> git checkout cppsvg +close git bash when done + +make sure c:\mingw\bin is part of the Path system variable, add it otherwise + +start cmake gui +source code: c:\slic3r\src +build directory: c:\slic3r\build +click configure, select "mingw makefiles" from list, select "default native compilers", click finish +click generate +close cmake gui + +go back to cmd window +> cd c:\slic3r\build +> mingw32-make.exe +might be mingw64 on 64-bit setup, I'm not sure +The resulting slic3r.exe is the target executable, it has no dependencies except windows system libraries (kernel32 and msvcrt) From fdd745386796ede4cb8ff79610b1a7c4072472ce Mon Sep 17 00:00:00 2001 From: Kliment Yanev Date: Wed, 1 Jun 2016 20:25:02 +0200 Subject: [PATCH 05/58] Only build GUI lib if building with wx --- src/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5fd7d09e65..a79b5ed3b7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -30,7 +30,6 @@ include_directories(${LIBDIR}/admesh/) include_directories(${LIBDIR}/poly2tri/) include_directories(${LIBDIR}/poly2tri/sweep) include_directories(${LIBDIR}/poly2tri/common) -add_library(slic3r_gui STATIC ${LIBDIR}/slic3r/GUI/3DScene.cpp ${LIBDIR}/slic3r/GUI/GUI.cpp) add_library(libslic3r STATIC ${LIBDIR}/libslic3r/BoundingBox.cpp ${LIBDIR}/libslic3r/ExPolygon.cpp ${LIBDIR}/libslic3r/GCode.cpp @@ -95,6 +94,8 @@ ENDIF(CMAKE_HOST_UNIX) IF(wxWidgets_FOUND) MESSAGE("wx found!") INCLUDE("${wxWidgets_USE_FILE}") + add_library(slic3r_gui STATIC ${LIBDIR}/slic3r/GUI/3DScene.cpp ${LIBDIR}/slic3r/GUI/GUI.cpp) + #only build GUI lib if building with wx target_link_libraries (slic3r slic3r_gui libslic3r admesh clipper polypartition poly2tri ${Boost_LIBRARIES} ${wxWidgets_LIBRARIES}) ELSE(wxWidgets_FOUND) # For convenience. When we cannot continue, inform the user From b1426514d1ce4df7316f7fee88d4a7edcf3b4ceb Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Tue, 14 Jun 2016 22:20:55 +0200 Subject: [PATCH 06/58] Command line call for cmake --- src/windows-build.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/windows-build.txt b/src/windows-build.txt index 7e98c69436..e2a4aa23cd 100644 --- a/src/windows-build.txt +++ b/src/windows-build.txt @@ -29,6 +29,10 @@ click configure, select "mingw makefiles" from list, select "default native comp click generate close cmake gui +alternatively, do it from command line: +cmake ..\src -G "MinGW Makefiles" -DBOOST_ROOT="c:\program files\boost\boost_1_61_0" +(in case cmake can't find the libs, -DBoost_DEBUG=1 and -DBoost_COMPILER=-mgw46 are useful) + go back to cmd window > cd c:\slic3r\build > mingw32-make.exe From a3ad66824c41a8d7e5272e6474d6dd6dbe202731 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Tue, 14 Jun 2016 22:34:55 +0200 Subject: [PATCH 07/58] We don't need c++14 --- src/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a79b5ed3b7..1b6a5184ec 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -7,7 +7,7 @@ set(workaround "-fno-inline-small-functions") endif(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.7.3) endif(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.7.0) -set(CMAKE_CXX_FLAGS "-DM_PI=3.14159265358979323846 -D_GLIBCXX_USE_C99 -DHAS_BOOL -DNOGDI -DBOOST_ASIO_DISABLE_KQUEUE -std=c++14 ${workaround}") +set(CMAKE_CXX_FLAGS "-DM_PI=3.14159265358979323846 -D_GLIBCXX_USE_C99 -DHAS_BOOL -DNOGDI -DBOOST_ASIO_DISABLE_KQUEUE ${workaround}") set(CMAKE_INCLUDE_CURRENT_DIR ON) IF(CMAKE_HOST_APPLE) From 9d1fb2e854a380c6b5f3159bf6a19c31efa74265 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Wed, 22 Jun 2016 17:19:04 +0200 Subject: [PATCH 08/58] Fix CMake compilation on OS X --- src/CMakeLists.txt | 4 ++-- xs/src/libslic3r/SVGExport.cpp | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1b6a5184ec..89bd31396f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -11,7 +11,7 @@ set(CMAKE_CXX_FLAGS "-DM_PI=3.14159265358979323846 -D_GLIBCXX_USE_C99 -DHAS_BOOL set(CMAKE_INCLUDE_CURRENT_DIR ON) IF(CMAKE_HOST_APPLE) - set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++ -framework IOKit -framework CoreFoundation") + set(CMAKE_EXE_LINKER_FLAGS "-framework IOKit -framework CoreFoundation") ELSE(CMAKE_HOST_APPLE) set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++") ENDIF(CMAKE_HOST_APPLE) @@ -89,7 +89,7 @@ include_directories(${Boost_INCLUDE_DIRS}) #find_package(wxWidgets) #disable wx for the time being - we're not building any of the gui yet IF(CMAKE_HOST_UNIX) - set(Boost_LIBRARIES bsystem bthread) + #set(Boost_LIBRARIES bsystem bthread) ENDIF(CMAKE_HOST_UNIX) IF(wxWidgets_FOUND) MESSAGE("wx found!") diff --git a/xs/src/libslic3r/SVGExport.cpp b/xs/src/libslic3r/SVGExport.cpp index f700ca34b3..2fb1b0cf56 100644 --- a/xs/src/libslic3r/SVGExport.cpp +++ b/xs/src/libslic3r/SVGExport.cpp @@ -9,7 +9,6 @@ namespace Slic3r { SVGExport::SVGExport(TriangleMesh &t, float layerheight, float firstlayerheight) :t(&t), sliced(false) { - heights={}; if(layerheight>0){ for(float f=firstlayerheight;f<=t.stl.stats.max.z;f+=layerheight){ heights.push_back(f); From 64da78788be0c03f75f4cacb6d402afbd9a49876 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Wed, 22 Jun 2016 17:45:10 +0200 Subject: [PATCH 09/58] Added --export-obj to slic3r.cpp. Some refactoring included --- src/CMakeLists.txt | 1 + src/slic3r.cpp | 68 ++++++++++++++++++++-------------- xs/src/libslic3r/IO.cpp | 2 +- xs/src/libslic3r/IO.hpp | 6 +-- xs/src/libslic3r/SVGExport.cpp | 6 +-- xs/src/libslic3r/SVGExport.hpp | 2 +- 6 files changed, 50 insertions(+), 35 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 89bd31396f..2c117bdcac 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -40,6 +40,7 @@ add_library(libslic3r STATIC ${LIBDIR}/libslic3r/BoundingBox.cpp ${LIBDIR}/libslic3r/BridgeDetector.cpp ${LIBDIR}/libslic3r/Extruder.cpp ${LIBDIR}/libslic3r/GCodeSender.cpp + ${LIBDIR}/libslic3r/IO.cpp ${LIBDIR}/libslic3r/Line.cpp ${LIBDIR}/libslic3r/PlaceholderParser.cpp ${LIBDIR}/libslic3r/PrintConfig.cpp diff --git a/src/slic3r.cpp b/src/slic3r.cpp index 7e39ae0e3a..a7e640f2a4 100644 --- a/src/slic3r.cpp +++ b/src/slic3r.cpp @@ -1,5 +1,5 @@ - - +#include "Model.hpp" +#include "IO.hpp" #include "TriangleMesh.hpp" #include "SVGExport.hpp" #include "libslic3r.h" @@ -13,29 +13,20 @@ using namespace Slic3r; void confess_at(const char *file, int line, const char *func, const char *pat, ...){} -void exportSVG(const char* stlname, const char* svgname, float layerheight=0.2, float initialheight=0., float scale=1.0, float rotate=0.){ - TriangleMesh t; - std::string outname; - if(strlen(svgname)==0){ - outname=outname+stlname+".svg"; - }else{ - outname=outname+svgname; - } - t.ReadSTLFile(const_cast(stlname)); - t.repair(); - t.scale(scale); - t.rotate_z(rotate); - t.mirror_x(); - t.align_to_origin(); - SVGExport e(t,layerheight,initialheight); - const char* svgfilename=outname.data(); - e.writeSVG(svgfilename); - printf("writing: %s\n",svgfilename); +void exportSVG(const Model &model, const std::string &outfile, float layerheight=0.2, float initialheight=0., float scale=1.0, float rotate=0.){ + TriangleMesh mesh = model.mesh(); + mesh.scale(scale); + mesh.rotate_z(rotate); + mesh.mirror_x(); + mesh.align_to_origin(); + SVGExport e(mesh, layerheight, initialheight); + e.writeSVG(outfile); + printf("writing: %s\n", outfile.c_str()); } int main (int argc, char **argv){ - try{ + try { TCLAP::CmdLine cmd("Rudimentary commandline slic3r, currently only supports STL to SVG slice export.", ' ', SLIC3R_VERSION); TCLAP::ValueArg outputArg("o","output","File to output results to",false,"","output file name"); cmd.add( outputArg ); @@ -48,18 +39,41 @@ int main (int argc, char **argv){ TCLAP::ValueArg lhArg("","layer-height","Layer height in mm (default: 0.2)",false,0.2,"float"); cmd.add( lhArg ); TCLAP::SwitchArg expsvg("","export-svg","Export a SVG file containing slices", cmd, false); + TCLAP::SwitchArg expobj("","export-obj","Export the input file as OBJ", cmd, false); TCLAP::UnlabeledValueArg input("inputfile","Input STL file name", true, "", "input file name"); cmd.add(input); cmd.parse(argc,argv); - if(expsvg.getValue()){ - exportSVG(input.getValue().data(),outputArg.getValue().data(),lhArg.getValue(),flhArg.getValue(),scaleArg.getValue(),rotArg.getValue()); - }else{ - std::cerr << "error: only svg export currently supported"<< std::endl; + + // read input file if any (TODO: read multiple) + Model model; + if (!input.getValue().empty()) { + Slic3r::IO::STL::read(input.getValue(), &model); + model.add_default_instances(); + } + + if (expobj.getValue()) { + std::string outfile = outputArg.getValue(); + if (outfile.empty()) outfile = input.getValue() + ".obj"; + + TriangleMesh mesh = model.mesh(); + printf("mesh has %zu facets\n", mesh.facets_count()); + Slic3r::IO::OBJ::write(mesh, outfile); + printf("File exported to %s\n", outfile.c_str()); + } else if (expsvg.getValue()) { + std::string outfile = outputArg.getValue(); + if (outfile.empty()) outfile = input.getValue() + ".svg"; + + exportSVG(model, outfile, lhArg.getValue(), flhArg.getValue(), scaleArg.getValue(), rotArg.getValue()); + } else { + std::cerr << "error: only --export-svg and --export-obj are currently supported"<< std::endl; return 1; } - }catch (TCLAP::ArgException &e) - { std::cerr << "error: " << e.error() << " for arg " << e.argId() << std::endl; } + } catch (TCLAP::ArgException &e) { + std::cerr << "error: " << e.error() << " for arg " << e.argId() << std::endl; + return 1; + } + return 0; } diff --git a/xs/src/libslic3r/IO.cpp b/xs/src/libslic3r/IO.cpp index 81ac8a127e..7bd42cea5e 100644 --- a/xs/src/libslic3r/IO.cpp +++ b/xs/src/libslic3r/IO.cpp @@ -4,7 +4,7 @@ namespace Slic3r { namespace IO { bool -STL::read_file(std::string input_file, Model* model) +STL::read(std::string input_file, Model* model) { // TODO: encode file name // TODO: check that file exists diff --git a/xs/src/libslic3r/IO.hpp b/xs/src/libslic3r/IO.hpp index 248f3be540..0c3cd991f8 100644 --- a/xs/src/libslic3r/IO.hpp +++ b/xs/src/libslic3r/IO.hpp @@ -11,14 +11,14 @@ namespace Slic3r { namespace IO { class STL { public: - bool read_file(std::string input_file, Model* model); - bool write(TriangleMesh& mesh, std::string output_file, bool binary = true); + static bool read(std::string input_file, Model* model); + static bool write(TriangleMesh& mesh, std::string output_file, bool binary = true); }; class OBJ { public: - bool write(TriangleMesh& mesh, std::string output_file); + static bool write(TriangleMesh& mesh, std::string output_file); }; } } diff --git a/xs/src/libslic3r/SVGExport.cpp b/xs/src/libslic3r/SVGExport.cpp index 2fb1b0cf56..ead30a04e1 100644 --- a/xs/src/libslic3r/SVGExport.cpp +++ b/xs/src/libslic3r/SVGExport.cpp @@ -22,9 +22,9 @@ SVGExport::SVGExport(TriangleMesh &t, float layerheight, float firstlayerheight) // -void SVGExport::writeSVG(const char* outputfile){ +void SVGExport::writeSVG(const std::string &outputfile){ if(sliced){ - FILE* f = fopen(outputfile, "w"); + FILE* f = fopen(outputfile.c_str(), "w"); fprintf(f, "\n" "\n" @@ -32,7 +32,7 @@ void SVGExport::writeSVG(const char* outputfile){ "\n" ,t->stl.stats.max.x*10,t->stl.stats.max.y*10,SLIC3R_VERSION); for (int i=0;i",i,heights[i]); + fprintf(f,"\t\n",i,heights[i]); for (ExPolygons::const_iterator it = layers[i].begin(); it != layers[i].end(); ++it){ std::string pd; Polygons pp = *it; diff --git a/xs/src/libslic3r/SVGExport.hpp b/xs/src/libslic3r/SVGExport.hpp index 554e627b6b..3d5f2b127a 100644 --- a/xs/src/libslic3r/SVGExport.hpp +++ b/xs/src/libslic3r/SVGExport.hpp @@ -12,7 +12,7 @@ class SVGExport { public: SVGExport(TriangleMesh &t, float layerheight, float firstlayerheight=0.0); - void writeSVG(const char* outputfile); + void writeSVG(const std::string &outputfile); private: TriangleMesh *t; std::vector layers; From 7cb20eb21a587fdfa53366d0be8a1cd1a5f8d6c6 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Tue, 28 Jun 2016 19:34:56 -0500 Subject: [PATCH 10/58] batch files to aid in producing built zip files. --- utils/autorun.bat | 1 + utils/package_win32.bat | 15 +++++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 utils/autorun.bat create mode 100644 utils/package_win32.bat diff --git a/utils/autorun.bat b/utils/autorun.bat new file mode 100644 index 0000000000..9b42380cdb --- /dev/null +++ b/utils/autorun.bat @@ -0,0 +1 @@ +@perl5.22.1.exe script/slic3r.pl diff --git a/utils/package_win32.bat b/utils/package_win32.bat new file mode 100644 index 0000000000..39d6f0fd6f --- /dev/null +++ b/utils/package_win32.bat @@ -0,0 +1,15 @@ +REM Written by Joseph Lenox +REM Licensed under the same license as the rest of Slic3r. +REM ------------------------ +REM You need to have Strawberry Perl 5.22 installed for this to work, +echo "Make this is run from the perl command window." +echo "Requires PAR." + +REM Change this to where you have Strawberry Perl installed. +SET STRAWBERRY_PATH=C:\Strawberry + +cpanm "PAR::Packer" + +pp -a %STRAWBERRY_PATH%\perl\bin\perl5.22.1.exe;perl5.22.1.exe -a %STRAWBERRY%\perl\bin\freeglut.dll;freeglut.dll -a %STRAWBERRY%\perl\bin\perl522.dll;perl522.dll -a %STRAWBERRY%\perl\bin\libgcc_s_sjlj-1.dll;libgcc_s_sjlj-1.dll -a %STRAWBERRY%\perl\bin\libstdc++-6.dll;libstdc++-6.dll -a %STRAWBERRY%\perl\bin\libwinpthread-1.dll;libwinpthread-1.dll -a %STRAWBERRY%\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxbase30u_gcc_custom.dll -a %STRAWBERRY%\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxmsw30u_adv_gcc_custom.dll -a %STRAWBERRY%\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxmsw30u_core_gcc_custom.dll -a %STRAWBERRY%\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxmsw30u_gl_gcc_custom.dll -a %STRAWBERRY%\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxmsw30u_html_gcc_custom.dll -a ..\utils;script\utils -a var;script\var -a autorun.bat;slic3r.bat -e -p -x slic3r.pl --xargs --gui -o ..\slic3r.par + +copy ..\slic3r.par ..\slic3r.zip From 1f63e89d5bd1f24481114a97280766d6ebdcfc20 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Wed, 29 Jun 2016 07:22:18 -0500 Subject: [PATCH 11/58] added partial modules list added powershell script --- utils/package_win32.bat | 2 +- utils/package_win32.ps1 | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 utils/package_win32.ps1 diff --git a/utils/package_win32.bat b/utils/package_win32.bat index 39d6f0fd6f..26184c86e4 100644 --- a/utils/package_win32.bat +++ b/utils/package_win32.bat @@ -10,6 +10,6 @@ SET STRAWBERRY_PATH=C:\Strawberry cpanm "PAR::Packer" -pp -a %STRAWBERRY_PATH%\perl\bin\perl5.22.1.exe;perl5.22.1.exe -a %STRAWBERRY%\perl\bin\freeglut.dll;freeglut.dll -a %STRAWBERRY%\perl\bin\perl522.dll;perl522.dll -a %STRAWBERRY%\perl\bin\libgcc_s_sjlj-1.dll;libgcc_s_sjlj-1.dll -a %STRAWBERRY%\perl\bin\libstdc++-6.dll;libstdc++-6.dll -a %STRAWBERRY%\perl\bin\libwinpthread-1.dll;libwinpthread-1.dll -a %STRAWBERRY%\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxbase30u_gcc_custom.dll -a %STRAWBERRY%\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxmsw30u_adv_gcc_custom.dll -a %STRAWBERRY%\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxmsw30u_core_gcc_custom.dll -a %STRAWBERRY%\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxmsw30u_gl_gcc_custom.dll -a %STRAWBERRY%\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxmsw30u_html_gcc_custom.dll -a ..\utils;script\utils -a var;script\var -a autorun.bat;slic3r.bat -e -p -x slic3r.pl --xargs --gui -o ..\slic3r.par +pp -a %STRAWBERRY_PATH%\perl\bin\perl5.22.1.exe;perl5.22.1.exe -a %STRAWBERRY%\perl\bin\freeglut.dll;freeglut.dll -a %STRAWBERRY%\perl\bin\perl522.dll;perl522.dll -a %STRAWBERRY%\perl\bin\libgcc_s_sjlj-1.dll;libgcc_s_sjlj-1.dll -a %STRAWBERRY%\perl\bin\libstdc++-6.dll;libstdc++-6.dll -a %STRAWBERRY%\perl\bin\libwinpthread-1.dll;libwinpthread-1.dll -a %STRAWBERRY%\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxbase30u_gcc_custom.dll -a %STRAWBERRY%\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxmsw30u_adv_gcc_custom.dll -a %STRAWBERRY%\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxmsw30u_core_gcc_custom.dll -a %STRAWBERRY%\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxmsw30u_gl_gcc_custom.dll -a %STRAWBERRY%\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxmsw30u_html_gcc_custom.dll -a ..\utils;script\utils -a var;script\var -a autorun.bat;slic3r.bat -M Encode::Locale -M Moo -M Thread::Semaphore -M OpenGL -M Slic3r::XS -M Unicode::Normalize -M Wx -M Class::Accessor -M Wx::DND -M Wx::Grid -M Wx::Print -M Wx::Html -M Wx::GLCanvas -M Math::Trig -M threads -M threads::shared -M Thread::Queue -e -p -x slic3r.pl -o ..\slic3r.par copy ..\slic3r.par ..\slic3r.zip diff --git a/utils/package_win32.ps1 b/utils/package_win32.ps1 new file mode 100644 index 0000000000..0a6cde4996 --- /dev/null +++ b/utils/package_win32.ps1 @@ -0,0 +1,17 @@ +# Written by Joseph Lenox +# Licensed under the same license as the rest of Slic3r. +# ------------------------ +# You need to have Strawberry Perl 5.22 installed for this to work, +echo "Make this is run from the perl command window." +echo "Requires PAR." + +# Change this to where you have Strawberry Perl installed. +#SET STRAWBERRY_PATH=C:\Strawberry +$STRAWBERRY_PATH=C:\Strawberry +# ([io.fileinfo](Get-Command "perl.exe").Path).basename + +cpanm "PAR::Packer" + +pp -a $STRAWBERRY_PATH\perl\bin\perl5.22.1.exe;perl5.22.1.exe -a $STRAWBERRY_PATH\perl\bin\freeglut.dll;freeglut.dll -a $STRAWBERRY_PATH\perl\bin\perl522.dll;perl522.dll -a $STRAWBERRY_PATH\perl\bin\libgcc_s_sjlj-1.dll;libgcc_s_sjlj-1.dll -a $STRAWBERRY_PATH\perl\bin\libstdc++-6.dll;libstdc++-6.dll -a $STRAWBERRY_PATH\perl\bin\libwinpthread-1.dll;libwinpthread-1.dll -a $STRAWBERRY_PATH\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxbase30u_gcc_custom.dll -a $STRAWBERRY_PATH\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxmsw30u_adv_gcc_custom.dll -a $STRAWBERRY_PATH\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxmsw30u_core_gcc_custom.dll -a $STRAWBERRY_PATH\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxmsw30u_gl_gcc_custom.dll -a $STRAWBERRY_PATH\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxmsw30u_html_gcc_custom.dll -a ..\utils;script\utils -a var;script\var -a autorun.bat;slic3r.bat -M Encode::Locale -M Moo -M Thread::Semaphore -M OpenGL -M Slic3r::XS -M Unicode::Normalize -M Wx -M Class::Accessor -M Wx::DND -M Wx::Grid -M Wx::Print -M Wx::Html -M Wx::GLCanvas -M Math::Trig -M threads -M threads::shared -M Thread::Queue -e -p -x slic3r.pl -o ..\slic3r.par + +cp ..\slic3r.par ..\slic3r-$(git rev-parse --abbrev-ref HEAD)-$(git rev-parse --short HEAD).zip From 7f2e774584a59b331543265971fdd1bb796de929 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sun, 3 Jul 2016 10:15:46 +0200 Subject: [PATCH 12/58] Removed dependency on TClap --- src/CMakeLists.txt | 10 +- src/slic3r.cpp | 119 +++-- src/tclap/Arg.h | 692 --------------------------- src/tclap/ArgException.h | 200 -------- src/tclap/ArgTraits.h | 87 ---- src/tclap/CmdLine.h | 633 ------------------------ src/tclap/CmdLineInterface.h | 150 ------ src/tclap/CmdLineOutput.h | 74 --- src/tclap/Constraint.h | 68 --- src/tclap/DocBookOutput.h | 299 ------------ src/tclap/HelpVisitor.h | 76 --- src/tclap/IgnoreRestVisitor.h | 52 -- src/tclap/Makefile.am | 28 -- src/tclap/Makefile.in | 403 ---------------- src/tclap/MultiArg.h | 433 ----------------- src/tclap/MultiSwitchArg.h | 216 --------- src/tclap/OptionalUnlabeledTracker.h | 62 --- src/tclap/StandardTraits.h | 208 -------- src/tclap/StdOutput.h | 298 ------------ src/tclap/SwitchArg.h | 266 ---------- src/tclap/UnlabeledMultiArg.h | 301 ------------ src/tclap/UnlabeledValueArg.h | 340 ------------- src/tclap/ValueArg.h | 425 ---------------- src/tclap/ValuesConstraint.h | 148 ------ src/tclap/VersionVisitor.h | 81 ---- src/tclap/Visitor.h | 53 -- src/tclap/XorHandler.h | 166 ------- src/tclap/ZshCompletionOutput.h | 323 ------------- xs/src/libslic3r/Config.cpp | 82 +++- xs/src/libslic3r/Config.hpp | 38 +- xs/src/libslic3r/Model.cpp | 37 +- xs/src/libslic3r/Model.hpp | 5 + xs/src/libslic3r/PrintConfig.cpp | 39 ++ xs/src/libslic3r/PrintConfig.hpp | 53 ++ xs/src/libslic3r/SVGExport.cpp | 71 ++- xs/src/libslic3r/SVGExport.hpp | 11 +- xs/src/libslic3r/TriangleMesh.cpp | 17 +- xs/src/libslic3r/TriangleMesh.hpp | 2 +- 38 files changed, 364 insertions(+), 6202 deletions(-) delete mode 100644 src/tclap/Arg.h delete mode 100644 src/tclap/ArgException.h delete mode 100644 src/tclap/ArgTraits.h delete mode 100644 src/tclap/CmdLine.h delete mode 100644 src/tclap/CmdLineInterface.h delete mode 100644 src/tclap/CmdLineOutput.h delete mode 100644 src/tclap/Constraint.h delete mode 100644 src/tclap/DocBookOutput.h delete mode 100644 src/tclap/HelpVisitor.h delete mode 100644 src/tclap/IgnoreRestVisitor.h delete mode 100644 src/tclap/Makefile.am delete mode 100644 src/tclap/Makefile.in delete mode 100644 src/tclap/MultiArg.h delete mode 100644 src/tclap/MultiSwitchArg.h delete mode 100644 src/tclap/OptionalUnlabeledTracker.h delete mode 100644 src/tclap/StandardTraits.h delete mode 100644 src/tclap/StdOutput.h delete mode 100644 src/tclap/SwitchArg.h delete mode 100644 src/tclap/UnlabeledMultiArg.h delete mode 100644 src/tclap/UnlabeledValueArg.h delete mode 100644 src/tclap/ValueArg.h delete mode 100644 src/tclap/ValuesConstraint.h delete mode 100644 src/tclap/VersionVisitor.h delete mode 100644 src/tclap/Visitor.h delete mode 100644 src/tclap/XorHandler.h delete mode 100644 src/tclap/ZshCompletionOutput.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2c117bdcac..09093bff46 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,10 +1,14 @@ cmake_minimum_required (VERSION 2.8) project (slic3r) + +# only on newer GCCs: -ftemplate-backtrace-limit=0 +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DSLIC3R_DEBUG") + set(workaround "") if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.7.0) -if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.7.3) -set(workaround "-fno-inline-small-functions") -endif(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.7.3) + if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.7.3) + set(workaround "-fno-inline-small-functions") + endif(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.7.3) endif(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.7.0) set(CMAKE_CXX_FLAGS "-DM_PI=3.14159265358979323846 -D_GLIBCXX_USE_C99 -DHAS_BOOL -DNOGDI -DBOOST_ASIO_DISABLE_KQUEUE ${workaround}") diff --git a/src/slic3r.cpp b/src/slic3r.cpp index a7e640f2a4..0cb674d82c 100644 --- a/src/slic3r.cpp +++ b/src/slic3r.cpp @@ -1,3 +1,4 @@ +#include "Config.hpp" #include "Model.hpp" #include "IO.hpp" #include "TriangleMesh.hpp" @@ -7,71 +8,83 @@ #include #include #include -#include "tclap/CmdLine.h" using namespace Slic3r; void confess_at(const char *file, int line, const char *func, const char *pat, ...){} -void exportSVG(const Model &model, const std::string &outfile, float layerheight=0.2, float initialheight=0., float scale=1.0, float rotate=0.){ - TriangleMesh mesh = model.mesh(); - mesh.scale(scale); - mesh.rotate_z(rotate); - mesh.mirror_x(); - mesh.align_to_origin(); - SVGExport e(mesh, layerheight, initialheight); - e.writeSVG(outfile); - printf("writing: %s\n", outfile.c_str()); -} - -int main (int argc, char **argv){ +int +main(const int argc, const char **argv) +{ + // parse all command line options into a DynamicConfig + ConfigDef config_def; + config_def.merge(cli_config_def); + config_def.merge(print_config_def); + DynamicConfig config(&config_def); + t_config_option_keys input_files; + config.read_cli(argc, argv, &input_files); - try { - TCLAP::CmdLine cmd("Rudimentary commandline slic3r, currently only supports STL to SVG slice export.", ' ', SLIC3R_VERSION); - TCLAP::ValueArg outputArg("o","output","File to output results to",false,"","output file name"); - cmd.add( outputArg ); - TCLAP::ValueArg scaleArg("","scale","Factor for scaling input object (default: 1)",false,1.0,"float"); - cmd.add( scaleArg ); - TCLAP::ValueArg rotArg("","rotate","Rotation angle in degrees (0-360, default: 0)",false,0.0,"float"); - cmd.add( rotArg ); - TCLAP::ValueArg flhArg("","first-layer-height","Layer height for first layer in mm (default: 0)",false,0.0,"float"); - cmd.add( flhArg ); - TCLAP::ValueArg lhArg("","layer-height","Layer height in mm (default: 0.2)",false,0.2,"float"); - cmd.add( lhArg ); - TCLAP::SwitchArg expsvg("","export-svg","Export a SVG file containing slices", cmd, false); - TCLAP::SwitchArg expobj("","export-obj","Export the input file as OBJ", cmd, false); - - TCLAP::UnlabeledValueArg input("inputfile","Input STL file name", true, "", "input file name"); - cmd.add(input); - cmd.parse(argc,argv); - - // read input file if any (TODO: read multiple) + // apply command line options to a more specific DynamicPrintConfig which provides normalize() + DynamicPrintConfig print_config; + print_config.apply(config, true); + print_config.normalize(); + + // apply command line options to a more handy CLIConfig + CLIConfig cli_config; + cli_config.apply(config, true); + + /* TODO: loop through the config files supplied on the command line (now stored in + cli_config), load each one, normalize it and apply it to print_config */ + + // read input file(s) if any + std::vector models; + for (t_config_option_keys::const_iterator it = input_files.begin(); it != input_files.end(); ++it) { Model model; - if (!input.getValue().empty()) { - Slic3r::IO::STL::read(input.getValue(), &model); - model.add_default_instances(); + // TODO: read other file formats with Model::read_from_file() + Slic3r::IO::STL::read(*it, &model); + + if (model.objects.empty()) { + printf("Error: file is empty: %s\n", it->c_str()); + continue; } - if (expobj.getValue()) { - std::string outfile = outputArg.getValue(); - if (outfile.empty()) outfile = input.getValue() + ".obj"; - - TriangleMesh mesh = model.mesh(); - printf("mesh has %zu facets\n", mesh.facets_count()); + model.add_default_instances(); + + // apply command line transform options + for (ModelObjectPtrs::iterator o = model.objects.begin(); o != model.objects.end(); ++o) { + (*o)->scale(cli_config.scale.value); + (*o)->rotate(cli_config.rotate.value, Z); + } + + // TODO: handle --merge + models.push_back(model); + } + + if (cli_config.export_obj) { + for (std::vector::iterator model = models.begin(); model != models.end(); ++model) { + std::string outfile = cli_config.output.value; + if (outfile.empty()) outfile = model->objects.front()->input_file + ".obj"; + + TriangleMesh mesh = model->mesh(); Slic3r::IO::OBJ::write(mesh, outfile); printf("File exported to %s\n", outfile.c_str()); - } else if (expsvg.getValue()) { - std::string outfile = outputArg.getValue(); - if (outfile.empty()) outfile = input.getValue() + ".svg"; - - exportSVG(model, outfile, lhArg.getValue(), flhArg.getValue(), scaleArg.getValue(), rotArg.getValue()); - } else { - std::cerr << "error: only --export-svg and --export-obj are currently supported"<< std::endl; - return 1; } - - } catch (TCLAP::ArgException &e) { - std::cerr << "error: " << e.error() << " for arg " << e.argId() << std::endl; + } else if (cli_config.export_svg) { + for (std::vector::iterator model = models.begin(); model != models.end(); ++model) { + std::string outfile = cli_config.output.value; + if (outfile.empty()) outfile = model->objects.front()->input_file + ".svg"; + + TriangleMesh mesh = model->mesh(); + mesh.mirror_x(); + mesh.align_to_origin(); + + SVGExport svg_export(mesh); + svg_export.config.apply(print_config, true); + svg_export.writeSVG(outfile); + printf("SVG file exported to %s\n", outfile.c_str()); + } + } else { + std::cerr << "error: only --export-svg and --export-obj are currently supported" << std::endl; return 1; } diff --git a/src/tclap/Arg.h b/src/tclap/Arg.h deleted file mode 100644 index b28eef117c..0000000000 --- a/src/tclap/Arg.h +++ /dev/null @@ -1,692 +0,0 @@ -// -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*- - -/****************************************************************************** - * - * file: Arg.h - * - * Copyright (c) 2003, Michael E. Smoot . - * Copyright (c) 2004, Michael E. Smoot, Daniel Aarno . - * All rights reverved. - * - * See the file COPYING in the top directory of this distribution for - * more information. - * - * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - *****************************************************************************/ - - -#ifndef TCLAP_ARGUMENT_H -#define TCLAP_ARGUMENT_H - -#ifdef HAVE_CONFIG_H -#include -#else -#define HAVE_SSTREAM -#endif - -#include -#include -#include -#include -#include -#include - -#if defined(HAVE_SSTREAM) -#include -typedef std::istringstream istringstream; -#elif defined(HAVE_STRSTREAM) -#include -typedef std::istrstream istringstream; -#else -#error "Need a stringstream (sstream or strstream) to compile!" -#endif - -#include -#include -#include -#include -#include - -namespace TCLAP { - -/** - * A virtual base class that defines the essential data for all arguments. - * This class, or one of its existing children, must be subclassed to do - * anything. - */ -class Arg -{ - private: - /** - * Prevent accidental copying. - */ - Arg(const Arg& rhs); - - /** - * Prevent accidental copying. - */ - Arg& operator=(const Arg& rhs); - - /** - * Indicates whether the rest of the arguments should be ignored. - */ - static bool& ignoreRestRef() { static bool ign = false; return ign; } - - /** - * The delimiter that separates an argument flag/name from the - * value. - */ - static char& delimiterRef() { static char delim = ' '; return delim; } - - protected: - - /** - * The single char flag used to identify the argument. - * This value (preceded by a dash {-}), can be used to identify - * an argument on the command line. The _flag can be blank, - * in fact this is how unlabeled args work. Unlabeled args must - * override appropriate functions to get correct handling. Note - * that the _flag does NOT include the dash as part of the flag. - */ - std::string _flag; - - /** - * A single work namd indentifying the argument. - * This value (preceded by two dashed {--}) can also be used - * to identify an argument on the command line. Note that the - * _name does NOT include the two dashes as part of the _name. The - * _name cannot be blank. - */ - std::string _name; - - /** - * Description of the argument. - */ - std::string _description; - - /** - * Indicating whether the argument is required. - */ - bool _required; - - /** - * Label to be used in usage description. Normally set to - * "required", but can be changed when necessary. - */ - std::string _requireLabel; - - /** - * Indicates whether a value is required for the argument. - * Note that the value may be required but the argument/value - * combination may not be, as specified by _required. - */ - bool _valueRequired; - - /** - * Indicates whether the argument has been set. - * Indicates that a value on the command line has matched the - * name/flag of this argument and the values have been set accordingly. - */ - bool _alreadySet; - - /** - * A pointer to a vistitor object. - * The visitor allows special handling to occur as soon as the - * argument is matched. This defaults to NULL and should not - * be used unless absolutely necessary. - */ - Visitor* _visitor; - - /** - * Whether this argument can be ignored, if desired. - */ - bool _ignoreable; - - /** - * Indicates that the arg was set as part of an XOR and not on the - * command line. - */ - bool _xorSet; - - bool _acceptsMultipleValues; - - /** - * Performs the special handling described by the Vistitor. - */ - void _checkWithVisitor() const; - - /** - * Primary constructor. YOU (yes you) should NEVER construct an Arg - * directly, this is a base class that is extended by various children - * that are meant to be used. Use SwitchArg, ValueArg, MultiArg, - * UnlabeledValueArg, or UnlabeledMultiArg instead. - * - * \param flag - The flag identifying the argument. - * \param name - The name identifying the argument. - * \param desc - The description of the argument, used in the usage. - * \param req - Whether the argument is required. - * \param valreq - Whether the a value is required for the argument. - * \param v - The visitor checked by the argument. Defaults to NULL. - */ - Arg( const std::string& flag, - const std::string& name, - const std::string& desc, - bool req, - bool valreq, - Visitor* v = NULL ); - - public: - /** - * Destructor. - */ - virtual ~Arg(); - - /** - * Adds this to the specified list of Args. - * \param argList - The list to add this to. - */ - virtual void addToList( std::list& argList ) const; - - /** - * Begin ignoring arguments since the "--" argument was specified. - */ - static void beginIgnoring() { ignoreRestRef() = true; } - - /** - * Whether to ignore the rest. - */ - static bool ignoreRest() { return ignoreRestRef(); } - - /** - * The delimiter that separates an argument flag/name from the - * value. - */ - static char delimiter() { return delimiterRef(); } - - /** - * The char used as a place holder when SwitchArgs are combined. - * Currently set to the bell char (ASCII 7). - */ - static char blankChar() { return (char)7; } - - /** - * The char that indicates the beginning of a flag. Defaults to '-', but - * clients can define TCLAP_FLAGSTARTCHAR to override. - */ -#ifndef TCLAP_FLAGSTARTCHAR -#define TCLAP_FLAGSTARTCHAR '-' -#endif - static char flagStartChar() { return TCLAP_FLAGSTARTCHAR; } - - /** - * The sting that indicates the beginning of a flag. Defaults to "-", but - * clients can define TCLAP_FLAGSTARTSTRING to override. Should be the same - * as TCLAP_FLAGSTARTCHAR. - */ -#ifndef TCLAP_FLAGSTARTSTRING -#define TCLAP_FLAGSTARTSTRING "-" -#endif - static const std::string flagStartString() { return TCLAP_FLAGSTARTSTRING; } - - /** - * The sting that indicates the beginning of a name. Defaults to "--", but - * clients can define TCLAP_NAMESTARTSTRING to override. - */ -#ifndef TCLAP_NAMESTARTSTRING -#define TCLAP_NAMESTARTSTRING "--" -#endif - static const std::string nameStartString() { return TCLAP_NAMESTARTSTRING; } - - /** - * The name used to identify the ignore rest argument. - */ - static const std::string ignoreNameString() { return "ignore_rest"; } - - /** - * Sets the delimiter for all arguments. - * \param c - The character that delimits flags/names from values. - */ - static void setDelimiter( char c ) { delimiterRef() = c; } - - /** - * Pure virtual method meant to handle the parsing and value assignment - * of the string on the command line. - * \param i - Pointer the the current argument in the list. - * \param args - Mutable list of strings. What is - * passed in from main. - */ - virtual bool processArg(int *i, std::vector& args) = 0; - - /** - * Operator ==. - * Equality operator. Must be virtual to handle unlabeled args. - * \param a - The Arg to be compared to this. - */ - virtual bool operator==(const Arg& a) const; - - /** - * Returns the argument flag. - */ - const std::string& getFlag() const; - - /** - * Returns the argument name. - */ - const std::string& getName() const; - - /** - * Returns the argument description. - */ - std::string getDescription() const; - - /** - * Indicates whether the argument is required. - */ - virtual bool isRequired() const; - - /** - * Sets _required to true. This is used by the XorHandler. - * You really have no reason to ever use it. - */ - void forceRequired(); - - /** - * Sets the _alreadySet value to true. This is used by the XorHandler. - * You really have no reason to ever use it. - */ - void xorSet(); - - /** - * Indicates whether a value must be specified for argument. - */ - bool isValueRequired() const; - - /** - * Indicates whether the argument has already been set. Only true - * if the arg has been matched on the command line. - */ - bool isSet() const; - - /** - * Indicates whether the argument can be ignored, if desired. - */ - bool isIgnoreable() const; - - /** - * A method that tests whether a string matches this argument. - * This is generally called by the processArg() method. This - * method could be re-implemented by a child to change how - * arguments are specified on the command line. - * \param s - The string to be compared to the flag/name to determine - * whether the arg matches. - */ - virtual bool argMatches( const std::string& s ) const; - - /** - * Returns a simple string representation of the argument. - * Primarily for debugging. - */ - virtual std::string toString() const; - - /** - * Returns a short ID for the usage. - * \param valueId - The value used in the id. - */ - virtual std::string shortID( const std::string& valueId = "val" ) const; - - /** - * Returns a long ID for the usage. - * \param valueId - The value used in the id. - */ - virtual std::string longID( const std::string& valueId = "val" ) const; - - /** - * Trims a value off of the flag. - * \param flag - The string from which the flag and value will be - * trimmed. Contains the flag once the value has been trimmed. - * \param value - Where the value trimmed from the string will - * be stored. - */ - virtual void trimFlag( std::string& flag, std::string& value ) const; - - /** - * Checks whether a given string has blank chars, indicating that - * it is a combined SwitchArg. If so, return true, otherwise return - * false. - * \param s - string to be checked. - */ - bool _hasBlanks( const std::string& s ) const; - - /** - * Sets the requireLabel. Used by XorHandler. You shouldn't ever - * use this. - * \param s - Set the requireLabel to this value. - */ - void setRequireLabel( const std::string& s ); - - /** - * Used for MultiArgs and XorHandler to determine whether args - * can still be set. - */ - virtual bool allowMore(); - - /** - * Use by output classes to determine whether an Arg accepts - * multiple values. - */ - virtual bool acceptsMultipleValues(); - - /** - * Clears the Arg object and allows it to be reused by new - * command lines. - */ - virtual void reset(); -}; - -/** - * Typedef of an Arg list iterator. - */ -typedef std::list::iterator ArgListIterator; - -/** - * Typedef of an Arg vector iterator. - */ -typedef std::vector::iterator ArgVectorIterator; - -/** - * Typedef of a Visitor list iterator. - */ -typedef std::list::iterator VisitorListIterator; - -/* - * Extract a value of type T from it's string representation contained - * in strVal. The ValueLike parameter used to select the correct - * specialization of ExtractValue depending on the value traits of T. - * ValueLike traits use operator>> to assign the value from strVal. - */ -template void -ExtractValue(T &destVal, const std::string& strVal, ValueLike vl) -{ - static_cast(vl); // Avoid warning about unused vl - std::istringstream is(strVal); - - int valuesRead = 0; - while ( is.good() ) { - if ( is.peek() != EOF ) -#ifdef TCLAP_SETBASE_ZERO - is >> std::setbase(0) >> destVal; -#else - is >> destVal; -#endif - else - break; - - valuesRead++; - } - - if ( is.fail() ) - throw( ArgParseException("Couldn't read argument value " - "from string '" + strVal + "'")); - - - if ( valuesRead > 1 ) - throw( ArgParseException("More than one valid value parsed from " - "string '" + strVal + "'")); - -} - -/* - * Extract a value of type T from it's string representation contained - * in strVal. The ValueLike parameter used to select the correct - * specialization of ExtractValue depending on the value traits of T. - * StringLike uses assignment (operator=) to assign from strVal. - */ -template void -ExtractValue(T &destVal, const std::string& strVal, StringLike sl) -{ - static_cast(sl); // Avoid warning about unused sl - SetString(destVal, strVal); -} - -////////////////////////////////////////////////////////////////////// -//BEGIN Arg.cpp -////////////////////////////////////////////////////////////////////// - -inline Arg::Arg(const std::string& flag, - const std::string& name, - const std::string& desc, - bool req, - bool valreq, - Visitor* v) : - _flag(flag), - _name(name), - _description(desc), - _required(req), - _requireLabel("required"), - _valueRequired(valreq), - _alreadySet(false), - _visitor( v ), - _ignoreable(true), - _xorSet(false), - _acceptsMultipleValues(false) -{ - if ( _flag.length() > 1 ) - throw(SpecificationException( - "Argument flag can only be one character long", toString() ) ); - - if ( _name != ignoreNameString() && - ( _flag == Arg::flagStartString() || - _flag == Arg::nameStartString() || - _flag == " " ) ) - throw(SpecificationException("Argument flag cannot be either '" + - Arg::flagStartString() + "' or '" + - Arg::nameStartString() + "' or a space.", - toString() ) ); - - if ( ( _name.substr( 0, Arg::flagStartString().length() ) == Arg::flagStartString() ) || - ( _name.substr( 0, Arg::nameStartString().length() ) == Arg::nameStartString() ) || - ( _name.find( " ", 0 ) != std::string::npos ) ) - throw(SpecificationException("Argument name begin with either '" + - Arg::flagStartString() + "' or '" + - Arg::nameStartString() + "' or space.", - toString() ) ); - -} - -inline Arg::~Arg() { } - -inline std::string Arg::shortID( const std::string& valueId ) const -{ - std::string id = ""; - - if ( _flag != "" ) - id = Arg::flagStartString() + _flag; - else - id = Arg::nameStartString() + _name; - - if ( _valueRequired ) - id += std::string( 1, Arg::delimiter() ) + "<" + valueId + ">"; - - if ( !_required ) - id = "[" + id + "]"; - - return id; -} - -inline std::string Arg::longID( const std::string& valueId ) const -{ - std::string id = ""; - - if ( _flag != "" ) - { - id += Arg::flagStartString() + _flag; - - if ( _valueRequired ) - id += std::string( 1, Arg::delimiter() ) + "<" + valueId + ">"; - - id += ", "; - } - - id += Arg::nameStartString() + _name; - - if ( _valueRequired ) - id += std::string( 1, Arg::delimiter() ) + "<" + valueId + ">"; - - return id; - -} - -inline bool Arg::operator==(const Arg& a) const -{ - if ( ( _flag != "" && _flag == a._flag ) || _name == a._name) - return true; - else - return false; -} - -inline std::string Arg::getDescription() const -{ - std::string desc = ""; - if ( _required ) - desc = "(" + _requireLabel + ") "; - -// if ( _valueRequired ) -// desc += "(value required) "; - - desc += _description; - return desc; -} - -inline const std::string& Arg::getFlag() const { return _flag; } - -inline const std::string& Arg::getName() const { return _name; } - -inline bool Arg::isRequired() const { return _required; } - -inline bool Arg::isValueRequired() const { return _valueRequired; } - -inline bool Arg::isSet() const -{ - if ( _alreadySet && !_xorSet ) - return true; - else - return false; -} - -inline bool Arg::isIgnoreable() const { return _ignoreable; } - -inline void Arg::setRequireLabel( const std::string& s) -{ - _requireLabel = s; -} - -inline bool Arg::argMatches( const std::string& argFlag ) const -{ - if ( ( argFlag == Arg::flagStartString() + _flag && _flag != "" ) || - argFlag == Arg::nameStartString() + _name ) - return true; - else - return false; -} - -inline std::string Arg::toString() const -{ - std::string s = ""; - - if ( _flag != "" ) - s += Arg::flagStartString() + _flag + " "; - - s += "(" + Arg::nameStartString() + _name + ")"; - - return s; -} - -inline void Arg::_checkWithVisitor() const -{ - if ( _visitor != NULL ) - _visitor->visit(); -} - -/** - * Implementation of trimFlag. - */ -inline void Arg::trimFlag(std::string& flag, std::string& value) const -{ - int stop = 0; - for ( int i = 0; static_cast(i) < flag.length(); i++ ) - if ( flag[i] == Arg::delimiter() ) - { - stop = i; - break; - } - - if ( stop > 1 ) - { - value = flag.substr(stop+1); - flag = flag.substr(0,stop); - } - -} - -/** - * Implementation of _hasBlanks. - */ -inline bool Arg::_hasBlanks( const std::string& s ) const -{ - for ( int i = 1; static_cast(i) < s.length(); i++ ) - if ( s[i] == Arg::blankChar() ) - return true; - - return false; -} - -inline void Arg::forceRequired() -{ - _required = true; -} - -inline void Arg::xorSet() -{ - _alreadySet = true; - _xorSet = true; -} - -/** - * Overridden by Args that need to added to the end of the list. - */ -inline void Arg::addToList( std::list& argList ) const -{ - argList.push_front( const_cast(this) ); -} - -inline bool Arg::allowMore() -{ - return false; -} - -inline bool Arg::acceptsMultipleValues() -{ - return _acceptsMultipleValues; -} - -inline void Arg::reset() -{ - _xorSet = false; - _alreadySet = false; -} - -////////////////////////////////////////////////////////////////////// -//END Arg.cpp -////////////////////////////////////////////////////////////////////// - -} //namespace TCLAP - -#endif - diff --git a/src/tclap/ArgException.h b/src/tclap/ArgException.h deleted file mode 100644 index 3411aa9543..0000000000 --- a/src/tclap/ArgException.h +++ /dev/null @@ -1,200 +0,0 @@ -// -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*- - -/****************************************************************************** - * - * file: ArgException.h - * - * Copyright (c) 2003, Michael E. Smoot . - * All rights reverved. - * - * See the file COPYING in the top directory of this distribution for - * more information. - * - * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - *****************************************************************************/ - - -#ifndef TCLAP_ARG_EXCEPTION_H -#define TCLAP_ARG_EXCEPTION_H - -#include -#include - -namespace TCLAP { - -/** - * A simple class that defines and argument exception. Should be caught - * whenever a CmdLine is created and parsed. - */ -class ArgException : public std::exception -{ - public: - - /** - * Constructor. - * \param text - The text of the exception. - * \param id - The text identifying the argument source. - * \param td - Text describing the type of ArgException it is. - * of the exception. - */ - ArgException( const std::string& text = "undefined exception", - const std::string& id = "undefined", - const std::string& td = "Generic ArgException") - : std::exception(), - _errorText(text), - _argId( id ), - _typeDescription(td) - { } - - /** - * Destructor. - */ - virtual ~ArgException() throw() { } - - /** - * Returns the error text. - */ - std::string error() const { return ( _errorText ); } - - /** - * Returns the argument id. - */ - std::string argId() const - { - if ( _argId == "undefined" ) - return " "; - else - return ( "Argument: " + _argId ); - } - - /** - * Returns the arg id and error text. - */ - const char* what() const throw() - { - static std::string ex; - ex = _argId + " -- " + _errorText; - return ex.c_str(); - } - - /** - * Returns the type of the exception. Used to explain and distinguish - * between different child exceptions. - */ - std::string typeDescription() const - { - return _typeDescription; - } - - - private: - - /** - * The text of the exception message. - */ - std::string _errorText; - - /** - * The argument related to this exception. - */ - std::string _argId; - - /** - * Describes the type of the exception. Used to distinguish - * between different child exceptions. - */ - std::string _typeDescription; - -}; - -/** - * Thrown from within the child Arg classes when it fails to properly - * parse the argument it has been passed. - */ -class ArgParseException : public ArgException -{ - public: - /** - * Constructor. - * \param text - The text of the exception. - * \param id - The text identifying the argument source - * of the exception. - */ - ArgParseException( const std::string& text = "undefined exception", - const std::string& id = "undefined" ) - : ArgException( text, - id, - std::string( "Exception found while parsing " ) + - std::string( "the value the Arg has been passed." )) - { } -}; - -/** - * Thrown from CmdLine when the arguments on the command line are not - * properly specified, e.g. too many arguments, required argument missing, etc. - */ -class CmdLineParseException : public ArgException -{ - public: - /** - * Constructor. - * \param text - The text of the exception. - * \param id - The text identifying the argument source - * of the exception. - */ - CmdLineParseException( const std::string& text = "undefined exception", - const std::string& id = "undefined" ) - : ArgException( text, - id, - std::string( "Exception found when the values ") + - std::string( "on the command line do not meet ") + - std::string( "the requirements of the defined ") + - std::string( "Args." )) - { } -}; - -/** - * Thrown from Arg and CmdLine when an Arg is improperly specified, e.g. - * same flag as another Arg, same name, etc. - */ -class SpecificationException : public ArgException -{ - public: - /** - * Constructor. - * \param text - The text of the exception. - * \param id - The text identifying the argument source - * of the exception. - */ - SpecificationException( const std::string& text = "undefined exception", - const std::string& id = "undefined" ) - : ArgException( text, - id, - std::string("Exception found when an Arg object ")+ - std::string("is improperly defined by the ") + - std::string("developer." )) - { } - -}; - -class ExitException { -public: - ExitException(int estat) : _estat(estat) {} - - int getExitStatus() const { return _estat; } - -private: - int _estat; -}; - -} // namespace TCLAP - -#endif - diff --git a/src/tclap/ArgTraits.h b/src/tclap/ArgTraits.h deleted file mode 100644 index 0b2c18f70c..0000000000 --- a/src/tclap/ArgTraits.h +++ /dev/null @@ -1,87 +0,0 @@ -// -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*- - -/****************************************************************************** - * - * file: ArgTraits.h - * - * Copyright (c) 2007, Daniel Aarno, Michael E. Smoot . - * All rights reverved. - * - * See the file COPYING in the top directory of this distribution for - * more information. - * - * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - *****************************************************************************/ - -// This is an internal tclap file, you should probably not have to -// include this directly - -#ifndef TCLAP_ARGTRAITS_H -#define TCLAP_ARGTRAITS_H - -namespace TCLAP { - -// We use two empty structs to get compile type specialization -// function to work - -/** - * A value like argument value type is a value that can be set using - * operator>>. This is the default value type. - */ -struct ValueLike { - typedef ValueLike ValueCategory; - virtual ~ValueLike() {} -}; - -/** - * A string like argument value type is a value that can be set using - * operator=(string). Usefull if the value type contains spaces which - * will be broken up into individual tokens by operator>>. - */ -struct StringLike { - virtual ~StringLike() {} -}; - -/** - * A class can inherit from this object to make it have string like - * traits. This is a compile time thing and does not add any overhead - * to the inherenting class. - */ -struct StringLikeTrait { - typedef StringLike ValueCategory; - virtual ~StringLikeTrait() {} -}; - -/** - * A class can inherit from this object to make it have value like - * traits. This is a compile time thing and does not add any overhead - * to the inherenting class. - */ -struct ValueLikeTrait { - typedef ValueLike ValueCategory; - virtual ~ValueLikeTrait() {} -}; - -/** - * Arg traits are used to get compile type specialization when parsing - * argument values. Using an ArgTraits you can specify the way that - * values gets assigned to any particular type during parsing. The two - * supported types are StringLike and ValueLike. - */ -template -struct ArgTraits { - typedef typename T::ValueCategory ValueCategory; - virtual ~ArgTraits() {} - //typedef ValueLike ValueCategory; -}; - -#endif - -} // namespace diff --git a/src/tclap/CmdLine.h b/src/tclap/CmdLine.h deleted file mode 100644 index 0fec8d8a11..0000000000 --- a/src/tclap/CmdLine.h +++ /dev/null @@ -1,633 +0,0 @@ -// -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*- - -/****************************************************************************** - * - * file: CmdLine.h - * - * Copyright (c) 2003, Michael E. Smoot . - * Copyright (c) 2004, Michael E. Smoot, Daniel Aarno. - * All rights reverved. - * - * See the file COPYING in the top directory of this distribution for - * more information. - * - * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - *****************************************************************************/ - -#ifndef TCLAP_CMDLINE_H -#define TCLAP_CMDLINE_H - -#include -#include -#include -#include - -#include -#include -#include -#include - -#include -#include - -#include -#include - -#include -#include -#include -#include -#include -#include -#include // Needed for exit(), which isn't defined in some envs. - -namespace TCLAP { - -template void DelPtr(T ptr) -{ - delete ptr; -} - -template void ClearContainer(C &c) -{ - typedef typename C::value_type value_type; - std::for_each(c.begin(), c.end(), DelPtr); - c.clear(); -} - - -/** - * The base class that manages the command line definition and passes - * along the parsing to the appropriate Arg classes. - */ -class CmdLine : public CmdLineInterface -{ - protected: - - /** - * The list of arguments that will be tested against the - * command line. - */ - std::list _argList; - - /** - * The name of the program. Set to argv[0]. - */ - std::string _progName; - - /** - * A message used to describe the program. Used in the usage output. - */ - std::string _message; - - /** - * The version to be displayed with the --version switch. - */ - std::string _version; - - /** - * The number of arguments that are required to be present on - * the command line. This is set dynamically, based on the - * Args added to the CmdLine object. - */ - int _numRequired; - - /** - * The character that is used to separate the argument flag/name - * from the value. Defaults to ' ' (space). - */ - char _delimiter; - - /** - * The handler that manages xoring lists of args. - */ - XorHandler _xorHandler; - - /** - * A list of Args to be explicitly deleted when the destructor - * is called. At the moment, this only includes the three default - * Args. - */ - std::list _argDeleteOnExitList; - - /** - * A list of Visitors to be explicitly deleted when the destructor - * is called. At the moment, these are the Vistors created for the - * default Args. - */ - std::list _visitorDeleteOnExitList; - - /** - * Object that handles all output for the CmdLine. - */ - CmdLineOutput* _output; - - /** - * Should CmdLine handle parsing exceptions internally? - */ - bool _handleExceptions; - - /** - * Throws an exception listing the missing args. - */ - void missingArgsException(); - - /** - * Checks whether a name/flag string matches entirely matches - * the Arg::blankChar. Used when multiple switches are combined - * into a single argument. - * \param s - The message to be used in the usage. - */ - bool _emptyCombined(const std::string& s); - - /** - * Perform a delete ptr; operation on ptr when this object is deleted. - */ - void deleteOnExit(Arg* ptr); - - /** - * Perform a delete ptr; operation on ptr when this object is deleted. - */ - void deleteOnExit(Visitor* ptr); - -private: - - /** - * Prevent accidental copying. - */ - CmdLine(const CmdLine& rhs); - CmdLine& operator=(const CmdLine& rhs); - - /** - * Encapsulates the code common to the constructors - * (which is all of it). - */ - void _constructor(); - - - /** - * Is set to true when a user sets the output object. We use this so - * that we don't delete objects that are created outside of this lib. - */ - bool _userSetOutput; - - /** - * Whether or not to automatically create help and version switches. - */ - bool _helpAndVersion; - - public: - - /** - * Command line constructor. Defines how the arguments will be - * parsed. - * \param message - The message to be used in the usage - * output. - * \param delimiter - The character that is used to separate - * the argument flag/name from the value. Defaults to ' ' (space). - * \param version - The version number to be used in the - * --version switch. - * \param helpAndVersion - Whether or not to create the Help and - * Version switches. Defaults to true. - */ - CmdLine(const std::string& message, - const char delimiter = ' ', - const std::string& version = "none", - bool helpAndVersion = true); - - /** - * Deletes any resources allocated by a CmdLine object. - */ - virtual ~CmdLine(); - - /** - * Adds an argument to the list of arguments to be parsed. - * \param a - Argument to be added. - */ - void add( Arg& a ); - - /** - * An alternative add. Functionally identical. - * \param a - Argument to be added. - */ - void add( Arg* a ); - - /** - * Add two Args that will be xor'd. If this method is used, add does - * not need to be called. - * \param a - Argument to be added and xor'd. - * \param b - Argument to be added and xor'd. - */ - void xorAdd( Arg& a, Arg& b ); - - /** - * Add a list of Args that will be xor'd. If this method is used, - * add does not need to be called. - * \param xors - List of Args to be added and xor'd. - */ - void xorAdd( std::vector& xors ); - - /** - * Parses the command line. - * \param argc - Number of arguments. - * \param argv - Array of arguments. - */ - void parse(int argc, const char * const * argv); - - /** - * Parses the command line. - * \param args - A vector of strings representing the args. - * args[0] is still the program name. - */ - void parse(std::vector& args); - - /** - * - */ - CmdLineOutput* getOutput(); - - /** - * - */ - void setOutput(CmdLineOutput* co); - - /** - * - */ - std::string& getVersion(); - - /** - * - */ - std::string& getProgramName(); - - /** - * - */ - std::list& getArgList(); - - /** - * - */ - XorHandler& getXorHandler(); - - /** - * - */ - char getDelimiter(); - - /** - * - */ - std::string& getMessage(); - - /** - * - */ - bool hasHelpAndVersion(); - - /** - * Disables or enables CmdLine's internal parsing exception handling. - * - * @param state Should CmdLine handle parsing exceptions internally? - */ - void setExceptionHandling(const bool state); - - /** - * Returns the current state of the internal exception handling. - * - * @retval true Parsing exceptions are handled internally. - * @retval false Parsing exceptions are propagated to the caller. - */ - bool getExceptionHandling() const; - - /** - * Allows the CmdLine object to be reused. - */ - void reset(); - -}; - - -/////////////////////////////////////////////////////////////////////////////// -//Begin CmdLine.cpp -/////////////////////////////////////////////////////////////////////////////// - -inline CmdLine::CmdLine(const std::string& m, - char delim, - const std::string& v, - bool help ) - : - _argList(std::list()), - _progName("not_set_yet"), - _message(m), - _version(v), - _numRequired(0), - _delimiter(delim), - _xorHandler(XorHandler()), - _argDeleteOnExitList(std::list()), - _visitorDeleteOnExitList(std::list()), - _output(0), - _handleExceptions(true), - _userSetOutput(false), - _helpAndVersion(help) -{ - _constructor(); -} - -inline CmdLine::~CmdLine() -{ - ClearContainer(_argDeleteOnExitList); - ClearContainer(_visitorDeleteOnExitList); - - if ( !_userSetOutput ) { - delete _output; - _output = 0; - } -} - -inline void CmdLine::_constructor() -{ - _output = new StdOutput; - - Arg::setDelimiter( _delimiter ); - - Visitor* v; - - if ( _helpAndVersion ) - { - v = new HelpVisitor( this, &_output ); - SwitchArg* help = new SwitchArg("h","help", - "Displays usage information and exits.", - false, v); - add( help ); - deleteOnExit(help); - deleteOnExit(v); - - v = new VersionVisitor( this, &_output ); - SwitchArg* vers = new SwitchArg("","version", - "Displays version information and exits.", - false, v); - add( vers ); - deleteOnExit(vers); - deleteOnExit(v); - } - - v = new IgnoreRestVisitor(); - SwitchArg* ignore = new SwitchArg(Arg::flagStartString(), - Arg::ignoreNameString(), - "Ignores the rest of the labeled arguments following this flag.", - false, v); - add( ignore ); - deleteOnExit(ignore); - deleteOnExit(v); -} - -inline void CmdLine::xorAdd( std::vector& ors ) -{ - _xorHandler.add( ors ); - - for (ArgVectorIterator it = ors.begin(); it != ors.end(); it++) - { - (*it)->forceRequired(); - (*it)->setRequireLabel( "OR required" ); - add( *it ); - } -} - -inline void CmdLine::xorAdd( Arg& a, Arg& b ) -{ - std::vector ors; - ors.push_back( &a ); - ors.push_back( &b ); - xorAdd( ors ); -} - -inline void CmdLine::add( Arg& a ) -{ - add( &a ); -} - -inline void CmdLine::add( Arg* a ) -{ - for( ArgListIterator it = _argList.begin(); it != _argList.end(); it++ ) - if ( *a == *(*it) ) - throw( SpecificationException( - "Argument with same flag/name already exists!", - a->longID() ) ); - - a->addToList( _argList ); - - if ( a->isRequired() ) - _numRequired++; -} - - -inline void CmdLine::parse(int argc, const char * const * argv) -{ - // this step is necessary so that we have easy access to - // mutable strings. - std::vector args; - for (int i = 0; i < argc; i++) - args.push_back(argv[i]); - - parse(args); -} - -inline void CmdLine::parse(std::vector& args) -{ - bool shouldExit = false; - int estat = 0; - - try { - _progName = args.front(); - args.erase(args.begin()); - - int requiredCount = 0; - - for (int i = 0; static_cast(i) < args.size(); i++) - { - bool matched = false; - for (ArgListIterator it = _argList.begin(); - it != _argList.end(); it++) { - if ( (*it)->processArg( &i, args ) ) - { - requiredCount += _xorHandler.check( *it ); - matched = true; - break; - } - } - - // checks to see if the argument is an empty combined - // switch and if so, then we've actually matched it - if ( !matched && _emptyCombined( args[i] ) ) - matched = true; - - if ( !matched && !Arg::ignoreRest() ) - throw(CmdLineParseException("Couldn't find match " - "for argument", - args[i])); - } - - if ( requiredCount < _numRequired ) - missingArgsException(); - - if ( requiredCount > _numRequired ) - throw(CmdLineParseException("Too many arguments!")); - - } catch ( ArgException& e ) { - // If we're not handling the exceptions, rethrow. - if ( !_handleExceptions) { - throw; - } - - try { - _output->failure(*this,e); - } catch ( ExitException &ee ) { - estat = ee.getExitStatus(); - shouldExit = true; - } - } catch (ExitException &ee) { - // If we're not handling the exceptions, rethrow. - if ( !_handleExceptions) { - throw; - } - - estat = ee.getExitStatus(); - shouldExit = true; - } - - if (shouldExit) - exit(estat); -} - -inline bool CmdLine::_emptyCombined(const std::string& s) -{ - if ( s.length() > 0 && s[0] != Arg::flagStartChar() ) - return false; - - for ( int i = 1; static_cast(i) < s.length(); i++ ) - if ( s[i] != Arg::blankChar() ) - return false; - - return true; -} - -inline void CmdLine::missingArgsException() -{ - int count = 0; - - std::string missingArgList; - for (ArgListIterator it = _argList.begin(); it != _argList.end(); it++) - { - if ( (*it)->isRequired() && !(*it)->isSet() ) - { - missingArgList += (*it)->getName(); - missingArgList += ", "; - count++; - } - } - missingArgList = missingArgList.substr(0,missingArgList.length()-2); - - std::string msg; - if ( count > 1 ) - msg = "Required arguments missing: "; - else - msg = "Required argument missing: "; - - msg += missingArgList; - - throw(CmdLineParseException(msg)); -} - -inline void CmdLine::deleteOnExit(Arg* ptr) -{ - _argDeleteOnExitList.push_back(ptr); -} - -inline void CmdLine::deleteOnExit(Visitor* ptr) -{ - _visitorDeleteOnExitList.push_back(ptr); -} - -inline CmdLineOutput* CmdLine::getOutput() -{ - return _output; -} - -inline void CmdLine::setOutput(CmdLineOutput* co) -{ - if ( !_userSetOutput ) - delete _output; - _userSetOutput = true; - _output = co; -} - -inline std::string& CmdLine::getVersion() -{ - return _version; -} - -inline std::string& CmdLine::getProgramName() -{ - return _progName; -} - -inline std::list& CmdLine::getArgList() -{ - return _argList; -} - -inline XorHandler& CmdLine::getXorHandler() -{ - return _xorHandler; -} - -inline char CmdLine::getDelimiter() -{ - return _delimiter; -} - -inline std::string& CmdLine::getMessage() -{ - return _message; -} - -inline bool CmdLine::hasHelpAndVersion() -{ - return _helpAndVersion; -} - -inline void CmdLine::setExceptionHandling(const bool state) -{ - _handleExceptions = state; -} - -inline bool CmdLine::getExceptionHandling() const -{ - return _handleExceptions; -} - -inline void CmdLine::reset() -{ - for( ArgListIterator it = _argList.begin(); it != _argList.end(); it++ ) - (*it)->reset(); - - _progName.clear(); -} - -/////////////////////////////////////////////////////////////////////////////// -//End CmdLine.cpp -/////////////////////////////////////////////////////////////////////////////// - - - -} //namespace TCLAP -#endif diff --git a/src/tclap/CmdLineInterface.h b/src/tclap/CmdLineInterface.h deleted file mode 100644 index 1b25e9b8c9..0000000000 --- a/src/tclap/CmdLineInterface.h +++ /dev/null @@ -1,150 +0,0 @@ - -/****************************************************************************** - * - * file: CmdLineInterface.h - * - * Copyright (c) 2003, Michael E. Smoot . - * Copyright (c) 2004, Michael E. Smoot, Daniel Aarno. - * All rights reverved. - * - * See the file COPYING in the top directory of this distribution for - * more information. - * - * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - *****************************************************************************/ - -#ifndef TCLAP_COMMANDLINE_INTERFACE_H -#define TCLAP_COMMANDLINE_INTERFACE_H - -#include -#include -#include -#include -#include - - -namespace TCLAP { - -class Arg; -class CmdLineOutput; -class XorHandler; - -/** - * The base class that manages the command line definition and passes - * along the parsing to the appropriate Arg classes. - */ -class CmdLineInterface -{ - public: - - /** - * Destructor - */ - virtual ~CmdLineInterface() {} - - /** - * Adds an argument to the list of arguments to be parsed. - * \param a - Argument to be added. - */ - virtual void add( Arg& a )=0; - - /** - * An alternative add. Functionally identical. - * \param a - Argument to be added. - */ - virtual void add( Arg* a )=0; - - /** - * Add two Args that will be xor'd. - * If this method is used, add does - * not need to be called. - * \param a - Argument to be added and xor'd. - * \param b - Argument to be added and xor'd. - */ - virtual void xorAdd( Arg& a, Arg& b )=0; - - /** - * Add a list of Args that will be xor'd. If this method is used, - * add does not need to be called. - * \param xors - List of Args to be added and xor'd. - */ - virtual void xorAdd( std::vector& xors )=0; - - /** - * Parses the command line. - * \param argc - Number of arguments. - * \param argv - Array of arguments. - */ - virtual void parse(int argc, const char * const * argv)=0; - - /** - * Parses the command line. - * \param args - A vector of strings representing the args. - * args[0] is still the program name. - */ - void parse(std::vector& args); - - /** - * Returns the CmdLineOutput object. - */ - virtual CmdLineOutput* getOutput()=0; - - /** - * \param co - CmdLineOutput object that we want to use instead. - */ - virtual void setOutput(CmdLineOutput* co)=0; - - /** - * Returns the version string. - */ - virtual std::string& getVersion()=0; - - /** - * Returns the program name string. - */ - virtual std::string& getProgramName()=0; - - /** - * Returns the argList. - */ - virtual std::list& getArgList()=0; - - /** - * Returns the XorHandler. - */ - virtual XorHandler& getXorHandler()=0; - - /** - * Returns the delimiter string. - */ - virtual char getDelimiter()=0; - - /** - * Returns the message string. - */ - virtual std::string& getMessage()=0; - - /** - * Indicates whether or not the help and version switches were created - * automatically. - */ - virtual bool hasHelpAndVersion()=0; - - /** - * Resets the instance as if it had just been constructed so that the - * instance can be reused. - */ - virtual void reset()=0; -}; - -} //namespace - - -#endif diff --git a/src/tclap/CmdLineOutput.h b/src/tclap/CmdLineOutput.h deleted file mode 100644 index 71ee5a3b41..0000000000 --- a/src/tclap/CmdLineOutput.h +++ /dev/null @@ -1,74 +0,0 @@ - - -/****************************************************************************** - * - * file: CmdLineOutput.h - * - * Copyright (c) 2004, Michael E. Smoot - * All rights reverved. - * - * See the file COPYING in the top directory of this distribution for - * more information. - * - * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - *****************************************************************************/ - -#ifndef TCLAP_CMDLINEOUTPUT_H -#define TCLAP_CMDLINEOUTPUT_H - -#include -#include -#include -#include -#include -#include - -namespace TCLAP { - -class CmdLineInterface; -class ArgException; - -/** - * The interface that any output object must implement. - */ -class CmdLineOutput -{ - - public: - - /** - * Virtual destructor. - */ - virtual ~CmdLineOutput() {} - - /** - * Generates some sort of output for the USAGE. - * \param c - The CmdLine object the output is generated for. - */ - virtual void usage(CmdLineInterface& c)=0; - - /** - * Generates some sort of output for the version. - * \param c - The CmdLine object the output is generated for. - */ - virtual void version(CmdLineInterface& c)=0; - - /** - * Generates some sort of output for a failure. - * \param c - The CmdLine object the output is generated for. - * \param e - The ArgException that caused the failure. - */ - virtual void failure( CmdLineInterface& c, - ArgException& e )=0; - -}; - -} //namespace TCLAP -#endif diff --git a/src/tclap/Constraint.h b/src/tclap/Constraint.h deleted file mode 100644 index a92acf9a9a..0000000000 --- a/src/tclap/Constraint.h +++ /dev/null @@ -1,68 +0,0 @@ - -/****************************************************************************** - * - * file: Constraint.h - * - * Copyright (c) 2005, Michael E. Smoot - * All rights reverved. - * - * See the file COPYING in the top directory of this distribution for - * more information. - * - * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - *****************************************************************************/ - -#ifndef TCLAP_CONSTRAINT_H -#define TCLAP_CONSTRAINT_H - -#include -#include -#include -#include -#include -#include - -namespace TCLAP { - -/** - * The interface that defines the interaction between the Arg and Constraint. - */ -template -class Constraint -{ - - public: - /** - * Returns a description of the Constraint. - */ - virtual std::string description() const =0; - - /** - * Returns the short ID for the Constraint. - */ - virtual std::string shortID() const =0; - - /** - * The method used to verify that the value parsed from the command - * line meets the constraint. - * \param value - The value that will be checked. - */ - virtual bool check(const T& value) const =0; - - /** - * Destructor. - * Silences warnings about Constraint being a base class with virtual - * functions but without a virtual destructor. - */ - virtual ~Constraint() { ; } -}; - -} //namespace TCLAP -#endif diff --git a/src/tclap/DocBookOutput.h b/src/tclap/DocBookOutput.h deleted file mode 100644 index a42ca274df..0000000000 --- a/src/tclap/DocBookOutput.h +++ /dev/null @@ -1,299 +0,0 @@ -// -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*- - -/****************************************************************************** - * - * file: DocBookOutput.h - * - * Copyright (c) 2004, Michael E. Smoot - * All rights reverved. - * - * See the file COPYING in the top directory of this distribution for - * more information. - * - * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - *****************************************************************************/ - -#ifndef TCLAP_DOCBOOKOUTPUT_H -#define TCLAP_DOCBOOKOUTPUT_H - -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -namespace TCLAP { - -/** - * A class that generates DocBook output for usage() method for the - * given CmdLine and its Args. - */ -class DocBookOutput : public CmdLineOutput -{ - - public: - - /** - * Prints the usage to stdout. Can be overridden to - * produce alternative behavior. - * \param c - The CmdLine object the output is generated for. - */ - virtual void usage(CmdLineInterface& c); - - /** - * Prints the version to stdout. Can be overridden - * to produce alternative behavior. - * \param c - The CmdLine object the output is generated for. - */ - virtual void version(CmdLineInterface& c); - - /** - * Prints (to stderr) an error message, short usage - * Can be overridden to produce alternative behavior. - * \param c - The CmdLine object the output is generated for. - * \param e - The ArgException that caused the failure. - */ - virtual void failure(CmdLineInterface& c, - ArgException& e ); - - protected: - - /** - * Substitutes the char r for string x in string s. - * \param s - The string to operate on. - * \param r - The char to replace. - * \param x - What to replace r with. - */ - void substituteSpecialChars( std::string& s, char r, std::string& x ); - void removeChar( std::string& s, char r); - void basename( std::string& s ); - - void printShortArg(Arg* it); - void printLongArg(Arg* it); - - char theDelimiter; -}; - - -inline void DocBookOutput::version(CmdLineInterface& _cmd) -{ - std::cout << _cmd.getVersion() << std::endl; -} - -inline void DocBookOutput::usage(CmdLineInterface& _cmd ) -{ - std::list argList = _cmd.getArgList(); - std::string progName = _cmd.getProgramName(); - std::string xversion = _cmd.getVersion(); - theDelimiter = _cmd.getDelimiter(); - XorHandler xorHandler = _cmd.getXorHandler(); - std::vector< std::vector > xorList = xorHandler.getXorList(); - basename(progName); - - std::cout << "" << std::endl; - std::cout << "" << std::endl << std::endl; - - std::cout << "" << std::endl; - - std::cout << "" << std::endl; - std::cout << "" << progName << "" << std::endl; - std::cout << "1" << std::endl; - std::cout << "" << std::endl; - - std::cout << "" << std::endl; - std::cout << "" << progName << "" << std::endl; - std::cout << "" << _cmd.getMessage() << "" << std::endl; - std::cout << "" << std::endl; - - std::cout << "" << std::endl; - std::cout << "" << std::endl; - - std::cout << "" << progName << "" << std::endl; - - // xor - for ( int i = 0; (unsigned int)i < xorList.size(); i++ ) - { - std::cout << "" << std::endl; - for ( ArgVectorIterator it = xorList[i].begin(); - it != xorList[i].end(); it++ ) - printShortArg((*it)); - - std::cout << "" << std::endl; - } - - // rest of args - for (ArgListIterator it = argList.begin(); it != argList.end(); it++) - if ( !xorHandler.contains( (*it) ) ) - printShortArg((*it)); - - std::cout << "" << std::endl; - std::cout << "" << std::endl; - - std::cout << "" << std::endl; - std::cout << "Description" << std::endl; - std::cout << "" << std::endl; - std::cout << _cmd.getMessage() << std::endl; - std::cout << "" << std::endl; - std::cout << "" << std::endl; - - std::cout << "" << std::endl; - std::cout << "Options" << std::endl; - - std::cout << "" << std::endl; - - for (ArgListIterator it = argList.begin(); it != argList.end(); it++) - printLongArg((*it)); - - std::cout << "" << std::endl; - std::cout << "" << std::endl; - - std::cout << "" << std::endl; - std::cout << "Version" << std::endl; - std::cout << "" << std::endl; - std::cout << xversion << std::endl; - std::cout << "" << std::endl; - std::cout << "" << std::endl; - - std::cout << "" << std::endl; - -} - -inline void DocBookOutput::failure( CmdLineInterface& _cmd, - ArgException& e ) -{ - static_cast(_cmd); // unused - std::cout << e.what() << std::endl; - throw ExitException(1); -} - -inline void DocBookOutput::substituteSpecialChars( std::string& s, - char r, - std::string& x ) -{ - size_t p; - while ( (p = s.find_first_of(r)) != std::string::npos ) - { - s.erase(p,1); - s.insert(p,x); - } -} - -inline void DocBookOutput::removeChar( std::string& s, char r) -{ - size_t p; - while ( (p = s.find_first_of(r)) != std::string::npos ) - { - s.erase(p,1); - } -} - -inline void DocBookOutput::basename( std::string& s ) -{ - size_t p = s.find_last_of('/'); - if ( p != std::string::npos ) - { - s.erase(0, p + 1); - } -} - -inline void DocBookOutput::printShortArg(Arg* a) -{ - std::string lt = "<"; - std::string gt = ">"; - - std::string id = a->shortID(); - substituteSpecialChars(id,'<',lt); - substituteSpecialChars(id,'>',gt); - removeChar(id,'['); - removeChar(id,']'); - - std::string choice = "opt"; - if ( a->isRequired() ) - choice = "plain"; - - std::cout << "acceptsMultipleValues() ) - std::cout << " rep='repeat'"; - - - std::cout << '>'; - if ( !a->getFlag().empty() ) - std::cout << a->flagStartChar() << a->getFlag(); - else - std::cout << a->nameStartString() << a->getName(); - if ( a->isValueRequired() ) - { - std::string arg = a->shortID(); - removeChar(arg,'['); - removeChar(arg,']'); - removeChar(arg,'<'); - removeChar(arg,'>'); - arg.erase(0, arg.find_last_of(theDelimiter) + 1); - std::cout << theDelimiter; - std::cout << "" << arg << ""; - } - std::cout << "" << std::endl; - -} - -inline void DocBookOutput::printLongArg(Arg* a) -{ - std::string lt = "<"; - std::string gt = ">"; - - std::string desc = a->getDescription(); - substituteSpecialChars(desc,'<',lt); - substituteSpecialChars(desc,'>',gt); - - std::cout << "" << std::endl; - - if ( !a->getFlag().empty() ) - { - std::cout << "" << std::endl; - std::cout << "" << std::endl; - std::cout << "" << std::endl; - } - - std::cout << "" << std::endl; - std::cout << "" << std::endl; - std::cout << "" << std::endl; - - std::cout << "" << std::endl; - std::cout << "" << std::endl; - std::cout << desc << std::endl; - std::cout << "" << std::endl; - std::cout << "" << std::endl; - - std::cout << "" << std::endl; -} - -} //namespace TCLAP -#endif diff --git a/src/tclap/HelpVisitor.h b/src/tclap/HelpVisitor.h deleted file mode 100644 index cc3bd070ca..0000000000 --- a/src/tclap/HelpVisitor.h +++ /dev/null @@ -1,76 +0,0 @@ - -/****************************************************************************** - * - * file: HelpVisitor.h - * - * Copyright (c) 2003, Michael E. Smoot . - * All rights reverved. - * - * See the file COPYING in the top directory of this distribution for - * more information. - * - * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - *****************************************************************************/ - -#ifndef TCLAP_HELP_VISITOR_H -#define TCLAP_HELP_VISITOR_H - -#include -#include -#include - -namespace TCLAP { - -/** - * A Visitor object that calls the usage method of the given CmdLineOutput - * object for the specified CmdLine object. - */ -class HelpVisitor: public Visitor -{ - private: - /** - * Prevent accidental copying. - */ - HelpVisitor(const HelpVisitor& rhs); - HelpVisitor& operator=(const HelpVisitor& rhs); - - protected: - - /** - * The CmdLine the output will be generated for. - */ - CmdLineInterface* _cmd; - - /** - * The output object. - */ - CmdLineOutput** _out; - - public: - - /** - * Constructor. - * \param cmd - The CmdLine the output will be generated for. - * \param out - The type of output. - */ - HelpVisitor(CmdLineInterface* cmd, CmdLineOutput** out) - : Visitor(), _cmd( cmd ), _out( out ) { } - - /** - * Calls the usage method of the CmdLineOutput for the - * specified CmdLine. - */ - void visit() { (*_out)->usage(*_cmd); throw ExitException(0); } - -}; - -} - -#endif diff --git a/src/tclap/IgnoreRestVisitor.h b/src/tclap/IgnoreRestVisitor.h deleted file mode 100644 index e328649e51..0000000000 --- a/src/tclap/IgnoreRestVisitor.h +++ /dev/null @@ -1,52 +0,0 @@ - -/****************************************************************************** - * - * file: IgnoreRestVisitor.h - * - * Copyright (c) 2003, Michael E. Smoot . - * All rights reverved. - * - * See the file COPYING in the top directory of this distribution for - * more information. - * - * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - *****************************************************************************/ - - -#ifndef TCLAP_IGNORE_REST_VISITOR_H -#define TCLAP_IGNORE_REST_VISITOR_H - -#include -#include - -namespace TCLAP { - -/** - * A Vistor that tells the CmdLine to begin ignoring arguments after - * this one is parsed. - */ -class IgnoreRestVisitor: public Visitor -{ - public: - - /** - * Constructor. - */ - IgnoreRestVisitor() : Visitor() {} - - /** - * Sets Arg::_ignoreRest. - */ - void visit() { Arg::beginIgnoring(); } -}; - -} - -#endif diff --git a/src/tclap/Makefile.am b/src/tclap/Makefile.am deleted file mode 100644 index 0e247bf5bf..0000000000 --- a/src/tclap/Makefile.am +++ /dev/null @@ -1,28 +0,0 @@ - -libtclapincludedir = $(includedir)/tclap - -libtclapinclude_HEADERS = \ - CmdLineInterface.h \ - ArgException.h \ - CmdLine.h \ - XorHandler.h \ - MultiArg.h \ - UnlabeledMultiArg.h \ - ValueArg.h \ - UnlabeledValueArg.h \ - Visitor.h Arg.h \ - HelpVisitor.h \ - SwitchArg.h \ - MultiSwitchArg.h \ - VersionVisitor.h \ - IgnoreRestVisitor.h \ - CmdLineOutput.h \ - StdOutput.h \ - DocBookOutput.h \ - ZshCompletionOutput.h \ - OptionalUnlabeledTracker.h \ - Constraint.h \ - ValuesConstraint.h \ - ArgTraits.h \ - StandardTraits.h - diff --git a/src/tclap/Makefile.in b/src/tclap/Makefile.in deleted file mode 100644 index 65ef2515c2..0000000000 --- a/src/tclap/Makefile.in +++ /dev/null @@ -1,403 +0,0 @@ -# Makefile.in generated by automake 1.10 from Makefile.am. -# @configure_input@ - -# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, -# 2003, 2004, 2005, 2006 Free Software Foundation, Inc. -# This Makefile.in is free software; the Free Software Foundation -# gives unlimited permission to copy and/or distribute it, -# with or without modifications, as long as this notice is preserved. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY, to the extent permitted by law; without -# even the implied warranty of MERCHANTABILITY or FITNESS FOR A -# PARTICULAR PURPOSE. - -@SET_MAKE@ - -VPATH = @srcdir@ -pkgdatadir = $(datadir)/@PACKAGE@ -pkglibdir = $(libdir)/@PACKAGE@ -pkgincludedir = $(includedir)/@PACKAGE@ -am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd -install_sh_DATA = $(install_sh) -c -m 644 -install_sh_PROGRAM = $(install_sh) -c -install_sh_SCRIPT = $(install_sh) -c -INSTALL_HEADER = $(INSTALL_DATA) -transform = $(program_transform_name) -NORMAL_INSTALL = : -PRE_INSTALL = : -POST_INSTALL = : -NORMAL_UNINSTALL = : -PRE_UNINSTALL = : -POST_UNINSTALL = : -subdir = include/tclap -DIST_COMMON = $(libtclapinclude_HEADERS) $(srcdir)/Makefile.am \ - $(srcdir)/Makefile.in -ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 -am__aclocal_m4_deps = $(top_srcdir)/config/ac_cxx_have_long_long.m4 \ - $(top_srcdir)/config/ac_cxx_have_sstream.m4 \ - $(top_srcdir)/config/ac_cxx_have_strstream.m4 \ - $(top_srcdir)/config/ac_cxx_namespaces.m4 \ - $(top_srcdir)/config/ac_cxx_warn_effective_cxx.m4 \ - $(top_srcdir)/config/bb_enable_doxygen.m4 \ - $(top_srcdir)/configure.in -am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ - $(ACLOCAL_M4) -mkinstalldirs = $(SHELL) $(top_srcdir)/config/mkinstalldirs -CONFIG_HEADER = $(top_builddir)/config/config.h -CONFIG_CLEAN_FILES = -SOURCES = -DIST_SOURCES = -am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; -am__vpath_adj = case $$p in \ - $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ - *) f=$$p;; \ - esac; -am__strip_dir = `echo $$p | sed -e 's|^.*/||'`; -am__installdirs = "$(DESTDIR)$(libtclapincludedir)" -libtclapincludeHEADERS_INSTALL = $(INSTALL_HEADER) -HEADERS = $(libtclapinclude_HEADERS) -ETAGS = etags -CTAGS = ctags -DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) -ACLOCAL = @ACLOCAL@ -AMTAR = @AMTAR@ -AUTOCONF = @AUTOCONF@ -AUTOHEADER = @AUTOHEADER@ -AUTOMAKE = @AUTOMAKE@ -AWK = @AWK@ -CPPFLAGS = @CPPFLAGS@ -CXX = @CXX@ -CXXCPP = @CXXCPP@ -CXXDEPMODE = @CXXDEPMODE@ -CXXFLAGS = @CXXFLAGS@ -CYGPATH_W = @CYGPATH_W@ -DEFS = @DEFS@ -DEPDIR = @DEPDIR@ -DOT = @DOT@ -DOXYGEN = @DOXYGEN@ -ECHO_C = @ECHO_C@ -ECHO_N = @ECHO_N@ -ECHO_T = @ECHO_T@ -EGREP = @EGREP@ -EXEEXT = @EXEEXT@ -GREP = @GREP@ -INSTALL = @INSTALL@ -INSTALL_DATA = @INSTALL_DATA@ -INSTALL_PROGRAM = @INSTALL_PROGRAM@ -INSTALL_SCRIPT = @INSTALL_SCRIPT@ -INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ -LDFLAGS = @LDFLAGS@ -LIBOBJS = @LIBOBJS@ -LIBS = @LIBS@ -LTLIBOBJS = @LTLIBOBJS@ -MAKEINFO = @MAKEINFO@ -MKDIR_P = @MKDIR_P@ -OBJEXT = @OBJEXT@ -PACKAGE = @PACKAGE@ -PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ -PACKAGE_NAME = @PACKAGE_NAME@ -PACKAGE_STRING = @PACKAGE_STRING@ -PACKAGE_TARNAME = @PACKAGE_TARNAME@ -PACKAGE_VERSION = @PACKAGE_VERSION@ -PATH_SEPARATOR = @PATH_SEPARATOR@ -RANLIB = @RANLIB@ -SET_MAKE = @SET_MAKE@ -SHELL = @SHELL@ -STRIP = @STRIP@ -VERSION = @VERSION@ -WARN_EFFECTIVE_CXX = @WARN_EFFECTIVE_CXX@ -WARN_NO_EFFECTIVE_CXX = @WARN_NO_EFFECTIVE_CXX@ -abs_builddir = @abs_builddir@ -abs_srcdir = @abs_srcdir@ -abs_top_builddir = @abs_top_builddir@ -abs_top_srcdir = @abs_top_srcdir@ -ac_ct_CXX = @ac_ct_CXX@ -am__include = @am__include@ -am__leading_dot = @am__leading_dot@ -am__quote = @am__quote@ -am__tar = @am__tar@ -am__untar = @am__untar@ -bindir = @bindir@ -build_alias = @build_alias@ -builddir = @builddir@ -datadir = @datadir@ -datarootdir = @datarootdir@ -docdir = @docdir@ -dvidir = @dvidir@ -exec_prefix = @exec_prefix@ -host_alias = @host_alias@ -htmldir = @htmldir@ -includedir = @includedir@ -infodir = @infodir@ -install_sh = @install_sh@ -libdir = @libdir@ -libexecdir = @libexecdir@ -localedir = @localedir@ -localstatedir = @localstatedir@ -mandir = @mandir@ -mkdir_p = @mkdir_p@ -oldincludedir = @oldincludedir@ -pdfdir = @pdfdir@ -prefix = @prefix@ -program_transform_name = @program_transform_name@ -psdir = @psdir@ -sbindir = @sbindir@ -sharedstatedir = @sharedstatedir@ -srcdir = @srcdir@ -sysconfdir = @sysconfdir@ -target_alias = @target_alias@ -top_builddir = @top_builddir@ -top_srcdir = @top_srcdir@ -libtclapincludedir = $(includedir)/tclap -libtclapinclude_HEADERS = \ - CmdLineInterface.h \ - ArgException.h \ - CmdLine.h \ - XorHandler.h \ - MultiArg.h \ - UnlabeledMultiArg.h \ - ValueArg.h \ - UnlabeledValueArg.h \ - Visitor.h Arg.h \ - HelpVisitor.h \ - SwitchArg.h \ - MultiSwitchArg.h \ - VersionVisitor.h \ - IgnoreRestVisitor.h \ - CmdLineOutput.h \ - StdOutput.h \ - DocBookOutput.h \ - ZshCompletionOutput.h \ - OptionalUnlabeledTracker.h \ - Constraint.h \ - ValuesConstraint.h \ - ArgTraits.h \ - StandardTraits.h - -all: all-am - -.SUFFIXES: -$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) - @for dep in $?; do \ - case '$(am__configure_deps)' in \ - *$$dep*) \ - cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \ - && exit 0; \ - exit 1;; \ - esac; \ - done; \ - echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu include/tclap/Makefile'; \ - cd $(top_srcdir) && \ - $(AUTOMAKE) --gnu include/tclap/Makefile -.PRECIOUS: Makefile -Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status - @case '$?' in \ - *config.status*) \ - cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ - *) \ - echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ - cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ - esac; - -$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) - cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh - -$(top_srcdir)/configure: $(am__configure_deps) - cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh -$(ACLOCAL_M4): $(am__aclocal_m4_deps) - cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh -install-libtclapincludeHEADERS: $(libtclapinclude_HEADERS) - @$(NORMAL_INSTALL) - test -z "$(libtclapincludedir)" || $(MKDIR_P) "$(DESTDIR)$(libtclapincludedir)" - @list='$(libtclapinclude_HEADERS)'; for p in $$list; do \ - if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ - f=$(am__strip_dir) \ - echo " $(libtclapincludeHEADERS_INSTALL) '$$d$$p' '$(DESTDIR)$(libtclapincludedir)/$$f'"; \ - $(libtclapincludeHEADERS_INSTALL) "$$d$$p" "$(DESTDIR)$(libtclapincludedir)/$$f"; \ - done - -uninstall-libtclapincludeHEADERS: - @$(NORMAL_UNINSTALL) - @list='$(libtclapinclude_HEADERS)'; for p in $$list; do \ - f=$(am__strip_dir) \ - echo " rm -f '$(DESTDIR)$(libtclapincludedir)/$$f'"; \ - rm -f "$(DESTDIR)$(libtclapincludedir)/$$f"; \ - done - -ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) - list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ - unique=`for i in $$list; do \ - if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ - done | \ - $(AWK) ' { files[$$0] = 1; } \ - END { for (i in files) print i; }'`; \ - mkid -fID $$unique -tags: TAGS - -TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ - $(TAGS_FILES) $(LISP) - tags=; \ - here=`pwd`; \ - list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ - unique=`for i in $$list; do \ - if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ - done | \ - $(AWK) ' { files[$$0] = 1; } \ - END { for (i in files) print i; }'`; \ - if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \ - test -n "$$unique" || unique=$$empty_fix; \ - $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ - $$tags $$unique; \ - fi -ctags: CTAGS -CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ - $(TAGS_FILES) $(LISP) - tags=; \ - here=`pwd`; \ - list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ - unique=`for i in $$list; do \ - if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ - done | \ - $(AWK) ' { files[$$0] = 1; } \ - END { for (i in files) print i; }'`; \ - test -z "$(CTAGS_ARGS)$$tags$$unique" \ - || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ - $$tags $$unique - -GTAGS: - here=`$(am__cd) $(top_builddir) && pwd` \ - && cd $(top_srcdir) \ - && gtags -i $(GTAGS_ARGS) $$here - -distclean-tags: - -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags - -distdir: $(DISTFILES) - @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ - topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ - list='$(DISTFILES)'; \ - dist_files=`for file in $$list; do echo $$file; done | \ - sed -e "s|^$$srcdirstrip/||;t" \ - -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ - case $$dist_files in \ - */*) $(MKDIR_P) `echo "$$dist_files" | \ - sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ - sort -u` ;; \ - esac; \ - for file in $$dist_files; do \ - if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ - if test -d $$d/$$file; then \ - dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ - if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ - cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \ - fi; \ - cp -pR $$d/$$file $(distdir)$$dir || exit 1; \ - else \ - test -f $(distdir)/$$file \ - || cp -p $$d/$$file $(distdir)/$$file \ - || exit 1; \ - fi; \ - done -check-am: all-am -check: check-am -all-am: Makefile $(HEADERS) -installdirs: - for dir in "$(DESTDIR)$(libtclapincludedir)"; do \ - test -z "$$dir" || $(MKDIR_P) "$$dir"; \ - done -install: install-am -install-exec: install-exec-am -install-data: install-data-am -uninstall: uninstall-am - -install-am: all-am - @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am - -installcheck: installcheck-am -install-strip: - $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ - install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ - `test -z '$(STRIP)' || \ - echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install -mostlyclean-generic: - -clean-generic: - -distclean-generic: - -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) - -maintainer-clean-generic: - @echo "This command is intended for maintainers to use" - @echo "it deletes files that may require special tools to rebuild." -clean: clean-am - -clean-am: clean-generic mostlyclean-am - -distclean: distclean-am - -rm -f Makefile -distclean-am: clean-am distclean-generic distclean-tags - -dvi: dvi-am - -dvi-am: - -html: html-am - -info: info-am - -info-am: - -install-data-am: install-libtclapincludeHEADERS - -install-dvi: install-dvi-am - -install-exec-am: - -install-html: install-html-am - -install-info: install-info-am - -install-man: - -install-pdf: install-pdf-am - -install-ps: install-ps-am - -installcheck-am: - -maintainer-clean: maintainer-clean-am - -rm -f Makefile -maintainer-clean-am: distclean-am maintainer-clean-generic - -mostlyclean: mostlyclean-am - -mostlyclean-am: mostlyclean-generic - -pdf: pdf-am - -pdf-am: - -ps: ps-am - -ps-am: - -uninstall-am: uninstall-libtclapincludeHEADERS - -.MAKE: install-am install-strip - -.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \ - ctags distclean distclean-generic distclean-tags distdir dvi \ - dvi-am html html-am info info-am install install-am \ - install-data install-data-am install-dvi install-dvi-am \ - install-exec install-exec-am install-html install-html-am \ - install-info install-info-am install-libtclapincludeHEADERS \ - install-man install-pdf install-pdf-am install-ps \ - install-ps-am install-strip installcheck installcheck-am \ - installdirs maintainer-clean maintainer-clean-generic \ - mostlyclean mostlyclean-generic pdf pdf-am ps ps-am tags \ - uninstall uninstall-am uninstall-libtclapincludeHEADERS - -# Tell versions [3.59,3.63) of GNU make to not export all variables. -# Otherwise a system limit (for SysV at least) may be exceeded. -.NOEXPORT: diff --git a/src/tclap/MultiArg.h b/src/tclap/MultiArg.h deleted file mode 100644 index 34bb2d7895..0000000000 --- a/src/tclap/MultiArg.h +++ /dev/null @@ -1,433 +0,0 @@ -/****************************************************************************** - * - * file: MultiArg.h - * - * Copyright (c) 2003, Michael E. Smoot . - * Copyright (c) 2004, Michael E. Smoot, Daniel Aarno. - * All rights reverved. - * - * See the file COPYING in the top directory of this distribution for - * more information. - * - * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - *****************************************************************************/ - - -#ifndef TCLAP_MULTIPLE_ARGUMENT_H -#define TCLAP_MULTIPLE_ARGUMENT_H - -#include -#include - -#include -#include - -namespace TCLAP { -/** - * An argument that allows multiple values of type T to be specified. Very - * similar to a ValueArg, except a vector of values will be returned - * instead of just one. - */ -template -class MultiArg : public Arg -{ -public: - typedef std::vector container_type; - typedef typename container_type::iterator iterator; - typedef typename container_type::const_iterator const_iterator; - -protected: - - /** - * The list of values parsed from the CmdLine. - */ - std::vector _values; - - /** - * The description of type T to be used in the usage. - */ - std::string _typeDesc; - - /** - * A list of constraint on this Arg. - */ - Constraint* _constraint; - - /** - * Extracts the value from the string. - * Attempts to parse string as type T, if this fails an exception - * is thrown. - * \param val - The string to be read. - */ - void _extractValue( const std::string& val ); - - /** - * Used by XorHandler to decide whether to keep parsing for this arg. - */ - bool _allowMore; - -public: - - /** - * Constructor. - * \param flag - The one character flag that identifies this - * argument on the command line. - * \param name - A one word name for the argument. Can be - * used as a long flag on the command line. - * \param desc - A description of what the argument is for or - * does. - * \param req - Whether the argument is required on the command - * line. - * \param typeDesc - A short, human readable description of the - * type that this object expects. This is used in the generation - * of the USAGE statement. The goal is to be helpful to the end user - * of the program. - * \param v - An optional visitor. You probably should not - * use this unless you have a very good reason. - */ - MultiArg( const std::string& flag, - const std::string& name, - const std::string& desc, - bool req, - const std::string& typeDesc, - Visitor* v = NULL); - - /** - * Constructor. - * \param flag - The one character flag that identifies this - * argument on the command line. - * \param name - A one word name for the argument. Can be - * used as a long flag on the command line. - * \param desc - A description of what the argument is for or - * does. - * \param req - Whether the argument is required on the command - * line. - * \param typeDesc - A short, human readable description of the - * type that this object expects. This is used in the generation - * of the USAGE statement. The goal is to be helpful to the end user - * of the program. - * \param parser - A CmdLine parser object to add this Arg to - * \param v - An optional visitor. You probably should not - * use this unless you have a very good reason. - */ - MultiArg( const std::string& flag, - const std::string& name, - const std::string& desc, - bool req, - const std::string& typeDesc, - CmdLineInterface& parser, - Visitor* v = NULL ); - - /** - * Constructor. - * \param flag - The one character flag that identifies this - * argument on the command line. - * \param name - A one word name for the argument. Can be - * used as a long flag on the command line. - * \param desc - A description of what the argument is for or - * does. - * \param req - Whether the argument is required on the command - * line. - * \param constraint - A pointer to a Constraint object used - * to constrain this Arg. - * \param v - An optional visitor. You probably should not - * use this unless you have a very good reason. - */ - MultiArg( const std::string& flag, - const std::string& name, - const std::string& desc, - bool req, - Constraint* constraint, - Visitor* v = NULL ); - - /** - * Constructor. - * \param flag - The one character flag that identifies this - * argument on the command line. - * \param name - A one word name for the argument. Can be - * used as a long flag on the command line. - * \param desc - A description of what the argument is for or - * does. - * \param req - Whether the argument is required on the command - * line. - * \param constraint - A pointer to a Constraint object used - * to constrain this Arg. - * \param parser - A CmdLine parser object to add this Arg to - * \param v - An optional visitor. You probably should not - * use this unless you have a very good reason. - */ - MultiArg( const std::string& flag, - const std::string& name, - const std::string& desc, - bool req, - Constraint* constraint, - CmdLineInterface& parser, - Visitor* v = NULL ); - - /** - * Handles the processing of the argument. - * This re-implements the Arg version of this method to set the - * _value of the argument appropriately. It knows the difference - * between labeled and unlabeled. - * \param i - Pointer the the current argument in the list. - * \param args - Mutable list of strings. Passed from main(). - */ - virtual bool processArg(int* i, std::vector& args); - - /** - * Returns a vector of type T containing the values parsed from - * the command line. - */ - const std::vector& getValue(); - - /** - * Returns an iterator over the values parsed from the command - * line. - */ - const_iterator begin() const { return _values.begin(); } - - /** - * Returns the end of the values parsed from the command - * line. - */ - const_iterator end() const { return _values.end(); } - - /** - * Returns the a short id string. Used in the usage. - * \param val - value to be used. - */ - virtual std::string shortID(const std::string& val="val") const; - - /** - * Returns the a long id string. Used in the usage. - * \param val - value to be used. - */ - virtual std::string longID(const std::string& val="val") const; - - /** - * Once we've matched the first value, then the arg is no longer - * required. - */ - virtual bool isRequired() const; - - virtual bool allowMore(); - - virtual void reset(); - -private: - /** - * Prevent accidental copying - */ - MultiArg(const MultiArg& rhs); - MultiArg& operator=(const MultiArg& rhs); - -}; - -template -MultiArg::MultiArg(const std::string& flag, - const std::string& name, - const std::string& desc, - bool req, - const std::string& typeDesc, - Visitor* v) : - Arg( flag, name, desc, req, true, v ), - _values(std::vector()), - _typeDesc( typeDesc ), - _constraint( NULL ), - _allowMore(false) -{ - _acceptsMultipleValues = true; -} - -template -MultiArg::MultiArg(const std::string& flag, - const std::string& name, - const std::string& desc, - bool req, - const std::string& typeDesc, - CmdLineInterface& parser, - Visitor* v) -: Arg( flag, name, desc, req, true, v ), - _values(std::vector()), - _typeDesc( typeDesc ), - _constraint( NULL ), - _allowMore(false) -{ - parser.add( this ); - _acceptsMultipleValues = true; -} - -/** - * - */ -template -MultiArg::MultiArg(const std::string& flag, - const std::string& name, - const std::string& desc, - bool req, - Constraint* constraint, - Visitor* v) -: Arg( flag, name, desc, req, true, v ), - _values(std::vector()), - _typeDesc( constraint->shortID() ), - _constraint( constraint ), - _allowMore(false) -{ - _acceptsMultipleValues = true; -} - -template -MultiArg::MultiArg(const std::string& flag, - const std::string& name, - const std::string& desc, - bool req, - Constraint* constraint, - CmdLineInterface& parser, - Visitor* v) -: Arg( flag, name, desc, req, true, v ), - _values(std::vector()), - _typeDesc( constraint->shortID() ), - _constraint( constraint ), - _allowMore(false) -{ - parser.add( this ); - _acceptsMultipleValues = true; -} - -template -const std::vector& MultiArg::getValue() { return _values; } - -template -bool MultiArg::processArg(int *i, std::vector& args) -{ - if ( _ignoreable && Arg::ignoreRest() ) - return false; - - if ( _hasBlanks( args[*i] ) ) - return false; - - std::string flag = args[*i]; - std::string value = ""; - - trimFlag( flag, value ); - - if ( argMatches( flag ) ) - { - if ( Arg::delimiter() != ' ' && value == "" ) - throw( ArgParseException( - "Couldn't find delimiter for this argument!", - toString() ) ); - - // always take the first one, regardless of start string - if ( value == "" ) - { - (*i)++; - if ( static_cast(*i) < args.size() ) - _extractValue( args[*i] ); - else - throw( ArgParseException("Missing a value for this argument!", - toString() ) ); - } - else - _extractValue( value ); - - /* - // continuing taking the args until we hit one with a start string - while ( (unsigned int)(*i)+1 < args.size() && - args[(*i)+1].find_first_of( Arg::flagStartString() ) != 0 && - args[(*i)+1].find_first_of( Arg::nameStartString() ) != 0 ) - _extractValue( args[++(*i)] ); - */ - - _alreadySet = true; - _checkWithVisitor(); - - return true; - } - else - return false; -} - -/** - * - */ -template -std::string MultiArg::shortID(const std::string& val) const -{ - static_cast(val); // Ignore input, don't warn - return Arg::shortID(_typeDesc) + " ... "; -} - -/** - * - */ -template -std::string MultiArg::longID(const std::string& val) const -{ - static_cast(val); // Ignore input, don't warn - return Arg::longID(_typeDesc) + " (accepted multiple times)"; -} - -/** - * Once we've matched the first value, then the arg is no longer - * required. - */ -template -bool MultiArg::isRequired() const -{ - if ( _required ) - { - if ( _values.size() > 1 ) - return false; - else - return true; - } - else - return false; - -} - -template -void MultiArg::_extractValue( const std::string& val ) -{ - try { - T tmp; - ExtractValue(tmp, val, typename ArgTraits::ValueCategory()); - _values.push_back(tmp); - } catch( ArgParseException &e) { - throw ArgParseException(e.error(), toString()); - } - - if ( _constraint != NULL ) - if ( ! _constraint->check( _values.back() ) ) - throw( CmdLineParseException( "Value '" + val + - "' does not meet constraint: " + - _constraint->description(), - toString() ) ); -} - -template -bool MultiArg::allowMore() -{ - bool am = _allowMore; - _allowMore = true; - return am; -} - -template -void MultiArg::reset() -{ - Arg::reset(); - _values.clear(); -} - -} // namespace TCLAP - -#endif diff --git a/src/tclap/MultiSwitchArg.h b/src/tclap/MultiSwitchArg.h deleted file mode 100644 index 8820b64162..0000000000 --- a/src/tclap/MultiSwitchArg.h +++ /dev/null @@ -1,216 +0,0 @@ - -/****************************************************************************** -* -* file: MultiSwitchArg.h -* -* Copyright (c) 2003, Michael E. Smoot . -* Copyright (c) 2004, Michael E. Smoot, Daniel Aarno. -* Copyright (c) 2005, Michael E. Smoot, Daniel Aarno, Erik Zeek. -* All rights reverved. -* -* See the file COPYING in the top directory of this distribution for -* more information. -* -* THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS -* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -* DEALINGS IN THE SOFTWARE. -* -*****************************************************************************/ - - -#ifndef TCLAP_MULTI_SWITCH_ARG_H -#define TCLAP_MULTI_SWITCH_ARG_H - -#include -#include - -#include - -namespace TCLAP { - -/** -* A multiple switch argument. If the switch is set on the command line, then -* the getValue method will return the number of times the switch appears. -*/ -class MultiSwitchArg : public SwitchArg -{ - protected: - - /** - * The value of the switch. - */ - int _value; - - /** - * Used to support the reset() method so that ValueArg can be - * reset to their constructed value. - */ - int _default; - - public: - - /** - * MultiSwitchArg constructor. - * \param flag - The one character flag that identifies this - * argument on the command line. - * \param name - A one word name for the argument. Can be - * used as a long flag on the command line. - * \param desc - A description of what the argument is for or - * does. - * \param init - Optional. The initial/default value of this Arg. - * Defaults to 0. - * \param v - An optional visitor. You probably should not - * use this unless you have a very good reason. - */ - MultiSwitchArg(const std::string& flag, - const std::string& name, - const std::string& desc, - int init = 0, - Visitor* v = NULL); - - - /** - * MultiSwitchArg constructor. - * \param flag - The one character flag that identifies this - * argument on the command line. - * \param name - A one word name for the argument. Can be - * used as a long flag on the command line. - * \param desc - A description of what the argument is for or - * does. - * \param parser - A CmdLine parser object to add this Arg to - * \param init - Optional. The initial/default value of this Arg. - * Defaults to 0. - * \param v - An optional visitor. You probably should not - * use this unless you have a very good reason. - */ - MultiSwitchArg(const std::string& flag, - const std::string& name, - const std::string& desc, - CmdLineInterface& parser, - int init = 0, - Visitor* v = NULL); - - - /** - * Handles the processing of the argument. - * This re-implements the SwitchArg version of this method to set the - * _value of the argument appropriately. - * \param i - Pointer the the current argument in the list. - * \param args - Mutable list of strings. Passed - * in from main(). - */ - virtual bool processArg(int* i, std::vector& args); - - /** - * Returns int, the number of times the switch has been set. - */ - int getValue(); - - /** - * Returns the shortID for this Arg. - */ - std::string shortID(const std::string& val) const; - - /** - * Returns the longID for this Arg. - */ - std::string longID(const std::string& val) const; - - void reset(); - -}; - -////////////////////////////////////////////////////////////////////// -//BEGIN MultiSwitchArg.cpp -////////////////////////////////////////////////////////////////////// -inline MultiSwitchArg::MultiSwitchArg(const std::string& flag, - const std::string& name, - const std::string& desc, - int init, - Visitor* v ) -: SwitchArg(flag, name, desc, false, v), -_value( init ), -_default( init ) -{ } - -inline MultiSwitchArg::MultiSwitchArg(const std::string& flag, - const std::string& name, - const std::string& desc, - CmdLineInterface& parser, - int init, - Visitor* v ) -: SwitchArg(flag, name, desc, false, v), -_value( init ), -_default( init ) -{ - parser.add( this ); -} - -inline int MultiSwitchArg::getValue() { return _value; } - -inline bool MultiSwitchArg::processArg(int *i, std::vector& args) -{ - if ( _ignoreable && Arg::ignoreRest() ) - return false; - - if ( argMatches( args[*i] )) - { - // so the isSet() method will work - _alreadySet = true; - - // Matched argument: increment value. - ++_value; - - _checkWithVisitor(); - - return true; - } - else if ( combinedSwitchesMatch( args[*i] ) ) - { - // so the isSet() method will work - _alreadySet = true; - - // Matched argument: increment value. - ++_value; - - // Check for more in argument and increment value. - while ( combinedSwitchesMatch( args[*i] ) ) - ++_value; - - _checkWithVisitor(); - - return false; - } - else - return false; -} - -inline std::string -MultiSwitchArg::shortID(const std::string& val) const -{ - return Arg::shortID(val) + " ... "; -} - -inline std::string -MultiSwitchArg::longID(const std::string& val) const -{ - return Arg::longID(val) + " (accepted multiple times)"; -} - -inline void -MultiSwitchArg::reset() -{ - MultiSwitchArg::_value = MultiSwitchArg::_default; -} - -////////////////////////////////////////////////////////////////////// -//END MultiSwitchArg.cpp -////////////////////////////////////////////////////////////////////// - -} //namespace TCLAP - -#endif diff --git a/src/tclap/OptionalUnlabeledTracker.h b/src/tclap/OptionalUnlabeledTracker.h deleted file mode 100644 index 8174c5f624..0000000000 --- a/src/tclap/OptionalUnlabeledTracker.h +++ /dev/null @@ -1,62 +0,0 @@ - - -/****************************************************************************** - * - * file: OptionalUnlabeledTracker.h - * - * Copyright (c) 2005, Michael E. Smoot . - * All rights reverved. - * - * See the file COPYING in the top directory of this distribution for - * more information. - * - * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - *****************************************************************************/ - - -#ifndef TCLAP_OPTIONAL_UNLABELED_TRACKER_H -#define TCLAP_OPTIONAL_UNLABELED_TRACKER_H - -#include - -namespace TCLAP { - -class OptionalUnlabeledTracker -{ - - public: - - static void check( bool req, const std::string& argName ); - - static void gotOptional() { alreadyOptionalRef() = true; } - - static bool& alreadyOptional() { return alreadyOptionalRef(); } - - private: - - static bool& alreadyOptionalRef() { static bool ct = false; return ct; } -}; - - -inline void OptionalUnlabeledTracker::check( bool req, const std::string& argName ) -{ - if ( OptionalUnlabeledTracker::alreadyOptional() ) - throw( SpecificationException( - "You can't specify ANY Unlabeled Arg following an optional Unlabeled Arg", - argName ) ); - - if ( !req ) - OptionalUnlabeledTracker::gotOptional(); -} - - -} // namespace TCLAP - -#endif diff --git a/src/tclap/StandardTraits.h b/src/tclap/StandardTraits.h deleted file mode 100644 index 46d7f6fafd..0000000000 --- a/src/tclap/StandardTraits.h +++ /dev/null @@ -1,208 +0,0 @@ -// -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*- - -/****************************************************************************** - * - * file: StandardTraits.h - * - * Copyright (c) 2007, Daniel Aarno, Michael E. Smoot . - * All rights reverved. - * - * See the file COPYING in the top directory of this distribution for - * more information. - * - * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - *****************************************************************************/ - -// This is an internal tclap file, you should probably not have to -// include this directly - -#ifndef TCLAP_STANDARD_TRAITS_H -#define TCLAP_STANDARD_TRAITS_H - -#ifdef HAVE_CONFIG_H -#include // To check for long long -#endif - -// If Microsoft has already typedef'd wchar_t as an unsigned -// short, then compiles will break because it's as if we're -// creating ArgTraits twice for unsigned short. Thus... -#ifdef _MSC_VER -#ifndef _NATIVE_WCHAR_T_DEFINED -#define TCLAP_DONT_DECLARE_WCHAR_T_ARGTRAITS -#endif -#endif - -namespace TCLAP { - -// ====================================================================== -// Integer types -// ====================================================================== - -/** - * longs have value-like semantics. - */ -template<> -struct ArgTraits { - typedef ValueLike ValueCategory; -}; - -/** - * ints have value-like semantics. - */ -template<> -struct ArgTraits { - typedef ValueLike ValueCategory; -}; - -/** - * shorts have value-like semantics. - */ -template<> -struct ArgTraits { - typedef ValueLike ValueCategory; -}; - -/** - * chars have value-like semantics. - */ -template<> -struct ArgTraits { - typedef ValueLike ValueCategory; -}; - -#ifdef HAVE_LONG_LONG -/** - * long longs have value-like semantics. - */ -template<> -struct ArgTraits { - typedef ValueLike ValueCategory; -}; -#endif - -// ====================================================================== -// Unsigned integer types -// ====================================================================== - -/** - * unsigned longs have value-like semantics. - */ -template<> -struct ArgTraits { - typedef ValueLike ValueCategory; -}; - -/** - * unsigned ints have value-like semantics. - */ -template<> -struct ArgTraits { - typedef ValueLike ValueCategory; -}; - -/** - * unsigned shorts have value-like semantics. - */ -template<> -struct ArgTraits { - typedef ValueLike ValueCategory; -}; - -/** - * unsigned chars have value-like semantics. - */ -template<> -struct ArgTraits { - typedef ValueLike ValueCategory; -}; - -// Microsoft implements size_t awkwardly. -#if defined(_MSC_VER) && defined(_M_X64) -/** - * size_ts have value-like semantics. - */ -template<> -struct ArgTraits { - typedef ValueLike ValueCategory; -}; -#endif - - -#ifdef HAVE_LONG_LONG -/** - * unsigned long longs have value-like semantics. - */ -template<> -struct ArgTraits { - typedef ValueLike ValueCategory; -}; -#endif - -// ====================================================================== -// Float types -// ====================================================================== - -/** - * floats have value-like semantics. - */ -template<> -struct ArgTraits { - typedef ValueLike ValueCategory; -}; - -/** - * doubles have value-like semantics. - */ -template<> -struct ArgTraits { - typedef ValueLike ValueCategory; -}; - -// ====================================================================== -// Other types -// ====================================================================== - -/** - * bools have value-like semantics. - */ -template<> -struct ArgTraits { - typedef ValueLike ValueCategory; -}; - - -/** - * wchar_ts have value-like semantics. - */ -#ifndef TCLAP_DONT_DECLARE_WCHAR_T_ARGTRAITS -template<> -struct ArgTraits { - typedef ValueLike ValueCategory; -}; -#endif - -/** - * Strings have string like argument traits. - */ -template<> -struct ArgTraits { - typedef StringLike ValueCategory; -}; - -template -void SetString(T &dst, const std::string &src) -{ - dst = src; -} - -} // namespace - -#endif - diff --git a/src/tclap/StdOutput.h b/src/tclap/StdOutput.h deleted file mode 100644 index 35f7b99b2c..0000000000 --- a/src/tclap/StdOutput.h +++ /dev/null @@ -1,298 +0,0 @@ -// -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*- - -/****************************************************************************** - * - * file: StdOutput.h - * - * Copyright (c) 2004, Michael E. Smoot - * All rights reverved. - * - * See the file COPYING in the top directory of this distribution for - * more information. - * - * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - *****************************************************************************/ - -#ifndef TCLAP_STDCMDLINEOUTPUT_H -#define TCLAP_STDCMDLINEOUTPUT_H - -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -namespace TCLAP { - -/** - * A class that isolates any output from the CmdLine object so that it - * may be easily modified. - */ -class StdOutput : public CmdLineOutput -{ - - public: - - /** - * Prints the usage to stdout. Can be overridden to - * produce alternative behavior. - * \param c - The CmdLine object the output is generated for. - */ - virtual void usage(CmdLineInterface& c); - - /** - * Prints the version to stdout. Can be overridden - * to produce alternative behavior. - * \param c - The CmdLine object the output is generated for. - */ - virtual void version(CmdLineInterface& c); - - /** - * Prints (to stderr) an error message, short usage - * Can be overridden to produce alternative behavior. - * \param c - The CmdLine object the output is generated for. - * \param e - The ArgException that caused the failure. - */ - virtual void failure(CmdLineInterface& c, - ArgException& e ); - - protected: - - /** - * Writes a brief usage message with short args. - * \param c - The CmdLine object the output is generated for. - * \param os - The stream to write the message to. - */ - void _shortUsage( CmdLineInterface& c, std::ostream& os ) const; - - /** - * Writes a longer usage message with long and short args, - * provides descriptions and prints message. - * \param c - The CmdLine object the output is generated for. - * \param os - The stream to write the message to. - */ - void _longUsage( CmdLineInterface& c, std::ostream& os ) const; - - /** - * This function inserts line breaks and indents long strings - * according the params input. It will only break lines at spaces, - * commas and pipes. - * \param os - The stream to be printed to. - * \param s - The string to be printed. - * \param maxWidth - The maxWidth allowed for the output line. - * \param indentSpaces - The number of spaces to indent the first line. - * \param secondLineOffset - The number of spaces to indent the second - * and all subsequent lines in addition to indentSpaces. - */ - void spacePrint( std::ostream& os, - const std::string& s, - int maxWidth, - int indentSpaces, - int secondLineOffset ) const; - -}; - - -inline void StdOutput::version(CmdLineInterface& _cmd) -{ - std::string progName = _cmd.getProgramName(); - std::string xversion = _cmd.getVersion(); - - std::cout << std::endl << progName << " version: " - << xversion << std::endl << std::endl; -} - -inline void StdOutput::usage(CmdLineInterface& _cmd ) -{ - std::cout << std::endl << "USAGE: " << std::endl << std::endl; - - _shortUsage( _cmd, std::cout ); - - std::cout << std::endl << std::endl << "Where: " << std::endl << std::endl; - - _longUsage( _cmd, std::cout ); - - std::cout << std::endl; - -} - -inline void StdOutput::failure( CmdLineInterface& _cmd, - ArgException& e ) -{ - std::string progName = _cmd.getProgramName(); - - std::cerr << "PARSE ERROR: " << e.argId() << std::endl - << " " << e.error() << std::endl << std::endl; - - if ( _cmd.hasHelpAndVersion() ) - { - std::cerr << "Brief USAGE: " << std::endl; - - _shortUsage( _cmd, std::cerr ); - - std::cerr << std::endl << "For complete USAGE and HELP type: " - << std::endl << " " << progName << " --help" - << std::endl << std::endl; - } - else - usage(_cmd); - - throw ExitException(1); -} - -inline void -StdOutput::_shortUsage( CmdLineInterface& _cmd, - std::ostream& os ) const -{ - std::list argList = _cmd.getArgList(); - std::string progName = _cmd.getProgramName(); - XorHandler xorHandler = _cmd.getXorHandler(); - std::vector< std::vector > xorList = xorHandler.getXorList(); - - std::string s = progName + " "; - - // first the xor - for ( int i = 0; static_cast(i) < xorList.size(); i++ ) - { - s += " {"; - for ( ArgVectorIterator it = xorList[i].begin(); - it != xorList[i].end(); it++ ) - s += (*it)->shortID() + "|"; - - s[s.length()-1] = '}'; - } - - // then the rest - for (ArgListIterator it = argList.begin(); it != argList.end(); it++) - if ( !xorHandler.contains( (*it) ) ) - s += " " + (*it)->shortID(); - - // if the program name is too long, then adjust the second line offset - int secondLineOffset = static_cast(progName.length()) + 2; - if ( secondLineOffset > 75/2 ) - secondLineOffset = static_cast(75/2); - - spacePrint( os, s, 75, 3, secondLineOffset ); -} - -inline void -StdOutput::_longUsage( CmdLineInterface& _cmd, - std::ostream& os ) const -{ - std::list argList = _cmd.getArgList(); - std::string message = _cmd.getMessage(); - XorHandler xorHandler = _cmd.getXorHandler(); - std::vector< std::vector > xorList = xorHandler.getXorList(); - - // first the xor - for ( int i = 0; static_cast(i) < xorList.size(); i++ ) - { - for ( ArgVectorIterator it = xorList[i].begin(); - it != xorList[i].end(); - it++ ) - { - spacePrint( os, (*it)->longID(), 75, 3, 3 ); - spacePrint( os, (*it)->getDescription(), 75, 5, 0 ); - - if ( it+1 != xorList[i].end() ) - spacePrint(os, "-- OR --", 75, 9, 0); - } - os << std::endl << std::endl; - } - - // then the rest - for (ArgListIterator it = argList.begin(); it != argList.end(); it++) - if ( !xorHandler.contains( (*it) ) ) - { - spacePrint( os, (*it)->longID(), 75, 3, 3 ); - spacePrint( os, (*it)->getDescription(), 75, 5, 0 ); - os << std::endl; - } - - os << std::endl; - - spacePrint( os, message, 75, 3, 0 ); -} - -inline void StdOutput::spacePrint( std::ostream& os, - const std::string& s, - int maxWidth, - int indentSpaces, - int secondLineOffset ) const -{ - int len = static_cast(s.length()); - - if ( (len + indentSpaces > maxWidth) && maxWidth > 0 ) - { - int allowedLen = maxWidth - indentSpaces; - int start = 0; - while ( start < len ) - { - // find the substring length - // int stringLen = std::min( len - start, allowedLen ); - // doing it this way to support a VisualC++ 2005 bug - using namespace std; - int stringLen = min( len - start, allowedLen ); - - // trim the length so it doesn't end in middle of a word - if ( stringLen == allowedLen ) - while ( stringLen >= 0 && - s[stringLen+start] != ' ' && - s[stringLen+start] != ',' && - s[stringLen+start] != '|' ) - stringLen--; - - // ok, the word is longer than the line, so just split - // wherever the line ends - if ( stringLen <= 0 ) - stringLen = allowedLen; - - // check for newlines - for ( int i = 0; i < stringLen; i++ ) - if ( s[start+i] == '\n' ) - stringLen = i+1; - - // print the indent - for ( int i = 0; i < indentSpaces; i++ ) - os << " "; - - if ( start == 0 ) - { - // handle second line offsets - indentSpaces += secondLineOffset; - - // adjust allowed len - allowedLen -= secondLineOffset; - } - - os << s.substr(start,stringLen) << std::endl; - - // so we don't start a line with a space - while ( s[stringLen+start] == ' ' && start < len ) - start++; - - start += stringLen; - } - } - else - { - for ( int i = 0; i < indentSpaces; i++ ) - os << " "; - os << s << std::endl; - } -} - -} //namespace TCLAP -#endif diff --git a/src/tclap/SwitchArg.h b/src/tclap/SwitchArg.h deleted file mode 100644 index 3916109069..0000000000 --- a/src/tclap/SwitchArg.h +++ /dev/null @@ -1,266 +0,0 @@ - -/****************************************************************************** - * - * file: SwitchArg.h - * - * Copyright (c) 2003, Michael E. Smoot . - * Copyright (c) 2004, Michael E. Smoot, Daniel Aarno. - * All rights reverved. - * - * See the file COPYING in the top directory of this distribution for - * more information. - * - * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - *****************************************************************************/ - - -#ifndef TCLAP_SWITCH_ARG_H -#define TCLAP_SWITCH_ARG_H - -#include -#include - -#include - -namespace TCLAP { - -/** - * A simple switch argument. If the switch is set on the command line, then - * the getValue method will return the opposite of the default value for the - * switch. - */ -class SwitchArg : public Arg -{ - protected: - - /** - * The value of the switch. - */ - bool _value; - - /** - * Used to support the reset() method so that ValueArg can be - * reset to their constructed value. - */ - bool _default; - - public: - - /** - * SwitchArg constructor. - * \param flag - The one character flag that identifies this - * argument on the command line. - * \param name - A one word name for the argument. Can be - * used as a long flag on the command line. - * \param desc - A description of what the argument is for or - * does. - * \param def - The default value for this Switch. - * \param v - An optional visitor. You probably should not - * use this unless you have a very good reason. - */ - SwitchArg(const std::string& flag, - const std::string& name, - const std::string& desc, - bool def = false, - Visitor* v = NULL); - - - /** - * SwitchArg constructor. - * \param flag - The one character flag that identifies this - * argument on the command line. - * \param name - A one word name for the argument. Can be - * used as a long flag on the command line. - * \param desc - A description of what the argument is for or - * does. - * \param parser - A CmdLine parser object to add this Arg to - * \param def - The default value for this Switch. - * \param v - An optional visitor. You probably should not - * use this unless you have a very good reason. - */ - SwitchArg(const std::string& flag, - const std::string& name, - const std::string& desc, - CmdLineInterface& parser, - bool def = false, - Visitor* v = NULL); - - - /** - * Handles the processing of the argument. - * This re-implements the Arg version of this method to set the - * _value of the argument appropriately. - * \param i - Pointer the the current argument in the list. - * \param args - Mutable list of strings. Passed - * in from main(). - */ - virtual bool processArg(int* i, std::vector& args); - - /** - * Checks a string to see if any of the chars in the string - * match the flag for this Switch. - */ - bool combinedSwitchesMatch(std::string& combined); - - /** - * Returns bool, whether or not the switch has been set. - */ - bool getValue(); - - virtual void reset(); - - private: - /** - * Checks to see if we've found the last match in - * a combined string. - */ - bool lastCombined(std::string& combined); - - /** - * Does the common processing of processArg. - */ - void commonProcessing(); -}; - -////////////////////////////////////////////////////////////////////// -//BEGIN SwitchArg.cpp -////////////////////////////////////////////////////////////////////// -inline SwitchArg::SwitchArg(const std::string& flag, - const std::string& name, - const std::string& desc, - bool default_val, - Visitor* v ) -: Arg(flag, name, desc, false, false, v), - _value( default_val ), - _default( default_val ) -{ } - -inline SwitchArg::SwitchArg(const std::string& flag, - const std::string& name, - const std::string& desc, - CmdLineInterface& parser, - bool default_val, - Visitor* v ) -: Arg(flag, name, desc, false, false, v), - _value( default_val ), - _default(default_val) -{ - parser.add( this ); -} - -inline bool SwitchArg::getValue() { return _value; } - -inline bool SwitchArg::lastCombined(std::string& combinedSwitches ) -{ - for ( unsigned int i = 1; i < combinedSwitches.length(); i++ ) - if ( combinedSwitches[i] != Arg::blankChar() ) - return false; - - return true; -} - -inline bool SwitchArg::combinedSwitchesMatch(std::string& combinedSwitches ) -{ - // make sure this is actually a combined switch - if ( combinedSwitches.length() > 0 && - combinedSwitches[0] != Arg::flagStartString()[0] ) - return false; - - // make sure it isn't a long name - if ( combinedSwitches.substr( 0, Arg::nameStartString().length() ) == - Arg::nameStartString() ) - return false; - - // make sure the delimiter isn't in the string - if ( combinedSwitches.find_first_of( Arg::delimiter() ) != std::string::npos ) - return false; - - // ok, we're not specifying a ValueArg, so we know that we have - // a combined switch list. - for ( unsigned int i = 1; i < combinedSwitches.length(); i++ ) - if ( _flag.length() > 0 && - combinedSwitches[i] == _flag[0] && - _flag[0] != Arg::flagStartString()[0] ) - { - // update the combined switches so this one is no longer present - // this is necessary so that no unlabeled args are matched - // later in the processing. - //combinedSwitches.erase(i,1); - combinedSwitches[i] = Arg::blankChar(); - return true; - } - - // none of the switches passed in the list match. - return false; -} - -inline void SwitchArg::commonProcessing() -{ - if ( _xorSet ) - throw(CmdLineParseException( - "Mutually exclusive argument already set!", toString())); - - if ( _alreadySet ) - throw(CmdLineParseException("Argument already set!", toString())); - - _alreadySet = true; - - if ( _value == true ) - _value = false; - else - _value = true; - - _checkWithVisitor(); -} - -inline bool SwitchArg::processArg(int *i, std::vector& args) -{ - if ( _ignoreable && Arg::ignoreRest() ) - return false; - - // if the whole string matches the flag or name string - if ( argMatches( args[*i] ) ) - { - commonProcessing(); - - return true; - } - // if a substring matches the flag as part of a combination - else if ( combinedSwitchesMatch( args[*i] ) ) - { - // check again to ensure we don't misinterpret - // this as a MultiSwitchArg - if ( combinedSwitchesMatch( args[*i] ) ) - throw(CmdLineParseException("Argument already set!", - toString())); - - commonProcessing(); - - // We only want to return true if we've found the last combined - // match in the string, otherwise we return true so that other - // switches in the combination will have a chance to match. - return lastCombined( args[*i] ); - } - else - return false; -} - -inline void SwitchArg::reset() -{ - Arg::reset(); - _value = _default; -} -////////////////////////////////////////////////////////////////////// -//End SwitchArg.cpp -////////////////////////////////////////////////////////////////////// - -} //namespace TCLAP - -#endif diff --git a/src/tclap/UnlabeledMultiArg.h b/src/tclap/UnlabeledMultiArg.h deleted file mode 100644 index d5e1781060..0000000000 --- a/src/tclap/UnlabeledMultiArg.h +++ /dev/null @@ -1,301 +0,0 @@ - -/****************************************************************************** - * - * file: UnlabeledMultiArg.h - * - * Copyright (c) 2003, Michael E. Smoot. - * All rights reverved. - * - * See the file COPYING in the top directory of this distribution for - * more information. - * - * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - *****************************************************************************/ - - -#ifndef TCLAP_MULTIPLE_UNLABELED_ARGUMENT_H -#define TCLAP_MULTIPLE_UNLABELED_ARGUMENT_H - -#include -#include - -#include -#include - -namespace TCLAP { - -/** - * Just like a MultiArg, except that the arguments are unlabeled. Basically, - * this Arg will slurp up everything that hasn't been matched to another - * Arg. - */ -template -class UnlabeledMultiArg : public MultiArg -{ - - // If compiler has two stage name lookup (as gcc >= 3.4 does) - // this is requried to prevent undef. symbols - using MultiArg::_ignoreable; - using MultiArg::_hasBlanks; - using MultiArg::_extractValue; - using MultiArg::_typeDesc; - using MultiArg::_name; - using MultiArg::_description; - using MultiArg::_alreadySet; - using MultiArg::toString; - - public: - - /** - * Constructor. - * \param name - The name of the Arg. Note that this is used for - * identification, not as a long flag. - * \param desc - A description of what the argument is for or - * does. - * \param req - Whether the argument is required on the command - * line. - * \param typeDesc - A short, human readable description of the - * type that this object expects. This is used in the generation - * of the USAGE statement. The goal is to be helpful to the end user - * of the program. - * \param ignoreable - Whether or not this argument can be ignored - * using the "--" flag. - * \param v - An optional visitor. You probably should not - * use this unless you have a very good reason. - */ - UnlabeledMultiArg( const std::string& name, - const std::string& desc, - bool req, - const std::string& typeDesc, - bool ignoreable = false, - Visitor* v = NULL ); - /** - * Constructor. - * \param name - The name of the Arg. Note that this is used for - * identification, not as a long flag. - * \param desc - A description of what the argument is for or - * does. - * \param req - Whether the argument is required on the command - * line. - * \param typeDesc - A short, human readable description of the - * type that this object expects. This is used in the generation - * of the USAGE statement. The goal is to be helpful to the end user - * of the program. - * \param parser - A CmdLine parser object to add this Arg to - * \param ignoreable - Whether or not this argument can be ignored - * using the "--" flag. - * \param v - An optional visitor. You probably should not - * use this unless you have a very good reason. - */ - UnlabeledMultiArg( const std::string& name, - const std::string& desc, - bool req, - const std::string& typeDesc, - CmdLineInterface& parser, - bool ignoreable = false, - Visitor* v = NULL ); - - /** - * Constructor. - * \param name - The name of the Arg. Note that this is used for - * identification, not as a long flag. - * \param desc - A description of what the argument is for or - * does. - * \param req - Whether the argument is required on the command - * line. - * \param constraint - A pointer to a Constraint object used - * to constrain this Arg. - * \param ignoreable - Whether or not this argument can be ignored - * using the "--" flag. - * \param v - An optional visitor. You probably should not - * use this unless you have a very good reason. - */ - UnlabeledMultiArg( const std::string& name, - const std::string& desc, - bool req, - Constraint* constraint, - bool ignoreable = false, - Visitor* v = NULL ); - - /** - * Constructor. - * \param name - The name of the Arg. Note that this is used for - * identification, not as a long flag. - * \param desc - A description of what the argument is for or - * does. - * \param req - Whether the argument is required on the command - * line. - * \param constraint - A pointer to a Constraint object used - * to constrain this Arg. - * \param parser - A CmdLine parser object to add this Arg to - * \param ignoreable - Whether or not this argument can be ignored - * using the "--" flag. - * \param v - An optional visitor. You probably should not - * use this unless you have a very good reason. - */ - UnlabeledMultiArg( const std::string& name, - const std::string& desc, - bool req, - Constraint* constraint, - CmdLineInterface& parser, - bool ignoreable = false, - Visitor* v = NULL ); - - /** - * Handles the processing of the argument. - * This re-implements the Arg version of this method to set the - * _value of the argument appropriately. It knows the difference - * between labeled and unlabeled. - * \param i - Pointer the the current argument in the list. - * \param args - Mutable list of strings. Passed from main(). - */ - virtual bool processArg(int* i, std::vector& args); - - /** - * Returns the a short id string. Used in the usage. - * \param val - value to be used. - */ - virtual std::string shortID(const std::string& val="val") const; - - /** - * Returns the a long id string. Used in the usage. - * \param val - value to be used. - */ - virtual std::string longID(const std::string& val="val") const; - - /** - * Opertor ==. - * \param a - The Arg to be compared to this. - */ - virtual bool operator==(const Arg& a) const; - - /** - * Pushes this to back of list rather than front. - * \param argList - The list this should be added to. - */ - virtual void addToList( std::list& argList ) const; -}; - -template -UnlabeledMultiArg::UnlabeledMultiArg(const std::string& name, - const std::string& desc, - bool req, - const std::string& typeDesc, - bool ignoreable, - Visitor* v) -: MultiArg("", name, desc, req, typeDesc, v) -{ - _ignoreable = ignoreable; - OptionalUnlabeledTracker::check(true, toString()); -} - -template -UnlabeledMultiArg::UnlabeledMultiArg(const std::string& name, - const std::string& desc, - bool req, - const std::string& typeDesc, - CmdLineInterface& parser, - bool ignoreable, - Visitor* v) -: MultiArg("", name, desc, req, typeDesc, v) -{ - _ignoreable = ignoreable; - OptionalUnlabeledTracker::check(true, toString()); - parser.add( this ); -} - - -template -UnlabeledMultiArg::UnlabeledMultiArg(const std::string& name, - const std::string& desc, - bool req, - Constraint* constraint, - bool ignoreable, - Visitor* v) -: MultiArg("", name, desc, req, constraint, v) -{ - _ignoreable = ignoreable; - OptionalUnlabeledTracker::check(true, toString()); -} - -template -UnlabeledMultiArg::UnlabeledMultiArg(const std::string& name, - const std::string& desc, - bool req, - Constraint* constraint, - CmdLineInterface& parser, - bool ignoreable, - Visitor* v) -: MultiArg("", name, desc, req, constraint, v) -{ - _ignoreable = ignoreable; - OptionalUnlabeledTracker::check(true, toString()); - parser.add( this ); -} - - -template -bool UnlabeledMultiArg::processArg(int *i, std::vector& args) -{ - - if ( _hasBlanks( args[*i] ) ) - return false; - - // never ignore an unlabeled multi arg - - - // always take the first value, regardless of the start string - _extractValue( args[(*i)] ); - - /* - // continue taking args until we hit the end or a start string - while ( (unsigned int)(*i)+1 < args.size() && - args[(*i)+1].find_first_of( Arg::flagStartString() ) != 0 && - args[(*i)+1].find_first_of( Arg::nameStartString() ) != 0 ) - _extractValue( args[++(*i)] ); - */ - - _alreadySet = true; - - return true; -} - -template -std::string UnlabeledMultiArg::shortID(const std::string& val) const -{ - static_cast(val); // Ignore input, don't warn - return std::string("<") + _typeDesc + "> ..."; -} - -template -std::string UnlabeledMultiArg::longID(const std::string& val) const -{ - static_cast(val); // Ignore input, don't warn - return std::string("<") + _typeDesc + "> (accepted multiple times)"; -} - -template -bool UnlabeledMultiArg::operator==(const Arg& a) const -{ - if ( _name == a.getName() || _description == a.getDescription() ) - return true; - else - return false; -} - -template -void UnlabeledMultiArg::addToList( std::list& argList ) const -{ - argList.push_back( const_cast(static_cast(this)) ); -} - -} - -#endif diff --git a/src/tclap/UnlabeledValueArg.h b/src/tclap/UnlabeledValueArg.h deleted file mode 100644 index 5721d61252..0000000000 --- a/src/tclap/UnlabeledValueArg.h +++ /dev/null @@ -1,340 +0,0 @@ - -/****************************************************************************** - * - * file: UnlabeledValueArg.h - * - * Copyright (c) 2003, Michael E. Smoot . - * Copyright (c) 2004, Michael E. Smoot, Daniel Aarno. - * All rights reverved. - * - * See the file COPYING in the top directory of this distribution for - * more information. - * - * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - *****************************************************************************/ - - -#ifndef TCLAP_UNLABELED_VALUE_ARGUMENT_H -#define TCLAP_UNLABELED_VALUE_ARGUMENT_H - -#include -#include - -#include -#include - - -namespace TCLAP { - -/** - * The basic unlabeled argument that parses a value. - * This is a template class, which means the type T defines the type - * that a given object will attempt to parse when an UnlabeledValueArg - * is reached in the list of args that the CmdLine iterates over. - */ -template -class UnlabeledValueArg : public ValueArg -{ - - // If compiler has two stage name lookup (as gcc >= 3.4 does) - // this is requried to prevent undef. symbols - using ValueArg::_ignoreable; - using ValueArg::_hasBlanks; - using ValueArg::_extractValue; - using ValueArg::_typeDesc; - using ValueArg::_name; - using ValueArg::_description; - using ValueArg::_alreadySet; - using ValueArg::toString; - - public: - - /** - * UnlabeledValueArg constructor. - * \param name - A one word name for the argument. Note that this is used for - * identification, not as a long flag. - * \param desc - A description of what the argument is for or - * does. - * \param req - Whether the argument is required on the command - * line. - * \param value - The default value assigned to this argument if it - * is not present on the command line. - * \param typeDesc - A short, human readable description of the - * type that this object expects. This is used in the generation - * of the USAGE statement. The goal is to be helpful to the end user - * of the program. - * \param ignoreable - Allows you to specify that this argument can be - * ignored if the '--' flag is set. This defaults to false (cannot - * be ignored) and should generally stay that way unless you have - * some special need for certain arguments to be ignored. - * \param v - Optional Vistor. You should leave this blank unless - * you have a very good reason. - */ - UnlabeledValueArg( const std::string& name, - const std::string& desc, - bool req, - T value, - const std::string& typeDesc, - bool ignoreable = false, - Visitor* v = NULL); - - /** - * UnlabeledValueArg constructor. - * \param name - A one word name for the argument. Note that this is used for - * identification, not as a long flag. - * \param desc - A description of what the argument is for or - * does. - * \param req - Whether the argument is required on the command - * line. - * \param value - The default value assigned to this argument if it - * is not present on the command line. - * \param typeDesc - A short, human readable description of the - * type that this object expects. This is used in the generation - * of the USAGE statement. The goal is to be helpful to the end user - * of the program. - * \param parser - A CmdLine parser object to add this Arg to - * \param ignoreable - Allows you to specify that this argument can be - * ignored if the '--' flag is set. This defaults to false (cannot - * be ignored) and should generally stay that way unless you have - * some special need for certain arguments to be ignored. - * \param v - Optional Vistor. You should leave this blank unless - * you have a very good reason. - */ - UnlabeledValueArg( const std::string& name, - const std::string& desc, - bool req, - T value, - const std::string& typeDesc, - CmdLineInterface& parser, - bool ignoreable = false, - Visitor* v = NULL ); - - /** - * UnlabeledValueArg constructor. - * \param name - A one word name for the argument. Note that this is used for - * identification, not as a long flag. - * \param desc - A description of what the argument is for or - * does. - * \param req - Whether the argument is required on the command - * line. - * \param value - The default value assigned to this argument if it - * is not present on the command line. - * \param constraint - A pointer to a Constraint object used - * to constrain this Arg. - * \param ignoreable - Allows you to specify that this argument can be - * ignored if the '--' flag is set. This defaults to false (cannot - * be ignored) and should generally stay that way unless you have - * some special need for certain arguments to be ignored. - * \param v - Optional Vistor. You should leave this blank unless - * you have a very good reason. - */ - UnlabeledValueArg( const std::string& name, - const std::string& desc, - bool req, - T value, - Constraint* constraint, - bool ignoreable = false, - Visitor* v = NULL ); - - - /** - * UnlabeledValueArg constructor. - * \param name - A one word name for the argument. Note that this is used for - * identification, not as a long flag. - * \param desc - A description of what the argument is for or - * does. - * \param req - Whether the argument is required on the command - * line. - * \param value - The default value assigned to this argument if it - * is not present on the command line. - * \param constraint - A pointer to a Constraint object used - * to constrain this Arg. - * \param parser - A CmdLine parser object to add this Arg to - * \param ignoreable - Allows you to specify that this argument can be - * ignored if the '--' flag is set. This defaults to false (cannot - * be ignored) and should generally stay that way unless you have - * some special need for certain arguments to be ignored. - * \param v - Optional Vistor. You should leave this blank unless - * you have a very good reason. - */ - UnlabeledValueArg( const std::string& name, - const std::string& desc, - bool req, - T value, - Constraint* constraint, - CmdLineInterface& parser, - bool ignoreable = false, - Visitor* v = NULL); - - /** - * Handles the processing of the argument. - * This re-implements the Arg version of this method to set the - * _value of the argument appropriately. Handling specific to - * unlabled arguments. - * \param i - Pointer the the current argument in the list. - * \param args - Mutable list of strings. - */ - virtual bool processArg(int* i, std::vector& args); - - /** - * Overrides shortID for specific behavior. - */ - virtual std::string shortID(const std::string& val="val") const; - - /** - * Overrides longID for specific behavior. - */ - virtual std::string longID(const std::string& val="val") const; - - /** - * Overrides operator== for specific behavior. - */ - virtual bool operator==(const Arg& a ) const; - - /** - * Instead of pushing to the front of list, push to the back. - * \param argList - The list to add this to. - */ - virtual void addToList( std::list& argList ) const; - -}; - -/** - * Constructor implemenation. - */ -template -UnlabeledValueArg::UnlabeledValueArg(const std::string& name, - const std::string& desc, - bool req, - T val, - const std::string& typeDesc, - bool ignoreable, - Visitor* v) -: ValueArg("", name, desc, req, val, typeDesc, v) -{ - _ignoreable = ignoreable; - - OptionalUnlabeledTracker::check(req, toString()); - -} - -template -UnlabeledValueArg::UnlabeledValueArg(const std::string& name, - const std::string& desc, - bool req, - T val, - const std::string& typeDesc, - CmdLineInterface& parser, - bool ignoreable, - Visitor* v) -: ValueArg("", name, desc, req, val, typeDesc, v) -{ - _ignoreable = ignoreable; - OptionalUnlabeledTracker::check(req, toString()); - parser.add( this ); -} - -/** - * Constructor implemenation. - */ -template -UnlabeledValueArg::UnlabeledValueArg(const std::string& name, - const std::string& desc, - bool req, - T val, - Constraint* constraint, - bool ignoreable, - Visitor* v) -: ValueArg("", name, desc, req, val, constraint, v) -{ - _ignoreable = ignoreable; - OptionalUnlabeledTracker::check(req, toString()); -} - -template -UnlabeledValueArg::UnlabeledValueArg(const std::string& name, - const std::string& desc, - bool req, - T val, - Constraint* constraint, - CmdLineInterface& parser, - bool ignoreable, - Visitor* v) -: ValueArg("", name, desc, req, val, constraint, v) -{ - _ignoreable = ignoreable; - OptionalUnlabeledTracker::check(req, toString()); - parser.add( this ); -} - -/** - * Implementation of processArg(). - */ -template -bool UnlabeledValueArg::processArg(int *i, std::vector& args) -{ - - if ( _alreadySet ) - return false; - - if ( _hasBlanks( args[*i] ) ) - return false; - - // never ignore an unlabeled arg - - _extractValue( args[*i] ); - _alreadySet = true; - return true; -} - -/** - * Overriding shortID for specific output. - */ -template -std::string UnlabeledValueArg::shortID(const std::string& val) const -{ - static_cast(val); // Ignore input, don't warn - return std::string("<") + _typeDesc + ">"; -} - -/** - * Overriding longID for specific output. - */ -template -std::string UnlabeledValueArg::longID(const std::string& val) const -{ - static_cast(val); // Ignore input, don't warn - - // Ideally we would like to be able to use RTTI to return the name - // of the type required for this argument. However, g++ at least, - // doesn't appear to return terribly useful "names" of the types. - return std::string("<") + _typeDesc + ">"; -} - -/** - * Overriding operator== for specific behavior. - */ -template -bool UnlabeledValueArg::operator==(const Arg& a ) const -{ - if ( _name == a.getName() || _description == a.getDescription() ) - return true; - else - return false; -} - -template -void UnlabeledValueArg::addToList( std::list& argList ) const -{ - argList.push_back( const_cast(static_cast(this)) ); -} - -} -#endif diff --git a/src/tclap/ValueArg.h b/src/tclap/ValueArg.h deleted file mode 100644 index 7ac29526b9..0000000000 --- a/src/tclap/ValueArg.h +++ /dev/null @@ -1,425 +0,0 @@ -/****************************************************************************** - * - * file: ValueArg.h - * - * Copyright (c) 2003, Michael E. Smoot . - * Copyright (c) 2004, Michael E. Smoot, Daniel Aarno. - * All rights reverved. - * - * See the file COPYING in the top directory of this distribution for - * more information. - * - * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - *****************************************************************************/ - - -#ifndef TCLAP_VALUE_ARGUMENT_H -#define TCLAP_VALUE_ARGUMENT_H - -#include -#include - -#include -#include - -namespace TCLAP { - -/** - * The basic labeled argument that parses a value. - * This is a template class, which means the type T defines the type - * that a given object will attempt to parse when the flag/name is matched - * on the command line. While there is nothing stopping you from creating - * an unflagged ValueArg, it is unwise and would cause significant problems. - * Instead use an UnlabeledValueArg. - */ -template -class ValueArg : public Arg -{ - protected: - - /** - * The value parsed from the command line. - * Can be of any type, as long as the >> operator for the type - * is defined. - */ - T _value; - - /** - * Used to support the reset() method so that ValueArg can be - * reset to their constructed value. - */ - T _default; - - /** - * A human readable description of the type to be parsed. - * This is a hack, plain and simple. Ideally we would use RTTI to - * return the name of type T, but until there is some sort of - * consistent support for human readable names, we are left to our - * own devices. - */ - std::string _typeDesc; - - /** - * A Constraint this Arg must conform to. - */ - Constraint* _constraint; - - /** - * Extracts the value from the string. - * Attempts to parse string as type T, if this fails an exception - * is thrown. - * \param val - value to be parsed. - */ - void _extractValue( const std::string& val ); - - public: - - /** - * Labeled ValueArg constructor. - * You could conceivably call this constructor with a blank flag, - * but that would make you a bad person. It would also cause - * an exception to be thrown. If you want an unlabeled argument, - * use the other constructor. - * \param flag - The one character flag that identifies this - * argument on the command line. - * \param name - A one word name for the argument. Can be - * used as a long flag on the command line. - * \param desc - A description of what the argument is for or - * does. - * \param req - Whether the argument is required on the command - * line. - * \param value - The default value assigned to this argument if it - * is not present on the command line. - * \param typeDesc - A short, human readable description of the - * type that this object expects. This is used in the generation - * of the USAGE statement. The goal is to be helpful to the end user - * of the program. - * \param v - An optional visitor. You probably should not - * use this unless you have a very good reason. - */ - ValueArg( const std::string& flag, - const std::string& name, - const std::string& desc, - bool req, - T value, - const std::string& typeDesc, - Visitor* v = NULL); - - - /** - * Labeled ValueArg constructor. - * You could conceivably call this constructor with a blank flag, - * but that would make you a bad person. It would also cause - * an exception to be thrown. If you want an unlabeled argument, - * use the other constructor. - * \param flag - The one character flag that identifies this - * argument on the command line. - * \param name - A one word name for the argument. Can be - * used as a long flag on the command line. - * \param desc - A description of what the argument is for or - * does. - * \param req - Whether the argument is required on the command - * line. - * \param value - The default value assigned to this argument if it - * is not present on the command line. - * \param typeDesc - A short, human readable description of the - * type that this object expects. This is used in the generation - * of the USAGE statement. The goal is to be helpful to the end user - * of the program. - * \param parser - A CmdLine parser object to add this Arg to - * \param v - An optional visitor. You probably should not - * use this unless you have a very good reason. - */ - ValueArg( const std::string& flag, - const std::string& name, - const std::string& desc, - bool req, - T value, - const std::string& typeDesc, - CmdLineInterface& parser, - Visitor* v = NULL ); - - /** - * Labeled ValueArg constructor. - * You could conceivably call this constructor with a blank flag, - * but that would make you a bad person. It would also cause - * an exception to be thrown. If you want an unlabeled argument, - * use the other constructor. - * \param flag - The one character flag that identifies this - * argument on the command line. - * \param name - A one word name for the argument. Can be - * used as a long flag on the command line. - * \param desc - A description of what the argument is for or - * does. - * \param req - Whether the argument is required on the command - * line. - * \param value - The default value assigned to this argument if it - * is not present on the command line. - * \param constraint - A pointer to a Constraint object used - * to constrain this Arg. - * \param parser - A CmdLine parser object to add this Arg to. - * \param v - An optional visitor. You probably should not - * use this unless you have a very good reason. - */ - ValueArg( const std::string& flag, - const std::string& name, - const std::string& desc, - bool req, - T value, - Constraint* constraint, - CmdLineInterface& parser, - Visitor* v = NULL ); - - /** - * Labeled ValueArg constructor. - * You could conceivably call this constructor with a blank flag, - * but that would make you a bad person. It would also cause - * an exception to be thrown. If you want an unlabeled argument, - * use the other constructor. - * \param flag - The one character flag that identifies this - * argument on the command line. - * \param name - A one word name for the argument. Can be - * used as a long flag on the command line. - * \param desc - A description of what the argument is for or - * does. - * \param req - Whether the argument is required on the command - * line. - * \param value - The default value assigned to this argument if it - * is not present on the command line. - * \param constraint - A pointer to a Constraint object used - * to constrain this Arg. - * \param v - An optional visitor. You probably should not - * use this unless you have a very good reason. - */ - ValueArg( const std::string& flag, - const std::string& name, - const std::string& desc, - bool req, - T value, - Constraint* constraint, - Visitor* v = NULL ); - - /** - * Handles the processing of the argument. - * This re-implements the Arg version of this method to set the - * _value of the argument appropriately. It knows the difference - * between labeled and unlabeled. - * \param i - Pointer the the current argument in the list. - * \param args - Mutable list of strings. Passed - * in from main(). - */ - virtual bool processArg(int* i, std::vector& args); - - /** - * Returns the value of the argument. - */ - T& getValue() ; - - /** - * Specialization of shortID. - * \param val - value to be used. - */ - virtual std::string shortID(const std::string& val = "val") const; - - /** - * Specialization of longID. - * \param val - value to be used. - */ - virtual std::string longID(const std::string& val = "val") const; - - virtual void reset() ; - -private: - /** - * Prevent accidental copying - */ - ValueArg(const ValueArg& rhs); - ValueArg& operator=(const ValueArg& rhs); -}; - - -/** - * Constructor implementation. - */ -template -ValueArg::ValueArg(const std::string& flag, - const std::string& name, - const std::string& desc, - bool req, - T val, - const std::string& typeDesc, - Visitor* v) -: Arg(flag, name, desc, req, true, v), - _value( val ), - _default( val ), - _typeDesc( typeDesc ), - _constraint( NULL ) -{ } - -template -ValueArg::ValueArg(const std::string& flag, - const std::string& name, - const std::string& desc, - bool req, - T val, - const std::string& typeDesc, - CmdLineInterface& parser, - Visitor* v) -: Arg(flag, name, desc, req, true, v), - _value( val ), - _default( val ), - _typeDesc( typeDesc ), - _constraint( NULL ) -{ - parser.add( this ); -} - -template -ValueArg::ValueArg(const std::string& flag, - const std::string& name, - const std::string& desc, - bool req, - T val, - Constraint* constraint, - Visitor* v) -: Arg(flag, name, desc, req, true, v), - _value( val ), - _default( val ), - _typeDesc( constraint->shortID() ), - _constraint( constraint ) -{ } - -template -ValueArg::ValueArg(const std::string& flag, - const std::string& name, - const std::string& desc, - bool req, - T val, - Constraint* constraint, - CmdLineInterface& parser, - Visitor* v) -: Arg(flag, name, desc, req, true, v), - _value( val ), - _default( val ), - _typeDesc( constraint->shortID() ), - _constraint( constraint ) -{ - parser.add( this ); -} - - -/** - * Implementation of getValue(). - */ -template -T& ValueArg::getValue() { return _value; } - -/** - * Implementation of processArg(). - */ -template -bool ValueArg::processArg(int *i, std::vector& args) -{ - if ( _ignoreable && Arg::ignoreRest() ) - return false; - - if ( _hasBlanks( args[*i] ) ) - return false; - - std::string flag = args[*i]; - - std::string value = ""; - trimFlag( flag, value ); - - if ( argMatches( flag ) ) - { - if ( _alreadySet ) - { - if ( _xorSet ) - throw( CmdLineParseException( - "Mutually exclusive argument already set!", - toString()) ); - else - throw( CmdLineParseException("Argument already set!", - toString()) ); - } - - if ( Arg::delimiter() != ' ' && value == "" ) - throw( ArgParseException( - "Couldn't find delimiter for this argument!", - toString() ) ); - - if ( value == "" ) - { - (*i)++; - if ( static_cast(*i) < args.size() ) - _extractValue( args[*i] ); - else - throw( ArgParseException("Missing a value for this argument!", - toString() ) ); - } - else - _extractValue( value ); - - _alreadySet = true; - _checkWithVisitor(); - return true; - } - else - return false; -} - -/** - * Implementation of shortID. - */ -template -std::string ValueArg::shortID(const std::string& val) const -{ - static_cast(val); // Ignore input, don't warn - return Arg::shortID( _typeDesc ); -} - -/** - * Implementation of longID. - */ -template -std::string ValueArg::longID(const std::string& val) const -{ - static_cast(val); // Ignore input, don't warn - return Arg::longID( _typeDesc ); -} - -template -void ValueArg::_extractValue( const std::string& val ) -{ - try { - ExtractValue(_value, val, typename ArgTraits::ValueCategory()); - } catch( ArgParseException &e) { - throw ArgParseException(e.error(), toString()); - } - - if ( _constraint != NULL ) - if ( ! _constraint->check( _value ) ) - throw( CmdLineParseException( "Value '" + val + - + "' does not meet constraint: " - + _constraint->description(), - toString() ) ); -} - -template -void ValueArg::reset() -{ - Arg::reset(); - _value = _default; -} - -} // namespace TCLAP - -#endif diff --git a/src/tclap/ValuesConstraint.h b/src/tclap/ValuesConstraint.h deleted file mode 100644 index cb41f645e5..0000000000 --- a/src/tclap/ValuesConstraint.h +++ /dev/null @@ -1,148 +0,0 @@ - - -/****************************************************************************** - * - * file: ValuesConstraint.h - * - * Copyright (c) 2005, Michael E. Smoot - * All rights reverved. - * - * See the file COPYING in the top directory of this distribution for - * more information. - * - * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - *****************************************************************************/ - -#ifndef TCLAP_VALUESCONSTRAINT_H -#define TCLAP_VALUESCONSTRAINT_H - -#include -#include -#include - -#ifdef HAVE_CONFIG_H -#include -#else -#define HAVE_SSTREAM -#endif - -#if defined(HAVE_SSTREAM) -#include -#elif defined(HAVE_STRSTREAM) -#include -#else -#error "Need a stringstream (sstream or strstream) to compile!" -#endif - -namespace TCLAP { - -/** - * A Constraint that constrains the Arg to only those values specified - * in the constraint. - */ -template -class ValuesConstraint : public Constraint -{ - - public: - - /** - * Constructor. - * \param allowed - vector of allowed values. - */ - ValuesConstraint(std::vector& allowed); - - /** - * Virtual destructor. - */ - virtual ~ValuesConstraint() {} - - /** - * Returns a description of the Constraint. - */ - virtual std::string description() const; - - /** - * Returns the short ID for the Constraint. - */ - virtual std::string shortID() const; - - /** - * The method used to verify that the value parsed from the command - * line meets the constraint. - * \param value - The value that will be checked. - */ - virtual bool check(const T& value) const; - - protected: - - /** - * The list of valid values. - */ - std::vector _allowed; - - /** - * The string used to describe the allowed values of this constraint. - */ - std::string _typeDesc; - -}; - -template -ValuesConstraint::ValuesConstraint(std::vector& allowed) -: _allowed(allowed), - _typeDesc("") -{ - for ( unsigned int i = 0; i < _allowed.size(); i++ ) - { - -#if defined(HAVE_SSTREAM) - std::ostringstream os; -#elif defined(HAVE_STRSTREAM) - std::ostrstream os; -#else -#error "Need a stringstream (sstream or strstream) to compile!" -#endif - - os << _allowed[i]; - - std::string temp( os.str() ); - - if ( i > 0 ) - _typeDesc += "|"; - _typeDesc += temp; - } -} - -template -bool ValuesConstraint::check( const T& val ) const -{ - if ( std::find(_allowed.begin(),_allowed.end(),val) == _allowed.end() ) - return false; - else - return true; -} - -template -std::string ValuesConstraint::shortID() const -{ - return _typeDesc; -} - -template -std::string ValuesConstraint::description() const -{ - return _typeDesc; -} - - -} //namespace TCLAP -#endif - diff --git a/src/tclap/VersionVisitor.h b/src/tclap/VersionVisitor.h deleted file mode 100644 index c110d4fa00..0000000000 --- a/src/tclap/VersionVisitor.h +++ /dev/null @@ -1,81 +0,0 @@ -// -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*- - -/****************************************************************************** - * - * file: VersionVisitor.h - * - * Copyright (c) 2003, Michael E. Smoot . - * All rights reverved. - * - * See the file COPYING in the top directory of this distribution for - * more information. - * - * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - *****************************************************************************/ - - -#ifndef TCLAP_VERSION_VISITOR_H -#define TCLAP_VERSION_VISITOR_H - -#include -#include -#include - -namespace TCLAP { - -/** - * A Vistor that will call the version method of the given CmdLineOutput - * for the specified CmdLine object and then exit. - */ -class VersionVisitor: public Visitor -{ - private: - /** - * Prevent accidental copying - */ - VersionVisitor(const VersionVisitor& rhs); - VersionVisitor& operator=(const VersionVisitor& rhs); - - protected: - - /** - * The CmdLine of interest. - */ - CmdLineInterface* _cmd; - - /** - * The output object. - */ - CmdLineOutput** _out; - - public: - - /** - * Constructor. - * \param cmd - The CmdLine the output is generated for. - * \param out - The type of output. - */ - VersionVisitor( CmdLineInterface* cmd, CmdLineOutput** out ) - : Visitor(), _cmd( cmd ), _out( out ) { } - - /** - * Calls the version method of the output object using the - * specified CmdLine. - */ - void visit() { - (*_out)->version(*_cmd); - throw ExitException(0); - } - -}; - -} - -#endif diff --git a/src/tclap/Visitor.h b/src/tclap/Visitor.h deleted file mode 100644 index 38ddcbdb86..0000000000 --- a/src/tclap/Visitor.h +++ /dev/null @@ -1,53 +0,0 @@ - -/****************************************************************************** - * - * file: Visitor.h - * - * Copyright (c) 2003, Michael E. Smoot . - * All rights reverved. - * - * See the file COPYING in the top directory of this distribution for - * more information. - * - * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - *****************************************************************************/ - - -#ifndef TCLAP_VISITOR_H -#define TCLAP_VISITOR_H - -namespace TCLAP { - -/** - * A base class that defines the interface for visitors. - */ -class Visitor -{ - public: - - /** - * Constructor. Does nothing. - */ - Visitor() { } - - /** - * Destructor. Does nothing. - */ - virtual ~Visitor() { } - - /** - * Does nothing. Should be overridden by child. - */ - virtual void visit() { } -}; - -} - -#endif diff --git a/src/tclap/XorHandler.h b/src/tclap/XorHandler.h deleted file mode 100644 index d9dfad31f6..0000000000 --- a/src/tclap/XorHandler.h +++ /dev/null @@ -1,166 +0,0 @@ - -/****************************************************************************** - * - * file: XorHandler.h - * - * Copyright (c) 2003, Michael E. Smoot . - * Copyright (c) 2004, Michael E. Smoot, Daniel Aarno. - * All rights reverved. - * - * See the file COPYING in the top directory of this distribution for - * more information. - * - * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - *****************************************************************************/ - -#ifndef TCLAP_XORHANDLER_H -#define TCLAP_XORHANDLER_H - -#include -#include -#include -#include -#include - -namespace TCLAP { - -/** - * This class handles lists of Arg's that are to be XOR'd on the command - * line. This is used by CmdLine and you shouldn't ever use it. - */ -class XorHandler -{ - protected: - - /** - * The list of of lists of Arg's to be or'd together. - */ - std::vector< std::vector > _orList; - - public: - - /** - * Constructor. Does nothing. - */ - XorHandler( ) : _orList(std::vector< std::vector >()) {} - - /** - * Add a list of Arg*'s that will be orred together. - * \param ors - list of Arg* that will be xor'd. - */ - void add( std::vector& ors ); - - /** - * Checks whether the specified Arg is in one of the xor lists and - * if it does match one, returns the size of the xor list that the - * Arg matched. If the Arg matches, then it also sets the rest of - * the Arg's in the list. You shouldn't use this. - * \param a - The Arg to be checked. - */ - int check( const Arg* a ); - - /** - * Returns the XOR specific short usage. - */ - std::string shortUsage(); - - /** - * Prints the XOR specific long usage. - * \param os - Stream to print to. - */ - void printLongUsage(std::ostream& os); - - /** - * Simply checks whether the Arg is contained in one of the arg - * lists. - * \param a - The Arg to be checked. - */ - bool contains( const Arg* a ); - - std::vector< std::vector >& getXorList(); - -}; - - -////////////////////////////////////////////////////////////////////// -//BEGIN XOR.cpp -////////////////////////////////////////////////////////////////////// -inline void XorHandler::add( std::vector& ors ) -{ - _orList.push_back( ors ); -} - -inline int XorHandler::check( const Arg* a ) -{ - // iterate over each XOR list - for ( int i = 0; static_cast(i) < _orList.size(); i++ ) - { - // if the XOR list contains the arg.. - ArgVectorIterator ait = std::find( _orList[i].begin(), - _orList[i].end(), a ); - if ( ait != _orList[i].end() ) - { - // first check to see if a mutually exclusive switch - // has not already been set - for ( ArgVectorIterator it = _orList[i].begin(); - it != _orList[i].end(); - it++ ) - if ( a != (*it) && (*it)->isSet() ) - throw(CmdLineParseException( - "Mutually exclusive argument already set!", - (*it)->toString())); - - // go through and set each arg that is not a - for ( ArgVectorIterator it = _orList[i].begin(); - it != _orList[i].end(); - it++ ) - if ( a != (*it) ) - (*it)->xorSet(); - - // return the number of required args that have now been set - if ( (*ait)->allowMore() ) - return 0; - else - return static_cast(_orList[i].size()); - } - } - - if ( a->isRequired() ) - return 1; - else - return 0; -} - -inline bool XorHandler::contains( const Arg* a ) -{ - for ( int i = 0; static_cast(i) < _orList.size(); i++ ) - for ( ArgVectorIterator it = _orList[i].begin(); - it != _orList[i].end(); - it++ ) - if ( a == (*it) ) - return true; - - return false; -} - -inline std::vector< std::vector >& XorHandler::getXorList() -{ - return _orList; -} - - - -////////////////////////////////////////////////////////////////////// -//END XOR.cpp -////////////////////////////////////////////////////////////////////// - -} //namespace TCLAP - -#endif diff --git a/src/tclap/ZshCompletionOutput.h b/src/tclap/ZshCompletionOutput.h deleted file mode 100644 index 0b37fc7296..0000000000 --- a/src/tclap/ZshCompletionOutput.h +++ /dev/null @@ -1,323 +0,0 @@ -// -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*- - -/****************************************************************************** - * - * file: ZshCompletionOutput.h - * - * Copyright (c) 2006, Oliver Kiddle - * All rights reverved. - * - * See the file COPYING in the top directory of this distribution for - * more information. - * - * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - *****************************************************************************/ - -#ifndef TCLAP_ZSHCOMPLETIONOUTPUT_H -#define TCLAP_ZSHCOMPLETIONOUTPUT_H - -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -namespace TCLAP { - -/** - * A class that generates a Zsh completion function as output from the usage() - * method for the given CmdLine and its Args. - */ -class ZshCompletionOutput : public CmdLineOutput -{ - - public: - - ZshCompletionOutput(); - - /** - * Prints the usage to stdout. Can be overridden to - * produce alternative behavior. - * \param c - The CmdLine object the output is generated for. - */ - virtual void usage(CmdLineInterface& c); - - /** - * Prints the version to stdout. Can be overridden - * to produce alternative behavior. - * \param c - The CmdLine object the output is generated for. - */ - virtual void version(CmdLineInterface& c); - - /** - * Prints (to stderr) an error message, short usage - * Can be overridden to produce alternative behavior. - * \param c - The CmdLine object the output is generated for. - * \param e - The ArgException that caused the failure. - */ - virtual void failure(CmdLineInterface& c, - ArgException& e ); - - protected: - - void basename( std::string& s ); - void quoteSpecialChars( std::string& s ); - - std::string getMutexList( CmdLineInterface& _cmd, Arg* a ); - void printOption( Arg* it, std::string mutex ); - void printArg( Arg* it ); - - std::map common; - char theDelimiter; -}; - -ZshCompletionOutput::ZshCompletionOutput() -: common(std::map()), - theDelimiter('=') -{ - common["host"] = "_hosts"; - common["hostname"] = "_hosts"; - common["file"] = "_files"; - common["filename"] = "_files"; - common["user"] = "_users"; - common["username"] = "_users"; - common["directory"] = "_directories"; - common["path"] = "_directories"; - common["url"] = "_urls"; -} - -inline void ZshCompletionOutput::version(CmdLineInterface& _cmd) -{ - std::cout << _cmd.getVersion() << std::endl; -} - -inline void ZshCompletionOutput::usage(CmdLineInterface& _cmd ) -{ - std::list argList = _cmd.getArgList(); - std::string progName = _cmd.getProgramName(); - std::string xversion = _cmd.getVersion(); - theDelimiter = _cmd.getDelimiter(); - basename(progName); - - std::cout << "#compdef " << progName << std::endl << std::endl << - "# " << progName << " version " << _cmd.getVersion() << std::endl << std::endl << - "_arguments -s -S"; - - for (ArgListIterator it = argList.begin(); it != argList.end(); it++) - { - if ( (*it)->shortID().at(0) == '<' ) - printArg((*it)); - else if ( (*it)->getFlag() != "-" ) - printOption((*it), getMutexList(_cmd, *it)); - } - - std::cout << std::endl; -} - -inline void ZshCompletionOutput::failure( CmdLineInterface& _cmd, - ArgException& e ) -{ - static_cast(_cmd); // unused - std::cout << e.what() << std::endl; -} - -inline void ZshCompletionOutput::quoteSpecialChars( std::string& s ) -{ - size_t idx = s.find_last_of(':'); - while ( idx != std::string::npos ) - { - s.insert(idx, 1, '\\'); - idx = s.find_last_of(':', idx); - } - idx = s.find_last_of('\''); - while ( idx != std::string::npos ) - { - s.insert(idx, "'\\'"); - if (idx == 0) - idx = std::string::npos; - else - idx = s.find_last_of('\'', --idx); - } -} - -inline void ZshCompletionOutput::basename( std::string& s ) -{ - size_t p = s.find_last_of('/'); - if ( p != std::string::npos ) - { - s.erase(0, p + 1); - } -} - -inline void ZshCompletionOutput::printArg(Arg* a) -{ - static int count = 1; - - std::cout << " \\" << std::endl << " '"; - if ( a->acceptsMultipleValues() ) - std::cout << '*'; - else - std::cout << count++; - std::cout << ':'; - if ( !a->isRequired() ) - std::cout << ':'; - - std::cout << a->getName() << ':'; - std::map::iterator compArg = common.find(a->getName()); - if ( compArg != common.end() ) - { - std::cout << compArg->second; - } - else - { - std::cout << "_guard \"^-*\" " << a->getName(); - } - std::cout << '\''; -} - -inline void ZshCompletionOutput::printOption(Arg* a, std::string mutex) -{ - std::string flag = a->flagStartChar() + a->getFlag(); - std::string name = a->nameStartString() + a->getName(); - std::string desc = a->getDescription(); - - // remove full stop and capitalisation from description as - // this is the convention for zsh function - if (!desc.compare(0, 12, "(required) ")) - { - desc.erase(0, 12); - } - if (!desc.compare(0, 15, "(OR required) ")) - { - desc.erase(0, 15); - } - size_t len = desc.length(); - if (len && desc.at(--len) == '.') - { - desc.erase(len); - } - if (len) - { - desc.replace(0, 1, 1, tolower(desc.at(0))); - } - - std::cout << " \\" << std::endl << " '" << mutex; - - if ( a->getFlag().empty() ) - { - std::cout << name; - } - else - { - std::cout << "'{" << flag << ',' << name << "}'"; - } - if ( theDelimiter == '=' && a->isValueRequired() ) - std::cout << "=-"; - quoteSpecialChars(desc); - std::cout << '[' << desc << ']'; - - if ( a->isValueRequired() ) - { - std::string arg = a->shortID(); - arg.erase(0, arg.find_last_of(theDelimiter) + 1); - if ( arg.at(arg.length()-1) == ']' ) - arg.erase(arg.length()-1); - if ( arg.at(arg.length()-1) == ']' ) - { - arg.erase(arg.length()-1); - } - if ( arg.at(0) == '<' ) - { - arg.erase(arg.length()-1); - arg.erase(0, 1); - } - size_t p = arg.find('|'); - if ( p != std::string::npos ) - { - do - { - arg.replace(p, 1, 1, ' '); - } - while ( (p = arg.find_first_of('|', p)) != std::string::npos ); - quoteSpecialChars(arg); - std::cout << ": :(" << arg << ')'; - } - else - { - std::cout << ':' << arg; - std::map::iterator compArg = common.find(arg); - if ( compArg != common.end() ) - { - std::cout << ':' << compArg->second; - } - } - } - - std::cout << '\''; -} - -inline std::string ZshCompletionOutput::getMutexList( CmdLineInterface& _cmd, Arg* a) -{ - XorHandler xorHandler = _cmd.getXorHandler(); - std::vector< std::vector > xorList = xorHandler.getXorList(); - - if (a->getName() == "help" || a->getName() == "version") - { - return "(-)"; - } - - std::ostringstream list; - if ( a->acceptsMultipleValues() ) - { - list << '*'; - } - - for ( int i = 0; static_cast(i) < xorList.size(); i++ ) - { - for ( ArgVectorIterator it = xorList[i].begin(); - it != xorList[i].end(); - it++) - if ( a == (*it) ) - { - list << '('; - for ( ArgVectorIterator iu = xorList[i].begin(); - iu != xorList[i].end(); - iu++ ) - { - bool notCur = (*iu) != a; - bool hasFlag = !(*iu)->getFlag().empty(); - if ( iu != xorList[i].begin() && (notCur || hasFlag) ) - list << ' '; - if (hasFlag) - list << (*iu)->flagStartChar() << (*iu)->getFlag() << ' '; - if ( notCur || hasFlag ) - list << (*iu)->nameStartString() << (*iu)->getName(); - } - list << ')'; - return list.str(); - } - } - - // wasn't found in xor list - if (!a->getFlag().empty()) { - list << "(" << a->flagStartChar() << a->getFlag() << ' ' << - a->nameStartString() << a->getName() << ')'; - } - - return list.str(); -} - -} //namespace TCLAP -#endif diff --git a/xs/src/libslic3r/Config.cpp b/xs/src/libslic3r/Config.cpp index 9194548c77..778c984ed8 100644 --- a/xs/src/libslic3r/Config.cpp +++ b/xs/src/libslic3r/Config.cpp @@ -1,6 +1,8 @@ #include "Config.hpp" #include // for setenv() #include +#include +#include #if defined(_WIN32) && !defined(setenv) && defined(_putenv_s) #define setenv(k, v, o) _putenv_s(k, v) @@ -20,12 +22,22 @@ operator!= (const ConfigOption &a, const ConfigOption &b) return !(a == b); } -ConfigDef::~ConfigDef() +ConfigOptionDef::ConfigOptionDef(const ConfigOptionDef &other) + : type(other.type), default_value(NULL), + gui_type(other.gui_type), gui_flags(other.gui_flags), label(other.label), + full_label(other.full_label), category(other.category), tooltip(other.tooltip), + sidetext(other.sidetext), cli(other.cli), ratio_over(other.ratio_over), + multiline(other.multiline), full_width(other.full_width), readonly(other.readonly), + height(other.height), width(other.width), min(other.min), max(other.max) { - for (t_optiondef_map::iterator it = this->options.begin(); it != this->options.end(); ++it) { - if (it->second.default_value != NULL) - delete it->second.default_value; - } + if (other.default_value != NULL) + this->default_value = other.default_value->clone(); +} + +ConfigOptionDef::~ConfigOptionDef() +{ + if (this->default_value != NULL) + delete this->default_value; } ConfigOptionDef* @@ -43,6 +55,12 @@ ConfigDef::get(const t_config_option_key &opt_key) const return &const_cast(this)->options[opt_key]; } +void +ConfigDef::merge(const ConfigDef &other) +{ + this->options.insert(other.options.begin(), other.options.end()); +} + bool ConfigBase::has(const t_config_option_key &opt_key) { return (this->option(opt_key, false) != NULL); @@ -200,7 +218,7 @@ DynamicConfig::optptr(const t_config_option_key &opt_key, bool create) { if (this->options.count(opt_key) == 0) { if (create) { const ConfigOptionDef* optdef = this->def->get(opt_key); - assert(optdef != NULL); + if (optdef == NULL) return NULL; ConfigOption* opt; if (optdef->type == coFloat) { opt = new ConfigOptionFloat (); @@ -265,6 +283,58 @@ DynamicConfig::erase(const t_config_option_key &opt_key) { this->options.erase(opt_key); } +void +DynamicConfig::read_cli(const int argc, const char** argv, t_config_option_keys* extra) +{ + bool parse_options = true; + for (int i = 1; i < argc; ++i) { + std::string token = argv[i]; + + if (token == "--") { + // stop parsing tokens as options + parse_options = false; + } else if (parse_options && boost::starts_with(token, "--")) { + boost::algorithm::erase_head(token, 2); + // TODO: handle --key=value + + // look for the option def + t_config_option_key opt_key; + const ConfigOptionDef* optdef; + for (t_optiondef_map::const_iterator oit = this->def->options.begin(); + oit != this->def->options.end(); ++oit) { + optdef = &oit->second; + + if (optdef->cli == token + || optdef->cli == token + '!' + || boost::starts_with(optdef->cli, token + "=")) { + opt_key = oit->first; + break; + } + } + + if (opt_key.empty()) { + printf("Warning: unknown option --%s\n", token.c_str()); + continue; + } + + if (ConfigOptionBool* opt = this->opt(opt_key, true)) { + opt->value = !boost::starts_with(token, "no-"); + } else if (ConfigOptionBools* opt = this->opt(opt_key, true)) { + opt->values.push_back(!boost::starts_with(token, "no-")); + } else { + // we expect one more token carrying the value + if (i == argc) { + printf("No value supplied for --%s\n", token.c_str()); + exit(1); + } + this->option(opt_key, true)->deserialize(argv[++i]); + } + } else { + extra->push_back(token); + } + } +} + void StaticConfig::set_defaults() { diff --git a/xs/src/libslic3r/Config.hpp b/xs/src/libslic3r/Config.hpp index 99cc02fb0c..a8a54baa19 100644 --- a/xs/src/libslic3r/Config.hpp +++ b/xs/src/libslic3r/Config.hpp @@ -20,6 +20,7 @@ typedef std::vector t_config_option_keys; class ConfigOption { public: virtual ~ConfigOption() {}; + virtual ConfigOption* clone() const = 0; virtual std::string serialize() const = 0; virtual bool deserialize(std::string str) = 0; virtual void set(const ConfigOption &option) = 0; @@ -54,8 +55,10 @@ template class ConfigOptionVector : public ConfigOptionVectorBase { public: - virtual ~ConfigOptionVector() {}; std::vector values; + ConfigOptionVector() {}; + ConfigOptionVector(const std::vector _values) : values(_values) {}; + virtual ~ConfigOptionVector() {}; void set(const ConfigOption &option) { const ConfigOptionVector* other = dynamic_cast< const ConfigOptionVector* >(&option); @@ -76,6 +79,7 @@ class ConfigOptionFloat : public ConfigOptionSingle public: ConfigOptionFloat() : ConfigOptionSingle(0) {}; ConfigOptionFloat(double _value) : ConfigOptionSingle(_value) {}; + ConfigOptionFloat* clone() const { return new ConfigOptionFloat(this->value); }; double getFloat() const { return this->value; }; @@ -95,6 +99,9 @@ class ConfigOptionFloat : public ConfigOptionSingle class ConfigOptionFloats : public ConfigOptionVector { public: + ConfigOptionFloats() {}; + ConfigOptionFloats(const std::vector _values) : ConfigOptionVector(_values) {}; + ConfigOptionFloats* clone() const { return new ConfigOptionFloats(this->values); }; std::string serialize() const { std::ostringstream ss; @@ -134,6 +141,7 @@ class ConfigOptionInt : public ConfigOptionSingle public: ConfigOptionInt() : ConfigOptionSingle(0) {}; ConfigOptionInt(double _value) : ConfigOptionSingle(_value) {}; + ConfigOptionInt* clone() const { return new ConfigOptionInt(this->value); }; int getInt() const { return this->value; }; void setInt(int val) { this->value = val; }; @@ -154,6 +162,9 @@ class ConfigOptionInt : public ConfigOptionSingle class ConfigOptionInts : public ConfigOptionVector { public: + ConfigOptionInts() {}; + ConfigOptionInts(const std::vector _values) : ConfigOptionVector(_values) {}; + ConfigOptionInts* clone() const { return new ConfigOptionInts(this->values); }; std::string serialize() const { std::ostringstream ss; @@ -193,6 +204,7 @@ class ConfigOptionString : public ConfigOptionSingle public: ConfigOptionString() : ConfigOptionSingle("") {}; ConfigOptionString(std::string _value) : ConfigOptionSingle(_value) {}; + ConfigOptionString* clone() const { return new ConfigOptionString(this->value); }; std::string serialize() const { std::string str = this->value; @@ -224,6 +236,9 @@ class ConfigOptionString : public ConfigOptionSingle class ConfigOptionStrings : public ConfigOptionVector { public: + ConfigOptionStrings() {}; + ConfigOptionStrings(const std::vector _values) : ConfigOptionVector(_values) {}; + ConfigOptionStrings* clone() const { return new ConfigOptionStrings(this->values); }; std::string serialize() const { std::ostringstream ss; @@ -254,6 +269,7 @@ class ConfigOptionPercent : public ConfigOptionFloat public: ConfigOptionPercent() : ConfigOptionFloat(0) {}; ConfigOptionPercent(double _value) : ConfigOptionFloat(_value) {}; + ConfigOptionPercent* clone() const { return new ConfigOptionPercent(this->value); }; double get_abs_value(double ratio_over) const { return ratio_over * this->value / 100; @@ -282,6 +298,7 @@ class ConfigOptionFloatOrPercent : public ConfigOptionPercent ConfigOptionFloatOrPercent() : ConfigOptionPercent(0), percent(false) {}; ConfigOptionFloatOrPercent(double _value, bool _percent) : ConfigOptionPercent(_value), percent(_percent) {}; + ConfigOptionFloatOrPercent* clone() const { return new ConfigOptionFloatOrPercent(this->value, this->percent); }; void set(const ConfigOption &option) { const ConfigOptionFloatOrPercent* other = dynamic_cast< const ConfigOptionFloatOrPercent* >(&option); @@ -320,6 +337,7 @@ class ConfigOptionPoint : public ConfigOptionSingle public: ConfigOptionPoint() : ConfigOptionSingle(Pointf(0,0)) {}; ConfigOptionPoint(Pointf _value) : ConfigOptionSingle(_value) {}; + ConfigOptionPoint* clone() const { return new ConfigOptionPoint(this->value); }; std::string serialize() const { std::ostringstream ss; @@ -342,6 +360,9 @@ class ConfigOptionPoint : public ConfigOptionSingle class ConfigOptionPoints : public ConfigOptionVector { public: + ConfigOptionPoints() {}; + ConfigOptionPoints(const std::vector _values) : ConfigOptionVector(_values) {}; + ConfigOptionPoints* clone() const { return new ConfigOptionPoints(this->values); }; std::string serialize() const { std::ostringstream ss; @@ -389,6 +410,7 @@ class ConfigOptionBool : public ConfigOptionSingle public: ConfigOptionBool() : ConfigOptionSingle(false) {}; ConfigOptionBool(bool _value) : ConfigOptionSingle(_value) {}; + ConfigOptionBool* clone() const { return new ConfigOptionBool(this->value); }; bool getBool() const { return this->value; }; @@ -405,6 +427,9 @@ class ConfigOptionBool : public ConfigOptionSingle class ConfigOptionBools : public ConfigOptionVector { public: + ConfigOptionBools() {}; + ConfigOptionBools(const std::vector _values) : ConfigOptionVector(_values) {}; + ConfigOptionBools* clone() const { return new ConfigOptionBools(this->values); }; std::string serialize() const { std::ostringstream ss; @@ -445,6 +470,7 @@ class ConfigOptionEnum : public ConfigOptionSingle // by default, use the first value (0) of the T enum type ConfigOptionEnum() : ConfigOptionSingle(static_cast(0)) {}; ConfigOptionEnum(T _value) : ConfigOptionSingle(_value) {}; + ConfigOptionEnum* clone() const { return new ConfigOptionEnum(this->value); }; std::string serialize() const { t_config_enum_values enum_keys_map = ConfigOptionEnum::get_enum_values(); @@ -532,6 +558,11 @@ class ConfigOptionDef ConfigOptionDef() : type(coNone), default_value(NULL), multiline(false), full_width(false), readonly(false), height(-1), width(-1), min(INT_MIN), max(INT_MAX) {}; + ConfigOptionDef(const ConfigOptionDef &other); + ~ConfigOptionDef(); + + private: + ConfigOptionDef& operator= (ConfigOptionDef other); }; typedef std::map t_optiondef_map; @@ -540,9 +571,9 @@ class ConfigDef { public: t_optiondef_map options; - ~ConfigDef(); ConfigOptionDef* add(const t_config_option_key &opt_key, ConfigOptionType type); const ConfigOptionDef* get(const t_config_option_key &opt_key) const; + void merge(const ConfigDef &other); }; class ConfigBase @@ -551,6 +582,7 @@ class ConfigBase const ConfigDef* def; ConfigBase() : def(NULL) {}; + ConfigBase(const ConfigDef* def) : def(def) {}; virtual ~ConfigBase() {}; bool has(const t_config_option_key &opt_key); const ConfigOption* option(const t_config_option_key &opt_key) const; @@ -571,6 +603,7 @@ class DynamicConfig : public virtual ConfigBase { public: DynamicConfig() {}; + DynamicConfig(const ConfigDef* def) : ConfigBase(def) {}; DynamicConfig(const DynamicConfig& other); DynamicConfig& operator= (DynamicConfig other); void swap(DynamicConfig &other); @@ -579,6 +612,7 @@ class DynamicConfig : public virtual ConfigBase virtual ConfigOption* optptr(const t_config_option_key &opt_key, bool create = false); t_config_option_keys keys() const; void erase(const t_config_option_key &opt_key); + void read_cli(const int argc, const char **argv, t_config_option_keys* extra); private: typedef std::map t_options_map; diff --git a/xs/src/libslic3r/Model.cpp b/xs/src/libslic3r/Model.cpp index 9eaf5e2f78..cc9563d914 100644 --- a/xs/src/libslic3r/Model.cpp +++ b/xs/src/libslic3r/Model.cpp @@ -479,7 +479,7 @@ ModelObject::mesh() const TriangleMesh raw_mesh = this->raw_mesh(); for (ModelInstancePtrs::const_iterator i = this->instances.begin(); i != this->instances.end(); ++i) { - TriangleMesh m = raw_mesh; + TriangleMesh m(raw_mesh); (*i)->transform_mesh(&m); mesh.merge(m); } @@ -568,6 +568,12 @@ ModelObject::translate(coordf_t x, coordf_t y, coordf_t z) if (this->_bounding_box_valid) this->_bounding_box.translate(x, y, z); } +void +ModelObject::scale(float factor) +{ + this->scale(Pointf3(factor, factor, factor)); +} + void ModelObject::scale(const Pointf3 &versor) { @@ -713,6 +719,21 @@ ModelVolume::ModelVolume(ModelObject* object, const ModelVolume &other) this->material_id(other.material_id()); } +ModelVolume& ModelVolume::operator= (ModelVolume other) +{ + this->swap(other); + return *this; +} + +void +ModelVolume::swap(ModelVolume &other) +{ + std::swap(this->name, other.name); + std::swap(this->mesh, other.mesh); + std::swap(this->config, other.config); + std::swap(this->modifier, other.modifier); +} + t_model_material_id ModelVolume::material_id() const { @@ -760,6 +781,20 @@ ModelInstance::ModelInstance(ModelObject *object, const ModelInstance &other) : rotation(other.rotation), scaling_factor(other.scaling_factor), offset(other.offset), object(object) {} +ModelInstance& ModelInstance::operator= (ModelInstance other) +{ + this->swap(other); + return *this; +} + +void +ModelInstance::swap(ModelInstance &other) +{ + std::swap(this->rotation, other.rotation); + std::swap(this->scaling_factor, other.scaling_factor); + std::swap(this->offset, other.offset); +} + void ModelInstance::transform_mesh(TriangleMesh* mesh, bool dont_translate) const { diff --git a/xs/src/libslic3r/Model.hpp b/xs/src/libslic3r/Model.hpp index f10707457a..4e2f15bf2c 100644 --- a/xs/src/libslic3r/Model.hpp +++ b/xs/src/libslic3r/Model.hpp @@ -124,6 +124,7 @@ class ModelObject void center_around_origin(); void translate(const Vectorf3 &vector); void translate(coordf_t x, coordf_t y, coordf_t z); + void scale(float factor); void scale(const Pointf3 &versor); void rotate(float angle, const Axis &axis); void mirror(const Axis &axis); @@ -167,6 +168,8 @@ class ModelVolume ModelVolume(ModelObject *object, const TriangleMesh &mesh); ModelVolume(ModelObject *object, const ModelVolume &other); + ModelVolume& operator= (ModelVolume other); + void swap(ModelVolume &other); }; class ModelInstance @@ -186,6 +189,8 @@ class ModelInstance ModelInstance(ModelObject *object); ModelInstance(ModelObject *object, const ModelInstance &other); + ModelInstance& operator= (ModelInstance other); + void swap(ModelInstance &other); }; } diff --git a/xs/src/libslic3r/PrintConfig.cpp b/xs/src/libslic3r/PrintConfig.cpp index 47609aaff8..8d0a3ce99e 100644 --- a/xs/src/libslic3r/PrintConfig.cpp +++ b/xs/src/libslic3r/PrintConfig.cpp @@ -1342,4 +1342,43 @@ PrintConfigBase::min_object_distance() const : duplicate_distance; } +CLIConfigDef::CLIConfigDef() +{ + t_optiondef_map &Options = this->options; + + ConfigOptionDef* def; + + def = this->add("export_obj", coBool); + def->label = "Export SVG"; + def->tooltip = "Export the model to OBJ."; + def->cli = "export-obj"; + def->default_value = new ConfigOptionBool(false); + + def = this->add("export_svg", coBool); + def->label = "Export SVG"; + def->tooltip = "Slice the model and export slices as SVG."; + def->cli = "export-svg"; + def->default_value = new ConfigOptionBool(false); + + def = this->add("output", coString); + def->label = "Output File"; + def->tooltip = "The file where the output will be written (if not specified, it will be based on the input file)."; + def->cli = "output"; + def->default_value = new ConfigOptionString(""); + + def = this->add("rotate", coFloat); + def->label = "Rotate"; + def->tooltip = "Rotation angle around the Z axis in degrees (0-360, default: 0)."; + def->cli = "rotate"; + def->default_value = new ConfigOptionFloat(0); + + def = this->add("scale", coFloat); + def->label = "Scale"; + def->tooltip = "Scaling factor (default: 1)."; + def->cli = "scale"; + def->default_value = new ConfigOptionFloat(1); +} + +CLIConfigDef cli_config_def; + } diff --git a/xs/src/libslic3r/PrintConfig.hpp b/xs/src/libslic3r/PrintConfig.hpp index 1492e61e87..02a140d16f 100644 --- a/xs/src/libslic3r/PrintConfig.hpp +++ b/xs/src/libslic3r/PrintConfig.hpp @@ -466,6 +466,59 @@ class FullPrintConfig }; }; +class SVGExportConfig + : public virtual StaticPrintConfig +{ + public: + ConfigOptionFloatOrPercent first_layer_height; + ConfigOptionFloat layer_height; + + SVGExportConfig() : StaticPrintConfig() { + this->set_defaults(); + }; + + virtual ConfigOption* optptr(const t_config_option_key &opt_key, bool create = false) { + OPT_PTR(first_layer_height); + OPT_PTR(layer_height); + + return NULL; + }; +}; + +class CLIConfigDef : public ConfigDef +{ + public: + CLIConfigDef(); +}; + +extern CLIConfigDef cli_config_def; + +class CLIConfig + : public virtual ConfigBase, public StaticConfig +{ + public: + ConfigOptionBool export_obj; + ConfigOptionBool export_svg; + ConfigOptionString output; + ConfigOptionFloat rotate; + ConfigOptionFloat scale; + + CLIConfig() : ConfigBase(), StaticConfig() { + this->def = &cli_config_def; + this->set_defaults(); + }; + + virtual ConfigOption* optptr(const t_config_option_key &opt_key, bool create = false) { + OPT_PTR(export_obj); + OPT_PTR(export_svg); + OPT_PTR(output); + OPT_PTR(rotate); + OPT_PTR(scale); + + return NULL; + }; +}; + } #endif diff --git a/xs/src/libslic3r/SVGExport.cpp b/xs/src/libslic3r/SVGExport.cpp index ead30a04e1..cd83e5ccab 100644 --- a/xs/src/libslic3r/SVGExport.cpp +++ b/xs/src/libslic3r/SVGExport.cpp @@ -6,54 +6,49 @@ namespace Slic3r { -SVGExport::SVGExport(TriangleMesh &t, float layerheight, float firstlayerheight) - :t(&t), sliced(false) +void +SVGExport::writeSVG(const std::string &outputfile) { - if(layerheight>0){ - for(float f=firstlayerheight;f<=t.stl.stats.max.z;f+=layerheight){ - heights.push_back(f); - } - - TriangleMeshSlicer(&t).slice(heights,&layers); - sliced=true; - } - -} + std::vector heights; + for (float z = this->config.first_layer_height.value; z <= this->mesh->stl.stats.max.z; + z += this->config.layer_height.value) + heights.push_back(z); -// - -void SVGExport::writeSVG(const std::string &outputfile){ - if(sliced){ - FILE* f = fopen(outputfile.c_str(), "w"); - fprintf(f, + std::vector layers; + TriangleMeshSlicer(this->mesh).slice(heights, &layers); + + FILE* f = fopen(outputfile.c_str(), "w"); + fprintf(f, "\n" "\n" "\n" "\n" - ,t->stl.stats.max.x*10,t->stl.stats.max.y*10,SLIC3R_VERSION); - for (int i=0;i\n",i,heights[i]); - for (ExPolygons::const_iterator it = layers[i].begin(); it != layers[i].end(); ++it){ - std::string pd; - Polygons pp = *it; - for (Polygons::const_iterator mp = pp.begin(); mp != pp.end(); ++mp) { - std::ostringstream d; - d << "M "; - for (Points::const_iterator p = mp->points.begin(); p != mp->points.end(); ++p) { - d << COORD(p->x) << " "; - d << COORD(p->y) << " "; - } - d << "z"; - pd += d.str() + " "; + , this->mesh->stl.stats.max.x*10, this->mesh->stl.stats.max.y*10, SLIC3R_VERSION); + + // + + for (size_t i = 0; i < heights.size(); ++i) { + fprintf(f, "\t\n", i, heights[i]); + for (ExPolygons::const_iterator it = layers[i].begin(); it != layers[i].end(); ++it){ + std::string pd; + Polygons pp = *it; + for (Polygons::const_iterator mp = pp.begin(); mp != pp.end(); ++mp) { + std::ostringstream d; + d << "M "; + for (Points::const_iterator p = mp->points.begin(); p != mp->points.end(); ++p) { + d << COORD(p->x) << " "; + d << COORD(p->y) << " "; } - fprintf(f,"\t\t\n", - pd.c_str(),"white","black","0" - ); + d << "z"; + pd += d.str() + " "; } - fprintf(f,"\t\n"); + fprintf(f,"\t\t\n", + pd.c_str(),"white","black","0" + ); } - fprintf(f,"\n"); + fprintf(f,"\t\n"); } + fprintf(f,"\n"); } } diff --git a/xs/src/libslic3r/SVGExport.hpp b/xs/src/libslic3r/SVGExport.hpp index 3d5f2b127a..3b24d1bd17 100644 --- a/xs/src/libslic3r/SVGExport.hpp +++ b/xs/src/libslic3r/SVGExport.hpp @@ -3,6 +3,7 @@ #include "libslic3r.h" #include "ExPolygon.hpp" +#include "PrintConfig.hpp" #include "SVG.hpp" #include "TriangleMesh.hpp" @@ -11,13 +12,13 @@ namespace Slic3r { class SVGExport { public: - SVGExport(TriangleMesh &t, float layerheight, float firstlayerheight=0.0); + SVGExportConfig config; + + SVGExport(TriangleMesh &mesh) : mesh(&mesh) {}; void writeSVG(const std::string &outputfile); + private: - TriangleMesh *t; - std::vector layers; - std::vector heights; - bool sliced; + TriangleMesh* mesh; }; } diff --git a/xs/src/libslic3r/TriangleMesh.cpp b/xs/src/libslic3r/TriangleMesh.cpp index 40d0e480b1..d29503de7f 100644 --- a/xs/src/libslic3r/TriangleMesh.cpp +++ b/xs/src/libslic3r/TriangleMesh.cpp @@ -50,19 +50,15 @@ TriangleMesh::TriangleMesh(const TriangleMesh &other) TriangleMesh& TriangleMesh::operator= (TriangleMesh other) { - this->swap(other); + swap(*this, other); return *this; } void -TriangleMesh::swap(TriangleMesh &other) +TriangleMesh::swap(TriangleMesh &first, TriangleMesh &second) { - std::swap(this->stl, other.stl); - std::swap(this->repaired, other.repaired); - std::swap(this->stl.facet_start, other.stl.facet_start); - std::swap(this->stl.neighbors_start, other.stl.neighbors_start); - std::swap(this->stl.v_indices, other.stl.v_indices); - std::swap(this->stl.v_shared, other.stl.v_shared); + std::swap(first.repaired, second.repaired); + std::swap(first.stl, second.stl); } TriangleMesh::~TriangleMesh() { @@ -340,9 +336,8 @@ TriangleMesh::merge(const TriangleMesh &mesh) stl_reallocate(&this->stl); // copy facets - for (int i = 0; i < mesh.stl.stats.number_of_facets; i++) { - this->stl.facet_start[number_of_facets + i] = mesh.stl.facet_start[i]; - } + std::copy(mesh.stl.facet_start, mesh.stl.facet_start + mesh.stl.stats.number_of_facets, this->stl.facet_start); + std::copy(mesh.stl.neighbors_start, mesh.stl.neighbors_start + mesh.stl.stats.number_of_facets, this->stl.neighbors_start); // update size stl_get_size(&this->stl); diff --git a/xs/src/libslic3r/TriangleMesh.hpp b/xs/src/libslic3r/TriangleMesh.hpp index 0eb62d65e0..62c38e90b5 100644 --- a/xs/src/libslic3r/TriangleMesh.hpp +++ b/xs/src/libslic3r/TriangleMesh.hpp @@ -22,7 +22,7 @@ class TriangleMesh TriangleMesh(); TriangleMesh(const TriangleMesh &other); TriangleMesh& operator= (TriangleMesh other); - void swap(TriangleMesh &other); + void swap(TriangleMesh &first, TriangleMesh &second); ~TriangleMesh(); void ReadSTLFile(const std::string &input_file); void write_ascii(const std::string &output_file); From 4ffe56b666c6121bf80f7f15d0158f559eadd27a Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Mon, 4 Jul 2016 14:37:18 -0500 Subject: [PATCH 13/58] Set LDLOADLIBS to get the linker switch to occur in the right place. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 8853e4bd97..9b71288081 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,5 @@ language: perl -install: true +install: export LDLOADLIBS=-lstdc++ script: perl ./Build.PL perl: - "5.14" From a6353f3d90e94ede106272cca46698850b253608 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Thu, 7 Jul 2016 10:58:45 -0500 Subject: [PATCH 14/58] Update package_win32.ps1 added missing packages --- utils/package_win32.ps1 | 209 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 208 insertions(+), 1 deletion(-) diff --git a/utils/package_win32.ps1 b/utils/package_win32.ps1 index 0a6cde4996..5f3a891429 100644 --- a/utils/package_win32.ps1 +++ b/utils/package_win32.ps1 @@ -12,6 +12,213 @@ $STRAWBERRY_PATH=C:\Strawberry cpanm "PAR::Packer" -pp -a $STRAWBERRY_PATH\perl\bin\perl5.22.1.exe;perl5.22.1.exe -a $STRAWBERRY_PATH\perl\bin\freeglut.dll;freeglut.dll -a $STRAWBERRY_PATH\perl\bin\perl522.dll;perl522.dll -a $STRAWBERRY_PATH\perl\bin\libgcc_s_sjlj-1.dll;libgcc_s_sjlj-1.dll -a $STRAWBERRY_PATH\perl\bin\libstdc++-6.dll;libstdc++-6.dll -a $STRAWBERRY_PATH\perl\bin\libwinpthread-1.dll;libwinpthread-1.dll -a $STRAWBERRY_PATH\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxbase30u_gcc_custom.dll -a $STRAWBERRY_PATH\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxmsw30u_adv_gcc_custom.dll -a $STRAWBERRY_PATH\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxmsw30u_core_gcc_custom.dll -a $STRAWBERRY_PATH\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxmsw30u_gl_gcc_custom.dll -a $STRAWBERRY_PATH\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxmsw30u_html_gcc_custom.dll -a ..\utils;script\utils -a var;script\var -a autorun.bat;slic3r.bat -M Encode::Locale -M Moo -M Thread::Semaphore -M OpenGL -M Slic3r::XS -M Unicode::Normalize -M Wx -M Class::Accessor -M Wx::DND -M Wx::Grid -M Wx::Print -M Wx::Html -M Wx::GLCanvas -M Math::Trig -M threads -M threads::shared -M Thread::Queue -e -p -x slic3r.pl -o ..\slic3r.par +pp -a $STRAWBERRY_PATH\perl\bin\perl5.22.1.exe;perl5.22.1.exe -a $STRAWBERRY_PATH\perl\bin\freeglut.dll;freeglut.dll -a $STRAWBERRY_PATH\perl\bin\perl522.dll;perl522.dll -a $STRAWBERRY_PATH\perl\bin\libgcc_s_sjlj-1.dll;libgcc_s_sjlj-1.dll -a $STRAWBERRY_PATH\perl\bin\libstdc++-6.dll;libstdc++-6.dll -a $STRAWBERRY_PATH\perl\bin\libwinpthread-1.dll;libwinpthread-1.dll -a $STRAWBERRY_PATH\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxbase30u_gcc_custom.dll -a $STRAWBERRY_PATH\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxmsw30u_adv_gcc_custom.dll -a $STRAWBERRY_PATH\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxmsw30u_core_gcc_custom.dll -a $STRAWBERRY_PATH\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxmsw30u_gl_gcc_custom.dll -a $STRAWBERRY_PATH\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxmsw30u_html_gcc_custom.dll -a ..\utils;script\utils -a var;script\var -a autorun.bat;slic3r.bat ` +-M AutoLoader ` +-M B ` +-M Carp ` +-M Class ` +-M Class::Accessor ` +-M Class::XSAccessor ` +-M Class::XSAccessor::Heavy ` +-M Config ` +-M Crypt ` +-M Crypt::CBC ` +-M Cwd ` +-M Data ` +-M Data::UUID ` +-M Devel ` +-M Devel::GlobalDestruction ` +-M Digest ` +-M Digest::MD5 ` +-M Digest::SHA ` +-M Digest::base ` +-M DynaLoader ` +-M Encode ` +-M Encode::Alias ` +-M Encode::Byte ` +-M Encode::Config ` +-M Encode::Encoding ` +-M Encode::Locale ` +-M Encode::MIME ` +-M Encode::MIME::Name ` +-M Errno ` +-M Exporter ` +-M Exporter::Heavy ` +-M Fcntl ` +-M File ` +-M File::Basename ` +-M File::Glob ` +-M File::Spec ` +-M File::Spec::Unix ` +-M File::Spec::Win32 ` +-M FindBin ` +-M Getopt ` +-M Getopt::Long ` +-M Growl ` +-M Growl::GNTP ` +-M HTTP ` +-M HTTP::Config ` +-M HTTP::Date ` +-M HTTP::Headers ` +-M HTTP::Headers::Util ` +-M HTTP::Message ` +-M HTTP::Request ` +-M HTTP::Request::Common ` +-M HTTP::Response ` +-M HTTP::Status ` +-M IO ` +-M IO::Handle ` +-M IO::Select ` +-M IO::Socket ` +-M IO::Socket::INET ` +-M IO::Socket::INET6 ` +-M IO::Socket::IP ` +-M IO::Socket::UNIX ` +-M LWP ` +-M LWP::MediaTypes ` +-M LWP::MemberMixin ` +-M LWP::Protocol ` +-M LWP::Protocol::http ` +-M LWP::UserAgent ` +-M List ` +-M List::Util ` +-M Math ` +-M Math::Libm ` +-M Math::PlanePath ` +-M Math::PlanePath::ArchimedeanChords ` +-M Math::PlanePath::Base ` +-M Math::PlanePath::Base::Digits ` +-M Math::PlanePath::Base::Generic ` +-M Math::PlanePath::Base::NSEW ` +-M Math::PlanePath::Flowsnake ` +-M Math::PlanePath::FlowsnakeCentres ` +-M Math::PlanePath::HilbertCurve ` +-M Math::PlanePath::OctagramSpiral ` +-M Math::PlanePath::SacksSpiral ` +-M Math::Trig ` +-M Method ` +-M Method::Generate ` +-M Method::Generate::Accessor ` +-M Method::Generate::BuildAll ` +-M Method::Generate::Constructor ` +-M Module ` +-M Module::Runtime ` +-M Moo ` +-M Moo::HandleMoose ` +-M Moo::Object ` +-M Moo::Role ` +-M Moo::sification ` +-M Net ` +-M Net::Bonjour ` +-M Net::Bonjour::Entry ` +-M Net::DNS ` +-M Net::DNS::Domain ` +-M Net::DNS::DomainName ` +-M Net::DNS::Header ` +-M Net::DNS::Packet ` +-M Net::DNS::Parameters ` +-M Net::DNS::Question ` +-M Net::DNS::RR ` +-M Net::DNS::RR::OPT ` +-M Net::DNS::RR::PTR ` +-M Net::DNS::Resolver ` +-M Net::DNS::Resolver ` +-M Net::DNS::Resolver::Base ` +-M Net::DNS::Resolver::MSWin32 ` +-M Net::DNS::Update ` +-M Net::HTTP ` +-M Net::HTTP::Methods ` +-M OpenGL ` +-M POSIX ` +-M Pod ` +-M Pod::Escapes ` +-M Pod::Text ` +-M Pod::Usage ` +-M Role ` +-M Role::Tiny ` +-M Scalar ` +-M Scalar::Util ` +-M SelectSaver ` +-M Slic3r ` +-M Slic3r::XS ` +-M Socket ` +-M Socket6 ` +-M Storable ` +-M Sub ` +-M Sub::Defer ` +-M Sub::Exporter ` +-M Sub::Exporter::Progressive ` +-M Sub::Name ` +-M Sub::Quote ` +-M Sub::Util ` +-M Symbol ` +-M Term ` +-M Term::Cap ` +-M Text ` +-M Text::ParseWords ` +-M Thread ` +-M Thread::Queue ` +-M Thread::Semaphore ` +-M Tie ` +-M Tie::Handle ` +-M Tie::Hash ` +-M Tie::StdHandle ` +-M Time ` +-M Time::HiRes ` +-M Time::Local ` +-M URI ` +-M URI::Escape ` +-M URI::http ` +-M Unicode ` +-M Unicode::Normalize ` +-M Win32 ` +-M Win32::API ` +-M Win32::API::Struct ` +-M Win32::API::Type ` +-M Win32::IPHelper ` +-M Win32::TieRegistry ` +-M Win32::WinError ` +-M Win32API ` +-M Win32API::Registry ` +-M Wx ` +-M Wx::App ` +-M Wx::DND ` +-M Wx::DropSource ` +-M Wx::Event ` +-M Wx::GLCanvas ` +-M Wx::Grid ` +-M Wx::Html ` +-M Wx::Locale ` +-M Wx::Menu ` +-M Wx::Mini ` +-M Wx::Print ` +-M Wx::RadioBox ` +-M Wx::Timer ` +-M XSLoader ` +-M attributes ` +-M base ` +-M bytes ` +-M constant ` +-M constant ` +-M constant::defer ` +-M enum ` +-M feature ` +-M integer ` +-a ../lib;lib ` +-M locale ` +-M mro ` +-M overload ` +-M overload::numbers ` +-M overloading ` +-M parent ` +-M re ` +-M strict ` +-M threads ` +-M threads::shared ` +-M utf8 ` +-M vars ` +-M warnings ` +-M warnings::register ` +-e -p -x slic3r.pl -o ..\slic3r.par cp ..\slic3r.par ..\slic3r-$(git rev-parse --abbrev-ref HEAD)-$(git rev-parse --short HEAD).zip From 80336e7130a6c6f7e7dea52d8e3c2299e1038efe Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Thu, 7 Jul 2016 12:07:58 -0500 Subject: [PATCH 15/58] Fix batch file. --- utils/autorun.bat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/autorun.bat b/utils/autorun.bat index 9b42380cdb..ad658efd07 100644 --- a/utils/autorun.bat +++ b/utils/autorun.bat @@ -1 +1 @@ -@perl5.22.1.exe script/slic3r.pl +@perl5.22.1.exe script/slic3r.pl %* From 67b5d12c06b1fc09e6a5be11d99292d8145e82cd Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Thu, 7 Jul 2016 12:40:07 -0500 Subject: [PATCH 16/58] Fix Powershell syntax --- utils/package_win32.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/package_win32.ps1 b/utils/package_win32.ps1 index 5f3a891429..551263782a 100644 --- a/utils/package_win32.ps1 +++ b/utils/package_win32.ps1 @@ -7,7 +7,7 @@ echo "Requires PAR." # Change this to where you have Strawberry Perl installed. #SET STRAWBERRY_PATH=C:\Strawberry -$STRAWBERRY_PATH=C:\Strawberry +New-Variable -Name "STRAWBERRY_PATH" -Visibility -Value "C:\Strawberry" # ([io.fileinfo](Get-Command "perl.exe").Path).basename cpanm "PAR::Packer" From 405f7456c58a3085b59d77dbe917242d9c6694f1 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Thu, 7 Jul 2016 13:53:45 -0500 Subject: [PATCH 17/58] set names up properly in powershell script --- utils/package_win32.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utils/package_win32.ps1 b/utils/package_win32.ps1 index 551263782a..663e621d26 100644 --- a/utils/package_win32.ps1 +++ b/utils/package_win32.ps1 @@ -12,7 +12,7 @@ New-Variable -Name "STRAWBERRY_PATH" -Visibility -Value "C:\Strawberry" cpanm "PAR::Packer" -pp -a $STRAWBERRY_PATH\perl\bin\perl5.22.1.exe;perl5.22.1.exe -a $STRAWBERRY_PATH\perl\bin\freeglut.dll;freeglut.dll -a $STRAWBERRY_PATH\perl\bin\perl522.dll;perl522.dll -a $STRAWBERRY_PATH\perl\bin\libgcc_s_sjlj-1.dll;libgcc_s_sjlj-1.dll -a $STRAWBERRY_PATH\perl\bin\libstdc++-6.dll;libstdc++-6.dll -a $STRAWBERRY_PATH\perl\bin\libwinpthread-1.dll;libwinpthread-1.dll -a $STRAWBERRY_PATH\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxbase30u_gcc_custom.dll -a $STRAWBERRY_PATH\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxmsw30u_adv_gcc_custom.dll -a $STRAWBERRY_PATH\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxmsw30u_core_gcc_custom.dll -a $STRAWBERRY_PATH\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxmsw30u_gl_gcc_custom.dll -a $STRAWBERRY_PATH\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxmsw30u_html_gcc_custom.dll -a ..\utils;script\utils -a var;script\var -a autorun.bat;slic3r.bat ` +pp "-a $STRAWBERRY_PATH\perl\bin\perl5.22.1.exe;perl5.22.1.exe -a $STRAWBERRY_PATH\perl\bin\freeglut.dll;freeglut.dll -a $STRAWBERRY_PATH\perl\bin\perl522.dll;perl522.dll -a $STRAWBERRY_PATH\perl\bin\libgcc_s_sjlj-1.dll;libgcc_s_sjlj-1.dll -a $STRAWBERRY_PATH\perl\bin\libstdc++-6.dll;libstdc++-6.dll -a $STRAWBERRY_PATH\perl\bin\libwinpthread-1.dll;libwinpthread-1.dll -a $STRAWBERRY_PATH\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxbase30u_gcc_custom.dll -a $STRAWBERRY_PATH\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxmsw30u_adv_gcc_custom.dll -a $STRAWBERRY_PATH\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxmsw30u_core_gcc_custom.dll -a $STRAWBERRY_PATH\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxmsw30u_gl_gcc_custom.dll -a $STRAWBERRY_PATH\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxmsw30u_html_gcc_custom.dll" -a ..\utils;script\utils -a var;script\var -a autorun.bat;slic3r.bat ` -M AutoLoader ` -M B ` -M Carp ` @@ -221,4 +221,4 @@ pp -a $STRAWBERRY_PATH\perl\bin\perl5.22.1.exe;perl5.22.1.exe -a $STRAWBERRY_PAT -M warnings::register ` -e -p -x slic3r.pl -o ..\slic3r.par -cp ..\slic3r.par ..\slic3r-$(git rev-parse --abbrev-ref HEAD)-$(git rev-parse --short HEAD).zip +copy ..\slic3r.par "..\slic3r-$(git rev-parse --abbrev-ref HEAD)-$(git rev-parse --short HEAD).zip" From a8a21d18ef5beb4269e310644652de731f094d0c Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Thu, 7 Jul 2016 14:36:43 -0500 Subject: [PATCH 18/58] typo in script --- utils/package_win32.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/package_win32.ps1 b/utils/package_win32.ps1 index 663e621d26..13fab13fba 100644 --- a/utils/package_win32.ps1 +++ b/utils/package_win32.ps1 @@ -7,7 +7,7 @@ echo "Requires PAR." # Change this to where you have Strawberry Perl installed. #SET STRAWBERRY_PATH=C:\Strawberry -New-Variable -Name "STRAWBERRY_PATH" -Visibility -Value "C:\Strawberry" +New-Variable -Name "STRAWBERRY_PATH" -Value "C:\Strawberry" # ([io.fileinfo](Get-Command "perl.exe").Path).basename cpanm "PAR::Packer" From ea0c8bced320c2af9b88f6eaf85210b267a6a55d Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Thu, 7 Jul 2016 16:09:00 -0500 Subject: [PATCH 19/58] quoted paths. --- utils/package_win32.ps1 | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/utils/package_win32.ps1 b/utils/package_win32.ps1 index 13fab13fba..cf6fa6c9ff 100644 --- a/utils/package_win32.ps1 +++ b/utils/package_win32.ps1 @@ -12,7 +12,18 @@ New-Variable -Name "STRAWBERRY_PATH" -Value "C:\Strawberry" cpanm "PAR::Packer" -pp "-a $STRAWBERRY_PATH\perl\bin\perl5.22.1.exe;perl5.22.1.exe -a $STRAWBERRY_PATH\perl\bin\freeglut.dll;freeglut.dll -a $STRAWBERRY_PATH\perl\bin\perl522.dll;perl522.dll -a $STRAWBERRY_PATH\perl\bin\libgcc_s_sjlj-1.dll;libgcc_s_sjlj-1.dll -a $STRAWBERRY_PATH\perl\bin\libstdc++-6.dll;libstdc++-6.dll -a $STRAWBERRY_PATH\perl\bin\libwinpthread-1.dll;libwinpthread-1.dll -a $STRAWBERRY_PATH\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxbase30u_gcc_custom.dll -a $STRAWBERRY_PATH\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxmsw30u_adv_gcc_custom.dll -a $STRAWBERRY_PATH\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxmsw30u_core_gcc_custom.dll -a $STRAWBERRY_PATH\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxmsw30u_gl_gcc_custom.dll -a $STRAWBERRY_PATH\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxmsw30u_html_gcc_custom.dll" -a ..\utils;script\utils -a var;script\var -a autorun.bat;slic3r.bat ` +pp -a "$STRAWBERRY_PATH\perl\bin\perl5.22.1.exe;perl5.22.1.exe" ^ +-a "$STRAWBERRY_PATH\perl\bin\freeglut.dll;freeglut.dll" ^ +-a "$STRAWBERRY_PATH\perl\bin\perl522.dll;perl522.dll" ^ +-a "$STRAWBERRY_PATH\perl\bin\libgcc_s_sjlj-1.dll;libgcc_s_sjlj-1.dll" ^ +-a "$STRAWBERRY_PATH\perl\bin\libstdc++-6.dll;libstdc++-6.dll" ^ +-a "$STRAWBERRY_PATH\perl\bin\libwinpthread-1.dll;libwinpthread-1.dll" ^ +-a "$STRAWBERRY_PATH\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxbase30u_gcc_custom.dll" ^ +-a "$STRAWBERRY_PATH\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxmsw30u_adv_gcc_custom.dll" ^ +-a "$STRAWBERRY_PATH\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxmsw30u_core_gcc_custom.dll" ^ +-a "$STRAWBERRY_PATH\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxmsw30u_gl_gcc_custom.dll" ^ +-a "$STRAWBERRY_PATH\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxmsw30u_html_gcc_custom.dll" ^ +-a ..\utils;script\utils -a var;script\var -a autorun.bat;slic3r.bat ` -M AutoLoader ` -M B ` -M Carp ` From 166d199fc48f8b62b4d3b2185ce80a7a5a74b407 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Thu, 7 Jul 2016 18:25:40 -0500 Subject: [PATCH 20/58] Finished cleaning up module and include list. --- utils/package_win32.ps1 | 31 ++++--------------------------- 1 file changed, 4 insertions(+), 27 deletions(-) diff --git a/utils/package_win32.ps1 b/utils/package_win32.ps1 index cf6fa6c9ff..1ae0ffb3be 100644 --- a/utils/package_win32.ps1 +++ b/utils/package_win32.ps1 @@ -23,21 +23,19 @@ pp -a "$STRAWBERRY_PATH\perl\bin\perl5.22.1.exe;perl5.22.1.exe" ^ -a "$STRAWBERRY_PATH\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxmsw30u_core_gcc_custom.dll" ^ -a "$STRAWBERRY_PATH\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxmsw30u_gl_gcc_custom.dll" ^ -a "$STRAWBERRY_PATH\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxmsw30u_html_gcc_custom.dll" ^ --a ..\utils;script\utils -a var;script\var -a autorun.bat;slic3r.bat ` +-a "..\utils;script\utils" -a "..\var;script\var" -a "autorun.bat;slic3r.bat" ` +-a "../lib;lib" ` -M AutoLoader ` -M B ` -M Carp ` --M Class ` -M Class::Accessor ` -M Class::XSAccessor ` -M Class::XSAccessor::Heavy ` -M Config ` --M Crypt ` -M Crypt::CBC ` -M Cwd ` -M Data ` -M Data::UUID ` --M Devel ` -M Devel::GlobalDestruction ` -M Digest ` -M Digest::MD5 ` @@ -50,24 +48,19 @@ pp -a "$STRAWBERRY_PATH\perl\bin\perl5.22.1.exe;perl5.22.1.exe" ^ -M Encode::Config ` -M Encode::Encoding ` -M Encode::Locale ` --M Encode::MIME ` -M Encode::MIME::Name ` -M Errno ` -M Exporter ` -M Exporter::Heavy ` -M Fcntl ` --M File ` -M File::Basename ` -M File::Glob ` -M File::Spec ` -M File::Spec::Unix ` -M File::Spec::Win32 ` -M FindBin ` --M Getopt ` -M Getopt::Long ` --M Growl ` -M Growl::GNTP ` --M HTTP ` -M HTTP::Config ` -M HTTP::Date ` -M HTTP::Headers ` @@ -91,13 +84,10 @@ pp -a "$STRAWBERRY_PATH\perl\bin\perl5.22.1.exe;perl5.22.1.exe" ^ -M LWP::Protocol ` -M LWP::Protocol::http ` -M LWP::UserAgent ` --M List ` -M List::Util ` --M Math ` -M Math::Libm ` -M Math::PlanePath ` -M Math::PlanePath::ArchimedeanChords ` --M Math::PlanePath::Base ` -M Math::PlanePath::Base::Digits ` -M Math::PlanePath::Base::Generic ` -M Math::PlanePath::Base::NSEW ` @@ -107,19 +97,15 @@ pp -a "$STRAWBERRY_PATH\perl\bin\perl5.22.1.exe;perl5.22.1.exe" ^ -M Math::PlanePath::OctagramSpiral ` -M Math::PlanePath::SacksSpiral ` -M Math::Trig ` --M Method ` --M Method::Generate ` -M Method::Generate::Accessor ` -M Method::Generate::BuildAll ` -M Method::Generate::Constructor ` --M Module ` -M Module::Runtime ` -M Moo ` -M Moo::HandleMoose ` -M Moo::Object ` -M Moo::Role ` -M Moo::sification ` --M Net ` -M Net::Bonjour ` -M Net::Bonjour::Entry ` -M Net::DNS ` @@ -141,16 +127,13 @@ pp -a "$STRAWBERRY_PATH\perl\bin\perl5.22.1.exe;perl5.22.1.exe" ^ -M Net::HTTP::Methods ` -M OpenGL ` -M POSIX ` --M Pod ` -M Pod::Escapes ` -M Pod::Text ` -M Pod::Usage ` --M Role ` -M Role::Tiny ` --M Scalar ` -M Scalar::Util ` -M SelectSaver ` --M Slic3r ` +-M Slic3r::* ` -M Slic3r::XS ` -M Socket ` -M Socket6 ` @@ -163,14 +146,11 @@ pp -a "$STRAWBERRY_PATH\perl\bin\perl5.22.1.exe;perl5.22.1.exe" ^ -M Sub::Quote ` -M Sub::Util ` -M Symbol ` --M Term ` -M Term::Cap ` --M Text ` -M Text::ParseWords ` -M Thread ` -M Thread::Queue ` -M Thread::Semaphore ` --M Tie ` -M Tie::Handle ` -M Tie::Hash ` -M Tie::StdHandle ` @@ -180,7 +160,6 @@ pp -a "$STRAWBERRY_PATH\perl\bin\perl5.22.1.exe;perl5.22.1.exe" ^ -M URI ` -M URI::Escape ` -M URI::http ` --M Unicode ` -M Unicode::Normalize ` -M Win32 ` -M Win32::API ` @@ -189,7 +168,6 @@ pp -a "$STRAWBERRY_PATH\perl\bin\perl5.22.1.exe;perl5.22.1.exe" ^ -M Win32::IPHelper ` -M Win32::TieRegistry ` -M Win32::WinError ` --M Win32API ` -M Win32API::Registry ` -M Wx ` -M Wx::App ` @@ -215,7 +193,6 @@ pp -a "$STRAWBERRY_PATH\perl\bin\perl5.22.1.exe;perl5.22.1.exe" ^ -M enum ` -M feature ` -M integer ` --a ../lib;lib ` -M locale ` -M mro ` -M overload ` @@ -230,6 +207,6 @@ pp -a "$STRAWBERRY_PATH\perl\bin\perl5.22.1.exe;perl5.22.1.exe" ^ -M vars ` -M warnings ` -M warnings::register ` --e -p -x slic3r.pl -o ..\slic3r.par +-e -p slic3r.pl -o ..\slic3r.par copy ..\slic3r.par "..\slic3r-$(git rev-parse --abbrev-ref HEAD)-$(git rev-parse --short HEAD).zip" From ec4c14afe95817089df908f1bcb9b936ac7083fe Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Thu, 7 Jul 2016 18:39:01 -0500 Subject: [PATCH 21/58] changed to correctly indicate which branch it belongs to, in addition to the commit. --- utils/autorun.bat | 2 +- utils/package_win32.bat | 15 --------------- utils/package_win32.ps1 | 13 ++++++++++--- 3 files changed, 11 insertions(+), 19 deletions(-) delete mode 100644 utils/package_win32.bat diff --git a/utils/autorun.bat b/utils/autorun.bat index ad658efd07..5a5d376423 100644 --- a/utils/autorun.bat +++ b/utils/autorun.bat @@ -1 +1 @@ -@perl5.22.1.exe script/slic3r.pl %* +@perl5.22.1.exe slic3r.pl %* diff --git a/utils/package_win32.bat b/utils/package_win32.bat deleted file mode 100644 index 26184c86e4..0000000000 --- a/utils/package_win32.bat +++ /dev/null @@ -1,15 +0,0 @@ -REM Written by Joseph Lenox -REM Licensed under the same license as the rest of Slic3r. -REM ------------------------ -REM You need to have Strawberry Perl 5.22 installed for this to work, -echo "Make this is run from the perl command window." -echo "Requires PAR." - -REM Change this to where you have Strawberry Perl installed. -SET STRAWBERRY_PATH=C:\Strawberry - -cpanm "PAR::Packer" - -pp -a %STRAWBERRY_PATH%\perl\bin\perl5.22.1.exe;perl5.22.1.exe -a %STRAWBERRY%\perl\bin\freeglut.dll;freeglut.dll -a %STRAWBERRY%\perl\bin\perl522.dll;perl522.dll -a %STRAWBERRY%\perl\bin\libgcc_s_sjlj-1.dll;libgcc_s_sjlj-1.dll -a %STRAWBERRY%\perl\bin\libstdc++-6.dll;libstdc++-6.dll -a %STRAWBERRY%\perl\bin\libwinpthread-1.dll;libwinpthread-1.dll -a %STRAWBERRY%\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxbase30u_gcc_custom.dll -a %STRAWBERRY%\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxmsw30u_adv_gcc_custom.dll -a %STRAWBERRY%\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxmsw30u_core_gcc_custom.dll -a %STRAWBERRY%\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxmsw30u_gl_gcc_custom.dll -a %STRAWBERRY%\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxmsw30u_html_gcc_custom.dll -a ..\utils;script\utils -a var;script\var -a autorun.bat;slic3r.bat -M Encode::Locale -M Moo -M Thread::Semaphore -M OpenGL -M Slic3r::XS -M Unicode::Normalize -M Wx -M Class::Accessor -M Wx::DND -M Wx::Grid -M Wx::Print -M Wx::Html -M Wx::GLCanvas -M Math::Trig -M threads -M threads::shared -M Thread::Queue -e -p -x slic3r.pl -o ..\slic3r.par - -copy ..\slic3r.par ..\slic3r.zip diff --git a/utils/package_win32.ps1 b/utils/package_win32.ps1 index 1ae0ffb3be..d31682e036 100644 --- a/utils/package_win32.ps1 +++ b/utils/package_win32.ps1 @@ -5,10 +5,16 @@ echo "Make this is run from the perl command window." echo "Requires PAR." +New-Variable -Name "current_branch" -Value "" + +git branch | foreach { + if ($_ -match "^\*(.*)"){ + $current_branch += $matches[1] + "> " + } +} + # Change this to where you have Strawberry Perl installed. -#SET STRAWBERRY_PATH=C:\Strawberry New-Variable -Name "STRAWBERRY_PATH" -Value "C:\Strawberry" -# ([io.fileinfo](Get-Command "perl.exe").Path).basename cpanm "PAR::Packer" @@ -25,6 +31,7 @@ pp -a "$STRAWBERRY_PATH\perl\bin\perl5.22.1.exe;perl5.22.1.exe" ^ -a "$STRAWBERRY_PATH\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxmsw30u_html_gcc_custom.dll" ^ -a "..\utils;script\utils" -a "..\var;script\var" -a "autorun.bat;slic3r.bat" ` -a "../lib;lib" ` +-a "../slic3r.pl;slic3r.pl" -M AutoLoader ` -M B ` -M Carp ` @@ -209,4 +216,4 @@ pp -a "$STRAWBERRY_PATH\perl\bin\perl5.22.1.exe;perl5.22.1.exe" ^ -M warnings::register ` -e -p slic3r.pl -o ..\slic3r.par -copy ..\slic3r.par "..\slic3r-$(git rev-parse --abbrev-ref HEAD)-$(git rev-parse --short HEAD).zip" +copy ..\slic3r.par "..\slic3r-${current_branch}-$(git rev-parse --short HEAD).zip" From 16d1a9a533bae6eae2c3e6e3141a30df99d7379c Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Thu, 7 Jul 2016 18:53:48 -0500 Subject: [PATCH 22/58] Build + packaging script for Win32 (#3402) * batch files to aid in producing built zip files. * added partial modules list added powershell script * Update package_win32.ps1 added missing packages * Fix batch file. * Fix Powershell syntax * set names up properly in powershell script * typo in script * quoted paths. * Finished cleaning up module and include list. * changed to correctly indicate which branch it belongs to, in addition to the commit. --- utils/autorun.bat | 1 + utils/package_win32.ps1 | 219 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 220 insertions(+) create mode 100644 utils/autorun.bat create mode 100644 utils/package_win32.ps1 diff --git a/utils/autorun.bat b/utils/autorun.bat new file mode 100644 index 0000000000..5a5d376423 --- /dev/null +++ b/utils/autorun.bat @@ -0,0 +1 @@ +@perl5.22.1.exe slic3r.pl %* diff --git a/utils/package_win32.ps1 b/utils/package_win32.ps1 new file mode 100644 index 0000000000..d31682e036 --- /dev/null +++ b/utils/package_win32.ps1 @@ -0,0 +1,219 @@ +# Written by Joseph Lenox +# Licensed under the same license as the rest of Slic3r. +# ------------------------ +# You need to have Strawberry Perl 5.22 installed for this to work, +echo "Make this is run from the perl command window." +echo "Requires PAR." + +New-Variable -Name "current_branch" -Value "" + +git branch | foreach { + if ($_ -match "^\*(.*)"){ + $current_branch += $matches[1] + "> " + } +} + +# Change this to where you have Strawberry Perl installed. +New-Variable -Name "STRAWBERRY_PATH" -Value "C:\Strawberry" + +cpanm "PAR::Packer" + +pp -a "$STRAWBERRY_PATH\perl\bin\perl5.22.1.exe;perl5.22.1.exe" ^ +-a "$STRAWBERRY_PATH\perl\bin\freeglut.dll;freeglut.dll" ^ +-a "$STRAWBERRY_PATH\perl\bin\perl522.dll;perl522.dll" ^ +-a "$STRAWBERRY_PATH\perl\bin\libgcc_s_sjlj-1.dll;libgcc_s_sjlj-1.dll" ^ +-a "$STRAWBERRY_PATH\perl\bin\libstdc++-6.dll;libstdc++-6.dll" ^ +-a "$STRAWBERRY_PATH\perl\bin\libwinpthread-1.dll;libwinpthread-1.dll" ^ +-a "$STRAWBERRY_PATH\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxbase30u_gcc_custom.dll" ^ +-a "$STRAWBERRY_PATH\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxmsw30u_adv_gcc_custom.dll" ^ +-a "$STRAWBERRY_PATH\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxmsw30u_core_gcc_custom.dll" ^ +-a "$STRAWBERRY_PATH\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxmsw30u_gl_gcc_custom.dll" ^ +-a "$STRAWBERRY_PATH\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxmsw30u_html_gcc_custom.dll" ^ +-a "..\utils;script\utils" -a "..\var;script\var" -a "autorun.bat;slic3r.bat" ` +-a "../lib;lib" ` +-a "../slic3r.pl;slic3r.pl" +-M AutoLoader ` +-M B ` +-M Carp ` +-M Class::Accessor ` +-M Class::XSAccessor ` +-M Class::XSAccessor::Heavy ` +-M Config ` +-M Crypt::CBC ` +-M Cwd ` +-M Data ` +-M Data::UUID ` +-M Devel::GlobalDestruction ` +-M Digest ` +-M Digest::MD5 ` +-M Digest::SHA ` +-M Digest::base ` +-M DynaLoader ` +-M Encode ` +-M Encode::Alias ` +-M Encode::Byte ` +-M Encode::Config ` +-M Encode::Encoding ` +-M Encode::Locale ` +-M Encode::MIME::Name ` +-M Errno ` +-M Exporter ` +-M Exporter::Heavy ` +-M Fcntl ` +-M File::Basename ` +-M File::Glob ` +-M File::Spec ` +-M File::Spec::Unix ` +-M File::Spec::Win32 ` +-M FindBin ` +-M Getopt::Long ` +-M Growl::GNTP ` +-M HTTP::Config ` +-M HTTP::Date ` +-M HTTP::Headers ` +-M HTTP::Headers::Util ` +-M HTTP::Message ` +-M HTTP::Request ` +-M HTTP::Request::Common ` +-M HTTP::Response ` +-M HTTP::Status ` +-M IO ` +-M IO::Handle ` +-M IO::Select ` +-M IO::Socket ` +-M IO::Socket::INET ` +-M IO::Socket::INET6 ` +-M IO::Socket::IP ` +-M IO::Socket::UNIX ` +-M LWP ` +-M LWP::MediaTypes ` +-M LWP::MemberMixin ` +-M LWP::Protocol ` +-M LWP::Protocol::http ` +-M LWP::UserAgent ` +-M List::Util ` +-M Math::Libm ` +-M Math::PlanePath ` +-M Math::PlanePath::ArchimedeanChords ` +-M Math::PlanePath::Base::Digits ` +-M Math::PlanePath::Base::Generic ` +-M Math::PlanePath::Base::NSEW ` +-M Math::PlanePath::Flowsnake ` +-M Math::PlanePath::FlowsnakeCentres ` +-M Math::PlanePath::HilbertCurve ` +-M Math::PlanePath::OctagramSpiral ` +-M Math::PlanePath::SacksSpiral ` +-M Math::Trig ` +-M Method::Generate::Accessor ` +-M Method::Generate::BuildAll ` +-M Method::Generate::Constructor ` +-M Module::Runtime ` +-M Moo ` +-M Moo::HandleMoose ` +-M Moo::Object ` +-M Moo::Role ` +-M Moo::sification ` +-M Net::Bonjour ` +-M Net::Bonjour::Entry ` +-M Net::DNS ` +-M Net::DNS::Domain ` +-M Net::DNS::DomainName ` +-M Net::DNS::Header ` +-M Net::DNS::Packet ` +-M Net::DNS::Parameters ` +-M Net::DNS::Question ` +-M Net::DNS::RR ` +-M Net::DNS::RR::OPT ` +-M Net::DNS::RR::PTR ` +-M Net::DNS::Resolver ` +-M Net::DNS::Resolver ` +-M Net::DNS::Resolver::Base ` +-M Net::DNS::Resolver::MSWin32 ` +-M Net::DNS::Update ` +-M Net::HTTP ` +-M Net::HTTP::Methods ` +-M OpenGL ` +-M POSIX ` +-M Pod::Escapes ` +-M Pod::Text ` +-M Pod::Usage ` +-M Role::Tiny ` +-M Scalar::Util ` +-M SelectSaver ` +-M Slic3r::* ` +-M Slic3r::XS ` +-M Socket ` +-M Socket6 ` +-M Storable ` +-M Sub ` +-M Sub::Defer ` +-M Sub::Exporter ` +-M Sub::Exporter::Progressive ` +-M Sub::Name ` +-M Sub::Quote ` +-M Sub::Util ` +-M Symbol ` +-M Term::Cap ` +-M Text::ParseWords ` +-M Thread ` +-M Thread::Queue ` +-M Thread::Semaphore ` +-M Tie::Handle ` +-M Tie::Hash ` +-M Tie::StdHandle ` +-M Time ` +-M Time::HiRes ` +-M Time::Local ` +-M URI ` +-M URI::Escape ` +-M URI::http ` +-M Unicode::Normalize ` +-M Win32 ` +-M Win32::API ` +-M Win32::API::Struct ` +-M Win32::API::Type ` +-M Win32::IPHelper ` +-M Win32::TieRegistry ` +-M Win32::WinError ` +-M Win32API::Registry ` +-M Wx ` +-M Wx::App ` +-M Wx::DND ` +-M Wx::DropSource ` +-M Wx::Event ` +-M Wx::GLCanvas ` +-M Wx::Grid ` +-M Wx::Html ` +-M Wx::Locale ` +-M Wx::Menu ` +-M Wx::Mini ` +-M Wx::Print ` +-M Wx::RadioBox ` +-M Wx::Timer ` +-M XSLoader ` +-M attributes ` +-M base ` +-M bytes ` +-M constant ` +-M constant ` +-M constant::defer ` +-M enum ` +-M feature ` +-M integer ` +-M locale ` +-M mro ` +-M overload ` +-M overload::numbers ` +-M overloading ` +-M parent ` +-M re ` +-M strict ` +-M threads ` +-M threads::shared ` +-M utf8 ` +-M vars ` +-M warnings ` +-M warnings::register ` +-e -p slic3r.pl -o ..\slic3r.par + +copy ..\slic3r.par "..\slic3r-${current_branch}-$(git rev-parse --short HEAD).zip" From 9cde70407dd3cb25c2b1f6f26d35b21ecc68b8ee Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Thu, 7 Jul 2016 18:56:33 -0500 Subject: [PATCH 23/58] Added Appveyor build badge. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ba3ef15ed5..9c34e7be7e 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ _Q: Oh cool, a new RepRap slicer?_ A: Yes. -Slic3r [![Build Status](https://travis-ci.org/alexrj/Slic3r.png?branch=master)](https://travis-ci.org/alexrj/Slic3r) +Slic3r [![Build Status](https://travis-ci.org/alexrj/Slic3r.png?branch=master)](https://travis-ci.org/alexrj/Slic3r) [![Build status](https://ci.appveyor.com/api/projects/status/8iqmeat6cj158vo6?svg=true)](https://ci.appveyor.com/project/lordofhyphens/slic3r) ====== Prebuilt Win32 builds https://bintray.com/lordofhyphens/Slic3r/slic3r_dev/view From 952e45f3a593f9d0f42d14acc7228f6162b51045 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Thu, 7 Jul 2016 18:56:56 -0500 Subject: [PATCH 24/58] Fixes a performance issues on Windows, where the cut is being (#3400) refreshed many times for a single move of the Z plane. Fixes a problem on Windows, where the new wxWidgets always returned Cancel, even if the window was closed with the "Cut" button. Improved performance if the live preview is disabled or not needed, because both top and bottom parts shall be displayed. --- lib/Slic3r/GUI/Plater/ObjectCutDialog.pm | 107 ++++++++++++++++++----- 1 file changed, 84 insertions(+), 23 deletions(-) diff --git a/lib/Slic3r/GUI/Plater/ObjectCutDialog.pm b/lib/Slic3r/GUI/Plater/ObjectCutDialog.pm index 8b9a2ed992..a523fb0854 100644 --- a/lib/Slic3r/GUI/Plater/ObjectCutDialog.pm +++ b/lib/Slic3r/GUI/Plater/ObjectCutDialog.pm @@ -15,6 +15,11 @@ sub new { $self->{model_object_idx} = $params{model_object_idx}; $self->{model_object} = $params{model_object}; $self->{new_model_objects} = []; + # Mark whether the mesh cut is valid. + # If not, it needs to be recalculated by _update() on wxTheApp->CallAfter() or on exit of the dialog. + $self->{mesh_cut_valid} = 0; + # Note whether the window was already closed, so a pending update is not executed. + $self->{already_closed} = 0; # cut options $self->{cut_options} = { @@ -31,11 +36,18 @@ sub new { title => 'Cut', on_change => sub { my ($opt_id) = @_; - - $self->{cut_options}{$opt_id} = $optgroup->get_value($opt_id); - wxTheApp->CallAfter(sub { - $self->_update; - }); + # There seems to be an issue with wxWidgets 3.0.2/3.0.3, where the slider + # genates tens of events for a single value change. + # Only trigger the recalculation if the value changes + # or a live preview was activated and the mesh cut is not valid yet. + if ($self->{cut_options}{$opt_id} != $optgroup->get_value($opt_id) || + ! $self->{mesh_cut_valid} && $self->_life_preview_active()) { + $self->{cut_options}{$opt_id} = $optgroup->get_value($opt_id); + $self->{mesh_cut_valid} = 0; + wxTheApp->CallAfter(sub { + $self->_update; + }); + } }, label_width => 120, ); @@ -113,6 +125,10 @@ sub new { $self->{sizer}->SetSizeHints($self); EVT_BUTTON($self, $self->{btn_cut}, sub { + # Recalculate the cut if the preview was not active. + $self->_perform_cut() unless $self->{mesh_cut_valid}; + + # Adjust position / orientation of the split object halves. if ($self->{new_model_objects}{lower}) { if ($self->{cut_options}{rotate_lower}) { $self->{new_model_objects}{lower}->rotate(PI, X); @@ -123,41 +139,86 @@ sub new { $self->{new_model_objects}{upper}->center_around_origin; # align to Z = 0 } + # Note that the window was already closed, so a pending update will not be executed. + $self->{already_closed} = 1; $self->EndModal(wxID_OK); - $self->Close; + $self->Destroy(); }); - + + EVT_CLOSE($self, sub { + # Note that the window was already closed, so a pending update will not be executed. + $self->{already_closed} = 1; + $self->EndModal(wxID_CANCEL); + $self->Destroy(); + }); + $self->_update; return $self; } +# scale Z down to original size since we're using the transformed mesh for 3D preview +# and cut dialog but ModelObject::cut() needs Z without any instance transformation +sub _mesh_slice_z_pos +{ + my ($self) = @_; + return $self->{cut_options}{z} / $self->{model_object}->instances->[0]->scaling_factor; +} + +# Only perform live preview if just a single part of the object shall survive. +sub _life_preview_active +{ + my ($self) = @_; + return $self->{cut_options}{preview} && ($self->{cut_options}{keep_upper} != $self->{cut_options}{keep_lower}); +} + +# Slice the mesh, keep the top / bottom part. +sub _perform_cut +{ + my ($self) = @_; + + # Early exit. If the cut is valid, don't recalculate it. + return if $self->{mesh_cut_valid}; + + my $z = $self->_mesh_slice_z_pos(); + + my ($new_model) = $self->{model_object}->cut($z); + my ($upper_object, $lower_object) = @{$new_model->objects}; + $self->{new_model} = $new_model; + $self->{new_model_objects} = {}; + if ($self->{cut_options}{keep_upper} && $upper_object->volumes_count > 0) { + $self->{new_model_objects}{upper} = $upper_object; + } + if ($self->{cut_options}{keep_lower} && $lower_object->volumes_count > 0) { + $self->{new_model_objects}{lower} = $lower_object; + } + + $self->{mesh_cut_valid} = 1; +} + sub _update { my ($self) = @_; - + + # Don't update if the window was already closed. + # We are not sure whether the action planned by wxTheApp->CallAfter() may be triggered after the window is closed. + # Probably not, but better be safe than sorry, which is espetially true on multiple platforms. + return if $self->{already_closed}; + + # Only recalculate the cut, if the live cut preview is active. + my $life_preview_active = $self->_life_preview_active(); + $self->_perform_cut() if $life_preview_active; + { # scale Z down to original size since we're using the transformed mesh for 3D preview # and cut dialog but ModelObject::cut() needs Z without any instance transformation - my $z = $self->{cut_options}{z} / $self->{model_object}->instances->[0]->scaling_factor; - - { - my ($new_model) = $self->{model_object}->cut($z); - my ($upper_object, $lower_object) = @{$new_model->objects}; - $self->{new_model} = $new_model; - $self->{new_model_objects} = {}; - if ($self->{cut_options}{keep_upper} && $upper_object->volumes_count > 0) { - $self->{new_model_objects}{upper} = $upper_object; - } - if ($self->{cut_options}{keep_lower} && $lower_object->volumes_count > 0) { - $self->{new_model_objects}{lower} = $lower_object; - } - } + my $z = $self->_mesh_slice_z_pos(); + # update canvas if ($self->{canvas}) { # get volumes to render my @objects = (); - if ($self->{cut_options}{preview}) { + if ($life_preview_active) { push @objects, values %{$self->{new_model_objects}}; } else { push @objects, $self->{model_object}; From 61fc0ec281dd1b34e0e2cd32b3ecad4ed6801ea9 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Thu, 7 Jul 2016 19:26:27 -0500 Subject: [PATCH 25/58] changing paths --- utils/package_win32.ps1 | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/utils/package_win32.ps1 b/utils/package_win32.ps1 index d31682e036..52b6cc30a8 100644 --- a/utils/package_win32.ps1 +++ b/utils/package_win32.ps1 @@ -8,28 +8,34 @@ echo "Requires PAR." New-Variable -Name "current_branch" -Value "" git branch | foreach { - if ($_ -match "^\*(.*)"){ + if ($_ -match "`\*(.*)"){ $current_branch += $matches[1] + "> " } } # Change this to where you have Strawberry Perl installed. -New-Variable -Name "STRAWBERRY_PATH" -Value "C:\Strawberry" +New-Variable -Name "STRAWBERRY_PATH" -Value "$STRAWBERRY_PATH" cpanm "PAR::Packer" -pp -a "$STRAWBERRY_PATH\perl\bin\perl5.22.1.exe;perl5.22.1.exe" ^ --a "$STRAWBERRY_PATH\perl\bin\freeglut.dll;freeglut.dll" ^ --a "$STRAWBERRY_PATH\perl\bin\perl522.dll;perl522.dll" ^ --a "$STRAWBERRY_PATH\perl\bin\libgcc_s_sjlj-1.dll;libgcc_s_sjlj-1.dll" ^ --a "$STRAWBERRY_PATH\perl\bin\libstdc++-6.dll;libstdc++-6.dll" ^ --a "$STRAWBERRY_PATH\perl\bin\libwinpthread-1.dll;libwinpthread-1.dll" ^ --a "$STRAWBERRY_PATH\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxbase30u_gcc_custom.dll" ^ --a "$STRAWBERRY_PATH\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxmsw30u_adv_gcc_custom.dll" ^ --a "$STRAWBERRY_PATH\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxmsw30u_core_gcc_custom.dll" ^ --a "$STRAWBERRY_PATH\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxmsw30u_gl_gcc_custom.dll" ^ --a "$STRAWBERRY_PATH\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxmsw30u_html_gcc_custom.dll" ^ --a "..\utils;script\utils" -a "..\var;script\var" -a "autorun.bat;slic3r.bat" ` +pp ` +-a "../utils;utils" ` +-a "autorun.bat;slic3r.bat" ` +-a "../var;var" ` +-a "../slic3r.pl;slic3r.pl" ` +-a "$STRAWBERRY_PATH\perl\bin\perl5.22.2.exe;perl5.22.2.exe" ` +-a "$STRAWBERRY_PATH\perl\bin\perl522.dll;perl522.dll" ` +-a "$STRAWBERRY_PATH\perl\bin\libgcc_s_sjlj-1.dll;libgcc_s_sjlj-1.dll" ` +-a "$STRAWBERRY_PATH\perl\bin\libstdc++-6.dll;libstdc++-6.dll" ` +-a "$STRAWBERRY_PATH\perl\bin\libwinpthread-1.dll;libwinpthread-1.dll" ` +-a "$STRAWBERRY_PATH\perl\bin\freeglut.dll;freeglut.dll" ` +-a "$STRAWBERRY_PATH\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxbase30u_gcc_custom.dll;wxbase30u_gcc_custom.dll" ` +-a "$STRAWBERRY_PATH\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxmsw30u_adv_gcc_custom.dll;wxmsw30u_adv_gcc_custom.dll" ` +-a "$STRAWBERRY_PATH\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxmsw30u_gl_gcc_custom.dll;wxmsw30u_gl_gcc_custom.dll" ` +-a "$STRAWBERRY_PATH\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxmsw30u_core_gcc_custom.dll;wxmsw30u_core_gcc_custom.dll" ` +-a "$STRAWBERRY_PATH\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxmsw30u_html_gcc_custom.dll;wxmsw30u_html_gcc_custom.dll" ` +-a "$STRAWBERRY_PATH\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxbase30u_xml_gcc_custom.dll;wxbase30u_xml_gcc_custom.dll" ` +-a "$STRAWBERRY_PATH\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxbase30u_net_gcc_custom.dll;wxbase30u_net_gcc_custom.dll" ` -a "../lib;lib" ` -a "../slic3r.pl;slic3r.pl" -M AutoLoader ` From 84a2de5bfa6591f99dc2f12f57450bdf2fd8e23b Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Thu, 7 Jul 2016 20:04:52 -0500 Subject: [PATCH 26/58] oops, forgot a backtick --- utils/package_win32.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/package_win32.ps1 b/utils/package_win32.ps1 index 52b6cc30a8..56ebaa3222 100644 --- a/utils/package_win32.ps1 +++ b/utils/package_win32.ps1 @@ -37,7 +37,7 @@ pp ` -a "$STRAWBERRY_PATH\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxbase30u_xml_gcc_custom.dll;wxbase30u_xml_gcc_custom.dll" ` -a "$STRAWBERRY_PATH\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxbase30u_net_gcc_custom.dll;wxbase30u_net_gcc_custom.dll" ` -a "../lib;lib" ` --a "../slic3r.pl;slic3r.pl" +-a "../slic3r.pl;slic3r.pl" ` -M AutoLoader ` -M B ` -M Carp ` From 7e0767b0f1b9eb6c827cf7aed760f12859425ff7 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Thu, 7 Jul 2016 20:42:41 -0500 Subject: [PATCH 27/58] fixing location of slic3r script --- utils/package_win32.ps1 | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/utils/package_win32.ps1 b/utils/package_win32.ps1 index 56ebaa3222..a7f98f60b9 100644 --- a/utils/package_win32.ps1 +++ b/utils/package_win32.ps1 @@ -22,7 +22,6 @@ pp ` -a "../utils;utils" ` -a "autorun.bat;slic3r.bat" ` -a "../var;var" ` --a "../slic3r.pl;slic3r.pl" ` -a "$STRAWBERRY_PATH\perl\bin\perl5.22.2.exe;perl5.22.2.exe" ` -a "$STRAWBERRY_PATH\perl\bin\perl522.dll;perl522.dll" ` -a "$STRAWBERRY_PATH\perl\bin\libgcc_s_sjlj-1.dll;libgcc_s_sjlj-1.dll" ` @@ -220,6 +219,6 @@ pp ` -M vars ` -M warnings ` -M warnings::register ` --e -p slic3r.pl -o ..\slic3r.par +-e -p ..\slic3r.pl -o ..\slic3r.par copy ..\slic3r.par "..\slic3r-${current_branch}-$(git rev-parse --short HEAD).zip" From d504a624be758d68aaa1d7de718cbadd3560c722 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Thu, 7 Jul 2016 21:41:00 -0500 Subject: [PATCH 28/58] minor fixes to packaging script --- utils/package_win32.ps1 | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/utils/package_win32.ps1 b/utils/package_win32.ps1 index a7f98f60b9..fb605b196c 100644 --- a/utils/package_win32.ps1 +++ b/utils/package_win32.ps1 @@ -8,8 +8,8 @@ echo "Requires PAR." New-Variable -Name "current_branch" -Value "" git branch | foreach { - if ($_ -match "`\*(.*)"){ - $current_branch += $matches[1] + "> " + if ($_ -match "` (.*)"){ + $current_branch += $matches[1] } } @@ -46,7 +46,6 @@ pp ` -M Config ` -M Crypt::CBC ` -M Cwd ` --M Data ` -M Data::UUID ` -M Devel::GlobalDestruction ` -M Digest ` @@ -150,7 +149,6 @@ pp ` -M Socket ` -M Socket6 ` -M Storable ` --M Sub ` -M Sub::Defer ` -M Sub::Exporter ` -M Sub::Exporter::Progressive ` @@ -166,7 +164,6 @@ pp ` -M Tie::Handle ` -M Tie::Hash ` -M Tie::StdHandle ` --M Time ` -M Time::HiRes ` -M Time::Local ` -M URI ` From 94b71f1aa9aeba42b58d3d82eeae4710f8f71039 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Thu, 7 Jul 2016 22:22:35 -0500 Subject: [PATCH 29/58] fixed perl path for batch file and added lib module --- utils/autorun.bat | 2 +- utils/package_win32.ps1 | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/utils/autorun.bat b/utils/autorun.bat index 5a5d376423..b952b87e59 100644 --- a/utils/autorun.bat +++ b/utils/autorun.bat @@ -1 +1 @@ -@perl5.22.1.exe slic3r.pl %* +@perl5.22.2.exe slic3r.pl %* diff --git a/utils/package_win32.ps1 b/utils/package_win32.ps1 index fb605b196c..fddabd2795 100644 --- a/utils/package_win32.ps1 +++ b/utils/package_win32.ps1 @@ -203,6 +203,7 @@ pp ` -M feature ` -M integer ` -M locale ` +-M lib ` -M mro ` -M overload ` -M overload::numbers ` From 1dd60cc295dff5dacdc3b55e2626ebaddb89370f Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Thu, 7 Jul 2016 22:41:51 -0500 Subject: [PATCH 30/58] fixed variable references. --- utils/package_win32.ps1 | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/utils/package_win32.ps1 b/utils/package_win32.ps1 index fddabd2795..773f3169eb 100644 --- a/utils/package_win32.ps1 +++ b/utils/package_win32.ps1 @@ -14,7 +14,7 @@ git branch | foreach { } # Change this to where you have Strawberry Perl installed. -New-Variable -Name "STRAWBERRY_PATH" -Value "$STRAWBERRY_PATH" +New-Variable -Name "STRAWBERRY_PATH" -Value "C:\Strawberry" cpanm "PAR::Packer" @@ -22,19 +22,19 @@ pp ` -a "../utils;utils" ` -a "autorun.bat;slic3r.bat" ` -a "../var;var" ` --a "$STRAWBERRY_PATH\perl\bin\perl5.22.2.exe;perl5.22.2.exe" ` --a "$STRAWBERRY_PATH\perl\bin\perl522.dll;perl522.dll" ` --a "$STRAWBERRY_PATH\perl\bin\libgcc_s_sjlj-1.dll;libgcc_s_sjlj-1.dll" ` --a "$STRAWBERRY_PATH\perl\bin\libstdc++-6.dll;libstdc++-6.dll" ` --a "$STRAWBERRY_PATH\perl\bin\libwinpthread-1.dll;libwinpthread-1.dll" ` --a "$STRAWBERRY_PATH\perl\bin\freeglut.dll;freeglut.dll" ` --a "$STRAWBERRY_PATH\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxbase30u_gcc_custom.dll;wxbase30u_gcc_custom.dll" ` --a "$STRAWBERRY_PATH\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxmsw30u_adv_gcc_custom.dll;wxmsw30u_adv_gcc_custom.dll" ` --a "$STRAWBERRY_PATH\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxmsw30u_gl_gcc_custom.dll;wxmsw30u_gl_gcc_custom.dll" ` --a "$STRAWBERRY_PATH\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxmsw30u_core_gcc_custom.dll;wxmsw30u_core_gcc_custom.dll" ` --a "$STRAWBERRY_PATH\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxmsw30u_html_gcc_custom.dll;wxmsw30u_html_gcc_custom.dll" ` --a "$STRAWBERRY_PATH\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxbase30u_xml_gcc_custom.dll;wxbase30u_xml_gcc_custom.dll" ` --a "$STRAWBERRY_PATH\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxbase30u_net_gcc_custom.dll;wxbase30u_net_gcc_custom.dll" ` +-a "${STRAWBERRY_PATH}\perl\bin\perl5.22.2.exe;perl5.22.2.exe" ` +-a "${STRAWBERRY_PATH}\perl\bin\perl522.dll;perl522.dll" ` +-a "${STRAWBERRY_PATH}\perl\bin\libgcc_s_sjlj-1.dll;libgcc_s_sjlj-1.dll" ` +-a "${STRAWBERRY_PATH}\perl\bin\libstdc++-6.dll;libstdc++-6.dll" ` +-a "${STRAWBERRY_PATH}\perl\bin\libwinpthread-1.dll;libwinpthread-1.dll" ` +-a "${STRAWBERRY_PATH}\perl\bin\freeglut.dll;freeglut.dll" ` +-a "${STRAWBERRY_PATH}\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxbase30u_gcc_custom.dll;wxbase30u_gcc_custom.dll" ` +-a "${STRAWBERRY_PATH}\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxmsw30u_adv_gcc_custom.dll;wxmsw30u_adv_gcc_custom.dll" ` +-a "${STRAWBERRY_PATH}\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxmsw30u_gl_gcc_custom.dll;wxmsw30u_gl_gcc_custom.dll" ` +-a "${STRAWBERRY_PATH}\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxmsw30u_core_gcc_custom.dll;wxmsw30u_core_gcc_custom.dll" ` +-a "${STRAWBERRY_PATH}\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxmsw30u_html_gcc_custom.dll;wxmsw30u_html_gcc_custom.dll" ` +-a "${STRAWBERRY_PATH}\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxbase30u_xml_gcc_custom.dll;wxbase30u_xml_gcc_custom.dll" ` +-a "${STRAWBERRY_PATH}\perl\site\lib\Alien\wxWidgets\msw_3_0_2_uni_gcc_3_4\lib\wxbase30u_net_gcc_custom.dll;wxbase30u_net_gcc_custom.dll" ` -a "../lib;lib" ` -a "../slic3r.pl;slic3r.pl" ` -M AutoLoader ` From 3954103b9aba5d7dcdeeb11a8d61badeb14b006a Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Fri, 8 Jul 2016 14:18:15 -0500 Subject: [PATCH 31/58] Update package_win32.ps1 Use appveyor variables --- utils/package_win32.ps1 | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/utils/package_win32.ps1 b/utils/package_win32.ps1 index 773f3169eb..d67b285a48 100644 --- a/utils/package_win32.ps1 +++ b/utils/package_win32.ps1 @@ -5,13 +5,13 @@ echo "Make this is run from the perl command window." echo "Requires PAR." -New-Variable -Name "current_branch" -Value "" +New-Variable -Name "current_branch" -Value "${APPVEYOR_REPO_BRANCH}" -git branch | foreach { - if ($_ -match "` (.*)"){ - $current_branch += $matches[1] - } -} +#git branch | foreach { +# if ($_ -match "` (.*)"){ +# $current_branch += $matches[1] +# } +#} # Change this to where you have Strawberry Perl installed. New-Variable -Name "STRAWBERRY_PATH" -Value "C:\Strawberry" @@ -219,4 +219,4 @@ pp ` -M warnings::register ` -e -p ..\slic3r.pl -o ..\slic3r.par -copy ..\slic3r.par "..\slic3r-${current_branch}-$(git rev-parse --short HEAD).zip" +copy ..\slic3r.par "..\slic3r-${current_branch}-${APPVEYOR_BUILD_NUMBER}-$(git rev-parse --short HEAD).zip" From 5cfaea8a7f81f0dbd1456ff41a22d98e6b1cf6da Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sat, 9 Jul 2016 10:31:52 +0200 Subject: [PATCH 32/58] Ported --info to C++ --- lib/Slic3r/GUI/Plater.pm | 2 +- lib/Slic3r/Model.pm | 37 -------------------------------- src/CMakeLists.txt | 4 ++-- src/slic3r.cpp | 22 +++++++++---------- xs/Build.PL | 2 +- xs/src/libslic3r/Model.cpp | 35 ++++++++++++++++++++++++++++++ xs/src/libslic3r/Model.hpp | 2 ++ xs/src/libslic3r/PrintConfig.cpp | 6 ++++++ xs/src/libslic3r/PrintConfig.hpp | 2 ++ xs/xsp/Model.xsp | 3 +++ 10 files changed, 63 insertions(+), 52 deletions(-) diff --git a/lib/Slic3r/GUI/Plater.pm b/lib/Slic3r/GUI/Plater.pm index 79e9ae2598..f10ca13148 100644 --- a/lib/Slic3r/GUI/Plater.pm +++ b/lib/Slic3r/GUI/Plater.pm @@ -1640,7 +1640,7 @@ sub selection_changed { $self->{object_info_size}->SetLabel(sprintf("%.2f x %.2f x %.2f", @{$model_object->instance_bounding_box(0)->size})); $self->{object_info_materials}->SetLabel($model_object->materials_count); - if (my $stats = $model_object->mesh_stats) { + if (my $stats = $model_object->raw_mesh->stats) { $self->{object_info_volume}->SetLabel(sprintf('%.2f', $stats->{volume} * ($model_instance->scaling_factor**3))); $self->{object_info_facets}->SetLabel(sprintf('%d (%d shells)', $model_object->facets_count, $stats->{number_of_parts})); if (my $errors = sum(@$stats{qw(degenerate_facets edges_fixed facets_removed facets_added facets_reversed backwards_edges)})) { diff --git a/lib/Slic3r/Model.pm b/lib/Slic3r/Model.pm index 057c1f7fee..01797316b0 100644 --- a/lib/Slic3r/Model.pm +++ b/lib/Slic3r/Model.pm @@ -67,11 +67,6 @@ sub set_material { return $material; } -sub print_info { - my $self = shift; - $_->print_info for @{$self->objects}; -} - sub looks_like_multipart_object { my ($self) = @_; @@ -182,36 +177,4 @@ sub add_instance { } } -sub mesh_stats { - my $self = shift; - - # TODO: sum values from all volumes - return $self->volumes->[0]->mesh->stats; -} - -sub print_info { - my $self = shift; - - printf "Info about %s:\n", basename($self->input_file); - printf " size: x=%.3f y=%.3f z=%.3f\n", @{$self->raw_mesh->bounding_box->size}; - if (my $stats = $self->mesh_stats) { - printf " number of facets: %d\n", $stats->{number_of_facets}; - printf " number of shells: %d\n", $stats->{number_of_parts}; - printf " volume: %.3f\n", $stats->{volume}; - if ($self->needed_repair) { - printf " needed repair: yes\n"; - printf " degenerate facets: %d\n", $stats->{degenerate_facets}; - printf " edges fixed: %d\n", $stats->{edges_fixed}; - printf " facets removed: %d\n", $stats->{facets_removed}; - printf " facets added: %d\n", $stats->{facets_added}; - printf " facets reversed: %d\n", $stats->{facets_reversed}; - printf " backwards edges: %d\n", $stats->{backwards_edges}; - } else { - printf " needed repair: no\n"; - } - } else { - printf " number of facets: %d\n", scalar(map @{$_->facets}, grep !$_->modifier, @{$self->volumes}); - } -} - 1; diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 09093bff46..acd711e772 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -22,7 +22,7 @@ ENDIF(CMAKE_HOST_APPLE) set(Boost_USE_STATIC_LIBS ON) set(Boost_USE_STATIC_RUNTIME ON) set(CMAKE_FIND_LIBRARY_SUFFIXES ".a") -find_package(Boost COMPONENTS system thread) +find_package(Boost COMPONENTS system thread filesystem) set(LIBDIR ${CMAKE_CURRENT_SOURCE_DIR}/../xs/src/) @@ -94,7 +94,7 @@ include_directories(${Boost_INCLUDE_DIRS}) #find_package(wxWidgets) #disable wx for the time being - we're not building any of the gui yet IF(CMAKE_HOST_UNIX) - #set(Boost_LIBRARIES bsystem bthread) + #set(Boost_LIBRARIES bsystem bthread bfilesystem) ENDIF(CMAKE_HOST_UNIX) IF(wxWidgets_FOUND) MESSAGE("wx found!") diff --git a/src/slic3r.cpp b/src/slic3r.cpp index 0cb674d82c..1f46288360 100644 --- a/src/slic3r.cpp +++ b/src/slic3r.cpp @@ -60,32 +60,32 @@ main(const int argc, const char **argv) models.push_back(model); } - if (cli_config.export_obj) { - for (std::vector::iterator model = models.begin(); model != models.end(); ++model) { + for (std::vector::iterator model = models.begin(); model != models.end(); ++model) { + if (cli_config.info) { + model->print_info(); + } else if (cli_config.export_obj) { std::string outfile = cli_config.output.value; if (outfile.empty()) outfile = model->objects.front()->input_file + ".obj"; - + TriangleMesh mesh = model->mesh(); Slic3r::IO::OBJ::write(mesh, outfile); printf("File exported to %s\n", outfile.c_str()); - } - } else if (cli_config.export_svg) { - for (std::vector::iterator model = models.begin(); model != models.end(); ++model) { + } else if (cli_config.export_svg) { std::string outfile = cli_config.output.value; if (outfile.empty()) outfile = model->objects.front()->input_file + ".svg"; - + TriangleMesh mesh = model->mesh(); mesh.mirror_x(); mesh.align_to_origin(); - + SVGExport svg_export(mesh); svg_export.config.apply(print_config, true); svg_export.writeSVG(outfile); printf("SVG file exported to %s\n", outfile.c_str()); + } else { + std::cerr << "error: only --export-svg and --export-obj are currently supported" << std::endl; + return 1; } - } else { - std::cerr << "error: only --export-svg and --export-obj are currently supported" << std::endl; - return 1; } return 0; diff --git a/xs/Build.PL b/xs/Build.PL index 6145777c7b..8a111c1a44 100644 --- a/xs/Build.PL +++ b/xs/Build.PL @@ -47,7 +47,7 @@ if (defined $ENV{BOOST_DIR}) { # In order to generate the -l switches we need to know how Boost libraries are named my $have_boost = 0; -my @boost_libraries = qw(system thread); # we need these +my @boost_libraries = qw(system thread filesystem); # we need these # check without explicit lib path (works on Linux) $have_boost = 1 diff --git a/xs/src/libslic3r/Model.cpp b/xs/src/libslic3r/Model.cpp index cc9563d914..ee389e5173 100644 --- a/xs/src/libslic3r/Model.cpp +++ b/xs/src/libslic3r/Model.cpp @@ -1,5 +1,7 @@ #include "Model.hpp" #include "Geometry.hpp" +#include +#include "boost/filesystem.hpp" namespace Slic3r { @@ -311,6 +313,13 @@ Model::duplicate_objects_grid(size_t x, size_t y, coordf_t dist) } } +void +Model::print_info() const +{ + for (ModelObjectPtrs::const_iterator o = this->objects.begin(); o != this->objects.end(); ++o) + (*o)->print_info(); +} + ModelMaterial::ModelMaterial(Model *model) : model(model) {} ModelMaterial::ModelMaterial(Model *model, const ModelMaterial &other) : attributes(other.attributes), config(other.config), model(model) @@ -707,6 +716,32 @@ ModelObject::split(ModelObjectPtrs* new_objects) return; } +void +ModelObject::print_info() const +{ + using namespace std; + cout << "Info about " << boost::filesystem::basename(this->input_file) << ":" << endl; + + TriangleMesh mesh = this->raw_mesh(); + mesh.repair(); + Sizef3 size = mesh.bounding_box().size(); + cout << " size: x=" << size.x << " y=" << size.y << " z=" << size.z << endl; + cout << " number of facets: " << mesh.stl.stats.number_of_facets << endl; + cout << " number of shells: " << mesh.stl.stats.number_of_parts << endl; + cout << " volume: " << mesh.stl.stats.volume << endl; + if (this->needed_repair()) { + cout << " needed repair: yes" << endl; + cout << " degenerate facets: " << mesh.stl.stats.degenerate_facets << endl; + cout << " edges fixed: " << mesh.stl.stats.edges_fixed << endl; + cout << " facets removed: " << mesh.stl.stats.facets_removed << endl; + cout << " facets added: " << mesh.stl.stats.facets_added << endl; + cout << " facets reversed: " << mesh.stl.stats.facets_reversed << endl; + cout << " backwards edges: " << mesh.stl.stats.backwards_edges << endl; + } else { + cout << " needed repair: no" << endl; + } +} + ModelVolume::ModelVolume(ModelObject* object, const TriangleMesh &mesh) : mesh(mesh), modifier(false), object(object) diff --git a/xs/src/libslic3r/Model.hpp b/xs/src/libslic3r/Model.hpp index 4e2f15bf2c..e98d1db281 100644 --- a/xs/src/libslic3r/Model.hpp +++ b/xs/src/libslic3r/Model.hpp @@ -61,6 +61,7 @@ class Model void duplicate(size_t copies_num, coordf_t dist, const BoundingBoxf* bb = NULL); void duplicate_objects(size_t copies_num, coordf_t dist, const BoundingBoxf* bb = NULL); void duplicate_objects_grid(size_t x, size_t y, coordf_t dist); + void print_info() const; }; class ModelMaterial @@ -134,6 +135,7 @@ class ModelObject void cut(coordf_t z, Model* model) const; void split(ModelObjectPtrs* new_objects); void update_bounding_box(); // this is a private method but we expose it until we need to expose it via XS + void print_info() const; private: Model* model; diff --git a/xs/src/libslic3r/PrintConfig.cpp b/xs/src/libslic3r/PrintConfig.cpp index 8d0a3ce99e..58d9437e75 100644 --- a/xs/src/libslic3r/PrintConfig.cpp +++ b/xs/src/libslic3r/PrintConfig.cpp @@ -1360,6 +1360,12 @@ CLIConfigDef::CLIConfigDef() def->cli = "export-svg"; def->default_value = new ConfigOptionBool(false); + def = this->add("info", coBool); + def->label = "Output Model Info"; + def->tooltip = "Write information about the model to the console."; + def->cli = "info"; + def->default_value = new ConfigOptionBool(false); + def = this->add("output", coString); def->label = "Output File"; def->tooltip = "The file where the output will be written (if not specified, it will be based on the input file)."; diff --git a/xs/src/libslic3r/PrintConfig.hpp b/xs/src/libslic3r/PrintConfig.hpp index 02a140d16f..9cae88b65a 100644 --- a/xs/src/libslic3r/PrintConfig.hpp +++ b/xs/src/libslic3r/PrintConfig.hpp @@ -499,6 +499,7 @@ class CLIConfig public: ConfigOptionBool export_obj; ConfigOptionBool export_svg; + ConfigOptionBool info; ConfigOptionString output; ConfigOptionFloat rotate; ConfigOptionFloat scale; @@ -511,6 +512,7 @@ class CLIConfig virtual ConfigOption* optptr(const t_config_option_key &opt_key, bool create = false) { OPT_PTR(export_obj); OPT_PTR(export_svg); + OPT_PTR(info); OPT_PTR(output); OPT_PTR(rotate); OPT_PTR(scale); diff --git a/xs/xsp/Model.xsp b/xs/xsp/Model.xsp index 3cc0f5e3b2..8bfd10123b 100644 --- a/xs/xsp/Model.xsp +++ b/xs/xsp/Model.xsp @@ -71,6 +71,7 @@ void duplicate(unsigned int copies_num, double dist, BoundingBoxf* bb = NULL); void duplicate_objects(unsigned int copies_num, double dist, BoundingBoxf* bb = NULL); void duplicate_objects_grid(unsigned int x, unsigned int y, double dist); + void print_info(); }; @@ -196,6 +197,8 @@ ModelMaterial::attributes() RETVAL = new ModelObjectPtrs(); // leak? THIS->split(RETVAL); %}; + + void print_info(); }; From 1ecf1c805f203a9a1df35dce0ba80f7f65896ad5 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sat, 9 Jul 2016 11:44:45 +0200 Subject: [PATCH 33/58] Raft for SVG export --- xs/src/libslic3r/ClipperUtils.cpp | 12 ++++++++ xs/src/libslic3r/ClipperUtils.hpp | 3 ++ xs/src/libslic3r/MotionPlanner.cpp | 2 +- xs/src/libslic3r/PrintConfig.cpp | 9 ++++++ xs/src/libslic3r/PrintConfig.hpp | 4 +++ xs/src/libslic3r/SVGExport.cpp | 44 ++++++++++++++++++++++++------ 6 files changed, 64 insertions(+), 10 deletions(-) diff --git a/xs/src/libslic3r/ClipperUtils.cpp b/xs/src/libslic3r/ClipperUtils.cpp index aea0ef5959..3490118ee3 100644 --- a/xs/src/libslic3r/ClipperUtils.cpp +++ b/xs/src/libslic3r/ClipperUtils.cpp @@ -222,6 +222,18 @@ offset_ex(const Slic3r::Polygons &polygons, const float delta, return expp; } +Slic3r::ExPolygons +offset_ex(const Slic3r::ExPolygons &expolygons, const float delta, + double scale, ClipperLib::JoinType joinType, double miterLimit) +{ + Slic3r::Polygons pp; + for (Slic3r::ExPolygons::const_iterator ex = expolygons.begin(); ex != expolygons.end(); ++ex) { + Slic3r::Polygons pp2 = *ex; + pp.insert(pp.end(), pp2.begin(), pp2.end()); + } + return offset_ex(pp, delta, scale, joinType, miterLimit); +} + void offset2(const Slic3r::Polygons &polygons, ClipperLib::Paths* retval, const float delta1, const float delta2, const double scale, const ClipperLib::JoinType joinType, const double miterLimit) diff --git a/xs/src/libslic3r/ClipperUtils.hpp b/xs/src/libslic3r/ClipperUtils.hpp index f3ab6158e4..4bc5ceb89a 100644 --- a/xs/src/libslic3r/ClipperUtils.hpp +++ b/xs/src/libslic3r/ClipperUtils.hpp @@ -61,6 +61,9 @@ void offset(const Slic3r::Polygons &polygons, Slic3r::ExPolygons* retval, const Slic3r::ExPolygons offset_ex(const Slic3r::Polygons &polygons, const float delta, double scale = 100000, ClipperLib::JoinType joinType = ClipperLib::jtMiter, double miterLimit = 3); +Slic3r::ExPolygons offset_ex(const Slic3r::ExPolygons &expolygons, const float delta, + double scale = 100000, ClipperLib::JoinType joinType = ClipperLib::jtMiter, + double miterLimit = 3); void offset2(const Slic3r::Polygons &polygons, ClipperLib::Paths* retval, const float delta1, const float delta2, double scale = 100000, ClipperLib::JoinType joinType = ClipperLib::jtMiter, diff --git a/xs/src/libslic3r/MotionPlanner.cpp b/xs/src/libslic3r/MotionPlanner.cpp index 21afb37c41..a1df679cfd 100644 --- a/xs/src/libslic3r/MotionPlanner.cpp +++ b/xs/src/libslic3r/MotionPlanner.cpp @@ -142,7 +142,7 @@ MotionPlanner::shortest_path(const Point &from, const Point &to) { // grow our environment slightly in order for simplify_by_visibility() // to work best by considering moves on boundaries valid as well - ExPolygonCollection grown_env(offset_ex(env.env, +SCALED_EPSILON)); + ExPolygonCollection grown_env(offset_ex((Polygons)env.env, +SCALED_EPSILON)); if (island_idx == -1) { /* If 'from' or 'to' are not inside our env, they were connected using the diff --git a/xs/src/libslic3r/PrintConfig.cpp b/xs/src/libslic3r/PrintConfig.cpp index 58d9437e75..1438bb2967 100644 --- a/xs/src/libslic3r/PrintConfig.cpp +++ b/xs/src/libslic3r/PrintConfig.cpp @@ -754,6 +754,15 @@ PrintConfigDef::PrintConfigDef() def->min = 0; def->default_value = new ConfigOptionInt(0); + def = this->add("raft_offset", coFloat); + def->label = "Raft offset"; + def->category = "Support material"; + def->tooltip = "Horizontal margin between object base layer and raft contour."; + def->sidetext = "mm"; + def->cli = "raft-offset=f"; + def->min = 0; + def->default_value = new ConfigOptionFloat(4); + def = this->add("resolution", coFloat); def->label = "Resolution"; def->tooltip = "Minimum detail resolution, used to simplify the input file for speeding up the slicing job and reducing memory usage. High-resolution models often carry more detail than printers can render. Set to zero to disable any simplification and use full resolution from input."; diff --git a/xs/src/libslic3r/PrintConfig.hpp b/xs/src/libslic3r/PrintConfig.hpp index 9cae88b65a..345406a6d5 100644 --- a/xs/src/libslic3r/PrintConfig.hpp +++ b/xs/src/libslic3r/PrintConfig.hpp @@ -472,6 +472,8 @@ class SVGExportConfig public: ConfigOptionFloatOrPercent first_layer_height; ConfigOptionFloat layer_height; + ConfigOptionInt raft_layers; + ConfigOptionFloat raft_offset; SVGExportConfig() : StaticPrintConfig() { this->set_defaults(); @@ -480,6 +482,8 @@ class SVGExportConfig virtual ConfigOption* optptr(const t_config_option_key &opt_key, bool create = false) { OPT_PTR(first_layer_height); OPT_PTR(layer_height); + OPT_PTR(raft_layers); + OPT_PTR(raft_offset); return NULL; }; diff --git a/xs/src/libslic3r/SVGExport.cpp b/xs/src/libslic3r/SVGExport.cpp index cd83e5ccab..d27a1cede2 100644 --- a/xs/src/libslic3r/SVGExport.cpp +++ b/xs/src/libslic3r/SVGExport.cpp @@ -1,5 +1,5 @@ #include "SVGExport.hpp" -#include "SVG.hpp" +#include "ClipperUtils.hpp" #include #include #define COORD(x) ((float)unscale(x)*10) @@ -9,13 +9,39 @@ namespace Slic3r { void SVGExport::writeSVG(const std::string &outputfile) { - std::vector heights; - for (float z = this->config.first_layer_height.value; z <= this->mesh->stl.stats.max.z; - z += this->config.layer_height.value) - heights.push_back(z); - + // if we are generating a raft, first_layer_height will not affect mesh slicing + const float lh = this->config.layer_height.value; + const float first_lh = this->config.first_layer_height.value; + + // generate the list of Z coordinates for mesh slicing + // (we slice each layer at half of its thickness) + std::vector slice_z, layer_z; + { + const float first_slice_lh = (this->config.raft_layers > 0) ? lh : first_lh; + slice_z.push_back(first_slice_lh/2); + layer_z.push_back(first_slice_lh); + } + while (layer_z.back() + lh/2 <= this->mesh->stl.stats.max.z) { + slice_z.push_back(layer_z.back() + lh/2); + layer_z.push_back(layer_z.back() + lh); + } + + // perform the slicing std::vector layers; - TriangleMeshSlicer(this->mesh).slice(heights, &layers); + TriangleMeshSlicer(this->mesh).slice(slice_z, &layers); + + // generate a solid raft if requested + if (this->config.raft_layers > 0) { + ExPolygons raft = offset_ex(layers.front(), scale_(this->config.raft_offset)); + for (int i = this->config.raft_layers; i >= 1; --i) { + layer_z.insert(layer_z.begin(), first_lh + lh * (i-1)); + layers.insert(layers.begin(), raft); + } + + // prepend total raft height to all sliced layers + for (int i = this->config.raft_layers; i < layer_z.size(); ++i) + layer_z[i] += first_lh + lh * (this->config.raft_layers-1); + } FILE* f = fopen(outputfile.c_str(), "w"); fprintf(f, @@ -27,8 +53,8 @@ SVGExport::writeSVG(const std::string &outputfile) // - for (size_t i = 0; i < heights.size(); ++i) { - fprintf(f, "\t\n", i, heights[i]); + for (size_t i = 0; i < layer_z.size(); ++i) { + fprintf(f, "\t\n", i, layer_z[i]); for (ExPolygons::const_iterator it = layers[i].begin(); it != layers[i].end(); ++it){ std::string pd; Polygons pp = *it; From f49458506fa407b4bdfab9d57fcaf17b872211e9 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sat, 9 Jul 2016 11:47:53 +0200 Subject: [PATCH 34/58] New attribute slic3r:area in SVG export --- xs/src/libslic3r/SVGExport.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xs/src/libslic3r/SVGExport.cpp b/xs/src/libslic3r/SVGExport.cpp index d27a1cede2..df2ba5940c 100644 --- a/xs/src/libslic3r/SVGExport.cpp +++ b/xs/src/libslic3r/SVGExport.cpp @@ -68,8 +68,8 @@ SVGExport::writeSVG(const std::string &outputfile) d << "z"; pd += d.str() + " "; } - fprintf(f,"\t\t\n", - pd.c_str(),"white","black","0" + fprintf(f,"\t\t\n", + pd.c_str(), "white", "black", "0", unscale(unscale(it->area())) ); } fprintf(f,"\t\n"); From 0b79b971e8dca06a28bb1d36cdb4663b05ee2df5 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sat, 9 Jul 2016 14:12:01 +0200 Subject: [PATCH 35/58] New --export-pov option (C++ only) --- src/slic3r.cpp | 7 +++++++ xs/src/libslic3r/IO.cpp | 20 ++++++++++++++++++++ xs/src/libslic3r/IO.hpp | 6 ++++++ xs/src/libslic3r/PrintConfig.cpp | 8 +++++++- xs/src/libslic3r/PrintConfig.hpp | 2 ++ 5 files changed, 42 insertions(+), 1 deletion(-) diff --git a/src/slic3r.cpp b/src/slic3r.cpp index 1f46288360..0b2dbf0ae9 100644 --- a/src/slic3r.cpp +++ b/src/slic3r.cpp @@ -70,6 +70,13 @@ main(const int argc, const char **argv) TriangleMesh mesh = model->mesh(); Slic3r::IO::OBJ::write(mesh, outfile); printf("File exported to %s\n", outfile.c_str()); + } else if (cli_config.export_pov) { + std::string outfile = cli_config.output.value; + if (outfile.empty()) outfile = model->objects.front()->input_file + ".pov"; + + TriangleMesh mesh = model->mesh(); + Slic3r::IO::POV::write(mesh, outfile); + printf("File exported to %s\n", outfile.c_str()); } else if (cli_config.export_svg) { std::string outfile = cli_config.output.value; if (outfile.empty()) outfile = model->objects.front()->input_file + ".svg"; diff --git a/xs/src/libslic3r/IO.cpp b/xs/src/libslic3r/IO.cpp index 7bd42cea5e..dddff3e22c 100644 --- a/xs/src/libslic3r/IO.cpp +++ b/xs/src/libslic3r/IO.cpp @@ -1,5 +1,7 @@ #include "IO.hpp" #include +#include +#include namespace Slic3r { namespace IO { @@ -44,4 +46,22 @@ OBJ::write(TriangleMesh& mesh, std::string output_file) return true; } +bool +POV::write(TriangleMesh& mesh, std::string output_file) +{ + using namespace std; + ofstream pov; + pov.open(output_file.c_str(), ios::out | ios::trunc); + for (int i = 0; i < mesh.stl.stats.number_of_facets; ++i) { + const stl_facet &f = mesh.stl.facet_start[i]; + pov << "triangle { "; + pov << "<" << f.vertex[0].x << "," << f.vertex[0].y << "," << f.vertex[0].z << ">,"; + pov << "<" << f.vertex[1].x << "," << f.vertex[1].y << "," << f.vertex[1].z << ">,"; + pov << "<" << f.vertex[2].x << "," << f.vertex[2].y << "," << f.vertex[2].z << ">"; + pov << " }" << endl; + } + pov.close(); + return true; +} + } } diff --git a/xs/src/libslic3r/IO.hpp b/xs/src/libslic3r/IO.hpp index 0c3cd991f8..0fe76a0681 100644 --- a/xs/src/libslic3r/IO.hpp +++ b/xs/src/libslic3r/IO.hpp @@ -21,6 +21,12 @@ class OBJ static bool write(TriangleMesh& mesh, std::string output_file); }; +class POV +{ + public: + static bool write(TriangleMesh& mesh, std::string output_file); +}; + } } #endif diff --git a/xs/src/libslic3r/PrintConfig.cpp b/xs/src/libslic3r/PrintConfig.cpp index 1438bb2967..3abc210e1c 100644 --- a/xs/src/libslic3r/PrintConfig.cpp +++ b/xs/src/libslic3r/PrintConfig.cpp @@ -1359,10 +1359,16 @@ CLIConfigDef::CLIConfigDef() def = this->add("export_obj", coBool); def->label = "Export SVG"; - def->tooltip = "Export the model to OBJ."; + def->tooltip = "Export the model as OBJ."; def->cli = "export-obj"; def->default_value = new ConfigOptionBool(false); + def = this->add("export_pov", coBool); + def->label = "Export POV"; + def->tooltip = "Export the model as POV-Ray definition."; + def->cli = "export-pov"; + def->default_value = new ConfigOptionBool(false); + def = this->add("export_svg", coBool); def->label = "Export SVG"; def->tooltip = "Slice the model and export slices as SVG."; diff --git a/xs/src/libslic3r/PrintConfig.hpp b/xs/src/libslic3r/PrintConfig.hpp index 345406a6d5..14bbc75220 100644 --- a/xs/src/libslic3r/PrintConfig.hpp +++ b/xs/src/libslic3r/PrintConfig.hpp @@ -502,6 +502,7 @@ class CLIConfig { public: ConfigOptionBool export_obj; + ConfigOptionBool export_pov; ConfigOptionBool export_svg; ConfigOptionBool info; ConfigOptionString output; @@ -515,6 +516,7 @@ class CLIConfig virtual ConfigOption* optptr(const t_config_option_key &opt_key, bool create = false) { OPT_PTR(export_obj); + OPT_PTR(export_pov); OPT_PTR(export_svg); OPT_PTR(info); OPT_PTR(output); From 7ddf2b4029f5c75be63f9cbefab0baba8aa82d34 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sat, 9 Jul 2016 14:14:59 +0200 Subject: [PATCH 36/58] Auto-scale POV output --- xs/src/libslic3r/IO.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/xs/src/libslic3r/IO.cpp b/xs/src/libslic3r/IO.cpp index dddff3e22c..60c1ff686b 100644 --- a/xs/src/libslic3r/IO.cpp +++ b/xs/src/libslic3r/IO.cpp @@ -49,11 +49,18 @@ OBJ::write(TriangleMesh& mesh, std::string output_file) bool POV::write(TriangleMesh& mesh, std::string output_file) { + TriangleMesh mesh2 = mesh; + { + Sizef3 size = mesh2.bounding_box().size(); + coordf_t maxdim = fmax(size.x, fmax(size.y, size.y)); + mesh2.scale(10.0/maxdim); + } + using namespace std; ofstream pov; pov.open(output_file.c_str(), ios::out | ios::trunc); - for (int i = 0; i < mesh.stl.stats.number_of_facets; ++i) { - const stl_facet &f = mesh.stl.facet_start[i]; + for (int i = 0; i < mesh2.stl.stats.number_of_facets; ++i) { + const stl_facet &f = mesh2.stl.facet_start[i]; pov << "triangle { "; pov << "<" << f.vertex[0].x << "," << f.vertex[0].y << "," << f.vertex[0].z << ">,"; pov << "<" << f.vertex[1].x << "," << f.vertex[1].y << "," << f.vertex[1].z << ">,"; From 76f8e355022b001dead35b8913af039fb97c739f Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sat, 9 Jul 2016 14:28:24 +0200 Subject: [PATCH 37/58] Center mesh around origin for POV export --- xs/src/libslic3r/IO.cpp | 1 + xs/src/libslic3r/TriangleMesh.cpp | 10 ++++++++++ xs/src/libslic3r/TriangleMesh.hpp | 1 + 3 files changed, 12 insertions(+) diff --git a/xs/src/libslic3r/IO.cpp b/xs/src/libslic3r/IO.cpp index 60c1ff686b..ee81924e5c 100644 --- a/xs/src/libslic3r/IO.cpp +++ b/xs/src/libslic3r/IO.cpp @@ -50,6 +50,7 @@ bool POV::write(TriangleMesh& mesh, std::string output_file) { TriangleMesh mesh2 = mesh; + mesh2.center_around_origin(); { Sizef3 size = mesh2.bounding_box().size(); coordf_t maxdim = fmax(size.x, fmax(size.y, size.y)); diff --git a/xs/src/libslic3r/TriangleMesh.cpp b/xs/src/libslic3r/TriangleMesh.cpp index d29503de7f..cea6706e99 100644 --- a/xs/src/libslic3r/TriangleMesh.cpp +++ b/xs/src/libslic3r/TriangleMesh.cpp @@ -262,6 +262,16 @@ void TriangleMesh::align_to_origin() ); } +void TriangleMesh::center_around_origin() +{ + this->align_to_origin(); + this->translate( + -(this->stl.stats.size.x/2), + -(this->stl.stats.size.y/2), + -(this->stl.stats.size.z/2) + ); +} + void TriangleMesh::rotate(double angle, Point* center) { this->translate(-center->x, -center->y, 0); diff --git a/xs/src/libslic3r/TriangleMesh.hpp b/xs/src/libslic3r/TriangleMesh.hpp index 62c38e90b5..f0dd66fbad 100644 --- a/xs/src/libslic3r/TriangleMesh.hpp +++ b/xs/src/libslic3r/TriangleMesh.hpp @@ -41,6 +41,7 @@ class TriangleMesh void mirror_y(); void mirror_z(); void align_to_origin(); + void center_around_origin(); void rotate(double angle, Point* center); TriangleMeshPtrs split() const; void merge(const TriangleMesh &mesh); From 437e9be32972cbb96867872e471a443a7826ba47 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sat, 9 Jul 2016 15:30:31 +0200 Subject: [PATCH 38/58] Fix sizes of SVG output --- src/slic3r.cpp | 6 +----- xs/src/libslic3r/SVGExport.cpp | 24 ++++++++++++++++-------- xs/src/libslic3r/SVGExport.hpp | 6 ++++-- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/src/slic3r.cpp b/src/slic3r.cpp index 0b2dbf0ae9..ac888deebe 100644 --- a/src/slic3r.cpp +++ b/src/slic3r.cpp @@ -80,12 +80,8 @@ main(const int argc, const char **argv) } else if (cli_config.export_svg) { std::string outfile = cli_config.output.value; if (outfile.empty()) outfile = model->objects.front()->input_file + ".svg"; - - TriangleMesh mesh = model->mesh(); - mesh.mirror_x(); - mesh.align_to_origin(); - SVGExport svg_export(mesh); + SVGExport svg_export(model->mesh()); svg_export.config.apply(print_config, true); svg_export.writeSVG(outfile); printf("SVG file exported to %s\n", outfile.c_str()); diff --git a/xs/src/libslic3r/SVGExport.cpp b/xs/src/libslic3r/SVGExport.cpp index df2ba5940c..c34b5216ed 100644 --- a/xs/src/libslic3r/SVGExport.cpp +++ b/xs/src/libslic3r/SVGExport.cpp @@ -2,13 +2,23 @@ #include "ClipperUtils.hpp" #include #include -#define COORD(x) ((float)unscale(x)*10) namespace Slic3r { void SVGExport::writeSVG(const std::string &outputfile) { + // align to origin taking raft into account + BoundingBoxf3 bb = this->mesh.bounding_box(); + if (this->config.raft_layers > 0) { + bb.min.x -= this->config.raft_offset.value; + bb.min.y -= this->config.raft_offset.value; + bb.max.x += this->config.raft_offset.value; + bb.max.y += this->config.raft_offset.value; + } + this->mesh.translate(-bb.min.x, -bb.min.y, -bb.min.z); // align to origin + const Sizef3 size = bb.size(); + // if we are generating a raft, first_layer_height will not affect mesh slicing const float lh = this->config.layer_height.value; const float first_lh = this->config.first_layer_height.value; @@ -21,14 +31,14 @@ SVGExport::writeSVG(const std::string &outputfile) slice_z.push_back(first_slice_lh/2); layer_z.push_back(first_slice_lh); } - while (layer_z.back() + lh/2 <= this->mesh->stl.stats.max.z) { + while (layer_z.back() + lh/2 <= this->mesh.stl.stats.max.z) { slice_z.push_back(layer_z.back() + lh/2); layer_z.push_back(layer_z.back() + lh); } // perform the slicing std::vector layers; - TriangleMeshSlicer(this->mesh).slice(slice_z, &layers); + TriangleMeshSlicer(&this->mesh).slice(slice_z, &layers); // generate a solid raft if requested if (this->config.raft_layers > 0) { @@ -49,9 +59,7 @@ SVGExport::writeSVG(const std::string &outputfile) "\n" "\n" "\n" - , this->mesh->stl.stats.max.x*10, this->mesh->stl.stats.max.y*10, SLIC3R_VERSION); - - // + , size.x, size.y, SLIC3R_VERSION); for (size_t i = 0; i < layer_z.size(); ++i) { fprintf(f, "\t\n", i, layer_z[i]); @@ -62,8 +70,8 @@ SVGExport::writeSVG(const std::string &outputfile) std::ostringstream d; d << "M "; for (Points::const_iterator p = mp->points.begin(); p != mp->points.end(); ++p) { - d << COORD(p->x) << " "; - d << COORD(p->y) << " "; + d << unscale(p->x) << " "; + d << unscale(p->y) << " "; } d << "z"; pd += d.str() + " "; diff --git a/xs/src/libslic3r/SVGExport.hpp b/xs/src/libslic3r/SVGExport.hpp index 3b24d1bd17..b77a21fa88 100644 --- a/xs/src/libslic3r/SVGExport.hpp +++ b/xs/src/libslic3r/SVGExport.hpp @@ -14,11 +14,13 @@ class SVGExport public: SVGExportConfig config; - SVGExport(TriangleMesh &mesh) : mesh(&mesh) {}; + SVGExport(const TriangleMesh &mesh) : mesh(mesh) { + this->mesh.mirror_x(); + }; void writeSVG(const std::string &outputfile); private: - TriangleMesh* mesh; + TriangleMesh mesh; }; } From 2c6e4ab7042f89393e4870d1d0e092076d4bb622 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sat, 9 Jul 2016 11:48:58 -0500 Subject: [PATCH 39/58] Added notes about pull requests and internal preview (#3354) New notes for contributing new code via PRs to Slic3r and feature requests. --- .github/CONTRIBUTING.md | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index ecf8a9177d..4865b332df 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -13,9 +13,21 @@ If possible, please include the following information when [reporting an issue]( * Any error messages * If the issue is related to G-code generation, please include the following: * STL, OBJ or AMF input file (please make sure the input file is not broken, e.g. non-manifold, before reporting a bug) - * a screenshot of the G-code layer with the issue (e.g. using [Pronterface](https://github.com/kliment/Printrun)) + * a screenshot of the G-code layer with the issue (e.g. using [Pronterface](https://github.com/kliment/Printrun) or preferably the internal preview tab in Slic3r). +* If the issue is a request for a new feature, be ready to explain why you think it's needed. + * Doing more prepatory work on your end makes it more likely it'll get done. This includes the "how" it can be done in addition to the "what". + * Define the "What" as strictly as you can. Consider what might happen with different infills than simple rectilinear. Please make sure only to include one issue per report. If you encounter multiple, unrelated issues, please report them as such. Simon Tatham has written an excellent on article on [How to Report Bugs Effectively](http://www.chiark.greenend.org.uk/~sgtatham/bugs.html) which is well worth reading, although it is not specific to Slic3r. +Do you want to help fix issues in or add features to Slic3r? That's also very, very welcome :) + +* A good place to start if you can is to look over the [Pull Request or Bust](https://github.com/alexrj/Slic3r/milestones/Pull%20Request%20or%20Bust) milestone. This contains all of the things (mostly new feature requests) that there isn't time or resources to address at this time. + * Things that are probably fixable via scripts (usually marked as such) have the lowest bar to getting something that works, as you don't need to recompile Slic3r to test. +* If you're starting on an issue, please say something in the related issues thread so that someone else doesn't start working on it too. +* If there's nothing in the [Pull Request or Bust](https://github.com/alexrj/Slic3r/milestones/Pull%20Request%20or%20Bust) milestone that interests you, the next place to look is for issues that don't have a milestone. Lots of people commit ideas to Slic3r, and it's difficult to keep up and sort through them. +* Before sending a pull request, please make sure that the changes you are submitting are contained in their own git branch, as PRs merge histories. + * A common workflow is to fork the master branch, create your new branch and do your work there. git-rebase is also helpful for separating out unrelated changes. +* If you are pushing Slic3r code changes that touch the main application, it is very much appreciated if you write some tests that check the functionality of the code. It's much easier to vet and merge in code that includes tests and doing so will likely speed things up. From 59b81fa11e3352ed9ca80d0ba846d5d19f8fa1d8 Mon Sep 17 00:00:00 2001 From: bubnikv Date: Fri, 27 May 2016 23:38:45 +0200 Subject: [PATCH 40/58] Support multi sampled anti-aliasing with wxWidgets 3.0.3. --- lib/Slic3r/GUI/3DScene.pm | 28 ++++++++++++++++++++++++---- lib/Slic3r/GUI/Plater/2DToolpaths.pm | 10 ++++++++-- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/lib/Slic3r/GUI/3DScene.pm b/lib/Slic3r/GUI/3DScene.pm index 162c385f15..a36d2263ca 100644 --- a/lib/Slic3r/GUI/3DScene.pm +++ b/lib/Slic3r/GUI/3DScene.pm @@ -11,7 +11,7 @@ use List::Util qw(reduce min max first); use Slic3r::Geometry qw(X Y Z MIN MAX triangle_normal normalize deg2rad tan scale unscale scaled_epsilon); use Slic3r::Geometry::Clipper qw(offset_ex intersection_pl); use Wx::GLCanvas qw(:all); - + __PACKAGE__->mk_accessors( qw(_quat _dirty init enable_picking enable_moving @@ -56,11 +56,31 @@ use constant HOVER_COLOR => [0.4,0.9,0,1]; sub new { my ($class, $parent) = @_; + # We can only enable multi sample anti aliasing wih wxWidgets 3.0.3 and with a hacked Wx::GLCanvas, + # which exports some new WX_GL_XXX constants, namely WX_GL_SAMPLE_BUFFERS and WX_GL_SAMPLES. + my $can_multisample = + Wx::wxVERSION >= 3.000003 && + defined Wx::GLCanvas->can('WX_GL_SAMPLE_BUFFERS') && + defined Wx::GLCanvas->can('WX_GL_SAMPLES'); + my $attrib = [WX_GL_RGBA, WX_GL_DOUBLEBUFFER, WX_GL_DEPTH_SIZE, 24]; + if ($can_multisample) { + # Request a window with multi sampled anti aliasing. This is a new feature in Wx 3.0.3 (backported from 3.1.0). + # Use eval to avoid compilation, if the subs WX_GL_SAMPLE_BUFFERS and WX_GL_SAMPLES are missing. + eval 'push(@$attrib, (WX_GL_SAMPLE_BUFFERS, 1, WX_GL_SAMPLES, 4));'; + } + # wxWidgets expect the attrib list to be ended by zero. + push(@$attrib, 0); + # we request a depth buffer explicitely because it looks like it's not created by # default on Linux, causing transparency issues - my $self = $class->SUPER::new($parent, -1, Wx::wxDefaultPosition, Wx::wxDefaultSize, 0, "", - [WX_GL_RGBA, WX_GL_DOUBLEBUFFER, WX_GL_DEPTH_SIZE, 16, 0]); - + my $self = $class->SUPER::new($parent, -1, Wx::wxDefaultPosition, Wx::wxDefaultSize, 0, "", $attrib); + if (Wx::wxVERSION >= 3.000003) { + # Wx 3.0.3 contains an ugly hack to support some advanced OpenGL attributes through the attribute list. + # The attribute list is transferred between the wxGLCanvas and wxGLContext constructors using a single static array s_wglContextAttribs. + # Immediatelly force creation of the OpenGL context to consume the static variable s_wglContextAttribs. + $self->GetContext(); + } + $self->background(1); $self->_quat((0, 0, 0, 1)); $self->_stheta(45); diff --git a/lib/Slic3r/GUI/Plater/2DToolpaths.pm b/lib/Slic3r/GUI/Plater/2DToolpaths.pm index 56912888d9..ee59c2980b 100644 --- a/lib/Slic3r/GUI/Plater/2DToolpaths.pm +++ b/lib/Slic3r/GUI/Plater/2DToolpaths.pm @@ -143,10 +143,16 @@ __PACKAGE__->mk_accessors(qw( sub new { my ($class, $parent, $print) = @_; - my $self = $class->SUPER::new($parent); + my $self = (Wx::wxVERSION >= 3.000003) ? + # The wxWidgets 3.0.3-beta have a bug, they crash with NULL attribute list. + $class->SUPER::new($parent, -1, Wx::wxDefaultPosition, Wx::wxDefaultSize, 0, "", + [WX_GL_RGBA, WX_GL_DOUBLEBUFFER, WX_GL_DEPTH_SIZE, 24, 0]) : + $class->SUPER::new($parent); + # Immediatelly force creation of the OpenGL context to consume the static variable s_wglContextAttribs. + $self->GetContext(); $self->print($print); $self->_zoom(1); - + # 2D point in model space $self->_camera_target(Slic3r::Pointf->new(0,0)); From b52d569aba7e1a4c6bcb5fefbcae128d755dbadd Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sat, 9 Jul 2016 14:13:28 -0500 Subject: [PATCH 41/58] Update CONTRIBUTING.md Added note about rejecting unrelated changes in pull requests. --- .github/CONTRIBUTING.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 4865b332df..004ad75e2c 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -29,5 +29,6 @@ Do you want to help fix issues in or add features to Slic3r? That's also very, v * If you're starting on an issue, please say something in the related issues thread so that someone else doesn't start working on it too. * If there's nothing in the [Pull Request or Bust](https://github.com/alexrj/Slic3r/milestones/Pull%20Request%20or%20Bust) milestone that interests you, the next place to look is for issues that don't have a milestone. Lots of people commit ideas to Slic3r, and it's difficult to keep up and sort through them. * Before sending a pull request, please make sure that the changes you are submitting are contained in their own git branch, as PRs merge histories. - * A common workflow is to fork the master branch, create your new branch and do your work there. git-rebase is also helpful for separating out unrelated changes. + * Pull requests that contain unrelated changes will be rejected. + * A common workflow is to fork the master branch, create your new branch and do your work there. git-rebase and git-cherry-pick are also helpful for separating out unrelated changes. * If you are pushing Slic3r code changes that touch the main application, it is very much appreciated if you write some tests that check the functionality of the code. It's much easier to vet and merge in code that includes tests and doing so will likely speed things up. From 8e5ff98c8d430f2c1bbd587869b011d32524fe55 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sat, 9 Jul 2016 19:41:26 -0500 Subject: [PATCH 42/58] Update package_win32.ps1 --- utils/package_win32.ps1 | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/utils/package_win32.ps1 b/utils/package_win32.ps1 index d67b285a48..114076586a 100644 --- a/utils/package_win32.ps1 +++ b/utils/package_win32.ps1 @@ -5,13 +5,13 @@ echo "Make this is run from the perl command window." echo "Requires PAR." -New-Variable -Name "current_branch" -Value "${APPVEYOR_REPO_BRANCH}" +New-Variable -Name "current_branch" -Value "" -#git branch | foreach { -# if ($_ -match "` (.*)"){ -# $current_branch += $matches[1] -# } -#} +git branch | foreach { + if ($_ -match "` (.*)"){ + $current_branch += $matches[1] + } +} # Change this to where you have Strawberry Perl installed. New-Variable -Name "STRAWBERRY_PATH" -Value "C:\Strawberry" From e05f8effe88cda2e30b9edf463270331043c0d3f Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sat, 9 Jul 2016 21:49:41 -0500 Subject: [PATCH 43/58] Change .travis.yml to build local Boost libs (#3403) Travis configuration now uses compiled boost (1.58.0), which is cached to avoid spending time on it again. --- .travis.yml | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9b71288081..14a95b8a52 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,16 @@ language: perl -install: export LDLOADLIBS=-lstdc++ -script: perl ./Build.PL +install: + - export LDLOADLIBS=-lstdc++ + - export BUILD_DIR=$(pwd) + - export FORCE_BOOST=1 + - cpanm local::lib + - eval "$(perl -I$HOME/perl5/lib/perl5 -Mlocal::lib)" + - export BOOST_DIR=$HOME/boost_1_58_0 + - if [ ! -d "$BOOST_DIR" ]; then wget https://sourceforge.net/projects/boost/files/boost/1.58.0/boost_1_58_0.tar.bz2; tar -xf boost_1_58_0.tar.bz2; mv boost_1_58_0 $HOME; cd $HOME/boost_1_58_0;$HOME/boost_1_58_0/bootstrap.sh gcc; $HOME/boost_1_58_0/b2; fi + - cd $BUILD_DIR +# Add our local boost version to the environment. + - export LD_LIBRARY_PATH=$HOME/boost_1_58_0/stage/lib:${LD_LIBRARY_PATH} +script: LIBRARY_PATH=$HOME/boost_1_58_0/stage/lib CPLUS_INCLUDE_PATH=$HOME/boost_1_58_0 perl ./Build.PL perl: - "5.14" - "5.18" @@ -11,11 +21,5 @@ branches: - stable sudo: false cache: - - apt -addons: - apt: - sources: - - boost-latest - packages: - - libboost-thread1.55-dev - - libboost-system1.55-dev + directories: + - $HOME/boost_1_58_0 From fc0c0ca1f0111ff493c6b3733438930b622c1cd7 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sun, 10 Jul 2016 12:25:25 +0200 Subject: [PATCH 44/58] Revert "Don't combine more layers than you have nozzle." This reverts commit 2ff9532f43b9375551035749d56382ed2cd86a7f. --- lib/Slic3r/Fill.pm | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/lib/Slic3r/Fill.pm b/lib/Slic3r/Fill.pm index 3bbe68ee98..9cb8319287 100644 --- a/lib/Slic3r/Fill.pm +++ b/lib/Slic3r/Fill.pm @@ -214,16 +214,14 @@ sub make_fill { # calculate flow spacing for infill pattern generation my $using_internal_flow = 0; - my $infill_combined_flow = $layerm->layer->object->config->layer_height * $layerm->region->config->infill_every_layers; # multiply the required layer height by infill_every_layers - if ($infill_combined_flow == 0) { - # just in case something happens we don't want to put in a 0mm layer. - $infill_combined_flow = $layerm->layer->object->config->layer_height; + my $infill_combined_flow = 0; # multiply the required layer height by infill_every_layers + if ($layerm->region->config->infill_every_layers > 1) { + $infill_combined_flow = + $layerm->layer->object->config->layer_height*$layerm->region->config->infill_every_layers; + } else { + $infill_combined_flow = + $layerm->layer->object->config->layer_height; } - if ($infill_combined_flow > $flow->nozzle_diameter) { - # can't put out layers bigger than the nozzle width, go as big as possible - $infill_combined_flow = (($flow->nozzle_diameter / $layerm->layer->object->config->layer_height) % 1) * $layerm->layer->object->config->layer_height - } - if (!$is_solid && !$is_bridge) { # it's internal infill, so we can calculate a generic flow spacing # for all layers, for avoiding the ugly effect of From fc8c16d33aea14f1ef0b8ec7c317e3f321d5c8c0 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sun, 10 Jul 2016 12:25:32 +0200 Subject: [PATCH 45/58] Revert "found the right spot for infill_every_layers." This reverts commit d1f6cdf55f87c2ecac52359d401c6103d2235c46. --- lib/Slic3r/Fill.pm | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/lib/Slic3r/Fill.pm b/lib/Slic3r/Fill.pm index 9cb8319287..960bae89c5 100644 --- a/lib/Slic3r/Fill.pm +++ b/lib/Slic3r/Fill.pm @@ -214,14 +214,6 @@ sub make_fill { # calculate flow spacing for infill pattern generation my $using_internal_flow = 0; - my $infill_combined_flow = 0; # multiply the required layer height by infill_every_layers - if ($layerm->region->config->infill_every_layers > 1) { - $infill_combined_flow = - $layerm->layer->object->config->layer_height*$layerm->region->config->infill_every_layers; - } else { - $infill_combined_flow = - $layerm->layer->object->config->layer_height; - } if (!$is_solid && !$is_bridge) { # it's internal infill, so we can calculate a generic flow spacing # for all layers, for avoiding the ugly effect of @@ -229,8 +221,7 @@ sub make_fill { # layer height my $internal_flow = $layerm->region->flow( FLOW_ROLE_INFILL, - $infill_combined_flow, - + $layerm->object->config->layer_height*$layerm->config->infill_every_layers, # TODO: handle infill_every_layers? 0, # no bridge 0, # no first layer -1, # auto width From 4b946f269ab50b7cbbe0a554b465341456d4c6ba Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sun, 10 Jul 2016 12:25:34 +0200 Subject: [PATCH 46/58] Revert "Small change to actually infill every layer. Should fix #1783, but there's side effects in that there's no check against the nozzle size." This reverts commit 86e1f2fb1173ed3071e41bf80bfaf3ae00cc4bd5. --- lib/Slic3r/Fill.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Slic3r/Fill.pm b/lib/Slic3r/Fill.pm index 960bae89c5..8c63fde596 100644 --- a/lib/Slic3r/Fill.pm +++ b/lib/Slic3r/Fill.pm @@ -221,7 +221,7 @@ sub make_fill { # layer height my $internal_flow = $layerm->region->flow( FLOW_ROLE_INFILL, - $layerm->object->config->layer_height*$layerm->config->infill_every_layers, # TODO: handle infill_every_layers? + $layerm->layer->object->config->layer_height, # TODO: handle infill_every_layers? 0, # no bridge 0, # no first layer -1, # auto width From 5a6d7bba8fdb063b0bedf32b19f03c9bec3f2a04 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sun, 10 Jul 2016 12:41:08 +0200 Subject: [PATCH 47/58] Mention all the omitted M-codes in the start_gcode tooltip. #3406 --- xs/src/libslic3r/PrintConfig.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xs/src/libslic3r/PrintConfig.cpp b/xs/src/libslic3r/PrintConfig.cpp index a505bd888f..90af82fbdf 100644 --- a/xs/src/libslic3r/PrintConfig.cpp +++ b/xs/src/libslic3r/PrintConfig.cpp @@ -1035,7 +1035,7 @@ PrintConfigDef::PrintConfigDef() def = this->add("start_gcode", coString); def->label = "Start G-code"; - def->tooltip = "This start procedure is inserted at the beginning, after bed has reached the target temperature and extruder just started heating, and before extruder has finished heating. If Slic3r detects M104 or M190 in your custom codes, such commands will not be prepended automatically so you're free to customize the order of heating commands and other custom actions. Note that you can use placeholder variables for all Slic3r settings, so you can put a \"M109 S[first_layer_temperature]\" command wherever you want."; + def->tooltip = "This start procedure is inserted at the beginning, after bed has reached the target temperature and extruder just started heating, and before extruder has finished heating. If Slic3r detects M104, M109, M140 or M190 in your custom codes, such commands will not be prepended automatically so you're free to customize the order of heating commands and other custom actions. Note that you can use placeholder variables for all Slic3r settings, so you can put a \"M109 S[first_layer_temperature]\" command wherever you want."; def->cli = "start-gcode=s"; def->multiline = true; def->full_width = true; From 96bf7b9d27fbf1b589c10506b07b2505e0d92a29 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sun, 10 Jul 2016 12:49:31 +0200 Subject: [PATCH 48/58] Fixed regression in TriangleMesh::merge() #3405 --- xs/src/libslic3r/TriangleMesh.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xs/src/libslic3r/TriangleMesh.cpp b/xs/src/libslic3r/TriangleMesh.cpp index cea6706e99..d2eb1a1177 100644 --- a/xs/src/libslic3r/TriangleMesh.cpp +++ b/xs/src/libslic3r/TriangleMesh.cpp @@ -346,8 +346,8 @@ TriangleMesh::merge(const TriangleMesh &mesh) stl_reallocate(&this->stl); // copy facets - std::copy(mesh.stl.facet_start, mesh.stl.facet_start + mesh.stl.stats.number_of_facets, this->stl.facet_start); - std::copy(mesh.stl.neighbors_start, mesh.stl.neighbors_start + mesh.stl.stats.number_of_facets, this->stl.neighbors_start); + std::copy(mesh.stl.facet_start, mesh.stl.facet_start + mesh.stl.stats.number_of_facets, this->stl.facet_start + number_of_facets); + std::copy(mesh.stl.neighbors_start, mesh.stl.neighbors_start + mesh.stl.stats.number_of_facets, this->stl.neighbors_start + number_of_facets); // update size stl_get_size(&this->stl); From 3daf64ae56bd8f7cc0de84c70ae1bf1973afc79e Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sun, 10 Jul 2016 13:09:06 +0200 Subject: [PATCH 49/58] Remove tabs and clean up code from 4c622c504f8f7c479a8368f7672ec96426391554 --- xs/src/libslic3r/GCode.cpp | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/xs/src/libslic3r/GCode.cpp b/xs/src/libslic3r/GCode.cpp index 32787d7654..41a8671a6b 100644 --- a/xs/src/libslic3r/GCode.cpp +++ b/xs/src/libslic3r/GCode.cpp @@ -632,17 +632,12 @@ GCode::travel_to(const Point &point, ExtrusionRole role, std::string comment) // use G1 because we rely on paths being straight (G0 may make round paths) Lines lines = travel.lines(); - double path_length = 0; - for (Lines::const_iterator line = lines.begin(); line != lines.end(); ++line) { - const double line_length = line->length() * SCALING_FACTOR; - path_length += line_length; - - gcode += this->writer.travel_to_xy(this->point_to_gcode(line->b), comment); - } - + for (Lines::const_iterator line = lines.begin(); line != lines.end(); ++line) + gcode += this->writer.travel_to_xy(this->point_to_gcode(line->b), comment); + if (this->config.cooling) - this->elapsed_time += path_length / this->config.get_abs_value("travel_speed"); - + this->elapsed_time += travel.length() / this->config.get_abs_value("travel_speed"); + return gcode; } From 6f1d1f6af77b2c452c170d59130020599428bd5d Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sun, 10 Jul 2016 13:38:33 +0200 Subject: [PATCH 50/58] Some cleanup and further optimization to 5f521b24c42ed657967b919871900fa6a65ba790. #3293 --- lib/Slic3r/Print/GCode.pm | 21 +++++++++------------ xs/src/libslic3r/BoundingBox.cpp | 9 +++++++++ xs/src/libslic3r/BoundingBox.hpp | 1 + xs/xsp/BoundingBox.xsp | 2 ++ 4 files changed, 21 insertions(+), 12 deletions(-) diff --git a/lib/Slic3r/Print/GCode.pm b/lib/Slic3r/Print/GCode.pm index 02b9d4d746..3c32875edb 100644 --- a/lib/Slic3r/Print/GCode.pm +++ b/lib/Slic3r/Print/GCode.pm @@ -490,21 +490,18 @@ sub process_layer { # group extrusions by extruder and then by island my %by_extruder = (); # extruder_id => [ { perimeters => \@perimeters, infill => \@infill } ] - - my $n_slices = $#{$layer->slices}; - my @layer_surface_bboxes = (); - for my $i (0 .. $n_slices) { - push @layer_surface_bboxes, $layer->slices->[$i]->contour->bounding_box; - } + + # cache bounding boxes of layer slices + my @layer_slices_bb = map $_->contour->bounding_box, @{$layer->slices}; my $point_inside_surface = sub { my ($i, $point) = @_; - my $bbox = $layer_surface_bboxes[$i]; - return - $point->x >= $bbox->x_min && $point->x < $bbox->x_max && - $point->y >= $bbox->y_min && $point->y < $bbox->y_max && - $layer->slices->[$i]->contour->contains_point($point); + + my $bbox = $layer_slices_bb[$i]; + return $layer_slices_bb[$i]->contains_point($point) + && $layer->slices->[$i]->contour->contains_point($point); }; - + + my $n_slices = $layer->slices->count - 1; foreach my $region_id (0..($self->print->region_count-1)) { my $layerm = $layer->regions->[$region_id] or next; my $region = $self->print->get_region($region_id); diff --git a/xs/src/libslic3r/BoundingBox.cpp b/xs/src/libslic3r/BoundingBox.cpp index 1116d2dcbe..3ec2258a93 100644 --- a/xs/src/libslic3r/BoundingBox.cpp +++ b/xs/src/libslic3r/BoundingBox.cpp @@ -219,4 +219,13 @@ BoundingBox3Base::center() const } template Pointf3 BoundingBox3Base::center() const; +template bool +BoundingBoxBase::contains(const PointClass &point) const +{ + return point.x >= this->min.x && point.x <= this->max.x + && point.y >= this->min.y && point.y <= this->max.y; +} +template bool BoundingBoxBase::contains(const Point &point) const; +template bool BoundingBoxBase::contains(const Pointf &point) const; + } diff --git a/xs/src/libslic3r/BoundingBox.hpp b/xs/src/libslic3r/BoundingBox.hpp index 533a19b56e..3fd6008a5a 100644 --- a/xs/src/libslic3r/BoundingBox.hpp +++ b/xs/src/libslic3r/BoundingBox.hpp @@ -30,6 +30,7 @@ class BoundingBoxBase void translate(coordf_t x, coordf_t y); void offset(coordf_t delta); PointClass center() const; + bool contains(const PointClass &point) const; }; template diff --git a/xs/xsp/BoundingBox.xsp b/xs/xsp/BoundingBox.xsp index db424ff29b..9da9173aa9 100644 --- a/xs/xsp/BoundingBox.xsp +++ b/xs/xsp/BoundingBox.xsp @@ -16,6 +16,7 @@ void scale(double factor); void translate(double x, double y); void offset(double delta); + bool contains_point(Point* point) %code{% RETVAL = THIS->contains(*point); %}; Clone polygon(); Clone size(); Clone center(); @@ -49,6 +50,7 @@ new_from_points(CLASS, points) void merge_point(Pointf* point) %code{% THIS->merge(*point); %}; void scale(double factor); void translate(double x, double y); + bool contains_point(Pointf* point) %code{% RETVAL = THIS->contains(*point); %}; Clone size(); Clone center(); Clone min_point() %code{% RETVAL = THIS->min; %}; From f352406c33011ff7be68242a9a830510ee683685 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sun, 10 Jul 2016 14:35:53 +0200 Subject: [PATCH 51/58] Prevent variable-width logic from causing negative extrusion. #3220 --- xs/src/libslic3r/PerimeterGenerator.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/xs/src/libslic3r/PerimeterGenerator.cpp b/xs/src/libslic3r/PerimeterGenerator.cpp index 7bb207e000..f9e6a8c6e6 100644 --- a/xs/src/libslic3r/PerimeterGenerator.cpp +++ b/xs/src/libslic3r/PerimeterGenerator.cpp @@ -492,16 +492,20 @@ PerimeterGenerator::_variable_width(const ThickPolylines &polylines, ExtrusionRo const double w = fmax(line.a_width, line.b_width); if (path.polyline.points.empty()) { - path.polyline.append(line.a); - path.polyline.append(line.b); - flow.width = unscale(w); #ifdef SLIC3R_DEBUG printf(" filling %f gap\n", flow.width); #endif + + // make sure we don't include too thin segments which + // may cause even slightly negative mm3_per_mm because of floating point math path.mm3_per_mm = flow.mm3_per_mm(); + if (path.mm3_per_mm < EPSILON) continue; + path.width = flow.width; path.height = flow.height; + path.polyline.append(line.a); + path.polyline.append(line.b); } else { thickness_delta = fabs(scale_(flow.width) - w); if (thickness_delta <= tolerance) { From 1d510f76dbec34fdda0db2e3fb8635dc3475a728 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sun, 10 Jul 2016 14:45:12 +0200 Subject: [PATCH 52/58] Update error message with machinekit. #2742 --- lib/Slic3r/Config.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Slic3r/Config.pm b/lib/Slic3r/Config.pm index 5598339870..bfbeee88cb 100644 --- a/lib/Slic3r/Config.pm +++ b/lib/Slic3r/Config.pm @@ -235,7 +235,7 @@ sub validate { die "Invalid value for --gcode-flavor\n" if !first { $_ eq $self->gcode_flavor } @{$Options->{gcode_flavor}{values}}; - die "--use-firmware-retraction is only supported by Marlin firmware\n" + die "--use-firmware-retraction is only supported by Marlin and Machinekit firmware\n" if $self->use_firmware_retraction && $self->gcode_flavor ne 'smoothie' && $self->gcode_flavor ne 'reprap' && $self->gcode_flavor ne 'machinekit'; die "--use-firmware-retraction is not compatible with --wipe\n" From 7d4d6fed7d8f589ebc141966034e0862b7012b74 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 10 Jul 2016 10:21:51 -0500 Subject: [PATCH 53/58] Add boost-filesystem to list of dependencies back to using packages, hopefully it works. --- .travis.yml | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/.travis.yml b/.travis.yml index 14a95b8a52..f25d6bcbdb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,16 +1,6 @@ language: perl -install: - - export LDLOADLIBS=-lstdc++ - - export BUILD_DIR=$(pwd) - - export FORCE_BOOST=1 - - cpanm local::lib - - eval "$(perl -I$HOME/perl5/lib/perl5 -Mlocal::lib)" - - export BOOST_DIR=$HOME/boost_1_58_0 - - if [ ! -d "$BOOST_DIR" ]; then wget https://sourceforge.net/projects/boost/files/boost/1.58.0/boost_1_58_0.tar.bz2; tar -xf boost_1_58_0.tar.bz2; mv boost_1_58_0 $HOME; cd $HOME/boost_1_58_0;$HOME/boost_1_58_0/bootstrap.sh gcc; $HOME/boost_1_58_0/b2; fi - - cd $BUILD_DIR -# Add our local boost version to the environment. - - export LD_LIBRARY_PATH=$HOME/boost_1_58_0/stage/lib:${LD_LIBRARY_PATH} -script: LIBRARY_PATH=$HOME/boost_1_58_0/stage/lib CPLUS_INCLUDE_PATH=$HOME/boost_1_58_0 perl ./Build.PL +install: export LDLOADLIBS=-lstdc++ +script: perl ./Build.PL perl: - "5.14" - "5.18" @@ -21,5 +11,12 @@ branches: - stable sudo: false cache: - directories: - - $HOME/boost_1_58_0 + - apt +addons: + apt: + sources: + - boost-latest + packages: + - libboost-thread1.55-dev + - libboost-system1.55-dev + - libboost-filesystem1.55-dev From 5346894accee42a35882c1b7f9d7e01250aa87f1 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Tue, 12 Jul 2016 13:44:37 +0200 Subject: [PATCH 54/58] New extrude-tin utility --- src/CMakeLists.txt | 99 +++++++++++++++++++------------ src/utils/extrude-tin.cpp | 94 +++++++++++++++++++++++++++++ xs/src/admesh/stl.h | 1 + xs/src/admesh/util.c | 2 +- xs/src/libslic3r/Config.cpp | 4 +- xs/src/libslic3r/Config.hpp | 3 + xs/src/libslic3r/IO.cpp | 10 +++- xs/src/libslic3r/IO.hpp | 1 + xs/src/libslic3r/TriangleMesh.cpp | 54 +++++++++-------- xs/src/libslic3r/TriangleMesh.hpp | 1 + 10 files changed, 204 insertions(+), 65 deletions(-) create mode 100644 src/utils/extrude-tin.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index acd711e772..efeaa41de4 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -34,49 +34,71 @@ include_directories(${LIBDIR}/admesh/) include_directories(${LIBDIR}/poly2tri/) include_directories(${LIBDIR}/poly2tri/sweep) include_directories(${LIBDIR}/poly2tri/common) -add_library(libslic3r STATIC ${LIBDIR}/libslic3r/BoundingBox.cpp - ${LIBDIR}/libslic3r/ExPolygon.cpp - ${LIBDIR}/libslic3r/GCode.cpp - ${LIBDIR}/libslic3r/LayerRegion.cpp - ${LIBDIR}/libslic3r/PerimeterGenerator.cpp - ${LIBDIR}/libslic3r/Polyline.cpp - ${LIBDIR}/libslic3r/SurfaceCollection.cpp - ${LIBDIR}/libslic3r/BridgeDetector.cpp - ${LIBDIR}/libslic3r/Extruder.cpp - ${LIBDIR}/libslic3r/GCodeSender.cpp - ${LIBDIR}/libslic3r/IO.cpp - ${LIBDIR}/libslic3r/Line.cpp - ${LIBDIR}/libslic3r/PlaceholderParser.cpp - ${LIBDIR}/libslic3r/PrintConfig.cpp - ${LIBDIR}/libslic3r/Surface.cpp - ${LIBDIR}/libslic3r/ClipperUtils.cpp - ${LIBDIR}/libslic3r/ExtrusionEntityCollection.cpp - ${LIBDIR}/libslic3r/GCodeWriter.cpp - ${LIBDIR}/libslic3r/Model.cpp - ${LIBDIR}/libslic3r/Point.cpp - ${LIBDIR}/libslic3r/Print.cpp - ${LIBDIR}/libslic3r/SVG.cpp - ${LIBDIR}/libslic3r/SVGExport.cpp - ${LIBDIR}/libslic3r/Config.cpp - ${LIBDIR}/libslic3r/ExtrusionEntity.cpp - ${LIBDIR}/libslic3r/Geometry.cpp - ${LIBDIR}/libslic3r/MotionPlanner.cpp - ${LIBDIR}/libslic3r/Polygon.cpp - ${LIBDIR}/libslic3r/PrintObject.cpp - ${LIBDIR}/libslic3r/TriangleMesh.cpp - ${LIBDIR}/libslic3r/ExPolygonCollection.cpp - ${LIBDIR}/libslic3r/Flow.cpp - ${LIBDIR}/libslic3r/Layer.cpp - ${LIBDIR}/libslic3r/MultiPoint.cpp - ${LIBDIR}/libslic3r/PolylineCollection.cpp - ${LIBDIR}/libslic3r/PrintRegion.cpp) -add_library(admesh STATIC ${LIBDIR}/admesh/util.c ${LIBDIR}/admesh/stl_io.c ${LIBDIR}/admesh/stlinit.c ${LIBDIR}/admesh/shared.c ${LIBDIR}/admesh/normals.c ${LIBDIR}/admesh/connect.c) + +add_library(libslic3r STATIC + ${LIBDIR}/libslic3r/BoundingBox.cpp + ${LIBDIR}/libslic3r/BridgeDetector.cpp + ${LIBDIR}/libslic3r/ClipperUtils.cpp + ${LIBDIR}/libslic3r/Config.cpp + ${LIBDIR}/libslic3r/ExPolygon.cpp + ${LIBDIR}/libslic3r/ExPolygonCollection.cpp + ${LIBDIR}/libslic3r/Extruder.cpp + ${LIBDIR}/libslic3r/ExtrusionEntity.cpp + ${LIBDIR}/libslic3r/ExtrusionEntityCollection.cpp + ${LIBDIR}/libslic3r/Flow.cpp + ${LIBDIR}/libslic3r/GCode.cpp + ${LIBDIR}/libslic3r/GCodeSender.cpp + ${LIBDIR}/libslic3r/GCodeWriter.cpp + ${LIBDIR}/libslic3r/Geometry.cpp + ${LIBDIR}/libslic3r/IO.cpp + ${LIBDIR}/libslic3r/Layer.cpp + ${LIBDIR}/libslic3r/LayerRegion.cpp + ${LIBDIR}/libslic3r/Line.cpp + ${LIBDIR}/libslic3r/Model.cpp + ${LIBDIR}/libslic3r/MotionPlanner.cpp + ${LIBDIR}/libslic3r/MultiPoint.cpp + ${LIBDIR}/libslic3r/PerimeterGenerator.cpp + ${LIBDIR}/libslic3r/PlaceholderParser.cpp + ${LIBDIR}/libslic3r/Point.cpp + ${LIBDIR}/libslic3r/Polygon.cpp + ${LIBDIR}/libslic3r/Polyline.cpp + ${LIBDIR}/libslic3r/PolylineCollection.cpp + ${LIBDIR}/libslic3r/Print.cpp + ${LIBDIR}/libslic3r/PrintConfig.cpp + ${LIBDIR}/libslic3r/PrintObject.cpp + ${LIBDIR}/libslic3r/PrintRegion.cpp + ${LIBDIR}/libslic3r/Surface.cpp + ${LIBDIR}/libslic3r/SurfaceCollection.cpp + ${LIBDIR}/libslic3r/SVG.cpp + ${LIBDIR}/libslic3r/SVGExport.cpp + ${LIBDIR}/libslic3r/TriangleMesh.cpp +) +add_library(admesh STATIC + ${LIBDIR}/admesh/connect.c + ${LIBDIR}/admesh/normals.c + ${LIBDIR}/admesh/shared.c + ${LIBDIR}/admesh/stl_io.c + ${LIBDIR}/admesh/stlinit.c + ${LIBDIR}/admesh/util.c +) add_library(clipper STATIC ${LIBDIR}/clipper.cpp) add_library(polypartition STATIC ${LIBDIR}/polypartition.cpp) -add_library(poly2tri STATIC ${LIBDIR}/poly2tri/sweep/sweep.cc ${LIBDIR}/poly2tri/sweep/sweep_context.cc ${LIBDIR}/poly2tri/sweep/cdt.cc ${LIBDIR}/poly2tri/sweep/advancing_front.cc ${LIBDIR}/poly2tri/common/shapes.cc) +add_library(poly2tri STATIC + ${LIBDIR}/poly2tri/common/shapes.cc + ${LIBDIR}/poly2tri/sweep/advancing_front.cc + ${LIBDIR}/poly2tri/sweep/cdt.cc + ${LIBDIR}/poly2tri/sweep/sweep_context.cc + ${LIBDIR}/poly2tri/sweep/sweep.cc +) + add_executable(slic3r slic3r.cpp) set_target_properties(slic3r PROPERTIES LINK_SEARCH_START_STATIC 1) set_target_properties(slic3r PROPERTIES LINK_SEARCH_END_STATIC 1) + +add_executable(extrude-tin utils/extrude-tin.cpp) +set_target_properties(extrude-tin PROPERTIES LINK_SEARCH_START_STATIC 1) +set_target_properties(extrude-tin PROPERTIES LINK_SEARCH_END_STATIC 1) + set(wxWidgets_USE_STATIC) SET(wxWidgets_USE_LIBS) @@ -109,3 +131,4 @@ ELSE(wxWidgets_FOUND) #skip gui when no wx included ENDIF(wxWidgets_FOUND) +target_link_libraries (extrude-tin libslic3r admesh clipper polypartition poly2tri ${Boost_LIBRARIES}) diff --git a/src/utils/extrude-tin.cpp b/src/utils/extrude-tin.cpp new file mode 100644 index 0000000000..16330b86b0 --- /dev/null +++ b/src/utils/extrude-tin.cpp @@ -0,0 +1,94 @@ +#include "Config.hpp" +#include "Model.hpp" +#include "IO.hpp" +#include "TriangleMesh.hpp" +#include "libslic3r.h" + +using namespace Slic3r; + +void confess_at(const char *file, int line, const char *func, const char *pat, ...){} + +int +main(const int argc, const char **argv) +{ + // read config + ConfigDef config_def; + { + ConfigOptionDef* def; + + def = config_def.add("offset", coFloat); + def->label = "Offset from the lowest point (min thickness)"; + def->cli = "offset"; + def->default_value = new ConfigOptionFloat(1); + + def = config_def.add("output", coString); + def->label = "Output File"; + def->tooltip = "The file where the output will be written (if not specified, it will be based on the input file)."; + def->cli = "output"; + def->default_value = new ConfigOptionString(""); + } + DynamicConfig config(&config_def); + t_config_option_keys input_files; + config.read_cli(argc, argv, &input_files); + + for (t_config_option_keys::const_iterator it = input_files.begin(); it != input_files.end(); ++it) { + TriangleMesh mesh; + Slic3r::IO::STL::read(*it, &mesh); + calculate_normals(&mesh.stl); + + if (mesh.facets_count() == 0) { + printf("Error: file is empty: %s\n", it->c_str()); + continue; + } + + float z = mesh.stl.stats.min.z - config.option("offset", true)->getFloat(); + printf("min.z = %f, z = %f\n", mesh.stl.stats.min.z, z); + TriangleMesh mesh2 = mesh; + + for (int i = 0; i < mesh.stl.stats.number_of_facets; ++i) { + const stl_facet &facet = mesh.stl.facet_start[i]; + + if (facet.normal.z < 0) { + printf("Invalid 2.5D mesh / TIN (one facet points downwards = %f)\n", facet.normal.z); + exit(1); + } + + for (int j = 0; j < 3; ++j) { + if (mesh.stl.neighbors_start[i].neighbor[j] == -1) { + stl_facet new_facet; + float normal[3]; + + // first triangle + new_facet.vertex[0] = new_facet.vertex[2] = facet.vertex[(j+1)%3]; + new_facet.vertex[1] = facet.vertex[j]; + new_facet.vertex[2].z = z; + stl_calculate_normal(normal, &new_facet); + stl_normalize_vector(normal); + new_facet.normal.x = normal[0]; + new_facet.normal.y = normal[1]; + new_facet.normal.z = normal[2]; + stl_add_facet(&mesh2.stl, &new_facet); + + // second triangle + new_facet.vertex[0] = new_facet.vertex[1] = facet.vertex[j]; + new_facet.vertex[2] = facet.vertex[(j+1)%3]; + new_facet.vertex[1].z = new_facet.vertex[2].z = z; + new_facet.normal.x = normal[0]; + new_facet.normal.y = normal[1]; + new_facet.normal.z = normal[2]; + stl_add_facet(&mesh2.stl, &new_facet); + } + } + } + + mesh2.repair(); + + std::string outfile = config.option("output", true)->getString(); + if (outfile.empty()) outfile = *it + "_extruded.stl"; + + Slic3r::IO::STL::write(mesh2, outfile); + printf("Extuded mesh written to %s\n", outfile.c_str()); + } + + return 0; +} diff --git a/xs/src/admesh/stl.h b/xs/src/admesh/stl.h index 3013a887c9..b2be5830e4 100644 --- a/xs/src/admesh/stl.h +++ b/xs/src/admesh/stl.h @@ -162,6 +162,7 @@ extern void stl_translate(stl_file *stl, float x, float y, float z); extern void stl_translate_relative(stl_file *stl, float x, float y, float z); extern void stl_scale_versor(stl_file *stl, float versor[3]); extern void stl_scale(stl_file *stl, float factor); +extern void calculate_normals(stl_file *stl); extern void stl_rotate_x(stl_file *stl, float angle); extern void stl_rotate_y(stl_file *stl, float angle); extern void stl_rotate_z(stl_file *stl, float angle); diff --git a/xs/src/admesh/util.c b/xs/src/admesh/util.c index f29ba16142..15f4054681 100644 --- a/xs/src/admesh/util.c +++ b/xs/src/admesh/util.c @@ -170,7 +170,7 @@ stl_scale(stl_file *stl, float factor) { stl_scale_versor(stl, versor); } -static void calculate_normals(stl_file *stl) { +void calculate_normals(stl_file *stl) { long i; float normal[3]; diff --git a/xs/src/libslic3r/Config.cpp b/xs/src/libslic3r/Config.cpp index 778c984ed8..dbc3ca89b4 100644 --- a/xs/src/libslic3r/Config.cpp +++ b/xs/src/libslic3r/Config.cpp @@ -220,7 +220,9 @@ DynamicConfig::optptr(const t_config_option_key &opt_key, bool create) { const ConfigOptionDef* optdef = this->def->get(opt_key); if (optdef == NULL) return NULL; ConfigOption* opt; - if (optdef->type == coFloat) { + if (optdef->default_value != NULL) { + opt = optdef->default_value->clone(); + } else if (optdef->type == coFloat) { opt = new ConfigOptionFloat (); } else if (optdef->type == coFloats) { opt = new ConfigOptionFloats (); diff --git a/xs/src/libslic3r/Config.hpp b/xs/src/libslic3r/Config.hpp index a8a54baa19..acbbaf9ff2 100644 --- a/xs/src/libslic3r/Config.hpp +++ b/xs/src/libslic3r/Config.hpp @@ -28,6 +28,7 @@ class ConfigOption { virtual double getFloat() const { return 0; }; virtual bool getBool() const { return false; }; virtual void setInt(int val) {}; + virtual std::string getString() const { return ""; }; friend bool operator== (const ConfigOption &a, const ConfigOption &b); friend bool operator!= (const ConfigOption &a, const ConfigOption &b); }; @@ -206,6 +207,8 @@ class ConfigOptionString : public ConfigOptionSingle ConfigOptionString(std::string _value) : ConfigOptionSingle(_value) {}; ConfigOptionString* clone() const { return new ConfigOptionString(this->value); }; + std::string getString() const { return this->value; }; + std::string serialize() const { std::string str = this->value; diff --git a/xs/src/libslic3r/IO.cpp b/xs/src/libslic3r/IO.cpp index ee81924e5c..47768817cb 100644 --- a/xs/src/libslic3r/IO.cpp +++ b/xs/src/libslic3r/IO.cpp @@ -5,6 +5,14 @@ namespace Slic3r { namespace IO { +bool +STL::read(std::string input_file, TriangleMesh* mesh) +{ + mesh->ReadSTLFile(input_file); + mesh->check_topology(); + return true; +} + bool STL::read(std::string input_file, Model* model) { @@ -12,7 +20,7 @@ STL::read(std::string input_file, Model* model) // TODO: check that file exists TriangleMesh mesh; - mesh.ReadSTLFile(input_file); + if (!STL::read(input_file, &mesh)) return false; mesh.repair(); if (mesh.facets_count() == 0) diff --git a/xs/src/libslic3r/IO.hpp b/xs/src/libslic3r/IO.hpp index 0fe76a0681..6efb1e8ee7 100644 --- a/xs/src/libslic3r/IO.hpp +++ b/xs/src/libslic3r/IO.hpp @@ -11,6 +11,7 @@ namespace Slic3r { namespace IO { class STL { public: + static bool read(std::string input_file, TriangleMesh* mesh); static bool read(std::string input_file, Model* model); static bool write(TriangleMesh& mesh, std::string output_file, bool binary = true); }; diff --git a/xs/src/libslic3r/TriangleMesh.cpp b/xs/src/libslic3r/TriangleMesh.cpp index d2eb1a1177..931292cce2 100644 --- a/xs/src/libslic3r/TriangleMesh.cpp +++ b/xs/src/libslic3r/TriangleMesh.cpp @@ -89,30 +89,7 @@ TriangleMesh::repair() { // admesh fails when repairing empty meshes if (this->stl.stats.number_of_facets == 0) return; - // checking exact - stl_check_facets_exact(&stl); - stl.stats.facets_w_1_bad_edge = (stl.stats.connected_facets_2_edge - stl.stats.connected_facets_3_edge); - stl.stats.facets_w_2_bad_edge = (stl.stats.connected_facets_1_edge - stl.stats.connected_facets_2_edge); - stl.stats.facets_w_3_bad_edge = (stl.stats.number_of_facets - stl.stats.connected_facets_1_edge); - - // checking nearby - //int last_edges_fixed = 0; - float tolerance = stl.stats.shortest_edge; - float increment = stl.stats.bounding_diameter / 10000.0; - int iterations = 2; - if (stl.stats.connected_facets_3_edge < stl.stats.number_of_facets) { - for (int i = 0; i < iterations; i++) { - if (stl.stats.connected_facets_3_edge < stl.stats.number_of_facets) { - //printf("Checking nearby. Tolerance= %f Iteration=%d of %d...", tolerance, i + 1, iterations); - stl_check_facets_nearby(&stl, tolerance); - //printf(" Fixed %d edges.\n", stl.stats.edges_fixed - last_edges_fixed); - //last_edges_fixed = stl.stats.edges_fixed; - tolerance += increment; - } else { - break; - } - } - } + this->check_topology(); // remove_unconnected if (stl.stats.connected_facets_3_edge < stl.stats.number_of_facets) { @@ -140,6 +117,35 @@ TriangleMesh::repair() { this->repaired = true; } +void +TriangleMesh::check_topology() +{ + // checking exact + stl_check_facets_exact(&stl); + stl.stats.facets_w_1_bad_edge = (stl.stats.connected_facets_2_edge - stl.stats.connected_facets_3_edge); + stl.stats.facets_w_2_bad_edge = (stl.stats.connected_facets_1_edge - stl.stats.connected_facets_2_edge); + stl.stats.facets_w_3_bad_edge = (stl.stats.number_of_facets - stl.stats.connected_facets_1_edge); + + // checking nearby + //int last_edges_fixed = 0; + float tolerance = stl.stats.shortest_edge; + float increment = stl.stats.bounding_diameter / 10000.0; + int iterations = 2; + if (stl.stats.connected_facets_3_edge < stl.stats.number_of_facets) { + for (int i = 0; i < iterations; i++) { + if (stl.stats.connected_facets_3_edge < stl.stats.number_of_facets) { + //printf("Checking nearby. Tolerance= %f Iteration=%d of %d...", tolerance, i + 1, iterations); + stl_check_facets_nearby(&stl, tolerance); + //printf(" Fixed %d edges.\n", stl.stats.edges_fixed - last_edges_fixed); + //last_edges_fixed = stl.stats.edges_fixed; + tolerance += increment; + } else { + break; + } + } + } +} + void TriangleMesh::reset_repair_stats() { this->stl.stats.degenerate_facets = 0; diff --git a/xs/src/libslic3r/TriangleMesh.hpp b/xs/src/libslic3r/TriangleMesh.hpp index f0dd66fbad..2a2a6dbd2d 100644 --- a/xs/src/libslic3r/TriangleMesh.hpp +++ b/xs/src/libslic3r/TriangleMesh.hpp @@ -28,6 +28,7 @@ class TriangleMesh void write_ascii(const std::string &output_file); void write_binary(const std::string &output_file); void repair(); + void check_topology(); void WriteOBJFile(const std::string &output_file); void scale(float factor); void scale(const Pointf3 &versor); From eb491056d88876cc9bd6e958191325ec499cb04a Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Tue, 12 Jul 2016 16:18:22 +0200 Subject: [PATCH 55/58] Typo --- src/utils/extrude-tin.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/extrude-tin.cpp b/src/utils/extrude-tin.cpp index 16330b86b0..d2b9b49e64 100644 --- a/src/utils/extrude-tin.cpp +++ b/src/utils/extrude-tin.cpp @@ -87,7 +87,7 @@ main(const int argc, const char **argv) if (outfile.empty()) outfile = *it + "_extruded.stl"; Slic3r::IO::STL::write(mesh2, outfile); - printf("Extuded mesh written to %s\n", outfile.c_str()); + printf("Extruded mesh written to %s\n", outfile.c_str()); } return 0; From c2b06b22aa81a4eb612ea7a442901ec1d9521d9e Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sun, 17 Jul 2016 13:13:51 +0200 Subject: [PATCH 56/58] Change output format for --info --- src/slic3r.cpp | 4 ++ xs/src/libslic3r/IO.cpp | 1 - xs/src/libslic3r/Model.cpp | 64 +++++++++++++++++++++++-------- xs/src/libslic3r/Model.hpp | 2 + xs/src/libslic3r/SVGExport.hpp | 4 +- xs/src/libslic3r/TriangleMesh.cpp | 15 +++++++- xs/src/libslic3r/TriangleMesh.hpp | 2 + 7 files changed, 70 insertions(+), 22 deletions(-) diff --git a/src/slic3r.cpp b/src/slic3r.cpp index ac888deebe..23cd8c7ff7 100644 --- a/src/slic3r.cpp +++ b/src/slic3r.cpp @@ -62,12 +62,14 @@ main(const int argc, const char **argv) for (std::vector::iterator model = models.begin(); model != models.end(); ++model) { if (cli_config.info) { + // --info works on unrepaired model model->print_info(); } else if (cli_config.export_obj) { std::string outfile = cli_config.output.value; if (outfile.empty()) outfile = model->objects.front()->input_file + ".obj"; TriangleMesh mesh = model->mesh(); + mesh.repair(); Slic3r::IO::OBJ::write(mesh, outfile); printf("File exported to %s\n", outfile.c_str()); } else if (cli_config.export_pov) { @@ -75,6 +77,7 @@ main(const int argc, const char **argv) if (outfile.empty()) outfile = model->objects.front()->input_file + ".pov"; TriangleMesh mesh = model->mesh(); + mesh.repair(); Slic3r::IO::POV::write(mesh, outfile); printf("File exported to %s\n", outfile.c_str()); } else if (cli_config.export_svg) { @@ -82,6 +85,7 @@ main(const int argc, const char **argv) if (outfile.empty()) outfile = model->objects.front()->input_file + ".svg"; SVGExport svg_export(model->mesh()); + svg_export.mesh.repair(); svg_export.config.apply(print_config, true); svg_export.writeSVG(outfile); printf("SVG file exported to %s\n", outfile.c_str()); diff --git a/xs/src/libslic3r/IO.cpp b/xs/src/libslic3r/IO.cpp index 47768817cb..809a7b3bf2 100644 --- a/xs/src/libslic3r/IO.cpp +++ b/xs/src/libslic3r/IO.cpp @@ -21,7 +21,6 @@ STL::read(std::string input_file, Model* model) TriangleMesh mesh; if (!STL::read(input_file, &mesh)) return false; - mesh.repair(); if (mesh.facets_count() == 0) throw std::runtime_error("This STL file couldn't be read because it's empty."); diff --git a/xs/src/libslic3r/Model.cpp b/xs/src/libslic3r/Model.cpp index ee389e5173..72c779339b 100644 --- a/xs/src/libslic3r/Model.cpp +++ b/xs/src/libslic3r/Model.cpp @@ -161,6 +161,13 @@ Model::bounding_box() const return bb; } +void +Model::repair() +{ + for (ModelObjectPtrs::const_iterator o = this->objects.begin(); o != this->objects.end(); ++o) + (*o)->repair(); +} + void Model::center_instances_around_point(const Pointf &point) { @@ -480,6 +487,13 @@ ModelObject::update_bounding_box() this->_bounding_box_valid = true; } +void +ModelObject::repair() +{ + for (ModelVolumePtrs::const_iterator v = this->volumes.begin(); v != this->volumes.end(); ++v) + (*v)->mesh.repair(); +} + // flattens all volumes and instances into a single mesh TriangleMesh ModelObject::mesh() const @@ -720,26 +734,42 @@ void ModelObject::print_info() const { using namespace std; - cout << "Info about " << boost::filesystem::basename(this->input_file) << ":" << endl; + cout << "[" << boost::filesystem::path(this->input_file).filename().string() << "]" << endl; TriangleMesh mesh = this->raw_mesh(); - mesh.repair(); - Sizef3 size = mesh.bounding_box().size(); - cout << " size: x=" << size.x << " y=" << size.y << " z=" << size.z << endl; - cout << " number of facets: " << mesh.stl.stats.number_of_facets << endl; - cout << " number of shells: " << mesh.stl.stats.number_of_parts << endl; - cout << " volume: " << mesh.stl.stats.volume << endl; - if (this->needed_repair()) { - cout << " needed repair: yes" << endl; - cout << " degenerate facets: " << mesh.stl.stats.degenerate_facets << endl; - cout << " edges fixed: " << mesh.stl.stats.edges_fixed << endl; - cout << " facets removed: " << mesh.stl.stats.facets_removed << endl; - cout << " facets added: " << mesh.stl.stats.facets_added << endl; - cout << " facets reversed: " << mesh.stl.stats.facets_reversed << endl; - cout << " backwards edges: " << mesh.stl.stats.backwards_edges << endl; - } else { - cout << " needed repair: no" << endl; + mesh.check_topology(); + BoundingBoxf3 bb = mesh.bounding_box(); + Sizef3 size = bb.size(); + cout << "size_x = " << size.x << endl; + cout << "size_y = " << size.y << endl; + cout << "size_z = " << size.z << endl; + cout << "min_x = " << bb.min.x << endl; + cout << "min_y = " << bb.min.y << endl; + cout << "min_z = " << bb.min.z << endl; + cout << "max_x = " << bb.max.x << endl; + cout << "max_y = " << bb.max.y << endl; + cout << "max_z = " << bb.max.z << endl; + cout << "number_of_facets = " << mesh.stl.stats.number_of_facets << endl; + cout << "manifold = " << (mesh.is_manifold() ? "yes" : "no") << endl; + + mesh.repair(); // this calculates number_of_parts + if (mesh.needed_repair()) { + mesh.repair(); + if (mesh.stl.stats.degenerate_facets > 0) + cout << "degenerate_facets = " << mesh.stl.stats.degenerate_facets << endl; + if (mesh.stl.stats.edges_fixed > 0) + cout << "edges_fixed = " << mesh.stl.stats.edges_fixed << endl; + if (mesh.stl.stats.facets_removed > 0) + cout << "facets_removed = " << mesh.stl.stats.facets_removed << endl; + if (mesh.stl.stats.facets_added > 0) + cout << "facets_added = " << mesh.stl.stats.facets_added << endl; + if (mesh.stl.stats.facets_reversed > 0) + cout << "facets_reversed = " << mesh.stl.stats.facets_reversed << endl; + if (mesh.stl.stats.backwards_edges > 0) + cout << "backwards_edges = " << mesh.stl.stats.backwards_edges << endl; } + cout << "number_of_parts = " << mesh.stl.stats.number_of_parts << endl; + cout << "volume = " << mesh.volume() << endl; } diff --git a/xs/src/libslic3r/Model.hpp b/xs/src/libslic3r/Model.hpp index e98d1db281..6d4ab1bfc4 100644 --- a/xs/src/libslic3r/Model.hpp +++ b/xs/src/libslic3r/Model.hpp @@ -51,6 +51,7 @@ class Model bool has_objects_with_no_instances() const; bool add_default_instances(); BoundingBoxf3 bounding_box() const; + void repair(); void center_instances_around_point(const Pointf &point); void align_instances_to_origin(); void translate(coordf_t x, coordf_t y, coordf_t z); @@ -118,6 +119,7 @@ class ModelObject BoundingBoxf3 bounding_box(); void invalidate_bounding_box(); + void repair(); TriangleMesh mesh() const; TriangleMesh raw_mesh() const; BoundingBoxf3 raw_bounding_box() const; diff --git a/xs/src/libslic3r/SVGExport.hpp b/xs/src/libslic3r/SVGExport.hpp index b77a21fa88..2075f1c6d4 100644 --- a/xs/src/libslic3r/SVGExport.hpp +++ b/xs/src/libslic3r/SVGExport.hpp @@ -13,14 +13,12 @@ class SVGExport { public: SVGExportConfig config; + TriangleMesh mesh; SVGExport(const TriangleMesh &mesh) : mesh(mesh) { this->mesh.mirror_x(); }; void writeSVG(const std::string &outputfile); - - private: - TriangleMesh mesh; }; } diff --git a/xs/src/libslic3r/TriangleMesh.cpp b/xs/src/libslic3r/TriangleMesh.cpp index 931292cce2..4286d5aa30 100644 --- a/xs/src/libslic3r/TriangleMesh.cpp +++ b/xs/src/libslic3r/TriangleMesh.cpp @@ -109,7 +109,7 @@ TriangleMesh::repair() { stl_fix_normal_values(&stl); // always calculate the volume and reverse all normals if volume is negative - stl_calculate_volume(&stl); + (void)this->volume(); // neighbors stl_verify_neighbors(&stl); @@ -117,6 +117,13 @@ TriangleMesh::repair() { this->repaired = true; } +float +TriangleMesh::volume() +{ + if (this->stl.stats.volume == -1) stl_calculate_volume(&this->stl); + return this->stl.stats.volume; +} + void TriangleMesh::check_topology() { @@ -146,6 +153,12 @@ TriangleMesh::check_topology() } } +bool +TriangleMesh::is_manifold() const +{ + return this->stl.stats.connected_facets_3_edge == this->stl.stats.number_of_facets; +} + void TriangleMesh::reset_repair_stats() { this->stl.stats.degenerate_facets = 0; diff --git a/xs/src/libslic3r/TriangleMesh.hpp b/xs/src/libslic3r/TriangleMesh.hpp index 2a2a6dbd2d..196ef17c01 100644 --- a/xs/src/libslic3r/TriangleMesh.hpp +++ b/xs/src/libslic3r/TriangleMesh.hpp @@ -29,6 +29,8 @@ class TriangleMesh void write_binary(const std::string &output_file); void repair(); void check_topology(); + float volume(); + bool is_manifold() const; void WriteOBJFile(const std::string &output_file); void scale(float factor); void scale(const Pointf3 &versor); From 30139fd64746f0a52ce489eb7f5e60965925f9fb Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sun, 17 Jul 2016 16:53:37 +0200 Subject: [PATCH 57/58] Port --load and --save to XS --- lib/Slic3r/Config.pm | 13 +++------ src/slic3r.cpp | 25 ++++++++++++----- xs/src/libslic3r/Config.cpp | 46 +++++++++++++++++++++++++++++--- xs/src/libslic3r/Config.hpp | 44 +++++++++++++++--------------- xs/src/libslic3r/PrintConfig.cpp | 12 +++++++++ xs/src/libslic3r/PrintConfig.hpp | 4 +++ xs/xsp/Config.xsp | 4 +++ 7 files changed, 107 insertions(+), 41 deletions(-) diff --git a/lib/Slic3r/Config.pm b/lib/Slic3r/Config.pm index bfbeee88cb..022c206f11 100644 --- a/lib/Slic3r/Config.pm +++ b/lib/Slic3r/Config.pm @@ -87,8 +87,10 @@ sub load { my $class = shift; my ($file) = @_; - my $ini = __PACKAGE__->read_ini($file); - return $class->load_ini_hash($ini->{_}); + # legacy syntax of load() + my $config = $class->new; + $config->_load($file); + return $config; } sub load_ini_hash { @@ -186,13 +188,6 @@ sub as_ini { return $ini; } -sub save { - my $self = shift; - my ($file) = @_; - - __PACKAGE__->write_ini($file, $self->as_ini); -} - # this method is idempotent by design and only applies to ::DynamicConfig or ::Full # objects because it performs cross checks sub validate { diff --git a/src/slic3r.cpp b/src/slic3r.cpp index 23cd8c7ff7..8a75564cdb 100644 --- a/src/slic3r.cpp +++ b/src/slic3r.cpp @@ -24,17 +24,28 @@ main(const int argc, const char **argv) t_config_option_keys input_files; config.read_cli(argc, argv, &input_files); - // apply command line options to a more specific DynamicPrintConfig which provides normalize() - DynamicPrintConfig print_config; - print_config.apply(config, true); - print_config.normalize(); - // apply command line options to a more handy CLIConfig CLIConfig cli_config; cli_config.apply(config, true); - /* TODO: loop through the config files supplied on the command line (now stored in - cli_config), load each one, normalize it and apply it to print_config */ + DynamicPrintConfig print_config; + + // load config files supplied via --load + for (std::vector::const_iterator file = cli_config.load.values.begin(); + file != cli_config.load.values.end(); ++file) { + DynamicPrintConfig c; + c.load(*file); + c.normalize(); + print_config.apply(c); + } + + // apply command line options to a more specific DynamicPrintConfig which provides normalize() + // (command line options override --load files) + print_config.apply(config, true); + print_config.normalize(); + + // write config if requested + if (!cli_config.save.value.empty()) print_config.save(cli_config.save.value); // read input file(s) if any std::vector models; diff --git a/xs/src/libslic3r/Config.cpp b/xs/src/libslic3r/Config.cpp index dbc3ca89b4..cac2010f4d 100644 --- a/xs/src/libslic3r/Config.cpp +++ b/xs/src/libslic3r/Config.cpp @@ -1,8 +1,14 @@ #include "Config.hpp" #include // for setenv() #include +#include +#include +#include #include #include +#include +#include +#include #if defined(_WIN32) && !defined(setenv) && defined(_putenv_s) #define setenv(k, v, o) _putenv_s(k, v) @@ -116,7 +122,7 @@ ConfigBase::serialize(const t_config_option_key &opt_key) const { } bool -ConfigBase::set_deserialize(const t_config_option_key &opt_key, std::string str) { +ConfigBase::set_deserialize(const t_config_option_key &opt_key, std::string str, bool append) { const ConfigOptionDef* optdef = this->def->get(opt_key); if (optdef == NULL) throw "Calling set_deserialize() on unknown option"; if (!optdef->shortcut.empty()) { @@ -128,7 +134,7 @@ ConfigBase::set_deserialize(const t_config_option_key &opt_key, std::string str) ConfigOption* opt = this->option(opt_key, true); assert(opt != NULL); - return opt->deserialize(str); + return opt->deserialize(str, append); } double @@ -189,6 +195,38 @@ ConfigBase::option(const t_config_option_key &opt_key, bool create) { return this->optptr(opt_key, create); } +void +ConfigBase::load(const std::string &file) +{ + namespace pt = boost::property_tree; + pt::ptree tree; + pt::read_ini(file, tree); + BOOST_FOREACH(const pt::ptree::value_type &v, tree) { + this->set_deserialize(v.first.c_str(), v.second.get_value().c_str()); + } +} + +void +ConfigBase::save(const std::string &file) const +{ + using namespace std; + ofstream c; + c.open(file.c_str(), ios::out | ios::trunc); + + { + time_t now; + time(&now); + char buf[sizeof "0000-00-00 00:00:00"]; + strftime(buf, sizeof buf, "%F %T", gmtime(&now)); + c << "# generated by Slic3r " << SLIC3R_VERSION << " on " << buf << endl; + } + + t_config_option_keys my_keys = this->keys(); + for (t_config_option_keys::const_iterator opt_key = my_keys.begin(); opt_key != my_keys.end(); ++opt_key) + c << *opt_key << " = " << this->serialize(*opt_key) << endl; + c.close(); +} + DynamicConfig& DynamicConfig::operator= (DynamicConfig other) { this->swap(other); @@ -325,11 +363,11 @@ DynamicConfig::read_cli(const int argc, const char** argv, t_config_option_keys* opt->values.push_back(!boost::starts_with(token, "no-")); } else { // we expect one more token carrying the value - if (i == argc) { + if (i == (argc-1)) { printf("No value supplied for --%s\n", token.c_str()); exit(1); } - this->option(opt_key, true)->deserialize(argv[++i]); + this->set_deserialize(opt_key, argv[++i], true); } } else { extra->push_back(token); diff --git a/xs/src/libslic3r/Config.hpp b/xs/src/libslic3r/Config.hpp index acbbaf9ff2..7892e3358e 100644 --- a/xs/src/libslic3r/Config.hpp +++ b/xs/src/libslic3r/Config.hpp @@ -22,7 +22,7 @@ class ConfigOption { virtual ~ConfigOption() {}; virtual ConfigOption* clone() const = 0; virtual std::string serialize() const = 0; - virtual bool deserialize(std::string str) = 0; + virtual bool deserialize(std::string str, bool append = false) = 0; virtual void set(const ConfigOption &option) = 0; virtual int getInt() const { return 0; }; virtual double getFloat() const { return 0; }; @@ -90,7 +90,7 @@ class ConfigOptionFloat : public ConfigOptionSingle return ss.str(); }; - bool deserialize(std::string str) { + bool deserialize(std::string str, bool append = false) { std::istringstream iss(str); iss >> this->value; return !iss.fail(); @@ -123,8 +123,8 @@ class ConfigOptionFloats : public ConfigOptionVector return vv; }; - bool deserialize(std::string str) { - this->values.clear(); + bool deserialize(std::string str, bool append = false) { + if (!append) this->values.clear(); std::istringstream is(str); std::string item_str; while (std::getline(is, item_str, ',')) { @@ -153,7 +153,7 @@ class ConfigOptionInt : public ConfigOptionSingle return ss.str(); }; - bool deserialize(std::string str) { + bool deserialize(std::string str, bool append = false) { std::istringstream iss(str); iss >> this->value; return !iss.fail(); @@ -186,8 +186,8 @@ class ConfigOptionInts : public ConfigOptionVector return vv; }; - bool deserialize(std::string str) { - this->values.clear(); + bool deserialize(std::string str, bool append = false) { + if (!append) this->values.clear(); std::istringstream is(str); std::string item_str; while (std::getline(is, item_str, ',')) { @@ -222,7 +222,7 @@ class ConfigOptionString : public ConfigOptionSingle return str; }; - bool deserialize(std::string str) { + bool deserialize(std::string str, bool append = false) { // s/\\n/\n/g size_t pos = 0; while ((pos = str.find("\\n", pos)) != std::string::npos) { @@ -256,8 +256,8 @@ class ConfigOptionStrings : public ConfigOptionVector return this->values; }; - bool deserialize(std::string str) { - this->values.clear(); + bool deserialize(std::string str, bool append = false) { + if (!append) this->values.clear(); std::istringstream is(str); std::string item_str; while (std::getline(is, item_str, ';')) { @@ -286,7 +286,7 @@ class ConfigOptionPercent : public ConfigOptionFloat return s; }; - bool deserialize(std::string str) { + bool deserialize(std::string str, bool append = false) { // don't try to parse the trailing % since it's optional std::istringstream iss(str); iss >> this->value; @@ -327,7 +327,7 @@ class ConfigOptionFloatOrPercent : public ConfigOptionPercent return s; }; - bool deserialize(std::string str) { + bool deserialize(std::string str, bool append = false) { this->percent = str.find_first_of("%") != std::string::npos; std::istringstream iss(str); iss >> this->value; @@ -350,7 +350,7 @@ class ConfigOptionPoint : public ConfigOptionSingle return ss.str(); }; - bool deserialize(std::string str) { + bool deserialize(std::string str, bool append = false) { std::istringstream iss(str); iss >> this->value.x; iss.ignore(std::numeric_limits::max(), ','); @@ -388,8 +388,8 @@ class ConfigOptionPoints : public ConfigOptionVector return vv; }; - bool deserialize(std::string str) { - this->values.clear(); + bool deserialize(std::string str, bool append = false) { + if (!append) this->values.clear(); std::istringstream is(str); std::string point_str; while (std::getline(is, point_str, ',')) { @@ -421,7 +421,7 @@ class ConfigOptionBool : public ConfigOptionSingle return std::string(this->value ? "1" : "0"); }; - bool deserialize(std::string str) { + bool deserialize(std::string str, bool append = false) { this->value = (str.compare("1") == 0); return true; }; @@ -453,8 +453,8 @@ class ConfigOptionBools : public ConfigOptionVector return vv; }; - bool deserialize(std::string str) { - this->values.clear(); + bool deserialize(std::string str, bool append = false) { + if (!append) this->values.clear(); std::istringstream is(str); std::string item_str; while (std::getline(is, item_str, ',')) { @@ -483,7 +483,7 @@ class ConfigOptionEnum : public ConfigOptionSingle return ""; }; - bool deserialize(std::string str) { + bool deserialize(std::string str, bool append = false) { t_config_enum_values enum_keys_map = ConfigOptionEnum::get_enum_values(); if (enum_keys_map.count(str) == 0) return false; this->value = static_cast(enum_keys_map[str]); @@ -507,7 +507,7 @@ class ConfigOptionEnumGeneric : public ConfigOptionInt return ""; }; - bool deserialize(std::string str) { + bool deserialize(std::string str, bool append = false) { if (this->keys_map->count(str) == 0) return false; this->value = (*const_cast(this->keys_map))[str]; return true; @@ -596,10 +596,12 @@ class ConfigBase bool equals(ConfigBase &other); t_config_option_keys diff(ConfigBase &other); std::string serialize(const t_config_option_key &opt_key) const; - bool set_deserialize(const t_config_option_key &opt_key, std::string str); + bool set_deserialize(const t_config_option_key &opt_key, std::string str, bool append = false); double get_abs_value(const t_config_option_key &opt_key); double get_abs_value(const t_config_option_key &opt_key, double ratio_over); void setenv_(); + void load(const std::string &file); + void save(const std::string &file) const; }; class DynamicConfig : public virtual ConfigBase diff --git a/xs/src/libslic3r/PrintConfig.cpp b/xs/src/libslic3r/PrintConfig.cpp index 90af82fbdf..461981cdaf 100644 --- a/xs/src/libslic3r/PrintConfig.cpp +++ b/xs/src/libslic3r/PrintConfig.cpp @@ -1383,6 +1383,12 @@ CLIConfigDef::CLIConfigDef() def->cli = "info"; def->default_value = new ConfigOptionBool(false); + def = this->add("load", coStrings); + def->label = "Load config file"; + def->tooltip = "Load configuration from the specified file. It can be used more than once to load options from multiple files."; + def->cli = "load"; + def->default_value = new ConfigOptionStrings(); + def = this->add("output", coString); def->label = "Output File"; def->tooltip = "The file where the output will be written (if not specified, it will be based on the input file)."; @@ -1395,6 +1401,12 @@ CLIConfigDef::CLIConfigDef() def->cli = "rotate"; def->default_value = new ConfigOptionFloat(0); + def = this->add("save", coString); + def->label = "Save config file"; + def->tooltip = "Save configuration to the specified file."; + def->cli = "save"; + def->default_value = new ConfigOptionString(); + def = this->add("scale", coFloat); def->label = "Scale"; def->tooltip = "Scaling factor (default: 1)."; diff --git a/xs/src/libslic3r/PrintConfig.hpp b/xs/src/libslic3r/PrintConfig.hpp index 442af51c23..ccc3b14719 100644 --- a/xs/src/libslic3r/PrintConfig.hpp +++ b/xs/src/libslic3r/PrintConfig.hpp @@ -506,8 +506,10 @@ class CLIConfig ConfigOptionBool export_pov; ConfigOptionBool export_svg; ConfigOptionBool info; + ConfigOptionStrings load; ConfigOptionString output; ConfigOptionFloat rotate; + ConfigOptionString save; ConfigOptionFloat scale; CLIConfig() : ConfigBase(), StaticConfig() { @@ -520,8 +522,10 @@ class CLIConfig OPT_PTR(export_pov); OPT_PTR(export_svg); OPT_PTR(info); + OPT_PTR(load); OPT_PTR(output); OPT_PTR(rotate); + OPT_PTR(save); OPT_PTR(scale); return NULL; diff --git a/xs/xsp/Config.xsp b/xs/xsp/Config.xsp index a2db75999c..4bc6081918 100644 --- a/xs/xsp/Config.xsp +++ b/xs/xsp/Config.xsp @@ -38,6 +38,8 @@ void normalize(); %name{setenv} void setenv_(); double min_object_distance(); + %name{_load} void load(std::string file); + void save(std::string file); }; %name{Slic3r::Config::Static} class StaticPrintConfig { @@ -84,6 +86,8 @@ %}; %name{setenv} void setenv_(); double min_object_distance(); + %name{_load} void load(std::string file); + void save(std::string file); }; %package{Slic3r::Config}; From 848374602d777f0795a6345c1b337a0d09c0eb4a Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sun, 17 Jul 2016 16:54:01 +0200 Subject: [PATCH 58/58] Add 'build' to .gitignore --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 62e52ce4e8..95428a002c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +build Build Build.bat MYMETA.json @@ -9,4 +10,4 @@ xs/buildtmp MANIFEST.bak xs/MANIFEST.bak xs/assertlib* -.init_bundle.ini \ No newline at end of file +.init_bundle.ini