LCOV - code coverage report
Current view: top level - sccomp/source/solver - SolverComponent.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 95 0.0 %
Date: 2015-06-13 12:38:46 Functions: 0 34 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include "SolverComponent.hxx"
      21             : #include "solver.hrc"
      22             : 
      23             : #include <com/sun/star/container/XIndexAccess.hpp>
      24             : #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
      25             : #include <com/sun/star/sheet/XSpreadsheet.hpp>
      26             : #include <com/sun/star/table/CellAddress.hpp>
      27             : 
      28             : #include <cppuhelper/supportsservice.hxx>
      29             : #include <vector>
      30             : 
      31             : #include <tools/resmgr.hxx>
      32             : 
      33             : using namespace com::sun::star;
      34             : 
      35             : 
      36             : #define STR_NONNEGATIVE   "NonNegative"
      37             : #define STR_INTEGER       "Integer"
      38             : #define STR_TIMEOUT       "Timeout"
      39             : #define STR_EPSILONLEVEL  "EpsilonLevel"
      40             : #define STR_LIMITBBDEPTH  "LimitBBDepth"
      41             : 
      42             : 
      43             : //  Resources from tools are used for translated strings
      44             : 
      45             : ResMgr* SolverComponent::pSolverResMgr = NULL;
      46             : 
      47           0 : OUString SolverComponent::GetResourceString( sal_uInt32 nId )
      48             : {
      49           0 :     if (!pSolverResMgr)
      50           0 :         pSolverResMgr = ResMgr::CreateResMgr("solver");
      51             : 
      52           0 :     return ResId(nId, *pSolverResMgr).toString();
      53             : }
      54             : 
      55           0 : size_t ScSolverCellHash::operator()( const css::table::CellAddress& rAddress ) const
      56             : {
      57           0 :     return ( rAddress.Sheet << 24 ) | ( rAddress.Column << 16 ) | rAddress.Row;
      58             : }
      59             : 
      60           0 : bool ScSolverCellEqual::operator()( const css::table::CellAddress& rAddr1, const css::table::CellAddress& rAddr2 ) const
      61             : {
      62           0 :     return AddressEqual( rAddr1, rAddr2 );
      63             : }
      64             : 
      65             : namespace
      66             : {
      67             :     enum
      68             :     {
      69             :         PROP_NONNEGATIVE,
      70             :         PROP_INTEGER,
      71             :         PROP_TIMEOUT,
      72             :         PROP_EPSILONLEVEL,
      73             :         PROP_LIMITBBDEPTH
      74             :     };
      75             : }
      76             : 
      77           0 : uno::Reference<table::XCell> SolverComponent::GetCell( const uno::Reference<sheet::XSpreadsheetDocument>& xDoc,
      78             :                                           const table::CellAddress& rPos )
      79             : {
      80           0 :     uno::Reference<container::XIndexAccess> xSheets( xDoc->getSheets(), uno::UNO_QUERY );
      81           0 :     uno::Reference<sheet::XSpreadsheet> xSheet( xSheets->getByIndex( rPos.Sheet ), uno::UNO_QUERY );
      82           0 :     return xSheet->getCellByPosition( rPos.Column, rPos.Row );
      83             : }
      84             : 
      85           0 : void SolverComponent::SetValue( const uno::Reference<sheet::XSpreadsheetDocument>& xDoc,
      86             :                    const table::CellAddress& rPos, double fValue )
      87             : {
      88           0 :     SolverComponent::GetCell( xDoc, rPos )->setValue( fValue );
      89           0 : }
      90             : 
      91           0 : double SolverComponent::GetValue( const uno::Reference<sheet::XSpreadsheetDocument>& xDoc,
      92             :                      const table::CellAddress& rPos )
      93             : {
      94           0 :     return SolverComponent::GetCell( xDoc, rPos )->getValue();
      95             : }
      96             : 
      97           0 : SolverComponent::SolverComponent() :
      98           0 :     OPropertyContainer( GetBroadcastHelper() ),
      99             :     mbMaximize( true ),
     100             :     mbNonNegative( false ),
     101             :     mbInteger( false ),
     102             :     mnTimeout( 100 ),
     103             :     mnEpsilonLevel( 0 ),
     104             :     mbLimitBBDepth( true ),
     105             :     mbSuccess( false ),
     106           0 :     mfResultValue( 0.0 )
     107             : {
     108             :     // for XPropertySet implementation:
     109           0 :     registerProperty( STR_NONNEGATIVE,  PROP_NONNEGATIVE,  0, &mbNonNegative,  cppu::UnoType<decltype(mbNonNegative)>::get()  );
     110           0 :     registerProperty( STR_INTEGER,      PROP_INTEGER,      0, &mbInteger,      cppu::UnoType<decltype(mbInteger)>::get()      );
     111           0 :     registerProperty( STR_TIMEOUT,      PROP_TIMEOUT,      0, &mnTimeout,      cppu::UnoType<decltype(mnTimeout)>::get()      );
     112           0 :     registerProperty( STR_EPSILONLEVEL, PROP_EPSILONLEVEL, 0, &mnEpsilonLevel, cppu::UnoType<decltype(mnEpsilonLevel)>::get() );
     113           0 :     registerProperty( STR_LIMITBBDEPTH, PROP_LIMITBBDEPTH, 0, &mbLimitBBDepth, cppu::UnoType<decltype(mbLimitBBDepth)>::get() );
     114           0 : }
     115             : 
     116           0 : SolverComponent::~SolverComponent()
     117             : {
     118           0 : }
     119             : 
     120           0 : IMPLEMENT_FORWARD_XINTERFACE2( SolverComponent, SolverComponent_Base, OPropertyContainer )
     121           0 : IMPLEMENT_FORWARD_XTYPEPROVIDER2( SolverComponent, SolverComponent_Base, OPropertyContainer )
     122             : 
     123           0 : cppu::IPropertyArrayHelper* SolverComponent::createArrayHelper() const
     124             : {
     125           0 :     uno::Sequence<beans::Property> aProps;
     126           0 :     describeProperties( aProps );
     127           0 :     return new cppu::OPropertyArrayHelper( aProps );
     128             : }
     129             : 
     130           0 : cppu::IPropertyArrayHelper& SAL_CALL SolverComponent::getInfoHelper()
     131             : {
     132           0 :     return *getArrayHelper();
     133             : }
     134             : 
     135           0 : uno::Reference<beans::XPropertySetInfo> SAL_CALL SolverComponent::getPropertySetInfo() throw(uno::RuntimeException, std::exception)
     136             : {
     137           0 :     return createPropertySetInfo( getInfoHelper() );
     138             : }
     139             : 
     140             : // XSolverDescription
     141             : 
     142           0 : OUString SAL_CALL SolverComponent::getStatusDescription() throw (uno::RuntimeException, std::exception)
     143             : {
     144           0 :     return maStatus;
     145             : }
     146             : 
     147           0 : OUString SAL_CALL SolverComponent::getPropertyDescription( const OUString& rPropertyName ) throw (uno::RuntimeException, std::exception)
     148             : {
     149           0 :     sal_uInt32 nResId = 0;
     150           0 :     sal_Int32 nHandle = getInfoHelper().getHandleByName( rPropertyName );
     151           0 :     switch (nHandle)
     152             :     {
     153             :         case PROP_NONNEGATIVE:
     154           0 :             nResId = RID_PROPERTY_NONNEGATIVE;
     155           0 :             break;
     156             :         case PROP_INTEGER:
     157           0 :             nResId = RID_PROPERTY_INTEGER;
     158           0 :             break;
     159             :         case PROP_TIMEOUT:
     160           0 :             nResId = RID_PROPERTY_TIMEOUT;
     161           0 :             break;
     162             :         case PROP_EPSILONLEVEL:
     163           0 :             nResId = RID_PROPERTY_EPSILONLEVEL;
     164           0 :             break;
     165             :         case PROP_LIMITBBDEPTH:
     166           0 :             nResId = RID_PROPERTY_LIMITBBDEPTH;
     167           0 :             break;
     168             :         default:
     169             :             {
     170             :                 // unknown - leave empty
     171             :             }
     172             :     }
     173           0 :     OUString aRet;
     174           0 :     if ( nResId )
     175           0 :         aRet = SolverComponent::GetResourceString( nResId );
     176           0 :     return aRet;
     177             : }
     178             : 
     179             : // XSolver: settings
     180             : 
     181           0 : uno::Reference<sheet::XSpreadsheetDocument> SAL_CALL SolverComponent::getDocument() throw(uno::RuntimeException, std::exception)
     182             : {
     183           0 :     return mxDoc;
     184             : }
     185             : 
     186           0 : void SAL_CALL SolverComponent::setDocument( const uno::Reference<sheet::XSpreadsheetDocument>& _document )
     187             :                                 throw(uno::RuntimeException, std::exception)
     188             : {
     189           0 :     mxDoc = _document;
     190           0 : }
     191             : 
     192           0 : table::CellAddress SAL_CALL SolverComponent::getObjective() throw(uno::RuntimeException, std::exception)
     193             : {
     194           0 :     return maObjective;
     195             : }
     196             : 
     197           0 : void SAL_CALL SolverComponent::setObjective( const table::CellAddress& _objective ) throw(uno::RuntimeException, std::exception)
     198             : {
     199           0 :     maObjective = _objective;
     200           0 : }
     201             : 
     202           0 : uno::Sequence<table::CellAddress> SAL_CALL SolverComponent::getVariables() throw(uno::RuntimeException, std::exception)
     203             : {
     204           0 :     return maVariables;
     205             : }
     206             : 
     207           0 : void SAL_CALL SolverComponent::setVariables( const uno::Sequence<table::CellAddress>& _variables )
     208             :                                 throw(uno::RuntimeException, std::exception)
     209             : {
     210           0 :     maVariables = _variables;
     211           0 : }
     212             : 
     213           0 : uno::Sequence<sheet::SolverConstraint> SAL_CALL SolverComponent::getConstraints() throw(uno::RuntimeException, std::exception)
     214             : {
     215           0 :     return maConstraints;
     216             : }
     217             : 
     218           0 : void SAL_CALL SolverComponent::setConstraints( const uno::Sequence<sheet::SolverConstraint>& _constraints )
     219             :                                 throw(uno::RuntimeException, std::exception)
     220             : {
     221           0 :     maConstraints = _constraints;
     222           0 : }
     223             : 
     224           0 : sal_Bool SAL_CALL SolverComponent::getMaximize() throw(uno::RuntimeException, std::exception)
     225             : {
     226           0 :     return mbMaximize;
     227             : }
     228             : 
     229           0 : void SAL_CALL SolverComponent::setMaximize( sal_Bool _maximize ) throw(uno::RuntimeException, std::exception)
     230             : {
     231           0 :     mbMaximize = _maximize;
     232           0 : }
     233             : 
     234             : // XSolver: get results
     235             : 
     236           0 : sal_Bool SAL_CALL SolverComponent::getSuccess() throw(uno::RuntimeException, std::exception)
     237             : {
     238           0 :     return mbSuccess;
     239             : }
     240             : 
     241           0 : double SAL_CALL SolverComponent::getResultValue() throw(uno::RuntimeException, std::exception)
     242             : {
     243           0 :     return mfResultValue;
     244             : }
     245             : 
     246           0 : uno::Sequence<double> SAL_CALL SolverComponent::getSolution() throw(uno::RuntimeException, std::exception)
     247             : {
     248           0 :     return maSolution;
     249             : }
     250             : 
     251             : // XServiceInfo
     252             : 
     253           0 : sal_Bool SAL_CALL SolverComponent::supportsService( const OUString& rServiceName ) throw(uno::RuntimeException, std::exception)
     254             : {
     255           0 :     return cppu::supportsService(this, rServiceName);
     256             : }
     257             : 
     258           0 : uno::Sequence<OUString> SAL_CALL SolverComponent::getSupportedServiceNames() throw(uno::RuntimeException, std::exception)
     259             : {
     260           0 :     uno::Sequence< OUString > aServiceNames( 1 );
     261           0 :     aServiceNames[ 0 ] = "com.sun.star.sheet.Solver";
     262           0 :     return aServiceNames;
     263             : }
     264             : 
     265             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11