<commit_before>/*********************************************************************
* Software License Agreement (BSD License)
*
*  Copyright (c) 2011, Willow Garage, Inc.
*  All rights reserved.
*
*  Redistribution and use in source and binary forms, with or without
*  modification, are permitted provided that the following conditions
*  are met:
*
*   * Redistributions of source code must retain the above copyright
*     notice, this list of conditions and the following disclaimer.
*   * Redistributions in binary form must reproduce the above
*     copyright notice, this list of conditions and the following
*     disclaimer in the documentation and/or other materials provided
*     with the distribution.
*   * Neither the name of the Willow Garage nor the names of its
*     contributors may be used to endorse or promote products derived
*     from this software without specific prior written permission.
*
*  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
*  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
*  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
*  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
*  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
*  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
*  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
*  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
*  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
*  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
*  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
*  POSSIBILITY OF SUCH DAMAGE.
*********************************************************************/

/* Author: Ioan Sucan */

#include <planning_models/transforms.h>
#include <ros/console.h>

bool planning_models::quatFromMsg(const geometry_msgs::Quaternion &qmsg, Eigen::Quaterniond &q)
{
  q = Eigen::Quaterniond(qmsg.w, qmsg.x, qmsg.y, qmsg.z);
  double error = fabs(q.squaredNorm() - 1.0);
  if (error > 0.1)
  {
    ROS_ERROR("Quaternion is NOWHERE CLOSE TO NORMALIZED [x,y,z,w], [%.2f, %.2f, %.2f, %.2f]. Can't do much, returning identity.",
        qmsg.x, qmsg.y, qmsg.z, qmsg.w);
    q = Eigen::Quaterniond(1.0, 0.0, 0.0, 0.0);
    return false;
  }
  else if(error > 1e-3)
    q.normalize();

  return true;
}

bool planning_models::poseFromMsg(const geometry_msgs::Pose &tmsg, Eigen::Affine3d &t)
{
  Eigen::Quaterniond q; bool r = quatFromMsg(tmsg.orientation, q);
  t = Eigen::Affine3d(Eigen::Translation3d(tmsg.position.x, tmsg.position.y, tmsg.position.z)*q.toRotationMatrix());
  return r;
}

void planning_models::msgFromPose(const Eigen::Affine3d &t, geometry_msgs::Pose &tmsg)
{
  tmsg.position.x = t.translation().x(); tmsg.position.y = t.translation().y(); tmsg.position.z = t.translation().z();
  Eigen::Quaterniond q(t.rotation());
  tmsg.orientation.x = q.x(); tmsg.orientation.y = q.y(); tmsg.orientation.z = q.z(); tmsg.orientation.w = q.w();
}

void planning_models::msgFromPose(const Eigen::Affine3d &t, geometry_msgs::Transform &tmsg)
{
  tmsg.translation.x = t.translation().x(); tmsg.translation.y = t.translation().y(); tmsg.translation.z = t.translation().z();
  Eigen::Quaterniond q(t.rotation());
  tmsg.rotation.x = q.x(); tmsg.rotation.y = q.y(); tmsg.rotation.z = q.z(); tmsg.rotation.w = q.w();
}

planning_models::Transforms::Transforms(const std::string &target_frame) : target_frame_(target_frame)
{
  Eigen::Affine3d t;
  t.setIdentity();
  transforms_[target_frame_] = t;
}

planning_models::Transforms::Transforms(const Transforms &other) : target_frame_(other.target_frame_), transforms_(other.transforms_)
{
}

planning_models::Transforms::~Transforms(void)
{
}

const std::string& planning_models::Transforms::getTargetFrame(void) const
{
  return target_frame_;
}

const planning_models::EigenAffine3dMapType& planning_models::Transforms::getAllTransforms(void) const
{
  return transforms_;
}

bool planning_models::Transforms::isFixedFrame(const std::string &frame) const
{
  return transforms_.find(frame) != transforms_.end();
}

const Eigen::Affine3d& planning_models::Transforms::getTransform(const std::string &from_frame) const
{
  EigenAffine3dMapType::const_iterator it = transforms_.find(from_frame);
  if (it != transforms_.end())
    return it->second;
  ROS_ERROR_STREAM("Unable to transform from frame '" + from_frame + "' to frame '" + target_frame_ + "'");
  // return identity
  return transforms_.find(target_frame_)->second;
}

const Eigen::Affine3d& planning_models::Transforms::getTransform(const planning_models::KinematicState &kstate, const std::string &from_frame) const
{
  std::map<std::string, Eigen::Affine3d>::const_iterator it = transforms_.find(from_frame);
  if (it != transforms_.end())
    return it->second;
  if (kstate.getKinematicModel()->getModelFrame() != target_frame_)
    ROS_ERROR("Target frame is assumed to be '%s' but the model of the kinematic state places the robot in frame '%s'",
              target_frame_.c_str(), kstate.getKinematicModel()->getModelFrame().c_str());
  const Eigen::Affine3d *t = kstate.getFrameTransform(from_frame);
  if (t)
    return *t;
  else
    // return identity
    return transforms_.find(target_frame_)->second;
}

void planning_models::Transforms::transformVector3(const std::string &from_frame, const Eigen::Vector3d &v_in, Eigen::Vector3d &v_out) const
{
  v_out = getTransform(from_frame) * v_in;
}

void planning_models::Transforms::transformQuaternion(const std::string &from_frame, const Eigen::Quaterniond &q_in, Eigen::Quaterniond &q_out) const
{
  q_out = getTransform(from_frame).rotation() * q_in;
}

void planning_models::Transforms::transformRotationMatrix(const std::string &from_frame, const Eigen::Matrix3d &m_in, Eigen::Matrix3d &m_out) const
{
  m_out = getTransform(from_frame).rotation() * m_in;
}

void planning_models::Transforms::transformPose(const std::string &from_frame, const Eigen::Affine3d &t_in, Eigen::Affine3d &t_out) const
{
  t_out = getTransform(from_frame) * t_in;
}

// specify the kinematic state
void planning_models::Transforms::transformVector3(const planning_models::KinematicState &kstate,
                                                   const std::string &from_frame, const Eigen::Vector3d &v_in, Eigen::Vector3d &v_out) const
{
  v_out = getTransform(kstate, from_frame).rotation() * v_in;
}

void planning_models::Transforms::transformQuaternion(const planning_models::KinematicState &kstate,
                                                      const std::string &from_frame, const Eigen::Quaterniond &q_in, Eigen::Quaterniond &q_out) const
{
  q_out = getTransform(kstate, from_frame).rotation() * q_in;
}

void planning_models::Transforms::transformRotationMatrix(const planning_models::KinematicState &kstate,
                                                          const std::string &from_frame, const Eigen::Matrix3d &m_in, Eigen::Matrix3d &m_out) const
{
  m_out = getTransform(kstate, from_frame).rotation() * m_in;
}

void planning_models::Transforms::transformPose(const planning_models::KinematicState &kstate,
                                                const std::string &from_frame, const Eigen::Affine3d &t_in, Eigen::Affine3d &t_out) const
{
  t_out = getTransform(kstate, from_frame) * t_in;
}

void planning_models::Transforms::setTransform(const Eigen::Affine3d &t, const std::string &from_frame)
{
  transforms_[from_frame] = t;
}

void planning_models::Transforms::setTransform(const geometry_msgs::TransformStamped &transform)
{
  if (transform.child_frame_id.rfind(target_frame_) == transform.child_frame_id.length() - target_frame_.length())
  {
    Eigen::Translation3d o(transform.transform.translation.x, transform.transform.translation.y, transform.transform.translation.z);
    Eigen::Quaterniond q;
    quatFromMsg(transform.transform.rotation, q);
    setTransform(Eigen::Affine3d(o*q.toRotationMatrix()), transform.header.frame_id);
  } else {
    ROS_ERROR("Given transform is to frame '%s', but frame '%s' was expected.", transform.child_frame_id.c_str(), target_frame_.c_str());
  }
}

void planning_models::Transforms::setTransforms(const std::vector<geometry_msgs::TransformStamped> &transforms)
{
  for (std::size_t i = 0 ; i < transforms.size() ; ++i)
    setTransform(transforms[i]);
}

void planning_models::Transforms::getTransforms(std::vector<geometry_msgs::TransformStamped> &transforms) const
{
  transforms.resize(transforms_.size());
  std::size_t i = 0;
  for (EigenAffine3dMapType::const_iterator it = transforms_.begin() ; it != transforms_.end() ; ++it, ++i)
  {
    transforms[i].child_frame_id = target_frame_;
    transforms[i].header.frame_id = it->first;
    transforms[i].transform.translation.x = it->second.translation().x();
    transforms[i].transform.translation.y = it->second.translation().y();
    transforms[i].transform.translation.z = it->second.translation().z();
    Eigen::Quaterniond q(it->second.rotation());
    transforms[i].transform.rotation.x = q.x();
    transforms[i].transform.rotation.y = q.y();
    transforms[i].transform.rotation.z = q.z();
    transforms[i].transform.rotation.w = q.w();
  }
}
<commit_msg>tighter checks on quaternions<commit_after>/*********************************************************************
* Software License Agreement (BSD License)
*
*  Copyright (c) 2011, Willow Garage, Inc.
*  All rights reserved.
*
*  Redistribution and use in source and binary forms, with or without
*  modification, are permitted provided that the following conditions
*  are met:
*
*   * Redistributions of source code must retain the above copyright
*     notice, this list of conditions and the following disclaimer.
*   * Redistributions in binary form must reproduce the above
*     copyright notice, this list of conditions and the following
*     disclaimer in the documentation and/or other materials provided
*     with the distribution.
*   * Neither the name of the Willow Garage nor the names of its
*     contributors may be used to endorse or promote products derived
*     from this software without specific prior written permission.
*
*  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
*  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
*  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
*  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
*  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
*  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
*  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
*  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
*  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
*  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
*  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
*  POSSIBILITY OF SUCH DAMAGE.
*********************************************************************/

/* Author: Ioan Sucan */

#include <planning_models/transforms.h>
#include <ros/console.h>

bool planning_models::quatFromMsg(const geometry_msgs::Quaternion &qmsg, Eigen::Quaterniond &q)
{
  q = Eigen::Quaterniond(qmsg.w, qmsg.x, qmsg.y, qmsg.z);
  double error = fabs(q.squaredNorm() - 1.0);
  if (error > 0.05)
  {
    ROS_ERROR("Quaternion is NOWHERE CLOSE TO NORMALIZED [x,y,z,w], [%.2f, %.2f, %.2f, %.2f]. Can't do much, returning identity.",
        qmsg.x, qmsg.y, qmsg.z, qmsg.w);
    q = Eigen::Quaterniond(1.0, 0.0, 0.0, 0.0);
    return false;
  }
  else if(error > 1e-3)
    q.normalize();

  return true;
}

bool planning_models::poseFromMsg(const geometry_msgs::Pose &tmsg, Eigen::Affine3d &t)
{
  Eigen::Quaterniond q; bool r = quatFromMsg(tmsg.orientation, q);
  t = Eigen::Affine3d(Eigen::Translation3d(tmsg.position.x, tmsg.position.y, tmsg.position.z)*q.toRotationMatrix());
  return r;
}

void planning_models::msgFromPose(const Eigen::Affine3d &t, geometry_msgs::Pose &tmsg)
{
  tmsg.position.x = t.translation().x(); tmsg.position.y = t.translation().y(); tmsg.position.z = t.translation().z();
  Eigen::Quaterniond q(t.rotation());
  tmsg.orientation.x = q.x(); tmsg.orientation.y = q.y(); tmsg.orientation.z = q.z(); tmsg.orientation.w = q.w();
}

void planning_models::msgFromPose(const Eigen::Affine3d &t, geometry_msgs::Transform &tmsg)
{
  tmsg.translation.x = t.translation().x(); tmsg.translation.y = t.translation().y(); tmsg.translation.z = t.translation().z();
  Eigen::Quaterniond q(t.rotation());
  tmsg.rotation.x = q.x(); tmsg.rotation.y = q.y(); tmsg.rotation.z = q.z(); tmsg.rotation.w = q.w();
}

planning_models::Transforms::Transforms(const std::string &target_frame) : target_frame_(target_frame)
{
  Eigen::Affine3d t;
  t.setIdentity();
  transforms_[target_frame_] = t;
}

planning_models::Transforms::Transforms(const Transforms &other) : target_frame_(other.target_frame_), transforms_(other.transforms_)
{
}

planning_models::Transforms::~Transforms(void)
{
}

const std::string& planning_models::Transforms::getTargetFrame(void) const
{
  return target_frame_;
}

const planning_models::EigenAffine3dMapType& planning_models::Transforms::getAllTransforms(void) const
{
  return transforms_;
}

bool planning_models::Transforms::isFixedFrame(const std::string &frame) const
{
  return transforms_.find(frame) != transforms_.end();
}

const Eigen::Affine3d& planning_models::Transforms::getTransform(const std::string &from_frame) const
{
  EigenAffine3dMapType::const_iterator it = transforms_.find(from_frame);
  if (it != transforms_.end())
    return it->second;
  ROS_ERROR_STREAM("Unable to transform from frame '" + from_frame + "' to frame '" + target_frame_ + "'");
  // return identity
  return transforms_.find(target_frame_)->second;
}

const Eigen::Affine3d& planning_models::Transforms::getTransform(const planning_models::KinematicState &kstate, const std::string &from_frame) const
{
  std::map<std::string, Eigen::Affine3d>::const_iterator it = transforms_.find(from_frame);
  if (it != transforms_.end())
    return it->second;
  if (kstate.getKinematicModel()->getModelFrame() != target_frame_)
    ROS_ERROR("Target frame is assumed to be '%s' but the model of the kinematic state places the robot in frame '%s'",
              target_frame_.c_str(), kstate.getKinematicModel()->getModelFrame().c_str());
  const Eigen::Affine3d *t = kstate.getFrameTransform(from_frame);
  if (t)
    return *t;
  else
    // return identity
    return transforms_.find(target_frame_)->second;
}

void planning_models::Transforms::transformVector3(const std::string &from_frame, const Eigen::Vector3d &v_in, Eigen::Vector3d &v_out) const
{
  v_out = getTransform(from_frame) * v_in;
}

void planning_models::Transforms::transformQuaternion(const std::string &from_frame, const Eigen::Quaterniond &q_in, Eigen::Quaterniond &q_out) const
{
  q_out = getTransform(from_frame).rotation() * q_in;
}

void planning_models::Transforms::transformRotationMatrix(const std::string &from_frame, const Eigen::Matrix3d &m_in, Eigen::Matrix3d &m_out) const
{
  m_out = getTransform(from_frame).rotation() * m_in;
}

void planning_models::Transforms::transformPose(const std::string &from_frame, const Eigen::Affine3d &t_in, Eigen::Affine3d &t_out) const
{
  t_out = getTransform(from_frame) * t_in;
}

// specify the kinematic state
void planning_models::Transforms::transformVector3(const planning_models::KinematicState &kstate,
                                                   const std::string &from_frame, const Eigen::Vector3d &v_in, Eigen::Vector3d &v_out) const
{
  v_out = getTransform(kstate, from_frame).rotation() * v_in;
}

void planning_models::Transforms::transformQuaternion(const planning_models::KinematicState &kstate,
                                                      const std::string &from_frame, const Eigen::Quaterniond &q_in, Eigen::Quaterniond &q_out) const
{
  q_out = getTransform(kstate, from_frame).rotation() * q_in;
}

void planning_models::Transforms::transformRotationMatrix(const planning_models::KinematicState &kstate,
                                                          const std::string &from_frame, const Eigen::Matrix3d &m_in, Eigen::Matrix3d &m_out) const
{
  m_out = getTransform(kstate, from_frame).rotation() * m_in;
}

void planning_models::Transforms::transformPose(const planning_models::KinematicState &kstate,
                                                const std::string &from_frame, const Eigen::Affine3d &t_in, Eigen::Affine3d &t_out) const
{
  t_out = getTransform(kstate, from_frame) * t_in;
}

void planning_models::Transforms::setTransform(const Eigen::Affine3d &t, const std::string &from_frame)
{
  transforms_[from_frame] = t;
}

void planning_models::Transforms::setTransform(const geometry_msgs::TransformStamped &transform)
{
  if (transform.child_frame_id.rfind(target_frame_) == transform.child_frame_id.length() - target_frame_.length())
  {
    Eigen::Translation3d o(transform.transform.translation.x, transform.transform.translation.y, transform.transform.translation.z);
    Eigen::Quaterniond q;
    quatFromMsg(transform.transform.rotation, q);
    setTransform(Eigen::Affine3d(o*q.toRotationMatrix()), transform.header.frame_id);
  } else {
    ROS_ERROR("Given transform is to frame '%s', but frame '%s' was expected.", transform.child_frame_id.c_str(), target_frame_.c_str());
  }
}

void planning_models::Transforms::setTransforms(const std::vector<geometry_msgs::TransformStamped> &transforms)
{
  for (std::size_t i = 0 ; i < transforms.size() ; ++i)
    setTransform(transforms[i]);
}

void planning_models::Transforms::getTransforms(std::vector<geometry_msgs::TransformStamped> &transforms) const
{
  transforms.resize(transforms_.size());
  std::size_t i = 0;
  for (EigenAffine3dMapType::const_iterator it = transforms_.begin() ; it != transforms_.end() ; ++it, ++i)
  {
    transforms[i].child_frame_id = target_frame_;
    transforms[i].header.frame_id = it->first;
    transforms[i].transform.translation.x = it->second.translation().x();
    transforms[i].transform.translation.y = it->second.translation().y();
    transforms[i].transform.translation.z = it->second.translation().z();
    Eigen::Quaterniond q(it->second.rotation());
    transforms[i].transform.rotation.x = q.x();
    transforms[i].transform.rotation.y = q.y();
    transforms[i].transform.rotation.z = q.z();
    transforms[i].transform.rotation.w = q.w();
  }
}
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: decryptorimpl.cxx,v $
 *
 *  $Revision: 1.5 $
 *
 *  last change: $Author: obo $ $Date: 2006-09-16 14:36:56 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

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

#include "decryptorimpl.hxx"

#ifndef _COM_SUN_STAR_XML_CRYPTO_XXMLENCRYPTIONTEMPLATE_HPP_
#include <com/sun/star/xml/crypto/XXMLEncryptionTemplate.hpp>
#endif
#ifndef _COM_SUN_STAR_XML_WRAPPER_XXMLELEMENTWRAPPER_HPP_
#include <com/sun/star/xml/wrapper/XXMLElementWrapper.hpp>
#endif
#ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#endif

namespace cssu = com::sun::star::uno;
namespace cssl = com::sun::star::lang;
namespace cssxc = com::sun::star::xml::crypto;
namespace cssxw = com::sun::star::xml::wrapper;

#define SERVICE_NAME "com.sun.star.xml.crypto.sax.Decryptor"
#define IMPLEMENTATION_NAME "com.sun.star.xml.security.framework.DecryptorImpl"

#define DECLARE_ASCII( SASCIIVALUE )                                                                            \
    rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SASCIIVALUE ) )

DecryptorImpl::DecryptorImpl( const cssu::Reference< cssl::XMultiServiceFactory >& rxMSF)
{
    mxMSF = rxMSF;
}

DecryptorImpl::~DecryptorImpl()
{
}

bool DecryptorImpl::checkReady() const
/****** DecryptorImpl/checkReady *********************************************
 *
 *   NAME
 *  checkReady -- checks the conditions for the decryption.
 *
 *   SYNOPSIS
 *  bReady = checkReady( );
 *
 *   FUNCTION
 *  checks whether all following conditions are satisfied:
 *  1. the result listener is ready;
 *  2. the EncryptionEngine is ready.
 *
 *   INPUTS
 *  empty
 *
 *   RESULT
 *  bReady - true if all conditions are satisfied, false otherwise
 *
 *   HISTORY
 *  05.01.2004 -    implemented
 *
 *   AUTHOR
 *  Michael Mi
 *  Email: michael.mi@sun.com
 ******************************************************************************/
{
    return (m_xResultListener.is() && EncryptionEngine::checkReady());
}

void DecryptorImpl::notifyResultListener() const
    throw (cssu::Exception, cssu::RuntimeException)
/****** DecryptorImpl/notifyResultListener ***********************************
 *
 *   NAME
 *  notifyResultListener -- notifies the listener about the decryption
 *  result.
 *
 *   SYNOPSIS
 *  notifyResultListener( );
 *
 *   FUNCTION
 *  see NAME.
 *
 *   INPUTS
 *  empty
 *
 *   RESULT
 *  empty
 *
 *   HISTORY
 *  05.01.2004 -    implemented
 *
 *   AUTHOR
 *  Michael Mi
 *  Email: michael.mi@sun.com
 ******************************************************************************/
{
    cssu::Reference< cssxc::sax::XDecryptionResultListener >
        xDecryptionResultListener ( m_xResultListener , cssu::UNO_QUERY ) ;

    xDecryptionResultListener->decrypted(m_nSecurityId,m_nStatus);
}

void DecryptorImpl::startEngine( const cssu::Reference<
    cssxc::XXMLEncryptionTemplate >&
    xEncryptionTemplate)
    throw (cssu::Exception, cssu::RuntimeException)
/****** DecryptorImpl/startEngine ********************************************
 *
 *   NAME
 *  startEngine -- decrypts the encryption.
 *
 *   SYNOPSIS
 *  startEngine( xEncryptionTemplate );
 *
 *   FUNCTION
 *  decrypts the encryption element, then if succeeds, updates the link
 *  of old template element to the new encryption element in
 *  SAXEventKeeper.
 *
 *   INPUTS
 *  xEncryptionTemplate - the encryption template to be decrypted.
 *
 *   RESULT
 *  empty
 *
 *   HISTORY
 *  05.01.2004 -    implemented
 *
 *   AUTHOR
 *  Michael Mi
 *  Email: michael.mi@sun.com
 ******************************************************************************/
{
    cssu::Reference< cssxc::XXMLEncryptionTemplate > xResultTemplate;
    try
    {
        xResultTemplate = m_xXMLEncryption->decrypt(xEncryptionTemplate, m_xXMLSecurityContext);
        m_nStatus = xResultTemplate->getStatus();
    }
    catch( cssu::Exception& )
    {
        m_nStatus = cssxc::SecurityOperationStatus_RUNTIMEERROR_FAILED;
    }

    if (m_nStatus == cssxc::SecurityOperationStatus_OPERATION_SUCCEEDED)
    {
        cssu::Reference< cssxw::XXMLElementWrapper > xDecryptedElement
            = xResultTemplate->getTemplate();
        m_xSAXEventKeeper->setElement(m_nIdOfTemplateEC, xDecryptedElement);
    }
}

/* XDecryptionResultBroadcaster */
void SAL_CALL DecryptorImpl::addDecryptionResultListener( const cssu::Reference< cssxc::sax::XDecryptionResultListener >& listener )
        throw (cssu::Exception, cssu::RuntimeException)
{
    m_xResultListener = listener;
    tryToPerform();
}

void SAL_CALL DecryptorImpl::removeDecryptionResultListener( const cssu::Reference< cssxc::sax::XDecryptionResultListener >& listener )
        throw (cssu::RuntimeException)
{
}

/* XInitialization */
void SAL_CALL DecryptorImpl::initialize( const cssu::Sequence< cssu::Any >& aArguments )
    throw (cssu::Exception, cssu::RuntimeException)
{
    sal_Int32 nLength = aArguments.getLength();
    OSL_ASSERT(nLength == 5);

    rtl::OUString ouTempString;

    aArguments[0] >>= ouTempString;
    m_nSecurityId = ouTempString.toInt32();
    aArguments[1] >>= m_xSAXEventKeeper;
    aArguments[2] >>= ouTempString;
    m_nIdOfTemplateEC = ouTempString.toInt32();
    aArguments[3] >>= m_xXMLSecurityContext;
    aArguments[4] >>= m_xXMLEncryption;
}

rtl::OUString DecryptorImpl_getImplementationName ()
    throw (cssu::RuntimeException)
{
    return rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM ( IMPLEMENTATION_NAME ) );
}

sal_Bool SAL_CALL DecryptorImpl_supportsService( const rtl::OUString& ServiceName )
    throw (cssu::RuntimeException)
{
    return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SERVICE_NAME ));
}

cssu::Sequence< rtl::OUString > SAL_CALL DecryptorImpl_getSupportedServiceNames(  )
    throw (cssu::RuntimeException)
{
    cssu::Sequence < rtl::OUString > aRet(1);
    rtl::OUString* pArray = aRet.getArray();
    pArray[0] =  rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME ) );
    return aRet;
}
#undef SERVICE_NAME

cssu::Reference< cssu::XInterface > SAL_CALL DecryptorImpl_createInstance( const cssu::Reference< cssl::XMultiServiceFactory >& rSMgr)
    throw( cssu::Exception )
{
    return (cppu::OWeakObject*) new DecryptorImpl(rSMgr);
}

/* XServiceInfo */
rtl::OUString SAL_CALL DecryptorImpl::getImplementationName(  )
    throw (cssu::RuntimeException)
{
    return DecryptorImpl_getImplementationName();
}
sal_Bool SAL_CALL DecryptorImpl::supportsService( const rtl::OUString& rServiceName )
    throw (cssu::RuntimeException)
{
    return DecryptorImpl_supportsService( rServiceName );
}
cssu::Sequence< rtl::OUString > SAL_CALL DecryptorImpl::getSupportedServiceNames(  )
    throw (cssu::RuntimeException)
{
    return DecryptorImpl_getSupportedServiceNames();
}

<commit_msg>INTEGRATION: CWS jl51 (1.5.30); FILE MERGED 2007/02/05 13:54:18 jl 1.5.30.1: #i69228 warning free code<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: decryptorimpl.cxx,v $
 *
 *  $Revision: 1.6 $
 *
 *  last change: $Author: ihi $ $Date: 2007-04-17 10:17:02 $
 *
 *  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_xmlsecurity.hxx"

#include "decryptorimpl.hxx"

#ifndef _COM_SUN_STAR_XML_CRYPTO_XXMLENCRYPTIONTEMPLATE_HPP_
#include <com/sun/star/xml/crypto/XXMLEncryptionTemplate.hpp>
#endif
#ifndef _COM_SUN_STAR_XML_WRAPPER_XXMLELEMENTWRAPPER_HPP_
#include <com/sun/star/xml/wrapper/XXMLElementWrapper.hpp>
#endif
#ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#endif

namespace cssu = com::sun::star::uno;
namespace cssl = com::sun::star::lang;
namespace cssxc = com::sun::star::xml::crypto;
namespace cssxw = com::sun::star::xml::wrapper;

#define SERVICE_NAME "com.sun.star.xml.crypto.sax.Decryptor"
#define IMPLEMENTATION_NAME "com.sun.star.xml.security.framework.DecryptorImpl"

#define DECLARE_ASCII( SASCIIVALUE )                                                                            \
    rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SASCIIVALUE ) )

DecryptorImpl::DecryptorImpl( const cssu::Reference< cssl::XMultiServiceFactory >& rxMSF)
{
    mxMSF = rxMSF;
}

DecryptorImpl::~DecryptorImpl()
{
}

bool DecryptorImpl::checkReady() const
/****** DecryptorImpl/checkReady *********************************************
 *
 *   NAME
 *  checkReady -- checks the conditions for the decryption.
 *
 *   SYNOPSIS
 *  bReady = checkReady( );
 *
 *   FUNCTION
 *  checks whether all following conditions are satisfied:
 *  1. the result listener is ready;
 *  2. the EncryptionEngine is ready.
 *
 *   INPUTS
 *  empty
 *
 *   RESULT
 *  bReady - true if all conditions are satisfied, false otherwise
 *
 *   HISTORY
 *  05.01.2004 -    implemented
 *
 *   AUTHOR
 *  Michael Mi
 *  Email: michael.mi@sun.com
 ******************************************************************************/
{
    return (m_xResultListener.is() && EncryptionEngine::checkReady());
}

void DecryptorImpl::notifyResultListener() const
    throw (cssu::Exception, cssu::RuntimeException)
/****** DecryptorImpl/notifyResultListener ***********************************
 *
 *   NAME
 *  notifyResultListener -- notifies the listener about the decryption
 *  result.
 *
 *   SYNOPSIS
 *  notifyResultListener( );
 *
 *   FUNCTION
 *  see NAME.
 *
 *   INPUTS
 *  empty
 *
 *   RESULT
 *  empty
 *
 *   HISTORY
 *  05.01.2004 -    implemented
 *
 *   AUTHOR
 *  Michael Mi
 *  Email: michael.mi@sun.com
 ******************************************************************************/
{
    cssu::Reference< cssxc::sax::XDecryptionResultListener >
        xDecryptionResultListener ( m_xResultListener , cssu::UNO_QUERY ) ;

    xDecryptionResultListener->decrypted(m_nSecurityId,m_nStatus);
}

void DecryptorImpl::startEngine( const cssu::Reference<
    cssxc::XXMLEncryptionTemplate >&
    xEncryptionTemplate)
    throw (cssu::Exception, cssu::RuntimeException)
/****** DecryptorImpl/startEngine ********************************************
 *
 *   NAME
 *  startEngine -- decrypts the encryption.
 *
 *   SYNOPSIS
 *  startEngine( xEncryptionTemplate );
 *
 *   FUNCTION
 *  decrypts the encryption element, then if succeeds, updates the link
 *  of old template element to the new encryption element in
 *  SAXEventKeeper.
 *
 *   INPUTS
 *  xEncryptionTemplate - the encryption template to be decrypted.
 *
 *   RESULT
 *  empty
 *
 *   HISTORY
 *  05.01.2004 -    implemented
 *
 *   AUTHOR
 *  Michael Mi
 *  Email: michael.mi@sun.com
 ******************************************************************************/
{
    cssu::Reference< cssxc::XXMLEncryptionTemplate > xResultTemplate;
    try
    {
        xResultTemplate = m_xXMLEncryption->decrypt(xEncryptionTemplate, m_xXMLSecurityContext);
        m_nStatus = xResultTemplate->getStatus();
    }
    catch( cssu::Exception& )
    {
        m_nStatus = cssxc::SecurityOperationStatus_RUNTIMEERROR_FAILED;
    }

    if (m_nStatus == cssxc::SecurityOperationStatus_OPERATION_SUCCEEDED)
    {
        cssu::Reference< cssxw::XXMLElementWrapper > xDecryptedElement
            = xResultTemplate->getTemplate();
        m_xSAXEventKeeper->setElement(m_nIdOfTemplateEC, xDecryptedElement);
    }
}

/* XDecryptionResultBroadcaster */
void SAL_CALL DecryptorImpl::addDecryptionResultListener( const cssu::Reference< cssxc::sax::XDecryptionResultListener >& listener )
        throw (cssu::Exception, cssu::RuntimeException)
{
    m_xResultListener = listener;
    tryToPerform();
}

void SAL_CALL DecryptorImpl::removeDecryptionResultListener( const cssu::Reference< cssxc::sax::XDecryptionResultListener >&)
        throw (cssu::RuntimeException)
{
}

/* XInitialization */
void SAL_CALL DecryptorImpl::initialize( const cssu::Sequence< cssu::Any >& aArguments )
    throw (cssu::Exception, cssu::RuntimeException)
{
    OSL_ASSERT(aArguments.getLength() == 5);

    rtl::OUString ouTempString;

    aArguments[0] >>= ouTempString;
    m_nSecurityId = ouTempString.toInt32();
    aArguments[1] >>= m_xSAXEventKeeper;
    aArguments[2] >>= ouTempString;
    m_nIdOfTemplateEC = ouTempString.toInt32();
    aArguments[3] >>= m_xXMLSecurityContext;
    aArguments[4] >>= m_xXMLEncryption;
}

rtl::OUString DecryptorImpl_getImplementationName ()
    throw (cssu::RuntimeException)
{
    return rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM ( IMPLEMENTATION_NAME ) );
}

sal_Bool SAL_CALL DecryptorImpl_supportsService( const rtl::OUString& ServiceName )
    throw (cssu::RuntimeException)
{
    return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SERVICE_NAME ));
}

cssu::Sequence< rtl::OUString > SAL_CALL DecryptorImpl_getSupportedServiceNames(  )
    throw (cssu::RuntimeException)
{
    cssu::Sequence < rtl::OUString > aRet(1);
    rtl::OUString* pArray = aRet.getArray();
    pArray[0] =  rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME ) );
    return aRet;
}
#undef SERVICE_NAME

cssu::Reference< cssu::XInterface > SAL_CALL DecryptorImpl_createInstance( const cssu::Reference< cssl::XMultiServiceFactory >& rSMgr)
    throw( cssu::Exception )
{
    return (cppu::OWeakObject*) new DecryptorImpl(rSMgr);
}

/* XServiceInfo */
rtl::OUString SAL_CALL DecryptorImpl::getImplementationName(  )
    throw (cssu::RuntimeException)
{
    return DecryptorImpl_getImplementationName();
}
sal_Bool SAL_CALL DecryptorImpl::supportsService( const rtl::OUString& rServiceName )
    throw (cssu::RuntimeException)
{
    return DecryptorImpl_supportsService( rServiceName );
}
cssu::Sequence< rtl::OUString > SAL_CALL DecryptorImpl::getSupportedServiceNames(  )
    throw (cssu::RuntimeException)
{
    return DecryptorImpl_getSupportedServiceNames();
}

<|endoftext|>


<commit_before>/*****************************************************************************
 *
 * This file is part of Mapnik (c++ mapping toolkit)
 *
 * Copyright (C) 2014 Artem Pavlenko
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * 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., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 *****************************************************************************/

#include <mapnik/function_call.hpp>

namespace mapnik {

// functions
// exp
//template <typename T>
struct exp_impl
{
    //using type = T;
    value_type operator() (value_type const& val) const
    {
        return std::exp(val.to_double());
    }

};

// sin
struct sin_impl
{
    value_type operator() (value_type const& val) const
    {
        return std::sin(val.to_double());
    }
};

// cos
struct cos_impl
{
    value_type operator() (value_type const& val) const
    {
        return std::cos(val.to_double());
    }
};

// tan
struct tan_impl
{
    value_type operator() (value_type const& val) const
    {
        return std::tan(val.to_double());
    }
};

// atan
struct atan_impl
{
    value_type operator()(value_type const& val) const
    {
        return std::atan(val.to_double());
    }
};

// abs
struct abs_impl
{
    value_type operator() (value_type const& val) const
    {
        return std::fabs(val.to_double());
    }
};

// length
struct length_impl
{
    value_type operator() (value_type const& val) const
    {
        return val.to_unicode().length();
    }
};

unary_function_types::unary_function_types()
{
    add
        ("sin",  sin_impl())
        ("cos",  cos_impl())
        ("tan",  tan_impl())
        ("atan", atan_impl())
        ("exp",  exp_impl())
        ("abs",  abs_impl())
        ("length",length_impl())
        ;
}

char const* unary_function_name(unary_function_impl const& fun)
{
    if (fun.target<sin_impl>()) return "sin";
    else if (fun.target<cos_impl>()) return "cos";
    else if (fun.target<tan_impl>()) return "tan";
    else if (fun.target<atan_impl>()) return "atan";
    else if (fun.target<exp_impl>()) return "exp";
    else if (fun.target<abs_impl>()) return "abs";
    else return "unknown";
}

// binary functions
// min
inline value_type min_impl(value_type const& arg1, value_type const& arg2)
{
    return std::min(arg1.to_double(), arg2.to_double());
}
// max
inline value_type max_impl(value_type const& arg1, value_type const& arg2)
{
    return std::max(arg1.to_double(), arg2.to_double());
}
// pow
inline value_type pow_impl(value_type const& arg1, value_type const& arg2)
{
    return std::pow(arg1.to_double(), arg2.to_double());
}

binary_function_types::binary_function_types()
{
    add
        ("min", binary_function_impl(min_impl))
        ("max", binary_function_impl(max_impl))
        ("pow", binary_function_impl(pow_impl))
        ;
}

char const* binary_function_name(binary_function_impl const& fun)
{
    value_type(*const* f_ptr)(value_type const&, value_type const&) =
        fun.target<value_type(*)
                   (value_type const&, value_type const&)>();
    if (f_ptr)
    {
        if (*f_ptr == min_impl) return "min";
        else if(*f_ptr == max_impl) return "max";
        else if(*f_ptr == pow_impl) return "pow";
    }
    return "unknown";
}

}
<commit_msg>add to string impl for length func - closes #2437<commit_after>/*****************************************************************************
 *
 * This file is part of Mapnik (c++ mapping toolkit)
 *
 * Copyright (C) 2014 Artem Pavlenko
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * 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., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 *****************************************************************************/

#include <mapnik/function_call.hpp>

namespace mapnik {

// functions
// exp
//template <typename T>
struct exp_impl
{
    //using type = T;
    value_type operator() (value_type const& val) const
    {
        return std::exp(val.to_double());
    }

};

// sin
struct sin_impl
{
    value_type operator() (value_type const& val) const
    {
        return std::sin(val.to_double());
    }
};

// cos
struct cos_impl
{
    value_type operator() (value_type const& val) const
    {
        return std::cos(val.to_double());
    }
};

// tan
struct tan_impl
{
    value_type operator() (value_type const& val) const
    {
        return std::tan(val.to_double());
    }
};

// atan
struct atan_impl
{
    value_type operator()(value_type const& val) const
    {
        return std::atan(val.to_double());
    }
};

// abs
struct abs_impl
{
    value_type operator() (value_type const& val) const
    {
        return std::fabs(val.to_double());
    }
};

// length
struct length_impl
{
    value_type operator() (value_type const& val) const
    {
        return val.to_unicode().length();
    }
};

unary_function_types::unary_function_types()
{
    add
        ("sin",  sin_impl())
        ("cos",  cos_impl())
        ("tan",  tan_impl())
        ("atan", atan_impl())
        ("exp",  exp_impl())
        ("abs",  abs_impl())
        ("length",length_impl())
        ;
}

char const* unary_function_name(unary_function_impl const& fun)
{
    if (fun.target<sin_impl>()) return "sin";
    else if (fun.target<cos_impl>()) return "cos";
    else if (fun.target<tan_impl>()) return "tan";
    else if (fun.target<atan_impl>()) return "atan";
    else if (fun.target<exp_impl>()) return "exp";
    else if (fun.target<abs_impl>()) return "abs";
    else if (fun.target<length_impl>()) return "length";
    else return "unknown";
}

// binary functions
// min
inline value_type min_impl(value_type const& arg1, value_type const& arg2)
{
    return std::min(arg1.to_double(), arg2.to_double());
}
// max
inline value_type max_impl(value_type const& arg1, value_type const& arg2)
{
    return std::max(arg1.to_double(), arg2.to_double());
}
// pow
inline value_type pow_impl(value_type const& arg1, value_type const& arg2)
{
    return std::pow(arg1.to_double(), arg2.to_double());
}

binary_function_types::binary_function_types()
{
    add
        ("min", binary_function_impl(min_impl))
        ("max", binary_function_impl(max_impl))
        ("pow", binary_function_impl(pow_impl))
        ;
}

char const* binary_function_name(binary_function_impl const& fun)
{
    value_type(*const* f_ptr)(value_type const&, value_type const&) =
        fun.target<value_type(*)
                   (value_type const&, value_type const&)>();
    if (f_ptr)
    {
        if (*f_ptr == min_impl) return "min";
        else if(*f_ptr == max_impl) return "max";
        else if(*f_ptr == pow_impl) return "pow";
    }
    return "unknown";
}

}
<|endoftext|>


<commit_before>
#include "FlareTechnologyMenu.h"
#include "../../Flare.h"

#include "../Components/FlareTechnologyInfo.h"
#include "../Components/FlareTabView.h"

#include "../../Data/FlareTechnologyCatalog.h"
#include "../../Data/FlareScannableCatalog.h"

#include "../../Game/FlareGame.h"
#include "../../Game/FlareCompany.h"
#include "../../Player/FlareMenuManager.h"

#include "../../Player/FlarePlayerController.h"

#define LOCTEXT_NAMESPACE "FlareTechnologyMenu"

/*----------------------------------------------------
	Construct
----------------------------------------------------*/

void SFlareTechnologyMenu::Construct(const FArguments& InArgs)
{
	// Data
	MenuManager = InArgs._MenuManager;
	const FFlareStyleCatalog& Theme = FFlareStyleSet::GetDefaultTheme();
	AFlarePlayerController* PC = MenuManager->GetPC();

	// Build structure
	ChildSlot
	.HAlign(HAlign_Fill)
	.VAlign(VAlign_Fill)
	.Padding(FMargin(0, AFlareMenuManager::GetMainOverlayHeight(), 0, 0))
	[
		SNew(SFlareTabView)

		// Technology block
		+ SFlareTabView::Slot()
		.Header(LOCTEXT("TechnologyMainTab", "Technologies"))
		.HeaderHelp(LOCTEXT("TechnologyMainTabInfo", "Technology tree & research status"))
		[
			SNew(SBox)
			.WidthOverride(2.2 * Theme.ContentWidth)
			.HAlign(HAlign_Center)
			.VAlign(VAlign_Fill)
			[
				SNew(SHorizontalBox)

				// Info block
				+ SHorizontalBox::Slot()
				.HAlign(HAlign_Left)
				.VAlign(VAlign_Top)
				.AutoWidth()
				[
					SNew(SBox)
					.WidthOverride(0.75 * Theme.ContentWidth)
					.HAlign(HAlign_Left)
					[
						SNew(SVerticalBox)

						// Title
						+ SVerticalBox::Slot()
						.AutoHeight()
						.Padding(Theme.TitlePadding)
						[
							SNew(STextBlock)
							.Text(LOCTEXT("CompanyTechnologyTitle", "Company technology"))
							.TextStyle(&Theme.SubTitleFont)
						]

						// Company info
						+ SVerticalBox::Slot()
						.AutoHeight()
						.Padding(Theme.ContentPadding)
						[
							SNew(SRichTextBlock)
							.TextStyle(&Theme.TextFont)
							.Text(this, &SFlareTechnologyMenu::GetCompanyTechnologyInfo)
							.DecoratorStyleSet(&FFlareStyleSet::Get())
							.WrapTextAt(0.7 * Theme.ContentWidth)
						]

						// Title
						+ SVerticalBox::Slot()
						.AutoHeight()
						.Padding(Theme.TitlePadding)
						[
							SNew(STextBlock)
							.TextStyle(&Theme.SubTitleFont)
							.Text(this, &SFlareTechnologyMenu::GetTechnologyName)
						]

						// Description
						+ SVerticalBox::Slot()
						.AutoHeight()
						.Padding(Theme.ContentPadding)
						[
							SNew(STextBlock)
							.TextStyle(&Theme.TextFont)
							.Text(this, &SFlareTechnologyMenu::GetTechnologyDescription)
							.WrapTextAt(0.7 * Theme.ContentWidth)
						]

						// Button
						+ SVerticalBox::Slot()
						.AutoHeight()
						.Padding(Theme.ContentPadding)
						.HAlign(HAlign_Left)
						[
							SNew(SFlareButton)
							.Width(6)
							.Icon(FFlareStyleSet::GetIcon("ResearchValue"))
							.Text(this, &SFlareTechnologyMenu::GetTechnologyUnlockText)
							.HelpText(this, &SFlareTechnologyMenu::GetTechnologyUnlockHintText)
							.OnClicked(this, &SFlareTechnologyMenu::OnTechnologyUnlocked)
							.IsDisabled(this, &SFlareTechnologyMenu::IsUnlockDisabled)
						]
					]
				]

				// Tree block
				+ SHorizontalBox::Slot()
				.HAlign(HAlign_Right)
				.VAlign(VAlign_Top)
				[
					SNew(SVerticalBox)

					// Title
					+ SVerticalBox::Slot()
					.AutoHeight()
					.Padding(Theme.TitlePadding)
					[
						SNew(STextBlock)
						.Text(LOCTEXT("AvailableTechnologyTitle", "Available technologies"))
						.TextStyle(&Theme.SubTitleFont)
					]

					// Data
					+ SVerticalBox::Slot()
					.AutoHeight()
					.Padding(Theme.ContentPadding)
					[
						SAssignNew(TechnologyTree, SScrollBox)
						.Style(&Theme.ScrollBoxStyle)
						.ScrollBarStyle(&Theme.ScrollBarStyle)
					]
				]
			]
		]

		// Scannable block
		+ SFlareTabView::Slot()
		.Header(LOCTEXT("TechnologyScannableTab", "Artifacts"))
		.HeaderHelp(LOCTEXT("TechnologyScannableTabInfo", "Artifacts are found drifting in the world and unlock research data"))
		[
			SNew(SBox)
			.WidthOverride(2.2 * Theme.ContentWidth)
			.HAlign(HAlign_Center)
			.VAlign(VAlign_Fill)
			[
				SNew(SBox)
				.HAlign(HAlign_Left)
				.WidthOverride(2.2 * Theme.ContentWidth)
				[
					SNew(SVerticalBox)

					// Title
					+ SVerticalBox::Slot()
					.AutoHeight()
					.Padding(Theme.TitlePadding)
					.HAlign(HAlign_Left)
					[
						SNew(STextBlock)
						.Text(LOCTEXT("CompanyScannableTitle", "Artifacts found"))
						.TextStyle(&Theme.SubTitleFont)
					]

					// Count
					+ SVerticalBox::Slot()
					.AutoHeight()
					.Padding(Theme.ContentPadding)
					.HAlign(HAlign_Left)
					[
						SNew(STextBlock)
						.Text(this, &SFlareTechnologyMenu::GetUnlockedScannableCount)
						.TextStyle(&Theme.TextFont)
						.WrapTextAt(2 * Theme.ContentWidth)
					]

					// Content
					+ SVerticalBox::Slot()
					.AutoHeight()
					.Padding(Theme.ContentPadding)
					.HAlign(HAlign_Left)
					[
						SAssignNew(ArtifactList, SVerticalBox)
					]
				]
			]
		]
	];
}

/*----------------------------------------------------
	Interaction
----------------------------------------------------*/

void SFlareTechnologyMenu::Setup()
{
	SetEnabled(false);
	SetVisibility(EVisibility::Collapsed);
}

void SFlareTechnologyMenu::Enter()
{
	FLOG("SFlareTechnologyMenu::Enter");

	// Menu data
	SetEnabled(true);
	SetVisibility(EVisibility::Visible);
	const FFlareStyleCatalog& Theme = FFlareStyleSet::GetDefaultTheme();

	// Sorting criteria for technologies
	struct FSortByLevelCategoryAndCost
	{
		FORCEINLINE bool operator()(const FFlareTechnologyDescription& A, const FFlareTechnologyDescription& B) const
		{
			if (A.Level > B.Level)
			{
				return true;
			}
			else if (A.Level < B.Level)
			{
				return false;
			}
			else if (A.Category < B.Category)
			{
				return true;
			}
			else if (A.Category > B.Category)
			{
				return false;
			}
			else
			{
				if (A.ResearchCost > B.ResearchCost)
				{
					return true;
				}
				else
				{
					return false;
				}
			}
		}
	};

	// List all technologies
	SelectedTechnology = NULL;
	TArray<const FFlareTechnologyDescription*> Technologies;
	for (auto& Entry : MenuManager->GetGame()->GetTechnologyCatalog()->TechnologyCatalog)
	{
		Technologies.Add(&Entry->Data);
	}
	Technologies.Sort(FSortByLevelCategoryAndCost());

	// Add technologies to the tree
	int CurrentLevel = -1;
	TSharedPtr<SHorizontalBox> CurrentLevelRow;
	for (const FFlareTechnologyDescription* Technology : Technologies)
	{
		// Add a new row
		if (Technology->Level != CurrentLevel)
		{
			CurrentLevel = Technology->Level;

			// Row
			TechnologyTree->AddSlot()
				.HAlign(HAlign_Fill)
				.VAlign(VAlign_Center)
				[
					SAssignNew(CurrentLevelRow, SHorizontalBox)
				];

			// Row title
			CurrentLevelRow->AddSlot()
				.HAlign(HAlign_Left)
				.VAlign(VAlign_Center)
				.Padding(FMargin(0, 0, 0, 10))
				[
					SNew(STextBlock)
					.TextStyle(&Theme.TitleFont)
					.Text(FText::Format(LOCTEXT("CurrentLevelFormat", "{0}"), FText::AsNumber(CurrentLevel)))
					.ColorAndOpacity(this, &SFlareTechnologyMenu::GetTitleTextColor, CurrentLevel)
				];
		}

		// Add entry to the row
		CurrentLevelRow->AddSlot()
			.HAlign(HAlign_Center)
			.VAlign(VAlign_Center)
			.Padding(Theme.ContentPadding)
			[
				SNew(SFlareTechnologyInfo)
				.MenuManager(MenuManager)
				.Technology(Technology)
				.OnClicked(FFlareButtonClicked::CreateSP(this, &SFlareTechnologyMenu::OnTechnologySelected, Technology))
			];
	}

	// List artifacts
	ArtifactList->ClearChildren();
	for (FName UnlockedScannableIdentifier : MenuManager->GetPC()->GetUnlockedScannables())
	{
		auto Scannable = MenuManager->GetGame()->GetScannableCatalog()->Get(UnlockedScannableIdentifier);

		ArtifactList->AddSlot()
			.HAlign(HAlign_Fill)
			.VAlign(VAlign_Center)
			.Padding(Theme.ContentPadding)
			[
				SNew(SVerticalBox)

				// Upper line
				+ SVerticalBox::Slot()
				.AutoHeight()
				[
					SNew(SHorizontalBox)

					+ SHorizontalBox::Slot()
					.AutoWidth()
					.Padding(Theme.SmallContentPadding)
					[
						SNew(SImage)
						.Image(FFlareStyleSet::GetIcon("OK"))
					]

					+ SHorizontalBox::Slot()
					.AutoWidth()
					[
						SNew(STextBlock)
						.TextStyle(&Theme.NameFont)
						.Text(Scannable->Name)
					]
				]

				// Lower line
				+ SVerticalBox::Slot()
				.AutoHeight()
				.Padding(Theme.SmallContentPadding)
				[
					SNew(STextBlock)
					.TextStyle(&Theme.TextFont)
					.Text(Scannable->Description)
					.WrapTextAt(Theme.ContentWidth)
				]
			];
	}

	SlatePrepass(FSlateApplicationBase::Get().GetApplicationScale());
}

void SFlareTechnologyMenu::Exit()
{
	SetEnabled(false);

	SelectedTechnology = NULL;
	TechnologyTree->ClearChildren();

	ArtifactList->ClearChildren();

	SetVisibility(EVisibility::Collapsed);
}

/*----------------------------------------------------
	Callbacks
----------------------------------------------------*/

bool SFlareTechnologyMenu::IsUnlockDisabled() const
{
	if (SelectedTechnology)
	{
		FText Unused;
		return !MenuManager->GetPC()->GetCompany()->IsTechnologyAvailable(SelectedTechnology->Identifier, Unused);
	}
	else
	{
		return true;
	}
}

FText SFlareTechnologyMenu::GetCompanyTechnologyInfo() const
{
	UFlareCompany* Company = MenuManager->GetPC()->GetCompany();

	CompanyValue CompanyValue = Company->GetCompanyValue(NULL, false);

	return FText::Format(LOCTEXT("TechnologyCompanyFormat", "\u2022 You can currently research technology up to <HighlightText>level {0}</>.\n\u2022 You have <HighlightText>{1} research</> left to spend in technology.\n\u2022 You have already spent {2} research."),
		FText::AsNumber(Company->GetTechnologyLevel()),
		FText::AsNumber(Company->GetResearchAmount()),
		FText::AsNumber(Company->GetResearchSpent()));
}

FText SFlareTechnologyMenu::GetTechnologyName() const
{
	if (SelectedTechnology)
	{
		return SelectedTechnology->Name;
	}
	else
	{
		return LOCTEXT("TechnologyDetailsTitle", "Technology details");
	}
}

FText SFlareTechnologyMenu::GetTechnologyDescription() const
{
	if (SelectedTechnology)
	{
		return SelectedTechnology->Description;
	}
	else
	{
		return LOCTEXT("NotechnologySelected", "No technology selected.");
	}
}

FSlateColor SFlareTechnologyMenu::GetTitleTextColor(int32 RowLevel) const
{
	const FFlareStyleCatalog& Theme = FFlareStyleSet::GetDefaultTheme();
	UFlareCompany* Company = MenuManager->GetPC()->GetCompany();

	if (RowLevel <= Company->GetTechnologyLevel())
	{
		return Theme.NeutralColor;
	}
	else
	{
		return Theme.UnknownColor;
	}
}

FText SFlareTechnologyMenu::GetTechnologyUnlockText() const
{
	UFlareCompany* Company = MenuManager->GetPC()->GetCompany();
	FText Unused;

	if (SelectedTechnology && !Company->IsTechnologyAvailable(SelectedTechnology->Identifier, Unused))
	{
		return LOCTEXT("UnlockTechImpossible", "Can't research");
	}
	else
	{
		return LOCTEXT("UnlockTechOK", "Research technology");
	}
}

FText SFlareTechnologyMenu::GetTechnologyUnlockHintText() const
{
	UFlareCompany* Company = MenuManager->GetPC()->GetCompany();
	FText Reason;

	if (SelectedTechnology && !Company->IsTechnologyAvailable(SelectedTechnology->Identifier, Reason))
	{
		return Reason;
	}
	else
	{
		return LOCTEXT("UnlockTechInfo", "Research this technology by spending some of your available budget");
	}
}

void SFlareTechnologyMenu::OnTechnologySelected(const FFlareTechnologyDescription* Technology)
{
	SelectedTechnology = Technology;
}

void SFlareTechnologyMenu::OnTechnologyUnlocked()
{
	if (SelectedTechnology)
	{
		MenuManager->GetPC()->GetCompany()->UnlockTechnology(SelectedTechnology->Identifier);
	}
}

FText SFlareTechnologyMenu::GetUnlockedScannableCount() const
{
	return FText::Format(LOCTEXT("ScannableCountFormat", "You have found {0} out of {1} artifacts. Explore the world and discover new sectors to unlock more research data !"),
		FText::AsNumber(MenuManager->GetPC()->GetUnlockedScannableCount()),
		FText::AsNumber(MenuManager->GetGame()->GetScannableCatalog()->ScannableCatalog.Num()));
}

#undef LOCTEXT_NAMESPACE
<commit_msg>Add assertion<commit_after>
#include "FlareTechnologyMenu.h"
#include "../../Flare.h"

#include "../Components/FlareTechnologyInfo.h"
#include "../Components/FlareTabView.h"

#include "../../Data/FlareTechnologyCatalog.h"
#include "../../Data/FlareScannableCatalog.h"

#include "../../Game/FlareGame.h"
#include "../../Game/FlareCompany.h"
#include "../../Player/FlareMenuManager.h"

#include "../../Player/FlarePlayerController.h"

#define LOCTEXT_NAMESPACE "FlareTechnologyMenu"

/*----------------------------------------------------
	Construct
----------------------------------------------------*/

void SFlareTechnologyMenu::Construct(const FArguments& InArgs)
{
	// Data
	MenuManager = InArgs._MenuManager;
	const FFlareStyleCatalog& Theme = FFlareStyleSet::GetDefaultTheme();
	AFlarePlayerController* PC = MenuManager->GetPC();

	// Build structure
	ChildSlot
	.HAlign(HAlign_Fill)
	.VAlign(VAlign_Fill)
	.Padding(FMargin(0, AFlareMenuManager::GetMainOverlayHeight(), 0, 0))
	[
		SNew(SFlareTabView)

		// Technology block
		+ SFlareTabView::Slot()
		.Header(LOCTEXT("TechnologyMainTab", "Technologies"))
		.HeaderHelp(LOCTEXT("TechnologyMainTabInfo", "Technology tree & research status"))
		[
			SNew(SBox)
			.WidthOverride(2.2 * Theme.ContentWidth)
			.HAlign(HAlign_Center)
			.VAlign(VAlign_Fill)
			[
				SNew(SHorizontalBox)

				// Info block
				+ SHorizontalBox::Slot()
				.HAlign(HAlign_Left)
				.VAlign(VAlign_Top)
				.AutoWidth()
				[
					SNew(SBox)
					.WidthOverride(0.75 * Theme.ContentWidth)
					.HAlign(HAlign_Left)
					[
						SNew(SVerticalBox)

						// Title
						+ SVerticalBox::Slot()
						.AutoHeight()
						.Padding(Theme.TitlePadding)
						[
							SNew(STextBlock)
							.Text(LOCTEXT("CompanyTechnologyTitle", "Company technology"))
							.TextStyle(&Theme.SubTitleFont)
						]

						// Company info
						+ SVerticalBox::Slot()
						.AutoHeight()
						.Padding(Theme.ContentPadding)
						[
							SNew(SRichTextBlock)
							.TextStyle(&Theme.TextFont)
							.Text(this, &SFlareTechnologyMenu::GetCompanyTechnologyInfo)
							.DecoratorStyleSet(&FFlareStyleSet::Get())
							.WrapTextAt(0.7 * Theme.ContentWidth)
						]

						// Title
						+ SVerticalBox::Slot()
						.AutoHeight()
						.Padding(Theme.TitlePadding)
						[
							SNew(STextBlock)
							.TextStyle(&Theme.SubTitleFont)
							.Text(this, &SFlareTechnologyMenu::GetTechnologyName)
						]

						// Description
						+ SVerticalBox::Slot()
						.AutoHeight()
						.Padding(Theme.ContentPadding)
						[
							SNew(STextBlock)
							.TextStyle(&Theme.TextFont)
							.Text(this, &SFlareTechnologyMenu::GetTechnologyDescription)
							.WrapTextAt(0.7 * Theme.ContentWidth)
						]

						// Button
						+ SVerticalBox::Slot()
						.AutoHeight()
						.Padding(Theme.ContentPadding)
						.HAlign(HAlign_Left)
						[
							SNew(SFlareButton)
							.Width(6)
							.Icon(FFlareStyleSet::GetIcon("ResearchValue"))
							.Text(this, &SFlareTechnologyMenu::GetTechnologyUnlockText)
							.HelpText(this, &SFlareTechnologyMenu::GetTechnologyUnlockHintText)
							.OnClicked(this, &SFlareTechnologyMenu::OnTechnologyUnlocked)
							.IsDisabled(this, &SFlareTechnologyMenu::IsUnlockDisabled)
						]
					]
				]

				// Tree block
				+ SHorizontalBox::Slot()
				.HAlign(HAlign_Right)
				.VAlign(VAlign_Top)
				[
					SNew(SVerticalBox)

					// Title
					+ SVerticalBox::Slot()
					.AutoHeight()
					.Padding(Theme.TitlePadding)
					[
						SNew(STextBlock)
						.Text(LOCTEXT("AvailableTechnologyTitle", "Available technologies"))
						.TextStyle(&Theme.SubTitleFont)
					]

					// Data
					+ SVerticalBox::Slot()
					.AutoHeight()
					.Padding(Theme.ContentPadding)
					[
						SAssignNew(TechnologyTree, SScrollBox)
						.Style(&Theme.ScrollBoxStyle)
						.ScrollBarStyle(&Theme.ScrollBarStyle)
					]
				]
			]
		]

		// Scannable block
		+ SFlareTabView::Slot()
		.Header(LOCTEXT("TechnologyScannableTab", "Artifacts"))
		.HeaderHelp(LOCTEXT("TechnologyScannableTabInfo", "Artifacts are found drifting in the world and unlock research data"))
		[
			SNew(SBox)
			.WidthOverride(2.2 * Theme.ContentWidth)
			.HAlign(HAlign_Center)
			.VAlign(VAlign_Fill)
			[
				SNew(SBox)
				.HAlign(HAlign_Left)
				.WidthOverride(2.2 * Theme.ContentWidth)
				[
					SNew(SVerticalBox)

					// Title
					+ SVerticalBox::Slot()
					.AutoHeight()
					.Padding(Theme.TitlePadding)
					.HAlign(HAlign_Left)
					[
						SNew(STextBlock)
						.Text(LOCTEXT("CompanyScannableTitle", "Artifacts found"))
						.TextStyle(&Theme.SubTitleFont)
					]

					// Count
					+ SVerticalBox::Slot()
					.AutoHeight()
					.Padding(Theme.ContentPadding)
					.HAlign(HAlign_Left)
					[
						SNew(STextBlock)
						.Text(this, &SFlareTechnologyMenu::GetUnlockedScannableCount)
						.TextStyle(&Theme.TextFont)
						.WrapTextAt(2 * Theme.ContentWidth)
					]

					// Content
					+ SVerticalBox::Slot()
					.AutoHeight()
					.Padding(Theme.ContentPadding)
					.HAlign(HAlign_Left)
					[
						SAssignNew(ArtifactList, SVerticalBox)
					]
				]
			]
		]
	];
}

/*----------------------------------------------------
	Interaction
----------------------------------------------------*/

void SFlareTechnologyMenu::Setup()
{
	SetEnabled(false);
	SetVisibility(EVisibility::Collapsed);
}

void SFlareTechnologyMenu::Enter()
{
	FLOG("SFlareTechnologyMenu::Enter");

	// Menu data
	SetEnabled(true);
	SetVisibility(EVisibility::Visible);
	const FFlareStyleCatalog& Theme = FFlareStyleSet::GetDefaultTheme();

	// Sorting criteria for technologies
	struct FSortByLevelCategoryAndCost
	{
		FORCEINLINE bool operator()(const FFlareTechnologyDescription& A, const FFlareTechnologyDescription& B) const
		{
			if (A.Level > B.Level)
			{
				return true;
			}
			else if (A.Level < B.Level)
			{
				return false;
			}
			else if (A.Category < B.Category)
			{
				return true;
			}
			else if (A.Category > B.Category)
			{
				return false;
			}
			else
			{
				if (A.ResearchCost > B.ResearchCost)
				{
					return true;
				}
				else
				{
					return false;
				}
			}
		}
	};

	// List all technologies
	SelectedTechnology = NULL;
	TArray<const FFlareTechnologyDescription*> Technologies;
	for (auto& Entry : MenuManager->GetGame()->GetTechnologyCatalog()->TechnologyCatalog)
	{
		Technologies.Add(&Entry->Data);
	}
	Technologies.Sort(FSortByLevelCategoryAndCost());

	// Add technologies to the tree
	int CurrentLevel = -1;
	TSharedPtr<SHorizontalBox> CurrentLevelRow;
	for (const FFlareTechnologyDescription* Technology : Technologies)
	{
		// Add a new row
		if (Technology->Level != CurrentLevel)
		{
			CurrentLevel = Technology->Level;

			// Row
			TechnologyTree->AddSlot()
				.HAlign(HAlign_Fill)
				.VAlign(VAlign_Center)
				[
					SAssignNew(CurrentLevelRow, SHorizontalBox)
				];

			// Row title
			CurrentLevelRow->AddSlot()
				.HAlign(HAlign_Left)
				.VAlign(VAlign_Center)
				.Padding(FMargin(0, 0, 0, 10))
				[
					SNew(STextBlock)
					.TextStyle(&Theme.TitleFont)
					.Text(FText::Format(LOCTEXT("CurrentLevelFormat", "{0}"), FText::AsNumber(CurrentLevel)))
					.ColorAndOpacity(this, &SFlareTechnologyMenu::GetTitleTextColor, CurrentLevel)
				];
		}

		// Add entry to the row
		CurrentLevelRow->AddSlot()
			.HAlign(HAlign_Center)
			.VAlign(VAlign_Center)
			.Padding(Theme.ContentPadding)
			[
				SNew(SFlareTechnologyInfo)
				.MenuManager(MenuManager)
				.Technology(Technology)
				.OnClicked(FFlareButtonClicked::CreateSP(this, &SFlareTechnologyMenu::OnTechnologySelected, Technology))
			];
	}

	// List artifacts
	ArtifactList->ClearChildren();
	for (FName UnlockedScannableIdentifier : MenuManager->GetPC()->GetUnlockedScannables())
	{
		auto Scannable = MenuManager->GetGame()->GetScannableCatalog()->Get(UnlockedScannableIdentifier);
		FCHECK(Scannable);

		ArtifactList->AddSlot()
			.HAlign(HAlign_Fill)
			.VAlign(VAlign_Center)
			.Padding(Theme.ContentPadding)
			[
				SNew(SVerticalBox)

				// Upper line
				+ SVerticalBox::Slot()
				.AutoHeight()
				[
					SNew(SHorizontalBox)

					+ SHorizontalBox::Slot()
					.AutoWidth()
					.Padding(Theme.SmallContentPadding)
					[
						SNew(SImage)
						.Image(FFlareStyleSet::GetIcon("OK"))
					]

					+ SHorizontalBox::Slot()
					.AutoWidth()
					[
						SNew(STextBlock)
						.TextStyle(&Theme.NameFont)
						.Text(Scannable->Name)
					]
				]

				// Lower line
				+ SVerticalBox::Slot()
				.AutoHeight()
				.Padding(Theme.SmallContentPadding)
				[
					SNew(STextBlock)
					.TextStyle(&Theme.TextFont)
					.Text(Scannable->Description)
					.WrapTextAt(Theme.ContentWidth)
				]
			];
	}

	SlatePrepass(FSlateApplicationBase::Get().GetApplicationScale());
}

void SFlareTechnologyMenu::Exit()
{
	SetEnabled(false);

	SelectedTechnology = NULL;
	TechnologyTree->ClearChildren();

	ArtifactList->ClearChildren();

	SetVisibility(EVisibility::Collapsed);
}

/*----------------------------------------------------
	Callbacks
----------------------------------------------------*/

bool SFlareTechnologyMenu::IsUnlockDisabled() const
{
	if (SelectedTechnology)
	{
		FText Unused;
		return !MenuManager->GetPC()->GetCompany()->IsTechnologyAvailable(SelectedTechnology->Identifier, Unused);
	}
	else
	{
		return true;
	}
}

FText SFlareTechnologyMenu::GetCompanyTechnologyInfo() const
{
	UFlareCompany* Company = MenuManager->GetPC()->GetCompany();

	CompanyValue CompanyValue = Company->GetCompanyValue(NULL, false);

	return FText::Format(LOCTEXT("TechnologyCompanyFormat", "\u2022 You can currently research technology up to <HighlightText>level {0}</>.\n\u2022 You have <HighlightText>{1} research</> left to spend in technology.\n\u2022 You have already spent {2} research."),
		FText::AsNumber(Company->GetTechnologyLevel()),
		FText::AsNumber(Company->GetResearchAmount()),
		FText::AsNumber(Company->GetResearchSpent()));
}

FText SFlareTechnologyMenu::GetTechnologyName() const
{
	if (SelectedTechnology)
	{
		return SelectedTechnology->Name;
	}
	else
	{
		return LOCTEXT("TechnologyDetailsTitle", "Technology details");
	}
}

FText SFlareTechnologyMenu::GetTechnologyDescription() const
{
	if (SelectedTechnology)
	{
		return SelectedTechnology->Description;
	}
	else
	{
		return LOCTEXT("NotechnologySelected", "No technology selected.");
	}
}

FSlateColor SFlareTechnologyMenu::GetTitleTextColor(int32 RowLevel) const
{
	const FFlareStyleCatalog& Theme = FFlareStyleSet::GetDefaultTheme();
	UFlareCompany* Company = MenuManager->GetPC()->GetCompany();

	if (RowLevel <= Company->GetTechnologyLevel())
	{
		return Theme.NeutralColor;
	}
	else
	{
		return Theme.UnknownColor;
	}
}

FText SFlareTechnologyMenu::GetTechnologyUnlockText() const
{
	UFlareCompany* Company = MenuManager->GetPC()->GetCompany();
	FText Unused;

	if (SelectedTechnology && !Company->IsTechnologyAvailable(SelectedTechnology->Identifier, Unused))
	{
		return LOCTEXT("UnlockTechImpossible", "Can't research");
	}
	else
	{
		return LOCTEXT("UnlockTechOK", "Research technology");
	}
}

FText SFlareTechnologyMenu::GetTechnologyUnlockHintText() const
{
	UFlareCompany* Company = MenuManager->GetPC()->GetCompany();
	FText Reason;

	if (SelectedTechnology && !Company->IsTechnologyAvailable(SelectedTechnology->Identifier, Reason))
	{
		return Reason;
	}
	else
	{
		return LOCTEXT("UnlockTechInfo", "Research this technology by spending some of your available budget");
	}
}

void SFlareTechnologyMenu::OnTechnologySelected(const FFlareTechnologyDescription* Technology)
{
	SelectedTechnology = Technology;
}

void SFlareTechnologyMenu::OnTechnologyUnlocked()
{
	if (SelectedTechnology)
	{
		MenuManager->GetPC()->GetCompany()->UnlockTechnology(SelectedTechnology->Identifier);
	}
}

FText SFlareTechnologyMenu::GetUnlockedScannableCount() const
{
	return FText::Format(LOCTEXT("ScannableCountFormat", "You have found {0} out of {1} artifacts. Explore the world and discover new sectors to unlock more research data !"),
		FText::AsNumber(MenuManager->GetPC()->GetUnlockedScannableCount()),
		FText::AsNumber(MenuManager->GetGame()->GetScannableCatalog()->ScannableCatalog.Num()));
}

#undef LOCTEXT_NAMESPACE
<|endoftext|>


<commit_before>// This file is a part of the OpenSurgSim project.
// Copyright 2013, SimQuest Solutions Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include <gtest/gtest.h>

#include "SurgSim/Blocks/PoseInterpolator.h"
#include "SurgSim/Framework/Runtime.h"
#include "SurgSim/Framework/Representation.h"
#include "SurgSim/Math/RigidTransform.h"
#include "SurgSim/Math/Vector.h"
#include "SurgSim/Math/Quaternion.h"

using SurgSim::Math::RigidTransform3d;
using SurgSim::Math::Quaterniond;
using SurgSim::Math::Vector3d;
using SurgSim::Math::makeRigidTransform;
using SurgSim::Math::interpolate;

namespace
{
	RigidTransform3d startPose = makeRigidTransform(Quaterniond::Identity(), Vector3d(1.0,2.0,3.0));
	RigidTransform3d endPose = makeRigidTransform(Quaterniond::Identity(), Vector3d(3.0,2.0,1.0));
}

class PoseTestRepresentation : public SurgSim::Framework::Representation
{
public:
	PoseTestRepresentation(const std::string& name) : Representation(name)
	{

	}

	virtual void setInitialPose(const SurgSim::Math::RigidTransform3d& pose)
	{
		m_pose = pose;
	}

	virtual const SurgSim::Math::RigidTransform3d& getInitialPose() const
	{
		return m_pose;
	}

	virtual void setPose(const SurgSim::Math::RigidTransform3d& pose)
	{
		m_pose = pose;
	}

	virtual const SurgSim::Math::RigidTransform3d& getPose() const
	{
		return m_pose;
	}

private:
	RigidTransform3d m_pose;
};

namespace SurgSim
{
namespace Blocks
{

TEST(PoseInterpolatorTests, InitTest)
{
	ASSERT_NO_THROW({auto interpolator = std::make_shared<PoseInterpolator>("test");});
}

TEST(PoseInterpolatorTests, StartAndEndPose)
{
	auto runtime = std::make_shared<SurgSim::Framework::Runtime>();
	auto representation = std::make_shared<PoseTestRepresentation>("representation");
	auto interpolator = std::make_shared<PoseInterpolator>("interpolator");

	interpolator->setStartingPose(startPose);
	interpolator->setEndingPose(endPose);
	interpolator->setTarget(representation);

	interpolator->initialize(runtime);
	interpolator->wakeUp();
	interpolator->update(0.0);

	EXPECT_TRUE(startPose.isApprox(representation->getPose()));
	interpolator->update(0.5);

	RigidTransform3d pose = interpolate(startPose, endPose, 0.5);
	EXPECT_TRUE(pose.matrix().isApprox(representation->getPose().matrix())) << pose.matrix() << std::endl
																			<< representation->getPose().matrix();
}

TEST(PoseInterpolatorTests, UseOptionalStartPose)
{
	auto runtime = std::make_shared<SurgSim::Framework::Runtime>();
	auto representation = std::make_shared<PoseTestRepresentation>("representation");
	auto interpolator = std::make_shared<PoseInterpolator>("interpolator");

	representation->setInitialPose(startPose);
	interpolator->setEndingPose(endPose);
	interpolator->setTarget(representation);

	interpolator->initialize(runtime);
	interpolator->wakeUp();
	interpolator->update(0.0);

	EXPECT_TRUE(startPose.isApprox(representation->getPose()));
	interpolator->update(0.5);

	RigidTransform3d pose = interpolate(startPose, endPose, 0.5);
	EXPECT_TRUE(pose.matrix().isApprox(representation->getPose().matrix())) << pose.matrix() << std::endl
																			<< representation->getPose().matrix();
}

TEST(PoseInterpolatorTests, UseLoop)
{
	auto runtime = std::make_shared<SurgSim::Framework::Runtime>();
	auto representation = std::make_shared<PoseTestRepresentation>("representation");
	auto interpolator = std::make_shared<PoseInterpolator>("interpolator");

	interpolator->setStartingPose(startPose);
	interpolator->setEndingPose(endPose);
	interpolator->setTarget(representation);

	interpolator->setPingPong(true);
	interpolator->setLoop(true);

	// Enabling loop should disable pingpong
	EXPECT_TRUE(interpolator->isLoop());
	EXPECT_FALSE(interpolator->isPingPong());

	interpolator->initialize(runtime);
	interpolator->wakeUp();
	interpolator->update(0.0);

	EXPECT_TRUE(startPose.isApprox(representation->getPose()));
	interpolator->update(0.25);

	RigidTransform3d pose = interpolate(startPose, endPose, 0.25);
	EXPECT_TRUE(pose.matrix().isApprox(representation->getPose().matrix())) << pose.matrix() << std::endl
																			<< representation->getPose().matrix();

	// We advance by 1.0, this should wrap around to 0.25 again and the poses should be the same
	interpolator->update(1.0);
	EXPECT_TRUE(pose.matrix().isApprox(representation->getPose().matrix())) << pose.matrix() << std::endl
																			<< representation->getPose().matrix();

}

TEST(PoseInterpolatorTests, UsePingPong)
{
	auto runtime = std::make_shared<SurgSim::Framework::Runtime>();
	auto representation = std::make_shared<PoseTestRepresentation>("representation");
	auto interpolator = std::make_shared<PoseInterpolator>("interpolator");

	interpolator->setStartingPose(startPose);
	interpolator->setEndingPose(endPose);
	interpolator->setTarget(representation);

	interpolator->setLoop(true);
	interpolator->setPingPong(true);

	// Enabling PingPong should disable Loop
	EXPECT_FALSE(interpolator->isLoop());
	EXPECT_TRUE(interpolator->isPingPong());

	interpolator->initialize(runtime);
	interpolator->wakeUp();
	interpolator->update(0.0);

	EXPECT_TRUE(startPose.isApprox(representation->getPose()));
	interpolator->update(0.25);

	RigidTransform3d pose = interpolate(startPose, endPose, 0.25);
	EXPECT_TRUE(pose.matrix().isApprox(representation->getPose().matrix())) << pose.matrix() << std::endl
																			<< representation->getPose().matrix();

	// We advance by 1.0, this should wrap around to 0.25 and the poses should be flipped
	pose = interpolate(endPose, startPose, 0.25);
	interpolator->update(1.0);
	EXPECT_TRUE(pose.matrix().isApprox(representation->getPose().matrix())) << pose.matrix() << std::endl
																			<< representation->getPose().matrix();

}

}
}

<commit_msg>Add keyword 'explicit' to PoseTestRepresentation()<commit_after>// This file is a part of the OpenSurgSim project.
// Copyright 2013, SimQuest Solutions Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include <gtest/gtest.h>

#include "SurgSim/Blocks/PoseInterpolator.h"
#include "SurgSim/Framework/Runtime.h"
#include "SurgSim/Framework/Representation.h"
#include "SurgSim/Math/RigidTransform.h"
#include "SurgSim/Math/Vector.h"
#include "SurgSim/Math/Quaternion.h"

using SurgSim::Math::RigidTransform3d;
using SurgSim::Math::Quaterniond;
using SurgSim::Math::Vector3d;
using SurgSim::Math::makeRigidTransform;
using SurgSim::Math::interpolate;

namespace
{
	RigidTransform3d startPose = makeRigidTransform(Quaterniond::Identity(), Vector3d(1.0, 2.0, 3.0));
	RigidTransform3d endPose = makeRigidTransform(Quaterniond::Identity(), Vector3d(3.0, 2.0, 1.0));
}

class PoseTestRepresentation : public SurgSim::Framework::Representation
{
public:
	explicit PoseTestRepresentation(const std::string& name) : Representation(name)
	{
	}

	virtual void setInitialPose(const SurgSim::Math::RigidTransform3d& pose)
	{
		m_pose = pose;
	}

	virtual const SurgSim::Math::RigidTransform3d& getInitialPose() const
	{
		return m_pose;
	}

	virtual void setPose(const SurgSim::Math::RigidTransform3d& pose)
	{
		m_pose = pose;
	}

	virtual const SurgSim::Math::RigidTransform3d& getPose() const
	{
		return m_pose;
	}

private:
	RigidTransform3d m_pose;
};

namespace SurgSim
{
namespace Blocks
{

TEST(PoseInterpolatorTests, InitTest)
{
	ASSERT_NO_THROW({auto interpolator = std::make_shared<PoseInterpolator>("test");});
}

TEST(PoseInterpolatorTests, StartAndEndPose)
{
	auto runtime = std::make_shared<SurgSim::Framework::Runtime>();
	auto representation = std::make_shared<PoseTestRepresentation>("representation");
	auto interpolator = std::make_shared<PoseInterpolator>("interpolator");

	interpolator->setStartingPose(startPose);
	interpolator->setEndingPose(endPose);
	interpolator->setTarget(representation);

	interpolator->initialize(runtime);
	interpolator->wakeUp();
	interpolator->update(0.0);

	EXPECT_TRUE(startPose.isApprox(representation->getPose()));
	interpolator->update(0.5);

	RigidTransform3d pose = interpolate(startPose, endPose, 0.5);
	EXPECT_TRUE(pose.matrix().isApprox(representation->getPose().matrix())) << pose.matrix() << std::endl
																			<< representation->getPose().matrix();
}

TEST(PoseInterpolatorTests, UseOptionalStartPose)
{
	auto runtime = std::make_shared<SurgSim::Framework::Runtime>();
	auto representation = std::make_shared<PoseTestRepresentation>("representation");
	auto interpolator = std::make_shared<PoseInterpolator>("interpolator");

	representation->setInitialPose(startPose);
	interpolator->setEndingPose(endPose);
	interpolator->setTarget(representation);

	interpolator->initialize(runtime);
	interpolator->wakeUp();
	interpolator->update(0.0);

	EXPECT_TRUE(startPose.isApprox(representation->getPose()));
	interpolator->update(0.5);

	RigidTransform3d pose = interpolate(startPose, endPose, 0.5);
	EXPECT_TRUE(pose.matrix().isApprox(representation->getPose().matrix())) << pose.matrix() << std::endl
																			<< representation->getPose().matrix();
}

TEST(PoseInterpolatorTests, UseLoop)
{
	auto runtime = std::make_shared<SurgSim::Framework::Runtime>();
	auto representation = std::make_shared<PoseTestRepresentation>("representation");
	auto interpolator = std::make_shared<PoseInterpolator>("interpolator");

	interpolator->setStartingPose(startPose);
	interpolator->setEndingPose(endPose);
	interpolator->setTarget(representation);

	interpolator->setPingPong(true);
	interpolator->setLoop(true);

	// Enabling loop should disable pingpong
	EXPECT_TRUE(interpolator->isLoop());
	EXPECT_FALSE(interpolator->isPingPong());

	interpolator->initialize(runtime);
	interpolator->wakeUp();
	interpolator->update(0.0);

	EXPECT_TRUE(startPose.isApprox(representation->getPose()));
	interpolator->update(0.25);

	RigidTransform3d pose = interpolate(startPose, endPose, 0.25);
	EXPECT_TRUE(pose.matrix().isApprox(representation->getPose().matrix())) << pose.matrix() << std::endl
																			<< representation->getPose().matrix();

	// We advance by 1.0, this should wrap around to 0.25 again and the poses should be the same
	interpolator->update(1.0);
	EXPECT_TRUE(pose.matrix().isApprox(representation->getPose().matrix())) << pose.matrix() << std::endl
																			<< representation->getPose().matrix();

}

TEST(PoseInterpolatorTests, UsePingPong)
{
	auto runtime = std::make_shared<SurgSim::Framework::Runtime>();
	auto representation = std::make_shared<PoseTestRepresentation>("representation");
	auto interpolator = std::make_shared<PoseInterpolator>("interpolator");

	interpolator->setStartingPose(startPose);
	interpolator->setEndingPose(endPose);
	interpolator->setTarget(representation);

	interpolator->setLoop(true);
	interpolator->setPingPong(true);

	// Enabling PingPong should disable Loop
	EXPECT_FALSE(interpolator->isLoop());
	EXPECT_TRUE(interpolator->isPingPong());

	interpolator->initialize(runtime);
	interpolator->wakeUp();
	interpolator->update(0.0);

	EXPECT_TRUE(startPose.isApprox(representation->getPose()));
	interpolator->update(0.25);

	RigidTransform3d pose = interpolate(startPose, endPose, 0.25);
	EXPECT_TRUE(pose.matrix().isApprox(representation->getPose().matrix())) << pose.matrix() << std::endl
																			<< representation->getPose().matrix();

	// We advance by 1.0, this should wrap around to 0.25 and the poses should be flipped
	pose = interpolate(endPose, startPose, 0.25);
	interpolator->update(1.0);
	EXPECT_TRUE(pose.matrix().isApprox(representation->getPose().matrix())) << pose.matrix() << std::endl
																			<< representation->getPose().matrix();

}

};
};
<|endoftext|>


<commit_before>// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/chromeos/login/username_view.h"

#include "base/logging.h"
#include "base/utf_string_conversions.h"
#include "gfx/canvas.h"
#include "gfx/canvas_skia.h"
#include "gfx/rect.h"
#include "third_party/skia/include/core/SkComposeShader.h"
#include "third_party/skia/include/effects/SkGradientShader.h"
#include "views/background.h"

namespace {
// Username label background color.
const SkColor kLabelBackgoundColor = 0x55000000;
// Holds margin to height ratio.
const double kMarginRatio = 1.0 / 3.0;
}  // namespace

namespace chromeos {

UsernameView::UsernameView(const std::wstring& username)
    : views::Label(username) {
}

void UsernameView::Paint(gfx::Canvas* canvas) {
  gfx::Rect bounds = GetLocalBounds(false);
  if (!text_image_.get())
    PaintUsername(bounds);

  DCHECK(bounds.size() ==
         gfx::Size(text_image_->width(), text_image_->height()));

  // Only alpha channel counts.
  SkColor gradient_colors[2];
  gradient_colors[0] = 0xFFFFFFFF;
  gradient_colors[1] = 0x00FFFFFF;

  int gradient_start = std::min(margin_width_ + text_width_,
                                bounds.width() - bounds.height());

  SkPoint gradient_borders[2];
  gradient_borders[0].set(SkIntToScalar(gradient_start), SkIntToScalar(0));
  gradient_borders[1].set(SkIntToScalar(
      gradient_start + bounds.height()), SkIntToScalar(0));

  SkShader* gradient_shader =
      SkGradientShader::CreateLinear(gradient_borders, gradient_colors, NULL, 2,
                                     SkShader::kClamp_TileMode, NULL);
  SkShader* image_shader = SkShader::CreateBitmapShader(
      *text_image_,
      SkShader::kRepeat_TileMode,
      SkShader::kRepeat_TileMode);

  SkXfermode* mode = SkXfermode::Create(SkXfermode::kSrcIn_Mode);
  SkShader* composite_shader = new SkComposeShader(gradient_shader,
                                                   image_shader, mode);
  gradient_shader->unref();
  image_shader->unref();

  SkPaint paint;
  paint.setAntiAlias(true);
  paint.setFilterBitmap(true);
  paint.setShader(composite_shader)->unref();
  canvas->DrawRectInt(bounds.x(), bounds.y(),
                      bounds.width(), bounds.height(), paint);
}

void UsernameView::PaintUsername(const gfx::Rect& bounds) {
  margin_width_ = bounds.height() * kMarginRatio;
  gfx::CanvasSkia canvas(bounds.width(), bounds.height(), false);
  // Draw background.
  canvas.drawColor(kLabelBackgoundColor);
  // Calculate needed space.
  int flags = gfx::Canvas::TEXT_ALIGN_LEFT |
      gfx::Canvas::TEXT_VALIGN_MIDDLE |
      gfx::Canvas::NO_ELLIPSIS;
  int text_height;
  gfx::CanvasSkia::SizeStringInt(WideToUTF16Hack(GetText()), font(),
                                 &text_width_, &text_height,
                                 flags);
  text_width_ = std::min(text_width_, bounds.width() - margin_width_);
  // Draw the text.
  canvas.DrawStringInt(GetText(), font(), GetColor(),
                        bounds.x() + margin_width_, bounds.y(),
                        bounds.width() - margin_width_, bounds.height(),
                        flags);

  text_image_.reset(new SkBitmap(canvas.ExtractBitmap()));
  text_image_->buildMipMap(false);
}

}  // namespace chromeos
<commit_msg>Avoid green artifacts on the username label.<commit_after>// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/chromeos/login/username_view.h"

#include "base/logging.h"
#include "base/utf_string_conversions.h"
#include "gfx/canvas.h"
#include "gfx/canvas_skia.h"
#include "gfx/rect.h"
#include "third_party/skia/include/core/SkComposeShader.h"
#include "third_party/skia/include/effects/SkGradientShader.h"

namespace {
// Username label background color.
const SkColor kLabelBackgoundColor = 0x55000000;
// Holds margin to height ratio.
const double kMarginRatio = 1.0 / 3.0;
}  // namespace

namespace chromeos {

UsernameView::UsernameView(const std::wstring& username)
    : views::Label(username) {
}

void UsernameView::Paint(gfx::Canvas* canvas) {
  gfx::Rect bounds = GetLocalBounds(false);
  if (!text_image_.get())
    PaintUsername(bounds);

  DCHECK(bounds.size() ==
         gfx::Size(text_image_->width(), text_image_->height()));

  // Only alpha channel counts.
  SkColor gradient_colors[2];
  gradient_colors[0] = 0xFFFFFFFF;
  gradient_colors[1] = 0x00FFFFFF;

  int gradient_start = std::min(margin_width_ + text_width_,
                                bounds.width() - bounds.height());

  SkPoint gradient_borders[2];
  gradient_borders[0].set(SkIntToScalar(gradient_start), SkIntToScalar(0));
  gradient_borders[1].set(SkIntToScalar(
      gradient_start + bounds.height()), SkIntToScalar(0));

  SkShader* gradient_shader =
      SkGradientShader::CreateLinear(gradient_borders, gradient_colors, NULL, 2,
                                     SkShader::kClamp_TileMode, NULL);
  SkShader* image_shader = SkShader::CreateBitmapShader(
      *text_image_,
      SkShader::kRepeat_TileMode,
      SkShader::kRepeat_TileMode);

  SkXfermode* mode = SkXfermode::Create(SkXfermode::kSrcIn_Mode);
  SkShader* composite_shader = new SkComposeShader(gradient_shader,
                                                   image_shader, mode);
  gradient_shader->unref();
  image_shader->unref();

  SkPaint paint;
  paint.setAntiAlias(true);
  paint.setFilterBitmap(true);
  paint.setShader(composite_shader)->unref();
  canvas->DrawRectInt(bounds.x(), bounds.y(),
                      bounds.width(), bounds.height(), paint);
}

void UsernameView::PaintUsername(const gfx::Rect& bounds) {
  margin_width_ = bounds.height() * kMarginRatio;
  gfx::CanvasSkia canvas(bounds.width(), bounds.height(), false);
  // Draw background.
  canvas.drawColor(kLabelBackgoundColor);
  // Calculate needed space.
  int flags = gfx::Canvas::TEXT_ALIGN_LEFT |
      gfx::Canvas::TEXT_VALIGN_MIDDLE |
      gfx::Canvas::NO_ELLIPSIS;
  int text_height;
  gfx::CanvasSkia::SizeStringInt(WideToUTF16Hack(GetText()), font(),
                                 &text_width_, &text_height,
                                 flags);
  text_width_ = std::min(text_width_, bounds.width() - margin_width_);
  // Draw the text.
  // Note, direct call of the DrawStringInt method produces the green dots
  // along the text perimeter (when the label is place on the white background).
  SkColor kInvisibleHaloColor = 0x00000000;
  canvas.DrawStringWithHalo(GetText(), font(), GetColor(), kInvisibleHaloColor,
                            bounds.x() + margin_width_, bounds.y(),
                            bounds.width() - margin_width_, bounds.height(),
                            flags);

  text_image_.reset(new SkBitmap(canvas.ExtractBitmap()));
  text_image_->buildMipMap(false);
}

}  // namespace chromeos
<|endoftext|>


<commit_before>#include <iostream>
#include <vector>

using namespace std;

int main(){
    unsigned int i, j, g;
    int n;
    string s;
    bool newline = false;

    while (cin >> n && n != 0){
        if (newline) cout << endl;
        else newline = !newline;

        g = 0;
        vector<string> ss;
        while (n--){
            cin >> s;
            if (s.length() > g) g = s.length();
            ss.push_back(s);
        }

        for (i = 0; i < ss.size(); i++){
            for (j = 0; j < g - ss[i].length(); j++) cout << " ";
            cout << ss[i] << endl;
        }
    }

    return 0;
}
<commit_msg>Refatorando 1273.<commit_after>#include <iostream>
#include <iomanip>
#include <vector>

using namespace std;

int main(){
    unsigned int i, g;
    int n;
    string s;
    bool newline = false;

    while (cin >> n && n != 0){
        if (newline) cout << endl;
        else newline = !newline;

        g = 0;
        vector<string> ss;
        while (n--){
            cin >> s;
            if (s.length() > g) g = s.length();
            ss.push_back(s);
        }

        for (i = 0; i < ss.size(); i++){
            cout << setw(g);
            cout << ss[i] << endl;
        }
    }

    return 0;
}
<|endoftext|>


<commit_before>// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/debugger/devtools_window_win.h"

#include "chrome/browser/debugger/devtools_manager.h"
#include "chrome/browser/debugger/devtools_view.h"
#include "chrome/views/window.h"

// static
DevToolsWindow* DevToolsWindow::Create(DevToolsInstanceDescriptor* descriptor) {
  DevToolsView* view = new DevToolsView(descriptor);
  DevToolsWindowWin* window = new DevToolsWindowWin(view);
  descriptor->SetDevToolsWindow(window);
  views::Window::CreateChromeWindow(NULL, gfx::Rect(), window);
  return window;
}

DevToolsWindowWin::DevToolsWindowWin(DevToolsView* view)
    : tools_view_(view) {
}

DevToolsWindowWin::~DevToolsWindowWin() {
  DCHECK(!tools_view_);
}

void DevToolsWindowWin::Show() {
  if (window()) {
    window()->Show();
  } else {
    NOTREACHED();
  }
}

void DevToolsWindowWin::Close() {
  if (window()) {
    window()->Close();
  } else {
    NOTREACHED();
  }
}

std::wstring DevToolsWindowWin::GetWindowTitle() const {
  return L"Developer Tools";
}

void DevToolsWindowWin::WindowClosing() {
  if (tools_view_) {
    ReleaseWindow();
    tools_view_->OnWindowClosing();
    tools_view_ = NULL;
  } else {
    NOTREACHED() << "WindowClosing called twice.";
  }
}

bool DevToolsWindowWin::CanResize() const {
  return true;
}

views::View* DevToolsWindowWin::GetContentsView() {
  return tools_view_;
}

void DevToolsWindowWin::DeleteDelegate() {
  DCHECK(!tools_view_) << "WindowClosing should have been called.";
  delete this;
}
<commit_msg>bustage fix - file moved<commit_after>// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/debugger/devtools_window_win.h"

#include "chrome/browser/debugger/devtools_manager.h"
#include "chrome/browser/debugger/devtools_view.h"
#include "chrome/views/window/window.h"

// static
DevToolsWindow* DevToolsWindow::Create(DevToolsInstanceDescriptor* descriptor) {
  DevToolsView* view = new DevToolsView(descriptor);
  DevToolsWindowWin* window = new DevToolsWindowWin(view);
  descriptor->SetDevToolsWindow(window);
  views::Window::CreateChromeWindow(NULL, gfx::Rect(), window);
  return window;
}

DevToolsWindowWin::DevToolsWindowWin(DevToolsView* view)
    : tools_view_(view) {
}

DevToolsWindowWin::~DevToolsWindowWin() {
  DCHECK(!tools_view_);
}

void DevToolsWindowWin::Show() {
  if (window()) {
    window()->Show();
  } else {
    NOTREACHED();
  }
}

void DevToolsWindowWin::Close() {
  if (window()) {
    window()->Close();
  } else {
    NOTREACHED();
  }
}

std::wstring DevToolsWindowWin::GetWindowTitle() const {
  return L"Developer Tools";
}

void DevToolsWindowWin::WindowClosing() {
  if (tools_view_) {
    ReleaseWindow();
    tools_view_->OnWindowClosing();
    tools_view_ = NULL;
  } else {
    NOTREACHED() << "WindowClosing called twice.";
  }
}

bool DevToolsWindowWin::CanResize() const {
  return true;
}

views::View* DevToolsWindowWin::GetContentsView() {
  return tools_view_;
}

void DevToolsWindowWin::DeleteDelegate() {
  DCHECK(!tools_view_) << "WindowClosing should have been called.";
  delete this;
}
<|endoftext|>