From 96ea6fce9ff92ba776703b6e6340205de12ebb7c Mon Sep 17 00:00:00 2001 From: Jim Evins Date: Wed, 30 Oct 2013 21:34:39 -0400 Subject: [PATCH] Added initial FrameCd, FrameRound and FrameEllipse implementations. --- libglabels/CMakeLists.txt | 3 ++ libglabels/FrameCd.cpp | 91 +++++++++++++++++++++++++++++++++++++ libglabels/FrameCd.h | 66 +++++++++++++++++++++++++++ libglabels/FrameEllipse.cpp | 75 ++++++++++++++++++++++++++++++ libglabels/FrameEllipse.h | 60 ++++++++++++++++++++++++ libglabels/FrameRound.cpp | 73 +++++++++++++++++++++++++++++ libglabels/FrameRound.h | 57 +++++++++++++++++++++++ 7 files changed, 425 insertions(+) create mode 100644 libglabels/FrameCd.cpp create mode 100644 libglabels/FrameCd.h create mode 100644 libglabels/FrameEllipse.cpp create mode 100644 libglabels/FrameEllipse.h create mode 100644 libglabels/FrameRound.cpp create mode 100644 libglabels/FrameRound.h diff --git a/libglabels/CMakeLists.txt b/libglabels/CMakeLists.txt index d9958cb..6cafba6 100644 --- a/libglabels/CMakeLists.txt +++ b/libglabels/CMakeLists.txt @@ -12,6 +12,9 @@ set (libglabels_sources Markup.cpp Frame.cpp FrameRect.cpp + FrameCd.cpp + FrameRound.cpp + FrameEllipse.cpp StrUtil.cpp ) diff --git a/libglabels/FrameCd.cpp b/libglabels/FrameCd.cpp new file mode 100644 index 0000000..5f71554 --- /dev/null +++ b/libglabels/FrameCd.cpp @@ -0,0 +1,91 @@ +/* FrameCd.cpp + * + * Copyright (C) 2013 Jim Evins + * + * 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 . + */ + +#include "FrameCd.h" + +#include + +#include "StrUtil.h" +#include "privateConstants.h" + + +namespace libglabels +{ + + void FrameCd::getSize( double *w, double *h ) const + { + if ( mW == 0 ) + { + *w = 2 * mR1; + } + else + { + *w = mW; + } + + if ( mH == 0 ) + { + *h = 2 * mR1; + } + else + { + *h = mH; + } + } + + + bool FrameCd::isSimilar( Frame *b ) const + { + if ( FrameCd *bCd = dynamic_cast(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; + } + + + QString &FrameCd::getSizeDescription( Units *units ) const + { + if ( units->id() == "in" ) + { + QString dStr = StrUtil::formatFraction( 2 * mR1 * units->unitsPerPoint() ); + + return QString().sprintf( "%s %s %s", + dStr.toStdString().c_str(), + units->name().toStdString().c_str(), + tr("diameter").toStdString().c_str() ); + } + else + { + return QString().sprintf( "%.5g %s %s", + 2 * mR1 * units->unitsPerPoint(), + units->name().toStdString().c_str(), + tr("diameter").toStdString().c_str() ); + } + } + +} + diff --git a/libglabels/FrameCd.h b/libglabels/FrameCd.h new file mode 100644 index 0000000..c1cafd5 --- /dev/null +++ b/libglabels/FrameCd.h @@ -0,0 +1,66 @@ +/* FrameCd.h + * + * Copyright (C) 2013 Jim Evins + * + * 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 . + */ + +#ifndef libglabels_FrameCd_h +#define libglabels_FrameCd_h + +#include "Frame.h" + + +namespace libglabels +{ + + class FrameCd : public Frame + { + public: + FrameCd( double r1, + double r2, + double w, + double h, + double waste, + QString id = "0" ) + : mR1(r1), mR2(r2), mW(w), mH(h), mWaste(waste), Frame(id) + { + } + + inline double r1() const { return mR1; } + inline double r2() const { return mR2; } + inline double w() const { return mW; } + inline double h() const { return mH; } + inline double waste() const { return mWaste; } + + + void getSize( double *w, double *h ) const; + bool isSimilar( Frame *b ) const; + QString &getSizeDescription( Units *units ) const; + + + private: + double mR1; + double mR2; + double mW; + double mH; + double mWaste; + + }; + +} + +#endif // libglabels_FrameCd_h diff --git a/libglabels/FrameEllipse.cpp b/libglabels/FrameEllipse.cpp new file mode 100644 index 0000000..60e95fc --- /dev/null +++ b/libglabels/FrameEllipse.cpp @@ -0,0 +1,75 @@ +/* FrameEllipse.cpp + * + * Copyright (C) 2013 Jim Evins + * + * 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 . + */ + +#include "FrameEllipse.h" + +#include + +#include "StrUtil.h" +#include "privateConstants.h" + + +namespace libglabels +{ + + void FrameEllipse::getSize( double *w, double *h ) const + { + *w = mW; + *h = mH; + } + + + bool FrameEllipse::isSimilar( Frame *b ) const + { + if ( FrameEllipse *bEllipse = dynamic_cast(b) ) + { + if ( (fabs( mW - bEllipse->mW ) <= Constants::EPSILON) && + (fabs( mH - bEllipse->mH ) <= Constants::EPSILON) ) + { + return true; + } + } + return false; + } + + + QString &FrameEllipse::getSizeDescription( Units *units ) const + { + if ( units->id() == "in" ) + { + QString wStr = StrUtil::formatFraction( mW * units->unitsPerPoint() ); + QString hStr = StrUtil::formatFraction( mH * units->unitsPerPoint() ); + + return QString().sprintf( "%s x %s %s", + wStr.toStdString().c_str(), + hStr.toStdString().c_str(), + units->name().toStdString().c_str() ); + } + else + { + return QString().sprintf( "%.5g x %.5g %s", + mW * units->unitsPerPoint(), + mH * units->unitsPerPoint(), + units->name().toStdString().c_str() ); + } + } + +} + diff --git a/libglabels/FrameEllipse.h b/libglabels/FrameEllipse.h new file mode 100644 index 0000000..a6b848e --- /dev/null +++ b/libglabels/FrameEllipse.h @@ -0,0 +1,60 @@ +/* FrameEllipse.h + * + * Copyright (C) 2013 Jim Evins + * + * 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 . + */ + +#ifndef libglabels_FrameEllipse_h +#define libglabels_FrameEllipse_h + +#include "Frame.h" + + +namespace libglabels +{ + + class FrameEllipse : public Frame + { + public: + FrameEllipse( double w, + double h, + double waste, + QString id = "0" ) + : mW(w), mH(h), mWaste(waste), Frame(id) + { + } + + inline double w() const { return mW; } + inline double h() const { return mH; } + inline double waste() const { return mWaste; } + + + void getSize( double *w, double *h ) const; + bool isSimilar( Frame *b ) const; + QString &getSizeDescription( Units *units ) const; + + + private: + double mW; + double mH; + double mWaste; + + }; + +} + +#endif // libglabels_FrameEllipse_h diff --git a/libglabels/FrameRound.cpp b/libglabels/FrameRound.cpp new file mode 100644 index 0000000..4253d12 --- /dev/null +++ b/libglabels/FrameRound.cpp @@ -0,0 +1,73 @@ +/* FrameRound.cpp + * + * Copyright (C) 2013 Jim Evins + * + * 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 . + */ + +#include "FrameRound.h" + +#include + +#include "StrUtil.h" +#include "privateConstants.h" + + +namespace libglabels +{ + + void FrameRound::getSize( double *w, double *h ) const + { + *w = 2*mR; + *h = 2*mR; + } + + + bool FrameRound::isSimilar( Frame *b ) const + { + if ( FrameRound *bRound = dynamic_cast(b) ) + { + if ( fabs( mR - bRound->mR ) <= Constants::EPSILON ) + { + return true; + } + } + return false; + } + + + QString &FrameRound::getSizeDescription( Units *units ) const + { + if ( units->id() == "in" ) + { + QString dStr = StrUtil::formatFraction( 2 * mR * units->unitsPerPoint() ); + + return QString().sprintf( "%s %s %s", + dStr.toStdString().c_str(), + units->name().toStdString().c_str(), + tr("diameter").toStdString().c_str() ); + } + else + { + return QString().sprintf( "%.5g %s %s", + 2 * mR * units->unitsPerPoint(), + units->name().toStdString().c_str(), + tr("diameter").toStdString().c_str() ); + } + } + +} + diff --git a/libglabels/FrameRound.h b/libglabels/FrameRound.h new file mode 100644 index 0000000..f55b4fb --- /dev/null +++ b/libglabels/FrameRound.h @@ -0,0 +1,57 @@ +/* FrameRound.h + * + * Copyright (C) 2013 Jim Evins + * + * 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 . + */ + +#ifndef libglabels_FrameRound_h +#define libglabels_FrameRound_h + +#include "Frame.h" + + +namespace libglabels +{ + + class FrameRound : public Frame + { + public: + FrameRound( double r, + double waste, + QString id = "0" ) + : mR(r), mWaste(waste), Frame(id) + { + } + + inline double r() const { return mR; } + inline double waste() const { return mWaste; } + + + void getSize( double *w, double *h ) const; + bool isSimilar( Frame *b ) const; + QString &getSizeDescription( Units *units ) const; + + + private: + double mR; + double mWaste; + + }; + +} + +#endif // libglabels_FrameRound_h