Added initial FrameCd, FrameRound and FrameEllipse implementations.
This commit is contained in:
@@ -12,6 +12,9 @@ set (libglabels_sources
|
||||
Markup.cpp
|
||||
Frame.cpp
|
||||
FrameRect.cpp
|
||||
FrameCd.cpp
|
||||
FrameRound.cpp
|
||||
FrameEllipse.cpp
|
||||
StrUtil.cpp
|
||||
)
|
||||
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
/* FrameCd.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 "FrameCd.h"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#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<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;
|
||||
}
|
||||
|
||||
|
||||
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() );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
/* FrameCd.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_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
|
||||
@@ -0,0 +1,75 @@
|
||||
/* FrameEllipse.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 "FrameEllipse.h"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#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<FrameEllipse*>(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() );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
/* FrameEllipse.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_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
|
||||
@@ -0,0 +1,73 @@
|
||||
/* FrameRound.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 "FrameRound.h"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#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<FrameRound*>(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() );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
/* FrameRound.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_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
|
||||
Reference in New Issue
Block a user