Пример #1
0
    def test_elbow_1(self):
        node_id = 9674342137
        node = gutils.node_with_id(self.s.root, node_id)
        print(node.get('$create'))
        assert node is not None
        mgr = rvt.make_actions_for(node)
        print(mgr._state)
        a = mgr.next_action()
        print(a[0:3], '\n', mgr._state)
        assert isinstance(a, list), msg('list', a)
        assert a[0] == _Cmd_pipe, msg(_Cmd_pipe, a[0])

        mgr.on_success(a)
        a = mgr.next_action()
        print(a[0:3], '\n', mgr._state)

        assert a[0] == _Cmd_elb, msg(_Cmd_elb, a[0])

        mgr.on_success(a)
        print(mgr._state)
        a = mgr.next_action()
        print(a, '\n', mgr._state)

        assert a is None, msg(None, a)

        e = node.successors(edges=True, ix=0)
        self._edge_stat(e, True, True, not True)
Пример #2
0
 def _reload(self):
     if self._path is not None and os.path.exists(self._path) is True:
         with open(self._path, 'rb') as F:
             nx_graph = nx.read_gpickle(F)
             root_nodes = utils.nxgraph_to_nodes(nx_graph)
             self._root = root_nodes
             self.q = root_nodes
             self.current_node = self.q[0]
             self.cmd_mgr = revit.make_actions_for(self.current_node)
Пример #3
0
 def _test_scenario(self, node, results):
     mgr = rvt.make_actions_for(node)
     a = -1
     while results and a is not None:
         print('\n')
         a = mgr.next_action()
         r = results.pop(0)
         print(a, r)
         if r == 1:
             mgr.on_success(a)
         elif r == 0:
             mgr.on_fail(a, 'x')
         print(mgr._state)
Пример #4
0
    def _single_node_success(self, node):
        mgr = rvt.make_actions_for(node)
        a = mgr.next_action()
        while a is not None:
            print(a)
            assert isinstance(a, list), msg('list', a)
            mgr.on_success(a)
            a = mgr.next_action()
            print(mgr._state)

        for e in node.successors(edges=True):
            self._edge_stat(e, True, True, None)
        for e in node.predecessors(edges=True):
            self._edge_stat(e, None, None, True)
Пример #5
0
    def _test_node_success(self, node: Node, ntype):
        mgr = rvt.make_actions_for(node)
        a1 = mgr.next_action()
        assert isinstance(a1, list), msg('list', a1)
        assert a1[0] == ntype, msg(ntype, a1[0])

        mgr.on_success(a1)
        assert rvt.is_built(node) is True, msg(True, rvt.is_built(node))

        for i in range(node.nsucs):
            a2 = mgr.next_action()
            assert a2[0] == _Cmd_pipe, msg(_Cmd_pipe, a2[0])
            assert a2[2] == _Pipe_CnPt, msg(_Pipe_CnPt, a2[2])
            mgr.on_success(a2)

        for e in node.successors(edges=True):
            self._edge_stat(e, True, True, not True)
Пример #6
0
    def test_elbow_fail(self):
        node_id = 9674342137
        node = gutils.node_with_id(self.s.root, node_id)
        # print(node.get('$create'))
        assert node is not None
        mgr = rvt.make_actions_for(node)
        a = mgr.next_action()
        # print(a)

        assert a[0] == _Cmd_pipe, msg(_Cmd_pipe, a[0])
        mgr.on_success(a)
        a = mgr.next_action()
        # print(a)
        assert a[0] == _Cmd_elb, msg(_Cmd_elb, a[0])
        mgr.on_fail(a)
        a = mgr.next_action()
        self._edge_stat(node.successors(edges=True, ix=0), True, True,
                        not True)
Пример #7
0
    def on_default(self, node, **kwargs):
        for succ_edg in node.successors(edges=True):
            succ_edg.write('$create', 'pipe')

        # if is_head_tee(node):
        #     node.write('$create', 'tee')
        #
        # elif is_coupling(node):
        #     node.write('$create', 'coupling')
        #
        # elif is_tee(node):
        #     node.write('$create', 'tee')
        #
        # elif is_elbow(node):
        #     node.write('$create', 'elbow')

        cmd_mgr = revit.make_actions_for(node)
        self._res.extend(list(iter(cmd_mgr)))
        return node
Пример #8
0
    def _test_node_fail(self, node: Node, ntype):
        mgr = rvt.make_actions_for(node)
        a1 = mgr.next_action()
        assert isinstance(a1, list), msg('list', a1)
        assert a1[0] == ntype, msg(ntype, a1[0])

        mgr.on_fail(a1)
        assert rvt.is_built(node) is False, msg(False, rvt.is_built(node))

        for i in range(node.nsucs):
            a2 = mgr.next_action()
            assert a2[0] == _Cmd_pipe, msg(_Cmd_pipe, a2[0])
            assert a2[2] == _Pipe_PtPt, msg(_Pipe_PtPt, a2[2])
            mgr.on_success(a2)

        for e in node.successors(edges=True):
            b, c1, c2 = _edge_status(e)
            assert b is True, msg(True, b)
            assert c1 is not True, msg(False, c1)
            assert c2 is not True, msg(False, c2)
Пример #9
0
    def on_default(self, *args):
        next_action = self.cmd_mgr.next_action()
        while next_action is None:
            # the action manager for current node is done
            # add node successors to the queue
            for n in self.current_node.successors():
                self.q.append(n)

            if len(self.q) == 0:
                return self.on_finish()

            # set the current node, create new cmd_manager
            self.current_node = self.q.pop(0)
            self.cmd_mgr = revit.make_actions_for(self.current_node)
            next_action = self.cmd_mgr.next_action()

        self._count += 1
        if self._lim is not None and self._count > self._lim:
            return self.on_finish()

        self.last_action = next_action
        return 'COMMAND,' + stringify(next_action)