Skip to content

Commit

Permalink
Core: SoShapeScale fix weird scaling on viewport resize. See FreeCAD#…
Browse files Browse the repository at this point in the history
  • Loading branch information
PaddleStroke authored and wwmayer committed Dec 10, 2024
1 parent 20d64a7 commit 3969630
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 19 deletions.
14 changes: 8 additions & 6 deletions src/Gui/Inventor/SoAxisCrossKit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,24 +85,26 @@ SoShapeScale::initClass()
void
SoShapeScale::GLRender(SoGLRenderAction * action)
{
SoState * state = action->getState();

SoScale * scale = static_cast<SoScale*>(this->getAnyPart(SbName("scale"), true));
auto* scale = static_cast<SoScale*>(this->getAnyPart(SbName("scale"), true));
if (!this->active.getValue()) {
SbVec3f v(1.0f, 1.0f, 1.0f);
if (scale->scaleFactor.getValue() != v)
if (scale->scaleFactor.getValue() != v){
scale->scaleFactor = v;
}
}
else {
SoState* state = action->getState();
const SbViewportRegion & vp = SoViewportRegionElement::get(state);
const SbViewVolume & vv = SoViewVolumeElement::get(state);

SbVec3f center(0.0f, 0.0f, 0.0f);
float nsize = this->scaleFactor.getValue() / float(vp.getViewportSizePixels()[1]);
float nsize = this->scaleFactor.getValue() / float(vp.getViewportSizePixels()[0]);
SoModelMatrixElement::get(state).multVecMatrix(center, center); // world coords
float sf = vv.getWorldToScreenScale(center, nsize);
SbVec3f v(sf, sf, sf);
if (scale->scaleFactor.getValue() != v)
if (scale->scaleFactor.getValue() != v){
scale->scaleFactor = v;
}
}

inherited::GLRender(action);
Expand Down
7 changes: 3 additions & 4 deletions src/Gui/ViewProviderDatum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ void ViewProviderDatum::attach(App::DocumentObject* pcObject)
{
ViewProviderGeometryObject::attach(pcObject);

float defaultSz = ViewProviderCoordinateSystem::defaultSize();

// Create an external separator
auto sep = new SoSeparator();
Expand All @@ -93,8 +92,8 @@ void ViewProviderDatum::attach(App::DocumentObject* pcObject)

// Setup font size
auto font = new SoFont();
float fontRatio = 4.0f;
font->size.setValue(defaultSz / fontRatio);
static const float size = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/View")->GetFloat("DatumFontSize", 15.0);
font->size.setValue(size);
sep->addChild(font);

// Create the selection node
Expand Down Expand Up @@ -135,7 +134,7 @@ void ViewProviderDatum::attach(App::DocumentObject* pcObject)
// Scale feature to the given size
float sz = App::GetApplication()
.GetParameterGroupByPath("User parameter:BaseApp/Preferences/View")
->GetFloat("LocalCoordinateSystemSize", 2.0); // NOLINT
->GetFloat("LocalCoordinateSystemSize", 1.0); // NOLINT

soScale->setPart("shape", sep);
soScale->scaleFactor = sz;
Expand Down
2 changes: 1 addition & 1 deletion src/Gui/ViewProviderLine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ void ViewProviderLine::attach(App::DocumentObject *obj) {
noRole = true;
}

static const float size = ViewProviderCoordinateSystem::defaultSize();
static const float size = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/View")->GetFloat("DatumLineSize", 70.0);

SbVec3f verts[2];
if (noRole) {
Expand Down
2 changes: 1 addition & 1 deletion src/Gui/ViewProviderPlane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ void ViewProviderPlane::attach(App::DocumentObject * obj) {
noRole = true;
}

static const float size = ViewProviderCoordinateSystem::defaultSize() * 0.6; //NOLINT
static const float size = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/View")->GetFloat("DatumPlaneSize", 40.0);
static const float startSize = 0.25 * size; //NOLINT


Expand Down
3 changes: 2 additions & 1 deletion src/Gui/ViewProviderPoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ void ViewProviderPoint::attach(App::DocumentObject * obj) {
pCoords->point.setValue(point);
sep->addChild(pCoords);

static const float size = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/View")->GetFloat("DatumPointSize", 2.5);
auto sphere = new SoSphere();
sphere->radius.setValue(1.0);
sphere->radius.setValue(size);
sep->addChild(sphere);

// Add pick style to define how the point can be selected
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/Assembly/JointObject.py
Original file line number Diff line number Diff line change
Expand Up @@ -999,7 +999,7 @@ def attach(self, vobj):
if groundedObj is None:
return

self.scaleFactor = 1.5
self.scaleFactor = 3.0

lockpadColorInt = Preferences.preferences().GetUnsigned("AssemblyConstraints", 0xCC333300)
self.lockpadColor = coin.SoBaseColor()
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/Assembly/SoSwitchMarker.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def __init__(self, vobj):
super().__init__() # Initialize the SoSwitch base class

self.axis_thickness = 3
self.scaleFactor = 20
self.scaleFactor = 40

view_params = App.ParamGet("User parameter:BaseApp/Preferences/View")
param_x_axis_color = view_params.GetUnsigned("AxisXColor", 0xCC333300)
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/CAM/Gui/ViewProviderPath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ ViewProviderPath::ViewProviderPath()
pArrow->set("zAxis.appearance.drawStyle", "style INVISIBLE");
pArrow->set("zHead.transform", "translation 0 0 0");
pArrowScale->setPart("shape", pArrow);
pArrowScale->scaleFactor = 1.0f;
pArrowScale->scaleFactor = 2.0f;
pArrowGroup->addChild(pArrowScale);

pcArrowSwitch->addChild(pArrowGroup);
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/CAM/Path/Dressup/Gui/Tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ def __init__(self, point, colors):
self.sphere = coin.SoSphere()
self.scale = coin.SoType.fromName("SoShapeScale").createInstance()
self.scale.setPart("shape", self.sphere)
self.scale.scaleFactor.setValue(7)
self.scale.scaleFactor.setValue(14)
self.material = coin.SoMaterial()
self.sep.addChild(self.pos)
self.sep.addChild(self.material)
Expand Down
4 changes: 2 additions & 2 deletions src/Mod/CAM/Path/Main/Gui/Job.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def attach(self, vobj):

self.sca = coin.SoType.fromName("SoShapeScale").createInstance()
self.sca.setPart("shape", self.axs)
self.sca.scaleFactor.setValue(1) # Keep or adjust if needed
self.sca.scaleFactor.setValue(2) # Keep or adjust if needed

self.mat = coin.SoMaterial()
# Set sphere color to bright yellow
Expand All @@ -161,7 +161,7 @@ def attach(self, vobj):
self.scs = coin.SoType.fromName("SoShapeScale").createInstance()
self.scs.setPart("shape", self.sph)
# Increase the scaleFactor to make the sphere larger
self.scs.scaleFactor.setValue(10) # Adjust this value as needed
self.scs.scaleFactor.setValue(20) # Adjust this value as needed

self.sep.addChild(self.sca)
self.sep.addChild(self.mat)
Expand Down

0 comments on commit 3969630

Please sign in to comment.