<commit_before>#include "navigate.h"

#include <assert.h>
#include <cstdio>
#include <string.h>
#include <cmath>

#define  REAL_TYPE_SIZE  (sizeof(real))

union charDouble
{
    char c[ REAL_TYPE_SIZE ];
    real db;
};

/**
 * @brief toDouble
 * 转换double型数据的字节序
 *
 * @param x
 */
void toDouble(real &x)
{
    charDouble cd;
    cd.db = x;

    char c[REAL_TYPE_SIZE] = {0};
    int  tpsize = REAL_TYPE_SIZE;

    for ( int i = 0; i < tpsize; ++i)
        c[i] = cd.c[tpsize-i-1];
    x = *(real*)c;
}
/**
 * @brief toBigEndian
 * 转换int型数据字节序
 * @param x
 */
void  toBigEndian(int& x)
{
    x = ( (x & 0x000000ff) << 24 ) | ( (x & 0x0000ff00) << 8)
            | ((x & 0x00ff0000) >> 8) | ( (x & 0xff000000) >> 24);
}

Navigate::Navigate()
{
    _coordsys = LeftHandSys;
}

Navigate::~Navigate()
{
    vector<Node*>::iterator ptiter= __points.begin();

    while ( ptiter != __points.end() )
    {
        delete *ptiter;
        ptiter = __points.erase(ptiter);
    }

    ClearResult();
}

list<Node*> Navigate::GetNeighbor(Node *center)
{
    vector<int> ids = center->neigbours;
    list<Node*> res;
    for ( size_t i = 0 ; i < ids.size(); i++ )
    {
        if (_id2points[ids[i]]->type != 1)
            res.push_back(_id2points[ids[i]]);
    }
    return res;

}

void Navigate::LoadPointsFile(const char *file)
{

    //二进制文件读取
    FILE *f = fopen(file,"rb");
    char buf[32] = {0};
    int floorcount = 0,k = 0;

    if ( NULL == f )
        return;

    //楼层编号
    fread(buf,1,32,f);
    //楼层数
    fread(&floorcount,sizeof(int),1,f);
    toBigEndian(floorcount);
    if ( floorcount <= 0) return;

    //for 楼层
    for ( k = 0 ; k < floorcount;k++)
    {
        int count = 0, floor = 0;
        //楼层编号
        fread(buf,1,32,f);
        fread(&floor,sizeof(int),1,f);
        toBigEndian(floor);
        //总点数
        fread(&count,sizeof(int),1,f);
        toBigEndian(count);
        list<int>  lnd;
        _floor_binds[count] = lnd;
        //for 楼层点
        for ( int i = 0 ; i < count; ++i)
        {
            Node *nd = new Node;

            //楼层
            nd->floor = floor;
            fread(&nd->id,sizeof(int),1,f);
            toBigEndian(nd->id);

            //点类型
            fread(&nd->type,sizeof(int),1,f);
            toBigEndian(nd->type);
            fread(&nd->x,sizeof(real),1,f);
            toDouble(nd->x);

            fread(&nd->y,sizeof(real),1,f);
            toDouble(nd->y);
            //相邻路口数
            int nbcount;
            fread(&nbcount,sizeof(int),1,f);
            toBigEndian(nbcount);
            nd->neighborcount = nbcount;
            nd->neigbours.resize(nbcount);
            for ( int j = 0 ; j < nbcount; ++j)
            {
                fread(&nd->neigbours[j],sizeof(int),1,f);
                toBigEndian(nd->neigbours[j]);
            }
            _id2points[nd->id] = nd;
            __points.push_back(nd);

            if ( nd->type == Bind )
            {
                _binds.push_back(nd);
                lnd.push_back(nd->id);
                _floor_binds[nd->floor] = lnd;
            }
        }//end for 楼层点
    }//end for 楼层
    fclose(f);
}

list<Node*> Navigate::GetBestPath(Node *start, Node *end)
{
    ClearResult();

    bool    bfinded = true;
    list<Node*> result;
    if ( start == NULL || end == NULL )
        return result;
    //起点终点相同，不予导航
    if ( EQUAL(start->x , end->x) && EQUAL(start->y,end->y))
        return result;
    //未给定路径，不予导航
    if (__points.size() <= 0)
        return result;

    assert(start != NULL && end != NULL);

    _start = start;
    _end = end;

    Node *start_2 = GetNearPathNode(start);
    Node *end_2 = GetNearPathNode(end);

    list<Node*> neighbor = GetNeighbor(start_2);
    list<Node*>::iterator iter = neighbor.begin();

    for ( ; iter != neighbor.end(); ++iter)
    {
        AddToOpenList( start_2,*iter );
    }
    AddToCloseList( start_2 );
    Node *nstart = start_2;
    //memcpy(&nstart,start,sizeof(Node));
    while ( !IsInPath(_closeList,end_2) )
    {
        if ( _openList.empty())
        {
            bfinded = false;
            break;
        }
        //从开放集中获取最小F值的数据点并加入封闭集中
        Node *min_nd = GetMiniFNode(nstart);
        nstart = min_nd;
        AddToCloseList(min_nd);
        RemoveFromOpenList(min_nd);
        //检查并更新该点邻域数值
        list<Node*> newneighbor = GetNeighbor(min_nd);
        list<Node*> ::iterator nbiter = newneighbor.begin();
        for ( ; nbiter != newneighbor.end(); ++nbiter )
        {
            // 分两种情况
            if ( IsInPath(_closeList,*nbiter))
                continue;
            //1: 未在开放集中,更新父节点及g值，放入开放集中
            if ( !IsInPath(_openList,*nbiter))
            {
                (*nbiter)->parent = min_nd;
                (*nbiter)->g = min_nd->g + GetGValue(min_nd,*nbiter);
                AddToOpenList(min_nd,*nbiter);
            }
            //2: 已在开放集中,发掘更优路径
            else
            {
                real g = min_nd->g + GetGValue(min_nd,*nbiter);
                if ( g < (*nbiter)->g )
                {
                    (*nbiter)->parent = min_nd;
                    (*nbiter)->g = g;
                }
            }
        }
    }

    if ( !bfinded ){

        cout<<"Can not Find"<<endl;
        return result;

    }
    else{
        cout<<"Finded and Path node cout:"<<_closeList.size()<<endl;
    }
    Node *nd = _closeList.front();
    result.push_front(end);
    while ( (*nd)!=(*start_2) )
    {
        result.push_front(nd->parent);
        nd = nd->parent;
    }
    if ( start_2 != start )
    {
        result.push_front(start);
    }
    _closeList.clear();
    _openList.clear();
    UpdateDirect(result);
    return result;
}

void Navigate::AddToCloseList(Node *center)
{
//    Node *nd = new Node;

//    memcpy(nd,center,sizeof(Node));
//    nd->parent = center->parent;
//    _closeList.push_front(nd);
    _closeList.push_front(center);
}
//为尽可能简化程序，提高运行效率
//该方法认为要添加的点在开放集中不存在，直接添加
void Navigate::AddToOpenList(Node *parent,Node *center)
{
//    Node *nd = new Node;

//    memcpy(nd,center,sizeof(Node));
//    nd->parent = parent;
//    _openList.push_front(nd);
    center->parent = parent;
    _openList.push_front(center);
}

void Navigate::ClearResult()
{
    _openList.clear();
    _closeList.clear();
//    list<Node*> ::iterator it1 = _openList.begin();
//    while ( it1 != _openList.end())
//    {
//        delete *it1;
//        it1 = _openList.erase(it1);
//    }

//    list<Node*> ::iterator it2 = _closeList.begin();
//    while ( it2!= _closeList.end() )
//    {
//        delete *it2;
//        it2 = _closeList.erase(it2);
//    }
}

real Navigate::GetGValue(Node *n1, Node *n2)
{
    real dx = n1->x - n2->x;
    real dy = n2->y - n1->y;

    return sqrt( dx * dx + dy * dy );
}
bool Navigate::IsInPath(list<Node *> path, Node *nd)
{
    if ( path.size() <= 0 || nd == NULL )
        return false;
    list<Node*>::iterator it = path.begin();
    for ( ; it != path.end() ; ++it )
    {
        if ( EQUAL( (*it)->x,nd->x) && EQUAL( (*it)->y,nd->y) )
            return true;
    }
    return false;
}
void Navigate::RemoveFromCloseList(Node *nd)
{
    list<Node*>::iterator iter = _closeList.begin();
    while ( iter != _closeList.end())
    {
        if ( EQUAL((*iter)->x,nd->x) && EQUAL((*iter)->y,nd->y) )
        {
            iter = _closeList.erase(iter);
        }else
            ++iter;
    }
}
void Navigate::RemoveFromOpenList(Node *nd)
{
    list<Node*>::iterator iter = _openList.begin();
    while ( iter != _openList.end())
    {
        if ( EQUAL((*iter)->x,nd->x) && EQUAL((*iter)->y,nd->y) )
        {
            iter = _openList.erase(iter);
        }else
            ++iter;
    }
}
Node* Navigate::GetMiniFNode(Node *cur)
{
    list<Node*>::iterator iter = _openList.begin();
    real minf = INVALID;
    bool flag = false;
    Node *res;

    for ( ; iter != _openList.end(); ++iter )
    {
        real g = cur->g + GetGValue(cur,*iter);
        (*iter)->h = GetGValue(*iter,_end);
        real f = g + (*iter)->h;
        if ( f < minf )
        {
            flag = true;
            minf = f;
//            res->parent = cur;
            res = (*iter);
        }
    }

    return res;
}

//
//根据路径更新路径点的方向信息
//路径中至少需包含三个数据点
void Navigate::UpdateDirect(list<Node *> &path)
{
    if ( path.size() < 3)
        return;

    list<Node*>::iterator iter = path.begin();
    Node *nd1 = *iter;
    Node *nd2 = NULL;
    Node *nd3 = NULL;

    nd2 = *(++iter);
    nd3 = *(++iter);
    --iter;
    --iter;

    nd1->attr = WalkDirect;
    for( iter ; iter != path.end(); ++iter )
    {

        Vec v12(nd2->x - nd1->x, nd2->y - nd1->y),
            v13(nd3->x - nd1->x, nd3->y - nd1->y);
        Vec v23(nd3->x - nd2->x, nd3->y - nd2->y);

        real angle = VectorAngle(&v12,&v23);

        real cross = VectorCrossMulti(&v12,&v13);
        if ( angle > 15 && cross < 0)
        {
            nd2->attr = TurnRight;
        }else if ( angle > 15 && cross > 0 )
        {
            nd2->attr = TurnLeft;
        }else
        {
            nd2->attr = WalkDirect;
        }

//        if ( nd2->neighborcount <= 2)
//        {
//            nd2->attr = WalkAlong;
//        }

        nd1 = nd2;
        nd2 = nd3;
        ++iter; //2
        ++iter; //3
        ++iter; //下一个要处理的点
        if ( iter == path.end())
        {
            (*(--iter))->attr = Arrive;
            break;
        }
        nd3 = *(iter);
        --iter;
        --iter;
        --iter;
    }

}

Node *Navigate::GetNearPathNode(Node *nd)
{
    Node *res = NULL;
    if ( nd->type == Endian )
    {
        return nd;
    }else
    {
        int nbcount = nd->neighborcount;
        real mindis = INVALID;
        for ( int i = 0 ; i < nbcount ; ++i)
        {
            Node * nb = GetPoint(nd->neigbours[i]);
            if ( nb->type != Endian )
            {
                continue;
            }
            real dis = Distance(nd,nb);
            if ( dis < mindis )
            {
                mindis = dis;
                res = nb;
            }
        }
    }

//    real mindis = INVALID;
//    Node *res = NULL;
//    int i = 0, count = __points.size();
//    for ( i = 0 ; i < count; ++i)
//    {
//        if (__points[i]->type == Endian)
//        {
//            real dis = Distance(nd,__points[i]);
//            if ( dis < mindis)
//            {
//                mindis = dis;
//                res = __points[i];
//            }
//        }

//    }
    return res;
}

Node *Navigate::getNearestBind(Node *ndsrc)
{
    real    mindis = INVALID;
    int     floor = ndsrc->floor;
    Node    *res = NULL;

    if ( _floor_binds.find(floor) == _floor_binds.end() )
        return NULL;
    list<int>   lbs = _floor_binds[floor];

    list<int>::iterator it = lbs.begin();
    while ( it != lbs.end() )
    {
        Node *nd = GetPoint(*it);
        real dis = Distance(ndsrc,nd);
        if ( dis <= mindis)
        {
            mindis = dis;
            res = nd;
        }
        ++it;
    }

    return res;
}
<commit_msg>update start point selection algorithm<commit_after>#include "navigate.h"

#include <assert.h>
#include <cstdio>
#include <string.h>
#include <cmath>

#define  REAL_TYPE_SIZE  (sizeof(real))

union charDouble
{
    char c[ REAL_TYPE_SIZE ];
    real db;
};

/**
 * @brief toDouble
 * 转换double型数据的字节序
 *
 * @param x
 */
void toDouble(real &x)
{
    charDouble cd;
    cd.db = x;

    char c[REAL_TYPE_SIZE] = {0};
    int  tpsize = REAL_TYPE_SIZE;

    for ( int i = 0; i < tpsize; ++i)
        c[i] = cd.c[tpsize-i-1];
    x = *(real*)c;
}
/**
 * @brief toBigEndian
 * 转换int型数据字节序
 * @param x
 */
void  toBigEndian(int& x)
{
    x = ( (x & 0x000000ff) << 24 ) | ( (x & 0x0000ff00) << 8)
            | ((x & 0x00ff0000) >> 8) | ( (x & 0xff000000) >> 24);
}

Navigate::Navigate()
{
    _coordsys = LeftHandSys;
}

Navigate::~Navigate()
{
    vector<Node*>::iterator ptiter= __points.begin();

    while ( ptiter != __points.end() )
    {
        delete *ptiter;
        ptiter = __points.erase(ptiter);
    }

    ClearResult();
}

list<Node*> Navigate::GetNeighbor(Node *center)
{
    vector<int> ids = center->neigbours;
    list<Node*> res;
    for ( size_t i = 0 ; i < ids.size(); i++ )
    {
        if (_id2points[ids[i]]->type != 1)
            res.push_back(_id2points[ids[i]]);
    }
    return res;

}

void Navigate::LoadPointsFile(const char *file)
{

    //二进制文件读取
    FILE *f = fopen(file,"rb");
    char buf[32] = {0};
    int floorcount = 0,k = 0;

    if ( NULL == f )
        return;

    //楼层编号
    fread(buf,1,32,f);
    //楼层数
    fread(&floorcount,sizeof(int),1,f);
    toBigEndian(floorcount);
    if ( floorcount <= 0) return;

    //for 楼层
    for ( k = 0 ; k < floorcount;k++)
    {
        int count = 0, floor = 0;
        //楼层编号
        fread(buf,1,32,f);
        fread(&floor,sizeof(int),1,f);
        toBigEndian(floor);
        //总点数
        fread(&count,sizeof(int),1,f);
        toBigEndian(count);
        list<int>  lnd;
        _floor_binds[count] = lnd;
        //for 楼层点
        for ( int i = 0 ; i < count; ++i)
        {
            Node *nd = new Node;

            //楼层
            nd->floor = floor;
            fread(&nd->id,sizeof(int),1,f);
            toBigEndian(nd->id);

            //点类型
            fread(&nd->type,sizeof(int),1,f);
            toBigEndian(nd->type);
            fread(&nd->x,sizeof(real),1,f);
            toDouble(nd->x);

            fread(&nd->y,sizeof(real),1,f);
            toDouble(nd->y);
            //相邻路口数
            int nbcount;
            fread(&nbcount,sizeof(int),1,f);
            toBigEndian(nbcount);
            nd->neighborcount = nbcount;
            nd->neigbours.resize(nbcount);
            for ( int j = 0 ; j < nbcount; ++j)
            {
                fread(&nd->neigbours[j],sizeof(int),1,f);
                toBigEndian(nd->neigbours[j]);
            }
            _id2points[nd->id] = nd;
            __points.push_back(nd);

            if ( nd->type == Bind )
            {
                _binds.push_back(nd);
                lnd.push_back(nd->id);
                _floor_binds[nd->floor] = lnd;
            }
        }//end for 楼层点
    }//end for 楼层
    fclose(f);
}

list<Node*> Navigate::GetBestPath(Node *start, Node *end)
{
    ClearResult();

    bool    bfinded = true;
    list<Node*> result;
    if ( start == NULL || end == NULL )
        return result;
    //起点终点相同，不予导航
    if ( EQUAL(start->x , end->x) && EQUAL(start->y,end->y))
        return result;
    //未给定路径，不予导航
    if (__points.size() <= 0)
        return result;

    assert(start != NULL && end != NULL);

    _start = start;
    _end = end;

    Node *start_2 = GetNearPathNode(start);
    Node *end_2 = GetNearPathNode(end);

    list<Node*> neighbor = GetNeighbor(start_2);
    list<Node*>::iterator iter = neighbor.begin();

    for ( ; iter != neighbor.end(); ++iter)
    {
        AddToOpenList( start_2,*iter );
    }
    AddToCloseList( start_2 );
    Node *nstart = start_2;
    //memcpy(&nstart,start,sizeof(Node));
    while ( !IsInPath(_closeList,end_2) )
    {
        if ( _openList.empty())
        {
            bfinded = false;
            break;
        }
        //从开放集中获取最小F值的数据点并加入封闭集中
        Node *min_nd = GetMiniFNode(nstart);
        nstart = min_nd;
        AddToCloseList(min_nd);
        RemoveFromOpenList(min_nd);
        //检查并更新该点邻域数值
        list<Node*> newneighbor = GetNeighbor(min_nd);
        list<Node*> ::iterator nbiter = newneighbor.begin();
        for ( ; nbiter != newneighbor.end(); ++nbiter )
        {
            // 分两种情况
            if ( IsInPath(_closeList,*nbiter))
                continue;
            //1: 未在开放集中,更新父节点及g值，放入开放集中
            if ( !IsInPath(_openList,*nbiter))
            {
                (*nbiter)->parent = min_nd;
                (*nbiter)->g = min_nd->g + GetGValue(min_nd,*nbiter);
                AddToOpenList(min_nd,*nbiter);
            }
            //2: 已在开放集中,发掘更优路径
            else
            {
                real g = min_nd->g + GetGValue(min_nd,*nbiter);
                if ( g < (*nbiter)->g )
                {
                    (*nbiter)->parent = min_nd;
                    (*nbiter)->g = g;
                }
            }
        }
    }

    if ( !bfinded ){

        cout<<"Can not Find"<<endl;
        return result;

    }
    else{
        cout<<"Finded and Path node cout:"<<_closeList.size()<<endl;
    }
    Node *nd = _closeList.front();
    result.push_front(end);
    while ( (*nd)!=(*start_2) )
    {
        result.push_front(nd->parent);
        nd = nd->parent;
    }
    if ( start_2 != start )
    {
        result.push_front(start);
    }
    _closeList.clear();
    _openList.clear();
    UpdateDirect(result);
    return result;
}

void Navigate::AddToCloseList(Node *center)
{
//    Node *nd = new Node;

//    memcpy(nd,center,sizeof(Node));
//    nd->parent = center->parent;
//    _closeList.push_front(nd);
    _closeList.push_front(center);
}
//为尽可能简化程序，提高运行效率
//该方法认为要添加的点在开放集中不存在，直接添加
void Navigate::AddToOpenList(Node *parent,Node *center)
{
//    Node *nd = new Node;

//    memcpy(nd,center,sizeof(Node));
//    nd->parent = parent;
//    _openList.push_front(nd);
    center->parent = parent;
    _openList.push_front(center);
}

void Navigate::ClearResult()
{
    _openList.clear();
    _closeList.clear();
//    list<Node*> ::iterator it1 = _openList.begin();
//    while ( it1 != _openList.end())
//    {
//        delete *it1;
//        it1 = _openList.erase(it1);
//    }

//    list<Node*> ::iterator it2 = _closeList.begin();
//    while ( it2!= _closeList.end() )
//    {
//        delete *it2;
//        it2 = _closeList.erase(it2);
//    }
}

real Navigate::GetGValue(Node *n1, Node *n2)
{
    real dx = n1->x - n2->x;
    real dy = n2->y - n1->y;

    return sqrt( dx * dx + dy * dy );
}
bool Navigate::IsInPath(list<Node *> path, Node *nd)
{
    if ( path.size() <= 0 || nd == NULL )
        return false;
    list<Node*>::iterator it = path.begin();
    for ( ; it != path.end() ; ++it )
    {
        if ( EQUAL( (*it)->x,nd->x) && EQUAL( (*it)->y,nd->y) )
            return true;
    }
    return false;
}
void Navigate::RemoveFromCloseList(Node *nd)
{
    list<Node*>::iterator iter = _closeList.begin();
    while ( iter != _closeList.end())
    {
        if ( EQUAL((*iter)->x,nd->x) && EQUAL((*iter)->y,nd->y) )
        {
            iter = _closeList.erase(iter);
        }else
            ++iter;
    }
}
void Navigate::RemoveFromOpenList(Node *nd)
{
    list<Node*>::iterator iter = _openList.begin();
    while ( iter != _openList.end())
    {
        if ( EQUAL((*iter)->x,nd->x) && EQUAL((*iter)->y,nd->y) )
        {
            iter = _openList.erase(iter);
        }else
            ++iter;
    }
}
Node* Navigate::GetMiniFNode(Node *cur)
{
    list<Node*>::iterator iter = _openList.begin();
    real minf = INVALID;
    bool flag = false;
    Node *res;

    for ( ; iter != _openList.end(); ++iter )
    {
        real g = cur->g + GetGValue(cur,*iter);
        (*iter)->h = GetGValue(*iter,_end);
        real f = g + (*iter)->h;
        if ( f < minf )
        {
            flag = true;
            minf = f;
//            res->parent = cur;
            res = (*iter);
        }
    }

    return res;
}

//
//根据路径更新路径点的方向信息
//路径中至少需包含三个数据点
void Navigate::UpdateDirect(list<Node *> &path)
{
    if ( path.size() < 3)
        return;

    list<Node*>::iterator iter = path.begin();
    Node *nd1 = *iter;
    Node *nd2 = NULL;
    Node *nd3 = NULL;

    nd2 = *(++iter);
    nd3 = *(++iter);
    --iter;
    --iter;

    nd1->attr = WalkDirect;
    for( iter ; iter != path.end(); ++iter )
    {

        Vec v12(nd2->x - nd1->x, nd2->y - nd1->y),
            v13(nd3->x - nd1->x, nd3->y - nd1->y);
        Vec v23(nd3->x - nd2->x, nd3->y - nd2->y);

        real angle = VectorAngle(&v12,&v23);

        real cross = VectorCrossMulti(&v12,&v13);
        if ( angle > 15 && cross < 0)
        {
            nd2->attr = TurnRight;
        }else if ( angle > 15 && cross > 0 )
        {
            nd2->attr = TurnLeft;
        }else
        {
            nd2->attr = WalkDirect;
        }

//        if ( nd2->neighborcount <= 2)
//        {
//            nd2->attr = WalkAlong;
//        }

        nd1 = nd2;
        nd2 = nd3;
        ++iter; //2
        ++iter; //3
        ++iter; //下一个要处理的点
        if ( iter == path.end())
        {
            (*(--iter))->attr = Arrive;
            break;
        }
        nd3 = *(iter);
        --iter;
        --iter;
        --iter;
    }

}

Node *Navigate::GetNearPathNode(Node *nd)
{
    Node *res = NULL;
    if ( nd->type == Endian )
    {
        return nd;
    }else
    {
        int nbcount = nd->neighborcount;
        real mindis = INVALID;
        for ( int i = 0 ; i < nbcount ; ++i)
        {
            Node * nb = GetPoint(nd->neigbours[i]);
            if ( nb->type != Endian )
            {
                continue;
            }
            real dis = Distance(_end,nb);
            if ( dis < mindis )
            {
                mindis = dis;
                res = nb;
            }
        }
    }

//    real mindis = INVALID;
//    Node *res = NULL;
//    int i = 0, count = __points.size();
//    for ( i = 0 ; i < count; ++i)
//    {
//        if (__points[i]->type == Endian)
//        {
//            real dis = Distance(nd,__points[i]);
//            if ( dis < mindis)
//            {
//                mindis = dis;
//                res = __points[i];
//            }
//        }

//    }
    return res;
}

Node *Navigate::getNearestBind(Node *ndsrc)
{
    real    mindis = INVALID;
    int     floor = ndsrc->floor;
    Node    *res = NULL;

    if ( _floor_binds.find(floor) == _floor_binds.end() )
        return NULL;
    list<int>   lbs = _floor_binds[floor];

    list<int>::iterator it = lbs.begin();
    while ( it != lbs.end() )
    {
        Node *nd = GetPoint(*it);
        real dis = Distance(ndsrc,nd);
        if ( dis <= mindis)
        {
            mindis = dis;
            res = nd;
        }
        ++it;
    }

    return res;
}
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: objfac3d.cxx,v $
 *
 *  $Revision: 1.4 $
 *
 *  last change: $Author: rt $ $Date: 2005-09-08 22:40:56 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library 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
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

#ifndef _SVDPAGE_HXX
#include "svdpage.hxx"
#endif

#ifndef _E3D_GLOBL3D_HXX
#include "globl3d.hxx"
#endif

#ifndef _E3D_POLYSC3D_HXX
#include "polysc3d.hxx"
#endif

#ifndef _E3D_DLIGHT3D_HXX
#include "dlight3d.hxx"
#endif

#ifndef _E3D_PLIGHT3D_HXX
#include "plight3d.hxx"
#endif

#ifndef _E3D_POLYOB3D_HXX
#include "polyob3d.hxx"
#endif

#ifndef _E3D_CUBE3D_HXX
#include "cube3d.hxx"
#endif

#ifndef _E3D_SPHERE3D_HXX
#include "sphere3d.hxx"
#endif

#ifndef _E3D_EXTRUD3D_HXX
#include "extrud3d.hxx"
#endif

#ifndef _E3D_LATHE3D_HXX
#include "lathe3d.hxx"
#endif

#ifndef _E3D_POLYGON3D_HXX
#include "polygn3d.hxx"
#endif

#ifndef _OBJFAC3D_HXX
#include "objfac3d.hxx"
#endif

#ifndef _SVDOBJ_HXX
#include "svdobj.hxx"
#endif

/*************************************************************************
|*
|* Konstruktor
|*
\************************************************************************/

static BOOL bInit = FALSE;

E3dObjFactory::E3dObjFactory()
{
    if ( !bInit )
    {
        SdrObjFactory::InsertMakeObjectHdl(LINK(this, E3dObjFactory, MakeObject));
        bInit = TRUE;
    }
}

/*************************************************************************
|*
|* Destruktor
|*
\************************************************************************/

E3dObjFactory::~E3dObjFactory()
{
}

/*************************************************************************
|*
|* Chart-interne Objekte erzeugen
|*
\************************************************************************/

IMPL_LINK( E3dObjFactory, MakeObject, SdrObjFactory*, pObjFactory)
{
    if ( pObjFactory->nInventor == E3dInventor )
    {
        switch ( pObjFactory->nIdentifier )
        {
            case E3D_POLYSCENE_ID:
                pObjFactory->pNewObj = new E3dPolyScene();
                break;
//BFS01         case E3D_LIGHT_ID:
//BFS01             pObjFactory->pNewObj = new E3dLight();
//BFS01             break;
//BFS01         case E3D_DISTLIGHT_ID:
//BFS01             pObjFactory->pNewObj = new E3dDistantLight();
//BFS01             break;
//BFS01         case E3D_POINTLIGHT_ID:
//BFS01             pObjFactory->pNewObj = new E3dPointLight();
//BFS01             break;
//BFS01         case E3D_SPOTLIGHT_ID:
//BFS01             break;
            case E3D_OBJECT_ID:
                pObjFactory->pNewObj = new E3dObject();
                break;
//BFS01         case E3D_POLYOBJ_ID :
//BFS01             pObjFactory->pNewObj = new E3dPolyObj();
//BFS01             break;
            case E3D_POLYGONOBJ_ID  :
                pObjFactory->pNewObj = new E3dPolygonObj();
                break;
            case E3D_CUBEOBJ_ID :
                pObjFactory->pNewObj = new E3dCubeObj();
                break;
            case E3D_SPHEREOBJ_ID:
                    // FG: ruft den dummy constructor, da dieser Aufruf nur beim Laden von Dokumenten erfolgt.
                    //     die wirkliche Anzahkl Segmente wird aber erst nach dem Laden der Member festgelegt.
                    //     dies hat zur Folge das die erste Kugel gleich wieder zerstoert wird, obwohl sie nie
                    //     gebraucht worden ist.
                pObjFactory->pNewObj = new E3dSphereObj(123);
                break;
            case E3D_POINTOBJ_ID:
                pObjFactory->pNewObj = new E3dPointObj();
                break;
            case E3D_EXTRUDEOBJ_ID:
                pObjFactory->pNewObj = new E3dExtrudeObj();
                break;
            case E3D_LATHEOBJ_ID:
                pObjFactory->pNewObj = new E3dLatheObj();
                break;
            case E3D_LABELOBJ_ID:
                pObjFactory->pNewObj = new E3dLabelObj();
                break;
            case E3D_COMPOUNDOBJ_ID:
                pObjFactory->pNewObj = new E3dCompoundObject();
                break;
        }
    }
    return 0;
}

<commit_msg>INTEGRATION: CWS warnings01 (1.4.220); FILE MERGED 2006/04/20 13:12:36 cl 1.4.220.1: warning free code changes<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: objfac3d.cxx,v $
 *
 *  $Revision: 1.5 $
 *
 *  last change: $Author: hr $ $Date: 2006-06-19 15:46:12 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library 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
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

#ifndef _SVDPAGE_HXX
#include "svdpage.hxx"
#endif

#ifndef _E3D_GLOBL3D_HXX
#include "globl3d.hxx"
#endif

#ifndef _E3D_POLYSC3D_HXX
#include "polysc3d.hxx"
#endif

#ifndef _E3D_DLIGHT3D_HXX
#include "dlight3d.hxx"
#endif

#ifndef _E3D_PLIGHT3D_HXX
#include "plight3d.hxx"
#endif

#ifndef _E3D_CUBE3D_HXX
#include "cube3d.hxx"
#endif

#ifndef _E3D_SPHERE3D_HXX
#include "sphere3d.hxx"
#endif

#ifndef _E3D_EXTRUD3D_HXX
#include "extrud3d.hxx"
#endif

#ifndef _E3D_LATHE3D_HXX
#include "lathe3d.hxx"
#endif

#ifndef _E3D_POLYGON3D_HXX
#include "polygn3d.hxx"
#endif

#ifndef _OBJFAC3D_HXX
#include "objfac3d.hxx"
#endif

#ifndef _SVDOBJ_HXX
#include "svdobj.hxx"
#endif

/*************************************************************************
|*
|* Konstruktor
|*
\************************************************************************/

static BOOL bInit = FALSE;

E3dObjFactory::E3dObjFactory()
{
    if ( !bInit )
    {
        SdrObjFactory::InsertMakeObjectHdl(LINK(this, E3dObjFactory, MakeObject));
        bInit = TRUE;
    }
}

/*************************************************************************
|*
|* Destruktor
|*
\************************************************************************/

E3dObjFactory::~E3dObjFactory()
{
}

/*************************************************************************
|*
|* Chart-interne Objekte erzeugen
|*
\************************************************************************/

IMPL_LINK( E3dObjFactory, MakeObject, SdrObjFactory*, pObjFactory)
{
    if ( pObjFactory->nInventor == E3dInventor )
    {
        switch ( pObjFactory->nIdentifier )
        {
            case E3D_POLYSCENE_ID:
                pObjFactory->pNewObj = new E3dPolyScene();
                break;
//BFS01         case E3D_LIGHT_ID:
//BFS01             pObjFactory->pNewObj = new E3dLight();
//BFS01             break;
//BFS01         case E3D_DISTLIGHT_ID:
//BFS01             pObjFactory->pNewObj = new E3dDistantLight();
//BFS01             break;
//BFS01         case E3D_POINTLIGHT_ID:
//BFS01             pObjFactory->pNewObj = new E3dPointLight();
//BFS01             break;
//BFS01         case E3D_SPOTLIGHT_ID:
//BFS01             break;
            case E3D_OBJECT_ID:
                pObjFactory->pNewObj = new E3dObject();
                break;
//BFS01         case E3D_POLYOBJ_ID :
//BFS01             pObjFactory->pNewObj = new E3dPolyObj();
//BFS01             break;
            case E3D_POLYGONOBJ_ID  :
                pObjFactory->pNewObj = new E3dPolygonObj();
                break;
            case E3D_CUBEOBJ_ID :
                pObjFactory->pNewObj = new E3dCubeObj();
                break;
            case E3D_SPHEREOBJ_ID:
                    // FG: ruft den dummy constructor, da dieser Aufruf nur beim Laden von Dokumenten erfolgt.
                    //     die wirkliche Anzahkl Segmente wird aber erst nach dem Laden der Member festgelegt.
                    //     dies hat zur Folge das die erste Kugel gleich wieder zerstoert wird, obwohl sie nie
                    //     gebraucht worden ist.
                pObjFactory->pNewObj = new E3dSphereObj(123);
                break;
            case E3D_POINTOBJ_ID:
                pObjFactory->pNewObj = new E3dPointObj();
                break;
            case E3D_EXTRUDEOBJ_ID:
                pObjFactory->pNewObj = new E3dExtrudeObj();
                break;
            case E3D_LATHEOBJ_ID:
                pObjFactory->pNewObj = new E3dLatheObj();
                break;
            case E3D_LABELOBJ_ID:
                pObjFactory->pNewObj = new E3dLabelObj();
                break;
            case E3D_COMPOUNDOBJ_ID:
                pObjFactory->pNewObj = new E3dCompoundObject();
                break;
        }
    }
    return 0;
}

<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: ParseContext.cxx,v $
 *
 *  $Revision: 1.7 $
 *
 *  last change: $Author: ihi $ $Date: 2006-08-28 15:01:09 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library 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
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/
#ifndef SVX_QUERYDESIGNCONTEXT_HXX
#include "ParseContext.hxx"
#endif
#ifndef _TOOLS_DEBUG_HXX
#include <tools/debug.hxx>
#endif
#ifndef INCLUDED_SVTOOLS_SYSLOCALE_HXX
#include <svtools/syslocale.hxx>
#endif
#ifndef _SVX_FMRESIDS_HRC
#include "fmresids.hrc"
#endif
#include "dialmgr.hxx"
#ifndef _SV_SVAPP_HXX
#include <vcl/svapp.hxx>
#endif
#ifndef _VOS_MUTEX_HXX_
#include <vos/mutex.hxx>
#endif

using namespace svxform;
using namespace ::connectivity;
//==========================================================================
//= OSystemParseContext
//==========================================================================
DBG_NAME(OSystemParseContext);
//-----------------------------------------------------------------------------
OSystemParseContext::OSystemParseContext() : IParseContext()
{
    DBG_CTOR(OSystemParseContext,NULL);
    vos::OGuard aGuard( Application::GetSolarMutex() );
    m_aSQLInternationals = ByteString(SVX_RES(RID_STR_SVT_SQL_INTERNATIONAL),RTL_TEXTENCODING_UTF8);
}

//-----------------------------------------------------------------------------
OSystemParseContext::~OSystemParseContext()
{
    DBG_DTOR(OSystemParseContext,NULL);
}

//-----------------------------------------------------------------------------
::com::sun::star::lang::Locale OSystemParseContext::getPreferredLocale( ) const
{
    return SvtSysLocale().GetLocaleData().getLocale();
}

//-----------------------------------------------------------------------------
::rtl::OUString OSystemParseContext::getErrorMessage(ErrorCode _eCode) const
{
    String aMsg;
    vos::OGuard aGuard( Application::GetSolarMutex() );
    switch (_eCode)
    {
        case ERROR_GENERAL:                 aMsg = SVX_RES(RID_STR_SVT_SQL_SYNTAX_ERROR); break;
        case ERROR_VALUE_NO_LIKE:           aMsg = SVX_RES(RID_STR_SVT_SQL_SYNTAX_VALUE_NO_LIKE); break;
        case ERROR_FIELD_NO_LIKE:           aMsg = SVX_RES(RID_STR_SVT_SQL_SYNTAX_FIELD_NO_LIKE); break;
        case ERROR_INVALID_COMPARE:         aMsg = SVX_RES(RID_STR_SVT_SQL_SYNTAX_CRIT_NO_COMPARE); break;
        case ERROR_INVALID_INT_COMPARE:     aMsg = SVX_RES(RID_STR_SVT_SQL_SYNTAX_INT_NO_VALID); break;
        case ERROR_INVALID_DATE_COMPARE:    aMsg = SVX_RES(RID_STR_SVT_SQL_SYNTAX_ACCESS_DAT_NO_VALID); break;
        case ERROR_INVALID_REAL_COMPARE:    aMsg = SVX_RES(RID_STR_SVT_SQL_SYNTAX_REAL_NO_VALID); break;
        case ERROR_INVALID_TABLE:           aMsg = SVX_RES(RID_STR_SVT_SQL_SYNTAX_TABLE); break;
        case ERROR_INVALID_TABLE_OR_QUERY:  aMsg = SVX_RES(RID_STR_SVT_SQL_SYNTAX_TABLE_OR_QUERY); break;
        case ERROR_INVALID_COLUMN:          aMsg = SVX_RES(RID_STR_SVT_SQL_SYNTAX_COLUMN); break;
        case ERROR_INVALID_TABLE_EXIST:     aMsg = SVX_RES(RID_STR_SVT_SQL_SYNTAX_TABLE_EXISTS); break;
        case ERROR_INVALID_QUERY_EXIST:     aMsg = SVX_RES(RID_STR_SVT_SQL_SYNTAX_QUERY_EXISTS); break;
        case ERROR_CYCLIC_SUB_QUERIES:      aMsg = SVX_RES(RID_STR_SVT_SQL_CYCLIC_SUB_QUERIES); break;
        case ERROR_NONE: break;
    }
    return aMsg;
}

//-----------------------------------------------------------------------------
::rtl::OString OSystemParseContext::getIntlKeywordAscii(InternationalKeyCode _eKey) const
{
    ByteString aKeyword;
    switch (_eKey)
    {
        case KEY_LIKE:      aKeyword = m_aSQLInternationals.GetToken(0); break;
        case KEY_NOT:       aKeyword = m_aSQLInternationals.GetToken(1); break;
        case KEY_NULL:      aKeyword = m_aSQLInternationals.GetToken(2); break;
        case KEY_TRUE:      aKeyword = m_aSQLInternationals.GetToken(3); break;
        case KEY_FALSE:     aKeyword = m_aSQLInternationals.GetToken(4); break;
        case KEY_IS:        aKeyword = m_aSQLInternationals.GetToken(5); break;
        case KEY_BETWEEN:   aKeyword = m_aSQLInternationals.GetToken(6); break;
        case KEY_OR:        aKeyword = m_aSQLInternationals.GetToken(7); break;
        case KEY_AND:       aKeyword = m_aSQLInternationals.GetToken(8); break;
        case KEY_AVG:       aKeyword = m_aSQLInternationals.GetToken(9); break;
        case KEY_COUNT:     aKeyword = m_aSQLInternationals.GetToken(10); break;
        case KEY_MAX:       aKeyword = m_aSQLInternationals.GetToken(11); break;
        case KEY_MIN:       aKeyword = m_aSQLInternationals.GetToken(12); break;
        case KEY_SUM:       aKeyword = m_aSQLInternationals.GetToken(13); break;
        case KEY_NONE:
            DBG_ERROR( "OSystemParseContext::getIntlKeywordAscii: illegal argument!" );
            break;
    }
    return aKeyword;
}

//-----------------------------------------------------------------------------
static sal_Unicode lcl_getSeparatorChar( const String& _rSeparator, sal_Unicode _nFallback )
{
    DBG_ASSERT( 0 < _rSeparator.Len(), "::lcl_getSeparatorChar: invalid decimal separator!" );

    sal_Unicode nReturn( _nFallback );
    if ( _rSeparator.Len() )
        nReturn = static_cast< sal_Char >( _rSeparator.GetBuffer( )[0] );
    return nReturn;
}

//-----------------------------------------------------------------------------
sal_Unicode OSystemParseContext::getNumDecimalSep( ) const
{
    return lcl_getSeparatorChar( SvtSysLocale().GetLocaleData().getNumDecimalSep(), '.' );
}

//-----------------------------------------------------------------------------
sal_Unicode OSystemParseContext::getNumThousandSep( ) const
{
    return lcl_getSeparatorChar( SvtSysLocale().GetLocaleData().getNumThousandSep(), ',' );
}
// -----------------------------------------------------------------------------
IParseContext::InternationalKeyCode OSystemParseContext::getIntlKeyCode(const ::rtl::OString& rToken) const
{
    static IParseContext::InternationalKeyCode Intl_TokenID[] =
    {
        KEY_LIKE, KEY_NOT, KEY_NULL, KEY_TRUE,
        KEY_FALSE, KEY_IS, KEY_BETWEEN, KEY_OR,
        KEY_AND, KEY_AVG, KEY_COUNT, KEY_MAX,
        KEY_MIN, KEY_SUM
    };

    sal_uInt32 nCount = sizeof Intl_TokenID / sizeof Intl_TokenID[0];
    for (sal_uInt32 i = 0; i < nCount; i++)
    {
        ::rtl::OString aKey = getIntlKeywordAscii(Intl_TokenID[i]);
        if (rToken.equalsIgnoreAsciiCase(aKey))
            return Intl_TokenID[i];
    }

    return KEY_NONE;
}

// =============================================================================
// =============================================================================
namespace
{
    // -----------------------------------------------------------------------------
    ::osl::Mutex& getSafteyMutex()
    {
        static ::osl::Mutex s_aSafety;
        return s_aSafety;
    }
    // -----------------------------------------------------------------------------
    oslInterlockedCount& getCounter()
    {
        static oslInterlockedCount s_nCounter;
        return s_nCounter;
    }
    // -----------------------------------------------------------------------------
    OSystemParseContext* getSharedContext(OSystemParseContext* _pContext = NULL,sal_Bool _bSet = sal_False)
    {
        static OSystemParseContext* s_pSharedContext = NULL;
        if ( _pContext && !s_pSharedContext || _bSet )
            s_pSharedContext = _pContext;
        return s_pSharedContext;
    }
    // -----------------------------------------------------------------------------
}
// -----------------------------------------------------------------------------
OParseContextClient::OParseContextClient()
{
    ::osl::MutexGuard aGuard( getSafteyMutex() );
    if ( 1 == osl_incrementInterlockedCount( &getCounter() ) )
    {   // first instance
        getSharedContext( new OSystemParseContext );
    }
}

// -----------------------------------------------------------------------------
OParseContextClient::~OParseContextClient()
{
    {
        ::osl::MutexGuard aGuard( getSafteyMutex() );
        if ( 0 == osl_decrementInterlockedCount( &getCounter() ) )
            delete getSharedContext(NULL,sal_True);
    }
}
// -----------------------------------------------------------------------------
const OSystemParseContext* OParseContextClient::getParseContext() const
{
    return getSharedContext();
}
// -----------------------------------------------------------------------------

<commit_msg>INTEGRATION: CWS pchfix02 (1.6.74); FILE MERGED 2006/09/01 17:46:47 kaib 1.6.74.1: #i68856# Added header markers and pch files<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: ParseContext.cxx,v $
 *
 *  $Revision: 1.8 $
 *
 *  last change: $Author: obo $ $Date: 2006-09-17 05:02:42 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library 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
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_svx.hxx"
#ifndef SVX_QUERYDESIGNCONTEXT_HXX
#include "ParseContext.hxx"
#endif
#ifndef _TOOLS_DEBUG_HXX
#include <tools/debug.hxx>
#endif
#ifndef INCLUDED_SVTOOLS_SYSLOCALE_HXX
#include <svtools/syslocale.hxx>
#endif
#ifndef _SVX_FMRESIDS_HRC
#include "fmresids.hrc"
#endif
#include "dialmgr.hxx"
#ifndef _SV_SVAPP_HXX
#include <vcl/svapp.hxx>
#endif
#ifndef _VOS_MUTEX_HXX_
#include <vos/mutex.hxx>
#endif

using namespace svxform;
using namespace ::connectivity;
//==========================================================================
//= OSystemParseContext
//==========================================================================
DBG_NAME(OSystemParseContext);
//-----------------------------------------------------------------------------
OSystemParseContext::OSystemParseContext() : IParseContext()
{
    DBG_CTOR(OSystemParseContext,NULL);
    vos::OGuard aGuard( Application::GetSolarMutex() );
    m_aSQLInternationals = ByteString(SVX_RES(RID_STR_SVT_SQL_INTERNATIONAL),RTL_TEXTENCODING_UTF8);
}

//-----------------------------------------------------------------------------
OSystemParseContext::~OSystemParseContext()
{
    DBG_DTOR(OSystemParseContext,NULL);
}

//-----------------------------------------------------------------------------
::com::sun::star::lang::Locale OSystemParseContext::getPreferredLocale( ) const
{
    return SvtSysLocale().GetLocaleData().getLocale();
}

//-----------------------------------------------------------------------------
::rtl::OUString OSystemParseContext::getErrorMessage(ErrorCode _eCode) const
{
    String aMsg;
    vos::OGuard aGuard( Application::GetSolarMutex() );
    switch (_eCode)
    {
        case ERROR_GENERAL:                 aMsg = SVX_RES(RID_STR_SVT_SQL_SYNTAX_ERROR); break;
        case ERROR_VALUE_NO_LIKE:           aMsg = SVX_RES(RID_STR_SVT_SQL_SYNTAX_VALUE_NO_LIKE); break;
        case ERROR_FIELD_NO_LIKE:           aMsg = SVX_RES(RID_STR_SVT_SQL_SYNTAX_FIELD_NO_LIKE); break;
        case ERROR_INVALID_COMPARE:         aMsg = SVX_RES(RID_STR_SVT_SQL_SYNTAX_CRIT_NO_COMPARE); break;
        case ERROR_INVALID_INT_COMPARE:     aMsg = SVX_RES(RID_STR_SVT_SQL_SYNTAX_INT_NO_VALID); break;
        case ERROR_INVALID_DATE_COMPARE:    aMsg = SVX_RES(RID_STR_SVT_SQL_SYNTAX_ACCESS_DAT_NO_VALID); break;
        case ERROR_INVALID_REAL_COMPARE:    aMsg = SVX_RES(RID_STR_SVT_SQL_SYNTAX_REAL_NO_VALID); break;
        case ERROR_INVALID_TABLE:           aMsg = SVX_RES(RID_STR_SVT_SQL_SYNTAX_TABLE); break;
        case ERROR_INVALID_TABLE_OR_QUERY:  aMsg = SVX_RES(RID_STR_SVT_SQL_SYNTAX_TABLE_OR_QUERY); break;
        case ERROR_INVALID_COLUMN:          aMsg = SVX_RES(RID_STR_SVT_SQL_SYNTAX_COLUMN); break;
        case ERROR_INVALID_TABLE_EXIST:     aMsg = SVX_RES(RID_STR_SVT_SQL_SYNTAX_TABLE_EXISTS); break;
        case ERROR_INVALID_QUERY_EXIST:     aMsg = SVX_RES(RID_STR_SVT_SQL_SYNTAX_QUERY_EXISTS); break;
        case ERROR_CYCLIC_SUB_QUERIES:      aMsg = SVX_RES(RID_STR_SVT_SQL_CYCLIC_SUB_QUERIES); break;
        case ERROR_NONE: break;
    }
    return aMsg;
}

//-----------------------------------------------------------------------------
::rtl::OString OSystemParseContext::getIntlKeywordAscii(InternationalKeyCode _eKey) const
{
    ByteString aKeyword;
    switch (_eKey)
    {
        case KEY_LIKE:      aKeyword = m_aSQLInternationals.GetToken(0); break;
        case KEY_NOT:       aKeyword = m_aSQLInternationals.GetToken(1); break;
        case KEY_NULL:      aKeyword = m_aSQLInternationals.GetToken(2); break;
        case KEY_TRUE:      aKeyword = m_aSQLInternationals.GetToken(3); break;
        case KEY_FALSE:     aKeyword = m_aSQLInternationals.GetToken(4); break;
        case KEY_IS:        aKeyword = m_aSQLInternationals.GetToken(5); break;
        case KEY_BETWEEN:   aKeyword = m_aSQLInternationals.GetToken(6); break;
        case KEY_OR:        aKeyword = m_aSQLInternationals.GetToken(7); break;
        case KEY_AND:       aKeyword = m_aSQLInternationals.GetToken(8); break;
        case KEY_AVG:       aKeyword = m_aSQLInternationals.GetToken(9); break;
        case KEY_COUNT:     aKeyword = m_aSQLInternationals.GetToken(10); break;
        case KEY_MAX:       aKeyword = m_aSQLInternationals.GetToken(11); break;
        case KEY_MIN:       aKeyword = m_aSQLInternationals.GetToken(12); break;
        case KEY_SUM:       aKeyword = m_aSQLInternationals.GetToken(13); break;
        case KEY_NONE:
            DBG_ERROR( "OSystemParseContext::getIntlKeywordAscii: illegal argument!" );
            break;
    }
    return aKeyword;
}

//-----------------------------------------------------------------------------
static sal_Unicode lcl_getSeparatorChar( const String& _rSeparator, sal_Unicode _nFallback )
{
    DBG_ASSERT( 0 < _rSeparator.Len(), "::lcl_getSeparatorChar: invalid decimal separator!" );

    sal_Unicode nReturn( _nFallback );
    if ( _rSeparator.Len() )
        nReturn = static_cast< sal_Char >( _rSeparator.GetBuffer( )[0] );
    return nReturn;
}

//-----------------------------------------------------------------------------
sal_Unicode OSystemParseContext::getNumDecimalSep( ) const
{
    return lcl_getSeparatorChar( SvtSysLocale().GetLocaleData().getNumDecimalSep(), '.' );
}

//-----------------------------------------------------------------------------
sal_Unicode OSystemParseContext::getNumThousandSep( ) const
{
    return lcl_getSeparatorChar( SvtSysLocale().GetLocaleData().getNumThousandSep(), ',' );
}
// -----------------------------------------------------------------------------
IParseContext::InternationalKeyCode OSystemParseContext::getIntlKeyCode(const ::rtl::OString& rToken) const
{
    static IParseContext::InternationalKeyCode Intl_TokenID[] =
    {
        KEY_LIKE, KEY_NOT, KEY_NULL, KEY_TRUE,
        KEY_FALSE, KEY_IS, KEY_BETWEEN, KEY_OR,
        KEY_AND, KEY_AVG, KEY_COUNT, KEY_MAX,
        KEY_MIN, KEY_SUM
    };

    sal_uInt32 nCount = sizeof Intl_TokenID / sizeof Intl_TokenID[0];
    for (sal_uInt32 i = 0; i < nCount; i++)
    {
        ::rtl::OString aKey = getIntlKeywordAscii(Intl_TokenID[i]);
        if (rToken.equalsIgnoreAsciiCase(aKey))
            return Intl_TokenID[i];
    }

    return KEY_NONE;
}

// =============================================================================
// =============================================================================
namespace
{
    // -----------------------------------------------------------------------------
    ::osl::Mutex& getSafteyMutex()
    {
        static ::osl::Mutex s_aSafety;
        return s_aSafety;
    }
    // -----------------------------------------------------------------------------
    oslInterlockedCount& getCounter()
    {
        static oslInterlockedCount s_nCounter;
        return s_nCounter;
    }
    // -----------------------------------------------------------------------------
    OSystemParseContext* getSharedContext(OSystemParseContext* _pContext = NULL,sal_Bool _bSet = sal_False)
    {
        static OSystemParseContext* s_pSharedContext = NULL;
        if ( _pContext && !s_pSharedContext || _bSet )
            s_pSharedContext = _pContext;
        return s_pSharedContext;
    }
    // -----------------------------------------------------------------------------
}
// -----------------------------------------------------------------------------
OParseContextClient::OParseContextClient()
{
    ::osl::MutexGuard aGuard( getSafteyMutex() );
    if ( 1 == osl_incrementInterlockedCount( &getCounter() ) )
    {   // first instance
        getSharedContext( new OSystemParseContext );
    }
}

// -----------------------------------------------------------------------------
OParseContextClient::~OParseContextClient()
{
    {
        ::osl::MutexGuard aGuard( getSafteyMutex() );
        if ( 0 == osl_decrementInterlockedCount( &getCounter() ) )
            delete getSharedContext(NULL,sal_True);
    }
}
// -----------------------------------------------------------------------------
const OSystemParseContext* OParseContextClient::getParseContext() const
{
    return getSharedContext();
}
// -----------------------------------------------------------------------------

<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  $RCSfile: lboxctrl.cxx,v $
 *
 *  $Revision: 1.15 $
 *
 *  last change: $Author: mt $ $Date: 2001-10-29 14:47:03 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 by Sun Microsystems, Inc.
 *  901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License version 2.1, as published by the Free Software Foundation.
 *
 *  This library 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
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *  MA  02111-1307  USA
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (the "License"); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://www.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/

#ifdef   _TOOLS_DEBUG_HXX
#include <tools/debug.hxx>
#endif
#ifndef _SV_LSTBOX_HXX
#include <vcl/lstbox.hxx>
#endif
#ifndef _SV_TOOLBOX_HXX
#include <vcl/toolbox.hxx>
#endif
#ifndef _SV_EVENT_HXX
#include <vcl/event.hxx>
#endif
#ifndef _SFXAPP_HXX
#include <sfx2/app.hxx>
#endif
#ifndef _SFXTBXCTRL_HXX
#include <sfx2/tbxctrl.hxx>
#endif
#ifndef _SFX_BINDINGS_HXX
#include <sfx2/bindings.hxx>
#endif
#ifndef _SFXDISPATCH_HXX
#include <sfx2/dispatch.hxx>
#endif
#ifndef _SFXVIEWSH_HXX
#include <sfx2/viewsh.hxx>
#endif
#ifndef _SV_GEN_HXX
#include <tools/gen.hxx>
#endif
#ifndef _SFXINTITEM_HXX
#include <svtools/intitem.hxx>
#endif
#ifndef _SFXENUMITEM_HXX
#include <svtools/eitem.hxx>
#endif
#ifndef _STDCTRL_HXX
#include <svtools/stdctrl.hxx>
#endif
#ifndef _SFXSLSTITM_HXX
#include <svtools/slstitm.hxx>
#endif
#ifndef _SFXSTRITEM_HXX
#include <svtools/stritem.hxx>
#endif

#ifndef _SVX_DIALMGR_HXX
#include <dialmgr.hxx>
#endif
#ifndef _SVX_LBOXCTRL_HXX_
#include <lboxctrl.hxx>
#endif

#include <svxids.hrc>
#include <dialogs.hrc>

#include "lboxctrl.hrc"

class SvxPopupWindowListBox;

/////////////////////////////////////////////////////////////////

class SvxPopupWindowListBox : public SfxPopupWindow
{
    FixedInfo       aInfo;
    ListBox *       pListBox;
    ToolBox &       rToolBox;
    BOOL            bUserSel;

    // disallow copy-constructor and assignment-operator

    SvxPopupWindowListBox(const& );
    SvxPopupWindowListBox & operator = (const& );

    SvxPopupWindowListBox( USHORT nSlotId,
                           ToolBox& rTbx, USHORT nTbxItemId );

public:
    SvxPopupWindowListBox( USHORT nSlotId,
                           ToolBox& rTbx,
                           SfxBindings &rBindings );
    virtual ~SvxPopupWindowListBox();

    // SfxPopupWindow
    virtual SfxPopupWindow *    Clone() const;
    virtual void                PopupModeEnd();
    virtual void                StateChanged( USHORT nSID, SfxItemState eState,
                                              const SfxPoolItem* pState );

    void                        StartSelection();
    inline ListBox &            GetListBox()    { return *pListBox; }
    inline FixedInfo &          GetInfo()       { return aInfo; }

    BOOL                        IsUserSelected() const          { return bUserSel; }
    void                        SetUserSelected( BOOL bVal )    { bUserSel = bVal; }
};

/////////////////////////////////////////////////////////////////

SvxPopupWindowListBox::SvxPopupWindowListBox(
            USHORT nSlotId,
            ToolBox& rTbx,
            SfxBindings &rBindings ) :

    SfxPopupWindow( nSlotId, SVX_RES( RID_SVXTBX_UNDO_REDO_CTRL ), rBindings ),
    aInfo       ( this, ResId( FT_NUM_OPERATIONS ) ),
    rToolBox    ( rTbx ),
    bUserSel    ( FALSE )
{
    DBG_ASSERT( nSlotId == GetId(), "id mismatch" );
    pListBox = new ListBox( this, SVX_RES( LB_SVXTBX_UNDO_REDO_CTRL ) );
    FreeResource();
    pListBox->EnableMultiSelection( TRUE, TRUE );
    SetBackground( GetSettings().GetStyleSettings().GetDialogColor() );
    pListBox->GrabFocus();
}

SvxPopupWindowListBox::~SvxPopupWindowListBox()
{
    delete pListBox;
}

SfxPopupWindow* SvxPopupWindowListBox::Clone() const
{
    return new SvxPopupWindowListBox( GetId(), rToolBox,
                                      (SfxBindings &) GetBindings() );
}

void SvxPopupWindowListBox::PopupModeEnd()
{
    rToolBox.EndSelection();
    SfxPopupWindow::PopupModeEnd();
    //FloatingWindow::PopupModeEnd();

    Window* pShellWnd = SfxViewShell::Current()->GetWindow();
    if (pShellWnd)
        pShellWnd->GrabFocus();
}

void SvxPopupWindowListBox::StateChanged(
        USHORT nSID, SfxItemState eState, const SfxPoolItem* pState )
{
    rToolBox.EnableItem( GetId(), (GetItemState(pState) != SFX_ITEM_DISABLED) );
    SfxPopupWindow::StateChanged( nSID, eState, pState );
}

void SvxPopupWindowListBox::StartSelection()
{
    rToolBox.StartSelection();
}

/////////////////////////////////////////////////////////////////

SFX_IMPL_TOOLBOX_CONTROL( SvxListBoxControl, SfxStringItem );

SvxListBoxControl::SvxListBoxControl(
                            USHORT nId, ToolBox& rTbx, SfxBindings& rBind )
    :SfxToolBoxControl( nId, rTbx, rBind ),
    pPopupWin   ( 0 )
{
    rTbx.SetItemBits( nId, TIB_DROPDOWN | rTbx.GetItemBits( nId ) );
    rTbx.Invalidate();
}

SvxListBoxControl::~SvxListBoxControl()
{
}

SfxPopupWindow* SvxListBoxControl::CreatePopupWindow()
{
    DBG_ERROR( "not implemented" );
    return 0;
}

SfxPopupWindowType SvxListBoxControl::GetPopupWindowType() const
{
    return SFX_POPUPWINDOW_ONTIMEOUT;
}

void SvxListBoxControl::StateChanged(
        USHORT nSID, SfxItemState eState, const SfxPoolItem* pState )
{
    GetToolBox().EnableItem( GetId(),
                            SFX_ITEM_DISABLED != GetItemState(pState) );
}

IMPL_LINK( SvxListBoxControl, PopupModeEndHdl, void *, EMPTYARG )
{
    if( pPopupWin && 0 == pPopupWin->GetPopupModeFlags()  &&
        pPopupWin->IsUserSelected() )
    {
        USHORT nCount = pPopupWin->GetListBox().GetSelectEntryCount();
        SfxUInt16Item aItem( GetId(), nCount );
        GetBindings().GetDispatcher()->Execute( GetId(),
                                        SFX_CALLMODE_SYNCHRON, &aItem, 0L );
    }
    return 0;
}

void SvxListBoxControl::Impl_SetInfo( USHORT nCount )
{
    DBG_ASSERT( pPopupWin, "NULL pointer, PopupWindow missing" );
    String aText( aActionStr );
    aText.SearchAndReplaceAllAscii( "$(ARG1)", String::CreateFromInt32( nCount ) );
    pPopupWin->GetInfo().SetText( aText );
}

IMPL_LINK( SvxListBoxControl, SelectHdl, void *, EMPTYARG )
{
    if (pPopupWin)
    {
        //pPopupWin->SetUserSelected( FALSE );

        ListBox &rListBox = pPopupWin->GetListBox();
        if (rListBox.IsTravelSelect())
            Impl_SetInfo( rListBox.GetSelectEntryCount() );
        else
        {
            pPopupWin->SetUserSelected( TRUE );
            pPopupWin->EndPopupMode( 0 );
        }
    }
    return 0;
}

/////////////////////////////////////////////////////////////////

SFX_IMPL_TOOLBOX_CONTROL( SvxUndoRedoControl, SfxStringItem );

SvxUndoRedoControl::~SvxUndoRedoControl()
{
}

SfxPopupWindow* SvxUndoRedoControl::CreatePopupWindow()
{
    const USHORT nId = GetId();
    DBG_ASSERT( SID_UNDO == nId || SID_REDO == nId, "mismatching ids" );

    const SfxPoolItem* pState = 0;
    SfxBindings &rBindings = GetBindings();
    SfxDispatcher &rDispatch = *rBindings.GetDispatcher();
    SfxItemState eState = rDispatch.QueryState( SID_UNDO == nId
                                                ? SID_GETUNDOSTRINGS
                                                : SID_GETREDOSTRINGS, pState );

    if( eState >= SFX_ITEM_AVAILABLE  &&  pState)
    {
        ToolBox& rBox = GetToolBox();

        pPopupWin = new SvxPopupWindowListBox( nId, rBox, rBindings );
        pPopupWin->SetPopupModeEndHdl( LINK( this, SvxUndoRedoControl,
                                                PopupModeEndHdl ) );
        ListBox &rListBox = pPopupWin->GetListBox();
        rListBox.SetSelectHdl( LINK( this, SvxUndoRedoControl, SelectHdl ) );

        SfxStringListItem &rItem = *(SfxStringListItem *) pState;
        const List* pLst = rItem.GetList();
        DBG_ASSERT( pLst, "no undo actions available" );
        if( pLst )
            for( long nI = 0, nEnd = pLst->Count(); nI < nEnd; ++nI )
                rListBox.InsertEntry( *((String*)pLst->GetObject( nI )) );
        rListBox.SelectEntryPos( 0 );

        aActionStr = String( SVX_RES( SID_UNDO == nId
                                        ? RID_SVXSTR_NUM_UNDO_ACTIONS
                                           : RID_SVXSTR_NUM_REDO_ACTIONS ) );
        Impl_SetInfo( rListBox.GetSelectEntryCount() );

        // #92220# MT: use special StartPopupMode instead...
/*
        // position window at the bottom-left of the toolbox icon.
        // The -2 offset takes the distance from the item-rect to
        // the toolbox border into account (can't be obtained from
        // the toolbox).
        Rectangle aItemRect( rBox.GetItemRect( nId ) );
        aItemRect.Bottom() += aItemRect.GetHeight() - 2;
        {
            MouseEvent aMEvt( aItemRect.TopLeft(), 1, 0, 0, 0 );
            Link aSave( rBox.GetSelectHdl() );
            rBox.SetSelectHdl( Link() );
            rBox.Tracking( TrackingEvent( aMEvt, ENDTRACK_END ) );
            rBox.SetSelectHdl( aSave );
        }

        pPopupWin->StartPopupMode( aItemRect );
*/

        pPopupWin->StartPopupMode( &rBox );
//      pPopupWin->StartSelection();
    }
    return pPopupWin;
}

<commit_msg>#98452# Focus has to switched after StartPopupMode now.<commit_after>/*************************************************************************
 *
 *  $RCSfile: lboxctrl.cxx,v $
 *
 *  $Revision: 1.16 $
 *
 *  last change: $Author: tl $ $Date: 2002-04-09 08:47:42 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 by Sun Microsystems, Inc.
 *  901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License version 2.1, as published by the Free Software Foundation.
 *
 *  This library 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
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *  MA  02111-1307  USA
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (the "License"); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://www.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/

#ifdef   _TOOLS_DEBUG_HXX
#include <tools/debug.hxx>
#endif
#ifndef _SV_LSTBOX_HXX
#include <vcl/lstbox.hxx>
#endif
#ifndef _SV_TOOLBOX_HXX
#include <vcl/toolbox.hxx>
#endif
#ifndef _SV_EVENT_HXX
#include <vcl/event.hxx>
#endif
#ifndef _SFXAPP_HXX
#include <sfx2/app.hxx>
#endif
#ifndef _SFXTBXCTRL_HXX
#include <sfx2/tbxctrl.hxx>
#endif
#ifndef _SFX_BINDINGS_HXX
#include <sfx2/bindings.hxx>
#endif
#ifndef _SFXDISPATCH_HXX
#include <sfx2/dispatch.hxx>
#endif
#ifndef _SFXVIEWSH_HXX
#include <sfx2/viewsh.hxx>
#endif
#ifndef _SV_GEN_HXX
#include <tools/gen.hxx>
#endif
#ifndef _SFXINTITEM_HXX
#include <svtools/intitem.hxx>
#endif
#ifndef _SFXENUMITEM_HXX
#include <svtools/eitem.hxx>
#endif
#ifndef _STDCTRL_HXX
#include <svtools/stdctrl.hxx>
#endif
#ifndef _SFXSLSTITM_HXX
#include <svtools/slstitm.hxx>
#endif
#ifndef _SFXSTRITEM_HXX
#include <svtools/stritem.hxx>
#endif

#ifndef _SVX_DIALMGR_HXX
#include <dialmgr.hxx>
#endif
#ifndef _SVX_LBOXCTRL_HXX_
#include <lboxctrl.hxx>
#endif

#include <svxids.hrc>
#include <dialogs.hrc>

#include "lboxctrl.hrc"

class SvxPopupWindowListBox;

/////////////////////////////////////////////////////////////////

class SvxPopupWindowListBox : public SfxPopupWindow
{
    FixedInfo       aInfo;
    ListBox *       pListBox;
    ToolBox &       rToolBox;
    BOOL            bUserSel;

    // disallow copy-constructor and assignment-operator

    SvxPopupWindowListBox(const& );
    SvxPopupWindowListBox & operator = (const& );

    SvxPopupWindowListBox( USHORT nSlotId,
                           ToolBox& rTbx, USHORT nTbxItemId );

public:
    SvxPopupWindowListBox( USHORT nSlotId,
                           ToolBox& rTbx,
                           SfxBindings &rBindings );
    virtual ~SvxPopupWindowListBox();

    // SfxPopupWindow
    virtual SfxPopupWindow *    Clone() const;
    virtual void                PopupModeEnd();
    virtual void                StateChanged( USHORT nSID, SfxItemState eState,
                                              const SfxPoolItem* pState );

    void                        StartSelection();
    inline ListBox &            GetListBox()    { return *pListBox; }
    inline FixedInfo &          GetInfo()       { return aInfo; }

    BOOL                        IsUserSelected() const          { return bUserSel; }
    void                        SetUserSelected( BOOL bVal )    { bUserSel = bVal; }
};

/////////////////////////////////////////////////////////////////

SvxPopupWindowListBox::SvxPopupWindowListBox(
            USHORT nSlotId,
            ToolBox& rTbx,
            SfxBindings &rBindings ) :

    SfxPopupWindow( nSlotId, SVX_RES( RID_SVXTBX_UNDO_REDO_CTRL ), rBindings ),
    aInfo       ( this, ResId( FT_NUM_OPERATIONS ) ),
    rToolBox    ( rTbx ),
    bUserSel    ( FALSE )
{
    DBG_ASSERT( nSlotId == GetId(), "id mismatch" );
    pListBox = new ListBox( this, SVX_RES( LB_SVXTBX_UNDO_REDO_CTRL ) );
    FreeResource();
    pListBox->EnableMultiSelection( TRUE, TRUE );
    SetBackground( GetSettings().GetStyleSettings().GetDialogColor() );
}

SvxPopupWindowListBox::~SvxPopupWindowListBox()
{
    delete pListBox;
}

SfxPopupWindow* SvxPopupWindowListBox::Clone() const
{
    return new SvxPopupWindowListBox( GetId(), rToolBox,
                                      (SfxBindings &) GetBindings() );
}

void SvxPopupWindowListBox::PopupModeEnd()
{
    rToolBox.EndSelection();
    SfxPopupWindow::PopupModeEnd();
    //FloatingWindow::PopupModeEnd();

    Window* pShellWnd = SfxViewShell::Current()->GetWindow();
    if (pShellWnd)
        pShellWnd->GrabFocus();
}

void SvxPopupWindowListBox::StateChanged(
        USHORT nSID, SfxItemState eState, const SfxPoolItem* pState )
{
    rToolBox.EnableItem( GetId(), (GetItemState(pState) != SFX_ITEM_DISABLED) );
    SfxPopupWindow::StateChanged( nSID, eState, pState );
}

void SvxPopupWindowListBox::StartSelection()
{
    rToolBox.StartSelection();
}

/////////////////////////////////////////////////////////////////

SFX_IMPL_TOOLBOX_CONTROL( SvxListBoxControl, SfxStringItem );

SvxListBoxControl::SvxListBoxControl(
                            USHORT nId, ToolBox& rTbx, SfxBindings& rBind )
    :SfxToolBoxControl( nId, rTbx, rBind ),
    pPopupWin   ( 0 )
{
    rTbx.SetItemBits( nId, TIB_DROPDOWN | rTbx.GetItemBits( nId ) );
    rTbx.Invalidate();
}

SvxListBoxControl::~SvxListBoxControl()
{
}

SfxPopupWindow* SvxListBoxControl::CreatePopupWindow()
{
    DBG_ERROR( "not implemented" );
    return 0;
}

SfxPopupWindowType SvxListBoxControl::GetPopupWindowType() const
{
    return SFX_POPUPWINDOW_ONTIMEOUT;
}

void SvxListBoxControl::StateChanged(
        USHORT nSID, SfxItemState eState, const SfxPoolItem* pState )
{
    GetToolBox().EnableItem( GetId(),
                            SFX_ITEM_DISABLED != GetItemState(pState) );
}

IMPL_LINK( SvxListBoxControl, PopupModeEndHdl, void *, EMPTYARG )
{
    if( pPopupWin && 0 == pPopupWin->GetPopupModeFlags()  &&
        pPopupWin->IsUserSelected() )
    {
        USHORT nCount = pPopupWin->GetListBox().GetSelectEntryCount();
        SfxUInt16Item aItem( GetId(), nCount );
        GetBindings().GetDispatcher()->Execute( GetId(),
                                        SFX_CALLMODE_SYNCHRON, &aItem, 0L );
    }
    return 0;
}

void SvxListBoxControl::Impl_SetInfo( USHORT nCount )
{
    DBG_ASSERT( pPopupWin, "NULL pointer, PopupWindow missing" );
    String aText( aActionStr );
    aText.SearchAndReplaceAllAscii( "$(ARG1)", String::CreateFromInt32( nCount ) );
    pPopupWin->GetInfo().SetText( aText );
}

IMPL_LINK( SvxListBoxControl, SelectHdl, void *, EMPTYARG )
{
    if (pPopupWin)
    {
        //pPopupWin->SetUserSelected( FALSE );

        ListBox &rListBox = pPopupWin->GetListBox();
        if (rListBox.IsTravelSelect())
            Impl_SetInfo( rListBox.GetSelectEntryCount() );
        else
        {
            pPopupWin->SetUserSelected( TRUE );
            pPopupWin->EndPopupMode( 0 );
        }
    }
    return 0;
}

/////////////////////////////////////////////////////////////////

SFX_IMPL_TOOLBOX_CONTROL( SvxUndoRedoControl, SfxStringItem );

SvxUndoRedoControl::~SvxUndoRedoControl()
{
}

SfxPopupWindow* SvxUndoRedoControl::CreatePopupWindow()
{
    const USHORT nId = GetId();
    DBG_ASSERT( SID_UNDO == nId || SID_REDO == nId, "mismatching ids" );

    const SfxPoolItem* pState = 0;
    SfxBindings &rBindings = GetBindings();
    SfxDispatcher &rDispatch = *rBindings.GetDispatcher();
    SfxItemState eState = rDispatch.QueryState( SID_UNDO == nId
                                                ? SID_GETUNDOSTRINGS
                                                : SID_GETREDOSTRINGS, pState );

    if( eState >= SFX_ITEM_AVAILABLE  &&  pState)
    {
        ToolBox& rBox = GetToolBox();

        pPopupWin = new SvxPopupWindowListBox( nId, rBox, rBindings );
        pPopupWin->SetPopupModeEndHdl( LINK( this, SvxUndoRedoControl,
                                                PopupModeEndHdl ) );
        ListBox &rListBox = pPopupWin->GetListBox();
        rListBox.SetSelectHdl( LINK( this, SvxUndoRedoControl, SelectHdl ) );

        SfxStringListItem &rItem = *(SfxStringListItem *) pState;
        const List* pLst = rItem.GetList();
        DBG_ASSERT( pLst, "no undo actions available" );
        if( pLst )
            for( long nI = 0, nEnd = pLst->Count(); nI < nEnd; ++nI )
                rListBox.InsertEntry( *((String*)pLst->GetObject( nI )) );
        rListBox.SelectEntryPos( 0 );

        aActionStr = String( SVX_RES( SID_UNDO == nId
                                        ? RID_SVXSTR_NUM_UNDO_ACTIONS
                                           : RID_SVXSTR_NUM_REDO_ACTIONS ) );
        Impl_SetInfo( rListBox.GetSelectEntryCount() );

        // #92220# MT: use special StartPopupMode instead...
/*
        // position window at the bottom-left of the toolbox icon.
        // The -2 offset takes the distance from the item-rect to
        // the toolbox border into account (can't be obtained from
        // the toolbox).
        Rectangle aItemRect( rBox.GetItemRect( nId ) );
        aItemRect.Bottom() += aItemRect.GetHeight() - 2;
        {
            MouseEvent aMEvt( aItemRect.TopLeft(), 1, 0, 0, 0 );
            Link aSave( rBox.GetSelectHdl() );
            rBox.SetSelectHdl( Link() );
            rBox.Tracking( TrackingEvent( aMEvt, ENDTRACK_END ) );
            rBox.SetSelectHdl( aSave );
        }

        pPopupWin->StartPopupMode( aItemRect );
*/

        pPopupWin->StartPopupMode( &rBox );

        //! Focus has to be altered *after* StartPopupMode
        //  It's probably better to overload 'GetFocus' but this would
        //  be an incompatible fix right now.
        pPopupWin->GetListBox().GrabFocus();    // needed for cursor-traveling

//      pPopupWin->StartSelection();
    }
    return pPopupWin;
}

<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: tbxdrctl.cxx,v $
 *
 *  $Revision: 1.13 $
 *
 *  last change: $Author: hr $ $Date: 2006-06-19 16:51:59 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library 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
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

#include <string> // HACK: prevent conflict between STLPORT and Workshop headers

#include <tools/ref.hxx>
#ifndef _SHL_HXX
#include <tools/shl.hxx>
#endif
#ifndef _AEITEM_HXX
#include <svtools/aeitem.hxx>
#endif
#ifndef _SFXDISPATCH_HXX //autogen
#include <sfx2/dispatch.hxx>
#endif
#ifndef _SFXVIEWSH_HXX
#include <sfx2/viewsh.hxx>
#endif
#include <sfx2/imagemgr.hxx>
#include <sfx2/viewfrm.hxx>
#include <vcl/toolbox.hxx>

#include "dialmgr.hxx"
#include "dialogs.hrc"

#include "tbxctl.hxx"
#include "tbxdraw.hxx"
#include "tbxcolor.hxx"
#include "tbxdraw.hrc"

#ifndef _COM_SUN_STAR_FRAME_XLAYOUTMANAGER_HPP_
#include <com/sun/star/frame/XLayoutManager.hpp>
#endif

SFX_IMPL_TOOLBOX_CONTROL(SvxTbxCtlDraw, SfxAllEnumItem);

using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::frame;

// -----------------------------------------------------------------------

SvxTbxCtlDraw::SvxTbxCtlDraw( USHORT nSlotId, USHORT nId, ToolBox& rTbx ) :

    SfxToolBoxControl( nSlotId, nId, rTbx ),

    m_sToolboxName( RTL_CONSTASCII_USTRINGPARAM( "private:resource/toolbar/drawbar" ) )

{
    rTbx.SetItemBits( nId, TIB_CHECKABLE | rTbx.GetItemBits( nId ) );
    rTbx.Invalidate();
}

// -----------------------------------------------------------------------

void SvxTbxCtlDraw::StateChanged( USHORT nSID, SfxItemState eState,
                                  const SfxPoolItem* pState )
{
    GetToolBox().EnableItem( GetId(), ( eState != SFX_ITEM_DISABLED ) );
    SfxToolBoxControl::StateChanged( nSID, eState, pState );

    Reference< XLayoutManager > xLayoutMgr = getLayoutManager();
    if ( xLayoutMgr.is() )
        GetToolBox().CheckItem(
            GetId(), xLayoutMgr->isElementVisible( m_sToolboxName ) != sal_False );
}

// -----------------------------------------------------------------------

SfxPopupWindowType SvxTbxCtlDraw::GetPopupWindowType() const
{
    return SFX_POPUPWINDOW_ONCLICK;
}

// -----------------------------------------------------------------------

void SvxTbxCtlDraw::toggleToolbox()
{
    Reference< XLayoutManager > xLayoutMgr = getLayoutManager();
    if ( xLayoutMgr.is() )
    {
        BOOL bCheck = FALSE;
        if ( xLayoutMgr->isElementVisible( m_sToolboxName ) )
        {
            xLayoutMgr->hideElement( m_sToolboxName );
            xLayoutMgr->destroyElement( m_sToolboxName );
        }
        else
        {
            bCheck = TRUE;
            xLayoutMgr->createElement( m_sToolboxName );
            xLayoutMgr->showElement( m_sToolboxName );
        }

        GetToolBox().CheckItem( GetId(), bCheck );
    }
}

// -----------------------------------------------------------------------

void SvxTbxCtlDraw::Select( BOOL bMod1 )
{
    toggleToolbox();
}

<commit_msg>INTEGRATION: CWS pchfix02 (1.13.116); FILE MERGED 2006/09/01 17:47:34 kaib 1.13.116.1: #i68856# Added header markers and pch files<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: tbxdrctl.cxx,v $
 *
 *  $Revision: 1.14 $
 *
 *  last change: $Author: obo $ $Date: 2006-09-17 06:07:32 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library 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
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_svx.hxx"

#include <string> // HACK: prevent conflict between STLPORT and Workshop headers

#include <tools/ref.hxx>
#ifndef _SHL_HXX
#include <tools/shl.hxx>
#endif
#ifndef _AEITEM_HXX
#include <svtools/aeitem.hxx>
#endif
#ifndef _SFXDISPATCH_HXX //autogen
#include <sfx2/dispatch.hxx>
#endif
#ifndef _SFXVIEWSH_HXX
#include <sfx2/viewsh.hxx>
#endif
#include <sfx2/imagemgr.hxx>
#include <sfx2/viewfrm.hxx>
#include <vcl/toolbox.hxx>

#include "dialmgr.hxx"
#include "dialogs.hrc"

#include "tbxctl.hxx"
#include "tbxdraw.hxx"
#include "tbxcolor.hxx"
#include "tbxdraw.hrc"

#ifndef _COM_SUN_STAR_FRAME_XLAYOUTMANAGER_HPP_
#include <com/sun/star/frame/XLayoutManager.hpp>
#endif

SFX_IMPL_TOOLBOX_CONTROL(SvxTbxCtlDraw, SfxAllEnumItem);

using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::frame;

// -----------------------------------------------------------------------

SvxTbxCtlDraw::SvxTbxCtlDraw( USHORT nSlotId, USHORT nId, ToolBox& rTbx ) :

    SfxToolBoxControl( nSlotId, nId, rTbx ),

    m_sToolboxName( RTL_CONSTASCII_USTRINGPARAM( "private:resource/toolbar/drawbar" ) )

{
    rTbx.SetItemBits( nId, TIB_CHECKABLE | rTbx.GetItemBits( nId ) );
    rTbx.Invalidate();
}

// -----------------------------------------------------------------------

void SvxTbxCtlDraw::StateChanged( USHORT nSID, SfxItemState eState,
                                  const SfxPoolItem* pState )
{
    GetToolBox().EnableItem( GetId(), ( eState != SFX_ITEM_DISABLED ) );
    SfxToolBoxControl::StateChanged( nSID, eState, pState );

    Reference< XLayoutManager > xLayoutMgr = getLayoutManager();
    if ( xLayoutMgr.is() )
        GetToolBox().CheckItem(
            GetId(), xLayoutMgr->isElementVisible( m_sToolboxName ) != sal_False );
}

// -----------------------------------------------------------------------

SfxPopupWindowType SvxTbxCtlDraw::GetPopupWindowType() const
{
    return SFX_POPUPWINDOW_ONCLICK;
}

// -----------------------------------------------------------------------

void SvxTbxCtlDraw::toggleToolbox()
{
    Reference< XLayoutManager > xLayoutMgr = getLayoutManager();
    if ( xLayoutMgr.is() )
    {
        BOOL bCheck = FALSE;
        if ( xLayoutMgr->isElementVisible( m_sToolboxName ) )
        {
            xLayoutMgr->hideElement( m_sToolboxName );
            xLayoutMgr->destroyElement( m_sToolboxName );
        }
        else
        {
            bCheck = TRUE;
            xLayoutMgr->createElement( m_sToolboxName );
            xLayoutMgr->showElement( m_sToolboxName );
        }

        GetToolBox().CheckItem( GetId(), bCheck );
    }
}

// -----------------------------------------------------------------------

void SvxTbxCtlDraw::Select( BOOL bMod1 )
{
    toggleToolbox();
}

<|endoftext|>


<commit_before><commit_msg>Mark as const<commit_after><|endoftext|>


<commit_before><commit_msg>coverity#705381 Mixing enum types<commit_after><|endoftext|>


<commit_before>void readDigits(int nev=-1,int evStart=0)
{

  gSystem->Load("libITSUpgradeBase");
  gSystem->Load("libITSUpgradeSim");
  gROOT->SetStyle("Plain");
  const Int_t kMaxROCycleAccept=126;
  gAlice=NULL;
  AliRunLoader* runLoader = AliRunLoader::Open("galice.root");
  runLoader->LoadgAlice();

  gAlice = runLoader->GetAliRun();

  runLoader->LoadHeader();
  runLoader->LoadKinematics();
  runLoader->LoadSDigits();
  runLoader->LoadDigits();

  AliGeomManager::LoadGeometry("geometry.root");
  AliITSUGeomTGeo* gm = new AliITSUGeomTGeo(kTRUE,kTRUE);
  //
  Int_t nLayers = gm->GetNLayers();
  Int_t nModules = gm->GetNModules();
  Int_t nbins=100;
  Int_t xmin=0;
  Int_t xmax=50000;//00*1e-09;

  TH1D **hNelSDig = new TH1D*[nLayers], **hNelDig = new TH1D*[nLayers];
  //
  for(Int_t i=0; i< nLayers; i++ ) {
    hNelSDig[i] = new TH1D(Form("hNelSDig%i",i),Form("electron distribution in SDigits [ Layer %i] ",i),nbins,xmin,xmax);
    hNelSDig[i]->SetXTitle("N electrons");
    hNelDig[i] = new TH1D(Form("hNelDig%i",i),Form("electron distribution in Digits [ Layer %i] ",i),nbins,xmin,xmax);
    hNelDig[i]->SetXTitle("N electrons");
  }

  AliLoader *dl = runLoader->GetDetectorLoader("ITS");

  //SDIGITS INIT
  TTree * sDigTree = 0x0;
  TClonesArray *sDigArr= new TClonesArray("AliITSUSDigit");

  //DIGITS INIT
  TTree * digTree = 0x0;
  TClonesArray *digArr= new TClonesArray("AliITSUDigitPix");

  int nevTot = (Int_t)runLoader->GetNumberOfEvents();
  printf("N Events : %i \n",nevTot);
  evStart = evStart<nevTot ? evStart : nevTot-1;
  if (evStart<0) evStart = 0;
  //
  int lastEv = nev<0 ? nevTot : evStart+nev;
  if (lastEv > nevTot) lastEv = nevTot;
  //
  printf("N Events : %i \n",(Int_t)nevTot);

  for (Int_t iEvent = evStart; iEvent < lastEv; iEvent++) {
    printf("\n Event %i \n",iEvent);
    runLoader->GetEvent(iEvent);
    AliStack *stack = runLoader->Stack();
    sDigTree=dl->TreeS();
    digTree=dl->TreeD();
    //
    sDigTree->SetBranchAddress("ITS",&sDigArr);
    digTree->SetBranchAddress("ITSDigitsPix",&digArr);

    for (int imod=0;imod<nModules;imod++) {
      sDigTree->GetEntry(imod);
      digTree->GetEntry(imod);
      int detType = gm->GetModuleDetTypeID(imod);
      AliITSUSegmentationPix* segm = (AliITSUSegmentationPix*)gm->GetSegmentationByID(detType);
      int lay,lad,det;
      int nsdig = sDigArr->GetEntries();
      int ndig  = digArr->GetEntries();
      if (nsdig<1) continue;
      gm->GetModuleId(imod, lay,lad,det);
      printf("\nModule %3d: (det %2d in ladder %2d of Layer %d) |NSDigits: %4d NDigits: %4d\n",imod,det,lad,lay,nsdig,ndig);
      //
      for (int isdig=0;isdig<nsdig;isdig++) {
	AliITSUSDigit *pSdig = (AliITSUSDigit*)sDigArr->At(isdig);
	int sdinfo = pSdig->GetUniqueID();
	UInt_t row,col;
	Int_t cycle;
	AliITSUSensMap::GetCell(sdinfo,segm->Npz(),segm->Npx(),kMaxROCycleAccept,col,row,cycle);
	printf("#%3d Sdigit col:%4d/row:%4d/cycle:%d generated by track %5d (%s)\t",isdig, col,row,cycle,
	       pSdig->GetTrack(0),stack->Particle(pSdig->GetTrack(0))->GetName());
	pSdig->Print();
	hNelSDig[lay]->Fill(pSdig->GetSignal());
      }
      //
      for (int idig=0;idig<ndig;idig++) {
	AliITSUDigitPix *pDig = (AliITSUDigitPix*)digArr->At(idig);
	printf("#%3d digit, col:%4d/row:%4d ROCycle:%d signal: %.2e,  generated by tracks ",idig,pDig->GetCoord1(),pDig->GetCoord2(),
	       pDig->GetROCycle(),pDig->GetSignalPix());
	for (int itr=0;itr<pDig->GetNTracks();itr++) if (pDig->GetTrack(itr)>=0) printf(" %5d",pDig->GetTrack(itr)); printf("\n");
	//
	hNelDig[lay]->Fill(pDig->GetSignalPix());
      }
      //
    }

  }//event loop

  TCanvas *cSd = new TCanvas("cSd","Summable Digits",1000,800);
  cSd->Divide(nLayers&0x1 ?  (nLayers/2+1) : nLayers/2,2);
  TCanvas *cD = new TCanvas("cD","Digits",1000,800);
  cD->Divide(nLayers&0x1 ?  (nLayers/2+1) : nLayers/2,2);

  for(Int_t ip =1; ip<=nLayers; ip++){
    cSd->cd(ip);
    hNelSDig[ip-1]->Draw();
    cD->cd(ip);
    hNelDig[ip-1]->Draw();
  }

}
<commit_msg>to allow reading digits only w/o sdigits<commit_after>void readDigits(int nev=-1,int evStart=0)
{

  gSystem->Load("libITSUpgradeBase");
  gSystem->Load("libITSUpgradeSim");
  gROOT->SetStyle("Plain");
  const Int_t kMaxROCycleAccept=126;
  gAlice=NULL;
  AliRunLoader* runLoader = AliRunLoader::Open("galice.root");
  runLoader->LoadgAlice();

  gAlice = runLoader->GetAliRun();

  runLoader->LoadHeader();
  runLoader->LoadKinematics();
  runLoader->LoadSDigits();
  runLoader->LoadDigits();

  AliGeomManager::LoadGeometry("geometry.root");
  AliITSUGeomTGeo* gm = new AliITSUGeomTGeo(kTRUE,kTRUE);
  //
  Int_t nLayers = gm->GetNLayers();
  Int_t nModules = gm->GetNModules();
  Int_t nbins=100;
  Int_t xmin=0;
  Int_t xmax=50000;//00*1e-09;

  TH1D **hNelSDig = new TH1D*[nLayers], **hNelDig = new TH1D*[nLayers];
  //
  for(Int_t i=0; i< nLayers; i++ ) {
    hNelSDig[i] = new TH1D(Form("hNelSDig%i",i),Form("electron distribution in SDigits [ Layer %i] ",i),nbins,xmin,xmax);
    hNelSDig[i]->SetXTitle("N electrons");
    hNelDig[i] = new TH1D(Form("hNelDig%i",i),Form("electron distribution in Digits [ Layer %i] ",i),nbins,xmin,xmax);
    hNelDig[i]->SetXTitle("N electrons");
  }

  AliLoader *dl = runLoader->GetDetectorLoader("ITS");

  //SDIGITS INIT
  TTree * sDigTree = 0x0;
  TClonesArray *sDigArr= new TClonesArray("AliITSUSDigit");

  //DIGITS INIT
  TTree * digTree = 0x0;
  TClonesArray *digArr= new TClonesArray("AliITSUDigitPix");

  int nevTot = (Int_t)runLoader->GetNumberOfEvents();
  printf("N Events : %i \n",nevTot);
  evStart = evStart<nevTot ? evStart : nevTot-1;
  if (evStart<0) evStart = 0;
  //
  int lastEv = nev<0 ? nevTot : evStart+nev;
  if (lastEv > nevTot) lastEv = nevTot;
  //
  printf("N Events : %i \n",(Int_t)nevTot);

  for (Int_t iEvent = evStart; iEvent < lastEv; iEvent++) {
    printf("\n Event %i \n",iEvent);
    runLoader->GetEvent(iEvent);
    AliStack *stack = runLoader->Stack();
    sDigTree=dl->TreeS();
    digTree=dl->TreeD();
    //
    if (sDigTree) sDigTree->SetBranchAddress("ITS",&sDigArr);
    digTree->SetBranchAddress("ITSDigitsPix",&digArr);

    for (int imod=0;imod<nModules;imod++) {
      if (sDigTree) sDigTree->GetEntry(imod);
      digTree->GetEntry(imod);
      int detType = gm->GetModuleDetTypeID(imod);
      AliITSUSegmentationPix* segm = (AliITSUSegmentationPix*)gm->GetSegmentationByID(detType);
      int lay,lad,det;
      int nsdig = sDigArr->GetEntries();
      int ndig  = digArr->GetEntries();
      if (ndig<1) continue;
      gm->GetModuleId(imod, lay,lad,det);
      printf("\nModule %3d: (det %2d in ladder %2d of Layer %d) |NSDigits: %4d NDigits: %4d\n",imod,det,lad,lay,nsdig,ndig);
      //
      for (int isdig=0;isdig<nsdig;isdig++) {
	AliITSUSDigit *pSdig = (AliITSUSDigit*)sDigArr->At(isdig);
	int sdinfo = pSdig->GetUniqueID();
	UInt_t row,col;
	Int_t cycle;
	AliITSUSensMap::GetCell(sdinfo,segm->Npz(),segm->Npx(),kMaxROCycleAccept,col,row,cycle);
	printf("#%3d Sdigit col:%4d/row:%4d/cycle:%d generated by track %5d (%s)\t",isdig, col,row,cycle,
	       pSdig->GetTrack(0),stack->Particle(pSdig->GetTrack(0))->GetName());
	pSdig->Print();
	hNelSDig[lay]->Fill(pSdig->GetSignal());
      }
      //
      for (int idig=0;idig<ndig;idig++) {
	AliITSUDigitPix *pDig = (AliITSUDigitPix*)digArr->At(idig);
	printf("#%3d digit, col:%4d/row:%4d ROCycle:%d signal: %.2e,  generated by tracks ",idig,pDig->GetCoord1(),pDig->GetCoord2(),
	       pDig->GetROCycle(),pDig->GetSignalPix());
	for (int itr=0;itr<pDig->GetNTracks();itr++) if (pDig->GetTrack(itr)>=0) printf(" %5d",pDig->GetTrack(itr)); printf("\n");
	//
	hNelDig[lay]->Fill(pDig->GetSignalPix());
      }
      //
    }

  }//event loop

  TCanvas *cSd = new TCanvas("cSd","Summable Digits",1000,800);
  cSd->Divide(nLayers&0x1 ?  (nLayers/2+1) : nLayers/2,2);
  TCanvas *cD = new TCanvas("cD","Digits",1000,800);
  cD->Divide(nLayers&0x1 ?  (nLayers/2+1) : nLayers/2,2);

  for(Int_t ip =1; ip<=nLayers; ip++){
    cSd->cd(ip);
    hNelSDig[ip-1]->Draw();
    cD->cd(ip);
    hNelDig[ip-1]->Draw();
  }

}
<|endoftext|>