Source code for Muscat.IO.IOFactory

# -*- coding: utf-8 -*-
#
# This file is subject to the terms and conditions defined in
# file 'LICENSE.txt', which is part of this source code package.
#


"""Factory for handling input and output
"""

from Muscat.Helpers.Factory import Factory

[docs]def RegisterReaderClass(name, classtype, constructor=None, withError = True): return ReaderFactory.RegisterClass(name,classtype, constructor=constructor, withError = withError )
[docs]def CreateReader(name,ops=None): return ReaderFactory.Create(name,ops)
[docs]class ReaderFactory(Factory): _Catalog = {} _SetCatalog = set() def __init__(self): super().__init__()
[docs]def GetAvailableReaders(): return list(ReaderFactory._Catalog.keys())
[docs]def InitAllReaders(): import Muscat.IO.InpReader as InpReader import Muscat.IO.AscReader as AscReader import Muscat.IO.AnsysReader as AnsysReader import Muscat.IO.GeofReader as GeofReader import Muscat.IO.GeoReader as GeoReader import Muscat.IO.GmshReader as GmshReader import Muscat.IO.MeshReader as MeshReader import Muscat.IO.GReader as GReader import Muscat.IO.FemReader as FemReader from Muscat.IO.StlReader import ReadStl from Muscat.IO.XdmfReader import ReadXdmf from Muscat.IO.PipeIO import PipeReader from Muscat.IO.OdbReader import OdbReader from Muscat.IO.UtReader import UtReader from Muscat.IO.VtkReader import VtkReader from Muscat.IO.SamcefReader import DatReader import Muscat.IO.SamcefOutputReader import Muscat.IO.PickleTools import Muscat.IO.CGNSReader import Muscat.IO.FemmReader
[docs]def InitAllWriters(): from Muscat.IO.GeofWriter import GeofWriter from Muscat.IO.GmshWriter import GmshWriter from Muscat.IO.MeshWriter import MeshWriter from Muscat.IO.OdbWriter import OdbWriter from Muscat.IO.StlWriter import StlWriter from Muscat.IO.XdmfWriter import XdmfWriter from Muscat.IO.PipeIO import PipeWriter from Muscat.IO.CsvWriter import CsvWriter import Muscat.IO.PickleTools import Muscat.IO.Catalyst import Muscat.IO.InpWriter import Muscat.IO.CGNSWriter
[docs]def RegisterWriterClass(name, classtype, constructor=None, withError = True): WriterFactory.RegisterClass(name,classtype, constructor=constructor, withError = withError )
[docs]def CreateWriter(name,ops=None): return WriterFactory.Create("."+name.split(".")[-1],ops)
[docs]class WriterFactory(Factory): _Catalog = {} _SetCatalog = set() def __init__(self): super().__init__()
[docs]def GetAvailableWriter(): return list(WriterFactory._Catalog.keys())
[docs]def CheckIntegrity(GUI:bool=False): from Muscat.IO.IOFactory import WriterFactory, ReaderFactory from Muscat.IO.IOFactory import GetAvailableReaders, RegisterReaderClass from Muscat.IO.IOFactory import GetAvailableWriter ## InitAllReaders() class DummyReaderI: pass class DummyReaderII: pass RegisterReaderClass(".test",DummyReaderI,withError=True) RegisterReaderClass(".test",DummyReaderII,withError=False) print("Available Readers : ", GetAvailableReaders()) print("Available Readers for '.test': ", ReaderFactory.GetAvailableFor(".test")) print(CreateReader(".test")) InitAllWriters() class DummyWriterI: pass class DummyWriterII: pass RegisterWriterClass(".test",DummyWriterI,withError=True) RegisterWriterClass(".test",DummyWriterII,withError=False) print("Available Writers : ", GetAvailableWriter()) print("Available Writers for '.test': ", WriterFactory.GetAvailableFor(".test")) print(CreateWriter(".test")) print("---------------------") ReaderFactory.PrintAvailable() print("---------------------") WriterFactory.PrintAvailable() ReaderFactory() WriterFactory() return "ok"
if __name__ == '__main__': print(CheckIntegrity())# pragma: no cover