From bac2b83537ef4acfb6f90a884db8514cbb7fe7d2 Mon Sep 17 00:00:00 2001 From: wmayer Date: Sun, 1 Oct 2023 19:27:25 +0200 Subject: [PATCH] Import: rename ImportOCAFExt to ImportOCAFGui and move to own source files --- src/Mod/Import/Gui/AppImportGuiPy.cpp | 81 +------------------ src/Mod/Import/Gui/CMakeLists.txt | 2 + src/Mod/Import/Gui/ImportOCAFGui.cpp | 108 ++++++++++++++++++++++++++ src/Mod/Import/Gui/ImportOCAFGui.h | 48 ++++++++++++ 4 files changed, 161 insertions(+), 78 deletions(-) create mode 100644 src/Mod/Import/Gui/ImportOCAFGui.cpp create mode 100644 src/Mod/Import/Gui/ImportOCAFGui.h diff --git a/src/Mod/Import/Gui/AppImportGuiPy.cpp b/src/Mod/Import/Gui/AppImportGuiPy.cpp index 1996939ef56e..2da59997de2e 100644 --- a/src/Mod/Import/Gui/AppImportGuiPy.cpp +++ b/src/Mod/Import/Gui/AppImportGuiPy.cpp @@ -86,6 +86,7 @@ #endif #include "ExportOCAFGui.h" +#include "ImportOCAFGui.h" #include #include @@ -96,7 +97,6 @@ #include #include #include -#include #include #include #include @@ -270,81 +270,6 @@ void OCAFBrowser::load(const TDF_Label& label, QTreeWidgetItem* item, const QStr } } -class ImportOCAFExt: public Import::ImportOCAF2 -{ -public: - ImportOCAFExt(Handle(TDocStd_Document) h, App::Document* d, const std::string& name) - : ImportOCAF2(h, d, name) - {} - -private: - void applyFaceColors(Part::Feature* part, const std::vector& colors) override - { - auto vp = dynamic_cast( - Gui::Application::Instance->getViewProvider(part)); - if (!vp) { - return; - } - if (colors.empty()) { - return; - } - - if (colors.size() == 1) { - vp->ShapeColor.setValue(colors.front()); - vp->Transparency.setValue(100 * colors.front().a); - } - else { - vp->DiffuseColor.setValues(colors); - } - } - void applyEdgeColors(Part::Feature* part, const std::vector& colors) override - { - auto vp = dynamic_cast( - Gui::Application::Instance->getViewProvider(part)); - if (!vp) { - return; - } - if (colors.size() == 1) { - vp->LineColor.setValue(colors.front()); - } - else { - vp->LineColorArray.setValues(colors); - } - } - void applyLinkColor(App::DocumentObject* obj, int index, App::Color color) override - { - auto vp = - dynamic_cast(Gui::Application::Instance->getViewProvider(obj)); - if (!vp) { - return; - } - if (index < 0) { - vp->OverrideMaterial.setValue(true); - vp->ShapeMaterial.setDiffuseColor(color); - return; - } - if (vp->OverrideMaterialList.getSize() <= index) { - vp->OverrideMaterialList.setSize(index + 1); - } - vp->OverrideMaterialList.set1Value(index, true); - App::Material mat(App::Material::DEFAULT); - if (vp->MaterialList.getSize() <= index) { - vp->MaterialList.setSize(index + 1, mat); - } - mat.diffuseColor = color; - vp->MaterialList.set1Value(index, mat); - } - void applyElementColors(App::DocumentObject* obj, - const std::map& colors) override - { - auto vp = Gui::Application::Instance->getViewProvider(obj); - if (!vp) { - return; - } - (void)colors; - } -}; - class Module: public Py::ExtensionModule { public: @@ -413,8 +338,8 @@ class Module: public Py::ExtensionModule Handle(XCAFApp_Application) hApp = XCAFApp_Application::GetApplication(); Handle(TDocStd_Document) hDoc; hApp->NewDocument(TCollection_ExtendedString("MDTV-CAF"), hDoc); - ImportOCAFExt ocaf(hDoc, pcDoc, file.fileNamePure()); - ocaf.setImportOptions(ImportOCAFExt::customImportOptions()); + ImportOCAFGui ocaf(hDoc, pcDoc, file.fileNamePure()); + ocaf.setImportOptions(ImportOCAFGui::customImportOptions()); FC_TIME_INIT(t); FC_DURATION_DECL_INIT2(d1, d2); diff --git a/src/Mod/Import/Gui/CMakeLists.txt b/src/Mod/Import/Gui/CMakeLists.txt index 0020c6c61d0b..b0017bf070b1 100644 --- a/src/Mod/Import/Gui/CMakeLists.txt +++ b/src/Mod/Import/Gui/CMakeLists.txt @@ -32,6 +32,8 @@ SET(ImportGui_SRCS Command.cpp ExportOCAFGui.cpp ExportOCAFGui.h + ImportOCAFGui.cpp + ImportOCAFGui.h PreCompiled.cpp PreCompiled.h Workbench.cpp diff --git a/src/Mod/Import/Gui/ImportOCAFGui.cpp b/src/Mod/Import/Gui/ImportOCAFGui.cpp new file mode 100644 index 000000000000..99aa44591942 --- /dev/null +++ b/src/Mod/Import/Gui/ImportOCAFGui.cpp @@ -0,0 +1,108 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later + +/*************************************************************************** + * Copyright (c) 2023 Zheng Lei * + * Copyright (c) 2023 Werner Mayer * + * * + * 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 * + * . * + * * + **************************************************************************/ + + +#include "PreCompiled.h" + +#include "ImportOCAFGui.h" +#include +#include +#include + +using namespace ImportGui; + +ImportOCAFGui::ImportOCAFGui(Handle(TDocStd_Document) hDoc, + App::Document* pDoc, + const std::string& name) + : ImportOCAF2(hDoc, pDoc, name) +{} + +void ImportOCAFGui::applyFaceColors(Part::Feature* part, const std::vector& colors) +{ + auto vp = dynamic_cast( + Gui::Application::Instance->getViewProvider(part)); + if (!vp) { + return; + } + if (colors.empty()) { + return; + } + + if (colors.size() == 1) { + vp->ShapeColor.setValue(colors.front()); + vp->Transparency.setValue(100 * colors.front().a); + } + else { + vp->DiffuseColor.setValues(colors); + } +} + +void ImportOCAFGui::applyEdgeColors(Part::Feature* part, const std::vector& colors) +{ + auto vp = dynamic_cast( + Gui::Application::Instance->getViewProvider(part)); + if (!vp) { + return; + } + if (colors.size() == 1) { + vp->LineColor.setValue(colors.front()); + } + else { + vp->LineColorArray.setValues(colors); + } +} + +void ImportOCAFGui::applyLinkColor(App::DocumentObject* obj, int index, App::Color color) +{ + auto vp = + dynamic_cast(Gui::Application::Instance->getViewProvider(obj)); + if (!vp) { + return; + } + if (index < 0) { + vp->OverrideMaterial.setValue(true); + vp->ShapeMaterial.setDiffuseColor(color); + return; + } + if (vp->OverrideMaterialList.getSize() <= index) { + vp->OverrideMaterialList.setSize(index + 1); + } + vp->OverrideMaterialList.set1Value(index, true); + App::Material mat(App::Material::DEFAULT); + if (vp->MaterialList.getSize() <= index) { + vp->MaterialList.setSize(index + 1, mat); + } + mat.diffuseColor = color; + vp->MaterialList.set1Value(index, mat); +} + +void ImportOCAFGui::applyElementColors(App::DocumentObject* obj, + const std::map& colors) +{ + auto vp = Gui::Application::Instance->getViewProvider(obj); + if (!vp) { + return; + } + (void)colors; +} diff --git a/src/Mod/Import/Gui/ImportOCAFGui.h b/src/Mod/Import/Gui/ImportOCAFGui.h new file mode 100644 index 000000000000..1b5c7d13c1e5 --- /dev/null +++ b/src/Mod/Import/Gui/ImportOCAFGui.h @@ -0,0 +1,48 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later + +/*************************************************************************** + * Copyright (c) 2023 Zheng Lei * + * Copyright (c) 2023 Werner Mayer * + * * + * 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 * + * . * + * * + **************************************************************************/ + +#ifndef IMPORT_IMPORTOCAFGUI_H +#define IMPORT_IMPORTOCAFGUI_H + +#include + +namespace ImportGui +{ + +class ImportOCAFGui: public Import::ImportOCAF2 +{ +public: + ImportOCAFGui(Handle(TDocStd_Document) hDoc, App::Document* pDoc, const std::string& name); + +private: + void applyFaceColors(Part::Feature* part, const std::vector& colors) override; + void applyEdgeColors(Part::Feature* part, const std::vector& colors) override; + void applyLinkColor(App::DocumentObject* obj, int index, App::Color color) override; + void applyElementColors(App::DocumentObject* obj, + const std::map& colors) override; +}; + +} // namespace ImportGui + +#endif // IMPORT_IMPORTOCAFGUI_H