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()*/ ...@@ -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) int* _splitterWidth /*= NULL*/, QSize *_viewportSize)
{ {
if (_view.left(sizeof(COPY_PASTE_VIEW_START_STRING)-1) != QString(COPY_PASTE_VIEW_START_STRING)) // Remove the magic from the string
{ QString temp = _view;
std::cerr << "No View was copied." << std::endl; temp.remove(0,sizeof(COPY_PASTE_VIEW_START_STRING));
return false;
}
// Remove the magic from the string //Split it into its components
QString temp = _view; QStringList split = temp.split(QRegExp("[\\n\\s]"),QString::SkipEmptyParts);
temp.remove(0,sizeof(COPY_PASTE_VIEW_START_STRING));
//Split it into its components // New version
QStringList split = temp.split(QRegExp("[\\n\\s]"),QString::SkipEmptyParts); if ( split.size() >= 37 ) {
ACG::GLMatrixd m, p; //*********************************************************
int pMode; // Parse the components
// first, get the projection and the modelview matrices
// New version //*********************************************************
if ( split.size() >= 37 ) { 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 //parse the window size if requested
// first, get the projection and the modelview matrices //*********************************************************
//********************************************************* if (_windowSize)
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(); //restore the old window size
p(i,j) = split[i*4 + j +16].toDouble(); int w = split[32].toInt();
int h = split[33].toInt();
*_windowSize = QSize(w,h);
} }
}
//********************************************************* //*********************************************************
//parse the window size if requested //parse the splitter width for the toolboxes if requested
//********************************************************* //*********************************************************
if (_windowSize) if (_splitterWidth) {
{ *_splitterWidth = split[34].toInt();
//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 // Projection mode and orthogonal width
//********************************************************* //*********************************************************
if (_splitterWidth) { pMode = split[35].toInt();
*_splitterWidth = split[34].toInt(); ortho_width = split[36].toDouble();
}
//********************************************************* if (_viewportSize && split.size() >= 39) {
// Projection mode and orthogonal width *_viewportSize = QSize(split[37].toInt(), split[38].toInt());
//********************************************************* }
pMode = split[35].toInt();
properties_.orthoWidth( split[36].toDouble() );
if (_viewportSize && split.size() >= 39) { } else if ( split.size() == 36 ) { // Old Version
*_viewportSize = QSize(split[37].toInt(), split[38].toInt());
}
} 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 //parse the window size if requested
// first, get the projection and the modelview matrices //*********************************************************
//********************************************************* if (_windowSize)
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(); //restore the old window size
p(i,j) = split[i*4 + j +16].toDouble(); 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();
//********************************************************* } else { // Garbage ?!
// Return -1 to inform, that the value is unknown std::cerr << "Unable to paste view ... wrong parameter count!! is" << split.size() << std::endl;
//********************************************************* return false;
if (_splitterWidth) {
*_splitterWidth = -1;
} }
//********************************************************* return true;
// Projection mode and orthogonal width }
//*********************************************************
pMode = split[34].toInt();
properties_.orthoWidth( split[35].toDouble() );
} else { // Garbage ?! bool glViewer::decodeView(const QString& _view, QSize *_windowSize /*= NULL*/,
std::cerr << "Unable to paste view ... wrong parameter count!! is" << split.size() << std::endl; 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; 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 // Switch to our gl context
makeCurrent(); makeCurrent();
......
...@@ -290,6 +290,24 @@ public: ...@@ -290,6 +290,24 @@ public:
\note QSize(0,0) indicates that the window is maximized. \note QSize(0,0) indicates that the window is maximized.
*/ */
void encodeView(QString& _view, const QSize& _windowSize = QSize(-1,-1), const int _toolBarWidth = -1); 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(). /** Decode and apply text representation of view encoded by encodeView().
If \c _view was successfully decoded it will immediately be applied If \c _view was successfully decoded it will immediately be applied
and \c true is returned, \c false is returned else. 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