ia-dev / opensimQt

CPP GUI for OpenSim
Apache License 2.0
5 stars 6 forks source link

MS0401_T0201 Python: opensim Python CPP communication #26

Closed riteshsv closed 4 years ago

riteshsv commented 4 years ago

With reference to the below quote :

I think there is no need to have many helper functions. I think we need only two python functions: #24 ref: MS0401_T02

  • [x] Use Case 1 : Open an instance of already loaded model in the Navigator, from Python script, and modify / update model, sync it back to the model in Navigator (cpp model). python function getModelFromNavigator("modelName") call save cpp function to save the model (update model data and reload model in Navigator)
  • [x] Use Case 2: Create and new model in Python script and set its parameters. Save the model and load this model in Navigator. Close existing model if different, if same then reload. python function setModelFromPython(modelName) call save python function to save the model. if same model exists in Navigator then close and reload else load new model from python. eg: to write model to a file from python -> modelName.printToXML(modelNamePath)
  • [x] call cpp open/reload model
idhamari commented 4 years ago

@riteshsv how is your progress so far? are there any difficulties?

riteshsv commented 4 years ago

@idhamari I had to go out of town for some work. I will get started today and get over with it asap.

riteshsv commented 4 years ago

@idhamari I have implemented Use Case 1 and Use Case 2 as mentioned above.

Below is the example code to test the same:

#usage of loadModel function

m=vsSim.loadModel('/Users/ritesh/test2.osim')
m.getName()                                                                #print the name of model
'test2'

m.setName('test3')                                                             #change the name of model    
vsSim.updateModelToNavigator(m)                                     #update the changes to navigator

#example of create a new model and add to navigator
m2 = osim.Model()
m2.setName('createdModel')                                      #set the name of new model
m2.setInputFileName('/Users/ritesh/createdModel.osim')      #set the path of model file to be created
vsSim.setModelToNavigator(m2)                                   #add the new model to navigator

#example of get current active model from the navigator
m3 = vsSim.getCurrentModel()                                      # get the current active model
m3.getName()                                                              # prints the name of current active model
'createdModel'

m3.getInputFileName()                                                 #prints the file path of model
'/Users/ritesh/createdModel.osim'

#example of get a model from navigator by model name
m4 = vsSim.getModelFromNavigator('test3')                   #get test3 model from the navigator
m4.getName()                                                               #print name of the model got from navigator
'test3'

m4.setName('test5')                                                  #change the name of model
m4.getGravity()                                                         #get the gravity of model
<opensim.simbody.Vec3; proxy of <Swig Object of type 'SimTK::Vec< 3 > *' at 0x13c0bbf30> >

g = m4.getGravity()

vsSim.updateModelToNavigator(m4)                            #update the changed name to navigator

I have committed the code. Please let me know what time I can give a demo. In the mean time I will start working on other item.

idhamari commented 4 years ago

@riteshsv looks excellent :watermelon: , I will test it and provide feedback if needed

riteshsv commented 4 years ago

@idhamari I got a weird bug today morning and spend the whole day trying to resolve it. Its kind of weird, but sometimes it happens. Please allow me 2 more days.