Sketcher: Port and fix internal faces from RealThunder's branch
Co-authored-by: Zheng Lei <realthunder.dev@gmail.com> Co-authored-by: Kacper Donat <kacper@kadet.net> Co-authored-by: Pierre-Louis Boyer <pierrelouis.boyer@gmail.com>
This commit is contained in:
@@ -54,6 +54,7 @@
|
||||
#include <Gui/Selection/Selection.h>
|
||||
#include <Gui/Selection/SelectionObject.h>
|
||||
#include <Gui/Selection/SoFCUnifiedSelection.h>
|
||||
// #include <Gui/Inventor/SoFCSwitch.h>
|
||||
#include <Gui/Utilities.h>
|
||||
#include <Gui/View3DInventor.h>
|
||||
#include <Gui/View3DInventorViewer.h>
|
||||
@@ -74,6 +75,8 @@
|
||||
#include "ViewProviderSketchGeometryExtension.h"
|
||||
#include "Workbench.h"
|
||||
|
||||
#include <Mod/Part/Gui/SoFCShapeObject.h>
|
||||
|
||||
|
||||
// clang-format off
|
||||
FC_LOG_LEVEL_INIT("Sketch", true, true)
|
||||
@@ -150,6 +153,20 @@ void ViewProviderSketch::ParameterObserver::updateColorProperty(const std::strin
|
||||
colorprop->setValue(elementAppColor);
|
||||
}
|
||||
|
||||
void ViewProviderSketch::ParameterObserver::updateShapeAppearanceProperty(const std::string& string, App::Property* property)
|
||||
{
|
||||
auto matProp = static_cast<App::PropertyMaterialList*>(property);
|
||||
|
||||
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher/General");
|
||||
unsigned long shcol = hGrp->GetUnsigned(string.c_str(), 0x54abff40);
|
||||
float r = ((shcol >> 24) & 0xff) / 255.0;
|
||||
float g = ((shcol >> 16) & 0xff) / 255.0;
|
||||
float b = ((shcol >> 8) & 0xff) / 255.0;
|
||||
float a = (shcol & 0xff) / 255.0;
|
||||
matProp->setDiffuseColor(r, g, b);
|
||||
matProp->setTransparency(1 - a);
|
||||
}
|
||||
|
||||
void ViewProviderSketch::ParameterObserver::updateGridSize(const std::string& string,
|
||||
App::Property* property)
|
||||
{
|
||||
@@ -380,6 +397,13 @@ void ViewProviderSketch::ParameterObserver::initParameters()
|
||||
}
|
||||
},
|
||||
&Client.PointColor}},
|
||||
{"SketchFaceColor",
|
||||
{[this](const std::string& string, App::Property* property) {
|
||||
if (Client.AutoColor.getValue()) {
|
||||
updateShapeAppearanceProperty(string, property);
|
||||
}
|
||||
},
|
||||
&Client.ShapeAppearance}},
|
||||
};
|
||||
|
||||
for (auto& val : parameterMap) {
|
||||
@@ -463,7 +487,30 @@ QString ViewProviderSketch::ToolManager::getToolWidgetText() const
|
||||
}
|
||||
}
|
||||
|
||||
/*************************** SoSketchFaces **************************/
|
||||
|
||||
SO_NODE_SOURCE(SoSketchFaces);
|
||||
|
||||
SoSketchFaces::SoSketchFaces(){
|
||||
SO_NODE_CONSTRUCTOR(SoSketchFaces);
|
||||
|
||||
SO_NODE_ADD_FIELD(color, (SbColor(1.0f, 1.0f, 1.0f)));
|
||||
SO_NODE_ADD_FIELD(transparency, (0.8));
|
||||
//
|
||||
auto* material = new SoMaterial;
|
||||
material->diffuseColor.connectFrom(&color);
|
||||
material->transparency.connectFrom(&transparency);
|
||||
|
||||
SoSeparator::addChild(material);
|
||||
SoSeparator::addChild(coords);
|
||||
SoSeparator::addChild(norm);
|
||||
SoSeparator::addChild(faceset);
|
||||
}
|
||||
|
||||
void SoSketchFaces::initClass()
|
||||
{
|
||||
SO_NODE_INIT_CLASS(SoSketchFaces, SoFCShape, "FCShape");
|
||||
}
|
||||
|
||||
/*************************** ViewProviderSketch **************************/
|
||||
|
||||
@@ -477,7 +524,6 @@ SbVec2s ViewProviderSketch::DoubleClick::newCursorPos;
|
||||
// Construction/Destruction
|
||||
|
||||
/* TRANSLATOR SketcherGui::ViewProviderSketch */
|
||||
|
||||
PROPERTY_SOURCE_WITH_EXTENSIONS(SketcherGui::ViewProviderSketch, PartGui::ViewProvider2DObject)
|
||||
|
||||
|
||||
@@ -485,6 +531,8 @@ ViewProviderSketch::ViewProviderSketch()
|
||||
: SelectionObserver(false)
|
||||
, toolManager(this)
|
||||
, Mode(STATUS_NONE)
|
||||
, pcSketchFaces(new SoSketchFaces)
|
||||
, pcSketchFacesToggle(new SoToggleSwitch)
|
||||
, listener(nullptr)
|
||||
, editCoinManager(nullptr)
|
||||
, snapManager(nullptr)
|
||||
@@ -588,6 +636,10 @@ ViewProviderSketch::ViewProviderSketch()
|
||||
rubberband = std::make_unique<Gui::Rubberband>();
|
||||
|
||||
cameraSensor.setFunction(&ViewProviderSketch::camSensCB);
|
||||
|
||||
updateColorPropertiesVisibility();
|
||||
|
||||
pcSketchFacesToggle->addChild(pcSketchFaces);
|
||||
}
|
||||
|
||||
ViewProviderSketch::~ViewProviderSketch()
|
||||
@@ -2895,10 +2947,22 @@ void ViewProviderSketch::drawEditMarkers(const std::vector<Base::Vector2d>& Edit
|
||||
}
|
||||
|
||||
void ViewProviderSketch::updateData(const App::Property* prop) {
|
||||
ViewProvider2DObject::updateData(prop);
|
||||
if (std::string(prop->getName()) != "ShapeMaterial") {
|
||||
// We don't want material to override the colors of sketches.
|
||||
ViewProvider2DObject::updateData(prop);
|
||||
}
|
||||
|
||||
if (prop != &getSketchObject()->Constraints)
|
||||
if (prop == &getSketchObject()->InternalShape) {
|
||||
const auto& shape = getSketchObject()->InternalShape.getValue();
|
||||
setupCoinGeometry(shape,
|
||||
pcSketchFaces,
|
||||
Deviation.getValue(),
|
||||
AngularDeflection.getValue());
|
||||
}
|
||||
|
||||
if (prop != &getSketchObject()->Constraints) {
|
||||
signalElementsChanged();
|
||||
}
|
||||
}
|
||||
|
||||
void ViewProviderSketch::slotSolverUpdate()
|
||||
@@ -2931,6 +2995,8 @@ void ViewProviderSketch::slotSolverUpdate()
|
||||
|
||||
void ViewProviderSketch::onChanged(const App::Property* prop)
|
||||
{
|
||||
ViewProvider2DObject::onChanged(prop);
|
||||
|
||||
if (prop == &VisualLayerList) {
|
||||
if (isInEditMode()) {
|
||||
// Configure and rebuild Coin SceneGraph
|
||||
@@ -2940,23 +3006,38 @@ void ViewProviderSketch::onChanged(const App::Property* prop)
|
||||
}
|
||||
|
||||
if (prop == &AutoColor) {
|
||||
auto usesAutomaticColors = AutoColor.getValue();
|
||||
|
||||
// when auto color is enabled don't save color information in the document
|
||||
// so it does not cause unnecessary updates if multiple users use different colors
|
||||
LineColor.setStatus(App::Property::Transient, usesAutomaticColors);
|
||||
PointColor.setStatus(App::Property::Transient, usesAutomaticColors);
|
||||
|
||||
// and mark this property as read-only hidden so it's not possible to change manually
|
||||
LineColor.setStatus(App::Property::ReadOnly, usesAutomaticColors);
|
||||
LineColor.setStatus(App::Property::Hidden, usesAutomaticColors);
|
||||
PointColor.setStatus(App::Property::ReadOnly, usesAutomaticColors);
|
||||
PointColor.setStatus(App::Property::Hidden, usesAutomaticColors);
|
||||
|
||||
updateColorPropertiesVisibility();
|
||||
return;
|
||||
}
|
||||
|
||||
ViewProvider2DObject::onChanged(prop);
|
||||
if (prop == &Visibility) {
|
||||
pcSketchFacesToggle->on = Visibility.getValue();
|
||||
return;
|
||||
}
|
||||
|
||||
if (prop == &ShapeAppearance) {
|
||||
pcSketchFaces->color.setValue(Base::convertTo<SbColor>(ShapeAppearance.getDiffuseColor()));
|
||||
pcSketchFaces->transparency.setValue(ShapeAppearance.getTransparency());
|
||||
}
|
||||
}
|
||||
|
||||
void SketcherGui::ViewProviderSketch::updateColorPropertiesVisibility()
|
||||
{
|
||||
auto usesAutomaticColors = AutoColor.getValue();
|
||||
|
||||
// when auto color is enabled don't save color information in the document
|
||||
// so it does not cause unnecessary updates if multiple users use different colors
|
||||
LineColor.setStatus(App::Property::Transient, usesAutomaticColors);
|
||||
PointColor.setStatus(App::Property::Transient, usesAutomaticColors);
|
||||
ShapeAppearance.setStatus(App::Property::Transient, usesAutomaticColors);
|
||||
|
||||
// and mark this property as read-only hidden so it's not possible to change manually
|
||||
LineColor.setStatus(App::Property::ReadOnly, usesAutomaticColors);
|
||||
LineColor.setStatus(App::Property::Hidden, usesAutomaticColors);
|
||||
PointColor.setStatus(App::Property::ReadOnly, usesAutomaticColors);
|
||||
PointColor.setStatus(App::Property::Hidden, usesAutomaticColors);
|
||||
ShapeAppearance.setStatus(App::Property::ReadOnly, usesAutomaticColors);
|
||||
ShapeAppearance.setStatus(App::Property::Hidden, usesAutomaticColors);
|
||||
}
|
||||
|
||||
void SketcherGui::ViewProviderSketch::startRestoring()
|
||||
@@ -2987,12 +3068,74 @@ void SketcherGui::ViewProviderSketch::finishRestoring()
|
||||
// update colors according to current user preferences
|
||||
pObserver->updateFromParameter("SketchEdgeColor");
|
||||
pObserver->updateFromParameter("SketchVertexColor");
|
||||
pObserver->updateFromParameter("SketchFaceColor");
|
||||
|
||||
updateColorPropertiesVisibility();
|
||||
}
|
||||
|
||||
if (getSketchObject()->MakeInternals.getValue()) {
|
||||
updateVisual();
|
||||
}
|
||||
}
|
||||
|
||||
// clang-format on
|
||||
bool ViewProviderSketch::getElementPicked(const SoPickedPoint* pp, std::string& subname) const
|
||||
{
|
||||
if (pp->getPath()->containsNode(pcSketchFaces) && !isInEditMode()) {
|
||||
if (ViewProvider2DObject::getElementPicked(pp, subname)) {
|
||||
subname = SketchObject::internalPrefix() + subname;
|
||||
auto& elementMap = getSketchObject()->getInternalElementMap();
|
||||
|
||||
if (auto it = elementMap.find(subname); it != elementMap.end()) {
|
||||
subname = it->second;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return ViewProvider2DObject::getElementPicked(pp, subname);
|
||||
}
|
||||
|
||||
bool ViewProviderSketch::getDetailPath(const char* subname,
|
||||
SoFullPath* pPath,
|
||||
bool append,
|
||||
SoDetail*& det) const
|
||||
{
|
||||
const auto getLastPartOfName = [](const char* subname) -> const char* {
|
||||
const char* realName = strrchr(subname, '.');
|
||||
|
||||
return realName ? realName + 1 : subname;
|
||||
};
|
||||
|
||||
if (!isInEditMode() && subname) {
|
||||
const char* realName = getLastPartOfName(subname);
|
||||
|
||||
realName = SketchObject::convertInternalName(realName);
|
||||
if (realName) {
|
||||
auto len = pPath->getLength();
|
||||
if (append) {
|
||||
pPath->append(pcRoot);
|
||||
pPath->append(pcModeSwitch);
|
||||
}
|
||||
|
||||
if (!ViewProvider2DObject::getDetailPath(realName, pPath, false, det)) {
|
||||
pPath->truncate(len);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return ViewProvider2DObject::getDetailPath(subname, pPath, append, det);
|
||||
}
|
||||
// clang-format off
|
||||
|
||||
void ViewProviderSketch::attach(App::DocumentObject* pcFeat)
|
||||
{
|
||||
ViewProvider2DObject::attach(pcFeat);
|
||||
|
||||
getAnnotation()->addChild(pcSketchFacesToggle);
|
||||
}
|
||||
|
||||
void ViewProviderSketch::setupContextMenu(QMenu* menu, QObject* receiver, const char* member)
|
||||
|
||||
Reference in New Issue
Block a user