diff --git a/src/Gui/Tree.cpp b/src/Gui/Tree.cpp index dba94c0df..a17e8fce1 100644 --- a/src/Gui/Tree.cpp +++ b/src/Gui/Tree.cpp @@ -638,6 +638,23 @@ void TreeWidget::slotActiveDocument(const Gui::Document& Doc) } } +void TreeWidget::markItem(const App::DocumentObject* Obj,bool mark) +{ + // never call without Object! + assert(Obj); + Gui::Document* Doc = Gui::Application::Instance->getDocument(Obj->getDocument()); + + std::map::iterator jt = DocumentMap.find(Doc); + for (std::map::iterator it = DocumentMap.begin(); + it != DocumentMap.end(); ++it) + { + it->second->markItem(Obj,mark); + + QFont f = it->second->font(0); + f.setBold(it == jt); + it->second->setFont(0,f); + } +} void TreeWidget::onTestStatus(void) { @@ -874,7 +891,7 @@ void DocumentItem::slotResetEdit(const Gui::ViewProviderDocumentObject& v) std::string name (v.getObject()->getNameInDocument()); std::map::iterator it = ObjectMap.find(name); if (it != ObjectMap.end()) { - it->second->setData(0, Qt::BackgroundColorRole,QVariant()); + it->second->setData(0, Qt::BackgroundColorRole,QVariant()); } } @@ -1071,6 +1088,21 @@ const Gui::Document* DocumentItem::document() const return this->pDocument; } +void DocumentItem::markItem(const App::DocumentObject* Obj,bool mark) +{ + // never call without Object! + assert(Obj); + + + std::map::iterator pos; + pos = ObjectMap.find(Obj->getNameInDocument()); + if (pos != ObjectMap.end()) { + QFont f = pos->second->font(0); + f.setUnderline(mark); + pos->second->setFont(0,f); + } +} + //void DocumentItem::markItem(const App::DocumentObject* Obj,bool mark) //{ // // never call without Object! @@ -1185,7 +1217,7 @@ void DocumentItem::selectItems(void) // The document objects in 'objs' is a subset of the document objects stored // in 'items'. Since both arrays are sorted we get the wanted tree items in // linear time. - std::vector common; + std::vector common; std::vector::iterator item_it = items.begin(); for (std::vector::iterator it = objs.begin(); it != objs.end(); ++it) { item_it = std::find_if(item_it, items.end(), std::bind2nd(ObjectItem_Equal(), *it)); @@ -1197,7 +1229,7 @@ void DocumentItem::selectItems(void) // get all unselected items of the given document std::sort(common.begin(), common.end()); std::sort(items.begin(), items.end()); - std::vector diff; + std::vector diff; std::back_insert_iterator > biit(diff); std::set_difference(items.begin(), items.end(), common.begin(), common.end(), biit); @@ -1315,28 +1347,28 @@ void DocumentObjectItem::testStatus() QIcon::Mode mode = QIcon::Normal; if (currentStatus & 1) { // visible - // Note: By default the foreground, i.e. text color is invalid - // to make use of the default color of the tree widget's palette. - // If we temporarily set this color to dark and reset to an invalid - // color again we cannot do it with setTextColor() or setForeground(), - // respectively, because for any reason the color would always switch - // to black which will lead to unreadable text if the system background - // hss already a dark color. + // Note: By default the foreground, i.e. text color is invalid + // to make use of the default color of the tree widget's palette. + // If we temporarily set this color to dark and reset to an invalid + // color again we cannot do it with setTextColor() or setForeground(), + // respectively, because for any reason the color would always switch + // to black which will lead to unreadable text if the system background + // hss already a dark color. // However, it works if we set the appropriate role to an empty QVariant(). -#if QT_VERSION >= 0x040200 - this->setData(0, Qt::ForegroundRole,QVariant()); +#if QT_VERSION >= 0x040200 + this->setData(0, Qt::ForegroundRole,QVariant()); #else - this->setData(0, Qt::TextColorRole,QVariant()); -#endif - } - else { // invisible - QStyleOptionViewItem opt; - opt.initFrom(this->treeWidget()); -#if QT_VERSION >= 0x040200 + this->setData(0, Qt::TextColorRole,QVariant()); +#endif + } + else { // invisible + QStyleOptionViewItem opt; + opt.initFrom(this->treeWidget()); +#if QT_VERSION >= 0x040200 this->setForeground(0, opt.palette.color(QPalette::Disabled,QPalette::Text)); #else this->setTextColor(0, opt.palette.color(QPalette::Disabled,QPalette::Text); -#endif +#endif mode = QIcon::Disabled; } diff --git a/src/Gui/Tree.h b/src/Gui/Tree.h index 9319e6bc7..8ed57c67e 100644 --- a/src/Gui/Tree.h +++ b/src/Gui/Tree.h @@ -149,6 +149,7 @@ public: void selectItems(void); void testStatus(void); void setData(int column, int role, const QVariant & value); + void markItem(const App::DocumentObject* Obj,bool mark); protected: /** Adds a view provider to the document item. diff --git a/src/Mod/Assembly/App/Constraint.h b/src/Mod/Assembly/App/Constraint.h index 28b8fa086..fd3562ce5 100644 --- a/src/Mod/Assembly/App/Constraint.h +++ b/src/Mod/Assembly/App/Constraint.h @@ -48,7 +48,7 @@ public: short mustExecute() const; /// returns the type name of the view provider //const char* getViewProviderName(void) const { - // return "PartDesignGui::ViewProviderConstraint"; + // return "AssemblyGui::ViewProviderConstraint"; //} //@} }; diff --git a/src/Mod/Assembly/App/Item.h b/src/Mod/Assembly/App/Item.h index fde898739..50ada9aee 100644 --- a/src/Mod/Assembly/App/Item.h +++ b/src/Mod/Assembly/App/Item.h @@ -68,7 +68,7 @@ public: short mustExecute() const; /// returns the type name of the view provider const char* getViewProviderName(void) const { - return "PartDesignGui::ViewProviderItem"; + return "AssemblyGui::ViewProviderItem"; } //@} }; diff --git a/src/Mod/Assembly/App/ItemAssembly.h b/src/Mod/Assembly/App/ItemAssembly.h index 35e822390..301177122 100644 --- a/src/Mod/Assembly/App/ItemAssembly.h +++ b/src/Mod/Assembly/App/ItemAssembly.h @@ -47,7 +47,7 @@ public: short mustExecute() const; /// returns the type name of the view provider const char* getViewProviderName(void) const { - return "PartDesignGui::ViewProviderItemAssembly"; + return "AssemblyGui::ViewProviderItemAssembly"; } //@} }; diff --git a/src/Mod/Assembly/App/ItemPart.h b/src/Mod/Assembly/App/ItemPart.h index bc472a473..19dbc8406 100644 --- a/src/Mod/Assembly/App/ItemPart.h +++ b/src/Mod/Assembly/App/ItemPart.h @@ -47,7 +47,7 @@ public: short mustExecute() const; // returns the type name of the view provider const char* getViewProviderName(void) const { - return "ItemPartDesignGui::ViewProviderItemPart"; + return "AssemblyGui::ViewProviderItemPart"; } //@} }; diff --git a/src/Mod/Assembly/Gui/AppAssemblyGui.cpp b/src/Mod/Assembly/Gui/AppAssemblyGui.cpp index a5973f1d2..7185b7ace 100644 --- a/src/Mod/Assembly/Gui/AppAssemblyGui.cpp +++ b/src/Mod/Assembly/Gui/AppAssemblyGui.cpp @@ -35,6 +35,8 @@ #include "ViewProviderPart.h" #include "ViewProviderAssembly.h" +#include + //#include "resources/qrc_Assembly.cpp" // use a different name to CreateCommand() @@ -52,6 +54,7 @@ void loadAssemblyResource() extern struct PyMethodDef AssemblyGui_Import_methods[]; + /* Python entry */ extern "C" { void AssemblyGuiExport initAssemblyGui() diff --git a/src/Mod/Assembly/Gui/AppAssemblyGuiPy.cpp b/src/Mod/Assembly/Gui/AppAssemblyGuiPy.cpp index f6cce5f9f..7ca515bfc 100644 --- a/src/Mod/Assembly/Gui/AppAssemblyGuiPy.cpp +++ b/src/Mod/Assembly/Gui/AppAssemblyGuiPy.cpp @@ -26,8 +26,45 @@ # include #endif +#include +#include + +#include + +#include + +// pointer to the active assembly object +Assembly::Item *ActiveAsmObject =0; + + +/* module functions */ +static PyObject * setActiveAssembly(PyObject *self, PyObject *args) +{ + PyObject *object; + if (PyArg_ParseTuple(args,"O!",&(Assembly::ItemPy::Type), &object)) { + Assembly::Item* Item = static_cast(object)->getItemPtr(); + // Should be set! + assert(Item); + + if(ActiveAsmObject){ + + ActiveAsmObject = 0; + + } + ActiveAsmObject = Item; + Gui::ViewProvider* vp = Gui::Application::Instance -> getViewProvider(ActiveAsmObject); + //PyErr_SetString(PyExc_Exception, "empty shape"); + + } + + return 0; +} + /* registration table */ struct PyMethodDef AssemblyGui_Import_methods[] = { + {"setActiveAssembly" ,setActiveAssembly ,METH_VARARGS, + "setActiveAssembly(AssemblyObject) -- Set the Assembly object in work."}, + {NULL, NULL} /* end of table marker */ }; diff --git a/src/Mod/Assembly/Gui/Command.cpp b/src/Mod/Assembly/Gui/Command.cpp index 3fb2de14c..453d6f7b6 100644 --- a/src/Mod/Assembly/Gui/Command.cpp +++ b/src/Mod/Assembly/Gui/Command.cpp @@ -48,7 +48,7 @@ CmdAssemblyAddNewPart::CmdAssemblyAddNewPart() sToolTipText = QT_TR_NOOP("Add a new Part into the active Assembly"); sWhatsThis = "Assembly_ConstraintAxle"; sStatusTip = sToolTipText; - sPixmap = "actions/Axle_constraint"; + sPixmap = "Part_Box"; } @@ -72,7 +72,7 @@ CmdAssemblyAddNewComponent::CmdAssemblyAddNewComponent() sToolTipText = QT_TR_NOOP("Add a new Component into the active Assembly"); sWhatsThis = sToolTipText; sStatusTip = sToolTipText; - sPixmap = "actions/Axle_constraint"; + sPixmap = "Part_Box"; } @@ -96,7 +96,7 @@ CmdAssemblyAddExistingComponent::CmdAssemblyAddExistingComponent() sToolTipText = QT_TR_NOOP("Add a existing Component or File into the active Assembly"); sWhatsThis = sToolTipText; sStatusTip = sToolTipText; - sPixmap = "actions/Axle_constraint"; + sPixmap = "Part_Box"; } diff --git a/src/Mod/Assembly/Gui/PreCompiled.h b/src/Mod/Assembly/Gui/PreCompiled.h index 3fe37f681..2f3bbc999 100644 --- a/src/Mod/Assembly/Gui/PreCompiled.h +++ b/src/Mod/Assembly/Gui/PreCompiled.h @@ -28,12 +28,14 @@ // Importing of App classes #ifdef FC_OS_WIN32 -# define AssemblyAppExport __declspec(dllimport) +# define AssemblyExport __declspec(dllimport) # define PartGuiExport __declspec(dllimport) +# define PartExport __declspec(dllimport) # define AssemblyGuiExport __declspec(dllexport) #else // for Linux -# define AssemblyAppExport +# define AssemblyExport # define PartGuiExport +# define PartExport # define AssemblyGuiExport #endif diff --git a/src/Mod/Assembly/Gui/Workbench.cpp b/src/Mod/Assembly/Gui/Workbench.cpp index b50793b24..ec04ec9dc 100644 --- a/src/Mod/Assembly/Gui/Workbench.cpp +++ b/src/Mod/Assembly/Gui/Workbench.cpp @@ -28,7 +28,11 @@ #endif #include "Workbench.h" +#include +#include #include +#include +#include using namespace AssemblyGui; @@ -56,6 +60,25 @@ Gui::ToolBarItem* Workbench::setupToolBars() const return root; } +Gui::MenuItem* Workbench::setupMenuBar() const +{ + Gui::MenuItem* root = StdWorkbench::setupMenuBar(); + Gui::MenuItem* item = root->findItem("&Windows"); + + + Gui::MenuItem* asmCmd = new Gui::MenuItem(); + root->insertItem(item, asmCmd); + asmCmd->setCommand("&Assembly"); + *asmCmd << "Assembly_ConstraintAxle" + << "Separator" + << "Assembly_AddNewPart" + << "Assembly_AddNewComponent" + << "Assembly_AddExistingComponent"; + + + return root; +} + Gui::ToolBarItem* Workbench::setupCommandBars() const { // Part tools @@ -63,3 +86,49 @@ Gui::ToolBarItem* Workbench::setupCommandBars() const return root; } +void Workbench::activated() +{ + Gui::Workbench::activated(); + + std::vector Watcher; + + const char* Asm[] = { + "Assembly_AddNewPart", + "PartDesign_Fillet", + "PartDesign_Chamfer", + 0}; + Watcher.push_back(new Gui::TaskView::TaskWatcherCommands( + "SELECT Assembly::Item COUNT 1", + Asm, + "Assembly tools", + "Part_Box" + )); + + addTaskWatcher(Watcher); + Gui::Control().showTaskView(); + + App::Document *doc = App::GetApplication().getActiveDocument(); + if(!doc){ + // create a new document + + Gui::Command::doCommand(Gui::Command::Doc,"App.newDocument()"); + doc = App::GetApplication().getActiveDocument(); + + } + // now we should have a document! + assert(doc); + + if(doc->countObjects()==0){ + Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject('Assembly::ItemAssembly','Product')"); + } + + +} + +void Workbench::deactivated() +{ + Gui::Workbench::deactivated(); + removeTaskWatcher(); + +} + diff --git a/src/Mod/Assembly/Gui/Workbench.h b/src/Mod/Assembly/Gui/Workbench.h index c1d887874..a9aced5cf 100644 --- a/src/Mod/Assembly/Gui/Workbench.h +++ b/src/Mod/Assembly/Gui/Workbench.h @@ -36,12 +36,19 @@ class AssemblyGuiExport Workbench : public Gui::StdWorkbench TYPESYSTEM_HEADER(); public: - Workbench(); - virtual ~Workbench(); + Workbench(); + virtual ~Workbench(); + + /** Run some actions when the workbench gets activated. */ + virtual void activated(); + /** Run some actions when the workbench gets deactivated. */ + virtual void deactivated(); protected: Gui::ToolBarItem* setupToolBars() const; Gui::ToolBarItem* setupCommandBars() const; + Gui::MenuItem* setupMenuBar() const; + }; } // namespace AssemblyGui