Minsky: 3.17.0
minsky::RavelLockGroup Class Reference

#include <ravelWrap.h>

Collaboration diagram for minsky::RavelLockGroup:
Collaboration graph

Public Member Functions

 RavelLockGroup ()
 
void addRavel (const std::weak_ptr< Ravel > &ravel)
 
const std::vector< std::weak_ptr< Ravel > > & ravels () const
 
void initialBroadcast ()
 broadcast first ravel's state to the remainder More...
 
void broadcast (const Ravel &ravel)
 broadcast state from ravel to the lock group More...
 
unsigned colour () const
 an identifying tag used to colour locked ravels on canvas More...
 
void validateLockHandleInfo ()
 checks handleLockInfo for non repeated handles, etc More...
 
std::vector< std::string > allLockHandles () const
 populate handlesToLock by all handles present in the lock group More...
 
std::vector< std::string > ravelNames () const
 return tooltips of the ravels in this lockGroup More...
 
std::vector< std::string > handleNames (size_t ravel_idx) const
 return the handle descriptions of of ravel ravel_idx in ravels More...
 
void setLockHandles (const std::vector< std::string > &handles)
 set handlesToLock to the handles in handles More...
 
void addHandleInfo (const std::weak_ptr< Ravel > &ravel)
 add ravel's handles to handleLockInfo, for a ravel stashed in m_ravels More...
 
void removeFromGroup (const Ravel &)
 

Public Attributes

std::vector< HandleLockInfohandleLockInfo
 

Private Attributes

unsigned m_colour
 
std::vector< std::weak_ptr< Ravel > > m_ravels
 

Static Private Attributes

static unsigned nextColour =1
 

Detailed Description

Definition at line 225 of file ravelWrap.h.

Constructor & Destructor Documentation

◆ RavelLockGroup()

minsky::RavelLockGroup::RavelLockGroup ( )
inline

Definition at line 231 of file ravelWrap.h.

231 {m_colour=nextColour++;}
static unsigned nextColour
Definition: ravelWrap.h:227

Member Function Documentation

◆ addHandleInfo()

void minsky::RavelLockGroup::addHandleInfo ( const std::weak_ptr< Ravel > &  ravel)

add ravel's handles to handleLockInfo, for a ravel stashed in m_ravels

Definition at line 797 of file ravelWrap.cc.

References handleLockInfo, handleNames(), and m_ravels.

Referenced by addRavel().

798  {
799  auto ravelIdx=&ravel-m_ravels.data();
800  assert(ravelIdx>=0);
801  if (ravelIdx<0 || size_t(ravelIdx)>=m_ravels.size()) return;
802  if (auto r=ravel.lock())
803  {
804  auto names=r->handleNames();
805  set<string> handleNames(names.begin(), names.end());
806  if (names.size()!=handleNames.size())
807  r->throw_error("Ambiguous handle names");
808  // add corresponding handles to what's already there
809  for (auto& hli: handleLockInfo)
810  {
811  assert(hli.handleNames.size()==m_ravels.size());
812  const set<string> lockNames(hli.handleNames.begin(), hli.handleNames.end());
813  for (auto& l: lockNames)
814  {
815  auto hn=handleNames.find(l);
816  if (hn!=handleNames.end())
817  {
818  hli.handleNames[ravelIdx]=l;
819  handleNames.erase(hn);
820  }
821  }
822  }
823  // now add in any extras
824  for (auto& h: handleNames)
825  {
826  handleLockInfo.emplace_back();
827  handleLockInfo.back().handleNames.resize(m_ravels.size());
828  handleLockInfo.back().handleNames[ravelIdx]=h;
829  }
830  }
831  }
std::vector< std::string > handleNames(size_t ravel_idx) const
return the handle descriptions of of ravel ravel_idx in ravels
Definition: ravelWrap.cc:761
std::vector< std::weak_ptr< Ravel > > m_ravels
Definition: ravelWrap.h:229
std::vector< HandleLockInfo > handleLockInfo
Definition: ravelWrap.h:240
Here is the call graph for this function:
Here is the caller graph for this function:

◆ addRavel()

void minsky::RavelLockGroup::addRavel ( const std::weak_ptr< Ravel > &  ravel)

Definition at line 789 of file ravelWrap.cc.

References addHandleInfo(), handleLockInfo, and m_ravels.

790  {
791  m_ravels.push_back(ravel);
792  for (auto& i: handleLockInfo)
793  i.handleNames.resize(m_ravels.size());
794  addHandleInfo(m_ravels.back());
795  }
std::vector< std::weak_ptr< Ravel > > m_ravels
Definition: ravelWrap.h:229
void addHandleInfo(const std::weak_ptr< Ravel > &ravel)
add ravel&#39;s handles to handleLockInfo, for a ravel stashed in m_ravels
Definition: ravelWrap.cc:797
std::vector< HandleLockInfo > handleLockInfo
Definition: ravelWrap.h:240
Here is the call graph for this function:

◆ allLockHandles()

vector< string > minsky::RavelLockGroup::allLockHandles ( ) const

populate handlesToLock by all handles present in the lock group

Definition at line 736 of file ravelWrap.cc.

References m_ravels.

737  {
738  set<string> handles;
739  for (auto& rr: m_ravels)
740  if (auto r=rr.lock())
741  {
742  auto state=r->getState();
743  for (auto& h: state.handleStates)
744  handles.insert(h.description);
745  }
746  return {handles.begin(), handles.end()};
747  }
std::vector< std::weak_ptr< Ravel > > m_ravels
Definition: ravelWrap.h:229

◆ broadcast()

void minsky::RavelLockGroup::broadcast ( const Ravel ravel)

broadcast state from ravel to the lock group

Definition at line 610 of file ravelWrap.cc.

References minsky::Ravel::getState(), handleLockInfo, and m_ravels.

Referenced by initialBroadcast().

611  {
612  vector<shared_ptr<Ravel>> lockedRavels;
613  size_t ravelIdx=m_ravels.size();
614  for (auto& i: m_ravels)
615  {
616  lockedRavels.push_back(i.lock());
617  if (lockedRavels.back().get()==&ravel)
618  ravelIdx=lockedRavels.size()-1;
619  }
620  if (ravelIdx==m_ravels.size()) return; // not in lock group
621 
622  auto sourceState=ravel.getState();
623 
624  if (handleLockInfo.empty()) // default is all handles are locked
625  {
626  for (auto& i: m_ravels)
627  if (auto r=i.lock())
628  {
629  sourceState.radius=r->radius(); // preserve radius
630  r->applyState(sourceState);
631  }
632  return;
633  }
634 
635  // reorder source handle states according to handleLockInfo
636  vector<const ravel::HandleState*> sourceHandleStates;
637  set<string> handlesAdded;
638  for (auto& i: handleLockInfo)
639  {
640  auto hs=find_if(sourceState.handleStates.begin(), sourceState.handleStates.end(),
641  [&](const ravel::HandleState& hs){return hs.description==i.handleNames[ravelIdx];});
642  if (hs!=sourceState.handleStates.end())
643  {
644  sourceHandleStates.emplace_back(&*hs);
645  if (!handlesAdded.insert(hs->description).second)
646  throw runtime_error("Multiple locks found on handle "+hs->description);
647  }
648  else
649  sourceHandleStates.emplace_back(nullptr);
650  }
651 
652  assert(sourceHandleStates.size()==handleLockInfo.size());
653 
654  for (size_t ri=0; ri<m_ravels.size(); ++ri)
655  if (auto r=m_ravels[ri].lock())
656  {
657  if (r.get()==&ravel) continue;
658  auto state=r->getState();
659  set<string> outputHandles(state.outputHandles.begin(), state.outputHandles.end());
660  for (size_t i=0; i<handleLockInfo.size(); ++i)
661  {
662  if (!sourceHandleStates[i]) continue;
663  auto& sourceHandleState=*sourceHandleStates[i];
664 
665  auto& hlInfo=handleLockInfo[i];
666  auto handleState=find_if(state.handleStates.begin(), state.handleStates.end(),
667  [&](ravel::HandleState& s){return s.description==hlInfo.handleNames[ri];});
668  if (handleState!=state.handleStates.end())
669  {
670  if (hlInfo.slicer)
671  {
672  handleState->sliceLabel=sourceHandleState.sliceLabel;
673  if (find(sourceState.outputHandles.begin(), sourceState.outputHandles.end(), sourceHandleState.description)!=sourceState.outputHandles.end())
674  // is an output handle
675  outputHandles.insert(handleState->description);
676  else
677  outputHandles.erase(handleState->description);
678  }
679  if (hlInfo.orientation)
680  {
681  handleState->x=sourceHandleState.x;
682  handleState->y=sourceHandleState.y;
683  handleState->collapsed=sourceHandleState.collapsed;
684  handleState->reductionOp=sourceHandleState.reductionOp;
685  }
686  if (hlInfo.calipers)
687  {
688  handleState->displayFilterCaliper=sourceHandleState.displayFilterCaliper;
689  handleState->minLabel=sourceHandleState.minLabel;
690  handleState->maxLabel=sourceHandleState.maxLabel;
691  }
692  if (hlInfo.order)
693  {
694  handleState->order=sourceHandleState.order;
695  handleState->customOrder=sourceHandleState.customOrder;
696  }
697  }
698  }
699  // reorder output handle list according to the source ravel output order.
700  state.outputHandles.clear();
701  for (auto& i: sourceState.outputHandles)
702  {
703  auto o=outputHandles.find(i);
704  if (o!=outputHandles.end())
705  {
706  state.outputHandles.push_back(i);
707  outputHandles.erase(o);
708  }
709  }
710  // add remaining handles in order.
711  state.outputHandles.insert(state.outputHandles.end(), outputHandles.begin(), outputHandles.end());
712  r->applyState(state);
713  }
714  }
std::vector< std::weak_ptr< Ravel > > m_ravels
Definition: ravelWrap.h:229
std::vector< HandleLockInfo > handleLockInfo
Definition: ravelWrap.h:240
Here is the call graph for this function:
Here is the caller graph for this function:

◆ colour()

unsigned minsky::RavelLockGroup::colour ( ) const
inline

an identifying tag used to colour locked ravels on canvas

Definition at line 239 of file ravelWrap.h.

239 {return m_colour;}

◆ handleNames()

std::vector< std::string > minsky::RavelLockGroup::handleNames ( size_t  ravel_idx) const

return the handle descriptions of of ravel ravel_idx in ravels

Definition at line 761 of file ravelWrap.cc.

References m_ravels.

Referenced by addHandleInfo(), and setLockHandles().

762  {
763  if (auto rr=m_ravels[ravel_idx].lock())
764  return rr->handleNames();
765  return {};
766  }
std::vector< std::weak_ptr< Ravel > > m_ravels
Definition: ravelWrap.h:229
Here is the caller graph for this function:

◆ initialBroadcast()

void minsky::RavelLockGroup::initialBroadcast ( )

broadcast first ravel's state to the remainder

Definition at line 603 of file ravelWrap.cc.

References broadcast(), and m_ravels.

604  {
605  if (!m_ravels.empty())
606  if (auto r=m_ravels.front().lock())
607  broadcast(*r);
608  }
std::vector< std::weak_ptr< Ravel > > m_ravels
Definition: ravelWrap.h:229
void broadcast(const Ravel &ravel)
broadcast state from ravel to the lock group
Definition: ravelWrap.cc:610
Here is the call graph for this function:

◆ ravelNames()

std::vector< std::string > minsky::RavelLockGroup::ravelNames ( ) const

return tooltips of the ravels in this lockGroup

Definition at line 749 of file ravelWrap.cc.

References m_ravels.

750  {
751  std::vector<std::string> r;
752  int cnt=0;
753  for (auto& i: m_ravels)
754  if (auto rr=i.lock())
755  r.emplace_back(rr->tooltip().empty()? to_string(cnt++): rr->tooltip());
756  else
757  r.emplace_back("<invalid>");
758  return r;
759  }
std::vector< std::weak_ptr< Ravel > > m_ravels
Definition: ravelWrap.h:229

◆ ravels()

const std::vector<std::weak_ptr<Ravel> >& minsky::RavelLockGroup::ravels ( ) const
inline

Definition at line 233 of file ravelWrap.h.

233 {return m_ravels;}
std::vector< std::weak_ptr< Ravel > > m_ravels
Definition: ravelWrap.h:229

◆ removeFromGroup()

void minsky::RavelLockGroup::removeFromGroup ( const Ravel ravel)

Definition at line 833 of file ravelWrap.cc.

References handleLockInfo, and m_ravels.

834  {
835  auto found=find_if(m_ravels.begin(), m_ravels.end(),
836  [&](const weak_ptr<Ravel>& i){
837  if (auto r=i.lock())
838  return r.get()==&ravel;
839  return false;
840  });
841  if (found==m_ravels.end()) return;
842  for (auto& i: handleLockInfo)
843  i.handleNames.erase(i.handleNames.begin()+(found-m_ravels.begin()));
844  m_ravels.erase(found);
845  if (m_ravels.size()==1)
846  if (auto r=m_ravels[0].lock())
847  r->lockGroup.reset(); // this may delete this, so should be last
848  }
std::vector< std::weak_ptr< Ravel > > m_ravels
Definition: ravelWrap.h:229
std::vector< HandleLockInfo > handleLockInfo
Definition: ravelWrap.h:240

◆ setLockHandles()

void minsky::RavelLockGroup::setLockHandles ( const std::vector< std::string > &  handles)

set handlesToLock to the handles in handles

Definition at line 768 of file ravelWrap.cc.

References handleLockInfo, handleNames(), and m_ravels.

769  {
770  handleLockInfo.clear();
771  std::vector<std::set<std::string>> handleNames;
772  for (auto& rp: m_ravels)
773  if (auto r=rp.lock())
774  {
775  auto names=r->handleNames();
776  handleNames.emplace_back(names.begin(), names.end());
777  }
778  else
779  handleNames.emplace_back();
780 
781  for (auto& h: handles)
782  {
783  handleLockInfo.emplace_back();
784  for (size_t i=0; i<m_ravels.size(); ++i)
785  handleLockInfo.back().handleNames.push_back(handleNames[i].contains(h)? h: "");
786  }
787  }
std::vector< std::string > handleNames(size_t ravel_idx) const
return the handle descriptions of of ravel ravel_idx in ravels
Definition: ravelWrap.cc:761
std::vector< std::weak_ptr< Ravel > > m_ravels
Definition: ravelWrap.h:229
std::vector< HandleLockInfo > handleLockInfo
Definition: ravelWrap.h:240
Here is the call graph for this function:

◆ validateLockHandleInfo()

void minsky::RavelLockGroup::validateLockHandleInfo ( )

checks handleLockInfo for non repeated handles, etc

Exceptions
iferror

Definition at line 716 of file ravelWrap.cc.

References handleLockInfo, and m_ravels.

717  {
718  vector<set<string>> checkHandleNames(m_ravels.size());
719  for (auto& hl: handleLockInfo)
720  {
721  if (hl.handleNames.size()!=m_ravels.size())
722  throw runtime_error("Insufficient data on line");
723  for (size_t i=0; i<hl.handleNames.size(); ++i)
724  {
725  auto& nm=hl.handleNames[i];
726  // non-breaking space 0xa0 not treated as space by isspace
727  if (find_if(nm.begin(), nm.end(), [](unsigned char i){return !isspace(i)&&i!=0xa0;})==nm.end())
728  continue; // disregard wholly white space strings
729  if (!checkHandleNames[i].insert(nm).second) // check for duplicated handle names in a column
730  throw runtime_error("duplicate handle name "+nm);
731  }
732  }
733  }
std::vector< std::weak_ptr< Ravel > > m_ravels
Definition: ravelWrap.h:229
std::vector< HandleLockInfo > handleLockInfo
Definition: ravelWrap.h:240

Member Data Documentation

◆ handleLockInfo

std::vector<HandleLockInfo> minsky::RavelLockGroup::handleLockInfo

◆ m_colour

unsigned minsky::RavelLockGroup::m_colour
private

Definition at line 228 of file ravelWrap.h.

◆ m_ravels

std::vector<std::weak_ptr<Ravel> > minsky::RavelLockGroup::m_ravels
private

◆ nextColour

unsigned minsky::RavelLockGroup::nextColour =1
staticprivate

Definition at line 227 of file ravelWrap.h.


The documentation for this class was generated from the following files: