ToolBarItem* StdWorkbench::setupToolBars() const { ToolBarItem* root = new ToolBarItem; // File ToolBarItem* file = new ToolBarItem( root ); file->setCommand("File"); *file << "Std_New" << "Std_Open" << "Std_Save" << "Std_Print" << "Separator" << "Std_Cut" << "Std_Copy" << "Std_Paste" << "Separator" << "Std_Undo" << "Std_Redo" << "Separator" << "Std_Refresh" << "Separator" << "Std_Workbench" << "Std_WhatsThis"; // Macro ToolBarItem* macro = new ToolBarItem( root ); macro->setCommand("Macro"); *macro << "Std_DlgMacroRecord" << "Std_MacroStopRecord" << "Std_DlgMacroExecute" << "Std_DlgMacroExecuteDirect"; // View ToolBarItem* view = new ToolBarItem( root ); view->setCommand("View"); *view << "Std_ViewFitAll" << "Separator" << "Std_ViewAxo" << "Separator" << "Std_ViewFront" << "Std_ViewRight" << "Std_ViewTop" << "Separator" << "Std_ViewRear" << "Std_ViewLeft" << "Std_ViewBottom" << "Separator" << "Std_MeasureDistance" ; return root; }
void Workbench::setupCustomToolbars(ToolBarItem* root, const Base::Reference<ParameterGrp>& hGrp) const { std::vector<Base::Reference<ParameterGrp> > hGrps = hGrp->GetGroups(); CommandManager& rMgr = Application::Instance->commandManager(); std::string separator = "Separator"; for (std::vector<Base::Reference<ParameterGrp> >::iterator it = hGrps.begin(); it != hGrps.end(); ++it) { bool active = (*it)->GetBool("Active", true); if (!active) // ignore this toolbar continue; ToolBarItem* bar = new ToolBarItem(root); bar->setCommand("Custom"); // get the elements of the subgroups std::vector<std::pair<std::string,std::string> > items = hGrp->GetGroup((*it)->GetGroupName())->GetASCIIMap(); for (std::vector<std::pair<std::string,std::string> >::iterator it2 = items.begin(); it2 != items.end(); ++it2) { if (it2->first.substr(0, separator.size()) == separator) { *bar << "Separator"; } else if (it2->first == "Name") { bar->setCommand(it2->second); } else { Command* pCmd = rMgr.getCommandByName(it2->first.c_str()); if (!pCmd) { // unknown command // first try the module name as is std::string pyMod = it2->second; try { Base::Interpreter().loadModule(pyMod.c_str()); // Try again pCmd = rMgr.getCommandByName(it2->first.c_str()); } catch(const Base::Exception&) { } } // still not there? if (!pCmd) { // add the 'Gui' suffix std::string pyMod = it2->second + "Gui"; try { Base::Interpreter().loadModule(pyMod.c_str()); // Try again pCmd = rMgr.getCommandByName(it2->first.c_str()); } catch(const Base::Exception&) { } } if (pCmd) { *bar << it2->first; // command name } } } } }
ToolBarItem* StdWorkbench::setupCommandBars() const { ToolBarItem* root = new ToolBarItem; // View ToolBarItem* view = new ToolBarItem( root ); view->setCommand("Standard views"); *view << "Std_ViewFitAll" << "Std_ViewFitSelection" << "Std_ViewAxo" << "Separator" << "Std_ViewFront" << "Std_ViewRight" << "Std_ViewTop" << "Separator" << "Std_ViewRear" << "Std_ViewLeft" << "Std_ViewBottom"; // Special Ops ToolBarItem* macro = new ToolBarItem( root ); macro->setCommand("Special Ops"); *macro << "Std_DlgParameter" << "Std_DlgPreferences" << "Std_DlgMacroRecord" << "Std_MacroStopRecord" << "Std_DlgMacroExecute" << "Std_DlgCustomize"; return root; }
void Workbench::setupCustomToolbars(ToolBarItem* root, const char* toolbar) const { std::string name = this->name(); ParameterGrp::handle hGrp = App::GetApplication().GetUserParameter().GetGroup("BaseApp") ->GetGroup("Workbench")->GetGroup(name.c_str())->GetGroup(toolbar); std::vector<Base::Reference<ParameterGrp> > hGrps = hGrp->GetGroups(); CommandManager& rMgr = Application::Instance->commandManager(); for (std::vector<Base::Reference<ParameterGrp> >::iterator it = hGrps.begin(); it != hGrps.end(); ++it) { bool active = (*it)->GetBool("Active", true); if (!active) // ignore this toolbar continue; ToolBarItem* bar = new ToolBarItem(root); bar->setCommand("Custom"); // get the elements of the subgroups std::vector<std::pair<std::string,std::string> > items = hGrp->GetGroup((*it)->GetGroupName())->GetASCIIMap(); for (std::vector<std::pair<std::string,std::string> >::iterator it2 = items.begin(); it2 != items.end(); ++it2) { if (it2->first == "Separator") { *bar << "Separator"; } else if (it2->first == "Name") { bar->setCommand(it2->second); } else { Command* pCmd = rMgr.getCommandByName(it2->first.c_str()); if (!pCmd) { // unknown command // try to find out the appropriate module name std::string pyMod = it2->second + "Gui"; try { Base::Interpreter().loadModule(pyMod.c_str()); } catch(const Base::Exception&) { } // Try again pCmd = rMgr.getCommandByName(it2->first.c_str()); } if (pCmd) { *bar << it2->first; // command name } } } } }
void PythonBaseWorkbench::appendToolbar(const std::string& bar, const std::list<std::string>& items) const { ToolBarItem* item = _toolBar->findItem(bar); if (!item) { item = new ToolBarItem(_toolBar); item->setCommand(bar); } for (std::list<std::string>::const_iterator it = items.begin(); it != items.end(); ++it) *item << *it; }