Syntaxes
New location
<identifier>
+ -<identifier> reverse the sense (ie, 180 degrees off)
Existing location
- [-]<identifier> (- means reverse the sense)
+ <identifier> simply the named location
+ -<identifier> reverse the sense (ie, 180 degrees off)
+ O![-]<identifier> the location from the specified object
+ in whatever coordinate system that object
+ happens to have
+ ^O![-]<identifier> the same, but the object is flipped
+ N-S first (see `part' and `objflip')
Quantity (length/angle)
<number>[<unit>]
Angle units: d (degrees,default) r (radians)
* showlibrary lists only parts, not objects
* the -e and -E command line options distinguish parts and objects
- part N [-]O [F [A]] [FR AR ...]
+ part N [^]O [F [A]] [FR AR ...]
obj[flip] O A F [P]
Places an instance of object or part O. The loc defined inside O as
F (`formal parameter', F must be just <identifier>) is placed at
features offered by both `part' and `obj[flip]' overlap the
behaviour is identical.
- If `part N -O' or `objflip' is used, rather than `part N O' or
+ If `part N ^O' or `objflip' is used, rather than `part N O' or
`obj', then the object is placed with object-space y coordinates
negated (ie, it is mirrored so that the object's North exchanges
with South).
Scope S is
O! when defining object or part O
- N:T scope T but inside part (introduced with `part') N
- O::T scope T but inside obj (introduced with `obj[flip]') O
+ N:T scope T but inside part (introduced with `part') N } when
+ O::T scope T but inside obj (introduced with `obj[flip]') O } placing
# Data structures:
# $ctx->{CmdLog}= undef } not in defobj
# $ctx->{CmdLog}[]= [ command args ] } in defobj
-# $ctx->{LocsMade}[]= $id
+# $ctx->{LocsMade}[]{Id}= $id
+# $ctx->{LocsMade}[]{Neg}= $id
# $ctx->{Loc}{$id}{X}
# $ctx->{Loc}{$id}{Y}
# $ctx->{Loc}{$id}{A}
return $&;
}
sub cva_idex ($) {
- my ($sp,$id)=@_;
- my ($r,$d,$k,$neg,$na);
+ my ($sp)=@_;
+ my ($id,$r,$d,$k,$neg,$na,$obj_id,$vflip,$locs);
+ if ($sp =~ s/^(\^?)(\w+)\!//) {
+ $vflip= length($1);
+ $obj_id= $2;
+ die "invalid obj $obj_id in loc" unless exists $objs{$obj_id};
+ $locs= $objs{$obj_id}{Loc};
+ } else {
+ $locs= $ctx->{Loc};
+ $vflip= 0;
+ }
$neg= $sp =~ s/^\-//;
$id= cva_idstr($sp);
- die "unknown $id" unless defined $ctx->{Loc}{$id};
- $r= $ctx->{Loc}{$id};
+ die "unknown $id" unless defined $locs->{$id};
+ $r= $locs->{$id};
$d= "idex $id";
foreach $k (sort keys %$r) { $d .= " $k=$r->{$k}"; }
printf DEBUG "%s\n", $d;
+ if ($vflip) {
+ $r= { X => $r->{X}, Y => -$r->{Y}, A => -$r->{A} };
+ }
if ($neg) {
$na= $r->{A} + $pi;
$na -= 2*$pi if $na >= 2*$pi;
}
sub cva_idnew ($) {
my ($sp)=@_;
- my ($id);
+ my ($id, $neg);
+ $neg = $sp =~ s/^\-//;
$id=cva_idstr($sp);
die "duplicate $id" if exists $ctx->{Loc}{$id};
exists $ctx->{Loc}{$id}{X};
- push @{ $ctx->{LocsMade} }, $id;
+ push @{ $ctx->{LocsMade} }, { Id => $id, Neg => $neg };
return $ctx->{Loc}{$id};
}
sub cva_cmd ($) { return cva_idstr($_[0]); }
my ($part_name, $ctx_inobj, $obj, $id, $newid, $newpt);
if ($how eq Part) {
$part_name= can(\&cva_idstr);
- $how= (@al && $al[0] =~ s/^\-//) ? -1 : +1;
+ $how= (@al && $al[0] =~ s/^\^//) ? -1 : +1;
}
$obj_id= can(\&cva_idstr);
if (defined $part_name) {
$formalr_id= "-$formalr_id";
$formalr_id =~ s/^\-\-//;
}
- $formalr= cva_idex($formalr_id);
{
- local ($ctx) = $ctx_save;
- $actualr= cva_idnew($actualr_id);
- };
+ local ($ctx) = $ctx_inobj;
+ $formalr= cva_idex($formalr_id);
+ }
+ $actualr= cva_idnew($actualr_id);
%$actualr= %$formalr;
}
}
my ($cmd);
dv("cmd__do $ctx @al ",'$ctx',$ctx);
$cmd= can(\&cva_cmd);
- my ($id,$loc,$io,$ad);
+ my ($lm,$id,$loc,$io,$ad);
$io= defined $ctx->{InDefObj} ? "$ctx->{InDefObj}!" : $ctx->{InRunObj};
o("%L cmd $io $cmd @al\n");
$ctx->{LocsMade}= [ ];
&{ "cmd_$cmd" };
};
die "too many args" if @al;
- foreach $id (@{ $ctx->{LocsMade} }) {
+ foreach $lm (@{ $ctx->{LocsMade} }) {
+ $id= $lm->{Id};
$loc= $ctx->{Loc}{$id};
+ $loc->{A} += $pi if $lm->{Neg};
$ad= ang2deg($loc->{A});
- ol("%L point $io$id ".loc2dbg($loc)."\n");
+ ol("%L point $io$id ".loc2dbg($loc)." ($lm->{Neg})\n");
if ($ctx->{Draw} =~ m/[LM]/) {
ol(" gsave\n".
" $loc->{X} $loc->{Y} translate $ad rotate\n");
abs midx_m 830 500 90
part midx cross_peco_l m
-abs dem_tljp_m 200 200 0
-obj pt_peco_mr dem_tljp_m c dem_tljp_
-
-obj pt_peco_ml dem_tljp_m c dem_trjp_
-
-extend midx_tl tlj0_b_ parallel dem_tljp_b -315
-obj pt_peco_mr -tlj0_b_ b tlj0_
-extend -tlj0_c lst0_ uptoang -90 -315
-rel lst0_ lst1 0 37 180
+define(`pt_main_r',`pt_peco_mr')
+
+defobj demos
+ abs right 200 200 0
+ part main_up ^pt_main_r c right b right_main_up
+ part main_down pt_main_r c right b right_main_down
+ abs up 200 200 90
+ part main_left ^pt_main_r c up b up_main_left
+ part main_right pt_main_r c up b up_main_right
+enddef
+
+abs demos_right 200 1200 0
+part demos demos right
+
+extend midx_tr -l0_jtr_b parallel demos!right_main_up 315
+part l0_jtr ^pt_main_r b
+
+extend midx_tl -l0_jtl_b parallel demos!-right_main_down -315
+part l0_jtl pt_main_r b
+extend -l0_jtl_c -l0_lst uptoang -90 -315
+rel l0_lst l2_lst 0 -37
+rel l2_lst l3_lst 0 -37
+eof
rel lst1 lst2 0 -37
rel lst2 lst3 0 -37