Merge branch 'master' into bugfix/ocl-import-recovery

This commit is contained in:
sliptonic
2019-07-08 08:26:51 -05:00
committed by GitHub
8 changed files with 131 additions and 16 deletions

View File

@@ -474,6 +474,7 @@ PyMOD_INIT_FUNC(Part)
Part::Offset ::init();
Part::Offset2D ::init();
Part::Thickness ::init();
Part::Refine ::init();
// Geometry types
Part::Geometry ::init();

View File

@@ -673,3 +673,28 @@ App::DocumentObjectExecReturn *Thickness::execute(void)
this->Shape.setValue(shape);
return App::DocumentObject::StdReturn;
}
// ----------------------------------------------------------------------------
PROPERTY_SOURCE(Part::Refine, Part::Feature)
Refine::Refine()
{
ADD_PROPERTY_TYPE(Source,(0),"Refine",App::Prop_None,"Source shape");
}
App::DocumentObjectExecReturn *Refine::execute(void)
{
Part::Feature* source = Source.getValue<Part::Feature*>();
if (!source)
return new App::DocumentObjectExecReturn("No part object linked.");
try {
TopoShape myShape = source->Shape.getShape();
this->Shape.setValue(myShape.removeSplitter());
return App::DocumentObject::StdReturn;
}
catch (Standard_Failure& e) {
return new App::DocumentObjectExecReturn(e.GetMessageString());
}
}

View File

@@ -154,6 +154,25 @@ private:
static const char* JoinEnums[];
};
class Refine : public Part::Feature
{
PROPERTY_HEADER(Part::Refine);
public:
Refine();
App::PropertyLink Source;
/** @name methods override feature */
//@{
/// recalculate the feature
App::DocumentObjectExecReturn *execute(void);
const char* getViewProviderName(void) const {
return "PartGui::ViewProviderRefine";
}
//@}
};
} //namespace Part

View File

@@ -171,6 +171,7 @@ PyMOD_INIT_FUNC(PartGui)
PartGui::ViewProviderOffset ::init();
PartGui::ViewProviderOffset2D ::init();
PartGui::ViewProviderThickness ::init();
PartGui::ViewProviderRefine ::init();
PartGui::ViewProviderCustom ::init();
PartGui::ViewProviderCustomPython ::init();
PartGui::ViewProviderBoolean ::init();

View File

@@ -235,21 +235,37 @@ CmdPartRefineShape::CmdPartRefineShape()
void CmdPartRefineShape::activated(int iMsg)
{
Q_UNUSED(iMsg);
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Part");
bool parametric = hGrp->GetBool("ParametricRefine", true);
Gui::WaitCursor wc;
Base::Type partid = Base::Type::fromName("Part::Feature");
std::vector<App::DocumentObject*> objs = Gui::Selection().getObjectsOfType(partid);
openCommand("Refine shape");
for (std::vector<App::DocumentObject*>::iterator it = objs.begin(); it != objs.end(); ++it) {
try {
doCommand(Doc,"App.ActiveDocument.addObject('Part::Feature','%s').Shape="
"App.ActiveDocument.%s.Shape.removeSplitter()\n"
"App.ActiveDocument.ActiveObject.Label="
"App.ActiveDocument.%s.Label\n"
"Gui.ActiveDocument.%s.hide()\n",
(*it)->getNameInDocument(),
(*it)->getNameInDocument(),
(*it)->getNameInDocument(),
(*it)->getNameInDocument());
if (parametric) {
doCommand(Doc,"App.ActiveDocument.addObject('Part::Refine','%s').Source="
"App.ActiveDocument.%s\n"
"App.ActiveDocument.ActiveObject.Label="
"App.ActiveDocument.%s.Label\n"
"Gui.ActiveDocument.%s.hide()\n",
(*it)->getNameInDocument(),
(*it)->getNameInDocument(),
(*it)->getNameInDocument(),
(*it)->getNameInDocument());
}
else {
doCommand(Doc,"App.ActiveDocument.addObject('Part::Feature','%s').Shape="
"App.ActiveDocument.%s.Shape.removeSplitter()\n"
"App.ActiveDocument.ActiveObject.Label="
"App.ActiveDocument.%s.Label\n"
"Gui.ActiveDocument.%s.hide()\n",
(*it)->getNameInDocument(),
(*it)->getNameInDocument(),
(*it)->getNameInDocument(),
(*it)->getNameInDocument());
}
copyVisual("ActiveObject", "ShapeColor", (*it)->getNameInDocument());
copyVisual("ActiveObject", "LineColor", (*it)->getNameInDocument());
copyVisual("ActiveObject", "PointColor", (*it)->getNameInDocument());

View File

@@ -667,3 +667,16 @@ bool ViewProviderThickness::onDelete(const std::vector<std::string> &)
return true;
}
// ---------------------------------------
PROPERTY_SOURCE(PartGui::ViewProviderRefine, PartGui::ViewProviderPart)
ViewProviderRefine::ViewProviderRefine()
{
sPixmap = "Part_Refine_Shape";
}
ViewProviderRefine::~ViewProviderRefine()
{
}

View File

@@ -193,6 +193,17 @@ protected:
virtual void unsetEdit(int ModNum);
};
class ViewProviderRefine : public ViewProviderPart
{
PROPERTY_HEADER(PartGui::ViewProviderRefine);
public:
/// constructor
ViewProviderRefine();
/// destructor
virtual ~ViewProviderRefine();
};
} // namespace PartGui

View File

@@ -66,6 +66,7 @@
#include "ReferenceSelection.h"
#include "Utils.h"
#include "WorkflowManager.h"
#include "ViewProviderBody.h"
// TODO Remove this header after fixing code so it won;t be needed here (2015-10-20, Fat-Zer)
#include "ui_DlgReference.h"
@@ -461,15 +462,42 @@ void CmdPartDesignNewSketch::activated(int iMsg)
App::DocumentObject* obj;
if (FaceFilter.match()) {
obj = FaceFilter.Result[0][0].getObject();
Gui::SelectionObject faceSelObject = FaceFilter.Result[0][0];
const std::vector<std::string>& subNames = faceSelObject.getSubNames();
obj = faceSelObject.getObject();
if(!obj->isDerivedFrom(Part::Feature::getClassTypeId()))
if (!obj->isDerivedFrom(Part::Feature::getClassTypeId()))
return;
// In case the selected face belongs to the body then it means its
// Display Mode Body is set to Tip. But the body face is not allowed
// to be used as support because otherwise it would cause a cyclic
// dependency. So, instead we use the tip object as reference.
// https://forum.freecadweb.org/viewtopic.php?f=3&t=37448
if (obj == pcActiveBody) {
App::DocumentObject* tip = pcActiveBody->Tip.getValue();
if (tip && tip->isDerivedFrom(Part::Feature::getClassTypeId()) && subNames.size() == 1) {
Gui::SelectionChanges msg;
msg.pDocName = faceSelObject.getDocName();
msg.pObjectName = tip->getNameInDocument();
msg.pSubName = subNames[0].c_str();
msg.pTypeName = tip->getTypeId().getName();
faceSelObject = Gui::SelectionObject(msg);
obj = tip;
// automatically switch to 'Through' mode
PartDesignGui::ViewProviderBody* vpBody = dynamic_cast<PartDesignGui::ViewProviderBody*>
(Gui::Application::Instance->getViewProvider(pcActiveBody));
if (vpBody) {
vpBody->DisplayModeBody.setValue("Through");
}
}
}
Part::Feature* feat = static_cast<Part::Feature*>(obj);
const std::vector<std::string> &sub = FaceFilter.Result[0][0].getSubNames();
if (sub.size() > 1) {
if (subNames.size() > 1) {
// No assert for wrong user input!
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Several sub-elements selected"),
QObject::tr("You have to select a single face as support for a sketch!"));
@@ -478,7 +506,7 @@ void CmdPartDesignNewSketch::activated(int iMsg)
// get the selected sub shape (a Face)
const Part::TopoShape &shape = feat->Shape.getValue();
TopoDS_Shape sh = shape.getSubShape(sub[0].c_str());
TopoDS_Shape sh = shape.getSubShape(subNames[0].c_str());
const TopoDS_Face& face = TopoDS::Face(sh);
if (face.IsNull()) {
// No assert for wrong user input!
@@ -498,8 +526,9 @@ void CmdPartDesignNewSketch::activated(int iMsg)
}
}
supportString = FaceFilter.Result[0][0].getAsPropertyLinkSubString();
} else {
supportString = faceSelObject.getAsPropertyLinkSubString();
}
else {
obj = static_cast<Part::Feature*>(PlaneFilter.Result[0][0].getObject());
supportString = std::string("(App.activeDocument().") + obj->getNameInDocument() + ", '')";
}