| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| |
|
| |
|
| | #include <BRepAdaptor_Curve.hxx>
|
| | #include <BRepAdaptor_Surface.hxx>
|
| | #include <TopoDS.hxx>
|
| | #include <TopoDS_Edge.hxx>
|
| | #include <TopoDS_Face.hxx>
|
| | #include <QDialog>
|
| |
|
| |
|
| | #include <App/Document.h>
|
| | #include <App/Origin.h>
|
| | #include <App/Datums.h>
|
| | #include <App/Part.h>
|
| | #include <Base/Tools.h>
|
| | #include <Gui/Command.h>
|
| | #include <Gui/Document.h>
|
| | #include <Gui/MainWindow.h>
|
| | #include <Mod/Part/App/Part2DObject.h>
|
| | #include <Mod/Part/App/PartFeature.h>
|
| | #include <Mod/Part/App/TopoShape.h>
|
| | #include <Mod/PartDesign/App/Feature.h>
|
| | #include <Mod/PartDesign/App/Body.h>
|
| | #include <Mod/PartDesign/App/DatumLine.h>
|
| | #include <Mod/PartDesign/App/DatumPlane.h>
|
| | #include <Mod/PartDesign/App/DatumPoint.h>
|
| |
|
| | #include "ui_DlgReference.h"
|
| | #include "ReferenceSelection.h"
|
| | #include "TaskFeaturePick.h"
|
| | #include "Utils.h"
|
| |
|
| |
|
| | using namespace PartDesignGui;
|
| | using namespace Gui;
|
| |
|
| |
|
| |
|
| | bool ReferenceSelection::allow(App::Document* pDoc, App::DocumentObject* pObj, const char* sSubName)
|
| | {
|
| | if (!pObj) {
|
| | return false;
|
| | }
|
| | PartDesign::Body* body = getBody();
|
| | App::OriginGroupExtension* originGroup = getOriginGroupExtension(body);
|
| |
|
| |
|
| | if (support && pDoc != support->getDocument()) {
|
| | return false;
|
| | }
|
| |
|
| |
|
| | if (pObj->isDerivedFrom<App::DatumElement>()) {
|
| | return allowOrigin(body, originGroup, pObj);
|
| | }
|
| |
|
| | if (pObj->isDerivedFrom<Part::Datum>()) {
|
| | return allowDatum(body, pObj);
|
| | }
|
| |
|
| |
|
| |
|
| | #if 0
|
| | if (!type.testFlag(AllowSelection::OTHERBODY)) {
|
| | if (support == NULL)
|
| | return false;
|
| | if (pObj != support)
|
| | return false;
|
| | }
|
| | #endif
|
| | if (pObj->isDerivedFrom<Part::Part2DObject>() && Base::Tools::isNullOrEmpty(sSubName)) {
|
| | return type.testFlag(AllowSelection::FACE);
|
| | }
|
| |
|
| |
|
| | if (Base::Tools::isNullOrEmpty(sSubName)) {
|
| | return type.testFlag(AllowSelection::WHOLE);
|
| | }
|
| |
|
| |
|
| | if (!pObj->isDerivedFrom<Part::Feature>()) {
|
| | pObj = Part::Feature::getShapeOwner(pObj, sSubName);
|
| | }
|
| |
|
| | if (pObj && pObj->isDerivedFrom<Part::Feature>()) {
|
| | return allowPartFeature(pObj, sSubName);
|
| | }
|
| |
|
| | return false;
|
| | }
|
| |
|
| | PartDesign::Body* ReferenceSelection::getBody() const
|
| | {
|
| | auto* body = support ? PartDesign::Body::findBodyOf(support) : PartDesignGui::getBody(false);
|
| | return body;
|
| | }
|
| |
|
| | App::OriginGroupExtension* ReferenceSelection::getOriginGroupExtension(PartDesign::Body* body) const
|
| | {
|
| | App::DocumentObject* originGroupObject = nullptr;
|
| |
|
| | if (body) {
|
| | originGroupObject = App::OriginGroupExtension::getGroupOfObject(body);
|
| | }
|
| | else if (support) {
|
| | originGroupObject = App::OriginGroupExtension::getGroupOfObject(support);
|
| | }
|
| | else {
|
| | originGroupObject = PartDesignGui::getActivePart();
|
| | }
|
| |
|
| | App::OriginGroupExtension* originGroup = nullptr;
|
| | if (originGroupObject) {
|
| | originGroup = originGroupObject->getExtensionByType<App::OriginGroupExtension>();
|
| | }
|
| |
|
| | return originGroup;
|
| | }
|
| |
|
| | bool ReferenceSelection::allowOrigin(
|
| | PartDesign::Body* body,
|
| | App::OriginGroupExtension* originGroup,
|
| | App::DocumentObject* pObj
|
| | ) const
|
| | {
|
| | bool fits = false;
|
| | if (type.testFlag(AllowSelection::FACE) && pObj->isDerivedFrom<App::Plane>()) {
|
| | fits = true;
|
| | }
|
| | else if (type.testFlag(AllowSelection::EDGE) && pObj->isDerivedFrom<App::Line>()) {
|
| | fits = true;
|
| | }
|
| |
|
| | if (fits) {
|
| | try {
|
| | if (body) {
|
| | if (body->hasObject(pObj, true)) {
|
| | return true;
|
| | }
|
| | }
|
| | else if (originGroup) {
|
| | if (originGroup->hasObject(pObj, true)) {
|
| | return true;
|
| | }
|
| | }
|
| | }
|
| | catch (const Base::Exception&) {
|
| | }
|
| | }
|
| | return false;
|
| | }
|
| |
|
| | bool ReferenceSelection::allowDatum(PartDesign::Body* body, App::DocumentObject* pObj) const
|
| | {
|
| | if (!body) {
|
| | return false;
|
| | }
|
| | else if (!type.testFlag(AllowSelection::OTHERBODY) && !body->hasObject(pObj)) {
|
| | return false;
|
| | }
|
| |
|
| | if (type.testFlag(AllowSelection::FACE) && (pObj->isDerivedFrom<PartDesign::Plane>())) {
|
| | return true;
|
| | }
|
| | if (type.testFlag(AllowSelection::EDGE) && (pObj->isDerivedFrom<PartDesign::Line>())) {
|
| | return true;
|
| | }
|
| | if (type.testFlag(AllowSelection::POINT) && (pObj->isDerivedFrom<PartDesign::Point>())) {
|
| | return true;
|
| | }
|
| |
|
| | return false;
|
| | }
|
| |
|
| | bool ReferenceSelection::allowPartFeature(App::DocumentObject* pObj, const char* sSubName) const
|
| | {
|
| | std::string subName(sSubName);
|
| | if (type.testFlag(AllowSelection::POINT) && subName.compare(0, 6, "Vertex") == 0) {
|
| | return true;
|
| | }
|
| |
|
| | if (type.testFlag(AllowSelection::EDGE) && subName.compare(0, 4, "Edge") == 0) {
|
| | if (isEdge(pObj, sSubName)) {
|
| | return true;
|
| | }
|
| | }
|
| |
|
| | if (type.testFlag(AllowSelection::CIRCLE) && subName.compare(0, 4, "Edge") == 0) {
|
| | if (isCircle(pObj, sSubName)) {
|
| | return true;
|
| | }
|
| | }
|
| |
|
| | if (type.testFlag(AllowSelection::FACE) && subName.compare(0, 4, "Face") == 0) {
|
| | if (isFace(pObj, sSubName)) {
|
| | return true;
|
| | }
|
| | }
|
| |
|
| | return false;
|
| | }
|
| |
|
| | bool ReferenceSelection::isEdge(App::DocumentObject* pObj, const char* sSubName) const
|
| | {
|
| | const Part::TopoShape& shape = static_cast<const Part::Feature*>(pObj)->Shape.getValue();
|
| | TopoDS_Shape sh = shape.getSubShape(sSubName);
|
| | const TopoDS_Edge& edgeShape = TopoDS::Edge(sh);
|
| | if (!edgeShape.IsNull()) {
|
| | if (type.testFlag(AllowSelection::PLANAR)) {
|
| | BRepAdaptor_Curve adapt(edgeShape);
|
| | if (adapt.GetType() == GeomAbs_Line) {
|
| | return true;
|
| | }
|
| | }
|
| | else {
|
| | return true;
|
| | }
|
| | }
|
| |
|
| | return false;
|
| | }
|
| |
|
| | bool ReferenceSelection::isFace(App::DocumentObject* pObj, const char* sSubName) const
|
| | {
|
| | const Part::TopoShape& shape = static_cast<const Part::Feature*>(pObj)->Shape.getValue();
|
| | TopoDS_Shape sh = shape.getSubShape(sSubName);
|
| | const TopoDS_Face& face = TopoDS::Face(sh);
|
| | if (!face.IsNull()) {
|
| | if (type.testFlag(AllowSelection::PLANAR)) {
|
| | BRepAdaptor_Surface adapt(face);
|
| | if (adapt.GetType() == GeomAbs_Plane) {
|
| | return true;
|
| | }
|
| | }
|
| | else {
|
| | return true;
|
| | }
|
| | }
|
| |
|
| | return false;
|
| | }
|
| |
|
| | bool ReferenceSelection::isCircle(App::DocumentObject* pObj, const char* sSubName) const
|
| | {
|
| | const Part::TopoShape& shape = static_cast<const Part::Feature*>(pObj)->Shape.getValue();
|
| | TopoDS_Shape sh = shape.getSubShape(sSubName);
|
| | const TopoDS_Edge& edgeShape = TopoDS::Edge(sh);
|
| | BRepAdaptor_Curve adapt(edgeShape);
|
| | if (adapt.GetType() == GeomAbs_Circle) {
|
| | return true;
|
| | }
|
| |
|
| | return false;
|
| | }
|
| |
|
| |
|
| |
|
| | bool NoDependentsSelection::allow(App::Document* , App::DocumentObject* pObj, const char* )
|
| | {
|
| | if (support && support->testIfLinkDAGCompatible(pObj)) {
|
| | return true;
|
| | }
|
| | else {
|
| | this->notAllowedReason = QT_TR_NOOP("Selecting this will cause circular dependency.");
|
| | return false;
|
| | }
|
| | }
|
| |
|
| | bool CombineSelectionFilterGates::allow(App::Document* pDoc, App::DocumentObject* pObj, const char* sSubName)
|
| | {
|
| | return filter1->allow(pDoc, pObj, sSubName) && filter2->allow(pDoc, pObj, sSubName);
|
| | }
|
| |
|
| |
|
| | namespace PartDesignGui
|
| | {
|
| |
|
| | bool getReferencedSelection(
|
| | const App::DocumentObject* thisObj,
|
| | const Gui::SelectionChanges& msg,
|
| | App::DocumentObject*& selObj,
|
| | std::vector<std::string>& selSub
|
| | )
|
| | {
|
| | selObj = nullptr;
|
| | if (!thisObj) {
|
| | return false;
|
| | }
|
| |
|
| | if (strcmp(thisObj->getDocument()->getName(), msg.pDocName) != 0) {
|
| | return false;
|
| | }
|
| |
|
| | selObj = thisObj->getDocument()->getObject(msg.pObjectName);
|
| | if (selObj == thisObj) {
|
| | return false;
|
| | }
|
| |
|
| | std::string subname = msg.pSubName;
|
| |
|
| |
|
| |
|
| |
|
| | PartDesign::Body* body = PartDesignGui::getBodyFor(thisObj, false);
|
| | bool originfeature = selObj->isDerivedFrom<App::DatumElement>();
|
| | if (!originfeature && body) {
|
| | PartDesign::Body* selBody = PartDesignGui::getBodyFor(selObj, false);
|
| | if (!selBody || body != selBody) {
|
| | QDialog dia(Gui::getMainWindow());
|
| | Ui_DlgReference dlg;
|
| | dlg.setupUi(&dia);
|
| | dia.setModal(true);
|
| | int result = dia.exec();
|
| | if (result == QDialog::DialogCode::Rejected) {
|
| | selObj = nullptr;
|
| | return false;
|
| | }
|
| |
|
| | if (!dlg.radioXRef->isChecked()) {
|
| | App::Document* document = thisObj->getDocument();
|
| | document->openTransaction("Make copy");
|
| | auto copy = PartDesignGui::TaskFeaturePick::makeCopy(
|
| | selObj,
|
| | subname,
|
| | dlg.radioIndependent->isChecked()
|
| | );
|
| | body->addObject(copy);
|
| |
|
| | selObj = copy;
|
| | subname.erase(std::remove_if(subname.begin(), subname.end(), &isdigit), subname.end());
|
| | subname.append("1");
|
| | }
|
| | }
|
| | }
|
| |
|
| |
|
| | if (PartDesign::Feature::isDatum(selObj)) {
|
| | subname = "";
|
| | }
|
| |
|
| | selSub = std::vector<std::string>(1, subname);
|
| |
|
| | return true;
|
| | }
|
| |
|
| | QString getRefStr(const App::DocumentObject* obj, const std::vector<std::string>& sub)
|
| | {
|
| | if (!obj) {
|
| | return {};
|
| | }
|
| |
|
| | if (PartDesign::Feature::isDatum(obj)) {
|
| | return QString::fromLatin1(obj->getNameInDocument());
|
| | }
|
| |
|
| | if (!sub.empty() && !sub.front().empty()) {
|
| | return QString::fromLatin1(obj->getNameInDocument()) + QStringLiteral(":")
|
| | + QString::fromLatin1(sub.front().c_str());
|
| | }
|
| |
|
| | if (obj->isDerivedFrom<Part::Part2DObject>()) {
|
| |
|
| | return QString::fromLatin1(obj->getNameInDocument());
|
| | }
|
| |
|
| | return {};
|
| | }
|
| |
|
| | std::string buildLinkSubPythonStr(const App::DocumentObject* obj, const std::vector<std::string>& subs)
|
| | {
|
| | if (!obj) {
|
| | return "None";
|
| | }
|
| |
|
| | std::string result("[");
|
| |
|
| | for (const auto& sub : subs) {
|
| | result += "\"" + sub + "\",";
|
| | }
|
| | result += "]";
|
| |
|
| | return result;
|
| | }
|
| |
|
| | std::string buildLinkSingleSubPythonStr(
|
| | const App::DocumentObject* obj,
|
| | const std::vector<std::string>& subs
|
| | )
|
| | {
|
| | if (!obj) {
|
| | return "None";
|
| | }
|
| |
|
| | if (PartDesign::Feature::isDatum(obj)) {
|
| | return Gui::Command::getObjectCmd(obj, "(", ", [''])");
|
| | }
|
| | else {
|
| | return Gui::Command::getObjectCmd(obj, "(", ", ['") + subs.front() + "'])";
|
| | }
|
| | }
|
| |
|
| | std::string buildLinkListPythonStr(const std::vector<App::DocumentObject*>& objs)
|
| | {
|
| | if (objs.empty()) {
|
| | return "None";
|
| | }
|
| |
|
| | std::string result("[");
|
| |
|
| | for (auto obj : objs) {
|
| | result += Gui::Command::getObjectCmd(obj, nullptr, ",");
|
| | }
|
| | result += "]";
|
| |
|
| | return result;
|
| | }
|
| |
|
| | std::string buildLinkSubListPythonStr(
|
| | const std::vector<App::DocumentObject*>& objs,
|
| | const std::vector<std::string>& subs
|
| | )
|
| | {
|
| | if (objs.empty()) {
|
| | return "None";
|
| | }
|
| |
|
| | std::string result("[");
|
| |
|
| | assert(objs.size() == subs.size());
|
| |
|
| | for (size_t i = 0, objs_sz = objs.size(); i < objs_sz; i++) {
|
| | if (objs[i]) {
|
| | result += '(';
|
| | result += Gui::Command::getObjectCmd(objs[i]);
|
| | result += ",\"";
|
| | result += subs[i];
|
| | result += "\"),";
|
| | }
|
| | }
|
| |
|
| | result += "]";
|
| |
|
| | return result;
|
| | }
|
| | }
|
| |
|