LibreOffice Module sc (master) 1
optsolver.hxx
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#pragma once
21
22#include <address.hxx>
23#include "anyrefdg.hxx"
24#include "docsh.hxx"
25#include <SolverSettings.hxx>
26#include <com/sun/star/uno/Sequence.hxx>
27
28#include <string_view>
29#include <vector>
30
31namespace com::sun::star {
32 namespace beans { struct PropertyValue; }
33}
34
36{
39
40public:
41 ScCursorRefEdit(std::unique_ptr<weld::Entry> xEntry);
43
44protected:
45 DECL_LINK(KeyInputHdl, const KeyEvent&, bool);
46};
47
49
51{
52public:
54 ScDocShell* pDocSh, const ScAddress& aCursorPos );
55 virtual ~ScOptSolverDlg() override;
56
57 virtual void SetReference( const ScRange& rRef, ScDocument& rDoc ) override;
58 virtual bool IsRefInputMode() const override;
59 virtual void SetActive() override;
60 virtual void Close() override;
61
62private:
63 OUString maInputError;
65
70
71 std::vector<sc::ModelConstraint> m_aConditions;
73
74 css::uno::Sequence<OUString> maImplNames;
75 css::uno::Sequence<OUString> maDescriptions;
76 OUString maEngine;
77 css::uno::Sequence<css::beans::PropertyValue> maProperties;
78
79 static const sal_uInt16 EDIT_ROW_COUNT = 4;
86
88
89 std::unique_ptr<weld::Label> m_xFtObjectiveCell;
90 std::unique_ptr<formula::RefEdit> m_xEdObjectiveCell;
91 std::unique_ptr<formula::RefButton> m_xRBObjectiveCell;
92
93 std::unique_ptr<weld::RadioButton> m_xRbMax;
94 std::unique_ptr<weld::RadioButton> m_xRbMin;
95 std::unique_ptr<weld::RadioButton> m_xRbValue;
96 std::unique_ptr<formula::RefEdit> m_xEdTargetValue;
97 std::unique_ptr<formula::RefButton> m_xRBTargetValue;
98
99 std::unique_ptr<weld::Label> m_xFtVariableCells;
100 std::unique_ptr<formula::RefEdit> m_xEdVariableCells;
101 std::unique_ptr<formula::RefButton> m_xRBVariableCells;
102
103 std::unique_ptr<weld::Label> m_xFtCellRef; // labels are together with controls for the first row
104 std::unique_ptr<ScCursorRefEdit> m_xEdLeft1;
105 std::unique_ptr<formula::RefButton> m_xRBLeft1;
106 std::unique_ptr<weld::ComboBox> m_xLbOp1;
107 std::unique_ptr<weld::Label> m_xFtConstraint;
108 std::unique_ptr<ScCursorRefEdit> m_xEdRight1;
109 std::unique_ptr<formula::RefButton> m_xRBRight1;
110 std::unique_ptr<weld::Button> m_xBtnDel1;
111
112 std::unique_ptr<ScCursorRefEdit> m_xEdLeft2;
113 std::unique_ptr<formula::RefButton> m_xRBLeft2;
114 std::unique_ptr<weld::ComboBox> m_xLbOp2;
115 std::unique_ptr<ScCursorRefEdit> m_xEdRight2;
116 std::unique_ptr<formula::RefButton> m_xRBRight2;
117 std::unique_ptr<weld::Button> m_xBtnDel2;
118
119 std::unique_ptr<ScCursorRefEdit> m_xEdLeft3;
120 std::unique_ptr<formula::RefButton> m_xRBLeft3;
121 std::unique_ptr<weld::ComboBox> m_xLbOp3;
122 std::unique_ptr<ScCursorRefEdit> m_xEdRight3;
123 std::unique_ptr<formula::RefButton> m_xRBRight3;
124 std::unique_ptr<weld::Button> m_xBtnDel3;
125
126 std::unique_ptr<ScCursorRefEdit> m_xEdLeft4;
127 std::unique_ptr<formula::RefButton> m_xRBLeft4;
128 std::unique_ptr<weld::ComboBox> m_xLbOp4;
129 std::unique_ptr<ScCursorRefEdit> m_xEdRight4;
130 std::unique_ptr<formula::RefButton> m_xRBRight4;
131 std::unique_ptr<weld::Button> m_xBtnDel4;
132
133 std::unique_ptr<weld::ScrolledWindow> m_xScrollBar;
134
135 std::unique_ptr<weld::Button> m_xBtnOpt;
136 std::unique_ptr<weld::Button> m_xBtnClose;
137 std::unique_ptr<weld::Button> m_xBtnSolve;
138 std::unique_ptr<weld::Button> m_xBtnResetAll;
139
140 std::unique_ptr<weld::Label> m_xResultFT;
141 std::unique_ptr<weld::Widget> m_xContents;
142
143 std::shared_ptr<ScSolverOptionsDialog> m_xOptDlg;
144 std::shared_ptr<sc::SolverSettings> m_pSolverSettings;
145
146 void Init(const ScAddress& rCursorPos);
147 bool CallSolver();
148 void ReadConditions();
149 void ShowConditions();
150 void EnableButtons();
151 bool ParseRef( ScRange& rRange, const OUString& rInput, bool bAllowRange );
152 bool FindTimeout( sal_Int32& rTimeout );
153 void ShowError( bool bCondition, formula::RefEdit* pFocus );
154 void LoadSolverSettings();
155 void SaveSolverSettings();
156 bool IsEngineAvailable(std::u16string_view sEngineName);
157
159
160 DECL_LINK( BtnHdl, weld::Button&, void );
161 DECL_LINK( DelBtnHdl, weld::Button&, void );
162 DECL_LINK( GetEditFocusHdl, formula::RefEdit&, void );
163 DECL_LINK( GetButtonFocusHdl, formula::RefButton&, void );
164 DECL_LINK( GetFocusHdl, weld::Widget&, void );
165 DECL_LINK( LoseEditFocusHdl, formula::RefEdit&, void );
166 DECL_LINK( LoseButtonFocusHdl, formula::RefButton&, void );
167 DECL_LINK( ScrollHdl, weld::ScrolledWindow&, void);
168 DECL_LINK( CursorUpHdl, ScCursorRefEdit&, void );
169 DECL_LINK( CursorDownHdl, ScCursorRefEdit&, void );
170 DECL_LINK( CondModifyHdl, formula::RefEdit&, void );
171 DECL_LINK( TargetModifyHdl, formula::RefEdit&, void );
172 DECL_LINK( SelectHdl, weld::ComboBox&, void );
173};
174
176{
177 std::unique_ptr<weld::Label> m_xFtTime;
178
179public:
181 virtual ~ScSolverProgressDialog() override;
182
183 void HideTimeLimit();
184 void SetTimeLimit( sal_Int32 nSeconds );
185};
186
188{
189 std::unique_ptr<weld::Label> m_xFtErrorText;
190
191public:
192 ScSolverNoSolutionDialog(weld::Window* pParent, const OUString& rErrorText);
193 virtual ~ScSolverNoSolutionDialog() override;
194};
195
197{
198 std::unique_ptr<weld::Label> m_xFtResult;
199 std::unique_ptr<weld::Button> m_xBtnOk;
200 std::unique_ptr<weld::Button> m_xBtnCancel;
201
202 DECL_LINK(ClickHdl, weld::Button&, void);
203
204public:
205 ScSolverSuccessDialog(weld::Window* pParent, std::u16string_view rSolution);
206 virtual ~ScSolverSuccessDialog() override;
207};
208
209/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void SetCursorLinks(const Link< ScCursorRefEdit &, void > &rUp, const Link< ScCursorRefEdit &, void > &rDown)
Definition: optsolver.cxx:114
Link< ScCursorRefEdit &, void > maCursorDownLink
Definition: optsolver.hxx:38
DECL_LINK(KeyInputHdl, const KeyEvent &, bool)
ScCursorRefEdit(std::unique_ptr< weld::Entry > xEntry)
Definition: optsolver.cxx:107
Link< ScCursorRefEdit &, void > maCursorUpLink
Definition: optsolver.hxx:37
std::shared_ptr< sc::SolverSettings > m_pSolverSettings
Definition: optsolver.hxx:144
bool CallSolver()
Definition: optsolver.cxx:860
std::unique_ptr< weld::Widget > m_xContents
Definition: optsolver.hxx:141
std::unique_ptr< formula::RefButton > m_xRBRight3
Definition: optsolver.hxx:123
std::unique_ptr< formula::RefButton > m_xRBRight1
Definition: optsolver.hxx:109
void Init(const ScAddress &rCursorPos)
Definition: optsolver.cxx:252
std::unique_ptr< ScCursorRefEdit > m_xEdLeft4
Definition: optsolver.hxx:126
virtual ~ScOptSolverDlg() override
Definition: optsolver.cxx:248
css::uno::Sequence< OUString > maDescriptions
Definition: optsolver.hxx:75
std::unique_ptr< ScCursorRefEdit > m_xEdLeft2
Definition: optsolver.hxx:112
DECL_LINK(SelectHdl, weld::ComboBox &, void)
void ShowError(bool bCondition, formula::RefEdit *pFocus)
Definition: optsolver.cxx:811
void LoadSolverSettings()
Definition: optsolver.cxx:479
std::unique_ptr< weld::RadioButton > m_xRbValue
Definition: optsolver.hxx:95
std::unique_ptr< weld::RadioButton > m_xRbMin
Definition: optsolver.hxx:94
DECL_LINK(LoseButtonFocusHdl, formula::RefButton &, void)
std::unique_ptr< formula::RefButton > m_xRBTargetValue
Definition: optsolver.hxx:97
weld::ComboBox * mpOperator[EDIT_ROW_COUNT]
Definition: optsolver.hxx:84
tools::Long nScrollPos
Definition: optsolver.hxx:72
std::unique_ptr< weld::Button > m_xBtnResetAll
Definition: optsolver.hxx:138
std::unique_ptr< ScCursorRefEdit > m_xEdLeft3
Definition: optsolver.hxx:119
std::unique_ptr< formula::RefButton > m_xRBRight2
Definition: optsolver.hxx:116
std::unique_ptr< weld::Button > m_xBtnClose
Definition: optsolver.hxx:136
bool ParseRef(ScRange &rRange, const OUString &rInput, bool bAllowRange)
Definition: optsolver.cxx:825
ScDocument & mrDoc
Definition: optsolver.hxx:67
formula::RefEdit * mpEdActive
Definition: optsolver.hxx:87
std::unique_ptr< weld::ComboBox > m_xLbOp2
Definition: optsolver.hxx:114
std::unique_ptr< weld::RadioButton > m_xRbMax
Definition: optsolver.hxx:93
static const sal_uInt16 EDIT_ROW_COUNT
Definition: optsolver.hxx:79
std::unique_ptr< weld::Button > m_xBtnDel2
Definition: optsolver.hxx:117
std::unique_ptr< formula::RefEdit > m_xEdVariableCells
Definition: optsolver.hxx:100
std::unique_ptr< formula::RefEdit > m_xEdObjectiveCell
Definition: optsolver.hxx:90
bool FindTimeout(sal_Int32 &rTimeout)
Definition: optsolver.cxx:843
std::unique_ptr< formula::RefButton > m_xRBLeft1
Definition: optsolver.hxx:105
std::unique_ptr< weld::Button > m_xBtnDel3
Definition: optsolver.hxx:124
virtual void SetActive() override
Definition: optsolver.cxx:407
std::unique_ptr< weld::ComboBox > m_xLbOp1
Definition: optsolver.hxx:106
ScDocShell * mpDocShell
Definition: optsolver.hxx:66
ScCursorRefEdit * mpRightEdit[EDIT_ROW_COUNT]
Definition: optsolver.hxx:82
std::unique_ptr< weld::Button > m_xBtnDel4
Definition: optsolver.hxx:131
std::shared_ptr< ScSolverOptionsDialog > m_xOptDlg
Definition: optsolver.hxx:143
ScOptSolverDlg(SfxBindings *pB, SfxChildWindow *pCW, weld::Window *pParent, ScDocShell *pDocSh, const ScAddress &aCursorPos)
Definition: optsolver.cxx:136
virtual bool IsRefInputMode() const override
Definition: optsolver.cxx:473
OUString maConditionError
Definition: optsolver.hxx:64
bool mbDlgLostFocus
Definition: optsolver.hxx:69
DECL_LINK(GetFocusHdl, weld::Widget &, void)
DECL_LINK(LoseEditFocusHdl, formula::RefEdit &, void)
std::unique_ptr< formula::RefEdit > m_xEdTargetValue
Definition: optsolver.hxx:96
css::uno::Sequence< OUString > maImplNames
Definition: optsolver.hxx:74
DECL_LINK(GetEditFocusHdl, formula::RefEdit &, void)
virtual void Close() override
Definition: optsolver.cxx:399
std::unique_ptr< weld::Label > m_xFtVariableCells
Definition: optsolver.hxx:99
const SCTAB mnCurTab
Definition: optsolver.hxx:68
std::unique_ptr< weld::ComboBox > m_xLbOp4
Definition: optsolver.hxx:128
std::unique_ptr< weld::ScrolledWindow > m_xScrollBar
Definition: optsolver.hxx:133
std::unique_ptr< weld::ComboBox > m_xLbOp3
Definition: optsolver.hxx:121
formula::RefButton * mpLeftButton[EDIT_ROW_COUNT]
Definition: optsolver.hxx:81
void ReadConditions()
Definition: optsolver.cxx:342
void SaveSolverSettings()
Definition: optsolver.cxx:512
DECL_LINK(DelBtnHdl, weld::Button &, void)
static sc::ConstraintOperator OperatorIndexToConstraintOperator(sal_Int32 nIndex)
Definition: optsolver.cxx:798
std::unique_ptr< formula::RefButton > m_xRBLeft4
Definition: optsolver.hxx:127
std::unique_ptr< formula::RefButton > m_xRBLeft2
Definition: optsolver.hxx:113
OUString maInputError
Definition: optsolver.hxx:63
ScCursorRefEdit * mpLeftEdit[EDIT_ROW_COUNT]
Definition: optsolver.hxx:80
std::unique_ptr< formula::RefButton > m_xRBRight4
Definition: optsolver.hxx:130
std::unique_ptr< weld::Label > m_xResultFT
Definition: optsolver.hxx:140
bool IsEngineAvailable(std::u16string_view sEngineName)
Definition: optsolver.cxx:540
std::unique_ptr< ScCursorRefEdit > m_xEdRight3
Definition: optsolver.hxx:122
weld::Button * mpDelButton[EDIT_ROW_COUNT]
Definition: optsolver.hxx:85
virtual void SetReference(const ScRange &rRef, ScDocument &rDoc) override
Definition: optsolver.cxx:422
std::unique_ptr< weld::Button > m_xBtnOpt
Definition: optsolver.hxx:135
DECL_LINK(BtnHdl, weld::Button &, void)
DECL_LINK(GetButtonFocusHdl, formula::RefButton &, void)
std::unique_ptr< ScCursorRefEdit > m_xEdRight4
Definition: optsolver.hxx:129
std::unique_ptr< weld::Label > m_xFtObjectiveCell
Definition: optsolver.hxx:89
void EnableButtons()
Definition: optsolver.cxx:390
DECL_LINK(TargetModifyHdl, formula::RefEdit &, void)
std::unique_ptr< formula::RefButton > m_xRBObjectiveCell
Definition: optsolver.hxx:91
std::unique_ptr< ScCursorRefEdit > m_xEdRight2
Definition: optsolver.hxx:115
std::unique_ptr< formula::RefButton > m_xRBVariableCells
Definition: optsolver.hxx:101
std::unique_ptr< weld::Button > m_xBtnSolve
Definition: optsolver.hxx:137
std::unique_ptr< formula::RefButton > m_xRBLeft3
Definition: optsolver.hxx:120
std::vector< sc::ModelConstraint > m_aConditions
Definition: optsolver.hxx:71
std::unique_ptr< weld::Label > m_xFtConstraint
Definition: optsolver.hxx:107
std::unique_ptr< weld::Button > m_xBtnDel1
Definition: optsolver.hxx:110
std::unique_ptr< ScCursorRefEdit > m_xEdRight1
Definition: optsolver.hxx:108
void ShowConditions()
Definition: optsolver.cxx:366
DECL_LINK(CursorUpHdl, ScCursorRefEdit &, void)
DECL_LINK(CondModifyHdl, formula::RefEdit &, void)
DECL_LINK(CursorDownHdl, ScCursorRefEdit &, void)
formula::RefButton * mpRightButton[EDIT_ROW_COUNT]
Definition: optsolver.hxx:83
OUString maEngine
Definition: optsolver.hxx:76
css::uno::Sequence< css::beans::PropertyValue > maProperties
Definition: optsolver.hxx:77
DECL_LINK(ScrollHdl, weld::ScrolledWindow &, void)
std::unique_ptr< weld::Label > m_xFtCellRef
Definition: optsolver.hxx:103
std::unique_ptr< ScCursorRefEdit > m_xEdLeft1
Definition: optsolver.hxx:104
std::unique_ptr< weld::Label > m_xFtErrorText
Definition: optsolver.hxx:189
ScSolverNoSolutionDialog(weld::Window *pParent, const OUString &rErrorText)
Definition: optsolver.cxx:72
virtual ~ScSolverNoSolutionDialog() override
Definition: optsolver.cxx:79
virtual ~ScSolverProgressDialog() override
Definition: optsolver.cxx:56
std::unique_ptr< weld::Label > m_xFtTime
Definition: optsolver.hxx:177
ScSolverProgressDialog(weld::Window *pParent)
Definition: optsolver.cxx:49
void SetTimeLimit(sal_Int32 nSeconds)
Definition: optsolver.cxx:65
virtual ~ScSolverSuccessDialog() override
Definition: optsolver.cxx:95
ScSolverSuccessDialog(weld::Window *pParent, std::u16string_view rSolution)
Definition: optsolver.cxx:83
std::unique_ptr< weld::Label > m_xFtResult
Definition: optsolver.hxx:198
std::unique_ptr< weld::Button > m_xBtnCancel
Definition: optsolver.hxx:200
DECL_LINK(ClickHdl, weld::Button &, void)
std::unique_ptr< weld::Button > m_xBtnOk
Definition: optsolver.hxx:199
std::unique_ptr< weld::Entry > xEntry
ConstraintOperator
long Long
sal_Int16 SCTAB
Definition: types.hxx:22