From 09f199ed9e3ac2a7862e5f8bd5673984212d1324 Mon Sep 17 00:00:00 2001 From: jriegel Date: Thu, 5 Apr 2012 22:51:07 +0200 Subject: [PATCH] View nesting working! --- src/Mod/Assembly/App/ItemPart.cpp | 3 +- src/Mod/Assembly/Gui/Command.cpp | 50 +++++++++++++++++++++-- src/Mod/Assembly/Gui/ViewProviderPart.cpp | 33 ++++++++++++++- src/Mod/Assembly/Gui/ViewProviderPart.h | 5 +++ 4 files changed, 84 insertions(+), 7 deletions(-) diff --git a/src/Mod/Assembly/App/ItemPart.cpp b/src/Mod/Assembly/App/ItemPart.cpp index 3e909a295..a74d6c527 100644 --- a/src/Mod/Assembly/App/ItemPart.cpp +++ b/src/Mod/Assembly/App/ItemPart.cpp @@ -39,7 +39,8 @@ PROPERTY_SOURCE(Assembly::ItemPart, Assembly::Item) ItemPart::ItemPart() { - ADD_PROPERTY(Model,(0)); + ADD_PROPERTY(Model, (0)); + ADD_PROPERTY(Annotation,(0)); } short ItemPart::mustExecute() const diff --git a/src/Mod/Assembly/Gui/Command.cpp b/src/Mod/Assembly/Gui/Command.cpp index ac89d7cc0..b626b2e66 100644 --- a/src/Mod/Assembly/Gui/Command.cpp +++ b/src/Mod/Assembly/Gui/Command.cpp @@ -69,7 +69,7 @@ void CmdAssemblyAddNewPart::activated(int iMsg) dest = dynamic_cast(ActiveAsmObject); }else { - + return; } openCommand("Insert Part"); @@ -81,10 +81,29 @@ void CmdAssemblyAddNewPart::activated(int iMsg) } Command::addModule(App,"PartDesign"); Command::addModule(Gui,"PartDesignGui"); + +#if 1 // test code for children nesting + Command::addModule(App,"Part"); + std::string BodyName = getUniqueObjectName("Box"); + doCommand(Doc,"App.activeDocument().addObject('Part::Box','%s')",BodyName.c_str()); + doCommand(Doc,"App.activeDocument().%s.Model = App.activeDocument().%s ",PartName.c_str(),BodyName.c_str(),BodyName.c_str()); +#else + std::string BodyName = getUniqueObjectName("Body"); + // add the standard planes + std::string Plane1Name = BodyName + "_PlaneXY"; + std::string Plane2Name = BodyName + "_PlaneYZ"; + std::string Plane3Name = BodyName + "_PlaneXZ"; + doCommand(Doc,"App.activeDocument().addObject('App::Plane','%s')",Plane1Name.c_str()); + doCommand(Doc,"App.activeDocument().addObject('App::Plane','%s')",Plane2Name.c_str()); + doCommand(Doc,"App.activeDocument().%s.Placement = App.Placement(App.Vector(0.000000,0.000000,0.000000),App.Rotation(-0.707107,0.000000,0.000000,-0.707107))",Plane2Name.c_str()); + doCommand(Doc,"App.activeDocument().addObject('App::Plane','%s')",Plane3Name.c_str()); + doCommand(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 doCommand(Doc,"App.activeDocument().addObject('PartDesign::Body','%s')",BodyName.c_str()); doCommand(Doc,"App.activeDocument().%s.Model = App.activeDocument().%s ",PartName.c_str(),BodyName.c_str(),BodyName.c_str()); - +#endif # + this->updateActive(); } //=========================================================================== @@ -144,8 +163,31 @@ CmdAssemblyAddExistingComponent::CmdAssemblyAddExistingComponent() void CmdAssemblyAddExistingComponent::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); + }else { + + return; + } + + openCommand("Insert TestPart"); + std::string PartName = getUniqueObjectName("Part"); + 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 ",PartName.c_str(),BodyName.c_str(),BodyName.c_str()); } diff --git a/src/Mod/Assembly/Gui/ViewProviderPart.cpp b/src/Mod/Assembly/Gui/ViewProviderPart.cpp index 2efa6ef1d..943846e2f 100644 --- a/src/Mod/Assembly/Gui/ViewProviderPart.cpp +++ b/src/Mod/Assembly/Gui/ViewProviderPart.cpp @@ -24,6 +24,7 @@ #include "PreCompiled.h" #ifndef _PreComp_ +# include #endif #include "ViewProviderPart.h" @@ -48,14 +49,42 @@ bool ViewProviderItemPart::doubleClicked(void) return true; } +void ViewProviderItemPart::attach(App::DocumentObject *pcFeat) +{ + // call parent attach method + ViewProviderGeometryObject::attach(pcFeat); + + + // putting all together with the switch + addDisplayMaskMode(getChildRoot(), "Main"); +} + +void ViewProviderItemPart::setDisplayMode(const char* ModeName) +{ + if ( strcmp("Main",ModeName)==0 ) + setDisplayMaskMode("Main"); + + ViewProviderGeometryObject::setDisplayMode( ModeName ); +} + +std::vector ViewProviderItemPart::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 ViewProviderItemPart::claimChildren(void)const { std::vector res; + res.insert( res.end(), static_cast(getObject())->Annotation.getValues().begin(),static_cast(getObject())->Annotation.getValues().end()); if(static_cast(getObject())->Model.getValue()) res.push_back( static_cast(getObject())->Model.getValue()); - res.insert( res.end(), static_cast(getObject())->Annotation.getValues().begin(),static_cast(getObject())->Annotation.getValues().end()); return res; @@ -65,9 +94,9 @@ std::vector ViewProviderItemPart::claimChildren3D(void)con { std::vector res; + res.insert( res.end(), static_cast(getObject())->Annotation.getValues().begin(),static_cast(getObject())->Annotation.getValues().end()); if(static_cast(getObject())->Model.getValue()) res.push_back( static_cast(getObject())->Model.getValue()); - res.insert( res.end(), static_cast(getObject())->Annotation.getValues().begin(),static_cast(getObject())->Annotation.getValues().end()); return res; diff --git a/src/Mod/Assembly/Gui/ViewProviderPart.h b/src/Mod/Assembly/Gui/ViewProviderPart.h index 5a3c4b309..720b81ff5 100644 --- a/src/Mod/Assembly/Gui/ViewProviderPart.h +++ b/src/Mod/Assembly/Gui/ViewProviderPart.h @@ -41,6 +41,11 @@ public: 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;