+ fixes #0001514: Padding a sketch inside a group fails with error message

This commit is contained in:
wmayer 2014-04-25 17:28:32 +02:00
parent 321063bb9c
commit 5370e20ce8
6 changed files with 60 additions and 7 deletions

View File

@ -31,6 +31,7 @@
#include "Document.h"
#include "DocumentObject.h"
#include "DocumentObjectPy.h"
#include "DocumentObjectGroup.h"
#include "PropertyLinks.h"
#define new DEBUG_CLIENTBLOCK
using namespace App;
@ -158,6 +159,11 @@ std::vector<App::DocumentObject*> DocumentObject::getInList(void) const
return std::vector<App::DocumentObject*>();
}
DocumentObjectGroup* DocumentObject::getGroup() const
{
return DocumentObjectGroup::getGroupOfObject(this);
}
void DocumentObject::onLostLinkToObject(DocumentObject*)
{

View File

@ -36,6 +36,7 @@
namespace App
{
class Document;
class DocumentObjectGroup;
class DocumentObjectPy;
enum ObjectStatus {
@ -122,6 +123,8 @@ public:
std::vector<App::DocumentObject*> getOutList(void) const;
/// get all objects link to this object
std::vector<App::DocumentObject*> getInList(void) const;
/// get group if object is part of a group, otherwise 0 is returned
DocumentObjectGroup* getGroup() const;
public:

View File

@ -103,7 +103,7 @@ DocumentObject *DocumentObjectGroup::getObject(const char *Name) const
return 0;
}
bool DocumentObjectGroup::hasObject(DocumentObject* obj) const
bool DocumentObjectGroup::hasObject(const DocumentObject* obj) const
{
const std::vector<DocumentObject*>& grp = Group.getValues();
for (std::vector<DocumentObject*>::const_iterator it = grp.begin(); it != grp.end(); ++it) {
@ -114,7 +114,7 @@ bool DocumentObjectGroup::hasObject(DocumentObject* obj) const
return false;
}
bool DocumentObjectGroup::isChildOf(DocumentObjectGroup* group) const
bool DocumentObjectGroup::isChildOf(const DocumentObjectGroup* group) const
{
const std::vector<DocumentObject*>& grp = group->Group.getValues();
for (std::vector<DocumentObject*>::const_iterator it = grp.begin(); it != grp.end(); ++it) {
@ -158,7 +158,7 @@ int DocumentObjectGroup::countObjectsOfType(const Base::Type& typeId) const
return type;
}
DocumentObjectGroup* DocumentObjectGroup::getGroupOfObject(DocumentObject* obj)
DocumentObjectGroup* DocumentObjectGroup::getGroupOfObject(const DocumentObject* obj)
{
const Document* doc = obj->getDocument();
std::vector<DocumentObject*> grps = doc->getObjectsOfType(DocumentObjectGroup::getClassTypeId());

View File

@ -65,12 +65,12 @@ public:
/**
* Checks whether the object \a obj is part of this group.
*/
bool hasObject(DocumentObject* obj) const;
bool hasObject(const DocumentObject* obj) const;
/**
* Checks whether this group object is a child (or sub-child)
* of the given group object.
*/
bool isChildOf(DocumentObjectGroup*) const;
bool isChildOf(const DocumentObjectGroup*) const;
/** Returns a list of all objects this group does have.
*/
std::vector<DocumentObject*> getObjects() const;
@ -83,7 +83,7 @@ public:
/** Returns the object group of the document which the given object \a obj is part of.
* In case this object is not part of a group 0 is returned.
*/
static DocumentObjectGroup* getGroupOfObject(DocumentObject* obj);
static DocumentObjectGroup* getGroupOfObject(const DocumentObject* obj);
//@}
/// returns the type name of the ViewProvider

View File

@ -40,6 +40,7 @@
#include <sstream>
#include <algorithm>
#include <App/DocumentObjectGroup.h>
#include <Gui/Application.h>
#include <Gui/Command.h>
#include <Gui/Control.h>
@ -69,7 +70,16 @@ void validateSketches(std::vector<App::DocumentObject*>& sketches, const bool su
while (s != sketches.end()) {
// Check whether this sketch is already being used by another feature
if ((*s)->getInList().size() != 0) {
std::vector<App::DocumentObject*> ref = (*s)->getInList();
std::vector<App::DocumentObject*>::iterator r = ref.begin();
while (r != ref.end()) {
if ((*r)->getTypeId().isDerivedFrom(App::DocumentObjectGroup::getClassTypeId())) {
r = ref.erase(r);
continue;
}
++r;
}
if (!ref.empty()) {
// TODO: Display some information message that this sketch was removed?
s = sketches.erase(s);
continue;
@ -205,6 +215,13 @@ void CmdPartDesignPad::activated(int iMsg)
doCommand(Doc,"App.activeDocument().addObject(\"PartDesign::Pad\",\"%s\")",FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.Sketch = App.activeDocument().%s",FeatName.c_str(),sketch->getNameInDocument());
doCommand(Doc,"App.activeDocument().%s.Length = 10.0",FeatName.c_str());
App::DocumentObjectGroup* grp = sketch->getGroup();
if (grp) {
doCommand(Doc,"App.activeDocument().%s.addObject(App.activeDocument().%s)"
,grp->getNameInDocument(),FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.removeObject(App.activeDocument().%s)"
,grp->getNameInDocument(),sketch->getNameInDocument());
}
updateActive();
if (isActiveObjectValid()) {
doCommand(Gui,"Gui.activeDocument().hide(\"%s\")",sketch->getNameInDocument());
@ -276,6 +293,13 @@ void CmdPartDesignPocket::activated(int iMsg)
doCommand(Doc,"App.activeDocument().addObject(\"PartDesign::Pocket\",\"%s\")",FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.Sketch = App.activeDocument().%s",FeatName.c_str(),sketch->getNameInDocument());
doCommand(Doc,"App.activeDocument().%s.Length = 5.0",FeatName.c_str());
App::DocumentObjectGroup* grp = sketch->getGroup();
if (grp) {
doCommand(Doc,"App.activeDocument().%s.addObject(App.activeDocument().%s)"
,grp->getNameInDocument(),FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.removeObject(App.activeDocument().%s)"
,grp->getNameInDocument(),sketch->getNameInDocument());
}
updateActive();
if (isActiveObjectValid()) {
doCommand(Gui,"Gui.activeDocument().hide(\"%s\")",sketch->getNameInDocument());
@ -346,6 +370,13 @@ void CmdPartDesignRevolution::activated(int iMsg)
PartDesign::Revolution* pcRevolution = static_cast<PartDesign::Revolution*>(getDocument()->getObject(FeatName.c_str()));
if (pcRevolution && pcRevolution->suggestReversed())
doCommand(Doc,"App.activeDocument().%s.Reversed = 1",FeatName.c_str());
App::DocumentObjectGroup* grp = sketch->getGroup();
if (grp) {
doCommand(Doc,"App.activeDocument().%s.addObject(App.activeDocument().%s)"
,grp->getNameInDocument(),FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.removeObject(App.activeDocument().%s)"
,grp->getNameInDocument(),sketch->getNameInDocument());
}
updateActive();
if (isActiveObjectValid()) {
doCommand(Gui,"Gui.activeDocument().hide(\"%s\")",sketch->getNameInDocument());
@ -419,6 +450,13 @@ void CmdPartDesignGroove::activated(int iMsg)
PartDesign::Groove* pcGroove = static_cast<PartDesign::Groove*>(getDocument()->getObject(FeatName.c_str()));
if (pcGroove && pcGroove->suggestReversed())
doCommand(Doc,"App.activeDocument().%s.Reversed = 1",FeatName.c_str());
App::DocumentObjectGroup* grp = sketch->getGroup();
if (grp) {
doCommand(Doc,"App.activeDocument().%s.addObject(App.activeDocument().%s)"
,grp->getNameInDocument(),FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.removeObject(App.activeDocument().%s)"
,grp->getNameInDocument(),sketch->getNameInDocument());
}
updateActive();
if (isActiveObjectValid()) {
doCommand(Gui,"Gui.activeDocument().hide(\"%s\")",sketch->getNameInDocument());

View File

@ -32,6 +32,7 @@
# include <QMessageBox>
#endif
#include <App/DocumentObjectGroup.h>
#include <Gui/Application.h>
#include <Gui/Document.h>
#include <Gui/Command.h>
@ -117,6 +118,11 @@ void CmdSketcherNewSketch::activated(int iMsg)
doCommand(Gui,"App.activeDocument().recompute()"); // recompute the sketch placement based on its support
//doCommand(Gui,"Gui.activeDocument().activeView().setCamera('%s')",cam.c_str());
doCommand(Gui,"Gui.activeDocument().setEdit('%s')",FeatName.c_str());
App::DocumentObjectGroup* grp = part->getGroup();
if (grp) {
doCommand(Doc,"App.activeDocument().%s.addObject(App.activeDocument().%s)"
,grp->getNameInDocument(),FeatName.c_str());
}
}
else {
// ask user for orientation