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", " ", " ", " ", -" .. .. ", -" ... .... ", -" ..... ..... ", -" ..... ..... ", -" .... ..... ", -" ... .... ", -" ..... .... ", -" ..... ..... ", -" .... .... ", -" ... ... ", -" . .. ", +" . + ", +" +. ++ ", +" +++ +++ ", +" ++++ +++++ ", +" +++ +++ ", +" ++ ++ ", +" +++ ++++ ", +" ++++ ++++ ", +" +++ +++ ", +" +@ + ", +" ", " ", " "}; diff --git a/src/Mod/Sketcher/Gui/SoDatumLabel.cpp b/src/Mod/Sketcher/Gui/SoDatumLabel.cpp index 86bdfc20db..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; // ------------------------------------------------------ @@ -338,8 +340,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(); @@ -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 @@ -458,6 +460,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); @@ -823,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 @@ -841,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 ffb6f05863..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; @@ -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); } @@ -1485,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()); @@ -2266,6 +2266,33 @@ 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()) @@ -2313,39 +2340,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); + } } } @@ -2373,6 +2407,7 @@ void ViewProviderSketch::drawMergedConstraintIcons(IconQueue iconQueue) QColor iconColor; QList labelColors; int maxColorPriority; + double iconRotation; ConstrIconBBVec boundingBoxes; while(!iconQueue.empty()) { @@ -2388,6 +2423,7 @@ void ViewProviderSketch::drawMergedConstraintIcons(IconQueue iconQueue) iconColor = constrColor(i->constraintId); labelColors.clear(); labelColors.append(iconColor); + iconRotation= i->iconRotation; maxColorPriority = constrColorPriority(i->constraintId); @@ -2439,6 +2475,7 @@ void ViewProviderSketch::drawMergedConstraintIcons(IconQueue iconQueue) iconColor, labels, labelColors, + iconRotation, &boundingBoxesVec, &lastVPad); } else { @@ -2447,6 +2484,7 @@ void ViewProviderSketch::drawMergedConstraintIcons(IconQueue iconQueue) iconColor, labels, labelColors, + iconRotation, &boundingBoxesVec, &thisVPad); @@ -2507,6 +2545,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 +2566,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 +2632,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..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; @@ -282,6 +281,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 +306,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.