"""
     pygl/graphicsmodel.py: CCP4MG Molecular Graphics Program
     Copyright (C) 2001-2008 University of York, CCLRC
     Copyright (C) 2009-2010 University of York
     Copyright (C) 2012 STFC

     This library is free software: you can redistribute it and/or
     modify it under the terms of the GNU Lesser General Public License
     version 3, modified in accordance with the provisions of the 
     license to address the requirements of UK law.
 
     You should have received a copy of the modified GNU Lesser General 
     Public License along with this library.  If not, copies may be 
     downloaded from http://www.ccp4.ac.uk/ccp4license.php
 
     This program 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.
"""


from displayobject import *
import cprim
from PyQt4 import QtCore, QtGui
import UtilityThread
import sys

class graphicsmodel:
   """
   Virtual graphics model class.
   Contains constructor and means of building primitives.
   """
   def __init__(self):
     self.graphicsmodel_init()

   def graphicsmodel_init(self,ui=''):
     self.obj = cprim.Displayobject()
     self.origin = (0,0,0)
     self.com = (0,0,0)
     self.style = "BONDS" # !??
     self.name = ""
     self.visible = 1
     self.first_build = 1
     self.ifColourContinuous = 0 # !??
     self.draw_symmetry = 0 # !??
     self.ui = ui
     self.symmetry_dependent = None
     self.doCentralSymmetry = True

   def setparams(self,**keywords):
      for key in keywords.keys():
         #print "setparams",key,keywords[key]
         setattr(self,key,keywords[key])

   def rebuild1(self):
      # The following two lines need to be backgrounded. (ie. Do as QThread).
      self.build_primitives()
      self.obj.rebuild()

   def rebuild2(self):
      # When they are done we do the rest. (ie. act on thread finished signal).
      self.first_build = 0
      import MGApplication
      win = MGApplication.GetMainWindow()
      #win.rebuildGLDisplayObject(self)
      """
      win.statusBar().showMessage(self.mt.tr(""))
      import mginterrupt
      mginterrupt.mginterrupt.SetStatus(0)
      if hasattr(self,'mtStopAction'): win.toolbar.removeAction(self.mtStopAction)
      """

   def stopRebuild(self):
      import mginterrupt
      mginterrupt.mginterrupt.SetStatus(1)

   """
   def addStopSign(self):
      if not self.mt.isRunning(): return
      import MGApplication,os
      win = MGApplication.GetMainWindow()
      win.statusBar().showMessage(self.mt.tr("Recalculating display object"))
      stopSign = QtGui.QIcon(os.path.join(os.environ['CCP4MG'],'qticons','stop_sign_128x128.png'))
      self.mtStopAction = win.toolbar.addAction(stopSign,self.mt.tr("Stop current calculation"))
      self.mt.connect(self.mtStopAction,QtCore.SIGNAL("triggered(bool)"),self.stopRebuild)
   """

   def rebuild(self):
      self.rebuild1()
      #self.rebuild2()
      return
      """
      app = QtGui.QApplication.instance()
      import MGApplication
      win = MGApplication.GetMainWindow()
      QtCore.QTimer.singleShot(500,self.addStopSign);
      #self.addStopSign()
      app.flush()
      self.mt.start()
      """

   def build_primitives(self):
     pass

   def label_primitive(self,primid,text_label=""):
     pass

   def SetupSymmetry(self,point,extents,**keywords):
     pass

   def DrawUnitCell(self,draw_unit_cell=0,xshift=0,yshift=0,zshift=0):
     pass

   def changeparams(self,**keywords):
     pass

   def copy_c_params(self):
     pass

   def GetAtomsInVolume(self,contained_volume):
     return []

   def GetClickedLinesAndPoints(self,xyzbox,near,far):
      self.line = [-1,-1,32768, -1]


   def GetClickedAtoms(self,a,b,c):
      return [None,None,32768,-1]
   
   def ClickedPrimitiveCoords(self):
     return None

   def AddLabel(self,text_label=""):
     pass

   def GetPrimitiveLabel(self,user_defined=0):
     pass

   def GetAtomLabel(self,atomPtr,user_defined=1):
     pass

   def GetMaxDimension(self):
     return -1

   def setup_symmetry(self,p,extents):
     pass

   def copy_params(self,params):
     pass

   def change_style(self,style):
     pass


