From e41b372cbfe2bebbb432f6cee9e84a42b78766c8 Mon Sep 17 00:00:00 2001 From: Abdullah Tahiri Date: Sat, 23 Aug 2014 06:30:48 +0200 Subject: [PATCH 1/5] Sketcher feature enhancement: Symmetry constraint perpendicular to axis of symmetry Solves Mantis ticket: http://www.freecadweb.org/tracker/view.php?id=1623 Unrelated minor fix: remove unused variable --- src/Mod/Sketcher/Gui/ViewProviderSketch.cpp | 48 ++++++++++++++++++--- src/Mod/Sketcher/Gui/ViewProviderSketch.h | 4 ++ 2 files changed, 45 insertions(+), 7 deletions(-) diff --git a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp index ffb6f05863..a4d350642c 100644 --- a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp +++ b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp @@ -452,8 +452,6 @@ void ViewProviderSketch::getProjectingLine(const SbVec2s& pnt, const Gui::View3D if (!pCam) return; SbViewVolume vol = pCam->getViewVolume(); - float focalDist = pCam->focalDistance.getValue(); - vol.projectPointToLine(SbVec2f(pX,pY), line); } @@ -2266,6 +2264,32 @@ void ViewProviderSketch::drawConstraintIcons() thisIcon.position = absPos; thisIcon.destination = coinIconPtr; thisIcon.infoPtr = infoPtr; + + if((*it)->Type==Symmetric) { + + Base::Vector3d startingpoint = getSketchObject()->getPoint((*it)->First,(*it)->FirstPos); + Base::Vector3d endpoint = getSketchObject()->getPoint((*it)->Second,(*it)->SecondPos); + + double x0,y0,x1,y1; + SbVec3f pos0(startingpoint.x,startingpoint.y,startingpoint.z); + SbVec3f pos1(endpoint.x,endpoint.y,endpoint.z); + + Gui::MDIView *mdi = Gui::Application::Instance->activeDocument()->getActiveView(); + Gui::View3DInventorViewer *viewer = static_cast(mdi)->getViewer(); + SoCamera* pCam = viewer->getCamera(); + if (!pCam) return; + + SbViewVolume vol = pCam->getViewVolume(); + + getCoordsOnSketchPlane(x0,y0,pos0,vol.getProjectionDirection()); + getCoordsOnSketchPlane(x1,y1,pos1,vol.getProjectionDirection()); + + thisIcon.iconRotation = -atan2f((y1-y0),(x1-x0))*180/M_PI; + + } + else { + thisIcon.iconRotation = 0; + } if(multipleIcons) { if((*it)->Name.empty()) @@ -2373,6 +2397,7 @@ void ViewProviderSketch::drawMergedConstraintIcons(IconQueue iconQueue) QColor iconColor; QList labelColors; int maxColorPriority; + double iconRotation; ConstrIconBBVec boundingBoxes; while(!iconQueue.empty()) { @@ -2388,6 +2413,7 @@ void ViewProviderSketch::drawMergedConstraintIcons(IconQueue iconQueue) iconColor = constrColor(i->constraintId); labelColors.clear(); labelColors.append(iconColor); + iconRotation= i->iconRotation; maxColorPriority = constrColorPriority(i->constraintId); @@ -2439,6 +2465,7 @@ void ViewProviderSketch::drawMergedConstraintIcons(IconQueue iconQueue) iconColor, labels, labelColors, + iconRotation, &boundingBoxesVec, &lastVPad); } else { @@ -2447,6 +2474,7 @@ void ViewProviderSketch::drawMergedConstraintIcons(IconQueue iconQueue) iconColor, labels, labelColors, + iconRotation, &boundingBoxesVec, &thisVPad); @@ -2507,6 +2535,7 @@ QImage ViewProviderSketch::renderConstrIcon(const QString &type, const QColor &iconColor, const QStringList &labels, const QList &labelColors, + double iconRotation, std::vector *boundingBoxes, int *vPad) { @@ -2527,17 +2556,21 @@ QImage ViewProviderSketch::renderConstrIcon(const QString &type, if(vPad) *vPad = pxBelowBase; - QImage image = icon.copy(0, 0, icon.width() + labelWidth, - icon.height() + pxBelowBase); + QTransform rotation; + rotation.rotate(iconRotation); + + QImage roticon = icon.transformed(rotation); + QImage image = roticon.copy(0, 0, roticon.width() + labelWidth, + roticon.height() + pxBelowBase); // Make a bounding box for the icon if(boundingBoxes) - boundingBoxes->push_back(QRect(0, 0, icon.width(), icon.height())); + boundingBoxes->push_back(QRect(0, 0, roticon.width(), roticon.height())); // Render the Icons QPainter qp(&image); qp.setCompositionMode(QPainter::CompositionMode_SourceIn); - qp.fillRect(icon.rect(), iconColor); + qp.fillRect(roticon.rect(), iconColor); // Render constraint label if necessary if (!labels.join(QString()).isEmpty()) { @@ -2589,7 +2622,8 @@ void ViewProviderSketch::drawTypicalConstraintIcon(const constrIconQueueItem &i) QImage image = renderConstrIcon(i.type, color, QStringList(i.label), - QList() << color); + QList() << color, + i.iconRotation); i.infoPtr->string.setValue(QString::number(i.constraintId).toAscii().data()); sendConstraintIconToCoin(image, i.destination); diff --git a/src/Mod/Sketcher/Gui/ViewProviderSketch.h b/src/Mod/Sketcher/Gui/ViewProviderSketch.h index 46969b44ff..a3237647dd 100644 --- a/src/Mod/Sketcher/Gui/ViewProviderSketch.h +++ b/src/Mod/Sketcher/Gui/ViewProviderSketch.h @@ -282,6 +282,9 @@ protected: /// Pointer to SoInfo object where we store the constraint IDs that the icon refers to SoInfo *infoPtr; + + /// Angle to rotate an icon + double iconRotation; }; /// Internal type used for drawing constraint icons @@ -304,6 +307,7 @@ protected: const QColor &iconColor, const QStringList &labels, const QList &labelColors, + double iconRotation, //! Gets populated with bounding boxes (in icon //! image coordinates) for the icon at left, then //! labels for different constraints. From 411dbd8ae6f25e025032b061d4cad0ad7d4658c5 Mon Sep 17 00:00:00 2001 From: Abdullah Tahiri Date: Sun, 24 Aug 2014 09:12:11 +0200 Subject: [PATCH 2/5] Sketcher visualization enhancement: Do not group sketcher symmetry icons. Do not add a symmetry constraint icon to a group of icons, so that it lies on the line or point providing the symmetry (symmetry axis/point), as it is more clear to the user which line this is. --- src/Mod/Sketcher/Gui/ViewProviderSketch.cpp | 62 ++++++++++++--------- src/Mod/Sketcher/Gui/ViewProviderSketch.h | 1 - 2 files changed, 35 insertions(+), 28 deletions(-) diff --git a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp index a4d350642c..e7cc851987 100644 --- a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp +++ b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp @@ -2265,6 +2265,7 @@ void ViewProviderSketch::drawConstraintIcons() thisIcon.destination = coinIconPtr; thisIcon.infoPtr = infoPtr; + if((*it)->Type==Symmetric) { Base::Vector3d startingpoint = getSketchObject()->getPoint((*it)->First,(*it)->FirstPos); @@ -2337,39 +2338,46 @@ void ViewProviderSketch::combineConstraintIcons(IconQueue iconQueue) // A group starts with an item popped off the back of our initial queue IconQueue thisGroup; thisGroup.push_back(iconQueue.back()); + ViewProviderSketch::constrIconQueueItem init = iconQueue.back(); iconQueue.pop_back(); + + // we group only icons not being Symmetry icons, because we want those on the line + if(init.type != QString::fromLatin1("small/Constraint_Symmetric_sm")){ + + IconQueue::iterator i = iconQueue.begin(); + while(i != iconQueue.end()) { + bool addedToGroup = false; + + for(IconQueue::iterator j = thisGroup.begin(); + j != thisGroup.end(); ++j) + if(i->position.equals(j->position, maxDistSquared) && (*i).type != QString::fromLatin1("small/Constraint_Symmetric_sm")) { + // Found an icon in iconQueue that's close enough to + // a member of thisGroup, so move it into thisGroup + thisGroup.push_back(*i); + i = iconQueue.erase(i); + addedToGroup = true; + break; + } - IconQueue::iterator i = iconQueue.begin(); - while(i != iconQueue.end()) { - bool addedToGroup = false; - - for(IconQueue::iterator j = thisGroup.begin(); - j != thisGroup.end(); ++j) - if(i->position.equals(j->position, maxDistSquared)) { - // Found an icon in iconQueue that's close enough to - // a member of thisGroup, so move it into thisGroup - thisGroup.push_back(*i); - i = iconQueue.erase(i); - addedToGroup = true; - break; - } - - if(addedToGroup) { - if(i == iconQueue.end()) - // We just got the last icon out of iconQueue - break; - else - // Start looking through the iconQueue again, in case - // we have an icon that's now close enough to thisGroup - i = iconQueue.begin(); - } else - ++i; + if(addedToGroup) { + if(i == iconQueue.end()) + // We just got the last icon out of iconQueue + break; + else + // Start looking through the iconQueue again, in case + // we have an icon that's now close enough to thisGroup + i = iconQueue.begin(); + } else + ++i; + } } - if(thisGroup.size() == 1) + if(thisGroup.size() == 1) { drawTypicalConstraintIcon(thisGroup[0]); - else + } + else { drawMergedConstraintIcons(thisGroup); + } } } diff --git a/src/Mod/Sketcher/Gui/ViewProviderSketch.h b/src/Mod/Sketcher/Gui/ViewProviderSketch.h index a3237647dd..2491197386 100644 --- a/src/Mod/Sketcher/Gui/ViewProviderSketch.h +++ b/src/Mod/Sketcher/Gui/ViewProviderSketch.h @@ -32,7 +32,6 @@ #include #include - class TopoDS_Shape; class TopoDS_Face; class SoSeparator; From cea93fa33c3eb422929d4f9c380c7a62e2bb65a9 Mon Sep 17 00:00:00 2001 From: Abdullah Tahiri Date: Wed, 27 Aug 2014 14:58:35 +0200 Subject: [PATCH 3/5] Sketcher Bug fix: Arrows for symmetry constraint are back The arrows were there in the code, but at a certain point, code was written to set the this->imgHeight value programatically, based on whether it had text or not. As symmetry constraint does not have text the variable failed to initialize. Being zero, it did not pass the ASSERT in the render function, so it was not rendered. This includes Werner's fix for improver cast of a SoRayPickAction to SoGLRenderAction: SbVec2s vp_size = static_cast(action)->getViewportRegion().getWindowSize(); to SbVec2s vp_size = SoViewportRegionElement::get(state).getWindowSize(); At least sometimes tt is a SoRayPickAction because: When you move with the mouse over the sketcher (when in edit mode) you enter the method ViewProviderSketch::mouseMove. Inside there the method getPointOnRay is called to get a picked point underneath the cursor. Inside the latter method an instance of SoRayPickAction is created to traverse the scene graph. After a long cascade of function calls you finally enter SoDatumLabel::generatePrimitives(SoAction*). --- src/Mod/Sketcher/Gui/SoDatumLabel.cpp | 12 ++++++++++-- src/Mod/Sketcher/Gui/ViewProviderSketch.cpp | 4 +++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/Mod/Sketcher/Gui/SoDatumLabel.cpp b/src/Mod/Sketcher/Gui/SoDatumLabel.cpp index 86bdfc20db..442e674af8 100644 --- a/src/Mod/Sketcher/Gui/SoDatumLabel.cpp +++ b/src/Mod/Sketcher/Gui/SoDatumLabel.cpp @@ -338,8 +338,8 @@ void SoDatumLabel::generatePrimitives(SoAction * action) SoState *state = action->getState(); const SbViewVolume & vv = SoViewVolumeElement::get(state); float scale = vv.getWorldToScreenScale(SbVec3f(0.f,0.f,0.f), 1.0f); - SbVec2s vp_size = static_cast(action)->getViewportRegion().getWindowSize(); - scale /= float(vp_size[0]); + SbVec2s vp_size = SoViewportRegionElement::get(state).getWindowSize(); + scale /= float(vp_size[0]); SbVec3f dir = (p2-p1); dir.normalize(); @@ -458,6 +458,14 @@ void SoDatumLabel::GLRender(SoGLRenderAction * action) this->imgHeight = scale * (float) (srch); this->imgWidth = aspectRatio * (float) this->imgHeight; } + + if (this->datumtype.getValue() == SYMMETRIC) { + // For the symmetry constraint that does not have text, but does have arrows + //this->imgHeight = 3.36f; + //this->imgWidth = 5.26f; + this->imgHeight = 1.5f; + this->imgWidth = 1.5f; + } // Get the points stored in the pnt field const SbVec3f *pnts = this->pnts.getValues(0); diff --git a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp index e7cc851987..3dd10d8311 100644 --- a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp +++ b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp @@ -1483,7 +1483,9 @@ std::set ViewProviderSketch::detectPreselectionConstr(const SoPickedPoint * } else { // Assume second icon was hit - constrIds = static_cast(sep->getChild(CONSTRAINT_SEPARATOR_INDEX_SECOND_CONSTRAINTID)); + if(CONSTRAINT_SEPARATOR_INDEX_SECOND_CONSTRAINTIDgetNumChildren()){ + constrIds = static_cast(sep->getChild(CONSTRAINT_SEPARATOR_INDEX_SECOND_CONSTRAINTID)); + } } if(constrIds) { QString constrIdsStr = QString::fromAscii(constrIds->string.getValue().getString()); From b3f0c4652decd35705874c9e1c1aa0560181de59 Mon Sep 17 00:00:00 2001 From: Abdullah Tahiri Date: Wed, 27 Aug 2014 15:11:33 +0200 Subject: [PATCH 4/5] Sketcher Art enhancement: New Symmetric constraint icon by Jim There is more space in between the > < symbols now, so it is more clear as it overlaps less. Thanks Jim! --- src/Mod/Sketcher/Gui/Resources/Sketcher.qrc | 1 + .../Resources/icons/Constraint_Symmetric.svg | 26 +++++++++------- .../icons/small/Constraint_Symmetric_sm.xpm | 30 ++++++++++--------- 3 files changed, 33 insertions(+), 24 deletions(-) diff --git a/src/Mod/Sketcher/Gui/Resources/Sketcher.qrc b/src/Mod/Sketcher/Gui/Resources/Sketcher.qrc index 38a9462fdf..2f6dd9650c 100644 --- a/src/Mod/Sketcher/Gui/Resources/Sketcher.qrc +++ b/src/Mod/Sketcher/Gui/Resources/Sketcher.qrc @@ -94,6 +94,7 @@ icons/small/Constraint_PointOnStart_sm.xpm icons/small/Constraint_PointToObject_sm.xpm icons/small/Constraint_Radius_sm.xpm + icons/small/Constraint_Symmetric.svg.zip icons/small/Constraint_Symmetric_sm.xpm icons/small/Constraint_TangentToEnd_sm.xpm icons/small/Constraint_TangentToStart_sm.xpm diff --git a/src/Mod/Sketcher/Gui/Resources/icons/Constraint_Symmetric.svg b/src/Mod/Sketcher/Gui/Resources/icons/Constraint_Symmetric.svg index 00ea06b255..67ff354376 100644 --- a/src/Mod/Sketcher/Gui/Resources/icons/Constraint_Symmetric.svg +++ b/src/Mod/Sketcher/Gui/Resources/icons/Constraint_Symmetric.svg @@ -14,8 +14,11 @@ height="64px" id="svg2816" version="1.1" - inkscape:version="0.47 r22583" - sodipodi:docname="Constraint_Symmetric.svg"> + inkscape:version="0.48.4 r9939" + sodipodi:docname="Constraint_Symmetric1.svg" + inkscape:export-filename="/home/user/Downloads/cad/mystuff/icons/sketcher/conflicting_constraints/Constraint_Symmetric1_16px.png" + inkscape:export-xdpi="22.5" + inkscape:export-ydpi="22.5"> image/svg+xml - + @@ -388,20 +391,23 @@ id="text3796"> + sodipodi:nodetypes="cczccczccccczcczccczcc" + inkscape:connector-curvature="0" /> + sodipodi:nodetypes="czcccccccc" + inkscape:connector-curvature="0" /> + sodipodi:nodetypes="czccccccc" + inkscape:connector-curvature="0" /> diff --git a/src/Mod/Sketcher/Gui/Resources/icons/small/Constraint_Symmetric_sm.xpm b/src/Mod/Sketcher/Gui/Resources/icons/small/Constraint_Symmetric_sm.xpm index 3f5dd217af..2d0249184c 100644 --- a/src/Mod/Sketcher/Gui/Resources/icons/small/Constraint_Symmetric_sm.xpm +++ b/src/Mod/Sketcher/Gui/Resources/icons/small/Constraint_Symmetric_sm.xpm @@ -1,21 +1,23 @@ /* XPM */ -static char * Constraint_Symmetric_sm_xpm[] = { -"16 16 2 1", +static char * Constraint_Symmetric_small_1_16px_xpm[] = { +"16 16 4 1", " c None", -". c #F12000", +". c #FF2500", +"+ c #FF2600", +"@ c #FF2700", " ", " ", " ", -" .. .. ", -" ... .... ", -" ..... ..... ", -" ..... ..... ", -" .... ..... ", -" ... .... ", -" ..... .... ", -" ..... ..... ", -" .... .... ", -" ... ... ", -" . .. ", +" . + ", +" +. ++ ", +" +++ +++ ", +" ++++ +++++ ", +" +++ +++ ", +" ++ ++ ", +" +++ ++++ ", +" ++++ ++++ ", +" +++ +++ ", +" +@ + ", +" ", " ", " "}; From 5dcd0815912fc6a07ed6de4a9fb741b12fef3635 Mon Sep 17 00:00:00 2001 From: Abdullah Tahiri Date: Mon, 15 Sep 2014 13:53:19 +0200 Subject: [PATCH 5/5] Sketcher enhancement: Constraint icons visible over lines --- src/Mod/Sketcher/Gui/Resources/Sketcher.qrc | 1 - src/Mod/Sketcher/Gui/SoDatumLabel.cpp | 32 +++++++++++---------- src/Mod/Sketcher/Gui/ViewProviderSketch.cpp | 6 ++-- 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/Mod/Sketcher/Gui/Resources/Sketcher.qrc b/src/Mod/Sketcher/Gui/Resources/Sketcher.qrc index 2f6dd9650c..38a9462fdf 100644 --- a/src/Mod/Sketcher/Gui/Resources/Sketcher.qrc +++ b/src/Mod/Sketcher/Gui/Resources/Sketcher.qrc @@ -94,7 +94,6 @@ icons/small/Constraint_PointOnStart_sm.xpm icons/small/Constraint_PointToObject_sm.xpm icons/small/Constraint_Radius_sm.xpm - icons/small/Constraint_Symmetric.svg.zip icons/small/Constraint_Symmetric_sm.xpm icons/small/Constraint_TangentToEnd_sm.xpm icons/small/Constraint_TangentToStart_sm.xpm diff --git a/src/Mod/Sketcher/Gui/SoDatumLabel.cpp b/src/Mod/Sketcher/Gui/SoDatumLabel.cpp index 442e674af8..7c02776c7d 100644 --- a/src/Mod/Sketcher/Gui/SoDatumLabel.cpp +++ b/src/Mod/Sketcher/Gui/SoDatumLabel.cpp @@ -56,6 +56,8 @@ #include "SoDatumLabel.h" #include +#define ZCONSTR 0.006f + using namespace SketcherGui; // ------------------------------------------------------ @@ -349,14 +351,14 @@ void SoDatumLabel::generatePrimitives(SoAction * action) // Calculate coordinates for the first arrow SbVec3f ar0, ar1, ar2; - ar0 = p1 + dir * 5 * margin; + ar0 = p1 + dir * 5 * margin ; ar1 = ar0 - dir * 0.866f * 2 * margin; // Base Point of Arrow ar2 = ar1 + norm * margin; // Triangular corners ar1 -= norm * margin; // Calculate coordinates for the second arrow SbVec3f ar3, ar4, ar5; - ar3 = p2 - dir * 5 * margin; + ar3 = p2 - dir * 5 * margin ; ar4 = ar3 + dir * 0.866f * 2 * margin; // Base Point of 2nd Arrow ar5 = ar4 + norm * margin; // Triangular corners @@ -831,14 +833,14 @@ void SoDatumLabel::GLRender(SoGLRenderAction * action) ar1 = ar0 - dir * 0.866f * 2 * margin; ar2 = ar1 + norm * margin; ar1 -= norm * margin; - + glBegin(GL_LINES); - glVertex2f(p1[0],p1[1]); - glVertex2f(ar0[0],ar0[1]); - glVertex2f(ar0[0],ar0[1]); - glVertex2f(ar1[0],ar1[1]); - glVertex2f(ar0[0],ar0[1]); - glVertex2f(ar2[0],ar2[1]); + glVertex3f(p1[0], p1[1], ZCONSTR); + glVertex3f(ar0[0], ar0[1], ZCONSTR); + glVertex3f(ar0[0], ar0[1], ZCONSTR); + glVertex3f(ar1[0], ar1[1], ZCONSTR); + glVertex3f(ar0[0], ar0[1], ZCONSTR); + glVertex3f(ar2[0], ar2[1], ZCONSTR); glEnd(); // Calculate coordinates for the second arrow @@ -849,12 +851,12 @@ void SoDatumLabel::GLRender(SoGLRenderAction * action) ar4 -= norm * margin; glBegin(GL_LINES); - glVertex2f(p2[0],p2[1]); - glVertex2f(ar3[0],ar3[1]); - glVertex2f(ar3[0], ar3[1]); - glVertex2f(ar4[0], ar4[1]); - glVertex2f(ar3[0], ar3[1]); - glVertex2f(ar5[0], ar5[1]); + glVertex3f(p2[0], p2[1], ZCONSTR); + glVertex3f(ar3[0], ar3[1], ZCONSTR); + glVertex3f(ar3[0], ar3[1], ZCONSTR); + glVertex3f(ar4[0], ar4[1], ZCONSTR); + glVertex3f(ar3[0], ar3[1], ZCONSTR); + glVertex3f(ar5[0], ar5[1], ZCONSTR); glEnd(); // BOUNDING BOX CALCULATION - IMPORTANT diff --git a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp index 3dd10d8311..404c7730cb 100644 --- a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp +++ b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp @@ -256,10 +256,10 @@ ViewProviderSketch::ViewProviderSketch() PointSize.setValue(4); zCross=0.001f; - zConstr=0.003f; // constraint not construction zLines=0.005f; - zHighLine=0.006f; - zPoints=0.007f; + zConstr=0.006f; // constraint not construction + zHighLine=0.007f; + zPoints=0.008f; zHighlight=0.009f; zText=0.011f; zEdit=0.001f;