9 #ifndef IMPRMF_SIMPLE_LINKS_H
10 #define IMPRMF_SIMPLE_LINKS_H
12 #include <IMP/rmf/rmf_config.h>
19 #include <RMF/SetCurrentFrame.h>
20 #include <RMF/names.h>
21 #include <RMF/decorators.h>
23 IMPRMF_BEGIN_NAMESPACE
26 class SimpleLoadLink:
public LoadLink {
27 base::Vector<base::Pointer<O> > os_;
34 (RMF::FileConstHandle fh),,
36 for (
unsigned int i=0; i< os_.size(); ++i) {
37 do_load_one(fh.get_node_from_id(nhs_[i]), os_[i]);
45 nhs_.push_back(nh.get_id());
46 set_association(nh, o,
true);
51 (RMF::NodeConstHandle nh), ,=0);
56 base::Vector<base::Pointer<O> > create(RMF::NodeConstHandle rt) {
58 RMF::SetCurrentFrame sf(rt.get_file(), 0);
59 RMF::NodeConstHandles ch= rt.get_children();
60 base::Vector<base::Pointer<O> > ret;
61 for (
unsigned int i=0; i< ch.size(); ++i) {
65 base::Pointer<O> o=do_create(ch[i]);
68 o->set_was_used(
true);
73 void link(RMF::NodeConstHandle rt,
74 const base::Vector<base::Pointer<O> > &ps) {
76 RMF::SetCurrentFrame sf(rt.get_file(), 0);
78 RMF::NodeConstHandles ch= rt.get_children();
80 for (
unsigned int i=0; i< ch.size(); ++i) {
84 if (ps.size() <=
static_cast<unsigned int>(links)) {
85 IMP_THROW(
"There are too many matching hierarchies in the rmf to "
86 <<
"link against " << ps, ValueException);
88 add_link(ps[links], ch[i]);
89 ps[links]->set_was_used(
true);
90 do_add_link(ps[links], ch[i]);
95 "Didn't find enough matching things.");
97 "Didn't find enough matching things. Found "
98 << links <<
" wanted " << ps.size());
105 class SimpleSaveLink:
public SaveLink {
106 base::Vector<base::Pointer<O> > os_;
109 virtual void do_save_one(O *o,
110 RMF::NodeHandle nh) = 0;
111 void do_save(RMF::FileHandle fh) {
112 for (
unsigned int i=0; i< os_.size(); ++i) {
113 os_[i]->set_was_used(
true);
116 do_save_one(os_[i], fh.get_node_from_id(nhs_[i]));
119 virtual void do_add(O *o, RMF::NodeHandle c) {
122 virtual RMF::NodeType get_type(O*o)
const = 0;
123 void add_link(O *o, RMF::NodeConstHandle nh) {
125 nhs_.push_back(nh.get_id());
126 set_association(nh, o,
true);
128 SimpleSaveLink(std::string name): SaveLink(name) {}
130 void add(RMF::NodeHandle parent,
131 const base::Vector<base::Pointer<O> > &os) {
133 RMF::FileHandle file = parent.get_file();
134 RMF::AliasFactory af(file);
135 RMF::SetCurrentFrame sf(parent.get_file(), RMF::ALL_FRAMES);
136 for (
unsigned int i=0; i< os.size(); ++i) {
137 std::string nicename= RMF::get_as_node_name(os[i]->get_name());
138 if (get_has_associated_node(file, os[i])) {
139 RMF::NodeHandle c= parent.add_child(nicename,
141 af.get(c).set_aliased(get_node_from_association(file, os[i]));
143 RMF::NodeHandle c= parent.add_child(nicename,
146 os[i]->set_was_used(
true);