From ebd7da397fa253a7d9054504fcb3a9c155d462c0 Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Tue, 29 Dec 2020 22:51:35 -0600 Subject: [PATCH 01/55] update macos build doc to include using homebrew to build freecad from source --- BUILD_OSX.md | 266 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 265 insertions(+), 1 deletion(-) diff --git a/BUILD_OSX.md b/BUILD_OSX.md index f3a5aea919..0ebbcc8b1c 100644 --- a/BUILD_OSX.md +++ b/BUILD_OSX.md @@ -1,5 +1,27 @@ +# Contents + + + +- [Building FreeCAD on Mac OS 10.15.x -- Catalina](#build-freecad-macos-catalina) +- [Directions](#directions) + - [Install Xcode Command line tools](#install-xcode-cli-tools) + - [Install Conda](#install-conda) + - [Run the shell script](#run-the-shell-script) +- [Building FreeCAD on macOS using homebrew packages with & without formual file](#homebrew-build-fc-on-macos) +- [Requirements](#homebrew-requirements) + - [Install required FreeCAD dependencies](#homebrew-install-required-deps) +- [Limitations of using freecad formula file](#homebrew-limits-of-formula-file) +- [Directions, Installing FreeCAD using brew packages without formula file](#homebrew-install-no-form-file) + - [Expanded Directions](#homebrew-expanded-directions) + - [Boost v1.75 fix](#homebrew-boost-175-fix) +- [Errors, Issues, & Possible Solutions](#errors-issues-solutions) + + + # Building FreeCAD on Mac OS 10.15.x -- Catalina # + + General notes on how the tooling works: This setup uses [conda](https://docs.conda.io) for dependency management. @@ -15,18 +37,26 @@ that architecture. All of this, and some sanity checks, are in a unified shell script. See below. -# Directions # +# Directions + + ## Install XCode Command line tools ## + + Run `xcode-select --install` and click through. ## Install Conda ## + + Refer to [MiniConda Docs](https://docs.conda.io/en/latest/miniconda.html). ## Run the shell script ## + + Run the `./build_unix_dev_conda.sh` and go get coffee. Builds take an hour+ on a 2012 Retina MacBook. @@ -36,3 +66,237 @@ Output binaries will be in the `./build/bin/FreeCAD` *and* You can code/build/test using the cmake configuration folder `./build` in the standard way *from within the freecad_dev conda environment*. +--- + +# Building ⚙️ FreeCAD on macOS ⌘ using homebrew 🍺 with & without a formula file + + + +> The below procedure provides on alternative way to install FreeCAD from the git source on macOS without having to use conda, but rather rely on [**mac homebrew**][lnk1] to manage dependencies. + +## Requirements + + + +- macOS, running high sierra _10.13_ or later +- mac homebrew installed and working +- all required dependencies to build FreeCAD installed using `brew install` + +There is an official [**homebrew tap**][lnk2] that provides a list of formula along with freecad to setup all the dependencies to build FreeCAD from source on macOS, and also provides prebuilt bottles to install FreeCAD from a package rather than building from source. + +> 💡 The below steps will build a FreeCAD binary that will launch FreeCAD from a command line interface, and will **NOT** build the **FreeCAD.app** bundle, ie. a double clickable app icon that can be launched from a Finder window. + +### Install required FreeCAD dependencies + + + +- setup homebrew to use the official [**freecad-homebrew**][lnk2] tap. + +```shell +brew tap FreeCAD/freecad +``` + +- install FreeCAD dependencies provided by the tap + +```shell +brew install --only-dependencies freecad +``` + +> the above step will install FreeCAD dependencies provided by the tap, and if a _bottle_ is provided by the tap homebrew will install the bottled version of the dep rather than building from source, unless the `install` command explicitly uses a _flag_ to build from source. + +After all the dependencies have been installed, it should be possible to install freecad from the provided bottle. + +```shell +brew install freecad/freecad/freecad +``` + +> As of writing this, there are bottles provided for macOS Catalina and Big Sur +> > if running a different version of macOS then building freecad from source will be required. + +To explicitly build freecad from source using the formula file provided by the tap + +```shell +brew install freecad/freecad/freecad --build-from-source --HEAD --verbose +``` + +The above command will grab the latest git source of FreeCAD and output the build process to the terminal. + +> ⏲ On my MacBookPro 2013 late model it takes ~ 60 minutes to build FreeCAD from source. + +After the _make_ and _make install_ process completes it should be possible to launch FreeCAD from any directory using a terminal with the below commands, + +```shell +FreeCAD +FreeCADCmd +``` + +- `FreeCAD` will launch a GUI version of FreeCAD +- `FreeCADCmd` will launch **only** a command line version of FreeCAD + +## Limitations of using the freecad formula file + + + +If freecad is installed via the bottle then one will have to wait for a new bottle to be generated to install a later version of freecad. However, if freecad is built from source, then FreeCAD will have all the updates up to the time the build process was started. + +When installing FreeCAD from source using the formula file provided by brew each subsequent build will require a complete rebuild of FreeCAD thus requiring an additional 60 minutes to build (my Macbook), and if any of the dependencies FreeCAD relies on is updated then more than likely FreeCAD will require a rebuild. mac homebrew does provide a feature to pin packages at specific versions to prevent them from updating, and also allows setting of an environment variable to prevent homebrew from automatically checking of updates (which can slow things down). All that said, FreeCAD can be built using all the dependencies provided by mac homebrew, but not using the formula file but rather cloning the source to an arbitrary path on a local file system providing a couple of advantages + +- if `brew cleanup` is ran, and FreeCAD was installed using the above provided command then all the source tarballs or bottles that were _checked out_ or downloaded during the install process will be delete from the system, and thus if a reinstall or upgrade is required then homebrew will have to refetch the bottles, or reclone the git source again. +- mac homebrew does provide a method, _install flag_ for keeping the source regardless if the build succeeds or fails, thus allowing to navigate to the git clone of FreeCAD source however the options are limited IMHO, and performing a standard `git clone` outside of homebrew is **much** preferred. +- cloning the FreeCAD source allows passing **any** cmake flags not provided by the formula file + - allowing to use other build systems such as _ninja_ + - allowing the use of alternate compilers, ie. _ccache_ + - pulling in subsequent updates are quicker because the `git clone` of the FreeCAD source will remain on the local filesystem even if a `brew cleanup` is ran + - subsequent recompiles should not take 60 minutes if using a cachining strategy such as _ccache_. + +## Directions, Installing FreeCAD using brew packages without a formula file + + + +> ⚠️ the below directions assume macOS high sierra or later is being used, homebrew is setup properly and all dependencies have successfully been installed. + +**TL;DR** + +- clone the FreeCAD source, pass cmake args/flags within source dir, run make, and make install, then profit 💰 + +### Expanded Directions + + + +- clone the FreeCAD source from GitHub + +```shell +git clone https://github.com/freecad/freecad +cd ./freecad +git fetch --unshallow +``` + +> The above _fetch_ cmd will take some time to fetch the commit history for the repo, but if a shallow clone is performed then FreeCAD will not show to correct build number in the About dialog [**learn more**][lnk3] + +I used the below cmake flags to build FreeCAD from a clone, and I'd recommend building FreeCAD in a specific _build branch_ rather than the master branch to not pollute the master branch with build artifacts. Also I'd prefer using clang provided by mac homebrew rather than Xcode, and if possible, I'd prefer using ccache provided by homebrew over using homebrew clang to speed rebuilds when required. + +Set the path / environment variables for specifying the compilers to use + +``` +export CC="/usr/local/opt/llvm/bin/clang" +export CXX="/usr/local/opt/llvm/bin/clang++" +``` + +- linking the brew provided install of python 3 will be required, in order for cmake to find the proper python, and python libraries. + +```shell +brew link python@3.9 +``` + +#### Boost v1.75 fix + + + +- due to recent changes in boost ie. v1.75, building FreeCAD will fail with the below linking error message, for a more exhaustive error message, [**learn more**][lnk4] + +To work around the linking issue until the [**PR**][lnk5] is merged install boost will the patches applied within the PR. + +```shell +ld: library not found for -licudata +``` + +```shell +git checkout -b mybuild + +cmake \ +-DCMAKE_C_FLAGS_RELEASE=-DNDEBUG \ +-DCMAKE_CXX_FLAGS_RELEASE=-DNDEBUG \ +-DCMAKE_INSTALL_PREFIX=/opt/beta/freecad \ +-DCMAKE_INSTALL_LIBDIR=lib \ +-DCMAKE_BUILD_TYPE=Release \ +-DCMAKE_FIND_FRAMEWORK=LAST +-DCMAKE_VERBOSE_MAKEFILE=ON \ +-Wno-dev \ +-DCMAKE_OSX_SYSROOT=/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk \ +-std=c++14 \ +-DCMAKE_CXX_STANDARD=14 \ +-DBUILD_ENABLE_CXX_STD:STRING=C++14 \ +-Wno-deprecated-declarations \ +-DBUILD_QT5=ON \ +-DUSE_PYTHON3=1 -DPYTHON_EXECUTABLE=/usr/local/bin/python3 \ +-DBUILD_FEM_NETGEN=1 \ +-DBUILD_FEM=1 \ +-DBUILD_TECHDRAW=0 \ +-DFREECAD_USE_EXTERNAL_KDL=ON \ +-DFREECAD_CREATE_MAC_APP=OFF +-DCMAKE_PREFIX_PATH="/usr/local/opt/qt/lib/cmake;/usr/local/opt/nglib/Contents/Resources;/usr/local/opt/vtk@8.2/lib/cmake;/usr/local;" . +``` + +After the configuration completes run the below commands to start the build & install process + +```shell +make +make install +``` + +> The above cmake build flags are the ones I've had good luck with, but that's not to say other ones can be added or removed. And for reasons unknown to me the above build process takes ~ twice along than using `brew install --build-from-source` + +If everything goes well FreeCAD should be able to launch from a terminal + +## Errors and Issues + possible solutions + + + +While going through the process of getting FreeCAD to compile on macOS using brew with a formula file and without a formula file I ran into several issues along the way, and I'll document them here in case anyone else is run into such error and may have a frame of reference why such error happens. All that said, I **can not** list every possible eror that could arrise, but hopefully these can help guide will troubleshooting a problematic build. + +--- + +
+error: no member named + +```shell +[ 18%] Building CXX object src/Gui/CMakeFiles/FreeCADGui.dir/DlgProjectInformationImp.cpp.o +cd /opt/code/github/public/forks/freecad/build/src/Gui && /usr/local/bin/ccache /usr/local/opt/llvm/bin/clang++ -DBOOST_ALL_NO_LIB -DBOOST_FILESYSTEM_DYN_LINK -DBOOST_PP_VARIADICS=1 -DBOOST_PROGRAM_OPTIONS_DYN_LINK -DBOOST_REGEX_DYN_LINK -DBOOST_SYSTEM_DYN_LINK -DBOOST_THREAD_DYN_LINK -DBUILD_ADDONMGR -DCMAKE_BUILD_TYPE=\"Release\" -DFreeCADGui_EXPORTS -DGL_SILENCE_DEPRECATION -DHAVE_CONFIG_H -DHAVE_FREEIMAGE -DHAVE_PYSIDE2 -DHAVE_RAPIDJSON -DHAVE_SHIBOKEN2 -DHAVE_TBB -DNDEBUG -DOCC_CONVERT_SIGNALS -DPYSIDE_QML_SUPPORT=1 -DQT_CORE_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_NO_DEBUG -DQT_OPENGL_LIB -DQT_PRINTSUPPORT_LIB -DQT_SVG_LIB -DQT_UITOOLS_LIB -DQT_WIDGETS_LIB -DQT_XML_LIB -D_OCC64 -I/opt/code/github/public/forks/freecad/build -I/opt/code/github/public/forks/freecad/build/src -I/opt/code/github/public/forks/freecad/src -I/opt/code/github/public/forks/freecad/src/Gui -I/opt/code/github/public/forks/freecad/src/Gui/Quarter -I/opt/code/github/public/forks/freecad/build/src/Gui -I/opt/code/github/public/forks/freecad/src/Gui/.. -I/opt/code/github/public/forks/freecad/build/src/Gui/.. -I/opt/code/github/public/forks/freecad/build/src/Gui/Language -I/opt/code/github/public/forks/freecad/build/src/Gui/propertyeditor -I/opt/code/github/public/forks/freecad/build/src/Gui/TaskView -I/opt/code/github/public/forks/freecad/build/src/Gui/Quarter -I/opt/code/github/public/forks/freecad/build/src/Gui/DAGView -I/usr/local/include/eigen3 -I/usr/local/include/PySide2/QtCore -I/usr/local/include/PySide2/QtGui -I/usr/local/include/PySide2/QtWidgets -isystem /usr/local/include -isystem /usr/local/Frameworks/Python.framework/Versions/3.9/include/python3.9 -iframework /usr/local/opt/qt/lib -isystem /usr/local/opt/qt/lib/QtCore.framework/Headers -isystem /usr/local/opt/qt/./mkspecs/macx-clang -isystem /usr/local/opt/qt/lib/QtWidgets.framework/Headers -isystem /usr/local/opt/qt/lib/QtGui.framework/Headers -isystem /Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/OpenGL.framework/Headers -isystem /usr/local/opt/qt/lib/QtOpenGL.framework/Headers -isystem /usr/local/opt/qt/lib/QtPrintSupport.framework/Headers -isystem /usr/local/opt/qt/lib/QtSvg.framework/Headers -isystem /usr/local/opt/qt/lib/QtNetwork.framework/Headers -isystem /usr/local/opt/qt/include -isystem /usr/local/opt/qt/include/QtUiTools -isystem /usr/local/include/shiboken2 -isystem /usr/local/include/PySide2 -isystem /usr/local/opt/qt/lib/QtXml.framework/Headers -Wall -Wextra -Wpedantic -Wno-write-strings -Wno-undefined-var-template -DNDEBUG -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk -fPIC -I/usr/local/Cellar/open-mpi/4.0.5/include -fPIC -std=gnu++14 -o CMakeFiles/FreeCADGui.dir/DlgProjectInformationImp.cpp.o -c /opt/code/github/public/forks/freecad/src/Gui/DlgProjectInformationImp.cpp +/opt/code/github/public/forks/freecad/src/Gui/DlgProjectInformationImp.cpp:56:9: error: no member named 'lineEditProgramVersion' in 'Gui::Dialog::Ui_DlgProjectInformation' + ui->lineEditProgramVersion->setText(QString::fromUtf8(doc->getProgramVersion())); + ~~ ^ +1 error generated. +make[2]: *** [src/Gui/CMakeFiles/FreeCADGui.dir/DlgProjectInformationImp.cpp.o] Error 1 +make[1]: *** [src/Gui/CMakeFiles/FreeCADGui.dir/all] Error 2 +make: *** [all] Error 2 +``` + +
+ +FreeCAD will fail to build if creating a build directory within the _src_ directory and running `cmake ..` within the newly created _build_ directory. As it currently stands, `cmake` needs run within the _src_ directory or the below error message will more than likely appear durning the build process. + +--- + +
+ ⚠️ warning: specified path differs in case from file name on disk + +``` +/opt/code/github/public/forks/FreeCAD/src/Gui/moc_DlgParameterFind.cpp:10:10: warning: non-portable path to file '"../../../FreeCAD/src/Gui/DlgParameterFind.h"'; specified path differs in case from file name on disk [-Wnonportable-include-path] +#include "../../../freecad/src/Gui/DlgParameterFind.h" + ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + "../../../FreeCAD/src/Gui/DlgParameterFind.h" +1 warning generated. +``` + +
+ +On macOS most if not all filesystems are case **insensitive** whereas most GNU+Linux distros use _case sensitive_ file systems. So if freecad source is cloned within a `FreeCAD` directory the build process on macOS will look for a `freecad` that is _case sensitive_ however the file system isn't case sensitive, thus the compiler will provide the above warning message. + +One way to resolve such error message is to rename `FreeCAD` to `freecad` + +```shell +mv FreeCAD freecadd; +mv freecadd freecad; +``` + +--- + +The text within this document is by no means exhaustive and aiming to cover every edge but does aim to serve as a decent starting point for setting up macOS to build FreeCAD from source. + + + +[lnk1]: +[lnk2]: +[lnk3]: +[lnk4]: +[lnk5]: From 2fd7625a9e1e3adbe2e7cc999d0311182c6f5e78 Mon Sep 17 00:00:00 2001 From: Syres916 <46537884+Syres916@users.noreply.github.com> Date: Sat, 1 May 2021 11:58:46 +0100 Subject: [PATCH 02/55] [Gui] Preferences - Selection Fix Bug for new... ... users who save an unrelated Preference such as Stylesheet from loosing the default selection settings. See discussion : https://forum.freecadweb.org/viewtopic.php?f=3&t=58215 --- src/Gui/DlgSettingsSelection.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/Gui/DlgSettingsSelection.cpp b/src/Gui/DlgSettingsSelection.cpp index aff8d341d2..9c52d37d90 100644 --- a/src/Gui/DlgSettingsSelection.cpp +++ b/src/Gui/DlgSettingsSelection.cpp @@ -58,6 +58,29 @@ void DlgSettingsSelection::saveSettings() void DlgSettingsSelection::loadSettings() { auto handle = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/TreeView"); + + // Stop new users loosing a number of default settings when changing an unrelated Preference Setting + bool treePreSelectionFalse = handle->GetBool("PreSelection", false); + bool treePreSelectionTrue = handle->GetBool("PreSelection", true); + bool treeRecordSelectionFalse = handle->GetBool("RecordSelection", false); + bool treeRecordSelectionTrue = handle->GetBool("RecordSelection", true); + bool treeSyncSelectionFalse = handle->GetBool("SyncSelection", false); + bool treeSyncSelectionTrue = handle->GetBool("SyncSelection", true); + bool treeSyncViewFalse = handle->GetBool("SyncView", false); + bool treeSyncViewTrue = handle->GetBool("SyncView", true); + if (treePreSelectionFalse != treePreSelectionTrue) { + handle->SetBool("PreSelection", true); + } + if (treeRecordSelectionFalse != treeRecordSelectionTrue) { + handle->SetBool("RecordSelection", true); + } + if (treeSyncSelectionFalse != treeSyncSelectionTrue) { + handle->SetBool("SyncSelection", true); + } + if (treeSyncViewFalse != treeSyncViewTrue) { + handle->SetBool("SyncView", true); + } + ui->checkBoxAutoSwitch->setChecked(handle->GetBool("SyncView")); ui->checkBoxAutoExpand->setChecked(handle->GetBool("SyncSelection")); ui->checkBoxPreselect->setChecked(handle->GetBool("PreSelection")); From 61b04b9969aba3643cb59d264c2cdfba2f454fd4 Mon Sep 17 00:00:00 2001 From: Syres916 <46537884+Syres916@users.noreply.github.com> Date: Sun, 2 May 2021 12:04:03 +0100 Subject: [PATCH 03/55] Changes as per @Chennes advice --- src/Gui/DlgSettingsSelection.cpp | 31 ++++--------------------------- 1 file changed, 4 insertions(+), 27 deletions(-) diff --git a/src/Gui/DlgSettingsSelection.cpp b/src/Gui/DlgSettingsSelection.cpp index 9c52d37d90..7ac6ddc2a2 100644 --- a/src/Gui/DlgSettingsSelection.cpp +++ b/src/Gui/DlgSettingsSelection.cpp @@ -58,33 +58,10 @@ void DlgSettingsSelection::saveSettings() void DlgSettingsSelection::loadSettings() { auto handle = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/TreeView"); - - // Stop new users loosing a number of default settings when changing an unrelated Preference Setting - bool treePreSelectionFalse = handle->GetBool("PreSelection", false); - bool treePreSelectionTrue = handle->GetBool("PreSelection", true); - bool treeRecordSelectionFalse = handle->GetBool("RecordSelection", false); - bool treeRecordSelectionTrue = handle->GetBool("RecordSelection", true); - bool treeSyncSelectionFalse = handle->GetBool("SyncSelection", false); - bool treeSyncSelectionTrue = handle->GetBool("SyncSelection", true); - bool treeSyncViewFalse = handle->GetBool("SyncView", false); - bool treeSyncViewTrue = handle->GetBool("SyncView", true); - if (treePreSelectionFalse != treePreSelectionTrue) { - handle->SetBool("PreSelection", true); - } - if (treeRecordSelectionFalse != treeRecordSelectionTrue) { - handle->SetBool("RecordSelection", true); - } - if (treeSyncSelectionFalse != treeSyncSelectionTrue) { - handle->SetBool("SyncSelection", true); - } - if (treeSyncViewFalse != treeSyncViewTrue) { - handle->SetBool("SyncView", true); - } - - ui->checkBoxAutoSwitch->setChecked(handle->GetBool("SyncView")); - ui->checkBoxAutoExpand->setChecked(handle->GetBool("SyncSelection")); - ui->checkBoxPreselect->setChecked(handle->GetBool("PreSelection")); - ui->checkBoxRecord->setChecked(handle->GetBool("RecordSelection")); + ui->checkBoxAutoSwitch->setChecked(handle->GetBool("SyncView", true)); + ui->checkBoxAutoExpand->setChecked(handle->GetBool("SyncSelection", true)); + ui->checkBoxPreselect->setChecked(handle->GetBool("PreSelection", true)); + ui->checkBoxRecord->setChecked(handle->GetBool("RecordSelection", true)); ui->checkBoxSelectionCheckBoxes->setChecked(handle->GetBool("CheckBoxesSelection")); } From ce678a2d4ddf1de227ca0ab4d738a2b6bbeae651 Mon Sep 17 00:00:00 2001 From: Heewa Barfchin Date: Wed, 12 May 2021 21:55:04 -0400 Subject: [PATCH 04/55] Fix lost filename in err msg In some circumstances, FileExceptions are constructed empty, then have a filename assigned to them, but the error message in these scenarios is left as the default "unknown" one, which is sometimes shown to users. This change fixes that case to be consistent with instances that are constructed with the filename. --- src/Base/Exception.cpp | 19 ++++++++++++------- src/Base/Exception.h | 1 + 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/Base/Exception.cpp b/src/Base/Exception.cpp index 1efd8c0110..8f8cfc74cf 100644 --- a/src/Base/Exception.cpp +++ b/src/Base/Exception.cpp @@ -248,17 +248,13 @@ const char* XMLAttributeError::what() const throw() FileException::FileException(const char * sMessage, const char * sFileName) : Exception( sMessage ),file(sFileName) { - if (sFileName) { - _sErrMsgAndFileName = _sErrMsg + ": "; - _sErrMsgAndFileName += sFileName; - } + setFileName(sFileName); } FileException::FileException(const char * sMessage, const FileInfo& File) : Exception( sMessage ),file(File) { - _sErrMsgAndFileName = _sErrMsg + ": "; - _sErrMsgAndFileName += File.fileName(); + setFileName(File.fileName().c_str()); } FileException::FileException() @@ -274,6 +270,15 @@ FileException::FileException(const FileException &inst) { } +void FileException::setFileName(const char * sFileName) { + file.setFile(sFileName); + _sErrMsgAndFileName = _sErrMsg; + if (sFileName) { + _sErrMsgAndFileName += ": "; + _sErrMsgAndFileName += sFileName; + } +} + std::string FileException::getFileName() const { return file.fileName(); @@ -324,7 +329,7 @@ void FileException::setPyObject( PyObject * pydict) Py::Dict edict(pydict); if (edict.hasKey("filename")) - file.setFile(static_cast(Py::String(edict.getItem("filename")))); + setFileName(Py::String(edict.getItem("filename")).as_std_string("utf-8").c_str()); } } diff --git a/src/Base/Exception.h b/src/Base/Exception.h index 7fd38ce75a..0aff3c9e1f 100644 --- a/src/Base/Exception.h +++ b/src/Base/Exception.h @@ -262,6 +262,7 @@ protected: // necessary for what() legacy behaviour as it returns a buffer that // can not be of a temporary object to be destroyed at end of what() std::string _sErrMsgAndFileName; + void setFileName(const char * sFileName=0); }; /** From 5a2e40c3f519ae138c6331499687c7f80321dff7 Mon Sep 17 00:00:00 2001 From: Heewa Barfchin Date: Wed, 12 May 2021 22:07:44 -0400 Subject: [PATCH 05/55] Fix app quitting after failed save. Fixes #4098 Return `false` from Document::save() to properly communicate the failure, which the app-quit process already handles by aborting. --- src/Gui/Document.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Gui/Document.cpp b/src/Gui/Document.cpp index 16c4fa5836..534a02c951 100644 --- a/src/Gui/Document.cpp +++ b/src/Gui/Document.cpp @@ -1161,6 +1161,7 @@ bool Document::save(void) catch (const Base::Exception& e) { QMessageBox::critical(getMainWindow(), QObject::tr("Saving document failed"), QString::fromLatin1(e.what())); + return false; } return true; } From 5beedc6efda2b800911706c78281e5a340c0af25 Mon Sep 17 00:00:00 2001 From: Heewa Barfchin Date: Wed, 12 May 2021 22:16:45 -0400 Subject: [PATCH 06/55] App: Abort save when unable to finish In these two cases, the project's file will not contain the latest changes, so returning as if the save is complete is incorrect and can lead to data loss (such as on app quit). --- src/App/Document.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/App/Document.cpp b/src/App/Document.cpp index bcbf6b3849..3b0ff5982f 100644 --- a/src/App/Document.cpp +++ b/src/App/Document.cpp @@ -2398,8 +2398,8 @@ private: Base::FileInfo tmp(sourcename); if (tmp.renameFile(targetname.c_str()) == false) { - Base::Console().Warning("Cannot rename file from '%s' to '%s'\n", - sourcename.c_str(), targetname.c_str()); + throw Base::FileException( + "Cannot rename tmp save file to project file", targetname); } } void applyTimeStamp(const std::string& sourcename, const std::string& targetname) { @@ -2531,9 +2531,8 @@ private: Base::FileInfo tmp(sourcename); if (tmp.renameFile(targetname.c_str()) == false) { - Base::Console().Error("Save interrupted: Cannot rename file from '%s' to '%s'\n", - sourcename.c_str(), targetname.c_str()); - //throw Base::FileException("Save interrupted: Cannot rename temporary file to project file", tmp); + throw Base::FileException( + "Save interrupted: Cannot rename temporary file to project file", tmp); } if (numberOfFiles <= 0) { From cdbf7acc80eb4c559f6259202138cbecc53fc3fb Mon Sep 17 00:00:00 2001 From: 0penBrain <48731257+0penBrain@users.noreply.github.com> Date: Sun, 12 Sep 2021 19:45:28 +0200 Subject: [PATCH 07/55] [Core] Rotation : fix gimbal lock handling + fix Euler representation on GUI --- src/Base/Rotation.cpp | 4 ++-- src/Gui/Placement.ui | 18 +++++++++--------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Base/Rotation.cpp b/src/Base/Rotation.cpp index ec15219388..118a7c6563 100644 --- a/src/Base/Rotation.cpp +++ b/src/Base/Rotation.cpp @@ -673,13 +673,13 @@ void Rotation::getYawPitchRoll(double& y, double& p, double& r) const double qd2 = 2.0*(q13-q02); // handle gimbal lock - if (fabs(qd2-1.0) < DBL_EPSILON) { + if (fabs(qd2-1.0) <= DBL_EPSILON) { // north pole y = 0.0; p = D_PI/2.0; r = 2.0 * atan2(quat[0],quat[3]); } - else if (fabs(qd2+1.0) < DBL_EPSILON) { + else if (fabs(qd2+1.0) <= DBL_EPSILON) { // south pole y = 0.0; p = -D_PI/2.0; diff --git a/src/Gui/Placement.ui b/src/Gui/Placement.ui index 844efe6d0a..a8fc09cedd 100644 --- a/src/Gui/Placement.ui +++ b/src/Gui/Placement.ui @@ -347,7 +347,7 @@ - Around y-axis: + Pitch (around y-axis): @@ -360,7 +360,7 @@ - Around z-axis: + Roll (around x-axis): @@ -373,28 +373,28 @@ - Around x-axis: + Yaw (around z-axis): - + - Rotation around the x-axis + Yaw (around z-axis) - Rotation around the y-axis + Pitch (around y-axis) - + - Rotation around the z-axis + Roll (around the x-axis) @@ -414,7 +414,7 @@ - Euler angles (xy'z'') + Euler angles (zy'x'') From a40d37a980e24a86b69a941b2f996f5eb781fefc Mon Sep 17 00:00:00 2001 From: wmayer Date: Tue, 14 Sep 2021 16:40:30 +0200 Subject: [PATCH 08/55] Base: split export/import macros from FCConfig.h and move them to FCGlobal.h The FCGlobal.h can be included in a Global.h header file of an extension module. The reason is that some IDEs (e.g. QtCreator) fails to detect the export/import macros when only defined in the PreCompiled.h files and thus raise a parser warning. --- src/App/Range.h | 3 + src/Base/Builder3D.h | 3 + src/Base/Debugger.h | 3 + src/Base/Factory.h | 12 ++-- src/Base/FileTemplate.h | 3 + src/Base/Handle.h | 3 + src/Base/InputSource.h | 3 + src/Base/Matrix.h | 5 +- src/Base/MemDebug.h | 38 +++++++----- src/Base/PyTools.h | 3 + src/Base/Rotation.h | 3 + src/Base/StackWalker.h | 5 +- src/Base/Tools.h | 3 + src/Base/Tools2D.h | 5 +- src/Base/Translate.h | 3 + src/Base/Type.h | 3 + src/Base/Uuid.h | 3 + src/FCConfig.h | 34 +--------- src/FCGlobal.h | 62 +++++++++++++++++++ src/Mod/Image/App/ImageBase.h | 2 + src/Mod/Image/App/ImagePlane.h | 1 + src/Mod/Image/Gui/ImageView.h | 1 + src/Mod/Image/Gui/ViewProviderImagePlane.h | 13 ++-- src/Mod/Image/Gui/Workbench.h | 1 + src/Mod/Image/ImageGlobal.h | 32 ++++++++++ src/Mod/Mesh/App/Core/Approximation.h | 3 + src/Mod/Mesh/App/Core/Definitions.h | 4 ++ src/Mod/Mesh/App/Core/Visitor.h | 4 ++ src/Mod/Mesh/App/FeatureMeshExport.h | 3 + src/Mod/Mesh/App/MeshPoint.h | 9 ++- src/Mod/Mesh/Gui/DlgSettingsImportExportImp.h | 3 + src/Mod/Mesh/Gui/DlgSettingsMeshView.h | 3 + src/Mod/Mesh/Gui/DlgSmoothing.h | 3 + src/Mod/Mesh/Gui/MeshSelection.h | 3 + src/Mod/Mesh/Gui/PropertyEditorMesh.h | 3 + src/Mod/Mesh/Gui/Segmentation.h | 3 + src/Mod/Mesh/Gui/SoFCIndexedFaceSet.h | 3 + src/Mod/Mesh/Gui/SoPolygon.h | 3 + src/Mod/Mesh/Gui/Workbench.h | 3 + src/Mod/Mesh/MeshGlobal.h | 47 ++++++++++++++ src/Mod/Points/App/Points.h | 1 + src/Mod/Points/Gui/ViewProvider.h | 1 + src/Mod/Points/Gui/Workbench.h | 1 + src/Mod/Points/PointsGlobal.h | 47 ++++++++++++++ 44 files changed, 327 insertions(+), 67 deletions(-) create mode 100644 src/FCGlobal.h create mode 100644 src/Mod/Image/ImageGlobal.h create mode 100644 src/Mod/Mesh/MeshGlobal.h create mode 100644 src/Mod/Points/PointsGlobal.h diff --git a/src/App/Range.h b/src/App/Range.h index 86872a4436..554a02057a 100644 --- a/src/App/Range.h +++ b/src/App/Range.h @@ -24,6 +24,9 @@ #define RANGE_H #include +#ifndef FC_GLOBAL_H +#include +#endif namespace App { diff --git a/src/Base/Builder3D.h b/src/Base/Builder3D.h index 239f56e5a2..927e0880d9 100644 --- a/src/Base/Builder3D.h +++ b/src/Base/Builder3D.h @@ -29,6 +29,9 @@ #include #include #include "Vector3D.h" +#ifndef FC_GLOBAL_H +#include +#endif namespace Base { diff --git a/src/Base/Debugger.h b/src/Base/Debugger.h index 114b7e38b0..503b3fba3a 100644 --- a/src/Base/Debugger.h +++ b/src/Base/Debugger.h @@ -26,6 +26,9 @@ #include #include +#ifndef FC_GLOBAL_H +#include +#endif namespace Base { /** diff --git a/src/Base/Factory.h b/src/Base/Factory.h index 06b51322cc..92699083cf 100644 --- a/src/Base/Factory.h +++ b/src/Base/Factory.h @@ -25,11 +25,13 @@ #ifndef BASE_FACTORY_H #define BASE_FACTORY_H -#include -#include -#include -#include -#include"../FCConfig.h" +#include +#include +#include +#include +#ifndef FC_GLOBAL_H +#include +#endif namespace Base diff --git a/src/Base/FileTemplate.h b/src/Base/FileTemplate.h index 42b90a19fa..c18e633f60 100644 --- a/src/Base/FileTemplate.h +++ b/src/Base/FileTemplate.h @@ -27,6 +27,9 @@ // Std. configurations #include +#ifndef FC_GLOBAL_H +#include +#endif namespace Base { diff --git a/src/Base/Handle.h b/src/Base/Handle.h index 539704ca43..7ca41f4466 100644 --- a/src/Base/Handle.h +++ b/src/Base/Handle.h @@ -30,6 +30,9 @@ #include #include #include +#ifndef FC_GLOBAL_H +#include +#endif class QAtomicInt; diff --git a/src/Base/InputSource.h b/src/Base/InputSource.h index 8178a130fe..856c5fd849 100644 --- a/src/Base/InputSource.h +++ b/src/Base/InputSource.h @@ -32,6 +32,9 @@ #include #include #include +#ifndef FC_GLOBAL_H +#include +#endif XERCES_CPP_NAMESPACE_BEGIN diff --git a/src/Base/Matrix.h b/src/Base/Matrix.h index dd2bbe2e13..f87b626b05 100644 --- a/src/Base/Matrix.h +++ b/src/Base/Matrix.h @@ -25,12 +25,15 @@ #define BASE_MATRIX_H #include +#include #include #include #include #include "Vector3D.h" -#include +#ifndef FC_GLOBAL_H +#include +#endif namespace Base { diff --git a/src/Base/MemDebug.h b/src/Base/MemDebug.h index 1b3d980f5a..4ef8ce5f43 100644 --- a/src/Base/MemDebug.h +++ b/src/Base/MemDebug.h @@ -22,30 +22,34 @@ #ifndef BASE_MEMDEBUG_H #define BASE_MEMDEBUG_H +#ifndef FC_GLOBAL_H +#include +#include +#endif namespace Base { - + // Std. configurations -#if defined(_MSC_VER) -class BaseExport MemCheck -{ -public: - MemCheck(); - ~MemCheck(); - - void setNextCheckpoint(); - static bool checkMemory(); - static bool dumpLeaks(); - static bool isValidHeapPointer(const void*); - -private: - _CrtMemState s1, s2, s3; -}; +#if defined(_MSC_VER) +class BaseExport MemCheck +{ +public: + MemCheck(); + ~MemCheck(); + + void setNextCheckpoint(); + static bool checkMemory(); + static bool dumpLeaks(); + static bool isValidHeapPointer(const void*); + +private: + _CrtMemState s1, s2, s3; +}; #endif - + } //namespace Base #endif // BASE_MEMDEBUG_H diff --git a/src/Base/PyTools.h b/src/Base/PyTools.h index bc1d4c43bc..13a7c0774c 100644 --- a/src/Base/PyTools.h +++ b/src/Base/PyTools.h @@ -73,6 +73,9 @@ extern "C" { /* a C library, but callable from C++ */ # undef _POSIX_C_SOURCE #endif // (re-)defined in pyconfig.h #include +#ifndef FC_GLOBAL_H +#include +#endif extern int PP_RELOAD; /* 1=reload py modules when attributes referenced */ extern int PP_DEBUG; /* 1=start debugger when string/function/member run */ diff --git a/src/Base/Rotation.h b/src/Base/Rotation.h index cb45dd0c19..aaf0c23307 100644 --- a/src/Base/Rotation.h +++ b/src/Base/Rotation.h @@ -25,6 +25,9 @@ #define BASE_ROTATION_H #include "Vector3D.h" +#ifndef FC_GLOBAL_H +#include +#endif namespace Base { diff --git a/src/Base/StackWalker.h b/src/Base/StackWalker.h index 788c818223..6e80971dc5 100644 --- a/src/Base/StackWalker.h +++ b/src/Base/StackWalker.h @@ -36,7 +36,10 @@ // so we need not to check the version (because we only support _MSC_VER >= 1100)! #pragma once -#include +#include +#ifndef FC_GLOBAL_H +#include +#endif // special defines for VC5/6 (if no actual PSDK is installed): #if _MSC_VER < 1300 diff --git a/src/Base/Tools.h b/src/Base/Tools.h index 6cac42a96b..be28e62183 100644 --- a/src/Base/Tools.h +++ b/src/Base/Tools.h @@ -24,6 +24,9 @@ #ifndef BASE_TOOLS_H #define BASE_TOOLS_H +#ifndef FC_GLOBAL_H +#include +#endif #include #include #include diff --git a/src/Base/Tools2D.h b/src/Base/Tools2D.h index cb228d10fe..7656557a70 100644 --- a/src/Base/Tools2D.h +++ b/src/Base/Tools2D.h @@ -28,11 +28,14 @@ #include #include #include -#include +#include #include #include #include "Vector3D.h" +#ifndef FC_GLOBAL_H +#include +#endif namespace Base { diff --git a/src/Base/Translate.h b/src/Base/Translate.h index c77a7b28c0..1b75a2fe26 100644 --- a/src/Base/Translate.h +++ b/src/Base/Translate.h @@ -26,6 +26,9 @@ #include #include +#ifndef FC_GLOBAL_H +#include +#endif namespace Base { diff --git a/src/Base/Type.h b/src/Base/Type.h index 866cdd3694..f77390cf56 100644 --- a/src/Base/Type.h +++ b/src/Base/Type.h @@ -30,6 +30,9 @@ #include #include #include +#ifndef FC_GLOBAL_H +#include +#endif namespace Base { diff --git a/src/Base/Uuid.h b/src/Base/Uuid.h index e8b8c01729..93e7d1986e 100644 --- a/src/Base/Uuid.h +++ b/src/Base/Uuid.h @@ -27,6 +27,9 @@ // Std. configurations #include +#ifndef FC_GLOBAL_H +#include +#endif namespace Base { diff --git a/src/FCConfig.h b/src/FCConfig.h index aeb476b061..a9addc0321 100644 --- a/src/FCConfig.h +++ b/src/FCConfig.h @@ -304,39 +304,7 @@ typedef unsigned __int64 uint64_t; //************************************************************************** // Windows import export DLL defines -#if defined (FC_OS_WIN32) || defined(FC_OS_CYGWIN) -# ifdef FCApp -# define AppExport __declspec(dllexport) -# define DataExport __declspec(dllexport) -# else -# define AppExport __declspec(dllimport) -# define DataExport __declspec(dllimport) -# endif -# ifdef FCBase -# define BaseExport __declspec(dllexport) -# else -# define BaseExport __declspec(dllimport) -# endif -# ifdef FCGui -# define GuiExport __declspec(dllexport) -# else -# define GuiExport __declspec(dllimport) -# endif -#else -# ifndef BaseExport -# define BaseExport -# endif -# ifndef GuiExport -# define GuiExport -# endif -# ifndef AppExport -# define AppExport -# endif -# ifndef DataExport -# define DataExport -# endif -#endif - +#include //************************************************************************** // here get the warnings of too long specifiers disabled (needed for VC6) diff --git a/src/FCGlobal.h b/src/FCGlobal.h new file mode 100644 index 0000000000..6e0e5ccf54 --- /dev/null +++ b/src/FCGlobal.h @@ -0,0 +1,62 @@ +/*************************************************************************** + * Copyright (c) 2019 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 * + * * + ***************************************************************************/ +/** \file FCGlobal.h + * \brief Include export or import macros. + */ + + +#ifndef FC_GLOBAL_H +#define FC_GLOBAL_H + + +#if defined(WIN64) || defined(_WIN64) || defined(__WIN64__) || defined(__CYGWIN__) +# define FREECAD_DECL_EXPORT __declspec(dllexport) +# define FREECAD_DECL_IMPORT __declspec(dllimport) +#else +# define FREECAD_DECL_EXPORT +# define FREECAD_DECL_IMPORT +#endif + +// FreeCADBase +#ifdef FreeCADBase_EXPORTS +# define BaseExport FREECAD_DECL_EXPORT +#else +# define BaseExport FREECAD_DECL_IMPORT +#endif + +// FreeCADApp +#ifdef FreeCADApp_EXPORTS +# define AppExport FREECAD_DECL_EXPORT +# define DataExport FREECAD_DECL_EXPORT +#else +# define AppExport FREECAD_DECL_IMPORT +# define DataExport FREECAD_DECL_IMPORT +#endif + +// FreeCADGui +#ifdef FreeCADGui_EXPORTS +# define GuiExport FREECAD_DECL_EXPORT +#else +# define GuiExport FREECAD_DECL_IMPORT +#endif + +#endif //FC_GLOBAL_H diff --git a/src/Mod/Image/App/ImageBase.h b/src/Mod/Image/App/ImageBase.h index 144699c717..bb013316be 100644 --- a/src/Mod/Image/App/ImageBase.h +++ b/src/Mod/Image/App/ImageBase.h @@ -18,6 +18,8 @@ #ifndef IMAGEBASE_H #define IMAGEBASE_H +#include + namespace Image { diff --git a/src/Mod/Image/App/ImagePlane.h b/src/Mod/Image/App/ImagePlane.h index a2633e155d..22a462f840 100644 --- a/src/Mod/Image/App/ImagePlane.h +++ b/src/Mod/Image/App/ImagePlane.h @@ -27,6 +27,7 @@ #include #include #include +#include namespace Image { diff --git a/src/Mod/Image/Gui/ImageView.h b/src/Mod/Image/Gui/ImageView.h index c66ef7c847..7bc34f8e21 100644 --- a/src/Mod/Image/Gui/ImageView.h +++ b/src/Mod/Image/Gui/ImageView.h @@ -25,6 +25,7 @@ #else #include "GLImageBox.h" #endif +#include class QSlider; class QAction; diff --git a/src/Mod/Image/Gui/ViewProviderImagePlane.h b/src/Mod/Image/Gui/ViewProviderImagePlane.h index d676fe8096..c4e3bba7f6 100644 --- a/src/Mod/Image/Gui/ViewProviderImagePlane.h +++ b/src/Mod/Image/Gui/ViewProviderImagePlane.h @@ -25,6 +25,7 @@ #define IMAGE_ViewProviderImagePlane_H #include +#include class SoCoordinate3; class SoDrawStyle; @@ -48,12 +49,12 @@ public: void attach(App::DocumentObject *pcObject); void setDisplayMode(const char* ModeName); std::vector getDisplayModes() const; - void updateData(const App::Property*); - -private: - bool loadSvg(const char*, float x, float y, QImage& img); - -protected: + void updateData(const App::Property*); + +private: + bool loadSvg(const char*, float x, float y, QImage& img); + +protected: SoCoordinate3 * pcCoords; SoTexture2 * texture; }; diff --git a/src/Mod/Image/Gui/Workbench.h b/src/Mod/Image/Gui/Workbench.h index d8533ff3ac..16f8eb2dde 100644 --- a/src/Mod/Image/Gui/Workbench.h +++ b/src/Mod/Image/Gui/Workbench.h @@ -25,6 +25,7 @@ #define IMAGE_WORKBENCH_H #include +#include namespace ImageGui { diff --git a/src/Mod/Image/ImageGlobal.h b/src/Mod/Image/ImageGlobal.h new file mode 100644 index 0000000000..26cca10062 --- /dev/null +++ b/src/Mod/Image/ImageGlobal.h @@ -0,0 +1,32 @@ +/*************************************************************************** + * Copyright (c) Imetric 4D Imaging Sarl * + * * + * Author: Werner Mayer * + * * + ***************************************************************************/ + +#include + +#ifndef IMAGE_GLOBAL_H +#define IMAGE_GLOBAL_H + + +// Image +#ifndef ImageExport +#ifdef Image_EXPORTS +# define ImageExport FREECAD_DECL_EXPORT +#else +# define ImageExport FREECAD_DECL_IMPORT +#endif +#endif + +// ImageGui +#ifndef ImageGuiExport +#ifdef ImageGui_EXPORTS +# define ImageGuiExport FREECAD_DECL_EXPORT +#else +# define ImageGuiExport FREECAD_DECL_IMPORT +#endif +#endif + +#endif //IMAGE_GLOBAL_H diff --git a/src/Mod/Mesh/App/Core/Approximation.h b/src/Mod/Mesh/App/Core/Approximation.h index db61724d3c..cd71e568fb 100644 --- a/src/Mod/Mesh/App/Core/Approximation.h +++ b/src/Mod/Mesh/App/Core/Approximation.h @@ -28,6 +28,9 @@ #include #include #include +#ifndef MESH_GLOBAL_H +#include +#endif #include #include #include diff --git a/src/Mod/Mesh/App/Core/Definitions.h b/src/Mod/Mesh/App/Core/Definitions.h index 454ffb6081..0aadd101db 100644 --- a/src/Mod/Mesh/App/Core/Definitions.h +++ b/src/Mod/Mesh/App/Core/Definitions.h @@ -24,6 +24,10 @@ #ifndef MESH_DEFINITIONS_H #define MESH_DEFINITIONS_H +#ifndef MESH_GLOBAL_H +#include +#endif + // default values #define MESH_MIN_PT_DIST 1.0e-6f #define MESH_MIN_EDGE_LEN 1.0e-3f diff --git a/src/Mod/Mesh/App/Core/Visitor.h b/src/Mod/Mesh/App/Core/Visitor.h index 52594dad98..bac568451e 100644 --- a/src/Mod/Mesh/App/Core/Visitor.h +++ b/src/Mod/Mesh/App/Core/Visitor.h @@ -24,6 +24,10 @@ #ifndef VISITOR_H #define VISITOR_H +#ifndef MESH_GLOBAL_H +#include +#endif + namespace MeshCore { class MeshFacet; diff --git a/src/Mod/Mesh/App/FeatureMeshExport.h b/src/Mod/Mesh/App/FeatureMeshExport.h index fcb380a6af..0c5bf479c3 100644 --- a/src/Mod/Mesh/App/FeatureMeshExport.h +++ b/src/Mod/Mesh/App/FeatureMeshExport.h @@ -27,6 +27,9 @@ #include #include #include +#ifndef MESH_GLOBAL_H +#include +#endif namespace Mesh { diff --git a/src/Mod/Mesh/App/MeshPoint.h b/src/Mod/Mesh/App/MeshPoint.h index c06e4c30a5..beaf2f6017 100644 --- a/src/Mod/Mesh/App/MeshPoint.h +++ b/src/Mod/Mesh/App/MeshPoint.h @@ -24,10 +24,13 @@ #ifndef MESH_MESHPOINT_H #define MESH_MESHPOINT_H +#include #include #include - -#include "Mesh.h" +#include +#ifndef MESH_GLOBAL_H +#include +#endif using Base::Vector3d; @@ -59,4 +62,4 @@ public: } // namespace Mesh -#endif // MESH_MESH_H +#endif // MESH_MESHPOINT_H diff --git a/src/Mod/Mesh/Gui/DlgSettingsImportExportImp.h b/src/Mod/Mesh/Gui/DlgSettingsImportExportImp.h index 9939ec7bcc..68b5f8e99c 100644 --- a/src/Mod/Mesh/Gui/DlgSettingsImportExportImp.h +++ b/src/Mod/Mesh/Gui/DlgSettingsImportExportImp.h @@ -24,6 +24,9 @@ #ifndef MESHGUI_DLGSETTINGSIMPORTEXPORTIMP_H #define MESHGUI_DLGSETTINGSIMPORTEXPORTIMP_H +#ifndef MESH_GLOBAL_H +#include +#endif #include namespace MeshGui { diff --git a/src/Mod/Mesh/Gui/DlgSettingsMeshView.h b/src/Mod/Mesh/Gui/DlgSettingsMeshView.h index 4157d10ab6..2e567094a2 100644 --- a/src/Mod/Mesh/Gui/DlgSettingsMeshView.h +++ b/src/Mod/Mesh/Gui/DlgSettingsMeshView.h @@ -24,6 +24,9 @@ #ifndef MESHGUI_DLGSETTINGSMESHVIEW_H #define MESHGUI_DLGSETTINGSMESHVIEW_H +#ifndef MESH_GLOBAL_H +#include +#endif #include #include diff --git a/src/Mod/Mesh/Gui/DlgSmoothing.h b/src/Mod/Mesh/Gui/DlgSmoothing.h index 49b8047cad..05e37c08bf 100644 --- a/src/Mod/Mesh/Gui/DlgSmoothing.h +++ b/src/Mod/Mesh/Gui/DlgSmoothing.h @@ -27,6 +27,9 @@ #include #include #include +#ifndef MESH_GLOBAL_H +#include +#endif class QButtonGroup; diff --git a/src/Mod/Mesh/Gui/MeshSelection.h b/src/Mod/Mesh/Gui/MeshSelection.h index 53bcef99b7..f3af6c48b5 100644 --- a/src/Mod/Mesh/Gui/MeshSelection.h +++ b/src/Mod/Mesh/Gui/MeshSelection.h @@ -30,6 +30,9 @@ #include #include #include +#ifndef MESH_GLOBAL_H +#include +#endif namespace Gui { class View3DInventorViewer; diff --git a/src/Mod/Mesh/Gui/PropertyEditorMesh.h b/src/Mod/Mesh/Gui/PropertyEditorMesh.h index f8311fdf6f..c08228a580 100644 --- a/src/Mod/Mesh/Gui/PropertyEditorMesh.h +++ b/src/Mod/Mesh/Gui/PropertyEditorMesh.h @@ -24,6 +24,9 @@ #define MESHGUI_PROPERTYEDITOR_MESH_H #include +#ifndef MESH_GLOBAL_H +#include +#endif namespace MeshGui { diff --git a/src/Mod/Mesh/Gui/Segmentation.h b/src/Mod/Mesh/Gui/Segmentation.h index fd9755ffe8..17a1d32f61 100644 --- a/src/Mod/Mesh/Gui/Segmentation.h +++ b/src/Mod/Mesh/Gui/Segmentation.h @@ -27,6 +27,9 @@ #include #include #include +#ifndef MESH_GLOBAL_H +#include +#endif // forward declarations namespace Mesh { class Feature; } diff --git a/src/Mod/Mesh/Gui/SoFCIndexedFaceSet.h b/src/Mod/Mesh/Gui/SoFCIndexedFaceSet.h index 2f85b74d18..cbd54ef8b4 100644 --- a/src/Mod/Mesh/Gui/SoFCIndexedFaceSet.h +++ b/src/Mod/Mesh/Gui/SoFCIndexedFaceSet.h @@ -28,6 +28,9 @@ #include #include #include +#ifndef MESH_GLOBAL_H +#include +#endif class SoGLCoordinateElement; class SoTextureCoordinateBundle; diff --git a/src/Mod/Mesh/Gui/SoPolygon.h b/src/Mod/Mesh/Gui/SoPolygon.h index df418c200a..265d17242a 100644 --- a/src/Mod/Mesh/Gui/SoPolygon.h +++ b/src/Mod/Mesh/Gui/SoPolygon.h @@ -30,6 +30,9 @@ #include #include #include +#ifndef MESH_GLOBAL_H +#include +#endif namespace MeshGui { diff --git a/src/Mod/Mesh/Gui/Workbench.h b/src/Mod/Mesh/Gui/Workbench.h index fba985f949..ce10c46dc3 100644 --- a/src/Mod/Mesh/Gui/Workbench.h +++ b/src/Mod/Mesh/Gui/Workbench.h @@ -24,6 +24,9 @@ #ifndef MESH_WORKBENCH_H #define MESH_WORKBENCH_H +#ifndef MESH_GLOBAL_H +#include +#endif #include namespace MeshGui { diff --git a/src/Mod/Mesh/MeshGlobal.h b/src/Mod/Mesh/MeshGlobal.h new file mode 100644 index 0000000000..bf8d4d3589 --- /dev/null +++ b/src/Mod/Mesh/MeshGlobal.h @@ -0,0 +1,47 @@ +/*************************************************************************** + * Copyright (c) 2019 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 + +#ifndef MESH_GLOBAL_H +#define MESH_GLOBAL_H + + +// Mesh +#ifndef MeshExport +#ifdef Mesh_EXPORTS +# define MeshExport FREECAD_DECL_EXPORT +#else +# define MeshExport FREECAD_DECL_IMPORT +#endif +#endif + +// MeshGui +#ifndef MeshGuiExport +#ifdef MeshGui_EXPORTS +# define MeshGuiExport FREECAD_DECL_EXPORT +#else +# define MeshGuiExport FREECAD_DECL_IMPORT +#endif +#endif + +#endif //MESH_GLOBAL_H diff --git a/src/Mod/Points/App/Points.h b/src/Mod/Points/App/Points.h index 643e3ea99e..67fa6e57a8 100644 --- a/src/Mod/Points/App/Points.h +++ b/src/Mod/Points/App/Points.h @@ -34,6 +34,7 @@ #include #include +#include namespace Points { diff --git a/src/Mod/Points/Gui/ViewProvider.h b/src/Mod/Points/Gui/ViewProvider.h index 926fa7f900..47cc7f7e78 100644 --- a/src/Mod/Points/Gui/ViewProvider.h +++ b/src/Mod/Points/Gui/ViewProvider.h @@ -28,6 +28,7 @@ #include #include #include +#include class SoSwitch; diff --git a/src/Mod/Points/Gui/Workbench.h b/src/Mod/Points/Gui/Workbench.h index ebb4c6dbde..99753fc1c3 100644 --- a/src/Mod/Points/Gui/Workbench.h +++ b/src/Mod/Points/Gui/Workbench.h @@ -25,6 +25,7 @@ #define POINTS_WORKBENCH_H #include +#include namespace PointsGui { diff --git a/src/Mod/Points/PointsGlobal.h b/src/Mod/Points/PointsGlobal.h new file mode 100644 index 0000000000..5ba83d6b96 --- /dev/null +++ b/src/Mod/Points/PointsGlobal.h @@ -0,0 +1,47 @@ +/*************************************************************************** + * Copyright (c) 2019 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 + +#ifndef POINTS_GLOBAL_H +#define POINTS_GLOBAL_H + + +// Points +#ifndef PointsExport +#ifdef Points_EXPORTS +# define PointsExport FREECAD_DECL_EXPORT +#else +# define PointsExport FREECAD_DECL_IMPORT +#endif +#endif + +// PointsGui +#ifndef PointsGuiExport +#ifdef PointsGui_EXPORTS +# define PointsGuiExport FREECAD_DECL_EXPORT +#else +# define PointsGuiExport FREECAD_DECL_IMPORT +#endif +#endif + +#endif //POINTS_GLOBAL_H From ba2341de33bfd9238bba8c883866935c3e73283a Mon Sep 17 00:00:00 2001 From: wmayer Date: Tue, 14 Sep 2021 16:42:30 +0200 Subject: [PATCH 09/55] Gui: fix compiler warnings: [-Wunused-parameter] --- src/Gui/MouseSelection.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Gui/MouseSelection.cpp b/src/Gui/MouseSelection.cpp index 0551d15951..a143685b14 100644 --- a/src/Gui/MouseSelection.cpp +++ b/src/Gui/MouseSelection.cpp @@ -280,6 +280,8 @@ void PolyPickerSelection::initialize() void PolyPickerSelection::terminate(bool abort) { + Q_UNUSED(abort) + _pcView3D->removeGraphicsItem(&polyline); _pcView3D->setRenderType(View3DInventorViewer::Native); _pcView3D->redraw(); @@ -673,6 +675,8 @@ void RubberbandSelection::initialize() void RubberbandSelection::terminate(bool abort) { + Q_UNUSED(abort) + _pcView3D->removeGraphicsItem(&rubberband); if (QtGLFramebufferObject::hasOpenGLFramebufferObjects()) { _pcView3D->setRenderType(View3DInventorViewer::Native); From eb88ebafaf8751cd7e8dfcdea3bebdb11f7aa006 Mon Sep 17 00:00:00 2001 From: mwganson Date: Tue, 14 Sep 2021 15:15:59 -0500 Subject: [PATCH 10/55] [Spreadsheet] Prevent infinite loop when copy/paste of non-rectangular selection --- src/Mod/Spreadsheet/App/PropertySheet.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Mod/Spreadsheet/App/PropertySheet.cpp b/src/Mod/Spreadsheet/App/PropertySheet.cpp index 7ae24ec849..c4798e74d1 100644 --- a/src/Mod/Spreadsheet/App/PropertySheet.cpp +++ b/src/Mod/Spreadsheet/App/PropertySheet.cpp @@ -391,14 +391,16 @@ void PropertySheet::pasteCells(XMLReader &reader, const CellAddress &addr) { roffset = addr.row() - from.row(); coffset = addr.col() - from.col(); }else - range.next(); + if (!range.next()) + break; while(src!=*range) { CellAddress dst(*range); dst.setRow(dst.row()+roffset); dst.setCol(dst.col()+coffset); owner->clear(dst); owner->cellUpdated(dst); - range.next(); + if (!range.next()) + break; } CellAddress dst(src.row()+roffset, src.col()+coffset); auto cell = owner->getNewCell(dst); From 9ce79bf3c768385ee47929c8a10fd76ee93c66b3 Mon Sep 17 00:00:00 2001 From: wmayer Date: Tue, 14 Sep 2021 22:57:17 +0200 Subject: [PATCH 11/55] Mod: fix warning [-Wmacro-redefined] --- src/Mod/Draft/App/PreCompiled.h | 2 -- src/Mod/Fem/App/PreCompiled.h | 2 -- src/Mod/Path/App/PreCompiled.h | 2 -- src/Mod/ReverseEngineering/Gui/PreCompiled.h | 2 -- src/Mod/Robot/App/PreCompiled.h | 2 -- 5 files changed, 10 deletions(-) diff --git a/src/Mod/Draft/App/PreCompiled.h b/src/Mod/Draft/App/PreCompiled.h index 8c8e0b33cd..0922240f4d 100644 --- a/src/Mod/Draft/App/PreCompiled.h +++ b/src/Mod/Draft/App/PreCompiled.h @@ -30,11 +30,9 @@ #ifdef FC_OS_WIN32 # define DraftUtilsExport __declspec(dllexport) # define PartExport __declspec(dllexport) -# define BaseExport __declspec(dllimport) #else // for Linux # define DraftUtilsExport # define PartExport -# define BaseExport #endif #ifdef _MSC_VER diff --git a/src/Mod/Fem/App/PreCompiled.h b/src/Mod/Fem/App/PreCompiled.h index 089be95ec2..4e4752d380 100644 --- a/src/Mod/Fem/App/PreCompiled.h +++ b/src/Mod/Fem/App/PreCompiled.h @@ -32,13 +32,11 @@ # define FemExport __declspec(dllexport) # define PartExport __declspec(dllimport) # define MeshExport __declspec(dllimport) -# define BaseExport __declspec(dllimport) #else // for Linux # define AppFemExport # define FemExport # define PartExport # define MeshExport -# define BaseExport #endif #ifdef _MSC_VER diff --git a/src/Mod/Path/App/PreCompiled.h b/src/Mod/Path/App/PreCompiled.h index d5a77f42f2..7a787a15ab 100644 --- a/src/Mod/Path/App/PreCompiled.h +++ b/src/Mod/Path/App/PreCompiled.h @@ -31,12 +31,10 @@ # define PathExport __declspec(dllexport) //# define RobotExport __declspec(dllexport) uncomment this to use KDL # define PartExport __declspec(dllimport) -# define BaseExport __declspec(dllimport) #else // for Linux # define PathExport //# define RobotExport uncomment this to use KDL # define PartExport -# define BaseExport #endif #ifdef _PreComp_ diff --git a/src/Mod/ReverseEngineering/Gui/PreCompiled.h b/src/Mod/ReverseEngineering/Gui/PreCompiled.h index 313b942286..fcd2cb3fe1 100644 --- a/src/Mod/ReverseEngineering/Gui/PreCompiled.h +++ b/src/Mod/ReverseEngineering/Gui/PreCompiled.h @@ -34,7 +34,6 @@ # define MeshExport __declspec(dllimport) # define MeshGuiExport __declspec(dllimport) # define PointsExport __declspec(dllimport) -# define AppExport __declspec(dllimport) #else // for Linux # define ReenExport # define ReenGuiExport @@ -42,7 +41,6 @@ # define MeshExport # define MeshGuiExport # define PointsExport -# define AppExport #endif #ifdef _MSC_VER diff --git a/src/Mod/Robot/App/PreCompiled.h b/src/Mod/Robot/App/PreCompiled.h index 30daa1dc9e..773769ffc0 100644 --- a/src/Mod/Robot/App/PreCompiled.h +++ b/src/Mod/Robot/App/PreCompiled.h @@ -31,12 +31,10 @@ # define RobotExport __declspec(dllexport) # define PartExport __declspec(dllimport) # define MeshExport __declspec(dllimport) -# define BaseExport __declspec(dllimport) #else // for Linux # define RobotExport # define PartExport # define MeshExport -# define BaseExport #endif #ifdef _PreComp_ From 2295c4b9a38d8fdda69c1169675b04e1df54a09e Mon Sep 17 00:00:00 2001 From: wmayer Date: Tue, 14 Sep 2021 23:01:29 +0200 Subject: [PATCH 12/55] Mesh: define the typenames FacetIndex and PointIndex to distinguish between facet and point related indexes --- src/Mod/Mesh/App/Core/Algorithm.cpp | 494 +++++++---------- src/Mod/Mesh/App/Core/Algorithm.h | 168 +++--- src/Mod/Mesh/App/Core/Approximation.cpp | 6 +- src/Mod/Mesh/App/Core/Approximation.h | 4 +- src/Mod/Mesh/App/Core/Builder.cpp | 18 +- src/Mod/Mesh/App/Core/Builder.h | 10 +- src/Mod/Mesh/App/Core/Curvature.cpp | 22 +- src/Mod/Mesh/App/Core/Curvature.h | 7 +- src/Mod/Mesh/App/Core/Definitions.cpp | 2 +- src/Mod/Mesh/App/Core/Definitions.h | 14 +- src/Mod/Mesh/App/Core/Degeneration.cpp | 280 ++++------ src/Mod/Mesh/App/Core/Degeneration.h | 42 +- src/Mod/Mesh/App/Core/Elements.cpp | 30 +- src/Mod/Mesh/App/Core/Elements.h | 160 +++--- src/Mod/Mesh/App/Core/Evaluation.cpp | 149 +++--- src/Mod/Mesh/App/Core/Evaluation.h | 66 +-- src/Mod/Mesh/App/Core/Grid.cpp | 76 +-- src/Mod/Mesh/App/Core/Grid.h | 116 ++-- src/Mod/Mesh/App/Core/Helpers.h | 69 +-- src/Mod/Mesh/App/Core/Info.cpp | 16 +- src/Mod/Mesh/App/Core/Info.h | 4 +- src/Mod/Mesh/App/Core/Iterator.h | 100 ++-- src/Mod/Mesh/App/Core/KDTree.cpp | 36 +- src/Mod/Mesh/App/Core/KDTree.h | 8 +- src/Mod/Mesh/App/Core/MeshIO.cpp | 25 +- src/Mod/Mesh/App/Core/MeshIO.h | 2 +- src/Mod/Mesh/App/Core/MeshKernel.cpp | 202 ++++--- src/Mod/Mesh/App/Core/MeshKernel.h | 98 ++-- src/Mod/Mesh/App/Core/Projection.cpp | 9 +- src/Mod/Mesh/App/Core/Projection.h | 5 +- src/Mod/Mesh/App/Core/Segmentation.cpp | 34 +- src/Mod/Mesh/App/Core/Segmentation.h | 24 +- src/Mod/Mesh/App/Core/SetOperations.cpp | 32 +- src/Mod/Mesh/App/Core/SetOperations.h | 16 +- src/Mod/Mesh/App/Core/Smoothing.cpp | 38 +- src/Mod/Mesh/App/Core/Smoothing.h | 11 +- src/Mod/Mesh/App/Core/Tools.cpp | 50 +- src/Mod/Mesh/App/Core/Tools.h | 29 +- src/Mod/Mesh/App/Core/TopoAlgorithm.cpp | 498 +++++++++--------- src/Mod/Mesh/App/Core/TopoAlgorithm.h | 82 +-- src/Mod/Mesh/App/Core/Triangulation.cpp | 44 +- src/Mod/Mesh/App/Core/Triangulation.h | 10 +- src/Mod/Mesh/App/Core/Trim.cpp | 34 +- src/Mod/Mesh/App/Core/Trim.h | 14 +- src/Mod/Mesh/App/Core/TrimByPlane.cpp | 6 +- src/Mod/Mesh/App/Core/TrimByPlane.h | 4 +- src/Mod/Mesh/App/Core/Visitor.cpp | 44 +- src/Mod/Mesh/App/Core/Visitor.h | 36 +- src/Mod/Mesh/App/Exporter.cpp | 8 +- src/Mod/Mesh/App/Facet.cpp | 4 +- src/Mod/Mesh/App/Facet.h | 10 +- src/Mod/Mesh/App/FacetPyImp.cpp | 42 +- src/Mod/Mesh/App/FeatureMeshSegmentByMesh.cpp | 22 +- src/Mod/Mesh/App/FeatureMeshSegmentByMesh.h | 2 +- src/Mod/Mesh/App/Mesh.cpp | 206 ++++---- src/Mod/Mesh/App/Mesh.h | 90 ++-- src/Mod/Mesh/App/MeshProperties.cpp | 4 +- src/Mod/Mesh/App/MeshProperties.h | 2 +- src/Mod/Mesh/App/MeshPyImp.cpp | 36 +- src/Mod/Mesh/App/MeshTexture.cpp | 22 +- src/Mod/Mesh/App/MeshTexture.h | 2 +- src/Mod/Mesh/App/Segment.cpp | 18 +- src/Mod/Mesh/App/Segment.h | 15 +- src/Mod/Mesh/App/Types.h | 40 ++ src/Mod/Mesh/Gui/Command.cpp | 2 +- src/Mod/Mesh/Gui/DlgEvaluateMeshImp.cpp | 30 +- src/Mod/Mesh/Gui/DlgEvaluateMeshImp.h | 3 +- src/Mod/Mesh/Gui/DlgSmoothing.cpp | 6 +- src/Mod/Mesh/Gui/MeshEditor.cpp | 34 +- src/Mod/Mesh/Gui/MeshEditor.h | 14 +- src/Mod/Mesh/Gui/MeshSelection.cpp | 40 +- src/Mod/Mesh/Gui/SegmentationBestFit.cpp | 2 +- src/Mod/Mesh/Gui/SoFCMeshObject.cpp | 32 +- src/Mod/Mesh/Gui/ViewProvider.cpp | 122 ++--- src/Mod/Mesh/Gui/ViewProvider.h | 32 +- src/Mod/Mesh/Gui/ViewProviderCurvature.cpp | 2 +- src/Mod/Mesh/Gui/ViewProviderDefects.cpp | 76 +-- src/Mod/Mesh/Gui/ViewProviderDefects.h | 20 +- src/Mod/Mesh/Gui/ViewProviderMeshFaceSet.cpp | 6 +- src/Mod/Mesh/Gui/ViewProviderMeshPyImp.cpp | 12 +- .../Gui/ViewProviderTransformDemolding.cpp | 2 +- src/Mod/MeshPart/App/AppMeshPartPy.cpp | 2 +- src/Mod/MeshPart/App/CurveProjector.cpp | 66 +-- src/Mod/MeshPart/App/CurveProjector.h | 8 +- src/Mod/MeshPart/App/MeshAlgos.cpp | 6 +- src/Mod/MeshPart/App/Mesher.cpp | 6 +- src/Mod/MeshPart/Gui/CurveOnMesh.cpp | 2 +- .../App/SurfaceTriangulation.cpp | 4 +- src/Mod/ReverseEngineering/Gui/Command.cpp | 6 +- .../ReverseEngineering/Gui/Segmentation.cpp | 4 +- .../Gui/SegmentationManual.cpp | 5 +- 91 files changed, 2057 insertions(+), 2254 deletions(-) create mode 100644 src/Mod/Mesh/App/Types.h diff --git a/src/Mod/Mesh/App/Core/Algorithm.cpp b/src/Mod/Mesh/App/Core/Algorithm.cpp index bc58c6e6cf..d18cbb229e 100644 --- a/src/Mod/Mesh/App/Core/Algorithm.cpp +++ b/src/Mod/Mesh/App/Core/Algorithm.cpp @@ -47,7 +47,8 @@ bool MeshAlgorithm::IsVertexVisible (const Base::Vector3f &rcVertex, const Base: { Base::Vector3f cDirection = rcVertex - rcView; float fDistance = cDirection.Length(); - Base::Vector3f cIntsct; unsigned long uInd; + Base::Vector3f cIntsct; + FacetIndex uInd; // search for the nearest facet to rcView in direction to rcVertex if (NearestFacetOnRay(rcView, cDirection, /*1.2f*fDistance,*/ rclGrid, cIntsct, uInd)) { @@ -66,11 +67,11 @@ bool MeshAlgorithm::IsVertexVisible (const Base::Vector3f &rcVertex, const Base: } bool MeshAlgorithm::NearestFacetOnRay (const Base::Vector3f &rclPt, const Base::Vector3f &rclDir, Base::Vector3f &rclRes, - unsigned long &rulFacet) const + FacetIndex &rulFacet) const { Base::Vector3f clProj, clRes; bool bSol = false; - unsigned long ulInd = 0; + FacetIndex ulInd = 0; // langsame Ausfuehrung ohne Grid MeshFacetIterator clFIter(_rclMesh); @@ -99,9 +100,9 @@ bool MeshAlgorithm::NearestFacetOnRay (const Base::Vector3f &rclPt, const Base:: } bool MeshAlgorithm::NearestFacetOnRay (const Base::Vector3f &rclPt, const Base::Vector3f &rclDir, const MeshFacetGrid &rclGrid, - Base::Vector3f &rclRes, unsigned long &rulFacet) const + Base::Vector3f &rclRes, FacetIndex &rulFacet) const { - std::vector aulFacets; + std::vector aulFacets; MeshGridIterator clGridIter(rclGrid); if (clGridIter.InitOnRay(rclPt, rclDir, aulFacets) == true) { @@ -120,9 +121,9 @@ bool MeshAlgorithm::NearestFacetOnRay (const Base::Vector3f &rclPt, const Base:: } bool MeshAlgorithm::NearestFacetOnRay (const Base::Vector3f &rclPt, const Base::Vector3f &rclDir, float fMaxSearchArea, - const MeshFacetGrid &rclGrid, Base::Vector3f &rclRes, unsigned long &rulFacet) const + const MeshFacetGrid &rclGrid, Base::Vector3f &rclRes, FacetIndex &rulFacet) const { - std::vector aulFacets; + std::vector aulFacets; MeshGridIterator clGridIter(rclGrid); if (clGridIter.InitOnRay(rclPt, rclDir, fMaxSearchArea, aulFacets) == true) { @@ -140,14 +141,14 @@ bool MeshAlgorithm::NearestFacetOnRay (const Base::Vector3f &rclPt, const Base:: return false; } -bool MeshAlgorithm::NearestFacetOnRay (const Base::Vector3f &rclPt, const Base::Vector3f &rclDir, const std::vector &raulFacets, - Base::Vector3f &rclRes, unsigned long &rulFacet) const +bool MeshAlgorithm::NearestFacetOnRay (const Base::Vector3f &rclPt, const Base::Vector3f &rclDir, const std::vector &raulFacets, + Base::Vector3f &rclRes, FacetIndex &rulFacet) const { Base::Vector3f clProj, clRes; bool bSol = false; - unsigned long ulInd = 0; + FacetIndex ulInd = 0; - for (std::vector::const_iterator pI = raulFacets.begin(); pI != raulFacets.end(); ++pI) { + for (std::vector::const_iterator pI = raulFacets.begin(); pI != raulFacets.end(); ++pI) { MeshGeomFacet rclSFacet = _rclMesh.GetFacet(*pI); if (rclSFacet.Foraminate(rclPt, rclDir, clRes) == true) { if (bSol == false) {// erste Loesung @@ -172,14 +173,14 @@ bool MeshAlgorithm::NearestFacetOnRay (const Base::Vector3f &rclPt, const Base:: return bSol; } -bool MeshAlgorithm::RayNearestField (const Base::Vector3f &rclPt, const Base::Vector3f &rclDir, const std::vector &raulFacets, - Base::Vector3f &rclRes, unsigned long &rulFacet, float /*fMaxAngle*/) const +bool MeshAlgorithm::RayNearestField (const Base::Vector3f &rclPt, const Base::Vector3f &rclDir, const std::vector &raulFacets, + Base::Vector3f &rclRes, FacetIndex &rulFacet, float /*fMaxAngle*/) const { Base::Vector3f clProj, clRes; bool bSol = false; - unsigned long ulInd = 0; + FacetIndex ulInd = 0; - for (std::vector::const_iterator pF = raulFacets.begin(); pF != raulFacets.end(); ++pF) { + for (std::vector::const_iterator pF = raulFacets.begin(); pF != raulFacets.end(); ++pF) { if (_rclMesh.GetFacet(*pF).Foraminate(rclPt, rclDir, clRes/*, fMaxAngle*/) == true) { if (bSol == false) { // erste Loesung bSol = true; @@ -203,18 +204,18 @@ bool MeshAlgorithm::RayNearestField (const Base::Vector3f &rclPt, const Base::Ve return bSol; } -bool MeshAlgorithm::FirstFacetToVertex(const Base::Vector3f &rPt, float fMaxDistance, const MeshFacetGrid &rGrid, unsigned long &uIndex) const +bool MeshAlgorithm::FirstFacetToVertex(const Base::Vector3f &rPt, float fMaxDistance, const MeshFacetGrid &rGrid, FacetIndex &uIndex) const { const float fEps = 0.001f; bool found = false; - std::vector facets; + std::vector facets; // get the facets of the grid the point lies into rGrid.GetElements(rPt, facets); // Check all facets inside the grid if the point is part of it - for (std::vector::iterator it = facets.begin(); it != facets.end(); ++it) { + for (std::vector::iterator it = facets.begin(); it != facets.end(); ++it) { MeshGeomFacet cFacet = this->_rclMesh.GetFacet(*it); if (cFacet.IsPointOfFace(rPt, fMaxDistance)) { found = true; @@ -289,153 +290,60 @@ Base::Vector3f MeshAlgorithm::GetGravityPoint() const void MeshAlgorithm::GetMeshBorders (std::list > &rclBorders) const { - std::vector aulAllFacets(_rclMesh.CountFacets()); - unsigned long k = 0; - for (std::vector::iterator pI = aulAllFacets.begin(); pI != aulAllFacets.end(); ++pI) + std::vector aulAllFacets(_rclMesh.CountFacets()); + FacetIndex k = 0; + for (std::vector::iterator pI = aulAllFacets.begin(); pI != aulAllFacets.end(); ++pI) *pI = k++; GetFacetBorders(aulAllFacets, rclBorders); } -void MeshAlgorithm::GetMeshBorders (std::list > &rclBorders) const +void MeshAlgorithm::GetMeshBorders (std::list > &rclBorders) const { - std::vector aulAllFacets(_rclMesh.CountFacets()); - unsigned long k = 0; - for (std::vector::iterator pI = aulAllFacets.begin(); pI != aulAllFacets.end(); ++pI) + std::vector aulAllFacets(_rclMesh.CountFacets()); + FacetIndex k = 0; + for (std::vector::iterator pI = aulAllFacets.begin(); pI != aulAllFacets.end(); ++pI) *pI = k++; GetFacetBorders(aulAllFacets, rclBorders, true); } -void MeshAlgorithm::GetFacetBorders (const std::vector &raulInd, std::list > &rclBorders) const +void MeshAlgorithm::GetFacetBorders (const std::vector &raulInd, std::list > &rclBorders) const { -#if 1 const MeshPointArray &rclPAry = _rclMesh._aclPointArray; - std::list > aulBorders; + std::list > aulBorders; GetFacetBorders (raulInd, aulBorders, true); - for ( std::list >::iterator it = aulBorders.begin(); it != aulBorders.end(); ++it ) + for ( std::list >::iterator it = aulBorders.begin(); it != aulBorders.end(); ++it ) { std::vector boundary; boundary.reserve( it->size() ); - for ( std::vector::iterator jt = it->begin(); jt != it->end(); ++jt ) + for ( std::vector::iterator jt = it->begin(); jt != it->end(); ++jt ) boundary.push_back(rclPAry[*jt]); rclBorders.push_back( boundary ); } - -#else - const MeshFacetArray &rclFAry = _rclMesh._aclFacetArray; - - // alle Facets markieren die in der Indizie-Liste vorkommen - ResetFacetFlag(MeshFacet::VISIT); - for (std::vector::const_iterator pIter = raulInd.begin(); pIter != raulInd.end(); ++pIter) - rclFAry[*pIter].SetFlag(MeshFacet::VISIT); - - std::list > aclEdges; - // alle Randkanten suchen und ablegen (unsortiert) - for (std::vector::const_iterator pIter2 = raulInd.begin(); pIter2 != raulInd.end(); ++pIter2) - { - const MeshFacet &rclFacet = rclFAry[*pIter2]; - for (int i = 0; i < 3; i++) - { - unsigned long ulNB = rclFacet._aulNeighbours[i]; - if (ulNB != ULONG_MAX) - { - if (rclFAry[ulNB].IsFlag(MeshFacet::VISIT) == true) - continue; - } - - aclEdges.push_back(rclFacet.GetEdge(i)); - } - } - - if (aclEdges.size() == 0) - return; // no borders found (=> solid) - - // Kanten aus der unsortieren Kantenliste suchen - const MeshPointArray &rclPAry = _rclMesh._aclPointArray; - unsigned long ulFirst, ulLast; - std::list clBorder; - ulFirst = aclEdges.begin()->first; - ulLast = aclEdges.begin()->second; - - aclEdges.erase(aclEdges.begin()); - clBorder.push_back(rclPAry[ulFirst]); - clBorder.push_back(rclPAry[ulLast]); - - while (aclEdges.size() > 0) - { - // naechste anliegende Kante suchen - std::list >::iterator pEI; - for (pEI = aclEdges.begin(); pEI != aclEdges.end(); ++pEI) - { - if (pEI->first == ulLast) - { - ulLast = pEI->second; - clBorder.push_back(rclPAry[ulLast]); - aclEdges.erase(pEI); - break; - } - else if (pEI->second == ulLast) - { - ulLast = pEI->first; - clBorder.push_back(rclPAry[ulLast]); - aclEdges.erase(pEI); - break; - } - else if (pEI->first == ulFirst) - { - ulFirst = pEI->second; - clBorder.push_front(rclPAry[ulFirst]); - aclEdges.erase(pEI); - break; - } - else if (pEI->second == ulFirst) - { - ulFirst = pEI->first; - clBorder.push_front(rclPAry[ulFirst]); - aclEdges.erase(pEI); - break; - } - } - if ((pEI == aclEdges.end()) || (ulLast == ulFirst)) - { // keine weitere Kante gefunden bzw. Polylinie geschlossen - rclBorders.push_back(std::vector(clBorder.begin(), clBorder.end())); - clBorder.clear(); - - if (aclEdges.size() > 0) - { // neue Border anfangen - ulFirst = aclEdges.begin()->first; - ulLast = aclEdges.begin()->second; - aclEdges.erase(aclEdges.begin()); - clBorder.push_back(rclPAry[ulFirst]); - clBorder.push_back(rclPAry[ulLast]); - } - } - } -#endif } -void MeshAlgorithm::GetFacetBorders (const std::vector &raulInd, - std::list > &rclBorders, +void MeshAlgorithm::GetFacetBorders (const std::vector &raulInd, + std::list > &rclBorders, bool ignoreOrientation) const { const MeshFacetArray &rclFAry = _rclMesh._aclFacetArray; // mark all facets that are in the indices list ResetFacetFlag(MeshFacet::VISIT); - for (std::vector::const_iterator it = raulInd.begin(); it != raulInd.end(); ++it) + for (std::vector::const_iterator it = raulInd.begin(); it != raulInd.end(); ++it) rclFAry[*it].SetFlag(MeshFacet::VISIT); // collect all boundary edges (unsorted) - std::list > aclEdges; - for (std::vector::const_iterator it = raulInd.begin(); it != raulInd.end(); ++it) { + std::list > aclEdges; + for (std::vector::const_iterator it = raulInd.begin(); it != raulInd.end(); ++it) { const MeshFacet &rclFacet = rclFAry[*it]; for (unsigned short i = 0; i < 3; i++) { - unsigned long ulNB = rclFacet._aulNeighbours[i]; - if (ulNB != ULONG_MAX) { + FacetIndex ulNB = rclFacet._aulNeighbours[i]; + if (ulNB != FACET_INDEX_MAX) { if (rclFAry[ulNB].IsFlag(MeshFacet::VISIT) == true) continue; } @@ -448,8 +356,8 @@ void MeshAlgorithm::GetFacetBorders (const std::vector &raulInd, return; // no borders found (=> solid) // search for edges in the unsorted list - unsigned long ulFirst, ulLast; - std::list clBorder; + PointIndex ulFirst, ulLast; + std::list clBorder; ulFirst = aclEdges.begin()->first; ulLast = aclEdges.begin()->second; @@ -459,7 +367,7 @@ void MeshAlgorithm::GetFacetBorders (const std::vector &raulInd, while (aclEdges.size() > 0) { // get adjacent edge - std::list >::iterator pEI; + std::list >::iterator pEI; for (pEI = aclEdges.begin(); pEI != aclEdges.end(); ++pEI) { if (pEI->first == ulLast) { ulLast = pEI->second; @@ -513,17 +421,17 @@ void MeshAlgorithm::GetFacetBorders (const std::vector &raulInd, } } -void MeshAlgorithm::GetMeshBorder(unsigned long uFacet, std::list& rBorder) const +void MeshAlgorithm::GetMeshBorder(FacetIndex uFacet, std::list& rBorder) const { const MeshFacetArray &rFAry = _rclMesh._aclFacetArray; - std::list > openEdges; + std::list > openEdges; if (uFacet >= rFAry.size()) return; // add the open edge to the beginning of the list MeshFacetArray::_TConstIterator face = rFAry.begin() + uFacet; for (unsigned short i = 0; i < 3; i++) { - if (face->_aulNeighbours[i] == ULONG_MAX) + if (face->_aulNeighbours[i] == FACET_INDEX_MAX) openEdges.push_back(face->GetEdge(i)); } @@ -536,14 +444,14 @@ void MeshAlgorithm::GetMeshBorder(unsigned long uFacet, std::list continue; for (unsigned short i = 0; i < 3; i++) { - if (it->_aulNeighbours[i] == ULONG_MAX) + if (it->_aulNeighbours[i] == FACET_INDEX_MAX) openEdges.push_back(it->GetEdge(i)); } } // Start with the edge that is associated to uFacet - unsigned long ulFirst = openEdges.begin()->first; - unsigned long ulLast = openEdges.begin()->second; + PointIndex ulFirst = openEdges.begin()->first; + PointIndex ulLast = openEdges.begin()->second; openEdges.erase(openEdges.begin()); rBorder.push_back(ulFirst); @@ -552,7 +460,7 @@ void MeshAlgorithm::GetMeshBorder(unsigned long uFacet, std::list while (ulLast != ulFirst) { // find adjacent edge - std::list >::iterator pEI; + std::list >::iterator pEI; for (pEI = openEdges.begin(); pEI != openEdges.end(); ++pEI) { if (pEI->first == ulLast) @@ -579,14 +487,14 @@ void MeshAlgorithm::GetMeshBorder(unsigned long uFacet, std::list } } -void MeshAlgorithm::SplitBoundaryLoops( std::list >& aBorders ) +void MeshAlgorithm::SplitBoundaryLoops( std::list >& aBorders ) { // Count the number of open edges for each point - std::map openPointDegree; + std::map openPointDegree; for (MeshFacetArray::_TConstIterator jt = _rclMesh._aclFacetArray.begin(); jt != _rclMesh._aclFacetArray.end(); ++jt) { for (int i=0; i<3; i++) { - if (jt->_aulNeighbours[i] == ULONG_MAX) { + if (jt->_aulNeighbours[i] == FACET_INDEX_MAX) { openPointDegree[jt->_aulPoints[i]]++; openPointDegree[jt->_aulPoints[(i+1)%3]]++; } @@ -594,11 +502,11 @@ void MeshAlgorithm::SplitBoundaryLoops( std::list >& } // go through all boundaries and split them if needed - std::list > aSplitBorders; - for (std::list >::iterator it = aBorders.begin(); + std::list > aSplitBorders; + for (std::list >::iterator it = aBorders.begin(); it != aBorders.end(); ++it) { bool split=false; - for (std::vector::iterator jt = it->begin(); jt != it->end(); ++jt) { + for (std::vector::iterator jt = it->begin(); jt != it->end(); ++jt) { // two (or more) boundaries meet in one non-manifold point if (openPointDegree[*jt] > 2) { split = true; @@ -615,17 +523,17 @@ void MeshAlgorithm::SplitBoundaryLoops( std::list >& aBorders = aSplitBorders; } -void MeshAlgorithm::SplitBoundaryLoops(const std::vector& rBound, - std::list >& aBorders) +void MeshAlgorithm::SplitBoundaryLoops(const std::vector& rBound, + std::list >& aBorders) { - std::map aPtDegree; - std::vector cBound; - for (std::vector::const_iterator it = rBound.begin(); it != rBound.end(); ++it) { + std::map aPtDegree; + std::vector cBound; + for (std::vector::const_iterator it = rBound.begin(); it != rBound.end(); ++it) { int deg = (aPtDegree[*it]++); if (deg > 0) { - for (std::vector::iterator jt = cBound.begin(); jt != cBound.end(); ++jt) { + for (std::vector::iterator jt = cBound.begin(); jt != cBound.end(); ++jt) { if (*jt == *it) { - std::vector cBoundLoop; + std::vector cBoundLoop; cBoundLoop.insert(cBoundLoop.end(), jt, cBound.end()); cBoundLoop.push_back(*it); cBound.erase(jt, cBound.end()); @@ -640,7 +548,7 @@ void MeshAlgorithm::SplitBoundaryLoops(const std::vector& rBound, } } -bool MeshAlgorithm::FillupHole(const std::vector& boundary, +bool MeshAlgorithm::FillupHole(const std::vector& boundary, AbstractPolygonTriangulator& cTria, MeshFacetArray& rFaces, MeshPointArray& rPoints, int level, const MeshRefPointToFacets* pP2FStructure) const @@ -657,14 +565,14 @@ bool MeshAlgorithm::FillupHole(const std::vector& boundary, // Get a facet as reference coordinate system MeshGeomFacet rTriangle; MeshFacet rFace; - unsigned long refPoint0 = *(boundary.begin()); - unsigned long refPoint1 = *(boundary.begin()+1); + PointIndex refPoint0 = *(boundary.begin()); + PointIndex refPoint1 = *(boundary.begin()+1); if (pP2FStructure) { - const std::set& ring1 = (*pP2FStructure)[refPoint0]; - const std::set& ring2 = (*pP2FStructure)[refPoint1]; - std::vector f_int; + const std::set& ring1 = (*pP2FStructure)[refPoint0]; + const std::set& ring2 = (*pP2FStructure)[refPoint1]; + std::vector f_int; std::set_intersection(ring1.begin(), ring1.end(), ring2.begin(), ring2.end(), - std::back_insert_iterator >(f_int)); + std::back_insert_iterator >(f_int)); if (f_int.size() != 1) return false; // error, this must be an open edge! @@ -691,13 +599,13 @@ bool MeshAlgorithm::FillupHole(const std::vector& boundary, // add points to the polygon std::vector polygon; - for (std::vector::const_iterator jt = boundary.begin(); jt != boundary.end(); ++jt) { + for (std::vector::const_iterator jt = boundary.begin(); jt != boundary.end(); ++jt) { polygon.push_back(_rclMesh._aclPointArray[*jt]); rPoints.push_back(_rclMesh._aclPointArray[*jt]); } // remove the last added point if it is duplicated - std::vector bounds = boundary; + std::vector bounds = boundary; if (boundary.front() == boundary.back()) { bounds.pop_back(); polygon.pop_back(); @@ -712,8 +620,8 @@ bool MeshAlgorithm::FillupHole(const std::vector& boundary, std::vector surf_pts = cTria.GetPolygon(); if (pP2FStructure && level > 0) { - std::set index = pP2FStructure->NeighbourPoints(boundary, level); - for (std::set::iterator it = index.begin(); it != index.end(); ++it) { + std::set index = pP2FStructure->NeighbourPoints(boundary, level); + for (std::set::iterator it = index.begin(); it != index.end(); ++it) { Base::Vector3f pt(_rclMesh._aclPointArray[*it]); surf_pts.push_back(pt); } @@ -816,28 +724,28 @@ bool MeshAlgorithm::FillupHole(const std::vector& boundary, return false; } -void MeshAlgorithm::SetFacetsProperty(const std::vector &raulInds, const std::vector &raulProps) const +void MeshAlgorithm::SetFacetsProperty(const std::vector &raulInds, const std::vector &raulProps) const { if (raulInds.size() != raulProps.size()) return; std::vector::const_iterator iP = raulProps.begin(); - for (std::vector::const_iterator i = raulInds.begin(); i != raulInds.end(); ++i, ++iP) + for (std::vector::const_iterator i = raulInds.begin(); i != raulInds.end(); ++i, ++iP) _rclMesh._aclFacetArray[*i].SetProperty(*iP); } -void MeshAlgorithm::SetFacetsFlag (const std::vector &raulInds, MeshFacet::TFlagType tF) const +void MeshAlgorithm::SetFacetsFlag (const std::vector &raulInds, MeshFacet::TFlagType tF) const { - for (std::vector::const_iterator i = raulInds.begin(); i != raulInds.end(); ++i) + for (std::vector::const_iterator i = raulInds.begin(); i != raulInds.end(); ++i) _rclMesh._aclFacetArray[*i].SetFlag(tF); } -void MeshAlgorithm::SetPointsFlag (const std::vector &raulInds, MeshPoint::TFlagType tF) const +void MeshAlgorithm::SetPointsFlag (const std::vector &raulInds, MeshPoint::TFlagType tF) const { - for (std::vector::const_iterator i = raulInds.begin(); i != raulInds.end(); ++i) + for (std::vector::const_iterator i = raulInds.begin(); i != raulInds.end(); ++i) _rclMesh._aclPointArray[*i].SetFlag(tF); } -void MeshAlgorithm::GetFacetsFlag (std::vector &raulInds, MeshFacet::TFlagType tF) const +void MeshAlgorithm::GetFacetsFlag (std::vector &raulInds, MeshFacet::TFlagType tF) const { raulInds.reserve(raulInds.size() + CountFacetFlag(tF)); MeshFacetArray::_TConstIterator beg = _rclMesh._aclFacetArray.begin(); @@ -848,7 +756,7 @@ void MeshAlgorithm::GetFacetsFlag (std::vector &raulInds, MeshFac } } -void MeshAlgorithm::GetPointsFlag (std::vector &raulInds, MeshPoint::TFlagType tF) const +void MeshAlgorithm::GetPointsFlag (std::vector &raulInds, MeshPoint::TFlagType tF) const { raulInds.reserve(raulInds.size() + CountPointFlag(tF)); MeshPointArray::_TConstIterator beg = _rclMesh._aclPointArray.begin(); @@ -859,15 +767,15 @@ void MeshAlgorithm::GetPointsFlag (std::vector &raulInds, MeshPoi } } -void MeshAlgorithm::ResetFacetsFlag (const std::vector &raulInds, MeshFacet::TFlagType tF) const +void MeshAlgorithm::ResetFacetsFlag (const std::vector &raulInds, MeshFacet::TFlagType tF) const { - for (std::vector::const_iterator i = raulInds.begin(); i != raulInds.end(); ++i) + for (std::vector::const_iterator i = raulInds.begin(); i != raulInds.end(); ++i) _rclMesh._aclFacetArray[*i].ResetFlag(tF); } -void MeshAlgorithm::ResetPointsFlag (const std::vector &raulInds, MeshPoint::TFlagType tF) const +void MeshAlgorithm::ResetPointsFlag (const std::vector &raulInds, MeshPoint::TFlagType tF) const { - for (std::vector::const_iterator i = raulInds.begin(); i != raulInds.end(); ++i) + for (std::vector::const_iterator i = raulInds.begin(); i != raulInds.end(); ++i) _rclMesh._aclPointArray[*i].ResetFlag(tF); } @@ -905,7 +813,7 @@ unsigned long MeshAlgorithm::CountPointFlag (MeshPoint::TFlagType tF) const [flag, tF](const MeshPoint& f) { return flag(f, tF);}); } -void MeshAlgorithm::GetFacetsFromToolMesh( const MeshKernel& rToolMesh, const Base::Vector3f& rcDir, std::vector &raclCutted ) const +void MeshAlgorithm::GetFacetsFromToolMesh( const MeshKernel& rToolMesh, const Base::Vector3f& rcDir, std::vector &raclCutted ) const { MeshFacetIterator cFIt(_rclMesh); MeshFacetIterator cTIt(rToolMesh); @@ -948,7 +856,7 @@ void MeshAlgorithm::GetFacetsFromToolMesh( const MeshKernel& rToolMesh, const Ba } void MeshAlgorithm::GetFacetsFromToolMesh(const MeshKernel& rToolMesh, const Base::Vector3f& rcDir, - const MeshFacetGrid& rGrid, std::vector &raclCutted) const + const MeshFacetGrid& rGrid, std::vector &raclCutted) const { // iterator over grid structure MeshGridIterator clGridIter(rGrid); @@ -966,7 +874,7 @@ void MeshAlgorithm::GetFacetsFromToolMesh(const MeshKernel& rToolMesh, const Bas // box is inside the toolmesh all facets are stored with no further tests because they must // also lie inside the toolmesh. Finally, if the grid box intersects with the toolmesh we must // also check for each whether it intersects with the toolmesh as well. - std::vector aulInds; + std::vector aulInds; for (clGridIter.Init(); clGridIter.More(); clGridIter.Next()) { int ret = cToolAlg.Surround(clGridIter.GetBoundBox(), rcDir); @@ -997,7 +905,7 @@ void MeshAlgorithm::GetFacetsFromToolMesh(const MeshKernel& rToolMesh, const Bas Base::SequencerLauncher seq("Check facets...", aulInds.size()); // check all facets - for (std::vector::iterator it = aulInds.begin(); it != aulInds.end(); ++it) { + for (std::vector::iterator it = aulInds.begin(); it != aulInds.end(); ++it) { cFIt.Set(*it); // check each point of each facet @@ -1104,9 +1012,9 @@ int MeshAlgorithm::Surround(const Base::BoundBox3f& rBox, const Base::Vector3f& } void MeshAlgorithm::CheckFacets(const MeshFacetGrid& rclGrid, const Base::ViewProjMethod* pclProj, const Base::Polygon2d& rclPoly, - bool bInner, std::vector &raulFacets) const + bool bInner, std::vector &raulFacets) const { - std::vector::iterator it; + std::vector::iterator it; MeshFacetIterator clIter(_rclMesh, 0); Base::Vector3f clPt2d; Base::Vector3f clGravityOfFacet; @@ -1120,7 +1028,7 @@ void MeshAlgorithm::CheckFacets(const MeshFacetGrid& rclGrid, const Base::ViewPr if (bInner) { BoundBox3f clBBox3d; BoundBox2d clViewBBox; - std::vector aulAllElements; + std::vector aulAllElements; // iterator for the bounding box grids MeshGridIterator clGridIter(rclGrid); for (clGridIter.Init(); clGridIter.More(); clGridIter.Next()) { @@ -1183,7 +1091,7 @@ void MeshAlgorithm::CheckFacets(const MeshFacetGrid& rclGrid, const Base::ViewPr } void MeshAlgorithm::CheckFacets(const Base::ViewProjMethod* pclProj, const Base::Polygon2d& rclPoly, - bool bInner, std::vector &raulFacets) const + bool bInner, std::vector &raulFacets) const { const MeshPointArray& p = _rclMesh.GetPoints(); const MeshFacetArray& f = _rclMesh.GetFacets(); @@ -1193,7 +1101,7 @@ void MeshAlgorithm::CheckFacets(const Base::ViewProjMethod* pclProj, const Base: // Precompute the screen projection matrix as Coin's projection function is expensive Base::ViewProjMatrix fixedProj(pclProj->getComposedProjectionMatrix()); - unsigned long index=0; + FacetIndex index=0; for (MeshFacetArray::_TConstIterator it = f.begin(); it != f.end(); ++it,++index) { for (int i = 0; i < 3; i++) { pt2d = fixedProj(p[it->_aulPoints[i]]); @@ -1208,7 +1116,7 @@ void MeshAlgorithm::CheckFacets(const Base::ViewProjMethod* pclProj, const Base: } } -float MeshAlgorithm::Surface (void) const +float MeshAlgorithm::Surface () const { float fTotal = 0.0f; MeshFacetIterator clFIter(_rclMesh); @@ -1250,13 +1158,13 @@ void MeshAlgorithm::SubSampleByCount (unsigned long ulCtPoints, std::vector &rclPolyline, float fRadius, - const MeshFacetGrid& rclGrid, std::vector &rclResultFacetsIndices) const + const MeshFacetGrid& rclGrid, std::vector &rclResultFacetsIndices) const { rclResultFacetsIndices.clear(); if ( rclPolyline.size() < 3 ) return; // no polygon defined - std::set aclFacets; + std::set aclFacets; for (std::vector::const_iterator pV = rclPolyline.begin(); pV < (rclPolyline.end() - 1); ++pV) { const Base::Vector3f &rclP0 = *pV, &rclP1 = *(pV + 1); @@ -1266,7 +1174,7 @@ void MeshAlgorithm::SearchFacetsFromPolyline (const std::vector clSegmBB.Add(rclP1); clSegmBB.Enlarge(fRadius); // BB um Suchradius vergroessern - std::vector aclBBFacets; + std::vector aclBBFacets; unsigned long k = rclGrid.Inside(clSegmBB, aclBBFacets, false); for (unsigned long i = 0; i < k; i++) { @@ -1278,17 +1186,17 @@ void MeshAlgorithm::SearchFacetsFromPolyline (const std::vector rclResultFacetsIndices.insert(rclResultFacetsIndices.begin(), aclFacets.begin(), aclFacets.end()); } -void MeshAlgorithm::CutBorderFacets (std::vector &raclFacetIndices, unsigned short usLevel) const +void MeshAlgorithm::CutBorderFacets (std::vector &raclFacetIndices, unsigned short usLevel) const { - std::vector aclToDelete; + std::vector aclToDelete; CheckBorderFacets(raclFacetIndices, aclToDelete, usLevel); // alle gefunden "Rand"-Facetsindizes" aus dem Array loeschen - std::vector aclResult; - std::set aclTmp(aclToDelete.begin(), aclToDelete.end()); + std::vector aclResult; + std::set aclTmp(aclToDelete.begin(), aclToDelete.end()); - for (std::vector::iterator pI = raclFacetIndices.begin(); pI != raclFacetIndices.end(); ++pI) + for (std::vector::iterator pI = raclFacetIndices.begin(); pI != raclFacetIndices.end(); ++pI) { if (aclTmp.find(*pI) == aclTmp.end()) aclResult.push_back(*pI); @@ -1304,7 +1212,7 @@ unsigned long MeshAlgorithm::CountBorderEdges() const MeshFacetArray::_TConstIterator end = rclFAry.end(); for (MeshFacetArray::_TConstIterator it = rclFAry.begin(); it != end; ++it) { for (int i=0; i<3; i++) { - if (it->_aulNeighbours[i] == ULONG_MAX) + if (it->_aulNeighbours[i] == FACET_INDEX_MAX) cnt++; } } @@ -1312,7 +1220,7 @@ unsigned long MeshAlgorithm::CountBorderEdges() const return cnt; } -void MeshAlgorithm::CheckBorderFacets (const std::vector &raclFacetIndices, std::vector &raclResultIndices, unsigned short usLevel) const +void MeshAlgorithm::CheckBorderFacets (const std::vector &raclFacetIndices, std::vector &raclResultIndices, unsigned short usLevel) const { ResetFacetFlag(MeshFacet::TMP0); SetFacetsFlag(raclFacetIndices, MeshFacet::TMP0); @@ -1321,12 +1229,12 @@ void MeshAlgorithm::CheckBorderFacets (const std::vector &raclFac for (unsigned short usL = 0; usL < usLevel; usL++) { - for (std::vector::const_iterator pF = raclFacetIndices.begin(); pF != raclFacetIndices.end(); ++pF) + for (std::vector::const_iterator pF = raclFacetIndices.begin(); pF != raclFacetIndices.end(); ++pF) { for (int i = 0; i < 3; i++) { - unsigned long ulNB = rclFAry[*pF]._aulNeighbours[i]; - if (ulNB == ULONG_MAX) + FacetIndex ulNB = rclFAry[*pF]._aulNeighbours[i]; + if (ulNB == FACET_INDEX_MAX) { raclResultIndices.push_back(*pF); rclFAry[*pF].ResetFlag(MeshFacet::TMP0); @@ -1343,20 +1251,20 @@ void MeshAlgorithm::CheckBorderFacets (const std::vector &raclFac } } -void MeshAlgorithm::GetBorderPoints (const std::vector &raclFacetIndices, std::set &raclResultPointsIndices) const +void MeshAlgorithm::GetBorderPoints (const std::vector &raclFacetIndices, std::set &raclResultPointsIndices) const { ResetFacetFlag(MeshFacet::TMP0); SetFacetsFlag(raclFacetIndices, MeshFacet::TMP0); const MeshFacetArray &rclFAry = _rclMesh._aclFacetArray; - for (std::vector::const_iterator pF = raclFacetIndices.begin(); pF != raclFacetIndices.end(); ++pF) + for (std::vector::const_iterator pF = raclFacetIndices.begin(); pF != raclFacetIndices.end(); ++pF) { for (int i = 0; i < 3; i++) { const MeshFacet &rclFacet = rclFAry[*pF]; - unsigned long ulNB = rclFacet._aulNeighbours[i]; - if (ulNB == ULONG_MAX) + FacetIndex ulNB = rclFacet._aulNeighbours[i]; + if (ulNB == FACET_INDEX_MAX) { raclResultPointsIndices.insert(rclFacet._aulPoints[i]); raclResultPointsIndices.insert(rclFacet._aulPoints[(i+1)%3]); @@ -1372,14 +1280,14 @@ void MeshAlgorithm::GetBorderPoints (const std::vector &raclFacet } } -bool MeshAlgorithm::NearestPointFromPoint (const Base::Vector3f &rclPt, unsigned long &rclResFacetIndex, Base::Vector3f &rclResPoint) const +bool MeshAlgorithm::NearestPointFromPoint (const Base::Vector3f &rclPt, FacetIndex &rclResFacetIndex, Base::Vector3f &rclResPoint) const { if (_rclMesh.CountFacets() == 0) return false; // calc each facet float fMinDist = FLOAT_MAX; - unsigned long ulInd = ULONG_MAX; + FacetIndex ulInd = FACET_INDEX_MAX; MeshFacetIterator pF(_rclMesh); for (pF.Init(); pF.More(); pF.Next()) { @@ -1398,11 +1306,11 @@ bool MeshAlgorithm::NearestPointFromPoint (const Base::Vector3f &rclPt, unsigned return true; } -bool MeshAlgorithm::NearestPointFromPoint (const Base::Vector3f &rclPt, const MeshFacetGrid& rclGrid, unsigned long &rclResFacetIndex, Base::Vector3f &rclResPoint) const +bool MeshAlgorithm::NearestPointFromPoint (const Base::Vector3f &rclPt, const MeshFacetGrid& rclGrid, FacetIndex &rclResFacetIndex, Base::Vector3f &rclResPoint) const { - unsigned long ulInd = rclGrid.SearchNearestFromPoint(rclPt); + FacetIndex ulInd = rclGrid.SearchNearestFromPoint(rclPt); - if (ulInd == ULONG_MAX) + if (ulInd == FACET_INDEX_MAX) { return false; } @@ -1415,11 +1323,11 @@ bool MeshAlgorithm::NearestPointFromPoint (const Base::Vector3f &rclPt, const Me } bool MeshAlgorithm::NearestPointFromPoint (const Base::Vector3f &rclPt, const MeshFacetGrid& rclGrid, float fMaxSearchArea, - unsigned long &rclResFacetIndex, Base::Vector3f &rclResPoint) const + FacetIndex &rclResFacetIndex, Base::Vector3f &rclResPoint) const { - unsigned long ulInd = rclGrid.SearchNearestFromPoint(rclPt, fMaxSearchArea); + FacetIndex ulInd = rclGrid.SearchNearestFromPoint(rclPt, fMaxSearchArea); - if (ulInd == ULONG_MAX) + if (ulInd == FACET_INDEX_MAX) return false; // no facets inside BoundingBox MeshGeomFacet rclSFacet = _rclMesh.GetFacet(ulInd); @@ -1432,7 +1340,7 @@ bool MeshAlgorithm::NearestPointFromPoint (const Base::Vector3f &rclPt, const Me bool MeshAlgorithm::CutWithPlane (const Base::Vector3f &clBase, const Base::Vector3f &clNormal, const MeshFacetGrid &rclGrid, std::list > &rclResult, float fMinEps, bool bConnectPolygons) const { - std::vector aulFacets; + std::vector aulFacets; // Grid durschsuchen MeshGridIterator clGridIter(rclGrid); @@ -1450,7 +1358,7 @@ bool MeshAlgorithm::CutWithPlane (const Base::Vector3f &clBase, const Base::Vect // alle Facets mit Ebene schneiden std::list > clTempPoly; // Feld mit Schnittlinien (unsortiert, nicht verkettet) - for (std::vector::iterator pF = aulFacets.begin(); pF != aulFacets.end(); ++pF) + for (std::vector::iterator pF = aulFacets.begin(); pF != aulFacets.end(); ++pF) { Base::Vector3f clE1, clE2; const MeshGeomFacet clF(_rclMesh.GetFacet(*pF)); @@ -1630,9 +1538,9 @@ bool MeshAlgorithm::ConnectPolygons(std::list > &clP } void MeshAlgorithm::GetFacetsFromPlane (const MeshFacetGrid &rclGrid, const Base::Vector3f& clNormal, float d, const Base::Vector3f &rclLeft, - const Base::Vector3f &rclRight, std::vector &rclRes) const + const Base::Vector3f &rclRight, std::vector &rclRes) const { - std::vector aulFacets; + std::vector aulFacets; Base::Vector3f clBase = d * clNormal; @@ -1648,7 +1556,7 @@ void MeshAlgorithm::GetFacetsFromPlane (const MeshFacetGrid &rclGrid, const Base } // testing facet against planes - for (std::vector::iterator pI = aulFacets.begin(); pI != aulFacets.end(); ++pI) { + for (std::vector::iterator pI = aulFacets.begin(); pI != aulFacets.end(); ++pI) { MeshGeomFacet clSFacet = _rclMesh.GetFacet(*pI); if (clSFacet.IntersectWithPlane(clBase, clNormal) == true) { bool bInner = false; @@ -1664,29 +1572,29 @@ void MeshAlgorithm::GetFacetsFromPlane (const MeshFacetGrid &rclGrid, const Base } } -void MeshAlgorithm::PointsFromFacetsIndices (const std::vector &rvecIndices, std::vector &rvecPoints) const +void MeshAlgorithm::PointsFromFacetsIndices (const std::vector &rvecIndices, std::vector &rvecPoints) const { const MeshFacetArray &rclFAry = _rclMesh._aclFacetArray; const MeshPointArray &rclPAry = _rclMesh._aclPointArray; - std::set setPoints; + std::set setPoints; - for (std::vector::const_iterator itI = rvecIndices.begin(); itI != rvecIndices.end(); ++itI) + for (std::vector::const_iterator itI = rvecIndices.begin(); itI != rvecIndices.end(); ++itI) { for (int i = 0; i < 3; i++) setPoints.insert(rclFAry[*itI]._aulPoints[i]); } rvecPoints.clear(); - for (std::set::iterator itP = setPoints.begin(); itP != setPoints.end(); ++itP) + for (std::set::iterator itP = setPoints.begin(); itP != setPoints.end(); ++itP) rvecPoints.push_back(rclPAry[*itP]); } -bool MeshAlgorithm::Distance (const Base::Vector3f &rclPt, unsigned long ulFacetIdx, float fMaxDistance, float &rfDistance) const +bool MeshAlgorithm::Distance (const Base::Vector3f &rclPt, FacetIndex ulFacetIdx, float fMaxDistance, float &rfDistance) const { const MeshFacetArray &rclFAry = _rclMesh._aclFacetArray; const MeshPointArray &rclPAry = _rclMesh._aclPointArray; - const unsigned long *pulIdx = rclFAry[ulFacetIdx]._aulPoints; + const PointIndex *pulIdx = rclFAry[ulFacetIdx]._aulPoints; BoundBox3f clBB; clBB.Add(rclPAry[*(pulIdx++)]); @@ -1714,7 +1622,7 @@ float MeshAlgorithm::CalculateMinimumGridLength(float fLength, const Base::Bound // ---------------------------------------------------- -void MeshRefPointToFacets::Rebuild (void) +void MeshRefPointToFacets::Rebuild () { _map.clear(); @@ -1730,12 +1638,12 @@ void MeshRefPointToFacets::Rebuild (void) } } -Base::Vector3f MeshRefPointToFacets::GetNormal(unsigned long pos) const +Base::Vector3f MeshRefPointToFacets::GetNormal(PointIndex pos) const { - const std::set& n = _map[pos]; + const std::set& n = _map[pos]; Base::Vector3f normal; MeshGeomFacet f; - for (std::set::const_iterator it = n.begin(); it != n.end(); ++it) { + for (std::set::const_iterator it = n.begin(); it != n.end(); ++it) { f = _rclMesh.GetFacet(*it); normal += f.Area() * f.GetNormal(); } @@ -1744,19 +1652,19 @@ Base::Vector3f MeshRefPointToFacets::GetNormal(unsigned long pos) const return normal; } -std::set MeshRefPointToFacets::NeighbourPoints(const std::vector& pt, int level) const +std::set MeshRefPointToFacets::NeighbourPoints(const std::vector& pt, int level) const { - std::set cp,nb,lp; + std::set cp,nb,lp; cp.insert(pt.begin(), pt.end()); lp.insert(pt.begin(), pt.end()); MeshFacetArray::_TConstIterator f_it = _rclMesh.GetFacets().begin(); for (int i=0; i < level; i++) { - std::set cur; - for (std::set::iterator it = lp.begin(); it != lp.end(); ++it) { - const std::set& ft = (*this)[*it]; - for (std::set::const_iterator jt = ft.begin(); jt != ft.end(); ++jt) { + std::set cur; + for (std::set::iterator it = lp.begin(); it != lp.end(); ++it) { + const std::set& ft = (*this)[*it]; + for (std::set::const_iterator jt = ft.begin(); jt != ft.end(); ++jt) { for (int j = 0; j < 3; j++) { - unsigned long index = f_it[*jt]._aulPoints[j]; + PointIndex index = f_it[*jt]._aulPoints[j]; if (cp.find(index) == cp.end() && nb.find(index) == nb.end()) { nb.insert(index); cur.insert(index); @@ -1772,12 +1680,12 @@ std::set MeshRefPointToFacets::NeighbourPoints(const std::vector< return nb; } -std::set MeshRefPointToFacets::NeighbourPoints(unsigned long pos) const +std::set MeshRefPointToFacets::NeighbourPoints(PointIndex pos) const { - std::set p; - const std::set& vf = _map[pos]; - for (std::set::const_iterator it = vf.begin(); it != vf.end(); ++it) { - unsigned long p1, p2, p3; + std::set p; + const std::set& vf = _map[pos]; + for (std::set::const_iterator it = vf.begin(); it != vf.end(); ++it) { + PointIndex p1, p2, p3; _rclMesh.GetFacetPoints(*it, p1, p2, p3); if (p1 != pos) p.insert(p1); @@ -1790,17 +1698,17 @@ std::set MeshRefPointToFacets::NeighbourPoints(unsigned long pos) return p; } -void MeshRefPointToFacets::Neighbours (unsigned long ulFacetInd, float fMaxDist, MeshCollector& collect) const +void MeshRefPointToFacets::Neighbours (FacetIndex ulFacetInd, float fMaxDist, MeshCollector& collect) const { - std::set visited; + std::set visited; Base::Vector3f clCenter = _rclMesh.GetFacet(ulFacetInd).GetGravityPoint(); const MeshFacetArray& rFacets = _rclMesh.GetFacets(); SearchNeighbours(rFacets, ulFacetInd, clCenter, fMaxDist * fMaxDist, visited, collect); } -void MeshRefPointToFacets::SearchNeighbours(const MeshFacetArray& rFacets, unsigned long index, const Base::Vector3f &rclCenter, - float fMaxDist2, std::set& visited, MeshCollector& collect) const +void MeshRefPointToFacets::SearchNeighbours(const MeshFacetArray& rFacets, FacetIndex index, const Base::Vector3f &rclCenter, + float fMaxDist2, std::set& visited, MeshCollector& collect) const { if (visited.find(index) != visited.end()) return; @@ -1812,61 +1720,61 @@ void MeshRefPointToFacets::SearchNeighbours(const MeshFacetArray& rFacets, unsig visited.insert(index); collect.Append(_rclMesh, index); for (int i = 0; i < 3; i++) { - const std::set &f = (*this)[face._aulPoints[i]]; + const std::set &f = (*this)[face._aulPoints[i]]; - for (std::set::const_iterator j = f.begin(); j != f.end(); ++j) { + for (std::set::const_iterator j = f.begin(); j != f.end(); ++j) { SearchNeighbours(rFacets, *j, rclCenter, fMaxDist2, visited, collect); } } } MeshFacetArray::_TConstIterator -MeshRefPointToFacets::GetFacet (unsigned long index) const +MeshRefPointToFacets::GetFacet (FacetIndex index) const { return _rclMesh.GetFacets().begin() + index; } -const std::set& -MeshRefPointToFacets::operator[] (unsigned long pos) const +const std::set& +MeshRefPointToFacets::operator[] (PointIndex pos) const { return _map[pos]; } -std::vector -MeshRefPointToFacets::GetIndices(unsigned long pos1, unsigned long pos2) const +std::vector +MeshRefPointToFacets::GetIndices(PointIndex pos1, PointIndex pos2) const { - std::vector intersection; - std::back_insert_iterator > result(intersection); - const std::set& set1 = _map[pos1]; - const std::set& set2 = _map[pos2]; + std::vector intersection; + std::back_insert_iterator > result(intersection); + const std::set& set1 = _map[pos1]; + const std::set& set2 = _map[pos2]; std::set_intersection(set1.begin(), set1.end(), set2.begin(), set2.end(), result); return intersection; } -std::vector -MeshRefPointToFacets::GetIndices(unsigned long pos1, unsigned long pos2, unsigned long pos3) const +std::vector +MeshRefPointToFacets::GetIndices(PointIndex pos1, PointIndex pos2, PointIndex pos3) const { - std::vector intersection; - std::back_insert_iterator > result(intersection); - std::vector set1 = GetIndices(pos1, pos2); - const std::set& set2 = _map[pos3]; + std::vector intersection; + std::back_insert_iterator > result(intersection); + std::vector set1 = GetIndices(pos1, pos2); + const std::set& set2 = _map[pos3]; std::set_intersection(set1.begin(), set1.end(), set2.begin(), set2.end(), result); return intersection; } -void MeshRefPointToFacets::AddNeighbour(unsigned long pos, unsigned long facet) +void MeshRefPointToFacets::AddNeighbour(PointIndex pos, FacetIndex facet) { _map[pos].insert(facet); } -void MeshRefPointToFacets::RemoveNeighbour(unsigned long pos, unsigned long facet) +void MeshRefPointToFacets::RemoveNeighbour(PointIndex pos, FacetIndex facet) { _map[pos].erase(facet); } -void MeshRefPointToFacets::RemoveFacet(unsigned long facetIndex) +void MeshRefPointToFacets::RemoveFacet(FacetIndex facetIndex) { - unsigned long p0, p1, p2; + PointIndex p0, p1, p2; _rclMesh.GetFacetPoints(facetIndex, p0, p1, p2); _map[p0].erase(facetIndex); @@ -1876,7 +1784,7 @@ void MeshRefPointToFacets::RemoveFacet(unsigned long facetIndex) //---------------------------------------------------------------------------- -void MeshRefFacetToFacets::Rebuild (void) +void MeshRefFacetToFacets::Rebuild () { _map.clear(); @@ -1887,33 +1795,33 @@ void MeshRefFacetToFacets::Rebuild (void) MeshFacetArray::_TConstIterator pFBegin = rFacets.begin(); for (MeshFacetArray::_TConstIterator pFIter = pFBegin; pFIter != rFacets.end(); ++pFIter) { for (int i = 0; i < 3; i++) { - const std::set& faces = vertexFace[pFIter->_aulPoints[i]]; - for (std::set::const_iterator it = faces.begin(); it != faces.end(); ++it) + const std::set& faces = vertexFace[pFIter->_aulPoints[i]]; + for (std::set::const_iterator it = faces.begin(); it != faces.end(); ++it) _map[pFIter - pFBegin].insert(*it); } } } -const std::set& -MeshRefFacetToFacets::operator[] (unsigned long pos) const +const std::set& +MeshRefFacetToFacets::operator[] (FacetIndex pos) const { return _map[pos]; } -std::vector -MeshRefFacetToFacets::GetIndices(unsigned long pos1, unsigned long pos2) const +std::vector +MeshRefFacetToFacets::GetIndices(FacetIndex pos1, FacetIndex pos2) const { - std::vector intersection; - std::back_insert_iterator > result(intersection); - const std::set& set1 = _map[pos1]; - const std::set& set2 = _map[pos2]; + std::vector intersection; + std::back_insert_iterator > result(intersection); + const std::set& set1 = _map[pos1]; + const std::set& set2 = _map[pos2]; std::set_intersection(set1.begin(), set1.end(), set2.begin(), set2.end(), result); return intersection; } //---------------------------------------------------------------------------- -void MeshRefPointToPoints::Rebuild (void) +void MeshRefPointToPoints::Rebuild () { _map.clear(); @@ -1922,9 +1830,9 @@ void MeshRefPointToPoints::Rebuild (void) const MeshFacetArray& rFacets = _rclMesh.GetFacets(); for (MeshFacetArray::_TConstIterator pFIter = rFacets.begin(); pFIter != rFacets.end(); ++pFIter) { - unsigned long ulP0 = pFIter->_aulPoints[0]; - unsigned long ulP1 = pFIter->_aulPoints[1]; - unsigned long ulP2 = pFIter->_aulPoints[2]; + PointIndex ulP0 = pFIter->_aulPoints[0]; + PointIndex ulP1 = pFIter->_aulPoints[1]; + PointIndex ulP2 = pFIter->_aulPoints[2]; _map[ulP0].insert(ulP1); _map[ulP0].insert(ulP2); @@ -1935,14 +1843,14 @@ void MeshRefPointToPoints::Rebuild (void) } } -Base::Vector3f MeshRefPointToPoints::GetNormal(unsigned long pos) const +Base::Vector3f MeshRefPointToPoints::GetNormal(PointIndex pos) const { const MeshPointArray& rPoints = _rclMesh.GetPoints(); MeshCore::PlaneFit pf; pf.AddPoint(rPoints[pos]); MeshCore::MeshPoint center = rPoints[pos]; - const std::set& cv = _map[pos]; - for (std::set::const_iterator cv_it = cv.begin(); cv_it !=cv.end(); ++cv_it) { + const std::set& cv = _map[pos]; + for (std::set::const_iterator cv_it = cv.begin(); cv_it !=cv.end(); ++cv_it) { pf.AddPoint(rPoints[*cv_it]); center += rPoints[*cv_it]; } @@ -1954,42 +1862,42 @@ Base::Vector3f MeshRefPointToPoints::GetNormal(unsigned long pos) const return normal; } -float MeshRefPointToPoints::GetAverageEdgeLength(unsigned long index) const +float MeshRefPointToPoints::GetAverageEdgeLength(PointIndex index) const { const MeshPointArray& rPoints = _rclMesh.GetPoints(); float len=0.0f; - const std::set& n = (*this)[index]; + const std::set& n = (*this)[index]; const Base::Vector3f& p = rPoints[index]; - for (std::set::const_iterator it = n.begin(); it != n.end(); ++it) { + for (std::set::const_iterator it = n.begin(); it != n.end(); ++it) { len += Base::Distance(p, rPoints[*it]); } return (len/n.size()); } -const std::set& -MeshRefPointToPoints::operator[] (unsigned long pos) const +const std::set& +MeshRefPointToPoints::operator[] (PointIndex pos) const { return _map[pos]; } -void MeshRefPointToPoints::AddNeighbour(unsigned long pos, unsigned long facet) +void MeshRefPointToPoints::AddNeighbour(PointIndex pos, PointIndex facet) { _map[pos].insert(facet); } -void MeshRefPointToPoints::RemoveNeighbour(unsigned long pos, unsigned long facet) +void MeshRefPointToPoints::RemoveNeighbour(PointIndex pos, PointIndex facet) { _map[pos].erase(facet); } //---------------------------------------------------------------------------- -void MeshRefEdgeToFacets::Rebuild (void) +void MeshRefEdgeToFacets::Rebuild () { _map.clear(); const MeshFacetArray& rFacets = _rclMesh.GetFacets(); - unsigned long index = 0; + FacetIndex index = 0; for (MeshFacetArray::_TConstIterator it = rFacets.begin(); it != rFacets.end(); ++it, ++index) { for (int i=0; i<3; i++) { MeshEdge e; @@ -1999,7 +1907,7 @@ void MeshRefEdgeToFacets::Rebuild (void) _map.find(e); if (jt == _map.end()) { _map[e].first = index; - _map[e].second = ULONG_MAX; + _map[e].second = FACET_INDEX_MAX; } else { _map[e].second = index; @@ -2008,7 +1916,7 @@ void MeshRefEdgeToFacets::Rebuild (void) } } -const std::pair& +const std::pair& MeshRefEdgeToFacets::operator[] (const MeshEdge& edge) const { return _map.find(edge)->second; @@ -2016,7 +1924,7 @@ MeshRefEdgeToFacets::operator[] (const MeshEdge& edge) const //---------------------------------------------------------------------------- -void MeshRefNormalToPoints::Rebuild (void) +void MeshRefNormalToPoints::Rebuild () { _norm.clear(); @@ -2042,7 +1950,7 @@ void MeshRefNormalToPoints::Rebuild (void) } const Base::Vector3f& -MeshRefNormalToPoints::operator[] (unsigned long pos) const +MeshRefNormalToPoints::operator[] (PointIndex pos) const { return _norm[pos]; } diff --git a/src/Mod/Mesh/App/Core/Algorithm.h b/src/Mod/Mesh/App/Core/Algorithm.h index 424ffda122..79848d2ee2 100644 --- a/src/Mod/Mesh/App/Core/Algorithm.h +++ b/src/Mod/Mesh/App/Core/Algorithm.h @@ -58,7 +58,7 @@ public: /// Construction MeshAlgorithm (const MeshKernel &rclM) : _rclMesh(rclM) { } /// Destruction - ~MeshAlgorithm (void) { } + ~MeshAlgorithm () { } public: /** @@ -70,7 +70,7 @@ public: * occasionally. */ bool NearestFacetOnRay (const Base::Vector3f &rclPt, const Base::Vector3f &rclDir, Base::Vector3f &rclRes, - unsigned long &rulFacet) const; + FacetIndex &rulFacet) const; /** * Searches for the nearest facet to the ray defined by * (\a rclPt, \a rclDir). @@ -80,7 +80,7 @@ public: * used for a lot of tests. */ bool NearestFacetOnRay (const Base::Vector3f &rclPt, const Base::Vector3f &rclDir, const MeshFacetGrid &rclGrid, - Base::Vector3f &rclRes, unsigned long &rulFacet) const; + Base::Vector3f &rclRes, FacetIndex &rulFacet) const; /** * Searches for the nearest facet to the ray defined by * (\a rclPt, \a rclDir). @@ -90,8 +90,8 @@ public: * the attached mesh. So the caller must ensure that the indices are valid * facets. */ - bool NearestFacetOnRay (const Base::Vector3f &rclPt, const Base::Vector3f &rclDir, const std::vector &raulFacets, - Base::Vector3f &rclRes, unsigned long &rulFacet) const; + bool NearestFacetOnRay (const Base::Vector3f &rclPt, const Base::Vector3f &rclDir, const std::vector &raulFacets, + Base::Vector3f &rclRes, FacetIndex &rulFacet) const; /** * Searches for the nearest facet to the ray defined by (\a rclPt, \a rclDir). The point \a rclRes holds * the intersection point with the ray and the nearest facet with index \a rulFacet. @@ -99,13 +99,13 @@ public: * \note This method is optimized by using a grid. So this method can be used for a lot of tests. */ bool NearestFacetOnRay (const Base::Vector3f &rclPt, const Base::Vector3f &rclDir, float fMaxSearchArea, - const MeshFacetGrid &rclGrid, Base::Vector3f &rclRes, unsigned long &rulFacet) const; + const MeshFacetGrid &rclGrid, Base::Vector3f &rclRes, FacetIndex &rulFacet) const; /** * Searches for the first facet of the grid element (\a rclGrid) in that the point \a rclPt lies into which is a distance not * higher than \a fMaxDistance. Of no such facet is found \a rulFacet is undefined and false is returned, otherwise true. * \note If the point \a rclPt is outside of the grid \a rclGrid nothing is done. */ - bool FirstFacetToVertex(const Base::Vector3f &rclPt, float fMaxDistance, const MeshFacetGrid &rclGrid, unsigned long &rulFacet) const; + bool FirstFacetToVertex(const Base::Vector3f &rclPt, float fMaxDistance, const MeshFacetGrid &rclGrid, FacetIndex &rulFacet) const; /** * Checks from the viewpoint \a rcView if the vertex \a rcVertex is visible or it is hidden by a facet. * If the vertex is visible true is returned, false otherwise. @@ -135,11 +135,11 @@ public: * Returns all boundaries of the mesh. This method does basically the same as above unless that it returns the point indices * of the boundaries. */ - void GetMeshBorders (std::list > &rclBorders) const; + void GetMeshBorders (std::list > &rclBorders) const; /** * Returns all boundaries of a subset the mesh defined by \a raulInd. */ - void GetFacetBorders (const std::vector &raulInd, std::list > &rclBorders) const; + void GetFacetBorders (const std::vector &raulInd, std::list > &rclBorders) const; /** * Returns all boundaries of a subset the mesh defined by \a raulInd. This method does basically the same as above unless * that it returns the point indices of the boundaries. @@ -148,18 +148,18 @@ public: * orientation even if the mesh is topologically correct. You should let the default value unless you exactly * know what you do. */ - void GetFacetBorders (const std::vector &raulInd, std::list > &rclBorders, + void GetFacetBorders (const std::vector &raulInd, std::list > &rclBorders, bool ignoreOrientation = false) const; /** * Returns the boundary of the mesh to the facet \a uFacet. If this facet does not have an open edge the returned * boundary is empty. */ - void GetMeshBorder(unsigned long uFacet, std::list& rBorder) const; + void GetMeshBorder(FacetIndex uFacet, std::list& rBorder) const; /** * Boundaries that consist of several loops must be split in several independent boundaries * to perform e.g. a polygon triangulation algorithm on them. */ - void SplitBoundaryLoops( std::list >& aBorders ); + void SplitBoundaryLoops( std::list >& aBorders ); /** * Fills up the single boundary if it is a hole with high quality triangles and a maximum area of \a fMaxArea. * The triangulation information is stored in \a rFaces and \a rPoints. @@ -172,14 +172,14 @@ public: * @note If the number of geometric points exceeds the number of boundary indices then the triangulation algorithm has * introduced new points which are added to the end of \a rPoints. */ - bool FillupHole(const std::vector& boundary, + bool FillupHole(const std::vector& boundary, AbstractPolygonTriangulator& cTria, MeshFacetArray& rFaces, MeshPointArray& rPoints, - int level, const MeshRefPointToFacets* pP2FStructure=0) const; + int level, const MeshRefPointToFacets* pP2FStructure=nullptr) const; /** Sets to all facets in \a raulInds the properties in raulProps. * \note Both arrays must have the same size. */ - void SetFacetsProperty(const std::vector &raulInds, const std::vector &raulProps) const; + void SetFacetsProperty(const std::vector &raulInds, const std::vector &raulProps) const; /** Sets to all facets the flag \a tF. */ void SetFacetFlag (MeshFacet::TFlagType tF) const; /** Sets to all points the flag \a tF. */ @@ -189,23 +189,23 @@ public: /** Resets of all points the flag \a tF. */ void ResetPointFlag (MeshPoint::TFlagType tF) const; /** Sets to all facets in \a raulInds the flag \a tF. */ - void SetFacetsFlag (const std::vector &raulInds, MeshFacet::TFlagType tF) const; + void SetFacetsFlag (const std::vector &raulInds, MeshFacet::TFlagType tF) const; /** Sets to all points in \a raulInds the flag \a tF. */ - void SetPointsFlag (const std::vector &raulInds, MeshPoint::TFlagType tF) const; + void SetPointsFlag (const std::vector &raulInds, MeshPoint::TFlagType tF) const; /** Gets all facets in \a raulInds with the flag \a tF. */ - void GetFacetsFlag (std::vector &raulInds, MeshFacet::TFlagType tF) const; + void GetFacetsFlag (std::vector &raulInds, MeshFacet::TFlagType tF) const; /** Gets all points in \a raulInds with the flag \a tF. */ - void GetPointsFlag (std::vector &raulInds, MeshPoint::TFlagType tF) const; + void GetPointsFlag (std::vector &raulInds, MeshPoint::TFlagType tF) const; /** Resets from all facets in \a raulInds the flag \a tF. */ - void ResetFacetsFlag (const std::vector &raulInds, MeshFacet::TFlagType tF) const; + void ResetFacetsFlag (const std::vector &raulInds, MeshFacet::TFlagType tF) const; /** Resets from all points in \a raulInds the flag \a tF. */ - void ResetPointsFlag (const std::vector &raulInds, MeshPoint::TFlagType tF) const; + void ResetPointsFlag (const std::vector &raulInds, MeshPoint::TFlagType tF) const; /** Count all facets with the flag \a tF. */ unsigned long CountFacetFlag (MeshFacet::TFlagType tF) const; /** Count all points with the flag \a tF. */ unsigned long CountPointFlag (MeshPoint::TFlagType tF) const; /** Returns all geometric points from the facets in \a rvecIndices. */ - void PointsFromFacetsIndices (const std::vector &rvecIndices, std::vector &rvecPoints) const; + void PointsFromFacetsIndices (const std::vector &rvecIndices, std::vector &rvecPoints) const; /** * Returns the indices of all facets that have at least one point that lies inside the tool mesh. The direction * \a dir is used to try to foraminate the facets of the tool mesh and counts the number of foraminated facets. @@ -213,11 +213,11 @@ public: * @note The tool mesh must be a valid solid. * @note It's not tested if \a rToolMesh is a valid solid. In case it is not the result is undefined. */ - void GetFacetsFromToolMesh( const MeshKernel& rToolMesh, const Base::Vector3f& rcDir, std::vector &raclCutted ) const; + void GetFacetsFromToolMesh( const MeshKernel& rToolMesh, const Base::Vector3f& rcDir, std::vector &raclCutted ) const; /** * Does basically the same as method above except it uses a mesh grid to speed up the computation. */ - void GetFacetsFromToolMesh( const MeshKernel& rToolMesh, const Base::Vector3f& rcDir, const MeshFacetGrid& rGrid, std::vector &raclCutted ) const; + void GetFacetsFromToolMesh( const MeshKernel& rToolMesh, const Base::Vector3f& rcDir, const MeshFacetGrid& rGrid, std::vector &raclCutted ) const; /** * Checks whether the bounding box \a rBox is surrounded by the attached mesh which must be a solid. * The direction \a rcDir is used to try to foraminate the facets of the tool mesh and counts the number of foraminated facets. @@ -234,34 +234,34 @@ public: * This algorithm is optimized by using a grid. */ void CheckFacets (const MeshFacetGrid &rclGrid, const Base::ViewProjMethod* pclProj, const Base::Polygon2d& rclPoly, - bool bInner, std::vector &rclRes) const; + bool bInner, std::vector &rclRes) const; /** * Does the same as the above method unless that it doesn't use a grid. */ void CheckFacets (const Base::ViewProjMethod* pclProj, const Base::Polygon2d& rclPoly, - bool bInner, std::vector &rclRes) const; + bool bInner, std::vector &rclRes) const; /** * Determines all facets of the given array \a raclFacetIndices that lie at the edge or that * have at least neighbour facet that is not inside the array. The resulting array \a raclResultIndices * is not be deleted before the algorithm starts. \a usLevel indicates how often the algorithm is * repeated. */ - void CheckBorderFacets (const std::vector &raclFacetIndices, - std::vector &raclResultIndices, unsigned short usLevel = 1) const; + void CheckBorderFacets (const std::vector &raclFacetIndices, + std::vector &raclResultIndices, unsigned short usLevel = 1) const; /** * Invokes CheckBorderFacets() to get all border facets of \a raclFacetIndices. Then the content of * \a raclFacetIndices is replaced by all facets that can be deleted. * \note The mesh structure is not modified by this method. This is in the responsibility of the user. */ - void CutBorderFacets (std::vector &raclFacetIndices, unsigned short usLevel = 1) const; + void CutBorderFacets (std::vector &raclFacetIndices, unsigned short usLevel = 1) const; /** Returns the number of border edges */ unsigned long CountBorderEdges() const; /** * Determines all border points as indices of the facets in \a raclFacetIndices. The points are unsorted. */ - void GetBorderPoints (const std::vector &raclFacetIndices, std::set &raclResultPointsIndices) const; + void GetBorderPoints (const std::vector &raclFacetIndices, std::set &raclResultPointsIndices) const; /** Computes the surface of the mesh. */ - float Surface (void) const; + float Surface () const; /** Subsamples the mesh with point distance \a fDist and stores the points in \a rclPoints. */ void SubSampleByDist (float fDist, std::vector &rclPoints) const; /** @@ -275,15 +275,15 @@ public: * Searches for all facets that intersect the "search tube" with radius \a r around the polyline. */ void SearchFacetsFromPolyline (const std::vector &rclPolyline, float fRadius, - const MeshFacetGrid& rclGrid, std::vector &rclResultFacetsIndices) const; + const MeshFacetGrid& rclGrid, std::vector &rclResultFacetsIndices) const; /** Projects a point directly to the mesh (means nearest facet), the result is the facet index and * the foraminate point, use second version with grid for more performance. */ - bool NearestPointFromPoint (const Base::Vector3f &rclPt, unsigned long &rclResFacetIndex, Base::Vector3f &rclResPoint) const; + bool NearestPointFromPoint (const Base::Vector3f &rclPt, FacetIndex &rclResFacetIndex, Base::Vector3f &rclResPoint) const; bool NearestPointFromPoint (const Base::Vector3f &rclPt, const MeshFacetGrid& rclGrid, - unsigned long &rclResFacetIndex, Base::Vector3f &rclResPoint) const; + FacetIndex &rclResFacetIndex, Base::Vector3f &rclResPoint) const; bool NearestPointFromPoint (const Base::Vector3f &rclPt, const MeshFacetGrid& rclGrid, float fMaxSearchArea, - unsigned long &rclResFacetIndex, Base::Vector3f &rclResPoint) const; + FacetIndex &rclResFacetIndex, Base::Vector3f &rclResPoint) const; /** Cuts the mesh with a plane. The result is a list of polylines. */ bool CutWithPlane (const Base::Vector3f &clBase, const Base::Vector3f &clNormal, const MeshFacetGrid &rclGrid, std::list > &rclResult, float fMinEps = 1.0e-2f, bool bConnectPolygons = false) const; @@ -292,12 +292,12 @@ public: * The plane is defined by it normalized normal and the signed distance to the origin. */ void GetFacetsFromPlane (const MeshFacetGrid &rclGrid, const Base::Vector3f& clNormal, float dist, - const Base::Vector3f &rclLeft, const Base::Vector3f &rclRight, std::vector &rclRes) const; + const Base::Vector3f &rclLeft, const Base::Vector3f &rclRight, std::vector &rclRes) const; /** Returns true if the distance from the \a rclPt to the facet \a ulFacetIdx is less than \a fMaxDistance. * If this restriction is met \a rfDistance is set to the actual distance, otherwise false is returned. */ - bool Distance (const Base::Vector3f &rclPt, unsigned long ulFacetIdx, float fMaxDistance, float &rfDistance) const; + bool Distance (const Base::Vector3f &rclPt, FacetIndex ulFacetIdx, float fMaxDistance, float &rfDistance) const; /** * Calculates the minimum grid length so that not more elements than \a maxElements will be created when the grid gets * built up. The minimum grid length must be at least \a fLength. @@ -311,12 +311,12 @@ protected: bool ConnectPolygons(std::list > &clPolyList, std::list > &rclLines) const; /** Searches the nearest facet in \a raulFacets to the ray (\a rclPt, \a rclDir). */ - bool RayNearestField (const Base::Vector3f &rclPt, const Base::Vector3f &rclDir, const std::vector &raulFacets, - Base::Vector3f &rclRes, unsigned long &rulFacet, float fMaxAngle = Mathf::PI) const; + bool RayNearestField (const Base::Vector3f &rclPt, const Base::Vector3f &rclDir, const std::vector &raulFacets, + Base::Vector3f &rclRes, FacetIndex &rulFacet, float fMaxAngle = Mathf::PI) const; /** * Splits the boundary \a rBound in several loops and append this loops to the list of borders. */ - void SplitBoundaryLoops( const std::vector& rBound, std::list >& aBorders ); + void SplitBoundaryLoops( const std::vector& rBound, std::list >& aBorders ); protected: const MeshKernel &_rclMesh; /**< The mesh kernel. */ @@ -327,17 +327,17 @@ class MeshExport MeshCollector public: MeshCollector(){} virtual ~MeshCollector(){} - virtual void Append(const MeshCore::MeshKernel&, unsigned long index) = 0; + virtual void Append(const MeshCore::MeshKernel&, FacetIndex index) = 0; }; class MeshExport PointCollector : public MeshCollector { public: - PointCollector(std::vector& ind) : indices(ind){} + PointCollector(std::vector& ind) : indices(ind){} virtual ~PointCollector(){} - virtual void Append(const MeshCore::MeshKernel& kernel, unsigned long index) + virtual void Append(const MeshCore::MeshKernel& kernel, FacetIndex index) { - unsigned long ulP1, ulP2, ulP3; + PointIndex ulP1, ulP2, ulP3; kernel.GetFacetPoints(index, ulP1, ulP2, ulP3); indices.push_back(ulP1); indices.push_back(ulP2); @@ -345,21 +345,21 @@ public: } private: - std::vector& indices; + std::vector& indices; }; class MeshExport FacetCollector : public MeshCollector { public: - FacetCollector(std::vector& ind) : indices(ind){} + FacetCollector(std::vector& ind) : indices(ind){} virtual ~FacetCollector(){} - void Append(const MeshCore::MeshKernel&, unsigned long index) + void Append(const MeshCore::MeshKernel&, FacetIndex index) { indices.push_back(index); } private: - std::vector& indices; + std::vector& indices; }; /** @@ -375,30 +375,30 @@ public: MeshRefPointToFacets (const MeshKernel &rclM) : _rclMesh(rclM) { Rebuild(); } /// Destruction - ~MeshRefPointToFacets (void) + ~MeshRefPointToFacets () { } /// Rebuilds up data structure - void Rebuild (void); - const std::set& operator[] (unsigned long) const; - std::vector GetIndices(unsigned long, unsigned long) const; - std::vector GetIndices(unsigned long, unsigned long, unsigned long) const; - MeshFacetArray::_TConstIterator GetFacet (unsigned long) const; - std::set NeighbourPoints(const std::vector& , int level) const; - std::set NeighbourPoints(unsigned long) const; - void Neighbours (unsigned long ulFacetInd, float fMaxDist, MeshCollector& collect) const; - Base::Vector3f GetNormal(unsigned long) const; - void AddNeighbour(unsigned long, unsigned long); - void RemoveNeighbour(unsigned long, unsigned long); - void RemoveFacet(unsigned long); + void Rebuild (); + const std::set& operator[] (PointIndex) const; + std::vector GetIndices(PointIndex, PointIndex) const; + std::vector GetIndices(PointIndex, PointIndex, PointIndex) const; + MeshFacetArray::_TConstIterator GetFacet (FacetIndex) const; + std::set NeighbourPoints(const std::vector& , int level) const; + std::set NeighbourPoints(PointIndex) const; + void Neighbours (FacetIndex ulFacetInd, float fMaxDist, MeshCollector& collect) const; + Base::Vector3f GetNormal(PointIndex) const; + void AddNeighbour(PointIndex, FacetIndex); + void RemoveNeighbour(PointIndex, FacetIndex); + void RemoveFacet(FacetIndex); protected: - void SearchNeighbours(const MeshFacetArray& rFacets, unsigned long index, const Base::Vector3f &rclCenter, - float fMaxDist, std::set &visit, MeshCollector& collect) const; + void SearchNeighbours(const MeshFacetArray& rFacets, FacetIndex index, const Base::Vector3f &rclCenter, + float fMaxDist, std::set &visit, MeshCollector& collect) const; protected: const MeshKernel &_rclMesh; /**< The mesh kernel. */ - std::vector > _map; + std::vector > _map; }; /** @@ -414,20 +414,20 @@ public: MeshRefFacetToFacets (const MeshKernel &rclM) : _rclMesh(rclM) { Rebuild(); } /// Destruction - ~MeshRefFacetToFacets (void) + ~MeshRefFacetToFacets () { } /// Rebuilds up data structure - void Rebuild (void); + void Rebuild (); /// Returns a set of facets sharing one or more points with the facet with /// index \a ulFacetIndex. - const std::set& operator[] (unsigned long) const; + const std::set& operator[] (FacetIndex) const; /// Returns an array of common facets of the passed facet indexes. - std::vector GetIndices(unsigned long, unsigned long) const; + std::vector GetIndices(FacetIndex, FacetIndex) const; protected: const MeshKernel &_rclMesh; /**< The mesh kernel. */ - std::vector > _map; + std::vector > _map; }; /** @@ -443,20 +443,20 @@ public: MeshRefPointToPoints (const MeshKernel &rclM) : _rclMesh(rclM) { Rebuild(); } /// Destruction - ~MeshRefPointToPoints (void) + ~MeshRefPointToPoints () { } /// Rebuilds up data structure - void Rebuild (void); - const std::set& operator[] (unsigned long) const; - Base::Vector3f GetNormal(unsigned long) const; - float GetAverageEdgeLength(unsigned long) const; - void AddNeighbour(unsigned long, unsigned long); - void RemoveNeighbour(unsigned long, unsigned long); + void Rebuild (); + const std::set& operator[] (PointIndex) const; + Base::Vector3f GetNormal(PointIndex) const; + float GetAverageEdgeLength(PointIndex) const; + void AddNeighbour(PointIndex, PointIndex); + void RemoveNeighbour(PointIndex, PointIndex); protected: const MeshKernel &_rclMesh; /**< The mesh kernel. */ - std::vector > _map; + std::vector > _map; }; /** @@ -472,12 +472,12 @@ public: MeshRefEdgeToFacets (const MeshKernel &rclM) : _rclMesh(rclM) { Rebuild(); } /// Destruction - ~MeshRefEdgeToFacets (void) + ~MeshRefEdgeToFacets () { } /// Rebuilds up data structure - void Rebuild (void); - const std::pair& operator[] (const MeshEdge&) const; + void Rebuild (); + const std::pair& operator[] (const MeshEdge&) const; protected: class EdgeOrder { @@ -494,7 +494,7 @@ protected: return false; } }; - typedef std::pair MeshFacetPair; + typedef std::pair MeshFacetPair; const MeshKernel &_rclMesh; /**< The mesh kernel. */ std::map _map; }; @@ -511,12 +511,12 @@ public: MeshRefNormalToPoints (const MeshKernel &rclM) : _rclMesh(rclM) { Rebuild(); } /// Destruction - ~MeshRefNormalToPoints (void) + ~MeshRefNormalToPoints () { } /// Rebuilds up data structure - void Rebuild (void); - const Base::Vector3f& operator[] (unsigned long) const; + void Rebuild (); + const Base::Vector3f& operator[] (PointIndex) const; protected: const MeshKernel &_rclMesh; /**< The mesh kernel. */ diff --git a/src/Mod/Mesh/App/Core/Approximation.cpp b/src/Mod/Mesh/App/Core/Approximation.cpp index 19fe054100..e8aa9e3148 100644 --- a/src/Mod/Mesh/App/Core/Approximation.cpp +++ b/src/Mod/Mesh/App/Core/Approximation.cpp @@ -117,7 +117,7 @@ Base::Vector3f Approximation::GetGravity() const return clGravity; } -unsigned long Approximation::CountPoints() const +std::size_t Approximation::CountPoints() const { return _vPoints.size(); } @@ -418,7 +418,7 @@ Base::BoundBox3f PlaneFit::GetBoundings() const { Base::BoundBox3f bbox; std::vector pts = GetLocalPoints(); - for (auto it : pts) + for (const auto& it : pts) bbox.Add(it); return bbox; } @@ -462,7 +462,7 @@ const double& QuadraticFit::GetCoeffArray() const return _fCoeff[0]; } -double QuadraticFit::GetCoeff(unsigned long ulIndex) const +double QuadraticFit::GetCoeff(std::size_t ulIndex) const { assert(ulIndex < 10); diff --git a/src/Mod/Mesh/App/Core/Approximation.h b/src/Mod/Mesh/App/Core/Approximation.h index cd71e568fb..99d73be059 100644 --- a/src/Mod/Mesh/App/Core/Approximation.h +++ b/src/Mod/Mesh/App/Core/Approximation.h @@ -147,7 +147,7 @@ public: * Determines the number of the current added points. * @return Number of points */ - unsigned long CountPoints() const; + std::size_t CountPoints() const; /** * Deletes the inserted points and frees any allocated resources. */ @@ -280,7 +280,7 @@ public: * @param ulIndex Number of coefficient (0..9) * @return double value of coefficient */ - double GetCoeff(unsigned long ulIndex) const; + double GetCoeff(std::size_t ulIndex) const; /** * Get the quadric coefficients as reference to the * internal array diff --git a/src/Mod/Mesh/App/Core/Builder.cpp b/src/Mod/Mesh/App/Core/Builder.cpp index db5a6271f5..e32a2bfcf8 100644 --- a/src/Mod/Mesh/App/Core/Builder.cpp +++ b/src/Mod/Mesh/App/Core/Builder.cpp @@ -38,12 +38,12 @@ using namespace MeshCore; -MeshBuilder::MeshBuilder (MeshKernel& kernel) : _meshKernel(kernel), _seq(0), _ptIdx(0) +MeshBuilder::MeshBuilder (MeshKernel& kernel) : _meshKernel(kernel), _seq(nullptr), _ptIdx(0) { _fSaveTolerance = MeshDefinitions::_fMinPointDistanceD1; } -MeshBuilder::~MeshBuilder (void) +MeshBuilder::~MeshBuilder () { MeshDefinitions::_fMinPointDistanceD1 = _fSaveTolerance; delete this->_seq; @@ -156,7 +156,7 @@ void MeshBuilder::AddFacet (Base::Vector3f* facetPoints, unsigned char flag, uns void MeshBuilder::SetNeighbourhood () { std::set edges; - unsigned long facetIdx = 0; + FacetIndex facetIdx = 0; for (MeshFacetArray::_TIterator it = _meshKernel._aclFacetArray.begin(); it != _meshKernel._aclFacetArray.end(); ++it) { @@ -218,7 +218,7 @@ void MeshBuilder::RemoveUnreferencedPoints() void MeshBuilder::Finish (bool freeMemory) { // now we can resize the vertex array to the exact size and copy the vertices with their correct positions in the array - unsigned long i=0; + PointIndex i=0; _meshKernel._aclPointArray.resize(_pointsIterator.size()); for ( std::vector::iterator it = _pointsIterator.begin(); it != _pointsIterator.end(); ++it) _meshKernel._aclPointArray[i++] = *(it->first); @@ -244,7 +244,7 @@ void MeshBuilder::Finish (bool freeMemory) if ( cap > siz+siz/20 ) { try { - unsigned long i=0; + FacetIndex i=0; MeshFacetArray faces(siz); for ( MeshFacetArray::_TIterator it = _meshKernel._aclFacetArray.begin(); it != _meshKernel._aclFacetArray.end(); ++it ) faces[i++]=*it; @@ -290,7 +290,7 @@ MeshFastBuilder::MeshFastBuilder(MeshKernel &rclM) : _meshKernel(rclM), p(new Pr { } -MeshFastBuilder::~MeshFastBuilder(void) +MeshFastBuilder::~MeshFastBuilder() { delete p; } @@ -335,18 +335,18 @@ void MeshFastBuilder::Finish () int threads = std::max(1, QThread::idealThreadCount()); MeshCore::parallel_sort(verts.begin(), verts.end(), std::less(), threads); - QVector indices(ulCtPts); + QVector indices(ulCtPts); size_type vertex_count = 0; for (QVector::iterator v = verts.begin(); v != verts.end(); ++v) { if (!vertex_count || *v != verts[vertex_count-1]) verts[vertex_count++] = *v; - indices[v->i] = static_cast(vertex_count - 1); + indices[v->i] = static_cast(vertex_count - 1); } size_type ulCt = verts.size()/3; - MeshFacetArray rFacets(static_cast(ulCt)); + MeshFacetArray rFacets(static_cast(ulCt)); for (size_type i=0; i < ulCt; ++i) { rFacets[static_cast(i)]._aulPoints[0] = indices[3*i]; rFacets[static_cast(i)]._aulPoints[1] = indices[3*i + 1]; diff --git a/src/Mod/Mesh/App/Core/Builder.h b/src/Mod/Mesh/App/Core/Builder.h index 65d24649d1..81415b1d56 100644 --- a/src/Mod/Mesh/App/Core/Builder.h +++ b/src/Mod/Mesh/App/Core/Builder.h @@ -64,9 +64,11 @@ private: class Edge { public: - unsigned long pt1, pt2, facetIdx; + PointIndex pt1; + PointIndex pt2; + FacetIndex facetIdx; - Edge (unsigned long p1, unsigned long p2, unsigned long idx) + Edge (PointIndex p1, PointIndex p2, FacetIndex idx) { facetIdx = idx; if (p1 > p2) @@ -113,7 +115,7 @@ private: public: MeshBuilder(MeshKernel &rclM); - ~MeshBuilder(void); + ~MeshBuilder(); /** * Set the tolerance for the comparison of points. Normally you don't need to set the tolerance. @@ -189,7 +191,7 @@ private: public: typedef int size_type; MeshFastBuilder(MeshKernel &rclM); - ~MeshFastBuilder(void); + ~MeshFastBuilder(); /** Initializes the class. Must be done before adding facets * @param ctFacets count of facets. diff --git a/src/Mod/Mesh/App/Core/Curvature.cpp b/src/Mod/Mesh/App/Core/Curvature.cpp index 4507363fc7..6f29347191 100644 --- a/src/Mod/Mesh/App/Core/Curvature.cpp +++ b/src/Mod/Mesh/App/Core/Curvature.cpp @@ -54,10 +54,10 @@ MeshCurvature::MeshCurvature(const MeshKernel& kernel) : myKernel(kernel), myMinPoints(20), myRadius(0.5f) { mySegment.resize(kernel.CountFacets()); - std::generate(mySegment.begin(), mySegment.end(), Base::iotaGen(0)); + std::generate(mySegment.begin(), mySegment.end(), Base::iotaGen(0)); } -MeshCurvature::MeshCurvature(const MeshKernel& kernel, const std::vector& segm) +MeshCurvature::MeshCurvature(const MeshKernel& kernel, const std::vector& segm) : myKernel(kernel), myMinPoints(20), myRadius(0.5f), mySegment(segm) { } @@ -72,7 +72,7 @@ void MeshCurvature::ComputePerFace(bool parallel) if (!parallel) { Base::SequencerLauncher seq("Curvature estimation", mySegment.size()); - for (std::vector::iterator it = mySegment.begin(); it != mySegment.end(); ++it) { + for (std::vector::iterator it = mySegment.begin(); it != mySegment.end(); ++it) { CurvatureInfo info = face.Compute(*it); myCurvature.push_back(info); seq.next(); @@ -343,10 +343,10 @@ namespace MeshCore { class FitPointCollector : public MeshCollector { public: - FitPointCollector(std::set& ind) : indices(ind){} - virtual void Append(const MeshCore::MeshKernel& kernel, unsigned long index) + FitPointCollector(std::set& ind) : indices(ind){} + virtual void Append(const MeshCore::MeshKernel& kernel, FacetIndex index) { - unsigned long ulP1, ulP2, ulP3; + PointIndex ulP1, ulP2, ulP3; kernel.GetFacetPoints(index, ulP1, ulP2, ulP3); indices.insert(ulP1); indices.insert(ulP2); @@ -354,7 +354,7 @@ public: } private: - std::set& indices; + std::set& indices; }; } @@ -365,15 +365,15 @@ FacetCurvature::FacetCurvature(const MeshKernel& kernel, const MeshRefPointToFac { } -CurvatureInfo FacetCurvature::Compute(unsigned long index) const +CurvatureInfo FacetCurvature::Compute(FacetIndex index) const { - Base::Vector3f rkDir0, rkDir1, rkPnt; + Base::Vector3f rkDir0, rkDir1; Base::Vector3f rkNormal; MeshGeomFacet face = myKernel.GetFacet(index); Base::Vector3f face_gravity = face.GetGravityPoint(); Base::Vector3f face_normal = face.GetNormal(); - std::set point_indices; + std::set point_indices; FitPointCollector collect(point_indices); float searchDist = myRadius; @@ -391,7 +391,7 @@ CurvatureInfo FacetCurvature::Compute(unsigned long index) const std::vector fitPoints; const MeshPointArray& verts = myKernel.GetPoints(); fitPoints.reserve(point_indices.size()); - for (std::set::iterator it = point_indices.begin(); it != point_indices.end(); ++it) { + for (std::set::iterator it = point_indices.begin(); it != point_indices.end(); ++it) { fitPoints.push_back(verts[*it] - face_gravity); } diff --git a/src/Mod/Mesh/App/Core/Curvature.h b/src/Mod/Mesh/App/Core/Curvature.h index 7c200946a4..2e3bc6e63b 100644 --- a/src/Mod/Mesh/App/Core/Curvature.h +++ b/src/Mod/Mesh/App/Core/Curvature.h @@ -25,6 +25,7 @@ #include #include +#include "Definitions.h" namespace MeshCore { @@ -42,7 +43,7 @@ class MeshExport FacetCurvature { public: FacetCurvature(const MeshKernel& kernel, const MeshRefPointToFacets& search, float, unsigned long); - CurvatureInfo Compute(unsigned long index) const; + CurvatureInfo Compute(FacetIndex index) const; private: const MeshKernel& myKernel; @@ -55,7 +56,7 @@ class MeshExport MeshCurvature { public: MeshCurvature(const MeshKernel& kernel); - MeshCurvature(const MeshKernel& kernel, const std::vector& segm); + MeshCurvature(const MeshKernel& kernel, const std::vector& segm); float GetRadius() const { return myRadius; } void SetRadius(float r) { myRadius = r; } void ComputePerFace(bool parallel); @@ -66,7 +67,7 @@ private: const MeshKernel& myKernel; unsigned long myMinPoints; float myRadius; - std::vector mySegment; + std::vector mySegment; std::vector myCurvature; }; diff --git a/src/Mod/Mesh/App/Core/Definitions.cpp b/src/Mod/Mesh/App/Core/Definitions.cpp index 2c1b2819f2..5c0f66290b 100644 --- a/src/Mod/Mesh/App/Core/Definitions.cpp +++ b/src/Mod/Mesh/App/Core/Definitions.cpp @@ -40,7 +40,7 @@ float MeshDefinitions::_fMinEdgeLength = MESH_MIN_EDGE_LEN; bool MeshDefinitions::_bRemoveMinLength = MESH_REMOVE_MIN_LEN; float MeshDefinitions::_fMinEdgeAngle = Base::toRadians(MESH_MIN_EDGE_ANGLE); -MeshDefinitions::MeshDefinitions (void) +MeshDefinitions::MeshDefinitions () { } diff --git a/src/Mod/Mesh/App/Core/Definitions.h b/src/Mod/Mesh/App/Core/Definitions.h index 0aadd101db..4745a015da 100644 --- a/src/Mod/Mesh/App/Core/Definitions.h +++ b/src/Mod/Mesh/App/Core/Definitions.h @@ -28,6 +28,8 @@ #include #endif +#include + // default values #define MESH_MIN_PT_DIST 1.0e-6f #define MESH_MIN_EDGE_LEN 1.0e-3f @@ -54,6 +56,14 @@ namespace MeshCore { +// type definitions +using ElementIndex = unsigned long; +const ElementIndex ELEMENT_INDEX_MAX = ULONG_MAX; +using FacetIndex = ElementIndex; +const FacetIndex FACET_INDEX_MAX = ULONG_MAX; +using PointIndex = ElementIndex; +const PointIndex POINT_INDEX_MAX = ULONG_MAX; + template class Math { @@ -71,8 +81,8 @@ typedef Math Mathd; class MeshExport MeshDefinitions { public: - MeshDefinitions (void); - virtual ~MeshDefinitions (void) + MeshDefinitions (); + virtual ~MeshDefinitions () {} static float _fMinPointDistance; diff --git a/src/Mod/Mesh/App/Core/Degeneration.cpp b/src/Mod/Mesh/App/Core/Degeneration.cpp index 261c30c452..96f8a6b74b 100644 --- a/src/Mod/Mesh/App/Core/Degeneration.cpp +++ b/src/Mod/Mesh/App/Core/Degeneration.cpp @@ -63,12 +63,12 @@ bool MeshEvalInvalids::Evaluate() return true; } -std::vector MeshEvalInvalids::GetIndices() const +std::vector MeshEvalInvalids::GetIndices() const { - std::vector aInds; + std::vector aInds; const MeshFacetArray& rFaces = _rclMesh.GetFacets(); const MeshPointArray& rPoints = _rclMesh.GetPoints(); - unsigned long ind=0; + FacetIndex ind=0; for ( MeshFacetArray::_TConstIterator it = rFaces.begin(); it != rFaces.end(); ++it, ind++ ) { if ( !it->IsValid() ) @@ -144,7 +144,7 @@ bool MeshEvalDuplicatePoints::Evaluate() return true; } -std::vector MeshEvalDuplicatePoints::GetIndices() const +std::vector MeshEvalDuplicatePoints::GetIndices() const { //Note: We must neither use map or set to get duplicated indices because //the sort algorithms deliver different results compared to std::sort of @@ -157,7 +157,7 @@ std::vector MeshEvalDuplicatePoints::GetIndices() const } // if there are two adjacent vertices which have the same coordinates - std::vector aInds; + std::vector aInds; Vertex_EqualTo pred; std::sort(vertices.begin(), vertices.end(), Vertex_Less()); @@ -187,21 +187,20 @@ bool MeshFixDuplicatePoints::Fixup() } // get the indices of adjacent vertices which have the same coordinates - std::vector aInds; std::sort(vertices.begin(), vertices.end(), Vertex_Less()); Vertex_EqualTo pred; std::vector::iterator next = vertices.begin(); - std::map mapPointIndex; - std::vector pointIndices; + std::map mapPointIndex; + std::vector pointIndices; while (next < vertices.end()) { next = std::adjacent_find(next, vertices.end(), pred); if (next < vertices.end()) { std::vector::iterator first = next; - unsigned long first_index = *first - rPoints.begin(); + PointIndex first_index = *first - rPoints.begin(); ++next; while (next < vertices.end() && pred(*first, *next)) { - unsigned long next_index = *next - rPoints.begin(); + PointIndex next_index = *next - rPoints.begin(); mapPointIndex[next_index] = first_index; pointIndices.push_back(next_index); ++next; @@ -213,7 +212,7 @@ bool MeshFixDuplicatePoints::Fixup() MeshFacetArray& rFacets = _rclMesh._aclFacetArray; for (MeshFacetArray::_TIterator it = rFacets.begin(); it != rFacets.end(); ++it) { for (int i=0; i<3; i++) { - std::map::iterator pt = mapPointIndex.find(it->_aulPoints[i]); + std::map::iterator pt = mapPointIndex.find(it->_aulPoints[i]); if (pt != mapPointIndex.end()) it->_aulPoints[i] = pt->second; } @@ -239,9 +238,9 @@ bool MeshEvalNaNPoints::Evaluate() return true; } -std::vector MeshEvalNaNPoints::GetIndices() const +std::vector MeshEvalNaNPoints::GetIndices() const { - std::vector aInds; + std::vector aInds; const MeshPointArray& rPoints = _rclMesh.GetPoints(); for (MeshPointArray::_TConstIterator it = rPoints.begin(); it != rPoints.end(); ++it) { if (boost::math::isnan(it->x) || boost::math::isnan(it->y) || boost::math::isnan(it->z)) @@ -253,7 +252,7 @@ std::vector MeshEvalNaNPoints::GetIndices() const bool MeshFixNaNPoints::Fixup() { - std::vector aInds; + std::vector aInds; const MeshPointArray& rPoints = _rclMesh.GetPoints(); for (MeshPointArray::_TConstIterator it = rPoints.begin(); it != rPoints.end(); ++it) { if (boost::math::isnan(it->x) || boost::math::isnan(it->y) || boost::math::isnan(it->z)) @@ -280,13 +279,13 @@ struct MeshFacet_Less bool operator()(const FaceIterator& x, const FaceIterator& y) const { - unsigned long tmp; - unsigned long x0 = x->_aulPoints[0]; - unsigned long x1 = x->_aulPoints[1]; - unsigned long x2 = x->_aulPoints[2]; - unsigned long y0 = y->_aulPoints[0]; - unsigned long y1 = y->_aulPoints[1]; - unsigned long y2 = y->_aulPoints[2]; + PointIndex tmp; + PointIndex x0 = x->_aulPoints[0]; + PointIndex x1 = x->_aulPoints[1]; + PointIndex x2 = x->_aulPoints[2]; + PointIndex y0 = y->_aulPoints[0]; + PointIndex y1 = y->_aulPoints[1]; + PointIndex y2 = y->_aulPoints[2]; if (x0 > x1) { tmp = x0; x0 = x1; x1 = tmp; } @@ -351,7 +350,7 @@ bool MeshEvalDuplicateFacets::Evaluate() return true; } -std::vector MeshEvalDuplicateFacets::GetIndices() const +std::vector MeshEvalDuplicateFacets::GetIndices() const { #if 1 const MeshFacetArray& rFacets = _rclMesh.GetFacets(); @@ -362,7 +361,7 @@ std::vector MeshEvalDuplicateFacets::GetIndices() const } // if there are two adjacent faces which references the same vertices - std::vector aInds; + std::vector aInds; MeshFacet_EqualTo pred; std::sort(faces.begin(), faces.end(), MeshFacet_Less()); @@ -378,9 +377,9 @@ std::vector MeshEvalDuplicateFacets::GetIndices() const return aInds; #else - std::vector aInds; + std::vector aInds; const MeshFacetArray& rFaces = _rclMesh.GetFacets(); - unsigned long uIndex=0; + FacetIndex uIndex=0; // get all facets std::set aFaceSet; @@ -398,8 +397,8 @@ std::vector MeshEvalDuplicateFacets::GetIndices() const bool MeshFixDuplicateFacets::Fixup() { - unsigned long uIndex=0; - std::vector aRemoveFaces; + FacetIndex uIndex=0; + std::vector aRemoveFaces; const MeshFacetArray& rFaces = _rclMesh.GetFacets(); // get all facets @@ -422,7 +421,7 @@ bool MeshFixDuplicateFacets::Fixup() bool MeshEvalInternalFacets::Evaluate() { _indices.clear(); - unsigned long uIndex=0; + FacetIndex uIndex=0; const MeshFacetArray& rFaces = _rclMesh.GetFacets(); // get all facets @@ -470,9 +469,9 @@ unsigned long MeshEvalDegeneratedFacets::CountEdgeTooSmall (float fMinEdgeLength return k; } -std::vector MeshEvalDegeneratedFacets::GetIndices() const +std::vector MeshEvalDegeneratedFacets::GetIndices() const { - std::vector aInds; + std::vector aInds; MeshFacetIterator it(_rclMesh); for (it.Init(); it.More(); it.Next()) { if (it->IsDegenerated(fEpsilon)) @@ -489,10 +488,9 @@ bool MeshFixDegeneratedFacets::Fixup() MeshFacetIterator it(_rclMesh); for (it.Init(); it.More(); it.Next()) { if (it->IsDegenerated(fEpsilon)) { - unsigned long uCt = _rclMesh.CountFacets(); - unsigned long uId = it.Position(); - cTopAlg.RemoveDegeneratedFacet(uId); - if (uCt != _rclMesh.CountFacets()) { + FacetIndex uId = it.Position(); + bool removed = cTopAlg.RemoveDegeneratedFacet(uId); + if (removed) { // due to a modification of the array the iterator became invalid it.Set(uId-1); } @@ -562,18 +560,18 @@ bool MeshRemoveNeedles::Fixup() ce._toPoint = rclFAry[faceedge.first]._aulPoints[(faceedge.second+1)%3]; ce._removeFacets.push_back(faceedge.first); - unsigned long neighbour = rclFAry[faceedge.first]._aulNeighbours[faceedge.second]; - if (neighbour != ULONG_MAX) + FacetIndex neighbour = rclFAry[faceedge.first]._aulNeighbours[faceedge.second]; + if (neighbour != FACET_INDEX_MAX) ce._removeFacets.push_back(neighbour); - std::set vf = vf_it[ce._fromPoint]; + std::set vf = vf_it[ce._fromPoint]; vf.erase(faceedge.first); - if (neighbour != ULONG_MAX) + if (neighbour != FACET_INDEX_MAX) vf.erase(neighbour); ce._changeFacets.insert(ce._changeFacets.begin(), vf.begin(), vf.end()); // get adjacent points - std::set vv; + std::set vv; vv = vf_it.NeighbourPoints(ce._fromPoint); ce._adjacentFrom.insert(ce._adjacentFrom.begin(), vv.begin(),vv.end()); vv = vf_it.NeighbourPoints(ce._toPoint); @@ -598,98 +596,6 @@ bool MeshRemoveNeedles::Fixup() } return true; -#if 0 - unsigned long ulCtLastLoop, ulCtFacets = _rclMesh.CountFacets(); - - const MeshFacetArray &rclFAry = _rclMesh.GetFacets(); - const MeshPointArray &rclPAry = _rclMesh.GetPoints(); - MeshFacetArray::_TConstIterator f_beg = rclFAry.begin(); - - // repeat until no facet can be removed - do { - MeshRefPointToFacets clPt2Facets(_rclMesh); - - rclFAry.ResetInvalid(); - rclPAry.ResetInvalid(); - rclPAry.ResetFlag(MeshPoint::VISIT); - - std::set > aclPtDelList; - - MeshFacetIterator clFIter(_rclMesh); - for (clFIter.Init(); clFIter.More(); clFIter.Next()) { - MeshGeomFacet clSFacet = *clFIter; - Base::Vector3f clP0 = clSFacet._aclPoints[0]; - Base::Vector3f clP1 = clSFacet._aclPoints[1]; - Base::Vector3f clP2 = clSFacet._aclPoints[2]; - Base::Vector3f clE01 = clP1 - clP0; - Base::Vector3f clE12 = clP2 - clP1; - Base::Vector3f clE20 = clP2 - clP0; - MeshFacet clFacet = clFIter.GetIndices(); - unsigned long ulP0 = clFacet._aulPoints[0]; - unsigned long ulP1 = clFacet._aulPoints[1]; - unsigned long ulP2 = clFacet._aulPoints[2]; - - if (Base::Distance(clP0, clP1) < fMinEdgeLength) { - // delete point P1 on P0 - aclPtDelList.insert(std::make_pair - (std::min(ulP1, ulP0), std::max(ulP1, ulP0))); - clFIter.SetFlag(MeshFacet::INVALID); - } - else if (Base::Distance(clP1, clP2) < fMinEdgeLength) { - // delete point P2 on P1 - aclPtDelList.insert(std::make_pair - (std::min(ulP2, ulP1), std::max(ulP2, ulP1))); - clFIter.SetFlag(MeshFacet::INVALID); - } - else if (Base::Distance(clP2, clP0) < fMinEdgeLength) { - // delete point P0 on P2 - aclPtDelList.insert(std::make_pair - (std::min(ulP0, ulP2), std::max(ulP0, ulP2))); - clFIter.SetFlag(MeshFacet::INVALID); - } - } -#if 0 - // remove points, fix indices - for (std::set >::iterator pI = aclPtDelList.begin(); - pI != aclPtDelList.end(); ++pI) { - // one of the point pairs is already processed - if ((rclPAry[pI->first].IsFlag(MeshPoint::VISIT) == true) || - (rclPAry[pI->second].IsFlag(MeshPoint::VISIT) == true)) - continue; - - rclPAry[pI->first].SetFlag(MeshPoint::VISIT); - rclPAry[pI->second].SetFlag(MeshPoint::VISIT); - rclPAry[pI->second].SetInvalid(); - - // Redirect all point-indices to the new neighbour point of all facets referencing the - // deleted point - const std::set& faces = clPt2Facets[pI->second]; - for (std::set::const_iterator pF = faces.begin(); pF != faces.end(); ++pF) { - const MeshFacet &rclF = f_beg[*pF]; - - for (int i = 0; i < 3; i++) { -// if (rclF._aulPoints[i] == pI->second) -// rclF._aulPoints[i] = pI->first; - } - - // Delete facets with two identical corners - if ((rclF._aulPoints[0] == rclF._aulPoints[1]) || - (rclF._aulPoints[0] == rclF._aulPoints[2]) || - (rclF._aulPoints[1] == rclF._aulPoints[2])) { - rclF.SetInvalid(); - } - } - } -#endif - ulCtLastLoop = _rclMesh.CountFacets(); - _rclMesh.RemoveInvalids(); - } - while (ulCtLastLoop > _rclMesh.CountFacets()); - - _rclMesh.RebuildNeighbours(); - - return ulCtFacets > _rclMesh.CountFacets(); -#endif } // ---------------------------------------------------------------------- @@ -754,9 +660,9 @@ bool MeshFixCaps::Fixup() if (distP2P4/distP2P3 < fSplitFactor || distP3P4/distP2P3 < fSplitFactor) continue; - unsigned long facetpos = facevertex.first; - unsigned long neighbour = rclFAry[facetpos]._aulNeighbours[(facevertex.second+1)%3]; - if (neighbour != ULONG_MAX) + FacetIndex facetpos = facevertex.first; + FacetIndex neighbour = rclFAry[facetpos]._aulNeighbours[(facevertex.second+1)%3]; + if (neighbour != FACET_INDEX_MAX) topAlg.SwapEdge(facetpos, neighbour); } @@ -779,12 +685,12 @@ bool MeshEvalDeformedFacets::Evaluate() return true; } -std::vector MeshEvalDeformedFacets::GetIndices() const +std::vector MeshEvalDeformedFacets::GetIndices() const { float fCosMinAngle = cos(fMinAngle); float fCosMaxAngle = cos(fMaxAngle); - std::vector aInds; + std::vector aInds; MeshFacetIterator it(_rclMesh); for (it.Init(); it.More(); it.Next()) { if (it->IsDeformed(fCosMinAngle, fCosMaxAngle)) @@ -825,8 +731,8 @@ bool MeshFixDeformedFacets::Fixup() float fCosAngle = fCosAngles[i]; if (fCosAngle < fCosMaxAngle) { const MeshFacet& face = it.GetReference(); - unsigned long uNeighbour = face._aulNeighbours[(i+1)%3]; - if (uNeighbour!=ULONG_MAX && cTopAlg.ShouldSwapEdge(it.Position(), uNeighbour, fMaxSwapAngle)) { + FacetIndex uNeighbour = face._aulNeighbours[(i+1)%3]; + if (uNeighbour!=FACET_INDEX_MAX && cTopAlg.ShouldSwapEdge(it.Position(), uNeighbour, fMaxSwapAngle)) { cTopAlg.SwapEdge(it.Position(), uNeighbour); done = true; } @@ -844,14 +750,14 @@ bool MeshFixDeformedFacets::Fixup() if (fCosAngle > fCosMinAngle) { const MeshFacet& face = it.GetReference(); - unsigned long uNeighbour = face._aulNeighbours[j]; - if (uNeighbour!=ULONG_MAX && cTopAlg.ShouldSwapEdge(it.Position(), uNeighbour, fMaxSwapAngle)) { + FacetIndex uNeighbour = face._aulNeighbours[j]; + if (uNeighbour!=FACET_INDEX_MAX && cTopAlg.ShouldSwapEdge(it.Position(), uNeighbour, fMaxSwapAngle)) { cTopAlg.SwapEdge(it.Position(), uNeighbour); break; } uNeighbour = face._aulNeighbours[(j+2)%3]; - if (uNeighbour!=ULONG_MAX && cTopAlg.ShouldSwapEdge(it.Position(), uNeighbour, fMaxSwapAngle)) { + if (uNeighbour!=FACET_INDEX_MAX && cTopAlg.ShouldSwapEdge(it.Position(), uNeighbour, fMaxSwapAngle)) { cTopAlg.SwapEdge(it.Position(), uNeighbour); break; } @@ -879,9 +785,9 @@ bool MeshFixMergeFacets::Fixup() if (vv_it[i].size() == 3 && vf_it[i].size() == 3) { VertexCollapse vc; vc._point = i; - const std::set& adjPts = vv_it[i]; + const std::set& adjPts = vv_it[i]; vc._circumPoints.insert(vc._circumPoints.begin(), adjPts.begin(), adjPts.end()); - const std::set& adjFts = vf_it[i]; + const std::set& adjFts = vf_it[i]; vc._circumFacets.insert(vc._circumFacets.begin(), adjFts.begin(), adjFts.end()); topAlg.CollapseVertex(vc); } @@ -904,16 +810,16 @@ bool MeshEvalDentsOnSurface::Evaluate() Base::Vector3f tmp; unsigned long ctPoints = _rclMesh.CountPoints(); for (unsigned long index=0; index < ctPoints; index++) { - std::vector point; + std::vector point; point.push_back(index); // get the local neighbourhood of the point - std::set nb = clPt2Facets.NeighbourPoints(point,1); - const std::set& faces = clPt2Facets[index]; + std::set nb = clPt2Facets.NeighbourPoints(point,1); + const std::set& faces = clPt2Facets[index]; - for (std::set::iterator pt = nb.begin(); pt != nb.end(); ++pt) { + for (std::set::iterator pt = nb.begin(); pt != nb.end(); ++pt) { const MeshPoint& mp = rPntAry[*pt]; - for (std::set::const_iterator + for (std::set::const_iterator ft = faces.begin(); ft != faces.end(); ++ft) { // the point must not be part of the facet we test if (f_beg[*ft]._aulPoints[0] == *pt) @@ -925,7 +831,7 @@ bool MeshEvalDentsOnSurface::Evaluate() // is the point projectable onto the facet? rTriangle = _rclMesh.GetFacet(f_beg[*ft]); if (rTriangle.IntersectWithLine(mp,rTriangle.GetNormal(),tmp)) { - const std::set& f = clPt2Facets[*pt]; + const std::set& f = clPt2Facets[*pt]; this->indices.insert(this->indices.end(), f.begin(), f.end()); break; } @@ -941,7 +847,7 @@ bool MeshEvalDentsOnSurface::Evaluate() return this->indices.empty(); } -std::vector MeshEvalDentsOnSurface::GetIndices() const +std::vector MeshEvalDentsOnSurface::GetIndices() const { return this->indices; } @@ -961,7 +867,7 @@ bool MeshFixDentsOnSurface::Fixup() { MeshEvalDentsOnSurface eval(_rclMesh); if (!eval.Evaluate()) { - std::vector inds = eval.GetIndices(); + std::vector inds = eval.GetIndices(); _rclMesh.DeleteFacets(inds); } @@ -977,10 +883,10 @@ bool MeshEvalFoldsOnSurface::Evaluate() unsigned long ct=0; for (MeshFacetArray::const_iterator it = rFAry.begin(); it != rFAry.end(); ++it, ct++) { for (int i=0; i<3; i++) { - unsigned long n1 = it->_aulNeighbours[i]; - unsigned long n2 = it->_aulNeighbours[(i+1)%3]; + FacetIndex n1 = it->_aulNeighbours[i]; + FacetIndex n2 = it->_aulNeighbours[(i+1)%3]; Base::Vector3f v1 =_rclMesh.GetFacet(*it).GetNormal(); - if (n1 != ULONG_MAX && n2 != ULONG_MAX) { + if (n1 != FACET_INDEX_MAX && n2 != FACET_INDEX_MAX) { Base::Vector3f v2 = _rclMesh.GetFacet(n1).GetNormal(); Base::Vector3f v3 = _rclMesh.GetFacet(n2).GetNormal(); if (v2 * v3 > 0.0f) { @@ -1001,7 +907,7 @@ bool MeshEvalFoldsOnSurface::Evaluate() return this->indices.empty(); } -std::vector MeshEvalFoldsOnSurface::GetIndices() const +std::vector MeshEvalFoldsOnSurface::GetIndices() const { return this->indices; } @@ -1017,7 +923,7 @@ bool MeshEvalFoldsOnBoundary::Evaluate() for (MeshFacetArray::_TConstIterator it = rFacAry.begin(); it != rFacAry.end(); ++it) { if (it->CountOpenEdges() == 2) { for (int i=0; i<3; i++) { - if (it->_aulNeighbours[i] != ULONG_MAX) { + if (it->_aulNeighbours[i] != FACET_INDEX_MAX) { MeshGeomFacet f1 = _rclMesh.GetFacet(*it); MeshGeomFacet f2 = _rclMesh.GetFacet(it->_aulNeighbours[i]); float cos_angle = f1.GetNormal() * f2.GetNormal(); @@ -1031,7 +937,7 @@ bool MeshEvalFoldsOnBoundary::Evaluate() return this->indices.empty(); } -std::vector MeshEvalFoldsOnBoundary::GetIndices() const +std::vector MeshEvalFoldsOnBoundary::GetIndices() const { return this->indices; } @@ -1040,7 +946,7 @@ bool MeshFixFoldsOnBoundary::Fixup() { MeshEvalFoldsOnBoundary eval(_rclMesh); if (!eval.Evaluate()) { - std::vector inds = eval.GetIndices(); + std::vector inds = eval.GetIndices(); _rclMesh.DeleteFacets(inds); } @@ -1059,9 +965,9 @@ bool MeshEvalFoldOversOnSurface::Evaluate() Base::Vector3f n1, n2; for (f_it = facets.begin(); f_it != f_end; ++f_it) { for (int i=0; i<3; i++) { - unsigned long index1 = f_it->_aulNeighbours[i]; - unsigned long index2 = f_it->_aulNeighbours[(i+1)%3]; - if (index1 != ULONG_MAX && index2 != ULONG_MAX) { + FacetIndex index1 = f_it->_aulNeighbours[i]; + FacetIndex index2 = f_it->_aulNeighbours[(i+1)%3]; + if (index1 != FACET_INDEX_MAX && index2 != FACET_INDEX_MAX) { // if the topology is correct but the normals flip from // two neighbours we have a fold if (f_it->HasSameOrientation(f_beg[index1]) && @@ -1093,7 +999,7 @@ bool MeshEvalBorderFacet::Evaluate() for (f_it = facets.begin(); f_it != f_end; ++f_it) { bool ok = true; for (int i=0; i<3; i++) { - unsigned long index = f_it->_aulPoints[i]; + PointIndex index = f_it->_aulPoints[i]; if (vv_it[index].size() == vf_it[index].size()) { ok = false; break; @@ -1112,11 +1018,11 @@ bool MeshEvalBorderFacet::Evaluate() bool MeshEvalRangeFacet::Evaluate() { const MeshFacetArray& rFaces = _rclMesh.GetFacets(); - unsigned long ulCtFacets = rFaces.size(); + FacetIndex ulCtFacets = rFaces.size(); for (MeshFacetArray::_TConstIterator it = rFaces.begin(); it != rFaces.end(); ++it) { for (int i = 0; i < 3; i++) { - if ((it->_aulNeighbours[i] >= ulCtFacets) && (it->_aulNeighbours[i] < ULONG_MAX)) { + if ((it->_aulNeighbours[i] >= ulCtFacets) && (it->_aulNeighbours[i] < FACET_INDEX_MAX)) { return false; } } @@ -1125,16 +1031,16 @@ bool MeshEvalRangeFacet::Evaluate() return true; } -std::vector MeshEvalRangeFacet::GetIndices() const +std::vector MeshEvalRangeFacet::GetIndices() const { - std::vector aInds; + std::vector aInds; const MeshFacetArray& rFaces = _rclMesh.GetFacets(); - unsigned long ulCtFacets = rFaces.size(); + FacetIndex ulCtFacets = rFaces.size(); - unsigned long ind=0; + FacetIndex ind=0; for (MeshFacetArray::_TConstIterator it = rFaces.begin(); it != rFaces.end(); ++it, ind++) { for (int i = 0; i < 3; i++) { - if ((it->_aulNeighbours[i] >= ulCtFacets) && (it->_aulNeighbours[i] < ULONG_MAX)) { + if ((it->_aulNeighbours[i] >= ulCtFacets) && (it->_aulNeighbours[i] < FACET_INDEX_MAX)) { aInds.push_back(ind); break; } @@ -1155,25 +1061,25 @@ bool MeshFixRangeFacet::Fixup() bool MeshEvalRangePoint::Evaluate() { const MeshFacetArray& rFaces = _rclMesh.GetFacets(); - unsigned long ulCtPoints = _rclMesh.CountPoints(); + PointIndex ulCtPoints = _rclMesh.CountPoints(); for (MeshFacetArray::_TConstIterator it = rFaces.begin(); it != rFaces.end(); ++it) { - if (std::find_if(it->_aulPoints, it->_aulPoints + 3, [ulCtPoints](unsigned long i) { return i >= ulCtPoints; }) < it->_aulPoints + 3) + if (std::find_if(it->_aulPoints, it->_aulPoints + 3, [ulCtPoints](PointIndex i) { return i >= ulCtPoints; }) < it->_aulPoints + 3) return false; } return true; } -std::vector MeshEvalRangePoint::GetIndices() const +std::vector MeshEvalRangePoint::GetIndices() const { - std::vector aInds; + std::vector aInds; const MeshFacetArray& rFaces = _rclMesh.GetFacets(); - unsigned long ulCtPoints = _rclMesh.CountPoints(); + PointIndex ulCtPoints = _rclMesh.CountPoints(); - unsigned long ind=0; + PointIndex ind=0; for (MeshFacetArray::_TConstIterator it = rFaces.begin(); it != rFaces.end(); ++it, ind++) { - if (std::find_if(it->_aulPoints, it->_aulPoints + 3, [ulCtPoints](unsigned long i) { return i >= ulCtPoints; }) < it->_aulPoints + 3) + if (std::find_if(it->_aulPoints, it->_aulPoints + 3, [ulCtPoints](PointIndex i) { return i >= ulCtPoints; }) < it->_aulPoints + 3) aInds.push_back(ind); } @@ -1190,10 +1096,10 @@ bool MeshFixRangePoint::Fixup() else { // facets with point indices out of range cannot be directly deleted because // 'DeleteFacets' will segfault. But setting all point indices to 0 works. - std::vector invalid = eval.GetIndices(); + std::vector invalid = eval.GetIndices(); if (!invalid.empty()) { const MeshFacetArray& rFaces = _rclMesh.GetFacets(); - for (std::vector::iterator it = invalid.begin(); it != invalid.end(); ++it) { + for (std::vector::iterator it = invalid.begin(); it != invalid.end(); ++it) { MeshFacet& face = const_cast(rFaces[*it]); face._aulPoints[0] = 0; face._aulPoints[1] = 0; @@ -1214,25 +1120,21 @@ bool MeshEvalCorruptedFacets::Evaluate() for ( MeshFacetArray::_TConstIterator it = rFaces.begin(); it != rFaces.end(); ++it ) { // dupicated point indices - if ((it->_aulPoints[0] == it->_aulPoints[1]) || - (it->_aulPoints[1] == it->_aulPoints[2]) || - (it->_aulPoints[2] == it->_aulPoints[0])) + if (it->IsDegenerated()) return false; } return true; } -std::vector MeshEvalCorruptedFacets::GetIndices() const +std::vector MeshEvalCorruptedFacets::GetIndices() const { - std::vector aInds; + std::vector aInds; const MeshFacetArray& rFaces = _rclMesh.GetFacets(); - unsigned long ind=0; + FacetIndex ind=0; for ( MeshFacetArray::_TConstIterator it = rFaces.begin(); it != rFaces.end(); ++it, ind++ ) { - if ((it->_aulPoints[0] == it->_aulPoints[1]) || - (it->_aulPoints[1] == it->_aulPoints[2]) || - (it->_aulPoints[2] == it->_aulPoints[0])) + if (it->IsDegenerated()) aInds.push_back(ind); } @@ -1246,7 +1148,7 @@ bool MeshFixCorruptedFacets::Fixup() MeshFacetIterator it(_rclMesh); for ( it.Init(); it.More(); it.Next() ) { - if ( it->Area() <= FLOAT_EPS ) + if ( it.GetReference().IsDegenerated() ) { unsigned long uId = it.Position(); bool removed = cTopAlg.RemoveCorruptedFacet(uId); @@ -1254,7 +1156,7 @@ bool MeshFixCorruptedFacets::Fixup() // due to a modification of the array the iterator became invalid it.Set(uId-1); } - + } } diff --git a/src/Mod/Mesh/App/Core/Degeneration.h b/src/Mod/Mesh/App/Core/Degeneration.h index 17fdebf24d..fdd6dfc876 100644 --- a/src/Mod/Mesh/App/Core/Degeneration.h +++ b/src/Mod/Mesh/App/Core/Degeneration.h @@ -62,7 +62,7 @@ public: /** * Returns the indices of all invalid facets or facets whose points are invalid. */ - std::vector GetIndices() const; + std::vector GetIndices() const; }; /** @@ -113,7 +113,7 @@ public: /** * Returns the indices of all duplicated points. */ - std::vector GetIndices() const; + std::vector GetIndices() const; }; /** @@ -161,7 +161,7 @@ public: /** * Returns the indices of all NaN points. */ - std::vector GetIndices() const; + std::vector GetIndices() const; }; /** @@ -211,7 +211,7 @@ public: /** * Returns the indices of all duplicated facets. */ - std::vector GetIndices() const; + std::vector GetIndices() const; }; /** @@ -258,11 +258,11 @@ public: /** * Return the indices. */ - const std::vector& GetIndices() const + const std::vector& GetIndices() const { return _indices; } private: - std::vector _indices; + std::vector _indices; }; /** @@ -297,7 +297,7 @@ public: /** * Returns the indices of all corrupt facets. */ - std::vector GetIndices() const; + std::vector GetIndices() const; private: float fEpsilon; @@ -417,7 +417,7 @@ public: /** * Returns the indices of deformed facets. */ - std::vector GetIndices() const; + std::vector GetIndices() const; private: float fMinAngle; /**< If an angle of a facet is lower than fMinAngle it's considered as deformed. */ @@ -493,10 +493,10 @@ public: ~MeshEvalDentsOnSurface() {} bool Evaluate(); - std::vector GetIndices() const; + std::vector GetIndices() const; private: - std::vector indices; + std::vector indices; }; class MeshExport MeshFixDentsOnSurface : public MeshValidation @@ -520,10 +520,10 @@ public: ~MeshEvalFoldsOnSurface() {} bool Evaluate(); - std::vector GetIndices() const; + std::vector GetIndices() const; private: - std::vector indices; + std::vector indices; }; /** @@ -539,10 +539,10 @@ public: ~MeshEvalFoldsOnBoundary() {} bool Evaluate(); - std::vector GetIndices() const; + std::vector GetIndices() const; private: - std::vector indices; + std::vector indices; }; class MeshExport MeshFixFoldsOnBoundary : public MeshValidation @@ -565,11 +565,11 @@ public: ~MeshEvalFoldOversOnSurface() {} bool Evaluate(); - std::vector GetIndices() const + std::vector GetIndices() const { return this->indices; } private: - std::vector indices; + std::vector indices; }; /** @@ -580,13 +580,13 @@ private: class MeshExport MeshEvalBorderFacet : public MeshEvaluation { public: - MeshEvalBorderFacet (const MeshKernel &rclB, std::vector& f) + MeshEvalBorderFacet (const MeshKernel &rclB, std::vector& f) : MeshEvaluation(rclB), _facets(f) {} virtual ~MeshEvalBorderFacet () {} bool Evaluate(); protected: - std::vector& _facets; + std::vector& _facets; }; // ---------------------------------------------------- @@ -618,7 +618,7 @@ public: /** * Returns the indices of all facets with invalid neighbour indices. */ - std::vector GetIndices() const; + std::vector GetIndices() const; }; /** @@ -666,7 +666,7 @@ public: /** * Returns the indices of all facets with invalid point indices. */ - std::vector GetIndices() const; + std::vector GetIndices() const; }; /** @@ -715,7 +715,7 @@ public: /** * Returns the indices of all corrupt facets. */ - std::vector GetIndices() const; + std::vector GetIndices() const; }; /** diff --git a/src/Mod/Mesh/App/Core/Elements.cpp b/src/Mod/Mesh/App/Core/Elements.cpp index 2775fd8d30..3d36923482 100644 --- a/src/Mod/Mesh/App/Core/Elements.cpp +++ b/src/Mod/Mesh/App/Core/Elements.cpp @@ -44,7 +44,7 @@ MeshPointArray::MeshPointArray(const MeshPointArray& ary) { } -unsigned long MeshPointArray::Get (const MeshPoint &rclPoint) +PointIndex MeshPointArray::Get (const MeshPoint &rclPoint) { iterator clIter; @@ -52,17 +52,17 @@ unsigned long MeshPointArray::Get (const MeshPoint &rclPoint) if (clIter != end()) return clIter - begin(); else - return ULONG_MAX; + return POINT_INDEX_MAX; } -unsigned long MeshPointArray::GetOrAddIndex (const MeshPoint &rclPoint) +PointIndex MeshPointArray::GetOrAddIndex (const MeshPoint &rclPoint) { - unsigned long ulIndex; + PointIndex ulIndex; - if ((ulIndex = Get(rclPoint)) == ULONG_MAX) + if ((ulIndex = Get(rclPoint)) == POINT_INDEX_MAX) { push_back(rclPoint); - return static_cast(size() - 1); + return static_cast(size() - 1); } else return ulIndex; @@ -83,7 +83,7 @@ void MeshPointArray::SetProperty (unsigned long ulVal) const for (_TConstIterator pP = begin(); pP != end(); ++pP) pP->SetProperty(ulVal); } -void MeshPointArray::ResetInvalid (void) const +void MeshPointArray::ResetInvalid () const { for (_TConstIterator pP = begin(); pP != end(); ++pP) pP->ResetInvalid(); } @@ -110,9 +110,9 @@ MeshFacetArray::MeshFacetArray(const MeshFacetArray& ary) void MeshFacetArray::Erase (_TIterator pIter) { - unsigned long i, *pulN; + FacetIndex i, *pulN; _TIterator pPass, pEnd; - unsigned long ulInd = pIter - begin(); + FacetIndex ulInd = pIter - begin(); erase(pIter); pPass = begin(); pEnd = end(); @@ -121,14 +121,14 @@ void MeshFacetArray::Erase (_TIterator pIter) for (i = 0; i < 3; i++) { pulN = &pPass->_aulNeighbours[i]; - if ((*pulN > ulInd) && (*pulN != ULONG_MAX)) + if ((*pulN > ulInd) && (*pulN != FACET_INDEX_MAX)) (*pulN)--; } pPass++; } } -void MeshFacetArray::TransposeIndices (unsigned long ulOrig, unsigned long ulNew) +void MeshFacetArray::TransposeIndices (PointIndex ulOrig, PointIndex ulNew) { _TIterator pIter = begin(), pEnd = end(); @@ -139,7 +139,7 @@ void MeshFacetArray::TransposeIndices (unsigned long ulOrig, unsigned long ulNew } } -void MeshFacetArray::DecrementIndices (unsigned long ulIndex) +void MeshFacetArray::DecrementIndices (PointIndex ulIndex) { _TIterator pIter = begin(), pEnd = end(); @@ -165,7 +165,7 @@ void MeshFacetArray::SetProperty (unsigned long ulVal) const for (_TConstIterator pF = begin(); pF != end(); ++pF) pF->SetProperty(ulVal); } -void MeshFacetArray::ResetInvalid (void) const +void MeshFacetArray::ResetInvalid () const { for (_TConstIterator pF = begin(); pF != end(); ++pF) pF->ResetInvalid(); } @@ -352,7 +352,7 @@ void MeshGeomEdge::ClosestPointsToLine(const Base::Vector3f &linePt, const Base: // ----------------------------------------------------------------- -MeshGeomFacet::MeshGeomFacet (void) +MeshGeomFacet::MeshGeomFacet () : _bNormalCalculated(false), _ucFlag(0), _ulProp(0) { @@ -497,7 +497,7 @@ void MeshGeomFacet::Enlarge (float fDist) { Base::Vector3f clM, clU, clV, clPNew[3]; float fA, fD; - unsigned long i, ulP1, ulP2, ulP3; + PointIndex i, ulP1, ulP2, ulP3; for (i = 0; i < 3; i++) { diff --git a/src/Mod/Mesh/App/Core/Elements.h b/src/Mod/Mesh/App/Core/Elements.h index 70a8469272..22c48c4cba 100644 --- a/src/Mod/Mesh/App/Core/Elements.h +++ b/src/Mod/Mesh/App/Core/Elements.h @@ -54,7 +54,7 @@ class MeshExport MeshHelpEdge { public: inline bool operator == (const MeshHelpEdge &rclEdge) const; - unsigned long _ulIndex[2]; // point indices + PointIndex _ulIndex[2]; // point indices }; /** @@ -64,28 +64,28 @@ public: class MeshExport MeshIndexEdge { public: - unsigned long _ulFacetIndex; // Facet index + FacetIndex _ulFacetIndex; // Facet index unsigned short _ausCorner[2]; // corner point indices of the facet }; /** MeshEdge just a pair of two point indices */ -typedef std::pair MeshEdge; +typedef std::pair MeshEdge; struct MeshExport EdgeCollapse { - unsigned long _fromPoint; - unsigned long _toPoint; - std::vector _adjacentFrom; // adjacent points to _fromPoint - std::vector _adjacentTo; // adjacent points to _toPoint - std::vector _removeFacets; - std::vector _changeFacets; + PointIndex _fromPoint; + PointIndex _toPoint; + std::vector _adjacentFrom; // adjacent points to _fromPoint + std::vector _adjacentTo; // adjacent points to _toPoint + std::vector _removeFacets; + std::vector _changeFacets; }; struct MeshExport VertexCollapse { - unsigned long _point; - std::vector _circumPoints; - std::vector _circumFacets; + PointIndex _point; + std::vector _circumPoints; + std::vector _circumFacets; }; /** @@ -108,11 +108,11 @@ public: /** @name Construction */ //@{ - MeshPoint (void) : _ucFlag(0), _ulProp(0) { } + MeshPoint () : _ucFlag(0), _ulProp(0) { } inline MeshPoint (float x, float y, float z); inline MeshPoint (const Base::Vector3f &rclPt); inline MeshPoint (const MeshPoint &rclPt); - ~MeshPoint (void) { } + ~MeshPoint () { } //@} public: @@ -126,11 +126,11 @@ public: { const_cast(this)->_ucFlag &= ~static_cast(tF); } bool IsFlag (TFlagType tF) const { return (_ucFlag & static_cast(tF)) == static_cast(tF); } - void ResetInvalid (void) const + void ResetInvalid () const { ResetFlag(INVALID); } - void SetInvalid (void) const + void SetInvalid () const { SetFlag(INVALID); } - bool IsValid (void) const + bool IsValid () const { return !IsFlag(INVALID); } void SetProperty(unsigned long uP) const { const_cast(this)->_ulProp = uP; } @@ -156,7 +156,7 @@ public: class MeshExport MeshGeomEdge { public: - MeshGeomEdge (void) : _bBorder(false) {} + MeshGeomEdge () : _bBorder(false) {} /** Checks if the edge is inside the bounding box or intersects with it. */ bool ContainedByOrIntersectBoundingBox (const Base::BoundBox3f &rclBB ) const; @@ -199,7 +199,7 @@ public: * \li neighbour or edge number of 0 is defined by corner 0 and 1 * \li neighbour or edge number of 1 is defined by corner 1 and 2 * \li neighbour or edge number of 2 is defined by corner 2 and 0 - * \li neighbour index is set to ULONG_MAX if there is no neighbour facet + * \li neighbour index is set to FACET_INDEX_MAX if there is no neighbour facet * * Note: The status flag SEGMENT mark a facet to be part of certain subset, a segment. * This flag must not be set by any algorithm unless it adds or removes facets to a segment. @@ -215,10 +215,10 @@ public: public: /** @name Construction */ //@{ - inline MeshFacet (void); + inline MeshFacet (); inline MeshFacet(const MeshFacet &rclF); - inline MeshFacet(unsigned long p1,unsigned long p2,unsigned long p3,unsigned long n1=ULONG_MAX,unsigned long n2=ULONG_MAX,unsigned long n3=ULONG_MAX); - ~MeshFacet (void) { } + inline MeshFacet(PointIndex p1,PointIndex p2,PointIndex p3,FacetIndex n1=FACET_INDEX_MAX,FacetIndex n2=FACET_INDEX_MAX,FacetIndex n3=FACET_INDEX_MAX); + ~MeshFacet () { } //@} /** @name Flag state @@ -231,7 +231,7 @@ public: { const_cast(this)->_ucFlag &= ~static_cast(tF); } bool IsFlag (TFlagType tF) const { return (_ucFlag & static_cast(tF)) == static_cast(tF); } - void ResetInvalid (void) const + void ResetInvalid () const { ResetFlag(INVALID); } void SetProperty(unsigned long uP) const { const_cast(this)->_ulProp = uP; } @@ -240,16 +240,16 @@ public: * (e.g. deletion of several facets) but must not be set permanently. * From outside the data-structure must not have invalid facets. */ - void SetInvalid (void) const + void SetInvalid () const { SetFlag(INVALID); } - bool IsValid (void) const + bool IsValid () const { return !IsFlag(INVALID); } //@} // Assignment inline MeshFacet& operator = (const MeshFacet &rclF); - inline void SetVertices(unsigned long,unsigned long,unsigned long); - inline void SetNeighbours(unsigned long,unsigned long,unsigned long); + inline void SetVertices(PointIndex,PointIndex,PointIndex); + inline void SetNeighbours(FacetIndex,FacetIndex,FacetIndex); /** * Returns the indices of the corner points of the given edge number. @@ -258,17 +258,17 @@ public: /** * Returns the indices of the corner points of the given edge number. */ - inline std::pair GetEdge (unsigned short usSide) const; + inline std::pair GetEdge (unsigned short usSide) const; /** * Returns the edge-number to the given index of neighbour facet. * If \a ulNIndex is not a neighbour USHRT_MAX is returned. */ - inline unsigned short Side (unsigned long ulNIndex) const; + inline unsigned short Side (FacetIndex ulNIndex) const; /** * Returns the edge-number defined by two points. If one point is * not a corner point USHRT_MAX is returned. */ - inline unsigned short Side (unsigned long ulP0, unsigned long P1) const; + inline unsigned short Side (PointIndex ulP0, PointIndex P1) const; /** * Returns the edge-number defined by the shared edge of both facets. If the facets don't * share a common edge USHRT_MAX is returned. @@ -284,26 +284,26 @@ public: * by \a ulNew. If the facet does not have a corner point with this index * nothing happens. */ - inline void Transpose (unsigned long ulOrig, unsigned long ulNew); + inline void Transpose (PointIndex ulOrig, PointIndex ulNew); /** * Decrement the index for each corner point that is higher than \a ulIndex. */ - inline void Decrement (unsigned long ulIndex); + inline void Decrement (PointIndex ulIndex); /** * Checks if the facets references the given point index. */ - inline bool HasPoint(unsigned long) const; + inline bool HasPoint(PointIndex) const; /** * Replaces the index of the neighbour facet that is equal to \a ulOrig * by \a ulNew. If the facet does not have a neighbourt with this index * nothing happens. */ - inline void ReplaceNeighbour (unsigned long ulOrig, unsigned long ulNew); + inline void ReplaceNeighbour (FacetIndex ulOrig, FacetIndex ulNew); /** * Checks if the neighbour exists at the given edge-number. */ bool HasNeighbour (unsigned short usSide) const - { return (_aulNeighbours[usSide] != ULONG_MAX); } + { return (_aulNeighbours[usSide] != FACET_INDEX_MAX); } /** Counts the number of edges without neighbour. */ inline unsigned short CountOpenEdges() const; /** Returns true if there is an edge without neighbour, otherwise false. */ @@ -315,7 +315,7 @@ public: /** Checks whether the facet is degenerated to a line of point. */ inline bool IsDegenerated() const; /** Flips the orientation of the facet. */ - void FlipNormal (void) + void FlipNormal () { std::swap(_aulPoints[1], _aulPoints[2]); std::swap(_aulNeighbours[0], _aulNeighbours[2]); @@ -324,8 +324,8 @@ public: public: unsigned char _ucFlag; /**< Flag member. */ unsigned long _ulProp; /**< Free usable property. */ - unsigned long _aulPoints[3]; /**< Indices of corner points. */ - unsigned long _aulNeighbours[3]; /**< Indices of neighbour facets. */ + PointIndex _aulPoints[3]; /**< Indices of corner points. */ + FacetIndex _aulNeighbours[3]; /**< Indices of neighbour facets. */ }; /** @@ -338,11 +338,11 @@ public: /** @name Construction */ //@{ /// default constructor - MeshGeomFacet (void); + MeshGeomFacet (); /// Constructor with the corner points MeshGeomFacet (const Base::Vector3f &v1,const Base::Vector3f &v2,const Base::Vector3f &v3); /// Destruction - ~MeshGeomFacet (void) { } + ~MeshGeomFacet () { } //@} public: @@ -403,7 +403,7 @@ public: /** * Calculates the facet normal for storing internally. */ - inline void CalcNormal (void); + inline void CalcNormal (); /** * Arrange the facet normal so the both vectors have the same orientation. */ @@ -411,9 +411,9 @@ public: /** * Adjusts the facet's orientation to its normal. */ - inline void AdjustCirculationDirection (void); + inline void AdjustCirculationDirection (); /** Invalidate the normal. It will be recomputed when querying it. */ - void NormalInvalid (void) { _bNormalCalculated = false; } + void NormalInvalid () { _bNormalCalculated = false; } /** Query the flag state of the facet. */ bool IsFlag (MeshFacet::TFlagType tF) const { return (_ucFlag & static_cast(tF)) == static_cast(tF); } @@ -424,13 +424,13 @@ public: void ResetFlag (MeshFacet::TFlagType tF) { _ucFlag &= ~static_cast(tF); } /** Calculates the facet's gravity point. */ - inline Base::Vector3f GetGravityPoint (void) const; + inline Base::Vector3f GetGravityPoint () const; /** Returns the normal of the facet. */ - inline Base::Vector3f GetNormal (void) const; + inline Base::Vector3f GetNormal () const; /** Sets the facet's normal. */ inline void SetNormal (const Base::Vector3f &rclNormal); /** Returns the wrapping bounding box. */ - inline Base::BoundBox3f GetBoundBox (void) const; + inline Base::BoundBox3f GetBoundBox () const; /** Calculates the perimeter of the facet. */ inline float Perimeter() const; /** Calculates the area of a facet. */ @@ -545,13 +545,13 @@ public: /** @name Construction */ //@{ // constructor - MeshPointArray (void) { } + MeshPointArray () { } // constructor - MeshPointArray (unsigned long ulSize) : TMeshPointArray(ulSize) { } + MeshPointArray (PointIndex ulSize) : TMeshPointArray(ulSize) { } /// copy-constructor MeshPointArray (const MeshPointArray&); // Destructor - ~MeshPointArray (void) { } + ~MeshPointArray () { } //@} /** @name Flag state @@ -563,7 +563,7 @@ public: /// Resets the flag for all points void ResetFlag (MeshPoint::TFlagType tF) const; /// Sets all points invalid - void ResetInvalid (void) const; + void ResetInvalid () const; /// Sets the property for all points void SetProperty (unsigned long ulVal) const; //@} @@ -573,15 +573,15 @@ public: void Transform(const Base::Matrix4D&); /** * Searches for the first point index Two points are equal if the distance is less - * than EPSILON. If no such points is found ULONG_MAX is returned. + * than EPSILON. If no such points is found POINT_INDEX_MAX is returned. */ - unsigned long Get (const MeshPoint &rclPoint); + PointIndex Get (const MeshPoint &rclPoint); /** * Searches for the first point index Two points are equal if the distance is less * than EPSILON. If no such points is found the point is added to the array at end * and its index is returned. */ - unsigned long GetOrAddIndex (const MeshPoint &rclPoint); + PointIndex GetOrAddIndex (const MeshPoint &rclPoint); }; typedef std::vector TMeshFacetArray; @@ -599,13 +599,13 @@ public: /** @name Construction */ //@{ /// constructor - MeshFacetArray (void) { } + MeshFacetArray () { } /// constructor - MeshFacetArray (unsigned long ulSize) : TMeshFacetArray(ulSize) { } + MeshFacetArray (FacetIndex ulSize) : TMeshFacetArray(ulSize) { } /// copy-constructor MeshFacetArray (const MeshFacetArray&); /// destructor - ~MeshFacetArray (void) { } + ~MeshFacetArray () { } //@} /** @name Flag state @@ -618,7 +618,7 @@ public: /// Resets the flag for all facets. void ResetFlag (MeshFacet::TFlagType tF) const; /// Sets all facets invalid - void ResetInvalid (void) const; + void ResetInvalid () const; /// Sets the property for all facets void SetProperty (unsigned long ulVal) const; //@} @@ -634,11 +634,11 @@ public: /** * Checks and flips the point indices if needed. @see MeshFacet::Transpose(). */ - void TransposeIndices (unsigned long ulOrig, unsigned long ulNew); + void TransposeIndices (PointIndex ulOrig, PointIndex ulNew); /** * Decrements all point indices that are higher than \a ulIndex. */ - void DecrementIndices (unsigned long ulIndex); + void DecrementIndices (PointIndex ulIndex); }; /** @@ -684,7 +684,7 @@ public: * that is equal to \a old by \a now. If the facet does not have a corner * point with this index nothing happens. */ - void Transpose(unsigned long pos, unsigned long old, unsigned long now) + void Transpose(PointIndex pos, PointIndex old, PointIndex now) { rFacets[pos].Transpose(old, now); } @@ -765,14 +765,14 @@ inline float MeshGeomFacet::DistancePlaneToPoint (const Base::Vector3f &rclPoint return float(fabs(rclPoint.DistanceToPlane(_aclPoints[0], GetNormal()))); } -inline void MeshGeomFacet::CalcNormal (void) +inline void MeshGeomFacet::CalcNormal () { _clNormal = (_aclPoints[1] - _aclPoints[0]) % (_aclPoints[2] - _aclPoints[0]); _clNormal.Normalize(); _bNormalCalculated = true; } -inline Base::Vector3f MeshGeomFacet::GetNormal (void) const +inline Base::Vector3f MeshGeomFacet::GetNormal () const { if (_bNormalCalculated == false) const_cast(this)->CalcNormal(); @@ -795,19 +795,19 @@ inline void MeshGeomFacet::ArrangeNormal (const Base::Vector3f &rclN) _clNormal = -_clNormal; } -inline Base::Vector3f MeshGeomFacet::GetGravityPoint (void) const +inline Base::Vector3f MeshGeomFacet::GetGravityPoint () const { return (1.0f / 3.0f) * (_aclPoints[0] + _aclPoints[1] + _aclPoints[2]); } -inline void MeshGeomFacet::AdjustCirculationDirection (void) +inline void MeshGeomFacet::AdjustCirculationDirection () { Base::Vector3f clN = (_aclPoints[1] - _aclPoints[0]) % (_aclPoints[2] - _aclPoints[0]); if ((clN * _clNormal) < 0.0f) std::swap(_aclPoints[1], _aclPoints[2]); } -inline Base::BoundBox3f MeshGeomFacet::GetBoundBox (void) const +inline Base::BoundBox3f MeshGeomFacet::GetBoundBox () const { return Base::BoundBox3f(_aclPoints, 3); } @@ -857,12 +857,12 @@ inline bool MeshGeomFacet::IntersectWithPlane (const Base::Vector3f &rclBase, co (bD0 == (_aclPoints[2].DistanceToPlane(rclBase, rclNormal) > 0.0f))); } -inline MeshFacet::MeshFacet (void) +inline MeshFacet::MeshFacet () : _ucFlag(0), _ulProp(0) { - memset(_aulNeighbours, 0xff, sizeof(unsigned long) * 3); - memset(_aulPoints, 0xff, sizeof(unsigned long) * 3); + memset(_aulNeighbours, 0xff, sizeof(FacetIndex) * 3); + memset(_aulPoints, 0xff, sizeof(PointIndex) * 3); } inline MeshFacet::MeshFacet(const MeshFacet &rclF) @@ -878,8 +878,8 @@ inline MeshFacet::MeshFacet(const MeshFacet &rclF) _aulNeighbours[2] = rclF._aulNeighbours[2]; } -inline MeshFacet::MeshFacet(unsigned long p1,unsigned long p2,unsigned long p3, - unsigned long n1,unsigned long n2,unsigned long n3) +inline MeshFacet::MeshFacet(PointIndex p1,PointIndex p2,PointIndex p3, + FacetIndex n1,FacetIndex n2,FacetIndex n3) : _ucFlag(0), _ulProp(0) { @@ -908,14 +908,14 @@ inline MeshFacet& MeshFacet::operator = (const MeshFacet &rclF) return *this; } -void MeshFacet::SetVertices(unsigned long p1,unsigned long p2,unsigned long p3) +void MeshFacet::SetVertices(PointIndex p1,PointIndex p2,PointIndex p3) { _aulPoints[0] = p1; _aulPoints[1] = p2; _aulPoints[2] = p3; } -void MeshFacet::SetNeighbours(unsigned long n1,unsigned long n2,unsigned long n3) +void MeshFacet::SetNeighbours(FacetIndex n1,FacetIndex n2,FacetIndex n3) { _aulNeighbours[0] = n1; _aulNeighbours[1] = n2; @@ -928,12 +928,12 @@ inline void MeshFacet::GetEdge (unsigned short usSide, MeshHelpEdge &rclEdge) co rclEdge._ulIndex[1] = _aulPoints[(usSide+1) % 3]; } -inline std::pair MeshFacet::GetEdge (unsigned short usSide) const +inline std::pair MeshFacet::GetEdge (unsigned short usSide) const { - return std::pair(_aulPoints[usSide], _aulPoints[(usSide+1)%3]); + return std::pair(_aulPoints[usSide], _aulPoints[(usSide+1)%3]); } -inline void MeshFacet::Transpose (unsigned long ulOrig, unsigned long ulNew) +inline void MeshFacet::Transpose (PointIndex ulOrig, PointIndex ulNew) { if (_aulPoints[0] == ulOrig) _aulPoints[0] = ulNew; @@ -943,14 +943,14 @@ inline void MeshFacet::Transpose (unsigned long ulOrig, unsigned long ulNew) _aulPoints[2] = ulNew; } -inline void MeshFacet::Decrement (unsigned long ulIndex) +inline void MeshFacet::Decrement (PointIndex ulIndex) { if (_aulPoints[0] > ulIndex) _aulPoints[0]--; if (_aulPoints[1] > ulIndex) _aulPoints[1]--; if (_aulPoints[2] > ulIndex) _aulPoints[2]--; } -inline bool MeshFacet::HasPoint(unsigned long ulIndex) const +inline bool MeshFacet::HasPoint(PointIndex ulIndex) const { if (_aulPoints[0] == ulIndex) return true; @@ -961,7 +961,7 @@ inline bool MeshFacet::HasPoint(unsigned long ulIndex) const return false; } -inline void MeshFacet::ReplaceNeighbour (unsigned long ulOrig, unsigned long ulNew) +inline void MeshFacet::ReplaceNeighbour (FacetIndex ulOrig, FacetIndex ulNew) { if (_aulNeighbours[0] == ulOrig) _aulNeighbours[0] = ulNew; @@ -1011,7 +1011,7 @@ inline bool MeshFacet::IsDegenerated() const return false; } -inline unsigned short MeshFacet::Side (unsigned long ulNIndex) const +inline unsigned short MeshFacet::Side (FacetIndex ulNIndex) const { if (_aulNeighbours[0] == ulNIndex) return 0; @@ -1023,7 +1023,7 @@ inline unsigned short MeshFacet::Side (unsigned long ulNIndex) const return USHRT_MAX; } -inline unsigned short MeshFacet::Side (unsigned long ulP0, unsigned long ulP1) const +inline unsigned short MeshFacet::Side (PointIndex ulP0, PointIndex ulP1) const { if (_aulPoints[0] == ulP0) { if (_aulPoints[1] == ulP1) diff --git a/src/Mod/Mesh/App/Core/Evaluation.cpp b/src/Mod/Mesh/App/Core/Evaluation.cpp index 440e538fd3..3977282438 100644 --- a/src/Mod/Mesh/App/Core/Evaluation.cpp +++ b/src/Mod/Mesh/App/Core/Evaluation.cpp @@ -52,7 +52,7 @@ MeshOrientationVisitor::MeshOrientationVisitor() : _nonuniformOrientation(false) } bool MeshOrientationVisitor::Visit (const MeshFacet &rclFacet, const MeshFacet &rclFrom, - unsigned long ulFInd, unsigned long ulLevel) + FacetIndex ulFInd, unsigned long ulLevel) { (void)ulFInd; (void)ulLevel; @@ -69,13 +69,13 @@ bool MeshOrientationVisitor::HasNonUnifomOrientedFacets() const return _nonuniformOrientation; } -MeshOrientationCollector::MeshOrientationCollector(std::vector& aulIndices, std::vector& aulComplement) +MeshOrientationCollector::MeshOrientationCollector(std::vector& aulIndices, std::vector& aulComplement) : _aulIndices(aulIndices), _aulComplement(aulComplement) { } bool MeshOrientationCollector::Visit (const MeshFacet &rclFacet, const MeshFacet &rclFrom, - unsigned long ulFInd, unsigned long ulLevel) + FacetIndex ulFInd, unsigned long ulLevel) { (void)ulLevel; // different orientation of rclFacet and rclFrom @@ -104,13 +104,13 @@ bool MeshOrientationCollector::Visit (const MeshFacet &rclFacet, const MeshFacet return true; } -MeshSameOrientationCollector::MeshSameOrientationCollector(std::vector& aulIndices) +MeshSameOrientationCollector::MeshSameOrientationCollector(std::vector& aulIndices) : _aulIndices(aulIndices) { } bool MeshSameOrientationCollector::Visit (const MeshFacet &rclFacet, const MeshFacet &rclFrom, - unsigned long ulFInd, unsigned long ulLevel) + FacetIndex ulFInd, unsigned long ulLevel) { // different orientation of rclFacet and rclFrom (void)ulLevel; @@ -139,7 +139,7 @@ bool MeshEvalOrientation::Evaluate () MeshFacetArray::_TConstIterator iEnd = rFAry.end(); for (MeshFacetArray::_TConstIterator it = iBeg; it != iEnd; ++it) { for (int i = 0; i < 3; i++) { - if (it->_aulNeighbours[i] != ULONG_MAX) { + if (it->_aulNeighbours[i] != FACET_INDEX_MAX) { const MeshFacet& rclFacet = iBeg[it->_aulNeighbours[i]]; for (int j = 0; j < 3; j++) { if (it->_aulPoints[i] == rclFacet._aulPoints[j]) { @@ -156,7 +156,7 @@ bool MeshEvalOrientation::Evaluate () return true; } -unsigned long MeshEvalOrientation::HasFalsePositives(const std::vector& inds) const +unsigned long MeshEvalOrientation::HasFalsePositives(const std::vector& inds) const { // All faces with wrong orientation (i.e. adjacent faces with a normal flip and their neighbours) // build a segment and are marked as TMP0. Now we check all border faces of the segments with @@ -166,10 +166,10 @@ unsigned long MeshEvalOrientation::HasFalsePositives(const std::vector::const_iterator it = inds.begin(); it != inds.end(); ++it) { + for (std::vector::const_iterator it = inds.begin(); it != inds.end(); ++it) { const MeshFacet& f = iBeg[*it]; for (int i = 0; i < 3; i++) { - if (f._aulNeighbours[i] != ULONG_MAX) { + if (f._aulNeighbours[i] != FACET_INDEX_MAX) { const MeshFacet& n = iBeg[f._aulNeighbours[i]]; if (f.IsFlag(MeshFacet::TMP0) && !n.IsFlag(MeshFacet::TMP0)) { for (int j = 0; j < 3; j++) { @@ -183,15 +183,15 @@ unsigned long MeshEvalOrientation::HasFalsePositives(const std::vector MeshEvalOrientation::GetIndices() const +std::vector MeshEvalOrientation::GetIndices() const { - unsigned long ulStartFacet, ulVisited; + FacetIndex ulStartFacet, ulVisited; if (_rclMesh.CountFacets() == 0) - return std::vector(); + return std::vector(); // reset VISIT flags MeshAlgorithm cAlg(_rclMesh); @@ -205,10 +205,10 @@ std::vector MeshEvalOrientation::GetIndices() const ulStartFacet = 0; - std::vector uIndices, uComplement; + std::vector uIndices, uComplement; MeshOrientationCollector clHarmonizer(uIndices, uComplement); - while (ulStartFacet != ULONG_MAX) { + while (ulStartFacet != FACET_INDEX_MAX) { unsigned long wrongFacets = uIndices.size(); uComplement.clear(); @@ -234,7 +234,7 @@ std::vector MeshEvalOrientation::GetIndices() const if (iTri < iEnd) ulStartFacet = iTri - iBeg; else - ulStartFacet = ULONG_MAX; + ulStartFacet = FACET_INDEX_MAX; } // in some very rare cases where we have some strange artifacts in the mesh structure @@ -242,23 +242,23 @@ std::vector MeshEvalOrientation::GetIndices() const cAlg.ResetFacetFlag(MeshFacet::TMP0); cAlg.SetFacetsFlag(uIndices, MeshFacet::TMP0); ulStartFacet = HasFalsePositives(uIndices); - while (ulStartFacet != ULONG_MAX) { + while (ulStartFacet != FACET_INDEX_MAX) { cAlg.ResetFacetsFlag(uIndices, MeshFacet::VISIT); - std::vector falsePos; + std::vector falsePos; MeshSameOrientationCollector coll(falsePos); _rclMesh.VisitNeighbourFacets(coll, ulStartFacet); std::sort(uIndices.begin(), uIndices.end()); std::sort(falsePos.begin(), falsePos.end()); - std::vector diff; - std::back_insert_iterator > biit(diff); + std::vector diff; + std::back_insert_iterator > biit(diff); std::set_difference(uIndices.begin(), uIndices.end(), falsePos.begin(), falsePos.end(), biit); uIndices = diff; cAlg.ResetFacetFlag(MeshFacet::TMP0); cAlg.SetFacetsFlag(uIndices, MeshFacet::TMP0); - unsigned long current = ulStartFacet; + FacetIndex current = ulStartFacet; ulStartFacet = HasFalsePositives(uIndices); if (current == ulStartFacet) break; // avoid an endless loop @@ -312,7 +312,8 @@ namespace MeshCore { struct Edge_Index { - unsigned long p0, p1, f; + PointIndex p0, p1; + FacetIndex f; }; struct Edge_Less @@ -347,8 +348,8 @@ bool MeshEvalTopology::Evaluate () for (pI = rclFAry.begin(); pI != rclFAry.end(); ++pI) { for (int i = 0; i < 3; i++) { Edge_Index item; - item.p0 = std::min(pI->_aulPoints[i], pI->_aulPoints[(i+1)%3]); - item.p1 = std::max(pI->_aulPoints[i], pI->_aulPoints[(i+1)%3]); + item.p0 = std::min(pI->_aulPoints[i], pI->_aulPoints[(i+1)%3]); + item.p1 = std::max(pI->_aulPoints[i], pI->_aulPoints[(i+1)%3]); item.f = pI - rclFAry.begin(); edges.push_back(item); } @@ -360,12 +361,12 @@ bool MeshEvalTopology::Evaluate () std::sort(edges.begin(), edges.end(), Edge_Less()); // search for non-manifold edges - unsigned long p0 = ULONG_MAX, p1 = ULONG_MAX; + PointIndex p0 = POINT_INDEX_MAX, p1 = POINT_INDEX_MAX; nonManifoldList.clear(); nonManifoldFacets.clear(); int count = 0; - std::vector facets; + std::vector facets; std::vector::iterator pE; for (pE = edges.begin(); pE != edges.end(); ++pE) { if (p0 == pE->p0 && p1 == pE->p1) { @@ -391,7 +392,7 @@ bool MeshEvalTopology::Evaluate () } // generate indexed edge list which tangents non-manifolds -void MeshEvalTopology::GetFacetManifolds (std::vector &raclFacetIndList) const +void MeshEvalTopology::GetFacetManifolds (std::vector &raclFacetIndList) const { raclFacetIndList.clear(); const MeshFacetArray& rclFAry = _rclMesh.GetFacets(); @@ -399,9 +400,9 @@ void MeshEvalTopology::GetFacetManifolds (std::vector &raclFacetI for (pI = rclFAry.begin(); pI != rclFAry.end(); ++pI) { for (int i = 0; i < 3; i++) { - unsigned long ulPt0 = std::min(pI->_aulPoints[i], pI->_aulPoints[(i+1)%3]); - unsigned long ulPt1 = std::max(pI->_aulPoints[i], pI->_aulPoints[(i+1)%3]); - std::pair edge = std::make_pair(ulPt0, ulPt1); + PointIndex ulPt0 = std::min(pI->_aulPoints[i], pI->_aulPoints[(i+1)%3]); + PointIndex ulPt1 = std::max(pI->_aulPoints[i], pI->_aulPoints[(i+1)%3]); + std::pair edge = std::make_pair(ulPt0, ulPt1); if (std::find(nonManifoldList.begin(), nonManifoldList.end(), edge) != nonManifoldList.end()) raclFacetIndList.push_back(pI - rclFAry.begin()); @@ -430,11 +431,11 @@ bool MeshFixTopology::Fixup () #else const MeshFacetArray& rFaces = _rclMesh.GetFacets(); deletedFaces.reserve(3 * nonManifoldList.size()); // allocate some memory - std::list >::const_iterator it; + std::list >::const_iterator it; for (it = nonManifoldList.begin(); it != nonManifoldList.end(); ++it) { - std::vector non_mf; + std::vector non_mf; non_mf.reserve(it->size()); - for (std::vector::const_iterator jt = it->begin(); jt != it->end(); ++jt) { + for (std::vector::const_iterator jt = it->begin(); jt != it->end(); ++jt) { // facet is only connected with one edge and there causes a non-manifold unsigned short numOpenEdges = rFaces[*jt].CountOpenEdges(); if (numOpenEdges == 2) @@ -474,10 +475,10 @@ bool MeshEvalPointManifolds::Evaluate () MeshCore::MeshRefPointToFacets vf_it(_rclMesh); unsigned long ctPoints = _rclMesh.CountPoints(); - for (unsigned long index=0; index < ctPoints; index++) { + for (PointIndex index=0; index < ctPoints; index++) { // get the local neighbourhood of the point - const std::set& nf = vf_it[index]; - const std::set& np = vv_it[index]; + const std::set& nf = vf_it[index]; + const std::set& np = vv_it[index]; std::set::size_type sp, sf; sp = np.size(); @@ -487,7 +488,7 @@ bool MeshEvalPointManifolds::Evaluate () // for a non-manifold point the number of adjacent points is higher by more than one than the number of shared faces if (sp > sf + 1) { nonManifoldPoints.push_back(index); - std::vector faces; + std::vector faces; faces.insert(faces.end(), nf.begin(), nf.end()); this->facetsOfNonManifoldPoints.push_back(faces); } @@ -496,9 +497,9 @@ bool MeshEvalPointManifolds::Evaluate () return this->nonManifoldPoints.empty(); } -void MeshEvalPointManifolds::GetFacetIndices (std::vector &facets) const +void MeshEvalPointManifolds::GetFacetIndices (std::vector &facets) const { - std::list >::const_iterator it; + std::list >::const_iterator it; for (it = facetsOfNonManifoldPoints.begin(); it != facetsOfNonManifoldPoints.end(); ++it) { facets.insert(facets.end(), it->begin(), it->end()); } @@ -576,11 +577,11 @@ bool MeshEvalSingleFacet::Evaluate () bool MeshFixSingleFacet::Fixup () { - std::vector aulInvalids; + std::vector aulInvalids; // MeshFacetArray& raFacets = _rclMesh._aclFacetArray; - for ( std::vector >::const_iterator it=_raclManifoldList.begin();it!=_raclManifoldList.end();++it ) + for ( std::vector >::const_iterator it=_raclManifoldList.begin();it!=_raclManifoldList.end();++it ) { - for ( std::list::const_iterator it2 = it->begin(); it2 != it->end(); ++it2 ) + for ( std::list::const_iterator it2 = it->begin(); it2 != it->end(); ++it2 ) { aulInvalids.push_back(*it2); // MeshFacet& rF = raFacets[*it2]; @@ -614,7 +615,7 @@ bool MeshEvalSelfIntersection::Evaluate () Base::SequencerLauncher seq("Checking for self-intersections...", ulGridX*ulGridY*ulGridZ); for (clGridIter.Init(); clGridIter.More(); clGridIter.Next()) { //Get the facet indices, belonging to the current grid unit - std::vector aulGridElements; + std::vector aulGridElements; clGridIter.GetElements(aulGridElements); seq.next(); @@ -623,12 +624,12 @@ bool MeshEvalSelfIntersection::Evaluate () MeshGeomFacet facet1, facet2; Base::Vector3f pt1, pt2; - for (std::vector::iterator it = aulGridElements.begin(); it != aulGridElements.end(); ++it) { + for (std::vector::iterator it = aulGridElements.begin(); it != aulGridElements.end(); ++it) { const Base::BoundBox3f& box1 = boxes[*it]; cMFI.Set(*it); facet1 = *cMFI; const MeshFacet& rface1 = rFaces[*it]; - for (std::vector::iterator jt = it; jt != aulGridElements.end(); ++jt) { + for (std::vector::iterator jt = it; jt != aulGridElements.end(); ++jt) { if (jt == it) // the identical facet continue; // If the facets share a common vertex we do not check for self-intersections because they @@ -665,7 +666,7 @@ bool MeshEvalSelfIntersection::Evaluate () return true; } -void MeshEvalSelfIntersection::GetIntersections(const std::vector >& indices, +void MeshEvalSelfIntersection::GetIntersections(const std::vector >& indices, std::vector >& intersection) const { intersection.reserve(indices.size()); @@ -673,7 +674,7 @@ void MeshEvalSelfIntersection::GetIntersections(const std::vector >::const_iterator it; + std::vector >::const_iterator it; for (it = indices.begin(); it != indices.end(); ++it) { cMF1.Set(it->first); cMF2.Set(it->second); @@ -689,7 +690,7 @@ void MeshEvalSelfIntersection::GetIntersections(const std::vector >& intersection) const +void MeshEvalSelfIntersection::GetIntersections(std::vector >& intersection) const { // Contains bounding boxes for every facet std::vector boxes; @@ -711,7 +712,7 @@ void MeshEvalSelfIntersection::GetIntersections(std::vector aulGridElements; + std::vector aulGridElements; clGridIter.GetElements(aulGridElements); seq.next(true); @@ -720,12 +721,12 @@ void MeshEvalSelfIntersection::GetIntersections(std::vector::iterator it = aulGridElements.begin(); it != aulGridElements.end(); ++it) { + for (std::vector::iterator it = aulGridElements.begin(); it != aulGridElements.end(); ++it) { const Base::BoundBox3f& box1 = boxes[*it]; cMFI.Set(*it); facet1 = *cMFI; const MeshFacet& rface1 = rFaces[*it]; - for (std::vector::iterator jt = it; jt != aulGridElements.end(); ++jt) { + for (std::vector::iterator jt = it; jt != aulGridElements.end(); ++jt) { if (jt == it) // the identical facet continue; // If the facets share a common vertex we do not check for self-intersections because they @@ -759,11 +760,11 @@ void MeshEvalSelfIntersection::GetIntersections(std::vector MeshFixSelfIntersection::GetFacets() const +std::vector MeshFixSelfIntersection::GetFacets() const { - std::vector indices; + std::vector indices; const MeshFacetArray& rFaces = _rclMesh.GetFacets(); - for (std::vector >::const_iterator + for (std::vector >::const_iterator it = selfIntersectons.begin(); it != selfIntersectons.end(); ++it) { unsigned short numOpenEdges1 = rFaces[it->first].CountOpenEdges(); unsigned short numOpenEdges2 = rFaces[it->second].CountOpenEdges(); @@ -819,8 +820,8 @@ bool MeshEvalNeighbourhood::Evaluate () for (pI = rclFAry.begin(); pI != rclFAry.end(); ++pI) { for (int i = 0; i < 3; i++) { Edge_Index item; - item.p0 = std::min(pI->_aulPoints[i], pI->_aulPoints[(i+1)%3]); - item.p1 = std::max(pI->_aulPoints[i], pI->_aulPoints[(i+1)%3]); + item.p0 = std::min(pI->_aulPoints[i], pI->_aulPoints[(i+1)%3]); + item.p1 = std::max(pI->_aulPoints[i], pI->_aulPoints[(i+1)%3]); item.f = pI - rclFAry.begin(); edges.push_back(item); } @@ -831,8 +832,8 @@ bool MeshEvalNeighbourhood::Evaluate () // sort the edges std::sort(edges.begin(), edges.end(), Edge_Less()); - unsigned long p0 = ULONG_MAX, p1 = ULONG_MAX; - unsigned long f0 = ULONG_MAX, f1 = ULONG_MAX; + PointIndex p0 = POINT_INDEX_MAX, p1 = POINT_INDEX_MAX; + PointIndex f0 = FACET_INDEX_MAX, f1 = FACET_INDEX_MAX; int count = 0; std::vector::iterator pE; for (pE = edges.begin(); pE != edges.end(); ++pE) { @@ -858,7 +859,7 @@ bool MeshEvalNeighbourhood::Evaluate () const MeshFacet& rFace = rclFAry[f0]; unsigned short side = rFace.Side(p0,p1); // should be "open edge" but isn't marked as such - if (rFace._aulNeighbours[side] != ULONG_MAX) + if (rFace._aulNeighbours[side] != FACET_INDEX_MAX) return false; } @@ -872,9 +873,9 @@ bool MeshEvalNeighbourhood::Evaluate () return true; } -std::vector MeshEvalNeighbourhood::GetIndices() const +std::vector MeshEvalNeighbourhood::GetIndices() const { - std::vector inds; + std::vector inds; const MeshFacetArray& rclFAry = _rclMesh.GetFacets(); std::vector edges; edges.reserve(3*rclFAry.size()); @@ -885,8 +886,8 @@ std::vector MeshEvalNeighbourhood::GetIndices() const for (pI = rclFAry.begin(); pI != rclFAry.end(); ++pI) { for (int i = 0; i < 3; i++) { Edge_Index item; - item.p0 = std::min(pI->_aulPoints[i], pI->_aulPoints[(i+1)%3]); - item.p1 = std::max(pI->_aulPoints[i], pI->_aulPoints[(i+1)%3]); + item.p0 = std::min(pI->_aulPoints[i], pI->_aulPoints[(i+1)%3]); + item.p1 = std::max(pI->_aulPoints[i], pI->_aulPoints[(i+1)%3]); item.f = pI - rclFAry.begin(); edges.push_back(item); } @@ -897,8 +898,8 @@ std::vector MeshEvalNeighbourhood::GetIndices() const // sort the edges std::sort(edges.begin(), edges.end(), Edge_Less()); - unsigned long p0 = ULONG_MAX, p1 = ULONG_MAX; - unsigned long f0 = ULONG_MAX, f1 = ULONG_MAX; + PointIndex p0 = POINT_INDEX_MAX, p1 = POINT_INDEX_MAX; + PointIndex f0 = FACET_INDEX_MAX, f1 = FACET_INDEX_MAX; int count = 0; std::vector::iterator pE; for (pE = edges.begin(); pE != edges.end(); ++pE) { @@ -926,7 +927,7 @@ std::vector MeshEvalNeighbourhood::GetIndices() const const MeshFacet& rFace = rclFAry[f0]; unsigned short side = rFace.Side(p0,p1); // should be "open edge" but isn't marked as such - if (rFace._aulNeighbours[side] != ULONG_MAX) + if (rFace._aulNeighbours[side] != FACET_INDEX_MAX) inds.push_back(f0); } @@ -950,7 +951,7 @@ bool MeshFixNeighbourhood::Fixup() return true; } -void MeshKernel::RebuildNeighbours (unsigned long index) +void MeshKernel::RebuildNeighbours (FacetIndex index) { std::vector edges; edges.reserve(3 * (this->_aclFacetArray.size() - index)); @@ -961,8 +962,8 @@ void MeshKernel::RebuildNeighbours (unsigned long index) for (pI = pB + index; pI != this->_aclFacetArray.end(); ++pI) { for (int i = 0; i < 3; i++) { Edge_Index item; - item.p0 = std::min(pI->_aulPoints[i], pI->_aulPoints[(i+1)%3]); - item.p1 = std::max(pI->_aulPoints[i], pI->_aulPoints[(i+1)%3]); + item.p0 = std::min(pI->_aulPoints[i], pI->_aulPoints[(i+1)%3]); + item.p1 = std::max(pI->_aulPoints[i], pI->_aulPoints[(i+1)%3]); item.f = pI - pB; edges.push_back(item); } @@ -973,8 +974,8 @@ void MeshKernel::RebuildNeighbours (unsigned long index) int threads = std::max(1, QThread::idealThreadCount()); MeshCore::parallel_sort(edges.begin(), edges.end(), Edge_Less(), threads); - unsigned long p0 = ULONG_MAX, p1 = ULONG_MAX; - unsigned long f0 = ULONG_MAX, f1 = ULONG_MAX; + PointIndex p0 = POINT_INDEX_MAX, p1 = POINT_INDEX_MAX; + PointIndex f0 = FACET_INDEX_MAX, f1 = FACET_INDEX_MAX; int count = 0; std::vector::iterator pE; for (pE = edges.begin(); pE != edges.end(); ++pE) { @@ -996,7 +997,7 @@ void MeshKernel::RebuildNeighbours (unsigned long index) else if (count == 1) { MeshFacet& rFace = this->_aclFacetArray[f0]; unsigned short side = rFace.Side(p0,p1); - rFace._aulNeighbours[side] = ULONG_MAX; + rFace._aulNeighbours[side] = FACET_INDEX_MAX; } p0 = pE->p0; @@ -1019,11 +1020,11 @@ void MeshKernel::RebuildNeighbours (unsigned long index) else if (count == 1) { MeshFacet& rFace = this->_aclFacetArray[f0]; unsigned short side = rFace.Side(p0,p1); - rFace._aulNeighbours[side] = ULONG_MAX; + rFace._aulNeighbours[side] = FACET_INDEX_MAX; } } -void MeshKernel::RebuildNeighbours (void) +void MeshKernel::RebuildNeighbours () { // complete rebuild RebuildNeighbours(0); diff --git a/src/Mod/Mesh/App/Core/Evaluation.h b/src/Mod/Mesh/App/Core/Evaluation.h index 0f5573340e..cc9b34e5d7 100644 --- a/src/Mod/Mesh/App/Core/Evaluation.h +++ b/src/Mod/Mesh/App/Core/Evaluation.h @@ -95,7 +95,7 @@ public: MeshOrientationVisitor(); /** Returns false after the first inconsistence is found, true otherwise. */ - bool Visit (const MeshFacet &, const MeshFacet &, unsigned long , unsigned long ); + bool Visit (const MeshFacet &, const MeshFacet &, FacetIndex , unsigned long ); bool HasNonUnifomOrientedFacets() const; private: @@ -110,15 +110,15 @@ private: class MeshExport MeshOrientationCollector : public MeshOrientationVisitor { public: - MeshOrientationCollector(std::vector& aulIndices, - std::vector& aulComplement); + MeshOrientationCollector(std::vector& aulIndices, + std::vector& aulComplement); /** Returns always true and collects the indices with wrong orientation. */ - bool Visit (const MeshFacet &, const MeshFacet &, unsigned long , unsigned long); + bool Visit (const MeshFacet &, const MeshFacet &, FacetIndex , unsigned long); private: - std::vector& _aulIndices; - std::vector& _aulComplement; + std::vector& _aulIndices; + std::vector& _aulComplement; }; /** @@ -127,12 +127,12 @@ private: class MeshExport MeshSameOrientationCollector : public MeshOrientationVisitor { public: - MeshSameOrientationCollector(std::vector& aulIndices); + MeshSameOrientationCollector(std::vector& aulIndices); /** Returns always true and collects the indices with wrong orientation. */ - bool Visit (const MeshFacet &, const MeshFacet &, unsigned long , unsigned long); + bool Visit (const MeshFacet &, const MeshFacet &, FacetIndex , unsigned long); private: - std::vector& _aulIndices; + std::vector& _aulIndices; }; /** @@ -145,10 +145,10 @@ public: MeshEvalOrientation (const MeshKernel& rclM); ~MeshEvalOrientation(); bool Evaluate (); - std::vector GetIndices() const; + std::vector GetIndices() const; private: - unsigned long HasFalsePositives(const std::vector&) const; + unsigned long HasFalsePositives(const std::vector&) const; }; /** @@ -192,14 +192,14 @@ public: virtual ~MeshEvalTopology () {} virtual bool Evaluate (); - void GetFacetManifolds (std::vector &raclFacetIndList) const; + void GetFacetManifolds (std::vector &raclFacetIndList) const; unsigned long CountManifolds() const; - const std::vector >& GetIndices() const { return nonManifoldList; } - const std::list >& GetFacets() const { return nonManifoldFacets; } + const std::vector >& GetIndices() const { return nonManifoldList; } + const std::list >& GetFacets() const { return nonManifoldFacets; } protected: - std::vector > nonManifoldList; - std::list > nonManifoldFacets; + std::vector > nonManifoldList; + std::list > nonManifoldFacets; }; /** @@ -209,16 +209,16 @@ protected: class MeshExport MeshFixTopology : public MeshValidation { public: - MeshFixTopology (MeshKernel &rclB, const std::list >& mf) + MeshFixTopology (MeshKernel &rclB, const std::list >& mf) : MeshValidation(rclB), nonManifoldList(mf) {} virtual ~MeshFixTopology () {} bool Fixup(); - const std::vector& GetDeletedFaces() const { return deletedFaces; } + const std::vector& GetDeletedFaces() const { return deletedFaces; } protected: - std::vector deletedFaces; - const std::list >& nonManifoldList; + std::vector deletedFaces; + const std::list >& nonManifoldList; }; // ---------------------------------------------------- @@ -236,14 +236,14 @@ public: virtual ~MeshEvalPointManifolds () {} virtual bool Evaluate (); - void GetFacetIndices (std::vector &facets) const; - const std::list >& GetFacetIndices () const { return facetsOfNonManifoldPoints; } - const std::vector& GetIndices() const { return nonManifoldPoints; } + void GetFacetIndices (std::vector &facets) const; + const std::list >& GetFacetIndices () const { return facetsOfNonManifoldPoints; } + const std::vector& GetIndices() const { return nonManifoldPoints; } unsigned long CountManifolds() const { return static_cast(nonManifoldPoints.size()); } protected: - std::vector nonManifoldPoints; - std::list > facetsOfNonManifoldPoints; + std::vector nonManifoldPoints; + std::list > facetsOfNonManifoldPoints; }; // ---------------------------------------------------- @@ -270,13 +270,13 @@ public: class MeshExport MeshFixSingleFacet : public MeshValidation { public: - MeshFixSingleFacet (MeshKernel &rclB, const std::vector >& mf) + MeshFixSingleFacet (MeshKernel &rclB, const std::vector >& mf) : MeshValidation(rclB), _raclManifoldList(mf) {} virtual ~MeshFixSingleFacet () {} bool Fixup(); protected: - const std::vector >& _raclManifoldList; + const std::vector >& _raclManifoldList; }; // ---------------------------------------------------- @@ -293,10 +293,10 @@ public: /// Evaluate the mesh and return if true if there are self intersections bool Evaluate (); /// collect all intersection lines - void GetIntersections(const std::vector >&, + void GetIntersections(const std::vector >&, std::vector >&) const; /// collect the index of all facets with self intersections - void GetIntersections(std::vector >&) const; + void GetIntersections(std::vector >&) const; }; /** @@ -306,14 +306,14 @@ public: class MeshExport MeshFixSelfIntersection : public MeshValidation { public: - MeshFixSelfIntersection (MeshKernel &rclB, const std::vector >& si) + MeshFixSelfIntersection (MeshKernel &rclB, const std::vector >& si) : MeshValidation(rclB), selfIntersectons(si) {} virtual ~MeshFixSelfIntersection () {} - std::vector GetFacets() const; + std::vector GetFacets() const; bool Fixup(); private: - const std::vector >& selfIntersectons; + const std::vector >& selfIntersectons; }; // ---------------------------------------------------- @@ -329,7 +329,7 @@ public: MeshEvalNeighbourhood (const MeshKernel &rclB) : MeshEvaluation(rclB) {} ~MeshEvalNeighbourhood () {} bool Evaluate (); - std::vector GetIndices() const; + std::vector GetIndices() const; }; /** diff --git a/src/Mod/Mesh/App/Core/Grid.cpp b/src/Mod/Mesh/App/Core/Grid.cpp index 4bbc1ce337..cb4572421a 100644 --- a/src/Mod/Mesh/App/Core/Grid.cpp +++ b/src/Mod/Mesh/App/Core/Grid.cpp @@ -45,8 +45,8 @@ MeshGrid::MeshGrid (const MeshKernel &rclM) { } -MeshGrid::MeshGrid (void) -: _pclMesh(NULL), +MeshGrid::MeshGrid () +: _pclMesh(nullptr), _ulCtElements(0), _ulCtGridsX(MESH_CT_GRID), _ulCtGridsY(MESH_CT_GRID), _ulCtGridsZ(MESH_CT_GRID), _fGridLenX(0.0f), _fGridLenY(0.0f), _fGridLenZ(0.0f), @@ -60,10 +60,10 @@ void MeshGrid::Attach (const MeshKernel &rclM) RebuildGrid(); } -void MeshGrid::Clear (void) +void MeshGrid::Clear () { _aulGrid.clear(); - _pclMesh = NULL; + _pclMesh = nullptr; } void MeshGrid::Rebuild (unsigned long ulX, unsigned long ulY, unsigned long ulZ) @@ -89,9 +89,9 @@ void MeshGrid::Rebuild (int iCtGridPerAxis) RebuildGrid(); } -void MeshGrid::InitGrid (void) +void MeshGrid::InitGrid () { - assert(_pclMesh != NULL); + assert(_pclMesh != nullptr); unsigned long i, j; @@ -138,7 +138,7 @@ void MeshGrid::InitGrid (void) } } -unsigned long MeshGrid::Inside (const Base::BoundBox3f &rclBB, std::vector &raulElements, +unsigned long MeshGrid::Inside (const Base::BoundBox3f &rclBB, std::vector &raulElements, bool bDelDoubles) const { unsigned long i, j, k, ulMinX, ulMinY, ulMinZ, ulMaxX, ulMaxY, ulMaxZ; @@ -170,7 +170,7 @@ unsigned long MeshGrid::Inside (const Base::BoundBox3f &rclBB, std::vector &raulElements, +unsigned long MeshGrid::Inside (const Base::BoundBox3f &rclBB, std::vector &raulElements, const Base::Vector3f &rclOrg, float fMaxDist, bool bDelDoubles) const { unsigned long i, j, k, ulMinX, ulMinY, ulMinZ, ulMaxX, ulMaxY, ulMaxZ; @@ -205,7 +205,7 @@ unsigned long MeshGrid::Inside (const Base::BoundBox3f &rclBB, std::vector &raulElements) const +unsigned long MeshGrid::Inside (const Base::BoundBox3f &rclBB, std::set &raulElements) const { unsigned long i, j, k, ulMinX, ulMinY, ulMinZ, ulMaxX, ulMaxY, ulMaxZ; @@ -450,7 +450,7 @@ void MeshGrid::CalculateGridLength (int iCtGridPerAxis) } } -void MeshGrid::SearchNearestFromPoint (const Base::Vector3f &rclPt, std::set &raclInd) const +void MeshGrid::SearchNearestFromPoint (const Base::Vector3f &rclPt, std::set &raclInd) const { raclInd.clear(); Base::BoundBox3f clBB = GetBoundBox(); @@ -563,7 +563,7 @@ void MeshGrid::SearchNearestFromPoint (const Base::Vector3f &rclPt, std::set &raclInd) const + unsigned long ulDistance, std::set &raclInd) const { int nX1 = std::max(0, int(ulX) - int(ulDistance)); int nY1 = std::max(0, int(ulY) - int(ulDistance)); @@ -643,9 +643,9 @@ void MeshGrid::GetHull (unsigned long ulX, unsigned long ulY, unsigned long ulZ, } unsigned long MeshGrid::GetElements (unsigned long ulX, unsigned long ulY, unsigned long ulZ, - std::set &raclInd) const + std::set &raclInd) const { - const std::set &rclSet = _aulGrid[ulX][ulY][ulZ]; + const std::set &rclSet = _aulGrid[ulX][ulY][ulZ]; if (rclSet.size() > 0) { raclInd.insert(rclSet.begin(), rclSet.end()); @@ -655,7 +655,7 @@ unsigned long MeshGrid::GetElements (unsigned long ulX, unsigned long ulY, unsig return 0; } -unsigned long MeshGrid::GetElements(const Base::Vector3f &rclPoint, std::vector& aulFacets) const +unsigned long MeshGrid::GetElements(const Base::Vector3f &rclPoint, std::vector& aulFacets) const { unsigned long ulX, ulY, ulZ; if (!CheckPosition(rclPoint, ulX, ulY, ulZ)) @@ -728,9 +728,9 @@ void MeshFacetGrid::Validate (const MeshKernel &rclMesh) RebuildGrid(); } -void MeshFacetGrid::Validate (void) +void MeshFacetGrid::Validate () { - if (_pclMesh == NULL) + if (_pclMesh == nullptr) return; if (_pclMesh->CountFacets() != _ulCtElements) @@ -748,9 +748,9 @@ bool MeshFacetGrid::Verify() const MeshFacetIterator cF(*_pclMesh); for ( it.Init(); it.More(); it.Next() ) { - std::vector aulElements; + std::vector aulElements; it.GetElements( aulElements ); - for ( std::vector::iterator itF = aulElements.begin(); itF != aulElements.end(); ++itF ) + for ( std::vector::iterator itF = aulElements.begin(); itF != aulElements.end(); ++itF ) { cF.Set( *itF ); if ( cF->IntersectBoundingBox( it.GetBoundBox() ) == false ) @@ -761,7 +761,7 @@ bool MeshFacetGrid::Verify() const return true; } -void MeshFacetGrid::RebuildGrid (void) +void MeshFacetGrid::RebuildGrid () { _ulCtElements = _pclMesh->CountFacets(); @@ -781,7 +781,7 @@ void MeshFacetGrid::RebuildGrid (void) unsigned long MeshFacetGrid::SearchNearestFromPoint (const Base::Vector3f &rclPt) const { - unsigned long ulFacetInd = ULONG_MAX; + ElementIndex ulFacetInd = ELEMENT_INDEX_MAX; float fMinDist = FLOAT_MAX; Base::BoundBox3f clBB = GetBoundBox(); @@ -897,8 +897,8 @@ unsigned long MeshFacetGrid::SearchNearestFromPoint (const Base::Vector3f &rclPt unsigned long MeshFacetGrid::SearchNearestFromPoint (const Base::Vector3f &rclPt, float fMaxSearchArea) const { - std::vector aulFacets; - unsigned long ulFacetInd = ULONG_MAX; + std::vector aulFacets; + ElementIndex ulFacetInd = ELEMENT_INDEX_MAX; float fMinDist = fMaxSearchArea; MeshAlgorithm clFTool(*_pclMesh); @@ -908,7 +908,7 @@ unsigned long MeshFacetGrid::SearchNearestFromPoint (const Base::Vector3f &rclPt Inside(clBB, aulFacets, rclPt, fMaxSearchArea, true); - for (std::vector::const_iterator pI = aulFacets.begin(); pI != aulFacets.end(); ++pI) + for (std::vector::const_iterator pI = aulFacets.begin(); pI != aulFacets.end(); ++pI) { float fDist; @@ -924,7 +924,7 @@ unsigned long MeshFacetGrid::SearchNearestFromPoint (const Base::Vector3f &rclPt void MeshFacetGrid::SearchNearestFacetInHull (unsigned long ulX, unsigned long ulY, unsigned long ulZ, unsigned long ulDistance, const Base::Vector3f &rclPt, - unsigned long &rulFacetInd, float &rfMinDist) const + ElementIndex &rulFacetInd, float &rfMinDist) const { int nX1 = std::max(0, int(ulX) - int(ulDistance)); int nY1 = std::max(0, int(ulY) - int(ulDistance)); @@ -1005,10 +1005,10 @@ void MeshFacetGrid::SearchNearestFacetInHull (unsigned long ulX, unsigned long u void MeshFacetGrid::SearchNearestFacetInGrid(unsigned long ulX, unsigned long ulY, unsigned long ulZ, const Base::Vector3f &rclPt, float &rfMinDist, - unsigned long &rulFacetInd) const + ElementIndex &rulFacetInd) const { - const std::set &rclSet = _aulGrid[ulX][ulY][ulZ]; - for (std::set::const_iterator pI = rclSet.begin(); pI != rclSet.end(); ++pI) + const std::set &rclSet = _aulGrid[ulX][ulY][ulZ]; + for (std::set::const_iterator pI = rclSet.begin(); pI != rclSet.end(); ++pI) { float fDist = _pclMesh->GetFacet(*pI).DistanceToPoint(rclPt); if (fDist < rfMinDist) @@ -1027,7 +1027,7 @@ MeshPointGrid::MeshPointGrid (const MeshKernel &rclM) RebuildGrid(); } -MeshPointGrid::MeshPointGrid (void) +MeshPointGrid::MeshPointGrid () : MeshGrid() { } @@ -1053,7 +1053,7 @@ MeshPointGrid::MeshPointGrid (const MeshKernel &rclM, float fGridLen) std::max(static_cast(clBBMesh.LengthZ() / fGridLen), 1)); } -void MeshPointGrid::AddPoint (const MeshPoint &rclPt, unsigned long ulPtIndex, float fEpsilon) +void MeshPointGrid::AddPoint (const MeshPoint &rclPt, ElementIndex ulPtIndex, float fEpsilon) { (void)fEpsilon; unsigned long ulX, ulY, ulZ; @@ -1070,9 +1070,9 @@ void MeshPointGrid::Validate (const MeshKernel &rclMesh) RebuildGrid(); } -void MeshPointGrid::Validate (void) +void MeshPointGrid::Validate () { - if (_pclMesh == NULL) + if (_pclMesh == nullptr) return; if (_pclMesh->CountPoints() != _ulCtElements) @@ -1090,9 +1090,9 @@ bool MeshPointGrid::Verify() const MeshPointIterator cP(*_pclMesh); for ( it.Init(); it.More(); it.Next() ) { - std::vector aulElements; + std::vector aulElements; it.GetElements( aulElements ); - for ( std::vector::iterator itP = aulElements.begin(); itP != aulElements.end(); ++itP ) + for ( std::vector::iterator itP = aulElements.begin(); itP != aulElements.end(); ++itP ) { cP.Set( *itP ); if ( it.GetBoundBox().IsInBox( *cP ) == false ) @@ -1103,7 +1103,7 @@ bool MeshPointGrid::Verify() const return true; } -void MeshPointGrid::RebuildGrid (void) +void MeshPointGrid::RebuildGrid () { _ulCtElements = _pclMesh->CountPoints(); @@ -1127,7 +1127,7 @@ void MeshPointGrid::Pos (const Base::Vector3f &rclPoint, unsigned long &rulX, un rulZ = static_cast((rclPoint.z - _fMinZ) / _fGridLenZ); } -unsigned long MeshPointGrid::FindElements (const Base::Vector3f &rclPoint, std::set& aulElements) const +unsigned long MeshPointGrid::FindElements (const Base::Vector3f &rclPoint, std::set& aulElements) const { unsigned long ulX, ulY, ulZ; Pos(rclPoint, ulX, ulY, ulZ); @@ -1154,7 +1154,7 @@ MeshGridIterator::MeshGridIterator (const MeshGrid &rclG) } bool MeshGridIterator::InitOnRay (const Base::Vector3f &rclPt, const Base::Vector3f &rclDir, float fMaxSearchArea, - std::vector &raulElements) + std::vector &raulElements) { bool ret = InitOnRay (rclPt, rclDir, raulElements); _fMaxSearchArea = fMaxSearchArea; @@ -1162,7 +1162,7 @@ bool MeshGridIterator::InitOnRay (const Base::Vector3f &rclPt, const Base::Vecto } bool MeshGridIterator::InitOnRay (const Base::Vector3f &rclPt, const Base::Vector3f &rclDir, - std::vector &raulElements) + std::vector &raulElements) { // needed in NextOnRay() to avoid an infinite loop _cSearchPositions.clear(); @@ -1200,7 +1200,7 @@ bool MeshGridIterator::InitOnRay (const Base::Vector3f &rclPt, const Base::Vecto return _bValidRay; } -bool MeshGridIterator::NextOnRay (std::vector &raulElements) +bool MeshGridIterator::NextOnRay (std::vector &raulElements) { if (_bValidRay == false) return false; // nicht initialisiert oder Strahl ausgetreten diff --git a/src/Mod/Mesh/App/Core/Grid.h b/src/Mod/Mesh/App/Core/Grid.h index 29b34f1c4d..e368184bbb 100644 --- a/src/Mod/Mesh/App/Core/Grid.h +++ b/src/Mod/Mesh/App/Core/Grid.h @@ -60,12 +60,12 @@ protected: /// Construction MeshGrid (const MeshKernel &rclM); /// Construction - MeshGrid (void); + MeshGrid (); //@} public: /// Destruction - virtual ~MeshGrid (void) { } + virtual ~MeshGrid () { } public: /** Attaches the mesh kernel to this grid, an already attached mesh gets detached. The grid gets rebuilt @@ -81,21 +81,21 @@ public: /** @name Search */ //@{ /** Searches for elements lying in the intersection area of the grid and the bounding box. */ - virtual unsigned long Inside (const Base::BoundBox3f &rclBB, std::vector &raulElements, bool bDelDoubles = true) const; + virtual unsigned long Inside (const Base::BoundBox3f &rclBB, std::vector &raulElements, bool bDelDoubles = true) const; /** Searches for elements lying in the intersection area of the grid and the bounding box. */ - virtual unsigned long Inside (const Base::BoundBox3f &rclBB, std::set &raulElementss) const; + virtual unsigned long Inside (const Base::BoundBox3f &rclBB, std::set &raulElementss) const; /** Searches for elements lying in the intersection area of the grid and the bounding box. */ - virtual unsigned long Inside (const Base::BoundBox3f &rclBB, std::vector &raulElements, + virtual unsigned long Inside (const Base::BoundBox3f &rclBB, std::vector &raulElements, const Base::Vector3f &rclOrg, float fMaxDist, bool bDelDoubles = true) const; /** Searches for the nearest grids that contain elements from a point, the result are grid indices. */ - void SearchNearestFromPoint (const Base::Vector3f &rclPt, std::set &rclInd) const; + void SearchNearestFromPoint (const Base::Vector3f &rclPt, std::set &rclInd) const; //@} /** @name Getters */ //@{ /** Returns the indices of the elements in the given grid. */ - unsigned long GetElements (unsigned long ulX, unsigned long ulY, unsigned long ulZ, std::set &raclInd) const; - unsigned long GetElements (const Base::Vector3f &rclPoint, std::vector& aulFacets) const; + unsigned long GetElements (unsigned long ulX, unsigned long ulY, unsigned long ulZ, std::set &raclInd) const; + unsigned long GetElements (const Base::Vector3f &rclPoint, std::vector& aulFacets) const; //@} /** Returns the lengths of the grid elements in x,y and z direction. */ @@ -110,9 +110,9 @@ public: /** Returns the bounding box of a given grid element. */ inline Base::BoundBox3f GetBoundBox (unsigned long ulX, unsigned long ulY, unsigned long ulZ) const; /** Returns the bounding box of the whole. */ - inline Base::BoundBox3f GetBoundBox (void) const; + inline Base::BoundBox3f GetBoundBox () const; /** Returns an extended bounding box of the mesh object. */ - inline Base::BoundBox3f GetMeshBoundBox (void) const; + inline Base::BoundBox3f GetMeshBoundBox () const; //@} /** Returns an index for the given grid position. If the specified triple is not a valid grid position ULONG_MAX is returned. * If the index is valid than its value is between zero and the number of grid elements. For each different grid position @@ -140,24 +140,24 @@ public: /** Checks if this is a valid grid position. */ inline bool CheckPos (unsigned long ulX, unsigned long ulY, unsigned long ulZ) const; /** Get the indices of all elements lying in the grids around a given grid with distance \a ulDistance. */ - void GetHull (unsigned long ulX, unsigned long ulY, unsigned long ulZ, unsigned long ulDistance, std::set &raclInd) const; + void GetHull (unsigned long ulX, unsigned long ulY, unsigned long ulZ, unsigned long ulDistance, std::set &raclInd) const; protected: /** Initializes the size of the internal structure. */ - virtual void InitGrid (void); + virtual void InitGrid (); /** Deletes the grid structure. */ - virtual void Clear (void); + virtual void Clear (); /** Calculates the grid length dependent on maximum number of grids. */ virtual void CalculateGridLength (unsigned long ulCtGrid, unsigned long ulMaxGrids); /** Calculates the grid length dependent on the number of grids per axis. */ virtual void CalculateGridLength (int iCtGridPerAxis); /** Rebuilds the grid structure. Must be implemented in sub-classes. */ - virtual void RebuildGrid (void) = 0; + virtual void RebuildGrid () = 0; /** Returns the number of stored elements. Must be implemented in sub-classes. */ - virtual unsigned long HasElements (void) const = 0; + virtual unsigned long HasElements () const = 0; protected: - std::vector > > > _aulGrid; /**< Grid data structure. */ + std::vector > > > _aulGrid; /**< Grid data structure. */ const MeshKernel* _pclMesh; /**< The mesh kernel. */ unsigned long _ulCtElements;/**< Number of grid elements for validation issues. */ unsigned long _ulCtGridsX; /**< Number of grid elements in z. */ @@ -186,7 +186,7 @@ public: /// Construction MeshFacetGrid (const MeshKernel &rclM); /// Construction - MeshFacetGrid (void) : MeshGrid() { } + MeshFacetGrid () : MeshGrid() { } /// Construction MeshFacetGrid (const MeshKernel &rclM, unsigned long ulX, unsigned long ulY, unsigned long ulZ); /// Construction @@ -194,7 +194,7 @@ public: /// Construction MeshFacetGrid (const MeshKernel &rclM, float fGridLen); /// Destruction - virtual ~MeshFacetGrid (void) { } + virtual ~MeshFacetGrid () { } //@} /** @name Search */ @@ -205,17 +205,17 @@ public: unsigned long SearchNearestFromPoint (const Base::Vector3f &rclPt, float fMaxSearchArea) const; /** Searches for the nearest facet in a given grid element and returns the facet index and the actual distance. */ void SearchNearestFacetInGrid(unsigned long ulX, unsigned long ulY, unsigned long ulZ, const Base::Vector3f &rclPt, - float &rfMinDist, unsigned long &rulFacetInd) const; + float &rfMinDist, ElementIndex &rulFacetInd) const; /** Does basically the same as the method above unless that grid neighbours up to the order of \a ulDistance * are introduced into the search. */ void SearchNearestFacetInHull (unsigned long ulX, unsigned long ulY, unsigned long ulZ, unsigned long ulDistance, - const Base::Vector3f &rclPt, unsigned long &rulFacetInd, float &rfMinDist) const; + const Base::Vector3f &rclPt, ElementIndex &rulFacetInd, float &rfMinDist) const; //@} /** Validates the grid structure and rebuilds it if needed. */ virtual void Validate (const MeshKernel &rclM); /** Validates the grid structure and rebuilds it if needed. */ - virtual void Validate (void); + virtual void Validate (); /** Verifies the grid structure and returns false if inconsistencies are found. */ virtual bool Verify() const; @@ -227,12 +227,12 @@ protected: /** Adds a new facet element to the grid structure. \a rclFacet is the geometric facet and \a ulFacetIndex * the corresponding index in the mesh kernel. The facet is added to each grid element that intersects * the facet. */ - inline void AddFacet (const MeshGeomFacet &rclFacet, unsigned long ulFacetIndex, float fEpsilon = 0.0f); + inline void AddFacet (const MeshGeomFacet &rclFacet, ElementIndex ulFacetIndex, float fEpsilon = 0.0f); /** Returns the number of stored elements. */ - unsigned long HasElements (void) const + unsigned long HasElements () const { return _pclMesh->CountFacets(); } /** Rebuilds the grid structure. */ - virtual void RebuildGrid (void); + virtual void RebuildGrid (); }; /** @@ -245,7 +245,7 @@ public: /** @name Construction */ //@{ /// Construction - MeshPointGrid (void); + MeshPointGrid (); /// Construction MeshPointGrid (const MeshKernel &rclM); /// Construction @@ -255,29 +255,29 @@ public: /// Construction MeshPointGrid (const MeshKernel &rclM, unsigned long ulX, unsigned long ulY, unsigned long ulZ); /// Destruction - virtual ~MeshPointGrid (void) {} + virtual ~MeshPointGrid () {} //@} /** Finds all points that lie in the same grid as the point \a rclPoint. */ - unsigned long FindElements(const Base::Vector3f &rclPoint, std::set& aulElements) const; + unsigned long FindElements(const Base::Vector3f &rclPoint, std::set& aulElements) const; /** Validates the grid structure and rebuilds it if needed. */ virtual void Validate (const MeshKernel &rclM); /** Validates the grid structure and rebuilds it if needed. */ - virtual void Validate (void); + virtual void Validate (); /** Verifies the grid structure and returns false if inconsistencies are found. */ virtual bool Verify() const; protected: /** Adds a new point element to the grid structure. \a rclPt is the geometric point and \a ulPtIndex * the corresponding index in the mesh kernel. */ - void AddPoint (const MeshPoint &rclPt, unsigned long ulPtIndex, float fEpsilon = 0.0f); + void AddPoint (const MeshPoint &rclPt, ElementIndex ulPtIndex, float fEpsilon = 0.0f); /** Returns the grid numbers to the given point \a rclPoint. */ void Pos(const Base::Vector3f &rclPoint, unsigned long &rulX, unsigned long &rulY, unsigned long &rulZ) const; /** Returns the number of stored elements. */ - unsigned long HasElements (void) const + unsigned long HasElements () const { return _pclMesh->CountPoints(); } /** Rebuilds the grid structure. */ - virtual void RebuildGrid (void); + virtual void RebuildGrid (); }; /** @@ -290,10 +290,10 @@ public: /// Construction MeshGridIterator (const MeshGrid &rclG); /** Returns the bounding box of the current grid element. */ - Base::BoundBox3f GetBoundBox (void) const + Base::BoundBox3f GetBoundBox () const { return _rclGrid.GetBoundBox(_ulX, _ulY, _ulZ); } /** Returns indices of the elements in the current grid. */ - void GetElements (std::vector &raulElements) const + void GetElements (std::vector &raulElements) const { raulElements.insert(raulElements.end(), _rclGrid._aulGrid[_ulX][_ulY][_ulZ].begin(), _rclGrid._aulGrid[_ulX][_ulY][_ulZ].end()); } @@ -305,13 +305,13 @@ public: /** @name Iteration */ //@{ /** Sets the iterator to the first element*/ - void Init (void) + void Init () { _ulX = _ulY = _ulZ = 0; } /** Checks if the iterator has not yet reached the end position. */ - bool More (void) const + bool More () const { return (_ulZ < _rclGrid._ulCtGridsZ); } /** Go to the next grid. */ - void Next (void) + void Next () { if (++_ulX >= (_rclGrid._ulCtGridsX)) _ulX = 0; else return; if (++_ulY >= (_rclGrid._ulCtGridsY)) { _ulY = 0; _ulZ++; } else return; @@ -321,11 +321,11 @@ public: /** @name Tests with rays */ //@{ /** Searches for facets around the ray. */ - bool InitOnRay (const Base::Vector3f &rclPt, const Base::Vector3f &rclDir, std::vector &raulElements); + bool InitOnRay (const Base::Vector3f &rclPt, const Base::Vector3f &rclDir, std::vector &raulElements); /** Searches for facets around the ray. */ - bool InitOnRay (const Base::Vector3f &rclPt, const Base::Vector3f &rclDir, float fMaxSearchArea, std::vector &raulElements); + bool InitOnRay (const Base::Vector3f &rclPt, const Base::Vector3f &rclDir, float fMaxSearchArea, std::vector &raulElements); /** Searches for facets around the ray. */ - bool NextOnRay (std::vector &raulElements); + bool NextOnRay (std::vector &raulElements); //@} /** Returns the grid number of the current position. */ @@ -372,13 +372,13 @@ inline Base::BoundBox3f MeshGrid::GetBoundBox (unsigned long ulX, unsigned long return Base::BoundBox3f(fX, fY, fZ, fX + _fGridLenX, fY + _fGridLenY, fZ + _fGridLenZ); } -inline Base::BoundBox3f MeshGrid::GetBoundBox (void) const +inline Base::BoundBox3f MeshGrid::GetBoundBox () const { return Base::BoundBox3f(_fMinX, _fMinY, _fMinZ, _fMinX + (_fGridLenX * float(_ulCtGridsX)), _fMinY + (_fGridLenY * float(_ulCtGridsY)), _fMinZ + (_fGridLenZ * float(_ulCtGridsZ))); } -inline Base::BoundBox3f MeshGrid::GetMeshBoundBox (void) const +inline Base::BoundBox3f MeshGrid::GetMeshBoundBox () const { Base::BoundBox3f clBBenlarged = _pclMesh->GetBoundBox(); clBBenlarged.Enlarge(MESHGRID_BBOX_EXTENSION); @@ -434,38 +434,8 @@ inline void MeshFacetGrid::PosWithCheck (const Base::Vector3f &rclPoint, unsigne assert((rulX < _ulCtGridsX) && (rulY < _ulCtGridsY) && (rulZ < _ulCtGridsZ)); } -inline void MeshFacetGrid::AddFacet (const MeshGeomFacet &rclFacet, unsigned long ulFacetIndex, float /*fEpsilon*/) +inline void MeshFacetGrid::AddFacet (const MeshGeomFacet &rclFacet, ElementIndex ulFacetIndex, float /*fEpsilon*/) { -#if 0 - unsigned long i, ulX, ulY, ulZ, ulX1, ulY1, ulZ1, ulX2, ulY2, ulZ2; - - ulX1 = ulY1 = ulZ1 = ULONG_MAX; - ulX2 = ulY2 = ulZ2 = 0; - - for (i = 0; i < 3; i++) - { - Pos(rclFacet._aclPoints[i], ulX, ulY, ulZ); - _aulGrid[ulX][ulY][ulZ].insert(ulFacetIndex); - ulX1 = RSmin(ulX1, ulX); ulY1 = RSmin(ulY1, ulY); ulZ1 = RSmin(ulZ1, ulZ); - ulX2 = RSmax(ulX2, ulX); ulY2 = RSmax(ulY2, ulY); ulZ2 = RSmax(ulZ2, ulZ); - } - - // falls Facet ueber mehrere BB reicht - if ((ulX1 < ulX2) || (ulY1 < ulY2) || (ulZ1 < ulZ2)) - { - for (ulX = ulX1; ulX <= ulX2; ulX++) - { - for (ulY = ulY1; ulY <= ulY2; ulY++) - { - for (ulZ = ulZ1; ulZ <= ulZ2; ulZ++) - { - if (CMeshFacetFunc::BBoxContainFacet(GetBoundBox(ulX, ulY, ulZ), rclFacet) == true) - _aulGrid[ulX][ulY][ulZ].insert(ulFacetIndex); - } - } - } - } -#else unsigned long ulX, ulY, ulZ; unsigned long ulX1, ulY1, ulZ1, ulX2, ulY2, ulZ2; @@ -510,8 +480,6 @@ inline void MeshFacetGrid::AddFacet (const MeshGeomFacet &rclFacet, unsigned lon } else _aulGrid[ulX1][ulY1][ulZ1].insert(ulFacetIndex); - -#endif } } // namespace MeshCore diff --git a/src/Mod/Mesh/App/Core/Helpers.h b/src/Mod/Mesh/App/Core/Helpers.h index 7726fb2dca..a5c844e9c1 100644 --- a/src/Mod/Mesh/App/Core/Helpers.h +++ b/src/Mod/Mesh/App/Core/Helpers.h @@ -36,19 +36,19 @@ namespace MeshCore { */ struct MeshExport MeshHelpPoint { - inline void Set (unsigned long ulCorner, unsigned long ulFacet, const Base::Vector3f &rclPt); + inline void Set (FacetIndex ulCorner, FacetIndex ulFacet, const Base::Vector3f &rclPt); inline bool operator < (const MeshHelpPoint &rclObj) const; inline bool operator == (const MeshHelpPoint &rclObj) const; - unsigned long Index (void) const + FacetIndex Index () const { return _ulInd >> 2; } - unsigned long Corner (void) const + FacetIndex Corner () const { return _ulInd & 3; } - MeshPoint _clPt; - unsigned long _ulInd; + MeshPoint _clPt; + FacetIndex _ulInd; }; /** @@ -56,7 +56,7 @@ struct MeshExport MeshHelpPoint */ struct MeshPointBuilder: public std::vector { - inline void Add (unsigned long ulCorner, unsigned long ulFacet, const Base::Vector3f &rclPt); + inline void Add (FacetIndex ulCorner, FacetIndex ulFacet, const Base::Vector3f &rclPt); }; /** @@ -64,14 +64,14 @@ struct MeshPointBuilder: public std::vector */ struct MeshExport MeshHelpBuilderEdge { - unsigned long Side (void) const + FacetIndex Side () const { return _ulFIndex & 3; } - unsigned long Index (void) const + FacetIndex Index () const { return _ulFIndex >> 2; } - inline void Set (unsigned long ulInd1, unsigned long ulInd2, - unsigned long ulSide, unsigned long ulFInd); + inline void Set (PointIndex ulInd1, PointIndex ulInd2, + FacetIndex ulSide, FacetIndex ulFInd); inline bool operator < (const MeshHelpBuilderEdge &rclObj) const; @@ -80,8 +80,8 @@ struct MeshExport MeshHelpBuilderEdge inline bool operator != (const MeshHelpBuilderEdge &rclObj) const; - unsigned long _ulFIndex; // facet index - unsigned long _aulInd[2]; // point index + FacetIndex _ulFIndex; // facet index + PointIndex _aulInd[2]; // point index }; /** @@ -90,10 +90,10 @@ struct MeshExport MeshHelpBuilderEdge struct MeshEdgeBuilder: public std::vector { typedef std::vector::iterator _TIterator; - inline void Add (unsigned long ulInd1, unsigned long ulInd2, unsigned long ulSide, unsigned long ulFInd); + inline void Add (PointIndex ulInd1, PointIndex ulInd2, FacetIndex ulSide, FacetIndex ulFInd); }; -inline void MeshHelpPoint::Set (unsigned long ulCorner, unsigned long ulFacet, const Base::Vector3f &rclPt) +inline void MeshHelpPoint::Set (FacetIndex ulCorner, FacetIndex ulFacet, const Base::Vector3f &rclPt) { _ulInd = (ulFacet << 2) | ulCorner; _clPt = rclPt; @@ -101,21 +101,6 @@ inline void MeshHelpPoint::Set (unsigned long ulCorner, unsigned long ulFacet, c inline bool MeshHelpPoint::operator < (const MeshHelpPoint &rclObj) const { -// if (fabs(_clPt.x - rclObj._clPt.x) < MeshDefinitions::_fMinPointDistanceD1) -// { -// if (fabs(_clPt.y - rclObj._clPt.y) < MeshDefinitions::_fMinPointDistanceD1) -// { -// if (fabs(_clPt.z - rclObj._clPt.z) < MeshDefinitions::_fMinPointDistanceD1) -// return false; -// else -// return _clPt.z < rclObj._clPt.z; -// } -// else -// return _clPt.y < rclObj._clPt.y; -// } -// else -// return _clPt.x < rclObj._clPt.x; - if (_clPt.x == rclObj._clPt.x) { if (_clPt.y == rclObj._clPt.y) @@ -130,33 +115,17 @@ inline bool MeshHelpPoint::operator < (const MeshHelpPoint &rclObj) const inline bool MeshHelpPoint::operator == (const MeshHelpPoint &rclObj) const { return Base::DistanceP2(_clPt, rclObj._clPt) < MeshDefinitions::_fMinPointDistanceP2; -/* - if (fabs(_clPt.x - rclObj._clPt.x) < (MeshDefinitions::_fMinPointDistanceD1 + 1.0e-2f)) - { - if (fabs(_clPt.y - rclObj._clPt.y) < (MeshDefinitions::_fMinPointDistanceD1 + 1.0e-2f)) - { - if (fabs(_clPt.z - rclObj._clPt.z) < (MeshDefinitions::_fMinPointDistanceD1 + 1.0e-2f)) - return true; - else - return false; - } - else - return false; - } - else - return false; -*/ } -inline void MeshPointBuilder::Add (unsigned long ulCorner, unsigned long ulFacet, const Base::Vector3f &rclPt) +inline void MeshPointBuilder::Add (FacetIndex ulCorner, FacetIndex ulFacet, const Base::Vector3f &rclPt) { MeshHelpPoint clObj; clObj.Set(ulCorner, ulFacet, rclPt); push_back(clObj); } -inline void MeshHelpBuilderEdge::Set ( unsigned long ulInd1, unsigned long ulInd2, - unsigned long ulSide, unsigned long ulFInd) +inline void MeshHelpBuilderEdge::Set (PointIndex ulInd1, PointIndex ulInd2, + FacetIndex ulSide, FacetIndex ulFInd) { if (ulInd1 < ulInd2) { @@ -190,8 +159,8 @@ inline bool MeshHelpBuilderEdge::operator != (const MeshHelpBuilderEdge &rclObj) } -inline void MeshEdgeBuilder::Add (unsigned long ulInd1, unsigned long ulInd2, - unsigned long ulSide, unsigned long ulFInd) +inline void MeshEdgeBuilder::Add (PointIndex ulInd1, PointIndex ulInd2, + FacetIndex ulSide, FacetIndex ulFInd) { MeshHelpBuilderEdge clObj; clObj.Set(ulInd1, ulInd2, ulSide, ulFInd); diff --git a/src/Mod/Mesh/App/Core/Info.cpp b/src/Mod/Mesh/App/Core/Info.cpp index 5eb0783290..cf7b6164b7 100644 --- a/src/Mod/Mesh/App/Core/Info.cpp +++ b/src/Mod/Mesh/App/Core/Info.cpp @@ -52,10 +52,7 @@ std::ostream& MeshInfo::GeneralInformation (std::ostream &rclStream) const rclStream << "Mesh: [" << ulCtFc << " Faces, "; - if (ulCtEd!=ULONG_MAX) rclStream << ulCtEd << " Edges, "; - else - rclStream << "Cannot determine number of edges, "; rclStream << ulCtPt << " Points" << "]" << std::endl; @@ -65,12 +62,11 @@ std::ostream& MeshInfo::GeneralInformation (std::ostream &rclStream) const std::ostream& MeshInfo::DetailedPointInfo (std::ostream& rclStream) const { // print points - unsigned long i; rclStream << _rclMesh.CountPoints() << " Points:" << std::endl; MeshPointIterator pPIter(_rclMesh), pPEnd(_rclMesh); pPIter.Begin(); pPEnd.End(); - i = 0; + PointIndex i = 0; rclStream.precision(3); rclStream.setf(std::ios::fixed | std::ios::showpoint | std::ios::showpos); @@ -90,7 +86,7 @@ std::ostream& MeshInfo::DetailedEdgeInfo (std::ostream& rclStream) const { // print edges // get edges from facets - std::map, int > lEdges; + std::map, int > lEdges; const MeshFacetArray& rFacets = _rclMesh.GetFacets(); MeshFacetArray::_TConstIterator pFIter; @@ -100,9 +96,9 @@ std::ostream& MeshInfo::DetailedEdgeInfo (std::ostream& rclStream) const const MeshFacet& rFacet = *pFIter; for ( int j=0; j<3; j++ ) { - unsigned long ulPt0 = std::min(rFacet._aulPoints[j], rFacet._aulPoints[(j+1)%3]); - unsigned long ulPt1 = std::max(rFacet._aulPoints[j], rFacet._aulPoints[(j+1)%3]); - std::pair cEdge(ulPt0, ulPt1); + PointIndex ulPt0 = std::min(rFacet._aulPoints[j], rFacet._aulPoints[(j+1)%3]); + PointIndex ulPt1 = std::max(rFacet._aulPoints[j], rFacet._aulPoints[(j+1)%3]); + std::pair cEdge(ulPt0, ulPt1); lEdges[ cEdge ]++; } @@ -111,7 +107,7 @@ std::ostream& MeshInfo::DetailedEdgeInfo (std::ostream& rclStream) const // print edges rclStream << lEdges.size() << " Edges:" << std::endl; - std::map, int >::const_iterator pEIter; + std::map, int >::const_iterator pEIter; pEIter = lEdges.begin(); rclStream.precision(3); diff --git a/src/Mod/Mesh/App/Core/Info.h b/src/Mod/Mesh/App/Core/Info.h index 85828d5a1e..166d595ed7 100644 --- a/src/Mod/Mesh/App/Core/Info.h +++ b/src/Mod/Mesh/App/Core/Info.h @@ -37,7 +37,7 @@ class MeshExport MeshInfo { public: MeshInfo (const MeshKernel &rclM); - virtual ~MeshInfo (void) {} + virtual ~MeshInfo () {} /** * Writes general information about the mesh structure into the stream. */ @@ -82,7 +82,7 @@ protected: const MeshKernel &_rclMesh; // const reference to mesh data structure private: - MeshInfo(void); // not accessible default constructor + MeshInfo(); // not accessible default constructor }; diff --git a/src/Mod/Mesh/App/Core/Iterator.h b/src/Mod/Mesh/App/Core/Iterator.h index b0197ad9c3..07e74ed2f2 100644 --- a/src/Mod/Mesh/App/Core/Iterator.h +++ b/src/Mod/Mesh/App/Core/Iterator.h @@ -53,7 +53,7 @@ public: /// construction inline MeshFacetIterator (const MeshKernel &rclM); /// construction - inline MeshFacetIterator (const MeshKernel &rclM, unsigned long ulPos); + inline MeshFacetIterator (const MeshKernel &rclM, FacetIndex ulPos); /// construction inline MeshFacetIterator (const MeshFacetIterator &rclI); //@} @@ -67,18 +67,18 @@ public: /** @name Access methods */ //@{ /// Access to the element the iterator points to. - const MeshGeomFacet& operator*(void) + const MeshGeomFacet& operator*() { return Dereference(); } /// Access to the element the iterator points to. - const MeshGeomFacet* operator->(void) + const MeshGeomFacet* operator->() { return &Dereference(); } /// Increments the iterator. It points then to the next element if the /// end is not reached. - const MeshFacetIterator& operator ++ (void) + const MeshFacetIterator& operator ++ () { ++_clIter; return *this; } /// Decrements the iterator. It points then to the previous element if the beginning /// is not reached. - const MeshFacetIterator& operator -- (void) + const MeshFacetIterator& operator -- () { --_clIter; return *this; } /// Increments the iterator by \a k positions. const MeshFacetIterator& operator += (int k) @@ -98,42 +98,42 @@ public: bool operator == (const MeshFacetIterator &rclI) const { return _clIter == rclI._clIter; } /// Sets the iterator to the beginning of the array. - void Begin (void) + void Begin () { _clIter = _rclFAry.begin(); } /// Sets the iterator to the end of the array. - void End (void) + void End () { _clIter = _rclFAry.end(); } /// Returns the current position of the iterator in the array. - unsigned long Position (void) const + FacetIndex Position () const { return _clIter - _rclFAry.begin(); } /// Checks if the end is already reached. - bool EndReached (void) const + bool EndReached () const { return !(_clIter < _rclFAry.end()); } /// Sets the iterator to the beginning of the array. - void Init (void) + void Init () { Begin(); } /// Checks if the end is not yet reached. - bool More (void) const + bool More () const { return !EndReached(); } /// Increments the iterator. - void Next (void) + void Next () { operator++(); } /// Sets the iterator to a given position. - inline bool Set (unsigned long ulIndex); + inline bool Set (FacetIndex ulIndex); /// Returns the topologic facet. - inline MeshFacet GetIndices (void) const + inline MeshFacet GetIndices () const { return *_clIter; } /// Returns the topologic facet. - inline const MeshFacet& GetReference (void) const + inline const MeshFacet& GetReference () const { return *_clIter; } /// Returns iterators pointing to the current facet's neighbours. inline void GetNeighbours (MeshFacetIterator &rclN0, MeshFacetIterator &rclN1, MeshFacetIterator &rclN2) const; /// Sets the iterator to the current facet's neighbour of the side \a usN. inline void SetToNeighbour (unsigned short usN); /// Returns the property information to the current facet. - inline unsigned long GetProperty (void) const; + inline unsigned long GetProperty () const; /// Checks if the iterator points to a valid element inside the array. - inline bool IsValid (void) const + inline bool IsValid () const { return (_clIter >= _rclFAry.begin()) && (_clIter < _rclFAry.end()); } //@} /** @name Flag state @@ -150,7 +150,7 @@ public: //@} protected: - inline const MeshGeomFacet& Dereference (void); + inline const MeshGeomFacet& Dereference (); protected: const MeshKernel& _rclMesh; @@ -176,7 +176,7 @@ public: /** @name Construction */ //@{ inline MeshPointIterator (const MeshKernel &rclM); - inline MeshPointIterator (const MeshKernel &rclM, unsigned long ulPos); + inline MeshPointIterator (const MeshKernel &rclM, PointIndex ulPos); inline MeshPointIterator (const MeshPointIterator &rclI); //@} @@ -189,18 +189,18 @@ public: /** @name Access methods */ //@{ /// Access to the element the iterator points to. - const MeshPoint& operator*(void) const + const MeshPoint& operator*() const { return Dereference(); } /// Access to the element the iterator points to. - const MeshPoint* operator->(void) const + const MeshPoint* operator->() const { return &Dereference(); } /// Increments the iterator. It points then to the next element if the /// end is not reached. - const MeshPointIterator& operator ++ (void) + const MeshPointIterator& operator ++ () { ++_clIter; return *this; } /// Decrements the iterator. It points then to the previous element if the beginning /// is not reached. - const MeshPointIterator& operator -- (void) + const MeshPointIterator& operator -- () { --_clIter; return *this; } /// Assignment. inline MeshPointIterator& operator = (const MeshPointIterator &rpI); @@ -214,30 +214,30 @@ public: bool operator == (const MeshPointIterator &rclI) const { return _clIter == rclI._clIter; } /// Sets the iterator to the beginning of the array. - void Begin (void) + void Begin () { _clIter = _rclPAry.begin(); } /// Sets the iterator to the end of the array. - void End (void) + void End () { _clIter = _rclPAry.end(); } /// Returns the current position of the iterator in the array. - unsigned long Position (void) const + PointIndex Position () const { return _clIter - _rclPAry.begin(); } /// Checks if the end is already reached. - bool EndReached (void) const + bool EndReached () const { return !(_clIter < _rclPAry.end()); } /// Sets the iterator to the beginning of the array. - void Init (void) + void Init () { Begin(); } /// Checks if the end is not yet reached. - bool More (void) const + bool More () const { return !EndReached(); } /// Increments the iterator. - void Next (void) + void Next () { operator++(); } /// Sets the iterator to a given position. - inline bool Set (unsigned long ulIndex); + inline bool Set (PointIndex ulIndex); /// Checks if the iterator points to a valid element inside the array. - inline bool IsValid (void) const + inline bool IsValid () const { return (_clIter >= _rclPAry.begin()) && (_clIter < _rclPAry.end()); } //@} /** @name Flag state @@ -254,7 +254,7 @@ public: //@} protected: - inline const MeshPoint& Dereference (void) const; + inline const MeshPoint& Dereference () const; protected: const MeshKernel& _rclMesh; @@ -274,9 +274,9 @@ public: inline MeshFastFacetIterator (const MeshKernel &rclM); virtual ~MeshFastFacetIterator () {} - void Init (void) { _clIter = _rclFAry.begin(); } - inline void Next (void); - bool More (void) { return _clIter != _rclFAry.end(); } + void Init () { _clIter = _rclFAry.begin(); } + inline void Next (); + bool More () { return _clIter != _rclFAry.end(); } Base::Vector3f _afPoints[3]; @@ -299,9 +299,9 @@ inline MeshFastFacetIterator::MeshFastFacetIterator (const MeshKernel &rclM) { } -inline void MeshFastFacetIterator::Next (void) +inline void MeshFastFacetIterator::Next () { - const unsigned long *paulPt = _clIter->_aulPoints; + const PointIndex *paulPt = _clIter->_aulPoints; Base::Vector3f *pfPt = _afPoints; *(pfPt++) = _rclPAry[*(paulPt++)]; *(pfPt++) = _rclPAry[*(paulPt++)]; @@ -317,7 +317,7 @@ inline MeshFacetIterator::MeshFacetIterator (const MeshKernel &rclM) { } -inline MeshFacetIterator::MeshFacetIterator (const MeshKernel &rclM, unsigned long ulPos) +inline MeshFacetIterator::MeshFacetIterator (const MeshKernel &rclM, FacetIndex ulPos) : _rclMesh(rclM), _rclFAry(rclM._aclFacetArray), _rclPAry(rclM._aclPointArray), @@ -344,10 +344,10 @@ inline void MeshFacetIterator::Transform( const Base::Matrix4D& rclTrf ) _clTrf != tmp ? _bApply = true : _bApply = false; } -inline const MeshGeomFacet& MeshFacetIterator::Dereference (void) +inline const MeshGeomFacet& MeshFacetIterator::Dereference () { MeshFacet rclF = *_clIter; - const unsigned long *paulPt = &(_clIter->_aulPoints[0]); + const PointIndex *paulPt = &(_clIter->_aulPoints[0]); Base::Vector3f *pclPt = _clFacet._aclPoints; *(pclPt++) = _rclPAry[*(paulPt++)]; *(pclPt++) = _rclPAry[*(paulPt++)]; @@ -364,7 +364,7 @@ inline const MeshGeomFacet& MeshFacetIterator::Dereference (void) return _clFacet; } -inline bool MeshFacetIterator::Set (unsigned long ulIndex) +inline bool MeshFacetIterator::Set (FacetIndex ulIndex) { if (ulIndex < _rclFAry.size()) { @@ -386,24 +386,24 @@ inline MeshFacetIterator& MeshFacetIterator::operator = (const MeshFacetIterator return *this; } -inline unsigned long MeshFacetIterator::GetProperty (void) const +inline unsigned long MeshFacetIterator::GetProperty () const { return _clIter->_ulProp; } inline void MeshFacetIterator::GetNeighbours (MeshFacetIterator &rclN0, MeshFacetIterator &rclN1, MeshFacetIterator &rclN2) const { - if (_clIter->_aulNeighbours[0] != ULONG_MAX) + if (_clIter->_aulNeighbours[0] != FACET_INDEX_MAX) rclN0.Set(_clIter->_aulNeighbours[0]); else rclN0.End(); - if (_clIter->_aulNeighbours[1] != ULONG_MAX) + if (_clIter->_aulNeighbours[1] != FACET_INDEX_MAX) rclN1.Set(_clIter->_aulNeighbours[1]); else rclN1.End(); - if (_clIter->_aulNeighbours[2] != ULONG_MAX) + if (_clIter->_aulNeighbours[2] != FACET_INDEX_MAX) rclN2.Set(_clIter->_aulNeighbours[2]); else rclN2.End(); @@ -411,7 +411,7 @@ inline void MeshFacetIterator::GetNeighbours (MeshFacetIterator &rclN0, MeshFace inline void MeshFacetIterator::SetToNeighbour (unsigned short usN) { - if (_clIter->_aulNeighbours[usN] != ULONG_MAX) + if (_clIter->_aulNeighbours[usN] != FACET_INDEX_MAX) _clIter = _rclFAry.begin() + _clIter->_aulNeighbours[usN]; else End(); @@ -423,7 +423,7 @@ inline MeshPointIterator::MeshPointIterator (const MeshKernel &rclM) _clIter = _rclPAry.begin(); } -inline MeshPointIterator::MeshPointIterator (const MeshKernel &rclM, unsigned long ulPos) +inline MeshPointIterator::MeshPointIterator (const MeshKernel &rclM, PointIndex ulPos) : _rclMesh(rclM), _rclPAry(_rclMesh._aclPointArray), _bApply(false) { _clIter = _rclPAry.begin() + ulPos; @@ -442,7 +442,7 @@ inline void MeshPointIterator::Transform( const Base::Matrix4D& rclTrf ) _clTrf != tmp ? _bApply = true : _bApply = false; } -inline const MeshPoint& MeshPointIterator::Dereference (void) const +inline const MeshPoint& MeshPointIterator::Dereference () const { // We change only the value of the point but not the actual iterator const_cast(this)->_clPoint = *_clIter; if ( _bApply ) @@ -450,7 +450,7 @@ inline const MeshPoint& MeshPointIterator::Dereference (void) const return _clPoint; } -inline bool MeshPointIterator::Set (unsigned long ulIndex) +inline bool MeshPointIterator::Set (PointIndex ulIndex) { if (ulIndex < _rclPAry.size()) { diff --git a/src/Mod/Mesh/App/Core/KDTree.cpp b/src/Mod/Mesh/App/Core/KDTree.cpp index adf5b39dcd..2620f8565d 100644 --- a/src/Mod/Mesh/App/Core/KDTree.cpp +++ b/src/Mod/Mesh/App/Core/KDTree.cpp @@ -37,7 +37,7 @@ struct Point3d { typedef float value_type; - Point3d(const Base::Vector3f& f, unsigned long i) : p(f), i(i) + Point3d(const Base::Vector3f& f, PointIndex i) : p(f), i(i) { } @@ -71,7 +71,7 @@ struct Point3d } Base::Vector3f p; - unsigned long i; + PointIndex i; }; typedef KDTree::KDTree<3, Point3d> MyKDTree; @@ -88,7 +88,7 @@ MeshKDTree::MeshKDTree() : d(new Private) MeshKDTree::MeshKDTree(const std::vector& points) : d(new Private) { - unsigned long index=0; + PointIndex index=0; for (std::vector::const_iterator it = points.begin(); it != points.end(); ++it) { d->kd_tree.insert(Point3d(*it, index++)); } @@ -96,7 +96,7 @@ MeshKDTree::MeshKDTree(const std::vector& points) : d(new Privat MeshKDTree::MeshKDTree(const MeshPointArray& points) : d(new Private) { - unsigned long index=0; + PointIndex index=0; for (MeshPointArray::_TConstIterator it = points.begin(); it != points.end(); ++it) { d->kd_tree.insert(Point3d(*it, index++)); } @@ -109,13 +109,13 @@ MeshKDTree::~MeshKDTree() void MeshKDTree::AddPoint(Base::Vector3f& point) { - unsigned long index=d->kd_tree.size(); + PointIndex index=d->kd_tree.size(); d->kd_tree.insert(Point3d(point, index)); } void MeshKDTree::AddPoints(const std::vector& points) { - unsigned long index=d->kd_tree.size(); + PointIndex index=d->kd_tree.size(); for (std::vector::const_iterator it = points.begin(); it != points.end(); ++it) { d->kd_tree.insert(Point3d(*it, index++)); } @@ -123,7 +123,7 @@ void MeshKDTree::AddPoints(const std::vector& points) void MeshKDTree::AddPoints(const MeshPointArray& points) { - unsigned long index=d->kd_tree.size(); + PointIndex index=d->kd_tree.size(); for (MeshPointArray::_TConstIterator it = points.begin(); it != points.end(); ++it) { d->kd_tree.insert(Point3d(*it, index++)); } @@ -144,42 +144,42 @@ void MeshKDTree::Optimize() d->kd_tree.optimize(); } -unsigned long MeshKDTree::FindNearest(const Base::Vector3f& p, Base::Vector3f& n, float& dist) const +PointIndex MeshKDTree::FindNearest(const Base::Vector3f& p, Base::Vector3f& n, float& dist) const { std::pair it = d->kd_tree.find_nearest(Point3d(p,0)); if (it.first == d->kd_tree.end()) - return ULONG_MAX; - unsigned long index = it.first->i; + return POINT_INDEX_MAX; + PointIndex index = it.first->i; n = it.first->p; dist = it.second; return index; } -unsigned long MeshKDTree::FindNearest(const Base::Vector3f& p, float max_dist, - Base::Vector3f& n, float& dist) const +PointIndex MeshKDTree::FindNearest(const Base::Vector3f& p, float max_dist, + Base::Vector3f& n, float& dist) const { std::pair it = d->kd_tree.find_nearest(Point3d(p,0), max_dist); if (it.first == d->kd_tree.end()) - return ULONG_MAX; - unsigned long index = it.first->i; + return POINT_INDEX_MAX; + PointIndex index = it.first->i; n = it.first->p; dist = it.second; return index; } -unsigned long MeshKDTree::FindExact(const Base::Vector3f& p) const +PointIndex MeshKDTree::FindExact(const Base::Vector3f& p) const { MyKDTree::const_iterator it = d->kd_tree.find_exact(Point3d(p,0)); if (it == d->kd_tree.end()) - return ULONG_MAX; - unsigned long index = it->i; + return POINT_INDEX_MAX; + PointIndex index = it->i; return index; } -void MeshKDTree::FindInRange(const Base::Vector3f& p, float range, std::vector& indices) const +void MeshKDTree::FindInRange(const Base::Vector3f& p, float range, std::vector& indices) const { std::vector v; d->kd_tree.find_within_range(Point3d(p,0), range, std::back_inserter(v)); diff --git a/src/Mod/Mesh/App/Core/KDTree.h b/src/Mod/Mesh/App/Core/KDTree.h index 39e396368c..0ed64ae82e 100644 --- a/src/Mod/Mesh/App/Core/KDTree.h +++ b/src/Mod/Mesh/App/Core/KDTree.h @@ -45,11 +45,11 @@ public: void Clear(); void Optimize(); - unsigned long FindNearest(const Base::Vector3f& p, Base::Vector3f& n, float&) const; - unsigned long FindNearest(const Base::Vector3f& p, float max_dist, + PointIndex FindNearest(const Base::Vector3f& p, Base::Vector3f& n, float&) const; + PointIndex FindNearest(const Base::Vector3f& p, float max_dist, Base::Vector3f& n, float&) const; - unsigned long FindExact(const Base::Vector3f& p) const; - void FindInRange(const Base::Vector3f&, float, std::vector&) const; + PointIndex FindExact(const Base::Vector3f& p) const; + void FindInRange(const Base::Vector3f&, float, std::vector&) const; private: class Private; diff --git a/src/Mod/Mesh/App/Core/MeshIO.cpp b/src/Mod/Mesh/App/Core/MeshIO.cpp index 5184bff722..7a18de2d54 100644 --- a/src/Mod/Mesh/App/Core/MeshIO.cpp +++ b/src/Mod/Mesh/App/Core/MeshIO.cpp @@ -58,7 +58,7 @@ char *upper(char * string) int i; int l; - if (string != NULL) { + if (string != nullptr) { l = std::strlen(string); for (i=0; ipubseekoff(0, std::ios::beg, std::ios::in); return LoadBinarySTL(rstrIn); @@ -1578,7 +1578,7 @@ bool MeshInput::LoadInventor (std::istream &rstrIn) } // read the point indices of the facets else if (points && line.find("INDEXEDFACESET {") != std::string::npos) { - unsigned long ulPoints[3]; + PointIndex ulPoints[3]; facets = true; unsigned long ulCt = 0; // Get the next line and check for the index field which might begin @@ -2062,7 +2062,6 @@ bool MeshOutput::SaveAsciiSTL (std::ostream &rstrOut) const MeshFacetIterator clIter(_rclMesh), clEnd(_rclMesh); clIter.Transform(this->_transform); const MeshGeomFacet *pclFacet; - unsigned long i; if (!rstrOut || rstrOut.bad() == true || _rclMesh.CountFacets() == 0) return false; @@ -2088,7 +2087,7 @@ bool MeshOutput::SaveAsciiSTL (std::ostream &rstrOut) const rstrOut << " outer loop\n"; // vertices - for (i = 0; i < 3; i++) { + for (int i = 0; i < 3; i++) { rstrOut << " vertex " << pclFacet->_aclPoints[i].x << " " << pclFacet->_aclPoints[i].y << " " << pclFacet->_aclPoints[i].z << '\n'; @@ -2305,7 +2304,7 @@ bool MeshOutput::SaveOBJ (std::ostream &out) const for (std::vector::const_iterator gt = _groups.begin(); gt != _groups.end(); ++gt) { out << "g " << Base::Tools::escapedUnicodeFromUtf8(gt->name.c_str()) << '\n'; - for (std::vector::const_iterator it = gt->indices.begin(); it != gt->indices.end(); ++it) { + for (std::vector::const_iterator it = gt->indices.begin(); it != gt->indices.end(); ++it) { const MeshFacet& f = rFacets[*it]; if (first || prev != Kd[*it]) { first = false; @@ -2326,7 +2325,7 @@ bool MeshOutput::SaveOBJ (std::ostream &out) const else { for (std::vector::const_iterator gt = _groups.begin(); gt != _groups.end(); ++gt) { out << "g " << Base::Tools::escapedUnicodeFromUtf8(gt->name.c_str()) << '\n'; - for (std::vector::const_iterator it = gt->indices.begin(); it != gt->indices.end(); ++it) { + for (std::vector::const_iterator it = gt->indices.begin(); it != gt->indices.end(); ++it) { const MeshFacet& f = rFacets[*it]; out << "f " << f._aulPoints[0]+1 << "//" << *it + 1 << " " << f._aulPoints[1]+1 << "//" << *it + 1 << " " @@ -3473,7 +3472,7 @@ bool MeshOutput::SaveVRML (std::ostream &rstrOut) const MeshCleanup::MeshCleanup(MeshPointArray& p, MeshFacetArray& f) : pointArray(p) , facetArray(f) - , materialArray(0) + , materialArray(nullptr) { } @@ -3553,12 +3552,12 @@ void MeshCleanup::RemoveInvalidPoints() [flag](const MeshPoint& p) { return flag(p, MeshPoint::INVALID); }); if (countInvalidPoints > 0) { // generate array of decrements - std::vector decrements; + std::vector decrements; decrements.resize(pointArray.size()); - unsigned long decr = 0; + PointIndex decr = 0; MeshPointArray::_TIterator p_end = pointArray.end(); - std::vector::iterator decr_it = decrements.begin(); + std::vector::iterator decr_it = decrements.begin(); for (MeshPointArray::_TIterator p_it = pointArray.begin(); p_it != p_end; ++p_it, ++decr_it) { *decr_it = decr; if (!p_it->IsValid()) @@ -3655,7 +3654,7 @@ void MeshPointFacetAdjacency::SetFacetNeighbourhood() } if (!success) { - facet1._aulNeighbours[i] = ULONG_MAX; + facet1._aulNeighbours[i] = FACET_INDEX_MAX; } } } diff --git a/src/Mod/Mesh/App/Core/MeshIO.h b/src/Mod/Mesh/App/Core/MeshIO.h index 8c89b90c70..fdb369c348 100644 --- a/src/Mod/Mesh/App/Core/MeshIO.h +++ b/src/Mod/Mesh/App/Core/MeshIO.h @@ -79,7 +79,7 @@ struct MeshExport Material struct MeshExport Group { - std::vector indices; + std::vector indices; std::string name; }; diff --git a/src/Mod/Mesh/App/Core/MeshKernel.cpp b/src/Mod/Mesh/App/Core/MeshKernel.cpp index dbcc8570b8..cca4dd085f 100644 --- a/src/Mod/Mesh/App/Core/MeshKernel.cpp +++ b/src/Mod/Mesh/App/Core/MeshKernel.cpp @@ -47,7 +47,7 @@ using namespace MeshCore; -MeshKernel::MeshKernel (void) +MeshKernel::MeshKernel () : _bValid(true) { _clBoundBox.SetVoid(); @@ -115,11 +115,10 @@ MeshKernel& MeshKernel::operator += (const MeshGeomFacet &rclSFacet) void MeshKernel::AddFacet(const MeshGeomFacet &rclSFacet) { - unsigned long i; MeshFacet clFacet; // set corner points - for (i = 0; i < 3; i++) { + for (int i = 0; i < 3; i++) { _clBoundBox.Add(rclSFacet._aclPoints[i]); clFacet._aulPoints[i] = _aclPointArray.GetOrAddIndex(rclSFacet._aclPoints[i]); } @@ -127,17 +126,17 @@ void MeshKernel::AddFacet(const MeshGeomFacet &rclSFacet) // adjust orientation to normal AdjustNormal(clFacet, rclSFacet.GetNormal()); - unsigned long ulCt = _aclFacetArray.size(); + FacetIndex ulCt = _aclFacetArray.size(); // set neighbourhood - unsigned long ulP0 = clFacet._aulPoints[0]; - unsigned long ulP1 = clFacet._aulPoints[1]; - unsigned long ulP2 = clFacet._aulPoints[2]; - unsigned long ulCC = 0; + PointIndex ulP0 = clFacet._aulPoints[0]; + PointIndex ulP1 = clFacet._aulPoints[1]; + PointIndex ulP2 = clFacet._aulPoints[2]; + FacetIndex ulCC = 0; for (TMeshFacetArray::iterator pF = _aclFacetArray.begin(); pF != _aclFacetArray.end(); ++pF, ulCC++) { for (int i=0; i<3;i++) { - unsigned long ulP = pF->_aulPoints[i]; - unsigned long ulQ = pF->_aulPoints[(i+1)%3]; + PointIndex ulP = pF->_aulPoints[i]; + PointIndex ulQ = pF->_aulPoints[(i+1)%3]; if (ulQ == ulP0 && ulP == ulP1) { clFacet._aulNeighbours[0] = ulCC; pF->_aulNeighbours[i] = ulCt; @@ -183,8 +182,8 @@ unsigned long MeshKernel::AddFacets(const std::vector &rclFAry, // if the manifold check shouldn't be done then just add all faces if (!checkManifolds) { - unsigned long countFacets = CountFacets(); - unsigned long countValid = rclFAry.size(); + FacetIndex countFacets = CountFacets(); + FacetIndex countValid = rclFAry.size(); _aclFacetArray.reserve(countFacets + countValid); // just add all faces now @@ -197,8 +196,8 @@ unsigned long MeshKernel::AddFacets(const std::vector &rclFAry, } this->_aclPointArray.ResetInvalid(); - unsigned long k = CountFacets(); - std::map, std::list > edgeMap; + FacetIndex k = CountFacets(); + std::map, std::list > edgeMap; for (std::vector::const_iterator pF = rclFAry.begin(); pF != rclFAry.end(); ++pF, k++) { // reset INVALID flag for all candidates pF->ResetFlag(MeshFacet::INVALID); @@ -207,10 +206,10 @@ unsigned long MeshKernel::AddFacets(const std::vector &rclFAry, assert( pF->_aulPoints[i] < countPoints ); #endif this->_aclPointArray[pF->_aulPoints[i]].SetFlag(MeshPoint::INVALID); - unsigned long ulT0 = pF->_aulPoints[i]; - unsigned long ulT1 = pF->_aulPoints[(i+1)%3]; - unsigned long ulP0 = std::min(ulT0, ulT1); - unsigned long ulP1 = std::max(ulT0, ulT1); + PointIndex ulT0 = pF->_aulPoints[i]; + PointIndex ulT1 = pF->_aulPoints[(i+1)%3]; + PointIndex ulP0 = std::min(ulT0, ulT1); + PointIndex ulP1 = std::max(ulT0, ulT1); edgeMap[std::make_pair(ulP0, ulP1)].push_front(k); } } @@ -224,12 +223,12 @@ unsigned long MeshKernel::AddFacets(const std::vector &rclFAry, !this->_aclPointArray[pF->_aulPoints[2]].IsFlag(MeshPoint::INVALID)) continue; for (int i=0; i<3; i++) { - unsigned long ulT0 = pF->_aulPoints[i]; - unsigned long ulT1 = pF->_aulPoints[(i+1)%3]; - unsigned long ulP0 = std::min(ulT0, ulT1); - unsigned long ulP1 = std::max(ulT0, ulT1); - std::pair edge = std::make_pair(ulP0, ulP1); - std::map, std::list >::iterator pI = edgeMap.find(edge); + PointIndex ulT0 = pF->_aulPoints[i]; + PointIndex ulT1 = pF->_aulPoints[(i+1)%3]; + PointIndex ulP0 = std::min(ulT0, ulT1); + PointIndex ulP1 = std::max(ulT0, ulT1); + std::pair edge = std::make_pair(ulP0, ulP1); + std::map, std::list >::iterator pI = edgeMap.find(edge); // Does the current facet share the same edge? if (pI != edgeMap.end()) { pI->second.push_front(k); @@ -240,17 +239,17 @@ unsigned long MeshKernel::AddFacets(const std::vector &rclFAry, this->_aclPointArray.ResetInvalid(); // Now let's see for which edges we might get manifolds, if so we don't add the corresponding candidates - unsigned long countFacets = CountFacets(); - std::map, std::list >::iterator pE; + FacetIndex countFacets = CountFacets(); + std::map, std::list >::iterator pE; for (pE = edgeMap.begin(); pE != edgeMap.end(); ++pE) { if (pE->second.size() > 2) { - for (std::list::iterator it = pE->second.begin(); it != pE->second.end(); ++it) + for (std::list::iterator it = pE->second.begin(); it != pE->second.end(); ++it) { if (*it >= countFacets) { // this is a candidate - unsigned long index = *it - countFacets; + FacetIndex index = *it - countFacets; rclFAry[index].SetFlag(MeshFacet::INVALID); } } @@ -260,12 +259,12 @@ 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 MeshIsNotFlag flag; - unsigned long countValid = std::count_if(rclFAry.begin(), rclFAry.end(), [flag](const MeshFacet& f) { + FacetIndex 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(); + FacetIndex startIndex = CountFacets(); for (std::vector::const_iterator pF = rclFAry.begin(); pF != rclFAry.end(); ++pF) { if (!pF->IsFlag(MeshFacet::INVALID)) { _aclFacetArray.push_back(*pF); @@ -276,55 +275,55 @@ unsigned long MeshKernel::AddFacets(const std::vector &rclFAry, // resolve neighbours for (pE = edgeMap.begin(); pE != edgeMap.end(); ++pE) { - unsigned long ulP0 = pE->first.first; - unsigned long ulP1 = pE->first.second; + PointIndex ulP0 = pE->first.first; + PointIndex ulP1 = pE->first.second; if (pE->second.size() == 1) // border facet { - unsigned long ulF0 = pE->second.front(); + FacetIndex ulF0 = pE->second.front(); if (ulF0 >= countFacets) { ulF0 -= countFacets; std::vector::const_iterator pF = rclFAry.begin() + ulF0; if (!pF->IsFlag(MeshFacet::INVALID)) ulF0 = pF->_ulProp; else - ulF0 = ULONG_MAX; + ulF0 = FACET_INDEX_MAX; } - if (ulF0 != ULONG_MAX) { + if (ulF0 != FACET_INDEX_MAX) { unsigned short usSide = _aclFacetArray[ulF0].Side(ulP0, ulP1); assert(usSide != USHRT_MAX); - _aclFacetArray[ulF0]._aulNeighbours[usSide] = ULONG_MAX; + _aclFacetArray[ulF0]._aulNeighbours[usSide] = FACET_INDEX_MAX; } } else if (pE->second.size() == 2) // normal facet with neighbour { // we must check if both facets are part of the mesh now - unsigned long ulF0 = pE->second.front(); + FacetIndex ulF0 = pE->second.front(); if (ulF0 >= countFacets) { ulF0 -= countFacets; std::vector::const_iterator pF = rclFAry.begin() + ulF0; if (!pF->IsFlag(MeshFacet::INVALID)) ulF0 = pF->_ulProp; else - ulF0 = ULONG_MAX; + ulF0 = FACET_INDEX_MAX; } - unsigned long ulF1 = pE->second.back(); + FacetIndex ulF1 = pE->second.back(); if (ulF1 >= countFacets) { ulF1 -= countFacets; std::vector::const_iterator pF = rclFAry.begin() + ulF1; if (!pF->IsFlag(MeshFacet::INVALID)) ulF1 = pF->_ulProp; else - ulF1 = ULONG_MAX; + ulF1 = FACET_INDEX_MAX; } - if (ulF0 != ULONG_MAX) { + if (ulF0 != FACET_INDEX_MAX) { unsigned short usSide = _aclFacetArray[ulF0].Side(ulP0, ulP1); assert(usSide != USHRT_MAX); _aclFacetArray[ulF0]._aulNeighbours[usSide] = ulF1; } - if (ulF1 != ULONG_MAX) { + if (ulF1 != FACET_INDEX_MAX) { unsigned short usSide = _aclFacetArray[ulF1].Side(ulP0, ulP1); assert(usSide != USHRT_MAX); _aclFacetArray[ulF1]._aulNeighbours[usSide] = ulF0; @@ -360,7 +359,7 @@ void MeshKernel::Merge(const MeshPointArray& rPoints, const MeshFacetArray& rFac return; // nothing to do std::vector increments(rPoints.size()); - unsigned long countFacets = this->_aclFacetArray.size(); + FacetIndex countFacets = this->_aclFacetArray.size(); // Reserve the additional memory to append the new facets this->_aclFacetArray.reserve(this->_aclFacetArray.size() + rFaces.size()); @@ -380,7 +379,7 @@ void MeshKernel::Merge(const MeshPointArray& rPoints, const MeshFacetArray& rFac return v > 0; }); // Reserve the additional memory to append the new points - unsigned long index = this->_aclPointArray.size(); + PointIndex index = this->_aclPointArray.size(); this->_aclPointArray.reserve(this->_aclPointArray.size() + countNewPoints); // Now we can start inserting the points and adjust the point indices of the faces @@ -414,7 +413,7 @@ void MeshKernel::Cleanup() meshCleanup.RemoveInvalids(); } -void MeshKernel::Clear (void) +void MeshKernel::Clear () { _aclPointArray.clear(); _aclFacetArray.clear(); @@ -428,7 +427,7 @@ void MeshKernel::Clear (void) bool MeshKernel::DeleteFacet (const MeshFacetIterator &rclIter) { - unsigned long i, j, ulNFacet, ulInd; + FacetIndex ulNFacet, ulInd; if (rclIter._clIter >= _aclFacetArray.end()) return false; @@ -437,12 +436,12 @@ bool MeshKernel::DeleteFacet (const MeshFacetIterator &rclIter) ulInd = rclIter._clIter - _aclFacetArray.begin(); // invalidate neighbour indices of the neighbour facet to this facet - for (i = 0; i < 3; i++) { + for (int i = 0; i < 3; i++) { ulNFacet = rclIter._clIter->_aulNeighbours[i]; - if (ulNFacet != ULONG_MAX) { - for (j = 0; j < 3; j++) { + if (ulNFacet != FACET_INDEX_MAX) { + for (int j = 0; j < 3; j++) { if (_aclFacetArray[ulNFacet]._aulNeighbours[j] == ulInd) { - _aclFacetArray[ulNFacet]._aulNeighbours[j] = ULONG_MAX; + _aclFacetArray[ulNFacet]._aulNeighbours[j] = FACET_INDEX_MAX; break; } } @@ -450,9 +449,9 @@ bool MeshKernel::DeleteFacet (const MeshFacetIterator &rclIter) } // erase corner point if needed - for (i = 0; i < 3; i++) { - if ((rclIter._clIter->_aulNeighbours[i] == ULONG_MAX) && - (rclIter._clIter->_aulNeighbours[(i+1)%3] == ULONG_MAX)) { + for (int i = 0; i < 3; i++) { + if ((rclIter._clIter->_aulNeighbours[i] == FACET_INDEX_MAX) && + (rclIter._clIter->_aulNeighbours[(i+1)%3] == FACET_INDEX_MAX)) { // no neighbours, possibly delete point ErasePoint(rclIter._clIter->_aulPoints[(i+1)%3], ulInd); } @@ -464,7 +463,7 @@ bool MeshKernel::DeleteFacet (const MeshFacetIterator &rclIter) return true; } -bool MeshKernel::DeleteFacet (unsigned long ulInd) +bool MeshKernel::DeleteFacet (FacetIndex ulInd) { if (ulInd >= _aclFacetArray.size()) return false; @@ -475,7 +474,7 @@ bool MeshKernel::DeleteFacet (unsigned long ulInd) return DeleteFacet(clIter); } -void MeshKernel::DeleteFacets (const std::vector &raulFacets) +void MeshKernel::DeleteFacets (const std::vector &raulFacets) { _aclPointArray.SetProperty(0); @@ -488,7 +487,7 @@ void MeshKernel::DeleteFacets (const std::vector &raulFacets) // invalidate facet and adjust number of point references _aclFacetArray.ResetInvalid(); - for (std::vector::const_iterator pI = raulFacets.begin(); pI != raulFacets.end(); ++pI) { + for (std::vector::const_iterator pI = raulFacets.begin(); pI != raulFacets.end(); ++pI) { MeshFacet &rclFacet = _aclFacetArray[*pI]; rclFacet.SetInvalid(); _aclPointArray[rclFacet._aulPoints[0]]._ulProp--; @@ -507,7 +506,7 @@ void MeshKernel::DeleteFacets (const std::vector &raulFacets) RecalcBoundBox(); } -bool MeshKernel::DeletePoint (unsigned long ulInd) +bool MeshKernel::DeletePoint (PointIndex ulInd) { if (ulInd >= _aclPointArray.size()) return false; @@ -522,7 +521,7 @@ bool MeshKernel::DeletePoint (const MeshPointIterator &rclIter) { MeshFacetIterator pFIter(*this), pFEnd(*this); std::vector clToDel; - unsigned long ulInd; + PointIndex ulInd; // index of the point to delete ulInd = rclIter._clIter - _aclPointArray.begin(); @@ -549,10 +548,10 @@ bool MeshKernel::DeletePoint (const MeshPointIterator &rclIter) return true; } -void MeshKernel::DeletePoints (const std::vector &raulPoints) +void MeshKernel::DeletePoints (const std::vector &raulPoints) { _aclPointArray.ResetInvalid(); - for (std::vector::const_iterator pI = raulPoints.begin(); pI != raulPoints.end(); ++pI) + for (std::vector::const_iterator pI = raulPoints.begin(); pI != raulPoints.end(); ++pI) _aclPointArray[*pI].SetInvalid(); // delete facets if at least one corner point is invalid @@ -583,9 +582,8 @@ void MeshKernel::DeletePoints (const std::vector &raulPoints) RecalcBoundBox(); } -void MeshKernel::ErasePoint (unsigned long ulIndex, unsigned long ulFacetIndex, bool bOnlySetInvalid) +void MeshKernel::ErasePoint (PointIndex ulIndex, FacetIndex ulFacetIndex, bool bOnlySetInvalid) { - unsigned long i; std::vector::iterator pFIter, pFEnd, pFNot; pFIter = _aclFacetArray.begin(); @@ -594,7 +592,7 @@ void MeshKernel::ErasePoint (unsigned long ulIndex, unsigned long ulFacetIndex, // check all facets while (pFIter < pFNot) { - for (i = 0; i < 3; i++) { + for (int i = 0; i < 3; i++) { if (pFIter->_aulPoints[i] == ulIndex) return; // point still referenced ==> do not delete } @@ -603,7 +601,7 @@ void MeshKernel::ErasePoint (unsigned long ulIndex, unsigned long ulFacetIndex, ++pFIter; while (pFIter < pFEnd) { - for (i = 0; i < 3; i++) { + for (int i = 0; i < 3; i++) { if (pFIter->_aulPoints[i] == ulIndex) return; // point still referenced ==> do not delete } @@ -618,7 +616,7 @@ void MeshKernel::ErasePoint (unsigned long ulIndex, unsigned long ulFacetIndex, // correct point indices of the facets pFIter = _aclFacetArray.begin(); while (pFIter < pFEnd) { - for (i = 0; i < 3; i++) { + for (int i = 0; i < 3; i++) { if (pFIter->_aulPoints[i] > ulIndex) pFIter->_aulPoints[i]--; } @@ -633,7 +631,7 @@ void MeshKernel::RemoveInvalids () { std::vector aulDecrements; std::vector::iterator pDIter; - unsigned long ulDec, i, k; + unsigned long ulDec; MeshPointArray::_TIterator pPIter, pPEnd; MeshFacetArray::_TIterator pFIter, pFEnd; @@ -691,13 +689,13 @@ void MeshKernel::RemoveInvalids () pFEnd = _aclFacetArray.end(); for (pFIter = _aclFacetArray.begin(); pFIter != pFEnd; ++pFIter) { if (pFIter->IsValid() == true) { - for (i = 0; i < 3; i++) { - k = pFIter->_aulNeighbours[i]; - if (k != ULONG_MAX) { + for (int i = 0; i < 3; i++) { + FacetIndex k = pFIter->_aulNeighbours[i]; + if (k != FACET_INDEX_MAX) { if (_aclFacetArray[k].IsValid() == true) pFIter->_aulNeighbours[i] -= aulDecrements[k]; else - pFIter->_aulNeighbours[i] = ULONG_MAX; + pFIter->_aulNeighbours[i] = FACET_INDEX_MAX; } } } @@ -722,28 +720,28 @@ void MeshKernel::RemoveInvalids () void MeshKernel::CutFacets(const MeshFacetGrid& rclGrid, const Base::ViewProjMethod* pclProj, const Base::Polygon2d& rclPoly, bool bCutInner, std::vector &raclFacets) { - std::vector aulFacets; + std::vector aulFacets; MeshAlgorithm(*this).CheckFacets(rclGrid, pclProj, rclPoly, bCutInner, aulFacets ); - for (std::vector::iterator i = aulFacets.begin(); i != aulFacets.end(); ++i) + for (std::vector::iterator i = aulFacets.begin(); i != aulFacets.end(); ++i) raclFacets.push_back(GetFacet(*i)); DeleteFacets(aulFacets); } void MeshKernel::CutFacets(const MeshFacetGrid& rclGrid, const Base::ViewProjMethod* pclProj, - const Base::Polygon2d& rclPoly, bool bInner, std::vector &raclCutted) + const Base::Polygon2d& rclPoly, bool bInner, std::vector &raclCutted) { MeshAlgorithm(*this).CheckFacets(rclGrid, pclProj, rclPoly, bInner, raclCutted); DeleteFacets(raclCutted); } -std::vector MeshKernel::GetFacetPoints(const std::vector& facets) const +std::vector MeshKernel::GetFacetPoints(const std::vector& facets) const { - std::vector points; - for (std::vector::const_iterator it = facets.begin(); it != facets.end(); ++it) { - unsigned long p0, p1, p2; + std::vector points; + for (std::vector::const_iterator it = facets.begin(); it != facets.end(); ++it) { + PointIndex p0, p1, p2; GetFacetPoints(*it, p0, p1, p2); points.push_back(p0); points.push_back(p1); @@ -755,11 +753,11 @@ std::vector MeshKernel::GetFacetPoints(const std::vector MeshKernel::GetPointFacets(const std::vector& points) const +std::vector MeshKernel::GetPointFacets(const std::vector& points) const { _aclPointArray.ResetFlag(MeshPoint::TMP0); _aclFacetArray.ResetFlag(MeshFacet::TMP0); - for (std::vector::const_iterator pI = points.begin(); pI != points.end(); ++pI) + for (std::vector::const_iterator pI = points.begin(); pI != points.end(); ++pI) _aclPointArray[*pI].SetFlag(MeshPoint::TMP0); // mark facets if at least one corner point is marked @@ -775,21 +773,21 @@ std::vector MeshKernel::GetPointFacets(const std::vector facets; + std::vector facets; MeshAlgorithm(*this).GetFacetsFlag(facets, MeshFacet::TMP0); return facets; } -std::vector MeshKernel::HasFacets (const MeshPointIterator &rclIter) const +std::vector MeshKernel::HasFacets (const MeshPointIterator &rclIter) const { - unsigned long i, ulPtInd = rclIter.Position(); + PointIndex ulPtInd = rclIter.Position(); std::vector::const_iterator pFIter = _aclFacetArray.begin(); std::vector::const_iterator pFBegin = _aclFacetArray.begin(); std::vector::const_iterator pFEnd = _aclFacetArray.end(); - std::vector aulBelongs; + std::vector aulBelongs; while (pFIter < pFEnd) { - for (i = 0; i < 3; i++) { + for (int i = 0; i < 3; i++) { if (pFIter->_aulPoints[i] == ulPtInd) { aulBelongs.push_back(pFIter - pFBegin); break; @@ -801,20 +799,20 @@ std::vector MeshKernel::HasFacets (const MeshPointIterator &rclIt return aulBelongs; } -MeshPointArray MeshKernel::GetPoints(const std::vector& indices) const +MeshPointArray MeshKernel::GetPoints(const std::vector& indices) const { MeshPointArray ary; ary.reserve(indices.size()); - for (std::vector::const_iterator it = indices.begin(); it != indices.end(); ++it) + for (std::vector::const_iterator it = indices.begin(); it != indices.end(); ++it) ary.push_back(this->_aclPointArray[*it]); return ary; } -MeshFacetArray MeshKernel::GetFacets(const std::vector& indices) const +MeshFacetArray MeshKernel::GetFacets(const std::vector& indices) const { MeshFacetArray ary; ary.reserve(indices.size()); - for (std::vector::const_iterator it = indices.begin(); it != indices.end(); ++it) + for (std::vector::const_iterator it = indices.begin(); it != indices.end(); ++it) ary.push_back(this->_aclFacetArray[*it]); return ary; } @@ -916,7 +914,7 @@ void MeshKernel::Read (std::istream &rclIn) it->_aulPoints[2] = v3; // On systems where an 'unsigned long' is a 64-bit value - // the empty neighbour must be explicitly set to 'ULONG_MAX' + // the empty neighbour must be explicitly set to 'FACET_INDEX_MAX' // because in algorithms this value is always used to check // for open edges. str >> v1 >> v2 >> v3; @@ -932,17 +930,17 @@ void MeshKernel::Read (std::istream &rclIn) if (v1 < open_edge) it->_aulNeighbours[0] = v1; else - it->_aulNeighbours[0] = ULONG_MAX; + it->_aulNeighbours[0] = FACET_INDEX_MAX; if (v2 < open_edge) it->_aulNeighbours[1] = v2; else - it->_aulNeighbours[1] = ULONG_MAX; + it->_aulNeighbours[1] = FACET_INDEX_MAX; if (v3 < open_edge) it->_aulNeighbours[2] = v3; else - it->_aulNeighbours[2] = ULONG_MAX; + it->_aulNeighbours[2] = FACET_INDEX_MAX; } str >> _clBoundBox.MinX >> _clBoundBox.MaxX; @@ -1021,7 +1019,7 @@ void MeshKernel::Read (std::istream &rclIn) for (int i=0; i<3; i++) { if (it->_aulPoints[i] >= uCtPts) throw Base::BadFormatError("Invalid data structure"); - if (it->_aulNeighbours[i] < ULONG_MAX && it->_aulNeighbours[i] >= uCtFts) + if (it->_aulNeighbours[i] < FACET_INDEX_MAX && it->_aulNeighbours[i] >= uCtFts) throw Base::BadFormatError("Invalid data structure"); } } @@ -1055,7 +1053,7 @@ void MeshKernel::Smooth(int iterations, float stepsize) LaplaceSmoothing(*this).Smooth(iterations); } -void MeshKernel::RecalcBoundBox (void) +void MeshKernel::RecalcBoundBox () { _clBoundBox.SetVoid(); for (MeshPointArray::_TConstIterator pI = _aclPointArray.begin(); pI != _aclPointArray.end(); pI++) @@ -1068,7 +1066,7 @@ std::vector MeshKernel::CalcVertexNormals() const normals.resize(CountPoints()); - unsigned long p1,p2,p3; + PointIndex p1,p2,p3; unsigned int ct = CountFacets(); for (unsigned int pFIter = 0;pFIter < ct; pFIter++) { GetFacetPoints(pFIter,p1,p2,p3); @@ -1082,12 +1080,12 @@ std::vector MeshKernel::CalcVertexNormals() const return normals; } -std::vector MeshKernel::GetFacetNormals(const std::vector& facets) const +std::vector MeshKernel::GetFacetNormals(const std::vector& facets) const { std::vector normals; normals.reserve(facets.size()); - for (std::vector::const_iterator it = facets.begin(); it != facets.end(); ++it) { + for (std::vector::const_iterator it = facets.begin(); it != facets.end(); ++it) { const MeshFacet& face = _aclFacetArray[*it]; const Base::Vector3f& p1 = _aclPointArray[face._aulPoints[0]]; @@ -1113,12 +1111,12 @@ float MeshKernel::GetSurface() const return fSurface; } -float MeshKernel::GetSurface( const std::vector& aSegment ) const +float MeshKernel::GetSurface( const std::vector& aSegment ) const { float fSurface = 0.0; MeshFacetIterator cIter(*this); - for (std::vector::const_iterator it = aSegment.begin(); it != aSegment.end(); ++it) { + for (std::vector::const_iterator it = aSegment.begin(); it != aSegment.end(); ++it) { cIter.Set(*it); fSurface += cIter->Area(); } @@ -1196,19 +1194,19 @@ void MeshKernel::GetEdges (std::vector& edges) const MeshGeomEdge edge; edge._aclPoints[0] = this->_aclPointArray[it2->pt1]; edge._aclPoints[1] = this->_aclPointArray[it2->pt2]; - edge._bBorder = it2->facetIdx == ULONG_MAX; + edge._bBorder = it2->facetIdx == FACET_INDEX_MAX; edges.push_back(edge); } } -unsigned long MeshKernel::CountEdges (void) const +unsigned long MeshKernel::CountEdges () const { unsigned long openEdges = 0, closedEdges = 0; for (MeshFacetArray::_TConstIterator it = _aclFacetArray.begin(); it != _aclFacetArray.end(); ++it) { for (int i = 0; i < 3; i++) { - if (it->_aulNeighbours[i] == ULONG_MAX) + if (it->_aulNeighbours[i] == FACET_INDEX_MAX) openEdges++; else closedEdges++; diff --git a/src/Mod/Mesh/App/Core/MeshKernel.h b/src/Mod/Mesh/App/Core/MeshKernel.h index b9e3ff399c..fc7b4abb32 100644 --- a/src/Mod/Mesh/App/Core/MeshKernel.h +++ b/src/Mod/Mesh/App/Core/MeshKernel.h @@ -24,7 +24,7 @@ #ifndef MESH_KERNEL_H #define MESH_KERNEL_H -#include +#include #include #include "Elements.h" @@ -65,11 +65,11 @@ class MeshExport MeshKernel { public: /// Construction - MeshKernel (void); + MeshKernel (); /// Construction MeshKernel (const MeshKernel &rclMesh); /// Destruction - ~MeshKernel (void) + ~MeshKernel () { Clear(); } /** @name I/O methods */ @@ -82,71 +82,71 @@ public: /** @name Querying */ //@{ /// Returns the number of facets - unsigned long CountFacets (void) const + unsigned long CountFacets () const { return static_cast(_aclFacetArray.size()); } /// Returns the number of edge - unsigned long CountEdges (void) const; + unsigned long CountEdges () const; // Returns the number of points - unsigned long CountPoints (void) const + unsigned long CountPoints () const { return static_cast(_aclPointArray.size()); } /// Returns the number of required memory in bytes - unsigned int GetMemSize (void) const + unsigned int GetMemSize () const { return static_cast(_aclPointArray.size() * sizeof(MeshPoint) + _aclFacetArray.size() * sizeof(MeshFacet)); } /// Determines the bounding box - const Base::BoundBox3f& GetBoundBox (void) const + const Base::BoundBox3f& GetBoundBox () const { return _clBoundBox; } /** Forces a recalculation of the bounding box. This method should be called after * the removal of points.or after a transformation of the data structure. */ - void RecalcBoundBox (void); + void RecalcBoundBox (); /** Returns the point at the given index. This method is rather slow and should be * called occasionally only. For fast access the MeshPointIterator interfsce should * be used. */ - inline MeshPoint GetPoint (unsigned long ulIndex) const; + inline MeshPoint GetPoint (PointIndex ulIndex) const; /** Returns an array of the vertex normals of the mesh. A vertex normal gets calculated * by summarizing the normals of the associated facets. */ std::vector CalcVertexNormals() const; - std::vector GetFacetNormals(const std::vector&) const; + std::vector GetFacetNormals(const std::vector&) const; /** Returns the facet at the given index. This method is rather slow and should be * called occasionally only. For fast access the MeshFacetIterator interface should * be used. */ - inline MeshGeomFacet GetFacet (unsigned long ulIndex) const; + inline MeshGeomFacet GetFacet (FacetIndex ulIndex) const; inline MeshGeomFacet GetFacet (const MeshFacet &rclFacet) const; /** Returns the point indices of the given facet index. */ - inline void GetFacetPoints (unsigned long ulFaIndex, unsigned long &rclP0, - unsigned long &rclP1, unsigned long &rclP2) const; + inline void GetFacetPoints (FacetIndex ulFaIndex, PointIndex &rclP0, + PointIndex &rclP1, PointIndex &rclP2) const; /** Returns the point indices of the given facet indices. */ - std::vector GetFacetPoints(const std::vector&) const; + std::vector GetFacetPoints(const std::vector&) const; /** Returns the facet indices that share the given point indices. */ - std::vector GetPointFacets(const std::vector&) const; + std::vector GetPointFacets(const std::vector&) const; /** Returns the indices of the neighbour facets of the given facet index. */ - inline void GetFacetNeighbours (unsigned long ulIndex, unsigned long &rulNIdx0, - unsigned long &rulNIdx1, unsigned long &rulNIdx2) const; + inline void GetFacetNeighbours (FacetIndex ulIndex, FacetIndex &rulNIdx0, + FacetIndex &rulNIdx1, FacetIndex &rulNIdx2) const; /** Determines all facets that are associated to this point. This method is very * slow and should be called occasionally only. */ - std::vector HasFacets (const MeshPointIterator &rclIter) const; + std::vector HasFacets (const MeshPointIterator &rclIter) const; /** Returns true if the data structure is valid. */ - bool IsValid (void) const + bool IsValid () const { return _bValid; } /** Returns the array of all data points. */ - const MeshPointArray& GetPoints (void) const { return _aclPointArray; } + const MeshPointArray& GetPoints () const { return _aclPointArray; } /** Returns an array of points to the given indices. The indices * must not be out of range. */ - MeshPointArray GetPoints(const std::vector&) const; + MeshPointArray GetPoints(const std::vector&) const; /** Returns a modifier for the point array */ MeshPointModifier ModifyPoints() @@ -155,11 +155,11 @@ public: } /** Returns the array of all facets */ - const MeshFacetArray& GetFacets (void) const { return _aclFacetArray; } + const MeshFacetArray& GetFacets () const { return _aclFacetArray; } /** Returns an array of facets to the given indices. The indices * must not be out of range. */ - MeshFacetArray GetFacets(const std::vector&) const; + MeshFacetArray GetFacets(const std::vector&) const; /** Returns a modifier for the facet array */ MeshFacetModifier ModifyFacets() @@ -179,7 +179,7 @@ public: /** Calculates the surface area of the mesh object. */ float GetSurface() const; /** Calculates the surface area of the segment defined by \a aSegment. */ - float GetSurface( const std::vector& aSegment ) const; + float GetSurface( const std::vector& aSegment ) const; /** Calculates the volume of the mesh object. Therefore the mesh must be a solid, if not 0 * is returned. */ @@ -216,12 +216,12 @@ public: * \note For the start facet \a ulStartFacet MeshFacetVisitor::Visit() does not get invoked though * the facet gets marked as VISIT. */ - unsigned long VisitNeighbourFacets (MeshFacetVisitor &rclFVisitor, unsigned long ulStartFacet) const; + unsigned long VisitNeighbourFacets (MeshFacetVisitor &rclFVisitor, FacetIndex ulStartFacet) const; /** * Does basically the same as the method above unless the facets that share just a common point * are regared as neighbours. */ - unsigned long VisitNeighbourFacetsOverCorners (MeshFacetVisitor &rclFVisitor, unsigned long ulStartFacet) const; + unsigned long VisitNeighbourFacetsOverCorners (MeshFacetVisitor &rclFVisitor, FacetIndex ulStartFacet) const; //@} /** @name Point visitors @@ -243,7 +243,7 @@ public: * \note For the start facet \a ulStartPoint MeshPointVisitor::Visit() does not get invoked though * the point gets marked as VISIT. */ - unsigned long VisitNeighbourPoints (MeshPointVisitor &rclPVisitor, unsigned long ulStartPoint) const; + unsigned long VisitNeighbourPoints (MeshPointVisitor &rclPVisitor, PointIndex ulStartPoint) const; //@} /** @name Iterators @@ -346,14 +346,14 @@ public: /** * Does basically the same as the method above unless that the index of the facet is given. */ - bool DeleteFacet (unsigned long ulInd); + bool DeleteFacet (FacetIndex ulInd); /** Removes several facets from the data structure. * @note This method overwrites the free usable property of each mesh point. * @note This method also removes points from the structure that are no longer * referenced by the facets. * @note This method is very slow and should only be called occasionally. */ - void DeleteFacets (const std::vector &raulFacets); + void DeleteFacets (const std::vector &raulFacets); /** Deletes the point the iterator points to. The deletion of a point requires the following step: * \li Find all associated facets to this point. * \li Delete these facets. @@ -366,19 +366,19 @@ public: /** * Does basically the same as the method above unless that the index of the facet is given. */ - bool DeletePoint (unsigned long ulInd); + bool DeletePoint (PointIndex ulInd); /** Removes several points from the data structure. * @note This method overwrites the free usable property of each mesh point. */ - void DeletePoints (const std::vector &raulPoints); + void DeletePoints (const std::vector &raulPoints); /** Removes all as INVALID marked points and facets from the structure. */ void RemoveInvalids (); /** Rebuilds the neighbour indices for all facets. */ - void RebuildNeighbours (void); + void RebuildNeighbours (); /** Removes unreferenced points or facets with invalid indices from the mesh. */ void Cleanup(); /** Clears the whole data structure. */ - void Clear (void); + void Clear (); /** Replaces the current data structure with the structure built up of the array * of triangles given in \a rclFAry. */ @@ -404,11 +404,11 @@ public: */ void Transform (const Base::Matrix4D &rclMat); /** Moves the point at the given index along the vector \a rclTrans. */ - inline void MovePoint (unsigned long ulPtIndex, const Base::Vector3f &rclTrans); + inline void MovePoint (PointIndex ulPtIndex, const Base::Vector3f &rclTrans); /** Sets the point at the given index to the new \a rPoint. */ - inline void SetPoint (unsigned long ulPtIndex, const Base::Vector3f &rPoint); + inline void SetPoint (PointIndex ulPtIndex, const Base::Vector3f &rPoint); /** Sets the point at the given index to the new \a rPoint. */ - inline void SetPoint (unsigned long ulPtIndex, float x, float y, float z); + inline void SetPoint (PointIndex ulPtIndex, float x, float y, float z); /** Smoothes the mesh kernel. */ void Smooth(int iterations, float d_max); /** @@ -423,19 +423,19 @@ public: * index number in the facet array of the mesh structure. */ void CutFacets (const MeshFacetGrid& rclGrid, const Base::ViewProjMethod* pclP, const Base::Polygon2d& rclPoly, - bool bCutInner, std::vector &raclCutted); + bool bCutInner, std::vector &raclCutted); //@} protected: /** Rebuilds the neighbour indices for subset of all facets from index \a index on. */ - void RebuildNeighbours (unsigned long); + void RebuildNeighbours (FacetIndex); /** Checks if this point is associated to no other facet and deletes if so. * The point indices of the facets get adjusted. * \a ulIndex is the index of the point to be deleted. \a ulFacetIndex is the index * of the quasi deleted facet and is ignored. If \a bOnlySetInvalid is true the point * doesn't get deleted but marked as invalid. */ - void ErasePoint (unsigned long ulIndex, unsigned long ulFacetIndex, bool bOnlySetInvalid = false); + void ErasePoint (PointIndex ulIndex, FacetIndex ulFacetIndex, bool bOnlySetInvalid = false); /** Adjusts the facet's orierntation to the given normal direction. */ inline void AdjustNormal (MeshFacet &rclFacet, const Base::Vector3f &rclNormal); @@ -460,13 +460,13 @@ protected: friend class MeshTrimming; }; -inline MeshPoint MeshKernel::GetPoint (unsigned long ulIndex) const +inline MeshPoint MeshKernel::GetPoint (PointIndex ulIndex) const { assert(ulIndex < _aclPointArray.size()); return _aclPointArray[ulIndex]; } -inline MeshGeomFacet MeshKernel::GetFacet (unsigned long ulIndex) const +inline MeshGeomFacet MeshKernel::GetFacet (FacetIndex ulIndex) const { assert(ulIndex < _aclFacetArray.size()); @@ -498,8 +498,8 @@ inline MeshGeomFacet MeshKernel::GetFacet (const MeshFacet &rclFacet) const return clFacet; } -inline void MeshKernel::GetFacetNeighbours (unsigned long ulIndex, unsigned long &rulNIdx0, - unsigned long &rulNIdx1, unsigned long &rulNIdx2) const +inline void MeshKernel::GetFacetNeighbours (FacetIndex ulIndex, FacetIndex &rulNIdx0, + FacetIndex &rulNIdx1, FacetIndex &rulNIdx2) const { assert(ulIndex < _aclFacetArray.size()); @@ -508,17 +508,17 @@ inline void MeshKernel::GetFacetNeighbours (unsigned long ulIndex, unsigned long rulNIdx2 = _aclFacetArray[ulIndex]._aulNeighbours[2]; } -inline void MeshKernel::MovePoint (unsigned long ulPtIndex, const Base::Vector3f &rclTrans) +inline void MeshKernel::MovePoint (PointIndex ulPtIndex, const Base::Vector3f &rclTrans) { _aclPointArray[ulPtIndex] += rclTrans; } -inline void MeshKernel::SetPoint (unsigned long ulPtIndex, const Base::Vector3f &rPoint) +inline void MeshKernel::SetPoint (PointIndex ulPtIndex, const Base::Vector3f &rPoint) { _aclPointArray[ulPtIndex] = rPoint; } -inline void MeshKernel::SetPoint (unsigned long ulPtIndex, float x, float y, float z) +inline void MeshKernel::SetPoint (PointIndex ulPtIndex, float x, float y, float z) { _aclPointArray[ulPtIndex].Set(x,y,z); } @@ -550,8 +550,8 @@ inline Base::Vector3f MeshKernel::GetGravityPoint (const MeshFacet &rclFacet) co (p0.z+p1.z+p2.z)/3.0f); } -inline void MeshKernel::GetFacetPoints (unsigned long ulFaIndex, unsigned long &rclP0, - unsigned long &rclP1, unsigned long &rclP2) const +inline void MeshKernel::GetFacetPoints (FacetIndex ulFaIndex, PointIndex &rclP0, + PointIndex &rclP1, PointIndex &rclP2) const { assert(ulFaIndex < _aclFacetArray.size()); const MeshFacet& rclFacet = _aclFacetArray[ulFaIndex]; diff --git a/src/Mod/Mesh/App/Core/Projection.cpp b/src/Mod/Mesh/App/Core/Projection.cpp index b7ff4d7578..a3a238c016 100644 --- a/src/Mod/Mesh/App/Core/Projection.cpp +++ b/src/Mod/Mesh/App/Core/Projection.cpp @@ -139,8 +139,8 @@ bool MeshProjection::connectLines(std::list< std::pair& polyline) { @@ -150,7 +150,7 @@ bool MeshProjection::projectLineOnMesh(const MeshFacetGrid& grid, dir.Normalize(); - std::vector facets; + std::vector facets; // special case: start and endpoint inside same facet if (f1 == f2) { @@ -172,8 +172,7 @@ bool MeshProjection::projectLineOnMesh(const MeshFacetGrid& grid, // cut all facets with plane std::list< std::pair > cutLine; - //unsigned long start = 0, end = 0; - for (std::vector::iterator it = facets.begin(); it != facets.end(); ++it) { + for (std::vector::iterator it = facets.begin(); it != facets.end(); ++it) { Base::Vector3f e1, e2; MeshGeomFacet tria = kernel.GetFacet(*it); if (bboxInsideRectangle(tria.GetBoundBox(), v1, v2, vd)) { diff --git a/src/Mod/Mesh/App/Core/Projection.h b/src/Mod/Mesh/App/Core/Projection.h index a09e68c04e..0ce76df03e 100644 --- a/src/Mod/Mesh/App/Core/Projection.h +++ b/src/Mod/Mesh/App/Core/Projection.h @@ -27,6 +27,7 @@ #include #include #include +#include using Base::Vector3f; @@ -48,8 +49,8 @@ public: MeshProjection(const MeshKernel&); ~MeshProjection(); - bool projectLineOnMesh(const MeshFacetGrid& grid, const Base::Vector3f& p1, unsigned long f1, - const Base::Vector3f& p2, unsigned long f2, const Base::Vector3f& view, + bool projectLineOnMesh(const MeshFacetGrid& grid, const Base::Vector3f& p1, FacetIndex f1, + const Base::Vector3f& p2, FacetIndex f2, const Base::Vector3f& view, std::vector& polyline); protected: bool bboxInsideRectangle (const Base::BoundBox3f& bbox, const Base::Vector3f& p1, const Base::Vector3f& p2, const Base::Vector3f& view) const; diff --git a/src/Mod/Mesh/App/Core/Segmentation.cpp b/src/Mod/Mesh/App/Core/Segmentation.cpp index 5e84f92ba4..3739af1e38 100644 --- a/src/Mod/Mesh/App/Core/Segmentation.cpp +++ b/src/Mod/Mesh/App/Core/Segmentation.cpp @@ -31,11 +31,11 @@ using namespace MeshCore; -void MeshSurfaceSegment::Initialize(unsigned long) +void MeshSurfaceSegment::Initialize(FacetIndex) { } -bool MeshSurfaceSegment::TestInitialFacet(unsigned long) const +bool MeshSurfaceSegment::TestInitialFacet(FacetIndex) const { return true; } @@ -44,14 +44,14 @@ void MeshSurfaceSegment::AddFacet(const MeshFacet&) { } -void MeshSurfaceSegment::AddSegment(const std::vector& segm) +void MeshSurfaceSegment::AddSegment(const std::vector& segm) { if (segm.size() >= minFacets) { segments.push_back(segm); } } -MeshSegment MeshSurfaceSegment::FindSegment(unsigned long index) const +MeshSegment MeshSurfaceSegment::FindSegment(FacetIndex index) const { for (std::vector::const_iterator it = segments.begin(); it != segments.end(); ++it) { if (std::find(it->begin(), it->end(), index) != it->end()) @@ -73,7 +73,7 @@ MeshDistancePlanarSegment::~MeshDistancePlanarSegment() delete fitter; } -void MeshDistancePlanarSegment::Initialize(unsigned long index) +void MeshDistancePlanarSegment::Initialize(FacetIndex index) { fitter->Clear(); @@ -312,7 +312,7 @@ SphereSurfaceFit::SphereSurfaceFit() SphereSurfaceFit::SphereSurfaceFit(const Base::Vector3f& c, float r) : center(c) , radius(r) - , fitter(0) + , fitter(nullptr) { } @@ -408,13 +408,13 @@ MeshDistanceGenericSurfaceFitSegment::~MeshDistanceGenericSurfaceFitSegment() delete fitter; } -void MeshDistanceGenericSurfaceFitSegment::Initialize(unsigned long index) +void MeshDistanceGenericSurfaceFitSegment::Initialize(FacetIndex index) { MeshGeomFacet triangle = kernel.GetFacet(index); fitter->Initialize(triangle); } -bool MeshDistanceGenericSurfaceFitSegment::TestInitialFacet(unsigned long index) const +bool MeshDistanceGenericSurfaceFitSegment::TestInitialFacet(FacetIndex index) const { MeshGeomFacet triangle = kernel.GetFacet(index); for (int i=0; i<3; i++) { @@ -511,7 +511,7 @@ bool MeshCurvatureFreeformSegment::TestFacet (const MeshFacet &rclFacet) const // -------------------------------------------------------- -MeshSurfaceVisitor::MeshSurfaceVisitor (MeshSurfaceSegment& segm, std::vector &indices) +MeshSurfaceVisitor::MeshSurfaceVisitor (MeshSurfaceSegment& segm, std::vector &indices) : indices(indices), segm(segm) { } @@ -521,13 +521,13 @@ MeshSurfaceVisitor::~MeshSurfaceVisitor () } bool MeshSurfaceVisitor::AllowVisit (const MeshFacet& face, const MeshFacet&, - unsigned long, unsigned long, unsigned short) + FacetIndex, unsigned long, unsigned short) { return segm.TestFacet(face); } bool MeshSurfaceVisitor::Visit (const MeshFacet & face, const MeshFacet &, - unsigned long ulFInd, unsigned long) + FacetIndex ulFInd, unsigned long) { indices.push_back(ulFInd); segm.AddFacet(face); @@ -539,7 +539,7 @@ bool MeshSurfaceVisitor::Visit (const MeshFacet & face, const MeshFacet &, void MeshSegmentAlgorithm::FindSegments(std::vector& segm) { // reset VISIT flags - unsigned long startFacet; + FacetIndex startFacet; MeshCore::MeshAlgorithm cAlgo(myKernel); cAlgo.ResetFacetFlag(MeshCore::MeshFacet::VISIT); @@ -550,7 +550,7 @@ void MeshSegmentAlgorithm::FindSegments(std::vector& segm // start from the first not visited facet cAlgo.CountFacetFlag(MeshCore::MeshFacet::VISIT); - std::vector resetVisited; + std::vector resetVisited; for (std::vector::iterator it = segm.begin(); it != segm.end(); ++it) { cAlgo.ResetFacetsFlag(resetVisited, MeshCore::MeshFacet::VISIT); @@ -563,10 +563,10 @@ void MeshSegmentAlgorithm::FindSegments(std::vector& segm if (iCur < iEnd) startFacet = iCur - iBeg; else - startFacet = ULONG_MAX; - while (startFacet != ULONG_MAX) { + startFacet = FACET_INDEX_MAX; + while (startFacet != FACET_INDEX_MAX) { // collect all facets of the same geometry - std::vector indices; + std::vector indices; (*it)->Initialize(startFacet); if ((*it)->TestInitialFacet(startFacet)) indices.push_back(startFacet); @@ -588,7 +588,7 @@ void MeshSegmentAlgorithm::FindSegments(std::vector& segm if (iCur < iEnd) startFacet = iCur - iBeg; else - startFacet = ULONG_MAX; + startFacet = FACET_INDEX_MAX; } } } diff --git a/src/Mod/Mesh/App/Core/Segmentation.h b/src/Mod/Mesh/App/Core/Segmentation.h index 0a90070f6f..f17593a35d 100644 --- a/src/Mod/Mesh/App/Core/Segmentation.h +++ b/src/Mod/Mesh/App/Core/Segmentation.h @@ -35,7 +35,7 @@ class PlaneFit; class CylinderFit; class SphereFit; class MeshFacet; -typedef std::vector MeshSegment; +typedef std::vector MeshSegment; class MeshExport MeshSurfaceSegment { @@ -45,12 +45,12 @@ public: virtual ~MeshSurfaceSegment() {} virtual bool TestFacet (const MeshFacet &rclFacet) const = 0; virtual const char* GetType() const = 0; - virtual void Initialize(unsigned long); - virtual bool TestInitialFacet(unsigned long) const; + virtual void Initialize(FacetIndex); + virtual bool TestInitialFacet(FacetIndex) const; virtual void AddFacet(const MeshFacet& rclFacet); - void AddSegment(const std::vector&); + void AddSegment(const std::vector&); const std::vector& GetSegments() const { return segments; } - MeshSegment FindSegment(unsigned long) const; + MeshSegment FindSegment(FacetIndex) const; protected: std::vector segments; @@ -78,7 +78,7 @@ public: virtual ~MeshDistancePlanarSegment(); bool TestFacet (const MeshFacet& rclFacet) const; const char* GetType() const { return "Plane"; } - void Initialize(unsigned long); + void Initialize(FacetIndex); void AddFacet(const MeshFacet& rclFacet); protected: @@ -174,8 +174,8 @@ public: virtual ~MeshDistanceGenericSurfaceFitSegment(); bool TestFacet (const MeshFacet& rclFacet) const; const char* GetType() const { return fitter->GetType(); } - void Initialize(unsigned long); - bool TestInitialFacet(unsigned long) const; + void Initialize(FacetIndex); + bool TestInitialFacet(FacetIndex) const; void AddFacet(const MeshFacet& rclFacet); std::vector Parameters() const; @@ -254,15 +254,15 @@ private: class MeshExport MeshSurfaceVisitor : public MeshFacetVisitor { public: - MeshSurfaceVisitor (MeshSurfaceSegment& segm, std::vector &indices); + MeshSurfaceVisitor (MeshSurfaceSegment& segm, std::vector &indices); virtual ~MeshSurfaceVisitor (); bool AllowVisit (const MeshFacet& face, const MeshFacet&, - unsigned long, unsigned long, unsigned short neighbourIndex); + FacetIndex, unsigned long, unsigned short neighbourIndex); bool Visit (const MeshFacet & face, const MeshFacet &, - unsigned long ulFInd, unsigned long); + FacetIndex ulFInd, unsigned long); protected: - std::vector &indices; + std::vector &indices; MeshSurfaceSegment& segm; }; diff --git a/src/Mod/Mesh/App/Core/SetOperations.cpp b/src/Mod/Mesh/App/Core/SetOperations.cpp index ede6b0b084..244b424228 100644 --- a/src/Mod/Mesh/App/Core/SetOperations.cpp +++ b/src/Mod/Mesh/App/Core/SetOperations.cpp @@ -59,7 +59,7 @@ SetOperations::SetOperations (const MeshKernel &cutMesh1, const MeshKernel &cutM { } -SetOperations::~SetOperations (void) +SetOperations::~SetOperations () { } @@ -74,7 +74,7 @@ void SetOperations::Do () // _builder.clear(); //Base::Sequencer().next(); - std::set facetsCuttingEdge0, facetsCuttingEdge1; + std::set facetsCuttingEdge0, facetsCuttingEdge1; Cut(facetsCuttingEdge0, facetsCuttingEdge1); // no intersection curve of the meshes found @@ -170,7 +170,7 @@ void SetOperations::Do () MeshDefinitions::SetMinPointDistance(saveMinMeshDistance); } -void SetOperations::Cut (std::set& facetsCuttingEdge0, std::set& facetsCuttingEdge1) +void SetOperations::Cut (std::set& facetsCuttingEdge0, std::set& facetsCuttingEdge1) { MeshFacetGrid grid1(_cutMesh0, 20); MeshFacetGrid grid2(_cutMesh1, 20); @@ -189,24 +189,24 @@ void SetOperations::Cut (std::set& facetsCuttingEdge0, std::set 0) { - std::vector vecFacets2; + std::vector vecFacets2; grid2.Inside(grid1.GetBoundBox(gx1, gy1, gz1), vecFacets2); if (vecFacets2.size() > 0) { - std::set vecFacets1; + std::set vecFacets1; grid1.GetElements(gx1, gy1, gz1, vecFacets1); - std::set::iterator it1; + std::set::iterator it1; for (it1 = vecFacets1.begin(); it1 != vecFacets1.end(); ++it1) { - unsigned long fidx1 = *it1; + FacetIndex fidx1 = *it1; MeshGeomFacet f1 = _cutMesh0.GetFacet(*it1); - std::vector::iterator it2; + std::vector::iterator it2; for (it2 = vecFacets2.begin(); it2 != vecFacets2.end(); ++it2) { - unsigned long fidx2 = *it2; + FacetIndex fidx2 = *it2; MeshGeomFacet f2 = _cutMesh1.GetFacet(fidx2); MeshPoint p0, p1; @@ -304,13 +304,13 @@ void SetOperations::Cut (std::set& facetsCuttingEdge0, std::set::iterator> >::iterator it1; + std::map::iterator> >::iterator it1; for (it1 = _facet2points[side].begin(); it1 != _facet2points[side].end(); ++it1) { std::vector points; std::set pointsSet; - unsigned long fidx = it1->first; + FacetIndex fidx = it1->first; MeshGeomFacet f = cutMesh.GetFacet(fidx); //if (side == 1) @@ -468,7 +468,7 @@ void SetOperations::CollectFacets (int side, float mult) { if (!itf->IsFlag(MeshFacet::VISIT)) { // Facet found, visit neighbours - std::vector facets; + std::vector facets; facets.push_back(itf - rFacets.begin()); // add seed facet CollectFacetVisitor visitor(mesh, facets, _edges, side, mult, _builder); mesh.VisitNeighbourFacets(visitor, itf - rFacets.begin()); @@ -492,7 +492,7 @@ void SetOperations::CollectFacets (int side, float mult) // MeshDefinitions::SetMinPointDistance(distSave); } -SetOperations::CollectFacetVisitor::CollectFacetVisitor (const MeshKernel& mesh, std::vector& facets, +SetOperations::CollectFacetVisitor::CollectFacetVisitor (const MeshKernel& mesh, std::vector& facets, std::map& edges, int side, float mult, Base::Builder3D& builder) : _facets(facets) @@ -506,7 +506,7 @@ SetOperations::CollectFacetVisitor::CollectFacetVisitor (const MeshKernel& mesh, } bool SetOperations::CollectFacetVisitor::Visit (const MeshFacet &rclFacet, const MeshFacet &rclFrom, - unsigned long ulFInd, unsigned long ulLevel) + FacetIndex ulFInd, unsigned long ulLevel) { (void)rclFacet; (void)rclFrom; @@ -517,14 +517,14 @@ bool SetOperations::CollectFacetVisitor::Visit (const MeshFacet &rclFacet, const //static int matchCounter = 0; bool SetOperations::CollectFacetVisitor::AllowVisit (const MeshFacet& rclFacet, const MeshFacet& rclFrom, - unsigned long ulFInd, unsigned long ulLevel, + FacetIndex ulFInd, unsigned long ulLevel, unsigned short neighbourIndex) { (void)ulFInd; (void)ulLevel; if (rclFacet.IsFlag(MeshFacet::MARKED) && rclFrom.IsFlag(MeshFacet::MARKED)) { // facet connected to an edge - unsigned long pt0 = rclFrom._aulPoints[neighbourIndex], pt1 = rclFrom._aulPoints[(neighbourIndex+1)%3]; + PointIndex pt0 = rclFrom._aulPoints[neighbourIndex], pt1 = rclFrom._aulPoints[(neighbourIndex+1)%3]; Edge edge(_mesh.GetPoint(pt0), _mesh.GetPoint(pt1)); std::map::iterator it = _edges.find(edge); diff --git a/src/Mod/Mesh/App/Core/SetOperations.h b/src/Mod/Mesh/App/Core/SetOperations.h index 9d68155607..6ec708f443 100644 --- a/src/Mod/Mesh/App/Core/SetOperations.h +++ b/src/Mod/Mesh/App/Core/SetOperations.h @@ -59,7 +59,7 @@ public: /// Construction SetOperations (const MeshKernel &cutMesh1, const MeshKernel &cutMesh2, MeshKernel &result, OperationType opType, float minDistanceToPoint = 1e-5f); /// Destruction - virtual ~SetOperations (void); + virtual ~SetOperations (); public: @@ -116,7 +116,7 @@ private: public: int fcounter[2]; // counter of facets attacted to the edge MeshGeomFacet facets[2][2]; // Geom-Facets attached to the edge - unsigned long facet[2]; // underlying Facet-Index + FacetIndex facet[2]; // underlying Facet-Index EdgeInfo () { @@ -146,7 +146,7 @@ private: class CollectFacetVisitor : public MeshFacetVisitor { public: - std::vector &_facets; + std::vector &_facets; const MeshKernel &_mesh; std::map &_edges; int _side; @@ -154,9 +154,9 @@ private: int _addFacets; // 0: add facets to the result 1: do not add facets to the result Base::Builder3D& _builder; - CollectFacetVisitor (const MeshKernel& mesh, std::vector& facets, std::map& edges, int side, float mult, Base::Builder3D& builder); - bool Visit (const MeshFacet &rclFacet, const MeshFacet &rclFrom, unsigned long ulFInd, unsigned long ulLevel); - bool AllowVisit (const MeshFacet& rclFacet, const MeshFacet& rclFrom, unsigned long ulFInd, unsigned long ulLevel, unsigned short neighbourIndex); + CollectFacetVisitor (const MeshKernel& mesh, std::vector& facets, std::map& edges, int side, float mult, Base::Builder3D& builder); + bool Visit (const MeshFacet &rclFacet, const MeshFacet &rclFrom, FacetIndex ulFInd, unsigned long ulLevel); + bool AllowVisit (const MeshFacet& rclFacet, const MeshFacet& rclFrom, FacetIndex ulFInd, unsigned long ulLevel, unsigned short neighbourIndex); }; /** all points from cut */ @@ -164,14 +164,14 @@ private: /** all edges */ std::map _edges; /** map from facet index to its cut points (mesh 1 and mesh 2) Key: Facet-Index Value: List of iterators of set */ - std::map::iterator> > _facet2points[2]; + std::map::iterator> > _facet2points[2]; /** Facets collected from region growing */ std::vector _facetsOf[2]; std::vector _newMeshFacets[2]; /** Cut mesh 1 with mesh 2 */ - void Cut (std::set& facetsNotCuttingEdge0, std::set& facetsCuttingEdge1); + void Cut (std::set& facetsNotCuttingEdge0, std::set& facetsCuttingEdge1); /** Trianglute each facets cut with its cutting points */ void TriangulateMesh (const MeshKernel &cutMesh, int side); /** search facets for adding (with region growing) */ diff --git a/src/Mod/Mesh/App/Core/Smoothing.cpp b/src/Mod/Mesh/App/Core/Smoothing.cpp index 5dcc3f119e..e0345cd9f1 100644 --- a/src/Mod/Mesh/App/Core/Smoothing.cpp +++ b/src/Mod/Mesh/App/Core/Smoothing.cpp @@ -78,11 +78,11 @@ void PlaneFitSmoothing::Smooth(unsigned int iterations) MeshCore::PlaneFit pf; pf.AddPoint(*v_it); center = *v_it; - const std::set& cv = vv_it[v_it.Position()]; + const std::set& cv = vv_it[v_it.Position()]; if (cv.size() < 3) continue; - std::set::const_iterator cv_it; + std::set::const_iterator cv_it; for (cv_it = cv.begin(); cv_it !=cv.end(); ++cv_it) { pf.AddPoint(v_beg[*cv_it]); center += v_beg[*cv_it]; @@ -109,14 +109,14 @@ void PlaneFitSmoothing::Smooth(unsigned int iterations) } // assign values without affecting iterators - unsigned long count = kernel.CountPoints(); - for (unsigned long idx = 0; idx < count; idx++) { + PointIndex count = kernel.CountPoints(); + for (PointIndex idx = 0; idx < count; idx++) { kernel.SetPoint(idx, PointArray[idx]); } } } -void PlaneFitSmoothing::SmoothPoints(unsigned int iterations, const std::vector& point_indices) +void PlaneFitSmoothing::SmoothPoints(unsigned int iterations, const std::vector& point_indices) { MeshCore::MeshPoint center; MeshCore::MeshPointArray PointArray = kernel.GetPoints(); @@ -127,16 +127,16 @@ void PlaneFitSmoothing::SmoothPoints(unsigned int iterations, const std::vector< for (unsigned int i=0; i::const_iterator it = point_indices.begin(); it != point_indices.end(); ++it) { + for (std::vector::const_iterator it = point_indices.begin(); it != point_indices.end(); ++it) { v_it.Set(*it); MeshCore::PlaneFit pf; pf.AddPoint(*v_it); center = *v_it; - const std::set& cv = vv_it[v_it.Position()]; + const std::set& cv = vv_it[v_it.Position()]; if (cv.size() < 3) continue; - std::set::const_iterator cv_it; + std::set::const_iterator cv_it; for (cv_it = cv.begin(); cv_it !=cv.end(); ++cv_it) { pf.AddPoint(v_beg[*cv_it]); center += v_beg[*cv_it]; @@ -163,8 +163,8 @@ void PlaneFitSmoothing::SmoothPoints(unsigned int iterations, const std::vector< } // assign values without affecting iterators - unsigned long count = kernel.CountPoints(); - for (unsigned long idx = 0; idx < count; idx++) { + PointIndex count = kernel.CountPoints(); + for (PointIndex idx = 0; idx < count; idx++) { kernel.SetPoint(idx, PointArray[idx]); } } @@ -186,9 +186,9 @@ void LaplaceSmoothing::Umbrella(const MeshRefPointToPoints& vv_it, MeshCore::MeshPointArray::_TConstIterator v_it, v_beg = points.begin(), v_end = points.end(); - unsigned long pos = 0; + PointIndex pos = 0; for (v_it = points.begin(); v_it != v_end; ++v_it,++pos) { - const std::set& cv = vv_it[pos]; + const std::set& cv = vv_it[pos]; if (cv.size() < 3) continue; if (cv.size() != vf_it[pos].size()) { @@ -201,7 +201,7 @@ void LaplaceSmoothing::Umbrella(const MeshRefPointToPoints& vv_it, w=1.0/double(n_count); double delx=0.0,dely=0.0,delz=0.0; - std::set::const_iterator cv_it; + std::set::const_iterator cv_it; for (cv_it = cv.begin(); cv_it !=cv.end(); ++cv_it) { delx += w*static_cast((v_beg[*cv_it]).x-v_it->x); dely += w*static_cast((v_beg[*cv_it]).y-v_it->y); @@ -217,13 +217,13 @@ void LaplaceSmoothing::Umbrella(const MeshRefPointToPoints& vv_it, void LaplaceSmoothing::Umbrella(const MeshRefPointToPoints& vv_it, const MeshRefPointToFacets& vf_it, double stepsize, - const std::vector& point_indices) + const std::vector& point_indices) { const MeshCore::MeshPointArray& points = kernel.GetPoints(); MeshCore::MeshPointArray::_TConstIterator v_beg = points.begin(); - for (std::vector::const_iterator pos = point_indices.begin(); pos != point_indices.end(); ++pos) { - const std::set& cv = vv_it[*pos]; + for (std::vector::const_iterator pos = point_indices.begin(); pos != point_indices.end(); ++pos) { + const std::set& cv = vv_it[*pos]; if (cv.size() < 3) continue; if (cv.size() != vf_it[*pos].size()) { @@ -236,7 +236,7 @@ void LaplaceSmoothing::Umbrella(const MeshRefPointToPoints& vv_it, w=1.0/double(n_count); double delx=0.0,dely=0.0,delz=0.0; - std::set::const_iterator cv_it; + std::set::const_iterator cv_it; for (cv_it = cv.begin(); cv_it !=cv.end(); ++cv_it) { delx += w*static_cast((v_beg[*cv_it]).x-(v_beg[*pos]).x); dely += w*static_cast((v_beg[*cv_it]).y-(v_beg[*pos]).y); @@ -260,7 +260,7 @@ void LaplaceSmoothing::Smooth(unsigned int iterations) } } -void LaplaceSmoothing::SmoothPoints(unsigned int iterations, const std::vector& point_indices) +void LaplaceSmoothing::SmoothPoints(unsigned int iterations, const std::vector& point_indices) { MeshCore::MeshRefPointToPoints vv_it(kernel); MeshCore::MeshRefPointToFacets vf_it(kernel); @@ -292,7 +292,7 @@ void TaubinSmoothing::Smooth(unsigned int iterations) } } -void TaubinSmoothing::SmoothPoints(unsigned int iterations, const std::vector& point_indices) +void TaubinSmoothing::SmoothPoints(unsigned int iterations, const std::vector& point_indices) { MeshCore::MeshRefPointToPoints vv_it(kernel); MeshCore::MeshRefPointToFacets vf_it(kernel); diff --git a/src/Mod/Mesh/App/Core/Smoothing.h b/src/Mod/Mesh/App/Core/Smoothing.h index 7373984e13..300d97b1d5 100644 --- a/src/Mod/Mesh/App/Core/Smoothing.h +++ b/src/Mod/Mesh/App/Core/Smoothing.h @@ -25,6 +25,7 @@ #define MESH_SMOOTHING_H #include +#include "Definitions.h" namespace MeshCore { @@ -54,7 +55,7 @@ public: /** Smooth the triangle mesh. */ virtual void Smooth(unsigned int) = 0; - virtual void SmoothPoints(unsigned int, const std::vector&) = 0; + virtual void SmoothPoints(unsigned int, const std::vector&) = 0; protected: MeshKernel& kernel; @@ -70,7 +71,7 @@ public: PlaneFitSmoothing(MeshKernel&); virtual ~PlaneFitSmoothing(); void Smooth(unsigned int); - void SmoothPoints(unsigned int, const std::vector&); + void SmoothPoints(unsigned int, const std::vector&); }; class MeshExport LaplaceSmoothing : public AbstractSmoothing @@ -79,7 +80,7 @@ public: LaplaceSmoothing(MeshKernel&); virtual ~LaplaceSmoothing(); void Smooth(unsigned int); - void SmoothPoints(unsigned int, const std::vector&); + void SmoothPoints(unsigned int, const std::vector&); void SetLambda(double l) { lambda = l;} protected: @@ -87,7 +88,7 @@ protected: const MeshRefPointToFacets&, double); void Umbrella(const MeshRefPointToPoints&, const MeshRefPointToFacets&, double, - const std::vector&); + const std::vector&); protected: double lambda; @@ -99,7 +100,7 @@ public: TaubinSmoothing(MeshKernel&); virtual ~TaubinSmoothing(); void Smooth(unsigned int); - void SmoothPoints(unsigned int, const std::vector&); + void SmoothPoints(unsigned int, const std::vector&); void SetMicro(double m) { micro = m;} protected: diff --git a/src/Mod/Mesh/App/Core/Tools.cpp b/src/Mod/Mesh/App/Core/Tools.cpp index eb1d212434..d2de883957 100644 --- a/src/Mod/Mesh/App/Core/Tools.cpp +++ b/src/Mod/Mesh/App/Core/Tools.cpp @@ -53,7 +53,7 @@ void MeshSearchNeighbours::Reinit (float fSampleDistance) MeshAlgorithm(_rclMesh).ResetPointFlag(MeshPoint::MARKED); } -unsigned long MeshSearchNeighbours::NeighboursFromFacet (unsigned long ulFacetIdx, float fDistance, unsigned long ulMinPoints, std::vector &raclResultPoints) +unsigned long MeshSearchNeighbours::NeighboursFromFacet (FacetIndex ulFacetIdx, float fDistance, unsigned long ulMinPoints, std::vector &raclResultPoints) { bool bAddPoints = false; @@ -82,12 +82,12 @@ unsigned long MeshSearchNeighbours::NeighboursFromFacet (unsigned long ulFacetId while ((bFound == true) && (nCtExpandRadius < 10)) { bFound = false; - std::set aclTmp; + std::set aclTmp; aclTmp.swap(_aclOuter); - for (std::set::iterator pI = aclTmp.begin(); pI != aclTmp.end(); ++pI) { - const std::set &rclISet = _clPt2Fa[*pI]; + for (std::set::iterator pI = aclTmp.begin(); pI != aclTmp.end(); ++pI) { + const std::set &rclISet = _clPt2Fa[*pI]; // search all facets hanging on this point - for (std::set::const_iterator pJ = rclISet.begin(); pJ != rclISet.end(); ++pJ) { + for (std::set::const_iterator pJ = rclISet.begin(); pJ != rclISet.end(); ++pJ) { const MeshFacet &rclF = f_beg[*pJ]; if (rclF.IsFlag(MeshFacet::MARKED) == false) { @@ -114,14 +114,14 @@ unsigned long MeshSearchNeighbours::NeighboursFromFacet (unsigned long ulFacetId for (std::vector::iterator pF = aclTestedFacet.begin(); pF != aclTestedFacet.end(); ++pF) (*pF)->ResetFlag(MeshFacet::MARKED); - for (std::set::iterator pR = _aclResult.begin(); pR != _aclResult.end(); ++pR) + for (std::set::iterator pR = _aclResult.begin(); pR != _aclResult.end(); ++pR) _rclPAry[*pR].ResetFlag(MeshPoint::MARKED); // copy points in result container raclResultPoints.resize(_aclResult.size()); size_t i = 0; - for (std::set::iterator pI = _aclResult.begin(); pI != _aclResult.end(); ++pI, i++) + for (std::set::iterator pI = _aclResult.begin(); pI != _aclResult.end(); ++pI, i++) raclResultPoints[i] = _rclPAry[*pI]; if (bAddPoints == true) { @@ -133,7 +133,7 @@ unsigned long MeshSearchNeighbours::NeighboursFromFacet (unsigned long ulFacetId return ulVisited; } -void MeshSearchNeighbours::SampleAllFacets (void) +void MeshSearchNeighbours::SampleAllFacets () { if (_aclSampledFacets.size() == _rclMesh.CountFacets()) return; // already sampled, do nothing @@ -149,7 +149,7 @@ void MeshSearchNeighbours::SampleAllFacets (void) } } -unsigned long MeshSearchNeighbours::NeighboursFromSampledFacets (unsigned long ulFacetIdx, float fDistance, std::vector &raclResultPoints) +unsigned long MeshSearchNeighbours::NeighboursFromSampledFacets (FacetIndex ulFacetIdx, float fDistance, std::vector &raclResultPoints) { SampleAllFacets(); @@ -175,12 +175,12 @@ unsigned long MeshSearchNeighbours::NeighboursFromSampledFacets (unsigned long u while (bFound == true) { bFound = false; - std::set aclTmp; + std::set aclTmp; aclTmp.swap(_aclOuter); - for (std::set::iterator pI = aclTmp.begin(); pI != aclTmp.end(); ++pI) { - const std::set &rclISet = _clPt2Fa[*pI]; + for (std::set::iterator pI = aclTmp.begin(); pI != aclTmp.end(); ++pI) { + const std::set &rclISet = _clPt2Fa[*pI]; // search all facets hanging on this point - for (std::set::const_iterator pJ = rclISet.begin(); pJ != rclISet.end(); ++pJ) { + for (std::set::const_iterator pJ = rclISet.begin(); pJ != rclISet.end(); ++pJ) { const MeshFacet &rclF = f_beg[*pJ]; if (rclF.IsFlag(MeshFacet::MARKED) == false) { @@ -203,7 +203,7 @@ unsigned long MeshSearchNeighbours::NeighboursFromSampledFacets (unsigned long u std::copy(_aclPointsResult.begin(), _aclPointsResult.end(), raclResultPoints.begin()); // facet points - for (std::set::iterator pI = _aclResult.begin(); pI != _aclResult.end(); ++pI) { + for (std::set::iterator pI = _aclResult.begin(); pI != _aclResult.end(); ++pI) { if (InnerPoint(_rclPAry[*pI]) == true) raclResultPoints.push_back(_rclPAry[*pI]); } @@ -211,12 +211,12 @@ unsigned long MeshSearchNeighbours::NeighboursFromSampledFacets (unsigned long u return ulVisited; } -bool MeshSearchNeighbours::AccumulateNeighbours (const MeshFacet &rclF, unsigned long ulFIdx) +bool MeshSearchNeighbours::AccumulateNeighbours (const MeshFacet &rclF, FacetIndex ulFIdx) { int k = 0; for (int i = 0; i < 3; i++) { - unsigned long ulPIdx = rclF._aulPoints[i]; + PointIndex ulPIdx = rclF._aulPoints[i]; _aclOuter.insert(ulPIdx); _aclResult.insert(ulPIdx); @@ -251,7 +251,7 @@ bool MeshSearchNeighbours::ExpandRadius (unsigned long ulMinPoints) { // add facets from current level _aclResult.insert(_aclOuter.begin(), _aclOuter.end()); - for (std::set::iterator pI = _aclOuter.begin(); pI != _aclOuter.end(); ++pI) + for (std::set::iterator pI = _aclOuter.begin(); pI != _aclOuter.end(); ++pI) _rclPAry[*pI].SetFlag(MeshPoint::MARKED); if (_aclResult.size() < ulMinPoints) { @@ -262,9 +262,9 @@ bool MeshSearchNeighbours::ExpandRadius (unsigned long ulMinPoints) return false; } -unsigned long MeshSearchNeighbours::NeighboursFacetFromFacet (unsigned long ulFacetIdx, float fDistance, std::vector &raclResultPoints, std::vector &raclResultFacets) +unsigned long MeshSearchNeighbours::NeighboursFacetFromFacet (FacetIndex ulFacetIdx, float fDistance, std::vector &raclResultPoints, std::vector &raclResultFacets) { - std::set aulFacetSet; + std::set aulFacetSet; _fMaxDistanceP2 = fDistance * fDistance; _clCenter = _rclMesh.GetFacet(ulFacetIdx).GetGravityPoint(); @@ -287,12 +287,12 @@ unsigned long MeshSearchNeighbours::NeighboursFacetFromFacet (unsigned long ulFa while (bFound == true) { bFound = false; - std::set aclTmp; + std::set aclTmp; aclTmp.swap(_aclOuter); - for (std::set::iterator pI = aclTmp.begin(); pI != aclTmp.end(); ++pI) { - const std::set &rclISet = _clPt2Fa[*pI]; + for (std::set::iterator pI = aclTmp.begin(); pI != aclTmp.end(); ++pI) { + const std::set &rclISet = _clPt2Fa[*pI]; // search all facets hanging on this point - for (std::set::const_iterator pJ = rclISet.begin(); pJ != rclISet.end(); ++pJ) { + for (std::set::const_iterator pJ = rclISet.begin(); pJ != rclISet.end(); ++pJ) { const MeshFacet &rclF = f_beg[*pJ]; for (int i = 0; i < 3; i++) { @@ -317,13 +317,13 @@ unsigned long MeshSearchNeighbours::NeighboursFacetFromFacet (unsigned long ulFa // reset marked facets, points for (std::vector::iterator pF = aclTestedFacet.begin(); pF != aclTestedFacet.end(); ++pF) (*pF)->ResetFlag(MeshFacet::MARKED); - for (std::set::iterator pR = _aclResult.begin(); pR != _aclResult.end(); ++pR) + for (std::set::iterator pR = _aclResult.begin(); pR != _aclResult.end(); ++pR) _rclPAry[*pR].ResetFlag(MeshPoint::MARKED); // copy points in result container raclResultPoints.resize(_aclResult.size()); size_t i = 0; - for (std::set::iterator pI = _aclResult.begin(); pI != _aclResult.end(); ++pI, i++) + for (std::set::iterator pI = _aclResult.begin(); pI != _aclResult.end(); ++pI, i++) raclResultPoints[i] = _rclPAry[*pI]; // copy facets in result container diff --git a/src/Mod/Mesh/App/Core/Tools.h b/src/Mod/Mesh/App/Core/Tools.h index 76269b4e9c..a6fc191850 100644 --- a/src/Mod/Mesh/App/Core/Tools.h +++ b/src/Mod/Mesh/App/Core/Tools.h @@ -51,18 +51,18 @@ public: * inside a sphere of radius \a fDistance, center \a center of the original facet. This method uses the * MARKED flags. */ - unsigned long NeighboursFromFacet (unsigned long ulFacetIdx, float fDistance, unsigned long ulMinPoints, std::vector &raclResultPoints); + unsigned long NeighboursFromFacet (FacetIndex ulFacetIdx, float fDistance, unsigned long ulMinPoints, std::vector &raclResultPoints); /** Searches for facets from the start facet, sample the neighbour facets and accumulates the points. */ - unsigned long NeighboursFromSampledFacets (unsigned long ulFacetIdx, float fDistance, std::vector &raclResultPoints); + unsigned long NeighboursFromSampledFacets (FacetIndex ulFacetIdx, float fDistance, std::vector &raclResultPoints); /** Searches for facets from the start facet. */ - unsigned long NeighboursFacetFromFacet (unsigned long ulFacetIdx, float fDistance, std::vector &raclResultPoints, - std::vector &raclResultFacets); + unsigned long NeighboursFacetFromFacet (FacetIndex ulFacetIdx, float fDistance, std::vector &raclResultPoints, + std::vector &raclResultFacets); protected: /** Subsamples the mesh. */ - void SampleAllFacets (void); + void SampleAllFacets (); inline bool CheckDistToFacet (const MeshFacet &rclF); // check distance to facet, add points inner radius - bool AccumulateNeighbours (const MeshFacet &rclF, unsigned long ulFIdx); // accumulate the sample neighbours facet + bool AccumulateNeighbours (const MeshFacet &rclF, FacetIndex ulFIdx); // accumulate the sample neighbours facet inline bool InnerPoint (const Base::Vector3f &rclPt) const; inline bool TriangleCutsSphere (const MeshFacet &rclF) const; bool ExpandRadius (unsigned long ulMinPoints); @@ -81,8 +81,8 @@ protected: MeshRefPointToFacets _clPt2Fa; float _fMaxDistanceP2; // square distance Base::Vector3f _clCenter; // center points of start facet - std::set _aclResult; // result container (point indices) - std::set _aclOuter; // next searching points + std::set _aclResult; // result container (point indices) + std::set _aclOuter; // next searching points std::vector _aclPointsResult; // result as vertex std::vector > _aclSampledFacets; // sample points from each facet float _fSampleDistance; // distance between two sampled points @@ -100,7 +100,7 @@ inline bool MeshSearchNeighbours::CheckDistToFacet (const MeshFacet &rclF) for (int i = 0; i < 3; i++) { - unsigned long ulPIdx = rclF._aulPoints[i]; + PointIndex ulPIdx = rclF._aulPoints[i]; if (_rclPAry[ulPIdx].IsFlag(MeshPoint::MARKED) == false) { if (Base::DistanceP2(_clCenter, _rclPAry[ulPIdx]) < _fMaxDistanceP2) @@ -146,7 +146,7 @@ class MeshFaceIterator public: MeshFaceIterator(const MeshKernel& mesh) : it(mesh) {} - Base::Vector3f operator() (unsigned long index) + Base::Vector3f operator() (FacetIndex index) { it.Set(index); return it->GetGravityPoint(); @@ -161,7 +161,7 @@ class MeshVertexIterator public: MeshVertexIterator(const MeshKernel& mesh) : it(mesh) {} - Base::Vector3f operator() (unsigned long index) + Base::Vector3f operator() (PointIndex index) { it.Set(index); return *it; @@ -175,9 +175,10 @@ template class MeshNearestIndexToPlane { public: + using Index = typename T::Index; MeshNearestIndexToPlane(const MeshKernel& mesh, const Base::Vector3f& b, const Base::Vector3f& n) - : nearest_index(ULONG_MAX),nearest_dist(FLOAT_MAX), it(mesh), base(b), normal(n) {} - void operator() (unsigned long index) + : nearest_index(-1),nearest_dist(FLOAT_MAX), it(mesh), base(b), normal(n) {} + void operator() (Index index) { float dist = (float)fabs(it(index).DistanceToPlane(base, normal)); if (dist < nearest_dist) { @@ -186,7 +187,7 @@ public: } } - unsigned long nearest_index; + Index nearest_index; float nearest_dist; private: diff --git a/src/Mod/Mesh/App/Core/TopoAlgorithm.cpp b/src/Mod/Mesh/App/Core/TopoAlgorithm.cpp index 76f13a68f1..bdd151e27c 100644 --- a/src/Mod/Mesh/App/Core/TopoAlgorithm.cpp +++ b/src/Mod/Mesh/App/Core/TopoAlgorithm.cpp @@ -44,26 +44,26 @@ using namespace MeshCore; MeshTopoAlgorithm::MeshTopoAlgorithm (MeshKernel &rclM) -: _rclMesh(rclM), _needsCleanup(false), _cache(0) +: _rclMesh(rclM), _needsCleanup(false), _cache(nullptr) { } -MeshTopoAlgorithm::~MeshTopoAlgorithm (void) +MeshTopoAlgorithm::~MeshTopoAlgorithm () { if ( _needsCleanup ) Cleanup(); EndCache(); } -bool MeshTopoAlgorithm::InsertVertex(unsigned long ulFacetPos, const Base::Vector3f& rclPoint) +bool MeshTopoAlgorithm::InsertVertex(FacetIndex ulFacetPos, const Base::Vector3f& rclPoint) { MeshFacet& rclF = _rclMesh._aclFacetArray[ulFacetPos]; MeshFacet clNewFacet1, clNewFacet2; // insert new point - unsigned long ulPtCnt = _rclMesh._aclPointArray.size(); - unsigned long ulPtInd = this->GetOrAddIndex(rclPoint); - unsigned long ulSize = _rclMesh._aclFacetArray.size(); + PointIndex ulPtCnt = _rclMesh._aclPointArray.size(); + PointIndex ulPtInd = this->GetOrAddIndex(rclPoint); + FacetIndex ulSize = _rclMesh._aclFacetArray.size(); if ( ulPtInd < ulPtCnt ) return false; // the given point is already part of the mesh => creating new facets would be an illegal operation @@ -85,9 +85,9 @@ bool MeshTopoAlgorithm::InsertVertex(unsigned long ulFacetPos, const Base::Vecto clNewFacet2._aulNeighbours[1] = ulFacetPos; clNewFacet2._aulNeighbours[2] = ulSize; // adjust the neighbour facet - if (rclF._aulNeighbours[1] != ULONG_MAX) + if (rclF._aulNeighbours[1] != FACET_INDEX_MAX) _rclMesh._aclFacetArray[rclF._aulNeighbours[1]].ReplaceNeighbour(ulFacetPos, ulSize); - if (rclF._aulNeighbours[2] != ULONG_MAX) + if (rclF._aulNeighbours[2] != FACET_INDEX_MAX) _rclMesh._aclFacetArray[rclF._aulNeighbours[2]].ReplaceNeighbour(ulFacetPos, ulSize+1); // original facet rclF._aulPoints[2] = ulPtInd; @@ -101,7 +101,7 @@ bool MeshTopoAlgorithm::InsertVertex(unsigned long ulFacetPos, const Base::Vecto return true; } -bool MeshTopoAlgorithm::SnapVertex(unsigned long ulFacetPos, const Base::Vector3f& rP) +bool MeshTopoAlgorithm::SnapVertex(FacetIndex ulFacetPos, const Base::Vector3f& rP) { MeshFacet& rFace = _rclMesh._aclFacetArray[ulFacetPos]; if (!rFace.HasOpenEdge()) @@ -109,7 +109,7 @@ bool MeshTopoAlgorithm::SnapVertex(unsigned long ulFacetPos, const Base::Vector3 Base::Vector3f cNo1 = _rclMesh.GetNormal(rFace); for (unsigned short i=0; i<3; i++) { - if (rFace._aulNeighbours[i]==ULONG_MAX) + if (rFace._aulNeighbours[i]==FACET_INDEX_MAX) { const Base::Vector3f& rPt1 = _rclMesh._aclPointArray[rFace._aulPoints[i]]; const Base::Vector3f& rPt2 = _rclMesh._aclPointArray[rFace._aulPoints[(i+1)%3]]; @@ -146,21 +146,21 @@ void MeshTopoAlgorithm::OptimizeTopology(float fMaxAngle) { // For each internal edge get the adjacent facets. When doing an edge swap we must update // this structure. - std::map, std::vector > aEdge2Face; + std::map, std::vector > aEdge2Face; for (MeshFacetArray::_TIterator pI = _rclMesh._aclFacetArray.begin(); pI != _rclMesh._aclFacetArray.end(); ++pI) { for (int i = 0; i < 3; i++) { // ignore open edges - if (pI->_aulNeighbours[i] != ULONG_MAX) { - unsigned long ulPt0 = std::min(pI->_aulPoints[i], pI->_aulPoints[(i+1)%3]); - unsigned long ulPt1 = std::max(pI->_aulPoints[i], pI->_aulPoints[(i+1)%3]); - aEdge2Face[std::pair(ulPt0, ulPt1)].push_back(pI - _rclMesh._aclFacetArray.begin()); + if (pI->_aulNeighbours[i] != FACET_INDEX_MAX) { + PointIndex ulPt0 = std::min(pI->_aulPoints[i], pI->_aulPoints[(i+1)%3]); + PointIndex ulPt1 = std::max(pI->_aulPoints[i], pI->_aulPoints[(i+1)%3]); + aEdge2Face[std::pair(ulPt0, ulPt1)].push_back(pI - _rclMesh._aclFacetArray.begin()); } } } // fill up this list with all internal edges and perform swap edges until this list is empty - std::list > aEdgeList; - std::map, std::vector >::iterator pE; + std::list > aEdgeList; + std::map, std::vector >::iterator pE; for (pE = aEdge2Face.begin(); pE != aEdge2Face.end(); ++pE) { if (pE->second.size() == 2) // make sure that we really have an internal edge aEdgeList.push_back(pE->first); @@ -172,7 +172,7 @@ void MeshTopoAlgorithm::OptimizeTopology(float fMaxAngle) // Perform a swap edge where needed while (!aEdgeList.empty() && uMaxIter > 0) { // get the first edge and remove it from the list - std::pair aEdge = aEdgeList.front(); + std::pair aEdge = aEdgeList.front(); aEdgeList.pop_front(); uMaxIter--; @@ -199,10 +199,10 @@ void MeshTopoAlgorithm::OptimizeTopology(float fMaxAngle) // adjust the edge list for (int i=0; i<3; i++) { - std::map, std::vector >::iterator it; + std::map, std::vector >::iterator it; // first facet - unsigned long ulPt0 = std::min(rF1._aulPoints[i], rF1._aulPoints[(i+1)%3]); - unsigned long ulPt1 = std::max(rF1._aulPoints[i], rF1._aulPoints[(i+1)%3]); + PointIndex ulPt0 = std::min(rF1._aulPoints[i], rF1._aulPoints[(i+1)%3]); + PointIndex ulPt1 = std::max(rF1._aulPoints[i], rF1._aulPoints[(i+1)%3]); it = aEdge2Face.find( std::make_pair(ulPt0, ulPt1) ); if (it != aEdge2Face.end()) { if (it->second[0] == pE->second[1]) @@ -213,8 +213,8 @@ void MeshTopoAlgorithm::OptimizeTopology(float fMaxAngle) } // second facet - ulPt0 = std::min(rF2._aulPoints[i], rF2._aulPoints[(i+1)%3]); - ulPt1 = std::max(rF2._aulPoints[i], rF2._aulPoints[(i+1)%3]); + ulPt0 = std::min(rF2._aulPoints[i], rF2._aulPoints[(i+1)%3]); + ulPt1 = std::max(rF2._aulPoints[i], rF2._aulPoints[(i+1)%3]); it = aEdge2Face.find( std::make_pair(ulPt0, ulPt1) ); if (it != aEdge2Face.end()) { if (it->second[0] == pE->second[0]) @@ -226,9 +226,9 @@ void MeshTopoAlgorithm::OptimizeTopology(float fMaxAngle) } // Now we must remove the edge and replace it through the new edge - unsigned long ulPt0 = std::min(rF1._aulPoints[(side1+1)%3], rF2._aulPoints[(side2+1)%3]); - unsigned long ulPt1 = std::max(rF1._aulPoints[(side1+1)%3], rF2._aulPoints[(side2+1)%3]); - std::pair aNewEdge = std::make_pair(ulPt0, ulPt1); + PointIndex ulPt0 = std::min(rF1._aulPoints[(side1+1)%3], rF2._aulPoints[(side2+1)%3]); + PointIndex ulPt1 = std::max(rF1._aulPoints[(side1+1)%3], rF2._aulPoints[(side2+1)%3]); + std::pair aNewEdge = std::make_pair(ulPt0, ulPt1); aEdge2Face[aNewEdge] = pE->second; aEdge2Face.erase(pE); } @@ -261,25 +261,25 @@ static float swap_benefit(const Base::Vector3f &v1, const Base::Vector3f &v2, std::max(-cos_maxangle(v1,v2,v4), -cos_maxangle(v2,v3,v4)); } -float MeshTopoAlgorithm::SwapEdgeBenefit(unsigned long f, int e) const +float MeshTopoAlgorithm::SwapEdgeBenefit(FacetIndex f, int e) const { const MeshFacetArray& faces = _rclMesh.GetFacets(); const MeshPointArray& vertices = _rclMesh.GetPoints(); - unsigned long n = faces[f]._aulNeighbours[e]; - if (n == ULONG_MAX) + FacetIndex n = faces[f]._aulNeighbours[e]; + if (n == FACET_INDEX_MAX) return 0.0f; // border edge - unsigned long v1 = faces[f]._aulPoints[e]; - unsigned long v2 = faces[f]._aulPoints[(e+1)%3]; - unsigned long v3 = faces[f]._aulPoints[(e+2)%3]; + PointIndex v1 = faces[f]._aulPoints[e]; + PointIndex v2 = faces[f]._aulPoints[(e+1)%3]; + PointIndex v3 = faces[f]._aulPoints[(e+2)%3]; unsigned short s = faces[n].Side(faces[f]); if (s == USHRT_MAX) { std::cerr << "MeshTopoAlgorithm::SwapEdgeBenefit: error in neighbourhood " << "of faces " << f << " and " << n << std::endl; return 0.0f; // topological error } - unsigned long v4 = faces[n]._aulPoints[(s+2)%3]; + PointIndex v4 = faces[n]._aulPoints[(s+2)%3]; if (v3 == v4) { std::cerr << "MeshTopoAlgorithm::SwapEdgeBenefit: duplicate faces " << f << " and " << n << std::endl; @@ -289,7 +289,7 @@ float MeshTopoAlgorithm::SwapEdgeBenefit(unsigned long f, int e) const vertices[v1], vertices[v4]); } -typedef std::pair FaceEdge; // (face, edge) pair +typedef std::pair FaceEdge; // (face, edge) pair typedef std::pair FaceEdgePriority; void MeshTopoAlgorithm::OptimizeTopology() @@ -297,9 +297,9 @@ void MeshTopoAlgorithm::OptimizeTopology() // Find all edges that can be swapped and insert them into a // priority queue const MeshFacetArray& faces = _rclMesh.GetFacets(); - unsigned long nf = _rclMesh.CountFacets(); + FacetIndex nf = _rclMesh.CountFacets(); std::priority_queue todo; - for (unsigned long i = 0; i < nf; i++) { + for (FacetIndex i = 0; i < nf; i++) { for (int j = 0; j < 3; j++) { float b = SwapEdgeBenefit(i, j); if (b > 0.0f) @@ -309,14 +309,14 @@ void MeshTopoAlgorithm::OptimizeTopology() // Edges are sorted in decreasing order with respect to their benefit while (!todo.empty()) { - unsigned long f = todo.top().second.first; + FacetIndex f = todo.top().second.first; int e = todo.top().second.second; todo.pop(); // Check again if the swap should still be done if (SwapEdgeBenefit(f, e) <= 0.0f) continue; // OK, swap the edge - unsigned long f2 = faces[f]._aulNeighbours[e]; + FacetIndex f2 = faces[f]._aulNeighbours[e]; SwapEdge(f, f2); // Insert new edges into queue, if necessary for (int j = 0; j < 3; j++) { @@ -335,23 +335,23 @@ void MeshTopoAlgorithm::OptimizeTopology() void MeshTopoAlgorithm::DelaunayFlip(float fMaxAngle) { // For each internal edge get the adjacent facets. - std::set > aEdge2Face; - unsigned long index = 0; + std::set > aEdge2Face; + FacetIndex index = 0; for (MeshFacetArray::_TIterator pI = _rclMesh._aclFacetArray.begin(); pI != _rclMesh._aclFacetArray.end(); ++pI, index++) { for (int i = 0; i < 3; i++) { // ignore open edges - if (pI->_aulNeighbours[i] != ULONG_MAX) { - unsigned long ulFt0 = std::min(index, pI->_aulNeighbours[i]); - unsigned long ulFt1 = std::max(index, pI->_aulNeighbours[i]); - aEdge2Face.insert(std::pair(ulFt0, ulFt1)); + if (pI->_aulNeighbours[i] != FACET_INDEX_MAX) { + FacetIndex ulFt0 = std::min(index, pI->_aulNeighbours[i]); + FacetIndex ulFt1 = std::max(index, pI->_aulNeighbours[i]); + aEdge2Face.insert(std::pair(ulFt0, ulFt1)); } } } Base::Vector3f center; while (!aEdge2Face.empty()) { - std::set >::iterator it = aEdge2Face.begin(); - std::pair edge = *it; + std::set >::iterator it = aEdge2Face.begin(); + std::pair edge = *it; aEdge2Face.erase(it); if (ShouldSwapEdge(edge.first, edge.second, fMaxAngle)) { float radius = _rclMesh.GetFacet(edge.first).CenterOfCircumCircle(center); @@ -363,15 +363,15 @@ void MeshTopoAlgorithm::DelaunayFlip(float fMaxAngle) if (Base::DistanceP2(center, vertex) < radius) { SwapEdge(edge.first, edge.second); for (int i=0; i<3; i++) { - if (face_1._aulNeighbours[i] != ULONG_MAX && face_1._aulNeighbours[i] != edge.second) { - unsigned long ulFt0 = std::min(edge.first, face_1._aulNeighbours[i]); - unsigned long ulFt1 = std::max(edge.first, face_1._aulNeighbours[i]); - aEdge2Face.insert(std::pair(ulFt0, ulFt1)); + if (face_1._aulNeighbours[i] != FACET_INDEX_MAX && face_1._aulNeighbours[i] != edge.second) { + FacetIndex ulFt0 = std::min(edge.first, face_1._aulNeighbours[i]); + FacetIndex ulFt1 = std::max(edge.first, face_1._aulNeighbours[i]); + aEdge2Face.insert(std::pair(ulFt0, ulFt1)); } - if (face_2._aulNeighbours[i] != ULONG_MAX && face_2._aulNeighbours[i] != edge.first) { - unsigned long ulFt0 = std::min(edge.second, face_2._aulNeighbours[i]); - unsigned long ulFt1 = std::max(edge.second, face_2._aulNeighbours[i]); - aEdge2Face.insert(std::pair(ulFt0, ulFt1)); + if (face_2._aulNeighbours[i] != FACET_INDEX_MAX && face_2._aulNeighbours[i] != edge.first) { + FacetIndex ulFt0 = std::min(edge.second, face_2._aulNeighbours[i]); + FacetIndex ulFt1 = std::max(edge.second, face_2._aulNeighbours[i]); + aEdge2Face.insert(std::pair(ulFt0, ulFt1)); } } } @@ -384,13 +384,13 @@ int MeshTopoAlgorithm::DelaunayFlip() int cnt_swap=0; _rclMesh._aclFacetArray.ResetFlag(MeshFacet::TMP0); size_t cnt_facets = _rclMesh._aclFacetArray.size(); - for (unsigned long i=0;i, std::list > aclEdgeMap; + FacetIndex k = 0; + std::map, std::list > aclEdgeMap; for ( std::vector::const_iterator jt = raFts.begin(); jt != raFts.end(); ++jt, k++ ) { for (int i=0; i<3; i++) { - unsigned long ulT0 = jt->_aulPoints[i]; - unsigned long ulT1 = jt->_aulPoints[(i+1)%3]; - unsigned long ulP0 = std::min(ulT0, ulT1); - unsigned long ulP1 = std::max(ulT0, ulT1); + PointIndex ulT0 = jt->_aulPoints[i]; + PointIndex ulT1 = jt->_aulPoints[(i+1)%3]; + PointIndex ulP0 = std::min(ulT0, ulT1); + PointIndex ulP1 = std::max(ulT0, ulT1); aclEdgeMap[std::make_pair(ulP0, ulP1)].push_front(k); aIdx.push_back( static_cast(jt->_aulPoints[i]) ); } @@ -460,20 +460,20 @@ void MeshTopoAlgorithm::AdjustEdgesToCurvatureDirection() raFts.ResetFlag(MeshFacet::VISIT); const MeshPointArray& raPts = _rclMesh.GetPoints(); - for ( std::map, std::list >::iterator kt = aclEdgeMap.begin(); kt != aclEdgeMap.end(); ++kt ) + for ( std::map, std::list >::iterator kt = aclEdgeMap.begin(); kt != aclEdgeMap.end(); ++kt ) { if ( kt->second.size() == 2 ) { - unsigned long uPt1 = kt->first.first; - unsigned long uPt2 = kt->first.second; - unsigned long uFt1 = kt->second.front(); - unsigned long uFt2 = kt->second.back(); + PointIndex uPt1 = kt->first.first; + PointIndex uPt2 = kt->first.second; + FacetIndex uFt1 = kt->second.front(); + FacetIndex uFt2 = kt->second.back(); const MeshFacet& rFace1 = raFts[uFt1]; const MeshFacet& rFace2 = raFts[uFt2]; if ( rFace1.IsFlag(MeshFacet::VISIT) || rFace2.IsFlag(MeshFacet::VISIT) ) continue; - unsigned long uPt3, uPt4; + PointIndex uPt3, uPt4; unsigned short side = rFace1.Side(uPt1, uPt2); uPt3 = rFace1._aulPoints[(side+2)%3]; side = rFace2.Side(uPt1, uPt2); @@ -513,24 +513,23 @@ void MeshTopoAlgorithm::AdjustEdgesToCurvatureDirection() } } -bool MeshTopoAlgorithm::InsertVertexAndSwapEdge(unsigned long ulFacetPos, const Base::Vector3f& rclPoint, float fMaxAngle) +bool MeshTopoAlgorithm::InsertVertexAndSwapEdge(FacetIndex ulFacetPos, const Base::Vector3f& rclPoint, float fMaxAngle) { if ( !InsertVertex(ulFacetPos, rclPoint) ) return false; // get the created elements - unsigned long ulF1Ind = _rclMesh._aclFacetArray.size()-2; - unsigned long ulF2Ind = _rclMesh._aclFacetArray.size()-1; + FacetIndex ulF1Ind = _rclMesh._aclFacetArray.size()-2; + FacetIndex ulF2Ind = _rclMesh._aclFacetArray.size()-1; MeshFacet& rclF1 = _rclMesh._aclFacetArray[ulFacetPos]; MeshFacet& rclF2 = _rclMesh._aclFacetArray[ulF1Ind]; MeshFacet& rclF3 = _rclMesh._aclFacetArray[ulF2Ind]; // first facet - int i; - for ( i=0; i<3; i++ ) + for (int i=0; i<3; i++ ) { - unsigned long uNeighbour = rclF1._aulNeighbours[i]; - if ( uNeighbour!=ULONG_MAX && uNeighbour!=ulF1Ind && uNeighbour!=ulF2Ind ) + FacetIndex uNeighbour = rclF1._aulNeighbours[i]; + if ( uNeighbour!=FACET_INDEX_MAX && uNeighbour!=ulF1Ind && uNeighbour!=ulF2Ind ) { if ( ShouldSwapEdge(ulFacetPos, uNeighbour, fMaxAngle) ) { SwapEdge(ulFacetPos, uNeighbour); @@ -538,11 +537,11 @@ bool MeshTopoAlgorithm::InsertVertexAndSwapEdge(unsigned long ulFacetPos, const } } } - for ( i=0; i<3; i++ ) + for (int i=0; i<3; i++ ) { // second facet - unsigned long uNeighbour = rclF2._aulNeighbours[i]; - if ( uNeighbour!=ULONG_MAX && uNeighbour!=ulFacetPos && uNeighbour!=ulF2Ind ) + FacetIndex uNeighbour = rclF2._aulNeighbours[i]; + if ( uNeighbour!=FACET_INDEX_MAX && uNeighbour!=ulFacetPos && uNeighbour!=ulF2Ind ) { if ( ShouldSwapEdge(ulF1Ind, uNeighbour, fMaxAngle) ) { SwapEdge(ulF1Ind, uNeighbour); @@ -552,10 +551,10 @@ bool MeshTopoAlgorithm::InsertVertexAndSwapEdge(unsigned long ulFacetPos, const } // third facet - for ( i=0; i<3; i++ ) + for (int i=0; i<3; i++ ) { - unsigned long uNeighbour = rclF3._aulNeighbours[i]; - if ( uNeighbour!=ULONG_MAX && uNeighbour!=ulFacetPos && uNeighbour!=ulF1Ind ) + FacetIndex uNeighbour = rclF3._aulNeighbours[i]; + if ( uNeighbour!=FACET_INDEX_MAX && uNeighbour!=ulFacetPos && uNeighbour!=ulF1Ind ) { if ( ShouldSwapEdge(ulF2Ind, uNeighbour, fMaxAngle) ) { SwapEdge(ulF2Ind, uNeighbour); @@ -567,7 +566,7 @@ bool MeshTopoAlgorithm::InsertVertexAndSwapEdge(unsigned long ulFacetPos, const return true; } -bool MeshTopoAlgorithm::IsSwapEdgeLegal(unsigned long ulFacetPos, unsigned long ulNeighbour) const +bool MeshTopoAlgorithm::IsSwapEdgeLegal(FacetIndex ulFacetPos, FacetIndex ulNeighbour) const { MeshFacet& rclF = _rclMesh._aclFacetArray[ulFacetPos]; MeshFacet& rclN = _rclMesh._aclFacetArray[ulNeighbour]; @@ -607,7 +606,7 @@ bool MeshTopoAlgorithm::IsSwapEdgeLegal(unsigned long ulFacetPos, unsigned long return true; } -bool MeshTopoAlgorithm::ShouldSwapEdge(unsigned long ulFacetPos, unsigned long ulNeighbour, float fMaxAngle) const +bool MeshTopoAlgorithm::ShouldSwapEdge(FacetIndex ulFacetPos, FacetIndex ulNeighbour, float fMaxAngle) const { if (!IsSwapEdgeLegal(ulFacetPos, ulNeighbour)) return false; @@ -640,7 +639,7 @@ bool MeshTopoAlgorithm::ShouldSwapEdge(unsigned long ulFacetPos, unsigned long u return fMax12 > fMax34; } -void MeshTopoAlgorithm::SwapEdge(unsigned long ulFacetPos, unsigned long ulNeighbour) +void MeshTopoAlgorithm::SwapEdge(FacetIndex ulFacetPos, FacetIndex ulNeighbour) { MeshFacet& rclF = _rclMesh._aclFacetArray[ulFacetPos]; MeshFacet& rclN = _rclMesh._aclFacetArray[ulNeighbour]; @@ -652,9 +651,9 @@ void MeshTopoAlgorithm::SwapEdge(unsigned long ulFacetPos, unsigned long ulNeigh return; // not neighbours // adjust the neighbourhood - if (rclF._aulNeighbours[(uFSide+1)%3] != ULONG_MAX) + if (rclF._aulNeighbours[(uFSide+1)%3] != FACET_INDEX_MAX) _rclMesh._aclFacetArray[rclF._aulNeighbours[(uFSide+1)%3]].ReplaceNeighbour(ulFacetPos, ulNeighbour); - if (rclN._aulNeighbours[(uNSide+1)%3] != ULONG_MAX) + if (rclN._aulNeighbours[(uNSide+1)%3] != FACET_INDEX_MAX) _rclMesh._aclFacetArray[rclN._aulNeighbours[(uNSide+1)%3]].ReplaceNeighbour(ulNeighbour, ulFacetPos); // swap the point and neighbour indices @@ -666,7 +665,7 @@ void MeshTopoAlgorithm::SwapEdge(unsigned long ulFacetPos, unsigned long ulNeigh rclN._aulNeighbours[(uNSide+1)%3] = ulFacetPos; } -bool MeshTopoAlgorithm::SplitEdge(unsigned long ulFacetPos, unsigned long ulNeighbour, const Base::Vector3f& rP) +bool MeshTopoAlgorithm::SplitEdge(FacetIndex ulFacetPos, FacetIndex ulNeighbour, const Base::Vector3f& rP) { MeshFacet& rclF = _rclMesh._aclFacetArray[ulFacetPos]; MeshFacet& rclN = _rclMesh._aclFacetArray[ulNeighbour]; @@ -677,9 +676,9 @@ bool MeshTopoAlgorithm::SplitEdge(unsigned long ulFacetPos, unsigned long ulNeig if (uFSide == USHRT_MAX || uNSide == USHRT_MAX) return false; // not neighbours - unsigned long uPtCnt = _rclMesh._aclPointArray.size(); - unsigned long uPtInd = this->GetOrAddIndex(rP); - unsigned long ulSize = _rclMesh._aclFacetArray.size(); + PointIndex uPtCnt = _rclMesh._aclPointArray.size(); + PointIndex uPtInd = this->GetOrAddIndex(rP); + FacetIndex ulSize = _rclMesh._aclFacetArray.size(); // the given point is already part of the mesh => creating new facets would // be an illegal operation @@ -687,9 +686,9 @@ bool MeshTopoAlgorithm::SplitEdge(unsigned long ulFacetPos, unsigned long ulNeig return false; // adjust the neighbourhood - if (rclF._aulNeighbours[(uFSide+1)%3] != ULONG_MAX) + if (rclF._aulNeighbours[(uFSide+1)%3] != FACET_INDEX_MAX) _rclMesh._aclFacetArray[rclF._aulNeighbours[(uFSide+1)%3]].ReplaceNeighbour(ulFacetPos, ulSize); - if (rclN._aulNeighbours[(uNSide+2)%3] != ULONG_MAX) + if (rclN._aulNeighbours[(uNSide+2)%3] != FACET_INDEX_MAX) _rclMesh._aclFacetArray[rclN._aulNeighbours[(uNSide+2)%3]].ReplaceNeighbour(ulNeighbour, ulSize+1); MeshFacet cNew1, cNew2; @@ -720,28 +719,28 @@ bool MeshTopoAlgorithm::SplitEdge(unsigned long ulFacetPos, unsigned long ulNeig return true; } -void MeshTopoAlgorithm::SplitOpenEdge(unsigned long ulFacetPos, unsigned short uSide, const Base::Vector3f& rP) +void MeshTopoAlgorithm::SplitOpenEdge(FacetIndex ulFacetPos, unsigned short uSide, const Base::Vector3f& rP) { MeshFacet& rclF = _rclMesh._aclFacetArray[ulFacetPos]; - if (rclF._aulNeighbours[uSide] != ULONG_MAX) + if (rclF._aulNeighbours[uSide] != FACET_INDEX_MAX) return; // not open - unsigned long uPtCnt = _rclMesh._aclPointArray.size(); - unsigned long uPtInd = this->GetOrAddIndex(rP); - unsigned long ulSize = _rclMesh._aclFacetArray.size(); + PointIndex uPtCnt = _rclMesh._aclPointArray.size(); + PointIndex uPtInd = this->GetOrAddIndex(rP); + FacetIndex ulSize = _rclMesh._aclFacetArray.size(); if (uPtInd < uPtCnt) return; // the given point is already part of the mesh => creating new facets would be an illegal operation // adjust the neighbourhood - if (rclF._aulNeighbours[(uSide+1)%3] != ULONG_MAX) + if (rclF._aulNeighbours[(uSide+1)%3] != FACET_INDEX_MAX) _rclMesh._aclFacetArray[rclF._aulNeighbours[(uSide+1)%3]].ReplaceNeighbour(ulFacetPos, ulSize); MeshFacet cNew; cNew._aulPoints[0] = uPtInd; cNew._aulPoints[1] = rclF._aulPoints[(uSide+1)%3]; cNew._aulPoints[2] = rclF._aulPoints[(uSide+2)%3]; - cNew._aulNeighbours[0] = ULONG_MAX; + cNew._aulNeighbours[0] = FACET_INDEX_MAX; cNew._aulNeighbours[1] = rclF._aulNeighbours[(uSide+1)%3]; cNew._aulNeighbours[2] = ulFacetPos; @@ -771,7 +770,7 @@ void MeshTopoAlgorithm::BeginCache() delete _cache; } _cache = new tCache(); - unsigned long nbPoints = _rclMesh._aclPointArray.size(); + PointIndex nbPoints = _rclMesh._aclPointArray.size(); for (unsigned int pntCpt = 0 ; pntCpt < nbPoints ; ++pntCpt) { _cache->insert(std::make_pair(_rclMesh._aclPointArray[pntCpt],pntCpt)); } @@ -782,11 +781,11 @@ void MeshTopoAlgorithm::EndCache() if (_cache) { _cache->clear(); delete _cache; - _cache = 0; + _cache = nullptr; } } -unsigned long MeshTopoAlgorithm::GetOrAddIndex (const MeshPoint &rclPoint) +PointIndex MeshTopoAlgorithm::GetOrAddIndex (const MeshPoint &rclPoint) { if (!_cache) return _rclMesh._aclPointArray.GetOrAddIndex(rclPoint); @@ -798,24 +797,24 @@ unsigned long MeshTopoAlgorithm::GetOrAddIndex (const MeshPoint &rclPoint) return retval.first->second; } -std::vector MeshTopoAlgorithm::GetFacetsToPoint(unsigned long uFacetPos, unsigned long uPointPos) const +std::vector MeshTopoAlgorithm::GetFacetsToPoint(FacetIndex uFacetPos, PointIndex uPointPos) const { // get all facets this point is referenced by - std::list aReference; + std::list aReference; aReference.push_back(uFacetPos); - std::set aRefFacet; + std::set aRefFacet; while (!aReference.empty()) { - unsigned long uIndex = aReference.front(); + FacetIndex uIndex = aReference.front(); aReference.pop_front(); aRefFacet.insert(uIndex); MeshFacet& rFace = _rclMesh._aclFacetArray[uIndex]; for (int i=0; i<3; i++) { if (rFace._aulPoints[i] == uPointPos) { - if (rFace._aulNeighbours[i] != ULONG_MAX) { + if (rFace._aulNeighbours[i] != FACET_INDEX_MAX) { if (aRefFacet.find(rFace._aulNeighbours[i]) == aRefFacet.end()) aReference.push_back( rFace._aulNeighbours[i] ); } - if (rFace._aulNeighbours[(i+2)%3] != ULONG_MAX) { + if (rFace._aulNeighbours[(i+2)%3] != FACET_INDEX_MAX) { if (aRefFacet.find(rFace._aulNeighbours[(i+2)%3]) == aRefFacet.end()) aReference.push_back( rFace._aulNeighbours[(i+2)%3] ); } @@ -825,7 +824,7 @@ std::vector MeshTopoAlgorithm::GetFacetsToPoint(unsigned long uFa } //copy the items - std::vector aRefs; + std::vector aRefs; aRefs.insert(aRefs.end(), aRefFacet.begin(), aRefFacet.end()); return aRefs; } @@ -852,8 +851,8 @@ bool MeshTopoAlgorithm::CollapseVertex(const VertexCollapse& vc) MeshFacet& rFace3 = _rclMesh._aclFacetArray[vc._circumFacets[2]]; // get the point that is not shared by rFace1 - unsigned long ptIndex = ULONG_MAX; - std::vector::const_iterator it; + PointIndex ptIndex = POINT_INDEX_MAX; + std::vector::const_iterator it; for (it = vc._circumPoints.begin(); it != vc._circumPoints.end(); ++it) { if (!rFace1.HasPoint(*it)) { ptIndex = *it; @@ -861,13 +860,13 @@ bool MeshTopoAlgorithm::CollapseVertex(const VertexCollapse& vc) } } - if (ptIndex == ULONG_MAX) + if (ptIndex == POINT_INDEX_MAX) return false; - unsigned long neighbour1 = ULONG_MAX; - unsigned long neighbour2 = ULONG_MAX; + FacetIndex neighbour1 = FACET_INDEX_MAX; + FacetIndex neighbour2 = FACET_INDEX_MAX; - const std::vector& faces = vc._circumFacets; + const std::vector& faces = vc._circumFacets; // get neighbours that are not part of the faces to be removed for (int i=0; i<3; i++) { if (std::find(faces.begin(), faces.end(), rFace2._aulNeighbours[i]) == faces.end()) { @@ -883,11 +882,11 @@ bool MeshTopoAlgorithm::CollapseVertex(const VertexCollapse& vc) rFace1.ReplaceNeighbour(vc._circumFacets[1], neighbour1); rFace1.ReplaceNeighbour(vc._circumFacets[2], neighbour2); - if (neighbour1 != ULONG_MAX) { + if (neighbour1 != FACET_INDEX_MAX) { MeshFacet& rFace4 = _rclMesh._aclFacetArray[neighbour1]; rFace4.ReplaceNeighbour(vc._circumFacets[1], vc._circumFacets[0]); } - if (neighbour2 != ULONG_MAX) { + if (neighbour2 != FACET_INDEX_MAX) { MeshFacet& rFace5 = _rclMesh._aclFacetArray[neighbour2]; rFace5.ReplaceNeighbour(vc._circumFacets[2], vc._circumFacets[0]); } @@ -902,7 +901,7 @@ bool MeshTopoAlgorithm::CollapseVertex(const VertexCollapse& vc) return true; } -bool MeshTopoAlgorithm::CollapseEdge(unsigned long ulFacetPos, unsigned long ulNeighbour) +bool MeshTopoAlgorithm::CollapseEdge(FacetIndex ulFacetPos, FacetIndex ulNeighbour) { MeshFacet& rclF = _rclMesh._aclFacetArray[ulFacetPos]; MeshFacet& rclN = _rclMesh._aclFacetArray[ulNeighbour]; @@ -917,35 +916,35 @@ bool MeshTopoAlgorithm::CollapseEdge(unsigned long ulFacetPos, unsigned long ulN return false; // the facets are marked invalid from a previous run // get the point index we want to remove - unsigned long ulPointPos = rclF._aulPoints[uFSide]; - unsigned long ulPointNew = rclN._aulPoints[uNSide]; + PointIndex ulPointPos = rclF._aulPoints[uFSide]; + PointIndex ulPointNew = rclN._aulPoints[uNSide]; // get all facets this point is referenced by - std::vector aRefs = GetFacetsToPoint(ulFacetPos, ulPointPos); - for ( std::vector::iterator it = aRefs.begin(); it != aRefs.end(); ++it ) + std::vector aRefs = GetFacetsToPoint(ulFacetPos, ulPointPos); + for ( std::vector::iterator it = aRefs.begin(); it != aRefs.end(); ++it ) { MeshFacet& rFace = _rclMesh._aclFacetArray[*it]; rFace.Transpose( ulPointPos, ulPointNew ); } // set the new neighbourhood - if (rclF._aulNeighbours[(uFSide+1)%3] != ULONG_MAX) + if (rclF._aulNeighbours[(uFSide+1)%3] != FACET_INDEX_MAX) _rclMesh._aclFacetArray[rclF._aulNeighbours[(uFSide+1)%3]].ReplaceNeighbour(ulFacetPos, rclF._aulNeighbours[(uFSide+2)%3]); - if (rclF._aulNeighbours[(uFSide+2)%3] != ULONG_MAX) + if (rclF._aulNeighbours[(uFSide+2)%3] != FACET_INDEX_MAX) _rclMesh._aclFacetArray[rclF._aulNeighbours[(uFSide+2)%3]].ReplaceNeighbour(ulFacetPos, rclF._aulNeighbours[(uFSide+1)%3]); - if (rclN._aulNeighbours[(uNSide+1)%3] != ULONG_MAX) + if (rclN._aulNeighbours[(uNSide+1)%3] != FACET_INDEX_MAX) _rclMesh._aclFacetArray[rclN._aulNeighbours[(uNSide+1)%3]].ReplaceNeighbour(ulNeighbour, rclN._aulNeighbours[(uNSide+2)%3]); - if (rclN._aulNeighbours[(uNSide+2)%3] != ULONG_MAX) + if (rclN._aulNeighbours[(uNSide+2)%3] != FACET_INDEX_MAX) _rclMesh._aclFacetArray[rclN._aulNeighbours[(uNSide+2)%3]].ReplaceNeighbour(ulNeighbour, rclN._aulNeighbours[(uNSide+1)%3]); // isolate the both facets and the point - rclF._aulNeighbours[0] = ULONG_MAX; - rclF._aulNeighbours[1] = ULONG_MAX; - rclF._aulNeighbours[2] = ULONG_MAX; + rclF._aulNeighbours[0] = FACET_INDEX_MAX; + rclF._aulNeighbours[1] = FACET_INDEX_MAX; + rclF._aulNeighbours[2] = FACET_INDEX_MAX; rclF.SetInvalid(); - rclN._aulNeighbours[0] = ULONG_MAX; - rclN._aulNeighbours[1] = ULONG_MAX; - rclN._aulNeighbours[2] = ULONG_MAX; + rclN._aulNeighbours[0] = FACET_INDEX_MAX; + rclN._aulNeighbours[1] = FACET_INDEX_MAX; + rclN._aulNeighbours[2] = FACET_INDEX_MAX; rclN.SetInvalid(); _rclMesh._aclPointArray[ulPointPos].SetInvalid(); @@ -959,16 +958,16 @@ bool MeshTopoAlgorithm::IsCollapseEdgeLegal(const EdgeCollapse& ec) const // http://stackoverflow.com/a/27049418/148668 // Check connectivity // - std::vector commonPoints; + std::vector commonPoints; std::set_intersection(ec._adjacentFrom.begin(), ec._adjacentFrom.end(), ec._adjacentTo.begin(), ec._adjacentTo.end(), - std::back_insert_iterator >(commonPoints)); + std::back_insert_iterator >(commonPoints)); if (commonPoints.size() > 2) { return false; } // Check geometry - std::vector::const_iterator it; + std::vector::const_iterator it; for (it = ec._changeFacets.begin(); it != ec._changeFacets.end(); ++it) { MeshFacet f = _rclMesh._aclFacetArray[*it]; if (!f.IsValid()) @@ -1005,16 +1004,16 @@ bool MeshTopoAlgorithm::IsCollapseEdgeLegal(const EdgeCollapse& ec) const bool MeshTopoAlgorithm::CollapseEdge(const EdgeCollapse& ec) { - std::vector::const_iterator it; + std::vector::const_iterator it; for (it = ec._removeFacets.begin(); it != ec._removeFacets.end(); ++it) { MeshFacet& f = _rclMesh._aclFacetArray[*it]; f.SetInvalid(); // adjust the neighbourhood - std::vector neighbours; + std::vector neighbours; for (int i=0; i<3; i++) { // get the neighbours of the facet that won't be invalidated - if (f._aulNeighbours[i] != ULONG_MAX) { + if (f._aulNeighbours[i] != FACET_INDEX_MAX) { if (std::find(ec._removeFacets.begin(), ec._removeFacets.end(), f._aulNeighbours[i]) == ec._removeFacets.end()) { neighbours.push_back(f._aulNeighbours[i]); @@ -1030,7 +1029,7 @@ bool MeshTopoAlgorithm::CollapseEdge(const EdgeCollapse& ec) } else if (neighbours.size() == 1) { MeshFacet& n1 = _rclMesh._aclFacetArray[neighbours[0]]; - n1.ReplaceNeighbour(*it, ULONG_MAX); + n1.ReplaceNeighbour(*it, FACET_INDEX_MAX); } } @@ -1045,61 +1044,61 @@ bool MeshTopoAlgorithm::CollapseEdge(const EdgeCollapse& ec) return true; } -bool MeshTopoAlgorithm::CollapseFacet(unsigned long ulFacetPos) +bool MeshTopoAlgorithm::CollapseFacet(FacetIndex ulFacetPos) { MeshFacet& rclF = _rclMesh._aclFacetArray[ulFacetPos]; if (!rclF.IsValid()) return false; // the facet is marked invalid from a previous run // get the point index we want to remove - unsigned long ulPointInd0 = rclF._aulPoints[0]; - unsigned long ulPointInd1 = rclF._aulPoints[1]; - unsigned long ulPointInd2 = rclF._aulPoints[2]; + PointIndex ulPointInd0 = rclF._aulPoints[0]; + PointIndex ulPointInd1 = rclF._aulPoints[1]; + PointIndex ulPointInd2 = rclF._aulPoints[2]; // move the vertex to the gravity center Base::Vector3f cCenter = _rclMesh.GetGravityPoint(rclF); _rclMesh._aclPointArray[ulPointInd0] = cCenter; // set the new point indices for all facets that share one of the points to be deleted - std::vector aRefs = GetFacetsToPoint(ulFacetPos, ulPointInd1); - for (std::vector::iterator it = aRefs.begin(); it != aRefs.end(); ++it) { + std::vector aRefs = GetFacetsToPoint(ulFacetPos, ulPointInd1); + for (std::vector::iterator it = aRefs.begin(); it != aRefs.end(); ++it) { MeshFacet& rFace = _rclMesh._aclFacetArray[*it]; rFace.Transpose(ulPointInd1, ulPointInd0); } aRefs = GetFacetsToPoint(ulFacetPos, ulPointInd2); - for (std::vector::iterator it = aRefs.begin(); it != aRefs.end(); ++it) { + for (std::vector::iterator it = aRefs.begin(); it != aRefs.end(); ++it) { MeshFacet& rFace = _rclMesh._aclFacetArray[*it]; rFace.Transpose(ulPointInd2, ulPointInd0); } // set the neighbourhood of the circumjacent facets for (int i=0; i<3; i++) { - if (rclF._aulNeighbours[i] == ULONG_MAX) + if (rclF._aulNeighbours[i] == FACET_INDEX_MAX) continue; MeshFacet& rclN = _rclMesh._aclFacetArray[rclF._aulNeighbours[i]]; unsigned short uNSide = rclN.Side(rclF); - if (rclN._aulNeighbours[(uNSide+1)%3] != ULONG_MAX) { + if (rclN._aulNeighbours[(uNSide+1)%3] != FACET_INDEX_MAX) { _rclMesh._aclFacetArray[rclN._aulNeighbours[(uNSide+1)%3]] .ReplaceNeighbour(rclF._aulNeighbours[i],rclN._aulNeighbours[(uNSide+2)%3]); } - if (rclN._aulNeighbours[(uNSide+2)%3] != ULONG_MAX) { + if (rclN._aulNeighbours[(uNSide+2)%3] != FACET_INDEX_MAX) { _rclMesh._aclFacetArray[rclN._aulNeighbours[(uNSide+2)%3]] .ReplaceNeighbour(rclF._aulNeighbours[i],rclN._aulNeighbours[(uNSide+1)%3]); } // Isolate the neighbours from the topology - rclN._aulNeighbours[0] = ULONG_MAX; - rclN._aulNeighbours[1] = ULONG_MAX; - rclN._aulNeighbours[2] = ULONG_MAX; + rclN._aulNeighbours[0] = FACET_INDEX_MAX; + rclN._aulNeighbours[1] = FACET_INDEX_MAX; + rclN._aulNeighbours[2] = FACET_INDEX_MAX; rclN.SetInvalid(); } // Isolate this facet and make two of its points invalid - rclF._aulNeighbours[0] = ULONG_MAX; - rclF._aulNeighbours[1] = ULONG_MAX; - rclF._aulNeighbours[2] = ULONG_MAX; + rclF._aulNeighbours[0] = FACET_INDEX_MAX; + rclF._aulNeighbours[1] = FACET_INDEX_MAX; + rclF._aulNeighbours[2] = FACET_INDEX_MAX; rclF.SetInvalid(); _rclMesh._aclPointArray[ulPointInd1].SetInvalid(); _rclMesh._aclPointArray[ulPointInd2].SetInvalid(); @@ -1109,7 +1108,7 @@ bool MeshTopoAlgorithm::CollapseFacet(unsigned long ulFacetPos) return true; } -void MeshTopoAlgorithm::SplitFacet(unsigned long ulFacetPos, const Base::Vector3f& rP1, const Base::Vector3f& rP2) +void MeshTopoAlgorithm::SplitFacet(FacetIndex ulFacetPos, const Base::Vector3f& rP1, const Base::Vector3f& rP2) { float fEps = MESH_MIN_EDGE_LEN; MeshFacet& rFace = _rclMesh._aclFacetArray[ulFacetPos]; @@ -1148,7 +1147,7 @@ void MeshTopoAlgorithm::SplitFacet(unsigned long ulFacetPos, const Base::Vector3 } } -void MeshTopoAlgorithm::SplitFacetOnOneEdge(unsigned long ulFacetPos, const Base::Vector3f& rP) +void MeshTopoAlgorithm::SplitFacetOnOneEdge(FacetIndex ulFacetPos, const Base::Vector3f& rP) { float fMinDist = FLOAT_MAX; unsigned short iEdgeNo = USHRT_MAX; @@ -1167,14 +1166,14 @@ void MeshTopoAlgorithm::SplitFacetOnOneEdge(unsigned long ulFacetPos, const Base } if (fMinDist < 0.05f) { - if (rFace._aulNeighbours[iEdgeNo] != ULONG_MAX) + if (rFace._aulNeighbours[iEdgeNo] != FACET_INDEX_MAX) SplitEdge(ulFacetPos, rFace._aulNeighbours[iEdgeNo], rP); else SplitOpenEdge(ulFacetPos, iEdgeNo, rP); } } -void MeshTopoAlgorithm::SplitFacetOnTwoEdges(unsigned long ulFacetPos, const Base::Vector3f& rP1, const Base::Vector3f& rP2) +void MeshTopoAlgorithm::SplitFacetOnTwoEdges(FacetIndex ulFacetPos, const Base::Vector3f& rP1, const Base::Vector3f& rP2) { // search for the matching edges unsigned short iEdgeNo1 = USHRT_MAX, iEdgeNo2 = USHRT_MAX; @@ -1210,21 +1209,21 @@ void MeshTopoAlgorithm::SplitFacetOnTwoEdges(unsigned long ulFacetPos, const Bas } // insert new points - unsigned long cntPts1 = this->GetOrAddIndex(cP1); - unsigned long cntPts2 = this->GetOrAddIndex(cP2); - unsigned long cntFts = _rclMesh.CountFacets(); + PointIndex cntPts1 = this->GetOrAddIndex(cP1); + PointIndex cntPts2 = this->GetOrAddIndex(cP2); + FacetIndex cntFts = _rclMesh.CountFacets(); unsigned short v0 = (iEdgeNo2 + 1) % 3; unsigned short v1 = iEdgeNo1; unsigned short v2 = iEdgeNo2; - unsigned long p0 = rFace._aulPoints[v0]; - unsigned long p1 = rFace._aulPoints[v1]; - unsigned long p2 = rFace._aulPoints[v2]; + PointIndex p0 = rFace._aulPoints[v0]; + PointIndex p1 = rFace._aulPoints[v1]; + PointIndex p2 = rFace._aulPoints[v2]; - unsigned long n0 = rFace._aulNeighbours[v0]; - unsigned long n1 = rFace._aulNeighbours[v1]; - unsigned long n2 = rFace._aulNeighbours[v2]; + FacetIndex n0 = rFace._aulNeighbours[v0]; + FacetIndex n1 = rFace._aulNeighbours[v1]; + FacetIndex n2 = rFace._aulNeighbours[v2]; // Modify and add facets // @@ -1244,15 +1243,15 @@ void MeshTopoAlgorithm::SplitFacetOnTwoEdges(unsigned long ulFacetPos, const Bas AddFacet(p0, cntPts1, cntPts2, cntFts, ulFacetPos, n2); } - std::vector fixIndices; + std::vector fixIndices; fixIndices.push_back(ulFacetPos); - if (n0 != ULONG_MAX) { + if (n0 != FACET_INDEX_MAX) { fixIndices.push_back(n0); } // split up the neighbour facets - if (n1 != ULONG_MAX) { + if (n1 != FACET_INDEX_MAX) { fixIndices.push_back(n1); MeshFacet& rN = _rclMesh._aclFacetArray[n1]; for (int i=0; i<3; i++) @@ -1260,7 +1259,7 @@ void MeshTopoAlgorithm::SplitFacetOnTwoEdges(unsigned long ulFacetPos, const Bas SplitFacet(n1, p1, p2, cntPts1); } - if (n2 != ULONG_MAX) { + if (n2 != FACET_INDEX_MAX) { fixIndices.push_back(n2); MeshFacet& rN = _rclMesh._aclFacetArray[n2]; for (int i=0; i<3; i++) @@ -1268,8 +1267,8 @@ void MeshTopoAlgorithm::SplitFacetOnTwoEdges(unsigned long ulFacetPos, const Bas SplitFacet(n2, p2, p0, cntPts2); } - unsigned long cntFts2 = _rclMesh.CountFacets(); - for (unsigned long i=cntFts; i& ulFacets) +void MeshTopoAlgorithm::HarmonizeNeighbours(const std::vector& ulFacets) { - for (unsigned long it : ulFacets) { - for (unsigned long jt : ulFacets) { + for (FacetIndex it : ulFacets) { + for (FacetIndex jt : ulFacets) { HarmonizeNeighbours(it, jt); } } } -void MeshTopoAlgorithm::HarmonizeNeighbours(unsigned long facet1, unsigned long facet2) +void MeshTopoAlgorithm::HarmonizeNeighbours(FacetIndex facet1, FacetIndex facet2) { if (facet1 == facet2) return; @@ -1350,21 +1349,20 @@ void MeshTopoAlgorithm::HarmonizeNeighbours(unsigned long facet1, unsigned long } } -void MeshTopoAlgorithm::SplitNeighbourFacet(unsigned long ulFacetPos, unsigned short uFSide, const Base::Vector3f rPoint) +void MeshTopoAlgorithm::SplitNeighbourFacet(FacetIndex ulFacetPos, unsigned short uFSide, const Base::Vector3f rPoint) { MeshFacet& rclF = _rclMesh._aclFacetArray[ulFacetPos]; - unsigned long ulNeighbour = rclF._aulNeighbours[uFSide]; + FacetIndex ulNeighbour = rclF._aulNeighbours[uFSide]; MeshFacet& rclN = _rclMesh._aclFacetArray[ulNeighbour]; unsigned short uNSide = rclN.Side(rclF); - //unsigned long uPtCnt = _rclMesh._aclPointArray.size(); - unsigned long uPtInd = this->GetOrAddIndex(rPoint); - unsigned long ulSize = _rclMesh._aclFacetArray.size(); + PointIndex uPtInd = this->GetOrAddIndex(rPoint); + FacetIndex ulSize = _rclMesh._aclFacetArray.size(); // adjust the neighbourhood - if (rclN._aulNeighbours[(uNSide+1)%3] != ULONG_MAX) + if (rclN._aulNeighbours[(uNSide+1)%3] != FACET_INDEX_MAX) _rclMesh._aclFacetArray[rclN._aulNeighbours[(uNSide+1)%3]].ReplaceNeighbour(ulNeighbour, ulSize); MeshFacet cNew; @@ -1407,9 +1405,9 @@ void MeshTopoAlgorithm::SplitNeighbourFacet(unsigned long ulFacetPos, unsigned s _aclNewFacets.push_back(clFacet); #endif -void MeshTopoAlgorithm::RemoveDegeneratedFacet(unsigned long index) +bool MeshTopoAlgorithm::RemoveDegeneratedFacet(FacetIndex index) { - if (index >= _rclMesh._aclFacetArray.size()) return; + if (index >= _rclMesh._aclFacetArray.size()) return false; MeshFacet& rFace = _rclMesh._aclFacetArray[index]; // coincident corners (either topological or geometrical) @@ -1417,19 +1415,19 @@ void MeshTopoAlgorithm::RemoveDegeneratedFacet(unsigned long index) const MeshPoint& rE0 = _rclMesh._aclPointArray[rFace._aulPoints[i]]; const MeshPoint& rE1 = _rclMesh._aclPointArray[rFace._aulPoints[(i+1)%3]]; if (rE0 == rE1) { - unsigned long uN1 = rFace._aulNeighbours[(i+1)%3]; - unsigned long uN2 = rFace._aulNeighbours[(i+2)%3]; - if (uN2 != ULONG_MAX) + FacetIndex uN1 = rFace._aulNeighbours[(i+1)%3]; + FacetIndex uN2 = rFace._aulNeighbours[(i+2)%3]; + if (uN2 != FACET_INDEX_MAX) _rclMesh._aclFacetArray[uN2].ReplaceNeighbour(index, uN1); - if (uN1 != ULONG_MAX) + if (uN1 != FACET_INDEX_MAX) _rclMesh._aclFacetArray[uN1].ReplaceNeighbour(index, uN2); // isolate the face and remove it - rFace._aulNeighbours[0] = ULONG_MAX; - rFace._aulNeighbours[1] = ULONG_MAX; - rFace._aulNeighbours[2] = ULONG_MAX; + rFace._aulNeighbours[0] = FACET_INDEX_MAX; + rFace._aulNeighbours[1] = FACET_INDEX_MAX; + rFace._aulNeighbours[2] = FACET_INDEX_MAX; _rclMesh.DeleteFacet(index); - return; + return true; } } @@ -1442,8 +1440,8 @@ void MeshTopoAlgorithm::RemoveDegeneratedFacet(unsigned long index) // adjust the neighbourhoods and point indices if (cVec1 * cVec2 < 0.0f) { - unsigned long uN1 = rFace._aulNeighbours[(j+1)%3]; - if (uN1 != ULONG_MAX) { + FacetIndex uN1 = rFace._aulNeighbours[(j+1)%3]; + if (uN1 != FACET_INDEX_MAX) { // get the neighbour and common edge side MeshFacet& rNb = _rclMesh._aclFacetArray[uN1]; unsigned short side = rNb.Side(index); @@ -1453,14 +1451,14 @@ void MeshTopoAlgorithm::RemoveDegeneratedFacet(unsigned long index) rNb._aulPoints[(side+1)%3] = rFace._aulPoints[j]; // set correct neighbourhood - unsigned long uN2 = rFace._aulNeighbours[(j+2)%3]; + FacetIndex uN2 = rFace._aulNeighbours[(j+2)%3]; rNb._aulNeighbours[side] = uN2; - if (uN2 != ULONG_MAX) { + if (uN2 != FACET_INDEX_MAX) { _rclMesh._aclFacetArray[uN2].ReplaceNeighbour(index, uN1); } - unsigned long uN3 = rNb._aulNeighbours[(side+1)%3]; + FacetIndex uN3 = rNb._aulNeighbours[(side+1)%3]; rFace._aulNeighbours[(j+1)%3] = uN3; - if (uN3 != ULONG_MAX) { + if (uN3 != FACET_INDEX_MAX) { _rclMesh._aclFacetArray[uN3].ReplaceNeighbour(uN1, index); } rNb._aulNeighbours[(side+1)%3] = index; @@ -1469,12 +1467,14 @@ void MeshTopoAlgorithm::RemoveDegeneratedFacet(unsigned long index) else _rclMesh.DeleteFacet(index); - return; + return true; } } + + return false; } -bool MeshTopoAlgorithm::RemoveCorruptedFacet(unsigned long index) +bool MeshTopoAlgorithm::RemoveCorruptedFacet(FacetIndex index) { if (index >= _rclMesh._aclFacetArray.size()) return false; MeshFacet& rFace = _rclMesh._aclFacetArray[index]; @@ -1482,17 +1482,17 @@ bool MeshTopoAlgorithm::RemoveCorruptedFacet(unsigned long index) // coincident corners (topological) for (int i=0; i<3; i++) { if (rFace._aulPoints[i] == rFace._aulPoints[(i+1)%3]) { - unsigned long uN1 = rFace._aulNeighbours[(i+1)%3]; - unsigned long uN2 = rFace._aulNeighbours[(i+2)%3]; - if (uN2 != ULONG_MAX) + FacetIndex uN1 = rFace._aulNeighbours[(i+1)%3]; + FacetIndex uN2 = rFace._aulNeighbours[(i+2)%3]; + if (uN2 != FACET_INDEX_MAX) _rclMesh._aclFacetArray[uN2].ReplaceNeighbour(index, uN1); - if (uN1 != ULONG_MAX) + if (uN1 != FACET_INDEX_MAX) _rclMesh._aclFacetArray[uN1].ReplaceNeighbour(index, uN2); // isolate the face and remove it - rFace._aulNeighbours[0] = ULONG_MAX; - rFace._aulNeighbours[1] = ULONG_MAX; - rFace._aulNeighbours[2] = ULONG_MAX; + rFace._aulNeighbours[0] = FACET_INDEX_MAX; + rFace._aulNeighbours[1] = FACET_INDEX_MAX; + rFace._aulNeighbours[2] = FACET_INDEX_MAX; _rclMesh.DeleteFacet(index); return true; } @@ -1503,17 +1503,17 @@ bool MeshTopoAlgorithm::RemoveCorruptedFacet(unsigned long index) void MeshTopoAlgorithm::FillupHoles(unsigned long length, int level, AbstractPolygonTriangulator& cTria, - std::list >& aFailed) + std::list >& aFailed) { // get the mesh boundaries as an array of point indices - std::list > aBorders, aFillBorders; + std::list > aBorders, aFillBorders; MeshAlgorithm cAlgo(_rclMesh); cAlgo.GetMeshBorders(aBorders); // split boundary loops if needed cAlgo.SplitBoundaryLoops(aBorders); - for (std::list >::iterator it = aBorders.begin(); it != aBorders.end(); ++it) { + for (std::list >::iterator it = aBorders.begin(); it != aBorders.end(); ++it) { if (it->size()-1 <= length) // ignore boundary with too many edges aFillBorders.push_back(*it); } @@ -1523,8 +1523,8 @@ void MeshTopoAlgorithm::FillupHoles(unsigned long length, int level, } void MeshTopoAlgorithm::FillupHoles(int level, AbstractPolygonTriangulator& cTria, - const std::list >& aBorders, - std::list >& aFailed) + const std::list >& aBorders, + std::list >& aFailed) { // get the facets to a point MeshRefPointToFacets cPt2Fac(_rclMesh); @@ -1533,10 +1533,10 @@ void MeshTopoAlgorithm::FillupHoles(int level, AbstractPolygonTriangulator& cTri MeshFacetArray newFacets; MeshPointArray newPoints; unsigned long numberOfOldPoints = _rclMesh._aclPointArray.size(); - for (std::list >::const_iterator it = aBorders.begin(); it != aBorders.end(); ++it) { + for (std::list >::const_iterator it = aBorders.begin(); it != aBorders.end(); ++it) { MeshFacetArray cFacets; MeshPointArray cPoints; - std::vector bound = *it; + std::vector bound = *it; if (cAlgo.FillupHole(bound, cTria, cFacets, cPoints, level, &cPt2Fac)) { if (bound.front() == bound.back()) bound.pop_back(); @@ -1594,24 +1594,24 @@ void MeshTopoAlgorithm::FillupHoles(int level, AbstractPolygonTriangulator& cTri } void MeshTopoAlgorithm::FindHoles(unsigned long length, - std::list >& aBorders) const + std::list >& aBorders) const { - std::list > border; + std::list > border; MeshAlgorithm cAlgo(_rclMesh); cAlgo.GetMeshBorders(border); - for (std::list >::iterator it = border.begin(); + for (std::list >::iterator it = border.begin(); it != border.end(); ++it) { if (it->size() <= length) aBorders.push_back(*it); } } -void MeshTopoAlgorithm::FindComponents(unsigned long count, std::vector& findIndices) +void MeshTopoAlgorithm::FindComponents(unsigned long count, std::vector& findIndices) { - std::vector > segments; + std::vector > segments; MeshComponents comp(_rclMesh); comp.SearchForComponents(MeshComponents::OverEdge,segments); - for (std::vector >::iterator it = segments.begin(); it != segments.end(); ++it) { + for (std::vector >::iterator it = segments.begin(); it != segments.end(); ++it) { if (it->size() <= count) findIndices.insert(findIndices.end(), it->begin(), it->end()); } @@ -1619,20 +1619,20 @@ void MeshTopoAlgorithm::FindComponents(unsigned long count, std::vector removeFacets; + std::vector removeFacets; FindComponents(count, removeFacets); if (!removeFacets.empty()) _rclMesh.DeleteFacets(removeFacets); } -void MeshTopoAlgorithm::HarmonizeNormals (void) +void MeshTopoAlgorithm::HarmonizeNormals () { - std::vector uIndices = MeshEvalOrientation(_rclMesh).GetIndices(); - for ( std::vector::iterator it = uIndices.begin(); it != uIndices.end(); ++it ) + std::vector uIndices = MeshEvalOrientation(_rclMesh).GetIndices(); + for ( std::vector::iterator it = uIndices.begin(); it != uIndices.end(); ++it ) _rclMesh._aclFacetArray[*it].FlipNormal(); } -void MeshTopoAlgorithm::FlipNormals (void) +void MeshTopoAlgorithm::FlipNormals () { for (MeshFacetArray::_TIterator i = _rclMesh._aclFacetArray.begin(); i < _rclMesh._aclFacetArray.end(); ++i) i->FlipNormal(); @@ -1672,20 +1672,20 @@ MeshComponents::~MeshComponents() { } -void MeshComponents::SearchForComponents(TMode tMode, std::vector >& aclT) const +void MeshComponents::SearchForComponents(TMode tMode, std::vector >& aclT) const { // all facets - std::vector aulAllFacets(_rclMesh.CountFacets()); - unsigned long k = 0; - for (std::vector::iterator pI = aulAllFacets.begin(); pI != aulAllFacets.end(); ++pI) + std::vector aulAllFacets(_rclMesh.CountFacets()); + FacetIndex k = 0; + for (std::vector::iterator pI = aulAllFacets.begin(); pI != aulAllFacets.end(); ++pI) *pI = k++; SearchForComponents( tMode, aulAllFacets, aclT ); } -void MeshComponents::SearchForComponents(TMode tMode, const std::vector& aSegment, std::vector >& aclT) const +void MeshComponents::SearchForComponents(TMode tMode, const std::vector& aSegment, std::vector >& aclT) const { - unsigned long ulStartFacet, ulVisited; + FacetIndex ulStartFacet; if (_rclMesh.CountFacets() == 0) return; @@ -1701,7 +1701,7 @@ void MeshComponents::SearchForComponents(TMode tMode, const std::vector flag; iTri = std::find_if(iTri, iEnd, [flag](const MeshFacet& f) { return flag(f, MeshFacet::VISIT); @@ -1709,11 +1709,11 @@ void MeshComponents::SearchForComponents(TMode tMode, const std::vector aclComponent; - std::vector > aclConnectComp; + std::vector aclComponent; + std::vector > aclConnectComp; MeshTopFacetVisitor clFVisitor( aclComponent ); - while ( ulStartFacet != ULONG_MAX ) + while ( ulStartFacet != FACET_INDEX_MAX ) { // collect all facets of a component aclComponent.clear(); @@ -1736,7 +1736,7 @@ void MeshComponents::SearchForComponents(TMode tMode, const std::vector >& aFailed); + std::list >& aFailed); /** * This is an overloaded method provided for convenience. It takes as first argument * the boundaries which must be filled up. */ void FillupHoles(int level, AbstractPolygonTriangulator&, - const std::list >& aBorders, - std::list >& aFailed); + const std::list >& aBorders, + std::list >& aFailed); /** * Find holes which consists of up to \a length edges. */ void FindHoles(unsigned long length, - std::list >& aBorders) const; + std::list >& aBorders) const; /** * Find topologic independent components with maximum \a count facets * and returns an array of the indices. */ - void FindComponents(unsigned long count, std::vector& aInds); + void FindComponents(unsigned long count, std::vector& aInds); /** * Removes topologic independent components with maximum \a count facets. */ @@ -273,11 +273,11 @@ public: /** * Harmonizes the normals. */ - void HarmonizeNormals (void); + void HarmonizeNormals (); /** * Flips the normals. */ - void FlipNormals (void); + void FlipNormals (); /** * Caching facility. */ @@ -288,28 +288,28 @@ private: /** * Splits the neighbour facet of \a ulFacetPos on side \a uSide. */ - void SplitNeighbourFacet(unsigned long ulFacetPos, unsigned short uSide, + void SplitNeighbourFacet(FacetIndex ulFacetPos, unsigned short uSide, const Base::Vector3f rPoint); - void SplitFacetOnOneEdge(unsigned long ulFacetPos, + void SplitFacetOnOneEdge(FacetIndex ulFacetPos, const Base::Vector3f& rP1); - void SplitFacetOnTwoEdges(unsigned long ulFacetPos, + void SplitFacetOnTwoEdges(FacetIndex ulFacetPos, const Base::Vector3f& rP1, const Base::Vector3f& rP2); - void SplitFacet(unsigned long ulFacetPos, unsigned long P1, - unsigned long P2, unsigned long Pn); - void AddFacet(unsigned long P1, unsigned long P2, unsigned long P3); - void AddFacet(unsigned long P1, unsigned long P2, unsigned long P3, - unsigned long N1, unsigned long N2, unsigned long N3); - void HarmonizeNeighbours(unsigned long facet1, unsigned long facet2); - void HarmonizeNeighbours(const std::vector& ulFacets); + void SplitFacet(FacetIndex ulFacetPos, PointIndex P1, + PointIndex P2, PointIndex Pn); + void AddFacet(PointIndex P1, PointIndex P2, PointIndex P3); + void AddFacet(PointIndex P1, PointIndex P2, PointIndex P3, + FacetIndex N1, FacetIndex N2, FacetIndex N3); + void HarmonizeNeighbours(FacetIndex facet1, FacetIndex facet2); + void HarmonizeNeighbours(const std::vector& ulFacets); /** * Returns all facets that references the point index \a uPointPos. \a uFacetPos * is a facet that must reference this point and is added to the list as well. */ - std::vector GetFacetsToPoint(unsigned long uFacetPos, - unsigned long uPointPos) const; + std::vector GetFacetsToPoint(FacetIndex uFacetPos, + PointIndex uPointPos) const; /** \internal */ - unsigned long GetOrAddIndex (const MeshPoint &rclPoint); + PointIndex GetOrAddIndex (const MeshPoint &rclPoint); private: MeshKernel& _rclMesh; @@ -321,7 +321,7 @@ private: }; // cache - typedef std::map tCache; + typedef std::map tCache; tCache* _cache; }; @@ -344,21 +344,21 @@ public: * sharing the same edge are regarded as connected, if \a tMode is \a OverPoint * then facets sharing a common point are regarded as connected. */ - void SearchForComponents(TMode tMode, std::vector >& aclT) const; + void SearchForComponents(TMode tMode, std::vector >& aclT) const; /** * Does basically the same as the method above escept that only the faces in * \a aSegment are regarded. */ - void SearchForComponents(TMode tMode, const std::vector& aSegment, - std::vector >& aclT) const; + void SearchForComponents(TMode tMode, const std::vector& aSegment, + std::vector >& aclT) const; protected: // for sorting of elements struct CNofFacetsCompare { - bool operator () (const std::vector &rclC1, - const std::vector &rclC2) + bool operator () (const std::vector &rclC1, + const std::vector &rclC2) { return rclC1.size() > rclC2.size(); } diff --git a/src/Mod/Mesh/App/Core/Triangulation.cpp b/src/Mod/Mesh/App/Core/Triangulation.cpp index 816d30a7b9..799e806e0e 100644 --- a/src/Mod/Mesh/App/Core/Triangulation.cpp +++ b/src/Mod/Mesh/App/Core/Triangulation.cpp @@ -253,7 +253,7 @@ bool AbstractPolygonTriangulator::TriangulatePolygon() } } -std::vector AbstractPolygonTriangulator::GetInfo() const +std::vector AbstractPolygonTriangulator::GetInfo() const { return _info; } @@ -292,7 +292,7 @@ bool EarClippingTriangulator::Triangulate() _triangles.clear(); std::vector pts = ProjectToFitPlane(); - std::vector result; + std::vector result; // Invoke the triangulator to triangulate this polygon. Triangulate::Process(pts,result); @@ -306,7 +306,7 @@ bool EarClippingTriangulator::Triangulate() MeshGeomFacet clFacet; MeshFacet clTopFacet; - for (unsigned long i=0; i &contour, - std::vector &result) + std::vector &result) { /* allocate and initialize list of Vertices in polygon */ @@ -483,30 +483,30 @@ bool QuasiDelaunayTriangulator::Triangulate() // For each internal edge get the adjacent facets. When doing an edge swap we must update // this structure. - std::map, std::vector > aEdge2Face; + std::map, std::vector > aEdge2Face; for (std::vector::iterator pI = _facets.begin(); pI != _facets.end(); ++pI) { for (int i = 0; i < 3; i++) { - unsigned long ulPt0 = std::min(pI->_aulPoints[i], pI->_aulPoints[(i+1)%3]); - unsigned long ulPt1 = std::max(pI->_aulPoints[i], pI->_aulPoints[(i+1)%3]); + PointIndex ulPt0 = std::min(pI->_aulPoints[i], pI->_aulPoints[(i+1)%3]); + PointIndex ulPt1 = std::max(pI->_aulPoints[i], pI->_aulPoints[(i+1)%3]); // ignore borderlines of the polygon if ((ulPt1-ulPt0)%(_points.size()-1) > 1) - aEdge2Face[std::pair(ulPt0, ulPt1)].push_back(pI - _facets.begin()); + aEdge2Face[std::pair(ulPt0, ulPt1)].push_back(pI - _facets.begin()); } } // fill up this list with all internal edges and perform swap edges until this list is empty - std::list > aEdgeList; - std::map, std::vector >::iterator pE; + std::list > aEdgeList; + std::map, std::vector >::iterator pE; for (pE = aEdge2Face.begin(); pE != aEdge2Face.end(); ++pE) aEdgeList.push_back(pE->first); // to be sure to avoid an endless loop - unsigned long uMaxIter = 5 * aEdge2Face.size(); + size_t uMaxIter = 5 * aEdge2Face.size(); // Perform a swap edge where needed while (!aEdgeList.empty() && uMaxIter > 0) { // get the first edge and remove it from the list - std::pair aEdge = aEdgeList.front(); + std::pair aEdge = aEdgeList.front(); aEdgeList.pop_front(); uMaxIter--; @@ -556,10 +556,10 @@ bool QuasiDelaunayTriangulator::Triangulate() // adjust the edge list for (int i=0; i<3; i++) { - std::map, std::vector >::iterator it; + std::map, std::vector >::iterator it; // first facet - unsigned long ulPt0 = std::min(rF1._aulPoints[i], rF1._aulPoints[(i+1)%3]); - unsigned long ulPt1 = std::max(rF1._aulPoints[i], rF1._aulPoints[(i+1)%3]); + PointIndex ulPt0 = std::min(rF1._aulPoints[i], rF1._aulPoints[(i+1)%3]); + PointIndex ulPt1 = std::max(rF1._aulPoints[i], rF1._aulPoints[(i+1)%3]); it = aEdge2Face.find( std::make_pair(ulPt0, ulPt1) ); if (it != aEdge2Face.end()) { if (it->second[0] == pE->second[1]) @@ -570,8 +570,8 @@ bool QuasiDelaunayTriangulator::Triangulate() } // second facet - ulPt0 = std::min(rF2._aulPoints[i], rF2._aulPoints[(i+1)%3]); - ulPt1 = std::max(rF2._aulPoints[i], rF2._aulPoints[(i+1)%3]); + ulPt0 = std::min(rF2._aulPoints[i], rF2._aulPoints[(i+1)%3]); + ulPt1 = std::max(rF2._aulPoints[i], rF2._aulPoints[(i+1)%3]); it = aEdge2Face.find( std::make_pair(ulPt0, ulPt1) ); if (it != aEdge2Face.end()) { if (it->second[0] == pE->second[0]) @@ -583,9 +583,9 @@ bool QuasiDelaunayTriangulator::Triangulate() } // Now we must remove the edge and replace it through the new edge - unsigned long ulPt0 = std::min(rF1._aulPoints[(side1+1)%3], rF2._aulPoints[(side2+1)%3]); - unsigned long ulPt1 = std::max(rF1._aulPoints[(side1+1)%3], rF2._aulPoints[(side2+1)%3]); - std::pair aNewEdge = std::make_pair(ulPt0, ulPt1); + PointIndex ulPt0 = std::min(rF1._aulPoints[(side1+1)%3], rF2._aulPoints[(side2+1)%3]); + PointIndex ulPt1 = std::max(rF1._aulPoints[(side1+1)%3], rF2._aulPoints[(side2+1)%3]); + std::pair aNewEdge = std::make_pair(ulPt0, ulPt1); aEdge2Face[aNewEdge] = pE->second; aEdge2Face.erase(pE); } @@ -664,7 +664,7 @@ bool DelaunayTriangulator::Triangulate() // then the triangulation must have 2*N-2-H triangles and 3*N-3-H // edges. int iEQuantity = 0; - int* aiIndex = 0; + int* aiIndex = nullptr; del.GetHull(iEQuantity,aiIndex); int iUniqueVQuantity = del.GetUniqueVertexQuantity(); int iTVerify = 2*iUniqueVQuantity - 2 - iEQuantity; @@ -680,7 +680,7 @@ bool DelaunayTriangulator::Triangulate() for (int i = 0; i < iTQuantity; i++) { for (int j=0; j<3; j++) { size_t index = static_cast(aiTVertex[static_cast(3*i+j)]); - facet._aulPoints[j] = static_cast(index); + facet._aulPoints[j] = static_cast(index); triangle._aclPoints[j].x = static_cast(akVertex[index].X()); triangle._aclPoints[j].y = static_cast(akVertex[index].Y()); } diff --git a/src/Mod/Mesh/App/Core/Triangulation.h b/src/Mod/Mesh/App/Core/Triangulation.h index 4899cc2dfe..805a835823 100644 --- a/src/Mod/Mesh/App/Core/Triangulation.h +++ b/src/Mod/Mesh/App/Core/Triangulation.h @@ -63,7 +63,7 @@ public: /** Sets the polygon to be triangulated. */ void SetPolygon(const std::vector& raclPoints); - void SetIndices(const std::vector& d) {_indices = d;} + void SetIndices(const std::vector& d) {_indices = d;} /** Set a verifier object that checks if the generated triangulation * can be accepted and added to the mesh kernel. * The triangulator takes ownership of the passed verifier. @@ -117,7 +117,7 @@ public: * It returns an array of the number of edges for each closed * polygon. */ - std::vector GetInfo() const; + std::vector GetInfo() const; virtual void Discard(); /** Resets some internals. The default implementation does nothing.*/ virtual void Reset(); @@ -132,12 +132,12 @@ protected: protected: bool _discard; Base::Matrix4D _inverse; - std::vector _indices; + std::vector _indices; std::vector _points; std::vector _newpoints; std::vector _triangles; std::vector _facets; - std::vector _info; + std::vector _info; TriangulationVerifier* _verifier; }; @@ -170,7 +170,7 @@ private: // triangulate a contour/polygon, places results in STL vector // as series of triangles.indicating the points static bool Process(const std::vector &contour, - std::vector &result); + std::vector &result); // compute area of a contour/polygon static float Area(const std::vector &contour); diff --git a/src/Mod/Mesh/App/Core/Trim.cpp b/src/Mod/Mesh/App/Core/Trim.cpp index e08fa463ad..0101f7d82b 100644 --- a/src/Mod/Mesh/App/Core/Trim.cpp +++ b/src/Mod/Mesh/App/Core/Trim.cpp @@ -53,16 +53,16 @@ void MeshTrimming::SetInnerOrOuter(TMode tMode) } } -void MeshTrimming::CheckFacets(const MeshFacetGrid& rclGrid, std::vector &raulFacets) const +void MeshTrimming::CheckFacets(const MeshFacetGrid& rclGrid, std::vector &raulFacets) const { - std::vector::iterator it; + std::vector::iterator it; MeshFacetIterator clIter(myMesh, 0); // cut inner: use grid to accelerate search if (myInner) { Base::BoundBox3f clBBox3d; Base::BoundBox2d clViewBBox, clPolyBBox; - std::vector aulAllElements; + std::vector aulAllElements; // BBox of polygon clPolyBBox = myPoly.CalcBoundBox(); @@ -103,13 +103,11 @@ void MeshTrimming::CheckFacets(const MeshFacetGrid& rclGrid, std::vectoroperator ()(rclFacet._aclPoints[i]); if (myPoly.Contains(Base::Vector2d(clPt2d.x, clPt2d.y)) == myInner) return true; @@ -118,17 +116,17 @@ bool MeshTrimming::HasIntersection(const MeshGeomFacet& rclFacet) const } // is corner of polygon inside the facet - for (j=0; j(A.x*B.y+A.y*C.x+B.x*C.y-(B.y*C.x+A.y*B.x+A.x*C.y)); - for (unsigned long j=0; j calculate the corresponding 3d-point if (clFacPoly.Contains(myPoly[j])) { P = myPoly[j]; @@ -195,7 +193,7 @@ bool MeshTrimming::IsPolygonPointInFacet(unsigned long ulIndex, Base::Vector3f& return false; } -bool MeshTrimming::GetIntersectionPointsOfPolygonAndFacet(unsigned long ulIndex, int& iSide, std::vector& raclPoints) const +bool MeshTrimming::GetIntersectionPointsOfPolygonAndFacet(FacetIndex ulIndex, int& iSide, std::vector& raclPoints) const { MeshGeomFacet clFac(myMesh.GetFacet(ulIndex)); Base::Vector2d S; @@ -206,7 +204,7 @@ bool MeshTrimming::GetIntersectionPointsOfPolygonAndFacet(unsigned long ulIndex, // Edge with no intersection iSide = -1; - for (unsigned long i=0; i& raclPoints, std::vector& aclNewFacets) +bool MeshTrimming::CreateFacets(FacetIndex ulFacetPos, int iSide, const std::vector& raclPoints, std::vector& aclNewFacets) { MeshGeomFacet clFac; @@ -603,7 +601,7 @@ bool MeshTrimming::CreateFacets(unsigned long ulFacetPos, int iSide, const std:: return true; } -bool MeshTrimming::CreateFacets(unsigned long ulFacetPos, int iSide, const std::vector& raclPoints, Base::Vector3f& clP3, +bool MeshTrimming::CreateFacets(FacetIndex ulFacetPos, int iSide, const std::vector& raclPoints, Base::Vector3f& clP3, std::vector& aclNewFacets) { // no valid triangulation possible @@ -716,14 +714,14 @@ bool MeshTrimming::CreateFacets(unsigned long ulFacetPos, int iSide, const std:: return true; } -void MeshTrimming::TrimFacets(const std::vector& raulFacets, std::vector& aclNewFacets) +void MeshTrimming::TrimFacets(const std::vector& raulFacets, std::vector& aclNewFacets) { Base::Vector3f clP; std::vector clIntsct; int iSide; Base::SequencerLauncher seq("trimming facets...", raulFacets.size()); - for (std::vector::const_iterator it=raulFacets.begin(); it!=raulFacets.end(); ++it) { + for (std::vector::const_iterator it=raulFacets.begin(); it!=raulFacets.end(); ++it) { clIntsct.clear(); if (IsPolygonPointInFacet(*it, clP) == false) { // facet must be trimmed diff --git a/src/Mod/Mesh/App/Core/Trim.h b/src/Mod/Mesh/App/Core/Trim.h index 857c9ad55b..3482008750 100644 --- a/src/Mod/Mesh/App/Core/Trim.h +++ b/src/Mod/Mesh/App/Core/Trim.h @@ -46,12 +46,12 @@ public: /** * Checks all facets for intersection with the polygon and writes all touched facets into the vector */ - void CheckFacets(const MeshFacetGrid& rclGrid, std::vector& raulFacets) const; + void CheckFacets(const MeshFacetGrid& rclGrid, std::vector& raulFacets) const; /** * The facets from raulFacets will be trimmed or deleted and aclNewFacets gives the new generated facets */ - void TrimFacets(const std::vector& raulFacets, std::vector& aclNewFacets); + void TrimFacets(const std::vector& raulFacets, std::vector& aclNewFacets); /** * Setter: Trimm INNER or OUTER @@ -67,30 +67,30 @@ private: /** * Checks if a facet lies totally within a polygon */ - bool PolygonContainsCompleteFacet(bool bInner, unsigned long ulIndex) const; + bool PolygonContainsCompleteFacet(bool bInner, FacetIndex ulIndex) const; /** * Creates new facets from edge points of the facet */ - bool CreateFacets(unsigned long ulFacetPos, int iSide, const std::vector& raclPoints, + bool CreateFacets(FacetIndex ulFacetPos, int iSide, const std::vector& raclPoints, std::vector& aclNewFacets); /** * Creates new facets from edge points of the facet and a point inside the facet */ - bool CreateFacets(unsigned long ulFacetPos, int iSide, const std::vector& raclPoints, + bool CreateFacets(FacetIndex ulFacetPos, int iSide, const std::vector& raclPoints, Base::Vector3f& clP3, std::vector& aclNewFacets); /** * Checks if a polygon point lies within a facet */ - bool IsPolygonPointInFacet(unsigned long ulIndex, Base::Vector3f& clPoint); + bool IsPolygonPointInFacet(FacetIndex ulIndex, Base::Vector3f& clPoint); /** * Calculates the two intersection points between polygonline and facet in 2D * and project the points back into 3D (not very exactly) */ - bool GetIntersectionPointsOfPolygonAndFacet(unsigned long ulIndex, int& iSide, + bool GetIntersectionPointsOfPolygonAndFacet(FacetIndex ulIndex, int& iSide, std::vector& raclPoints) const; void AdjustFacet(MeshFacet& facet, int iInd); diff --git a/src/Mod/Mesh/App/Core/TrimByPlane.cpp b/src/Mod/Mesh/App/Core/TrimByPlane.cpp index 49b81d11b0..d785b5772b 100644 --- a/src/Mod/Mesh/App/Core/TrimByPlane.cpp +++ b/src/Mod/Mesh/App/Core/TrimByPlane.cpp @@ -39,12 +39,12 @@ MeshTrimByPlane::~MeshTrimByPlane() } void MeshTrimByPlane::CheckFacets(const MeshFacetGrid& rclGrid, const Base::Vector3f& base, const Base::Vector3f& normal, - std::vector &trimFacets, std::vector& removeFacets) const + std::vector &trimFacets, std::vector& removeFacets) const { // Go through the grid and check for each cell if its bounding box intersects the plane. // If the box is completely below the plane all facets will be kept, if it's above the // plane all triangles will be removed. - std::vector checkElements; + std::vector checkElements; MeshGridIterator clGridIter(rclGrid); for (clGridIter.Init(); clGridIter.More(); clGridIter.Next()) { Base::BoundBox3f clBBox3d = clGridIter.GetBoundBox(); @@ -134,7 +134,7 @@ void MeshTrimByPlane::CreateTwoFacet(const Base::Vector3f& base, const Base::Vec trimmedFacets.push_back(create); } -void MeshTrimByPlane::TrimFacets(const std::vector& trimFacets, const Base::Vector3f& base, +void MeshTrimByPlane::TrimFacets(const std::vector& trimFacets, const Base::Vector3f& base, const Base::Vector3f& normal, std::vector& trimmedFacets) { trimmedFacets.reserve(2 * trimFacets.size()); diff --git a/src/Mod/Mesh/App/Core/TrimByPlane.h b/src/Mod/Mesh/App/Core/TrimByPlane.h index 0da728355f..6192365e5a 100644 --- a/src/Mod/Mesh/App/Core/TrimByPlane.h +++ b/src/Mod/Mesh/App/Core/TrimByPlane.h @@ -43,12 +43,12 @@ public: * Checks all facets for intersection with the plane and writes all touched facets into the vector */ void CheckFacets(const MeshFacetGrid& rclGrid, const Base::Vector3f& base, const Base::Vector3f& normal, - std::vector& trimFacets, std::vector& removeFacets) const; + std::vector& trimFacets, std::vector& removeFacets) const; /** * The facets from \a trimFacets will be trimmed or deleted and \a trimmedFacets holds the newly generated facets */ - void TrimFacets(const std::vector& trimFacets, const Base::Vector3f& base, + void TrimFacets(const std::vector& trimFacets, const Base::Vector3f& base, const Base::Vector3f& normal, std::vector& trimmedFacets); private: diff --git a/src/Mod/Mesh/App/Core/Visitor.cpp b/src/Mod/Mesh/App/Core/Visitor.cpp index b532adbefe..ab0b17a4f7 100644 --- a/src/Mod/Mesh/App/Core/Visitor.cpp +++ b/src/Mod/Mesh/App/Core/Visitor.cpp @@ -31,12 +31,12 @@ using namespace MeshCore; -unsigned long MeshKernel::VisitNeighbourFacets (MeshFacetVisitor &rclFVisitor, unsigned long ulStartFacet) const +unsigned long MeshKernel::VisitNeighbourFacets (MeshFacetVisitor &rclFVisitor, FacetIndex ulStartFacet) const { unsigned long ulVisited = 0, j, ulLevel = 0; unsigned long ulCount = _aclFacetArray.size(); - std::vector clCurrentLevel, clNextLevel; - std::vector::iterator clCurrIter; + std::vector clCurrentLevel, clNextLevel; + std::vector::iterator clCurrIter; MeshFacetArray::_TConstIterator clCurrFacet, clNBFacet; // pick up start point @@ -52,7 +52,7 @@ unsigned long MeshKernel::VisitNeighbourFacets (MeshFacetVisitor &rclFVisitor, u // visit all neighbours of the current level if not yet done for (unsigned short i = 0; i < 3; i++) { j = clCurrFacet->_aulNeighbours[i]; // index to neighbour facet - if (j == ULONG_MAX) + if (j == FACET_INDEX_MAX) continue; // no neighbour facet if (j >= ulCount) @@ -83,28 +83,28 @@ unsigned long MeshKernel::VisitNeighbourFacets (MeshFacetVisitor &rclFVisitor, u return ulVisited; } -unsigned long MeshKernel::VisitNeighbourFacetsOverCorners (MeshFacetVisitor &rclFVisitor, unsigned long ulStartFacet) const +unsigned long MeshKernel::VisitNeighbourFacetsOverCorners (MeshFacetVisitor &rclFVisitor, FacetIndex ulStartFacet) const { unsigned long ulVisited = 0, ulLevel = 0; MeshRefPointToFacets clRPF(*this); const MeshFacetArray& raclFAry = _aclFacetArray; MeshFacetArray::_TConstIterator pFBegin = raclFAry.begin(); - std::vector aclCurrentLevel, aclNextLevel; + std::vector aclCurrentLevel, aclNextLevel; aclCurrentLevel.push_back(ulStartFacet); raclFAry[ulStartFacet].SetFlag(MeshFacet::VISIT); while (aclCurrentLevel.size() > 0) { // visit all neighbours of the current level - for (std::vector::iterator pCurrFacet = aclCurrentLevel.begin(); pCurrFacet < aclCurrentLevel.end(); ++pCurrFacet) { + for (std::vector::iterator pCurrFacet = aclCurrentLevel.begin(); pCurrFacet < aclCurrentLevel.end(); ++pCurrFacet) { for (int i = 0; i < 3; i++) { const MeshFacet &rclFacet = raclFAry[*pCurrFacet]; - const std::set& raclNB = clRPF[rclFacet._aulPoints[i]]; - for (std::set::const_iterator pINb = raclNB.begin(); pINb != raclNB.end(); ++pINb) { + const std::set& raclNB = clRPF[rclFacet._aulPoints[i]]; + for (std::set::const_iterator pINb = raclNB.begin(); pINb != raclNB.end(); ++pINb) { if (pFBegin[*pINb].IsFlag(MeshFacet::VISIT) == false) { // only visit if VISIT Flag not set ulVisited++; - unsigned long ulFInd = *pINb; + FacetIndex ulFInd = *pINb; aclNextLevel.push_back(ulFInd); pFBegin[*pINb].SetFlag(MeshFacet::VISIT); if (rclFVisitor.Visit(pFBegin[*pINb], raclFAry[*pCurrFacet], ulFInd, ulLevel) == false) @@ -121,11 +121,11 @@ unsigned long MeshKernel::VisitNeighbourFacetsOverCorners (MeshFacetVisitor &rcl return ulVisited; } -unsigned long MeshKernel::VisitNeighbourPoints (MeshPointVisitor &rclPVisitor, unsigned long ulStartPoint) const +unsigned long MeshKernel::VisitNeighbourPoints (MeshPointVisitor &rclPVisitor, PointIndex ulStartPoint) const { unsigned long ulVisited = 0, ulLevel = 0; - std::vector aclCurrentLevel, aclNextLevel; - std::vector::iterator clCurrIter; + std::vector aclCurrentLevel, aclNextLevel; + std::vector::iterator clCurrIter; MeshPointArray::_TConstIterator pPBegin = _aclPointArray.begin(); MeshRefPointToPoints clNPs(*this); @@ -135,12 +135,12 @@ unsigned long MeshKernel::VisitNeighbourPoints (MeshPointVisitor &rclPVisitor, u while (aclCurrentLevel.size() > 0) { // visit all neighbours of the current level for (clCurrIter = aclCurrentLevel.begin(); clCurrIter < aclCurrentLevel.end(); ++clCurrIter) { - const std::set& raclNB = clNPs[*clCurrIter]; - for (std::set::const_iterator pINb = raclNB.begin(); pINb != raclNB.end(); ++pINb) { + const std::set& raclNB = clNPs[*clCurrIter]; + for (std::set::const_iterator pINb = raclNB.begin(); pINb != raclNB.end(); ++pINb) { if (pPBegin[*pINb].IsFlag(MeshPoint::VISIT) == false) { // only visit if VISIT Flag not set ulVisited++; - unsigned long ulPInd = *pINb; + PointIndex ulPInd = *pINb; aclNextLevel.push_back(ulPInd); pPBegin[*pINb].SetFlag(MeshPoint::VISIT); if (rclPVisitor.Visit(pPBegin[*pINb], *(pPBegin + (*clCurrIter)), ulPInd, ulLevel) == false) @@ -160,7 +160,7 @@ unsigned long MeshKernel::VisitNeighbourPoints (MeshPointVisitor &rclPVisitor, u MeshSearchNeighbourFacetsVisitor::MeshSearchNeighbourFacetsVisitor (const MeshKernel &rclMesh, float fRadius, - unsigned long ulStartFacetIdx) + FacetIndex ulStartFacetIdx) : _rclMeshBase(rclMesh), _clCenter(rclMesh.GetFacet(ulStartFacetIdx).GetGravityPoint()), _fRadius(fRadius), @@ -169,7 +169,7 @@ MeshSearchNeighbourFacetsVisitor::MeshSearchNeighbourFacetsVisitor (const MeshKe { } -std::vector MeshSearchNeighbourFacetsVisitor::GetAndReset (void) +std::vector MeshSearchNeighbourFacetsVisitor::GetAndReset () { MeshAlgorithm(_rclMeshBase).ResetFacetsFlag(_vecFacets, MeshFacet::VISIT); return _vecFacets; @@ -177,8 +177,8 @@ std::vector MeshSearchNeighbourFacetsVisitor::GetAndReset (void) // ------------------------------------------------------------------------- -MeshPlaneVisitor::MeshPlaneVisitor (const MeshKernel& mesh, unsigned long index, - float deviation, std::vector &indices) +MeshPlaneVisitor::MeshPlaneVisitor (const MeshKernel& mesh, FacetIndex index, + float deviation, std::vector &indices) : mesh(mesh), indices(indices), max_deviation(deviation), fitter(new PlaneFit) { MeshGeomFacet triangle = mesh.GetFacet(index); @@ -195,7 +195,7 @@ MeshPlaneVisitor::~MeshPlaneVisitor () } bool MeshPlaneVisitor::AllowVisit (const MeshFacet& face, const MeshFacet&, - unsigned long, unsigned long, unsigned short) + FacetIndex, unsigned long, unsigned short) { if (!fitter->Done()) fitter->Fit(); @@ -208,7 +208,7 @@ bool MeshPlaneVisitor::AllowVisit (const MeshFacet& face, const MeshFacet&, } bool MeshPlaneVisitor::Visit (const MeshFacet & face, const MeshFacet &, - unsigned long ulFInd, unsigned long) + FacetIndex ulFInd, unsigned long) { MeshGeomFacet triangle = mesh.GetFacet(face); indices.push_back(ulFInd); diff --git a/src/Mod/Mesh/App/Core/Visitor.h b/src/Mod/Mesh/App/Core/Visitor.h index bac568451e..6c31c298e5 100644 --- a/src/Mod/Mesh/App/Core/Visitor.h +++ b/src/Mod/Mesh/App/Core/Visitor.h @@ -24,9 +24,7 @@ #ifndef VISITOR_H #define VISITOR_H -#ifndef MESH_GLOBAL_H -#include -#endif +#include "Definitions.h" namespace MeshCore { @@ -53,14 +51,14 @@ public: * If \a true is returned the next iteration is done if there are still facets to visit. * If \a false is returned the calling method stops immediately visiting further facets. */ - virtual bool Visit (const MeshFacet &rclFacet, const MeshFacet &rclFrom, unsigned long ulFInd, + virtual bool Visit (const MeshFacet &rclFacet, const MeshFacet &rclFrom, FacetIndex ulFInd, unsigned long ulLevel) = 0; /** Test before a facet will be flagged as VISIT, return false means: go on with * visiting the facets but not this one and set not the VISIT flag */ virtual bool AllowVisit (const MeshFacet& rclFacet, const MeshFacet& rclFrom, - unsigned long ulFInd, unsigned long ulLevel, + FacetIndex ulFInd, unsigned long ulLevel, unsigned short neighbourIndex) { (void)rclFacet; @@ -78,12 +76,12 @@ public: class MeshExport MeshSearchNeighbourFacetsVisitor : public MeshFacetVisitor { public: - MeshSearchNeighbourFacetsVisitor (const MeshKernel &rclMesh, float fRadius, unsigned long ulStartFacetIdx); + MeshSearchNeighbourFacetsVisitor (const MeshKernel &rclMesh, float fRadius, FacetIndex ulStartFacetIdx); virtual ~MeshSearchNeighbourFacetsVisitor () {} /** Checks the facet if it lies inside the search radius. */ - inline bool Visit (const MeshFacet &rclFacet, const MeshFacet &rclFrom, unsigned long ulFInd, unsigned long ulLevel); + inline bool Visit (const MeshFacet &rclFacet, const MeshFacet &rclFrom, FacetIndex ulFInd, unsigned long ulLevel); /** Resets the VISIT flag of already visited facets. */ - inline std::vector GetAndReset (void); + inline std::vector GetAndReset (); protected: const MeshKernel& _rclMeshBase; /**< The mesh kernel. */ @@ -91,11 +89,11 @@ protected: float _fRadius; /**< Search radius. */ unsigned long _ulCurrentLevel; bool _bFacetsFoundInCurrentLevel; - std::vector _vecFacets; /**< Found facets. */ + std::vector _vecFacets; /**< Found facets. */ }; inline bool MeshSearchNeighbourFacetsVisitor::Visit (const MeshFacet &rclFacet, const MeshFacet &rclFrom, - unsigned long ulFInd, unsigned long ulLevel) + FacetIndex ulFInd, unsigned long ulLevel) { (void)rclFrom; if (ulLevel > _ulCurrentLevel) { @@ -122,11 +120,11 @@ inline bool MeshSearchNeighbourFacetsVisitor::Visit (const MeshFacet &rclFacet, class MeshExport MeshTopFacetVisitor : public MeshFacetVisitor { public: - MeshTopFacetVisitor (std::vector &raulNB) : _raulNeighbours(raulNB) {} + MeshTopFacetVisitor (std::vector &raulNB) : _raulNeighbours(raulNB) {} virtual ~MeshTopFacetVisitor () {} /** Collects the facet indices. */ virtual bool Visit (const MeshFacet &rclFacet, const MeshFacet &rclFrom, - unsigned long ulFInd, unsigned long) + FacetIndex ulFInd, unsigned long) { (void)rclFacet; (void)rclFrom; @@ -135,7 +133,7 @@ public: } protected: - std::vector &_raulNeighbours; /**< Indices of all visited facets. */ + std::vector &_raulNeighbours; /**< Indices of all visited facets. */ }; // ------------------------------------------------------------------------- @@ -148,18 +146,18 @@ class MeshPlaneVisitor : public MeshFacetVisitor { public: MeshPlaneVisitor (const MeshKernel& mesh, - unsigned long index, + FacetIndex index, float deviation, - std::vector &indices); + std::vector &indices); virtual ~MeshPlaneVisitor (); bool AllowVisit (const MeshFacet& face, const MeshFacet&, - unsigned long, unsigned long, unsigned short neighbourIndex); + FacetIndex, unsigned long, unsigned short neighbourIndex); bool Visit (const MeshFacet & face, const MeshFacet &, - unsigned long ulFInd, unsigned long); + FacetIndex ulFInd, unsigned long); protected: const MeshKernel& mesh; - std::vector &indices; + std::vector &indices; Base::Vector3f basepoint; Base::Vector3f normal; float max_deviation; @@ -185,7 +183,7 @@ public: * \a false is returned the calling method stops immediately visiting further points. */ virtual bool Visit (const MeshPoint &rclPoint, const MeshPoint &rclFrom, - unsigned long ulPInd, unsigned long ulLevel) = 0; + FacetIndex ulPInd, unsigned long ulLevel) = 0; }; } // namespace MeshCore diff --git a/src/Mod/Mesh/App/Exporter.cpp b/src/Mod/Mesh/App/Exporter.cpp index bd21ff0106..5be6ba4ae5 100644 --- a/src/Mod/Mesh/App/Exporter.cpp +++ b/src/Mod/Mesh/App/Exporter.cpp @@ -180,9 +180,9 @@ bool MergeExporter::addMesh(const char *name, const MeshObject & mesh) for (unsigned long i=0; i indices = segm.getIndices(); + std::vector indices = segm.getIndices(); std::for_each( indices.begin(), indices.end(), - [countFacets] (unsigned long &v) { + [countFacets] (FacetIndex &v) { v += countFacets; } ); Segment new_segm(&mergingMesh, indices, true); @@ -192,9 +192,9 @@ bool MergeExporter::addMesh(const char *name, const MeshObject & mesh) } } else { // now create a segment for the added mesh - std::vector indices; + std::vector indices; indices.resize(mergingMesh.countFacets() - countFacets); - std::generate(indices.begin(), indices.end(), Base::iotaGen(countFacets)); + std::generate(indices.begin(), indices.end(), Base::iotaGen(countFacets)); Segment segm(&mergingMesh, indices, true); segm.setName(name); mergingMesh.addSegment(segm); diff --git a/src/Mod/Mesh/App/Facet.cpp b/src/Mod/Mesh/App/Facet.cpp index b8e1df0d28..73ff133527 100644 --- a/src/Mod/Mesh/App/Facet.cpp +++ b/src/Mod/Mesh/App/Facet.cpp @@ -31,14 +31,14 @@ using namespace Mesh; -Facet::Facet(const MeshCore::MeshFacet& face, MeshObject* obj, unsigned long index) +Facet::Facet(const MeshCore::MeshFacet& face, MeshObject* obj, MeshCore::FacetIndex index) : Index(index), Mesh(obj) { for (int i=0; i<3; i++) { PIndex[i] = face._aulPoints[i]; NIndex[i] = face._aulNeighbours[i]; } - if (Mesh.isValid() && index != ULONG_MAX) { + if (Mesh.isValid() && index != MeshCore::FACET_INDEX_MAX) { for (int i=0; i<3; i++) { Base::Vector3d vert = Mesh->getPoint(PIndex[i]); _aclPoints[i].Set((float)vert.x, (float)vert.y, (float)vert.z); diff --git a/src/Mod/Mesh/App/Facet.h b/src/Mod/Mesh/App/Facet.h index c2f8a9e3e9..9fb8224605 100644 --- a/src/Mod/Mesh/App/Facet.h +++ b/src/Mod/Mesh/App/Facet.h @@ -43,16 +43,16 @@ class MeshObject; class MeshExport Facet : public MeshCore::MeshGeomFacet { public: - Facet(const MeshCore::MeshFacet& face = MeshCore::MeshFacet(), MeshObject* obj = 0, unsigned long index = ULONG_MAX); + Facet(const MeshCore::MeshFacet& face = MeshCore::MeshFacet(), MeshObject* obj = nullptr, MeshCore::FacetIndex index = MeshCore::FACET_INDEX_MAX); Facet(const Facet& f); ~Facet(); - bool isBound(void) const {return Index != ULONG_MAX;} + bool isBound() const {return Index != MeshCore::FACET_INDEX_MAX;} void operator = (const Facet& f); - unsigned long Index; - unsigned long PIndex[3]; - unsigned long NIndex[3]; + MeshCore::FacetIndex Index; + MeshCore::PointIndex PIndex[3]; + MeshCore::FacetIndex NIndex[3]; Base::Reference Mesh; }; diff --git a/src/Mod/Mesh/App/FacetPyImp.cpp b/src/Mod/Mesh/App/FacetPyImp.cpp index dba93fb20e..4610b17e95 100644 --- a/src/Mod/Mesh/App/FacetPyImp.cpp +++ b/src/Mod/Mesh/App/FacetPyImp.cpp @@ -34,7 +34,7 @@ using namespace Mesh; // returns a string which represent the object e.g. when printed in python -std::string FacetPy::representation(void) const +std::string FacetPy::representation() const { FacetPy::PointerType ptr = getFacetPtr(); std::stringstream str; @@ -72,23 +72,23 @@ int FacetPy::PyInit(PyObject* args, PyObject* /*kwds*/) PyObject* FacetPy::unbound(PyObject *args) { if (!PyArg_ParseTuple(args, "")) - return NULL; - getFacetPtr()->Index = ULONG_MAX; - getFacetPtr()->Mesh = 0; + return nullptr; + getFacetPtr()->Index = MeshCore::FACET_INDEX_MAX; + getFacetPtr()->Mesh = nullptr; Py_Return; } -Py::Long FacetPy::getIndex(void) const +Py::Long FacetPy::getIndex() const { return Py::Long((long) getFacetPtr()->Index); } -Py::Boolean FacetPy::getBound(void) const +Py::Boolean FacetPy::getBound() const { return Py::Boolean(getFacetPtr()->Index != UINT_MAX); } -Py::Object FacetPy::getNormal(void) const +Py::Object FacetPy::getNormal() const { Base::VectorPy* normal = new Base::VectorPy(getFacetPtr()->GetNormal()); normal->setConst(); @@ -99,7 +99,7 @@ PyObject* FacetPy::intersect(PyObject *args) { PyObject* object; if (!PyArg_ParseTuple(args, "O!", &FacetPy::Type, &object)) - return NULL; + return nullptr; FacetPy *face = static_cast(object); FacetPy::PointerType face_ptr = face->getFacetPtr(); FacetPy::PointerType this_ptr = this->getFacetPtr(); @@ -127,7 +127,7 @@ PyObject* FacetPy::intersect(PyObject *args) return Py::new_reference_to(sct); } catch (const Py::Exception&) { - return 0; + return nullptr; } } @@ -135,7 +135,7 @@ PyObject* FacetPy::isDegenerated(PyObject *args) { float fEpsilon = MeshCore::MeshDefinitions::_fMinPointDistanceP2; if (!PyArg_ParseTuple(args, "|f", &fEpsilon)) - return NULL; + return nullptr; FacetPy::PointerType face = this->getFacetPtr(); if (!face->isBound()) { @@ -152,7 +152,7 @@ PyObject* FacetPy::isDeformed(PyObject *args) float fMinAngle; float fMaxAngle; if (!PyArg_ParseTuple(args, "ff", &fMinAngle, &fMaxAngle)) - return NULL; + return nullptr; FacetPy::PointerType face = this->getFacetPtr(); if (!face->isBound()) { @@ -166,7 +166,7 @@ PyObject* FacetPy::isDeformed(PyObject *args) return Py::new_reference_to(Py::Boolean(tria.IsDeformed(fCosOfMinAngle, fCosOfMaxAngle))); } -Py::List FacetPy::getPoints(void) const +Py::List FacetPy::getPoints() const { FacetPy::PointerType face = this->getFacetPtr(); @@ -182,7 +182,7 @@ Py::List FacetPy::getPoints(void) const return pts; } -Py::Tuple FacetPy::getPointIndices(void) const +Py::Tuple FacetPy::getPointIndices() const { FacetPy::PointerType face = this->getFacetPtr(); if (!face->isBound()) @@ -195,7 +195,7 @@ Py::Tuple FacetPy::getPointIndices(void) const return idxTuple; } -Py::Tuple FacetPy::getNeighbourIndices(void) const +Py::Tuple FacetPy::getNeighbourIndices() const { FacetPy::PointerType face = this->getFacetPtr(); if (!face->isBound()) { @@ -209,7 +209,7 @@ Py::Tuple FacetPy::getNeighbourIndices(void) const return idxTuple; } -Py::Float FacetPy::getArea(void) const +Py::Float FacetPy::getArea() const { FacetPy::PointerType face = this->getFacetPtr(); if (!face->isBound()) { @@ -221,7 +221,7 @@ Py::Float FacetPy::getArea(void) const return Py::Float(tria.Area()); } -Py::Float FacetPy::getAspectRatio(void) const +Py::Float FacetPy::getAspectRatio() const { FacetPy::PointerType face = this->getFacetPtr(); if (!face->isBound()) { @@ -233,7 +233,7 @@ Py::Float FacetPy::getAspectRatio(void) const return Py::Float(tria.AspectRatio()); } -Py::Float FacetPy::getAspectRatio2(void) const +Py::Float FacetPy::getAspectRatio2() const { FacetPy::PointerType face = this->getFacetPtr(); if (!face->isBound()) { @@ -245,7 +245,7 @@ Py::Float FacetPy::getAspectRatio2(void) const return Py::Float(tria.AspectRatio2()); } -Py::Float FacetPy::getRoundness(void) const +Py::Float FacetPy::getRoundness() const { FacetPy::PointerType face = this->getFacetPtr(); if (!face->isBound()) { @@ -257,7 +257,7 @@ Py::Float FacetPy::getRoundness(void) const return Py::Float(tria.Roundness()); } -Py::Tuple FacetPy::getCircumCircle(void) const +Py::Tuple FacetPy::getCircumCircle() const { FacetPy::PointerType face = this->getFacetPtr(); if (!face->isBound()) { @@ -274,7 +274,7 @@ Py::Tuple FacetPy::getCircumCircle(void) const return tuple; } -Py::Tuple FacetPy::getInCircle(void) const +Py::Tuple FacetPy::getInCircle() const { FacetPy::PointerType face = this->getFacetPtr(); if (!face->isBound()) { @@ -293,7 +293,7 @@ Py::Tuple FacetPy::getInCircle(void) const PyObject *FacetPy::getCustomAttributes(const char* /*attr*/) const { - return 0; + return nullptr; } int FacetPy::setCustomAttributes(const char* /*attr*/, PyObject * /*obj*/) diff --git a/src/Mod/Mesh/App/FeatureMeshSegmentByMesh.cpp b/src/Mod/Mesh/App/FeatureMeshSegmentByMesh.cpp index 0988b699b3..4c6b51345b 100644 --- a/src/Mod/Mesh/App/FeatureMeshSegmentByMesh.cpp +++ b/src/Mod/Mesh/App/FeatureMeshSegmentByMesh.cpp @@ -44,10 +44,10 @@ using namespace MeshCore; PROPERTY_SOURCE(Mesh::SegmentByMesh, Mesh::Feature) -SegmentByMesh::SegmentByMesh(void) +SegmentByMesh::SegmentByMesh() { - ADD_PROPERTY(Source ,(0)); - ADD_PROPERTY(Tool ,(0)); + ADD_PROPERTY(Source ,(nullptr)); + ADD_PROPERTY(Tool ,(nullptr)); ADD_PROPERTY(Base ,(0.0,0.0,0.0)); ADD_PROPERTY(Normal ,(0.0,0.0,1.0)); } @@ -63,9 +63,9 @@ short SegmentByMesh::mustExecute() const return 0; } -App::DocumentObjectExecReturn *SegmentByMesh::execute(void) +App::DocumentObjectExecReturn *SegmentByMesh::execute() { - Mesh::PropertyMeshKernel *kernel=0; + Mesh::PropertyMeshKernel *kernel=nullptr; App::DocumentObject* mesh = Source.getValue(); if (mesh) { App::Property* prop = mesh->getPropertyByName("Mesh"); @@ -77,7 +77,7 @@ App::DocumentObjectExecReturn *SegmentByMesh::execute(void) else if (mesh->isError()) return new App::DocumentObjectExecReturn("No valid mesh.\n"); - Mesh::PropertyMeshKernel *toolmesh=0; + Mesh::PropertyMeshKernel *toolmesh=nullptr; App::DocumentObject* tool = Tool.getValue(); if (tool) { App::Property* prop = tool->getPropertyByName("Mesh"); @@ -106,7 +106,7 @@ App::DocumentObjectExecReturn *SegmentByMesh::execute(void) return new App::DocumentObjectExecReturn("Toolmesh is not solid.\n"); } - std::vector faces; + std::vector faces; std::vector aFaces; MeshAlgorithm cAlg(rMeshKernel); @@ -121,11 +121,11 @@ App::DocumentObjectExecReturn *SegmentByMesh::execute(void) // so we need the nearest facet to the front clipping plane // float fDist = FLOAT_MAX; - unsigned long uIdx=ULONG_MAX; + MeshCore::FacetIndex uIdx = MeshCore::FACET_INDEX_MAX; MeshFacetIterator cFIt(rMeshKernel); // get the nearest facet to the user (front clipping plane) - for ( std::vector::iterator it = faces.begin(); it != faces.end(); ++it ) { + for ( std::vector::iterator it = faces.begin(); it != faces.end(); ++it ) { cFIt.Set(*it); float dist = (float)fabs(cFIt->GetGravityPoint().DistanceToPlane( cBase, cNormal )); if ( dist < fDist ) { @@ -135,7 +135,7 @@ App::DocumentObjectExecReturn *SegmentByMesh::execute(void) } // succeeded - if ( uIdx != ULONG_MAX ) { + if ( uIdx != MeshCore::FACET_INDEX_MAX ) { // set VISIT-Flag to all outer facets cAlg.SetFacetFlag( MeshFacet::VISIT ); cAlg.ResetFacetsFlag(faces, MeshFacet::VISIT); @@ -149,7 +149,7 @@ App::DocumentObjectExecReturn *SegmentByMesh::execute(void) } } - for ( std::vector::iterator it = faces.begin(); it != faces.end(); ++it ) + for ( std::vector::iterator it = faces.begin(); it != faces.end(); ++it ) aFaces.push_back( rMeshKernel.GetFacet(*it) ); std::unique_ptr pcKernel(new MeshObject); diff --git a/src/Mod/Mesh/App/FeatureMeshSegmentByMesh.h b/src/Mod/Mesh/App/FeatureMeshSegmentByMesh.h index 5cc9c7ead3..29295b9f8e 100644 --- a/src/Mod/Mesh/App/FeatureMeshSegmentByMesh.h +++ b/src/Mod/Mesh/App/FeatureMeshSegmentByMesh.h @@ -56,7 +56,7 @@ public: /** @name methods override Feature */ //@{ /// recalculate the Feature - App::DocumentObjectExecReturn *execute(void); + App::DocumentObjectExecReturn *execute(); short mustExecute() const; //@} }; diff --git a/src/Mod/Mesh/App/Mesh.cpp b/src/Mod/Mesh/App/Mesh.cpp index 2f727d90c6..5c45b0e641 100644 --- a/src/Mod/Mesh/App/Mesh.cpp +++ b/src/Mod/Mesh/App/Mesh.cpp @@ -90,7 +90,7 @@ MeshObject::~MeshObject() { } -std::vector MeshObject::getElementTypes(void) const +std::vector MeshObject::getElementTypes() const { std::vector temp; temp.push_back("Face"); // that's the mesh itself @@ -114,10 +114,10 @@ Data::Segment* MeshObject::getSubElement(const char* Type, unsigned long /*n*/) //TODO std::string element(Type); if (element == "Face") - return 0; + return nullptr; else if (element == "Segment") - return 0; - return 0; + return nullptr; + return nullptr; } void MeshObject::getFacesFromSubelement(const Data::Segment* /*segm*/, @@ -142,12 +142,12 @@ void MeshObject::setTransform(const Base::Matrix4D& rclTrf) _Mtrx = rclTrf; } -Base::Matrix4D MeshObject::getTransform(void) const +Base::Matrix4D MeshObject::getTransform() const { return _Mtrx; } -Base::BoundBox3d MeshObject::getBoundBox(void)const +Base::BoundBox3d MeshObject::getBoundBox()const { const_cast(_kernel).RecalcBoundBox(); Base::BoundBox3f Bnd = _kernel.GetBoundBox(); @@ -266,7 +266,7 @@ double MeshObject::getVolume() const return _kernel.GetVolume(); } -MeshPoint MeshObject::getPoint(unsigned long index) const +MeshPoint MeshObject::getPoint(PointIndex index) const { Base::Vector3f vertf = _kernel.GetPoint(index); Base::Vector3d vertd(vertf.x, vertf.y, vertf.z); @@ -304,7 +304,7 @@ void MeshObject::getPoints(std::vector &Points, } } -Mesh::Facet MeshObject::getFacet(unsigned long index) const +Mesh::Facet MeshObject::getFacet(FacetIndex index) const { Mesh::Facet face(_kernel.GetFacets()[index], const_cast(this), index); return face; @@ -331,7 +331,7 @@ void MeshObject::getFaces(std::vector &Points,std::vector } } -unsigned int MeshObject::getMemSize (void) const +unsigned int MeshObject::getMemSize () const { return _kernel.GetMemSize(); } @@ -470,7 +470,7 @@ void MeshObject::swapKernel(MeshCore::MeshKernel& kernel, this->_segments.clear(); const MeshCore::MeshFacetArray& faces = _kernel.GetFacets(); MeshCore::MeshFacetArray::_TConstIterator it; - std::vector segment; + std::vector segment; segment.reserve(faces.size()); unsigned long prop = 0; unsigned long index = 0; @@ -637,7 +637,7 @@ void MeshObject::addMesh(const MeshCore::MeshKernel& kernel) _kernel.Merge(kernel); } -void MeshObject::deleteFacets(const std::vector& removeIndices) +void MeshObject::deleteFacets(const std::vector& removeIndices) { if (removeIndices.empty()) return; @@ -645,7 +645,7 @@ void MeshObject::deleteFacets(const std::vector& removeIndices) deletedFacets(removeIndices); } -void MeshObject::deletePoints(const std::vector& removeIndices) +void MeshObject::deletePoints(const std::vector& removeIndices) { if (removeIndices.empty()) return; @@ -653,21 +653,21 @@ void MeshObject::deletePoints(const std::vector& removeIndices) this->_segments.clear(); } -void MeshObject::deletedFacets(const std::vector& remFacets) +void MeshObject::deletedFacets(const std::vector& remFacets) { if (remFacets.empty()) return; // nothing has changed if (this->_segments.empty()) return; // nothing to do - // set an array with the original indices and mark the removed as ULONG_MAX - std::vector f_indices(_kernel.CountFacets()+remFacets.size()); - for (std::vector::const_iterator it = remFacets.begin(); + // set an array with the original indices and mark the removed as MeshCore::FACET_INDEX_MAX + std::vector f_indices(_kernel.CountFacets()+remFacets.size()); + for (std::vector::const_iterator it = remFacets.begin(); it != remFacets.end(); ++it) { - f_indices[*it] = ULONG_MAX; + f_indices[*it] = MeshCore::FACET_INDEX_MAX; } - unsigned long index = 0; - for (std::vector::iterator it = f_indices.begin(); + FacetIndex index = 0; + for (std::vector::iterator it = f_indices.begin(); it != f_indices.end(); ++it) { if (*it == 0) *it = index++; @@ -676,17 +676,17 @@ void MeshObject::deletedFacets(const std::vector& remFacets) // the array serves now as LUT to set the new indices in the segments for (std::vector::iterator it = this->_segments.begin(); it != this->_segments.end(); ++it) { - std::vector segm = it->_indices; - for (std::vector::iterator jt = segm.begin(); + std::vector segm = it->_indices; + for (std::vector::iterator jt = segm.begin(); jt != segm.end(); ++jt) { *jt = f_indices[*jt]; } // remove the invalid indices std::sort(segm.begin(), segm.end()); - std::vector::iterator ft = std::find_if - (segm.begin(), segm.end(), [](unsigned long v) { - return v == ULONG_MAX; + std::vector::iterator ft = std::find_if + (segm.begin(), segm.end(), [](FacetIndex v) { + return v == MeshCore::FACET_INDEX_MAX; }); if (ft != segm.end()) segm.erase(ft, segm.end()); @@ -696,14 +696,14 @@ void MeshObject::deletedFacets(const std::vector& remFacets) void MeshObject::deleteSelectedFacets() { - std::vector facets; + std::vector facets; MeshCore::MeshAlgorithm(this->_kernel).GetFacetsFlag(facets, MeshCore::MeshFacet::SELECTED); deleteFacets(facets); } void MeshObject::deleteSelectedPoints() { - std::vector points; + std::vector points; MeshCore::MeshAlgorithm(this->_kernel).GetPointsFlag(points, MeshCore::MeshPoint::SELECTED); deletePoints(points); } @@ -718,32 +718,32 @@ void MeshObject::clearPointSelection() const MeshCore::MeshAlgorithm(this->_kernel).ResetPointFlag(MeshCore::MeshPoint::SELECTED); } -void MeshObject::addFacetsToSelection(const std::vector& inds) const +void MeshObject::addFacetsToSelection(const std::vector& inds) const { MeshCore::MeshAlgorithm(this->_kernel).SetFacetsFlag(inds, MeshCore::MeshFacet::SELECTED); } -void MeshObject::addPointsToSelection(const std::vector& inds) const +void MeshObject::addPointsToSelection(const std::vector& inds) const { MeshCore::MeshAlgorithm(this->_kernel).SetPointsFlag(inds, MeshCore::MeshPoint::SELECTED); } -void MeshObject::removeFacetsFromSelection(const std::vector& inds) const +void MeshObject::removeFacetsFromSelection(const std::vector& inds) const { MeshCore::MeshAlgorithm(this->_kernel).ResetFacetsFlag(inds, MeshCore::MeshFacet::SELECTED); } -void MeshObject::removePointsFromSelection(const std::vector& inds) const +void MeshObject::removePointsFromSelection(const std::vector& inds) const { MeshCore::MeshAlgorithm(this->_kernel).ResetPointsFlag(inds, MeshCore::MeshPoint::SELECTED); } -void MeshObject::getFacetsFromSelection(std::vector& inds) const +void MeshObject::getFacetsFromSelection(std::vector& inds) const { MeshCore::MeshAlgorithm(this->_kernel).GetFacetsFlag(inds, MeshCore::MeshFacet::SELECTED); } -void MeshObject::getPointsFromSelection(std::vector& inds) const +void MeshObject::getPointsFromSelection(std::vector& inds) const { MeshCore::MeshAlgorithm(this->_kernel).GetPointsFlag(inds, MeshCore::MeshPoint::SELECTED); } @@ -768,14 +768,14 @@ bool MeshObject::hasSelectedPoints() const return (countSelectedPoints() > 0); } -std::vector MeshObject::getPointsFromFacets(const std::vector& facets) const +std::vector MeshObject::getPointsFromFacets(const std::vector& facets) const { return _kernel.GetFacetPoints(facets); } -void MeshObject::updateMesh(const std::vector& facets) +void MeshObject::updateMesh(const std::vector& facets) { - std::vector points; + std::vector points; points = _kernel.GetFacetPoints(facets); MeshCore::MeshAlgorithm alg(_kernel); @@ -790,16 +790,16 @@ void MeshObject::updateMesh() alg.ResetPointFlag(MeshCore::MeshPoint::SEGMENT); for (std::vector::iterator it = this->_segments.begin(); it != this->_segments.end(); ++it) { - std::vector points; + std::vector points; points = _kernel.GetFacetPoints(it->getIndices()); alg.SetFacetsFlag(it->getIndices(), MeshCore::MeshFacet::SEGMENT); alg.SetPointsFlag(points, MeshCore::MeshPoint::SEGMENT); } } -std::vector > MeshObject::getComponents() const +std::vector > MeshObject::getComponents() const { - std::vector > segments; + std::vector > segments; MeshCore::MeshComponents comp(_kernel); comp.SearchForComponents(MeshCore::MeshComponents::OverEdge,segments); return segments; @@ -807,7 +807,7 @@ std::vector > MeshObject::getComponents() const unsigned long MeshObject::countComponents() const { - std::vector > segments; + std::vector > segments; MeshCore::MeshComponents comp(_kernel); comp.SearchForComponents(MeshCore::MeshComponents::OverEdge,segments); return segments.size(); @@ -815,17 +815,17 @@ unsigned long MeshObject::countComponents() const void MeshObject::removeComponents(unsigned long count) { - std::vector removeIndices; + std::vector removeIndices; MeshCore::MeshTopoAlgorithm(_kernel).FindComponents(count, removeIndices); _kernel.DeleteFacets(removeIndices); deletedFacets(removeIndices); } -unsigned long MeshObject::getPointDegree(const std::vector& indices, - std::vector& point_degree) const +unsigned long MeshObject::getPointDegree(const std::vector& indices, + std::vector& point_degree) const { const MeshCore::MeshFacetArray& faces = _kernel.GetFacets(); - std::vector pointDeg(_kernel.CountPoints()); + std::vector pointDeg(_kernel.CountPoints()); for (MeshCore::MeshFacetArray::_TConstIterator it = faces.begin(); it != faces.end(); ++it) { pointDeg[it->_aulPoints[0]]++; @@ -833,14 +833,14 @@ unsigned long MeshObject::getPointDegree(const std::vector& indic pointDeg[it->_aulPoints[2]]++; } - for (std::vector::const_iterator it = indices.begin(); it != indices.end(); ++it) { + for (std::vector::const_iterator it = indices.begin(); it != indices.end(); ++it) { const MeshCore::MeshFacet& face = faces[*it]; pointDeg[face._aulPoints[0]]--; pointDeg[face._aulPoints[1]]--; pointDeg[face._aulPoints[2]]--; } - unsigned long countInvalids = std::count_if(pointDeg.begin(), pointDeg.end(), [](unsigned long v) { + unsigned long countInvalids = std::count_if(pointDeg.begin(), pointDeg.end(), [](PointIndex v) { return v == 0; }); @@ -851,7 +851,7 @@ unsigned long MeshObject::getPointDegree(const std::vector& indic void MeshObject::fillupHoles(unsigned long length, int level, MeshCore::AbstractPolygonTriangulator& cTria) { - std::list > aFailed; + std::list > aFailed; MeshCore::MeshTopoAlgorithm topalg(_kernel); topalg.FillupHoles(length, level, cTria, aFailed); } @@ -873,7 +873,7 @@ void MeshObject::offsetSpecial2(float fSize) Base::Builder3D builder; std::vector PointNormals= _kernel.CalcVertexNormals(); std::vector FaceNormals; - std::set fliped; + std::set fliped; MeshCore::MeshFacetIterator it(_kernel); for (it.Init(); it.More(); it.Next()) @@ -908,7 +908,7 @@ void MeshObject::offsetSpecial2(float fSize) if (fliped.size() == 0) break; - for( std::set::iterator It= fliped.begin();It!=fliped.end();++It) + for( std::set::iterator It= fliped.begin();It!=fliped.end();++It) alg.CollapseFacet(*It); fliped.clear(); } @@ -917,7 +917,7 @@ void MeshObject::offsetSpecial2(float fSize) // search for intersected facets MeshCore::MeshEvalSelfIntersection eval(_kernel); - std::vector > faces; + std::vector > faces; eval.GetIntersections(faces); builder.saveToLog(); } @@ -941,7 +941,7 @@ void MeshObject::offsetSpecial(float fSize, float zmax, float zmin) } } -void MeshObject::clear(void) +void MeshObject::clear() { _kernel.Clear(); this->_segments.clear(); @@ -964,7 +964,7 @@ Base::Matrix4D MeshObject::getEigenSystem(Base::Vector3d& v) const return cMeshEval.Transform(); } -void MeshObject::movePoint(unsigned long index, const Base::Vector3d& v) +void MeshObject::movePoint(PointIndex index, const Base::Vector3d& v) { // v is a vector, hence we must not apply the translation part // of the transformation to the vector @@ -975,7 +975,7 @@ void MeshObject::movePoint(unsigned long index, const Base::Vector3d& v) _kernel.MovePoint(index,transformToInside(vec)); } -void MeshObject::setPoint(unsigned long index, const Base::Vector3d& p) +void MeshObject::setPoint(PointIndex index, const Base::Vector3d& p) { _kernel.SetPoint(index,transformToInside(p)); } @@ -997,7 +997,7 @@ void MeshObject::decimate(int targetSize) dm.simplify(targetSize); } -Base::Vector3d MeshObject::getPointNormal(unsigned long index) const +Base::Vector3d MeshObject::getPointNormal(PointIndex index) const { std::vector temp = _kernel.CalcVertexNormals(); Base::Vector3d normal = transformToOutside(temp[index]); @@ -1050,7 +1050,7 @@ void MeshObject::cut(const Base::Polygon2d& polygon2d, const Base::ViewProjMethod& proj, MeshObject::CutType type) { MeshCore::MeshAlgorithm meshAlg(this->_kernel); - std::vector check; + std::vector check; bool inner; switch (type) { @@ -1075,7 +1075,7 @@ void MeshObject::trim(const Base::Polygon2d& polygon2d, const Base::ViewProjMethod& proj, MeshObject::CutType type) { MeshCore::MeshTrimming trim(this->_kernel, &proj, polygon2d); - std::vector check; + std::vector check; std::vector triangle; switch (type) { @@ -1099,7 +1099,7 @@ void MeshObject::trim(const Base::Polygon2d& polygon2d, void MeshObject::trim(const Base::Vector3f& base, const Base::Vector3f& normal) { MeshCore::MeshTrimByPlane trim(this->_kernel); - std::vector trimFacets, removeFacets; + std::vector trimFacets, removeFacets; std::vector triangle; MeshCore::MeshFacetGrid meshGrid(this->_kernel); @@ -1230,13 +1230,13 @@ void MeshObject::optimizeEdges() void MeshObject::splitEdges() { - std::vector > adjacentFacet; + std::vector > adjacentFacet; MeshCore::MeshAlgorithm alg(_kernel); alg.ResetFacetFlag(MeshCore::MeshFacet::VISIT); const MeshCore::MeshFacetArray& rFacets = _kernel.GetFacets(); for (MeshCore::MeshFacetArray::_TConstIterator pF = rFacets.begin(); pF != rFacets.end(); ++pF) { int id=2; - if (pF->_aulNeighbours[id] != ULONG_MAX) { + if (pF->_aulNeighbours[id] != MeshCore::FACET_INDEX_MAX) { const MeshCore::MeshFacet& rFace = rFacets[pF->_aulNeighbours[id]]; if (!pF->IsFlag(MeshCore::MeshFacet::VISIT) && !rFace.IsFlag(MeshCore::MeshFacet::VISIT)) { pF->SetFlag(MeshCore::MeshFacet::VISIT); @@ -1248,7 +1248,7 @@ void MeshObject::splitEdges() MeshCore::MeshFacetIterator cIter(_kernel); MeshCore::MeshTopoAlgorithm topalg(_kernel); - for (std::vector >::iterator it = adjacentFacet.begin(); it != adjacentFacet.end(); ++it) { + for (std::vector >::iterator it = adjacentFacet.begin(); it != adjacentFacet.end(); ++it) { cIter.Set(it->first); Base::Vector3f mid = 0.5f*(cIter->_aclPoints[0]+cIter->_aclPoints[2]); topalg.SplitEdge(it->first, it->second, mid); @@ -1259,62 +1259,62 @@ void MeshObject::splitEdges() this->_segments.clear(); } -void MeshObject::splitEdge(unsigned long facet, unsigned long neighbour, const Base::Vector3f& v) +void MeshObject::splitEdge(FacetIndex facet, FacetIndex neighbour, const Base::Vector3f& v) { MeshCore::MeshTopoAlgorithm topalg(_kernel); topalg.SplitEdge(facet, neighbour, v); } -void MeshObject::splitFacet(unsigned long facet, const Base::Vector3f& v1, const Base::Vector3f& v2) +void MeshObject::splitFacet(FacetIndex facet, const Base::Vector3f& v1, const Base::Vector3f& v2) { MeshCore::MeshTopoAlgorithm topalg(_kernel); topalg.SplitFacet(facet, v1, v2); } -void MeshObject::swapEdge(unsigned long facet, unsigned long neighbour) +void MeshObject::swapEdge(FacetIndex facet, FacetIndex neighbour) { MeshCore::MeshTopoAlgorithm topalg(_kernel); topalg.SwapEdge(facet, neighbour); } -void MeshObject::collapseEdge(unsigned long facet, unsigned long neighbour) +void MeshObject::collapseEdge(FacetIndex facet, FacetIndex neighbour) { MeshCore::MeshTopoAlgorithm topalg(_kernel); topalg.CollapseEdge(facet, neighbour); - std::vector remFacets; + std::vector remFacets; remFacets.push_back(facet); remFacets.push_back(neighbour); deletedFacets(remFacets); } -void MeshObject::collapseFacet(unsigned long facet) +void MeshObject::collapseFacet(FacetIndex facet) { MeshCore::MeshTopoAlgorithm topalg(_kernel); topalg.CollapseFacet(facet); - std::vector remFacets; + std::vector remFacets; remFacets.push_back(facet); deletedFacets(remFacets); } -void MeshObject::collapseFacets(const std::vector& facets) +void MeshObject::collapseFacets(const std::vector& facets) { MeshCore::MeshTopoAlgorithm alg(_kernel); - for (std::vector::const_iterator it = facets.begin(); it != facets.end(); ++it) { + for (std::vector::const_iterator it = facets.begin(); it != facets.end(); ++it) { alg.CollapseFacet(*it); } deletedFacets(facets); } -void MeshObject::insertVertex(unsigned long facet, const Base::Vector3f& v) +void MeshObject::insertVertex(FacetIndex facet, const Base::Vector3f& v) { MeshCore::MeshTopoAlgorithm topalg(_kernel); topalg.InsertVertex(facet, v); } -void MeshObject::snapVertex(unsigned long facet, const Base::Vector3f& v) +void MeshObject::snapVertex(FacetIndex facet, const Base::Vector3f& v) { MeshCore::MeshTopoAlgorithm topalg(_kernel); topalg.SnapVertex(facet, v); @@ -1323,7 +1323,7 @@ void MeshObject::snapVertex(unsigned long facet, const Base::Vector3f& v) unsigned long MeshObject::countNonUniformOrientedFacets() const { MeshCore::MeshEvalOrientation cMeshEval(_kernel); - std::vector inds = cMeshEval.GetIndices(); + std::vector inds = cMeshEval.GetIndices(); return inds.size(); } @@ -1359,7 +1359,7 @@ void MeshObject::removeNonManifoldPoints() { MeshCore::MeshEvalPointManifolds p_eval(_kernel); if (!p_eval.Evaluate()) { - std::vector faces; + std::vector faces; p_eval.GetFacetIndices(faces); deleteFacets(faces); } @@ -1373,7 +1373,7 @@ bool MeshObject::hasSelfIntersections() const void MeshObject::removeSelfIntersections() { - std::vector > selfIntersections; + std::vector > selfIntersections; MeshCore::MeshEvalSelfIntersection cMeshEval(_kernel); cMeshEval.GetIntersections(selfIntersections); @@ -1383,19 +1383,19 @@ void MeshObject::removeSelfIntersections() } } -void MeshObject::removeSelfIntersections(const std::vector& indices) +void MeshObject::removeSelfIntersections(const std::vector& indices) { // make sure that the number of indices is even and are in range if (indices.size() % 2 != 0) return; unsigned long cntfacets = _kernel.CountFacets(); - if (std::find_if(indices.begin(), indices.end(), [cntfacets](unsigned long v) { return v >= cntfacets; }) < indices.end()) + if (std::find_if(indices.begin(), indices.end(), [cntfacets](FacetIndex v) { return v >= cntfacets; }) < indices.end()) return; - std::vector > selfIntersections; - std::vector::const_iterator it; + std::vector > selfIntersections; + std::vector::const_iterator it; for (it = indices.begin(); it != indices.end(); ) { - unsigned long id1 = *it; ++it; - unsigned long id2 = *it; ++it; + FacetIndex id1 = *it; ++it; + FacetIndex id2 = *it; ++it; selfIntersections.emplace_back(id1,id2); } @@ -1408,15 +1408,15 @@ void MeshObject::removeSelfIntersections(const std::vector& indic void MeshObject::removeFoldsOnSurface() { - std::vector indices; + std::vector indices; MeshCore::MeshEvalFoldsOnSurface s_eval(_kernel); MeshCore::MeshEvalFoldOversOnSurface f_eval(_kernel); f_eval.Evaluate(); - std::vector inds = f_eval.GetIndices(); + std::vector inds = f_eval.GetIndices(); s_eval.Evaluate(); - std::vector inds1 = s_eval.GetIndices(); + std::vector inds1 = s_eval.GetIndices(); // remove duplicates inds.insert(inds.end(), inds1.begin(), inds1.end()); @@ -1439,7 +1439,7 @@ void MeshObject::removeFoldsOnSurface() void MeshObject::removeFullBoundaryFacets() { - std::vector facets; + std::vector facets; if (!MeshCore::MeshEvalBorderFacet(_kernel, facets).Evaluate()) { deleteFacets(facets); } @@ -1592,7 +1592,7 @@ MeshObject* MeshObject::createSphere(float radius, int sampling) try { Py::Module module(PyImport_ImportModule("BuildRegularGeoms"),true); if (module.isNull()) - return 0; + return nullptr; Py::Dict dict = module.getDict(); Py::Callable call(dict.getItem("Sphere")); Py::Tuple args(2); @@ -1605,7 +1605,7 @@ MeshObject* MeshObject::createSphere(float radius, int sampling) e.clear(); } - return 0; + return nullptr; } MeshObject* MeshObject::createEllipsoid(float radius1, float radius2, int sampling) @@ -1615,7 +1615,7 @@ MeshObject* MeshObject::createEllipsoid(float radius1, float radius2, int sampli try { Py::Module module(PyImport_ImportModule("BuildRegularGeoms"),true); if (module.isNull()) - return 0; + return nullptr; Py::Dict dict = module.getDict(); Py::Callable call(dict.getItem("Ellipsoid")); Py::Tuple args(3); @@ -1629,7 +1629,7 @@ MeshObject* MeshObject::createEllipsoid(float radius1, float radius2, int sampli e.clear(); } - return 0; + return nullptr; } MeshObject* MeshObject::createCylinder(float radius, float length, int closed, float edgelen, int sampling) @@ -1639,7 +1639,7 @@ MeshObject* MeshObject::createCylinder(float radius, float length, int closed, f try { Py::Module module(PyImport_ImportModule("BuildRegularGeoms"),true); if (module.isNull()) - return 0; + return nullptr; Py::Dict dict = module.getDict(); Py::Callable call(dict.getItem("Cylinder")); Py::Tuple args(5); @@ -1655,7 +1655,7 @@ MeshObject* MeshObject::createCylinder(float radius, float length, int closed, f e.clear(); } - return 0; + return nullptr; } MeshObject* MeshObject::createCone(float radius1, float radius2, float len, int closed, float edgelen, int sampling) @@ -1665,7 +1665,7 @@ MeshObject* MeshObject::createCone(float radius1, float radius2, float len, int try { Py::Module module(PyImport_ImportModule("BuildRegularGeoms"),true); if (module.isNull()) - return 0; + return nullptr; Py::Dict dict = module.getDict(); Py::Callable call(dict.getItem("Cone")); Py::Tuple args(6); @@ -1682,7 +1682,7 @@ MeshObject* MeshObject::createCone(float radius1, float radius2, float len, int e.clear(); } - return 0; + return nullptr; } MeshObject* MeshObject::createTorus(float radius1, float radius2, int sampling) @@ -1692,7 +1692,7 @@ MeshObject* MeshObject::createTorus(float radius1, float radius2, int sampling) try { Py::Module module(PyImport_ImportModule("BuildRegularGeoms"),true); if (module.isNull()) - return 0; + return nullptr; Py::Dict dict = module.getDict(); Py::Callable call(dict.getItem("Toroid")); Py::Tuple args(3); @@ -1706,7 +1706,7 @@ MeshObject* MeshObject::createTorus(float radius1, float radius2, int sampling) e.clear(); } - return 0; + return nullptr; } MeshObject* MeshObject::createCube(float length, float width, float height) @@ -1716,7 +1716,7 @@ MeshObject* MeshObject::createCube(float length, float width, float height) try { Py::Module module(PyImport_ImportModule("BuildRegularGeoms"),true); if (module.isNull()) - return 0; + return nullptr; Py::Dict dict = module.getDict(); Py::Callable call(dict.getItem("Cube")); Py::Tuple args(3); @@ -1730,7 +1730,7 @@ MeshObject* MeshObject::createCube(float length, float width, float height) e.clear(); } - return 0; + return nullptr; } MeshObject* MeshObject::createCube(float length, float width, float height, float edgelen) @@ -1740,7 +1740,7 @@ MeshObject* MeshObject::createCube(float length, float width, float height, floa try { Py::Module module(PyImport_ImportModule("BuildRegularGeoms"),true); if (module.isNull()) - return 0; + return nullptr; Py::Dict dict = module.getDict(); Py::Callable call(dict.getItem("FineCube")); Py::Tuple args(4); @@ -1755,7 +1755,7 @@ MeshObject* MeshObject::createCube(float length, float width, float height, floa e.clear(); } - return 0; + return nullptr; } void MeshObject::addSegment(const Segment& s) @@ -1767,10 +1767,10 @@ void MeshObject::addSegment(const Segment& s) this->_segments.back()._modifykernel = s._modifykernel; } -void MeshObject::addSegment(const std::vector& inds) +void MeshObject::addSegment(const std::vector& inds) { unsigned long maxIndex = _kernel.CountFacets(); - for (std::vector::const_iterator it = inds.begin(); it != inds.end(); ++it) { + for (std::vector::const_iterator it = inds.begin(); it != inds.end(); ++it) { if (*it >= maxIndex) throw Base::IndexError("Index out of range"); } @@ -1788,13 +1788,13 @@ Segment& MeshObject::getSegment(unsigned long index) return this->_segments[index]; } -MeshObject* MeshObject::meshFromSegment(const std::vector& indices) const +MeshObject* MeshObject::meshFromSegment(const std::vector& indices) const { MeshCore::MeshFacetArray facets; facets.reserve(indices.size()); const MeshCore::MeshPointArray& kernel_p = _kernel.GetPoints(); const MeshCore::MeshFacetArray& kernel_f = _kernel.GetFacets(); - for (std::vector::const_iterator it = indices.begin(); it != indices.end(); ++it) { + for (std::vector::const_iterator it = indices.begin(); it != indices.end(); ++it) { facets.push_back(kernel_f[*it]); } @@ -1847,7 +1847,7 @@ std::vector MeshObject::getSegmentsOfType(MeshObject::GeometryType type // ---------------------------------------------------------------------------- -MeshObject::const_point_iterator::const_point_iterator(const MeshObject* mesh, unsigned long index) +MeshObject::const_point_iterator::const_point_iterator(const MeshObject* mesh, PointIndex index) : _mesh(mesh), _p_it(mesh->getKernel()) { this->_p_it.Set(index); @@ -1916,7 +1916,7 @@ MeshObject::const_point_iterator& MeshObject::const_point_iterator::operator--() // ---------------------------------------------------------------------------- -MeshObject::const_facet_iterator::const_facet_iterator(const MeshObject* mesh, unsigned long index) +MeshObject::const_facet_iterator::const_facet_iterator(const MeshObject* mesh, FacetIndex index) : _mesh(mesh), _f_it(mesh->getKernel()) { this->_f_it.Set(index); diff --git a/src/Mod/Mesh/App/Mesh.h b/src/Mod/Mesh/App/Mesh.h index 1086ee01a5..c8b73515d5 100644 --- a/src/Mod/Mesh/App/Mesh.h +++ b/src/Mod/Mesh/App/Mesh.h @@ -92,7 +92,7 @@ public: * List of different subelement types * its NOT a list of the subelements itself */ - virtual std::vector getElementTypes(void) const; + virtual std::vector getElementTypes() const; virtual unsigned long countSubElements(const char* Type) const; /// get the subelement by type and number virtual Data::Segment* getSubElement(const char* Type, unsigned long) const; @@ -105,7 +105,7 @@ public: //@} void setTransform(const Base::Matrix4D& rclTrf); - Base::Matrix4D getTransform(void) const; + Base::Matrix4D getTransform() const; void transformGeometry(const Base::Matrix4D &rclMat); /** @@ -123,8 +123,8 @@ public: unsigned long countEdges () const; unsigned long countSegments() const; bool isSolid() const; - MeshPoint getPoint(unsigned long) const; - Mesh::Facet getFacet(unsigned long) const; + MeshPoint getPoint(PointIndex) const; + Mesh::Facet getFacet(FacetIndex) const; double getSurface() const; double getVolume() const; /** Get points from object with given accuracy */ @@ -133,33 +133,33 @@ public: float Accuracy, uint16_t flags=0) const; virtual void getFaces(std::vector &Points,std::vector &Topo, float Accuracy, uint16_t flags=0) const; - std::vector getPointsFromFacets(const std::vector& facets) const; + std::vector getPointsFromFacets(const std::vector& facets) const; //@} void setKernel(const MeshCore::MeshKernel& m); - MeshCore::MeshKernel& getKernel(void) + MeshCore::MeshKernel& getKernel() { return _kernel; } - const MeshCore::MeshKernel& getKernel(void) const + const MeshCore::MeshKernel& getKernel() const { return _kernel; } - virtual Base::BoundBox3d getBoundBox(void)const; + virtual Base::BoundBox3d getBoundBox()const; /** @name I/O */ //@{ // Implemented from Persistence - unsigned int getMemSize (void) const; + unsigned int getMemSize () const; void Save (Base::Writer &writer) const; void SaveDocFile (Base::Writer &writer) const; void Restore(Base::XMLReader &reader); void RestoreDocFile(Base::Reader &reader); void save(const char* file,MeshCore::MeshIO::Format f=MeshCore::MeshIO::Undefined, - const MeshCore::Material* mat = 0, - const char* objectname = 0) const; + const MeshCore::Material* mat = nullptr, + const char* objectname = nullptr) const; void save(std::ostream&,MeshCore::MeshIO::Format f, - const MeshCore::Material* mat = 0, - const char* objectname = 0) const; - bool load(const char* file, MeshCore::Material* mat = 0); - bool load(std::istream&, MeshCore::MeshIO::Format f, MeshCore::Material* mat = 0); + const MeshCore::Material* mat = nullptr, + const char* objectname = nullptr) const; + bool load(const char* file, MeshCore::Material* mat = nullptr); + bool load(std::istream&, MeshCore::MeshIO::Format f, MeshCore::Material* mat = nullptr); // Save and load in internal format void save(std::ostream&) const; void load(std::istream&); @@ -192,9 +192,9 @@ public: * this mesh object. */ void addMesh(const MeshCore::MeshKernel&); - void deleteFacets(const std::vector& removeIndices); - void deletePoints(const std::vector& removeIndices); - std::vector > getComponents() const; + void deleteFacets(const std::vector& removeIndices); + void deletePoints(const std::vector& removeIndices); + std::vector > getComponents() const; unsigned long countComponents() const; void removeComponents(unsigned long); /** @@ -203,22 +203,22 @@ public: * The point degree information is stored in \a point_degree. The return value * gives the number of points which will have a degree of zero. */ - unsigned long getPointDegree(const std::vector& facets, - std::vector& point_degree) const; + unsigned long getPointDegree(const std::vector& facets, + std::vector& point_degree) const; void fillupHoles(unsigned long, int, MeshCore::AbstractPolygonTriangulator&); void offset(float fSize); void offsetSpecial2(float fSize); void offsetSpecial(float fSize, float zmax, float zmin); /// clears the Mesh - void clear(void); + void clear(); void transformToEigenSystem(); Base::Matrix4D getEigenSystem(Base::Vector3d& v) const; - void movePoint(unsigned long, const Base::Vector3d& v); - void setPoint(unsigned long, const Base::Vector3d& v); + void movePoint(PointIndex, const Base::Vector3d& v); + void setPoint(PointIndex, const Base::Vector3d& v); void smooth(int iterations, float d_max); void decimate(float fTolerance, float fReduction); void decimate(int targetSize); - Base::Vector3d getPointNormal(unsigned long) const; + Base::Vector3d getPointNormal(PointIndex) const; std::vector getPointNormals() const; void crossSections(const std::vector&, std::vector §ions, float fMinEps = 1.0e-2f, bool bConnectPolygons = false) const; @@ -231,16 +231,16 @@ public: //@{ void deleteSelectedFacets(); void deleteSelectedPoints(); - void addFacetsToSelection(const std::vector&) const; - void addPointsToSelection(const std::vector&) const; - void removeFacetsFromSelection(const std::vector&) const; - void removePointsFromSelection(const std::vector&) const; + void addFacetsToSelection(const std::vector&) const; + void addPointsToSelection(const std::vector&) const; + void removeFacetsFromSelection(const std::vector&) const; + void removePointsFromSelection(const std::vector&) const; unsigned long countSelectedFacets() const; bool hasSelectedFacets() const; unsigned long countSelectedPoints() const; bool hasSelectedPoints() const; - void getFacetsFromSelection(std::vector&) const; - void getPointsFromSelection(std::vector&) const; + void getFacetsFromSelection(std::vector&) const; + void getPointsFromSelection(std::vector&) const; void clearFacetSelection() const; void clearPointSelection() const; //@} @@ -261,14 +261,14 @@ public: void optimizeTopology(float); void optimizeEdges(); void splitEdges(); - void splitEdge(unsigned long, unsigned long, const Base::Vector3f&); - void splitFacet(unsigned long, const Base::Vector3f&, const Base::Vector3f&); - void swapEdge(unsigned long, unsigned long); - void collapseEdge(unsigned long, unsigned long); - void collapseFacet(unsigned long); - void collapseFacets(const std::vector&); - void insertVertex(unsigned long, const Base::Vector3f& v); - void snapVertex(unsigned long, const Base::Vector3f& v); + void splitEdge(FacetIndex, FacetIndex, const Base::Vector3f&); + void splitFacet(FacetIndex, const Base::Vector3f&, const Base::Vector3f&); + void swapEdge(FacetIndex, FacetIndex); + void collapseEdge(FacetIndex, FacetIndex); + void collapseFacet(FacetIndex); + void collapseFacets(const std::vector&); + void insertVertex(FacetIndex, const Base::Vector3f& v); + void snapVertex(FacetIndex, const Base::Vector3f& v); //@} /** @name Mesh validation */ @@ -291,7 +291,7 @@ public: void removeNonManifoldPoints(); bool hasSelfIntersections() const; void removeSelfIntersections(); - void removeSelfIntersections(const std::vector&); + void removeSelfIntersections(const std::vector&); void removeFoldsOnSurface(); void removeFullBoundaryFacets(); bool hasInvalidPoints() const; @@ -302,10 +302,10 @@ public: /** @name Mesh segments */ //@{ void addSegment(const Segment&); - void addSegment(const std::vector&); + void addSegment(const std::vector&); const Segment& getSegment(unsigned long) const; Segment& getSegment(unsigned long); - MeshObject* meshFromSegment(const std::vector&) const; + MeshObject* meshFromSegment(const std::vector&) const; std::vector getSegmentsOfType(GeometryType, float dev, unsigned long minFacets) const; //@} @@ -325,7 +325,7 @@ public: class MeshExport const_point_iterator { public: - const_point_iterator(const MeshObject*, unsigned long index); + const_point_iterator(const MeshObject*, PointIndex index); const_point_iterator(const const_point_iterator& pi); ~const_point_iterator(); @@ -346,7 +346,7 @@ public: class MeshExport const_facet_iterator { public: - const_facet_iterator(const MeshObject*, unsigned long index); + const_facet_iterator(const MeshObject*, FacetIndex index); const_facet_iterator(const const_facet_iterator& fi); ~const_facet_iterator(); @@ -387,8 +387,8 @@ public: friend class Segment; private: - void deletedFacets(const std::vector& remFacets); - void updateMesh(const std::vector&); + void deletedFacets(const std::vector& remFacets); + void updateMesh(const std::vector&); void updateMesh(); void swapKernel(MeshCore::MeshKernel& m, const std::vector& g); void copySegments(const MeshObject&); diff --git a/src/Mod/Mesh/App/MeshProperties.cpp b/src/Mod/Mesh/App/MeshProperties.cpp index 41139f3b03..224a37a1f9 100644 --- a/src/Mod/Mesh/App/MeshProperties.cpp +++ b/src/Mod/Mesh/App/MeshProperties.cpp @@ -529,11 +529,11 @@ void PropertyMeshKernel::transformGeometry(const Base::Matrix4D &rclMat) hasSetValue(); } -void PropertyMeshKernel::setPointIndices(const std::vector >& inds) +void PropertyMeshKernel::setPointIndices(const std::vector >& inds) { aboutToSetValue(); MeshCore::MeshKernel& kernel = _meshObject->getKernel(); - for (std::vector >::const_iterator it = inds.begin(); it != inds.end(); ++it) + for (std::vector >::const_iterator it = inds.begin(); it != inds.end(); ++it) kernel.SetPoint(it->first, it->second); hasSetValue(); } diff --git a/src/Mod/Mesh/App/MeshProperties.h b/src/Mod/Mesh/App/MeshProperties.h index 65607ca221..1b5fc3a473 100644 --- a/src/Mod/Mesh/App/MeshProperties.h +++ b/src/Mod/Mesh/App/MeshProperties.h @@ -215,7 +215,7 @@ public: void finishEditing(); /// Transform the real mesh data void transformGeometry(const Base::Matrix4D &rclMat); - void setPointIndices( const std::vector >& ); + void setPointIndices( const std::vector >& ); //@} /** @name Python interface */ diff --git a/src/Mod/Mesh/App/MeshPyImp.cpp b/src/Mod/Mesh/App/MeshPyImp.cpp index d4ca9b4d52..2df58c6e58 100644 --- a/src/Mod/Mesh/App/MeshPyImp.cpp +++ b/src/Mod/Mesh/App/MeshPyImp.cpp @@ -756,10 +756,10 @@ PyObject* MeshPy::getInternalFacets(PyObject *args) MeshCore::MeshEvalInternalFacets eval(kernel); eval.Evaluate(); - const std::vector& indices = eval.GetIndices(); + const std::vector& indices = eval.GetIndices(); Py::List ary(indices.size()); Py::List::size_type pos=0; - for (std::vector::const_iterator it = indices.begin(); it != indices.end(); ++it) { + for (std::vector::const_iterator it = indices.begin(); it != indices.end(); ++it) { ary[pos++] = Py::Long(*it); } @@ -841,8 +841,8 @@ PyObject* MeshPy::getSegment(PyObject *args) } Py::List ary; - const std::vector& segm = getMeshObjectPtr()->getSegment(index).getIndices(); - for (std::vector::const_iterator it = segm.begin(); it != segm.end(); ++it) { + const std::vector& segm = getMeshObjectPtr()->getSegment(index).getIndices(); + for (std::vector::const_iterator it = segm.begin(); it != segm.end(); ++it) { ary.append(Py::Long((int)*it)); } @@ -855,7 +855,7 @@ PyObject* MeshPy::getSeparateComponents(PyObject *args) return NULL; Py::List meshesList; - std::vector > segs; + std::vector > segs; segs = getMeshObjectPtr()->getComponents(); for (unsigned int i=0; imeshFromSegment(segs[i]); @@ -870,9 +870,9 @@ PyObject* MeshPy::getFacetSelection(PyObject *args) return 0; Py::List ary; - std::vector facets; + std::vector facets; getMeshObjectPtr()->getFacetsFromSelection(facets); - for (std::vector::const_iterator it = facets.begin(); it != facets.end(); ++it) { + for (std::vector::const_iterator it = facets.begin(); it != facets.end(); ++it) { ary.append(Py::Long((int)*it)); } @@ -885,9 +885,9 @@ PyObject* MeshPy::getPointSelection(PyObject *args) return 0; Py::List ary; - std::vector points; + std::vector points; getMeshObjectPtr()->getPointsFromSelection(points); - for (std::vector::const_iterator it = points.begin(); it != points.end(); ++it) { + for (std::vector::const_iterator it = points.begin(); it != points.end(); ++it) { ary.append(Py::Long((int)*it)); } @@ -900,7 +900,7 @@ PyObject* MeshPy::meshFromSegment(PyObject *args) if (!PyArg_ParseTuple(args, "O", &list)) return 0; - std::vector segment; + std::vector segment; Py::Sequence ary(list); for (Py::Sequence::iterator it = ary.begin(); it != ary.end(); ++it) { Py::Long f(*it); @@ -997,7 +997,7 @@ PyObject* MeshPy::getSelfIntersections(PyObject *args) if (!PyArg_ParseTuple(args, "")) return NULL; - std::vector > selfIndices; + std::vector > selfIndices; std::vector > selfPoints; MeshCore::MeshEvalSelfIntersection eval(getMeshObjectPtr()->getKernel()); eval.GetIntersections(selfIndices); @@ -1104,7 +1104,7 @@ PyObject* MeshPy::getNonUniformOrientedFacets(PyObject *args) const MeshCore::MeshKernel& kernel = getMeshObjectPtr()->getKernel(); MeshCore::MeshEvalOrientation cMeshEval(kernel); - std::vector inds = cMeshEval.GetIndices(); + std::vector inds = cMeshEval.GetIndices(); Py::Tuple tuple(inds.size()); for (std::size_t i=0; i facets; + std::vector facets; for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) { Py::Long idx(*it); unsigned long iIdx = static_cast(idx); @@ -1756,7 +1756,7 @@ PyObject* MeshPy::nearestFacetOnRay(PyObject *args) (float)Py::Float(dir_t.getItem(1)), (float)Py::Float(dir_t.getItem(2))); - unsigned long index = 0; + FacetIndex index = 0; Base::Vector3f res; MeshCore::MeshAlgorithm alg(getMeshObjectPtr()->getKernel()); @@ -1814,9 +1814,9 @@ PyObject* MeshPy::getPlanarSegments(PyObject *args) Py::List s; for (std::vector::iterator it = segments.begin(); it != segments.end(); ++it) { - const std::vector& segm = it->getIndices(); + const std::vector& segm = it->getIndices(); Py::List ary; - for (std::vector::const_iterator jt = segm.begin(); jt != segm.end(); ++jt) { + for (std::vector::const_iterator jt = segm.begin(); jt != segm.end(); ++jt) { ary.append(Py::Long((int)*jt)); } s.append(ary); @@ -1854,9 +1854,9 @@ PyObject* MeshPy::getSegmentsOfType(PyObject *args) Py::List s; for (std::vector::iterator it = segments.begin(); it != segments.end(); ++it) { - const std::vector& segm = it->getIndices(); + const std::vector& segm = it->getIndices(); Py::List ary; - for (std::vector::const_iterator jt = segm.begin(); jt != segm.end(); ++jt) { + for (std::vector::const_iterator jt = segm.begin(); jt != segm.end(); ++jt) { ary.append(Py::Long((int)*jt)); } s.append(ary); diff --git a/src/Mod/Mesh/App/MeshTexture.cpp b/src/Mod/Mesh/App/MeshTexture.cpp index 72b3a3fd2c..a8a1f98e43 100644 --- a/src/Mod/Mesh/App/MeshTexture.cpp +++ b/src/Mod/Mesh/App/MeshTexture.cpp @@ -85,7 +85,7 @@ void MeshTexture::apply(const Mesh::MeshObject& mesh, bool addDefaultColor, cons if (binding == MeshCore::MeshIO::PER_VERTEX) { diffuseColor.reserve(points.size()); for (size_t index=0; index pointMap; + std::vector pointMap; pointMap.reserve(points.size()); for (size_t index=0; index found = refPnt2Fac->GetIndices(index1, index2, index3); + for (const auto& it : facets) { + PointIndex index1 = pointMap[it._aulPoints[0]]; + PointIndex index2 = pointMap[it._aulPoints[1]]; + PointIndex index3 = pointMap[it._aulPoints[2]]; + if (index1 != MeshCore::POINT_INDEX_MAX && + index2 != MeshCore::POINT_INDEX_MAX && + index3 != MeshCore::POINT_INDEX_MAX) { + std::vector found = refPnt2Fac->GetIndices(index1, index2, index3); if (found.size() == 1) { diffuseColor.push_back(textureColor[found.front()]); } diff --git a/src/Mod/Mesh/App/MeshTexture.h b/src/Mod/Mesh/App/MeshTexture.h index 8f6b279a18..4222baf4ed 100644 --- a/src/Mod/Mesh/App/MeshTexture.h +++ b/src/Mod/Mesh/App/MeshTexture.h @@ -74,7 +74,7 @@ public: private: void apply(const Mesh::MeshObject& mesh, bool addDefaultColor, const App::Color& defaultColor, float max_dist, MeshCore::Material &material); - unsigned long findIndex(const Base::Vector3f& p, float max_dist) const { + PointIndex findIndex(const Base::Vector3f& p, float max_dist) const { if (max_dist < 0.0f) { return kdTree->FindExact(p); } diff --git a/src/Mod/Mesh/App/Segment.cpp b/src/Mod/Mesh/App/Segment.cpp index 726100f80c..cf7eb5c414 100644 --- a/src/Mod/Mesh/App/Segment.cpp +++ b/src/Mod/Mesh/App/Segment.cpp @@ -43,7 +43,7 @@ Segment::Segment(MeshObject* mesh, bool mod) { } -Segment::Segment(MeshObject* mesh, const std::vector& inds, bool mod) +Segment::Segment(MeshObject* mesh, const std::vector& inds, bool mod) : _mesh(mesh) , _indices(inds) , _save(false) @@ -53,7 +53,7 @@ Segment::Segment(MeshObject* mesh, const std::vector& inds, bool _mesh->updateMesh(inds); } -void Segment::addIndices(const std::vector& inds) +void Segment::addIndices(const std::vector& inds) { _indices.insert(_indices.end(), inds.begin(), inds.end()); std::sort(_indices.begin(), _indices.end()); @@ -62,21 +62,21 @@ void Segment::addIndices(const std::vector& inds) _mesh->updateMesh(inds); } -void Segment::removeIndices(const std::vector& inds) +void Segment::removeIndices(const std::vector& inds) { // make difference - std::vector result; - std::set s1(_indices.begin(), _indices.end()); - std::set s2(inds.begin(), inds.end()); + std::vector result; + std::set s1(_indices.begin(), _indices.end()); + std::set s2(inds.begin(), inds.end()); std::set_difference(s1.begin(), s1.end(), s2.begin(), s2.end(), - std::back_insert_iterator >(result)); + std::back_insert_iterator >(result)); _indices = result; if (_modifykernel) _mesh->updateMesh(); } -const std::vector& Segment::getIndices() const +const std::vector& Segment::getIndices() const { return _indices; } @@ -109,7 +109,7 @@ bool Segment::operator == (const Segment& s) const // ---------------------------------------------------------------------------- -Segment::const_facet_iterator::const_facet_iterator(const Segment* segm, std::vector::const_iterator it) +Segment::const_facet_iterator::const_facet_iterator(const Segment* segm, std::vector::const_iterator it) : _segment(segm), _f_it(segm->_mesh->getKernel()), _it(it) { this->_f_it.Set(0); diff --git a/src/Mod/Mesh/App/Segment.h b/src/Mod/Mesh/App/Segment.h index c0233ce982..aea805c1b9 100644 --- a/src/Mod/Mesh/App/Segment.h +++ b/src/Mod/Mesh/App/Segment.h @@ -27,6 +27,7 @@ #include #include #include "Facet.h" +#include "Types.h" #include "Core/Iterator.h" namespace Mesh @@ -38,10 +39,10 @@ class MeshExport Segment { public: Segment(MeshObject*, bool mod); - Segment(MeshObject*, const std::vector& inds, bool mod); - void addIndices(const std::vector& inds); - void removeIndices(const std::vector& inds); - const std::vector& getIndices() const; + Segment(MeshObject*, const std::vector& inds, bool mod); + void addIndices(const std::vector& inds); + void removeIndices(const std::vector& inds); + const std::vector& getIndices() const; bool isEmpty() const { return _indices.empty(); } Segment(const Segment&); @@ -62,7 +63,7 @@ public: private: MeshObject* _mesh; - std::vector _indices; + std::vector _indices; std::string _name; std::string _color; bool _save; @@ -72,7 +73,7 @@ public: class MeshExport const_facet_iterator { public: - const_facet_iterator(const Segment*, std::vector::const_iterator); + const_facet_iterator(const Segment*, std::vector::const_iterator); const_facet_iterator(const const_facet_iterator& fi); ~const_facet_iterator(); @@ -88,7 +89,7 @@ public: const Segment* _segment; Facet _facet; MeshCore::MeshFacetIterator _f_it; - std::vector::const_iterator _it; + std::vector::const_iterator _it; }; const_facet_iterator facets_begin() const diff --git a/src/Mod/Mesh/App/Types.h b/src/Mod/Mesh/App/Types.h new file mode 100644 index 0000000000..061323ffb7 --- /dev/null +++ b/src/Mod/Mesh/App/Types.h @@ -0,0 +1,40 @@ +/*************************************************************************** + * Copyright (c) 2021 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 * + * * + ***************************************************************************/ + + +#ifndef MESH_TYPES_H +#define MESH_TYPES_H + +#include "Core/Definitions.h" + + +namespace Mesh +{ + +// type definitions +using ElementIndex = MeshCore::ElementIndex; +using FacetIndex = MeshCore::FacetIndex; +using PointIndex = MeshCore::PointIndex; + +} // namespace Mesh + +#endif // MESH_TYPES_H diff --git a/src/Mod/Mesh/Gui/Command.cpp b/src/Mod/Mesh/Gui/Command.cpp index b02940792e..0110e54240 100644 --- a/src/Mod/Mesh/Gui/Command.cpp +++ b/src/Mod/Mesh/Gui/Command.cpp @@ -1845,7 +1845,7 @@ void CmdMeshSplitComponents::activated(int) std::vector objs = Gui::Selection().getObjectsOfType(Mesh::Feature::getClassTypeId()); for (std::vector::const_iterator it = objs.begin(); it != objs.end(); ++it) { const MeshObject& mesh = static_cast(*it)->Mesh.getValue(); - std::vector > comps = mesh.getComponents(); + std::vector > comps = mesh.getComponents(); for (const auto& comp : comps) { std::unique_ptr kernel(mesh.meshFromSegment(comp)); diff --git a/src/Mod/Mesh/Gui/DlgEvaluateMeshImp.cpp b/src/Mod/Mesh/Gui/DlgEvaluateMeshImp.cpp index cf4ef6631b..a14fc796e6 100644 --- a/src/Mod/Mesh/Gui/DlgEvaluateMeshImp.cpp +++ b/src/Mod/Mesh/Gui/DlgEvaluateMeshImp.cpp @@ -97,7 +97,7 @@ public: std::map vp; Mesh::Feature* meshFeature; QPointer view; - std::vector self_intersections; + std::vector self_intersections; bool enableFoldsCheck; bool checkNonManfoldPoints; bool strictlyDegenerated; @@ -276,7 +276,7 @@ void DlgEvaluateMeshImp::setMesh(Mesh::Feature* m) } } -void DlgEvaluateMeshImp::addViewProvider(const char* name, const std::vector& indices) +void DlgEvaluateMeshImp::addViewProvider(const char* name, const std::vector& indices) { removeViewProvider(name); @@ -440,7 +440,7 @@ void DlgEvaluateMeshImp::on_analyzeOrientationButton_clicked() const MeshKernel& rMesh = d->meshFeature->Mesh.getValue().getKernel(); MeshEvalOrientation eval(rMesh); - std::vector inds = eval.GetIndices(); + std::vector inds = eval.GetIndices(); #if 0 if (inds.empty() && !eval.Evaluate()) { d->ui.checkOrientationButton->setText(tr("Flipped normals found")); @@ -532,7 +532,7 @@ void DlgEvaluateMeshImp::on_analyzeNonmanifoldsButton_clicked() MeshEvalTopology f_eval(rMesh); bool ok1 = f_eval.Evaluate(); bool ok2 = true; - std::vector point_indices; + std::vector point_indices; if (d->checkNonManfoldPoints) { MeshEvalPointManifolds p_eval(rMesh); @@ -555,10 +555,10 @@ void DlgEvaluateMeshImp::on_analyzeNonmanifoldsButton_clicked() d->ui.repairAllTogether->setEnabled(true); if (!ok1) { - const std::vector >& inds = f_eval.GetIndices(); - std::vector indices; + const std::vector >& inds = f_eval.GetIndices(); + std::vector indices; indices.reserve(2*inds.size()); - std::vector >::const_iterator it; + std::vector >::const_iterator it; for (it = inds.begin(); it != inds.end(); ++it) { indices.push_back(it->first); indices.push_back(it->second); @@ -721,7 +721,7 @@ void DlgEvaluateMeshImp::on_analyzeDegeneratedButton_clicked() const MeshKernel& rMesh = d->meshFeature->Mesh.getValue().getKernel(); MeshEvalDegeneratedFacets eval(rMesh, d->epsilonDegenerated); - std::vector degen = eval.GetIndices(); + std::vector degen = eval.GetIndices(); if (degen.empty()) { d->ui.checkDegenerationButton->setText(tr("No degenerations")); @@ -787,7 +787,7 @@ void DlgEvaluateMeshImp::on_analyzeDuplicatedFacesButton_clicked() const MeshKernel& rMesh = d->meshFeature->Mesh.getValue().getKernel(); MeshEvalDuplicateFacets eval(rMesh); - std::vector dupl = eval.GetIndices(); + std::vector dupl = eval.GetIndices(); if (dupl.empty()) { d->ui.checkDuplicatedFacesButton->setText(tr("No duplicated faces")); @@ -919,7 +919,7 @@ void DlgEvaluateMeshImp::on_analyzeSelfIntersectionButton_clicked() const MeshKernel& rMesh = d->meshFeature->Mesh.getValue().getKernel(); MeshEvalSelfIntersection eval(rMesh); - std::vector > intersection; + std::vector > intersection; try { eval.GetIntersections(intersection); } @@ -939,9 +939,9 @@ void DlgEvaluateMeshImp::on_analyzeSelfIntersectionButton_clicked() d->ui.repairSelfIntersectionButton->setEnabled(true); d->ui.repairAllTogether->setEnabled(true); - std::vector indices; + std::vector indices; indices.reserve(2*intersection.size()); - std::vector >::iterator it; + std::vector >::iterator it; for (it = intersection.begin(); it != intersection.end(); ++it) { indices.push_back(it->first); indices.push_back(it->second); @@ -1022,9 +1022,9 @@ void DlgEvaluateMeshImp::on_analyzeFoldsButton_clicked() removeViewProvider("MeshGui::ViewProviderMeshFolds"); } else { - std::vector inds = f_eval.GetIndices(); - std::vector inds1 = s_eval.GetIndices(); - std::vector inds2 = b_eval.GetIndices(); + std::vector inds = f_eval.GetIndices(); + std::vector inds1 = s_eval.GetIndices(); + std::vector inds2 = b_eval.GetIndices(); inds.insert(inds.end(), inds1.begin(), inds1.end()); inds.insert(inds.end(), inds2.begin(), inds2.end()); diff --git a/src/Mod/Mesh/Gui/DlgEvaluateMeshImp.h b/src/Mod/Mesh/Gui/DlgEvaluateMeshImp.h index e5cf94472f..e663e795ae 100644 --- a/src/Mod/Mesh/Gui/DlgEvaluateMeshImp.h +++ b/src/Mod/Mesh/Gui/DlgEvaluateMeshImp.h @@ -31,6 +31,7 @@ #include #include #include +#include class QAbstractButton; @@ -127,7 +128,7 @@ protected: void refreshList(); void showInformation(); void cleanInformation(); - void addViewProvider(const char* vp, const std::vector& indices); + void addViewProvider(const char* vp, const std::vector& indices); void removeViewProvider(const char* vp); void removeViewProviders(); void changeEvent(QEvent *e); diff --git a/src/Mod/Mesh/Gui/DlgSmoothing.cpp b/src/Mod/Mesh/Gui/DlgSmoothing.cpp index 726afb2d62..2241f93a39 100644 --- a/src/Mod/Mesh/Gui/DlgSmoothing.cpp +++ b/src/Mod/Mesh/Gui/DlgSmoothing.cpp @@ -121,7 +121,7 @@ SmoothingDialog::SmoothingDialog(QWidget* parent, Qt::WindowFlags fl) QVBoxLayout* hboxLayout = new QVBoxLayout(this); QDialogButtonBox* buttonBox = new QDialogButtonBox(this); buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok); - + connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept())); connect(buttonBox, SIGNAL(rejected()), @@ -138,7 +138,7 @@ SmoothingDialog::~SmoothingDialog() // --------------------------------------- /* TRANSLATOR MeshGui::TaskSmoothing */ - + TaskSmoothing::TaskSmoothing() { widget = new DlgSmoothing(); @@ -180,7 +180,7 @@ bool TaskSmoothing::accept() bool hasSelection = false; for (std::vector::const_iterator it = meshes.begin(); it != meshes.end(); ++it) { Mesh::Feature* mesh = static_cast(*it); - std::vector selection; + std::vector selection; if (widget->smoothSelection()) { // clear the selection before editing the mesh to avoid // to have coloured triangles when doing an 'undo' diff --git a/src/Mod/Mesh/Gui/MeshEditor.cpp b/src/Mod/Mesh/Gui/MeshEditor.cpp index 1343450329..673b188464 100644 --- a/src/Mod/Mesh/Gui/MeshEditor.cpp +++ b/src/Mod/Mesh/Gui/MeshEditor.cpp @@ -65,7 +65,7 @@ namespace bp = boost::placeholders; PROPERTY_SOURCE(MeshGui::ViewProviderFace, Gui::ViewProviderDocumentObject) -ViewProviderFace::ViewProviderFace() : mesh(0), current_index(-1) +ViewProviderFace::ViewProviderFace() : mesh(nullptr), current_index(-1) { pcCoords = new SoCoordinate3(); pcCoords->ref(); @@ -150,7 +150,7 @@ const char* ViewProviderFace::getDefaultDisplayMode() const return "Marker"; } -std::vector ViewProviderFace::getDisplayModes(void) const +std::vector ViewProviderFace::getDisplayModes() const { std::vector modes; modes.push_back("Marker"); @@ -174,7 +174,7 @@ SoPickedPoint* ViewProviderFace::getPickedPoint(const SbVec2s& pos, const Gui::V // returns a copy of the point SoPickedPoint* pick = rp.getPickedPoint(); //return (pick ? pick->copy() : 0); // needs the same instance of CRT under MS Windows - return (pick ? new SoPickedPoint(*pick) : 0); + return (pick ? new SoPickedPoint(*pick) : nullptr); } // ---------------------------------------------------------------------- @@ -314,8 +314,8 @@ void MeshFaceAddition::showMarker(SoPickedPoint* pp) int index = (int)f._aulPoints[i]; if (std::find(faceView->index.begin(), faceView->index.end(), index) != faceView->index.end()) continue; // already inside - if (f._aulNeighbours[i] == ULONG_MAX || - f._aulNeighbours[(i+2)%3] == ULONG_MAX) { + if (f._aulNeighbours[i] == MeshCore::FACET_INDEX_MAX || + f._aulNeighbours[(i+2)%3] == MeshCore::FACET_INDEX_MAX) { pnt = points[index]; float len = Base::DistanceP2(pnt, Base::Vector3f(vec[0],vec[1],vec[2])); if (len < distance) { @@ -418,8 +418,8 @@ namespace MeshGui { // for sorting of elements struct NofFacetsCompare { - bool operator () (const std::vector &rclC1, - const std::vector &rclC2) + bool operator () (const std::vector &rclC1, + const std::vector &rclC2) { return rclC1.size() < rclC2.size(); } @@ -430,7 +430,7 @@ namespace MeshGui { MeshFillHole::MeshFillHole(MeshHoleFiller& hf, Gui::View3DInventor* parent) : QObject(parent) - , myMesh(0) + , myMesh(nullptr) , myNumPoints(0) , myVertex1(0) , myVertex2(0) @@ -566,7 +566,7 @@ void MeshFillHole::createPolygons() const MeshCore::MeshKernel & rMesh = this->myMesh->Mesh.getValue().getKernel(); // get the mesh boundaries as an array of point indices - std::list > borders; + std::list > borders; MeshCore::MeshAlgorithm cAlgo(rMesh); MeshCore::MeshPointIterator p_iter(rMesh); cAlgo.GetMeshBorders(borders); @@ -576,7 +576,7 @@ void MeshFillHole::createPolygons() borders.sort(NofFacetsCompare()); int32_t count=0; - for (std::list >::iterator it = + for (std::list >::iterator it = borders.begin(); it != borders.end(); ++it) { if (it->front() == it->back()) it->pop_back(); @@ -589,14 +589,14 @@ void MeshFillHole::createPolygons() coords->point.setNum(count); int32_t index = 0; - for (std::list >::iterator it = + for (std::list >::iterator it = borders.begin(); it != borders.end(); ++it) { SoPolygon* polygon = new SoPolygon(); polygon->startIndex = index; polygon->numVertices = it->size(); myBoundariesGroup->addChild(polygon); myPolygons[polygon] = *it; - for (std::vector::iterator jt = it->begin(); + for (std::vector::iterator jt = it->begin(); jt != it->end(); ++jt) { p_iter.Set(*jt); coords->point.set1Value(index++,p_iter->x,p_iter->y,p_iter->z); @@ -606,7 +606,7 @@ void MeshFillHole::createPolygons() SoNode* MeshFillHole::getPickedPolygon(const SoRayPickAction& action/*SoNode* root, const SbVec2s& pos*/) const { - SoPolygon* poly = 0; + SoPolygon* poly = nullptr; const SoPickedPointList & points = action.getPickedPointList(); for (int i=0; i < points.getLength(); i++) { const SoPickedPoint * point = points[i]; @@ -627,11 +627,11 @@ SoNode* MeshFillHole::getPickedPolygon(const SoRayPickAction& action/*SoNode* ro } float MeshFillHole::findClosestPoint(const SbLine& ray, const TBoundary& polygon, - unsigned long& vertex_index, SbVec3f& closestPoint) const + Mesh::PointIndex& vertex_index, SbVec3f& closestPoint) const { // now check which vertex of the polygon is closest to the ray float minDist = FLT_MAX; - vertex_index = ULONG_MAX; + vertex_index = MeshCore::POINT_INDEX_MAX; const MeshCore::MeshKernel & rMesh = myMesh->Mesh.getValue().getKernel(); const MeshCore::MeshPointArray& pts = rMesh.GetPoints(); @@ -671,7 +671,7 @@ void MeshFillHole::fileHoleCallback(void * ud, SoEventCallback * n) std::map::iterator it = self->myPolygons.find(node); if (it != self->myPolygons.end()) { // now check which vertex of the polygon is closest to the ray - unsigned long vertex_index; + Mesh::PointIndex vertex_index; SbVec3f closestPoint; float minDist = self->findClosestPoint(rp.getLine(), it->second, vertex_index, closestPoint); if (minDist < 1.0f) { @@ -701,7 +701,7 @@ void MeshFillHole::fileHoleCallback(void * ud, SoEventCallback * n) std::map::iterator it = self->myPolygons.find(node); if (it != self->myPolygons.end()) { // now check which vertex of the polygon is closest to the ray - unsigned long vertex_index; + Mesh::PointIndex vertex_index; SbVec3f closestPoint; float minDist = self->findClosestPoint(rp.getLine(), it->second, vertex_index, closestPoint); if (minDist < 1.0f) { diff --git a/src/Mod/Mesh/Gui/MeshEditor.h b/src/Mod/Mesh/Gui/MeshEditor.h index 6675d73620..225c40ab9a 100644 --- a/src/Mod/Mesh/Gui/MeshEditor.h +++ b/src/Mod/Mesh/Gui/MeshEditor.h @@ -58,7 +58,7 @@ public: void attach(App::DocumentObject* obj); void setDisplayMode(const char* ModeName); const char* getDefaultDisplayMode() const; - std::vector getDisplayModes(void) const; + std::vector getDisplayModes() const; SoPickedPoint* getPickedPoint(const SbVec2s& pos, const Gui::View3DInventorViewer* viewer) const; ViewProviderMesh* mesh; @@ -110,8 +110,8 @@ public: virtual ~MeshHoleFiller() { } - virtual bool fillHoles(Mesh::MeshObject&, const std::list >&, - unsigned long, unsigned long) + virtual bool fillHoles(Mesh::MeshObject&, const std::list >&, + Mesh::PointIndex, Mesh::PointIndex) { return false; } @@ -138,14 +138,14 @@ private Q_SLOTS: void closeBridge(); private: - typedef std::vector TBoundary; + typedef std::vector TBoundary; typedef boost::signals2::connection Connection; static void fileHoleCallback(void * ud, SoEventCallback * n); void createPolygons(); SoNode* getPickedPolygon(const SoRayPickAction& action) const; float findClosestPoint(const SbLine& ray, const TBoundary& polygon, - unsigned long&, SbVec3f&) const; + Mesh::PointIndex&, SbVec3f&) const; void slotChangedObject(const App::DocumentObject& Obj, const App::Property& Prop); private: @@ -157,8 +157,8 @@ private: std::map myPolygons; Mesh::Feature* myMesh; int myNumPoints; - unsigned long myVertex1; - unsigned long myVertex2; + Mesh::PointIndex myVertex1; + Mesh::PointIndex myVertex2; TBoundary myPolygon; MeshHoleFiller& myHoleFiller; Connection myConnection; diff --git a/src/Mod/Mesh/Gui/MeshSelection.cpp b/src/Mod/Mesh/Gui/MeshSelection.cpp index 65fdde88f8..6f47b0dd86 100644 --- a/src/Mod/Mesh/Gui/MeshSelection.cpp +++ b/src/Mod/Mesh/Gui/MeshSelection.cpp @@ -254,8 +254,8 @@ void MeshSelection::fullSelection() for (std::list::iterator it = views.begin(); it != views.end(); ++it) { Mesh::Feature* mf = static_cast((*it)->getObject()); const Mesh::MeshObject* mo = mf->Mesh.getValuePtr(); - std::vector faces(mo->countFacets()); - std::generate(faces.begin(), faces.end(), Base::iotaGen(0)); + std::vector faces(mo->countFacets()); + std::generate(faces.begin(), faces.end(), Base::iotaGen(0)); (*it)->addSelection(faces); } } @@ -301,12 +301,12 @@ bool MeshSelection::deleteSelectionBorder() Mesh::Feature* mf = static_cast((*it)->getObject()); // mark the selected facet as visited - std::vector selection, remove; - std::set borderPoints; + std::vector selection, remove; + std::set borderPoints; MeshCore::MeshAlgorithm meshAlg(mf->Mesh.getValue().getKernel()); meshAlg.GetFacetsFlag(selection, MeshCore::MeshFacet::SELECTED); meshAlg.GetBorderPoints(selection, borderPoints); - std::vector border; + std::vector border; border.insert(border.begin(), borderPoints.begin(), borderPoints.end()); meshAlg.ResetFacetFlag(MeshCore::MeshFacet::VISIT); @@ -359,13 +359,13 @@ void MeshSelection::selectComponent(int size) Mesh::Feature* mf = static_cast((*it)->getObject()); const Mesh::MeshObject* mo = mf->Mesh.getValuePtr(); - std::vector > segm; + std::vector > segm; MeshCore::MeshComponents comp(mo->getKernel()); comp.SearchForComponents(MeshCore::MeshComponents::OverEdge,segm); - std::vector faces; - for (std::vector >::iterator jt = segm.begin(); jt != segm.end(); ++jt) { - if (jt->size() < (unsigned long)size) + std::vector faces; + for (std::vector >::iterator jt = segm.begin(); jt != segm.end(); ++jt) { + if (jt->size() < (Mesh::FacetIndex)size) faces.insert(faces.end(), jt->begin(), jt->end()); } @@ -380,13 +380,13 @@ void MeshSelection::deselectComponent(int size) Mesh::Feature* mf = static_cast((*it)->getObject()); const Mesh::MeshObject* mo = mf->Mesh.getValuePtr(); - std::vector > segm; + std::vector > segm; MeshCore::MeshComponents comp(mo->getKernel()); comp.SearchForComponents(MeshCore::MeshComponents::OverEdge,segm); - std::vector faces; - for (std::vector >::iterator jt = segm.begin(); jt != segm.end(); ++jt) { - if (jt->size() > (unsigned long)size) + std::vector faces; + for (std::vector >::iterator jt = segm.begin(); jt != segm.end(); ++jt) { + if (jt->size() > (Mesh::FacetIndex)size) faces.insert(faces.end(), jt->begin(), jt->end()); } @@ -472,7 +472,7 @@ void MeshSelection::selectGLCallback(void * ud, SoEventCallback * n) for (std::list::iterator it = views.begin(); it != views.end(); ++it) { ViewProviderMesh* vp = *it; - std::vector faces; + std::vector faces; const Mesh::MeshObject& mesh = static_cast((*it)->getObject())->Mesh.getValue(); const MeshCore::MeshKernel& kernel = mesh.getKernel(); @@ -494,23 +494,23 @@ void MeshSelection::selectGLCallback(void * ud, SoEventCallback * n) const SbVec2s& p = *it; rect.extendBy(SbVec2s(p[0],height-p[1])); } - std::vector rf; rf.swap(faces); - std::vector vf = vp->getVisibleFacetsAfterZoom + std::vector rf; rf.swap(faces); + std::vector vf = vp->getVisibleFacetsAfterZoom (rect, view->getSoRenderManager()->getViewportRegion(), view->getSoRenderManager()->getCamera()); // get common facets of the viewport and the visible one std::sort(vf.begin(), vf.end()); std::sort(rf.begin(), rf.end()); - std::back_insert_iterator > biit(faces); + std::back_insert_iterator > biit(faces); std::set_intersection(vf.begin(), vf.end(), rf.begin(), rf.end(), biit); } // if set filter out all triangles which do not point into user direction if (self->onlyPointToUserTriangles) { - std::vector screen; + std::vector screen; screen.reserve(faces.size()); MeshCore::MeshFacetIterator it_f(kernel); - for (std::vector::iterator it = faces.begin(); it != faces.end(); ++it) { + for (std::vector::iterator it = faces.begin(); it != faces.end(); ++it) { it_f.Set(*it); if (it_f->GetNormal() * normal > 0.0f) { screen.push_back(*it); @@ -560,7 +560,7 @@ void MeshSelection::pickFaceCallback(void * ud, SoEventCallback * n) const SoDetail* detail = point->getDetail(/*mesh->getShapeNode()*/); if (detail && detail->getTypeId() == SoFaceDetail::getClassTypeId()) { // get the boundary to the picked facet - unsigned long uFacet = static_cast(detail)->getFaceIndex(); + Mesh::FacetIndex uFacet = static_cast(detail)->getFaceIndex(); if (self->addToSelection) { if (self->addComponent) mesh->selectComponent(uFacet); diff --git a/src/Mod/Mesh/Gui/SegmentationBestFit.cpp b/src/Mod/Mesh/Gui/SegmentationBestFit.cpp index 380c138476..efcddb8b65 100644 --- a/src/Mod/Mesh/Gui/SegmentationBestFit.cpp +++ b/src/Mod/Mesh/Gui/SegmentationBestFit.cpp @@ -262,7 +262,7 @@ void ParametersDialog::on_compute_clicked() const Mesh::MeshObject& kernel = myMesh->Mesh.getValue(); if (kernel.hasSelectedFacets()) { FitParameter::Points fitpts; - std::vector facets, points; + std::vector facets, points; kernel.getFacetsFromSelection(facets); points = kernel.getPointsFromFacets(facets); MeshCore::MeshPointArray coords = kernel.getKernel().GetPoints(points); diff --git a/src/Mod/Mesh/Gui/SoFCMeshObject.cpp b/src/Mod/Mesh/Gui/SoFCMeshObject.cpp index 03fdcc78b9..a7928a7cab 100644 --- a/src/Mod/Mesh/Gui/SoFCMeshObject.cpp +++ b/src/Mod/Mesh/Gui/SoFCMeshObject.cpp @@ -388,7 +388,7 @@ void SoFCMeshPickNode::pick(SoPickAction * action) const SbVec3f& dir = line.getDirection(); Base::Vector3f pt(pos[0],pos[1],pos[2]); Base::Vector3f dr(dir[0],dir[1],dir[2]); - unsigned long index; + Mesh::FacetIndex index; if (alg.NearestFacetOnRay(pt, dr, *meshGrid, pt, index)) { SoPickedPoint* pp = raypick->addIntersection(SbVec3f(pt.x,pt.y,pt.z)); if (pp) { @@ -1350,7 +1350,7 @@ void SoFCMeshSegmentShape::drawFaces(const Mesh::MeshObject * mesh, SoMaterialBu const MeshCore::MeshFacetArray & rFacets = mesh->getKernel().GetFacets(); if (mesh->countSegments() <= this->index.getValue()) return; - const std::vector rSegm = mesh->getSegment + const std::vector rSegm = mesh->getSegment (this->index.getValue()).getIndices(); bool perVertex = (mb && bind == PER_VERTEX_INDEXED); bool perFace = (mb && bind == PER_FACE_INDEXED); @@ -1360,7 +1360,7 @@ void SoFCMeshSegmentShape::drawFaces(const Mesh::MeshObject * mesh, SoMaterialBu glBegin(GL_TRIANGLES); if (ccw) { // counterclockwise ordering - for (std::vector::const_iterator it = rSegm.begin(); it != rSegm.end(); ++it) + for (std::vector::const_iterator it = rSegm.begin(); it != rSegm.end(); ++it) { const MeshCore::MeshFacet& f = rFacets[*it]; const MeshCore::MeshPoint& v0 = rPoints[f._aulPoints[0]]; @@ -1389,7 +1389,7 @@ void SoFCMeshSegmentShape::drawFaces(const Mesh::MeshObject * mesh, SoMaterialBu } else { // clockwise ordering - for (std::vector::const_iterator it = rSegm.begin(); it != rSegm.end(); ++it) + for (std::vector::const_iterator it = rSegm.begin(); it != rSegm.end(); ++it) { const MeshCore::MeshFacet& f = rFacets[*it]; const MeshCore::MeshPoint& v0 = rPoints[f._aulPoints[0]]; @@ -1412,7 +1412,7 @@ void SoFCMeshSegmentShape::drawFaces(const Mesh::MeshObject * mesh, SoMaterialBu } else { glBegin(GL_TRIANGLES); - for (std::vector::const_iterator it = rSegm.begin(); it != rSegm.end(); ++it) + for (std::vector::const_iterator it = rSegm.begin(); it != rSegm.end(); ++it) { const MeshCore::MeshFacet& f = rFacets[*it]; glVertex(rPoints[f._aulPoints[0]]); @@ -1432,7 +1432,7 @@ void SoFCMeshSegmentShape::drawPoints(const Mesh::MeshObject * mesh, SbBool need const MeshCore::MeshFacetArray & rFacets = mesh->getKernel().GetFacets(); if (mesh->countSegments() <= this->index.getValue()) return; - const std::vector rSegm = mesh->getSegment + const std::vector rSegm = mesh->getSegment (this->index.getValue()).getIndices(); int mod = rSegm.size()/renderTriangleLimit+1; @@ -1444,7 +1444,7 @@ void SoFCMeshSegmentShape::drawPoints(const Mesh::MeshObject * mesh, SbBool need glBegin(GL_POINTS); int ct=0; if (ccw) { - for (std::vector::const_iterator it = rSegm.begin(); it != rSegm.end(); ++it, ct++) + for (std::vector::const_iterator it = rSegm.begin(); it != rSegm.end(); ++it, ct++) { if (ct%mod==0) { const MeshCore::MeshFacet& f = rFacets[*it]; @@ -1469,7 +1469,7 @@ void SoFCMeshSegmentShape::drawPoints(const Mesh::MeshObject * mesh, SbBool need } } else { - for (std::vector::const_iterator it = rSegm.begin(); it != rSegm.end(); ++it, ct++) + for (std::vector::const_iterator it = rSegm.begin(); it != rSegm.end(); ++it, ct++) { if (ct%mod==0) { const MeshCore::MeshFacet& f = rFacets[*it]; @@ -1498,7 +1498,7 @@ void SoFCMeshSegmentShape::drawPoints(const Mesh::MeshObject * mesh, SbBool need else { glBegin(GL_POINTS); int ct=0; - for (std::vector::const_iterator it = rSegm.begin(); it != rSegm.end(); ++it, ct++) + for (std::vector::const_iterator it = rSegm.begin(); it != rSegm.end(); ++it, ct++) { if (ct%mod==0) { const MeshCore::MeshFacet& f = rFacets[*it]; @@ -1536,7 +1536,7 @@ void SoFCMeshSegmentShape::generatePrimitives(SoAction* action) return; if (mesh->countSegments() <= this->index.getValue()) return; - const std::vector rSegm = mesh->getSegment + const std::vector rSegm = mesh->getSegment (this->index.getValue()).getIndices(); // get material binding @@ -1552,7 +1552,7 @@ void SoFCMeshSegmentShape::generatePrimitives(SoAction* action) beginShape(action, TRIANGLES, &faceDetail); try { - for (std::vector::const_iterator it = rSegm.begin(); it != rSegm.end(); ++it) + for (std::vector::const_iterator it = rSegm.begin(); it != rSegm.end(); ++it) { const MeshCore::MeshFacet& f = rFacets[*it]; const MeshCore::MeshPoint& v0 = rPoints[f._aulPoints[0]]; @@ -1618,13 +1618,13 @@ void SoFCMeshSegmentShape::computeBBox(SoAction *action, SbBox3f &box, SbVec3f & const Mesh::MeshObject * mesh = SoFCMeshObjectElement::get(state); if (mesh && mesh->countSegments() > this->index.getValue()) { const Mesh::Segment& segm = mesh->getSegment(this->index.getValue()); - const std::vector& indices = segm.getIndices(); + const std::vector& indices = segm.getIndices(); Base::BoundBox3f cBox; if (!indices.empty()) { const MeshCore::MeshPointArray& rPoint = mesh->getKernel().GetPoints(); const MeshCore::MeshFacetArray& rFaces = mesh->getKernel().GetFacets(); - for (std::vector::const_iterator it = indices.begin(); + for (std::vector::const_iterator it = indices.begin(); it != indices.end(); ++it) { const MeshCore::MeshFacet& face = rFaces[*it]; cBox.Add(rPoint[face._aulPoints[0]]); @@ -1709,7 +1709,7 @@ void SoFCMeshObjectBoundary::drawLines(const Mesh::MeshObject * mesh) const glBegin(GL_LINES); for (MeshCore::MeshFacetArray::_TConstIterator it = rFacets.begin(); it != rFacets.end(); ++it) { for (int i=0; i<3; i++) { - if (it->_aulNeighbours[i] == ULONG_MAX) { + if (it->_aulNeighbours[i] == MeshCore::FACET_INDEX_MAX) { glVertex(rPoints[it->_aulPoints[i]]); glVertex(rPoints[it->_aulPoints[(i+1)%3]]); } @@ -1741,7 +1741,7 @@ void SoFCMeshObjectBoundary::generatePrimitives(SoAction* action) for (MeshCore::MeshFacetArray::_TConstIterator it = rFacets.begin(); it != rFacets.end(); ++it) { for (int i=0; i<3; i++) { - if (it->_aulNeighbours[i] == ULONG_MAX) { + if (it->_aulNeighbours[i] == MeshCore::FACET_INDEX_MAX) { const MeshCore::MeshPoint& v0 = rPoints[it->_aulPoints[i]]; const MeshCore::MeshPoint& v1 = rPoints[it->_aulPoints[(i+1)%3]]; @@ -1805,7 +1805,7 @@ void SoFCMeshObjectBoundary::getPrimitiveCount(SoGetPrimitiveCountAction * actio int ctEdges=0; for (MeshCore::MeshFacetArray::_TConstIterator jt = rFaces.begin(); jt != rFaces.end(); ++jt) { for (int i=0; i<3; i++) { - if (jt->_aulNeighbours[i] == ULONG_MAX) { + if (jt->_aulNeighbours[i] == MeshCore::FACET_INDEX_MAX) { ctEdges++; } } diff --git a/src/Mod/Mesh/Gui/ViewProvider.cpp b/src/Mod/Mesh/Gui/ViewProvider.cpp index bf66337d29..c3a23b0575 100644 --- a/src/Mod/Mesh/Gui/ViewProvider.cpp +++ b/src/Mod/Mesh/Gui/ViewProvider.cpp @@ -147,14 +147,14 @@ void ViewProviderMeshBuilder::createMesh(const App::Property* prop, SoCoordinate const MeshCore::MeshPointArray& cP = rcMesh.GetPoints(); coords->point.setNum(rcMesh.CountPoints()); SbVec3f* verts = coords->point.startEditing(); - unsigned long i=0; + int i=0; for (MeshCore::MeshPointArray::_TConstIterator it = cP.begin(); it != cP.end(); ++it, i++) { verts[i].setValue(it->x, it->y, it->z); } coords->point.finishEditing(); // set the face indices - unsigned long j=0; + int j=0; const MeshCore::MeshFacetArray& cF = rcMesh.GetFacets(); faces->coordIndex.setNum(4*rcMesh.CountFacets()); int32_t* indices = faces->coordIndex.startEditing(); @@ -1211,7 +1211,7 @@ void ViewProviderMesh::selectGLCallback(void * ud, SoEventCallback * n) void ViewProviderMesh::getFacetsFromPolygon(const std::vector& picked, const Base::ViewProjMethod& proj, SbBool inner, - std::vector& indices) const + std::vector& indices) const { const bool ok = true; Base::Polygon2d polygon; @@ -1225,11 +1225,11 @@ void ViewProviderMesh::getFacetsFromPolygon(const std::vector& picked, if (!inner) { // get the indices that are completely outside - std::vector complete(meshProp.getValue().countFacets()); - std::generate(complete.begin(), complete.end(), Base::iotaGen(0)); + std::vector complete(meshProp.getValue().countFacets()); + std::generate(complete.begin(), complete.end(), Base::iotaGen(0)); std::sort(indices.begin(), indices.end()); - std::vector complementary; - std::back_insert_iterator > biit(complementary); + std::vector complementary; + std::back_insert_iterator > biit(complementary); std::set_difference(complete.begin(), complete.end(), indices.begin(), indices.end(), biit); indices = complementary; } @@ -1238,7 +1238,7 @@ void ViewProviderMesh::getFacetsFromPolygon(const std::vector& picked, Base::Console().Message("The picked polygon seems to have self-overlappings. This could lead to strange results."); } -std::vector ViewProviderMesh::getFacetsOfRegion(const SbViewportRegion& select, +std::vector ViewProviderMesh::getFacetsOfRegion(const SbViewportRegion& select, const SbViewportRegion& region, SoCamera* camera) const { @@ -1251,7 +1251,7 @@ std::vector ViewProviderMesh::getFacetsOfRegion(const SbViewportR gl.apply(root); root->unref(); - std::vector faces; + std::vector faces; faces.insert(faces.end(), gl.indices.begin(), gl.indices.end()); return faces; } @@ -1315,7 +1315,7 @@ void ViewProviderMesh::boxZoom(const SbBox2s& box, const SbViewportRegion & vp, } } -std::vector ViewProviderMesh::getVisibleFacetsAfterZoom(const SbBox2s& rect, +std::vector ViewProviderMesh::getVisibleFacetsAfterZoom(const SbBox2s& rect, const SbViewportRegion& vp, SoCamera* camera) const { @@ -1363,7 +1363,7 @@ private: } -std::vector ViewProviderMesh::getVisibleFacets(const SbViewportRegion& vp, +std::vector ViewProviderMesh::getVisibleFacets(const SbViewportRegion& vp, SoCamera* camera) const { #if 0 @@ -1458,14 +1458,14 @@ std::vector ViewProviderMesh::getVisibleFacets(const SbViewportRe int width = img.width(); int height = img.height(); QRgb color=0; - std::vector faces; + std::vector faces; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { QRgb rgb = img.pixel(x,y); rgb = rgb-(0xff << 24); if (rgb != 0 && rgb != color) { color = rgb; - faces.push_back((unsigned long)rgb); + faces.push_back((Mesh::FacetIndex)rgb); } } } @@ -1481,7 +1481,7 @@ void ViewProviderMesh::cutMesh(const std::vector& picked, const Base::ViewProjMethod& proj, SbBool inner) { // Get the facet indices inside the tool mesh - std::vector indices; + std::vector indices; getFacetsFromPolygon(picked, proj, inner, indices); removeFacets(indices); } @@ -1510,17 +1510,17 @@ void ViewProviderMesh::splitMesh(const MeshCore::MeshKernel& toolMesh, const Bas const MeshCore::MeshKernel& meshPropKernel = meshProp.getValue().getKernel(); // Get the facet indices inside the tool mesh - std::vector indices; + std::vector indices; MeshCore::MeshFacetGrid cGrid(meshPropKernel); MeshCore::MeshAlgorithm cAlg(meshPropKernel); cAlg.GetFacetsFromToolMesh(toolMesh, normal, cGrid, indices); if (!clip_inner) { // get the indices that are completely outside - std::vector complete(meshPropKernel.CountFacets()); - std::generate(complete.begin(), complete.end(), Base::iotaGen(0)); + std::vector complete(meshPropKernel.CountFacets()); + std::generate(complete.begin(), complete.end(), Base::iotaGen(0)); std::sort(indices.begin(), indices.end()); - std::vector complementary; - std::back_insert_iterator > biit(complementary); + std::vector complementary; + std::back_insert_iterator > biit(complementary); std::set_difference(complete.begin(), complete.end(), indices.begin(), indices.end(), biit); indices = complementary; } @@ -1542,17 +1542,17 @@ void ViewProviderMesh::segmentMesh(const MeshCore::MeshKernel& toolMesh, const B const MeshCore::MeshKernel& meshPropKernel = meshProp.getValue().getKernel(); // Get the facet indices inside the tool mesh - std::vector indices; + std::vector indices; MeshCore::MeshFacetGrid cGrid(meshPropKernel); MeshCore::MeshAlgorithm cAlg(meshPropKernel); cAlg.GetFacetsFromToolMesh(toolMesh, normal, cGrid, indices); if (!clip_inner) { // get the indices that are completely outside - std::vector complete(meshPropKernel.CountFacets()); - std::generate(complete.begin(), complete.end(), Base::iotaGen(0)); + std::vector complete(meshPropKernel.CountFacets()); + std::generate(complete.begin(), complete.end(), Base::iotaGen(0)); std::sort(indices.begin(), indices.end()); - std::vector complementary; - std::back_insert_iterator > biit(complementary); + std::vector complementary; + std::back_insert_iterator > biit(complementary); std::set_difference(complete.begin(), complete.end(), indices.begin(), indices.end(), biit); indices = complementary; } @@ -1617,7 +1617,7 @@ void ViewProviderMesh::faceInfoCallback(void * ud, SoEventCallback * n) if (detail && detail->getTypeId() == SoFaceDetail::getClassTypeId()) { // get the boundary to the picked facet const SoFaceDetail* faceDetail = static_cast(detail); - unsigned long uFacet = faceDetail->getFaceIndex(); + Mesh::FacetIndex uFacet = faceDetail->getFaceIndex(); that->faceInfo(uFacet); Gui::GLFlagWindow* flags = 0; std::list glItems = view->getGraphicsItemsOfType(Gui::GLFlagWindow::getClassTypeId()); @@ -1683,7 +1683,7 @@ void ViewProviderMesh::fillHoleCallback(void * ud, SoEventCallback * n) const SoDetail* detail = point->getDetail(that->getShapeNode()); if ( detail && detail->getTypeId() == SoFaceDetail::getClassTypeId() ) { // get the boundary to the picked facet - unsigned long uFacet = ((SoFaceDetail*)detail)->getFaceIndex(); + Mesh::FacetIndex uFacet = ((SoFaceDetail*)detail)->getFaceIndex(); that->fillHole(uFacet); } } @@ -1750,14 +1750,14 @@ void ViewProviderMesh::markPartCallback(void * ud, SoEventCallback * n) const SoDetail* detail = point->getDetail(that->getShapeNode()); if ( detail && detail->getTypeId() == SoFaceDetail::getClassTypeId() ) { // get the boundary to the picked facet - unsigned long uFacet = static_cast(detail)->getFaceIndex(); + Mesh::FacetIndex uFacet = static_cast(detail)->getFaceIndex(); that->selectComponent(uFacet); } } } } -void ViewProviderMesh::faceInfo(unsigned long uFacet) +void ViewProviderMesh::faceInfo(Mesh::FacetIndex uFacet) { Mesh::Feature* fea = static_cast(this->getObject()); const MeshCore::MeshKernel& rKernel = fea->Mesh.getValue().getKernel(); @@ -1775,28 +1775,28 @@ void ViewProviderMesh::faceInfo(unsigned long uFacet) } } -void ViewProviderMesh::fillHole(unsigned long uFacet) +void ViewProviderMesh::fillHole(Mesh::FacetIndex uFacet) { // get parameter from user settings Base::Reference hGrp = Gui::WindowParameter::getDefaultParameter()->GetGroup("Mod/Mesh"); int level = (int)hGrp->GetInt("FillHoleLevel", 2); // get the boundary to the picked facet - std::list aBorder; + std::list aBorder; Mesh::Feature* fea = reinterpret_cast(this->getObject()); const MeshCore::MeshKernel& rKernel = fea->Mesh.getValue().getKernel(); MeshCore::MeshRefPointToFacets cPt2Fac(rKernel); MeshCore::MeshAlgorithm meshAlg(rKernel); meshAlg.GetMeshBorder(uFacet, aBorder); - std::vector boundary(aBorder.begin(), aBorder.end()); - std::list > boundaries; + std::vector boundary(aBorder.begin(), aBorder.end()); + std::list > boundaries; boundaries.push_back(boundary); meshAlg.SplitBoundaryLoops(boundaries); std::vector newFacets; std::vector newPoints; unsigned long numberOfOldPoints = rKernel.CountPoints(); - for (std::list >::iterator it = boundaries.begin(); it != boundaries.end(); ++it) { + for (std::list >::iterator it = boundaries.begin(); it != boundaries.end(); ++it) { if (it->size() < 3/* || it->size() > 200*/) continue; boundary = *it; @@ -1863,7 +1863,12 @@ void ViewProviderMesh::resetFacetTransparency() pcShapeMaterial->transparency.setValue(0); } -void ViewProviderMesh::removeFacets(const std::vector& facets) +/*! The triangles with the passed indices are already added to the mesh. */ +void ViewProviderMesh::appendFacets(const std::vector&) +{ +} + +void ViewProviderMesh::removeFacets(const std::vector& facets) { // Get the attached mesh property Mesh::PropertyMeshKernel& meshProp = static_cast(pcObject)->Mesh; @@ -1874,7 +1879,7 @@ void ViewProviderMesh::removeFacets(const std::vector& facets) bool ok = Coloring.getValue(); if (prop && prop->getSize() == static_cast(kernel->countPoints())) { - std::vector pointDegree; + std::vector pointDegree; unsigned long invalid = kernel->getPointDegree(facets, pointDegree); if (invalid > 0) { // switch off coloring mode @@ -1921,9 +1926,9 @@ void ViewProviderMesh::removeFacets(const std::vector& facets) Coloring.setValue(ok); } -void ViewProviderMesh::selectFacet(unsigned long facet) +void ViewProviderMesh::selectFacet(Mesh::FacetIndex facet) { - std::vector selection; + std::vector selection; selection.push_back(facet); const Mesh::MeshObject& rMesh = static_cast(pcObject)->Mesh.getValue(); @@ -1941,9 +1946,9 @@ void ViewProviderMesh::selectFacet(unsigned long facet) } } -void ViewProviderMesh::deselectFacet(unsigned long facet) +void ViewProviderMesh::deselectFacet(Mesh::FacetIndex facet) { - std::vector selection; + std::vector selection; selection.push_back(facet); const Mesh::MeshObject& rMesh = static_cast(pcObject)->Mesh.getValue(); @@ -1967,16 +1972,16 @@ void ViewProviderMesh::deselectFacet(unsigned long facet) } } -bool ViewProviderMesh::isFacetSelected(unsigned long facet) +bool ViewProviderMesh::isFacetSelected(Mesh::FacetIndex facet) { const Mesh::MeshObject& rMesh = static_cast(pcObject)->Mesh.getValue(); const MeshCore::MeshFacetArray& faces = rMesh.getKernel().GetFacets(); return faces[facet].IsFlag(MeshCore::MeshFacet::SELECTED); } -void ViewProviderMesh::selectComponent(unsigned long uFacet) +void ViewProviderMesh::selectComponent(Mesh::FacetIndex uFacet) { - std::vector selection; + std::vector selection; selection.push_back(uFacet); MeshCore::MeshTopFacetVisitor clVisitor(selection); @@ -1990,9 +1995,9 @@ void ViewProviderMesh::selectComponent(unsigned long uFacet) highlightSelection(); } -void ViewProviderMesh::deselectComponent(unsigned long uFacet) +void ViewProviderMesh::deselectComponent(Mesh::FacetIndex uFacet) { - std::vector selection; + std::vector selection; selection.push_back(uFacet); MeshCore::MeshTopFacetVisitor clVisitor(selection); @@ -2009,7 +2014,7 @@ void ViewProviderMesh::deselectComponent(unsigned long uFacet) unhighlightSelection(); } -void ViewProviderMesh::setSelection(const std::vector& indices) +void ViewProviderMesh::setSelection(const std::vector& indices) { const Mesh::MeshObject& rMesh = static_cast(pcObject)->Mesh.getValue(); rMesh.clearFacetSelection(); @@ -2022,7 +2027,7 @@ void ViewProviderMesh::setSelection(const std::vector& indices) highlightSelection(); } -void ViewProviderMesh::addSelection(const std::vector& indices) +void ViewProviderMesh::addSelection(const std::vector& indices) { const Mesh::MeshObject& rMesh = static_cast(pcObject)->Mesh.getValue(); rMesh.addFacetsToSelection(indices); @@ -2031,7 +2036,7 @@ void ViewProviderMesh::addSelection(const std::vector& indices) highlightSelection(); } -void ViewProviderMesh::removeSelection(const std::vector& indices) +void ViewProviderMesh::removeSelection(const std::vector& indices) { const Mesh::MeshObject& rMesh = static_cast(pcObject)->Mesh.getValue(); rMesh.removeFacetsFromSelection(indices); @@ -2051,7 +2056,7 @@ void ViewProviderMesh::invertSelection() 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; + std::vector notselect; notselect.reserve(num_notsel); MeshCore::MeshFacetArray::_TConstIterator beg = faces.begin(); MeshCore::MeshFacetArray::_TConstIterator end = faces.end(); @@ -2071,7 +2076,7 @@ void ViewProviderMesh::clearSelection() void ViewProviderMesh::deleteSelection() { - std::vector indices; + std::vector indices; Mesh::PropertyMeshKernel& meshProp = static_cast(pcObject)->Mesh; const Mesh::MeshObject& rMesh = meshProp.getValue(); rMesh.getFacetsFromSelection(indices); @@ -2084,7 +2089,6 @@ void ViewProviderMesh::deleteSelection() bool ViewProviderMesh::hasSelection() const { - std::vector indices; Mesh::PropertyMeshKernel& meshProp = static_cast(pcObject)->Mesh; const Mesh::MeshObject& rMesh = meshProp.getValue(); return rMesh.hasSelectedFacets(); @@ -2096,7 +2100,7 @@ void ViewProviderMesh::selectArea(short x, short y, short w, short h, { SbViewportRegion vp; vp.setViewportPixels (x, y, w, h); - std::vector faces = getFacetsOfRegion(vp, region, camera); + std::vector faces = getFacetsOfRegion(vp, region, camera); const Mesh::MeshObject& rMesh = static_cast(pcObject)->Mesh.getValue(); rMesh.addFacetsToSelection(faces); @@ -2107,7 +2111,7 @@ void ViewProviderMesh::selectArea(short x, short y, short w, short h, void ViewProviderMesh::highlightSelection() { - std::vector selection; + std::vector selection; const Mesh::MeshObject& rMesh = static_cast(pcObject)->Mesh.getValue(); rMesh.getFacetsFromSelection(selection); if (selection.empty()) { @@ -2125,7 +2129,7 @@ void ViewProviderMesh::highlightSelection() SbColor* cols = pcShapeMaterial->diffuseColor.startEditing(); for (int i=0; i::iterator it = selection.begin(); it != selection.end(); ++it) + for (std::vector::iterator it = selection.begin(); it != selection.end(); ++it) cols[*it].setValue(1.0f,0.0f,0.0f); pcShapeMaterial->diffuseColor.finishEditing(); } @@ -2153,7 +2157,7 @@ void ViewProviderMesh::setHighlightedComponents(bool on) void ViewProviderMesh::highlightComponents() { const Mesh::MeshObject& rMesh = static_cast(pcObject)->Mesh.getValue(); - std::vector > comps = rMesh.getComponents(); + std::vector > comps = rMesh.getComponents(); // Colorize the components pcMatBinding->value = SoMaterialBinding::PER_FACE; @@ -2161,12 +2165,12 @@ void ViewProviderMesh::highlightComponents() pcShapeMaterial->diffuseColor.setNum(uCtFacets); SbColor* cols = pcShapeMaterial->diffuseColor.startEditing(); - for (std::vector >::iterator it = comps.begin(); it != comps.end(); ++it) { + for (std::vector >::iterator it = comps.begin(); it != comps.end(); ++it) { float fMax = (float)RAND_MAX; float fRed = (float)rand()/fMax; float fGrn = (float)rand()/fMax; float fBlu = (float)rand()/fMax; - for (std::vector::iterator jt = it->begin(); jt != it->end(); ++jt) { + for (std::vector::iterator jt = it->begin(); jt != it->end(); ++jt) { cols[*jt].setValue(fRed,fGrn,fBlu); } } @@ -2213,11 +2217,11 @@ void ViewProviderMesh::highlightSegments(const std::vector& colors) pcShapeMaterial->diffuseColor.setNum(uCtFacets); SbColor* cols = pcShapeMaterial->diffuseColor.startEditing(); for (unsigned long i=0; i segm = rMesh.getSegment(i).getIndices(); + std::vector segm = rMesh.getSegment(i).getIndices(); float fRed = colors[i].r; float fGrn = colors[i].g; float fBlu = colors[i].b; - for (std::vector::iterator it = segm.begin(); it != segm.end(); ++it) { + for (std::vector::iterator it = segm.begin(); it != segm.end(); ++it) { cols[*it].setValue(fRed,fGrn,fBlu); } } @@ -2311,7 +2315,7 @@ void ViewProviderIndexedFaceSet::showOpenEdges(bool show) const MeshCore::MeshFacetArray& rFaces = rMesh.GetFacets(); for (MeshCore::MeshFacetArray::_TConstIterator it = rFaces.begin(); it != rFaces.end(); ++it) { for (int i=0; i<3; i++) { - if (it->_aulNeighbours[i] == ULONG_MAX) { + if (it->_aulNeighbours[i] == MeshCore::FACET_INDEX_MAX) { lines->coordIndex.set1Value(index++,it->_aulPoints[i]); lines->coordIndex.set1Value(index++,it->_aulPoints[(i+1)%3]); lines->coordIndex.set1Value(index++,SO_END_LINE_INDEX); diff --git a/src/Mod/Mesh/Gui/ViewProvider.h b/src/Mod/Mesh/Gui/ViewProvider.h index 4ac5979a99..7a0d87b22b 100644 --- a/src/Mod/Mesh/Gui/ViewProvider.h +++ b/src/Mod/Mesh/Gui/ViewProvider.h @@ -27,6 +27,7 @@ #include #include +#include #include #include #include @@ -142,27 +143,28 @@ public: /** @name Editing */ //@{ bool doubleClicked(void){ return false; } - bool isFacetSelected(unsigned long facet); - void selectComponent(unsigned long facet); - void deselectComponent(unsigned long facet); - void selectFacet(unsigned long facet); - void deselectFacet(unsigned long facet); - void setSelection(const std::vector&); - void addSelection(const std::vector&); - void removeSelection(const std::vector&); + bool isFacetSelected(Mesh::FacetIndex facet); + void selectComponent(Mesh::FacetIndex facet); + void deselectComponent(Mesh::FacetIndex facet); + void selectFacet(Mesh::FacetIndex facet); + void deselectFacet(Mesh::FacetIndex facet); + void setSelection(const std::vector&); + void addSelection(const std::vector&); + void removeSelection(const std::vector&); void invertSelection(); void clearSelection(); void deleteSelection(); bool hasSelection() const; void getFacetsFromPolygon(const std::vector& picked, const Base::ViewProjMethod& proj, SbBool inner, - std::vector& indices) const; - std::vector getFacetsOfRegion(const SbViewportRegion&, const SbViewportRegion&, SoCamera*) const; - std::vector getVisibleFacetsAfterZoom(const SbBox2s&, const SbViewportRegion&, SoCamera*) const; - std::vector getVisibleFacets(const SbViewportRegion&, SoCamera*) const; + std::vector& indices) const; + std::vector getFacetsOfRegion(const SbViewportRegion&, const SbViewportRegion&, SoCamera*) const; + std::vector getVisibleFacetsAfterZoom(const SbBox2s&, const SbViewportRegion&, SoCamera*) const; + std::vector getVisibleFacets(const SbViewportRegion&, SoCamera*) const; virtual void cutMesh(const std::vector& picked, const Base::ViewProjMethod& proj, SbBool inner); virtual void trimMesh(const std::vector& picked, const Base::ViewProjMethod& proj, SbBool inner); - virtual void removeFacets(const std::vector&); + virtual void appendFacets(const std::vector&); + virtual void removeFacets(const std::vector&); /*! The size of the array must be equal to the number of facets. */ void setFacetTransparency(const std::vector&); void resetFacetTransparency(); @@ -180,8 +182,8 @@ protected: void setOpenEdgeColorFrom(const App::Color& col); virtual void splitMesh(const MeshCore::MeshKernel& toolMesh, const Base::Vector3f& normal, SbBool inner); virtual void segmentMesh(const MeshCore::MeshKernel& toolMesh, const Base::Vector3f& normal, SbBool inner); - virtual void faceInfo(unsigned long facet); - virtual void fillHole(unsigned long facet); + virtual void faceInfo(Mesh::FacetIndex facet); + virtual void fillHole(Mesh::FacetIndex facet); virtual void selectArea(short, short, short, short, const SbViewportRegion&, SoCamera*); virtual void highlightSelection(); virtual void unhighlightSelection(); diff --git a/src/Mod/Mesh/Gui/ViewProviderCurvature.cpp b/src/Mod/Mesh/Gui/ViewProviderCurvature.cpp index 89cc682171..73bafb8578 100644 --- a/src/Mod/Mesh/Gui/ViewProviderCurvature.cpp +++ b/src/Mod/Mesh/Gui/ViewProviderCurvature.cpp @@ -340,7 +340,7 @@ void ViewProviderMeshCurvature::setVertexCurvatureMode(int mode) // curvature values std::vector fValues = pCurvInfo->getCurvature( mode ); - unsigned long j=0; + int j=0; for ( std::vector::const_iterator jt = fValues.begin(); jt != fValues.end(); ++jt, j++ ) { App::Color col = pcColorBar->getColor( *jt ); pcColorMat->diffuseColor.set1Value(j, SbColor(col.r, col.g, col.b)); diff --git a/src/Mod/Mesh/Gui/ViewProviderDefects.cpp b/src/Mod/Mesh/Gui/ViewProviderDefects.cpp index d0e9673a09..d086511e70 100644 --- a/src/Mod/Mesh/Gui/ViewProviderDefects.cpp +++ b/src/Mod/Mesh/Gui/ViewProviderDefects.cpp @@ -149,7 +149,7 @@ void ViewProviderMeshOrientation::attach(App::DocumentObject* pcFeat) addDisplayMaskMode(pcFaceRoot, "Face"); } -void ViewProviderMeshOrientation::showDefects(const std::vector& inds) +void ViewProviderMeshOrientation::showDefects(const std::vector& inds) { Mesh::Feature* f = static_cast(pcObject); const MeshCore::MeshKernel & rMesh = f->Mesh.getValue().getKernel(); @@ -157,9 +157,9 @@ void ViewProviderMeshOrientation::showDefects(const std::vector& pcCoords->point.deleteValues(0); pcCoords->point.setNum(3*inds.size()); MeshCore::MeshFacetIterator cF(rMesh); - unsigned long i=0; - unsigned long j=0; - for (std::vector::const_iterator it = inds.begin(); it != inds.end(); ++it) { + int i=0; + int j=0; + for (std::vector::const_iterator it = inds.begin(); it != inds.end(); ++it) { cF.Set(*it); for (int k=0; k<3; k++) { Base::Vector3f cP = cF->_aclPoints[k]; @@ -214,7 +214,7 @@ void ViewProviderMeshNonManifolds::attach(App::DocumentObject* pcFeat) addDisplayMaskMode(pcLineRoot, "Line"); } -void ViewProviderMeshNonManifolds::showDefects(const std::vector& inds) +void ViewProviderMeshNonManifolds::showDefects(const std::vector& inds) { if ((inds.size() % 2) != 0) return; @@ -224,9 +224,9 @@ void ViewProviderMeshNonManifolds::showDefects(const std::vector& pcCoords->point.deleteValues(0); pcCoords->point.setNum(inds.size()); MeshCore::MeshPointIterator cP(rMesh); - unsigned long i=0; - unsigned long j=0; - for (std::vector::const_iterator it = inds.begin(); it != inds.end(); ++it) { + int i=0; + int j=0; + for (std::vector::const_iterator it = inds.begin(); it != inds.end(); ++it) { cP.Set(*it); pcCoords->point.set1Value(i++,cP->x,cP->y,cP->z); ++it; // go to end point @@ -279,15 +279,15 @@ void ViewProviderMeshNonManifoldPoints::attach(App::DocumentObject* pcFeat) addDisplayMaskMode(pcPointRoot, "Point"); } -void ViewProviderMeshNonManifoldPoints::showDefects(const std::vector& inds) +void ViewProviderMeshNonManifoldPoints::showDefects(const std::vector& inds) { Mesh::Feature* f = static_cast(pcObject); const MeshCore::MeshKernel & rMesh = f->Mesh.getValue().getKernel(); pcCoords->point.deleteValues(0); pcCoords->point.setNum(inds.size()); MeshCore::MeshPointIterator cP(rMesh); - unsigned long i = 0; - for ( std::vector::const_iterator it = inds.begin(); it != inds.end(); ++it ) { + int i = 0; + for ( std::vector::const_iterator it = inds.begin(); it != inds.end(); ++it ) { cP.Set(*it); pcCoords->point.set1Value(i++,cP->x,cP->y,cP->z); } @@ -343,7 +343,7 @@ void ViewProviderMeshDuplicatedFaces::attach(App::DocumentObject* pcFeat) addDisplayMaskMode(pcFaceRoot, "Face"); } -void ViewProviderMeshDuplicatedFaces::showDefects(const std::vector& inds) +void ViewProviderMeshDuplicatedFaces::showDefects(const std::vector& inds) { Mesh::Feature* f = static_cast(pcObject); const MeshCore::MeshKernel & rMesh = f->Mesh.getValue().getKernel(); @@ -351,9 +351,9 @@ void ViewProviderMeshDuplicatedFaces::showDefects(const std::vectorpoint.deleteValues(0); pcCoords->point.setNum(3*inds.size()); MeshCore::MeshFacetIterator cF(rMesh); - unsigned long i=0; - unsigned long j=0; - for (std::vector::const_iterator it = inds.begin(); it != inds.end(); ++it) { + int i=0; + int j=0; + for (std::vector::const_iterator it = inds.begin(); it != inds.end(); ++it) { cF.Set(*it); for (int k=0; k<3; k++) { Base::Vector3f cP = cF->_aclPoints[k]; @@ -408,15 +408,15 @@ void ViewProviderMeshDuplicatedPoints::attach(App::DocumentObject* pcFeat) addDisplayMaskMode(pcPointRoot, "Point"); } -void ViewProviderMeshDuplicatedPoints::showDefects(const std::vector& inds) +void ViewProviderMeshDuplicatedPoints::showDefects(const std::vector& inds) { Mesh::Feature* f = static_cast(pcObject); const MeshCore::MeshKernel & rMesh = f->Mesh.getValue().getKernel(); pcCoords->point.deleteValues(0); pcCoords->point.setNum(inds.size()); MeshCore::MeshPointIterator cP(rMesh); - unsigned long i = 0; - for ( std::vector::const_iterator it = inds.begin(); it != inds.end(); ++it ) { + int i = 0; + for ( std::vector::const_iterator it = inds.begin(); it != inds.end(); ++it ) { cP.Set(*it); pcCoords->point.set1Value(i++,cP->x,cP->y,cP->z); } @@ -465,7 +465,7 @@ void ViewProviderMeshDegenerations::attach(App::DocumentObject* pcFeat) addDisplayMaskMode(pcLineRoot, "Line"); } -void ViewProviderMeshDegenerations::showDefects(const std::vector& inds) +void ViewProviderMeshDegenerations::showDefects(const std::vector& inds) { Mesh::Feature* f = static_cast(pcObject); const MeshCore::MeshKernel & rMesh = f->Mesh.getValue().getKernel(); @@ -473,9 +473,9 @@ void ViewProviderMeshDegenerations::showDefects(const std::vector pcCoords->point.deleteValues(0); pcCoords->point.setNum(2*inds.size()); MeshCore::MeshFacetIterator cF(rMesh); - unsigned long i=0; - unsigned long j=0; - for (std::vector::const_iterator it = inds.begin(); it != inds.end(); ++it) { + int i=0; + int j=0; + for (std::vector::const_iterator it = inds.begin(); it != inds.end(); ++it) { cF.Set(*it); const MeshCore::MeshPoint& rE0 = cF->_aclPoints[0]; const MeshCore::MeshPoint& rE1 = cF->_aclPoints[1]; @@ -571,7 +571,7 @@ void ViewProviderMeshIndices::attach(App::DocumentObject* pcFeat) addDisplayMaskMode(pcFaceRoot, "Face"); } -void ViewProviderMeshIndices::showDefects(const std::vector& inds) +void ViewProviderMeshIndices::showDefects(const std::vector& inds) { Mesh::Feature* f = static_cast(pcObject); const MeshCore::MeshKernel & rMesh = f->Mesh.getValue().getKernel(); @@ -580,9 +580,9 @@ void ViewProviderMeshIndices::showDefects(const std::vector& inds pcCoords->point.deleteValues(0); pcCoords->point.setNum(3*inds.size()); MeshCore::MeshFacetIterator cF(rMesh); - unsigned long i=0; - unsigned long j=0; - for (std::vector::const_iterator it = inds.begin(); it != inds.end(); ++it) { + int i=0; + int j=0; + for (std::vector::const_iterator it = inds.begin(); it != inds.end(); ++it) { cF.Set(*it); for (int k=0; k<3; k++) { Base::Vector3f cP = cF->_aclPoints[k]; @@ -638,7 +638,7 @@ void ViewProviderMeshSelfIntersections::attach(App::DocumentObject* pcFeat) addDisplayMaskMode(pcLineRoot, "Line"); } -void ViewProviderMeshSelfIntersections::showDefects(const std::vector& indices) +void ViewProviderMeshSelfIntersections::showDefects(const std::vector& indices) { if (indices.size() % 2 != 0) return; @@ -646,12 +646,12 @@ void ViewProviderMeshSelfIntersections::showDefects(const std::vectorMesh.getValue().getKernel(); MeshCore::MeshEvalSelfIntersection eval(rMesh); - std::vector > intersection; - std::vector::const_iterator it; + std::vector > intersection; + std::vector::const_iterator it; for (it = indices.begin(); it != indices.end(); ) { - unsigned long id1 = *it; ++it; - unsigned long id2 = *it; ++it; - intersection.emplace_back(id1,id2); + Mesh::ElementIndex id1 = *it; ++it; + Mesh::ElementIndex id2 = *it; ++it; + intersection.push_back(std::make_pair(id1,id2)); } std::vector > lines; @@ -659,8 +659,8 @@ void ViewProviderMeshSelfIntersections::showDefects(const std::vectorpoint.deleteValues(0); pcCoords->point.setNum(2*lines.size()); - unsigned long i=0; - unsigned long j=0; + int i=0; + int j=0; for (std::vector >::const_iterator it = lines.begin(); it != lines.end(); ++it) { pcCoords->point.set1Value(i++,it->first.x,it->first.y,it->first.z); pcCoords->point.set1Value(i++,it->second.x,it->second.y,it->second.z); @@ -718,7 +718,7 @@ void ViewProviderMeshFolds::attach(App::DocumentObject* pcFeat) addDisplayMaskMode(pcFaceRoot, "Face"); } -void ViewProviderMeshFolds::showDefects(const std::vector& inds) +void ViewProviderMeshFolds::showDefects(const std::vector& inds) { Mesh::Feature* f = static_cast(pcObject); const MeshCore::MeshKernel & rMesh = f->Mesh.getValue().getKernel(); @@ -726,9 +726,9 @@ void ViewProviderMeshFolds::showDefects(const std::vector& inds) pcCoords->point.deleteValues(0); pcCoords->point.setNum(3*inds.size()); MeshCore::MeshFacetIterator cF(rMesh); - unsigned long i=0; - unsigned long j=0; - for (std::vector::const_iterator it = inds.begin(); it != inds.end(); ++it) { + int i=0; + int j=0; + for (std::vector::const_iterator it = inds.begin(); it != inds.end(); ++it) { cF.Set(*it); for (int k=0; k<3; k++) { Base::Vector3f cP = cF->_aclPoints[k]; diff --git a/src/Mod/Mesh/Gui/ViewProviderDefects.h b/src/Mod/Mesh/Gui/ViewProviderDefects.h index d9815a8f2b..223585558f 100644 --- a/src/Mod/Mesh/Gui/ViewProviderDefects.h +++ b/src/Mod/Mesh/Gui/ViewProviderDefects.h @@ -50,7 +50,7 @@ public: // Build up the initial Inventor node virtual void attach(App::DocumentObject* pcFeature) = 0; /// Fill up the Inventor node with data - virtual void showDefects(const std::vector&) = 0; + virtual void showDefects(const std::vector&) = 0; protected: /// get called by the container whenever a property has been changed @@ -72,7 +72,7 @@ public: virtual ~ViewProviderMeshOrientation(); void attach(App::DocumentObject* pcFeature); - void showDefects(const std::vector&); + void showDefects(const std::vector&); protected: SoFaceSet* pcFaces; @@ -90,7 +90,7 @@ public: virtual ~ViewProviderMeshNonManifolds(); void attach(App::DocumentObject* pcFeature); - void showDefects(const std::vector&); + void showDefects(const std::vector&); protected: SoLineSet* pcLines; @@ -108,7 +108,7 @@ public: virtual ~ViewProviderMeshNonManifoldPoints(); void attach(App::DocumentObject* pcFeature); - void showDefects(const std::vector&); + void showDefects(const std::vector&); protected: SoPointSet* pcPoints; @@ -126,7 +126,7 @@ public: virtual ~ViewProviderMeshDuplicatedFaces(); void attach(App::DocumentObject* pcFeature); - void showDefects(const std::vector&); + void showDefects(const std::vector&); protected: SoFaceSet* pcFaces; @@ -144,7 +144,7 @@ public: virtual ~ViewProviderMeshDegenerations(); void attach(App::DocumentObject* pcFeature); - void showDefects(const std::vector&); + void showDefects(const std::vector&); protected: SoLineSet* pcLines; @@ -159,7 +159,7 @@ public: virtual ~ViewProviderMeshDuplicatedPoints(); void attach(App::DocumentObject* pcFeature); - void showDefects(const std::vector&); + void showDefects(const std::vector&); protected: SoPointSet* pcPoints; @@ -174,7 +174,7 @@ public: virtual ~ViewProviderMeshIndices(); void attach(App::DocumentObject* pcFeature); - void showDefects(const std::vector&); + void showDefects(const std::vector&); protected: SoFaceSet* pcFaces; @@ -192,7 +192,7 @@ public: virtual ~ViewProviderMeshSelfIntersections(); void attach(App::DocumentObject* pcFeature); - void showDefects(const std::vector&); + void showDefects(const std::vector&); protected: SoLineSet* pcLines; @@ -207,7 +207,7 @@ public: virtual ~ViewProviderMeshFolds(); void attach(App::DocumentObject* pcFeature); - void showDefects(const std::vector&); + void showDefects(const std::vector&); protected: SoFaceSet* pcFaces; diff --git a/src/Mod/Mesh/Gui/ViewProviderMeshFaceSet.cpp b/src/Mod/Mesh/Gui/ViewProviderMeshFaceSet.cpp index 822de958c9..7c0d7765a7 100644 --- a/src/Mod/Mesh/Gui/ViewProviderMeshFaceSet.cpp +++ b/src/Mod/Mesh/Gui/ViewProviderMeshFaceSet.cpp @@ -167,7 +167,7 @@ void ViewProviderMeshFaceSet::updateData(const App::Property* prop) } showOpenEdges(OpenEdges.getValue()); - std::vector selection; + std::vector selection; mesh->getFacetsFromSelection(selection); if (selection.empty()) unhighlightSelection(); @@ -181,7 +181,7 @@ void ViewProviderMeshFaceSet::showOpenEdges(bool show) if (pcOpenEdge) { // remove the node and destroy the data pcRoot->removeChild(pcOpenEdge); - pcOpenEdge = 0; + pcOpenEdge = nullptr; } if (show) { @@ -204,7 +204,7 @@ void ViewProviderMeshFaceSet::showOpenEdges(bool show) const MeshCore::MeshFacetArray& rFaces = rMesh.GetFacets(); for (MeshCore::MeshFacetArray::_TConstIterator it = rFaces.begin(); it != rFaces.end(); ++it) { for (int i=0; i<3; i++) { - if (it->_aulNeighbours[i] == ULONG_MAX) { + if (it->_aulNeighbours[i] == MeshCore::FACET_INDEX_MAX) { lines->coordIndex.set1Value(index++,it->_aulPoints[i]); lines->coordIndex.set1Value(index++,it->_aulPoints[(i+1)%3]); lines->coordIndex.set1Value(index++,SO_END_LINE_INDEX); diff --git a/src/Mod/Mesh/Gui/ViewProviderMeshPyImp.cpp b/src/Mod/Mesh/Gui/ViewProviderMeshPyImp.cpp index 7c4d546473..543c1f6953 100644 --- a/src/Mod/Mesh/Gui/ViewProviderMeshPyImp.cpp +++ b/src/Mod/Mesh/Gui/ViewProviderMeshPyImp.cpp @@ -51,11 +51,11 @@ PyObject* ViewProviderMeshPy::setSelection(PyObject *args) return 0; Py::Sequence list(obj); - std::vector selection; + std::vector selection; selection.reserve(list.size()); for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) { Py::Long index(*it); - unsigned long value = static_cast(index); + Mesh::FacetIndex value = static_cast(index); selection.push_back(value); } @@ -71,11 +71,11 @@ PyObject* ViewProviderMeshPy::addSelection(PyObject *args) return 0; Py::Sequence list(obj); - std::vector selection; + std::vector selection; selection.reserve(list.size()); for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) { Py::Long index(*it); - unsigned long value = static_cast(index); + Mesh::FacetIndex value = static_cast(index); selection.push_back(value); } @@ -91,11 +91,11 @@ PyObject* ViewProviderMeshPy::removeSelection(PyObject *args) return 0; Py::Sequence list(obj); - std::vector selection; + std::vector selection; selection.reserve(list.size()); for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) { Py::Long index(*it); - unsigned long value = static_cast(index); + Mesh::FacetIndex value = static_cast(index); selection.push_back(value); } diff --git a/src/Mod/Mesh/Gui/ViewProviderTransformDemolding.cpp b/src/Mod/Mesh/Gui/ViewProviderTransformDemolding.cpp index 996cdf89d7..1bd005df30 100644 --- a/src/Mod/Mesh/Gui/ViewProviderTransformDemolding.cpp +++ b/src/Mod/Mesh/Gui/ViewProviderTransformDemolding.cpp @@ -150,7 +150,7 @@ void ViewProviderMeshTransformDemolding::calcMaterialIndex(const SbRotation &rot // 3.1415926535897932384626433832795 SbVec3f Up(0,0,1),result; - unsigned long i=0; + int i=0; for( std::vector::const_iterator it=normalVector.begin();it != normalVector.end(); ++it,i++) { rot.multVec(*it,result); diff --git a/src/Mod/MeshPart/App/AppMeshPartPy.cpp b/src/Mod/MeshPart/App/AppMeshPartPy.cpp index c33f16daa8..489ae76933 100644 --- a/src/Mod/MeshPart/App/AppMeshPartPy.cpp +++ b/src/Mod/MeshPart/App/AppMeshPartPy.cpp @@ -419,7 +419,7 @@ private: Py::List list(o); Mesh::MeshObject* mesh = static_cast(m)->getMeshObjectPtr(); - std::vector segm; + std::vector segm; segm.reserve(list.size()); for (Py_ssize_t i=0; i > FaceProjctMap; + std::map > FaceProjctMap; for (unsigned long i = 0; i <= ulNbOfPoints; i++) { @@ -387,7 +387,7 @@ void CurveProjectorSimple::projectCurve( const TopoDS_Edge& aEdge, MeshGeomFacet cCurFacet= MeshK.GetFacet(uCurFacetIdx); MeshK.GetFacetNeighbours ( uCurFacetIdx, auNeighboursIdx[0], auNeighboursIdx[1], auNeighboursIdx[2]); - uCurFacetIdx = ULONG_MAX; + uCurFacetIdx = MeshCore::FACET_INDEX_MAX; PointCount = 0; for(int i=0; i<3; i++) @@ -405,7 +405,7 @@ void CurveProjectorSimple::projectCurve( const TopoDS_Edge& aEdge, } - }while(uCurFacetIdx != ULONG_MAX); + }while(uCurFacetIdx != MeshCore::FACET_INDEX_MAX); */ } @@ -425,9 +425,9 @@ void CurveProjectorSimple::projectCurve( const TopoDS_Edge& aEdge, // projection of the first point Base::Vector3f cStartPoint = Base::Vector3f(gpPt.X(),gpPt.Y(),gpPt.Z()); Base::Vector3f cResultPoint, cSplitPoint, cPlanePnt, cPlaneNormal,TempResultPoint; - unsigned long uStartFacetIdx,uCurFacetIdx; - unsigned long uLastFacetIdx=ULONG_MAX-1; // use another value as ULONG_MAX - unsigned long auNeighboursIdx[3]; + MeshCore::FacetIndex uStartFacetIdx,uCurFacetIdx; + MeshCore::FacetIndex uLastFacetIdx=MeshCore::FACET_INDEX_MAX-1; // use another value as FACET_INDEX_MAX + MeshCore::FacetIndex auNeighboursIdx[3]; bool GoOn; // go through the whole Mesh, find the first projection @@ -471,7 +471,7 @@ void CurveProjectorSimple::projectCurve( const TopoDS_Edge& aEdge, for(int i=0; i<3; i++) { // if the i'th neighbour is valid - if ( auNeighboursIdx[i] != ULONG_MAX ) + if ( auNeighboursIdx[i] != MeshCore::FACET_INDEX_MAX ) { // try to project next interval MeshGeomFacet N = MeshK.GetFacet( auNeighboursIdx[i] ); @@ -511,9 +511,9 @@ void CurveProjectorSimple::projectCurve( const TopoDS_Edge& aEdge, // projection of the first point Base::Vector3f cStartPoint = Base::Vector3f(gpPt.X(),gpPt.Y(),gpPt.Z()); Base::Vector3f cResultPoint, cSplitPoint, cPlanePnt, cPlaneNormal; - unsigned long uStartFacetIdx,uCurFacetIdx; - unsigned long uLastFacetIdx=ULONG_MAX-1; // use another value as ULONG_MAX - unsigned long auNeighboursIdx[3]; + MeshCore::FacetIndex uStartFacetIdx,uCurFacetIdx; + MeshCore::FacetIndex uLastFacetIdx=MeshCore::FACET_INDEX_MAX-1; // use another value as FACET_INDEX_MAX + MeshCore::FacetIndex auNeighboursIdx[3]; bool GoOn; if( !findStartPoint(MeshK,cStartPoint,cResultPoint,uStartFacetIdx) ) @@ -542,7 +542,7 @@ void CurveProjectorSimple::projectCurve( const TopoDS_Edge& aEdge, } */ -bool CurveProjectorSimple::findStartPoint(const MeshKernel &MeshK,const Base::Vector3f &Pnt,Base::Vector3f &Rslt,unsigned long &FaceIndex) +bool CurveProjectorSimple::findStartPoint(const MeshKernel &MeshK,const Base::Vector3f &Pnt,Base::Vector3f &Rslt,MeshCore::FacetIndex &FaceIndex) { Base::Vector3f TempResultPoint; float MinLength = FLOAT_MAX; @@ -621,7 +621,7 @@ void CurveProjectorWithToolMesh::makeToolMesh( const TopoDS_Edge& aEdge,std::vec Base::SequencerLauncher seq("Building up tool mesh...", ulNbOfPoints+1); - std::map > FaceProjctMap; + std::map > FaceProjctMap; for (unsigned long i = 0; i < ulNbOfPoints; i++) { @@ -878,7 +878,7 @@ void MeshProjection::projectOnMesh(const std::vector& pointsIn, for (auto it : pointsIn) { Base::Vector3f result; - unsigned long index; + MeshCore::FacetIndex index; if (clAlg.NearestFacetOnRay(it, dir, cGrid, result, index)) { MeshCore::MeshGeomFacet geomFacet = _rcMesh.GetFacet(index); if (tolerance > 0 && geomFacet.IntersectPlaneWithLine(it, dir, result)) { @@ -943,13 +943,13 @@ void MeshProjection::projectParallelToMesh (const TopoDS_Shape &aShape, const Ba std::vector points; discretize(aEdge, points, 5); - typedef std::pair HitPoint; + typedef std::pair HitPoint; std::vector hitPoints; typedef std::pair HitPoints; std::vector hitPointPairs; for (auto it : points) { Base::Vector3f result; - unsigned long index; + MeshCore::FacetIndex index; if (clAlg.NearestFacetOnRay(it, dir, cGrid, result, index)) { hitPoints.emplace_back(result, index); @@ -988,13 +988,13 @@ void MeshProjection::projectParallelToMesh (const std::vector &aEdges, for (auto it : aEdges) { std::vector points = it.points; - typedef std::pair HitPoint; + typedef std::pair HitPoint; std::vector hitPoints; typedef std::pair HitPoints; std::vector hitPointPairs; for (auto it : points) { Base::Vector3f result; - unsigned long index; + MeshCore::FacetIndex index; if (clAlg.NearestFacetOnRay(it, dir, cGrid, result, index)) { hitPoints.emplace_back(result, index); @@ -1024,8 +1024,8 @@ void MeshProjection::projectParallelToMesh (const std::vector &aEdges, void MeshProjection::projectEdgeToEdge( const TopoDS_Edge &aEdge, float fMaxDist, const MeshFacetGrid& rGrid, std::vector& rSplitEdges ) const { - std::vector auFInds; - std::map, std::list > pEdgeToFace; + std::vector auFInds; + std::map, std::list > pEdgeToFace; const std::vector& rclFAry = _rcMesh.GetFacets(); // search the facets in the local area of the curve @@ -1038,12 +1038,12 @@ void MeshProjection::projectEdgeToEdge( const TopoDS_Edge &aEdge, float fMaxDist auFInds.erase(std::unique(auFInds.begin(), auFInds.end()), auFInds.end()); // facet to edge - for ( std::vector::iterator pI = auFInds.begin(); pI != auFInds.end(); ++pI ) { + for ( std::vector::iterator pI = auFInds.begin(); pI != auFInds.end(); ++pI ) { const MeshFacet& rF = rclFAry[*pI]; for (int i = 0; i < 3; i++) { - unsigned long ulPt0 = std::min(rF._aulPoints[i], rF._aulPoints[(i+1)%3]); - unsigned long ulPt1 = std::max(rF._aulPoints[i], rF._aulPoints[(i+1)%3]); - pEdgeToFace[std::pair(ulPt0, ulPt1)].push_front(*pI); + MeshCore::PointIndex ulPt0 = std::min(rF._aulPoints[i], rF._aulPoints[(i+1)%3]); + MeshCore::PointIndex ulPt1 = std::max(rF._aulPoints[i], rF._aulPoints[(i+1)%3]); + pEdgeToFace[std::pair(ulPt0, ulPt1)].push_front(*pI); } } @@ -1063,26 +1063,26 @@ void MeshProjection::projectEdgeToEdge( const TopoDS_Edge &aEdge, float fMaxDist MeshFacetIterator cFI( _rcMesh ); Base::SequencerLauncher seq( "Project curve on mesh", pEdgeToFace.size() ); - std::map, std::list >::iterator it; + std::map, std::list >::iterator it; for ( it = pEdgeToFace.begin(); it != pEdgeToFace.end(); ++it ) { seq.next(); // edge points - unsigned long uE0 = it->first.first; + MeshCore::PointIndex uE0 = it->first.first; cPI.Set( uE0 ); Base::Vector3f cE0 = *cPI; - unsigned long uE1 = it->first.second; + MeshCore::PointIndex uE1 = it->first.second; cPI.Set( uE1 ); Base::Vector3f cE1 = *cPI; - const std::list& auFaces = it->second; + const std::list& auFaces = it->second; if ( auFaces.size() > 2 ) continue; // non-manifold edge -> don't handle this // if ( clBB.IsOut( gp_Pnt(cE0.x, cE0.y, cE0.z) ) && clBB.IsOut( gp_Pnt(cE1.x, cE1.y, cE1.z) ) ) // continue; Base::Vector3f cEdgeNormal; - for ( std::list::const_iterator itF = auFaces.begin(); itF != auFaces.end(); ++itF ) { + for ( std::list::const_iterator itF = auFaces.begin(); itF != auFaces.end(); ++itF ) { cFI.Set( *itF ); cEdgeNormal += cFI->GetNormal(); } diff --git a/src/Mod/MeshPart/App/CurveProjector.h b/src/Mod/MeshPart/App/CurveProjector.h index 6076971d14..20d2479fea 100644 --- a/src/Mod/MeshPart/App/CurveProjector.h +++ b/src/Mod/MeshPart/App/CurveProjector.h @@ -57,7 +57,7 @@ public: struct FaceSplitEdge { - unsigned long ulFaceIndex; + MeshCore::FacetIndex ulFaceIndex; Base::Vector3f p1,p2; }; @@ -95,7 +95,7 @@ public: void projectCurve(const TopoDS_Edge& aEdge, std::vector &vSplitEdges); - bool findStartPoint(const MeshKernel &MeshK,const Base::Vector3f &Pnt,Base::Vector3f &Rslt,unsigned long &FaceIndex); + bool findStartPoint(const MeshKernel &MeshK,const Base::Vector3f &Pnt,Base::Vector3f &Rslt,MeshCore::FacetIndex &FaceIndex); @@ -121,7 +121,7 @@ public: const std::vector &rclPoints, std::vector &vSplitEdges); - bool findStartPoint(const MeshKernel &MeshK,const Base::Vector3f &Pnt,Base::Vector3f &Rslt,unsigned long &FaceIndex); + bool findStartPoint(const MeshKernel &MeshK,const Base::Vector3f &Pnt,Base::Vector3f &Rslt,MeshCore::FacetIndex &FaceIndex); @@ -162,7 +162,7 @@ public: /// Helper class struct SplitEdge { - unsigned long uE0, uE1; /**< start and endpoint of an edge */ + MeshCore::PointIndex uE0, uE1; /**< start and endpoint of an edge */ Base::Vector3f cPt; /**< Point on edge (\a uE0, \a uE1) */ }; struct Edge diff --git a/src/Mod/MeshPart/App/MeshAlgos.cpp b/src/Mod/MeshPart/App/MeshAlgos.cpp index f7d0b19044..0f1f2439d2 100644 --- a/src/Mod/MeshPart/App/MeshAlgos.cpp +++ b/src/Mod/MeshPart/App/MeshAlgos.cpp @@ -67,7 +67,7 @@ void MeshAlgos::offsetSpecial2(MeshCore::MeshKernel* Mesh, float fSize) Base::Builder3D builder; std::vector PointNormals= Mesh->CalcVertexNormals(); std::vector FaceNormals; - std::set fliped; + std::set fliped; MeshFacetIterator it(*Mesh); for ( it.Init(); it.More(); it.Next() ) @@ -103,7 +103,7 @@ void MeshAlgos::offsetSpecial2(MeshCore::MeshKernel* Mesh, float fSize) if(fliped.size() == 0) break; - for(std::set::iterator It= fliped.begin();It!=fliped.end();++It) + for(std::set::iterator It= fliped.begin();It!=fliped.end();++It) alg.CollapseFacet(*It); fliped.clear(); } @@ -112,7 +112,7 @@ void MeshAlgos::offsetSpecial2(MeshCore::MeshKernel* Mesh, float fSize) // search for intersected facets MeshCore::MeshEvalSelfIntersection eval(*Mesh); - std::vector > faces; + std::vector > faces; eval.GetIntersections(faces); diff --git a/src/Mod/MeshPart/App/Mesher.cpp b/src/Mod/MeshPart/App/Mesher.cpp index a23e048f24..2f51741111 100644 --- a/src/Mod/MeshPart/App/Mesher.cpp +++ b/src/Mod/MeshPart/App/Mesher.cpp @@ -186,7 +186,7 @@ public: Standard_Real x2, y2, z2; Standard_Real x3, y3, z3; - std::vector< std::vector > meshSegments; + std::vector< std::vector > meshSegments; std::size_t numMeshFaces = 0; for (std::size_t i = 0; i < domains.size(); ++i) { @@ -256,8 +256,8 @@ public: // add a segment for the face if (createSegm || this->segments) { - std::vector segment(numDomainFaces); - std::generate(segment.begin(), segment.end(), Base::iotaGen(numMeshFaces)); + std::vector segment(numDomainFaces); + std::generate(segment.begin(), segment.end(), Base::iotaGen(numMeshFaces)); numMeshFaces += numDomainFaces; meshSegments.push_back(segment); } diff --git a/src/Mod/MeshPart/Gui/CurveOnMesh.cpp b/src/Mod/MeshPart/Gui/CurveOnMesh.cpp index 833f8fd06f..1a7aab7f2e 100644 --- a/src/Mod/MeshPart/Gui/CurveOnMesh.cpp +++ b/src/Mod/MeshPart/Gui/CurveOnMesh.cpp @@ -217,7 +217,7 @@ class CurveOnMeshHandler::Private public: struct PickedPoint { - unsigned long facet; + MeshCore::FacetIndex facet; SbVec3f point; SbVec3f normal; }; diff --git a/src/Mod/ReverseEngineering/App/SurfaceTriangulation.cpp b/src/Mod/ReverseEngineering/App/SurfaceTriangulation.cpp index 6cafed46dd..f597cf4fd4 100644 --- a/src/Mod/ReverseEngineering/App/SurfaceTriangulation.cpp +++ b/src/Mod/ReverseEngineering/App/SurfaceTriangulation.cpp @@ -466,7 +466,7 @@ void ImageTriangulation::perform() const MeshCore::MeshFacetArray& face = kernel.GetFacets(); MeshCore::MeshAlgorithm meshAlg(kernel); meshAlg.SetPointFlag(MeshCore::MeshPoint::INVALID); - std::vector validPoints; + std::vector validPoints; validPoints.reserve(face.size()*3); for (MeshCore::MeshFacetArray::_TConstIterator it = face.begin(); it != face.end(); ++it) { validPoints.push_back(it->_aulPoints[0]); @@ -481,7 +481,7 @@ void ImageTriangulation::perform() unsigned long countInvalid = meshAlg.CountPointFlag(MeshCore::MeshPoint::INVALID); if (countInvalid > 0) { - std::vector invalidPoints; + std::vector invalidPoints; invalidPoints.reserve(countInvalid); meshAlg.GetPointsFlag(invalidPoints, MeshCore::MeshPoint::INVALID); diff --git a/src/Mod/ReverseEngineering/Gui/Command.cpp b/src/Mod/ReverseEngineering/Gui/Command.cpp index e954e1d042..e7c7fb9c94 100644 --- a/src/Mod/ReverseEngineering/Gui/Command.cpp +++ b/src/Mod/ReverseEngineering/Gui/Command.cpp @@ -227,8 +227,8 @@ void CmdApproxCylinder::activated(int) // get normals { - std::vector facets(kernel.CountFacets()); - std::generate(facets.begin(), facets.end(), Base::iotaGen(0)); + std::vector facets(kernel.CountFacets()); + std::generate(facets.begin(), facets.end(), Base::iotaGen(0)); std::vector normals = kernel.GetFacetNormals(facets); Base::Vector3f base = fit.GetGravity(); Base::Vector3f axis = fit.GetInitialAxisFromNormals(normals); @@ -460,7 +460,7 @@ void CmdSegmentationFromComponents::activated(int) group->Label.setValue(labelname); const Mesh::MeshObject& mesh = it->Mesh.getValue(); - std::vector > comps = mesh.getComponents(); + std::vector > comps = mesh.getComponents(); for (auto jt : comps) { std::unique_ptr segment(mesh.meshFromSegment(jt)); Mesh::Feature* feaSegm = static_cast(group->addObject("Mesh::Feature", "Segment")); diff --git a/src/Mod/ReverseEngineering/Gui/Segmentation.cpp b/src/Mod/ReverseEngineering/Gui/Segmentation.cpp index ad830963fe..21b6e128c8 100644 --- a/src/Mod/ReverseEngineering/Gui/Segmentation.cpp +++ b/src/Mod/ReverseEngineering/Gui/Segmentation.cpp @@ -111,7 +111,7 @@ void Segmentation::accept() // For each planar segment compute a plane and use this then for a more accurate 2nd segmentation if (strcmp((*it)->GetType(), "Plane") == 0) { for (std::vector::const_iterator jt = data.begin(); jt != data.end(); ++jt) { - std::vector indexes = kernel.GetFacetPoints(*jt); + std::vector indexes = kernel.GetFacetPoints(*jt); MeshCore::PlaneFit fit; fit.AddPoints(kernel.GetPoints(indexes)); if (fit.Fit() < FLOAT_MAX) { @@ -213,7 +213,7 @@ void Segmentation::accept() if (createUnused) { // collect all facets that don't have set the flag TMP0 - std::vector unusedFacets; + std::vector unusedFacets; algo.GetFacetsFlag(unusedFacets, MeshCore::MeshFacet::TMP0); if (!unusedFacets.empty()) { diff --git a/src/Mod/ReverseEngineering/Gui/SegmentationManual.cpp b/src/Mod/ReverseEngineering/Gui/SegmentationManual.cpp index 64b3806283..3176463659 100644 --- a/src/Mod/ReverseEngineering/Gui/SegmentationManual.cpp +++ b/src/Mod/ReverseEngineering/Gui/SegmentationManual.cpp @@ -130,7 +130,8 @@ static void findGeometry(int minFaces, double tolerance, if (mesh.hasSelectedFacets()) { const MeshCore::MeshKernel& kernel = mesh.getKernel(); - std::vector facets, vertexes; + std::vector facets; + std::vector vertexes; mesh.getFacetsFromSelection(facets); vertexes = mesh.getPointsFromFacets(facets); MeshCore::MeshPointArray coords = kernel.GetPoints(vertexes); @@ -244,7 +245,7 @@ void SegmentationManual::createSegment() if (ct > 0) { selected = true; - std::vector facets; + std::vector facets; algo.GetFacetsFlag(facets, MeshCore::MeshFacet::SELECTED); std::unique_ptr segment(mesh.meshFromSegment(facets)); From fa86b0216e2b7348d711d9de089e81171911008c Mon Sep 17 00:00:00 2001 From: wmayer Date: Wed, 15 Sep 2021 14:07:32 +0200 Subject: [PATCH 13/55] Mod: make sure to call the base class' handleChangedPropertyType --- src/Mod/Part/App/FeatureMirroring.cpp | 3 +++ src/Mod/Part/App/Part2DObject.cpp | 3 +++ src/Mod/Part/App/PartFeatures.cpp | 3 +++ src/Mod/Part/Gui/ViewProvider2DObject.cpp | 3 +++ src/Mod/PartDesign/App/FeatureDraft.cpp | 3 +++ src/Mod/PartDesign/App/FeatureHelix.cpp | 3 +++ src/Mod/PartDesign/App/FeatureLinearPattern.cpp | 3 +++ src/Mod/PartDesign/App/FeaturePolarPattern.cpp | 3 +++ src/Mod/PartDesign/App/ShapeBinder.cpp | 8 ++++++-- src/Mod/TechDraw/Gui/ViewProviderBalloon.cpp | 3 +++ src/Mod/TechDraw/Gui/ViewProviderDimension.cpp | 3 +++ src/Mod/TechDraw/Gui/ViewProviderLeader.cpp | 8 ++++++-- src/Mod/TechDraw/Gui/ViewProviderRichAnno.cpp | 8 ++++++-- src/Mod/TechDraw/Gui/ViewProviderViewPart.cpp | 3 +++ 14 files changed, 51 insertions(+), 6 deletions(-) diff --git a/src/Mod/Part/App/FeatureMirroring.cpp b/src/Mod/Part/App/FeatureMirroring.cpp index 7427422b14..b67d585bc3 100644 --- a/src/Mod/Part/App/FeatureMirroring.cpp +++ b/src/Mod/Part/App/FeatureMirroring.cpp @@ -88,6 +88,9 @@ void Mirroring::handleChangedPropertyType(Base::XMLReader &reader, const char *T Normal.setValue(v.getValue()); } + else { + Part::Feature::handleChangedPropertyType(reader, TypeName, prop); + } } App::DocumentObjectExecReturn *Mirroring::execute(void) diff --git a/src/Mod/Part/App/Part2DObject.cpp b/src/Mod/Part/App/Part2DObject.cpp index e26414b592..d91dee9075 100644 --- a/src/Mod/Part/App/Part2DObject.cpp +++ b/src/Mod/Part/App/Part2DObject.cpp @@ -274,6 +274,9 @@ void Part2DObject::handleChangedPropertyType(Base::XMLReader &reader, } this->MapMode.setValue(Attacher::mmFlatFace); } + else { + Part::Feature::handleChangedPropertyType(reader, TypeName, prop); + } } void Part2DObject::handleChangedPropertyName(Base::XMLReader &reader, diff --git a/src/Mod/Part/App/PartFeatures.cpp b/src/Mod/Part/App/PartFeatures.cpp index 86ec1f1cc7..2dc503bdf2 100644 --- a/src/Mod/Part/App/PartFeatures.cpp +++ b/src/Mod/Part/App/PartFeatures.cpp @@ -629,6 +629,9 @@ void Thickness::handleChangedPropertyType(Base::XMLReader &reader, const char *T Value.setValue(v.getValue()); } + else { + Part::Feature::handleChangedPropertyType(reader, TypeName, prop); + } } App::DocumentObjectExecReturn *Thickness::execute(void) diff --git a/src/Mod/Part/Gui/ViewProvider2DObject.cpp b/src/Mod/Part/Gui/ViewProvider2DObject.cpp index b4dc8ca5c2..3c1ad047a4 100644 --- a/src/Mod/Part/Gui/ViewProvider2DObject.cpp +++ b/src/Mod/Part/Gui/ViewProvider2DObject.cpp @@ -305,6 +305,9 @@ void ViewProvider2DObjectGrid::handleChangedPropertyType(Base::XMLReader &reader floatProp.Restore(reader); static_cast(prop)->setValue(floatProp.getValue()); } + else { + ViewProviderPart::handleChangedPropertyType(reader, TypeName, prop); + } } void ViewProvider2DObjectGrid::attach(App::DocumentObject *pcFeat) diff --git a/src/Mod/PartDesign/App/FeatureDraft.cpp b/src/Mod/PartDesign/App/FeatureDraft.cpp index 8c946a741a..a21f797036 100644 --- a/src/Mod/PartDesign/App/FeatureDraft.cpp +++ b/src/Mod/PartDesign/App/FeatureDraft.cpp @@ -88,6 +88,9 @@ void Draft::handleChangedPropertyType(Base::XMLReader &reader, v.Restore(reader); Angle.setValue(v.getValue()); } + else { + DressUp::handleChangedPropertyType(reader, TypeName, prop); + } } short Draft::mustExecute() const diff --git a/src/Mod/PartDesign/App/FeatureHelix.cpp b/src/Mod/PartDesign/App/FeatureHelix.cpp index f8dc38b4d1..a6fdedac22 100644 --- a/src/Mod/PartDesign/App/FeatureHelix.cpp +++ b/src/Mod/PartDesign/App/FeatureHelix.cpp @@ -514,6 +514,9 @@ void Helix::handleChangedPropertyType(Base::XMLReader& reader, const char* TypeN TurnsProperty.Restore(reader); Turns.setValue(TurnsProperty.getValue()); } + else { + ProfileBased::handleChangedPropertyType(reader, TypeName, prop); + } } PROPERTY_SOURCE(PartDesign::AdditiveHelix, PartDesign::Helix) diff --git a/src/Mod/PartDesign/App/FeatureLinearPattern.cpp b/src/Mod/PartDesign/App/FeatureLinearPattern.cpp index 225da7daa8..08ffa89d5b 100644 --- a/src/Mod/PartDesign/App/FeatureLinearPattern.cpp +++ b/src/Mod/PartDesign/App/FeatureLinearPattern.cpp @@ -200,6 +200,9 @@ void LinearPattern::handleChangedPropertyType(Base::XMLReader& reader, const cha OccurrencesProperty.Restore(reader); Occurrences.setValue(OccurrencesProperty.getValue()); } + else { + Transformed::handleChangedPropertyType(reader, TypeName, prop); + } } } diff --git a/src/Mod/PartDesign/App/FeaturePolarPattern.cpp b/src/Mod/PartDesign/App/FeaturePolarPattern.cpp index b5eda35ba8..646216564a 100644 --- a/src/Mod/PartDesign/App/FeaturePolarPattern.cpp +++ b/src/Mod/PartDesign/App/FeaturePolarPattern.cpp @@ -189,6 +189,9 @@ void PolarPattern::handleChangedPropertyType(Base::XMLReader& reader, const char OccurrencesProperty.Restore(reader); Occurrences.setValue(OccurrencesProperty.getValue()); } + else { + Transformed::handleChangedPropertyType(reader, TypeName, prop); + } } } diff --git a/src/Mod/PartDesign/App/ShapeBinder.cpp b/src/Mod/PartDesign/App/ShapeBinder.cpp index b1db1349bc..64d33f19e6 100644 --- a/src/Mod/PartDesign/App/ShapeBinder.cpp +++ b/src/Mod/PartDesign/App/ShapeBinder.cpp @@ -224,6 +224,9 @@ void ShapeBinder::handleChangedPropertyType(Base::XMLReader &reader, const char if (prop == &Support && strcmp(TypeName, "App::PropertyLinkSubList") == 0) { Support.Restore(reader); } + else { + Part::Feature::handleChangedPropertyType(reader, TypeName, prop); + } } void ShapeBinder::onSettingDocument() @@ -727,8 +730,9 @@ void SubShapeBinder::handleChangedPropertyType( { if(prop == &Support) { Support.upgrade(reader,TypeName); - return; } - inherited::handleChangedPropertyType(reader,TypeName,prop); + else { + inherited::handleChangedPropertyType(reader,TypeName,prop); + } } diff --git a/src/Mod/TechDraw/Gui/ViewProviderBalloon.cpp b/src/Mod/TechDraw/Gui/ViewProviderBalloon.cpp index 28450ce266..2d899bbc5d 100644 --- a/src/Mod/TechDraw/Gui/ViewProviderBalloon.cpp +++ b/src/Mod/TechDraw/Gui/ViewProviderBalloon.cpp @@ -195,6 +195,9 @@ void ViewProviderBalloon::handleChangedPropertyType(Base::XMLReader &reader, con LineWidthProperty.Restore(reader); LineWidth.setValue(LineWidthProperty.getValue()); } + else { + ViewProviderDrawingView::handleChangedPropertyType(reader, TypeName, prop); + } } bool ViewProviderBalloon::canDelete(App::DocumentObject *obj) const diff --git a/src/Mod/TechDraw/Gui/ViewProviderDimension.cpp b/src/Mod/TechDraw/Gui/ViewProviderDimension.cpp index 4ab084793f..1000ba7677 100644 --- a/src/Mod/TechDraw/Gui/ViewProviderDimension.cpp +++ b/src/Mod/TechDraw/Gui/ViewProviderDimension.cpp @@ -271,6 +271,9 @@ void ViewProviderDimension::handleChangedPropertyType(Base::XMLReader &reader, c LineWidthProperty.Restore(reader); LineWidth.setValue(LineWidthProperty.getValue()); } + else { + ViewProviderDrawingView::handleChangedPropertyType(reader, TypeName, prop); + } } bool ViewProviderDimension::canDelete(App::DocumentObject *obj) const diff --git a/src/Mod/TechDraw/Gui/ViewProviderLeader.cpp b/src/Mod/TechDraw/Gui/ViewProviderLeader.cpp index 434e89a189..5f4520d03d 100644 --- a/src/Mod/TechDraw/Gui/ViewProviderLeader.cpp +++ b/src/Mod/TechDraw/Gui/ViewProviderLeader.cpp @@ -224,7 +224,7 @@ void ViewProviderLeader::handleChangedPropertyType(Base::XMLReader &reader, cons } // property LineStyle had the App::PropertyInteger and was changed to App::PropertyIntegerConstraint - if (prop == &LineStyle && strcmp(TypeName, "App::PropertyInteger") == 0) { + else if (prop == &LineStyle && strcmp(TypeName, "App::PropertyInteger") == 0) { App::PropertyInteger LineStyleProperty; // restore the PropertyInteger to be able to set its value LineStyleProperty.Restore(reader); @@ -232,12 +232,16 @@ void ViewProviderLeader::handleChangedPropertyType(Base::XMLReader &reader, cons } // property LineStyle had the App::PropertyIntegerConstraint and was changed to App::PropertyEnumeration - if (prop == &LineStyle && strcmp(TypeName, "App::PropertyIntegerConstraint") == 0) { + else if (prop == &LineStyle && strcmp(TypeName, "App::PropertyIntegerConstraint") == 0) { App::PropertyIntegerConstraint LineStyleProperty; // restore the PropertyIntegerConstraint to be able to set its value LineStyleProperty.Restore(reader); LineStyle.setValue(LineStyleProperty.getValue()); } + + else { + ViewProviderDrawingView::handleChangedPropertyType(reader, TypeName, prop); + } } bool ViewProviderLeader::onDelete(const std::vector &) diff --git a/src/Mod/TechDraw/Gui/ViewProviderRichAnno.cpp b/src/Mod/TechDraw/Gui/ViewProviderRichAnno.cpp index d747df5b27..b8d4875ff1 100644 --- a/src/Mod/TechDraw/Gui/ViewProviderRichAnno.cpp +++ b/src/Mod/TechDraw/Gui/ViewProviderRichAnno.cpp @@ -208,7 +208,7 @@ void ViewProviderRichAnno::handleChangedPropertyType(Base::XMLReader &reader, co } // property LineStyle had App::PropertyInteger and was changed to App::PropertyIntegerConstraint - if (prop == &LineStyle && strcmp(TypeName, "App::PropertyInteger") == 0) { + else if (prop == &LineStyle && strcmp(TypeName, "App::PropertyInteger") == 0) { App::PropertyInteger LineStyleProperty; // restore the PropertyInteger to be able to set its value LineStyleProperty.Restore(reader); @@ -216,12 +216,16 @@ void ViewProviderRichAnno::handleChangedPropertyType(Base::XMLReader &reader, co } // property LineStyle had App::PropertyIntegerConstraint and was changed to App::PropertyEnumeration - if (prop == &LineStyle && strcmp(TypeName, "App::PropertyIntegerConstraint") == 0) { + else if (prop == &LineStyle && strcmp(TypeName, "App::PropertyIntegerConstraint") == 0) { App::PropertyIntegerConstraint LineStyleProperty; // restore the PropertyIntegerConstraint to be able to set its value LineStyleProperty.Restore(reader); LineStyle.setValue(LineStyleProperty.getValue()); } + + else { + ViewProviderDrawingView::handleChangedPropertyType(reader, TypeName, prop); + } } bool ViewProviderRichAnno::canDelete(App::DocumentObject *obj) const diff --git a/src/Mod/TechDraw/Gui/ViewProviderViewPart.cpp b/src/Mod/TechDraw/Gui/ViewProviderViewPart.cpp index 6773ccdeda..d6373dd0e2 100644 --- a/src/Mod/TechDraw/Gui/ViewProviderViewPart.cpp +++ b/src/Mod/TechDraw/Gui/ViewProviderViewPart.cpp @@ -334,6 +334,9 @@ void ViewProviderViewPart::handleChangedPropertyType(Base::XMLReader &reader, co ExtraWidthProperty.Restore(reader); ExtraWidth.setValue(ExtraWidthProperty.getValue()); } + else { + ViewProviderDrawingView::handleChangedPropertyType(reader, TypeName, prop); + } } bool ViewProviderViewPart::onDelete(const std::vector &) From 44eeae72868b81ce49bcdb9966a5efcba4543027 Mon Sep 17 00:00:00 2001 From: wmayer Date: Wed, 15 Sep 2021 14:45:50 +0200 Subject: [PATCH 14/55] Part: move handling of changed properties of the Primitive class to handleChangedPropertyName and handleChangedPropertyType --- src/Mod/Part/App/PrimitiveFeature.cpp | 74 +++++++++------------------ src/Mod/Part/App/PrimitiveFeature.h | 2 + 2 files changed, 26 insertions(+), 50 deletions(-) diff --git a/src/Mod/Part/App/PrimitiveFeature.cpp b/src/Mod/Part/App/PrimitiveFeature.cpp index 7240e72e6a..579120daee 100644 --- a/src/Mod/Part/App/PrimitiveFeature.cpp +++ b/src/Mod/Part/App/PrimitiveFeature.cpp @@ -132,59 +132,33 @@ PyObject* Primitive::getPyObject() void Primitive::Restore(Base::XMLReader &reader) { - reader.readElement("Properties"); - int Cnt = reader.getAttributeAsInteger("Count"); + Part::Feature::Restore(reader); +} - for (int i=0 ;igetTypeId().getName(), TypeName) == 0) { - prop->Restore(reader); - } - else if (prop) { - Base::Type inputType = Base::Type::fromName(TypeName); - if (prop->getTypeId().isDerivedFrom(App::PropertyFloat::getClassTypeId()) && - inputType.isDerivedFrom(App::PropertyFloat::getClassTypeId())) { - // Do not directly call the property's Restore method in case the implementation - // has changed. So, create a temporary PropertyFloat object and assign the value. - App::PropertyFloat floatProp; - floatProp.Restore(reader); - static_cast(prop)->setValue(floatProp.getValue()); - } - } - else { - extHandleChangedPropertyName(reader, TypeName, PropName); // AttachExtension - } - } - catch (const Base::XMLParseException&) { - throw; // re-throw - } - catch (const Base::Exception &e) { - Base::Console().Error("%s\n", e.what()); - } - catch (const std::exception &e) { - Base::Console().Error("%s\n", e.what()); - } - catch (const char* e) { - Base::Console().Error("%s\n", e); - } -#ifndef FC_DEBUG - catch (...) { - Base::Console().Error("Primitive::Restore: Unknown C++ exception thrown\n"); - } -#endif +void Primitive::handleChangedPropertyName(Base::XMLReader &reader, const char * TypeName, const char *PropName) +{ + extHandleChangedPropertyName(reader, TypeName, PropName); // AttachExtension +} - reader.readEndElement("Property"); +void Primitive::handleChangedPropertyType(Base::XMLReader &reader, const char * TypeName, App::Property * prop) +{ + // For #0001652 the property types of many primitive features have changed + // from PropertyFloat or PropertyFloatConstraint to a more meaningful type. + // In order to load older project files there must be checked in case the + // types don't match if both inherit from PropertyFloat because all derived + // classes do not re-implement the Save/Restore methods. + Base::Type inputType = Base::Type::fromName(TypeName); + if (prop->getTypeId().isDerivedFrom(App::PropertyFloat::getClassTypeId()) && + inputType.isDerivedFrom(App::PropertyFloat::getClassTypeId())) { + // Do not directly call the property's Restore method in case the implementation + // has changed. So, create a temporary PropertyFloat object and assign the value. + App::PropertyFloat floatProp; + floatProp.Restore(reader); + static_cast(prop)->setValue(floatProp.getValue()); + } + else { + Part::Feature::handleChangedPropertyType(reader, TypeName, prop); } - reader.readEndElement("Properties"); } void Primitive::onChanged(const App::Property* prop) diff --git a/src/Mod/Part/App/PrimitiveFeature.h b/src/Mod/Part/App/PrimitiveFeature.h index e9cd075e72..a873055345 100644 --- a/src/Mod/Part/App/PrimitiveFeature.h +++ b/src/Mod/Part/App/PrimitiveFeature.h @@ -51,6 +51,8 @@ public: protected: void Restore(Base::XMLReader &reader) override; void onChanged (const App::Property* prop) override; + virtual void handleChangedPropertyName(Base::XMLReader &reader, const char * TypeName, const char *PropName) override; + virtual void handleChangedPropertyType(Base::XMLReader &reader, const char * TypeName, App::Property * prop) override; }; class PartExport Vertex : public Part::Primitive From ba2ad05983e547928f03f4536a80f2ce2538b1cf Mon Sep 17 00:00:00 2001 From: wmayer Date: Wed, 15 Sep 2021 15:14:14 +0200 Subject: [PATCH 15/55] PD: move handling of changed properties of the Chamfer/Fillet to handleChangedPropertyType --- src/Mod/PartDesign/App/FeatureChamfer.cpp | 42 ++++++--------------- src/Mod/PartDesign/App/FeatureChamfer.h | 1 + src/Mod/PartDesign/App/FeatureFillet.cpp | 46 +++++++---------------- src/Mod/PartDesign/App/FeatureFillet.h | 2 +- 4 files changed, 28 insertions(+), 63 deletions(-) diff --git a/src/Mod/PartDesign/App/FeatureChamfer.cpp b/src/Mod/PartDesign/App/FeatureChamfer.cpp index f594649e5f..81513332e1 100644 --- a/src/Mod/PartDesign/App/FeatureChamfer.cpp +++ b/src/Mod/PartDesign/App/FeatureChamfer.cpp @@ -196,38 +196,20 @@ App::DocumentObjectExecReturn *Chamfer::execute(void) void Chamfer::Restore(Base::XMLReader &reader) { - reader.readElement("Properties"); - int Cnt = reader.getAttributeAsInteger("Count"); + DressUp::Restore(reader); +} - for (int i=0 ;igetTypeId().getName(), TypeName) == 0) { - prop->Restore(reader); - } - else if (prop && strcmp(TypeName,"App::PropertyFloatConstraint") == 0 && - strcmp(prop->getTypeId().getName(), "App::PropertyQuantityConstraint") == 0) { - App::PropertyFloatConstraint p; - p.Restore(reader); - static_cast(prop)->setValue(p.getValue()); - } - } - catch (const Base::XMLParseException&) { - throw; // re-throw - } - catch (const Base::Exception &e) { - Base::Console().Error("%s\n", e.what()); - } - catch (const std::exception &e) { - Base::Console().Error("%s\n", e.what()); - } - reader.readEndElement("Property"); +void Chamfer::handleChangedPropertyType(Base::XMLReader &reader, const char * TypeName, App::Property * prop) +{ + if (prop && strcmp(TypeName,"App::PropertyFloatConstraint") == 0 && + strcmp(prop->getTypeId().getName(), "App::PropertyQuantityConstraint") == 0) { + App::PropertyFloatConstraint p; + p.Restore(reader); + static_cast(prop)->setValue(p.getValue()); + } + else { + DressUp::handleChangedPropertyType(reader, TypeName, prop); } - reader.readEndElement("Properties"); } void Chamfer::onChanged(const App::Property* prop) diff --git a/src/Mod/PartDesign/App/FeatureChamfer.h b/src/Mod/PartDesign/App/FeatureChamfer.h index e36e708d1d..96536a777c 100644 --- a/src/Mod/PartDesign/App/FeatureChamfer.h +++ b/src/Mod/PartDesign/App/FeatureChamfer.h @@ -62,6 +62,7 @@ public: protected: void Restore(Base::XMLReader &reader) override; + void handleChangedPropertyType(Base::XMLReader &reader, const char * TypeName, App::Property * prop) override; static const App::PropertyQuantityConstraint::Constraints floatSize; static const App::PropertyAngle::Constraints floatAngle; }; diff --git a/src/Mod/PartDesign/App/FeatureFillet.cpp b/src/Mod/PartDesign/App/FeatureFillet.cpp index 646d3fde59..96952fa2a4 100644 --- a/src/Mod/PartDesign/App/FeatureFillet.cpp +++ b/src/Mod/PartDesign/App/FeatureFillet.cpp @@ -134,36 +134,18 @@ App::DocumentObjectExecReturn *Fillet::execute(void) void Fillet::Restore(Base::XMLReader &reader) { - reader.readElement("Properties"); - int Cnt = reader.getAttributeAsInteger("Count"); - - for (int i=0 ;igetTypeId().getName(), TypeName) == 0) { - prop->Restore(reader); - } - else if (prop && strcmp(TypeName,"App::PropertyFloatConstraint") == 0 && - strcmp(prop->getTypeId().getName(), "App::PropertyQuantityConstraint") == 0) { - App::PropertyFloatConstraint p; - p.Restore(reader); - static_cast(prop)->setValue(p.getValue()); - } - } - catch (const Base::XMLParseException&) { - throw; // re-throw - } - catch (const Base::Exception &e) { - Base::Console().Error("%s\n", e.what()); - } - catch (const std::exception &e) { - Base::Console().Error("%s\n", e.what()); - } - reader.readEndElement("Property"); - } - reader.readEndElement("Properties"); + DressUp::Restore(reader); +} + +void Fillet::handleChangedPropertyType(Base::XMLReader &reader, const char * TypeName, App::Property * prop) +{ + if (prop && strcmp(TypeName,"App::PropertyFloatConstraint") == 0 && + strcmp(prop->getTypeId().getName(), "App::PropertyQuantityConstraint") == 0) { + App::PropertyFloatConstraint p; + p.Restore(reader); + static_cast(prop)->setValue(p.getValue()); + } + else { + DressUp::handleChangedPropertyType(reader, TypeName, prop); + } } diff --git a/src/Mod/PartDesign/App/FeatureFillet.h b/src/Mod/PartDesign/App/FeatureFillet.h index 6637040049..e46b5b05bd 100644 --- a/src/Mod/PartDesign/App/FeatureFillet.h +++ b/src/Mod/PartDesign/App/FeatureFillet.h @@ -54,7 +54,7 @@ public: protected: void Restore(Base::XMLReader &reader); - + void handleChangedPropertyType(Base::XMLReader &reader, const char * TypeName, App::Property * prop); }; } //namespace Part From 2af9c5038e899d543f7570d5abf64dc9298af9ae Mon Sep 17 00:00:00 2001 From: wmayer Date: Wed, 15 Sep 2021 15:20:40 +0200 Subject: [PATCH 16/55] PD: move handling of changed properties of Transformed to handleChangedPropertyType --- src/Mod/PartDesign/App/FeatureTransformed.cpp | 63 +++++-------------- src/Mod/PartDesign/App/FeatureTransformed.h | 1 + 2 files changed, 18 insertions(+), 46 deletions(-) diff --git a/src/Mod/PartDesign/App/FeatureTransformed.cpp b/src/Mod/PartDesign/App/FeatureTransformed.cpp index f52d1dfca8..bcde049a73 100644 --- a/src/Mod/PartDesign/App/FeatureTransformed.cpp +++ b/src/Mod/PartDesign/App/FeatureTransformed.cpp @@ -146,54 +146,25 @@ App::DocumentObject* Transformed::getSketchObject() const void Transformed::Restore(Base::XMLReader &reader) { - reader.readElement("Properties"); - int Cnt = reader.getAttributeAsInteger("Count"); + PartDesign::Feature::Restore(reader); +} - for (int i=0 ;igetTypeId().getName(), TypeName) == 0) { - prop->Restore(reader); - } - else if (prop) { - Base::Type inputType = Base::Type::fromName(TypeName); - if (prop->getTypeId().isDerivedFrom(App::PropertyFloat::getClassTypeId()) && - inputType.isDerivedFrom(App::PropertyFloat::getClassTypeId())) { - // Do not directly call the property's Restore method in case the implementation - // has changed. So, create a temporary PropertyFloat object and assign the value. - App::PropertyFloat floatProp; - floatProp.Restore(reader); - static_cast(prop)->setValue(floatProp.getValue()); - } - } - } - catch (const Base::XMLParseException&) { - throw; // re-throw - } - catch (const Base::Exception &e) { - Base::Console().Error("%s\n", e.what()); - } - catch (const std::exception &e) { - Base::Console().Error("%s\n", e.what()); - } - catch (const char* e) { - Base::Console().Error("%s\n", e); - } -#ifndef FC_DEBUG - catch (...) { - Base::Console().Error("Primitive::Restore: Unknown C++ exception thrown\n"); - } -#endif - - reader.readEndElement("Property"); +void Transformed::handleChangedPropertyType(Base::XMLReader &reader, const char * TypeName, App::Property * prop) +{ + // The property 'Angle' of PolarPattern has changed from PropertyFloat + // to PropertyAngle and the property 'Length' has changed to PropertyLength. + Base::Type inputType = Base::Type::fromName(TypeName); + if (prop->getTypeId().isDerivedFrom(App::PropertyFloat::getClassTypeId()) && + inputType.isDerivedFrom(App::PropertyFloat::getClassTypeId())) { + // Do not directly call the property's Restore method in case the implementation + // has changed. So, create a temporary PropertyFloat object and assign the value. + App::PropertyFloat floatProp; + floatProp.Restore(reader); + static_cast(prop)->setValue(floatProp.getValue()); + } + else { + PartDesign::Feature::handleChangedPropertyType(reader, TypeName, prop); } - reader.readEndElement("Properties"); } short Transformed::mustExecute() const diff --git a/src/Mod/PartDesign/App/FeatureTransformed.h b/src/Mod/PartDesign/App/FeatureTransformed.h index e306871497..6907288c98 100644 --- a/src/Mod/PartDesign/App/FeatureTransformed.h +++ b/src/Mod/PartDesign/App/FeatureTransformed.h @@ -90,6 +90,7 @@ public: protected: void Restore(Base::XMLReader &reader); + void handleChangedPropertyType(Base::XMLReader &reader, const char * TypeName, App::Property * prop); virtual void positionBySupport(void); TopoDS_Shape refineShapeIfActive(const TopoDS_Shape&) const; void divideTools(const std::vector &toolsIn, std::vector &individualsOut, From fff27ee78b738483eb8e4e2ad5ce07014828aacb Mon Sep 17 00:00:00 2001 From: wmayer Date: Wed, 15 Sep 2021 15:45:24 +0200 Subject: [PATCH 17/55] PD: fix ProfileBased::Restore to not affect sub-classes that need to handle changed property types/names --- src/Mod/PartDesign/App/FeatureSketchBased.cpp | 81 +++++++------------ src/Mod/PartDesign/App/FeatureSketchBased.h | 1 + 2 files changed, 29 insertions(+), 53 deletions(-) diff --git a/src/Mod/PartDesign/App/FeatureSketchBased.cpp b/src/Mod/PartDesign/App/FeatureSketchBased.cpp index a0db850e05..05a7fc77b3 100644 --- a/src/Mod/PartDesign/App/FeatureSketchBased.cpp +++ b/src/Mod/PartDesign/App/FeatureSketchBased.cpp @@ -1196,57 +1196,32 @@ Base::Vector3d ProfileBased::getProfileNormal() const { return SketchVector; } - -void ProfileBased::Restore(Base::XMLReader& reader) { - - reader.readElement("Properties"); - int Cnt = reader.getAttributeAsInteger("Count"); - - for (int i=0 ;i vec; - // read my element - reader.readElement("Link"); - // get the value of my attribute - std::string name = reader.getAttribute("value"); - - if (name != "") { - App::Document* document = getDocument(); - DocumentObject* object = document ? document->getObject(name.c_str()) : 0; - Profile.setValue(object, vec); - } - else { - Profile.setValue(0, vec); - } - } - else if (prop && strcmp(prop->getTypeId().getName(), TypeName) == 0) - prop->Restore(reader); - } - catch (const Base::XMLParseException&) { - throw; // re-throw - } - catch (const Base::Exception &e) { - Base::Console().Error("%s\n", e.what()); - } - catch (const std::exception &e) { - Base::Console().Error("%s\n", e.what()); - } - catch (const char* e) { - Base::Console().Error("%s\n", e); - } - - reader.readEndElement("Property"); - } - reader.readEndElement("Properties"); +void ProfileBased::Restore(Base::XMLReader& reader) +{ + PartDesign::FeatureAddSub::Restore(reader); +} + +void ProfileBased::handleChangedPropertyName(Base::XMLReader &reader, const char * TypeName, const char *PropName) +{ + //check if we load the old sketch property + if ((strcmp("Sketch", PropName) == 0) && (strcmp("App::PropertyLink", TypeName) == 0)) { + + std::vector vec; + // read my element + reader.readElement("Link"); + // get the value of my attribute + std::string name = reader.getAttribute("value"); + + if (name != "") { + App::Document* document = getDocument(); + DocumentObject* object = document ? document->getObject(name.c_str()) : 0; + Profile.setValue(object, vec); + } + else { + Profile.setValue(0, vec); + } + } + else { + PartDesign::FeatureAddSub::handleChangedPropertyName(reader, TypeName, PropName); + } } diff --git a/src/Mod/PartDesign/App/FeatureSketchBased.h b/src/Mod/PartDesign/App/FeatureSketchBased.h index 17a5659287..bf3c1964d1 100644 --- a/src/Mod/PartDesign/App/FeatureSketchBased.h +++ b/src/Mod/PartDesign/App/FeatureSketchBased.h @@ -112,6 +112,7 @@ public: //backwards compatibility: profile property was renamed and has different type now virtual void Restore(Base::XMLReader& reader); + virtual void handleChangedPropertyName(Base::XMLReader &reader, const char * TypeName, const char *PropName); // calculate the through all length double getThroughAllLength() const; From 909030859df2f0b938e1a38c80820619c8592702 Mon Sep 17 00:00:00 2001 From: luz paz Date: Tue, 14 Sep 2021 17:29:11 -0400 Subject: [PATCH 18/55] PD: Fix typo in function getContiniusEdges->getContinuousEdges Related to PR #5029 --- src/Mod/PartDesign/App/FeatureChamfer.cpp | 2 +- src/Mod/PartDesign/App/FeatureDressUp.cpp | 2 +- src/Mod/PartDesign/App/FeatureDressUp.h | 2 +- src/Mod/PartDesign/App/FeatureFillet.cpp | 2 +- src/Mod/PartDesign/App/FeaturePipe.cpp | 4 ++-- src/Mod/PartDesign/App/FeaturePipe.h | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Mod/PartDesign/App/FeatureChamfer.cpp b/src/Mod/PartDesign/App/FeatureChamfer.cpp index 81513332e1..24c20482c1 100644 --- a/src/Mod/PartDesign/App/FeatureChamfer.cpp +++ b/src/Mod/PartDesign/App/FeatureChamfer.cpp @@ -115,7 +115,7 @@ App::DocumentObjectExecReturn *Chamfer::execute(void) } std::vector SubNames = std::vector(Base.getSubValues()); - getContiniusEdges(TopShape, SubNames); + getContinuousEdges(TopShape, SubNames); if (SubNames.size() == 0) return new App::DocumentObjectExecReturn("No edges specified"); diff --git a/src/Mod/PartDesign/App/FeatureDressUp.cpp b/src/Mod/PartDesign/App/FeatureDressUp.cpp index dc16fb2ef4..67daa010d1 100644 --- a/src/Mod/PartDesign/App/FeatureDressUp.cpp +++ b/src/Mod/PartDesign/App/FeatureDressUp.cpp @@ -97,7 +97,7 @@ Part::Feature *DressUp::getBaseObject(bool silent) const return rv; } -void DressUp::getContiniusEdges(Part::TopoShape TopShape, std::vector< std::string >& SubNames) { +void DressUp::getContinuousEdges(Part::TopoShape TopShape, std::vector< std::string >& SubNames) { TopTools_IndexedMapOfShape mapOfEdges; TopTools_IndexedDataMapOfShapeListOfShape mapEdgeFace; diff --git a/src/Mod/PartDesign/App/FeatureDressUp.h b/src/Mod/PartDesign/App/FeatureDressUp.h index be22b3399e..61831ee8e8 100644 --- a/src/Mod/PartDesign/App/FeatureDressUp.h +++ b/src/Mod/PartDesign/App/FeatureDressUp.h @@ -58,7 +58,7 @@ public: virtual Part::Feature* getBaseObject(bool silent=false) const; /// extracts all edges from the subshapes (including face edges) and furthermore adds /// all C0 continuous edges to the vector - void getContiniusEdges(Part::TopoShape, std::vector< std::string >&); + void getContinuousEdges(Part::TopoShape, std::vector< std::string >&); virtual void getAddSubShape(Part::TopoShape &addShape, Part::TopoShape &subShape); diff --git a/src/Mod/PartDesign/App/FeatureFillet.cpp b/src/Mod/PartDesign/App/FeatureFillet.cpp index 96952fa2a4..5f2d52c4d0 100644 --- a/src/Mod/PartDesign/App/FeatureFillet.cpp +++ b/src/Mod/PartDesign/App/FeatureFillet.cpp @@ -74,7 +74,7 @@ App::DocumentObjectExecReturn *Fillet::execute(void) return new App::DocumentObjectExecReturn(e.what()); } std::vector SubNames = std::vector(Base.getSubValues()); - getContiniusEdges(TopShape, SubNames); + getContinuousEdges(TopShape, SubNames); if (SubNames.size() == 0) return new App::DocumentObjectExecReturn("Fillet not possible on selected shapes"); diff --git a/src/Mod/PartDesign/App/FeaturePipe.cpp b/src/Mod/PartDesign/App/FeaturePipe.cpp index fa25ac00eb..dfd410d0ad 100644 --- a/src/Mod/PartDesign/App/FeaturePipe.cpp +++ b/src/Mod/PartDesign/App/FeaturePipe.cpp @@ -401,7 +401,7 @@ void Pipe::setupAlgorithm(BRepOffsetAPI_MakePipeShell& mkPipeShell, TopoDS_Shape } -void Pipe::getContiniusEdges(Part::TopoShape /*TopShape*/, std::vector< std::string >& /*SubNames*/) { +void Pipe::getContinuousEdges(Part::TopoShape /*TopShape*/, std::vector< std::string >& /*SubNames*/) { /* TopTools_IndexedMapOfShape mapOfEdges; @@ -458,7 +458,7 @@ void Pipe::buildPipePath(const Part::TopoShape& shape, const std::vector< std::s try { if (!subedge.empty()) { //if(SpineTangent.getValue()) - //getContiniusEdges(shape, subedge); + //getContinuousEdges(shape, subedge); BRepBuilderAPI_MakeWire mkWire; for (std::vector::const_iterator it = subedge.begin(); it != subedge.end(); ++it) { diff --git a/src/Mod/PartDesign/App/FeaturePipe.h b/src/Mod/PartDesign/App/FeaturePipe.h index 9fbf90df01..9b1f937788 100644 --- a/src/Mod/PartDesign/App/FeaturePipe.h +++ b/src/Mod/PartDesign/App/FeaturePipe.h @@ -60,7 +60,7 @@ public: protected: ///get the given edges and all their tangent ones - void getContiniusEdges(Part::TopoShape TopShape, std::vector< std::string >& SubNames); + void getContinuousEdges(Part::TopoShape TopShape, std::vector< std::string >& SubNames); void buildPipePath(const Part::TopoShape& input, const std::vector& edges, TopoDS_Shape& result); void setupAlgorithm(BRepOffsetAPI_MakePipeShell& mkPipeShell, TopoDS_Shape& auxshape); From 85a84a71767926a174b9703b77680ed76bede3e1 Mon Sep 17 00:00:00 2001 From: Roy-043 <70520633+Roy-043@users.noreply.github.com> Date: Wed, 15 Sep 2021 17:08:09 +0200 Subject: [PATCH 19/55] TechDraw: Changed "TechDraw_Dimension_Link" -> "TechDraw_LinkDimension" (#5032) * Update and rename TechDraw_Dimension_Link.svg to TechDraw_LinkDimension.svg Icon name should match the command name. --- src/Mod/TechDraw/Gui/CommandCreateDims.cpp | 4 ++-- src/Mod/TechDraw/Gui/Resources/TechDraw.qrc | 2 +- ...chDraw_Dimension_Link.svg => TechDraw_LinkDimension.svg} | 6 +++--- src/Mod/TechDraw/Gui/TaskLinkDim.cpp | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) rename src/Mod/TechDraw/Gui/Resources/icons/{TechDraw_Dimension_Link.svg => TechDraw_LinkDimension.svg} (99%) diff --git a/src/Mod/TechDraw/Gui/CommandCreateDims.cpp b/src/Mod/TechDraw/Gui/CommandCreateDims.cpp index cdadc5ecb8..ed3de2b190 100644 --- a/src/Mod/TechDraw/Gui/CommandCreateDims.cpp +++ b/src/Mod/TechDraw/Gui/CommandCreateDims.cpp @@ -976,9 +976,9 @@ CmdTechDrawLinkDimension::CmdTechDrawLinkDimension() sGroup = QT_TR_NOOP("TechDraw"); sMenuText = QT_TR_NOOP("Link Dimension to 3D Geometry"); sToolTipText = sMenuText; - sWhatsThis = "TechDraw_Dimension_Link"; + sWhatsThis = "TechDraw_LinkDimension"; sStatusTip = sToolTipText; - sPixmap = "TechDraw_Dimension_Link"; + sPixmap = "TechDraw_LinkDimension"; } void CmdTechDrawLinkDimension::activated(int iMsg) diff --git a/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc b/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc index ebc5c28142..96becf9604 100644 --- a/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc +++ b/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc @@ -36,7 +36,7 @@ icons/TechDraw_RadiusDimension.svg icons/TechDraw_Balloon.svg icons/TechDraw_VerticalDimension.svg - icons/TechDraw_Dimension_Link.svg + icons/TechDraw_LinkDimension.svg icons/TechDraw_HorizontalExtentDimension.svg icons/TechDraw_VerticalExtentDimension.svg icons/techdraw-landmarkdistance.svg diff --git a/src/Mod/TechDraw/Gui/Resources/icons/TechDraw_Dimension_Link.svg b/src/Mod/TechDraw/Gui/Resources/icons/TechDraw_LinkDimension.svg similarity index 99% rename from src/Mod/TechDraw/Gui/Resources/icons/TechDraw_Dimension_Link.svg rename to src/Mod/TechDraw/Gui/Resources/icons/TechDraw_LinkDimension.svg index fec78eb2d3..3fb249fc93 100644 --- a/src/Mod/TechDraw/Gui/Resources/icons/TechDraw_Dimension_Link.svg +++ b/src/Mod/TechDraw/Gui/Resources/icons/TechDraw_LinkDimension.svg @@ -15,7 +15,7 @@ height="64" id="svg5821" inkscape:version="0.48.5 r10040" - sodipodi:docname="TechDraw_Dimension_Link.svg"> + sodipodi:docname="TechDraw_LinkDimension.svg"> [WandererFan] - TechDraw_Dimension_Link + TechDraw_LinkDimension 2016-04-27 http://www.freecadweb.org/wiki/index.php?title=Artwork @@ -259,7 +259,7 @@ FreeCAD - FreeCAD/src/Mod/TechDraw/Gui/Resources/icons/TechDraw_Dimension_Link.svg + FreeCAD/src/Mod/TechDraw/Gui/Resources/icons/TechDraw_LinkDimension.svg FreeCAD LGPL2+ diff --git a/src/Mod/TechDraw/Gui/TaskLinkDim.cpp b/src/Mod/TechDraw/Gui/TaskLinkDim.cpp index 560a214212..6f398c262e 100644 --- a/src/Mod/TechDraw/Gui/TaskLinkDim.cpp +++ b/src/Mod/TechDraw/Gui/TaskLinkDim.cpp @@ -265,7 +265,7 @@ TaskDlgLinkDim::TaskDlgLinkDim(std::vector parts,std::vect TaskDialog() { widget = new TaskLinkDim(parts,subs,page); - taskbox = new Gui::TaskView::TaskBox(Gui::BitmapFactory().pixmap("TechDraw_Dimension_Link"), + taskbox = new Gui::TaskView::TaskBox(Gui::BitmapFactory().pixmap("TechDraw_LinkDimension"), widget->windowTitle(), true, 0); taskbox->groupLayout()->addWidget(widget); Content.push_back(taskbox); From 703b824526ff3d70cf30463174e59a8d7c5115b2 Mon Sep 17 00:00:00 2001 From: wmayer Date: Wed, 15 Sep 2021 17:09:54 +0200 Subject: [PATCH 20/55] MeshPart: show a more useful error message if the currently selected object cannot be tessellated --- src/Mod/MeshPart/Gui/Tessellation.cpp | 28 ++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/src/Mod/MeshPart/Gui/Tessellation.cpp b/src/Mod/MeshPart/Gui/Tessellation.cpp index aa343fc07b..2c01789194 100644 --- a/src/Mod/MeshPart/Gui/Tessellation.cpp +++ b/src/Mod/MeshPart/Gui/Tessellation.cpp @@ -44,7 +44,7 @@ #include #include #include -#include +#include #include #include @@ -222,16 +222,38 @@ bool Tessellation::accept() this->document = QString::fromLatin1(activeDoc->getName()); + bool bodyWithNoTip = false; + bool partWithNoFace = false; for (auto &sel : Gui::Selection().getSelection("*",0)) { auto shape = Part::Feature::getTopoShape(sel.pObject,sel.SubName); if (shape.hasSubShape(TopAbs_FACE)) { shapeObjects.emplace_back(sel.pObject, sel.SubName); } + else if (sel.pObject) { + if (sel.pObject->isDerivedFrom(Part::Feature::getClassTypeId())) { + partWithNoFace = true; + } + if (sel.pObject->isDerivedFrom(Part::BodyBase::getClassTypeId())) { + Part::BodyBase* body = static_cast(sel.pObject); + if (!body->Tip.getValue()) { + bodyWithNoTip = true; + } + } + } } if (shapeObjects.empty()) { - QMessageBox::critical(this, windowTitle(), - tr("Select a shape for meshing, first.")); + if (bodyWithNoTip) { + QMessageBox::critical(this, windowTitle(), tr("You have selected a body without tip.\n" + "Either set the tip of the body or select a different shape, please.")); + } + else if (partWithNoFace) { + QMessageBox::critical(this, windowTitle(), tr("You have selected a shape without faces.\n" + "Select a different shape, please.")); + } + else { + QMessageBox::critical(this, windowTitle(), tr("Select a shape for meshing, first.")); + } return false; } From 614e247dff3fd97659da98bdf2e0493302d281e5 Mon Sep 17 00:00:00 2001 From: wmayer Date: Thu, 16 Sep 2021 12:43:32 +0200 Subject: [PATCH 21/55] Part: support null shapes in boolean operations --- src/Mod/Part/App/TopoShape.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Mod/Part/App/TopoShape.cpp b/src/Mod/Part/App/TopoShape.cpp index a714012221..887a798be2 100644 --- a/src/Mod/Part/App/TopoShape.cpp +++ b/src/Mod/Part/App/TopoShape.cpp @@ -1812,9 +1812,9 @@ bool TopoShape::isClosed() const TopoDS_Shape TopoShape::cut(TopoDS_Shape shape) const { if (this->_Shape.IsNull()) - Standard_Failure::Raise("Base shape is null"); + return this->_Shape; if (shape.IsNull()) - Standard_Failure::Raise("Tool shape is null"); + return this->_Shape; BRepAlgoAPI_Cut mkCut(this->_Shape, shape); return makeShell(mkCut.Shape()); } @@ -1822,7 +1822,7 @@ TopoDS_Shape TopoShape::cut(TopoDS_Shape shape) const TopoDS_Shape TopoShape::cut(const std::vector& shapes, Standard_Real tolerance) const { if (this->_Shape.IsNull()) - Standard_Failure::Raise("Base shape is null"); + return this->_Shape; #if OCC_VERSION_HEX < 0x060900 (void)shapes; (void)tolerance; @@ -1858,9 +1858,9 @@ TopoDS_Shape TopoShape::cut(const std::vector& shapes, Standard_Re TopoDS_Shape TopoShape::common(TopoDS_Shape shape) const { if (this->_Shape.IsNull()) - Standard_Failure::Raise("Base shape is null"); + return this->_Shape; if (shape.IsNull()) - Standard_Failure::Raise("Tool shape is null"); + return shape; BRepAlgoAPI_Common mkCommon(this->_Shape, shape); return makeShell(mkCommon.Shape()); } @@ -1868,7 +1868,7 @@ TopoDS_Shape TopoShape::common(TopoDS_Shape shape) const TopoDS_Shape TopoShape::common(const std::vector& shapes, Standard_Real tolerance) const { if (this->_Shape.IsNull()) - Standard_Failure::Raise("Base shape is null"); + return this->_Shape; #if OCC_VERSION_HEX < 0x060900 (void)shapes; (void)tolerance; @@ -1904,9 +1904,9 @@ TopoDS_Shape TopoShape::common(const std::vector& shapes, Standard TopoDS_Shape TopoShape::fuse(TopoDS_Shape shape) const { if (this->_Shape.IsNull()) - Standard_Failure::Raise("Base shape is null"); + return shape; if (shape.IsNull()) - Standard_Failure::Raise("Tool shape is null"); + return this->_Shape; BRepAlgoAPI_Fuse mkFuse(this->_Shape, shape); return makeShell(mkFuse.Shape()); } From 5694f08f1546b2e8bccb9869976a3bc93d4cc6ac Mon Sep 17 00:00:00 2001 From: wmayer Date: Thu, 16 Sep 2021 17:31:45 +0200 Subject: [PATCH 22/55] Mesh: add function section() to Mesh class --- src/Mod/Mesh/App/Core/SetOperations.cpp | 229 ++++++++++++++++++++++++ src/Mod/Mesh/App/Core/SetOperations.h | 48 +++++ src/Mod/Mesh/App/Mesh.cpp | 38 ++++ src/Mod/Mesh/App/Mesh.h | 1 + src/Mod/Mesh/App/MeshPy.xml | 9 +- src/Mod/Mesh/App/MeshPyImp.cpp | 26 +++ 6 files changed, 350 insertions(+), 1 deletion(-) diff --git a/src/Mod/Mesh/App/Core/SetOperations.cpp b/src/Mod/Mesh/App/Core/SetOperations.cpp index 244b424228..463b6fb620 100644 --- a/src/Mod/Mesh/App/Core/SetOperations.cpp +++ b/src/Mod/Mesh/App/Core/SetOperations.cpp @@ -618,3 +618,232 @@ bool SetOperations::CollectFacetVisitor::AllowVisit (const MeshFacet& rclFacet, return true; } + +// ---------------------------------------------------------------------------- + +bool MeshIntersection::hasIntersection() const +{ + Base::BoundBox3f bbox1 = kernel1.GetBoundBox(); + Base::BoundBox3f bbox2 = kernel2.GetBoundBox(); + if (!(bbox1 && bbox2)) + return false; + + if (testIntersection(kernel1, kernel2)) + return true; + + return false; +} + +void MeshIntersection::getIntersection(std::list& intsct) const +{ + const MeshKernel& k1 = kernel1; + const MeshKernel& k2 = kernel2; + + // Contains bounding boxes for every facet of 'k1' + std::vector boxes1; + MeshFacetIterator cMFI1(k1); + for (cMFI1.Begin(); cMFI1.More(); cMFI1.Next()) { + boxes1.push_back((*cMFI1).GetBoundBox()); + } + + // Contains bounding boxes for every facet of 'k2' + std::vector boxes2; + MeshFacetIterator cMFI2(k2); + for (cMFI2.Begin(); cMFI2.More(); cMFI2.Next()) { + boxes2.push_back((*cMFI2).GetBoundBox()); + } + + // Splits the mesh using grid for speeding up the calculation + MeshFacetGrid cMeshFacetGrid(k1); + + const MeshFacetArray& rFaces2 = k2.GetFacets(); + Base::SequencerLauncher seq("Checking for intersections...", rFaces2.size()); + int index = 0; + MeshGeomFacet facet1, facet2; + Base::Vector3f pt1, pt2; + + // Iterate over the facets of the 2nd mesh and find the grid elements of the 1st mesh + for (MeshFacetArray::_TConstIterator it = rFaces2.begin(); it != rFaces2.end(); ++it, index++) { + seq.next(); + std::vector elements; + cMeshFacetGrid.Inside(boxes2[index], elements, true); + + cMFI2.Set(index); + facet2 = *cMFI2; + + for (std::vector::iterator jt = elements.begin(); jt != elements.end(); ++jt) { + if (boxes2[index] && boxes1[*jt]) { + cMFI1.Set(*jt); + facet1 = *cMFI1; + int ret = facet1.IntersectWithFacet(facet2, pt1, pt2); + if (ret == 2) { + Tuple d; + d.p1 = pt1; + d.p2 = pt2; + d.f1 = *jt; + d.f2 = index; + intsct.push_back(d); + } + } + } + } +} + +bool MeshIntersection::testIntersection(const MeshKernel& k1, + const MeshKernel& k2) +{ + // Contains bounding boxes for every facet of 'k1' + std::vector boxes1; + MeshFacetIterator cMFI1(k1); + for (cMFI1.Begin(); cMFI1.More(); cMFI1.Next()) { + boxes1.push_back((*cMFI1).GetBoundBox()); + } + + // Contains bounding boxes for every facet of 'k2' + std::vector boxes2; + MeshFacetIterator cMFI2(k2); + for (cMFI2.Begin(); cMFI2.More(); cMFI2.Next()) { + boxes2.push_back((*cMFI2).GetBoundBox()); + } + + // Splits the mesh using grid for speeding up the calculation + MeshFacetGrid cMeshFacetGrid(k1); + + const MeshFacetArray& rFaces2 = k2.GetFacets(); + Base::SequencerLauncher seq("Checking for intersections...", rFaces2.size()); + int index = 0; + MeshGeomFacet facet1, facet2; + Base::Vector3f pt1, pt2; + + // Iterate over the facets of the 2nd mesh and find the grid elements of the 1st mesh + for (MeshFacetArray::_TConstIterator it = rFaces2.begin(); it != rFaces2.end(); ++it, index++) { + seq.next(); + std::vector elements; + cMeshFacetGrid.Inside(boxes2[index], elements, true); + + cMFI2.Set(index); + facet2 = *cMFI2; + + for (std::vector::iterator jt = elements.begin(); jt != elements.end(); ++jt) { + if (boxes2[index] && boxes1[*jt]) { + cMFI1.Set(*jt); + facet1 = *cMFI1; + int ret = facet1.IntersectWithFacet(facet2, pt1, pt2); + if (ret == 2) { + // abort after the first detected self-intersection + return true; + } + } + } + } + + return false; +} + +void MeshIntersection::connectLines(bool onlyclosed, const std::list& rdata, + std::list< std::list >& lines) +{ + float fMinEps = minDistance * minDistance; + + std::list data = rdata; + while (!data.empty()) { + std::list::iterator pF; + std::list newPoly; + + // add first line and delete from the list + Triple front, back; + front.f1 = data.begin()->f1; + front.f2 = data.begin()->f2; + front.p = data.begin()->p1; // current start point of the polyline + back.f1 = data.begin()->f1; + back.f2 = data.begin()->f2; + back.p = data.begin()->p2; // current end point of the polyline + newPoly.push_back(front); + newPoly.push_back(back); + data.erase(data.begin()); + + // search for the next line on the begin/end of the polyline and add it + std::list::iterator pFront, pEnd; + bool bFoundLine; + do { + float fFrontMin = fMinEps, fEndMin = fMinEps; + bool bFrontFirst=false, bEndFirst=false; + + pFront = data.end(); + pEnd = data.end(); + bFoundLine = false; + + for (pF = data.begin(); pF != data.end(); ++pF) { + if (Base::DistanceP2(front.p, pF->p1) < fFrontMin) { + fFrontMin = Base::DistanceP2(front.p, pF->p1); + pFront = pF; + bFrontFirst = true; + } + else if (Base::DistanceP2(back.p, pF->p1) < fEndMin) { + fEndMin = Base::DistanceP2(back.p, pF->p1); + pEnd = pF; + bEndFirst = true; + } + else if (Base::DistanceP2(front.p, pF->p2) < fFrontMin) { + fFrontMin = Base::DistanceP2(front.p, pF->p2); + pFront = pF; + bFrontFirst = false; + } + else if (Base::DistanceP2(back.p, pF->p2) < fEndMin) { + fEndMin = Base::DistanceP2(back.p, pF->p2); + pEnd = pF; + bEndFirst = false; + } + + if (fFrontMin == 0.0f || fEndMin == 0.0f) { + break; + } + } + + if (pFront != data.end()) { + bFoundLine = true; + if (bFrontFirst) { + front.f1 = pFront->f1; + front.f2 = pFront->f2; + front.p = pFront->p2; + newPoly.push_front(front); + } + else { + front.f1 = pFront->f1; + front.f2 = pFront->f2; + front.p = pFront->p1; + newPoly.push_front(front); + } + + data.erase(pFront); + } + + if (pEnd != data.end()) { + bFoundLine = true; + if (bEndFirst) { + back.f1 = pEnd->f1; + back.f2 = pEnd->f2; + back.p = pEnd->p2; + newPoly.push_back(back); + } + else { + back.f1 = pEnd->f1; + back.f2 = pEnd->f2; + back.p = pEnd->p1; + newPoly.push_back(back); + } + + data.erase(pEnd); + } + } + while (bFoundLine); + + if (onlyclosed) { + if (newPoly.size() > 2 && Base::DistanceP2(newPoly.front().p, newPoly.back().p) < fMinEps) + lines.push_back(newPoly); + } + else { + lines.push_back(newPoly); + } + } +} diff --git a/src/Mod/Mesh/App/Core/SetOperations.h b/src/Mod/Mesh/App/Core/SetOperations.h index 6ec708f443..d83cc4f362 100644 --- a/src/Mod/Mesh/App/Core/SetOperations.h +++ b/src/Mod/Mesh/App/Core/SetOperations.h @@ -184,6 +184,54 @@ private: }; +/*! + Determine the intersections between two meshes. +*/ +class MeshExport MeshIntersection +{ +public: + struct Tuple { + Base::Vector3f p1, p2; + FacetIndex f1, f2; + }; + struct Triple { + Base::Vector3f p; + FacetIndex f1, f2; + }; + struct Pair { + Base::Vector3f p; + FacetIndex f; + }; + + MeshIntersection(const MeshKernel& m1, + const MeshKernel& m2, + float dist) + : kernel1(m1) + , kernel2(m2) + , minDistance(dist) + { + } + ~MeshIntersection() + { + } + + bool hasIntersection() const; + void getIntersection(std::list&) const; + /*! + From an unsorted list of intersection points make a list of sorted intersection points. If parameter \a onlyclosed + is set to true then only closed intersection curves are taken and all other curves are filtered out. + */ + void connectLines(bool onlyclosed, const std::list&, std::list< std::list >&); + +private: + static bool testIntersection(const MeshKernel& k1, const MeshKernel& k2); + +private: + const MeshKernel& kernel1; + const MeshKernel& kernel2; + float minDistance; +}; + } // namespace MeshCore diff --git a/src/Mod/Mesh/App/Mesh.cpp b/src/Mod/Mesh/App/Mesh.cpp index 5c45b0e641..1ba161800f 100644 --- a/src/Mod/Mesh/App/Mesh.cpp +++ b/src/Mod/Mesh/App/Mesh.cpp @@ -1176,6 +1176,44 @@ MeshObject* MeshObject::outer(const MeshObject& mesh) const return new MeshObject(result); } +std::vector< std::vector > +MeshObject::section(const MeshObject& mesh, bool connectLines, float fMinDist) const +{ + MeshCore::MeshKernel kernel1(this->_kernel); + kernel1.Transform(this->_Mtrx); + MeshCore::MeshKernel kernel2(mesh._kernel); + kernel2.Transform(mesh._Mtrx); + std::vector< std::vector > lines; + + MeshCore::MeshIntersection sec(kernel1, kernel2, fMinDist); + std::list tuple; + sec.getIntersection(tuple); + + if (!connectLines) { + for (const auto& it : tuple) { + std::vector curve; + curve.push_back(it.p1); + curve.push_back(it.p2); + lines.push_back(curve); + } + } + else { + std::list< std::list > triple; + sec.connectLines(false, tuple, triple); + + for (const auto& it : triple) { + std::vector curve; + curve.reserve(it.size()); + + for (const auto& jt : it) + curve.push_back(jt.p); + lines.push_back(curve); + } + } + + return lines; +} + void MeshObject::refine() { unsigned long cnt = _kernel.CountFacets(); diff --git a/src/Mod/Mesh/App/Mesh.h b/src/Mod/Mesh/App/Mesh.h index c8b73515d5..4ca1df4565 100644 --- a/src/Mod/Mesh/App/Mesh.h +++ b/src/Mod/Mesh/App/Mesh.h @@ -252,6 +252,7 @@ public: MeshObject* subtract(const MeshObject&) const; MeshObject* inner(const MeshObject&) const; MeshObject* outer(const MeshObject&) const; + std::vector< std::vector > section(const MeshObject&, bool connectLines, float fMinDist) const; //@} /** @name Topological operations */ diff --git a/src/Mod/Mesh/App/MeshPy.xml b/src/Mod/Mesh/App/MeshPy.xml index fdaad6cf92..4469c29af1 100644 --- a/src/Mod/Mesh/App/MeshPy.xml +++ b/src/Mod/Mesh/App/MeshPy.xml @@ -91,7 +91,14 @@ mesh.write(Stream=file,Format='STL',[Name='Object name',Material=colors])Get the part outside the intersection - + + + Get the section curves of this and the given mesh object. +lines = mesh.section(mesh2, [ConnectLines=True, MinDist=0.0001]) + + + + Coarse the mesh diff --git a/src/Mod/Mesh/App/MeshPyImp.cpp b/src/Mod/Mesh/App/MeshPyImp.cpp index 2df58c6e58..a736502c83 100644 --- a/src/Mod/Mesh/App/MeshPyImp.cpp +++ b/src/Mod/Mesh/App/MeshPyImp.cpp @@ -514,6 +514,32 @@ PyObject* MeshPy::outer(PyObject *args) Py_Return; } +PyObject* MeshPy::section(PyObject *args, PyObject *kwds) +{ + PyObject *pcObj; + PyObject *connectLines = Py_True; + float fMinDist = 0.0001f; + + static char* keywords_section[] = {"Mesh", "ConnectLines", "MinDist", nullptr}; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!|O!f",keywords_section, + &(MeshPy::Type), &pcObj, &PyBool_Type, &connectLines, &fMinDist)) + return nullptr; + + MeshPy* pcObject = static_cast(pcObj); + + std::vector< std::vector > curves = getMeshObjectPtr()->section(*pcObject->getMeshObjectPtr(), PyObject_IsTrue(connectLines), fMinDist); + Py::List outer; + for (const auto& it : curves) { + Py::List inner; + for (const auto& jt : it) { + inner.append(Py::Vector(jt)); + } + outer.append(inner); + } + + return Py::new_reference_to(outer); +} + PyObject* MeshPy::coarsen(PyObject *args) { if (!PyArg_ParseTuple(args, "")) From c123bc2bf83330994feb3e175f1080881e4a8e28 Mon Sep 17 00:00:00 2001 From: Ajinkya Dahale Date: Thu, 16 Sep 2021 13:06:29 -0400 Subject: [PATCH 23/55] [Core] (Partially?) Fix data loss on dir rename (#4996) * Fix lost filename in err msg In some circumstances, FileExceptions are constructed empty, then have a filename assigned to them, but the error message in these scenarios is left as the default "unknown" one, which is sometimes shown to users. This change fixes that case to be consistent with instances that are constructed with the filename. The exception can happen when trying to save the file in a location that does not exist, or when the user does not have permission to write there. If it comes when saving after closing the document, all previous changes can be lost. Partially fixes issue #4098. Co-authored-by: Heewa Barfchin --- src/App/Document.cpp | 5 ++++ src/Gui/Document.cpp | 68 +++++++++++++++++++++++++++++++++++++++--- src/Gui/MainWindow.cpp | 38 ++++++++++++++++------- src/Gui/MainWindow.h | 7 +++++ 4 files changed, 104 insertions(+), 14 deletions(-) diff --git a/src/App/Document.cpp b/src/App/Document.cpp index bcbf6b3849..aa099d216a 100644 --- a/src/App/Document.cpp +++ b/src/App/Document.cpp @@ -66,6 +66,7 @@ recompute path. Also, it enables more complicated dependencies beyond trees. # include # include # include +# include #endif #include @@ -142,6 +143,8 @@ using namespace zipios; # define FC_LOGFEATUREUPDATE #endif +namespace fs = boost::filesystem; + // typedef boost::property VertexProperty; typedef boost::adjacency_list < boost::vecS, // class OutEdgeListS : a Sequence or an AssociativeContainer @@ -2610,6 +2613,8 @@ bool Document::saveToFile(const char* filename) const fn += uuid; } Base::FileInfo tmp(fn); + // In case some folders in the path do not exist + fs::create_directories(fs::path(filename).parent_path()); // open extra scope to close ZipWriter properly { diff --git a/src/Gui/Document.cpp b/src/Gui/Document.cpp index 16c4fa5836..99e9bddf18 100644 --- a/src/Gui/Document.cpp +++ b/src/Gui/Document.cpp @@ -1158,6 +1158,25 @@ bool Document::save(void) if(gdoc) gdoc->setModified(false); } } + catch (const Base::FileException& e) { + int ret = QMessageBox::question( + getMainWindow(), + QObject::tr("Could not Save Document"), + QObject::tr("There was an issue trying to save the file. " + "This may be because some of the parent folders do not exist, " + "or you do not have sufficient permissions, " + "or for other reasons. Error details:\n\n\"%1\"\n\n" + "Would you like to save the file with a different name?") + .arg(QString::fromLatin1(e.what())), + QMessageBox::Yes, QMessageBox::No); + if (ret == QMessageBox::No) { + // TODO: Understand what exactly is supposed to be returned here + getMainWindow()->showMessage(QObject::tr("Saving aborted"), 2000); + return false; + } else if (ret == QMessageBox::Yes) { + return saveAs(); + } + } catch (const Base::Exception& e) { QMessageBox::critical(getMainWindow(), QObject::tr("Saving document failed"), QString::fromLatin1(e.what())); @@ -1196,6 +1215,25 @@ bool Document::saveAs(void) setModified(false); getMainWindow()->appendRecentFile(fi.filePath()); } + catch (const Base::FileException& e) { + int ret = QMessageBox::question( + getMainWindow(), + QObject::tr("Could not Save Document"), + QObject::tr("There was an issue trying to save the file. " + "This may be because some of the parent folders do not exist, " + "or you do not have sufficient permissions, " + "or for other reasons. Error details:\n\n\"%1\"\n\n" + "Would you like to save the file with a different name?") + .arg(QString::fromLatin1(e.what())), + QMessageBox::Yes, QMessageBox::No); + if (ret == QMessageBox::No) { + // TODO: Understand what exactly is supposed to be returned here + getMainWindow()->showMessage(QObject::tr("Saving aborted"), 2000); + return false; + } else if (ret == QMessageBox::Yes) { + return saveAs(); + } + } catch (const Base::Exception& e) { QMessageBox::critical(getMainWindow(), QObject::tr("Saving document failed"), QString::fromLatin1(e.what())); @@ -1942,11 +1980,33 @@ bool Document::canClose (bool checkModify, bool checkLink) bool ok = true; if (checkModify && isModified() && !getDocument()->testStatus(App::Document::PartialDoc)) { - int res = getMainWindow()->confirmSave(getDocument()->Label.getValue(),getActiveView()); - if(res>0) + const char *docName = getDocument()->Label.getValue(); + int res = getMainWindow()->confirmSave(docName, getActiveView()); + switch (res) + { + case MainWindow::ConfirmSaveResult::Cancel: + ok = false; + break; + case MainWindow::ConfirmSaveResult::SaveAll: + case MainWindow::ConfirmSaveResult::Save: ok = save(); - else - ok = res<0; + if (!ok) { + int ret = QMessageBox::question( + getActiveView(), + QObject::tr("Document not saved"), + QObject::tr("The document%1 could not be saved. Do you want to cancel closing it?") + .arg(docName?(QString::fromUtf8(" ")+QString::fromUtf8(docName)):QString()), + QMessageBox::Discard | QMessageBox::Cancel, + QMessageBox::Discard); + if (ret == QMessageBox::Discard) + ok = true; + } + break; + case MainWindow::ConfirmSaveResult::DiscardAll: + case MainWindow::ConfirmSaveResult::Discard: + ok = true; + break; + } } if (ok) { diff --git a/src/Gui/MainWindow.cpp b/src/Gui/MainWindow.cpp index 6d35aae1da..05801cbeb5 100644 --- a/src/Gui/MainWindow.cpp +++ b/src/Gui/MainWindow.cpp @@ -612,15 +612,15 @@ int MainWindow::confirmSave(const char *docName, QWidget *parent, bool addCheckb discardBtn->setShortcut(QKeySequence::mnemonic(text)); } - int res = 0; + int res = ConfirmSaveResult::Cancel; box.adjustSize(); // Silence warnings from Qt on Windows switch (box.exec()) { case QMessageBox::Save: - res = checkBox.isChecked()?2:1; + res = checkBox.isChecked()?ConfirmSaveResult::SaveAll:ConfirmSaveResult::Save; break; case QMessageBox::Discard: - res = checkBox.isChecked()?-2:-1; + res = checkBox.isChecked()?ConfirmSaveResult::DiscardAll:ConfirmSaveResult::Discard; break; } if(addCheckbox && res) @@ -632,12 +632,13 @@ bool MainWindow::closeAllDocuments (bool close) { auto docs = App::GetApplication().getDocuments(); try { - docs = App::Document::getDependentDocuments(docs,true); + docs = App::Document::getDependentDocuments(docs, true); }catch(Base::Exception &e) { e.ReportException(); } bool checkModify = true; bool saveAll = false; + int failedSaves = 0; for(auto doc : docs) { auto gdoc = Application::Instance->getDocument(doc); if(!gdoc) @@ -650,19 +651,36 @@ bool MainWindow::closeAllDocuments (bool close) continue; bool save = saveAll; if(!save && checkModify) { - int res = confirmSave(doc->Label.getStrValue().c_str(),this,docs.size()>1); - if(res==0) + int res = confirmSave(doc->Label.getStrValue().c_str(), this, docs.size()>1); + switch (res) + { + case ConfirmSaveResult::Cancel: return false; - if(res>0) { + case ConfirmSaveResult::SaveAll: + saveAll = true; + case ConfirmSaveResult::Save: save = true; - if(res==2) - saveAll = true; - } else if(res==-2) + break; + case ConfirmSaveResult::DiscardAll: checkModify = false; + } } + if(save && !gdoc->save()) + failedSaves++; + } + + if (failedSaves > 0) { + int ret = QMessageBox::question( + getMainWindow(), + QObject::tr("%1 Document(s) not saved").arg(QString::number(failedSaves)), + QObject::tr("Some documents could not be saved. Do you want to cancel closing?"), + QMessageBox::Discard | QMessageBox::Cancel, + QMessageBox::Discard); + if (ret == QMessageBox::Cancel) return false; } + if(close) App::GetApplication().closeAllDocuments(); // d->mdiArea->closeAllSubWindows(); diff --git a/src/Gui/MainWindow.h b/src/Gui/MainWindow.h index 3c864eeaf1..a980f0433c 100644 --- a/src/Gui/MainWindow.h +++ b/src/Gui/MainWindow.h @@ -77,6 +77,13 @@ class GuiExport MainWindow : public QMainWindow Q_OBJECT public: + enum ConfirmSaveResult { + Cancel = 0, + Save, + SaveAll, + Discard, + DiscardAll + }; /** * Constructs an empty main window. For default \a parent is 0, as there usually is * no toplevel window there. From 28d8d808a8da5a89c92974a2b4d0772cd380d93b Mon Sep 17 00:00:00 2001 From: Ajinkya Dahale Date: Thu, 16 Sep 2021 13:27:46 -0400 Subject: [PATCH 24/55] PartDesign: Add new need active body dialog with option to choose body (#4949) * [PD] Add new need active body dialog Intended for use wherever an active body is needed but none exists. The dialog contains a list with the bodies present in the document, with an extra option to make a new body. Custom text can be provided if needed. This commit also replaces the warnings used by "new sketch" and "primitive" command with this new dialog. Addresses issue #4288. --- src/Mod/PartDesign/Gui/CMakeLists.txt | 3 + src/Mod/PartDesign/Gui/Command.cpp | 12 ++- src/Mod/PartDesign/Gui/CommandPrimitive.cpp | 12 ++- src/Mod/PartDesign/Gui/DlgActiveBody.cpp | 95 +++++++++++++++++++++ src/Mod/PartDesign/Gui/DlgActiveBody.h | 59 +++++++++++++ src/Mod/PartDesign/Gui/DlgActiveBody.ui | 88 +++++++++++++++++++ src/Mod/PartDesign/Gui/Utils.cpp | 81 ++++++++++-------- src/Mod/PartDesign/Gui/Utils.h | 16 ++++ 8 files changed, 324 insertions(+), 42 deletions(-) create mode 100644 src/Mod/PartDesign/Gui/DlgActiveBody.cpp create mode 100644 src/Mod/PartDesign/Gui/DlgActiveBody.h create mode 100644 src/Mod/PartDesign/Gui/DlgActiveBody.ui diff --git a/src/Mod/PartDesign/Gui/CMakeLists.txt b/src/Mod/PartDesign/Gui/CMakeLists.txt index 5db22b5752..01c0ad1cc0 100644 --- a/src/Mod/PartDesign/Gui/CMakeLists.txt +++ b/src/Mod/PartDesign/Gui/CMakeLists.txt @@ -59,6 +59,7 @@ set(PartDesignGui_UIC_SRCS TaskPipeScaling.ui TaskLoftParameters.ui DlgReference.ui + DlgActiveBody.ui TaskHelixParameters.ui ) @@ -213,6 +214,8 @@ SET(PartDesignGuiTaskDlgs_SRCS TaskHelixParameters.ui TaskHelixParameters.h TaskHelixParameters.cpp + DlgActiveBody.h + DlgActiveBody.cpp ) SOURCE_GROUP("TaskDialogs" FILES ${PartDesignGuiTaskDlgs_SRCS}) diff --git a/src/Mod/PartDesign/Gui/Command.cpp b/src/Mod/PartDesign/Gui/Command.cpp index 6b268304d9..77a65c45a2 100644 --- a/src/Mod/PartDesign/Gui/Command.cpp +++ b/src/Mod/PartDesign/Gui/Command.cpp @@ -70,6 +70,7 @@ #include "WorkflowManager.h" #include "ViewProvider.h" #include "ViewProviderBody.h" +#include "DlgActiveBody.h" // TODO Remove this header after fixing code so it won;t be needed here (2015-10-20, Fat-Zer) #include "ui_DlgReference.h" @@ -505,12 +506,15 @@ void CmdPartDesignNewSketch::activated(int iMsg) // objects (in which case, just make one) to make a new sketch. pcActiveBody = PartDesignGui::getBody( /* messageIfNot = */ false ); - if (pcActiveBody == nullptr) { - if ( doc->getObjectsOfType(PartDesign::Body::getClassTypeId()).empty() ) { + if (!pcActiveBody) { + if ( doc->countObjectsOfType(PartDesign::Body::getClassTypeId()) == 0 ) { shouldMakeBody = true; } else { - PartDesignGui::needActiveBodyError(); - return; + PartDesignGui::DlgActiveBody dia(Gui::getMainWindow(), doc); + if (dia.exec() == QDialog::DialogCode::Accepted) + pcActiveBody = dia.getActiveBody(); + if (!pcActiveBody) + return; } } diff --git a/src/Mod/PartDesign/Gui/CommandPrimitive.cpp b/src/Mod/PartDesign/Gui/CommandPrimitive.cpp index 22ba6540b7..6aceb1116d 100644 --- a/src/Mod/PartDesign/Gui/CommandPrimitive.cpp +++ b/src/Mod/PartDesign/Gui/CommandPrimitive.cpp @@ -41,6 +41,7 @@ #include "Utils.h" #include "WorkflowManager.h" +#include "DlgActiveBody.h" using namespace std; @@ -85,12 +86,15 @@ void CmdPrimtiveCompAdditive::activated(int iMsg) PartDesign::Body *pcActiveBody = PartDesignGui::getBody( /* messageIfNot = */ false ); auto shouldMakeBody( false ); - if (pcActiveBody == nullptr) { + if (!pcActiveBody) { if ( doc->getObjectsOfType(PartDesign::Body::getClassTypeId()).empty() ) { shouldMakeBody = true; } else { - PartDesignGui::needActiveBodyError(); - return; + PartDesignGui::DlgActiveBody dia(Gui::getMainWindow(), doc); + if (dia.exec() == QDialog::DialogCode::Accepted) + pcActiveBody = dia.getActiveBody(); + if (!pcActiveBody) + return; } } @@ -104,7 +108,7 @@ void CmdPrimtiveCompAdditive::activated(int iMsg) pcActiveBody = PartDesignGui::makeBody(doc); } - if (pcActiveBody == nullptr) { + if (!pcActiveBody) { return; } diff --git a/src/Mod/PartDesign/Gui/DlgActiveBody.cpp b/src/Mod/PartDesign/Gui/DlgActiveBody.cpp new file mode 100644 index 0000000000..aa916d6208 --- /dev/null +++ b/src/Mod/PartDesign/Gui/DlgActiveBody.cpp @@ -0,0 +1,95 @@ + /************************************************************************** + * Copyright (c) 2021 FreeCAD Developers * + * Author: Ajinkya Dahale * + * Based on src/Gui/DlgAddProperty.cpp * + * * + * 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 +#endif + +#include + +#include "DlgActiveBody.h" +#include "ReferenceSelection.h" +#include "Utils.h" + +Q_DECLARE_METATYPE(App::DocumentObject*); + +using namespace PartDesignGui; + +DlgActiveBody::DlgActiveBody(QWidget *parent, App::Document*& doc, + const QString& infoText) + : QDialog(parent), + ui(new Ui_DlgActiveBody), + _doc(doc), + activeBody(nullptr) +{ + ui->setupUi(this); + + QObject::connect(ui->bodySelect, SIGNAL(itemDoubleClicked(QListWidgetItem *)), + this, SLOT(accept())); + + if(!infoText.isEmpty()) { + ui->label->setText(infoText + QString::fromUtf8("\n\n") + + QObject::tr("Please select")); + } + + auto bodies = _doc->getObjectsOfType(PartDesign::Body::getClassTypeId()); + + PartDesign::Body* bodyOfActiveObject = nullptr; + for (const auto &obj : Gui::Selection().getSelection()) { + bodyOfActiveObject = PartDesign::Body::findBodyOf(obj.pObject); + break; // Just get the body for first selected object + } + + for (const auto &body : bodies) { + auto item = new QListWidgetItem(QString::fromUtf8(body->Label.getValue())); + item->setData(Qt::UserRole, QVariant::fromValue(body)); + ui->bodySelect->addItem(item); + + if (body == bodyOfActiveObject) { + item->setSelected(true); + } + + // TODO: Any other logic (hover, select effects on view etc.) + } +} + +void DlgActiveBody::accept() +{ + auto selectedItems = ui->bodySelect->selectedItems(); + if (selectedItems.empty()) + return; + + App::DocumentObject* selectedBody = + selectedItems[0]->data(Qt::UserRole).value(); + if (selectedBody) + activeBody = makeBodyActive(selectedBody, _doc); + else + activeBody = makeBody(_doc); + + QDialog::accept(); +} + +#include "moc_DlgActiveBody.cpp" diff --git a/src/Mod/PartDesign/Gui/DlgActiveBody.h b/src/Mod/PartDesign/Gui/DlgActiveBody.h new file mode 100644 index 0000000000..c73f3c8bcd --- /dev/null +++ b/src/Mod/PartDesign/Gui/DlgActiveBody.h @@ -0,0 +1,59 @@ + /************************************************************************** + * Copyright (c) 2021 FreeCAD Developers * + * Author: Ajinkya Dahale * + * Based on src/Gui/DlgAddProperty.h * + * * + * 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 * + * * + ***************************************************************************/ + + +#ifndef PARTDESIGNGUI_DLGACTIVEBODY_H +#define PARTDESIGNGUI_DLGACTIVEBODY_H + +#include +#include + +// TODO: Apparently this header can be avoided. See ./Command.cpp:74. +#include "ui_DlgActiveBody.h" + +namespace PartDesignGui { + +/** Dialog box to ask user to pick a Part Design body to make active + * or make a new one + */ +class PartDesignGuiExport DlgActiveBody : public QDialog +{ + Q_OBJECT + +public: + DlgActiveBody(QWidget* parent, App::Document*& doc, + const QString& infoText=QString()); + + void accept() override; + PartDesign::Body* getActiveBody() { return activeBody; }; + +private: + std::unique_ptr ui; + App::Document* _doc; + PartDesign::Body* activeBody; +}; + +} // namespace PartDesignGui + +#endif // PARTDESIGNGUI_DLGACTIVEBODY_H diff --git a/src/Mod/PartDesign/Gui/DlgActiveBody.ui b/src/Mod/PartDesign/Gui/DlgActiveBody.ui new file mode 100644 index 0000000000..84c6506a85 --- /dev/null +++ b/src/Mod/PartDesign/Gui/DlgActiveBody.ui @@ -0,0 +1,88 @@ + + + PartDesignGui::DlgActiveBody + + + + 0 + 0 + 480 + 270 + + + + Active Body Required + + + + + + To create a new PartDesign object, there must be an active Body object in the document. + +Please select a body from below, or create a new body. + + + true + + + true + + + + + + + + Create new body + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + PartDesignGui::DlgActiveBody + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + PartDesignGui::DlgActiveBody + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/Mod/PartDesign/Gui/Utils.cpp b/src/Mod/PartDesign/Gui/Utils.cpp index 19536e3cfe..250dfbd280 100644 --- a/src/Mod/PartDesign/Gui/Utils.cpp +++ b/src/Mod/PartDesign/Gui/Utils.cpp @@ -52,6 +52,8 @@ #include "ReferenceSelection.h" #include "Utils.h" #include "WorkflowManager.h" +#include "DlgActiveBody.h" + FC_LOG_LEVEL_INIT("PartDesignGui",true,true) @@ -108,44 +110,30 @@ PartDesign::Body *getBody(bool messageIfNot, bool autoActivate, bool assertModer Gui::MDIView *activeView = Gui::Application::Instance->activeView(); if (activeView) { - bool singleBodyDocument = activeView->getAppDocument()-> - countObjectsOfType(PartDesign::Body::getClassTypeId()) == 1; - if (assertModern && PartDesignGui::assureModernWorkflow ( activeView->getAppDocument() ) ) { + auto doc = activeView->getAppDocument(); + bool singleBodyDocument = doc->countObjectsOfType(PartDesign::Body::getClassTypeId()) == 1; + if (assertModern && PartDesignGui::assureModernWorkflow (doc) ) { activeBody = activeView->getActiveObject(PDBODYKEY,topParent,subname); if (!activeBody && singleBodyDocument && autoActivate) { - auto doc = activeView->getAppDocument(); auto bodies = doc->getObjectsOfType(PartDesign::Body::getClassTypeId()); - App::DocumentObject *parent = 0; App::DocumentObject *body = 0; - std::string sub; if(bodies.size()==1) { body = bodies[0]; - for(auto &v : body->getParents()) { - if(v.first->getDocument()!=doc) - continue; - if(parent) { - body = 0; - break; - } - parent = v.first; - sub = v.second; - } - } - if(body) { - auto doc = parent?parent->getDocument():body->getDocument(); - _FCMD_DOC_CMD(Gui,doc,"ActiveView.setActiveObject('" << PDBODYKEY << "'," - << Gui::Command::getObjectCmd(parent?parent:body) << ",'" << sub << "')"); - return activeView->getActiveObject(PDBODYKEY,topParent,subname); + activeBody = makeBodyActive(body, doc, topParent, subname); } } if (!activeBody && messageIfNot) { - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No active Body"), + DlgActiveBody dia( + Gui::getMainWindow(), + doc, QObject::tr("In order to use PartDesign you need an active Body object in the document. " - "Please make one active (double click) or create one.\n\nIf you have a legacy document " - "with PartDesign objects without Body, use the migrate function in " - "PartDesign to put them into a Body." - )); + "Please make one active (double click) or create one." + "\n\nIf you have a legacy document with PartDesign objects without Body, " + "use the migrate function in PartDesign to put them into a Body." + )); + if (dia.exec() == QDialog::DialogCode::Accepted) + activeBody = dia.getActiveBody(); } } } @@ -153,6 +141,36 @@ PartDesign::Body *getBody(bool messageIfNot, bool autoActivate, bool assertModer return activeBody; } +PartDesign::Body * makeBodyActive(App::DocumentObject *body, App::Document *doc, + App::DocumentObject **topParent, + std::string *subname) +{ + App::DocumentObject *parent = 0; + std::string sub; + + for(auto &v : body->getParents()) { + if(v.first->getDocument()!=doc) + continue; + if(parent) { + body = 0; + break; + } + parent = v.first; + sub = v.second; + } + + if(body) { + auto _doc = parent?parent->getDocument():body->getDocument(); + _FCMD_DOC_CMD(Gui, _doc, "ActiveView.setActiveObject('" << PDBODYKEY + << "'," << Gui::Command::getObjectCmd(parent?parent:body) + << ",'" << sub << "')"); + return Gui::Application::Instance->activeView()-> + getActiveObject(PDBODYKEY,topParent,subname); + } + + return dynamic_cast(body); +} + void needActiveBodyError(void) { QMessageBox::warning( Gui::getMainWindow(), @@ -170,13 +188,8 @@ PartDesign::Body * makeBody(App::Document *doc) "App.getDocument('%s').addObject('PartDesign::Body','%s')", doc->getName(), bodyName.c_str() ); auto body = dynamic_cast(doc->getObject(bodyName.c_str())); - if(body) { - auto vp = Gui::Application::Instance->getViewProvider(body); - if(vp) { - // make the new body active - vp->doubleClicked(); - } - } + if(body) + makeBodyActive(body, doc); return body; } diff --git a/src/Mod/PartDesign/Gui/Utils.h b/src/Mod/PartDesign/Gui/Utils.h index e9a3aede92..e36725cbf1 100644 --- a/src/Mod/PartDesign/Gui/Utils.h +++ b/src/Mod/PartDesign/Gui/Utils.h @@ -50,6 +50,22 @@ bool setEdit(App::DocumentObject *obj, PartDesign::Body *body = 0); PartDesign::Body *getBody(bool messageIfNot, bool autoActivate=true, bool assertModern=true, App::DocumentObject **topParent=0, std::string *subname=0); +/// Display a dialog to select or create a Body object when none is active +PartDesign::Body * needActiveBodyMessage(App::Document *doc, + const QString& infoText=QString()); + +/** + * Set given body active, and return pointer to it. + * \param body the pointer to the body + * \param doc the pointer to the document in question + * \param topParent and + * \param subname to be passed under certain circumstances + * (currently only subshapebinder) + */ +PartDesign::Body * makeBodyActive(App::DocumentObject *body, App::Document *doc, + App::DocumentObject **topParent=0, + std::string *subname=0); + /// Display error when there are existing Body objects, but none are active void needActiveBodyError(void); From fa2851a7e81f75bb9fb956d874d5eab1f58a3d78 Mon Sep 17 00:00:00 2001 From: Roy-043 <70520633+Roy-043@users.noreply.github.com> Date: Fri, 17 Sep 2021 01:42:11 +0200 Subject: [PATCH 25/55] TechDraw housekeeping: TechDraw_LandmarkDimension icon fix (#5033) TechDraw housekeeping: TechDraw_LandmarkDimension icon fix --- src/Mod/TechDraw/Gui/CommandCreateDims.cpp | 2 +- src/Mod/TechDraw/Gui/Resources/TechDraw.qrc | 2 +- ...aw-landmarkdistance.svg => TechDraw_LandmarkDimension.svg} | 4 ++-- src/Mod/TechDraw/Gui/ViewProviderDimension.cpp | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) rename src/Mod/TechDraw/Gui/Resources/icons/{techdraw-landmarkdistance.svg => TechDraw_LandmarkDimension.svg} (99%) diff --git a/src/Mod/TechDraw/Gui/CommandCreateDims.cpp b/src/Mod/TechDraw/Gui/CommandCreateDims.cpp index ed3de2b190..a5474f2d71 100644 --- a/src/Mod/TechDraw/Gui/CommandCreateDims.cpp +++ b/src/Mod/TechDraw/Gui/CommandCreateDims.cpp @@ -1319,7 +1319,7 @@ CmdTechDrawLandmarkDimension::CmdTechDrawLandmarkDimension() sToolTipText = sMenuText; sWhatsThis = "TechDraw_LandmarkDimension"; sStatusTip = sToolTipText; - sPixmap = "techdraw-landmarkdistance"; + sPixmap = "TechDraw_LandmarkDimension"; } void CmdTechDrawLandmarkDimension::activated(int iMsg) diff --git a/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc b/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc index 96becf9604..45b09b6e62 100644 --- a/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc +++ b/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc @@ -39,7 +39,7 @@ icons/TechDraw_LinkDimension.svg icons/TechDraw_HorizontalExtentDimension.svg icons/TechDraw_VerticalExtentDimension.svg - icons/techdraw-landmarkdistance.svg + icons/TechDraw_LandmarkDimension.svg icons/actions/techdraw-View.svg icons/actions/TechDraw_ActiveView.svg icons/actions/techdraw-multiview.svg diff --git a/src/Mod/TechDraw/Gui/Resources/icons/techdraw-landmarkdistance.svg b/src/Mod/TechDraw/Gui/Resources/icons/TechDraw_LandmarkDimension.svg similarity index 99% rename from src/Mod/TechDraw/Gui/Resources/icons/techdraw-landmarkdistance.svg rename to src/Mod/TechDraw/Gui/Resources/icons/TechDraw_LandmarkDimension.svg index 4cc6c5fa36..1faa78b10f 100644 --- a/src/Mod/TechDraw/Gui/Resources/icons/techdraw-landmarkdistance.svg +++ b/src/Mod/TechDraw/Gui/Resources/icons/TechDraw_LandmarkDimension.svg @@ -176,7 +176,7 @@ [WandererFan] - TechDraw_Dimension_Length + TechDraw_LandmarkDimension 2016-04-27 http://www.freecadweb.org/wiki/index.php?title=Artwork @@ -184,7 +184,7 @@ FreeCAD - FreeCAD/src/Mod/TechDraw/Gui/Resources/icons/TechDraw_Dimension_Length.svg + FreeCAD/src/Mod/TechDraw/Gui/Resources/icons/TechDraw_LandmarkDimension.svg FreeCAD LGPL2+ diff --git a/src/Mod/TechDraw/Gui/ViewProviderDimension.cpp b/src/Mod/TechDraw/Gui/ViewProviderDimension.cpp index 1000ba7677..bfd0febd65 100644 --- a/src/Mod/TechDraw/Gui/ViewProviderDimension.cpp +++ b/src/Mod/TechDraw/Gui/ViewProviderDimension.cpp @@ -102,7 +102,7 @@ void ViewProviderDimension::attach(App::DocumentObject *pcFeat) sPixmap = "TechDraw_Dimension"; if (getViewObject()->isDerivedFrom(TechDraw::LandmarkDimension::getClassTypeId())) { - sPixmap = "techdraw-landmarkdistance"; + sPixmap = "TechDraw_LandmarkDimension"; } } From a5076e316d9b003c0eacc11f0ac5dc6ae5054235 Mon Sep 17 00:00:00 2001 From: mwganson Date: Fri, 17 Sep 2021 00:22:39 -0500 Subject: [PATCH 26/55] [Macros Dialog] begin searching for unique name for duplicate function with current numbers rather than from 001 --- src/Gui/DlgMacroExecuteImp.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Gui/DlgMacroExecuteImp.cpp b/src/Gui/DlgMacroExecuteImp.cpp index 316221c31c..e19450c49f 100644 --- a/src/Gui/DlgMacroExecuteImp.cpp +++ b/src/Gui/DlgMacroExecuteImp.cpp @@ -714,6 +714,10 @@ void DlgMacroExecuteImp::on_duplicateButton_clicked() QDir dir; QTreeWidgetItem* item = 0; + //When duplicating a macro we can either begin trying to find a unique name with @001 or begin with the current @NNN if applicable + + bool from001 = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Macro")->GetBool("DuplicateFrom001", false); + App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Macro")->SetBool("DuplicateFrom001", from001); //create parameter int index = ui->tabMacroWidget->currentIndex(); if (index == 0) { //user-specific item = ui->userMacroListBox->currentItem(); @@ -733,10 +737,13 @@ void DlgMacroExecuteImp::on_duplicateButton_clicked() QString last3 = baseName.right(3); bool ok = true; //was conversion to int successful? int nLast3 = last3.toInt(&ok); - last3 = QString::fromStdString("001"); //increment beginning with 001 no matter what + last3 = QString::fromStdString("001"); //increment beginning with 001 unless from001 = false if (ok ){ //last3 were all digits, so we strip them from the base name if (baseName.size()>3){ //if <= 3 leave be (e.g. 2.py becomes 2@001.py) + if(!from001){ + last3 = baseName.right(3); //use these instead of 001 + } baseName = baseName.left(baseName.size()-3); //strip digits if (baseName.endsWith(neutralSymbol)){ baseName = baseName.left(baseName.size()-1); //trim the "@", will be added back later @@ -746,6 +753,7 @@ void DlgMacroExecuteImp::on_duplicateButton_clicked() //at this point baseName = the base name without any digits, e.g. "MyMacro" //neutralSymbol = "@" //last3 is a string representing 3 digits, always "001" at this time + //unless from001 = false, in which case we begin with previous numbers //completeSuffix = FCMacro or py or FCMacro.py or else suffix will become FCMacro below QString oldNameDigitized = baseName+neutralSymbol+last3+QString::fromStdString(".")+completeSuffix; From 9a23ffb35a9c2d1e7ef7c705643fa857d5f06104 Mon Sep 17 00:00:00 2001 From: wmayer Date: Fri, 17 Sep 2021 08:28:34 +0200 Subject: [PATCH 27/55] Gui: fix typos --- src/Gui/Document.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Gui/Document.cpp b/src/Gui/Document.cpp index 99e9bddf18..5bced7547b 100644 --- a/src/Gui/Document.cpp +++ b/src/Gui/Document.cpp @@ -1161,7 +1161,7 @@ bool Document::save(void) catch (const Base::FileException& e) { int ret = QMessageBox::question( getMainWindow(), - QObject::tr("Could not Save Document"), + QObject::tr("Could not save document"), QObject::tr("There was an issue trying to save the file. " "This may be because some of the parent folders do not exist, " "or you do not have sufficient permissions, " @@ -1218,7 +1218,7 @@ bool Document::saveAs(void) catch (const Base::FileException& e) { int ret = QMessageBox::question( getMainWindow(), - QObject::tr("Could not Save Document"), + QObject::tr("Could not save document"), QObject::tr("There was an issue trying to save the file. " "This may be because some of the parent folders do not exist, " "or you do not have sufficient permissions, " From 16a82d1eb7de16801f3e51acc07ba6670f410d22 Mon Sep 17 00:00:00 2001 From: Ajinkya Dahale Date: Sat, 11 Sep 2021 13:25:35 -0400 Subject: [PATCH 28/55] [FEM] Add tools for more yield points in simple hardening materials String List instead of String should allow for arbitrarily many entries, theoretically. Note the defaults previously in `YieldPoint1` an `YieldPoint2` were arbitrary. Now the list is kept empty by default. Fixes issue #4720. --- .../femexamples/material_nl_platewithhole.py | 3 +-- .../material_mechanicalnonlinear.py | 25 ++++--------------- .../calculix/write_femelement_material.py | 8 ++---- 3 files changed, 8 insertions(+), 28 deletions(-) diff --git a/src/Mod/Fem/femexamples/material_nl_platewithhole.py b/src/Mod/Fem/femexamples/material_nl_platewithhole.py index e81d72f71a..6ce3d71ec8 100644 --- a/src/Mod/Fem/femexamples/material_nl_platewithhole.py +++ b/src/Mod/Fem/femexamples/material_nl_platewithhole.py @@ -149,8 +149,7 @@ def setup(doc=None, solvertype="ccxtools"): # nonlinear material name_nlm = "Material_nonlin" nonlinear_mat = ObjectsFem.makeMaterialMechanicalNonlinear(doc, material_obj, name_nlm) - nonlinear_mat.YieldPoint1 = '240.0, 0.0' - nonlinear_mat.YieldPoint2 = '270.0, 0.025' + nonlinear_mat.YieldPoints = ['240.0, 0.0', '270.0, 0.025'] analysis.addObject(nonlinear_mat) # check solver attributes, Nonlinearity needs to be set to nonlinear diff --git a/src/Mod/Fem/femobjects/material_mechanicalnonlinear.py b/src/Mod/Fem/femobjects/material_mechanicalnonlinear.py index 9184aa26ac..8aa8b3b577 100644 --- a/src/Mod/Fem/femobjects/material_mechanicalnonlinear.py +++ b/src/Mod/Fem/femobjects/material_mechanicalnonlinear.py @@ -60,25 +60,10 @@ class MaterialMechanicalNonlinear(base_fempythonobject.BaseFemPythonObject): obj.MaterialModelNonlinearity = choices_nonlinear_material_models[0] obj.addProperty( - "App::PropertyString", - "YieldPoint1", + "App::PropertyStringList", + "YieldPoints", "Fem", - "Set stress and strain for yield point one, separated by a comma." + "Set stress and strain for yield points as a list of strings, " + "each point \"stress, plastic strain\"" ) - obj.YieldPoint1 = "235.0, 0.0" - - obj.addProperty( - "App::PropertyString", - "YieldPoint2", - "Fem", - "Set stress and strain for yield point two, separated by a comma." - ) - obj.YieldPoint2 = "241.0, 0.025" - - obj.addProperty( - "App::PropertyString", - "YieldPoint3", - "Fem", - "Set stress and strain for yield point three, separated by a comma." - ) - obj.YieldPoint3 = "" + obj.YieldPoints = [] diff --git a/src/Mod/Fem/femsolver/calculix/write_femelement_material.py b/src/Mod/Fem/femsolver/calculix/write_femelement_material.py index 98747fd7b5..edccbd6135 100644 --- a/src/Mod/Fem/femsolver/calculix/write_femelement_material.py +++ b/src/Mod/Fem/femsolver/calculix/write_femelement_material.py @@ -113,10 +113,6 @@ def write_femelement_material(f, ccxwriter): if nl_mat_obj.LinearBaseMaterial == mat_obj: if nl_mat_obj.MaterialModelNonlinearity == "simple hardening": f.write("*PLASTIC\n") - if nl_mat_obj.YieldPoint1: - f.write("{}\n".format(nl_mat_obj.YieldPoint1)) - if nl_mat_obj.YieldPoint2: - f.write("{}\n".format(nl_mat_obj.YieldPoint2)) - if nl_mat_obj.YieldPoint3: - f.write("{}\n".format(nl_mat_obj.YieldPoint3)) + for yield_point in nl_mat_obj.YieldPoints: + f.write("{}\n".format(yield_point)) f.write("\n") From 0327a0987909758bbcb9974f914216be045c4973 Mon Sep 17 00:00:00 2001 From: Ajinkya Dahale Date: Tue, 14 Sep 2021 00:33:27 -0400 Subject: [PATCH 29/55] [FEM] Add backward compatibility for simple hardening Prior to a recent commit (or this, if squashed), yield points of a non-linear material with simple hardening were stored as three different properties. These changes consolidate them into the new `YieldPoints` property. --- .../material_mechanicalnonlinear.py | 79 +++++++++++++------ 1 file changed, 56 insertions(+), 23 deletions(-) diff --git a/src/Mod/Fem/femobjects/material_mechanicalnonlinear.py b/src/Mod/Fem/femobjects/material_mechanicalnonlinear.py index 8aa8b3b577..c95296dd66 100644 --- a/src/Mod/Fem/femobjects/material_mechanicalnonlinear.py +++ b/src/Mod/Fem/femobjects/material_mechanicalnonlinear.py @@ -41,29 +41,62 @@ class MaterialMechanicalNonlinear(base_fempythonobject.BaseFemPythonObject): def __init__(self, obj): super(MaterialMechanicalNonlinear, self).__init__(obj) + self.add_properties(obj) - obj.addProperty( - "App::PropertyLink", - "LinearBaseMaterial", - "Base", - "Set the linear material the nonlinear builds upon." - ) + def onDocumentRestored(self, obj): - choices_nonlinear_material_models = ["simple hardening"] - obj.addProperty( - "App::PropertyEnumeration", - "MaterialModelNonlinearity", - "Fem", - "Set the type on nonlinear material model" - ) - obj.MaterialModelNonlinearity = choices_nonlinear_material_models - obj.MaterialModelNonlinearity = choices_nonlinear_material_models[0] + # YieldPoints was (until 0.19) stored as 3 separate variables. Consolidate them if present. + yield_points = [] + if hasattr(obj, "YieldPoint1"): + if obj.YieldPoint1: + yield_points.append(obj.YieldPoint1) + obj.removeProperty("YieldPoint1") + if hasattr(obj, "YieldPoint2"): + if obj.YieldPoint2: + yield_points.append(obj.YieldPoint2) + obj.removeProperty("YieldPoint2") + if hasattr(obj, "YieldPoint3"): + if obj.YieldPoint3: + yield_points.append(obj.YieldPoint3) + obj.removeProperty("YieldPoint3") - obj.addProperty( - "App::PropertyStringList", - "YieldPoints", - "Fem", - "Set stress and strain for yield points as a list of strings, " - "each point \"stress, plastic strain\"" - ) - obj.YieldPoints = [] + self.add_properties(obj) + if yield_points: + obj.YieldPoints = yield_points + + # TODO: If in the future more nonlinear options are added, update choices here. + + def add_properties(self, obj): + + # this method is called from onDocumentRestored + # thus only add and or set a attribute + # if the attribute does not exist + + if not hasattr(obj, "LinearBaseMaterial"): + obj.addProperty( + "App::PropertyLink", + "LinearBaseMaterial", + "Base", + "Set the linear material the nonlinear builds upon." + ) + + if not hasattr(obj, "MaterialModelNonlinearity"): + choices_nonlinear_material_models = ["simple hardening"] + obj.addProperty( + "App::PropertyEnumeration", + "MaterialModelNonlinearity", + "Fem", + "Set the type on nonlinear material model" + ) + obj.MaterialModelNonlinearity = choices_nonlinear_material_models + obj.MaterialModelNonlinearity = choices_nonlinear_material_models[0] + + if not hasattr(obj, "YieldPoints"): + obj.addProperty( + "App::PropertyStringList", + "YieldPoints", + "Fem", + "Set stress and strain for yield points as a list of strings, " + "each point \"stress, plastic strain\"" + ) + obj.YieldPoints = [] From 354987b45da9ba539cbf50882c809e835bddcf42 Mon Sep 17 00:00:00 2001 From: Preslav Date: Tue, 31 Aug 2021 11:23:01 +0100 Subject: [PATCH 30/55] Ammending stiffness units --- src/App/PropertyUnits.cpp | 12 ++++++++++++ src/App/PropertyUnits.h | 12 ++++++++++++ src/Base/UnitsSchemaImperial1.cpp | 8 ++++++++ 3 files changed, 32 insertions(+) diff --git a/src/App/PropertyUnits.cpp b/src/App/PropertyUnits.cpp index 8e3443cc01..6189e144fb 100644 --- a/src/App/PropertyUnits.cpp +++ b/src/App/PropertyUnits.cpp @@ -324,6 +324,18 @@ PropertyPressure::PropertyPressure() setUnit(Base::Unit::Pressure); } +//************************************************************************** +//************************************************************************** +// PropertyStiffness +//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + +TYPESYSTEM_SOURCE(App::PropertyStiffness, App::PropertyQuantity) + +PropertyStiffness::PropertyStiffness() +{ + setUnit(Base::Unit::Stiffness); +} + //************************************************************************** //************************************************************************** // PropertyForce diff --git a/src/App/PropertyUnits.h b/src/App/PropertyUnits.h index a95a201d3f..fdc4b453f3 100644 --- a/src/App/PropertyUnits.h +++ b/src/App/PropertyUnits.h @@ -227,6 +227,18 @@ public: virtual ~PropertyPressure(){} }; +/** Stiffness property + * This is a property for representing stiffness. It is basically a float + * property. On the Gui it has a quantity like m/s^2. + */ +class AppExport PropertyStiffness: public PropertyQuantity +{ + TYPESYSTEM_HEADER(); +public: + PropertyStiffness(void); + virtual ~PropertyStiffness(){} +}; + /** Force property * This is a property for representing acceleration. It is basically a float * property. On the Gui it has a quantity like m/s^2. diff --git a/src/Base/UnitsSchemaImperial1.cpp b/src/Base/UnitsSchemaImperial1.cpp index 3ef90398d4..fadafafe49 100644 --- a/src/Base/UnitsSchemaImperial1.cpp +++ b/src/Base/UnitsSchemaImperial1.cpp @@ -187,6 +187,10 @@ QString UnitsSchemaImperialDecimal::schemaTranslate(const Base::Quantity& quant, unitString = QString::fromLatin1("psi"); factor = 6.894744825494; } + else if (unit == Unit::Stiffness) { + unitString = QString::fromLatin1("lbf/in"); + factor = 4.448222/0.0254; + } else if (unit == Unit::Velocity) { unitString = QString::fromLatin1("in/min"); factor = 25.4 / 60; @@ -360,6 +364,10 @@ QString UnitsSchemaImperialCivil::schemaTranslate(const Base::Quantity& quant, d unitString = QString::fromLatin1("psi"); factor = 6.894744825494; } + else if (unit == Unit::Stiffness) { + unitString = QString::fromLatin1("lbf/in"); + factor = 4.448222/0.0254; + } else if (unit == Unit::Velocity) { unitString = QString::fromLatin1("mph"); factor = 447.04; //1mm/sec => mph From fb0e670d8a1cc58a072635b1d3126b43365ab174 Mon Sep 17 00:00:00 2001 From: Preslav Date: Tue, 31 Aug 2021 12:16:11 +0100 Subject: [PATCH 31/55] Added spring boundary condition --- src/Mod/Fem/App/AppFem.cpp | 2 + src/Mod/Fem/App/CMakeLists.txt | 2 + src/Mod/Fem/App/FemConstraintSpring.cpp | 81 +++++ src/Mod/Fem/App/FemConstraintSpring.h | 56 +++ src/Mod/Fem/Gui/AppFemGui.cpp | 2 + src/Mod/Fem/Gui/CMakeLists.txt | 6 + src/Mod/Fem/Gui/Command.cpp | 46 +++ src/Mod/Fem/Gui/Resources/Fem.qrc | 1 + .../Resources/icons/FEM_ConstraintSpring.svg | 134 ++++++++ src/Mod/Fem/Gui/TaskFemConstraintSpring.cpp | 322 ++++++++++++++++++ src/Mod/Fem/Gui/TaskFemConstraintSpring.h | 83 +++++ src/Mod/Fem/Gui/TaskFemConstraintSpring.ui | 116 +++++++ src/Mod/Fem/Gui/ViewProviderFemConstraint.cpp | 24 ++ src/Mod/Fem/Gui/ViewProviderFemConstraint.h | 3 + .../Gui/ViewProviderFemConstraintSpring.cpp | 156 +++++++++ .../Fem/Gui/ViewProviderFemConstraintSpring.h | 46 +++ src/Mod/Fem/Gui/Workbench.cpp | 2 + src/Mod/Fem/ObjectsFem.py | 10 + src/Mod/Fem/femtest/app/test_object.py | 29 ++ 19 files changed, 1121 insertions(+) create mode 100644 src/Mod/Fem/App/FemConstraintSpring.cpp create mode 100644 src/Mod/Fem/App/FemConstraintSpring.h create mode 100644 src/Mod/Fem/Gui/Resources/icons/FEM_ConstraintSpring.svg create mode 100644 src/Mod/Fem/Gui/TaskFemConstraintSpring.cpp create mode 100644 src/Mod/Fem/Gui/TaskFemConstraintSpring.h create mode 100644 src/Mod/Fem/Gui/TaskFemConstraintSpring.ui create mode 100644 src/Mod/Fem/Gui/ViewProviderFemConstraintSpring.cpp create mode 100644 src/Mod/Fem/Gui/ViewProviderFemConstraintSpring.h diff --git a/src/Mod/Fem/App/AppFem.cpp b/src/Mod/Fem/App/AppFem.cpp index bcb6c4dbe8..5473efd7c4 100644 --- a/src/Mod/Fem/App/AppFem.cpp +++ b/src/Mod/Fem/App/AppFem.cpp @@ -59,6 +59,7 @@ #include "FemConstraintContact.h" #include "FemConstraintFluidBoundary.h" #include "FemConstraintTransform.h" +#include "FemConstraintSpring.h" #include "FemResultObject.h" #include "FemSolverObject.h" @@ -156,6 +157,7 @@ PyMOD_INIT_FUNC(Fem) Fem::ConstraintPulley ::init(); Fem::ConstraintTemperature ::init(); Fem::ConstraintTransform ::init(); + Fem::ConstraintSpring ::init(); Fem::FemMesh ::init(); Fem::FemMeshObject ::init(); diff --git a/src/Mod/Fem/App/CMakeLists.txt b/src/Mod/Fem/App/CMakeLists.txt index aafd14d98a..6ca4f157f3 100644 --- a/src/Mod/Fem/App/CMakeLists.txt +++ b/src/Mod/Fem/App/CMakeLists.txt @@ -158,6 +158,8 @@ SET(FemConstraints_SRCS FemConstraintFluidBoundary.h FemConstraintPressure.cpp FemConstraintPressure.h + FemConstraintSpring.cpp + FemConstraintSpring.h FemConstraintGear.cpp FemConstraintGear.h FemConstraintPulley.cpp diff --git a/src/Mod/Fem/App/FemConstraintSpring.cpp b/src/Mod/Fem/App/FemConstraintSpring.cpp new file mode 100644 index 0000000000..20ffe69338 --- /dev/null +++ b/src/Mod/Fem/App/FemConstraintSpring.cpp @@ -0,0 +1,81 @@ +/*************************************************************************** + * Copyright (c) 2021 FreeCAD Developers * + * Author: Preslav Aleksandrov * + * Based on Force constraint by Jan Rheinländer * + * 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 +#include +#include +#include +#include +#endif + +#include "FemConstraintSpring.h" + +using namespace Fem; + +PROPERTY_SOURCE(Fem::ConstraintSpring, Fem::Constraint) + +ConstraintSpring::ConstraintSpring() +{ + ADD_PROPERTY(normalStiffness,(0.0)); + ADD_PROPERTY(tangentialStiffness,(0.0)); + ADD_PROPERTY_TYPE(Points,(Base::Vector3d()),"ConstraintSpring", + App::PropertyType(App::Prop_ReadOnly|App::Prop_Output), + "Points where arrows are drawn"); + ADD_PROPERTY_TYPE(Normals,(Base::Vector3d()),"ConstraintSpring", + App::PropertyType(App::Prop_ReadOnly|App::Prop_Output), + "Normals where symbols are drawn"); + Points.setValues(std::vector()); + Normals.setValues(std::vector()); +} + +App::DocumentObjectExecReturn *ConstraintSpring::execute(void) +{ + return Constraint::execute(); +} + +const char* ConstraintSpring::getViewProviderName(void) const +{ + return "FemGui::ViewProviderFemConstraintSpring"; +} + +void ConstraintSpring::onChanged(const App::Property* prop) +{ + Constraint::onChanged(prop); + + if (prop == &References) { + std::vector points; + std::vector normals; + int scale = Scale.getValue(); + if (getPoints(points, normals, &scale)) { + Points.setValues(points); + Normals.setValues(normals); + Scale.setValue(scale); + Points.touch(); + } + } +} diff --git a/src/Mod/Fem/App/FemConstraintSpring.h b/src/Mod/Fem/App/FemConstraintSpring.h new file mode 100644 index 0000000000..585564b6de --- /dev/null +++ b/src/Mod/Fem/App/FemConstraintSpring.h @@ -0,0 +1,56 @@ +/*************************************************************************** + * Copyright (c) 2021 FreeCAD Developers * + * Author: Preslav Aleksandrov * + * Based on Force constraint by Jan Rheinländer * + * 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 * + * * + ***************************************************************************/ + + +#ifndef FEM_CONSTRAINTPSPRING_H +#define FEM_CONSTRAINTPSPRING_H + +#include "FemConstraint.h" + +namespace Fem { + +class AppFemExport ConstraintSpring : public Fem::Constraint +{ + PROPERTY_HEADER(Fem::ConstraintSpring); + +public: + ConstraintSpring(void); + + App::PropertyFloat normalStiffness; + App::PropertyFloat tangentialStiffness; + App::PropertyVectorList Points; + App::PropertyVectorList Normals; + + /// recalculate the object + virtual App::DocumentObjectExecReturn *execute(void); + + /// returns the type name of the ViewProvider + const char* getViewProviderName(void) const; + +protected: + virtual void onChanged(const App::Property* prop); +}; + +} + +#endif // FEM_CONSTRAINTPSPRING_H diff --git a/src/Mod/Fem/Gui/AppFemGui.cpp b/src/Mod/Fem/Gui/AppFemGui.cpp index fad9b28703..36424fec8a 100644 --- a/src/Mod/Fem/Gui/AppFemGui.cpp +++ b/src/Mod/Fem/Gui/AppFemGui.cpp @@ -57,6 +57,7 @@ #include "ViewProviderFemConstraintForce.h" #include "ViewProviderFemConstraintFluidBoundary.h" #include "ViewProviderFemConstraintPressure.h" +#include "ViewProviderFemConstraintSpring.h" #include "ViewProviderFemConstraintGear.h" #include "ViewProviderFemConstraintPulley.h" #include "ViewProviderFemConstraintDisplacement.h" @@ -129,6 +130,7 @@ PyMOD_INIT_FUNC(FemGui) FemGui::ViewProviderFemConstraintPulley ::init(); FemGui::ViewProviderFemConstraintTemperature ::init(); FemGui::ViewProviderFemConstraintTransform ::init(); + FemGui::ViewProviderFemConstraintSpring ::init(); FemGui::ViewProviderFemMesh ::init(); FemGui::ViewProviderFemMeshPython ::init(); diff --git a/src/Mod/Fem/Gui/CMakeLists.txt b/src/Mod/Fem/Gui/CMakeLists.txt index b70a41634d..cb1d00273c 100755 --- a/src/Mod/Fem/Gui/CMakeLists.txt +++ b/src/Mod/Fem/Gui/CMakeLists.txt @@ -80,6 +80,7 @@ set(FemGui_UIC_SRCS TaskFemConstraintPlaneRotation.ui TaskFemConstraintContact.ui TaskFemConstraintTransform.ui + TaskFemConstraintSpring.ui TaskTetParameter.ui TaskAnalysisInfo.ui TaskDriver.ui @@ -154,6 +155,9 @@ SET(FemGui_DLG_SRCS TaskFemConstraintPressure.ui TaskFemConstraintPressure.cpp TaskFemConstraintPressure.h + TaskFemConstraintSpring.ui + TaskFemConstraintSpring.cpp + TaskFemConstraintSpring.h TaskFemConstraintGear.cpp TaskFemConstraintGear.h TaskFemConstraintPulley.cpp @@ -224,6 +228,8 @@ SET(FemGui_SRCS_ViewProvider ViewProviderFemConstraintFluidBoundary.h ViewProviderFemConstraintPressure.cpp ViewProviderFemConstraintPressure.h + ViewProviderFemConstraintSpring.cpp + ViewProviderFemConstraintSpring.h ViewProviderFemConstraintGear.cpp ViewProviderFemConstraintGear.h ViewProviderFemConstraintPulley.cpp diff --git a/src/Mod/Fem/Gui/Command.cpp b/src/Mod/Fem/Gui/Command.cpp index 24556d5df9..6620d24f3a 100644 --- a/src/Mod/Fem/Gui/Command.cpp +++ b/src/Mod/Fem/Gui/Command.cpp @@ -759,6 +759,51 @@ bool CmdFemConstraintPressure::isActive(void) } +//================================================================================================ +DEF_STD_CMD_A(CmdFemConstraintSpring) + +CmdFemConstraintSpring::CmdFemConstraintSpring() + : Command("FEM_ConstraintSpring") +{ + sAppModule = "Fem"; + sGroup = QT_TR_NOOP("Fem"); + sMenuText = QT_TR_NOOP("Constraint spring"); + sToolTipText = QT_TR_NOOP("Creates a FEM constraint for a spring acting on a face"); + sWhatsThis = "FEM_ConstraintSpring"; + sStatusTip = sToolTipText; + sPixmap = "FEM_ConstraintSpring"; +} + +void CmdFemConstraintSpring::activated(int) +{ + Fem::FemAnalysis *Analysis; + + if(getConstraintPrerequisits(&Analysis)) + return; + + std::string FeatName = getUniqueObjectName("ConstraintSpring"); + + openCommand(QT_TRANSLATE_NOOP("Command", "Make FEM constraint spring on face")); + doCommand(Doc,"App.activeDocument().addObject(\"Fem::ConstraintSpring\",\"%s\")",FeatName.c_str()); + doCommand(Doc,"App.activeDocument().%s.normalStiffness = 1.0",FeatName.c_str()); //OvG: set default not equal to 0 + doCommand(Doc,"App.activeDocument().%s.tangentialStiffness = 0.0",FeatName.c_str()); //OvG: set default to False + doCommand(Doc,"App.activeDocument().%s.Scale = 1",FeatName.c_str()); //OvG: set initial scale to 1 + doCommand(Doc,"App.activeDocument().%s.addObject(App.activeDocument().%s)", + Analysis->getNameInDocument(),FeatName.c_str()); + + doCommand(Doc,"%s",gethideMeshShowPartStr(FeatName).c_str()); //OvG: Hide meshes and show parts + + updateActive(); + + doCommand(Gui,"Gui.activeDocument().setEdit('%s')",FeatName.c_str()); +} + +bool CmdFemConstraintSpring::isActive(void) +{ + return FemGui::ActiveAnalysisObserver::instance()->hasActiveObject(); +} + + //================================================================================================ DEF_STD_CMD_A(CmdFemConstraintPulley) @@ -1687,6 +1732,7 @@ void CreateFemCommands(void) rcCmdMgr.addCommand(new CmdFemConstraintPulley()); rcCmdMgr.addCommand(new CmdFemConstraintTemperature()); rcCmdMgr.addCommand(new CmdFemConstraintTransform()); + rcCmdMgr.addCommand(new CmdFemConstraintSpring()); // mesh rcCmdMgr.addCommand(new CmdFemCreateNodesSet()); diff --git a/src/Mod/Fem/Gui/Resources/Fem.qrc b/src/Mod/Fem/Gui/Resources/Fem.qrc index caf67b0333..d8ac00bb62 100755 --- a/src/Mod/Fem/Gui/Resources/Fem.qrc +++ b/src/Mod/Fem/Gui/Resources/Fem.qrc @@ -30,6 +30,7 @@ icons/FEM_ConstraintTemperature.svg icons/FEM_ConstraintTie.svg icons/FEM_ConstraintTransform.svg + icons/FEM_ConstraintSpring.svg icons/FEM_ElementFluid1D.svg diff --git a/src/Mod/Fem/Gui/Resources/icons/FEM_ConstraintSpring.svg b/src/Mod/Fem/Gui/Resources/icons/FEM_ConstraintSpring.svg new file mode 100644 index 0000000000..d434552239 --- /dev/null +++ b/src/Mod/Fem/Gui/Resources/icons/FEM_ConstraintSpring.svg @@ -0,0 +1,134 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Mod/Fem/Gui/TaskFemConstraintSpring.cpp b/src/Mod/Fem/Gui/TaskFemConstraintSpring.cpp new file mode 100644 index 0000000000..005b56c591 --- /dev/null +++ b/src/Mod/Fem/Gui/TaskFemConstraintSpring.cpp @@ -0,0 +1,322 @@ +/*************************************************************************** + * Copyright (c) 2021 FreeCAD Developers * + * Author: Preslav Aleksandrov * + * Based on Force constraint by Jan Rheinländer * + * 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 +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include + +# include +#endif + +#include "Mod/Fem/App/FemConstraintSpring.h" +#include "TaskFemConstraintSpring.h" +#include "ui_TaskFemConstraintSpring.h" +#include +#include +#include +#include +#include +#include + + +using namespace FemGui; +using namespace Gui; + +/* TRANSLATOR FemGui::TaskFemConstraintSpring */ + +TaskFemConstraintSpring::TaskFemConstraintSpring(ViewProviderFemConstraintSpring *ConstraintView, QWidget *parent) + : TaskFemConstraint(ConstraintView, parent, "FEM_ConstraintSpring") +{ + proxy = new QWidget(this); + ui = new Ui_TaskFemConstraintSpring(); + ui->setupUi(proxy); + QMetaObject::connectSlotsByName(this); + + // create a context menu for the listview of the references + createDeleteAction(ui->lw_references); + deleteAction->connect(deleteAction, SIGNAL(triggered()), this, SLOT(onReferenceDeleted())); + + connect(ui->lw_references, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), + this, SLOT(setSelection(QListWidgetItem*))); + connect(ui->lw_references, SIGNAL(itemClicked(QListWidgetItem*)), + this, SLOT(setSelection(QListWidgetItem*))); + + this->groupLayout()->addWidget(proxy); + +/* Note: */ + // Get the feature data + Fem::ConstraintSpring* pcConstraint = static_cast(ConstraintView->getObject()); + + std::vector Objects = pcConstraint->References.getValues(); + std::vector SubElements = pcConstraint->References.getSubValues(); + + // Fill data into dialog elements + ui->if_norm->setMinimum(0); // TODO fix this ------------------------------------------------------------------- + ui->if_norm->setMaximum(FLOAT_MAX); + Base::Quantity ns = Base::Quantity((pcConstraint->normalStiffness.getValue()), Base::Unit::Stiffness); + ui->if_norm->setValue(ns); + + // Fill data into dialog elements + ui->if_tan->setMinimum(0); // TODO fix this ------------------------------------------------------------------- + ui->if_tan->setMaximum(FLOAT_MAX); + Base::Quantity ts = Base::Quantity((pcConstraint->tangentialStiffness.getValue()), Base::Unit::Stiffness); + ui->if_tan->setValue(ts); + +/* */ + + ui->lw_references->clear(); + for (std::size_t i = 0; i < Objects.size(); i++) { + ui->lw_references->addItem(makeRefText(Objects[i], SubElements[i])); + } + if (Objects.size() > 0) { + ui->lw_references->setCurrentRow(0, QItemSelectionModel::ClearAndSelect); + } + + //Selection buttons + connect(ui->btnAdd, SIGNAL(clicked()), this, SLOT(addToSelection())); + connect(ui->btnRemove, SIGNAL(clicked()), this, SLOT(removeFromSelection())); + + updateUI(); +} + +TaskFemConstraintSpring::~TaskFemConstraintSpring() +{ + delete ui; +} + +void TaskFemConstraintSpring::updateUI() +{ + if (ui->lw_references->model()->rowCount() == 0) { + // Go into reference selection mode if no reference has been selected yet + onButtonReference(true); + return; + } +} + + +void TaskFemConstraintSpring::addToSelection() +{ + std::vector selection = Gui::Selection().getSelectionEx(); //gets vector of selected objects of active document + if (selection.size() == 0){ + QMessageBox::warning(this, tr("Selection error"), tr("Nothing selected!")); + return; + } + Fem::ConstraintSpring* pcConstraint = static_cast(ConstraintView->getObject()); + std::vector Objects = pcConstraint->References.getValues(); + std::vector SubElements = pcConstraint->References.getSubValues(); + + for (std::vector::iterator it = selection.begin(); it != selection.end(); ++it){//for every selected object + if (!it->isObjectTypeOf(Part::Feature::getClassTypeId())) { + QMessageBox::warning(this, tr("Selection error"), tr("Selected object is not a part!")); + return; + } + const std::vector& subNames = it->getSubNames(); + App::DocumentObject* obj = it->getObject(); + + for (size_t subIt = 0; subIt < (subNames.size()); ++subIt){// for every selected sub element + bool addMe = true; + if (subNames[subIt].substr(0, 4) != "Face") { + QMessageBox::warning(this, tr("Selection error"), tr("Only faces can be picked")); + return; + } + for (std::vector::iterator itr = std::find(SubElements.begin(), SubElements.end(), subNames[subIt]); + itr != SubElements.end(); + itr = std::find(++itr,SubElements.end(), subNames[subIt])) + {// for every sub element in selection that matches one in old list + if (obj == Objects[std::distance(SubElements.begin(), itr)]){//if selected sub element's object equals the one in old list then it was added before so don't add + addMe=false; + } + } + if (addMe){ + QSignalBlocker block(ui->lw_references); + Objects.push_back(obj); + SubElements.push_back(subNames[subIt]); + ui->lw_references->addItem(makeRefText(obj, subNames[subIt])); + } + } + } + //Update UI + pcConstraint->References.setValues(Objects, SubElements); + updateUI(); +} + +void TaskFemConstraintSpring::removeFromSelection() +{ + std::vector selection = Gui::Selection().getSelectionEx(); //gets vector of selected objects of active document + if (selection.size() == 0){ + QMessageBox::warning(this, tr("Selection error"), tr("Nothing selected!")); + return; + } + Fem::ConstraintSpring* pcConstraint = static_cast(ConstraintView->getObject()); + std::vector Objects = pcConstraint->References.getValues(); + std::vector SubElements = pcConstraint->References.getSubValues(); + std::vector itemsToDel; + for (std::vector::iterator it = selection.begin(); it != selection.end(); ++it){//for every selected object + if (!it->isObjectTypeOf(Part::Feature::getClassTypeId())) { + QMessageBox::warning(this, tr("Selection error"),tr("Selected object is not a part!")); + return; + } + const std::vector& subNames=it->getSubNames(); + App::DocumentObject* obj = it->getObject(); + + for (size_t subIt = 0; subIt < (subNames.size()); ++subIt){// for every selected sub element + for (std::vector::iterator itr = std::find(SubElements.begin(), SubElements.end(), subNames[subIt]); + itr != SubElements.end(); + itr = std::find(++itr,SubElements.end(), subNames[subIt])) + {// for every sub element in selection that matches one in old list + if (obj == Objects[std::distance(SubElements.begin(), itr)]){//if selected sub element's object equals the one in old list then it was added before so mark for deletion + itemsToDel.push_back(std::distance(SubElements.begin(), itr)); + } + } + } + } + std::sort(itemsToDel.begin(), itemsToDel.end()); + while (itemsToDel.size() > 0){ + Objects.erase(Objects.begin() + itemsToDel.back()); + SubElements.erase(SubElements.begin() + itemsToDel.back()); + itemsToDel.pop_back(); + } + //Update UI + { + QSignalBlocker block(ui->lw_references); + ui->lw_references->clear(); + for (unsigned int j = 0; j < Objects.size(); j++) { + ui->lw_references->addItem(makeRefText(Objects[j], SubElements[j])); + } + } + pcConstraint->References.setValues(Objects, SubElements); + updateUI(); +} + +void TaskFemConstraintSpring::onReferenceDeleted() { + TaskFemConstraintSpring::removeFromSelection(); +} + +const std::string TaskFemConstraintSpring::getReferences() const +{ + int rows = ui->lw_references->model()->rowCount(); + std::vector items; + for (int r = 0; r < rows; r++) { + items.push_back(ui->lw_references->item(r)->text().toStdString()); + } + return TaskFemConstraint::getReferences(items); +} + +/* Note: */ +double TaskFemConstraintSpring::get_normalStiffness() const +{ + Base::Quantity stiffness = ui->if_norm->getQuantity(); + double stiffness_double = stiffness.getValueAs(Base::Quantity::NewtonPerMeter); + return stiffness_double; +} + +double TaskFemConstraintSpring::get_tangentialStiffness() const +{ + Base::Quantity stiffness = ui->if_tan->getQuantity(); + double stiffness_double = stiffness.getValueAs(Base::Quantity::NewtonPerMeter); + return stiffness_double; +} + + +bool TaskFemConstraintSpring::event(QEvent *e) +{ + return TaskFemConstraint::KeyEvent(e); +} + +void TaskFemConstraintSpring::changeEvent(QEvent *) +{ +} + +//************************************************************************** +// TaskDialog +//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + +TaskDlgFemConstraintSpring::TaskDlgFemConstraintSpring(ViewProviderFemConstraintSpring *ConstraintView) +{ + this->ConstraintView = ConstraintView; + assert(ConstraintView); + this->parameter = new TaskFemConstraintSpring(ConstraintView); + + Content.push_back(parameter); +} + +//==== calls from the TaskView =============================================================== + +void TaskDlgFemConstraintSpring::open() +{ + // a transaction is already open at creation time of the panel + if (!Gui::Command::hasPendingCommand()) { + QString msg = QObject::tr("Constraint spring"); + Gui::Command::openCommand((const char*)msg.toUtf8()); + ConstraintView->setVisible(true); + Gui::Command::doCommand(Gui::Command::Doc,ViewProviderFemConstraint::gethideMeshShowPartStr((static_cast(ConstraintView->getObject()))->getNameInDocument()).c_str()); //OvG: Hide meshes and show parts + } +} + +bool TaskDlgFemConstraintSpring::accept() +{ +/* Note: */ + std::string name = ConstraintView->getObject()->getNameInDocument(); + const TaskFemConstraintSpring* parameterStiffness = static_cast(parameter); + //const TaskFemConstraintSpring* parameterTan = static_cast(parameter); + + try { + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.normalStiffness = %f", + name.c_str(), parameterStiffness->get_normalStiffness()); + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.tangentialStiffness = %f", + name.c_str(), parameterStiffness->get_tangentialStiffness()); + std::string scale = parameterStiffness->getScale(); //OvG: determine modified scale + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Scale = %s", name.c_str(), scale.c_str()); //OvG: implement modified scale + } + catch (const Base::Exception& e) { + QMessageBox::warning(parameter, tr("Input error"), QString::fromLatin1(e.what())); + return false; + } +/* */ + return TaskDlgFemConstraint::accept(); +} + +bool TaskDlgFemConstraintSpring::reject() +{ + Gui::Command::abortCommand(); + Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()"); + Gui::Command::updateActive(); + + return true; +} + +#include "moc_TaskFemConstraintSpring.cpp" diff --git a/src/Mod/Fem/Gui/TaskFemConstraintSpring.h b/src/Mod/Fem/Gui/TaskFemConstraintSpring.h new file mode 100644 index 0000000000..08d515478a --- /dev/null +++ b/src/Mod/Fem/Gui/TaskFemConstraintSpring.h @@ -0,0 +1,83 @@ +/*************************************************************************** + * Copyright (c) 2015 FreeCAD Developers * + * Authors: Preslav Aleksandrov * + * Based on Force constraint by Jan Rheinländer * + * 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 * + * * + ***************************************************************************/ + + +#ifndef GUI_TASKVIEW_TaskFemConstraintSpring_H +#define GUI_TASKVIEW_TaskFemConstraintSpring_H + +#include +#include +#include +#include + +#include "TaskFemConstraint.h" +#include "ViewProviderFemConstraintSpring.h" + +#include +#include +#include +#include + +class Ui_TaskFemConstraintSpring; + +namespace FemGui { +class TaskFemConstraintSpring : public TaskFemConstraint +{ + Q_OBJECT + +public: + TaskFemConstraintSpring(ViewProviderFemConstraintSpring *ConstraintView,QWidget *parent = 0); + ~TaskFemConstraintSpring(); + const std::string getReferences() const; + double get_normalStiffness()const; + double get_tangentialStiffness()const; + +private Q_SLOTS: + void onReferenceDeleted(void); + void addToSelection(); + void removeFromSelection(); + +protected: + bool event(QEvent *e); + void changeEvent(QEvent *e); + +private: + void updateUI(); + Ui_TaskFemConstraintSpring* ui; + +}; + +class TaskDlgFemConstraintSpring : public TaskDlgFemConstraint +{ + Q_OBJECT + +public: + TaskDlgFemConstraintSpring(ViewProviderFemConstraintSpring *ConstraintView); + void open(); + bool accept(); + bool reject(); +}; + +} //namespace FemGui + +#endif // GUI_TASKVIEW_TaskFemConstraintSpring_H diff --git a/src/Mod/Fem/Gui/TaskFemConstraintSpring.ui b/src/Mod/Fem/Gui/TaskFemConstraintSpring.ui new file mode 100644 index 0000000000..244619cde1 --- /dev/null +++ b/src/Mod/Fem/Gui/TaskFemConstraintSpring.ui @@ -0,0 +1,116 @@ + + + TaskFemConstraintSpring + + + + 0 + 0 + 313 + 321 + + + + Form + + + + + + Select multiple face(s), click Add or Remove + + + + + + + + + Add + + + + + + + Remove + + + + + + + + + + 0 + 0 + + + + + 0 + 0 + + + + + + + + + + + 0 + 0 + + + + + + + + + + + 0 + + + + + + + + + + Normal Stiffness + + + + + + + + 0 + 0 + + + + Tangential Stiffness + + + + + + + + + + Gui::InputField + QLineEdit +
Gui/InputField.h
+
+
+ + +
diff --git a/src/Mod/Fem/Gui/ViewProviderFemConstraint.cpp b/src/Mod/Fem/Gui/ViewProviderFemConstraint.cpp index 33ac5c4c9c..ffdc33782d 100644 --- a/src/Mod/Fem/Gui/ViewProviderFemConstraint.cpp +++ b/src/Mod/Fem/Gui/ViewProviderFemConstraint.cpp @@ -394,6 +394,30 @@ void ViewProviderFemConstraint::updateArrow(const SoNode* node, const int idx, c updateCylinder(sep, idx+CONE_CHILDREN+PLACEMENT_CHILDREN, length-radius, radius/5); } +#define SPRING_CHILDREN (CUBE_CHILDREN + PLACEMENT_CHILDREN + CYLINDER_CHILDREN) + +void ViewProviderFemConstraint::createSpring(SoSeparator* sep, const double length, const double width) +{ + createCube(sep, width, width, length/2); + createPlacement(sep, SbVec3f(0, -length/2, 0), SbRotation()); + createCylinder(sep, length/2, width/4); +} + +SoSeparator* ViewProviderFemConstraint::createSpring(const double length, const double width) +{ + SoSeparator* sep = new SoSeparator(); + createSpring(sep, length, width); + return sep; +} + +void ViewProviderFemConstraint::updateSpring(const SoNode* node, const int idx, const double length, const double width) +{ + const SoSeparator* sep = static_cast(node); + updateCube(sep, idx, width, width, length/2); + updatePlacement(sep, idx+CUBE_CHILDREN, SbVec3f(0, -length/2, 0), SbRotation()); + updateCylinder(sep, idx+CUBE_CHILDREN+PLACEMENT_CHILDREN, length/2, width/4); +} + #define FIXED_CHILDREN (CONE_CHILDREN + PLACEMENT_CHILDREN + CUBE_CHILDREN) void ViewProviderFemConstraint::createFixed(SoSeparator* sep, const double height, const double width, const bool gap) diff --git a/src/Mod/Fem/Gui/ViewProviderFemConstraint.h b/src/Mod/Fem/Gui/ViewProviderFemConstraint.h index f32687b473..4eb076dd48 100644 --- a/src/Mod/Fem/Gui/ViewProviderFemConstraint.h +++ b/src/Mod/Fem/Gui/ViewProviderFemConstraint.h @@ -89,6 +89,9 @@ protected: static void createArrow(SoSeparator* sep, const double length, const double radius); static SoSeparator* createArrow(const double length, const double radius); static void updateArrow(const SoNode* node, const int idx, const double length, const double radius); + static void createSpring(SoSeparator* sep, const double length, const double width); + static SoSeparator* createSpring(const double length, const double width); + static void updateSpring(const SoNode* node, const int idx, const double length, const double width); static void createFixed(SoSeparator* sep, const double height, const double width, const bool gap = false); static SoSeparator* createFixed(const double height, const double width, const bool gap = false); static void updateFixed(const SoNode* node, const int idx, const double height, const double width, const bool gap = false); diff --git a/src/Mod/Fem/Gui/ViewProviderFemConstraintSpring.cpp b/src/Mod/Fem/Gui/ViewProviderFemConstraintSpring.cpp new file mode 100644 index 0000000000..f6c5ab5f29 --- /dev/null +++ b/src/Mod/Fem/Gui/ViewProviderFemConstraintSpring.cpp @@ -0,0 +1,156 @@ +/*************************************************************************** + * Copyright (c) 2015 FreeCAD Developers * + * Author: Preslav Aleksandrov * + * Based on Force constraint by Jan Rheinländer * + * 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 +# include +# include +# include +#endif + +#include "Mod/Fem/App/FemConstraintSpring.h" +#include "TaskFemConstraintSpring.h" //TODO do next +#include "ViewProviderFemConstraintSpring.h" +#include +#include + +using namespace FemGui; + +PROPERTY_SOURCE(FemGui::ViewProviderFemConstraintSpring, FemGui::ViewProviderFemConstraint) + +ViewProviderFemConstraintSpring::ViewProviderFemConstraintSpring() +{ + sPixmap = "FEM_ConstraintSpring"; + ADD_PROPERTY(FaceColor,(0.0f,0.2f,0.8f)); +} + +ViewProviderFemConstraintSpring::~ViewProviderFemConstraintSpring() +{ +} + +//FIXME setEdit needs a careful review +bool ViewProviderFemConstraintSpring::setEdit(int ModNum) +{ + if (ModNum == ViewProvider::Default) { + // When double-clicking on the item for this constraint the + // object unsets and sets its edit mode without closing + // the task panel + Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog(); + TaskDlgFemConstraintSpring *constrDlg = qobject_cast(dlg); // check this out too + if (constrDlg && constrDlg->getConstraintView() != this) + constrDlg = 0; // another constraint left open its task panel + if (dlg && !constrDlg) { + if (constraintDialog != NULL) { + // Ignore the request to open another dialog + return false; + } else { + constraintDialog = new TaskFemConstraintSpring(this); + return true; + } + } + + // clear the selection (convenience) + Gui::Selection().clearSelection(); + + // start the edit dialog + if (constrDlg) + Gui::Control().showDialog(constrDlg); + else + Gui::Control().showDialog(new TaskDlgFemConstraintSpring(this)); + return true; + } + else { + return ViewProviderDocumentObject::setEdit(ModNum); + } +} + +#define WIDTH (1) +#define LENGTH (2) +//#define USE_MULTIPLE_COPY //OvG: MULTICOPY fails to update scaled arrows on initial drawing - so disable + +void ViewProviderFemConstraintSpring::updateData(const App::Property* prop) +{ + // Gets called whenever a property of the attached object changes + Fem::ConstraintSpring* pcConstraint = static_cast(this->getObject()); + float scaledwidth = WIDTH * pcConstraint->Scale.getValue(); //OvG: Calculate scaled values once only + float scaledlength = LENGTH * pcConstraint->Scale.getValue(); + +#ifdef USE_MULTIPLE_COPY + //OvG: always need access to cp for scaling + SoMultipleCopy* cp = new SoMultipleCopy(); + if (pShapeSep->getNumChildren() == 0) { + // Set up the nodes + cp->matrix.setNum(0); + cp->addChild((SoNode*)createSpring(scaledlength, scaledwidth)); //OvG: Scaling + pShapeSep->addChild(cp); + } +#endif + + if (strcmp(prop->getName(),"Points") == 0) { + const std::vector& points = pcConstraint->Points.getValues(); + const std::vector& normals = pcConstraint->Normals.getValues(); + if (points.size() != normals.size()) { + return; + } + std::vector::const_iterator n = normals.begin(); + +#ifdef USE_MULTIPLE_COPY + cp = static_cast(pShapeSep->getChild(0)); //OvG: Use top cp + cp->matrix.setNum(points.size()); + SbMatrix* matrices = cp->matrix.startEditing(); + int idx = 0; +#else + // Redraw all cylinders + Gui::coinRemoveAllChildren(pShapeSep); +#endif + + for (std::vector::const_iterator p = points.begin(); p != points.end(); p++) { + SbVec3f base(p->x, p->y, p->z); + SbVec3f dir(n->x, n->y, n->z); + SbRotation rot(SbVec3f(0, -1.0, 0), dir); +#ifdef USE_MULTIPLE_COPY + SbMatrix m; + m.setTransform(base, rot, SbVec3f(1,1,1)); + matrices[idx] = m; + idx++; +#else + SoSeparator* sep = new SoSeparator(); + createPlacement(sep, base, rot); + createSpring(sep, scaledlength , scaledwidth); //OvG: Scaling + pShapeSep->addChild(sep); +#endif + n++; + } +#ifdef USE_MULTIPLE_COPY + cp->matrix.finishEditing(); +#endif + } + + ViewProviderFemConstraint::updateData(prop); +} diff --git a/src/Mod/Fem/Gui/ViewProviderFemConstraintSpring.h b/src/Mod/Fem/Gui/ViewProviderFemConstraintSpring.h new file mode 100644 index 0000000000..c9e9aa32d8 --- /dev/null +++ b/src/Mod/Fem/Gui/ViewProviderFemConstraintSpring.h @@ -0,0 +1,46 @@ +/*************************************************************************** + * Copyright (c) 2021 FreeCAD Developers * + * Author: Preslav Aleksandrov * + * Based on Force constraint by Jan Rheinländer * + * 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 * + * * + ***************************************************************************/ + +#ifndef GUI_VIEWPROVIDERFEMCONSTRAINTSPRING_H +#define GUI_VIEWPROVIDERFEMCONSTRAINTSPRING_H + +#include "ViewProviderFemConstraint.h" + +namespace FemGui { + +class FemGuiExport ViewProviderFemConstraintSpring : public FemGui::ViewProviderFemConstraint +{ + PROPERTY_HEADER(FemGui::ViewProviderFemConstraintSpring); + +public: + ViewProviderFemConstraintSpring(); + virtual ~ViewProviderFemConstraintSpring(); + virtual void updateData(const App::Property*); + +protected: + virtual bool setEdit(int ModNum); +}; + +} + +#endif // GUI_VIEWPROVIDERFEMCONSTRAINTSPRING_H diff --git a/src/Mod/Fem/Gui/Workbench.cpp b/src/Mod/Fem/Gui/Workbench.cpp index 238c31a142..2dd0114567 100755 --- a/src/Mod/Fem/Gui/Workbench.cpp +++ b/src/Mod/Fem/Gui/Workbench.cpp @@ -139,6 +139,7 @@ Gui::ToolBarItem* Workbench::setupToolBars() const << "FEM_ConstraintDisplacement" << "FEM_ConstraintContact" << "FEM_ConstraintTie" + << "FEM_ConstraintSpring" << "Separator" << "FEM_ConstraintForce" << "FEM_ConstraintPressure" @@ -266,6 +267,7 @@ Gui::MenuItem* Workbench::setupMenuBar() const << "FEM_ConstraintDisplacement" << "FEM_ConstraintContact" << "FEM_ConstraintTie" + << "FEM_ConstraintSpring" << "Separator" << "FEM_ConstraintForce" << "FEM_ConstraintPressure" diff --git a/src/Mod/Fem/ObjectsFem.py b/src/Mod/Fem/ObjectsFem.py index bc99add23a..5d9a8b51cd 100644 --- a/src/Mod/Fem/ObjectsFem.py +++ b/src/Mod/Fem/ObjectsFem.py @@ -335,6 +335,16 @@ def makeConstraintSectionPrint( return obj +def makeConstraintSpring( + doc, + name="ConstraintSpring" +): + """makeConstraintSpring(document, [name]): + makes a Fem ConstraintSpring object""" + obj = doc.addObject("Fem::ConstraintSpring", name) + return obj + + # ********* element definition objects *********************************************************** def makeElementFluid1D( doc, diff --git a/src/Mod/Fem/femtest/app/test_object.py b/src/Mod/Fem/femtest/app/test_object.py index 89371f1714..1ec683da3e 100644 --- a/src/Mod/Fem/femtest/app/test_object.py +++ b/src/Mod/Fem/femtest/app/test_object.py @@ -193,6 +193,10 @@ class TestObjectType(unittest.TestCase): "Fem::ConstraintFluidBoundary", type_of_obj(ObjectsFem.makeConstraintFluidBoundary(doc)) ) + self.assertEqual( + "Fem::ConstraintSpring", + type_of_obj(ObjectsFem.makeConstraintSpring(doc)) + ) self.assertEqual( "Fem::ConstraintForce", type_of_obj(ObjectsFem.makeConstraintForce(doc)) @@ -410,6 +414,10 @@ class TestObjectType(unittest.TestCase): ObjectsFem.makeConstraintFluidBoundary(doc), "Fem::ConstraintFluidBoundary" )) + self.assertTrue(is_of_type( + ObjectsFem.makeConstraintSpring(doc), + "Fem::ConstraintSpring" + )) self.assertTrue(is_of_type( ObjectsFem.makeConstraintForce(doc), "Fem::ConstraintForce" @@ -737,6 +745,21 @@ class TestObjectType(unittest.TestCase): "Fem::ConstraintFluidBoundary" )) + # ConstraintSpring + constraint_spring = ObjectsFem.makeConstraintSpring(doc) + self.assertTrue(is_derived_from( + constraint_spring, + "App::DocumentObject" + )) + self.assertTrue(is_derived_from( + constraint_spring, + "Fem::Constraint" + )) + self.assertTrue(is_derived_from( + constraint_spring, + "Fem::ConstraintSpring" + )) + # ConstraintForce constraint_force = ObjectsFem.makeConstraintForce(doc) self.assertTrue(is_derived_from( @@ -1415,6 +1438,11 @@ class TestObjectType(unittest.TestCase): doc ).isDerivedFrom("Fem::ConstraintFluidBoundary") ) + self.assertTrue( + ObjectsFem.makeConstraintSpring( + doc + ).isDerivedFrom("Fem::ConstraintSpring") + ) self.assertTrue( ObjectsFem.makeConstraintForce( doc @@ -1645,6 +1673,7 @@ def create_all_fem_objects_doc( analysis.addObject(ObjectsFem.makeConstraintFixed(doc)) analysis.addObject(ObjectsFem.makeConstraintFlowVelocity(doc)) analysis.addObject(ObjectsFem.makeConstraintFluidBoundary(doc)) + analysis.addObject(ObjectsFem.makeConstraintSpring(doc)) analysis.addObject(ObjectsFem.makeConstraintForce(doc)) analysis.addObject(ObjectsFem.makeConstraintGear(doc)) analysis.addObject(ObjectsFem.makeConstraintHeatflux(doc)) From e011250548e052d07f256ce68c57f2b30c769437 Mon Sep 17 00:00:00 2001 From: mwganson Date: Fri, 17 Sep 2021 12:47:57 -0500 Subject: [PATCH 32/55] [Macros Dialog] Add 2 new parameters: DuplicateIgnoreExtraNote and DuplicateReplaceSpaces --- src/Gui/DlgMacroExecuteImp.cpp | 38 +++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/src/Gui/DlgMacroExecuteImp.cpp b/src/Gui/DlgMacroExecuteImp.cpp index e19450c49f..0c095386c6 100644 --- a/src/Gui/DlgMacroExecuteImp.cpp +++ b/src/Gui/DlgMacroExecuteImp.cpp @@ -718,6 +718,20 @@ void DlgMacroExecuteImp::on_duplicateButton_clicked() bool from001 = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Macro")->GetBool("DuplicateFrom001", false); App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Macro")->SetBool("DuplicateFrom001", from001); //create parameter + + //A user may wish to add a note to end of the filename when duplicating + //example: mymacro@005.fix_bug_in_dialog.FCMacro + //and then when duplicating to have the extra note removed so the suggested new name is: + //mymacro@006.FCMacro instead of mymacro@006.fix_bug_in_dialog.FCMacro since the new duplicate will be given a new note + + bool ignoreExtra = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Macro")->GetBool("DuplicateIgnoreExtraNote", false); + App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Macro")->SetBool("DuplicateIgnoreExtraNote", ignoreExtra); //create parameter + + //when creating a note it will be convenient to convert spaces to underscores if the user desires this behavior + + bool replaceSpaces = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Macro")->GetBool("DuplicateReplaceSpaces", false); + App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Macro")->SetBool("DuplicateReplaceSpaces", replaceSpaces); //create parameter + int index = ui->tabMacroWidget->currentIndex(); if (index == 0) { //user-specific item = ui->userMacroListBox->currentItem(); @@ -732,6 +746,7 @@ void DlgMacroExecuteImp::on_duplicateButton_clicked() QFileInfo oldfi(dir, oldName); QFile oldfile(oldfi.absoluteFilePath()); QString completeSuffix = oldfi.completeSuffix(); //everything after the first "." + QString extraNote = completeSuffix.left(completeSuffix.size()-oldfi.suffix().size()); QString baseName = oldfi.baseName(); //everything before first "." QString neutralSymbol = QString::fromStdString("@"); QString last3 = baseName.right(3); @@ -752,14 +767,28 @@ void DlgMacroExecuteImp::on_duplicateButton_clicked() } //at this point baseName = the base name without any digits, e.g. "MyMacro" //neutralSymbol = "@" - //last3 is a string representing 3 digits, always "001" at this time + //last3 is a string representing 3 digits, always "001" //unless from001 = false, in which case we begin with previous numbers //completeSuffix = FCMacro or py or FCMacro.py or else suffix will become FCMacro below + //if ignoreExtra any extra notes added between @NN. and .FCMacro will be ignored + //when suggesting a new filename + + if(ignoreExtra && !extraNote.isEmpty()){ + nLast3++; + last3 = QString::number(nLast3); + while (last3.size()<3){ + last3.prepend(QString::fromStdString("0")); //pad 0's if needed + } + } + QString oldNameDigitized = baseName+neutralSymbol+last3+QString::fromStdString(".")+completeSuffix; QFileInfo fi(dir, oldNameDigitized); + + // increment until we find available name with smallest digits // test from "001" through "999", then give up and let user enter name of choice + while (fi.exists()) { nLast3 = last3.toInt()+1; if (nLast3 >=1000){ //avoid infinite loop, 999 files will have to be enough @@ -773,10 +802,17 @@ void DlgMacroExecuteImp::on_duplicateButton_clicked() fi = QFileInfo(dir,oldNameDigitized); } + if(ignoreExtra && !extraNote.isEmpty()){ + oldNameDigitized = oldNameDigitized.remove(extraNote); + } + // give user a chance to pick a different name from digitized name suggested QString fn = QInputDialog::getText(this, tr("Duplicate Macro"), tr("Enter new name:"), QLineEdit::Normal, oldNameDigitized, nullptr, Qt::MSWindowsFixedSizeDialogHint); + if (replaceSpaces){ + fn = fn.replace(QString::fromStdString(" "),QString::fromStdString("_")); + } if (!fn.isEmpty() && fn != oldName) { QString suffix = QFileInfo(fn).suffix().toLower(); if (suffix != QLatin1String("fcmacro") && suffix != QLatin1String("py")){ From 301758d85173633c6673f17d3051a09721b9408b Mon Sep 17 00:00:00 2001 From: mwganson Date: Fri, 17 Sep 2021 14:04:01 -0500 Subject: [PATCH 33/55] [Macros Dialog]rename DuplicateReplaceSpaces parameter to ReplaceSpaces, make it default = true, apply also to new file creation and renaming in the dialog --- src/Gui/DlgMacroExecuteImp.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/Gui/DlgMacroExecuteImp.cpp b/src/Gui/DlgMacroExecuteImp.cpp index 0c095386c6..3cb83d54b9 100644 --- a/src/Gui/DlgMacroExecuteImp.cpp +++ b/src/Gui/DlgMacroExecuteImp.cpp @@ -350,8 +350,16 @@ void DlgMacroExecuteImp::on_editButton_clicked() void DlgMacroExecuteImp::on_createButton_clicked() { // query file name + bool replaceSpaces = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Macro")->GetBool("ReplaceSpaces", true); + App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Macro")->SetBool("ReplaceSpaces", replaceSpaces); //create parameter + QString fn = QInputDialog::getText(this, tr("Macro file"), tr("Enter a file name, please:"), QLineEdit::Normal, QString(), nullptr, Qt::MSWindowsFixedSizeDialogHint); + + if(replaceSpaces){ + fn = fn.replace(QString::fromStdString(" "),QString::fromStdString("_")); + } + if (!fn.isEmpty()) { QString suffix = QFileInfo(fn).suffix().toLower(); @@ -674,6 +682,9 @@ void DlgMacroExecuteImp::on_renameButton_clicked() if (!item) return; + bool replaceSpaces = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Macro")->GetBool("ReplaceSpaces", true); + App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Macro")->SetBool("ReplaceSpaces", replaceSpaces); //create parameter + QString oldName = item->text(0); QFileInfo oldfi(dir, oldName); QFile oldfile(oldfi.absoluteFilePath()); @@ -681,6 +692,11 @@ void DlgMacroExecuteImp::on_renameButton_clicked() // query new name QString fn = QInputDialog::getText(this, tr("Renaming Macro File"), tr("Enter new name:"), QLineEdit::Normal, oldName, nullptr, Qt::MSWindowsFixedSizeDialogHint); + + if(replaceSpaces){ + fn = fn.replace(QString::fromStdString(" "),QString::fromStdString("_")); + } + if (!fn.isEmpty() && fn != oldName) { QString suffix = QFileInfo(fn).suffix().toLower(); if (suffix != QLatin1String("fcmacro") && suffix != QLatin1String("py")) @@ -729,8 +745,8 @@ void DlgMacroExecuteImp::on_duplicateButton_clicked() //when creating a note it will be convenient to convert spaces to underscores if the user desires this behavior - bool replaceSpaces = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Macro")->GetBool("DuplicateReplaceSpaces", false); - App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Macro")->SetBool("DuplicateReplaceSpaces", replaceSpaces); //create parameter + bool replaceSpaces = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Macro")->GetBool("ReplaceSpaces", true); + App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Macro")->SetBool("ReplaceSpaces", replaceSpaces); //create parameter int index = ui->tabMacroWidget->currentIndex(); if (index == 0) { //user-specific From 9afc4503abf55df7c189f7c7338c71c3e55b6ea9 Mon Sep 17 00:00:00 2001 From: Chris Hennes Date: Sun, 22 Aug 2021 14:49:15 -0500 Subject: [PATCH 34/55] [Sketcher] Refactor split code LGTM complains about using continue statements inside a loop whose condition is always false. In addition, the C++ core guidelines recommend against using the do...while construct, and in this case it was really serving as a goto, just hiding the actual goto keyword. This commit replaces the loop and continue structure with simple conditionals. --- src/Mod/Sketcher/App/SketchObject.cpp | 205 +++++++++++++------------- 1 file changed, 99 insertions(+), 106 deletions(-) diff --git a/src/Mod/Sketcher/App/SketchObject.cpp b/src/Mod/Sketcher/App/SketchObject.cpp index 29531d61bf..ac03e294ec 100644 --- a/src/Mod/Sketcher/App/SketchObject.cpp +++ b/src/Mod/Sketcher/App/SketchObject.cpp @@ -2982,156 +2982,149 @@ int SketchObject::split(int GeoId, const Base::Vector3d &point) std::vector newGeometries; std::vector newIds; std::vector newConstraints; - bool ok = false; Base::Vector3d startPoint, endPoint, splitPoint; double radius, startAngle, endAngle, splitAngle; unsigned int longestPart = 0; - do { - if (geo->getTypeId() == Part::GeomLineSegment::getClassTypeId()) { - const Part::GeomLineSegment *lineSegm = static_cast(geo); - startPoint = lineSegm->getStartPoint(); - endPoint = lineSegm->getEndPoint(); - splitPoint = point.Perpendicular(startPoint, endPoint - startPoint); - if ((endPoint - splitPoint).Length() > (splitPoint - startPoint).Length()) { - longestPart = 1; - } + bool ok = false; + if (geo->getTypeId() == Part::GeomLineSegment::getClassTypeId()) { + const Part::GeomLineSegment *lineSegm = static_cast(geo); - Part::GeomLineSegment *newLine = static_cast(lineSegm->copy()); - newGeometries.push_back(newLine); + startPoint = lineSegm->getStartPoint(); + endPoint = lineSegm->getEndPoint(); + splitPoint = point.Perpendicular(startPoint, endPoint - startPoint); + if ((endPoint - splitPoint).Length() > (splitPoint - startPoint).Length()) { + longestPart = 1; + } - newLine->setPoints(startPoint, splitPoint); - int newId = addGeometry(newLine); - if (newId < 0) { - continue; - } + Part::GeomLineSegment *newLine = static_cast(lineSegm->copy()); + newGeometries.push_back(newLine); + + newLine->setPoints(startPoint, splitPoint); + int newId = addGeometry(newLine); + if (newId >= 0) { newIds.push_back(newId); setConstruction(newId, GeometryFacade::getConstruction(geo)); - newLine = static_cast(lineSegm->copy()); + newLine = static_cast(lineSegm->copy()); newGeometries.push_back(newLine); newLine->setPoints(splitPoint, endPoint); newId = addGeometry(newLine); - if (newId < 0) { - continue; + if (newId >= 0) { + newIds.push_back(newId); + setConstruction(newId, GeometryFacade::getConstruction(geo)); + + Constraint* joint = new Constraint(); + joint->Type = Coincident; + joint->First = newIds[0]; + joint->FirstPos = end; + joint->Second = newIds[1]; + joint->SecondPos = start; + newConstraints.push_back(joint); + + transferConstraints(GeoId, start, newIds[0], start, true); + transferConstraints(GeoId, end, newIds[1], end, true); + ok = true; } - newIds.push_back(newId); - setConstruction(newId, GeometryFacade::getConstruction(geo)); - - Constraint *joint = new Constraint(); - joint->Type = Coincident; - joint->First = newIds[0]; - joint->FirstPos = end; - joint->Second = newIds[1]; - joint->SecondPos = start; - newConstraints.push_back(joint); - - transferConstraints(GeoId, start, newIds[0], start, true); - transferConstraints(GeoId, end, newIds[1], end, true); - ok = true; } - else if (geo->getTypeId() == Part::GeomCircle::getClassTypeId()) { - const Part::GeomCircle *circle = static_cast(geo); + } + else if (geo->getTypeId() == Part::GeomCircle::getClassTypeId()) { + const Part::GeomCircle *circle = static_cast(geo); - Base::Vector3d center(circle->getLocation()); - Base::Vector3d dir(point - center); - radius = circle->getRadius(); + Base::Vector3d center(circle->getLocation()); + Base::Vector3d dir(point - center); + radius = circle->getRadius(); - splitAngle = atan2(dir.y, dir.x); - startAngle = splitAngle; - endAngle = splitAngle + M_PI*2.0; + splitAngle = atan2(dir.y, dir.x); + startAngle = splitAngle; + endAngle = splitAngle + M_PI*2.0; - splitPoint = Base::Vector3d(center.x + radius*cos(splitAngle), center.y + radius*sin(splitAngle)); - startPoint = splitPoint; - endPoint = splitPoint; + splitPoint = Base::Vector3d(center.x + radius*cos(splitAngle), center.y + radius*sin(splitAngle)); + startPoint = splitPoint; + endPoint = splitPoint; - Part::GeomArcOfCircle *arc = new Part::GeomArcOfCircle(); - newGeometries.push_back(arc); + Part::GeomArcOfCircle *arc = new Part::GeomArcOfCircle(); + newGeometries.push_back(arc); - arc->setLocation(center); - arc->setRadius(radius); - arc->setRange(startAngle, endAngle, false); - int arcId = addGeometry(arc); - if (arcId < 0) { - continue; - } + arc->setLocation(center); + arc->setRadius(radius); + arc->setRange(startAngle, endAngle, false); + int arcId = addGeometry(arc); + if (arcId >= 0) { newIds.push_back(arcId); setConstruction(arcId, GeometryFacade::getConstruction(geo)); transferConstraints(GeoId, mid, arcId, mid); ok = true; } - else if (geo->getTypeId() == Part::GeomArcOfCircle::getClassTypeId()) { - const Part::GeomArcOfCircle *arc = static_cast(geo); + } + else if (geo->getTypeId() == Part::GeomArcOfCircle::getClassTypeId()) { + const Part::GeomArcOfCircle *arc = static_cast(geo); - startPoint = arc->getStartPoint(); - endPoint = arc->getEndPoint(); + startPoint = arc->getStartPoint(); + endPoint = arc->getEndPoint(); - Base::Vector3d center(arc->getLocation()); - radius = arc->getRadius(); - arc->getRange(startAngle, endAngle, false); + Base::Vector3d center(arc->getLocation()); + radius = arc->getRadius(); + arc->getRange(startAngle, endAngle, false); - Base::Vector3d dir(point - center); - splitAngle = atan2(dir.y, dir.x); - if (splitAngle < startAngle) { - splitAngle += M_PI*2.0; - } - if (endAngle - splitAngle > splitAngle - startAngle) { - longestPart = 1; - } + Base::Vector3d dir(point - center); + splitAngle = atan2(dir.y, dir.x); + if (splitAngle < startAngle) { + splitAngle += M_PI*2.0; + } + if (endAngle - splitAngle > splitAngle - startAngle) { + longestPart = 1; + } - splitPoint = Base::Vector3d(center.x + radius*cos(splitAngle), center.y + radius*sin(splitAngle)); - startPoint = splitPoint; - endPoint = splitPoint; + splitPoint = Base::Vector3d(center.x + radius*cos(splitAngle), center.y + radius*sin(splitAngle)); + startPoint = splitPoint; + endPoint = splitPoint; - Part::GeomArcOfCircle *newArc = static_cast(arc->copy()); - newGeometries.push_back(newArc); + Part::GeomArcOfCircle *newArc = static_cast(arc->copy()); + newGeometries.push_back(newArc); - newArc->setRange(startAngle, splitAngle, false); - int newId = addGeometry(newArc); - if (newId < 0) { - continue; - } + newArc->setRange(startAngle, splitAngle, false); + int newId = addGeometry(newArc); + if (newId >= 0) { newIds.push_back(newId); setConstruction(newId, GeometryFacade::getConstruction(geo)); - newArc = static_cast(arc->copy()); + newArc = static_cast(arc->copy()); newGeometries.push_back(newArc); newArc->setRange(splitAngle, endAngle, false); newId = addGeometry(newArc); - if (newId < 0) { - continue; + if (newId >= 0) { + newIds.push_back(newId); + setConstruction(newId, GeometryFacade::getConstruction(geo)); + + Constraint* joint = new Constraint(); + joint->Type = Coincident; + joint->First = newIds[0]; + joint->FirstPos = end; + joint->Second = newIds[1]; + joint->SecondPos = start; + newConstraints.push_back(joint); + + joint = new Constraint(); + joint->Type = Coincident; + joint->First = newIds[0]; + joint->FirstPos = mid; + joint->Second = newIds[1]; + joint->SecondPos = mid; + newConstraints.push_back(joint); + + transferConstraints(GeoId, start, newIds[0], start, true); + transferConstraints(GeoId, mid, newIds[0], mid); + transferConstraints(GeoId, end, newIds[1], end, true); + ok = true; } - newIds.push_back(newId); - setConstruction(newId, GeometryFacade::getConstruction(geo)); - - Constraint *joint = new Constraint(); - joint->Type = Coincident; - joint->First = newIds[0]; - joint->FirstPos = end; - joint->Second = newIds[1]; - joint->SecondPos = start; - newConstraints.push_back(joint); - - joint = new Constraint(); - joint->Type = Coincident; - joint->First = newIds[0]; - joint->FirstPos = mid; - joint->Second = newIds[1]; - joint->SecondPos = mid; - newConstraints.push_back(joint); - - transferConstraints(GeoId, start, newIds[0], start, true); - transferConstraints(GeoId, mid, newIds[0], mid); - transferConstraints(GeoId, end, newIds[1], end, true); - ok = true; } } - while (false); if (ok) { std::vector oldConstraints; From de3e44a11795cd8ec9d005bef6030a821b491f6f Mon Sep 17 00:00:00 2001 From: Syres916 <46537884+Syres916@users.noreply.github.com> Date: Sat, 18 Sep 2021 11:19:42 +0100 Subject: [PATCH 35/55] [AddonManager] Handle stderr from git status See discussion https://forum.freecadweb.org/viewtopic.php?f=10&t=62265 --- src/Mod/AddonManager/addonmanager_workers.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/Mod/AddonManager/addonmanager_workers.py b/src/Mod/AddonManager/addonmanager_workers.py index 470d5b7bc3..04be5c935f 100644 --- a/src/Mod/AddonManager/addonmanager_workers.py +++ b/src/Mod/AddonManager/addonmanager_workers.py @@ -259,11 +259,16 @@ class CheckWBWorker(QtCore.QThread): except Exception: print("AddonManager: Unable to fetch git updates for repo", repo[0]) else: - if "git pull" in gitrepo.status(): - self.mark.emit(repo[0]) - upds.append(repo[0]) - # mark as already installed AND already checked for updates AND update available - self.repos[self.repos.index(repo)][2] = 3 + try: + if "git pull" in gitrepo.status(): + self.mark.emit(repo[0]) + upds.append(repo[0]) + # mark as already installed AND already checked for updates AND update available + self.repos[self.repos.index(repo)][2] = 3 + except stderr: + FreeCAD.Console.PrintWarning(translate("AddonsInstaller", + "AddonManager - " + repo[0]) + " git status" + " fatal: this operation must be run in a work tree \n") self.addon_repos.emit(self.repos) self.enable.emit(len(upds)) self.stop = True From b3dbcd9ff8c0bd1c8b84ea32b9fa620060b7b268 Mon Sep 17 00:00:00 2001 From: troyp76 <86191547+troyp76@users.noreply.github.com> Date: Sat, 18 Sep 2021 01:03:09 +1000 Subject: [PATCH 36/55] Improved chamfer behavior when faces are selected Improved chamfer behavior when faces are selected and non equal chamfer types are used --- src/Mod/PartDesign/App/FeatureChamfer.cpp | 37 ++++++++++++++++++----- src/Mod/PartDesign/App/FeatureDressUp.cpp | 8 +++++ src/Mod/PartDesign/App/FeatureDressUp.h | 2 ++ 3 files changed, 39 insertions(+), 8 deletions(-) diff --git a/src/Mod/PartDesign/App/FeatureChamfer.cpp b/src/Mod/PartDesign/App/FeatureChamfer.cpp index 24c20482c1..06eee9cf15 100644 --- a/src/Mod/PartDesign/App/FeatureChamfer.cpp +++ b/src/Mod/PartDesign/App/FeatureChamfer.cpp @@ -115,7 +115,9 @@ App::DocumentObjectExecReturn *Chamfer::execute(void) } std::vector SubNames = std::vector(Base.getSubValues()); - getContinuousEdges(TopShape, SubNames); + std::vector FaceNames; + + getContinuousEdges(TopShape, SubNames, FaceNames); if (SubNames.size() == 0) return new App::DocumentObjectExecReturn("No edges specified"); @@ -138,16 +140,35 @@ App::DocumentObjectExecReturn *Chamfer::execute(void) try { BRepFilletAPI_MakeChamfer mkChamfer(baseShape.getShape()); - TopTools_IndexedMapOfShape mapOfEdges; TopTools_IndexedDataMapOfShapeListOfShape mapEdgeFace; TopExp::MapShapesAndAncestors(baseShape.getShape(), TopAbs_EDGE, TopAbs_FACE, mapEdgeFace); - TopExp::MapShapes(baseShape.getShape(), TopAbs_EDGE, mapOfEdges); - for (std::vector::const_iterator it=SubNames.begin(); it != SubNames.end(); ++it) { - TopoDS_Edge edge = TopoDS::Edge(baseShape.getSubShape(it->c_str())); - const TopoDS_Face& face = (chamferType != 0 && flipDirection) ? - TopoDS::Face(mapEdgeFace.FindFromKey(edge).Last()) : - TopoDS::Face(mapEdgeFace.FindFromKey(edge).First()); + for (const auto &itSN : SubNames) { + TopoDS_Edge edge = TopoDS::Edge(baseShape.getSubShape(itSN.c_str())); + + const TopoDS_Shape& faceLast = mapEdgeFace.FindFromKey(edge).Last(); + const TopoDS_Shape& faceFirst = mapEdgeFace.FindFromKey(edge).First(); + + // Set the face based on flipDirection for all edges by default. Note for chamferType==0 it does not matter which face is used. + TopoDS_Face face = TopoDS::Face( flipDirection ? faceLast : faceFirst ); + + // for chamfer types otherthan Equal (type = 0) check if one of the faces associated with the edge + // is one of the originally selected faces. If so use the other face by default or the selected face if "flipDirection" is set + if (chamferType != 0) { + + // for each selected face + for (const auto &itFN : FaceNames) { + const TopoDS_Shape selFace = baseShape.getSubShape(itFN.c_str()); + + if ( faceLast.IsEqual(selFace) ) + face = TopoDS::Face( flipDirection ? faceFirst : faceLast ); + + else if ( faceFirst.IsEqual(selFace) ) + face = TopoDS::Face( flipDirection ? faceLast : faceFirst ); + } + + } + switch (chamferType) { case 0: // Equal distance mkChamfer.Add(size, size, edge, face); diff --git a/src/Mod/PartDesign/App/FeatureDressUp.cpp b/src/Mod/PartDesign/App/FeatureDressUp.cpp index 67daa010d1..430eac64ba 100644 --- a/src/Mod/PartDesign/App/FeatureDressUp.cpp +++ b/src/Mod/PartDesign/App/FeatureDressUp.cpp @@ -99,6 +99,13 @@ Part::Feature *DressUp::getBaseObject(bool silent) const void DressUp::getContinuousEdges(Part::TopoShape TopShape, std::vector< std::string >& SubNames) { + std::vector< std::string > FaceNames; + + getContinuousEdges(TopShape, SubNames, FaceNames); +} + +void DressUp::getContinuousEdges(Part::TopoShape TopShape, std::vector< std::string >& SubNames, std::vector< std::string >& FaceNames) { + TopTools_IndexedMapOfShape mapOfEdges; TopTools_IndexedDataMapOfShapeListOfShape mapEdgeFace; TopExp::MapShapesAndAncestors(TopShape.getShape(), TopAbs_EDGE, TopAbs_FACE, mapEdgeFace); @@ -153,6 +160,7 @@ void DressUp::getContinuousEdges(Part::TopoShape TopShape, std::vector< std::str } + FaceNames.push_back(aSubName.c_str()); SubNames.erase(SubNames.begin()+i); } // empty name or any other sub-element diff --git a/src/Mod/PartDesign/App/FeatureDressUp.h b/src/Mod/PartDesign/App/FeatureDressUp.h index 61831ee8e8..1a590ba26b 100644 --- a/src/Mod/PartDesign/App/FeatureDressUp.h +++ b/src/Mod/PartDesign/App/FeatureDressUp.h @@ -59,6 +59,8 @@ public: /// extracts all edges from the subshapes (including face edges) and furthermore adds /// all C0 continuous edges to the vector void getContinuousEdges(Part::TopoShape, std::vector< std::string >&); + // add argument to return the selected face that edges were derived from + void getContinuousEdges(Part::TopoShape, std::vector< std::string >&, std::vector< std::string >&); virtual void getAddSubShape(Part::TopoShape &addShape, Part::TopoShape &subShape); From 842abfcee47b12d32baf1f6ea84edf109be9290e Mon Sep 17 00:00:00 2001 From: Syres916 <46537884+Syres916@users.noreply.github.com> Date: Sat, 18 Sep 2021 13:05:36 +0100 Subject: [PATCH 37/55] [AddonManager] stderr remove translate --- src/Mod/AddonManager/addonmanager_workers.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Mod/AddonManager/addonmanager_workers.py b/src/Mod/AddonManager/addonmanager_workers.py index 04be5c935f..ba12996a78 100644 --- a/src/Mod/AddonManager/addonmanager_workers.py +++ b/src/Mod/AddonManager/addonmanager_workers.py @@ -266,9 +266,8 @@ class CheckWBWorker(QtCore.QThread): # mark as already installed AND already checked for updates AND update available self.repos[self.repos.index(repo)][2] = 3 except stderr: - FreeCAD.Console.PrintWarning(translate("AddonsInstaller", - "AddonManager - " + repo[0]) + " git status" - " fatal: this operation must be run in a work tree \n") + FreeCAD.Console.PrintWarning("AddonManager - " + repo[0] + " git status" + " fatal: this operation must be run in a work tree \n") self.addon_repos.emit(self.repos) self.enable.emit(len(upds)) self.stop = True From ff29bb14538ed63eea001b340fad9b9cc136f150 Mon Sep 17 00:00:00 2001 From: Chris Hennes Date: Sat, 18 Sep 2021 23:18:51 -0500 Subject: [PATCH 38/55] [App] LGTM fix - rename loop variable LGTM complains that the use of "obj" as the loop variable here hides the parameter "obj". To silence the warning, rename the loop variable. --- src/App/Link.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/App/Link.cpp b/src/App/Link.cpp index 7c4859fd7b..3e67cbe16c 100644 --- a/src/App/Link.cpp +++ b/src/App/Link.cpp @@ -1322,8 +1322,8 @@ void LinkBaseExtension::setLink(int index, DocumentObject *obj, auto objs = getElementListValue(); getElementListProperty()->setValue(); - for(auto obj : objs) - detachElement(obj); + for(auto thisObj : objs) + detachElement(thisObj); return; } From 967a97e9a8ed6811bb3c12c0966821f5d721f0af Mon Sep 17 00:00:00 2001 From: carlopav Date: Sun, 19 Sep 2021 14:31:44 +0200 Subject: [PATCH 39/55] Draft: fix Snapper GridSnap not working over a face ref. https://forum.freecadweb.org/viewtopic.php?f=23&t=62274&sid=4c9d07255e4f0db219b661c345768319 If the cursor is over a Face and no SnapCenter is active, the snapToObject method returns the current cursor point instead of None. Doing so the snap() method does not check for extension and grid snaps. It seems this is a bug since the snap() already contains the deleted code. One note: the no snaps case was moved before the lastObj setting, since if no snap point was found, it's not right to set it to a non snapped object. --- src/Mod/Draft/draftguitools/gui_snapper.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/Mod/Draft/draftguitools/gui_snapper.py b/src/Mod/Draft/draftguitools/gui_snapper.py index 93ac7f3b3c..b396e7fdb1 100644 --- a/src/Mod/Draft/draftguitools/gui_snapper.py +++ b/src/Mod/Draft/draftguitools/gui_snapper.py @@ -475,6 +475,9 @@ class Snapper: # snap to corners of section planes snaps.extend(self.snapToEndpoints(obj.Shape)) + if not snaps: + return None + # updating last objects list if not self.lastObj[1]: self.lastObj[1] = obj.Name @@ -482,15 +485,6 @@ class Snapper: self.lastObj[0] = self.lastObj[1] self.lastObj[1] = obj.Name - if not snaps: - self.spoint = self.cstr(lastpoint, constrain, point) - self.running = False - if self.trackLine and lastpoint: - self.trackLine.p2(self.spoint) - self.trackLine.color.rgb = Gui.draftToolBar.getDefaultColor("line") - self.trackLine.on() - return self.spoint - # calculating the nearest snap point shortest = 1000000000000000000 origin = App.Vector(self.snapInfo['x'], From b067a13a9172dac750de057919b78d75bd4d2ed6 Mon Sep 17 00:00:00 2001 From: wmayer Date: Sun, 19 Sep 2021 18:01:24 +0200 Subject: [PATCH 40/55] Tools: port example of embedding to Py3 --- .../Win32/FreeCAD_widget/FreeCAD_widget.cpp | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/Tools/embedded/Win32/FreeCAD_widget/FreeCAD_widget.cpp b/src/Tools/embedded/Win32/FreeCAD_widget/FreeCAD_widget.cpp index 054693b8e6..b65140bef0 100644 --- a/src/Tools/embedded/Win32/FreeCAD_widget/FreeCAD_widget.cpp +++ b/src/Tools/embedded/Win32/FreeCAD_widget/FreeCAD_widget.cpp @@ -236,11 +236,11 @@ std::string OnFileOpen(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) void OnLoadFreeCAD(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { if (!Py_IsInitialized()) { - Py_SetProgramName("CEmbed_FreeCADDlg"); + Py_SetProgramName(L"CEmbed_FreeCADDlg"); Py_Initialize(); static int argc = 1; - static char* app = "CEmbed_FreeCADDlg"; - static char *argv[2] = {app,0}; + static wchar_t* app = L"CEmbed_FreeCADDlg"; + static wchar_t *argv[2] = {app,0}; PySys_SetArgv(argc, argv); } @@ -268,12 +268,12 @@ void OnLoadFreeCAD(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) EnableMenuItem(hMenu, ID_FREECAD_EMBEDWINDOW, MF_ENABLED); } else { - PyObject *ptype, *pvalue, *ptrace; - PyErr_Fetch(&ptype, &pvalue, &ptrace); - PyObject* pystring = PyObject_Str(pvalue); - const char* error = PyString_AsString(pystring); - MessageBox(0, error, "Error", MB_OK); - Py_DECREF(pystring); + PyObject *ptype, *pvalue, *ptrace; + PyErr_Fetch(&ptype, &pvalue, &ptrace); + PyObject* pystring = PyObject_Str(pvalue); + const char* error = PyUnicode_AsUTF8(pystring); + MessageBox(0, error, "Error", MB_OK); + Py_DECREF(pystring); } Py_DECREF(dict); } @@ -291,12 +291,12 @@ void OnNewDocument(HWND hWnd) Py_DECREF(result); } else { - PyObject *ptype, *pvalue, *ptrace; - PyErr_Fetch(&ptype, &pvalue, &ptrace); - PyObject* pystring = PyObject_Str(pvalue); - const char* error = PyString_AsString(pystring); - MessageBox(hWnd, error, "Error", MB_OK); - Py_DECREF(pystring); + PyObject *ptype, *pvalue, *ptrace; + PyErr_Fetch(&ptype, &pvalue, &ptrace); + PyObject* pystring = PyObject_Str(pvalue); + const char* error = PyUnicode_AsUTF8(pystring); + MessageBox(hWnd, error, "Error", MB_OK); + Py_DECREF(pystring); } Py_DECREF(dict); } @@ -326,12 +326,12 @@ void OnEmbedWidget(HWND hWnd) EnableMenuItem(hMenu, ID_FREECAD_EMBEDWINDOW, MF_DISABLED); } else { - PyObject *ptype, *pvalue, *ptrace; - PyErr_Fetch(&ptype, &pvalue, &ptrace); - PyObject* pystring = PyObject_Str(pvalue); - const char* error = PyString_AsString(pystring); - MessageBox(hWnd, error, "Error", MB_OK); - Py_DECREF(pystring); + PyObject *ptype, *pvalue, *ptrace; + PyErr_Fetch(&ptype, &pvalue, &ptrace); + PyObject* pystring = PyObject_Str(pvalue); + const char* error = PyUnicode_AsUTF8(pystring); + MessageBox(hWnd, error, "Error", MB_OK); + Py_DECREF(pystring); } Py_DECREF(dict); } From 44272480f4617972bfb5e8f7bc62add961331ee8 Mon Sep 17 00:00:00 2001 From: wmayer Date: Sun, 19 Sep 2021 18:06:47 +0200 Subject: [PATCH 41/55] App: handle empty, . or .. as parent directory --- src/App/Document.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/App/Document.cpp b/src/App/Document.cpp index aa099d216a..3abcde08b5 100644 --- a/src/App/Document.cpp +++ b/src/App/Document.cpp @@ -2614,7 +2614,9 @@ bool Document::saveToFile(const char* filename) const } Base::FileInfo tmp(fn); // In case some folders in the path do not exist - fs::create_directories(fs::path(filename).parent_path()); + fs::path parent = fs::path(filename).parent_path(); + if (!parent.empty() && !parent.filename_is_dot() && !parent.filename_is_dot_dot()) + fs::create_directories(parent); // open extra scope to close ZipWriter properly { From 373246858e2fab528ad0eeab16a76fdea0ab1827 Mon Sep 17 00:00:00 2001 From: Chris Hennes Date: Sun, 19 Sep 2021 12:31:24 -0500 Subject: [PATCH 42/55] [App] Fix LGTM warning decl hides param --- src/App/Expression.cpp | 6 +++--- src/App/ObjectIdentifier.cpp | 6 +++--- src/App/PropertyLinks.cpp | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/App/Expression.cpp b/src/App/Expression.cpp index 1edc62605b..8149ce708b 100644 --- a/src/App/Expression.cpp +++ b/src/App/Expression.cpp @@ -484,11 +484,11 @@ App::any pyObjectToAny(Py::Object value, bool check) { if (PyLong_Check(pyvalue)) return App::any(PyLong_AsLong(pyvalue)); else if (PyUnicode_Check(pyvalue)) { - const char* value = PyUnicode_AsUTF8(pyvalue); - if (!value) { + const char* utf8value = PyUnicode_AsUTF8(pyvalue); + if (!utf8value) { FC_THROWM(Base::ValueError, "Invalid unicode string"); } - return App::any(std::string(value)); + return App::any(std::string(utf8value)); } else { return App::any(pyObjectWrap(pyvalue)); diff --git a/src/App/ObjectIdentifier.cpp b/src/App/ObjectIdentifier.cpp index 3b47871109..0aebc7f48d 100644 --- a/src/App/ObjectIdentifier.cpp +++ b/src/App/ObjectIdentifier.cpp @@ -1490,14 +1490,14 @@ void ObjectIdentifier::String::checkImport(const App::DocumentObject *owner, else { str.resize(str.size()-1); auto mapped = reader->getName(str.c_str()); - auto obj = owner->getDocument()->getObject(mapped); - if (!obj) { + auto objForMapped = owner->getDocument()->getObject(mapped); + if (!objForMapped) { FC_ERR("Cannot find object " << str); } else { isString = true; forceIdentifier = false; - str = obj->Label.getValue(); + str = objForMapped->Label.getValue(); } } } diff --git a/src/App/PropertyLinks.cpp b/src/App/PropertyLinks.cpp index 44b79a607c..e78abd3c22 100644 --- a/src/App/PropertyLinks.cpp +++ b/src/App/PropertyLinks.cpp @@ -2729,9 +2729,9 @@ public: // potentially unchanged. So we just touch at most one. std::set docs; for(auto link : links) { - auto doc = static_cast(link->getContainer())->getDocument(); - auto ret = docs.insert(doc); - if(ret.second && !doc->isTouched()) + auto linkdoc = static_cast(link->getContainer())->getDocument(); + auto ret = docs.insert(linkdoc); + if(ret.second && !linkdoc->isTouched()) link->touch(); } } From 8cbd92d874eafcc76f5ca85b289063c1d91097c3 Mon Sep 17 00:00:00 2001 From: wmayer Date: Sun, 19 Sep 2021 19:49:44 +0200 Subject: [PATCH 43/55] port to MSYS2/clang --- .../SetGlobalCompilerAndLinkerSettings.cmake | 32 ++++++++++++------- src/3rdParty/libkdtree/kdtree++/iterator.hpp | 4 +-- src/3rdParty/salomesmesh/CMakeLists.txt | 2 +- src/3rdParty/salomesmesh/inc/Basics_Utils.hxx | 2 +- src/3rdParty/salomesmesh/inc/ObjectPool.hxx | 6 ++-- .../salomesmesh/inc/SMDS_SpacePosition.hxx | 2 +- .../salomesmesh/inc/SMESH_ExceptHandlers.hxx | 4 +-- src/3rdParty/salomesmesh/inc/SMESH_Mesh.hxx | 2 +- .../salomesmesh/inc/Utils_ExceptHandlers.hxx | 4 +-- .../src/DriverSTL/DriverSTL_W_SMDS_Mesh.cpp | 2 ++ .../salomesmesh/src/DriverSTL/SMESH_File.cpp | 3 +- .../StdMeshers/StdMeshers_ProjectionUtils.cpp | 4 +-- src/Base/Sequencer.cpp | 8 +++++ src/Base/TimeInfo.cpp | 4 +-- src/CXX/Python3/Objects.hxx | 2 +- src/Gui/Command.h | 2 +- src/Gui/DocumentObserver.h | 2 +- src/Main/MainPy.cpp | 2 +- src/Mod/Image/Gui/OpenGLImageBox.cpp | 1 + src/Mod/Mesh/App/Core/Definitions.cpp | 4 +-- src/Mod/Part/Gui/SoBrepFaceSet.cpp | 2 +- src/Mod/Path/App/CMakeLists.txt | 9 ++++++ src/Mod/Path/libarea/kurve/geometry.h | 6 ++-- src/Mod/Points/App/Points.cpp | 6 ++-- src/Mod/Points/App/Properties.cpp | 4 +-- src/Mod/Robot/App/CMakeLists.txt | 4 +++ src/Mod/TechDraw/App/HatchLine.cpp | 4 +-- src/Mod/TechDraw/App/LineGroup.cpp | 2 +- src/zipios++/directory.cpp | 2 +- 29 files changed, 82 insertions(+), 49 deletions(-) diff --git a/cMake/FreeCAD_Helpers/SetGlobalCompilerAndLinkerSettings.cmake b/cMake/FreeCAD_Helpers/SetGlobalCompilerAndLinkerSettings.cmake index 514c4aad24..9a936bffbe 100644 --- a/cMake/FreeCAD_Helpers/SetGlobalCompilerAndLinkerSettings.cmake +++ b/cMake/FreeCAD_Helpers/SetGlobalCompilerAndLinkerSettings.cmake @@ -62,17 +62,25 @@ macro(SetGlobalCompilerAndLinkerSettings) endif(MSVC) if(MINGW) - # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=12477 - # Actually '-Wno-inline-dllimport' should work to suppress warnings of the form: - # inline function 'foo' is declared as dllimport: attribute ignored - # But it doesn't work with MinGW gcc 4.5.0 while using '-Wno-attributes' seems to - # do the trick. - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mthreads -Wno-attributes") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mthreads -Wno-attributes") - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -mthreads -Wl,--export-all-symbols") - set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -mthreads -Wl,--export-all-symbols") - # http://stackoverflow.com/questions/8375310/warning-auto-importing-has-been-activated-without-enable-auto-import-specifie - # set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-libgcc -static-libstdc++") - link_libraries(-lgdi32) + if(CMAKE_COMPILER_IS_CLANGXX) + # clang for MSYS doesn't support -mthreads + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-attributes") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-attributes") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--export-all-symbols") + #set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--export-all-symbols") + else() + # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=12477 + # Actually '-Wno-inline-dllimport' should work to suppress warnings of the form: + # inline function 'foo' is declared as dllimport: attribute ignored + # But it doesn't work with MinGW gcc 4.5.0 while using '-Wno-attributes' seems to + # do the trick. + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-attributes") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-attributes") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--export-all-symbols") + #set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--export-all-symbols") + # http://stackoverflow.com/questions/8375310/warning-auto-importing-has-been-activated-without-enable-auto-import-specifie + # set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-libgcc -static-libstdc++") + link_libraries(-lgdi32) + endif() endif(MINGW) endmacro(SetGlobalCompilerAndLinkerSettings) diff --git a/src/3rdParty/libkdtree/kdtree++/iterator.hpp b/src/3rdParty/libkdtree/kdtree++/iterator.hpp index 801dc40ae4..b6f7933442 100644 --- a/src/3rdParty/libkdtree/kdtree++/iterator.hpp +++ b/src/3rdParty/libkdtree/kdtree++/iterator.hpp @@ -54,8 +54,8 @@ namespace KDTree inline _Base_iterator(_Base_const_ptr const __N = NULL) : _M_node(__N) {} - inline _Base_iterator(_Base_iterator const& __THAT) - : _M_node(__THAT._M_node) {} + //inline _Base_iterator(_Base_iterator const& __THAT) + // : _M_node(__THAT._M_node) {} inline void _M_increment() diff --git a/src/3rdParty/salomesmesh/CMakeLists.txt b/src/3rdParty/salomesmesh/CMakeLists.txt index 104ffebba6..9f53ee423a 100644 --- a/src/3rdParty/salomesmesh/CMakeLists.txt +++ b/src/3rdParty/salomesmesh/CMakeLists.txt @@ -243,7 +243,7 @@ TARGET_LINK_LIBRARIES(DriverSTL ${SMESH_LIBS} Driver SMDS ${Boost_LIBRARIES}) SET_BIN_DIR(DriverSTL DriverSTL) if(WIN32) - set_target_properties(DriverSTL PROPERTIES COMPILE_FLAGS "-DMESHDRIVERSTL_EXPORTS -DBASICS_EXPORT -DSMESHUtils_EXPORTS -DBASICS_EXPORTS") + set_target_properties(DriverSTL PROPERTIES COMPILE_FLAGS "-DMESHDRIVERSTL_EXPORTS -DSMESHUtils_EXPORTS -DBASICS_EXPORTS") endif(WIN32) diff --git a/src/3rdParty/salomesmesh/inc/Basics_Utils.hxx b/src/3rdParty/salomesmesh/inc/Basics_Utils.hxx index 20d0923c97..3e9a2fd392 100644 --- a/src/3rdParty/salomesmesh/inc/Basics_Utils.hxx +++ b/src/3rdParty/salomesmesh/inc/Basics_Utils.hxx @@ -34,7 +34,7 @@ #else // avoid name collision with std::byte in C++17 #define NOCRYPT -#define NOGDI +#define NOGDI NOGDI #include #include #pragma comment(lib,"winmm.lib") diff --git a/src/3rdParty/salomesmesh/inc/ObjectPool.hxx b/src/3rdParty/salomesmesh/inc/ObjectPool.hxx index f27161122c..6212cbbf5c 100644 --- a/src/3rdParty/salomesmesh/inc/ObjectPool.hxx +++ b/src/3rdParty/salomesmesh/inc/ObjectPool.hxx @@ -126,14 +126,14 @@ public: void destroy(X* obj) { - long adrobj = (long) (obj); + intptr_t adrobj = (intptr_t) (obj); for (size_t i = 0; i < _chunkList.size(); i++) { X* chunk = _chunkList[i]; - long adrmin = (long) (chunk); + intptr_t adrmin = (intptr_t) (chunk); if (adrobj < adrmin) continue; - long adrmax = (long) (chunk + _chunkSize); + intptr_t adrmax = (intptr_t) (chunk + _chunkSize); if (adrobj >= adrmax) continue; int rank = (adrobj - adrmin) / sizeof(X); diff --git a/src/3rdParty/salomesmesh/inc/SMDS_SpacePosition.hxx b/src/3rdParty/salomesmesh/inc/SMDS_SpacePosition.hxx index 31f6423442..f19c752e00 100644 --- a/src/3rdParty/salomesmesh/inc/SMDS_SpacePosition.hxx +++ b/src/3rdParty/salomesmesh/inc/SMDS_SpacePosition.hxx @@ -36,7 +36,7 @@ class SMDS_EXPORT SMDS_SpacePosition:public SMDS_Position public: SMDS_SpacePosition(double x=0, double y=0, double z=0); - virtual inline SMDS_TypeOfPosition GetTypeOfPosition() const; + virtual SMDS_TypeOfPosition GetTypeOfPosition() const; static SMDS_PositionPtr originSpacePosition(); private: static SMDS_SpacePosition* _originPosition; diff --git a/src/3rdParty/salomesmesh/inc/SMESH_ExceptHandlers.hxx b/src/3rdParty/salomesmesh/inc/SMESH_ExceptHandlers.hxx index 50cd06c805..d0d8e4604c 100644 --- a/src/3rdParty/salomesmesh/inc/SMESH_ExceptHandlers.hxx +++ b/src/3rdParty/salomesmesh/inc/SMESH_ExceptHandlers.hxx @@ -50,7 +50,7 @@ typedef void (*PVF)(); class SMESH_EXPORT Unexpect { //save / retrieve unexpected exceptions treatment PVF old; public : -#ifndef WNT +#ifndef _MSC_VER // std::set_unexpected has been removed in C++17 Unexpect( PVF f ) { /*old = std::set_unexpected(f);*/old = f; } @@ -66,7 +66,7 @@ class SMESH_EXPORT Terminate {//save / retrieve terminate function PVF old; public : -#ifndef WNT +#ifndef _MSC_VER Terminate( PVF f ) { old = std::set_terminate(f); } ~Terminate() { std::set_terminate(old); } diff --git a/src/3rdParty/salomesmesh/inc/SMESH_Mesh.hxx b/src/3rdParty/salomesmesh/inc/SMESH_Mesh.hxx index e5f1f1b661..a776949b58 100644 --- a/src/3rdParty/salomesmesh/inc/SMESH_Mesh.hxx +++ b/src/3rdParty/salomesmesh/inc/SMESH_Mesh.hxx @@ -46,7 +46,7 @@ #include -#ifdef WIN32 +#ifdef _MSC_VER #pragma warning(disable:4251) // Warning DLL Interface ... #pragma warning(disable:4290) // Warning Exception ... #endif diff --git a/src/3rdParty/salomesmesh/inc/Utils_ExceptHandlers.hxx b/src/3rdParty/salomesmesh/inc/Utils_ExceptHandlers.hxx index 6985f8fa67..8f2362ded1 100644 --- a/src/3rdParty/salomesmesh/inc/Utils_ExceptHandlers.hxx +++ b/src/3rdParty/salomesmesh/inc/Utils_ExceptHandlers.hxx @@ -38,7 +38,7 @@ typedef void (*PVF)(); class UTILS_EXPORT Unexpect { //save / retrieve unexpected exceptions treatment PVF old; public : -#ifndef WIN32 +#ifndef _MSC_VER // std::set_unexpected has been removed in C++17 Unexpect( PVF f ) { /*old = std::set_unexpected(f);*/old = f; } @@ -54,7 +54,7 @@ class UTILS_EXPORT Terminate {//save / retrieve terminate function PVF old; public : -#ifndef WIN32 +#ifndef _MSC_VER Terminate( PVF f ) { old = std::set_terminate(f); } ~Terminate() { std::set_terminate(old); } diff --git a/src/3rdParty/salomesmesh/src/DriverSTL/DriverSTL_W_SMDS_Mesh.cpp b/src/3rdParty/salomesmesh/src/DriverSTL/DriverSTL_W_SMDS_Mesh.cpp index 05b0480936..749f241ec0 100644 --- a/src/3rdParty/salomesmesh/src/DriverSTL/DriverSTL_W_SMDS_Mesh.cpp +++ b/src/3rdParty/salomesmesh/src/DriverSTL/DriverSTL_W_SMDS_Mesh.cpp @@ -23,8 +23,10 @@ #include "DriverSTL_W_SMDS_Mesh.h" #ifdef WIN32 +#ifndef NOMINMAX #define NOMINMAX #endif +#endif #include diff --git a/src/3rdParty/salomesmesh/src/DriverSTL/SMESH_File.cpp b/src/3rdParty/salomesmesh/src/DriverSTL/SMESH_File.cpp index 43d567298c..481110f4b2 100644 --- a/src/3rdParty/salomesmesh/src/DriverSTL/SMESH_File.cpp +++ b/src/3rdParty/salomesmesh/src/DriverSTL/SMESH_File.cpp @@ -141,7 +141,8 @@ void SMESH_File::close() _pos = _end = 0; _size = -1; } - else if ( _file >= 0 ) + //else if ( _file >= 0 ) + else if ( _file != 0 ) { #ifdef WIN32 if(_file != INVALID_HANDLE_VALUE) { diff --git a/src/3rdParty/salomesmesh/src/StdMeshers/StdMeshers_ProjectionUtils.cpp b/src/3rdParty/salomesmesh/src/StdMeshers/StdMeshers_ProjectionUtils.cpp index 4905d0d062..5ec96bdbec 100644 --- a/src/3rdParty/salomesmesh/src/StdMeshers/StdMeshers_ProjectionUtils.cpp +++ b/src/3rdParty/salomesmesh/src/StdMeshers/StdMeshers_ProjectionUtils.cpp @@ -102,11 +102,11 @@ namespace HERE = StdMeshers_ProjectionUtils; namespace { static SMESHDS_Mesh* theMeshDS[2] = { 0, 0 }; // used for debug only - inline long shapeIndex(const TopoDS_Shape& S) + inline intptr_t shapeIndex(const TopoDS_Shape& S) { if ( theMeshDS[0] && theMeshDS[1] ) return max(theMeshDS[0]->ShapeToIndex(S), theMeshDS[1]->ShapeToIndex(S) ); - return long(S.TShape().operator->()); + return intptr_t(S.TShape().operator->()); } //================================================================================ diff --git a/src/Base/Sequencer.cpp b/src/Base/Sequencer.cpp index 751a6273de..57cd67904f 100644 --- a/src/Base/Sequencer.cpp +++ b/src/Base/Sequencer.cpp @@ -41,7 +41,11 @@ namespace Base { // members static std::vector _instances; /**< A vector of all created instances */ static SequencerLauncher* _topLauncher; /**< The outermost launcher */ +#if QT_VERSION >= QT_VERSION_CHECK(5,14,0) + static QRecursiveMutex mutex; /**< A mutex-locker for the launcher */ +#else static QMutex mutex; /**< A mutex-locker for the launcher */ +#endif /** Sets a global sequencer object. * Access to the last registered object is performed by @see Sequencer(). */ @@ -67,7 +71,11 @@ namespace Base { */ std::vector SequencerP::_instances; SequencerLauncher* SequencerP::_topLauncher = 0; +#if QT_VERSION >= QT_VERSION_CHECK(5,14,0) + QRecursiveMutex SequencerP::mutex; +#else QMutex SequencerP::mutex(QMutex::Recursive); +#endif } SequencerBase& SequencerBase::Instance () diff --git a/src/Base/TimeInfo.cpp b/src/Base/TimeInfo.cpp index 03cbff2959..d34dc6edbe 100644 --- a/src/Base/TimeInfo.cpp +++ b/src/Base/TimeInfo.cpp @@ -26,7 +26,7 @@ #ifndef _PreComp_ # include # include -# if defined(FC_OS_LINUX) +# if defined(FC_OS_LINUX) || defined(__MINGW32__) # include # endif #endif @@ -60,7 +60,7 @@ TimeInfo::~TimeInfo() void TimeInfo::setCurrent(void) { -#if defined (FC_OS_BSD) || defined(FC_OS_LINUX) +#if defined (FC_OS_BSD) || defined(FC_OS_LINUX) || defined(__MINGW32__) struct timeval t; gettimeofday(&t, NULL); timebuffer.time = t.tv_sec; diff --git a/src/CXX/Python3/Objects.hxx b/src/CXX/Python3/Objects.hxx index 08f77df6c1..d86cd138a1 100644 --- a/src/CXX/Python3/Objects.hxx +++ b/src/CXX/Python3/Objects.hxx @@ -55,7 +55,7 @@ namespace Py { typedef Py_ssize_t sequence_index_type; // type of an index into a sequence - Py_ssize_t numeric_limits_max(); + PYCXX_EXPORT Py_ssize_t numeric_limits_max(); // Forward declarations class Object; diff --git a/src/Gui/Command.h b/src/Gui/Command.h index f03fd22de8..852da24852 100644 --- a/src/Gui/Command.h +++ b/src/Gui/Command.h @@ -454,7 +454,7 @@ public: * * @sa Command::_doCommand() */ -#ifdef FC_OS_WIN32 +#ifdef _MSC_VER #define doCommand(_type,...) _doCommand(__FILE__,__LINE__,_type,##__VA_ARGS__) #else #define doCommand(...) _doCommand(__FILE__,__LINE__,__VA_ARGS__) diff --git a/src/Gui/DocumentObserver.h b/src/Gui/DocumentObserver.h index 90f84dcd00..6608fa9df7 100644 --- a/src/Gui/DocumentObserver.h +++ b/src/Gui/DocumentObserver.h @@ -165,7 +165,7 @@ private: /** * @brief The ViewProviderWeakPtrT class */ -class AppExport ViewProviderWeakPtrT +class GuiExport ViewProviderWeakPtrT { public: ViewProviderWeakPtrT(ViewProviderDocumentObject*); diff --git a/src/Main/MainPy.cpp b/src/Main/MainPy.cpp index 10ed3a39c1..739deb9afc 100644 --- a/src/Main/MainPy.cpp +++ b/src/Main/MainPy.cpp @@ -56,7 +56,7 @@ /** DllMain is called when DLL is loaded */ -BOOL APIENTRY DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) +BOOL APIENTRY DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID /*lpReserved*/) { switch (ul_reason_for_call) { case DLL_PROCESS_ATTACH: { diff --git a/src/Mod/Image/Gui/OpenGLImageBox.cpp b/src/Mod/Image/Gui/OpenGLImageBox.cpp index bb22ae0f83..3c4a6e2441 100644 --- a/src/Mod/Image/Gui/OpenGLImageBox.cpp +++ b/src/Mod/Image/Gui/OpenGLImageBox.cpp @@ -31,6 +31,7 @@ #if defined(__MINGW32__) # include +# include # include #elif defined (FC_OS_MACOSX) # include diff --git a/src/Mod/Mesh/App/Core/Definitions.cpp b/src/Mod/Mesh/App/Core/Definitions.cpp index 5c0f66290b..ebbdec2b6d 100644 --- a/src/Mod/Mesh/App/Core/Definitions.cpp +++ b/src/Mod/Mesh/App/Core/Definitions.cpp @@ -30,8 +30,8 @@ namespace MeshCore { -template<> const float Math ::PI = (float)(4.0*atan(1.0)); -template<> const double Math::PI = 4.0*atan(1.0); +template<> MeshExport const float Math ::PI = (float)(4.0*atan(1.0)); +template<> MeshExport const double Math::PI = 4.0*atan(1.0); float MeshDefinitions::_fMinPointDistance = float(MESH_MIN_PT_DIST); float MeshDefinitions::_fMinPointDistanceP2 = _fMinPointDistance * _fMinPointDistance; diff --git a/src/Mod/Part/Gui/SoBrepFaceSet.cpp b/src/Mod/Part/Gui/SoBrepFaceSet.cpp index b000c03966..a2fe4d2bd7 100644 --- a/src/Mod/Part/Gui/SoBrepFaceSet.cpp +++ b/src/Mod/Part/Gui/SoBrepFaceSet.cpp @@ -1471,7 +1471,7 @@ void SoBrepFaceSet::VBO::render(SoGLRenderAction * action, const cc_glglue * glue = cc_glglue_instance(action->getCacheContext()); PFNGLBINDBUFFERARBPROC glBindBufferARB = (PFNGLBINDBUFFERARBPROC) cc_glglue_getprocaddress(glue, "glBindBufferARB"); - PFNGLMAPBUFFERARBPROC glMapBufferARB = (PFNGLMAPBUFFERARBPROC) cc_glglue_getprocaddress(glue, "glMapBufferARB"); + //PFNGLMAPBUFFERARBPROC glMapBufferARB = (PFNGLMAPBUFFERARBPROC) cc_glglue_getprocaddress(glue, "glMapBufferARB"); PFNGLGENBUFFERSPROC glGenBuffersARB = (PFNGLGENBUFFERSPROC)cc_glglue_getprocaddress(glue, "glGenBuffersARB"); PFNGLDELETEBUFFERSARBPROC glDeleteBuffersARB = (PFNGLDELETEBUFFERSARBPROC)cc_glglue_getprocaddress(glue, "glDeleteBuffersARB"); PFNGLBUFFERDATAARBPROC glBufferDataARB = (PFNGLBUFFERDATAARBPROC)cc_glglue_getprocaddress(glue, "glBufferDataARB"); diff --git a/src/Mod/Path/App/CMakeLists.txt b/src/Mod/Path/App/CMakeLists.txt index 2ec0a12615..fa9a52c302 100644 --- a/src/Mod/Path/App/CMakeLists.txt +++ b/src/Mod/Path/App/CMakeLists.txt @@ -145,6 +145,15 @@ target_link_libraries(Path ${Path_LIBS}) if(NOT ${Boost_VERSION} LESS 107500) set_target_properties(Path PROPERTIES CXX_STANDARD_REQUIRED ON) set_target_properties(Path PROPERTIES CXX_STANDARD 14) + + # Suppress -Wc++17-extensions when using OCCT 7.5 or newer + if (MINGW AND CMAKE_COMPILER_IS_CLANGXX) + unset(_flag_found CACHE) + check_cxx_compiler_flag("-Wno-c++17-extensions" _flag_found) + if (_flag_found) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-c++17-extensions") + endif() + endif() endif() if(FREECAD_USE_PCH) diff --git a/src/Mod/Path/libarea/kurve/geometry.h b/src/Mod/Path/libarea/kurve/geometry.h index 0148d0552b..58e6041dd1 100644 --- a/src/Mod/Path/libarea/kurve/geometry.h +++ b/src/Mod/Path/libarea/kurve/geometry.h @@ -10,7 +10,7 @@ // ///////////////////////////////////////////////////////////////////////////////////////// #pragma once -#ifdef WIN32 +#ifdef _MSC_VER #pragma warning( disable : 4996 ) #ifndef WINVER #define WINVER 0x501 @@ -772,7 +772,7 @@ inline bool FNEZ(double a, double tolerance = TIGHT_TOLERANCE) {return fabs(a) > -#ifdef WIN32 +#ifdef _MSC_VER #pragma warning(disable:4522) #endif @@ -902,7 +902,7 @@ inline bool FNEZ(double a, double tolerance = TIGHT_TOLERANCE) {return fabs(a) > PK_BODY_t ToPKlofted_thickened_body(Kurve &sec, double thickness); #endif }; -#ifdef WIN32 +#ifdef _MSC_VER #pragma warning(default:4522) #endif diff --git a/src/Mod/Points/App/Points.cpp b/src/Mod/Points/App/Points.cpp index a568bdb68c..947c27cee3 100644 --- a/src/Mod/Points/App/Points.cpp +++ b/src/Mod/Points/App/Points.cpp @@ -40,7 +40,7 @@ #include "PointsAlgos.h" #include "PointsPy.h" -#ifdef _WIN32 +#ifdef _MSC_VER # include #endif @@ -85,7 +85,7 @@ Data::Segment* PointKernel::getSubElement(const char* /*Type*/, unsigned long /* void PointKernel::transformGeometry(const Base::Matrix4D &rclMat) { std::vector& kernel = getBasicPoints(); -#ifdef _WIN32 +#ifdef _MSC_VER // Win32-only at the moment since ppl.h is a Microsoft library. Points is not using Qt so we cannot use QtConcurrent // We could also rewrite Points to leverage SIMD instructions // Other option: openMP. But with VC2013 results in high CPU usage even after computation (busy-waits for >100ms) @@ -103,7 +103,7 @@ Base::BoundBox3d PointKernel::getBoundBox(void)const { Base::BoundBox3d bnd; -#ifdef _WIN32 +#ifdef _MSC_VER // Thread-local bounding boxes Concurrency::combinable bbs; // Cannot use a const_point_iterator here as it is *not* a proper iterator (fails the for_each template) diff --git a/src/Mod/Points/App/Properties.cpp b/src/Mod/Points/App/Properties.cpp index 4d6b87d86d..77099e6d6b 100644 --- a/src/Mod/Points/App/Properties.cpp +++ b/src/Mod/Points/App/Properties.cpp @@ -41,7 +41,7 @@ #include "PointsPy.h" #include -#ifdef _WIN32 +#ifdef _MSC_VER # include #endif @@ -393,7 +393,7 @@ void PropertyNormalList::transformGeometry(const Base::Matrix4D &mat) aboutToSetValue(); // Rotate the normal vectors -#ifdef _WIN32 +#ifdef _MSC_VER Concurrency::parallel_for_each(_lValueList.begin(), _lValueList.end(), [rot](Base::Vector3f& value) { value = rot * value; }); diff --git a/src/Mod/Robot/App/CMakeLists.txt b/src/Mod/Robot/App/CMakeLists.txt index 383386c01b..a7cbaf55bf 100644 --- a/src/Mod/Robot/App/CMakeLists.txt +++ b/src/Mod/Robot/App/CMakeLists.txt @@ -131,6 +131,10 @@ if (_flag_found) target_compile_options(Robot PRIVATE -Wno-deprecated-copy) endif() +if(MINGW) + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--export-all-symbols") +endif() + SET_BIN_DIR(Robot Robot /Mod/Robot) SET_PYTHON_PREFIX_SUFFIX(Robot) diff --git a/src/Mod/TechDraw/App/HatchLine.cpp b/src/Mod/TechDraw/App/HatchLine.cpp index 00bfc7e4a5..d9602a6f8b 100644 --- a/src/Mod/TechDraw/App/HatchLine.cpp +++ b/src/Mod/TechDraw/App/HatchLine.cpp @@ -337,7 +337,7 @@ bool PATLineSpec::findPatternStart(std::ifstream& inFile, std::string& parmName std::getline(inFile,line); std::string nameTag = line.substr(0,1); std::string patternName; - unsigned long int commaPos; + std::size_t commaPos; if ((nameTag == ";") || (nameTag == " ") || (line.empty()) ) { //is cr/lf empty? @@ -394,7 +394,7 @@ std::vector PATLineSpec::getPatternList(std::string& parmFile) std::string line; std::getline(inFile,line); std::string nameTag = line.substr(0,1); //dupl code here - unsigned long int commaPos; + std::size_t commaPos; if (nameTag == "*") { //found a pattern commaPos = line.find(',',1); std::string patternName; diff --git a/src/Mod/TechDraw/App/LineGroup.cpp b/src/Mod/TechDraw/App/LineGroup.cpp index 05f3da24d8..3b2dc9bc85 100644 --- a/src/Mod/TechDraw/App/LineGroup.cpp +++ b/src/Mod/TechDraw/App/LineGroup.cpp @@ -208,7 +208,7 @@ std::string LineGroup::getGroupNamesFromFile(std::string FileName) std::getline(inFile, line); std::string nameTag = line.substr(0, 1); std::string found; - unsigned long int commaPos; + std::size_t commaPos; if (nameTag == "*") { commaPos = line.find(',', 1); if (commaPos != std::string::npos) { diff --git a/src/zipios++/directory.cpp b/src/zipios++/directory.cpp index 7dc7a28a08..ec05488fe2 100644 --- a/src/zipios++/directory.cpp +++ b/src/zipios++/directory.cpp @@ -317,7 +317,7 @@ namespace boost { return (it.rep->get_data().attrib & _A_HIDDEN) != 0; } - template <> bool get(dir_it const &it) + template <> bool get(dir_it const & /*it*/) { return true; } From 6c532c2fda66a17caac65aecfd8236f370781ec9 Mon Sep 17 00:00:00 2001 From: Chris Hennes Date: Sun, 19 Sep 2021 13:39:49 -0500 Subject: [PATCH 44/55] PD: Silence LGTM warning about empty block --- src/Mod/PartDesign/App/FeatureHole.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Mod/PartDesign/App/FeatureHole.cpp b/src/Mod/PartDesign/App/FeatureHole.cpp index 69772c77e2..b99c42c463 100644 --- a/src/Mod/PartDesign/App/FeatureHole.cpp +++ b/src/Mod/PartDesign/App/FeatureHole.cpp @@ -1456,6 +1456,7 @@ void Hole::onChanged(const App::Property *prop) ThreadDepth.setReadOnly(Threaded.getValue() && std::string(ThreadDepthType.getValueAsString()) != "Dimension"); } else if (prop == &ThreadDepth) { + // Nothing else needs to be updated on ThreadDepth change } else if (prop == &UseCustomThreadClearance) { updateDiameterParam(); From c5491d64e276e87e0c49aabcf4e1a47166101fa6 Mon Sep 17 00:00:00 2001 From: Chris Hennes Date: Sun, 19 Sep 2021 14:36:12 -0500 Subject: [PATCH 45/55] Arch: LGTM - don't catch BaseException --- src/Mod/Arch/ArchReference.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Mod/Arch/ArchReference.py b/src/Mod/Arch/ArchReference.py index 25b227746b..861db01306 100644 --- a/src/Mod/Arch/ArchReference.py +++ b/src/Mod/Arch/ArchReference.py @@ -211,7 +211,7 @@ class ArchReference: shape = Part.makeCompound(shapes) try: shape = shape.removeSplitter() - except: + except Exception: print(obj.Label,": error removing splitter") return shape From f99059e371b5b4f668f42e7a01bab604cdd77056 Mon Sep 17 00:00:00 2001 From: Chris Hennes Date: Sun, 19 Sep 2021 14:36:38 -0500 Subject: [PATCH 46/55] Draft: LGTM - don't catch BaseException --- src/Mod/Draft/draftgeoutils/general.py | 2 +- src/Mod/Draft/draftguitools/gui_setstyle.py | 4 ++-- src/Mod/Draft/draftobjects/patharray.py | 2 +- src/Mod/Draft/draftutils/units.py | 2 +- src/Mod/Draft/importDWG.py | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Mod/Draft/draftgeoutils/general.py b/src/Mod/Draft/draftgeoutils/general.py index ba45625906..e89c5f0daa 100644 --- a/src/Mod/Draft/draftgeoutils/general.py +++ b/src/Mod/Draft/draftgeoutils/general.py @@ -258,7 +258,7 @@ def geomType(edge): return "Ellipse" else: return "Unknown" - except: # catch all errors, no only TypeError + except Exception: # catch all errors, no only TypeError return "Unknown" diff --git a/src/Mod/Draft/draftguitools/gui_setstyle.py b/src/Mod/Draft/draftguitools/gui_setstyle.py index d502dd7a06..1d3046ea99 100644 --- a/src/Mod/Draft/draftguitools/gui_setstyle.py +++ b/src/Mod/Draft/draftguitools/gui_setstyle.py @@ -297,7 +297,7 @@ class Draft_SetStyle_TaskPanel: try: import json from json.decoder import JSONDecodeError - except: + except Exception: return if os.path.exists(PRESETPATH): with open(PRESETPATH,"r") as f: @@ -313,7 +313,7 @@ class Draft_SetStyle_TaskPanel: try: import json - except: + except Exception: FreeCAD.Console.PrintError(translate("Draft","Error: json module not found. Unable to save style")+"\n") return folder = os.path.dirname(PRESETPATH) diff --git a/src/Mod/Draft/draftobjects/patharray.py b/src/Mod/Draft/draftobjects/patharray.py index 264964e775..82284df5b4 100644 --- a/src/Mod/Draft/draftobjects/patharray.py +++ b/src/Mod/Draft/draftobjects/patharray.py @@ -521,7 +521,7 @@ def calculate_placement(globalRotation, try: t = edge.tangentAt(get_parameter_from_v0(edge, offset)) t.normalize() - except: + except Exception: _wrn(translate("draft","Cannot calculate path tangent. Copy not aligned.")) return placement diff --git a/src/Mod/Draft/draftutils/units.py b/src/Mod/Draft/draftutils/units.py index df5bb657da..2966716d19 100644 --- a/src/Mod/Draft/draftutils/units.py +++ b/src/Mod/Draft/draftutils/units.py @@ -107,7 +107,7 @@ def display_external(internal_value, uom = unit internal_value = q.getValueAs(unit) conversion = 1 - except: + except Exception: conversion = q.getUserPreferred()[1] uom = q.getUserPreferred()[2] elif dim == 'Angle': diff --git a/src/Mod/Draft/importDWG.py b/src/Mod/Draft/importDWG.py index 29fc05d4c8..8c9dd1c19d 100644 --- a/src/Mod/Draft/importDWG.py +++ b/src/Mod/Draft/importDWG.py @@ -210,7 +210,7 @@ def convertToDxf(dwgfilename): proc = subprocess.Popen(("dwg2dxf", dwgfilename, "-o", result)) proc.communicate() return result - except: + except Exception: pass teigha = getTeighaConverter() From 985438f2b26a137c983ca82a8edd5d91a234229f Mon Sep 17 00:00:00 2001 From: Chris Hennes Date: Sun, 19 Sep 2021 14:36:51 -0500 Subject: [PATCH 47/55] Plot: LGTM - don't catch BaseException --- src/Mod/Plot/Plot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Mod/Plot/Plot.py b/src/Mod/Plot/Plot.py index ace9f094d9..5b0070b027 100644 --- a/src/Mod/Plot/Plot.py +++ b/src/Mod/Plot/Plot.py @@ -199,7 +199,7 @@ def legend(status=True, pos=None, fontsize=None): # Get resultant position try: fax = axes.get_frame().get_extents() - except: + except Exception: fax = axes.patch.get_extents() fl = l.get_frame() plt.legPos = ( From 38eb31e01d7aa8725e4c4199b7f79dda93d464b6 Mon Sep 17 00:00:00 2001 From: Chris Hennes Date: Sun, 19 Sep 2021 14:37:11 -0500 Subject: [PATCH 48/55] Path: LGTM - don't catch BaseException --- src/Mod/Path/PathScripts/post/heidenhain_post.py | 2 +- src/Mod/Path/PathScripts/post/marlin_post.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Mod/Path/PathScripts/post/heidenhain_post.py b/src/Mod/Path/PathScripts/post/heidenhain_post.py index acfc1a9b22..5443504566 100644 --- a/src/Mod/Path/PathScripts/post/heidenhain_post.py +++ b/src/Mod/Path/PathScripts/post/heidenhain_post.py @@ -238,7 +238,7 @@ def processArguments(argstring): SHOW_EDITOR = False if args.no_warns: SKIP_WARNS = True - except: + except Exception: return False return True diff --git a/src/Mod/Path/PathScripts/post/marlin_post.py b/src/Mod/Path/PathScripts/post/marlin_post.py index 44fad8210e..f7cee65634 100644 --- a/src/Mod/Path/PathScripts/post/marlin_post.py +++ b/src/Mod/Path/PathScripts/post/marlin_post.py @@ -319,7 +319,7 @@ def dump(obj): print('==============\n', attr_text) if 'mm/s' in attr_text: print('===> metric values <===') - except: # Insignificant errors + except Exception: # Insignificant errors # print('==>', obj, attr) pass From ccaa439d1a76cd439c29fba85d0e5aeeb566df9a Mon Sep 17 00:00:00 2001 From: Chris Hennes Date: Sun, 19 Sep 2021 14:37:23 -0500 Subject: [PATCH 49/55] PD: LGTM - don't catch BaseException --- src/Mod/PartDesign/FeatureHole/FeatureHole.py | 2 +- src/Mod/PartDesign/FeatureHole/TaskHole.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Mod/PartDesign/FeatureHole/FeatureHole.py b/src/Mod/PartDesign/FeatureHole/FeatureHole.py index a4cc7275c3..da4d520d8f 100644 --- a/src/Mod/PartDesign/FeatureHole/FeatureHole.py +++ b/src/Mod/PartDesign/FeatureHole/FeatureHole.py @@ -153,7 +153,7 @@ class Hole(): secondLineIndex = i if (firstLineIndex > -1) and (secondLineIndex > -1): break - except: + except Exception: # Unknown curvetype GeomAbs_OtherCurve continue axis.References = [(support, elementList[0]), (support, "Edge" + str(firstLineIndex+1)), (support, "Edge" + str(secondLineIndex+1))] diff --git a/src/Mod/PartDesign/FeatureHole/TaskHole.py b/src/Mod/PartDesign/FeatureHole/TaskHole.py index b0752d356a..6805cb27bd 100644 --- a/src/Mod/PartDesign/FeatureHole/TaskHole.py +++ b/src/Mod/PartDesign/FeatureHole/TaskHole.py @@ -61,7 +61,7 @@ class TaskHole: body.removeObject(sketch) try: document.removeObject(sketch.Name) - except: + except Exception: pass # This always throws an exception: "Sketch support has been deleted" from SketchObject::execute() body.removeObject(plane) document.removeObject(plane.Name) From 105dd61e84110b5b9915c6166e6c61d416ea27b7 Mon Sep 17 00:00:00 2001 From: Chris Hennes Date: Sun, 19 Sep 2021 14:37:47 -0500 Subject: [PATCH 50/55] Template: LGTM - don't catch BaseException --- src/Mod/TemplatePyMod/Automation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Mod/TemplatePyMod/Automation.py b/src/Mod/TemplatePyMod/Automation.py index 8a990d08f7..36f744b013 100644 --- a/src/Mod/TemplatePyMod/Automation.py +++ b/src/Mod/TemplatePyMod/Automation.py @@ -52,7 +52,7 @@ def makeSnapshotWithoutGui(): inp=coin.SoInput() try: inp.setBuffer(iv) - except: + except Exception: tempPath = tempfile.gettempdir() fileName = tempPath + os.sep + "cone.iv" file = open(fileName, "w") From 6acffa237886fd95f4b02f5305eb16e6458b8508 Mon Sep 17 00:00:00 2001 From: Chris Hennes Date: Sun, 19 Sep 2021 14:38:05 -0500 Subject: [PATCH 51/55] Tools: LGTM - don't catch BaseException --- src/Tools/generateBase/generateTools.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Tools/generateBase/generateTools.py b/src/Tools/generateBase/generateTools.py index fb98f70f8a..d6d6ad92b1 100644 --- a/src/Tools/generateBase/generateTools.py +++ b/src/Tools/generateBase/generateTools.py @@ -63,7 +63,7 @@ class copier: # uncomment for debug: print ('!!! replacing',match.group(1)) expr = self.preproc(match.group(1), 'eval') try: return str(eval(expr, self.globals, self.locals)) - except: return str(self.handle(expr)) + except Exception: return str(self.handle(expr)) block = self.locals['_bl'] if last is None: last = len(block) while i Date: Sun, 19 Sep 2021 20:27:13 -0500 Subject: [PATCH 52/55] [Docs] Minor tweaks to BUILD_OSX.md Most based on feedback from @hyarion. --- BUILD_OSX.md | 79 +++++++++++++++++++++++++--------------------------- 1 file changed, 38 insertions(+), 41 deletions(-) diff --git a/BUILD_OSX.md b/BUILD_OSX.md index 0ebbcc8b1c..76778d5088 100644 --- a/BUILD_OSX.md +++ b/BUILD_OSX.md @@ -27,7 +27,7 @@ General notes on how the tooling works: This setup uses [conda](https://docs.conda.io) for dependency management. Conda is able to pull the deps from a repository called conda-forge and setup an isolated build environment. Not quite as isolated as docker, but -it is a good option for Mac and its what the FreeCAD CI system uses. +it is a good option for Mac and is what the FreeCAD CI system uses. Once the dependencies are installed into a conda environment, then the build uses the standard `cmake` configuration process to configure the build @@ -68,21 +68,21 @@ the standard way *from within the freecad_dev conda environment*. --- -# Building ⚙️ FreeCAD on macOS ⌘ using homebrew 🍺 with & without a formula file +# Building FreeCAD on macOS using homebrew with & without a formula file -> The below procedure provides on alternative way to install FreeCAD from the git source on macOS without having to use conda, but rather rely on [**mac homebrew**][lnk1] to manage dependencies. +> The below procedure provides an alternative way to install FreeCAD from the git source on macOS without having to use conda, but rather relies on [**mac homebrew**][lnk1] to manage dependencies. ## Requirements -- macOS, running high sierra _10.13_ or later -- mac homebrew installed and working -- all required dependencies to build FreeCAD installed using `brew install` +- macOS, running High Sierra _10.13_ or later +- homebrew installed and working +- All required dependencies to build FreeCAD installed using `brew install` -There is an official [**homebrew tap**][lnk2] that provides a list of formula along with freecad to setup all the dependencies to build FreeCAD from source on macOS, and also provides prebuilt bottles to install FreeCAD from a package rather than building from source. +There is an official [**homebrew tap**][lnk2] that provides a list of formulas along with FreeCAD to setup all the dependencies to build FreeCAD from source on macOS, and also provides prebuilt bottles to install FreeCAD from a package rather than building from source. > 💡 The below steps will build a FreeCAD binary that will launch FreeCAD from a command line interface, and will **NOT** build the **FreeCAD.app** bundle, ie. a double clickable app icon that can be launched from a Finder window. @@ -90,30 +90,30 @@ There is an official [**homebrew tap**][lnk2] that provides a list of formula al -- setup homebrew to use the official [**freecad-homebrew**][lnk2] tap. +- Setup homebrew to use the official [**freecad-homebrew**][lnk2] tap. ```shell brew tap FreeCAD/freecad ``` -- install FreeCAD dependencies provided by the tap +- Install FreeCAD dependencies provided by the tap ```shell brew install --only-dependencies freecad ``` -> the above step will install FreeCAD dependencies provided by the tap, and if a _bottle_ is provided by the tap homebrew will install the bottled version of the dep rather than building from source, unless the `install` command explicitly uses a _flag_ to build from source. +> The above step will install FreeCAD dependencies provided by the tap, and if a _bottle_ is provided by the tap homebrew will install the bottled version of the dep rather than building from source, unless the `install` command explicitly uses a _flag_ to build from source. -After all the dependencies have been installed, it should be possible to install freecad from the provided bottle. +After all the dependencies have been installed, it should be possible to install FreeCAD from the provided bottle. ```shell brew install freecad/freecad/freecad ``` > As of writing this, there are bottles provided for macOS Catalina and Big Sur -> > if running a different version of macOS then building freecad from source will be required. +> > If running a different version of macOS then building FreeCAD from source will be required. -To explicitly build freecad from source using the formula file provided by the tap +To explicitly build FreeCAD from source using the formula file provided by the tap ```shell brew install freecad/freecad/freecad --build-from-source --HEAD --verbose @@ -121,7 +121,7 @@ brew install freecad/freecad/freecad --build-from-source --HEAD --verbose The above command will grab the latest git source of FreeCAD and output the build process to the terminal. -> ⏲ On my MacBookPro 2013 late model it takes ~ 60 minutes to build FreeCAD from source. +> NOTE: On a MacBookPro 2013 late model it takes ~60 minutes to build FreeCAD from source. After the _make_ and _make install_ process completes it should be possible to launch FreeCAD from any directory using a terminal with the below commands, @@ -133,47 +133,47 @@ FreeCADCmd - `FreeCAD` will launch a GUI version of FreeCAD - `FreeCADCmd` will launch **only** a command line version of FreeCAD -## Limitations of using the freecad formula file +## Limitations of using the FreeCAD formula file -If freecad is installed via the bottle then one will have to wait for a new bottle to be generated to install a later version of freecad. However, if freecad is built from source, then FreeCAD will have all the updates up to the time the build process was started. +If FreeCAD is installed via the bottle then one will have to wait for a new bottle to be generated to install a later version of FreeCAD. However, if FreeCAD is built from source, then FreeCAD will have all the updates up to the time the build process was started. -When installing FreeCAD from source using the formula file provided by brew each subsequent build will require a complete rebuild of FreeCAD thus requiring an additional 60 minutes to build (my Macbook), and if any of the dependencies FreeCAD relies on is updated then more than likely FreeCAD will require a rebuild. mac homebrew does provide a feature to pin packages at specific versions to prevent them from updating, and also allows setting of an environment variable to prevent homebrew from automatically checking of updates (which can slow things down). All that said, FreeCAD can be built using all the dependencies provided by mac homebrew, but not using the formula file but rather cloning the source to an arbitrary path on a local file system providing a couple of advantages +If any of the dependencies FreeCAD relies on is updated FreeCAD will likely require a rebuild. Mac homebrew does provide a feature to pin packages at specific versions to prevent them from updating, and also allows setting of an environment variable to prevent homebrew from automatically checking for updates (which can slow things down). All that said, FreeCAD can be built using all the dependencies provided by Mac homebrew, but not using the formula file: instead cloning the source to an arbitrary path on a local filesystem. This provides a couple of advantages: -- if `brew cleanup` is ran, and FreeCAD was installed using the above provided command then all the source tarballs or bottles that were _checked out_ or downloaded during the install process will be delete from the system, and thus if a reinstall or upgrade is required then homebrew will have to refetch the bottles, or reclone the git source again. -- mac homebrew does provide a method, _install flag_ for keeping the source regardless if the build succeeds or fails, thus allowing to navigate to the git clone of FreeCAD source however the options are limited IMHO, and performing a standard `git clone` outside of homebrew is **much** preferred. -- cloning the FreeCAD source allows passing **any** cmake flags not provided by the formula file - - allowing to use other build systems such as _ninja_ - - allowing the use of alternate compilers, ie. _ccache_ - - pulling in subsequent updates are quicker because the `git clone` of the FreeCAD source will remain on the local filesystem even if a `brew cleanup` is ran - - subsequent recompiles should not take 60 minutes if using a cachining strategy such as _ccache_. +- If `brew cleanup` is run and FreeCAD was installed using the above-provided command, all source tarballs or bottles that were _checked out_ or downloaded during the install process will be deleted from the system. If a reinstall or upgrade is later required then homebrew will have to refetch the bottles, or reclone the git source again. +- Mac homebrew provides a method, _install flag_, for keeping the source regardless if the build succeeds or fails. The options are limited, however, and performing a standard `git clone` outside of homebrew is **much** preferred. +- Cloning the FreeCAD source allows passing **any** cmake flags not provided by the formula file + - Allowing the use of other build systems such as _ninja_ + - Allowing the use of alternate compilers, e.g. _ccache_ + - Pulling in subsequent updates are quicker because the `git clone` of the FreeCAD source will remain on the local filesystem even if a `brew cleanup` is run + - Subsequent recompiles should not take 60 minutes if using a caching strategy such as _ccache_. ## Directions, Installing FreeCAD using brew packages without a formula file -> ⚠️ the below directions assume macOS high sierra or later is being used, homebrew is setup properly and all dependencies have successfully been installed. +> ⚠️ The below directions assume macOS High Sierra or later is being used, homebrew is setup properly, and all dependencies were installed successfully. **TL;DR** -- clone the FreeCAD source, pass cmake args/flags within source dir, run make, and make install, then profit 💰 +- Clone the FreeCAD source, pass cmake args/flags within source dir, run make, and make install, then profit 💰 ### Expanded Directions -- clone the FreeCAD source from GitHub +- Clone the FreeCAD source from GitHub ```shell git clone https://github.com/freecad/freecad cd ./freecad -git fetch --unshallow +git fetch ``` -> The above _fetch_ cmd will take some time to fetch the commit history for the repo, but if a shallow clone is performed then FreeCAD will not show to correct build number in the About dialog [**learn more**][lnk3] +> The above _fetch_ cmd will take some time to fetch the commit history for the repo, but if a shallow clone is performed then FreeCAD will not show to correct build number in the About dialog [**learn more**][lnk3]. -I used the below cmake flags to build FreeCAD from a clone, and I'd recommend building FreeCAD in a specific _build branch_ rather than the master branch to not pollute the master branch with build artifacts. Also I'd prefer using clang provided by mac homebrew rather than Xcode, and if possible, I'd prefer using ccache provided by homebrew over using homebrew clang to speed rebuilds when required. +Advanced users may alter the process below to build in a different location, use a different compiler, etc. but these instructions represent a procedure that works successfully for this author. Set the path / environment variables for specifying the compilers to use @@ -182,7 +182,7 @@ export CC="/usr/local/opt/llvm/bin/clang" export CXX="/usr/local/opt/llvm/bin/clang++" ``` -- linking the brew provided install of python 3 will be required, in order for cmake to find the proper python, and python libraries. +- Linking the brew-provided install of python 3 will be required in order for cmake to find the proper python and python libraries. ```shell brew link python@3.9 @@ -192,7 +192,7 @@ brew link python@3.9 -- due to recent changes in boost ie. v1.75, building FreeCAD will fail with the below linking error message, for a more exhaustive error message, [**learn more**][lnk4] +- Due to recent changes in boost v1.75, building FreeCAD will fail with the below linking error message (for a more exhaustive error message, [**learn more**][lnk4]) To work around the linking issue until the [**PR**][lnk5] is merged install boost will the patches applied within the PR. @@ -212,12 +212,11 @@ cmake \ -DCMAKE_FIND_FRAMEWORK=LAST -DCMAKE_VERBOSE_MAKEFILE=ON \ -Wno-dev \ --DCMAKE_OSX_SYSROOT=/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk \ +-DCMAKE_OSX_SYSROOT=/Library/Developer/CommandLineTools/SDKs/macOSX10.14.sdk \ -std=c++14 \ -DCMAKE_CXX_STANDARD=14 \ -DBUILD_ENABLE_CXX_STD:STRING=C++14 \ -Wno-deprecated-declarations \ --DBUILD_QT5=ON \ -DUSE_PYTHON3=1 -DPYTHON_EXECUTABLE=/usr/local/bin/python3 \ -DBUILD_FEM_NETGEN=1 \ -DBUILD_FEM=1 \ @@ -234,7 +233,7 @@ make make install ``` -> The above cmake build flags are the ones I've had good luck with, but that's not to say other ones can be added or removed. And for reasons unknown to me the above build process takes ~ twice along than using `brew install --build-from-source` +> 💡 Author's note: The above cmake build flags are the ones I've had good luck with, but that's not to say other ones can be added or removed. And for reasons unknown to me the above build process takes ~ twice along than using `brew install --build-from-source` If everything goes well FreeCAD should be able to launch from a terminal @@ -242,7 +241,7 @@ If everything goes well FreeCAD should be able to launch from a terminal -While going through the process of getting FreeCAD to compile on macOS using brew with a formula file and without a formula file I ran into several issues along the way, and I'll document them here in case anyone else is run into such error and may have a frame of reference why such error happens. All that said, I **can not** list every possible eror that could arrise, but hopefully these can help guide will troubleshooting a problematic build. +Some common pitfalls are listed in this section. --- @@ -251,7 +250,7 @@ While going through the process of getting FreeCAD to compile on macOS using bre ```shell [ 18%] Building CXX object src/Gui/CMakeFiles/FreeCADGui.dir/DlgProjectInformationImp.cpp.o -cd /opt/code/github/public/forks/freecad/build/src/Gui && /usr/local/bin/ccache /usr/local/opt/llvm/bin/clang++ -DBOOST_ALL_NO_LIB -DBOOST_FILESYSTEM_DYN_LINK -DBOOST_PP_VARIADICS=1 -DBOOST_PROGRAM_OPTIONS_DYN_LINK -DBOOST_REGEX_DYN_LINK -DBOOST_SYSTEM_DYN_LINK -DBOOST_THREAD_DYN_LINK -DBUILD_ADDONMGR -DCMAKE_BUILD_TYPE=\"Release\" -DFreeCADGui_EXPORTS -DGL_SILENCE_DEPRECATION -DHAVE_CONFIG_H -DHAVE_FREEIMAGE -DHAVE_PYSIDE2 -DHAVE_RAPIDJSON -DHAVE_SHIBOKEN2 -DHAVE_TBB -DNDEBUG -DOCC_CONVERT_SIGNALS -DPYSIDE_QML_SUPPORT=1 -DQT_CORE_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_NO_DEBUG -DQT_OPENGL_LIB -DQT_PRINTSUPPORT_LIB -DQT_SVG_LIB -DQT_UITOOLS_LIB -DQT_WIDGETS_LIB -DQT_XML_LIB -D_OCC64 -I/opt/code/github/public/forks/freecad/build -I/opt/code/github/public/forks/freecad/build/src -I/opt/code/github/public/forks/freecad/src -I/opt/code/github/public/forks/freecad/src/Gui -I/opt/code/github/public/forks/freecad/src/Gui/Quarter -I/opt/code/github/public/forks/freecad/build/src/Gui -I/opt/code/github/public/forks/freecad/src/Gui/.. -I/opt/code/github/public/forks/freecad/build/src/Gui/.. -I/opt/code/github/public/forks/freecad/build/src/Gui/Language -I/opt/code/github/public/forks/freecad/build/src/Gui/propertyeditor -I/opt/code/github/public/forks/freecad/build/src/Gui/TaskView -I/opt/code/github/public/forks/freecad/build/src/Gui/Quarter -I/opt/code/github/public/forks/freecad/build/src/Gui/DAGView -I/usr/local/include/eigen3 -I/usr/local/include/PySide2/QtCore -I/usr/local/include/PySide2/QtGui -I/usr/local/include/PySide2/QtWidgets -isystem /usr/local/include -isystem /usr/local/Frameworks/Python.framework/Versions/3.9/include/python3.9 -iframework /usr/local/opt/qt/lib -isystem /usr/local/opt/qt/lib/QtCore.framework/Headers -isystem /usr/local/opt/qt/./mkspecs/macx-clang -isystem /usr/local/opt/qt/lib/QtWidgets.framework/Headers -isystem /usr/local/opt/qt/lib/QtGui.framework/Headers -isystem /Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/OpenGL.framework/Headers -isystem /usr/local/opt/qt/lib/QtOpenGL.framework/Headers -isystem /usr/local/opt/qt/lib/QtPrintSupport.framework/Headers -isystem /usr/local/opt/qt/lib/QtSvg.framework/Headers -isystem /usr/local/opt/qt/lib/QtNetwork.framework/Headers -isystem /usr/local/opt/qt/include -isystem /usr/local/opt/qt/include/QtUiTools -isystem /usr/local/include/shiboken2 -isystem /usr/local/include/PySide2 -isystem /usr/local/opt/qt/lib/QtXml.framework/Headers -Wall -Wextra -Wpedantic -Wno-write-strings -Wno-undefined-var-template -DNDEBUG -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk -fPIC -I/usr/local/Cellar/open-mpi/4.0.5/include -fPIC -std=gnu++14 -o CMakeFiles/FreeCADGui.dir/DlgProjectInformationImp.cpp.o -c /opt/code/github/public/forks/freecad/src/Gui/DlgProjectInformationImp.cpp +cd /opt/code/github/public/forks/freecad/build/src/Gui && /usr/local/bin/ccache /usr/local/opt/llvm/bin/clang++ -DBOOST_ALL_NO_LIB -DBOOST_FILESYSTEM_DYN_LINK -DBOOST_PP_VARIADICS=1 -DBOOST_PROGRAM_OPTIONS_DYN_LINK -DBOOST_REGEX_DYN_LINK -DBOOST_SYSTEM_DYN_LINK -DBOOST_THREAD_DYN_LINK -DBUILD_ADDONMGR -DCMAKE_BUILD_TYPE=\"Release\" -DFreeCADGui_EXPORTS -DGL_SILENCE_DEPRECATION -DHAVE_CONFIG_H -DHAVE_FREEIMAGE -DHAVE_PYSIDE2 -DHAVE_RAPIDJSON -DHAVE_SHIBOKEN2 -DHAVE_TBB -DNDEBUG -DOCC_CONVERT_SIGNALS -DPYSIDE_QML_SUPPORT=1 -DQT_CORE_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_NO_DEBUG -DQT_OPENGL_LIB -DQT_PRINTSUPPORT_LIB -DQT_SVG_LIB -DQT_UITOOLS_LIB -DQT_WIDGETS_LIB -DQT_XML_LIB -D_OCC64 -I/opt/code/github/public/forks/freecad/build -I/opt/code/github/public/forks/freecad/build/src -I/opt/code/github/public/forks/freecad/src -I/opt/code/github/public/forks/freecad/src/Gui -I/opt/code/github/public/forks/freecad/src/Gui/Quarter -I/opt/code/github/public/forks/freecad/build/src/Gui -I/opt/code/github/public/forks/freecad/src/Gui/.. -I/opt/code/github/public/forks/freecad/build/src/Gui/.. -I/opt/code/github/public/forks/freecad/build/src/Gui/Language -I/opt/code/github/public/forks/freecad/build/src/Gui/propertyeditor -I/opt/code/github/public/forks/freecad/build/src/Gui/TaskView -I/opt/code/github/public/forks/freecad/build/src/Gui/Quarter -I/opt/code/github/public/forks/freecad/build/src/Gui/DAGView -I/usr/local/include/eigen3 -I/usr/local/include/PySide2/QtCore -I/usr/local/include/PySide2/QtGui -I/usr/local/include/PySide2/QtWidgets -isystem /usr/local/include -isystem /usr/local/Frameworks/Python.framework/Versions/3.9/include/python3.9 -iframework /usr/local/opt/qt/lib -isystem /usr/local/opt/qt/lib/QtCore.framework/Headers -isystem /usr/local/opt/qt/./mkspecs/macx-clang -isystem /usr/local/opt/qt/lib/QtWidgets.framework/Headers -isystem /usr/local/opt/qt/lib/QtGui.framework/Headers -isystem /Library/Developer/CommandLineTools/SDKs/macOSX10.14.sdk/System/Library/Frameworks/OpenGL.framework/Headers -isystem /usr/local/opt/qt/lib/QtOpenGL.framework/Headers -isystem /usr/local/opt/qt/lib/QtPrintSupport.framework/Headers -isystem /usr/local/opt/qt/lib/QtSvg.framework/Headers -isystem /usr/local/opt/qt/lib/QtNetwork.framework/Headers -isystem /usr/local/opt/qt/include -isystem /usr/local/opt/qt/include/QtUiTools -isystem /usr/local/include/shiboken2 -isystem /usr/local/include/PySide2 -isystem /usr/local/opt/qt/lib/QtXml.framework/Headers -Wall -Wextra -Wpedantic -Wno-write-strings -Wno-undefined-var-template -DNDEBUG -isysroot /Library/Developer/CommandLineTools/SDKs/macOSX10.14.sdk -fPIC -I/usr/local/Cellar/open-mpi/4.0.5/include -fPIC -std=gnu++14 -o CMakeFiles/FreeCADGui.dir/DlgProjectInformationImp.cpp.o -c /opt/code/github/public/forks/freecad/src/Gui/DlgProjectInformationImp.cpp /opt/code/github/public/forks/freecad/src/Gui/DlgProjectInformationImp.cpp:56:9: error: no member named 'lineEditProgramVersion' in 'Gui::Dialog::Ui_DlgProjectInformation' ui->lineEditProgramVersion->setText(QString::fromUtf8(doc->getProgramVersion())); ~~ ^ @@ -263,7 +262,7 @@ make: *** [all] Error 2 -FreeCAD will fail to build if creating a build directory within the _src_ directory and running `cmake ..` within the newly created _build_ directory. As it currently stands, `cmake` needs run within the _src_ directory or the below error message will more than likely appear durning the build process. +FreeCAD may fail to build if creating a build directory within the _src_ directory and running `cmake ..` within the newly created _build_ directory. As it currently stands, `cmake` needs run within the _src_ directory or the this error message will likely appear during the build process. --- @@ -280,7 +279,7 @@ FreeCAD will fail to build if creating a build directory within the _src_ direct -On macOS most if not all filesystems are case **insensitive** whereas most GNU+Linux distros use _case sensitive_ file systems. So if freecad source is cloned within a `FreeCAD` directory the build process on macOS will look for a `freecad` that is _case sensitive_ however the file system isn't case sensitive, thus the compiler will provide the above warning message. +On macOS most filesystems are case **insensitive**, whereas most GNU+Linux distros use _case sensitive_ file systems. So if FreeCAD source is cloned within a `FreeCAD` directory the build process on macOS may look for a `freecad` that is _case sensitive_ however the file system isn't case sensitive, thus the compiler will provide the above warning message. One way to resolve such error message is to rename `FreeCAD` to `freecad` @@ -291,8 +290,6 @@ mv freecadd freecad; --- -The text within this document is by no means exhaustive and aiming to cover every edge but does aim to serve as a decent starting point for setting up macOS to build FreeCAD from source. - [lnk1]: From 65a60fa639c8344a43525408d555d3b648f758f4 Mon Sep 17 00:00:00 2001 From: Roy-043 <70520633+Roy-043@users.noreply.github.com> Date: Mon, 20 Sep 2021 11:01:59 +0200 Subject: [PATCH 53/55] Draft: Fix annotation scale to label issue. The scale_to_label function did not handle scale 5:1, 10:1 or 20:1 properly. --- .../Draft/draftutils/init_draft_statusbar.py | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/Mod/Draft/draftutils/init_draft_statusbar.py b/src/Mod/Draft/draftutils/init_draft_statusbar.py index 5d41b8b6a1..67a700b113 100644 --- a/src/Mod/Draft/draftutils/init_draft_statusbar.py +++ b/src/Mod/Draft/draftutils/init_draft_statusbar.py @@ -97,14 +97,22 @@ def scale_to_label(scale): """ transform a float number into a 1:X or X:1 scale and return it as label """ - f = 1/scale - f = round(f,2) - f = f.as_integer_ratio() - if f[1] == 1 or f[0] == 1: - label = str(f[1]) + ":" + str(f[0]) - return label + f = round(scale, 2) + if f == 1.0: + return "1:1" + elif f > 1.0: + f = f.as_integer_ratio() + if f[1] == 1: + return str(f[0]) + ":1" + else: + return str(scale) else: - return str(scale) + f = round(1/scale, 2) + f = f.as_integer_ratio() + if f[1] == 1: + return "1:" + str(f[0]) + else: + return str(scale) def label_to_scale(label): """ From 47fe2babac89ee47edd9fc362d8fd2d7d9653b2c Mon Sep 17 00:00:00 2001 From: wmayer Date: Mon, 20 Sep 2021 18:15:44 +0200 Subject: [PATCH 54/55] port to MSYS2/clang --- src/Base/BaseClass.h | 1 - src/Mod/Part/App/GeometryDefaultExtension.h | 9 +++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Base/BaseClass.h b/src/Base/BaseClass.h index 66be845d6a..f5b5a20f4f 100644 --- a/src/Base/BaseClass.h +++ b/src/Base/BaseClass.h @@ -63,7 +63,6 @@ void * _class_::create(void){\ /// define to implement a subclass of Base::BaseClass #define TYPESYSTEM_SOURCE_TEMPLATE_P(_class_) \ -template<> Base::Type _class_::classTypeId = Base::Type::badType(); \ template<> Base::Type _class_::getClassTypeId(void) { return _class_::classTypeId; } \ template<> Base::Type _class_::getTypeId(void) const { return _class_::classTypeId; } \ template<> void * _class_::create(void){\ diff --git a/src/Mod/Part/App/GeometryDefaultExtension.h b/src/Mod/Part/App/GeometryDefaultExtension.h index 246f55d185..4eaf1de579 100644 --- a/src/Mod/Part/App/GeometryDefaultExtension.h +++ b/src/Mod/Part/App/GeometryDefaultExtension.h @@ -86,6 +86,15 @@ namespace Part { // 5. Provide specialisations if your type does not meet the assumptions above (e.g. for serialisation) (cpp file) // 6. Register your type and corresponding python type in AppPart.cpp + template + Base::Type GeometryDefaultExtension::classTypeId{Base::Type::badType()}; + + // Must be explicitly declared here + template<> void * GeometryDefaultExtension::create(); + template<> void * GeometryDefaultExtension::create(); + template<> void * GeometryDefaultExtension::create(); + template<> void * GeometryDefaultExtension::create(); + template inline GeometryDefaultExtension::GeometryDefaultExtension():value{}{} From d91ba28614cc5924ca0dd0e4901373f0da1b5e0e Mon Sep 17 00:00:00 2001 From: Przemo Firszt Date: Sun, 4 Jul 2021 19:11:19 +0100 Subject: [PATCH 55/55] [gitlab-ci] gitlab CI on docker initial commit --- ci/.gitlab-ci.yml | 56 ++++++++++++++++++++++ ci/Dockerfile | 118 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 174 insertions(+) create mode 100644 ci/.gitlab-ci.yml create mode 100644 ci/Dockerfile diff --git a/ci/.gitlab-ci.yml b/ci/.gitlab-ci.yml new file mode 100644 index 0000000000..edb7bd10b9 --- /dev/null +++ b/ci/.gitlab-ci.yml @@ -0,0 +1,56 @@ +# This file is a template, and might need editing before it works on your project. +# To contribute improvements to CI/CD templates, please follow the Development guide at: +# https://docs.gitlab.com/ee/development/cicd/templates.html +# This specific template is located at: +# https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/Getting-Started.gitlab-ci.yml + +# This is a sample GitLab CI/CD configuration file that should run without any modifications. +# It demonstrates a basic 3 stage CI/CD pipeline. Instead of real tests or scripts, +# it uses echo commands to simulate the pipeline execution. +# +# A pipeline is composed of independent jobs that run scripts, grouped into stages. +# Stages run in sequential order, but jobs within stages run in parallel. +# +# For more information, see: https://docs.gitlab.com/ee/ci/yaml/README.html#stages + +# this image is on dockerhub. Dockerfile is here: https://gitlab.com/PrzemoF/FreeCAD/-/blob/gitlab-v1/ci/Dockerfile +image: freecadci/runner + +stages: # List of stages for jobs, and their order of execution + - build + - test + +before_script: + - apt-get update -yqq + # CCache Config + - mkdir -p ccache + - export CCACHE_BASEDIR=${PWD} + - export CCACHE_DIR=${PWD}/ccache + +cache: + paths: + - ccache/ + +build-job: # This job runs in the build stage, which runs first. + stage: build + + script: + - echo "Compiling the code..." + - mkdir build + - cd build + - ccache cmake ../ + - ccache cmake --build ./ -j$(nproc) + - echo "Compile complete." + + artifacts: + paths: + - build/ + +test-job: # This job runs in the test stage. + stage: test # It only starts when the job in the build stage completes successfully. + script: + - echo "Running unit tests... " + - cd build/bin/ + # Testing currently doesn't work due to problems with libraries ot being visible by the binary. + - ./FreeCADCmd -t 0 + diff --git a/ci/Dockerfile b/ci/Dockerfile new file mode 100644 index 0000000000..fb5196ed4d --- /dev/null +++ b/ci/Dockerfile @@ -0,0 +1,118 @@ +FROM ubuntu:20.04 +MAINTAINER Przemo Firszt +# This is the docker image definition used to build FreeCAD. It's currently accessible on: +# https://hub.docker.com/repository/docker/freecadci/runner +# on under name freecadci/runner when using docker + +ENV DEBIAN_FRONTEND=noninteractive + +RUN apt-get update -y +RUN apt-get update -y && apt-get install -y gnupg2 +RUN echo "deb http://ppa.launchpad.net/freecad-maintainers/freecad-daily/ubuntu focal main" >> /etc/apt/sources.list.d/freecad-daily.list +RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 83193AA3B52FF6FCF10A1BBF005EAE8119BB5BCA +RUN apt-get update -y + +# those 3 are for debugging purposes only. Not required to build FreeCAD +RUN apt-get install -y \ + vim \ + nano \ + bash + +# Main set of FreeCAD dependencies. To be verified. +RUN apt-get install -y \ + ccache \ + cmake \ + debhelper \ + dh-exec \ + dh-python \ + doxygen \ + git \ + graphviz \ + libboost-date-time-dev \ + libboost-dev \ + libboost-filesystem-dev \ + libboost-filesystem1.71-dev \ + libboost-graph-dev \ + libboost-iostreams-dev \ + libboost-program-options-dev \ + libboost-program-options1.71-dev \ + libboost-python1.71-dev \ + libboost-regex-dev \ + libboost-regex1.71-dev \ + libboost-serialization-dev \ + libboost-system1.71-dev \ + libboost-thread-dev \ + libboost-thread1.71-dev \ + libboost1.71-dev \ + libcoin-dev \ + libdouble-conversion-dev \ + libeigen3-dev \ + libglew-dev \ + libgts-bin \ + libgts-dev \ + libkdtree++-dev \ + liblz4-dev \ + libmedc-dev \ + libmetis-dev \ + libnglib-dev \ + libocct-data-exchange-dev \ + libocct-ocaf-dev \ + libocct-visualization-dev \ + libopencv-dev \ + libproj-dev \ + libpyside2-dev \ + libqt5opengl5 \ + libqt5opengl5-dev \ + libqt5svg5-dev \ + libqt5webkit5 \ + libqt5webkit5-dev \ + libqt5x11extras5-dev \ + libqt5xmlpatterns5-dev \ + libshiboken2-dev \ + libspnav-dev \ + libvtk7-dev \ + libvtk7.1p \ + libvtk7.1p-qt \ + libx11-dev \ + libxerces-c-dev \ + libzipios++-dev \ + lsb-release \ + nastran \ + netgen \ + netgen-headers \ + occt-draw \ + pybind11-dev \ + pyqt5-dev-tools \ + pyside2-tools \ + python3-dev \ + python3-matplotlib \ + python3-pivy \ + python3-ply \ + python3-pyqt5 \ + python3-pyside2.* \ + python3-pyside2.qtcore \ + python3-pyside2.qtgui \ + python3-pyside2.qtsvg \ + python3-pyside2.qtuitools \ + python3-pyside2.qtwidgets \ + python3-pyside2.qtxml \ + python3-requests \ + python3-yaml \ + qt5-default \ + qt5-qmake \ + qtbase5-dev \ + qttools5-dev \ + qtwebengine5-dev \ + swig + +RUN apt-get update -y --fix-missing + +# Clean +RUN apt-get clean \ + && rm /var/lib/apt/lists/* \ + /usr/share/doc/* \ + /usr/share/locale/* \ + /usr/share/man/* \ + /usr/share/info/* -fR + +