class CivilToolsSettings:
    def GetResources(self):
    def Activated(self): class CivilEarthquakeFactor:
    def GetResources(self):
    def Activated(self):
    def IsActive(self): class CivilIrregularityOfMass:
    def GetResources(self):
    def Activated(self):
    def IsActive(self): class CivilExplodLoadPatterns:
    def GetResources(self):
    def Activated(self):
    def IsActive(self): class CivilStoryStiffness:
    def GetResources(self):
    def Activated(self):
    def IsActive(self): class CivilGetWeakness:
    def GetResources(self):
    def Activated(self):
    def IsActive(self): class CivilShowTorsion:
    def GetResources(self):
    def Activated(self):
    def IsActive(self): class CivilCreatePeriodFile:
    def GetResources(self):
    def Activated(self):
    def IsActive(self): class CivilAutomaticDrift:
    def GetResources(self):
    def Activated(self):
    def IsActive(self): class CivilBeamJ:
    def GetResources(self):
    def Activated(self):
    def IsActive(self): class CivilStoryForces:
    def GetResources(self):
    def Activated(self):
    def IsActive(self): class CivilShowStoryStiffness:
    def GetResources(self):
    def Activated(self):
    def IsActive(self): class CivilShowWeakness:
    def GetResources(self):
    def Activated(self):
    def IsActive(self): class CivilShowAj:
    def GetResources(self):
    def Activated(self):
    def IsActive(self):
def get_mdiarea(): class CivilScaleResponseSpec:
    def GetResources(self):
    def Activated(self):
    def IsActive(self): class CivilHighPressureColumns:
    def GetResources(self):
    def Activated(self):
    def IsActive(self): class CivilAssignFrameSections:
    def GetResources(self):
    def Activated(self):
    def IsActive(self): class CivilOffsetBeam:
    def GetResources(self):
    def Activated(self):
    def IsActive(self): class CivilWallLoadOnFrames:
    def GetResources(self):
    def Activated(self):
    def IsActive(self): class CivilConnectBeam:
    def GetResources(self):
    def Activated(self):
    def IsActive(self): class CivilDistance:
    def GetResources(self):
    def Activated(self):
    def IsActive(self): class CivilSectionCuts:
    def GetResources(self):
    def Activated(self):
    def IsActive(self): class CivilDeleteBackups:
    def GetResources(self):
    def Activated(self):
    def IsActive(self): class CivilRestoreBackups:
    def GetResources(self):
    def Activated(self):
    def IsActive(self): class CivilToolsHelp:
    def GetResources(self):
    def Activated(self):
    def IsActive(self): def allowed_to_continue(
                        filename,
                        gist_url,
                        dir_name,
                        n=5,
                        ):
def show_warning_about_number_of_use(check):
    def __init__(self, parent=None):
def submit():
    def GetResources(self):
    def Activated(self):
    def IsActive(self):
class SerialForm(QtWidgets.QWidget):
class CivilToolsRegister: class CivilTools100_30Columns:
    def GetResources(self):
    def Activated(self):
    def IsActive(self): class CivilToolsImportModel:
    def GetResources(self):
    def Activated(self):
    def IsActive(self): class CivilToolsCreateLoadCombinations:
    def GetResources(self):
    def Activated(self):
    def IsActive(self): class CivilGetWeaknessTorsion:
    def GetResources(self):
    def Activated(self):
    def IsActive(self): class CivilToolsDiscretize:
    def parseSel(self, selectionObject):
    def Activated(self):
    def IsActive(self):
    def GetResources(self): UPDATEINTERVAL = 2000 # number of milliseconds between civiltools Views window update
class CivilToolsViews:
    def GetResources(self):
    def Activated(self):
    def update(self,retrigger=True):
    def select(self,item,column=None):
    def view_objects(self):
    def toggle(self):
    def isolate(self):
def findWidget(mw=None):
def show_object(obj, show : bool):
def iter_items(root, column=0):
    def recurse(parent, column=0):
def show(item,column=None):
import os
import FreeCADGui as Gui
        import webbrowser
from pathlib import Path
from PySide2 import QtCore
from PySide2.QtWidgets import QMessageBox
from gui_civiltools import (
    gui_civiltools_settings,
    gui_earthquake_factor,
    gui_irregurality_of_mass,
    gui_explod_load_patterns,
    gui_story_stiffness,
    gui_get_weakness,
    gui_show_torsion,
    gui_create_period_file,
    gui_automatic_drift,
    gui_modify_torsion_stiffness,
    gui_show_story_forces,
    gui_show_story_stiffness,
    gui_show_weakness,
    gui_show_aj,
    gui_scale_response_spec,
    gui_high_pressure_columns,
    gui_assign_frame_sections,
    gui_offset_beams,
    gui_wall_load_on_frames,
    gui_connect_beam,
    gui_distance_between_two_points,
    gui_create_section_cuts,
    gui_delete_backups,
    gui_restore_backups,
    gui_help,
    gui_check_legal,
    gui_100_30_columns,
    gui_import_model,
    )
from gui_civiltools.define import (
    gui_create_load_combinations, 
)
from gui_civiltools.control import (
    gui_get_weakness_torsion, 
)
from gui_civiltools.tools import (
    gui_discretize, 
)
from freecad_py import civiltools_views
    from PySide2.QtWidgets import QFileDialog
    from functions import check_legal
# import FreeCAD
# import DraftTools
# import civiltoolswelcome





def QT_TRANSLATE_NOOP(ctx, txt): return txt



class CivilHelp:

    def GetResources(self):
        MenuText = QtCore.QT_TRANSLATE_NOOP(
            "Civil_help",
            "Help")
        ToolTip = QtCore.QT_TRANSLATE_NOOP(
            "Civil_help",
            "Help")
        path = str(
                   Path(__file__).parent.absolute() / "Resources" / "icons" / "help.svg"
                   )
        return {'Pixmap': path,
                'MenuText': MenuText,
                'ToolTip': ToolTip}
    def Activated(self):
        path = str(
                   Path(__file__).parent.absolute() / "help" / "help.pdf"
                   )
        webbrowser.open_new(path)

    def IsActive(self):
        return True


def get_save_filename(ext):
    filters = f"{ext[1:]} (*{ext})"
    filename, _ = QFileDialog.getSaveFileName(None, 'select file',
                                              None, filters)
    if not filename:
        return
    if not ext in filename:
        filename += ext
    return filename

def allowed_to_continue(
                        filename,
                        gist_url,
                        dir_name,
                        n = 2,
                        ):
    check = check_legal.CheckLegalUse(
                                filename,
                                gist_url,
                                dir_name,
                                n = n,
    )
    allow, text = check.allowed_to_continue()
    if allow and not text:
        return True, check
    else:
        if text in ('INTERNET', 'SERIAL'):
            ui = SerialForm()
            ui.form.serial.setText(check.serial)
            Gui.Control.showDialog(ui)
            # if ui.setupUi():
            #     Gui.Control.closeDialog(ui)
            return False, check
        elif text == 'REGISTERED':
            msg = "Congrajulation! You are now registered, enjoy using this features!"
            QMessageBox.information(None, 'Registered', str(msg))
            return True, check
    return False, check

def show_warning_about_number_of_use(check):
    check.add_using_feature()
    _, no_of_use = check.get_registered_numbers()
    n = check.n - no_of_use
    if n > 0:
        msg = f"You can use this feature {n} more times!\n then you must register the software."
        QMessageBox.warning(None, 'Not registered!', str(msg))

class SerialForm:
    def __init__(self):
        serial_ui = str(
            Path(__file__).parent.absolute() / 'Resources' / 'ui' / 'serial.ui'
            )
        self.form = Gui.PySideUic.loadUi(serial_ui)




# Gui.addCommand('Civil_help', CivilHelp())
Gui.addCommand('civiltools_settings', gui_civiltools_settings.CivilToolsSettings())
Gui.addCommand('civil_earthquake_factor', gui_earthquake_factor.CivilEarthquakeFactor())
Gui.addCommand('civil_irregurality_of_mass', gui_irregurality_of_mass.CivilIrregularityOfMass())
Gui.addCommand('civil_explod_load_patterns', gui_explod_load_patterns.CivilExplodLoadPatterns())
Gui.addCommand('civil_story_stiffness', gui_story_stiffness.CivilStoryStiffness())
Gui.addCommand('civil_get_weakness', gui_get_weakness.CivilGetWeakness())
Gui.addCommand('civil_get_weakness_torsion', gui_get_weakness_torsion.CivilGetWeaknessTorsion())
Gui.addCommand('civil_show_torsion', gui_show_torsion.CivilShowTorsion())
Gui.addCommand('civil_create_period_file', gui_create_period_file.CivilCreatePeriodFile())
Gui.addCommand('civil_automatic_drift', gui_automatic_drift.CivilAutomaticDrift())
Gui.addCommand('civil_modify_torsion_stiffness', gui_modify_torsion_stiffness.CivilBeamJ())
Gui.addCommand('civil_show_story_forces', gui_show_story_forces.CivilStoryForces())
Gui.addCommand('civil_show_story_stiffness', gui_show_story_stiffness.CivilShowStoryStiffness())
Gui.addCommand('civil_show_weakness', gui_show_weakness.CivilShowWeakness())
Gui.addCommand('civil_show_aj', gui_show_aj.CivilShowAj())
Gui.addCommand('civil_scale_response_spec', gui_scale_response_spec.CivilScaleResponseSpec())
Gui.addCommand('civil_high_pressure_columns', gui_high_pressure_columns.CivilHighPressureColumns())
Gui.addCommand('civil_assign_frame_sections', gui_assign_frame_sections.CivilAssignFrameSections())
Gui.addCommand('civil_offset_beams', gui_offset_beams.CivilOffsetBeam())

Gui.addCommand('civil_wall_load_on_frames', gui_wall_load_on_frames.CivilWallLoadOnFrames())