LibreOffice Module sccomp (master) 1
SolverComponent.cxx
Go to the documentation of this file.
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 <strings.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
29
30#include <unotools/resmgr.hxx>
31
32using namespace com::sun::star;
33
34
35constexpr OUStringLiteral STR_NONNEGATIVE = u"NonNegative";
36constexpr OUStringLiteral STR_INTEGER = u"Integer";
37constexpr OUStringLiteral STR_TIMEOUT = u"Timeout";
38constexpr OUStringLiteral STR_EPSILONLEVEL = u"EpsilonLevel";
39constexpr OUStringLiteral STR_LIMITBBDEPTH = u"LimitBBDepth";
40
41
42// Resources from tools are used for translated strings
43
45{
46 return Translate::get(aId, Translate::Create("scc"));
47}
48
49size_t ScSolverCellHash::operator()( const css::table::CellAddress& rAddress ) const
50{
51 return ( rAddress.Sheet << 24 ) | ( rAddress.Column << 16 ) | rAddress.Row;
52}
53
54bool ScSolverCellEqual::operator()( const css::table::CellAddress& rAddr1, const css::table::CellAddress& rAddr2 ) const
55{
56 return AddressEqual( rAddr1, rAddr2 );
57}
58
59namespace
60{
61 enum
62 {
63 PROP_NONNEGATIVE,
64 PROP_INTEGER,
65 PROP_TIMEOUT,
66 PROP_EPSILONLEVEL,
67 PROP_LIMITBBDEPTH
68 };
69}
70
71uno::Reference<table::XCell> SolverComponent::GetCell( const uno::Reference<sheet::XSpreadsheetDocument>& xDoc,
72 const table::CellAddress& rPos )
73{
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 );
77}
78
79void SolverComponent::SetValue( const uno::Reference<sheet::XSpreadsheetDocument>& xDoc,
80 const table::CellAddress& rPos, double fValue )
81{
82 SolverComponent::GetCell( xDoc, rPos )->setValue( fValue );
83}
84
85double SolverComponent::GetValue( const uno::Reference<sheet::XSpreadsheetDocument>& xDoc,
86 const table::CellAddress& rPos )
87{
88 return SolverComponent::GetCell( xDoc, rPos )->getValue();
89}
90
92 OPropertyContainer( GetBroadcastHelper() ),
93 mbMaximize( true ),
94 mbNonNegative( false ),
95 mbInteger( false ),
96 mnTimeout( 100 ),
97 mnEpsilonLevel( 0 ),
98 mbLimitBBDepth( true ),
99 mbSuccess( false ),
100 mfResultValue( 0.0 )
101{
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() );
108}
109
111{
112}
113
116
117cppu::IPropertyArrayHelper* SolverComponent::createArrayHelper() const
118{
119 uno::Sequence<beans::Property> aProps;
120 describeProperties( aProps );
121 return new cppu::OPropertyArrayHelper( aProps );
122}
123
125{
126 return *getArrayHelper();
127}
128
129uno::Reference<beans::XPropertySetInfo> SAL_CALL SolverComponent::getPropertySetInfo()
130{
131 return createPropertySetInfo( getInfoHelper() );
132}
133
134// XSolverDescription
135
137{
138 return maStatus;
139}
140
141OUString SAL_CALL SolverComponent::getPropertyDescription( const OUString& rPropertyName )
142{
143 TranslateId pResId;
144 sal_Int32 nHandle = getInfoHelper().getHandleByName( rPropertyName );
145 switch (nHandle)
146 {
147 case PROP_NONNEGATIVE:
148 pResId = RID_PROPERTY_NONNEGATIVE;
149 break;
150 case PROP_INTEGER:
151 pResId = RID_PROPERTY_INTEGER;
152 break;
153 case PROP_TIMEOUT:
154 pResId = RID_PROPERTY_TIMEOUT;
155 break;
156 case PROP_EPSILONLEVEL:
157 pResId = RID_PROPERTY_EPSILONLEVEL;
158 break;
159 case PROP_LIMITBBDEPTH:
160 pResId = RID_PROPERTY_LIMITBBDEPTH;
161 break;
162 default:
163 {
164 // unknown - leave empty
165 }
166 }
167 OUString aRet;
168 if (pResId)
170 return aRet;
171}
172
173// XSolver: settings
174
175uno::Reference<sheet::XSpreadsheetDocument> SAL_CALL SolverComponent::getDocument()
176{
177 return mxDoc;
178}
179
180void SAL_CALL SolverComponent::setDocument( const uno::Reference<sheet::XSpreadsheetDocument>& _document )
181{
182 mxDoc = _document;
183}
184
185table::CellAddress SAL_CALL SolverComponent::getObjective()
186{
187 return maObjective;
188}
189
190void SAL_CALL SolverComponent::setObjective( const table::CellAddress& _objective )
191{
192 maObjective = _objective;
193}
194
195uno::Sequence<table::CellAddress> SAL_CALL SolverComponent::getVariables()
196{
197 return maVariables;
198}
199
200void SAL_CALL SolverComponent::setVariables( const uno::Sequence<table::CellAddress>& _variables )
201{
202 maVariables = _variables;
203}
204
205uno::Sequence<sheet::SolverConstraint> SAL_CALL SolverComponent::getConstraints()
206{
207 return maConstraints;
208}
209
210void SAL_CALL SolverComponent::setConstraints( const uno::Sequence<sheet::SolverConstraint>& _constraints )
211{
212 maConstraints = _constraints;
213}
214
216{
217 return mbMaximize;
218}
219
220void SAL_CALL SolverComponent::setMaximize( sal_Bool _maximize )
221{
222 mbMaximize = _maximize;
223}
224
225// XSolver: get results
226
228{
229 return mbSuccess;
230}
231
233{
234 return mfResultValue;
235}
236
237uno::Sequence<double> SAL_CALL SolverComponent::getSolution()
238{
239 return maSolution;
240}
241
242// XServiceInfo
243
244sal_Bool SAL_CALL SolverComponent::supportsService( const OUString& rServiceName )
245{
246 return cppu::supportsService(this, rServiceName);
247}
248
249uno::Sequence<OUString> SAL_CALL SolverComponent::getSupportedServiceNames()
250{
251 return { "com.sun.star.sheet.Solver" };
252}
253
254/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
constexpr OUStringLiteral STR_TIMEOUT
constexpr OUStringLiteral STR_INTEGER
constexpr OUStringLiteral STR_NONNEGATIVE
constexpr OUStringLiteral STR_LIMITBBDEPTH
constexpr OUStringLiteral STR_EPSILONLEVEL
cppu::WeakImplHelper< css::sheet::XSolver, css::sheet::XSolverDescription, css::lang::XServiceInfo > SolverComponent_Base
bool AddressEqual(const css::table::CellAddress &rAddr1, const css::table::CellAddress &rAddr2)
virtual css::uno::Sequence< css::sheet::SolverConstraint > SAL_CALL getConstraints() override
virtual css::uno::Sequence< css::table::CellAddress > SAL_CALL getVariables() override
virtual ::cppu::IPropertyArrayHelper &SAL_CALL getInfoHelper() override
virtual void SAL_CALL setVariables(const css::uno::Sequence< css::table::CellAddress > &_variables) override
virtual sal_Bool SAL_CALL getSuccess() override
virtual sal_Bool SAL_CALL getMaximize() override
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
sal_Int32 mnEpsilonLevel
virtual css::uno::Reference< css::sheet::XSpreadsheetDocument > SAL_CALL getDocument() override
virtual double SAL_CALL getResultValue() override
css::uno::Sequence< double > maSolution
virtual ~SolverComponent() override
static css::uno::Reference< css::table::XCell > GetCell(const css::uno::Reference< css::sheet::XSpreadsheetDocument > &xDoc, const css::table::CellAddress &rPos)
virtual OUString SAL_CALL getPropertyDescription(const OUString &aPropertyName) override
css::uno::Reference< css::sheet::XSpreadsheetDocument > mxDoc
css::uno::Sequence< css::sheet::SolverConstraint > maConstraints
css::table::CellAddress maObjective
static double GetValue(const css::uno::Reference< css::sheet::XSpreadsheetDocument > &xDoc, const css::table::CellAddress &rPos)
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
static void SetValue(const css::uno::Reference< css::sheet::XSpreadsheetDocument > &xDoc, const css::table::CellAddress &rPos, double fValue)
virtual void SAL_CALL setObjective(const css::table::CellAddress &_objective) override
static OUString GetResourceString(TranslateId aId)
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual OUString SAL_CALL getStatusDescription() override
virtual css::uno::Sequence< double > SAL_CALL getSolution() override
css::uno::Sequence< css::table::CellAddress > maVariables
virtual css::table::CellAddress SAL_CALL getObjective() override
virtual void SAL_CALL setDocument(const css::uno::Reference< css::sheet::XSpreadsheetDocument > &_document) override
virtual void SAL_CALL setConstraints(const css::uno::Sequence< css::sheet::SolverConstraint > &_constraints) override
virtual void SAL_CALL setMaximize(sal_Bool _maximize) override
void registerProperty(const OUString &_rName, sal_Int32 _nHandle, sal_Int32 _nAttributes, void *_pPointerToMember, const css::uno::Type &_rMemberType)
virtual sal_Int32 SAL_CALL getHandleByName(const ::rtl::OUString &rPropertyName)=0
float u
std::locale Create(std::string_view aPrefixName, const LanguageTag &rLocale)
OUString get(TranslateId sContextAndId, const std::locale &loc)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
IMPLEMENT_FORWARD_XTYPEPROVIDER2(ChildWindowPane, ChildWindowPaneInterfaceBase, Pane)
IMPLEMENT_FORWARD_XINTERFACE2(ChildWindowPane, ChildWindowPaneInterfaceBase, Pane)
sal_Int32 nHandle
bool mbSuccess
bool operator()(const css::table::CellAddress &rAddr1, const css::table::CellAddress &rAddr2) const
size_t operator()(const css::table::CellAddress &rAddress) const
unsigned char sal_Bool