diff --git a/src/proc/mobject/session.hpp b/src/proc/mobject/session.hpp index 72a213907..4bab5f285 100644 --- a/src/proc/mobject/session.hpp +++ b/src/proc/mobject/session.hpp @@ -129,14 +129,14 @@ namespace mobject { TimelineAccess timelines; ///< collection of timelines (top level) SequenceAccess sequences; ///< collection of sequences - virtual bool isValid () = 0; - virtual MObjectRef attach (PMO& placement) = 0; - virtual bool detach (PMO& placement) = 0; + virtual bool isValid () = 0; + virtual MObjectRef attach (PMO const& placement) = 0; + virtual bool detach (PMO const& placement) = 0; - virtual MObjectRef getRoot() = 0; + virtual MObjectRef getRoot() = 0; - virtual session::PFix& getFixture () = 0; - virtual void rebuildFixture () = 0; + virtual session::PFix& getFixture () = 0; + virtual void rebuildFixture () = 0; }; diff --git a/src/proc/mobject/session/binding.cpp b/src/proc/mobject/session/binding.cpp index 955d94149..eac8d70ea 100644 --- a/src/proc/mobject/session/binding.cpp +++ b/src/proc/mobject/session/binding.cpp @@ -32,7 +32,7 @@ namespace session { : boundSequence_(sequence_to_bind) { throwIfInvalid(); - UNIMPLEMENTED ("what additionally to do when binding a sequence??"); + TODO ("what additionally to do when binding a sequence??"); } diff --git a/src/proc/mobject/session/query-focus.hpp b/src/proc/mobject/session/query-focus.hpp index 1fed6da2a..3dfe9ba04 100644 --- a/src/proc/mobject/session/query-focus.hpp +++ b/src/proc/mobject/session/query-focus.hpp @@ -27,6 +27,7 @@ #include "proc/mobject/session/scope-path.hpp" #include "proc/mobject/session/scope-query.hpp" #include "proc/mobject/session/scope-locator.hpp" +#include "proc/mobject/placement-ref.hpp" #include #include @@ -91,6 +92,7 @@ namespace session { QueryFocus(); ScopePath const& currentPath() const; + RefPlacement currentPoint() const; operator Scope() const; operator string() const; @@ -144,6 +146,15 @@ namespace session { return *focus_; } + /** @return placement-ref to the object the + * QueryFocus is currently pointing at + */ + inline RefPlacement + QueryFocus::currentPoint() const + { + return RefPlacement (focus_->getLeaf().getTop()); + } + /** discover depth-first any matching object * within \em current focus. Resolution is diff --git a/src/proc/mobject/session/session-impl.cpp b/src/proc/mobject/session/session-impl.cpp index becf042f2..6ce106049 100644 --- a/src/proc/mobject/session/session-impl.cpp +++ b/src/proc/mobject/session/session-impl.cpp @@ -23,10 +23,13 @@ #include "proc/mobject/session/session-impl.hpp" #include "proc/mobject/session/mobjectfactory.hpp" +#include "proc/mobject/session/query-focus.hpp" #include "proc/mobject/placement.hpp" #include "proc/mobject/mobject.hpp" #include "lib/error.hpp" +using namespace lumiera; + namespace mobject { namespace session { @@ -63,7 +66,7 @@ namespace session { } catch (...) { - throw lumiera::error::Fatal ("unexpected exception while clearing the session"); ///////////TODO still required?? + throw error::Fatal ("unexpected exception while clearing the session"); ///////////TODO still required?? } } @@ -75,25 +78,58 @@ namespace session { } + + /** attach a copy within the scope + * of the current QueryFocus point + * @return reference to the newly created + * instance (placement) which was attached + * below the position given by current focus + */ MObjectRef - SessionImpl::attach (PMO& placement) + SessionImpl::attach (PMO const& placement) { - UNIMPLEMENTED ("add Placement to the current Session"); + MObjectRef newAttachedInstance; + RefPlacement attachmentPoint = QueryFocus().currentPoint(); + newAttachedInstance.activate( + contents_.insert (placement, attachmentPoint)); + return newAttachedInstance; } + /** detach the denoted object (placement) from model, + * together with any child objects contained in the + * scope of this placement. + * @note as a sideeffect, the current QueryFocus + * is moved to the scope containing the + * object to be removed + * @throw error::Invalid when attempting to kill root + * @return \c true if actually removing something + */ bool - SessionImpl::detach (PMO& placement) + SessionImpl::detach (PMO const& placement) { - UNIMPLEMENTED ("search and remove a given Placement from current Session"); - return false; // TODO + bool is_known = contents_.contains (placement); + if (is_known) + { + if (Scope(placement).isRoot()) + throw error::Invalid ("Can't detach the model root." + , LUMIERA_ERROR_INVALID_SCOPE); + + QueryFocus currentFocus; + currentFocus.attach (Scope(placement).getParent()); + contents_.clear (placement); + } + ENSURE (!contents_.contains (placement)); + return is_known; } MObjectRef SessionImpl::getRoot() { - UNIMPLEMENTED ("access and return the model root, packaged as MObject-ref"); + MObjectRef refRoot; + refRoot.activate (contents_.getRoot()); + return refRoot; } diff --git a/src/proc/mobject/session/session-impl.hpp b/src/proc/mobject/session/session-impl.hpp index e0bec4767..c741bde80 100644 --- a/src/proc/mobject/session/session-impl.hpp +++ b/src/proc/mobject/session/session-impl.hpp @@ -84,8 +84,8 @@ namespace session { /* ==== Session API ==== */ virtual bool isValid (); - virtual MObjectRef attach (PMO& placement); - virtual bool detach (PMO& placement); + virtual MObjectRef attach (PMO const& placement); + virtual bool detach (PMO const& placement); virtual MObjectRef getRoot();