Commit 7b028e69 authored by Hans-Christian Ebke's avatar Hans-Christian Ebke

Refactored glWidget::decodeView.


git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@19065 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 0f6f26c5
......@@ -1124,114 +1124,128 @@ void glViewer::encodeView(QString& _view, const QSize& _windowSize /*= QSize()*/
//----------------------------------------------------------------------------
bool glViewer::decodeView(const QString& _view, QSize *_windowSize /*= NULL*/,
bool glViewer::decodeView(const QString& _view,
ACG::GLMatrixd &m, ACG::GLMatrixd &p, int &pMode, double &ortho_width,
QSize *_windowSize /*= NULL*/,
int* _splitterWidth /*= NULL*/, QSize *_viewportSize)
{
if (_view.left(sizeof(COPY_PASTE_VIEW_START_STRING)-1) != QString(COPY_PASTE_VIEW_START_STRING))
{
std::cerr << "No View was copied." << std::endl;
return false;
}
// Remove the magic from the string
QString temp = _view;
temp.remove(0,sizeof(COPY_PASTE_VIEW_START_STRING));
// Remove the magic from the string
QString temp = _view;
temp.remove(0,sizeof(COPY_PASTE_VIEW_START_STRING));
//Split it into its components
QStringList split = temp.split(QRegExp("[\\n\\s]"),QString::SkipEmptyParts);
//Split it into its components
QStringList split = temp.split(QRegExp("[\\n\\s]"),QString::SkipEmptyParts);
// New version
if ( split.size() >= 37 ) {
ACG::GLMatrixd m, p;
int pMode;
// New version
if ( split.size() >= 37 ) {
//*********************************************************
// Parse the components
// first, get the projection and the modelview matrices
//*********************************************************
for (std::size_t i = 0; i < 4; ++i)
{
for (std::size_t j = 0; j < 4; ++j)
{
m(i,j) = split[i*4 + j].toDouble();
p(i,j) = split[i*4 + j +16].toDouble();
}
}
//*********************************************************
// Parse the components
// first, get the projection and the modelview matrices
//*********************************************************
for (std::size_t i = 0; i < 4; ++i)
{
for (std::size_t j = 0; j < 4; ++j)
//*********************************************************
//parse the window size if requested
//*********************************************************
if (_windowSize)
{
m(i,j) = split[i*4 + j].toDouble();
p(i,j) = split[i*4 + j +16].toDouble();
//restore the old window size
int w = split[32].toInt();
int h = split[33].toInt();
*_windowSize = QSize(w,h);
}
}
//*********************************************************
//parse the window size if requested
//*********************************************************
if (_windowSize)
{
//restore the old window size
int w = split[32].toInt();
int h = split[33].toInt();
*_windowSize = QSize(w,h);
}
//*********************************************************
//parse the splitter width for the toolboxes if requested
//*********************************************************
if (_splitterWidth) {
*_splitterWidth = split[34].toInt();
}
//*********************************************************
//parse the splitter width for the toolboxes if requested
//*********************************************************
if (_splitterWidth) {
*_splitterWidth = split[34].toInt();
}
//*********************************************************
// Projection mode and orthogonal width
//*********************************************************
pMode = split[35].toInt();
ortho_width = split[36].toDouble();
//*********************************************************
// Projection mode and orthogonal width
//*********************************************************
pMode = split[35].toInt();
properties_.orthoWidth( split[36].toDouble() );
if (_viewportSize && split.size() >= 39) {
*_viewportSize = QSize(split[37].toInt(), split[38].toInt());
}
if (_viewportSize && split.size() >= 39) {
*_viewportSize = QSize(split[37].toInt(), split[38].toInt());
}
} else if ( split.size() == 36 ) { // Old Version
} else if ( split.size() == 36 ) { // Old Version
//*********************************************************
// Parse the components
// first, get the projection and the modelview matrices
//*********************************************************
for (std::size_t i = 0; i < 4; ++i)
{
for (std::size_t j = 0; j < 4; ++j)
{
m(i,j) = split[i*4 + j].toDouble();
p(i,j) = split[i*4 + j +16].toDouble();
}
}
//*********************************************************
// Parse the components
// first, get the projection and the modelview matrices
//*********************************************************
for (std::size_t i = 0; i < 4; ++i)
{
for (std::size_t j = 0; j < 4; ++j)
//*********************************************************
//parse the window size if requested
//*********************************************************
if (_windowSize)
{
m(i,j) = split[i*4 + j].toDouble();
p(i,j) = split[i*4 + j +16].toDouble();
//restore the old window size
int w = split[32].toInt();
int h = split[33].toInt();
*_windowSize = QSize(w,h);
}
}
//*********************************************************
//parse the window size if requested
//*********************************************************
if (_windowSize)
{
//restore the old window size
int w = split[32].toInt();
int h = split[33].toInt();
*_windowSize = QSize(w,h);
}
//*********************************************************
// Return -1 to inform, that the value is unknown
//*********************************************************
if (_splitterWidth) {
*_splitterWidth = -1;
}
//*********************************************************
// Projection mode and orthogonal width
//*********************************************************
pMode = split[34].toInt();
ortho_width = split[35].toDouble();
//*********************************************************
// Return -1 to inform, that the value is unknown
//*********************************************************
if (_splitterWidth) {
*_splitterWidth = -1;
} else { // Garbage ?!
std::cerr << "Unable to paste view ... wrong parameter count!! is" << split.size() << std::endl;
return false;
}
//*********************************************************
// Projection mode and orthogonal width
//*********************************************************
pMode = split[34].toInt();
properties_.orthoWidth( split[35].toDouble() );
return true;
}
} else { // Garbage ?!
std::cerr << "Unable to paste view ... wrong parameter count!! is" << split.size() << std::endl;
bool glViewer::decodeView(const QString& _view, QSize *_windowSize /*= NULL*/,
int* _splitterWidth /*= NULL*/, QSize *_viewportSize)
{
if (_view.left(sizeof(COPY_PASTE_VIEW_START_STRING)-1) != QString(COPY_PASTE_VIEW_START_STRING))
{
std::cerr << "No View was copied." << std::endl;
return false;
}
ACG::GLMatrixd m, p;
int pMode;
double ortho_width;
if (!decodeView(_view, m, p, pMode, ortho_width,
_windowSize, _splitterWidth, _viewportSize))
return false;
properties_.orthoWidth(ortho_width);
// Switch to our gl context
makeCurrent();
......
......@@ -290,6 +290,24 @@ public:
\note QSize(0,0) indicates that the window is maximized.
*/
void encodeView(QString& _view, const QSize& _windowSize = QSize(-1,-1), const int _toolBarWidth = -1);
/** Decode text representation of view encoded by encodeView() into
the supplied output parameters.
If \c _view was successfully decoded \c true is returned, \c false is
returned otherwise.
You can save the current Window size via parameter _windowSize and one
splitter size via _splitterwidth
\note QSize(0,0) indicates that the window was maximized.
\note _splitterWidth is -1 if no splitterWidth was saved
*/
static bool decodeView(const QString& _view,
ACG::GLMatrixd &m, ACG::GLMatrixd &p, int &pMode, double &ortho_width,
QSize *_windowSize = NULL,
int* _splitterWidth = NULL, QSize *_viewportSize = NULL);
/** Decode and apply text representation of view encoded by encodeView().
If \c _view was successfully decoded it will immediately be applied
and \c true is returned, \c false is returned else.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment