Apply fix from mrlukeparry for datum labels
This commit is contained in:
parent
6d3659bda2
commit
2e31e177a8
|
@ -1,5 +1,5 @@
|
|||
/***************************************************************************
|
||||
* Copyright (c) 2011-2012 Luke Parry <l.parry@warwick.ac.uk> *
|
||||
* Copyright (c) 2011-2012 Luke Parry <l.parry@warwick.ac.uk> *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
|
@ -44,7 +44,6 @@
|
|||
# include <Inventor/misc/SoState.h>
|
||||
# include <math.h>
|
||||
#endif
|
||||
|
||||
#include <Inventor/actions/SoGetMatrixAction.h>
|
||||
#include <Inventor/elements/SoFontNameElement.h>
|
||||
#include <Inventor/elements/SoFontSizeElement.h>
|
||||
|
@ -75,6 +74,7 @@ SoDatumLabel::SoDatumLabel()
|
|||
SO_NODE_ADD_FIELD(string, (""));
|
||||
SO_NODE_ADD_FIELD(textColor, (SbVec3f(1.0f,1.0f,1.0f)));
|
||||
SO_NODE_ADD_FIELD(pnts, (SbVec3f(.0f,.0f,.0f)));
|
||||
SO_NODE_ADD_FIELD(norm, (SbVec3f(.0f,.0f,1.f)));
|
||||
|
||||
SO_NODE_ADD_FIELD(name, ("Helvetica"));
|
||||
SO_NODE_ADD_FIELD(size, (12.f));
|
||||
|
@ -88,7 +88,7 @@ SoDatumLabel::SoDatumLabel()
|
|||
SO_NODE_DEFINE_ENUM_VALUE(Type, ANGLE);
|
||||
SO_NODE_DEFINE_ENUM_VALUE(Type, RADIUS);
|
||||
SO_NODE_SET_SF_ENUM_TYPE(datumtype, Type);
|
||||
|
||||
|
||||
SO_NODE_ADD_FIELD(param1, (0.f));
|
||||
SO_NODE_ADD_FIELD(param2, (0.f));
|
||||
|
||||
|
@ -123,7 +123,7 @@ void SoDatumLabel::drawImage()
|
|||
|
||||
QImage image(w, h,QImage::Format_ARGB32_Premultiplied);
|
||||
image.fill(0x00000000);
|
||||
|
||||
|
||||
QPainter painter(&image);
|
||||
painter.setRenderHint(QPainter::Antialiasing);
|
||||
|
||||
|
@ -191,7 +191,7 @@ void SoDatumLabel::generatePrimitives(SoAction * action)
|
|||
float c = cos(angle);
|
||||
|
||||
img1 = SbVec3f((img1[0] * c) - (img1[1] * s), (img1[0] * s) + (img1[1] * c), 0.f);
|
||||
img2 = SbVec3f((img2[0] * c) - (img2[1] * s), (img2[0] * s) + (img2[1] * c), 0.f);
|
||||
img2 = SbVec3f((img2[0] * c) - (img2[1] * s), (img2[0] * s) + (img2[1] * c), 0.f);
|
||||
img3 = SbVec3f((img3[0] * c) - (img3[1] * s), (img3[0] * s) + (img3[1] * c), 0.f);
|
||||
img4 = SbVec3f((img4[0] * c) - (img4[1] * s), (img4[0] * s) + (img4[1] * c), 0.f);
|
||||
|
||||
|
@ -589,7 +589,7 @@ void SoDatumLabel::GLRender(SoGLRenderAction * action)
|
|||
// Get the Points
|
||||
SbVec3f p1 = pnts[0];
|
||||
SbVec3f p2 = pnts[1];
|
||||
|
||||
|
||||
SbVec3f dir = (p2-p1);
|
||||
dir.normalize();
|
||||
SbVec3f norm (-dir[1],dir[0],0);
|
||||
|
@ -668,7 +668,7 @@ void SoDatumLabel::GLRender(SoGLRenderAction * action)
|
|||
float range = this->param3.getValue();
|
||||
float endangle = startangle + range;
|
||||
|
||||
|
||||
|
||||
float r = 2*length;
|
||||
|
||||
// Set the Text label angle to zero
|
||||
|
@ -813,7 +813,7 @@ void SoDatumLabel::GLRender(SoGLRenderAction * action)
|
|||
std::vector<SbVec3f> corners;
|
||||
corners.push_back(p1);
|
||||
corners.push_back(p2);
|
||||
|
||||
|
||||
float minX = p1[0], minY = p1[1], maxX = p1[0] , maxY = p1[1];
|
||||
for (std::vector<SbVec3f>::iterator it=corners.begin(); it != corners.end(); ++it) {
|
||||
minX = ((*it)[0] < minX) ? (*it)[0] : minX;
|
||||
|
@ -829,18 +829,10 @@ void SoDatumLabel::GLRender(SoGLRenderAction * action)
|
|||
|
||||
const unsigned char * dataptr = this->image.getValue(size, nc);
|
||||
|
||||
SbVec3f surfNorm(0.f, 0.f, 1.f) ;
|
||||
//Get the camera z-direction
|
||||
SbVec3f z = vv.zVector();
|
||||
const SbViewportRegion & vpr = SoViewportRegionElement::get(state);
|
||||
|
||||
SoGetMatrixAction getmatrixaction(vpr);
|
||||
getmatrixaction.apply(action);
|
||||
|
||||
SbMatrix transform = getmatrixaction.getMatrix();
|
||||
transform.multVecMatrix(surfNorm, surfNorm);
|
||||
|
||||
bool flip = surfNorm.dot(z) > FLT_EPSILON;
|
||||
bool flip = norm.getValue().dot(z) > FLT_EPSILON;
|
||||
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glEnable(GL_TEXTURE_2D); // Enable Textures
|
||||
|
@ -850,7 +842,7 @@ void SoDatumLabel::GLRender(SoGLRenderAction * action)
|
|||
// deleting the texture. I guess we don't need this texture and thus
|
||||
// comment out the block.
|
||||
// #0000721: massive memory leak when dragging an unconstrained model
|
||||
//
|
||||
//
|
||||
#if 0
|
||||
// Copy the text bitmap into memory and bind
|
||||
GLuint myTexture;
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
#include <Inventor/fields/SoSFName.h>
|
||||
#include <Inventor/fields/SoMFString.h>
|
||||
#include <Inventor/fields/SoSFInt32.h>
|
||||
#include <Inventor/fields/SoSFVec3f.h>
|
||||
#include <Inventor/fields/SoMFVec3f.h>
|
||||
#include <Inventor/SbBox3f.h>
|
||||
#include <Inventor/fields/SoSFImage.h>
|
||||
|
@ -67,6 +68,7 @@ public:
|
|||
SoSFFloat param2;
|
||||
SoSFFloat param3;
|
||||
SoMFVec3f pnts;
|
||||
SoSFVec3f norm;
|
||||
SoSFImage image;
|
||||
SoSFFloat lineWidth;
|
||||
|
||||
|
|
|
@ -1041,11 +1041,11 @@ void ViewProviderSketch::moveConstraint(int constNum, const Base::Vector2D &toPo
|
|||
} else {
|
||||
Base::Vector3d norm(-dir.y,dir.x,0);
|
||||
Constr->LabelDistance = vec.x * norm.x + vec.y * norm.y;
|
||||
if (Constr->Type == Distance ||
|
||||
Constr->Type == DistanceX || Constr->Type == DistanceY) {
|
||||
if (Constr->Type == Distance ||
|
||||
Constr->Type == DistanceX || Constr->Type == DistanceY) {
|
||||
vec = Base::Vector3d(toPos.fX, toPos.fY, 0) - (p2 + p1) / 2;
|
||||
Constr->LabelPosition = vec.x * dir.x + vec.y * dir.y;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (Constr->Type == Angle) {
|
||||
|
@ -1743,7 +1743,7 @@ void ViewProviderSketch::updateColor(void)
|
|||
type == Sketcher::Distance ||
|
||||
type == Sketcher::DistanceX || type == Sketcher::DistanceY);
|
||||
|
||||
// Non DatumLabel Nodes will have a material excluding coincident
|
||||
// Non DatumLabel Nodes will have a material excluding coincident
|
||||
bool hasMaterial = false;
|
||||
|
||||
SoMaterial *m;
|
||||
|
@ -1756,7 +1756,7 @@ void ViewProviderSketch::updateColor(void)
|
|||
if (hasDatumLabel) {
|
||||
SoDatumLabel *l = dynamic_cast<SoDatumLabel *>(s->getChild(0));
|
||||
l->textColor = SelectColor;
|
||||
} else if (hasMaterial)
|
||||
} else if (hasMaterial)
|
||||
m->diffuseColor = SelectColor;
|
||||
} else if (edit->PreselectConstraint == i) {
|
||||
if (hasDatumLabel) {
|
||||
|
@ -2695,6 +2695,16 @@ void ViewProviderSketch::rebuildConstraintsVisual(void)
|
|||
SoMaterial *mat = new SoMaterial;
|
||||
mat->ref();
|
||||
mat->diffuseColor = ConstrDimColor;
|
||||
// Get sketch normal
|
||||
Base::Vector3d RN(0,0,1);
|
||||
|
||||
// move to position of Sketch
|
||||
Base::Placement Plz = getSketchObject()->Placement.getValue();
|
||||
Base::Rotation tmp(Plz.getRotation());
|
||||
tmp.multVec(RN,RN);
|
||||
Plz.setRotation(tmp);
|
||||
|
||||
SbVec3f norm(RN.x, RN.y, RN.z);
|
||||
|
||||
// distinguish different constraint types to build up
|
||||
switch ((*it)->Type) {
|
||||
|
@ -2703,85 +2713,87 @@ void ViewProviderSketch::rebuildConstraintsVisual(void)
|
|||
case DistanceY:
|
||||
case Radius:
|
||||
case Angle:
|
||||
{
|
||||
SoDatumLabel *text = new SoDatumLabel();
|
||||
text->string = "";
|
||||
text->textColor = ConstrDimColor;
|
||||
SoAnnotation *anno = new SoAnnotation();
|
||||
anno->renderCaching = SoSeparator::OFF;
|
||||
anno->addChild(text);
|
||||
sep->addChild(text);
|
||||
edit->constrGroup->addChild(anno);
|
||||
edit->vConstrType.push_back((*it)->Type);
|
||||
// nodes not needed
|
||||
sep->unref();
|
||||
mat->unref();
|
||||
continue; // jump to next constraint
|
||||
}
|
||||
break;
|
||||
{
|
||||
SoDatumLabel *text = new SoDatumLabel();
|
||||
text->norm.setValue(norm);
|
||||
text->string = "";
|
||||
text->textColor = ConstrDimColor;
|
||||
SoAnnotation *anno = new SoAnnotation();
|
||||
anno->renderCaching = SoSeparator::OFF;
|
||||
anno->addChild(text);
|
||||
sep->addChild(text);
|
||||
edit->constrGroup->addChild(anno);
|
||||
edit->vConstrType.push_back((*it)->Type);
|
||||
// nodes not needed
|
||||
sep->unref();
|
||||
mat->unref();
|
||||
continue; // jump to next constraint
|
||||
}
|
||||
break;
|
||||
case Horizontal:
|
||||
case Vertical:
|
||||
{
|
||||
sep->addChild(mat);
|
||||
sep->addChild(new SoZoomTranslation()); // 1.
|
||||
sep->addChild(new SoImage()); // 2. constraint icon
|
||||
{
|
||||
sep->addChild(mat);
|
||||
sep->addChild(new SoZoomTranslation()); // 1.
|
||||
sep->addChild(new SoImage()); // 2. constraint icon
|
||||
|
||||
// remember the type of this constraint node
|
||||
edit->vConstrType.push_back((*it)->Type);
|
||||
}
|
||||
break;
|
||||
// remember the type of this constraint node
|
||||
edit->vConstrType.push_back((*it)->Type);
|
||||
}
|
||||
break;
|
||||
case Coincident: // no visual for coincident so far
|
||||
edit->vConstrType.push_back(Coincident);
|
||||
break;
|
||||
case Parallel:
|
||||
case Perpendicular:
|
||||
case Equal:
|
||||
{
|
||||
// Add new nodes to Constraint Seperator
|
||||
sep->addChild(mat);
|
||||
sep->addChild(new SoZoomTranslation()); // 1.
|
||||
sep->addChild(new SoImage()); // 2. first constraint icon
|
||||
sep->addChild(new SoZoomTranslation()); // 3.
|
||||
sep->addChild(new SoImage()); // 4. second constraint icon
|
||||
{
|
||||
// Add new nodes to Constraint Seperator
|
||||
sep->addChild(mat);
|
||||
sep->addChild(new SoZoomTranslation()); // 1.
|
||||
sep->addChild(new SoImage()); // 2. first constraint icon
|
||||
sep->addChild(new SoZoomTranslation()); // 3.
|
||||
sep->addChild(new SoImage()); // 4. second constraint icon
|
||||
|
||||
// remember the type of this constraint node
|
||||
edit->vConstrType.push_back((*it)->Type);
|
||||
}
|
||||
break;
|
||||
// remember the type of this constraint node
|
||||
edit->vConstrType.push_back((*it)->Type);
|
||||
}
|
||||
break;
|
||||
case PointOnObject:
|
||||
case Tangent:
|
||||
{
|
||||
// Add new nodes to Constraint Seperator
|
||||
sep->addChild(mat);
|
||||
sep->addChild(new SoZoomTranslation()); // 1.
|
||||
sep->addChild(new SoImage()); // 2. constraint icon
|
||||
{
|
||||
// Add new nodes to Constraint Seperator
|
||||
sep->addChild(mat);
|
||||
sep->addChild(new SoZoomTranslation()); // 1.
|
||||
sep->addChild(new SoImage()); // 2. constraint icon
|
||||
|
||||
if ((*it)->Type == Tangent) {
|
||||
const Part::Geometry *geo1 = getSketchObject()->getGeometry((*it)->First);
|
||||
const Part::Geometry *geo2 = getSketchObject()->getGeometry((*it)->Second);
|
||||
if (geo1->getTypeId() == Part::GeomLineSegment::getClassTypeId() &&
|
||||
geo2->getTypeId() == Part::GeomLineSegment::getClassTypeId()) {
|
||||
sep->addChild(new SoZoomTranslation());
|
||||
sep->addChild(new SoImage()); // 3. second constraint icon
|
||||
if ((*it)->Type == Tangent) {
|
||||
const Part::Geometry *geo1 = getSketchObject()->getGeometry((*it)->First);
|
||||
const Part::Geometry *geo2 = getSketchObject()->getGeometry((*it)->Second);
|
||||
if (geo1->getTypeId() == Part::GeomLineSegment::getClassTypeId() &&
|
||||
geo2->getTypeId() == Part::GeomLineSegment::getClassTypeId()) {
|
||||
sep->addChild(new SoZoomTranslation());
|
||||
sep->addChild(new SoImage()); // 3. second constraint icon
|
||||
}
|
||||
}
|
||||
|
||||
edit->vConstrType.push_back((*it)->Type);
|
||||
}
|
||||
break;
|
||||
|
||||
edit->vConstrType.push_back((*it)->Type);
|
||||
}
|
||||
break;
|
||||
case Symmetric:
|
||||
{
|
||||
SoDatumLabel *arrows = new SoDatumLabel();
|
||||
arrows->string = "";
|
||||
arrows->textColor = ConstrDimColor;
|
||||
{
|
||||
SoDatumLabel *arrows = new SoDatumLabel();
|
||||
arrows->norm.setValue(norm);
|
||||
arrows->string = "";
|
||||
arrows->textColor = ConstrDimColor;
|
||||
|
||||
sep->addChild(arrows); // 0.
|
||||
sep->addChild(new SoTranslation()); // 1.
|
||||
sep->addChild(new SoImage()); // 2. constraint icon
|
||||
sep->addChild(arrows); // 0.
|
||||
sep->addChild(new SoTranslation()); // 1.
|
||||
sep->addChild(new SoImage()); // 2. constraint icon
|
||||
|
||||
edit->vConstrType.push_back((*it)->Type);
|
||||
}
|
||||
break;
|
||||
edit->vConstrType.push_back((*it)->Type);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
edit->vConstrType.push_back(None);
|
||||
}
|
||||
|
@ -3195,7 +3207,7 @@ void ViewProviderSketch::setPositionText(const Base::Vector2D &Pos, const SbStri
|
|||
edit->textX->string = text;
|
||||
edit->textPos->translation = SbVec3f(Pos.fX,Pos.fY,zText);
|
||||
}
|
||||
|
||||
|
||||
void ViewProviderSketch::setPositionText(const Base::Vector2D &Pos)
|
||||
{
|
||||
SbString text;
|
||||
|
|
Loading…
Reference in New Issue
Block a user