1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "SolverComponent.hxx"
21 #include <strings.hrc>
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>
28 #include <cppuhelper/supportsservice.hxx>
30 #include <unotools/resmgr.hxx>
32 using namespace com::sun::star
;
35 #define STR_NONNEGATIVE "NonNegative"
36 #define STR_INTEGER "Integer"
37 #define STR_TIMEOUT "Timeout"
38 #define STR_EPSILONLEVEL "EpsilonLevel"
39 #define STR_LIMITBBDEPTH "LimitBBDepth"
42 // Resources from tools are used for translated strings
44 OUString
SolverComponent::GetResourceString(const char* pId
)
46 return Translate::get(pId
, Translate::Create("scc"));
49 size_t ScSolverCellHash::operator()( const css::table::CellAddress
& rAddress
) const
51 return ( rAddress
.Sheet
<< 24 ) | ( rAddress
.Column
<< 16 ) | rAddress
.Row
;
54 bool ScSolverCellEqual::operator()( const css::table::CellAddress
& rAddr1
, const css::table::CellAddress
& rAddr2
) const
56 return AddressEqual( rAddr1
, rAddr2
);
71 uno::Reference
<table::XCell
> SolverComponent::GetCell( const uno::Reference
<sheet::XSpreadsheetDocument
>& xDoc
,
72 const table::CellAddress
& rPos
)
74 uno::Reference
<container::XIndexAccess
> xSheets( xDoc
->getSheets(), uno::UNO_QUERY
);
75 uno::Reference
<sheet::XSpreadsheet
> xSheet( xSheets
->getByIndex( rPos
.Sheet
), uno::UNO_QUERY
);
76 return xSheet
->getCellByPosition( rPos
.Column
, rPos
.Row
);
79 void SolverComponent::SetValue( const uno::Reference
<sheet::XSpreadsheetDocument
>& xDoc
,
80 const table::CellAddress
& rPos
, double fValue
)
82 SolverComponent::GetCell( xDoc
, rPos
)->setValue( fValue
);
85 double SolverComponent::GetValue( const uno::Reference
<sheet::XSpreadsheetDocument
>& xDoc
,
86 const table::CellAddress
& rPos
)
88 return SolverComponent::GetCell( xDoc
, rPos
)->getValue();
91 SolverComponent::SolverComponent() :
92 OPropertyContainer( GetBroadcastHelper() ),
94 mbNonNegative( false ),
98 mbLimitBBDepth( true ),
102 // for XPropertySet implementation:
103 registerProperty( STR_NONNEGATIVE
, PROP_NONNEGATIVE
, 0, &mbNonNegative
, cppu::UnoType
<decltype(mbNonNegative
)>::get() );
104 registerProperty( STR_INTEGER
, PROP_INTEGER
, 0, &mbInteger
, cppu::UnoType
<decltype(mbInteger
)>::get() );
105 registerProperty( STR_TIMEOUT
, PROP_TIMEOUT
, 0, &mnTimeout
, cppu::UnoType
<decltype(mnTimeout
)>::get() );
106 registerProperty( STR_EPSILONLEVEL
, PROP_EPSILONLEVEL
, 0, &mnEpsilonLevel
, cppu::UnoType
<decltype(mnEpsilonLevel
)>::get() );
107 registerProperty( STR_LIMITBBDEPTH
, PROP_LIMITBBDEPTH
, 0, &mbLimitBBDepth
, cppu::UnoType
<decltype(mbLimitBBDepth
)>::get() );
110 SolverComponent::~SolverComponent()
114 IMPLEMENT_FORWARD_XINTERFACE2( SolverComponent
, SolverComponent_Base
, OPropertyContainer
)
115 IMPLEMENT_FORWARD_XTYPEPROVIDER2( SolverComponent
, SolverComponent_Base
, OPropertyContainer
)
117 cppu::IPropertyArrayHelper
* SolverComponent::createArrayHelper() const
119 uno::Sequence
<beans::Property
> aProps
;
120 describeProperties( aProps
);
121 return new cppu::OPropertyArrayHelper( aProps
);
124 cppu::IPropertyArrayHelper
& SAL_CALL
SolverComponent::getInfoHelper()
126 return *getArrayHelper();
129 uno::Reference
<beans::XPropertySetInfo
> SAL_CALL
SolverComponent::getPropertySetInfo()
131 return createPropertySetInfo( getInfoHelper() );
134 // XSolverDescription
136 OUString SAL_CALL
SolverComponent::getStatusDescription()
141 OUString SAL_CALL
SolverComponent::getPropertyDescription( const OUString
& rPropertyName
)
143 const char* pResId
= nullptr;
144 sal_Int32 nHandle
= getInfoHelper().getHandleByName( rPropertyName
);
147 case PROP_NONNEGATIVE
:
148 pResId
= RID_PROPERTY_NONNEGATIVE
;
151 pResId
= RID_PROPERTY_INTEGER
;
154 pResId
= RID_PROPERTY_TIMEOUT
;
156 case PROP_EPSILONLEVEL
:
157 pResId
= RID_PROPERTY_EPSILONLEVEL
;
159 case PROP_LIMITBBDEPTH
:
160 pResId
= RID_PROPERTY_LIMITBBDEPTH
;
164 // unknown - leave empty
169 aRet
= SolverComponent::GetResourceString(pResId
);
175 uno::Reference
<sheet::XSpreadsheetDocument
> SAL_CALL
SolverComponent::getDocument()
180 void SAL_CALL
SolverComponent::setDocument( const uno::Reference
<sheet::XSpreadsheetDocument
>& _document
)
185 table::CellAddress SAL_CALL
SolverComponent::getObjective()
190 void SAL_CALL
SolverComponent::setObjective( const table::CellAddress
& _objective
)
192 maObjective
= _objective
;
195 uno::Sequence
<table::CellAddress
> SAL_CALL
SolverComponent::getVariables()
200 void SAL_CALL
SolverComponent::setVariables( const uno::Sequence
<table::CellAddress
>& _variables
)
202 maVariables
= _variables
;
205 uno::Sequence
<sheet::SolverConstraint
> SAL_CALL
SolverComponent::getConstraints()
207 return maConstraints
;
210 void SAL_CALL
SolverComponent::setConstraints( const uno::Sequence
<sheet::SolverConstraint
>& _constraints
)
212 maConstraints
= _constraints
;
215 sal_Bool SAL_CALL
SolverComponent::getMaximize()
220 void SAL_CALL
SolverComponent::setMaximize( sal_Bool _maximize
)
222 mbMaximize
= _maximize
;
225 // XSolver: get results
227 sal_Bool SAL_CALL
SolverComponent::getSuccess()
232 double SAL_CALL
SolverComponent::getResultValue()
234 return mfResultValue
;
237 uno::Sequence
<double> SAL_CALL
SolverComponent::getSolution()
244 sal_Bool SAL_CALL
SolverComponent::supportsService( const OUString
& rServiceName
)
246 return cppu::supportsService(this, rServiceName
);
249 uno::Sequence
<OUString
> SAL_CALL
SolverComponent::getSupportedServiceNames()
251 return { "com.sun.star.sheet.Solver" };
254 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */