import abqpy.abaqus
from .Canvas.Highlight import *
from .Mdb.Mdb import Mdb as AbaqusMdb
from .Odb.Odb import Odb
from .Session.Session import Session as AbaqusSession
from .UtilityAndView.BackwardCompatibility import BackwardCompatibility
from .UtilityAndView.SymbolicConstant import SymbolicConstant
from .UtilityAndView.abaqusConstants import Boolean, OFF
from .UtilityAndView.User import *


class Mdb(AbaqusMdb):

    def __init__(self, pathName: str = ""):
        super().__init__(pathName)

    def save(self):
        super().save()

    def saveAs(self, pathName: str):
        abqpy.abaqus.run()


class Session(AbaqusSession):

    def openOdb(self, name: str, path: str = "", readOnly: Boolean = OFF) -> Odb:
        """This method opens an existing output database (`.odb`) file and creates a new Odb object.
        This method is accessed only via the session object inside Abaqus/CAE and adds the new
        Odb object to the session.odbs repository. This method allows you to open multiple
        output databases at the same time and to use the repository key to specify a particular
        output database. For example::
        
            import visualization
            session.openOdb(name='myOdb', path='stress.odb', readOnly=True)

        Parameters
        ----------
        name
            A String specifying the repository key. If the `name` is not the same as the `path` to the
            output database (`.odb`) file, the `path` must be specified as well. Additionally, to
            support backwards compatibility of the interface, if the `name` parameter is omitted,
            the `path` and `name` will be presumed to be the same.
        path
            A String specifying the path to an existing output database (`.odb`) file.
        readOnly
            A Boolean specifying whether the file will permit only read access or both read and
            write access. The initial value is TRUE when the output database file is opened from
            Abaqus/CAE, indicating that only read access will be permitted.

        Returns
        -------
        Odb
            An :py:class:`~abaqus.Odb.Odb.Odb` object.

        Raises
        ------
        OdbError: The database is from a previous release of Abaqus
            If the output database was generated by a previous release of Abaqus and needs
            upgrading, Run  `abaqus upgrade -job <newFilename> -odb <oldFileName>` to upgrade it.
        OdbError: Abaqus installation must be upgraded before this output database can be opened
            If the output database was generated by a newer release of Abaqus, and the
            installation of Abaqus needs upgrading.
        AbaqusError: Cannot open file <filename>
            If the file is not a valid database.
        """
        self.odbs[name] = odb = Odb(name)
        abqpy.abaqus.run()
        return odb


session = Session()
mdb = Mdb()

backwardCompatibility = BackwardCompatibility()

YES = SymbolicConstant('YES')
NO = SymbolicConstant('NO')
