Re: gEDA-user: Please test updates to auto-uref.scm

2011-06-22 Thread Kai-Martin Knaak
Krzysztof Kościuszkiewicz wrote:

> Thanks for the comments, it's now in git HEAD.
> 
:^)

---<)kaimartin(>---
-- 
Kai-Martin Knaak
Email: k...@familieknaak.de
Öffentlicher PGP-Schlüssel:
http://pool.sks-keyservers.net:11371/pks/lookup?search=0x6C0B9F53



___
geda-user mailing list
geda-user@moria.seul.org
http://www.seul.org/cgi-bin/mailman/listinfo/geda-user


Re: gEDA-user: Please test updates to auto-uref.scm

2011-06-22 Thread Krzysztof Kościuszkiewicz
Thanks for the comments, it's now in git HEAD.

-- 
Krzysztof Kościuszkiewicz
"Simplicity is the ultimate sophistication" -- Leonardo da Vinci


___
geda-user mailing list
geda-user@moria.seul.org
http://www.seul.org/cgi-bin/mailman/listinfo/geda-user


Re: gEDA-user: Please test updates to auto-uref.scm

2011-06-17 Thread Kai-Martin Knaak
Krzysztof Kościuszkiewicz wrote:

>> Please add this to the system-gschemrc:
>>
>> /--
(..snip...)
>> \-
> 
> My patch contains something like this

Except for the first line, the text was taken from your patch ;-)

> - I have provided a separate
> function for changing this value because new Guile versions do not
> allow for redefinition of values.

Ah. I did not get what auto-uref-set-page-offset was good for.
So the system-gschemrc addition would be:

/---
;; Set the value of page-offset for auto number on insert.
;; Refdeses will be numbered from integer multiples of page-offset,
;; depending on the lowest refdes value found on the page.
;; If lowest value is 323 and page offset is 100, then next refdes
;; will be 301.
;; Setting to 0 disables the feature.

(auto-uref-set-page-offset 100)
\---

I think, it is reasonable to set this value to 100 by default. This
covers probably most use cases. 

---<)kaimartin(>---
-- 
Kai-Martin Knaak
Email: k...@familieknaak.de
Öffentlicher PGP-Schlüssel:
http://pool.sks-keyservers.net:11371/pks/lookup?search=0x6C0B9F53



___
geda-user mailing list
geda-user@moria.seul.org
http://www.seul.org/cgi-bin/mailman/listinfo/geda-user


Re: gEDA-user: Please test updates to auto-uref.scm

2011-06-16 Thread Krzysztof Kościuszkiewicz
2011/6/16 Kai-Martin Knaak :

>> Comments & ideas welcome.
>
> Please add this to the system-gschemrc:
>
> /--
> ;; Define value of page-offset for auto number on insert.
> ;; Refdeses will be numbered from integer multiples of page-offset,
> ;; depending on the lowest refdes value found on the page.
> ;; If lowest value is 323 and page offset is 100, then next refdes
> ;; will be 301.
> ;; Setting to 0 disables the feature.
>
> (define auto-uref-page-offset 100)
> \-

My patch contains something like this - I have provided a separate
function for changing this value because new Guile versions do not
allow for redefinition of values.

Thanks for the comments.
-- 
Krzysztof Kościuszkiewicz
"Simplicity is the ultimate sophistication" -- Leonardo da Vinci


___
geda-user mailing list
geda-user@moria.seul.org
http://www.seul.org/cgi-bin/mailman/listinfo/geda-user


Re: gEDA-user: Please test updates to auto-uref.scm

2011-06-16 Thread Kai-Martin Knaak
Krzysztof Kościuszkiewicz wrote:


> Script requires recent modifications to libgeda, so test with git HEAD.

Done. It works nicely!


> Comments & ideas welcome.

Please add this to the system-gschemrc:

/--
;; Define value of page-offset for auto number on insert.
;; Refdeses will be numbered from integer multiples of page-offset,
;; depending on the lowest refdes value found on the page.
;; If lowest value is 323 and page offset is 100, then next refdes
;; will be 301.
;; Setting to 0 disables the feature.

(define auto-uref-page-offset 100)
\-

---<)kaimartin(>---
-- 
Kai-Martin Knaak  tel: +49-511-762-2895
Universität Hannover, Inst. für Quantenoptik  fax: +49-511-762-2211 
Welfengarten 1, 30167 Hannover   http://www.iqo.uni-hannover.de
GPG key:http://pgp.mit.edu:11371/pks/lookup?search=Knaak+kmk&op=get



___
geda-user mailing list
geda-user@moria.seul.org
http://www.seul.org/cgi-bin/mailman/listinfo/geda-user


gEDA-user: Please test updates to auto-uref.scm

2011-06-15 Thread Krzysztof Kościuszkiewicz
Hello,

Taking advice from Peter B I have implemented some changes to the
auto-uref script.  It does not cache refdeses anymore, and allows
refdes reuse after deleting components from the schematic.

Another change allows to specify refdes numbering offset that is applied
automatically - for example:

Page contains R10, R121 and R33, offset set to 100.
Resistors will be numbered: R1, R2, R3...

Page contains R123, R223, R102, offset set to 100.
Resistors will be numbered: R101, R102, R103...

Script requires recent modifications to libgeda, so test with git HEAD.

Comments & ideas welcome.
-- 
Krzysztof Kościuszkiewicz
"Simplicity is the ultimate sophistication" -- Leonardo da Vinci
;; gEDA - GPL Electronic Design Automation
;; gschem - gEDA Schematic Capture
;; Copyright (C) 1998-2010 Ales Hvezda
;; Copyright (C) 1998-2010 gEDA Contributors (see ChangeLog for details)
;;
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2 of the License, or
;; (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program; if not, write to the Free Software
;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

(use-modules (ice-9 regex) (srfi srfi-1))

(define auto-uref-page-offset 0)

;; Redefine value of page-offset.
;; Refdeses will be numbered from integer multiples of page-offset,
;; depending on the lowest refdes value found on the page.
;; If lowest value is 323 and page offset is 100, then next refdes
;; will be 301.
;; Setting to 0 disables the feature.
(define (auto-uref-set-page-offset new-offset)
  (set! auto-uref-page-offset new-offset))

;; Modify attributes of an object to assign next unused refdes value
(define (auto-uref attribs)

  ; Return (prefix . number) on match or #f on failure
  (define (split-value value)
(let ((match (string-match "^([A-Za-z]+)([0-9]+)$" value)))
  (if match
(cons (match:substring match 1)
  (string->number (match:substring match 2)))
#f)))

  ; Extract prefix from a refdes attribute value
  (define (get-prefix value)
(let ((prefix (string-match "^[A-Za-z]+" value)))
  (if (= 0 (match:end prefix))
  #f
  (match:substring prefix

  ; Filter non-inherited refdes values
  (define (refdes-attrs attribs)
(filter (lambda (a)
  (and
(not (attrib-inherited? a))
(string=? "refdes" (car (get-attribute-name-value a)
attribs))

  ; Extract numbers from refdeses that have given prefix
  (define (extract-numbers object prefix)
(let* ((refdeses (refdes-attrs (get-object-attributes object)))
   (vals (map (lambda (a)
(cdr (get-attribute-name-value a)))
  refdeses))
   (prefix-numbers (filter-map split-value vals))
   (numbers (filter-map (lambda (n.v)
  (if (string=? prefix (car n.v))
  (cdr n.v)
  #f))
prefix-numbers)))
  numbers))

  ; Collect all numbers associated with prefix on current page
  (define (collect-all-numbers prefix)
(let ((objects (get-objects-in-page (get-current-page
  (concatenate (map (lambda (o)
  (extract-numbers o prefix))
objects

  ; Return first number not present in used greater or equal to minimum
  (define (find-first-unused used minimum)
(define (go n xs)
  (cond ((null? xs) n)
((< n (car xs)) n)
((= n (car xs)) (go (1+ n) (cdr xs)))
(else (go n (cdr xs)
(go minimum used))

  ; Do the work - first check if attributes contain refdes with prefix
  (let* ((refdeses (refdes-attrs attribs))
 (refdes (if (null? refdeses)
 #f
 (car refdeses)))
 (prefix (if refdes
 (get-prefix (cdr (get-attribute-name-value refdes)))
 #f)))
(if prefix
(let* ((used-nums (sort-list (collect-all-numbers prefix) <))
   ; minimum value considering the page-offset
   (min-num (if (or
  (null? used-nums)
  (<= auto-uref-page-offset 0))
0
(* (floor (/ (car used-nums)
 auto-uref-page-offset))
   auto-uref-page-offset)))
   ; next refde