First claimChildren3D implementation and Starting PartItem implementation

This commit is contained in:
jriegel 2012-04-01 21:47:24 +02:00 committed by Stefan Tröger
parent 8537926edc
commit 29507a44ed
11 changed files with 95 additions and 36 deletions

View File

@ -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<std::string>& 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());};

View File

@ -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<Gui::BaseView*>::iterator vIt;
// cycling to all views of the document
for (vIt = d->baseViews.begin();vIt != d->baseViews.end();++vIt) {

View File

@ -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<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)
{
@ -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<DocumentObjectItem*>(item);
obj->displayStatusInfo();
}

View File

@ -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.

View File

@ -642,6 +642,7 @@ void View3DInventorViewer::removeViewProvider(ViewProvider* pcProvider)
_ViewProviderSet.erase(pcProvider);
}
SbBool View3DInventorViewer::setEditingViewProvider(Gui::ViewProvider* p, int ModNum)
{
if (this->editViewProvider)

View File

@ -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<App::DocumentObject*> Sel = getSelection().getObjectsOfType(Assembly::ItemAssembly::getClassTypeId());
dest = dynamic_cast<Assembly::ItemAssembly*>(Sel.front());
}else if(ActiveAsmObject && ActiveAsmObject->getTypeId().isDerivedFrom(Assembly::ItemAssembly::getClassTypeId())) {
dest = dynamic_cast<Assembly::ItemAssembly*>(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();

View File

@ -24,22 +24,29 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# include <Inventor/nodes/SoGroup.h>
#endif
#include "ViewProvider.h"
#include <Gui/Command.h>
//#include <Gui/Document.h>
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)

View File

@ -26,6 +26,7 @@
#include <Mod/Part/Gui/ViewProvider.h>
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;
};

View File

@ -24,6 +24,7 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# include <Inventor/nodes/SoGroup.h>
#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<std::string> ViewProviderItemAssembly::getDisplayModes(void) const
{
// get the modes of the father
std::vector<std::string> StrList = ViewProviderGeometryObject::getDisplayModes();
// add your own modes
StrList.push_back("Main");
return StrList;
}
std::vector<App::DocumentObject*> ViewProviderItemAssembly::claimChildren(void)const
{
@ -57,3 +87,10 @@ std::vector<App::DocumentObject*> ViewProviderItemAssembly::claimChildren(void)c
return static_cast<Assembly::ItemAssembly*>(getObject())->Items.getValues();
}
std::vector<App::DocumentObject*> ViewProviderItemAssembly::claimChildren3D(void)const
{
return static_cast<Assembly::ItemAssembly*>(getObject())->Items.getValues();
}

View File

@ -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<std::string> getDisplayModes(void) const;
virtual std::vector<App::DocumentObject*> claimChildren(void)const;
virtual std::vector<App::DocumentObject*> claimChildren3D(void)const;
};

View File

@ -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')");
}
}