Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Material: Material handling enhancements #10690

Merged
merged 3 commits into from Sep 27, 2023

Conversation

davesrocketshop
Copy link
Contributor

Rework of the material handling system.

This is a replacement for #10368, which will be closed in favour of this request.

This first part concentrates on a rework of the material cards. Rather than use a fixed list of possible properties, properties can be defined separately in their own files and mixed to provide a complete list of possible properties. Properties can be inherited.

The cards then provide values for the properties. These can also be inherited allowing for small changes in cards as required.

The new property definitions are more extensive than previously. 2 and 3 dimensional arrays of properties can be defined. Values are obtained by calling an API instead of reading from a dictionary.

For compatibility, a Python dictionary of values can be obtained similar to how it was done previously, but this is considered a deprecated API and won't support the newer advanced features.

The editor is completely reworked. It will be able to edit older format material cards, but can only save them in the new format.

For testing during the development phase, a system preference can specify whether the old or new material editors are to be used. This option will be removed before release.

@github-actions github-actions bot added WB FEM Related to the FEM Workbench :octocat: labels Sep 15, 2023
@chennes chennes self-assigned this Sep 15, 2023
@chennes chennes added this to the 1.0 milestone Sep 15, 2023
@chennes
Copy link
Member

chennes commented Sep 18, 2023

@FEA-eng -- can you take a look at the FEM side of this to make sure I'm not missing any major flaws?

@sliptonic
Copy link
Member

This is obviously a big one. So we need some concentrated testing and code review.
Maintainers will revisit this at the meeting next week (9/25)

@FEA-eng
Copy link
Contributor

FEA-eng commented Sep 18, 2023

@FEA-eng -- can you take a look at the FEM side of this to make sure I'm not missing any major flaws?

I have issues with compilation from source code but I'll try to test this somehow.

@davesrocketshop
Copy link
Contributor Author

@FEA-eng -- can you take a look at the FEM side of this to make sure I'm not missing any major flaws?

I have issues with compilation from source code but I'll try to test this somehow.

There is a new dependency on lib-yaml. If you're on Linux, you'll need to install lib-yaml-dev. On windows, you'll need the latest libpack

@FEA-eng
Copy link
Contributor

FEA-eng commented Sep 18, 2023

There is a new dependency on lib-yaml. If you're on Linux, you'll need to install lib-yaml-dev. On windows, you'll need the latest libpack

Well, it's a bigger issue in my case. I haven't been able to compile on Windows without crashes when creating any geometry: https://forum.freecad.org/viewtopic.php?t=73143&start=30#p703935

When it comes to Linux, my virtual Ubuntu machine is missing some dependencies and I don't know how to add them: https://forum.freecad.org/viewtopic.php?t=81204

macro(SetupYamlCpp)
# -------------------------------- YamlCpp --------------------------------

find_package(yaml-cpp REQUIRED)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Marking this as "REQUIRED" should eliminate the need for the test code after it, right?

@chennes
Copy link
Member

chennes commented Sep 18, 2023

@davesrocketshop The only changes to FEM appear to be clang-format-based -- is that correct?

@davesrocketshop
Copy link
Contributor Author

@davesrocketshop The only changes to FEM appear to be clang-format-based -- is that correct?

Not quite. The material preferences have been removed from FEM. There are now separate preferences under Materials.

This means the removal of the .ui file, it's corresponding .h and .cpp, CMakefiles, and the line of code that loaded it in AppFemGui.cpp.

@chennes
Copy link
Member

chennes commented Sep 18, 2023

I don't see those changes in the current version of this PR -- can you double-check that you've git added them?

@davesrocketshop
Copy link
Contributor Author

I don't see those changes in the current version of this PR -- can you double-check that you've git added them?

Looking at the changed files, they're in there. They also show correctly in the PR branch.

@chennes
Copy link
Member

chennes commented Sep 18, 2023

That's very strange, I don't see any file removals from FEM in this PR. I'll try to look closer this evening.

@davesrocketshop
Copy link
Contributor Author

The removals aren't showing in the "Files changed" section, but they're not there. Can't really explain that. The removed files are:

src/Mod/Fem/Gui/DlgSettingsFemMaterial.ui
src/Mod/Fem/Gui/DlgSettingsFemMaterialImp.cpp
src/Mod/Fem/Gui/DlgSettingsFemMaterialImp.h

The changes are showing in CMakeFiles.txt and AppFemGui.cpp

@@ -25,35 +25,26 @@
#include <Base/Console.h>
#include <Base/PyObjectBase.h>
#include <Gui/Application.h>
#include <Gui/WidgetFactory.h>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know who or what has modified this file but as long as Fem is not listed in the .pre-commit-config.yaml file any formatting changes should be avoided.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This happened when saving the file in VSCode, which is configured to apply the clang rules on saving. The modification was the removal of the material preferences panel, in favour of moving it to a Materials preferences page.

{
this->setMessage(msg);
}
~Uninitialized() throw() override = default;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

throw() is deprecated. Use noexcept instead.

{}
virtual ~FolderTreeNode() = default;

NodeType getType(void) const
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See modernize-redundant-void-arg: In modern C++ code void shouldn't be use any more as argument of a function.


private:
NodeType _type;
std::map<QString, FolderTreeNode<T>*>* _folder;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the ownership of these pointers handled? If not consider using a std::shared_ptr.

MaterialConfigLoader::MaterialConfigLoader()
{}

bool MaterialConfigLoader::isConfigStyle(const QString& path)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix const-correctness

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Static function, so already const correct

return true;
}

QString MaterialConfigLoader::getAuthorAndLicense(const QString& path)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix const-correctness

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Static function, so already const correct

* *
* This file is part of the FreeCAD CAx development system. *
* *
* This program is free software; you can redistribute it and/or modify *
Copy link
Contributor

@wwmayer wwmayer Sep 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For new source files we should use the new copyright text:

/***************************************************************************
 *   Copyright (c) 2023 David Carter <dcarter@david.carter.ca>             *
 *                                                                         *
 *   This file is part of FreeCAD.                                         *
 *                                                                         *
 *   FreeCAD is free software: you can redistribute it and/or modify it    *
 *   under the terms of the GNU Lesser General Public License as           *
 *   published by the Free Software Foundation, either version 2.1 of the  *
 *   License, or (at your option) any later version.                       *
 *                                                                         *
 *   FreeCAD 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      *
 *   Lesser General Public License for more details.                       *
 *                                                                         *
 *   You should have received a copy of the GNU Lesser General Public      *
 *   License along with FreeCAD. If not, see                               *
 *   <https://www.gnu.org/licenses/>.                                      *
 *                                                                         *
 **************************************************************************/


public:
MaterialManager();
virtual ~MaterialManager() = default;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be ~MaterialManager() override = default;

#define MATERIAL_MATERIALVALUE_H

#include <QVariant>

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lacks of #include <Mod/Material/MaterialGlobal.h>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copied from other workbenches but I'll definitely fix


MaterialProperty::MaterialProperty()
{
_valuePtr = new MaterialValue(MaterialValue::None);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possible memory leak! _valuePtr is a raw pointer but the destructor doesn't destroy it.
As said above consider using a std::shared_ptr or std::unique_ptr


#include <FCConfig.h>

#include <Mod/Material/MaterialGlobal.h>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This include shouldn't be needed here because every header that requires the export macro should include it. Only this way the clang code model will be able to correctly parse source files.

Copy link
Contributor

@wwmayer wwmayer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comments in the source code.

@davesrocketshop
Copy link
Contributor Author

See comments in the source code.

Good comments. I'll get to work. It should be noted however that many of your comments are for code copied closely from other workbenches, which is why it was done this way. I also appear to have skipped a few C++ "standardization" meetings, so I'm relearning :)

@FEA-eng
Copy link
Contributor

FEA-eng commented Sep 24, 2023

For testing during the development phase, a system preference can specify whether the old or new material editors are to be used. This option will be removed before release.

What is that variable ? I built FreeCAD from your branch but I see the old editor. How can I activate the new one ?

@davesrocketshop
Copy link
Contributor Author

preferences

Unselect "Use legacy editor" in the Material preferences

@FEA-eng
Copy link
Contributor

FEA-eng commented Sep 24, 2023

Unselect "Use legacy editor" in the Material preferences

The problem is that I don't have "Material" in Preferences. Is there something else that I should do to activate it ?

@davesrocketshop
Copy link
Contributor Author

Unselect "Use legacy editor" in the Material preferences

The problem is that I don't have "Material" in Preferences. Is there something else that I should do to activate it ?

This is a problem I haven't figured out. If you load the workbench it shows up, but I haven't figured out how to do that automatically. There's also no option to load the workbench in the workbench preferences, it just doesn't show up.

As a workaround, in the Python console, type 'import MatGui'. You'll then have the preferences available.

@davesrocketshop davesrocketshop force-pushed the material_merge branch 2 times, most recently from 485be95 to bb83faa Compare September 25, 2023 11:27
@davesrocketshop
Copy link
Contributor Author

Unselect "Use legacy editor" in the Material preferences

The problem is that I don't have "Material" in Preferences. Is there something else that I should do to activate it ?

I have fixed the issue and merged the changes. If you refresh your repo you will see normal workbench behaviour

@chennes
Copy link
Member

chennes commented Sep 25, 2023

@davesrocketshop can you rebase? You're probably getting conflicts because we just added FEM to our pre-commit formatter.

@davesrocketshop
Copy link
Contributor Author

@davesrocketshop can you rebase? You're probably getting conflicts because we just added FEM to our pre-commit formatter.

I'd want someone to walk me through that as it's not something I've done before. Every thing I read says don't do it unless you know what you're doing and I definitely don't

@chennes
Copy link
Member

chennes commented Sep 25, 2023

Sorry, I was using "rebase" as shorthand for "using whatever strategy you like, fix the conflicts that have now appeared with the merge" -- I'd personally git pull --rebase upstream master.

Rework of the material handling system.

This first part concntrates on a rework of the material cards.
Rather than use a fixed list of possible properties, properties can
be defined separately in their own files and mixed to provide a
complete list of possible properties. Properties can be inherited.

The cards then provide values for the properties. These can also
be inherited allowing for small changes in cards as required.

The new property definitions are more extensive than previously.
2 and 3 dimensional arrays of properties can be defined. Values
are obtained by calling an API instead of reading from a dictionary.

For compatibility, a Python dictionary of values can be obtained
similar to how it was done previously, but this is considered a
deprecated API and won't support the newer advanced features.

The editor is completely reworked. It will be able to edit older format
material cards, but can only save them in the new format.

For testing during the development phase, a system preference can
specifiy wether the old or new material editors are to be used. This
option will be removed before release.
Rework of the material handling system.

This first part concntrates on a rework of the material cards.
Rather than use a fixed list of possible properties, properties can
be defined separately in their own files and mixed to provide a
complete list of possible properties. Properties can be inherited.

The cards then provide values for the properties. These can also
be inherited allowing for small changes in cards as required.

The new property definitions are more extensive than previously.
2 and 3 dimensional arrays of properties can be defined. Values
are obtained by calling an API instead of reading from a dictionary.

For compatibility, a Python dictionary of values can be obtained
similar to how it was done previously, but this is considered a
deprecated API and won't support the newer advanced features.

The editor is completely reworked. It will be able to edit older format
material cards, but can only save them in the new format.

For testing during the development phase, a system preference can
specifiy wether the old or new material editors are to be used. This
option will be removed before release.
@davesrocketshop
Copy link
Contributor Author

Sorry, I was using "rebase" as shorthand for "using whatever strategy you like, fix the conflicts that have now appeared with the merge" -- I'd personally git pull --rebase upstream master.

Done

@luzpaz
Copy link
Contributor

luzpaz commented Sep 27, 2023

What's left to do here ?

@davesrocketshop
Copy link
Contributor Author

What's left to do here ?

I have no actionable items I'm aware of for this PR. I'm already working on the follow on.

@chennes
Copy link
Member

chennes commented Sep 27, 2023

I was waiting for the CI to get cleaned up in the master branch (an earlier PR broke things) -- since this is going to be a big merge I didn't want to muddy the waters 😄 .

@chennes chennes merged commit dcbb74a into FreeCAD:master Sep 27, 2023
7 checks passed
@luzpaz
Copy link
Contributor

luzpaz commented Sep 28, 2023

Congrats @davesrocketshop and FreeCAD as a whole. Really exciting milestone!

@davesrocketshop davesrocketshop deleted the material_merge branch November 2, 2023 12:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:octocat: WB FEM Related to the FEM Workbench
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

6 participants