Beispiel #1
0
    def run(self):
        sources=[STLFile(f) for f in self.parser.getArgs()]
        rst=RestructuredTextHelper()
        
        if self.opts.patchNames:
            print rst.buildHeading("Patch names",level=RestructuredTextHelper.LevelSection)
            for s in sources:
                print rst.buildHeading(s.filename(),level=RestructuredTextHelper.LevelSubSection)
                for p in s.patchInfo():
                    print p["name"]

        if self.opts.info:
            print rst.buildHeading("Patch info",level=RestructuredTextHelper.LevelSection)
            for s in sources:
                print rst.buildHeading(s.filename(),level=RestructuredTextHelper.LevelSubSection)
                tab=rst.table()
                tab[0]=["name","facets","range in file","bounding box"]
                tab.addLine(head=True)
                for i,p in enumerate(s.patchInfo()):
                    tab[(i+1,0)]=p["name"]
                    tab[(i+1,1)]=p["facets"]
                    tab[(i+1,2)]="%d-%d" % (p["start"],p["end"])
                    tab[(i+1,3)]="(%g %g %g) - (%g %g %g)" % tuple(p["min"]+p["max"])

                print tab
                    
        if self.opts.joinTo:
            if path.exists(self.opts.joinTo):
                self.error("File",self.opts.joinTo,"does allready exist")

            result=STLFile()
            for s in sources:
                result+=s

            result.writeTo(self.opts.joinTo)
Beispiel #2
0
    def run(self):
        sources = None
        if "stdin" in self.opts.__dict__:
            if self.opts.stdin:
                if len(self.parser.getArgs()) > 0:
                    self.error(
                        "If --from-stdin specified no arguments are allowed but we have",
                        self.parser.getArgs())
                sources = [STLFile(sys.stdin)]
        if sources == None:
            sources = [STLFile(f) for f in self.parser.getArgs()]

        if self.cmdname in ["remove", "merge"]:
            if len(sources) != 1:
                self.error("Only one input allowed for", self.cmdname)

        if self.cmdname in ["remove", "merge"]:
            if len(self.opts.patchExpr) == 0 and len(
                    self.opts.patchNames) == 0:
                self.error(
                    "Neither --patch-name nor --select-expression specified")
            for e in self.opts.patchExpr:
                expr = re.compile(e)
                for s in sources:
                    for p in s.patchInfo():
                        if expr.match(p["name"]):
                            self.opts.patchNames.append(p["name"])
            if len(self.opts.patchNames) == 0:
                self.error("No patches fit the provided regular expressions")

        if self.cmdname in ["remove", "join", "merge"]:
            # Check whether output is correct
            if self.opts.stdout and self.opts.stlFile:
                self.error(
                    "Can't specify --to-stdout and --stl-file at the same time"
                )

            if self.opts.stlFile:
                if path.exists(self.opts.stlFile):
                    if not self.opts.forceWrite:
                        self.error(
                            "File", self.opts.stlFile,
                            "does allready exist. Use --force-write to overwrite"
                        )
                outputTo = self.opts.stlFile
            elif self.opts.stdout:
                outputTo = sys.stdout
            else:
                self.error("Specify either --to-stdout or --stld-file")

        rst = RestructuredTextHelper()

        if self.cmdname == "names":
            print_(
                rst.buildHeading("Patch names",
                                 level=RestructuredTextHelper.LevelSection))
            for s in sources:
                print_(
                    rst.buildHeading(
                        s.filename(),
                        level=RestructuredTextHelper.LevelSubSection))
                for p in s.patchInfo():
                    print_(p["name"])

        elif self.cmdname == "info":
            print_(
                rst.buildHeading("Patch info",
                                 level=RestructuredTextHelper.LevelSection))
            for s in sources:
                print_(
                    rst.buildHeading(
                        s.filename(),
                        level=RestructuredTextHelper.LevelSubSection))
                tab = rst.table()
                tab[0] = ["name", "facets", "range in file", "bounding box"]
                tab.addLine(head=True)
                for i, p in enumerate(s.patchInfo()):
                    tab[(i + 1, 0)] = p["name"]
                    tab[(i + 1, 1)] = p["facets"]
                    tab[(i + 1, 2)] = "%d-%d" % (p["start"], p["end"])
                    tab[(i + 1,
                         3)] = "(%g %g %g) - (%g %g %g)" % tuple(p["min"] +
                                                                 p["max"])

                print_(tab)

        elif self.cmdname == "join":
            result = STLFile()
            for s in sources:
                result += s

            result.writeTo(outputTo)
        elif self.cmdname == "remove":
            s = sources[0]
            s.erasePatches(self.opts.patchNames)
            s.writeTo(outputTo)
        elif self.cmdname == "merge":
            if self.opts.newName == None:
                self.error("Specify --new-patch-name")
            s = sources[0]
            s.mergePatches(self.opts.patchNames, self.opts.newName)
            s.writeTo(outputTo)
        else:
            self.error("Unimplemented subcommand", self.cmdname)
Beispiel #3
0
    def run(self):
        sources=None
        if "stdin" in self.opts.__dict__:
            if self.opts.stdin:
                if len(self.parser.getArgs())>0:
                    self.error("If --from-stdin specified no arguments are allowed but we have",self.parser.getArgs())
                sources=[STLFile(sys.stdin)]
        if sources==None:
            sources=[STLFile(f) for f in self.parser.getArgs()]

        if self.cmdname in ["remove","merge"]:
            if len(sources)!=1:
                self.error("Only one input allowed for",self.cmdname)

        if self.cmdname in ["remove","merge"]:
            if len(self.opts.patchExpr)==0 and len(self.opts.patchNames)==0:
                self.error("Neither --patch-name nor --select-expression specified")
            for e in self.opts.patchExpr:
                expr=re.compile(e)
                for s in sources:
                    for p in s.patchInfo():
                        if expr.match(p["name"]):
                            self.opts.patchNames.append(p["name"])
            if len(self.opts.patchNames)==0:
                self.error("No patches fit the provided regular expressions")

        if self.cmdname in ["remove","join","merge"]:
            # Check whether output is correct
            if self.opts.stdout and self.opts.stlFile:
                self.error("Can't specify --to-stdout and --stl-file at the same time")

            if self.opts.stlFile:
                if path.exists(self.opts.stlFile):
                    if not self.opts.forceWrite:
                        self.error("File",self.opts.stlFile,"does allready exist. Use --force-write to overwrite")
                outputTo=self.opts.stlFile
            elif self.opts.stdout:
                outputTo=sys.stdout
            else:
                self.error("Specify either --to-stdout or --stld-file")

        rst=RestructuredTextHelper()

        if self.cmdname=="names":
            print_(rst.buildHeading("Patch names",level=RestructuredTextHelper.LevelSection))
            for s in sources:
                print_(rst.buildHeading(s.filename(),level=RestructuredTextHelper.LevelSubSection))
                for p in s.patchInfo():
                    print_(p["name"])

        elif self.cmdname=="info":
            print_(rst.buildHeading("Patch info",level=RestructuredTextHelper.LevelSection))
            for s in sources:
                print_(rst.buildHeading(s.filename(),level=RestructuredTextHelper.LevelSubSection))
                tab=rst.table()
                tab[0]=["name","facets","range in file","bounding box"]
                tab.addLine(head=True)
                for i,p in enumerate(s.patchInfo()):
                    tab[(i+1,0)]=p["name"]
                    tab[(i+1,1)]=p["facets"]
                    tab[(i+1,2)]="%d-%d" % (p["start"],p["end"])
                    tab[(i+1,3)]="(%g %g %g) - (%g %g %g)" % tuple(p["min"]+p["max"])

                print_(tab)

        elif self.cmdname=="join":
            result=STLFile()
            for s in sources:
                result+=s

            result.writeTo(outputTo)
        elif self.cmdname=="remove":
            s=sources[0]
            s.erasePatches(self.opts.patchNames)
            s.writeTo(outputTo)
        elif self.cmdname=="merge":
            if self.opts.newName==None:
                self.error("Specify --new-patch-name")
            s=sources[0]
            s.mergePatches(self.opts.patchNames,self.opts.newName)
            s.writeTo(outputTo)
        else:
            self.error("Unimplemented subcommand",self.cmdname)