Différences
Ci-dessous, les différences entre deux révisions de la page.
api [2017/03/06 17:19] emmanuel [How to distribute an addon] |
api [2021/03/20 21:14] |
||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
- | ===== API description for the conception of addons ===== | ||
- | |||
- | |||
- | ==== Presentation ==== | ||
- | |||
- | Arbre-Analyste comes with a rich API to design advanced addons. | ||
- | |||
- | You can see below an example of addon. | ||
- | |||
- | <code python># Open an Open-PSA file | ||
- | AA.OpenOPSA(" | ||
- | # Find the gate with name " | ||
- | element = AA.Elements.GetGateByName(" | ||
- | # element is the gate named " | ||
- | results = element.Compute(8760) | ||
- | # We show the probability at 8760h | ||
- | AA.Windows.MsgBox(" | ||
- | "The probability of ' | ||
- | </ | ||
- | |||
- | Addons have to be developped with the Python language version 3. You can get its documentation at this address: https:// | ||
- | |||
- | ==== Anatomy of an addon ==== | ||
- | |||
- | The anatomy of an addon have to respect the following rules. | ||
- | - All parts of the addon have to be in the same directory; | ||
- | - The directory of the addon have to be in the " | ||
- | - main.py have to be the entry script of your addon. | ||
- | |||
- | For example, the anatomy of the simplest addon is : | ||
- | * C:\Program files\Arbre-Analyste\externe\modules\**My new addon\main.py** | ||
- | |||
- | In addition, in the " | ||
- | * %%__plugin_version%% //Set the version of the addon// | ||
- | * %%__plugin_author%% //Set informations about authors// | ||
- | * %%__plugin_description%% //Set a description// | ||
- | * %%__plugin_platform%% //Set the platform compatibility (win32, linux64, all)// | ||
- | * %%__plugin_arbre-analyste_minimum%% //Set the minimal version of Arbre-Analyste// | ||
- | |||
- | Example: | ||
- | |||
- | <code python> | ||
- | # -*- coding: utf8 -*- | ||
- | |||
- | """ | ||
- | __plugin_version 1.0 | ||
- | __plugin_author M. DUPOND marc.dupond at webmail.com | ||
- | __plugin_description The "Hello world" script | ||
- | __plugin_platform all | ||
- | __plugin_arbre-analyste_minimum 2.0.0 | ||
- | """ | ||
- | |||
- | AA.Windows.MsgBox(" | ||
- | </ | ||
- | |||
- | ==== How to distribute an addon ==== | ||
- | |||
- | To distribute an addon, you have to create a *.zpk file. A *.zpk file is just a zip file which contains all addon directories. | ||
- | It's realy important to zip the addon directory and not the file in the directory. | ||
- | Rename the zip extension to zpk extension, that's all. | ||
- | |||
- | In addition, you can zip many addons in the same zpk file. | ||
- | |||
- | |||
- | ===== API documentation ===== | ||
- | |||
- | ==== class AA ==== | ||
- | |||
- | **AA** class is the entry point of the API. This class contains all functions of the API. | ||
- | |||
- | * bool **AA.OpenProject**( __file__ ) //Open an Arbre-Analyste project from file// | ||
- | * bool **AA.SaveProject**( __file__ ) //Save an Arbre-Analyste project to file// | ||
- | * bool **AA.OpenOPSA**( __file__ ) //Open an Open-PSA STRICT project from file// | ||
- | * bool **AA.SaveOPSA**( __file__ ) //Save an Open-PSA STRICT project to file// | ||
- | * bool **AA.New()** //Create an empty project// | ||
- | * string **AA.GetLang()** //Get the user's language// | ||
- | * list of int **AA.GetVersion()** //Get the version of Arbre-Analyste// | ||
- | * class **AA.Compute** //Class to create and compute calculations// | ||
- | * class **AA.Elements** //Class to create and edit fault tree's elements (gates, basic events etc...)// | ||
- | * class **AA.Pages** //Class to create and edit pages// | ||
- | * class **AA.Parameters** //Class to create and edit named parameters// | ||
- | * class **AA.Windows** //Class to create and edit windows and dialogs// | ||
- | ==== class AA.Compute ==== | ||
- | |||
- | **AA.Compute** class contains all functions to perform calculations. | ||
- | |||
- | * compute object **AA.Compute.Create** ( __name__ | ||
- | * compute object **AA.Compute.GetByName** ( __name__ | ||
- | * list of compute object **AA.Compute.GetAll** () // Get a list which contains all programmed calculations.// | ||
- | * dictionnary **AA.Compute.Compute** ( element object __gate__ | ||
- | * **Q** : Unavailability | ||
- | * **F** : Unreliability | ||
- | * **L** : Conditional Failure Intensity | ||
- | * **Lavg** | ||
- | * **W** : Unconditional Failure Intensity | ||
- | * **T** : Time | ||
- | * **MCS** | ||
- | * **IMPORTANCE** | ||
- | * **PROBABILITY** | ||
- | * **FAILURE** | ||
- | Certain functions of AA.Compute class return a compute object. The compute object is defined as below. | ||
- | |||
- | * bool or string **Name** ( __name__ | ||
- | * bool or list **Time** ( __time__ | ||
- | * bool or element object **Gate** ( element object __gate__ | ||
- | * bool **HTML** ( string file ) //Compute and create a HTML report.// | ||
- | * dictionnary **Compute** () // Compute and return a dictionary which contains all results as it is described above.// | ||
- | * bool **Delete** () //Delete the programmed calculation.// | ||
- | |||
- | Example: | ||
- | |||
- | <code python># Get a gate | ||
- | myTopGate = AA.Elements.GetGateByName(" | ||
- | # Create a new programmed calculation | ||
- | myCompute = AA.Compute.Create(" | ||
- | # Compute | ||
- | myResults = myCompute.Compute() | ||
- | # Display the unavailability | ||
- | AA.Windows.MsgBox(" | ||
- | # Remove the programmed calculation | ||
- | myCompute.Delete() | ||
- | </ | ||
- | |||
- | ==== class AA.Elements ==== | ||
- | |||
- | **AA.Elements** class contains all functions to create, edit and delete elements (gate, transfert, basic event, house event) in fault tree. | ||
- | |||
- | * element object **AA.Elements.Create**( __type__ = " | ||
- | * list element object **AA.Elements.GetByName**( __name__ ) //Get a list of all elements found by their name.// | ||
- | * element object **AA.Elements.GetGateByName**( __name__ ) //Get the only gate found bye its name// | ||
- | * list element object **AA.Elements.GetBasicByName**( __name__ ) //Get a list of all basic events found by their name.// | ||
- | * list element object **AA.Elements.GetTransfertByName**( __name__ ) //Get a list of all transfers found by their name.// | ||
- | * lit element object **AA.Elements.GetHouseByName**( __name__ ) //Get a list of all house events found by their name.// | ||
- | * element object **AA.Elements.GetById**( __id__ ) //Get an element by it id.// | ||
- | * list element object **AA.Elements.GetAll**() //Get a list of all elements. // | ||
- | |||
- | Certain functions of **AA.Elements** class return an element object. The element object is defined as below. | ||
- | |||
- | * integer **GetId**() //Return the id of the element.// | ||
- | * string **GetType**() // Return the type of the element. Can be " | ||
- | * bool or string **Name**( __name__ = None ) //Change the name if name is specified else return the name of the element.// | ||
- | * bool or string **Description**( __text__ = None ) //Change the description if text is specified else return the description of the element.// | ||
- | * bool or list **Position**( __coords__ = None ) //Change the position if the list coords is specified else return the position of the element. The list coords is constituted by a list of x and y.// | ||
- | * bool or element object **Parent**( element object __parent__ = "" | ||
- | * list element object **GetChildren**() //Return a list which contains all children of the gate.// | ||
- | * bool **Organize**( __axis__ = " | ||
- | * bool or string **Color**( __color__ = None ) //If color is specified then change the color of the element else return the color. color must be an HTML code like #FFFFFF, #FF0000 etc...// | ||
- | * bool **IsGate**() //Return True if the element is a gate else False.// | ||
- | * bool **IsBasic**() //Return True if the element is a basic event else False.// | ||
- | * bool **IsHouse**() //Return True if the element is a house event else False.// | ||
- | * bool **IsTransfert**() //Return True if the element is a transfert else False.// | ||
- | * parameter object **GetParameter**( __type__) //Return the parameter of a certain type.// | ||
- | * dictionary **Compute**( __time__ = 1, __zero__ = 0, __step__ = None, __maxOrder__ = 100, __minProbability__ = 0) // Compute the current gate and return a dictionary which contains all results as it is described for AA.Compute.Compute().// | ||
- | * bool **Logic**( __logic__ ) //Change the logic of the gate. logic must be " | ||
- | * bool **State**( __state__ = None ) //Return the state of the house event if state is not specified else change the state. state must be True or False.// | ||
- | * bool or list **Law**( __law__ = None, * parameters object )//If law is specified, change the law of the basic event. law must be " | ||
- | * bool **Delete**() //Delete the current element.// | ||
- | |||
- | Example: | ||
- | |||
- | <code python> | ||
- | # Creation of the top gate | ||
- | myTopGate = AA.Elements.Create(" | ||
- | # Creation of the basic event parameter | ||
- | myParameter = AA.Parameters.Create(" | ||
- | # Creation of 10 basic events | ||
- | for num in range(10): | ||
- | # Creation of the basic event | ||
- | be = AA.Elements.Create(" | ||
- | # Modification of its gate parent | ||
- | be.Parent(myTopGate) | ||
- | # Configuration of its probability law | ||
- | be.Law(" | ||
- | # Organization of the fault tree | ||
- | myTopGate.Organize() | ||
- | # Computation of the top gate | ||
- | results = myTopGate.Compute(1) | ||
- | # Print the Q and F results | ||
- | AA.Windows.MsgBox(" | ||
- | </ | ||
- | ==== class AA.Pages ==== | ||
- | |||
- | **AA.Pages** class contains all functions to create, edit and delete pages. | ||
- | |||
- | * page object **AA.Pages.Create**( __name__ = None ) //Create a new page and return it.// | ||
- | * page object **AA.Pages.GetByName**( __name__ ) //Get a page by its name.// | ||
- | * page object **AA.Pages.GetById**( __id__ ) //Get a page by its id.// | ||
- | * page object **AA.Pages.GetActive**() //Get the active page.// | ||
- | * list page object **AA.Pages.GetAll**() //Return a list which contains all pages.// | ||
- | * bool **AA.Pages.Draw**() //Draw the page.// | ||
- | |||
- | Certain functions of **AA.Pages** class return a page object. The page object is defined as below. | ||
- | |||
- | * integer **GetId**() //Return the id of the element.// | ||
- | * bool or string **Name**( __name__ = None ) //Change the name if name is specified else return the name.// | ||
- | * bool **Activate**() //Change the active page of the project.// | ||
- | * bool **SVG**( file ) //Export the page to a SVG file.// | ||
- | * bool **Delete**() //Delete the page and all it contains.// | ||
- | ==== class AA.Parameters ==== | ||
- | |||
- | **AA.Parameters** class contains all functions to create, edit and delete named parameters (lambda, probability, | ||
- | |||
- | * parameter object **AA.Parameters.Create**( __name__ , __type__ = " | ||
- | * list parameter object **AA.Parameters.GetByName**( __name__ , __type__ = None ) | ||
- | * parameter object **AA.Parameters.GetById**( __id__ ) | ||
- | * list parameter object **AA.Elements.GetAll**( __type__ = None ) | ||
- | |||
- | Certain functions of **AA.Parameters** class return a parameter object. The parameter object is defined as below. | ||
- | |||
- | * integer **GetId**() //Return the id of the parameter.// | ||
- | * string **GetType**() //Return the type of the parameter. __type__ can be " | ||
- | * bool or string **Name**( __name__ = None ) //Change the name if name is specified else return the name of the parameter.// | ||
- | * bool or float **Value**( __value__ = None ) //Change the value if value is specified else return the value of the parameter.// | ||
- | * bool or string **Description**( __text__ = None ) //Change the description if text is specified else return the description of the parameter.// | ||
- | * bool **IsUsed**() //Return True is the parameter is used by a basic event.// | ||
- | * bool **Delete**() //Delete the parameter if it is unused.// | ||
- | |||
- | The example bellow create a window which contains all parameters informations to be modified by the user and finally save the user modifications. | ||
- | |||
- | <code python> | ||
- | # Creation of the function which gets data from the text box and saves modifications | ||
- | def save(): | ||
- | global myWindow | ||
- | # Save modifications for all parameters | ||
- | for line in myWindow.Get().splitlines(): | ||
- | data = line.split(" | ||
- | try: | ||
- | p = AA.Parameters.GetById(int(data[0])) | ||
- | if p: | ||
- | p.Name(data[3]) | ||
- | p.Value(float(data[7])) | ||
- | except: | ||
- | pass | ||
- | # Show confirmation | ||
- | AA.Windows.MsgBox(" | ||
- | # Quit | ||
- | myWindow.Close() | ||
- | | ||
- | |||
- | # Creation of a text box | ||
- | myWindow = AA.Windows.TextBox(" | ||
- | "You can edit parameters bellow and then click on save button. However, never change the Id value.", | ||
- | " | ||
- | " | ||
- | # We print parameter informations | ||
- | for p in AA.Parameters.GetAll(): | ||
- | myWindow.Add(" | ||
- | </ | ||
- | ==== class AA.Windows ==== | ||
- | |||
- | **AA.Windows** class contains all functions to create, edit and delete windows. | ||
- | |||
- | * window object **AA.Windows.Create** ( __title__ | ||
- | * string **AA.Windows.MsgBox** ( __title__ | ||
- | * string **AA.Windows.InputBox** ( __title__ | ||
- | * window object **AA.Windows.TextBox** ( __ title__ , __ text__ , __ default__ = "", | ||
- | * string **AA.Windows.AskOpenFileBox( __title__ | ||
- | * string **AA.Windows.AskSaveFileBox( __title__ | ||
- | |||
- | Certain functions of **AA.Windows** class return a window object. The window object is defined as bellow. | ||
- | * bool **Show**() //Show the window.// | ||
- | * bool **Hide**() //Hide the window.// | ||
- | * bool **Close**() //Destroy the window.// | ||
- | |||
- | To create advanced windows, you can go at this address [[http:// | ||