* Moved qoca to src/libs/qoca.
* Made use of qoca opt-in. You have to set the jam/environment variable LAYOUT_CONSTRAINT_SOLVER to "qoca" to do that. Unfortunately it turned the latest version of qoca is GPL (only earlier version were LGPL; the license included in the downloadable archive was misleading), so we can't use it. Complex layouts constraints that would require constraint solver support are ignored until I've found a replacement. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22235 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -63,7 +63,9 @@ BEOS_SYSTEM_LIB = libbe.so $(HAIKU_LIBSTDC++) libmedia.so libtracker.so
|
|||||||
libtranslation.so libnetwork.so libdebug.so libbsd.so libmail.so
|
libtranslation.so libnetwork.so libdebug.so libbsd.so libmail.so
|
||||||
libtextencoding.so libz.so libfreetype.so libpng.so libmidi.so libmidi2.so
|
libtextencoding.so libz.so libfreetype.so libpng.so libmidi.so libmidi2.so
|
||||||
libdevice.so libgame.so libscreensaver.so <revisioned>libroot.so
|
libdevice.so libgame.so libscreensaver.so <revisioned>libroot.so
|
||||||
$(X86_ONLY)libGL.so libfluidsynth.so libqoca.so
|
$(X86_ONLY)libGL.so libfluidsynth.so
|
||||||
|
# constraint solver lib
|
||||||
|
lib$(LAYOUT_CONSTRAINT_SOLVER).so
|
||||||
;
|
;
|
||||||
BEOS_SYSTEM_SERVERS = registrar debug_server syslog_daemon media_server
|
BEOS_SYSTEM_SERVERS = registrar debug_server syslog_daemon media_server
|
||||||
net_server media_addon_server input_server app_server fake_app_server
|
net_server media_addon_server input_server app_server fake_app_server
|
||||||
|
|||||||
+2
-2
@@ -32,7 +32,7 @@ SharedLibrary libbe.so :
|
|||||||
<libbe>storage_kit.o
|
<libbe>storage_kit.o
|
||||||
<libbe>support_kit.o
|
<libbe>support_kit.o
|
||||||
|
|
||||||
libqoca.so
|
lib$(LAYOUT_CONSTRAINT_SOLVER).so
|
||||||
|
|
||||||
libicon.a
|
libicon.a
|
||||||
libagg.a
|
libagg.a
|
||||||
@@ -68,7 +68,7 @@ SharedLibrary libbe_haiku.so :
|
|||||||
<libbe>storage_kit.o
|
<libbe>storage_kit.o
|
||||||
<libbe>support_kit.o
|
<libbe>support_kit.o
|
||||||
|
|
||||||
libqoca.so
|
lib$(LAYOUT_CONSTRAINT_SOLVER).so
|
||||||
|
|
||||||
libicon.a
|
libicon.a
|
||||||
libagg.a
|
libagg.a
|
||||||
|
|||||||
@@ -28,9 +28,21 @@ SetSubDirSupportedPlatforms haiku libbe_test ;
|
|||||||
UsePrivateHeaders app input interface shared tracker ;
|
UsePrivateHeaders app input interface shared tracker ;
|
||||||
UseLibraryHeaders icon ;
|
UseLibraryHeaders icon ;
|
||||||
|
|
||||||
# qoca headers
|
|
||||||
SubDirSysHdrs $(SUBDIR) ;
|
# constraint solver to use
|
||||||
SubDirHdrs [ FDirName $(SUBDIR) qoca ] ;
|
local constraintSolverSources = ;
|
||||||
|
switch $(LAYOUT_CONSTRAINT_SOLVER) {
|
||||||
|
case qoca :
|
||||||
|
{
|
||||||
|
DEFINES += USE_QOCA_CONSTRAINT_SOLVER ;
|
||||||
|
constraintSolverSources = QocaConstraintSolverLayouter.cpp ;
|
||||||
|
SubDirSysHdrs [ FDirName $(HAIKU_TOP) src libs ] ;
|
||||||
|
SubDirHdrs [ FDirName $(HAIKU_TOP) src libs qoca ] ;
|
||||||
|
}
|
||||||
|
case * :
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
SEARCH_SOURCE += [ FDirName $(SUBDIR) textview_support ] ;
|
SEARCH_SOURCE += [ FDirName $(SUBDIR) textview_support ] ;
|
||||||
@@ -126,10 +138,9 @@ MergeObject <libbe>interface_kit.o :
|
|||||||
WidthBuffer.cpp
|
WidthBuffer.cpp
|
||||||
|
|
||||||
# layouter
|
# layouter
|
||||||
ConstraintSolverLayouter.cpp
|
|
||||||
Layouter.cpp
|
Layouter.cpp
|
||||||
OneElementLayouter.cpp
|
OneElementLayouter.cpp
|
||||||
SimpleLayouter.cpp
|
SimpleLayouter.cpp
|
||||||
;
|
|
||||||
|
|
||||||
SubInclude HAIKU_TOP src kits interface qoca ;
|
$(constraintSolverSources)
|
||||||
|
;
|
||||||
|
|||||||
@@ -1,144 +1,18 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2006, Haiku Inc.
|
* Copyright 2007, Ingo Weinhold <[email protected]>.
|
||||||
* Distributed under the terms of the MIT License.
|
* All rights reserved. Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
#ifndef CONSTRAINT_SOLVER_LAYOUTER_H
|
#ifndef CONSTRAINT_SOLVER_LAYOUTER_H
|
||||||
#define CONSTRAINT_SOLVER_LAYOUTER_H
|
#define CONSTRAINT_SOLVER_LAYOUTER_H
|
||||||
|
|
||||||
#include "Layouter.h"
|
|
||||||
|
|
||||||
#include <List.h>
|
#ifdef USE_QOCA_CONSTRAINT_SOLVER
|
||||||
|
# include "QocaConstraintSolverLayouter.h"
|
||||||
|
typedef QocaConstraintSolverLayouter ConstraintSolverLayouter;
|
||||||
|
#else
|
||||||
|
# include "SimpleLayouter.h"
|
||||||
|
typedef SimpleLayouter ConstraintSolverLayouter;
|
||||||
|
#endif
|
||||||
|
|
||||||
class QcLinInEqSolver;
|
|
||||||
class QcConstraint;
|
|
||||||
class QcConstraint;
|
|
||||||
|
|
||||||
namespace BPrivate {
|
|
||||||
namespace Layout {
|
|
||||||
|
|
||||||
class ConstraintSolverLayouter : public Layouter {
|
|
||||||
public:
|
|
||||||
ConstraintSolverLayouter(int32 elementCount,
|
|
||||||
int32 spacing);
|
|
||||||
virtual ~ConstraintSolverLayouter();
|
|
||||||
|
|
||||||
virtual void AddConstraints(int32 element, int32 length,
|
|
||||||
float min, float max, float preferred);
|
|
||||||
virtual void SetWeight(int32 element, float weight);
|
|
||||||
|
|
||||||
virtual float MinSize();
|
|
||||||
virtual float MaxSize();
|
|
||||||
virtual float PreferredSize();
|
|
||||||
|
|
||||||
virtual LayoutInfo* CreateLayoutInfo();
|
|
||||||
|
|
||||||
virtual void Layout(LayoutInfo* layoutInfo, float size);
|
|
||||||
|
|
||||||
virtual Layouter* CloneLayouter();
|
|
||||||
|
|
||||||
private:
|
|
||||||
class Set;
|
|
||||||
|
|
||||||
class Variable;
|
|
||||||
class Constraint;
|
|
||||||
class MinConstraint;
|
|
||||||
class MaxConstraint;
|
|
||||||
class MinMaxEntry;
|
|
||||||
class MinMaxMatrix;
|
|
||||||
class MyLayoutInfo;
|
|
||||||
|
|
||||||
friend class Constraint;
|
|
||||||
|
|
||||||
enum {
|
|
||||||
MIN_CONSTRAINT = 0,
|
|
||||||
MAX_CONSTRAINT = 1,
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
void _ValidateMinMax();
|
|
||||||
|
|
||||||
void _AddMinConstraint(int32 first, int32 last,
|
|
||||||
int32 value);
|
|
||||||
void _AddMaxConstraint(int32 first, int32 last,
|
|
||||||
int32 value);
|
|
||||||
|
|
||||||
int32 _ComputeMin();
|
|
||||||
int32 _ComputeMax();
|
|
||||||
bool _ComputeSolution(int32 size);
|
|
||||||
|
|
||||||
bool _FindIntegerSolution(int32 size);
|
|
||||||
bool _FindIntegerSolution(const Set& nonIntVariables,
|
|
||||||
const BList& minConstraints,
|
|
||||||
const BList& maxConstraints,
|
|
||||||
int32 sizeDiff);
|
|
||||||
|
|
||||||
Constraint* _CreateConstraint(int32 type, int32 first,
|
|
||||||
int32 last, int32 value);
|
|
||||||
void _SetConstraint(int32 type,
|
|
||||||
Constraint** constraints,
|
|
||||||
int32 element, int32 value, bool restrict);
|
|
||||||
void _SetConstraint(int32 type,
|
|
||||||
BList& constraints,
|
|
||||||
int32 first, int32 last, int32 value,
|
|
||||||
bool restrict);
|
|
||||||
int _IndexOfConstraint(BList& constraints,
|
|
||||||
int32 first, int32 last);
|
|
||||||
bool _AddSetSizeConstraint(int32 size);
|
|
||||||
|
|
||||||
void _AddConstraints();
|
|
||||||
void _AddConstraints(const BList& constraints);
|
|
||||||
void _RemoveSetSizeConstraint();
|
|
||||||
void _RemoveConstraints();
|
|
||||||
void _RemoveConstraint(Constraint* constraint);
|
|
||||||
void _GetInvolvedConstraints(
|
|
||||||
const BList& constraints,
|
|
||||||
const BList& variables,
|
|
||||||
BList& filteredConstraints);
|
|
||||||
void _GetViolatedConstraints(
|
|
||||||
const BList& constraints,
|
|
||||||
BList& violatedConstraints);
|
|
||||||
void _FilterVariablesByMaxConstraints(
|
|
||||||
const BList& variables,
|
|
||||||
const BList& constraints,
|
|
||||||
Set& filteredVars);
|
|
||||||
|
|
||||||
static int _CompareVariables(const void* a, const void* b);
|
|
||||||
static int _CompareConstraintsByLength(const void* a,
|
|
||||||
const void* b);
|
|
||||||
static int _CompareConstraintsBySatisfactionDistance(
|
|
||||||
const void* a, const void* b);
|
|
||||||
|
|
||||||
private:
|
|
||||||
int32 fElementCount;
|
|
||||||
float* fWeights;
|
|
||||||
|
|
||||||
Constraint** fBasicMinConstraints;
|
|
||||||
Constraint** fBasicMaxConstraints;
|
|
||||||
|
|
||||||
BList fComplexMinConstraints;
|
|
||||||
BList fComplexMaxConstraints;
|
|
||||||
|
|
||||||
Variable* fVariables;
|
|
||||||
Variable* fSizeVariable;
|
|
||||||
|
|
||||||
QcLinInEqSolver* fSolver;
|
|
||||||
QcConstraint* fSizeSumConstraint;
|
|
||||||
QcConstraint* fSetSizeConstraint;
|
|
||||||
|
|
||||||
bool fConstraintsAdded;
|
|
||||||
bool fSetSizeConstraintAdded;
|
|
||||||
|
|
||||||
int32 fSpacing;
|
|
||||||
int32 fMin;
|
|
||||||
int32 fMax;
|
|
||||||
bool fMinMaxValid;
|
|
||||||
|
|
||||||
MyLayoutInfo* fLayoutInfo;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace Layout
|
|
||||||
} // namespace BPrivate
|
|
||||||
|
|
||||||
using BPrivate::Layout::ConstraintSolverLayouter;
|
|
||||||
|
|
||||||
#endif // CONSTRAINT_SOLVER_LAYOUTER_H
|
#endif // CONSTRAINT_SOLVER_LAYOUTER_H
|
||||||
|
|||||||
+72
-72
@@ -1,9 +1,9 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2006, Ingo Weinhold <bonefish@cs.tu-berlin.de>.
|
* Copyright 2006-2007, Ingo Weinhold <bonefish@cs.tu-berlin.de>.
|
||||||
* All rights reserved. Distributed under the terms of the MIT License.
|
* All rights reserved. Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "ConstraintSolverLayouter.h"
|
#include "QocaConstraintSolverLayouter.h"
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
@@ -29,7 +29,6 @@
|
|||||||
#include <qoca/QcLinPoly.hh>
|
#include <qoca/QcLinPoly.hh>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// This monster is a Layouter implementation similar to SimpleLayouter with
|
// This monster is a Layouter implementation similar to SimpleLayouter with
|
||||||
// the difference that it accepts min/max constraints over several elements,
|
// the difference that it accepts min/max constraints over several elements,
|
||||||
// i.e. not only constraints of the form x_i <=/>= a, but also of the form
|
// i.e. not only constraints of the form x_i <=/>= a, but also of the form
|
||||||
@@ -66,7 +65,7 @@
|
|||||||
|
|
||||||
|
|
||||||
// Set
|
// Set
|
||||||
class ConstraintSolverLayouter::Set {
|
class QocaConstraintSolverLayouter::Set {
|
||||||
public:
|
public:
|
||||||
Set()
|
Set()
|
||||||
: fElements()
|
: fElements()
|
||||||
@@ -140,7 +139,7 @@ private:
|
|||||||
|
|
||||||
|
|
||||||
// Variable
|
// Variable
|
||||||
class ConstraintSolverLayouter::Variable {
|
class QocaConstraintSolverLayouter::Variable {
|
||||||
public:
|
public:
|
||||||
Variable()
|
Variable()
|
||||||
: fQocaVariable(NULL),
|
: fQocaVariable(NULL),
|
||||||
@@ -213,9 +212,9 @@ private:
|
|||||||
|
|
||||||
|
|
||||||
// Constraint
|
// Constraint
|
||||||
class ConstraintSolverLayouter::Constraint {
|
class QocaConstraintSolverLayouter::Constraint {
|
||||||
public:
|
public:
|
||||||
Constraint(ConstraintSolverLayouter* layouter,
|
Constraint(QocaConstraintSolverLayouter* layouter,
|
||||||
int32 first, int32 last, int32 value)
|
int32 first, int32 last, int32 value)
|
||||||
: fLayouter(layouter),
|
: fLayouter(layouter),
|
||||||
fFirst(first),
|
fFirst(first),
|
||||||
@@ -241,7 +240,8 @@ public:
|
|||||||
delete fQocaConstraint;
|
delete fQocaConstraint;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual Constraint* CloneConstraint(ConstraintSolverLayouter* layouter) = 0;
|
virtual Constraint* CloneConstraint(
|
||||||
|
QocaConstraintSolverLayouter* layouter) = 0;
|
||||||
|
|
||||||
int32 First() const
|
int32 First() const
|
||||||
{
|
{
|
||||||
@@ -338,7 +338,7 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
ConstraintSolverLayouter* fLayouter;
|
QocaConstraintSolverLayouter* fLayouter;
|
||||||
|
|
||||||
int32 fFirst;
|
int32 fFirst;
|
||||||
int32 fLast;
|
int32 fLast;
|
||||||
@@ -357,16 +357,16 @@ private:
|
|||||||
|
|
||||||
|
|
||||||
// MinConstraint
|
// MinConstraint
|
||||||
class ConstraintSolverLayouter::MinConstraint : public Constraint {
|
class QocaConstraintSolverLayouter::MinConstraint : public Constraint {
|
||||||
public:
|
public:
|
||||||
MinConstraint(ConstraintSolverLayouter* layouter, int32 first, int32 last,
|
MinConstraint(QocaConstraintSolverLayouter* layouter, int32 first,
|
||||||
int32 value)
|
int32 last, int32 value)
|
||||||
: Constraint(layouter, first, last, value)
|
: Constraint(layouter, first, last, value)
|
||||||
{
|
{
|
||||||
SetOriginalValue(value);
|
SetOriginalValue(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual Constraint* CloneConstraint(ConstraintSolverLayouter* layouter)
|
virtual Constraint* CloneConstraint(QocaConstraintSolverLayouter* layouter)
|
||||||
{
|
{
|
||||||
Constraint* constraint = new MinConstraint(layouter, fFirst, fLast,
|
Constraint* constraint = new MinConstraint(layouter, fFirst, fLast,
|
||||||
fOriginalValue);
|
fOriginalValue);
|
||||||
@@ -398,16 +398,16 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
// MaxConstraint
|
// MaxConstraint
|
||||||
class ConstraintSolverLayouter::MaxConstraint : public Constraint {
|
class QocaConstraintSolverLayouter::MaxConstraint : public Constraint {
|
||||||
public:
|
public:
|
||||||
MaxConstraint(ConstraintSolverLayouter* layouter, int32 first, int32 last,
|
MaxConstraint(QocaConstraintSolverLayouter* layouter, int32 first,
|
||||||
int32 value)
|
int32 last, int32 value)
|
||||||
: Constraint(layouter, first, last, value)
|
: Constraint(layouter, first, last, value)
|
||||||
{
|
{
|
||||||
SetOriginalValue(value);
|
SetOriginalValue(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual Constraint* CloneConstraint(ConstraintSolverLayouter* layouter)
|
virtual Constraint* CloneConstraint(QocaConstraintSolverLayouter* layouter)
|
||||||
{
|
{
|
||||||
Constraint* constraint = new MaxConstraint(layouter, fFirst, fLast,
|
Constraint* constraint = new MaxConstraint(layouter, fFirst, fLast,
|
||||||
fOriginalValue);
|
fOriginalValue);
|
||||||
@@ -439,7 +439,7 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
// MinMaxEntry
|
// MinMaxEntry
|
||||||
class ConstraintSolverLayouter::MinMaxEntry {
|
class QocaConstraintSolverLayouter::MinMaxEntry {
|
||||||
public:
|
public:
|
||||||
Constraint* minConstraint;
|
Constraint* minConstraint;
|
||||||
Constraint* maxConstraint;
|
Constraint* maxConstraint;
|
||||||
@@ -473,7 +473,7 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
// MinMaxMatrix
|
// MinMaxMatrix
|
||||||
class ConstraintSolverLayouter::MinMaxMatrix {
|
class QocaConstraintSolverLayouter::MinMaxMatrix {
|
||||||
public:
|
public:
|
||||||
MinMaxMatrix(int size)
|
MinMaxMatrix(int size)
|
||||||
: fSize(size),
|
: fSize(size),
|
||||||
@@ -500,7 +500,7 @@ private:
|
|||||||
|
|
||||||
|
|
||||||
// MyLayoutInfo
|
// MyLayoutInfo
|
||||||
class ConstraintSolverLayouter::MyLayoutInfo : public LayoutInfo {
|
class QocaConstraintSolverLayouter::MyLayoutInfo : public LayoutInfo {
|
||||||
public:
|
public:
|
||||||
MyLayoutInfo(int32 elementCount)
|
MyLayoutInfo(int32 elementCount)
|
||||||
: fCount(elementCount)
|
: fCount(elementCount)
|
||||||
@@ -533,7 +533,7 @@ public:
|
|||||||
|
|
||||||
void Dump()
|
void Dump()
|
||||||
{
|
{
|
||||||
printf("ConstraintSolverLayouter::MyLayoutInfo(): %ld elements:\n",
|
printf("QocaConstraintSolverLayouter::MyLayoutInfo(): %ld elements:\n",
|
||||||
fCount);
|
fCount);
|
||||||
for (int32 i = 0; i < fCount; i++) {
|
for (int32 i = 0; i < fCount; i++) {
|
||||||
printf(" %2ld: location: %4ld, size: %4ld\n", i, fLocations[i],
|
printf(" %2ld: location: %4ld, size: %4ld\n", i, fLocations[i],
|
||||||
@@ -548,11 +548,11 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark - ConstraintSolverLayouter
|
// #pragma mark - QocaConstraintSolverLayouter
|
||||||
|
|
||||||
|
|
||||||
// constructor
|
// constructor
|
||||||
ConstraintSolverLayouter::ConstraintSolverLayouter(int32 elementCount,
|
QocaConstraintSolverLayouter::QocaConstraintSolverLayouter(int32 elementCount,
|
||||||
int32 spacing)
|
int32 spacing)
|
||||||
: fElementCount(elementCount),
|
: fElementCount(elementCount),
|
||||||
fWeights(NULL),
|
fWeights(NULL),
|
||||||
@@ -612,7 +612,7 @@ ConstraintSolverLayouter::ConstraintSolverLayouter(int32 elementCount,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// destructor
|
// destructor
|
||||||
ConstraintSolverLayouter::~ConstraintSolverLayouter()
|
QocaConstraintSolverLayouter::~QocaConstraintSolverLayouter()
|
||||||
{
|
{
|
||||||
delete fSetSizeConstraint;
|
delete fSetSizeConstraint;
|
||||||
delete fSizeSumConstraint;
|
delete fSizeSumConstraint;
|
||||||
@@ -627,7 +627,7 @@ ConstraintSolverLayouter::~ConstraintSolverLayouter()
|
|||||||
|
|
||||||
// AddConstraints
|
// AddConstraints
|
||||||
void
|
void
|
||||||
ConstraintSolverLayouter::AddConstraints(int32 element, int32 length,
|
QocaConstraintSolverLayouter::AddConstraints(int32 element, int32 length,
|
||||||
float _min, float _max, float _preferred)
|
float _min, float _max, float _preferred)
|
||||||
{
|
{
|
||||||
if (length <= 0 || length > fElementCount)
|
if (length <= 0 || length > fElementCount)
|
||||||
@@ -649,7 +649,7 @@ ConstraintSolverLayouter::AddConstraints(int32 element, int32 length,
|
|||||||
|
|
||||||
// SetWeight
|
// SetWeight
|
||||||
void
|
void
|
||||||
ConstraintSolverLayouter::SetWeight(int32 element, float weight)
|
QocaConstraintSolverLayouter::SetWeight(int32 element, float weight)
|
||||||
{
|
{
|
||||||
if (element < 0 || element >= fElementCount)
|
if (element < 0 || element >= fElementCount)
|
||||||
return;
|
return;
|
||||||
@@ -659,7 +659,7 @@ ConstraintSolverLayouter::SetWeight(int32 element, float weight)
|
|||||||
|
|
||||||
// MinSize
|
// MinSize
|
||||||
float
|
float
|
||||||
ConstraintSolverLayouter::MinSize()
|
QocaConstraintSolverLayouter::MinSize()
|
||||||
{
|
{
|
||||||
_ValidateMinMax();
|
_ValidateMinMax();
|
||||||
return fMin - 1;
|
return fMin - 1;
|
||||||
@@ -667,7 +667,7 @@ ConstraintSolverLayouter::MinSize()
|
|||||||
|
|
||||||
// MaxSize
|
// MaxSize
|
||||||
float
|
float
|
||||||
ConstraintSolverLayouter::MaxSize()
|
QocaConstraintSolverLayouter::MaxSize()
|
||||||
{
|
{
|
||||||
_ValidateMinMax();
|
_ValidateMinMax();
|
||||||
return fMax - 1;
|
return fMax - 1;
|
||||||
@@ -675,7 +675,7 @@ ConstraintSolverLayouter::MaxSize()
|
|||||||
|
|
||||||
// PreferredSize
|
// PreferredSize
|
||||||
float
|
float
|
||||||
ConstraintSolverLayouter::PreferredSize()
|
QocaConstraintSolverLayouter::PreferredSize()
|
||||||
{
|
{
|
||||||
_ValidateMinMax();
|
_ValidateMinMax();
|
||||||
return fMin - 1;
|
return fMin - 1;
|
||||||
@@ -683,16 +683,16 @@ ConstraintSolverLayouter::PreferredSize()
|
|||||||
|
|
||||||
// CreateLayoutInfo
|
// CreateLayoutInfo
|
||||||
LayoutInfo*
|
LayoutInfo*
|
||||||
ConstraintSolverLayouter::CreateLayoutInfo()
|
QocaConstraintSolverLayouter::CreateLayoutInfo()
|
||||||
{
|
{
|
||||||
return new MyLayoutInfo(fElementCount);
|
return new MyLayoutInfo(fElementCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Layout
|
// Layout
|
||||||
void
|
void
|
||||||
ConstraintSolverLayouter::Layout(LayoutInfo* layoutInfo, float _size)
|
QocaConstraintSolverLayouter::Layout(LayoutInfo* layoutInfo, float _size)
|
||||||
{
|
{
|
||||||
//printf("ConstraintSolverLayouter::Layout(%p, %.1f): min: %ld, max: %ld\n",
|
//printf("QocaConstraintSolverLayouter::Layout(%p, %.1f): min: %ld, max: %ld\n",
|
||||||
//layoutInfo, _size, fMin, fMax);
|
//layoutInfo, _size, fMin, fMax);
|
||||||
int32 size = (int32)_size + 1;
|
int32 size = (int32)_size + 1;
|
||||||
|
|
||||||
@@ -710,7 +710,7 @@ ConstraintSolverLayouter::Layout(LayoutInfo* layoutInfo, float _size)
|
|||||||
size -= additionalSpace;
|
size -= additionalSpace;
|
||||||
int32 spacing = (fElementCount - 1) * fSpacing;
|
int32 spacing = (fElementCount - 1) * fSpacing;
|
||||||
if (!_ComputeSolution(size - spacing)) {
|
if (!_ComputeSolution(size - spacing)) {
|
||||||
ERROR_MESSAGE("ConstraintSolverLayouter::Layout(): no solution\n");
|
ERROR_MESSAGE("QocaConstraintSolverLayouter::Layout(): no solution\n");
|
||||||
// no solution
|
// no solution
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -750,10 +750,10 @@ ConstraintSolverLayouter::Layout(LayoutInfo* layoutInfo, float _size)
|
|||||||
|
|
||||||
// CloneLayouter
|
// CloneLayouter
|
||||||
Layouter*
|
Layouter*
|
||||||
ConstraintSolverLayouter::CloneLayouter()
|
QocaConstraintSolverLayouter::CloneLayouter()
|
||||||
{
|
{
|
||||||
ConstraintSolverLayouter* layouter
|
QocaConstraintSolverLayouter* layouter
|
||||||
= new ConstraintSolverLayouter(fElementCount, fSpacing);
|
= new QocaConstraintSolverLayouter(fElementCount, fSpacing);
|
||||||
|
|
||||||
memcpy(layouter->fWeights, fWeights, sizeof(float) * fElementCount);
|
memcpy(layouter->fWeights, fWeights, sizeof(float) * fElementCount);
|
||||||
|
|
||||||
@@ -790,7 +790,7 @@ ConstraintSolverLayouter::CloneLayouter()
|
|||||||
|
|
||||||
// _ValidateMinMax
|
// _ValidateMinMax
|
||||||
void
|
void
|
||||||
ConstraintSolverLayouter::_ValidateMinMax()
|
QocaConstraintSolverLayouter::_ValidateMinMax()
|
||||||
{
|
{
|
||||||
if (fMinMaxValid)
|
if (fMinMaxValid)
|
||||||
return;
|
return;
|
||||||
@@ -809,7 +809,7 @@ ConstraintSolverLayouter::_ValidateMinMax()
|
|||||||
|
|
||||||
// _AddMinConstraint
|
// _AddMinConstraint
|
||||||
void
|
void
|
||||||
ConstraintSolverLayouter::_AddMinConstraint(int32 first, int32 last,
|
QocaConstraintSolverLayouter::_AddMinConstraint(int32 first, int32 last,
|
||||||
int32 value)
|
int32 value)
|
||||||
{
|
{
|
||||||
if (first == last) {
|
if (first == last) {
|
||||||
@@ -823,7 +823,7 @@ ConstraintSolverLayouter::_AddMinConstraint(int32 first, int32 last,
|
|||||||
|
|
||||||
// _AddMaxConstraint
|
// _AddMaxConstraint
|
||||||
void
|
void
|
||||||
ConstraintSolverLayouter::_AddMaxConstraint(int32 first, int32 last,
|
QocaConstraintSolverLayouter::_AddMaxConstraint(int32 first, int32 last,
|
||||||
int32 value)
|
int32 value)
|
||||||
{
|
{
|
||||||
if (first == last) {
|
if (first == last) {
|
||||||
@@ -837,7 +837,7 @@ ConstraintSolverLayouter::_AddMaxConstraint(int32 first, int32 last,
|
|||||||
|
|
||||||
// _ComputeMin
|
// _ComputeMin
|
||||||
int32
|
int32
|
||||||
ConstraintSolverLayouter::_ComputeMin()
|
QocaConstraintSolverLayouter::_ComputeMin()
|
||||||
{
|
{
|
||||||
_RemoveSetSizeConstraint();
|
_RemoveSetSizeConstraint();
|
||||||
_AddConstraints();
|
_AddConstraints();
|
||||||
@@ -855,7 +855,7 @@ ConstraintSolverLayouter::_ComputeMin()
|
|||||||
bool success = _FindIntegerSolution(size);
|
bool success = _FindIntegerSolution(size);
|
||||||
if (!success) {
|
if (!success) {
|
||||||
ERROR_MESSAGE(
|
ERROR_MESSAGE(
|
||||||
"ConstraintSolverLayouter::_ComputeMin(): no int solution\n");
|
"QocaConstraintSolverLayouter::_ComputeMin(): no int solution\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -864,7 +864,7 @@ ConstraintSolverLayouter::_ComputeMin()
|
|||||||
|
|
||||||
// _ComputeMax
|
// _ComputeMax
|
||||||
int32
|
int32
|
||||||
ConstraintSolverLayouter::_ComputeMax()
|
QocaConstraintSolverLayouter::_ComputeMax()
|
||||||
{
|
{
|
||||||
_RemoveSetSizeConstraint();
|
_RemoveSetSizeConstraint();
|
||||||
_AddConstraints();
|
_AddConstraints();
|
||||||
@@ -888,7 +888,7 @@ ConstraintSolverLayouter::_ComputeMax()
|
|||||||
bool success = _FindIntegerSolution(size);
|
bool success = _FindIntegerSolution(size);
|
||||||
if (!success) {
|
if (!success) {
|
||||||
ERROR_MESSAGE(
|
ERROR_MESSAGE(
|
||||||
"ConstraintSolverLayouter::_ComputeMax(): no int solution\n");
|
"QocaConstraintSolverLayouter::_ComputeMax(): no int solution\n");
|
||||||
return B_SIZE_UNLIMITED;
|
return B_SIZE_UNLIMITED;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -897,9 +897,9 @@ ConstraintSolverLayouter::_ComputeMax()
|
|||||||
|
|
||||||
// _ComputeSolution
|
// _ComputeSolution
|
||||||
bool
|
bool
|
||||||
ConstraintSolverLayouter::_ComputeSolution(int32 size)
|
QocaConstraintSolverLayouter::_ComputeSolution(int32 size)
|
||||||
{
|
{
|
||||||
//printf("ConstraintSolverLayouter::_ComputeSolution(%ld)\n", size);
|
//printf("QocaConstraintSolverLayouter::_ComputeSolution(%ld)\n", size);
|
||||||
_RemoveSetSizeConstraint();
|
_RemoveSetSizeConstraint();
|
||||||
_AddConstraints();
|
_AddConstraints();
|
||||||
|
|
||||||
@@ -913,7 +913,7 @@ ConstraintSolverLayouter::_ComputeSolution(int32 size)
|
|||||||
|
|
||||||
if (!_AddSetSizeConstraint(size)) {
|
if (!_AddSetSizeConstraint(size)) {
|
||||||
// Ugh! Contradictory!
|
// Ugh! Contradictory!
|
||||||
ERROR_MESSAGE("ConstraintSolverLayouter::_ComputeSolution(): "
|
ERROR_MESSAGE("QocaConstraintSolverLayouter::_ComputeSolution(): "
|
||||||
"contradictory CSP\n");
|
"contradictory CSP\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -922,7 +922,7 @@ ConstraintSolverLayouter::_ComputeSolution(int32 size)
|
|||||||
fSolver->Solve();
|
fSolver->Solve();
|
||||||
|
|
||||||
if (!_FindIntegerSolution(size)) {
|
if (!_FindIntegerSolution(size)) {
|
||||||
ERROR_MESSAGE("ConstraintSolverLayouter::_ComputeSolution(): "
|
ERROR_MESSAGE("QocaConstraintSolverLayouter::_ComputeSolution(): "
|
||||||
"no int solution\n");
|
"no int solution\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -932,9 +932,9 @@ ConstraintSolverLayouter::_ComputeSolution(int32 size)
|
|||||||
|
|
||||||
// _FindIntegerSolution
|
// _FindIntegerSolution
|
||||||
bool
|
bool
|
||||||
ConstraintSolverLayouter::_FindIntegerSolution(int32 size)
|
QocaConstraintSolverLayouter::_FindIntegerSolution(int32 size)
|
||||||
{
|
{
|
||||||
//printf("ConstraintSolverLayouter::_FindIntegerSolution(%ld)\n", size);
|
//printf("QocaConstraintSolverLayouter::_FindIntegerSolution(%ld)\n", size);
|
||||||
//printf(" solution:\n");
|
//printf(" solution:\n");
|
||||||
// check whether there are non-integer variable values
|
// check whether there are non-integer variable values
|
||||||
Set nonIntVariables;
|
Set nonIntVariables;
|
||||||
@@ -981,13 +981,13 @@ ConstraintSolverLayouter::_FindIntegerSolution(int32 size)
|
|||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (sum > size) {
|
if (sum > size) {
|
||||||
ERROR_MESSAGE("ConstraintSolverLayouter::_FindIntegerSolution(): "
|
ERROR_MESSAGE("QocaConstraintSolverLayouter::_FindIntegerSolution(): "
|
||||||
"computed size %ld, but element sum is %ld\n", size, sum);
|
"computed size %ld, but element sum is %ld\n", size, sum);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nonIntVariables.IsEmpty()) {
|
if (nonIntVariables.IsEmpty()) {
|
||||||
ERROR_MESSAGE("ConstraintSolverLayouter::_FindIntegerSolution(): "
|
ERROR_MESSAGE("QocaConstraintSolverLayouter::_FindIntegerSolution(): "
|
||||||
"computed size %ld, element sum is %ld, but we have no "
|
"computed size %ld, element sum is %ld, but we have no "
|
||||||
"non-integer variables\n", size, sum);
|
"non-integer variables\n", size, sum);
|
||||||
return false;
|
return false;
|
||||||
@@ -1014,7 +1014,7 @@ ConstraintSolverLayouter::_FindIntegerSolution(int32 size)
|
|||||||
|
|
||||||
// _FindIntegerSolution
|
// _FindIntegerSolution
|
||||||
bool
|
bool
|
||||||
ConstraintSolverLayouter::_FindIntegerSolution(const Set& _nonIntVariables,
|
QocaConstraintSolverLayouter::_FindIntegerSolution(const Set& _nonIntVariables,
|
||||||
const BList& _minConstraints, const BList& _maxConstraints, int32 sizeDiff)
|
const BList& _minConstraints, const BList& _maxConstraints, int32 sizeDiff)
|
||||||
{
|
{
|
||||||
// We get the variables that had a non-integer value, and lists of minimum
|
// We get the variables that had a non-integer value, and lists of minimum
|
||||||
@@ -1108,14 +1108,14 @@ ConstraintSolverLayouter::_FindIntegerSolution(const Set& _nonIntVariables,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// if we are here, we didn't find a solution
|
// if we are here, we didn't find a solution
|
||||||
ERROR_MESSAGE("ConstraintSolverLayouter::_FindIntegerSolution(): "
|
ERROR_MESSAGE("QocaConstraintSolverLayouter::_FindIntegerSolution(): "
|
||||||
"found no int solution\n");
|
"found no int solution\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// _CreateConstraint
|
// _CreateConstraint
|
||||||
ConstraintSolverLayouter::Constraint*
|
QocaConstraintSolverLayouter::Constraint*
|
||||||
ConstraintSolverLayouter::_CreateConstraint(int32 type, int32 first,
|
QocaConstraintSolverLayouter::_CreateConstraint(int32 type, int32 first,
|
||||||
int32 last, int32 value)
|
int32 last, int32 value)
|
||||||
{
|
{
|
||||||
switch (type) {
|
switch (type) {
|
||||||
@@ -1131,8 +1131,8 @@ ConstraintSolverLayouter::_CreateConstraint(int32 type, int32 first,
|
|||||||
|
|
||||||
// _SetConstraint
|
// _SetConstraint
|
||||||
void
|
void
|
||||||
ConstraintSolverLayouter::_SetConstraint(int32 type, Constraint** constraints,
|
QocaConstraintSolverLayouter::_SetConstraint(int32 type,
|
||||||
int32 element, int32 value, bool restrict)
|
Constraint** constraints, int32 element, int32 value, bool restrict)
|
||||||
{
|
{
|
||||||
if (element < 0 || element >= fElementCount)
|
if (element < 0 || element >= fElementCount)
|
||||||
return;
|
return;
|
||||||
@@ -1156,7 +1156,7 @@ ConstraintSolverLayouter::_SetConstraint(int32 type, Constraint** constraints,
|
|||||||
|
|
||||||
// _SetConstraint
|
// _SetConstraint
|
||||||
void
|
void
|
||||||
ConstraintSolverLayouter::_SetConstraint(int32 type, BList& constraints,
|
QocaConstraintSolverLayouter::_SetConstraint(int32 type, BList& constraints,
|
||||||
int32 first, int32 last, int32 value, bool restrict)
|
int32 first, int32 last, int32 value, bool restrict)
|
||||||
{
|
{
|
||||||
if (first < 0 || first > last || last >= fElementCount)
|
if (first < 0 || first > last || last >= fElementCount)
|
||||||
@@ -1185,8 +1185,8 @@ ConstraintSolverLayouter::_SetConstraint(int32 type, BList& constraints,
|
|||||||
|
|
||||||
// _IndexOfConstraint
|
// _IndexOfConstraint
|
||||||
int
|
int
|
||||||
ConstraintSolverLayouter::_IndexOfConstraint(BList& constraints, int32 first,
|
QocaConstraintSolverLayouter::_IndexOfConstraint(BList& constraints,
|
||||||
int32 last)
|
int32 first, int32 last)
|
||||||
{
|
{
|
||||||
int32 count = constraints.CountItems();
|
int32 count = constraints.CountItems();
|
||||||
for (int32 i = 0; i < count; i++) {
|
for (int32 i = 0; i < count; i++) {
|
||||||
@@ -1200,7 +1200,7 @@ ConstraintSolverLayouter::_IndexOfConstraint(BList& constraints, int32 first,
|
|||||||
|
|
||||||
// _AddSetSizeConstraint
|
// _AddSetSizeConstraint
|
||||||
bool
|
bool
|
||||||
ConstraintSolverLayouter::_AddSetSizeConstraint(int32 size)
|
QocaConstraintSolverLayouter::_AddSetSizeConstraint(int32 size)
|
||||||
{
|
{
|
||||||
if (fSetSizeConstraintAdded) {
|
if (fSetSizeConstraintAdded) {
|
||||||
if (fSetSizeConstraint->RHS() == size)
|
if (fSetSizeConstraint->RHS() == size)
|
||||||
@@ -1220,7 +1220,7 @@ ConstraintSolverLayouter::_AddSetSizeConstraint(int32 size)
|
|||||||
|
|
||||||
// _AddConstraints
|
// _AddConstraints
|
||||||
void
|
void
|
||||||
ConstraintSolverLayouter::_AddConstraints()
|
QocaConstraintSolverLayouter::_AddConstraints()
|
||||||
{
|
{
|
||||||
if (fConstraintsAdded)
|
if (fConstraintsAdded)
|
||||||
return;
|
return;
|
||||||
@@ -1441,7 +1441,7 @@ ConstraintSolverLayouter::_AddConstraints()
|
|||||||
|
|
||||||
// _AddConstraints
|
// _AddConstraints
|
||||||
void
|
void
|
||||||
ConstraintSolverLayouter::_AddConstraints(const BList& constraints)
|
QocaConstraintSolverLayouter::_AddConstraints(const BList& constraints)
|
||||||
{
|
{
|
||||||
int32 count = constraints.CountItems();
|
int32 count = constraints.CountItems();
|
||||||
for (int32 i = 0; i < count; i++) {
|
for (int32 i = 0; i < count; i++) {
|
||||||
@@ -1507,7 +1507,7 @@ ConstraintSolverLayouter::_AddConstraints(const BList& constraints)
|
|||||||
|
|
||||||
// _RemoveSetSizeConstraint
|
// _RemoveSetSizeConstraint
|
||||||
void
|
void
|
||||||
ConstraintSolverLayouter::_RemoveSetSizeConstraint()
|
QocaConstraintSolverLayouter::_RemoveSetSizeConstraint()
|
||||||
{
|
{
|
||||||
if (fSetSizeConstraintAdded) {
|
if (fSetSizeConstraintAdded) {
|
||||||
fSolver->RemoveConstraint(*fSetSizeConstraint);
|
fSolver->RemoveConstraint(*fSetSizeConstraint);
|
||||||
@@ -1517,7 +1517,7 @@ ConstraintSolverLayouter::_RemoveSetSizeConstraint()
|
|||||||
|
|
||||||
// _RemoveConstraints
|
// _RemoveConstraints
|
||||||
void
|
void
|
||||||
ConstraintSolverLayouter::_RemoveConstraints()
|
QocaConstraintSolverLayouter::_RemoveConstraints()
|
||||||
{
|
{
|
||||||
if (!fConstraintsAdded)
|
if (!fConstraintsAdded)
|
||||||
return;
|
return;
|
||||||
@@ -1547,7 +1547,7 @@ ConstraintSolverLayouter::_RemoveConstraints()
|
|||||||
|
|
||||||
// _RemoveConstraint
|
// _RemoveConstraint
|
||||||
void
|
void
|
||||||
ConstraintSolverLayouter::_RemoveConstraint(Constraint* constraint)
|
QocaConstraintSolverLayouter::_RemoveConstraint(Constraint* constraint)
|
||||||
{
|
{
|
||||||
if (constraint != NULL && constraint->IsAdded()) {
|
if (constraint != NULL && constraint->IsAdded()) {
|
||||||
fSolver->RemoveConstraint(*constraint->QocaConstraint());
|
fSolver->RemoveConstraint(*constraint->QocaConstraint());
|
||||||
@@ -1557,7 +1557,7 @@ ConstraintSolverLayouter::_RemoveConstraint(Constraint* constraint)
|
|||||||
|
|
||||||
// _GetInvolvedConstraints
|
// _GetInvolvedConstraints
|
||||||
void
|
void
|
||||||
ConstraintSolverLayouter::_GetInvolvedConstraints(const BList& constraints,
|
QocaConstraintSolverLayouter::_GetInvolvedConstraints(const BList& constraints,
|
||||||
const BList& variables, BList& filteredConstraints)
|
const BList& variables, BList& filteredConstraints)
|
||||||
{
|
{
|
||||||
filteredConstraints.MakeEmpty();
|
filteredConstraints.MakeEmpty();
|
||||||
@@ -1591,7 +1591,7 @@ ConstraintSolverLayouter::_GetInvolvedConstraints(const BList& constraints,
|
|||||||
|
|
||||||
// _GetViolatedConstraints
|
// _GetViolatedConstraints
|
||||||
void
|
void
|
||||||
ConstraintSolverLayouter::_GetViolatedConstraints(const BList& constraints,
|
QocaConstraintSolverLayouter::_GetViolatedConstraints(const BList& constraints,
|
||||||
BList& violatedConstraints)
|
BList& violatedConstraints)
|
||||||
{
|
{
|
||||||
violatedConstraints.MakeEmpty();
|
violatedConstraints.MakeEmpty();
|
||||||
@@ -1615,7 +1615,7 @@ ConstraintSolverLayouter::_GetViolatedConstraints(const BList& constraints,
|
|||||||
|
|
||||||
// _FilterVariablesByMaxConstraints
|
// _FilterVariablesByMaxConstraints
|
||||||
void
|
void
|
||||||
ConstraintSolverLayouter::_FilterVariablesByMaxConstraints(
|
QocaConstraintSolverLayouter::_FilterVariablesByMaxConstraints(
|
||||||
const BList& variables, const BList& constraints, Set& filteredVars)
|
const BList& variables, const BList& constraints, Set& filteredVars)
|
||||||
{
|
{
|
||||||
filteredVars.MakeEmpty();
|
filteredVars.MakeEmpty();
|
||||||
@@ -1642,7 +1642,7 @@ ConstraintSolverLayouter::_FilterVariablesByMaxConstraints(
|
|||||||
|
|
||||||
// _CompareVariables
|
// _CompareVariables
|
||||||
int
|
int
|
||||||
ConstraintSolverLayouter::_CompareVariables(const void* _a, const void* _b)
|
QocaConstraintSolverLayouter::_CompareVariables(const void* _a, const void* _b)
|
||||||
{
|
{
|
||||||
// compare by distance of the float solution to the integer solution
|
// compare by distance of the float solution to the integer solution
|
||||||
Variable* a = *(Variable**)_a;
|
Variable* a = *(Variable**)_a;
|
||||||
@@ -1658,7 +1658,7 @@ ConstraintSolverLayouter::_CompareVariables(const void* _a, const void* _b)
|
|||||||
|
|
||||||
// _CompareConstraints
|
// _CompareConstraints
|
||||||
int
|
int
|
||||||
ConstraintSolverLayouter::_CompareConstraintsByLength(const void* _a,
|
QocaConstraintSolverLayouter::_CompareConstraintsByLength(const void* _a,
|
||||||
const void* _b)
|
const void* _b)
|
||||||
{
|
{
|
||||||
// compare by number of involved variables
|
// compare by number of involved variables
|
||||||
@@ -1670,7 +1670,7 @@ ConstraintSolverLayouter::_CompareConstraintsByLength(const void* _a,
|
|||||||
|
|
||||||
// _CompareConstraints
|
// _CompareConstraints
|
||||||
int
|
int
|
||||||
ConstraintSolverLayouter::_CompareConstraintsBySatisfactionDistance(
|
QocaConstraintSolverLayouter::_CompareConstraintsBySatisfactionDistance(
|
||||||
const void* _a, const void* _b)
|
const void* _a, const void* _b)
|
||||||
{
|
{
|
||||||
// compare by number of involved variables
|
// compare by number of involved variables
|
||||||
@@ -0,0 +1,144 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2006-2007, Ingo Weinhold <[email protected]>.
|
||||||
|
* All rights reserved. Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
#ifndef QOCA_CONSTRAINT_SOLVER_LAYOUTER_H
|
||||||
|
#define QOCA_CONSTRAINT_SOLVER_LAYOUTER_H
|
||||||
|
|
||||||
|
#include "Layouter.h"
|
||||||
|
|
||||||
|
#include <List.h>
|
||||||
|
|
||||||
|
class QcLinInEqSolver;
|
||||||
|
class QcConstraint;
|
||||||
|
class QcConstraint;
|
||||||
|
|
||||||
|
namespace BPrivate {
|
||||||
|
namespace Layout {
|
||||||
|
|
||||||
|
class QocaConstraintSolverLayouter : public Layouter {
|
||||||
|
public:
|
||||||
|
QocaConstraintSolverLayouter(int32 elementCount,
|
||||||
|
int32 spacing);
|
||||||
|
virtual ~QocaConstraintSolverLayouter();
|
||||||
|
|
||||||
|
virtual void AddConstraints(int32 element, int32 length,
|
||||||
|
float min, float max, float preferred);
|
||||||
|
virtual void SetWeight(int32 element, float weight);
|
||||||
|
|
||||||
|
virtual float MinSize();
|
||||||
|
virtual float MaxSize();
|
||||||
|
virtual float PreferredSize();
|
||||||
|
|
||||||
|
virtual LayoutInfo* CreateLayoutInfo();
|
||||||
|
|
||||||
|
virtual void Layout(LayoutInfo* layoutInfo, float size);
|
||||||
|
|
||||||
|
virtual Layouter* CloneLayouter();
|
||||||
|
|
||||||
|
private:
|
||||||
|
class Set;
|
||||||
|
|
||||||
|
class Variable;
|
||||||
|
class Constraint;
|
||||||
|
class MinConstraint;
|
||||||
|
class MaxConstraint;
|
||||||
|
class MinMaxEntry;
|
||||||
|
class MinMaxMatrix;
|
||||||
|
class MyLayoutInfo;
|
||||||
|
|
||||||
|
friend class Constraint;
|
||||||
|
|
||||||
|
enum {
|
||||||
|
MIN_CONSTRAINT = 0,
|
||||||
|
MAX_CONSTRAINT = 1,
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
void _ValidateMinMax();
|
||||||
|
|
||||||
|
void _AddMinConstraint(int32 first, int32 last,
|
||||||
|
int32 value);
|
||||||
|
void _AddMaxConstraint(int32 first, int32 last,
|
||||||
|
int32 value);
|
||||||
|
|
||||||
|
int32 _ComputeMin();
|
||||||
|
int32 _ComputeMax();
|
||||||
|
bool _ComputeSolution(int32 size);
|
||||||
|
|
||||||
|
bool _FindIntegerSolution(int32 size);
|
||||||
|
bool _FindIntegerSolution(const Set& nonIntVariables,
|
||||||
|
const BList& minConstraints,
|
||||||
|
const BList& maxConstraints,
|
||||||
|
int32 sizeDiff);
|
||||||
|
|
||||||
|
Constraint* _CreateConstraint(int32 type, int32 first,
|
||||||
|
int32 last, int32 value);
|
||||||
|
void _SetConstraint(int32 type,
|
||||||
|
Constraint** constraints,
|
||||||
|
int32 element, int32 value, bool restrict);
|
||||||
|
void _SetConstraint(int32 type,
|
||||||
|
BList& constraints,
|
||||||
|
int32 first, int32 last, int32 value,
|
||||||
|
bool restrict);
|
||||||
|
int _IndexOfConstraint(BList& constraints,
|
||||||
|
int32 first, int32 last);
|
||||||
|
bool _AddSetSizeConstraint(int32 size);
|
||||||
|
|
||||||
|
void _AddConstraints();
|
||||||
|
void _AddConstraints(const BList& constraints);
|
||||||
|
void _RemoveSetSizeConstraint();
|
||||||
|
void _RemoveConstraints();
|
||||||
|
void _RemoveConstraint(Constraint* constraint);
|
||||||
|
void _GetInvolvedConstraints(
|
||||||
|
const BList& constraints,
|
||||||
|
const BList& variables,
|
||||||
|
BList& filteredConstraints);
|
||||||
|
void _GetViolatedConstraints(
|
||||||
|
const BList& constraints,
|
||||||
|
BList& violatedConstraints);
|
||||||
|
void _FilterVariablesByMaxConstraints(
|
||||||
|
const BList& variables,
|
||||||
|
const BList& constraints,
|
||||||
|
Set& filteredVars);
|
||||||
|
|
||||||
|
static int _CompareVariables(const void* a, const void* b);
|
||||||
|
static int _CompareConstraintsByLength(const void* a,
|
||||||
|
const void* b);
|
||||||
|
static int _CompareConstraintsBySatisfactionDistance(
|
||||||
|
const void* a, const void* b);
|
||||||
|
|
||||||
|
private:
|
||||||
|
int32 fElementCount;
|
||||||
|
float* fWeights;
|
||||||
|
|
||||||
|
Constraint** fBasicMinConstraints;
|
||||||
|
Constraint** fBasicMaxConstraints;
|
||||||
|
|
||||||
|
BList fComplexMinConstraints;
|
||||||
|
BList fComplexMaxConstraints;
|
||||||
|
|
||||||
|
Variable* fVariables;
|
||||||
|
Variable* fSizeVariable;
|
||||||
|
|
||||||
|
QcLinInEqSolver* fSolver;
|
||||||
|
QcConstraint* fSizeSumConstraint;
|
||||||
|
QcConstraint* fSetSizeConstraint;
|
||||||
|
|
||||||
|
bool fConstraintsAdded;
|
||||||
|
bool fSetSizeConstraintAdded;
|
||||||
|
|
||||||
|
int32 fSpacing;
|
||||||
|
int32 fMin;
|
||||||
|
int32 fMax;
|
||||||
|
bool fMinMaxValid;
|
||||||
|
|
||||||
|
MyLayoutInfo* fLayoutInfo;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Layout
|
||||||
|
} // namespace BPrivate
|
||||||
|
|
||||||
|
using BPrivate::Layout::QocaConstraintSolverLayouter;
|
||||||
|
|
||||||
|
#endif // QOCA_CONSTRAINT_SOLVER_LAYOUTER_H
|
||||||
@@ -13,6 +13,7 @@ SubInclude HAIKU_TOP src libs libtelnet ;
|
|||||||
SubInclude HAIKU_TOP src libs ncurses ;
|
SubInclude HAIKU_TOP src libs ncurses ;
|
||||||
SubInclude HAIKU_TOP src libs pdflib ;
|
SubInclude HAIKU_TOP src libs pdflib ;
|
||||||
SubInclude HAIKU_TOP src libs png ;
|
SubInclude HAIKU_TOP src libs png ;
|
||||||
|
SubInclude HAIKU_TOP src libs qoca ;
|
||||||
SubInclude HAIKU_TOP src libs stdc++ ;
|
SubInclude HAIKU_TOP src libs stdc++ ;
|
||||||
SubInclude HAIKU_TOP src libs termcap ;
|
SubInclude HAIKU_TOP src libs termcap ;
|
||||||
SubInclude HAIKU_TOP src libs usb ;
|
SubInclude HAIKU_TOP src libs usb ;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
SubDir HAIKU_TOP src kits interface qoca ;
|
SubDir HAIKU_TOP src libs qoca ;
|
||||||
|
|
||||||
# Don't compile qoca with debugging. Debug/non-debug versions are
|
# Don't compile qoca with debugging. Debug/non-debug versions are
|
||||||
# incompatible.
|
# incompatible.
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user