Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add parameters to visual states tool. #1

Merged
merged 33 commits into from
Aug 29, 2019
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
de26bfe
Add core file for parameters
sudo-panda Jun 1, 2019
4f4ed20
Add parameters to visualstates
sudo-panda Jun 1, 2019
3a4cd96
Add dialog to add, edit and remove parameters
sudo-panda Jun 1, 2019
8dc6f0c
Enable saving of parameters
sudo-panda Jun 5, 2019
d5b8bdd
Enable opening of files with parameters
sudo-panda Jun 5, 2019
bbb00e9
Add a case to name validation of parameters
sudo-panda Jun 5, 2019
732aa11
Add cpp code generation with parameters
sudo-panda Jun 5, 2019
2213cb6
Add python code generation with parameters
sudo-panda Jun 5, 2019
88d5f74
Add initialization of global variables by taking input
sudo-panda Jun 9, 2019
c0deb28
Handle cases where value and description fields are empty
sudo-panda Jun 9, 2019
149f3bc
Stop searching for parameters in all files and only search in source …
sudo-panda Jun 9, 2019
fb5c98e
Enable importing of parameters
sudo-panda Jun 9, 2019
c48866e
Resolves issue in which editing parameters required change names
sudo-panda Jun 9, 2019
23e41e5
Merge branch 'master' into devel
sudo-panda Jun 10, 2019
27dfd4b
Moved parameters dialog to Local namespace dialog tab
sudo-panda Jun 20, 2019
1f31a7e
Prevent addition of parameters to Global Namespace"
sudo-panda Jun 20, 2019
47c0f1f
Save parameters inside namespace element
sudo-panda Jun 20, 2019
95d05c7
Open files that have parameters in namespace elements
sudo-panda Jun 20, 2019
fe0a687
Add import of parameters in local namespace
sudo-panda Jun 20, 2019
a7c665d
Add parameters to code during generation
sudo-panda Jun 20, 2019
4041e8f
Solve generation of code not working
sudo-panda Jun 23, 2019
65f7fc1
Replace try catch with if else
sudo-panda Jul 5, 2019
1e331c9
Add dialog to display imported parameters
sudo-panda Jul 7, 2019
e934de9
Change desc to value
sudo-panda Jul 8, 2019
aba93b9
Add selective import of states
sudo-panda Jul 11, 2019
5cd07e7
Add toggle view buttons
sudo-panda Jul 11, 2019
cc5a48f
Change absolute import to relative import
sudo-panda Jul 14, 2019
b54f87c
Add better display of parameters
sudo-panda Jul 15, 2019
741c73e
fix qgroupbox title spacing at the top
okanasik Jul 18, 2019
861224a
Copy list before pop to resolve empty list error
sudo-panda Jul 18, 2019
3eef8dc
Use dict in place of list to store and access parameter Namespace Dialog
sudo-panda Jul 26, 2019
d585894
Modify code to reselect sub states with parent
sudo-panda Aug 11, 2019
1d44a54
Remove .idea files
sudo-panda Aug 26, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/visualstates.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 28 additions & 1 deletion src/visualstates/core/namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@
Authors : Pushkal Katara ([email protected])

'''
from visualstates.core.parameter import Parameter

class Namespace:
def __init__(self, functions, variables):
def __init__(self, functions, variables, params):
self.functions = functions
self.variables = variables
self.params = params

def createNode(self, doc, globalNamespace=False):
if globalNamespace:
Expand All @@ -33,6 +36,10 @@ def createNode(self, doc, globalNamespace=False):
variablesElement = doc.createElement('variables')
variablesElement.appendChild(doc.createTextNode(self.variables))
namespaceElement.appendChild(variablesElement)
paramsElement = doc.createElement('parameters')
for param in self.params:
paramsElement.appendChild(param.createDocFromParam(doc))
namespaceElement.appendChild(paramsElement)
return namespaceElement

def parseElement(self, elementName, parentElement):
Expand All @@ -42,9 +49,20 @@ def parseElement(self, elementName, parentElement):
return elements[0].childNodes[0].nodeValue
return ''

def parseParamElement(self, parentElement):
params = []
paramsElement = parentElement.getElementsByTagName('parameters')
if len(paramsElement) > 0:
for paramElement in paramsElement[0].getElementsByTagName('param'):
param = Parameter()
param.parseElement(paramElement)
params.append(param)
return params

def parse(self, namespaceElement):
self.functions = self.parseElement('functions', namespaceElement)
self.variables = self.parseElement('variables', namespaceElement)
self.params = self.parseParamElement(namespaceElement)

def getVariables(self):
return self.variables
Expand Down Expand Up @@ -80,3 +98,12 @@ def addFunctions(self, functions):

def setFunctions(self, functions):
self.functions = functions

def addParams(self, params):
self.params += params

def getParams(self):
return self.params

def setParams(self, params):
self.params = params
88 changes: 88 additions & 0 deletions src/visualstates/core/parameter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
'''
Copyright (C) 1997-2019 JDERobot Developers Team

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Library General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, see <http://www.gnu.org/licenses/>.

Authors : Baidyanath Kundu ([email protected])

'''

class Parameter:
def __init__(self, name='', type='', value='', desc=''):
self.name = name
self.type = type
self.value = value
self.desc = desc

def setName(self, name):
self.name = name

def setType(self, type):
self.type = type

def setValue(self, value):
self.value = value

def setDesc(self, desc):
self.desc = desc

def createDocFromParam(self, doc):
paramElement = doc.createElement('param')
paramElement.setAttribute('type', self.type)
paramElement.setAttribute('name', self.name)

valueElement = doc.createElement('value')
valueElement.appendChild(doc.createTextNode(self.value))
paramElement.appendChild(valueElement)
descElement = doc.createElement('description')
descElement.appendChild(doc.createTextNode(self.desc))
paramElement.appendChild(descElement)

return paramElement

def parseElement(self, element):
for (name, value) in element.attributes.items():
if name == 'name':
self.name = str(value)
elif name == 'type':
self.type = str(value)

if len(element.getElementsByTagName('value')[0].childNodes) > 0:
self.value = str(element.getElementsByTagName('value')[0].childNodes[0].nodeValue)
else:
self.value = ''
if len(element.getElementsByTagName('description')[0].childNodes) > 0:
self.desc = str(element.getElementsByTagName('description')[0].childNodes[0].nodeValue)
else:
self.desc = ''

def isTypeEqualValue(type, value):
if type == 'Boolean' and not (value == 'True' or value == 'False' or value == 'true' or value == 'false'):
return False
elif type == 'Integer' and not value.isdigit():
sudo-panda marked this conversation as resolved.
Show resolved Hide resolved
return False
elif type == 'Float' and not (value.replace('.', '', 1).isdigit()):
sudo-panda marked this conversation as resolved.
Show resolved Hide resolved
return False
elif type == 'Character' and not len(value) == 1:
sudo-panda marked this conversation as resolved.
Show resolved Hide resolved
return False
else:
return True

def isParamName(name):
if name == '':
return False
elif name.replace('_', '').isalnum() and name[0].isalpha():
return True
else:
return False
2 changes: 1 addition & 1 deletion src/visualstates/core/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def parse(self, stateElement):
self.code = self.parseElement('code', stateElement)
self.timeStepDuration = int((self.parseElement('timestep', stateElement)))

namespace = Namespace('', '')
namespace = Namespace('', '', [])
namespace.parse(stateElement.getElementsByTagName('namespace')[0])
self.namespace = namespace
# recursive child state parsing
Expand Down
34 changes: 20 additions & 14 deletions src/visualstates/generators/cpprosgenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,7 @@ def generate(self, projectPath, projectName):
self.generateStateClasses(stringList)
self.generateTransitionClasses(stringList)
stringList.append('#endif')
sourceCode = ''.join(stringList)
fp = open(projectPath + os.sep + 'src' + os.sep + projectName + '.h', 'w')
fp.write(sourceCode)
fp.close()
headerSourceCode = ''.join(stringList)

stringList = []
self.generateHeadersForCpp(stringList, projectName)
Expand All @@ -56,28 +53,37 @@ def generate(self, projectPath, projectName):
self.generateMain(stringList, projectName)
sourceCode = ''.join(stringList)

stringList = []
self.generateRunTimeGui(stringList)
guiSourceCode = ''.join(stringList)

stringList = []
self.generateCmake(stringList, projectName, self.config)
cmakeString = ''.join(stringList)

xmlDoc = self.generatePackageXml(self.config, projectName)
xmlStr = xmlDoc.toprettyxml(indent=' ')

# writing to files
fp = open(projectPath + os.sep + 'src' + os.sep + projectName + '.h', 'w')
fp.write(headerSourceCode)
fp.close()


fp = open(projectPath + os.sep + 'src' + os.sep + projectName + '.cpp', 'w')
fp.write(sourceCode)
fp.close()

stringList = []
self.generateRunTimeGui(stringList)
sourceCode = ''.join(stringList)
fp = open(projectPath + os.sep + projectName + '_runtime.py', 'w')
fp.write(sourceCode)
fp.write(guiSourceCode)
fp.close()
# make runtime gui python file executable
os.chmod(projectPath + os.sep + projectName + '_runtime.py', stat.S_IEXEC | stat.S_IXOTH | stat.S_IWRITE | stat.S_IREAD)

stringList = []
self.generateCmake(stringList, projectName, self.config)
cmakeString = ''.join(stringList)
fp = open(projectPath + os.sep + 'CMakeLists.txt', 'w')
fp.write(cmakeString)
fp.close()

xmlDoc = self.generatePackageXml(self.config, projectName)
xmlStr = xmlDoc.toprettyxml(indent=' ')
with open(projectPath + os.sep + 'package.xml', 'w') as f:
f.write(xmlStr)

Expand Down Expand Up @@ -177,7 +183,7 @@ def generateStateNamespaceClass(self, classStr):
classStr.append('class Namespace' + str(state.id) + ' {\n')
classStr.append('public:\n')
classStr.append('\tGlobalNamespace* globalNamespace;\n')
types, varNames, initialValues = CPPParser.parseVariables(state.getNamespace().variables)
types, varNames, initialValues = CPPParser.parseVariables(state.getNamespace().variables, state.getNamespace().params)
for i in range(len(types)):
classStr.append(types[i] + ' ' + varNames[i] + ';\n')
classStr.append('\n')
Expand Down
Loading