예제 #1
0
func (s *FilesTreeStore) Remove(c tr.Cursor) (prefix string, index int) {
	s.deleteSubtree(c.Path)
	var suffix string
	if strings.Contains(c.Path, ":") {
		prefix = c.Path[:strings.LastIndex(c.Path, ":")]
		suffix = c.Path[strings.LastIndex(c.Path, ":")+1:]
	} else {
		suffix = c.Path
	}
	fmt.Sscanf(suffix, "%d", &index)
	i := index
	for ok := true; ok; i++ {
		ok = s.shiftLookup(prefix, fmt.Sprintf("%d", i+1), fmt.Sprintf("%d", i))
	}
	_, ok := s.lookup[c.Path]
	if !ok {
		log.Printf("FilesTreeStore.Remove: c.Path=%s not found, decreasing\n", c.Path)
		index--
		suffix = fmt.Sprintf("%d", index)
		if len(prefix) > 0 {
			c.Path = fmt.Sprintf("%s:%d", prefix, index)
		} else {
			c.Path = fmt.Sprintf("%d", index)
		}
		log.Printf("FilesTreeStore.Remove: new c.Path=%s\n", c.Path)
		_, ok = s.lookup[c.Path]
		if !ok {
			s.currentSelection = nil
		} else {
			_, s.currentSelection, _ = s.getObjAndIterById(c.Path)
		}
	}
	return
}
예제 #2
0
파일: arch.go 프로젝트: axel-freesp/sge
func (a *arch) AddNewObject(tree tr.TreeIf, cursor tr.Cursor, obj tr.TreeElementIf) (newCursor tr.Cursor, err error) {
	if obj == nil {
		err = fmt.Errorf("arch.AddNewObject error: nil object")
		return
	}
	switch obj.(type) {
	case pf.IOTypeIf:
		t := obj.(pf.IOTypeIf)
		_, ok := a.iotypes.Find(t.Name())
		if ok {
			err = fmt.Errorf("arch.AddNewObject warning: duplicate ioType name %s (abort)\n", t.Name())
			return
		}
		a.iotypes.Append(t.(*iotype))
		cursor.Position = len(a.IOTypes()) - 1
		newCursor = tree.Insert(cursor)
		t.AddToTree(tree, newCursor)

	case pf.ProcessIf:
		p := obj.(pf.ProcessIf)
		_, ok := a.processes.Find(p.Name())
		if ok {
			err = fmt.Errorf("arch.AddNewObject warning: duplicate process name %s (abort)\n", p.Name())
			return
		}
		a.processes.Append(p.(*process))
		newCursor = tree.Insert(cursor)
		p.AddToTree(tree, newCursor)
		//log.Printf("arch.AddNewObject: successfully added process %v\n", p)

	default:
		log.Fatalf("arch.AddNewObject error: invalid type %T\n", obj)
	}
	return
}
예제 #3
0
파일: library.go 프로젝트: axel-freesp/sge
func (l *library) AddNewObject(tree tr.TreeIf, cursor tr.Cursor, obj tr.TreeElementIf) (newCursor tr.Cursor, err error) {
	if obj == nil {
		err = fmt.Errorf("library.AddNewObject error: nil object")
		return
	}
	switch obj.(type) {
	case bh.SignalTypeIf:
		t := obj.(bh.SignalTypeIf)
		ok := l.AddSignalType(t)
		if !ok {
			err = fmt.Errorf("library.AddNewObject warning: duplicate")
			return
		}
		cursor.Position = len(l.SignalTypes()) - 1
		newCursor = tree.Insert(cursor)
		t.AddToTree(tree, newCursor)

	case bh.NodeTypeIf:
		t := obj.(bh.NodeTypeIf)
		err = l.AddNodeType(t)
		if err != nil {
			err = fmt.Errorf("library.AddNewObject error: AddNodeType failed: %s", err)
			return
		}
		newCursor = tree.Insert(cursor)
		t.AddToTree(tree, newCursor)

	default:
		log.Fatalf("library.AddNewObject error: invalid type %T\n", obj)
	}
	return
}
예제 #4
0
파일: nodetype.go 프로젝트: axel-freesp/sge
func (t *nodeType) AddNewObject(tree tr.TreeIf, cursor tr.Cursor, obj tr.TreeElementIf) (newCursor tr.Cursor, err error) {
	switch obj.(type) {
	case bh.ImplementationIf:
		t.AddImplementation(obj.(bh.ImplementationIf))
		cursor.Position = len(t.Implementation()) - 1

	case bh.PortTypeIf:
		pt := obj.(bh.PortTypeIf)
		t.AddNamedPortType(pt) // adds ports of all instances, linked io-nodes in graph implementation
		// Adjust offset to insert:
		if pt.Direction() == gr.InPort {
			cursor.Position = len(t.Implementation()) + len(t.InPorts()) - 1
		} else {
			cursor.Position = -1
		}

	default:
		log.Fatalf("nodeType.AddNewObject error: invalid type %T\n", obj)
	}

	newCursor = t.treeNewObject(tree, cursor, obj)
	t.treeInstObject(tree, cursor, obj)
	return
}
예제 #5
0
파일: nodetype.go 프로젝트: axel-freesp/sge
func (t *nodeType) treeNewObject(tree tr.TreeIf, cursor tr.Cursor, obj tr.TreeElementIf) (newCursor tr.Cursor) {
	switch obj.(type) {
	case bh.ImplementationIf:
		cursor.Position = len(t.Implementation()) - 1
		newCursor = tree.Insert(cursor)
		obj.(bh.ImplementationIf).AddToTree(tree, newCursor)

	case bh.PortTypeIf:
		pt := obj.(bh.PortTypeIf)
		newCursor = tree.Insert(cursor)
		pt.AddToTree(tree, newCursor)
		for _, impl := range t.Implementation() {
			if impl.ImplementationType() == bh.NodeTypeGraph {
				// bh.NodeIf linked to outer port
				g := impl.Graph().(*signalGraphType)
				var n bh.NodeIf
				index := -len(t.Implementation())
				if pt.Direction() == gr.InPort {
					n = g.findInputNodeFromPortType(pt)
					if cursor.Position == tr.AppendCursor {
						index += len(g.InputNodes())
					}
				} else {
					n = g.findOutputNodeFromPortType(pt)
					if cursor.Position == tr.AppendCursor {
						index += len(g.InputNodes()) + len(g.OutputNodes())
					}
				}
				if n == nil {
					log.Fatalf("nodeType.AddNewObject error: invalid implementation...\n")
				}
				if cursor.Position != tr.AppendCursor {
					index += cursor.Position
				}
				gCursor := tree.CursorAt(cursor, impl)
				gCursor.Position = index
				n.AddToTree(tree, tree.Insert(gCursor))
			}
		}

	default:
		log.Fatalf("nodeType.AddNewObject error: invalid type %T\n", obj)
	}
	return
}
예제 #6
0
파일: process.go 프로젝트: axel-freesp/sge
func (p *process) AddNewObject(tree tr.TreeIf, cursor tr.Cursor, obj tr.TreeElementIf) (newCursor tr.Cursor, err error) {
	if obj == nil {
		err = fmt.Errorf("process.AddNewObject error: %v nil object", p)
		return
	}
	switch obj.(type) {
	case pf.ChannelIf:
		c := obj.(*channel)
		c.process = p
		cLinkText := c.linkText
		link := strings.Split(cLinkText, "/")
		if len(link) != 2 {
			err = fmt.Errorf("process.AddNewObject error: %v invalid link text %s (abort)\n", p, c.linkText)
			return
		}
		archlist := p.Arch().Platform().(*platform).archlist
		aa, ok := archlist.Find(link[0])
		if !ok {
			err = fmt.Errorf("process.AddNewObject error: %v invalid link text %s: no such arch (abort)\n", p, c.linkText)
			return
		}
		var pp pf.ProcessIf
		pp, ok = aa.(*arch).processes.Find(link[1])
		if !ok {
			err = fmt.Errorf("process.AddNewObject error: %v invalid link text %s: no such process (abort)\n", p, c.linkText)
			return
		}
		var l *channelList
		var dd gr.PortDirection
		var ll *channelList
		var cPos, ccPos int
		if c.Direction() == gr.InPort {
			l = &p.inChannels
			ll = &pp.(*process).outChannels
			dd = gr.OutPort
			cPos = len(l.Channels())
			ccPos = tr.AppendCursor
		} else {
			l = &p.outChannels
			ll = &pp.(*process).inChannels
			dd = gr.InPort
			cPos = tr.AppendCursor
			ccPos = len(ll.Channels())
		}
		cName := channelMakeName(c.iotype, pp)
		_, ok = l.Find(cName)
		if ok {
			err = fmt.Errorf("process.AddNewObject warning: %v duplicate %v channel name %s/%s (abort)\n",
				p, c.Direction(), c.linkText, c.iotype.Name())
			return
		}
		ccLinkText := fmt.Sprintf("%s/%s", p.Arch().Name(), p.Name())
		ccName := channelMakeName(c.iotype, p)
		_, ok = l.Find(ccName)
		_, ok = ll.Find(cName)
		if ok {
			err = fmt.Errorf("process.AddNewObject warning: %v duplicate %v channel name %s/%s on other side (abort)\n",
				pp, dd, ccLinkText, c.iotype.Name())
			return
		}
		cc := ChannelNew(dd, c.iotype, pp, ccLinkText)
		cc.link = c
		c.link = cc
		l.Append(c)
		ll.Append(cc)
		ppCursor := tree.Cursor(pp)
		if ppCursor.Position == tr.AppendCursor {
			ppCursor.Position = ccPos
		}
		newCursor = tree.Insert(ppCursor)
		cc.AddToTree(tree, newCursor)
		if cursor.Position == tr.AppendCursor {
			cursor.Position = cPos
		}
		newCursor = tree.Insert(cursor)
		c.AddToTree(tree, newCursor)
		if p.Arch().Name() != aa.Name() {
			p.Arch().(*arch).AddArchPort(c)
			aa.(*arch).AddArchPort(cc)
		}
		//log.Printf("process.AddNewObject: %v successfully added channel %v\n", p, c)

	default:
		log.Fatalf("process.AddNewObject error: invalid type %T\n", obj)
	}
	return
}