#ifndef QSAS_QDU_H_
#define QSAS_QDU_H_

#define REMOVE_GAP "remove gaps"
#define ZERO_FILL_GAP "zero-fill"
#define FILL_GAP "fill value"
#define LINEAR_INTERP_GAP "linear interpolation"
#define NEAREST_NEIGHBOUR_GAP "nearest neighbour"
#define NEW_NAME "new name"

#include <stdlib.h>
#include "Qdos.h"
#include "Xrefs.h"
#include "qprofile.h"
#include <qcolordialog.h>
#include <qcheckbox.h>

#if QT_VERSION >= 0x040000
#include <QLayout>
#endif

namespace QSAS
{

   void QuMultiJoin( QdObjectSeq_var        join_obj_seq,
		               QdTimeSeq_var          join_pts,
                       QdObjectSeq_var        joined_obj_seq,
		               vector<KVDataBase_var> options,
                      int                    triage_cnt = -1 );

   void QuMultiJoinXrefs(QdObject_var preJoinObj, QdObject_var joinedObj, QdObject_var joinMethod, QdObject_var gap);

} // end namespace QSAS

using namespace std;

typedef vector <int> dimTriple;
typedef vector <dimTriple> dimTripleStack;

#define R_STR_CMP " [ r (mag) ]"
#define X_STR_CMP " [ x ]"
#define Y_STR_CMP " [ y ]"
#define Z_STR_CMP " [ z ]"
#define Ld_STR_CMP " [ Lat (deg) ]"
#define Lr_STR_CMP " [ Lat (rad) ]"
#define Td_STR_CMP " [ theta (deg) ]"
#define Tr_STR_CMP " [ theta (rad) ]"
#define Pd_STR_CMP " [ phi (deg) ]"
#define Pr_STR_CMP " [ phi (rad) ]"
#define T_STR_START " [ Start Time ]"
#define T_STR_CENTRE " [ Centre Time ]"
#define T_STR_END " [ End Time ]"

typedef enum QguComp_e
{
  UNKNOWN_COMP=-1,
  WL_OBJ=0,
  R_COMP=1,
  X_COMP=2,
  Y_COMP=3,
  Z_COMP=4,
  LAT_DEG_COMP=5,
  THETA_DEG_COMP=6,
  PHI_DEG_COMP=7,
  LAT_RAD_COMP=8,
  THETA_RAD_COMP=9,
  PHI_RAD_COMP=10,
  ARRAY_COMP=11,
  XREF_COMP=12,
  T_START_COMP=13,
  T_CENTRE_COMP=14,
  T_END_COMP=15,
  XREF_OBJ=16,
  SLICE_COMP=17
} QguComp;

QString QuGetDefaultComp(const QString& WL, const QString& compDef);
void QuReplaceTokens(QString &newTxt, QString &oldTxt);
bool QuIsMatch(double value, double fill);
QCheckBox * checkBadData(QWidget *parent=0);
QCheckBox * checkFills(QWidget *parent=0);
bool QuSlotDebug();
string QuCommonLabl(string str1, string str2);
QdObject_var QuGetObjByName(QString name);
QdObject_var QuTakeSlice(vector <string> objectNameList, QdObject_var dobj, dimTriple sliceTriple, bool getInterval);
QdObject_var QuGetSubset(QdObject_var dobj, int recStart, int recEnd);
QString baseObjectText(QString);
QguComp compEntry(const char*,const char*);
QguComp compEntry(const char*);
QString compText(QString);
QString compText(QString, const dimTriple&);
QString getXrefName(QString);
dimTriple getDimTriple(QString &compTxt);
dimTriple getSliceTriple(const QString &compTxt);
dimTripleStack getDimTripleStack(QString &compTxt);
QdObject_var QuGetObjByNameAndComp(QString name);
QdObject_var QuGetIntervalByNameAndComp(QString name);
ObjectNamesTable_var QuGet_object_names_table();
void QuSetTxtAttr(char *attrName, const char *value, QdObject_var obj);
bool QuIsBadData(double value, double fill);
void applyMaskToXrefs(QdObject_var ms_in, QdObject_var ms_out, SequenceMask msk, QdTimeSeq_var tt_out);
QdObject_var QuCleanObject(QdObject_var dobj);
void QuMsgBar(const char * text, bool error);
void QuMsgBar(const char* text1, const char* text2, bool error);
void QuSetOK();
int QuStrcpy(char * To, const char * From, int ToLen);
int QuStrcat(char * To, const char * From, int ToLen);
char* QuGetAttrConcat(const char *attrName, QdObject_var obj);
const char* QuGetAttrCondensed(const char *attrName, QdObject_var obj);
char * QuGetAttrText(const char* attrName, QdObject_var obj);
const char * QuToUpper(const char *InStr);
void QuSetFrame(QdObject_var obj, const char *txt, const char*frm=0, const char*rep=0);
char * QuGetFrameAttr(QdObject_var obj);
char * QuGetFrameAttr(QdObject_var obj1, QdObject_var obj2);
const char * QuGetOrder(QdObject_var obj);
const char * QuGetFrame(QdObject_var obj);
const char * QuGetRep(QdObject_var obj);
bool QuIsThreeVector(QdObject_var obj);
bool QuIsScalar(QdObject_var obj);
char* QuGetVectorRep(QdObject_var obj);
QdObject_var QuGetVectorXYZ(QdObject_var dov);
void QuSetRep(const char* rep, QdObject_var do_out);
bool QuIsAngleDegrees(QdObject_var dobj);
double ConvertThetaRad(double theta);
double ConvertThetaDeg(double theta);
bool QuIsTSRegular(QdTimeSeq_var tt, double *spacing);
char * QuSanitizeName ( const char * oldName);
bool QuIsJoined(QdObject_var obj1, QdObject_var obj2);
int QuArrayDims(QdObject_var obj);
bool copyXref(const char * name, QdObject_var from_ptr, QdObject_var to_ptr);
bool copyDimXrefs( QdObject_var from_ptr, QdObject_var to_ptr);
QdObject_var QuGetArrayComponent(QdObject_var doa, dimTripleStack dimStack, string arrComp_xref="");
QdObject_var QuGetVectorComponent(QdObject_var dov, const char *vcomp);
QdObject_var QuGetTimeComponent(QdObject_var dot, const char *tcomp);
QdObject_var QuSliceArray(QdObject_var doa, int indx, int entry );
QdObject_var QuSumArray(QdObject_var doa, int indx, int from, int to, bool average );
QdObject_var QuSubsetArray(QdObject_var doa, int indx, int from, int to );
bool QuStrCmp(const char *A, const char *B);
QColor QuGetColour(QColor inC, bool *newChoice, QWidget * parent);
void QuGetBounds(QdTimeSeq_var tt, int &recL, int &recU, const Time& t);
bool QuGetIvlRecBound(QdTimeSeq_var tt, int &recStart, int &recEnd, const Time& tStart, const Time& tEnd);
QdObject_var QuSetCompFromObjText(const QString&, QString&);
QdTimeInterval_var QuGetIvlFromSlice(QdObject_var, const dimTriple&);
bool QuGetSliceFromIvl(QdObject_var,QdTimeInterval_var,dimTriple&);
QdTimeSeq_var get_timetags(const QdObject_var& obj);
QdTimeInterval_var get_timeinterval(const QdObject_var& obj);
QdTimeSeq_var get_timetags_inrange(const QdTimeSeq_var& ts_in, const QdTimeInterval_var& tint);
double get_time_spacing(const QdObject_var& obj);
void set_timetags(QdObject_var obj, QdTimeSeq_var ts);
int num_timetags_inrange(const QdTimeSeq_var& ts, const QdTimeInterval_var& tint);
bool is_empty(const QdObject_var& obj);
void QuNow(const char * txt);
int QuLength(QdObject_var obj);
bool QuSet_Array(int ndata, double *floatArray, QdObject_var obj);

bool QuSetObjByName(QdObject_var ToSetobj, QString name);
void QuRenameObject(QString oldName, QString newName);
QdObject_var QuGetObjByName(QString name);
void QuDeleteObject(QString name);
void QuReplaceObject(QString name, QdObject_var new_obj);
QdObject_var QuDuplicateObject(QString name);
QString QuNameOnly(QString nameContext);
QString QuTextInputDialog(const char *caption, const char *label, const char * defText, bool *OK, QWidget * parent);
double getSpacingTolerance(QdRScalarSeq_var rseq);
bool QuGetDataRange(QdObject_var obj, double &min, double &max);
bool QuIsBad(double value, double fill);
void setRestoreVersion(const char *version);

# endif // QSAS_QDU_H_
