CMS 3D CMS Logo

Public Member Functions | Private Member Functions | Private Attributes

FWModelContextMenuHandler Class Reference

#include <Fireworks/Core/interface/FWModelContextMenuHandler.h>

List of all members.

Public Member Functions

void addViewEntry (const char *, int, bool enabled=true)
void chosenItem (Int_t)
 ClassDef (FWModelContextMenuHandler, 0)
void colorChangeRequested (Color_t)
 FWModelContextMenuHandler (FWSelectionManager *, FWDetailViewManager *, FWColorManager *, FWGUIManager *)
void showSelectedModelContext (Int_t iX, Int_t iY, FWViewContextMenuHandlerBase *) const
 NOTE: iX and iY are in global coordinates.
virtual ~FWModelContextMenuHandler ()

Private Member Functions

void createColorPopup () const
void createModelContext () const
 FWModelContextMenuHandler (const FWModelContextMenuHandler &)
const FWModelContextMenuHandleroperator= (const FWModelContextMenuHandler &)

Private Attributes

TGMenuEntry * m_afterViewSeperator
FWColorManagerm_colorManager
FWColorPopupm_colorPopup
FWDetailViewManagerm_detailViewManager
FWGUIManagerm_guiManager
TGPopupMenu * m_modelPopup
unsigned int m_nDetailViewEntries
unsigned int m_nViewEntries
FWSelectionManagerm_selectionManager
TGMenuEntry * m_seperator
FWViewContextMenuHandlerBasem_viewHander
TGMenuEntry * m_viewSeperator
Int_t m_x
Int_t m_y

Detailed Description

Description: Controls the context menus

Usage: This file is used internally by the system

Definition at line 38 of file FWModelContextMenuHandler.h.


Constructor & Destructor Documentation

FWModelContextMenuHandler::FWModelContextMenuHandler ( FWSelectionManager iSM,
FWDetailViewManager iDVM,
FWColorManager iCM,
FWGUIManager iGM 
)
FWModelContextMenuHandler::~FWModelContextMenuHandler ( ) [virtual]

Definition at line 84 of file FWModelContextMenuHandler.cc.

References m_modelPopup.

{
   delete m_modelPopup;
}
FWModelContextMenuHandler::FWModelContextMenuHandler ( const FWModelContextMenuHandler ) [private]

Member Function Documentation

void FWModelContextMenuHandler::addViewEntry ( const char *  iEntryName,
int  iEntryIndex,
bool  enabled = true 
)

Definition at line 208 of file FWModelContextMenuHandler.cc.

References kViewOptionsMO, m_afterViewSeperator, m_modelPopup, m_nViewEntries, and m_viewSeperator.

{
   if(!m_viewSeperator) {        
      m_modelPopup->AddSeparator(m_afterViewSeperator);          
      m_viewSeperator=dynamic_cast<TGMenuEntry*>(m_modelPopup->GetListOfEntries()->Before(m_afterViewSeperator));
      assert(0!=m_viewSeperator);        
   }
 
   if(static_cast<int>(m_nViewEntries) > iEntryIndex) {
      m_modelPopup->GetEntry(iEntryIndex+kViewOptionsMO)->GetLabel()->SetString(iEntryName);
      if(enabled)
         m_modelPopup->EnableEntry(iEntryIndex+kViewOptionsMO);
      else
         m_modelPopup->DisableEntry(iEntryIndex+kViewOptionsMO);

   } else {
      assert(static_cast<int>(m_nViewEntries) == iEntryIndex);
      m_modelPopup->AddEntry(iEntryName,kViewOptionsMO+iEntryIndex,0,0,m_viewSeperator);

      if (enabled)
         m_modelPopup->EnableEntry(kViewOptionsMO+iEntryIndex);
      else
         m_modelPopup->DisableEntry(kViewOptionsMO+iEntryIndex);

      ++m_nViewEntries;
   }

}
void FWModelContextMenuHandler::chosenItem ( Int_t  iChoice)

Definition at line 118 of file FWModelContextMenuHandler.cc.

References FWColorManager::backgroundColorIndex(), asciidump::cmd, colors, gather_cfg::cout, createColorPopup(), FWDetailViewManager::detailViewsFor(), FWColorManager::fillLimitedColors(), getHLTprescales::index, FWDisplayProperties::isVisible(), FWColorManager::kBlackIndex, kOpenCollectionControllerMO, kOpenDetailViewMO, kOpenObjectControllerMO, kPrint, kSetColorMO, kSetVisibleMO, kViewOptionsMO, m_colorManager, m_colorPopup, m_detailViewManager, m_guiManager, m_selectionManager, m_viewHander, m_x, m_y, python::connectstrParser::o, FWDetailViewManager::openDetailViewFor(), FWColorPopup::PlacePopup(), FWColorPopup::ResetColors(), FWViewContextMenuHandlerBase::select(), FWSelectionManager::selected(), FWColorPopup::SetName(), FWColorPopup::SetSelection(), FWGUIManager::showEDIFrame(), and FWGUIManager::showModelPopup().

{
   assert(!m_selectionManager->selected().empty());
   switch (iChoice) {
      case kSetVisibleMO:
      {
         FWModelId id = *(m_selectionManager->selected().begin());
         const FWDisplayProperties& props = id.item()->modelInfo(id.index()).displayProperties();
         for_each(m_selectionManager->selected().begin(),
                  m_selectionManager->selected().end(), 
                  change_visibility(!props.isVisible())
                  );
         break;
      }
      case kSetColorMO:
      {
         FWModelId id = *(m_selectionManager->selected().begin());
         createColorPopup();
         m_colorPopup->SetName("Selected");
         std::vector<Color_t> colors;
         m_colorManager->fillLimitedColors(colors);
         m_colorPopup->ResetColors(colors, m_colorManager->backgroundColorIndex()==FWColorManager::kBlackIndex);
         m_colorPopup->SetSelection(id.item()->modelInfo(id.index()).displayProperties().color());
         m_colorPopup->PlacePopup(m_x, m_y, m_colorPopup->GetDefaultWidth(), m_colorPopup->GetDefaultHeight());
         break;
      }
      case kPrint:
      {
         using namespace Reflex;
         FWModelId id = *(m_selectionManager->selected().begin());
         Type rtype(ROOT::Reflex::Type::ByName(id.item()->modelType()->GetName()));
         Object o(rtype, const_cast<void *>(id.item()->modelData(id.index())));

         // void* xx = &std::cout;
         //const std::vector<void*> j(1, xx);
         //Member m = rtype.FunctionMemberByName("print",Type(Type::ByName("void (std::ostream&)"), CONST), 0 ,INHERITEDMEMBERS_ALSO );
         //m.Invoke(o, 0, j);

         const char* cmd  = Form("FWGUIManager::OStream() << *(%s*)%p ;",  id.item()->modelType()->GetName(), (void*)id.item()->modelData(id.index()));
         //const char* cmd  = Form("*((std::ostream*)%p) << (%s*)%p ;", (void*)(&std::cout), id.item()->modelType()->GetName(), (void*)id.item()->modelData(id.index()));
         std::cout << cmd << std::endl;
         gROOT->ProcessLine(cmd);


         break;
      }
      case kOpenObjectControllerMO:
      {
         m_guiManager->showModelPopup();
         break;
      }
      case kOpenCollectionControllerMO:
      {
         m_guiManager->showEDIFrame();
         break;
      }
      case kOpenDetailViewMO:
      case kViewOptionsMO:
      default:
      {
         if(iChoice>=kViewOptionsMO) {
            assert(0!=m_viewHander);
            m_viewHander->select(iChoice-kViewOptionsMO, *(m_selectionManager->selected().begin()), m_x, m_y);
         }else {
            assert(iChoice<kOpenObjectControllerMO);
            assert(m_selectionManager->selected().size()==1);
            std::vector<std::string> viewChoices = m_detailViewManager->detailViewsFor(*(m_selectionManager->selected().begin()));
            assert(0!=viewChoices.size());
            m_detailViewManager->openDetailViewFor(*(m_selectionManager->selected().begin()),viewChoices[iChoice-kOpenDetailViewMO]) ;
         }
         break;
      }
      break;
   }
}
FWModelContextMenuHandler::ClassDef ( FWModelContextMenuHandler  ,
 
)
void FWModelContextMenuHandler::colorChangeRequested ( Color_t  color)

Definition at line 195 of file FWModelContextMenuHandler.cc.

References m_selectionManager, FWSelectionManager::selected(), and FWDisplayProperties::setColor().

{
   for(std::set<FWModelId>::const_iterator it =m_selectionManager->selected().begin(),
       itEnd = m_selectionManager->selected().end();
       it != itEnd;
       ++it) {
      FWDisplayProperties changeProperties = it->item()->modelInfo(it->index()).displayProperties();
      changeProperties.setColor(color);
      it->item()->setDisplayProperties(it->index(), changeProperties);
   }
}
void FWModelContextMenuHandler::createColorPopup ( ) const [private]

Definition at line 346 of file FWModelContextMenuHandler.cc.

References colors, FWColorManager::fillLimitedColors(), FWColorPopup::InitContent(), m_colorManager, and m_colorPopup.

Referenced by chosenItem().

{
   if(0==m_colorPopup) {
      std::vector<Color_t> colors;
      m_colorManager->fillLimitedColors(colors);
      
      m_colorPopup = new FWColorPopup(gClient->GetDefaultRoot(), colors.front());
      m_colorPopup->InitContent("", colors);
      m_colorPopup->Connect("ColorSelected(Color_t)","FWModelContextMenuHandler", const_cast<FWModelContextMenuHandler*>(this), "colorChangeRequested(Color_t)");
   }
}
void FWModelContextMenuHandler::createModelContext ( ) const [private]

Definition at line 321 of file FWModelContextMenuHandler.cc.

References kOpenCollectionControllerMO, kOpenDetailView, kOpenDetailViewMO, kOpenObjectControllerMO, kPrint, kSetColorMO, kSetVisibleMO, m_afterViewSeperator, m_modelPopup, m_nDetailViewEntries, and m_seperator.

Referenced by showSelectedModelContext().

{
   if(0==m_modelPopup) {
      m_modelPopup = new FWPopupMenu();
      
      m_modelPopup->AddEntry("Set Visible",kSetVisibleMO);
      m_modelPopup->AddEntry("Set Color ...",kSetColorMO);
      m_modelPopup->AddEntry("Print ...",kPrint);
      m_modelPopup->AddEntry(kOpenDetailView,kOpenDetailViewMO);
      m_nDetailViewEntries=1;
      m_modelPopup->AddSeparator();
      m_seperator = dynamic_cast<TGMenuEntry*>(m_modelPopup->GetListOfEntries()->Last());
      assert(0!=m_seperator);
      m_modelPopup->AddEntry("Open Object Controller ...",kOpenObjectControllerMO);
      m_afterViewSeperator = dynamic_cast<TGMenuEntry*>(m_modelPopup->GetListOfEntries()->Last());
      m_modelPopup->AddEntry("Open Collection Controller ...",kOpenCollectionControllerMO);

      m_modelPopup->Connect("Activated(Int_t)",
                            "FWModelContextMenuHandler",
                            const_cast<FWModelContextMenuHandler*>(this),
                            "chosenItem(Int_t)");
   }
}
const FWModelContextMenuHandler& FWModelContextMenuHandler::operator= ( const FWModelContextMenuHandler ) [private]
void FWModelContextMenuHandler::showSelectedModelContext ( Int_t  iX,
Int_t  iY,
FWViewContextMenuHandlerBase iHandler 
) const

NOTE: iX and iY are in global coordinates.

Definition at line 240 of file FWModelContextMenuHandler.cc.

References FWViewContextMenuHandlerBase::addTo(), createModelContext(), FWDetailViewManager::detailViewsFor(), i, getHLTprescales::index, FWDisplayProperties::isVisible(), kOpenDetailView, kOpenDetailViewMO, kPrint, kSetVisibleMO, kViewOptionsMO, m_detailViewManager, m_modelPopup, m_nDetailViewEntries, m_nViewEntries, m_selectionManager, m_seperator, m_viewHander, m_viewSeperator, m_x, m_y, python::connectstrParser::o, and FWSelectionManager::selected().

Referenced by FWGUIManager::showSelectedModelContextMenu().

{
   m_viewHander=iHandler;
   assert(!m_selectionManager->selected().empty());
   createModelContext();

   //setup the menu based on this object
   FWModelId id = *(m_selectionManager->selected().begin());
   const FWDisplayProperties& props = id.item()->modelInfo(id.index()).displayProperties();
   if(props.isVisible()) {
      m_modelPopup->CheckEntry(kSetVisibleMO);
   }else {
      m_modelPopup->UnCheckEntry(kSetVisibleMO);
   }


   if( m_selectionManager->selected().size()==1 ) {
      {
         using namespace Reflex;
         ROOT::Reflex::Type rtype(ROOT::Reflex::Type::ByName(id.item()->modelType()->GetName()));
         ROOT::Reflex::Object o(rtype, const_cast<void *>(id.item()->modelData(id.index())));
         EMEMBERQUERY inh =  INHERITEDMEMBERS_ALSO;
         if ( rtype.FunctionMemberByName("print",Type(Type::ByName("void (std::ostream&)"), CONST), 0 , inh))
         {
            m_modelPopup->EnableEntry(kPrint);
            // std::cout <<  "Enable " <<std::endl;
         }
         else
         {           
            m_modelPopup->DisableEntry(kPrint);
            // printf("Disable print \n");
         }         
      }
      //add the detail view entries
      std::vector<std::string> viewChoices = m_detailViewManager->detailViewsFor(*(m_selectionManager->selected().begin()));
      if(viewChoices.size()>0) {
         if(m_nDetailViewEntries < viewChoices.size()) {
            for(unsigned int index = m_nDetailViewEntries;
                index != viewChoices.size();
                ++index) {
               m_modelPopup->AddEntry(kOpenDetailView,kOpenDetailViewMO+index,0,0,m_seperator);
            }
            m_nDetailViewEntries=viewChoices.size();
         }
         const std::string kStart("Open ");
         const std::string kEnd(" Detail View ...");
         for(unsigned int index=0; index != viewChoices.size(); ++index) {
            m_modelPopup->GetEntry(index+kOpenDetailViewMO)->GetLabel()->SetString((kStart+viewChoices[index]+kEnd).c_str());
            m_modelPopup->EnableEntry(index+kOpenDetailViewMO);
         }
         for(unsigned int i =viewChoices.size(); i <m_nDetailViewEntries; ++i) {
            m_modelPopup->HideEntry(kOpenDetailViewMO+i);
         }
         
      } else {
         for(unsigned int i =0; i <m_nDetailViewEntries; ++i) {
            m_modelPopup->HideEntry(kOpenDetailViewMO+i);
         }
      }
   } else {
      for(unsigned int i =0; i <m_nDetailViewEntries; ++i) {
         m_modelPopup->HideEntry(kOpenDetailViewMO+i);
      }
   }
   //add necessary entries from the view
   m_modelPopup->DeleteEntry(m_viewSeperator);
   m_viewSeperator=0;

   for(unsigned int i=0; i<m_nViewEntries; ++i) {
      m_modelPopup->HideEntry(kViewOptionsMO+i);
   }
   if(m_viewHander) {
      m_viewHander->addTo(const_cast<FWModelContextMenuHandler&>(*this), *(m_selectionManager->selected().begin()));
   }
   
   m_x=iX;
   m_y=iY;
   m_modelPopup->PlaceMenu(iX,iY,false,true);
}

Member Data Documentation

TGMenuEntry* FWModelContextMenuHandler::m_afterViewSeperator [mutable, private]

Definition at line 76 of file FWModelContextMenuHandler.h.

Referenced by addViewEntry(), and createModelContext().

Definition at line 72 of file FWModelContextMenuHandler.h.

Referenced by chosenItem(), and createColorPopup().

Definition at line 69 of file FWModelContextMenuHandler.h.

Referenced by chosenItem(), and createColorPopup().

Definition at line 71 of file FWModelContextMenuHandler.h.

Referenced by chosenItem(), and showSelectedModelContext().

Definition at line 73 of file FWModelContextMenuHandler.h.

Referenced by chosenItem().

TGPopupMenu* FWModelContextMenuHandler::m_modelPopup [mutable, private]
unsigned int FWModelContextMenuHandler::m_nDetailViewEntries [mutable, private]

Definition at line 79 of file FWModelContextMenuHandler.h.

Referenced by createModelContext(), and showSelectedModelContext().

unsigned int FWModelContextMenuHandler::m_nViewEntries [mutable, private]

Definition at line 80 of file FWModelContextMenuHandler.h.

Referenced by addViewEntry(), and showSelectedModelContext().

TGMenuEntry* FWModelContextMenuHandler::m_seperator [mutable, private]

Definition at line 74 of file FWModelContextMenuHandler.h.

Referenced by createModelContext(), and showSelectedModelContext().

Definition at line 81 of file FWModelContextMenuHandler.h.

Referenced by chosenItem(), and showSelectedModelContext().

TGMenuEntry* FWModelContextMenuHandler::m_viewSeperator [mutable, private]

Definition at line 75 of file FWModelContextMenuHandler.h.

Referenced by addViewEntry(), and showSelectedModelContext().

Int_t FWModelContextMenuHandler::m_x [mutable, private]

Definition at line 77 of file FWModelContextMenuHandler.h.

Referenced by chosenItem(), and showSelectedModelContext().

Int_t FWModelContextMenuHandler::m_y [mutable, private]

Definition at line 78 of file FWModelContextMenuHandler.h.

Referenced by chosenItem(), and showSelectedModelContext().