From 3b46d4a3f0eda1f03854ac5d86084323c235f406 Mon Sep 17 00:00:00 2001 From: dish Date: Fri, 14 Jun 2024 12:45:33 +0000 Subject: [PATCH] [bos #35154][EDF](2023-T1) Edge thickness. Fix setting thickness to individual edges. --- src/ModelAPI/ModelAPI_Tools.cpp | 21 +++++++++++++++++--- src/XGUI/XGUI_Displayer.cpp | 35 +++++++++++++++++++++++++++++---- src/XGUI/XGUI_Workshop.cpp | 23 +++++++++++++++++++++- 3 files changed, 71 insertions(+), 8 deletions(-) diff --git a/src/ModelAPI/ModelAPI_Tools.cpp b/src/ModelAPI/ModelAPI_Tools.cpp index 2c59a5c90..e53108182 100644 --- a/src/ModelAPI/ModelAPI_Tools.cpp +++ b/src/ModelAPI/ModelAPI_Tools.cpp @@ -1417,27 +1417,42 @@ void setSubShapeEdgeThickness( std::shared_ptr theSubShape, int theEdgeThickness ) { - if (!theResult || theSubShape->isNull()) + std::wcout << "ModelAPI_Tools::setSubShapeEdgeThickness() START" << std::endl; + + if (!theResult || theSubShape->isNull()) { + std::wcout << "if (!theResult || theSubShape->isNull())" << std::endl; + std::wcout << "ModelAPI_Tools::setSubShapeEdgeThickness() END" << std::endl; return; + } - if (!theResult->shape()->isSubShape(theSubShape)) + if (!theResult->shape()->isSubShape(theSubShape)) { + std::wcout << "if (!theResult->shape()->isSubShape(theSubShape))" << std::endl; + std::wcout << "ModelAPI_Tools::setSubShapeEdgeThickness() END" << std::endl; return; + } auto resultBody = std::dynamic_pointer_cast(theResult); if (resultBody) { + std::wcout << "if (resultBody)" << std::endl; resultBody = mainBody(resultBody); resultBody->setSubShapeEdgeThickness(theResult, theSubShape, theEdgeThickness); } else { + std::wcout << "NOT if (resultBody)" << std::endl; + const auto resultPart = std::dynamic_pointer_cast(theResult); - if (!resultPart) + if (!resultPart) { + std::wcout << "if (!resultPart)" << std::endl; + std::wcout << "ModelAPI_Tools::setSubShapeEdgeThickness() END" << std::endl; return; + } resultPart->setSubShapeEdgeThickness(theSubShape, theEdgeThickness); } static const Events_ID EVENT = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY); ModelAPI_EventCreator::get()->sendUpdated(theResult, EVENT); + std::wcout << "ModelAPI_Tools::setSubShapeEdgeThickness() END" << std::endl; } //****************************************************** diff --git a/src/XGUI/XGUI_Displayer.cpp b/src/XGUI/XGUI_Displayer.cpp index 4f67eaf8c..045f350f5 100644 --- a/src/XGUI/XGUI_Displayer.cpp +++ b/src/XGUI/XGUI_Displayer.cpp @@ -96,6 +96,8 @@ #include +#include + #ifdef _MSC_VER #pragma warning(disable: 4702) #endif @@ -248,7 +250,7 @@ bool XGUI_Displayer::display(ObjectPtr theObject, AISObjectPtr theAIS, // bos#40617: Apply clipping planes // Retrieve the clipping plane from the OCCT Presentation Manager directly, - // as they are stored in the ViewModel of the OCCViewer in GUI, where we + // as they are stored in the ViewModel of the OCCViewer in GUI, where we // don't have access to. Handle(ViewerData_AISShape) aShape = Handle(ViewerData_AISShape)::DownCast (anAISIO); if (!aShape.IsNull() && aShape->IsClippable()) { @@ -427,13 +429,38 @@ bool XGUI_Displayer::redisplay(ObjectPtr theObject, bool theUpdateViewer) if ((aTransparency >= 0) && (aTransparency != aAISObj->getTransparency())) aAISObj->setTransparency(aTransparency); - // Set edge thickness + // Set edge thickness. const int aEdgeThickness = ModelAPI_Tools::getEdgeThickness(aResult); - // std::cout << "aEdgeThickness " << aEdgeThickness << "\t"; - // std::cout << "aAISObj->width() " << aAISObj->width() << std::endl; if ((aEdgeThickness > 0) && (aEdgeThickness != aAISObj->width())) aAISObj->setWidth(aEdgeThickness); + { // Set subshapes' edge thickness. + std::wcout << "XGUI_Displayer::redisplay/Set subshapes' edge thickness. START" << std::endl; + + std::map subShapesAndThicknesses; + ModelAPI_Tools::getSubShapesWithEdgeThickness(aResult, subShapesAndThicknesses); + Handle(AIS_ColoredShape) aResShape = Handle(AIS_ColoredShape)::DownCast(aAISIO); + Handle(ModuleBase_ResultPrs) aResPrsShape = Handle(ModuleBase_ResultPrs)::DownCast(aResShape); + + std::wcout << "subShapesAndThicknesses.size = " << subShapesAndThicknesses.size() << std::endl; + + if (!subShapesAndThicknesses.empty() && !aResPrsShape.IsNull()) { + for (auto it = subShapesAndThicknesses.cbegin(); it != subShapesAndThicknesses.cend(); ++it) { + const auto& subShape = it->first; + const auto& subShapeThickness = it->second; + std::wcout << "subShapeThickness = " << subShapeThickness << std::endl; + + if (aAISObj->getShape()->isSubShape(subShape)) + aResPrsShape->SetCustomWidth(subShape->impl(), subShapeThickness); + } + } + else { + aResShape->ClearCustomAspects(); + } + + std::wcout << "XGUI_Displayer::redisplay/Set subshapes' edge thickness. END" << std::endl; + } + // Set Iso-Lines Handle(ModuleBase_ResultPrs) aResPrs = Handle(ModuleBase_ResultPrs)::DownCast(aAISIO); if (!aResPrs.IsNull()) diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 8baa5dd57..dd89da764 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -961,7 +961,10 @@ void XGUI_Workshop::setGrantedFeatures(ModuleBase_Operation* theOperation) //****************************************************** void XGUI_Workshop::applyEdgeThicknessToCanvas(const QMap>& theSelectedObjects, int theThickness) { + std::wcout << "XGUI_Workshop::applyEdgeThicknessToCanvas( theThickness = " << theThickness << ") START" << std::endl; + const bool isSubShapeWithEdgeThickness = Config_PropManager::boolean("Visualization", "result_subshape_with_edge_thickness"); + std::wcout << "isSubShapeWithEdgeThickness = " << (isSubShapeWithEdgeThickness ? "true" : "false") << std::endl; // 3. Abort previous operation and start a new one. SessionPtr session = ModelAPI_Session::get(); @@ -974,12 +977,24 @@ void XGUI_Workshop::applyEdgeThicknessToCanvas(const QMap(result); + + std::wcout << "theSelectedObjects.size() = " << theSelectedObjects.size() << std::endl; + std::wcout << "foreach START" << std::endl; + if (theSelectedObjects.contains(result)) + std::wcout << "theSelectedObjects[result].size = " << theSelectedObjects[result].size() << std::endl; + foreach(GeomShapePtr shape, theSelectedObjects[result]) { if (result->shape()->impl().IsEqual(shape->impl()) || !isSubShapeWithEdgeThickness) { + std::wcout << "If 1" << std::endl; + if (result) { + std::wcout << "if (result)" << std::endl; + // Change edge thickness for all sub-solids. std::list allSubResults; ModelAPI_Tools::allSubs(bodyResult, allSubResults); + std::wcout << "allSubResults.size() = " << allSubResults.size() << std::endl; + for (auto itSubRes = allSubResults.begin(); itSubRes != allSubResults.end(); itSubRes++) { ModelAPI_Tools::setEdgeThickness(*itSubRes, theThickness); } @@ -990,15 +1005,20 @@ void XGUI_Workshop::applyEdgeThicknessToCanvas(const QMapisNull()) + else if (!shape->isNull()) { + std::wcout << "else if (!shape->isNull())" << std::endl; ModelAPI_Tools::setSubShapeEdgeThickness(result, shape, theThickness); + } } + std::wcout << "foreach END" << std::endl; } Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY)); session->finishOperation(); updateCommandStatus(); myViewerProxy->update(); + + std::wcout << "XGUI_Workshop::applyEdgeThicknessToCanvas( theThickness = " << theThickness << ") END" << std::endl; } //****************************************************** @@ -3000,6 +3020,7 @@ void XGUI_Workshop::changeEdgeThickness(const QMap aValues = mySelector->selection()->getSelected(ModuleBase_ISelection::Viewer); const bool isSubShapeWithEdgeThickness = Config_PropManager::boolean("Visualization", "result_subshape_with_edge_thickness"); foreach(ResultPtr result, theSelectedObjects.keys()) { if (!result) -- 2.39.2