<commit_before>/*!
  \copyright (c) RDO-Team, 2011
  \file      calc_relevant.inl
  \authors   Барс Александр
  \authors   Урусов Андрей (rdo@rk9.bmstu.ru)
  \date      16.04.2011
  \brief     RDOCalc для подбора релевантных ресурсов
  \indent    4T
*/

// ----------------------------------------------------------------------- INCLUDES
// ----------------------------------------------------------------------- SYNOPSIS
#include "simulator/runtime/rdo_runtime.h"
#include "simulator/runtime/rdo_activity.h"
// --------------------------------------------------------------------------------

OPEN_RDO_RUNTIME_NAMESPACE

// --------------------------------------------------------------------------------
// -------------------- RDOSetRelResParamCalc
// --------------------------------------------------------------------------------
template <SetOperationType::Type setOperationType>
inline RDOSetRelResParamCalc<setOperationType>::RDOSetRelResParamCalc(ruint relResID, ruint paramID, CREF(LPRDOCalc) pCalc)
	: m_relResID(relResID)
	, m_paramID (paramID )
	, m_pCalc   (pCalc   )
{
	if (m_pCalc)
	{
		setSrcInfo(m_pCalc->srcInfo());
	}
}

template <SetOperationType::Type setOperationType>
inline RDOSetRelResParamCalc<setOperationType>::~RDOSetRelResParamCalc()
{}

template <>
inline RDOValue RDOSetRelResParamCalc<SetOperationType::SET>::doCalc(CREF(LPRDORuntime) pRuntime)
{
	RDOValue value = m_pCalc->calcValue(pRuntime);
	ruint resID = pRuntime->getCurrentActivity()->getResByRelRes(m_relResID);
	pRuntime->setResParamVal(resID, m_paramID, value);
	return value;
}

template <>
inline RDOValue RDOSetRelResParamCalc<SetOperationType::ADDITION>::doCalc(CREF(LPRDORuntime) pRuntime)
{
	ruint resID = pRuntime->getCurrentActivity()->getResByRelRes(m_relResID);
	return pRuntime->getResParamValRaw(resID, m_paramID) += m_pCalc->calcValue(pRuntime);
}

template <>
inline RDOValue RDOSetRelResParamCalc<SetOperationType::SUBTRACTION>::doCalc(CREF(LPRDORuntime) pRuntime)
{
	ruint resID = pRuntime->getCurrentActivity()->getResByRelRes(m_relResID);
	return pRuntime->getResParamValRaw(resID, m_paramID) -= m_pCalc->calcValue(pRuntime);
}

template <>
inline RDOValue RDOSetRelResParamCalc<SetOperationType::MULTIPLY>::doCalc(CREF(LPRDORuntime) pRuntime)
{
	ruint resID = pRuntime->getCurrentActivity()->getResByRelRes(m_relResID);
	return pRuntime->getResParamValRaw(resID, m_paramID) *= m_pCalc->calcValue(pRuntime);
}

template <>
inline RDOValue RDOSetRelResParamCalc<SetOperationType::DIVIDE>::doCalc(CREF(LPRDORuntime) pRuntime)
{
	ruint resID = pRuntime->getCurrentActivity()->getResByRelRes(m_relResID);
	return pRuntime->getResParamValRaw(resID, m_paramID) /= m_pCalc->calcValue(pRuntime);
}

template <>
inline RDOValue RDOSetRelResParamCalc<SetOperationType::INCREMENT>::doCalc(CREF(LPRDORuntime) pRuntime)
{
	ruint resID = pRuntime->getCurrentActivity()->getResByRelRes(m_relResID);
	return pRuntime->getResParamValRaw(resID, m_paramID) += RDOValue(1);
}

template <>
inline RDOValue RDOSetRelResParamCalc<SetOperationType::DECRIMENT>::doCalc(CREF(LPRDORuntime) pRuntime)
{
	ruint resID = pRuntime->getCurrentActivity()->getResByRelRes(m_relResID);
	return pRuntime->getResParamValRaw(resID, m_paramID) -= RDOValue(1);
}

CLOSE_RDO_RUNTIME_NAMESPACE
<commit_msg> - добавлен NOCHANGE<commit_after>/*!
  \copyright (c) RDO-Team, 2011
  \file      calc_relevant.inl
  \authors   Барс Александр
  \authors   Урусов Андрей (rdo@rk9.bmstu.ru)
  \date      16.04.2011
  \brief     RDOCalc для подбора релевантных ресурсов
  \indent    4T
*/

// ----------------------------------------------------------------------- INCLUDES
// ----------------------------------------------------------------------- SYNOPSIS
#include "simulator/runtime/rdo_runtime.h"
#include "simulator/runtime/rdo_activity.h"
// --------------------------------------------------------------------------------

OPEN_RDO_RUNTIME_NAMESPACE

// --------------------------------------------------------------------------------
// -------------------- RDOSetRelResParamCalc
// --------------------------------------------------------------------------------
template <SetOperationType::Type setOperationType>
inline RDOSetRelResParamCalc<setOperationType>::RDOSetRelResParamCalc(ruint relResID, ruint paramID, CREF(LPRDOCalc) pCalc)
	: m_relResID(relResID)
	, m_paramID (paramID )
	, m_pCalc   (pCalc   )
{
	if (m_pCalc)
	{
		setSrcInfo(m_pCalc->srcInfo());
	}
}

template <SetOperationType::Type setOperationType>
inline RDOSetRelResParamCalc<setOperationType>::~RDOSetRelResParamCalc()
{}

template <>
inline RDOValue RDOSetRelResParamCalc<SetOperationType::NOCHANGE>::doCalc(CREF(LPRDORuntime) pRuntime)
{
	UNUSED(pRuntime);
	RDOValue value(true);
	return value;
}

template <>
inline RDOValue RDOSetRelResParamCalc<SetOperationType::SET>::doCalc(CREF(LPRDORuntime) pRuntime)
{
	RDOValue value = m_pCalc->calcValue(pRuntime);
	ruint resID = pRuntime->getCurrentActivity()->getResByRelRes(m_relResID);
	pRuntime->setResParamVal(resID, m_paramID, value);
	return value;
}

template <>
inline RDOValue RDOSetRelResParamCalc<SetOperationType::ADDITION>::doCalc(CREF(LPRDORuntime) pRuntime)
{
	ruint resID = pRuntime->getCurrentActivity()->getResByRelRes(m_relResID);
	return pRuntime->getResParamValRaw(resID, m_paramID) += m_pCalc->calcValue(pRuntime);
}

template <>
inline RDOValue RDOSetRelResParamCalc<SetOperationType::SUBTRACTION>::doCalc(CREF(LPRDORuntime) pRuntime)
{
	ruint resID = pRuntime->getCurrentActivity()->getResByRelRes(m_relResID);
	return pRuntime->getResParamValRaw(resID, m_paramID) -= m_pCalc->calcValue(pRuntime);
}

template <>
inline RDOValue RDOSetRelResParamCalc<SetOperationType::MULTIPLY>::doCalc(CREF(LPRDORuntime) pRuntime)
{
	ruint resID = pRuntime->getCurrentActivity()->getResByRelRes(m_relResID);
	return pRuntime->getResParamValRaw(resID, m_paramID) *= m_pCalc->calcValue(pRuntime);
}

template <>
inline RDOValue RDOSetRelResParamCalc<SetOperationType::DIVIDE>::doCalc(CREF(LPRDORuntime) pRuntime)
{
	ruint resID = pRuntime->getCurrentActivity()->getResByRelRes(m_relResID);
	return pRuntime->getResParamValRaw(resID, m_paramID) /= m_pCalc->calcValue(pRuntime);
}

template <>
inline RDOValue RDOSetRelResParamCalc<SetOperationType::INCREMENT>::doCalc(CREF(LPRDORuntime) pRuntime)
{
	ruint resID = pRuntime->getCurrentActivity()->getResByRelRes(m_relResID);
	return pRuntime->getResParamValRaw(resID, m_paramID) += RDOValue(1);
}

template <>
inline RDOValue RDOSetRelResParamCalc<SetOperationType::DECRIMENT>::doCalc(CREF(LPRDORuntime) pRuntime)
{
	ruint resID = pRuntime->getCurrentActivity()->getResByRelRes(m_relResID);
	return pRuntime->getResParamValRaw(resID, m_paramID) -= RDOValue(1);
}

CLOSE_RDO_RUNTIME_NAMESPACE
<|endoftext|>


<commit_before>AliAnalysisTaskCheckPerformanceCascadepp276 *AddTaskCheckPerformanceCascadepp276( Int_t    minnTPCcls             = 70,
                                                                                Float_t  vtxlim                 = 10.,
                                                                                Float_t  vtxlimmin              = 0.,
                                                                                Bool_t   fwithsdd               = kFALSE,
                                                                                Bool_t   kextrasel              = kFALSE,
                                                                                Bool_t   kacccut                = kFALSE,
                                                                                Bool_t   krelaunchvertexers     = kFALSE,
                                                                                Bool_t   ksddonselection        = kFALSE,
                                                                                Float_t  minptondaughtertracks  = 0.0,
                                                                                Float_t  etacutondaughtertracks = 0.8) {

   // Creates, configures and attaches to the train a cascades check task.
   // Get the pointer to the existing analysis manager via the static access method.
   //==============================================================================
   AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
   if (!mgr) {
      ::Error("AddTaskCheckPerformanceCascadepp276", "No analysis manager to connect to.");
      return NULL;
   }

   // Check the analysis type using the event handlers connected to the analysis manager.
   //==============================================================================
   if (!mgr->GetInputEventHandler()) {
      ::Error("AddTaskCheckPerformanceCascadepp276", "This task requires an input event handler");
      return NULL;
   }
   TString type = mgr->GetInputEventHandler()->GetDataType(); // can be "ESD" or "AOD"

   // Create and configure the task
   //==============================================================================
   TString tasknameperf = "TaskCheckPerformanceCascadepp276";
     tasknameperf += Form("_minnTPCcls%i_vtxlim%.1f-%.1f_minptdghtrk%.1f_etacutdghtrk%.1f",minnTPCcls,vtxlim,vtxlimmin,minptondaughtertracks,etacutondaughtertracks);
   AliAnalysisTaskCheckPerformanceCascadepp276 *taskCheckPerfCascadepp276 = new AliAnalysisTaskCheckPerformanceCascadepp276(tasknameperf);
     taskCheckPerfCascadepp276->SetAnalysisType               (type);                   // "ESD" or "AOD"
     taskCheckPerfCascadepp276->SetRelaunchV0CascVertexers    (krelaunchvertexers);     // choose if reconstruct the vertex of V0 in the cascades
     taskCheckPerfCascadepp276->SetSDDSelection               (fwithsdd);               // choose if apply SDD event selection
     taskCheckPerfCascadepp276->SetQualityCutZprimVtxPos      (kTRUE);                  // choose if apply Z vtx PV position event selection
     taskCheckPerfCascadepp276->SetRejectEventPileUp          (kFALSE);                 // choose if apply no Pileup event selection
     taskCheckPerfCascadepp276->SetQualityCutNoTPConlyPrimVtx (kTRUE);                  // choose if apply no TPC only event selection
     taskCheckPerfCascadepp276->SetQualityCutTPCrefit         (kTRUE);                  // choose if apply TPC refit on daughter tracks
     taskCheckPerfCascadepp276->SetQualityCutnTPCcls          (kTRUE);                  // choose if apply n TPC cluster selection on daughter tracks
     taskCheckPerfCascadepp276->SetWithSDDOn                  (ksddonselection);        // which SDD selection do you want apply? [if kTRUE select SDDon events]
     taskCheckPerfCascadepp276->SetQualityCutMinnTPCcls       (minnTPCcls);             // which value do you want apply for the minTPCcls cut?
     taskCheckPerfCascadepp276->SetExtraSelections            (kextrasel);              // choose if apply the extra selection of cascade reco.
     taskCheckPerfCascadepp276->SetApplyAccCut                (kacccut);                // choose if apply acceptance cut
     taskCheckPerfCascadepp276->SetVertexRange                (vtxlim);                 // which higher value do you want apply for vtx Z cut?
     taskCheckPerfCascadepp276->SetVertexRangeMin             (vtxlimmin);              // which lower value do you want apply for vtx Z cut?
     taskCheckPerfCascadepp276->SetMinptCutOnDaughterTracks   (minptondaughtertracks);  // which value do you want apply for cut on min pt daughter track?
     taskCheckPerfCascadepp276->SetEtaCutOnDaughterTracks     (etacutondaughtertracks); // which value do you want apply for cut on eta daughter track?

   mgr->AddTask(taskCheckPerfCascadepp276);

   // Create ONLY the output containers for the data produced by the task.
   // Get and connect other common input/output containers via the manager as below
   //==============================================================================
   // Directory name
   TString outputFileNamePerf = Form("%s:PWGLFStrangeness.outputCheckPerformanceCascadepp276", AliAnalysisManager::GetCommonFileName());
   // Objects name
   TString outputnameperf0 = "clistCascPerf";
   TString outputnameperf1 = "cfcontPIDAsXiM";
   TString outputnameperf2 = "cfcontPIDAsXiP";
   TString outputnameperf3 = "cfcontPIDAsOmegaM";
   TString outputnameperf4 = "cfcontPIDAsOmegaP";
   TString outputnameperf5 = "cfcontAsCuts";
     outputnameperf0 += Form("_minnTPCcls%i_vtxlim%.1f-%.1f_minptdghtrk%.1f_etacutdghtrk%.1f",minnTPCcls,vtxlim,vtxlimmin,minptondaughtertracks,etacutondaughtertracks);
     outputnameperf1 += Form("_minnTPCcls%i_vtxlim%.1f-%.1f_minptdghtrk%.1f_etacutdghtrk%.1f",minnTPCcls,vtxlim,vtxlimmin,minptondaughtertracks,etacutondaughtertracks);
     outputnameperf2 += Form("_minnTPCcls%i_vtxlim%.1f-%.1f_minptdghtrk%.1f_etacutdghtrk%.1f",minnTPCcls,vtxlim,vtxlimmin,minptondaughtertracks,etacutondaughtertracks);
     outputnameperf3 += Form("_minnTPCcls%i_vtxlim%.1f-%.1f_minptdghtrk%.1f_etacutdghtrk%.1f",minnTPCcls,vtxlim,vtxlimmin,minptondaughtertracks,etacutondaughtertracks);
     outputnameperf4 += Form("_minnTPCcls%i_vtxlim%.1f-%.1f_minptdghtrk%.1f_etacutdghtrk%.1f",minnTPCcls,vtxlim,vtxlimmin,minptondaughtertracks,etacutondaughtertracks);
     outputnameperf5 += Form("_minnTPCcls%i_vtxlim%.1f-%.1f_minptdghtrk%.1f_etacutdghtrk%.1f",minnTPCcls,vtxlim,vtxlimmin,minptondaughtertracks,etacutondaughtertracks);

   //Save objects into the train common file
   AliAnalysisDataContainer *coutputperf1 = mgr->CreateContainer(outputnameperf0,
							                                     TList::Class(),
                                                                 AliAnalysisManager::kOutputContainer,
							                                     outputFileNamePerf );
   AliAnalysisDataContainer *coutputperf2 = mgr->CreateContainer(outputnameperf1,
                                                                 AliCFContainer::Class(),
                                                                 AliAnalysisManager::kOutputContainer,
                                                                 outputFileNamePerf );
   AliAnalysisDataContainer *coutputperf3 = mgr->CreateContainer(outputnameperf2,
                                                                 AliCFContainer::Class(),
                                                                 AliAnalysisManager::kOutputContainer,
                                                                 outputFileNamePerf );
   AliAnalysisDataContainer *coutputperf4 = mgr->CreateContainer(outputnameperf3,
                                                                 AliCFContainer::Class(),
                                                                 AliAnalysisManager::kOutputContainer,
                                                                 outputFileNamePerf );
   AliAnalysisDataContainer *coutputperf5 = mgr->CreateContainer(outputnameperf4,
                                                                 AliCFContainer::Class(),
                                                                 AliAnalysisManager::kOutputContainer,
                                                                 outputFileNamePerf );
   AliAnalysisDataContainer *coutputperf6 = mgr->CreateContainer(outputnameperf5,
                                                                 AliCFContainer::Class(),
                                                                 AliAnalysisManager::kOutputContainer,
                                                                 outputFileNamePerf );

   mgr->ConnectInput( taskCheckPerfCascadepp276, 0, mgr->GetCommonInputContainer());
   mgr->ConnectOutput(taskCheckPerfCascadepp276, 1, coutputperf1);
   mgr->ConnectOutput(taskCheckPerfCascadepp276, 2, coutputperf2);
   mgr->ConnectOutput(taskCheckPerfCascadepp276, 3, coutputperf3);
   mgr->ConnectOutput(taskCheckPerfCascadepp276, 4, coutputperf4);
   mgr->ConnectOutput(taskCheckPerfCascadepp276, 5, coutputperf5);
   mgr->ConnectOutput(taskCheckPerfCascadepp276, 6, coutputperf6);

   return taskCheckPerfCascadepp276;
}
<commit_msg>Fix to apply pileup selection in MC performance<commit_after>AliAnalysisTaskCheckPerformanceCascadepp276 *AddTaskCheckPerformanceCascadepp276( Int_t    minnTPCcls             = 70,
                                                                                Float_t  vtxlim                 = 10.,
                                                                                Float_t  vtxlimmin              = 0.,
                                                                                Bool_t   fwithsdd               = kFALSE,
                                                                                Bool_t   kextrasel              = kFALSE,
                                                                                Bool_t   kacccut                = kFALSE,
                                                                                Bool_t   krelaunchvertexers     = kFALSE,
                                                                                Bool_t   ksddonselection        = kFALSE,
                                                                                Float_t  minptondaughtertracks  = 0.0,
                                                                                Float_t  etacutondaughtertracks = 0.8) {

   // Creates, configures and attaches to the train a cascades check task.
   // Get the pointer to the existing analysis manager via the static access method.
   //==============================================================================
   AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
   if (!mgr) {
      ::Error("AddTaskCheckPerformanceCascadepp276", "No analysis manager to connect to.");
      return NULL;
   }

   // Check the analysis type using the event handlers connected to the analysis manager.
   //==============================================================================
   if (!mgr->GetInputEventHandler()) {
      ::Error("AddTaskCheckPerformanceCascadepp276", "This task requires an input event handler");
      return NULL;
   }
   TString type = mgr->GetInputEventHandler()->GetDataType(); // can be "ESD" or "AOD"

   // Create and configure the task
   //==============================================================================
   TString tasknameperf = "TaskCheckPerformanceCascadepp276";
     tasknameperf += Form("_minnTPCcls%i_vtxlim%.1f-%.1f_minptdghtrk%.1f_etacutdghtrk%.1f",minnTPCcls,vtxlim,vtxlimmin,minptondaughtertracks,etacutondaughtertracks);
   AliAnalysisTaskCheckPerformanceCascadepp276 *taskCheckPerfCascadepp276 = new AliAnalysisTaskCheckPerformanceCascadepp276(tasknameperf);
     taskCheckPerfCascadepp276->SetAnalysisType               (type);                   // "ESD" or "AOD"
     taskCheckPerfCascadepp276->SetRelaunchV0CascVertexers    (krelaunchvertexers);     // choose if reconstruct the vertex of V0 in the cascades
     taskCheckPerfCascadepp276->SetSDDSelection               (fwithsdd);               // choose if apply SDD event selection
     taskCheckPerfCascadepp276->SetQualityCutZprimVtxPos      (kTRUE);                  // choose if apply Z vtx PV position event selection
     taskCheckPerfCascadepp276->SetRejectEventPileUp          (kTRUE);                  // choose if apply no Pileup event selection
     taskCheckPerfCascadepp276->SetQualityCutNoTPConlyPrimVtx (kTRUE);                  // choose if apply no TPC only event selection
     taskCheckPerfCascadepp276->SetQualityCutTPCrefit         (kTRUE);                  // choose if apply TPC refit on daughter tracks
     taskCheckPerfCascadepp276->SetQualityCutnTPCcls          (kTRUE);                  // choose if apply n TPC cluster selection on daughter tracks
     taskCheckPerfCascadepp276->SetWithSDDOn                  (ksddonselection);        // which SDD selection do you want apply? [if kTRUE select SDDon events]
     taskCheckPerfCascadepp276->SetQualityCutMinnTPCcls       (minnTPCcls);             // which value do you want apply for the minTPCcls cut?
     taskCheckPerfCascadepp276->SetExtraSelections            (kextrasel);              // choose if apply the extra selection of cascade reco.
     taskCheckPerfCascadepp276->SetApplyAccCut                (kacccut);                // choose if apply acceptance cut
     taskCheckPerfCascadepp276->SetVertexRange                (vtxlim);                 // which higher value do you want apply for vtx Z cut?
     taskCheckPerfCascadepp276->SetVertexRangeMin             (vtxlimmin);              // which lower value do you want apply for vtx Z cut?
     taskCheckPerfCascadepp276->SetMinptCutOnDaughterTracks   (minptondaughtertracks);  // which value do you want apply for cut on min pt daughter track?
     taskCheckPerfCascadepp276->SetEtaCutOnDaughterTracks     (etacutondaughtertracks); // which value do you want apply for cut on eta daughter track?

   mgr->AddTask(taskCheckPerfCascadepp276);

   // Create ONLY the output containers for the data produced by the task.
   // Get and connect other common input/output containers via the manager as below
   //==============================================================================
   // Directory name
   TString outputFileNamePerf = Form("%s:PWGLFStrangeness.outputCheckPerformanceCascadepp276", AliAnalysisManager::GetCommonFileName());
   // Objects name
   TString outputnameperf0 = "clistCascPerf";
   TString outputnameperf1 = "cfcontPIDAsXiM";
   TString outputnameperf2 = "cfcontPIDAsXiP";
   TString outputnameperf3 = "cfcontPIDAsOmegaM";
   TString outputnameperf4 = "cfcontPIDAsOmegaP";
   TString outputnameperf5 = "cfcontAsCuts";
     outputnameperf0 += Form("_minnTPCcls%i_vtxlim%.1f-%.1f_minptdghtrk%.1f_etacutdghtrk%.1f",minnTPCcls,vtxlim,vtxlimmin,minptondaughtertracks,etacutondaughtertracks);
     outputnameperf1 += Form("_minnTPCcls%i_vtxlim%.1f-%.1f_minptdghtrk%.1f_etacutdghtrk%.1f",minnTPCcls,vtxlim,vtxlimmin,minptondaughtertracks,etacutondaughtertracks);
     outputnameperf2 += Form("_minnTPCcls%i_vtxlim%.1f-%.1f_minptdghtrk%.1f_etacutdghtrk%.1f",minnTPCcls,vtxlim,vtxlimmin,minptondaughtertracks,etacutondaughtertracks);
     outputnameperf3 += Form("_minnTPCcls%i_vtxlim%.1f-%.1f_minptdghtrk%.1f_etacutdghtrk%.1f",minnTPCcls,vtxlim,vtxlimmin,minptondaughtertracks,etacutondaughtertracks);
     outputnameperf4 += Form("_minnTPCcls%i_vtxlim%.1f-%.1f_minptdghtrk%.1f_etacutdghtrk%.1f",minnTPCcls,vtxlim,vtxlimmin,minptondaughtertracks,etacutondaughtertracks);
     outputnameperf5 += Form("_minnTPCcls%i_vtxlim%.1f-%.1f_minptdghtrk%.1f_etacutdghtrk%.1f",minnTPCcls,vtxlim,vtxlimmin,minptondaughtertracks,etacutondaughtertracks);

   //Save objects into the train common file
   AliAnalysisDataContainer *coutputperf1 = mgr->CreateContainer(outputnameperf0,
							                                     TList::Class(),
                                                                 AliAnalysisManager::kOutputContainer,
							                                     outputFileNamePerf );
   AliAnalysisDataContainer *coutputperf2 = mgr->CreateContainer(outputnameperf1,
                                                                 AliCFContainer::Class(),
                                                                 AliAnalysisManager::kOutputContainer,
                                                                 outputFileNamePerf );
   AliAnalysisDataContainer *coutputperf3 = mgr->CreateContainer(outputnameperf2,
                                                                 AliCFContainer::Class(),
                                                                 AliAnalysisManager::kOutputContainer,
                                                                 outputFileNamePerf );
   AliAnalysisDataContainer *coutputperf4 = mgr->CreateContainer(outputnameperf3,
                                                                 AliCFContainer::Class(),
                                                                 AliAnalysisManager::kOutputContainer,
                                                                 outputFileNamePerf );
   AliAnalysisDataContainer *coutputperf5 = mgr->CreateContainer(outputnameperf4,
                                                                 AliCFContainer::Class(),
                                                                 AliAnalysisManager::kOutputContainer,
                                                                 outputFileNamePerf );
   AliAnalysisDataContainer *coutputperf6 = mgr->CreateContainer(outputnameperf5,
                                                                 AliCFContainer::Class(),
                                                                 AliAnalysisManager::kOutputContainer,
                                                                 outputFileNamePerf );

   mgr->ConnectInput( taskCheckPerfCascadepp276, 0, mgr->GetCommonInputContainer());
   mgr->ConnectOutput(taskCheckPerfCascadepp276, 1, coutputperf1);
   mgr->ConnectOutput(taskCheckPerfCascadepp276, 2, coutputperf2);
   mgr->ConnectOutput(taskCheckPerfCascadepp276, 3, coutputperf3);
   mgr->ConnectOutput(taskCheckPerfCascadepp276, 4, coutputperf4);
   mgr->ConnectOutput(taskCheckPerfCascadepp276, 5, coutputperf5);
   mgr->ConnectOutput(taskCheckPerfCascadepp276, 6, coutputperf6);

   return taskCheckPerfCascadepp276;
}
<|endoftext|>


<commit_before>/*
 * File:  ft_index_data.cpp
 * Copyright (C) 2004 The Institute for System Programming of the Russian Academy of Sciences (ISP RAS)
 */

#include "common/sedna.h"

#include "tr/ft/ft_index_data.h"
#include "common/xptr.h"
#include "tr/crmutils/node_utils.h"
#include "tr/vmm/vmm.h"
#include "tr/executor/base/tuple.h"
#include "tr/ft/FTindex.h"
#include "tr/log/log.h"
#include "tr/structures/schema.h"
#include "tr/executor/fo/casting_operations.h"
//#include "indexes.h"
#include "tr/executor/base/dm_accessors.h"

using namespace std;

pers_sset<ft_index_cell,unsigned short> *ft_indexdata;
index_id   *ft_idx_counter;
USemaphore ft_index_sem;//SEMAPHOR!!!

static bool ft_index_initialized = false;

//inits metadata library
void ft_index_on_session_begin(pers_sset<ft_index_cell,unsigned short> * _indexdata_, index_id *_idx_counter_)
{
    ft_indexdata = _indexdata_;
    ft_idx_counter = _idx_counter_;
	//SEMAPHOR INIT SECTION
	if (USemaphoreOpen(&ft_index_sem, FT_INDEX_SEMAPHORE_STR, __sys_call_error) != 0)
        throw USER_EXCEPTION2(SE4012, "FT_INDEX_SEMAPHORE_STR");

    ft_index_initialized = true;
}

void ft_index_on_session_end()
{
    if (!ft_index_initialized) return;
	//SEMAPHOR RELEASE SECTION
    if (USemaphoreClose(ft_index_sem, __sys_call_error) != 0)
        throw USER_EXCEPTION2(SE4013, "FT_INDEX_SEMAPHORE_STR");
    ft_index_initialized = false;
}

pers_sset<ft_index_cell,unsigned short>::pers_sset_entry* search_ft_indexdata_cell(const char *index_title)
{
	return ft_indexdata->get(index_title,NULL);
}
ft_custom_cell* ft_custom_cell::init(xml_ns* _ns, const char* _local,ft_index_type _cm,bool persistent)
{
	ft_custom_cell* ftc=(ft_custom_cell*)scm_malloc(sizeof(ft_custom_cell),persistent);
	ftc->ns=_ns;
	if (_local!=NULL)
	{
		char* z=(char*)scm_malloc(strlen(_local)+1,persistent);
		strcpy(z,_local);
		ftc->local=z;
	}
	else
		ftc->local=NULL;
	ftc->cm=_cm;
	return ftc;
}
void ft_index_cell::delete_custom_tree (pers_sset<ft_custom_cell,unsigned short> * custom_tree)
{
	pers_sset<ft_custom_cell,unsigned short>::pers_sset_entry* tmp=custom_tree->rb_minimum(custom_tree->root);
	while (tmp!=NULL)
	{
		//coll->free_metadata(tmp);
		ft_custom_cell* mdc=tmp->obj;
		if (mdc->local)
			scm_free(mdc->local,IS_PH_PTR(mdc));
		scm_free(mdc,IS_PH_PTR(mdc));
		tmp->obj=NULL;
		tmp=custom_tree->rb_successor(tmp);
	}
	pers_sset<ft_custom_cell,unsigned short>::sset_free(custom_tree);
}
void inline free_ft_indexdata_cell(pers_sset<ft_index_cell,unsigned short>::pers_sset_entry* entry)
{
	ft_index_cell* idc=entry->obj;
	ft_indexdata->rb_delete(entry);
	if (idc->index_title!=NULL)
		scm_free(idc->index_title,true);
	delete_PathExpr(idc->object);
	scm_free(idc->doc_name,true);
	if (idc->custom_tree!=NULL)
		ft_index_cell::delete_custom_tree(idc->custom_tree);
	scm_free(idc,true);
}
bool ft_index_cell::fits_to_index(schema_node* snode)
{
	t_scmnodes res;
	t_scmnodes objs=execute_abs_path_expr(snode->root,object);
	t_scmnodes::iterator it=objs.begin();
	while (it!=objs.end())
	{
		if (*it==snode)
			return true;
		it++;
	}
	return false;
}
ft_index_cell* ft_index_cell::create_index (PathExpr *object_path, ft_index_type it, doc_schema_node* schemaroot,const char * index_title, const char* doc_name,bool is_doc,std::vector< std::pair< std::pair<xml_ns*,char*>,ft_index_type> >* templ, bool just_heap)
{
	// I. Create and fill new index cell
	ft_index_sem_down();
	if (search_ft_indexdata_cell(index_title)!=NULL)
	{
		ft_index_sem_up();
		throw USER_EXCEPTION(SE2033);
	}
	down_concurrent_micro_ops_number();
	ft_index_cell* idc=(ft_index_cell*)scm_malloc(sizeof(ft_index_cell),true);
    idc->id = *ft_idx_counter;
    (*ft_idx_counter)++;
	idc->schemaroot = schemaroot;
	schemaroot->create_ft_index(idc);
	idc->object = object_path;
	idc->ftype=it;
	idc->index_title=(char*)scm_malloc(strlen(index_title)+1,true);
	strcpy(idc->index_title,index_title);
	idc->doc_name=(char*)scm_malloc(strlen(doc_name)+1,true);
	strcpy(idc->doc_name,doc_name);
	idc->is_doc=is_doc;
	if (it==ft_customized_value && templ!=NULL)
	{
		idc->custom_tree= pers_sset<ft_custom_cell,unsigned short>::init();
		std::vector<std::pair<std::pair<xml_ns*,char*>,ft_index_type> >::iterator tmp=templ->begin();
		while (tmp!=templ->end())
		{

			idc->custom_tree->put(ft_custom_cell::init((*tmp).first.first,(*tmp).first.second,(*tmp).second));
			tmp++;
		}
	}
	/*idc->next = *indexdata;
	if ((*indexdata) != NULL) (*indexdata)->pred = idc;
	*indexdata = idc;*/
	ft_indexdata->put(idc);
	ft_index_sem_up();
    hl_logical_log_ft_index(object_path, it,(char *) index_title, doc_name,is_doc,idc->custom_tree,true);
	up_concurrent_micro_ops_number();
	// ALGORITHM: indexing data
	//II. Execute abs path (object_path) on the desriptive schema
	if (!just_heap)
	{
		t_scmnodes sobj = execute_abs_path_expr(schemaroot, object_path);
		//III. For each schema node found (sn_obj)
		std::vector<xptr> start_nodes;
		for (int i = 0; i < sobj.size(); i++)
		{
			xptr blk= sobj[i]->bblk;
			sobj[i]->add_ft_index(idc);
			if (blk!=XNULL)
			{
			CHECKP(blk);
			start_nodes.push_back((GETBLOCKFIRSTDESCRIPTORABSOLUTE(((node_blk_hdr*)XADDR(blk)))));
			}
		}

		SednaIndexJob sij(idc);
		sij.create_index(&start_nodes);
	}
	return idc;
}
void ft_index_cell::delete_index (const char *index_title, bool just_heap)
{
	ft_index_sem_down();
	pers_sset<ft_index_cell,unsigned short>::pers_sset_entry* idc=search_ft_indexdata_cell(index_title);
	if (idc!=NULL)
	{

		if (!just_heap)
		{
			SednaIndexJob sij(idc->obj);
			sij.clear_index();
		}
		down_concurrent_micro_ops_number();
		hl_logical_log_ft_index((idc->obj)->object,(idc->obj)->ftype,(idc->obj)->index_title,(idc->obj)->doc_name,(idc->obj)->is_doc,(idc->obj)->custom_tree,false);
		ft_index_cell* ic=idc->obj;
		doc_schema_node* sm=(idc->obj)->schemaroot;
		free_ft_indexdata_cell(idc);
		(*ft_idx_counter)--;
		sm->delete_ft_index(ic);
		ft_index_sem_up();
		up_concurrent_micro_ops_number();
	}
	else
		ft_index_sem_up();
}
ft_index_cell* ft_index_cell::find_index(const char* title)
{
	xptr res;
    ft_index_sem_down();
	pers_sset<ft_index_cell,unsigned short>::pers_sset_entry* idc=search_ft_indexdata_cell(title);
	if (idc==NULL)
	{
		ft_index_sem_up();
		return NULL;
	}
	else
	{
		ft_index_sem_up();
		return idc->obj;
	}
}
void ft_index_cell::update_index(xptr_sequence* upserted)
{
	SednaIndexJob sij(this);
	sij.update_index(upserted);

}
void ft_index_cell::insert_to_index(xptr_sequence* upserted)
{
	SednaIndexJob sij(this);
	sij.insert_into_index(upserted);

}
void ft_index_cell::delete_from_index(xptr_sequence* deleted)
{
	SednaIndexJob sij(this);
	sij.delete_from_index(deleted);
}
void ft_index_cell::change_index(xptr_sequence* inserted,xptr_sequence* updated,xptr_sequence* deleted)
{
	SednaIndexJob sij(this);
	sij.insert_into_index(inserted);
	sij.update_index(updated);
	sij.delete_from_index(deleted);
}
<commit_msg>ftindex fix<commit_after>/*
 * File:  ft_index_data.cpp
 * Copyright (C) 2004 The Institute for System Programming of the Russian Academy of Sciences (ISP RAS)
 */

#include "common/sedna.h"

#include "tr/ft/ft_index_data.h"
#include "common/xptr.h"
#include "tr/crmutils/node_utils.h"
#include "tr/vmm/vmm.h"
#include "tr/executor/base/tuple.h"
#include "tr/ft/FTindex.h"
#include "tr/log/log.h"
#include "tr/structures/schema.h"
#include "tr/executor/fo/casting_operations.h"
//#include "indexes.h"
#include "tr/executor/base/dm_accessors.h"

using namespace std;

pers_sset<ft_index_cell,unsigned short> *ft_indexdata;
index_id   *ft_idx_counter;
USemaphore ft_index_sem;//SEMAPHOR!!!

static bool ft_index_initialized = false;

//inits metadata library
void ft_index_on_session_begin(pers_sset<ft_index_cell,unsigned short> * _indexdata_, index_id *_idx_counter_)
{
    ft_indexdata = _indexdata_;
    ft_idx_counter = _idx_counter_;
	//SEMAPHOR INIT SECTION
	if (USemaphoreOpen(&ft_index_sem, FT_INDEX_SEMAPHORE_STR, __sys_call_error) != 0)
        throw USER_EXCEPTION2(SE4012, "FT_INDEX_SEMAPHORE_STR");

    ft_index_initialized = true;
}

void ft_index_on_session_end()
{
    if (!ft_index_initialized) return;
	//SEMAPHOR RELEASE SECTION
    if (USemaphoreClose(ft_index_sem, __sys_call_error) != 0)
        throw USER_EXCEPTION2(SE4013, "FT_INDEX_SEMAPHORE_STR");
    ft_index_initialized = false;
}

pers_sset<ft_index_cell,unsigned short>::pers_sset_entry* search_ft_indexdata_cell(const char *index_title)
{
	return ft_indexdata->get(index_title,NULL);
}
ft_custom_cell* ft_custom_cell::init(xml_ns* _ns, const char* _local,ft_index_type _cm,bool persistent)
{
	ft_custom_cell* ftc=(ft_custom_cell*)scm_malloc(sizeof(ft_custom_cell),persistent);
	ftc->ns=_ns;
	if (_local!=NULL)
	{
		char* z=(char*)scm_malloc(strlen(_local)+1,persistent);
		strcpy(z,_local);
		ftc->local=z;
	}
	else
		ftc->local=NULL;
	ftc->cm=_cm;
	return ftc;
}
void ft_index_cell::delete_custom_tree (pers_sset<ft_custom_cell,unsigned short> * custom_tree)
{
	pers_sset<ft_custom_cell,unsigned short>::pers_sset_entry* tmp=custom_tree->rb_minimum(custom_tree->root);
	while (tmp!=NULL)
	{
		//coll->free_metadata(tmp);
		ft_custom_cell* mdc=tmp->obj;
		if (mdc->local)
			scm_free(mdc->local,IS_PH_PTR(mdc));
		scm_free(mdc,IS_PH_PTR(mdc));
		tmp->obj=NULL;
		tmp=custom_tree->rb_successor(tmp);
	}
	pers_sset<ft_custom_cell,unsigned short>::sset_free(custom_tree);
}
void inline free_ft_indexdata_cell(pers_sset<ft_index_cell,unsigned short>::pers_sset_entry* entry)
{
	ft_index_cell* idc=entry->obj;
	ft_indexdata->rb_delete(entry);
	if (idc->index_title!=NULL)
		scm_free(idc->index_title,true);
	delete_PathExpr(idc->object);
	scm_free(idc->doc_name,true);
	if (idc->custom_tree!=NULL)
		ft_index_cell::delete_custom_tree(idc->custom_tree);
	scm_free(idc,true);
}
bool ft_index_cell::fits_to_index(schema_node* snode)
{
	t_scmnodes res;
	t_scmnodes objs=execute_abs_path_expr(snode->root,object);
	t_scmnodes::iterator it=objs.begin();
	while (it!=objs.end())
	{
		if (*it==snode)
			return true;
		it++;
	}
	return false;
}
ft_index_cell* ft_index_cell::create_index (PathExpr *object_path, ft_index_type it, doc_schema_node* schemaroot,const char * index_title, const char* doc_name,bool is_doc,std::vector< std::pair< std::pair<xml_ns*,char*>,ft_index_type> >* templ, bool just_heap)
{
	// I. Create and fill new index cell
	ft_index_sem_down();
	if (search_ft_indexdata_cell(index_title)!=NULL)
	{
		ft_index_sem_up();
		throw USER_EXCEPTION(SE2033);
	}
	down_concurrent_micro_ops_number();
	ft_index_cell* idc=(ft_index_cell*)scm_malloc(sizeof(ft_index_cell),true);
    idc->id = *ft_idx_counter;
    (*ft_idx_counter)++;
	idc->schemaroot = schemaroot;
	schemaroot->create_ft_index(idc);
	idc->object = object_path;
	idc->ftype=it;
	idc->index_title=(char*)scm_malloc(strlen(index_title)+1,true);
	strcpy(idc->index_title,index_title);
	idc->doc_name=(char*)scm_malloc(strlen(doc_name)+1,true);
	strcpy(idc->doc_name,doc_name);
	idc->is_doc=is_doc;
	if (it==ft_customized_value && templ!=NULL)
	{
		idc->custom_tree= pers_sset<ft_custom_cell,unsigned short>::init();
		std::vector<std::pair<std::pair<xml_ns*,char*>,ft_index_type> >::iterator tmp=templ->begin();
		while (tmp!=templ->end())
		{

			idc->custom_tree->put(ft_custom_cell::init((*tmp).first.first,(*tmp).first.second,(*tmp).second));
			tmp++;
		}
	}
	/*idc->next = *indexdata;
	if ((*indexdata) != NULL) (*indexdata)->pred = idc;
	*indexdata = idc;*/
	ft_indexdata->put(idc);
	ft_index_sem_up();
    hl_logical_log_ft_index(object_path, it,(char *) index_title, doc_name,is_doc,idc->custom_tree,true);
	up_concurrent_micro_ops_number();
	// ALGORITHM: indexing data
	//II. Execute abs path (object_path) on the desriptive schema
	if (!just_heap)
	{
		t_scmnodes sobj = execute_abs_path_expr(schemaroot, object_path);
		//III. For each schema node found (sn_obj)
		std::vector<xptr> start_nodes;
		for (int i = 0; i < sobj.size(); i++)
		{
			xptr blk= sobj[i]->bblk;
			sobj[i]->add_ft_index(idc);
			if (blk!=XNULL)
			{
			CHECKP(blk);
			start_nodes.push_back((GETBLOCKFIRSTDESCRIPTORABSOLUTE(((node_blk_hdr*)XADDR(blk)))));
			}
		}

		SednaIndexJob sij(idc);
		sij.create_index(&start_nodes);
	}
	return idc;
}
void ft_index_cell::delete_index (const char *index_title, bool just_heap)
{
	ft_index_sem_down();
	pers_sset<ft_index_cell,unsigned short>::pers_sset_entry* idc=search_ft_indexdata_cell(index_title);
	if (idc!=NULL)
	{

		down_concurrent_micro_ops_number();
		hl_logical_log_ft_index((idc->obj)->object,(idc->obj)->ftype,(idc->obj)->index_title,(idc->obj)->doc_name,(idc->obj)->is_doc,(idc->obj)->custom_tree,false);
		if (!just_heap) //FIXME: mb move out of down_concurrent_micro_ops_number() block
		{
			SednaIndexJob sij(idc->obj);
			sij.clear_index();
		}
		ft_index_cell* ic=idc->obj;
		doc_schema_node* sm=(idc->obj)->schemaroot;
		free_ft_indexdata_cell(idc);
		(*ft_idx_counter)--;
		sm->delete_ft_index(ic);
		ft_index_sem_up();
		up_concurrent_micro_ops_number();
	}
	else
		ft_index_sem_up();
}
ft_index_cell* ft_index_cell::find_index(const char* title)
{
	xptr res;
    ft_index_sem_down();
	pers_sset<ft_index_cell,unsigned short>::pers_sset_entry* idc=search_ft_indexdata_cell(title);
	if (idc==NULL)
	{
		ft_index_sem_up();
		return NULL;
	}
	else
	{
		ft_index_sem_up();
		return idc->obj;
	}
}
void ft_index_cell::update_index(xptr_sequence* upserted)
{
	SednaIndexJob sij(this);
	sij.update_index(upserted);

}
void ft_index_cell::insert_to_index(xptr_sequence* upserted)
{
	SednaIndexJob sij(this);
	sij.insert_into_index(upserted);

}
void ft_index_cell::delete_from_index(xptr_sequence* deleted)
{
	SednaIndexJob sij(this);
	sij.delete_from_index(deleted);
}
void ft_index_cell::change_index(xptr_sequence* inserted,xptr_sequence* updated,xptr_sequence* deleted)
{
	SednaIndexJob sij(this);
	sij.insert_into_index(inserted);
	sij.update_index(updated);
	sij.delete_from_index(deleted);
}
<|endoftext|>


<commit_before>#include "QmitkSimpleExampleFunctionality.h"
#include "QmitkStdMultiWidget.h"
#include "QmitkSelectableGLWidget.h"

#include "QmitkSimpleExampleControls.h"

#include <qaction.h>
#include <qslider.h>

#include "slicer.xpm"

#include "mitkPlaneGeometry.h"
#include <mitkSurfaceData.h>
#include <mitkColorProperty.h>
#include <mitkLookupTable.h>

#include <mitkEventMapper.h>
#include <mitkGlobalInteraction.h>
#include <mitkCoordinateSupplier.h>
#include <mitkPointOperation.h>
#include <mitkDisplayCoordinateOperation.h>
#include <mitkDisplayVectorInteractor.h>
#include <mitkBaseRenderer.h>
#include <mitkInteractionConst.h>

#include <QmitkStepperAdapter.h>

#include <algorithm>

#if (defined(_MSC_VER) && (_MSC_VER <= 1200))
  #include <xutility>
#else
  #define _MAX	max
  #define _MIN	min
#endif

QmitkSimpleExampleFunctionality::QmitkSimpleExampleFunctionality(QObject *parent, const char *name, QmitkStdMultiWidget *mitkStdMultiWidget, mitk::DataTreeIterator * it) : QmitkFunctionality(parent, name, it) ,
controls(NULL), multiWidget(mitkStdMultiWidget), opacityprop(NULL), lookupTableProp(NULL)
{
    setAvailability(true);

    mitk::GlobalInteraction* globalInteraction = dynamic_cast<mitk::GlobalInteraction*>(mitk::EventMapper::GetGlobalStateMachine());
    if(globalInteraction!=NULL)
    {
	    globalInteraction->AddStateMachine(new mitk::CoordinateSupplier("navigation", this));//sends PointOperations
	    globalInteraction->AddStateMachine(new mitk::DisplayVectorInteractor("move", this));//sends DisplayCoordinateOperation
	    globalInteraction->AddStateMachine(new mitk::DisplayVectorInteractor("zoom", this));//sends DisplayCoordinateOperation
    }

    m_DataTreeIterator->getTree()->addTreeChangeListener(this);
}

QmitkSimpleExampleFunctionality::~QmitkSimpleExampleFunctionality()
{
}

QString QmitkSimpleExampleFunctionality::getFunctionalityName()
{
    return "simple example";
}

QWidget * QmitkSimpleExampleFunctionality::createMainWidget(QWidget *parent)
{
    if (multiWidget == NULL)
    {
        return multiWidget = new QmitkStdMultiWidget(parent);
    }
    else
        return NULL;
}

QWidget * QmitkSimpleExampleFunctionality::createControlWidget(QWidget *parent)
{
    if (controls == NULL)
    {
        controls = new QmitkSimpleExampleControls(parent);

        sliceNavigatorTransversal = mitk::SliceNavigationController::New();
        sliceNavigatorTransversal->SetViewDirection(mitk::SliceNavigationController::Transversal);
        sliceNavigatorTransversal->ConnectGeometrySliceEvent(multiWidget->mitkWidget1->GetRenderer().GetPointer());
        new QmitkStepperAdapter(controls->getSliceNavigatorTransversal(), sliceNavigatorTransversal->GetSlice(), "sliceNavigatorTransversalFromSimpleExample");

        sliceNavigatorSagittal = mitk::SliceNavigationController::New();
        sliceNavigatorSagittal->SetViewDirection(mitk::SliceNavigationController::Sagittal);
        sliceNavigatorSagittal->ConnectGeometrySliceEvent(multiWidget->mitkWidget2->GetRenderer().GetPointer());
        new QmitkStepperAdapter(controls->getSliceNavigatorSagittal(), sliceNavigatorSagittal->GetSlice(), "sliceNavigatorSagittalFromSimpleExample");

        sliceNavigatorFrontal = mitk::SliceNavigationController::New();
        sliceNavigatorFrontal->SetViewDirection(mitk::SliceNavigationController::Frontal);
        sliceNavigatorFrontal->ConnectGeometrySliceEvent(multiWidget->mitkWidget3->GetRenderer().GetPointer());
        new QmitkStepperAdapter(controls->getSliceNavigatorFrontal(), sliceNavigatorFrontal->GetSlice(), "sliceNavigatorFrontalFromSimpleExample");

        sliceNavigatorTime = mitk::SliceNavigationController::New();
        sliceNavigatorTime->ConnectGeometryTimeEvent(multiWidget->mitkWidget1->GetRenderer().GetPointer());
        new QmitkStepperAdapter(controls->getSliceNavigatorTime(), sliceNavigatorTime->GetTime(), "sliceNavigatorTimeFromSimpleExample");
    }
    return controls;
}

void QmitkSimpleExampleFunctionality::createConnections()
{
    connect(controls, SIGNAL(xySliderChanged(int)), this, SLOT(selectSliceWidgetXY(int)) );
    connect(controls, SIGNAL(yzSliderChanged(int)), this, SLOT(selectSliceWidgetYZ(int)) );
    connect(controls, SIGNAL(xzSliderChanged(int)), this, SLOT(selectSliceWidgetXZ(int)) );
    connect(controls, SIGNAL(fpSliderChanged(int)), this, SLOT(selectSliceWidgetFP(int)) );
}

QAction * QmitkSimpleExampleFunctionality::createAction(QActionGroup *parent)
{
    QAction* action;
    action = new QAction( tr( "Left" ), QPixmap((const char**)slicer_xpm), tr( "&Left" ), CTRL + Key_L, parent, "simple example" );
    //    action = new QAction( tr( "Left" ), QPixmap(textleft_xpm), tr( "&Left" ), CTRL + Key_L, parent, "simple example" );
    return action;
}
void QmitkSimpleExampleFunctionality::initNavigators()
{
  const mitk::BoundingBox::Pointer boundingbox = mitk::DataTree::ComputeVisibleBoundingBox(m_DataTreeIterator, NULL, "includeInBoundingBox");
  if(boundingbox->GetPoints()->Size()>0)
  {
    mitk::Geometry3D::Pointer geometry = mitk::Geometry3D::New();
    geometry->Initialize();
    geometry->SetBoundingBox(boundingbox);
    sliceNavigatorTransversal->SetInputWorldGeometry(geometry.GetPointer()); sliceNavigatorTransversal->Update();
    sliceNavigatorFrontal->SetInputWorldGeometry(geometry.GetPointer());     sliceNavigatorFrontal->Update();
    sliceNavigatorSagittal->SetInputWorldGeometry(geometry.GetPointer());    sliceNavigatorSagittal->Update();
  }
}

void QmitkSimpleExampleFunctionality::treeChanged(mitk::DataTreeIterator& itpos)
{
  if(isActivated())
    initNavigators();
}

void QmitkSimpleExampleFunctionality::activated()
{
  QmitkFunctionality::activated();
    assert( multiWidget != NULL );
    // init widget 4 as a 3D widget
    multiWidget->mitkWidget4->GetRenderer()->SetMapperID(2);

    initNavigators();
}

//void QmitkSimpleExampleFunctionality::deactivated()
//{
//
//}

void QmitkSimpleExampleFunctionality::selectSliceWidgetXY( int z )
{
    const mitk::Geometry2D* g2d = multiWidget->mitkWidget1->GetRenderer()->GetCurrentWorldGeometry2D();
    const mitk::PlaneGeometry* pg = dynamic_cast<const mitk::PlaneGeometry*>(g2d);
    mitk::PlaneView pv = pg->GetPlaneView();
    pv.point.z = z;
    mitk::PlaneGeometry::Pointer plane = mitk::PlaneGeometry::New();
    plane->SetPlaneView(pv);
    multiWidget->mitkWidget1->GetRenderer()->SetWorldGeometry(plane);
    multiWidget->updateMitkWidgets();
    //std::cout << "Slider:" << z << std::endl;
}

void QmitkSimpleExampleFunctionality::selectSliceWidgetXZ(int y)
{
    const mitk::Geometry2D* g2d = multiWidget->mitkWidget3->GetRenderer()->GetCurrentWorldGeometry2D();
    const mitk::PlaneGeometry* pg = dynamic_cast<const mitk::PlaneGeometry*>(g2d);
    mitk::PlaneView pv = pg->GetPlaneView();
    pv.point.y=y;
    mitk::PlaneGeometry::Pointer plane = mitk::PlaneGeometry::New();
    plane->SetPlaneView(pv);
    multiWidget->mitkWidget3->GetRenderer()->SetWorldGeometry(plane);
    multiWidget->updateMitkWidgets();
    //std::cout << "Slider:" << y << std::endl;
}

void QmitkSimpleExampleFunctionality::selectSliceWidgetYZ(int x)
{
    const mitk::Geometry2D* g2d = multiWidget->mitkWidget2->GetRenderer()->GetCurrentWorldGeometry2D();
    const mitk::PlaneGeometry* pg = dynamic_cast<const mitk::PlaneGeometry*>(g2d);
    mitk::PlaneView pv = pg->GetPlaneView();
    pv.point.x = x;
    mitk::PlaneGeometry::Pointer plane = mitk::PlaneGeometry::New();
    plane->SetPlaneView(pv);
    multiWidget->mitkWidget2->GetRenderer()->SetWorldGeometry(plane);
    multiWidget->updateMitkWidgets();
    //std::cout << "Slider:" << x << std::endl;
}

void QmitkSimpleExampleFunctionality::selectSliceWidgetFP( int p )
{
  bool update=false;
  if( opacityprop.IsNotNull() )
  {
		opacityprop->SetValue(p/100.0);
    update = true;
	}
  if(lookupTableProp.IsNotNull())
  {
		lookupTableProp->GetLookupTable().ChangeOpacityForAll(p/100.0);
    update = true;
	}

  if(update)
    multiWidget->updateMitkWidgets();
}

void QmitkSimpleExampleFunctionality::initWidgets()
{
	int count = 0;
	mitk::DataTreeIterator* it=m_DataTreeIterator->clone();
	while (it->hasNext()) {
		it->next();
		printf("\nrequesting boundingbox\n");
		mitk::DataTreeNode::Pointer node = it->get();
		mitk::BaseData::Pointer data=node->GetData();
    if((data.IsNotNull()) && (dynamic_cast<mitk::Geometry2DData*>(node->GetData()) == NULL ))
		{
			// get
			if ((data->GetUpdatedGeometry())!=NULL )
			{
				mitk::BoundingBox::ConstPointer bb = data->GetGeometry()->GetBoundingBox();
				printf("boundsArrayType\n");
				const mitk::BoundingBox::BoundsArrayType bounds = bb->GetBounds();
				printf("\nboundingbox\n");

				// init slider limits
				controls->sliderYZ->setMinValue(std::_MIN<int>(bounds[0],controls->sliderYZ->minValue()));
				controls->sliderYZ->setMaxValue(std::_MAX<int>(bounds[1],controls->sliderYZ->maxValue()));
				controls->sliderXZ->setMinValue(std::_MIN<int>(bounds[2],controls->sliderXZ->minValue()));
				controls->sliderXZ->setMaxValue(std::_MAX<int>(bounds[3],controls->sliderXZ->maxValue()));
				controls->sliderXY->setMinValue(std::_MIN<int>(bounds[4],controls->sliderXY->minValue()));
				controls->sliderXY->setMaxValue(std::_MAX<int>(bounds[5],controls->sliderXY->maxValue()));
				count++;
			}

      lookupTableProp=NULL;
		}
	}
	delete it;
}

void QmitkSimpleExampleFunctionality::ExecuteOperation(mitk::Operation* operation)
{
    bool ok;//as return

    mitk::PointOperation* pointoperation=dynamic_cast<mitk::PointOperation*>(operation);
    if(pointoperation!=NULL)
    {
    /****NAVIGATION inside the volume****/
        switch (operation->GetOperationType())
        {
        case mitk::OpMOVE:
                {
                    mitk::ITKPoint3D point;
                    mitk::Point3D seed;

                    point = pointoperation->GetPoint();
                    mitk::itk2vm(point, seed);

                    const mitk::Geometry2D* g2d;
                    const mitk::PlaneGeometry* pg;
                    mitk::PlaneView pv;
                    mitk::PlaneGeometry::Pointer plane;

                    int v;
                    v=(int)seed.x;
                    if(controls->getSliderYZ()->value()!=v)
                    {
                        g2d = multiWidget->mitkWidget2->GetRenderer()->GetCurrentWorldGeometry2D();
                        pg = dynamic_cast<const mitk::PlaneGeometry*>(g2d);
                        pv = pg->GetPlaneView();
                        pv.point.x = v;
                        plane = mitk::PlaneGeometry::New();
                        plane->SetPlaneView(pv);
                        multiWidget->mitkWidget2->GetRenderer()->SetWorldGeometry(plane);
                        controls->getSliderYZ()->blockSignals(true);
                        controls->getSliderYZ()->setValue(v);
                        controls->getSliderYZ()->blockSignals(false);
                    }
                    v=(int)seed.y;
                    if(controls->getSliderXZ()->value()!=v)
                    {
                        g2d = multiWidget->mitkWidget3->GetRenderer()->GetCurrentWorldGeometry2D();
                        pg = dynamic_cast<const mitk::PlaneGeometry*>(g2d);
                        pv = pg->GetPlaneView();
                        pv.point.y = v;
                        plane  = mitk::PlaneGeometry::New();
                        plane->SetPlaneView(pv);
                        multiWidget->mitkWidget3->GetRenderer()->SetWorldGeometry(plane);
                        controls->getSliderXZ()->blockSignals(true);
                        controls->getSliderXZ()->setValue(v);
                        controls->getSliderXZ()->blockSignals(false);
                    }

                    v=(int)seed.z;
                    if(controls->getSliderXY()->value()!=v)
                    {
                        g2d = multiWidget->mitkWidget1->GetRenderer()->GetCurrentWorldGeometry2D();
                        pg = dynamic_cast<const mitk::PlaneGeometry*>(g2d);
                        pv = pg->GetPlaneView();
                        pv.point.z = v;
                        plane = mitk::PlaneGeometry::New();
                        plane->SetPlaneView(pv);
                        multiWidget->mitkWidget1->GetRenderer()->SetWorldGeometry(plane);
                        controls->getSliderXY()->blockSignals(true);
                        controls->getSliderXY()->setValue(v);
                        controls->getSliderXY()->blockSignals(false);
                    }
                    multiWidget->updateMitkWidgets();
                    ok = true;
                }
                break;
            case mitk::OpNOTHING:
                break;
            default:
                ;
        }
    }
    mitk::DisplayCoordinateOperation* dcOperation=dynamic_cast<mitk::DisplayCoordinateOperation*>(operation);
    if( dcOperation != NULL )
    {
    /****ZOOM & MOVE of the whole volume****/
        mitk::BaseRenderer* renderer = dcOperation->GetRenderer();
        if( renderer == NULL )
            return;
        switch (operation->GetOperationType())
        {
            case mitk::OpMOVE :
                {
                    renderer->GetDisplayGeometry()->MoveBy(dcOperation->GetLastToCurrentDisplayVector()*(-1.0));
                    renderer->GetRenderWindow()->Update();
                    ok = true;
                }
                break;
            case mitk::OpZOOM :
                {
                    float distance = dcOperation->GetLastToCurrentDisplayVector().y;
                    distance = (distance > 0 ? 1 : (distance < 0 ? -1 : 0));
                    float factor= 1.0 + distance * 0.05;
                    renderer->GetDisplayGeometry()->Zoom(factor, dcOperation->GetStartDisplayCoordinate());
                    renderer->GetRenderWindow()->Update();
                    ok = true;
                }
                break;
            default:
                ;
        }
    }
}
<commit_msg>initialization of time-slicenavigationcontroller. works a bit.<commit_after>#include "QmitkSimpleExampleFunctionality.h"
#include "QmitkStdMultiWidget.h"
#include "QmitkSelectableGLWidget.h"

#include "QmitkSimpleExampleControls.h"

#include <qaction.h>
#include <qslider.h>

#include "slicer.xpm"

#include "mitkPlaneGeometry.h"
#include <mitkSurfaceData.h>
#include <mitkColorProperty.h>
#include <mitkLookupTable.h>

#include <mitkEventMapper.h>
#include <mitkGlobalInteraction.h>
#include <mitkCoordinateSupplier.h>
#include <mitkPointOperation.h>
#include <mitkDisplayCoordinateOperation.h>
#include <mitkDisplayVectorInteractor.h>
#include <mitkBaseRenderer.h>
#include <mitkInteractionConst.h>

#include <QmitkStepperAdapter.h>

#include <algorithm>

#if (defined(_MSC_VER) && (_MSC_VER <= 1200))
  #include <xutility>
#else
  #define _MAX	max
  #define _MIN	min
#endif

QmitkSimpleExampleFunctionality::QmitkSimpleExampleFunctionality(QObject *parent, const char *name, QmitkStdMultiWidget *mitkStdMultiWidget, mitk::DataTreeIterator * it) : QmitkFunctionality(parent, name, it) ,
controls(NULL), multiWidget(mitkStdMultiWidget), opacityprop(NULL), lookupTableProp(NULL)
{
    setAvailability(true);

    mitk::GlobalInteraction* globalInteraction = dynamic_cast<mitk::GlobalInteraction*>(mitk::EventMapper::GetGlobalStateMachine());
    if(globalInteraction!=NULL)
    {
	    globalInteraction->AddStateMachine(new mitk::CoordinateSupplier("navigation", this));//sends PointOperations
	    globalInteraction->AddStateMachine(new mitk::DisplayVectorInteractor("move", this));//sends DisplayCoordinateOperation
	    globalInteraction->AddStateMachine(new mitk::DisplayVectorInteractor("zoom", this));//sends DisplayCoordinateOperation
    }

    m_DataTreeIterator->getTree()->addTreeChangeListener(this);
}

QmitkSimpleExampleFunctionality::~QmitkSimpleExampleFunctionality()
{
}

QString QmitkSimpleExampleFunctionality::getFunctionalityName()
{
    return "simple example";
}

QWidget * QmitkSimpleExampleFunctionality::createMainWidget(QWidget *parent)
{
    if (multiWidget == NULL)
    {
        return multiWidget = new QmitkStdMultiWidget(parent);
    }
    else
        return NULL;
}

QWidget * QmitkSimpleExampleFunctionality::createControlWidget(QWidget *parent)
{
    if (controls == NULL)
    {
        controls = new QmitkSimpleExampleControls(parent);

        sliceNavigatorTransversal = mitk::SliceNavigationController::New();
        sliceNavigatorTransversal->SetViewDirection(mitk::SliceNavigationController::Transversal);
        sliceNavigatorTransversal->ConnectGeometrySliceEvent(multiWidget->mitkWidget1->GetRenderer().GetPointer());
        new QmitkStepperAdapter(controls->getSliceNavigatorTransversal(), sliceNavigatorTransversal->GetSlice(), "sliceNavigatorTransversalFromSimpleExample");

        sliceNavigatorSagittal = mitk::SliceNavigationController::New();
        sliceNavigatorSagittal->SetViewDirection(mitk::SliceNavigationController::Sagittal);
        sliceNavigatorSagittal->ConnectGeometrySliceEvent(multiWidget->mitkWidget2->GetRenderer().GetPointer());
        new QmitkStepperAdapter(controls->getSliceNavigatorSagittal(), sliceNavigatorSagittal->GetSlice(), "sliceNavigatorSagittalFromSimpleExample");

        sliceNavigatorFrontal = mitk::SliceNavigationController::New();
        sliceNavigatorFrontal->SetViewDirection(mitk::SliceNavigationController::Frontal);
        sliceNavigatorFrontal->ConnectGeometrySliceEvent(multiWidget->mitkWidget3->GetRenderer().GetPointer());
        new QmitkStepperAdapter(controls->getSliceNavigatorFrontal(), sliceNavigatorFrontal->GetSlice(), "sliceNavigatorFrontalFromSimpleExample");

        sliceNavigatorTime = mitk::SliceNavigationController::New();
        sliceNavigatorTime->ConnectGeometryTimeEvent(multiWidget->mitkWidget1->GetRenderer().GetPointer());
        new QmitkStepperAdapter(controls->getSliceNavigatorTime(), sliceNavigatorTime->GetTime(), "sliceNavigatorTimeFromSimpleExample");
    }
    return controls;
}

void QmitkSimpleExampleFunctionality::createConnections()
{
    connect(controls, SIGNAL(xySliderChanged(int)), this, SLOT(selectSliceWidgetXY(int)) );
    connect(controls, SIGNAL(yzSliderChanged(int)), this, SLOT(selectSliceWidgetYZ(int)) );
    connect(controls, SIGNAL(xzSliderChanged(int)), this, SLOT(selectSliceWidgetXZ(int)) );
    connect(controls, SIGNAL(fpSliderChanged(int)), this, SLOT(selectSliceWidgetFP(int)) );
}

QAction * QmitkSimpleExampleFunctionality::createAction(QActionGroup *parent)
{
    QAction* action;
    action = new QAction( tr( "Left" ), QPixmap((const char**)slicer_xpm), tr( "&Left" ), CTRL + Key_L, parent, "simple example" );
    //    action = new QAction( tr( "Left" ), QPixmap(textleft_xpm), tr( "&Left" ), CTRL + Key_L, parent, "simple example" );
    return action;
}
void QmitkSimpleExampleFunctionality::initNavigators()
{
  const mitk::BoundingBox::Pointer boundingbox = mitk::DataTree::ComputeVisibleBoundingBox(m_DataTreeIterator, NULL, "includeInBoundingBox");
  if(boundingbox->GetPoints()->Size()>0)
  {
    // const mitk::BoundingBox::Pointer bb=boundingbox;
    //const mitk::BoundingBox::BoundsArrayType bounds = bb->GetBounds();
    // float boundingbox[6]={-2*bounds[1],2*bounds[1],-2*bounds[3],2*bounds[3],-2*bounds[5],2*bounds[5]};
    mitk::Geometry3D::Pointer geometry = mitk::Geometry3D::New();
    geometry->Initialize();
    geometry->SetBoundingBox(boundingbox);

    //lets see if we have data with a limited live-span ...
    mitk::TimeBounds timebounds = mitk::DataTree::ComputeTimeBoundsInMS(m_DataTreeIterator, NULL, "includeInBoundingBox");
    if(timebounds[1]<mitk::ScalarTypeNumericTraits::max())
    {
      mitk::TimeSlicedGeometry::Pointer timegeometry = mitk::TimeSlicedGeometry::New();
      timegeometry->Initialize(10);
      timegeometry->SetTimeBoundsInMS(timebounds); //@bug really required?
      timegeometry->SetEvenlyTimed();
      mitk::ScalarType duration = timebounds[1]-timebounds[0];
      timebounds[1] = timebounds[0]+duration/10.0;

      timegeometry->SetGeometry3D(geometry, 0);
      geometry->SetTimeBoundsInMS(timebounds);

      geometry=timegeometry;
    }

    sliceNavigatorTransversal->SetInputWorldGeometry(geometry.GetPointer()); sliceNavigatorTransversal->Update();
    sliceNavigatorFrontal->SetInputWorldGeometry(geometry.GetPointer());     sliceNavigatorFrontal->Update();
    sliceNavigatorSagittal->SetInputWorldGeometry(geometry.GetPointer());    sliceNavigatorSagittal->Update();
    sliceNavigatorTime->SetInputWorldGeometry(geometry.GetPointer());        sliceNavigatorTime->Update();
  }
}

void QmitkSimpleExampleFunctionality::treeChanged(mitk::DataTreeIterator& itpos)
{
  if(isActivated())
    initNavigators();
}

void QmitkSimpleExampleFunctionality::activated()
{
  QmitkFunctionality::activated();
    assert( multiWidget != NULL );
    // init widget 4 as a 3D widget
    multiWidget->mitkWidget4->GetRenderer()->SetMapperID(2);

    initNavigators();
}

//void QmitkSimpleExampleFunctionality::deactivated()
//{
//
//}

void QmitkSimpleExampleFunctionality::selectSliceWidgetXY( int z )
{
    const mitk::Geometry2D* g2d = multiWidget->mitkWidget1->GetRenderer()->GetCurrentWorldGeometry2D();
    const mitk::PlaneGeometry* pg = dynamic_cast<const mitk::PlaneGeometry*>(g2d);
    mitk::PlaneView pv = pg->GetPlaneView();
    pv.point.z = z;
    mitk::PlaneGeometry::Pointer plane = mitk::PlaneGeometry::New();
    plane->SetPlaneView(pv);
    multiWidget->mitkWidget1->GetRenderer()->SetWorldGeometry(plane);
    multiWidget->updateMitkWidgets();
    //std::cout << "Slider:" << z << std::endl;
}

void QmitkSimpleExampleFunctionality::selectSliceWidgetXZ(int y)
{
    const mitk::Geometry2D* g2d = multiWidget->mitkWidget3->GetRenderer()->GetCurrentWorldGeometry2D();
    const mitk::PlaneGeometry* pg = dynamic_cast<const mitk::PlaneGeometry*>(g2d);
    mitk::PlaneView pv = pg->GetPlaneView();
    pv.point.y=y;
    mitk::PlaneGeometry::Pointer plane = mitk::PlaneGeometry::New();
    plane->SetPlaneView(pv);
    multiWidget->mitkWidget3->GetRenderer()->SetWorldGeometry(plane);
    multiWidget->updateMitkWidgets();
    //std::cout << "Slider:" << y << std::endl;
}

void QmitkSimpleExampleFunctionality::selectSliceWidgetYZ(int x)
{
    const mitk::Geometry2D* g2d = multiWidget->mitkWidget2->GetRenderer()->GetCurrentWorldGeometry2D();
    const mitk::PlaneGeometry* pg = dynamic_cast<const mitk::PlaneGeometry*>(g2d);
    mitk::PlaneView pv = pg->GetPlaneView();
    pv.point.x = x;
    mitk::PlaneGeometry::Pointer plane = mitk::PlaneGeometry::New();
    plane->SetPlaneView(pv);
    multiWidget->mitkWidget2->GetRenderer()->SetWorldGeometry(plane);
    multiWidget->updateMitkWidgets();
    //std::cout << "Slider:" << x << std::endl;
}

void QmitkSimpleExampleFunctionality::selectSliceWidgetFP( int p )
{
  bool update=false;
  if( opacityprop.IsNotNull() )
  {
		opacityprop->SetValue(p/100.0);
    update = true;
	}
  if(lookupTableProp.IsNotNull())
  {
		lookupTableProp->GetLookupTable().ChangeOpacityForAll(p/100.0);
    update = true;
	}

  if(update)
    multiWidget->updateMitkWidgets();
}

void QmitkSimpleExampleFunctionality::initWidgets()
{
	int count = 0;
	mitk::DataTreeIterator* it=m_DataTreeIterator->clone();
	while (it->hasNext()) {
		it->next();
		printf("\nrequesting boundingbox\n");
		mitk::DataTreeNode::Pointer node = it->get();
		mitk::BaseData::Pointer data=node->GetData();
    if((data.IsNotNull()) && (dynamic_cast<mitk::Geometry2DData*>(node->GetData()) == NULL ))
		{
			// get
			if ((data->GetUpdatedGeometry())!=NULL )
			{
				mitk::BoundingBox::ConstPointer bb = data->GetGeometry()->GetBoundingBox();
				printf("boundsArrayType\n");
				const mitk::BoundingBox::BoundsArrayType bounds = bb->GetBounds();
				printf("\nboundingbox\n");

				// init slider limits
				controls->sliderYZ->setMinValue(std::_MIN<int>(bounds[0],controls->sliderYZ->minValue()));
				controls->sliderYZ->setMaxValue(std::_MAX<int>(bounds[1],controls->sliderYZ->maxValue()));
				controls->sliderXZ->setMinValue(std::_MIN<int>(bounds[2],controls->sliderXZ->minValue()));
				controls->sliderXZ->setMaxValue(std::_MAX<int>(bounds[3],controls->sliderXZ->maxValue()));
				controls->sliderXY->setMinValue(std::_MIN<int>(bounds[4],controls->sliderXY->minValue()));
				controls->sliderXY->setMaxValue(std::_MAX<int>(bounds[5],controls->sliderXY->maxValue()));
				count++;
			}

      lookupTableProp=NULL;
		}
	}
	delete it;
}

void QmitkSimpleExampleFunctionality::ExecuteOperation(mitk::Operation* operation)
{
    bool ok;//as return

    mitk::PointOperation* pointoperation=dynamic_cast<mitk::PointOperation*>(operation);
    if(pointoperation!=NULL)
    {
    /****NAVIGATION inside the volume****/
        switch (operation->GetOperationType())
        {
        case mitk::OpMOVE:
                {
                    mitk::ITKPoint3D point;
                    mitk::Point3D seed;

                    point = pointoperation->GetPoint();
                    mitk::itk2vm(point, seed);

                    const mitk::Geometry2D* g2d;
                    const mitk::PlaneGeometry* pg;
                    mitk::PlaneView pv;
                    mitk::PlaneGeometry::Pointer plane;

                    int v;
                    v=(int)seed.x;
                    if(controls->getSliderYZ()->value()!=v)
                    {
                        g2d = multiWidget->mitkWidget2->GetRenderer()->GetCurrentWorldGeometry2D();
                        pg = dynamic_cast<const mitk::PlaneGeometry*>(g2d);
                        pv = pg->GetPlaneView();
                        pv.point.x = v;
                        plane = mitk::PlaneGeometry::New();
                        plane->SetPlaneView(pv);
                        multiWidget->mitkWidget2->GetRenderer()->SetWorldGeometry(plane);
                        controls->getSliderYZ()->blockSignals(true);
                        controls->getSliderYZ()->setValue(v);
                        controls->getSliderYZ()->blockSignals(false);
                    }
                    v=(int)seed.y;
                    if(controls->getSliderXZ()->value()!=v)
                    {
                        g2d = multiWidget->mitkWidget3->GetRenderer()->GetCurrentWorldGeometry2D();
                        pg = dynamic_cast<const mitk::PlaneGeometry*>(g2d);
                        pv = pg->GetPlaneView();
                        pv.point.y = v;
                        plane  = mitk::PlaneGeometry::New();
                        plane->SetPlaneView(pv);
                        multiWidget->mitkWidget3->GetRenderer()->SetWorldGeometry(plane);
                        controls->getSliderXZ()->blockSignals(true);
                        controls->getSliderXZ()->setValue(v);
                        controls->getSliderXZ()->blockSignals(false);
                    }

                    v=(int)seed.z;
                    if(controls->getSliderXY()->value()!=v)
                    {
                        g2d = multiWidget->mitkWidget1->GetRenderer()->GetCurrentWorldGeometry2D();
                        pg = dynamic_cast<const mitk::PlaneGeometry*>(g2d);
                        pv = pg->GetPlaneView();
                        pv.point.z = v;
                        plane = mitk::PlaneGeometry::New();
                        plane->SetPlaneView(pv);
                        multiWidget->mitkWidget1->GetRenderer()->SetWorldGeometry(plane);
                        controls->getSliderXY()->blockSignals(true);
                        controls->getSliderXY()->setValue(v);
                        controls->getSliderXY()->blockSignals(false);
                    }
                    multiWidget->updateMitkWidgets();
                    ok = true;
                }
                break;
            case mitk::OpNOTHING:
                break;
            default:
                ;
        }
    }
    mitk::DisplayCoordinateOperation* dcOperation=dynamic_cast<mitk::DisplayCoordinateOperation*>(operation);
    if( dcOperation != NULL )
    {
    /****ZOOM & MOVE of the whole volume****/
        mitk::BaseRenderer* renderer = dcOperation->GetRenderer();
        if( renderer == NULL )
            return;
        switch (operation->GetOperationType())
        {
            case mitk::OpMOVE :
                {
                    renderer->GetDisplayGeometry()->MoveBy(dcOperation->GetLastToCurrentDisplayVector()*(-1.0));
                    renderer->GetRenderWindow()->Update();
                    ok = true;
                }
                break;
            case mitk::OpZOOM :
                {
                    float distance = dcOperation->GetLastToCurrentDisplayVector().y;
                    distance = (distance > 0 ? 1 : (distance < 0 ? -1 : 0));
                    float factor= 1.0 + distance * 0.05;
                    renderer->GetDisplayGeometry()->Zoom(factor, dcOperation->GetStartDisplayCoordinate());
                    renderer->GetRenderWindow()->Update();
                    ok = true;
                }
                break;
            default:
                ;
        }
    }
}
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: AccessibleSlideSorterObject.cxx,v $
 *
 *  $Revision: 1.8 $
 *
 *  last change: $Author: ihi $ $Date: 2006-11-14 14:23:53 $
 *
 *  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_sd.hxx"

#include "AccessibleSlideSorterObject.hxx"

#include "controller/SlideSorterController.hxx"
#include "controller/SlsPageSelector.hxx"
#include "controller/SlsFocusManager.hxx"
#include "model/SlideSorterModel.hxx"
#include "model/SlsPageDescriptor.hxx"
#include "view/SlideSorterView.hxx"

#ifndef _COM_SUN_STAR_ACCESSIBILITY_ACCESSIBLEROLE_HPP_
#include <com/sun/star/accessibility/AccessibleRole.hpp>
#endif
#ifndef _COM_SUN_STAR_ACCESSIBILITY_ACCESSIBLESTATETYPE_HPP_
#include <com/sun/star/accessibility/AccessibleStateType.hpp>
#endif
#ifndef COMPHELPER_ACCESSIBLE_EVENT_NOTIFIER
#include <comphelper/accessibleeventnotifier.hxx>
#endif
#include <unotools/accessiblestatesethelper.hxx>

#include "sdpage.hxx"
#include "sdresid.hxx"

#ifndef _SV_SVAPP_HXX
#include <vcl/svapp.hxx>
#endif

#include "glob.hrc"

using ::rtl::OUString;
using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::accessibility;

namespace accessibility {

AccessibleSlideSorterObject::AccessibleSlideSorterObject(
    const Reference<XAccessible>& rxParent,
    ::sd::slidesorter::controller::SlideSorterController& rSlideSorterController,
    sal_uInt16 nPageNumber)
    : AccessibleSlideSorterObjectBase(::sd::MutexOwner::maMutex),
      mxParent(rxParent),
      mnPageNumber(nPageNumber),
      mrSlideSorterController(rSlideSorterController),
      mnClientId(0)
{
}

AccessibleSlideSorterObject::~AccessibleSlideSorterObject (void)
{
    if ( ! IsDisposed())
        dispose();
}

sal_uInt16 AccessibleSlideSorterObject::GetPageNumber (void) const
{
    return mnPageNumber;
}

void AccessibleSlideSorterObject::FireAccessibleEvent (
    short nEventId,
    const uno::Any& rOldValue,
    const uno::Any& rNewValue)
{
    if (mnClientId != 0)
    {
        AccessibleEventObject aEventObject;

        aEventObject.Source = Reference<XWeak>(this);
        aEventObject.EventId = nEventId;
        aEventObject.NewValue = rNewValue;
        aEventObject.OldValue = rOldValue;

        comphelper::AccessibleEventNotifier::addEvent(mnClientId, aEventObject);
    }
}

void SAL_CALL AccessibleSlideSorterObject::disposing (void)
{
    const vos::OGuard aSolarGuard (Application::GetSolarMutex());

    // Send a disposing to all listeners.
    if (mnClientId != 0)
    {
        comphelper::AccessibleEventNotifier::revokeClientNotifyDisposing(mnClientId, *this);
        mnClientId =  0;
    }
}

//===== XAccessible ===========================================================

Reference<XAccessibleContext> SAL_CALL
    AccessibleSlideSorterObject::getAccessibleContext (void)
    throw (uno::RuntimeException)
{
    ThrowIfDisposed();
    return this;
}

//===== XAccessibleContext ====================================================

sal_Int32 SAL_CALL AccessibleSlideSorterObject::getAccessibleChildCount (void)
    throw (uno::RuntimeException)
{
    ThrowIfDisposed();
    return 0;
}

Reference<XAccessible> SAL_CALL AccessibleSlideSorterObject::getAccessibleChild (sal_Int32 i)
    throw (lang::IndexOutOfBoundsException, RuntimeException)
{
    ThrowIfDisposed();
    throw lang::IndexOutOfBoundsException();
    return Reference<XAccessible>();
}

Reference<XAccessible> SAL_CALL AccessibleSlideSorterObject::getAccessibleParent (void)
    throw (uno::RuntimeException)
{
    ThrowIfDisposed();
    return mxParent;
}

sal_Int32 SAL_CALL AccessibleSlideSorterObject::getAccessibleIndexInParent()
    throw (uno::RuntimeException)
{
    ThrowIfDisposed();
    const vos::OGuard aSolarGuard (Application::GetSolarMutex());
    sal_Int32 nIndexInParent(-1);

    if (mxParent.is())
    {
        Reference<XAccessibleContext> xParentContext (mxParent->getAccessibleContext());
        if (xParentContext.is())
        {
            sal_Int32 nChildCount (xParentContext->getAccessibleChildCount());
            for (sal_Int32 i=0; i<nChildCount; ++i)
                if (xParentContext->getAccessibleChild(i).get()
                    == static_cast<XAccessible*>(this))
                {
                    nIndexInParent = i;
                    break;
                }
        }
    }

    return nIndexInParent;
}

sal_Int16 SAL_CALL AccessibleSlideSorterObject::getAccessibleRole (void)
    throw (uno::RuntimeException)
{
    ThrowIfDisposed();
    static sal_Int16 nRole = AccessibleRole::LIST_ITEM;
    return nRole;
}

::rtl::OUString SAL_CALL AccessibleSlideSorterObject::getAccessibleDescription (void)
    throw (uno::RuntimeException)
{
    ThrowIfDisposed();
    return String(SdResId(STR_PAGE));
}

::rtl::OUString SAL_CALL AccessibleSlideSorterObject::getAccessibleName (void)
    throw (uno::RuntimeException)
{
    ThrowIfDisposed();
    const vos::OGuard aSolarGuard (Application::GetSolarMutex());

    SdPage* pPage = GetPage();
    if (pPage != NULL)
        return pPage->GetName();
    else
        return String();
}

Reference<XAccessibleRelationSet> SAL_CALL
    AccessibleSlideSorterObject::getAccessibleRelationSet (void)
    throw (uno::RuntimeException)
{
    ThrowIfDisposed();
    return Reference<XAccessibleRelationSet>();
}

Reference<XAccessibleStateSet> SAL_CALL
    AccessibleSlideSorterObject::getAccessibleStateSet (void)
    throw (uno::RuntimeException)
{
    ThrowIfDisposed();
    const vos::OGuard aSolarGuard (Application::GetSolarMutex());
    ::utl::AccessibleStateSetHelper* pStateSet = new ::utl::AccessibleStateSetHelper();

    if (mxParent.is())
    {
        // SELECTABLE
        pStateSet->AddState(AccessibleStateType::SELECTABLE);

        // SELECTED
        if (mrSlideSorterController.GetPageSelector().IsPageSelected(mnPageNumber))
            pStateSet->AddState(AccessibleStateType::SELECTED);

        // FOCUSABLE
        pStateSet->AddState(AccessibleStateType::FOCUSABLE);

        // FOCUSED
        if (mrSlideSorterController.GetFocusManager().GetFocusedPageIndex() == mnPageNumber)
            if (mrSlideSorterController.GetFocusManager().IsFocusShowing())
                pStateSet->AddState(AccessibleStateType::FOCUSED);

        pStateSet->AddState(AccessibleStateType::ENABLED);
        pStateSet->AddState(AccessibleStateType::VISIBLE);
        pStateSet->AddState(AccessibleStateType::SHOWING);
        pStateSet->AddState(AccessibleStateType::ACTIVE);
    }

    return pStateSet;
}

lang::Locale SAL_CALL AccessibleSlideSorterObject::getLocale (void)
    throw (IllegalAccessibleComponentStateException,
        RuntimeException)
{
    ThrowIfDisposed();
    // Delegate request to parent.
    if (mxParent.is())
    {
        Reference<XAccessibleContext> xParentContext (mxParent->getAccessibleContext());
        if (xParentContext.is())
            return xParentContext->getLocale ();
    }

    //  No locale and no parent.  Therefore throw exception to indicate this
    //  cluelessness.
    throw IllegalAccessibleComponentStateException();
}

//===== XAccessibleEventBroadcaster ===========================================

void SAL_CALL AccessibleSlideSorterObject::addEventListener(
    const Reference<XAccessibleEventListener>& rxListener)
    throw (RuntimeException)
{
    if (rxListener.is())
    {
        const osl::MutexGuard aGuard(maMutex);

        if (IsDisposed())
        {
            uno::Reference<uno::XInterface> x ((lang::XComponent *)this, uno::UNO_QUERY);
            rxListener->disposing (lang::EventObject (x));
        }
        else
        {
            if (mnClientId == 0)
                mnClientId = comphelper::AccessibleEventNotifier::registerClient();
            comphelper::AccessibleEventNotifier::addEventListener(mnClientId, rxListener);
        }
    }
}

void SAL_CALL AccessibleSlideSorterObject::removeEventListener(
    const Reference<XAccessibleEventListener>& rxListener)
    throw (uno::RuntimeException)
{
    ThrowIfDisposed();
    if (rxListener.is())
    {
        const osl::MutexGuard aGuard(maMutex);

        sal_Int32 nListenerCount = comphelper::AccessibleEventNotifier::removeEventListener( mnClientId, rxListener );
        if ( !nListenerCount )
        {
            // no listeners anymore
            // -> revoke ourself. This may lead to the notifier thread dying (if we were the last client),
            // and at least to us not firing any events anymore, in case somebody calls
            // NotifyAccessibleEvent, again
            comphelper::AccessibleEventNotifier::revokeClient( mnClientId );
            mnClientId = 0;
        }
    }
}

//===== XAccessibleComponent ==================================================

sal_Bool SAL_CALL AccessibleSlideSorterObject::containsPoint(const awt::Point& aPoint)
    throw (uno::RuntimeException)
{
    ThrowIfDisposed();
    const awt::Size aSize (getSize());
    return (aPoint.X >= 0)
        && (aPoint.X < aSize.Width)
        && (aPoint.Y >= 0)
        && (aPoint.Y < aSize.Height);
}

Reference<XAccessible> SAL_CALL
    AccessibleSlideSorterObject::getAccessibleAtPoint(const awt::Point& aPoint)
    throw (uno::RuntimeException)
{
    return NULL;
}

awt::Rectangle SAL_CALL AccessibleSlideSorterObject::getBounds (void)
    throw (RuntimeException)
{
    const vos::OGuard aSolarGuard( Application::GetSolarMutex() );

    Rectangle aBBox (mrSlideSorterController.GetView().GetPageBoundingBox (
        mnPageNumber,
        ::sd::slidesorter::view::SlideSorterView::CS_SCREEN,
        ::sd::slidesorter::view::SlideSorterView::BBT_INFO));

    if (mxParent.is())
    {
        Reference<XAccessibleComponent> xParentComponent(mxParent->getAccessibleContext(), UNO_QUERY);
        if (xParentComponent.is())
        {
            awt::Rectangle aParentBBox (xParentComponent->getBounds());
            aBBox.Intersection(Rectangle(
                aParentBBox.X,
                aParentBBox.Y,
                aParentBBox.Width,
                aParentBBox.Height));
        }
    }

    return awt::Rectangle(
        aBBox.Left(),
        aBBox.Top(),
        aBBox.GetWidth(),
        aBBox.GetHeight());
}

awt::Point SAL_CALL AccessibleSlideSorterObject::getLocation ()
    throw (RuntimeException)
{
    const awt::Rectangle aBBox (getBounds());
    return awt::Point(aBBox.X, aBBox.Y);
}

awt::Point SAL_CALL AccessibleSlideSorterObject::getLocationOnScreen (void)
    throw (RuntimeException)
{
    const vos::OGuard aSolarGuard( Application::GetSolarMutex() );

    awt::Point aLocation (getLocation());

    if (mxParent.is())
    {
        Reference<XAccessibleComponent> xParentComponent(mxParent->getAccessibleContext(),UNO_QUERY);
        if (xParentComponent.is())
        {
            const awt::Point aParentLocationOnScreen(xParentComponent->getLocationOnScreen());
            aLocation.X += aParentLocationOnScreen.X;
            aLocation.Y += aParentLocationOnScreen.Y;
        }
    }

    return aLocation;
}

awt::Size SAL_CALL AccessibleSlideSorterObject::getSize (void)
    throw (RuntimeException)
{
    const awt::Rectangle aBBox (getBounds());
    return awt::Size(aBBox.Width,aBBox.Height);
}

void SAL_CALL AccessibleSlideSorterObject::grabFocus (void)
    throw (RuntimeException)
{
    // nothing to do
}

sal_Int32 SAL_CALL AccessibleSlideSorterObject::getForeground (void)
    throw (::com::sun::star::uno::RuntimeException)
{
    svtools::ColorConfig aColorConfig;
    UINT32 nColor = aColorConfig.GetColorValue( svtools::FONTCOLOR ).nColor;
    return static_cast<sal_Int32>(nColor);
}

sal_Int32 SAL_CALL AccessibleSlideSorterObject::getBackground (void)
    throw (::com::sun::star::uno::RuntimeException)
{
    UINT32 nColor = Application::GetSettings().GetStyleSettings().GetWindowColor().GetColor();
    return static_cast<sal_Int32>(nColor);
}

//=====  XServiceInfo  ========================================================

::rtl::OUString SAL_CALL
       AccessibleSlideSorterObject::getImplementationName (void)
    throw (::com::sun::star::uno::RuntimeException)
{
    return OUString(RTL_CONSTASCII_USTRINGPARAM("AccessibleSlideSorterObject"));
}

sal_Bool SAL_CALL
     AccessibleSlideSorterObject::supportsService (const OUString& sServiceName)
    throw (::com::sun::star::uno::RuntimeException)
{
    //  Iterate over all supported service names and return true if on of them
    //  matches the given name.
    uno::Sequence< ::rtl::OUString> aSupportedServices (
        getSupportedServiceNames ());
    for (int i=0; i<aSupportedServices.getLength(); i++)
        if (sServiceName == aSupportedServices[i])
            return sal_True;
    return sal_False;
}

uno::Sequence< ::rtl::OUString> SAL_CALL
       AccessibleSlideSorterObject::getSupportedServiceNames (void)
    throw (::com::sun::star::uno::RuntimeException)
{
    static const OUString sServiceNames[2] = {
        OUString(RTL_CONSTASCII_USTRINGPARAM(
            "com.sun.star.accessibility.Accessible")),
        OUString(RTL_CONSTASCII_USTRINGPARAM(
            "com.sun.star.accessibility.AccessibleContext"))
    };
    return uno::Sequence<OUString> (sServiceNames, 2);
}

void AccessibleSlideSorterObject::ThrowIfDisposed (void)
    throw (lang::DisposedException)
{
    if (rBHelper.bDisposed || rBHelper.bInDispose)
    {
        OSL_TRACE ("Calling disposed object. Throwing exception:");
        throw lang::DisposedException (
            OUString(RTL_CONSTASCII_USTRINGPARAM("object has been already disposed")),
            static_cast<uno::XWeak*>(this));
    }
}

sal_Bool AccessibleSlideSorterObject::IsDisposed (void)
{
    return (rBHelper.bDisposed || rBHelper.bInDispose);
}

SdPage* AccessibleSlideSorterObject::GetPage (void) const
{
    ::sd::slidesorter::model::SharedPageDescriptor pDescriptor(
        mrSlideSorterController.GetModel().GetPageDescriptor(mnPageNumber));
    if (pDescriptor.get() != NULL)
        return pDescriptor->GetPage();
    else
        return NULL;
}

} // end of namespace ::accessibility
<commit_msg>INTEGRATION: CWS sdwarningsbegone (1.7.36); FILE MERGED 2006/11/22 15:00:03 cl 1.7.36.2: RESYNC: (1.7-1.8); FILE MERGED 2006/11/22 12:41:40 cl 1.7.36.1: #i69285# warning free code changes for unxlngi6.pro<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: AccessibleSlideSorterObject.cxx,v $
 *
 *  $Revision: 1.9 $
 *
 *  last change: $Author: kz $ $Date: 2006-12-12 16:49:05 $
 *
 *  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_sd.hxx"

#include "AccessibleSlideSorterObject.hxx"

#include "controller/SlideSorterController.hxx"
#include "controller/SlsPageSelector.hxx"
#include "controller/SlsFocusManager.hxx"
#include "model/SlideSorterModel.hxx"
#include "model/SlsPageDescriptor.hxx"
#include "view/SlideSorterView.hxx"

#ifndef _COM_SUN_STAR_ACCESSIBILITY_ACCESSIBLEROLE_HPP_
#include <com/sun/star/accessibility/AccessibleRole.hpp>
#endif
#ifndef _COM_SUN_STAR_ACCESSIBILITY_ACCESSIBLESTATETYPE_HPP_
#include <com/sun/star/accessibility/AccessibleStateType.hpp>
#endif
#ifndef COMPHELPER_ACCESSIBLE_EVENT_NOTIFIER
#include <comphelper/accessibleeventnotifier.hxx>
#endif
#include <unotools/accessiblestatesethelper.hxx>

#include "sdpage.hxx"
#include "sdresid.hxx"

#ifndef _SV_SVAPP_HXX
#include <vcl/svapp.hxx>
#endif

#include "glob.hrc"

using ::rtl::OUString;
using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::accessibility;

namespace accessibility {

AccessibleSlideSorterObject::AccessibleSlideSorterObject(
    const Reference<XAccessible>& rxParent,
    ::sd::slidesorter::controller::SlideSorterController& rSlideSorterController,
    sal_uInt16 nPageNumber)
    : AccessibleSlideSorterObjectBase(::sd::MutexOwner::maMutex),
      mxParent(rxParent),
      mnPageNumber(nPageNumber),
      mrSlideSorterController(rSlideSorterController),
      mnClientId(0)
{
}

AccessibleSlideSorterObject::~AccessibleSlideSorterObject (void)
{
    if ( ! IsDisposed())
        dispose();
}

sal_uInt16 AccessibleSlideSorterObject::GetPageNumber (void) const
{
    return mnPageNumber;
}

void AccessibleSlideSorterObject::FireAccessibleEvent (
    short nEventId,
    const uno::Any& rOldValue,
    const uno::Any& rNewValue)
{
    if (mnClientId != 0)
    {
        AccessibleEventObject aEventObject;

        aEventObject.Source = Reference<XWeak>(this);
        aEventObject.EventId = nEventId;
        aEventObject.NewValue = rNewValue;
        aEventObject.OldValue = rOldValue;

        comphelper::AccessibleEventNotifier::addEvent(mnClientId, aEventObject);
    }
}

void SAL_CALL AccessibleSlideSorterObject::disposing (void)
{
    const vos::OGuard aSolarGuard (Application::GetSolarMutex());

    // Send a disposing to all listeners.
    if (mnClientId != 0)
    {
        comphelper::AccessibleEventNotifier::revokeClientNotifyDisposing(mnClientId, *this);
        mnClientId =  0;
    }
}

//===== XAccessible ===========================================================

Reference<XAccessibleContext> SAL_CALL
    AccessibleSlideSorterObject::getAccessibleContext (void)
    throw (uno::RuntimeException)
{
    ThrowIfDisposed();
    return this;
}

//===== XAccessibleContext ====================================================

sal_Int32 SAL_CALL AccessibleSlideSorterObject::getAccessibleChildCount (void)
    throw (uno::RuntimeException)
{
    ThrowIfDisposed();
    return 0;
}

Reference<XAccessible> SAL_CALL AccessibleSlideSorterObject::getAccessibleChild (sal_Int32 )
    throw (lang::IndexOutOfBoundsException, RuntimeException)
{
    ThrowIfDisposed();
    throw lang::IndexOutOfBoundsException();
}

Reference<XAccessible> SAL_CALL AccessibleSlideSorterObject::getAccessibleParent (void)
    throw (uno::RuntimeException)
{
    ThrowIfDisposed();
    return mxParent;
}

sal_Int32 SAL_CALL AccessibleSlideSorterObject::getAccessibleIndexInParent()
    throw (uno::RuntimeException)
{
    ThrowIfDisposed();
    const vos::OGuard aSolarGuard (Application::GetSolarMutex());
    sal_Int32 nIndexInParent(-1);

    if (mxParent.is())
    {
        Reference<XAccessibleContext> xParentContext (mxParent->getAccessibleContext());
        if (xParentContext.is())
        {
            sal_Int32 nChildCount (xParentContext->getAccessibleChildCount());
            for (sal_Int32 i=0; i<nChildCount; ++i)
                if (xParentContext->getAccessibleChild(i).get()
                    == static_cast<XAccessible*>(this))
                {
                    nIndexInParent = i;
                    break;
                }
        }
    }

    return nIndexInParent;
}

sal_Int16 SAL_CALL AccessibleSlideSorterObject::getAccessibleRole (void)
    throw (uno::RuntimeException)
{
    ThrowIfDisposed();
    static sal_Int16 nRole = AccessibleRole::LIST_ITEM;
    return nRole;
}

::rtl::OUString SAL_CALL AccessibleSlideSorterObject::getAccessibleDescription (void)
    throw (uno::RuntimeException)
{
    ThrowIfDisposed();
    return String(SdResId(STR_PAGE));
}

::rtl::OUString SAL_CALL AccessibleSlideSorterObject::getAccessibleName (void)
    throw (uno::RuntimeException)
{
    ThrowIfDisposed();
    const vos::OGuard aSolarGuard (Application::GetSolarMutex());

    SdPage* pPage = GetPage();
    if (pPage != NULL)
        return pPage->GetName();
    else
        return String();
}

Reference<XAccessibleRelationSet> SAL_CALL
    AccessibleSlideSorterObject::getAccessibleRelationSet (void)
    throw (uno::RuntimeException)
{
    ThrowIfDisposed();
    return Reference<XAccessibleRelationSet>();
}

Reference<XAccessibleStateSet> SAL_CALL
    AccessibleSlideSorterObject::getAccessibleStateSet (void)
    throw (uno::RuntimeException)
{
    ThrowIfDisposed();
    const vos::OGuard aSolarGuard (Application::GetSolarMutex());
    ::utl::AccessibleStateSetHelper* pStateSet = new ::utl::AccessibleStateSetHelper();

    if (mxParent.is())
    {
        // SELECTABLE
        pStateSet->AddState(AccessibleStateType::SELECTABLE);

        // SELECTED
        if (mrSlideSorterController.GetPageSelector().IsPageSelected(mnPageNumber))
            pStateSet->AddState(AccessibleStateType::SELECTED);

        // FOCUSABLE
        pStateSet->AddState(AccessibleStateType::FOCUSABLE);

        // FOCUSED
        if (mrSlideSorterController.GetFocusManager().GetFocusedPageIndex() == mnPageNumber)
            if (mrSlideSorterController.GetFocusManager().IsFocusShowing())
                pStateSet->AddState(AccessibleStateType::FOCUSED);

        pStateSet->AddState(AccessibleStateType::ENABLED);
        pStateSet->AddState(AccessibleStateType::VISIBLE);
        pStateSet->AddState(AccessibleStateType::SHOWING);
        pStateSet->AddState(AccessibleStateType::ACTIVE);
    }

    return pStateSet;
}

lang::Locale SAL_CALL AccessibleSlideSorterObject::getLocale (void)
    throw (IllegalAccessibleComponentStateException,
        RuntimeException)
{
    ThrowIfDisposed();
    // Delegate request to parent.
    if (mxParent.is())
    {
        Reference<XAccessibleContext> xParentContext (mxParent->getAccessibleContext());
        if (xParentContext.is())
            return xParentContext->getLocale ();
    }

    //  No locale and no parent.  Therefore throw exception to indicate this
    //  cluelessness.
    throw IllegalAccessibleComponentStateException();
}

//===== XAccessibleEventBroadcaster ===========================================

void SAL_CALL AccessibleSlideSorterObject::addEventListener(
    const Reference<XAccessibleEventListener>& rxListener)
    throw (RuntimeException)
{
    if (rxListener.is())
    {
        const osl::MutexGuard aGuard(maMutex);

        if (IsDisposed())
        {
            uno::Reference<uno::XInterface> x ((lang::XComponent *)this, uno::UNO_QUERY);
            rxListener->disposing (lang::EventObject (x));
        }
        else
        {
            if (mnClientId == 0)
                mnClientId = comphelper::AccessibleEventNotifier::registerClient();
            comphelper::AccessibleEventNotifier::addEventListener(mnClientId, rxListener);
        }
    }
}

void SAL_CALL AccessibleSlideSorterObject::removeEventListener(
    const Reference<XAccessibleEventListener>& rxListener)
    throw (uno::RuntimeException)
{
    ThrowIfDisposed();
    if (rxListener.is())
    {
        const osl::MutexGuard aGuard(maMutex);

        sal_Int32 nListenerCount = comphelper::AccessibleEventNotifier::removeEventListener( mnClientId, rxListener );
        if ( !nListenerCount )
        {
            // no listeners anymore
            // -> revoke ourself. This may lead to the notifier thread dying (if we were the last client),
            // and at least to us not firing any events anymore, in case somebody calls
            // NotifyAccessibleEvent, again
            comphelper::AccessibleEventNotifier::revokeClient( mnClientId );
            mnClientId = 0;
        }
    }
}

//===== XAccessibleComponent ==================================================

sal_Bool SAL_CALL AccessibleSlideSorterObject::containsPoint(const awt::Point& aPoint)
    throw (uno::RuntimeException)
{
    ThrowIfDisposed();
    const awt::Size aSize (getSize());
    return (aPoint.X >= 0)
        && (aPoint.X < aSize.Width)
        && (aPoint.Y >= 0)
        && (aPoint.Y < aSize.Height);
}

Reference<XAccessible> SAL_CALL
    AccessibleSlideSorterObject::getAccessibleAtPoint(const awt::Point& )
    throw (uno::RuntimeException)
{
    return NULL;
}

awt::Rectangle SAL_CALL AccessibleSlideSorterObject::getBounds (void)
    throw (RuntimeException)
{
    const vos::OGuard aSolarGuard( Application::GetSolarMutex() );

    Rectangle aBBox (mrSlideSorterController.GetView().GetPageBoundingBox (
        mnPageNumber,
        ::sd::slidesorter::view::SlideSorterView::CS_SCREEN,
        ::sd::slidesorter::view::SlideSorterView::BBT_INFO));

    if (mxParent.is())
    {
        Reference<XAccessibleComponent> xParentComponent(mxParent->getAccessibleContext(), UNO_QUERY);
        if (xParentComponent.is())
        {
            awt::Rectangle aParentBBox (xParentComponent->getBounds());
            aBBox.Intersection(Rectangle(
                aParentBBox.X,
                aParentBBox.Y,
                aParentBBox.Width,
                aParentBBox.Height));
        }
    }

    return awt::Rectangle(
        aBBox.Left(),
        aBBox.Top(),
        aBBox.GetWidth(),
        aBBox.GetHeight());
}

awt::Point SAL_CALL AccessibleSlideSorterObject::getLocation ()
    throw (RuntimeException)
{
    const awt::Rectangle aBBox (getBounds());
    return awt::Point(aBBox.X, aBBox.Y);
}

awt::Point SAL_CALL AccessibleSlideSorterObject::getLocationOnScreen (void)
    throw (RuntimeException)
{
    const vos::OGuard aSolarGuard( Application::GetSolarMutex() );

    awt::Point aLocation (getLocation());

    if (mxParent.is())
    {
        Reference<XAccessibleComponent> xParentComponent(mxParent->getAccessibleContext(),UNO_QUERY);
        if (xParentComponent.is())
        {
            const awt::Point aParentLocationOnScreen(xParentComponent->getLocationOnScreen());
            aLocation.X += aParentLocationOnScreen.X;
            aLocation.Y += aParentLocationOnScreen.Y;
        }
    }

    return aLocation;
}

awt::Size SAL_CALL AccessibleSlideSorterObject::getSize (void)
    throw (RuntimeException)
{
    const awt::Rectangle aBBox (getBounds());
    return awt::Size(aBBox.Width,aBBox.Height);
}

void SAL_CALL AccessibleSlideSorterObject::grabFocus (void)
    throw (RuntimeException)
{
    // nothing to do
}

sal_Int32 SAL_CALL AccessibleSlideSorterObject::getForeground (void)
    throw (::com::sun::star::uno::RuntimeException)
{
    svtools::ColorConfig aColorConfig;
    UINT32 nColor = aColorConfig.GetColorValue( svtools::FONTCOLOR ).nColor;
    return static_cast<sal_Int32>(nColor);
}

sal_Int32 SAL_CALL AccessibleSlideSorterObject::getBackground (void)
    throw (::com::sun::star::uno::RuntimeException)
{
    UINT32 nColor = Application::GetSettings().GetStyleSettings().GetWindowColor().GetColor();
    return static_cast<sal_Int32>(nColor);
}

//=====  XServiceInfo  ========================================================

::rtl::OUString SAL_CALL
       AccessibleSlideSorterObject::getImplementationName (void)
    throw (::com::sun::star::uno::RuntimeException)
{
    return OUString(RTL_CONSTASCII_USTRINGPARAM("AccessibleSlideSorterObject"));
}

sal_Bool SAL_CALL
     AccessibleSlideSorterObject::supportsService (const OUString& sServiceName)
    throw (::com::sun::star::uno::RuntimeException)
{
    //  Iterate over all supported service names and return true if on of them
    //  matches the given name.
    uno::Sequence< ::rtl::OUString> aSupportedServices (
        getSupportedServiceNames ());
    for (int i=0; i<aSupportedServices.getLength(); i++)
        if (sServiceName == aSupportedServices[i])
            return sal_True;
    return sal_False;
}

uno::Sequence< ::rtl::OUString> SAL_CALL
       AccessibleSlideSorterObject::getSupportedServiceNames (void)
    throw (::com::sun::star::uno::RuntimeException)
{
    static const OUString sServiceNames[2] = {
        OUString(RTL_CONSTASCII_USTRINGPARAM(
            "com.sun.star.accessibility.Accessible")),
        OUString(RTL_CONSTASCII_USTRINGPARAM(
            "com.sun.star.accessibility.AccessibleContext"))
    };
    return uno::Sequence<OUString> (sServiceNames, 2);
}

void AccessibleSlideSorterObject::ThrowIfDisposed (void)
    throw (lang::DisposedException)
{
    if (rBHelper.bDisposed || rBHelper.bInDispose)
    {
        OSL_TRACE ("Calling disposed object. Throwing exception:");
        throw lang::DisposedException (
            OUString(RTL_CONSTASCII_USTRINGPARAM("object has been already disposed")),
            static_cast<uno::XWeak*>(this));
    }
}

sal_Bool AccessibleSlideSorterObject::IsDisposed (void)
{
    return (rBHelper.bDisposed || rBHelper.bInDispose);
}

SdPage* AccessibleSlideSorterObject::GetPage (void) const
{
    ::sd::slidesorter::model::SharedPageDescriptor pDescriptor(
        mrSlideSorterController.GetModel().GetPageDescriptor(mnPageNumber));
    if (pDescriptor.get() != NULL)
        return pDescriptor->GetPage();
    else
        return NULL;
}

} // end of namespace ::accessibility
<|endoftext|>