/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
    \\  /    A nd           | Copyright (C) 1991-2005 OpenCFD Ltd.
     \\/     M anipulation  |
-------------------------------------------------------------------------------
License
    This file is part of OpenFOAM.

    OpenFOAM is free software; you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by the
    Free Software Foundation; either version 2 of the License, or (at your
    option) any later version.

    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    for more details.

    You should have received a copy of the GNU General Public License
    along with OpenFOAM; if not, write to the Free Software Foundation,
    Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

Class
    PatchTool

Description
    IDL definitions for FoamX patch tool.

SourceFiles
    PatchTool.H
    PatchTool.C

\*---------------------------------------------------------------------------*/

#ifndef FoamX_IDL
#define FoamX_IDL

module FoamXServer
{
    // Forward declare all interfaces in this module.

    // -------------------------------------------------------------------------
    // - Enums -----------------------------------------------------------------
    // -------------------------------------------------------------------------

    enum FoamXType
    {
        Type_Undefined,
        Type_Boolean,
        Type_Label,
        Type_Scalar,
        Type_Char,
        Type_Word,
        Type_String,
        Type_RootDir,       // Any directory in caseRoots
        Type_RootAndCase,   // Path to valid case
        Type_CaseName,      // Valid case directory
        Type_HostName,      // Valid license host
        Type_File,          // Generic file (not directory)
        Type_Directory,     // Generic directory
        Type_Time,          // Time (as string)
        Type_DimensionSet,
        Type_VectorSpace,
        Type_List,
        Type_Dictionary,
        Type_Selection,
        Type_Compound,
        Type_Field          // Special type for late-bound field types.
    };

    enum ErrorCode
    {
        S_OK,
        E_FAIL,
        E_FOAM,
        E_INVALID_ARG,
        E_INVALID_PTR,
        E_INVALID_REF,
        E_INDEX_OUT_OF_BOUNDS,
        E_UNKNOWN_NAME,
        E_UNEXPECTED
    };

    enum JobStatus
    {
        JOB_UNDEFINED,
        JOB_LAUNCHING,
        JOB_RUNNING,
        JOB_STOPPING,
        JOB_SUSPENDED,
        JOB_FINISHED,
        JOB_ABORTED
    };

    enum MessageType
    {
        M_DIAGNOSTIC,    // Diagnostic and informational messages.
        M_WARNING,       // Warning messages.
        M_ERROR          // Error messages.
    };


    // -------------------------------------------------------------------------
    // - General Typedefs-------------------------------------------------------
    // -------------------------------------------------------------------------

    typedef sequence<string> StringList;
    typedef sequence<double> DoubleList;
    typedef sequence<float> FloatList;
    typedef sequence<boolean> BoolList;
    typedef sequence<long> LongList;
    typedef sequence<LongList> LongLongList;
    typedef float Point3[3];


    // -------------------------------------------------------------------------
    // - Structs----------------------------------------------------------------
    // -------------------------------------------------------------------------

    struct FoamXAny
    {
        FoamXType type;
        any value;
    };
    typedef sequence<FoamXAny> FoamXAnyList;

    struct StringPair
    {
        string name;
        string value;
    };
    typedef sequence<StringPair> StringPairList;

    // Host descriptor structure.
    struct HostDescriptor
    {
        string  name;
        boolean alive;
    };
    typedef sequence<HostDescriptor> HostDescriptorList;

    // Application class descriptor structure.
    struct ApplicationClassDescriptor
    {
        string  name;
        string  category;
        boolean systemClass;         // System defined application class.
    };
    typedef sequence<ApplicationClassDescriptor> ApplicationClassDescriptorList;

    // Case descriptor structure.
    struct CaseDescriptor
    {
        string rootDir;     // rootDir (after expansion)
        string rawRootDir;  // rootDir (before expansion)
        string caseName;
        string appClass;
        long nProcs;        // 1 or number of subdomains in parallel
        boolean managed;    // True if this is a FoamX managed case.
        boolean locked;     // True if this case is locked by another user.
        boolean error;      // True if this case is in error.
    };
    typedef sequence<CaseDescriptor> CaseDescriptorList;

    // Job ID.
    struct JobID
    {
        string hostName;    // Host name.
        long   processID;   // Process ID.
    };
    typedef sequence<JobID> JobIDList;

    // Job descriptor structure.
    struct JobDescriptor
    {
        JobID  jobID;           // Job ID.
        long   ppid;            // Parent pid.
        long   pgid;            // Group pid.
        string startDate;       // Start date.
        string startTime;       // Start time.
        string userName;        // Username.
        string foamVersion;     // FOAM version: 2.3
        string code;            // Code.
        string argList;         // Argument list.
        string currentDir;      // Current working directory.
        string rootDir;         // Case root.
        string caseName;        // Case name.
        long   nProcs;          // Number of processes.
        JobIDList slaves;       // slave JobIDs
        long   nCountedProcs;   // Number of licences taken up.
        double cpuTime;         // Used cpuTime.
        string endDate;         // End date.
        string endTime;         // End time.
        JobStatus status;       // Job status.
    };
    typedef sequence<JobDescriptor> JobDescriptorList;

    struct DimensionSet
    {
        double mass;                // Kilogramme Kg.
        double length;              // meter      m.
        double time;                // second     s.
        double temperature;         // Kelvin     K.
        double moles;               // mole       mol.
        double current;             // Ampere     Amp.
        double luminousIntensity;   // Candela    Cd.
    };
    typedef sequence<DimensionSet> DimensionSetList;

    // Surface patch description.
    struct SurfacePatch
    {
        string name;            // Name of patch
        string geometricType;   // Optional geometric type
        long size;              // Size of patch
        long start;             // Start of patch
    };
    typedef sequence<SurfacePatch> SurfacePatchList;

    // -------------------------------------------------------------------------
    // - Exceptions-------------------------------------------------------------
    // -------------------------------------------------------------------------

    // Standard exception
    exception FoamXError
    {
        ErrorCode errorCode;
        string errorMessage;

        string methodName;
        string fileName;
        long lineNo;
    };

    // Invalid remote system invocation (e.g. machine can't be reached)
    exception FoamXSYSError
    {
        ErrorCode errorCode;
        string errorMessage;
        string hostName;

        string methodName;
        string fileName;
        long lineNo;
    };

    // Invalid dictionary
    exception ValidationError
    {
        ErrorCode errorCode;
        string errorMessage;
        string itemPath;
    };

    // Exception from error on file
    exception FoamXIOError
    {
        string errorMessage;
        string ioFileName;
        long ioStartLineNo;
        long ioEndLineNo;

        string methodName;
        string fileName;
        long lineNo;
    };


    // -------------------------------------------------------------------------
    // - FoamX PatchToolServer Module -----------------------------------------------
    // -------------------------------------------------------------------------

    module PatchToolServer
    {
        // Forward declare all interfaces in this module.
        interface IPatchToolServer;


        // ---------------------------------------------------------------------
        // - Interfaces --------------------------------------------------------
        // ---------------------------------------------------------------------

        interface IPatchToolServer
        {
            // Attributes.
            readonly attribute string caseRoot;
            readonly attribute string caseName;

            //
            // Database
            //

            // Time-steps.
            readonly attribute StringList availableTimeSteps;

            // Get current time
            string getTime()
                raises(FoamXError, FoamXIOError);

            // Set time
            void setTime(in string timeName, in long timeIndex)
                raises(FoamXError, FoamXIOError);


            //
            // I/O
            //

            // Read mesh and construct boundary mesh
            void read() raises(FoamXError, FoamXIOError);

            // Read triangulated surface from file
            void readTriSurface(in string fileName)
                raises(FoamXError, FoamXIOError);

            // Map onto mesh and write mesh
            void write() raises(FoamXError, FoamXIOError);

            // Write triangulated surface file
            void writeTriSurface(in string fileName)
                raises(FoamXError, FoamXIOError);


            //
            // Access
            //

            void getPoints(out FloatList points) raises(FoamXError);

            long getNFaces() raises(FoamXError);

            long getNEdges() raises(FoamXError);

            void getEdges(out LongList verts) raises(FoamXError);


            //
            // Feature edges and extra edges
            //

            // Calculate feature edges
            void setFeatureEdges(in double minCos) raises(FoamXError);

            // Compact points
            void getFeaturePoints(out FloatList points) raises(FoamXError);

            // labels of featurePoints
            void getFeatureEdges(out LongList edgeLabels) raises(FoamXError);

            // labels of edges that are features
            void getFeatureToEdge(out LongList edgeLabels) raises(FoamXError);

            // From edge to featureEdge
            void getEdgeToFeature(out LongList featLabels) raises(FoamXError);

            // Feature 'segments'. Arrays of indices into featureEdges
            void getFeatureSegments(out LongLongList featureSegments)
                raises(FoamXError);


            // Extra edges: labels of edges that are within some distance
            // of an edge
            void setExtraEdges(in long edgeI) raises(FoamXError);

            void getExtraEdges(out LongList edgeLabels) raises(FoamXError);


            //
            // Patches
            //

            // Get patch of face
            long whichPatch(in long faceI) raises(FoamXError);

            // Get index of patch by name
            long findPatchID(in string patchName) raises(FoamXError);

            // Get all patches
            void getPatches(out SurfacePatchList patches) raises(FoamXError);

            // Add patch
            void addPatch(in string patchName) raises(FoamXError);

            // Delete patch
            void deletePatch(in string patchName) raises(FoamXError);

            // Change patch type
            void changePatchType(in string patchName, in string patchType)
                raises(FoamXError);

            // Change patch faces
            void changeFaces(in LongList patchIDs, out LongList oldToNew)
             raises(FoamXError);


            //
            // Face handling
            //

            // Precalculate number of triangles resulting from triangulation
            // of subset of faces startFaceI .. startFaceI + nFaces.
            // Return total number of triangles.
            long getNTris
            (
                in long startFaceI,
                in long nFaces,
                out LongList nTris
            ) raises(FoamXError);

            // Triangulate faces startFaceI .. startFaceI + nFaces.
            // Triangles returned as 3 consecutive vertices in tris.
            void triangulate
            (
                in long startFaceI,
                in long nFaces,
                in long totalNTris,
                out LongList triVerts
            ) raises(FoamXError);

            // Precalculate number of points used in face set local
            // triangulation
            long getNPoints(in long startFaceI, in long nFaces)
             raises(FoamXError);

            // Like triangulate but in local coords. Returns map from local
            // to global coords.
            void triangulateLocal
            (
                in long startFaceI,
                in long nFaces,
                in long totalNTris,
                out LongList triVerts,
                out LongList localToGlobal
            ) raises(FoamXError);


            //
            // Other
            //

            // Flood filling
            void markFaces
            (
                in LongList protectedEdges,
                in long faceI,
                out BoolList visited
            ) raises(FoamXError);

            //- Lifetime management.
            oneway void close();
        };
    };

};


// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

#endif

// ************************************************************************* //
