Commands and object making
This commit is contained in:
parent
6700512efe
commit
80217bf10f
|
@ -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<const Gui::Document*, DocumentItem*>::iterator jt = DocumentMap.find(Doc);
|
||||
for (std::map<const Gui::Document*, DocumentItem*>::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<std::string, DocumentObjectItem*>::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<std::string,DocumentObjectItem*>::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<DocumentObjectItem*> common;
|
||||
std::vector<DocumentObjectItem*> common;
|
||||
std::vector<DocumentObjectItem*>::iterator item_it = items.begin();
|
||||
for (std::vector<App::DocumentObject*>::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<DocumentObjectItem*> diff;
|
||||
std::vector<DocumentObjectItem*> diff;
|
||||
std::back_insert_iterator<std::vector<DocumentObjectItem*> > 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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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";
|
||||
//}
|
||||
//@}
|
||||
};
|
||||
|
|
|
@ -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";
|
||||
}
|
||||
//@}
|
||||
};
|
||||
|
|
|
@ -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";
|
||||
}
|
||||
//@}
|
||||
};
|
||||
|
|
|
@ -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";
|
||||
}
|
||||
//@}
|
||||
};
|
||||
|
|
|
@ -35,6 +35,8 @@
|
|||
#include "ViewProviderPart.h"
|
||||
#include "ViewProviderAssembly.h"
|
||||
|
||||
#include <Mod/Assembly/App/ItemAssembly.h>
|
||||
|
||||
//#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()
|
||||
|
|
|
@ -26,8 +26,45 @@
|
|||
# include <Python.h>
|
||||
#endif
|
||||
|
||||
#include <Base/PyObjectBase.h>
|
||||
#include <Base/Console.h>
|
||||
|
||||
#include <Gui/Application.h>
|
||||
|
||||
#include <Mod/Assembly/App/ItemPy.h>
|
||||
|
||||
// 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<Assembly::ItemPy*>(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 */
|
||||
};
|
||||
|
|
|
@ -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";
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -28,7 +28,11 @@
|
|||
#endif
|
||||
|
||||
#include "Workbench.h"
|
||||
#include <App/Application.h>
|
||||
#include <Gui/MenuManager.h>
|
||||
#include <Gui/ToolBarManager.h>
|
||||
#include <Gui/Control.h>
|
||||
#include <Gui/Command.h>
|
||||
|
||||
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<Gui::TaskView::TaskWatcher*> 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();
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user