Minsky
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 798 of file ravelWrap.cc.

References handleLockInfo, handleNames(), and m_ravels.

Referenced by addRavel().

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

References addHandleInfo(), handleLockInfo, and m_ravels.

791  {
792  m_ravels.push_back(ravel);
793  for (auto& i: handleLockInfo)
794  i.handleNames.resize(m_ravels.size());
795  addHandleInfo(m_ravels.back());
796  }
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:798
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 737 of file ravelWrap.cc.

References m_ravels.

738  {
739  set<string> handles;
740  for (auto& rr: m_ravels)
741  if (auto r=rr.lock())
742  {
743  auto state=r->getState();
744  for (auto& h: state.handleStates)
745  handles.insert(h.description);
746  }
747  return {handles.begin(), handles.end()};
748  }
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 611 of file ravelWrap.cc.

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

Referenced by initialBroadcast().

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

References m_ravels.

Referenced by addHandleInfo(), and setLockHandles().

763  {
764  if (auto rr=m_ravels[ravel_idx].lock())
765  return rr->handleNames();
766  return {};
767  }
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 604 of file ravelWrap.cc.

References broadcast(), and m_ravels.

605  {
606  if (!m_ravels.empty())
607  if (auto r=m_ravels.front().lock())
608  broadcast(*r);
609  }
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:611
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 750 of file ravelWrap.cc.

References m_ravels, and minsky::to_string().

751  {
752  std::vector<std::string> r;
753  int cnt=0;
754  for (auto& i: m_ravels)
755  if (auto rr=i.lock())
756  r.emplace_back(rr->tooltip().empty()? to_string(cnt++): rr->tooltip());
757  else
758  r.emplace_back("<invalid>");
759  return r;
760  }
std::vector< std::weak_ptr< Ravel > > m_ravels
Definition: ravelWrap.h:229
string to_string(CONST84 char *x)
Definition: minskyTCLObj.h:33
Here is the call graph for this function:

◆ 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 834 of file ravelWrap.cc.

References handleLockInfo, and m_ravels.

835  {
836  auto found=find_if(m_ravels.begin(), m_ravels.end(),
837  [&](const weak_ptr<Ravel>& i){
838  if (auto r=i.lock())
839  return r.get()==&ravel;
840  return false;
841  });
842  if (found==m_ravels.end()) return;
843  for (auto& i: handleLockInfo)
844  i.handleNames.erase(i.handleNames.begin()+(found-m_ravels.begin()));
845  m_ravels.erase(found);
846  if (m_ravels.size()==1)
847  if (auto r=m_ravels[0].lock())
848  r->lockGroup.reset(); // this may delete this, so should be last
849  }
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 769 of file ravelWrap.cc.

References handleLockInfo, handleNames(), and m_ravels.

770  {
771  handleLockInfo.clear();
772  std::vector<std::set<std::string>> handleNames;
773  for (auto& rp: m_ravels)
774  if (auto r=rp.lock())
775  {
776  auto names=r->handleNames();
777  handleNames.emplace_back(names.begin(), names.end());
778  }
779  else
780  handleNames.emplace_back();
781 
782  for (auto& h: handles)
783  {
784  handleLockInfo.emplace_back();
785  for (size_t i=0; i<m_ravels.size(); ++i)
786  handleLockInfo.back().handleNames.push_back(handleNames[i].contains(h)? h: "");
787  }
788  }
std::vector< std::string > handleNames(size_t ravel_idx) const
return the handle descriptions of of ravel ravel_idx in ravels
Definition: ravelWrap.cc:762
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 717 of file ravelWrap.cc.

References handleLockInfo, and m_ravels.

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