A last note:
I leave the pinlabel and pinnumber visible, and the other two hidden. I
think this is how most people draw the symbols. Am I right?
Thanks,
Carlos
El dom, 29-01-2006 a las 04:30 +0100, Carlos Nieves Ónega escribió:
> Just to clarify it: I wrote a C function to add an attribute to an
> object. It is called from scheme, and it needs w_current and o_current
> pointers. I searched in the web, and now I found how to convert a
> pointer to a SCM variable.
>
> I would not want to change the behaviour of the hooks (they don't get
> w_current and o_current as parameters), so I wonder if w_current and
> o_current pointers could be passed to scheme as two variables, with
> names __wcurrent, and __ocurrent (using scm_c_define).
> These variables can be defined just before calling scm_run_hook.
> I have tried this and it works fine: when you place a new pin, the
> default attributes (pinlabel, pintype, pinnumber, and pinseq) are added
> automatically. This is configurable in system-gschemrc file. However, I
> leave it activated by default. Any thoughts/objections?
>
> Would it be interesting to set __wcurrent and __ocurrent before calling
> any other scm_run_hook function? (Just to standardize this way). I think
> it would be better...
>
> Thanks,
>
> Carlos
>
> P.D.: Ales, I suppose you want to wait a little time before making any
> changes to CVS. Let me know when the CVS can be updated again.
>
>
> El sáb, 28-01-2006 a las 23:24 +0100, Carlos Nieves Ónega escribió:
> > Hi all,
> > I'm thinking about adding some configurable default attributes to a
> > newly placed pin.
> > I thought about two options:
> > - Option 1: Load a list with name,values of attributes to be added
> > from the file gschemrc.
> > - Option 2: Write an add-pin-hook function and do it in scheme.
> >
> > By now I like option 2, but my knowledge about C interfacing to scheme
> > is limited, so I have some doubts...
> >
> > At the end of o_pin_end function I added:
> >
> > if (scm_hook_empty_p(add_pin_hook) == SCM_BOOL_F &&
> > o_current != NULL) {
> > scm_run_hook(add_pin_hook,
> > scm_cons(g_make_attrib_smob_list(w_current, o_current),
> > SCM_EOL));
> > }
> >
> > so the new hook is run. As I understand, the first two parameters are
> > w_current and o_current.
> >
> > The new hook is run, and if I put into gschemrc the following:
> >
> > (define (print-all-attributes attribute-list)
> > (for-each (lambda (attribute) (display attribute)) attribute-list))
> >
> > (add-hook! add-pin-hook print-all-attributes)
> >
> > I get nothing printed: the attribute list is empty. This isn't
> > surprising because by default, a pin has no attributes.
> >
> > Now I wrote a very basic (and untested) scheme function which calls to
> > o_attrib_add_attrib:
> >
> > SCM
> > g_add_attrib(SCM scm_wcurrent, SCM scm_object, SCM scm_newtext,
> > SCM scm_vis, SCM scm_show)
> > {
> > TOPLEVEL *w_current = (TOPLEVEL *) SCM_SMOB_DATA(scm_wcurrent);
> > OBJECT *object = (OBJECT *) SCM_SMOB_DATA (scm_object);
> > int vis, show;
> > gchar *newtext=SCM_STRING_CHARS(scm_newtext);
> >
> > vis = SCM_INUM(scm_vis);
> > show = SCM_INUM(scm_show);
> >
> > o_attrib_add_attrib (w_current, newtext, vis, show, object);
> >
> > return SCM_BOOL_T;
> >
> > }
> >
> > This function is registered in g_register.nw as:
> > scm_c_define_gsubr ("add-attribute-to-object", 5, 0, 0, g_add_attrib);
> >
> >
> > I expect to be able to call this function inside the add-pin-hook
> > function, just adding the new parameters. The problem is: how can I do
> > it? if I try to print all the arguments to the add-pin-hook function, I
> > get an empty list.
> > Even if I do:
> > (define (print-all-attributes attribute-list)
> > (display "Parameter List length: ")
> > (display (length attribute-list))
> > (display ".\n")
> > (for-each (lambda (attribute) (display attribute)) attribute-list))
> > (add-hook! add-pin-hook print-all-attributes)
> >
> > It reports a 0 elements list. Where have w_current and o_current gone?
> >
> > Any ideas?. Thanks,
> >
> > Carlos
> >
>