Skip to content

Commit

Permalink
PartDesign: Primitives are attachable directly
Browse files Browse the repository at this point in the history
With the recently introduced AttachExtension the PartDesign primitives can be attachable by themself and don't need anymore the helping coordinate system datum. This simplyfies the code and the TreeView largely
  • Loading branch information
ickby committed Dec 7, 2016
1 parent d0d4d6b commit bc133e4
Show file tree
Hide file tree
Showing 8 changed files with 8 additions and 103 deletions.
10 changes: 3 additions & 7 deletions src/Mod/PartDesign/App/FeaturePrimitive.cpp
Expand Up @@ -59,12 +59,12 @@ const App::PropertyQuantityConstraint::Constraints angleRangeU = {0.0,360.0,1.0}
const App::PropertyQuantityConstraint::Constraints angleRangeV = {-90.0,90.0,1.0};
const App::PropertyQuantityConstraint::Constraints quantityRange = {0.0,FLT_MAX,0.1};

PROPERTY_SOURCE(PartDesign::FeaturePrimitive, PartDesign::FeatureAddSub)
PROPERTY_SOURCE_WITH_EXTENSIONS(PartDesign::FeaturePrimitive, PartDesign::FeatureAddSub)

FeaturePrimitive::FeaturePrimitive()
: primitiveType(Box)
{
ADD_PROPERTY_TYPE(CoordinateSystem, (0), "Primitive", App::Prop_None, "References to build the location of the primitive");
Part::AttachExtension::initExtension(this);
}

TopoDS_Shape FeaturePrimitive::refineShapeIfActive(const TopoDS_Shape& oldShape) const
Expand All @@ -84,11 +84,7 @@ App::DocumentObjectExecReturn* FeaturePrimitive::execute(const TopoDS_Shape& pri
{
try {
//transform the primitive in the correct coordinance
App::DocumentObject* cs = CoordinateSystem.getValue();
if(cs && cs->getTypeId() == PartDesign::CoordinateSystem::getClassTypeId())
Placement.setValue(static_cast<PartDesign::CoordinateSystem*>(cs)->Placement.getValue());
else
Placement.setValue(Base::Placement());
FeatureAddSub::execute();

//if we have no base we just add the standard primitive shape
TopoDS_Shape base;
Expand Down
8 changes: 3 additions & 5 deletions src/Mod/PartDesign/App/FeaturePrimitive.h
Expand Up @@ -28,13 +28,14 @@
#include <App/PropertyUnits.h>

#include "FeatureAddSub.h"
#include <Mod/Part/App/AttachExtension.h>

namespace PartDesign
{

class PartDesignExport FeaturePrimitive : public PartDesign::FeatureAddSub
class PartDesignExport FeaturePrimitive : public PartDesign::FeatureAddSub, public Part::AttachExtension
{
PROPERTY_HEADER(PartDesign::FeaturePrimitive);
PROPERTY_HEADER_WITH_EXTENSIONS(PartDesign::FeaturePrimitive);

public:
enum Type {
Expand All @@ -57,9 +58,6 @@ class PartDesignExport FeaturePrimitive : public PartDesign::FeatureAddSub
TopoDS_Shape refineShapeIfActive(const TopoDS_Shape& oldShape) const;
virtual void onChanged(const App::Property* prop);

/// The references datum defining the primtive location
App::PropertyLink CoordinateSystem;

/// Do nothing, just to suppress warning, must be redefined in derived classes
virtual App::DocumentObjectExecReturn* execute() {
return PartDesign::FeatureAddSub::execute();
Expand Down
16 changes: 0 additions & 16 deletions src/Mod/PartDesign/Gui/CommandPrimitive.cpp
Expand Up @@ -67,7 +67,6 @@ void CmdPrimtiveCompAdditive::activated(int iMsg)
pcAction->setIcon(pcAction->actions().at(iMsg)->icon());

std::string FeatName;
std::string CSName = getUniqueObjectName("CoordinateSystem");;
if(iMsg == 0) {

FeatName = getUniqueObjectName("Box");
Expand Down Expand Up @@ -136,19 +135,12 @@ void CmdPrimtiveCompAdditive::activated(int iMsg)

Gui::Command::doCommand(Doc,"App.ActiveDocument.%s.addFeature(App.activeDocument().%s)"
,pcActiveBody->getNameInDocument(), FeatName.c_str());
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.addObject(\'PartDesign::CoordinateSystem\',\'%s\')",
CSName.c_str());
Gui::Command::doCommand(Doc,"App.ActiveDocument.%s.addFeature(App.activeDocument().%s)"
,pcActiveBody->getNameInDocument(), CSName.c_str());
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.CoordinateSystem=(App.ActiveDocument.%s)",
FeatName.c_str(), CSName.c_str());
Gui::Command::updateActive();

auto* prm = static_cast<PartDesign::FeaturePrimitive*>(getDocument()->getObject(FeatName.c_str()));
if (prm->BaseFeature.getValue())
doCommand(Gui,"Gui.activeDocument().hide(\"%s\")", prm->BaseFeature.getValue()->getNameInDocument());

Gui::Command::doCommand(Gui, "Gui.activeDocument().hide(\'%s\')", CSName.c_str());
Gui::Command::doCommand(Gui, "Gui.activeDocument().setEdit(\'%s\')", FeatName.c_str());
}

Expand Down Expand Up @@ -265,7 +257,6 @@ void CmdPrimtiveCompSubtractive::activated(int iMsg)
}

std::string FeatName;
std::string CSName = getUniqueObjectName("CoordinateSystem");
if(iMsg == 0) {

FeatName = getUniqueObjectName("Box");
Expand Down Expand Up @@ -333,12 +324,6 @@ void CmdPrimtiveCompSubtractive::activated(int iMsg)

Gui::Command::doCommand(Doc,"App.ActiveDocument.%s.addFeature(App.activeDocument().%s)"
,pcActiveBody->getNameInDocument(), FeatName.c_str());
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.addObject(\'PartDesign::CoordinateSystem\',\'%s\')",
CSName.c_str());
Gui::Command::doCommand(Doc,"App.ActiveDocument.%s.addFeature(App.activeDocument().%s)"
,pcActiveBody->getNameInDocument(), CSName.c_str());
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.CoordinateSystem=(App.ActiveDocument.%s)",
FeatName.c_str(), CSName.c_str());
Gui::Command::updateActive();

if (isActiveObjectValid() && (pcActiveBody != NULL)) {
Expand All @@ -348,7 +333,6 @@ void CmdPrimtiveCompSubtractive::activated(int iMsg)
}
}

Gui::Command::doCommand(Gui, "Gui.activeDocument().hide(\'%s\')", CSName.c_str());
Gui::Command::doCommand(Gui, "Gui.activeDocument().setEdit(\'%s\')", FeatName.c_str());
}

Expand Down
50 changes: 2 additions & 48 deletions src/Mod/PartDesign/Gui/TaskPrimitiveParameters.cpp
Expand Up @@ -601,62 +601,25 @@ TaskPrimitiveParameters::TaskPrimitiveParameters(ViewProviderPrimitive* Primitiv
{

assert(PrimitiveView);

PartDesign::FeaturePrimitive* prm = static_cast<PartDesign::FeaturePrimitive*>(PrimitiveView->getObject());
cs = static_cast<PartDesign::CoordinateSystem*>(prm->CoordinateSystem.getValue());

//if no coordinate system exist we need to add one, it is highly important that it exists!
if(!cs) {
std::string CSName = App::GetApplication().getActiveDocument()->getUniqueObjectName("CoordinateSystem");
cs = static_cast<PartDesign::CoordinateSystem*>(
App::GetApplication().getActiveDocument()->addObject("PartDesign::CoordinateSystem", CSName.c_str()));
prm->CoordinateSystem.setValue(cs);
}

ViewProviderDatumCoordinateSystem* vp = static_cast<ViewProviderDatumCoordinateSystem*>(
Gui::Application::Instance->activeDocument()->getViewProvider(cs));

assert(vp);

//make sure the relevant things are visible
cs_visibility = vp->isVisible();
vp->Visibility.setValue(true);

parameter = new TaskDatumParameters(vp);
Content.push_back(parameter);
//parameter = new TaskDatumParameters(vp);
//Content.push_back(parameter);

primitive = new TaskBoxPrimitives(PrimitiveView);
Content.push_back(primitive);

//make sure we track changes from the coordinate system to the primitive position
auto bnd = boost::bind(&TaskPrimitiveParameters::objectChanged, this, _1, _2);
connection = vp_prm->getObject()->getDocument()->signalChangedObject.connect(bnd);
}

TaskPrimitiveParameters::~TaskPrimitiveParameters()
{

}

void TaskPrimitiveParameters::objectChanged(const App::DocumentObject& obj, const App::Property& p)
{
if (&obj == cs && strcmp(p.getName(), "Placement")==0) {
vp_prm->getObject()->recomputeFeature();
}
}

bool TaskPrimitiveParameters::accept()
{
primitive->setPrimitive(QString::fromUtf8(vp_prm->getObject()->getNameInDocument()));
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.recompute()");
Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()");

ViewProviderDatumCoordinateSystem* vp = static_cast<ViewProviderDatumCoordinateSystem*>(
Gui::Application::Instance->activeDocument()->getViewProvider(cs));
vp->setVisible(cs_visibility);

connection.disconnect();

return true;
}

Expand All @@ -666,15 +629,6 @@ bool TaskPrimitiveParameters::reject()
Gui::Command::abortCommand();
Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()");

//if we did not delete the document object we need to set the visibilities right
ViewProviderDatumCoordinateSystem* vp = static_cast<ViewProviderDatumCoordinateSystem*>(
Gui::Application::Instance->activeDocument()->getViewProvider(cs));

if (vp)
vp->setVisible(cs_visibility);

connection.disconnect();

return true;
}

Expand Down
5 changes: 0 additions & 5 deletions src/Mod/PartDesign/Gui/TaskPrimitiveParameters.h
Expand Up @@ -113,21 +113,16 @@ class TaskPrimitiveParameters : public Gui::TaskView::TaskDialog
TaskPrimitiveParameters(ViewProviderPrimitive *PrimitiveView);
~TaskPrimitiveParameters();

void objectChanged(const App::DocumentObject&, const App::Property&);

protected:
virtual QDialogButtonBox::StandardButtons getStandardButtons(void) const;

virtual bool accept();
virtual bool reject();

private:
s::connection connection;
TaskBoxPrimitives* primitive;
TaskDatumParameters* parameter;
PartDesign::CoordinateSystem* cs;
ViewProviderPrimitive* vp_prm;
bool cs_visibility;
};

} //namespace PartDesignGui
Expand Down
14 changes: 0 additions & 14 deletions src/Mod/PartDesign/Gui/Utils.cpp
Expand Up @@ -355,13 +355,6 @@ bool isFeatureMovable(App::DocumentObject* const feat)
return false;
}

if (feat->getTypeId().isDerivedFrom(PartDesign::FeaturePrimitive::getClassTypeId())) {
auto prim = static_cast<PartDesign::FeaturePrimitive*>(feat);

if (!isFeatureMovable(prim->CoordinateSystem.getValue()))
return false;
}

if (feat->getTypeId().isDerivedFrom(PartDesign::ProfileBased::getClassTypeId())) {
auto prim = static_cast<PartDesign::ProfileBased*>(feat);
auto sk = prim->getVerifiedSketch(true);
Expand Down Expand Up @@ -410,13 +403,6 @@ std::vector<App::DocumentObject*> collectMovableDependencies(std::vector<App::Do

for (auto const &feat : features)
{
// Get coordinate system object
if (feat->getTypeId().isDerivedFrom(PartDesign::FeaturePrimitive::getClassTypeId())) {
auto prim = static_cast<PartDesign::FeaturePrimitive*>(feat);
App::DocumentObject* cs = prim->CoordinateSystem.getValue();
if (cs && cs->getTypeId() == PartDesign::CoordinateSystem::getClassTypeId())
unique_objs.insert(cs);
}

// Get sketches and datums from profile based features
if (feat->getTypeId().isDerivedFrom(PartDesign::ProfileBased::getClassTypeId())) {
Expand Down
7 changes: 0 additions & 7 deletions src/Mod/PartDesign/Gui/ViewProviderPrimitive.cpp
Expand Up @@ -121,13 +121,6 @@ void ViewProviderPrimitive::updateData(const App::Property* p) {
PartDesignGui::ViewProviderAddSub::updateData(p);
}

std::vector< App::DocumentObject* > ViewProviderPrimitive::claimChildren(void) const {
std::vector< App::DocumentObject* > vec;
vec.push_back(static_cast<PartDesign::FeaturePrimitive*>(getObject())->CoordinateSystem.getValue());

return vec;
}

QIcon ViewProviderPrimitive::getIcon(void) const {

QString str = QString::fromLatin1("PartDesign_");
Expand Down
1 change: 0 additions & 1 deletion src/Mod/PartDesign/Gui/ViewProviderPrimitive.h
Expand Up @@ -40,7 +40,6 @@ class PartDesignGuiExport ViewProviderPrimitive : public ViewProviderAddSub
/// destructor
virtual ~ViewProviderPrimitive();

virtual std::vector< App::DocumentObject* > claimChildren(void) const;
virtual void attach(App::DocumentObject*);
virtual void updateData(const App::Property*);

Expand Down

0 comments on commit bc133e4

Please sign in to comment.