def load(self, p):

        cp = CanvasParser(p)
        if cp.get_root() is None:
            return

        nodes = dict()

        #=======================================================================
        # load nodes
        #=======================================================================
        # load roots
        for t, klass in (('stage', RootNode),
                         ('spectrometer', SpectrometerNode),
                         ('valve', ValveNode),
                         ('rough_valve', ValveNode),
                         ('turbo', PumpNode),
                         ('ionpump', PumpNode),
                         ('laser', LaserNode),
                         ('tank', TankNode),
                         ('pipette', PipetteNode),
                         ('gauge', GaugeNode),
        ):
            for si in cp.get_elements(t):
                n = si.text.strip()
                if t in ('valve', 'rough_valve'):
                    o_vol = get_volume(si, tag='open_volume', default=10)
                    c_vol = get_volume(si, tag='closed_volume', default=5)
                    vol = (o_vol, c_vol)
                else:
                    vol = get_volume(si)

                node = klass(name=n, volume=vol)
                nodes[n] = node

        #=======================================================================
        # load edges
        #=======================================================================
        for ei in cp.get_elements('connection'):
            sa = ei.find('start')
            ea = ei.find('end')
            vol = get_volume(ei)
            edge = Edge(volume=vol)
            s_name = ''
            if sa.text in nodes:
                s_name = sa.text
                sa = nodes[s_name]
                edge.a_node = sa
                sa.add_edge(edge)

            e_name = ''
            if ea.text in nodes:
                e_name = ea.text
                ea = nodes[e_name]
                edge.b_node = ea
                ea.add_edge(edge)

            edge.name = '{}_{}'.format(s_name, e_name)

        self.nodes = nodes
Example #2
0
    def _save_xml(self, p):
        cp = CanvasParser(p)

        for tag in ('laser', 'stage', 'spectrometer'):
            for ei in cp.get_elements(tag):
                self._set_element_color(ei)
                self._set_element_translation(ei)

        for ei in cp.get_elements('valve'):
            self._set_element_translation(ei)

        for ei in cp.get_elements('connection'):
            # name = ei.text.strip()
            start = ei.find('start').text.strip()
            end = ei.find('end').text.strip()
            name = '{}_{}'.format(start, end)

            obj = self.scene.get_item(name)
            for t, tt in ((
                    obj.clear_vorientation,
                    'vertical',
            ), (obj.clear_horientation, 'horizontal')):
                if t and obj.get('orientation') == tt:
                    ei.set('orientation', '')

                    # if obj.clear_vorientation and obj.orientation=='vertical':
                    # ei.set('orientation', '')
                    # if obj.clear_orientation and obj.orientation=='':
                    # ei.set('orientation', '')

        # p = os.path.join(os.path.dirname(p, ), 'test.xml')
        cp.save()
Example #3
0
 def _construct_xml(self):
     tags = {Valve: 'valve'}
     cp = CanvasParser()
     for elem in self.scene.iteritems():
         if type(elem) in tags:
             tag = tags[type(elem)]
             print 'adsfafd', tag, elem
         elif hasattr(elem, 'type_tag'):
             print 'fffff', elem.type_tag, elem
Example #4
0
    def _save_xml(self, p):
        cp = CanvasParser(p)

        for tag in ('laser', 'stage', 'turbo', 'getter',
                    'ionpump','gauge',
                    'spectrometer', 'tank', 'pipette'):
            for ei in cp.get_elements(tag):
                self._set_element_color(ei)
                self._set_element_translation(ei)

        for ei in cp.get_elements('valve'):
            self._set_element_translation(ei)

        for ei in cp.get_elements('connection'):
            # name = ei.text.strip()
            start = ei.find('start').text.strip()
            end = ei.find('end').text.strip()
            name = '{}_{}'.format(start, end)

            obj = self.scene.get_item(name)
            for t, tt in ((obj.clear_vorientation, 'vertical',),
                          (obj.clear_horientation, 'horizontal')):
                if t and obj.get('orientation') == tt:
                    ei.set('orientation', '')

                    # if obj.clear_vorientation and obj.orientation=='vertical':
                    # ei.set('orientation', '')
                    # if obj.clear_orientation and obj.orientation=='':
                    # ei.set('orientation', '')

        # p = os.path.join(os.path.dirname(p, ), 'test.xml')
        cp.save()
Example #5
0
    def _save_button_fired(self):
        cp = CanvasParser(self.path)

        for o in self._valve_changes:
            for t in SWITCH_TAGS:
                elem = next(
                    (s
                     for s in cp.get_elements(t) if s.text.strip() == o.name),
                    None)
                if elem:
                    t = elem.find('translation')
                    t.text = '{},{}'.format(o.x, o.y)
                    break

        for o in self._rect_changes:
            for t in RECT_TAGS:
                elem = next(
                    (s
                     for s in cp.get_elements(t) if s.text.strip() == o.name),
                    None)
                if elem:
                    t = elem.find('translation')
                    t.text = '{},{}'.format(o.x, o.y)
                    t = elem.find('dimension')
                    t.text = '{},{}'.format(o.width, o.height)
                    break

        cp.save()
Example #6
0
    def _save_xml(self, p):
        cp = CanvasParser(p)

        for tag in ("laser", "stage", "turbo", "getter", "ionpump", "gauge", "spectrometer", "tank", "pipette"):
            for ei in cp.get_elements(tag):
                self._set_element_color(ei)
                self._set_element_translation(ei)

        for ei in cp.get_elements("valve"):
            self._set_element_translation(ei)

        for ei in cp.get_elements("connection"):
            # name = ei.text.strip()
            start = ei.find("start").text.strip()
            end = ei.find("end").text.strip()
            name = "{}_{}".format(start, end)

            obj = self.scene.get_item(name)
            for t, tt in ((obj.clear_vorientation, "vertical"), (obj.clear_horientation, "horizontal")):
                if t and obj.get("orientation") == tt:
                    ei.set("orientation", "")

                    # if obj.clear_vorientation and obj.orientation=='vertical':
                    # ei.set('orientation', '')
                    # if obj.clear_orientation and obj.orientation=='':
                    # ei.set('orientation', '')

        # p = os.path.join(os.path.dirname(p, ), 'test.xml')
        cp.save()
Example #7
0
    def _save_xml(self, p):
        cp = CanvasParser(p)

        for tag in ('laser', 'stage', 'spectrometer'):
            for ei in cp.get_elements(tag):
                self._set_element_color(ei)
                self._set_element_translation(ei)

        for ei in cp.get_elements('valve'):
            self._set_element_translation(ei)

        for ei in cp.get_elements('connection'):
            name = ei.text.strip()
            obj = self.scene.get_item(name)
            if obj.clear_orientation:
                ei.set('orientation', '')

        p = os.path.join(os.path.dirname(p, ), 'test.xml')
        cp.save()
Example #8
0
    def _save_xml(self, p):
        cp = CanvasParser(p)

        for tag in ('laser', 'stage', 'spectrometer'):
            for ei in cp.get_elements(tag):
                self._set_element_color(ei)
                self._set_element_translation(ei)

        for ei in cp.get_elements('valve'):
            self._set_element_translation(ei)

        for ei in cp.get_elements('connection'):
            name = ei.text.strip()
            obj = self.scene.get_item(name)
            if obj.clear_orientation:
                ei.set('orientation', '')

        p = os.path.join(os.path.dirname(p, ), 'test.xml')
        cp.save()
Example #9
0
    def load(self, p):

        cp = CanvasParser(p)
        if cp.get_root() is None:
            return

        nodes = dict()

        # =======================================================================
        # load nodes
        # =======================================================================
        # load roots
        for t, klass in (('stage', RootNode),
                         ('spectrometer', SpectrometerNode),
                         ('valve', ValveNode),
                         ('rough_valve', ValveNode),
                         ('manual_valve', ValveNode),
                         ('turbo', PumpNode),
                         ('ionpump', PumpNode),
                         ('laser', LaserNode),
                         ('tank', TankNode),
                         ('pipette', PipetteNode),
                         ('gauge', GaugeNode),
                         ('getter', GetterNode)):
            for si in cp.get_elements(t):
                n = si.text.strip()
                if t in ('valve', 'rough_valve', 'manual_valve'):
                    o_vol = get_volume(si, tag='open_volume', default=10)
                    c_vol = get_volume(si, tag='closed_volume', default=5)
                    vol = (o_vol, c_vol)
                else:
                    vol = get_volume(si)

                node = klass(name=n, volume=vol)
                nodes[n] = node

        # =======================================================================
        # load edges
        # =======================================================================
        for tag in ('connection','elbow'):
            for ei in cp.get_elements(tag):
                sa = ei.find('start')
                ea = ei.find('end')
                vol = get_volume(ei)
                edge = Edge(volume=vol)
                s_name = ''
                if sa.text in nodes:
                    s_name = sa.text
                    sa = nodes[s_name]
                    edge.nodes.append(sa)
                    sa.add_edge(edge)

                e_name = ''
                if ea.text in nodes:
                    e_name = ea.text
                    ea = nodes[e_name]
                    # edge.b_node = ea
                    edge.nodes.append(ea)
                    ea.add_edge(edge)

                edge.name = '{}_{}'.format(s_name, e_name)

        for c in ('tee_connection', 'fork_connection'):
            for conn in cp.get_elements(c):
                left = conn.find('left')
                right = conn.find('right')
                mid = conn.find('mid')

                edge = Edge(vol=get_volume(conn))
                lt = left.text.strip()
                rt = right.text.strip()
                mt = mid.text.strip()

                ns = []
                for x in (lt, mt, rt):
                    if x in nodes:
                        ln = nodes[x]
                        edge.nodes.append(ln)
                        ln.add_edge(edge)
                        ns.append(x)

                edge.name = '-'.join(ns)

        self.nodes = nodes
Example #10
0
    def load(self, p):

        cp = CanvasParser(p)
        if cp.get_root() is None:
            return

        nodes = dict()

        # =======================================================================
        # load nodes
        # =======================================================================
        # load roots
        for t, klass in (('stage', RootNode), ('spectrometer',
                                               SpectrometerNode),
                         ('valve', ValveNode), ('rough_valve', ValveNode),
                         ('manual_valve', ValveNode), ('turbo', PumpNode),
                         ('ionpump', PumpNode), ('laser', LaserNode),
                         ('tank', TankNode), ('pipette', PipetteNode),
                         ('gauge', GaugeNode), ('getter', GetterNode)):
            for si in cp.get_elements(t):
                n = si.text.strip()
                if t in ('valve', 'rough_valve', 'manual_valve'):
                    o_vol = get_volume(si, tag='open_volume', default=10)
                    c_vol = get_volume(si, tag='closed_volume', default=5)
                    vol = (o_vol, c_vol)
                else:
                    vol = get_volume(si)

                node = klass(name=n, volume=vol)
                nodes[n] = node

        # =======================================================================
        # load edges
        # =======================================================================
        for tag in ('connection', 'elbow'):
            for ei in cp.get_elements(tag):
                sa = ei.find('start')
                ea = ei.find('end')
                vol = get_volume(ei)
                edge = Edge(volume=vol)
                s_name = ''
                if sa.text in nodes:
                    s_name = sa.text
                    sa = nodes[s_name]
                    edge.nodes.append(sa)
                    sa.add_edge(edge)

                e_name = ''
                if ea.text in nodes:
                    e_name = ea.text
                    ea = nodes[e_name]
                    # edge.b_node = ea
                    edge.nodes.append(ea)
                    ea.add_edge(edge)

                edge.name = '{}_{}'.format(s_name, e_name)

        for c in ('tee_connection', 'fork_connection'):
            for conn in cp.get_elements(c):
                left = conn.find('left')
                right = conn.find('right')
                mid = conn.find('mid')

                edge = Edge(vol=get_volume(conn))
                lt = left.text.strip()
                rt = right.text.strip()
                mt = mid.text.strip()

                ns = []
                for x in (lt, mt, rt):
                    if x in nodes:
                        ln = nodes[x]
                        edge.nodes.append(ln)
                        ln.add_edge(edge)
                        ns.append(x)

                edge.name = '-'.join(ns)

        self.nodes = nodes
Example #11
0
    def load(self, p):

        cp = CanvasParser(p)
        if cp.get_root() is None:
            return

        nodes = dict()

        #=======================================================================
        # load nodes
        #=======================================================================
        # load roots
        for t, klass in (
            ('stage', RootNode),
            ('spectrometer', SpectrometerNode),
            ('valve', ValveNode),
            ('rough_valve', ValveNode),
            ('turbo', PumpNode),
            ('ionpump', PumpNode),
            ('laser', LaserNode),
            ('tank', TankNode),
            ('pipette', PipetteNode),
            ('gauge', GaugeNode),
        ):
            for si in cp.get_elements(t):
                n = si.text.strip()
                if t in ('valve', 'rough_valve'):
                    o_vol = get_volume(si, tag='open_volume', default=10)
                    c_vol = get_volume(si, tag='closed_volume', default=5)
                    vol = (o_vol, c_vol)
                else:
                    vol = get_volume(si)

                node = klass(name=n, volume=vol)
                nodes[n] = node

        #=======================================================================
        # load edges
        #=======================================================================
        for ei in cp.get_elements('connection'):
            sa = ei.find('start')
            ea = ei.find('end')
            vol = get_volume(ei)
            edge = Edge(volume=vol)
            s_name = ''
            if sa.text in nodes:
                s_name = sa.text
                sa = nodes[s_name]
                edge.a_node = sa
                sa.add_edge(edge)

            e_name = ''
            if ea.text in nodes:
                e_name = ea.text
                ea = nodes[e_name]
                edge.b_node = ea
                ea.add_edge(edge)

            edge.name = '{}_{}'.format(s_name, e_name)

        self.nodes = nodes