importmanager.py
Go to the documentation of this file.
1 '''
2  Copyright (C) 1997-2018 JDERobot Developers Team
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU Library General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, see <http://www.gnu.org/licenses/>.
16 
17  Authors : Pushkal Katara (katarapushkal@gmail.com)
18 
19  '''
20 
21 from visualstates.configs.rosconfig import RosConfig
22 
23 class ImportManager():
24  """
25  Functionality:
26  Import PreBuild State into Current State
27  Verify Configurations
28  Verify Libraries
29  Verify Functions
30  Verify Variables
31 
32  :param rootState: Root Imported State
33  :param config: Configurations of Imported State
34  :param libraries: Libraries of Imported State
35  :param functions: Functions of Imported State
36  :param variables: Variables of Imported State
37 
38  Returns list of States which needs to be Imported
39  """
40 
41  def updateAuxiliaryData(self, file, klass):
42  """Wrapper upon all update functions"""
43  importedState = self.updateActiveState(file[0], klass.automataScene.stateIndex, klass.automataScene.transitionIndex, klass.activeState)
44  config = self.updateConfigs(file[1], klass.config)
45  libraries = self.updateLibraries(file[2], klass.libraries)
46  globalNamespace = self.updateNamespace(file[3], klass.globalNamespace)
47  return importedState, config, libraries, globalNamespace
48 
49  def updateNamespace(self, newNamespace, namespace):
50  newFunctions = newNamespace.getFunctions()
51  newVariables = newNamespace.getVariables()
52  if newFunctions and newVariables:
53  namespace.addFunctions(newFunctions)
54  namespace.addVariables(newVariables)
55  return namespace
56 
57  def updateLibraries(self, newLibraries, libraries):
58  """Updates existing libraries with imported libraries"""
59  for lib in newLibraries:
60  if lib not in libraries:
61  libraries.append(lib)
62  return libraries
63 
64  def updateConfigs(self, newConfig, config):
65  """Updates Existing Configurations with imported Configurations"""
66  if newConfig:
67  if config is None:
68  config = RosConfig()
69  config.updateROSConfig(newConfig)
70  return config
71 
72  def updateActiveState(self, importState, stateID, transitionID, activeState):
73  """Updates Parent State with States to be imported"""
74  importState = self.updateIDs(importState, stateID, transitionID)
75  for state in importState.getChildren():
76  activeState.addChild(state)
77  state.setParent(activeState)
78  updatedParentNamespace = self.updateNamespace(importState.getNamespace(), activeState.namespace)
79  activeState.setNamespace(updatedParentNamespace)
80  return importState
81 
82  def updateIDs(self, importState, stateID, transitionID):
83  """ Wrapper upon UpdateStateIDs """
84  self.updateStateIDs(importState, stateID)
85  self.updateTranIDs(importState, transitionID)
86  return importState
87 
88  def updateStateIDs(self, importState, stateID):
89  """ Assign New IDs to Imported State Data Recursively """
90  for child in importState.getChildren():
91  child.setID(stateID + child.getID())
92  self.updateStateIDs(child, stateID)
93 
94  def updateTranIDs(self, importState, transitionID):
95  for child in importState.getChildrenTransitions():
96  child.setID(transitionID + child.getID())
97 
def updateLibraries(self, newLibraries, libraries)
def updateNamespace(self, newNamespace, namespace)
def updateStateIDs(self, importState, stateID)
def updateTranIDs(self, importState, transitionID)
def updateActiveState(self, importState, stateID, transitionID, activeState)
def updateIDs(self, importState, stateID, transitionID)


visualstates
Author(s):
autogenerated on Thu Apr 1 2021 02:42:20