From 91196ee24474ad8ff6ee6680db754a79efbf6ebe Mon Sep 17 00:00:00 2001 From: jriegel Date: Sun, 2 Feb 2014 22:44:07 +0100 Subject: [PATCH] dripping Body in Assembly (ongoing) --- src/Mod/Assembly/Gui/ViewProviderAssembly.cpp | 65 +++++++++++++++++++ src/Mod/Assembly/Gui/ViewProviderAssembly.h | 6 ++ src/Mod/Assembly/Gui/ViewProviderPart.cpp | 51 +++++++++++++++ src/Mod/Assembly/Gui/ViewProviderPart.h | 6 ++ 4 files changed, 128 insertions(+) diff --git a/src/Mod/Assembly/Gui/ViewProviderAssembly.cpp b/src/Mod/Assembly/Gui/ViewProviderAssembly.cpp index 0e2e7f3005..8bf5f2e972 100644 --- a/src/Mod/Assembly/Gui/ViewProviderAssembly.cpp +++ b/src/Mod/Assembly/Gui/ViewProviderAssembly.cpp @@ -32,8 +32,11 @@ #include #include #include +#include #include +#include +#include using namespace AssemblyGui; @@ -133,3 +136,65 @@ bool ViewProviderItemAssembly::setEdit(int ModNum) } return ViewProviderItem::setEdit(ModNum); // call the base class } + +bool ViewProviderItemAssembly::allowDrop(const std::vector &objList,Qt::KeyboardModifiers keys,Qt::MouseButtons mouseBts,const QPoint &pos) +{ + for( std::vector::const_iterator it = objList.begin();it!=objList.end();++it){ + if ((*it)->getTypeId().isDerivedFrom(Part::BodyBase::getClassTypeId())) { + continue; + } else if ((*it)->getTypeId().isDerivedFrom(Assembly::ItemPart::getClassTypeId())) { + continue; + } else + return false; + } + return true; +} +void ViewProviderItemAssembly::drop(const std::vector &objList,Qt::KeyboardModifiers keys,Qt::MouseButtons mouseBts,const QPoint &pos) +{ + // Open command + Assembly::ItemAssembly* AsmItem = static_cast(getObject()); + App::Document* doc = AsmItem->getDocument(); + Gui::Document* gui = Gui::Application::Instance->getDocument(doc); + + gui->openCommand("Move into Assembly"); + for( std::vector::const_iterator it = objList.begin();it!=objList.end();++it) { + if ((*it)->getTypeId().isDerivedFrom(Part::BodyBase::getClassTypeId())) { + // get document object + const App::DocumentObject* obj = *it; + + // build Python command for execution + std::string PartName = doc->getUniqueObjectName("Part"); + Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject('Assembly::ItemPart','%s')",PartName.c_str()); + std::string fatherName = AsmItem->getNameInDocument(); + Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.Items = App.activeDocument().%s.Items + [App.activeDocument().%s] ",fatherName.c_str(),fatherName.c_str(),PartName.c_str()); + Gui::Command::addModule(Gui::Command::App,"PartDesign"); + Gui::Command::addModule(Gui::Command::Gui,"PartDesignGui"); + + + std::string BodyName = obj->getNameInDocument(); + // add the standard planes + std::string Plane1Name = BodyName + "_PlaneXY"; + std::string Plane2Name = BodyName + "_PlaneYZ"; + std::string Plane3Name = BodyName + "_PlaneXZ"; + Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject('App::Plane','%s')",Plane1Name.c_str()); + Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().ActiveObject.Label = 'XY-Plane'"); + Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject('App::Plane','%s')",Plane2Name.c_str()); + Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().ActiveObject.Placement = App.Placement(App.Vector(),App.Rotation(App.Vector(0,1,0),90))"); + Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().ActiveObject.Label = 'YZ-Plane'"); + Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject('App::Plane','%s')",Plane3Name.c_str()); + Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().ActiveObject.Placement = App.Placement(App.Vector(),App.Rotation(App.Vector(1,0,0),90))"); + Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().ActiveObject.Label = 'XZ-Plane'"); + // add to anotation set of the Part object + Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.Annotation = [App.activeDocument().%s,App.activeDocument().%s,App.activeDocument().%s] ",PartName.c_str(),Plane1Name.c_str(),Plane2Name.c_str(),Plane3Name.c_str()); + // add the main body + Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.Model = App.activeDocument().%s ",PartName.c_str(),BodyName.c_str()); + + } else if ((*it)->getTypeId().isDerivedFrom(Assembly::ItemPart::getClassTypeId())) { + continue; + } else + continue; + + } + gui->commitCommand(); + +} \ No newline at end of file diff --git a/src/Mod/Assembly/Gui/ViewProviderAssembly.h b/src/Mod/Assembly/Gui/ViewProviderAssembly.h index 93462091bb..27e9b0c80a 100644 --- a/src/Mod/Assembly/Gui/ViewProviderAssembly.h +++ b/src/Mod/Assembly/Gui/ViewProviderAssembly.h @@ -53,6 +53,12 @@ public: virtual void setupContextMenu(QMenu* menu, QObject* receiver, const char* member); virtual bool setEdit(int ModNum); + + /// get called if the user hover over a object in the tree + virtual bool allowDrop(const std::vector &objList,Qt::KeyboardModifiers keys,Qt::MouseButtons mouseBts,const QPoint &pos); + /// get called if the user drops some objects + virtual void drop(const std::vector &objList,Qt::KeyboardModifiers keys,Qt::MouseButtons mouseBts,const QPoint &pos); + }; diff --git a/src/Mod/Assembly/Gui/ViewProviderPart.cpp b/src/Mod/Assembly/Gui/ViewProviderPart.cpp index b1e2ecbca2..583c57bb63 100644 --- a/src/Mod/Assembly/Gui/ViewProviderPart.cpp +++ b/src/Mod/Assembly/Gui/ViewProviderPart.cpp @@ -144,6 +144,56 @@ std::vector ViewProviderItemPart::claimChildren3D(void)con } +bool ViewProviderItemPart::allowDrop(const std::vector &objList,Qt::KeyboardModifiers keys,Qt::MouseButtons mouseBts,const QPoint &pos) +{ + //for( std::vector::const_iterator it = objList.begin();it!=objList.end();++it) + // if ((*it)->getTypeId().isDerivedFrom(App::DocumentObjectGroup::getClassTypeId())) { + // if (static_cast(getObject())->isChildOf( + // static_cast(*it))) { + // return false; + // } + // } + + return false; +} +void ViewProviderItemPart::drop(const std::vector &objList,Qt::KeyboardModifiers keys,Qt::MouseButtons mouseBts,const QPoint &pos) +{ + //// Open command + //App::DocumentObjectGroup* grp = static_cast(getObject()); + //App::Document* doc = grp->getDocument(); + //Gui::Document* gui = Gui::Application::Instance->getDocument(doc); + //gui->openCommand("Move object"); + //for( std::vector::const_iterator it = objList.begin();it!=objList.end();++it) { + // // get document object + // const App::DocumentObject* obj = *it; + // const App::DocumentObjectGroup* par = App::DocumentObjectGroup::getGroupOfObject(obj); + // if (par) { + // // allow an object to be in one group only + // QString cmd; + // cmd = QString::fromAscii("App.getDocument(\"%1\").getObject(\"%2\").removeObject(" + // "App.getDocument(\"%1\").getObject(\"%3\"))") + // .arg(QString::fromAscii(doc->getName())) + // .arg(QString::fromAscii(par->getNameInDocument())) + // .arg(QString::fromAscii(obj->getNameInDocument())); + // Gui::Application::Instance->runPythonCode(cmd.toUtf8()); + // } + + // // build Python command for execution + // QString cmd; + // cmd = QString::fromAscii("App.getDocument(\"%1\").getObject(\"%2\").addObject(" + // "App.getDocument(\"%1\").getObject(\"%3\"))") + // .arg(QString::fromAscii(doc->getName())) + // .arg(QString::fromAscii(grp->getNameInDocument())) + // .arg(QString::fromAscii(obj->getNameInDocument())); + // + // Gui::Application::Instance->runPythonCode(cmd.toUtf8()); + //} + //gui->commitCommand(); + +} + + + #ifdef ASSEMBLY_DEBUG_FACILITIES void ViewProviderItemPart::onChanged(const App::Property* prop) { @@ -235,4 +285,5 @@ void ViewProviderItemPart::onChanged(const App::Property* prop) { ViewProviderItem::onChanged(prop); } + #endif diff --git a/src/Mod/Assembly/Gui/ViewProviderPart.h b/src/Mod/Assembly/Gui/ViewProviderPart.h index ec8cbe30ea..2f26a67d8c 100644 --- a/src/Mod/Assembly/Gui/ViewProviderPart.h +++ b/src/Mod/Assembly/Gui/ViewProviderPart.h @@ -54,6 +54,12 @@ public: virtual std::vector claimChildren(void)const; virtual std::vector claimChildren3D(void)const; + + /// get called if the user hover over a object in the tree + virtual bool allowDrop(const std::vector &objList,Qt::KeyboardModifiers keys,Qt::MouseButtons mouseBts,const QPoint &pos); + /// get called if the user drops some objects + virtual void drop(const std::vector &objList,Qt::KeyboardModifiers keys,Qt::MouseButtons mouseBts,const QPoint &pos); + #ifdef ASSEMBLY_DEBUG_FACILITIES //draw the dcm points