func (c *Core) Group(layer string, reply *int) error { c.Lock.Lock() defer c.Lock.Unlock() err := c.updatemetadata(layer) if err != nil { return err } //map af array of visuals, the key is the metadata/layer groups := make(map[string][]*mrclean.Visual, len(c.Visuals)) //map of the maximum size of each group rowsize := make(map[string]float64, len(c.Visuals)) for _, v := range c.Visuals { groups[v.Meta[0]] = append(groups[v.Meta[0]], v) rowsize[v.Meta[0]] = math.Max(v.Size[0], rowsize[v.Meta[0]]) } dx := c.mx + 0.05 //5 cm dy := 0.05 //c.my + 0.05 //5 cm var origins *mrclean.VisualOrigins = mrclean.NewVisualOrigins() for k, row := range groups { lastpx := -c.DispW*0.5 + dx*0.5 lastpy := c.DispH*0.5 - dy - rowsize[k]*0.5 + 0.05 //keep track of the height dy += rowsize[k] + 0.05 //sort the row the first part of teh metadaa is the same //for all the element s in the row, the user should define the //order of the rest of the metadata variables By(metaf).Sort(row) //put row by row on screen here for _, v := range row { v.Origin[0], v.Origin[1] = lastpx, lastpy //keep track of the position locally c.Visuals[v.Name].Origin = v.Origin origins.Vids = append(origins.Vids, v.ID) origins.Origins = append(origins.Origins, v.Origin) lastpx += dx } // back to the left //lastpx = -c.DispW*0.5 + dx*0.5 // next row //lastpy -= dy } //CALL var repl int = 0 //log.Printf("calling Display.SetVisualsOrigin %v\n", origins) err = client.Call("Display.SetVisualsOrigin", origins, &repl) if err != nil { *reply = -1 //log.Println("Display error setting Visuals orgin: ", err) return err } if repl == 0 { reply = &repl } else { log.Println("Something happened during Display.SetVisualsOrigin ", repl) *reply = -1 } return nil }
//Sort handle the gestures received from ths users to sort the visuals func (c *Core) Sort(layersorder string, reply *int) error { c.Lock.Lock() defer c.Lock.Unlock() err := c.updatemetadata(layersorder) if err != nil { return err } //need to copy the map in a slice to sort it //maybe this should change visuals := make([]*mrclean.Visual, 0, len(c.Visuals)) for _, v := range c.Visuals { visuals = append(visuals, v) } log.Printf("sorting: len(visuals) = %v\n", len(visuals)) //SORT By(metaf).Sort(visuals) //loop to put the visuals on screen // evenly spaced and sorted dx := c.mx + 0.05 //5 cm dy := c.my + 0.05 //5 cm var ( row float64 = 1.0 lastpx = -c.DispW*0.5 + dx*0.5 lastpy = c.DispH*0.5 - dy*0.5*row origins *mrclean.VisualOrigins = mrclean.NewVisualOrigins() ) //log.Printf("dx: %f, dy: %f\n", dx, dy) //log.Printf(" lastpx: %f lastpy: %f \n", lastpx, lastpy) for i := range visuals { visuals[i].Origin[0], visuals[i].Origin[1] = lastpx, lastpy //keep track of the position locally c.Visuals[visuals[i].Name].Origin = visuals[i].Origin //log.Println("Origin: ", visuals[i].Origin) //fmt.Println("before: ", v.rect, v.rect.Center()) //fmt.Println("after: ", v.rect, v.rect.Center()) origins.Vids = append(origins.Vids, visuals[i].ID) origins.Origins = append(origins.Origins, visuals[i].Origin) lastpx += dx //log.Printf(" lastpx+dx: %f c.DispW*0.5: %f \n", lastpx+dx, c.DispW*0.5) if lastpx+dx > c.DispW*0.5 { lastpx = -c.DispW*0.5 + dx*0.5 row += 1 lastpy -= dy //c.DispH*0.5 - dy*row //c.DispH - row*dy //log.Printf("New ROW: %f ", row) } //log.Printf(" lastpx: %f lastpy: %f \n", lastpx, lastpy) } //CALL var repl int = 0 //log.Printf("calling Display.SetVisualsOrigin %v\n", origins) err = client.Call("Display.SetVisualsOrigin", origins, &repl) if err != nil { *reply = -1 //log.Println("Display error setting Visuals orgin: ", err) return err } if repl == 0 { reply = &repl } else { log.Println("Something happened during Display.SetVisualsOrigin ", repl) *reply = -1 } //here we set the position of th evisuals locally //for _, v := range visuals{ // c.Visuals[v.Name] return nil }