Work on inserting, removing, hiding and showing features in the body
This commit is contained in:
parent
df7983fe10
commit
1ec99c5d32
|
@ -1032,6 +1032,12 @@ void DocumentItem::slotHighlightObject (const Gui::ViewProviderDocumentObject& o
|
||||||
else
|
else
|
||||||
jt->second->setData(0, Qt::BackgroundColorRole,QVariant());
|
jt->second->setData(0, Qt::BackgroundColorRole,QVariant());
|
||||||
break;
|
break;
|
||||||
|
case Gui::LightBlue:
|
||||||
|
if(set)
|
||||||
|
jt->second->setBackgroundColor(0,QColor(230,230,255));
|
||||||
|
else
|
||||||
|
jt->second->setData(0, Qt::BackgroundColorRole,QVariant());
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,7 +44,8 @@ enum HighlightMode { Underlined,
|
||||||
Italic ,
|
Italic ,
|
||||||
Overlined ,
|
Overlined ,
|
||||||
Bold ,
|
Bold ,
|
||||||
Blue
|
Blue ,
|
||||||
|
LightBlue
|
||||||
};
|
};
|
||||||
|
|
||||||
/// highlight modes for the tree items
|
/// highlight modes for the tree items
|
||||||
|
|
|
@ -31,11 +31,12 @@
|
||||||
|
|
||||||
#include <Gui/Application.h>
|
#include <Gui/Application.h>
|
||||||
#include <Gui/Document.h>
|
#include <Gui/Document.h>
|
||||||
#include <Gui/Tree.h>
|
|
||||||
#include <Gui/ViewProviderDocumentObject.h>
|
#include <Gui/ViewProviderDocumentObject.h>
|
||||||
|
|
||||||
#include <Mod/PartDesign/App/BodyPy.h>
|
#include <Mod/PartDesign/App/BodyPy.h>
|
||||||
|
|
||||||
|
#include "ViewProviderBody.h"
|
||||||
|
|
||||||
namespace PartDesignGui {
|
namespace PartDesignGui {
|
||||||
|
|
||||||
// pointer to the active assembly object
|
// pointer to the active assembly object
|
||||||
|
@ -48,35 +49,25 @@ Gui::ViewProviderDocumentObject *ActiveVp =0;
|
||||||
|
|
||||||
static PyObject * setActivePart(PyObject *self, PyObject *args)
|
static PyObject * setActivePart(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
if(PartDesignGui::ActivePartObject){
|
|
||||||
// check if the document not already closed
|
|
||||||
std::vector<App::Document*> docs = App::GetApplication().getDocuments();
|
|
||||||
for(std::vector<App::Document*>::const_iterator it=docs.begin();it!=docs.end();++it)
|
|
||||||
if(*it == PartDesignGui::ActiveAppDoc){
|
|
||||||
PartDesignGui::ActiveGuiDoc->signalHighlightObject(*PartDesignGui::ActiveVp,Gui::Underlined,false);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
PartDesignGui::ActivePartObject->IsActive.setValue(false);
|
|
||||||
PartDesignGui::ActivePartObject = 0;
|
|
||||||
PartDesignGui::ActiveGuiDoc =0;
|
|
||||||
PartDesignGui::ActiveAppDoc =0;
|
|
||||||
PartDesignGui::ActiveVp =0;
|
|
||||||
}
|
|
||||||
|
|
||||||
PyObject *object=0;
|
PyObject *object=0;
|
||||||
if (PyArg_ParseTuple(args,"|O!",&(PartDesign::BodyPy::Type), &object)&& object) {
|
if (PyArg_ParseTuple(args,"|O!",&(PartDesign::BodyPy::Type), &object)&& object) {
|
||||||
PartDesign::Body* Item = static_cast<PartDesign::BodyPy*>(object)->getBodyPtr();
|
PartDesign::Body* Item = static_cast<PartDesign::BodyPy*>(object)->getBodyPtr();
|
||||||
// Should be set!
|
// Should be set!
|
||||||
assert(Item);
|
assert(Item);
|
||||||
|
|
||||||
Item->IsActive.setValue(true);
|
if (PartDesignGui::ActivePartObject != NULL)
|
||||||
|
PartDesignGui::ActivePartObject->IsActive.setValue(false);
|
||||||
PartDesignGui::ActivePartObject = Item;
|
PartDesignGui::ActivePartObject = Item;
|
||||||
PartDesignGui::ActiveAppDoc = Item->getDocument();
|
PartDesignGui::ActiveAppDoc = Item->getDocument();
|
||||||
PartDesignGui::ActiveGuiDoc = Gui::Application::Instance->getDocument(PartDesignGui::ActiveAppDoc);
|
PartDesignGui::ActiveGuiDoc = Gui::Application::Instance->getDocument(PartDesignGui::ActiveAppDoc);
|
||||||
PartDesignGui::ActiveVp = dynamic_cast<Gui::ViewProviderDocumentObject*> (PartDesignGui::ActiveGuiDoc->getViewProvider(Item)) ;
|
PartDesignGui::ActiveVp = dynamic_cast<Gui::ViewProviderDocumentObject*> (PartDesignGui::ActiveGuiDoc->getViewProvider(Item)) ;
|
||||||
PartDesignGui::ActiveGuiDoc->signalHighlightObject(*PartDesignGui::ActiveVp,Gui::Underlined,true);
|
Item->IsActive.setValue(true);
|
||||||
|
} else {
|
||||||
|
// This handles the case of deactivating the workbench
|
||||||
|
PartDesignGui::ActivePartObject = 0;
|
||||||
|
PartDesignGui::ActiveGuiDoc =0;
|
||||||
|
PartDesignGui::ActiveAppDoc =0;
|
||||||
|
PartDesignGui::ActiveVp =0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Py_Return;
|
Py_Return;
|
||||||
|
|
|
@ -80,6 +80,8 @@ void Part2DObject::positionBySupport(void)
|
||||||
bool Reverse = false;
|
bool Reverse = false;
|
||||||
gp_Pln plane;
|
gp_Pln plane;
|
||||||
App::DocumentObject* support = Support.getValue();
|
App::DocumentObject* support = Support.getValue();
|
||||||
|
if (support == NULL)
|
||||||
|
throw Base::Exception("Sketch support has been deleted");
|
||||||
|
|
||||||
if (support->getTypeId().isDerivedFrom(App::Plane::getClassTypeId())) {
|
if (support->getTypeId().isDerivedFrom(App::Plane::getClassTypeId())) {
|
||||||
Place = static_cast<App::Plane*>(support)->Placement.getValue();
|
Place = static_cast<App::Plane*>(support)->Placement.getValue();
|
||||||
|
|
|
@ -28,10 +28,14 @@
|
||||||
#include <Base/Placement.h>
|
#include <Base/Placement.h>
|
||||||
|
|
||||||
#include "Feature.h"
|
#include "Feature.h"
|
||||||
|
#include "DatumFeature.h"
|
||||||
#include "Body.h"
|
#include "Body.h"
|
||||||
#include "BodyPy.h"
|
#include "BodyPy.h"
|
||||||
|
|
||||||
|
#include <App/Application.h>
|
||||||
|
#include <App/Document.h>
|
||||||
#include <Base/Console.h>
|
#include <Base/Console.h>
|
||||||
|
#include "FeatureSketchBased.h"
|
||||||
|
|
||||||
|
|
||||||
using namespace PartDesign;
|
using namespace PartDesign;
|
||||||
|
@ -46,6 +50,26 @@ Body::Body()
|
||||||
ADD_PROPERTY(IsActive,(0));
|
ADD_PROPERTY(IsActive,(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Body::onChanged(const App::Property *prop)
|
||||||
|
{
|
||||||
|
Base::Console().Error("Checking Body '%s' for sanity\n", getNameInDocument());
|
||||||
|
App::DocumentObject* tip = Tip.getValue();
|
||||||
|
Base::Console().Error(" Tip: %s\n", (tip == NULL) ? "None" : tip->getNameInDocument());
|
||||||
|
std::vector<App::DocumentObject*> model = Model.getValues();
|
||||||
|
Base::Console().Error(" Model:\n");
|
||||||
|
for (std::vector<App::DocumentObject*>::const_iterator m = model.begin(); m != model.end(); m++) {
|
||||||
|
Base::Console().Error(" %s", (*m)->getNameInDocument());
|
||||||
|
if ((*m)->getTypeId().isDerivedFrom(PartDesign::SketchBased::getClassTypeId())) {
|
||||||
|
App::DocumentObject* baseFeature = static_cast<PartDesign::SketchBased*>(*m)->BaseFeature.getValue();
|
||||||
|
Base::Console().Error(", Base: %s\n", baseFeature == NULL ? "None" : baseFeature->getNameInDocument());
|
||||||
|
} else {
|
||||||
|
Base::Console().Error("\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Part::Feature::onChanged(prop);
|
||||||
|
}
|
||||||
|
|
||||||
short Body::mustExecute() const
|
short Body::mustExecute() const
|
||||||
{
|
{
|
||||||
if (Tip.isTouched() )
|
if (Tip.isTouched() )
|
||||||
|
@ -66,7 +90,7 @@ const Part::TopoShape Body::getTipShape()
|
||||||
// get the shape of the tip
|
// get the shape of the tip
|
||||||
return static_cast<Part::Feature*>(link)->Shape.getShape();
|
return static_cast<Part::Feature*>(link)->Shape.getShape();
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
const Part::TopoShape Body::getPreviousSolid(const PartDesign::Feature* f)
|
const Part::TopoShape Body::getPreviousSolid(const PartDesign::Feature* f)
|
||||||
{
|
{
|
||||||
std::vector<App::DocumentObject*> features = Model.getValues();
|
std::vector<App::DocumentObject*> features = Model.getValues();
|
||||||
|
@ -76,8 +100,9 @@ const Part::TopoShape Body::getPreviousSolid(const PartDesign::Feature* f)
|
||||||
return Part::TopoShape();
|
return Part::TopoShape();
|
||||||
// move to previous feature
|
// move to previous feature
|
||||||
it--;
|
it--;
|
||||||
// Skip sketches
|
// Skip sketches and datum features
|
||||||
while (!(*it)->getTypeId().isDerivedFrom(PartDesign::Feature::getClassTypeId())) {
|
while ((*it)->getTypeId().isDerivedFrom(PartDesign::Datum::getClassTypeId()) ||
|
||||||
|
(*it)->getTypeId().isDerivedFrom(Part::Part2DObject::getClassTypeId())) {
|
||||||
if (it == features.begin())
|
if (it == features.begin())
|
||||||
return Part::TopoShape();
|
return Part::TopoShape();
|
||||||
it--;
|
it--;
|
||||||
|
@ -85,38 +110,47 @@ const Part::TopoShape Body::getPreviousSolid(const PartDesign::Feature* f)
|
||||||
|
|
||||||
return static_cast<const PartDesign::Feature*>(*it)->Shape.getShape();
|
return static_cast<const PartDesign::Feature*>(*it)->Shape.getShape();
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
App::DocumentObject* Body::getTipSolidFeature()
|
App::DocumentObject* Body::getPrevSolidFeature(App::DocumentObject *start, const bool inclusive)
|
||||||
{
|
{
|
||||||
std::vector<App::DocumentObject*> features = Model.getValues();
|
std::vector<App::DocumentObject*> features = Model.getValues();
|
||||||
if (features.empty()) return NULL;
|
if (features.empty()) return NULL;
|
||||||
std::vector<App::DocumentObject*>::const_iterator it = std::find(features.begin(), features.end(), Tip.getValue());
|
App::DocumentObject* st = (start == NULL ? Tip.getValue() : start);
|
||||||
|
|
||||||
// Skip sketches
|
if (inclusive && isSolidFeature(st))
|
||||||
while (!(*it)->getTypeId().isDerivedFrom(PartDesign::Feature::getClassTypeId())) {
|
return st;
|
||||||
|
|
||||||
|
std::vector<App::DocumentObject*>::iterator it = std::find(features.begin(), features.end(), st);
|
||||||
|
if (it == features.end()) return NULL; // Invalid start object
|
||||||
|
|
||||||
|
// Skip sketches and datum features
|
||||||
|
do {
|
||||||
if (it == features.begin())
|
if (it == features.begin())
|
||||||
return NULL;
|
return NULL;
|
||||||
it--;
|
it--;
|
||||||
}
|
} while (!isSolidFeature(*it));
|
||||||
|
|
||||||
return *it;
|
return *it;
|
||||||
}
|
}
|
||||||
|
|
||||||
App::DocumentObject* Body::getNextSolidFeature()
|
App::DocumentObject* Body::getNextSolidFeature(App::DocumentObject *start, const bool inclusive)
|
||||||
{
|
{
|
||||||
std::vector<App::DocumentObject*> features = Model.getValues();
|
std::vector<App::DocumentObject*> features = Model.getValues();
|
||||||
if (features.empty()) return NULL;
|
if (features.empty()) return NULL;
|
||||||
if (Tip.getValue() == features.back()) return NULL;
|
App::DocumentObject* st = (start == NULL ? Tip.getValue() : start);
|
||||||
|
|
||||||
std::vector<App::DocumentObject*>::const_iterator it = std::find(features.begin(), features.end(), Tip.getValue());
|
if (inclusive && isSolidFeature(st))
|
||||||
it++; // Move beyond the Tip
|
return st;
|
||||||
|
|
||||||
// Skip sketches
|
std::vector<App::DocumentObject*>::iterator it = std::find(features.begin(), features.end(), st);
|
||||||
while (!(*it)->getTypeId().isDerivedFrom(PartDesign::Feature::getClassTypeId())) {
|
if (it == features.end()) return NULL; // Invalid start object
|
||||||
|
|
||||||
|
// Skip sketches and datum features
|
||||||
|
do {
|
||||||
it++;
|
it++;
|
||||||
if (it == features.end())
|
if (it == features.end())
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
} while (!isSolidFeature(*it));
|
||||||
|
|
||||||
return *it;
|
return *it;
|
||||||
}
|
}
|
||||||
|
@ -127,19 +161,122 @@ const bool Body::hasFeature(const App::DocumentObject* f)
|
||||||
return std::find(features.begin(), features.end(), f) != features.end();
|
return std::find(features.begin(), features.end(), f) != features.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool Body::insertMode() {
|
const bool Body::isAfterTip(const App::DocumentObject *f) {
|
||||||
std::vector<App::DocumentObject*> features = Model.getValues();
|
std::vector<App::DocumentObject*> features = Model.getValues();
|
||||||
if (features.empty()) return false;
|
std::vector<App::DocumentObject*>::const_iterator it = std::find(features.begin(), features.end(), f);
|
||||||
return Tip.getValue() != features.back();
|
std::vector<App::DocumentObject*>::const_iterator tip = std::find(features.begin(), features.end(), Tip.getValue());
|
||||||
|
return (it > tip);
|
||||||
|
}
|
||||||
|
|
||||||
|
const bool Body::isSolidFeature(const App::DocumentObject* f)
|
||||||
|
{
|
||||||
|
return (!f->getTypeId().isDerivedFrom(PartDesign::Datum::getClassTypeId()) &&
|
||||||
|
!f->getTypeId().isDerivedFrom(Part::Part2DObject::getClassTypeId()));
|
||||||
|
}
|
||||||
|
|
||||||
|
Body* Body::findBodyOf(const App::DocumentObject* f)
|
||||||
|
{
|
||||||
|
App::Document* doc = App::GetApplication().getActiveDocument();
|
||||||
|
if (doc != NULL) {
|
||||||
|
std::vector<App::DocumentObject*> bodies = doc->getObjectsOfType(PartDesign::Body::getClassTypeId());
|
||||||
|
for (std::vector<App::DocumentObject*>::const_iterator b = bodies.begin(); b != bodies.end(); b++) {
|
||||||
|
PartDesign::Body* body = static_cast<PartDesign::Body*>(*b);
|
||||||
|
if (body->hasFeature(f))
|
||||||
|
return body;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Body::insertFeature(App::DocumentObject *feature)
|
||||||
|
{
|
||||||
|
// Set the BaseFeature property
|
||||||
|
// Note: This is not strictly necessary for Datum features
|
||||||
|
if (feature->getTypeId().isDerivedFrom(PartDesign::Feature::getClassTypeId())) {
|
||||||
|
App::DocumentObject* prevSolidFeature = getPrevSolidFeature(NULL, true);
|
||||||
|
if (prevSolidFeature != NULL)
|
||||||
|
// Set BaseFeature property to previous feature (this might be the Tip feature)
|
||||||
|
static_cast<PartDesign::Feature*>(feature)->BaseFeature.setValue(prevSolidFeature);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Body::isSolidFeature(feature)) {
|
||||||
|
// Reroute the next solid feature's BaseFeature property to this feature
|
||||||
|
App::DocumentObject* nextSolidFeature = getNextSolidFeature(NULL, false);
|
||||||
|
if (nextSolidFeature != NULL)
|
||||||
|
static_cast<PartDesign::Feature*>(nextSolidFeature)->BaseFeature.setValue(feature);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Insert the new feature after the current Tip feature
|
||||||
|
App::DocumentObject* tipFeature = Tip.getValue();
|
||||||
|
std::vector<App::DocumentObject*> model = Model.getValues();
|
||||||
|
if (tipFeature == NULL) {
|
||||||
|
if (model.empty())
|
||||||
|
// First feature in the body
|
||||||
|
model.push_back(feature);
|
||||||
|
else
|
||||||
|
throw Base::Exception("Body has features, but Tip is not valid");
|
||||||
|
} else {
|
||||||
|
// Insert after Tip
|
||||||
|
std::vector<App::DocumentObject*>::iterator it = std::find(model.begin(), model.end(), tipFeature);
|
||||||
|
if (it == model.end())
|
||||||
|
throw Base::Exception("Body: Tip is not contained in model");
|
||||||
|
|
||||||
|
it++;
|
||||||
|
if (it == model.end())
|
||||||
|
model.push_back(feature);
|
||||||
|
else
|
||||||
|
model.insert(it, feature);
|
||||||
|
}
|
||||||
|
Model.setValues(model);
|
||||||
|
|
||||||
|
// Move the Tip
|
||||||
|
Tip.setValue(feature);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Body::removeFeature(App::DocumentObject* feature)
|
||||||
|
{
|
||||||
|
if (isSolidFeature(feature)) {
|
||||||
|
// This is a solid feature
|
||||||
|
// If the next feature is solid, reroute its BaseFeature property to the previous solid feature
|
||||||
|
App::DocumentObject* nextSolidFeature = getNextSolidFeature(feature, false);
|
||||||
|
if (nextSolidFeature != NULL) {
|
||||||
|
App::DocumentObject* prevSolidFeature = getPrevSolidFeature(feature, false);
|
||||||
|
PartDesign::Feature* nextFeature = static_cast<PartDesign::Feature*>(nextSolidFeature);
|
||||||
|
if ((prevSolidFeature == NULL) && (nextFeature->BaseFeature.getValue() != NULL))
|
||||||
|
// sanity check
|
||||||
|
throw Base::Exception((std::string("Body: Base feature of ") + nextFeature->getNameInDocument() + " was removed!").c_str());
|
||||||
|
nextFeature->BaseFeature.setValue(prevSolidFeature);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Adjust Tip feature if it is pointing to the deleted object
|
||||||
|
App::DocumentObject* tipFeature = Tip.getValue();
|
||||||
|
std::vector<App::DocumentObject*> model = Model.getValues();
|
||||||
|
std::vector<App::DocumentObject*>::iterator it = std::find(model.begin(), model.end(), feature);
|
||||||
|
if (tipFeature == feature) {
|
||||||
|
// Set the Tip to the previous feature if possible, otherwise to the next feature
|
||||||
|
std::vector<App::DocumentObject*>::const_iterator prev = it, next = it;
|
||||||
|
prev--;
|
||||||
|
next++;
|
||||||
|
|
||||||
|
if (prev != model.end()) {
|
||||||
|
Tip.setValue(*prev);
|
||||||
|
} else {
|
||||||
|
if (next != model.end())
|
||||||
|
Tip.setValue(*next);
|
||||||
|
else
|
||||||
|
Tip.setValue(NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Erase feature from Model
|
||||||
|
model.erase(it);
|
||||||
|
Model.setValues(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
App::DocumentObjectExecReturn *Body::execute(void)
|
App::DocumentObjectExecReturn *Body::execute(void)
|
||||||
{
|
{
|
||||||
std::vector<App::DocumentObject*> children = Model.getValues();
|
|
||||||
//Base::Console().Error("Body exec children:\n");
|
|
||||||
//for (std::vector<App::DocumentObject*>::const_iterator o = children.begin(); o != children.end(); o++)
|
|
||||||
// Base::Console().Error("%s\n", (*o)->getNameInDocument());
|
|
||||||
|
|
||||||
const Part::TopoShape& TipShape = getTipShape();
|
const Part::TopoShape& TipShape = getTipShape();
|
||||||
|
|
||||||
if (TipShape._Shape.IsNull())
|
if (TipShape._Shape.IsNull())
|
||||||
|
|
|
@ -49,6 +49,8 @@ public:
|
||||||
/// recalculate the feature
|
/// recalculate the feature
|
||||||
App::DocumentObjectExecReturn *execute(void);
|
App::DocumentObjectExecReturn *execute(void);
|
||||||
short mustExecute() const;
|
short mustExecute() const;
|
||||||
|
/// Just for debugging, remove when Body functionality is stable
|
||||||
|
void onChanged(const App::Property* prop);
|
||||||
/// returns the type name of the view provider
|
/// returns the type name of the view provider
|
||||||
const char* getViewProviderName(void) const {
|
const char* getViewProviderName(void) const {
|
||||||
return "PartDesignGui::ViewProviderBody";
|
return "PartDesignGui::ViewProviderBody";
|
||||||
|
@ -59,28 +61,44 @@ public:
|
||||||
const Part::TopoShape getTipShape();
|
const Part::TopoShape getTipShape();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return Tip feature if it is a solid. Otherwise, go backwards in the Model and
|
* Return the solid feature before the given feature, or before the Tip feature
|
||||||
* find the first feature that is a solid (i.e. Sketches are skipped)
|
* That is, sketches and datum features are skipped
|
||||||
* This is used by SketchBased features to determine the shape they should fuse with or cut out off
|
* If inclusive is true, start or the Tip is returned if it is a solid feature
|
||||||
* NOTE: Currently only PartDesign features are accepted as TipSolidFeatures
|
|
||||||
*/
|
*/
|
||||||
App::DocumentObject *getTipSolidFeature();
|
App::DocumentObject *getPrevSolidFeature(App::DocumentObject *start = NULL, const bool inclusive = true);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the next solid feature after the Tip feature (so this only makes sense in insert mode)
|
* Return the next solid feature after the given feature, or after the Tip feature
|
||||||
* This is used by Sketchbased features in insert mode to re-route the Base property
|
* That is, sketches and datum features are skipped
|
||||||
* NOTE: Currently only PartDesign features are accepted as nextSolidFeatures
|
* If inclusive is true, start or the Tip is returned if it is a solid feature
|
||||||
*/
|
*/
|
||||||
App::DocumentObject *getNextSolidFeature();
|
App::DocumentObject *getNextSolidFeature(App::DocumentObject* start = NULL, const bool inclusive = true);
|
||||||
|
|
||||||
/// Return the shape of the feature preceding this feature
|
// Return the shape of the feature preceding this feature
|
||||||
const Part::TopoShape getPreviousSolid(const PartDesign::Feature* f);
|
//const Part::TopoShape getPreviousSolid(const PartDesign::Feature* f);
|
||||||
|
|
||||||
/// Return true if the feature belongs to this body
|
/// Return true if the feature belongs to this body
|
||||||
const bool hasFeature(const App::DocumentObject *f);
|
const bool hasFeature(const App::DocumentObject *f);
|
||||||
|
|
||||||
/// Returns true if we are inserting into the feature tree instead of appending at the end
|
/// Return true if the feature is located after the current Tip feature
|
||||||
const bool insertMode();
|
const bool isAfterTip(const App::DocumentObject *f);
|
||||||
|
|
||||||
|
/// Insert the feature into the body at the current insert point (Tip feature)
|
||||||
|
void insertFeature(App::DocumentObject* feature);
|
||||||
|
|
||||||
|
/// Remove the feature from the body
|
||||||
|
void removeFeature(App::DocumentObject* feature);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return true if the given feature is a solid feature allowed in a Body. Currently this is only valid
|
||||||
|
* for features derived from PartDesign::Feature with the exception of PartDesign::Datum features
|
||||||
|
* Return false if the given feature is a Sketch or a PartDesign::Datum feature
|
||||||
|
*/
|
||||||
|
static const bool isSolidFeature(const App::DocumentObject* f);
|
||||||
|
|
||||||
|
/// Return the body which this feature belongs too, or NULL
|
||||||
|
static Body* findBodyOf(const App::DocumentObject* f);
|
||||||
|
|
||||||
PyObject *getPyObject(void);
|
PyObject *getPyObject(void);
|
||||||
|
|
||||||
|
|
|
@ -13,5 +13,15 @@
|
||||||
<Author Licence="LGPL" Name="Juergen Riegel" EMail="FreeCAD@juergen-riegel.net" />
|
<Author Licence="LGPL" Name="Juergen Riegel" EMail="FreeCAD@juergen-riegel.net" />
|
||||||
<UserDocu>PartDesign body class</UserDocu>
|
<UserDocu>PartDesign body class</UserDocu>
|
||||||
</Documentation>
|
</Documentation>
|
||||||
|
<Methode Name="insertFeature">
|
||||||
|
<Documentation>
|
||||||
|
<UserDocu>insertFeature(feat) - Insert the given feature after the current Tip feature</UserDocu>
|
||||||
|
</Documentation>
|
||||||
|
</Methode>
|
||||||
|
<Methode Name="removeFeature">
|
||||||
|
<Documentation>
|
||||||
|
<UserDocu>removeFeature(feat) - Remove the given feature from the Body</UserDocu>
|
||||||
|
</Documentation>
|
||||||
|
</Methode>
|
||||||
</PythonExport>
|
</PythonExport>
|
||||||
</GenerateModel>
|
</GenerateModel>
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
|
|
||||||
#include "PreCompiled.h"
|
#include "PreCompiled.h"
|
||||||
|
|
||||||
|
#include "Mod/Part/App/Part2DObject.h"
|
||||||
#include "Mod/PartDesign/App/Body.h"
|
#include "Mod/PartDesign/App/Body.h"
|
||||||
|
#include "Mod/PartDesign/App/DatumFeature.h"
|
||||||
|
|
||||||
// inclusion of the generated files (generated out of ItemPy.xml)
|
// inclusion of the generated files (generated out of ItemPy.xml)
|
||||||
#include "BodyPy.h"
|
#include "BodyPy.h"
|
||||||
|
@ -27,4 +29,48 @@ int BodyPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PyObject* BodyPy::insertFeature(PyObject *args)
|
||||||
|
{
|
||||||
|
PyObject* featurePy;
|
||||||
|
if (!PyArg_ParseTuple(args, "O!", &(Part::PartFeaturePy::Type), &featurePy))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
Part::Feature* feature = static_cast<Part::PartFeaturePy*>(featurePy)->getFeaturePtr();
|
||||||
|
|
||||||
|
if (!feature->getTypeId().isDerivedFrom(PartDesign::Feature::getClassTypeId()) &&
|
||||||
|
!feature->getTypeId().isDerivedFrom(Part::Part2DObject::getClassTypeId())) {
|
||||||
|
PyErr_SetString(PyExc_SystemError, "Only PartDesign features and sketches can be inserted into a Body");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
Body* body = this->getBodyPtr();
|
||||||
|
|
||||||
|
try {
|
||||||
|
body->insertFeature(feature);
|
||||||
|
} catch (Base::Exception& e) {
|
||||||
|
PyErr_SetString(PyExc_SystemError, e.what());
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
Py_Return;
|
||||||
|
}
|
||||||
|
|
||||||
|
PyObject* BodyPy::removeFeature(PyObject *args)
|
||||||
|
{
|
||||||
|
PyObject* featurePy;
|
||||||
|
if (!PyArg_ParseTuple(args, "O!", &(Part::PartFeaturePy::Type), &featurePy))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
Part::Feature* feature = static_cast<Part::PartFeaturePy*>(featurePy)->getFeaturePtr();
|
||||||
|
Body* body = this->getBodyPtr();
|
||||||
|
|
||||||
|
try {
|
||||||
|
body->removeFeature(feature);
|
||||||
|
} catch (Base::Exception& e) {
|
||||||
|
PyErr_SetString(PyExc_SystemError, e.what());
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
Py_Return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -56,6 +56,7 @@
|
||||||
|
|
||||||
#include <Mod/Part/App/Part2DObject.h>
|
#include <Mod/Part/App/Part2DObject.h>
|
||||||
#include <Mod/PartDesign/App/Body.h>
|
#include <Mod/PartDesign/App/Body.h>
|
||||||
|
#include <Mod/PartDesign/App/DatumFeature.h>
|
||||||
#include <Mod/Sketcher/App/SketchObject.h>
|
#include <Mod/Sketcher/App/SketchObject.h>
|
||||||
#include <Mod/Sketcher/Gui/SketchOrientationDialog.h>
|
#include <Mod/Sketcher/Gui/SketchOrientationDialog.h>
|
||||||
#include <Mod/PartDesign/App/FeatureGroove.h>
|
#include <Mod/PartDesign/App/FeatureGroove.h>
|
||||||
|
@ -125,6 +126,7 @@ void CmdPartDesignBody::activated(int iMsg)
|
||||||
|
|
||||||
// add the Body feature itself, and make it active
|
// add the Body feature itself, and make it active
|
||||||
doCommand(Doc,"App.activeDocument().addObject('PartDesign::Body','%s')",FeatName.c_str());
|
doCommand(Doc,"App.activeDocument().addObject('PartDesign::Body','%s')",FeatName.c_str());
|
||||||
|
doCommand(Doc,"App.activeDocument().%s.Tip = None",FeatName.c_str());
|
||||||
doCommand(Doc,"import PartDesignGui");
|
doCommand(Doc,"import PartDesignGui");
|
||||||
doCommand(Gui,"PartDesignGui.setActivePart(App.ActiveDocument.ActiveObject)");
|
doCommand(Gui,"PartDesignGui.setActivePart(App.ActiveDocument.ActiveObject)");
|
||||||
// Make the "Create sketch" prompt appear in the task panel
|
// Make the "Create sketch" prompt appear in the task panel
|
||||||
|
@ -163,25 +165,30 @@ void CmdPartDesignMoveTip::activated(int iMsg)
|
||||||
|
|
||||||
std::vector<App::DocumentObject*> features = getSelection().getObjectsOfType(Part::Feature::getClassTypeId());
|
std::vector<App::DocumentObject*> features = getSelection().getObjectsOfType(Part::Feature::getClassTypeId());
|
||||||
if (features.empty()) return;
|
if (features.empty()) return;
|
||||||
Gui::ViewProvider* vp = Gui::Application::Instance->getViewProvider(pcActiveBody);
|
App::DocumentObject* selFeature = features.front();
|
||||||
std::vector<App::DocumentObject*> bodyChildren = vp->claimChildren();
|
|
||||||
|
|
||||||
App::DocumentObject* tipFeature = pcActiveBody->Tip.getValue();
|
if (!pcActiveBody->hasFeature(selFeature)) {
|
||||||
const Gui::ViewProviderDocumentObject* vpFeature = dynamic_cast<Gui::ViewProviderDocumentObject*>(Gui::Application::Instance->getViewProvider(tipFeature));
|
// Switch to other body
|
||||||
PartDesignGui::ActiveGuiDoc->signalHighlightObject(*vpFeature, Gui::Blue, false);
|
pcActiveBody = PartDesign::Body::findBodyOf(selFeature);
|
||||||
|
if (pcActiveBody != NULL)
|
||||||
|
Gui::Command::doCommand(Gui::Command::Gui,"PartDesignGui.setActivePart(App.activeDocument().%s)",
|
||||||
|
pcActiveBody->getNameInDocument());
|
||||||
|
}
|
||||||
|
|
||||||
|
App::DocumentObject* oldTip = pcActiveBody->Tip.getValue();
|
||||||
|
doCommand(Gui,"Gui.activeDocument().hide(\"%s\")", oldTip->getNameInDocument());
|
||||||
|
App::DocumentObject* prevSolidFeature = pcActiveBody->getPrevSolidFeature();
|
||||||
|
if (prevSolidFeature != NULL)
|
||||||
|
doCommand(Gui,"Gui.activeDocument().hide(\"%s\")", prevSolidFeature->getNameInDocument());
|
||||||
|
|
||||||
openCommand("Move insert point to selected feature");
|
openCommand("Move insert point to selected feature");
|
||||||
doCommand(Doc,"App.activeDocument().%s.Tip = App.activeDocument().%s",pcActiveBody->getNameInDocument(),features.front()->getNameInDocument());
|
doCommand(Doc,"App.activeDocument().%s.Tip = App.activeDocument().%s",pcActiveBody->getNameInDocument(), selFeature->getNameInDocument());
|
||||||
|
|
||||||
// Adjust visibility
|
// Adjust visibility to show only the Tip feature and (if the Tip feature is not solid) the solid feature prior to the Tip
|
||||||
for (std::vector<App::DocumentObject*>::const_iterator f = bodyChildren.begin(); f != bodyChildren.end(); f++) {
|
doCommand(Gui,"Gui.activeDocument().show(\"%s\")", selFeature->getNameInDocument());
|
||||||
if ((*f) == pcActiveBody->Tip.getValue()) {
|
prevSolidFeature = pcActiveBody->getPrevSolidFeature();
|
||||||
doCommand(Gui,"Gui.activeDocument().show(\"%s\")", (*f)->getNameInDocument());
|
if ((prevSolidFeature != NULL) && !PartDesign::Body::isSolidFeature(selFeature))
|
||||||
vpFeature = dynamic_cast<Gui::ViewProviderDocumentObject*>(Gui::Application::Instance->getViewProvider(*f));
|
doCommand(Gui,"Gui.activeDocument().show(\"%s\")", prevSolidFeature->getNameInDocument());
|
||||||
PartDesignGui::ActiveGuiDoc->signalHighlightObject(*vpFeature,Gui::Blue,true);
|
|
||||||
} else
|
|
||||||
doCommand(Gui,"Gui.activeDocument().hide(\"%s\")", (*f)->getNameInDocument());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CmdPartDesignMoveTip::isActive(void)
|
bool CmdPartDesignMoveTip::isActive(void)
|
||||||
|
@ -218,19 +225,22 @@ void CmdPartDesignNewSketch::activated(int iMsg)
|
||||||
|
|
||||||
Gui::SelectionFilter SketchFilter("SELECT Sketcher::SketchObject COUNT 1");
|
Gui::SelectionFilter SketchFilter("SELECT Sketcher::SketchObject COUNT 1");
|
||||||
Gui::SelectionFilter FaceFilter ("SELECT Part::Feature SUBELEMENT Face COUNT 1");
|
Gui::SelectionFilter FaceFilter ("SELECT Part::Feature SUBELEMENT Face COUNT 1");
|
||||||
Gui::SelectionFilter PlaneFilter ("SELECT App::Plane COUNT 1");
|
Gui::SelectionFilter PlaneFilter1 ("SELECT App::Plane COUNT 1");
|
||||||
|
Gui::SelectionFilter PlaneFilter2 ("SELECT PartDesign::Plane COUNT 1");
|
||||||
|
|
||||||
if (SketchFilter.match()) {
|
if (SketchFilter.match()) {
|
||||||
Sketcher::SketchObject *Sketch = static_cast<Sketcher::SketchObject*>(SketchFilter.Result[0][0].getObject());
|
Sketcher::SketchObject *Sketch = static_cast<Sketcher::SketchObject*>(SketchFilter.Result[0][0].getObject());
|
||||||
openCommand("Edit Sketch");
|
openCommand("Edit Sketch");
|
||||||
doCommand(Gui,"Gui.activeDocument().setEdit('%s')",Sketch->getNameInDocument());
|
doCommand(Gui,"Gui.activeDocument().setEdit('%s')",Sketch->getNameInDocument());
|
||||||
}
|
}
|
||||||
else if (FaceFilter.match() || PlaneFilter.match()) {
|
else if (FaceFilter.match() || PlaneFilter1.match() || PlaneFilter2.match()) {
|
||||||
// get the selected object
|
// get the selected object
|
||||||
std::string supportString;
|
std::string supportString;
|
||||||
|
|
||||||
if (FaceFilter.match()) {
|
if (FaceFilter.match()) {
|
||||||
Part::Feature *part = static_cast<Part::Feature*>(FaceFilter.Result[0][0].getObject());
|
Part::Feature *part = static_cast<Part::Feature*>(FaceFilter.Result[0][0].getObject());
|
||||||
|
// FIXME: Reject or warn about feature that is outside of active body, and feature
|
||||||
|
// that comes after the current insert point (Tip)
|
||||||
const std::vector<std::string> &sub = FaceFilter.Result[0][0].getSubNames();
|
const std::vector<std::string> &sub = FaceFilter.Result[0][0].getSubNames();
|
||||||
if (sub.size() > 1){
|
if (sub.size() > 1){
|
||||||
// No assert for wrong user input!
|
// No assert for wrong user input!
|
||||||
|
@ -258,32 +268,20 @@ void CmdPartDesignNewSketch::activated(int iMsg)
|
||||||
|
|
||||||
supportString = FaceFilter.Result[0][0].getAsPropertyLinkSubString();
|
supportString = FaceFilter.Result[0][0].getAsPropertyLinkSubString();
|
||||||
} else {
|
} else {
|
||||||
supportString = PlaneFilter.Result[0][0].getAsPropertyLinkSubString();
|
if (PlaneFilter1.match())
|
||||||
|
supportString = PlaneFilter1.Result[0][0].getAsPropertyLinkSubString();
|
||||||
|
else
|
||||||
|
supportString = PlaneFilter2.Result[0][0].getAsPropertyLinkSubString();
|
||||||
}
|
}
|
||||||
|
|
||||||
// create Sketch on Face
|
// create Sketch on Face
|
||||||
std::string FeatName = getUniqueObjectName("Sketch");
|
std::string FeatName = getUniqueObjectName("Sketch");
|
||||||
App::DocumentObject* nextSolidFeature = pcActiveBody->getNextSolidFeature();
|
|
||||||
|
|
||||||
openCommand("Create a Sketch on Face");
|
openCommand("Create a Sketch on Face");
|
||||||
doCommand(Doc,"App.activeDocument().addObject('Sketcher::SketchObject','%s')",FeatName.c_str());
|
doCommand(Doc,"App.activeDocument().addObject('Sketcher::SketchObject','%s')",FeatName.c_str());
|
||||||
if (nextSolidFeature != NULL) {
|
doCommand(Doc,"App.activeDocument().%s.Support = %s",FeatName.c_str(),supportString.c_str());
|
||||||
// Insert mode
|
doCommand(Doc,"App.activeDocument().%s.insertFeature(App.activeDocument().%s)",
|
||||||
doCommand(Doc,"m = App.activeDocument().%s.Model; "
|
pcActiveBody->getNameInDocument(), FeatName.c_str());
|
||||||
"m.insert(m.index(App.activeDocument().%s.Tip) + 1, App.activeDocument().%s);"
|
|
||||||
"App.activeDocument().%s.Model = m",
|
|
||||||
pcActiveBody->getNameInDocument(),
|
|
||||||
pcActiveBody->getNameInDocument(),FeatName.c_str(),
|
|
||||||
pcActiveBody->getNameInDocument());
|
|
||||||
} else {
|
|
||||||
doCommand(Doc,"App.activeDocument().%s.Model = "
|
|
||||||
"App.activeDocument().%s.Model + [App.activeDocument().%s]",
|
|
||||||
pcActiveBody->getNameInDocument(),
|
|
||||||
pcActiveBody->getNameInDocument(),FeatName.c_str());
|
|
||||||
}
|
|
||||||
doCommand(Doc,"App.activeDocument().%s.Tip = App.activeDocument().%s",
|
|
||||||
pcActiveBody->getNameInDocument(),FeatName.c_str());
|
|
||||||
doCommand(Gui,"App.activeDocument().%s.Support = %s",FeatName.c_str(),supportString.c_str());
|
|
||||||
doCommand(Gui,"App.activeDocument().recompute()"); // recompute the sketch placement based on its support
|
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().activeView().setCamera('%s')",cam.c_str());
|
||||||
doCommand(Gui,"Gui.activeDocument().setEdit('%s')",FeatName.c_str());
|
doCommand(Gui,"Gui.activeDocument().setEdit('%s')",FeatName.c_str());
|
||||||
|
@ -292,6 +290,8 @@ void CmdPartDesignNewSketch::activated(int iMsg)
|
||||||
// Get a valid plane from the user
|
// Get a valid plane from the user
|
||||||
std::vector<PartDesignGui::FeaturePickDialog::featureStatus> status;
|
std::vector<PartDesignGui::FeaturePickDialog::featureStatus> status;
|
||||||
std::vector<App::DocumentObject*> planes = getDocument()->getObjectsOfType(App::Plane::getClassTypeId());
|
std::vector<App::DocumentObject*> planes = getDocument()->getObjectsOfType(App::Plane::getClassTypeId());
|
||||||
|
std::vector<App::DocumentObject*> planestmp = getDocument()->getObjectsOfType(PartDesign::Plane::getClassTypeId());
|
||||||
|
planes.insert(planes.end(), planestmp.begin(), planestmp.end());
|
||||||
|
|
||||||
unsigned validPlanes = 0;
|
unsigned validPlanes = 0;
|
||||||
std::vector<App::DocumentObject*>::const_iterator firstValidPlane = planes.end();
|
std::vector<App::DocumentObject*>::const_iterator firstValidPlane = planes.end();
|
||||||
|
@ -316,6 +316,10 @@ void CmdPartDesignNewSketch::activated(int iMsg)
|
||||||
if (!body->hasFeature(*p)) {
|
if (!body->hasFeature(*p)) {
|
||||||
status.push_back(PartDesignGui::FeaturePickDialog::otherBody);
|
status.push_back(PartDesignGui::FeaturePickDialog::otherBody);
|
||||||
continue;
|
continue;
|
||||||
|
} else {
|
||||||
|
if (body->isAfterTip(*p))
|
||||||
|
status.push_back(PartDesignGui::FeaturePickDialog::afterTip);
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// All checks passed - found a valid plane
|
// All checks passed - found a valid plane
|
||||||
|
@ -345,27 +349,14 @@ void CmdPartDesignNewSketch::activated(int iMsg)
|
||||||
|
|
||||||
std::string FeatName = getUniqueObjectName("Sketch");
|
std::string FeatName = getUniqueObjectName("Sketch");
|
||||||
std::string supportString = std::string("(App.activeDocument().") + plane->getNameInDocument() + ", [])";
|
std::string supportString = std::string("(App.activeDocument().") + plane->getNameInDocument() + ", [])";
|
||||||
App::DocumentObject* nextSolidFeature = pcActiveBody->getNextSolidFeature();
|
|
||||||
|
|
||||||
openCommand("Create a new Sketch");
|
openCommand("Create a new Sketch");
|
||||||
doCommand(Doc,"App.activeDocument().addObject('Sketcher::SketchObject','%s')",FeatName.c_str());
|
doCommand(Doc,"App.activeDocument().addObject('Sketcher::SketchObject','%s')",FeatName.c_str());
|
||||||
doCommand(Doc,"App.activeDocument().%s.Support = %s",FeatName.c_str(),supportString.c_str());
|
doCommand(Doc,"App.activeDocument().%s.Support = %s",FeatName.c_str(),supportString.c_str());
|
||||||
doCommand(Doc,"App.activeDocument().%s.Placement = App.Placement(App.Vector(%f,%f,%f),App.Rotation(%f,%f,%f,%f))",FeatName.c_str(),p.x,p.y,p.z,r[0],r[1],r[2],r[3]);
|
doCommand(Doc,"App.activeDocument().%s.Placement = App.Placement(App.Vector(%f,%f,%f),App.Rotation(%f,%f,%f,%f))",FeatName.c_str(),p.x,p.y,p.z,r[0],r[1],r[2],r[3]);
|
||||||
if (nextSolidFeature != NULL) {
|
doCommand(Doc,"App.activeDocument().%s.insertFeature(App.activeDocument().%s)",
|
||||||
// Insert mode
|
pcActiveBody->getNameInDocument(), FeatName.c_str());
|
||||||
doCommand(Doc,"m = App.activeDocument().%s.Model; "
|
//doCommand(Gui,"Gui.activeDocument().activeView().setCamera('%s')",cam.c_str());
|
||||||
"m.insert(m.index(App.activeDocument().%s.Tip) + 1, App.activeDocument().%s);"
|
|
||||||
"App.activeDocument().%s.Model = m",
|
|
||||||
pcActiveBody->getNameInDocument(),
|
|
||||||
pcActiveBody->getNameInDocument(),FeatName.c_str(),
|
|
||||||
pcActiveBody->getNameInDocument());
|
|
||||||
} else {
|
|
||||||
doCommand(Doc,"App.activeDocument().%s.Model = "
|
|
||||||
"App.activeDocument().%s.Model + [App.activeDocument().%s]",
|
|
||||||
pcActiveBody->getNameInDocument(),
|
|
||||||
pcActiveBody->getNameInDocument(),FeatName.c_str());
|
|
||||||
}
|
|
||||||
doCommand(Doc,"App.activeDocument().%s.Tip = App.activeDocument().%s",pcActiveBody->getNameInDocument(),FeatName.c_str());
|
|
||||||
doCommand(Gui,"Gui.activeDocument().setEdit('%s')",FeatName.c_str());
|
doCommand(Gui,"Gui.activeDocument().setEdit('%s')",FeatName.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -447,8 +438,7 @@ bool CmdPartDesignNewSketch::isActive(void)
|
||||||
return validSketches;
|
return validSketches;
|
||||||
}
|
}
|
||||||
|
|
||||||
void prepareSketchBased(Gui::Command* cmd, const std::string& which,
|
void prepareSketchBased(Gui::Command* cmd, const std::string& which, Part::Part2DObject*& sketch, std::string& FeatName)
|
||||||
Part::Part2DObject*& sketch, std::string& FeatName, App::DocumentObject*& prevSolidFeature)
|
|
||||||
{
|
{
|
||||||
PartDesign::Body *pcActiveBody = PartDesignGui::getBody();
|
PartDesign::Body *pcActiveBody = PartDesignGui::getBody();
|
||||||
if (!pcActiveBody) return;
|
if (!pcActiveBody) return;
|
||||||
|
@ -481,43 +471,18 @@ void prepareSketchBased(Gui::Command* cmd, const std::string& which,
|
||||||
|
|
||||||
sketch = static_cast<Part::Part2DObject*>(*firstValidSketch);
|
sketch = static_cast<Part::Part2DObject*>(*firstValidSketch);
|
||||||
|
|
||||||
// Find valid Body feature to set as the base feature
|
|
||||||
prevSolidFeature = pcActiveBody->getTipSolidFeature();
|
|
||||||
App::DocumentObject* nextSolidFeature = pcActiveBody->getNextSolidFeature();
|
|
||||||
FeatName = cmd->getUniqueObjectName(which.c_str());
|
FeatName = cmd->getUniqueObjectName(which.c_str());
|
||||||
|
|
||||||
cmd->openCommand((std::string("Make ") + which).c_str());
|
cmd->openCommand((std::string("Make ") + which).c_str());
|
||||||
cmd->doCommand(cmd->Doc,"App.activeDocument().addObject(\"PartDesign::%s\",\"%s\")",which.c_str(), FeatName.c_str());
|
cmd->doCommand(cmd->Doc,"App.activeDocument().addObject(\"PartDesign::%s\",\"%s\")",
|
||||||
if (prevSolidFeature != NULL)
|
which.c_str(), FeatName.c_str());
|
||||||
// Set BaseFeature property to previous feature
|
|
||||||
cmd->doCommand(cmd->Doc,"App.activeDocument().%s.BaseFeature = App.activeDocument().%s",
|
|
||||||
FeatName.c_str(),prevSolidFeature->getNameInDocument());
|
|
||||||
if (nextSolidFeature != NULL) {
|
|
||||||
// Insert mode
|
|
||||||
cmd->doCommand(cmd->Doc,"m = App.activeDocument().%s.Model; "
|
|
||||||
"m.insert(m.index(App.activeDocument().%s.Tip) + 1, App.activeDocument().%s);"
|
|
||||||
"App.activeDocument().%s.Model = m",
|
|
||||||
pcActiveBody->getNameInDocument(),
|
|
||||||
pcActiveBody->getNameInDocument(),FeatName.c_str(),
|
|
||||||
pcActiveBody->getNameInDocument());
|
|
||||||
// Reroute BaseFeature property of the next feature to this feature
|
|
||||||
cmd->doCommand(cmd->Doc,"App.activeDocument().%s.BaseFeature = App.activeDocument().%s",
|
|
||||||
nextSolidFeature->getNameInDocument(), FeatName.c_str());
|
|
||||||
} else {
|
|
||||||
cmd->doCommand(cmd->Doc,"App.activeDocument().%s.Model = "
|
|
||||||
"App.activeDocument().%s.Model + [App.activeDocument().%s]",
|
|
||||||
pcActiveBody->getNameInDocument(),
|
|
||||||
pcActiveBody->getNameInDocument(),FeatName.c_str());
|
|
||||||
}
|
|
||||||
cmd->doCommand(cmd->Doc,"App.activeDocument().%s.Tip = App.activeDocument().%s",
|
|
||||||
pcActiveBody->getNameInDocument(),FeatName.c_str());
|
|
||||||
|
|
||||||
cmd->doCommand(cmd->Doc,"App.activeDocument().%s.Sketch = App.activeDocument().%s",
|
cmd->doCommand(cmd->Doc,"App.activeDocument().%s.Sketch = App.activeDocument().%s",
|
||||||
FeatName.c_str(),sketch->getNameInDocument());
|
FeatName.c_str(), sketch->getNameInDocument());
|
||||||
|
cmd->doCommand(cmd->Doc,"App.activeDocument().%s.insertFeature(App.activeDocument().%s)",
|
||||||
|
pcActiveBody->getNameInDocument(), FeatName.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void finishSketchBased(const Gui::Command* cmd,
|
void finishSketchBased(const Gui::Command* cmd, const Part::Part2DObject* sketch, const std::string& FeatName)
|
||||||
const Part::Part2DObject* sketch, const std::string& FeatName, const App::DocumentObject* prevSolidFeature)
|
|
||||||
{
|
{
|
||||||
App::DocumentObjectGroup* grp = sketch->getGroup();
|
App::DocumentObjectGroup* grp = sketch->getGroup();
|
||||||
if (grp) {
|
if (grp) {
|
||||||
|
@ -528,10 +493,14 @@ void finishSketchBased(const Gui::Command* cmd,
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd->updateActive();
|
cmd->updateActive();
|
||||||
|
PartDesign::Body *pcActiveBody = PartDesignGui::getBody();
|
||||||
if (cmd->isActiveObjectValid()) {
|
if (cmd->isActiveObjectValid()) {
|
||||||
cmd->doCommand(cmd->Gui,"Gui.activeDocument().hide(\"%s\")", sketch->getNameInDocument());
|
cmd->doCommand(cmd->Gui,"Gui.activeDocument().hide(\"%s\")", sketch->getNameInDocument());
|
||||||
if (prevSolidFeature != NULL)
|
if (pcActiveBody != NULL) {
|
||||||
cmd->doCommand(cmd->Gui,"Gui.activeDocument().hide(\"%s\")", prevSolidFeature->getNameInDocument());
|
App::DocumentObject* prevSolidFeature = pcActiveBody->getPrevSolidFeature(NULL, false);
|
||||||
|
if (prevSolidFeature != NULL)
|
||||||
|
cmd->doCommand(cmd->Gui,"Gui.activeDocument().hide(\"%s\")", prevSolidFeature->getNameInDocument());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// #0001721: use '0' as edit value to avoid switching off selection in
|
// #0001721: use '0' as edit value to avoid switching off selection in
|
||||||
// ViewProviderGeometryObject::setEditViewer
|
// ViewProviderGeometryObject::setEditViewer
|
||||||
|
@ -539,7 +508,6 @@ void finishSketchBased(const Gui::Command* cmd,
|
||||||
cmd->doCommand(cmd->Gui,"Gui.Selection.clearSelection()");
|
cmd->doCommand(cmd->Gui,"Gui.Selection.clearSelection()");
|
||||||
cmd->doCommand(cmd->Gui,"Gui.Selection.addSelection(App.ActiveDocument.ActiveObject)");
|
cmd->doCommand(cmd->Gui,"Gui.Selection.addSelection(App.ActiveDocument.ActiveObject)");
|
||||||
|
|
||||||
PartDesign::Body *pcActiveBody = PartDesignGui::getBody();
|
|
||||||
if (pcActiveBody) {
|
if (pcActiveBody) {
|
||||||
cmd->copyVisual(FeatName.c_str(), "ShapeColor", pcActiveBody->getNameInDocument());
|
cmd->copyVisual(FeatName.c_str(), "ShapeColor", pcActiveBody->getNameInDocument());
|
||||||
cmd->copyVisual(FeatName.c_str(), "LineColor", pcActiveBody->getNameInDocument());
|
cmd->copyVisual(FeatName.c_str(), "LineColor", pcActiveBody->getNameInDocument());
|
||||||
|
@ -568,14 +536,13 @@ void CmdPartDesignPad::activated(int iMsg)
|
||||||
{
|
{
|
||||||
Part::Part2DObject* sketch;
|
Part::Part2DObject* sketch;
|
||||||
std::string FeatName;
|
std::string FeatName;
|
||||||
App::DocumentObject* prevSolidFeature;
|
prepareSketchBased(this, "Pad", sketch, FeatName);
|
||||||
prepareSketchBased(this, "Pad", sketch, FeatName, prevSolidFeature);
|
|
||||||
if (FeatName.empty()) return;
|
if (FeatName.empty()) return;
|
||||||
|
|
||||||
// specific parameters for Pad
|
// specific parameters for Pad
|
||||||
doCommand(Doc,"App.activeDocument().%s.Length = 10.0",FeatName.c_str());
|
doCommand(Doc,"App.activeDocument().%s.Length = 10.0",FeatName.c_str());
|
||||||
|
|
||||||
finishSketchBased(this, sketch, FeatName, prevSolidFeature);
|
finishSketchBased(this, sketch, FeatName);
|
||||||
adjustCameraPosition();
|
adjustCameraPosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -605,13 +572,12 @@ void CmdPartDesignPocket::activated(int iMsg)
|
||||||
{
|
{
|
||||||
Part::Part2DObject* sketch;
|
Part::Part2DObject* sketch;
|
||||||
std::string FeatName;
|
std::string FeatName;
|
||||||
App::DocumentObject* prevSolidFeature;
|
prepareSketchBased(this, "Pocket", sketch, FeatName);
|
||||||
prepareSketchBased(this, "Pocket", sketch, FeatName, prevSolidFeature);
|
|
||||||
if (FeatName.empty()) return;
|
if (FeatName.empty()) return;
|
||||||
|
|
||||||
doCommand(Doc,"App.activeDocument().%s.Length = 5.0",FeatName.c_str());
|
doCommand(Doc,"App.activeDocument().%s.Length = 5.0",FeatName.c_str());
|
||||||
|
|
||||||
finishSketchBased(this, sketch, FeatName, prevSolidFeature);
|
finishSketchBased(this, sketch, FeatName);
|
||||||
adjustCameraPosition();
|
adjustCameraPosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -641,8 +607,7 @@ void CmdPartDesignRevolution::activated(int iMsg)
|
||||||
{
|
{
|
||||||
Part::Part2DObject* sketch;
|
Part::Part2DObject* sketch;
|
||||||
std::string FeatName;
|
std::string FeatName;
|
||||||
App::DocumentObject* prevSolidFeature;
|
prepareSketchBased(this, "Revolution", sketch, FeatName);
|
||||||
prepareSketchBased(this, "Revolution", sketch, FeatName, prevSolidFeature);
|
|
||||||
if (FeatName.empty()) return;
|
if (FeatName.empty()) return;
|
||||||
|
|
||||||
doCommand(Doc,"App.activeDocument().%s.ReferenceAxis = (App.activeDocument().%s,['V_Axis'])",
|
doCommand(Doc,"App.activeDocument().%s.ReferenceAxis = (App.activeDocument().%s,['V_Axis'])",
|
||||||
|
@ -652,7 +617,7 @@ void CmdPartDesignRevolution::activated(int iMsg)
|
||||||
if (pcRevolution && pcRevolution->suggestReversed())
|
if (pcRevolution && pcRevolution->suggestReversed())
|
||||||
doCommand(Doc,"App.activeDocument().%s.Reversed = 1",FeatName.c_str());
|
doCommand(Doc,"App.activeDocument().%s.Reversed = 1",FeatName.c_str());
|
||||||
|
|
||||||
finishSketchBased(this, sketch, FeatName, prevSolidFeature);
|
finishSketchBased(this, sketch, FeatName);
|
||||||
adjustCameraPosition();
|
adjustCameraPosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -682,8 +647,7 @@ void CmdPartDesignGroove::activated(int iMsg)
|
||||||
{
|
{
|
||||||
Part::Part2DObject* sketch;
|
Part::Part2DObject* sketch;
|
||||||
std::string FeatName;
|
std::string FeatName;
|
||||||
App::DocumentObject* prevSolidFeature;
|
prepareSketchBased(this, "Groove", sketch, FeatName);
|
||||||
prepareSketchBased(this, "Groove", sketch, FeatName, prevSolidFeature);
|
|
||||||
if (FeatName.empty()) return;
|
if (FeatName.empty()) return;
|
||||||
|
|
||||||
doCommand(Doc,"App.activeDocument().%s.ReferenceAxis = (App.activeDocument().%s,['V_Axis'])",
|
doCommand(Doc,"App.activeDocument().%s.ReferenceAxis = (App.activeDocument().%s,['V_Axis'])",
|
||||||
|
@ -693,7 +657,7 @@ void CmdPartDesignGroove::activated(int iMsg)
|
||||||
if (pcGroove && pcGroove->suggestReversed())
|
if (pcGroove && pcGroove->suggestReversed())
|
||||||
doCommand(Doc,"App.activeDocument().%s.Reversed = 1",FeatName.c_str());
|
doCommand(Doc,"App.activeDocument().%s.Reversed = 1",FeatName.c_str());
|
||||||
|
|
||||||
finishSketchBased(this, sketch, FeatName, prevSolidFeature);
|
finishSketchBased(this, sketch, FeatName);
|
||||||
adjustCameraPosition();
|
adjustCameraPosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,6 +48,7 @@ const QString FeaturePickDialog::getFeatureStatusString(const featureStatus st)
|
||||||
case isUsed: return tr("Sketch already used by other feature");
|
case isUsed: return tr("Sketch already used by other feature");
|
||||||
case otherBody: return tr("Sketch belongs to another Body feature");
|
case otherBody: return tr("Sketch belongs to another Body feature");
|
||||||
case basePlane: return tr("Base plane");
|
case basePlane: return tr("Base plane");
|
||||||
|
case afterTip: return tr("Feature is located after the Tip feature");
|
||||||
}
|
}
|
||||||
|
|
||||||
return tr("");
|
return tr("");
|
||||||
|
@ -106,6 +107,7 @@ void FeaturePickDialog::updateList()
|
||||||
case isUsed: item->setFlags(ui->checkOtherFeature->isChecked() ? Qt::ItemIsSelectable | Qt::ItemIsEnabled : Qt::NoItemFlags); break;
|
case isUsed: item->setFlags(ui->checkOtherFeature->isChecked() ? Qt::ItemIsSelectable | Qt::ItemIsEnabled : Qt::NoItemFlags); break;
|
||||||
case otherBody: item->setFlags(ui->checkOtherBody->isChecked() ? Qt::ItemIsSelectable | Qt::ItemIsEnabled : Qt::NoItemFlags); break;
|
case otherBody: item->setFlags(ui->checkOtherBody->isChecked() ? Qt::ItemIsSelectable | Qt::ItemIsEnabled : Qt::NoItemFlags); break;
|
||||||
case basePlane: item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); break;
|
case basePlane: item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); break;
|
||||||
|
case afterTip: item->setFlags(Qt::NoItemFlags); break;
|
||||||
}
|
}
|
||||||
|
|
||||||
index++;
|
index++;
|
||||||
|
|
|
@ -41,7 +41,8 @@ public:
|
||||||
noWire,
|
noWire,
|
||||||
isUsed,
|
isUsed,
|
||||||
otherBody,
|
otherBody,
|
||||||
basePlane
|
basePlane,
|
||||||
|
afterTip
|
||||||
};
|
};
|
||||||
|
|
||||||
FeaturePickDialog(std::vector<App::DocumentObject*> &objects, const std::vector<featureStatus> &status);
|
FeaturePickDialog(std::vector<App::DocumentObject*> &objects, const std::vector<featureStatus> &status);
|
||||||
|
|
|
@ -27,8 +27,11 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "ViewProvider.h"
|
#include "ViewProvider.h"
|
||||||
|
#include "Workbench.h"
|
||||||
|
#include <Mod/PartDesign/App/Body.h>
|
||||||
#include <Mod/Part/App/PropertyTopoShape.h>
|
#include <Mod/Part/App/PropertyTopoShape.h>
|
||||||
#include <Gui/Command.h>
|
#include <Gui/Command.h>
|
||||||
|
#include <Gui/Application.h>
|
||||||
#include <Base/Exception.h>
|
#include <Base/Exception.h>
|
||||||
|
|
||||||
using namespace PartDesignGui;
|
using namespace PartDesignGui;
|
||||||
|
@ -69,3 +72,25 @@ void ViewProvider::updateData(const App::Property* prop)
|
||||||
}
|
}
|
||||||
inherited::updateData(prop);
|
inherited::updateData(prop);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ViewProvider::onDelete(const std::vector<std::string> &)
|
||||||
|
{
|
||||||
|
// Body feature housekeeping
|
||||||
|
PartDesign::Body* body = PartDesign::Body::findBodyOf(getObject());
|
||||||
|
if (body != NULL) {
|
||||||
|
body->removeFeature(getObject());
|
||||||
|
// Make the new Tip and the previous solid feature visible again
|
||||||
|
App::DocumentObject* tip = body->Tip.getValue();
|
||||||
|
App::DocumentObject* prev = body->getPrevSolidFeature();
|
||||||
|
Gui::Application::Instance->getViewProvider(tip)->show();
|
||||||
|
if (tip != prev)
|
||||||
|
Gui::Application::Instance->getViewProvider(prev)->show();
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Ask user what to do about dependent objects, e.g. Sketches that have this feature as their support
|
||||||
|
// 1. Delete
|
||||||
|
// 2. Suppress
|
||||||
|
// 3. Re-route
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
|
@ -41,6 +41,8 @@ public:
|
||||||
|
|
||||||
virtual bool doubleClicked(void);
|
virtual bool doubleClicked(void);
|
||||||
void updateData(const App::Property*);
|
void updateData(const App::Property*);
|
||||||
|
|
||||||
|
virtual bool onDelete(const std::vector<std::string> &);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user