From 05dc17a61a15875b76283825d64cb8b4a96fce75 Mon Sep 17 00:00:00 2001 From: wmayer Date: Sat, 23 Mar 2024 14:00:59 +0100 Subject: [PATCH] Gui: Apply clang-format on DlgProjectionOnSurface and fix linter warnings --- src/Mod/Part/Gui/DlgProjectionOnSurface.cpp | 1789 ++++++++++--------- src/Mod/Part/Gui/DlgProjectionOnSurface.h | 149 +- 2 files changed, 996 insertions(+), 942 deletions(-) diff --git a/src/Mod/Part/Gui/DlgProjectionOnSurface.cpp b/src/Mod/Part/Gui/DlgProjectionOnSurface.cpp index c45a9841e4..1baf8ccb54 100644 --- a/src/Mod/Part/Gui/DlgProjectionOnSurface.cpp +++ b/src/Mod/Part/Gui/DlgProjectionOnSurface.cpp @@ -22,25 +22,25 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #endif #include @@ -60,81 +60,79 @@ using namespace PartGui; ////////////////////////////////////////////////////////////////////////// -class DlgProjectionOnSurface::EdgeSelection : public Gui::SelectionFilterGate +class DlgProjectionOnSurface::EdgeSelection: public Gui::SelectionFilterGate { public: - bool canSelect; + bool canSelect = false; - EdgeSelection() - : Gui::SelectionFilterGate(nullPointer()) - { - canSelect = false; - } - ~EdgeSelection() override = default; + EdgeSelection() + : Gui::SelectionFilterGate(nullPointer()) + {} - bool allow(App::Document* /*pDoc*/, App::DocumentObject* iPObj, const char* sSubName) override - { - Part::Feature* aPart = dynamic_cast(iPObj); - if (!aPart) - return false; - if (!sSubName) - return false; - std::string subName(sSubName); - if (subName.empty()) - return false; + bool allow(App::Document* /*pDoc*/, App::DocumentObject* iPObj, const char* sSubName) override + { + auto aPart = dynamic_cast(iPObj); + if (!aPart) { + return false; + } + if (!sSubName) { + return false; + } + std::string subName(sSubName); + if (subName.empty()) { + return false; + } - auto subShape = aPart->Shape.getShape().getSubShape(sSubName); - if (subShape.IsNull()) - return false; - auto type = subShape.ShapeType(); - if (type != TopAbs_EDGE) - return false; - return true; - } + auto subShape = aPart->Shape.getShape().getSubShape(sSubName); + if (subShape.IsNull()) { + return false; + } + auto type = subShape.ShapeType(); + return (type == TopAbs_EDGE); + } }; ////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// -class DlgProjectionOnSurface::FaceSelection : public Gui::SelectionFilterGate +class DlgProjectionOnSurface::FaceSelection: public Gui::SelectionFilterGate { public: - bool canSelect; + bool canSelect = false; - FaceSelection() - : Gui::SelectionFilterGate(nullPointer()) - { - canSelect = false; - } - ~FaceSelection() override = default; + FaceSelection() + : Gui::SelectionFilterGate(nullPointer()) + {} - bool allow(App::Document* /*pDoc*/, App::DocumentObject* iPObj, const char* sSubName) override - { - Part::Feature* aPart = dynamic_cast(iPObj); - if (!aPart) - return false; - if (!sSubName) - return false; - std::string subName(sSubName); - if (subName.empty()) - return false; + bool allow(App::Document* /*pDoc*/, App::DocumentObject* iPObj, const char* sSubName) override + { + auto aPart = dynamic_cast(iPObj); + if (!aPart) { + return false; + } + if (!sSubName) { + return false; + } + std::string subName(sSubName); + if (subName.empty()) { + return false; + } - auto subShape = aPart->Shape.getShape().getSubShape(sSubName, true); - if (subShape.IsNull()) - return false; - auto type = subShape.ShapeType(); - if (type != TopAbs_FACE) - return false; - return true; - } + auto subShape = aPart->Shape.getShape().getSubShape(sSubName, true); + if (subShape.IsNull()) { + return false; + } + auto type = subShape.ShapeType(); + return (type == TopAbs_FACE); + } }; ////////////////////////////////////////////////////////////////////////// -DlgProjectionOnSurface::DlgProjectionOnSurface(QWidget *parent) - : QWidget(parent) - , ui(new Ui::DlgProjectionOnSurface) - , m_projectionObjectName(tr("Projection Object")) - , filterEdge(nullptr) - , filterFace(nullptr) +DlgProjectionOnSurface::DlgProjectionOnSurface(QWidget* parent) + : QWidget(parent) + , ui(new Ui::DlgProjectionOnSurface) + , m_projectionObjectName(tr("Projection Object")) + , filterEdge(nullptr) + , filterFace(nullptr) { ui->setupUi(this); setupConnections(); @@ -160,16 +158,15 @@ DlgProjectionOnSurface::DlgProjectionOnSurface(QWidget *parent) disable_ui_elements(m_guiObjectVec, ui->pushButtonAddProjFace); m_partDocument = App::GetApplication().getActiveDocument(); - if (!m_partDocument) - { - throw Base::ValueError(QString(tr("Have no active document!!!")).toUtf8()); + if (!m_partDocument) { + throw Base::ValueError(QString(tr("Have no active document!!!")).toUtf8()); } this->attachDocument(m_partDocument); m_partDocument->openTransaction("Project on surface"); - m_projectionObject = dynamic_cast(m_partDocument->addObject("Part::Feature", "Projection Object")); - if (!m_projectionObject) - { - throw Base::ValueError(QString(tr("Can not create a projection object!!!")).toUtf8()); + m_projectionObject = dynamic_cast( + m_partDocument->addObject("Part::Feature", "Projection Object")); + if (!m_projectionObject) { + throw Base::ValueError(QString(tr("Can not create a projection object!!!")).toUtf8()); } m_projectionObject->Label.setValue(std::string(m_projectionObjectName.toUtf8()).c_str()); onRadioButtonShowAllClicked(); @@ -178,965 +175,1013 @@ DlgProjectionOnSurface::DlgProjectionOnSurface(QWidget *parent) DlgProjectionOnSurface::~DlgProjectionOnSurface() { - delete ui; - for (const auto& it : m_projectionSurfaceVec) - { - try { - higlight_object(it.partFeature, it.partName, false, 0); + delete ui; + for (const auto& it : m_projectionSurfaceVec) { + try { + higlight_object(it.partFeature, it.partName, false, 0); + } + catch (Standard_NoSuchObject& e) { + Base::Console().Warning("DlgProjectionOnSurface::~DlgProjectionOnSurface: %s", + e.GetMessageString()); + } + auto vp = dynamic_cast( + Gui::Application::Instance->getViewProvider(it.partFeature)); + if (vp) { + vp->Selectable.setValue(it.is_selectable); + vp->Transparency.setValue(it.transparency); + } } - catch (Standard_NoSuchObject& e) { - Base::Console().Warning("DlgProjectionOnSurface::~DlgProjectionOnSurface: %s", e.GetMessageString()); + for (const auto& it : m_shapeVec) { + try { + higlight_object(it.partFeature, it.partName, false, 0); + } + catch (Standard_NoSuchObject& e) { + Base::Console().Warning("DlgProjectionOnSurface::~DlgProjectionOnSurface: %s", + e.GetMessageString()); + } } - PartGui::ViewProviderPartExt* vp = dynamic_cast(Gui::Application::Instance->getViewProvider(it.partFeature)); - if (vp) - { - vp->Selectable.setValue(it.is_selectable); - vp->Transparency.setValue(it.transparency); - } - } - for (const auto& it : m_shapeVec) - { - try { - higlight_object(it.partFeature, it.partName, false, 0); - } - catch (Standard_NoSuchObject& e) { - Base::Console().Warning("DlgProjectionOnSurface::~DlgProjectionOnSurface: %s", e.GetMessageString()); - } - } - Gui::Selection().rmvSelectionGate(); + Gui::Selection().rmvSelectionGate(); } void PartGui::DlgProjectionOnSurface::setupConnections() { - connect(ui->pushButtonAddFace, &QPushButton::clicked, - this, &DlgProjectionOnSurface::onPushButtonAddFaceClicked); - connect(ui->pushButtonAddEdge, &QPushButton::clicked, - this, &DlgProjectionOnSurface::onPushButtonAddEdgeClicked); - connect(ui->pushButtonGetCurrentCamDir, &QPushButton::clicked, - this, &DlgProjectionOnSurface::onPushButtonGetCurrentCamDirClicked); - connect(ui->pushButtonDirX, &QPushButton::clicked, - this, &DlgProjectionOnSurface::onPushButtonDirXClicked); - connect(ui->pushButtonDirY, &QPushButton::clicked, - this, &DlgProjectionOnSurface::onPushButtonDirYClicked); - connect(ui->pushButtonDirZ, &QPushButton::clicked, - this, &DlgProjectionOnSurface::onPushButtonDirZClicked); - connect(ui->pushButtonAddProjFace, &QPushButton::clicked, - this, &DlgProjectionOnSurface::onPushButtonAddProjFaceClicked); - connect(ui->radioButtonShowAll, &QRadioButton::clicked, - this, &DlgProjectionOnSurface::onRadioButtonShowAllClicked); - connect(ui->radioButtonFaces, &QRadioButton::clicked, - this, &DlgProjectionOnSurface::onRadioButtonFacesClicked); - connect(ui->radioButtonEdges, &QRadioButton::clicked, - this, &DlgProjectionOnSurface::onRadioButtonEdgesClicked); - connect(ui->doubleSpinBoxExtrudeHeight, qOverload(&QDoubleSpinBox::valueChanged), - this, &DlgProjectionOnSurface::onDoubleSpinBoxExtrudeHeightValueChanged); - connect(ui->pushButtonAddWire, &QPushButton::clicked, - this, &DlgProjectionOnSurface::onPushButtonAddWireClicked); - connect(ui->doubleSpinBoxSolidDepth, qOverload(&QDoubleSpinBox::valueChanged), - this, &DlgProjectionOnSurface::onDoubleSpinBoxSolidDepthValueChanged); + connect(ui->pushButtonAddFace, + &QPushButton::clicked, + this, + &DlgProjectionOnSurface::onPushButtonAddFaceClicked); + connect(ui->pushButtonAddEdge, + &QPushButton::clicked, + this, + &DlgProjectionOnSurface::onPushButtonAddEdgeClicked); + connect(ui->pushButtonGetCurrentCamDir, + &QPushButton::clicked, + this, + &DlgProjectionOnSurface::onPushButtonGetCurrentCamDirClicked); + connect(ui->pushButtonDirX, + &QPushButton::clicked, + this, + &DlgProjectionOnSurface::onPushButtonDirXClicked); + connect(ui->pushButtonDirY, + &QPushButton::clicked, + this, + &DlgProjectionOnSurface::onPushButtonDirYClicked); + connect(ui->pushButtonDirZ, + &QPushButton::clicked, + this, + &DlgProjectionOnSurface::onPushButtonDirZClicked); + connect(ui->pushButtonAddProjFace, + &QPushButton::clicked, + this, + &DlgProjectionOnSurface::onPushButtonAddProjFaceClicked); + connect(ui->radioButtonShowAll, + &QRadioButton::clicked, + this, + &DlgProjectionOnSurface::onRadioButtonShowAllClicked); + connect(ui->radioButtonFaces, + &QRadioButton::clicked, + this, + &DlgProjectionOnSurface::onRadioButtonFacesClicked); + connect(ui->radioButtonEdges, + &QRadioButton::clicked, + this, + &DlgProjectionOnSurface::onRadioButtonEdgesClicked); + connect(ui->doubleSpinBoxExtrudeHeight, + qOverload(&QDoubleSpinBox::valueChanged), + this, + &DlgProjectionOnSurface::onDoubleSpinBoxExtrudeHeightValueChanged); + connect(ui->pushButtonAddWire, + &QPushButton::clicked, + this, + &DlgProjectionOnSurface::onPushButtonAddWireClicked); + connect(ui->doubleSpinBoxSolidDepth, + qOverload(&QDoubleSpinBox::valueChanged), + this, + &DlgProjectionOnSurface::onDoubleSpinBoxSolidDepthValueChanged); } void PartGui::DlgProjectionOnSurface::slotDeletedDocument(const App::Document& Doc) { - if (m_partDocument == &Doc) { - m_partDocument = nullptr; - m_projectionObject = nullptr; - } + if (m_partDocument == &Doc) { + m_partDocument = nullptr; + m_projectionObject = nullptr; + } } void PartGui::DlgProjectionOnSurface::slotDeletedObject(const App::DocumentObject& Obj) { - if (m_projectionObject == &Obj) { - m_projectionObject = nullptr; - } + if (m_projectionObject == &Obj) { + m_projectionObject = nullptr; + } } void PartGui::DlgProjectionOnSurface::apply() { - if (m_partDocument) - m_partDocument->commitTransaction(); + if (m_partDocument) { + m_partDocument->commitTransaction(); + } } void PartGui::DlgProjectionOnSurface::reject() { - if (m_partDocument) - m_partDocument->abortTransaction(); + if (m_partDocument) { + m_partDocument->abortTransaction(); + } } void PartGui::DlgProjectionOnSurface::onPushButtonAddFaceClicked() { - if ( ui->pushButtonAddFace->isChecked() ) - { - m_currentSelection = "add_face"; - disable_ui_elements(m_guiObjectVec, ui->pushButtonAddFace); - if (!filterFace) - { - filterFace = new FaceSelection(); - Gui::Selection().addSelectionGate(filterFace); + if (ui->pushButtonAddFace->isChecked()) { + m_currentSelection = "add_face"; + disable_ui_elements(m_guiObjectVec, ui->pushButtonAddFace); + if (!filterFace) { + filterFace = new FaceSelection(); + Gui::Selection().addSelectionGate(filterFace); + } + } + else { + m_currentSelection = ""; + enable_ui_elements(m_guiObjectVec, nullptr); + Gui::Selection().rmvSelectionGate(); + filterFace = nullptr; } - } - else - { - m_currentSelection = ""; - enable_ui_elements(m_guiObjectVec, nullptr); - Gui::Selection().rmvSelectionGate(); - filterFace = nullptr; - } } void PartGui::DlgProjectionOnSurface::onPushButtonAddEdgeClicked() { - if (ui->pushButtonAddEdge->isChecked()) - { - m_currentSelection = "add_edge"; - disable_ui_elements(m_guiObjectVec, ui->pushButtonAddEdge); - if (!filterEdge) - { - filterEdge = new EdgeSelection(); - Gui::Selection().addSelectionGate(filterEdge); + if (ui->pushButtonAddEdge->isChecked()) { + m_currentSelection = "add_edge"; + disable_ui_elements(m_guiObjectVec, ui->pushButtonAddEdge); + if (!filterEdge) { + filterEdge = new EdgeSelection(); + Gui::Selection().addSelectionGate(filterEdge); + } + ui->radioButtonEdges->setChecked(true); + onRadioButtonEdgesClicked(); + } + else { + m_currentSelection = ""; + enable_ui_elements(m_guiObjectVec, nullptr); + Gui::Selection().rmvSelectionGate(); + filterEdge = nullptr; } - ui->radioButtonEdges->setChecked(true); - onRadioButtonEdgesClicked(); - } - else - { - m_currentSelection = ""; - enable_ui_elements(m_guiObjectVec, nullptr); - Gui::Selection().rmvSelectionGate(); - filterEdge = nullptr; - } } void PartGui::DlgProjectionOnSurface::onPushButtonGetCurrentCamDirClicked() { - get_camera_direction(); + get_camera_direction(); } void PartGui::DlgProjectionOnSurface::onPushButtonDirXClicked() { - set_xyz_dir_spinbox(ui->doubleSpinBoxDirX); + set_xyz_dir_spinbox(ui->doubleSpinBoxDirX); } void PartGui::DlgProjectionOnSurface::onPushButtonDirYClicked() { - set_xyz_dir_spinbox(ui->doubleSpinBoxDirY); + set_xyz_dir_spinbox(ui->doubleSpinBoxDirY); } void PartGui::DlgProjectionOnSurface::onPushButtonDirZClicked() { - set_xyz_dir_spinbox(ui->doubleSpinBoxDirZ); + set_xyz_dir_spinbox(ui->doubleSpinBoxDirZ); } void PartGui::DlgProjectionOnSurface::onSelectionChanged(const Gui::SelectionChanges& msg) { - if (msg.Type == Gui::SelectionChanges::AddSelection) - { - if ( m_currentSelection == "add_face" || m_currentSelection == "add_edge" || m_currentSelection == "add_wire") - { - store_current_selected_parts(m_shapeVec, 0xff00ff00); - create_projection_wire(m_shapeVec); - create_projection_face_from_wire(m_shapeVec); - create_face_extrude(m_shapeVec); - show_projected_shapes(m_shapeVec); - } - else if (m_currentSelection == "add_projection_surface") - { - m_projectionSurfaceVec.clear(); - store_current_selected_parts(m_projectionSurfaceVec, 0xffff0000); - if (!m_projectionSurfaceVec.empty()) - { - PartGui::ViewProviderPartExt* vp = dynamic_cast(Gui::Application::Instance->getViewProvider(m_projectionSurfaceVec.back().partFeature)); - if (vp) - { - vp->Selectable.setValue(false); - vp->Transparency.setValue(90); + if (msg.Type == Gui::SelectionChanges::AddSelection) { + if (m_currentSelection == "add_face" || m_currentSelection == "add_edge" + || m_currentSelection == "add_wire") { + store_current_selected_parts(m_shapeVec, 0xff00ff00); + create_projection_wire(m_shapeVec); + create_projection_face_from_wire(m_shapeVec); + create_face_extrude(m_shapeVec); + show_projected_shapes(m_shapeVec); } - } + else if (m_currentSelection == "add_projection_surface") { + m_projectionSurfaceVec.clear(); + store_current_selected_parts(m_projectionSurfaceVec, 0xffff0000); + if (!m_projectionSurfaceVec.empty()) { + auto vp = dynamic_cast( + Gui::Application::Instance->getViewProvider( + m_projectionSurfaceVec.back().partFeature)); + if (vp) { + vp->Selectable.setValue(false); + vp->Transparency.setValue(90); + } + } - ui->pushButtonAddProjFace->setChecked(false); - onPushButtonAddProjFaceClicked(); + ui->pushButtonAddProjFace->setChecked(false); + onPushButtonAddProjFaceClicked(); + } } - } } void PartGui::DlgProjectionOnSurface::get_camera_direction() { - auto mainWindow = Gui::getMainWindow(); + auto mainWindow = Gui::getMainWindow(); - auto mdiObject = dynamic_cast(mainWindow->activeWindow()); - if (!mdiObject) - return; - auto camerRotation = mdiObject->getViewer()->getCameraOrientation(); - - SbVec3f lookAt(0, 0, -1); - camerRotation.multVec(lookAt, lookAt); - - float valX, valY, valZ; - lookAt.getValue(valX, valY, valZ); - - ui->doubleSpinBoxDirX->setValue(valX); - ui->doubleSpinBoxDirY->setValue(valY); - ui->doubleSpinBoxDirZ->setValue(valZ); -} - -void PartGui::DlgProjectionOnSurface::store_current_selected_parts(std::vector& iStoreVec, const unsigned int iColor) -{ - if (!m_partDocument) - return; - std::vector selObj = Gui::Selection().getSelectionEx(); - if (!selObj.empty()) - { - for (auto it = selObj.begin(); it != selObj.end(); ++it) - { - auto aPart = dynamic_cast(it->getObject()); - if (!aPart) continue; - - if (aPart) - { - SShapeStore currentShapeStore; - currentShapeStore.inputShape = aPart->Shape.getShape().getShape(); - currentShapeStore.partFeature = aPart; - currentShapeStore.partName = aPart->getNameInDocument(); - - PartGui::ViewProviderPartExt* vp = dynamic_cast(Gui::Application::Instance->getViewProvider(aPart)); - if (vp) - { - currentShapeStore.is_selectable = vp->Selectable.getValue(); - currentShapeStore.transparency = vp->Transparency.getValue(); - } - if (!it->getSubNames().empty() ) - { - auto parentShape = currentShapeStore.inputShape; - for (const auto & itName : selObj.front().getSubNames()) - { - auto currentShape = aPart->Shape.getShape().getSubShape(itName.c_str()); - - transform_shape_to_global_position(currentShape, aPart); - - currentShapeStore.inputShape = currentShape; - currentShapeStore.partName = itName; - auto store = store_part_in_vector(currentShapeStore, iStoreVec); - higlight_object(aPart, itName, store, iColor); - store_wire_in_vector(currentShapeStore, parentShape, iStoreVec, iColor); - } - } - else - { - transform_shape_to_global_position(currentShapeStore.inputShape,currentShapeStore.partFeature); - auto store = store_part_in_vector(currentShapeStore, iStoreVec); - higlight_object(aPart, aPart->Shape.getName(), store, iColor); - } - Gui::Selection().clearSelection(m_partDocument->getName()); - Gui::Selection().rmvPreselect(); - } - } - } -} - -bool PartGui::DlgProjectionOnSurface::store_part_in_vector(SShapeStore& iCurrentShape, std::vector& iStoreVec) -{ - if (iCurrentShape.inputShape.IsNull()) - return false; - auto currentType = iCurrentShape.inputShape.ShapeType(); - for ( auto it = iStoreVec.begin(); it != iStoreVec.end(); ++it) - { - if ( currentType == TopAbs_FACE ) - { - if (it->aFace.IsSame(iCurrentShape.inputShape)) - { - iStoreVec.erase(it); - return false; - } - } - else if ( currentType == TopAbs_EDGE ) - { - if (it->aEdge.IsSame(iCurrentShape.inputShape)) - { - iStoreVec.erase(it); - return false; - } - } - } - - if (currentType == TopAbs_FACE) - { - iCurrentShape.aFace = TopoDS::Face(iCurrentShape.inputShape); - } - else if (currentType == TopAbs_EDGE) - { - iCurrentShape.aEdge = TopoDS::Edge(iCurrentShape.inputShape); - } - - auto valX = ui->doubleSpinBoxDirX->value(); - auto valY = ui->doubleSpinBoxDirY->value(); - auto valZ = ui->doubleSpinBoxDirZ->value(); - - iCurrentShape.aProjectionDir = gp_Dir(valX, valY, valZ); - if ( !m_projectionSurfaceVec.empty() ) - { - iCurrentShape.surfaceToProject = m_projectionSurfaceVec.front().aFace; - } - iStoreVec.push_back(iCurrentShape); - return true; -} - -void PartGui::DlgProjectionOnSurface::create_projection_wire(std::vector& iCurrentShape) -{ - try - { - if (iCurrentShape.empty()) + auto mdiObject = dynamic_cast(mainWindow->activeWindow()); + if (!mdiObject) { return; - for ( auto &itCurrentShape : iCurrentShape ) - { - if (m_projectionSurfaceVec.empty()) continue;; - if (!itCurrentShape.aProjectedEdgeVec.empty()) continue;; - if (!itCurrentShape.aProjectedFace.IsNull()) continue;; - if (!itCurrentShape.aProjectedWireVec.empty()) continue;; - - if (!itCurrentShape.aFace.IsNull()) - { - get_all_wire_from_face(itCurrentShape); - for (const auto& itWire : itCurrentShape.aWireVec) - { - BRepProj_Projection aProjection(itWire, itCurrentShape.surfaceToProject, itCurrentShape.aProjectionDir); - double minDistance = std::numeric_limits::max(); - TopoDS_Wire wireToTake; - for ( ; aProjection.More(); aProjection.Next() ) - { - auto it = aProjection.Current(); - BRepExtrema_DistShapeShape distanceMeasure(it, itCurrentShape.aFace); - distanceMeasure.Perform(); - auto currentDistance = distanceMeasure.Value(); - if ( currentDistance > minDistance ) continue; - wireToTake = it; - minDistance = currentDistance; - } - auto aWire = sort_and_heal_wire(wireToTake, itCurrentShape.surfaceToProject); - itCurrentShape.aProjectedWireVec.push_back(aWire); - } - } - else if (!itCurrentShape.aEdge.IsNull()) - { - BRepProj_Projection aProjection(itCurrentShape.aEdge, itCurrentShape.surfaceToProject, itCurrentShape.aProjectionDir); - double minDistance = std::numeric_limits::max(); - TopoDS_Wire wireToTake; - for (; aProjection.More(); aProjection.Next()) - { - auto it = aProjection.Current(); - BRepExtrema_DistShapeShape distanceMeasure(it, itCurrentShape.aEdge); - distanceMeasure.Perform(); - auto currentDistance = distanceMeasure.Value(); - if (currentDistance > minDistance) continue; - wireToTake = it; - minDistance = currentDistance; - } - for (TopExp_Explorer aExplorer(wireToTake, TopAbs_EDGE); aExplorer.More(); aExplorer.Next()) - { - itCurrentShape.aProjectedEdgeVec.push_back(TopoDS::Edge(aExplorer.Current())); - } - } - } - } - catch (const Standard_Failure& error) - { - std::stringstream ssOcc; - error.Print(ssOcc); - throw Base::ValueError(ssOcc.str().c_str()); - } + auto camerRotation = mdiObject->getViewer()->getCameraOrientation(); + + SbVec3f lookAt(0, 0, -1); + camerRotation.multVec(lookAt, lookAt); + + float valX {}; + float valY {}; + float valZ {}; + lookAt.getValue(valX, valY, valZ); + + ui->doubleSpinBoxDirX->setValue(valX); + ui->doubleSpinBoxDirY->setValue(valY); + ui->doubleSpinBoxDirZ->setValue(valZ); } -TopoDS_Shape PartGui::DlgProjectionOnSurface::create_compound(const std::vector& iShapeVec) +void PartGui::DlgProjectionOnSurface::store_current_selected_parts( + std::vector& iStoreVec, + unsigned int iColor) { - if (iShapeVec.empty()) - return {}; - - TopoDS_Compound aCompound; - TopoDS_Builder aBuilder; - aBuilder.MakeCompound(aCompound); - - for (const auto& it : iShapeVec) - { - if ( m_currentShowType == "edges" ) - { - for (const auto& it2 : it.aProjectedEdgeVec) - { - aBuilder.Add(aCompound, it2); - } - for (const auto& it2 : it.aProjectedWireVec) - { - aBuilder.Add(aCompound, it2); - } - continue; - } - else if ( m_currentShowType == "faces" ) - { - if (it.aProjectedFace.IsNull()) - { - for (const auto& it2 : it.aProjectedWireVec) - { - if (!it2.IsNull()) - { - aBuilder.Add(aCompound, it2); - } - } - } - else aBuilder.Add(aCompound, it.aProjectedFace); - continue; - } - else if ( m_currentShowType == "all" ) - { - if (!it.aProjectedSolid.IsNull()) - { - aBuilder.Add(aCompound, it.aProjectedSolid); - } - else if ( !it.aProjectedFace.IsNull() ) - { - aBuilder.Add(aCompound, it.aProjectedFace); - } - else if (!it.aProjectedWireVec.empty()) - { - for (const auto& itWire : it.aProjectedWireVec ) - { - if ( itWire.IsNull() ) continue; - aBuilder.Add(aCompound, itWire); - } - } - else if (!it.aProjectedEdgeVec.empty()) - { - for (const auto& itEdge : it.aProjectedEdgeVec) - { - if (itEdge.IsNull()) continue; - aBuilder.Add(aCompound, itEdge); - } - } - } - } - return TopoDS_Shape(std::move(aCompound)); -} - -void PartGui::DlgProjectionOnSurface::show_projected_shapes(const std::vector& iShapeStoreVec) -{ - if (!m_projectionObject) - return; - auto aCompound = create_compound(iShapeStoreVec); - if ( aCompound.IsNull() ) - { - if (!m_partDocument) + if (!m_partDocument) { return; - m_projectionObject->Shape.setValue(TopoDS_Shape()); - return; - } - auto currentPlacement = m_projectionObject->Placement.getValue(); - m_projectionObject->Shape.setValue(aCompound); - m_projectionObject->Placement.setValue(currentPlacement); + } + std::vector selObj = Gui::Selection().getSelectionEx(); + if (!selObj.empty()) { + for (auto it = selObj.begin(); it != selObj.end(); ++it) { + auto aPart = dynamic_cast(it->getObject()); + if (!aPart) { + continue; + } - //set color - PartGui::ViewProviderPartExt* vp = dynamic_cast(Gui::Application::Instance->getViewProvider(m_projectionObject)); - if (vp) - { - vp->LineColor.setValue(0x8ae23400); - vp->ShapeColor.setValue(0x8ae23400); - vp->PointColor.setValue(0x8ae23400); - vp->Transparency.setValue(0); - } + if (aPart) { + SShapeStore currentShapeStore; + currentShapeStore.inputShape = aPart->Shape.getShape().getShape(); + currentShapeStore.partFeature = aPart; + currentShapeStore.partName = aPart->getNameInDocument(); + + auto vp = dynamic_cast( + Gui::Application::Instance->getViewProvider(aPart)); + if (vp) { + currentShapeStore.is_selectable = vp->Selectable.getValue(); + currentShapeStore.transparency = vp->Transparency.getValue(); + } + if (!it->getSubNames().empty()) { + auto parentShape = currentShapeStore.inputShape; + for (const auto& itName : selObj.front().getSubNames()) { + auto currentShape = aPart->Shape.getShape().getSubShape(itName.c_str()); + + transform_shape_to_global_position(currentShape, aPart); + + currentShapeStore.inputShape = currentShape; + currentShapeStore.partName = itName; + auto store = store_part_in_vector(currentShapeStore, iStoreVec); + higlight_object(aPart, itName, store, iColor); + store_wire_in_vector(currentShapeStore, parentShape, iStoreVec, iColor); + } + } + else { + transform_shape_to_global_position(currentShapeStore.inputShape, + currentShapeStore.partFeature); + auto store = store_part_in_vector(currentShapeStore, iStoreVec); + higlight_object(aPart, aPart->Shape.getName(), store, iColor); + } + Gui::Selection().clearSelection(m_partDocument->getName()); + Gui::Selection().rmvPreselect(); + } + } + } } -void PartGui::DlgProjectionOnSurface::disable_ui_elements(const std::vector& iObjectVec, QWidget* iExceptThis) +bool PartGui::DlgProjectionOnSurface::store_part_in_vector(SShapeStore& iCurrentShape, + std::vector& iStoreVec) { - for ( auto it : iObjectVec ) - { - if ( !it ) continue; - if ( it == iExceptThis ) continue; - it->setDisabled(true); - } + if (iCurrentShape.inputShape.IsNull()) { + return false; + } + auto currentType = iCurrentShape.inputShape.ShapeType(); + for (auto it = iStoreVec.begin(); it != iStoreVec.end(); ++it) { + if (currentType == TopAbs_FACE) { + if (it->aFace.IsSame(iCurrentShape.inputShape)) { + iStoreVec.erase(it); + return false; + } + } + else if (currentType == TopAbs_EDGE) { + if (it->aEdge.IsSame(iCurrentShape.inputShape)) { + iStoreVec.erase(it); + return false; + } + } + } + + if (currentType == TopAbs_FACE) { + iCurrentShape.aFace = TopoDS::Face(iCurrentShape.inputShape); + } + else if (currentType == TopAbs_EDGE) { + iCurrentShape.aEdge = TopoDS::Edge(iCurrentShape.inputShape); + } + + auto valX = ui->doubleSpinBoxDirX->value(); + auto valY = ui->doubleSpinBoxDirY->value(); + auto valZ = ui->doubleSpinBoxDirZ->value(); + + iCurrentShape.aProjectionDir = gp_Dir(valX, valY, valZ); + if (!m_projectionSurfaceVec.empty()) { + iCurrentShape.surfaceToProject = m_projectionSurfaceVec.front().aFace; + } + iStoreVec.push_back(iCurrentShape); + return true; } -void PartGui::DlgProjectionOnSurface::enable_ui_elements(const std::vector& iObjectVec, QWidget* iExceptThis) +void PartGui::DlgProjectionOnSurface::create_projection_wire( + std::vector& iCurrentShape) { - for (auto it : iObjectVec) - { - if (!it) continue; - if (it == iExceptThis) continue; - it->setEnabled(true); - } + try { + if (iCurrentShape.empty()) { + return; + } + for (auto& itCurrentShape : iCurrentShape) { + if (m_projectionSurfaceVec.empty()) { + continue; + }; + if (!itCurrentShape.aProjectedEdgeVec.empty()) { + continue; + }; + if (!itCurrentShape.aProjectedFace.IsNull()) { + continue; + }; + if (!itCurrentShape.aProjectedWireVec.empty()) { + continue; + }; + + if (!itCurrentShape.aFace.IsNull()) { + get_all_wire_from_face(itCurrentShape); + for (const auto& itWire : itCurrentShape.aWireVec) { + BRepProj_Projection aProjection(itWire, + itCurrentShape.surfaceToProject, + itCurrentShape.aProjectionDir); + double minDistance = std::numeric_limits::max(); + TopoDS_Wire wireToTake; + for (; aProjection.More(); aProjection.Next()) { + auto it = aProjection.Current(); + BRepExtrema_DistShapeShape distanceMeasure(it, itCurrentShape.aFace); + distanceMeasure.Perform(); + auto currentDistance = distanceMeasure.Value(); + if (currentDistance > minDistance) { + continue; + } + wireToTake = it; + minDistance = currentDistance; + } + auto aWire = sort_and_heal_wire(wireToTake, itCurrentShape.surfaceToProject); + itCurrentShape.aProjectedWireVec.push_back(aWire); + } + } + else if (!itCurrentShape.aEdge.IsNull()) { + BRepProj_Projection aProjection(itCurrentShape.aEdge, + itCurrentShape.surfaceToProject, + itCurrentShape.aProjectionDir); + double minDistance = std::numeric_limits::max(); + TopoDS_Wire wireToTake; + for (; aProjection.More(); aProjection.Next()) { + auto it = aProjection.Current(); + BRepExtrema_DistShapeShape distanceMeasure(it, itCurrentShape.aEdge); + distanceMeasure.Perform(); + auto currentDistance = distanceMeasure.Value(); + if (currentDistance > minDistance) { + continue; + } + wireToTake = it; + minDistance = currentDistance; + } + for (TopExp_Explorer aExplorer(wireToTake, TopAbs_EDGE); aExplorer.More(); + aExplorer.Next()) { + itCurrentShape.aProjectedEdgeVec.push_back(TopoDS::Edge(aExplorer.Current())); + } + } + } + } + catch (const Standard_Failure& error) { + std::stringstream ssOcc; + error.Print(ssOcc); + throw Base::ValueError(ssOcc.str().c_str()); + } } -void PartGui::DlgProjectionOnSurface::higlight_object(Part::Feature* iCurrentObject, const std::string& iShapeName, bool iHighlight, const unsigned int iColor) +TopoDS_Shape +PartGui::DlgProjectionOnSurface::create_compound(const std::vector& iShapeVec) { - if (!iCurrentObject) - return; - auto partenShape = iCurrentObject->Shape.getShape().getShape(); - auto subShape = iCurrentObject->Shape.getShape().getSubShape(iShapeName.c_str(), true); - - TopoDS_Shape currentShape = subShape; - if (subShape.IsNull()) currentShape = partenShape; - - auto currentShapeType = currentShape.ShapeType(); - TopTools_IndexedMapOfShape anIndices; - TopExp::MapShapes(partenShape, currentShapeType, anIndices); - if (anIndices.IsEmpty()) - return; - if (!anIndices.Contains(currentShape)) - return; - auto index = anIndices.FindIndex(currentShape); - - //set color - PartGui::ViewProviderPartExt* vp = dynamic_cast(Gui::Application::Instance->getViewProvider(iCurrentObject)); - if (vp) - { - std::vector colors; - App::Color defaultColor; - if (currentShapeType == TopAbs_FACE) - { - colors = vp->DiffuseColor.getValues(); - defaultColor = vp->ShapeColor.getValue(); - } - else if ( currentShapeType == TopAbs_EDGE ) - { - colors = vp->LineColorArray.getValues(); - defaultColor = vp->LineColor.getValue(); + if (iShapeVec.empty()) { + return {}; } - if ( static_cast(colors.size()) != anIndices.Extent() ) - { - colors.resize(anIndices.Extent(), defaultColor); + TopoDS_Compound aCompound; + TopoDS_Builder aBuilder; + aBuilder.MakeCompound(aCompound); + + for (const auto& it : iShapeVec) { + if (m_currentShowType == "edges") { + for (const auto& it2 : it.aProjectedEdgeVec) { + aBuilder.Add(aCompound, it2); + } + for (const auto& it2 : it.aProjectedWireVec) { + aBuilder.Add(aCompound, it2); + } + } + else if (m_currentShowType == "faces") { + if (it.aProjectedFace.IsNull()) { + for (const auto& it2 : it.aProjectedWireVec) { + if (!it2.IsNull()) { + aBuilder.Add(aCompound, it2); + } + } + } + else { + aBuilder.Add(aCompound, it.aProjectedFace); + } + } + else if (m_currentShowType == "all") { + if (!it.aProjectedSolid.IsNull()) { + aBuilder.Add(aCompound, it.aProjectedSolid); + } + else if (!it.aProjectedFace.IsNull()) { + aBuilder.Add(aCompound, it.aProjectedFace); + } + else if (!it.aProjectedWireVec.empty()) { + for (const auto& itWire : it.aProjectedWireVec) { + if (itWire.IsNull()) { + continue; + } + aBuilder.Add(aCompound, itWire); + } + } + else if (!it.aProjectedEdgeVec.empty()) { + for (const auto& itEdge : it.aProjectedEdgeVec) { + if (itEdge.IsNull()) { + continue; + } + aBuilder.Add(aCompound, itEdge); + } + } + } + } + return {std::move(aCompound)}; +} + +void PartGui::DlgProjectionOnSurface::show_projected_shapes( + const std::vector& iShapeStoreVec) +{ + if (!m_projectionObject) { + return; + } + auto aCompound = create_compound(iShapeStoreVec); + if (aCompound.IsNull()) { + if (!m_partDocument) { + return; + } + m_projectionObject->Shape.setValue(TopoDS_Shape()); + return; + } + auto currentPlacement = m_projectionObject->Placement.getValue(); + m_projectionObject->Shape.setValue(aCompound); + m_projectionObject->Placement.setValue(currentPlacement); + + // set color + auto vp = dynamic_cast( + Gui::Application::Instance->getViewProvider(m_projectionObject)); + if (vp) { + const unsigned int color = 0x8ae23400; + vp->LineColor.setValue(color); + vp->ShapeColor.setValue(color); + vp->PointColor.setValue(color); + vp->Transparency.setValue(0); + } +} + +void PartGui::DlgProjectionOnSurface::disable_ui_elements(const std::vector& iObjectVec, + QWidget* iExceptThis) +{ + for (auto it : iObjectVec) { + if (!it) { + continue; + } + if (it == iExceptThis) { + continue; + } + it->setDisabled(true); + } +} + +void PartGui::DlgProjectionOnSurface::enable_ui_elements(const std::vector& iObjectVec, + QWidget* iExceptThis) +{ + for (auto it : iObjectVec) { + if (!it) { + continue; + } + if (it == iExceptThis) { + continue; + } + it->setEnabled(true); + } +} + +void PartGui::DlgProjectionOnSurface::higlight_object(Part::Feature* iCurrentObject, + const std::string& iShapeName, + bool iHighlight, + unsigned int iColor) +{ + if (!iCurrentObject) { + return; + } + auto partenShape = iCurrentObject->Shape.getShape().getShape(); + auto subShape = iCurrentObject->Shape.getShape().getSubShape(iShapeName.c_str(), true); + + TopoDS_Shape currentShape = subShape; + if (subShape.IsNull()) { + currentShape = partenShape; } - if ( iHighlight ) - { - App::Color aColor; - aColor.setPackedValue(iColor); - colors.at(index - 1) = aColor; + auto currentShapeType = currentShape.ShapeType(); + TopTools_IndexedMapOfShape anIndices; + TopExp::MapShapes(partenShape, currentShapeType, anIndices); + if (anIndices.IsEmpty()) { + return; } - else - { - colors.at(index - 1) = defaultColor; + if (!anIndices.Contains(currentShape)) { + return; } - if (currentShapeType == TopAbs_FACE) - { - vp->DiffuseColor.setValues(colors); + auto index = anIndices.FindIndex(currentShape); + + // set color + auto vp = dynamic_cast( + Gui::Application::Instance->getViewProvider(iCurrentObject)); + if (vp) { + std::vector colors; + App::Color defaultColor; + if (currentShapeType == TopAbs_FACE) { + colors = vp->DiffuseColor.getValues(); + defaultColor = vp->ShapeColor.getValue(); + } + else if (currentShapeType == TopAbs_EDGE) { + colors = vp->LineColorArray.getValues(); + defaultColor = vp->LineColor.getValue(); + } + + if (static_cast(colors.size()) != anIndices.Extent()) { + colors.resize(anIndices.Extent(), defaultColor); + } + + if (iHighlight) { + App::Color aColor; + aColor.setPackedValue(iColor); + colors.at(index - 1) = aColor; + } + else { + colors.at(index - 1) = defaultColor; + } + if (currentShapeType == TopAbs_FACE) { + vp->DiffuseColor.setValues(colors); + } + else if (currentShapeType == TopAbs_EDGE) { + vp->LineColorArray.setValues(colors); + } } - else if (currentShapeType == TopAbs_EDGE) - { - vp->LineColorArray.setValues(colors); - } - } } void PartGui::DlgProjectionOnSurface::get_all_wire_from_face(SShapeStore& ioCurrentSahpe) { - auto outerWire = ShapeAnalysis::OuterWire(ioCurrentSahpe.aFace); - ioCurrentSahpe.aWireVec.push_back(outerWire); - for (TopExp_Explorer aExplorer(ioCurrentSahpe.aFace, TopAbs_WIRE); aExplorer.More(); aExplorer.Next()) - { - auto currentWire = TopoDS::Wire(aExplorer.Current()); - if (currentWire.IsSame(outerWire)) continue; - ioCurrentSahpe.aWireVec.push_back(currentWire); - } -} - -void PartGui::DlgProjectionOnSurface::create_projection_face_from_wire(std::vector& iCurrentShape) -{ - try - { - if (iCurrentShape.empty()) - return; - - for ( auto &itCurrentShape : iCurrentShape ) - { - if (itCurrentShape.aFace.IsNull()) continue;; - if (itCurrentShape.aProjectedWireVec.empty()) continue;; - if (!itCurrentShape.aProjectedFace.IsNull()) continue;; - - auto surface = BRep_Tool::Surface(itCurrentShape.surfaceToProject); - - //create a wire of all edges in parametric space on the surface of the face to projected - // --> otherwise BRepBuilderAPI_MakeFace can not make a face from the wire! - for (const auto& itWireVec : itCurrentShape.aProjectedWireVec) - { - std::vector edgeVec; - for (TopExp_Explorer aExplorer(itWireVec, TopAbs_EDGE); aExplorer.More(); aExplorer.Next()) - { - auto currentEdge = TopoDS::Edge(aExplorer.Current()); - edgeVec.push_back(currentEdge); + auto outerWire = ShapeAnalysis::OuterWire(ioCurrentSahpe.aFace); + ioCurrentSahpe.aWireVec.push_back(outerWire); + for (TopExp_Explorer aExplorer(ioCurrentSahpe.aFace, TopAbs_WIRE); aExplorer.More(); + aExplorer.Next()) { + auto currentWire = TopoDS::Wire(aExplorer.Current()); + if (currentWire.IsSame(outerWire)) { + continue; } - if (edgeVec.empty()) continue; - - std::vector edgeInParametricSpaceVec; - for (auto itEdge : edgeVec) - { - Standard_Real first, last; - auto currentCurve = BRep_Tool::CurveOnSurface(TopoDS::Edge(itEdge), itCurrentShape.surfaceToProject, first, last); - if (!currentCurve) continue; - auto edgeInParametricSpace = BRepBuilderAPI_MakeEdge(currentCurve, surface, first,last).Edge(); - edgeInParametricSpaceVec.push_back(edgeInParametricSpace); - } - auto aWire = sort_and_heal_wire(edgeInParametricSpaceVec, itCurrentShape.surfaceToProject); - itCurrentShape.aProjectedWireInParametricSpaceVec.push_back(aWire); - } - - // try to create a face from the wires - // the first wire is the otherwise - // the following wires are the inside wires - BRepBuilderAPI_MakeFace faceMaker; - bool first = true; - for (auto itWireVec : itCurrentShape.aProjectedWireInParametricSpaceVec) - { - if (first) - { - first = false; - // change the wire direction, otherwise no face is created - auto currentWire = TopoDS::Wire(itWireVec.Reversed()); - if (itCurrentShape.surfaceToProject.Orientation() == TopAbs_REVERSED) currentWire = itWireVec; - faceMaker = BRepBuilderAPI_MakeFace(surface, currentWire); - ShapeFix_Face fix(faceMaker.Face()); - fix.Perform(); - auto aFace = fix.Face(); - BRepCheck_Analyzer aChecker(aFace); - if (!aChecker.IsValid()) - { - faceMaker = BRepBuilderAPI_MakeFace(surface, TopoDS::Wire(currentWire.Reversed())); - } - } - else - { - // make a copy of the current face maker - // if the face fails just try again with the copy - TopoDS_Face tempCopy = BRepBuilderAPI_MakeFace(faceMaker.Face()).Face(); - faceMaker.Add(TopoDS::Wire(itWireVec.Reversed())); - ShapeFix_Face fix(faceMaker.Face()); - fix.Perform(); - auto aFace = fix.Face(); - BRepCheck_Analyzer aChecker(aFace); - if (!aChecker.IsValid()) - { - faceMaker = BRepBuilderAPI_MakeFace(tempCopy); - faceMaker.Add(TopoDS::Wire(itWireVec)); - } - } - } - //auto doneFlag = faceMaker.IsDone(); - //auto error = faceMaker.Error(); - itCurrentShape.aProjectedFace = faceMaker.Face(); + ioCurrentSahpe.aWireVec.push_back(currentWire); } - } - catch (const Standard_Failure& error) - { - std::stringstream ssOcc; - error.Print(ssOcc); - throw Base::ValueError(ssOcc.str().c_str()); - } } -TopoDS_Wire PartGui::DlgProjectionOnSurface::sort_and_heal_wire(const TopoDS_Shape& iShape, const TopoDS_Face& iFaceToProject) +void PartGui::DlgProjectionOnSurface::create_projection_face_from_wire( + std::vector& iCurrentShape) { - std::vector aEdgeVec; - for (TopExp_Explorer aExplorer(iShape, TopAbs_EDGE); aExplorer.More(); aExplorer.Next()) - { - auto anEdge = TopoDS::Edge(aExplorer.Current()); - aEdgeVec.push_back(anEdge); - } - return sort_and_heal_wire(aEdgeVec, iFaceToProject); + try { + if (iCurrentShape.empty()) { + return; + } + + for (auto& itCurrentShape : iCurrentShape) { + if (itCurrentShape.aFace.IsNull()) { + continue; + }; + if (itCurrentShape.aProjectedWireVec.empty()) { + continue; + }; + if (!itCurrentShape.aProjectedFace.IsNull()) { + continue; + }; + + auto surface = BRep_Tool::Surface(itCurrentShape.surfaceToProject); + + // create a wire of all edges in parametric space on the surface of the face to + // projected + // --> otherwise BRepBuilderAPI_MakeFace can not make a face from the wire! + for (const auto& itWireVec : itCurrentShape.aProjectedWireVec) { + std::vector edgeVec; + for (TopExp_Explorer aExplorer(itWireVec, TopAbs_EDGE); aExplorer.More(); + aExplorer.Next()) { + auto currentEdge = TopoDS::Edge(aExplorer.Current()); + edgeVec.push_back(currentEdge); + } + if (edgeVec.empty()) { + continue; + } + + std::vector edgeInParametricSpaceVec; + for (auto itEdge : edgeVec) { + Standard_Real first {}; + Standard_Real last {}; + auto currentCurve = BRep_Tool::CurveOnSurface(TopoDS::Edge(itEdge), + itCurrentShape.surfaceToProject, + first, + last); + if (!currentCurve) { + continue; + } + auto edgeInParametricSpace = + BRepBuilderAPI_MakeEdge(currentCurve, surface, first, last).Edge(); + edgeInParametricSpaceVec.push_back(edgeInParametricSpace); + } + auto aWire = + sort_and_heal_wire(edgeInParametricSpaceVec, itCurrentShape.surfaceToProject); + itCurrentShape.aProjectedWireInParametricSpaceVec.push_back(aWire); + } + + // try to create a face from the wires + // the first wire is the otherwise + // the following wires are the inside wires + BRepBuilderAPI_MakeFace faceMaker; + bool first = true; + for (auto itWireVec : itCurrentShape.aProjectedWireInParametricSpaceVec) { + if (first) { + first = false; + // change the wire direction, otherwise no face is created + auto currentWire = TopoDS::Wire(itWireVec.Reversed()); + if (itCurrentShape.surfaceToProject.Orientation() == TopAbs_REVERSED) { + currentWire = itWireVec; + } + faceMaker = BRepBuilderAPI_MakeFace(surface, currentWire); + ShapeFix_Face fix(faceMaker.Face()); + fix.Perform(); + auto aFace = fix.Face(); + BRepCheck_Analyzer aChecker(aFace); + if (!aChecker.IsValid()) { + faceMaker = + BRepBuilderAPI_MakeFace(surface, TopoDS::Wire(currentWire.Reversed())); + } + } + else { + // make a copy of the current face maker + // if the face fails just try again with the copy + TopoDS_Face tempCopy = BRepBuilderAPI_MakeFace(faceMaker.Face()).Face(); + faceMaker.Add(TopoDS::Wire(itWireVec.Reversed())); + ShapeFix_Face fix(faceMaker.Face()); + fix.Perform(); + auto aFace = fix.Face(); + BRepCheck_Analyzer aChecker(aFace); + if (!aChecker.IsValid()) { + faceMaker = BRepBuilderAPI_MakeFace(tempCopy); + faceMaker.Add(TopoDS::Wire(itWireVec)); + } + } + } + // auto doneFlag = faceMaker.IsDone(); + // auto error = faceMaker.Error(); + itCurrentShape.aProjectedFace = faceMaker.Face(); + } + } + catch (const Standard_Failure& error) { + std::stringstream ssOcc; + error.Print(ssOcc); + throw Base::ValueError(ssOcc.str().c_str()); + } } -TopoDS_Wire PartGui::DlgProjectionOnSurface::sort_and_heal_wire(const std::vector& iEdgeVec, const TopoDS_Face& iFaceToProject) +TopoDS_Wire PartGui::DlgProjectionOnSurface::sort_and_heal_wire(const TopoDS_Shape& iShape, + const TopoDS_Face& iFaceToProject) { - // try to sort and heal all wires -// if the wires are not clean making a face will fail! - ShapeAnalysis_FreeBounds shapeAnalyzer; - Handle(TopTools_HSequenceOfShape) shapeList = new TopTools_HSequenceOfShape; - Handle(TopTools_HSequenceOfShape) aWireHandle; - Handle(TopTools_HSequenceOfShape) aWireWireHandle; + std::vector aEdgeVec; + for (TopExp_Explorer aExplorer(iShape, TopAbs_EDGE); aExplorer.More(); aExplorer.Next()) { + auto anEdge = TopoDS::Edge(aExplorer.Current()); + aEdgeVec.push_back(anEdge); + } + return sort_and_heal_wire(aEdgeVec, iFaceToProject); +} - for (const auto& it : iEdgeVec) - { - shapeList->Append(it); - } +TopoDS_Wire +PartGui::DlgProjectionOnSurface::sort_and_heal_wire(const std::vector& iEdgeVec, + const TopoDS_Face& iFaceToProject) +{ + // try to sort and heal all wires + // if the wires are not clean making a face will fail! + ShapeAnalysis_FreeBounds shapeAnalyzer; + Handle(TopTools_HSequenceOfShape) shapeList = new TopTools_HSequenceOfShape; + Handle(TopTools_HSequenceOfShape) aWireHandle; + Handle(TopTools_HSequenceOfShape) aWireWireHandle; - shapeAnalyzer.ConnectEdgesToWires(shapeList, 0.0001, false, aWireHandle); - shapeAnalyzer.ConnectWiresToWires(aWireHandle, 0.0001, false, aWireWireHandle); - if (!aWireWireHandle) - return {}; - for (auto it = 1; it <= aWireWireHandle->Length(); ++it) - { - auto aShape = TopoDS::Wire(aWireWireHandle->Value(it)); - ShapeFix_Wire aWireRepair(aShape, iFaceToProject, 0.0001); - aWireRepair.FixAddCurve3dMode() = 1; - aWireRepair.FixAddPCurveMode() = 1; - aWireRepair.Perform(); - //return aWireRepair.Wire(); - ShapeFix_Wireframe aWireFramFix(aWireRepair.Wire()); - auto retVal = aWireFramFix.FixWireGaps(); - retVal = aWireFramFix.FixSmallEdges(); - Q_UNUSED(retVal); - return TopoDS::Wire(aWireFramFix.Shape()); - } - return {}; + for (const auto& it : iEdgeVec) { + shapeList->Append(it); + } + + const double tolerance = 0.0001; + ShapeAnalysis_FreeBounds::ConnectEdgesToWires(shapeList, tolerance, false, aWireHandle); + ShapeAnalysis_FreeBounds::ConnectWiresToWires(aWireHandle, tolerance, false, aWireWireHandle); + if (!aWireWireHandle) { + return {}; + } + for (auto it = 1; it <= aWireWireHandle->Length(); ++it) { + auto aShape = TopoDS::Wire(aWireWireHandle->Value(it)); + ShapeFix_Wire aWireRepair(aShape, iFaceToProject, tolerance); + aWireRepair.FixAddCurve3dMode() = 1; + aWireRepair.FixAddPCurveMode() = 1; + aWireRepair.Perform(); + // return aWireRepair.Wire(); + ShapeFix_Wireframe aWireFramFix(aWireRepair.Wire()); + aWireFramFix.FixWireGaps(); + aWireFramFix.FixSmallEdges(); + return TopoDS::Wire(aWireFramFix.Shape()); + } + return {}; } void PartGui::DlgProjectionOnSurface::create_face_extrude(std::vector& iCurrentShape) { - try - { - if (iCurrentShape.empty()) - return; + try { + if (iCurrentShape.empty()) { + return; + } - auto height = ui->doubleSpinBoxExtrudeHeight->value(); + auto height = ui->doubleSpinBoxExtrudeHeight->value(); - for ( auto &itCurrentShape : iCurrentShape ) - { - if (itCurrentShape.aProjectedFace.IsNull()) continue;; - if (itCurrentShape.extrudeValue == height) continue;; + for (auto& itCurrentShape : iCurrentShape) { + if (itCurrentShape.aProjectedFace.IsNull()) { + continue; + } + if (itCurrentShape.extrudeValue == height) { + continue; + } - itCurrentShape.extrudeValue = height; - if (height == 0) - { - itCurrentShape.aProjectedSolid.Nullify(); - } - else - { - gp_Vec directionToExtrude(itCurrentShape.aProjectionDir.XYZ()); - directionToExtrude.Reverse(); - directionToExtrude.Multiply(height); - BRepPrimAPI_MakePrism extrude(itCurrentShape.aProjectedFace, directionToExtrude); - itCurrentShape.aProjectedSolid = extrude.Shape(); - } + itCurrentShape.extrudeValue = height; + if (height == 0) { + itCurrentShape.aProjectedSolid.Nullify(); + } + else { + gp_Vec directionToExtrude(itCurrentShape.aProjectionDir.XYZ()); + directionToExtrude.Reverse(); + directionToExtrude.Multiply(height); + BRepPrimAPI_MakePrism extrude(itCurrentShape.aProjectedFace, directionToExtrude); + itCurrentShape.aProjectedSolid = extrude.Shape(); + } + } + } + catch (const Standard_Failure& error) { + std::stringstream ssOcc; + error.Print(ssOcc); + throw Base::ValueError(ssOcc.str().c_str()); } - } - catch (const Standard_Failure& error) - { - std::stringstream ssOcc; - error.Print(ssOcc); - throw Base::ValueError(ssOcc.str().c_str()); - } } -void PartGui::DlgProjectionOnSurface::store_wire_in_vector(const SShapeStore& iCurrentShape, const TopoDS_Shape& iParentShape, std::vector& iStoreVec, const unsigned int iColor) +void PartGui::DlgProjectionOnSurface::store_wire_in_vector(const SShapeStore& iCurrentShape, + const TopoDS_Shape& iParentShape, + std::vector& iStoreVec, + unsigned int iColor) { - if (m_currentSelection != "add_wire") - return; - if (iParentShape.IsNull()) - return; - if (iCurrentShape.inputShape.IsNull()) - return; - auto currentType = iCurrentShape.inputShape.ShapeType(); - if (currentType != TopAbs_EDGE) - return; - - std::vector aWireVec; - for (TopExp_Explorer aExplorer(iParentShape, TopAbs_WIRE); aExplorer.More(); aExplorer.Next()) - { - aWireVec.push_back(TopoDS::Wire(aExplorer.Current())); - } - - std::vector edgeVec; - for (const auto& it : aWireVec ) - { - bool edgeExists = false; - for (TopExp_Explorer aExplorer(it, TopAbs_EDGE); aExplorer.More(); aExplorer.Next()) - { - auto currentEdge = TopoDS::Edge(aExplorer.Current()); - edgeVec.push_back(currentEdge); - if (currentEdge.IsSame(iCurrentShape.inputShape)) edgeExists = true; - } - if (edgeExists) break; - edgeVec.clear(); - } - - if (edgeVec.empty()) - return; - TopTools_IndexedMapOfShape indexMap; - TopExp::MapShapes(iParentShape, TopAbs_EDGE, indexMap); - if (indexMap.IsEmpty()) - return; - - for (const auto& it : edgeVec ) - { - if ( it.IsSame(iCurrentShape.inputShape)) continue; - if (!indexMap.Contains(it)) + if (m_currentSelection != "add_wire") { return; - auto index = indexMap.FindIndex(it); - auto newEdgeObject = iCurrentShape; - newEdgeObject.inputShape = it; - newEdgeObject.partName = "Edge" + std::to_string(index); + } + if (iParentShape.IsNull()) { + return; + } + if (iCurrentShape.inputShape.IsNull()) { + return; + } + auto currentType = iCurrentShape.inputShape.ShapeType(); + if (currentType != TopAbs_EDGE) { + return; + } - auto store = store_part_in_vector(newEdgeObject, iStoreVec); - higlight_object(newEdgeObject.partFeature, newEdgeObject.partName, store, iColor); - } + std::vector aWireVec; + for (TopExp_Explorer aExplorer(iParentShape, TopAbs_WIRE); aExplorer.More(); aExplorer.Next()) { + aWireVec.push_back(TopoDS::Wire(aExplorer.Current())); + } + + std::vector edgeVec; + for (const auto& it : aWireVec) { + bool edgeExists = false; + for (TopExp_Explorer aExplorer(it, TopAbs_EDGE); aExplorer.More(); aExplorer.Next()) { + auto currentEdge = TopoDS::Edge(aExplorer.Current()); + edgeVec.push_back(currentEdge); + if (currentEdge.IsSame(iCurrentShape.inputShape)) { + edgeExists = true; + } + } + if (edgeExists) { + break; + } + edgeVec.clear(); + } + + if (edgeVec.empty()) { + return; + } + TopTools_IndexedMapOfShape indexMap; + TopExp::MapShapes(iParentShape, TopAbs_EDGE, indexMap); + if (indexMap.IsEmpty()) { + return; + } + + for (const auto& it : edgeVec) { + if (it.IsSame(iCurrentShape.inputShape)) { + continue; + } + if (!indexMap.Contains(it)) { + return; + } + auto index = indexMap.FindIndex(it); + auto newEdgeObject = iCurrentShape; + newEdgeObject.inputShape = it; + newEdgeObject.partName = "Edge" + std::to_string(index); + + auto store = store_part_in_vector(newEdgeObject, iStoreVec); + higlight_object(newEdgeObject.partFeature, newEdgeObject.partName, store, iColor); + } } void PartGui::DlgProjectionOnSurface::set_xyz_dir_spinbox(QDoubleSpinBox* icurrentSpinBox) { - auto currentVal = icurrentSpinBox->value(); - auto newVal = 0.0; - if (currentVal != 1.0 && currentVal != -1.0) - { - newVal = -1; - } - else if (currentVal == 1.0) - { - newVal = -1; - } - else if (currentVal == -1.0) - { - newVal = 1; - } - ui->doubleSpinBoxDirX->setValue(0); - ui->doubleSpinBoxDirY->setValue(0); - ui->doubleSpinBoxDirZ->setValue(0); - icurrentSpinBox->setValue(newVal); + auto currentVal = icurrentSpinBox->value(); + auto newVal = 0.0; + if (currentVal != 1.0 && currentVal != -1.0) { + newVal = -1; + } + else if (currentVal == 1.0) { + newVal = -1; + } + else if (currentVal == -1.0) { + newVal = 1; + } + ui->doubleSpinBoxDirX->setValue(0); + ui->doubleSpinBoxDirY->setValue(0); + ui->doubleSpinBoxDirZ->setValue(0); + icurrentSpinBox->setValue(newVal); } -void PartGui::DlgProjectionOnSurface::transform_shape_to_global_position(TopoDS_Shape& ioShape, Part::Feature* iPart) +void PartGui::DlgProjectionOnSurface::transform_shape_to_global_position(TopoDS_Shape& ioShape, + Part::Feature* iPart) { - auto currentPos = iPart->Placement.getValue().getPosition(); - auto currentRotation = iPart->Placement.getValue().getRotation(); - auto globalPlacement = iPart->globalPlacement(); - auto globalPosition = globalPlacement.getPosition(); - auto globalRotation = globalPlacement.getRotation(); + auto currentPos = iPart->Placement.getValue().getPosition(); + auto currentRotation = iPart->Placement.getValue().getRotation(); + auto globalPlacement = iPart->globalPlacement(); + auto globalPosition = globalPlacement.getPosition(); + auto globalRotation = globalPlacement.getRotation(); - if (currentRotation != globalRotation) - { - auto newRotation = globalRotation; - newRotation *= currentRotation.invert(); + if (currentRotation != globalRotation) { + auto newRotation = globalRotation; + newRotation *= currentRotation.invert(); - gp_Trsf aAngleTransform; - Base::Vector3d rotationAxes; - double rotationAngle; - newRotation.getRawValue(rotationAxes, rotationAngle); - aAngleTransform.SetRotation(gp_Ax1(gp_Pnt(currentPos.x, currentPos.y, currentPos.z), gp_Dir(rotationAxes.x, rotationAxes.y, rotationAxes.z)), rotationAngle); - ioShape = BRepBuilderAPI_Transform(ioShape, aAngleTransform, true).Shape(); - } + gp_Trsf aAngleTransform; + Base::Vector3d rotationAxes; + double rotationAngle {}; + newRotation.getRawValue(rotationAxes, rotationAngle); + aAngleTransform.SetRotation(gp_Ax1(gp_Pnt(currentPos.x, currentPos.y, currentPos.z), + gp_Dir(rotationAxes.x, rotationAxes.y, rotationAxes.z)), + rotationAngle); + ioShape = BRepBuilderAPI_Transform(ioShape, aAngleTransform, true).Shape(); + } - if (currentPos != globalPosition) - { - gp_Trsf aPosTransform; - aPosTransform.SetTranslation(gp_Pnt(currentPos.x, currentPos.y, currentPos.z), gp_Pnt(globalPosition.x, globalPosition.y, globalPosition.z)); - ioShape = BRepBuilderAPI_Transform(ioShape, aPosTransform, true).Shape(); - } + if (currentPos != globalPosition) { + gp_Trsf aPosTransform; + aPosTransform.SetTranslation(gp_Pnt(currentPos.x, currentPos.y, currentPos.z), + gp_Pnt(globalPosition.x, globalPosition.y, globalPosition.z)); + ioShape = BRepBuilderAPI_Transform(ioShape, aPosTransform, true).Shape(); + } } void PartGui::DlgProjectionOnSurface::onPushButtonAddProjFaceClicked() { - if (ui->pushButtonAddProjFace->isChecked()) - { - m_currentSelection = "add_projection_surface"; - disable_ui_elements(m_guiObjectVec, ui->pushButtonAddProjFace); - if (!filterFace) - { - filterFace = new FaceSelection(); - Gui::Selection().addSelectionGate(filterFace); + if (ui->pushButtonAddProjFace->isChecked()) { + m_currentSelection = "add_projection_surface"; + disable_ui_elements(m_guiObjectVec, ui->pushButtonAddProjFace); + if (!filterFace) { + filterFace = new FaceSelection(); + Gui::Selection().addSelectionGate(filterFace); + } + } + else { + m_currentSelection = ""; + enable_ui_elements(m_guiObjectVec, nullptr); + Gui::Selection().rmvSelectionGate(); + filterFace = nullptr; } - } - else - { - m_currentSelection = ""; - enable_ui_elements(m_guiObjectVec, nullptr); - Gui::Selection().rmvSelectionGate(); - filterFace = nullptr; - } } void PartGui::DlgProjectionOnSurface::onRadioButtonShowAllClicked() { - m_currentShowType = "all"; - show_projected_shapes(m_shapeVec); + m_currentShowType = "all"; + show_projected_shapes(m_shapeVec); } void PartGui::DlgProjectionOnSurface::onRadioButtonFacesClicked() { - m_currentShowType = "faces"; - show_projected_shapes(m_shapeVec); + m_currentShowType = "faces"; + show_projected_shapes(m_shapeVec); } void PartGui::DlgProjectionOnSurface::onRadioButtonEdgesClicked() { - m_currentShowType = "edges"; - show_projected_shapes(m_shapeVec); + m_currentShowType = "edges"; + show_projected_shapes(m_shapeVec); } void PartGui::DlgProjectionOnSurface::onDoubleSpinBoxExtrudeHeightValueChanged(double arg1) { - Q_UNUSED(arg1); - create_face_extrude(m_shapeVec); - show_projected_shapes(m_shapeVec); + Q_UNUSED(arg1); + create_face_extrude(m_shapeVec); + show_projected_shapes(m_shapeVec); } void PartGui::DlgProjectionOnSurface::onPushButtonAddWireClicked() { - if (ui->pushButtonAddWire->isChecked()) - { - m_currentSelection = "add_wire"; - disable_ui_elements(m_guiObjectVec, ui->pushButtonAddWire); - if (!filterEdge) - { - filterEdge = new EdgeSelection(); - Gui::Selection().addSelectionGate(filterEdge); + if (ui->pushButtonAddWire->isChecked()) { + m_currentSelection = "add_wire"; + disable_ui_elements(m_guiObjectVec, ui->pushButtonAddWire); + if (!filterEdge) { + filterEdge = new EdgeSelection(); + Gui::Selection().addSelectionGate(filterEdge); + } + ui->radioButtonEdges->setChecked(true); + onRadioButtonEdgesClicked(); + } + else { + m_currentSelection = ""; + enable_ui_elements(m_guiObjectVec, nullptr); + Gui::Selection().rmvSelectionGate(); + filterEdge = nullptr; } - ui->radioButtonEdges->setChecked(true); - onRadioButtonEdgesClicked(); - } - else - { - m_currentSelection = ""; - enable_ui_elements(m_guiObjectVec, nullptr); - Gui::Selection().rmvSelectionGate(); - filterEdge = nullptr; - } } void PartGui::DlgProjectionOnSurface::onDoubleSpinBoxSolidDepthValueChanged(double arg1) { - auto valX = ui->doubleSpinBoxDirX->value(); - auto valY = ui->doubleSpinBoxDirY->value(); - auto valZ = ui->doubleSpinBoxDirZ->value(); + auto valX = ui->doubleSpinBoxDirX->value(); + auto valY = ui->doubleSpinBoxDirY->value(); + auto valZ = ui->doubleSpinBoxDirZ->value(); - auto valueToMove = arg1 - m_lastDepthVal; - Base::Vector3d vectorToMove(valX, valY, valZ); - vectorToMove *= valueToMove; + auto valueToMove = arg1 - m_lastDepthVal; + Base::Vector3d vectorToMove(valX, valY, valZ); + vectorToMove *= valueToMove; - auto placment = m_projectionObject->Placement.getValue(); - placment.move(vectorToMove); - m_projectionObject->Placement.setValue(placment); + auto placment = m_projectionObject->Placement.getValue(); + placment.move(vectorToMove); + m_projectionObject->Placement.setValue(placment); - m_lastDepthVal = ui->doubleSpinBoxSolidDepth->value(); + m_lastDepthVal = ui->doubleSpinBoxSolidDepth->value(); } // --------------------------------------- TaskProjectionOnSurface::TaskProjectionOnSurface() + : widget(new DlgProjectionOnSurface()) + , taskbox(new Gui::TaskView::TaskBox(Gui::BitmapFactory().pixmap("Part_ProjectionOnSurface"), + widget->windowTitle(), + true, + nullptr)) { - widget = new DlgProjectionOnSurface(); - taskbox = new Gui::TaskView::TaskBox( - Gui::BitmapFactory().pixmap("Part_ProjectionOnSurface"), - widget->windowTitle(), true, nullptr); - taskbox->groupLayout()->addWidget(widget); - Content.push_back(taskbox); + taskbox->groupLayout()->addWidget(widget); + Content.push_back(taskbox); } bool TaskProjectionOnSurface::accept() { - widget->apply(); - return true; - //return (widget->result() == QDialog::Accepted); + widget->apply(); + return true; } bool TaskProjectionOnSurface::reject() { - widget->reject(); - return true; + widget->reject(); + return true; } void TaskProjectionOnSurface::clicked(int id) { - if (id == QDialogButtonBox::Apply) { - try { - widget->apply(); + if (id == QDialogButtonBox::Apply) { + try { + widget->apply(); + } + catch (Base::AbortException&) { + } } - catch (Base::AbortException&) { - - }; - } } #include "moc_DlgProjectionOnSurface.cpp" diff --git a/src/Mod/Part/Gui/DlgProjectionOnSurface.h b/src/Mod/Part/Gui/DlgProjectionOnSurface.h index ec1cd285b0..4a4f6c10bc 100644 --- a/src/Mod/Part/Gui/DlgProjectionOnSurface.h +++ b/src/Mod/Part/Gui/DlgProjectionOnSurface.h @@ -36,22 +36,24 @@ #include -namespace PartGui { +namespace PartGui +{ - class Ui_DlgProjectionOnSurface; +class Ui_DlgProjectionOnSurface; - namespace Ui { - class DlgProjectionOnSurface; - } +namespace Ui +{ +class DlgProjectionOnSurface; +} -class DlgProjectionOnSurface : public QWidget, - public Gui::SelectionObserver, - public App::DocumentObserver +class DlgProjectionOnSurface: public QWidget, + public Gui::SelectionObserver, + public App::DocumentObserver { Q_OBJECT public: - explicit DlgProjectionOnSurface(QWidget *parent = nullptr); + explicit DlgProjectionOnSurface(QWidget* parent = nullptr); ~DlgProjectionOnSurface() override; void apply(); @@ -74,57 +76,64 @@ private: void onDoubleSpinBoxSolidDepthValueChanged(double arg1); private: + struct SShapeStore + { + TopoDS_Shape inputShape; + TopoDS_Face surfaceToProject; + gp_Dir aProjectionDir; + TopoDS_Face aFace; + TopoDS_Edge aEdge; + std::vector aWireVec; + std::vector aProjectedWireVec; + std::vector aProjectedEdgeVec; + std::vector aProjectedWireInParametricSpaceVec; + TopoDS_Face aProjectedFace; + TopoDS_Shape aProjectedSolid; + Part::Feature* partFeature = nullptr; + std::string partName; + bool is_selectable = false; + long transparency = 0; + double extrudeValue = 0.0; + }; - struct SShapeStore - { - TopoDS_Shape inputShape; - TopoDS_Face surfaceToProject; - gp_Dir aProjectionDir; - TopoDS_Face aFace; - TopoDS_Edge aEdge; - std::vector aWireVec; - std::vector aProjectedWireVec; - std::vector aProjectedEdgeVec; - std::vector aProjectedWireInParametricSpaceVec; - TopoDS_Face aProjectedFace; - TopoDS_Shape aProjectedSolid; - Part::Feature* partFeature = nullptr; - std::string partName; - bool is_selectable = false; - long transparency = 0; - float extrudeValue = 0.0f; - }; - - //from Gui::SelectionObserver - void onSelectionChanged(const Gui::SelectionChanges& msg) override; + // from Gui::SelectionObserver + void onSelectionChanged(const Gui::SelectionChanges& msg) override; - void get_camera_direction(); - void store_current_selected_parts(std::vector& iStoreVec, const unsigned int iColor); - bool store_part_in_vector(SShapeStore& iCurrentShape, std::vector& iStoreVec); - void create_projection_wire(std::vector& iCurrentShape); - TopoDS_Shape create_compound(const std::vector& iShapeVec); - void show_projected_shapes(const std::vector& iShapeStoreVec); - void disable_ui_elements(const std::vector& iObjectVec, QWidget* iExceptThis); - void enable_ui_elements(const std::vector& iObjectVec, QWidget* iExceptThis); - void higlight_object(Part::Feature* iCurrentObject, const std::string& iShapeName, bool iHighlight, const unsigned int iColor); - void get_all_wire_from_face(SShapeStore& ioCurrentSahpe); - void create_projection_face_from_wire(std::vector& iCurrentShape); - TopoDS_Wire sort_and_heal_wire(const TopoDS_Shape& iShape, const TopoDS_Face& iFaceToProject); - TopoDS_Wire sort_and_heal_wire(const std::vector& iEdgeVec, const TopoDS_Face& iFaceToProject); - void create_face_extrude(std::vector& iCurrentShape); - void store_wire_in_vector(const SShapeStore& iCurrentShape, const TopoDS_Shape& iParentShape, std::vector& iStoreVec, const unsigned int iColor); - void set_xyz_dir_spinbox(QDoubleSpinBox* icurrentSpinBox); - void transform_shape_to_global_position(TopoDS_Shape& ioShape, Part::Feature* iPart); + void get_camera_direction(); + void store_current_selected_parts(std::vector& iStoreVec, + unsigned int iColor); + bool store_part_in_vector(SShapeStore& iCurrentShape, std::vector& iStoreVec); + void create_projection_wire(std::vector& iCurrentShape); + TopoDS_Shape create_compound(const std::vector& iShapeVec); + void show_projected_shapes(const std::vector& iShapeStoreVec); + void disable_ui_elements(const std::vector& iObjectVec, QWidget* iExceptThis); + void enable_ui_elements(const std::vector& iObjectVec, QWidget* iExceptThis); + void higlight_object(Part::Feature* iCurrentObject, + const std::string& iShapeName, + bool iHighlight, + unsigned int iColor); + void get_all_wire_from_face(SShapeStore& ioCurrentSahpe); + void create_projection_face_from_wire(std::vector& iCurrentShape); + TopoDS_Wire sort_and_heal_wire(const TopoDS_Shape& iShape, const TopoDS_Face& iFaceToProject); + TopoDS_Wire sort_and_heal_wire(const std::vector& iEdgeVec, + const TopoDS_Face& iFaceToProject); + void create_face_extrude(std::vector& iCurrentShape); + void store_wire_in_vector(const SShapeStore& iCurrentShape, + const TopoDS_Shape& iParentShape, + std::vector& iStoreVec, + unsigned int iColor); + void set_xyz_dir_spinbox(QDoubleSpinBox* icurrentSpinBox); + void transform_shape_to_global_position(TopoDS_Shape& ioShape, Part::Feature* iPart); private: - /** Checks if the given document is about to be closed */ - void slotDeletedDocument(const App::Document& Doc) override; - /** Checks if the given object is about to be removed. */ - void slotDeletedObject(const App::DocumentObject& Obj) override; + /** Checks if the given document is about to be closed */ + void slotDeletedDocument(const App::Document& Doc) override; + /** Checks if the given object is about to be removed. */ + void slotDeletedObject(const App::DocumentObject& Obj) override; private: - Ui::DlgProjectionOnSurface *ui; + Ui::DlgProjectionOnSurface* ui; std::vector m_shapeVec; std::vector m_projectionSurfaceVec; @@ -134,9 +143,9 @@ private: std::vector m_guiObjectVec; const QString m_projectionObjectName; - Part::Feature* m_projectionObject; - App::Document* m_partDocument; - float m_lastDepthVal; + Part::Feature* m_projectionObject = nullptr; + App::Document* m_partDocument = nullptr; + double m_lastDepthVal; class EdgeSelection; EdgeSelection* filterEdge; @@ -145,28 +154,28 @@ private: FaceSelection* filterFace; }; -class TaskProjectionOnSurface : public Gui::TaskView::TaskDialog +class TaskProjectionOnSurface: public Gui::TaskView::TaskDialog { - Q_OBJECT + Q_OBJECT public: - TaskProjectionOnSurface(); + TaskProjectionOnSurface(); public: - bool accept() override; - bool reject() override; - void clicked(int) override; + bool accept() override; + bool reject() override; + void clicked(int id) override; - QDialogButtonBox::StandardButtons getStandardButtons() const override - { - return QDialogButtonBox::Ok | QDialogButtonBox::Cancel; - } + QDialogButtonBox::StandardButtons getStandardButtons() const override + { + return QDialogButtonBox::Ok | QDialogButtonBox::Cancel; + } private: - DlgProjectionOnSurface* widget; - Gui::TaskView::TaskBox* taskbox; + DlgProjectionOnSurface* widget = nullptr; + Gui::TaskView::TaskBox* taskbox = nullptr; }; -} // namespace PartGui -#endif // PARTGUI_DLGPROJECTIONONSURFACE_H +} // namespace PartGui +#endif // PARTGUI_DLGPROJECTIONONSURFACE_H