Created
December 1, 2017 03:33
-
-
Save johnhmj/a77edf7bbfb4269f028300f052cb462f to your computer and use it in GitHub Desktop.
AutoCAD Text height calculator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "header.h" | |
// | |
CACADTextHeight::CACADTextHeight() | |
{ | |
this->m_dDIMTXT = 0.0f; | |
this->m_dDIMSCALE = 0.0f; | |
this->m_dViewportScale = 0.0f; | |
this->m_dTextHeightModel = 0.0f; | |
this->m_dTextHeightLayout = 0.0f; | |
} | |
CACADTextHeight::~CACADTextHeight() | |
{ | |
this->m_dDIMTXT = 0.0f; | |
this->m_dDIMSCALE = 0.0f; | |
this->m_dViewportScale = 0.0f; | |
this->m_dTextHeightModel = 0.0f; | |
this->m_dTextHeightLayout = 0.0f; | |
} | |
CACADTextHeight::CACADTextHeight(const CACADTextHeight& _c) | |
{ | |
if (this == &_c) | |
{ | |
return; | |
} | |
this->m_dDIMTXT = _c.m_dDIMTXT; | |
this->m_dDIMSCALE = _c.m_dDIMSCALE; | |
this->m_dViewportScale = _c.m_dViewportScale; | |
this->m_dTextHeightModel = _c.m_dTextHeightModel; | |
this->m_dTextHeightLayout = _c.m_dTextHeightLayout; | |
} | |
CACADTextHeight& CACADTextHeight::operator=(const CACADTextHeight& _c) | |
{ | |
if (this != &_c) | |
{ | |
this->m_dDIMTXT = _c.m_dDIMTXT; | |
this->m_dDIMSCALE = _c.m_dDIMSCALE; | |
this->m_dViewportScale = _c.m_dViewportScale; | |
this->m_dTextHeightModel = _c.m_dTextHeightModel; | |
this->m_dTextHeightLayout = _c.m_dTextHeightLayout; | |
} | |
return *this; | |
} | |
void CACADTextHeight::setDIMTXT(const double _v) | |
{ | |
this->m_dDIMTXT = (_v > 0.0f)?_v:0.0f; | |
double _dTemp = this->m_dViewportScale * this->m_dDIMTXT; | |
this->m_dDIMSCALE = (_dTemp > 0.0f)?(this->m_dTextHeightLayout / _dTemp):0.0f; | |
} | |
void CACADTextHeight::setDIMSCALE(const double _v) | |
{ | |
this->m_dDIMSCALE = (_v > 0.0f)?_v:0.0f; | |
double _dTemp = this->m_dViewportScale * this->m_dDIMSCALE; | |
this->m_dDIMTXT = (_dTemp > 0.0f)?(this->m_dTextHeightLayout / _dTemp):0.0f; | |
} | |
void CACADTextHeight::setViewportScale(const double _v) | |
{ | |
this->m_dViewportScale = (_v > 0.0f)?_v:0.0f; | |
this->m_dTextHeightModel = (this->m_dViewportScale > 0.0f)?(this->m_dTextHeightLayout / this->m_dViewportScale):0.0f; | |
} | |
void CACADTextHeight::setTextHeightModel(const double _v) | |
{ | |
this->m_dTextHeightModel = (_v > 0.0f)?_v:0.0f; | |
} | |
void CACADTextHeight::setTextHeightLayout(const double _v) | |
{ | |
this->m_dTextHeightLayout = (_v > 0.0f)?_v:0.0f; | |
} | |
double CACADTextHeight::getDIMTXT() | |
{ | |
return this->m_dDIMTXT; | |
} | |
double CACADTextHeight::getDIMSCALE() | |
{ | |
return this->m_dDIMSCALE; | |
} | |
double CACADTextHeight::getViewportScale() | |
{ | |
return this->m_dViewportScale; | |
} | |
double CACADTextHeight::getTextHeightModel() | |
{ | |
return this->m_dTextHeightModel; | |
} | |
double CACADTextHeight::getTextHeightLayout() | |
{ | |
return this->m_dTextHeightLayout; | |
} | |
void Header::PrintLineSign(const char _c, const unsigned int _v) | |
{ | |
for (unsigned int i = 0; i < _v; i ++) | |
{ | |
cout << _c; | |
} | |
cout << endl; | |
} | |
void Header::PrintOption(int& _v) | |
{ | |
string _sOption; | |
cout << "1. change " << _TEXT_OPTION_1 << endl; | |
cout << "2. change " << _TEXT_OPTION_2 << endl; | |
cout << "3. change " << _TEXT_OPTION_3 << endl; | |
cout << "4. change " << _TEXT_OPTION_4 << endl; | |
cout << "x. " << _TEXT_OPTION_0 << endl; | |
for (_sOption.clear(); (! _sOption.size()); ) | |
{ | |
cout << "\rInput option: ", getline(cin, _sOption); | |
} | |
_v = _sOption.front(); | |
} | |
void Header::PrintVersion() | |
{ | |
cout << "# AutoCAD Text height v1.0" << endl; | |
cout << "# Date: Dec 1, 2017" << endl; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef _HEADER_H_ | |
#define _HEADER_H_ | |
// | |
#define _LENGTH_VALUE 6 | |
#define _LENGTH_LINE_SIGN 40 | |
#define _TEXT_OPTION_0 "EXIT" | |
#define _TEXT_OPTION_1 "\"Text height of Layout\"" | |
#define _TEXT_OPTION_2 "\"Viewport scale\"" | |
#define _TEXT_OPTION_3 "\"Text height (DIMTXT)\"" | |
#define _TEXT_OPTION_4 "\"Use overall scale of (DIMSCALE)\"" | |
#define _TEXT_OPTION_5 "\"Text height of model\"" | |
// | |
#include <iostream> | |
#include <iomanip> | |
#include <string> | |
// | |
using std::cin; | |
using std::cout; | |
using std::endl; | |
using std::string; | |
// | |
class CACADTextHeight | |
{ | |
// | |
// Text height (DIMTXT) | |
// Use overall scale of (DIMSCALE) | |
// Text height of layout = DIMTXT x DIMSCALE x Viewport scale | |
// Text height of layout = Text height of model x Viewport scale | |
// | |
public: | |
CACADTextHeight(); | |
~CACADTextHeight(); | |
CACADTextHeight(const CACADTextHeight& _c); | |
CACADTextHeight& operator=(const CACADTextHeight& _c); | |
// | |
void setDIMTXT(const double _v); | |
void setDIMSCALE(const double _v); | |
void setViewportScale(const double _v); | |
void setTextHeightModel(const double _v); | |
void setTextHeightLayout(const double _v); | |
// | |
double getDIMTXT(); | |
double getDIMSCALE(); | |
double getViewportScale(); | |
double getTextHeightModel(); | |
double getTextHeightLayout(); | |
private: | |
double m_dDIMTXT, m_dDIMSCALE, m_dViewportScale, m_dTextHeightModel, m_dTextHeightLayout; | |
}; | |
// | |
namespace Header | |
{ | |
void PrintLineSign(const char _c, const unsigned int _v); | |
void PrintOption(int& _v); | |
void PrintVersion(); | |
} | |
// | |
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "header.h" | |
// | |
int wmain(int argc, wchar_t* argv[]) | |
{ | |
CACADTextHeight cACADTextHeight; | |
bool bLoop = true; | |
double _dTemp = 0.0f; | |
int _chOption = 0; | |
Header::PrintVersion(); | |
cout << setiosflags(std::ios_base::fixed); | |
for (; bLoop; _dTemp = 0.0f) | |
{ | |
Header::PrintLineSign('#', _LENGTH_LINE_SIGN); | |
cout << "# " << _TEXT_OPTION_1 << " = " << cACADTextHeight.getTextHeightLayout() << endl; | |
cout << "# " << _TEXT_OPTION_2 << " = " << cACADTextHeight.getViewportScale() << endl; | |
cout << "# " << _TEXT_OPTION_3 << " = " << cACADTextHeight.getDIMTXT() << endl; | |
cout << "# " << _TEXT_OPTION_4 << " = " << cACADTextHeight.getDIMSCALE() << endl; | |
cout << "# " << _TEXT_OPTION_5 << " = " << cACADTextHeight.getTextHeightModel() << endl; | |
Header::PrintLineSign('#', _LENGTH_LINE_SIGN); | |
Header::PrintOption(_chOption); | |
switch (_chOption) | |
{ | |
case '1': | |
cout << "Input " << _TEXT_OPTION_1 << ": ", cin >> _dTemp; | |
cACADTextHeight.setTextHeightLayout(_dTemp); | |
break; | |
case '2': | |
cout << "Input " << _TEXT_OPTION_2 << ": ", cin >> _dTemp; | |
cACADTextHeight.setViewportScale(_dTemp); | |
break; | |
case '3': | |
cout << "Input " << _TEXT_OPTION_3 << ": ", cin >> _dTemp; | |
cACADTextHeight.setDIMTXT(_dTemp); | |
break; | |
case '4': | |
cout << "Input " << _TEXT_OPTION_4 << ": ", cin >> _dTemp; | |
cACADTextHeight.setDIMSCALE(_dTemp); | |
break; | |
case 'x': | |
case 'X': | |
bLoop = false; | |
break; | |
default: | |
cout << "# ERROR: incorrect option." << endl; | |
break; | |
} | |
cout << endl; | |
} | |
// | |
// PAUSE | |
// for process cin stream, not string class | |
// cin.clear(); | |
// cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); | |
cout << "press any key to continue..."; | |
cin.get(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment