diff --git a/src/Base/PyObjectBase.cpp b/src/Base/PyObjectBase.cpp index 182366e9e4b8..634b4e0d5af5 100644 --- a/src/Base/PyObjectBase.cpp +++ b/src/Base/PyObjectBase.cpp @@ -133,8 +133,12 @@ PyTypeObject PyObjectBase::Type = { #if PY_MAJOR_VERSION >= 3 ,0 /*tp_finalize */ #endif -#if PY_VERSION_HEX >= 0x03080000 +#if PY_VERSION_HEX >= 0x03090000 ,0 /*tp_vectorcall */ +#elif PY_VERSION_HEX >= 0x03080000 + ,0 /*tp_vectorcall */ + /* bpo-37250: kept for backwards compatibility in CPython 3.8 only */ + ,0 /*tp_print */ #endif }; diff --git a/src/Gui/Assistant.cpp b/src/Gui/Assistant.cpp index d999471e10b9..20f6fb2f673d 100644 --- a/src/Gui/Assistant.cpp +++ b/src/Gui/Assistant.cpp @@ -61,7 +61,7 @@ void Assistant::showDocumentation(const QString &page) if (!page.isEmpty()) { QTextStream str(proc); str << QLatin1String("setSource qthelp://org.freecad.usermanual/doc/") - << page << QLatin1Char('\n') << endl; + << page << QLatin1String("\n\n"); } } diff --git a/src/Gui/AutoSaver.cpp b/src/Gui/AutoSaver.cpp index 636f75ea2500..899de87ba1b1 100644 --- a/src/Gui/AutoSaver.cpp +++ b/src/Gui/AutoSaver.cpp @@ -149,12 +149,12 @@ void AutoSaver::saveDocument(const std::string& name, AutoSaveProperty& saver) if (file.open(QFile::WriteOnly)) { QTextStream str(&file); str.setCodec("UTF-8"); - str << "" << endl - << "" << endl; - str << " Created" << endl; - str << " " << endl; // store the document's current label - str << " " << QString::fromUtf8(doc->FileName.getValue()) << "" << endl; // store the document's current filename - str << "" << endl; + str << "\n" + << "\n"; + str << " Created\n"; + str << " \n"; // store the document's current label + str << " " << QString::fromUtf8(doc->FileName.getValue()) << "\n"; // store the document's current filename + str << "\n"; file.close(); } diff --git a/src/Gui/CommandView.cpp b/src/Gui/CommandView.cpp index 1fa52154d5c3..831ff1e3ca99 100644 --- a/src/Gui/CommandView.cpp +++ b/src/Gui/CommandView.cpp @@ -337,9 +337,9 @@ void StdCmdFreezeViews::onSaveViews() QTextStream str(&file); ActionGroup* pcAction = qobject_cast(_pcAction); QList acts = pcAction->actions(); - str << "" << endl - << "" << endl; - str << " " << endl; + str << "\n" + << "\n"; + str << " \n"; for (QList::ConstIterator it = acts.begin()+offset; it != acts.end(); ++it) { if ( !(*it)->isVisible() ) @@ -356,11 +356,11 @@ void StdCmdFreezeViews::onSaveViews() viewPos = lines.join(QString::fromLatin1(" ")); } - str << " " << endl; + str << " \n"; } - str << " " << endl; - str << "" << endl; + str << " \n"; + str << "\n"; } } diff --git a/src/Gui/DlgDisplayPropertiesImp.cpp b/src/Gui/DlgDisplayPropertiesImp.cpp index a65b5bad5f31..c84eb5d3b4e9 100644 --- a/src/Gui/DlgDisplayPropertiesImp.cpp +++ b/src/Gui/DlgDisplayPropertiesImp.cpp @@ -168,9 +168,8 @@ void DlgDisplayPropertiesImp::slotChangedObject(const Gui::ViewProvider& obj, // We pick out all the properties for which we need to update this dialog. std::vector Provider = getSelection(); std::vector::const_iterator vp = std::find_if - (Provider.begin(), Provider.end(), - std::bind2nd(std::equal_to(), - const_cast(&obj))); + (Provider.begin(), Provider.end(), [&obj](Gui::ViewProvider* v) { return v == &obj; }); + if (vp != Provider.end()) { const char* name = obj.getPropertyName(&prop); // this is not a property of the view provider but of the document object diff --git a/src/Gui/DocumentRecovery.cpp b/src/Gui/DocumentRecovery.cpp index 8dbcaa66180d..446cef1070ed 100644 --- a/src/Gui/DocumentRecovery.cpp +++ b/src/Gui/DocumentRecovery.cpp @@ -362,28 +362,28 @@ void DocumentRecoveryPrivate::writeRecoveryInfo(const DocumentRecoveryPrivate::I if (file.open(QFile::WriteOnly)) { QTextStream str(&file); str.setCodec("UTF-8"); - str << "" << endl - << "" << endl; + str << "\n" + << "\n"; switch (info.status) { case Created: - str << " Created" << endl; + str << " Created\n"; break; case Overage: - str << " Deprecated" << endl; + str << " Deprecated\n"; break; case Success: - str << " Success" << endl; + str << " Success\n"; break; case Failure: - str << " Failure" << endl; + str << " Failure\n"; break; default: - str << " Unknown" << endl; + str << " Unknown\n"; break; } - str << " " << endl; - str << " " << info.fileName << "" << endl; - str << "" << endl; + str << " \n"; + str << " " << info.fileName << "\n"; + str << "\n"; file.close(); } } diff --git a/src/Gui/NetworkRetriever.cpp b/src/Gui/NetworkRetriever.cpp index 646a8baf7d20..b6cbe153bc1c 100644 --- a/src/Gui/NetworkRetriever.cpp +++ b/src/Gui/NetworkRetriever.cpp @@ -374,7 +374,12 @@ void NetworkRetriever::wgetFinished(int exitCode, QProcess::ExitStatus status) bool NetworkRetriever::testWget() { QProcess proc; +#if QT_VERSION > 0x050000 + proc.setProgram(QString::fromLatin1("wget")); + proc.start(); +#else proc.start(QString::fromLatin1("wget")); +#endif bool ok = proc.state() == QProcess::Running; proc.kill(); proc.waitForFinished(); diff --git a/src/Gui/OnlineDocumentation.cpp b/src/Gui/OnlineDocumentation.cpp index 5504607948ed..4c1921c3ee7e 100644 --- a/src/Gui/OnlineDocumentation.cpp +++ b/src/Gui/OnlineDocumentation.cpp @@ -255,8 +255,7 @@ QByteArray PythonOnlineHelp::fileNotFound() const QString http(QLatin1String("HTTP/1.1 %1 %2\r\n%3\r\n")); QString httpResponseHeader = http.arg(404).arg(QLatin1String("File not found")).arg(header); - QByteArray res; - res.append(httpResponseHeader); + QByteArray res = httpResponseHeader.toLatin1(); return res; } @@ -285,8 +284,7 @@ QByteArray PythonOnlineHelp::loadFailed(const QString& error) const QString http(QLatin1String("HTTP/1.1 %1 %2\r\n%3\r\n")); QString httpResponseHeader = http.arg(404).arg(QLatin1String("File not found")).arg(header); - QByteArray res; - res.append(httpResponseHeader); + QByteArray res = httpResponseHeader.toLatin1(); return res; } diff --git a/src/Gui/ProjectView.cpp b/src/Gui/ProjectView.cpp index 857cf24f59c0..64e10e2b5027 100644 --- a/src/Gui/ProjectView.cpp +++ b/src/Gui/ProjectView.cpp @@ -36,7 +36,7 @@ # include #endif -#include +#include #include #include @@ -56,8 +56,7 @@ using namespace Gui; ProjectWidget::ProjectWidget(QWidget* parent) : QTreeView(parent) { - fileModel = new QDirModel(this); - fileModel->setSorting(QDir::DirsFirst | QDir::Type); + fileModel = new QFileSystemModel(this); setModel(fileModel); } diff --git a/src/Gui/ProjectView.h b/src/Gui/ProjectView.h index 7b45386184cf..3e361cb4e775 100644 --- a/src/Gui/ProjectView.h +++ b/src/Gui/ProjectView.h @@ -31,7 +31,8 @@ #include #include -class QDirModel; + +class QFileSystemModel; namespace Gui { @@ -48,7 +49,7 @@ class ProjectWidget : public QTreeView ~ProjectWidget(); private: - QDirModel *fileModel; + QFileSystemModel *fileModel; }; diff --git a/src/Gui/QSint/actionpanel/actionbox.cpp b/src/Gui/QSint/actionpanel/actionbox.cpp index 2ed673b4d5a9..8bd92e7bb5f5 100644 --- a/src/Gui/QSint/actionpanel/actionbox.cpp +++ b/src/Gui/QSint/actionpanel/actionbox.cpp @@ -116,6 +116,19 @@ void ActionBox::setIcon(const QPixmap & icon) iconLabel->setFixedSize(icon.size()); } +QPixmap ActionBox::icon() const +{ +#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) + return iconLabel->pixmap(Qt::ReturnByValue); +#else + QPixmap p; + const QPixmap* ptr = iconLabel->pixmap(); + if (ptr) + p = *ptr; + return p; +#endif +} + ActionLabel* ActionBox::createItem(QAction * action, QLayout * l) { if (!action) diff --git a/src/Gui/QSint/actionpanel/actionbox.h b/src/Gui/QSint/actionpanel/actionbox.h index 0b599349dce9..645d56175c47 100644 --- a/src/Gui/QSint/actionpanel/actionbox.h +++ b/src/Gui/QSint/actionpanel/actionbox.h @@ -182,7 +182,7 @@ class QSINT_EXPORT ActionBox : public QFrame void setIcon(const QPixmap & icon); /** Returns icon of the ActionBox. */ - inline const QPixmap* icon() const { return iconLabel->pixmap(); } + QPixmap icon() const;// { return iconLabel->pixmap(); } /** Returns header item of the ActionBox. */ diff --git a/src/Gui/QSint/actionpanel/taskgroup_p.cpp b/src/Gui/QSint/actionpanel/taskgroup_p.cpp index 10a1a5a53037..6133ab2e20a3 100644 --- a/src/Gui/QSint/actionpanel/taskgroup_p.cpp +++ b/src/Gui/QSint/actionpanel/taskgroup_p.cpp @@ -106,7 +106,7 @@ void TaskGroup::keyPressEvent ( QKeyEvent * event ) { case Qt::Key_Down: { - QKeyEvent ke(QEvent::KeyPress, Qt::Key_Tab, 0); + QKeyEvent ke(QEvent::KeyPress, Qt::Key_Tab, Qt::NoModifier); QApplication::sendEvent(this, &ke); return; } @@ -131,7 +131,7 @@ void TaskGroup::keyReleaseEvent ( QKeyEvent * event ) { case Qt::Key_Down: { - QKeyEvent ke(QEvent::KeyRelease, Qt::Key_Tab, 0); + QKeyEvent ke(QEvent::KeyRelease, Qt::Key_Tab, Qt::NoModifier); QApplication::sendEvent(this, &ke); return; } diff --git a/src/Gui/QSint/actionpanel/taskheader_p.cpp b/src/Gui/QSint/actionpanel/taskheader_p.cpp index 63c9e0d19c8f..38c4ab4e1e1b 100644 --- a/src/Gui/QSint/actionpanel/taskheader_p.cpp +++ b/src/Gui/QSint/actionpanel/taskheader_p.cpp @@ -264,7 +264,7 @@ void TaskHeader::keyPressEvent ( QKeyEvent * event ) { case Qt::Key_Down: { - QKeyEvent ke(QEvent::KeyPress, Qt::Key_Tab,0 ); + QKeyEvent ke(QEvent::KeyPress, Qt::Key_Tab, Qt::NoModifier); QApplication::sendEvent(this, &ke); return; } @@ -288,7 +288,7 @@ void TaskHeader::keyReleaseEvent ( QKeyEvent * event ) { case Qt::Key_Down: { - QKeyEvent ke(QEvent::KeyRelease, Qt::Key_Tab, 0); + QKeyEvent ke(QEvent::KeyRelease, Qt::Key_Tab, Qt::NoModifier); QApplication::sendEvent(this, &ke); return; } diff --git a/src/Gui/Splashscreen.cpp b/src/Gui/Splashscreen.cpp index fda58b346177..7d8addcb38dd 100644 --- a/src/Gui/Splashscreen.cpp +++ b/src/Gui/Splashscreen.cpp @@ -770,38 +770,38 @@ void AboutDialog::on_copyButton_clicked() } } - str << "OS: " << SystemInfo::getOperatingSystem() << deskInfo << endl; + str << "OS: " << SystemInfo::getOperatingSystem() << deskInfo << '\n'; int wordSize = SystemInfo::getWordSizeOfOS(); if (wordSize > 0) { - str << "Word size of OS: " << wordSize << "-bit" << endl; + str << "Word size of OS: " << wordSize << "-bit\n"; } - str << "Word size of " << exe << ": " << QSysInfo::WordSize << "-bit" << endl; + str << "Word size of " << exe << ": " << QSysInfo::WordSize << "-bit\n"; str << "Version: " << major << "." << minor << "." << build; char *appimage = getenv("APPIMAGE"); if (appimage) str << " AppImage"; - str << endl; + str << '\n'; #if defined(_DEBUG) || defined(DEBUG) - str << "Build type: Debug" << endl; + str << "Build type: Debug\n"; #elif defined(NDEBUG) - str << "Build type: Release" << endl; + str << "Build type: Release\n"; #elif defined(CMAKE_BUILD_TYPE) - str << "Build type: " << CMAKE_BUILD_TYPE << endl; + str << "Build type: " << CMAKE_BUILD_TYPE << '\n'; #else - str << "Build type: Unknown" << endl; + str << "Build type: Unknown\n"; #endif it = config.find("BuildRevisionBranch"); if (it != config.end()) - str << "Branch: " << QString::fromUtf8(it->second.c_str()) << endl; + str << "Branch: " << QString::fromUtf8(it->second.c_str()) << '\n'; it = config.find("BuildRevisionHash"); if (it != config.end()) - str << "Hash: " << it->second.c_str() << endl; + str << "Hash: " << it->second.c_str() << '\n'; // report also the version numbers of the most important libraries in FreeCAD - str << "Python version: " << PY_VERSION << endl; - str << "Qt version: " << QT_VERSION_STR << endl; - str << "Coin version: " << COIN_VERSION << endl; + str << "Python version: " << PY_VERSION << '\n'; + str << "Qt version: " << QT_VERSION_STR << '\n'; + str << "Coin version: " << COIN_VERSION << '\n'; #if defined(HAVE_OCC_VERSION) str << "OCC version: " << OCC_VERSION_MAJOR << "." @@ -810,12 +810,12 @@ void AboutDialog::on_copyButton_clicked() #ifdef OCC_VERSION_DEVELOPMENT << "." OCC_VERSION_DEVELOPMENT #endif - << endl; + << '\n'; #endif QLocale loc; str << "Locale: " << loc.languageToString(loc.language()) << "/" << loc.countryToString(loc.country()) - << " (" << loc.name() << ")" << endl; + << " (" << loc.name() << ")\n"; QClipboard* cb = QApplication::clipboard(); cb->setText(data); diff --git a/src/Gui/TaskElementColors.cpp b/src/Gui/TaskElementColors.cpp index c9d3dd30b6fa..39b70b2bf4dc 100644 --- a/src/Gui/TaskElementColors.cpp +++ b/src/Gui/TaskElementColors.cpp @@ -263,7 +263,7 @@ class ElementColors::Private: public Gui::SelectionGate boost::starts_with(msg.pSubName,editSub)) { for(auto item : ui->elementList->findItems( - QString::fromLatin1(msg.pSubName-editSub.size()),0)) + QString::fromLatin1(msg.pSubName-editSub.size()), Qt::MatchExactly)) item->setSelected(msg.Type==SelectionChanges::AddSelection); } } diff --git a/src/Gui/TaskView/TaskAppearance.cpp b/src/Gui/TaskView/TaskAppearance.cpp index 08b09fa62339..10b034f0675d 100644 --- a/src/Gui/TaskView/TaskAppearance.cpp +++ b/src/Gui/TaskView/TaskAppearance.cpp @@ -101,9 +101,8 @@ void TaskAppearance::slotChangedObject(const Gui::ViewProvider& obj, // We pick out all the properties for which we need to update this dialog. std::vector Provider = getSelection(); std::vector::const_iterator vp = std::find_if - (Provider.begin(), Provider.end(), - std::bind2nd(std::equal_to(), - const_cast(&obj))); + (Provider.begin(), Provider.end(), [&obj](Gui::ViewProvider* v) { return v == &obj; }); + if (vp != Provider.end()) { std::string prop_name = obj.getPropertyName(&prop); if (prop.getTypeId().isDerivedFrom(App::PropertyInteger::getClassTypeId())) { diff --git a/src/Mod/Arch/ArchSectionPlane.py b/src/Mod/Arch/ArchSectionPlane.py index a75999cf1b93..8cfd49b5de83 100644 --- a/src/Mod/Arch/ArchSectionPlane.py +++ b/src/Mod/Arch/ArchSectionPlane.py @@ -368,14 +368,14 @@ def getSVG(source, for o in objs: if Draft.getType(o) == "Space": spaces.append(o) - elif Draft.getType(o) in ["AngularDimension","LinearDimension","Annotation","Label","Text", "DraftText"]: + elif Draft.getType(o) in ["Dimension","AngularDimension","LinearDimension","Annotation","Label","Text", "DraftText"]: if isOriented(o,cutplane): drafts.append(o) elif o.isDerivedFrom("Part::Part2DObject"): drafts.append(o) elif looksLikeDraft(o): drafts.append(o) - else: + elif not o.isDerivedFrom("App::DocumentObjectGroup"): nonspaces.append(o) if Draft.getType(o) == "Window": windows.append(o) diff --git a/src/Mod/Arch/ArchWindowPresets.py b/src/Mod/Arch/ArchWindowPresets.py index 817fa6d5c4cb..6074a00d587a 100644 --- a/src/Mod/Arch/ArchWindowPresets.py +++ b/src/Mod/Arch/ArchWindowPresets.py @@ -170,7 +170,7 @@ def doorFrame(s,width,height,h1,w1,o1): fw = str(w2) if w2 == w1: fw = "0.00+V" - wp.extend(["InnerFrame","Frame","Wire2,Wire3",fw,str(o2)+"+V"]) + wp.extend(["InnerFrame","Frame","Wire2,Wire3,Edge8,Mode1",fw,str(o2)+"+V"]) wp.extend(["InnerGlass","Glass panel","Wire3",str(w2/gla),str(o2+w2/2)+"+V"]) elif windowtype == "Open 2-pane": @@ -220,9 +220,9 @@ def doorFrame(s,width,height,h1,w1,o1): fw = str(w2) if w2 == w1: fw = "0.00+V" - wp.extend(["LeftFrame","Frame","Wire2,Wire3",fw,str(o2)+"+V"]) + wp.extend(["LeftFrame","Frame","Wire2,Wire3,Edge8,Mode1",fw,str(o2)+"+V"]) wp.extend(["LeftGlass","Glass panel","Wire3",str(w2/gla),str(o2+w2/2)+"+V"]) - wp.extend(["RightFrame","Frame","Wire4,Wire5",fw,str(o2)+"+V"]) + wp.extend(["RightFrame","Frame","Wire4,Wire5,Edge6,Mode2",fw,str(o2)+"+V"]) wp.extend(["RightGlass","Glass panel","Wire5",str(w2/gla),str(o2+w2/2)+"+V"]) elif windowtype == "Sash 2-pane": @@ -433,7 +433,7 @@ def doorFrame(s,width,height,h1,w1,o1): elif windowtype == "Simple door": wp = doorFrame(s,width,height,h1,w1,o1) - wp.extend(["Door","Solid panel","Wire1",str(w2),str(o2)+"+V"]) + wp.extend(["Door","Solid panel","Wire1,Edge8,Mode2",str(w2),str(o2)+"+V"]) elif windowtype == "Glass door": @@ -463,7 +463,7 @@ def doorFrame(s,width,height,h1,w1,o1): fw = str(w2) if w2 == w1: fw = "0.00+V" - wp.extend(["InnerFrame","Frame","Wire2,Wire3",fw,str(o2)+"+V"]) + wp.extend(["InnerFrame","Frame","Wire2,Wire3,Edge8,Mode1",fw,str(o2)+"+V"]) wp.extend(["InnerGlass","Glass panel","Wire3",str(w2/gla),str(o2+w2/2)+"+V"]) return (s,wp) diff --git a/src/Mod/Draft/Resources/ui/TaskSelectPlane.ui b/src/Mod/Draft/Resources/ui/TaskSelectPlane.ui index 0402aa8e626b..690dc214cf58 100644 --- a/src/Mod/Draft/Resources/ui/TaskSelectPlane.ui +++ b/src/Mod/Draft/Resources/ui/TaskSelectPlane.ui @@ -6,8 +6,8 @@ 0 0 - 200 - 547 + 210 + 568 @@ -192,7 +192,7 @@ will be moved to the center of the view - + The distance at which a point can be snapped to @@ -201,7 +201,7 @@ value by using the [ and ] keys while drawing - + The distance at which a point can be snapped to @@ -213,6 +213,26 @@ value by using the [ and ] keys while drawing + + + + Grid extension + + + + + + + lines + + + 1 + + + 9999 + + + diff --git a/src/Mod/Draft/draftguitools/gui_selectplane.py b/src/Mod/Draft/draftguitools/gui_selectplane.py index 248c4478c2b0..b4d61d57df16 100644 --- a/src/Mod/Draft/draftguitools/gui_selectplane.py +++ b/src/Mod/Draft/draftguitools/gui_selectplane.py @@ -102,6 +102,7 @@ def Activated(self): q = FreeCAD.Units.Quantity(self.param.GetFloat("gridSpacing", 1.0), FreeCAD.Units.Length) self.taskd.form.fieldGridSpacing.setText(q.UserString) self.taskd.form.fieldGridMainLine.setValue(self.param.GetInt("gridEvery", 10)) + self.taskd.form.fieldGridExtension.setValue(self.param.GetInt("gridSize", 100)) self.taskd.form.fieldSnapRadius.setValue(self.param.GetInt("snapRange", 8)) # Set icons @@ -126,6 +127,7 @@ def Activated(self): self.taskd.form.buttonPrevious.clicked.connect(self.onClickPrevious) self.taskd.form.fieldGridSpacing.textEdited.connect(self.onSetGridSize) self.taskd.form.fieldGridMainLine.valueChanged.connect(self.onSetMainline) + self.taskd.form.fieldGridExtension.valueChanged.connect(self.onSetExtension) self.taskd.form.fieldSnapRadius.valueChanged.connect(self.onSetSnapRadius) # Try to find a WP from the current selection @@ -475,6 +477,13 @@ def onSetMainline(self, i): if hasattr(FreeCADGui, "Snapper"): FreeCADGui.Snapper.setGrid() + def onSetExtension(self, i): + """Execute when setting grid extension.""" + if i > 1: + self.param.SetInt("gridSize", i) + if hasattr(FreeCADGui, "Snapper"): + FreeCADGui.Snapper.setGrid() + def onSetSnapRadius(self, i): """Execute when setting the snap radius.""" self.param.SetInt("snapRange", i) diff --git a/src/Mod/Mesh/App/Core/Algorithm.cpp b/src/Mod/Mesh/App/Core/Algorithm.cpp index 40d7727dbc13..bc58c6e6cf5d 100644 --- a/src/Mod/Mesh/App/Core/Algorithm.cpp +++ b/src/Mod/Mesh/App/Core/Algorithm.cpp @@ -893,14 +893,16 @@ void MeshAlgorithm::ResetPointFlag (MeshPoint::TFlagType tF) const unsigned long MeshAlgorithm::CountFacetFlag (MeshFacet::TFlagType tF) const { + MeshIsFlag flag; return std::count_if(_rclMesh._aclFacetArray.begin(), _rclMesh._aclFacetArray.end(), - std::bind2nd(MeshIsFlag(), tF)); + [flag, tF](const MeshFacet& f) { return flag(f, tF);}); } unsigned long MeshAlgorithm::CountPointFlag (MeshPoint::TFlagType tF) const { + MeshIsFlag flag; return std::count_if(_rclMesh._aclPointArray.begin(), _rclMesh._aclPointArray.end(), - std::bind2nd(MeshIsFlag(), tF)); + [flag, tF](const MeshPoint& f) { return flag(f, tF);}); } void MeshAlgorithm::GetFacetsFromToolMesh( const MeshKernel& rToolMesh, const Base::Vector3f& rcDir, std::vector &raclCutted ) const diff --git a/src/Mod/Mesh/App/Core/Builder.cpp b/src/Mod/Mesh/App/Core/Builder.cpp index 02e6174f3c5b..db5a6271f5bb 100644 --- a/src/Mod/Mesh/App/Core/Builder.cpp +++ b/src/Mod/Mesh/App/Core/Builder.cpp @@ -208,7 +208,9 @@ void MeshBuilder::RemoveUnreferencedPoints() _meshKernel._aclPointArray[it->_aulPoints[i]].ResetInvalid(); } - unsigned long uValidPts = std::count_if(_meshKernel._aclPointArray.begin(), _meshKernel._aclPointArray.end(), std::mem_fun_ref(&MeshPoint::IsValid)); + unsigned long uValidPts = std::count_if(_meshKernel._aclPointArray.begin(), + _meshKernel._aclPointArray.end(), + [](const MeshPoint& p) { return p.IsValid(); }); if ( uValidPts < _meshKernel.CountPoints() ) _meshKernel.RemoveInvalids(); } diff --git a/src/Mod/Mesh/App/Core/Degeneration.cpp b/src/Mod/Mesh/App/Core/Degeneration.cpp index 6b09730d7248..440fb0bdeb00 100644 --- a/src/Mod/Mesh/App/Core/Degeneration.cpp +++ b/src/Mod/Mesh/App/Core/Degeneration.cpp @@ -1158,7 +1158,7 @@ bool MeshEvalRangePoint::Evaluate() unsigned long ulCtPoints = _rclMesh.CountPoints(); for (MeshFacetArray::_TConstIterator it = rFaces.begin(); it != rFaces.end(); ++it) { - if (std::find_if(it->_aulPoints, it->_aulPoints + 3, std::bind2nd(std::greater_equal(), ulCtPoints)) < it->_aulPoints + 3) + if (std::find_if(it->_aulPoints, it->_aulPoints + 3, [ulCtPoints](unsigned long i) { return i >= ulCtPoints; }) < it->_aulPoints + 3) return false; } @@ -1173,7 +1173,7 @@ std::vector MeshEvalRangePoint::GetIndices() const unsigned long ind=0; for (MeshFacetArray::_TConstIterator it = rFaces.begin(); it != rFaces.end(); ++it, ind++) { - if (std::find_if(it->_aulPoints, it->_aulPoints + 3, std::bind2nd(std::greater_equal(), ulCtPoints)) < it->_aulPoints + 3) + if (std::find_if(it->_aulPoints, it->_aulPoints + 3, [ulCtPoints](unsigned long i) { return i >= ulCtPoints; }) < it->_aulPoints + 3) aInds.push_back(ind); } diff --git a/src/Mod/Mesh/App/Core/Evaluation.cpp b/src/Mod/Mesh/App/Core/Evaluation.cpp index 23e0afb0df56..440e538fd380 100644 --- a/src/Mod/Mesh/App/Core/Evaluation.cpp +++ b/src/Mod/Mesh/App/Core/Evaluation.cpp @@ -226,7 +226,10 @@ std::vector MeshEvalOrientation::GetIndices() const // if the mesh consists of several topologic independent components // We can search from position 'iTri' on because all elements _before_ are already visited // what we know from the previous iteration. - iTri = std::find_if(iTri, iEnd, std::bind2nd(MeshIsNotFlag(), MeshFacet::VISIT)); + MeshIsNotFlag flag; + iTri = std::find_if(iTri, iEnd, [flag](const MeshFacet& f) { + return flag(f, MeshFacet::VISIT); + }); if (iTri < iEnd) ulStartFacet = iTri - iBeg; diff --git a/src/Mod/Mesh/App/Core/MeshIO.cpp b/src/Mod/Mesh/App/Core/MeshIO.cpp index 4cd066e5e761..bd8c5597ef6b 100644 --- a/src/Mod/Mesh/App/Core/MeshIO.cpp +++ b/src/Mod/Mesh/App/Core/MeshIO.cpp @@ -967,17 +967,17 @@ bool MeshInput::LoadPLY (std::istream &inp) // check if valid 3d points Property property; std::size_t num_x = std::count_if(vertex_props.begin(), vertex_props.end(), - std::bind2nd(property, "x")); + [&property](const std::pair& p) { return property(p, "x"); }); if (num_x != 1) return false; std::size_t num_y = std::count_if(vertex_props.begin(), vertex_props.end(), - std::bind2nd(property, "y")); + [&property](const std::pair& p) { return property(p, "y"); }); if (num_y != 1) return false; std::size_t num_z = std::count_if(vertex_props.begin(), vertex_props.end(), - std::bind2nd(property, "z")); + [&property](const std::pair& p) { return property(p, "z"); }); if (num_z != 1) return false; @@ -993,11 +993,11 @@ bool MeshInput::LoadPLY (std::istream &inp) // check if valid colors are set std::size_t num_r = std::count_if(vertex_props.begin(), vertex_props.end(), - std::bind2nd(property, "red")); + [&property](const std::pair& p) { return property(p, "red"); }); std::size_t num_g = std::count_if(vertex_props.begin(), vertex_props.end(), - std::bind2nd(property, "green")); + [&property](const std::pair& p) { return property(p, "green"); }); std::size_t num_b = std::count_if(vertex_props.begin(), vertex_props.end(), - std::bind2nd(property, "blue")); + [&property](const std::pair& p) { return property(p, "blue"); }); std::size_t rgb_colors = num_r + num_g + num_b; if (rgb_colors != 0 && rgb_colors != 3) return false; @@ -3501,8 +3501,9 @@ void MeshCleanup::RemoveInvalids() void MeshCleanup::RemoveInvalidFacets() { + MeshIsFlag flag; std::size_t countInvalidFacets = std::count_if(facetArray.begin(), facetArray.end(), - std::bind2nd(MeshIsFlag(), MeshFacet::INVALID)); + [flag](const MeshFacet& f) { return flag(f, MeshFacet::INVALID); }); if (countInvalidFacets > 0) { // adjust the material array if needed @@ -3522,15 +3523,16 @@ void MeshCleanup::RemoveInvalidFacets() MeshFacetArray copy_facets(facetArray.size() - countInvalidFacets); // copy all valid facets to the new array std::remove_copy_if(facetArray.begin(), facetArray.end(), copy_facets.begin(), - std::bind2nd(MeshIsFlag(), MeshFacet::INVALID)); + [flag](const MeshFacet& f) { return flag(f, MeshFacet::INVALID); }); facetArray.swap(copy_facets); } } void MeshCleanup::RemoveInvalidPoints() { + MeshIsFlag flag; std::size_t countInvalidPoints = std::count_if(pointArray.begin(), pointArray.end(), - std::bind2nd(MeshIsFlag(), MeshPoint::INVALID)); + [flag](const MeshPoint& p) { return flag(p, MeshPoint::INVALID); }); if (countInvalidPoints > 0) { // generate array of decrements std::vector decrements; @@ -3573,7 +3575,7 @@ void MeshCleanup::RemoveInvalidPoints() MeshPointArray copy_points(validPoints); // copy all valid facets to the new array std::remove_copy_if(pointArray.begin(), pointArray.end(), copy_points.begin(), - std::bind2nd(MeshIsFlag(), MeshPoint::INVALID)); + [flag](const MeshPoint& p) { return flag(p, MeshPoint::INVALID); }); pointArray.swap(copy_points); } } diff --git a/src/Mod/Mesh/App/Core/MeshKernel.cpp b/src/Mod/Mesh/App/Core/MeshKernel.cpp index c73e2314b8c7..dbcc8570b8a3 100644 --- a/src/Mod/Mesh/App/Core/MeshKernel.cpp +++ b/src/Mod/Mesh/App/Core/MeshKernel.cpp @@ -259,8 +259,10 @@ unsigned long MeshKernel::AddFacets(const std::vector &rclFAry, // Do not insert directly to the data structure because we should get the correct size of new // facets, otherwise std::vector reallocates too much memory which can't be freed so easily - unsigned long countValid = std::count_if(rclFAry.begin(), rclFAry.end(), - std::bind2nd(MeshIsNotFlag(), MeshFacet::INVALID)); + MeshIsNotFlag flag; + unsigned long countValid = std::count_if(rclFAry.begin(), rclFAry.end(), [flag](const MeshFacet& f) { + return flag(f, MeshFacet::INVALID); + }); _aclFacetArray.reserve( _aclFacetArray.size() + countValid ); // now start inserting the facets to the data structure and set the correct neighbourhood as well unsigned long startIndex = CountFacets(); @@ -374,8 +376,9 @@ void MeshKernel::Merge(const MeshPointArray& rPoints, const MeshFacetArray& rFac this->_aclFacetArray.push_back(face); } - unsigned long countNewPoints = std::count_if(increments.begin(), increments.end(), - std::bind2nd(std::greater(), 0)); + unsigned long countNewPoints = std::count_if(increments.begin(), increments.end(),[](unsigned long v) { + return v > 0; + }); // Reserve the additional memory to append the new points unsigned long index = this->_aclPointArray.size(); this->_aclPointArray.reserve(this->_aclPointArray.size() + countNewPoints); @@ -657,7 +660,7 @@ void MeshKernel::RemoveInvalids () // delete point, number of valid points unsigned long ulNewPts = std::count_if(_aclPointArray.begin(), _aclPointArray.end(), - std::mem_fun_ref(&MeshPoint::IsValid)); + [](const MeshPoint& p) { return p.IsValid(); }); // tmp. point array MeshPointArray aclTempPt(ulNewPts); MeshPointArray::_TIterator pPTemp = aclTempPt.begin(); @@ -702,7 +705,7 @@ void MeshKernel::RemoveInvalids () // delete facets, number of valid facets unsigned long ulDelFacets = std::count_if(_aclFacetArray.begin(), _aclFacetArray.end(), - std::mem_fun_ref(&MeshFacet::IsValid)); + [](const MeshFacet& f) { return f.IsValid(); }); MeshFacetArray aclFArray(ulDelFacets); MeshFacetArray::_TIterator pFTemp = aclFArray.begin(); pFEnd = _aclFacetArray.end(); diff --git a/src/Mod/Mesh/App/Core/Segmentation.cpp b/src/Mod/Mesh/App/Core/Segmentation.cpp index 1e6e6eefb5cd..5e84f92ba443 100644 --- a/src/Mod/Mesh/App/Core/Segmentation.cpp +++ b/src/Mod/Mesh/App/Core/Segmentation.cpp @@ -556,8 +556,10 @@ void MeshSegmentAlgorithm::FindSegments(std::vector& segm cAlgo.ResetFacetsFlag(resetVisited, MeshCore::MeshFacet::VISIT); resetVisited.clear(); - iCur = std::find_if(iBeg, iEnd, std::bind2nd(MeshCore::MeshIsNotFlag(), - MeshCore::MeshFacet::VISIT)); + MeshCore::MeshIsNotFlag flag; + iCur = std::find_if(iBeg, iEnd, [flag](const MeshFacet& f) { + return flag(f, MeshFacet::VISIT); + }); if (iCur < iEnd) startFacet = iCur - iBeg; else @@ -580,8 +582,9 @@ void MeshSegmentAlgorithm::FindSegments(std::vector& segm } // search for the next start facet - iCur = std::find_if(iCur, iEnd, std::bind2nd(MeshCore::MeshIsNotFlag(), - MeshCore::MeshFacet::VISIT)); + iCur = std::find_if(iCur, iEnd, [flag](const MeshFacet& f) { + return flag(f, MeshFacet::VISIT); + }); if (iCur < iEnd) startFacet = iCur - iBeg; else diff --git a/src/Mod/Mesh/App/Core/TopoAlgorithm.cpp b/src/Mod/Mesh/App/Core/TopoAlgorithm.cpp index 1f598fabdc0e..830a18a327f4 100644 --- a/src/Mod/Mesh/App/Core/TopoAlgorithm.cpp +++ b/src/Mod/Mesh/App/Core/TopoAlgorithm.cpp @@ -1587,7 +1587,10 @@ void MeshComponents::SearchForComponents(TMode tMode, const std::vector(), MeshFacet::VISIT)); + MeshIsNotFlag flag; + iTri = std::find_if(iTri, iEnd, [flag](const MeshFacet& f) { + return flag(f, MeshFacet::VISIT); + }); ulStartFacet = iTri - iBeg; // visitor @@ -1611,7 +1614,9 @@ void MeshComponents::SearchForComponents(TMode tMode, const std::vector(), MeshFacet::VISIT)); + iTri = std::find_if(iTri, iEnd, [flag](const MeshFacet& f) { + return flag(f, MeshFacet::VISIT); + }); if (iTri < iEnd) ulStartFacet = iTri - iBeg; diff --git a/src/Mod/Mesh/App/Mesh.cpp b/src/Mod/Mesh/App/Mesh.cpp index de8d7cb08386..f3347c8b3278 100644 --- a/src/Mod/Mesh/App/Mesh.cpp +++ b/src/Mod/Mesh/App/Mesh.cpp @@ -685,8 +685,9 @@ void MeshObject::deletedFacets(const std::vector& remFacets) // remove the invalid indices std::sort(segm.begin(), segm.end()); std::vector::iterator ft = std::find_if - (segm.begin(), segm.end(), - std::bind2nd(std::equal_to(), ULONG_MAX)); + (segm.begin(), segm.end(), [](unsigned long v) { + return v == ULONG_MAX; + }); if (ft != segm.end()) segm.erase(ft, segm.end()); it->_indices = segm; @@ -839,8 +840,9 @@ unsigned long MeshObject::getPointDegree(const std::vector& indic pointDeg[face._aulPoints[2]]--; } - unsigned long countInvalids = std::count_if(pointDeg.begin(), pointDeg.end(), - std::bind2nd(std::equal_to(), 0)); + unsigned long countInvalids = std::count_if(pointDeg.begin(), pointDeg.end(), [](unsigned long v) { + return v == 0; + }); point_degree.swap(pointDeg); return countInvalids; @@ -1386,8 +1388,8 @@ void MeshObject::removeSelfIntersections(const std::vector& indic // make sure that the number of indices is even and are in range if (indices.size() % 2 != 0) return; - if (std::find_if(indices.begin(), indices.end(), - std::bind2nd(std::greater_equal(), _kernel.CountFacets())) < indices.end()) + unsigned long cntfacets = _kernel.CountFacets(); + if (std::find_if(indices.begin(), indices.end(), [cntfacets](unsigned long v) { return v >= cntfacets; }) < indices.end()) return; std::vector > selfIntersections; std::vector::const_iterator it; diff --git a/src/Mod/Mesh/Gui/ViewProvider.cpp b/src/Mod/Mesh/Gui/ViewProvider.cpp index c288568a4dc6..8e7601dd4817 100644 --- a/src/Mod/Mesh/Gui/ViewProvider.cpp +++ b/src/Mod/Mesh/Gui/ViewProvider.cpp @@ -2047,9 +2047,10 @@ void ViewProviderMesh::invertSelection() { const Mesh::MeshObject& rMesh = static_cast(pcObject)->Mesh.getValue(); const MeshCore::MeshFacetArray& faces = rMesh.getKernel().GetFacets(); - unsigned long num_notsel = std::count_if(faces.begin(), faces.end(), - std::bind2nd(MeshCore::MeshIsNotFlag(), - MeshCore::MeshFacet::SELECTED)); + MeshCore::MeshIsNotFlag flag; + unsigned long num_notsel = std::count_if(faces.begin(), faces.end(), [flag](const MeshCore::MeshFacet& f) { + return flag(f, MeshCore::MeshFacet::SELECTED); + }); std::vector notselect; notselect.reserve(num_notsel); MeshCore::MeshFacetArray::_TConstIterator beg = faces.begin(); diff --git a/src/Mod/Part/App/AppPart.cpp b/src/Mod/Part/App/AppPart.cpp index 1406ea900f18..ba5ae7d84dbb 100644 --- a/src/Mod/Part/App/AppPart.cpp +++ b/src/Mod/Part/App/AppPart.cpp @@ -108,6 +108,7 @@ #include "Mod/Part/App/BRepOffsetAPI_MakeFillingPy.h" #include "Mod/Part/App/PartFeaturePy.h" #include "Mod/Part/App/AttachEnginePy.h" +#include #include #include #include @@ -376,6 +377,10 @@ PyMOD_INIT_FUNC(Part) Base::Interpreter().addType(&Part::GeometryBoolExtensionPy ::Type,partModule,"GeometryBoolExtension"); Base::Interpreter().addType(&Part::GeometryDoubleExtensionPy ::Type,partModule,"GeometryDoubleExtension"); + // BRepFeat package + PyObject* brepfeatModule(module.getAttr("BRepFeat").ptr()); + Base::Interpreter().addType(&Part::MakePrismPy::Type,brepfeatModule,"MakePrism"); + // BRepOffsetAPI package PyObject* brepOffsetApiModule(module.getAttr("BRepOffsetAPI").ptr()); Base::Interpreter().addType(&Part::BRepOffsetAPI_MakePipeShellPy::Type,brepOffsetApiModule,"MakePipeShell"); diff --git a/src/Mod/Part/App/AppPartPy.cpp b/src/Mod/Part/App/AppPartPy.cpp index 4a94a21528da..8bafa61b1d11 100644 --- a/src/Mod/Part/App/AppPartPy.cpp +++ b/src/Mod/Part/App/AppPartPy.cpp @@ -271,6 +271,17 @@ PartExport std::list sort_Edges(double tol3d, std::list +{ +public: + BRepFeatModule() : Py::ExtensionModule("BRepFeat") + { + initialize("This is a module working with the BRepFeat package."); // register with Python + } + + virtual ~BRepFeatModule() {} +}; + class BRepOffsetAPIModule : public Py::ExtensionModule { public: @@ -317,6 +328,7 @@ class ShapeUpgradeModule : public Py::ExtensionModule class Module : public Py::ExtensionModule { + BRepFeatModule brepFeat; BRepOffsetAPIModule brepOffsetApi; Geom2dModule geom2d; GeomPlateModule geomPlate; @@ -537,6 +549,7 @@ class Module : public Py::ExtensionModule ); initialize("This is a module working with shapes."); // register with Python + PyModule_AddObject(m_module, "BRepFeat", brepFeat.module().ptr()); PyModule_AddObject(m_module, "BRepOffsetAPI", brepOffsetApi.module().ptr()); PyModule_AddObject(m_module, "Geom2d", geom2d.module().ptr()); PyModule_AddObject(m_module, "GeomPlate", geomPlate.module().ptr()); @@ -912,17 +925,8 @@ class Module : public Py::ExtensionModule fm->Build(); - if(fm->Shape().IsNull()) - return Py::asObject(new TopoShapePy(new TopoShape(fm->Shape()))); - - switch(fm->Shape().ShapeType()){ - case TopAbs_FACE: - return Py::asObject(new TopoShapeFacePy(new TopoShape(fm->Shape()))); - case TopAbs_COMPOUND: - return Py::asObject(new TopoShapeCompoundPy(new TopoShape(fm->Shape()))); - default: - return Py::asObject(new TopoShapePy(new TopoShape(fm->Shape()))); - } + TopoShape topo(fm->Shape()); + return Py::asObject(topo.getPyObject()); } throw Py::Exception(Base::BaseExceptionFreeCADError, std::string("Argument type signature not recognized. Should be either (list, string), or (shape, string)")); @@ -2012,36 +2016,7 @@ class Module : public Py::ExtensionModule PyObject *object; if (PyArg_ParseTuple(args.ptr(),"O!",&(Part::TopoShapePy::Type), &object)) { TopoShape* ptr = static_cast(object)->getTopoShapePtr(); - TopoDS_Shape shape = ptr->getShape(); - if (!shape.IsNull()) { - TopAbs_ShapeEnum type = shape.ShapeType(); - switch (type) - { - case TopAbs_COMPOUND: - return Py::asObject(new TopoShapeCompoundPy(new TopoShape(shape))); - case TopAbs_COMPSOLID: - return Py::asObject(new TopoShapeCompSolidPy(new TopoShape(shape))); - case TopAbs_SOLID: - return Py::asObject(new TopoShapeSolidPy(new TopoShape(shape))); - case TopAbs_SHELL: - return Py::asObject(new TopoShapeShellPy(new TopoShape(shape))); - case TopAbs_FACE: - return Py::asObject(new TopoShapeFacePy(new TopoShape(shape))); - case TopAbs_WIRE: - return Py::asObject(new TopoShapeWirePy(new TopoShape(shape))); - case TopAbs_EDGE: - return Py::asObject(new TopoShapeEdgePy(new TopoShape(shape))); - case TopAbs_VERTEX: - return Py::asObject(new TopoShapeVertexPy(new TopoShape(shape))); - case TopAbs_SHAPE: - return Py::asObject(new TopoShapePy(new TopoShape(shape))); - default: - break; - } - } - else { - throw Py::Exception(PartExceptionOCCError, "empty shape"); - } + return Py::asObject(ptr->getPyObject()); } throw Py::Exception(); diff --git a/src/Mod/Part/App/BRepFeat/MakePrismPy.xml b/src/Mod/Part/App/BRepFeat/MakePrismPy.xml new file mode 100644 index 000000000000..a56b19cee327 --- /dev/null +++ b/src/Mod/Part/App/BRepFeat/MakePrismPy.xml @@ -0,0 +1,100 @@ + + + + + + Describes functions to build prism features. + + + + +Initializes this algorithm for building prisms along surfaces. +A face Pbase is selected in the shape Sbase +to serve as the basis for the prism. The orientation +of the prism will be defined by the vector Direction. + +Fuse offers a choice between: +- removing matter with a Boolean cut using the setting 0 +- adding matter with Boolean fusion using the setting 1. +The sketch face Skface serves to determine +the type of operation. If it is inside the basis +shape, a local operation such as glueing can be performed. + + + + + + +Indicates that the edge will slide on the face. +Raises ConstructionError if the face does not belong to the +basis shape, or the edge to the prismed shape. + + + + + + + + + + + +Realizes a semi-infinite prism, limited by the +position of the prism base. All other faces extend infinitely. + + + + + + +Realizes a semi-infinite prism, limited by the face Funtil. + + + + + + +Builds an infinite prism. The infinite descendants will not be kept in the result. + + + + + + +Assigns both a limiting shape, Until from TopoDS_Shape +and a height, Length at which to stop generation of the prism feature. + + + + + + +Returns the list of curves S parallel to the axis of the prism. + + + + + + +Generates a curve along the center of mass of the primitive. + + + + + + Returns a shape built by the shape construction algorithm. + + + + diff --git a/src/Mod/Part/App/BRepFeat/MakePrismPyImp.cpp b/src/Mod/Part/App/BRepFeat/MakePrismPyImp.cpp new file mode 100644 index 000000000000..12bdee0cc6e9 --- /dev/null +++ b/src/Mod/Part/App/BRepFeat/MakePrismPyImp.cpp @@ -0,0 +1,339 @@ +/*************************************************************************** + * Copyright (c) 2020 Werner Mayer * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + + +#include "PreCompiled.h" +#ifndef _PreComp_ +# include +# include +# include +#endif + +#include "BRepFeat/MakePrismPy.h" +#include "BRepFeat/MakePrismPy.cpp" +#include "Geometry.h" +#include "TopoShapeEdgePy.h" +#include "TopoShapeFacePy.h" +#include + +using namespace Part; + + +PyObject *MakePrismPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper +{ + // create a new instance of MakePrismPy + return new MakePrismPy(nullptr); +} + +// constructor method +int MakePrismPy::PyInit(PyObject* args, PyObject* kwds) +{ + PyObject* Sbase; + PyObject* Pbase; + PyObject* Skface; + PyObject* Direction; + int Fuse; + PyObject* Modify; + static char* keywords[] = {"Sbase", "Pbase", "Skface", "Direction", "Fuse", "Modifiy", nullptr}; + if (PyArg_ParseTupleAndKeywords(args, kwds, "O!O!O!O!iO!", keywords, + &(TopoShapePy::Type), &Sbase, + &(TopoShapePy::Type), &Pbase, + &(TopoShapeFacePy::Type), &Skface, + &(Base::VectorPy::Type), &Direction, &Fuse, + &(PyBool_Type), &Modify)) { + try { + TopoDS_Shape sbase = static_cast(Sbase)->getTopoShapePtr()->getShape(); + TopoDS_Shape pbase = static_cast(Pbase)->getTopoShapePtr()->getShape(); + TopoDS_Face skface = TopoDS::Face(static_cast(Skface)->getTopoShapePtr()->getShape()); + Base::Vector3d dir = static_cast(Direction)->value(); + std::unique_ptr ptr(new BRepFeat_MakePrism(sbase, pbase, skface, gp_Dir(dir.x, dir.y, dir.z), Fuse, + PyObject_IsTrue(Modify) ? Standard_True : Standard_False)); + + setTwinPointer(ptr.release()); + return 0; + } + catch (const Standard_Failure& e) { + PyErr_SetString(PyExc_RuntimeError, e.GetMessageString()); + return -1; + } + } + + PyErr_Clear(); + if (PyArg_ParseTuple(args, "")) { + try { + std::unique_ptr ptr(new BRepFeat_MakePrism()); + setTwinPointer(ptr.release()); + return 0; + } + catch (const Standard_Failure& e) { + PyErr_SetString(PyExc_RuntimeError, e.GetMessageString()); + return -1; + } + } + + PyErr_SetString(PyExc_TypeError, "supported signatures:\n" + "MakePrism()\n" + "MakePrism(Sbase [shape], Pbase [shape], Skface [face], Direction [Vector], Fuse [int={0, 1}], Modify [bool])\n"); + return -1; +} + +// returns a string which represents the object e.g. when printed in python +std::string MakePrismPy::representation(void) const +{ + return std::string(""); +} + +PyObject* MakePrismPy::init(PyObject *args, PyObject* kwds) +{ + PyObject* Sbase; + PyObject* Pbase; + PyObject* Skface; + PyObject* Direction; + int Fuse; + PyObject* Modify; + static char* keywords[] = {"Sbase", "Pbase", "Skface", "Direction", "Fuse", "Modifiy", nullptr}; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!O!O!O!iO!", keywords, + &(TopoShapePy::Type), &Sbase, + &(TopoShapePy::Type), &Pbase, + &(TopoShapeFacePy::Type), &Skface, + &(Base::VectorPy::Type), &Direction, &Fuse, + &(PyBool_Type), &Modify)) + return nullptr; + + + try { + TopoDS_Shape sbase = static_cast(Sbase)->getTopoShapePtr()->getShape(); + TopoDS_Shape pbase = static_cast(Pbase)->getTopoShapePtr()->getShape(); + TopoDS_Face skface = TopoDS::Face(static_cast(Skface)->getTopoShapePtr()->getShape()); + Base::Vector3d dir = static_cast(Direction)->value(); + getBRepFeat_MakePrismPtr()->Init(sbase, pbase, skface, gp_Dir(dir.x, dir.y, dir.z), Fuse, + PyObject_IsTrue(Modify) ? Standard_True : Standard_False); + + Py_Return; + } + catch (const Standard_Failure& e) { + PyErr_SetString(PyExc_RuntimeError, e.GetMessageString()); + return nullptr; + } +} + +PyObject* MakePrismPy::add(PyObject *args, PyObject* kwds) +{ + PyObject* Edge; + PyObject* Face; + static char* keywords[] = {"Edge", "Face", nullptr}; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!O!", keywords, + &(TopoShapeEdgePy::Type), &Edge, + &(TopoShapeFacePy::Type), &Face)) + return nullptr; + + + try { + TopoDS_Edge edge = TopoDS::Edge(static_cast(Edge)->getTopoShapePtr()->getShape()); + TopoDS_Face face = TopoDS::Face(static_cast(Face)->getTopoShapePtr()->getShape()); + getBRepFeat_MakePrismPtr()->Add(edge, face); + + Py_Return; + } + catch (const Standard_Failure& e) { + PyErr_SetString(PyExc_RuntimeError, e.GetMessageString()); + return nullptr; + } +} + +PyObject* MakePrismPy::perform(PyObject *args, PyObject* kwds) +{ + PyObject* From; + PyObject* Until; + static char* keywords_fu[] = {"From", "Until", nullptr}; + if (PyArg_ParseTupleAndKeywords(args, kwds, "O!O!", keywords_fu, + &(TopoShapePy::Type), &From, + &(TopoShapePy::Type), &Until)) { + try { + TopoDS_Shape from = static_cast(From)->getTopoShapePtr()->getShape(); + TopoDS_Shape until = static_cast(Until)->getTopoShapePtr()->getShape(); + getBRepFeat_MakePrismPtr()->Perform(from, until); + Py_Return; + } + catch (const Standard_Failure& e) { + PyErr_SetString(PyExc_RuntimeError, e.GetMessageString()); + return nullptr; + } + } + + PyErr_Clear(); + static char* keywords_u[] = {"Until", nullptr}; + if (PyArg_ParseTupleAndKeywords(args, kwds, "O!", keywords_u, + &(TopoShapePy::Type), &Until)) { + try { + TopoDS_Shape until = static_cast(Until)->getTopoShapePtr()->getShape(); + getBRepFeat_MakePrismPtr()->Perform(until); + Py_Return; + } + catch (const Standard_Failure& e) { + PyErr_SetString(PyExc_RuntimeError, e.GetMessageString()); + return nullptr; + } + } + + PyErr_Clear(); + double length; + static char* keywords_l[] = {"Length", nullptr}; + if (PyArg_ParseTupleAndKeywords(args, kwds, "d", keywords_l, &length)) { + try { + getBRepFeat_MakePrismPtr()->Perform(length); + Py_Return; + } + catch (const Standard_Failure& e) { + PyErr_SetString(PyExc_RuntimeError, e.GetMessageString()); + return nullptr; + } + } + + PyErr_SetString(PyExc_TypeError, "supported signatures:\n" + "perform(From [shape], Until [shape])\n" + "perform(Until [shape])\n" + "perform(Length [float])\n"); + return nullptr; +} + +PyObject* MakePrismPy::performUntilEnd(PyObject *args) +{ + if (!PyArg_ParseTuple(args, "")) + return nullptr; + + try { + getBRepFeat_MakePrismPtr()->PerformUntilEnd(); + Py_Return; + } + catch (const Standard_Failure& e) { + PyErr_SetString(PyExc_RuntimeError, e.GetMessageString()); + return nullptr; + } +} + +PyObject* MakePrismPy::performFromEnd(PyObject *args) +{ + PyObject* Until; + if (!PyArg_ParseTuple(args, "O!", &(TopoShapePy::Type), &Until)) + return nullptr; + + try { + TopoDS_Shape until = static_cast(Until)->getTopoShapePtr()->getShape(); + getBRepFeat_MakePrismPtr()->PerformFromEnd(until); + Py_Return; + } + catch (const Standard_Failure& e) { + PyErr_SetString(PyExc_RuntimeError, e.GetMessageString()); + return nullptr; + } +} + +PyObject* MakePrismPy::performThruAll(PyObject *args) +{ + if (!PyArg_ParseTuple(args, "")) + return nullptr; + + try { + getBRepFeat_MakePrismPtr()->PerformThruAll(); + Py_Return; + } + catch (const Standard_Failure& e) { + PyErr_SetString(PyExc_RuntimeError, e.GetMessageString()); + return nullptr; + } +} + +PyObject* MakePrismPy::performUntilHeight(PyObject *args) +{ + PyObject* Until; + double length; + if (!PyArg_ParseTuple(args, "O!d", &(TopoShapePy::Type), &Until, &length)) + return nullptr; + + try { + TopoDS_Shape until = static_cast(Until)->getTopoShapePtr()->getShape(); + getBRepFeat_MakePrismPtr()->PerformUntilHeight(until, length); + Py_Return; + } + catch (const Standard_Failure& e) { + PyErr_SetString(PyExc_RuntimeError, e.GetMessageString()); + return nullptr; + } +} + +PyObject* MakePrismPy::curves(PyObject *args) +{ + if (!PyArg_ParseTuple(args, "")) + return nullptr; + + TColGeom_SequenceOfCurve S; + getBRepFeat_MakePrismPtr()->Curves(S); + + Py::Tuple tuple(S.Length()); + for (int i = S.Lower(); i <= S.Upper(); ++i) { + Handle(Geom_Curve) hC = S.Value(i); + if (hC.IsNull()) + continue; + std::unique_ptr gc(Part::makeFromCurve(hC)); + tuple.setItem(i, Py::asObject(gc->getPyObject())); + } + + return Py::new_reference_to(tuple); +} + +PyObject* MakePrismPy::barycCurve(PyObject *args) +{ + if (!PyArg_ParseTuple(args, "")) + return nullptr; + + Handle(Geom_Curve) hC = getBRepFeat_MakePrismPtr()->BarycCurve(); + if (hC.IsNull()) + Py_Return; + std::unique_ptr gc(Part::makeFromCurve(hC)); + return gc->getPyObject(); +} + +PyObject* MakePrismPy::shape(PyObject *args) +{ + if (!PyArg_ParseTuple(args, "")) + return nullptr; + + try { + TopoShape shape(getBRepFeat_MakePrismPtr()->Shape()); + return shape.getPyObject(); + } + catch (const Standard_Failure& e) { + PyErr_SetString(PyExc_RuntimeError, e.GetMessageString()); + return nullptr; + } +} + +PyObject *MakePrismPy::getCustomAttributes(const char* /*attr*/) const +{ + return 0; +} + +int MakePrismPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/) +{ + return 0; +} diff --git a/src/Mod/Part/App/CMakeLists.txt b/src/Mod/Part/App/CMakeLists.txt index b6aed42172b7..d291c20e4504 100644 --- a/src/Mod/Part/App/CMakeLists.txt +++ b/src/Mod/Part/App/CMakeLists.txt @@ -94,10 +94,13 @@ generate_from_xml(BRepOffsetAPI_MakePipeShellPy) generate_from_xml(BRepOffsetAPI_MakeFillingPy) # make sure to create the directory at configure time +file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/BRepFeat) file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/Geom2d) file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/GeomPlate) file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/ShapeUpgrade) +generate_from_xml(BRepFeat/MakePrismPy) + generate_from_xml(Geom2d/ArcOfCircle2dPy) generate_from_xml(Geom2d/ArcOfConic2dPy) generate_from_xml(Geom2d/ArcOfEllipse2dPy) @@ -312,6 +315,14 @@ SET(Python_SRCS ) SOURCE_GROUP("Python" FILES ${Python_SRCS}) +# BRepFeat wrappers +SET(BRepFeatPy_SRCS + BRepFeat/MakePrismPy.xml + BRepFeat/MakePrismPyImp.cpp +) + +SOURCE_GROUP("ShapeUpgrade" FILES ${ShapeUpgradePy_SRCS}) + # Geom2d wrappers SET(Geom2dPy_SRCS Geom2d/ArcOfCircle2dPy.xml @@ -376,6 +387,7 @@ SET(Part_SRCS ${Features_SRCS} ${Properties_SRCS} ${Python_SRCS} + ${BRepFeatPy_SRCS} ${Geom2dPy_SRCS} ${GeomPlatePy_SRCS} ${ShapeUpgradePy_SRCS} diff --git a/src/Mod/Part/App/PartPyCXX.cpp b/src/Mod/Part/App/PartPyCXX.cpp index 44eda6bf96a2..53967567cab8 100644 --- a/src/Mod/Part/App/PartPyCXX.cpp +++ b/src/Mod/Part/App/PartPyCXX.cpp @@ -35,48 +35,7 @@ namespace Part { PartExport Py::Object shape2pyshape(const TopoShape &shape) { - PyObject* ret = 0; - if (!shape.isNull()) { - TopAbs_ShapeEnum type = shape.getShape().ShapeType(); - switch (type) - { - case TopAbs_COMPOUND: - ret = new TopoShapeCompoundPy(new TopoShape(shape)); - break; - case TopAbs_COMPSOLID: - ret = new TopoShapeCompSolidPy(new TopoShape(shape)); - break; - case TopAbs_SOLID: - ret = new TopoShapeSolidPy(new TopoShape(shape)); - break; - case TopAbs_SHELL: - ret = new TopoShapeShellPy(new TopoShape(shape)); - break; - case TopAbs_FACE: - ret = new TopoShapeFacePy(new TopoShape(shape)); - break; - case TopAbs_WIRE: - ret = new TopoShapeWirePy(new TopoShape(shape)); - break; - case TopAbs_EDGE: - ret = new TopoShapeEdgePy(new TopoShape(shape)); - break; - case TopAbs_VERTEX: - ret = new TopoShapeVertexPy(new TopoShape(shape)); - break; - case TopAbs_SHAPE: - ret = new TopoShapePy(new TopoShape(shape)); - break; - default: - //shouldn't happen - ret = new TopoShapePy(new TopoShape(shape)); - break; - } - } else { - ret = new TopoShapePy(new TopoShape(shape)); - } - assert(ret); - + PyObject* ret = const_cast(shape).getPyObject(); return Py::asObject(ret); } diff --git a/src/Mod/Part/App/PropertyTopoShape.cpp b/src/Mod/Part/App/PropertyTopoShape.cpp index b632411a8a61..ca011e5e4b9b 100644 --- a/src/Mod/Part/App/PropertyTopoShape.cpp +++ b/src/Mod/Part/App/PropertyTopoShape.cpp @@ -146,47 +146,9 @@ void PropertyPartShape::transformGeometry(const Base::Matrix4D &rclTrf) PyObject *PropertyPartShape::getPyObject(void) { - Base::PyObjectBase* prop; - const TopoDS_Shape& sh = _Shape.getShape(); - if (sh.IsNull()) { - prop = new TopoShapePy(new TopoShape(sh)); - } - else { - TopAbs_ShapeEnum type = sh.ShapeType(); - switch (type) - { - case TopAbs_COMPOUND: - prop = new TopoShapeCompoundPy(new TopoShape(sh)); - break; - case TopAbs_COMPSOLID: - prop = new TopoShapeCompSolidPy(new TopoShape(sh)); - break; - case TopAbs_SOLID: - prop = new TopoShapeSolidPy(new TopoShape(sh)); - break; - case TopAbs_SHELL: - prop = new TopoShapeShellPy(new TopoShape(sh)); - break; - case TopAbs_FACE: - prop = new TopoShapeFacePy(new TopoShape(sh)); - break; - case TopAbs_WIRE: - prop = new TopoShapeWirePy(new TopoShape(sh)); - break; - case TopAbs_EDGE: - prop = new TopoShapeEdgePy(new TopoShape(sh)); - break; - case TopAbs_VERTEX: - prop = new TopoShapeVertexPy(new TopoShape(sh)); - break; - case TopAbs_SHAPE: - default: - prop = new TopoShapePy(new TopoShape(sh)); - break; - } - } - - prop->setConst(); + Base::PyObjectBase* prop = static_cast(_Shape.getPyObject()); + if (prop) + prop->setConst(); return prop; } diff --git a/src/Mod/Part/App/TopoShape.cpp b/src/Mod/Part/App/TopoShape.cpp index f954552dcce8..0e523ef3a624 100644 --- a/src/Mod/Part/App/TopoShape.cpp +++ b/src/Mod/Part/App/TopoShape.cpp @@ -199,6 +199,11 @@ #include "TopoShapeFacePy.h" #include "TopoShapeEdgePy.h" #include "TopoShapeVertexPy.h" +#include "TopoShapeWirePy.h" +#include "TopoShapeShellPy.h" +#include "TopoShapeSolidPy.h" +#include "TopoShapeCompoundPy.h" +#include "TopoShapeCompSolidPy.h" #include "ProgressIndicator.h" #include "modelRefine.h" #include "Tools.h" @@ -542,6 +547,62 @@ PyObject * TopoShape::getPySubShape(const char* Type, bool silent) const return Py::new_reference_to(shape2pyshape(getSubShape(Type,silent))); } +PyObject * TopoShape::getPyObject() +{ + Base::PyObjectBase* prop = nullptr; + if (_Shape.IsNull()) { + prop = new TopoShapePy(new TopoShape(_Shape)); + } + else { + TopAbs_ShapeEnum type = _Shape.ShapeType(); + switch (type) + { + case TopAbs_COMPOUND: + prop = new TopoShapeCompoundPy(new TopoShape(_Shape)); + break; + case TopAbs_COMPSOLID: + prop = new TopoShapeCompSolidPy(new TopoShape(_Shape)); + break; + case TopAbs_SOLID: + prop = new TopoShapeSolidPy(new TopoShape(_Shape)); + break; + case TopAbs_SHELL: + prop = new TopoShapeShellPy(new TopoShape(_Shape)); + break; + case TopAbs_FACE: + prop = new TopoShapeFacePy(new TopoShape(_Shape)); + break; + case TopAbs_WIRE: + prop = new TopoShapeWirePy(new TopoShape(_Shape)); + break; + case TopAbs_EDGE: + prop = new TopoShapeEdgePy(new TopoShape(_Shape)); + break; + case TopAbs_VERTEX: + prop = new TopoShapeVertexPy(new TopoShape(_Shape)); + break; + case TopAbs_SHAPE: + default: + prop = new TopoShapePy(new TopoShape(_Shape)); + break; + } + } + + return prop; +} + +void TopoShape::setPyObject(PyObject* obj) +{ + if (PyObject_TypeCheck(obj, &TopoShapePy::Type)) { + this->_Shape = static_cast(obj)->getTopoShapePtr()->getShape(); + } + else { + std::string error = std::string("type must be 'Shape', not "); + error += obj->ob_type->tp_name; + throw Base::TypeError(error); + } +} + void TopoShape::operator = (const TopoShape& sh) { if (this != &sh) { diff --git a/src/Mod/Part/App/TopoShape.h b/src/Mod/Part/App/TopoShape.h index 37ed0882f90a..650eebecf45c 100644 --- a/src/Mod/Part/App/TopoShape.h +++ b/src/Mod/Part/App/TopoShape.h @@ -157,6 +157,8 @@ class PartExport TopoShape : public Data::ComplexGeoData bool hasSubShape(TopAbs_ShapeEnum type) const; /// get the Topo"sub"Shape with the given name PyObject * getPySubShape(const char* Type, bool silent=false) const; + PyObject * getPyObject(); + void setPyObject(PyObject*); /** @name Save/restore */ //@{ diff --git a/src/Mod/Part/App/TopoShapeCompSolidPyImp.cpp b/src/Mod/Part/App/TopoShapeCompSolidPyImp.cpp index 6245ef1493cb..f64467b0a07c 100644 --- a/src/Mod/Part/App/TopoShapeCompSolidPyImp.cpp +++ b/src/Mod/Part/App/TopoShapeCompSolidPyImp.cpp @@ -55,6 +55,13 @@ PyObject *TopoShapeCompSolidPy::PyMake(struct _typeobject *, PyObject *, PyObjec int TopoShapeCompSolidPy::PyInit(PyObject* args, PyObject* /*kwd*/) { + if (PyArg_ParseTuple(args, "")) { + // Undefined CompSolid + getTopoShapePtr()->setShape(TopoDS_CompSolid()); + return 0; + } + + PyErr_Clear(); PyObject *pcObj; if (!PyArg_ParseTuple(args, "O", &pcObj)) return -1; diff --git a/src/Mod/Part/App/TopoShapeCompoundPyImp.cpp b/src/Mod/Part/App/TopoShapeCompoundPyImp.cpp index 9c35c44d2834..174f7b955063 100644 --- a/src/Mod/Part/App/TopoShapeCompoundPyImp.cpp +++ b/src/Mod/Part/App/TopoShapeCompoundPyImp.cpp @@ -59,6 +59,13 @@ PyObject *TopoShapeCompoundPy::PyMake(struct _typeobject *, PyObject *, PyObject // constructor method int TopoShapeCompoundPy::PyInit(PyObject* args, PyObject* /*kwd*/) { + if (PyArg_ParseTuple(args, "")) { + // Undefined Compound + getTopoShapePtr()->setShape(TopoDS_Compound()); + return 0; + } + + PyErr_Clear(); PyObject *pcObj; if (!PyArg_ParseTuple(args, "O", &pcObj)) return -1; @@ -79,7 +86,6 @@ int TopoShapeCompoundPy::PyInit(PyObject* args, PyObject* /*kwd*/) } } catch (Standard_Failure& e) { - PyErr_SetString(PartExceptionOCCError, e.GetMessageString()); return -1; } diff --git a/src/Mod/Part/App/TopoShapeEdgePyImp.cpp b/src/Mod/Part/App/TopoShapeEdgePyImp.cpp index 61370f718400..782efc4fbfef 100644 --- a/src/Mod/Part/App/TopoShapeEdgePyImp.cpp +++ b/src/Mod/Part/App/TopoShapeEdgePyImp.cpp @@ -121,6 +121,13 @@ PyObject *TopoShapeEdgePy::PyMake(struct _typeobject *, PyObject *, PyObject *) // constructor method int TopoShapeEdgePy::PyInit(PyObject* args, PyObject* /*kwd*/) { + if (PyArg_ParseTuple(args, "")) { + // Undefined Edge + getTopoShapePtr()->setShape(TopoDS_Edge()); + return 0; + } + + PyErr_Clear(); PyObject *pcObj, *pcObj2; double first=DBL_MAX, last=DBL_MAX; if (PyArg_ParseTuple(args, "O!|dd", &(Part::GeometryPy::Type), &pcObj, &first, &last)) { diff --git a/src/Mod/Part/App/TopoShapeFacePyImp.cpp b/src/Mod/Part/App/TopoShapeFacePyImp.cpp index 66e32bb1586b..cd0ff350a18e 100644 --- a/src/Mod/Part/App/TopoShapeFacePyImp.cpp +++ b/src/Mod/Part/App/TopoShapeFacePyImp.cpp @@ -117,6 +117,13 @@ PyObject *TopoShapeFacePy::PyMake(struct _typeobject *, PyObject *, PyObject *) // constructor method int TopoShapeFacePy::PyInit(PyObject* args, PyObject* /*kwd*/) { + if (PyArg_ParseTuple(args, "")) { + // Undefined Face + getTopoShapePtr()->setShape(TopoDS_Face()); + return 0; + } + + PyErr_Clear(); PyObject *pW; if (PyArg_ParseTuple(args, "O!", &(Part::TopoShapePy::Type), &pW)) { try { diff --git a/src/Mod/Part/App/TopoShapeShellPyImp.cpp b/src/Mod/Part/App/TopoShapeShellPyImp.cpp index 7e7e8d68f215..1d8fbf90a95d 100644 --- a/src/Mod/Part/App/TopoShapeShellPyImp.cpp +++ b/src/Mod/Part/App/TopoShapeShellPyImp.cpp @@ -77,6 +77,13 @@ PyObject *TopoShapeShellPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // constructor method int TopoShapeShellPy::PyInit(PyObject* args, PyObject* /*kwd*/) { + if (PyArg_ParseTuple(args, "")) { + // Undefined Shell + getTopoShapePtr()->setShape(TopoDS_Shell()); + return 0; + } + + PyErr_Clear(); PyObject *obj; if (!PyArg_ParseTuple(args, "O", &obj)) return -1; diff --git a/src/Mod/Part/App/TopoShapeSolidPyImp.cpp b/src/Mod/Part/App/TopoShapeSolidPyImp.cpp index 24e5b9e37797..8c2960e75148 100644 --- a/src/Mod/Part/App/TopoShapeSolidPyImp.cpp +++ b/src/Mod/Part/App/TopoShapeSolidPyImp.cpp @@ -79,6 +79,13 @@ PyObject *TopoShapeSolidPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // constructor method int TopoShapeSolidPy::PyInit(PyObject* args, PyObject* /*kwd*/) { + if (PyArg_ParseTuple(args, "")) { + // Undefined Solid + getTopoShapePtr()->setShape(TopoDS_Solid()); + return 0; + } + + PyErr_Clear(); PyObject *obj; if (!PyArg_ParseTuple(args, "O!", &(TopoShapePy::Type), &obj)) return -1; diff --git a/src/Mod/Part/App/TopoShapeVertexPyImp.cpp b/src/Mod/Part/App/TopoShapeVertexPyImp.cpp index a522a216a075..6c7dd4bba0c7 100644 --- a/src/Mod/Part/App/TopoShapeVertexPyImp.cpp +++ b/src/Mod/Part/App/TopoShapeVertexPyImp.cpp @@ -63,6 +63,13 @@ PyObject *TopoShapeVertexPy::PyMake(struct _typeobject *, PyObject *, PyObject * // constructor method int TopoShapeVertexPy::PyInit(PyObject* args, PyObject* /*kwd*/) { + if (PyArg_ParseTuple(args, "")) { + // Undefined Vertex + getTopoShapePtr()->setShape(TopoDS_Vertex()); + return 0; + } + + PyErr_Clear(); double x=0.0,y=0.0,z=0.0; PyObject *object; bool success = false; diff --git a/src/Mod/Part/App/TopoShapeWirePyImp.cpp b/src/Mod/Part/App/TopoShapeWirePyImp.cpp index 24abdf2cf1f6..800546abb247 100644 --- a/src/Mod/Part/App/TopoShapeWirePyImp.cpp +++ b/src/Mod/Part/App/TopoShapeWirePyImp.cpp @@ -85,6 +85,13 @@ PyObject *TopoShapeWirePy::PyMake(struct _typeobject *, PyObject *, PyObject *) // constructor method int TopoShapeWirePy::PyInit(PyObject* args, PyObject* /*kwd*/) { + if (PyArg_ParseTuple(args, "")) { + // Undefined Wire + getTopoShapePtr()->setShape(TopoDS_Wire()); + return 0; + } + + PyErr_Clear(); PyObject *pcObj; if (PyArg_ParseTuple(args, "O!", &(Part::TopoShapePy::Type), &pcObj)) { BRepBuilderAPI_MakeWire mkWire; diff --git a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp index 38aaea14e791..1d2f6117da0f 100644 --- a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp +++ b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp @@ -3198,8 +3198,7 @@ void ViewProviderSketch::drawConstraintIcons() void ViewProviderSketch::combineConstraintIcons(IconQueue iconQueue) { // getScaleFactor gives us a ratio of pixels per some kind of real units - // (Translation: this number is somewhat made-up.) - float maxDistSquared = pow(0.05 * getScaleFactor(), 2); + float maxDistSquared = pow(getScaleFactor(), 2); // There's room for optimisation here; we could reuse the combined icons... edit->combinedConstrBoxes.clear(); @@ -3219,8 +3218,9 @@ void ViewProviderSketch::combineConstraintIcons(IconQueue iconQueue) bool addedToGroup = false; for(IconQueue::iterator j = thisGroup.begin(); - j != thisGroup.end(); ++j) - if(i->position.equals(j->position, maxDistSquared) && (*i).type != QString::fromLatin1("small/Constraint_Symmetric_sm")) { + j != thisGroup.end(); ++j) { + float distSquared = pow(i->position[0]-j->position[0],2) + pow(i->position[1]-j->position[1],2); + if(distSquared <= maxDistSquared && (*i).type != QString::fromLatin1("small/Constraint_Symmetric_sm")) { // Found an icon in iconQueue that's close enough to // a member of thisGroup, so move it into thisGroup thisGroup.push_back(*i); @@ -3228,6 +3228,7 @@ void ViewProviderSketch::combineConstraintIcons(IconQueue iconQueue) addedToGroup = true; break; } + } if(addedToGroup) { if(i == iconQueue.end()) @@ -3253,17 +3254,13 @@ void ViewProviderSketch::combineConstraintIcons(IconQueue iconQueue) void ViewProviderSketch::drawMergedConstraintIcons(IconQueue iconQueue) { - SbVec3f avPos(0, 0, 0); for(IconQueue::iterator i = iconQueue.begin(); i != iconQueue.end(); ++i) { clearCoinImage(i->destination); - avPos = avPos + i->position; } - avPos = avPos/iconQueue.size(); QImage compositeIcon; - float closest = FLT_MAX; // Closest distance between avPos and any icon - SoImage *thisDest = 0; - SoInfo *thisInfo = 0; + SoImage *thisDest = iconQueue[0].destination; + SoInfo *thisInfo = iconQueue[0].infoPtr; // Tracks all constraint IDs that are combined into this icon QString idString; @@ -3299,12 +3296,6 @@ void ViewProviderSketch::drawMergedConstraintIcons(IconQueue iconQueue) idString.append(QString::fromLatin1(",")); idString.append(QString::number(i->constraintId)); - if((avPos - i->position).length() < closest) { - thisDest = i->destination; - thisInfo = i->infoPtr; - closest = (avPos - i->position).length(); - } - i = iconQueue.erase(i); while(i != iconQueue.end()) { if(i->type != thisType) { @@ -3312,12 +3303,6 @@ void ViewProviderSketch::drawMergedConstraintIcons(IconQueue iconQueue) continue; } - if((avPos - i->position).length() < closest) { - thisDest = i->destination; - thisInfo = i->infoPtr; - closest = (avPos - i->position).length(); - } - labels.append(i->label); ids.push_back(i->constraintId); labelColors.append(constrColor(i->constraintId)); diff --git a/src/Mod/TechDraw/Gui/QGIViewPart.cpp b/src/Mod/TechDraw/Gui/QGIViewPart.cpp index 26e7535d536a..de3afe61518c 100644 --- a/src/Mod/TechDraw/Gui/QGIViewPart.cpp +++ b/src/Mod/TechDraw/Gui/QGIViewPart.cpp @@ -717,9 +717,12 @@ QGIFace* QGIViewPart::drawFace(TechDraw::Face* f, int idx) std::vector fWires = f->wires; QPainterPath facePath; for(std::vector::iterator wire = fWires.begin(); wire != fWires.end(); ++wire) { - QPainterPath wirePath; std::vector geoms = (*wire)->geoms; + if (geoms.empty()) + continue; + TechDraw::BaseGeom* firstGeom = geoms.front(); + QPainterPath wirePath; //QPointF startPoint(firstGeom->getStartPoint().x, firstGeom->getStartPoint().y); //wirePath.moveTo(startPoint); QPainterPath firstSeg = drawPainterPath(firstGeom); diff --git a/src/Tools/generateTemplates/templateClassPyExport.py b/src/Tools/generateTemplates/templateClassPyExport.py index aaea98c77128..bc7f60749a77 100644 --- a/src/Tools/generateTemplates/templateClassPyExport.py +++ b/src/Tools/generateTemplates/templateClassPyExport.py @@ -279,6 +279,11 @@ class @self.export.Namespace.replace("::","_")@Export @self.export.Name@ : publi #include #include +#if defined(__clang__) +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wdeprecated-declarations" +#endif + using Base::streq; using namespace @self.export.Namespace@; @@ -366,8 +371,12 @@ class @self.export.Namespace.replace("::","_")@Export @self.export.Name@ : publi #if PY_MAJOR_VERSION >= 3 ,0 /*tp_finalize */ #endif -#if PY_VERSION_HEX >= 0x03080000 +#if PY_VERSION_HEX >= 0x03090000 + ,0 /*tp_vectorcall */ +#elif PY_VERSION_HEX >= 0x03080000 ,0 /*tp_vectorcall */ + /* bpo-37250: kept for backwards compatibility in CPython 3.8 only */ + ,0 /*tp_print */ #endif }; @@ -888,6 +897,10 @@ class @self.export.Namespace.replace("::","_")@Export @self.export.Name@ : publi return static_cast<@self.export.TwinPointer@ *>(_pcTwinPointer); } +#if defined(__clang__) +# pragma clang diagnostic pop +#endif + #if 0 /* From here on come the methods you have to implement, but NOT in this module. Implement in @self.export.Name@Imp.cpp! This prototypes * are just for convenience when you add a new method.