Skip to content

Commit

Permalink
Assembly: Implement Bill Of Materials (#14198)
Browse files Browse the repository at this point in the history
* Assembly: Implementation of BOM

* Assembly: BOM: make it possible for BOM to be made without an assembly.
  • Loading branch information
PaddleStroke committed Jun 17, 2024
1 parent 60a0e70 commit 3fa0b68
Show file tree
Hide file tree
Showing 31 changed files with 2,355 additions and 29 deletions.
6 changes: 6 additions & 0 deletions src/Mod/Assembly/App/AppAssembly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include <Base/PyObjectBase.h>

#include "AssemblyObject.h"
#include "BomObject.h"
#include "BomGroup.h"
#include "JointGroup.h"
#include "ViewGroup.h"

Expand All @@ -43,6 +45,7 @@ PyMOD_INIT_FUNC(AssemblyApp)
// load dependent module
try {
Base::Interpreter().runString("import Part");
Base::Interpreter().runString("import Spreadsheet");
}
catch (const Base::Exception& e) {
PyErr_SetString(PyExc_ImportError, e.what());
Expand All @@ -58,6 +61,9 @@ PyMOD_INIT_FUNC(AssemblyApp)
// This function is responsible for adding inherited slots from a type's base class.

Assembly::AssemblyObject ::init();
Assembly::BomObject ::init();

Assembly::BomGroup ::init();
Assembly::JointGroup ::init();
Assembly::ViewGroup ::init();

Expand Down
55 changes: 55 additions & 0 deletions src/Mod/Assembly/App/BomGroup.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
/****************************************************************************
* *
* Copyright (c) 2023 Ondsel <development@ondsel.com> *
* *
* 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/>. *
* *
***************************************************************************/

#include "PreCompiled.h"
#ifndef _PreComp_
#endif

#include <App/Application.h>
#include <App/Document.h>
#include <App/FeaturePythonPyImp.h>
#include <App/PropertyPythonObject.h>
#include <Base/Console.h>
#include <Base/Tools.h>

#include "BomGroup.h"
#include "BomGroupPy.h"

using namespace Assembly;


PROPERTY_SOURCE(Assembly::BomGroup, App::DocumentObjectGroup)

Check warning on line 41 in src/Mod/Assembly/App/BomGroup.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

variable 'classTypeId' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables]

Check warning on line 41 in src/Mod/Assembly/App/BomGroup.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

variable 'propertyData' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables]

BomGroup::BomGroup()

Check warning on line 43 in src/Mod/Assembly/App/BomGroup.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

use '= default' to define a trivial default constructor [modernize-use-equals-default]
{}

BomGroup::~BomGroup() = default;

PyObject* BomGroup::getPyObject()
{
if (PythonObject.is(Py::_None())) {
// ref counter is set to 1
PythonObject = Py::Object(new BomGroupPy(this), true);
}
return Py::new_reference_to(PythonObject);
}
58 changes: 58 additions & 0 deletions src/Mod/Assembly/App/BomGroup.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
/****************************************************************************
* *
* Copyright (c) 2023 Ondsel <development@ondsel.com> *
* *
* 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/>. *
* *
***************************************************************************/


#ifndef ASSEMBLY_BomGroup_H
#define ASSEMBLY_BomGroup_H

#include <Mod/Assembly/AssemblyGlobal.h>

#include <App/DocumentObjectGroup.h>
#include <App/PropertyLinks.h>


namespace Assembly
{

class AssemblyExport BomGroup: public App::DocumentObjectGroup

Check warning on line 37 in src/Mod/Assembly/App/BomGroup.h

View workflow job for this annotation

GitHub Actions / Lint / Lint

class 'BomGroup' defines a non-default destructor but does not define a copy constructor, a copy assignment operator, a move constructor or a move assignment operator [cppcoreguidelines-special-member-functions]
{
PROPERTY_HEADER_WITH_OVERRIDE(Assembly::BomGroup);

Check warning on line 39 in src/Mod/Assembly/App/BomGroup.h

View workflow job for this annotation

GitHub Actions / Lint / Lint

variable 'classTypeId' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables]

public:
BomGroup();
~BomGroup() override;

PyObject* getPyObject() override;

/// returns the type name of the ViewProvider
const char* getViewProviderName() const override
{
return "AssemblyGui::ViewProviderBomGroup";
}
};


} // namespace Assembly


#endif // ASSEMBLY_BomGroup_H
19 changes: 19 additions & 0 deletions src/Mod/Assembly/App/BomGroupPy.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<GenerateModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="generateMetaModel_Module.xsd">
<PythonExport
Father="DocumentObjectGroupPy"
Name="BomGroupPy"
Twin="BomGroup"
TwinPointer="BomGroup"
Include="Mod/Assembly/App/BomGroup.h"
Namespace="Assembly"
FatherInclude="App/DocumentObjectGroupPy.h"
FatherNamespace="App">
<Documentation>
<Author Licence="LGPL" Name="Ondsel" EMail="development@ondsel.com" />
<UserDocu>This class is a group subclass for boms.</UserDocu>
</Documentation>

<CustomAttributes />
</PythonExport>
</GenerateModel>
46 changes: 46 additions & 0 deletions src/Mod/Assembly/App/BomGroupPyImp.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/***************************************************************************
* Copyright (c) 2014 Jürgen Riegel <juergen.riegel@web.de> *
* *
* 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"

// inclusion of the generated files (generated out of BomGroup.xml)
#include "BomGroupPy.h"
#include "BomGroupPy.cpp"

using namespace Assembly;

// returns a string which represents the object e.g. when printed in python
std::string BomGroupPy::representation() const
{
return {"<Bom Group>"};
}

PyObject* BomGroupPy::getCustomAttributes(const char* /*attr*/) const
{
return nullptr;
}

int BomGroupPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
{
return 0;
}

7 comments on commit 3fa0b68

@adrianinsaval
Copy link
Member

Choose a reason for hiding this comment

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

this broke gui tests on ubuntu 20.04, @PaddleStroke please check

@wwmayer
Copy link
Contributor

Choose a reason for hiding this comment

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

Here some details:

2024-06-17T20:06:27.3678931Z Activate workbench 'AssemblyWorkbench'
2024-06-17T20:06:27.3679549Z FAILED: testActivate (Workbench.WorkbenchTestCase)
2024-06-17T20:06:27.3680191Z Traceback (most recent call last):
2024-06-17T20:06:27.3680896Z   File "/usr/local/Mod/Test/Workbench.py", line 63, in testActivate
2024-06-17T20:06:27.3681929Z     self.assertTrue(success, "Test on activating workbench {0} failed".format(i))
2024-06-17T20:06:27.3683135Z   File "/usr/lib/python3.8/unittest/case.py", line 765, in assertTrue
2024-06-17T20:06:27.3683915Z     raise self.failureException(msg)
2024-06-17T20:06:27.3684803Z AssertionError: False is not true : Test on activating workbench AssemblyWorkbench failed
2024-06-17T20:06:27.3685559Z 
2024-06-17T20:06:27.3685924Z During handling of the above exception, another exception occurred:
2024-06-17T20:06:27.3686517Z 
2024-06-17T20:06:27.3686683Z Traceback (most recent call last):
2024-06-17T20:06:27.3687431Z   File "/usr/lib/python3.8/unittest/case.py", line 60, in testPartExecutor
2024-06-17T20:06:27.3688187Z     yield
2024-06-17T20:06:27.3688685Z   File "/usr/lib/python3.8/unittest/case.py", line 676, in run
2024-06-17T20:06:27.3689381Z     self._callTestMethod(testMethod)
2024-06-17T20:06:27.3690140Z   File "/usr/lib/python3.8/unittest/case.py", line 633, in _callTestMethod
2024-06-17T20:06:27.3690873Z     method()
2024-06-17T20:06:27.3691432Z   File "/usr/local/Mod/Test/Workbench.py", line 65, in testActivate
2024-06-17T20:06:27.3692466Z     self.fail("Loading of workbench '{0}' failed: {1}".format(i, e))
2024-06-17T20:06:27.3693338Z   File "/usr/lib/python3.8/unittest/case.py", line 753, in fail
2024-06-17T20:06:27.3694032Z     raise self.failureException(msg)
2024-06-17T20:06:27.3695244Z AssertionError: Loading of Optional dependency on disallowed_package ignored because it is not in the allow-list

@PaddleStroke
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @wwmayer for the details. However I have a hard time understanding this report. Do you know what is the allow-list ? It sounds like it is failing to load Assembly because of the dependency on spreadsheet.

@wwmayer
Copy link
Contributor

Choose a reason for hiding this comment

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

AFAIK the allow list comes from the addon manager test cases and probably has nothing to do with the failing test.
But maybe @chennes knows more.

@chennes
Copy link
Member

Choose a reason for hiding this comment

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

That's right -- the "Assertion error" you see at the bottom is actually the test passing -- an error was raised, and caught. So it's not part of the "real" output above it.

@PaddleStroke
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Anyone has a ubuntu 20.04 at hand?
If so can you test if you can activate the assembly workbench ? Perhaps that will give more details about the problem than the failing test

@PaddleStroke
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Finally found the issue : #14812

Please sign in to comment.