import FreeCAD
if FreeCAD.GuiUp:
    import FreeCADGui, os
    from PySide.QtCore import QT_TRANSLATE_NOOP
else:
    # \cond
    def translate(ctxt,txt):
        return txt
    def QT_TRANSLATE_NOOP(ctxt,txt):
        return txt
    # \endcond

global __dir__
__dir__ = os.path.join(FreeCAD.getUserAppDataDir(), "Mod", "PVPlant")


class _CommandReload:
    def GetResources(self):
        return {'Pixmap': str(os.path.join(__dir__, "Resources", "Icons", "Reload.svg")),
                'Accel': "R,E",
                'MenuText': QT_TRANSLATE_NOOP("Reload","Reload"),
                'ToolTip': QT_TRANSLATE_NOOP("Reload","Reload")}

    def Activated(self):
        import PVPlantPlacement, \
            PVPlantGeoreferencing, PVPlantImportGrid, PVPlantTerrainAnalisys, \
            PVPlantSite, PVPlantRackChecking, PVPlantCreateTerrainMesh, \
            PVPlantFoundation, PVPlantBuilding, PVPlantEarthWorks, PVPlantPad, \
            PVPlantRoad, PVPlantTerrain, PVPlantStringing, PVPlantManhole, \
            GraphProfile

        from Civil.Fence import PVPlantFenceGate as PVPlantFenceGate
        from Civil.Fence import PVPlantFence as PVPlantFence
        from Civil.Fence import PVPlantFencePost as PVPlantFencePost

        from Civil import PVPlantTrench
        from Vegetation import PVPlantTreeGenerator

        from Mechanical.Frame import PVPlantFrame
        from Project.Area import PVPlantArea, PVPlantAreaUtils
        #from Importer import importDXF
        from Export import PVPlantBOQCivil, PVPlantBOQElectrical, PVPlantBOQMechanical, exportPVSyst, exportDXF
        from Utils import PVPlantUtils, PVPlantTrace, m_gui_edit, profile_editor, graphics

        from Electrical.Cable import PVPlantCable, PVPlantElectricalLine
        from Electrical import Conduit
        from Electrical.CombinerBox import PVPlantStringBox
        from Electrical.Inverter import PVPlantInverter

        from Export import layoutToExcel
        import MeshTools.MeshGetBoundary as MeshGetBoundary
        import MeshTools.Triangulation as Triangulation
        from Project import ProjectSetup
        import importlib
        import hydro.hydrological as hydro
        import Importer.importOSM as iOSM

        import docgenerator

        importlib.reload(docgenerator)

        importlib.reload(ProjectSetup)
        importlib.reload(PVPlantPlacement)
        importlib.reload(PVPlantImportGrid)
        importlib.reload(PVPlantGeoreferencing)
        importlib.reload(PVPlantTerrainAnalisys)
        importlib.reload(PVPlantSite)
        importlib.reload(PVPlantFrame)
        importlib.reload(PVPlantRackChecking)

        importlib.reload(PVPlantFence)
        importlib.reload(PVPlantFenceGate)
        importlib.reload(PVPlantFencePost)

        importlib.reload(PVPlantFoundation)
        importlib.reload(PVPlantCreateTerrainMesh)
        importlib.reload(PVPlantTreeGenerator)
        importlib.reload(PVPlantBuilding)
        importlib.reload(exportPVSyst)
        importlib.reload(PVPlantTrench)
        importlib.reload(PVPlantEarthWorks)

        importlib.reload(PVPlantStringBox)
        importlib.reload(PVPlantCable)
        importlib.reload(PVPlantElectricalLine)
        importlib.reload(PVPlantInverter)

        importlib.reload(PVPlantPad)
        importlib.reload(PVPlantRoad)
        importlib.reload(PVPlantTerrain)
        importlib.reload(PVPlantStringing)
        importlib.reload(PVPlantBOQCivil)
        importlib.reload(PVPlantBOQMechanical)
        importlib.reload(PVPlantBOQElectrical)
        importlib.reload(PVPlantArea)
        importlib.reload(PVPlantAreaUtils)
        importlib.reload(PVPlantUtils)
        importlib.reload(PVPlantManhole)
        importlib.reload(GraphProfile)

        importlib.reload(PVPlantTrace)
        importlib.reload(m_gui_edit)
        importlib.reload(profile_editor)
        importlib.reload(graphics)

        importlib.reload(MeshGetBoundary)
        importlib.reload(Triangulation)

        #importlib.reload(importDXF)
        importlib.reload(exportDXF)
        importlib.reload(layoutToExcel)
        importlib.reload(Conduit)

        importlib.reload(hydro)
        importlib.reload(iOSM)

        import Project.GenerateExternalDocument as GED
        importlib.reload(GED)

        #importlib.reload(GoogleMapDownloader)
        print("Reload modules...")


    def IsActive(self):
        if FreeCAD.ActiveDocument:
            return True
        else:
            return False


if FreeCAD.GuiUp:
    FreeCADGui.addCommand('Reload', _CommandReload())