Ejemplo n.º 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)
Ejemplo n.º 2
0
Archivo: app.py Proyecto: fbob/dice-dev
 def __load_stl_files(self):
     files = []
     for f in self.__object_files:
         stl_file = STLFile(self.current_run_path(f['filePath']))
         try:
             stl_file.patchInfo()
             files.append(stl_file)
         except FatalErrorPyFoamException:
             pass
     return files
Ejemplo n.º 3
0
 def __load_stl_files(self):
     files = []
     for f in self.__object_files:
         stl_file = STLFile(self.current_run_path(f['filePath']))
         try:
             stl_file.patchInfo()
             files.append(stl_file)
         except FatalErrorPyFoamException:
             pass
     return files
Ejemplo n.º 4
0
class STLLoader(BasicWrapper):
    def __init__(self, stl=None, parent=None):
        """
        :param QObject parent:
        :param STLFile|str stl:
        """
        super(STLLoader, self).__init__(parent)

        if isinstance(stl, str):
            self.__stl = STLFile(stl)
        elif isinstance(stl, STLFile):
            self.__stl = stl
        else:
            raise TypeError("stl must be a STLFile or str")

        self.tree_info = [{
            "text":
            self.__stl.filename(),
            "object":
            self,
            "elements": [{
                "object": self,
                "text": region["name"]
            } for region in self.__stl.patchInfo()]
        }]

    file_name_changed = pyqtSignal(name="fileNameChanged")

    @property
    def file_name(self):
        return self.__stl._filename

    fileName = pyqtProperty(str, fget=file_name.fget, notify=file_name_changed)

    @property
    def basename(self):
        return os.path.basename(self.file_name)

    # @property
    # def tree_info(self):
    #     return self.__tree_info

    def has_path(self, path):
        if len(path) == 1:
            return path[0] == self.__stl.filename()
        elif len(path) == 2:
            regions = [region["name"] for region in self.__stl.patchInfo()]
            return path[0] == self.__stl.filename() and path[1] in regions
        else:
            return False
Ejemplo n.º 5
0
class STLLoader(BasicWrapper):
    def __init__(self, stl=None, parent=None):
        """
        :param QObject parent:
        :param STLFile|str stl:
        """
        super(STLLoader, self).__init__(parent)

        if isinstance(stl, str):
            self.__stl = STLFile(stl)
        elif isinstance(stl, STLFile):
            self.__stl = stl
        else:
            raise TypeError("stl must be a STLFile or str")

        self.tree_info = [{"text": self.__stl.filename(),
                           "object" : self,
                           "elements": [{
                                "object": self,
                                "text": region["name"]
                             } for region in self.__stl.patchInfo()]}]

    file_name_changed = pyqtSignal(name="fileNameChanged")

    @property
    def file_name(self):
        return self.__stl._filename

    fileName = pyqtProperty(str, fget=file_name.fget, notify=file_name_changed)

    @property
    def basename(self):
        return os.path.basename(self.file_name)

    # @property
    # def tree_info(self):
    #     return self.__tree_info

    def has_path(self, path):
        if len(path) == 1:
            return path[0] == self.__stl.filename()
        elif len(path) == 2:
            regions = [region["name"] for region in self.__stl.patchInfo()]
            return path[0] == self.__stl.filename() and path[1] in regions
        else:
            return False
Ejemplo n.º 6
0
    def update_changed_stl_file(self, filename):
        for stl in list(self.__stl_files):
            if stl.filename() == filename:
                self.__stl_files.remove(stl)
        self.__stl_files.append(STLFile(self.current_run_path("files", filename)))
        self.object_files_changed.emit()
        self.stl_files_out_changed.emit()

        for vis in list(self.__stl_vis_objects):
            if vis.basename == filename:
                self.__stl_vis_objects.remove(vis)
                self.remove_vis_object(vis)
        self.__load_stl_vis_objects()
Ejemplo n.º 7
0
    def __init__(self, stl=None, parent=None):
        """
        :param QObject parent:
        :param STLFile|str stl:
        """
        super(STLLoader, self).__init__(parent)

        if isinstance(stl, str):
            self.__stl = STLFile(stl)
        elif isinstance(stl, STLFile):
            self.__stl = stl
        else:
            raise TypeError("stl must be a STLFile or str")

        self.tree_info = [{
            "text":
            self.__stl.filename(),
            "object":
            self,
            "elements": [{
                "object": self,
                "text": region["name"]
            } for region in self.__stl.patchInfo()]
        }]
Ejemplo n.º 8
0
Archivo: app.py Proyecto: fbob/dice-dev
    def add_to_file_model(self, full_path, src, file_path):
        """
        Adds a stl file to the file model.
        :param full_path: The full path to the stl file
        :param src: The path of the original file
        :param file_path: relative file path, must start with "files/"
        """
        stl_file = STLFile(full_path)
        self.__stl_files.append(stl_file)

        vo = STLLoader(stl_file)
        self.__stl_vis_objects.append(vo)
        self.add_vis_object(vo)

        self.__object_files.append({'src': src, 'filePath': file_path})
        self.object_files_changed.emit()
        self.stl_files_out_changed.emit()
Ejemplo n.º 9
0
    def object_refinements_load(self):

        # Load objectRefinements
        # ======================

        if "objectRefinements" not in self._mesh_dict:
            self._mesh_dict["objectRefinements"] = {}
        self._object_refinements = self._mesh_dict["objectRefinements"]

        if "surfaceMeshRefinement" not in self._mesh_dict:
            self._mesh_dict["surfaceMeshRefinement"] = {}
        self._surface_mesh_refinement = self._mesh_dict[
            "surfaceMeshRefinement"]
        for surface_file in self._surface_mesh_refinement:
            surface_file_url = self._surface_mesh_refinement[surface_file][
                "surfaceFile"].split('"')[1]
            surface_file_object = STLFile(self.config_path(surface_file_url))
            self._surface_mesh_refinement_files.append(surface_file_object)
Ejemplo n.º 10
0
    def __init__(self, stl=None, parent=None):
        """
        :param QObject parent:
        :param STLFile|str stl:
        """
        super(STLLoader, self).__init__(parent)

        if isinstance(stl, str):
            self.__stl = STLFile(stl)
        elif isinstance(stl, STLFile):
            self.__stl = stl
        else:
            raise TypeError("stl must be a STLFile or str")

        self.tree_info = [{"text": self.__stl.filename(),
                           "object" : self,
                           "elements": [{
                                "object": self,
                                "text": region["name"]
                             } for region in self.__stl.patchInfo()]}]
Ejemplo n.º 11
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)
Ejemplo n.º 12
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)