From 29507a44eded6a0440dbcc24b6feef9bf9d5dfc3 Mon Sep 17 00:00:00 2001 From: jriegel Date: Sun, 1 Apr 2012 21:47:24 +0200 Subject: [PATCH] First claimChildren3D implementation and Starting PartItem implementation --- src/Gui/Command.h | 2 - src/Gui/Document.cpp | 1 + src/Gui/Tree.cpp | 19 +--------- src/Gui/Tree.h | 1 - src/Gui/View3DInventorViewer.cpp | 1 + src/Mod/Assembly/Gui/Command.cpp | 28 ++++++++++++-- src/Mod/Assembly/Gui/ViewProvider.cpp | 7 ++++ src/Mod/Assembly/Gui/ViewProvider.h | 7 ++++ src/Mod/Assembly/Gui/ViewProviderAssembly.cpp | 37 +++++++++++++++++++ src/Mod/Assembly/Gui/ViewProviderAssembly.h | 6 +++ src/Mod/Assembly/Gui/Workbench.cpp | 22 +++++------ 11 files changed, 95 insertions(+), 36 deletions(-) diff --git a/src/Gui/Command.h b/src/Gui/Command.h index 36e9f3a175..9907ecda95 100644 --- a/src/Gui/Command.h +++ b/src/Gui/Command.h @@ -252,8 +252,6 @@ public: static void copyVisual(const char* to, const char* attr_to, const char* from, const char* attr_from); /// Get Python tuple from object and sub-elements static std::string getPythonTuple(const std::string& name, const std::vector& subnames); - /// import an external module only once - //static void addModule(const char* sModuleName); /// translate a string to a python string literal (needed e.g. in file names for windows...) const std::string strToPython(const char* Str); const std::string strToPython(const std::string &Str){return strToPython(Str.c_str());}; diff --git a/src/Gui/Document.cpp b/src/Gui/Document.cpp index b0391a1ef8..6cb877102d 100644 --- a/src/Gui/Document.cpp +++ b/src/Gui/Document.cpp @@ -423,6 +423,7 @@ void Document::slotNewObject(const App::DocumentObject& Obj) Base::Console().Error("App::Document::_RecomputeFeature(): Unknown exception in Feature \"%s\" thrown\n",Obj.getNameInDocument()); } #endif + std::list::iterator vIt; // cycling to all views of the document for (vIt = d->baseViews.begin();vIt != d->baseViews.end();++vIt) { diff --git a/src/Gui/Tree.cpp b/src/Gui/Tree.cpp index bda4f985e5..37d2901621 100644 --- a/src/Gui/Tree.cpp +++ b/src/Gui/Tree.cpp @@ -638,23 +638,6 @@ 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) { @@ -672,7 +655,7 @@ void TreeWidget::onTestStatus(void) void TreeWidget::onItemEntered(QTreeWidgetItem * item) { // object item selected - if (item && item->type() == TreeWidget::ObjectType) { + if ( item && item->type() == TreeWidget::ObjectType ) { DocumentObjectItem* obj = static_cast(item); obj->displayStatusInfo(); } diff --git a/src/Gui/Tree.h b/src/Gui/Tree.h index a103137460..2a8fa840e6 100644 --- a/src/Gui/Tree.h +++ b/src/Gui/Tree.h @@ -149,7 +149,6 @@ 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/Gui/View3DInventorViewer.cpp b/src/Gui/View3DInventorViewer.cpp index 0e2b4a515d..5735564097 100644 --- a/src/Gui/View3DInventorViewer.cpp +++ b/src/Gui/View3DInventorViewer.cpp @@ -642,6 +642,7 @@ void View3DInventorViewer::removeViewProvider(ViewProvider* pcProvider) _ViewProviderSet.erase(pcProvider); } + SbBool View3DInventorViewer::setEditingViewProvider(Gui::ViewProvider* p, int ModNum) { if (this->editViewProvider) diff --git a/src/Mod/Assembly/Gui/Command.cpp b/src/Mod/Assembly/Gui/Command.cpp index eaee42af09..02fcac0f60 100644 --- a/src/Mod/Assembly/Gui/Command.cpp +++ b/src/Mod/Assembly/Gui/Command.cpp @@ -59,9 +59,29 @@ CmdAssemblyAddNewPart::CmdAssemblyAddNewPart() void CmdAssemblyAddNewPart::activated(int iMsg) { - // load the file with the module - //Command::doCommand(Command::Gui, "import Assembly, AssemblyGui"); - + Assembly::ItemAssembly *dest = 0; + + unsigned int n = getSelection().countObjectsOfType(Assembly::ItemAssembly::getClassTypeId()); + if (n >= 1) { + std::vector Sel = getSelection().getObjectsOfType(Assembly::ItemAssembly::getClassTypeId()); + dest = dynamic_cast(Sel.front()); + }else if(ActiveAsmObject && ActiveAsmObject->getTypeId().isDerivedFrom(Assembly::ItemAssembly::getClassTypeId())) { + dest = dynamic_cast(ActiveAsmObject); + } + + openCommand("Insert Part"); + std::string PartName = getUniqueObjectName("Part.0"); + doCommand(Doc,"App.activeDocument().addObject('Assembly::ItemPart','%s')",PartName.c_str()); + if(dest){ + std::string fatherName = dest->getNameInDocument(); + doCommand(Doc,"App.activeDocument().%s.Items = App.activeDocument().%s.Items + [App.activeDocument().%s] ",fatherName.c_str(),fatherName.c_str(),PartName.c_str()); + } + Command::addModule(App,"PartDesign"); + Command::addModule(Gui,"PartDesignGui"); + std::string BodyName = getUniqueObjectName("Body"); + doCommand(Doc,"App.activeDocument().addObject('PartDesign::Body','%s')",BodyName.c_str()); + doCommand(Doc,"App.activeDocument().%s.Model = App.activeDocument().%s.Items = App.activeDocument().%s ",BodyName.c_str(),BodyName.c_str(),BodyName.c_str()); + } //=========================================================================== @@ -94,7 +114,7 @@ void CmdAssemblyAddNewComponent::activated(int iMsg) } openCommand("Insert Component"); - std::string CompName = getUniqueObjectName("Product"); + std::string CompName = getUniqueObjectName("Product.0"); doCommand(Doc,"App.activeDocument().addObject('Assembly::ItemAssembly','%s')",CompName.c_str()); if(dest){ std::string fatherName = dest->getNameInDocument(); diff --git a/src/Mod/Assembly/Gui/ViewProvider.cpp b/src/Mod/Assembly/Gui/ViewProvider.cpp index 160f3daa39..5b0fd1474f 100644 --- a/src/Mod/Assembly/Gui/ViewProvider.cpp +++ b/src/Mod/Assembly/Gui/ViewProvider.cpp @@ -24,22 +24,29 @@ #include "PreCompiled.h" #ifndef _PreComp_ +# include #endif #include "ViewProvider.h" #include //#include + using namespace AssemblyGui; PROPERTY_SOURCE(AssemblyGui::ViewProviderItem,PartGui::ViewProviderPart) ViewProviderItem::ViewProviderItem() { + pcChildren = new SoGroup(); + pcChildren->ref(); + } ViewProviderItem::~ViewProviderItem() { + pcChildren->unref(); + pcChildren = 0; } bool ViewProviderItem::doubleClicked(void) diff --git a/src/Mod/Assembly/Gui/ViewProvider.h b/src/Mod/Assembly/Gui/ViewProvider.h index 03fb5d42e2..a28bb51a38 100644 --- a/src/Mod/Assembly/Gui/ViewProvider.h +++ b/src/Mod/Assembly/Gui/ViewProvider.h @@ -26,6 +26,7 @@ #include +class SoGroup; namespace AssemblyGui { @@ -39,7 +40,13 @@ public: /// destructor virtual ~ViewProviderItem(); + // returns the root node where the children gets collected(3D) + virtual SoGroup* getChildRoot(void) const {return pcChildren;} + + virtual bool doubleClicked(void); +private: + SoGroup *pcChildren; }; diff --git a/src/Mod/Assembly/Gui/ViewProviderAssembly.cpp b/src/Mod/Assembly/Gui/ViewProviderAssembly.cpp index 74a475d9f9..23af658abf 100644 --- a/src/Mod/Assembly/Gui/ViewProviderAssembly.cpp +++ b/src/Mod/Assembly/Gui/ViewProviderAssembly.cpp @@ -24,6 +24,7 @@ #include "PreCompiled.h" #ifndef _PreComp_ +# include #endif #include "ViewProviderAssembly.h" @@ -50,6 +51,35 @@ bool ViewProviderItemAssembly::doubleClicked(void) return true; } +void ViewProviderItemAssembly::attach(App::DocumentObject *pcFeat) +{ + // call parent attach method + ViewProviderGeometryObject::attach(pcFeat); + + + // putting all together with the switch + addDisplayMaskMode(getChildRoot(), "Main"); +} + +void ViewProviderItemAssembly::setDisplayMode(const char* ModeName) +{ + if ( strcmp("Main",ModeName)==0 ) + setDisplayMaskMode("Main"); + + ViewProviderGeometryObject::setDisplayMode( ModeName ); +} + +std::vector ViewProviderItemAssembly::getDisplayModes(void) const +{ + // get the modes of the father + std::vector StrList = ViewProviderGeometryObject::getDisplayModes(); + + // add your own modes + StrList.push_back("Main"); + + return StrList; +} + std::vector ViewProviderItemAssembly::claimChildren(void)const { @@ -57,3 +87,10 @@ std::vector ViewProviderItemAssembly::claimChildren(void)c return static_cast(getObject())->Items.getValues(); } + +std::vector ViewProviderItemAssembly::claimChildren3D(void)const +{ + + return static_cast(getObject())->Items.getValues(); + +} diff --git a/src/Mod/Assembly/Gui/ViewProviderAssembly.h b/src/Mod/Assembly/Gui/ViewProviderAssembly.h index 747b28ee82..1e3fe40ccf 100644 --- a/src/Mod/Assembly/Gui/ViewProviderAssembly.h +++ b/src/Mod/Assembly/Gui/ViewProviderAssembly.h @@ -40,9 +40,15 @@ public: virtual ~ViewProviderItemAssembly(); virtual bool doubleClicked(void); + virtual void attach(App::DocumentObject *); + virtual void setDisplayMode(const char* ModeName); + /// returns a list of all possible modes + virtual std::vector getDisplayModes(void) const; virtual std::vector claimChildren(void)const; + virtual std::vector claimChildren3D(void)const; + }; diff --git a/src/Mod/Assembly/Gui/Workbench.cpp b/src/Mod/Assembly/Gui/Workbench.cpp index d0032a0878..ec04ec9dcd 100644 --- a/src/Mod/Assembly/Gui/Workbench.cpp +++ b/src/Mod/Assembly/Gui/Workbench.cpp @@ -107,20 +107,20 @@ void Workbench::activated() addTaskWatcher(Watcher); Gui::Control().showTaskView(); - //App::Document *doc = App::GetApplication().getActiveDocument(); - //if(!doc){ - // // create a new document + App::Document *doc = App::GetApplication().getActiveDocument(); + if(!doc){ + // create a new document - // Gui::Command::doCommand(Gui::Command::Doc,"App.newDocument()"); - // doc = App::GetApplication().getActiveDocument(); + Gui::Command::doCommand(Gui::Command::Doc,"App.newDocument()"); + doc = App::GetApplication().getActiveDocument(); - //} - //// now we should have a document! - //assert(doc); + } + // now we should have a document! + assert(doc); - //if(doc->countObjects()==0){ - // Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject('Assembly::ItemAssembly','Product')"); - //} + if(doc->countObjects()==0){ + Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject('Assembly::ItemAssembly','Product')"); + } }