def _save(self): """ """ _name = str(self.ui.name_lineEdit.text()) # try: _mass = float(self.ui.m_lineEdit.text()) _J_zz = float(self.ui.J_lineEdit.text()) _R = np.array(string2array(self.ui.R_lineEdit.text()), dtype="float32") _theta = np.array(string2array(self.ui.theta_lineEdit.text()), dtype="float32") if self.ui.transformCS_comboBox.currentText() == "CAD": __dR = self.item.CM_CAD_LCS - Ai_ui_P_vector( self.item.CM_CAD_LCS, np.deg2rad(_theta[2])) else: __dR = np.zeros(3) _dR = string2array(self.ui.dR_lineEdit.text()) _dtheta = string2array(self.ui.dtheta_lineEdit.text()) _color = string2array(self.ui.color_lineEdit.text()) _transparent = float(self.ui.transparent_lineEdit.text()) _display_style = str( self.ui.display_style_comboBox.currentText()).lower() # update data to selected object if self.item is not None: self.item._name = _name self.item.mass = _mass self.item.J_zz = _J_zz self.item.R = _R - __dR self.item.theta = np.deg2rad(_theta) self.item.dR = _dR self.item.dtheta = np.deg2rad(_dtheta) self.item.display_style = _display_style # update vbo if it is changed if any(_color != self.item.color_GL ) or _transparent != self.item.transparent_GL: self.item.color_GL = _color self.item.transparent_GL = _transparent self.item._update_VBO() # create new object else: _item = Body(body_name=_name, parent=self.group_item) pos = len(self.parent_node._children) self.parent_node._parent.forces.append(_item) self._parent.ui.treeView.model().insertRow(pos, _item, self.parent_node) # update dependent parameters self.item.update() self.close()
def _save(self, item=None): """ """ # name _name = self.ui.name_lineEdit.text() # contact type _type = self.ui.contactTypecomboBox.currentText() # contact model type _type = str(self.ui.contactModelTypecomboBox.currentText()).lower() print "_type =", _type self.item.contact_model._type = _type print "self.item.contact_model._type =", self.item.contact_model._type # distance tolerance self.item.distance_TOL = float(self.ui.TOL_distance_lineEdit.text()) # try: _body_id_i = int(self.ui.bodyIDi_lineEdit.text()) _body_id_j = int(self.ui.bodyIDj_lineEdit.text()) _coef_of_friction_static = self.ui.frictionCoefStatic_lineEdit.text().toDouble() _coef_of_friction_dynamic = self.ui.frictionCoefDynamic_lineEdit.text().toDouble() _coef_of_restitution = self.ui.restitution_coefficient_lineEdit.text().toDouble() if self.item._type == "Revolute Clearance Joint": _uPi = string2array(self.ui.uPi_lineEdit.text()) _uPj = string2array(self.ui.uPj_lineEdit.text()) _Ri = float(self.ui.Ri_lineEdit.text()) _Rj = float(self.ui.Rj_lineEdit.text()) if self.item._type == "General": pass if self.item is not None: self.item.body_id_i = _body_id_i self.item.body_id_j = _body_id_j self.item.friction_model.coef_of_friction_static = _coef_of_friction_static self.item.friction_model.coef_of_friction_dynamic = _coef_of_friction_dynamic self.item.contact_model.coef_of_restitution = _coef_of_restitution if self.item._type == "Revolute Clearance Joint": self.item.u_iP = _uPi self.item.u_jP = _uPj self.item.R_i = _Ri self.item.R_j = _Rj else: _item = Contact(body_id_i=_body_id_i, body_id_j=_body_id_j) pos = len(self.parent_node._children) self.parent_node._parent.forces.append(_item) self._parent.ui.treeView.model().insertRow(pos, _item, self.parent_node) self.close()
def _save(self): """ """ _name = str(self.ui.name_lineEdit.text()) # try: _mass = float(self.ui.m_lineEdit.text()) _J_zz = float(self.ui.J_lineEdit.text()) _R = np.array(string2array(self.ui.R_lineEdit.text()), dtype="float32") _theta = np.array(string2array(self.ui.theta_lineEdit.text()), dtype="float32") if self.ui.transformCS_comboBox.currentText() == "CAD": __dR = self.item.CM_CAD_LCS - Ai_ui_P_vector(self.item.CM_CAD_LCS, np.deg2rad(_theta[2])) else: __dR = np.zeros(3) _dR = string2array(self.ui.dR_lineEdit.text()) _dtheta = string2array(self.ui.dtheta_lineEdit.text()) _color = string2array(self.ui.color_lineEdit.text()) _transparent = float(self.ui.transparent_lineEdit.text()) _display_style = str(self.ui.display_style_comboBox.currentText()).lower() # update data to selected object if self.item is not None: self.item._name = _name self.item.mass = _mass self.item.J_zz = _J_zz self.item.R = _R - __dR self.item.theta = np.deg2rad(_theta) self.item.dR = _dR self.item.dtheta = np.deg2rad(_dtheta) self.item.display_style = _display_style # update vbo if it is changed if any(_color != self.item.color_GL) or _transparent != self.item.transparent_GL: self.item.color_GL = _color self.item.transparent_GL = _transparent self.item._update_VBO() # create new object else: _item = Body(body_name=_name, parent=self.group_item) pos = len(self.parent_node._children) self.parent_node._parent.forces.append(_item) self._parent.ui.treeView.model().insertRow(pos, _item, self.parent_node) self.close()
def _save(self, item=None): """ """ _name = self.ui.name_lineEdit.text() _type = self.ui.jointTypecomboBox.currentText() # try: if self.ui.bodyIDi_lineEdit.text() == "ground": pass else: _body_id_i = int(self.ui.bodyIDi_lineEdit.text()) if self.ui.bodyIDj_lineEdit.text() == "ground": _body_id_j = self.ui.bodyIDj_lineEdit.text() else: _body_id_j = int(self.ui.bodyIDj_lineEdit.text()) _uPi = string2array(self.ui.uPi_lineEdit.text()) _uPj = string2array(self.ui.uPj_lineEdit.text()) # update data to selected object if self.item is not None: self.item._name = _name self.item.body_id_i = _body_id_i self.item.body_id_j = _body_id_j # update position of marker if vector uP is changed for _uP, _u_P, _id, body_id in zip( [_uPi, _uPj], [self.item.u_iP, self.item.u_jP], [0, 1], self.item.body_id_list): if (_uP != _u_P).any() and (body_id != "ground"): self.item.markers[_id]._update_node( np.array(np.append(_uP, self.item.z_dim), dtype='float32')) else: _type = str(_type).lower() _item = Joint(_type, _body_id_i, _body_id_j) pos = len(self.parent_node._children) self.parent_node._parent.forces.append(_item) self._parent.ui.treeView.model().insertRow(pos, _item, self.parent_node) self.close()
def _save(self, item=None): """ """ _name = self.ui.name_lineEdit.text() _type = self.ui.jointTypecomboBox.currentText() # try: if self.ui.bodyIDi_lineEdit.text() == "ground": pass else: _body_id_i = int(self.ui.bodyIDi_lineEdit.text()) if self.ui.bodyIDj_lineEdit.text() == "ground": _body_id_j = self.ui.bodyIDj_lineEdit.text() else: _body_id_j = int(self.ui.bodyIDj_lineEdit.text()) _uPi = string2array(self.ui.uPi_lineEdit.text()) _uPj = string2array(self.ui.uPj_lineEdit.text()) # update data to selected object if self.item is not None: self.item._name = _name self.item.body_id_i = _body_id_i self.item.body_id_j = _body_id_j # update position of marker if vector uP is changed for _uP, _u_P, _id, body_id in zip([_uPi, _uPj], [self.item.u_iP, self.item.u_jP], [0, 1], self.item.body_id_list): if (_uP != _u_P).any() and (body_id != "ground"): self.item.markers[_id]._update_node(np.array(np.append(_uP, self.item.z_dim), dtype='float32')) else: _type = str(_type).lower() _item = Joint(_type, _body_id_i, _body_id_j) pos = len(self.parent_node._children) self.parent_node._parent.forces.append(_item) self._parent.ui.treeView.model().insertRow(pos, _item, self.parent_node) self.close()
def _save(self, item=None): """ """ _force_name = self.ui.name_lineEdit.text() # try: _body_id = int(self.ui.bodyID_lineEdit.text()) try: _Fx = float(self.ui.Fx_lineEdit.text()) except: _Fx = self.ui.Fx_lineEdit.text() try: _Fy = float(self.ui.Fy_lineEdit.text()) except: _Fy = self.ui.Fy_lineEdit.text() try: _Mz = float(self.ui.Mz_lineEdit.text()) except: _Mz = self.ui.Mz_lineEdit.text() _u_iP_f = string2array(self.ui.uPi_lineEdit.text()) # save tzo existing object if self.item is not None: self.item.body_id = _body_id self.item.force_name = _force_name self.item.Fx = _Fx self.item.Fy = _Fy self.item.Mz = _Mz self.item.u_iP_f = _u_iP_f self.item._scale_GL, status = self.ui.scale_lineEdit.text( ).toFloat() # create new object with user specified properties else: _force = Force(body_id=_body_id, force_name=_force_name, Fx=_Fx, Fy=_Fy, Mz=_Mz, u_iP_f=_u_iP_f) pos = len(self.parent_node._children) self.parent_node._parent.forces.append(_force) self._parent.ui.treeView.model().insertRow(pos, _force, self.parent_node) self.close()
def _save(self, item=None): """ """ _force_name = self.ui.name_lineEdit.text() # try: _body_id = int(self.ui.bodyID_lineEdit.text()) try: _Fx = float(self.ui.Fx_lineEdit.text()) except: _Fx = self.ui.Fx_lineEdit.text() try: _Fy = float(self.ui.Fy_lineEdit.text()) except: _Fy = self.ui.Fy_lineEdit.text() try: _Mz = float(self.ui.Mz_lineEdit.text()) except: _Mz = self.ui.Mz_lineEdit.text() _u_iP_f = string2array(self.ui.Mz_lineEdit.text()) if self.item is not None: self.item.body_id = _body_id self.item.force_name = _force_name self.item.Fx = _Fx self.item.Fy = _Fy self.item.Mz = _Mz self.item.u_iP_f = _u_iP_f else: _force = Force(body_id=_body_id, force_name=_force_name, Fx=_Fx, Fy=_Fy, Mz=_Mz, u_iP_f=_u_iP_f) pos = len(self.parent_node._children) self.parent_node._parent.forces.append(_force) self._parent.ui.treeView.model().insertRow(pos, _force, self.parent_node) self.close()
def read_data(filename): """ method reads geometry data file of a body in: filename of the body data file out: _dict - dictionary of attributes to assgin to body object """ # predefine empty dictionary dict_ = OrderedDict([]) with open(filename, 'r') as file_: # 'r' - read # 'w' - write # 'a' - append # 'r+' - read and write # # predefined values # name = [] # body_geometry_filename = [] # # density = 0. # volume = 0. # mass = 0. # J_zz = 0. # CM_LCS = np.zeros(3, dtype="float32") # R_GCS = np.zeros(3, dtype="float32") # theta_GCS = np.zeros(3, dtype="float32") # dR_GCS = np.zeros(3, dtype="float32") # dtheta_GCS = np.zeros(3, dtype="float32") # # color_GL = np.ones(3, dtype="float32") # transparent_GL = 1 # display_style = "filled" # ln = "name = actuating_lever" # print ln[ln.index("=")] for line in file_: if "#" in line: line = line[:line.index("#")].strip() # if line is empty or begins with #-comment, skip it if len(line.strip()) == 0 or line.startswith("#"): pass else: # attribute name key = line[0:line.find("=")].strip() # if vasriable name includes units, remove it if "[" in key: key = key[0:line.find("[")].strip() val = line[line.find("=")+1:].strip() # if string has commas, then convert to array if "," in val: val = string2array(val) else: try: # try covnert string to integer val = int(val) except: try: # try convert string to float val = float(val) except: # # check if string is bool and convert it to bool if val.lower() == "true": val = True elif val.lower() == "false": val = False # add dict item to dict with value # print key," = ", val, type(val) dict_[key] = val # if line.startswith("name="): # line_ = file_.next() # match_newline = re.search(r"\n", line_) # name = line_[:match_newline.start()] # # elif line.startswith("density"): # density = float(file_.next().strip()) # # elif line.startswith("volume"): # volume = float(file_.next().strip()) # # elif line.startswith("mass"): # mass = float(file_.next().strip()) # # elif line.startswith("J_zz"): # J_zz = float(file_.next().strip()) # # elif line.startswith("CM in CAD LCS"): # CM_CAD_LCS = np.array(file_.next().split(','), dtype="float32") # # elif line.startswith("CAD LCS in GCS"): # CAD_LCS_GCS = np.array(file_.next().split(','), dtype="float32") # # elif line.startswith("theta"): # theta_GCS = np.deg2rad(np.array(file_.next().split(','), dtype="float32")) # # elif line.startswith("dR"): # dR_GCS = np.array(file_.next().split(','), dtype="float32") # # elif line.startswith("angular"): # dtheta_GCS = np.deg2rad(np.array(file_.next().split(','), dtype="float32")) # # elif line.startswith("body geometry filename"): # line_ = file_.next() # match_newline = re.search(r"\n", line_) # body_geometry_filename = line_[:match_newline.start()] # # elif line.startswith("color"): # color_GL = np.array(file_.next().split(','), dtype="float32") # # elif line.startswith("transparent"): # transparent_GL = float(file_.next().strip()) # # elif line.startswith("display style"): # line_ = file_.next() # match_newline = re.search(r"\n", line_) # display_style = line_.translate(None, '\n') # # elif line.startswith("material"): # line_ = file_.next() # match_newline = re.search(r"\n", line_) # material = line_[0:match_newline.start()] # calculate mass from volume and density # if (volume != 0) and (density != 0): # mass = density * volume # close opened file file_.closed return dict_
def read_body_data_file(filename): """ method reads geometry data file of a body in: filename of the body data file out: _dict - dictionary of attributes to assgin to body object """ # predefine empty dictionary dict_ = OrderedDict([]) if os.path.isfile(filename): # 'r' - read # 'w' - write # 'a' - append # 'r+' - read and write with open(filename, 'r') as file_: for line in file_: if "#" in line: line = line[:line.index("#")].strip() # if line is empty or begins with #-comment, skip it if len(line.strip()) == 0 or line.startswith("#"): pass else: # attribute name key = line[0:line.find("=")].strip() # if vasriable name includes units, remove it if "[" in key: key = key[0:line.find("[")].strip() val = line[line.find("=")+1:].strip() # if string has commas, then convert to array if "," in val: val = string2array(val) else: try: # try convert string to integer val = int(val) except: try: # try convert string to float val = float(val) except: # check if string is bool and convert it to bool if val.lower() == "true": val = True elif val.lower() == "false": val = False # add dict item to dict with value dict_[key] = val # close opened file file_.close() else: print "Body data file not found! Check filename %s"%filename return dict_
def _save(self, item=None): """ """ # name _name = self.ui.name_lineEdit.text() # contact type _type = self.ui.contactTypecomboBox.currentText() # contact model type _type = str(self.ui.contactModelTypecomboBox.currentText()).lower() print "_type =", _type self.item.contact_model._type = _type print "self.item.contact_model._type =", self.item.contact_model._type # distance tolerance self.item.distance_TOL = float(self.ui.TOL_distance_lineEdit.text()) # try: _body_id_i = int(self.ui.bodyIDi_lineEdit.text()) _body_id_j = int(self.ui.bodyIDj_lineEdit.text()) _coef_of_friction_static = self.ui.frictionCoefStatic_lineEdit.text( ).toDouble() _coef_of_friction_dynamic = self.ui.frictionCoefDynamic_lineEdit.text( ).toDouble() _coef_of_restitution = self.ui.restitution_coefficient_lineEdit.text( ).toDouble() if self.item._type == "Revolute Clearance Joint": _uPi = string2array(self.ui.uPi_lineEdit.text()) _uPj = string2array(self.ui.uPj_lineEdit.text()) _Ri = float(self.ui.Ri_lineEdit.text()) _Rj = float(self.ui.Rj_lineEdit.text()) if self.item._type == "General": pass if self.item is not None: self.item.body_id_i = _body_id_i self.item.body_id_j = _body_id_j self.item.friction_model.coef_of_friction_static = _coef_of_friction_static self.item.friction_model.coef_of_friction_dynamic = _coef_of_friction_dynamic self.item.contact_model.coef_of_restitution = _coef_of_restitution if self.item._type == "Revolute Clearance Joint": self.item.u_iP = _uPi self.item.u_jP = _uPj self.item.R_i = _Ri self.item.R_j = _Rj else: _item = Contact(body_id_i=_body_id_i, body_id_j=_body_id_j) pos = len(self.parent_node._children) self.parent_node._parent.forces.append(_item) self._parent.ui.treeView.model().insertRow(pos, _item, self.parent_node) self.close()
def _save(self, item=None): """ """ _name = self.ui.name_lineEdit.text() _type = self.ui.springType_comboBox.currentText() try: if self.ui.bodyIDi_lineEdit.text() == "ground": pass else: _body_id_i = int(self.ui.bodyIDi_lineEdit.text()) if self.ui.bodyIDj_lineEdit.text() == "ground": _body_id_j = self.ui.bodyIDj_lineEdit.text() else: _body_id_j = int(self.ui.bodyIDj_lineEdit.text()) _uPi = string2array(self.ui.uPi_lineEdit.text()) _uPj = string2array(self.ui.uPj_lineEdit.text()) _k = float(self.ui.K_lineEdit.text()) _d = float(self.ui.D_lineEdit.text()) _l0 = float(self.ui.L0_lineEdit.text()) # color # force scale # save attributes to an existing object if self.item is not None: self.item._name = _name self.item.body_id_i = _body_id_i self.item.body_id_j = _body_id_j self.item.k = _k self.item.c = _d self.item.l_0 = _l0 # spring force for Fn in self.item._Fn_list: # scale Fn._scale_GL = float(self.ui.scale_lineEdit.text()) # color Fn._color_GL = string2array(self.ui.color_lineEdit.text()) # create new object else: _type = str(_type).lower() self.item = Spring(_name, _type, _body_id_i, _body_id_j, _uPi, _uPj, parent=self.parent_node) pos = len(self.parent_node._children) self.parent_node._parent.springs.append(self.item) self._parent.ui.treeView.model().insertRow( pos, self.item, self.parent_node) print "self.item =", self.item pprint(vars(self.item)) self.item = None self.close() except: QtGui.QMessageBox.warning(self, "Warning!", "Input not correct!", QtGui.QMessageBox.Cancel, QtGui.QMessageBox.NoButton, QtGui.QMessageBox.NoButton)
def load_contact_profile(self, filename): """ Load geometry nodes from text file """ # print "Contact_profile", filename, 'loaded for body', self.body._name, 'with id', self.body_id,'.' # load data from file data = [] arc_ = False with open(filename, 'r') as file_: for line in file_: if "#" in line: line = line[:line.index("#")].strip() if len(line.strip()) == 0 or line.startswith("#"): pass else: # if string has commas, then convert to array if "," in line and not "arc" in line: line = string2array(line) if data == []: data = np.append(data, line) else: data = np.vstack((data, line)) if "arc" in line: arc_ = True if line.startswith("arc R ="): R = float(line[line.find("=") + 1:].strip()) elif line.startswith("arc x0 ="): x0 = float(line[line.find("=") + 1:].strip()) elif line.startswith("arc y0 ="): y0 = float(line[line.find("=") + 1:].strip()) elif line.startswith("arc n ="): n = float(line[line.find("=") + 1:].strip()) if arc_ is True: theta = np.arccos(x0 / R) arcpoints = np.linspace((np.pi + theta), (np.pi - theta), n) arcx = np.cos(arcpoints) * R + x0 arcy = np.sin(arcpoints) * R + y0 arc = np.vstack((arcx, arcy)).T data = np.concatenate((data, arc), axis=0) # data = np.array(np.loadtxt(filename, delimiter=',')) # if self.body_id == 0: # print data # check size and if normals are included in file n, cols = np.shape(data) # cols - number of columns # options (data shape): # 2 cols (x, y) # 4 cols (x, y, nx, ny) # 6 cols (x, y, nx, nz, tx, ty) if cols == 2: self.nodes = data * self.scale self.tangents = self._evaluate_tangents(self.nodes) self.normals = self._evaluate_normals(self.tangents) logging.getLogger("DyS_logger").info( "Profile geometry from file %s read successfully!" % filename) if cols == 4: self.nodes = data[:, 0:3] print "todo" if cols == 6: print "todo"