Ejemplo n.º 1
0
 def expression(self):
     expr_list = set([])
     for expr in self.Expression.text().split(';'):
         param_list = get_from_parenthesis(expr, '[', ']').split(',')
         param_list.append(get_from_parenthesis(expr, '(', ')'))
         expr_list.update(param_list)
     return expr_list
Ejemplo n.º 2
0
 def symbols(self) -> Set[List[str]]:
     """Return all symbols."""
     expr_list = set([])
     for expr in self.Expression.text().split(';'):
         param_list = get_from_parenthesis(expr, '[', ']').split(',')
         param_list.append(get_from_parenthesis(expr, '(', ')'))
         expr_list.update(param_list)
     return expr_list
Ejemplo n.º 3
0
 def on_load_button_clicked(self):
     """Show up the dialog to load structure data."""
     dlg = CollectionsDialog(self)
     dlg.show()
     if not dlg.exec_():
         return
     self.profile_name = dlg.name_loaded
     params = dlg.mechanismParams
     mapping = params['name_dict']
     #Add customize joints.
     G = Graph(params['Graph'])
     self.setGraph(G, params['pos'])
     self.PreviewWindow.cus = params['cus']
     self.PreviewWindow.same = params['same']
     #Grounded setting.
     Driver = [mapping[e] for e in params['Driver']]
     Follower = [mapping[e] for e in params['Follower']]
     for row, link in enumerate(G.nodes):
         points = set('P{}'.format(n) for n, edge in edges_view(G)
                      if link in edge)
         if set(Driver + Follower) <= points:
             self.grounded_list.setCurrentRow(row)
             break
     #Driver, Follower, Target
     for row in reversed(range(self.Follower_list.count())):
         if self.Follower_list.item(row).text() in Driver:
             self.Follower_list.setCurrentRow(row)
             self.Driver_add.click()
     self.Target_list.addItems([mapping[e] for e in params['Target']])
     self.setWarning(self.Target_label, not self.Target_list.count() > 0)
     #Constraints
     self.constraint_list.addItems(
         [", ".join(mapping[e] for e in c) for c in params['constraint']])
     #Expression
     for expr in params['Expression'].split(';'):
         params = get_from_parenthesis(expr, '[', ']').split(',')
         target = get_from_parenthesis(expr, '(', ')')
         params.append(target)
         for p in params:
             try:
                 #Try to avoid replace function name.
                 expr = mapping[p].join(expr.rsplit(p, 1))
             except KeyError:
                 continue
         item = QListWidgetItem()
         self.Expression_list.addItem(item)
         item.setText(expr)
         self.PreviewWindow.setStatus(mapping[target], True)
     self.setWarning(self.Expression_list_label,
                     not self.PreviewWindow.isAllLock())
Ejemplo n.º 4
0
 def set_parm_bind(self, item=None):
     """Set parameters binding."""
     self.parm_bind.clear()
     expr_list = []
     #At this time, we should turn the points number to letter names.
     ln = letter_names()
     #Set functional expression.
     for expr in list_texts(self.Expression_list):
         params = get_from_parenthesis(expr, '[', ']').split(',')
         params.append(get_from_parenthesis(expr, '(', ')'))
         for name in params:
             if 'P' in name:
                 #Find out with who was shown earlier.
                 if name not in self.parm_bind:
                     self.parm_bind[name] = next(ln)
                 expr = expr.replace(name, self.parm_bind[name])
         expr_list.append(expr)
     #If there has any joints not named yet.
     for name in combo_texts(self.joint_name):
         if name not in self.parm_bind:
             self.parm_bind[name] = next(ln)
     #Set link expression.
     link_expr_list = []
     self.Expression.setText(';'.join(expr_list))
     for row, gs in list_texts(self.grounded_list, True):
         try:
             link_expr = []
             #Links from grounded list.
             for name in gs.replace('(', '').replace(')', '').split(", "):
                 if self.PreviewWindow.isMultiple(name):
                     name = 'P{}'.format(self.PreviewWindow.same[int(
                         name.replace('P', ''))])
                 link_expr.append(self.parm_bind[name])
         except KeyError:
             continue
         else:
             #Customize joints.
             for joint, link in self.PreviewWindow.cus.items():
                 if row == link:
                     link_expr.append(self.parm_bind[joint])
             link_expr_str = ','.join(sorted(set(link_expr)))
             if row == self.grounded_list.currentRow():
                 link_expr_list.insert(0, link_expr_str)
             else:
                 link_expr_list.append(link_expr_str)
     self.Link_Expression.setText(';'.join(
         ('ground' if i == 0 else '') + "[{}]".format(link)
         for i, link in enumerate(link_expr_list)))
Ejemplo n.º 5
0
 def hasSolution(self, index=None):
     if index is None:
         index = self.joint_name.currentIndex()
     if index > -1:
         status = self.PreviewWindow.getStatus(index)
         if not status:
             status_str = "Not known."
         elif index in self.PreviewWindow.same:
             status_str = "Same as P{}.".format(
                 self.PreviewWindow.same[index])
         else:
             status_str = "Grounded."
             for expr in list_texts(self.Expression_list):
                 if index == int(
                         get_from_parenthesis(expr, '(',
                                              ')').replace('P', '')):
                     status_str = "From {}.".format(
                         get_front_of_parenthesis(expr, '['))
         self.status.setText(status_str)
         self.PLAP_solution.setEnabled(not status)
         self.PLLP_solution.setEnabled(not status)
     else:
         self.status.setText("N/A")
         self.PLAP_solution.setEnabled(False)
         self.PLLP_solution.setEnabled(False)
Ejemplo n.º 6
0
 def on_Expression_pop_clicked(self):
     count = self.Expression_list.count()
     if count:
         expr = self.Expression_list.item(count - 1).text()
         self.Expression_list.takeItem(count - 1)
         self.PreviewWindow.setStatus(get_from_parenthesis(expr, '(', ')'),
                                      False)
         self.set_parm_bind()
Ejemplo n.º 7
0
 def on_Expression_pop_clicked(self):
     """Remove the last solution."""
     count = self.Expression_list.count()
     if not count:
         return
     expr = self.Expression_list.item(count - 1).text()
     self.Expression_list.takeItem(count - 1)
     self.PreviewWindow.setStatus(get_from_parenthesis(expr, '(', ')'),
                                  False)
     self.set_parm_bind()
Ejemplo n.º 8
0
 def __init__(self, mechanism, Path, parent=None):
     super(DynamicCanvas, self).__init__(parent)
     self.mechanism = mechanism
     self.Path.path = Path
     self.solvingPath = self.mechanism['Target']
     self.index = 0
     #exp_symbol = ('A', 'B', 'C', 'D', 'E')
     self.exp_symbol = []
     self.links = []
     for exp in self.mechanism['Link_Expression'].split(';'):
         tags = get_from_parenthesis(exp, '[', ']').split(',')
         self.links.append(tuple(tags))
         for name in tags:
             if name not in self.exp_symbol:
                 self.exp_symbol.append(name)
     self.exp_symbol = sorted(self.exp_symbol)
     #Timer start.
     timer = QTimer(self)
     timer.setInterval(10)
     timer.timeout.connect(self.change_index)
     timer.start()