Commit 98cf4921 authored by Olivier Lantsoght's avatar Olivier Lantsoght
Browse files

[MBsysPy][BugFix] Asking for unset string option (ptr at NULL address) does not crash anymore.

parent 5f2aa527
......@@ -9,7 +9,6 @@ class has the functions required to manipulate the direct dynamic module. This
includes setting the options, running an(or multiple) analysis and freeing the
memory.
"""
# MBsysC version: 1.13.0
# Author: Robotran Team
# (c) Universite catholique de Louvain, 2019
......@@ -19,6 +18,7 @@ import ctypes
import numpy as np
# importing MbsysPy functions
from ..mbs_utilities import str_from_c_pointer
from ..mbs_utilities import bytes_to_str
from ..mbs_utilities import str_to_bytes
from ..mbs_utilities import mbs_warning
......@@ -733,15 +733,17 @@ class MbsDirdyn(object):
elif key == "save2file":
options.append(self.mbs_dirdyn_ptr.contents.options.contents.save2file)
elif key == "resfilename":
ptr = self.mbs_dirdyn_ptr.contents.options.contents.resfilename
if ptr is not None:
options.append(bytes_to_str(ctypes.string_at(self.mbs_dirdyn_ptr.contents.options.contents.resfilename)))
else:
options.append("dirdyn")
address = self.mbs_dirdyn_ptr.contents.options.contents.resfilename
defaut = "dirdyn"
options.append(str_from_c_pointer(address, defaut))
elif key == "respath":
options.append(bytes_to_str(ctypes.string_at(self.mbs_dirdyn_ptr.contents.options.contents.respath)))
address = self.mbs_dirdyn_ptr.contents.options.contents.respath
defaut = os.path.abspath(os.path.join(self.mbs.project_path, 'resultsR'))
options.append(str_from_c_pointer(address, defaut))
elif key == "animpath":
options.append(bytes_to_str(ctypes.string_at(self.mbs_dirdyn_ptr.contents.options.contents.animpath)))
address = self.mbs_dirdyn_ptr.contents.options.contents.animpath
defaut = os.path.abspath(os.path.join(self.mbs.project_path, 'animationR'))
options.append(str_from_c_pointer(address, defaut))
elif key == "save_anim":
options.append(self.mbs_dirdyn_ptr.contents.options.contents.save_anim)
elif key == "save_visu":
......
......@@ -18,6 +18,7 @@ import ctypes
import numpy as np
# importing MbsysPy functions
from ..mbs_utilities import str_from_c_pointer
from ..mbs_utilities import bytes_to_str
from ..mbs_utilities import str_to_bytes
from ..mbs_utilities import mbs_msg
......@@ -801,11 +802,17 @@ class MbsEquil(object):
elif key == "lpk_lintol":
options.append(self.mbs_equil_ptr.contents.options.contents.lpk_lintol)
elif key == "resfilename":
options.append(bytes_to_str(ctypes.string_at(self.mbs_equil_ptr.contents.options.contents.resfilename)))
address = self.mbs_equil_ptr.contents.options.contents.resfilename
defaut = 'equil'
options.append(str_from_c_pointer(address, defaut))
elif key == "respath":
options.append(bytes_to_str(ctypes.string_at(self.mbs_equil_ptr.contents.options.contents.respath)))
address = self.mbs_equil_ptr.contents.options.contents.respath
defaut = os.path.abspath(os.path.join(self.mbs.project_path, 'resultsR'))
options.append(str_from_c_pointer(address, defaut))
elif key == "animpath":
options.append(bytes_to_str(ctypes.string_at(self.mbs_equil_ptr.contents.options.contents.animpath)))
address = self.mbs_equil_ptr.contents.options.contents.animpath
defaut = os.path.abspath(os.path.join(self.mbs.project_path, 'animationR'))
options.append(str_from_c_pointer(address, defaut))
elif key == "mode":
options.append(self.mbs_equil_ptr.contents.options.contents.mode)
elif key == "relax":
......
......@@ -19,6 +19,7 @@ import ctypes
import numpy as np
# importing MbsysPy functions
from ..mbs_utilities import str_from_c_pointer
from ..mbs_utilities import bytes_to_str
from ..mbs_utilities import str_to_bytes
from ..mbs_utilities import mbs_msg
......@@ -499,11 +500,17 @@ class MbsInvdyn(object):
elif self.mbs_invdyn_ptr.contents.options.contents.motion == 2:
options.append("trajectory")
elif key == "trajectoryqname":
options.append(bytes_to_str(ctypes.string_at(self.mbs_invdyn_ptr.contents.options.contents.trajectoryqname)))
address = self.mbs_invdyn_ptr.contents.options.contents.trajectoryqname
defaut = None
options.append(str_from_c_pointer(address, defaut))
elif key == "trajectoryqdname":
options.append(bytes_to_str(ctypes.string_at(self.mbs_invdyn_ptr.contents.options.contents.trajectoryqdname)))
address = self.mbs_invdyn_ptr.contents.options.contents.trajectoryqdname
defaut = None
options.append(str_from_c_pointer(address, defaut))
elif key == "trajectoryqddname":
options.append(bytes_to_str(ctypes.string_at(self.mbs_invdyn_ptr.contents.options.contents.trajectoryqddname)))
address = self.mbs_invdyn_ptr.contents.options.contents.trajectoryqddname
defaut = None
options.append(str_from_c_pointer(address, defaut))
elif key == "t0":
options.append(self.mbs_invdyn_ptr.contents.options.contents.t0)
elif key == "tf":
......@@ -513,21 +520,17 @@ class MbsInvdyn(object):
elif key == "save2file":
options.append(self.mbs_invdyn_ptr.contents.options.contents.save2file)
elif key == "resfilename":
if self.mbs_invdyn_ptr.contents.options.contents.resfilename is None:
mbs_msg(">>" + self.module_name + ">> The option " + key + " is not assigned")
else:
options.append(bytes_to_str(ctypes.string_at(self.mbs_invdyn_ptr.contents.options.contents.resfilename)))
address = self.mbs_invdyn_ptr.contents.options.contents.resfilename
defaut = 'invdyn'
options.append(str_from_c_pointer(address, defaut))
elif key == "respath":
if self.mbs_invdyn_ptr.contents.options.contents.respath is None:
mbs_msg(">>" + self.module_name + ">> The option " + key + " is not assigned")
else:
options.append(bytes_to_str(ctypes.string_at(self.mbs_invdyn_ptr.contents.options.contents.respath)))
address = self.mbs_invdyn_ptr.contents.options.contents.respath
defaut = os.path.abspath(os.path.join(self.mbs.project_path, 'resultsR'))
options.append(str_from_c_pointer(address, defaut))
elif key == "animpath":
if self.mbs_invdyn_ptr.contents.options.contents.animpath is None:
mbs_msg(">>" + self.module_name + ">> The option " + key + " is not assigned")
else:
options.append(bytes_to_str(ctypes.string_at(self.mbs_invdyn_ptr.contents.options.contents.animpath)))
address = self.mbs_invdyn_ptr.contents.options.contents.animpath
defaut = os.path.abspath(os.path.join(self.mbs.project_path, 'animationR'))
options.append(str_from_c_pointer(address, defaut))
elif key == "save_anim":
options.append(self.mbs_invdyn_ptr.contents.options.contents.save_anim)
elif key == "framerate":
......
......@@ -9,12 +9,14 @@ class has the functions required to manipulate the direct modal analysis module.
This includes setting the options, running an(or multiple) analysis and freeing
the memory.
"""
# Author: Robotran Team
# (c) Universite catholique de Louvain, 2021
import os
import ctypes
import numpy as np
# importing MbsysPy functions
from ..mbs_utilities import str_from_c_pointer
from ..mbs_utilities import bytes_to_str
from ..mbs_utilities import str_to_bytes
from ..mbs_utilities import mbs_msg
......@@ -419,11 +421,17 @@ class MbsModal(object):
if key == "save2file":
options.append(self.mbs_modal_ptr.contents.options.contents.save2file)
elif key == "resfilename":
options.append(bytes_to_str(ctypes.string_at(self.mbs_modal_ptr.contents.options.contents.resfilename)))
address = self.mbs_modal_ptr.contents.options.contents.resfilename
defaut = "modal"
options.append(str_from_c_pointer(address, defaut))
elif key == "respath":
options.append(bytes_to_str(ctypes.string_at(self.mbs_modal_ptr.contents.options.contents.respath)))
address = self.mbs_modal_ptr.contents.options.contents.respath
defaut = os.path.abspath(os.path.join(self.mbs.project_path, 'resultsR'))
options.append(str_from_c_pointer(address, defaut))
elif key == "animpath":
options.append(bytes_to_str(ctypes.string_at(self.mbs_modal_ptr.contents.options.contents.animpath)))
address = self.mbs_modal_ptr.contents.options.contents.animpath
defaut = os.path.abspath(os.path.join(self.mbs.project_path, 'animationR'))
options.append(str_from_c_pointer(address, defaut))
elif key == "save_anim":
options.append(self.mbs_modal_ptr.contents.options.contents.save_anim)
elif key == "save_mat":
......
......@@ -19,6 +19,7 @@ import ctypes
import numpy as np
# importing MbsysPy functions
from ..mbs_utilities import str_from_c_pointer
from ..mbs_utilities import bytes_to_str
from ..mbs_utilities import str_to_bytes
from ..mbs_utilities import mbs_msg
......@@ -450,11 +451,17 @@ class MbsSolvekin(MbsInvdyn):
elif self.mbs_solvekin_ptr.contents.options.contents.motion == 2:
options.append("trajectory")
elif key == "trajectoryqname":
options.append(bytes_to_str(ctypes.string_at(self.mbs_solvekin_ptr.contents.options.contents.trajectoryqname)))
address = self.mbs_solvekin_ptr.contents.options.contents.trajectoryqname
defaut = None
options.append(str_from_c_pointer(address, defaut))
elif key == "trajectoryqdname":
options.append(bytes_to_str(ctypes.string_at(self.mbs_solvekin_ptr.contents.options.contents.trajectoryqdname)))
address = self.mbs_solvekin_ptr.contents.options.contents.trajectoryqdname
defaut = None
options.append(str_from_c_pointer(address, defaut))
elif key == "trajectoryqddname":
options.append(bytes_to_str(ctypes.string_at(self.mbs_solvekin_ptr.contents.options.contents.trajectoryqddname)))
address = self.mbs_solvekin_ptr.contents.options.contents.trajectoryqddname
defaut = None
options.append(str_from_c_pointer(address, defaut))
elif key == "t0":
options.append(self.mbs_solvekin_ptr.contents.options.contents.t0)
elif key == "tf":
......@@ -464,11 +471,17 @@ class MbsSolvekin(MbsInvdyn):
elif key == "save2file":
options.append(self.mbs_solvekin_ptr.contents.options.contents.save2file)
elif key == "resfilename":
options.append(bytes_to_str(ctypes.string_at(self.mbs_solvekin_ptr.contents.options.contents.resfilename)))
address = self.mbs_solvekin_ptr.contents.options.contents.resfilename
defaut = 'solvekin'
options.append(str_from_c_pointer(address, defaut))
elif key == "respath":
options.append(bytes_to_str(ctypes.string_at(self.mbs_solvekin_ptr.contents.options.contents.respath)))
address = self.mbs_solvekin_ptr.contents.options.contents.respath
defaut = os.path.abspath(os.path.join(self.mbs.project_path, 'resultsR'))
options.append(str_from_c_pointer(address, defaut))
elif key == "animpath":
options.append(bytes_to_str(ctypes.string_at(self.mbs_solvekin_ptr.contents.options.contents.animpath)))
address = self.mbs_solvekin_ptr.contents.options.contents.animpath
defaut = os.path.abspath(os.path.join(self.mbs.project_path, 'animationR'))
options.append(str_from_c_pointer(address, defaut))
elif key == "save_anim":
options.append(self.mbs_solvekin_ptr.contents.options.contents.save_anim)
elif key == "framerate":
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment