# Path: qad_msg.py
# class QadMsgClass():
#    def __init__(self):
#    def translate(self, context, sourceText, disambiguation = None, encoding = QCoreApplication.UnicodeUTF8, n = -1):
# def qadShowPluginHelp(section = "", filename = "index", packageName = None):
# 
# Path: qad_rubberband.py
# class QadRubberBand():
#    def __init__(self, mapCanvas, alternativeBand = False, borderColor = None, fillColor = None):
#       """
#       Se <alternativeBand> = True, il rubber band sarà impostato con più trasparenza e tipolinea punteggiato   
#       """
#       self.mapCanvas = mapCanvas
#       self.__rubberBandPoint = createRubberBand(self.mapCanvas, QGis.Point, alternativeBand, borderColor, fillColor)
#       self.__rubberBandLine = createRubberBand(self.mapCanvas, QGis.Line, alternativeBand, borderColor, fillColor)
#       self.__rubberBandPolygon = createRubberBand(self.mapCanvas, QGis.Polygon, alternativeBand, borderColor, fillColor)
# 
#    def __del__(self):
#       self.hide()
#       
#       self.mapCanvas.scene().removeItem(self.__rubberBandPoint)
#       del self.__rubberBandPoint
#       
#       self.mapCanvas.scene().removeItem(self.__rubberBandLine)
#       del self.__rubberBandLine
#       
#       self.mapCanvas.scene().removeItem(self.__rubberBandPolygon)
#       del self.__rubberBandPolygon         
#    
#    def hide(self):
#       self.__rubberBandPoint.hide()
#       self.__rubberBandLine.hide()
#       self.__rubberBandPolygon.hide()         
# 
#    def show(self):
#       self.__rubberBandPoint.show()
#       self.__rubberBandLine.show()
#       self.__rubberBandPolygon.show()
#       
#    def addGeometry(self, geom, layer):
#       # uso la geometria del layer per risolvere il caso ambiguo in cui
#       # si vuole inserire una linea chiusa in un layer poligono 
#       geomType = layer.geometryType()
#       #geomType = geom.type()
#       if geomType == QGis.Point:
#          self.__rubberBandPoint.addGeometry(geom, layer)
#       elif geomType == QGis.Line:
#          self.__rubberBandLine.addGeometry(geom, layer)
#       elif geomType == QGis.Polygon:
#          self.__rubberBandPolygon.addGeometry(geom, layer)
#       
#    def addGeometries(self, geoms, layer):
#       for g in geoms:
#          self.addGeometry(g, layer)
#          
#          
#    def setLine(self, points):
#       self.__rubberBandLine.reset(QGis.Line)
#       tot = len(points) - 1
#       i = 0
#       while i <= tot:
#          if i < tot:
#             self.__rubberBandLine.addPoint(points[i], False)
#          else: # ultimo punto
#             self.__rubberBandLine.addPoint(points[i], True)
#          i = i + 1
# 
#    def setPolygon(self, points):
#       self.__rubberBandPolygon.reset(QGis.Polygon)
#       tot = len(points) - 1
#       i = 0
#       while i <= tot:
#          if i < tot:
#             self.__rubberBandPolygon.addPoint(points[i], False)
#          else: # ultimo punto
#             self.__rubberBandPolygon.addPoint(points[i], True)
#          i = i + 1
# 
#    def addLinePoint(self, point, doUpdate = True, geometryIndex = 0):
#       self.__rubberBandLine.addPoint(point, doUpdate, geometryIndex)
# 
#    def addPolygonPoint(self, point, doUpdate = True, geometryIndex = 0):
#       self.__rubberBandPolygon.addPoint(point, doUpdate, geometryIndex)
# 
#    def reset(self):
#       self.__rubberBandPoint.reset(QGis.Point)
#       self.__rubberBandLine.reset(QGis.Line)
#       self.__rubberBandPolygon.reset(QGis.Polygon)      
#       
#    def setLineStyle(self, penStyle):      
#       self.__rubberBandLine.setLineStyle(penStyle)
#       self.__rubberBandPolygon.setLineStyle(penStyle)
#       
#    def setBorderColor(self, color):
#       self.__rubberBandPoint.setBorderColor(color)
#       self.__rubberBandLine.setBorderColor(color)
#       self.__rubberBandPolygon.setBorderColor(color)
#       
#    def setFillColor(self, color):
#       self.__rubberBandPolygon.setFillColor(color)


from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.core import *
from qgis.gui import *
from qad_msg import QadMsg
from qad_snapper import *
from qad_snappointsdisplaymanager import *
from qad_variables import *
from qad_getpoint import *
from qad_rubberband import QadRubberBand
import math
import qad_utils
      self.__rubberBand = QadRubberBand(self.canvas, True)

   def setRubberBandColor(self, rubberBandBorderColor, rubberBandFillColor):
      if rubberBandBorderColor is not None:
         self.__rubberBand.setBorderColor(rubberBandBorderColor)
      if rubberBandFillColor is not None:
         self.__rubberBand.setFillColor(rubberBandFillColor)

   def hidePointMapToolMarkers(self):
      QadGetPoint.hidePointMapToolMarkers(self)
      self.__rubberBand.hide()

   def showPointMapToolMarkers(self):
      QadGetPoint.showPointMapToolMarkers(self)
      self.__rubberBand.show()
                             
   def clear(self):
      QadGetPoint.clear(self)
      self.__rubberBand.reset()
      self.mode = None    
      
      
   def canvasMoveEvent(self, event):
      QadGetPoint.canvasMoveEvent(self, event)
      
      self.__rubberBand.reset()
               
      # noto il primo punto si richiede la larghezza del buffer
      if self.mode == Qad_mbuffer_maptool_ModeEnum.FIRST_PT_ASK_FOR_BUFFER_WIDTH:
         width = qad_utils.getDistance(self.startPtForBufferWidth, self.tmpPoint)

# Path: qad_msg.py
# class QadMsgClass():
#    def __init__(self):
#    def translate(self, context, sourceText, disambiguation = None, encoding = QCoreApplication.UnicodeUTF8, n = -1):
# def qadShowPluginHelp(section = "", filename = "index", packageName = None):
# 
# Path: qad_rubberband.py
# class QadRubberBand():
#    def __init__(self, mapCanvas, alternativeBand = False, borderColor = None, fillColor = None):
#       """
#       Se <alternativeBand> = True, il rubber band sarà impostato con più trasparenza e tipolinea punteggiato   
#       """
#       self.mapCanvas = mapCanvas
#       self.__rubberBandPoint = createRubberBand(self.mapCanvas, QGis.Point, alternativeBand, borderColor, fillColor)
#       self.__rubberBandLine = createRubberBand(self.mapCanvas, QGis.Line, alternativeBand, borderColor, fillColor)
#       self.__rubberBandPolygon = createRubberBand(self.mapCanvas, QGis.Polygon, alternativeBand, borderColor, fillColor)
# 
#    def __del__(self):
#       self.hide()
#       
#       self.mapCanvas.scene().removeItem(self.__rubberBandPoint)
#       del self.__rubberBandPoint
#       
#       self.mapCanvas.scene().removeItem(self.__rubberBandLine)
#       del self.__rubberBandLine
#       
#       self.mapCanvas.scene().removeItem(self.__rubberBandPolygon)
#       del self.__rubberBandPolygon         
#    
#    def hide(self):
#       self.__rubberBandPoint.hide()
#       self.__rubberBandLine.hide()
#       self.__rubberBandPolygon.hide()         
# 
#    def show(self):
#       self.__rubberBandPoint.show()
#       self.__rubberBandLine.show()
#       self.__rubberBandPolygon.show()
#       
#    def addGeometry(self, geom, layer):
#       # uso la geometria del layer per risolvere il caso ambiguo in cui
#       # si vuole inserire una linea chiusa in un layer poligono 
#       geomType = layer.geometryType()
#       #geomType = geom.type()
#       if geomType == QGis.Point:
#          self.__rubberBandPoint.addGeometry(geom, layer)
#       elif geomType == QGis.Line:
#          self.__rubberBandLine.addGeometry(geom, layer)
#       elif geomType == QGis.Polygon:
#          self.__rubberBandPolygon.addGeometry(geom, layer)
#       
#    def addGeometries(self, geoms, layer):
#       for g in geoms:
#          self.addGeometry(g, layer)
#          
#          
#    def setLine(self, points):
#       self.__rubberBandLine.reset(QGis.Line)
#       tot = len(points) - 1
#       i = 0
#       while i <= tot:
#          if i < tot:
#             self.__rubberBandLine.addPoint(points[i], False)
#          else: # ultimo punto
#             self.__rubberBandLine.addPoint(points[i], True)
#          i = i + 1
# 
#    def setPolygon(self, points):
#       self.__rubberBandPolygon.reset(QGis.Polygon)
#       tot = len(points) - 1
#       i = 0
#       while i <= tot:
#          if i < tot:
#             self.__rubberBandPolygon.addPoint(points[i], False)
#          else: # ultimo punto
#             self.__rubberBandPolygon.addPoint(points[i], True)
#          i = i + 1
# 
#    def addLinePoint(self, point, doUpdate = True, geometryIndex = 0):
#       self.__rubberBandLine.addPoint(point, doUpdate, geometryIndex)
# 
#    def addPolygonPoint(self, point, doUpdate = True, geometryIndex = 0):
#       self.__rubberBandPolygon.addPoint(point, doUpdate, geometryIndex)
# 
#    def reset(self):
#       self.__rubberBandPoint.reset(QGis.Point)
#       self.__rubberBandLine.reset(QGis.Line)
#       self.__rubberBandPolygon.reset(QGis.Polygon)      
#       
#    def setLineStyle(self, penStyle):      
#       self.__rubberBandLine.setLineStyle(penStyle)
#       self.__rubberBandPolygon.setLineStyle(penStyle)
#       
#    def setBorderColor(self, color):
#       self.__rubberBandPoint.setBorderColor(color)
#       self.__rubberBandLine.setBorderColor(color)
#       self.__rubberBandPolygon.setBorderColor(color)
#       
#    def setFillColor(self, color):
#       self.__rubberBandPolygon.setFillColor(color)


# Path: qad_mbuffer_maptool.py
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.core import *
from qgis.gui import *
from qad_msg import QadMsg
from qad_snapper import *
from qad_snappointsdisplaymanager import *
from qad_variables import *
from qad_getpoint import *
from qad_rubberband import QadRubberBand
import math
import qad_utils

      self.__rubberBand = QadRubberBand(self.canvas, True)

   def setRubberBandColor(self, rubberBandBorderColor, rubberBandFillColor):
      if rubberBandBorderColor is not None:
         self.__rubberBand.setBorderColor(rubberBandBorderColor)
      if rubberBandFillColor is not None:
         self.__rubberBand.setFillColor(rubberBandFillColor)

   def hidePointMapToolMarkers(self):
      QadGetPoint.hidePointMapToolMarkers(self)
      self.__rubberBand.hide()

   def showPointMapToolMarkers(self):
      QadGetPoint.showPointMapToolMarkers(self)
      self.__rubberBand.show()
                             
   def clear(self):
      QadGetPoint.clear(self)
      self.__rubberBand.reset()
      self.mode = None    
      
      
   def canvasMoveEvent(self, event):
      QadGetPoint.canvasMoveEvent(self, event)
      
      self.__rubberBand.reset()
               
      # noto il primo punto si richiede la larghezza del buffer
      if self.mode == Qad_mbuffer_maptool_ModeEnum.FIRST_PT_ASK_FOR_BUFFER_WIDTH:
         width = qad_utils.getDistance(self.startPtForBufferWidth, self.tmpPoint)

         tolerance = QadVariables.get(QadMsg.translate("Environment variables", "TOLERANCE2APPROXCURVE"))