Added initial implementation of Template.

This commit is contained in:
Jim Evins
2013-11-02 17:10:49 -04:00
parent be55bebc50
commit 262932a4c7
16 changed files with 416 additions and 60 deletions
+1
View File
@@ -16,6 +16,7 @@ set (libglabels_sources
FrameRound.cpp
FrameEllipse.cpp
StrUtil.cpp
Template.cpp
)
set (libglabels_qobject_headers
+27
View File
@@ -24,6 +24,33 @@
namespace libglabels
{
Frame::Frame( const Frame &other )
{
mId = other.mId;
mNLabels = 0;
{
std::list<Layout*>::const_iterator it;
for ( it = other.mLayouts.begin(); it != other.mLayouts.end(); it++ )
{
Layout *layout = (*it)->dup();
addLayout( layout );
}
}
{
std::list<Markup*>::const_iterator it;
for ( it = other.mMarkups.begin(); it != other.mMarkups.end(); it++ )
{
Markup *markup = (*it)->dup();
addMarkup( markup );
}
}
}
std::vector<Point> Frame::getOrigins() const
{
std::vector<Point> origins( nLabels() );
+8 -1
View File
@@ -45,10 +45,16 @@ namespace libglabels
{
}
Frame( const Frame &other );
public:
virtual Frame *dup() const = 0;
inline const QString &id() const { return mId; }
inline int nLabels() const { return mNLabels; }
inline const QString &layoutDescription() { return mLayoutDescription; }
inline const std::list<Layout*> &layouts() { return mLayouts; }
inline const std::list<Markup*> &markups() { return mMarkups; }
std::vector<Point> getOrigins() const;
@@ -59,7 +65,8 @@ namespace libglabels
virtual double h() const = 0;
virtual const QString &sizeDescription( Units *units ) = 0;
virtual bool isSimilar( Frame *b ) const = 0;
virtual bool isSimilarTo( Frame *other ) const = 0;
private:
QString mId;
+16 -16
View File
@@ -29,22 +29,6 @@
namespace libglabels
{
bool FrameCd::isSimilar( Frame *b ) const
{
if ( FrameCd *bCd = dynamic_cast<FrameCd*>(b) )
{
if ( (fabs( mW - bCd->mW ) <= Constants::EPSILON) &&
(fabs( mH - bCd->mH ) <= Constants::EPSILON) &&
(fabs( mR1 - bCd->mR1 ) <= Constants::EPSILON) &&
(fabs( mR2 - bCd->mR2 ) <= Constants::EPSILON) )
{
return true;
}
}
return false;
}
const QString &FrameCd::sizeDescription( Units *units )
{
if ( units->id() == "in" )
@@ -67,5 +51,21 @@ namespace libglabels
return mSizeDescription;
}
bool FrameCd::isSimilarTo( Frame *other ) const
{
if ( FrameCd *otherCd = dynamic_cast<FrameCd*>(other) )
{
if ( (fabs( mW - otherCd->mW ) <= Constants::EPSILON) &&
(fabs( mH - otherCd->mH ) <= Constants::EPSILON) &&
(fabs( mR1 - otherCd->mR1 ) <= Constants::EPSILON) &&
(fabs( mR2 - otherCd->mR2 ) <= Constants::EPSILON) )
{
return true;
}
}
return false;
}
}
+8 -1
View File
@@ -40,6 +40,13 @@ namespace libglabels
{
}
FrameCd( const FrameCd &other )
: mR1(other.mR1), mR2(other.mR2), mW(other.mW), mH(other.mH), mWaste(other.mWaste), Frame(other)
{
}
Frame *dup() const { return new FrameCd( *this ); }
inline double r1() const { return mR1; }
inline double r2() const { return mR2; }
inline double waste() const { return mWaste; }
@@ -48,7 +55,7 @@ namespace libglabels
double h() const { return (mH == 0) ? 2*mR1 : mH; }
const QString &sizeDescription( Units *units );
bool isSimilar( Frame *b ) const;
bool isSimilarTo( Frame *other ) const;
private:
+14 -14
View File
@@ -29,20 +29,6 @@
namespace libglabels
{
bool FrameEllipse::isSimilar( Frame *b ) const
{
if ( FrameEllipse *bEllipse = dynamic_cast<FrameEllipse*>(b) )
{
if ( (fabs( mW - bEllipse->mW ) <= Constants::EPSILON) &&
(fabs( mH - bEllipse->mH ) <= Constants::EPSILON) )
{
return true;
}
}
return false;
}
const QString &FrameEllipse::sizeDescription( Units *units )
{
if ( units->id() == "in" )
@@ -64,5 +50,19 @@ namespace libglabels
}
}
bool FrameEllipse::isSimilarTo( Frame *other ) const
{
if ( FrameEllipse *otherEllipse = dynamic_cast<FrameEllipse*>(other) )
{
if ( (fabs( mW - otherEllipse->mW ) <= Constants::EPSILON) &&
(fabs( mH - otherEllipse->mH ) <= Constants::EPSILON) )
{
return true;
}
}
return false;
}
}
+8 -1
View File
@@ -38,13 +38,20 @@ namespace libglabels
{
}
FrameEllipse( const FrameEllipse &other )
: mW(other.mW), mH(other.mH), mWaste(other.mWaste), Frame(other)
{
}
Frame *dup() const { return new FrameEllipse( *this ); }
inline double waste() const { return mWaste; }
double w() const { return mW; }
double h() const { return mH; }
const QString &sizeDescription( Units *units );
bool isSimilar( Frame *b ) const;
bool isSimilarTo( Frame *other ) const;
private:
+5 -4
View File
@@ -53,12 +53,12 @@ namespace libglabels
}
bool FrameRect::isSimilar( Frame *b ) const
bool FrameRect::isSimilarTo( Frame *other ) const
{
if ( FrameRect *bRect = dynamic_cast<FrameRect*>(b) )
if ( FrameRect *otherRect = dynamic_cast<FrameRect*>(other) )
{
if ( (fabs( mW - bRect->mW ) <= Constants::EPSILON) &&
(fabs( mH - bRect->mH ) <= Constants::EPSILON) )
if ( (fabs( mW - otherRect->mW ) <= Constants::EPSILON) &&
(fabs( mH - otherRect->mH ) <= Constants::EPSILON) )
{
return true;
}
@@ -66,5 +66,6 @@ namespace libglabels
return false;
}
}
+9 -1
View File
@@ -40,6 +40,14 @@ namespace libglabels
{
}
FrameRect( const FrameRect &other )
: mW(other.mW), mH(other.mH), mR(other.mR), mXWaste(other.mXWaste), mYWaste(other.mYWaste),
Frame(other)
{
}
Frame *dup() const { return new FrameRect( *this ); }
inline double r() const { return mR; }
inline double xWaste() const { return mXWaste; }
inline double yWaste() const { return mYWaste; }
@@ -48,7 +56,7 @@ namespace libglabels
double h() const { return mH; }
const QString &sizeDescription( Units *units );
bool isSimilar( Frame *b ) const;
bool isSimilarTo( Frame *other ) const;
private:
+13 -13
View File
@@ -29,19 +29,6 @@
namespace libglabels
{
bool FrameRound::isSimilar( Frame *b ) const
{
if ( FrameRound *bRound = dynamic_cast<FrameRound*>(b) )
{
if ( fabs( mR - bRound->mR ) <= Constants::EPSILON )
{
return true;
}
}
return false;
}
const QString &FrameRound::sizeDescription( Units *units )
{
if ( units->id() == "in" )
@@ -64,5 +51,18 @@ namespace libglabels
return mSizeDescription;
}
bool FrameRound::isSimilarTo( Frame *other ) const
{
if ( FrameRound *otherRound = dynamic_cast<FrameRound*>(other) )
{
if ( fabs( mR - otherRound->mR ) <= Constants::EPSILON )
{
return true;
}
}
return false;
}
}
+8 -1
View File
@@ -37,6 +37,13 @@ namespace libglabels
{
}
FrameRound( const FrameRound &other )
: mR(other.mR), mWaste(other.mWaste), Frame(other)
{
}
Frame *dup() const { return new FrameRound( *this ); }
inline double r() const { return mR; }
inline double waste() const { return mWaste; }
@@ -44,7 +51,7 @@ namespace libglabels
double h() const { return 2*mR; }
const QString &sizeDescription( Units *units );
bool isSimilar( Frame *b ) const;
bool isSimilarTo( Frame *other ) const;
private:
+7 -7
View File
@@ -28,14 +28,14 @@
namespace libglabels
{
bool Layout::is_similar_to( const Layout &b )
bool Layout::isSimilarTo( const Layout *other )
{
return ( (mNx == b.mNx) &&
(mNy == b.mNy) &&
(fabs(mX0 - b.mX0) < Constants::EPSILON) &&
(fabs(mY0 - b.mY0) < Constants::EPSILON) &&
(fabs(mDx - b.mDx) < Constants::EPSILON) &&
(fabs(mDy - b.mDy) < Constants::EPSILON) );
return ( (mNx == other->mNx) &&
(mNy == other->mNy) &&
(fabs(mX0 - other->mX0) < Constants::EPSILON) &&
(fabs(mY0 - other->mY0) < Constants::EPSILON) &&
(fabs(mDx - other->mDx) < Constants::EPSILON) &&
(fabs(mDy - other->mDy) < Constants::EPSILON) );
}
}
+12 -1
View File
@@ -33,6 +33,11 @@ namespace libglabels
{
}
Layout( const Layout &other )
: mNx(other.mNx), mNy(other.mNy), mX0(other.mX0), mY0(other.mY0), mDx(other.mDx), mDy(other.mDy)
{
}
inline int nx() const { return mNx; }
inline int ny() const { return mNy; }
@@ -42,7 +47,13 @@ namespace libglabels
inline double dx() const { return mDx; }
inline double dy() const { return mDy; }
bool is_similar_to( const Layout &b );
bool isSimilarTo( const Layout *other );
inline Layout *dup() const
{
Layout *other = new Layout( *this );
return other;
}
private:
+12
View File
@@ -27,6 +27,8 @@ namespace libglabels
class Markup
{
public:
virtual Markup *dup() const = 0;
};
@@ -39,6 +41,8 @@ namespace libglabels
inline double size() const { return mSize; }
Markup *dup() const { return new MarkupMargin( mSize ); }
private:
double mSize;
};
@@ -56,6 +60,8 @@ namespace libglabels
inline double x2() const { return mX2; }
inline double y2() const { return mY2; }
Markup *dup() const { return new MarkupLine( mX1, mY1, mX2, mY2 ); }
private:
double mX1;
double mY1;
@@ -78,6 +84,8 @@ namespace libglabels
inline double h() const { return mH; }
inline double r() const { return mR; }
Markup *dup() const { return new MarkupRect( mX1, mY1, mW, mH, mR ); }
private:
double mX1;
double mY1;
@@ -100,6 +108,8 @@ namespace libglabels
inline double w() const { return mW; }
inline double h() const { return mH; }
Markup *dup() const { return new MarkupEllipse( mX1, mY1, mW, mH ); }
private:
double mX1;
double mY1;
@@ -120,6 +130,8 @@ namespace libglabels
inline double y0() const { return mY0; }
inline double r() const { return mR; }
Markup *dup() const { return new MarkupCircle( mX0, mY0, mR ); }
private:
double mX0;
double mY0;
+154
View File
@@ -0,0 +1,154 @@
/* Template.cpp
*
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
*
* This file is part of gLabels-qt.
*
* gLabels-qt is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* gLabels-qt 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Template.h"
namespace libglabels
{
Template::Template( const Template &other )
{
mBrand = other.mBrand;
mPart = other.mPart;
mDescription = other.mDescription;
mPaperId = other.mPaperId;
mPageWidth = other.mPageWidth;
mPageHeight = other.mPageHeight;
mEquivPart = other.mEquivPart;
mName = other.mName;
mProductUrl = other.mProductUrl;
{
std::list<Frame*>::const_iterator it;
for ( it = other.mFrames.begin(); it != other.mFrames.end(); it++ )
{
Frame *frame = (*it)->dup();
addFrame( frame );
}
}
{
std::list<QString>::const_iterator it;
for ( it = other.mCategoryIds.begin(); it != other.mCategoryIds.end(); it++ )
{
addCategory( *it );
}
}
}
// Generic full page template
Template *Template::full_page( const QString &paperId )
{
// TODO
return NULL;
}
// From equivalent part number
Template *Template::from_equiv( const QString &brand,
const QString &part,
const QString &equiv_part )
{
// TODO
return NULL;
}
void Template::addCategory( const QString &categoryId )
{
mCategoryIds.push_back( categoryId );
}
void Template::addFrame( Frame *frame )
{
mFrames.push_back( frame );
}
bool Template::operator==( const Template &other ) const
{
return (mBrand == other.mBrand) && (mPart == other.mPart);
}
bool Template::hasCategory( const QString &categoryId ) const
{
std::list<QString>::const_iterator it;
for ( it = mCategoryIds.begin(); it != mCategoryIds.end(); it++ )
{
if ( categoryId == *it )
{
return true;
}
}
return false;
}
bool Template::isSimilarTo( const Template &other ) const
{
// Does page size match?
if ( (mPaperId != other.mPaperId) ||
(mPageWidth != other.mPageWidth ) ||
(mPageHeight != other.mPageHeight ) )
{
return false;
}
// Are frames similar
Frame *frame1 = *(mFrames.begin());
Frame *frame2 = *(other.mFrames.begin());
if ( !frame1->isSimilarTo( frame2 ) )
{
return false;
}
// Are they layed out similarly?
std::list<Layout*>::const_iterator it1;
std::list<Layout*>::const_iterator it2;
for ( it1 = frame1->layouts().begin(); it1 != frame1->layouts().end(); it1++ )
{
bool matchFound = false;
for ( it2 = frame2->layouts().begin(); it2 != frame2->layouts().end(); it2++ )
{
if ( (*it1)->isSimilarTo(*it2) )
{
matchFound = true;
break;
}
}
if ( !matchFound )
{
return false;
}
}
return true;
}
}
+114
View File
@@ -0,0 +1,114 @@
/* Template.h
*
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
*
* This file is part of gLabels-qt.
*
* gLabels-qt is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* gLabels-qt 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef libglabels_Template_h
#define libglabels_Template_h
#include <QCoreApplication>
#include <QString>
#include <list>
#include <vector>
#include "Units.h"
#include "Point.h"
#include "Frame.h"
namespace libglabels
{
class Template
{
Q_DECLARE_TR_FUNCTIONS(Template)
public:
Template( const QString &brand,
const QString &part,
const QString &description,
const QString &paperId,
double pageWidth = 0,
double pageHeight = 0 )
: mBrand(brand),
mPart(part),
mDescription(description),
mPaperId(paperId),
mPageWidth(pageWidth),
mPageHeight(pageHeight)
{
}
Template( const Template &other );
inline Template *dup() const { return new Template( *this ); }
// Generic full page template
static Template *full_page( const QString &paperId );
// From equivalent part number
static Template *from_equiv( const QString &brand,
const QString &part,
const QString &equiv_part );
inline const QString &brand() const { return mBrand; }
inline const QString &part() const { return mPart; }
inline const QString &description() const { return mDescription; }
inline const QString &paperId() const { return mPaperId; }
inline double pageWidth() const { return mPageWidth; }
inline double pageHeight() const { return mPageHeight; }
inline const QString &equivPart() const { return mEquivPart; }
inline void setEquivPart( const QString &value ) { mEquivPart = value; }
inline const QString &productUrl() const { return mProductUrl; }
inline void setProductUrl( const QString &value ) { mProductUrl = value; }
void addCategory( const QString &categoryId );
void addFrame( Frame *frame );
bool operator==( const Template &other ) const;
bool hasCategory( const QString &categoryId ) const;
bool isSimilarTo( const Template &other ) const;
private:
QString mBrand;
QString mPart;
QString mDescription;
QString mPaperId;
double mPageWidth;
double mPageHeight;
QString mEquivPart;
QString mName;
QString mProductUrl;
std::list<QString> mCategoryIds;
std::list<Frame*> mFrames;
};
}
#endif // libglabels_Template_h