//
// Copyright (C) 2004-2011 by Autodesk, Inc.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of version 2.1 of the GNU Lesser
// General Public License as published by the Free Software Foundation.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
//
#ifndef GRIDTHEME_H_
#define GRIDTHEME_H_
#include "MdfModel.h"
#include "GridColorRule.h"
#include "Color.h"
///
/// Class GridBucket is used to store the parsed result of one filter string.
/// It includes the mathematic range info and the color which should be used on that range.
/// Moreover, it also supports the comparison with other GridBucket object.
/// Some instance of GridBucket are organized by GridTheme.
///
class GridBucket
{
public:
///
/// Enum CompareResultType defined three results when compare with two
/// GridBuckest.
///
enum CompareResultType
{
kLess,
kGreater,
kOverlapped
};
///
/// Constructor.
///
GridBucket();
///
/// Destructor.
///
~GridBucket();
///
/// Function to set the range of this GridBucket.
///
///
/// The min value of the range.
///
///
/// If bEqualBeginValue is ture, that means "dBeginValue" is in the range.
/// Otherwise, only the value which is greater then "dBeginValue" can be
/// in the range.
///
///
/// The max value of the range.
///
///
/// If bEqualEndValue is ture, that means "dEndValue" is in the range.
/// Otherwise, only the value which is less then "dEndValue" can be
/// in the range.
///
void SetRange(double dBeginValue, bool bEqualBeginValue, double dEndValue, bool bEqualEndValue);
///
/// Function to check whether the argument is in the bucket or not.
///
///
/// If the pass argument value is in the range, returns true.
/// Otherwise, returns false.
///
bool IsValueInBucket(double value) const;
///
/// Retrieve the color value of the GridBucket.
///
const Color& GetColor() const;
///
/// Set the color of the GridBucketl
///
void SetColor(const Color &color);
///
/// Retrieve the begin value of the range.
///
double GetBeginValue() const;
///
/// Retrieve whether the begin value is in the range.
///
bool IsEqualToBeginValue() const;
///
/// Retrieve the end value of the range.
///
double GetEndValue() const;
///
/// Retrieve whether the end value is in the range.
///
bool IsEqualToEndValue() const;
///
/// Static function to compare two buckets.
/// If all the value of left bucket is less than right bucket, the result is CompareResultType::kLess.
/// If all the value of left bucket is greater than right bucket, the result is CompareResultType::kGreater.
/// Otherwise, the result is CompareResultType::kOverlapped.
///
static CompareResultType CompareBuckets(const GridBucket &left, const GridBucket &right);
private:
// Begin value of the range.
double m_dBeginValue;
// Whether the begin value is in the range.
bool m_bEqualBeginValue;
// End value of the range.
double m_dEndValue;
// Whether the End value is in the range.
bool m_bEqualEndValue;
// keeps track of comparison functions to use
// when checking if value is in a bucket
int m_compareMask;
// Color of the bucket.
Color m_color;
public:
// The min value.
static const double sm_MinDouble;
// The max value.
static const double sm_MaxDouble;
};
///
/// Class GridTheme is used to manage the collection of GridBucket.
/// It also supports to search the corresponding bucket or color
/// through the value.
///
class GridTheme
{
public:
///
/// Constructor
///
GridTheme();
///
/// Destructor.
///
~GridTheme();
///
/// Function to find which bucket the value is in.
/// And it returns that bucket's defined color.
///
///
/// Returns true if find the color.
/// Otherwise, returns false.
///
bool SearchColorByValue(Color &color, double value) const;
///
/// Retrieve the band name that the theme applies on.
///
const MdfModel::MdfString& GetBandName() const;
///
/// Set the band name that the theme will applies on.
///
void SetBandName(const MdfModel::MdfString &sBandName);
///
/// Retrieve the theme type. It can be Aspect, Slope, or Height.
///
const MdfModel::MdfString& GetType() const;
///
/// Set the theme type.
///
void SetType(const MdfModel::MdfString &sType);
///
/// Retrieve the count of buckets.
///
int GetBucketCount();
///
/// Adopt the bucket into the current collection of the bucket.
/// It will compare the bucket with the existing buckets and find
/// a reasonable place to store the bucket.
/// It returns true, this GridTheme takes ownership of pBucket.
/// Caller cannot free the pBucket anymore.
///
///
/// Returns true if the pBucket is adopted by the GridTheme.
/// Otherwise, returns false.
///
bool AdoptBucket(GridBucket *pBucket);
///
/// Orphan the bucket at nIndex.
///
///
/// Returns the pointer of orphan bucket.
///
GridBucket* OrphanBucketAt(int nIndex);
///
/// Orphan the pBucket.
///
///
/// Returns the pointer of orphan bucket.
///
GridBucket* OrphanBucket(GridBucket *pBucket);
///
/// Retrieve the bucket at nIndex.
///
GridBucket* GetBucketAt(int nIndex);
private:
// Band that theme will apply on
MdfModel::MdfString m_sBandName;
// Theme type
MdfModel::MdfString m_sType;
// Grid Buckets
MdfModel::MdfOwnerCollection m_buckets;
};
///
/// Class GridThemeHashTable is used to improve the search performance of GridTheme.
/// It generates a hash table from the GridTheme's Buckets. And the caller can get the
/// same result from this class, and benefit better performance.
///
class GridThemeHashTable
{
public:
///
/// Constructor
///
GridThemeHashTable();
///
/// Destructor.
///
~GridThemeHashTable();
///
/// Function to initialze the hash table.
///
///
/// Returns true if the hash table is generated.
/// Otherwise, returns false.
///
bool Initialize(GridTheme *pTheme);
///
/// Function to search the corresponding color according
/// to the value. It will calculate the index value first and
/// search the color by the index value. So the performance is better
/// than GridTheme's same funciton.
///
bool SearchColorByValue(Color &color, double value) const;
///
/// Clear the generated hash table.
///
void Clear();
private:
// Start value of the hash table
double m_dStart;
// End value of the hash table
double m_dInterval;
double m_dInvInterval;
// The rows of hash table.
std::vector > m_vHashRows;
};
#endif