Skip to content
Snippets Groups Projects
Select Git revision
  • 13fa395eb7b72646cca6fe1e12210e57ed545d76
  • master default protected
  • develop protected
  • cmake_boost_refactor
  • ubuntu_ci
  • mmtf
  • non-orthogonal-maps
  • no_boost_filesystem
  • data_viewer
  • 2.11.1
  • 2.11.0
  • 2.10.0
  • 2.9.3
  • 2.9.2
  • 2.9.1
  • 2.9.0
  • 2.8.0
  • 2.7.0
  • 2.6.1
  • 2.6.0
  • 2.6.0-rc4
  • 2.6.0-rc3
  • 2.6.0-rc2
  • 2.6.0-rc
  • 2.5.0
  • 2.5.0-rc2
  • 2.5.0-rc
  • 2.4.0
  • 2.4.0-rc2
29 results

export_map.cc

Blame
  • gl_win.cc 4.63 KiB
    //------------------------------------------------------------------------------
    // This file is part of the OpenStructure project <www.openstructure.org>
    //
    // Copyright (C) 2008-2010 by the OpenStructure authors
    //
    // This library is free software; you can redistribute it and/or modify it under
    // the terms of the GNU Lesser General Public License as published by the Free
    // Software Foundation; either version 3.0 of the License, or (at your option)
    // any later version.
    // This library 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 Lesser General Public License for more
    // details.
    //
    // You should have received a copy of the GNU Lesser General Public License
    // along with this library; if not, write to the Free Software Foundation, Inc.,
    // 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
    //------------------------------------------------------------------------------
    #include <ost/log.hh>
    #include <ost/config.hh>
    #include <ost/gfx/scene.hh>
    
    #include <ost/gui/gl_win.hh>
    #include <ost/gui/tools/tool_manager.hh>
    #include <ost/gui/tools/selection_tool.hh>
    #include <ost/gui/tools/manipulator.hh>
    #include <ost/gui/tools/measure_tool.hh>
    #include <ost/gui/gosty_app.hh>
    #include <ost/gui/perspective.hh>
    
    #if OST_IMG_ENABLED
    #  include <ost/gui/tools/map_tool.hh>
    #endif
    
    #include <QApplication>
    #include <QDesktopWidget>
    #include <QIcon>
    #include <QActionGroup>
    #include <QLabel>
    #include <QStatusBar>
    #include <QVBoxLayout>
    
    /*
      Authors: Ansgar Philippsen, Marco Biasini
     */
    
    namespace ost { namespace gui {
    
    GLWin::GLWin(QWidget* p):
      Widget(NULL, p), 
      gl_canvas_(NULL)
    {
      QMainWindow* main=new QMainWindow;
      for(int format_id=2;format_id>=0;--format_id) {
        gl_canvas_=new GLCanvas(this, main, GLWin::CreateFormat(format_id));
        if(gl_canvas_->isValid()) {
          break; // format is fine
        } else {
          delete gl_canvas_; // delete this canvas and try a less sophisticated format
        }
      }
    
      if(!gl_canvas_->isValid()) {
        LOGN_ERROR("no valid GL context found, GL canvas could not be created");
        return;
      }
    
      this->SetInternalWidget(main);
      gfx::Scene::Instance().AttachObserver(this);
      QGLFormat format = gl_canvas_->format();
      LOGN_VERBOSE("GLCanvas created with rbits=" << format.redBufferSize() 
                   << " gbits=" << format.greenBufferSize() 
                   << " bbits=" << format.blueBufferSize() 
                   << " abits=" << format.alphaBufferSize() 
                   << " dbits=" << format.depthBufferSize()
                   << " accumbits=" << format.accumBufferSize()
                   << " multisample=" << format.sampleBuffers()
                   << " with samples=" << format.samples());
      main->setCentralWidget(gl_canvas_);
      connect(gl_canvas_, SIGNAL(ReleaseFocus()), this, SIGNAL(ReleaseFocus()));
      connect(&ToolManager::Instance(), SIGNAL(ActiveToolChanged(Tool*)), this, SLOT(ActiveToolChanged(Tool*)));
      toolbar_=build_toolbar();     
      main->addToolBar(Qt::LeftToolBarArea, toolbar_);
      ToolManager::Instance().AddTool(new SelectionTool);
      ToolManager::Instance().AddTool(new Manipulator);
      ToolManager::Instance().AddTool(new MeasureTool);
    #if OST_IMG_ENABLED
      ToolManager::Instance().AddTool(new MapTool);
    #endif
      QBoxLayout* l=new QVBoxLayout(this);
      l->setMargin(0);
      l->setSpacing(0);
      l->addWidget(main);
    }
    
    void GLWin::ActiveToolChanged(Tool* t)
    {
      gfx::Scene::Instance().RequestRedraw();
    }
    
    QGLFormat GLWin::CreateFormat(int fid)
    {
      QGLFormat format = QGLFormat::defaultFormat();
      if(fid==2) {
        format.setDepthBufferSize(12);
        format.setRedBufferSize(8);
        format.setGreenBufferSize(8);
        format.setBlueBufferSize(8);
        format.setAlpha(true);
        format.setAlphaBufferSize(8);
        format.setAccum(true);
        format.setSampleBuffers(true);
      } else if(fid==1) {
        format.setDepthBufferSize(12);
        format.setRedBufferSize(8);
        format.setGreenBufferSize(8);
        format.setBlueBufferSize(8);
        format.setAlpha(true);
        format.setAlphaBufferSize(8);
      } else {
        format.setDepthBufferSize(6);
        format.setRedBufferSize(4);
        format.setGreenBufferSize(4);
        format.setBlueBufferSize(4);
      }
      return format;  
    }
    
    GLWin::~GLWin()
    {
      gfx::Scene::Instance().DetachObserver(this);
    }
    
    void GLWin::SetTestMode(bool f)
    {
      gl_canvas_->SetTestMode(f);
    }
    
    ToolBar* GLWin::build_toolbar()
    {
      ToolBar* tb=new ToolBar(this);
      return tb;
    }
    
    void GLWin::StatusMessage(const String& m)
    {
      GostyApp::Instance()->GetPerspective()->StatusMessage(m);
    }
    
    bool GLWin::Restore(const QString& prefix)
    {
      return true;
    }
    
    bool GLWin::Save(const QString& prefix)
    {
      return true;
    }
    
    }} // ns